From 6ae9a7bc89dfb99a953f108dbe03bdf76621d5bc Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 22 Nov 2023 16:40:14 +0100 Subject: [PATCH 1/9] Partner Battle refactor --- .../MossdeepCity_SpaceCenter_2F/scripts.inc | 17 +-- data/scripts/debug.inc | 14 ++ include/constants/battle_frontier.h | 7 +- include/constants/battle_partner.h | 11 ++ include/constants/opponents.h | 4 + include/constants/trainers.h | 2 - include/data.h | 2 + include/event_scripts.h | 3 + src/battle_bg.c | 3 +- src/battle_controller_player.c | 5 +- src/battle_controller_player_partner.c | 17 +-- src/battle_intro.c | 3 +- src/battle_main.c | 3 +- src/battle_script_commands.c | 24 +--- src/battle_tower.c | 127 ++++-------------- src/data/battle_partners.h | 32 +++++ src/data/partner_parties.h | 50 +++++++ src/pokemon.c | 21 ++- 18 files changed, 179 insertions(+), 166 deletions(-) create mode 100644 include/constants/battle_partner.h create mode 100644 src/data/battle_partners.h create mode 100644 src/data/partner_parties.h diff --git a/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc b/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc index 4a22bf8eeaeb..a4fcc0237cc2 100644 --- a/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc +++ b/data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc @@ -257,14 +257,7 @@ MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle:: goto MossdeepCity_SpaceCenter_2F_EventScript_ReadyForBattlePrompt MossdeepCity_SpaceCenter_2F_EventScript_DoStevenMultiBattle:: - special ReducePlayerPartyToSelectedMons - frontier_set FRONTIER_DATA_SELECTED_MON_ORDER - setvar VAR_0x8004, SPECIAL_BATTLE_STEVEN - setvar VAR_0x8005, 0 - special DoSpecialTrainerBattle - waitstate - frontier_saveparty - special LoadPlayerParty + multi_2_vs_2 TRAINER_MAXIE_MOSSDEEP, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand, TRAINER_TABITHA_MOSSDEEP, MossdeepCity_SpaceCenter_Text_TabithaDefeat, PARTNER_STEVEN, TRAINER_BACK_PIC_STEVEN switch VAR_RESULT case 1, MossdeepCity_SpaceCenter_2F_EventScript_DefeatedMaxieTabitha fadescreen FADE_TO_BLACK @@ -336,14 +329,6 @@ MossdeepCity_SpaceCenter_2F_EventScript_StevenFacePlayerWest:: turnobject LOCALID_STEVEN, DIR_EAST return -MossdeepCity_SpaceCenter_2F_EventScript_MaxieTrainer:: - trainerbattle TRAINER_BATTLE_SET_TRAINER_A, TRAINER_MAXIE_MOSSDEEP, 0, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand - end - -MossdeepCity_SpaceCenter_2F_EventScript_TabithaTrainer:: - trainerbattle TRAINER_BATTLE_SET_TRAINER_B, TRAINER_TABITHA_MOSSDEEP, 0, MossdeepCity_SpaceCenter_Text_TabithaDefeat, MossdeepCity_SpaceCenter_Text_TabithaDefeat - end - MossdeepCity_SpaceCenter_2F_EventScript_RivalRayquazaCall:: lockall checkplayergender diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 3e482c839104..8fe76c238d51 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -96,11 +96,25 @@ Debug_BoxFilledMessage_Text: .string "Storage boxes filled!$" Debug_EventScript_Script_1:: + goto MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle end Debug_EventScript_Script_2:: + multi_fixed_2_vs_2 TRAINER_JOSH, RustboroCity_Gym_Text_JoshDefeat, TRAINER_TOMMY, RustboroCity_Gym_Text_TommyDefeat, PARTNER_MAY, TRAINER_BACK_PIC_MAY + switch VAR_RESULT + case 1, Debug_EventScript_Script_2_WonBattle + fadescreen FADE_TO_BLACK + special SetCB2WhiteOut + waitstate + +Debug_EventScript_Script_2_WonBattle: + msgbox Debug_EventScript_Text_2_WonBattle, MSGBOX_DEFAULT + closemessage end +Debug_EventScript_Text_2_WonBattle: + .string "You and your partner won!$" + Debug_EventScript_Script_3:: end diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index 85c1df085ed4..e4a56b15d147 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -41,10 +41,9 @@ #define SPECIAL_BATTLE_ARENA 5 #define SPECIAL_BATTLE_FACTORY 6 #define SPECIAL_BATTLE_PIKE_SINGLE 7 -#define SPECIAL_BATTLE_STEVEN 8 -#define SPECIAL_BATTLE_PIKE_DOUBLE 9 -#define SPECIAL_BATTLE_PYRAMID 10 -#define SPECIAL_BATTLE_MULTI 11 +#define SPECIAL_BATTLE_PIKE_DOUBLE 8 +#define SPECIAL_BATTLE_PYRAMID 9 +#define SPECIAL_BATTLE_MULTI 10 #define MAX_BATTLE_FRONTIER_POINTS 9999 #define MAX_STREAK 9999 diff --git a/include/constants/battle_partner.h b/include/constants/battle_partner.h new file mode 100644 index 000000000000..c51872ace5d9 --- /dev/null +++ b/include/constants/battle_partner.h @@ -0,0 +1,11 @@ + +#ifndef GUARD_CONSTANTS_BATTLE_PARTNERS_H +#define GUARD_CONSTANTS_BATTLE_PARTNERS_H + +#define PARTNER_NONE 0 +#define PARTNER_STEVEN 1 +#define PARTNER_MAY 2 + +#define PARTNERS_COUNT 3 + +#endif // GUARD_CONSTANTS_BATTLE_PARTNERS_H diff --git a/include/constants/opponents.h b/include/constants/opponents.h index c9cf9239d851..74dfca8bbae3 100644 --- a/include/constants/opponents.h +++ b/include/constants/opponents.h @@ -1,6 +1,8 @@ #ifndef GUARD_CONSTANTS_OPPONENTS_H #define GUARD_CONSTANTS_OPPONENTS_H +#include "constants/battle_partner.h" + #define TRAINER_NONE 0 #define TRAINER_SAWYER_1 1 #define TRAINER_GRUNT_AQUA_HIDEOUT_1 2 @@ -863,5 +865,7 @@ #define TRAINERS_COUNT 855 #define MAX_TRAINERS_COUNT 864 +#define TRAINER_PARTNER(partner) (865 + partner) + #endif // GUARD_CONSTANTS_OPPONENTS_H diff --git a/include/constants/trainers.h b/include/constants/trainers.h index 16904bcd1221..ff7d5b11f393 100644 --- a/include/constants/trainers.h +++ b/include/constants/trainers.h @@ -14,8 +14,6 @@ #define TRAINER_SECRET_BASE 1024 #define TRAINER_LINK_OPPONENT 2048 #define TRAINER_UNION_ROOM 3072 -#define TRAINER_STEVEN_PARTNER 3075 -#define TRAINER_CUSTOM_PARTNER 3076 #define TRAINER_PIC_HIKER 0 #define TRAINER_PIC_AQUA_GRUNT_M 1 diff --git a/include/data.h b/include/data.h index 842332911423..46d617738a26 100644 --- a/include/data.h +++ b/include/data.h @@ -115,6 +115,8 @@ extern const struct CompressedSpriteSheet gMonFrontPicTable[]; extern const struct CompressedSpriteSheet gMonFrontPicTableFemale[]; extern const struct Trainer gTrainers[]; +extern const struct Trainer gBattlePartners[]; + extern const u8 gTrainerClassNames[][13]; extern const u8 gSpeciesNames[NUM_SPECIES][POKEMON_NAME_LENGTH + 1]; extern const u8 gMoveNames[MOVES_COUNT_DYNAMAX][MOVE_NAME_LENGTH + 1]; diff --git a/include/event_scripts.h b/include/event_scripts.h index 4e0a88f82ac1..ca965afa8b7a 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -612,4 +612,7 @@ extern const u8 EventScript_TradeCenter_Chair0[]; extern const u8 EventScript_ConfirmLeaveCableClubRoom[]; extern const u8 EventScript_TerminateLink[]; +extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle[]; + + #endif // GUARD_EVENT_SCRIPTS_H diff --git a/src/battle_bg.c b/src/battle_bg.c index 2e9265834388..749671ad6f50 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -26,6 +26,7 @@ #include "constants/songs.h" #include "constants/trainers.h" #include "constants/battle_anim.h" +#include "constants/battle_partner.h" // .rodata static const u16 sUnrefArray[] = {0x0300, 0x0000}; //OamData? @@ -1146,7 +1147,7 @@ void DrawBattleEntryBackground(void) } else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_EREADER_TRAINER)) { - if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) + if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) { LZDecompressVram(gBattleTerrainAnimTiles_Building, (void *)(BG_CHAR_ADDR(1))); LZDecompressVram(gBattleTerrainAnimTilemap_Building, (void *)(BG_SCREEN_ADDR(28))); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 48ab691dfa93..854871c58ecb 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -31,6 +31,7 @@ #include "util.h" #include "window.h" #include "constants/battle_anim.h" +#include "constants/battle_partner.h" #include "constants/items.h" #include "constants/moves.h" #include "constants/party_menu.h" @@ -1858,7 +1859,7 @@ static void PlayerHandleDrawTrainerPic(u32 battler) else // First mon, on the left. xPos = 32; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE)) { xPos = 90; yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80; @@ -1876,7 +1877,7 @@ static void PlayerHandleDrawTrainerPic(u32 battler) } // Use front pic table for any tag battles unless your partner is Steven or a custom partner. - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE)) { trainerPicId = PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender); isFrontPic = TRUE; diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index f56c14a07669..94964ba6bb64 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -27,6 +27,7 @@ #include "util.h" #include "window.h" #include "constants/battle_anim.h" +#include "constants/battle_partner.h" #include "constants/songs.h" #include "constants/party_menu.h" #include "constants/trainers.h" @@ -295,15 +296,9 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler) s16 xPos, yPos; u32 trainerPicId; - if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) + if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) { - trainerPicId = TRAINER_BACK_PIC_STEVEN; - xPos = 90; - yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80; - } - else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) - { - trainerPicId = gPartnerSpriteId; + trainerPicId = gBattlePartners[gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic; xPos = 90; yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80; } @@ -321,7 +316,7 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler) } // Use back pic only if the partner is Steven or a custom partner. - if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) + if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) isFrontPic = FALSE; else isFrontPic = TRUE; @@ -438,9 +433,7 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(u32 battler) { const u32 *trainerPal; - if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) - trainerPal = gTrainerBackPicPaletteTable[TRAINER_STEVEN_PARTNER].data; - else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) // Custom multi battle. + if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data; else if (IsAiVsAiBattle()) trainerPal = gTrainerFrontPicPaletteTable[gTrainers[gPartnerTrainerId].trainerPic].data; diff --git a/src/battle_intro.c b/src/battle_intro.c index 90ff736f003e..463804368fe9 100644 --- a/src/battle_intro.c +++ b/src/battle_intro.c @@ -9,6 +9,7 @@ #include "scanline_effect.h" #include "task.h" #include "trig.h" +#include "constants/battle_partner.h" #include "constants/trainers.h" extern const u8 gBattleAnimBgCntSet[]; @@ -104,7 +105,7 @@ void HandleIntroSlide(u8 terrain) { u8 taskId; - if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER) + if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE)) { taskId = CreateTask(BattleIntroSlidePartner, 0); } diff --git a/src/battle_main.c b/src/battle_main.c index 28484a7061fa..f72784b7e860 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -56,6 +56,7 @@ #include "constants/abilities.h" #include "constants/battle_move_effects.h" #include "constants/battle_string_ids.h" +#include "constants/battle_partner.h" #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/moves.h" @@ -514,7 +515,7 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0H = DISPLAY_WIDTH; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE)) { gBattle_WIN0V = DISPLAY_HEIGHT - 1; gBattle_WIN1H = DISPLAY_WIDTH; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 8de129f474e6..69d8521d657a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -50,6 +50,7 @@ #include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_string_ids.h" +#include "constants/battle_partner.h" #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/item_effects.h" @@ -4309,7 +4310,7 @@ static bool32 NoAliveMonsForPlayerAndPartner(void) u32 i; u32 HP_count = 0; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER)) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) { for (i = 0; i < PARTY_SIZE; i++) { @@ -4329,25 +4330,12 @@ static bool32 NoAliveMonsForPlayer(void) u32 i; u32 HP_count = 0; - // Get total HP for the player's party to determine if the player has lost - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER)) + for (i = 0; i < PARTY_SIZE; i++) { - // In multi battle with Steven, skip his Pokémon - for (i = 0; i < MULTI_PARTY_SIZE; i++) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) + && (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !(gBattleStruct->arenaLostPlayerMons & gBitTable[i]))) { - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) - HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP); - } - } - else - { - for (i = 0; i < PARTY_SIZE; i++) - { - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) - && (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !(gBattleStruct->arenaLostPlayerMons & gBitTable[i]))) - { - HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP); - } + HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP); } } diff --git a/src/battle_tower.c b/src/battle_tower.c index c30406f79834..61029d2ca587 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -32,15 +32,13 @@ #include "constants/battle_tent_mons.h" #include "constants/battle_tent_trainers.h" #include "constants/battle_tower.h" +#include "constants/battle_partner.h" #include "constants/frontier_util.h" #include "constants/items.h" #include "constants/trainers.h" #include "constants/event_objects.h" #include "constants/moves.h" -extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_MaxieTrainer[]; -extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_TabithaTrainer[]; - // EWRAM vars. EWRAM_DATA const struct BattleFrontierTrainer *gFacilityTrainers = NULL; EWRAM_DATA const struct FacilityMon *gFacilityTrainerMons = NULL; @@ -762,44 +760,11 @@ static const u8 *const *const sPartnerApprenticeTextTables[NUM_APPRENTICES] = sPartnerApprenticeTexts16 }; -struct -{ - u16 species; - u8 fixedIV; - u8 level; - u8 nature; - u8 evs[NUM_STATS]; - u16 moves[MAX_MON_MOVES]; -} static const sStevenMons[MULTI_PARTY_SIZE] = -{ - { - .species = SPECIES_METANG, - .fixedIV = MAX_PER_STAT_IVS, - .level = 42, - .nature = NATURE_BRAVE, - .evs = {0, 252, 252, 0, 6, 0}, - .moves = {MOVE_LIGHT_SCREEN, MOVE_PSYCHIC, MOVE_REFLECT, MOVE_METAL_CLAW} - }, - { - .species = SPECIES_SKARMORY, - .fixedIV = MAX_PER_STAT_IVS, - .level = 43, - .nature = NATURE_IMPISH, - .evs = {252, 0, 0, 0, 6, 252}, - .moves = {MOVE_TOXIC, MOVE_AERIAL_ACE, MOVE_PROTECT, MOVE_STEEL_WING} - }, - { - .species = SPECIES_AGGRON, - .fixedIV = MAX_PER_STAT_IVS, - .level = 44, - .nature = NATURE_ADAMANT, - .evs = {0, 252, 0, 0, 252, 6}, - .moves = {MOVE_THUNDER, MOVE_PROTECT, MOVE_SOLAR_BEAM, MOVE_DRAGON_CLAW} - } -}; - #include "data/battle_frontier/battle_tent.h" +#include "data/partner_parties.h" +#include "data/battle_partners.h" + static void (* const sBattleTowerFuncs[])(void) = { [BATTLE_TOWER_FUNC_INIT] = InitTowerChallenge, @@ -1447,13 +1412,9 @@ u8 GetFrontierOpponentClass(u16 trainerId) { return GetFrontierBrainTrainerClass(); } - else if (trainerId == TRAINER_STEVEN_PARTNER) - { - trainerClass = gTrainers[TRAINER_STEVEN].trainerClass; - } - else if (trainerId >= TRAINER_CUSTOM_PARTNER) + else if (trainerId >= TRAINER_PARTNER(PARTNER_NONE)) { - trainerClass = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerClass; + trainerClass = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerClass; } else if (trainerId < FRONTIER_TRAINERS_COUNT) { @@ -1531,15 +1492,10 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) CopyFrontierBrainTrainerName(dst); return; } - else if (trainerId == TRAINER_STEVEN_PARTNER) + else if (trainerId >= TRAINER_PARTNER(PARTNER_NONE)) { - for (i = 0; i < PLAYER_NAME_LENGTH; i++) - dst[i] = gTrainers[TRAINER_STEVEN].trainerName[i]; - } - else if (trainerId >= TRAINER_CUSTOM_PARTNER) - { - for (i = 0; gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName[i] != EOS; i++) - dst[i] = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName[i]; + for (i = 0; gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName[i] != EOS; i++) + dst[i] = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName[i]; } else if (trainerId < FRONTIER_TRAINERS_COUNT) { @@ -2136,18 +2092,6 @@ void DoSpecialTrainerBattle(void) PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(GetSpecialBattleTransition(B_TRANSITION_GROUP_B_PIKE)); break; - case SPECIAL_BATTLE_STEVEN: - gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER; - FillPartnerParty(TRAINER_STEVEN_PARTNER); - gApproachingTrainerId = 0; - BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_MaxieTrainer + 1); - gApproachingTrainerId = 1; - BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_TabithaTrainer + 1); - gPartnerTrainerId = TRAINER_STEVEN_PARTNER; - CreateTask(Task_StartBattleAfterTransition, 1); - PlayMapChosenOrBattleBGM(0); - BattleTransition_StartOnField(B_TRANSITION_MAGMA); - break; case SPECIAL_BATTLE_MULTI: if (gSpecialVar_0x8005 & MULTI_BATTLE_2_VS_WILD) // Player + AI against wild mon { @@ -2164,7 +2108,7 @@ void DoSpecialTrainerBattle(void) } gPartnerSpriteId = VarGet(gSpecialVar_0x8007); - gPartnerTrainerId = VarGet(gSpecialVar_0x8006) + TRAINER_CUSTOM_PARTNER; + gPartnerTrainerId = VarGet(gSpecialVar_0x8006) + TRAINER_PARTNER(PARTNER_NONE); FillPartnerParty(gPartnerTrainerId); CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); @@ -3012,46 +2956,25 @@ static void FillPartnerParty(u16 trainerId) s32 ball = -1; SetFacilityPtrsGetLevel(); - if (trainerId == TRAINER_STEVEN_PARTNER) - { - for (i = 0; i < MULTI_PARTY_SIZE; i++) - { - do - { - j = Random32(); - } while (IsShinyOtIdPersonality(STEVEN_OTID, j) || sStevenMons[i].nature != GetNatureFromPersonality(j)); - CreateMon(&gPlayerParty[MULTI_PARTY_SIZE + i], - sStevenMons[i].species, - sStevenMons[i].level, - sStevenMons[i].fixedIV, - TRUE, - #ifdef BUGFIX - j, - #else - i, // BUG: personality was stored in the 'j' variable. As a result, Steven's pokemon do not have the intended natures. - #endif - OT_ID_PRESET, STEVEN_OTID); - for (j = 0; j < PARTY_SIZE; j++) - SetMonData(&gPlayerParty[MULTI_PARTY_SIZE + i], MON_DATA_HP_EV + j, &sStevenMons[i].evs[j]); - for (j = 0; j < MAX_MON_MOVES; j++) - SetMonMoveSlot(&gPlayerParty[MULTI_PARTY_SIZE + i], sStevenMons[i].moves[j], j); - SetMonData(&gPlayerParty[MULTI_PARTY_SIZE + i], MON_DATA_OT_NAME, gTrainers[TRAINER_STEVEN].trainerName); - j = MALE; - SetMonData(&gPlayerParty[MULTI_PARTY_SIZE + i], MON_DATA_OT_GENDER, &j); - CalculateMonStats(&gPlayerParty[MULTI_PARTY_SIZE + i]); - } - } - else if (trainerId >= TRAINER_CUSTOM_PARTNER) + if (trainerId >= TRAINER_PARTNER(PARTNER_NONE) +) { - otID = Random32(); - for (i = 0; i < 3; i++) ZeroMonData(&gPlayerParty[i + 3]); - for (i = 0; i < 3 && i < gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partySize; i++) + for (i = 0; i < 3 && i < gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].partySize; i++) { - const struct TrainerMon *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party; + const struct TrainerMon *partyData = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].party; u32 otIdType = OT_ID_RANDOM_NO_SHINY; + + if (trainerId == PARTNER_STEVEN) + { + otID = STEVEN_OTID; + otIdType = OT_ID_PRESET; + } + else + otID = Random32(); + do { personality = Random32(); @@ -3107,9 +3030,9 @@ static void FillPartnerParty(u16 trainerId) } CalculateMonStats(&gPlayerParty[i+3]); - StringCopy(trainerName, gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName); + StringCopy(trainerName, gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName); SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_NAME, trainerName); - j = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].encounterMusic_gender >> 7; + j = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].encounterMusic_gender >> 7; SetMonData(&gPlayerParty[i+3], MON_DATA_OT_GENDER, &j); } } diff --git a/src/data/battle_partners.h b/src/data/battle_partners.h new file mode 100644 index 000000000000..d2f8b0ee6c93 --- /dev/null +++ b/src/data/battle_partners.h @@ -0,0 +1,32 @@ +const struct Trainer gBattlePartners[] = { + [TRAINER_NONE] = + { + .trainerClass = TRAINER_CLASS_PKMN_TRAINER_1, + .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_MALE, + .trainerPic = TRAINER_PIC_HIKER, + .trainerName = _(""), + .items = {}, + .doubleBattle = FALSE, + .aiFlags = 0, + .partySize = 0, + .party = NULL, + }, + + [PARTNER_STEVEN] = + { + .party = TRAINER_PARTY(sParty_StevenPartner), + .trainerClass = TRAINER_CLASS_RIVAL, + .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_MALE, + .trainerPic = TRAINER_BACK_PIC_STEVEN, + .trainerName = _("STEVEN"), + }, + + [PARTNER_MAY] = + { + .party = TRAINER_PARTY(sParty_MayPartner), + .trainerClass = TRAINER_CLASS_RIVAL, + .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_FEMALE, + .trainerPic = TRAINER_BACK_PIC_MAY, + .trainerName = _("MAY"), + }, +}; diff --git a/src/data/partner_parties.h b/src/data/partner_parties.h new file mode 100644 index 000000000000..86c9b4ccccf2 --- /dev/null +++ b/src/data/partner_parties.h @@ -0,0 +1,50 @@ +static const struct TrainerMon sParty_StevenPartner[] = { + { + .species = SPECIES_METANG, + .lvl = 42, + .nature = TRAINER_PARTY_NATURE(NATURE_BRAVE), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .ev = TRAINER_PARTY_EVS(0, 252, 252, 0, 6, 0), + .moves = {MOVE_LIGHT_SCREEN, MOVE_PSYCHIC, MOVE_REFLECT, MOVE_METAL_CLAW}, + }, + { + .species = SPECIES_SKARMORY, + .lvl = 43, + .nature = TRAINER_PARTY_NATURE(NATURE_IMPISH), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .ev = TRAINER_PARTY_EVS(252, 0, 0, 0, 6, 252), + .moves = {MOVE_TOXIC, MOVE_AERIAL_ACE, MOVE_PROTECT, MOVE_STEEL_WING}, + }, + { + .species = SPECIES_AGGRON, + .lvl = 44, + .nature = TRAINER_PARTY_NATURE(NATURE_ADAMANT), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .ev = TRAINER_PARTY_EVS(0, 252, 0, 0, 252, 6), + .moves = {MOVE_THUNDER, MOVE_PROTECT, MOVE_SOLAR_BEAM, MOVE_DRAGON_CLAW}, + } +}; + +static const struct TrainerMon sParty_MayPartner[] = { + { + .species = SPECIES_TREECKO, + .lvl = 20, + .nature = TRAINER_PARTY_NATURE(NATURE_TIMID), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .moves = {MOVE_ENERGY_BALL}, + }, + { + .species = SPECIES_TORCHIC, + .lvl = 20, + .nature = TRAINER_PARTY_NATURE(NATURE_MODEST), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .moves = {MOVE_FLAMETHROWER}, + }, + { + .species = SPECIES_MUDKIP, + .lvl = 20, + .nature = TRAINER_PARTY_NATURE(NATURE_ADAMANT), + .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), + .moves = {MOVE_WATERFALL}, + } +}; diff --git a/src/pokemon.c b/src/pokemon.c index 97577efbb06f..f9cc339801bf 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -42,6 +42,7 @@ #include "constants/battle_frontier.h" #include "constants/battle_move_effects.h" #include "constants/battle_script_commands.h" +#include "constants/battle_partner.h" #include "constants/form_change_types.h" #include "constants/hold_effects.h" #include "constants/item_effects.h" @@ -8540,7 +8541,7 @@ const u8 *GetTrainerPartnerName(void) { if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) + if (gPartnerTrainerId == TRAINER_PARTNER(PARTNER_STEVEN)) { return gTrainers[TRAINER_STEVEN].trainerName; } @@ -8763,16 +8764,22 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) const u8 *GetTrainerClassNameFromId(u16 trainerId) { - if (trainerId >= TRAINERS_COUNT) - trainerId = TRAINER_NONE; - return gTrainerClassNames[gTrainers[trainerId].trainerClass]; + if (trainerId >= MAX_TRAINERS_COUNT && trainerId < PARTNERS_COUNT) + return gTrainerClassNames[gBattlePartners[trainerId].trainerClass]; + else if (trainerId < TRAINERS_COUNT) + return gTrainerClassNames[gTrainers[trainerId].trainerClass]; + else + return gTrainerClassNames[gTrainers[TRAINER_NONE].trainerClass]; } const u8 *GetTrainerNameFromId(u16 trainerId) { - if (trainerId >= TRAINERS_COUNT) - trainerId = TRAINER_NONE; - return gTrainers[trainerId].trainerName; + if (trainerId >= MAX_TRAINERS_COUNT && trainerId < PARTNERS_COUNT) + return gBattlePartners[trainerId].trainerName; + else if (trainerId < TRAINERS_COUNT) + return gTrainers[trainerId].trainerName; + else + return gTrainers[TRAINER_NONE].trainerName; } bool8 HasTwoFramesAnimation(u16 species) From 40844d79f89ebd11b79d2a636ddfd24957140650 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 22 Nov 2023 18:04:00 +0100 Subject: [PATCH 2/9] fix for steven id --- src/battle_tower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_tower.c b/src/battle_tower.c index 61029d2ca587..54884b14ea63 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2967,7 +2967,7 @@ static void FillPartnerParty(u16 trainerId) const struct TrainerMon *partyData = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].party; u32 otIdType = OT_ID_RANDOM_NO_SHINY; - if (trainerId == PARTNER_STEVEN) + if (trainerId == TRAINER_PARTNER(PARTNER_STEVEN)) { otID = STEVEN_OTID; otIdType = OT_ID_PRESET; From 953d7a1f21115212386be3b91c198405978d8ed1 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Nov 2023 12:51:47 +0100 Subject: [PATCH 3/9] clean up --- include/constants/opponents.h | 2 +- src/battle_bg.c | 2 +- src/battle_controller_player_partner.c | 8 +++--- src/battle_script_commands.c | 2 +- src/battle_tower.c | 37 +++++++++++++------------- src/data/battle_partners.h | 5 +--- src/pokemon.c | 12 ++++----- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/include/constants/opponents.h b/include/constants/opponents.h index 74dfca8bbae3..47b633cd499e 100644 --- a/include/constants/opponents.h +++ b/include/constants/opponents.h @@ -865,7 +865,7 @@ #define TRAINERS_COUNT 855 #define MAX_TRAINERS_COUNT 864 -#define TRAINER_PARTNER(partner) (865 + partner) +#define TRAINER_PARTNER(partner) (MAX_TRAINERS_COUNT + partner) #endif // GUARD_CONSTANTS_OPPONENTS_H diff --git a/src/battle_bg.c b/src/battle_bg.c index 749671ad6f50..cf5d177cfb27 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -1147,7 +1147,7 @@ void DrawBattleEntryBackground(void) } else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_EREADER_TRAINER)) { - if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) + if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) { LZDecompressVram(gBattleTerrainAnimTiles_Building, (void *)(BG_CHAR_ADDR(1))); LZDecompressVram(gBattleTerrainAnimTilemap_Building, (void *)(BG_SCREEN_ADDR(28))); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 94964ba6bb64..5028cc1ca450 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -296,7 +296,7 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler) s16 xPos, yPos; u32 trainerPicId; - if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) + if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) { trainerPicId = gBattlePartners[gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic; xPos = 90; @@ -315,8 +315,8 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler) yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80; } - // Use back pic only if the partner is Steven or a custom partner. - if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) + // Use back pic only if the partner is custom. + if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) isFrontPic = FALSE; else isFrontPic = TRUE; @@ -433,7 +433,7 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(u32 battler) { const u32 *trainerPal; - if (gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) + if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data; else if (IsAiVsAiBattle()) trainerPal = gTrainerFrontPicPaletteTable[gTrainers[gPartnerTrainerId].trainerPic].data; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 69d8521d657a..037fa5e23f96 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4310,7 +4310,7 @@ static bool32 NoAliveMonsForPlayerAndPartner(void) u32 i; u32 HP_count = 0; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId >= TRAINER_PARTNER(PARTNER_NONE)) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) { for (i = 0; i < PARTY_SIZE; i++) { diff --git a/src/battle_tower.c b/src/battle_tower.c index 54884b14ea63..977c1f92f7a6 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1412,7 +1412,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) { return GetFrontierBrainTrainerClass(); } - else if (trainerId >= TRAINER_PARTNER(PARTNER_NONE)) + else if (trainerId > TRAINER_PARTNER(PARTNER_NONE)) { trainerClass = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerClass; } @@ -1492,7 +1492,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) CopyFrontierBrainTrainerName(dst); return; } - else if (trainerId >= TRAINER_PARTNER(PARTNER_NONE)) + else if (trainerId > TRAINER_PARTNER(PARTNER_NONE)) { for (i = 0; gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName[i] != EOS; i++) dst[i] = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName[i]; @@ -2956,8 +2956,7 @@ static void FillPartnerParty(u16 trainerId) s32 ball = -1; SetFacilityPtrsGetLevel(); - if (trainerId >= TRAINER_PARTNER(PARTNER_NONE) -) + if (trainerId > TRAINER_PARTNER(PARTNER_NONE)) { for (i = 0; i < 3; i++) ZeroMonData(&gPlayerParty[i + 3]); @@ -2994,46 +2993,46 @@ static void FillPartnerParty(u16 trainerId) CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, 0, TRUE, personality, otIdType, otID); SetMonData(&gPlayerParty[i + 3], MON_DATA_HELD_ITEM, &partyData[i].heldItem); - CustomTrainerPartyAssignMoves(&gPlayerParty[i+3], &partyData[i]); + CustomTrainerPartyAssignMoves(&gPlayerParty[i + 3], &partyData[i]); - SetMonData(&gPlayerParty[i+3], MON_DATA_IVS, &(partyData[i].iv)); + SetMonData(&gPlayerParty[i + 3], MON_DATA_IVS, &(partyData[i].iv)); if (partyData[i].ev != NULL) { - SetMonData(&gPlayerParty[i+3], MON_DATA_HP_EV, &(partyData[i].ev[0])); - SetMonData(&gPlayerParty[i+3], MON_DATA_ATK_EV, &(partyData[i].ev[1])); - SetMonData(&gPlayerParty[i+3], MON_DATA_DEF_EV, &(partyData[i].ev[2])); - SetMonData(&gPlayerParty[i+3], MON_DATA_SPATK_EV, &(partyData[i].ev[3])); - SetMonData(&gPlayerParty[i+3], MON_DATA_SPDEF_EV, &(partyData[i].ev[4])); - SetMonData(&gPlayerParty[i+3], MON_DATA_SPEED_EV, &(partyData[i].ev[5])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_HP_EV, &(partyData[i].ev[0])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_ATK_EV, &(partyData[i].ev[1])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_DEF_EV, &(partyData[i].ev[2])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_SPATK_EV, &(partyData[i].ev[3])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_SPDEF_EV, &(partyData[i].ev[4])); + SetMonData(&gPlayerParty[i + 3], MON_DATA_SPEED_EV, &(partyData[i].ev[5])); } if (partyData[i].ability != ABILITY_NONE) { const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[partyData[i].species]; u32 maxAbilities = ARRAY_COUNT(speciesInfo->abilities); - for (j = 0; j < maxAbilities; ++j) + for (j = 0; j < maxAbilities; j++) { if (speciesInfo->abilities[j] == partyData[i].ability) break; } if (j < maxAbilities) - SetMonData(&gPlayerParty[i+3], MON_DATA_ABILITY_NUM, &j); + SetMonData(&gPlayerParty[i + 3], MON_DATA_ABILITY_NUM, &j); } - SetMonData(&gPlayerParty[i+3], MON_DATA_FRIENDSHIP, &(partyData[i].friendship)); + SetMonData(&gPlayerParty[i + 3], MON_DATA_FRIENDSHIP, &(partyData[i].friendship)); if (partyData[i].ball != ITEM_NONE) { ball = partyData[i].ball; - SetMonData(&gPlayerParty[i+3], MON_DATA_POKEBALL, &ball); + SetMonData(&gPlayerParty[i + 3], MON_DATA_POKEBALL, &ball); } if (partyData[i].nickname != NULL) { - SetMonData(&gPlayerParty[i+3], MON_DATA_NICKNAME, partyData[i].nickname); + SetMonData(&gPlayerParty[i + 3], MON_DATA_NICKNAME, partyData[i].nickname); } - CalculateMonStats(&gPlayerParty[i+3]); + CalculateMonStats(&gPlayerParty[i + 3]); StringCopy(trainerName, gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName); SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_NAME, trainerName); j = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].encounterMusic_gender >> 7; - SetMonData(&gPlayerParty[i+3], MON_DATA_OT_GENDER, &j); + SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_GENDER, &j); } } else if (trainerId == TRAINER_EREADER) diff --git a/src/data/battle_partners.h b/src/data/battle_partners.h index d2f8b0ee6c93..51034e3aca63 100644 --- a/src/data/battle_partners.h +++ b/src/data/battle_partners.h @@ -1,15 +1,12 @@ const struct Trainer gBattlePartners[] = { [TRAINER_NONE] = { + .party = NULL, .trainerClass = TRAINER_CLASS_PKMN_TRAINER_1, .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_MALE, .trainerPic = TRAINER_PIC_HIKER, .trainerName = _(""), .items = {}, - .doubleBattle = FALSE, - .aiFlags = 0, - .partySize = 0, - .party = NULL, }, [PARTNER_STEVEN] = diff --git a/src/pokemon.c b/src/pokemon.c index f9cc339801bf..9d5dc67fdd6d 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8764,22 +8764,22 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) const u8 *GetTrainerClassNameFromId(u16 trainerId) { - if (trainerId >= MAX_TRAINERS_COUNT && trainerId < PARTNERS_COUNT) + if (trainerId > TRAINER_PARTNER(PARTNER_NONE)) return gTrainerClassNames[gBattlePartners[trainerId].trainerClass]; else if (trainerId < TRAINERS_COUNT) return gTrainerClassNames[gTrainers[trainerId].trainerClass]; - else - return gTrainerClassNames[gTrainers[TRAINER_NONE].trainerClass]; + + return gTrainerClassNames[gTrainers[TRAINER_NONE].trainerClass]; } const u8 *GetTrainerNameFromId(u16 trainerId) { - if (trainerId >= MAX_TRAINERS_COUNT && trainerId < PARTNERS_COUNT) + if (trainerId > TRAINER_PARTNER(PARTNER_NONE)) return gBattlePartners[trainerId].trainerName; else if (trainerId < TRAINERS_COUNT) return gTrainers[trainerId].trainerName; - else - return gTrainers[TRAINER_NONE].trainerName; + + return gTrainers[TRAINER_NONE].trainerName; } bool8 HasTwoFramesAnimation(u16 species) From fe1bad68b4e7fe37de7a33b5cdab5ef6314d1a00 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 19 Dec 2023 22:57:59 +0100 Subject: [PATCH 4/9] Use trainer partner names for id --- include/config.h | 2 +- src/battle_tower.c | 37 ++++++++++++++++++++++++------------- src/data/partner_parties.h | 1 + 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/config.h b/include/config.h index 8a6e990a5d59..d2347789f8cb 100644 --- a/include/config.h +++ b/include/config.h @@ -6,7 +6,7 @@ // still has them in the ROM. This is because the developers forgot // to define NDEBUG before release, however this has been changed as // Ruby's actual debug build does not use the AGBPrint features. -#define NDEBUG +// #define NDEBUG // To enable printf debugging, comment out "#define NDEBUG". This allows // the various AGBPrint functions to be used. (See include/gba/isagbprint.h). diff --git a/src/battle_tower.c b/src/battle_tower.c index 977c1f92f7a6..26b9054d4933 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2947,7 +2947,8 @@ void TryHideBattleTowerReporter(void) static void FillPartnerParty(u16 trainerId) { - s32 i, j; + s32 i, j, k; + u32 firstIdPart = 0, secondIdPart = 0, thridIdPart = 0; u32 ivs, level, personality; u32 friendship; u16 monId; @@ -2964,17 +2965,30 @@ static void FillPartnerParty(u16 trainerId) for (i = 0; i < 3 && i < gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].partySize; i++) { const struct TrainerMon *partyData = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].party; - u32 otIdType = OT_ID_RANDOM_NO_SHINY; + const u8 *partnerName = gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName; - if (trainerId == TRAINER_PARTNER(PARTNER_STEVEN)) + for (k = 0; partnerName[k] != EOS && k < 3; k++) { - otID = STEVEN_OTID; - otIdType = OT_ID_PRESET; + if (k == 0) + { + firstIdPart = partnerName[k]; + secondIdPart = partnerName[k]; + thridIdPart = partnerName[k]; + } + else if (k == 1) + { + secondIdPart = partnerName[k]; + thridIdPart = partnerName[k]; + } + else if (k == 2) + { + thridIdPart = partnerName[k]; + } } + if (trainerId == TRAINER_PARTNER(PARTNER_STEVEN)) + otID = STEVEN_OTID; else - otID = Random32(); - - do + otID = ((firstIdPart % 72) * 1000) + ((secondIdPart % 23) * 10) + (thridIdPart % 37) % 65536; { personality = Random32(); } while (IsShinyOtIdPersonality(otID, personality)); @@ -2986,12 +3000,9 @@ static void FillPartnerParty(u16 trainerId) if (partyData[i].nature != 0) ModifyPersonalityForNature(&personality, partyData[i].nature - 1); if (partyData[i].isShiny) - { - otIdType = OT_ID_PRESET; - otID = HIHALF(personality) ^ LOHALF(personality); - } + otID ^= GET_SHINY_VALUE(otID, personality) << 16; - CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, 0, TRUE, personality, otIdType, otID); + CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, 0, TRUE, personality, OT_ID_PRESET, otID); SetMonData(&gPlayerParty[i + 3], MON_DATA_HELD_ITEM, &partyData[i].heldItem); CustomTrainerPartyAssignMoves(&gPlayerParty[i + 3], &partyData[i]); diff --git a/src/data/partner_parties.h b/src/data/partner_parties.h index 86c9b4ccccf2..03a084721a25 100644 --- a/src/data/partner_parties.h +++ b/src/data/partner_parties.h @@ -32,6 +32,7 @@ static const struct TrainerMon sParty_MayPartner[] = { .nature = TRAINER_PARTY_NATURE(NATURE_TIMID), .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), .moves = {MOVE_ENERGY_BALL}, + .isShiny = TRUE, }, { .species = SPECIES_TORCHIC, From 0132f15b0753e685400d4c8f3ae06b75af3465be Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 19 Dec 2023 23:23:47 +0100 Subject: [PATCH 5/9] removed testing leftover --- data/scripts/debug.inc | 14 -------------- include/config.h | 2 +- include/event_scripts.h | 1 - src/data/battle_partners.h | 8 -------- src/data/partner_parties.h | 25 ------------------------- 5 files changed, 1 insertion(+), 49 deletions(-) diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 6998dae4b8dc..4d14a2a2a65b 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -96,25 +96,11 @@ Debug_BoxFilledMessage_Text: .string "Storage boxes filled!$" Debug_EventScript_Script_1:: - goto MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle end Debug_EventScript_Script_2:: - multi_fixed_2_vs_2 TRAINER_JOSH, RustboroCity_Gym_Text_JoshDefeat, TRAINER_TOMMY, RustboroCity_Gym_Text_TommyDefeat, PARTNER_MAY, TRAINER_BACK_PIC_MAY - switch VAR_RESULT - case 1, Debug_EventScript_Script_2_WonBattle - fadescreen FADE_TO_BLACK - special SetCB2WhiteOut - waitstate - -Debug_EventScript_Script_2_WonBattle: - msgbox Debug_EventScript_Text_2_WonBattle, MSGBOX_DEFAULT - closemessage end -Debug_EventScript_Text_2_WonBattle: - .string "You and your partner won!$" - Debug_EventScript_Script_3:: end diff --git a/include/config.h b/include/config.h index d2347789f8cb..8a6e990a5d59 100644 --- a/include/config.h +++ b/include/config.h @@ -6,7 +6,7 @@ // still has them in the ROM. This is because the developers forgot // to define NDEBUG before release, however this has been changed as // Ruby's actual debug build does not use the AGBPrint features. -// #define NDEBUG +#define NDEBUG // To enable printf debugging, comment out "#define NDEBUG". This allows // the various AGBPrint functions to be used. (See include/gba/isagbprint.h). diff --git a/include/event_scripts.h b/include/event_scripts.h index a5ec24774ee3..153935695900 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -615,6 +615,5 @@ extern const u8 VSSeeker_Text_BatteryNotChargedNeedXSteps[]; extern const u8 VSSeeker_Text_NoTrainersWithinRange[]; extern const u8 VSSeeker_Text_TrainersNotReady[]; extern const u8 EventScript_VsSeekerChargingDone[]; -extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle[]; #endif // GUARD_EVENT_SCRIPTS_H diff --git a/src/data/battle_partners.h b/src/data/battle_partners.h index 51034e3aca63..4e7faee388f7 100644 --- a/src/data/battle_partners.h +++ b/src/data/battle_partners.h @@ -18,12 +18,4 @@ const struct Trainer gBattlePartners[] = { .trainerName = _("STEVEN"), }, - [PARTNER_MAY] = - { - .party = TRAINER_PARTY(sParty_MayPartner), - .trainerClass = TRAINER_CLASS_RIVAL, - .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_FEMALE, - .trainerPic = TRAINER_BACK_PIC_MAY, - .trainerName = _("MAY"), - }, }; diff --git a/src/data/partner_parties.h b/src/data/partner_parties.h index 03a084721a25..fec80c6ca11c 100644 --- a/src/data/partner_parties.h +++ b/src/data/partner_parties.h @@ -24,28 +24,3 @@ static const struct TrainerMon sParty_StevenPartner[] = { .moves = {MOVE_THUNDER, MOVE_PROTECT, MOVE_SOLAR_BEAM, MOVE_DRAGON_CLAW}, } }; - -static const struct TrainerMon sParty_MayPartner[] = { - { - .species = SPECIES_TREECKO, - .lvl = 20, - .nature = TRAINER_PARTY_NATURE(NATURE_TIMID), - .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), - .moves = {MOVE_ENERGY_BALL}, - .isShiny = TRUE, - }, - { - .species = SPECIES_TORCHIC, - .lvl = 20, - .nature = TRAINER_PARTY_NATURE(NATURE_MODEST), - .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), - .moves = {MOVE_FLAMETHROWER}, - }, - { - .species = SPECIES_MUDKIP, - .lvl = 20, - .nature = TRAINER_PARTY_NATURE(NATURE_ADAMANT), - .iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31), - .moves = {MOVE_WATERFALL}, - } -}; From b1774ecbe3cde49653d35c53a499281368d0addc Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 19 Dec 2023 23:27:20 +0100 Subject: [PATCH 6/9] comment change --- src/battle_controller_player_partner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 02b141ba02f4..8f989c677d7b 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -316,7 +316,7 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler) yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80; } - // Use back pic only if the partner is custom. + // Use back pic only if the partner Steven or is custom. if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE)) isFrontPic = FALSE; else From 94b3cdb39620eeda94ff1fbe69f31b5b6af4541a Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Dec 2023 00:10:48 +0100 Subject: [PATCH 7/9] more review changes --- include/constants/battle_partner.h | 3 +-- include/constants/opponents.h | 1 - src/battle_tower.c | 8 ++++---- src/data/battle_partners.h | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/constants/battle_partner.h b/include/constants/battle_partner.h index c51872ace5d9..f81c452118ca 100644 --- a/include/constants/battle_partner.h +++ b/include/constants/battle_partner.h @@ -4,8 +4,7 @@ #define PARTNER_NONE 0 #define PARTNER_STEVEN 1 -#define PARTNER_MAY 2 -#define PARTNERS_COUNT 3 +#define PARTNERS_COUNT 1 #endif // GUARD_CONSTANTS_BATTLE_PARTNERS_H diff --git a/include/constants/opponents.h b/include/constants/opponents.h index 47b633cd499e..9e7131077c3b 100644 --- a/include/constants/opponents.h +++ b/include/constants/opponents.h @@ -867,5 +867,4 @@ #define MAX_TRAINERS_COUNT 864 #define TRAINER_PARTNER(partner) (MAX_TRAINERS_COUNT + partner) - #endif // GUARD_CONSTANTS_OPPONENTS_H diff --git a/src/battle_tower.c b/src/battle_tower.c index 26b9054d4933..10e89085f332 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2948,7 +2948,7 @@ void TryHideBattleTowerReporter(void) static void FillPartnerParty(u16 trainerId) { s32 i, j, k; - u32 firstIdPart = 0, secondIdPart = 0, thridIdPart = 0; + u32 firstIdPart = 0, secondIdPart = 0, thirdIdPart = 0; u32 ivs, level, personality; u32 friendship; u16 monId; @@ -2973,16 +2973,16 @@ static void FillPartnerParty(u16 trainerId) { firstIdPart = partnerName[k]; secondIdPart = partnerName[k]; - thridIdPart = partnerName[k]; + thirdIdPart = partnerName[k]; } else if (k == 1) { secondIdPart = partnerName[k]; - thridIdPart = partnerName[k]; + thirdIdPart = partnerName[k]; } else if (k == 2) { - thridIdPart = partnerName[k]; + thirdIdPart = partnerName[k]; } } if (trainerId == TRAINER_PARTNER(PARTNER_STEVEN)) diff --git a/src/data/battle_partners.h b/src/data/battle_partners.h index 4e7faee388f7..806a50bdf6e5 100644 --- a/src/data/battle_partners.h +++ b/src/data/battle_partners.h @@ -1,5 +1,5 @@ const struct Trainer gBattlePartners[] = { - [TRAINER_NONE] = + [PARTNER_NONE] = { .party = NULL, .trainerClass = TRAINER_CLASS_PKMN_TRAINER_1, From 247d21d4563a70910a2668c60d755ddac66f5c02 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Dec 2023 00:29:45 +0100 Subject: [PATCH 8/9] fix compiling --- src/battle_tower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_tower.c b/src/battle_tower.c index 10e89085f332..015f6d207f34 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2988,7 +2988,7 @@ static void FillPartnerParty(u16 trainerId) if (trainerId == TRAINER_PARTNER(PARTNER_STEVEN)) otID = STEVEN_OTID; else - otID = ((firstIdPart % 72) * 1000) + ((secondIdPart % 23) * 10) + (thridIdPart % 37) % 65536; + otID = ((firstIdPart % 72) * 1000) + ((secondIdPart % 23) * 10) + (thirdIdPart % 37) % 65536; { personality = Random32(); } while (IsShinyOtIdPersonality(otID, personality)); From b621c5494588970c8a1c015f23cfb6903e85331c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Dec 2023 11:47:21 +0100 Subject: [PATCH 9/9] remove partener count --- include/constants/battle_partner.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/constants/battle_partner.h b/include/constants/battle_partner.h index f81c452118ca..5622349a888c 100644 --- a/include/constants/battle_partner.h +++ b/include/constants/battle_partner.h @@ -5,6 +5,4 @@ #define PARTNER_NONE 0 #define PARTNER_STEVEN 1 -#define PARTNERS_COUNT 1 - #endif // GUARD_CONSTANTS_BATTLE_PARTNERS_H