diff options
Diffstat (limited to 'src/battle_util.c')
-rw-r--r-- | src/battle_util.c | 136 |
1 files changed, 83 insertions, 53 deletions
diff --git a/src/battle_util.c b/src/battle_util.c index c0d897707..6fb307d63 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -49,7 +49,29 @@ extern const u8 *const gBattlescriptsForRunningByItem[]; extern const u8 *const gBattlescriptsForUsingItem[]; extern const u8 *const gBattlescriptsForSafariActions[]; -static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; +static const u8 sPkblToEscapeFactor[][3] = { + { + [B_MSG_MON_CURIOUS] = 0, + [B_MSG_MON_ENTHRALLED] = 0, + [B_MSG_MON_IGNORED] = 0 + },{ + [B_MSG_MON_CURIOUS] = 3, + [B_MSG_MON_ENTHRALLED] = 5, + [B_MSG_MON_IGNORED] = 0 + },{ + [B_MSG_MON_CURIOUS] = 2, + [B_MSG_MON_ENTHRALLED] = 3, + [B_MSG_MON_IGNORED] = 0 + },{ + [B_MSG_MON_CURIOUS] = 1, + [B_MSG_MON_ENTHRALLED] = 2, + [B_MSG_MON_IGNORED] = 0 + },{ + [B_MSG_MON_CURIOUS] = 1, + [B_MSG_MON_ENTHRALLED] = 1, + [B_MSG_MON_IGNORED] = 0 + } +}; static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; @@ -238,10 +260,9 @@ void HandleAction_UseMove(void) } } - // choose battlescript - if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) + if (gBattleTypeFlags & BATTLE_TYPE_PALACE && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) { + // Battle Palace, select battle script for failure to use move if (gBattleMons[gBattlerAttacker].hp == 0) { gCurrentActionFuncId = B_ACTION_FINISHED; @@ -249,13 +270,13 @@ void HandleAction_UseMove(void) } else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_INCAPABLE_OF_POWER; gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_INCAPABLE_OF_POWER; gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; } } @@ -318,26 +339,29 @@ void HandleAction_UseItem(void) case AI_ITEM_HEAL_HP: break; case AI_ITEM_CURE_CONDITION: - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) + gBattleCommunication[MULTISTRING_CHOOSER] = AI_HEAL_CONFUSION; + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & (1 << AI_HEAL_CONFUSION)) { if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) - gBattleCommunication[MULTISTRING_CHOOSER] = 5; + gBattleCommunication[MULTISTRING_CHOOSER] = AI_HEAL_SLEEP; } else { + // Check for other statuses, stopping at first (shouldn't be more than one) while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) { *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; + // MULTISTRING_CHOOSER will be either AI_HEAL_PARALYSIS, AI_HEAL_FREEZE, + // AI_HEAL_BURN, AI_HEAL_POISON, or AI_HEAL_SLEEP } } break; case AI_ITEM_X_STAT: - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_ROSE_ITEM; + if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & (1 << AI_DIRE_HIT)) { - gBattleCommunication[MULTISTRING_CHOOSER] = 5; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_USED_DIRE_HIT; } else { @@ -356,9 +380,9 @@ void HandleAction_UseItem(void) break; case AI_ITEM_GUARD_SPECS: if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - gBattleCommunication[MULTISTRING_CHOOSER] = 2; + gBattleCommunication[MULTISTRING_CHOOSER] = 2; // Going OOB for gMistUsedStringIds? else - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_MIST; break; } @@ -479,7 +503,7 @@ void HandleAction_Run(void) if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away { ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gBattleCommunication[MULTISTRING_CHOOSER] = 3; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE_2; gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } @@ -488,7 +512,7 @@ void HandleAction_Run(void) { if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ATTACKER_CANT_ESCAPE; gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } @@ -567,11 +591,11 @@ void HandleAction_GoNear(void) if (gBattleStruct->safariGoNearCounter < 3) { gBattleStruct->safariGoNearCounter++; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CREPT_CLOSER; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_GET_CLOSER; } gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; @@ -1295,20 +1319,20 @@ u8 DoFieldEndTurnEffects(void) { gBattleWeather &= ~WEATHER_RAIN_TEMPORARY; gBattleWeather &= ~WEATHER_RAIN_DOWNPOUR; - gBattleCommunication[MULTISTRING_CHOOSER] = 2; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; } else if (gBattleWeather & WEATHER_RAIN_DOWNPOUR) - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; else - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; } else if (gBattleWeather & WEATHER_RAIN_DOWNPOUR) { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; } BattleScriptExecute(BattleScript_RainContinuesOrEnds); @@ -1330,7 +1354,7 @@ u8 DoFieldEndTurnEffects(void) } gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SANDSTORM; BattleScriptExecute(gBattlescriptCurrInstr); effect++; } @@ -1368,7 +1392,7 @@ u8 DoFieldEndTurnEffects(void) } gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES; - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_HAIL; BattleScriptExecute(gBattlescriptCurrInstr); effect++; } @@ -1597,16 +1621,16 @@ u8 DoBattlerEndTurnEffects(void) if (WasUnableToUseMove(gActiveBattler)) { CancelMultiTurnMoves(gActiveBattler); - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_ENDS; } else if (gBattleMons[gActiveBattler].status2 & STATUS2_UPROAR) { - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_CONTINUES; gBattleMons[gActiveBattler].status2 |= STATUS2_MULTIPLETURNS; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_UPROAR_ENDS; CancelMultiTurnMoves(gActiveBattler); } BattleScriptExecute(BattleScript_PrintUproarOverTurns); @@ -1749,9 +1773,9 @@ bool8 HandleWishPerishSongOnTurnEnd(void) && gBattleMons[gActiveBattler].hp != 0) { if (gWishFutureKnock.futureSightMove[gActiveBattler] == MOVE_FUTURE_SIGHT) - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_FUTURE_SIGHT; else - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOOM_DESIRE; PREPARE_MOVE_BUFFER(gBattleTextBuff1, gWishFutureKnock.futureSightMove[gActiveBattler]); @@ -1962,7 +1986,7 @@ u8 AtkCanceller_UnableToUseMove(void) gBattleMons[gBattlerAttacker].status1 &= ~(STATUS1_SLEEP); gBattleMons[gBattlerAttacker].status2 &= ~(STATUS2_NIGHTMARE); BattleScriptPushCursor(); - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WOKE_UP_UPROAR; gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; effect = 2; } @@ -1990,7 +2014,7 @@ u8 AtkCanceller_UnableToUseMove(void) { gBattleMons[gBattlerAttacker].status2 &= ~(STATUS2_NIGHTMARE); BattleScriptPushCursor(); - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WOKE_UP; gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp; effect = 2; } @@ -2019,7 +2043,7 @@ u8 AtkCanceller_UnableToUseMove(void) gBattleMons[gBattlerAttacker].status1 &= ~(STATUS1_FREEZE); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_MoveUsedUnfroze; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DEFROSTED; } effect = 2; } @@ -2030,7 +2054,7 @@ u8 AtkCanceller_UnableToUseMove(void) { CancelMultiTurnMoves(gBattlerAttacker); gHitMarker |= HITMARKER_UNABLE_TO_USE_MOVE; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_LOAFING; gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; gMoveResultFlags |= MOVE_RESULT_MISSED; effect = 1; @@ -2103,12 +2127,14 @@ u8 AtkCanceller_UnableToUseMove(void) { if (Random() & 1) { - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + // The MULTISTRING_CHOOSER is used here as a bool to signal + // to BattleScript_MoveUsedIsConfused whether or not damage was taken + gBattleCommunication[MULTISTRING_CHOOSER] = FALSE; BattleScriptPushCursor(); } else // confusion dmg { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = TRUE; gBattlerTarget = gBattlerAttacker; gBattleMoveDamage = CalculateBaseDamage(&gBattleMons[gBattlerAttacker], &gBattleMons[gBattlerAttacker], MOVE_POUND, 0, 40, 0, gBattlerAttacker, gBattlerAttacker); gProtectStructs[gBattlerAttacker].confusionSelfDmg = 1; @@ -2195,7 +2221,7 @@ u8 AtkCanceller_UnableToUseMove(void) gBattleMons[gBattlerAttacker].status1 &= ~(STATUS1_FREEZE); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_MoveUsedUnfroze; - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DEFROSTED_BY_MOVE; } effect = 2; } @@ -2593,7 +2619,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA if (gBattleMons[battler].statStages[STAT_SPEED] < MAX_STAT_STAGE && gDisableStructs[battler].isFirstTurn != 2) { gBattleMons[battler].statStages[STAT_SPEED]++; - gBattleScripting.animArg1 = 0x11; + gBattleScripting.animArg1 = 14 + STAT_SPEED; gBattleScripting.animArg2 = 0; BattleScriptPushCursorAndCallback(BattleScript_SpeedBoostActivates); gBattleScripting.battler = battler; @@ -2655,7 +2681,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA { if (!(gBattleResources->flags->flags[battler] & RESOURCE_FLAG_FLASH_FIRE)) { - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_FLASH_FIRE_BOOST; if (gProtectStructs[gBattlerAttacker].notFirstStrike) gBattlescriptCurrInstr = BattleScript_FlashFireBoost; else @@ -2666,7 +2692,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_FLASH_FIRE_NO_BOOST; if (gProtectStructs[gBattlerAttacker].notFirstStrike) gBattlescriptCurrInstr = BattleScript_FlashFireBoost; else @@ -3431,7 +3457,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gEffectBattler = battlerId; SET_STATCHANGER(STAT_ATK, 1, FALSE); - gBattleScripting.animArg1 = 0xE + STAT_ATK; + gBattleScripting.animArg1 = 14 + STAT_ATK; gBattleScripting.animArg2 = 0; BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; @@ -3445,7 +3471,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gEffectBattler = battlerId; SET_STATCHANGER(STAT_DEF, 1, FALSE); - gBattleScripting.animArg1 = 0xE + STAT_DEF; + gBattleScripting.animArg1 = 14 + STAT_DEF; gBattleScripting.animArg2 = 0; BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; @@ -3459,7 +3485,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gEffectBattler = battlerId; SET_STATCHANGER(STAT_SPEED, 1, FALSE); - gBattleScripting.animArg1 = 0xE + STAT_SPEED; + gBattleScripting.animArg1 = 14 + STAT_SPEED; gBattleScripting.animArg2 = 0; BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; @@ -3473,7 +3499,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gEffectBattler = battlerId; SET_STATCHANGER(STAT_SPATK, 1, FALSE); - gBattleScripting.animArg1 = 0xE + STAT_SPATK; + gBattleScripting.animArg1 = 14 + STAT_SPATK; gBattleScripting.animArg2 = 0; BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; @@ -3487,7 +3513,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gEffectBattler = battlerId; SET_STATCHANGER(STAT_SPDEF, 1, FALSE); - gBattleScripting.animArg1 = 0xE + STAT_SPDEF; + gBattleScripting.animArg1 = 14 + STAT_SPDEF; gBattleScripting.animArg2 = 0; BattleScriptExecute(BattleScript_BerryStatRaiseEnd2); effect = ITEM_STATS_CHANGE; @@ -3622,9 +3648,9 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) i++; } if (!(i > 1)) - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; else - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_NORMALIZED_STATUS; gBattleMons[battlerId].status1 = 0; gBattleMons[battlerId].status2 &= ~(STATUS2_CONFUSION); BattleScriptExecute(BattleScript_BerryCureChosenStatusEnd2); @@ -3637,7 +3663,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleMons[battlerId].status2 &= ~(STATUS2_INFATUATION); StringCopy(gBattleTextBuff1, gStatusConditionString_LoveJpn); BattleScriptExecute(BattleScript_BerryCureChosenStatusEnd2); - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; effect = ITEM_EFFECT_OTHER; } break; @@ -3740,7 +3766,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleMons[battlerId].status2 &= ~(STATUS2_INFATUATION); StringCopy(gBattleTextBuff1, gStatusConditionString_LoveJpn); BattleScriptPushCursor(); - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; gBattlescriptCurrInstr = BattleScript_BerryCureChosenStatusRet; effect = ITEM_EFFECT_OTHER; } @@ -3776,7 +3802,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleMons[battlerId].status1 = 0; gBattleMons[battlerId].status2 &= ~(STATUS2_CONFUSION); BattleScriptPushCursor(); - gBattleCommunication[MULTISTRING_CHOOSER] = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CURED_PROBLEM; gBattlescriptCurrInstr = BattleScript_BerryCureChosenStatusRet; effect = ITEM_STATUS_CHANGE; } @@ -4016,7 +4042,9 @@ u8 IsMonDisobedient(void) calc = CheckMoveLimitations(gBattlerAttacker, gBitTable[gCurrMovePos], 0xFF); if (calc == 0xF) // all moves cannot be used { - gBattleCommunication[MULTISTRING_CHOOSER] = Random() & 3; + // Randomly select, then print a disobedient string + // B_MSG_LOAFING, B_MSG_WONT_OBEY, B_MSG_TURNED_AWAY, or B_MSG_PRETEND_NOT_NOTICE + gBattleCommunication[MULTISTRING_CHOOSER] = Random() & (NUM_LOAF_STRINGS - 1); gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; return 1; } @@ -4024,7 +4052,7 @@ u8 IsMonDisobedient(void) { do { - gCurrMovePos = gChosenMovePos = Random() & 3; + gCurrMovePos = gChosenMovePos = Random() & (MAX_MON_MOVES - 1); } while (gBitTable[gCurrMovePos] & calc); gCalledMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; @@ -4065,7 +4093,9 @@ u8 IsMonDisobedient(void) } else { - gBattleCommunication[MULTISTRING_CHOOSER] = Random() & 3; + // Randomly select, then print a disobedient string + // B_MSG_LOAFING, B_MSG_WONT_OBEY, B_MSG_TURNED_AWAY, or B_MSG_PRETEND_NOT_NOTICE + gBattleCommunication[MULTISTRING_CHOOSER] = Random() & (NUM_LOAF_STRINGS - 1); gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; return 1; } |