mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Made socialising NPCs dance
This commit is contained in:
parent
5aaee96cb1
commit
7dfbc2bdab
@ -216,6 +216,7 @@ pub enum NpcActivity {
|
||||
Gather(&'static [ChunkResource]),
|
||||
// TODO: Generalise to other entities? What kinds of animals?
|
||||
HuntAnimals,
|
||||
Dance,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
@ -66,7 +66,9 @@ impl Controller {
|
||||
|
||||
pub fn do_hunt_animals(&mut self) { self.activity = Some(NpcActivity::HuntAnimals); }
|
||||
|
||||
pub fn do_greet(&mut self, actor: Actor) { self.actions.push(NpcAction::Greet(actor)); }
|
||||
pub fn do_dance(&mut self) { self.activity = Some(NpcActivity::Dance); }
|
||||
|
||||
pub fn greet(&mut self, actor: Actor) { self.actions.push(NpcAction::Greet(actor)); }
|
||||
}
|
||||
|
||||
pub struct Brain {
|
||||
|
@ -454,19 +454,25 @@ fn timeout(time: f64) -> impl FnMut(&mut NpcCtx) -> bool + Clone + Send + Sync {
|
||||
}
|
||||
|
||||
fn socialize() -> impl Action {
|
||||
just(|ctx| {
|
||||
now(|ctx| {
|
||||
let mut rng = thread_rng();
|
||||
// TODO: Bit odd, should wait for a while after greeting
|
||||
if thread_rng().gen_bool(0.0003) {
|
||||
if let Some(other) = ctx
|
||||
.state
|
||||
.data()
|
||||
.npcs
|
||||
.nearby(ctx.npc.wpos.xy(), 8.0)
|
||||
.choose(&mut rng)
|
||||
{
|
||||
ctx.controller.do_greet(other);
|
||||
}
|
||||
if thread_rng().gen_bool(0.0003) && let Some(other) = ctx
|
||||
.state
|
||||
.data()
|
||||
.npcs
|
||||
.nearby(ctx.npc.wpos.xy(), 8.0)
|
||||
.choose(&mut rng)
|
||||
{
|
||||
just(move |ctx| ctx.controller.greet(other)).boxed()
|
||||
} else if thread_rng().gen_bool(0.0003) {
|
||||
just(|ctx| ctx.controller.do_dance())
|
||||
.repeat()
|
||||
.stop_if(timeout(6.0))
|
||||
.map(|_| ())
|
||||
.boxed()
|
||||
} else {
|
||||
idle().boxed()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -249,7 +249,8 @@ impl Rule for SimulateNpcs {
|
||||
Some(
|
||||
NpcActivity::Goto(_, _)
|
||||
| NpcActivity::Gather(_)
|
||||
| NpcActivity::HuntAnimals,
|
||||
| NpcActivity::HuntAnimals
|
||||
| NpcActivity::Dance,
|
||||
) => {},
|
||||
None => {},
|
||||
}
|
||||
@ -276,7 +277,11 @@ impl Rule for SimulateNpcs {
|
||||
.with_z(0.0);
|
||||
}
|
||||
},
|
||||
Some(NpcActivity::Gather(_) | NpcActivity::HuntAnimals) => {
|
||||
Some(
|
||||
NpcActivity::Gather(_)
|
||||
| NpcActivity::HuntAnimals
|
||||
| NpcActivity::Dance,
|
||||
) => {
|
||||
// TODO: Maybe they should walk around randomly
|
||||
// when gathering resources?
|
||||
},
|
||||
|
@ -349,6 +349,10 @@ impl<'a> AgentData<'a> {
|
||||
controller.push_action(ControlAction::Dance);
|
||||
break 'activity; // Don't fall through to idle wandering
|
||||
},
|
||||
Some(NpcActivity::Dance) => {
|
||||
controller.push_action(ControlAction::Dance);
|
||||
break 'activity; // Don't fall through to idle wandering
|
||||
},
|
||||
Some(NpcActivity::HuntAnimals) => {
|
||||
if rng.gen::<f32>() < 0.1 {
|
||||
self.choose_target(
|
||||
|
Loading…
Reference in New Issue
Block a user