From f2c584c9a479a3dc092f25d359f7763bd467e80d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 21 Mar 2021 00:16:01 +0000 Subject: [PATCH] hidden: Update max_z for max occulted displaced Z Signed-off-by: Ian Jackson --- src/error.rs | 2 ++ src/hand.rs | 2 +- src/hidden.rs | 20 ++++++++++++++++++++ src/vpid.rs | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5e639317..789921ad 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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, } diff --git a/src/hand.rs b/src/hand.rs index af6d663a..6e8cd7fa 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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)?; diff --git a/src/hidden.rs b/src/hidden.rs index 96cbc9d3..34a5a7bb 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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() { diff --git a/src/vpid.rs b/src/vpid.rs index 62e431c1..d706ced6 100644 --- a/src/vpid.rs +++ b/src/vpid.rs @@ -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 }, -- 2.30.2