chiark / gitweb /
hidden: Handle removal of occulted pieces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 23:37:35 +0000 (23:37 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 23:37:35 +0000 (23:37 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/hidden.rs

index 0cdc55215d63dde0dfb759cbf5b52ea4476afe01..c966dc080c1f1ff764a0b5757bb01cd1c2497c2a 100644 (file)
@@ -607,6 +607,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
                 piece)?
           );
         }
+        gpc.occult.passive_delete_hook(&mut gs.occults, piece);
         ipc.p.into_inner().delete_hook(&gpc, gs);
       }
       if let Some(occilk) = ipc.occilk { ig.ioccults.ilks.dispose(occilk); }
index ad0feac884e552b27fe78ba3aaa6c29ea275ede1..5e84f361ef172a0127b4893481626144c7648754 100644 (file)
@@ -73,6 +73,17 @@ pub type OccultationKind = OccultationKindGeneral<(Area, ZCoord)>;
 impl PieceOccult {
   pub fn is_active(&self) -> bool { self.active.is_some() }
   pub fn passive_occid(&self) -> Option<OccId> { Some(self.passive?.occid) }
+  pub fn passive_delete_hook(&self, goccults: &mut GameOccults,
+                             piece: PieceId) {
+    if_chain! {
+      if let Some(Passive { occid, notch }) = self.passive;
+      if let Some(occ) = goccults.occults.get_mut(occid);
+      then {
+        occ.notches.remove(piece, notch)
+          .unwrap_or_else(|e| error!("removing occulted piece {:?}", e));
+      }
+    }
+  }
 }
 
 impl Default for OccultationKind {
@@ -305,9 +316,6 @@ pub fn vpiece_decode(
   piece
 }
 
-// xxx prevent addpiece and removepiece in places that would be occulted
-// xxx this means this only happens on ungrab I think ?
-
 #[throws(InternalError)]
 fn recalculate_occultation_general<
   RD: Debug,                                          // return data