From b6235a16302aae17738034e92800aca5181b33a8 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 23 Jul 2023 02:53:19 +0200 Subject: [PATCH] Don't copy flight events of child boosters --- .../simulation/FlightDataBranch.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/simulation/FlightDataBranch.java b/core/src/net/sf/openrocket/simulation/FlightDataBranch.java index 270431deb..395c96343 100644 --- a/core/src/net/sf/openrocket/simulation/FlightDataBranch.java +++ b/core/src/net/sf/openrocket/simulation/FlightDataBranch.java @@ -6,6 +6,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import net.sf.openrocket.rocketcomponent.AxialStage; +import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.Monitorable; @@ -195,11 +197,35 @@ public class FlightDataBranch implements Monitorable { if (event.getType() == FlightEvent.Type.STAGE_SEPARATION) { continue; } - if (srcComponent != null && (srcComponent == event.getSource() || srcComponent.containsChild(event.getSource()))) { + RocketComponent srcEventComponent = event.getSource(); + // Ignore null events + if (srcComponent == null || srcEventComponent == null) { + continue; + } + // Ignore events from other stages. Important for when the current stage has a booster stage; we don't want to copy over the booster events. + if (getStageForComponent(srcComponent) != getStageForComponent(srcEventComponent)) { + continue; + } + if (srcComponent == srcEventComponent || srcComponent.containsChild(srcEventComponent)) { events.add(event); } } } + + /** + * A safer method for checking the stage of a component (that shouldn't throw exceptions when calling on stages/rockets) + * @param component the component to get the stage of + * @return the stage of the component, or null if the component is a rocket + */ + private AxialStage getStageForComponent(RocketComponent component) { + if (component instanceof AxialStage) { + return (AxialStage) component; + } else if (component instanceof Rocket) { + return null; + } else { + return component.getStage(); + } + } /** * Return the branch name.