chiark / gitweb /
hidden: Update max_z for max occulted displaced Z
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Mar 2021 00:16:01 +0000 (00:16 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Mar 2021 00:19:46 +0000 (00:19 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/error.rs
src/hand.rs
src/hidden.rs
src/vpid.rs

index 5e63931755c0649a9dbac53c9f46fd9f87b953ec..789921ad87df8f5de8f88447ba65c2ae7b11c230 100644 (file)
@@ -59,6 +59,8 @@ pub enum InternalError {
   PartialPlayerData,
   #[error("Coordinate overflow")]
   CoordinateOverflow(#[from] CoordinateOverflow),
+  #[error("Z Coordinate overflow (game is too crufty?)")]
+  ZCoordinateOverflow(#[from] zcoord::Overflow),
   #[error("Multiple errors occurred where only one could be reported")]
   Aggregated,
 }
index af6d663ab0ed2e88a1e37f62f416a6df26637fd5..6e8cd7faee23c717931055e1530a580af2f68f70 100644 (file)
@@ -196,7 +196,7 @@ impl PieceTrait for Hand {
         // actually do things:
         dbgc!("creating occ");
         let xupdates =
-          create_occultation(&mut gen.unique_gen(),
+          create_occultation(&mut gen.unique_gen(), &mut gs.max_z,
                              gplayers, gpieces, goccults, ipieces, ioccults,
                              to_permute,
                              region, piece, views)?;
index 96cbc9d38ab634ffab7aff8548eb45ce5db3fa9f..34a5a7bb1d448cdbe408ae1bdc4e334655727bb8 100644 (file)
@@ -670,6 +670,7 @@ impl OccultationViewDef for OwnerOccultationView {
 #[throws(OnlineError)]
 pub fn create_occultation(
   gen: &mut UniqueGenGen,
+  max_z: &mut ZCoord,
   gplayers: &mut GPlayers,
   gpieces: &mut GPieces,
   goccults: &mut GameOccults,
@@ -686,6 +687,25 @@ pub fn create_occultation(
     if ogpc.occult.active.is_some() {
       throw!(internal_logic_error("re-occulting!"))
     }
+
+    if let Some(displ_z) = {
+      views.views
+        .iter().map(|ov| &ov.occult)
+        .chain(iter::once(&views.defview))
+        .filter_map(|ok| { use OccKG::*; match ok {
+          Visible | Scrambled | Invisible => None,
+          Displaced((_area, ref z)) => Some(z)
+        }})
+        .max()
+    } {
+      // We expect that ogpc.zlevel.z.increment() is shorter than
+      // the displ_z, but in case it isn't, we must look at both.
+      (||{
+        max_z.update_max(&ogpc.zlevel.z.clone_mut().increment()?);
+        max_z.update_max(&displ_z.plus_offset(! 0)?);
+        Ok::<_,IE>(())
+      })()?;
+    }
   }
 
   for occ in goccults.occults.values() {
index 62e431c103ee8e62730a48184478b71e9f5860f7..d706ced64d269d87f17106401e0904d1115cff14 100644 (file)
@@ -115,7 +115,7 @@ impl Notches {
       None => {
         let a = self.table.push(new);
         let b = self.zg.push(zg);
-        // xxx maybe update z_max in gs
+        // gs.max_z was updated when we created the occultation
         assert_eq!(a,b);
         a
       },