From 3aec63b8cfb23b0983b92ba03e89c31db84b20a1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 20 Apr 2023 15:08:42 +0200 Subject: [PATCH] new define to restore items after battle --- include/battle.h | 4 ++-- include/battle_util.h | 2 +- include/config/battle.h | 1 + src/battle_main.c | 6 +++--- src/battle_script_commands.c | 14 +++++++------- src/battle_util.c | 18 ++++++++++-------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/battle.h b/include/battle.h index 46975bec3..f86a5c975 100644 --- a/include/battle.h +++ b/include/battle.h @@ -517,7 +517,7 @@ struct ZMoveData u8 splits[MAX_BATTLERS_COUNT]; }; -struct StolenItem +struct LostItem { u16 originalItem:15; u16 stolen:1; @@ -640,7 +640,7 @@ struct BattleStruct u16 moveEffect2; // For Knock Off u16 changedSpecies[PARTY_SIZE]; // For Zygarde or future forms when multiple mons can change into the same pokemon. u8 quickClawBattlerId; - struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member) + struct LostItem itemLost[PARTY_SIZE]; // Player's team that had items consumed or stolen (two bytes per party member) u8 blunderPolicy:1; // should blunder policy activate u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky u8 forcedSwitch:4; // For each battler diff --git a/include/battle_util.h b/include/battle_util.h index 0661081e4..b83209a69 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -197,7 +197,7 @@ bool32 IsPartnerMonFromSameTrainer(u8 battlerId); u8 GetSplitBasedOnStats(u8 battlerId); void SortBattlersBySpeed(u8 *battlers, bool8 slowToFast); bool32 TestSheerForceFlag(u8 battler, u16 move); -void TryRestoreStolenItems(void); +void TryRestoreHeldItems(void); bool32 CanStealItem(u8 battlerStealing, u8 battlerItem, u16 item); void TrySaveExchangedItem(u8 battlerId, u16 stolenItem); bool32 IsPartnerMonFromSameTrainer(u8 battlerId); diff --git a/include/config/battle.h b/include/config/battle.h index 3e9ec9b9a..4bead3ae8 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -126,6 +126,7 @@ #define B_X_ITEMS_BUFF GEN_LATEST // In Gen7+, the X Items raise a stat by 2 stages instead of 1. #define B_MENTAL_HERB GEN_LATEST // In Gen5+, the Mental Herb cures Taunt, Encore, Torment, Heal Block, and Disable in addition to Infatuation from before. #define B_TRAINERS_KNOCK_OFF_ITEMS TRUE // If TRUE, trainers can steal/swap your items (non-berries are restored after battle). In vanilla games trainers cannot steal items. +#define B_RESTORE_HELD_BATTLE_ITEMS TRUE // In Gen9 all non berry items are restored after battle. #define B_SOUL_DEW_BOOST GEN_LATEST // In Gens3-6, Soul Dew boosts Lati@s' Sp. Atk and Sp. Def. In Gen7+ it boosts the power of their Psychic and Dragon type moves instead. #define B_NET_BALL_MODIFIER GEN_LATEST // In Gen7+, Net Ball's catch multiplier is x5 instead of x3. #define B_DIVE_BALL_MODIFIER GEN_LATEST // In Gen4+, Dive Ball's effectiveness increases by when Surfing or Fishing. diff --git a/src/battle_main.c b/src/battle_main.c index a5a9b5bbf..01d79db3e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3189,7 +3189,7 @@ static void BattleStartClearSetData(void) { gBattleStruct->usedHeldItems[i][B_SIDE_PLAYER] = 0; gBattleStruct->usedHeldItems[i][B_SIDE_OPPONENT] = 0; - gBattleStruct->itemStolen[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + gBattleStruct->itemLost[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); gPartyCriticalHits[i] = 0; gBattleStruct->allowedToChangeFormInWeather[i][B_SIDE_PLAYER] = FALSE; gBattleStruct->allowedToChangeFormInWeather[i][B_SIDE_OPPONENT] = FALSE; @@ -5387,9 +5387,9 @@ static void HandleEndTurn_FinishBattle(void) TestRunner_Battle_AfterLastTurn(); BeginFastPaletteFade(3); FadeOutMapMusic(5); - #if B_TRAINERS_KNOCK_OFF_ITEMS == TRUE + #if B_TRAINERS_KNOCK_OFF_ITEMS == TRUE || B_RESTORE_HELD_BATTLE_ITEMS == TRUE if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) - TryRestoreStolenItems(); + TryRestoreHeldItems(); #endif for (i = 0; i < PARTY_SIZE; i++) { diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4e1494ce3..228cbb812 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7892,7 +7892,7 @@ static void BestowItem(u32 battlerAtk, u32 battlerDef) // Called by Cmd_removeitem. itemId represents the item that was removed, not being given. static bool32 TrySymbiosis(u32 battler, u32 itemId) { - if (!gBattleStruct->itemStolen[gBattlerPartyIndexes[battler]].stolen + if (!gBattleStruct->itemLost[gBattlerPartyIndexes[battler]].stolen && gBattleStruct->changedItems[battler] == ITEM_NONE && GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_EJECT_BUTTON && GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_EJECT_PACK @@ -11264,7 +11264,7 @@ static void Cmd_various(void) // Open party menu, wait to go to next instruction. else - { + { BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_FAINTED_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gBattlerAttacker]); MarkBattlerForControllerExec(gBattlerAttacker); } @@ -16469,7 +16469,7 @@ void BS_ItemRestoreHP(void) { } if (hp + healAmount > maxHP) healAmount = maxHP - hp; - + // Heal is applied as move damage if battler is active. if (battlerId != MAX_BATTLERS_COUNT && hp != 0) { @@ -16494,10 +16494,10 @@ void BS_ItemRestoreHP(void) { void BS_ItemCureStatus(void) { NATIVE_ARGS(); struct Pokemon *party = (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; - + // Heal Status1 conditions. HealStatusConditions(&party[gBattleStruct->itemPartyIndex[gBattlerAttacker]], gBattleStruct->itemPartyIndex[gBattlerAttacker], GetItemStatus1Mask(gLastUsedItem), gBattlerAttacker); - + // Heal Status2 conditions if battler is active. if (gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[gBattlerAttacker]) { @@ -16506,10 +16506,10 @@ void BS_ItemCureStatus(void) { else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerAttacker)]) { - gBattleMons[gBattlerAttacker].status2 &= ~GetItemStatus2Mask(gLastUsedItem); + gBattleMons[gBattlerAttacker].status2 &= ~GetItemStatus2Mask(gLastUsedItem); gBattlerTarget = BATTLE_PARTNER(gBattlerAttacker); } - + if (GetItemStatus1Mask(gLastUsedItem) & STATUS1_SLEEP) gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; diff --git a/src/battle_util.c b/src/battle_util.c index ac274bf0f..e057b78dc 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10536,18 +10536,20 @@ void SortBattlersBySpeed(u8 *battlers, bool8 slowToFast) } } -void TryRestoreStolenItems(void) +void TryRestoreHeldItems(void) { u32 i; - u16 stolenItem = ITEM_NONE; + u16 lostItem = ITEM_NONE; for (i = 0; i < PARTY_SIZE; i++) { - if (gBattleStruct->itemStolen[i].stolen) + #if B_RESTORE_HELD_BATTLE_ITEMS == FALSE + if (gBattleStruct->itemLost[i].stolen) + #endif { - stolenItem = gBattleStruct->itemStolen[i].originalItem; - if (stolenItem != ITEM_NONE && ItemId_GetPocket(stolenItem) != POCKET_BERRIES) - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &stolenItem); // Restore stolen non-berry items + lostItem = gBattleStruct->itemLost[i].originalItem; + if (lostItem != ITEM_NONE && ItemId_GetPocket(lostItem) != POCKET_BERRIES) + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &lostItem); // Restore stolen non-berry items } } } @@ -10601,8 +10603,8 @@ void TrySaveExchangedItem(u8 battlerId, u16 stolenItem) if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & BATTLE_TYPE_FRONTIER) && GetBattlerSide(battlerId) == B_SIDE_PLAYER - && stolenItem == gBattleStruct->itemStolen[gBattlerPartyIndexes[battlerId]].originalItem) - gBattleStruct->itemStolen[gBattlerPartyIndexes[battlerId]].stolen = TRUE; + && stolenItem == gBattleStruct->itemLost[gBattlerPartyIndexes[battlerId]].originalItem) + gBattleStruct->itemLost[gBattlerPartyIndexes[battlerId]].stolen = TRUE; #endif }