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

[battle_engine] Explosion, Mind Blown, Multihit-absorb interaction, Mega-related fixes. #1975

Closed
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
3 changes: 2 additions & 1 deletion asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@
.byte 0x77
.endm

.macro faintifabilitynotdamp
@ previously faintifabilitynotdamp
.macro canpursuitusermegaevolve
.byte 0x78
.endm

Expand Down
1 change: 1 addition & 0 deletions charmap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ B_DEF_TEAM1 = FD 3A
B_DEF_TEAM2 = FD 3B
B_ACTIVE_NAME = FD 3C
B_ACTIVE_NAME2 = FD 3D @ no Illusion check
B_BATTLER_ABILITY_NAME_WITH_PREFIX = FD 3E @ uses gBattlerAbility, as the ability pop up battlescript

@ indicates the end of a town/city name (before " TOWN" or " CITY")
NAME_END = FC 00
Expand Down
129 changes: 50 additions & 79 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,19 @@ BattleScript_EffectPlaceholder:
pause 5
printstring STRINGID_NOTDONEYET
goto BattleScript_MoveEnd

BattleScript_EffectMindBlown::
BattleScript_EffectExplosion::
attackcanceler
attackstring
ppreduce
attackanimation
waitanimation
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
critcalc
damagecalc
adjustdamage
goto BattleScript_HitFromEffectivenessSound

BattleScript_EffectHit::
BattleScript_HitFromAtkCanceler::
Expand All @@ -2638,6 +2651,7 @@ BattleScript_HitFromCritCalc::
BattleScript_HitFromAtkAnimation::
attackanimation
waitanimation
BattleScript_HitFromEffectivenessSound:
effectivenesssound
hitanimation BS_TARGET
waitstate
Expand Down Expand Up @@ -2878,69 +2892,6 @@ BattleScript_EffectParalyzeHit::
setmoveeffect MOVE_EFFECT_PARALYSIS
goto BattleScript_EffectHit

BattleScript_EffectExplosion::
attackcanceler
attackstring
ppreduce
faintifabilitynotdamp
setatkhptozero
waitstate
jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionDoAnimStartLoop
call BattleScript_PreserveMissedBitDoMoveAnim
goto BattleScript_ExplosionLoop
BattleScript_ExplosionDoAnimStartLoop:
attackanimation
waitanimation
BattleScript_ExplosionLoop:
movevaluescleanup
critcalc
damagecalc
adjustdamage
accuracycheck BattleScript_ExplosionMissed, ACC_CURR_MOVE
effectivenesssound
hitanimation BS_TARGET
waitstate
healthbarupdate BS_TARGET
datahpupdate BS_TARGET
critmessage
waitmessage B_WAIT_TIME_LONG
resultmessage
waitmessage B_WAIT_TIME_LONG
tryfaintmon BS_TARGET, FALSE, NULL
moveendto MOVEEND_NEXT_TARGET
jumpifnexttargetvalid BattleScript_ExplosionLoop
tryfaintmon BS_ATTACKER, FALSE, NULL
moveendcase MOVEEND_CLEAR_BITS
end
BattleScript_ExplosionMissed:
effectivenesssound
resultmessage
waitmessage B_WAIT_TIME_LONG
moveendto MOVEEND_NEXT_TARGET
jumpifnexttargetvalid BattleScript_ExplosionLoop
tryfaintmon BS_ATTACKER, FALSE, NULL
end

BattleScript_EffectMindBlown::
attackcanceler
attackstring
ppreduce
faintifabilitynotdamp
dmg_1_2_attackerhp
healthbarupdate BS_ATTACKER
datahpupdate BS_ATTACKER
waitstate
jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionDoAnimStartLoop
call BattleScript_PreserveMissedBitDoMoveAnim
goto BattleScript_ExplosionLoop

BattleScript_PreserveMissedBitDoMoveAnim:
bichalfword gMoveResultFlags, MOVE_RESULT_MISSED
attackanimation
waitanimation
orhalfword gMoveResultFlags, MOVE_RESULT_MISSED
return

BattleScript_EffectDreamEater::
attackcanceler
jumpifsubstituteblocks BattleScript_DreamEaterNoEffect
Expand Down Expand Up @@ -4958,6 +4909,14 @@ BattleScript_ButItFailed::
resultmessage
waitmessage B_WAIT_TIME_LONG
goto BattleScript_MoveEnd

BattleScript_ExplosionInVoid::
attackstring
bichalfword gMoveResultFlags, MOVE_RESULT_FAILED @ to avoid getting "but it failed" and thus not play the animation
attackanimation
waitanimation
orhalfword gMoveResultFlags, MOVE_RESULT_FAILED @ restores the flag
goto BattleScript_ButItFailedPpReduce

BattleScript_NotAffected::
pause B_WAIT_TIME_SHORT
Expand Down Expand Up @@ -6109,6 +6068,7 @@ BattleScript_DoSwitchOut2:

BattleScript_PursuitDmgOnSwitchOut::
pause B_WAIT_TIME_SHORT
canpursuitusermegaevolve
attackstring
ppreduce
critcalc
Expand Down Expand Up @@ -7107,20 +7067,25 @@ BattleScript_FocusPunchSetUp::

BattleScript_MegaEvolution::
printstring STRINGID_MEGAEVOREACTING
waitmessage B_WAIT_TIME_LONG
setbyte gIsCriticalHit, 0
handlemegaevo BS_ATTACKER, 0
handlemegaevo BS_ATTACKER, 1
playanimation BS_ATTACKER, B_ANIM_MEGA_EVOLUTION, NULL
waitanimation
handlemegaevo BS_ATTACKER, 2
printstring STRINGID_MEGAEVOEVOLVED
waitmessage B_WAIT_TIME_LONG
switchinabilities BS_ATTACKER
call BattleScript_MegaEvolutionExecution
end2

BattleScript_WishMegaEvolution::
printstring STRINGID_FERVENTWISHREACHED
call BattleScript_MegaEvolutionExecution
end2

BattleScript_MegaEvolutionPursuit::
printstring STRINGID_MEGAEVOREACTING
call BattleScript_MegaEvolutionExecution
return

BattleScript_WishMegaEvolutionPursuit::
printstring STRINGID_FERVENTWISHREACHED
call BattleScript_MegaEvolutionExecution
return

BattleScript_MegaEvolutionExecution:: @ for pursuit and it's better to have only one anyway
waitmessage B_WAIT_TIME_LONG
setbyte gIsCriticalHit, 0
handlemegaevo BS_ATTACKER, 0
Expand All @@ -7131,7 +7096,7 @@ BattleScript_WishMegaEvolution::
printstring STRINGID_MEGAEVOEVOLVED
waitmessage B_WAIT_TIME_LONG
switchinabilities BS_ATTACKER
end2
return

BattleScript_PrimalReversion::
printstring STRINGID_EMPTYSTRING3
Expand Down Expand Up @@ -7607,6 +7572,14 @@ BattleScript_DoRecoil::
tryfaintmon BS_ATTACKER, FALSE, NULL
BattleScript_RecoilEnd::
return

BattleScript_DoRecoilNoString:: @ mind blown, explosion
orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE | HITMARKER_IGNORE_DISGUISE
healthbarupdate BS_ATTACKER
datahpupdate BS_ATTACKER
pause B_WAIT_TIME_SHORT
tryfaintmon BS_ATTACKER, FALSE, NULL
return

BattleScript_EffectWithChance::
seteffectwithchance
Expand Down Expand Up @@ -8037,12 +8010,11 @@ BattleScript_SturdyPreventsOHKO::
goto BattleScript_MoveEnd

BattleScript_DampStopsExplosion::
call BattleScript_FlushMessageBox @ smother transition when our second poke uses explosion in double
pause B_WAIT_TIME_SHORT
copybyte gBattlerAbility, gBattlerTarget
call BattleScript_AbilityPopUp
printstring STRINGID_PKMNPREVENTSUSAGE
pause B_WAIT_TIME_LONG
moveendto MOVEEND_NEXT_TARGET
moveendcase MOVEEND_CLEAR_BITS
end

Expand Down Expand Up @@ -8072,7 +8044,7 @@ BattleScript_MoveStatDrain::
printstring STRINGID_TARGETABILITYSTATRAISE
waitmessage B_WAIT_TIME_LONG
clearsemiinvulnerablebit
tryfaintmon BS_ATTACKER, FALSE, NULL
orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE
goto BattleScript_MoveEnd

BattleScript_MonMadeMoveUseless_PPLoss::
Expand All @@ -8083,7 +8055,6 @@ BattleScript_MonMadeMoveUseless::
call BattleScript_AbilityPopUp
printstring STRINGID_PKMNSXMADEYUSELESS
waitmessage B_WAIT_TIME_LONG
tryfaintmon BS_ATTACKER, FALSE, NULL
orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE
goto BattleScript_MoveEnd

Expand All @@ -8095,7 +8066,7 @@ BattleScript_FlashFireBoost::
call BattleScript_AbilityPopUp
printfromtable gFlashFireStringIds
waitmessage B_WAIT_TIME_LONG
tryfaintmon BS_ATTACKER, FALSE, NULL
orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE
goto BattleScript_MoveEnd

BattleScript_AbilityPreventsPhasingOut::
Expand Down
10 changes: 6 additions & 4 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define GET_BATTLER_POSITION(battler) (gBattlerPositions[battler])
#define GET_BATTLER_SIDE(battler) (GetBattlerPosition(battler) & BIT_SIDE)
#define GET_BATTLER_SIDE2(battler) (GET_BATTLER_POSITION(battler) & BIT_SIDE)

// Battle Actions
// These determine what each battler will do in a turn
#define B_ACTION_USE_MOVE 0
Expand Down Expand Up @@ -474,8 +474,10 @@ struct MegaEvolutionData
u8 battlerId;
bool8 playerSelect;
u8 triggerSpriteId;
bool8 isWishMegaEvo;
bool8 isWishMegaEvo[4]; // array to check whether the mega to be executed will be wish.
bool8 isPrimalReversion;
u8 megaEvoWasDone; // used after executing the battlescript for mega evolution, to set gCurrentActionFuncId back to B_ACTION_USE_MOVE and not bypass the
// fastest mon's turn. Mega evolutions are done one by one, so a single byte (even bit) is enough
};

struct Illusion
Expand Down Expand Up @@ -792,8 +794,8 @@ struct MonSpritesGfx
void* firstDecompressed; // ptr to the decompressed sprite of the first pokemon
union
{
void* ptr[4];
u8* byte[4];
void* ptr[4];
u8* byte[4];
} sprites;
struct SpriteTemplate templates[4];
struct SpriteFrameImage field_74[4][4];
Expand Down
1 change: 1 addition & 0 deletions include/battle_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#define B_TXT_DEF_TEAM2 0x3B // your/the opposing
#define B_TXT_ACTIVE_NAME 0x3C
#define B_TXT_ACTIVE_NAME2 0x3D // no Illusion check
#define B_TXT_BATTLER_ABILITY_NAME_WITH_PREFIX 0x3E // uses gBattlerAbility, as the pop up ability battlescript

// for B_TXT_BUFF1, B_TXT_BUFF2 and B_TXT_BUFF3

Expand Down
6 changes: 6 additions & 0 deletions include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ extern const u8 BattleScript_MoveEffectPayDay[];
extern const u8 BattleScript_MoveEffectWrap[];
extern const u8 BattleScript_MoveEffectConfusion[];
extern const u8 BattleScript_MoveEffectRecoil[];
extern const u8 BattleScript_DoRecoil[];
extern const u8 BattleScript_DoRecoilNoString[];
extern const u8 BattleScript_DoRecoil33[];
extern const u8 BattleScript_Recoil33End[];
extern const u8 BattleScript_ItemSteal[];
Expand All @@ -158,6 +160,7 @@ extern const u8 BattleScript_DroughtActivates[];
extern const u8 BattleScript_TookAttack[];
extern const u8 BattleScript_SturdyPreventsOHKO[];
extern const u8 BattleScript_DampStopsExplosion[];
extern const u8 BattleScript_ExplosionInVoid[];
extern const u8 BattleScript_MoveHPDrain_PPLoss[];
extern const u8 BattleScript_MoveHPDrain[];
extern const u8 BattleScript_MonMadeMoveUseless_PPLoss[];
Expand Down Expand Up @@ -284,7 +287,10 @@ extern const u8 BattleScript_ToxicSpikesFree[];
extern const u8 BattleScript_StickyWebFree[];
extern const u8 BattleScript_StealthRockFree[];
extern const u8 BattleScript_MegaEvolution[];
extern const u8 BattleScript_MegaEvolutionPursuit[];
extern const u8 BattleScript_WishMegaEvolution[];
extern const u8 BattleScript_WishMegaEvolutionPursuit[];
extern const u8 BattleScript_MegaEvolutionExecution[];
extern const u8 BattleScript_MoveEffectRecoilWithStatus[];
extern const u8 BattleScript_EffectWithChance[];
extern const u8 BattleScript_MoveEffectClearSmog[];
Expand Down
19 changes: 10 additions & 9 deletions include/constants/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,16 @@
#define MOVEEND_UPDATE_LAST_MOVES 18
#define MOVEEND_MIRROR_MOVE 19
#define MOVEEND_NEXT_TARGET 20 // Everything up until here is handled for each strike of a multi-hit move
#define MOVEEND_EJECT_BUTTON 21
#define MOVEEND_RED_CARD 22
#define MOVEEND_EJECT_PACK 23
#define MOVEEND_LIFEORB_SHELLBELL 24 // Includes shell bell, throat spray, etc
#define MOVEEND_PICKPOCKET 25
#define MOVEEND_DANCER 26
#define MOVEEND_EMERGENCY_EXIT 27
#define MOVEEND_CLEAR_BITS 28
#define MOVEEND_COUNT 29
#define MOVEEND_KO_USER 21 // Explosion like move, also mind blown
#define MOVEEND_EJECT_BUTTON 22
#define MOVEEND_RED_CARD 23
#define MOVEEND_EJECT_PACK 24
#define MOVEEND_LIFEORB_SHELLBELL 25 // Includes shell bell, throat spray, etc
#define MOVEEND_PICKPOCKET 26
#define MOVEEND_DANCER 27
#define MOVEEND_EMERGENCY_EXIT 28
#define MOVEEND_CLEAR_BITS 29
#define MOVEEND_COUNT 30

// switch cases
#define B_SWITCH_NORMAL 0
Expand Down
Loading