From 6ef917d5d1e694642001fdd54f086c060592163f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 17 Nov 2022 17:55:27 +1000 Subject: [PATCH] Fix lifts --- src/game/propobj.c | 12 +++++++----- src/game/proptick.c | 2 +- src/game/setup.c | 3 +++ src/include/data.h | 2 ++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/game/propobj.c b/src/game/propobj.c index 987242ffb..d5024d309 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -4563,7 +4563,9 @@ s32 glassCalculateOpacity(struct coord *pos, f32 xludist, f32 opadist, f32 arg3) return opacity; } -struct prop *g_Lifts[MAX_LIFTS] = {NULL}; +struct prop *g_Lifts[MAX_LIFTS]; +s32 g_NumLifts; +u8 g_LiftnumToIndex[MAX_LIFTS]; struct hovtype g_HovTypes[] = { #if PAL @@ -4673,9 +4675,9 @@ void func0f070ca0(struct defaultobj *obj, struct geotilef *tile, u32 flags, stru void liftActivate(struct prop *prop, u8 liftnum) { - if (liftnum > 0 && liftnum <= MAX_LIFTS) { - g_Lifts[liftnum - 1] = prop; - } + g_Lifts[g_NumLifts] = prop; + g_LiftnumToIndex[liftnum] = g_NumLifts; + g_NumLifts++; } struct prop *liftFindByPad(s16 padnum) @@ -4684,7 +4686,7 @@ struct prop *liftFindByPad(s16 padnum) return NULL; } - return g_Lifts[g_Pads[padnum].liftnum - 1]; + return g_Lifts[g_LiftnumToIndex[g_Pads[padnum].liftnum]]; } f32 liftGetY(struct liftobj *lift) diff --git a/src/game/proptick.c b/src/game/proptick.c index de36accb9..466bfc26b 100644 --- a/src/game/proptick.c +++ b/src/game/proptick.c @@ -59,7 +59,7 @@ void propsTick(void) shieldhitsTick(); chraTickBg(); - for (i = 0; g_Lifts[i] != NULL; i++) { + for (i = 0; i < g_NumLifts; i++) { liftTick(g_Lifts[i]); } diff --git a/src/game/setup.c b/src/game/setup.c index 95c202322..1777e58ac 100644 --- a/src/game/setup.c +++ b/src/game/setup.c @@ -181,8 +181,11 @@ void propsReset(void) for (i = 0; i < ARRAYCOUNT(g_Lifts); i++) { g_Lifts[i] = NULL; + g_LiftnumToIndex[i] = 0; } + g_NumLifts = 0; + g_MaxWeaponSlots = 50; g_MaxAmmoCrates = 20; g_MaxDebrisSlots = 15; diff --git a/src/include/data.h b/src/include/data.h index 7dc3b5dba..78b5fb4a7 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -272,6 +272,8 @@ extern struct autogunobj *g_ThrownLaptops; extern struct beam *g_ThrownLaptopBeams; extern s32 g_MaxThrownLaptops; extern struct prop *g_Lifts[MAX_LIFTS]; +extern s32 g_NumLifts; +extern u8 g_LiftnumToIndex[MAX_LIFTS]; extern u32 g_TvCmdlist00[]; extern u32 var8006aaa0[]; extern u32 var8006aae4[];