From 682872514fe6eea283d5e611085760629ad71dda Mon Sep 17 00:00:00 2001 From: indy91 Date: Wed, 26 Jun 2024 17:47:25 +0200 Subject: [PATCH] Save/load state of CSM O2 hose --- .../samples/ProjectApollo/src_csm/ecs.cpp | 34 +++++++++++++++++-- .../samples/ProjectApollo/src_csm/ecs.h | 4 +++ .../samples/ProjectApollo/src_csm/saturn.cpp | 8 +++++ .../samples/ProjectApollo/src_csm/saturn.h | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/ecs.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/ecs.cpp index 63e5c43a1e..600bd510d1 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/ecs.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/ecs.cpp @@ -1354,6 +1354,8 @@ SaturnForwardHatch::SaturnForwardHatch(Sound &opensound, Sound &closesound) : { open = false; toggle = 0; + isHoseConnected = false; + FirstTimeStepDone = false; pipe = NULL; saturn = NULL; @@ -1408,6 +1410,11 @@ void SaturnForwardHatch::Toggle() void SaturnForwardHatch::Timestep(double simdt) { + if (!FirstTimeStepDone) { + DoFirstTimeStep(); + FirstTimeStepDone = true; + } + if (toggle > 0) { toggle--; if (toggle == 0) { @@ -1419,19 +1426,40 @@ void SaturnForwardHatch::Timestep(double simdt) { saturn->SetAnimation(anim_pressequalvlv, equalvalve_state / 3); } +void SaturnForwardHatch::DoFirstTimeStep() +{ + if (isHoseConnected) + { + saturn->ConnectCSMO2Hose(); + } +} + void SaturnForwardHatch::LoadState(char *line) { - int i1; + int i1, i2; + + i2 = 0; - sscanf(line + 12, "%d %d", &i1, &toggle); + sscanf(line + 12, "%d %d %d", &i1, &toggle, &i2); open = (i1 != 0); + isHoseConnected = (i2 != 0); } void SaturnForwardHatch::SaveState(FILEHANDLE scn) { char buffer[100]; + bool hose; + + if (saturn->GetCSMO2Hose()->out != NULL) + { + hose = true; + } + else + { + hose = false; + } - sprintf(buffer, "%i %i", (open ? 1 : 0), toggle); + sprintf(buffer, "%i %i %i", (open ? 1 : 0), toggle, (hose ? 1 : 0)); oapiWriteScenario_string(scn, "FORWARDHATCH", buffer); } diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/ecs.h b/Orbitersdk/samples/ProjectApollo/src_csm/ecs.h index 3e92f1a4fb..6c2354f291 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/ecs.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/ecs.h @@ -361,8 +361,12 @@ class SaturnForwardHatch void DefineAnimationsVC(UINT idx); protected: + void DoFirstTimeStep(); + bool open; int toggle; + bool isHoseConnected; //Only used as a temporary variable to store the state of the hose connection from LoadState to clbkPostCreation, doesn't keep track of the connection after loading + bool FirstTimeStepDone; Saturn *saturn; h_Pipe *pipe; diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp index 37c6c69b4e..6b06549c9e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp @@ -4903,6 +4903,14 @@ h_Pipe* Saturn::GetCSMO2Hose() return (h_Pipe*)Panelsdk.GetPointerByString("HYDRAULIC:CSMTOLMO2HOSE"); } +void Saturn::ConnectCSMO2Hose() +{ + if (ForwardHatch.IsOpen()) + { + lemECSConnector.ConnectCSMO2Hose(); + } +} + bool Saturn::GetLMDesBatLVOn() { return LMPowerSwitch.IsDown() && MnbLMPWR2CircuitBraker.IsPowered(); diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h index 4d8b0d7b92..2d9040c280 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h @@ -1020,6 +1020,7 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener { //CSM to LM interface functions h_Pipe* GetCMTunnelPipe() { return CMTunnel; } h_Pipe* GetCSMO2Hose(); + void ConnectCSMO2Hose(); void ConnectTunnelToCabinVent(); bool GetLMDesBatLVOn(); bool GetLMDesBatLVHVOffA();