make special case ABILITYEFFECT_xx ids their own caseId switch cases to fix potential overlap with ability IDs 0xFF etc (#3083)

Co-authored-by: ghoulslash <pokevoyager0@gmail.com>
This commit is contained in:
ghoulslash 2023-07-03 04:03:50 -04:00 committed by GitHub
parent 1fa9a05470
commit cc3a6d4d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 78 deletions

View File

@ -35,11 +35,11 @@
#define ABILITYEFFECT_FIELD_SPORT 13 // Only used if B_SPORT_TURNS < GEN_6
#define ABILITYEFFECT_ON_WEATHER 14
#define ABILITYEFFECT_ON_TERRAIN 15
#define ABILITYEFFECT_SWITCH_IN_TERRAIN 16
#define ABILITYEFFECT_SWITCH_IN_WEATHER 17
// Special cases
#define ABILITYEFFECT_MUD_SPORT 252 // Only used if B_SPORT_TURNS < GEN_6
#define ABILITYEFFECT_WATER_SPORT 253 // Only used if B_SPORT_TURNS < GEN_6
#define ABILITYEFFECT_SWITCH_IN_TERRAIN 254
#define ABILITYEFFECT_SWITCH_IN_WEATHER 255
// For the first argument of ItemBattleEffects, to deteremine which block of item effects to try
#define ITEMEFFECT_ON_SWITCH_IN 0

View File

@ -3823,13 +3823,13 @@ static void TryDoEventsBeforeFirstTurn(void)
}
}
if (!gBattleStruct->overworldWeatherDone
&& AbilityBattleEffects(0, 0, 0, ABILITYEFFECT_SWITCH_IN_WEATHER, 0) != 0)
&& AbilityBattleEffects(ABILITYEFFECT_SWITCH_IN_WEATHER, 0, 0, ABILITYEFFECT_SWITCH_IN_WEATHER, 0) != 0)
{
gBattleStruct->overworldWeatherDone = TRUE;
return;
}
if (!gBattleStruct->terrainDone && AbilityBattleEffects(0, 0, 0, ABILITYEFFECT_SWITCH_IN_TERRAIN, 0) != 0)
if (!gBattleStruct->terrainDone && AbilityBattleEffects(ABILITYEFFECT_SWITCH_IN_TERRAIN, 0, 0, ABILITYEFFECT_SWITCH_IN_TERRAIN, 0) != 0)
{
gBattleStruct->terrainDone = TRUE;
return;

View File

@ -4157,11 +4157,8 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
switch (caseID)
{
case ABILITYEFFECT_ON_SWITCHIN: // 0
gBattleScripting.battler = battler;
switch (gLastUsedAbility)
{
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)
@ -4197,6 +4194,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
#endif
break;
case ABILITYEFFECT_SWITCH_IN_WEATHER:
gBattleScripting.battler = battler;
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
{
switch (GetCurrentWeather())
@ -4235,6 +4233,10 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
BattleScriptPushCursorAndCallback(BattleScript_OverworldWeatherStarts);
}
break;
case ABILITYEFFECT_ON_SWITCHIN: // 0
gBattleScripting.battler = battler;
switch (gLastUsedAbility)
{
case ABILITY_IMPOSTER:
if (IsBattlerAlive(BATTLE_OPPOSITE(battler))
&& !(gBattleMons[BATTLE_OPPOSITE(battler)].status2 & (STATUS2_TRANSFORMED | STATUS2_SUBSTITUTE))