Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pass at sleep clause cleanup #7

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,8 @@ struct BattleGimmickData

struct SleepClauseData
{
u8 isActive[NUM_BATTLE_SIDES]; // Stores sleep clause state for each battle side
bool8 effectExempt; // Stores whether effect should be exempt from triggering sleep clause (Effect Spore)
bool8 isCausingSleepClause[NUM_BATTLE_SIDES][PARTY_SIZE]; // When a Pokemon falls asleep, need to know if it should deactivate sleep clause upon waking
bool8 effectExempt; // Stores whether effect should be exempt from triggering Sleep Clause (Effect Spore)
u8 isCausingSleepClause[NUM_BATTLE_SIDES]; // stores which pokemon on a given side is causing Sleep Clause to be active as a bitfield
};

struct LostItem
Expand Down
2 changes: 2 additions & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,7 @@ bool8 CanMonParticipateInSkyBattle(struct Pokemon *mon);
bool8 IsMonBannedFromSkyBattles(u16 species);
void RemoveBattlerType(u32 battler, u8 type);
u32 GetMoveType(u32 move);
void TryActivateSleepClause(u32 battlerSide, u32 indexInParty);
void TryDeactivateSleepClause(u32 battlerSide, u32 indexInParty);

#endif // GUARD_BATTLE_UTIL_H
9 changes: 3 additions & 6 deletions src/battle_dynamax.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,12 +890,9 @@ void BS_TrySetStatus1(void)
gBattleMons[gBattlerTarget].status1 |= STATUS1_SLEEP_TURN((Random() % 3) + 2);
else
gBattleMons[gBattlerTarget].status1 |= STATUS1_SLEEP_TURN((Random() % 4) + 3);
if (FlagGet(B_FLAG_SLEEP_CLAUSE))
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerTarget)] = TRUE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerTarget)][gBattlerPartyIndexes[gBattlerTarget]] = TRUE;
}


// Try to activate Sleep Clause when a mon is put to Sleep
TryActivateSleepClause(GetBattlerSide(gBattlerTarget), gBattlerPartyIndexes[gBattlerTarget]);
gBattleCommunication[MULTISTRING_CHOOSER] = 4;
effect++;
}
Expand Down
86 changes: 23 additions & 63 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -3238,10 +3238,11 @@ void SetMoveEffect(bool32 primary, bool32 certain)
gBattleMons[gEffectBattler].status1 |= STATUS1_SLEEP_TURN(1 + RandomUniform(RNG_SLEEP_TURNS, 1, 3));
else
gBattleMons[gEffectBattler].status1 |= STATUS1_SLEEP_TURN(1 + RandomUniform(RNG_SLEEP_TURNS, 2, 5));

// TODO sleep clause: revisit this and determine if effectExempt is needed
if (FlagGet(B_FLAG_SLEEP_CLAUSE) && !gBattleStruct->sleepClause.effectExempt)
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gEffectBattler)] = TRUE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gEffectBattler)][gBattlerPartyIndexes[gEffectBattler]] = TRUE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gEffectBattler)] |= 1u << gBattlerPartyIndexes[gEffectBattler];
gBattleStruct->sleepClause.effectExempt = FALSE;
}
}
Expand Down Expand Up @@ -4200,11 +4201,9 @@ static void Cmd_tryfaintmon(void)

PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].moves[moveIndex])
}
if (FlagGet(B_FLAG_SLEEP_CLAUSE) && gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]])
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE;
}

// Try to deactivate Sleep Clause when a mon faints
TryDeactivateSleepClause(GetBattlerSide(battler), gBattlerPartyIndexes[battler]);
}
else
{
Expand Down Expand Up @@ -5917,11 +5916,8 @@ static void Cmd_moveend(void)
gBattlescriptCurrInstr = BattleScript_TargetPRLZHeal;
break;
case STATUS1_SLEEP:
if (FlagGet(B_FLAG_SLEEP_CLAUSE) && gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerTarget)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerTarget)][gBattlerPartyIndexes[gBattlerTarget]])
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerTarget)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerTarget)][gBattlerPartyIndexes[gBattlerTarget]] = FALSE;
}
// Try to deactivate Sleep Clause when a mon gets woken up by Wake-Up Slap
TryDeactivateSleepClause(GetBattlerSide(gBattlerTarget), gBattlerPartyIndexes[gBattlerTarget]);
gBattlescriptCurrInstr = BattleScript_TargetWokeUp;
break;
case STATUS1_BURN:
Expand Down Expand Up @@ -10202,25 +10198,17 @@ static void Cmd_various(void)
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1);
MarkBattlerForControllerExec(battler);
gBattlescriptCurrInstr = cmd->nextInstr;
if (FlagGet(B_FLAG_SLEEP_CLAUSE))
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = TRUE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = TRUE;
}
// Try to activate Sleep Clause when a mon is put to Sleep by Psycho Shift
TryActivateSleepClause(GetBattlerSide(battler), gBattlerPartyIndexes[battler]);
return;
}
case VARIOUS_CURE_STATUS:
{
VARIOUS_ARGS();

if (FlagGet(B_FLAG_SLEEP_CLAUSE)
&& (gBattleMons[battler].status1 & STATUS1_SLEEP)
&& gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)]
&& gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]])
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE;
}
// Try to deactivate Sleep Clause when a mon gets woken up by curing sleep via Jungle Healing, Purify, Psycho Shift, Healer, G-Max Sweetness
if (gBattleMons[battler].status1 & STATUS1_SLEEP)
TryDeactivateSleepClause(GetBattlerSide(battler), gBattlerPartyIndexes[battler]);

gBattleMons[battler].status1 = 0;
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1);
Expand Down Expand Up @@ -13410,21 +13398,8 @@ static void Cmd_healpartystatus(void)
if (ability != ABILITY_SOUNDPROOF)
{
toHeal |= (1 << i);

if (FlagGet(B_FLAG_SLEEP_CLAUSE) && gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i])
{
gBattleStruct->sleepClause.isActive[gBattlerAttacker] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i] = FALSE;
}

if (IsDoubleBattle() && !(gAbsentBattlerFlags & (1u << gBattlerTarget)))
{
if (FlagGet(B_FLAG_SLEEP_CLAUSE) && gBattleStruct->sleepClause.isCausingSleepClause[partner][i])
{
gBattleStruct->sleepClause.isActive[partner] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[partner][i] = FALSE;
}
}
// Try to deactivate Sleep Clause when a mon gets woken up by curing sleep via Heal Bell
TryDeactivateSleepClause(GetBattlerSide(gBattlerAttacker), i);
}
}
}
Expand All @@ -13434,13 +13409,10 @@ static void Cmd_healpartystatus(void)
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SOOTHING_AROMA;
toHeal = (1 << PARTY_SIZE) - 1;

if (FlagGet(B_FLAG_SLEEP_CLAUSE))
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->sleepClause.isActive[gBattlerAttacker] = FALSE;
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i] = FALSE;
}
// Try to deactivate Sleep Clause when a mon gets woken up by curing sleep via Aromatherapy, Sparkly Swirl
TryDeactivateSleepClause(GetBattlerSide(gBattlerAttacker), i);
}

gBattleMons[gBattlerAttacker].status1 = 0;
Expand All @@ -13449,14 +13421,6 @@ static void Cmd_healpartystatus(void)
if (IsDoubleBattle()
&& !(gAbsentBattlerFlags & (1u <<partner)))
{
if (FlagGet(B_FLAG_SLEEP_CLAUSE))
{
gBattleStruct->sleepClause.isActive[partner] = FALSE;
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->sleepClause.isCausingSleepClause[partner][i] = FALSE;
}
}
gBattleMons[partner].status1 = 0;
gBattleMons[partner].status2 &= ~STATUS2_NIGHTMARE;
}
Expand Down Expand Up @@ -14828,14 +14792,10 @@ static void Cmd_switchoutabilities(void)
switch (GetBattlerAbility(battler))
{
case ABILITY_NATURAL_CURE:
if (FlagGet(B_FLAG_SLEEP_CLAUSE)
&& (gBattleMons[battler].status1 & STATUS1_SLEEP )
&& gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)]
&& gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]])
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE;
}
// Try to deactivate Sleep Clause when a mon gets woken up by curing sleep via Natural Cure
if (gBattleMons[battler].status1 & STATUS1_SLEEP)
TryDeactivateSleepClause(GetBattlerSide(battler), gBattlerPartyIndexes[battler]);

gBattleMons[battler].status1 = 0;
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE,
1u << *(gBattleStruct->battlerPartyIndexes + battler),
Expand Down Expand Up @@ -17360,7 +17320,7 @@ void BS_JumpIfSleepClause(void)
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);
u8 battler = GetBattlerForBattleScript(cmd->battler);

if (gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)])
if (gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)])
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
Expand Down
Loading
Loading