From 57b2bef08987074782eddf68674fc492599c3e3f Mon Sep 17 00:00:00 2001 From: laserXdolphin <107103137+laserXdolphin@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:06:38 +0200 Subject: [PATCH 1/5] Implemented "Earn battle points from trainer battles (with a variable)" from ScyrousFX https://www.pokecommunity.com/showpost.php?p=10422051 --- data/battle_scripts_1.s | 6 ++++++ include/config/overworld.h | 1 + include/constants/battle_string_ids.h | 3 ++- include/field_specials.h | 1 + src/battle_message.c | 2 ++ src/battle_script_commands.c | 29 +++++++++++++++++++-------- src/battle_setup.c | 5 +++++ 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 9d0bc6fc1f04..c510d3c74664 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5612,7 +5612,13 @@ BattleScript_LocalBattleWonLoseTexts:: trainerslidein BS_FAINTED waitstate printstring STRINGID_TRAINER2LOSETEXT +BattleScript_LocalBattleWonBP:: + getmoneyreward + printstring STRINGID_PLAYERGOTBP + waitmessage B_WAIT_TIME_LONG + end2 BattleScript_LocalBattleWonReward:: + jumpifbyte CMP_EQUAL, gSpecialVar_0x8003, 1, BattleScript_LocalBattleWonBP getmoneyreward printstring STRINGID_PLAYERGOTMONEY waitmessage B_WAIT_TIME_LONG diff --git a/include/config/overworld.h b/include/config/overworld.h index b6664269960c..b56edbf327a4 100644 --- a/include/config/overworld.h +++ b/include/config/overworld.h @@ -75,6 +75,7 @@ #define OW_FLAG_NO_COLLISION 0 // If this flag is set, the player will be able to walk over tiles with collision. Mainly intended for debugging purposes. #define BATTLE_PYRAMID_RANDOM_ENCOUNTERS FALSE // If set to TRUE, battle pyramid Pokemon will be generated randomly based on the round's challenge instead of hardcoded in src/data/battle_frontier/battle_pyramid_level_50_wild_mons.h (or open_level_wild_mons.h) +#define BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS FALSE // If set to TRUE, battle frontier intros will be played before a fight where a player can earn BP // Map pop-up config #define OW_POPUP_GENERATION GEN_3 // Different generations display location names in overworld pop-ups differently. diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index 9fbb70a22397..fc8dcc644933 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -712,8 +712,9 @@ #define STRINGID_FOGLIFTED 710 #define STRINGID_PKMNMADESHELLGLEAM 711 #define STRINGID_FICKLEBEAMDOUBLED 712 +#define STRINGID_PLAYERGOTBP 713 -#define BATTLESTRINGS_COUNT 713 +#define BATTLESTRINGS_COUNT 714 // This is the string id that gBattleStringsTable starts with. // String ids before this (e.g. STRINGID_INTROMSG) are not in the table, diff --git a/include/field_specials.h b/include/field_specials.h index 95a91d543f06..a1d78ec3d44b 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -33,5 +33,6 @@ void ResetFanClub(void); bool8 ShouldShowBoxWasFullMessage(void); void SetPCBoxToSendMon(u8 boxId); void PreparePartyForSkyBattle(void); +void GiveFrontierBattlePoints(void); #endif // GUARD_FIELD_SPECIALS_H diff --git a/src/battle_message.c b/src/battle_message.c index ecb2932124a3..55f2c83de70b 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -78,6 +78,7 @@ static const u8 sText_ItDoesntAffect[] = _("It doesn't affect\n{B_DEF_NAME_WITH_ static const u8 sText_AttackerFainted[] = _("{B_ATK_NAME_WITH_PREFIX}\nfainted!\p"); static const u8 sText_TargetFainted[] = _("{B_DEF_NAME_WITH_PREFIX}\nfainted!\p"); static const u8 sText_PlayerGotMoney[] = _("{B_PLAYER_NAME} got ¥{B_BUFF1}\nfor winning!\p"); +static const u8 sText_PlayerGotBP[] = _("{B_PLAYER_NAME} got {B_BUFF1} Battle Point(s)\nfor winning!\p"); static const u8 sText_PlayerLostToEnemyTrainer[] = _("{B_PLAYER_NAME} is out of\nusable POKéMON!\pPlayer lost against\n{B_TRAINER1_CLASS} {B_TRAINER1_NAME}!{PAUSE_UNTIL_PRESS}"); static const u8 sText_PlayerPaidPrizeMoney[] = _("{B_PLAYER_NAME} paid ¥{B_BUFF1} as the prize\nmoney…\p… … … …\p{B_PLAYER_NAME} whited out!{PAUSE_UNTIL_PRESS}"); static const u8 sText_PlayerWhiteout[] = _("{B_PLAYER_NAME} is out of\nusable POKéMON!\p"); @@ -1018,6 +1019,7 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = [STRINGID_ATTACKERFAINTED - BATTLESTRINGS_TABLE_START] = sText_AttackerFainted, [STRINGID_TARGETFAINTED - BATTLESTRINGS_TABLE_START] = sText_TargetFainted, [STRINGID_PLAYERGOTMONEY - BATTLESTRINGS_TABLE_START] = sText_PlayerGotMoney, + [STRINGID_PLAYERGOTBP - BATTLESTRINGS_TABLE_START] = sText_PlayerGotBP, [STRINGID_PLAYERWHITEOUT - BATTLESTRINGS_TABLE_START] = sText_PlayerWhiteout, [STRINGID_PLAYERWHITEOUT2 - BATTLESTRINGS_TABLE_START] = sText_PlayerWhiteout2, [STRINGID_PREVENTSESCAPE - BATTLESTRINGS_TABLE_START] = sText_PreventsEscape, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9e1af78714bc..7e3e89da7575 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7756,11 +7756,17 @@ static void Cmd_getmoneyreward(void) u8 sPartyLevel = 1; if (gBattleOutcome == B_OUTCOME_WON) - { - money = GetTrainerMoneyToGive(gTrainerBattleOpponent_A); - if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) - money += GetTrainerMoneyToGive(gTrainerBattleOpponent_B); - AddMoney(&gSaveBlock1Ptr->money, money); + { + if (VarGet(gSpecialVar_0x8003) == 1) + { + GiveFrontierBattlePoints(); + } + else{ + money = GetTrainerMoneyToGive(gTrainerBattleOpponent_A); + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) + money += GetTrainerMoneyToGive(gTrainerBattleOpponent_B); + AddMoney(&gSaveBlock1Ptr->money, money); + } } else { @@ -7768,7 +7774,7 @@ static void Cmd_getmoneyreward(void) for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_NONE - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_EGG) + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_EGG) { if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) > sPartyLevel) sPartyLevel = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); @@ -7782,8 +7788,15 @@ static void Cmd_getmoneyreward(void) money = sWhiteOutBadgeMoney[count] * sPartyLevel; RemoveMoney(&gSaveBlock1Ptr->money, money); } - - PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, money); + + if (VarGet(gSpecialVar_0x8003) == 1) + { + PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 3, gSpecialVar_0x8004); + gSpecialVar_0x8003 = 0; + gSpecialVar_0x8004 = 0;} + else{ + PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, money); + } gBattlescriptCurrInstr = cmd->nextInstr; } diff --git a/src/battle_setup.c b/src/battle_setup.c index 54c4f99b9289..c7b6ebf1d335 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -899,6 +899,11 @@ u8 GetTrainerBattleTransition(void) u32 trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + #if BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS + if (VarGet(gSpecialVar_0x8003) == 1) + return GetSpecialBattleTransition(FRONTIER_MODE_DOUBLES); + #endif + if (DoesTrainerHaveMugshot(trainerId)) return B_TRANSITION_MUGSHOT; From d0ba200ec5809d0da30c16df693f76be2b483889 Mon Sep 17 00:00:00 2001 From: laserXdolphin <107103137+laserXdolphin@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:42:57 +0200 Subject: [PATCH 2/5] Fixed "money may be used uninitialized" warning --- src/battle_script_commands.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 7e3e89da7575..8b3697ba4dee 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7754,11 +7754,14 @@ static void Cmd_getmoneyreward(void) u32 money; u8 sPartyLevel = 1; + u8 b_buff_number = 5; if (gBattleOutcome == B_OUTCOME_WON) { if (VarGet(gSpecialVar_0x8003) == 1) { + money = gSpecialVar_0x8004; + b_buff_number = 3; GiveFrontierBattlePoints(); } else{ @@ -7791,12 +7794,11 @@ static void Cmd_getmoneyreward(void) if (VarGet(gSpecialVar_0x8003) == 1) { - PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 3, gSpecialVar_0x8004); gSpecialVar_0x8003 = 0; - gSpecialVar_0x8004 = 0;} - else{ - PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, money); + gSpecialVar_0x8004 = 0; } + + PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, b_buff_number, money); gBattlescriptCurrInstr = cmd->nextInstr; } From 39cd584cd59fe1aedf679231a6a47ca362178116 Mon Sep 17 00:00:00 2001 From: laserXdolphin <107103137+laserXdolphin@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:26:13 +0200 Subject: [PATCH 3/5] Turned preproc block into normal if statement --- src/battle_setup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/battle_setup.c b/src/battle_setup.c index c7b6ebf1d335..d18a4b528518 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -899,10 +899,8 @@ u8 GetTrainerBattleTransition(void) u32 trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); - #if BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS - if (VarGet(gSpecialVar_0x8003) == 1) + if (VarGet(gSpecialVar_0x8003) == 1 && BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS) return GetSpecialBattleTransition(FRONTIER_MODE_DOUBLES); - #endif if (DoesTrainerHaveMugshot(trainerId)) return B_TRANSITION_MUGSHOT; From aab9fa87d20896e835a25423ef11de1b9db180da Mon Sep 17 00:00:00 2001 From: laserXdolphin <107103137+laserXdolphin@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:36:02 +0200 Subject: [PATCH 4/5] Switched if condition parts such that the config is checked first. --- src/battle_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_setup.c b/src/battle_setup.c index d18a4b528518..59137cf4b24a 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -899,7 +899,7 @@ u8 GetTrainerBattleTransition(void) u32 trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); - if (VarGet(gSpecialVar_0x8003) == 1 && BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS) + if (BATTLE_FRONTIER_INTRO_FOR_BP_FIGHTS && VarGet(gSpecialVar_0x8003) == 1) return GetSpecialBattleTransition(FRONTIER_MODE_DOUBLES); if (DoesTrainerHaveMugshot(trainerId)) From 9b0135aef1709a881e9b4145e4a33d3e4cfbf9f1 Mon Sep 17 00:00:00 2001 From: laserXdolphin <107103137+laserXdolphin@users.noreply.github.com> Date: Sat, 31 Aug 2024 08:56:49 +0200 Subject: [PATCH 5/5] Reverted to correct alingment --- src/battle_script_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 8b3697ba4dee..53ea240e0ff4 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7777,7 +7777,7 @@ static void Cmd_getmoneyreward(void) for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_NONE - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_EGG) + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG) != SPECIES_EGG) { if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) > sPartyLevel) sPartyLevel = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL);