Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes score adjustments to tempScore increases #4987

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/battle_ai_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef s32 (*AiScoreFunc)(u32, u32, u32, s32);
#define NO_DAMAGE_OR_FAILS -20 // Move fails or does no damage

// Scores given in AI_CalcMoveEffectScore
#define NO_INCREASE 0
#define WEAK_EFFECT 1
#define DECENT_EFFECT 2
#define GOOD_EFFECT 3
Expand Down
4 changes: 2 additions & 2 deletions include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ bool32 PartyHasMoveCategory(u32 battlerId, u32 category);
bool32 SideHasMoveCategory(u32 battlerId, u32 category);

// score increases
void IncreaseStatUpScore(u32 battlerAtk, u32 battlerDef, u32 statId, s32 *score);
void IncreaseStatUpScoreContrary(u32 battlerAtk, u32 battlerDef, u32 statId, s32 *score);
u32 IncreaseStatUpScore(u32 battlerAtk, u32 battlerDef, u32 statId);
u32 IncreaseStatUpScoreContrary(u32 battlerAtk, u32 battlerDef, u32 statId);
void IncreasePoisonScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
void IncreaseBurnScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
void IncreaseParalyzeScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
Expand Down
116 changes: 58 additions & 58 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static u32 GetAiFlags(u16 trainerId)
// Automatically includes AI_FLAG_SMART_MON_CHOICES to improve smart switching
if (flags & AI_FLAG_SMART_SWITCHING)
flags |= AI_FLAG_SMART_MON_CHOICES;

if (sDynamicAiFunc != NULL)
flags |= AI_FLAG_DYNAMIC_FUNC;

Expand Down Expand Up @@ -3303,44 +3303,44 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
break;
case EFFECT_ATTACK_UP:
case EFFECT_ATTACK_UP_USER_ALLY:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
break;
case EFFECT_ATTACK_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK_2, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK_2));
break;
case EFFECT_DEFENSE_UP:
case EFFECT_DEFENSE_UP_3:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
break;
case EFFECT_DEFENSE_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF_2, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF_2));
break;
case EFFECT_SPEED_UP:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
break;
case EFFECT_SPEED_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED_2, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED_2));
break;
case EFFECT_SPECIAL_ATTACK_UP:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK));
break;
case EFFECT_SPECIAL_ATTACK_UP_2:
case EFFECT_SPECIAL_ATTACK_UP_3:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK_2, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK_2));
break;
case EFFECT_SPECIAL_DEFENSE_UP:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_SPECIAL_DEFENSE_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF_2, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF_2));
break;
case EFFECT_ACCURACY_UP:
case EFFECT_ACCURACY_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC));
break;
case EFFECT_EVASION_UP:
case EFFECT_EVASION_UP_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_EVASION, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_EVASION));
break;
case EFFECT_ATTACK_DOWN:
case EFFECT_ATTACK_DOWN_2:
Expand Down Expand Up @@ -3437,13 +3437,13 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
case EFFECT_ACUPRESSURE:
break;
case EFFECT_ATTACK_ACCURACY_UP: // hone claws
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC));
break;
case EFFECT_GROWTH:
case EFFECT_ATTACK_SPATK_UP: // work up
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK));
break;
case EFFECT_HAZE:
if (AnyStatIsRaised(BATTLE_PARTNER(battlerAtk))
Expand Down Expand Up @@ -3572,7 +3572,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
ADJUST_SCORE(GOOD_EFFECT);
else if (gBattleMons[battlerDef].status1 & (STATUS1_BURN | STATUS1_PSN_ANY | STATUS1_FROSTBITE))
ADJUST_SCORE(DECENT_EFFECT);
// TODO:
// TODO:
// if (IsPredictedToSwitch(battlerDef, battlerAtk)
// ADJUST_SCORE(DECENT_EFFECT);
if (HasMoveEffect(battlerDef, EFFECT_SLEEP)
Expand Down Expand Up @@ -3698,8 +3698,8 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
}
else
{
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
}
break;
case EFFECT_PROTECT:
Expand Down Expand Up @@ -3887,7 +3887,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
case EFFECT_DEFENSE_CURL:
if (HasMoveEffect(battlerAtk, EFFECT_ROLLOUT) && !(gBattleMons[battlerAtk].status2 & STATUS2_DEFENSE_CURL))
ADJUST_SCORE(DECENT_EFFECT);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
break;
case EFFECT_FIRST_TURN_ONLY:
if (ShouldFakeOut(battlerAtk, battlerDef, move) && MoveHasAdditionalEffectWithChance(move, MOVE_EFFECT_FLINCH, 100))
Expand All @@ -3900,8 +3900,8 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
break;
if (HasMoveEffect(battlerAtk, EFFECT_SWALLOW) || HasMoveEffect(battlerAtk, EFFECT_SPIT_UP))
ADJUST_SCORE(DECENT_EFFECT);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_SWAGGER:
case EFFECT_FLATTER:
Expand Down Expand Up @@ -3981,7 +3981,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
if (HasDamagingMoveOfType(battlerAtk, TYPE_ELECTRIC))
ADJUST_SCORE(DECENT_EFFECT);
if (B_CHARGE_SPDEF_RAISE >= GEN_5)
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_TAUNT:
if (IS_MOVE_STATUS(predictedMove))
Expand Down Expand Up @@ -4192,44 +4192,44 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
ADJUST_SCORE(DECENT_EFFECT);
break;
case EFFECT_COSMIC_POWER:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_BULK_UP:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
break;
case EFFECT_CALM_MIND:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_GEOMANCY:
if (aiData->holdEffects[battlerAtk] == HOLD_EFFECT_POWER_HERB)
ADJUST_SCORE(GOOD_EFFECT);
case EFFECT_QUIVER_DANCE:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case EFFECT_VICTORY_DANCE:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_DEF));
break;
case EFFECT_SHELL_SMASH:
if (aiData->holdEffects[battlerAtk] == HOLD_EFFECT_RESTORE_STATS)
ADJUST_SCORE(WEAK_EFFECT);

IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPATK));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
break;
case EFFECT_TIDY_UP:
IncreaseTidyUpScore(battlerAtk, battlerDef, move, &score);
case EFFECT_DRAGON_DANCE:
case EFFECT_SHIFT_GEAR:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ATK));
break;
case EFFECT_GUARD_SWAP:
if (gBattleMons[battlerDef].statStages[STAT_DEF] > gBattleMons[battlerAtk].statStages[STAT_DEF]
Expand Down Expand Up @@ -4448,7 +4448,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
break;
case EFFECT_TOXIC_THREAD:
IncreasePoisonScore(battlerAtk, battlerDef, move, &score);
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
break;
case EFFECT_COUNTER:
if ((!IsBattlerIncapacitated(battlerDef, aiData->abilities[battlerDef]) && predictedMove != MOVE_NONE)
Expand Down Expand Up @@ -4519,23 +4519,23 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
case MOVE_EFFECT_SP_ATK_PLUS_1:
case MOVE_EFFECT_SP_DEF_PLUS_1:
StageStatId = STAT_CHANGE_ATK + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;
IncreaseStatUpScore(battlerAtk, battlerDef, StageStatId, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, StageStatId));
break;
case MOVE_EFFECT_ATK_PLUS_2:
case MOVE_EFFECT_DEF_PLUS_2:
case MOVE_EFFECT_SPD_PLUS_2:
case MOVE_EFFECT_SP_ATK_PLUS_2:
case MOVE_EFFECT_SP_DEF_PLUS_2:
StageStatId = STAT_CHANGE_ATK_2 + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;
IncreaseStatUpScore(battlerAtk, battlerDef, StageStatId, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, StageStatId));
break;
case MOVE_EFFECT_ACC_PLUS_1:
case MOVE_EFFECT_ACC_PLUS_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_ACC));
break;
case MOVE_EFFECT_EVS_PLUS_1:
case MOVE_EFFECT_EVS_PLUS_2:
IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_EVASION, &score);
ADJUST_SCORE(IncreaseStatUpScore(battlerAtk, battlerDef, STAT_CHANGE_EVASION));
break;
case MOVE_EFFECT_RAPID_SPIN:
if ((gSideStatuses[GetBattlerSide(battlerAtk)] & SIDE_STATUS_HAZARDS_ANY && CountUsablePartyMons(battlerAtk) != 0)
Expand All @@ -4554,36 +4554,36 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
case MOVE_EFFECT_SP_ATK_MINUS_1:
case MOVE_EFFECT_SP_DEF_MINUS_1:
StageStatId = STAT_CHANGE_ATK + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_MINUS_1;
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, StageStatId, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, StageStatId));
break;
case MOVE_EFFECT_ATK_MINUS_2:
case MOVE_EFFECT_DEF_MINUS_2:
case MOVE_EFFECT_SPD_MINUS_2:
case MOVE_EFFECT_SP_ATK_MINUS_2:
case MOVE_EFFECT_SP_DEF_MINUS_2:
StageStatId = STAT_CHANGE_ATK + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_MINUS_2;
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, StageStatId, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, StageStatId));
break;
case MOVE_EFFECT_ACC_MINUS_1:
case MOVE_EFFECT_ACC_MINUS_2:
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_ACC, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_ACC));
break;
case MOVE_EFFECT_EVS_MINUS_1:
case MOVE_EFFECT_EVS_MINUS_2:
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_EVASION, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_EVASION));
break;
case MOVE_EFFECT_DEF_SPDEF_DOWN:
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF));
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
case MOVE_EFFECT_ATK_DEF_DOWN:
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_ATK, &score);
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_ATK));
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF));
break;
case MOVE_EFFECT_V_CREATE:
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF, &score);
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPEED, &score);
IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPDEF, &score);
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_DEF));
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPEED));
ADJUST_SCORE(IncreaseStatUpScoreContrary(battlerAtk, battlerDef, STAT_CHANGE_SPDEF));
break;
}
}
Expand Down Expand Up @@ -5376,7 +5376,7 @@ s32 AI_TagBattlePreferFoe(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
/* attacking along the diagonal */
ADJUST_SCORE(-20);
}

return score;
}

Expand Down
Loading
Loading