From 204748e01ac859094652370cf296866298de3db2 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 28 Oct 2021 17:52:52 -0400 Subject: [PATCH] fix recycle and harvest --- data/battle_scripts_1.s | 2 ++ include/battle.h | 2 +- include/battle_util.h | 1 + src/battle_ai_main.c | 8 ++++---- src/battle_main.c | 5 ++++- src/battle_script_commands.c | 8 ++++---- src/battle_util.c | 11 +++++++---- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5b1048e7b..70f2d5fb1 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -7490,9 +7490,11 @@ BattleScript_CheekPouchActivates:: BattleScript_HarvestActivates:: pause 5 + tryrecycleitem BattleScript_HarvestActivatesEnd call BattleScript_AbilityPopUp printstring STRINGID_HARVESTBERRY waitmessage B_WAIT_TIME_LONG +BattleScript_HarvestActivatesEnd: end3 BattleScript_SolarPowerActivates:: diff --git a/include/battle.h b/include/battle.h index 5077053e3..5e5aa2479 100644 --- a/include/battle.h +++ b/include/battle.h @@ -547,7 +547,7 @@ struct BattleStruct u16 synchronizeMoveEffect; bool8 anyMonHasTransformed; void (*savedCallback)(void); - u16 usedHeldItems[MAX_BATTLERS_COUNT]; + u16 usedHeldItems[PARTY_SIZE][2]; // For each party member and side. For harvest, recycle u16 chosenItem[MAX_BATTLERS_COUNT]; u8 AI_itemType[2]; u8 AI_itemFlags[2]; diff --git a/include/battle_util.h b/include/battle_util.h index ee7337ef2..d98c511e2 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -155,6 +155,7 @@ bool32 TryRoomService(u8 battlerId); void BufferStatChange(u8 battlerId, u8 statId, u8 stringId); void DoBurmyFormChange(u32 monId); bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 checkTarget); +u16 GetUsedHeldItem(u8 battler); // ability checks bool32 IsRolePlayBannedAbilityAtk(u16 ability); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index b8ed21e9d..84fa7b634 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1530,7 +1530,7 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) score -= 10; break; case EFFECT_RECYCLE: - if (gBattleStruct->usedHeldItems[battlerAtk] == 0 || gBattleMons[battlerAtk].item != 0) + if (GetUsedHeldItem(battlerAtk) == 0 || gBattleMons[battlerAtk].item != 0) score -= 10; break; case EFFECT_IMPRISON: @@ -1951,7 +1951,7 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) score -= 10; break; case EFFECT_BELCH: - if (ItemId_GetPocket(gBattleStruct->usedHeldItems[battlerAtk]) != POCKET_BERRIES) + if (ItemId_GetPocket(GetUsedHeldItem(battlerAtk)) != POCKET_BERRIES) score -= 10; // attacker has not consumed a berry break; case EFFECT_YAWN: @@ -4097,9 +4097,9 @@ static s16 AI_CheckViability(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) score += 3; break; case EFFECT_RECYCLE: - if (gBattleStruct->usedHeldItems[battlerAtk] != ITEM_NONE) + if (GetUsedHeldItem(battlerAtk) != ITEM_NONE) score++; - if (IsRecycleEncouragedItem(gBattleStruct->usedHeldItems[battlerAtk])) + if (IsRecycleEncouragedItem(GetUsedHeldItem(battlerAtk))) score++; break; case EFFECT_BRICK_BREAK: diff --git a/src/battle_main.c b/src/battle_main.c index 271e97731..2cc3f5e2d 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2862,7 +2862,6 @@ static void BattleStartClearSetData(void) gBattleResources->flags->flags[i] = 0; gPalaceSelectionBattleScripts[i] = 0; gBattleStruct->lastTakenMove[i] = 0; - gBattleStruct->usedHeldItems[i] = 0; gBattleStruct->choicedMove[i] = 0; gBattleStruct->changedItems[i] = 0; gBattleStruct->lastTakenMoveFrom[i][0] = 0; @@ -2935,7 +2934,11 @@ static void BattleStartClearSetData(void) gBattleStruct->mega.triggerSpriteId = 0xFF; for (i = 0; i < PARTY_SIZE; i++) + { + gBattleStruct->usedHeldItems[i][0] = 0; + gBattleStruct->usedHeldItems[i][1] = 0; gBattleStruct->itemStolen[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + } } void SwitchInClearSetData(void) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e41f0982a..ca0ceb749 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6796,10 +6796,10 @@ static void Cmd_removeitem(void) gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); itemId = gBattleMons[gActiveBattler].item; - // Popped Air Balloon cannot be restored by no means. + // Popped Air Balloon cannot be restored by any means. if (GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_AIR_BALLOON) - gBattleStruct->usedHeldItems[gActiveBattler] = itemId; - + gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)] = itemId; // Remember if switched out + gBattleMons[gActiveBattler].item = 0; CheckSetUnburden(gActiveBattler); @@ -12547,7 +12547,7 @@ static void Cmd_tryrecycleitem(void) u16 *usedHeldItem; gActiveBattler = gBattlerAttacker; - usedHeldItem = &gBattleStruct->usedHeldItems[gActiveBattler]; + usedHeldItem = &gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)]; if (*usedHeldItem != 0 && gBattleMons[gActiveBattler].item == 0) { gLastUsedItem = *usedHeldItem; diff --git a/src/battle_util.c b/src/battle_util.c index 275139f4f..ca280a722 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4373,11 +4373,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move case ABILITY_HARVEST: if (((WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SUN_ANY) || Random() % 2 == 0) && gBattleMons[battler].item == ITEM_NONE - && gBattleStruct->changedItems[battler] == ITEM_NONE - && ItemId_GetPocket(gBattleStruct->usedHeldItems[battler]) == POCKET_BERRIES) + && gBattleStruct->changedItems[battler] == ITEM_NONE // Will not inherit an item + && ItemId_GetPocket(GetUsedHeldItem(battler)) == POCKET_BERRIES) { - gLastUsedItem = gBattleStruct->changedItems[battler] = gBattleStruct->usedHeldItems[battler]; - gBattleStruct->usedHeldItems[battler] = ITEM_NONE; BattleScriptPushCursorAndCallback(BattleScript_HarvestActivates); effect++; } @@ -9519,3 +9517,8 @@ bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 chec #endif return FALSE; } + +u16 GetUsedHeldItem(u8 battler) +{ + return gBattleStruct->usedHeldItems[gBattlerPartyIndexes[battler]][GetBattlerSide(battler)]; +}