Renamed VAR_TERRAIN to B_VAR_TERRAIN and added a var-based field terrain timer (#4132)

* Renamed VAR_TERRAIN and introduced a var-based field terrains timer

* Fixed sky battle configs alignment and syntax

* Added B_VAR_TERRAIN_TIMER handling to Overworld_ResetBattleFlagsAndVars

* Removed pointless edits to EndTurnTerrain

* Updated B_VAR_TERRAIN_TIMER's comment

* Updated the syntax of ABILITYEFFECT_SWITCH_IN_TERRAIN to comply with Agbcc

* Nuked pointless VarGet calls in the case ABILITYEFFECT_SWITCH_IN_TERRAIN of AbilityBattleEffects

* Reverted changes made to BS_SetRemoveTerrain
I shouldn't have touched it at all since it's not involved with B_VAR_TERRAIN functionality.

* Removed trailing spaces in the case ABILITYEFFECT_SWITCH_IN_TERRAIN of AbilityBattleEffects
This commit is contained in:
LOuroboros 2024-02-04 09:04:55 -03:00 committed by GitHub
parent ab2774f8c7
commit 691b1879f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 83 additions and 50 deletions

View file

@ -179,15 +179,15 @@
// Var Settings
// To use the following features in scripting, replace the 0s with the var ID you're assigning it to.
// Eg: Replace with VAR_UNUSED_0x40F7 so you can use 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
// Eg: Replace with VAR_UNUSED_0x40F7 so you can use B_VAR_TERRAIN for that feature.
#define B_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.
#define B_VAR_TERRAIN_TIMER 0 // If this var has a value greater or equal than 1 field terrains will last that number of turns, otherwise they will last until they're overwritten.
#define B_VAR_WILD_AI_FLAGS 0 // If not 0, you can use this var to add to default wild AI flags. NOT usable with flags above (1 << 15)
// Sky Battles
#define B_FLAG_SKY_BATTLE 0 // If this flag has a value, the player will be able to engage in scripted Sky Battles.
#define B_VAR_SKY_BATTLE 0 // If this var has a value, the game will remember the positions of Pokémon used in Sky Battles.
#define B_SKY_BATTLE_STRICT_ELIGIBILITY FALSE //If TRUE, Sky Battles will use the eligibility from Pokémon XY. If FALSE, all Flying-types or Pokémon with Levitate are allowed.
#define B_FLAG_SKY_BATTLE 0 // If this flag has a value, the player will be able to engage in scripted Sky Battles.
#define B_VAR_SKY_BATTLE 0 // If this var has a value, the game will remember the positions of Pokémon used in Sky Battles.
#define B_SKY_BATTLE_STRICT_ELIGIBILITY FALSE // If TRUE, Sky Battles will use the eligibility from Pokémon XY. If FALSE, all Flying-types or Pokémon with Levitate are allowed.
// Flag and Var settings
#define B_RESET_FLAGS_VARS_AFTER_WHITEOUT TRUE // If TRUE, Overworld_ResetBattleFlagsAndVars will reset battle-related Flags and Vars when the player whites out.

View file

@ -4016,50 +4016,79 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
switch (caseID)
{
case ABILITYEFFECT_SWITCH_IN_TERRAIN:
gBattleScripting.battler = battler;
if (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY)
{
u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; // only works for status flag (1 << 15)
gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent
switch (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY)
{
case STATUS_FIELD_ELECTRIC_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_ELECTRIC;
break;
case STATUS_FIELD_MISTY_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_MISTY;
break;
case STATUS_FIELD_GRASSY_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_GRASSY;
break;
case STATUS_FIELD_PSYCHIC_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_PSYCHIC;
break;
}
u8 varTerrainTimer = VarGet(B_VAR_TERRAIN_TIMER);
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
gBattleScripting.battler = battler;
if (VarGet(B_VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY)
{
u16 terrainFlags = VarGet(B_VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; // only works for status flag (1 << 15)
if (varTerrainTimer == 0)
{
gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent
}
else
{
gFieldStatuses |= terrainFlags;
gFieldTimers.terrainTimer = varTerrainTimer;
}
switch (VarGet(B_VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY)
{
case STATUS_FIELD_ELECTRIC_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_ELECTRIC;
break;
case STATUS_FIELD_MISTY_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_MISTY;
break;
case STATUS_FIELD_GRASSY_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_GRASSY;
break;
case STATUS_FIELD_PSYCHIC_TERRAIN:
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_PSYCHIC;
break;
}
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
}
else if (B_THUNDERSTORM_TERRAIN == TRUE
&& GetCurrentWeather() == WEATHER_RAIN_THUNDERSTORM
&& !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN))
{
// overworld weather started rain, so just do electric terrain anim
if (varTerrainTimer == 0)
{
gFieldStatuses = (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT);
}
else
{
gFieldStatuses |= STATUS_FIELD_ELECTRIC_TERRAIN;
gFieldTimers.terrainTimer = varTerrainTimer;
}
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_ELECTRIC;
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
}
else if (B_FOG_TERRAIN == TRUE
&& (GetCurrentWeather() == WEATHER_FOG_HORIZONTAL || GetCurrentWeather() == WEATHER_FOG_DIAGONAL)
&& !(gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN))
{
if (varTerrainTimer == 0)
{
gFieldStatuses = (STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT);
}
else
{
gFieldStatuses |= STATUS_FIELD_ELECTRIC_TERRAIN;
gFieldTimers.terrainTimer = varTerrainTimer;
}
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_MISTY;
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
}
}
else if (B_THUNDERSTORM_TERRAIN == TRUE
&& GetCurrentWeather() == WEATHER_RAIN_THUNDERSTORM
&& !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN))
{
// overworld weather started rain, so just do electric terrain anim
gFieldStatuses = (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT);
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_ELECTRIC;
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
}
else if (B_FOG_TERRAIN == TRUE
&& (GetCurrentWeather() == WEATHER_FOG_HORIZONTAL || GetCurrentWeather() == WEATHER_FOG_DIAGONAL)
&& !(gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN))
{
gFieldStatuses = (STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT);
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TERRAIN_SET_MISTY;
BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain);
effect++;
}
break;
break;
case ABILITYEFFECT_SWITCH_IN_WEATHER:
gBattleScripting.battler = battler;
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))

View file

@ -399,10 +399,14 @@ void Overworld_ResetStateAfterDigEscRope(void)
}
#if B_RESET_FLAGS_VARS_AFTER_WHITEOUT == TRUE
void Overworld_ResetBattleFlagsAndVars(void)
void Overworld_ResetBattleFlagsAndVars(void)
{
#if VAR_TERRAIN != 0
VarSet(VAR_TERRAIN, 0);
#if B_VAR_TERRAIN != 0
VarSet(B_VAR_TERRAIN, 0);
#endif
#if B_VAR_TERRAIN_TIMER != 0
VarSet(B_VAR_TERRAIN_TIMER, 0);
#endif
#if B_VAR_WILD_AI_FLAGS != 0