From: Ian Jackson Date: Sun, 21 Mar 2021 00:32:04 +0000 (+0000) Subject: hidden: Do not allow a player to access entirely-invisible pieces X-Git-Tag: otter-0.5.0~581 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c011c4da55f0bd2484fd9ac13b815d2fa4b23801;p=otter.git hidden: Do not allow a player to access entirely-invisible pieces Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 34a5a7bb..059d6f84 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -303,15 +303,22 @@ impl GPiece { } pub fn vpiece_decode( - _gs: &GameState, // xxx + gs: &GameState, player: PlayerId, gpl: &GPlayer, vis: VisiblePieceId ) -> Option { - let piece = gpl.idmap.rev(vis); - // xxx check for occultation: - // check that this piece is visible at all to this player, - // or they might manipulate it despite not seeing it! + let piece: Option = gpl.idmap.rev(vis); + let piece: Option = if_chain! { + if let Some(p) = piece; + if let Some(gpc) = gs.pieces.get(p); + if let Some(Passive { occid, notch:_ }) = gpc.occult.passive; + if let Some(occ) = gs.occults.occults.get(occid); + let kind = occ.views.get_kind(player); + if ! kind.at_all_visible(); + then { None } + else { piece } + }; trace!("{} {:?} <= {}", player, piece, vis); piece }