From 0cbcd1c8d13972d0ab6d05bfb6080ae1b4c2d9db Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Fri, 6 Nov 2026 12:19:37 +0100 Subject: [PATCH] Markers: a second click or tap removes them; right click with the flag tool takes the flag Co-Authored-By: Claude Opus 5.5 --- src/main.rs | 2 +- src/orders.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c002a8..002ee4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1410,7 +1410,7 @@ async fn main() { if !inp.rdrag && !over_ui && app.game.state == 0 { if inp.ldown.is_some() { inp.ldown = None; - } else if app.game.hand.is_empty() && matches!(ui.tool, Tool::Order(_)) { + } else if app.game.hand.is_empty() && matches!(ui.tool, Tool::Order(_) | Tool::Flag) { app.game.queue(Act::Unmark { x: wx, y: wy }); } else { app.game.queue(Act::Drop { x: wx, y: wy }); diff --git a/src/orders.rs b/src/orders.rs index 49cc2d0..cfe3132 100644 --- a/src/orders.rs +++ b/src/orders.rs @@ -86,7 +86,9 @@ impl Game { let (mx, my) = xy(m); (mx - x).abs() <= 1 && (my - y).abs() <= 1 }) { - return; // there is one already + // a second click (tap) on a marker takes it away again + self.unmark(x as f32 + 0.5, y as f32 + 0.5); + return; } if marks.len() >= MAX_MARKS { self.hint(31, "hint.marks_full"); @@ -128,6 +130,11 @@ impl Game { } } } + } else if let Some(f) = self.flag.filter(|f| near(f)) { + // the rally flag goes the same way + let (fx, fy) = xy(f); + self.set_flag(fx, fy); + return; } else { self.cancel_orders(); return; @@ -329,6 +336,31 @@ mod tests { assert_eq!(g.ents.iter().filter(|e| matches!(e.job, Job::Guard(_))).count(), 0); } + #[test] + fn a_second_tap_removes_a_marker_and_right_click_takes_the_flag() { + let mut g = Game::new(14, 64, 64); + let (cx, cy) = g.map.core; + for y in cy - 6..=cy + 8 { + for x in cx - 6..=cx + 10 { + let t = &mut g.map.t[idx(x, y)]; + if t.kind != Kind::Core { + t.kind = Kind::Floor; + t.owner = Owner::Player; + } + } + } + g.place_mark(cx + 5, cy + 5, false); + g.place_mark(cx + 7, cy + 2, true); + assert_eq!((g.guard_marks.len(), g.attack_marks.len()), (1, 1)); + g.place_mark(cx + 5, cy + 5, false); + g.place_mark(cx + 7, cy + 2, true); + assert_eq!((g.guard_marks.len(), g.attack_marks.len()), (0, 0), "tapped again: gone"); + g.set_flag(cx + 4, cy - 3); + assert!(g.flag.is_some()); + g.unmark(cx as f32 + 4.5, cy as f32 - 2.5); + assert!(g.flag.is_none(), "the flag goes too"); + } + #[test] fn shields_are_held_and_swords_share_the_creatures() { let mut g = Game::new(14, 64, 64);