Start Side/Field end turn

This commit is contained in:
DizzyEggg 2018-07-21 12:10:08 +02:00
parent 1468107002
commit 382f640809
4 changed files with 60 additions and 43 deletions

View File

@ -251,7 +251,13 @@ struct SideTimer
/*0x08*/ u8 followmeTimer; /*0x08*/ u8 followmeTimer;
/*0x09*/ u8 followmeTarget; /*0x09*/ u8 followmeTarget;
/*0x0A*/ u8 spikesAmount; /*0x0A*/ u8 spikesAmount;
/*0x0B*/ u8 fieldB; u8 toxicSpikesAmount;
bool8 stealthRock;
bool8 stickyWeb;
u8 auroraVeilTimer;
u8 auroraVeilBattlerId;
u8 tailwindTimer;
u8 tailwindBattlerId;
}; };
struct FieldTimer struct FieldTimer
@ -554,7 +560,7 @@ struct BattleStruct
u8 intimidateBattler; u8 intimidateBattler;
u8 switchInItemsCounter; u8 switchInItemsCounter;
u8 field_DA; u8 field_DA;
u8 turnSideTracker; u8 turnEffectsSide;
u8 fillerDC[0xDF-0xDC]; u8 fillerDC[0xDF-0xDC];
u8 field_DF; u8 field_DF;
u8 mirrorMoveArrays[32]; u8 mirrorMoveArrays[32];

View File

@ -56,7 +56,7 @@ u8 TrySetCantSelectMoveBattleScript(void);
u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u8 check); u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u8 check);
bool8 AreAllMovesUnusable(void); bool8 AreAllMovesUnusable(void);
u8 GetImprisonedMovesCount(u8 battlerId, u16 move); u8 GetImprisonedMovesCount(u8 battlerId, u16 move);
u8 UpdateTurnCounters(void); u8 DoFieldEndTurnEffects(void);
u8 DoBattlerEndTurnEffects(void); u8 DoBattlerEndTurnEffects(void);
bool8 HandleWishPerishSongOnTurnEnd(void); bool8 HandleWishPerishSongOnTurnEnd(void);
bool8 HandleFaintedMonActions(void); bool8 HandleFaintedMonActions(void);

View File

@ -3966,7 +3966,7 @@ void BattleTurnPassed(void)
TurnValuesCleanUp(TRUE); TurnValuesCleanUp(TRUE);
if (gBattleOutcome == 0) if (gBattleOutcome == 0)
{ {
if (UpdateTurnCounters()) if (DoFieldEndTurnEffects())
return; return;
if (DoBattlerEndTurnEffects()) if (DoBattlerEndTurnEffects())
return; return;
@ -4010,7 +4010,7 @@ void BattleTurnPassed(void)
gChosenMoveByBattler[i] = MOVE_NONE; gChosenMoveByBattler[i] = MOVE_NONE;
} }
for (i = 0; i < 4; i++) for (i = 0; i < MAX_BATTLERS_COUNT; i++)
*(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE; *(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE;
*(&gBattleStruct->field_91) = gAbsentBattlerFlags; *(&gBattleStruct->field_91) = gAbsentBattlerFlags;

View File

@ -743,7 +743,22 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move)
return imprisionedMoves; return imprisionedMoves;
} }
u8 UpdateTurnCounters(void) enum
{
ENDTURN_ORDER,
ENDTURN_REFLECT,
ENDTURN_LIGHT_SCREEN,
ENDTURN_MIST,
ENDTURN_SAFEGUARD,
ENDTURN_WISH,
ENDTURN_RAIN,
ENDTURN_SANDSTORM,
ENDTURN_SUN,
ENDTURN_HAIL,
ENDTURN_FIELD_COUNT,
};
u8 DoFieldEndTurnEffects(void)
{ {
u8 effect = 0; u8 effect = 0;
s32 i; s32 i;
@ -761,7 +776,7 @@ u8 UpdateTurnCounters(void)
switch (gBattleStruct->turnCountersTracker) switch (gBattleStruct->turnCountersTracker)
{ {
case 0: case ENDTURN_ORDER:
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
gBattlerByTurnOrder[i] = i; gBattlerByTurnOrder[i] = i;
@ -776,17 +791,13 @@ u8 UpdateTurnCounters(void)
} }
} }
// It's stupid, but won't match without it gBattleStruct->turnCountersTracker++;
{ gBattleStruct->turnEffectsSide = 0;
u8* var = &gBattleStruct->turnCountersTracker;
(*var)++;
gBattleStruct->turnSideTracker = 0;
}
// fall through // fall through
case 1: case ENDTURN_REFLECT:
while (gBattleStruct->turnSideTracker < 2) while (gBattleStruct->turnEffectsSide < 2)
{ {
side = gBattleStruct->turnSideTracker; side = gBattleStruct->turnEffectsSide;
gActiveBattler = gBattlerAttacker = gSideTimers[side].reflectBattlerId; gActiveBattler = gBattlerAttacker = gSideTimers[side].reflectBattlerId;
if (gSideStatuses[side] & SIDE_STATUS_REFLECT) if (gSideStatuses[side] & SIDE_STATUS_REFLECT)
{ {
@ -798,20 +809,20 @@ u8 UpdateTurnCounters(void)
effect++; effect++;
} }
} }
gBattleStruct->turnSideTracker++; gBattleStruct->turnEffectsSide++;
if (effect) if (effect)
break; break;
} }
if (!effect) if (!effect)
{ {
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
gBattleStruct->turnSideTracker = 0; gBattleStruct->turnEffectsSide = 0;
} }
break; break;
case 2: case ENDTURN_LIGHT_SCREEN:
while (gBattleStruct->turnSideTracker < 2) while (gBattleStruct->turnEffectsSide < 2)
{ {
side = gBattleStruct->turnSideTracker; side = gBattleStruct->turnEffectsSide;
gActiveBattler = gBattlerAttacker = gSideTimers[side].lightscreenBattlerId; gActiveBattler = gBattlerAttacker = gSideTimers[side].lightscreenBattlerId;
if (gSideStatuses[side] & SIDE_STATUS_LIGHTSCREEN) if (gSideStatuses[side] & SIDE_STATUS_LIGHTSCREEN)
{ {
@ -824,20 +835,20 @@ u8 UpdateTurnCounters(void)
effect++; effect++;
} }
} }
gBattleStruct->turnSideTracker++; gBattleStruct->turnEffectsSide++;
if (effect) if (effect)
break; break;
} }
if (!effect) if (!effect)
{ {
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
gBattleStruct->turnSideTracker = 0; gBattleStruct->turnEffectsSide = 0;
} }
break; break;
case 3: case ENDTURN_MIST:
while (gBattleStruct->turnSideTracker < 2) while (gBattleStruct->turnEffectsSide < 2)
{ {
side = gBattleStruct->turnSideTracker; side = gBattleStruct->turnEffectsSide;
gActiveBattler = gBattlerAttacker = gSideTimers[side].mistBattlerId; gActiveBattler = gBattlerAttacker = gSideTimers[side].mistBattlerId;
if (gSideTimers[side].mistTimer != 0 if (gSideTimers[side].mistTimer != 0
&& --gSideTimers[side].mistTimer == 0) && --gSideTimers[side].mistTimer == 0)
@ -848,20 +859,20 @@ u8 UpdateTurnCounters(void)
PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_MIST); PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_MIST);
effect++; effect++;
} }
gBattleStruct->turnSideTracker++; gBattleStruct->turnEffectsSide++;
if (effect) if (effect)
break; break;
} }
if (!effect) if (!effect)
{ {
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
gBattleStruct->turnSideTracker = 0; gBattleStruct->turnEffectsSide = 0;
} }
break; break;
case 4: case ENDTURN_SAFEGUARD:
while (gBattleStruct->turnSideTracker < 2) while (gBattleStruct->turnEffectsSide < 2)
{ {
side = gBattleStruct->turnSideTracker; side = gBattleStruct->turnEffectsSide;
gActiveBattler = gBattlerAttacker = gSideTimers[side].safeguardBattlerId; gActiveBattler = gBattlerAttacker = gSideTimers[side].safeguardBattlerId;
if (gSideStatuses[side] & SIDE_STATUS_SAFEGUARD) if (gSideStatuses[side] & SIDE_STATUS_SAFEGUARD)
{ {
@ -872,20 +883,20 @@ u8 UpdateTurnCounters(void)
effect++; effect++;
} }
} }
gBattleStruct->turnSideTracker++; gBattleStruct->turnEffectsSide++;
if (effect) if (effect)
break; break;
} }
if (!effect) if (!effect)
{ {
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
gBattleStruct->turnSideTracker = 0; gBattleStruct->turnEffectsSide = 0;
} }
break; break;
case 5: case ENDTURN_WISH:
while (gBattleStruct->turnSideTracker < gBattlersCount) while (gBattleStruct->turnEffectsSide < gBattlersCount)
{ {
gActiveBattler = gBattlerByTurnOrder[gBattleStruct->turnSideTracker]; gActiveBattler = gBattlerByTurnOrder[gBattleStruct->turnEffectsSide];
if (gWishFutureKnock.wishCounter[gActiveBattler] != 0 if (gWishFutureKnock.wishCounter[gActiveBattler] != 0
&& --gWishFutureKnock.wishCounter[gActiveBattler] == 0 && --gWishFutureKnock.wishCounter[gActiveBattler] == 0
&& gBattleMons[gActiveBattler].hp != 0) && gBattleMons[gActiveBattler].hp != 0)
@ -894,7 +905,7 @@ u8 UpdateTurnCounters(void)
BattleScriptExecute(BattleScript_WishComesTrue); BattleScriptExecute(BattleScript_WishComesTrue);
effect++; effect++;
} }
gBattleStruct->turnSideTracker++; gBattleStruct->turnEffectsSide++;
if (effect) if (effect)
break; break;
} }
@ -903,7 +914,7 @@ u8 UpdateTurnCounters(void)
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
} }
break; break;
case 6: case ENDTURN_RAIN:
if (gBattleWeather & WEATHER_RAIN_ANY) if (gBattleWeather & WEATHER_RAIN_ANY)
{ {
if (!(gBattleWeather & WEATHER_RAIN_PERMANENT)) if (!(gBattleWeather & WEATHER_RAIN_PERMANENT))
@ -933,7 +944,7 @@ u8 UpdateTurnCounters(void)
} }
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
break; break;
case 7: case ENDTURN_SANDSTORM:
if (gBattleWeather & WEATHER_SANDSTORM_ANY) if (gBattleWeather & WEATHER_SANDSTORM_ANY)
{ {
if (!(gBattleWeather & WEATHER_SANDSTORM_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) if (!(gBattleWeather & WEATHER_SANDSTORM_PERMANENT) && --gWishFutureKnock.weatherDuration == 0)
@ -953,7 +964,7 @@ u8 UpdateTurnCounters(void)
} }
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
break; break;
case 8: case ENDTURN_SUN:
if (gBattleWeather & WEATHER_SUN_ANY) if (gBattleWeather & WEATHER_SUN_ANY)
{ {
if (!(gBattleWeather & WEATHER_SUN_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) if (!(gBattleWeather & WEATHER_SUN_PERMANENT) && --gWishFutureKnock.weatherDuration == 0)
@ -971,8 +982,8 @@ u8 UpdateTurnCounters(void)
} }
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
break; break;
case 9: case ENDTURN_HAIL:
if (gBattleWeather & WEATHER_HAIL) if (gBattleWeather & WEATHER_HAIL_ANY)
{ {
if (--gWishFutureKnock.weatherDuration == 0) if (--gWishFutureKnock.weatherDuration == 0)
{ {
@ -991,7 +1002,7 @@ u8 UpdateTurnCounters(void)
} }
gBattleStruct->turnCountersTracker++; gBattleStruct->turnCountersTracker++;
break; break;
case 10: case ENDTURN_FIELD_COUNT:
effect++; effect++;
break; break;
} }