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

BOTS Decomp (WIP) #207

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
41 changes: 20 additions & 21 deletions decompile/General/BOTS/BOTS_05_UpdateGlobals.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
#include <common.h>

#define MAX_KARTS 8

void BOTS_UpdateGlobals(void) //UNTESTED
{
if (sdata->gGT->numBotsNextGame > 0)
if (sdata->gGT->numBotsNextGame != 0)
{
EngineSound_NearestAIs();
}

sdata->bestHumanRank = NULL;
sdata->bestRobotRank = NULL;
struct Driver* worstAI = NULL;
for (int i = 7; i >= 0; i--) //loop through all driver rank low to high (7 to 0)
struct Driver* worstRobotDriver = NULL;

for (int i = MAX_KARTS - 1; i >= 0; i--)
{
struct Driver* d = sdata->gGT->driversInRaceOrder[7];
struct Driver* bestHuman = sdata->bestHumanRank;
if (
(
(d != NULL) && //is valid (for races w/ less than 8 drivers?)
(bestHuman = d, d->actionsFlagSet & 0x100000 != 0) //if this is an AI
) &&
(
bestHuman = sdata->bestHumanRank, //get best human from backup
sdata->bestRobotRank = d, //set best AI driver
worstAI == NULL //if worst AI is not found
)
)
struct Driver* d = sdata->gGT->driversInRaceOrder[i];
if (d != NULL)
{
worstAI = d;
if (d->actionsFlagSet & 0x100000 != 0) //is AI
{
sdata->bestRobotRank = d;
if (worstRobotDriver == NULL)
worstRobotDriver = d;
}
else //is human
sdata->bestHumanRank = d;
}
sdata->bestHumanRank = bestHuman;
}

if (sdata->bestHumanRank == NULL)
{
sdata->bestHumanRank = worstAI;
sdata->bestHumanRank = worstRobotDriver;
}

sdata->unk_counter_upTo450++;
//I finished doing this decomp, and before testing I realized there's also an entry
//in /WIP for this function. Whoops.
}
79 changes: 57 additions & 22 deletions decompile/General/BOTS/BOTS_06_SetRotation.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
#include <common.h>

void BOTS_SetRotation(struct Driver* param_1, short param_2) //UNTESTED
void DECOMP_BOTS_SetRotation(struct Driver* bot, short param_2) //UNTESTED
{
//1st param may be `struct Driver*`
//2nd param may be `short`
//TODO
struct NavFrame* nf = param_1->botNavFrame;

(*(int*)&param_1->unk5bc[0x28]) = 0;
(*(int*)&param_1->unk5bc[0x2C]) = 0;
(*(int*)&param_1->unk5bc[0x30]) = 0;
param_1->estimatePos[0] = (short)(((u_int)param_1->posCurr.x) >> 8);
param_1->estimatePos[1] = (short)(((u_int)param_1->posCurr.y) >> 8);
param_1->estimatePos[2] = (short)(((u_int)param_1->posCurr.z) >> 8);
int dx = nf->pos[0] - param_1->estimatePos[0];
int dy = nf->pos[1] - param_1->estimatePos[1];
int dz = nf->pos[2] - param_1->estimatePos[2];
int xzDist = SquareRoot0(dx * dx + dz * dz);
param_1->distToNextNavXZ = xzDist;
int xyzDist = SquareRoot0(dx * dx + dy * dy + dz * dz);
param_1->distToNextNavXYZ = xyzDist;

//there's more to this function, but at this point I realized that there's already an entry
//in /WIP for this file. Whoops
struct NavFrame* nf = bot->botNavFrame;

(*(int*)&bot->unk5bc[0x28]) = 0;
(*(int*)&bot->unk5bc[0x2C]) = 0;
(*(int*)&bot->unk5bc[0x30]) = 0;

// ======== Get Driver Position =============

bot->estimatePos[0] = (short)(((u_int)bot->posCurr.x) >> 8);
bot->estimatePos[1] = (short)(((u_int)bot->posCurr.y) >> 8);
bot->estimatePos[2] = (short)(((u_int)bot->posCurr.z) >> 8);

// ======== Compare to Nav Position =============

int dx = nf->pos[0] - bot->estimatePos[0];
int dy = nf->pos[1] - bot->estimatePos[1];
int dz = nf->pos[2] - bot->estimatePos[2];

// ======== Calculate Distance =============

//xz dist from driver to nav
int xzDist = SquareRoot0_stub(dx * dx + dz * dz);
bot->distToNextNavXZ = xzDist;
//xyz distance from driver to nav
int xyzDist = SquareRoot0_stub(dx * dx + dy * dy + dz * dz);
bot->distToNextNavXYZ = xyzDist;

// ======== Calculate Rotation =============

int rot = ratan2(dy * 0x1000, bot->distToNextNavXZ * 0x1000);
bot->estimateRotCurrY = rot >> 4;
bot->unk5a8 = 0;

// "if BOTS_ThTick_Drive or BOTS_Driver_Convert"
if (param_2 == 0)
{
bot->estimateRotNav[0] = nf->rot[0];
rot = ratan2(-dx, -dz);
bot->estimateRotNav[1] = ((rot + 0x800) >> 4);
bot->estimateRotNav[2] = nf->rot[1];
}
else
{
bot->estimateRotNav[1] = (char)((sdata->gGT->level1->DriverSpawn[0].rot[1] + 0x400) >> 4);
}

short v = bot->estimateRotNav[1] << 4;

//why does the Driver class have so many ways to store y rotation >:(
bot->ai_rotY_608 = v;
bot->angle = v;
bot->rotCurr.y = v;
bot->rotPrev.y = v;
bot->ai_rot4[1] = v;

bot->botFlags |= 1;
}
101 changes: 97 additions & 4 deletions decompile/General/BOTS/BOTS_09_MaskGrab.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,100 @@
#include <common.h>

void BOTS_MaskGrab(int param_1) //TODO: & add "DECOMP_" prefix
void DECOMP_BOTS_MaskGrab(struct Thread* botThread)
{
//1st param may be `int`, but is almost certainly a `struct*` of some kind
//TODO
}
int midpoint;
struct NavFrame* frame;
struct NavFrame* nextframe;
struct Driver* bot;
struct MaskHeadWeapon* mask;


bot = botThread->object; // get object from thread
frame = bot->botNavFrame; // pointer to nav point
nextframe = frame + 1; // pointer to next nav point after this

// if the next nav point is a farther address than last point
if (sdata->NavPath_ptrHeader[bot->botPath]->last <= nextframe)
{
// set next nav point to first nav point
nextframe = sdata->NavPath_ptrNavFrameArray[bot->botPath];
}

bot->kartState = KS_MASK_GRABBED;

int idk = frame->unk[1] << 0x10;
bot->unk5a8 = ((idk >> 0x10) - (idk >> 0x1f) >> 1) << 8;

// midpointX between nav frames
midpoint = (frame->pos[0] + (nextframe->pos[0] - frame->pos[0]) / 2) * 0x100;
bot->ai_posBackup[0] = midpoint;
bot->posPrev.x = midpoint;

// midpointY between nav frames
midpoint = (frame->pos[1] + (nextframe->pos[1] - frame->pos[1]) / 2) * 0x100;
bot->ai_posBackup[1] = midpoint;
bot->posPrev.y = midpoint;
bot->quadBlockHeight = midpoint;

// midpointZ between nav frames
midpoint = (frame->pos[2] + (nextframe->pos[2] - frame->pos[2]) / 2) * 0x100;
bot->ai_posBackup[2] = midpoint;
bot->posPrev.z = midpoint;

*(short*)(bot->unk5bc + 0x4) = 0;
*(int*)(bot->unk5bc + 0xc) = 0;
*(int*)(bot->unk5bc + 0x10) = 0;
*(int*)(bot->unk5bc + 0x14) = 0;
*(int*)(bot->unk5bc + 0x18) = 0;
*(int*)(bot->unk5bc + 0x28) = 0;
*(int*)(bot->unk5bc + 0x2c) = 0;
*(int*)(bot->unk5bc + 0x30) = 0;

// turn on 1st flag of actions flag set (means racer is on the ground)
bot->actionsFlagSet |= 1;

bot->botFlags &= 0xffffffb0;

bot->rotCurr.x = frame->rot[0] << 4;
bot->rotCurr.y = frame->rot[1] << 4;
bot->rotCurr.z = frame->rot[2] << 4;

bot->turbo_MeterRoomLeft = 0;
bot->reserves = 0;
bot->clockReceive = 0;
bot->squishTimer = 0;
bot->turbo_outsideTimer = 0;
bot->matrixArray = 0;
bot->matrixIndex = 0;

// turn off 7th and 20th flags of actions flag set (means ghost? racer is not in the air (20) and ? (7))
bot->actionsFlagSet &= 0xfff7ffbf;

// if driver is not ghost
if (botThread->modelIndex != 0x4b)
{
// enable collision for this thread
botThread->flags &= 0xffffefff;
}

// posY, plus height to be dropped from
bot->posCurr.x = bot->ai_posBackup[0];
bot->posCurr.y = bot->ai_posBackup[1] + 0x10000;
bot->posCurr.z = bot->ai_posBackup[2];

mask = VehPickupItem_MaskUseWeapon(bot, 1);

// Mask Object (620?)
bot->maskObj = mask;

if (mask)
{
mask->duration = 0x1e00;
mask->rot[2] |= 1;
}

// execute, then assign per-frame to BOTS_ThTick_RevEngine
ThTick_SetAndExec(botThread, BOTS_ThTick_RevEngine);

return;
}
101 changes: 98 additions & 3 deletions decompile/General/BOTS/BOTS_10_Killplane.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,102 @@
#include <common.h>

void BOTS_Killplane(int param_1) //TODO: & add "DECOMP_" prefix
void DECOMP_BOTS_Killplane(struct Thread* botThread)
{
//1st param may be `int`, but is almost certainly a `struct*` of some kind
//TODO
char i;
char boolOverride;
char currNav;
char backCount;
short override;
struct NavFrame* frame;
struct Driver* bot;

// get object from thread
bot = botThread->object;

boolOverride = false;

// check for level "asphalt2"
// check for Tiny Arena
if (strcmp(sdata->gGT->levelName, rdata.s_asphalt2_thisAppearsTwice) == 0) //2nd arg of strcmp 0x80010000
{
// edge-case override?
switch (bot->unknown_lap_related[1])
{
case (unsigned char)-0x6c:
override = 0x84;
break;
case (unsigned char)-0x60:
override = 0x80;
break;
default:
override = 0xff;
}

if (override != 0xff)
{
// pointer to nav point
frame = bot->botNavFrame;

// goBackCount
backCount = frame->goBackCount;
boolOverride = (backCount < (override - 1));

while ((boolOverride || (override + 1 < backCount)))
{
// nav path index
i = bot->botPath;

// go back to previous point
frame -= 1;

// if this is less than address of first nav point
if (frame < sdata->NavPath_ptrNavFrameArray[i])
{
// go to last nav point
frame = sdata->NavPath_ptrHeader[i]->last - 0x14;
}

backCount = frame->goBackCount;
boolOverride = (backCount < (override - 1));
}
bot->botNavFrame = frame;
boolOverride = true;
}
}

// if not Tiny Arena, or goBackCount didn't happen
if (!boolOverride)
{
// pointer to navFrame
frame = bot->botNavFrame;

// current nav point (player turned AI)
currNav = bot->unknown_lap_related[1];

// goBackCount
backCount = frame->goBackCount;

while ((backCount == currNav || ((frame->flags & 0x4000) != 0)))
{
// nav path index
i = bot->botPath;

// go back one navFrame
frame -= 1;

// if you go back to far
if (frame < sdata->NavPath_ptrNavFrameArray[i])
{
// loop back to last navFrame
frame = sdata->NavPath_ptrHeader[i]->last - 0x14;
}
backCount = frame->goBackCount;
currNav = bot->unknown_lap_related[1];
}
// save ptr to nav frame
bot->botNavFrame = frame;
}

DECOMP_BOTS_MaskGrab(botThread);
return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void DECOMP_RB_MakeInstanceReflective(struct ScratchpadStruct* param_1, struct I
// if there is one player
quadFlags = ((struct QuadBlock *)param_1 + 0x80)->quadFlags;

if ((quadFlags & 0x2000) == 0)
if ((quadFlags & 0x2000) == 0) //is not wall
{
// visible?
if ((quadFlags & 1) != 0)
Expand Down
Loading