Review corrections

-Simplified the affection mechanics' battle scripts.
-Corrected the value seting inside CalcCritChanceStage.
-Simplified the checks inside Cmd_adjustdamage
-Simplified the contents of GetLeadMonFriendshipScore now that a more general function to do the same thing was added.
-Added constants for the values returned by GetMonFriendshipScore.
This commit is contained in:
LOuroboros 2022-08-25 09:37:42 -03:00
parent 032b7b2ab9
commit e792fae415
5 changed files with 54 additions and 76 deletions

View File

@ -421,47 +421,29 @@ BattleScript_AffectionBasedEndurance::
return return
BattleScript_AffectionBasedStatusHeal:: BattleScript_AffectionBasedStatusHeal::
jumpifstatus BS_ATTACKER, STATUS1_POISON, BattleScript_AffectionBasedStatusHeal_Poison jumpifstatus BS_ATTACKER, STATUS1_POISON, BattleScript_AffectionBasedStatus_HealPoisonString
jumpifstatus BS_ATTACKER, STATUS1_TOXIC_POISON, BattleScript_AffectionBasedStatusHeal_Poison jumpifstatus BS_ATTACKER, STATUS1_TOXIC_POISON, BattleScript_AffectionBasedStatus_HealPoisonString
jumpifstatus BS_ATTACKER, STATUS1_SLEEP, BattleScript_AffectionBasedStatusHeal_Sleep jumpifstatus BS_ATTACKER, STATUS1_SLEEP, BattleScript_AffectionBasedStatus_HealSleepString
jumpifstatus BS_ATTACKER, STATUS1_PARALYSIS, BattleScript_AffectionBasedStatusHeal_Paralysis jumpifstatus BS_ATTACKER, STATUS1_PARALYSIS, BattleScript_AffectionBasedStatus_HealParalysisString
jumpifstatus BS_ATTACKER, STATUS1_BURN, BattleScript_AffectionBasedStatusHeal_Burn jumpifstatus BS_ATTACKER, STATUS1_BURN, BattleScript_AffectionBasedStatus_HealBurnString
jumpifstatus BS_ATTACKER, STATUS1_FREEZE, BattleScript_AffectionBasedStatusHeal_Freeze jumpifstatus BS_ATTACKER, STATUS1_FREEZE, BattleScript_AffectionBasedStatus_HealFreezeString
end2 end2
BattleScript_AffectionBasedStatusHeal_Poison: BattleScript_AffectionBasedStatus_HealPoisonString:
printstring STRINGID_ATTACKEREXPELLEDTHEPOISON printstring STRINGID_ATTACKEREXPELLEDTHEPOISON
waitmessage B_WAIT_TIME_LONG goto BattleScript_AffectionBasedStatusHeal_Continue
clearstatus BS_ATTACKER BattleScript_AffectionBasedStatus_HealSleepString:
waitstate
updatestatusicon BS_ATTACKER
waitstate
end2
BattleScript_AffectionBasedStatusHeal_Sleep:
printstring STRINGID_ATTACKERSHOOKITSELFAWAKE printstring STRINGID_ATTACKERSHOOKITSELFAWAKE
waitmessage B_WAIT_TIME_LONG goto BattleScript_AffectionBasedStatusHeal_Continue
clearstatus BS_ATTACKER BattleScript_AffectionBasedStatus_HealParalysisString:
waitstate
updatestatusicon BS_ATTACKER
waitstate
end2
BattleScript_AffectionBasedStatusHeal_Paralysis:
printstring STRINGID_ATTACKERBROKETHROUGHPARALYSIS printstring STRINGID_ATTACKERBROKETHROUGHPARALYSIS
waitmessage B_WAIT_TIME_LONG goto BattleScript_AffectionBasedStatusHeal_Continue
clearstatus BS_ATTACKER BattleScript_AffectionBasedStatus_HealBurnString:
waitstate
updatestatusicon BS_ATTACKER
waitstate
end2
BattleScript_AffectionBasedStatusHeal_Burn:
printstring STRINGID_ATTACKERHEALEDITSBURN printstring STRINGID_ATTACKERHEALEDITSBURN
waitmessage B_WAIT_TIME_LONG goto BattleScript_AffectionBasedStatusHeal_Continue
clearstatus BS_ATTACKER BattleScript_AffectionBasedStatus_HealFreezeString:
waitstate
updatestatusicon BS_ATTACKER
waitstate
end2
BattleScript_AffectionBasedStatusHeal_Freeze:
printstring STRINGID_ATTACKERMELTEDTHEICE printstring STRINGID_ATTACKERMELTEDTHEICE
goto BattleScript_AffectionBasedStatusHeal_Continue
BattleScript_AffectionBasedStatusHeal_Continue:
waitmessage B_WAIT_TIME_LONG waitmessage B_WAIT_TIME_LONG
clearstatus BS_ATTACKER clearstatus BS_ATTACKER
waitstate waitstate

View File

@ -273,6 +273,15 @@
#define FRIENDSHIP_EVENT_FAINT_FIELD_PSN 7 #define FRIENDSHIP_EVENT_FAINT_FIELD_PSN 7
#define FRIENDSHIP_EVENT_FAINT_LARGE 8 // If opponent was >= 30 levels higher. See AdjustFriendshipOnBattleFaint #define FRIENDSHIP_EVENT_FAINT_LARGE 8 // If opponent was >= 30 levels higher. See AdjustFriendshipOnBattleFaint
// Constants for GetLeadMonFriendshipScore
#define FRIENDSHIP_NONE 0
#define FRIENDSHIP_GE_1 1
#define FRIENDSHIP_GE_50 2
#define FRIENDSHIP_GE_100 3
#define FRIENDSHIP_GE_150 4
#define FRIENDSHIP_GE_200 5
#define FRIENDSHIP_MAX 6
#define MAX_FRIENDSHIP 255 #define MAX_FRIENDSHIP 255
#define MAX_SHEEN 255 #define MAX_SHEEN 255
#define MAX_CONDITION 255 #define MAX_CONDITION 255

View File

@ -59,6 +59,7 @@
#include "constants/songs.h" #include "constants/songs.h"
#include "constants/trainers.h" #include "constants/trainers.h"
#include "battle_util.h" #include "battle_util.h"
#include "constants/pokemon.h"
extern struct Evolution gEvolutionTable[][EVOS_PER_MON]; extern struct Evolution gEvolutionTable[][EVOS_PER_MON];
@ -1732,7 +1733,7 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u
#if B_AFFECTION_MECHANICS == TRUE #if B_AFFECTION_MECHANICS == TRUE
// With high affection/friendship there's a chance to evade a move by substracting 10% of its accuracy. // With high affection/friendship there's a chance to evade a move by substracting 10% of its accuracy.
// I can't find exact information about that chance, so I'm just gonna write it as a 20% chance for now. // I can't find exact information about that chance, so I'm just gonna write it as a 20% chance for now.
if (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[battlerDef]]) >= 4 && (Random() % 100) <= 20) if (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[battlerDef]]) >= FRIENDSHIP_GE_150 && (Random() % 100) <= 20)
calc = (calc * 90) / 100; calc = (calc * 90) / 100;
#endif #endif
@ -1904,11 +1905,9 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi
+ 2 * (holdEffectAtk == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * (holdEffectAtk == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY)
+ 2 * BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk) + 2 * BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk)
#if B_AFFECTION_MECHANICS == TRUE #if B_AFFECTION_MECHANICS == TRUE
+ (abilityAtk == ABILITY_SUPER_LUCK) + 2 * (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_GE_200)
+ 2 * (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= 5);
#else
+ (abilityAtk == ABILITY_SUPER_LUCK);
#endif #endif
+ (abilityAtk == ABILITY_SUPER_LUCK);
if (critChance >= ARRAY_COUNT(sCriticalHitChance)) if (critChance >= ARRAY_COUNT(sCriticalHitChance))
critChance = ARRAY_COUNT(sCriticalHitChance) - 1; critChance = ARRAY_COUNT(sCriticalHitChance) - 1;
@ -1976,6 +1975,8 @@ static void Cmd_adjustdamage(void)
{ {
u8 holdEffect, param; u8 holdEffect, param;
u32 moveType; u32 moveType;
u32 friendshipScore = GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]);
u32 rand = Random() % 100;
GET_MOVE_TYPE(gCurrentMove, moveType); GET_MOVE_TYPE(gCurrentMove, moveType);
@ -1991,7 +1992,7 @@ static void Cmd_adjustdamage(void)
gPotentialItemEffectBattler = gBattlerTarget; gPotentialItemEffectBattler = gBattlerTarget;
if (holdEffect == HOLD_EFFECT_FOCUS_BAND && (Random() % 100) < param) if (holdEffect == HOLD_EFFECT_FOCUS_BAND && rand < param)
{ {
RecordItemEffectBattle(gBattlerTarget, holdEffect); RecordItemEffectBattle(gBattlerTarget, holdEffect);
gSpecialStatuses[gBattlerTarget].focusBanded = TRUE; gSpecialStatuses[gBattlerTarget].focusBanded = TRUE;
@ -2009,12 +2010,12 @@ static void Cmd_adjustdamage(void)
gSpecialStatuses[gBattlerTarget].focusSashed = TRUE; gSpecialStatuses[gBattlerTarget].focusSashed = TRUE;
} }
#if B_AFFECTION_MECHANICS == TRUE #if B_AFFECTION_MECHANICS == TRUE
else if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER && GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]) >= 3) else if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER && friendshipScore >= FRIENDSHIP_GE_100)
{ {
if ((GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]) == 6 && (Random() % 100) < 25) if ((friendshipScore == FRIENDSHIP_MAX && rand < 25)
|| (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]) == 5 && (Random() % 100) < 20) || (friendshipScore == FRIENDSHIP_GE_200 && rand < 20)
|| (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]) == 4 && (Random() % 100) < 15) || (friendshipScore == FRIENDSHIP_GE_150 && rand < 15)
|| (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]) == 3 && (Random() % 100) < 10)) || (friendshipScore == FRIENDSHIP_GE_100 && rand < 10))
gSpecialStatuses[gBattlerTarget].affectionEndured = TRUE; gSpecialStatuses[gBattlerTarget].affectionEndured = TRUE;
} }
#endif #endif
@ -2024,11 +2025,9 @@ static void Cmd_adjustdamage(void)
&& !gSpecialStatuses[gBattlerTarget].focusBanded && !gSpecialStatuses[gBattlerTarget].focusBanded
&& !gSpecialStatuses[gBattlerTarget].focusSashed && !gSpecialStatuses[gBattlerTarget].focusSashed
#if B_AFFECTION_MECHANICS == TRUE #if B_AFFECTION_MECHANICS == TRUE
&& !gSpecialStatuses[gBattlerTarget].sturdied && !gSpecialStatuses[gBattlerTarget].affectionEndured
&& !gSpecialStatuses[gBattlerTarget].affectionEndured)
#else
&& !gSpecialStatuses[gBattlerTarget].sturdied)
#endif #endif
&& !gSpecialStatuses[gBattlerTarget].sturdied)
goto END; goto END;
// Handle reducing the dmg to 1 hp. // Handle reducing the dmg to 1 hp.
@ -4063,7 +4062,7 @@ static void Cmd_getexp(void)
} }
#endif #endif
#if B_AFFECTION_MECHANICS == TRUE #if B_AFFECTION_MECHANICS == TRUE
if (GetMonFriendshipScore(&gPlayerParty[gBattleStruct->expGetterMonId]) >= 2) if (GetMonFriendshipScore(&gPlayerParty[gBattleStruct->expGetterMonId]) >= FRIENDSHIP_GE_50)
gBattleMoveDamage = (gBattleMoveDamage * 120) / 100; gBattleMoveDamage = (gBattleMoveDamage * 120) / 100;
#endif #endif

View File

@ -45,6 +45,7 @@
#include "constants/species.h" #include "constants/species.h"
#include "constants/trainers.h" #include "constants/trainers.h"
#include "constants/weather.h" #include "constants/weather.h"
#include "constants/pokemon.h"
extern struct Evolution gEvolutionTable[][EVOS_PER_MON]; extern struct Evolution gEvolutionTable[][EVOS_PER_MON];
@ -2084,22 +2085,22 @@ void TryToRevertMimicry(void)
} }
} }
u32 GetMonFriendshipScore(struct Pokemon *pokemon) // Based on GetLeadMonFriendshipScore u32 GetMonFriendshipScore(struct Pokemon *pokemon)
{ {
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) == 255) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) == MAX_FRIENDSHIP)
return 6; return FRIENDSHIP_MAX;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 200) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 200)
return 5; return FRIENDSHIP_GE_200;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 150) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 150)
return 4; return FRIENDSHIP_GE_150;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 100) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 100)
return 3; return FRIENDSHIP_GE_100;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 50) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 50)
return 2; return FRIENDSHIP_GE_50;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 1) if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 1)
return 1; return FRIENDSHIP_GE_1;
return 0; return FRIENDSHIP_NONE;
} }
enum enum
@ -2585,7 +2586,7 @@ u8 DoFieldEndTurnEffects(void)
for (gBattlerAttacker = 0; gBattlerAttacker < gBattlersCount; gBattlerAttacker++) for (gBattlerAttacker = 0; gBattlerAttacker < gBattlersCount; gBattlerAttacker++)
{ {
if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER
&& GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= 4 && GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_GE_150
&& (Random() % 100 < 20)) && (Random() % 100 < 20))
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = 1; gBattleCommunication[MULTISTRING_CHOOSER] = 1;

View File

@ -65,6 +65,7 @@
#include "constants/weather.h" #include "constants/weather.h"
#include "constants/metatile_labels.h" #include "constants/metatile_labels.h"
#include "palette.h" #include "palette.h"
#include "battle_util.h"
EWRAM_DATA bool8 gBikeCyclingChallenge = FALSE; EWRAM_DATA bool8 gBikeCyclingChallenge = FALSE;
EWRAM_DATA u8 gBikeCollisions = 0; EWRAM_DATA u8 gBikeCollisions = 0;
@ -939,21 +940,7 @@ u16 GetWeekCount(void)
u8 GetLeadMonFriendshipScore(void) u8 GetLeadMonFriendshipScore(void)
{ {
struct Pokemon *pokemon = &gPlayerParty[GetLeadMonIndex()]; return GetMonFriendshipScore(&gPlayerParty[GetLeadMonIndex()]);
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) == MAX_FRIENDSHIP)
return 6;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 200)
return 5;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 150)
return 4;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 100)
return 3;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 50)
return 2;
if (GetMonData(pokemon, MON_DATA_FRIENDSHIP) >= 1)
return 1;
return 0;
} }
static void CB2_FieldShowRegionMap(void) static void CB2_FieldShowRegionMap(void)