From 0852cba111a3b660f26e679ce9edfb11083e4dbf Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 16 Jul 2018 21:42:03 +0200 Subject: [PATCH] Fix dynamic move power moves, get rid of gDynamicBasePower' ' --- asm/macros/battle_script.inc | 8 +-- data/battle_scripts_1.s | 19 ++---- include/battle.h | 1 - src/battle_ai_script_commands.c | 5 -- src/battle_ai_switch_items.c | 1 - src/battle_main.c | 9 +-- src/battle_script_commands.c | 106 ++++++++++++-------------------- 7 files changed, 49 insertions(+), 100 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index df8bb78d3..1b3cd28a8 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -892,7 +892,7 @@ .4byte \param0 .endm - .macro rolloutdamagecalculation + .macro handlerollout .byte 0xb3 .endm @@ -902,11 +902,11 @@ .4byte \param1 .endm - .macro furycuttercalc + .macro handlefurycutter .byte 0xb5 .endm - .macro happinesstodamagecalculation + .macro nop_B6 .byte 0xb6 .endm @@ -1066,7 +1066,7 @@ .4byte \param0 .endm - .macro scaledamagebyhealthratio + .macro nop_D9 .byte 0xd9 .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index cd6244d36..65e3c060e 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -258,6 +258,9 @@ BattleScript_EffectLowKick: BattleScript_EffectFlail: BattleScript_EffectFacade: BattleScript_EffectRevenge: +BattleScript_EffectReturn: +BattleScript_EffectFrustration: +BattleScript_EffectEruption: jumpifnotmove MOVE_SURF, BattleScript_HitFromAtkCanceler jumpifnostatus3 BS_TARGET, STATUS3_UNDERWATER, BattleScript_HitFromAtkCanceler orword gHitMarker, HITMARKER_IGNORE_UNDERWATER @@ -1417,7 +1420,6 @@ BattleScript_DoTripleKickAttack:: movevaluescleanup addbyte sTRIPLE_KICK_POWER, 10 addbyte sMULTIHIT_STRING + 4, 0x1 - copyhword gDynamicBasePower, sTRIPLE_KICK_POWER critcalc damagecalc adjustdamage @@ -1622,7 +1624,7 @@ BattleScript_RolloutCheckAccuracy:: accuracycheck BattleScript_RolloutHit, ACC_CURR_MOVE BattleScript_RolloutHit:: typecalc2 - rolloutdamagecalculation + handlerollout goto BattleScript_HitFromCritCalc BattleScript_EffectSwagger:: @@ -1654,7 +1656,7 @@ BattleScript_EffectFuryCutter:: ppreduce accuracycheck BattleScript_FuryCutterHit, ACC_CURR_MOVE BattleScript_FuryCutterHit:: - furycuttercalc + handlefurycutter critcalc damagecalc jumpifmovehadnoeffect BattleScript_FuryCutterHit @@ -1673,13 +1675,6 @@ BattleScript_EffectAttract:: waitmessage 0x40 goto BattleScript_MoveEnd -BattleScript_EffectReturn:: -BattleScript_EffectFrustration:: - attackcanceler - accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE - happinesstodamagecalculation - goto BattleScript_HitFromAtkString - BattleScript_EffectPresent:: attackcanceler accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE @@ -2483,10 +2478,6 @@ BattleScript_EffectEndeavor:: adjustdamage goto BattleScript_HitFromAtkAnimation -BattleScript_EffectEruption:: - scaledamagebyhealthratio - goto BattleScript_EffectHit - BattleScript_EffectSkillSwap:: attackcanceler attackstring diff --git a/include/battle.h b/include/battle.h index 8d8647144..e32a5e827 100644 --- a/include/battle.h +++ b/include/battle.h @@ -805,7 +805,6 @@ extern u16 gBattleWeather; extern struct WishFutureKnock gWishFutureKnock; extern u16 gIntroSlideFlags; extern u8 gSentPokesToOpponent[2]; -extern u16 gDynamicBasePower; extern u16 gExpShareExp; extern struct BattleEnigmaBerry gEnigmaBerries[MAX_BATTLERS_COUNT]; extern struct BattleScripting gBattleScripting; diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index c76beafb3..ae9ba92de 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1308,7 +1308,6 @@ static void BattleAICmd_get_how_powerful_move_is(void) if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power > 1 && sDiscouragedPowerfulMoveEffects[i] == 0xFFFF) { - gDynamicBasePower = 0; *(&gBattleStruct->dynamicMoveType) = 0; gMoveResultFlags = 0; @@ -1585,7 +1584,6 @@ static void BattleAICmd_get_highest_type_effectiveness(void) s32 i; u8 *dynamicMoveType; - gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gMoveResultFlags = 0; AI_THINKING_STRUCT->funcResult = 0; @@ -1633,7 +1631,6 @@ static void BattleAICmd_if_type_effectiveness(void) u8 damageVar; u32 effectivenessMultiplier; - gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gMoveResultFlags = 0; gCurrentMove = AI_THINKING_STRUCT->moveConsidered; @@ -1850,7 +1847,6 @@ static void BattleAICmd_if_can_faint(void) return; } - gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gMoveResultFlags = 0; dmg = AI_CalcDamage(AI_THINKING_STRUCT->moveConsidered, sBattler_AI, gBattlerTarget); @@ -1876,7 +1872,6 @@ static void BattleAICmd_if_cant_faint(void) return; } - gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gMoveResultFlags = 0; dmg = AI_CalcDamage(AI_THINKING_STRUCT->moveConsidered, sBattler_AI, gBattlerTarget); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index babf3004e..234d6b1f2 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -710,7 +710,6 @@ u8 GetMostSuitableMonToSwitchInto(void) } } - gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gMoveResultFlags = 0; bestDmg = 0; diff --git a/src/battle_main.c b/src/battle_main.c index 2a7e016e9..d3456ad09 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -266,7 +266,6 @@ EWRAM_DATA u16 gBattleWeather = 0; EWRAM_DATA struct WishFutureKnock gWishFutureKnock = {0}; EWRAM_DATA u16 gIntroSlideFlags = 0; EWRAM_DATA u8 gSentPokesToOpponent[2] = {0}; -EWRAM_DATA u16 gDynamicBasePower = 0; EWRAM_DATA u16 gExpShareExp = 0; EWRAM_DATA struct BattleEnigmaBerry gEnigmaBerries[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA struct BattleScripting gBattleScripting = {0}; @@ -4922,12 +4921,7 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) TryClearRageStatuses(); gCurrentTurnActionNumber = 0; -{ - // something stupid needed to match - u8 zero; - gCurrentActionFuncId = gActionsByTurnOrder[(zero = 0)]; -} - gDynamicBasePower = 0; + gCurrentActionFuncId = gActionsByTurnOrder[0]; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; gBattleCommunication[3] = 0; @@ -5842,7 +5836,6 @@ static void HandleAction_ActionFinished(void) gLastLandedMoves[gBattlerAttacker] = 0; gLastHitByType[gBattlerAttacker] = 0; gBattleStruct->dynamicMoveType = 0; - gDynamicBasePower = 0; gBattleScripting.atk49_state = 0; gBattleCommunication[3] = 0; gBattleCommunication[4] = 0; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9123a3732..e2bd03fac 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -269,10 +269,10 @@ static void atkAF_cursetarget(void); static void atkB0_trysetspikes(void); static void atkB1_setforesight(void); static void atkB2_trysetperishsong(void); -static void atkB3_rolloutdamagecalculation(void); +static void atkB3_handlerollout(void); static void atkB4_jumpifconfusedandstatmaxed(void); -static void atkB5_furycuttercalc(void); -static void atkB6_happinesstodamagecalculation(void); +static void atkB5_handlefurycutter(void); +static void atkB6_nop(void); static void atkB7_presentdamagecalculation(void); static void atkB8_setsafeguard(void); static void atkB9_magnitudedamagecalculation(void); @@ -307,7 +307,7 @@ static void atkD5_trysetroots(void); static void atkD6_nop(void); static void atkD7_setyawn(void); static void atkD8_setdamagetohealthdifference(void); -static void atkD9_scaledamagebyhealthratio(void); +static void atkD9_nop(void); static void atkDA_tryswapabilities(void); static void atkDB_tryimprision(void); static void atkDC_trysetgrudge(void); @@ -521,10 +521,10 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkB0_trysetspikes, atkB1_setforesight, atkB2_trysetperishsong, - atkB3_rolloutdamagecalculation, + atkB3_handlerollout, atkB4_jumpifconfusedandstatmaxed, - atkB5_furycuttercalc, - atkB6_happinesstodamagecalculation, + atkB5_handlefurycutter, + atkB6_nop, atkB7_presentdamagecalculation, atkB8_setsafeguard, atkB9_magnitudedamagecalculation, @@ -559,7 +559,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkD6_nop, atkD7_setyawn, atkD8_setdamagetohealthdifference, - atkD9_scaledamagebyhealthratio, + atkD9_nop, atkDA_tryswapabilities, atkDB_tryimprision, atkDC_trysetgrudge, @@ -8350,7 +8350,7 @@ static void atkB2_trysetperishsong(void) gBattlescriptCurrInstr += 5; } -static void atkB3_rolloutdamagecalculation(void) +static void atkB3_handlerollout(void) { if (gMoveResultFlags & MOVE_RESULT_NO_EFFECT) { @@ -8359,28 +8359,18 @@ static void atkB3_rolloutdamagecalculation(void) } else { - s32 i; - - if (!(gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)) // first hit + if (!(gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)) // First hit. { gDisableStructs[gBattlerAttacker].rolloutCounter1 = 5; gDisableStructs[gBattlerAttacker].rolloutCounter2 = 5; gBattleMons[gBattlerAttacker].status2 |= STATUS2_MULTIPLETURNS; gLockedMoves[gBattlerAttacker] = gCurrentMove; } - if (--gDisableStructs[gBattlerAttacker].rolloutCounter1 == 0) // last hit + if (--gDisableStructs[gBattlerAttacker].rolloutCounter1 == 0) // Last hit. { gBattleMons[gBattlerAttacker].status2 &= ~(STATUS2_MULTIPLETURNS); } - gDynamicBasePower = gBattleMoves[gCurrentMove].power; - - for (i = 1; i < (5 - gDisableStructs[gBattlerAttacker].rolloutCounter1); i++) - gDynamicBasePower *= 2; - - if (gBattleMons[gBattlerAttacker].status2 & STATUS2_DEFENSE_CURL) - gDynamicBasePower *= 2; - gBattlescriptCurrInstr++; } } @@ -8394,7 +8384,7 @@ static void atkB4_jumpifconfusedandstatmaxed(void) gBattlescriptCurrInstr += 6; } -static void atkB5_furycuttercalc(void) +static void atkB5_handlefurycutter(void) { if (gMoveResultFlags & MOVE_RESULT_NO_EFFECT) { @@ -8403,40 +8393,34 @@ static void atkB5_furycuttercalc(void) } else { - s32 i; - if (gDisableStructs[gBattlerAttacker].furyCutterCounter != 5) gDisableStructs[gBattlerAttacker].furyCutterCounter++; - gDynamicBasePower = gBattleMoves[gCurrentMove].power; - - for (i = 1; i < gDisableStructs[gBattlerAttacker].furyCutterCounter; i++) - gDynamicBasePower *= 2; - gBattlescriptCurrInstr++; } } -static void atkB6_happinesstodamagecalculation(void) +static void atkB6_nop(void) { - if (gBattleMoves[gCurrentMove].effect == EFFECT_RETURN) - gDynamicBasePower = 10 * (gBattleMons[gBattlerAttacker].friendship) / 25; - else // EFFECT_FRUSTRATION - gDynamicBasePower = 10 * (255 - gBattleMons[gBattlerAttacker].friendship) / 25; - gBattlescriptCurrInstr++; } static void atkB7_presentdamagecalculation(void) { - s32 rand = Random() & 0xFF; + u32 rand = Random() & 0xFF; if (rand < 102) - gDynamicBasePower = 40; + { + gBattleStruct->presentBasePower = 40; + } else if (rand < 178) - gDynamicBasePower = 80; + { + gBattleStruct->presentBasePower = 80; + } else if (rand < 204) - gDynamicBasePower = 120; + { + gBattleStruct->presentBasePower = 120; + } else { gBattleMoveDamage = gBattleMons[gBattlerTarget].maxHP / 4; @@ -8444,10 +8428,15 @@ static void atkB7_presentdamagecalculation(void) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; } + if (rand < 204) + { gBattlescriptCurrInstr = BattleScript_HitFromCritCalc; + } else if (gBattleMons[gBattlerTarget].maxHP == gBattleMons[gBattlerTarget].hp) + { gBattlescriptCurrInstr = BattleScript_AlreadyAtFullHp; + } else { gMoveResultFlags &= ~(MOVE_RESULT_DOESNT_AFFECT_FOE); @@ -8475,52 +8464,52 @@ static void atkB8_setsafeguard(void) static void atkB9_magnitudedamagecalculation(void) { - s32 magnitude = Random() % 100; + u32 magnitude = Random() % 100; if (magnitude < 5) { - gDynamicBasePower = 10; + gBattleStruct->magnitudeBasePower = 10; magnitude = 4; } else if (magnitude < 15) { - gDynamicBasePower = 30; + gBattleStruct->magnitudeBasePower = 30; magnitude = 5; } else if (magnitude < 35) { - gDynamicBasePower = 50; + gBattleStruct->magnitudeBasePower = 50; magnitude = 6; } else if (magnitude < 65) { - gDynamicBasePower = 70; + gBattleStruct->magnitudeBasePower = 70; magnitude = 7; } else if (magnitude < 85) { - gDynamicBasePower = 90; + gBattleStruct->magnitudeBasePower = 90; magnitude = 8; } else if (magnitude < 95) { - gDynamicBasePower = 110; + gBattleStruct->magnitudeBasePower = 110; magnitude = 9; } else { - gDynamicBasePower = 150; + gBattleStruct->magnitudeBasePower = 150; magnitude = 10; } - PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff1, 2, magnitude) + PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff1, 2, magnitude); for (gBattlerTarget = 0; gBattlerTarget < gBattlersCount; gBattlerTarget++) { if (gBattlerTarget == gBattlerAttacker) continue; - if (!(gAbsentBattlerFlags & gBitTable[gBattlerTarget])) // a valid target was found + if (!(gAbsentBattlerFlags & gBitTable[gBattlerTarget])) // A valid target was found. break; } @@ -8693,16 +8682,8 @@ static void atkC0_recoverbasedonsunlight(void) static void atkC1_hiddenpowercalc(void) { - u8 powerBits; u8 typeBits; - powerBits = ((gBattleMons[gBattlerAttacker].hpIV & 2) >> 1) - | ((gBattleMons[gBattlerAttacker].attackIV & 2) << 0) - | ((gBattleMons[gBattlerAttacker].defenseIV & 2) << 1) - | ((gBattleMons[gBattlerAttacker].speedIV & 2) << 2) - | ((gBattleMons[gBattlerAttacker].spAttackIV & 2) << 3) - | ((gBattleMons[gBattlerAttacker].spDefenseIV & 2) << 4); - typeBits = ((gBattleMons[gBattlerAttacker].hpIV & 1) << 0) | ((gBattleMons[gBattlerAttacker].attackIV & 1) << 1) | ((gBattleMons[gBattlerAttacker].defenseIV & 1) << 2) @@ -8710,8 +8691,6 @@ static void atkC1_hiddenpowercalc(void) | ((gBattleMons[gBattlerAttacker].spAttackIV & 1) << 4) | ((gBattleMons[gBattlerAttacker].spDefenseIV & 1) << 5); - gDynamicBasePower = (40 * powerBits) / 63 + 30; - gBattleStruct->dynamicMoveType = (15 * typeBits) / 63 + 1; if (gBattleStruct->dynamicMoveType >= TYPE_MYSTERY) gBattleStruct->dynamicMoveType++; @@ -9155,15 +9134,8 @@ static void atkD8_setdamagetohealthdifference(void) } } -static void atkD9_scaledamagebyhealthratio(void) +static void atkD9_nop(void) { - if (gDynamicBasePower == 0) - { - u8 power = gBattleMoves[gCurrentMove].power; - gDynamicBasePower = gBattleMons[gBattlerAttacker].hp * power / gBattleMons[gBattlerAttacker].maxHP; - if (gDynamicBasePower == 0) - gDynamicBasePower = 1; - } gBattlescriptCurrInstr++; }