Skip to content

Commit 8f142cd

Browse files
authored
BOTS Decomp (#207)
* working on decomp * add comment * BOTS Killplane * BOTS_MaskGrab * Update globals * BOTS_Driver_Convert * BOTS_Driver_Init * BOTS_GotoStartingLine * BOTS_CollideWithOtherAI * BOTS_ThTick_RevEngine * BOTS_ChangeState * BOTS_LevInstColl (uses scratchpad struct, needs to be modified to work for the PC port). * clean up BOTS_LevInstColl * BOTS_ThTick_Drive in progress. * break out section of struct Driver as new type for bot data, more progress on BOTS_ThTick_Drive * more bots_thtick progress * more bot thtick progress * clean up some BOTS code with new variable names * more progress on BOTS_ThTick * More BOTS_ThTick progress * more bot_thtick progress * more BOTS_ThTick progress * clean up stuff for merge and move ThTick_Drive to WIP * don't ask questions.
1 parent 4fb4802 commit 8f142cd

36 files changed

Lines changed: 2457 additions & 1024 deletions
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
#include <common.h>
22

3+
#define MAX_KARTS 8
4+
35
void BOTS_UpdateGlobals(void) //UNTESTED
46
{
5-
if (sdata->gGT->numBotsNextGame > 0)
7+
if (sdata->gGT->numBotsNextGame != 0)
68
{
79
EngineSound_NearestAIs();
810
}
11+
912
sdata->bestHumanRank = NULL;
1013
sdata->bestRobotRank = NULL;
11-
struct Driver* worstAI = NULL;
12-
for (int i = 7; i >= 0; i--) //loop through all driver rank low to high (7 to 0)
14+
struct Driver* worstRobotDriver = NULL, *bestHumanDriver = NULL;
15+
16+
for (int i = MAX_KARTS - 1; i >= 0; i--)
1317
{
14-
struct Driver* d = sdata->gGT->driversInRaceOrder[7];
18+
struct Driver* d = sdata->gGT->driversInRaceOrder[i];
1519
struct Driver* bestHuman = sdata->bestHumanRank;
16-
if (
17-
(
18-
(d != NULL) && //is valid (for races w/ less than 8 drivers?)
19-
(bestHuman = d, d->actionsFlagSet & 0x100000 != 0) //if this is an AI
20-
) &&
21-
(
22-
bestHuman = sdata->bestHumanRank, //get best human from backup
23-
sdata->bestRobotRank = d, //set best AI driver
24-
worstAI == NULL //if worst AI is not found
25-
)
26-
)
20+
if (d != NULL)
2721
{
28-
worstAI = d;
22+
bestHuman = d; //assume human for now
23+
if (d->actionsFlagSet & 0x100000 != 0)
24+
{
25+
bestHuman = sdata->bestHumanRank; //is bot, nevermind
26+
sdata->bestRobotRank = d; //since it's a bot, it is also the *best* bot so far
27+
if (worstRobotDriver == NULL)
28+
{
29+
worstRobotDriver = d; //if not yet assigned, assign worst bot.
30+
}
31+
}
2932
}
33+
3034
sdata->bestHumanRank = bestHuman;
3135
}
36+
3237
if (sdata->bestHumanRank == NULL)
3338
{
34-
sdata->bestHumanRank = worstAI;
39+
sdata->bestHumanRank = worstRobotDriver;
3540
}
41+
3642
sdata->unk_counter_upTo450++;
37-
//I finished doing this decomp, and before testing I realized there's also an entry
38-
//in /WIP for this function. Whoops.
3943
}
Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,61 @@
11
#include <common.h>
22

3-
void BOTS_SetRotation(struct Driver* param_1, short param_2) //UNTESTED
3+
void DECOMP_BOTS_SetRotation(struct Driver* bot, short param_2) //UNTESTED
44
{
5-
//1st param may be `struct Driver*`
6-
//2nd param may be `short`
7-
//TODO
8-
struct NavFrame* nf = param_1->botNavFrame;
9-
10-
(*(int*)&param_1->unk5bc[0x28]) = 0;
11-
(*(int*)&param_1->unk5bc[0x2C]) = 0;
12-
(*(int*)&param_1->unk5bc[0x30]) = 0;
13-
param_1->estimatePos[0] = (short)(((u_int)param_1->posCurr.x) >> 8);
14-
param_1->estimatePos[1] = (short)(((u_int)param_1->posCurr.y) >> 8);
15-
param_1->estimatePos[2] = (short)(((u_int)param_1->posCurr.z) >> 8);
16-
int dx = nf->pos[0] - param_1->estimatePos[0];
17-
int dy = nf->pos[1] - param_1->estimatePos[1];
18-
int dz = nf->pos[2] - param_1->estimatePos[2];
19-
int xzDist = SquareRoot0(dx * dx + dz * dz);
20-
param_1->distToNextNavXZ = xzDist;
21-
int xyzDist = SquareRoot0(dx * dx + dy * dy + dz * dz);
22-
param_1->distToNextNavXYZ = xyzDist;
23-
24-
//there's more to this function, but at this point I realized that there's already an entry
25-
//in /WIP for this file. Whoops
5+
struct NavFrame* nf = bot->botNavFrame;
6+
7+
(*(int*)&bot->unk5bc[0x28]) = 0;
8+
(*(int*)&bot->unk5bc[0x2C]) = 0;
9+
(*(int*)&bot->unk5bc[0x30]) = 0;
10+
11+
// ======== Get Driver Position =============
12+
13+
bot->estimatePos[0] = (short)(((u_int)bot->posCurr.x) >> 8);
14+
bot->estimatePos[1] = (short)(((u_int)bot->posCurr.y) >> 8);
15+
bot->estimatePos[2] = (short)(((u_int)bot->posCurr.z) >> 8);
16+
17+
// ======== Compare to Nav Position =============
18+
19+
int dx = nf->pos[0] - bot->estimatePos[0];
20+
int dy = nf->pos[1] - bot->estimatePos[1];
21+
int dz = nf->pos[2] - bot->estimatePos[2];
22+
23+
// ======== Calculate Distance =============
24+
25+
//xz dist from driver to nav
26+
int xzDist = SquareRoot0_stub(dx * dx + dz * dz);
27+
bot->distToNextNavXZ = xzDist;
28+
//xyz distance from driver to nav
29+
int xyzDist = SquareRoot0_stub(dx * dx + dy * dy + dz * dz);
30+
bot->distToNextNavXYZ = xyzDist;
31+
32+
// ======== Calculate Rotation =============
33+
34+
int rot = ratan2(dy * 0x1000, bot->distToNextNavXZ * 0x1000);
35+
bot->estimateRotCurrY = rot >> 4;
36+
bot->unk5a8 = 0;
37+
38+
// "if BOTS_ThTick_Drive or BOTS_Driver_Convert"
39+
if (param_2 == 0)
40+
{
41+
bot->estimateRotNav[0] = nf->rot[0];
42+
rot = ratan2(-dx, -dz);
43+
bot->estimateRotNav[1] = ((rot + 0x800) >> 4);
44+
bot->estimateRotNav[2] = nf->rot[1];
45+
}
46+
else
47+
{
48+
bot->estimateRotNav[1] = (char)((sdata->gGT->level1->DriverSpawn[0].rot[1] + 0x400) >> 4);
49+
}
50+
51+
short v = bot->estimateRotNav[1] << 4;
52+
53+
//why does the Driver class have so many ways to store y rotation >:(
54+
bot->ai_rotY_608 = v;
55+
bot->angle = v;
56+
bot->rotCurr.y = v;
57+
bot->rotPrev.y = v;
58+
bot->ai_rot4[1] = v;
59+
60+
bot->botFlags |= 1;
2661
}
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11
#include <common.h>
22

3-
void BOTS_LevInstColl(int param_1) //TODO: & add "DECOMP_" prefix
3+
void DECOMP_BOTS_LevInstColl(struct Thread* param_1)
44
{
5-
//1st param may be `int`, but is almost certainly a `struct*` of some kind
6-
//TODO
5+
short currPos[6];
6+
short prevPos[3];
7+
struct Driver* d = (struct Driver*)param_1->object;
8+
struct ScratchpadStruct* sps = (struct ScratchpadStruct*)0x1f800108;
9+
10+
//scratchpad stuff
11+
sps->ptr_mesh_info = sdata->gGT->level1->ptr_mesh_info;
12+
sps->Union.QuadBlockColl.searchFlags = 1;
13+
(*(int*)(0x1f800114)) = 0x3f; //Input1.modelID._0_2_ (this location probably has another name).
14+
(*(int*)(0x1f80012c)) = 0; //Union._20_4_ (this location probably has another name).
15+
sps->Union.QuadBlockColl.qbFlagsIgnored = 0;
16+
sps->Input1.hitRadius = 0x19; //this might be the wrong name for this location, idk.
17+
18+
//grab driver stuff
19+
currPos[0] = (short)(d->posCurr.x >> 8);
20+
currPos[1] = ((short)(d->posCurr.y >> 8)) + 0x19;
21+
currPos[2] = (short)(d->posCurr.z >> 8);
22+
prevPos[0] = (short)(d->posPrev.x >> 8);
23+
prevPos[1] = ((short)(d->posPrev.y >> 8)) + 0x19;
24+
prevPos[2] = (short)(d->posPrev.z >> 8);
25+
26+
DECOMP_COLL_FIXED_BotsSearch(currPos, prevPos, (short*)sps);
27+
28+
if (sps->boolDidTouchHitbox)
29+
{
30+
sps->Union.QuadBlockColl.searchFlags &= 0xfff7;
31+
32+
if ((sps->bspHitbox->flag & 0x80) != 0)
33+
{
34+
struct QuadBlock* qb = sps->bspHitbox->data.leaf.ptrQuadBlockArray;
35+
int iVar3 = *(int*)&qb->bbox.min[0]; //x & y concatenated, I'm confused though, it's being passed as `struct Instance*`
36+
if (iVar3 != 0)
37+
{
38+
struct MetaDataMODEL* mdm = DECOMP_COLL_LevModelMeta(qb->blockID);
39+
if (mdm != NULL)
40+
{
41+
if (mdm->LInC != NULL)
42+
{
43+
mdm->LInC((struct Instance*)iVar3, param_1, sps); //1st param doesn't make much sense to me...
44+
}
45+
}
46+
}
47+
}
48+
}
749
}
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
#include <common.h>
22

3-
void BOTS_ThTick_RevEngine() //TODO: & add "DECOMP_" prefix
3+
void DECOMP_BOTS_ThTick_RevEngine(struct Thread* botThread)
44
{
5-
//1st param may be `int`, but is almost certainly a `struct Thread*`
6-
//There may be a 2nd param, `undefined4`
7-
//There may be a 3rd param, `undefined*`
8-
//There may be a 4th param, may be `uint`
9-
//TODO
5+
struct Driver* botDriver = (struct Driver*)botThread->object;
6+
struct MaskHeadWeapon* mask = botDriver->botData.maskObj;
7+
8+
if (botDriver->botData.ai_posBackup[1] < botDriver->posCurr.y)
9+
{ //mask grabbed
10+
botDriver->posCurr.y -= ((sdata->gGT->elapsedTimeMS << 9) >> 5);
11+
12+
if (mask != NULL)
13+
{
14+
mask->pos[0] = (short)(botDriver->posCurr.x >> 8);
15+
mask->pos[1] = (short)(botDriver->posCurr.y >> 8);
16+
mask->pos[2] = (short)(botDriver->posCurr.z >> 8);
17+
}
18+
19+
VehPhysForce_TranslateMatrix(botThread, botDriver);
20+
VehFrameProc_Driving(botThread, botDriver);
21+
VehEmitter_DriverMain(botThread, botDriver);
22+
}
23+
else
24+
{ //not a mask grab
25+
if (mask != NULL)
26+
{
27+
mask->scale = 0x1000;
28+
mask->duration = 0;
29+
mask->rot[2] &= 0xfffe;
30+
}
31+
32+
botDriver->botData.maskObj = NULL;
33+
botDriver->kartState = KS_ENGINE_REVVING;
34+
botDriver->clockReceive = 0;
35+
botDriver->squishTimer = 0;
36+
37+
ThTick_SetAndExec(botThread, BOTS_ThTick_Drive);
38+
}
1039
}
Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,100 @@
11
#include <common.h>
22

3-
void BOTS_MaskGrab(int param_1) //TODO: & add "DECOMP_" prefix
3+
void DECOMP_BOTS_MaskGrab(struct Thread* botThread)
44
{
5-
//1st param may be `int`, but is almost certainly a `struct*` of some kind
6-
//TODO
7-
}
5+
int midpoint;
6+
struct NavFrame* frame;
7+
struct NavFrame* nextframe;
8+
struct Driver* bot;
9+
struct MaskHeadWeapon* mask;
10+
11+
12+
bot = botThread->object; // get object from thread
13+
frame = bot->botData.botNavFrame; // pointer to nav point
14+
nextframe = frame + 1; // pointer to next nav point after this
15+
16+
// if the next nav point is a farther address than last point
17+
if (sdata->NavPath_ptrHeader[bot->botData.botPath]->last <= nextframe)
18+
{
19+
// set next nav point to first nav point
20+
nextframe = sdata->NavPath_ptrNavFrameArray[bot->botData.botPath];
21+
}
22+
23+
bot->kartState = KS_MASK_GRABBED;
24+
25+
int idk = frame->unk[1] << 0x10;
26+
bot->botData.unk5a8 = ((idk >> 0x10) - (idk >> 0x1f) >> 1) << 8;
27+
28+
// midpointX between nav frames
29+
midpoint = (frame->pos[0] + (nextframe->pos[0] - frame->pos[0]) / 2) * 0x100;
30+
bot->botData.ai_posBackup[0] = midpoint;
31+
bot->posPrev.x = midpoint;
32+
33+
// midpointY between nav frames
34+
midpoint = (frame->pos[1] + (nextframe->pos[1] - frame->pos[1]) / 2) * 0x100;
35+
bot->botData.ai_posBackup[1] = midpoint;
36+
bot->posPrev.y = midpoint;
37+
bot->quadBlockHeight = midpoint;
38+
39+
// midpointZ between nav frames
40+
midpoint = (frame->pos[2] + (nextframe->pos[2] - frame->pos[2]) / 2) * 0x100;
41+
bot->botData.ai_posBackup[2] = midpoint;
42+
bot->posPrev.z = midpoint;
43+
44+
bot->botData.unk5bc.ai_mulDrift = 0;
45+
bot->botData.unk5bc.ai_squishCooldown = 0;
46+
bot->botData.unk5bc.unk5cc = 0;
47+
bot->botData.unk5bc.ai_speedY = 0;
48+
bot->botData.unk5bc.ai_speedLinear = 0;
49+
bot->botData.unk5bc.ai_velAxis[0] = 0;
50+
bot->botData.unk5bc.ai_velAxis[1] = 0;
51+
bot->botData.unk5bc.ai_velAxis[2] = 0;
52+
53+
// turn on 1st flag of actions flag set (means racer is on the ground)
54+
bot->actionsFlagSet |= 1;
55+
56+
bot->botData.botFlags &= 0xffffffb0;
57+
58+
bot->rotCurr.x = frame->rot[0] << 4;
59+
bot->rotCurr.y = frame->rot[1] << 4;
60+
bot->rotCurr.z = frame->rot[2] << 4;
61+
62+
bot->turbo_MeterRoomLeft = 0;
63+
bot->reserves = 0;
64+
bot->clockReceive = 0;
65+
bot->squishTimer = 0;
66+
bot->turbo_outsideTimer = 0;
67+
bot->matrixArray = 0;
68+
bot->matrixIndex = 0;
69+
70+
// turn off 7th and 20th flags of actions flag set (means ghost? racer is not in the air (20) and ? (7))
71+
bot->actionsFlagSet &= 0xfff7ffbf;
72+
73+
// if driver is not ghost
74+
if (botThread->modelIndex != 0x4b)
75+
{
76+
// enable collision for this thread
77+
botThread->flags &= 0xffffefff;
78+
}
79+
80+
// posY, plus height to be dropped from
81+
bot->posCurr.x = bot->botData.ai_posBackup[0];
82+
bot->posCurr.y = bot->botData.ai_posBackup[1] + 0x10000;
83+
bot->posCurr.z = bot->botData.ai_posBackup[2];
84+
85+
mask = VehPickupItem_MaskUseWeapon(bot, 1);
86+
87+
// Mask Object (620?)
88+
bot->botData.maskObj = mask;
89+
90+
if (mask)
91+
{
92+
mask->duration = 0x1e00;
93+
mask->rot[2] |= 1;
94+
}
95+
96+
// execute, then assign per-frame to BOTS_ThTick_RevEngine
97+
ThTick_SetAndExec(botThread, BOTS_ThTick_RevEngine);
98+
99+
return;
100+
}

0 commit comments

Comments
 (0)