2023-06-29 04:10:08 -04:00
|
|
|
#include "dunebuggy.h"
|
|
|
|
|
2023-09-10 08:01:39 -04:00
|
|
|
#include "decomp.h"
|
2024-07-02 15:16:35 -04:00
|
|
|
#include "isle.h"
|
|
|
|
#include "isle_actions.h"
|
|
|
|
#include "jukebox_actions.h"
|
|
|
|
#include "legoanimationmanager.h"
|
|
|
|
#include "legocontrolmanager.h"
|
|
|
|
#include "legonavcontroller.h"
|
|
|
|
#include "legopathstruct.h"
|
|
|
|
#include "legoutils.h"
|
|
|
|
#include "legovariables.h"
|
|
|
|
#include "legoworld.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mxmisc.h"
|
|
|
|
#include "mxsoundpresenter.h"
|
|
|
|
#include "mxtimer.h"
|
|
|
|
#include "mxtransitionmanager.h"
|
|
|
|
#include "mxvariabletable.h"
|
2023-09-10 08:01:39 -04:00
|
|
|
|
2024-03-22 21:30:58 -04:00
|
|
|
DECOMP_SIZE_ASSERT(DuneBuggy, 0x16c)
|
2023-09-10 08:01:39 -04:00
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// GLOBAL: LEGO1 0x100f7660
|
|
|
|
// STRING: LEGO1 0x100f7634
|
|
|
|
const char* g_varDBFRFNY4 = "C_DBFRFNY4";
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x10067bb0
|
2023-06-29 04:10:08 -04:00
|
|
|
DuneBuggy::DuneBuggy()
|
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
m_maxLinearVel = 25.0;
|
|
|
|
m_fuel = 1.0;
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|
2024-01-20 18:04:46 -05:00
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10067e30
|
2024-01-20 18:04:46 -05:00
|
|
|
MxResult DuneBuggy::Create(MxDSAction& p_dsAction)
|
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
MxResult result = IslePathActor::Create(p_dsAction);
|
|
|
|
m_world = CurrentWorld();
|
|
|
|
|
|
|
|
if (m_world) {
|
|
|
|
m_world->Add(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableTable()->SetVariable(g_varDUNEFUEL, "1.0");
|
|
|
|
m_fuel = 1.0;
|
|
|
|
m_time = Timer()->GetTime();
|
|
|
|
return result;
|
2024-01-20 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10067ec0
|
2024-12-13 14:30:50 -05:00
|
|
|
void DuneBuggy::Animate(float p_time)
|
2024-01-20 18:04:46 -05:00
|
|
|
{
|
2024-12-13 14:30:50 -05:00
|
|
|
IslePathActor::Animate(p_time);
|
2024-07-02 15:16:35 -04:00
|
|
|
|
|
|
|
char buf[200];
|
|
|
|
float speed = abs(m_worldSpeed);
|
|
|
|
float maxLinearVel = NavController()->GetMaxLinearVel();
|
|
|
|
|
|
|
|
sprintf(buf, "%g", speed / maxLinearVel);
|
|
|
|
VariableTable()->SetVariable(g_varDUNESPEED, 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_varDUNEFUEL, buf);
|
2024-01-20 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10067fa0
|
2024-06-06 11:45:37 -04:00
|
|
|
void DuneBuggy::Exit()
|
2024-01-20 18:04:46 -05:00
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
IslePathActor::Exit();
|
|
|
|
GameState()->m_currentArea = LegoGameState::e_dunecar;
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, m_dashboard);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarArms_Ctl);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarHorn_Ctl);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarHorn_Sound);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarInfo_Ctl);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarSpeedMeter);
|
|
|
|
RemoveFromCurrentWorld(*g_isleScript, IsleScript::c_DuneCarFuelMeter);
|
|
|
|
ControlManager()->Unregister(this);
|
2024-01-20 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10068060
|
2024-06-06 12:19:43 -04:00
|
|
|
MxLong DuneBuggy::HandleClick()
|
2024-01-20 18:04:46 -05:00
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
if (!FUN_1003ef60()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUN_10015820(TRUE, 0);
|
|
|
|
|
|
|
|
((Isle*) CurrentWorld())->SetDestLocation(LegoGameState::Area::e_dunecar);
|
2024-07-04 17:28:23 -04:00
|
|
|
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 50, FALSE, TRUE);
|
2024-07-02 15:16:35 -04:00
|
|
|
|
|
|
|
if (GameState()->GetActorId() != UserActor()->GetActorId()) {
|
|
|
|
((IslePathActor*) UserActor())->Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_time = Timer()->GetTime();
|
2024-07-04 20:11:20 -04:00
|
|
|
m_dashboard = IsleScript::c_DuneCarSpeedMeter + GetColorOffset(g_varDBFRFNY4);
|
2024-07-02 15:16:35 -04:00
|
|
|
|
|
|
|
InvokeAction(Extra::ActionType::e_start, *g_isleScript, m_dashboard, NULL);
|
|
|
|
InvokeAction(Extra::ActionType::e_start, *g_isleScript, IsleScript::c_DuneCarDashboard, NULL);
|
|
|
|
GetCurrentAction().SetObjectId(-1);
|
|
|
|
|
|
|
|
Vector3 position = m_roi->GetWorldPosition();
|
|
|
|
AnimationManager()->FUN_10064670(&position);
|
|
|
|
AnimationManager()->FUN_10064740(&position);
|
|
|
|
Enter();
|
|
|
|
ControlManager()->Register(this);
|
|
|
|
return 1;
|
2024-01-20 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x100681b0
|
2024-06-16 10:47:53 -04:00
|
|
|
MxLong DuneBuggy::HandleControl(LegoControlManagerNotificationParam& p_param)
|
2024-01-20 18:04:46 -05:00
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
MxLong result = 0;
|
|
|
|
|
|
|
|
if (p_param.GetUnknown0x28() == 1) {
|
|
|
|
switch (p_param.GetClickedObjectId()) {
|
|
|
|
case IsleScript::c_DuneCarArms_Ctl:
|
|
|
|
Exit();
|
|
|
|
GameState()->m_currentArea = LegoGameState::e_unk66;
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
case IsleScript::c_DuneCarInfo_Ctl:
|
|
|
|
((Isle*) CurrentWorld())->SetDestLocation(LegoGameState::e_infomain);
|
|
|
|
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 50, FALSE, FALSE);
|
|
|
|
Exit();
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
case IsleScript::c_DuneCarHorn_Ctl:
|
|
|
|
MxSoundPresenter* presenter =
|
|
|
|
(MxSoundPresenter*) CurrentWorld()->Find("MxSoundPresenter", "DuneCarHorn_Sound");
|
|
|
|
presenter->Enable(p_param.GetUnknown0x28());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2024-01-20 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10068270
|
2024-06-16 10:47:53 -04:00
|
|
|
MxLong DuneBuggy::HandlePathStruct(LegoPathStructNotificationParam& p_param)
|
2024-01-20 18:04:46 -05:00
|
|
|
{
|
2024-07-02 15:16:35 -04:00
|
|
|
// 0x168 corresponds to the path at the gas station
|
|
|
|
if (p_param.GetData() == 0x168) {
|
|
|
|
m_fuel = 1.0f;
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:04:46 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2024-03-17 13:01:47 -04:00
|
|
|
|
2024-07-02 15:16:35 -04:00
|
|
|
// FUNCTION: LEGO1 0x10068290
|
2024-07-04 20:11:20 -04:00
|
|
|
MxS32 DuneBuggy::GetColorOffset(const char* p_variable)
|
2024-03-17 13:01:47 -04:00
|
|
|
{
|
2024-07-04 20:11:20 -04:00
|
|
|
MxS32 offset = 1;
|
2024-07-02 15:16:35 -04:00
|
|
|
const char* colorName = VariableTable()->GetVariable(p_variable);
|
|
|
|
|
|
|
|
if (strcmpi(colorName, "lego green")) {
|
|
|
|
if (!strcmpi(colorName, "lego red")) {
|
2024-07-04 20:11:20 -04:00
|
|
|
offset = 2;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
else if (!strcmpi(colorName, "lego yellow")) {
|
2024-07-04 20:11:20 -04:00
|
|
|
offset = 3;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
else if (!strcmpi(colorName, "lego black")) {
|
2024-07-04 20:11:20 -04:00
|
|
|
offset = 4;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
else if (!strcmpi(colorName, "lego blue")) {
|
2024-07-04 20:11:20 -04:00
|
|
|
offset = 5;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
else if (!strcmpi(colorName, "lego white")) {
|
2024-07-04 20:11:20 -04:00
|
|
|
offset = 6;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-04 20:11:20 -04:00
|
|
|
return offset;
|
2024-07-02 15:16:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x10068350
|
|
|
|
void DuneBuggy::ActivateSceneActions()
|
|
|
|
{
|
|
|
|
PlayMusic(JukeboxScript::c_GarageArea_Music);
|
|
|
|
|
|
|
|
Act1State* act1state = (Act1State*) GameState()->GetState("Act1State");
|
|
|
|
if (!act1state->m_unk0x022) {
|
|
|
|
act1state->m_unk0x022 = TRUE;
|
|
|
|
|
|
|
|
MxMatrix mat(UserActor()->GetROI()->GetLocal2World());
|
|
|
|
mat.TranslateBy(mat[2][0] * 2.5, mat[2][1] + 0.7, mat[2][2] * 2.5);
|
|
|
|
|
|
|
|
AnimationManager()
|
|
|
|
->FUN_10060dc0(IsleScript::c_sns005in_RunAnim, &mat, TRUE, FALSE, NULL, FALSE, TRUE, TRUE, TRUE);
|
|
|
|
}
|
2024-03-17 13:01:47 -04:00
|
|
|
}
|