diff --git a/src/game/chraction.c b/src/game/chraction.c index 6ac24a3e8..be7ec9018 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -10401,9 +10401,10 @@ void propUnsetDangerous(struct prop *prop) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < g_NumDangerousProps; i++) { if (g_DangerousProps[i] == prop) { - g_DangerousProps[i] = NULL; + g_DangerousProps[i] = g_DangerousProps[g_NumDangerousProps - 1]; + g_NumDangerousProps--; return; } } @@ -10413,11 +10414,9 @@ void propSetDangerous(struct prop *prop) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { - if (g_DangerousProps[i] == NULL) { - g_DangerousProps[i] = prop; - return; - } + if (g_NumDangerousProps < ARRAYCOUNT(g_DangerousProps)) { + g_DangerousProps[g_NumDangerousProps] = prop; + g_NumDangerousProps++; } } @@ -10475,43 +10474,22 @@ void chrTickThrowGrenade(struct chrdata *chr) } } -bool chrDetectDangerousObject(struct chrdata *chr, u8 flags) +bool chrDetectDangerousObject(struct chrdata *chr) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < g_NumDangerousProps; i++) { struct prop *prop = g_DangerousProps[i]; - bool pass = false; - if (prop) { - if ((flags & 1) && prop->weapon && - prop->weapon->weaponnum == WEAPON_GRENADE && - prop->weapon->timer240 < TICKS(480)) { - pass = true; - } - - if ((flags & 2) && prop->type == PROPTYPE_EXPLOSION) { - pass = true; - } - - if (pass && chrGetSquaredDistanceToCoord(chr, &prop->pos) < 1600) { + if (prop->type == PROPTYPE_EXPLOSION + || (prop->weapon->weaponnum == WEAPON_GRENADE && prop->weapon->timer240 < TICKS(480))) { + if (chrGetSquaredDistanceToCoord(chr, &prop->pos) < 1600) { chr->runfrompos = g_DangerousProps[i]->pos; - - if (chr->aibot) { - chr->aibot->unk064 |= 0x0004; - chr->aibot->dangerouspropnum = i; - } - return true; } } } - if (chr->aibot) { - chr->aibot->unk064 &= ~0x0004; - chr->aibot->dangerouspropnum = -1; - } - return false; } diff --git a/src/game/chraicommands.c b/src/game/chraicommands.c index d27e76e5d..a369e464a 100644 --- a/src/game/chraicommands.c +++ b/src/game/chraicommands.c @@ -1780,9 +1780,9 @@ bool aiIfCoopMode(void) return !g_Vars.normmplayerisrunning && g_MissionConfig.iscoop; } -bool aiIfDangerousObjectNearby(u32 flags) +bool aiIfDangerousObjectNearby(void) { - return chrDetectDangerousObject(g_Vars.chrdata, flags); + return chrDetectDangerousObject(g_Vars.chrdata); } bool aiIfDistanceToGunLessThan(f32 distance) diff --git a/src/game/game_00b820.c b/src/game/game_00b820.c index 1c7679398..551f06290 100644 --- a/src/game/game_00b820.c +++ b/src/game/game_00b820.c @@ -13,6 +13,7 @@ #include "types.h" struct prop *g_DangerousProps[MAX_DANGEROUSPROPS]; +s32 g_NumDangerousProps; void resetSomeStageThings(void) { @@ -22,6 +23,7 @@ void resetSomeStageThings(void) g_DangerousProps[i] = NULL; } + g_NumDangerousProps = 0; g_StageFlags = 0; } diff --git a/src/include/bss.h b/src/include/bss.h index e6334e229..5f04708f5 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -67,6 +67,7 @@ extern u8 var8009caee; extern u8 var8009caef; extern u8 var8009caf0; extern struct prop *g_DangerousProps[MAX_DANGEROUSPROPS]; +extern s32 g_NumDangerousProps; extern u16 *g_WallhitCountsPerRoom; extern s32 g_WallhitsMax; extern u32 var8009cc48; diff --git a/src/include/game/chraction.h b/src/include/game/chraction.h index c7bb7edf7..be80a084d 100644 --- a/src/include/game/chraction.h +++ b/src/include/game/chraction.h @@ -280,7 +280,7 @@ void chrSetHandFiring(struct chrdata *chr, s32 hand, bool arg2); void func0f0429d8(struct chrdata *chr, f32 arg1, f32 arg2); void propUnsetDangerous(struct prop *prop); void propSetDangerous(struct prop *prop); -bool chrDetectDangerousObject(struct chrdata *chr, u8 flags); +bool chrDetectDangerousObject(struct chrdata *chr); void chrTickBondDie(struct chrdata *chr); s32 chrIsUsingLift(struct chrdata *chr); bool chrTrySkJump(struct chrdata *chr, u8 arg1, u8 arg2, s32 arg3, u8 arg4); diff --git a/tools/ai2asm/ai2asm.py b/tools/ai2asm/ai2asm.py index 167851e53..3b4b58a45 100755 --- a/tools/ai2asm/ai2asm.py +++ b/tools/ai2asm/ai2asm.py @@ -781,7 +781,6 @@ class App(): self.emit_bnez_label(params[2]) def ai_if_dangerous_object_nearby(self, params): - self.emit('li', ['$a0', params[0]]) self.emit('jal', ['aiIfDangerousObjectNearby']) self.emit_bnez_label(params[1])