From 2e386f7a34e32c6e974e607bb0fdae193d66a1a3 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 28 May 2023 00:48:58 +1000 Subject: [PATCH] Use ARRAYCOUNT in many more places --- src/game/activemenu.c | 6 +- src/game/activemenutick.c | 2 +- src/game/bg.c | 6 +- src/game/bondgun.c | 24 +- src/game/bondmove.c | 6 +- src/game/bondview.c | 2 +- src/game/bossfile.c | 8 +- src/game/bot.c | 54 +-- src/game/botact.c | 2 +- src/game/botinv.c | 4 +- src/game/botmgr.c | 2 +- src/game/camdraw.c | 29 +- src/game/casingreset.c | 2 +- src/game/challenge.c | 72 ++-- src/game/challengeinit.c | 2 +- src/game/cheats.c | 40 +-- src/game/chr.c | 28 +- src/game/chraction.c | 32 +- src/game/chraicommands.c | 7 +- src/game/debug2.c | 2 +- src/game/dlights.c | 2 +- src/game/endscreen.c | 22 +- src/game/explosions.c | 6 +- src/game/explosionsreset.c | 2 +- src/game/explosionsstop.c | 2 +- src/game/filelist.c | 18 +- src/game/filemgr.c | 24 +- src/game/fmb.c | 2 +- src/game/game_00b820.c | 8 +- src/game/game_0b0fd0.c | 30 +- src/game/game_13c510.c | 4 +- src/game/gamefile.c | 38 +- src/game/gunfx.c | 8 +- src/game/gunfxreset.c | 4 +- src/game/invreset.c | 2 +- src/game/lv.c | 14 +- src/game/mainmenu.c | 40 +-- src/game/menu.c | 34 +- src/game/menugfx.c | 2 +- src/game/menuitem.c | 4 +- src/game/menutick.c | 22 +- src/game/mplayer/ingame.c | 2 +- src/game/mplayer/mplayer.c | 330 +++++++++--------- src/game/mplayer/scenarios.c | 4 +- src/game/mplayer/scenarios/capturethecase.inc | 30 +- src/game/mplayer/scenarios/kingofthehill.inc | 16 +- src/game/mplayer/setup.c | 32 +- src/game/music.c | 4 +- src/game/nbomb.c | 34 +- src/game/pak.c | 38 +- src/game/player.c | 2 +- src/game/playermgr.c | 21 +- src/game/playerreset.c | 4 +- src/game/prop.c | 54 +-- src/game/propobj.c | 12 +- src/game/race.c | 2 +- src/game/radar.c | 4 +- src/game/setup.c | 9 +- src/game/sight.c | 10 +- src/game/smoke.c | 16 +- src/game/sparks.c | 6 +- src/game/sparksreset.c | 2 +- src/game/sparkstick.c | 2 +- src/game/title.c | 2 +- src/game/training.c | 26 +- src/game/trainingmenus.c | 2 +- src/game/utils.c | 6 +- src/game/varsreset.c | 4 +- src/game/vtxstorereset.c | 2 +- src/game/wallhit.c | 18 +- src/game/weather.c | 2 +- src/include/bss.h | 24 +- src/include/constants.h | 93 +++-- src/include/data.h | 23 +- src/include/game/camdraw.h | 2 +- src/include/game/challenge.h | 3 +- src/include/game/game_0b0fd0.h | 4 +- src/include/game/mplayer/mplayer.h | 2 +- src/include/lib/joy.h | 1 - src/include/types.h | 59 ++-- src/lib/args.c | 2 +- src/lib/boot.c | 8 +- src/lib/crash.c | 13 +- src/lib/joy.c | 108 +++--- src/lib/memp.c | 4 +- 85 files changed, 837 insertions(+), 823 deletions(-) diff --git a/src/game/activemenu.c b/src/game/activemenu.c index 18adcc870..1c98bb432 100644 --- a/src/game/activemenu.c +++ b/src/game/activemenu.c @@ -26,7 +26,7 @@ #include "data.h" #include "types.h" -struct activemenu g_AmMenus[4]; +struct activemenu g_AmMenus[MAX_PLAYERS]; struct fontchar *g_AmFont1; struct font *g_AmFont2; s32 g_AmIndex; @@ -535,7 +535,7 @@ void amReset(void) g_AmMenus[i].favourites[g_AmMapping[index]] = WEAPON_UNARMED; index++; - for (j = 0; j < ARRAYCOUNT(g_MpSetup.weapons); j++) { + for (j = 0; j < MIN(ARRAYCOUNT(g_AmMapping), ARRAYCOUNT(g_MpSetup.weapons)); j++) { s32 weaponnum = g_MpWeapons[g_MpSetup.weapons[j]].weaponnum; switch (weaponnum) { @@ -577,7 +577,7 @@ s16 amCalculateSlotWidth(void) u32 flags; char text[32]; - for (i = 0; i != 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_AmBotCommands); i++) { amGetSlotDetails(i, &flags, text); textMeasure(&textheight, &textwidth, text, g_AmFont1, g_AmFont2, 0); diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index a9c4677ae..de1a0cd6e 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -275,7 +275,7 @@ void amTick(void) } } else { // Bot command screen, in multiplayer - if (g_AmBotCommands[g_AmMenus[g_AmIndex].slotnum] == MPBOTCOMMAND_ATTACK) { + if (g_AmBotCommands[g_AmMenus[g_AmIndex].slotnum] == AIBOTCMD_ATTACK) { amOpenPickTarget(); } else if (g_AmMenus[g_AmIndex].allbots == false) { gotonextscreen = true; diff --git a/src/game/bg.c b/src/game/bg.c index fd6d15283..07d046d74 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -2101,7 +2101,7 @@ void bgBuildTables(s32 stagenum) bgSetStageTranslationThing(g_Stages[g_StageIndex].unk14); chr0f028490(g_Stages[g_StageIndex].unk14); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.playerstats[i].scale_bg2gfx = g_Stages[g_StageIndex].unk18; } @@ -6939,7 +6939,7 @@ void bgAddToSnake(s16 fromroomnum, s16 roomnum, s16 depth, struct screenbox *box while (i != g_BgSnake.headindex) { if (item->roomnum == roomnum) { - for (j = 0; j < 5; j++) { + for (j = 0; j < ARRAYCOUNT(item->fromroomnums); j++) { if (item->fromroomnums[j] == -1) { bgExpandBox(&item->screenbox, box); item->fromroomnums[j] = fromroomnum; @@ -6972,7 +6972,7 @@ void bgAddToSnake(s16 fromroomnum, s16 roomnum, s16 depth, struct screenbox *box g_Rooms[roomnum].snakecount++; - for (i = 1; i < 5; i++) { + for (i = 1; i < ARRAYCOUNT(item->fromroomnums); i++) { item->fromroomnums[i] = -1; } diff --git a/src/game/bondgun.c b/src/game/bondgun.c index 77c112096..5782df75a 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -69,7 +69,7 @@ struct sndstate *g_CasingAudioHandles[2]; s32 var8009d0d8; u32 fill2; -struct sndstate *g_BgunAudioHandles[4]; +struct sndstate *g_BgunAudioHandles[MAX_PLAYERS]; s32 var8009d0dc; u32 fill2_2; s32 var8009d0f0[3]; @@ -94,12 +94,12 @@ f32 var8009d140; struct hand *var8009d144; s32 var8009d148; u32 var8009d14c; -struct fireslot g_Fireslots[NUM_FIRESLOTS]; +struct fireslot g_Fireslots[20]; #elif VERSION >= VERSION_NTSC_1_0 struct sndstate *g_CasingAudioHandles[2]; s32 var8009d0d8; s32 var8009d0dc; -struct sndstate *g_BgunAudioHandles[4]; +struct sndstate *g_BgunAudioHandles[MAX_PLAYERS]; s32 var8009d0f0[3]; u32 var8009d0fc; u32 var8009d100; @@ -122,7 +122,7 @@ f32 var8009d140; struct hand *var8009d144; s32 var8009d148; u32 var8009d14c; -struct fireslot g_Fireslots[NUM_FIRESLOTS]; +struct fireslot g_Fireslots[20]; #else s32 var8009d0dc; u32 var800a1800nb; @@ -150,8 +150,8 @@ s32 var8009d148; u32 var8009d14c; struct sndstate *g_CasingAudioHandles[2]; s32 var8009d0d8; -struct sndstate *g_BgunAudioHandles[4]; -struct fireslot g_Fireslots[NUM_FIRESLOTS]; +struct sndstate *g_BgunAudioHandles[MAX_PLAYERS]; +struct fireslot g_Fireslots[20]; u32 fill2[1]; #endif @@ -475,7 +475,7 @@ void bgunTickUnequippedReload(void) s32 j; for (i = 0; i < 2; i++) { - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(g_Vars.currentplayer->hands[i].gunroundsspent); j++) { u16 spent = g_Vars.currentplayer->hands[i].gunroundsspent[j]; if (spent > g_Vars.lvupdate60) { @@ -1688,7 +1688,7 @@ s32 bgunTickIncReload(struct handweaponinfo *info, s32 handnum, struct hand *han } if (hand->count60 >= TICKS(23) - || !weaponGetModelNum2(info->weaponnum) + || !weaponGetFileNum2(info->weaponnum) || !weaponHasFlag(info->weaponnum, WEAPONFLAG_00000040) || weaponHasFlag(info->weaponnum, WEAPONFLAG_00000080)) { hand->mode = HANDMODE_NONE; @@ -3117,7 +3117,7 @@ s32 bgunTickIncChangeGun(struct handweaponinfo *info, s32 handnum, struct hand * } if (hand->count60 >= delay - || !weaponGetModelNum2(info->weaponnum) + || !weaponGetFileNum2(info->weaponnum) || !weaponHasFlag(info->weaponnum, WEAPONFLAG_00000040) || weaponHasFlag(info->weaponnum, WEAPONFLAG_00000080)) { hand->mode = HANDMODE_NONE; @@ -3999,7 +3999,7 @@ void bgunTickMasterLoad(void) handfilenum = FILE_GCOMBATHANDSLOD; } - filenum = weaponGetModelNum(newweaponnum); + filenum = weaponGetFileNum(newweaponnum); if (player->gunctrl.masterloadstate != MASTERLOADSTATE_LOADED || newweaponnum != player->gunctrl.gunmemtype) { if (filenum) { @@ -6978,7 +6978,7 @@ void bgunUpdateSniperRifle(struct modeldef *modeldef, u8 *allocation) nodes[2] = modelGetPart(modeldef, MODELPART_SNIPERRIFLE_SCOPE3); nodes[3] = modelGetPart(modeldef, MODELPART_SNIPERRIFLE_SCOPE4); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(nodes); i++) { if (nodes[i]) { f32 f20 = f26 * 4.0f; mtxindex = modelFindNodeMtxIndex(nodes[i], 0); @@ -8271,7 +8271,7 @@ s8 bgunFreeFireslotWrapper(s32 slotnum) s8 bgunFreeFireslot(s32 fireslot_id) { #if VERSION >= VERSION_NTSC_1_0 - if (fireslot_id >= 0 && fireslot_id < NUM_FIRESLOTS) { + if (fireslot_id >= 0 && fireslot_id < ARRAYCOUNT(g_Fireslots)) { g_Fireslots[fireslot_id].endlvframe = -1; } #else diff --git a/src/game/bondmove.c b/src/game/bondmove.c index ccffc4773..3270b5f31 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -444,7 +444,7 @@ f32 bmoveCalculateLookahead(void) } if (sp160 > 60.0f || (flags & GEOFLAG_FLOOR1)) { - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(populated); i++) { populated[i] = false; value = (i + 1) * sp160 * 0.2f; @@ -487,7 +487,7 @@ f32 bmoveCalculateLookahead(void) for (i = 0; i < numpopulated - 1; i++) { indextoremove = -1; - for (j = 0; j < 5; j++) { + for (j = 0; j < ARRAYCOUNT(populated); j++) { if (populated[j]) { if (indextoremove < 0) { indextoremove = j; @@ -511,7 +511,7 @@ f32 bmoveCalculateLookahead(void) } } - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(populated); i++) { if (populated[i]) { result = angles[i]; break; diff --git a/src/game/bondview.c b/src/game/bondview.c index 64a35530c..1b4960976 100644 --- a/src/game/bondview.c +++ b/src/game/bondview.c @@ -1730,7 +1730,7 @@ Gfx *bviewDrawEyespyMetrics(Gfx *gdl) } #endif - for (i = 0; i < 8; i++) { + for (i = 0; i < MAX_EYESPYDARTS; i++) { if (i >= g_Vars.currentplayer->eyespydarts) { brightness2 = 0x88; } diff --git a/src/game/bossfile.c b/src/game/bossfile.c index 2b162150b..9c8e99705 100644 --- a/src/game/bossfile.c +++ b/src/game/bossfile.c @@ -119,7 +119,7 @@ void bossfileLoad(void) g_Vars.language = savebufferReadBits(&buffer, 4); - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.teamnames); i++) { savebufferReadString(&buffer, g_BossFile.teamnames[i], 1); } @@ -131,7 +131,7 @@ void bossfileLoad(void) g_BossFile.tracknum = tracknum; } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.multipletracknums); i++) { g_BossFile.multipletracknums[i] = savebufferReadBits(&buffer, 8); } @@ -167,7 +167,7 @@ void bossfileSave(void) savebufferOr(&buffer, g_BossFile.unk89, 1); savebufferOr(&buffer, g_Vars.language, 4); - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.teamnames); i++) { func0f0d55a4(&buffer, g_BossFile.teamnames[i]); } @@ -177,7 +177,7 @@ void bossfileSave(void) savebufferOr(&buffer, g_BossFile.tracknum, 8); } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.multipletracknums); i++) { savebufferOr(&buffer, g_BossFile.multipletracknums[i], 8); } diff --git a/src/game/bot.c b/src/game/bot.c index 5eb84fea5..ada7a11f1 100644 --- a/src/game/bot.c +++ b/src/game/bot.c @@ -1157,30 +1157,30 @@ void bot0f1921f8(struct chrdata *chr, f32 *move) #endif } -u32 g_MpBotCommands[NUM_MPBOTCOMMANDS] = { - L_MISC_175, // "Follow" - L_MISC_176, // "Attack" - L_MISC_177, // "Defend" - L_MISC_178, // "Hold" - L_MISC_179, // "Normal" - L_MISC_180, // "Download" - L_MISC_181, // "Get Case" - L_MISC_182, // "Tag Box" - L_MISC_209, // "Save Case" - L_MISC_210, // "Def Hill" - L_MISC_211, // "Hold Hill" - L_MISC_212, // "Get Case" - L_MISC_213, // "Pop Cap" - L_MISC_214, // "Protect" -}; - char *botGetCommandName(s32 command) { - if (command < 0 || command >= NUM_MPBOTCOMMANDS) { + static u32 names[] = { + L_MISC_175, // "Follow" + L_MISC_176, // "Attack" + L_MISC_177, // "Defend" + L_MISC_178, // "Hold" + L_MISC_179, // "Normal" + L_MISC_180, // "Download" + L_MISC_181, // "Get Case" + L_MISC_182, // "Tag Box" + L_MISC_209, // "Save Case" + L_MISC_210, // "Def Hill" + L_MISC_211, // "Hold Hill" + L_MISC_212, // "Get Case" + L_MISC_213, // "Pop Cap" + L_MISC_214, // "Protect" + }; + + if (command < 0 || command >= ARRAYCOUNT(names)) { return langGet(L_MISC_179); // "Normal" } - return langGet(g_MpBotCommands[command]); + return langGet(names[command]); } void botApplyAttack(struct chrdata *chr, struct prop *prop) @@ -1790,14 +1790,14 @@ void botScheduleReload(struct chrdata *chr, s32 handnum) struct prop *botFindPickup(struct chrdata *chr, s32 criteria) { struct aibot *aibot = chr->aibot; - s32 weaponnums[6]; - s32 scores1[6]; - s32 scores2[6]; - struct prop *weapproplist[6]; - f32 weapdistlist[6]; + s32 weaponnums[NUM_MPWEAPONSLOTS]; + s32 scores1[NUM_MPWEAPONSLOTS]; + s32 scores2[NUM_MPWEAPONSLOTS]; + struct prop *weapproplist[NUM_MPWEAPONSLOTS]; + f32 weapdistlist[NUM_MPWEAPONSLOTS]; struct prop *ammoproplist[33]; f32 ammodistlist[33]; - struct invitem *invitems[6]; + struct invitem *invitems[NUM_MPWEAPONSLOTS]; s32 i; s32 j; struct prop *prop; @@ -2326,7 +2326,7 @@ s32 botGetNumOpponentsInHill(struct chrdata *chr) { struct mpchrconfig *mpchr = g_MpAllChrConfigPtrs[mpPlayerGetIndex(chr)]; struct mpchrconfig *loopmpchr; - s32 countsperteam[8] = {0}; + s32 countsperteam[MAX_TEAMS] = {0}; s32 max = 0; s32 i; @@ -2342,7 +2342,7 @@ s32 botGetNumOpponentsInHill(struct chrdata *chr) } } - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(countsperteam); i++) { if (countsperteam[i] > max) { max = countsperteam[i]; } diff --git a/src/game/botact.c b/src/game/botact.c index 7479d14bd..a4dda58b4 100644 --- a/src/game/botact.c +++ b/src/game/botact.c @@ -444,7 +444,7 @@ bool botactFindRocketRoute(struct chrdata *chr, struct coord *frompos, struct co { struct waypoint *from = waypointFindClosestToPos(frompos, fromrooms); struct waypoint *to = waypointFindClosestToPos(topos, torooms); - struct waypoint *waypoints[6]; + struct waypoint *waypoints[MAX_CHRWAYPOINTS]; s32 numwaypoints; if (from && to) { diff --git a/src/game/botinv.c b/src/game/botinv.c index 46f8b0e0b..9092c86db 100644 --- a/src/game/botinv.c +++ b/src/game/botinv.c @@ -895,7 +895,7 @@ void botinvTick(struct chrdata *chr) if (aibot->dampensuicidesttl60 < 0) { aibot->dampensuicidesttl60 = TICKS(3600) + random() % TICKS(60); - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(aibot->suicidesbygunfunc); i++) { aibot->suicidesbygunfunc[i][0] *= 0.9f; aibot->suicidesbygunfunc[i][1] *= 0.9f; } @@ -907,7 +907,7 @@ void botinvTick(struct chrdata *chr) if (aibot->unk2a4 < 0) { aibot->unk2a4 = TICKS(600) + random() % TICKS(3000); - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(aibot->unk2a8); i++) { if (aibot->config->difficulty == BOTDIFF_MEAT) { aibot->unk2a8[i] = random() % 200 - 100; // -100 to +100 } else if (aibot->config->difficulty == BOTDIFF_EASY) { diff --git a/src/game/botmgr.c b/src/game/botmgr.c index 4c6a8116a..7c01a3719 100644 --- a/src/game/botmgr.c +++ b/src/game/botmgr.c @@ -238,7 +238,7 @@ void botmgrAllocateBot(s32 chrnum, s32 aibotnum) aibot->random1 = random(); aibot->random1ttl60 = 0; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(aibot->killsbygunfunc); i++) { aibot->killsbygunfunc[i][0] = 0.0f; aibot->killsbygunfunc[i][1] = 0.0f; diff --git a/src/game/camdraw.c b/src/game/camdraw.c index 7eeb9bdeb..58592eba4 100644 --- a/src/game/camdraw.c +++ b/src/game/camdraw.c @@ -1338,7 +1338,7 @@ void func0f14bdbc(s32 index) thing->unk094 = 0; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(thing->unk098); i++) { thing->unk098[i] = 0xff; thing->unk0b6[i] = 0xff; } @@ -1381,26 +1381,26 @@ void func0f14bec8(s32 index) pak0f11d9c4(index, NULL, thing->unk098, 0); thing->unk0f4 = 2; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(thing->unk098); i++) { if (thing->unk098[i] != 0xff) { thing->unk098[i] += 2; } } - for (i = 0, thing->unk094 = 0; i < 30; i++) { + for (i = 0, thing->unk094 = 0; i < ARRAYCOUNT(thing->unk098); i++) { if (thing->unk098[i] != 0xff) { thing->unk0b6[thing->unk094] = thing->unk098[i]; thing->unk094++; } } - for (i = thing->unk094; i < 30; i++) { + for (i = thing->unk094; i < ARRAYCOUNT(thing->unk0b6); i++) { thing->unk0b6[i] = 0xff; } if (thing->unk094); - for (i = 0; i < 30; i++); + for (i = 0; i < ARRAYCOUNT(thing->unk0b6); i++); pak0f1171b4(func0f14a5a4(), 3, 0); pak0f11d478(func0f14a5a4()); @@ -1501,7 +1501,7 @@ void func0f14c3a4(s32 index) thing->unk0dc[i] = 0; } - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(thing->unk098); i++) { thing->unk094 = 0; thing->unk098[i] = 0xff; thing->unk0b6[i] = 0xff; @@ -1567,7 +1567,7 @@ void func0f14c50c(struct var8007f8e0 *dst, struct var8007f8e0 *src, u32 line, ch dst->fileguid.fileid = src->fileguid.fileid; dst->fileguid.deviceserial = src->fileguid.deviceserial; - for (i = 0; i != 7; i++) { + for (i = 0; i < ARRAYCOUNT(dst->unk3d0); i++) { dst->unk3d0[i] = src->unk3d0[i]; } @@ -2148,11 +2148,11 @@ s32 func0f14dfc0(struct var8007f8e0 *arg0, s32 arg1, s32 arg2) len = 0; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(sp28); i++) { s32 bestvalue = 9999; s32 bestindex = -1; - for (j = 0; j < 5; j++) { + for (j = 0; j < ARRAYCOUNT(sp28); j++) { if (sp28[j] < bestvalue) { bestindex = j; bestvalue = sp28[j]; @@ -2522,13 +2522,13 @@ void func0f14ee18(u32 arg0) } // @bug? Nothing is done with tmp -void func0f14eeb0(f32 *arg0) +void func0f14eeb0(f32 arg0[7]) { struct var8007f8e0 *thing1 = func0f14a06c(-1); struct var8007f8e0 *thing2 = func0f14a06c(-2); s32 i; - for (i = 0; i < 7; i++) { + for (i = 0; i < ARRAYCOUNT(thing1->unk3d0); i++) { f32 tmp = arg0[i]; if (tmp > 1.9f) { @@ -2553,10 +2553,11 @@ void func0f14eeb0(f32 *arg0) void func0f14ef50(f32 *arg0) { + struct var8007f8e0 *thing; s32 i; - for (i = 0; i < 7; i++) { - struct var8007f8e0 *thing = func0f14a06c(-2); + for (i = 0; i < ARRAYCOUNT(thing->unk3d0); i++) { + thing = func0f14a06c(-2); arg0[i] = thing->unk3d0[i]; } @@ -3195,7 +3196,7 @@ bool pheadLoadFile(s8 device, s32 fileid, u16 serial, s32 arg3) s0->unk3f4_03 = true; s0->unk3f4_00 = true; - for (i = 0; i < 7; i++) { + for (i = 0; i < ARRAYCOUNT(s0->unk3d0); i++) { s0->unk3d0[i] = file.unk90[i] / 1000.0f; } diff --git a/src/game/casingreset.c b/src/game/casingreset.c index 41bb938f4..237b2acec 100644 --- a/src/game/casingreset.c +++ b/src/game/casingreset.c @@ -15,7 +15,7 @@ void casingsReset(void) var8009d0d8 = 0; for (i = 0; i != ARRAYCOUNT(g_BgunAudioHandles); i++) { - g_BgunAudioHandles[i] = 0; + g_BgunAudioHandles[i] = NULL; } end = g_Casings + ARRAYCOUNT(g_Casings); diff --git a/src/game/challenge.c b/src/game/challenge.c index f1e493e20..bab5c3e7d 100644 --- a/src/game/challenge.c +++ b/src/game/challenge.c @@ -26,7 +26,7 @@ u8 g_MpFeaturesUnlocked[80]; u32 g_MpChallengeIndex = 0; struct mpconfigfull *g_MpCurrentChallengeConfig = NULL; -struct challenge g_MpChallenges[NUM_CHALLENGES] = { +struct challenge g_MpChallenges[] = { { L_OPTIONS_406, MPCONFIG_CHALLENGE01 }, // "Challenge 1" { L_OPTIONS_407, MPCONFIG_CHALLENGE02 }, // "Challenge 2" { L_OPTIONS_408, MPCONFIG_CHALLENGE03 }, // "Challenge 3" @@ -89,14 +89,14 @@ void challengeDetermineUnlockedFeatures(void) s32 k; // Clear all challenge availability - for (challengeindex = 0; challengeindex < 30; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { g_MpChallenges[challengeindex].availability = 0; } numgifted = 0; // Mark challenges completed by any player - for (challengeindex = 0; challengeindex < 30; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { flag = 0; if (challengeIsCompletedByAnyPlayerWithNumPlayers(challengeindex, 1) @@ -128,7 +128,7 @@ void challengeDetermineUnlockedFeatures(void) } // Gift up to 4 challenges - for (challengeindex = 0; numgifted < 4 && challengeindex < 30; challengeindex++) { + for (challengeindex = 0; numgifted < 4 && challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if ((g_MpChallenges[challengeindex].availability & 1) == 0) { g_MpChallenges[challengeindex].availability |= 1; numgifted++; @@ -136,10 +136,10 @@ void challengeDetermineUnlockedFeatures(void) } // Now same as above, but per player - for (j = 0; j < 4; j++) { + for (j = 0; j < MAX_PLAYERS; j++) { numgifted = 0; - for (challengeindex = 0; challengeindex < 30; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { flag = 0; if (challengeIsCompletedByPlayerWithNumPlayers(j, challengeindex, 1) @@ -169,7 +169,7 @@ void challengeDetermineUnlockedFeatures(void) } // Gift up to 4 challenges - for (challengeindex = 0; numgifted < 4 && challengeindex < 30; challengeindex++) { + for (challengeindex = 0; numgifted < 4 && challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if ((g_MpChallenges[challengeindex].availability & (2 << j)) == 0) { g_MpChallenges[challengeindex].availability |= 2 << j; numgifted++; @@ -180,9 +180,9 @@ void challengeDetermineUnlockedFeatures(void) for (j = 0; j < ARRAYCOUNT(g_MpFeaturesUnlocked); j++) { flag = 0; - for (challengeindex = 0; challengeindex < 30; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if (challengeIsAvailableToAnyPlayer(challengeindex)) { - for (i = 0; i < 16; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges[challengeindex].unlockfeatures); i++) { if (g_MpChallenges[challengeindex].unlockfeatures[i] == j) { flag |= 1; } @@ -196,10 +196,10 @@ void challengeDetermineUnlockedFeatures(void) } } - for (challengeindex = 0; challengeindex < 30; challengeindex++) { - for (prev = 0; prev < 4; prev++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { + for (prev = 0; prev < MAX_PLAYERS; prev++) { if (challengeIsAvailableToPlayer(prev, challengeindex)) { - for (i = 0; i < 16; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges[challengeindex].unlockfeatures); i++) { if (g_MpChallenges[challengeindex].unlockfeatures[i] == j) { flag |= 2 << prev; } @@ -224,7 +224,7 @@ void challengeDetermineUnlockedFeatures(void) // If the ability to have 8 simulants hasn't been unlocked, limit them to 4 if (!challengeIsFeatureUnlocked(MPFEATURE_8BOTS)) { for (k = 4; k < MAX_BOTS; k++) { - if (g_MpSetup.chrslots & (1 << (4 + k))) { + if (g_MpSetup.chrslots & (1 << (MAX_PLAYERS + k))) { mpRemoveSimulant(k); } } @@ -242,7 +242,7 @@ void challengePerformSanityChecks(void) s32 i; // Reset player handicaps - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_MpSetup.chrslots & (1 << i)) { g_PlayerConfigsArray[i].handicap = 0x80; numplayers++; @@ -253,11 +253,11 @@ void challengePerformSanityChecks(void) // for this number of players g_MpSetup.chrslots &= 0x000f; - for (i = 0; i != MAX_BOTS; i++) { + for (i = 0; i < MAX_BOTS; i++) { g_BotConfigsArray[i].difficulty = g_MpSimulantDifficultiesPerNumPlayers[i][numplayers - 1]; if (g_BotConfigsArray[i].difficulty != BOTDIFF_DISABLED) { - g_MpSetup.chrslots |= 1 << (i + 4); + g_MpSetup.chrslots |= 1 << (i + MAX_PLAYERS); } } @@ -275,7 +275,7 @@ s32 challengeGetNumAvailable(void) s32 challengeindex; s32 count = 0; - for (challengeindex = 0; challengeindex != NUM_CHALLENGES; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if (challengeIsAvailableToAnyPlayer(challengeindex)) { count++; } @@ -294,7 +294,7 @@ char *challengeGetNameBySlot(s32 slot) s32 index = 0; s32 i; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { if (challengeIsAvailableToAnyPlayer(i)) { if (index == slot) { return challengeGetName(i); @@ -312,7 +312,7 @@ void challengeSetCurrentBySlot(s32 slotnum) s32 challengeindex; g_MpChallengeIndex = 0; - for (challengeindex = 0; challengeindex != NUM_CHALLENGES; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if (challengeIsAvailableToAnyPlayer(challengeindex)) { if (slotnum == 0) { g_MpChallengeIndex = challengeindex; @@ -336,7 +336,7 @@ bool challengeIsCompletedByAnyChrWithNumPlayersBySlot(s32 slot, s32 numplayers) s32 availableindex = 0; s32 i; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { if (challengeIsAvailableToAnyPlayer(i)) { if (availableindex == slot) { return challengeIsCompletedByAnyPlayerWithNumPlayers(i, numplayers); @@ -354,7 +354,7 @@ bool challengeIsCompletedByChrWithNumPlayersBySlot(s32 mpchrnum, s32 slot, s32 n s32 availableindex = 0; s32 i; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { if (challengeIsAvailableToAnyPlayer(i)) { if (availableindex == slot) { return challengeIsCompletedByPlayerWithNumPlayers(mpchrnum, i, numplayers); @@ -422,7 +422,7 @@ struct mpconfigfull *challengeLoadBySlot(s32 n, u8 *buffer, s32 len) s32 numavailable = 0; s32 challengeindex; - for (challengeindex = 0; challengeindex != NUM_CHALLENGES; challengeindex++) { + for (challengeindex = 0; challengeindex < ARRAYCOUNT(g_MpChallenges); challengeindex++) { if (challengeIsAvailableToAnyPlayer(challengeindex)) { if (numavailable == n) { return challengeLoad(challengeindex, buffer, len); @@ -467,7 +467,7 @@ s32 challengeForceUnlockSetupFeatures(struct mpsetup *setup, u8 *array, s32 len) s32 i; // Force unlock the weapons (if never held before) - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(setup->weapons); i++) { s32 featurenum = g_MpWeapons[setup->weapons[i]].unlockfeature; if (featurenum) { @@ -514,7 +514,7 @@ void challengeForceUnlockConfigFeatures(struct mpconfig *config, u8 *array, s32 s32 numplayers; s32 i; - for (i = 0; i < 8; i++) { + for (i = 0; i < MAX_BOTS; i++) { s32 simtype = mpFindBotProfile(config->simulants[i].type, BOTDIFF_NORMAL); if (simtype >= 0) { @@ -525,7 +525,7 @@ void challengeForceUnlockConfigFeatures(struct mpconfig *config, u8 *array, s32 } } - for (numplayers = 0; numplayers < 4; numplayers++) { + for (numplayers = 0; numplayers < MAX_PLAYERS; numplayers++) { simtype = mpFindBotProfile(0, config->simulants[i].difficulties[numplayers]); if (simtype >= 0) { @@ -537,7 +537,7 @@ void challengeForceUnlockConfigFeatures(struct mpconfig *config, u8 *array, s32 } } - if (config->simulants[i].mpbodynum < NUM_MPBODIES) { + if (config->simulants[i].mpbodynum < ARRAYCOUNT(g_MpBodies)) { featurenum = g_MpBodies[config->simulants[i].mpbodynum].requirefeature; if (featurenum) { @@ -545,7 +545,7 @@ void challengeForceUnlockConfigFeatures(struct mpconfig *config, u8 *array, s32 } } - if (config->simulants[i].mpheadnum < NUM_MPHEADS) { + if (config->simulants[i].mpheadnum < ARRAYCOUNT(g_MpHeads)) { featurenum = g_MpHeads[config->simulants[i].mpheadnum].requirefeature; if (featurenum) { @@ -592,7 +592,7 @@ void challengeForceUnlockBotFeatures(void) s32 index = challengeForceUnlockSetupFeatures(&g_MpSetup, g_MpFeaturesForceUnlocked, ARRAYCOUNT(g_MpFeaturesForceUnlocked)); s32 i; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BotConfigsArray); i++) { // Force unlock the simulant type s32 simtypeindex = mpFindBotProfile(g_BotConfigsArray[i].type, BOTDIFF_NORMAL); @@ -620,7 +620,7 @@ void challengeForceUnlockBotFeatures(void) } // Force unlock the simulant's body - if (g_BotConfigsArray[i].base.mpbodynum < NUM_MPBODIES) { + if (g_BotConfigsArray[i].base.mpbodynum < ARRAYCOUNT(g_MpBodies)) { s32 featurenum = g_MpBodies[g_BotConfigsArray[i].base.mpbodynum].requirefeature; if (featurenum) { @@ -629,7 +629,7 @@ void challengeForceUnlockBotFeatures(void) } // Force unlock the simulant's head - if (g_BotConfigsArray[i].base.mpheadnum < NUM_MPHEADS) { + if (g_BotConfigsArray[i].base.mpheadnum < ARRAYCOUNT(g_MpHeads)) { s32 featurenum = g_MpHeads[g_BotConfigsArray[i].base.mpheadnum].requirefeature; if (featurenum) { @@ -665,12 +665,12 @@ void challengeRemoveForceUnlocks(void) void challengeApply(void) { s32 i; - u8 buffer[458]; + u8 buffer[0x1ca]; - mpApplyConfig(challengeLoadCurrent(buffer, 458)); + mpApplyConfig(challengeLoadCurrent(buffer, 0x1ca)); mpSetLock(MPLOCKTYPE_CHALLENGE, 5); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].base.team = 0; } } @@ -722,7 +722,7 @@ s32 challengeGetAutoFocusedIndex(s32 mpchrnum) s32 challengeindex; s32 index = 0; - for (challengeindex = 29; challengeindex >= 0; challengeindex--) { + for (challengeindex = ARRAYCOUNT(g_MpChallenges) - 1; challengeindex >= 0; challengeindex--) { if (challengeIsCompletedByPlayerWithNumPlayers(mpchrnum, challengeindex, 1) || challengeIsCompletedByPlayerWithNumPlayers(mpchrnum, challengeindex, 2) || challengeIsCompletedByPlayerWithNumPlayers(mpchrnum, challengeindex, 3) || @@ -739,7 +739,7 @@ s32 challengeGetAutoFocusedIndex(s32 mpchrnum) return index; } -char *xhallengeGetName(s32 arg0, s32 challengeindex) +char *challengeGetName2(s32 playernum, s32 challengeindex) { return langGet(g_MpChallenges[challengeindex].name); } @@ -798,7 +798,7 @@ bool challengeIsCompleteForEndscreen(void) setCurrentPlayerNum(prevplayernum); if (!aborted) { - struct ranking rankings[12]; + struct ranking rankings[MAX_MPCHRS]; mpGetTeamRankings(rankings); if (rankings[0].teamnum == 0) { diff --git a/src/game/challengeinit.c b/src/game/challengeinit.c index ca005e728..e40d6284f 100644 --- a/src/game/challengeinit.c +++ b/src/game/challengeinit.c @@ -12,7 +12,7 @@ void challengesInit(void) u8 buffer[0x1ca]; s32 i; - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { g_MpChallenges[i].availability = 0; g_MpChallenges[i].completions[0] = 0; g_MpChallenges[i].completions[1] = 0; diff --git a/src/game/cheats.c b/src/game/cheats.c index e18856868..bfe910cb0 100644 --- a/src/game/cheats.c +++ b/src/game/cheats.c @@ -27,7 +27,7 @@ struct menudialogdef g_CheatsBuddiesMenuDialog; #define m #define s -struct cheat g_Cheats[NUM_CHEATS] = { +struct cheat g_Cheats[] = { { L_MPWEAPONS_075, TIME(2 m, 3 s), SOLOSTAGEINDEX_EXTRACTION, DIFF_A, CHEATFLAG_TIMED | CHEATFLAG_TRANSFERPAK }, // Hurricane Fists #if VERSION >= VERSION_NTSC_1_0 { L_MPWEAPONS_076, TIME(1 m, 40 s), SOLOSTAGEINDEX_G5BUILDING, DIFF_A, CHEATFLAG_TIMED | CHEATFLAG_TRANSFERPAK }, // Cloaking Device @@ -271,7 +271,7 @@ void cheatsReset(void) } // Set any "always on" cheats to active and properly activate all active cheats - for (cheat_id = 0; cheat_id != NUM_CHEATS; cheat_id++) { + for (cheat_id = 0; cheat_id < ARRAYCOUNT(g_Cheats); cheat_id++) { if (g_Cheats[cheat_id].flags & CHEATFLAG_ALWAYSON) { if (cheatIsUnlocked(cheat_id)) { if (cheat_id < 32) { @@ -526,8 +526,8 @@ char *cheatGetMarquee(struct menuitem *arg0) if (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION) { sprintf(g_CheatMarqueeString, "%s %s %s %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_138), // "for cheat:" &cheatname ); @@ -544,8 +544,8 @@ char *cheatGetMarquee(struct menuitem *arg0) sprintf(g_CheatMarqueeString, "%s %s %s %s %s %s %d:%02d %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_139), // "on" &difficultyname, langGet(L_MPWEAPONS_140), // "in under" @@ -609,8 +609,8 @@ char *cheatGetMarquee(struct menuitem *arg0) if (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION) { sprintf(g_CheatMarqueeString, "%s %s: %s %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_138), // "for cheat:" &cheatname ); @@ -627,8 +627,8 @@ char *cheatGetMarquee(struct menuitem *arg0) sprintf(g_CheatMarqueeString, "%s %s: %s %s %s %s %d:%02d %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_139), // "on" &difficultyname, langGet(L_MPWEAPONS_140), // "in under" @@ -688,8 +688,8 @@ char *cheatGetMarquee(struct menuitem *arg0) if (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION) { sprintf(g_CheatMarqueeString, "%s %s: %s %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_138), // "for cheat:" &cheatname ); @@ -706,8 +706,8 @@ char *cheatGetMarquee(struct menuitem *arg0) sprintf(g_CheatMarqueeString, "%s %s: %s %s %s %s %d:%02d %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_139), // "on" &difficultyname, langGet(L_MPWEAPONS_140), // "in under" @@ -757,8 +757,8 @@ char *cheatGetMarquee(struct menuitem *arg0) if (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION) { sprintf(g_StringPointer, "%s %s: %s %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_138), // "for cheat:" &cheatname ); @@ -775,8 +775,8 @@ char *cheatGetMarquee(struct menuitem *arg0) sprintf(g_StringPointer, "%s %s: %s %s %s %s %d:%02d %s %s", langGet(L_MPWEAPONS_137), // "Complete" - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name1), - langGet(g_StageNames[g_Cheats[cheat_id].stage_index].name2), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name1), + langGet(g_SoloStages[g_Cheats[cheat_id].stage_index].name2), langGet(L_MPWEAPONS_139), // "on" &difficultyname, langGet(L_MPWEAPONS_140), // "in under" @@ -817,7 +817,7 @@ s32 cheatGetByTimedStageIndex(s32 stage_index, s32 difficulty) { s32 cheat_id; - for (cheat_id = 0; cheat_id < NUM_CHEATS; cheat_id++) { + for (cheat_id = 0; cheat_id < ARRAYCOUNT(g_Cheats); cheat_id++) { if (g_Cheats[cheat_id].stage_index == stage_index && g_Cheats[cheat_id].difficulty == difficulty && (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION) == 0 && @@ -835,7 +835,7 @@ s32 cheatGetByCompletedStageIndex(s32 stage_index) { s32 cheat_id; - for (cheat_id = 0; cheat_id < NUM_CHEATS; cheat_id++) { + for (cheat_id = 0; cheat_id < ARRAYCOUNT(g_Cheats); cheat_id++) { if (g_Cheats[cheat_id].stage_index == stage_index && (g_Cheats[cheat_id].flags & CHEATFLAG_COMPLETION)) { return cheat_id; } diff --git a/src/game/chr.c b/src/game/chr.c index b17c8d685..e02fddd45 100644 --- a/src/game/chr.c +++ b/src/game/chr.c @@ -1414,7 +1414,7 @@ void chrRemove(struct prop *prop, bool free) if (g_Vars.normmplayerisrunning == false && g_MissionConfig.iscoop) { s32 i; - for (i = 0; i < g_Vars.numaibuddies && i < 4; i++) { + for (i = 0; i < g_Vars.numaibuddies && i < ARRAYCOUNT(g_Vars.aibuddies); i++) { if (g_Vars.aibuddies[i] == prop) { g_Vars.aibuddies[i] = NULL; } @@ -5530,8 +5530,8 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop vertices = gfxAllocateVertices(24); - for (i = 0; i < 6; i++) { - for (j = 0; j < 4; j++) { + for (i = 0; i < ARRAYCOUNT(sp104); i++) { + for (j = 0; j < ARRAYCOUNT(sp104[i]); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[sp104[i][j]][0]; vertices[j].y = sp180[sp104[i][j]][1]; @@ -5657,8 +5657,8 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop st4 = 512; } - for (i = 0; i < 6; i++) { - for (j = 0; j < 4; j++) { + for (i = 0; i < ARRAYCOUNT(sp104); i++) { + for (j = 0; j < ARRAYCOUNT(sp104[i]); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[sp104[i][j]][0]; vertices[j].y = sp180[sp104[i][j]][1]; @@ -5716,8 +5716,8 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop vertices = gfxAllocateVertices(30); - for (i = 0; i < 6; i++) { - for (j = 0; j < 4; j++) { + for (i = 0; i < ARRAYCOUNT(sp104); i++) { + for (j = 0; j < ARRAYCOUNT(sp104[i]); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[sp104[i][j]][0]; vertices[j].y = sp180[sp104[i][j]][1]; @@ -5796,7 +5796,7 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop colours[0].a = (s32) alpha4; } - for (j = 0; j < 8; j++) { + for (j = 0; j < ARRAYCOUNT(sp180); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[j][0]; vertices[j].y = sp180[j][1]; @@ -5957,7 +5957,7 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop vertices = gfxAllocateVertices(30); - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(sp104[side]); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[sp104[side][j]][0]; vertices[j].y = sp180[sp104[side][j]][1]; @@ -5996,7 +5996,7 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop vertices += 5; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(sp104[side]); j++) { s32 next = (j + 1) % 4; u32 stack; @@ -6076,7 +6076,7 @@ Gfx *chrRenderShieldComponent(Gfx *gdl, struct shieldhit *hit, struct prop *prop vertices += 5; } - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(sp104[side]); j++) { vertices[j] = vtxtemplate; vertices[j].x = sp180[sp104[side][3 - j]][0]; vertices[j].y = sp180[sp104[side][3 - j]][1]; @@ -6581,7 +6581,9 @@ void shieldhitsTick(void) void chrSetDrCarollImages(struct chrdata *drcaroll, s32 imageleft, s32 imageright) { - if (drcaroll && imageleft >= 0 && imageleft < 6 && imageright >= 0 && imageright < 6) { + if (drcaroll + && imageleft >= DRCAROLLIMAGE_EYESDEFAULT && imageleft <= DRCAROLLIMAGE_BINARY + && imageright >= DRCAROLLIMAGE_EYESDEFAULT && imageright <= DRCAROLLIMAGE_BINARY) { struct model *model = drcaroll->model; struct modelnode *nodes[2]; union modelrwdata *rwdata; @@ -6596,7 +6598,7 @@ void chrSetDrCarollImages(struct chrdata *drcaroll, s32 imageleft, s32 imagerigh nodes[0] = modelGetPart(model->definition, i); nodes[1] = modelGetPart(model->definition, i + 6); - for (j = 0; j < 2; j++) { + for (j = 0; j < ARRAYCOUNT(nodes); j++) { if (nodes[j]) { rwdata = modelGetNodeRwData(model, nodes[j]); diff --git a/src/game/chraction.c b/src/game/chraction.c index 22527df3e..bc4231421 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -8022,7 +8022,7 @@ void chrTickStand(struct chrdata *chr) sp6c = sp70 = chrGetInverseTheta(chr); - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(sp74); i++) { sp6c += 0.7852731347084f; if (sp6c >= M_BADTAU) { @@ -8032,14 +8032,14 @@ void chrTickStand(struct chrdata *chr) sp74[i] = func0f02e550(chr->prop, sp6c, 1000, CDTYPE_BG, 0, 1); } - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(sp44); i++) { sp44[i] = i; } - for (i = 0; i < 7; i++) { + for (i = 0; i < ARRAYCOUNT(sp44) - 1; i++) { index = i; - for (j = index + 1; j < 8; j++) { + for (j = index + 1; j < ARRAYCOUNT(sp44); j++) { if (sp74[sp44[j]] < sp74[sp44[index]]) { index = j; } @@ -9740,7 +9740,7 @@ void chrCalculateShieldHit(struct chrdata *chr, struct coord *pos, struct coord sides[4] = z; sides[5] = -z; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(sides); i++) { if (sides[i] > bestvolume) { bestvolume = sides[i]; *sideptr = i; @@ -11242,7 +11242,7 @@ void propPrintDangerous(void) osSyncPrintf("Current dangerous items:"); - for (i = 0; i < MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < ARRAYCOUNT(g_DangerousProps); i++) { struct prop *prop = g_DangerousProps[i]; if (prop) { @@ -11263,7 +11263,7 @@ void propUnsetDangerous(struct prop *prop) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < ARRAYCOUNT(g_DangerousProps); i++) { if (g_DangerousProps[i] == prop) { g_DangerousProps[i] = NULL; return; @@ -11275,7 +11275,7 @@ void propSetDangerous(struct prop *prop) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < ARRAYCOUNT(g_DangerousProps); i++) { if (g_DangerousProps[i] == NULL) { g_DangerousProps[i] = prop; return; @@ -11343,7 +11343,7 @@ bool chrDetectDangerousObject(struct chrdata *chr, u8 flags) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < ARRAYCOUNT(g_DangerousProps); i++) { struct prop *prop = g_DangerousProps[i]; bool pass = false; @@ -15902,7 +15902,7 @@ void rebuildTeams(void) struct chrdata *chr; u8 teammasks[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; - for (team = 0; team < 8; team++) { + for (team = 0; team < ARRAYCOUNT(teammasks); team++) { if (team != 0) { g_TeamList[team - 1] = index; } @@ -15919,7 +15919,7 @@ void rebuildTeams(void) g_TeamList[index] = -2; index++; - if (index >= 264) { + if (index >= (MAX_CHRSPERTEAM + 1) * MAX_TEAMS) { break; } } @@ -15942,7 +15942,7 @@ void rebuildSquadrons(void) s32 squadron; s32 i; - for (squadron = 0; squadron < 16; squadron++) { + for (squadron = 0; squadron < MAX_SQUADRONS; squadron++) { if (squadron != 0) { g_SquadronList[squadron - 1] = index; } @@ -15961,7 +15961,7 @@ void rebuildSquadrons(void) g_SquadronList[index] = -2; index++; - if (index >= 272) { + if (index >= (MAX_CHRSPERSQUADRON + 1) * MAX_SQUADRONS) { break; } } @@ -15972,7 +15972,7 @@ s16 *teamGetChrIds(s32 team_id) s32 i; u8 lookup[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; - for (i = 0; i != MAX_TEAMS; i++) { + for (i = 0; i < MAX_TEAMS; i++) { if (lookup[i] == team_id) { team_id = i; break; @@ -16007,7 +16007,7 @@ void audioMarkAsRecentlyPlayed(s16 audioid) { g_RecentQuipsPlayed[g_RecentQuipsIndex++] = audioid; - if (g_RecentQuipsIndex > 4) { + if (g_RecentQuipsIndex >= ARRAYCOUNT(g_RecentQuipsPlayed)) { g_RecentQuipsIndex = 0; } } @@ -16016,7 +16016,7 @@ bool audioWasNotPlayedRecently(s16 audioid) { u8 i; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_RecentQuipsPlayed); i++) { if (g_RecentQuipsPlayed[i] == audioid) { return false; } diff --git a/src/game/chraicommands.c b/src/game/chraicommands.c index e9918a784..f452c035c 100644 --- a/src/game/chraicommands.c +++ b/src/game/chraicommands.c @@ -4784,9 +4784,10 @@ bool aiSetObjImage(void) struct singlemonitorobj *sm = (struct singlemonitorobj *) obj; tvscreenSetImageByNum(&sm->screen, cmd[4]); } else if (obj->type == OBJTYPE_MULTIMONITOR) { + struct multimonitorobj *mm = (struct multimonitorobj *) obj; u8 slot = cmd[3]; - if (slot < 4) { - struct multimonitorobj *mm = (struct multimonitorobj *) obj; + + if (slot < ARRAYCOUNT(mm->screens)) { tvscreenSetImageByNum(&mm->screens[slot], cmd[4]); } } @@ -9041,7 +9042,7 @@ bool aiSayQuip(void) audioid = 0; // 92c - for (i = 1; i < 4; i++) { + for (i = 1; i < ARRAYCOUNT(g_GuardQuipBank[row]); i++) { if (audioWasNotPlayedRecently(g_GuardQuipBank[row][i]) && audioWasNotPlayedRecently(bank[row][i])) { audioid = bank[row][i]; diff --git a/src/game/debug2.c b/src/game/debug2.c index ccb4747ae..e4f545ae5 100644 --- a/src/game/debug2.c +++ b/src/game/debug2.c @@ -480,7 +480,7 @@ void debugUpdateMenu(void) if (g_DebugCurMenu == DEBUGMENU_MAIN) { dmenuSetMenu(g_DebugMenuLabels, g_DebugMenuPositions, g_DebugMenuOffsets); } else if (g_DebugCurMenu == DEBUGMENU_CUTSCENE) { - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_DebugCutsceneLabelPtrs); i++) { g_DebugCutsceneLabelPtrs[i] = g_DebugCutsceneLabelBuffers[i]; } diff --git a/src/game/dlights.c b/src/game/dlights.c index 2264c1366..2c383f450 100644 --- a/src/game/dlights.c +++ b/src/game/dlights.c @@ -223,7 +223,7 @@ bool lightGetBboxCentre(s32 roomnum, u32 lightnum, struct coord *pos) pos->y = 0; pos->z = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(light->bbox); i++) { pos->x += light->bbox[i].x; pos->y += light->bbox[i].y; pos->z += light->bbox[i].z; diff --git a/src/game/endscreen.c b/src/game/endscreen.c index 2c8e88058..9652e14b4 100644 --- a/src/game/endscreen.c +++ b/src/game/endscreen.c @@ -105,7 +105,7 @@ char *endscreenMenuTitleRetryMission(struct menudialogdef *dialogdef) } prefix = langGet(L_OPTIONS_296); // "Retry" - name = langGet(g_StageNames[g_MissionConfig.stageindex].name3); + name = langGet(g_SoloStages[g_MissionConfig.stageindex].name3); sprintf(g_StringPointer, "%s: %s\n", prefix, name); @@ -122,7 +122,7 @@ char *endscreenMenuTitleNextMission(struct menudialogdef *dialogdef) } prefix = langGet(L_OPTIONS_297); // "Next Mission" - name = langGet(g_StageNames[g_MissionConfig.stageindex].name3); + name = langGet(g_SoloStages[g_MissionConfig.stageindex].name3); sprintf(g_StringPointer, "%s: %s\n", prefix, name); @@ -133,7 +133,7 @@ MenuItemHandlerResult endscreenHandleReplayPreviousMission(s32 operation, struct { if (operation == MENUOP_SET) { g_MissionConfig.stageindex--; - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; } return menuhandlerAcceptMission(operation, NULL, data); @@ -374,11 +374,11 @@ char *endscreenMenuTitleStageCompleted(struct menuitem *item) { #if VERSION >= VERSION_NTSC_1_0 sprintf(g_StringPointer, "%s: %s\n", - langGet(g_StageNames[g_Menus[g_MpPlayerNum].endscreen.stageindex].name3), + langGet(g_SoloStages[g_Menus[g_MpPlayerNum].endscreen.stageindex].name3), langGet(L_OPTIONS_276)); // "Completed" #else sprintf(g_StringPointer, "%s: %s\n", - langGet(g_StageNames[g_MissionConfig.stageindex].name3), + langGet(g_SoloStages[g_MissionConfig.stageindex].name3), langGet(L_OPTIONS_276)); // "Completed" #endif @@ -388,7 +388,7 @@ char *endscreenMenuTitleStageCompleted(struct menuitem *item) #if VERSION >= VERSION_NTSC_1_0 char *endscreenMenuTextCurrentStageName3(struct menuitem *item) { - char *name = langGet(g_StageNames[g_MissionConfig.stageindex].name3); + char *name = langGet(g_SoloStages[g_MissionConfig.stageindex].name3); sprintf(g_StringPointer, "%s\n", name); return g_StringPointer; @@ -398,7 +398,7 @@ char *endscreenMenuTextCurrentStageName3(struct menuitem *item) char *endscreenMenuTitleStageFailed(struct menuitem *item) { sprintf(g_StringPointer, "%s: %s\n", - langGet(g_StageNames[g_MissionConfig.stageindex].name3), + langGet(g_SoloStages[g_MissionConfig.stageindex].name3), langGet(L_OPTIONS_277)); // "Failed" return g_StringPointer; @@ -427,7 +427,7 @@ struct menudialogdef *endscreenAdvance(void) #endif g_MissionConfig.stageindex++; - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; return &g_NextMissionMenuDialog; } @@ -451,7 +451,7 @@ void endscreen0f10d770(void) MenuItemHandlerResult endscreenHandleReplayLastLevel(s32 operation, struct menuitem *item, union handlerdata *data) { if (operation == MENUOP_SET) { - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; return menuhandlerAcceptMission(operation, NULL, data); } @@ -621,7 +621,7 @@ void endscreenContinue(s32 context) } else { // Commit to starting next stage g_MissionConfig.stageindex++; - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; titleSetNextStage(g_MissionConfig.stagenum); @@ -730,7 +730,7 @@ MenuDialogHandlerResult endscreenHandle2PCompleted(s32 operation, struct menudia menuPopDialog(); } else { g_MissionConfig.stageindex++; - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; titleSetNextStage(g_MissionConfig.stagenum); lvSetDifficulty(g_MissionConfig.difficulty); diff --git a/src/game/explosions.c b/src/game/explosions.c index 275710270..5ec84b453 100644 --- a/src/game/explosions.c +++ b/src/game/explosions.c @@ -38,7 +38,7 @@ u32 var8007e4ac = 0x0000004b; u32 var8007e4b0 = 0x000001e0; u32 var8007e4b4 = 0x000000a8; -struct explosiontype g_ExplosionTypes[NUM_EXPLOSIONTYPES] = { +struct explosiontype g_ExplosionTypes[] = { // rangeh // | rangev // | | changerateh @@ -217,7 +217,7 @@ void explosionAlertChrs(f32 *radius, struct coord *noisepos) struct explosiontype *type = &g_ExplosionTypes[0]; s32 i; - for (i = 0; i != NUM_EXPLOSIONTYPES - 1; i++) { + for (i = 0; i != ARRAYCOUNT(g_ExplosionTypes) - 1; i++) { type->rangeh = 80; type->rangev = 60; type->changerateh = 15; @@ -330,7 +330,7 @@ bool explosionCreate(struct prop *sourceprop, struct coord *exppos, s16 *exproom expprop->pos.y = exppos->y; expprop->pos.z = exppos->z; - for (i = 0; exprooms[i] != -1 && i < 7; i++) { + for (i = 0; exprooms[i] != -1 && i < ARRAYCOUNT(expprop->rooms) - 1; i++) { expprop->rooms[i] = exprooms[i]; roomFlashLighting(exprooms[i], g_ExplosionTypes[type].rangeh, 255); diff --git a/src/game/explosionsreset.c b/src/game/explosionsreset.c index 9c4212329..666f099ca 100644 --- a/src/game/explosionsreset.c +++ b/src/game/explosionsreset.c @@ -14,7 +14,7 @@ void explosionsReset(void) g_ExplosionShakeIntensityTimer = 0; g_ExplosionDamageTxScale = 1; - g_MaxExplosions = 6; + g_MaxExplosions = MAX_EXPLOSIONS; if (g_Vars.stagenum >= STAGE_TITLE) { g_MaxExplosions = 0; diff --git a/src/game/explosionsstop.c b/src/game/explosionsstop.c index ccc148415..f23ad575b 100644 --- a/src/game/explosionsstop.c +++ b/src/game/explosionsstop.c @@ -14,7 +14,7 @@ void explosionsStop(void) viShake(0); if (g_Explosions) { - for (i = 0; i < 6; i++) { + for (i = 0; i < MAX_EXPLOSIONS; i++) { if (g_Explosions[i].prop) { propDelist(g_Explosions[i].prop); propDisable(g_Explosions[i].prop); diff --git a/src/game/filelist.c b/src/game/filelist.c index fef5f2a4d..bdeebcc0a 100644 --- a/src/game/filelist.c +++ b/src/game/filelist.c @@ -24,7 +24,7 @@ s32 var800a2330[5]; -struct filelist *g_FileLists[] = { NULL, NULL, NULL, NULL }; +struct filelist *g_FileLists[MAX_PLAYERS] = { NULL }; bool var80075bd0[] = { true, true, true, true }; bool var80075be0[] = { false, false, false, false }; u32 var80075bf0 = false; @@ -38,7 +38,7 @@ void func0f110bf8(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_FileLists); i++) { if (g_FileLists[i] != NULL) { memaFree(g_FileLists[i], align16(sizeof(struct filelist))); g_FileLists[i] = NULL; @@ -71,7 +71,7 @@ s32 filelistFindOrCreate(u8 filetype) s32 bestindex = -1; s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_FileLists); i++) { if (g_FileLists[i]) { if (g_FileLists[i]->filetype == filetype) { return i; @@ -106,7 +106,7 @@ void filelistsTick(void) static bool var80075bf4 = false; if (!var80075bf4) { - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(var800a2330); i++) { var800a2330[i] = -1; } @@ -114,14 +114,14 @@ void filelistsTick(void) } #if VERSION >= VERSION_NTSC_1_0 - for (i = 0, updateall = false; i < 5; i++) { + for (i = 0, updateall = false; i < ARRAYCOUNT(var800a2330); i++) { if (pak0f1167d8(i) && var800a2330[i] != pakGetUnk264(i)) { updateall = true; var800a2330[i] = pakGetUnk264(i); } } #else - for (i = 0, updateall = false; i < 5; i++) { + for (i = 0, updateall = false; i < ARRAYCOUNT(var800a2330); i++) { s32 tmp = pakGetUnk264(i); pak0f11698c(i); @@ -137,7 +137,7 @@ void filelistsTick(void) } #endif - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_FileLists); i++) { if (g_FileLists[i] != NULL) { g_FileLists[i]->updatedthisframe = false; @@ -163,7 +163,7 @@ void filelistsTick(void) } } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(var80075bd0); i++) { var80075bd0[i] = false; } } @@ -203,7 +203,7 @@ void filelistUpdate(struct filelist *list) list->numdevices = 0; // Iterating in display order (game pak then controller paks) - for (i = 0, len = 0; i < 5; i++) { + for (i = 0, len = 0; i < ARRAYCOUNT(dis2dev); i++) { list->unk305[dis2dev[i]] = 0; list->devicestartindexes[i] = -1; diff --git a/src/game/filemgr.c b/src/game/filemgr.c index dc062af5e..43566b180 100644 --- a/src/game/filemgr.c +++ b/src/game/filemgr.c @@ -25,7 +25,7 @@ struct fileguid g_FilemgrFileToCopy; struct fileguid var800a21e8; #if VERSION >= VERSION_JPN_FINAL -struct fileguid g_FilemgrFileToDelete[4]; +struct fileguid g_FilemgrFileToDelete[MAX_PLAYERS]; #else struct fileguid g_FilemgrFileToDelete; #endif @@ -669,7 +669,7 @@ void filemgrEraseCorruptFile(void) pakDeleteFile(device, g_Menus[g_MpPlayerNum].fm.fileid); } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_FileLists); i++) { if (g_FileLists[i]) { g_FileLists[i]->timeuntilupdate = 1; } @@ -986,7 +986,7 @@ void filemgrDeleteCurrentFile(void) filemgrPushErrorDialog(FILEERROR_DELETEFAILED); } else { // If deleting a loaded MP player, reset them to default - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_FilemgrFileToDelete[g_MpPlayerNum].fileid == g_PlayerConfigsArray[i].fileguid.fileid && g_FilemgrFileToDelete[g_MpPlayerNum].deviceserial == g_PlayerConfigsArray[i].fileguid.deviceserial) { mpPlayerSetDefaults(i, true); @@ -1013,7 +1013,7 @@ void filemgrDeleteCurrentFile(void) filemgrPushErrorDialog(FILEERROR_DELETEFAILED); } else { // If deleting a loaded MP player, reset them to default - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_FilemgrFileToDelete.fileid == g_PlayerConfigsArray[i].fileguid.fileid && g_FilemgrFileToDelete.deviceserial == g_PlayerConfigsArray[i].fileguid.deviceserial) { mpPlayerSetDefaults(i, true); @@ -1850,7 +1850,7 @@ bool filemgrIsFileInUse(struct filelistfile *file) } // JPN adds this loop - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (i != g_MpPlayerNum && g_Menus[i].curdialog && g_Menus[i].curdialog->definition == &g_FilemgrConfirmDeleteMenuDialog @@ -1860,7 +1860,7 @@ bool filemgrIsFileInUse(struct filelistfile *file) } } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if ((g_MpSetup.chrslots & (1 << i)) && g_PlayerConfigsArray[i].fileguid.fileid == file->fileid && g_PlayerConfigsArray[i].fileguid.deviceserial == file->deviceserial) { @@ -1998,7 +1998,7 @@ bool filemgrIsFileInUse(struct filelistfile *file) return true; } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if ((g_MpSetup.chrslots & (1 << i)) && g_PlayerConfigsArray[i].fileguid.fileid == file->fileid && g_PlayerConfigsArray[i].fileguid.deviceserial == file->deviceserial) { @@ -2436,7 +2436,7 @@ MenuDialogHandlerResult pakChoosePakMenuDialog(s32 operation, struct menudialogd if (g_Vars.stagenum != STAGE_BOOTPAKMENU) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_Menus[g_MpPlayerNum].fm.unke24 & (1 << i)) { g_Vars.unk0004e4 &= 0xfff0; g_Vars.unk0004e4 |= 0x0008; @@ -2461,7 +2461,7 @@ MenuDialogHandlerResult pakChoosePakMenuDialog(s32 operation, struct menudialogd { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_Menus[g_MpPlayerNum].fm.unke24 & (1 << i)) { pak0f1169c8(i, STAGE_BOOTPAKMENU == g_Vars.stagenum); } @@ -2677,8 +2677,8 @@ MenuItemHandlerResult filemgrChooseAgentListMenuHandler(s32 operation, struct me if (stage > 0) { sprintf(buffer, "%s %s", - langGet(g_StageNames[stage - 1].name1), - langGet(g_StageNames[stage - 1].name2)); + langGet(g_SoloStages[stage - 1].name1), + langGet(g_SoloStages[stage - 1].name2)); } else { // "New Recruit" strcpy(buffer, langGet(L_OPTIONS_404)); @@ -2773,7 +2773,7 @@ MenuDialogHandlerResult filemgrMainMenuDialog(s32 operation, struct menudialogde mpInit(); // Set MP player names to "Player 1" through 4 if blank - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_PlayerConfigsArray[i].base.name[0] == '\0') { sprintf(g_PlayerConfigsArray[i].base.name, "%s %d\n", langGet(L_MISC_437), i + 1); } diff --git a/src/game/fmb.c b/src/game/fmb.c index 76538943d..2fe4c2c05 100644 --- a/src/game/fmb.c +++ b/src/game/fmb.c @@ -72,7 +72,7 @@ void fmbReset(void) } else { g_FileState = FILESTATE_SELECTED; - for (i = 0; i != 6; i++) { + for (i = 0; i != MAX_MPPLAYERCONFIGS; i++) { mpPlayerSetDefaults(i, true); } diff --git a/src/game/game_00b820.c b/src/game/game_00b820.c index b03452350..222b1df6f 100644 --- a/src/game/game_00b820.c +++ b/src/game/game_00b820.c @@ -12,13 +12,13 @@ #include "data.h" #include "types.h" -struct prop *g_DangerousProps[MAX_DANGEROUSPROPS]; +struct prop *g_DangerousProps[12]; void resetSomeStageThings(void) { s32 i; - for (i = 0; i != MAX_DANGEROUSPROPS; i++) { + for (i = 0; i < ARRAYCOUNT(g_DangerousProps); i++) { g_DangerousProps[i] = NULL; } @@ -123,8 +123,8 @@ void stageAllocateBgChrs(void) } } - g_TeamList = mempAlloc(0x210, MEMPOOL_STAGE); - g_SquadronList = mempAlloc(0x220, MEMPOOL_STAGE); + g_TeamList = mempAlloc((MAX_CHRSPERTEAM + 1) * MAX_TEAMS * sizeof(s16), MEMPOOL_STAGE); + g_SquadronList = mempAlloc((MAX_CHRSPERSQUADRON + 1) * MAX_SQUADRONS * sizeof(s16), MEMPOOL_STAGE); } void stageLoadAllAilistModels(void) diff --git a/src/game/game_0b0fd0.c b/src/game/game_0b0fd0.c index 48dc3a4cd..49c7bd777 100644 --- a/src/game/game_0b0fd0.c +++ b/src/game/game_0b0fd0.c @@ -220,9 +220,15 @@ void currentPlayerZoomOut(f32 fovpersec) s32 index = -1; switch (bgunGetWeaponNum2(0)) { - case WEAPON_SNIPERRIFLE: index = 0; break; - case WEAPON_FARSIGHT: index = 1; break; - case WEAPON_HORIZONSCANNER: index = 2; break; + case WEAPON_SNIPERRIFLE: + index = 0; + break; + case WEAPON_FARSIGHT: + index = 1; + break; + case WEAPON_HORIZONSCANNER: + index = 2; + break; } if (index >= 0) { @@ -245,9 +251,15 @@ void currentPlayerZoomIn(f32 fovpersec) s32 index = -1; switch (bgunGetWeaponNum2(0)) { - case WEAPON_SNIPERRIFLE: index = 0; break; - case WEAPON_FARSIGHT: index = 1; break; - case WEAPON_HORIZONSCANNER: index = 2; break; + case WEAPON_SNIPERRIFLE: + index = 0; + break; + case WEAPON_FARSIGHT: + index = 1; + break; + case WEAPON_HORIZONSCANNER: + index = 2; + break; } if (index >= 0) { @@ -371,7 +383,7 @@ void currentPlayerSetDeviceActive(s32 weaponnum, bool active) } } -u16 weaponGetModelNum(s32 weaponnum) +u16 weaponGetFileNum(s32 weaponnum) { struct weapon *weapon = NULL; @@ -390,9 +402,9 @@ u16 weaponGetModelNum(s32 weaponnum) return 0; } -u16 weaponGetModelNum2(s32 weaponnum) +u16 weaponGetFileNum2(s32 weaponnum) { - return weaponGetModelNum(weaponnum); + return weaponGetFileNum(weaponnum); } void gsetPopulateFromCurrentPlayer(s32 handnum, struct gset *gset) diff --git a/src/game/game_13c510.c b/src/game/game_13c510.c index 87759add0..1360b5ed6 100644 --- a/src/game/game_13c510.c +++ b/src/game/game_13c510.c @@ -155,7 +155,7 @@ void artifactsCalculateGlaresForRoom(s32 roomnum) origin.y = 0.0f; origin.z = 0.0f; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(roomlights[i].bbox); j++) { origin.x += roomlights[i].bbox[j].x; origin.y += roomlights[i].bbox[j].y; origin.z += roomlights[i].bbox[j].z; @@ -277,7 +277,7 @@ void artifactsCalculateGlaresForRoom(s32 roomnum) } if (s1[i * 3 + 1] > 0) { - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(roomlights[i].bbox); j++) { spec.x = origin.x + (roomlights[i].bbox[j].x - origin.x) * 0.6f; spec.y = origin.y + (roomlights[i].bbox[j].y - origin.y) * 0.6f; spec.z = origin.z + (roomlights[i].bbox[j].z - origin.z) * 0.6f; diff --git a/src/game/gamefile.c b/src/game/gamefile.c index 133a8c5dc..5061e77d9 100644 --- a/src/game/gamefile.c +++ b/src/game/gamefile.c @@ -231,8 +231,8 @@ void gamefileLoadDefaults(struct gamefile *file) } } - for (i = 0; i < 30; i++) { - for (j = 1; j != 5; j++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j < MAX_PLAYERS + 1; j++) { challengeSetCompletedByAnyPlayerWithNumPlayers(i, j, false); } } @@ -313,32 +313,32 @@ s32 gamefileLoad(s32 device) optionsSetControlMode(p1index, savebufferReadBits(&buffer, 3)); optionsSetControlMode(p2index, savebufferReadBits(&buffer, 3)); - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.flags); i++) { g_GameFile.flags[i] = savebufferReadBits(&buffer, 8); } g_GameFile.unk1e = savebufferReadBits(&buffer, 16); - for (i = 0; i < NUM_SOLOSTAGES; i++) { - for (j = 0; j < 3; j++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.besttimes); i++) { + for (j = 0; j < ARRAYCOUNT(g_GameFile.besttimes[i]); j++) { g_GameFile.besttimes[i][j] = savebufferReadBits(&buffer, 12); } } - for (i = 0; i < 30; i++) { - for (j = 1; j < 5; j++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j < MAX_PLAYERS + 1; j++) { challengeSetCompletedByAnyPlayerWithNumPlayers(i, j, savebufferReadBits(&buffer, 1)); } } challengeDetermineUnlockedFeatures(); - for (i = 0; i < 3; i++) { - g_GameFile.coopcompletions[i] = savebufferReadBits(&buffer, 21); + for (i = 0; i < ARRAYCOUNT(g_GameFile.coopcompletions); i++) { + g_GameFile.coopcompletions[i] = savebufferReadBits(&buffer, NUM_SOLOSTAGES); } - for (i = 0; i < 9; i++) { - s32 numbits = i == 8 ? 2 : 8; + for (i = 0; i < ARRAYCOUNT(g_GameFile.firingrangescores); i++) { + s32 numbits = i == ARRAYCOUNT(g_GameFile.firingrangescores) - 1 ? 2 : 8; g_GameFile.firingrangescores[i] = savebufferReadBits(&buffer, numbits); } @@ -482,29 +482,29 @@ s32 gamefileSave(s32 device, s32 fileid, u16 deviceserial) savebufferOr(&buffer, optionsGetControlMode(p1index), 3); savebufferOr(&buffer, optionsGetControlMode(p2index), 3); - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.flags); i++) { savebufferOr(&buffer, g_GameFile.flags[i], 8); } savebufferOr(&buffer, g_GameFile.unk1e, 16); - for (i = 0; i < NUM_SOLOSTAGES; i++) { - for (j = 0; j < 3; j++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.besttimes); i++) { + for (j = 0; j < ARRAYCOUNT(g_GameFile.besttimes[i]); j++) { savebufferOr(&buffer, g_GameFile.besttimes[i][j], 12); } } - for (i = 0; i < 30; i++) { - for (j = 1; j < 5; j++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j < MAX_PLAYERS + 1; j++) { savebufferOr(&buffer, challengeIsCompletedByAnyPlayerWithNumPlayers(i, j), 1); } } - for (i = 0; i < 3; i++) { - savebufferOr(&buffer, g_GameFile.coopcompletions[i], 21); + for (i = 0; i < ARRAYCOUNT(g_GameFile.coopcompletions); i++) { + savebufferOr(&buffer, g_GameFile.coopcompletions[i], NUM_SOLOSTAGES); } - for (i = 0; i < 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.firingrangescores); i++) { savebufferOr(&buffer, g_GameFile.firingrangescores[i], i == 8 ? 2 : 8); } diff --git a/src/game/gunfx.c b/src/game/gunfx.c index fe2e68646..0fded7300 100644 --- a/src/game/gunfx.c +++ b/src/game/gunfx.c @@ -22,7 +22,7 @@ struct casing g_Casings[20]; struct boltbeam g_BoltBeams[8]; -struct lasersight g_LaserSights[4]; +struct lasersight g_LaserSights[MAX_PLAYERS]; void beamCreate(struct beam *beam, s32 weaponnum, struct coord *from, struct coord *to) { @@ -2132,7 +2132,7 @@ void boltbeamsTick(void) { s32 i; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BoltBeams); i++) { if (g_BoltBeams[i].unk00 != -1 && g_BoltBeams[i].tickmode == BOLTBEAMTICKMODE_AUTOMATIC) { f32 length = sqrtf( (g_BoltBeams[i].tailpos.f[0] - g_BoltBeams[i].headpos.f[0]) * (g_BoltBeams[i].tailpos.f[0] - g_BoltBeams[i].headpos.f[0]) + @@ -2243,7 +2243,7 @@ Gfx *lasersightRenderDot(Gfx *gdl) gSPMatrix(gdl++, osVirtualToPhysical(mtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_LaserSights); i++) { if (g_LaserSights[i].id != -1) { struct coord pos; struct coord rot; @@ -2429,7 +2429,7 @@ Gfx *lasersightRenderBeam(Gfx *gdl) gSPMatrix(gdl++, osVirtualToPhysical(mtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_LaserSights); i++) { if (g_LaserSights[i].id != -1) { Col *colours; struct coord spcc; diff --git a/src/game/gunfxreset.c b/src/game/gunfxreset.c index ab0ae527b..efa506cae 100644 --- a/src/game/gunfxreset.c +++ b/src/game/gunfxreset.c @@ -16,7 +16,7 @@ void boltbeamsReset(void) { s32 i; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BoltBeams); i++) { g_BoltBeams[i].unk00 = -1; } } @@ -25,7 +25,7 @@ void lasersightsReset(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_LaserSights); i++) { g_LaserSights[i].id = -1; } } diff --git a/src/game/invreset.c b/src/game/invreset.c index 98fcd6350..8aeb2ee6a 100644 --- a/src/game/invreset.c +++ b/src/game/invreset.c @@ -18,7 +18,7 @@ void invReset(void) g_Vars.currentplayer->equipallguns = false; } - for (i = 0; i != 10; i++) { + for (i = 0; i != ARRAYCOUNT(g_Vars.currentplayer->gunheldarr); i++) { g_Vars.currentplayer->gunheldarr[i].totaltime240_60 = -1; } } diff --git a/src/game/lv.c b/src/game/lv.c index fc8179985..c33b852dd 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -781,7 +781,7 @@ void lvFindThreatsForProp(struct prop *prop, bool inchild, struct coord *playerp } if (pass) { - for (i = 0; i != 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { if (g_Vars.currentplayer->trackedprops[i].prop == prop) { pass = false; } @@ -808,7 +808,7 @@ void lvFindThreatsForProp(struct prop *prop, bool inchild, struct coord *playerp (prop->pos.f[1] - playerpos->f[1]) * (prop->pos.f[1] - playerpos->f[1]) + (prop->pos.f[2] - playerpos->f[2]) * (prop->pos.f[2] - playerpos->f[2]); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { if (!activeslots[i]) { index = i; } @@ -816,7 +816,7 @@ void lvFindThreatsForProp(struct prop *prop, bool inchild, struct coord *playerp if (index == -1) { // No slots available - consider replacing the furtherest - for (i = 0; i != 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { if (distances[i] > furtherestdist) { furtherestdist = distances[i]; index = i; @@ -911,8 +911,8 @@ void lvFindThreats(void) { s32 i; struct prop *prop; - f32 distances[] = {0, 0, 0, 0}; - s32 activeslots[] = {false, false, false, false}; + f32 distances[ARRAYCOUNT(g_Vars.currentplayer->trackedprops)] = {0}; + s32 activeslots[ARRAYCOUNT(g_Vars.currentplayer->trackedprops)] = {false}; struct prop **propptr = g_Vars.endonscreenprops - 1; struct coord campos; @@ -2378,7 +2378,7 @@ void lvStop(void) audioStop(g_MiscAudioHandle); } - if (g_Vars.stagenum < NUM_STAGES) { + if (g_Vars.stagenum < STAGE_TITLE) { s32 bank = langGetLangBankIndexFromStagenum(g_Vars.stagenum); langClearBank(bank); stub0f015270(); @@ -2401,7 +2401,7 @@ void lvStop(void) musicStop(); hudmsgsStop(); - if (g_Vars.stagenum < NUM_STAGES) { + if (g_Vars.stagenum < STAGE_TITLE) { bgStop(); } diff --git a/src/game/mainmenu.c b/src/game/mainmenu.c index e6ea4c649..30cb31975 100644 --- a/src/game/mainmenu.c +++ b/src/game/mainmenu.c @@ -41,7 +41,7 @@ struct menudialogdef g_CinemaMenuDialog; char *menuTextCurrentStageName(struct menuitem *item) { - sprintf(g_StringPointer, "%s\n", langGet(g_StageNames[g_MissionConfig.stageindex].name3)); + sprintf(g_StringPointer, "%s\n", langGet(g_SoloStages[g_MissionConfig.stageindex].name3)); return g_StringPointer; } @@ -762,7 +762,7 @@ char *soloMenuTitleStageOverview(struct menudialogdef *dialogdef) } sprintf(g_StringPointer, "%s: %s\n", - langGet(g_StageNames[g_MissionConfig.stageindex].name3), + langGet(g_SoloStages[g_MissionConfig.stageindex].name3), langGet(L_OPTIONS_273)); return g_StringPointer; @@ -995,7 +995,7 @@ bool isStageDifficultyUnlocked(s32 stageindex, s32 difficulty) // Handle normal missions if (stageindex <= SOLOSTAGEINDEX_SKEDARRUINS && difficulty <= DIFF_PA) { // Defection is always unlocked on all difficulties - if (g_StageNames[stageindex].stagenum == STAGE_DEFECTION) { + if (g_SoloStages[stageindex].stagenum == STAGE_DEFECTION) { return true; } @@ -1014,7 +1014,7 @@ bool isStageDifficultyUnlocked(s32 stageindex, s32 difficulty) } if (stageindex > 0) { - if (g_StageNames[stageindex].stagenum != STAGE_SKEDARRUINS) { + if (g_SoloStages[stageindex].stagenum != STAGE_SKEDARRUINS) { // For normal stages prior to Skedar Ruins, test if the // prior stage is complete on the same difficulty or higher. for (d = difficulty; d <= DIFF_PA; d++) { @@ -1058,7 +1058,7 @@ bool isStageDifficultyUnlocked(s32 stageindex, s32 difficulty) // querying SA or higher, grant the difficulty if the stage is complete // on the prior difficulty or higher. if (difficulty >= DIFF_SA) { - if (g_StageNames[stageindex].stagenum != STAGE_SKEDARRUINS) { + if (g_SoloStages[stageindex].stagenum != STAGE_SKEDARRUINS) { // Check if all normal stages are complete on any difficulty for (s = 0; s <= SOLOSTAGEINDEX_SKEDARRUINS; s++) { for (d = DIFF_A; d <= DIFF_PA; d++) { @@ -1732,7 +1732,7 @@ struct menudialogdef g_AntiMissionDifficultyMenuDialog = { NULL, }; -struct stageoverviewentry g_StageNames[NUM_SOLOSTAGES] = { +struct solostage g_SoloStages[NUM_SOLOSTAGES] = { // stage, unk04, { STAGE_DEFECTION, 0x0c, L_OPTIONS_133, L_OPTIONS_134, L_MPWEAPONS_124 }, { STAGE_INVESTIGATION, 0x0d, L_OPTIONS_135, L_OPTIONS_136, L_MPWEAPONS_172 }, @@ -1759,13 +1759,13 @@ struct stageoverviewentry g_StageNames[NUM_SOLOSTAGES] = { s32 getNumUnlockedSpecialStages(void) { - s32 next = 0; + s32 count = 0; s32 offsetforduel = 1; s32 i; - for (i = 0; i < 3; i++) { + for (i = 0; i < ARRAYCOUNT(g_GameFile.besttimes[0]); i++) { if (g_GameFile.besttimes[SOLOSTAGEINDEX_SKEDARRUINS][i]) { - next = i + 1; + count = i + 1; } } @@ -1779,7 +1779,7 @@ s32 getNumUnlockedSpecialStages(void) } } - return next + offsetforduel; + return count + offsetforduel; } s32 func0f104720(s32 value) @@ -1787,7 +1787,7 @@ s32 func0f104720(s32 value) s32 next = 0; s32 d; - for (d = 0; d != 3; d++) { + for (d = 0; d < ARRAYCOUNT(g_GameFile.besttimes[0]); d++) { if (g_GameFile.besttimes[SOLOSTAGEINDEX_SKEDARRUINS][d]) { next = d + 1; } @@ -1841,10 +1841,10 @@ MenuItemHandlerResult menuhandlerMissionList(s32 operation, struct menuitem *ite case MENUOP_GETOPTIONCOUNT: data->list.value = 0; - for (i = 0; i < 17; i++) { + for (i = 0; i <= SOLOSTAGEINDEX_SKEDARRUINS; i++) { stageiscomplete = false; - for (j = 0; j < 3; j++) { + for (j = 0; j < ARRAYCOUNT(g_GameFile.besttimes[i]); j++) { if (g_GameFile.besttimes[i][j] != 0) { stageiscomplete = true; } @@ -1873,11 +1873,11 @@ MenuItemHandlerResult menuhandlerMissionList(s32 operation, struct menuitem *ite if (data->list.value < data->list.unk04u32) { // Regular stage such as "dataDyne Central - Defection" // Return the name before the dash, such as "dataDyne Central" - return (s32) langGet(g_StageNames[data->list.value].name1); + return (s32) langGet(g_SoloStages[data->list.value].name1); } // Special stages have no dash and suffix, so just return the name - return (s32) langGet(g_StageNames[func0f104720(data->list.value - data->list.unk04u32)].name1); + return (s32) langGet(g_SoloStages[func0f104720(data->list.value - data->list.unk04u32)].name1); case MENUOP_SET: sp188 = data->list.value; menuhandlerMissionList(MENUOP_GETOPTIONCOUNT, item, &sp178); @@ -1889,7 +1889,7 @@ MenuItemHandlerResult menuhandlerMissionList(s32 operation, struct menuitem *ite g_Vars.mplayerisrunning = false; g_Vars.normmplayerisrunning = false; - g_MissionConfig.stagenum = g_StageNames[sp188].stagenum; + g_MissionConfig.stagenum = g_SoloStages[sp188].stagenum; g_MissionConfig.stageindex = sp188; if (g_MissionConfig.iscoop) { @@ -2072,14 +2072,14 @@ MenuItemHandlerResult menuhandlerMissionList(s32 operation, struct menuitem *ite gdl = text0f153628(gdl); // Draw first part of name - strcpy(text, langGet(g_StageNames[stageindex].name1)); + strcpy(text, langGet(g_SoloStages[stageindex].name1)); strcat(text, "\n"); gdl = textRenderProjected(gdl, &x, &y, text, g_CharsHandelGothicMd, g_FontHandelGothicMd, renderdata->colour, viGetWidth(), viGetHeight(), 0, 0); // Draw last part of name - strcpy(text, langGet(g_StageNames[stageindex].name2)); + strcpy(text, langGet(g_SoloStages[stageindex].name2)); gdl = textRenderProjected(gdl, &x, &y, text, g_CharsHandelGothicSm, g_FontHandelGothicSm, renderdata->colour, viGetWidth(), viGetHeight(), 0, 0); @@ -3777,7 +3777,7 @@ void func0f105948(s32 weaponnum) g_Menus[g_MpPlayerNum].unk840.unk000 = 8; g_Menus[g_MpPlayerNum].unk840.unk010 = 0; - g_Menus[g_MpPlayerNum].unk840.unk00c = weaponGetModelNum(weaponnum); + g_Menus[g_MpPlayerNum].unk840.unk00c = weaponGetFileNum(weaponnum); g_Menus[g_MpPlayerNum].unk840.unk538 = 0; g_Menus[g_MpPlayerNum].unk840.unk510 = 0; g_Menus[g_MpPlayerNum].unk840.unk53c = 0; @@ -4372,7 +4372,7 @@ char *soloMenuTitlePauseStatus(struct menudialogdef *dialogdef) } sprintf(g_StringPointer, "%s: %s\n", - langGet(g_StageNames[g_MissionConfig.stageindex].name3), + langGet(g_SoloStages[g_MissionConfig.stageindex].name3), langGet(L_OPTIONS_172)); return g_StringPointer; diff --git a/src/game/menu.c b/src/game/menu.c index cffb10fa6..e9836b21e 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -63,13 +63,13 @@ u32 var8009dfc4; struct briefing g_Briefing; u32 var8009dfe4; struct missionconfig g_MissionConfig; -struct menu g_Menus[4]; +struct menu g_Menus[MAX_PLAYERS]; struct menudata g_MenuData; s32 g_MenuScissorX1; s32 g_MenuScissorX2; s32 g_MenuScissorY1; s32 g_MenuScissorY2; -Vp var800a2048[4][2]; +Vp var800a2048[MAX_PLAYERS][2]; #if VERSION >= VERSION_NTSC_1_0 struct menudialogdef g_PakCannotReadGameBoyMenuDialog; @@ -392,7 +392,7 @@ struct menudfc *func0f0f1338(struct menuitem *item) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus[0].unkdfc); i++) { if (g_Menus[g_MpPlayerNum].unkdfc[i].item == item) { return &g_Menus[g_MpPlayerNum].unkdfc[i]; } @@ -431,7 +431,7 @@ void func0f0f1418(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus[0].unkdfc); i++) { if (g_Menus[g_MpPlayerNum].unkdfc[i].item) { #if VERSION >= VERSION_PAL_BETA g_Menus[g_MpPlayerNum].unkdfc[i].unk04 += g_Vars.diffframe60freal / 60.0f; @@ -446,7 +446,7 @@ void func0f0f1494(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus[0].unkdfc); i++) { g_Menus[g_MpPlayerNum].unkdfc[i].item = NULL; } } @@ -771,7 +771,7 @@ void menuCalculateItemSize(struct menuitem *item, s16 *width, s16 *height, struc numobjectives = 0; *width = 240; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Briefing.objectivenames); i++) { if (g_Briefing.objectivenames[i] && (g_Briefing.objectivedifficulties[i] & (1 << lvGetDifficulty()))) { numobjectives++; } @@ -1496,7 +1496,7 @@ bool func0f0f3220(s32 arg0) if (g_MenuData.unk669[arg0] == 4) { s32 prevplayernum = g_MpPlayerNum; - for (i = 3; i >= 0; i--) { + for (i = ARRAYCOUNT(g_Menus) - 1; i >= 0; i--) { if (g_Menus[i].curdialog) { g_MpPlayerNum = i; } @@ -1543,7 +1543,7 @@ void func0f0f3220(s32 arg0) if (g_MenuData.unk669[arg0] == 4) { s32 prevplayernum = g_MpPlayerNum; - for (i = 3; i >= 0; i--) { + for (i = ARRAYCOUNT(g_Menus) - 1; i >= 0; i--) { if (g_Menus[i].curdialog) { g_MpPlayerNum = i; } @@ -3421,7 +3421,7 @@ void func0f0f820c(struct menudialogdef *dialogdef, s32 root) s32 i; s32 prevplayernum = g_MpPlayerNum; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (g_Menus[i].curdialog) { g_MpPlayerNum = i; func0f0f8120(); @@ -3460,7 +3460,7 @@ void func0f0f8300(void) s32 i; if (g_MenuData.count == 0) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_MenuData.playerjoinalpha); i++) { g_MenuData.playerjoinalpha[i] = 0; } } @@ -3757,7 +3757,7 @@ void menuReset(void) texLoadFromConfig(&g_TexGeneralConfigs[35]); } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { g_Menus[i].unk840.unk004 = NULL; } @@ -3788,7 +3788,7 @@ void menuReset(void) func0f0f8bb4(&g_MenuData.unk01c, 0xc800, 1); } - g_MenuData.unk01c.unk00c = 0x259; + g_MenuData.unk01c.unk00c = FILE_GHUDPIECE; g_MenuData.unk01c.unk524 = g_MenuData.unk01c.unk54c = -M_PI; g_MenuData.unk01c.unk520 = g_MenuData.unk01c.unk548 = 0; g_MenuData.unk01c.unk528 = g_MenuData.unk01c.unk550 = 0; @@ -3804,7 +3804,7 @@ void menuReset(void) g_MenuData.unk5d4 = 0; g_MenuData.unk5d5_05 = false; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { g_Menus[i].curdialog = NULL; g_Menus[i].depth = 0; g_Menus[i].numdialogs = 0; @@ -3829,7 +3829,7 @@ void menuReset(void) g_MenuData.nextbg = 255; g_MenuData.bannernum = -1; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_MenuData.unk669); i++) { g_MenuData.unk669[i] = 0xff; } @@ -5294,7 +5294,7 @@ Gfx *menuRender(Gfx *gdl) } else { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpPlayerNum = i; gdl = menuRenderDialogs(gdl); } @@ -5327,7 +5327,7 @@ Gfx *menuRender(Gfx *gdl) gdl = text0f153628(gdl); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { // Figure out what text will be displayed. The text calculated // here is for measuring purposes only and isn't rendered. // Amusingly, there's a %d placeholder in the text which isn't @@ -5344,7 +5344,7 @@ Gfx *menuRender(Gfx *gdl) if (g_Vars.mpsetupmenu == MPSETUPMENU_GENERAL) { renderit = true; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(g_Vars.waitingtojoin); j++) { if (g_Vars.waitingtojoin[j]) { renderit = false; } diff --git a/src/game/menugfx.c b/src/game/menugfx.c index b1cfad1fb..f992507e5 100644 --- a/src/game/menugfx.c +++ b/src/game/menugfx.c @@ -134,7 +134,7 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) gDPPipeSync(gdl++); gSPTexture(gdl++, 0xffff, 0xffff, 0, G_TX_RENDERTILE, G_ON); - gDPLoadTextureBlock(gdl++, g_BlurBuffer, G_IM_FMT_RGBA, G_IM_SIZ_16b, 40, 30, 0, + gDPLoadTextureBlock(gdl++, g_BlurBuffer, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, BLURIMG_HEIGHT, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); diff --git a/src/game/menuitem.c b/src/game/menuitem.c index 2e417b636..2d96ec468 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -23,7 +23,7 @@ #include "data.h" #include "types.h" -u8 g_MpSelectedPlayersForStats[4]; +u8 g_MpSelectedPlayersForStats[MAX_PLAYERS]; #if VERSION >= VERSION_NTSC_1_0 s32 g_ScissorX1 = 0; @@ -1791,7 +1791,7 @@ Gfx *menuitemObjectivesRender(Gfx *gdl, struct menurendercontext *context) s32 position = 1; s32 i; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Briefing.objectivenames); i++) { if (g_Briefing.objectivenames[i] && g_Briefing.objectivedifficulties[i] & (1 << lvGetDifficulty())) { gdl = menuitemObjectivesRenderOne(gdl, context->dialog, diff --git a/src/game/menutick.c b/src/game/menutick.c index 3ad6ba401..a0f57fbae 100644 --- a/src/game/menutick.c +++ b/src/game/menutick.c @@ -47,7 +47,7 @@ void menuCountDialogs(void) s32 i; g_MenuData.count = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (g_Menus[i].curdialog) { g_MenuData.count++; } @@ -77,7 +77,7 @@ void menuTick(void) menuCountDialogs(); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (i); if (g_Menus[i].openinhibit > 0) { @@ -97,7 +97,7 @@ void menuTick(void) s32 bVar12 = 50; s32 bVar11 = false; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(g_Menus); j++) { if (g_Menus[j].curdialog) { if (g_Menus[j].curdialog->state == MENUDIALOGSTATE_OPENING || g_Menus[j].curdialog->state == MENUDIALOGSTATE_POPULATING @@ -224,7 +224,7 @@ void menuTick(void) g_Vars.mpsetupmenu = MPSETUPMENU_GENERAL; } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.waitingtojoin[i] = false; if (g_MpSetup.chrslots & (1 << i)) { @@ -291,7 +291,7 @@ void menuTick(void) g_MpNumJoined = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (g_Menus[i].curdialog) { g_Menus[i].playernum = g_MpNumJoined++; @@ -305,7 +305,7 @@ void menuTick(void) challengePerformSanityChecks(); } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpPlayerNum = i; if (g_Menus[g_MpPlayerNum].curdialog) { @@ -317,7 +317,7 @@ void menuTick(void) } } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpPlayerNum = i; if (g_Menus[g_MpPlayerNum].curdialog) { @@ -341,7 +341,7 @@ void menuTick(void) // Limit to 2 players? But in a roundabout kind of way canjoin = true; - for (j = 0; j < 4; j++) { + for (j = 0; j < MAX_PLAYERS; j++) { if (g_Vars.waitingtojoin[j]) { canjoin = false; } @@ -488,7 +488,7 @@ void menuTick(void) g_MpPlayerNum = 0; sp344 = false; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { if (g_Menus[i].curdialog) { sp344 = true; } @@ -527,12 +527,12 @@ void menuTick(void) func0f0fd548(4); } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_MpSetup.chrslots & (1 << i)) { if (g_Vars.coopplayernum >= 0) { if (g_Vars.stagenum == STAGE_DEEPSEA) { g_MissionConfig.stageindex++; - g_MissionConfig.stagenum = g_StageNames[g_MissionConfig.stageindex].stagenum; + g_MissionConfig.stagenum = g_SoloStages[g_MissionConfig.stageindex].stagenum; titleSetNextStage(g_MissionConfig.stagenum); lvSetDifficulty(g_MissionConfig.difficulty); titleSetNextMode(TITLEMODE_SKIP); diff --git a/src/game/mplayer/ingame.c b/src/game/mplayer/ingame.c index 6eaa5646a..ef96daa54 100644 --- a/src/game/mplayer/ingame.c +++ b/src/game/mplayer/ingame.c @@ -644,7 +644,7 @@ MenuItemHandlerResult mpAwardsMenuHandler(s32 operation, struct menuitem *item, s32 i; u32 colour; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_PlayerConfigsArray[g_MpPlayerNum].medals & (1 << i)) { switch (i) { case 0: colour = 0xff7f7fff; break; // killmaster - red diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 5d4cda704..7ad23df96 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -35,9 +35,9 @@ struct mpchrconfig *g_MpAllChrConfigPtrs[MAX_MPCHRS]; s32 g_MpNumChrs; u32 var800ac534; struct mpbotconfig g_BotConfigsArray[MAX_BOTS]; -u8 g_MpSimulantDifficultiesPerNumPlayers[MAX_BOTS][4]; -struct mpplayerconfig g_PlayerConfigsArray[6]; -u8 g_AmBotCommands[16]; +u8 g_MpSimulantDifficultiesPerNumPlayers[MAX_BOTS][MAX_PLAYERS]; +struct mpplayerconfig g_PlayerConfigsArray[MAX_MPPLAYERCONFIGS]; +u8 g_AmBotCommands[9]; struct mpsetup g_MpSetup; struct bossfile g_BossFile; u32 var800acc1c; @@ -152,7 +152,7 @@ void mpStartMatch(void) g_MpSetup.options &= ~(MPOPTION_SLOWMOTION_ON | MPOPTION_SLOWMOTION_SMART); } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_MpSetup.chrslots & (1 << i)) { numplayers++; } @@ -195,12 +195,12 @@ void mpReset(void) if (g_Vars.coopplayernum >= 0 || g_Vars.antiplayernum >= 0) { struct mpplayerconfig tmp; - tmp = g_PlayerConfigsArray[4]; - g_PlayerConfigsArray[4] = g_PlayerConfigsArray[0]; + tmp = g_PlayerConfigsArray[MAX_PLAYERS]; + g_PlayerConfigsArray[MAX_PLAYERS] = g_PlayerConfigsArray[0]; g_PlayerConfigsArray[0] = tmp; - tmp = g_PlayerConfigsArray[5]; - g_PlayerConfigsArray[5] = g_PlayerConfigsArray[1]; + tmp = g_PlayerConfigsArray[MAX_PLAYERS + 1]; + g_PlayerConfigsArray[MAX_PLAYERS + 1] = g_PlayerConfigsArray[1]; g_PlayerConfigsArray[1] = tmp; // Player index 0 @@ -231,7 +231,7 @@ void mpReset(void) g_MpNumChrs = 2; } else { - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_MpSetup.chrslots & (1 << i)) { g_Vars.playerstats[mpindex].mpindex = i; @@ -240,7 +240,6 @@ void mpReset(void) mpCalculatePlayerTitle(&g_PlayerConfigsArray[i]); - g_PlayerConfigsArray[i].newtitle = g_PlayerConfigsArray[i].title; g_MpNumChrs++; mpindex++; @@ -248,7 +247,7 @@ void mpReset(void) } } - for (i = 0; i != MAX_MPCHRS; i++) { + for (i = 0; i < MAX_MPCHRS; i++) { struct mpchrconfig *mpchr = MPCHR(i); func0f187838(mpchr); @@ -283,7 +282,7 @@ void mpReset(void) } // Assign aibot commands to active menu slots - for (i = 0; i < 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_AmBotCommands); i++) { g_AmBotCommands[i] = AIBOTCMD_NORMAL; } @@ -433,9 +432,9 @@ void mpPlayerSetDefaults(s32 playernum, bool autonames) g_PlayerConfigsArray[playernum].survivormedals = 0; g_PlayerConfigsArray[playernum].title = MPPLAYERTITLE_BEGINNER; - if (playernum < 4) { - for (i = 0; i < 30; i++) { - for (j = 1; j <= 4; j++) { + if (playernum < MAX_PLAYERS) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j <= MAX_PLAYERS; j++) { challengeSetCompletedByPlayerWithNumPlayers(playernum, i, j, false); } } @@ -443,7 +442,7 @@ void mpPlayerSetDefaults(s32 playernum, bool autonames) challengeDetermineUnlockedFeatures(); } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_PlayerConfigsArray); i++) { g_PlayerConfigsArray[playernum].gunfuncs[i] = 0; } } @@ -486,7 +485,7 @@ void mpInit(void) strcpy(g_MpSetup.name, ""); - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_PlayerConfigsArray); i++) { mpPlayerSetDefaults(i, false); } @@ -496,7 +495,7 @@ void mpInit(void) if (argFindByPrefix(1, "-mpwpnset")) { char *value = argFindByPrefix(1, "-mpwpnset"); - mpSetWeaponSet(*value - 0x30); + mpSetWeaponSet(*value - '0'); } else { mpSetWeaponSet(0); } @@ -514,7 +513,7 @@ void mpInit(void) challengeForceUnlockBotFeatures(); for (i = 0; i < ARRAYCOUNT(g_PlayerConfigsArray); i++) { - for (j = 0; j < 6; j++) { + for (j = 0; j < ARRAYCOUNT(g_PlayerConfigsArray[i].gunfuncs); j++) { g_PlayerConfigsArray[i].gunfuncs[j] = 0; } } @@ -529,7 +528,7 @@ void mpGetTeamsWithDefaultName(u8 *mask) *mask = 0; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.teamnames); i++) { if (strcmp(g_BossFile.teamnames[i], langGet(L_OPTIONS_008 + i)) == 0) { *mask |= 1 << i; } @@ -542,7 +541,7 @@ void mpSetTeamNamesToDefault(u8 mask) { s32 i; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.teamnames); i++) { if (mask & (1 << i)) { strcpy(g_BossFile.teamnames[i], langGet(L_OPTIONS_008 + i)); } @@ -560,14 +559,14 @@ void mpSetDefaultNamesIfEmpty(void) } // Team names - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(g_BossFile.teamnames); i++) { if (g_BossFile.teamnames[i][0] == '\0') { strcpy(g_BossFile.teamnames[i], langGet(L_OPTIONS_008 + i)); // "Red", "Yellow" etc } } // Player names - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_PlayerConfigsArray[i].base.name[0] == '\0') { sprintf(g_PlayerConfigsArray[i].base.name, "%s %d\n", langGet(L_MISC_437), i + 1); // "Player 1" etc } @@ -584,7 +583,7 @@ s32 mpCalculateTeamScoreLimit(void) && (g_MpSetup.scenario == MPSCENARIO_COMBAT || g_MpSetup.scenario == MPSCENARIO_KINGOFTHEHILL)) { s32 numchrs = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_MpSetup.chrslots & (1 << i)) { numchrs++; } @@ -810,15 +809,15 @@ s32 mpGetTeamRankings(struct ranking *rankings) { s32 i; s32 count; - s32 apparentscores[8]; - u32 rankablescores[8]; + s32 apparentscores[MAX_TEAMS]; + u32 rankablescores[MAX_TEAMS]; u32 bestrankablescore; s32 thisteamnum; count = 0; // Calculate scores for each team - for (i = 0; i < 8; i++) { + for (i = 0; i < MAX_TEAMS; i++) { apparentscores[i] = -8000; rankablescores[i] = mpCalculateTeamScore(i, &apparentscores[i]); } @@ -831,7 +830,7 @@ s32 mpGetTeamRankings(struct ranking *rankings) thisteamnum = -8000; // Check which team has the best remaining score - for (i = 0; i < 8; i++) { + for (i = 0; i < MAX_TEAMS; i++) { if (apparentscores[7 - i] > -8000 && rankablescores[7 - i] >= bestrankablescore) { thisteamnum = 7 - i; bestrankablescore = rankablescores[thisteamnum]; @@ -955,7 +954,7 @@ struct mpweapon *mpGetMpWeaponByLocation(s32 locationindex) if (v0 > 0) { slot++; - if (slot >= 6) { + if (slot >= ARRAYCOUNT(g_MpSetup.weapons)) { slot = 0; if (a2 == v0) { @@ -1015,29 +1014,29 @@ s32 func0f188f9c(s32 arg0) return i + arg0; } -s32 func0f189058(s32 arg0) +s32 func0f189058(bool full) { - return mpCountWeaponSetThing(arg0 ? 15 : 12); + return mpCountWeaponSetThing(full ? ARRAYCOUNT(g_MpWeaponSets) + 3 : ARRAYCOUNT(g_MpWeaponSets)); } s32 func0f189088(void) { - return mpCountWeaponSetThing(14); + return mpCountWeaponSetThing(ARRAYCOUNT(g_MpWeaponSets) + 2); } char *mpGetWeaponSetName(s32 index) { index = func0f188f9c(index); - if (index < 0 || index >= 14) { + if (index < 0 || index >= ARRAYCOUNT(g_MpWeaponSets) + 2) { return langGet(L_MPWEAPONS_041); // "Custom" } - if (index == 13) { + if (index == ARRAYCOUNT(g_MpWeaponSets) + 1) { return langGet(L_MPWEAPONS_042); // "Random" } - if (index == 12) { + if (index == ARRAYCOUNT(g_MpWeaponSets)) { return langGet(L_MPWEAPONS_043); // "Random Five" } @@ -1051,7 +1050,7 @@ void func0f18913c(void) u8 *ptr; s32 j; - for (i = 0; !done && i < 12; i++) { + for (i = 0; !done && i < ARRAYCOUNT(g_MpWeaponSets); i++) { if (challengeIsFeatureUnlocked(g_MpWeaponSets[i].requirefeatures[0]) && challengeIsFeatureUnlocked(g_MpWeaponSets[i].requirefeatures[1]) && challengeIsFeatureUnlocked(g_MpWeaponSets[i].requirefeatures[2]) @@ -1066,7 +1065,7 @@ void func0f18913c(void) if (ptr != NULL) { bool ok = true; - for (j = 0; j < 6; j++) { + for (j = 0; j < ARRAYCOUNT(g_MpWeaponSets[j].slots); j++) { s32 weaponnum = ptr[j]; if (weaponnum == WEAPON_MPSHIELD) { @@ -1097,7 +1096,7 @@ void mpApplyWeaponSet(void) s32 i; u8 *ptr; - if (g_MpWeaponSetNum >= 0 && g_MpWeaponSetNum < 12) { + if (g_MpWeaponSetNum >= 0 && g_MpWeaponSetNum < ARRAYCOUNT(g_MpWeaponSets)) { if (challengeIsFeatureUnlocked(g_MpWeaponSets[g_MpWeaponSetNum].requirefeatures[0]) && challengeIsFeatureUnlocked(g_MpWeaponSets[g_MpWeaponSetNum].requirefeatures[1]) && challengeIsFeatureUnlocked(g_MpWeaponSets[g_MpWeaponSetNum].requirefeatures[2]) @@ -1110,7 +1109,7 @@ void mpApplyWeaponSet(void) } if (ptr != NULL) { - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) { u32 j; bool done = false; s32 mpweaponnum = MPWEAPON_NONE; @@ -1135,7 +1134,7 @@ void mpApplyWeaponSet(void) } else if (g_MpWeaponSetNum == WEAPONSET_RANDOM) { s32 numoptions = mpGetNumWeaponOptions(); - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) { mpSetWeaponSlot(i, random() % numoptions); } } else if (g_MpWeaponSetNum == WEAPONSET_RANDOMFIVE) { @@ -1157,7 +1156,7 @@ void mpSetWeaponSet(s32 weaponsetnum) void func0f1895e8(void) { - if (g_MpWeaponSetNum < 12) { + if (g_MpWeaponSetNum < ARRAYCOUNT(g_MpWeaponSets)) { mpApplyWeaponSet(); } } @@ -1505,7 +1504,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) #define MULT(val) (val) #endif - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->kills >= tiers[i] * MULT(20)) { tallies[0]++; } else { @@ -1513,7 +1512,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->gameswon >= tiers[i] * MULT(1)) { tallies[1]++; } else { @@ -1521,7 +1520,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->accuracymedals >= tiers[i] * MULT(1)) { tallies[2]++; } else { @@ -1529,7 +1528,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->headshotmedals >= tiers[i] * MULT(1)) { tallies[3]++; } else { @@ -1537,7 +1536,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->killmastermedals >= tiers[i] * MULT(1)) { tallies[4]++; } else { @@ -1545,7 +1544,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->time >= tiers[i] * MULT(1200)) { tallies[5]++; } else { @@ -1553,7 +1552,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->distance >= tiers[i] * MULT(100)) { tallies[6]++; } else { @@ -1561,7 +1560,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->damagedealt >= tiers[i] * MULT(1)) { tallies[7]++; } else { @@ -1569,7 +1568,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->ammoused >= tiers[i] * MULT(500)) { tallies[8]++; } else { @@ -1577,7 +1576,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) } } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tiers); i++) { if (mpplayer->survivormedals >= tiers[i] * MULT(1)) { tallies[9]++; } else { @@ -1587,7 +1586,7 @@ void mpCalculatePlayerTitle(struct mpplayerconfig *mpplayer) sum = 0; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(tallies); i++) { sum = sum + tallies[i]; } @@ -1615,7 +1614,7 @@ const char var7f1b8b44[] = ""; const char var7f1b8b48[] = "Player %d TitleCalc ============\n"; #endif -struct mphead g_MpBeauHeads[NUM_MPBEAUHEADS] = { +struct mphead g_MpBeauHeads[] = { // head, require feature { HEAD_BEAU2, 0 }, { HEAD_BEAU3, 0 }, @@ -1624,12 +1623,12 @@ struct mphead g_MpBeauHeads[NUM_MPBEAUHEADS] = { { HEAD_BEAU6, 0 }, }; -struct mphead g_MpHeads[NUM_MPHEADS] = { +struct mphead g_MpHeads[] = { // head, require feature { /*0x00*/ HEAD_DARK_COMBAT, 0 }, { /*0x01*/ HEAD_DARK_FROCK, MPFEATURE_CHR_CI }, { /*0x02*/ HEAD_DARKAQUA, MPFEATURE_CHR_PELAGIC }, - { /*0x03*/ HEAD_DARK_SNOW, MPFEATURE_4A }, + { /*0x03*/ HEAD_DARK_SNOW, MPFEATURE_CHR_DARKSNOW }, { /*0x04*/ HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, { /*0x05*/ HEAD_ELVIS_GOGS, MPFEATURE_CHR_ELVIS }, { /*0x06*/ HEAD_CARRINGTON, 0 }, @@ -1763,7 +1762,6 @@ u32 g_BotHeads[] = { #endif }; -// 2d74c struct botprofile g_BotProfiles[] = { // type, difficulty, name, body, require feature { BOTTYPE_GENERAL, BOTDIFF_MEAT, L_MISC_088, MPBODY_DD_GUARD, 0 }, @@ -1786,70 +1784,69 @@ struct botprofile g_BotProfiles[] = { { BOTTYPE_VENGE, BOTDIFF_NORMAL, L_MISC_105, MPBODY_ALASKAN_GUARD, 0 }, }; -// 2d7dc -struct mpbody g_MpBodies[NUM_MPBODIES] = { - // global body ID, name, head, require feature - /*0x00*/ { BODY_DARK_COMBAT, L_OPTIONS_016, HEAD_DARK_COMBAT, 0 }, - /*0x01*/ { BODY_DARK_TRENCH, L_OPTIONS_017, HEAD_DARK_COMBAT, MPFEATURE_CHR_JOTRENCH }, - /*0x02*/ { BODY_DARK_FROCK, L_OPTIONS_018, HEAD_DARK_FROCK, MPFEATURE_CHR_CI }, - /*0x03*/ { BODY_DARK_RIPPED, L_OPTIONS_019, HEAD_DARK_FROCK, MPFEATURE_CHR_CI }, - /*0x04*/ { BODY_DARK_AF1, L_OPTIONS_020, HEAD_DARK_COMBAT, MPFEATURE_CHR_AF1 }, - /*0x05*/ { BODY_DARK_LEATHER, L_MPWEAPONS_156, HEAD_DARK_COMBAT, MPFEATURE_CHR_G5 }, +struct mpbody g_MpBodies[] = { + // global body ID, name, head, require feature + /*0x00*/ { BODY_DARK_COMBAT, L_OPTIONS_016, HEAD_DARK_COMBAT, 0 }, + /*0x01*/ { BODY_DARK_TRENCH, L_OPTIONS_017, HEAD_DARK_COMBAT, MPFEATURE_CHR_JOTRENCH }, + /*0x02*/ { BODY_DARK_FROCK, L_OPTIONS_018, HEAD_DARK_FROCK, MPFEATURE_CHR_CI }, + /*0x03*/ { BODY_DARK_RIPPED, L_OPTIONS_019, HEAD_DARK_FROCK, MPFEATURE_CHR_CI }, + /*0x04*/ { BODY_DARK_AF1, L_OPTIONS_020, HEAD_DARK_COMBAT, MPFEATURE_CHR_AF1 }, + /*0x05*/ { BODY_DARK_LEATHER, L_MPWEAPONS_156, HEAD_DARK_COMBAT, MPFEATURE_CHR_G5 }, /*0x06*/ { BODY_DARK_NEGOTIATOR, L_MPWEAPONS_157, HEAD_DARK_COMBAT, MPFEATURE_CHR_VILLACHRS }, - /*0x07*/ { BODY_DARKWET, L_OPTIONS_021, HEAD_DARKAQUA, MPFEATURE_CHR_PELAGIC }, - /*0x08*/ { BODY_DARKAQUALUNG, L_OPTIONS_022, HEAD_DARKAQUA, MPFEATURE_CHR_PELAGIC }, - /*0x09*/ { BODY_DARKSNOW, L_OPTIONS_023, HEAD_DARK_SNOW, MPFEATURE_4A }, - /*0x0a*/ { BODY_DARKLAB, L_OPTIONS_024, HEAD_DARK_COMBAT, MPFEATURE_CHR_INFILTRATION }, - /*0x0b*/ { BODY_THEKING, L_OPTIONS_025, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, - /*0x0c*/ { BODY_ELVIS1, L_OPTIONS_026, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, - /*0x0d*/ { BODY_ELVISWAISTCOAT, L_MPWEAPONS_158, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, - /*0x0e*/ { BODY_CARRINGTON, L_OPTIONS_027, HEAD_CARRINGTON, 0 }, - /*0x0f*/ { BODY_CARREVENINGSUIT, L_OPTIONS_028, HEAD_CARRINGTON, MPFEATURE_CHR_CI }, - /*0x10*/ { BODY_MRBLONDE, L_OPTIONS_029, HEAD_MRBLONDE, MPFEATURE_CHR_MRBLONDE }, - /*0x11*/ { BODY_CASSANDRA, L_OPTIONS_030, HEAD_CASSANDRA, 0 }, - /*0x12*/ { BODY_TRENT, L_OPTIONS_031, HEAD_TRENT, MPFEATURE_CHR_TRENT }, - /*0x13*/ { BODY_JONATHAN, L_OPTIONS_032, HEAD_JONATHAN, MPFEATURE_4C }, - /*0x14*/ { BODY_CILABTECH, L_OPTIONS_033, 1000, 0 }, - /*0x15*/ { BODY_CIFEMTECH, L_OPTIONS_034, 1000, 0 }, - /*0x16*/ { BODY_CISOLDIER, L_OPTIONS_035, 1000, 0 }, - /*0x17*/ { BODY_DDSHOCK, L_OPTIONS_036, HEAD_DDSHOCK, 0 }, - /*0x18*/ { BODY_FEM_GUARD, L_OPTIONS_037, 1000, MPFEATURE_CHR_FEMGUARD }, - /*0x19*/ { BODY_DD_SECGUARD, L_OPTIONS_038, 1000, 0 }, - /*0x1a*/ { BODY_DD_GUARD, L_OPTIONS_039, 1000, 0 }, - /*0x1b*/ { BODY_DD_SHOCK_INF, L_OPTIONS_040, 1000, 0 }, - /*0x1c*/ { BODY_SECRETARY, L_OPTIONS_041, 1000, 0 }, - /*0x1d*/ { BODY_OFFICEWORKER, L_OPTIONS_042, 1000, MPFEATURE_CHR_OFFICEWORKER }, - /*0x1e*/ { BODY_OFFICEWORKER2, L_OPTIONS_043, 1000, MPFEATURE_CHR_OFFICEWORKER }, - /*0x1f*/ { BODY_NEGOTIATOR, L_OPTIONS_044, 1000, MPFEATURE_CHR_VILLACHRS }, - /*0x20*/ { BODY_DDSNIPER, L_OPTIONS_045, HEAD_DDSNIPER, MPFEATURE_CHR_VILLACHRS }, - /*0x21*/ { BODY_G5_GUARD, L_OPTIONS_046, 1000, MPFEATURE_CHR_G5 }, - /*0x22*/ { BODY_G5_SWAT_GUARD, L_OPTIONS_047, 1000, MPFEATURE_CHR_G5 }, - /*0x23*/ { BODY_CIAGUY, L_OPTIONS_048, 1000, MPFEATURE_CHR_CIAFBI }, - /*0x24*/ { BODY_FBIGUY, L_OPTIONS_049, 1000, MPFEATURE_CHR_CIAFBI }, - /*0x25*/ { BODY_AREA51GUARD, L_OPTIONS_050, 1000, MPFEATURE_CHR_INFILTRATION }, - /*0x26*/ { BODY_A51TROOPER, L_OPTIONS_051, 1000, MPFEATURE_CHR_INFILTRATION }, - /*0x27*/ { BODY_A51AIRMAN, L_OPTIONS_052, 1000, MPFEATURE_CHR_INFILTRATION }, - /*0x28*/ { BODY_OVERALL, L_OPTIONS_053, 1000, MPFEATURE_CHR_INFILTRATION }, - /*0x29*/ { BODY_STRIPES, L_OPTIONS_054, 1000, MPFEATURE_CHR_STRIPES }, - /*0x2a*/ { BODY_LABTECH, L_OPTIONS_055, 1000, MPFEATURE_CHR_LABTECH }, - /*0x2b*/ { BODY_FEMLABTECH, L_OPTIONS_056, 1000, MPFEATURE_CHR_LABTECH }, - /*0x2c*/ { BODY_DD_LABTECH, L_OPTIONS_057, 1000, MPFEATURE_CHR_LABTECH }, - /*0x2d*/ { BODY_BIOTECH, L_OPTIONS_058, HEAD_BIOTECH, MPFEATURE_CHR_BIOTECH }, - /*0x2e*/ { BODY_ALASKAN_GUARD, L_OPTIONS_059, 1000, MPFEATURE_CHR_ALASKANGUARD }, - /*0x2f*/ { BODY_PILOTAF1, L_OPTIONS_060, 1000, MPFEATURE_CHR_AF1 }, - /*0x30*/ { BODY_STEWARD, L_OPTIONS_061, 1000, MPFEATURE_CHR_AF1 }, - /*0x31*/ { BODY_STEWARDESS, L_OPTIONS_062, 1000, MPFEATURE_CHR_AF1 }, - /*0x32*/ { BODY_STEWARDESS_COAT, L_OPTIONS_063, 1000, MPFEATURE_CHR_AF1 }, - /*0x33*/ { BODY_PRESIDENT, L_OPTIONS_064, HEAD_PRESIDENT, MPFEATURE_CHR_CI }, - /*0x34*/ { BODY_NSA_LACKEY, L_OPTIONS_065, 1000, MPFEATURE_CHR_NSALACKEY }, - /*0x35*/ { BODY_PRES_SECURITY, L_OPTIONS_066, 1000, MPFEATURE_CHR_PRESSECURITY }, - /*0x36*/ { BODY_PRESIDENT_CLONE2, L_OPTIONS_067, HEAD_PRESIDENT, MPFEATURE_CHR_PRESCLONE }, - /*0x37*/ { BODY_PELAGIC_GUARD, L_OPTIONS_068, 1000, MPFEATURE_CHR_PELAGIC }, - /*0x38*/ { BODY_MAIAN_SOLDIER, L_OPTIONS_069, HEAD_MAIAN_S, MPFEATURE_CHR_ELVIS }, - /*0x39*/ { BODY_CONNERY, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, - /*0x3a*/ { BODY_MOORE, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, - /*0x3b*/ { BODY_DALTON, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, - /*0x3c*/ { BODY_DJBOND, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, + /*0x07*/ { BODY_DARKWET, L_OPTIONS_021, HEAD_DARKAQUA, MPFEATURE_CHR_PELAGIC }, + /*0x08*/ { BODY_DARKAQUALUNG, L_OPTIONS_022, HEAD_DARKAQUA, MPFEATURE_CHR_PELAGIC }, + /*0x09*/ { BODY_DARKSNOW, L_OPTIONS_023, HEAD_DARK_SNOW, MPFEATURE_CHR_DARKSNOW }, + /*0x0a*/ { BODY_DARKLAB, L_OPTIONS_024, HEAD_DARK_COMBAT, MPFEATURE_CHR_INFILTRATION }, + /*0x0b*/ { BODY_THEKING, L_OPTIONS_025, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, + /*0x0c*/ { BODY_ELVIS1, L_OPTIONS_026, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, + /*0x0d*/ { BODY_ELVISWAISTCOAT, L_MPWEAPONS_158, HEAD_ELVIS, MPFEATURE_CHR_ELVIS }, + /*0x0e*/ { BODY_CARRINGTON, L_OPTIONS_027, HEAD_CARRINGTON, 0 }, + /*0x0f*/ { BODY_CARREVENINGSUIT, L_OPTIONS_028, HEAD_CARRINGTON, MPFEATURE_CHR_CI }, + /*0x10*/ { BODY_MRBLONDE, L_OPTIONS_029, HEAD_MRBLONDE, MPFEATURE_CHR_MRBLONDE }, + /*0x11*/ { BODY_CASSANDRA, L_OPTIONS_030, HEAD_CASSANDRA, 0 }, + /*0x12*/ { BODY_TRENT, L_OPTIONS_031, HEAD_TRENT, MPFEATURE_CHR_TRENT }, + /*0x13*/ { BODY_JONATHAN, L_OPTIONS_032, HEAD_JONATHAN, MPFEATURE_CHR_JONATHAN }, + /*0x14*/ { BODY_CILABTECH, L_OPTIONS_033, 1000, 0 }, + /*0x15*/ { BODY_CIFEMTECH, L_OPTIONS_034, 1000, 0 }, + /*0x16*/ { BODY_CISOLDIER, L_OPTIONS_035, 1000, 0 }, + /*0x17*/ { BODY_DDSHOCK, L_OPTIONS_036, HEAD_DDSHOCK, 0 }, + /*0x18*/ { BODY_FEM_GUARD, L_OPTIONS_037, 1000, MPFEATURE_CHR_FEMGUARD }, + /*0x19*/ { BODY_DD_SECGUARD, L_OPTIONS_038, 1000, 0 }, + /*0x1a*/ { BODY_DD_GUARD, L_OPTIONS_039, 1000, 0 }, + /*0x1b*/ { BODY_DD_SHOCK_INF, L_OPTIONS_040, 1000, 0 }, + /*0x1c*/ { BODY_SECRETARY, L_OPTIONS_041, 1000, 0 }, + /*0x1d*/ { BODY_OFFICEWORKER, L_OPTIONS_042, 1000, MPFEATURE_CHR_OFFICEWORKER }, + /*0x1e*/ { BODY_OFFICEWORKER2, L_OPTIONS_043, 1000, MPFEATURE_CHR_OFFICEWORKER }, + /*0x1f*/ { BODY_NEGOTIATOR, L_OPTIONS_044, 1000, MPFEATURE_CHR_VILLACHRS }, + /*0x20*/ { BODY_DDSNIPER, L_OPTIONS_045, HEAD_DDSNIPER, MPFEATURE_CHR_VILLACHRS }, + /*0x21*/ { BODY_G5_GUARD, L_OPTIONS_046, 1000, MPFEATURE_CHR_G5 }, + /*0x22*/ { BODY_G5_SWAT_GUARD, L_OPTIONS_047, 1000, MPFEATURE_CHR_G5 }, + /*0x23*/ { BODY_CIAGUY, L_OPTIONS_048, 1000, MPFEATURE_CHR_CIAFBI }, + /*0x24*/ { BODY_FBIGUY, L_OPTIONS_049, 1000, MPFEATURE_CHR_CIAFBI }, + /*0x25*/ { BODY_AREA51GUARD, L_OPTIONS_050, 1000, MPFEATURE_CHR_INFILTRATION }, + /*0x26*/ { BODY_A51TROOPER, L_OPTIONS_051, 1000, MPFEATURE_CHR_INFILTRATION }, + /*0x27*/ { BODY_A51AIRMAN, L_OPTIONS_052, 1000, MPFEATURE_CHR_INFILTRATION }, + /*0x28*/ { BODY_OVERALL, L_OPTIONS_053, 1000, MPFEATURE_CHR_INFILTRATION }, + /*0x29*/ { BODY_STRIPES, L_OPTIONS_054, 1000, MPFEATURE_CHR_STRIPES }, + /*0x2a*/ { BODY_LABTECH, L_OPTIONS_055, 1000, MPFEATURE_CHR_LABTECH }, + /*0x2b*/ { BODY_FEMLABTECH, L_OPTIONS_056, 1000, MPFEATURE_CHR_LABTECH }, + /*0x2c*/ { BODY_DD_LABTECH, L_OPTIONS_057, 1000, MPFEATURE_CHR_LABTECH }, + /*0x2d*/ { BODY_BIOTECH, L_OPTIONS_058, HEAD_BIOTECH, MPFEATURE_CHR_BIOTECH }, + /*0x2e*/ { BODY_ALASKAN_GUARD, L_OPTIONS_059, 1000, MPFEATURE_CHR_ALASKANGUARD }, + /*0x2f*/ { BODY_PILOTAF1, L_OPTIONS_060, 1000, MPFEATURE_CHR_AF1 }, + /*0x30*/ { BODY_STEWARD, L_OPTIONS_061, 1000, MPFEATURE_CHR_AF1 }, + /*0x31*/ { BODY_STEWARDESS, L_OPTIONS_062, 1000, MPFEATURE_CHR_AF1 }, + /*0x32*/ { BODY_STEWARDESS_COAT, L_OPTIONS_063, 1000, MPFEATURE_CHR_AF1 }, + /*0x33*/ { BODY_PRESIDENT, L_OPTIONS_064, HEAD_PRESIDENT, MPFEATURE_CHR_CI }, + /*0x34*/ { BODY_NSA_LACKEY, L_OPTIONS_065, 1000, MPFEATURE_CHR_NSALACKEY }, + /*0x35*/ { BODY_PRES_SECURITY, L_OPTIONS_066, 1000, MPFEATURE_CHR_PRESSECURITY }, + /*0x36*/ { BODY_PRESIDENT_CLONE2, L_OPTIONS_067, HEAD_PRESIDENT, MPFEATURE_CHR_PRESCLONE }, + /*0x37*/ { BODY_PELAGIC_GUARD, L_OPTIONS_068, 1000, MPFEATURE_CHR_PELAGIC }, + /*0x38*/ { BODY_MAIAN_SOLDIER, L_OPTIONS_069, HEAD_MAIAN_S, MPFEATURE_CHR_ELVIS }, + /*0x39*/ { BODY_CONNERY, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, + /*0x3a*/ { BODY_MOORE, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, + /*0x3b*/ { BODY_DALTON, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, + /*0x3c*/ { BODY_DJBOND, L_OPTIONS_070, 1000, MPFEATURE_8BOTS }, }; u32 g_MpMaleHeads[] = { @@ -1921,7 +1918,7 @@ void mpCalculateAwards(void) s32 j; s32 prevplayernum; s32 duration60; - struct awardmetrics metrics[4]; + struct awardmetrics metrics[MAX_PLAYERS]; // @bug: playerrankings should have 12 elements. Because it's too small, // overflow occurs in mpGetPlayerRankings. The overflow writes into the @@ -2413,12 +2410,12 @@ void mpEndMatch(void) s32 mpGetNumHeads2(void) { - return NUM_MPHEADS; + return ARRAYCOUNT(g_MpHeads); } s32 mpGetNumHeads(void) { - return NUM_MPHEADS; + return ARRAYCOUNT(g_MpHeads); } s32 mpGetHeadId(u8 headnum) @@ -2438,18 +2435,22 @@ s32 mpGetBeauHeadId(u8 headnum) s32 mpGetNumBeauHeads(void) { - return NUM_MPBEAUHEADS; + return ARRAYCOUNT(g_MpBeauHeads); } u32 mpGetNumBodies(void) { - return NUM_MPBODIES; + return ARRAYCOUNT(g_MpBodies); } s32 mpGetBodyId(u8 bodynum) { - if (bodynum >= 62) { - if (bodynum == 62) { + /** + * @bug: bodynum 61 (0x3d) would cause an array overflow. + * ARRAYCOUNT(g_MpBodies) is 61. + */ + if (bodynum > ARRAYCOUNT(g_MpBodies)) { + if (bodynum == ARRAYCOUNT(g_MpBodies) + 1) { return BODY_DRCAROLL; } @@ -2464,37 +2465,36 @@ s32 mpGetMpbodynumByBodynum(u16 bodynum) s32 i; if (bodynum == BODY_DRCAROLL) { - return 62; // NUM_MPBODIES + 1 + return ARRAYCOUNT(g_MpBodies) + 1; } - for (i = 0; i != NUM_MPBODIES; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpBodies); i++) { if (g_MpBodies[i].bodynum == bodynum) { return i; } } - // @bug: Should return 0 as a fallback, not the first body's bodynum return g_MpBodies[0].bodynum; } char *mpGetBodyName(u8 mpbodynum) { - // Possible @bug: This should probably be >= - if (mpbodynum > NUM_MPBODIES) { + // @bug: This should be >= + if (mpbodynum > ARRAYCOUNT(g_MpBodies)) { mpbodynum = 0; } return langGet(g_MpBodies[mpbodynum].name); } -u8 mpGetBodyRequiredFeature(u8 bodynum) +u8 mpGetBodyRequiredFeature(u8 mpbodynum) { - // Possible @bug: This should probably be >= - if (bodynum > NUM_MPBODIES) { - bodynum = 0; + // @bug: This should be >= + if (mpbodynum > ARRAYCOUNT(g_MpBodies)) { + mpbodynum = 0; } - return g_MpBodies[bodynum].requirefeature; + return g_MpBodies[mpbodynum].requirefeature; } s32 mpGetMpheadnumByMpbodynum(s32 mpbodynum) @@ -2536,8 +2536,8 @@ void mpFindUnusedHeadAndBody(u8 *mpheadnum, u8 *mpbodynum) do { available = true; - trympheadnum = random() % NUM_MPHEADS; - trympbodynum = random() % NUM_MPBODIES; + trympheadnum = random() % ARRAYCOUNT(g_MpHeads); + trympbodynum = random() % ARRAYCOUNT(g_MpBodies); for (i = 0; i < MAX_MPCHRS; i++) { if (g_MpSetup.chrslots & (1 << i)) { @@ -2628,7 +2628,7 @@ void mpCalculateLockIfLastWinnerOrLoser(void) } } -struct mptrack g_MpTracks[NUM_MPTRACKS] = { +struct mptrack g_MpTracks[] = { // Audio ID, duration, name, unlock after stage /*0x00*/ { MUSIC_DARK_COMBAT, 160, L_MISC_124, -1 }, // "Dark Combat" /*0x01*/ { MUSIC_SKEDAR_MYSTERY, 170, L_MISC_125, -1 }, // "Skedar Mystery" @@ -2680,7 +2680,7 @@ bool mpIsTrackUnlocked(s32 tracknum) bool unlocked = false; u32 i; - if (stageindex < 0 || stageindex >= NUM_SOLONORMALSTAGES) { + if (stageindex < 0 || stageindex > SOLOSTAGEINDEX_SKEDARRUINS) { unlocked = true; } else { for (i = 0; i != 3; i++) { @@ -2713,7 +2713,7 @@ s32 mpGetTrackNumAtSlotIndex(s32 slotindex) s32 i; s32 numunlocked = 0; - for (i = 0; i != NUM_MPTRACKS; i++) { + for (i = 0; i != ARRAYCOUNT(g_MpTracks); i++) { if (mpIsTrackUnlocked(i)) { if (numunlocked == slotindex) { break; @@ -2728,7 +2728,7 @@ s32 mpGetTrackNumAtSlotIndex(s32 slotindex) s32 mpGetNumUnlockedTracks(void) { - return mpGetTrackSlotIndex(NUM_MPTRACKS); + return mpGetTrackSlotIndex(ARRAYCOUNT(g_MpTracks)); } s32 mpGetTrackMusicNum(s32 slotindex) @@ -2794,7 +2794,7 @@ void mpEnableAllMultiTracks(void) { s32 i; - for (i = 0; i != 6; i++) { + for (i = 0; i != ARRAYCOUNT(g_BossFile.multipletracknums); i++) { g_BossFile.multipletracknums[i] = 0xff; } } @@ -2803,7 +2803,7 @@ void mpDisableAllMultiTracks(void) { s32 i; - for (i = 0; i != 6; i++) { + for (i = 0; i != ARRAYCOUNT(g_BossFile.multipletracknums); i++) { g_BossFile.multipletracknums[i] = 0; } } @@ -2812,7 +2812,7 @@ void mpRandomiseMultiTracks(void) { s32 i; - for (i = 0; i != 6; i++) { + for (i = 0; i != ARRAYCOUNT(g_BossFile.multipletracknums); i++) { g_BossFile.multipletracknums[i] = random(); } } @@ -3004,7 +3004,7 @@ void mpCreateBotFromProfile(s32 botnum, u8 profilenum) g_BotConfigsArray[botnum].type = g_BotProfiles[profilenum].type; g_BotConfigsArray[botnum].difficulty = g_BotProfiles[profilenum].difficulty; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpSimulantDifficultiesPerNumPlayers[botnum][i] = g_BotConfigsArray[botnum].difficulty; } @@ -3037,7 +3037,7 @@ void mpSetBotDifficulty(s32 botnum, s32 difficulty) g_BotConfigsArray[botnum].difficulty = difficulty; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpSimulantDifficultiesPerNumPlayers[botnum][i] = g_BotConfigsArray[botnum].difficulty; } } @@ -3227,7 +3227,7 @@ s32 func0f18d074(s32 index) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (&g_PlayerConfigsArray[i].base == g_MpAllChrConfigPtrs[index]) { return i; } @@ -3355,8 +3355,8 @@ void mpplayerfileLoadWad(s32 playernum, struct savebuffer *buffer, s32 arg2) g_PlayerConfigsArray[playernum].controlmode = savebufferReadBits(buffer, 2); g_PlayerConfigsArray[playernum].options = savebufferReadBits(buffer, 12); - for (i = 0; i < 30; i++) { - for (j = 1; j < 5; j++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j < MAX_PLAYERS + 1; j++) { challengeSetCompletedByPlayerWithNumPlayers(playernum, i, j, savebufferReadBits(buffer, 1)); } } @@ -3488,8 +3488,8 @@ void mpplayerfileSaveWad(s32 playernum, struct savebuffer *buffer) savebufferOr(buffer, g_PlayerConfigsArray[playernum].controlmode, 2); savebufferOr(buffer, g_PlayerConfigsArray[playernum].options, 12); - for (i = 0; i < 30; i++) { - for (j = 1; j < 5; j++) { + for (i = 0; i < ARRAYCOUNT(g_MpChallenges); i++) { + for (j = 1; j < MAX_PLAYERS + 1; j++) { savebufferOr(buffer, challengeIsCompletedByPlayerWithNumPlayers(playernum, i, j), 1); } } @@ -3563,7 +3563,7 @@ s32 mpplayerfileLoad(s32 playernum, s32 device, s32 fileid, u16 deviceserial) return -1; } -struct mppreset g_MpPresets[NUM_MPPRESETS] = { +struct mppreset g_MpPresets[] = { { L_MPWEAPONS_025, MPCONFIG_NOSHIELD }, // "No Shield" { L_MPWEAPONS_026, MPCONFIG_AUTOMATICS }, // "Automatics" { L_MPWEAPONS_027, MPCONFIG_ROCKETS }, // "Rocket Launcher" @@ -3582,14 +3582,14 @@ struct mppreset g_MpPresets[NUM_MPPRESETS] = { s32 mpGetNumPresets(void) { - return NUM_MPPRESETS; + return ARRAYCOUNT(g_MpPresets); } bool mpIsPresetUnlocked(s32 presetnum) { s32 i; - for (i = 0; i != 16; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpPresets[presetnum].requirefeatures); i++) { if (!challengeIsFeatureUnlocked(g_MpPresets[presetnum].requirefeatures[i]) && g_MpPresets[presetnum].requirefeatures[i] != MPFEATURE_WEAPON_SHIELD) { return false; @@ -3604,7 +3604,7 @@ s32 mpGetNumUnlockedPresets(void) s32 numunlocked = 0; s32 i; - for (i = 0; i != NUM_MPPRESETS; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpPresets); i++) { if (mpIsPresetUnlocked(i)) { numunlocked++; } @@ -3617,7 +3617,7 @@ char *mpGetPresetNameBySlot(s32 slot) { s32 i; - for (i = 0; i != 14; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpPresets); i++) { if (mpIsPresetUnlocked(i)) { if (slot == 0) { return langGet(g_MpPresets[i].name); @@ -3678,7 +3678,7 @@ void mpApplyConfig(struct mpconfigfull *config) for (i = 0; i < MAX_BOTS; i++) { g_BotConfigsArray[i].type = config->config.simulants[i].type; - for (j = 0; j < 4; j++) { + for (j = 0; j < MAX_PLAYERS; j++) { g_MpSimulantDifficultiesPerNumPlayers[i][j] = config->config.simulants[i].difficulties[j]; } @@ -3701,7 +3701,7 @@ void mpApplyConfig(struct mpconfigfull *config) } if (!challengeIsFeatureUnlocked(MPFEATURE_WEAPON_SHIELD)) { - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) { if (g_MpSetup.weapons[i] == MPWEAPON_SHIELD) { g_MpSetup.weapons[i] = MPWEAPON_NONE; } @@ -3719,7 +3719,7 @@ void mp0f18dec4(s32 slot) s32 confignum = 0; u32 i; - for (i = 0; i < 14; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpPresets); i++) { if (mpIsPresetUnlocked(i)) { if (slot == 0) { confignum = g_MpPresets[i].confignum; @@ -3767,7 +3767,7 @@ void mpsetupfileLoadWad(struct savebuffer *buffer) g_BotConfigsArray[i].type = savebufferReadBits(buffer, 5); g_BotConfigsArray[i].difficulty = savebufferReadBits(buffer, 3); - for (j = 0; j < 4; j++) { + for (j = 0; j < MAX_PLAYERS; j++) { g_MpSimulantDifficultiesPerNumPlayers[i][j] = g_BotConfigsArray[i].difficulty; } @@ -3782,7 +3782,7 @@ void mpsetupfileLoadWad(struct savebuffer *buffer) mpGenerateBotNames(); - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) { g_MpSetup.weapons[i] = savebufferReadBits(buffer, 7); } @@ -3792,7 +3792,7 @@ void mpsetupfileLoadWad(struct savebuffer *buffer) g_MpSetup.scorelimit = savebufferReadBits(buffer, 7); g_MpSetup.teamscorelimit = savebufferReadBits(buffer, 9); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].base.team = savebufferReadBits(buffer, 3); } @@ -3848,7 +3848,7 @@ void mpsetupfileSaveWad(struct savebuffer *buffer) savebufferOr(buffer, g_BotConfigsArray[i].base.team, 3); } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_MpSetup.weapons); i++) { savebufferOr(buffer, g_MpSetup.weapons[i], 7); } @@ -3856,7 +3856,7 @@ void mpsetupfileSaveWad(struct savebuffer *buffer) savebufferOr(buffer, g_MpSetup.scorelimit, 7); savebufferOr(buffer, g_MpSetup.teamscorelimit, 9); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { savebufferOr(buffer, g_PlayerConfigsArray[i].base.team, 3); } } diff --git a/src/game/mplayer/scenarios.c b/src/game/mplayer/scenarios.c index 1a1275514..4ee3e806c 100644 --- a/src/game/mplayer/scenarios.c +++ b/src/game/mplayer/scenarios.c @@ -1160,7 +1160,7 @@ s32 scenarioPickUpBriefcase(struct chrdata *chr, struct prop *prop) // their home case. ie. A point has just been scored mpchr->numpoints++; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.tokens); i++) { if (g_ScenarioData.ctc.tokens[i] == chr->prop) { break; } @@ -1354,7 +1354,7 @@ void scenarioHandleDroppedToken(struct chrdata *chr, struct prop *prop) s16 rooms[2]; if (g_MpSetup.scenario == MPSCENARIO_CAPTURETHECASE) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.tokens); i++) { if (chr->prop == g_ScenarioData.ctc.tokens[i]) { objFreeProjectile(&weapon->base); diff --git a/src/game/mplayer/scenarios/capturethecase.inc b/src/game/mplayer/scenarios/capturethecase.inc index 7b9a74b1b..652561aca 100644 --- a/src/game/mplayer/scenarios/capturethecase.inc +++ b/src/game/mplayer/scenarios/capturethecase.inc @@ -122,17 +122,17 @@ void ctcInit(void) s32 i, j, k; g_MpSetup.options |= MPOPTION_TEAMSENABLED; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.spawnpadsperteam); i++) { s32 j; g_ScenarioData.ctc.spawnpadsperteam[i].homepad = i; g_ScenarioData.ctc.spawnpadsperteam[i].numspawnpads = 0; - for (j = 0; j < 6; j++) { + for (j = 0; j < ARRAYCOUNT(g_ScenarioData.ctc.spawnpadsperteam[i].spawnpads); j++) { g_ScenarioData.ctc.spawnpadsperteam[i].spawnpads[j] = -1; } } - for (i = 0; i != 4; i++) { + for (i = 0; i != ARRAYCOUNT(g_ScenarioData.ctc.playercountsperteam); i++) { g_ScenarioData.ctc.playercountsperteam[i] = 0; g_ScenarioData.ctc.teamindexes[i] = -1; } @@ -169,7 +169,7 @@ void ctcInitProps(void) struct weaponobj *tmp; s32 mpindex; u32 stack; - bool teamsdone[4]; + bool teamsdone[ARRAYCOUNT(g_ScenarioData.ctc.playercountsperteam)]; struct weaponobj template = { 256, // extrascale @@ -208,17 +208,17 @@ void ctcInitProps(void) s32 j; s32 k; - for (i = 0; i < 4; i++) { - for (j = 0; j < 6; j++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.spawnpadsperteam); i++) { + for (j = 0; j < ARRAYCOUNT(g_ScenarioData.ctc.spawnpadsperteam[i].spawnpads); j++) { } } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(teamsdone); i++) { teamsdone[i] = false; g_ScenarioData.ctc.playercountsperteam[i] = 0; } - for (i = 0; i != 4; i++) { + for (i = 0; i != ARRAYCOUNT(g_ScenarioData.ctc.teamindexes); i++) { do { g_ScenarioData.ctc.teamindexes[i] = random() % 4; } while (teamsdone[g_ScenarioData.ctc.teamindexes[i]]); @@ -258,21 +258,21 @@ void ctcInitProps(void) } } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.playercountsperteam); i++) { if (g_ScenarioData.ctc.playercountsperteam[i] == 0) { g_ScenarioData.ctc.teamindexes[i] = -1; } } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.teamindexes); i++) { // empty } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.tokens); i++) { g_ScenarioData.ctc.tokens[i] = NULL; } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.baserooms); i++) { g_ScenarioData.ctc.baserooms[i] = -1; } @@ -336,7 +336,7 @@ void ctcInitProps(void) g_ScenarioData.ctc.baserooms[3] = g_ScenarioData.ctc.tokens[3]->rooms[0]; } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.playercountsperteam); i++) { if (g_ScenarioData.ctc.playercountsperteam[i] && g_ScenarioData.ctc.baserooms[i] != -1) { roomSetLightOp(g_ScenarioData.ctc.baserooms[i], LIGHTOP_HIGHLIGHT, 0, 0, 0); } @@ -481,7 +481,7 @@ bool ctcIsRoomHighlighted(s16 room) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.teamindexes); i++) { if (g_ScenarioData.ctc.baserooms[i] == room && g_ScenarioData.ctc.teamindexes[i] != -1) { return true; } @@ -494,7 +494,7 @@ void ctcHighlightRoom(s16 roomnum, s32 *arg1, s32 *arg2, s32 *arg3) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.ctc.baserooms); i++) { if (g_ScenarioData.ctc.baserooms[i] == roomnum) { u32 colour = g_TeamColours[i]; f32 a = *arg1; diff --git a/src/game/mplayer/scenarios/kingofthehill.inc b/src/game/mplayer/scenarios/kingofthehill.inc index 2c86fb3ed..ae926e975 100644 --- a/src/game/mplayer/scenarios/kingofthehill.inc +++ b/src/game/mplayer/scenarios/kingofthehill.inc @@ -176,7 +176,7 @@ void kohInit(void) g_ScenarioData.koh.colourfracg = 1; g_ScenarioData.koh.colourfracb = 0.25; - for (i = 0; i < 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_ScenarioData.koh.hillpads); i++) { g_ScenarioData.koh.hillpads[i] = -1; } } @@ -229,7 +229,7 @@ void kohTick(void) f32 targetg; f32 targetb; char text[64]; - s32 teamsinhill[8]; + s32 teamsinhill[MAX_TEAMS]; struct pad pad; struct prop *chrsinhill[MAX_MPCHRS]; struct prop *prop; @@ -333,7 +333,7 @@ void kohTick(void) // chrs in the hill. During development, this array likely stored a // count of that team's chrs but was later changed to just be 0 or 1 // to denote if they have any chrs in the hill. - for (s0 = 0; s0 < 8; s0++) { + for (s0 = 0; s0 < ARRAYCOUNT(teamsinhill); s0++) { teamsinhill[s0] = 0; } @@ -353,7 +353,7 @@ void kohTick(void) } else { if (numteamsinhill == 1) { // Set hillteam for later - for (hillteam = 0; hillteam < 8; hillteam++) { + for (hillteam = 0; hillteam < MAX_TEAMS; hillteam++) { if (teamsinhill[hillteam]) { break; } @@ -365,13 +365,13 @@ void kohTick(void) // only contains values 0 or 1 so it effectively does nothing. mostchrs = 0; - for (s0 = 0; s0 < 8; s0++) { + for (s0 = 0; s0 < MAX_TEAMS; s0++) { if (teamsinhill[s0] > mostchrs) { mostchrs = teamsinhill[s0]; } } - for (s0 = 0; s0 < 8; s0++) { + for (s0 = 0; s0 < MAX_TEAMS; s0++) { if (teamsinhill[s0] != mostchrs) { teamsinhill[s0] = false; } @@ -381,7 +381,7 @@ void kohTick(void) // the hill. Or rather, because the teamsinhill array only // contains 0 or 1 values, this is just recounting the number of // teams who have presence in the hill. - for (s0 = 0; s0 < 8; s0++) { + for (s0 = 0; s0 < MAX_TEAMS; s0++) { if (teamsinhill[s0]) { dualoccupancy++; } @@ -391,7 +391,7 @@ void kohTick(void) // Set the hillteam to whoever was holding it previously // so the hill remains the same colour - for (hillteam = 0; hillteam < 8; hillteam++) { + for (hillteam = 0; hillteam < MAX_TEAMS; hillteam++) { if (teamsinhill[hillteam] && hillteam == g_ScenarioData.koh.occupiedteam) { break; } diff --git a/src/game/mplayer/setup.c b/src/game/mplayer/setup.c index 4d9233118..7656332f4 100644 --- a/src/game/mplayer/setup.c +++ b/src/game/mplayer/setup.c @@ -704,7 +704,7 @@ MenuItemHandlerResult mpChallengesListHandler(s32 operation, struct menuitem *it gdl = text0f153628(gdl); - name = xhallengeGetName(g_MpPlayerNum, challengeindex); + name = challengeGetName2(g_MpPlayerNum, challengeindex); gdl = textRenderProjected(gdl, &x, &y, name, g_CharsHandelGothicSm, g_FontHandelGothicSm, renderdata->colour, @@ -1190,7 +1190,7 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, MENUITEMFLAG_DROPDOWN_BELOW | MENUITEMFLAG_LOCKABLEMINOR | MENUITEMFLAG_MPWEAPONSLOT, L_MPMENU_177, // "2:" - 0x00000001, + 1, menuhandlerMpWeaponSlot, }, { @@ -1198,7 +1198,7 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, MENUITEMFLAG_DROPDOWN_BELOW | MENUITEMFLAG_LOCKABLEMINOR | MENUITEMFLAG_MPWEAPONSLOT, L_MPMENU_178, // "3:" - 0x00000002, + 2, menuhandlerMpWeaponSlot, }, { @@ -1206,7 +1206,7 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, MENUITEMFLAG_DROPDOWN_BELOW | MENUITEMFLAG_LOCKABLEMINOR | MENUITEMFLAG_MPWEAPONSLOT, L_MPMENU_179, // "4:" - 0x00000003, + 3, menuhandlerMpWeaponSlot, }, { @@ -1214,7 +1214,7 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, MENUITEMFLAG_DROPDOWN_BELOW | MENUITEMFLAG_LOCKABLEMINOR | MENUITEMFLAG_MPWEAPONSLOT, L_MPMENU_180, // "5:" - 0x00000004, + 4, menuhandlerMpWeaponSlot, }, { @@ -1222,7 +1222,7 @@ struct menuitem g_MpWeaponsMenuItems[] = { 0, MENUITEMFLAG_DROPDOWN_BELOW | MENUITEMFLAG_LOCKABLEMINOR | MENUITEMFLAG_MPWEAPONSLOT, L_MPMENU_181, // "6:" - 0x00000005, + 5, menuhandlerMpWeaponSlot, }, { @@ -2154,7 +2154,7 @@ MenuItemHandlerResult mpLoadPlayerMenuHandler(s32 operation, struct menuitem *it file = &g_FileLists[0]->files[data->list.value]; available = true; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (file->fileid == g_PlayerConfigsArray[i].fileguid.fileid && file->deviceserial == g_PlayerConfigsArray[i].fileguid.deviceserial) { if ((g_MpSetup.chrslots & (1 << i)) == 0) { @@ -2296,7 +2296,7 @@ MenuItemHandlerResult menuhandlerMpRestoreHandicapDefaults(s32 operation, struct if (operation == MENUOP_SET) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].handicap = 0x80; } } @@ -4826,7 +4826,7 @@ void mpConfigureQuickTeamPlayers(void) case MPQUICKTEAM_PLAYERSTEAMS: g_MpSetup.options |= MPOPTION_TEAMSENABLED; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].base.team = g_Vars.mpplayerteams[i]; } @@ -4834,7 +4834,7 @@ void mpConfigureQuickTeamPlayers(void) case MPQUICKTEAM_PLAYERSVSSIMS: g_MpSetup.options |= MPOPTION_TEAMSENABLED; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].base.team = 0; } @@ -4842,7 +4842,7 @@ void mpConfigureQuickTeamPlayers(void) case MPQUICKTEAM_PLAYERSIMTEAMS: g_MpSetup.options |= MPOPTION_TEAMSENABLED; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_PlayerConfigsArray[i].base.team = i; } @@ -5039,7 +5039,7 @@ MenuItemHandlerResult mpQuickTeamSimulantDifficultyHandler(s32 operation, struct switch (operation) { case MENUOP_GETOPTIONCOUNT: - for (i = 0; i < 6; i++) { + for (i = 0; i < NUM_BOTDIFFS; i++) { if (challengeIsFeatureUnlocked(g_BotProfiles[i].requirefeature)) { count++; } @@ -5048,7 +5048,7 @@ MenuItemHandlerResult mpQuickTeamSimulantDifficultyHandler(s32 operation, struct data->dropdown.value = count; break; case MENUOP_GETOPTIONTEXT: - for (i = 0; i < 6; i++) { + for (i = 0; i < NUM_BOTDIFFS; i++) { if (challengeIsFeatureUnlocked(g_BotProfiles[i].requirefeature)) { if (count == data->dropdown.value) { return (s32) langGet(i + L_MISC_082); @@ -5065,7 +5065,9 @@ MenuItemHandlerResult mpQuickTeamSimulantDifficultyHandler(s32 operation, struct data->dropdown.value = g_Vars.mpsimdifficulty; break; case MENUOP_CHECKHIDDEN: - if (g_Vars.mpquickteam != 1 && g_Vars.mpquickteam != 3 && g_Vars.mpquickteam != 4) { + if (g_Vars.mpquickteam != MPQUICKTEAM_PLAYERSANDSIMS + && g_Vars.mpquickteam != MPQUICKTEAM_PLAYERSVSSIMS + && g_Vars.mpquickteam != MPQUICKTEAM_PLAYERSIMTEAMS) { return true; } } @@ -5139,7 +5141,7 @@ void mpCloseDialogsForNewSetup(void) s32 k; // Loop through each player - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_MpPlayerNum = i; // If they have a menu open diff --git a/src/game/music.c b/src/game/music.c index 63f30aefa..c6ed3dd5f 100644 --- a/src/game/music.c +++ b/src/game/music.c @@ -221,7 +221,7 @@ void musicReset(void) s32 i; if (!g_SndDisabled) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_AudioXReasonsActive); i++) { g_AudioXReasonsActive[i] = 0; g_MusicXReasonMinDurations[i] = 0; g_MusicXReasonMaxDurations[i] = 0; @@ -680,7 +680,7 @@ void musicUnsetXReason(s32 reason) if (reason >= 0) { g_AudioXReasonsActive[reason] = false; } else { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_AudioXReasonsActive); i++) { g_AudioXReasonsActive[i] = false; g_MusicXReasonMinDurations[i] = 0; g_MusicXReasonMaxDurations[i] = 0; diff --git a/src/game/nbomb.c b/src/game/nbomb.c index 6d3ff25f6..dbbeb2227 100644 --- a/src/game/nbomb.c +++ b/src/game/nbomb.c @@ -573,7 +573,7 @@ void nbombsTick(void) g_NbombsActive = false; } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Nbombs); i++) { if (g_Vars.lvupdate240 != 0 && g_Nbombs[i].age240 >= 0) { nbombTick(&g_Nbombs[i]); @@ -621,7 +621,7 @@ void nbombsTick(void) } if (g_Vars.lvupdate240 == 0) { - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Nbombs); i++) { if (g_Nbombs[i].age240 >= 0) { if (g_Nbombs[i].audiohandle20 && sndGetState(g_Nbombs[i].audiohandle20) != AL_STOPPED) { audioStop(g_Nbombs[i].audiohandle20); @@ -646,7 +646,7 @@ Gfx *nbombsRender(Gfx *gdl) s32 i; Gfx *subgdl = NULL; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Nbombs); i++) { if (g_Nbombs[i].age240 >= 0) { if (!subgdl) { subgdl = nbombCreateGdl(); @@ -671,7 +671,7 @@ void nbombCreateStorm(struct coord *pos, struct prop *ownerprop) g_NbombsActive = true; - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAYCOUNT(g_Nbombs); i++) { if (g_Nbombs[i].age240 == -1 #if VERSION >= VERSION_NTSC_1_0 && g_Nbombs[i].audiohandle20 == NULL @@ -910,18 +910,18 @@ Gfx *gasRender(Gfx *gdl) bool drawn = false; const s32 gasrooms[] = { - 0x92, - 0x93, - 0x94, - 0x95, - 0x96, - 0x97, - 0x98, - 0x99, - 0x9a, - 0x91, - 0x8f, - 0x90, + ROOM_LUE_0092, + ROOM_LUE_0093, + ROOM_LUE_0094, + ROOM_LUE_0095, + ROOM_LUE_0096, + ROOM_LUE_0097, + ROOM_LUE_0098, + ROOM_LUE_0099, + ROOM_LUE_009A, + ROOM_LUE_0091, + ROOM_LUE_008F, + ROOM_LUE_0090, }; if (g_Vars.stagenum == STAGE_ESCAPE) { @@ -931,7 +931,7 @@ Gfx *gasRender(Gfx *gdl) campos.y = g_Vars.currentplayer->cam_pos.y; campos.z = g_Vars.currentplayer->cam_pos.z; - for (i = 0; i < 12; i++) { + for (i = 0; i < ARRAYCOUNT(gasrooms); i++) { if (bgRoomContainsCoord(&campos, gasrooms[i])) { show = true; } diff --git a/src/game/pak.c b/src/game/pak.c index 0e914c9c5..0361f980d 100644 --- a/src/game/pak.c +++ b/src/game/pak.c @@ -218,13 +218,13 @@ const char g_N64FontCodeMap[] = "\0************** 0123456789ABCDEFGHIJKLMNOPQRST const char var7f1b3ad4[] = "Pak %d -> Pak_UpdateAndGetPakNoteInfo - ERROR - ekPakErrorPakFatal\n"; const char var7f1b3b18[] = "Pak %d -> Pak_UpdateAndGetPakNoteInfo - ERROR - ekPakErrorNoPakPresent\n"; -struct pak g_Paks[5]; +struct pak g_Paks[5]; // controller paks + EEPROM #if VERSION >= VERSION_NTSC_1_0 u32 var800a317c; #endif -OSPfs g_Pfses[4]; +OSPfs g_Pfses[MAX_PLAYERS]; u32 var800a3320; u32 var800a3324; u32 var800a3328; @@ -1593,11 +1593,11 @@ void paksInit(void) g_Vars.unk0004e4 = 0; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { pakInit(i); } - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { #if VERSION >= VERSION_JPN_FINAL pak0f11a32c(i, 7, 2054, "pak/pak.c"); #elif VERSION >= VERSION_PAL_BETA @@ -1627,13 +1627,13 @@ void paksInit(void) s8 i; s32 j; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { pakInit(i); } g_Vars.paksconnected2 = 0x1f; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { pak0f11a32c(i, 7, 1929, "pak.c"); } @@ -4413,7 +4413,7 @@ void pak0f11c6d0(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { switch (g_Paks[i].unk010) { case PAK010_02: case PAK010_03: @@ -4484,13 +4484,13 @@ void pakExecuteDebugOperations(void) pak0f11ca30(); - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { if (g_Paks[i].unk014) { pak0f11df94(i); } } - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { switch (g_Paks[i].unk010) { case PAK010_02: case PAK010_03: @@ -4550,7 +4550,7 @@ void pakExecuteDebugOperations(void) pak0f11ca30(); pakDumpPak(); - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { if (g_Paks[i].unk014) { pak0f11df94(i); } @@ -4612,7 +4612,7 @@ void pak0f11ca30(void) s32 i; if ((g_Vars.unk0004e4 & 0xf) == 0) { - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { if ((g_Vars.paksconnected2 | g_Vars.paksconnected) & (1 << i)) { if (thing == 0xff) { thing = joyShiftPfsStates(); @@ -4641,7 +4641,7 @@ void pak0f11ca30(void) u8 newvalue = var80075d10; s32 i; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { u32 thisbit = 1 << i; if ((g_Vars.paksconnected2 | g_Vars.paksconnected) & thisbit) { @@ -5362,7 +5362,7 @@ void paksStop(bool disablepolling) { s8 i; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { s32 type = g_Paks[i].type; if (type); @@ -5425,14 +5425,14 @@ void pakDisableRumbleForAllPlayers(void) s32 i; #if VERSION >= VERSION_NTSC_1_0 - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_Paks[i].type == PAKTYPE_RUMBLE) { g_Paks[i].rumblestate = RUMBLESTATE_DISABLED_STOPPING; joyStopRumble(i, true); } } #else - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { pakDisableRumbleForPlayer(i); } #endif @@ -5443,13 +5443,13 @@ void pakEnableRumbleForAllPlayers(void) s32 i; #if VERSION >= VERSION_NTSC_FINAL - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_Paks[i].type == PAKTYPE_RUMBLE && g_Paks[i].rumblestate == RUMBLESTATE_DISABLED_STOPPED) { g_Paks[i].rumblestate = RUMBLESTATE_ENABLING; } } #else - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { pakEnableRumbleForPlayer(i); } #endif @@ -6004,7 +6004,7 @@ s8 pakFindBySerial(s32 findserial) s8 device = -1; s32 i; - for (i = 0; i < 5; i++) { + for (i = 0; i < ARRAYCOUNT(g_Paks); i++) { if (pak0f116aec(i)) { s32 serial = pakGetSerial(i); @@ -6035,7 +6035,7 @@ bool gbpakIsAnyPerfectDark(void) { s8 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (gbpakIdentifyGame(i) == GBGAME_PD) { return true; } diff --git a/src/game/player.c b/src/game/player.c index f850f50c4..f93ffe7db 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -110,7 +110,7 @@ f32 g_CutsceneCurTotalFrame60f; s32 g_CutsceneTweenDuration60; f32 g_CutsceneTweenFrac; // 0 when bars across the top and bottom, 1 when fullscreen u32 var8009de34; -s16 g_SpawnPoints[MAX_SPAWNPOINTS]; +s16 g_SpawnPoints[24]; s32 g_NumSpawnPoints; struct vimode g_ViModes[] = { diff --git a/src/game/playermgr.c b/src/game/playermgr.c index aad0d2c03..869d01dcb 100644 --- a/src/game/playermgr.c +++ b/src/game/playermgr.c @@ -15,7 +15,7 @@ void playermgrInit(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.playerstats[i].damagescale = 1; } @@ -30,14 +30,17 @@ void playermgrReset(void) g_Vars.players[1] = NULL; g_Vars.players[2] = NULL; g_Vars.players[3] = NULL; + g_Vars.currentplayer = NULL; g_Vars.currentplayerindex = 0; g_Vars.currentplayerstats = NULL; g_Vars.currentplayernum = 0; + g_Vars.playerorder[0] = 0; g_Vars.playerorder[1] = 1; g_Vars.playerorder[2] = 2; g_Vars.playerorder[3] = 3; + g_Vars.bond = NULL; g_Vars.coop = NULL; g_Vars.anti = NULL; @@ -432,7 +435,7 @@ void playermgrAllocatePlayer(s32 index) g_Vars.players[index]->aimtype = 0; g_Vars.players[index]->lookingatprop.prop = NULL; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.players[index]->trackedprops[i].prop = NULL; } @@ -588,7 +591,7 @@ void playermgrAllocatePlayer(s32 index) g_Vars.players[index]->introanimnum = 0; g_Vars.players[index]->lastsighton = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.players[index]->targetset[i] = 0; } @@ -599,7 +602,7 @@ void playermgrAllocatePlayer(s32 index) g_Vars.players[index]->model.anim = &g_Vars.players[index]->unk01c0; g_Vars.players[index]->eyespy = NULL; - g_Vars.players[index]->eyespydarts = 8; + g_Vars.players[index]->eyespydarts = MAX_EYESPYDARTS; g_Vars.players[index]->autocontrol_aimpad = 0; g_Vars.players[index]->autocontrol_lookup = 0; @@ -799,13 +802,13 @@ void playermgrShuffle(void) s32 i; // Order them ascending - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { g_Vars.playerorder[i] = i; } // Randomly swap numbers with later elements - for (i = 0; i != 3; i++) { - s32 otherindex = random() % (4 - i); + for (i = 0; i < MAX_PLAYERS - 1; i++) { + s32 otherindex = random() % (MAX_PLAYERS - i); s32 tmp = g_Vars.playerorder[i]; g_Vars.playerorder[i] = g_Vars.playerorder[i + otherindex]; @@ -818,7 +821,7 @@ s32 playermgrGetOrderOfPlayer(s32 playernum) s32 index = 0; s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { s32 thisnum = g_Vars.playerorder[i]; if (playernum == thisnum) { @@ -837,7 +840,7 @@ s32 playermgrGetPlayerAtOrder(s32 ordernum) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (g_Vars.players[g_Vars.playerorder[i]]) { if (ordernum == 0) { return g_Vars.playerorder[i]; diff --git a/src/game/playerreset.c b/src/game/playerreset.c index 90c7bbfcf..0e786b62c 100644 --- a/src/game/playerreset.c +++ b/src/game/playerreset.c @@ -467,8 +467,8 @@ void playerReset(void) g_Vars.currentplayer->tickdiefinished = false; g_Vars.currentplayer->chokehandle = NULL; - for (i = 0; i != 4; i++) { - g_Vars.aibuddies[i] = 0; + for (i = 0; i < ARRAYCOUNT(g_Vars.aibuddies); i++) { + g_Vars.aibuddies[i] = NULL; } playerChooseBodyAndHead(&bodynum, &headnum, 0); diff --git a/src/game/prop.c b/src/game/prop.c index bb8806c75..4f2f6b585 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -653,7 +653,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc shotdata.unk34 = arg7; - for (i = 0; i != 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { shotdata.hits[i].prop = NULL; shotdata.hits[i].hitpart = 0; shotdata.hits[i].node = NULL; @@ -762,7 +762,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc } if (arg1) { - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { hitprop = shotdata.hits[i].prop; if (hitprop && !(laserstream && shotdata.hits[i].distance > 300)) { @@ -913,7 +913,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc hitindex = 0; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { if (shotdata.hits[i].prop && shotdata.hits[i].distance < range) { hitaprop = true; hitindex = i; @@ -940,7 +940,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc // For laser stream, bail early once the laser's range is reached. done = false; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { hitprop = shotdata.hits[i].prop; if (hitprop && !done) { @@ -1027,7 +1027,7 @@ void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hi f32 mostdist = 0; f32 prevmostdist = 0; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop && shotdata->hits[i].unk4c) { count++; @@ -1047,7 +1047,7 @@ void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hi shotdata->unk34 = arg2; } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop && !shotdata->hits[i].unk4c && shotdata->hits[i].distance > prevmostdist) { shotdata->hits[i].prop = NULL; } @@ -1060,7 +1060,7 @@ void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hi } if (arg10) { - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop && shotdata->hits[i].distance > arg2) { shotdata->hits[i].prop = NULL; } @@ -1069,7 +1069,7 @@ void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hi shotdata->unk34 = arg2; } - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop == NULL) { struct hit *hit = &shotdata->hits[i]; @@ -2916,7 +2916,7 @@ bool propTryAddToChunk(s16 propnum, s32 chunkindex) { s32 i; - for (i = 0; i < 7; i++) { + for (i = 0; i < ARRAYCOUNT(g_RoomPropListChunks[chunkindex].propnums) - 1; i++) { if (g_RoomPropListChunks[chunkindex].propnums[i] < 0) { g_RoomPropListChunks[chunkindex].propnums[i] = propnum; return true; @@ -2931,14 +2931,14 @@ s32 roomAllocatePropListChunk(s32 room, s32 prevchunkindex) s32 i; s32 j; - for (i = 0; i < 256; i++) { + for (i = 0; i < MAX_ROOMPROPLISTCHUNKS; i++) { if (g_RoomPropListChunks[i].propnums[0] == -2) { - for (j = 0; j < 8; j++) { + for (j = 0; j < ARRAYCOUNT(g_RoomPropListChunks[i].propnums); j++) { g_RoomPropListChunks[i].propnums[j] = -1; } if (prevchunkindex >= 0) { - g_RoomPropListChunks[prevchunkindex].propnums[7] = i; + g_RoomPropListChunks[prevchunkindex].propnums[MAX_PROPSPERROOMCHUNK] = i; } else { g_RoomPropListChunkIndexes[room] = i; } @@ -2966,7 +2966,7 @@ void propRegisterRoom(struct prop *prop, s16 room) } prev = chunkindex; - chunkindex = g_RoomPropListChunks[chunkindex].propnums[7]; + chunkindex = g_RoomPropListChunks[chunkindex].propnums[MAX_PROPSPERROOMCHUNK]; } // Allocate a new chunk @@ -2993,7 +2993,7 @@ void propDeregisterRoom(struct prop *prop, s16 room) s32 j; // Iterate propnums in this chunk - for (j = 0; j < 7; j++) { + for (j = 0; j < MAX_PROPSPERROOMCHUNK; j++) { if (g_RoomPropListChunks[chunkindex].propnums[j] == propnum) { g_RoomPropListChunks[chunkindex].propnums[j] = -1; removed = true; @@ -3007,9 +3007,9 @@ void propDeregisterRoom(struct prop *prop, s16 room) g_RoomPropListChunks[chunkindex].propnums[0] = -2; if (prev >= 0) { - g_RoomPropListChunks[prev].propnums[7] = g_RoomPropListChunks[chunkindex].propnums[7]; + g_RoomPropListChunks[prev].propnums[MAX_PROPSPERROOMCHUNK] = g_RoomPropListChunks[chunkindex].propnums[MAX_PROPSPERROOMCHUNK]; } else { - g_RoomPropListChunkIndexes[room] = g_RoomPropListChunks[chunkindex].propnums[7]; + g_RoomPropListChunkIndexes[room] = g_RoomPropListChunks[chunkindex].propnums[MAX_PROPSPERROOMCHUNK]; } } else { prev = chunkindex; @@ -3019,7 +3019,7 @@ void propDeregisterRoom(struct prop *prop, s16 room) return; } - chunkindex = g_RoomPropListChunks[chunkindex].propnums[7]; + chunkindex = g_RoomPropListChunks[chunkindex].propnums[MAX_PROPSPERROOMCHUNK]; } } } @@ -3164,7 +3164,7 @@ void roomGetProps(s16 *rooms, s16 *propnums, s32 len) // Iterate the chunks while (chunkindex >= 0) { // Iterate the propnums within each chunk - for (i = 0; i < 7; i++) { + for (i = 0; i < MAX_PROPSPERROOMCHUNK; i++) { s16 propnum = g_RoomPropListChunks[chunkindex].propnums[i]; if (propnum >= 0) { @@ -3187,7 +3187,7 @@ void roomGetProps(s16 *rooms, s16 *propnums, s32 len) } } - chunkindex = g_RoomPropListChunks[chunkindex].propnums[7]; + chunkindex = g_RoomPropListChunks[chunkindex].propnums[MAX_PROPSPERROOMCHUNK]; } rooms++; @@ -3208,17 +3208,17 @@ void propsDefragRoomProps(void) s32 previndex = g_RoomPropListChunkIndexes[i]; if (previndex >= 0) { - s32 nextindex = g_RoomPropListChunks[previndex].propnums[7]; + s32 nextindex = g_RoomPropListChunks[previndex].propnums[MAX_PROPSPERROOMCHUNK]; // Iterate this room's chunks but skip the first while (nextindex >= 0) { // Iterate propnums within this chunk - for (j = 0; j < 7; j++) { + for (j = 0; j < MAX_PROPSPERROOMCHUNK; j++) { // If this propnum is unallocated if (g_RoomPropListChunks[previndex].propnums[j] < 0) { // Iterate forward through the chunk list and find a // propnum to move back to the prev chunk - for (k = 0; k < 7; k++) { + for (k = 0; k < MAX_PROPSPERROOMCHUNK; k++) { if (g_RoomPropListChunks[nextindex].propnums[k] >= 0) { g_RoomPropListChunks[previndex].propnums[j] = g_RoomPropListChunks[nextindex].propnums[k]; g_RoomPropListChunks[nextindex].propnums[k] = -1; @@ -3227,18 +3227,18 @@ void propsDefragRoomProps(void) } // Check if there are more propnums in the future chunk - for (; k < 7; k++) { + for (; k < MAX_PROPSPERROOMCHUNK; k++) { if (g_RoomPropListChunks[nextindex].propnums[k] >= 0) { break; } } - if (k == 7) { + if (k == MAX_PROPSPERROOMCHUNK) { // There's no more propnums, so this chunk can be removed g_RoomPropListChunks[nextindex].propnums[0] = -2; - g_RoomPropListChunks[previndex].propnums[7] = g_RoomPropListChunks[nextindex].propnums[7]; + g_RoomPropListChunks[previndex].propnums[MAX_PROPSPERROOMCHUNK] = g_RoomPropListChunks[nextindex].propnums[MAX_PROPSPERROOMCHUNK]; - nextindex = g_RoomPropListChunks[previndex].propnums[7]; + nextindex = g_RoomPropListChunks[previndex].propnums[MAX_PROPSPERROOMCHUNK]; if (nextindex < 0) { break; @@ -3249,7 +3249,7 @@ void propsDefragRoomProps(void) if (nextindex >= 0) { previndex = nextindex; - nextindex = g_RoomPropListChunks[nextindex].propnums[7]; + nextindex = g_RoomPropListChunks[nextindex].propnums[MAX_PROPSPERROOMCHUNK]; } } } diff --git a/src/game/propobj.c b/src/game/propobj.c index 889b8bd14..b3a6915ec 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -486,7 +486,7 @@ s32 objCalculateGeoBlockVertices(f32 xmin, f32 xmax, f32 ymin, f32 ymax, f32 zmi sp270[7][0] = mtx00max + mtx10max + mtx20max; sp270[7][1] = mtx02max + mtx12max + mtx22max; - for (i = 0; i < 8; i++) { + for (i = 0; i < ARRAYCOUNT(sp270); i++) { for (j = 0; j < len; j++) { f32 tmp = 0.001f; f64 f0 = tmp; @@ -4815,7 +4815,7 @@ s32 glassCalculateOpacity(struct coord *pos, f32 xludist, f32 opadist, f32 arg3) return opacity; } -struct prop *g_Lifts[MAX_LIFTS] = {NULL}; +struct prop *g_Lifts[10] = {NULL}; struct hovtype g_HovTypes[] = { #if PAL @@ -4876,7 +4876,7 @@ void func0f070bd0(struct modelrodata_type19 *rodata, f32 rot[3][3], struct coord { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(rodata->vertices); i++) { vertices[i].x = pos->x + rot[0][0] * rodata->vertices[i].x + rot[1][0] * rodata->vertices[i].y + rot[2][0] * rodata->vertices[i].z; vertices[i].y = pos->y + rot[0][1] * rodata->vertices[i].x + rot[1][1] * rodata->vertices[i].y + rot[2][1] * rodata->vertices[i].z; vertices[i].z = pos->z + rot[0][2] * rodata->vertices[i].x + rot[1][2] * rodata->vertices[i].y + rot[2][2] * rodata->vertices[i].z; @@ -4929,7 +4929,7 @@ void func0f070ca0(struct defaultobj *obj, struct geotilef *tile, u32 flags, stru void liftActivate(struct prop *prop, u8 liftnum) { - if (liftnum > 0 && liftnum <= MAX_LIFTS) { + if (liftnum > 0 && liftnum <= ARRAYCOUNT(g_Lifts)) { g_Lifts[liftnum - 1] = prop; } } @@ -4939,7 +4939,7 @@ struct prop *liftFindByPad(s16 padnum) struct pad pad; padUnpack(padnum, PADFIELD_LIFT, &pad); - if (pad.liftnum <= 0 || pad.liftnum > MAX_LIFTS) { + if (pad.liftnum <= 0 || pad.liftnum > ARRAYCOUNT(g_Lifts)) { return NULL; } @@ -15711,7 +15711,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) mtx4TransformVec(obj->model->matrices, &sp110, &spec); tmp = -spec.z; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop && shotdata->hits[i].prop != spe4 && shotdata->hits[i].distance > tmp) { shotdata->hits[i].prop = NULL; } diff --git a/src/game/race.c b/src/game/race.c index 26179fced..6285babbe 100644 --- a/src/game/race.c +++ b/src/game/race.c @@ -93,7 +93,7 @@ void raceInitAnims(void) s32 race; s32 i; - for (race = 0; race < 5; race++) { + for (race = 0; race < ARRAYCOUNT(g_AnimTablesByRace); race++) { for (i = 0; g_AnimTablesByRace[race][i].hitpart != -1; i++) { if (g_AnimTablesByRace[race][i].deathanims) { g_AnimTablesByRace[race][i].deathanimcount = raceCountAnims(g_AnimTablesByRace[race][i].deathanims); diff --git a/src/game/radar.c b/src/game/radar.c index 3d6fa819d..0d184bc57 100644 --- a/src/game/radar.c +++ b/src/game/radar.c @@ -351,7 +351,7 @@ Gfx *radarRender(Gfx *gdl) // Draw dots for coop AI buddies if (!g_Vars.normmplayerisrunning && g_MissionConfig.iscoop) { - for (i = 0; i < g_Vars.numaibuddies && i < 4; i++) { + for (i = 0; i < g_Vars.numaibuddies && i < ARRAYCOUNT(g_Vars.aibuddies); i++) { struct prop *prop = g_Vars.aibuddies[i]; if (prop @@ -369,7 +369,7 @@ Gfx *radarRender(Gfx *gdl) } // Draw dots for MP simulants - if (g_Vars.normmplayerisrunning != 0) { + if (g_Vars.normmplayerisrunning) { for (i = 0; i < g_BotCount; i++) { if (!chrIsDead(g_MpBotChrPtrs[i]) && (g_MpBotChrPtrs[i]->hidden & CHRHFLAG_CLOAKED) == 0 diff --git a/src/game/setup.c b/src/game/setup.c index ac7025ea2..fd0d5f718 100644 --- a/src/game/setup.c +++ b/src/game/setup.c @@ -38,9 +38,6 @@ #include "types.h" s32 g_SetupCurMpLocation; -u32 var8009cc34; -u32 var8009cc38; -u32 var8009cc3c; struct tvscreen var80061a80 = { g_TvCmdlist00, // cmdlist @@ -1250,7 +1247,7 @@ void setupLoadBriefing(s32 stagenum, u8 *buffer, s32 bufferlen, struct briefing wanttype = BRIEFINGTYPE_TEXT_SA; } - for (i = 0; (u32)(i < 6); i++) { + for (i = 0; (u32)(i < ARRAYCOUNT(briefing->objectivenames)); i++) { briefing->objectivenames[i] = 0; } @@ -1477,7 +1474,7 @@ void setupCreateProps(s32 stagenum) escstepy = 0; g_Vars.textoverrides = NULL; - for (j = 0; j != 6; j++) { + for (j = 0; j != ARRAYCOUNT(g_Briefing.objectivenames); j++) { g_Briefing.objectivenames[j] = 0; g_Briefing.objectivedifficulties[j] = 0; } @@ -1643,7 +1640,7 @@ void setupCreateProps(s32 stagenum) lift->levelcur = 0; lift->levelaim = 0; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(lift->doors); i++) { if (lift->doors[i]) { lift->doors[i] = (struct doorobj *)setupGetCmdByIndex(index + *(s32*)&lift->doors[i]); } diff --git a/src/game/sight.c b/src/game/sight.c index df3aa2317..e79bd8ef9 100644 --- a/src/game/sight.c +++ b/src/game/sight.c @@ -166,7 +166,7 @@ void sightTick(bool sighton) g_Vars.currentplayer->sighttimer240 += g_Vars.lvupdate240; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->targetset); i++) { if (g_Vars.currentplayer->targetset[i] > TICKS(512)) { if (g_Vars.currentplayer->targetset[i] < (VERSION >= VERSION_PAL_BETA ? TICKS(1020) : 1024) - g_Vars.lvupdate240) { g_Vars.currentplayer->targetset[i] += g_Vars.lvupdate240; @@ -194,7 +194,7 @@ void sightTick(bool sighton) if (newtracktype != g_Vars.currentplayer->sighttracktype) { if (newtracktype == SIGHTTRACKTYPE_THREATDETECTOR) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { g_Vars.currentplayer->trackedprops[i].prop = NULL; } } @@ -212,12 +212,12 @@ void sightTick(bool sighton) } if (sighton && g_Vars.currentplayer->lastsighton == false && newtracktype != SIGHTTRACKTYPE_THREATDETECTOR) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { g_Vars.currentplayer->trackedprops[i].prop = NULL; } } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { trackedprop = &g_Vars.currentplayer->trackedprops[i]; if (trackedprop->prop && !sightIsReactiveToProp(trackedprop->prop)) { @@ -736,7 +736,7 @@ Gfx *sightDrawDefault(Gfx *gdl, bool sighton) break; case SIGHTTRACKTYPE_FOLLOWLOCKON: case SIGHTTRACKTYPE_THREATDETECTOR: - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { trackedprop = &g_Vars.currentplayer->trackedprops[i]; if (trackedprop->prop) { diff --git a/src/game/smoke.c b/src/game/smoke.c index aca83424e..af2439db1 100644 --- a/src/game/smoke.c +++ b/src/game/smoke.c @@ -21,7 +21,7 @@ s32 g_MaxSmokes; Mtx var800a3448; Mtx var800a3488; -struct smoketype g_SmokeTypes[NUM_SMOKETYPES] = { +struct smoketype g_SmokeTypes[] = { // duration // | fadespeed // | | spreadspeed @@ -308,7 +308,7 @@ struct smoke *smokeCreate(struct coord *pos, s16 *rooms, s16 type) prop->pos.y = pos->y; prop->pos.z = pos->z; - for (i = 0; rooms[i] != -1 && i < 7; i++) { + for (i = 0; rooms[i] != -1 && i < ARRAYCOUNT(prop->rooms) - 1; i++) { prop->rooms[i] = rooms[i]; } @@ -340,7 +340,7 @@ bool smokeCreateForHand(struct coord *pos, s16 *rooms, s16 type, s32 handnum) bool fail = false; if (g_Smokes[i].age < g_SmokeTypes[g_Smokes[i].type].duration) { - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(g_Smokes[i].parts); j++) { if (g_Smokes[i].parts[j].size == 0) { fail = true; } @@ -385,7 +385,7 @@ bool smokeCreateWithSource(void *source, struct coord *pos, s16 *rooms, s16 type bool fail = false; if (g_Smokes[i].age < g_SmokeTypes[g_Smokes[i].type].duration) { - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(g_Smokes[i].parts); j++) { if (g_Smokes[i].parts[j].size == 0) { fail = true; } @@ -464,7 +464,7 @@ u32 smokeTick(struct prop *prop) part = smoke->parts; - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(smoke->parts); j++) { if (part->size != 0.0f) { part->pos.y += g_SmokeTypes[smoke->type].unk1c; part->size += g_SmokeTypes[smoke->type].unk18; @@ -491,7 +491,7 @@ u32 smokeTick(struct prop *prop) if (smoke->age % g_SmokeTypes[smoke->type].spreadspeed == 1) { part = smoke->parts; - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(smoke->parts); j++) { if (smoke->parts[j].size == 0.0f) { if (g_SmokeTypes[smoke->type].size == 0) { part->size = (RANDOMFRAC() * 0.5f + 1.0f) * 0.33f; @@ -549,7 +549,7 @@ u32 smokeTick(struct prop *prop) bbmax.y = prop->pos.y + 1.0f; bbmax.z = prop->pos.z + 1.0f; - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(smoke->parts); j++) { if (smoke->parts[j].size != 0.0f) { for (k = 0; k < 3; k++) { if (bbmin.f[k] > smoke->parts[j].pos.f[k] - smoke->parts[j].size) { @@ -568,7 +568,7 @@ u32 smokeTick(struct prop *prop) if (smoke->age > g_SmokeTypes[smoke->type].spreadspeed) { free = true; - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(smoke->parts); j++) { if (smoke->parts[j].size > 0.0f) { free = false; break; diff --git a/src/game/sparks.c b/src/game/sparks.c index 2d0db1212..44456db25 100644 --- a/src/game/sparks.c +++ b/src/game/sparks.c @@ -162,7 +162,7 @@ void sparkgroupEnsureFreeSparkSlot(struct sparkgroup *group) { s32 i; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_SparkGroups); i++) { if (&g_SparkGroups[i] != group && g_SparkGroups[i].startindex == g_NextSparkIndex) { g_SparkGroups[i].startindex = (g_SparkGroups[i].startindex + 1) % 100; g_SparkGroups[i].numsparks--; @@ -208,13 +208,13 @@ void sparksCreate(s32 room, struct prop *prop, struct coord *pos, struct coord * } } - g_NextSparkGroupIndex = (g_NextSparkGroupIndex + 1) % 10; + g_NextSparkGroupIndex = (g_NextSparkGroupIndex + 1) % ARRAYCOUNT(g_SparkGroups); if (typenum == SPARKTYPE_SHALLOWWATER) { if (group->age != 0) { s32 newindex = -1; - for (i = 0; i < 10 && newindex < 0; i++) { + for (i = 0; i < ARRAYCOUNT(g_SparkGroups) && newindex < 0; i++) { if (g_SparkGroups[i].age == 0) { newindex = i; } diff --git a/src/game/sparksreset.c b/src/game/sparksreset.c index c642ed59f..e0ca39701 100644 --- a/src/game/sparksreset.c +++ b/src/game/sparksreset.c @@ -9,7 +9,7 @@ void sparksReset(void) s32 i; g_NextSparkIndex = 0; - for (i = 0; i < 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_SparkGroups); i++) { g_SparkGroups[i].age = 0; } diff --git a/src/game/sparkstick.c b/src/game/sparkstick.c index 8e097bf3c..a75d347b1 100644 --- a/src/game/sparkstick.c +++ b/src/game/sparkstick.c @@ -19,7 +19,7 @@ void sparksTick(void) group = &g_SparkGroups[0]; // Iterate spark groups - for (i = 0; i != 10; i++) { + for (i = 0; i < ARRAYCOUNT(g_SparkGroups); i++) { type = &g_SparkTypes[group->type]; if (group->age >= type->maxage) { diff --git a/src/game/title.c b/src/game/title.c index fc2c8a8d8..9a8709bf3 100644 --- a/src/game/title.c +++ b/src/game/title.c @@ -545,7 +545,7 @@ void titleInitPdLogo(void) var8009d34cjf = 0.99f * var8009d34cjf + 0.01f; } - for (j = 0; j < 3; j++) { + for (j = 0; j < ARRAYCOUNT(var8009d358jf) - 1; j++) { var8009d358jf[j] = var8009d358jf[j + 1]; } diff --git a/src/game/training.c b/src/game/training.c index f4cc26e6c..78ebbdca2 100644 --- a/src/game/training.c +++ b/src/game/training.c @@ -413,7 +413,7 @@ void frInitLighting(void) if (g_FrData.donelighting == false) { s32 roomnum; - for (roomnum = 7; roomnum < 10; roomnum++) { + for (roomnum = ROOM_DISH_0007; roomnum <= ROOM_DISH_0009; roomnum++) { roomSetLightOp(roomnum, LIGHTOP_TRANSITION, 50, 100, TICKS(32)); } @@ -432,7 +432,7 @@ void frRestoreLighting(void) if (g_FrData.donelighting == true) { s32 roomnum; - for (roomnum = 7; roomnum < 10; roomnum++) { + for (roomnum = ROOM_DISH_0007; roomnum <= ROOM_DISH_0009; roomnum++) { roomSetLightOp(roomnum, LIGHTOP_TRANSITION, 100, 50, TICKS(8)); } @@ -1330,7 +1330,7 @@ void frEndSession(bool hidetargets) for (i = 0; i < g_MaxExplosions; i++) { g_Explosions[i].age = 256; - for (j = 0; j < 40; j++) { + for (j = 0; j < ARRAYCOUNT(g_Explosions[i].parts); j++) { g_Explosions[i].parts[j].frame = 0; } } @@ -1339,7 +1339,7 @@ void frEndSession(bool hidetargets) for (i = 0; i < g_MaxSmokes; i++) { g_Smokes[i].age = 256; - for (j = 0; j < 10; j++) { + for (j = 0; j < ARRAYCOUNT(g_Smokes[i].parts); j++) { g_Smokes[i].parts[j].size = 0; } } @@ -1534,7 +1534,7 @@ bool frIsAmmoWasted(void) } // Check if there are any explosions - for (i = 0; i != 6; i++) { + for (i = 0; i != MAX_EXPLOSIONS; i++) { if (g_Explosions[i].prop) { return false; } @@ -2182,7 +2182,7 @@ void func0f1a0924(struct prop *prop) modelGetScreenCoords(obj->model, &sp56, &sp64, &sp60, &sp68); - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->trackedprops); i++) { if (g_Vars.currentplayer->trackedprops[i].prop == prop) { return; } @@ -2407,7 +2407,7 @@ s32 ciGetNumUnlockedChrBios(void) s32 count = 0; s32 bodynum; - for (bodynum = 0; bodynum < NUM_BODIES; bodynum++) { + for (bodynum = 0; bodynum < ARRAYCOUNT(g_HeadsAndBodies) - 1; bodynum++) { if (ciIsChrBioUnlocked(bodynum)) { count++; } @@ -2421,7 +2421,7 @@ s32 ciGetChrBioBodynumBySlot(s32 slot) s32 index = -1; s32 bodynum; - for (bodynum = 0; bodynum < NUM_BODIES; bodynum++) { + for (bodynum = 0; bodynum < ARRAYCOUNT(g_HeadsAndBodies) - 1; bodynum++) { if (ciIsChrBioUnlocked(bodynum)) { index++; } @@ -2877,7 +2877,7 @@ bool dtIsAvailable(s32 deviceindex) deviceindex--; - if (deviceindex >= 10) { + if (deviceindex >= ARRAYCOUNT(flags)) { return true; } @@ -2893,7 +2893,7 @@ s32 dtGetNumAvailable(void) s32 count = 0; s32 i; - for (i = 0; i < 10; i++) { + for (i = 0; i < NUM_DEVICETESTS; i++) { if (dtIsAvailable(i)) { count++; } @@ -2907,7 +2907,7 @@ s32 dtGetIndexBySlot(s32 wantindex) s32 index = -1; s32 i; - for (i = 0; i < 10; i++) { + for (i = 0; i < NUM_DEVICETESTS; i++) { if (dtIsAvailable(i)) { index++; } @@ -3199,7 +3199,7 @@ s32 htGetNumUnlocked(void) s32 count = 0; s32 i; - for (i = 0; i < 7; i++) { + for (i = 0; i < NUM_HOLOTESTS; i++) { if (htIsUnlocked(i)) { count++; } @@ -3213,7 +3213,7 @@ s32 htGetIndexBySlot(s32 slot) s32 index = -1; s32 i; - for (i = 0; i < 7; i++) { + for (i = 0; i < NUM_HOLOTESTS; i++) { if (htIsUnlocked(i)) { index++; } diff --git a/src/game/trainingmenus.c b/src/game/trainingmenus.c index ecbe54bf6..53ba1232f 100644 --- a/src/game/trainingmenus.c +++ b/src/game/trainingmenus.c @@ -57,7 +57,7 @@ MenuItemHandlerResult frDetailsOkMenuHandler(s32 operation, struct menuitem *ite g_FrWeaponNum = weapon; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_Vars.currentplayer->hands[0].gunroundsspent); i++) { g_Vars.currentplayer->hands[0].gunroundsspent[i] = 0; g_Vars.currentplayer->hands[1].gunroundsspent[i] = 0; } diff --git a/src/game/utils.c b/src/game/utils.c index 6213b6e28..0432870f4 100644 --- a/src/game/utils.c +++ b/src/game/utils.c @@ -91,11 +91,11 @@ void utilsInit(void) var800ac0e8[0] = mempAlloc(allocsize, MEMPOOL_8); if (var800ac0e8[0] != NULL) { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(var800ac0e8); i++) { var800ac0e8[i] = var800ac0e8[0] + ((i * 100) << 4); } } else { - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(var800ac0e8); i++) { var800ac0e8[i] = NULL; } } @@ -367,7 +367,7 @@ void utilsReset(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(var800ac0f8); i++) { var800ac0f8[i] = 0; } } diff --git a/src/game/varsreset.c b/src/game/varsreset.c index 4ae2412cd..29d301316 100644 --- a/src/game/varsreset.c +++ b/src/game/varsreset.c @@ -64,13 +64,13 @@ void varsResetRoomProps(void) s32 j; g_RoomPropListChunkIndexes = mempAlloc(ALIGN16(g_Vars.roomcount * sizeof(s16)), MEMPOOL_STAGE); - g_RoomPropListChunks = mempAlloc(256 * sizeof(struct roomproplistchunk), MEMPOOL_STAGE); + g_RoomPropListChunks = mempAlloc(MAX_ROOMPROPLISTCHUNKS * sizeof(struct roomproplistchunk), MEMPOOL_STAGE); for (i = 0; i < g_Vars.roomcount; i++) { g_RoomPropListChunkIndexes[i] = -1; } - for (i = 0; i < 256; i++) { + for (i = 0; i < MAX_ROOMPROPLISTCHUNKS; i++) { g_RoomPropListChunks[i].propnums[0] = -2; for (j = 1; j < ARRAYCOUNT(g_RoomPropListChunks[i].propnums); j++) { diff --git a/src/game/vtxstorereset.c b/src/game/vtxstorereset.c index ef2300261..a95e0a244 100644 --- a/src/game/vtxstorereset.c +++ b/src/game/vtxstorereset.c @@ -12,7 +12,7 @@ void vtxstoreReset(void) s32 num; s32 val; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(g_VtxstoreTypes); i++) { if (PLAYERCOUNT() >= 2) { val = g_VtxstoreTypes[i].valifmp; num = g_VtxstoreTypes[i].numifmp; diff --git a/src/game/wallhit.c b/src/game/wallhit.c index 3ff3f0bfc..c5e244369 100644 --- a/src/game/wallhit.c +++ b/src/game/wallhit.c @@ -186,7 +186,7 @@ void wallhitFree(struct wallhit *wallhit) g_WallhitsNumUsed--; g_WallhitsNumFree++; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(wallhit->basecolours); i++) { wallhit->basecolours[i].a = 0; wallhit->finalcolours[i].a = 0; } @@ -519,7 +519,7 @@ void wallhitsTick(void) midz = var800845dc.z; // Copy the vertices into a float array - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(wallhit->vertices); j++) { spc8[j].x = wallhit->vertices[j].x; spc8[j].y = wallhit->vertices[j].y; spc8[j].z = wallhit->vertices[j].z; @@ -528,7 +528,7 @@ void wallhitsTick(void) // Sum the vertices and divide them by 4 to get the centre minindex = 0; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(spc8); j++) { midx = midx + spc8[j].x; midy = midy + spc8[j].y; midz = midz + spc8[j].z; @@ -545,7 +545,7 @@ void wallhitsTick(void) midz = 0.25f * midz; // Calculate and apply the new size - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(spc8); j++) { s32 j2; f32 xradius = spc8[j].x - midx; f32 yradius = spc8[j].y - midy; @@ -570,7 +570,7 @@ void wallhitsTick(void) ; } - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(wallhit->basecolours); j++) { u32 alpha; if (f22 > 1.0f) { @@ -589,7 +589,7 @@ void wallhitsTick(void) if (wallhit->inuse) { wallhit->vertices2 = NULL; - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(wallhit->basecolours); j++) { wallhit->finalcolours[j].a = wallhit->basecolours[j].a; } } else { @@ -1031,7 +1031,7 @@ void wallhitCreateWith20Args(struct coord *relpos, struct coord *arg1, struct co wallhit->createdframe = g_Vars.lvframenum; wallhit->unk6f_05 = false; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(sp17c); i++) { struct coord sp58; s16 x; s16 y; @@ -1088,7 +1088,7 @@ void wallhitCreateWith20Args(struct coord *relpos, struct coord *arg1, struct co alpha = 0; } - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAYCOUNT(wallhit->basecolours); i++) { switch (type) { case WALLHITTYPE_BULLET: r = g = b = 255 - (random() % 40); @@ -1463,7 +1463,7 @@ void wallhitsRecolour(void) } if (room > 0) { - for (j = 0; j < 4; j++) { + for (j = 0; j < ARRAYCOUNT(wallhit->basecolours); j++) { wallhit->finalcolours[j].r = wallhit->basecolours[j].r * r; wallhit->finalcolours[j].g = wallhit->basecolours[j].g * g; wallhit->finalcolours[j].b = wallhit->basecolours[j].b * b; diff --git a/src/game/weather.c b/src/game/weather.c index 18cb7a2aa..337a57eb4 100644 --- a/src/game/weather.c +++ b/src/game/weather.c @@ -2577,7 +2577,7 @@ Gfx *weatherRenderRain(Gfx *gdl, struct weatherdata *weather, s32 arg2) osGetCount(); - for (i = 0; i != 10; i++) { + for (i = 0; i != ARRAYCOUNT(spdb0); i++) { spdb0[i] = 0; } diff --git a/src/include/bss.h b/src/include/bss.h index 3cf675a9f..74b947566 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -67,7 +67,7 @@ extern u8 var8009caed; extern u8 var8009caee; extern u8 var8009caef; extern u8 var8009caf0; -extern struct prop *g_DangerousProps[MAX_DANGEROUSPROPS]; +extern struct prop *g_DangerousProps[12]; extern u16 *g_WallhitCountsPerRoom; extern s32 g_WallhitsMax; extern u32 g_WallhitsNumSettled; @@ -129,11 +129,11 @@ extern struct criteria_throwinroom *g_ThrowInRoomCriterias; extern struct criteria_holograph *g_HolographCriterias; extern struct sndstate *g_CasingAudioHandles[2]; extern s32 var8009d0d8; -extern struct sndstate *g_BgunAudioHandles[4]; -extern struct fireslot g_Fireslots[NUM_FIRESLOTS]; +extern struct sndstate *g_BgunAudioHandles[MAX_PLAYERS]; +extern struct fireslot g_Fireslots[20]; extern struct casing g_Casings[20]; extern struct boltbeam g_BoltBeams[8]; -extern struct lasersight g_LaserSights[4]; +extern struct lasersight g_LaserSights[MAX_PLAYERS]; extern struct model *g_ModelSlots; extern struct anim *g_AnimSlots; extern s32 g_ModelNumObjs; @@ -159,21 +159,21 @@ extern s16 g_CutsceneAnimNum; extern s32 g_CutsceneFrameOverrun240; extern bool g_CutsceneSkipRequested; extern f32 g_CutsceneCurTotalFrame60f; -extern s16 g_SpawnPoints[MAX_SPAWNPOINTS]; +extern s16 g_SpawnPoints[]; extern s32 g_NumSpawnPoints; extern s32 var8009de90; extern s32 var8009de94; extern s32 var8009de98; extern s32 var8009de9c; -extern u8 g_MpSelectedPlayersForStats[4]; +extern u8 g_MpSelectedPlayersForStats[MAX_PLAYERS]; extern char g_CheatMarqueeString[]; extern u8 *g_BlurBuffer; extern s32 var8009dfc0; extern struct briefing g_Briefing; extern struct missionconfig g_MissionConfig; -extern struct menu g_Menus[4]; +extern struct menu g_Menus[MAX_PLAYERS]; extern struct menudata g_MenuData; -extern struct activemenu g_AmMenus[4]; +extern struct activemenu g_AmMenus[MAX_PLAYERS]; extern s32 g_AmIndex; extern u32 g_CheatsActiveBank0; extern u32 g_CheatsActiveBank1; @@ -192,7 +192,7 @@ extern struct covercandidate *g_CoverCandidates; extern u16 g_NumSpecialCovers; extern u16 *g_SpecialCoverNums; extern struct pak g_Paks[5]; -extern OSPfs g_Pfses[4]; +extern OSPfs g_Pfses[MAX_PLAYERS]; extern u32 g_SkyStageNum; extern bool g_SkyLightningActive; extern struct explosion *g_Explosions; @@ -281,9 +281,9 @@ extern struct chrdata *g_MpAllChrPtrs[MAX_MPCHRS]; extern struct mpchrconfig *g_MpAllChrConfigPtrs[MAX_MPCHRS]; extern s32 g_MpNumChrs; extern struct mpbotconfig g_BotConfigsArray[MAX_BOTS]; -extern u8 g_MpSimulantDifficultiesPerNumPlayers[MAX_BOTS][4]; -extern struct mpplayerconfig g_PlayerConfigsArray[6]; -extern u8 g_AmBotCommands[16]; +extern u8 g_MpSimulantDifficultiesPerNumPlayers[MAX_BOTS][MAX_PLAYERS]; +extern struct mpplayerconfig g_PlayerConfigsArray[MAX_MPPLAYERCONFIGS]; +extern u8 g_AmBotCommands[9]; extern struct mpsetup g_MpSetup; extern struct bossfile g_BossFile; extern struct chrdata *g_MpBotChrPtrs[MAX_BOTS]; diff --git a/src/include/constants.h b/src/include/constants.h index 10ab73214..5fb320b46 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -13,6 +13,32 @@ #define false 0 #define true 1 +#define MAX_ARTIFACTS 120 +#define MAX_BOTS 8 +#define MAX_CHRSPERSQUADRON 16 +#define MAX_CHRSPERTEAM 32 +#define MAX_CHRWAYPOINTS 6 +#define MAX_EXPLOSIONS 6 +#define MAX_EYESPYDARTS 8 +#define MAX_MPCHRS (MAX_PLAYERS + MAX_BOTS) +#define MAX_MPPLAYERCONFIGS (MAX_PLAYERS + 2) +#define MAX_OBJECTIVES 10 +#define MAX_PLAYERS 4 +#define MAX_PROPSPERROOMCHUNK 7 +#define MAX_ROOMPROPLISTCHUNKS 256 +#define MAX_SQUADRONS 16 +#define MAX_TEAMS 8 + +#define NUM_BOTDIFFS 6 +#define NUM_CYCLEABLE_WEAPONS 45 +#define NUM_DEVICETESTS 10 +#define NUM_FRAMEBUFFERS 2 +#define NUM_GFXTASKS 2 +#define NUM_HOLOTESTS 7 +#define NUM_MPWEAPONSLOTS 6 +#define NUM_SOLOSTAGES 21 +#define NUM_TEXTURES (VERSION == VERSION_JPN_FINAL ? 3511 : 3503) + #define osSyncPrintf #define S32_MAX 2147483647 @@ -34,13 +60,22 @@ #define IS8MB() (g_Is4Mb != true) #define LINEHEIGHT (VERSION == VERSION_JPN_FINAL ? 14 : 11) #define MIXCOLOUR(dialog, property) dialog->transitionfrac < 0.0f ? g_MenuColourPalettes[dialog->type].property : colourBlend(g_MenuColourPalettes[dialog->type2].property, g_MenuColourPalettes[dialog->type].property, dialog->colourweight) -#define MPCHR(index) ((index) < 4 ? &g_PlayerConfigsArray[index].base : &g_BotConfigsArray[(index) - 4].base) -#define PLAYERCOUNT() ((g_Vars.players[0] ? 1 : 0) + (g_Vars.players[1] ? 1 : 0) + (g_Vars.players[2] ? 1 : 0) + (g_Vars.players[3] ? 1 : 0)) +#define MPCHR(index) ((index) < MAX_PLAYERS ? &g_PlayerConfigsArray[index].base : &g_BotConfigsArray[(index) - MAX_PLAYERS].base) #define RANDOMFRAC() (random() * (1.0f / U32_MAX)) #define SECSTOTIME240(secs) (secs * 240) #define SECSTOTIME60(secs) (secs * 60) #define PFS(device) (device == SAVEDEVICE_GAMEPAK ? NULL : &g_Pfses[device]) +#if MAX_PLAYERS >= 4 +#define PLAYERCOUNT() ((g_Vars.players[0] ? 1 : 0) + (g_Vars.players[1] ? 1 : 0) + (g_Vars.players[2] ? 1 : 0) + (g_Vars.players[3] ? 1 : 0)) +#elif MAX_PLAYERS >= 3 +#define PLAYERCOUNT() ((g_Vars.players[0] ? 1 : 0) + (g_Vars.players[1] ? 1 : 0) + (g_Vars.players[2] ? 1 : 0)) +#elif MAX_PLAYERS >= 2 +#define PLAYERCOUNT() ((g_Vars.players[0] ? 1 : 0) + (g_Vars.players[1] ? 1 : 0)) +#else +#define PLAYERCOUNT() 1 +#endif + #define VALIDWEAPON() (g_Vars.currentplayer->gunctrl.weaponnum >= WEAPON_UNARMED && g_Vars.currentplayer->gunctrl.weaponnum <= WEAPON_COMBATBOOST) #define FUNCISSEC() (VALIDWEAPON() && (g_PlayerConfigsArray[g_Vars.currentplayerstats->mpindex].gunfuncs[(g_Vars.currentplayer->gunctrl.weaponnum - 1) >> 3] & (1 << ((g_Vars.currentplayer->gunctrl.weaponnum - 1) & 7)))) @@ -1515,17 +1550,6 @@ #define MA_PUNCHING 54 #define MA_END 55 -#define MAX_ARTIFACTS 120 -#define MAX_CHRWAYPOINTS 6 -#define MAX_DANGEROUSPROPS 12 -#define MAX_LIFTS 10 -#define MAX_MPCHRS (4 + MAX_BOTS) -#define MAX_OBJECTIVES 10 -#define MAX_BOTS 8 -#define MAX_SPAWNPOINTS 24 -#define MAX_SQUADRONS 16 -#define MAX_TEAMS 8 - #define MEDAL_KILLMASTER 0x01 #define MEDAL_HEADSHOT 0x02 #define MEDAL_ACCURACY 0x04 @@ -2583,21 +2607,6 @@ #define MPBODY_DALTON 0x3b #define MPBODY_DJBOND 0x3c -#define MPBOTCOMMAND_FOLLOW 0 -#define MPBOTCOMMAND_ATTACK 1 -#define MPBOTCOMMAND_DEFEND 2 -#define MPBOTCOMMAND_HOLD 3 -#define MPBOTCOMMAND_NORMAL 4 -#define MPBOTCOMMAND_DOWNLOAD 5 -#define MPBOTCOMMAND_GETCASE 6 -#define MPBOTCOMMAND_TAGBOX 7 -#define MPBOTCOMMAND_SAVECASE 8 -#define MPBOTCOMMAND_DEFHILL 9 -#define MPBOTCOMMAND_HOLDHILL 10 -#define MPBOTCOMMAND_GETCASE2 11 -#define MPBOTCOMMAND_POPCAP 12 -#define MPBOTCOMMAND_PROTECT 13 - #define MPCONFIG_TEMPLE 0x00 #define MPCONFIG_PISTOLS 0x01 #define MPCONFIG_FARSIGHT 0x02 @@ -2720,11 +2729,11 @@ #define MPFEATURE_CHR_PELAGIC 0x45 #define MPFEATURE_CHR_JOTRENCH 0x46 #define MPFEATURE_CHR_JOSNOW 0x47 -#define MPFEATURE_CHR_JONATHAN 0x48 +#define MPFEATURE_48 0x48 #define MPFEATURE_49 0x49 -#define MPFEATURE_4A 0x4a +#define MPFEATURE_CHR_DARKSNOW 0x4a #define MPFEATURE_4B 0x4b -#define MPFEATURE_4C 0x4c +#define MPFEATURE_CHR_JONATHAN 0x4c #define MPFEATURE_SCENARIO_PAC 0x4d #define MPFEATURE_SCENARIO_HTM 0x4e #define MPFEATURE_WEAPON_LASER 0x4f @@ -2934,27 +2943,6 @@ #define MUSICEVENTTYPE_STOPALL 4 #define MUSICEVENTTYPE_SETINTERVAL 5 -#define NUM_BODIES 151 -#define NUM_CHALLENGES 30 -#define NUM_CHEATS 42 -#define NUM_CYCLEABLE_WEAPONS 45 -#define NUM_EXPLOSIONTYPES 26 -#define NUM_FIRESLOTS 20 -#define NUM_FRAMEBUFFERS 2 -#define NUM_GFXTASKS 2 -#define NUM_MPBEAUHEADS 5 -#define NUM_MPBOTCOMMANDS 14 -#define NUM_MPBODIES 61 -#define NUM_MPHEADS (VERSION == VERSION_JPN_FINAL ? 74 : 75) -#define NUM_MPPRESETS 14 -#define NUM_MPTRACKS 42 -#define NUM_RACES 5 -#define NUM_SMOKETYPES 23 -#define NUM_SOLONORMALSTAGES 17 -#define NUM_SOLOSTAGES 21 -#define NUM_STAGES 90 -#define NUM_TEXTURES (VERSION == VERSION_JPN_FINAL ? 3511 : 3503) - #define OBJECTIVE_INCOMPLETE 0 #define OBJECTIVE_COMPLETE 1 #define OBJECTIVE_FAILED 2 @@ -4043,6 +4031,7 @@ #define THREAD_AUDIO 4 #define THREAD_FAULT 5 #define THREAD_RESET 6 +#define NUM_THREADS 7 #define THREADPRI_IDLE 0 #define THREADPRI_MAIN 10 diff --git a/src/include/data.h b/src/include/data.h index b50ba8653..5378c4bc3 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -7,8 +7,8 @@ #define bool s32 #define ubool u32 -extern u8 *g_StackLeftAddrs[7]; -extern u8 *g_StackRightAddrs[7]; +extern u8 *g_StackLeftAddrs[NUM_THREADS]; +extern u8 *g_StackRightAddrs[NUM_THREADS]; extern u8 *g_StackAllocatedPos; extern s32 var8005ce74; extern f32 g_ViXScalesBySlot[NUM_GFXTASKS]; @@ -162,7 +162,7 @@ extern f32 g_AttackWalkDurationScale; extern s32 g_NumChrsSeenPlayerRecently2; extern struct animtablerow g_DeathAnimsHumanGun[]; extern struct animtablerow g_AnimTableHumanSlumped[]; -extern struct animtable *g_AnimTablesByRace[]; +extern struct animtable *g_AnimTablesByRace[5]; extern struct attackanimconfig var800656c0[]; extern struct attackanimgroup *g_StandHeavyAttackAnims[][32]; extern struct attackanimconfig var80065be0[]; @@ -222,7 +222,7 @@ extern s32 g_LastPadEffectIndex; extern struct autogunobj *g_ThrownLaptops; extern struct beam *g_ThrownLaptopBeams; extern s32 g_MaxThrownLaptops; -extern struct prop *g_Lifts[MAX_LIFTS]; +extern struct prop *g_Lifts[10]; extern u32 g_TvCmdlist00[]; extern u32 var8006aaa0[]; extern u32 var8006aae4[]; @@ -278,7 +278,7 @@ extern s32 g_MpPlayerNum; extern u32 g_MpNumJoined; extern u16 g_ControlStyleOptions[]; extern struct menudialogdef g_PreAndPostMissionBriefingMenuDialog; -extern struct stageoverviewentry g_StageNames[NUM_SOLOSTAGES]; +extern struct solostage g_SoloStages[]; extern struct menudialogdef g_SoloMissionControlStyleMenuDialog; extern struct menudialogdef g_CiControlStyleMenuDialog; extern struct menudialogdef g_CiControlStylePlayer2MenuDialog; @@ -300,7 +300,7 @@ extern struct menudialogdef g_MpConfirmChallenge4MbMenuDialog; extern struct menudialogdef g_MainMenu4MbMenuDialog; extern struct menudialogdef g_MpEditSimulant4MbMenuDialog; extern struct menudialogdef g_AdvancedSetup4MbMenuDialog; -extern struct filelist *g_FileLists[]; +extern struct filelist *g_FileLists[MAX_PLAYERS]; extern bool var80075bd0[]; extern struct var80075c00 var80075c00[]; extern s32 var80075d60; @@ -393,7 +393,7 @@ extern struct skeleton g_SkelSkedar; extern struct skeleton g_SkelDrCaroll; extern struct skeleton g_Skel22; extern struct skeleton g_SkelRobot; -extern struct headorbody g_HeadsAndBodies[]; +extern struct headorbody g_HeadsAndBodies[152]; extern struct hatposition var8007dae4[1][6]; extern f32 g_SkyCloudOffset; extern f32 g_SkyWindSpeed; @@ -493,22 +493,23 @@ extern struct menudialogdef g_MpQuickTeamScenarioMenuDialog; extern s32 var80087260; extern bool g_MpEnableMusicSwitching; extern struct mpweapon g_MpWeapons[NUM_MPWEAPONS]; -extern struct mphead g_MpHeads[NUM_MPHEADS]; +extern struct mphead g_MpHeads[VERSION == VERSION_JPN_FINAL ? 74 : 75]; extern struct botprofile g_BotProfiles[18]; -extern struct mpbody g_MpBodies[NUM_MPBODIES]; -extern struct mppreset g_MpPresets[NUM_MPPRESETS]; +extern struct mpbody g_MpBodies[61]; +extern struct mppreset g_MpPresets[]; extern u32 g_TeamColours[]; extern u32 var80087ce4[]; extern u8 g_BotCount; extern struct aibotweaponpreference g_AibotWeaponPreferences[]; extern u32 var80087eb4; -extern struct challenge g_MpChallenges[NUM_CHALLENGES]; +extern struct challenge g_MpChallenges[30]; extern u8 g_FrIsValidWeapon; extern s32 g_FrWeaponNum; extern u8 g_ChrBioSlot; extern u8 g_HangarBioSlot; extern u8 g_DtSlot; extern u8 var80088bb4; +extern struct vtxstoretype g_VtxstoreTypes[4]; extern struct menudialogdef g_FrWeaponListMenuDialog; extern struct menudialogdef g_FrTrainingInfoInGameMenuDialog; extern struct menudialogdef g_FrTrainingInfoPreGameMenuDialog; diff --git a/src/include/game/camdraw.h b/src/include/game/camdraw.h index 4ff657d28..3c58fb303 100644 --- a/src/include/game/camdraw.h +++ b/src/include/game/camdraw.h @@ -68,7 +68,7 @@ void func0f14e7e0(u8 *arg0); void func0f14e884(struct textureconfig *tconfig, s32 arg1, s32 arg2, u64 arg3); void func0f14ec2c(u32 arg0, u32 arg1, u32 arg2, u32 arg3); void func0f14ecd8(s32 *arg0, s32 *arg1, s32 *arg2, s32 *arg3); -void func0f14eeb0(f32 *arg0); +void func0f14eeb0(f32 arg0[7]); void func0f14ef50(f32 *arg0); s32 func0f14f008(s32 index); Gfx *func0f14f07c(Gfx *gdl, s32 headorbodynum, s32 x1, s32 y1, s32 x2, s32 y2); diff --git a/src/include/game/challenge.h b/src/include/game/challenge.h index fe32d1f85..e5a814e79 100644 --- a/src/include/game/challenge.h +++ b/src/include/game/challenge.h @@ -6,7 +6,6 @@ extern u32 g_MpChallengeIndex; extern struct mpconfigfull *g_MpCurrentChallengeConfig; -extern struct challenge g_MpChallenges[NUM_CHALLENGES]; void challengesInit(void); @@ -40,7 +39,7 @@ void challengeLoadAndStoreCurrent(u8 *buffer, s32 len); void challengeUnsetCurrent(void); bool challengeIsLoaded(void); s32 challengeGetAutoFocusedIndex(s32 mpchrnum); -char *xhallengeGetName(s32 playernum, s32 challengeindex); +char *challengeGetName2(s32 playernum, s32 challengeindex); bool challengeIsCompletedByPlayerWithNumPlayers2(s32 mpchrnum, s32 index, s32 numplayers); bool challengeIsCompletedByAnyPlayerWithNumPlayers(s32 index, s32 numplayers); void challengeSetCompletedByAnyPlayerWithNumPlayers(s32 index, s32 numplayers, bool completed); diff --git a/src/include/game/game_0b0fd0.h b/src/include/game/game_0b0fd0.h index 8bbccd8eb..cd573b5ae 100644 --- a/src/include/game/game_0b0fd0.h +++ b/src/include/game/game_0b0fd0.h @@ -22,8 +22,8 @@ bool weaponHasAimFlag(s32 weaponnum, u32 flag); bool weaponHasAmmoFlag(s32 weaponnum, s32 funcnum, u32 flag); s32 currentPlayerGetDeviceState(s32 weaponnum); void currentPlayerSetDeviceActive(s32 weaponum, bool active); -u16 weaponGetModelNum(s32 weaponnum); -u16 weaponGetModelNum2(s32 weaponnum); +u16 weaponGetFileNum(s32 weaponnum); +u16 weaponGetFileNum2(s32 weaponnum); void gsetPopulateFromCurrentPlayer(s32 handnum, struct gset *gset); struct inventory_ammo *gsetGetAmmoDefinition(struct gset *gset); u8 gsetGetSinglePenetration(struct gset *gset); diff --git a/src/include/game/mplayer/mplayer.h b/src/include/game/mplayer/mplayer.h index fb04898ae..bb4b17e56 100644 --- a/src/include/game/mplayer/mplayer.h +++ b/src/include/game/mplayer/mplayer.h @@ -30,7 +30,7 @@ s32 mpGetWeaponSlot(s32 slot); struct mpweapon *mpGetMpWeaponByLocation(s32 locationindex); s32 mpCountWeaponSetThing(s32 weaponsetindex); s32 func0f188f9c(s32 arg0); -s32 func0f189058(s32 arg0); +s32 func0f189058(bool full); s32 func0f189088(void); char *mpGetWeaponSetName(s32 arg0); void func0f18913c(void); diff --git a/src/include/lib/joy.h b/src/include/lib/joy.h index 6ec3748da..c50727b22 100644 --- a/src/include/lib/joy.h +++ b/src/include/lib/joy.h @@ -19,7 +19,6 @@ void joyDisableTemporarily(void); void joyReset(void); void joy00013e84(void); u32 joyGetConnectedControllers(void); -void joyConsumeSamples(struct joydata *joydata); void joy00014238(void); void joyDebugJoy(void); s32 joyStartReadData(OSMesgQueue *mq); diff --git a/src/include/types.h b/src/include/types.h index 962844aff..69a015d51 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -70,7 +70,7 @@ struct playerstats { /*0x00*/ s32 shotcount[7]; /*0x1c*/ s32 killcount; /*0x20*/ s32 ggkillcount; - /*0x24*/ s32 kills[4]; + /*0x24*/ s32 kills[MAX_PLAYERS]; /*0x34*/ s32 drawplayercount; /*0x38*/ f32 distance; /*0x3c*/ s32 backshotcount; @@ -137,9 +137,9 @@ struct g_vars { /*0x058*/ s32 thisframestart240; // current frame's start time in 240ths (incrementing) /*0x05c*/ f32 diffframe240freal; /*0x060*/ s16 *waypointnums; // ordered by room asc, padnum asc - /*0x064*/ struct player *players[4]; - /*0x074*/ struct playerstats playerstats[4]; - /*0x274*/ u32 playerorder[4]; + /*0x064*/ struct player *players[MAX_PLAYERS]; + /*0x074*/ struct playerstats playerstats[MAX_PLAYERS]; + /*0x274*/ u32 playerorder[MAX_PLAYERS]; /*0x284*/ struct player *currentplayer; /*0x288*/ struct playerstats *currentplayerstats; /*0x28c*/ s32 currentplayernum; // 0-3 - controller numbers I think @@ -210,13 +210,13 @@ struct g_vars { /*0x488*/ s32 totalkills; /*0x48c*/ bool useperimshoot; /*0x490*/ s32 mpsetupmenu; - /*0x494*/ s8 waitingtojoin[4]; + /*0x494*/ s8 waitingtojoin[MAX_PLAYERS]; /*0x498*/ s32 unk000498; /*0x49c*/ bool usingadvsetup; /*0x4a0*/ s32 unk0004a0; /*0x4a4*/ s32 mpquickteamnumsims; /*0x4a8*/ s32 mpsimdifficulty; - /*0x4ac*/ s8 mpplayerteams[4]; + /*0x4ac*/ s8 mpplayerteams[MAX_PLAYERS]; /*0x4b0*/ u32 mpquickteam; /*0x4b4*/ s32 stagenum; /*0x4b8*/ struct prop *aibuddies[4]; @@ -231,7 +231,7 @@ struct g_vars { /*0x4d6*/ s8 autocutfinished; // true if cutscene reached natural end /*0x4d7*/ s8 autocutgroupskip; // true if pressed start during auto cutscene /*0x4d8*/ s32 joydisableframestogo; - /*0x4dc*/ u8 playertojoymap[4]; + /*0x4dc*/ u8 playertojoymap[MAX_PLAYERS]; /*0x4e0*/ u8 fourmeg2player; /*0x4e1*/ u8 remakewallhitvtx; /*0x4e2*/ u8 cutsceneskip60ths; @@ -808,11 +808,11 @@ struct aibot { /*0x208*/ s32 unk208; /*0x20c*/ s32 random1ttl60; /*0x210*/ u32 random1; - /*0x214*/ f32 killsbygunfunc[6][2]; - /*0x244*/ f32 suicidesbygunfunc[6][2]; - /*0x274*/ s32 equipdurations60[6][2]; + /*0x214*/ f32 killsbygunfunc[NUM_MPWEAPONSLOTS][2]; + /*0x244*/ f32 suicidesbygunfunc[NUM_MPWEAPONSLOTS][2]; + /*0x274*/ s32 equipdurations60[NUM_MPWEAPONSLOTS][2]; /*0x2a4*/ s32 unk2a4; - /*0x2a8*/ s32 unk2a8[6]; + /*0x2a8*/ s32 unk2a8[NUM_MPWEAPONSLOTS]; /*0x2c0*/ s32 dampensuicidesttl60; /** @@ -1381,7 +1381,7 @@ struct projectile { /*0x0ec*/ f32 unk0ec; /*0x0f0*/ f32 unk0f0; /*0x0f4*/ s32 smoketimer240; - /*0x0f8*/ s16 waypads[6]; + /*0x0f8*/ s16 waypads[MAX_CHRWAYPOINTS]; /*0x104*/ u8 numwaypads; /*0x105*/ u8 step; /*0x108*/ struct prop *pickupby; @@ -3091,7 +3091,7 @@ struct stagetableentry { struct mpweaponset { /*0x00*/ u16 name; - /*0x02*/ u8 slots[6]; + /*0x02*/ u8 slots[NUM_MPWEAPONSLOTS]; /*0x08*/ u8 requirefeatures[4]; /*0x0c*/ u8 unk0c; /*0x0d*/ u8 unk0d; @@ -3128,7 +3128,7 @@ struct mptrack { s16 unlockstage; }; -struct stageoverviewentry { +struct solostage { /*0x00*/ u32 stagenum; /*0x04*/ u8 unk04; /*0x06*/ u16 name1; // "dataDyne Central" @@ -4325,13 +4325,13 @@ struct mpsetup { * Bits 0xf000 are probably not used */ /*0x800acb9e*/ u16 chrslots; - /*0x800acba0*/ u8 weapons[6]; + /*0x800acba0*/ u8 weapons[NUM_MPWEAPONSLOTS]; /*0x800acba6*/ u8 paused; /*0x800acba8*/ struct fileguid fileguid; }; struct bossfile { - /*0x00*/ char teamnames[8][12]; + /*0x00*/ char teamnames[MAX_TEAMS][12]; /*0x60*/ u8 locktype; /*0x61*/ u8 unk89; /*0x62*/ u8 usingmultipletunes; @@ -4386,7 +4386,7 @@ struct challenge { // Same structure as availability, however each byte determines how many // players it was completed with. So completions[0] is for completions with // a single player and completions[3] is for completions with 4 players. - /*0x05*/ u8 completions[4]; + /*0x05*/ u8 completions[MAX_PLAYERS]; // Array of features which will become unlocked once the challenge is // available. The array is automatically populated at runtime based on what @@ -5013,7 +5013,7 @@ struct menudata { /*0x014*/ u8 bg; /*0x015*/ u8 nextbg; /*0x016*/ u8 screenshottimer; - /*0x017*/ u8 playerjoinalpha[4]; + /*0x017*/ u8 playerjoinalpha[MAX_PLAYERS]; /*0x01b*/ s8 bannernum; /*0x01c*/ struct menu840 unk01c; /*0x5d4*/ u8 unk5d4; @@ -5209,12 +5209,12 @@ struct mpconfigsim { u8 mpheadnum; u8 mpbodynum; u8 team; - u8 difficulties[4]; // per player count + u8 difficulties[MAX_PLAYERS]; }; struct mpconfig { struct mpsetup setup; - struct mpconfigsim simulants[8]; + struct mpconfigsim simulants[MAX_BOTS]; }; struct mpweapon { @@ -5231,7 +5231,7 @@ struct mpweapon { struct mpstrings { char description[200]; - char aibotnames[8][15]; + char aibotnames[MAX_BOTS][15]; }; struct mpconfigfull { @@ -5579,21 +5579,6 @@ struct stageallocation { char *string; }; -struct contsample { - OSContPad pads[4]; -}; - -struct joydata { - struct contsample samples[20]; - s32 curlast; - s32 curstart; - s32 nextlast; - s32 nextsecondlast; - u16 buttonspressed[4]; - u16 buttonsreleased[4]; - s32 unk200; -}; - struct guncmd { u8 type; u8 unk01; @@ -5744,7 +5729,7 @@ struct wallhit { * The first item in the propnums array is -2 if this chunk is unallocated. */ struct roomproplistchunk { - s16 propnums[8]; + s16 propnums[MAX_PROPSPERROOMCHUNK + 1]; }; struct nbomb { diff --git a/src/lib/args.c b/src/lib/args.c index bf4a48001..cc9baf77b 100644 --- a/src/lib/args.c +++ b/src/lib/args.c @@ -74,7 +74,7 @@ bool argsParseDebugArgs(void) if (rmonIsDisabled()) { g_ArgBuffer[0] = 0; } else { - for (i = 0; i < 30; i++) { + for (i = 0; i < ARRAYCOUNT(g_ArgBuffer); i++) { osPiReadIo(devaddr, &g_ArgBuffer[i]); devaddr += 4; } diff --git a/src/lib/boot.c b/src/lib/boot.c index a1b83259f..05c03535b 100644 --- a/src/lib/boot.c +++ b/src/lib/boot.c @@ -39,8 +39,8 @@ u32 var8005ce00 = 0; u32 var8005ce04 = 0; u32 var8005ce08 = 0; u32 var8005ce0c = 0; -u8 *g_StackLeftAddrs[7] = {0}; -u8 *g_StackRightAddrs[7] = {0}; +u8 *g_StackLeftAddrs[NUM_THREADS] = {0}; +u8 *g_StackRightAddrs[NUM_THREADS] = {0}; u8 *g_StackAllocatedPos = (u8 *) K0BASE + 4 * 1024 * 1024; u32 var8005ce4c = 0x00000002; u32 var8005ce50 = 0x10000000; @@ -287,7 +287,7 @@ void bootCountUnusedStack(void) { s32 threadid; - for (threadid = 0; threadid < 7; threadid++) { + for (threadid = 0; threadid < NUM_THREADS; threadid++) { u8 *left = g_StackLeftAddrs[threadid]; u8 *right = g_StackRightAddrs[threadid]; @@ -307,7 +307,7 @@ void bootCheckStackOverflow(void) { s32 threadid; - for (threadid = 0; threadid < 7; threadid++) { + for (threadid = 0; threadid < NUM_THREADS; threadid++) { if (g_StackLeftAddrs[threadid] != NULL) { u32 *ptr = (u32 *) g_StackLeftAddrs[threadid]; s32 i; diff --git a/src/lib/crash.c b/src/lib/crash.c index b64b7da40..5c0c7a9bc 100644 --- a/src/lib/crash.c +++ b/src/lib/crash.c @@ -20,6 +20,9 @@ #define MAX_LINES 31 #endif +#define CHAR_W 4 +#define CHAR_H 7 + #if VERSION < VERSION_NTSC_1_0 char g_CrashMessage[70]; #endif @@ -888,8 +891,8 @@ void crashRenderChar(s32 x, s32 y, char c) a2 = 0; #endif - for (i = 0; i < 7; i++) { - for (j = 0; j < 4; j++) { + for (i = 0; i < CHAR_H; i++) { + for (j = 0; j < CHAR_W; j++) { u32 gray = a2 & 0x80000000; if (gray) { @@ -963,13 +966,13 @@ void crashRenderFrame(u16 *fb) g_CrashFrameBuffer = (u16 *) PHYS_TO_K1(fb); - width = (viGetWidth() - 13) / 4; - height = (viGetHeight() - 10) / 7 - 1; + width = (viGetWidth() - 13) / CHAR_W; + height = (viGetHeight() - 10) / CHAR_H - 1; if (g_CrashCharBuffer != NULL) { for (y = 0; y < height && y < MAX_LINES; y++) { for (x = 0; x < width - 5 && x < 71; x++) { - crashRenderChar(20 + x * 4, 7 + y * 7, g_CrashCharBuffer[y][x]); + crashRenderChar(20 + x * CHAR_W, CHAR_H + y * CHAR_H, g_CrashCharBuffer[y][x]); } } } diff --git a/src/lib/joy.c b/src/lib/joy.c index 75521ecf3..ae8650210 100644 --- a/src/lib/joy.c +++ b/src/lib/joy.c @@ -31,8 +31,27 @@ * sample in the next partition. */ -struct joydata g_JoyData[2]; -s32 g_JoyDisableCooldown[4]; +#define NUM_DATA 2 +#define NUM_SAMPLES 20 +#define NUM_PADS MAXCONTROLLERS + +struct contsample { + OSContPad pads[NUM_PADS]; +}; + +struct joydata { + struct contsample samples[NUM_SAMPLES]; + s32 curlast; + s32 curstart; + s32 nextlast; + s32 nextsecondlast; + u16 buttonspressed[NUM_PADS]; + u16 buttonsreleased[NUM_PADS]; + s32 unk200; +}; + +struct joydata g_JoyData[NUM_DATA]; +s32 g_JoyDisableCooldown[NUM_PADS]; OSMesgQueue g_PiMesgQueue; OSMesg g_PiMesgBuf[10]; OSMesg g_JoyStopCyclicPollingMesgBuf[1]; @@ -43,7 +62,7 @@ OSMesg g_JoyStartCyclicPollingMesgBuf[1]; OSMesgQueue g_JoyStartCyclicPollingMesgQueue; OSMesg g_JoyStartCyclicPollingDoneMesgBuf[1]; OSMesgQueue g_JoyStartCyclicPollingDoneMesgQueue; -OSContStatus var80099f38[4]; +OSContStatus g_JoyContStatuses[NUM_PADS]; #if VERSION >= VERSION_NTSC_1_0 u8 g_JoyPfsStates[100]; u32 var80099fac; @@ -59,10 +78,10 @@ u32 var8005ee68 = 0; // Number of times per pad that different inputs were attempted to be read // when controller was disconnected or not ready. -u32 g_JoyBadReadsStickX[4] = {0}; -u32 g_JoyBadReadsStickY[4] = {0}; -u32 g_JoyBadReadsButtons[4] = {0}; -u32 g_JoyBadReadsButtonsPressed[4] = {0}; +u32 g_JoyBadReadsStickX[NUM_PADS] = {0}; +u32 g_JoyBadReadsStickY[NUM_PADS] = {0}; +u32 g_JoyBadReadsButtons[NUM_PADS] = {0}; +u32 g_JoyBadReadsButtonsPressed[NUM_PADS] = {0}; u8 g_JoyConnectedControllers = 0; bool g_JoyQueuesCreated = false; @@ -182,7 +201,7 @@ s32 joyShiftPfsStates(void) #if VERSION >= VERSION_NTSC_1_0 void joyRecordPfsState(u8 pfsstate) { - if (g_JoyNextPfsStateIndex + 1 >= 100) { + if (g_JoyNextPfsStateIndex + 1 >= ARRAYCOUNT(g_JoyPfsStates)) { joyShiftPfsStates(); } @@ -292,14 +311,14 @@ void joyInit(void) var8005eec4 = NULL; var8005eec8 = NULL; - for (i = 0; i < 2; i++) { + for (i = 0; i < NUM_DATA; i++) { g_JoyData[i].curlast = 0; g_JoyData[i].curstart = 0; g_JoyData[i].nextlast = 0; g_JoyData[i].nextsecondlast = 0; g_JoyData[i].unk200 = -1; - for (j = 0; j < 4; j++) { + for (j = 0; j < NUM_PADS; j++) { g_JoyData[i].samples[0].pads[j].button = 0; g_JoyData[i].samples[0].pads[j].stick_x = 0; g_JoyData[i].samples[0].pads[j].stick_y = 0; @@ -307,7 +326,7 @@ void joyInit(void) } } - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { g_JoyDisableCooldown[i] = 0; } } @@ -324,7 +343,7 @@ void joyDisableTemporarily(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { g_JoyDisableCooldown[i] = TICKS(60); } } @@ -348,7 +367,7 @@ void joyReset(void) void joy00013e84(void) { - static u8 var8005ef00 = 0xff; + static u8 prevconnected = 0xff; // osContInit should be called only once. The first time this function is // called it'll take the first branch here, and all subsequent calls will @@ -356,10 +375,10 @@ void joy00013e84(void) if (g_JoyNeedsInit) { s32 i; g_JoyNeedsInit = false; - osContInit(&g_PiMesgQueue, &g_JoyConnectedControllers, var80099f38); + osContInit(&g_PiMesgQueue, &g_JoyConnectedControllers, g_JoyContStatuses); g_JoyInitDone = true; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { joyStopRumble(i, false); } } else { @@ -368,10 +387,10 @@ void joy00013e84(void) osContStartQuery(&g_PiMesgQueue); osRecvMesg(&g_PiMesgQueue, NULL, OS_MESG_BLOCK); - osContGetQuery(var80099f38); + osContGetQuery(g_JoyContStatuses); - for (i = 0; i < 4; i++) { - if (var80099f38[i].errno & CONT_NO_RESPONSE_ERROR) { + for (i = 0; i < ARRAYCOUNT(g_JoyContStatuses); i++) { + if (g_JoyContStatuses[i].errno & CONT_NO_RESPONSE_ERROR) { slots -= 1 << i; } } @@ -379,17 +398,17 @@ void joy00013e84(void) g_JoyConnectedControllers = slots; } - if (var8005ef00 != g_JoyConnectedControllers) { + if (prevconnected != g_JoyConnectedControllers) { s32 i = 0; s32 index = 0; - for (; i < 4; i++) { + for (; i < NUM_PADS; i++) { if (g_JoyConnectedControllers & (1 << i)) { g_Vars.playertojoymap[index++] = i; } } - var8005ef00 = g_JoyConnectedControllers; + prevconnected = g_JoyConnectedControllers; } } @@ -401,13 +420,13 @@ s8 contGetFreeSlot(void) return g_JoyDataPtr->unk200; } - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if ((g_JoyConnectedControllers & (1 << i)) == 0) { return i; } } - return 4; + return NUM_PADS; } u32 joyGetConnectedControllers(void) @@ -440,14 +459,15 @@ void joyConsumeSamples(struct joydata *joydata) joydata->curstart = joydata->curlast; joydata->curlast = joydata->nextlast; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { joydata->buttonspressed[i] = 0; joydata->buttonsreleased[i] = 0; if (joydata->curlast != joydata->curstart) { - samplenum = (joydata->curstart + 1) % 20; while (true) { + samplenum = (joydata->curstart + 1) % NUM_SAMPLES; \ + while (true) { buttons1 = joydata->samples[samplenum].pads[i].button; - buttons2 = joydata->samples[(samplenum + 19) % 20].pads[i].button; + buttons2 = joydata->samples[(samplenum + NUM_SAMPLES - 1) % NUM_SAMPLES].pads[i].button; joydata->buttonspressed[i] |= buttons1 & ~buttons2; joydata->buttonsreleased[i] |= ~buttons1 & buttons2; @@ -468,7 +488,7 @@ void joyConsumeSamples(struct joydata *joydata) break; } - samplenum = (samplenum + 1) % 20; + samplenum = (samplenum + 1) % NUM_SAMPLES; } } } @@ -506,7 +526,7 @@ void joy00014238(void) if (!doingit) { doingit = true; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if (joy000155f4(i) == PAK010_13) { pakSetUnk010(i, PAK010_11); } @@ -587,7 +607,7 @@ s32 joyStartReadData(OSMesgQueue *mq) void joyReadData(void) { - s32 index = (g_JoyData[0].nextlast + 1) % 20; + s32 index = (g_JoyData[0].nextlast + 1) % NUM_SAMPLES; if (index == g_JoyData[0].curstart) { // If the sample queue is full, don't overwrite the oldest sample. @@ -598,7 +618,7 @@ void joyReadData(void) osContGetReadData(g_JoyData[0].samples[index].pads); g_JoyData[0].nextlast = index; - g_JoyData[0].nextsecondlast = (g_JoyData[0].nextlast + 19) % 20; + g_JoyData[0].nextsecondlast = (g_JoyData[0].nextlast + NUM_SAMPLES - 1) % NUM_SAMPLES; } void joysHandleRetrace(void) @@ -618,7 +638,7 @@ void joysHandleRetrace(void) joyReadData(); // Check if error state has changed for any controller - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno != 0) || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno == 0)) { joy00013e84(); @@ -670,7 +690,7 @@ void joysHandleRetrace(void) joyReadData(); // Check if error state has changed for any controller - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if ((g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno == 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno != 0) || (g_JoyData[0].samples[g_JoyData[0].nextlast].pads[i].errno != 0 && g_JoyData[0].samples[g_JoyData[0].nextsecondlast].pads[i].errno == 0)) { joy00013e84(); @@ -694,7 +714,7 @@ void joysHandleRetrace(void) if (count >= 60) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if (g_JoyBadReadsStickX[i] || g_JoyBadReadsStickY[i] || g_JoyBadReadsButtons[i] || g_JoyBadReadsButtonsPressed[i]) { g_JoyBadReadsStickX[i] = 0; g_JoyBadReadsStickY[i] = 0; @@ -716,7 +736,7 @@ void joy00014810(bool value) s32 joyGetNumSamples(void) { - return (g_JoyDataPtr->curlast - g_JoyDataPtr->curstart + 20) % 20; + return (g_JoyDataPtr->curlast - g_JoyDataPtr->curstart + NUM_SAMPLES) % NUM_SAMPLES; } s32 joyGetStickXOnSample(s32 samplenum, s8 contpadnum) @@ -730,7 +750,7 @@ s32 joyGetStickXOnSample(s32 samplenum, s8 contpadnum) return 0; } - return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % 20].pads[contpadnum].stick_x; + return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % NUM_SAMPLES].pads[contpadnum].stick_x; } s32 joyGetStickYOnSample(s32 samplenum, s8 contpadnum) @@ -744,7 +764,7 @@ s32 joyGetStickYOnSample(s32 samplenum, s8 contpadnum) return 0; } - return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % 20].pads[contpadnum].stick_y; + return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % NUM_SAMPLES].pads[contpadnum].stick_y; } s32 joyGetStickYOnSampleIndex(s32 samplenum, s8 contpadnum) @@ -758,7 +778,7 @@ s32 joyGetStickYOnSampleIndex(s32 samplenum, s8 contpadnum) return 0; } - return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum) % 20].pads[contpadnum].stick_y; + return g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum) % NUM_SAMPLES].pads[contpadnum].stick_y; } u16 joyGetButtonsOnSample(s32 samplenum, s8 contpadnum, u16 mask) @@ -774,7 +794,7 @@ u16 joyGetButtonsOnSample(s32 samplenum, s8 contpadnum, u16 mask) return 0; } - button = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % 20].pads[contpadnum].button; + button = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % NUM_SAMPLES].pads[contpadnum].button; return button & mask; } @@ -793,8 +813,8 @@ u16 joyGetButtonsPressedOnSample(s32 samplenum, s8 contpadnum, u16 mask) return 0; } - button1 = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % 20].pads[contpadnum].button; - button2 = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum) % 20].pads[contpadnum].button; + button1 = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum + 1) % NUM_SAMPLES].pads[contpadnum].button; + button2 = g_JoyDataPtr->samples[(g_JoyDataPtr->curstart + samplenum) % NUM_SAMPLES].pads[contpadnum].button; return (button1 & ~button2) & mask; } @@ -822,7 +842,7 @@ s32 joyCountButtonsOnSpecificSamples(u32 *checksamples, s8 contpadnum, u16 mask) return 0; } - i = (g_JoyDataPtr->curstart + 1) % 20; + i = (g_JoyDataPtr->curstart + 1) % NUM_SAMPLES; while (true) { if (checksamples == NULL || checksamples[index]) { @@ -837,7 +857,7 @@ s32 joyCountButtonsOnSpecificSamples(u32 *checksamples, s8 contpadnum, u16 mask) break; } - i = (i + 1) % 20; + i = (i + 1) % NUM_SAMPLES; index++; } @@ -987,7 +1007,7 @@ void joyDestroy(void) osCreateMesgQueue(&g_PiMesgQueue, g_PiMesgBuf, ARRAYCOUNT(g_PiMesgBuf)); osSetEventMesg(OS_EVENT_SI, &g_PiMesgQueue, 0); - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if (osMotorProbe(&g_PiMesgQueue, PFS(i), i) == 0) { osMotorStop(PFS(i)); osMotorStop(PFS(i)); @@ -1072,7 +1092,7 @@ void joysTickRumble(void) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_PADS; i++) { if (g_Paks[i].unk010 == PAK010_11 && g_Paks[i].type == PAKTYPE_RUMBLE) { switch (g_Paks[i].rumblestate) { case RUMBLESTATE_ENABLED_STARTING: diff --git a/src/lib/memp.c b/src/lib/memp.c index 8fa817f5b..17005c214 100644 --- a/src/lib/memp.c +++ b/src/lib/memp.c @@ -70,7 +70,7 @@ void mempSetHeap(u8 *heapstart, u32 heaplen) s32 i; u8 *extraend; - for (i = 0; i < 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_MempOnboardPools); i++) { g_MempOnboardPools[i].start = 0; g_MempOnboardPools[i].leftpos = 0; g_MempOnboardPools[i].rightpos = 0; @@ -106,7 +106,7 @@ void mempSetHeap(u8 *heapstart, u32 heaplen) g_MempExpansionPools[MEMPOOL_STAGE].rightpos = extraend; } - for (i = 0; i < 9; i++) { + for (i = 0; i < ARRAYCOUNT(g_MempOnboardPools); i++) { g_MempOnboardPools[i].end = g_MempOnboardPools[i].rightpos; g_MempExpansionPools[i].end = g_MempExpansionPools[i].rightpos; }