Recruit nearby raiders only while the raid pathfinding goal runs

Raiders recruited other raiders every 20 ticks whether or not they were
heading for the raid. In vanilla the recruiting is part of
PathfindToRaidGoal.tick, so a raider that has a target or carries a
rider does not recruit. Do the recruiting from the goal's tick.
This commit is contained in:
Kacpherek
2026-10-26 19:31:28 +01:00
parent 68db8847e7
commit 7d7a85d184
2 changed files with 19 additions and 10 deletions
+4 -6
View File
@@ -791,7 +791,7 @@ impl Game<'_> {
let has_rider = ridden.contains(&m.id);
let target_golem = matches!(m.ai.target, Some(horizon_client::mobs::Who::Mob(t)) if golems.contains(&t));
let target_player = m.ai.target == Some(horizon_client::mobs::Who::Player);
let (health, age, range) = (m.health, m.age, m.attrs.follow_range);
let (health, range) = (m.health, m.attrs.follow_range);
let raids = &mut self.raiding.raids;
let s = m.extra.raider.get_or_insert_with(Box::default);
s.rider = has_rider;
@@ -837,11 +837,9 @@ impl Game<'_> {
{
joins.push((m.id, id, health));
}
// PathfindToRaidGoal.recruitNearby.
if s.active_raid
&& !s.raid_over
&& !s.in_village
&& age % 20 == 0
// PathfindToRaidGoal.tick: recruitNearby, only while the goal runs.
if std::mem::take(&mut s.recruit_due)
&& s.active_raid
&& let Some(id) = s.raid_id
{
recruit.push((id, position));
+15 -4
View File
@@ -38,6 +38,9 @@ pub struct State {
pub in_village: bool,
/// A dropped ominous banner this raider may fetch.
pub banner_at: Option<[f64; 3]>,
/// `PathfindToRaidGoal.tick` ran its 20 tick recruitment: the game
/// recruits the raiders around this one.
pub recruit_due: bool,
/// Beds around the raid's centre.
pub homes: Option<std::sync::Arc<Vec<[i32; 3]>>>,
/// A ravager carrying a raider, set every tick from `Extra::rider`.
@@ -114,7 +117,7 @@ pub fn register(m: &mut Mob) {
m.extra.raider = Some(Box::default());
m.ai.goals.add(4, LongDistancePatrol::new(0.7, 0.595));
m.ai.goals.add(1, ObtainBanner);
m.ai.goals.add(3, PathfindToRaid);
m.ai.goals.add(3, PathfindToRaid::default());
m.ai.goals.add(4, MoveThroughVillage::new(1.05, 1.0));
m.ai.goals.add(5, Celebration);
}
@@ -357,9 +360,11 @@ impl Goal for ObtainBanner {
}
/// `PathfindToRaidGoal`: outside the village, head for the raid's centre in
/// hops of up to 15 blocks.
#[derive(Clone, Debug)]
pub struct PathfindToRaid;
/// hops of up to 15 blocks, recruiting nearby raiders every 20 ticks.
#[derive(Clone, Debug, Default)]
pub struct PathfindToRaid {
recruitment_tick: i32,
}
impl PathfindToRaid {
fn valid(s: &State) -> bool {
s.active_raid && !s.raid_over && !s.in_village
@@ -380,6 +385,12 @@ impl Goal for PathfindToRaid {
let Some(c) = state(m).map(|s| s.raid_center) else {
return;
};
if m.age as i32 > self.recruitment_tick {
self.recruitment_tick = m.age as i32 + 20;
if let Some(s) = m.extra.raider.as_deref_mut() {
s.recruit_due = true;
}
}
if m.ai.nav.is_done() {
let to = [
f64::from(c[0]) + 0.5,