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]),
|
Gather(&'static [ChunkResource]),
|
||||||
// TODO: Generalise to other entities? What kinds of animals?
|
// TODO: Generalise to other entities? What kinds of animals?
|
||||||
HuntAnimals,
|
HuntAnimals,
|
||||||
|
Dance,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[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_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 {
|
pub struct Brain {
|
||||||
|
@ -454,19 +454,25 @@ fn timeout(time: f64) -> impl FnMut(&mut NpcCtx) -> bool + Clone + Send + Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn socialize() -> impl Action {
|
fn socialize() -> impl Action {
|
||||||
just(|ctx| {
|
now(|ctx| {
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
// TODO: Bit odd, should wait for a while after greeting
|
// TODO: Bit odd, should wait for a while after greeting
|
||||||
if thread_rng().gen_bool(0.0003) {
|
if thread_rng().gen_bool(0.0003) && let Some(other) = ctx
|
||||||
if let Some(other) = ctx
|
.state
|
||||||
.state
|
.data()
|
||||||
.data()
|
.npcs
|
||||||
.npcs
|
.nearby(ctx.npc.wpos.xy(), 8.0)
|
||||||
.nearby(ctx.npc.wpos.xy(), 8.0)
|
.choose(&mut rng)
|
||||||
.choose(&mut rng)
|
{
|
||||||
{
|
just(move |ctx| ctx.controller.greet(other)).boxed()
|
||||||
ctx.controller.do_greet(other);
|
} 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(
|
Some(
|
||||||
NpcActivity::Goto(_, _)
|
NpcActivity::Goto(_, _)
|
||||||
| NpcActivity::Gather(_)
|
| NpcActivity::Gather(_)
|
||||||
| NpcActivity::HuntAnimals,
|
| NpcActivity::HuntAnimals
|
||||||
|
| NpcActivity::Dance,
|
||||||
) => {},
|
) => {},
|
||||||
None => {},
|
None => {},
|
||||||
}
|
}
|
||||||
@ -276,7 +277,11 @@ impl Rule for SimulateNpcs {
|
|||||||
.with_z(0.0);
|
.with_z(0.0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(NpcActivity::Gather(_) | NpcActivity::HuntAnimals) => {
|
Some(
|
||||||
|
NpcActivity::Gather(_)
|
||||||
|
| NpcActivity::HuntAnimals
|
||||||
|
| NpcActivity::Dance,
|
||||||
|
) => {
|
||||||
// TODO: Maybe they should walk around randomly
|
// TODO: Maybe they should walk around randomly
|
||||||
// when gathering resources?
|
// when gathering resources?
|
||||||
},
|
},
|
||||||
|
@ -349,6 +349,10 @@ impl<'a> AgentData<'a> {
|
|||||||
controller.push_action(ControlAction::Dance);
|
controller.push_action(ControlAction::Dance);
|
||||||
break 'activity; // Don't fall through to idle wandering
|
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) => {
|
Some(NpcActivity::HuntAnimals) => {
|
||||||
if rng.gen::<f32>() < 0.1 {
|
if rng.gen::<f32>() < 0.1 {
|
||||||
self.choose_target(
|
self.choose_target(
|
||||||
|
Loading…
Reference in New Issue
Block a user