From 6a7d58003b8962ce50e0528b5963c75122503710 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 22 Jul 2018 21:05:12 +0200 Subject: [PATCH] Add Bad Dreams --- asm/macros/battle_script.inc | 9 ++++++++ data/battle_scripts_1.s | 18 ++++++++++++++++ include/battle_scripts.h | 1 + include/constants/battle_script_commands.h | 1 + include/constants/battle_string_ids.h | 3 ++- src/battle_message.c | 2 ++ src/battle_script_commands.c | 24 ++++++++++++++++++++++ src/battle_util.c | 7 +++++++ 8 files changed, 64 insertions(+), 1 deletion(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 3b67ac731..55b681b80 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1238,6 +1238,11 @@ .4byte \ptr .endm + .macro trygetbaddreamstarget ptr + .byte 0xfd + .4byte \ptr + .endm + @ various command changed to more readable macros .macro cancelmultiturnmoves bank various \bank, VARIOUS_CANCEL_MULTI_TURN_MOVES @@ -1431,3 +1436,7 @@ .macro jumpifnotbattletype flags, jumpptr jumpifword CMP_NO_COMMON_BITS, gBattleTypeFlags, \flags, \jumpptr .endm + + .macro dmg_1_8_targethp + manipulatedamage ATK80_1_8_TARGET_HP + .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5d39fae94..a2b1bbee4 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -4461,6 +4461,24 @@ BattleScript_DroughtActivates:: playanimation BS_BATTLER_0, B_ANIM_SUN_CONTINUES, NULL call BattleScript_WeatherFormChanges end3 + +BattleScript_BadDreamsActivates:: + setbyte gBattlerTarget, 0 +BattleScript_BadDreamsLoop: + trygetbaddreamstarget BattleScript_BadDreamsEnd + dmg_1_8_targethp + orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_x100000 + printstring STRINGID_BADDREAMSDMG + waitmessage 0x40 + healthbarupdate BS_TARGET + datahpupdate BS_TARGET + tryfaintmon BS_TARGET, FALSE, NULL + atk24 BattleScript_BadDreamsIncrement +BattleScript_BadDreamsIncrement: + addbyte gBattlerTarget, 1 + goto BattleScript_BadDreamsLoop +BattleScript_BadDreamsEnd: + end3 BattleScript_TookAttack:: attackstring diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 520e32b00..0971b1182 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -312,5 +312,6 @@ extern const u8 BattleScript_AngryPointActivates[]; extern const u8 BattleScript_AttackerAbilityStatRaise[]; extern const u8 BattleScript_AttackerAbilityStatRaiseEnd3[]; extern const u8 BattleScript_PoisonHealActivates[]; +extern const u8 BattleScript_BadDreamsActivates[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 3e1906442..bf88aba9c 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -79,6 +79,7 @@ #define ATK80_DMG_CHANGE_SIGN 0 #define ATK80_DMG_HALF_BY_TWO_NOT_MORE_THAN_HALF_MAX_HP 1 #define ATK80_DMG_DOUBLED 2 +#define ATK80_1_8_TARGET_HP 3 // atk4F, a flag used for the jumpifcantswitch command #define ATK4F_DONT_CHECK_STATUSES 0x80 diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index c2fc1ca10..80c57af87 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -454,7 +454,8 @@ #define STRINGID_ANGRYPOINTACTIVATES 451 #define STRINGID_ATTACKERABILITYSTATRAISE 452 #define STRINGID_POISONHEALHPUP 453 +#define STRINGID_BADDREAMSDMG 454 -#define BATTLESTRINGS_COUNT 442 +#define BATTLESTRINGS_COUNT 443 #endif // GUARD_CONSTANTS_BATTLE_STRING_IDS_H diff --git a/src/battle_message.c b/src/battle_message.c index 213770fdd..43e845b3e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -597,6 +597,7 @@ static const u8 sText_PsychicTerrainEnds[] = _(""); static const u8 sText_GrassyTerrainEnds[] = _(""); static const u8 sText_AngryPointActivates[] = _(""); static const u8 sText_PoisonHealHpUp[] = _(""); +static const u8 sText_BadDreamsDmg[] = _(""); const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { @@ -1043,6 +1044,7 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = sText_AngryPointActivates, // 451 sText_AttackerAbilityRaisedStat, // 452 sText_PoisonHealHpUp, // 453 + sText_BadDreamsDmg, // 454 }; const u16 gMissStringIds[] = diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a43f58b0b..7205cfb47 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -344,6 +344,7 @@ static void atkF9_settelekinesis(void); static void atkFA_swapstatstages(void); static void atkFB_averagestats(void); static void atkFC_jumpifoppositegenders(void); +static void atkFD_trygetbaddreamstarget(void); void (* const gBattleScriptingCommandsTable[])(void) = { @@ -600,6 +601,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkFA_swapstatstages, atkFB_averagestats, atkFC_jumpifoppositegenders, + atkFD_trygetbaddreamstarget, }; struct StatFractions @@ -6787,6 +6789,11 @@ static void atk80_manipulatedamage(void) case ATK80_DMG_DOUBLED: gBattleMoveDamage *= 2; break; + case ATK80_1_8_TARGET_HP: + gBattleMoveDamage = gBattleMons[gBattlerTarget].maxHP / 8; + if (gBattleMoveDamage == 0) + gBattleMoveDamage = 1; + break; } gBattlescriptCurrInstr += 2; @@ -10339,3 +10346,20 @@ static void atkFC_jumpifoppositegenders(void) else gBattlescriptCurrInstr += 5; } + +static void atkFD_trygetbaddreamstarget(void) +{ + u8 badDreamsMonSide = GetBattlerSide(gBattlerAttacker); + for (;gBattlerTarget < gBattlersCount; gBattlerTarget++) + { + if (GetBattlerSide(gBattlerTarget) == badDreamsMonSide) + continue; + if (gBattleMons[gBattlerTarget].status1 & STATUS1_SLEEP && IsBattlerAlive(gBattlerTarget)) + break; + } + + if (gBattlerTarget >= gBattlersCount) + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); + else + gBattlescriptCurrInstr += 5; +} diff --git a/src/battle_util.c b/src/battle_util.c index caa9bdd38..6ef1c1dd8 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2551,6 +2551,13 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA case ABILITY_TRUANT: gDisableStructs[gBattlerAttacker].truantCounter ^= 1; break; + case ABILITY_BAD_DREAMS: + if (gBattleMons[BATTLE_OPPOSITE(battler)].status1 & STATUS1_SLEEP || gBattleMons[BATTLE_OPPOSITE(battler)].status1 & STATUS1_SLEEP) + { + BattleScriptPushCursorAndCallback(BattleScript_BadDreamsActivates); + effect++; + } + break; } } break;