Fix raid gameplay, finite ammunition and truck routing
Check launch terrain, reserve ballistic targets for marked objectives, tune in-game reach and fallback fire, and support bounded terrain work on supply routes. Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -35,10 +35,29 @@ impl Sam {
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_move(sam: &mut Sam, routes: &mut route::Routes, index: usize, now: u64, why: Option<route::Why>, out: &mut Out) {
|
||||
if let Some(why) = why {
|
||||
let report = sam.job.take().is_none_or(|job| {
|
||||
routes.unreachable.insert((sam.id, job), now + route::UNREACHABLE_FOR).is_none()
|
||||
});
|
||||
if report {
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), index + 1, why.text()));
|
||||
}
|
||||
}
|
||||
routes.map.remove(&sam.id);
|
||||
sam.dest = None;
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
}
|
||||
|
||||
impl Sim {
|
||||
/// Orders unit `i` to drive to `to`. False for one that can't (a depot, a wreck, failed running gear).
|
||||
pub fn order_move(&mut self, i: usize, to: DVec3) -> bool {
|
||||
self.order_move_near(i, to, 0.0)
|
||||
if !self.order_move_near(i, to, 0.0) {
|
||||
return false;
|
||||
}
|
||||
self.sams[i].job = None;
|
||||
true
|
||||
}
|
||||
|
||||
/// The same, where arriving within `slack` blocks of `to` will do (a truck stops beside its job).
|
||||
@@ -97,45 +116,45 @@ impl Sim {
|
||||
sam.dest = None;
|
||||
}
|
||||
let Some(to) = sam.dest else {
|
||||
routes.map.remove(&sam.id);
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
finish_move(sam, routes, n, now, None, out);
|
||||
continue;
|
||||
};
|
||||
let route = routes.map.entry(sam.id).or_insert_with(|| route::Route::new(sam.pos, to, 0.0, sam.kind, now));
|
||||
let (go, last) = match route.drive(ground, now, sam.pos, share) {
|
||||
route::Drive::Wait(why) => {
|
||||
if route.waited(now) > 40 && !route.told {
|
||||
if sam.job.is_none() && route.waited(now) > 40 && !route.told {
|
||||
route.told = true;
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), n + 1, why.text()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
route::Drive::Fail(why) => {
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), n + 1, why.text()));
|
||||
// A truck leaves that job alone for a while, and takes another.
|
||||
if let Some(job) = sam.job.take() {
|
||||
routes.unreachable.insert((sam.id, job), now + route::UNREACHABLE_FOR);
|
||||
if why == route::Why::NoWay && route.approach_works() {
|
||||
continue;
|
||||
}
|
||||
routes.map.remove(&sam.id);
|
||||
sam.dest = None;
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
if matches!(why, route::Why::NoWay | route::Why::Stuck)
|
||||
&& route.try_works(ground, sam.pos, now, out)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
finish_move(sam, routes, n, now, Some(why), out);
|
||||
continue;
|
||||
}
|
||||
route::Drive::Go(p, last) => (p, last),
|
||||
};
|
||||
let flat = horizontal(go - sam.pos);
|
||||
if last && flat.length() < SPEED * 2.0 {
|
||||
let partial = route.partial;
|
||||
sam.pos = DVec3::new(go.x, sam.pos.y, go.z);
|
||||
sam.dest = None;
|
||||
routes.map.remove(&sam.id);
|
||||
if partial {
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), n + 1, route::Why::Partial.text()));
|
||||
}
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
let why = if route.work_approach() {
|
||||
if route.try_works(ground, sam.pos, now, out) {
|
||||
continue;
|
||||
}
|
||||
Some(route::Why::NoWay)
|
||||
} else {
|
||||
// A partial route already made measurable progress. A delivery
|
||||
// continues from here when the next stretch of terrain is ready.
|
||||
(route.partial && sam.job.is_none()).then_some(route::Why::Partial)
|
||||
};
|
||||
finish_move(sam, routes, n, now, why, out);
|
||||
out.sound("minecraft:block.piston.contract", sam.pos, 2.0, 0.6);
|
||||
continue;
|
||||
}
|
||||
@@ -143,17 +162,17 @@ impl Sim {
|
||||
sam.heading = slew(sam.heading, heading_of(flat), 0.06);
|
||||
let ahead = DQuat::from_rotation_y(sam.heading) * DVec3::NEG_Z;
|
||||
let turning = angle_diff(sam.heading, heading_of(flat)).abs();
|
||||
if sam.kind == SamKind::Tzm && turning > 0.45 {
|
||||
sam.yaw = sam.heading;
|
||||
continue;
|
||||
}
|
||||
let step = SPEED * sam.drive_speed() * (1.0 - turning / std::f64::consts::PI).max(0.2);
|
||||
let next = sam.pos + ahead * step;
|
||||
// The column and chassis clearance ahead: a wall, low ceiling or a change after planning
|
||||
// turns the vehicle back to the planner. Unknown voxels remain a wait, never a drive.
|
||||
let Some(y) = ground.at(next, now) else {
|
||||
if route.wait_ahead() {
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), n + 1, route::Why::NoMap.text()));
|
||||
routes.map.remove(&sam.id);
|
||||
sam.dest = None;
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
finish_move(sam, routes, n, now, Some(route::Why::NoMap), out);
|
||||
}
|
||||
continue;
|
||||
};
|
||||
@@ -161,11 +180,7 @@ impl Sim {
|
||||
route::Clearance::Clear => {}
|
||||
route::Clearance::Pending => {
|
||||
if route.wait_ahead() {
|
||||
out.messages.push(format!("{} №{}: {}", sam.kind.name(), n + 1, route::Why::NoMap.text()));
|
||||
routes.map.remove(&sam.id);
|
||||
sam.dest = None;
|
||||
sam.state = SamState::Deploying;
|
||||
sam.march = sam.kind.march_ticks();
|
||||
finish_move(sam, routes, n, now, Some(route::Why::NoMap), out);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user