From 42c22131cbc5a22bc2de586ce2afd2108ff296a0 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 16 Nov 2022 22:37:32 +1000 Subject: [PATCH] Improve proxy detection code --- src/game/propobj.c | 53 +++++++++++++++++++++++----------------------- src/game/setup.c | 2 ++ src/include/bss.h | 1 + 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/game/propobj.c b/src/game/propobj.c index 3e95475dd..328485730 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -78,6 +78,7 @@ #include "string.h" struct weaponobj *g_Proxies[30]; +s32 g_NumProxies; s32 g_MaxWeaponSlots; s32 g_MaxAmmoCrates; s32 g_MaxDebrisSlots; @@ -15468,11 +15469,9 @@ void weaponRegisterProxy(struct weaponobj *weapon) { s32 i; - for (i = 0; i < ARRAYCOUNT(g_Proxies); i++) { - if (g_Proxies[i] == NULL) { - g_Proxies[i] = weapon; - return; - } + if (g_NumProxies < ARRAYCOUNT(g_Proxies)) { + g_Proxies[g_NumProxies] = weapon; + g_NumProxies++; } } @@ -15482,7 +15481,8 @@ void weaponUnregisterProxy(struct weaponobj *weapon) for (i = 0; i < ARRAYCOUNT(g_Proxies); i++) { if (g_Proxies[i] == weapon) { - g_Proxies[i] = NULL; + g_Proxies[i] = g_Proxies[g_NumProxies - 1]; + g_NumProxies--; return; } } @@ -15492,25 +15492,25 @@ void coordTriggerProxies(struct coord *pos, bool arg1) { s32 i; - for (i = 0; i < ARRAYCOUNT(g_Proxies); i++) { + for (i = 0; i < g_NumProxies; i++) { struct weaponobj *weapon = g_Proxies[i]; - if (weapon && weapon->timer240 == 1) { - f32 xdiff; - f32 ydiff; - f32 zdiff; - f32 range = 250 * 250; + if (weapon->timer240 == 1) { + if (weapon->weaponnum != WEAPON_GRENADE || arg1 == true) { + f32 xdiff; + f32 ydiff; + f32 zdiff; + f32 range = 250 * 250; - if (weapon->weaponnum == WEAPON_DRAGON) { - range += range; - } + if (weapon->weaponnum == WEAPON_DRAGON) { + range += range; + } - xdiff = pos->x - weapon->base.prop->pos.x; - ydiff = pos->y - weapon->base.prop->pos.y; - zdiff = pos->z - weapon->base.prop->pos.z; + xdiff = pos->x - weapon->base.prop->pos.x; + ydiff = pos->y - weapon->base.prop->pos.y; + zdiff = pos->z - weapon->base.prop->pos.z; - if (xdiff * xdiff + ydiff * ydiff + zdiff * zdiff < range) { - if (weapon->weaponnum != WEAPON_GRENADE || arg1 == true) { + if (xdiff * xdiff + ydiff * ydiff + zdiff * zdiff < range) { weapon->timer240 = 0; } } @@ -15527,16 +15527,14 @@ void chrsTriggerProxies(void) struct chrdata *chr = &g_ChrSlots[i]; struct coord pos; - if (chr->model + if (chr->prop + && !chrIsDead(chr) && (chr->chrflags & CHRCFLAG_HIDDEN) == 0 - && chr->prop && (chr->prop->flags & PROPFLAG_ENABLED) - && !chrIsDead(chr)) { + && chr->model) { chrCalculatePosition(chr, &pos); coordTriggerProxies(&pos, true); } - - if (chr); } } @@ -18055,7 +18053,10 @@ void alarmTick(void) } countdownTimerTick(); - chrsTriggerProxies(); + + if (g_NumProxies) { + chrsTriggerProxies(); + } g_PlayersDetonatingMines = 0; } diff --git a/src/game/setup.c b/src/game/setup.c index ac81d8549..78485e88d 100644 --- a/src/game/setup.c +++ b/src/game/setup.c @@ -325,6 +325,8 @@ void setupResetProxyMines(void) for (i = 0; i < ARRAYCOUNT(g_Proxies); i++) { g_Proxies[i] = NULL; } + + g_NumProxies = 0; } s32 setupCountCommandType(u32 type) diff --git a/src/include/bss.h b/src/include/bss.h index 009937322..e6334e229 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -98,6 +98,7 @@ extern struct prop *g_InteractProp; extern s32 var8009cdac; extern s32 var8009cdb0; extern struct weaponobj *g_Proxies[30]; +extern s32 g_NumProxies; extern s32 g_MaxWeaponSlots; extern s32 g_MaxHatSlots; extern s32 g_MaxAmmoCrates;