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

Minor shouldUseGimmick refactor #4962

Merged
merged 1 commit into from
Jul 13, 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
7 changes: 4 additions & 3 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ struct TrainerMon
u8 nature:5;
bool8 gender:2;
bool8 isShiny:1;
u8 useGimmick:4;
u8 dynamaxLevel:4;
u8 teraType:5;
bool8 gigantamaxFactor:1;
u8 padding:2;
u8 shouldUseDynamax:1;
u8 padding1:1;
u8 dynamaxLevel:4;
u8 padding2:4;
};

#define TRAINER_PARTY(partyArray) partyArray, .partySize = ARRAY_COUNT(partyArray)
Expand Down
10 changes: 8 additions & 2 deletions src/battle_gimmick.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ bool32 ShouldTrainerBattlerUseGimmick(u32 battler, enum Gimmick gimmick)
bool32 isSecondTrainer = (GetBattlerPosition(battler) == B_POSITION_OPPONENT_RIGHT) && (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && !BATTLE_TWO_VS_ONE_OPPONENT;
u16 trainerId = isSecondTrainer ? gTrainerBattleOpponent_B : gTrainerBattleOpponent_A;
const struct TrainerMon *mon = &GetTrainerPartyFromId(trainerId)[isSecondTrainer ? gBattlerPartyIndexes[battler] - MULTI_PARTY_SIZE : gBattlerPartyIndexes[battler]];
return mon->useGimmick == gimmick;

if (gimmick == GIMMICK_TERA && mon->teraType != TYPE_NONE)
return TRUE;
if (gimmick == GIMMICK_DYNAMAX && mon->shouldUseDynamax)
return TRUE;
}

return FALSE;
}

// Returns whether a trainer has used a gimmick during a battle.
Expand Down Expand Up @@ -290,7 +296,7 @@ static inline u32 GetIndicatorSpriteId(u32 healthboxId)
u32 GetIndicatorTileTag(u32 battler)
{
u32 gimmick = GetActiveGimmick(battler);

if (IsBattlerPrimalReverted(battler))
{
if (gBattleMons[battler].species == SPECIES_GROUDON_PRIMAL)
Expand Down
21 changes: 12 additions & 9 deletions src/battle_terastal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void ActivateTera(u32 battler)
{
FlagClear(B_FLAG_TERA_ORB_CHARGED);
}

// Execute battle script.
PREPARE_TYPE_BUFFER(gBattleTextBuff1, GetBattlerTeraType(battler));
if (TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_TERASTALLIZATION))
Expand Down Expand Up @@ -63,16 +63,19 @@ bool32 CanTerastallize(u32 battler)
{
u32 holdEffect = GetBattlerHoldEffect(battler, FALSE);

// Check if Player has Tera Orb and has charge.
if (!TESTING && !CheckBagHasItem(ITEM_TERA_ORB, 1))
return FALSE;

if (!TESTING
&& !(B_FLAG_TERA_ORB_NO_COST != 0 && FlagGet(B_FLAG_TERA_ORB_NO_COST))
&& (battler == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && battler == B_POSITION_PLAYER_RIGHT)))
if (GetBattlerSide(battler) == B_SIDE_PLAYER)
{
if (B_FLAG_TERA_ORB_CHARGED != 0 && !FlagGet(B_FLAG_TERA_ORB_CHARGED))
// Check if Player has Tera Orb and has charge.
if (!TESTING && !CheckBagHasItem(ITEM_TERA_ORB, 1))
return FALSE;

if (!TESTING
Comment on lines +69 to +72
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we check !TESTING twice, shouldn't we just rewrite it so it only needs to be checked once?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this touches the same code as #4863. Does this supersede that PR, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. Only thing I did was wrap it around the player check but I agree with you that it should be somehow simplified. In general I think that the whole sequence of checks is very weird which I tried to simplify in #4863. In general though I would prefer it if this pr gets merged (ideally first) and the rest is handled in the old pr.

&& !(B_FLAG_TERA_ORB_NO_COST != 0 && FlagGet(B_FLAG_TERA_ORB_NO_COST))
&& (battler == B_POSITION_PLAYER_LEFT || (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && battler == B_POSITION_PLAYER_RIGHT)))
{
if (B_FLAG_TERA_ORB_CHARGED != 0 && !FlagGet(B_FLAG_TERA_ORB_CHARGED))
return FALSE;
}
}

// Check if Trainer has already Terastallized.
Expand Down
2 changes: 1 addition & 1 deletion test/battle/trainer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
.isShiny = TRUE,
#line 18
.dynamaxLevel = 5,
.useGimmick = GIMMICK_DYNAMAX,
.shouldUseDynamax = TRUE,
.moves = {
#line 19
MOVE_AIR_SLASH,
Expand Down
3 changes: 1 addition & 2 deletions tools/trainerproc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,15 +1824,14 @@ static void fprint_trainers(const char *output_path, FILE *f, struct Parsed *par

if (pokemon->dynamax_level_line || pokemon->gigantamax_factor_line)
{
fprintf(f, " .useGimmick = GIMMICK_DYNAMAX,\n");
fprintf(f, " .shouldUseDynamax = TRUE,\n");
}
else if (pokemon->tera_type_line)
{
fprintf(f, "#line %d\n", pokemon->tera_type_line);
fprintf(f, " .teraType = ");
fprint_constant(f, "TYPE", pokemon->tera_type);
fprintf(f, ",\n");
fprintf(f, " .useGimmick = GIMMICK_TERA,\n");
}

if (pokemon->moves_n > 0)
Expand Down
Loading