From 8d630fd996d33c3dd7d0db803e7687076b8e2b9c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 25 Feb 2021 08:21:46 +1000 Subject: [PATCH] Attempt to decompile aibotTick --- src/game/bondeyespy.c | 2 +- src/game/bondmove.c | 2 +- src/game/chr/chr.c | 2 +- src/game/chr/chraction.c | 18 +-- src/game/game_0147d0.c | 2 +- src/game/game_0b69d0.c | 8 +- src/game/game_190260.c | 194 ++++++++++++++++++++++++++++++- src/game/prop.c | 4 +- src/include/game/chr/chr.h | 2 +- src/include/game/chr/chraction.h | 2 +- src/include/game/game_190260.h | 10 +- src/include/types.h | 4 +- 12 files changed, 219 insertions(+), 31 deletions(-) diff --git a/src/game/bondeyespy.c b/src/game/bondeyespy.c index f978cdf0d..0de21849b 100644 --- a/src/game/bondeyespy.c +++ b/src/game/bondeyespy.c @@ -2086,7 +2086,7 @@ glabel var7f1adb00 /* f0d1cf0: 8fa400e4 */ lw $a0,0xe4($sp) /* f0d1cf4: 46043002 */ mul.s $f0,$f6,$f4 /* f0d1cf8: 44050000 */ mfc1 $a1,$f0 -/* f0d1cfc: 0fc0f94e */ jal func0f03e538 +/* f0d1cfc: 0fc0f94e */ jal chrSetLookAngle /* f0d1d00: 00000000 */ nop /* f0d1d04: 3c09800a */ lui $t1,%hi(g_Vars) /* f0d1d08: 25299fc0 */ addiu $t1,$t1,%lo(g_Vars) diff --git a/src/game/bondmove.c b/src/game/bondmove.c index fa32340f6..4667accd3 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -5418,7 +5418,7 @@ void bmoveUpdateVerta(void) struct chrdata *chr = g_Vars.currentplayer->prop->chr; if (chr && chr->model) { - func0f03e538(chr, BADDEG2RAD(360 - g_Vars.currentplayer->vv_theta)); + chrSetLookAngle(chr, BADDEG2RAD(360 - g_Vars.currentplayer->vv_theta)); } } } diff --git a/src/game/chr/chr.c b/src/game/chr/chr.c index 8cdeb60f1..9c9fc44b1 100644 --- a/src/game/chr/chr.c +++ b/src/game/chr/chr.c @@ -2579,7 +2579,7 @@ struct prop *func0f020b14(struct prop *prop, struct model *model, model->chr = chr; model->unk01 = 1; chr->model = model; - func0f03e538(chr, arg4); + chrSetLookAngle(chr, arg4); modelSetAnimPlaySpeed(model, var80062968, 0); testpos.x = pos->x; diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index de018c9af..3efc1f090 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -9722,7 +9722,7 @@ void chrGoPosInitCheap(struct chrdata *chr, struct waydata *waydata, struct coor waydata->segdisttotal = sqrtf(xdiff1 * xdiff1 + zdiff1 * zdiff1); waydata->segdistdone = waydata->segdisttotal - sqrtf(xdiff2 * xdiff2 + zdiff2 * zdiff2); - func0f03e538(chr, angle); + chrSetLookAngle(chr, angle); } void chrGoPosGetCurWaypointInfoWithFlags(struct chrdata *chr, struct coord *pos, s16 *rooms, u32 *flags) @@ -10197,7 +10197,7 @@ glabel var7f1a8dac /* f0378bc: 0fc259d4 */ jal atan2f /* f0378c0: 46104381 */ sub.s $f14,$f8,$f16 /* f0378c4: 44050000 */ mfc1 $a1,$f0 -/* f0378c8: 0fc0f94e */ jal func0f03e538 +/* f0378c8: 0fc0f94e */ jal chrSetLookAngle /* f0378cc: 02002025 */ or $a0,$s0,$zero .L0f0378d0: /* f0378d0: 12000003 */ beqz $s0,.L0f0378e0 @@ -14782,7 +14782,7 @@ f32 chrGetInverseTheta(struct chrdata *chr) return func0001ae44(chr->model); } -void func0f03e538(struct chrdata *chr, f32 angle) +void chrSetLookAngle(struct chrdata *chr, f32 angle) { if (chr->aibot) { chr->aibot->unk0b0 = angle; @@ -15061,7 +15061,7 @@ glabel var7f1a8f40 /* f03e938: 46006301 */ sub.s $f12,$f12,$f0 /* f03e93c: 44056000 */ mfc1 $a1,$f12 .L0f03e940: -/* f03e940: 0fc0f94e */ jal func0f03e538 +/* f03e940: 0fc0f94e */ jal chrSetLookAngle /* f03e944: 02002025 */ or $a0,$s0,$zero /* f03e948: 24080003 */ addiu $t0,$zero,0x3 /* f03e94c: 1000001c */ b .L0f03e9c0 @@ -15082,7 +15082,7 @@ glabel var7f1a8f40 /* f03e984: 46006301 */ sub.s $f12,$f12,$f0 /* f03e988: 44056000 */ mfc1 $a1,$f12 .L0f03e98c: -/* f03e98c: 0fc0f94e */ jal func0f03e538 +/* f03e98c: 0fc0f94e */ jal chrSetLookAngle /* f03e990: 02002025 */ or $a0,$s0,$zero /* f03e994: 1000000b */ b .L0f03e9c4 /* f03e998: c7a60030 */ lwc1 $f6,0x30($sp) @@ -15095,7 +15095,7 @@ glabel var7f1a8f40 /* f03e9b0: 46006300 */ add.s $f12,$f12,$f0 /* f03e9b4: 44056000 */ mfc1 $a1,$f12 .L0f03e9b8: -/* f03e9b8: 0fc0f94e */ jal func0f03e538 +/* f03e9b8: 0fc0f94e */ jal chrSetLookAngle /* f03e9bc: 02002025 */ or $a0,$s0,$zero .L0f03e9c0: /* f03e9c0: c7a60030 */ lwc1 $f6,0x30($sp) @@ -19614,7 +19614,7 @@ void func0f0429d8(struct chrdata *chr, f32 arg1, f32 arg2) struct prop *prop = chrGetTargetProp(chr); f32 distance = atan2f(prop->pos.x - chr->prop->pos.x, prop->pos.z - chr->prop->pos.z); f32 value = func0001afe8(arg2, distance, arg1); - func0f03e538(chr, value); + chrSetLookAngle(chr, value); } GLOBAL_ASM( @@ -24382,7 +24382,7 @@ void chrTickSkJump(struct chrdata *chr) case SKJUMPSTATE_TAKEOFF: fVar6 = chrGetInverseTheta(chr); fVar5 = func0001afe8(fVar6, chr->act_skjump.angle, 0.35); - func0f03e538(chr, fVar5); + chrSetLookAngle(chr, fVar5); frame = modelGetCurAnimFrame(chr->model); if (frame >= modelGetAnimEndFrame(chr->model)) { @@ -27016,7 +27016,7 @@ bool chrMoveToPos(struct chrdata *chr, struct coord *pos, s16 *rooms, f32 angle, } chr->chrflags |= CHRCFLAG_00000001; - func0f03e538(chr, angle); + chrSetLookAngle(chr, angle); if (chr->prop->type == PROPTYPE_PLAYER) { player = g_Vars.players[propGetPlayerNum(chr->prop)]; diff --git a/src/game/game_0147d0.c b/src/game/game_0147d0.c index 3b0a59a6d..b10d17fab 100644 --- a/src/game/game_0147d0.c +++ b/src/game/game_0147d0.c @@ -279,7 +279,7 @@ void aibotAllocate(s32 chrnum, s32 aibotnum) aibot->unk2d0 = random(); aibot->unk2d4 = random() * (1.0f / U32_MAX); aibot->unk078 = 0; - aibot->unk09c_07 = 0; + aibot->cheap = false; aibot->unk050 = 0; aibot->unk09d = 0; } else { diff --git a/src/game/game_0b69d0.c b/src/game/game_0b69d0.c index 494db6da5..5b4aacb35 100644 --- a/src/game/game_0b69d0.c +++ b/src/game/game_0b69d0.c @@ -2133,7 +2133,7 @@ glabel var7f1ad5b4 /* f0b929c: 8e0d0284 */ lw $t5,0x284($s0) /* f0b92a0: 8fa50114 */ lw $a1,0x114($sp) /* f0b92a4: 8dab00bc */ lw $t3,0xbc($t5) -/* f0b92a8: 0fc0f94e */ jal func0f03e538 +/* f0b92a8: 0fc0f94e */ jal chrSetLookAngle /* f0b92ac: 8d640004 */ lw $a0,0x4($t3) /* f0b92b0: 8fa20110 */ lw $v0,0x110($sp) /* f0b92b4: 8fae0064 */ lw $t6,0x64($sp) @@ -2296,7 +2296,7 @@ glabel var7f1ad5b4 /* f0b9508: 8e180284 */ lw $t8,0x284($s0) /* f0b950c: 8fa50114 */ lw $a1,0x114($sp) /* f0b9510: 8f0800bc */ lw $t0,0xbc($t8) -/* f0b9514: 0fc0f94e */ jal func0f03e538 +/* f0b9514: 0fc0f94e */ jal chrSetLookAngle /* f0b9518: 8d040004 */ lw $a0,0x4($t0) /* f0b951c: 0fc32e31 */ jal bmove0f0cb8c4 /* f0b9520: 8e040284 */ lw $a0,0x284($s0) @@ -2942,7 +2942,7 @@ void func0f0ba190(u32 arg0) theta = (M_BADTAU - theta) * 57.304901123047f; g_Vars.bond->vv_theta = theta; - func0f03e538(g_Vars.bond->prop->chr, (360 - theta) * 0.017450513318181f); + chrSetLookAngle(g_Vars.bond->prop->chr, (360 - theta) * 0.017450513318181f); } GLOBAL_ASM( @@ -10432,7 +10432,7 @@ glabel var7f1ad710 .L0f0c27dc: /* f0c27dc: 44050000 */ mfc1 $a1,$f0 .L0f0c27e0: -/* f0c27e0: 0fc0f94e */ jal func0f03e538 +/* f0c27e0: 0fc0f94e */ jal chrSetLookAngle /* f0c27e4: 02002025 */ or $a0,$s0,$zero /* f0c27e8: 8e0f0018 */ lw $t7,0x18($s0) /* f0c27ec: 35f80001 */ ori $t8,$t7,0x1 diff --git a/src/game/game_190260.c b/src/game/game_190260.c index 2db36197c..7b24524b9 100644 --- a/src/game/game_190260.c +++ b/src/game/game_190260.c @@ -426,7 +426,7 @@ glabel mpChrReset // aibot->unk2d0 = random(); // aibot->aibot = random(); // aibot->unk078 = 0; -// aibot->unk09c_07 = 0; +// aibot->cheap = 0; // aibot->unk050 = 0; // aibot->unk09d = 0; // } @@ -1573,7 +1573,7 @@ glabel var7f1b8ec8 ); GLOBAL_ASM( -glabel func0f1918d0 +glabel aibotTick .late_rodata glabel var7f1b8ecc .word 0x40c907a9 @@ -1971,7 +1971,7 @@ glabel var7f1b8ef0 /* f191e14: 460e0000 */ add.s $f0,$f0,$f14 /* f191e18: 44050000 */ mfc1 $a1,$f0 .L0f191e1c: -/* f191e1c: 0fc0f94e */ jal func0f03e538 +/* f191e1c: 0fc0f94e */ jal chrSetLookAngle /* f191e20: 02202025 */ or $a0,$s1,$zero /* f191e24: 862c017e */ lh $t4,0x17e($s1) /* f191e28: 44809000 */ mtc1 $zero,$f18 @@ -2084,6 +2084,194 @@ glabel var7f1b8ef0 /* f191fa0: 27bd0068 */ addiu $sp,$sp,0x68 ); +// Mismatch: updateable is calculated differently +//bool aibotTick(struct prop *prop) +//{ +// struct chrdata *chr = prop->chr; +// struct aibot *aibot = chr->aibot; +// bool result = false; +// bool updateable; +// f32 oldangle; +// f32 newangle; +// f32 diffangle; +// f32 tweenangle; +// s32 i; +// +// updateable = ((prop->flags & PROPFLAG_08) && g_Vars.lvupdate240) != 0; +// +// if (aibot) { +// if (updateable && g_Vars.lvframe60 >= 145) { +// func0f194b40(chr); +// +// // Calculate cheap +// aibot->cheap = true; +// +// for (i = 0; prop->rooms[i] != -1; i++) { +// if (roomIsVisibleByAnyPlayer(prop->rooms[i]) || roomIsVisibleByAnyAibot(prop->rooms[i])) { +// aibot->cheap = false; +// break; +// } +// } +// +// // Dampen blur +// if (chr->blurdrugamount > 0) { +// if (chr->blurdrugamount > 5000) { +// chr->blurdrugamount = 5000; +// } +// +// chr->blurdrugamount -= g_Vars.lvupdate240_60 * (chr->blurnumtimesdied + 1); +// +// if (chr->blurdrugamount <= 0) { +// chr->blurdrugamount = 0; +// chr->blurnumtimesdied = 0; +// } +// } +// +// // Calculate target angle +// oldangle = chrGetInverseTheta(chr); +// +// if (chrIsDead(chr)) { +// newangle = chrGetInverseTheta(chr); +// } else if (aibot->unk044) { +// newangle = chrGetInverseTheta(chr); +// } else if (func0f191638(chr, false)) { +// struct prop *target = chrGetTargetProp(chr); +// newangle = oldangle + chrGetAngleToPos(chr, &target->pos) + aibot->unk1c0; +// } else if (chr->myaction == MA_AIBOTDOWNLOAD && g_ScenarioData.htm.unk0d4 != -1) { +// newangle = oldangle + chrGetAngleToPos(chr, &g_ScenarioData.htm.unk07c[g_ScenarioData.htm.unk0d4].prop->pos); +// } else if (chr->myaction == MA_AIBOTFOLLOW +// && aibot->followingplayernum >= 0 +// && aibot->playerdistances[aibot->followingplayernum] < 300 +// && aibot->unk1e4 >= g_Vars.lvframe60 - 60 +// && aibot->simulant->difficulty != SIMDIFF_MEAT) { +// newangle = chrGetInverseTheta(g_MpPlayerChrs[aibot->followingplayernum]); +// } else if (chr->myaction == MA_AIBOTDEFEND +// && aibot->unk1e4 >= g_Vars.lvframe60 - 60 +// && aibot->simulant->difficulty != SIMDIFF_MEAT) { +// newangle = aibot->unk098; +// } else { +// newangle = func0f03e578(chr); +// } +// +// while (newangle >= M_BADTAU) { +// newangle -= M_BADTAU; +// } +// +// while (newangle < 0) { +// newangle += M_BADTAU; +// } +// +// if (chr->blurdrugamount > 0 && !chrIsDead(chr) && aibot->unk044 == NULL) { +// newangle += chr->blurdrugamount * 0.00031410926021636f * sinf((g_Vars.lvframe60 % 120) * 0.052351541817188f); +// +// if (newangle >= M_BADTAU) { +// newangle -= M_BADTAU; +// } +// +// newangle += M_BADTAU; +// } +// +// diffangle = newangle - oldangle; +// tweenangle = g_Vars.lvupdate240freal * 0.061590049415827f; +// +// // cc8? +// if (diffangle < -M_PI) { +// diffangle += M_BADTAU; +// } else if (diffangle >= M_PI) { +// diffangle -= M_BADTAU; +// } +// +// // cfc +// if (diffangle >= 0) { +// if (diffangle >= tweenangle) { +// newangle = tweenangle; +// } else { +// newangle = oldangle + tweenangle; +// +// if (newangle >= M_BADTAU) { +// newangle -= M_BADTAU; +// } +// } +// } else { +// // d40 +// if (diffangle <= -tweenangle) { +// newangle = tweenangle; +// } else { +// newangle = oldangle - tweenangle; +// +// if (newangle < 0) { +// newangle += M_BADTAU; +// } +// } +// } +// +// aibot->unk0ac = newangle - oldangle; +// +// if (aibot->unk0ac < 0) { +// aibot->unk0ac += M_BADTAU; +// } +// +// if (aibot->unk0ac >= M_BADPI) { +// aibot->unk0ac -= M_BADTAU; +// } +// +// aibot->unk0ac /= g_Vars.lvupdate240freal; +// aibot->unk0ac *= 16.236389160156f; +// +// while (newangle >= M_BADTAU) { +// newangle -= M_BADTAU; +// } +// +// while (newangle < 0) { +// newangle += M_BADTAU; +// } +// +// chrSetLookAngle(chr, newangle); +// +// if (chr->target != -1 && !aibot->iscloserangeweapon) { +// bool left = chr->weapons_held[HAND_LEFT] ? true : false; +// bool right = chr->weapons_held[HAND_RIGHT] ? true : false; +// +// func0f03e9f4(chr, aibot->unk068, left, right, 0); +// } else { +// chrResetAimEndProperties(chr); +// } +// +// if (chr->actiontype == ACT_DIE || chr->actiontype == ACT_DEAD) { +// aibot->unk06c = 0; +// aibot->unk070 = 0; +// } else if (aibot->unk044) { +// aibot->unk06c = 0; +// aibot->unk070 = 0; +// aibot->unk1e4 = g_Vars.lvframe60; +// } else if (chr->actiontype == ACT_GOPOS && (chr->act_gopos.flags & GOPOSFLAG_20) == 0) { +// aibot->unk06c = 1; +// aibot->unk070 = 0; +// } else { +// aibot->unk06c = 0; +// aibot->unk070 = 0; +// aibot->unk1e4 = g_Vars.lvframe60; +// } +// } +// +// func0f191448(chr); +// +// result = func0f023098(prop); +// +// if (g_Vars.lvframe60 >= 145) { +// if (updateable) { +// scenarioCallback14(chr); +// } +// +// if (updateable && !chrIsDead(chr)) { +// func0f19124c(chr); +// } +// } +// } +// +// return result; +//} + f32 aibotCalculateMaxSpeed(struct chrdata *chr) { f32 speed; diff --git a/src/game/prop.c b/src/game/prop.c index 264c20dbd..ca883b55a 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -3126,7 +3126,7 @@ glabel func0f06302c /* f0634d4: 8c4f02d4 */ lw $t7,0x2d4($v0) /* f0634d8: 11e00005 */ beqz $t7,.L0f0634f0 /* f0634dc: 00000000 */ nop -/* f0634e0: 0fc64634 */ jal func0f1918d0 +/* f0634e0: 0fc64634 */ jal aibotTick /* f0634e4: 02002025 */ or $a0,$s0,$zero /* f0634e8: 10000004 */ b .L0f0634fc /* f0634ec: 00403025 */ or $a2,$v0,$zero @@ -3290,7 +3290,7 @@ glabel func0f06302c /* f063728: 8c4f02d4 */ lw $t7,0x2d4($v0) /* f06372c: 11e00005 */ beqz $t7,.L0f063744 /* f063730: 00000000 */ nop -/* f063734: 0fc64634 */ jal func0f1918d0 +/* f063734: 0fc64634 */ jal aibotTick /* f063738: 02002025 */ or $a0,$s0,$zero /* f06373c: 1000003c */ b .L0f063830 /* f063740: 00403025 */ or $a2,$v0,$zero diff --git a/src/include/game/chr/chr.h b/src/include/game/chr/chr.h index 1760a1d67..81e8034ad 100644 --- a/src/include/game/chr/chr.h +++ b/src/include/game/chr/chr.h @@ -26,7 +26,7 @@ s32 func0f022be4(struct chrdata *chr); void chrSetPoisoned(struct chrdata *chr, struct prop *poisonprop); void chrTickPoisoned(struct chrdata *chr); bool propchrDoFireslotThing(struct prop *prop); -u32 func0f023098(void); +bool func0f023098(struct prop *prop); void chrDropItems(struct chrdata *chr); void chrSetHudpieceVisible(struct chrdata *chr, bool visible); void chrDropWeapons(struct chrdata *chr); diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index f821ec36b..eefff0c70 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -265,7 +265,7 @@ void chrTickKneel(struct chrdata *chr); void chrFadeCorpse(struct chrdata *chr); void chrEnableReap(struct chrdata *chr); void chrTickTest(struct chrdata *chr); -void func0f03e538(struct chrdata *chr, f32 angle); +void chrSetLookAngle(struct chrdata *chr, f32 angle); f32 func0f03e578(struct chrdata *chr); void func0f03e5b0(struct chrdata *chr, f32 arg1); void chrResetAimEndProperties(struct chrdata *chr); diff --git a/src/include/game/game_190260.h b/src/include/game/game_190260.h index 91b17e0d6..aa08e4f97 100644 --- a/src/include/game/game_190260.h +++ b/src/include/game/game_190260.h @@ -11,11 +11,11 @@ void mpInitSimulants(void); u32 add87654321(u32 value); u32 propobjHandlePickupByAibot(struct prop *prop, struct chrdata *chr); u32 func0f190be4(void); -u32 func0f19124c(void); +void func0f19124c(struct chrdata *chr); s32 chrGuessCrouchPos(struct chrdata *chr); -u32 func0f191448(void); -u32 func0f191638(void); -u32 func0f1918d0(void); +void func0f191448(struct chrdata *chr); +bool func0f191638(struct chrdata *chr, bool arg1); +bool aibotTick(struct prop *prop); f32 aibotCalculateMaxSpeed(struct chrdata *chr); u32 func0f1921f8(void); void func0f192628(struct chrdata *chr, struct prop *arg1); @@ -29,7 +29,7 @@ u32 func0f192e90(void); u32 func0f19369c(void); s32 func0f1937a4(struct chrdata *chr, s32 arg1); u32 func0f194990(void); -u32 func0f194b40(void); +void func0f194b40(struct chrdata *chr); s32 mpObjIsSafe(struct defaultobj *obj); s32 mpchrGetWeaponNum(struct chrdata *chr); u8 mpchrGetTargetsWeaponNum(struct chrdata *chr); diff --git a/src/include/types.h b/src/include/types.h index 5cdf0365e..a9b1b4704 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -417,7 +417,7 @@ struct aibot { */ /*0x064*/ u16 unk064; - /*0x068*/ u32 unk068; + /*0x068*/ struct act_attackamount_2c *unk068; /*0x06c*/ f32 unk06c; /*0x070*/ f32 unk070; /*0x074*/ s8 unk074; @@ -439,7 +439,7 @@ struct aibot { /*0x09c*/ u8 unk09c_04 : 1; /*0x09c*/ u8 unk09c_05 : 1; /*0x09c*/ u8 unk09c_06 : 1; - /*0x09c*/ u8 unk09c_07 : 1; + /*0x09c*/ u8 cheap : 1; // True if aibot is not in any visible room /*0x09d*/ u8 unk09d; /*0x0a0*/ s32 unk0a0; /*0x0a4*/ f32 unk0a4;