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

EndTurnEffectOrder Refactor #6224

Open
wants to merge 7 commits into
base: upcoming
Choose a base branch
from
Open
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 asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@
.4byte \jumpInstr
.endm

.macro unused_bb
.macro tryhealingitem
.byte 0xbb
.endm

Expand Down Expand Up @@ -1140,9 +1140,8 @@
.4byte \failInstr
.endm

.macro trywish turnNumber:req, failInstr:req
.macro trywish failInstr:req
.byte 0xd4
.byte \turnNumber
.4byte \failInstr
.endm

Expand Down
79 changes: 51 additions & 28 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ BattleScript_MoveEffectSaltCure::
return

BattleScript_SaltCureExtraDamage::
playanimation BS_TARGET, B_ANIM_SALT_CURE_DAMAGE, NULL
playanimation BS_ATTACKER, B_ANIM_SALT_CURE_DAMAGE, NULL
waitanimation
call BattleScript_HurtTarget_NoString
printstring STRINGID_TARGETISHURTBYSALTCURE
waitmessage B_WAIT_TIME_LONG
tryfaintmon BS_TARGET
tryfaintmon BS_ATTACKER
end2

BattleScript_HurtTarget_NoString:
Expand Down Expand Up @@ -5059,7 +5059,7 @@ BattleScript_EffectWish::
attackcanceler
attackstring
ppreduce
trywish 0, BattleScript_ButItFailed
trywish BattleScript_ButItFailed
attackanimation
waitanimation
goto BattleScript_MoveEnd
Expand Down Expand Up @@ -5857,13 +5857,13 @@ BattleScript_FogEnded_Ret::
return

BattleScript_IceBodyHeal::
call BattleScript_AbilityPopUpScripting
playanimation BS_SCRIPTING, B_ANIM_SIMPLE_HEAL
healthbarupdate BS_SCRIPTING
datahpupdate BS_SCRIPTING
call BattleScript_AbilityPopUp
playanimation BS_ATTACKER, B_ANIM_SIMPLE_HEAL
healthbarupdate BS_ATTACKER
datahpupdate BS_ATTACKER
printstring STRINGID_ICEBODYHPGAIN
waitmessage B_WAIT_TIME_LONG
end2
end3

BattleScript_OverworldStatusStarts::
printfromtable gStartingStatusStringIds
Expand Down Expand Up @@ -5924,12 +5924,13 @@ BattleScript_WonderRoomEnds::
BattleScript_MagicRoomEnds::
printstring STRINGID_MAGICROOMENDS
waitmessage B_WAIT_TIME_LONG
setbyte gBattlerAttacker, 0
BattleScript_MagicRoomHealingItemsLoop:
tryhealingitem
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
addbyte gBattlerAttacker, 1 @ TODO: Pretty sure it should be based on speed
jumpifbytenotequal gBattlerAttacker, gBattlersCount, BattleScript_MagicRoomHealingItemsLoop
end2

BattleScript_GrassyTerrainEnds::
call BattleScript_GrassyTerrainHeals_Ret
goto BattleScript_TerrainEnds

BattleScript_TerrainEnds_Ret::
printfromtable gTerrainStringIds
waitmessage B_WAIT_TIME_LONG
Expand Down Expand Up @@ -6693,7 +6694,6 @@ BattleScript_SelectingNotAllowedCurrentMoveInPalace::
goto BattleScript_SelectingUnusableMoveInPalace

BattleScript_WishComesTrue::
trywish 1, BattleScript_WishButFullHp
playanimation BS_TARGET, B_ANIM_WISH_HEAL
printstring STRINGID_PKMNWISHCAMETRUE
waitmessage B_WAIT_TIME_LONG
Expand Down Expand Up @@ -7012,7 +7012,7 @@ BattleScript_CudChewActivates::
pause B_WAIT_TIME_SHORTEST
call BattleScript_AbilityPopUp
setbyte sBERRY_OVERRIDE, 1 @ override the requirements for eating berries
consumeberry BS_SCRIPTING, FALSE
consumeberry BS_ATTACKER, FALSE
setbyte sBERRY_OVERRIDE, 0
end3

Expand Down Expand Up @@ -7164,6 +7164,7 @@ BattleScript_DoTurnDmg:
datahpupdate BS_ATTACKER
tryfaintmon BS_ATTACKER
checkteamslost BattleScript_DoTurnDmgEnd
tryhealingitem
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
BattleScript_DoTurnDmgEnd:
end2

Expand Down Expand Up @@ -7411,6 +7412,7 @@ BattleScript_YawnEnd:
BattleScript_EmbargoEndTurn::
printstring STRINGID_EMBARGOENDS
waitmessage B_WAIT_TIME_LONG
tryhealingitem
end2

BattleScript_TelekinesisEndTurn::
Expand Down Expand Up @@ -7627,6 +7629,37 @@ BattleScript_EmergencyExitWildNoPopUp::
finishaction
return

BattleScript_EmergencyExitEnd2::
pause 5
call BattleScript_AbilityPopUp
pause B_WAIT_TIME_LONG
playanimation BS_ATTACKER, B_ANIM_SLIDE_OFFSCREEN
waitanimation
openpartyscreen BS_ATTACKER, BattleScript_EmergencyExitRetEnd2
switchoutabilities BS_ATTACKER
waitstate
switchhandleorder BS_ATTACKER, 2
returntoball BS_TARGET, FALSE
getswitchedmondata BS_ATTACKER
switchindataupdate BS_ATTACKER
hpthresholds BS_ATTACKER
printstring STRINGID_SWITCHINMON
switchinanim BS_ATTACKER, FALSE, TRUE
waitstate
switchineffects BS_ATTACKER
BattleScript_EmergencyExitRetEnd2:
end2

BattleScript_EmergencyExitWildEnd2::
pause 5
call BattleScript_AbilityPopUp
pause B_WAIT_TIME_LONG
playanimation BS_ATTACKER, B_ANIM_SLIDE_OFFSCREEN
waitanimation
setoutcomeonteleport BS_ATTACKER
finishaction
end2

BattleScript_TraceActivates::
pause B_WAIT_TIME_SHORT
call BattleScript_AbilityPopUpScripting
Expand Down Expand Up @@ -7669,6 +7702,7 @@ BattleScript_PickupActivates::
call BattleScript_AbilityPopUp
printstring STRINGID_XFOUNDONEY
waitmessage B_WAIT_TIME_LONG
tryhealingitem
BattleScript_PickupActivatesEnd:
end3

Expand All @@ -7678,6 +7712,7 @@ BattleScript_HarvestActivates::
call BattleScript_AbilityPopUp
printstring STRINGID_HARVESTBERRY
waitmessage B_WAIT_TIME_LONG
tryhealingitem
BattleScript_HarvestActivatesEnd:
end3

Expand Down Expand Up @@ -8308,25 +8343,13 @@ BattleScript_MoveUsedPsychicTerrainPrevents::
goto BattleScript_MoveEnd

BattleScript_GrassyTerrainHeals::
call BattleScript_GrassyTerrainHeals_Ret
end2

BattleScript_GrassyTerrainHeals_Ret::
setbyte gBattleCommunication, 0
BattleScript_GrassyTerrainLoop:
copyarraywithindex gBattlerAttacker, gBattlerByTurnOrder, gBattleCommunication, 1
checkgrassyterrainheal BS_ATTACKER, BattleScript_GrassyTerrainLoopIncrement
printstring STRINGID_GRASSYTERRAINHEALS
waitmessage B_WAIT_TIME_LONG
orword gHitMarker, HITMARKER_IGNORE_BIDE | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE
healthbarupdate BS_ATTACKER
datahpupdate BS_ATTACKER
BattleScript_GrassyTerrainLoopIncrement::
addbyte gBattleCommunication, 1
jumpifbytenotequal gBattleCommunication, gBattlersCount, BattleScript_GrassyTerrainLoop
bicword gHitMarker, HITMARKER_IGNORE_BIDE | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE
BattleScript_GrassyTerrainHealEnd:
return
end2

BattleScript_AbilityNoSpecificStatLoss::
pause B_WAIT_TIME_SHORT
Expand Down Expand Up @@ -10021,7 +10044,7 @@ BattleScript_DynamaxBegins::
BattleScript_DynamaxEnds::
flushtextbox
updatedynamax
playanimation BS_SCRIPTING, B_ANIM_FORM_CHANGE
playanimation BS_ATTACKER, B_ANIM_FORM_CHANGE
waitanimation
end2

Expand Down
23 changes: 23 additions & 0 deletions endturneffect_bak.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
bool32 HandleWishPerishSongOnTurnEnd(void)
{
gHitMarker |= (HITMARKER_GRUDGE | HITMARKER_IGNORE_BIDE);

if ((gBattleTypeFlags & BATTLE_TYPE_ARENA)
&& gBattleStruct->arenaTurnCounter == 2
&& IsBattlerAlive(B_POSITION_PLAYER_LEFT) && IsBattlerAlive(B_POSITION_OPPONENT_LEFT))
{
s32 i;

// This seems to be a bug?
for (i = 0; i < 2; i++)
CancelMultiTurnMoves(i);

gBattlescriptCurrInstr = BattleScript_ArenaDoJudgment;
BattleScriptExecute(BattleScript_ArenaDoJudgment);
return TRUE;
}

gHitMarker &= ~(HITMARKER_GRUDGE | HITMARKER_IGNORE_BIDE);

return FALSE;
}
12 changes: 5 additions & 7 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ struct DisableStruct
u8 embargoTimer;
u8 magnetRiseTimer;
u8 telekinesisTimer;
u8 healBlockTimer;
u16 healBlockTimer;
u8 laserFocusTimer;
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
u8 throatChopTimer;
u16 throatChopTimer;
u8 wrapTurns;
u8 syrupBombTimer;
u8 tormentTimer:4; // used for G-Max Meltdown
Expand Down Expand Up @@ -571,7 +571,7 @@ struct ZMoveData

struct DynamaxData
{
u8 dynamaxTurns[MAX_BATTLERS_COUNT];
u16 dynamaxTurns[MAX_BATTLERS_COUNT];
u16 baseMoves[MAX_BATTLERS_COUNT]; // base move of Max Move
u16 lastUsedBaseMove;
};
Expand Down Expand Up @@ -648,9 +648,9 @@ struct BattlerState
struct BattleStruct
{
struct BattlerState battlerState[MAX_BATTLERS_COUNT];
u8 turnEffectsTracker;
u8 eventBlockCounter;
u8 turnEffectsBattlerId;
u8 turnCountersTracker;
u8 endTurnEventsCounter;
u16 wrappedMove[MAX_BATTLERS_COUNT];
u16 moveTarget[MAX_BATTLERS_COUNT];
u32 expShareExpValue;
Expand Down Expand Up @@ -722,8 +722,6 @@ struct BattleStruct
struct LinkBattlerHeader linkBattlerHeader;
struct BattleVideo battleVideo;
} multiBuffer;
u8 wishPerishSongState;
u8 wishPerishSongBattlerId;
u8 startingStatus:6; // status to apply at battle start. defined in constants/battle.h
u8 startingStatusDone:1;
u8 terrainDone:1;
Expand Down
6 changes: 6 additions & 0 deletions include/battle_end_turn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef GUARD_BATTLE_END_TURN
#define GUARD_BATTLE_END_TURN

u32 DoEndTurnEffects(void);

#endif // GUARD_BATTLE_END_TURN
4 changes: 3 additions & 1 deletion include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ extern const u8 BattleScript_SelectingTormentedMoveInPalace[];
extern const u8 BattleScript_SelectingNotAllowedMoveTaunt[];
extern const u8 BattleScript_MoveUsedIsTaunted[];
extern const u8 BattleScript_SelectingNotAllowedMoveTauntInPalace[];
extern const u8 BattleScript_WishButFullHp[];
extern const u8 BattleScript_WishComesTrue[];
extern const u8 BattleScript_IngrainTurnHeal[];
extern const u8 BattleScript_AtkDefDown[];
Expand Down Expand Up @@ -269,7 +270,6 @@ extern const u8 BattleScript_WonderRoomEnds[];
extern const u8 BattleScript_MagicRoomEnds[];
extern const u8 BattleScript_TerrainEnds[];
extern const u8 BattleScript_TerrainEnds_Ret[];
extern const u8 BattleScript_GrassyTerrainEnds[];
extern const u8 BattleScript_MudSportEnds[];
extern const u8 BattleScript_WaterSportEnds[];
extern const u8 BattleScript_SturdiedMsg[];
Expand Down Expand Up @@ -387,6 +387,8 @@ extern const u8 BattleScript_EmergencyExit[];
extern const u8 BattleScript_EmergencyExitNoPopUp[];
extern const u8 BattleScript_EmergencyExitWild[];
extern const u8 BattleScript_EmergencyExitWildNoPopUp[];
extern const u8 BattleScript_EmergencyExitEnd2[];
extern const u8 BattleScript_EmergencyExitWildEnd2[];
extern const u8 BattleScript_CheekPouchActivates[];
extern const u8 BattleScript_TotemVar[];
extern const u8 BattleScript_TotemFlaredToLife[];
Expand Down
8 changes: 5 additions & 3 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum ItemCaseId
ITEMEFFECT_ON_SWITCH_IN,
ITEMEFFECT_ON_SWITCH_IN_FIRST_TURN,
ITEMEFFECT_NORMAL,
ITEMEFFECT_TRY_HEALING,
ITEMEFFECT_MOVE_END,
ITEMEFFECT_KINGSROCK,
ITEMEFFECT_TARGET,
Expand Down Expand Up @@ -171,6 +172,8 @@ enum SleepClauseBlock
};

void HandleAction_ThrowBall(void);
u32 GetCurrentBattleWeather(void);
u32 EndOrContinueWeather(void);
bool32 IsAffectedByFollowMe(u32 battlerAtk, u32 defSide, u32 move);
void HandleAction_UseMove(void);
void HandleAction_Switch(void);
Expand Down Expand Up @@ -203,10 +206,8 @@ u32 TrySetCantSelectMoveBattleScript(u32 battler);
u8 CheckMoveLimitations(u32 battler, u8 unusableMoves, u16 check);
bool32 AreAllMovesUnusable(u32 battler);
u8 GetImprisonedMovesCount(u32 battler, u16 move);
u8 DoFieldEndTurnEffects(void);
s32 GetDrainedBigRootHp(u32 battler, s32 hp);
u8 DoBattlerEndTurnEffects(void);
bool32 HandleWishPerishSongOnTurnEnd(void);
u32 DoEndTurnEffects(void);
bool32 HandleFaintedMonActions(void);
void TryClearRageAndFuryCutter(void);
u32 AtkCanceller_MoveSuccessOrder(void);
Expand Down Expand Up @@ -322,6 +323,7 @@ bool32 CanBeConfused(u32 battler);
bool32 IsBattlerTerrainAffected(u32 battler, u32 terrainFlag);
u32 GetBattlerAffectionHearts(u32 battler);
void TryToRevertMimicryAndFlags(void);
bool32 BattleArenaTurnEnd(void);
u32 CountBattlerStatIncreases(u32 battler, bool32 countEvasionAcc);
bool32 ChangeTypeBasedOnTerrain(u32 battler);
void RemoveConfusionStatus(u32 battler);
Expand Down
2 changes: 1 addition & 1 deletion include/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// still has them in the ROM. This is because the developers forgot
// to define NDEBUG before release, however this has been changed as
// Ruby's actual debug build does not use the AGBPrint features.
#define NDEBUG
// #define NDEBUG

// To enable printf debugging, comment out "#define NDEBUG". This allows
// the various AGBPrint functions to be used. (See include/gba/isagbprint.h).
Expand Down
6 changes: 3 additions & 3 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
// the following checks apply to any target (including user)

// throat chop check
if (gDisableStructs[battlerAtk].throatChopTimer && IsSoundMove(move))
if (gDisableStructs[battlerAtk].throatChopTimer > gBattleTurnCounter && IsSoundMove(move))
return 0; // Can't even select move at all
// heal block check
if (gStatuses3[battlerAtk] & STATUS3_HEAL_BLOCK && IsHealBlockPreventingMove(battlerAtk, move))
Expand Down Expand Up @@ -2460,7 +2460,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
case EFFECT_EMBARGO:
if (aiData->abilities[battlerDef] == ABILITY_KLUTZ
|| gFieldStatuses & STATUS_FIELD_MAGIC_ROOM
|| gDisableStructs[battlerDef].embargoTimer != 0
|| gStatuses3[battlerDef] & STATUS3_EMBARGO
|| PartnerMoveIsSameAsAttacker(BATTLE_PARTNER(battlerAtk), battlerDef, move, aiData->partnerMove))
ADJUST_SCORE(-10);
break;
Expand All @@ -2478,7 +2478,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
ADJUST_SCORE(-10);
break;
case EFFECT_HEAL_BLOCK:
if (gDisableStructs[battlerDef].healBlockTimer != 0
if (gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK
|| PartnerMoveIsSameAsAttacker(BATTLE_PARTNER(battlerAtk), battlerDef, move, aiData->partnerMove))
ADJUST_SCORE(-10);
break;
Expand Down
Loading