Skip to content

Commit

Permalink
Adds Commander and Order Up (#5246)
Browse files Browse the repository at this point in the history
* Adds Commander

* review points

* new line

* correction

* regression / double targeting still broken

* fix wrong target order

* transform fixes

* haze test

* fixes, tests

* bring back wrongly removed else if case

* Eject Pack / Button test + fix

* red card fix

* test fixes

* Fixes Tatsu being hit by multi hit move

* change transform check

* fix test + revert change

* Fix Tatsugiri attacking after freed up from Dozo in the same turn

* Dragon Darts tests

* fix test

* review comments

* assumtion in wrong file

* Order Up test fixes

---------

Co-authored-by: hedara90 <[email protected]>
  • Loading branch information
AlexOn1ine and hedara90 authored Sep 29, 2024
1 parent 8d33169 commit 42c43a3
Show file tree
Hide file tree
Showing 20 changed files with 872 additions and 44 deletions.
6 changes: 5 additions & 1 deletion asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,6 @@
.4byte \func
.endm

@ callnative macros
.macro savetarget
callnative BS_SaveTarget
.endm
Expand Down Expand Up @@ -1727,6 +1726,11 @@
.4byte \failInstr
.endm

.macro jumpifcommanderactive jumpInstr:req
callnative BS_JumpIfCommanderActive
.4byte \jumpInstr
.endm

@ various command changed to more readable macros
.macro cancelmultiturnmoves battler:req
various \battler, VARIOUS_CANCEL_MULTI_TURN_MOVES
Expand Down
52 changes: 51 additions & 1 deletion data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -3265,6 +3265,7 @@ BattleScript_EffectRoar::
attackstring
ppreduce
jumpifroarfails BattleScript_ButItFailed
jumpifcommanderactive BattleScript_ButItFailed
jumpifability BS_TARGET, ABILITY_GUARD_DOG, BattleScript_ButItFailed
jumpifability BS_TARGET, ABILITY_SUCTION_CUPS, BattleScript_AbilityPreventsPhasingOut
jumpifstatus3 BS_TARGET, STATUS3_ROOTED, BattleScript_PrintMonIsRooted
Expand Down Expand Up @@ -8008,11 +8009,52 @@ BattleScript_CostarActivates::

BattleScript_ZeroToHeroActivates::
pause B_WAIT_TIME_SHORT
call BattleScript_AbilityPopUp
call BattleScript_AbilityPopUpScripting
printstring STRINGID_ZEROTOHEROTRANSFORMATION
waitmessage B_WAIT_TIME_LONG
end3

BattleScript_CommanderActivates::
pause B_WAIT_TIME_SHORT
call BattleScript_AbilityPopUpScripting
printstring STRINGID_COMMANDERACTIVATES
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderAtkIncrease:
setbyte sSTAT_ANIM_PLAYED, FALSE
playstatchangeanimation BS_ATTACKER, BIT_ATK | BIT_DEF | BIT_SPATK | BIT_SPDEF | BIT_SPEED, STAT_CHANGE_BY_TWO
setstatchanger STAT_ATK, 2, FALSE
statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_ALLOW_PTR, BattleScript_CommanderDefIncrease
jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_CommanderDefIncrease
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderDefIncrease:
setstatchanger STAT_DEF, 2, FALSE
statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_ALLOW_PTR, BattleScript_CommanderSpAtkIncrease
jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_CommanderSpAtkIncrease
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderSpAtkIncrease:
setstatchanger STAT_SPATK, 2, FALSE
statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_ALLOW_PTR, BattleScript_CommanderSpDefIncrease
jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_CommanderSpDefIncrease
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderSpDefIncrease:
setstatchanger STAT_SPDEF, 2, FALSE
statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_ALLOW_PTR, BattleScript_CommanderSpeedIncrease
jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_CommanderSpeedIncrease
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderSpeedIncrease:
setstatchanger STAT_SPEED, 2, FALSE
statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_ALLOW_PTR, BattleScript_CommanderEnd
jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_CommanderEnd
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
BattleScript_CommanderEnd:
restoreattacker
end3

BattleScript_HospitalityActivates::
pause B_WAIT_TIME_SHORT
call BattleScript_AbilityPopUp
Expand Down Expand Up @@ -9533,6 +9575,14 @@ BattleScript_StickyBarbTransfer::
removeitem BS_TARGET
return

BattleScript_RedCardActivationNoSwitch::
playanimation BS_SCRIPTING, B_ANIM_HELD_ITEM_EFFECT
printstring STRINGID_REDCARDACTIVATE
waitmessage B_WAIT_TIME_LONG
removeitem BS_SCRIPTING
restoretarget
return

BattleScript_RedCardActivates::
playanimation BS_SCRIPTING, B_ANIM_HELD_ITEM_EFFECT
printstring STRINGID_REDCARDACTIVATE
Expand Down
7 changes: 7 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ struct ProtectStruct
u16 eatMirrorHerb:1;
u16 activateOpportunist:2; // 2 - to copy stats. 1 - stats copied (do not repeat). 0 - no stats to copy
u16 usedAllySwitch:1;
u16 padding:2;
// End of 16-bit bitfield
u32 physicalDmg;
u32 specialDmg;
u8 physicalBattlerId;
u8 specialBattlerId;

};

struct SpecialStatus
Expand Down Expand Up @@ -818,9 +821,13 @@ struct BattleStruct
u8 boosterEnergyActivates;
u8 distortedTypeMatchups;
u8 categoryOverride; // for Z-Moves and Max Moves
u8 commandingDondozo;
u16 commanderActive[NUM_BATTLE_SIDES];
u32 stellarBoostFlags[NUM_BATTLE_SIDES]; // stored as a bitfield of flags for all types for each side
u8 fickleBeamBoosted:1;
u8 obedienceResult:3;
u8 padding:4;
u8 usedEjectItem;
u8 usedMicleBerry;
};

Expand Down
2 changes: 2 additions & 0 deletions include/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ bool32 IsMoveNotAllowedInSkyBattles(u32 move);
bool32 DoSwitchInAbilities(u32 battlerId);
u8 GetFirstFaintedPartyIndex(u8 battlerId);
bool32 IsMoveAffectedByParentalBond(u32 move, u32 battler);
void SaveBattlerTarget(u32 battler);
void SaveBattlerAttacker(u32 battler);

extern void (* const gBattleScriptingCommandsTable[])(void);
extern const struct StatFractions gAccuracyStageRatios[];
Expand Down
2 changes: 2 additions & 0 deletions include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ extern const u8 BattleScript_BattlerGotOverItsInfatuation[];
extern const u8 BattleScript_Pickpocket[];
extern const u8 BattleScript_StickyBarbTransfer[];
extern const u8 BattleScript_AttackerItemStatRaise[];
extern const u8 BattleScript_RedCardActivationNoSwitch[];
extern const u8 BattleScript_RedCardActivates[];
extern const u8 BattleScript_EjectButtonActivates[];
extern const u8 BattleScript_EjectPackActivate_Ret[];
Expand Down Expand Up @@ -477,6 +478,7 @@ extern const u8 BattleScript_CudChewActivates[];
extern const u8 BattleScript_SupremeOverlordActivates[];
extern const u8 BattleScript_CostarActivates[];
extern const u8 BattleScript_ZeroToHeroActivates[];
extern const u8 BattleScript_CommanderActivates[];
extern const u8 BattleScript_HospitalityActivates[];
extern const u8 BattleScript_ToxicDebrisActivates[];
extern const u8 BattleScript_EarthEaterActivates[];
Expand Down
8 changes: 5 additions & 3 deletions include/constants/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
#define STATUS3_YAWN_TURN(num) (((num) << 11) & STATUS3_YAWN)
#define STATUS3_IMPRISONED_OTHERS (1 << 13)
#define STATUS3_GRUDGE (1 << 14)
#define STATUS3___UNUSED (1 << 15)
#define STATUS3_COMMANDER (1 << 15)
#define STATUS3_GASTRO_ACID (1 << 16)
#define STATUS3_EMBARGO (1 << 17)
#define STATUS3_UNDERWATER (1 << 18)
Expand All @@ -183,7 +183,8 @@
#define STATUS3_LASER_FOCUS (1 << 29)
#define STATUS3_POWER_TRICK (1 << 30)
#define STATUS3_SKY_DROPPED (1 << 31) // Target of Sky Drop
#define STATUS3_SEMI_INVULNERABLE (STATUS3_UNDERGROUND | STATUS3_ON_AIR | STATUS3_UNDERWATER | STATUS3_PHANTOM_FORCE)
#define STATUS3_SEMI_INVULNERABLE_NO_COMMANDER (STATUS3_UNDERGROUND | STATUS3_ON_AIR | STATUS3_UNDERWATER | STATUS3_PHANTOM_FORCE) // Exception for Transform / Imposter
#define STATUS3_SEMI_INVULNERABLE (STATUS3_SEMI_INVULNERABLE_NO_COMMANDER | STATUS3_COMMANDER)

#define STATUS4_ELECTRIFIED (1 << 0)
#define STATUS4_MUD_SPORT (1 << 1) // Only used if B_SPORT_TURNS < GEN_6
Expand Down Expand Up @@ -401,8 +402,9 @@
#define MOVE_EFFECT_SECRET_POWER 77
#define MOVE_EFFECT_PSYCHIC_NOISE 78
#define MOVE_EFFECT_TERA_BLAST 79
#define MOVE_EFFECT_ORDER_UP 80

#define NUM_MOVE_EFFECTS 80
#define NUM_MOVE_EFFECTS 81

#define MOVE_EFFECT_AFFECTS_USER 0x2000
#define MOVE_EFFECT_CERTAIN 0x4000
Expand Down
1 change: 1 addition & 0 deletions include/constants/battle_move_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ enum {
EFFECT_DRAGON_DARTS,
EFFECT_GUARDIAN_OF_ALOLA,
EFFECT_SHELL_SIDE_ARM,
EFFECT_ORDER_UP,
NUM_BATTLE_MOVE_EFFECTS,
};

Expand Down
3 changes: 2 additions & 1 deletion include/constants/battle_string_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,9 @@
#define STRINGID_FOGLIFTED 710
#define STRINGID_PKMNMADESHELLGLEAM 711
#define STRINGID_FICKLEBEAMDOUBLED 712
#define STRINGID_COMMANDERACTIVATES 713

#define BATTLESTRINGS_COUNT 713
#define BATTLESTRINGS_COUNT 714

// This is the string id that gBattleStringsTable starts with.
// String ids before this (e.g. STRINGID_INTROMSG) are not in the table,
Expand Down
3 changes: 3 additions & 0 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,9 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
if (IsTwoTurnNotSemiInvulnerableMove(battlerAtk, move) && CanTargetFaintAi(battlerDef, battlerAtk))
RETURN_SCORE_MINUS(10);

if (gBattleStruct->commandingDondozo & (1u << battlerDef))
RETURN_SCORE_MINUS(20);

// check if negates type
switch (effectiveness)
{
Expand Down
5 changes: 5 additions & 0 deletions src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ bool32 IsDamageMoveUnusable(u32 move, u32 battlerAtk, u32 battlerDef)
if (battlerDef == BATTLE_PARTNER(battlerAtk))
battlerDefAbility = aiData->abilities[battlerDef];

if (gBattleStruct->commandingDondozo & (1u << battlerDef))
return TRUE;

switch (battlerDefAbility)
{
case ABILITY_LIGHTNING_ROD:
Expand Down Expand Up @@ -1508,6 +1511,8 @@ bool32 IsSemiInvulnerable(u32 battlerDef, u32 move)
{
if (gStatuses3[battlerDef] & STATUS3_PHANTOM_FORCE)
return TRUE;
else if (gBattleStruct->commandingDondozo & (1u << battlerDef))
return TRUE;
else if (!gMovesInfo[move].damagesAirborne && gStatuses3[battlerDef] & STATUS3_ON_AIR)
return TRUE;
else if (!gMovesInfo[move].damagesUnderwater && gStatuses3[battlerDef] & STATUS3_UNDERWATER)
Expand Down
16 changes: 15 additions & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,16 @@ const u8* FaintClearSetData(u32 battler)
gBattleStruct->palaceFlags &= ~(1u << battler);
gBattleStruct->boosterEnergyActivates &= ~(1u << battler);

if (gBattleStruct->commanderActive[battler] != SPECIES_NONE)
{
u32 partner = BATTLE_PARTNER(battler);
if (IsBattlerAlive(partner))
{
BtlController_EmitSpriteInvisibility(partner, BUFFER_A, FALSE);
MarkBattlerForControllerExec(partner);
}
}

for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{
// User of sticky web fainted, so reset the stored battler ID
Expand Down Expand Up @@ -4194,7 +4204,7 @@ static void HandleTurnActionSelectionState(void)
|| gBattleStruct->absentBattlerFlags & (1u << GetBattlerAtPosition(BATTLE_PARTNER(position)))
|| gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == STATE_WAIT_ACTION_CONFIRMED)
{
if (gBattleStruct->absentBattlerFlags & (1u << battler))
if ((gBattleStruct->absentBattlerFlags & (1u << battler)) || (gBattleStruct->commandingDondozo & (1u << battler)))
{
gChosenActionByBattler[battler] = B_ACTION_NOTHING_FAINTED;
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
Expand Down Expand Up @@ -5116,6 +5126,9 @@ static void TurnValuesCleanUp(bool8 var0)
if (gDisableStructs[i].substituteHP == 0)
gBattleMons[i].status2 &= ~STATUS2_SUBSTITUTE;

if (!(gStatuses3[i] & STATUS3_COMMANDER))
gBattleStruct->commandingDondozo &= ~(1u << i);

gSpecialStatuses[i].parentalBondState = PARENTAL_BOND_OFF;
}

Expand All @@ -5124,6 +5137,7 @@ static void TurnValuesCleanUp(bool8 var0)
gSideTimers[B_SIDE_PLAYER].followmeTimer = 0;
gSideTimers[B_SIDE_OPPONENT].followmeTimer = 0;

gBattleStruct->usedEjectItem = 0;
gBattleStruct->pledgeMove = FALSE; // combined pledge move may not have been used due to a canceller
}

Expand Down
4 changes: 3 additions & 1 deletion src/battle_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ static const u8 sText_TargetIsBeingSaltCured[] = _("{B_DEF_NAME_WITH_PREFIX} is
static const u8 sText_TargetIsHurtBySaltCure[] = _("{B_DEF_NAME_WITH_PREFIX} is hurt by {B_BUFF1}!");
static const u8 sText_TargetCoveredInStickyCandySyrup[] = _("{B_DEF_NAME_WITH_PREFIX} got covered\nin sticky syrup!");
static const u8 sText_PkmnTellChillingReceptionJoke[] = _("{B_ATK_NAME_WITH_PREFIX} is preparing to tell a\nchillingly bad joke!");
static const u8 sText_ZeroToHeroTransformation[] = _("{B_ATK_NAME_WITH_PREFIX} underwent a heroic\ntransformation!");
static const u8 sText_ZeroToHeroTransformation[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} underwent a heroic\ntransformation!");
static const u8 sText_CommanderActivates[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} was swallowed by Dondozo\nand became Dondozo's commander!");
static const u8 sText_TheTwoMovesBecomeOne[] = _("The two moves become one!\nIt's a combined move!{PAUSE 16}");
static const u8 sText_ARainbowAppearedOnSide[] = _("A rainbow appeared in the sky\non {B_ATK_TEAM2} team's side!");
static const u8 sText_TheRainbowDisappeared[] = _("The rainbow on {B_ATK_TEAM2}\nside disappeared!");
Expand Down Expand Up @@ -869,6 +870,7 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] =
[STRINGID_ARAINBOWAPPEAREDONSIDE - BATTLESTRINGS_TABLE_START] = sText_ARainbowAppearedOnSide,
[STRINGID_THETWOMOVESBECOMEONE - BATTLESTRINGS_TABLE_START] = sText_TheTwoMovesBecomeOne,
[STRINGID_ZEROTOHEROTRANSFORMATION - BATTLESTRINGS_TABLE_START] = sText_ZeroToHeroTransformation,
[STRINGID_COMMANDERACTIVATES - BATTLESTRINGS_TABLE_START] = sText_CommanderActivates,
[STRINGID_PKMNTELLCHILLINGRECEPTIONJOKE - BATTLESTRINGS_TABLE_START] = sText_PkmnTellChillingReceptionJoke,
[STRINGID_MOVEBLOCKEDBYDYNAMAX - BATTLESTRINGS_TABLE_START] = sText_MoveBlockedByDynamax,
[STRINGID_TARGETISHURTBYSALTCURE - BATTLESTRINGS_TABLE_START] = sText_TargetIsHurtBySaltCure,
Expand Down
Loading

0 comments on commit 42c43a3

Please sign in to comment.