From: Ian Jackson Date: Sat, 20 Mar 2021 23:37:35 +0000 (+0000) Subject: hidden: Handle removal of occulted pieces X-Git-Tag: otter-0.5.0~587 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d5c5041cb86d94d28f3977a52a068c021956fc82;p=otter.git hidden: Handle removal of occulted pieces Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 0cdc5521..c966dc08 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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); } diff --git a/src/hidden.rs b/src/hidden.rs index ad0feac8..5e84f361 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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 { 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