From 9d4d8c5dac8b98b23a456677360ad947228931c7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 21 Jul 2018 15:11:13 +0200 Subject: [PATCH] Add new Sturdy effect --- asm/macros/battle_script.inc | 2 +- data/battle_scripts_1.s | 54 +++++++++++++++------------ include/battle.h | 3 +- include/battle_scripts.h | 1 + include/constants/battle.h | 1 + src/battle_main.c | 2 +- src/battle_script_commands.c | 71 +++++++++++++++++++++++++++++------- 7 files changed, 93 insertions(+), 41 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 1b3cd28a8..03f0196d7 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -33,7 +33,7 @@ .byte 0x7 .endm - .macro nop_08 + .macro multihitresultmessage .byte 0x8 .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index f47bbbf90..52fe703a3 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -442,10 +442,10 @@ BattleScript_82D8BCF:: end BattleScript_82D8BEA:: - bicbyte gMoveResultFlags, MOVE_RESULT_MISSED + bichalfword gMoveResultFlags, MOVE_RESULT_MISSED attackanimation waitanimation - orbyte gMoveResultFlags, MOVE_RESULT_MISSED + orhalfword gMoveResultFlags, MOVE_RESULT_MISSED return BattleScript_EffectDreamEater:: @@ -492,7 +492,7 @@ BattleScript_EffectMirrorMove:: pause 0x40 trymirrormove ppreduce - orbyte gMoveResultFlags, MOVE_RESULT_FAILED + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED printstring STRINGID_MIRRORMOVEFAILED waitmessage 0x40 goto BattleScript_MoveEnd @@ -655,6 +655,7 @@ BattleScript_DoMultiHit:: datahpupdate BS_TARGET critmessage waitmessage 0x40 + multihitresultmessage printstring STRINGID_EMPTYSTRING3 waitmessage 0x1 addbyte sMULTIHIT_STRING + 4, 0x1 @@ -839,7 +840,7 @@ BattleScript_EffectSuperFang:: attackstring ppreduce typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE damagetohalftargethp goto BattleScript_HitFromAtkAnimation @@ -849,7 +850,7 @@ BattleScript_EffectDragonRage:: attackstring ppreduce typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE setword gBattleMoveDamage, 40 adjustdamage goto BattleScript_HitFromAtkAnimation @@ -889,12 +890,12 @@ BattleScript_MoveMissedDoDamage:: typecalc adjustdamage manipulatedamage ATK80_DMG_HALF_BY_TWO_NOT_MORE_THAN_HALF_MAX_HP - bicbyte gMoveResultFlags, MOVE_RESULT_MISSED + bichalfword gMoveResultFlags, MOVE_RESULT_MISSED orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER tryfaintmon BS_ATTACKER, FALSE, NULL - orbyte gMoveResultFlags, MOVE_RESULT_MISSED + orhalfword gMoveResultFlags, MOVE_RESULT_MISSED goto BattleScript_MoveEnd BattleScript_EffectMist:: @@ -1224,7 +1225,7 @@ BattleScript_EffectLevelDamage:: attackstring ppreduce typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE dmgtolevel adjustdamage goto BattleScript_HitFromAtkAnimation @@ -1235,7 +1236,7 @@ BattleScript_EffectPsywave:: attackstring ppreduce typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE psywavedamageeffect adjustdamage goto BattleScript_HitFromAtkAnimation @@ -1443,7 +1444,7 @@ BattleScript_DoTripleKickAttack:: BattleScript_TripleKickNoMoreHits:: pause 0x20 jumpifbyte CMP_EQUAL, sMULTIHIT_STRING + 4, 0x0, BattleScript_TripleKickPrintStrings - bicbyte gMoveResultFlags, MOVE_RESULT_MISSED + bichalfword gMoveResultFlags, MOVE_RESULT_MISSED BattleScript_TripleKickPrintStrings:: resultmessage waitmessage 0x40 @@ -1737,7 +1738,7 @@ BattleScript_EffectSonicboom:: attackstring ppreduce typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE setword gBattleMoveDamage, 20 adjustdamage goto BattleScript_HitFromAtkAnimation @@ -2065,14 +2066,14 @@ BattleScript_ButItFailedPpReduce:: ppreduce BattleScript_ButItFailed:: pause 0x20 - orbyte gMoveResultFlags, MOVE_RESULT_FAILED + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED resultmessage waitmessage 0x40 goto BattleScript_MoveEnd BattleScript_NotAffected:: pause 0x20 - orbyte gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE + orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE resultmessage waitmessage 0x40 goto BattleScript_MoveEnd @@ -2414,7 +2415,7 @@ BattleScript_EffectBrickBreak:: damagecalc adjustdamage jumpifbyte CMP_EQUAL, sB_ANIM_TURN, 0x0, BattleScript_BrickBreakAnim - bicbyte gMoveResultFlags, MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE + bichalfword gMoveResultFlags, MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE BattleScript_BrickBreakAnim:: attackanimation waitanimation @@ -2473,7 +2474,7 @@ BattleScript_EffectEndeavor:: accuracycheck BattleScript_MoveMissedPause, ACC_CURR_MOVE typecalc jumpifmovehadnoeffect BattleScript_HitFromAtkAnimation - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE copyword gBattleMoveDamage, gHpDealt adjustdamage goto BattleScript_HitFromAtkAnimation @@ -2656,7 +2657,7 @@ BattleScript_TickleEnd:: BattleScript_CantLowerMultipleStats:: pause 0x20 - orbyte gMoveResultFlags, MOVE_RESULT_FAILED + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED printstring STRINGID_STATSWONTDECREASE2 waitmessage 0x40 goto BattleScript_MoveEnd @@ -2742,7 +2743,7 @@ BattleScript_CalmMindEnd:: BattleScript_CantRaiseMultipleStats:: pause 0x20 - orbyte gMoveResultFlags, MOVE_RESULT_FAILED + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED printstring STRINGID_STATSWONTINCREASE2 waitmessage 0x40 goto BattleScript_MoveEnd @@ -3330,7 +3331,7 @@ BattleScript_BideAttack:: waitmessage 0x40 accuracycheck BattleScript_MoveMissed, ACC_CURR_MOVE typecalc - bicbyte gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE + bichalfword gMoveResultFlags, MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE copyword gBattleMoveDamage, sBIDE_DMG adjustdamage setbyte sB_ANIM_TURN, 0x1 @@ -3572,16 +3573,16 @@ BattleScript_FutureAttackEnd:: moveend 0x1, 0x0 setbyte sMOVEEND_STATE, 0xB moveend 0x2, 0xE - setbyte gMoveResultFlags, 0 + sethword gMoveResultFlags, 0 end2 BattleScript_FutureAttackMiss:: pause 0x20 - setbyte gMoveResultFlags, 0 - orbyte gMoveResultFlags, MOVE_RESULT_FAILED + sethword gMoveResultFlags, 0 + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED resultmessage waitmessage 0x40 - setbyte gMoveResultFlags, 0 + sethword gMoveResultFlags, 0 end2 BattleScript_NoMovesLeft:: @@ -3734,6 +3735,11 @@ BattleScript_EnduredMsg:: printstring STRINGID_PKMNENDUREDHIT waitmessage 0x40 return + +BattleScript_SturdiedMsg:: + printstring STRINGID_ENDUREDSTURDY + waitmessage 0x40 + return BattleScript_OneHitKOMsg:: printstring STRINGID_ONEHITKO @@ -4151,7 +4157,7 @@ BattleScript_MoveHPDrain:: datahpupdate BS_TARGET printstring STRINGID_PKMNRESTOREDHPUSING waitmessage 0x40 - orbyte gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE + orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE goto BattleScript_MoveEnd BattleScript_MonMadeMoveUseless_PPLoss:: @@ -4161,7 +4167,7 @@ BattleScript_MonMadeMoveUseless:: pause 0x20 printstring STRINGID_PKMNSXMADEYUSELESS waitmessage 0x40 - orbyte gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE + orhalfword gMoveResultFlags, MOVE_RESULT_DOESNT_AFFECT_FOE goto BattleScript_MoveEnd BattleScript_FlashFireBoost_PPLoss:: diff --git a/include/battle.h b/include/battle.h index b57341908..2ff032cef 100644 --- a/include/battle.h +++ b/include/battle.h @@ -229,6 +229,7 @@ struct SpecialStatus u8 flag40:1; u8 focusBanded:1; u8 focusSashed:1; + u8 sturdied:1; s32 dmg; s32 physicalDmg; s32 specialDmg; @@ -800,7 +801,7 @@ extern u16 gLastResultingMoves[MAX_BATTLERS_COUNT]; extern u16 gLockedMoves[MAX_BATTLERS_COUNT]; extern u8 gLastHitBy[MAX_BATTLERS_COUNT]; extern u16 gChosenMoveByBattler[MAX_BATTLERS_COUNT]; -extern u8 gMoveResultFlags; +extern u16 gMoveResultFlags; extern u32 gHitMarker; extern u8 gTakenDmgByBattler[MAX_BATTLERS_COUNT]; extern u8 gUnknown_0202428C; diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 6286af678..1bd00027d 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -303,5 +303,6 @@ extern const u8 BattleScript_GrassyTerrainEnds[]; extern const u8 BattleScript_PsychicTerrainEnds[]; extern const u8 BattleScript_MudSportEnds[]; extern const u8 BattleScript_WaterSportEnds[]; +extern const u8 BattleScript_SturdiedMsg[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/include/constants/battle.h b/include/constants/battle.h index 546ce4dba..7b0b00356 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -220,6 +220,7 @@ #define MOVE_RESULT_FAILED (1 << 5) #define MOVE_RESULT_FOE_ENDURED (1 << 6) #define MOVE_RESULT_FOE_HUNG_ON (1 << 7) +#define MOVE_RESULT_STURDIED (1 << 8) #define MOVE_RESULT_NO_EFFECT (MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED) // Battle Weather flags diff --git a/src/battle_main.c b/src/battle_main.c index 0fd16dcb9..e66468caf 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -246,7 +246,7 @@ EWRAM_DATA u16 gLastResultingMoves[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u16 gLockedMoves[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u8 gLastHitBy[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u16 gChosenMoveByBattler[MAX_BATTLERS_COUNT] = {0}; -EWRAM_DATA u8 gMoveResultFlags = 0; +EWRAM_DATA u16 gMoveResultFlags = 0; EWRAM_DATA u32 gHitMarker = 0; EWRAM_DATA static u8 sUnusedBattlersArray[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u8 gTakenDmgByBattler[MAX_BATTLERS_COUNT] = {0}; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index dc7839b58..20476282f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -99,7 +99,7 @@ static void atk04_critcalc(void); static void atk05_damagecalc(void); static void atk06_typecalc(void); static void atk07_adjustdamage(void); -static void atk08_nop(void); +static void atk08_multihitresultmessage(void); static void atk09_attackanimation(void); static void atk0A_waitanimation(void); static void atk0B_healthbarupdate(void); @@ -351,7 +351,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk05_damagecalc, atk06_typecalc, atk07_adjustdamage, - atk08_nop, + atk08_multihitresultmessage, atk09_attackanimation, atk0A_waitanimation, atk0B_healthbarupdate, @@ -1380,19 +1380,16 @@ static void atk07_adjustdamage(void) { u8 holdEffect, param; - holdEffect = GetBattlerHoldEffect(gBattlerTarget, TRUE); - if (gBattleMons[gBattlerTarget].item == ITEM_ENIGMA_BERRY) - param = gEnigmaBerries[gBattlerTarget].holdEffectParam; - else - param = ItemId_GetHoldEffectParam(gBattleMons[gBattlerTarget].item); - - gPotentialItemEffectBattler = gBattlerTarget; - if (gBattleMons[gBattlerTarget].status2 & STATUS2_SUBSTITUTE) goto END; if (gBattleMons[gBattlerTarget].hp > gBattleMoveDamage) goto END; + holdEffect = GetBattlerHoldEffect(gBattlerTarget, TRUE); + param = GetBattlerHoldEffectParam(gBattlerTarget); + + gPotentialItemEffectBattler = gBattlerTarget; + if (holdEffect == HOLD_EFFECT_FOCUS_BAND && (Random() % 100) < param) { RecordItemEffectBattle(gBattlerTarget, holdEffect); @@ -1403,14 +1400,20 @@ static void atk07_adjustdamage(void) RecordItemEffectBattle(gBattlerTarget, holdEffect); gSpecialStatuses[gBattlerTarget].focusSashed = 1; } + else if (GetBattlerAbility(gBattlerTarget) == ABILITY_STURDY && BATTLER_MAX_HP(gBattlerTarget)) + { + RecordAbilityBattle(gBattlerTarget, ABILITY_STURDY); + gSpecialStatuses[gBattlerTarget].sturdied = 1; + } if (gBattleMoves[gCurrentMove].effect != EFFECT_FALSE_SWIPE && !gProtectStructs[gBattlerTarget].endured && !gSpecialStatuses[gBattlerTarget].focusBanded - && !gSpecialStatuses[gBattlerTarget].focusSashed) + && !gSpecialStatuses[gBattlerTarget].focusSashed + && !gSpecialStatuses[gBattlerTarget].sturdied) goto END; - // Handle reducing the dmg to 1 hp + // Handle reducing the dmg to 1 hp. gBattleMoveDamage = gBattleMons[gBattlerTarget].hp - 1; if (gProtectStructs[gBattlerTarget].endured) @@ -1422,14 +1425,45 @@ static void atk07_adjustdamage(void) gMoveResultFlags |= MOVE_RESULT_FOE_HUNG_ON; gLastUsedItem = gBattleMons[gBattlerTarget].item; } + else if (gSpecialStatuses[gBattlerTarget].sturdied) + { + gMoveResultFlags |= MOVE_RESULT_STURDIED; + gLastUsedAbility = ABILITY_STURDY; + } END: gBattlescriptCurrInstr++; } -static void atk08_nop(void) +static void atk08_multihitresultmessage(void) { + if (gBattleControllerExecFlags) + return; + if (!(gMoveResultFlags & MOVE_RESULT_FAILED) && !(gMoveResultFlags & MOVE_RESULT_FOE_ENDURED)) + { + if (gMoveResultFlags & MOVE_RESULT_STURDIED) + { + gMoveResultFlags &= ~(MOVE_RESULT_STURDIED | MOVE_RESULT_FOE_HUNG_ON); + gSpecialStatuses[gBattlerTarget].sturdied = 0; // Delete this line to make Sturdy last for the duration of the whole move turn. + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_SturdiedMsg; + return; + } + else if (gMoveResultFlags & MOVE_RESULT_FOE_HUNG_ON) + { + gLastUsedItem = gBattleMons[gBattlerTarget].item; + gPotentialItemEffectBattler = gBattlerTarget; + gMoveResultFlags &= ~(MOVE_RESULT_STURDIED | MOVE_RESULT_FOE_HUNG_ON); + gSpecialStatuses[gBattlerTarget].focusBanded = 0; // Delete this line to make Focus Band last for the duration of the whole move turn. + gSpecialStatuses[gBattlerTarget].focusSashed = 0; // Delete this line to make Focus Sash last for the duration of the whole move turn. + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_HangedOnMsg; + return; + } + } + + gBattlescriptCurrInstr++; } static void atk09_attackanimation(void) @@ -1692,6 +1726,7 @@ static void atk0E_effectivenesssound(void) case MOVE_RESULT_FOE_ENDURED: case MOVE_RESULT_ONE_HIT_KO: case MOVE_RESULT_FOE_HUNG_ON: + case MOVE_RESULT_STURDIED: default: if (gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) { @@ -1729,7 +1764,7 @@ static void atk0F_resultmessage(void) else { gBattleCommunication[MSG_DISPLAY] = 1; - switch (gMoveResultFlags & (u8)(~(MOVE_RESULT_MISSED))) + switch (gMoveResultFlags & (~MOVE_RESULT_MISSED)) { case MOVE_RESULT_SUPER_EFFECTIVE: stringId = STRINGID_SUPEREFFECTIVE; @@ -1770,6 +1805,14 @@ static void atk0F_resultmessage(void) gBattlescriptCurrInstr = BattleScript_OneHitKOMsg; return; } + else if (gMoveResultFlags & MOVE_RESULT_STURDIED) + { + gMoveResultFlags &= ~(MOVE_RESULT_STURDIED | MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON); + gSpecialStatuses[gBattlerTarget].sturdied = 0; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_SturdiedMsg; + return; + } else if (gMoveResultFlags & MOVE_RESULT_FOE_ENDURED) { gMoveResultFlags &= ~(MOVE_RESULT_FOE_ENDURED | MOVE_RESULT_FOE_HUNG_ON);