diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 135960c12..1de63ad16 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1760,6 +1760,11 @@ various BS_ABILITY_BATTLER, VARIOUS_DESTROY_ABILITY_POPUP .endm + .macro doterrainseed battler:req, ptr:req + various \battler, VARIOUS_TERRAIN_SEED + .4byte \ptr + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 14751559e..40f4d0d93 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1520,6 +1520,7 @@ BattleScript_EffectPsychicTerrain: waitanimation printfromtable gTerrainStringIds waitmessage 0x40 + call BattleScript_TerrainSeedLoop goto BattleScript_MoveEnd BattleScript_EffectTopsyTurvy: @@ -1862,10 +1863,6 @@ RoomServiceLoop: playanimation BS_TARGET, B_ANIM_HELD_ITEM_EFFECT, NULL waitanimation playstatchangeanimation BS_TARGET, BIT_SPEED, STAT_CHANGE_NEGATIVE - -@ setgraphicalstatchangevalues -@ playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 -@ waitanimation printstring STRINGID_USINGXTHEYOFZN waitmessage 0x40 removeitem BS_TARGET @@ -6882,6 +6879,19 @@ BattleScript_SnowWarningActivates:: playanimation BS_BATTLER_0, B_ANIM_HAIL_CONTINUES, NULL call BattleScript_WeatherFormChanges end3 + +BattleScript_TerrainSeedLoop: + savetarget + setbyte gBattlerTarget, 0 +TerrainSeedLoop: + copybyte sBATTLER, gBattlerTarget + doterrainseed BS_TARGET, TerrainSeedLoop_NextBattler + removeitem BS_TARGET +TerrainSeedLoop_NextBattler: + addbyte gBattlerTarget, 0x1 + jumpifbytenotequal gBattlerTarget, gBattlersCount, TerrainSeedLoop + restoretarget + return BattleScript_ElectricSurgeActivates:: pause 0x20 @@ -6889,6 +6899,7 @@ BattleScript_ElectricSurgeActivates:: printstring STRINGID_TERRAINBECOMESELECTRIC waitstate playanimation BS_SCRIPTING, B_ANIM_TERRAIN_ELECTRIC, NULL + call BattleScript_TerrainSeedLoop end3 BattleScript_MistySurgeActivates:: @@ -6897,6 +6908,7 @@ BattleScript_MistySurgeActivates:: printstring STRINGID_TERRAINBECOMESMISTY waitstate playanimation BS_SCRIPTING, B_ANIM_TERRAIN_MISTY, NULL + call BattleScript_TerrainSeedLoop end3 BattleScript_GrassySurgeActivates:: @@ -6905,6 +6917,7 @@ BattleScript_GrassySurgeActivates:: printstring STRINGID_TERRAINBECOMESGRASSY waitstate playanimation BS_SCRIPTING, B_ANIM_TERRAIN_GRASSY, NULL + call BattleScript_TerrainSeedLoop end3 BattleScript_PsychicSurgeActivates:: @@ -6913,6 +6926,7 @@ BattleScript_PsychicSurgeActivates:: printstring STRINGID_TERRAINBECOMESPSYCHIC waitstate playanimation BS_SCRIPTING, B_ANIM_TERRAIN_PSYCHIC, NULL + call BattleScript_TerrainSeedLoop end3 BattleScript_BadDreamsActivates:: @@ -7612,6 +7626,20 @@ BattleScript_82DB85B:: call BattleScript_StatUp removeitem BS_ATTACKER end2 + +BattleScript_BerryStatRaiseRet:: + jumpifability BS_SCRIPTING, ABILITY_RIPEN, BattleScript_BerryStatRaiseRet_AbilityPopup + goto BattleScript_BerryStatRaiseRet_Anim +BattleScript_BerryStatRaiseRet_AbilityPopup: + call BattleScript_AbilityPopUp +BattleScript_BerryStatRaiseRet_Anim: + playanimation BS_SCRIPTING, B_ANIM_HELD_ITEM_EFFECT, NULL + statbuffchange STAT_BUFF_ALLOW_PTR, BattleScript_BerryStatRaiseRet_End +BattleScript_BerryStatRaiseRet_End: + setbyte cMULTISTRING_CHOOSER, 0x4 + call BattleScript_StatUp + removeitem BS_SCRIPTING + return BattleScript_BerryFocusEnergyEnd2:: playanimation BS_ATTACKER, B_ANIM_HELD_ITEM_EFFECT, NULL diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 1efb9052d..7153eebb8 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -209,6 +209,7 @@ extern const u8 BattleScript_SelectingNotAllowedMoveChoiceItem[]; extern const u8 BattleScript_HangedOnMsg[]; extern const u8 BattleScript_BerryConfuseHealEnd2[]; extern const u8 BattleScript_BerryStatRaiseEnd2[]; +extern const u8 BattleScript_BerryStatRaiseRet[]; extern const u8 BattleScript_BerryFocusEnergyEnd2[]; extern const u8 BattleScript_ActionSelectionItemsCantBeUsed[]; extern const u8 BattleScript_ArenaTurnBeginning[]; diff --git a/include/battle_util.h b/include/battle_util.h index f7699fced..602901f93 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -130,5 +130,6 @@ void ClearIllusionMon(u32 battlerId); bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId); bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId); u8 GetBattleMoveSplit(u32 moveId); +u8 TryHandleSeed(u8 battler, u32 terrainFlag, u8 statId, u16 itemId, bool32 execute); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 5e27fe300..d06db22b4 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -167,6 +167,7 @@ #define VARIOUS_PARALYZE_TYPE_IMMUNITY 100 #define VARIOUS_JUMP_IF_ABSENT 101 #define VARIOUS_DESTROY_ABILITY_POPUP 102 +#define VARIOUS_TERRAIN_SEED 103 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/include/constants/hold_effects.h b/include/constants/hold_effects.h index c90f35651..890f99a3a 100644 --- a/include/constants/hold_effects.h +++ b/include/constants/hold_effects.h @@ -146,4 +146,10 @@ #define HOLD_EFFECT_CHOICE(holdEffect)((holdEffect == HOLD_EFFECT_CHOICE_BAND || holdEffect == HOLD_EFFECT_CHOICE_SCARF || holdEffect == HOLD_EFFECT_CHOICE_SPECS)) +// terrain seed params +#define HOLD_EFFECT_PARAM_ELECTRIC_TERRAIN 0 +#define HOLD_EFFECT_PARAM_GRASSY_TERRAIN 1 +#define HOLD_EFFECT_PARAM_MISTY_TERRAIN 2 +#define HOLD_EFFECT_PARAM_PSYCHIC_TERRAIN 3 + #endif // GUARD_HOLD_EFFECTS_H diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4d98390d6..11326d82f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8322,6 +8322,34 @@ static void Cmd_various(void) case VARIOUS_DESTROY_ABILITY_POPUP: DestroyAbilityPopUp(gActiveBattler); break; + case VARIOUS_TERRAIN_SEED: + if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_SEEDS) + { + u8 effect = 0; + u16 item = gBattleMons[gActiveBattler].item; + switch (GetBattlerHoldEffectParam(gActiveBattler)) + { + case HOLD_EFFECT_PARAM_ELECTRIC_TERRAIN: + effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, item, FALSE); + break; + case HOLD_EFFECT_PARAM_GRASSY_TERRAIN: + effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, item, FALSE); + break; + case HOLD_EFFECT_PARAM_MISTY_TERRAIN: + effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, item, FALSE); + break; + case HOLD_EFFECT_PARAM_PSYCHIC_TERRAIN: + effect = TryHandleSeed(gActiveBattler, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, item, FALSE); + break; + } + if (effect) + { + //gBattlescriptCurrInstr += 7; + return; + } + } + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); + return; } gBattlescriptCurrInstr += 3; diff --git a/src/battle_util.c b/src/battle_util.c index 3c1a864d1..1a2589938 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5073,6 +5073,33 @@ static u8 RandomStatRaiseBerry(u32 battlerId, u32 itemId) return 0; } +u8 TryHandleSeed(u8 battler, u32 terrainFlag, u8 statId, u16 itemId, bool32 execute) +{ + if (gFieldStatuses & terrainFlag && gBattleMons[battler].statStages[statId] < MAX_STAT_STAGE) + { + PREPARE_STAT_BUFFER(gBattleTextBuff1, statId); + PREPARE_STRING_BUFFER(gBattleTextBuff2, STRINGID_STATROSE); + + gLastUsedItem = itemId; // for surge abilities + gEffectBattler = battler; + gBattleScripting.battler = battler; + SET_STATCHANGER(statId, 1, FALSE); + gBattleScripting.animArg1 = 0xE + statId; + gBattleScripting.animArg2 = 0; + if (execute) + { + BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); + } + else + { + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_BerryStatRaiseRet; + } + return ITEM_STATS_CHANGE; + } + return 0; +} + static u8 ItemHealHp(u32 battlerId, u32 itemId, bool32 end2, bool32 percentHeal) { if (HasEnoughHpToEatBerry(battlerId, 2, itemId)) @@ -5312,6 +5339,23 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; } + case HOLD_EFFECT_SEEDS: + switch (GetBattlerHoldEffectParam(battlerId)) + { + case HOLD_EFFECT_PARAM_ELECTRIC_TERRAIN: + effect = TryHandleSeed(battlerId, STATUS_FIELD_ELECTRIC_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); + break; + case HOLD_EFFECT_PARAM_GRASSY_TERRAIN: + effect = TryHandleSeed(battlerId, STATUS_FIELD_GRASSY_TERRAIN, STAT_DEF, gLastUsedItem, TRUE); + break; + case HOLD_EFFECT_PARAM_MISTY_TERRAIN: + effect = TryHandleSeed(battlerId, STATUS_FIELD_MISTY_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); + break; + case HOLD_EFFECT_PARAM_PSYCHIC_TERRAIN: + effect = TryHandleSeed(battlerId, STATUS_FIELD_PSYCHIC_TERRAIN, STAT_SPDEF, gLastUsedItem, TRUE); + break; + + } break; }