From: Ian Jackson Date: Sat, 13 Mar 2021 19:45:44 +0000 (+0000) Subject: hidden: introduce Passive, with field names X-Git-Tag: otter-0.4.0~103 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9acc2b5b3a4cd10d9e75041b4c25c2e2ed3bd950;p=otter.git hidden: introduce Passive, with field names Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 9e2601e9..94dac5ba 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -21,7 +21,14 @@ pub struct GameOccults { // kept in synch with Occultation::pieces pub struct PieceOccult { active: Option, // kept in synch with Occultation::occulter - passive: Option<(OccId, Notch, Generation)>, // kept in synch with Occultation::pieces + passive: Option, // kept in synch with Occultation::pieces +} + +#[derive(Clone,Copy,Debug,Serialize,Deserialize,Eq,PartialEq)] +struct Passive { + occid: OccId, + notch: Notch, + zg: Generation, } #[derive(Clone,Debug,Serialize,Deserialize)] @@ -446,7 +453,7 @@ mod vpid { new_notches[notch] = NR::Piece(new_piece); gpieces.get_mut(new_piece).unwrap() .occult.passive.as_mut().unwrap() - .1 + .notch = notch; } } @@ -506,7 +513,7 @@ fn inner( ) -> Option { let occk = if_chain! { - if let Some((occid, notch, zg)) = gpc.occult.passive; + if let Some(Passive { occid, notch, zg }) = gpc.occult.passive; if let Some(occultation) = occults.occults.get(occid); then { occultation.views.get_kind(player) @@ -634,7 +641,7 @@ fn recalculate_occultation_general< let occulteds = OldNewOcculteds { old: - gpc.occult.passive.map(|(occid, notch, _zg)| Ok::<_,IE>(( + gpc.occult.passive.map(|Passive { occid, notch, zg:_zg }| Ok::<_,IE>(( Occulted { occid, occ: goccults.occults.get(occid).ok_or_else( @@ -787,7 +794,7 @@ fn recalculate_occultation_general< let zg = gen.next(); let notch = notches(goccults, occid) .insert(zg, piece); - Some((occid, notch, zg)) + Some(Passive { occid, notch, zg }) } else { None }; @@ -1043,8 +1050,9 @@ pub fn remove_occultation( gpieces .iter() .filter_map(|(ppiece, pgpc)| { - if pgpc.occult.passive.map(|p| p.0) == Some(occid) { Some(ppiece) } - else { None } + if pgpc.occult.passive.map(|p| p.occid) == Some(occid) { + Some(ppiece) + } else { None } }) .collect() };