chiark / gitweb /
hidden: Do not allow a player to access entirely-invisible pieces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Mar 2021 00:32:04 +0000 (00:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Mar 2021 00:32:04 +0000 (00:32 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/hidden.rs

index 34a5a7bb1d448cdbe408ae1bdc4e334655727bb8..059d6f843de4f6f4d1a30d56124915b172cfb9d7 100644 (file)
@@ -303,15 +303,22 @@ impl GPiece {
 }
 
 pub fn vpiece_decode(
-  _gs: &GameState, // xxx
+  gs: &GameState,
   player: PlayerId,
   gpl: &GPlayer,
   vis: VisiblePieceId
 ) -> Option<PieceId> {
-  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<PieceId> = gpl.idmap.rev(vis);
+  let piece: Option<PieceId> = 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
 }