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

MoveInfo rearrangement and flag optimisation #4096

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e602a31
BattleMove adjustment
cfmnephrite Jan 29, 2024
02ffd05
Removed Sheer Force flag
cfmnephrite Jan 30, 2024
086375a
Moved a couple more flags
cfmnephrite Jan 30, 2024
8a8d181
AdditionalEffects storage tweak
cfmnephrite Feb 1, 2024
ce4dd72
Merged from upcoming
cfmnephrite Feb 9, 2024
436ef7e
Tweaks + RETURN_MOVE_HAS_MOVE_EFFECT_WITH macro
cfmnephrite Feb 9, 2024
3695f03
Reordered everything in moves_info.h to be in struct order
cfmnephrite Feb 12, 2024
b665e72
Merge remote-tracking branch 'rhh/upcoming' into battlemove_refactored
cfmnephrite Feb 12, 2024
16ab876
Swapped power/accuracy and type/split
cfmnephrite Feb 12, 2024
b447add
Minor fixes to RNG and additional effect count
cfmnephrite Feb 12, 2024
3537a37
Re-added missing linebreaks
cfmnephrite Feb 12, 2024
1ac9934
Reverted `forcePressure` flag move
cfmnephrite Feb 13, 2024
7592ec5
Revert moves_info.h reorder
cfmnephrite Feb 25, 2024
b55b1ea
Added word comment
cfmnephrite Feb 25, 2024
9db03fb
Removed GET_MOVE_EFFECT
cfmnephrite Feb 25, 2024
174c6fc
Renamed "MoveHasMoveEffect" functions
cfmnephrite Feb 26, 2024
46b6735
Merge remote-tracking branch 'rhh/upcoming' into battlemove_refactored
cfmnephrite Feb 26, 2024
0aac57b
Renamed TestSheerForceFlag
cfmnephrite Feb 26, 2024
b0d36b2
Fixed test
cfmnephrite Feb 26, 2024
170070b
Apply suggestions from code review
cfmnephrite Feb 26, 2024
4781ca4
Renamed GET_ADDITIONAL_EFFECT_COUNT macro
cfmnephrite Feb 26, 2024
b1f0fbd
Merge remote-tracking branch 'rhh/upcoming' into battlemove_refactored
cfmnephrite Feb 27, 2024
e9b2f33
Fixed Tangling Hair + Mirror Armor interaction
cfmnephrite Feb 27, 2024
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
2 changes: 1 addition & 1 deletion data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -8552,7 +8552,7 @@ BattleScript_GooeyActivates::
waitstate
call BattleScript_AbilityPopUp
swapattackerwithtarget @ for defiant, mirror armor
seteffectsecondary
seteffectsecondary MOVE_EFFECT_SPD_MINUS_1
swapattackerwithtarget
return

Expand Down
6 changes: 4 additions & 2 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ struct __attribute__((packed, aligned(2))) BattleMoveEffect
const u8 *battleScript;
u16 battleTvScore:3;
u16 encourageEncore:1;
u16 twoTurnEffect:1;
u16 semiInvulnerableEffect:1;
u16 flags:11; // coming soon...
u16 usesProtectCounter:1;
u16 padding:9;
};

#define GET_MOVE_BATTLESCRIPT(move) gBattleMoveEffects[gMovesInfo[move].effect].battleScript
Expand Down Expand Up @@ -612,7 +614,6 @@ struct BattleStruct
u32 expValue;
u8 expGettersOrder[PARTY_SIZE]; // First battlers which were sent out, then via exp-share
u8 expGetterMonId;
u8 additionalEffectsCounter:2;
u8 expOrderId:3;
u8 expGetterBattlerId:2;
u8 teamGotExpMsgPrinted:1; // The 'Rest of your team got msg' has been printed.
Expand Down Expand Up @@ -736,6 +737,7 @@ struct BattleStruct
u8 forcedSwitch:4; // For each battler
u8 blunderPolicy:1; // should blunder policy activate
u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky
u8 additionalEffectsCounter:4; // A counter for the additionalEffects applied by the current move in Cmd_setadditionaleffects
u8 ballSpriteIds[2]; // item gfx, window gfx
u8 appearedInBattle; // Bitfield to track which Pokemon appeared in battle. Used for Burmy's form change
u8 skyDropTargets[MAX_BATTLERS_COUNT]; // For Sky Drop, to account for if multiple Pokemon use Sky Drop in a double battle.
Expand Down
13 changes: 7 additions & 6 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ bool32 IsHealBlockPreventingMove(u32 battler, u32 move);
bool32 HasEnoughHpToEatBerry(u32 battler, u32 hpFraction, u32 itemId);
bool32 IsPartnerMonFromSameTrainer(u32 battler);
u8 GetCategoryBasedOnStats(u32 battler);
bool32 TestSheerForceFlag(u32 battler, u16 move);
bool32 MoveIsAffectedBySheerForce(u16 move);
bool32 TestIfSheerForceAffected(u32 battler, u16 move);
void TryRestoreHeldItems(void);
bool32 CanStealItem(u32 battlerStealing, u32 battlerItem, u16 item);
void TrySaveExchangedItem(u32 battler, u16 stolenItem);
Expand All @@ -222,11 +223,11 @@ void CopyMonAbilityAndTypesToBattleMon(u32 battler, struct Pokemon *mon);
void RecalcBattlerStats(u32 battler, struct Pokemon *mon);
bool32 IsAlly(u32 battlerAtk, u32 battlerDef);
bool32 IsGen6ExpShareEnabled(void);
bool32 MoveHasMoveEffect(u32 move, u32 moveEffect);
bool32 MoveHasMoveEffectWithChance(u32 move, u32 moveEffect, u32 chance);
bool32 MoveHasMoveEffectSelf(u32 move, u32 moveEffect);
bool32 MoveHasMoveEffectSelfArg(u32 move, u32 moveEffect, u32 argument);
bool32 MoveHasChargeTurnMoveEffect(u32 move);
bool32 MoveHasAdditionalEffect(u32 move, u32 moveEffect);
bool32 MoveHasAdditionalEffectWithChance(u32 move, u32 moveEffect, u32 chance);
bool32 MoveHasAdditionalEffectSelf(u32 move, u32 moveEffect);
bool32 MoveHasAdditionalEffectSelfArg(u32 move, u32 moveEffect, u32 argument);
bool32 MoveHasChargeTurnAdditionalEffect(u32 move);

bool32 CanSleep(u32 battler);
bool32 CanBePoisoned(u32 battlerAttacker, u32 battlerTarget);
Expand Down
51 changes: 28 additions & 23 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,44 +451,40 @@ struct MoveInfo
const u8 *name;
const u8 *description;
u16 effect;
u8 power;
u8 type:5;
u8 category:3;

u16 type:5;
u16 category:2;
u16 power:9; // up to 511
cfmnephrite marked this conversation as resolved.
Show resolved Hide resolved
u16 accuracy:7;
u16 recoil:7;
u16 criticalHitStage:2;
u8 padding:6; // coming soon...
u8 numAdditionalEffects:2; // limited to 3 - don't want to get too crazy
u16 target:9;
u8 pp;

u16 target;
s8 priority;
union {
u8 effect;
u8 powerOverride;
} zMove;

s32 priority:4;
u32 recoil:7;
u32 strikeCount:4; // Max 15 hits. Defaults to 1 if not set. May apply its effect on each hit.
u32 criticalHitStage:2;
u32 alwaysCriticalHit:1;
// 14 bits left to complete this word - continues into flags
cfmnephrite marked this conversation as resolved.
Show resolved Hide resolved

// Flags
u32 makesContact:1;
u32 ignoresProtect:1;
u32 magicCoatAffected:1;
u32 snatchAffected:1;
u32 mirrorMoveBanned:1;
u32 ignoresKingsRock:1;
u32 alwaysCriticalHit:1;
u32 twoTurnMove:1;
u32 punchingMove:1;
u32 sheerForceBoost:1;
u32 bitingMove:1;
u32 pulseMove:1;
u32 soundMove:1;
u32 ballisticMove:1;
u32 protectionMove:1;
u32 powderMove:1;
u32 danceMove:1;
u32 windMove:1;
u32 slicingMove:1;
u32 slicingMove:1; // end of word
u32 healingMove:1;
u32 minimizeDoubleDamage:1;
u32 ignoresTargetAbility:1;
u32 ignoresTargetDefenseEvasionStages:1;
Expand All @@ -499,11 +495,12 @@ struct MoveInfo
u32 ignoreTypeIfFlyingAndUngrounded:1;
u32 thawsUser:1;
u32 ignoresSubstitute:1;
u32 strikeCount:4; // Max 15 hits. Defaults to 1 if not set. May apply its effect on each hit.
u32 forcePressure:1;
u32 cantUseTwice:1;

// Ban flags
u32 gravityBanned:1;
u32 healingMove:1;
u32 mirrorMoveBanned:1;
u32 meFirstBanned:1;
u32 mimicBanned:1;
u32 metronomeBanned:1;
Expand All @@ -516,10 +513,10 @@ struct MoveInfo
u32 skyBattleBanned:1;
u32 sketchBanned:1;

u32 argument; // also coming soon
u32 argument;

// primary/secondary effects
const struct AdditionalEffect *additionalEffects;
uintptr_t additionalEffects;

// contest parameters
u8 contestEffect;
Expand All @@ -529,15 +526,23 @@ struct MoveInfo
};

#define EFFECTS_ARR(...) (const struct AdditionalEffect[]) {__VA_ARGS__}
#define ADDITIONAL_EFFECTS(...) EFFECTS_ARR( __VA_ARGS__ ), .numAdditionalEffects = ARRAY_COUNT(EFFECTS_ARR( __VA_ARGS__ ))
#define ADDITIONAL_EFFECTS(...) ((min(ARRAY_COUNT(EFFECTS_ARR( __VA_ARGS__ )), 15)) << 28) + (uintptr_t)(EFFECTS_ARR( __VA_ARGS__ ))

// Retrieve a move's additional effects and the count thereof
#define GET_ADDITIONAL_EFFECTS(move) (void *)(gMovesInfo[move].additionalEffects & 0x8FFFFFF)
#define GET_ADDITIONAL_EFFECT_COUNT(move) (gMovesInfo[move].additionalEffects >> 28)
#define GET_ADDITIONAL_EFFECTS_AND_COUNT(move, _count, _effects) u32 _count = GET_ADDITIONAL_EFFECT_COUNT(move); const struct AdditionalEffect *_effects = GET_ADDITIONAL_EFFECTS(move)

// Just a hack to make a move boosted by Sheer Force despite having no secondary effects affected
#define SHEER_FORCE_HACK { .moveEffect = 0, .chance = 100, }

struct AdditionalEffect
{
u16 moveEffect;
u8 self:1;
u8 onlyIfTargetRaisedStats:1;
u8 onChargeTurnOnly:1;
u8 chance; // 0% = effect certain, primary effect
u16 moveEffect;
};

struct Ability
Expand Down
34 changes: 21 additions & 13 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2507,8 +2507,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)

if (instructedMove == MOVE_NONE
|| gMovesInfo[instructedMove].instructBanned
|| gMovesInfo[instructedMove].twoTurnMove
AsparagusEduardo marked this conversation as resolved.
Show resolved Hide resolved
|| MoveHasMoveEffectSelf(instructedMove, MOVE_EFFECT_RECHARGE)
|| MoveHasAdditionalEffectSelf(instructedMove, MOVE_EFFECT_RECHARGE)
|| IsZMove(instructedMove)
|| (gLockedMoves[battlerDef] != 0 && gLockedMoves[battlerDef] != 0xFFFF)
|| gBattleMons[battlerDef].status2 & STATUS2_MULTIPLETURNS
Expand Down Expand Up @@ -3229,6 +3228,9 @@ static u32 AI_CalcMoveScore(u32 battlerAtk, u32 battlerDef, u32 move)
u32 movesetIndex = AI_THINKING_STRUCT->movesetIndex;
u32 effectiveness = aiData->effectiveness[battlerAtk][battlerDef][movesetIndex];

// additional effects
GET_ADDITIONAL_EFFECTS_AND_COUNT(move, additionalEffectsCount, additionalEffects);

s32 score = 0;
u32 predictedMove = aiData->predictedMoves[battlerDef];
u32 predictedMoveSlot = GetMoveSlot(GetMovesArray(battlerDef), predictedMove);
Expand Down Expand Up @@ -4458,19 +4460,19 @@ static u32 AI_CalcMoveScore(u32 battlerAtk, u32 battlerDef, u32 move)
} // move effect checks

// check move additional effects that are likely to happen
for (i = 0; i < gMovesInfo[move].numAdditionalEffects; i++)
for (i = 0; i < additionalEffectsCount; i++)
{
// Only consider effects with a guaranteed chance to happen
if (!MoveEffectIsGuaranteed(battlerAtk, aiData->abilities[battlerAtk], &gMovesInfo[move].additionalEffects[i]))
if (!MoveEffectIsGuaranteed(battlerAtk, aiData->abilities[battlerAtk], &additionalEffects[i]))
continue;

// Consider move effects that target self
if (gMovesInfo[move].additionalEffects[i].self)
if (additionalEffects[i].self)
{
u32 oneStageStatId = STAT_CHANGE_ATK + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;
u32 twoStageStatId = STAT_CHANGE_ATK_2 + gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;
u32 oneStageStatId = STAT_CHANGE_ATK + additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;
u32 twoStageStatId = STAT_CHANGE_ATK_2 + additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_PLUS_1;

switch (gMovesInfo[move].additionalEffects[i].moveEffect)
switch (additionalEffects[i].moveEffect)
{
case MOVE_EFFECT_SPD_PLUS_2:
case MOVE_EFFECT_SPD_PLUS_1:
Expand Down Expand Up @@ -4521,7 +4523,7 @@ static u32 AI_CalcMoveScore(u32 battlerAtk, u32 battlerDef, u32 move)
}
else // consider move effects that hinder the target
{
switch (gMovesInfo[move].additionalEffects[i].moveEffect)
switch (additionalEffects[i].moveEffect)
{
case MOVE_EFFECT_FLINCH:
score += ShouldTryToFlinch(battlerAtk, battlerDef, aiData->abilities[battlerAtk], aiData->abilities[battlerDef], move);
Expand Down Expand Up @@ -4805,11 +4807,13 @@ static s32 AI_SetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score
ADJUST_SCORE(DECENT_EFFECT);
break;
case EFFECT_HIT:
{
// TEMPORARY - should applied to all moves regardless of EFFECT
// Consider move effects
for (i = 0; i < gMovesInfo[move].numAdditionalEffects; i++)
GET_ADDITIONAL_EFFECTS_AND_COUNT(move, additionalEffectsCount, additionalEffects);
for (i = 0; i < additionalEffectsCount; i++)
{
switch (gMovesInfo[move].additionalEffects[i].moveEffect)
switch (additionalEffects[i].moveEffect)
{
case MOVE_EFFECT_STEALTH_ROCK:
case MOVE_EFFECT_SPIKES:
Expand All @@ -4819,6 +4823,7 @@ static s32 AI_SetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score
break;
}
}
}
default:
break;
}
Expand Down Expand Up @@ -4859,11 +4864,13 @@ static s32 AI_Risky(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
ADJUST_SCORE(DECENT_EFFECT);
break;
case EFFECT_HIT:
{
// TEMPORARY - should applied to all moves regardless of EFFECT
// Consider move effects
for (i = 0; i < gMovesInfo[move].numAdditionalEffects; i++)
GET_ADDITIONAL_EFFECTS_AND_COUNT(move, additionalEffectsCount, additionalEffects);
for (i = 0; i < additionalEffectsCount; i++)
{
switch (gMovesInfo[move].additionalEffects[i].moveEffect)
switch (additionalEffects[i].moveEffect)
{
case MOVE_EFFECT_ALL_STATS_UP:
if (Random() & 1)
Expand All @@ -4873,6 +4880,7 @@ static s32 AI_Risky(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
break;
}
}
}
default:
break;
}
Expand Down
Loading
Loading