From 67fefd0261ff0f2b11f26829ecfa3622d05eabf0 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 13 Dec 2020 19:42:48 -0700 Subject: [PATCH] var terrain, surge fixes --- data/battle_anim_scripts.s | 16 ---------- data/battle_scripts_1.s | 16 +++++++--- include/battle.h | 1 + include/battle_scripts.h | 1 + include/battle_util.h | 1 + include/constants/battle.h | 25 ++++++++-------- include/constants/battle_anim.h | 12 +++----- include/constants/battle_config.h | 5 ++++ src/battle_interface.c | 5 +--- src/battle_main.c | 6 ++++ src/battle_script_commands.c | 7 +++-- src/battle_util.c | 50 +++++++++++++++++++++++++++---- 12 files changed, 94 insertions(+), 51 deletions(-) diff --git a/data/battle_anim_scripts.s b/data/battle_anim_scripts.s index cf11f4d6ae..1cd25477fd 100644 --- a/data/battle_anim_scripts.s +++ b/data/battle_anim_scripts.s @@ -808,10 +808,6 @@ gBattleAnims_General:: .4byte General_IngrainHeal .4byte General_WishHeal .4byte General_MegaEvolution - .4byte General_TerrainMisty - .4byte General_TerrainGrassy - .4byte General_TerrainElectric - .4byte General_TerrainPsychic .4byte General_IllusionOff .4byte General_FormChange .4byte General_SlideOffScreen @@ -24319,18 +24315,6 @@ MegaEvolutionParticles: delay 3 return -General_TerrainMisty: - end - -General_TerrainGrassy: - end - -General_TerrainElectric: - end - -General_TerrainPsychic: - end - General_RestoreBg: restorebg waitbgfadein diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 0ccaa7ef64..9811a2fba9 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5386,6 +5386,12 @@ BattleScript_OverworldWeatherStarts:: playanimation2 BS_ATTACKER, sB_ANIM_ARG1, NULL end3 +BattleScript_OverworldTerrain:: + printfromtable gTerrainStringIds + waitmessage 0x40 + playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL + end3 + BattleScript_SideStatusWoreOff:: printstring STRINGID_PKMNSXWOREOFF waitmessage 0x40 @@ -6823,7 +6829,7 @@ BattleScript_ElectricSurgeActivates:: call BattleScript_AbilityPopUp printstring STRINGID_TERRAINBECOMESELECTRIC waitstate - playanimation BS_SCRIPTING, B_ANIM_TERRAIN_ELECTRIC, NULL + playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL end3 BattleScript_MistySurgeActivates:: @@ -6831,7 +6837,7 @@ BattleScript_MistySurgeActivates:: call BattleScript_AbilityPopUp printstring STRINGID_TERRAINBECOMESMISTY waitstate - playanimation BS_SCRIPTING, B_ANIM_TERRAIN_MISTY, NULL + playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL end3 BattleScript_GrassySurgeActivates:: @@ -6839,7 +6845,7 @@ BattleScript_GrassySurgeActivates:: call BattleScript_AbilityPopUp printstring STRINGID_TERRAINBECOMESGRASSY waitstate - playanimation BS_SCRIPTING, B_ANIM_TERRAIN_GRASSY, NULL + playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL end3 BattleScript_PsychicSurgeActivates:: @@ -6847,7 +6853,7 @@ BattleScript_PsychicSurgeActivates:: call BattleScript_AbilityPopUp printstring STRINGID_TERRAINBECOMESPSYCHIC waitstate - playanimation BS_SCRIPTING, B_ANIM_TERRAIN_PSYCHIC, NULL + playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL end3 BattleScript_BadDreamsActivates:: @@ -7035,7 +7041,9 @@ BattleScript_GrassyTerrainLoopIncrement:: jumpifbytenotequal gBattleCommunication, gBattlersCount, BattleScript_GrassyTerrainLoop BattleScript_GrassyTerrainLoopEnd:: bicword gHitMarker, HITMARKER_x20 | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_x100000 + jumpifword CMP_COMMON_BITS, gFieldStatuses, STATUS_FIELD_TERRAIN_PERMANENT, BattleScript_GrassyTerrainHealEnd jumpifbyte CMP_EQUAL, gFieldTimers + 5, 0x0, BattleScript_GrassyTerrainEnds +BattleScript_GrassyTerrainHealEnd: end2 BattleScript_AbilityNoSpecificStatLoss:: diff --git a/include/battle.h b/include/battle.h index 488e0fc51c..f43220e9b1 100644 --- a/include/battle.h +++ b/include/battle.h @@ -503,6 +503,7 @@ struct BattleStruct u8 wishPerishSongState; u8 wishPerishSongBattlerId; bool8 overworldWeatherDone; + bool8 terrainDone; u8 atkCancellerTracker; struct BattleTvMovePoints tvMovePoints; struct BattleTv tv; diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 3566a1c4d2..980dde468a 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -48,6 +48,7 @@ extern const u8 BattleScript_SandStormHailEnds[]; extern const u8 BattleScript_SunlightContinues[]; extern const u8 BattleScript_SunlightFaded[]; extern const u8 BattleScript_OverworldWeatherStarts[]; +extern const u8 BattleScript_OverworldTerrain[]; extern const u8 BattleScript_SideStatusWoreOff[]; extern const u8 BattleScript_SafeguardProtected[]; extern const u8 BattleScript_SafeguardEnds[]; diff --git a/include/battle_util.h b/include/battle_util.h index f7699fceda..0637e80f77 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -23,6 +23,7 @@ #define ABILITYEFFECT_TRACE1 0xC #define ABILITYEFFECT_TRACE2 0xD #define ABILITYEFFECT_MOVE_END_OTHER 0xE +#define ABILITYEFFECT_SWITCH_IN_TERRAIN 0xFE #define ABILITYEFFECT_SWITCH_IN_WEATHER 0xFF #define ITEMEFFECT_ON_SWITCH_IN 0x0 diff --git a/include/constants/battle.h b/include/constants/battle.h index 40c604c9ed..7ea1e5e483 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -221,18 +221,19 @@ #define SIDE_STATUS_MAT_BLOCK (1 << 21) // Field affecting statuses. -#define STATUS_FIELD_MAGIC_ROOM 0x1 -#define STATUS_FIELD_TRICK_ROOM 0x2 -#define STATUS_FIELD_WONDER_ROOM 0x4 -#define STATUS_FIELD_MUDSPORT 0x8 -#define STATUS_FIELD_WATERSPORT 0x10 -#define STATUS_FIELD_GRAVITY 0x20 -#define STATUS_FIELD_GRASSY_TERRAIN 0x40 -#define STATUS_FIELD_MISTY_TERRAIN 0x80 -#define STATUS_FIELD_ELECTRIC_TERRAIN 0x100 -#define STATUS_FIELD_PSYCHIC_TERRAIN 0x200 -#define STATUS_FIELD_ION_DELUGE 0x400 -#define STATUS_FIELD_FAIRY_LOCK 0x800 +#define STATUS_FIELD_MAGIC_ROOM (1 << 0) +#define STATUS_FIELD_TRICK_ROOM (1 << 1) +#define STATUS_FIELD_WONDER_ROOM (1 << 2) +#define STATUS_FIELD_MUDSPORT (1 << 3) +#define STATUS_FIELD_WATERSPORT (1 << 4) +#define STATUS_FIELD_GRAVITY (1 << 5) +#define STATUS_FIELD_GRASSY_TERRAIN (1 << 6) +#define STATUS_FIELD_MISTY_TERRAIN (1 << 7) +#define STATUS_FIELD_ELECTRIC_TERRAIN (1 << 8) +#define STATUS_FIELD_PSYCHIC_TERRAIN (1 << 9) +#define STATUS_FIELD_ION_DELUGE (1 << 10) +#define STATUS_FIELD_FAIRY_LOCK (1 << 11) +#define STATUS_FIELD_TERRAIN_PERMANENT (1 << 12) // Overworld thunderstorm generates electric terrain #define STATUS_TERRAIN_ANY (STATUS_FIELD_GRASSY_TERRAIN | STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_PSYCHIC_TERRAIN) diff --git a/include/constants/battle_anim.h b/include/constants/battle_anim.h index 4066060505..025b9e310c 100644 --- a/include/constants/battle_anim.h +++ b/include/constants/battle_anim.h @@ -518,14 +518,10 @@ #define B_ANIM_INGRAIN_HEAL 0x15 #define B_ANIM_WISH_HEAL 0x16 #define B_ANIM_MEGA_EVOLUTION 0x17 -#define B_ANIM_TERRAIN_MISTY 0x18 -#define B_ANIM_TERRAIN_GRASSY 0x19 -#define B_ANIM_TERRAIN_ELECTRIC 0x1A -#define B_ANIM_TERRAIN_PSYCHIC 0x1B -#define B_ANIM_ILLUSION_OFF 0x1C -#define B_ANIM_FORM_CHANGE 0x1D -#define B_ANIM_SLIDE_OFFSCREEN 0x1E // for Emergency Exit -#define B_ANIM_RESTORE_BG 0x1F // for Terrain Endings +#define B_ANIM_ILLUSION_OFF 0x18 +#define B_ANIM_FORM_CHANGE 0x19 +#define B_ANIM_SLIDE_OFFSCREEN 0x1A // for Emergency Exit +#define B_ANIM_RESTORE_BG 0x1B // for Terrain Endings, Surge abilities // special animations table #define B_ANIM_LVL_UP 0x0 diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index be58ba7e74..df255ac59d 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -131,6 +131,10 @@ #define B_FLAG_INVERSE_BATTLE 0 // If this flag is set, the battle's type effectiveness are inversed. For example, fire is super effective against water. #define B_FLAG_FORCE_DOUBLE_WILD 0 // If this flag is set, all land and surfing wild battles will be double battles. +// Var Settings +// To use the following features in scripting, replace the 0s with the Var ID you're assigning to it. Eg: replace VAR_UNUSED_0x40F7 with VAR_TERRAIN for that feature +#define VAR_TERRAIN 0 // If this var has a value, assigning a STATUS_FIELD_xx_TERRAIN to it before battle causes the battle to start with that terrain active + // Interface settings #define B_ABILITY_POP_UP TRUE // In Gen5+, the Pokémon abilities are displayed in a pop-up, when they activate in battle. #define B_FAST_INTRO TRUE // If set to TRUE, battle intro texts print at the same time as animation of a Pokémon, as opposing to waiting for the animation to end. @@ -147,6 +151,7 @@ #define B_PARALYZE_ELECTRIC GEN_6 // In Gen6+, Electric-type Pokémon can't be paralyzed. #define B_POWDER_GRASS GEN_6 // In Gen6+, Grass-type Pokémon are immune to powder and spore moves. #define B_STEEL_RESISTANCES GEN_6 // In Gen6+, Steel-type Pokémon are no longer resistant to Dark and Ghost moves. +#define B_THUNDERSTORM_TERRAIN TRUE // If TRUE, overworld Thunderstorm generates Rain and Electric Terrain as in Gen 8. // Animation Settings #define B_NEW_SWORD_PARTICLE TRUE // If set to TRUE, it updates Swords Dance's particle. diff --git a/src/battle_interface.c b/src/battle_interface.c index 267b06ece1..9a0b98618f 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -965,10 +965,7 @@ static void TryToggleHealboxVisibility(u8 priority, u8 healthboxLeftSpriteId, u8 case B_ANIM_WISH_HEAL: //new case B_ANIM_MEGA_EVOLUTION: - case B_ANIM_TERRAIN_MISTY: - case B_ANIM_TERRAIN_GRASSY: - case B_ANIM_TERRAIN_ELECTRIC: - case B_ANIM_TERRAIN_PSYCHIC: + case B_ANIM_RESTORE_BG: break; } return; //all other special anims dont hide diff --git a/src/battle_main.c b/src/battle_main.c index 48129c5230..d9b3757f0e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3483,6 +3483,12 @@ static void TryDoEventsBeforeFirstTurn(void) gBattleStruct->overworldWeatherDone = TRUE; return; } + if (!gBattleStruct->terrainDone && AbilityBattleEffects(0, 0, 0, ABILITYEFFECT_SWITCH_IN_TERRAIN, 0) != 0) + { + gBattleStruct->terrainDone = TRUE; + return; + } + // Check all switch in abilities happening from the fastest mon to slowest. while (gBattleStruct->switchInAbilitiesCounter < gBattlersCount) { diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c1587f0940..df46f35a2d 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6937,8 +6937,11 @@ static void HandleTerrainMove(u32 moveEffect) gBattleCommunication[MULTISTRING_CHOOSER] = 1; break; case EFFECT_ELECTRIC_TERRAIN: - statusFlag = STATUS_FIELD_ELECTRIC_TERRAIN, timer = &gFieldTimers.electricTerrainTimer; - gBattleCommunication[MULTISTRING_CHOOSER] = 2; + if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT)) + { + statusFlag = STATUS_FIELD_ELECTRIC_TERRAIN, timer = &gFieldTimers.electricTerrainTimer; + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + } break; case EFFECT_PSYCHIC_TERRAIN: statusFlag = STATUS_FIELD_PSYCHIC_TERRAIN, timer = &gFieldTimers.psychicTerrainTimer; diff --git a/src/battle_util.c b/src/battle_util.c index b929b7499d..bff9c1d75d 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1988,16 +1988,18 @@ u8 DoFieldEndTurnEffects(void) gBattleStruct->turnCountersTracker++; break; case ENDTURN_ELECTRIC_TERRAIN: - if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN && --gFieldTimers.electricTerrainTimer == 0) + if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN + && ((!gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.electricTerrainTimer == 0)) { - gFieldStatuses &= ~(STATUS_FIELD_ELECTRIC_TERRAIN); + gFieldStatuses &= ~(STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); BattleScriptExecute(BattleScript_ElectricTerrainEnds); effect++; } gBattleStruct->turnCountersTracker++; break; case ENDTURN_MISTY_TERRAIN: - if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN && --gFieldTimers.mistyTerrainTimer == 0) + if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN + && ((!gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.mistyTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN); BattleScriptExecute(BattleScript_MistyTerrainEnds); @@ -2008,15 +2010,18 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_GRASSY_TERRAIN: if (gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN) { - if (gFieldTimers.grassyTerrainTimer == 0 || --gFieldTimers.grassyTerrainTimer == 0) + if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) + && (gFieldTimers.grassyTerrainTimer == 0 || --gFieldTimers.grassyTerrainTimer == 0)) gFieldStatuses &= ~(STATUS_FIELD_GRASSY_TERRAIN); + BattleScriptExecute(BattleScript_GrassyTerrainHeals); effect++; } gBattleStruct->turnCountersTracker++; break; case ENDTURN_PSYCHIC_TERRAIN: - if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN && --gFieldTimers.psychicTerrainTimer == 0) + if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN + && ((!gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.psychicTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_PSYCHIC_TERRAIN); BattleScriptExecute(BattleScript_PsychicTerrainEnds); @@ -3602,6 +3607,41 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move gBattleScripting.battler = battler; switch (gLastUsedAbility) { + case ABILITYEFFECT_SWITCH_IN_TERRAIN: + if (VarGet(VAR_TERRAIN) & STATUS_TERRAIN_ANY) + { + u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_TERRAIN_ANY; // only works for status flag (1 << 15) + gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent + switch (VarGet(VAR_TERRAIN) & STATUS_TERRAIN_ANY) + { + case STATUS_FIELD_ELECTRIC_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + break; + case STATUS_FIELD_MISTY_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + break; + case STATUS_FIELD_GRASSY_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 1; + break; + case STATUS_FIELD_PSYCHIC_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 3; + break; + } + + BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); + effect++; + } + #if B_THUNDERSTORM_TERRAIN == TRUE + else if (GetCurrentWeather() == WEATHER_RAIN_THUNDERSTORM && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)) + { + // drizzle started rain, so just do electric terrain anim + gFieldStatuses = (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); + effect++; + } + #endif + break; case ABILITYEFFECT_SWITCH_IN_WEATHER: if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) {