Cultists now properly raid villages.

This commit is contained in:
Sam 2021-09-04 12:25:04 -04:00
parent f198349f61
commit f65b3a094d
4 changed files with 30 additions and 19 deletions

View File

@ -504,6 +504,11 @@ impl Agent {
self.position_pid_controller = Some(pid);
self
}
pub fn with_aggro_no_warn(mut self) -> Self {
self.psyche.aggro_dist = None;
self
}
}
impl Component for Agent {

View File

@ -495,7 +495,7 @@ impl Entity {
let dist = wpos.map(|e| e as f32).distance_squared(self.pos.xy()) as u32;
// Once at site, stay for a bit, then move to other site
if dist < 10_u32.pow(2) {
if dist < 128_u32.pow(2) {
// If time_to_move is not set yet, use current time, ceiling to nearest multiple
// of 100, and then add another 100.
let time_to_move = if time_to_move.is_none() {
@ -513,10 +513,9 @@ impl Entity {
time_to_move: None,
}
} else {
let mut rng = RandomPerm::new((time.0 / 25.0) as u32);
let theta = (time.0 / 30.0).floor() as f32 * self.seed as f32;
// Otherwise wander around site (or "plunder" if target site)
let travel_to =
self.pos.xy() + Vec2::<f32>::zero().map(|_| rng.gen_range(-50.0..50.0));
let travel_to = wpos.map(|e| e as f32) + Vec2::new(theta.cos(), theta.sin()) * 100.0/* * RandomPerm::new(theta as u32).gen_range(0.0..1.0)*/;
let travel_to_alt = world
.sim()
.get_alt_approx(travel_to.map(|e| e as i32))
@ -531,7 +530,7 @@ impl Entity {
+ Vec3::new(0.5, 0.5, 0.0);
self.controller.travel_to = Some((travel_to, destination_name));
self.controller.speed_factor = 0.25;
self.controller.speed_factor = 0.75;
Travel::DirectRaid {
target_id,
home_id,
@ -560,7 +559,7 @@ impl Entity {
+ Vec3::new(0.5, 0.5, 0.0);
self.controller.travel_to = Some((travel_to, destination_name));
self.controller.speed_factor = 0.70;
self.controller.speed_factor = 0.90;
Travel::DirectRaid {
target_id,
home_id,

View File

@ -143,7 +143,9 @@ pub fn init(
.filter_map(|(site_id, site)| site.site_tmp.map(|id| (site_id, &index.sites[id])))
{
use world::site::SiteKind;
#[allow(clippy::single_match)]
match &site.kind {
#[allow(clippy::single_match)]
SiteKind::Dungeon(dungeon) => match dungeon.dungeon_difficulty() {
Some(5) => {
let pos = site.get_origin();

View File

@ -107,12 +107,24 @@ impl<'a> System<'a> for Sys {
rtsim.reify_entity(id);
let entity = &rtsim.entities[id];
let body = entity.get_body();
let alignment = match body {
comp::Body::Humanoid(_) => match entity.kind {
RtSimEntityKind::Random => comp::Alignment::Npc,
RtSimEntityKind::Cultist => comp::Alignment::Enemy,
},
comp::Body::BirdLarge(bird_large) => match bird_large.species {
comp::bird_large::Species::Roc => comp::Alignment::Enemy,
comp::bird_large::Species::Cockatrice => comp::Alignment::Enemy,
_ => comp::Alignment::Wild,
},
_ => comp::Alignment::Wild,
};
let spawn_pos = terrain
.find_space(entity.pos.map(|e| e.floor() as i32))
.map(|e| e as f32)
+ Vec3::new(0.5, 0.5, body.flying_height());
let pos = comp::Pos(spawn_pos);
let agent = Some(comp::Agent::from_body(&body).with_behavior(
let mut agent = Some(comp::Agent::from_body(&body).with_behavior(
if matches!(body, comp::Body::Humanoid(_)) {
Behavior::from(BehaviorCapability::SPEAK)
} else {
@ -120,6 +132,10 @@ impl<'a> System<'a> for Sys {
},
));
if matches!(alignment, comp::Alignment::Enemy) {
agent = agent.map(|a| a.with_aggro_no_warn());
}
let rtsim_entity = Some(RtSimEntity(id));
// TODO: this should be a bit more intelligent
@ -145,18 +161,7 @@ impl<'a> System<'a> for Sys {
poise: comp::Poise::new(body),
body,
agent,
alignment: match body {
comp::Body::Humanoid(_) => match entity.kind {
RtSimEntityKind::Random => comp::Alignment::Npc,
RtSimEntityKind::Cultist => comp::Alignment::Enemy,
},
comp::Body::BirdLarge(bird_large) => match bird_large.species {
comp::bird_large::Species::Roc => comp::Alignment::Enemy,
comp::bird_large::Species::Cockatrice => comp::Alignment::Enemy,
_ => comp::Alignment::Wild,
},
_ => comp::Alignment::Wild,
},
alignment,
scale: match body {
comp::Body::Ship(_) => comp::Scale(comp::ship::AIRSHIP_SCALE),
_ => comp::Scale(1.0),