Towers shoot enemy towers and the enemy gate; build areas use the floor under the pointer

- With no unit in reach, towers fire at opposing towers (both sides) and the player's towers
  at the gate of the order / hero gate (line of sight needed, walls block)
- Rooms, bridges, sell, flag and towers pick the floor tile under the pointer; only digging
  and the hand still aim at walls
- Test for tower duels and gate fire

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-03 11:27:13 +01:00
1 parent 09e22b009e
commit bd8f53e8a1
2 files changed
+162 -6

No files matched your search

+19 -5
View File
@@ -64,6 +64,21 @@ struct Input {
inspect: Option<(f32, f32, f64)>, // long press: show information for this point (CSS pixels)
}
// Tile under the pointer for a tool: digging (and the hand) aim at walls too,
// building and everything else only at the floor below the pointer
fn tool_tile(cam: &Cam, map: &map::Map, tool: Tool, mx: f32, my: f32) -> Option<(i32, i32)> {
if matches!(tool, Tool::Dig | Tool::Hand) {
return cam.pick_tile(map, mx, my).map(|(x, z, _)| (x, z));
}
let p = cam.ground_point(mx, my);
let (x, z) = (p.x.floor() as i32, p.y.floor() as i32);
if inb(x, z) {
Some((x, z))
} else {
None
}
}
fn area_tool(t: Tool) -> bool {
matches!(t, Tool::Dig | Tool::Room(_) | Tool::Sell | Tool::Bridge)
}
@@ -74,7 +89,7 @@ fn world_action(app: &mut App, ui: &mut Ui, r3d: &R3d, inp: &mut Input, mx: f32,
if app.game.state != 0 {
return;
}
let tile = app.cam.pick_tile(&app.game.map, mx, my).map(|(x, z, _)| (x, z));
let tile = tool_tile(&app.cam, &app.game.map, ui.tool, mx, my);
let ground = app.cam.ground_point(mx, my);
let (wx, wy) = (ground.x, ground.y);
match (ui.tool, tile) {
@@ -101,7 +116,7 @@ fn world_action(app: &mut App, ui: &mut Ui, r3d: &R3d, inp: &mut Input, mx: f32,
// Finish a selection rectangle at the tile under (mx, my)
fn finish_rect(app: &mut App, tool: Tool, start: (i32, i32), mx: f32, my: f32) {
let Some((ex, ey, _)) = app.cam.pick_tile(&app.game.map, mx, my) else { return };
let Some((ex, ey)) = tool_tile(&app.cam, &app.game.map, tool, mx, my) else { return };
let (sx, sy) = start;
match tool {
Tool::Dig => {
@@ -406,8 +421,7 @@ async fn main() {
let in_menu = menu.open();
let playing = !in_menu && !dialog;
let over_ui = ui.over_ui(ux, uy);
let picked = app.cam.pick_tile(&app.game.map, mx, my);
let hover_tile = picked.map(|(x, z, _)| (x, z));
let hover_tile = tool_tile(&app.cam, &app.game.map, ui.tool, mx, my);
let ground = app.cam.ground_point(mx, my);
let (wx, wy) = (ground.x, ground.y);
let keys = app.settings.clone();
@@ -866,7 +880,7 @@ fn draw_frame(app: &mut App, gfx: &Gfx, r3d: &mut R3d, ui: &mut Ui, menu: &mut M
let (ux, uy) = (mx * ui::dpr(), my * ui::dpr());
let blocked = menu.open() || ui.show_help || ui.show_langsel;
let over_ui = blocked || ui.over_ui(ux, uy);
let hover_tile = app.cam.pick_tile(&app.game.map, mx, my).map(|(x, z, _)| (x, z));
let hover_tile = tool_tile(&app.cam, &app.game.map, ui.tool, mx, my);
let ground = app.cam.ground_point(mx, my);
clear_background(Color::from_rgba(4, 3, 5, 255));
let (color, radius) = match ui.tool {