diff options
Diffstat (limited to 'src/battle_tent.c')
-rw-r--r-- | src/battle_tent.c | 280 |
1 files changed, 147 insertions, 133 deletions
diff --git a/src/battle_tent.c b/src/battle_tent.c index 34e3e9628..b2db0e39c 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -11,140 +11,154 @@ #include "battle_factory_screen.h" #include "frontier_util.h" #include "string_util.h" +#include "constants/battle_tent.h" +#include "constants/battle_tent_trainers.h" +#include "constants/battle_tent_mons.h" #include "constants/items.h" #include "constants/layouts.h" #include "constants/region_map_sections.h" #include "constants/species.h" +#include "constants/trainers.h" // This file's functions. -static void sub_81B99D4(void); -static void sub_81B9A28(void); -static void sub_81B9A44(void); -static void sub_81B9A60(void); -static void sub_81B9A90(void); -static void sub_81B9ABC(void); -static void sub_81B9B00(void); -static void sub_81B9B28(void); -static void sub_81B9BA0(void); -static void sub_81B9BF4(void); -static void sub_81B9C10(void); -static void sub_81B9C2C(void); -static void sub_81B9C70(void); -static void sub_81B9C98(void); -static void sub_81B9CF0(void); -static void sub_81B9D28(void); -static void sub_81B9D7C(void); -static void sub_81B9D98(void); -static void sub_81B9DB4(void); -static void sub_81B9DF8(void); -static void sub_81B9E20(void); -static void sub_81B9E78(void); -static void sub_81B9E88(void); -static void sub_81BA040(void); -static void sub_81B9EC0(void); +static void InitVerdanturfTentChallenge(void); +static void GetVerdanturfTentPrize(void); +static void SetVerdanturfTentPrize(void); +static void SetVerdanturfTentTrainerGfx(void); +static void BufferVerdanturfTentTrainerIntro(void); +static void SaveVerdanturfTentChallenge(void); +static void SetRandomVerdanturfTentPrize(void); +static void GiveVerdanturfTentPrize(void); +static void InitFallarborTentChallenge(void); +static void GetFallarborTentPrize(void); +static void SetFallarborTentPrize(void); +static void SaveFallarborTentChallenge(void); +static void SetRandomFallarborTentPrize(void); +static void GiveFallarborTentPrize(void); +static void BufferFallarborTentTrainerName(void); +static void InitSlateportTentChallenge(void); +static void GetSlateportTentPrize(void); +static void SetSlateportTentPrize(void); +static void SaveSlateportTentChallenge(void); +static void SetRandomSlateportTentPrize(void); +static void GiveSlateportTentPrize(void); +static void SelectInitialRentalMons(void); +static void SwapRentalMons(void); +static void GenerateOpponentMons(void); +static void GenerateInitialRentalMons(void); + +/* + * Battle Tents are mini versions of particular Battle Frontier facilities + * As such they each share some scripts and functions with their counterpart + * + * Verdanturf Battle Tent: Battle Palace + * Fallarbor Battle Tent: Battle Arena + * Slateport Battle Tent: Battle Factory + * + */ // IWRAM bss static u16 sRandMonSetId; // const rom data -void static (*const gUnknown_086160B4[])(void) = -{ - sub_81B99D4, - sub_81B9A28, - sub_81B9A44, - sub_81B9A60, - sub_81B9A90, - sub_81B9ABC, - sub_81B9B00, - sub_81B9B28 +void static (*const sVerdanturfTentFuncs[])(void) = +{ + [VERDANTURF_TENT_FUNC_INIT] = InitVerdanturfTentChallenge, + [VERDANTURF_TENT_FUNC_GET_PRIZE] = GetVerdanturfTentPrize, + [VERDANTURF_TENT_FUNC_SET_PRIZE] = SetVerdanturfTentPrize, + [VERDANTURF_TENT_FUNC_SET_OPPONENT_GFX] = SetVerdanturfTentTrainerGfx, + [VERDANTURF_TENT_FUNC_GET_OPPONENT_INTRO] = BufferVerdanturfTentTrainerIntro, + [VERDANTURF_TENT_FUNC_SAVE] = SaveVerdanturfTentChallenge, + [VERDANTURF_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomVerdanturfTentPrize, + [VERDANTURF_TENT_FUNC_GIVE_PRIZE] = GiveVerdanturfTentPrize }; static const u16 sVerdanturfTentRewards[] = {ITEM_NEST_BALL}; -void static (*const gUnknown_086160D8[])(void) = +void static (*const sFallarborTentFuncs[])(void) = { - sub_81B9BA0, - sub_81B9BF4, - sub_81B9C10, - sub_81B9C2C, - sub_81B9C70, - sub_81B9C98, - sub_81B9CF0 + [FALLARBOR_TENT_FUNC_INIT] = InitFallarborTentChallenge, + [FALLARBOR_TENT_FUNC_GET_PRIZE] = GetFallarborTentPrize, + [FALLARBOR_TENT_FUNC_SET_PRIZE] = SetFallarborTentPrize, + [FALLARBOR_TENT_FUNC_SAVE] = SaveFallarborTentChallenge, + [FALLARBOR_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomFallarborTentPrize, + [FALLARBOR_TENT_FUNC_GIVE_PRIZE] = GiveFallarborTentPrize, + [FALLARBOR_TENT_FUNC_GET_OPPONENT_NAME] = BufferFallarborTentTrainerName }; static const u16 sFallarborTentRewards[] = {ITEM_HYPER_POTION}; -void static (*const gUnknown_086160F8[])(void) = -{ - sub_81B9D28, - sub_81B9D7C, - sub_81B9D98, - sub_81B9DB4, - sub_81B9DF8, - sub_81B9E20, - sub_81B9E78, - sub_81B9E88, - sub_81BA040, - sub_81B9EC0 +void static (*const sSlateportTentFuncs[])(void) = +{ + [SLATEPORT_TENT_FUNC_INIT] = InitSlateportTentChallenge, + [SLATEPORT_TENT_FUNC_GET_PRIZE] = GetSlateportTentPrize, + [SLATEPORT_TENT_FUNC_SET_PRIZE] = SetSlateportTentPrize, + [SLATEPORT_TENT_FUNC_SAVE] = SaveSlateportTentChallenge, + [SLATEPORT_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomSlateportTentPrize, + [SLATEPORT_TENT_FUNC_GIVE_PRIZE] = GiveSlateportTentPrize, + [SLATEPORT_TENT_FUNC_SELECT_RENT_MONS] = SelectInitialRentalMons, + [SLATEPORT_TENT_FUNC_SWAP_RENT_MONS] = SwapRentalMons, + [SLATEPORT_TENT_FUNC_GENERATE_OPPONENT_MONS] = GenerateOpponentMons, + [SLATEPORT_TENT_FUNC_GENERATE_RENTAL_MONS] = GenerateInitialRentalMons }; static const u16 sSlateportTentRewards[] = {ITEM_FULL_HEAL}; // code -void sub_81B99B4(void) +void CallVerdanturfTentFunction(void) { - gUnknown_086160B4[gSpecialVar_0x8004](); + sVerdanturfTentFuncs[gSpecialVar_0x8004](); } -static void sub_81B99D4(void) +static void InitVerdanturfTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; - gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; + gSaveBlock2Ptr->frontier.challengePaused = FALSE; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } -static void sub_81B9A28(void) +static void GetVerdanturfTentPrize(void) { - gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E6A; + gSpecialVar_Result = gSaveBlock2Ptr->frontier.verdanturfTentPrize; } -static void sub_81B9A44(void) +static void SetVerdanturfTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6A = gSpecialVar_0x8006; + gSaveBlock2Ptr->frontier.verdanturfTentPrize = gSpecialVar_0x8006; } -static void sub_81B9A60(void) +static void SetVerdanturfTentTrainerGfx(void) { gTrainerBattleOpponent_A = (u32)((Random() % 255) * 5) / 64; SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); } -static void sub_81B9A90(void) +static void BufferVerdanturfTentTrainerIntro(void) { - if (gTrainerBattleOpponent_A < 300) + if (gTrainerBattleOpponent_A < FRONTIER_TRAINERS_COUNT) FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); } -static void sub_81B9ABC(void) +static void SaveVerdanturfTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); - gSaveBlock2Ptr->frontier.field_CA9_a = TRUE; - sub_81A4C30(); + gSaveBlock2Ptr->frontier.challengePaused = TRUE; + SaveGameFrontier(); } -static void sub_81B9B00(void) +static void SetRandomVerdanturfTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6A = sVerdanturfTentRewards[Random() % ARRAY_COUNT(sVerdanturfTentRewards)]; + gSaveBlock2Ptr->frontier.verdanturfTentPrize = sVerdanturfTentRewards[Random() % ARRAY_COUNT(sVerdanturfTentRewards)]; } -static void sub_81B9B28(void) +static void GiveVerdanturfTentPrize(void) { - if (AddBagItem(gSaveBlock2Ptr->frontier.field_E6A, 1) == TRUE) + if (AddBagItem(gSaveBlock2Ptr->frontier.verdanturfTentPrize, 1) == TRUE) { - CopyItemName(gSaveBlock2Ptr->frontier.field_E6A, gStringVar1); - gSaveBlock2Ptr->frontier.field_E6A = ITEM_NONE; + CopyItemName(gSaveBlock2Ptr->frontier.verdanturfTentPrize, gStringVar1); + gSaveBlock2Ptr->frontier.verdanturfTentPrize = ITEM_NONE; gSpecialVar_Result = TRUE; } else @@ -153,48 +167,48 @@ static void sub_81B9B28(void) } } -void sub_81B9B80(void) +void CallFallarborTentFunction(void) { - gUnknown_086160D8[gSpecialVar_0x8004](); + sFallarborTentFuncs[gSpecialVar_0x8004](); } -static void sub_81B9BA0(void) +static void InitFallarborTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; - gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; + gSaveBlock2Ptr->frontier.challengePaused = FALSE; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } -static void sub_81B9BF4(void) +static void GetFallarborTentPrize(void) { - gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E6C; + gSpecialVar_Result = gSaveBlock2Ptr->frontier.fallarborTentPrize; } -static void sub_81B9C10(void) +static void SetFallarborTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6C = gSpecialVar_0x8006; + gSaveBlock2Ptr->frontier.fallarborTentPrize = gSpecialVar_0x8006; } -static void sub_81B9C2C(void) +static void SaveFallarborTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); - gSaveBlock2Ptr->frontier.field_CA9_a = TRUE; - sub_81A4C30(); + gSaveBlock2Ptr->frontier.challengePaused = TRUE; + SaveGameFrontier(); } -static void sub_81B9C70(void) +static void SetRandomFallarborTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6C = sFallarborTentRewards[Random() % ARRAY_COUNT(sFallarborTentRewards)]; + gSaveBlock2Ptr->frontier.fallarborTentPrize = sFallarborTentRewards[Random() % ARRAY_COUNT(sFallarborTentRewards)]; } -static void sub_81B9C98(void) +static void GiveFallarborTentPrize(void) { - if (AddBagItem(gSaveBlock2Ptr->frontier.field_E6C, 1) == TRUE) + if (AddBagItem(gSaveBlock2Ptr->frontier.fallarborTentPrize, 1) == TRUE) { - CopyItemName(gSaveBlock2Ptr->frontier.field_E6C, gStringVar1); - gSaveBlock2Ptr->frontier.field_E6C = ITEM_NONE; + CopyItemName(gSaveBlock2Ptr->frontier.fallarborTentPrize, gStringVar1); + gSaveBlock2Ptr->frontier.fallarborTentPrize = ITEM_NONE; gSpecialVar_Result = TRUE; } else @@ -203,53 +217,53 @@ static void sub_81B9C98(void) } } -static void sub_81B9CF0(void) +static void BufferFallarborTentTrainerName(void) { GetFrontierTrainerName(gStringVar1, gTrainerBattleOpponent_A); } -void sub_81B9D08(void) +void CallSlateportTentFunction(void) { - gUnknown_086160F8[gSpecialVar_0x8004](); + sSlateportTentFuncs[gSpecialVar_0x8004](); } -static void sub_81B9D28(void) +static void InitSlateportTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; - gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; + gSaveBlock2Ptr->frontier.challengePaused = FALSE; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } -static void sub_81B9D7C(void) +static void GetSlateportTentPrize(void) { - gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E6E; + gSpecialVar_Result = gSaveBlock2Ptr->frontier.slateportTentPrize; } -static void sub_81B9D98(void) +static void SetSlateportTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6E = gSpecialVar_0x8006; + gSaveBlock2Ptr->frontier.slateportTentPrize = gSpecialVar_0x8006; } -static void sub_81B9DB4(void) +static void SaveSlateportTentChallenge(void) { - gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); - gSaveBlock2Ptr->frontier.field_CA9_a = TRUE; - sub_81A4C30(); + gSaveBlock2Ptr->frontier.challengePaused = TRUE; + SaveGameFrontier(); } -static void sub_81B9DF8(void) +static void SetRandomSlateportTentPrize(void) { - gSaveBlock2Ptr->frontier.field_E6E = sSlateportTentRewards[Random() % ARRAY_COUNT(sSlateportTentRewards)]; + gSaveBlock2Ptr->frontier.slateportTentPrize = sSlateportTentRewards[Random() % ARRAY_COUNT(sSlateportTentRewards)]; } -static void sub_81B9E20(void) +static void GiveSlateportTentPrize(void) { - if (AddBagItem(gSaveBlock2Ptr->frontier.field_E6E, 1) == TRUE) + if (AddBagItem(gSaveBlock2Ptr->frontier.slateportTentPrize, 1) == TRUE) { - CopyItemName(gSaveBlock2Ptr->frontier.field_E6E, gStringVar1); - gSaveBlock2Ptr->frontier.field_E6E = ITEM_NONE; + CopyItemName(gSaveBlock2Ptr->frontier.slateportTentPrize, gStringVar1); + gSaveBlock2Ptr->frontier.slateportTentPrize = ITEM_NONE; gSpecialVar_Result = TRUE; } else @@ -258,13 +272,13 @@ static void sub_81B9E20(void) } } -static void sub_81B9E78(void) +static void SelectInitialRentalMons(void) { ZeroPlayerPartyMons(); DoBattleFactorySelectScreen(); } -static void sub_81B9E88(void) +static void SwapRentalMons(void) { DoBattleFactorySwapScreen(); } @@ -275,7 +289,7 @@ bool8 InSlateportBattleTent(void) && (gMapHeader.mapLayoutId == LAYOUT_BATTLE_TENT_CORRIDOR || gMapHeader.mapLayoutId == LAYOUT_BATTLE_TENT_BATTLE_ROOM); } -static void sub_81B9EC0(void) +static void GenerateInitialRentalMons(void) { s32 i, j; u8 firstMonId; @@ -299,7 +313,7 @@ static void sub_81B9EC0(void) while (i != PARTY_SIZE) { // Cannot have two pokemon of the same species. - monSetId = Random() % 70; + monSetId = Random() % NUM_SLATEPORT_TENT_MONS; for (j = firstMonId; j < firstMonId + i; j++) { u16 monId = monIds[j]; @@ -337,14 +351,14 @@ static void sub_81B9EC0(void) } } -static void sub_81BA040(void) +static void GenerateOpponentMons(void) { u16 trainerId; s32 i, j, k; - register const u16 *monSets asm("r9"); // Fix me. Compiler insists on moving that variable into stack. - u16 species[3]; - u16 heldItems[3]; - s32 setsCount = 0; + register const u16 *monSet asm("r9"); // Fix me. Compiler insists on moving that variable into stack. + u16 species[FRONTIER_PARTY_SIZE]; + u16 heldItems[FRONTIER_PARTY_SIZE]; + s32 monId = 0; gFacilityTrainers = gSlateportBattleTentTrainers; gFacilityTrainerMons = gSlateportBattleTentMons; @@ -353,7 +367,7 @@ static void sub_81BA040(void) { do { - trainerId = Random() % 30; + trainerId = Random() % NUM_BATTLE_TENT_TRAINERS; for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId) @@ -362,21 +376,21 @@ static void sub_81BA040(void) } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); gTrainerBattleOpponent_A = trainerId; - while (gFacilityTrainers[gTrainerBattleOpponent_A].monSets[setsCount] != 0xFFFF) - setsCount++; - if (setsCount > 8) + while (gFacilityTrainers[gTrainerBattleOpponent_A].monSet[monId] != 0xFFFF) + monId++; + if (monId > 8) break; - setsCount = 0; + monId = 0; } if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; - monSets = gFacilityTrainers[gTrainerBattleOpponent_A].monSets; + monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; i = 0; - while (i != 3) + while (i != FRONTIER_PARTY_SIZE) { - sRandMonSetId = monSets[Random() % setsCount]; + sRandMonSetId = monSet[Random() % monId]; for (j = 0; j < 6; j++) { if (gFacilityTrainerMons[sRandMonSetId].species == gFacilityTrainerMons[gSaveBlock2Ptr->frontier.rentalMons[j].monId].species) |