From 7143865f6f7dd8c17077111eac49a8972fb31399 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 6 Jun 2022 15:15:46 -0400 Subject: [PATCH 1/4] Add some battle frontier constant usage --- include/constants/battle_frontier.h | 10 +++ include/constants/battle_pike.h | 2 + include/constants/battle_pyramid.h | 7 ++ include/constants/battle_tent.h | 6 ++ include/constants/union_room.h | 2 + include/global.h | 2 +- src/battle_dome.c | 2 +- src/battle_factory.c | 44 ++++++----- src/battle_pike.c | 24 +++--- src/battle_pyramid.c | 78 +++++++++---------- src/battle_pyramid_bag.c | 6 +- src/battle_tent.c | 40 +++++----- src/battle_tower.c | 66 +++++++++------- .../battle_pyramid_open_level_wild_mons.h | 2 +- src/frontier_util.c | 17 ++-- src/map_name_popup.c | 5 +- src/mystery_gift_client.c | 2 +- src/party_menu.c | 6 +- src/pokemon.c | 2 +- src/start_menu.c | 7 +- src/union_room.c | 2 +- 21 files changed, 189 insertions(+), 143 deletions(-) diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index b6d15e6b2..6cfdc7931 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -1,6 +1,8 @@ #ifndef GUARD_CONSTANTS_BATTLE_FRONTIER_H #define GUARD_CONSTANTS_BATTLE_FRONTIER_H +#include "constants/pokemon.h" + #define FRONTIER_CHALLENGE(facility, mode) ((facility << 8) + mode) // Battle Frontier facility ids. @@ -46,6 +48,14 @@ #define MAX_BATTLE_FRONTIER_POINTS 9999 #define MAX_STREAK 9999 +#define FRONTIER_MAX_LEVEL_50 50 +#define FRONTIER_MIN_LEVEL_OPEN 60 +#define FRONTIER_MAX_LEVEL_OPEN MAX_LEVEL + +// This is the default number of battles (or floors, in Battle Pyramid) per challenge. +// There are 2 facilities that differ: Battle Dome (DOME_ROUNDS_COUNT) and Battle Pike (NUM_PIKE_ROOMS). +#define FRONTIER_STAGES_PER_CHALLENGE 7 + // These sets of facility ids would be redundant if the order was consistent // The order is important for this set so that all the non-link records can be continuous #define RANKING_HALL_TOWER_SINGLES 0 diff --git a/include/constants/battle_pike.h b/include/constants/battle_pike.h index 76309436e..eebfd741a 100644 --- a/include/constants/battle_pike.h +++ b/include/constants/battle_pike.h @@ -1,6 +1,8 @@ #ifndef GUARD_CONSTANTS_BATTLE_PIKE_H #define GUARD_CONSTANTS_BATTLE_PIKE_H +#define NUM_PIKE_ROOMS 14 + #define PIKE_ROOM_SINGLE_BATTLE 0 #define PIKE_ROOM_HEAL_FULL 1 #define PIKE_ROOM_NPC 2 diff --git a/include/constants/battle_pyramid.h b/include/constants/battle_pyramid.h index ebb753882..297f3b1ff 100644 --- a/include/constants/battle_pyramid.h +++ b/include/constants/battle_pyramid.h @@ -14,6 +14,13 @@ #define HINT_EXIT_FAR_REMAINING_TRAINERS 7 #define HINT_EXIT_FAR_REMAINING_ITEMS 8 +#define MAX_PYRAMID_TRAINERS 8 + +// Each floor of the Battle Pyramid is 32x32 metatiles, subdivided into a 4x4 grid of 8x8 metatile squares +#define PYRAMID_FLOOR_SQUARES_WIDE 4 +#define PYRAMID_FLOOR_SQUARES_HIGH 4 +#define NUM_PYRAMID_FLOOR_SQUARES (PYRAMID_FLOOR_SQUARES_WIDE * PYRAMID_FLOOR_SQUARES_HIGH) + #define OBJ_TRAINERS 0 #define OBJ_ITEMS 1 diff --git a/include/constants/battle_tent.h b/include/constants/battle_tent.h index 666ada6bd..6f9989b7a 100644 --- a/include/constants/battle_tent.h +++ b/include/constants/battle_tent.h @@ -1,6 +1,12 @@ #ifndef GUARD_CONSTANTS_BATTLE_TENT_H #define GUARD_CONSTANTS_BATTLE_TENT_H +#define TENT_MIN_LEVEL 30 + +// The number of battles in each Battle Tent challenge. +// Battle Tent equivalent of FRONTIER_STAGES_PER_CHALLENGE. +#define TENT_STAGES_PER_CHALLENGE 3 + #define VERDANTURF_TENT_FUNC_INIT 0 #define VERDANTURF_TENT_FUNC_GET_PRIZE 1 #define VERDANTURF_TENT_FUNC_SET_PRIZE 2 diff --git a/include/constants/union_room.h b/include/constants/union_room.h index 6e08c9ebb..f47a8723f 100644 --- a/include/constants/union_room.h +++ b/include/constants/union_room.h @@ -11,6 +11,8 @@ #define UNION_ROOM_SPAWN_IN 1 #define UNION_ROOM_SPAWN_OUT 2 +#define UNION_ROOM_MAX_LEVEL 30 + #define ACTIVITY_NONE 0 #define ACTIVITY_BATTLE_SINGLE 1 #define ACTIVITY_BATTLE_DOUBLE 2 diff --git a/include/global.h b/include/global.h index 60476b13f..64af518ce 100644 --- a/include/global.h +++ b/include/global.h @@ -409,7 +409,7 @@ struct BattleFrontier /*0xE1A*/ u16 pyramidWinStreaks[FRONTIER_LVL_MODE_COUNT]; /*0xE1E*/ u16 pyramidRecordStreaks[FRONTIER_LVL_MODE_COUNT]; /*0xE22*/ u16 pyramidRandoms[4]; - /*0xE2A*/ u8 pyramidTrainerFlags; + /*0xE2A*/ u8 pyramidTrainerFlags; // 1 bit for each trainer (MAX_PYRAMID_TRAINERS) /*0xE2C*/ struct PyramidBag pyramidBag; /*0xE68*/ u8 pyramidLightRadius; /*0xE6A*/ u16 verdanturfTentPrize; diff --git a/src/battle_dome.c b/src/battle_dome.c index aadd85afd..5c18cff42 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -5847,7 +5847,7 @@ static void InitRandomTourneyTreeResults(void) DOME_TRAINERS[i].forfeited = FALSE; } - monLevel = 50; + monLevel = FRONTIER_MAX_LEVEL_50; for (i = 0; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++) { monTypesBits = 0; diff --git a/src/battle_factory.c b/src/battle_factory.c index d88ed37f9..a68ef8180 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -12,15 +12,15 @@ #include "constants/battle_factory.h" #include "constants/battle_frontier.h" #include "constants/battle_frontier_mons.h" +#include "constants/battle_tent.h" #include "constants/frontier_util.h" #include "constants/layouts.h" #include "constants/trainers.h" #include "constants/moves.h" +#include "constants/items.h" -// IWRAM bss static bool8 sPerformedRentalSwap; -// This file's functions. static void InitFactoryChallenge(void); static void GetBattleFactoryData(void); static void SetBattleFactoryData(void); @@ -212,7 +212,7 @@ static void InitFactoryChallenge(void) } sPerformedRentalSwap = FALSE; - for (i = 0; i < 6; i++) + for (i = 0; i < ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons); i++) gSaveBlock2Ptr->frontier.rentalMons[i].monId = 0xFFFF; for (i = 0; i < FRONTIER_PARTY_SIZE; i++) gFrontierTempParty[i] = 0xFFFF; @@ -310,11 +310,12 @@ static void GenerateOpponentMons(void) u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u32 winStreak = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode]; - u32 challengeNum = winStreak / 7; + u32 challengeNum = winStreak / FRONTIER_STAGES_PER_CHALLENGE; gFacilityTrainers = gBattleFrontierTrainers; do { + // Choose a random trainer, ensuring no repeats in this challenge trainerId = GetRandomScaledFrontierTrainerId(challengeNum, gSaveBlock2Ptr->frontier.curChallengeBattleNum); for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { @@ -324,27 +325,32 @@ static void GenerateOpponentMons(void) } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); gTrainerBattleOpponent_A = trainerId; - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < FRONTIER_STAGES_PER_CHALLENGE - 1) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = trainerId; i = 0; while (i != FRONTIER_PARTY_SIZE) { u16 monId = GetFactoryMonId(lvlMode, challengeNum, FALSE); + + // Unown (FRONTIER_MON_UNOWN) is forbidden on opponent Factory teams. if (gFacilityTrainerMons[monId].species == SPECIES_UNOWN) continue; - for (j = 0; j < 6; j++) + // Ensure none of the opponent's pokemon are the same as the potential rental pokemon for the player + for (j = 0; j < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons); j++) { if (gFacilityTrainerMons[monId].species == gFacilityTrainerMons[gSaveBlock2Ptr->frontier.rentalMons[j].monId].species) break; } - if (j != 6) + if (j != (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons)) continue; + // "High tier" pokemon are only allowed on open level mode if (lvlMode == FRONTIER_LVL_50 && monId > FRONTIER_MONS_HIGH_TIER) continue; + // Ensure this species hasn't already been chosen for the opponent for (k = firstMonId; k < firstMonId + i; k++) { if (species[k] == gFacilityTrainerMons[monId].species) @@ -353,14 +359,16 @@ static void GenerateOpponentMons(void) if (k != firstMonId + i) continue; + // Ensure held items don't repeat on the opponent's team for (k = firstMonId; k < firstMonId + i; k++) { - if (heldItems[k] != 0 && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]) + if (heldItems[k] != ITEM_NONE && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]) break; } if (k != firstMonId + i) continue; + // Successful selection species[i] = gFacilityTrainerMons[monId].species; heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]; gFrontierTempParty[i] = monId; @@ -406,15 +414,15 @@ static void SetPlayerAndOpponentParties(void) if (gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_TENT) { gFacilityTrainerMons = gSlateportBattleTentMons; - monLevel = 30; + monLevel = TENT_MIN_LEVEL; } else { gFacilityTrainerMons = gBattleFrontierMons; if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) - monLevel = 100; + monLevel = FRONTIER_MAX_LEVEL_OPEN; else - monLevel = 50; + monLevel = FRONTIER_MAX_LEVEL_50; } if (gSpecialVar_0x8005 < 2) @@ -618,9 +626,9 @@ static void GetOpponentMostCommonMonType(void) // Determine which are the two most-common types. // The second most-common type is only updated if // its count is equal to the most-common type. - mostCommonTypes[0] = TYPE_NORMAL; - mostCommonTypes[1] = TYPE_NORMAL; - for (i = TYPE_FIGHTING; i < NUMBER_OF_MON_TYPES; i++) + mostCommonTypes[0] = 0; + mostCommonTypes[1] = 0; + for (i = 1; i < NUMBER_OF_MON_TYPES; i++) { if (typeCounts[mostCommonTypes[0]] < typeCounts[i]) mostCommonTypes[0] = i; @@ -765,15 +773,15 @@ void FillFactoryBrainParty(void) if (gFacilityTrainerMons[monId].species == SPECIES_UNOWN) continue; - if (monLevel == 50 && monId > FRONTIER_MONS_HIGH_TIER) + if (monLevel == FRONTIER_MAX_LEVEL_50 && monId > FRONTIER_MONS_HIGH_TIER) continue; - for (j = 0; j < 6; j++) + for (j = 0; j < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons); j++) { if (monId == gSaveBlock2Ptr->frontier.rentalMons[j].monId) break; } - if (j != 6) + if (j != (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons)) continue; for (k = 0; k < i; k++) @@ -786,7 +794,7 @@ void FillFactoryBrainParty(void) for (k = 0; k < i; k++) { - if (heldItems[k] != 0 && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]) + if (heldItems[k] != ITEM_NONE && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]) break; } if (k != i) diff --git a/src/battle_pike.c b/src/battle_pike.c index 2b0cf6420..6c97c99fc 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -684,7 +684,7 @@ static void SetBattlePikeData(void) static void IsNextRoomFinal(void) { - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum > 14) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum > NUM_PIKE_ROOMS) gSpecialVar_Result = TRUE; else gSpecialVar_Result = FALSE; @@ -1117,20 +1117,20 @@ bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate) if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) { monLevel = GetHighestLevelInPlayerParty(); - if (monLevel < 60) + if (monLevel < FRONTIER_MIN_LEVEL_OPEN) { - monLevel = 60; + monLevel = FRONTIER_MIN_LEVEL_OPEN; } else { monLevel -= wildMons[headerId][pikeMonId].levelDelta; - if (monLevel < 60) - monLevel = 60; + if (monLevel < FRONTIER_MIN_LEVEL_OPEN) + monLevel = FRONTIER_MIN_LEVEL_OPEN; } } else { - monLevel = 50 - wildMons[headerId][pikeMonId].levelDelta; + monLevel = FRONTIER_MAX_LEVEL_50 - wildMons[headerId][pikeMonId].levelDelta; } if (checkKeenEyeIntimidate == TRUE && !CanEncounterWildMon(monLevel)) @@ -1395,7 +1395,7 @@ static void PrepareOneTrainer(bool8 difficult) battleNum = 6; lvlMode = gSaveBlock2Ptr->frontier.lvlMode; - challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / 14; + challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / NUM_PIKE_ROOMS; do { trainerId = GetRandomScaledFrontierTrainerId(challengeNum, battleNum); @@ -1409,7 +1409,7 @@ static void PrepareOneTrainer(bool8 difficult) gTrainerBattleOpponent_A = trainerId; gFacilityTrainers = gBattleFrontierTrainers; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 14) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < NUM_PIKE_ROOMS) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; } @@ -1418,7 +1418,7 @@ static void PrepareTwoTrainers(void) int i; u16 trainerId; u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; - u16 challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / 14; + u16 challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / NUM_PIKE_ROOMS; gFacilityTrainers = gBattleFrontierTrainers; do @@ -1433,7 +1433,7 @@ static void PrepareTwoTrainers(void) gTrainerBattleOpponent_A = trainerId; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= 14) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= NUM_PIKE_ROOMS) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; do @@ -1448,7 +1448,7 @@ static void PrepareTwoTrainers(void) gTrainerBattleOpponent_B = trainerId; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 14) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < NUM_PIKE_ROOMS) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2] = gTrainerBattleOpponent_B; } @@ -1456,7 +1456,7 @@ static void ClearPikeTrainerIds(void) { u8 i; - for (i = 0; i < 14; i++) + for (i = 0; i < NUM_PIKE_ROOMS; i++) gSaveBlock2Ptr->frontier.trainerIds[i] = 0xFFFF; } diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 9039f60f2..bbd4c84dc 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -279,9 +279,9 @@ static const u8 sPyramidFloorTemplateOptions[][2] = {100, 15} }; -static const u8 sFloorTemplateOffsets[] = +static const u8 sFloorTemplateOffsets[FRONTIER_STAGES_PER_CHALLENGE] = { - 0, 4, 9, 14, 19, 24, 29, 0 + 0, 4, 9, 14, 19, 24, 29 }; static const u16 sPickupItemsLvl50[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND] = @@ -406,7 +406,7 @@ static const u8 sPickupItemSlots[][2] = {100, 9}, }; -static const u8 sPickupItemOffsets[] = {0, 9, 18, 27, 36, 45, 54}; +static const u8 sPickupItemOffsets[FRONTIER_STAGES_PER_CHALLENGE] = {0, 9, 18, 27, 36, 45, 54}; static const struct PyramidTrainerEncounterMusic sTrainerClassEncounterMusic[54] = { @@ -963,7 +963,7 @@ static void SeedPyramidFloor(void) { int i; - for (i = 0; i < 4; i++) + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.pyramidRandoms); i++) gSaveBlock2Ptr->frontier.pyramidRandoms[i] = Random(); gSaveBlock2Ptr->frontier.pyramidTrainerFlags = 0; @@ -977,7 +977,7 @@ static void SetPickupItem(void) u8 id; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % TOTAL_ROUNDS; + u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE) % TOTAL_ROUNDS; if (round >= TOTAL_ROUNDS) round = TOTAL_ROUNDS - 1; @@ -1016,8 +1016,8 @@ static void HidePyramidItem(void) { // Rather than using event flags to hide the item object event, // it moves them far off the map bounds. - events[i].x = 0x7FFF; - events[i].y = 0x7FFF; + events[i].x = SHRT_MAX; + events[i].y = SHRT_MAX; break; } i++; @@ -1063,7 +1063,7 @@ static void ShowPostBattleHintText(void) case HINT_REMAINING_ITEMS: for (i = 0; i < GetNumBattlePyramidObjectEvents(); i++) { - if (events[i].graphicsId == OBJ_EVENT_GFX_ITEM_BALL && events[i].x != 0x7FFF && events[i].y != 0x7FFF) + if (events[i].graphicsId == OBJ_EVENT_GFX_ITEM_BALL && events[i].x != SHRT_MAX && events[i].y != SHRT_MAX) textIndex++; } i = 1; @@ -1071,7 +1071,7 @@ static void ShowPostBattleHintText(void) case HINT_REMAINING_TRAINERS: id = GetPyramidFloorTemplateId(); textIndex = sPyramidFloorTemplates[id].numTrainers; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_PYRAMID_TRAINERS; i++) { if (gBitTable[i] & gSaveBlock2Ptr->frontier.pyramidTrainerFlags) textIndex--; @@ -1326,7 +1326,7 @@ static void MarkPyramidTrainerAsBattled(u16 trainerId) { int i; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_PYRAMID_TRAINERS; i++) { if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId) gSaveBlock2Ptr->frontier.pyramidTrainerFlags |= gBitTable[i]; @@ -1345,7 +1345,7 @@ void GenerateBattlePyramidWildMon(void) const struct PyramidWildMon *wildMons; u32 id; u32 lvl = gSaveBlock2Ptr->frontier.lvlMode; - u16 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] / 7) % TOTAL_ROUNDS; + u16 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] / FRONTIER_STAGES_PER_CHALLENGE) % TOTAL_ROUNDS; if (round >= TOTAL_ROUNDS) round = TOTAL_ROUNDS - 1; @@ -1488,13 +1488,13 @@ static u16 GetUniqueTrainerId(u8 objectEventId) int i; u16 trainerId; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; - u32 challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7; - u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (battleNum == 7) + u32 challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; + u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + if (floor == FRONTIER_STAGES_PER_CHALLENGE) { do { - trainerId = GetRandomScaledFrontierTrainerId(challengeNum + 1, battleNum); + trainerId = GetRandomScaledFrontierTrainerId(challengeNum + 1, floor); for (i = 0; i < objectEventId; i++) { if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId) @@ -1506,7 +1506,7 @@ static u16 GetUniqueTrainerId(u8 objectEventId) { do { - trainerId = GetRandomScaledFrontierTrainerId(challengeNum, battleNum); + trainerId = GetRandomScaledFrontierTrainerId(challengeNum, floor); for (i = 0; i < objectEventId; i++) { if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId) @@ -1523,11 +1523,11 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio int y, x; int i; u8 entranceSquareId, exitSquareId; - u8 *floorLayoutOffsets = AllocZeroed(16); + u8 *floorLayoutOffsets = AllocZeroed(NUM_PYRAMID_FLOOR_SQUARES); GetPyramidFloorLayoutOffsets(floorLayoutOffsets); GetPyramidEntranceAndExitSquareIds(&entranceSquareId, &exitSquareId); - for (i = 0; i < 16; i++) + for (i = 0; i < NUM_PYRAMID_FLOOR_SQUARES; i++) { u16 *map; int yOffset, xOffset; @@ -1535,11 +1535,11 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio const u16 *layoutMap = mapLayout->map; gBackupMapLayout.map = backupMapData; - gBackupMapLayout.width = mapLayout->width * 4 + MAP_OFFSET_W; - gBackupMapLayout.height = mapLayout->height * 4 + MAP_OFFSET_H; + gBackupMapLayout.width = mapLayout->width * PYRAMID_FLOOR_SQUARES_WIDE + MAP_OFFSET_W; + gBackupMapLayout.height = mapLayout->height * PYRAMID_FLOOR_SQUARES_HIGH + MAP_OFFSET_H; map = backupMapData; - yOffset = ((i / 4 * mapLayout->height) + MAP_OFFSET) * gBackupMapLayout.width; - xOffset = (i % 4 * mapLayout->width) + MAP_OFFSET; + yOffset = ((i / PYRAMID_FLOOR_SQUARES_WIDE * mapLayout->height) + MAP_OFFSET) * gBackupMapLayout.width; + xOffset = (i % PYRAMID_FLOOR_SQUARES_WIDE * mapLayout->width) + MAP_OFFSET; map += yOffset + xOffset; for (y = 0; y < mapLayout->height; y++) { @@ -1553,8 +1553,8 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio { if (i == entranceSquareId && setPlayerPosition == FALSE) { - gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % 4)) + x; - gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / 4)) + y; + gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % PYRAMID_FLOOR_SQUARES_WIDE)) + x; + gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / PYRAMID_FLOOR_SQUARES_WIDE)) + y; } map[x] = (layoutMap[x] & (MAPGRID_ELEVATION_MASK | MAPGRID_COLLISION_MASK)) | METATILE_BattlePyramid_Floor; } @@ -1563,7 +1563,7 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio map[x] = layoutMap[x]; } } - map += MAP_OFFSET_W + (mapLayout->width * 4); + map += MAP_OFFSET_W + (mapLayout->width * PYRAMID_FLOOR_SQUARES_WIDE); layoutMap += mapLayout->width; } } @@ -1577,7 +1577,7 @@ void LoadBattlePyramidObjectEventTemplates(void) u8 id; u8 entranceSquareId, exitSquareId; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_PYRAMID_TRAINERS; i++) gSaveBlock2Ptr->frontier.trainerIds[i] = 0xFFFF; id = GetPyramidFloorTemplateId(); @@ -1633,13 +1633,13 @@ void LoadBattlePyramidFloorObjectEventScripts(void) static void GetPyramidEntranceAndExitSquareIds(u8 *entranceSquareId, u8 *exitSquareId) { - *entranceSquareId = gSaveBlock2Ptr->frontier.pyramidRandoms[3] % 16; - *exitSquareId = gSaveBlock2Ptr->frontier.pyramidRandoms[0] % 16; + *entranceSquareId = gSaveBlock2Ptr->frontier.pyramidRandoms[3] % NUM_PYRAMID_FLOOR_SQUARES; + *exitSquareId = gSaveBlock2Ptr->frontier.pyramidRandoms[0] % NUM_PYRAMID_FLOOR_SQUARES; if (*entranceSquareId == *exitSquareId) { - *entranceSquareId = (gSaveBlock2Ptr->frontier.pyramidRandoms[3] + 1 ) % 16; - *exitSquareId = (gSaveBlock2Ptr->frontier.pyramidRandoms[0] + 15) % 16; + *entranceSquareId = (gSaveBlock2Ptr->frontier.pyramidRandoms[3] + 1 ) % NUM_PYRAMID_FLOOR_SQUARES; + *exitSquareId = (gSaveBlock2Ptr->frontier.pyramidRandoms[0] + NUM_PYRAMID_FLOOR_SQUARES - 1) % NUM_PYRAMID_FLOOR_SQUARES; } } @@ -1651,10 +1651,10 @@ static void SetPyramidObjectPositionsUniformly(u8 objType) int squareId; u32 bits = 0; u8 id = GetPyramidFloorTemplateId(); - u8 *floorLayoutOffsets = AllocZeroed(16); + u8 *floorLayoutOffsets = AllocZeroed(NUM_PYRAMID_FLOOR_SQUARES); GetPyramidFloorLayoutOffsets(floorLayoutOffsets); - squareId = gSaveBlock2Ptr->frontier.pyramidRandoms[2] % 16; + squareId = gSaveBlock2Ptr->frontier.pyramidRandoms[2] % NUM_PYRAMID_FLOOR_SQUARES; if (objType == OBJ_TRAINERS) { numObjects = sPyramidFloorTemplates[id].numTrainers; @@ -1682,10 +1682,10 @@ static void SetPyramidObjectPositionsUniformly(u8 objType) if (gBitTable[squareId] & gSaveBlock2Ptr->frontier.pyramidRandoms[3]) bits |= 2; } - if (++squareId >= 16) + if (++squareId >= NUM_PYRAMID_FLOOR_SQUARES) squareId = 0; - if (squareId == gSaveBlock2Ptr->frontier.pyramidRandoms[2] % 16) + if (squareId == gSaveBlock2Ptr->frontier.pyramidRandoms[2] % NUM_PYRAMID_FLOOR_SQUARES) { if (bits & 1) bits |= 6; @@ -1709,7 +1709,7 @@ static bool8 SetPyramidObjectPositionsInAndNearSquare(u8 objType, u8 squareId) int numPlacedObjects = 0; int numObjects; u8 id = GetPyramidFloorTemplateId(); - u8 *floorLayoutOffsets = AllocZeroed(16); + u8 *floorLayoutOffsets = AllocZeroed(NUM_PYRAMID_FLOOR_SQUARES); GetPyramidFloorLayoutOffsets(floorLayoutOffsets); if (objType == OBJ_TRAINERS) @@ -1775,7 +1775,7 @@ static bool8 SetPyramidObjectPositionsNearSquare(u8 objType, u8 squareId) int r8 = 0; int numObjects; u8 id = GetPyramidFloorTemplateId(); - u8 *floorLayoutOffsets = AllocZeroed(16); + u8 *floorLayoutOffsets = AllocZeroed(NUM_PYRAMID_FLOOR_SQUARES); GetPyramidFloorLayoutOffsets(floorLayoutOffsets); if (objType == OBJ_TRAINERS) @@ -1900,7 +1900,7 @@ static void GetPyramidFloorLayoutOffsets(u8 *layoutOffsets) int rand = (gSaveBlock2Ptr->frontier.pyramidRandoms[0]) | (gSaveBlock2Ptr->frontier.pyramidRandoms[1] << 16); u8 id = GetPyramidFloorTemplateId(); - for (i = 0; i < 16; i++) + for (i = 0; i < NUM_PYRAMID_FLOOR_SQUARES; i++) { layoutOffsets[i] = sPyramidFloorTemplates[id].layoutOffsets[rand & 0x7]; rand >>= 3; @@ -1931,7 +1931,7 @@ u8 GetNumBattlePyramidObjectEvents(void) u8 i; struct ObjectEventTemplate *events = gSaveBlock1Ptr->objectEventTemplates; - for (i = 0; i < 16; i++) + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { if (events[i].localId == 0) break; @@ -1959,7 +1959,7 @@ u16 GetBattlePyramidPickupItemId(void) int rand; u32 i; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; - int round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7); + int round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE); if (round >= TOTAL_ROUNDS) round = TOTAL_ROUNDS - 1; diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index d1b946146..66b4cd97d 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -1410,7 +1410,7 @@ void TryStoreHeldItemsInPyramidBag(void) memcpy(newItems, gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u16)); memcpy(newQuantities, gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode], PYRAMID_BAG_ITEMS_COUNT * sizeof(u8)); - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { heldItem = GetMonData(&party[i], MON_DATA_HELD_ITEM); if (heldItem != ITEM_NONE && !AddBagItem(heldItem, 1)) @@ -1426,10 +1426,8 @@ void TryStoreHeldItemsInPyramidBag(void) } heldItem = ITEM_NONE; - for (i = 0; i < 3; i++) - { + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) SetMonData(&party[i], MON_DATA_HELD_ITEM, &heldItem); - } gSpecialVar_Result = 0; Free(newItems); Free(newQuantities); diff --git a/src/battle_tent.c b/src/battle_tent.c index 53c91c871..dba9e6e8a 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -56,10 +56,8 @@ static void GenerateInitialRentalMons(void); * */ -// IWRAM bss -static u16 sRandMonSetId; +static u16 sRandMonId; -// const rom data void static (*const sVerdanturfTentFuncs[])(void) = { [VERDANTURF_TENT_FUNC_INIT] = InitVerdanturfTentChallenge, @@ -357,7 +355,7 @@ static void GenerateOpponentMons(void) const u16 *monSet; u16 species[FRONTIER_PARTY_SIZE]; u16 heldItems[FRONTIER_PARTY_SIZE]; - s32 monId = 0; + s32 numMons = 0; gFacilityTrainers = gSlateportBattleTentTrainers; gFacilityTrainerMons = gSlateportBattleTentMons; @@ -366,6 +364,7 @@ static void GenerateOpponentMons(void) { do { + // Choose a random trainer, ensuring no repeats in this challenge trainerId = Random() % NUM_BATTLE_TENT_TRAINERS; for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { @@ -376,48 +375,53 @@ static void GenerateOpponentMons(void) gTrainerBattleOpponent_A = trainerId; monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; - while (monSet[monId] != 0xFFFF) - monId++; - if (monId > 8) + while (monSet[numMons] != 0xFFFF) + numMons++; + if (numMons > 8) break; - monId = 0; + numMons = 0; } - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < TENT_STAGES_PER_CHALLENGE - 1) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; i = 0; while (i != FRONTIER_PARTY_SIZE) { - sRandMonSetId = monSet[Random() % monId]; - for (j = 0; j < 6; j++) + sRandMonId = monSet[Random() % numMons]; + + // Ensure none of the opponent's pokemon are the same as the potential rental pokemon for the player + for (j = 0; j < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons); j++) { - if (gFacilityTrainerMons[sRandMonSetId].species == gFacilityTrainerMons[gSaveBlock2Ptr->frontier.rentalMons[j].monId].species) + if (gFacilityTrainerMons[sRandMonId].species == gFacilityTrainerMons[gSaveBlock2Ptr->frontier.rentalMons[j].monId].species) break; } - if (j != 6) + if (j != (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.rentalMons)) continue; + // Ensure this species hasn't already been chosen for the opponent for (k = 0; k < i; k++) { - if (species[k] == gFacilityTrainerMons[sRandMonSetId].species) + if (species[k] == gFacilityTrainerMons[sRandMonId].species) break; } if (k != i) continue; + // Ensure held items don't repeat on the opponent's team for (k = 0; k < i; k++) { - if (heldItems[k] != 0 && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonSetId].itemTableId]) + if (heldItems[k] != ITEM_NONE && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonId].itemTableId]) break; } if (k != i) continue; - species[i] = gFacilityTrainerMons[sRandMonSetId].species; - heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonSetId].itemTableId]; - gFrontierTempParty[i] = sRandMonSetId; + // Successful selection + species[i] = gFacilityTrainerMons[sRandMonId].species; + heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonId].itemTableId]; + gFrontierTempParty[i] = sRandMonId; i++; } } diff --git a/src/battle_tower.c b/src/battle_tower.c index e652038ac..839b99b24 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -27,6 +27,7 @@ #include "constants/battle_dome.h" #include "constants/battle_frontier.h" #include "constants/battle_frontier_mons.h" +#include "constants/battle_tent.h" #include "constants/battle_tent_mons.h" #include "constants/battle_tent_trainers.h" #include "constants/battle_tower.h" @@ -1060,7 +1061,7 @@ static void SetNextFacilityOpponent(void) u16 id; u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u16 winStreak = GetCurrentFacilityWinStreak(); - u32 challengeNum = winStreak / 7; + u32 challengeNum = winStreak / FRONTIER_STAGES_PER_CHALLENGE; SetFacilityPtrsGetLevel(); if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS) @@ -1095,7 +1096,7 @@ static void SetNextFacilityOpponent(void) gTrainerBattleOpponent_A = id; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 7) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < FRONTIER_STAGES_PER_CHALLENGE) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; } } @@ -1107,7 +1108,7 @@ u16 GetRandomScaledFrontierTrainerId(u8 challengeNum, u8 battleNum) if (challengeNum <= 7) { - if (battleNum == 6) + if (battleNum == FRONTIER_STAGES_PER_CHALLENGE - 1) { // The last battle in each challenge has a jump in difficulty, pulls from a table with higher ranges trainerId = (sFrontierTrainerIdRangesHard[challengeNum][1] - sFrontierTrainerIdRangesHard[challengeNum][0]) + 1; @@ -1136,7 +1137,7 @@ static void GetRandomScaledFrontierTrainerIdRange(u8 challengeNum, u8 battleNum, if (challengeNum <= 7) { - if (battleNum == 6) + if (battleNum == FRONTIER_STAGES_PER_CHALLENGE - 1) { // The last battle in each challenge has a jump in difficulty, pulls from a table with higher ranges range = (sFrontierTrainerIdRangesHard[challengeNum][1] - sFrontierTrainerIdRangesHard[challengeNum][0]) + 1; @@ -1691,7 +1692,10 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) while (i != monCount) { u16 monId = monSet[Random() % bfMonCount]; - if ((level == 50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER) + + // "High tier" pokemon are only allowed on open level mode + // 20 is not a possible value for level here + if ((level == FRONTIER_MAX_LEVEL_50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER) continue; // Ensure this pokemon species isn't a duplicate. @@ -1767,9 +1771,9 @@ static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) fixedIV = 9; if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) - level = 100; + level = FRONTIER_MAX_LEVEL_OPEN; else - level = 50; + level = FRONTIER_MAX_LEVEL_50; for (i = 0; i != 3; i++) { @@ -1802,8 +1806,10 @@ u16 GetRandomFrontierMonFromSet(u16 trainerId) do { + // "High tier" pokemon are only allowed on open level mode + // 20 is not a possible value for level here monId = monSet[Random() % numMons]; - } while((level == 50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER); + } while((level == FRONTIER_MAX_LEVEL_50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER); return monId; } @@ -1831,11 +1837,11 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); // By mistake Battle Tower's Level 50 challenge number is used to determine the IVs for Battle Factory. #ifdef BUGFIX - u8 challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / 7; + u8 challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; #else - u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / 7; + u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / FRONTIER_STAGES_PER_CHALLENGE; #endif - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < FRONTIER_STAGES_PER_CHALLENGE - 1) fixedIV = GetFactoryMonFixedIV(challengeNum, FALSE); else fixedIV = GetFactoryMonFixedIV(challengeNum, TRUE); // Last trainer in challenge uses higher IVs @@ -1882,7 +1888,7 @@ static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId) { u8 i, j; u8 friendship; - u8 level = 30; + u8 level = TENT_MIN_LEVEL; u8 fixedIV = 0; u32 otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId); @@ -2043,7 +2049,7 @@ void DoSpecialTrainerBattle(void) break; case SPECIAL_BATTLE_EREADER: ZeroEnemyPartyMons(); - for (i = 0; i < 3; i++) + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.ereaderTrainer.party); i++) CreateBattleTowerMon(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i]); gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_EREADER_TRAINER; gTrainerBattleOpponent_A = 0; @@ -2189,7 +2195,7 @@ static void SaveTowerChallenge(void) { u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7); + s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE); if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) SaveBattleTowerRecord(); @@ -2279,7 +2285,7 @@ static void LoadMultiPartnerCandidatesData(void) objEventTemplates = gSaveBlock1Ptr->objectEventTemplates; lvlMode = gSaveBlock2Ptr->frontier.lvlMode; battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); level = SetFacilityPtrsGetLevel(); @@ -2338,7 +2344,7 @@ static void LoadMultiPartnerCandidatesData(void) for (i = 0; i < APPRENTICE_COUNT; i++) { if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0 - && sApprenticeChallengeThreshold[gSaveBlock2Ptr->apprentices[i].numQuestions] / 7 <= challengeNum + && sApprenticeChallengeThreshold[gSaveBlock2Ptr->apprentices[i].numQuestions] / FRONTIER_STAGES_PER_CHALLENGE <= challengeNum && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode) { k = 0; @@ -2377,7 +2383,7 @@ static void LoadMultiPartnerCandidatesData(void) checksum += record[j]; } - if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / 7 <= challengeNum + if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / FRONTIER_STAGES_PER_CHALLENGE <= challengeNum && gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode && recordHasData && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum) @@ -2458,7 +2464,7 @@ static void ShowPartnerCandidateMessage(void) s32 monId; s32 level = SetFacilityPtrsGetLevel(); u16 winStreak = GetCurrentFacilityWinStreak(); - s32 challengeNum = winStreak / 7; + s32 challengeNum = winStreak / FRONTIER_STAGES_PER_CHALLENGE; s32 k = gSpecialVar_LastTalked - 2; s32 trainerId = gSaveBlock2Ptr->frontier.trainerIds[k]; @@ -2517,7 +2523,7 @@ static void ShowPartnerCandidateMessage(void) gSaveBlock2Ptr->frontier.trainerIds[18] = gFrontierTempParty[0]; gSaveBlock2Ptr->frontier.trainerIds[19] = gFrontierTempParty[1]; } - for (k = 0; k < 14; k++) + for (k = 0; k < FRONTIER_STAGES_PER_CHALLENGE * 2; k++) { while (1) { @@ -2576,7 +2582,7 @@ static void LoadLinkMultiOpponentsData(void) case 0: if (battleMode == FRONTIER_MODE_LINK_MULTIS) { - challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; if (IsLinkTaskFinished()) { SendBlock(BitmaskAllOtherLinkPlayers(), &challengeNum, sizeof(challengeNum)); @@ -2596,7 +2602,7 @@ static void LoadLinkMultiOpponentsData(void) challengeNum = gBlockRecvBuffer[0][0]; else challengeNum = gBlockRecvBuffer[1][0]; - for (i = 0; i < 14; i++) + for (i = 0; i < FRONTIER_STAGES_PER_CHALLENGE * 2; i++) { do { @@ -2840,7 +2846,7 @@ static void FillEReaderTrainerWithPlayerData(void) ereaderTrainer->winStreak = 1; j = 7; - for (i = 0; i < 6; i++) + for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) { ereaderTrainer->greeting[i] = gSaveBlock1Ptr->easyChatBattleStart[i]; ereaderTrainer->farewellPlayerLost[i] = j; @@ -2848,7 +2854,7 @@ static void FillEReaderTrainerWithPlayerData(void) j++; } - for (i = 0; i < 3; i++) + for (i = 0; i < (int)ARRAY_COUNT(ereaderTrainer->party); i++) ConvertPokemonToBattleTowerPokemon(&gPlayerParty[i], &ereaderTrainer->party[i]); SetEReaderTrainerChecksum(ereaderTrainer); @@ -3246,12 +3252,12 @@ u8 GetFrontierEnemyMonLevel(u8 lvlMode) { default: case FRONTIER_LVL_50: - level = 50; + level = FRONTIER_MAX_LEVEL_50; break; case FRONTIER_LVL_OPEN: level = GetHighestLevelInPlayerParty(); - if (level < 60) - level = 60; + if (level < FRONTIER_MIN_LEVEL_OPEN) + level = FRONTIER_MIN_LEVEL_OPEN; break; } @@ -3321,7 +3327,7 @@ static u16 GetBattleTentTrainerId(void) static u8 SetTentPtrsGetLevel(void) { - u8 level = 30; + u8 level = TENT_MIN_LEVEL; u32 facility = VarGet(VAR_FRONTIER_FACILITY); if (facility == FRONTIER_FACILITY_FACTORY) @@ -3346,8 +3352,8 @@ static u8 SetTentPtrsGetLevel(void) } level = GetHighestLevelInPlayerParty(); - if (level < 30) - level = 30; + if (level < TENT_MIN_LEVEL) + level = TENT_MIN_LEVEL; return level; } @@ -3369,7 +3375,7 @@ static void SetNextBattleTentOpponent(void) gTrainerBattleOpponent_A = trainerId; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 3) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < TENT_STAGES_PER_CHALLENGE) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; } diff --git a/src/data/battle_frontier/battle_pyramid_open_level_wild_mons.h b/src/data/battle_frontier/battle_pyramid_open_level_wild_mons.h index 8738b0de6..f09448b82 100644 --- a/src/data/battle_frontier/battle_pyramid_open_level_wild_mons.h +++ b/src/data/battle_frontier/battle_pyramid_open_level_wild_mons.h @@ -1038,7 +1038,7 @@ static const struct PyramidWildMon sOpenLevelWildMons_Round20[] = } }; -static const struct PyramidWildMon *const sOpenLevelWildMonPointers[] = +static const struct PyramidWildMon *const sOpenLevelWildMonPointers[TOTAL_ROUNDS] = { sOpenLevelWildMons_Round1, sOpenLevelWildMons_Round2, diff --git a/src/frontier_util.c b/src/frontier_util.c index 03d7b0cb5..a08ccad4f 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -29,6 +29,7 @@ #include "load_save.h" #include "battle_dome.h" #include "constants/battle_frontier.h" +#include "constants/battle_pike.h" #include "constants/frontier_util.h" #include "constants/trainers.h" #include "constants/game_stat.h" @@ -968,7 +969,7 @@ static void PrintHyphens(s32 y) s32 i; u8 text[37]; - for (i = 0; i < 36; i++) + for (i = 0; i < (int)ARRAY_COUNT(text) - 1; i++) text[i] = CHAR_HYPHEN; text[i] = EOS; @@ -1860,25 +1861,25 @@ static void GiveBattlePoints(void) switch (facility) { case FRONTIER_FACILITY_TOWER: - challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; break; case FRONTIER_FACILITY_DOME: challengeNum = gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode]; break; case FRONTIER_FACILITY_PALACE: - challengeNum = gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; break; case FRONTIER_FACILITY_ARENA: - challengeNum = gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; break; case FRONTIER_FACILITY_FACTORY: - challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; break; case FRONTIER_FACILITY_PIKE: - challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / 14; + challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / NUM_PIKE_ROOMS; break; case FRONTIER_FACILITY_PYRAMID: - challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7; + challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; break; } @@ -1982,7 +1983,7 @@ static void AppendIfValid(u16 species, u16 heldItem, u16 hp, u8 lvlMode, u8 monL if (gFrontierBannedSpecies[i] != 0xFFFF) return; - if (lvlMode == FRONTIER_LVL_50 && monLevel > 50) + if (lvlMode == FRONTIER_LVL_50 && monLevel > FRONTIER_MAX_LEVEL_50) return; for (i = 0; i < *count && speciesArray[i] != species; i++) diff --git a/src/map_name_popup.c b/src/map_name_popup.c index 363f2bc06..9eaa035ca 100644 --- a/src/map_name_popup.c +++ b/src/map_name_popup.c @@ -12,6 +12,7 @@ #include "string_util.h" #include "task.h" #include "text.h" +#include "constants/battle_frontier.h" #include "constants/layouts.h" #include "constants/region_map_sections.h" #include "constants/weather.h" @@ -185,7 +186,7 @@ static const u8 sText_PyramidFloor6[] = _("PYRAMID FLOOR 6"); static const u8 sText_PyramidFloor7[] = _("PYRAMID FLOOR 7"); static const u8 sText_Pyramid[] = _("PYRAMID"); -static const u8 * const sBattlePyramid_MapHeaderStrings[] = +static const u8 * const sBattlePyramid_MapHeaderStrings[FRONTIER_STAGES_PER_CHALLENGE + 1] = { sText_PyramidFloor1, sText_PyramidFloor2, @@ -309,7 +310,7 @@ static void ShowMapNamePopUpWindow(void) if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_TOP) { withoutPrefixPtr = &(mapDisplayHeader[3]); - mapDisplayHeaderSource = sBattlePyramid_MapHeaderStrings[7]; + mapDisplayHeaderSource = sBattlePyramid_MapHeaderStrings[FRONTIER_STAGES_PER_CHALLENGE]; } else { diff --git a/src/mystery_gift_client.c b/src/mystery_gift_client.c index eeebec5d6..bd177e6f8 100644 --- a/src/mystery_gift_client.c +++ b/src/mystery_gift_client.c @@ -202,7 +202,7 @@ static u32 Client_Run(struct MysteryGiftClient * client) MysteryGiftLink_InitSend(&client->link, MG_LINKID_GAME_DATA, client->sendBuffer, sizeof(struct MysteryGiftLinkGameData)); break; case CLI_LOAD_TOSS_RESPONSE: - // param here is set by MG_STATE_LINK_ASK_TOSS or MG_STATE_LINK_ASK_TOSS_UNRECEIVED + // param here is set by MG_STATE_CLIENT_ASK_TOSS or MG_STATE_CLIENT_ASK_TOSS_UNRECEIVED MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, client->param); break; case CLI_SAVE_CARD: diff --git a/src/party_menu.c b/src/party_menu.c index cbe127bb9..016c359cb 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -5647,11 +5647,11 @@ static u8 GetBattleEntryLevelCap(void) case FACILITY_MULTI_OR_EREADER: return MAX_LEVEL; case FACILITY_UNION_ROOM: - return 30; + return UNION_ROOM_MAX_LEVEL; default: // Battle Frontier if (gSpecialVar_0x8004 == FRONTIER_LVL_50) - return 50; - return MAX_LEVEL; + return FRONTIER_MAX_LEVEL_50; + return FRONTIER_MAX_LEVEL_OPEN; } } diff --git a/src/pokemon.c b/src/pokemon.c index 7cdad72e9..b0bc41897 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2464,7 +2464,7 @@ void CreateBattleTowerMon_HandleLevel(struct Pokemon *mon, struct BattleTowerPok if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50) level = GetFrontierEnemyMonLevel(gSaveBlock2Ptr->frontier.lvlMode); else if (lvl50) - level = 50; + level = FRONTIER_MAX_LEVEL_50; else level = src->level; diff --git a/src/start_menu.c b/src/start_menu.c index 90230c3dd..11189ee83 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -42,9 +42,10 @@ #include "text_window.h" #include "trainer_card.h" #include "window.h" -#include "constants/songs.h" #include "union_room.h" +#include "constants/battle_frontier.h" #include "constants/rgb.h" +#include "constants/songs.h" // Menu actions enum @@ -138,7 +139,7 @@ static bool8 FieldCB_ReturnToFieldStartMenu(void); static const struct WindowTemplate sSafariBallsWindowTemplate = {0, 1, 1, 9, 4, 0xF, 8}; -static const u8* const sPyramidFloorNames[] = +static const u8* const sPyramidFloorNames[FRONTIER_STAGES_PER_CHALLENGE + 1] = { gText_Floor1, gText_Floor2, @@ -392,7 +393,7 @@ static void ShowSafariBallsWindow(void) static void ShowPyramidFloorWindow(void) { - if (gSaveBlock2Ptr->frontier.curChallengeBattleNum == 7) + if (gSaveBlock2Ptr->frontier.curChallengeBattleNum == FRONTIER_STAGES_PER_CHALLENGE) sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_1); else sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_2); diff --git a/src/union_room.c b/src/union_room.c index 9a743dbab..05b41a088 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -4318,7 +4318,7 @@ static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) for (i = 0; i < gPlayerPartyCount; i++) { - if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) <= 30 + if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) <= UNION_ROOM_MAX_LEVEL && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) count++; } From dec54e6e928217cdb6249fdad03d1b6492c7c7ff Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Jun 2022 15:32:08 -0400 Subject: [PATCH 2/4] Additional constant usage --- data/maps/BattleFrontier_Lounge2/scripts.inc | 26 ++++++++-------- src/battle_pike.c | 8 ++--- src/battle_tower.c | 32 ++++++++++---------- src/frontier_util.c | 26 ++++++++-------- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/data/maps/BattleFrontier_Lounge2/scripts.inc b/data/maps/BattleFrontier_Lounge2/scripts.inc index 8efc17293..12eda4a5e 100644 --- a/data/maps/BattleFrontier_Lounge2/scripts.inc +++ b/data/maps/BattleFrontier_Lounge2/scripts.inc @@ -22,18 +22,20 @@ BattleFrontier_Lounge2_EventScript_AlreadyMetManiac:: end BattleFrontier_Lounge2_EventScript_GiveAdvice:: - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 0, BattleFrontier_Lounge2_EventScript_BufferSingle - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 1, BattleFrontier_Lounge2_EventScript_BufferDouble - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 2, BattleFrontier_Lounge2_EventScript_BufferMulti - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 3, BattleFrontier_Lounge2_EventScript_BufferMultiLink - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 4, BattleFrontier_Lounge2_EventScript_BufferBattleDome - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 5, BattleFrontier_Lounge2_EventScript_BufferBattleFactory - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 6, BattleFrontier_Lounge2_EventScript_BufferBattlePalace - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 7, BattleFrontier_Lounge2_EventScript_BufferBattleArena - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 8, BattleFrontier_Lounge2_EventScript_BufferBattlePike - call_if_eq VAR_FRONTIER_MANIAC_FACILITY, 9, BattleFrontier_Lounge2_EventScript_BufferBattlePyramid - call_if_le VAR_FRONTIER_MANIAC_FACILITY, 3, BattleFrontier_Lounge2_EventScript_BattleTowerNews - call_if_ge VAR_FRONTIER_MANIAC_FACILITY, 4, BattleFrontier_Lounge2_EventScript_FacilityNews + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_TOWER_SINGLES, BattleFrontier_Lounge2_EventScript_BufferSingle + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_TOWER_DOUBLES, BattleFrontier_Lounge2_EventScript_BufferDouble + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_TOWER_MULTIS, BattleFrontier_Lounge2_EventScript_BufferMulti + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_TOWER_LINK, BattleFrontier_Lounge2_EventScript_BufferMultiLink + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_DOME, BattleFrontier_Lounge2_EventScript_BufferBattleDome + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_FACTORY, BattleFrontier_Lounge2_EventScript_BufferBattleFactory + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_PALACE, BattleFrontier_Lounge2_EventScript_BufferBattlePalace + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_ARENA, BattleFrontier_Lounge2_EventScript_BufferBattleArena + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_PIKE, BattleFrontier_Lounge2_EventScript_BufferBattlePike + call_if_eq VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_PYRAMID, BattleFrontier_Lounge2_EventScript_BufferBattlePyramid +@ <= FRONTIER_MANIAC_TOWER_LINK is any Battle Tower mode + call_if_le VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_TOWER_LINK, BattleFrontier_Lounge2_EventScript_BattleTowerNews +@ >= FRONTIER_MANIAC_DOME is any facility other than Battle Tower + call_if_ge VAR_FRONTIER_MANIAC_FACILITY, FRONTIER_MANIAC_DOME, BattleFrontier_Lounge2_EventScript_FacilityNews special ShowFrontierManiacMessage waitmessage waitbuttonpress diff --git a/src/battle_pike.c b/src/battle_pike.c index 6c97c99fc..433dd0a08 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -1158,11 +1158,11 @@ u8 GetBattlePikeWildMonHeaderId(void) u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u16 winStreak = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode]; - if (winStreak <= 280) + if (winStreak <= 20 * NUM_PIKE_ROOMS) headerId = 0; - else if (winStreak <= 560) + else if (winStreak <= 40 * NUM_PIKE_ROOMS) headerId = 1; - else if (winStreak <= 840) + else if (winStreak <= 60 * NUM_PIKE_ROOMS) headerId = 2; else headerId = 3; @@ -1392,7 +1392,7 @@ static void PrepareOneTrainer(bool8 difficult) if (!difficult) battleNum = 1; else - battleNum = 6; + battleNum = FRONTIER_STAGES_PER_CHALLENGE - 1; lvlMode = gSaveBlock2Ptr->frontier.lvlMode; challengeNum = gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] / NUM_PIKE_ROOMS; diff --git a/src/battle_tower.c b/src/battle_tower.c index 839b99b24..354a087c4 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1327,19 +1327,19 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm) if (gSaveBlock2Ptr->frontier.towerRecords[i].trainerId[j] != newRecord->trainerId[j]) break; } - if (j == 4) + if (j == TRAINER_ID_LENGTH) { for (k = 0; k < PLAYER_NAME_LENGTH; k++) { - #ifdef BUGFIX - if (gSaveBlock2Ptr->frontier.towerRecords[i].name[k] != newRecord->name[k]) + // Incorrect index being used + #ifdef BUGFIX + #define INDEX k + #else + #define INDEX j + #endif + if (gSaveBlock2Ptr->frontier.towerRecords[i].name[INDEX] != newRecord->name[INDEX]) break; - if (newRecord->name[k] == EOS) - #else - if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecord->name[j]) - break; - if (newRecord->name[j] == EOS) - #endif + if (newRecord->name[INDEX] == EOS) { k = PLAYER_NAME_LENGTH; break; @@ -1635,7 +1635,7 @@ static void FillTentTrainerParty(u8 monsCount) static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) { s32 i, j; - u16 chosenMonIndices[4]; + u16 chosenMonIndices[MAX_FRONTIER_PARTY_SIZE]; u8 friendship = MAX_FRIENDSHIP; u8 level = SetFacilityPtrsGetLevel(); u8 fixedIV = 0; @@ -1651,7 +1651,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) } else if (trainerId == TRAINER_EREADER) { - for (i = firstMonId; i < firstMonId + 3; i++) + for (i = firstMonId; i < firstMonId + FRONTIER_PARTY_SIZE; i++) CreateBattleTowerMon(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); return; } @@ -1676,7 +1676,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) else { // Apprentice. - for (i = firstMonId; i < firstMonId + 3; i++) + for (i = firstMonId; i < firstMonId + FRONTIER_PARTY_SIZE; i++) CreateApprenticeMon(&gEnemyParty[i], &gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE], i - firstMonId); return; } @@ -1775,7 +1775,7 @@ static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) else level = FRONTIER_MAX_LEVEL_50; - for (i = 0; i != 3; i++) + for (i = 0; i != FRONTIER_PARTY_SIZE; i++) { CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->party[i].species, level, fixedIV, 8); friendship = MAX_FRIENDSHIP; @@ -1848,7 +1848,7 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) } else if (trainerId == TRAINER_EREADER) { - for (i = firstMonId; i < firstMonId + 3; i++) + for (i = firstMonId; i < firstMonId + FRONTIER_PARTY_SIZE; i++) CreateBattleTowerMon(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]); return; } @@ -2743,8 +2743,8 @@ u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode) { u16 winStreak = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]; - if (winStreak > 9999) - return 9999; + if (winStreak > MAX_STREAK) + return MAX_STREAK; else return winStreak; } diff --git a/src/frontier_util.c b/src/frontier_util.c index a08ccad4f..545f48ac0 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -595,13 +595,13 @@ static const u8 sBattlePointAwards[][NUM_FRONTIER_FACILITIES][FRONTIER_MODE_COUN // First bit is has battled them before and not won yet, second bit is has battled them and won (obtained a Symbol) static const u16 sBattledBrainBitFlags[NUM_FRONTIER_FACILITIES][2] = { - [FRONTIER_FACILITY_TOWER] = {0x0001, 0x0002}, - [FRONTIER_FACILITY_DOME] = {0x0004, 0x0008}, - [FRONTIER_FACILITY_PALACE] = {0x0010, 0x0020}, - [FRONTIER_FACILITY_ARENA] = {0x0040, 0x0080}, - [FRONTIER_FACILITY_FACTORY] = {0x0100, 0x0200}, - [FRONTIER_FACILITY_PIKE] = {0x0400, 0x0800}, - [FRONTIER_FACILITY_PYRAMID] = {0x1000, 0x2000}, + [FRONTIER_FACILITY_TOWER] = {1 << 0, 1 << 1}, + [FRONTIER_FACILITY_DOME] = {1 << 2, 1 << 3}, + [FRONTIER_FACILITY_PALACE] = {1 << 4, 1 << 5}, + [FRONTIER_FACILITY_ARENA] = {1 << 6, 1 << 7}, + [FRONTIER_FACILITY_FACTORY] = {1 << 8, 1 << 9}, + [FRONTIER_FACILITY_PIKE] = {1 << 10, 1 << 11}, + [FRONTIER_FACILITY_PYRAMID] = {1 << 12, 1 << 13}, }; static void (* const sFrontierUtilFuncs[])(void) = @@ -636,8 +636,8 @@ static const struct WindowTemplate sFrontierResultsWindowTemplate = .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, - .width = 0x1c, - .height = 0x12, + .width = 28, + .height = 18, .paletteNum = 15, .baseBlock = 1 }; @@ -647,7 +647,7 @@ static const struct WindowTemplate sLinkContestResultsWindowTemplate = .bg = 0, .tilemapLeft = 2, .tilemapTop = 2, - .width = 0x1a, + .width = 26, .height = 15, .paletteNum = 15, .baseBlock = 1 @@ -658,7 +658,7 @@ static const struct WindowTemplate sRankingHallRecordsWindowTemplate = .bg = 0, .tilemapLeft = 2, .tilemapTop = 1, - .width = 0x1a, + .width = 26, .height = 17, .paletteNum = 15, .baseBlock = 1 @@ -959,7 +959,7 @@ static bool8 IsWinStreakActive(u32 challenge) static void PrintAligned(const u8 *str, s32 y) { - s32 x = GetStringCenterAlignXOffset(FONT_NORMAL, str, 224); + s32 x = GetStringCenterAlignXOffset(FONT_NORMAL, str, DISPLAY_WIDTH - 16); y = (y * 8) + 1; AddTextPrinterParameterized(gRecordsWindowId, FONT_NORMAL, str, x, y, TEXT_SKIP_DRAW, NULL); } @@ -2345,7 +2345,7 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode) StringCopy(gStringVar1, sRecordsWindowChallengeTexts[hallFacilityId][0]); StringExpandPlaceholders(gStringVar4, sRecordsWindowChallengeTexts[hallFacilityId][1]); AddTextPrinterParameterized(gRecordsWindowId, FONT_NORMAL, gStringVar4, 0, 1, TEXT_SKIP_DRAW, NULL); - x = GetStringRightAlignXOffset(FONT_NORMAL, sLevelModeText[lvlMode], 0xD0); + x = GetStringRightAlignXOffset(FONT_NORMAL, sLevelModeText[lvlMode], DISPLAY_WIDTH - 32); AddTextPrinterParameterized(gRecordsWindowId, FONT_NORMAL, sLevelModeText[lvlMode], x, 1, TEXT_SKIP_DRAW, NULL); if (hallFacilityId == RANKING_HALL_TOWER_LINK) { From 95f075ec905da35ff1bc97f70a92c13a5a218c9a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 13 Jun 2022 15:01:04 -0400 Subject: [PATCH 3/4] Remove erroneous bugfix --- src/match_call.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/match_call.c b/src/match_call.c index de7f13416..8b25d5b44 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -33,6 +33,13 @@ #include "constants/songs.h" #include "constants/trainers.h" +// In this file only the values normally associated with Battle Pike and Factory are swapped. +// Note that this is *not* a bug, because they are properly swapped consistently in this file. +// There would only be an issue if anything in this file interacted with something expecting +// the usual value order, or vice versa. +#define MATCH_CALL_FACTORY FRONTIER_FACILITY_PIKE +#define MATCH_CALL_PIKE FRONTIER_FACILITY_FACTORY + // Each match call message has variables that can be populated randomly or // dependent on the trainer. The below are IDs for how to populate the vars // in a given message. @@ -1590,6 +1597,7 @@ static const struct MatchCallText *GetGeneralMatchCallText(int matchCallId, u8 * rand = Random(); if (!(rand & 1)) { + // Count the number of facilities with a win streak for (count = 0, i = 0; i < NUM_FRONTIER_FACILITIES; i++) { if (GetFrontierStreakInfo(i, &topic) > 1) @@ -1598,6 +1606,8 @@ static const struct MatchCallText *GetGeneralMatchCallText(int matchCallId, u8 * if (count) { + // At least one facility with a win streak + // Randomly choose one to have a call about count = Random() % count; for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) { @@ -1807,15 +1817,15 @@ static void PopulateSpeciesFromTrainerParty(int matchCallId, u8 *destStr) StringCopy(destStr, speciesName); } -static const u8 *const sBattleFrontierFacilityNames[] = +static const u8 *const sBattleFrontierFacilityNames[NUM_FRONTIER_FACILITIES] = { - gText_BattleTower2, - gText_BattleDome, - gText_BattlePalace, - gText_BattleArena, - gText_BattlePike, - gText_BattleFactory, - gText_BattlePyramid, + [FRONTIER_FACILITY_TOWER] = gText_BattleTower2, + [FRONTIER_FACILITY_DOME] = gText_BattleDome, + [FRONTIER_FACILITY_PALACE] = gText_BattlePalace, + [FRONTIER_FACILITY_ARENA] = gText_BattleArena, + [MATCH_CALL_PIKE] = gText_BattlePike, + [MATCH_CALL_FACTORY] = gText_BattleFactory, + [FRONTIER_FACILITY_PYRAMID] = gText_BattlePyramid, }; static void PopulateBattleFrontierFacilityName(int matchCallId, u8 *destStr) @@ -1899,7 +1909,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) switch (facilityId) { case FRONTIER_FACILITY_DOME: - for (i = 0; i < 2; i++) + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.domeRecordWinStreaks); i++) { for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { @@ -1909,11 +1919,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) } *topicTextId = GEN_TOPIC_B_DOME - 1; break; - #ifdef BUGFIX - case FRONTIER_FACILITY_PIKE: - #else - case FRONTIER_FACILITY_FACTORY: - #endif + case MATCH_CALL_PIKE: for (i = 0; i < FRONTIER_LVL_MODE_COUNT; i++) { if (streak < gSaveBlock2Ptr->frontier.pikeRecordStreaks[i]) @@ -1922,7 +1928,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) *topicTextId = GEN_TOPIC_B_PIKE - 1; break; case FRONTIER_FACILITY_TOWER: - for (i = 0; i < 4; i++) + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.towerRecordWinStreaks); i++) { for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { @@ -1933,7 +1939,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) *topicTextId = GEN_TOPIC_STREAK_RECORD - 1; break; case FRONTIER_FACILITY_PALACE: - for (i = 0; i < 2; i++) + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.palaceRecordWinStreaks); i++) { for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { @@ -1943,12 +1949,8 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) } *topicTextId = GEN_TOPIC_STREAK_RECORD - 1; break; - #ifdef BUGFIX - case FRONTIER_FACILITY_FACTORY: - #else - case FRONTIER_FACILITY_PIKE: - #endif - for (i = 0; i < 2; i++) + case MATCH_CALL_FACTORY: + for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.factoryRecordWinStreaks); i++) { for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { From 4660f8c88baeccf3ab0baba03e8f0b7430ed73df Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 14 Jun 2022 09:18:55 -0400 Subject: [PATCH 4/4] Document battle tower TV show --- data/text/tv.inc | 30 +++++------ include/constants/tv.h | 17 ++++++ include/event_scripts.h | 30 +++++------ src/easy_chat.c | 2 +- src/frontier_util.c | 60 +++++++++++----------- src/tv.c | 111 ++++++++++++++++++++-------------------- 6 files changed, 134 insertions(+), 116 deletions(-) diff --git a/data/text/tv.inc b/data/text/tv.inc index 68b842158..6cfc289d2 100644 --- a/data/text/tv.inc +++ b/data/text/tv.inc @@ -166,7 +166,7 @@ BattleFrontier_BattleTowerLobby_Text_LookingForwardToNextBattle:: .string "I'll be looking forward to your\n" .string "next battle!$" -gTVBravoTrainerBattleTowerText00:: +BravoTrainerBattleTower_Text_Intro:: .string "Yeah!\n" .string "It's BRAVO TRAINER time!\p" .string "Today, we're going to profile {STR_VAR_1},\n" @@ -174,12 +174,12 @@ gTVBravoTrainerBattleTowerText00:: .string "For the challenge, {STR_VAR_1} entered\n" .string "one wicked {STR_VAR_2}.$" -gTVBravoTrainerBattleTowerText01:: +BravoTrainerBattleTower_Text_NewRecord:: .string "The pair set a new record of {STR_VAR_2} wins\n" .string "in a row in {STR_VAR_1} competition!\l" .string "Bravo, TRAINER!$" -gTVBravoTrainerBattleTowerText02:: +BravoTrainerBattleTower_Text_Lost:: .string "The twosome finally succumbed to\n" .string "{STR_VAR_1} in match number {STR_VAR_2}.\l" .string "Nice try, TRAINER!\p" @@ -188,7 +188,7 @@ gTVBravoTrainerBattleTowerText02:: .string "We asked the TRAINER for impressions\n" .string "on the match with {STR_VAR_1}.$" -gTVBravoTrainerBattleTowerText03:: +BravoTrainerBattleTower_Text_Won:: .string "The twosome won it all by defeating\n" .string "{STR_VAR_1}'s {STR_VAR_2} thoroughly.\l" .string "Bravo, TRAINER!\p" @@ -197,7 +197,7 @@ gTVBravoTrainerBattleTowerText03:: .string "We asked the TRAINER for impressions\n" .string "on the moment of glory.$" -gTVBravoTrainerBattleTowerText04:: +BravoTrainerBattleTower_Text_LostFinal:: .string "After a string of wins, the pair finally\n" .string "succumbed to {STR_VAR_1}'s {STR_VAR_2},\l" .string "their final hurdle.\p" @@ -208,7 +208,7 @@ gTVBravoTrainerBattleTowerText04:: .string "We asked the TRAINER for impressions\n" .string "on battling the celebrity pair.$" -gTVBravoTrainerBattleTowerText05:: +BravoTrainerBattleTower_Text_Satisfied:: .string "This is what the TRAINER had to say:\n" .string "“I'm satisfied!”\p" .string "Now isn't that a refreshing reply?\n" @@ -218,7 +218,7 @@ gTVBravoTrainerBattleTowerText05:: .string "I found out exactly how satisfied\n" .string "when I heard the TRAINER say this:$" -gTVBravoTrainerBattleTowerText06:: +BravoTrainerBattleTower_Text_Unsatisfied:: .string "This is what the TRAINER had to say:\n" .string "“I'm not satisfied…”\p" .string "Our TRAINER was obviously a little down\n" @@ -228,22 +228,22 @@ gTVBravoTrainerBattleTowerText06:: .string "Anyway, I found out how dissatisfied\n" .string "our TRAINER was when I heard this:$" -gTVBravoTrainerBattleTowerText07:: +BravoTrainerBattleTower_Text_None1:: .string "None$" -gTVBravoTrainerBattleTowerText08:: +BravoTrainerBattleTower_Text_None2:: .string "None$" -gTVBravoTrainerBattleTowerText09:: +BravoTrainerBattleTower_Text_None3:: .string "None$" -gTVBravoTrainerBattleTowerText10:: +BravoTrainerBattleTower_Text_None4:: .string "None$" -gTVBravoTrainerBattleTowerText11:: +BravoTrainerBattleTower_Text_Response:: .string "“{STR_VAR_1}.”$" -gTVBravoTrainerBattleTowerText12:: +BravoTrainerBattleTower_Text_ResponseSatisfied:: .string "“{STR_VAR_1}.”\n" .string "Now isn't that great?\p" .string "It really expresses {STR_VAR_2}'s joy,\n" @@ -252,7 +252,7 @@ gTVBravoTrainerBattleTowerText12:: .string "end… It really was what you'd call\l" .string "“{STR_VAR_1}”!$" -gTVBravoTrainerBattleTowerText13:: +BravoTrainerBattleTower_Text_ResponseUnsatisfied:: .string "“{STR_VAR_1}.”\n" .string "Now isn't that fitting?\p" .string "That battle with {STR_VAR_3} at the\n" @@ -261,7 +261,7 @@ gTVBravoTrainerBattleTowerText13:: .string "{STR_VAR_2}'s disappointment comes across\n" .string "loud and clear, I'd say!$" -gTVBravoTrainerBattleTowerText14:: +BravoTrainerBattleTower_Text_Outro:: .string "Bravo, {STR_VAR_1}!\n" .string "Bravo, {STR_VAR_2}!\p" .string "I hope we can count on seeing\n" diff --git a/include/constants/tv.h b/include/constants/tv.h index 4c8dd4fa8..87748a31d 100644 --- a/include/constants/tv.h +++ b/include/constants/tv.h @@ -274,4 +274,21 @@ #define SMARTSHOPPER_NUM_ITEMS 3 +// TV Show states for Bravo Trainer's Battle Tower interview +#define BRAVOTOWER_STATE_INTRO 0 +#define BRAVOTOWER_STATE_NEW_RECORD 1 +#define BRAVOTOWER_STATE_LOST 2 +#define BRAVOTOWER_STATE_WON 3 +#define BRAVOTOWER_STATE_LOST_FINAL 4 +#define BRAVOTOWER_STATE_SATISFIED 5 +#define BRAVOTOWER_STATE_UNSATISFIED 6 +#define BRAVOTOWER_STATE_UNUSED_1 7 +#define BRAVOTOWER_STATE_UNUSED_2 8 +#define BRAVOTOWER_STATE_UNUSED_3 9 +#define BRAVOTOWER_STATE_UNUSED_4 10 +#define BRAVOTOWER_STATE_RESPONSE 11 +#define BRAVOTOWER_STATE_RESPONSE_SATISFIED 12 +#define BRAVOTOWER_STATE_RESPONSE_UNSATISFIED 13 +#define BRAVOTOWER_STATE_OUTRO 14 + #endif //GUARD_CONSTANTS_TV_H diff --git a/include/event_scripts.h b/include/event_scripts.h index a19d4553a..4e0a88f82 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -21,21 +21,21 @@ extern const u8 gTVBravoTrainerText05[]; extern const u8 gTVBravoTrainerText06[]; extern const u8 gTVBravoTrainerText07[]; extern const u8 gTVBravoTrainerText08[]; -extern const u8 gTVBravoTrainerBattleTowerText00[]; -extern const u8 gTVBravoTrainerBattleTowerText01[]; -extern const u8 gTVBravoTrainerBattleTowerText02[]; -extern const u8 gTVBravoTrainerBattleTowerText03[]; -extern const u8 gTVBravoTrainerBattleTowerText04[]; -extern const u8 gTVBravoTrainerBattleTowerText05[]; -extern const u8 gTVBravoTrainerBattleTowerText06[]; -extern const u8 gTVBravoTrainerBattleTowerText07[]; -extern const u8 gTVBravoTrainerBattleTowerText08[]; -extern const u8 gTVBravoTrainerBattleTowerText09[]; -extern const u8 gTVBravoTrainerBattleTowerText10[]; -extern const u8 gTVBravoTrainerBattleTowerText11[]; -extern const u8 gTVBravoTrainerBattleTowerText12[]; -extern const u8 gTVBravoTrainerBattleTowerText13[]; -extern const u8 gTVBravoTrainerBattleTowerText14[]; +extern const u8 BravoTrainerBattleTower_Text_Intro[]; +extern const u8 BravoTrainerBattleTower_Text_NewRecord[]; +extern const u8 BravoTrainerBattleTower_Text_Lost[]; +extern const u8 BravoTrainerBattleTower_Text_Won[]; +extern const u8 BravoTrainerBattleTower_Text_LostFinal[]; +extern const u8 BravoTrainerBattleTower_Text_Satisfied[]; +extern const u8 BravoTrainerBattleTower_Text_Unsatisfied[]; +extern const u8 BravoTrainerBattleTower_Text_None1[]; +extern const u8 BravoTrainerBattleTower_Text_None2[]; +extern const u8 BravoTrainerBattleTower_Text_None3[]; +extern const u8 BravoTrainerBattleTower_Text_None4[]; +extern const u8 BravoTrainerBattleTower_Text_Response[]; +extern const u8 BravoTrainerBattleTower_Text_ResponseSatisfied[]; +extern const u8 BravoTrainerBattleTower_Text_ResponseUnsatisfied[]; +extern const u8 BravoTrainerBattleTower_Text_Outro[]; extern const u8 gTVFanClubOpinionsText00[]; extern const u8 gTVFanClubOpinionsText01[]; extern const u8 gTVFanClubOpinionsText02[]; diff --git a/src/easy_chat.c b/src/easy_chat.c index 4d6006f1c..2bbd16cb2 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1492,7 +1492,7 @@ void ShowEasyChatScreen(void) displayedPersonType = EASY_CHAT_PERSON_REPORTER_MALE; break; case EASY_CHAT_TYPE_BATTLE_TOWER_INTERVIEW: - words = gSaveBlock1Ptr->tvShows[gSpecialVar_0x8005].fanclubOpinions.words18; + words = gSaveBlock1Ptr->tvShows[gSpecialVar_0x8005].bravoTrainerTower.words; displayedPersonType = EASY_CHAT_PERSON_REPORTER_FEMALE; break; case EASY_CHAT_TYPE_GOOD_SAYING: diff --git a/src/frontier_util.c b/src/frontier_util.c index 545f48ac0..f5dde452f 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -500,94 +500,94 @@ static const struct FrontierBrainMon sFrontierBrainsMons[][2][FRONTIER_PARTY_SIZ static const u8 sBattlePointAwards[][NUM_FRONTIER_FACILITIES][FRONTIER_MODE_COUNT] = { { - {1, 2, 3, 3}, {1, 1, 0, 0}, {4, 5, 0, 0}, {1, 0, 0, 0}, {3, 4, 0, 0}, {1, 0, 0, 0}, {5, 0, 0, 0} + {1, 2, 3, 3}, {1, 1}, {4, 5}, {1}, {3, 4}, {1}, {5} }, { - {2, 3, 4, 4}, {1, 1, 0, 0}, {4, 5, 0, 0}, {1, 0, 0, 0}, {3, 4, 0, 0}, {1, 0, 0, 0}, {5, 0, 0, 0} + {2, 3, 4, 4}, {1, 1}, {4, 5}, {1}, {3, 4}, {1}, {5} }, { - {3, 4, 5, 5}, {2, 2, 0, 0}, {5, 6, 0, 0}, {1, 0, 0, 0}, {4, 5, 0, 0}, {2, 0, 0, 0}, {6, 0, 0, 0} + {3, 4, 5, 5}, {2, 2}, {5, 6}, {1}, {4, 5}, {2}, {6} }, { - {4, 5, 6, 6}, {2, 2, 0, 0}, {5, 6, 0, 0}, {2, 0, 0, 0}, {4, 5, 0, 0}, {2, 0, 0, 0}, {6, 0, 0, 0} + {4, 5, 6, 6}, {2, 2}, {5, 6}, {2}, {4, 5}, {2}, {6} }, { - {5, 6, 7, 7}, {3, 3, 0, 0}, {6, 7, 0, 0}, {2, 0, 0, 0}, {5, 6, 0, 0}, {2, 0, 0, 0}, {7, 0, 0, 0} + {5, 6, 7, 7}, {3, 3}, {6, 7}, {2}, {5, 6}, {2}, {7} }, { - {6, 7, 8, 8}, {3, 3, 0, 0}, {6, 7, 0, 0}, {2, 0, 0, 0}, {5, 6, 0, 0}, {4, 0, 0, 0}, {7, 0, 0, 0} + {6, 7, 8, 8}, {3, 3}, {6, 7}, {2}, {5, 6}, {4}, {7} }, { - {7, 8, 9, 9}, {4, 4, 0, 0}, {7, 8, 0, 0}, {3, 0, 0, 0}, {6, 7, 0, 0}, {4, 0, 0, 0}, {8, 0, 0, 0} + {7, 8, 9, 9}, {4, 4}, {7, 8}, {3}, {6, 7}, {4}, {8} }, { - {8, 9, 10, 10}, {4, 4, 0, 0}, {7, 8, 0, 0}, {3, 0, 0, 0},{6, 7, 0, 0}, {4, 0, 0, 0}, {8, 0, 0, 0} + {8, 9, 10, 10}, {4, 4}, {7, 8}, {3},{6, 7}, {4}, {8} }, { - {9, 10, 11, 11}, {5, 5, 0, 0}, {8, 9, 0, 0}, {4, 0, 0, 0}, {7, 8, 0, 0}, {8, 0, 0, 0}, {9, 0, 0, 0} + {9, 10, 11, 11}, {5, 5}, {8, 9}, {4}, {7, 8}, {8}, {9} }, { - {10, 11, 12, 12}, {5, 5, 0, 0}, {8, 9, 0, 0}, {4, 0, 0, 0}, {7, 8, 0, 0}, {8, 0, 0, 0}, {9, 0, 0, 0} + {10, 11, 12, 12}, {5, 5}, {8, 9}, {4}, {7, 8}, {8}, {9} }, { - {11, 12, 13, 13}, {6, 6, 0, 0}, {9, 10, 0, 0}, {5, 0, 0,0}, {8, 9, 0, 0}, {8, 0, 0, 0}, {10, 0, 0, 0} + {11, 12, 13, 13}, {6, 6}, {9, 10}, {5,0}, {8, 9}, {8}, {10} }, { - {12, 13, 14, 14}, {6, 6, 0, 0}, {9, 10, 0, 0}, {6, 0, 0,0}, {8, 9, 0, 0}, {8, 0, 0, 0}, {10, 0, 0, 0} + {12, 13, 14, 14}, {6, 6}, {9, 10}, {6,0}, {8, 9}, {8}, {10} }, { - {13, 14, 15, 15}, {7, 7, 0, 0}, {10, 11, 0, 0}, {7, 0, 0, 0}, {9, 10, 0, 0}, {10, 0, 0, 0}, {11, 0, 0, 0} + {13, 14, 15, 15}, {7, 7}, {10, 11}, {7}, {9, 10}, {10}, {11} }, { - {14, 15, 15, 15}, {7, 7, 0, 0}, {10, 11, 0, 0}, {8, 0, 0, 0}, {9, 10, 0, 0}, {10, 0, 0, 0}, {11, 0, 0, 0} + {14, 15, 15, 15}, {7, 7}, {10, 11}, {8}, {9, 10}, {10}, {11} }, { - {15, 15, 15, 15}, {8, 8, 0, 0}, {11, 12, 0, 0}, {9, 0, 0, 0}, {10, 11, 0, 0}, {10, 0, 0, 0}, {12, 0, 0, 0} + {15, 15, 15, 15}, {8, 8}, {11, 12}, {9}, {10, 11}, {10}, {12} }, { - {15, 15, 15, 15}, {8, 8, 0, 0}, {11, 12, 0, 0}, {10, 0, 0, 0}, {10, 11, 0, 0}, {10, 0, 0, 0}, {12, 0, 0, 0} + {15, 15, 15, 15}, {8, 8}, {11, 12}, {10}, {10, 11}, {10}, {12} }, { - {15, 15, 15, 15}, {9, 9, 0, 0}, {12, 13, 0, 0}, {11, 0, 0, 0}, {11, 12, 0, 0}, {12, 0, 0, 0}, {13, 0, 0, 0} + {15, 15, 15, 15}, {9, 9}, {12, 13}, {11}, {11, 12}, {12}, {13} }, { - {15, 15, 15, 15}, {9, 9, 0, 0}, {12, 13, 0, 0}, {12, 0, 0, 0}, {11, 12, 0, 0}, {12, 0, 0, 0}, {13, 0, 0, 0} + {15, 15, 15, 15}, {9, 9}, {12, 13}, {12}, {11, 12}, {12}, {13} }, { - {15, 15, 15, 15}, {10, 10, 0, 0}, {13, 14, 0, 0}, {13, 0, 0, 0}, {12, 13, 0, 0}, {12, 0, 0, 0}, {14, 0, 0, 0} + {15, 15, 15, 15}, {10, 10}, {13, 14}, {13}, {12, 13}, {12}, {14} }, { - {15, 15, 15, 15}, {10, 10, 0, 0}, {13, 14, 0, 0}, {14, 0, 0, 0}, {12, 13, 0, 0}, {12, 0, 0, 0}, {14, 0, 0, 0} + {15, 15, 15, 15}, {10, 10}, {13, 14}, {14}, {12, 13}, {12}, {14} }, { - {15, 15, 15, 15}, {11, 11, 0, 0}, {14, 15, 0, 0}, {15, 0, 0, 0}, {13, 14, 0, 0}, {12, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {11, 11}, {14, 15}, {15}, {13, 14}, {12}, {15} }, { - {15, 15, 15, 15}, {11, 11, 0, 0}, {14, 15, 0, 0}, {15, 0, 0, 0}, {13, 14, 0, 0}, {14, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {11, 11}, {14, 15}, {15}, {13, 14}, {14}, {15} }, { - {15, 15, 15, 15}, {12, 12, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {14, 15, 0, 0}, {14, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {12, 12}, {15, 15}, {15}, {14, 15}, {14}, {15} }, { - {15, 15, 15, 15}, {12, 12, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {14, 15, 0, 0}, {14, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {12, 12}, {15, 15}, {15}, {14, 15}, {14}, {15} }, { - {15, 15, 15, 15}, {13, 13, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {14, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {13, 13}, {15, 15}, {15}, {15, 15}, {14}, {15} }, { - {15, 15, 15, 15}, {13, 13, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {13, 13}, {15, 15}, {15}, {15, 15}, {15}, {15} }, { - {15, 15, 15, 15}, {14, 14, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {14, 14}, {15, 15}, {15}, {15, 15}, {15}, {15} }, { - {15, 15, 15, 15}, {14, 14, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {14, 14}, {15, 15}, {15}, {15, 15}, {15}, {15} }, { - {15, 15, 15, 15}, {15, 15, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {15, 15}, {15, 15}, {15}, {15, 15}, {15}, {15} }, { - {15, 15, 15, 15}, {15, 15, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 15, 0, 0}, {15, 0, 0, 0}, {15, 0, 0, 0} + {15, 15, 15, 15}, {15, 15}, {15, 15}, {15}, {15, 15}, {15}, {15} }, }; diff --git a/src/tv.c b/src/tv.c index 5cca91ff7..ec36a3ff0 100644 --- a/src/tv.c +++ b/src/tv.c @@ -373,21 +373,21 @@ static const u8 *const sTV3CheersForPokeblocksTextGroup[] = { }; static const u8 *const sTVBravoTrainerBattleTowerTextGroup[] = { - gTVBravoTrainerBattleTowerText00, - gTVBravoTrainerBattleTowerText01, - gTVBravoTrainerBattleTowerText02, - gTVBravoTrainerBattleTowerText03, - gTVBravoTrainerBattleTowerText04, - gTVBravoTrainerBattleTowerText05, - gTVBravoTrainerBattleTowerText06, - gTVBravoTrainerBattleTowerText07, - gTVBravoTrainerBattleTowerText08, - gTVBravoTrainerBattleTowerText09, - gTVBravoTrainerBattleTowerText10, - gTVBravoTrainerBattleTowerText11, - gTVBravoTrainerBattleTowerText12, - gTVBravoTrainerBattleTowerText13, - gTVBravoTrainerBattleTowerText14 + [BRAVOTOWER_STATE_INTRO] = BravoTrainerBattleTower_Text_Intro, + [BRAVOTOWER_STATE_NEW_RECORD] = BravoTrainerBattleTower_Text_NewRecord, + [BRAVOTOWER_STATE_LOST] = BravoTrainerBattleTower_Text_Lost, + [BRAVOTOWER_STATE_WON] = BravoTrainerBattleTower_Text_Won, + [BRAVOTOWER_STATE_LOST_FINAL] = BravoTrainerBattleTower_Text_LostFinal, + [BRAVOTOWER_STATE_SATISFIED] = BravoTrainerBattleTower_Text_Satisfied, + [BRAVOTOWER_STATE_UNSATISFIED] = BravoTrainerBattleTower_Text_Unsatisfied, + [BRAVOTOWER_STATE_UNUSED_1] = BravoTrainerBattleTower_Text_None1, + [BRAVOTOWER_STATE_UNUSED_2] = BravoTrainerBattleTower_Text_None2, + [BRAVOTOWER_STATE_UNUSED_3] = BravoTrainerBattleTower_Text_None3, + [BRAVOTOWER_STATE_UNUSED_4] = BravoTrainerBattleTower_Text_None4, + [BRAVOTOWER_STATE_RESPONSE] = BravoTrainerBattleTower_Text_Response, + [BRAVOTOWER_STATE_RESPONSE_SATISFIED] = BravoTrainerBattleTower_Text_ResponseSatisfied, + [BRAVOTOWER_STATE_RESPONSE_UNSATISFIED] = BravoTrainerBattleTower_Text_ResponseUnsatisfied, + [BRAVOTOWER_STATE_OUTRO] = BravoTrainerBattleTower_Text_Outro }; static const u8 *const sTVContestLiveUpdatesTextGroup[] = { @@ -1490,9 +1490,9 @@ static void InterviewAfter_BravoTrainerBattleTowerProfile(void) show->bravoTrainerTower.numFights = GetCurrentBattleTowerWinStreak(gSaveBlock2Ptr->frontier.towerLvlMode, 0); show->bravoTrainerTower.wonTheChallenge = gSaveBlock2Ptr->frontier.towerBattleOutcome; if (gSaveBlock2Ptr->frontier.towerLvlMode == FRONTIER_LVL_50) - show->bravoTrainerTower.btLevel = 50; + show->bravoTrainerTower.btLevel = FRONTIER_MAX_LEVEL_50; else - show->bravoTrainerTower.btLevel = 100; + show->bravoTrainerTower.btLevel = FRONTIER_MAX_LEVEL_OPEN; show->bravoTrainerTower.interviewResponse = gSpecialVar_0x8004; StorePlayerIdInNormalShow(show); show->bravoTrainerTower.language = gGameLanguage; @@ -4371,6 +4371,9 @@ static void DoTVShowBravoTrainerPokemonProfile(void) ShowFieldMessage(sTVBravoTrainerTextGroup[state]); } +// This is the TV show triggered by accepting the reporter's interview in the lobby of Battle Tower. +// The reporter had asked the player if they were satisfied or not with the challenge, and then asked +// for a one word Easy Chat description of their feelings about the challenge. static void DoTVShowBravoTrainerBattleTower(void) { TVShow *show; @@ -4381,85 +4384,83 @@ static void DoTVShowBravoTrainerBattleTower(void) state = sTVShowState; switch(state) { - case 0: + case BRAVOTOWER_STATE_INTRO: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); - if (show->bravoTrainerTower.numFights >= 7) - sTVShowState = 1; + if (show->bravoTrainerTower.numFights >= FRONTIER_STAGES_PER_CHALLENGE) + sTVShowState = BRAVOTOWER_STATE_NEW_RECORD; else - sTVShowState = 2; + sTVShowState = BRAVOTOWER_STATE_LOST; break; - case 1: - if (show->bravoTrainerTower.btLevel == 50) - { + case BRAVOTOWER_STATE_NEW_RECORD: + // The TV show states a "new record" was achieved as long as all the battles in the challenge were attempted, + // regardless of any previous records or whether the final battle was won or lost. + if (show->bravoTrainerTower.btLevel == FRONTIER_MAX_LEVEL_50) StringCopy(gStringVar1, gText_Lv50); - } else - { StringCopy(gStringVar1, gText_OpenLevel); - } ConvertIntToDecimalString(1, show->bravoTrainerTower.numFights); if (show->bravoTrainerTower.wonTheChallenge == TRUE) - sTVShowState = 3; + sTVShowState = BRAVOTOWER_STATE_WON; else - sTVShowState = 4; + sTVShowState = BRAVOTOWER_STATE_LOST_FINAL; break; - case 2: + case BRAVOTOWER_STATE_LOST: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); ConvertIntToDecimalString(1, show->bravoTrainerTower.numFights + 1); if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; + sTVShowState = BRAVOTOWER_STATE_SATISFIED; else - sTVShowState = 6; + sTVShowState = BRAVOTOWER_STATE_UNSATISFIED; break; - case 3: + case BRAVOTOWER_STATE_WON: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; + sTVShowState = BRAVOTOWER_STATE_SATISFIED; else - sTVShowState = 6; + sTVShowState = BRAVOTOWER_STATE_UNSATISFIED; break; - case 4: + case BRAVOTOWER_STATE_LOST_FINAL: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; + sTVShowState = BRAVOTOWER_STATE_SATISFIED; else - sTVShowState = 6; + sTVShowState = BRAVOTOWER_STATE_UNSATISFIED; break; - case 5: + case BRAVOTOWER_STATE_SATISFIED: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 11; + sTVShowState = BRAVOTOWER_STATE_RESPONSE; break; - case 6: + case BRAVOTOWER_STATE_UNSATISFIED: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 11; + sTVShowState = BRAVOTOWER_STATE_RESPONSE; break; - case 7: - sTVShowState = 11; + case BRAVOTOWER_STATE_UNUSED_1: + sTVShowState = BRAVOTOWER_STATE_RESPONSE; break; - case 8: - case 9: - case 10: + case BRAVOTOWER_STATE_UNUSED_2: + case BRAVOTOWER_STATE_UNUSED_3: + case BRAVOTOWER_STATE_UNUSED_4: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); - sTVShowState = 11; + sTVShowState = BRAVOTOWER_STATE_RESPONSE; break; - case 11: + case BRAVOTOWER_STATE_RESPONSE: CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 12; + sTVShowState = BRAVOTOWER_STATE_RESPONSE_SATISFIED; else - sTVShowState = 13; + sTVShowState = BRAVOTOWER_STATE_RESPONSE_UNSATISFIED; break; - case 12: - case 13: + case BRAVOTOWER_STATE_RESPONSE_SATISFIED: + case BRAVOTOWER_STATE_RESPONSE_UNSATISFIED: CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); TVShowConvertInternationalString(gStringVar2, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); TVShowConvertInternationalString(gStringVar3, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 14; + sTVShowState = BRAVOTOWER_STATE_OUTRO; break; - case 14: + case BRAVOTOWER_STATE_OUTRO: TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); TVShowDone();