From 33c64bb00296fa4e9bbebd3eb0c8e15f8a41bae4 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Thu, 13 Jun 2024 11:25:48 -0400 Subject: [PATCH] Implement/match Ambulance::VTable0x70 (#1027) --- LEGO1/lego/legoomni/include/ambulance.h | 4 +-- LEGO1/lego/legoomni/include/legovariables.h | 1 + LEGO1/lego/legoomni/src/actors/ambulance.cpp | 31 +++++++++++++++---- .../legoomni/src/common/legovariables.cpp | 4 +++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/LEGO1/lego/legoomni/include/ambulance.h b/LEGO1/lego/legoomni/include/ambulance.h index f4105678..f8213c90 100644 --- a/LEGO1/lego/legoomni/include/ambulance.h +++ b/LEGO1/lego/legoomni/include/ambulance.h @@ -87,7 +87,7 @@ class Ambulance : public IslePathActor { MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c - void VTable0x70(float p_float) override; // vtable+0x70 + void VTable0x70(float p_time) override; // vtable+0x70 MxLong HandleClick() override; // vtable+0xcc MxLong HandleControl(LegoControlManagerEvent& p_param) override; // vtable+0xd4 MxLong HandleNotification19(MxType19NotificationParam& p_param) override; // vtable+0xdc @@ -119,7 +119,7 @@ class Ambulance : public IslePathActor { MxS16 m_unk0x172; // 0x172 IsleScript::Script m_lastAction; // 0x174 IsleScript::Script m_lastAnimation; // 0x178 - MxFloat m_unk0x17c; // 0x17c + MxFloat m_fuel; // 0x17c MxFloat m_time; // 0x180 }; diff --git a/LEGO1/lego/legoomni/include/legovariables.h b/LEGO1/lego/legoomni/include/legovariables.h index 9ef1a197..582c5b58 100644 --- a/LEGO1/lego/legoomni/include/legovariables.h +++ b/LEGO1/lego/legoomni/include/legovariables.h @@ -3,6 +3,7 @@ #include "mxvariable.h" +extern const char* g_varAMBULSPEED; extern const char* g_varAMBULFUEL; extern const char* g_varTOWFUEL; extern const char* g_varVISIBILITY; diff --git a/LEGO1/lego/legoomni/src/actors/ambulance.cpp b/LEGO1/lego/legoomni/src/actors/ambulance.cpp index 708764ec..5459c882 100644 --- a/LEGO1/lego/legoomni/src/actors/ambulance.cpp +++ b/LEGO1/lego/legoomni/src/actors/ambulance.cpp @@ -7,6 +7,7 @@ #include "legoanimationmanager.h" #include "legocontrolmanager.h" #include "legogamestate.h" +#include "legonavcontroller.h" #include "legoutils.h" #include "legovariables.h" #include "legoworld.h" @@ -37,7 +38,7 @@ Ambulance::Ambulance() m_lastAction = IsleScript::c_noneIsle; m_unk0x172 = 0; m_lastAnimation = IsleScript::c_noneIsle; - m_unk0x17c = 1.0; + m_fuel = 1.0; } // FUNCTION: LEGO1 0x10035f90 @@ -75,16 +76,34 @@ MxResult Ambulance::Create(MxDSAction& p_dsAction) } VariableTable()->SetVariable(g_varAMBULFUEL, "1.0"); - m_unk0x17c = 1.0; + m_fuel = 1.0; m_time = Timer()->GetTime(); return result; } -// STUB: LEGO1 0x10036300 -void Ambulance::VTable0x70(float p_float) +// FUNCTION: LEGO1 0x10036300 +void Ambulance::VTable0x70(float p_time) { - // TODO - IslePathActor::VTable0x70(p_float); + IslePathActor::VTable0x70(p_time); + + if (UserActor() == this) { + char buf[200]; + float speed = abs(m_worldSpeed); + float maxLinearVel = NavController()->GetMaxLinearVel(); + + sprintf(buf, "%g", speed / maxLinearVel); + VariableTable()->SetVariable(g_varAMBULSPEED, buf); + + m_fuel += (p_time - m_time) * -3.333333333e-06f; + if (m_fuel < 0) { + m_fuel = 0; + } + + m_time = p_time; + + sprintf(buf, "%g", m_fuel); + VariableTable()->SetVariable(g_varAMBULFUEL, buf); + } } // FUNCTION: LEGO1 0x100363f0 diff --git a/LEGO1/lego/legoomni/src/common/legovariables.cpp b/LEGO1/lego/legoomni/src/common/legovariables.cpp index 38b5b5e8..52e78930 100644 --- a/LEGO1/lego/legoomni/src/common/legovariables.cpp +++ b/LEGO1/lego/legoomni/src/common/legovariables.cpp @@ -16,6 +16,10 @@ DECOMP_SIZE_ASSERT(CursorVariable, 0x24) DECOMP_SIZE_ASSERT(WhoAmIVariable, 0x24) DECOMP_SIZE_ASSERT(CustomizeAnimFileVariable, 0x24) +// GLOBAL: LEGO1 0x100f39b8 +// STRING: LEGO1 0x100f39ac +const char* g_varAMBULSPEED = "ambulSPEED"; + // GLOBAL: LEGO1 0x100f39bc // STRING: LEGO1 0x100f39a0 const char* g_varAMBULFUEL = "ambulFUEL";