diff options
author | LOuroboros <lunosouroboros@gmail.com> | 2021-09-26 06:13:56 -0300 |
---|---|---|
committer | LOuroboros <lunosouroboros@gmail.com> | 2021-09-26 06:13:56 -0300 |
commit | b8b163729df0cbc8cfe8303af5185225c3924f2c (patch) | |
tree | f7eac3380845540448b781975dfd51158ed4be39 | |
parent | 9abb1cdf4d3439e78edaed0a06968af84e2e1969 (diff) |
Replaced gMaxPartyLevel with a local variable instead. There isn't a reason to add a EWRAM variable when one could just do make `GetSumOfPlayerPartyLevel` non-static and pass `CalculatePlayerPartyCount()` through it.`
-rw-r--r-- | Better-White-Out-Money-Calculation.md | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/Better-White-Out-Money-Calculation.md b/Better-White-Out-Money-Calculation.md index 623ff8d..ba5f2c5 100644 --- a/Better-White-Out-Money-Calculation.md +++ b/Better-White-Out-Money-Calculation.md @@ -77,11 +77,9 @@ You can guess what are we going to change next, can't you? ## 3. Modifying the `Cmd_getmoneyreward` function Now we want to open **[src/battle_script_commands.c](https://github.com/pret/pokeemerald/blob/master/src/battle_script_commands.c)**. -Before anything, we have to define a new variable and 2 array lists that we're going to use soon enough. +Before anything, we have to define 2 array lists that we're going to use soon enough. ```diff -+extern u8 gMaxPartyLevel; - +static const u16 sBadgeFlags[8] = { + FLAG_BADGE01_GET, FLAG_BADGE02_GET, FLAG_BADGE03_GET, FLAG_BADGE04_GET, + FLAG_BADGE05_GET, FLAG_BADGE06_GET, FLAG_BADGE07_GET, FLAG_BADGE08_GET, @@ -103,6 +101,7 @@ static void Cmd_getmoneyreward(void) - if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) - moneyReward += GetTrainerMoneyToGive(gTrainerBattleOpponent_B); + u32 money; ++ u8 sPartyLevel = 1; - AddMoney(&gSaveBlock1Ptr->money, moneyReward); - PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, moneyReward); @@ -121,8 +120,8 @@ static void Cmd_getmoneyreward(void) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) + { -+ if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) > gMaxPartyLevel) -+ gMaxPartyLevel = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); ++ if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) > sPartyLevel) ++ sPartyLevel = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); + } + } + for (count = 0, i = 0; i < ARRAY_COUNT(sBadgeFlags); i++) @@ -130,27 +129,17 @@ static void Cmd_getmoneyreward(void) + if (FlagGet(sBadgeFlags[i]) == TRUE) + ++count; + } -+ money = sWhiteOutBadgeMoney[count] * gMaxPartyLevel; ++ money = sWhiteOutBadgeMoney[count] * sPartyLevel; + RemoveMoney(&gSaveBlock1Ptr->money, money); + } -+ PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, money); ++ PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff1, 5, money); gBattlescriptCurrInstr++; } ``` Here, we're making `Cmd_getmoneyreward` handle not only the money calculation for winning a battle, but we're also making it calculate how much money should be removed from the Player when they lose a battle, and then we're storing that amount in a buffer to display it in the `STRINGID_PLAYERPAIDPRIZEMONEY` we added earlier. -As you can see, we're introducing a new extern variable; `gMaxPartyLevel`. - -As this variable plays a central role in `Cmd_getmoneyreward` which is a function that can only be triggered In Battle, we have to make the battle system recognize it. - -To do that, we'll visit the **[src/battle_main.c](https://github.com/pret/pokeemerald/blob/master/src/battle_main.c)** file and throw it in at the end of the EWRAM vars list like so: - -```diff -+EWRAM_DATA u8 gMaxPartyLevel = 1; -``` - ## 4. Modifying the `DoWhiteOut` function This function which can be found in the **[src/overworld.c file](https://github.com/pret/pokeemerald/blob/master/src/overworld.c)** is always triggered whenever you lose a battle and it's also in charge of cutting the Player's money by half whenever they lose a battle, as you can easily tell by reading it. |