Skip to main content
Verticopolis engine

verticopolis_engine/
events_bomb_edits.rs

1//! The tower's edit lock during a bomb search: while Security's guards are
2//! out, nothing is built, sold or bulldozed, no elevator is changed, and no
3//! edit is undone or redone, in both modes (owner, 2026-11-13).
4
5use serde_json::Value;
6
7use crate::sim::Simulation;
8
9/// What the player reads when an edit is refused during a bomb search.
10pub const BOMB_SEARCH_EDIT_REFUSAL: &str =
11    "Security is searching for the bomb. Building, bulldozing and elevator changes wait until the search ends.";
12
13impl Simulation {
14    /// Why the tower can't be edited now, or `None` when it can. While a
15    /// [`bomb_lockdown`](Simulation::bomb_lockdown) holds, every build,
16    /// sale, bulldoze, elevator change, undo and redo is refused with
17    /// [`BOMB_SEARCH_EDIT_REFUSAL`]. A bomb nobody searches for locks
18    /// nothing, as it freezes nothing.
19    pub fn edit_refusal(&self) -> Option<&'static str> {
20        self.bomb_lockdown().then_some(BOMB_SEARCH_EDIT_REFUSAL)
21    }
22
23    /// A player's stop change on elevator `id`
24    /// ([`Tower::set_stop`](crate::tower::Tower::set_stop)): whether it was
25    /// made. Refused, changing nothing, while the tower takes no edits.
26    pub fn edit_stop(&mut self, id: i64, floor: i64, stop: bool) -> bool {
27        self.edit_refusal().is_none() && self.tower.set_stop(id, floor, stop)
28    }
29
30    /// A player's express stops for shaft `id`
31    /// ([`Tower::set_express_stops`](crate::tower::Tower::set_express_stops)):
32    /// whether `id` names a shaft and the stops were set. Refused, changing
33    /// nothing, while the tower takes no edits.
34    pub fn edit_express_stops(&mut self, id: i64) -> bool {
35        let known = self.edit_refusal().is_none() && self.tower.get_transport(id).is_some();
36        if known {
37            self.tower.set_express_stops(id);
38        }
39        known
40    }
41
42    /// A player clearing shaft `id`'s skipped stops
43    /// ([`Tower::clear_stops`](crate::tower::Tower::clear_stops)). Refused,
44    /// changing nothing, while the tower takes no edits.
45    pub fn edit_clear_stops(&mut self, id: i64) -> bool {
46        self.edit_refusal().is_none() && self.tower.clear_stops(id)
47    }
48
49    /// A player's schedule for elevator `id`
50    /// ([`Tower::set_schedule`](crate::tower::Tower::set_schedule)). Refused,
51    /// changing nothing, while the tower takes no edits.
52    pub fn edit_schedule(&mut self, id: i64, raw: &Value) -> bool {
53        self.edit_refusal().is_none() && self.tower.set_schedule(id, raw)
54    }
55}