This commit is contained in:
@@ -1340,17 +1340,18 @@ impl Recording {
|
||||
}
|
||||
}
|
||||
}
|
||||
EventKind::Hit { drone, sam, .. } => {
|
||||
let by_sam = sam.and_then(|(_, i)| self.sams.get(i).map(|s| s.0));
|
||||
EventKind::Hit { drone, .. } => {
|
||||
// This is the contact's outcome, whatever it hit. A system named in
|
||||
// the impact is the object hit, not the observer on the chain.
|
||||
for ((_, target), chain) in chains.iter_mut() {
|
||||
if *target == drone && by_sam.is_none_or(|id| id == chain.sam) {
|
||||
if *target == drone {
|
||||
set_chain_outcome(chain, ChainOutcome::Hit, event.at, Some(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
EventKind::Crash { drone, .. } => {
|
||||
for ((_, target), chain) in chains.iter_mut() {
|
||||
if *target == drone && !chain.launched() {
|
||||
if *target == drone && chain.outcome == ChainOutcome::Unfinished && !chain.launched() {
|
||||
set_chain_outcome(chain, ChainOutcome::Lost, event.at, Some(index));
|
||||
}
|
||||
}
|
||||
@@ -1362,6 +1363,7 @@ impl Recording {
|
||||
for event in scene.events() {
|
||||
if let SceneKind::TrackLost { sam, target } = event.kind
|
||||
&& let Some(chain) = chains.get_mut(&(sam, target))
|
||||
&& chain.outcome == ChainOutcome::Unfinished
|
||||
&& !chain.launched()
|
||||
{
|
||||
set_chain_outcome(chain, ChainOutcome::Lost, event.at, None);
|
||||
@@ -1727,6 +1729,33 @@ mod tests {
|
||||
assert_eq!(chain.outcome_event(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_recorded_impact_stays_in_every_observers_chain_when_the_track_ends() {
|
||||
let mut r = Recording::blank(100);
|
||||
r.sams = vec![(10, SamKind::Pantsir, DVec3::ZERO), (20, SamKind::S400, DVec3::X)];
|
||||
let mut scene = SceneJournal::default();
|
||||
for sam in [10, 20] {
|
||||
scene.push(SceneEvent { at: 10, pos: DVec3::ZERO, kind: SceneKind::TrackAcquired { sam, target: 7, ever_own: false } });
|
||||
}
|
||||
for sam in [10, 20] {
|
||||
scene.push(SceneEvent { at: 51, pos: DVec3::ZERO, kind: SceneKind::TrackLost { sam, target: 7 } });
|
||||
}
|
||||
r.scene = Some(scene);
|
||||
r.events.push(Event {
|
||||
at: 50,
|
||||
pos: DVec3::ZERO,
|
||||
kind: EventKind::Hit { drone: 7, kind: DroneKind::Shahed, power: 2, object: None, sam: Some((SamKind::S400, 1)) },
|
||||
});
|
||||
for id in [10, 20] {
|
||||
let chains = r.chains(Some(id));
|
||||
assert_eq!(chains.len(), 1);
|
||||
assert_eq!(chains[0].outcome, ChainOutcome::Hit);
|
||||
assert_eq!(chains[0].outcome_event(), Some(0));
|
||||
assert_eq!(chains[0].step(ChainStepKind::Outcome).unwrap().at, 50);
|
||||
assert!(chains[0].missed());
|
||||
}
|
||||
}
|
||||
|
||||
fn recording() -> Recording {
|
||||
Recording::blank(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user