Let flyers path over water and lava everywhere

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-05 14:46:16 +01:00
1 parent 574660e173
commit 1ef2239fbf
7 files changed
+85 -23

No files matched your search

+31 -6
View File
@@ -656,7 +656,9 @@ impl Map {
let mut step = c * 10;
if k >= 4 {
// diagonal only if both neighbours are walkable (no corner cutting)
if c > 1 || !self.walk(x + dx, y) || !self.walk(x, y + dy) {
// (judged with the same cost, so flyers may cut corners over water and lava)
let open = |cx: i32, cy: i32| cost(idx(cx, cy)) == Some(1);
if c > 1 || !open(x + dx, y) || !open(x, y + dy) {
continue;
}
step = 14;
@@ -673,9 +675,22 @@ impl Map {
}
pub fn walk_cost(&self) -> impl Fn(usize) -> Option<u32> + '_ {
self.creature_cost(false)
}
// flying creatures also cross water and lava
pub fn fly_cost(&self) -> impl Fn(usize) -> Option<u32> + '_ {
self.creature_cost(true)
}
// the dungeon's creatures walk on open ground; flyers also cross water and lava
pub fn creature_cost(&self, fly: bool) -> impl Fn(usize) -> Option<u32> + '_ {
move |i| {
let t = &self.t[i];
// a locked door stops the dungeon's own creatures too
if fly && t.liquid() {
return Some(1);
}
// a locked door stops the dungeon's own creatures too (flyers included)
if t.walkable() && !(t.kind == Kind::Door && t.res & 1 == 1) {
Some(1)
} else {
@@ -684,9 +699,9 @@ impl Map {
}
}
// flying creatures also cross water and lava
pub fn fly_cost(&self) -> impl Fn(usize) -> Option<u32> + '_ {
move |i| if self.t[i].walkable() || self.t[i].liquid() { Some(1) } else { None }
// path for a walking or flying creature
pub fn creature_path(&self, fly: bool, start: usize, target: usize) -> Option<Vec<usize>> {
self.search(start, self.creature_cost(fly), |i| i == target, true)
}
pub fn fly_path_to(&self, start: usize, target: usize) -> Option<Vec<usize>> {
@@ -694,9 +709,15 @@ impl Map {
}
pub fn hero_cost(&self) -> impl Fn(usize) -> Option<u32> + '_ {
self.hero_cost_as(false)
}
// attackers dig through earth; flying ones also cross water and lava
pub fn hero_cost_as(&self, fly: bool) -> impl Fn(usize) -> Option<u32> + '_ {
move |i| {
let tl = &self.t[i];
match tl.kind {
Kind::Water | Kind::Lava if fly => Some(1),
Kind::Earth if tl.reinforced => Some(70),
Kind::Steel => Some(300),
Kind::Earth => Some(7),
@@ -720,7 +741,11 @@ impl Map {
}
pub fn hero_path_to_core(&self, start: usize) -> Option<Vec<usize>> {
self.search(start, self.hero_cost(), |i| self.adj_core(i), true)
self.hero_path_to_core_as(false, start)
}
pub fn hero_path_to_core_as(&self, fly: bool, start: usize) -> Option<Vec<usize>> {
self.search(start, self.hero_cost_as(fly), |i| self.adj_core(i), true)
}