Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish decompiling zTaxi & mark it as equivalent #278

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
Object(NonMatching, "SB/Game/zNPCTypeBossPatrick.cpp"),
Object(NonMatching, "SB/Game/zNPCTypeBossPlankton.cpp"),
Object(NonMatching, "SB/Game/zParPTank.cpp"),
Object(NonMatching, "SB/Game/zTaxi.cpp"),
Object(Equivalent, "SB/Game/zTaxi.cpp"),
Object(NonMatching, "SB/Game/zNPCTypeDutchman.cpp"),
Object(Matching, "SB/Game/zCameraFly.cpp"),
Object(Matching, "SB/Core/x/xCurveAsset.cpp"),
Expand Down
6 changes: 5 additions & 1 deletion src/SB/Game/zTalkBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct ztalkbox : xBase
{
ANSWER_CONTINUE,
ANSWER_YES,
ANSWER_NO
ANSWER_NO,
ANSWER_3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably just call this ANSWER_NUM, though it's somewhat confusing to me that this enum definition in the dwarf doesn't have this value. Possibly sAnswer was just defined as ztalkbox::ANSWER_NO + 1 but that's also pretty strange.

};

struct callback
Expand Down Expand Up @@ -85,7 +86,10 @@ struct ztalkbox : xBase
static void reset_all();
static void permit(uint32 add_flags, uint32 remove_flags);

void start_talk(uint32 textID, callback*, zNPCCommon*); // FIXME: params not verified
void stop_talk();

void set_text(uint32 textID);
};

#endif
176 changes: 169 additions & 7 deletions src/SB/Game/zTaxi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,51 @@
#include "xstransvc.h"

#include "zTaxi.h"
#include "zEntPlayer.h"
#include "zGlobals.h"
#include "zScene.h"

#include <types.h>

extern ztalkbox::answer_enum sAnswer;
extern float32 portalTimer;
static ztalkbox::answer_enum sAnswer = ztalkbox::ANSWER_3;

static taxiCB* tCB;

void zTaxi_Init(xBase& data, xDynAsset& asset, ulong32)
{
zTaxi_Init((zTaxi*)&data, (taxi_asset*)&asset);
}

// Nonmatch due to scheduling. https://decomp.me/scratch/wfRIQ
void zTaxi_Init(zTaxi* taxi, taxi_asset* asset)
{
xBaseInit((xBase*)taxi, (xBaseAsset*)asset);

static taxiCB tCB1;
tCB = &tCB1;

taxi->basset = asset;
taxi->eventFunc = zTaxiEventCB;
if (taxi->linkCount != 0)
{
taxi->link = (xLinkAsset*)(asset + 1);
}
else
{
taxi->link = NULL;
}

uint32 size;
xVec3* assetPosition = (xVec3*)xSTFindAsset(asset->marker, &size);
if (assetPosition != NULL && size == sizeof(xVec3))
{
xVec3Copy(&taxi->pos, assetPosition);
taxi->prevState = 0;
taxi->currState = 0;
taxi->radius = 1.3f;
}
}

void zTaxi_Setup(zTaxi* taxi)
{
// Load assets.
Expand All @@ -26,13 +59,142 @@ void zTaxi_Setup(zTaxi* taxi)
// Taxi setup.
xBase* taxiObj = zSceneFindObject(taxi->basset->taxiID);
*(xBase**)&taxi->taxi = taxiObj;
taxi->portalTimer = portalTimer;
taxi->portalTimer = -1.0f;
taxi->baseFlags |= (uint16)2;
}

void zTaxi_tb_answer(ztalkbox::answer_enum answer)
// Nonmatch due to regalloc, scheduling. https://decomp.me/scratch/1o3TG
void zTaxi_Update(xBase* to, xScene*, float32 dt)
{
sAnswer = answer;
zTaxi* taxi = (zTaxi*)to;

xCylinder cylinder;
xVec3Copy(&cylinder.center, &taxi->pos);
cylinder.r = taxi->radius;
cylinder.h = 5.0f;
xIsect isect;
iCylinderIsectVec(&cylinder, (xVec3*)&globals.player.ent.model->Mat->pos, &isect);
if (isect.penned == -1.0f && xBaseIsEnabled((xBase*)taxi))
{
if (taxi->currState == 0)
{
sAnswer = ztalkbox::ANSWER_3;
taxi->currState = 1;
taxi->radius = 2.5f;
}
}
else
{
taxi->currState = 0;
taxi->radius = 1.3f;
}

switch (taxi->currState)
{
case 0:
break;
case 1:
if (gCurrentPlayer == NULL && globals.player.JumpState == 0)
{
if (sAnswer == 1)
{
taxi->currState = 3;
zEntPlayer_SNDPlay(ePlayerSnd_Taxi, 0.0f);
zEntPlayer_SNDPlay(ePlayerSnd_Bus, 0.2f);
}
if (sAnswer == 2)
{
taxi->currState = 2;
}
}
break;
case 2:
zEntPlayerControlOn(CONTROL_OWNER_TAXI);
break;
case 3:
case 5:
break;
}

if (taxi->prevState != taxi->currState)
{
switch (taxi->currState)
{
case 0:
zEntEvent(taxi->basset->talkBoxID, eEventEndConversation);
break;
case 1:
{
ztalkbox* talkbox = (ztalkbox*)zSceneFindObject(taxi->basset->talkBoxID);
talkbox->start_talk(taxi->basset->textID, tCB, NULL);
if (gCurrentPlayer == eCurrentPlayerSpongeBob)
{
zEntPlayerControlOff(CONTROL_OWNER_TAXI);
zEntEvent(taxi->basset->cameraID, eEventEndConversation);
zEntEvent(taxi->basset->taxiID, eEventInvisible);
talkbox->set_text(taxi->basset->textID);
}
else
{
talkbox->set_text(xStrHash("MNU5 TAXI WARNING TXT"));
}
break;
}
case 2:
zEntEvent(taxi->basset->talkBoxID, eEventEndConversation);
break;
case 3:
zEntEvent(taxi->basset->talkBoxID, eEventEndConversation);
zEntEvent(taxi->basset->cameraID, eEventStartConversation);
zEntEvent(taxi->basset->cameraID, eEventSwitch, 0.5f, 0.0f, 0.0f, 0.0f);
zEntEvent(taxi->basset->taxiID, eEventVisible);
zEntEvent(taxi->basset->taxiID, eEventAnimPlay, 2.0f, 0.0f, 0.0f, 0.0f);
taxi->invTimer = taxi->basset->invDelay;
taxi->portalTimer = taxi->basset->portalDelay;
break;
case 4:
xEntHide(&globals.player.ent);
break;
case 5:
zEntEvent(taxi->basset->portalID, eEventTeleportPlayer);
break;
}
}

taxi->prevState = taxi->currState;

if (0.0f == taxi->invTimer && taxi->currState == 3)
{
taxi->currState = 4;
}

if (0.0f == taxi->portalTimer)
{
taxi->currState = 5;
}

if (taxi->portalTimer > 0.0f)
{
taxi->portalTimer -= dt;
if (taxi->portalTimer < 0.0f)
{
taxi->portalTimer = 0.0f;
}
}

if (taxi->invTimer > 0.0f)
{
taxi->invTimer -= dt;
if (taxi->invTimer < 0.0f)
{
taxi->invTimer = 0.0f;
}
}
}

void zTaxi_tb_answer(uint32 answer)
{
sAnswer = (ztalkbox::answer_enum)answer;
}

void zTaxi_Save(zTaxi* taxi, xSerial* s)
Expand Down Expand Up @@ -63,11 +225,11 @@ int32 zTaxiEventCB(xBase* from, xBase* to, uint32 toEvent, const float32* toPara
return eEventEnable;
}

void taxiCB::on_start()
void taxiCB::on_signal(uint32)
{
}

void taxiCB::on_signal()
void taxiCB::on_start()
{
}

Expand Down
16 changes: 6 additions & 10 deletions src/SB/Game/zTaxi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#include "zEnt.h"
#include "zTalkBox.h"

struct callback
{
};

struct taxi_asset : xDynAsset
{
uint32 marker;
Expand All @@ -35,23 +31,23 @@ struct zTaxi : xBase
float32 radius;
};

struct taxiCB : callback
struct taxiCB : ztalkbox::callback
{
zTaxi* taxi;
ztalkbox::answer_enum answer;

void on_start();
void on_signal();
void on_answer(ztalkbox::answer_enum answer);
void on_stop();
virtual void on_signal(uint32);
virtual void on_start();
virtual void on_stop();
virtual void on_answer(ztalkbox::answer_enum answer);
};

struct xScene;

void zTaxi_Init(xBase& data, xDynAsset& asset, ulong32);
void zTaxi_Init(zTaxi* taxi, taxi_asset* asset);
void zTaxi_Setup(zTaxi* taxi);
void zTaxi_tb_answer(ztalkbox::answer_enum answer);
void zTaxi_tb_answer(uint32 answer);
void zTaxi_Save(zTaxi* taxi, xSerial* s);
void zTaxi_Load(zTaxi* taxi, xSerial* s);
int32 zTaxiEventCB(xBase* from, xBase* to, uint32 toEvent, const float32* toParam, xBase* b3);
Expand Down