Setting Battle configs during tests (#5803)

Co-authored-by: sbird <sbird@no.tld>
This commit is contained in:
Eduardo Quezada 2024-12-29 19:28:39 -03:00 committed by GitHub
parent e64da065e8
commit 009de5c98c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 103 additions and 9 deletions

View file

@ -350,6 +350,8 @@ $(C_BUILDDIR)/pokedex_plus_hgss.o: CFLAGS := -mthumb -mthumb-interwork -O2 -mabi
# Annoyingly we can't turn this on just for src/data/trainers.h # Annoyingly we can't turn this on just for src/data/trainers.h
$(C_BUILDDIR)/data.o: CFLAGS += -fno-show-column -fno-diagnostics-show-caret $(C_BUILDDIR)/data.o: CFLAGS += -fno-show-column -fno-diagnostics-show-caret
$(TEST_BUILDDIR)/%.o: CFLAGS := -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -Wno-pointer-to-int-cast -Werror -Wall -Wno-strict-aliasing -Wno-attribute-alias -Woverride-init
# Dependency rules (for the *.c & *.s sources to .o files) # Dependency rules (for the *.c & *.s sources to .o files)
# Have to be explicit or else missing files won't be reported. # Have to be explicit or else missing files won't be reported.

View file

@ -0,0 +1,10 @@
#ifndef GUARD_CONSTANTS_GENERATIONAL_CHANGES_H
#define GUARD_CONSTANTS_GENERATIONAL_CHANGES_H
enum GenConfigTag
{
GEN_CONFIG_GALE_WINGS,
GEN_CONFIG_COUNT
};
#endif // GUARD_CONSTANTS_GENERATIONAL_CHANGES_H

View file

@ -0,0 +1,41 @@
#ifndef GUARD_GENERATIONAL_CHANGES_H
#define GUARD_GENERATIONAL_CHANGES_H
#include "constants/generational_changes.h"
#include "config/battle.h"
static const u8 sGenerationalChanges[GEN_CONFIG_COUNT] =
{
[GEN_CONFIG_GALE_WINGS] = B_GALE_WINGS,
};
#if TESTING
extern u8 *gGenerationalChangesTestOverride;
#endif
static inline u32 GetGenConfig(enum GenConfigTag configTag)
{
if (configTag >= GEN_CONFIG_COUNT) return GEN_LATEST;
#if TESTING
if (gGenerationalChangesTestOverride == NULL) return sGenerationalChanges[configTag];
return gGenerationalChangesTestOverride[configTag];
#else
return sGenerationalChanges[configTag];
#endif
}
static inline void SetGenConfig(enum GenConfigTag configTag, u32 value)
{
#if TESTING
if (configTag >= GEN_CONFIG_COUNT) return;
if (gGenerationalChangesTestOverride == NULL) return;
gGenerationalChangesTestOverride[configTag] = value;
#endif
}
#if TESTING
void TestInitConfigData(void);
void TestFreeConfigData(void);
#endif
#endif // GUARD_GENERATIONAL_CHANGES_H

View file

@ -287,6 +287,16 @@
* GIVEN { * GIVEN {
* FLAG_SET(FLAG_SYS_EXAMPLE_FLAG); * FLAG_SET(FLAG_SYS_EXAMPLE_FLAG);
* *
* WITH_CONFIG(configTag, value)
* Runs the test with a specified config override. `configTag` must be
* of `enum GenConfigTag`
* Example:
* GIVEN {
* WITH_CONFIG(GEN_CONFIG_GALE_WINGS, GEN_6);
* }
* The `value` may be inferred from a local variable, e.g. set by
* PARAMETRIZE.
*
* PLAYER(species) and OPPONENT(species) * PLAYER(species) and OPPONENT(species)
* Adds the species to the player's or opponent's party respectively. * Adds the species to the player's or opponent's party respectively.
* The Pokémon can be further customized with the following functions: * The Pokémon can be further customized with the following functions:
@ -488,6 +498,7 @@
#include "battle.h" #include "battle.h"
#include "battle_anim.h" #include "battle_anim.h"
#include "data.h" #include "data.h"
#include "generational_changes.h"
#include "item.h" #include "item.h"
#include "random.h" #include "random.h"
#include "recorded_battle.h" #include "recorded_battle.h"
@ -822,6 +833,7 @@ struct moveWithPP {
#define AI_LOG AILogScores(__LINE__) #define AI_LOG AILogScores(__LINE__)
#define FLAG_SET(flagId) SetFlagForTest(__LINE__, flagId) #define FLAG_SET(flagId) SetFlagForTest(__LINE__, flagId)
#define WITH_CONFIG(configTag, value) TestSetConfig(__LINE__, configTag, value)
#define PLAYER(species) for (OpenPokemon(__LINE__, B_SIDE_PLAYER, species); gBattleTestRunnerState->data.currentMon; ClosePokemon(__LINE__)) #define PLAYER(species) for (OpenPokemon(__LINE__, B_SIDE_PLAYER, species); gBattleTestRunnerState->data.currentMon; ClosePokemon(__LINE__))
#define OPPONENT(species) for (OpenPokemon(__LINE__, B_SIDE_OPPONENT, species); gBattleTestRunnerState->data.currentMon; ClosePokemon(__LINE__)) #define OPPONENT(species) for (OpenPokemon(__LINE__, B_SIDE_OPPONENT, species); gBattleTestRunnerState->data.currentMon; ClosePokemon(__LINE__))
@ -855,6 +867,7 @@ struct moveWithPP {
#define Shadow(isShadow) Shadow_(__LINE__, shadow) #define Shadow(isShadow) Shadow_(__LINE__, shadow)
void SetFlagForTest(u32 sourceLine, u16 flagId); void SetFlagForTest(u32 sourceLine, u16 flagId);
void TestSetConfig(u32 sourceLine, enum GenConfigTag configTag, u32 value);
void ClearFlagAfterTest(void); void ClearFlagAfterTest(void);
void OpenPokemon(u32 sourceLine, u32 side, u32 species); void OpenPokemon(u32 sourceLine, u32 side, u32 species);
void ClosePokemon(u32 sourceLine); void ClosePokemon(u32 sourceLine);

View file

@ -24,6 +24,7 @@
#include "event_data.h" #include "event_data.h"
#include "evolution_scene.h" #include "evolution_scene.h"
#include "field_weather.h" #include "field_weather.h"
#include "generational_changes.h"
#include "graphics.h" #include "graphics.h"
#include "gpu_regs.h" #include "gpu_regs.h"
#include "international_string_util.h" #include "international_string_util.h"
@ -4851,7 +4852,7 @@ s8 GetMovePriority(u32 battler, u16 move)
return gMovesInfo[MOVE_MAX_GUARD].priority; return gMovesInfo[MOVE_MAX_GUARD].priority;
if (ability == ABILITY_GALE_WINGS if (ability == ABILITY_GALE_WINGS
&& (B_GALE_WINGS < GEN_7 || BATTLER_MAX_HP(battler)) && (GetGenConfig(GEN_CONFIG_GALE_WINGS) < GEN_7 || BATTLER_MAX_HP(battler))
&& gMovesInfo[move].type == TYPE_FLYING) && gMovesInfo[move].type == TYPE_FLYING)
{ {
priority++; priority++;

View file

@ -0,0 +1,19 @@
#include "global.h"
#include "generational_changes.h"
#include "malloc.h"
#include "constants/generational_changes.h"
#if TESTING
EWRAM_DATA u8 *gGenerationalChangesTestOverride = NULL;
void TestInitConfigData(void)
{
gGenerationalChangesTestOverride = Alloc(sizeof(sGenerationalChanges));
memcpy(gGenerationalChangesTestOverride, sGenerationalChanges, sizeof(sGenerationalChanges));
}
void TestFreeConfigData(void)
{
TRY_FREE_AND_SET_NULL(gGenerationalChangesTestOverride)
}
#endif

View file

@ -1,20 +1,22 @@
#include "global.h" #include "global.h"
#include "test/battle.h" #include "test/battle.h"
SINGLE_BATTLE_TEST("Gale Wings only grants priority at full HP") SINGLE_BATTLE_TEST("Gale Wings only grants priority at full HP (Gen 7+)")
{ {
u16 hp; u32 hp, config;
PARAMETRIZE { hp = 100; } PARAMETRIZE { hp = 100; config = GEN_7; }
PARAMETRIZE { hp = 99; } PARAMETRIZE { hp = 99; config = GEN_7; }
PARAMETRIZE { hp = 100; config = GEN_6; }
PARAMETRIZE { hp = 99; config = GEN_6; }
GIVEN { GIVEN {
ASSUME(B_GALE_WINGS >= GEN_7); WITH_CONFIG(GEN_CONFIG_GALE_WINGS, config);
ASSUME(gMovesInfo[MOVE_AERIAL_ACE].type == TYPE_FLYING); ASSUME(gMovesInfo[MOVE_AERIAL_ACE].type == TYPE_FLYING);
PLAYER(SPECIES_TALONFLAME) { Ability(ABILITY_GALE_WINGS); HP(hp); MaxHP(100); Speed(1);} PLAYER(SPECIES_TALONFLAME) { Ability(ABILITY_GALE_WINGS); HP(hp); MaxHP(100); Speed(1);}
OPPONENT(SPECIES_WOBBUFFET) { Speed(100);}; OPPONENT(SPECIES_WOBBUFFET) { Speed(100);};
} WHEN { } WHEN {
TURN { MOVE(player, MOVE_AERIAL_ACE); } TURN { MOVE(player, MOVE_AERIAL_ACE); }
} SCENE { } SCENE {
if (hp == 100) { if (hp == 100 || config <= GEN_6) {
MESSAGE("Talonflame used Aerial Ace!"); MESSAGE("Talonflame used Aerial Ace!");
MESSAGE("The opposing Wobbuffet used Celebrate!"); MESSAGE("The opposing Wobbuffet used Celebrate!");
} }
@ -31,7 +33,6 @@ SINGLE_BATTLE_TEST("Gale Wings only grants priority to Flying-type moves")
PARAMETRIZE { move = MOVE_AERIAL_ACE; } PARAMETRIZE { move = MOVE_AERIAL_ACE; }
PARAMETRIZE { move = MOVE_FLARE_BLITZ; } PARAMETRIZE { move = MOVE_FLARE_BLITZ; }
GIVEN { GIVEN {
ASSUME(B_GALE_WINGS >= GEN_7);
ASSUME(gMovesInfo[MOVE_AERIAL_ACE].type == TYPE_FLYING); ASSUME(gMovesInfo[MOVE_AERIAL_ACE].type == TYPE_FLYING);
ASSUME(gMovesInfo[MOVE_FLARE_BLITZ].type == TYPE_FIRE); ASSUME(gMovesInfo[MOVE_FLARE_BLITZ].type == TYPE_FIRE);
PLAYER(SPECIES_TALONFLAME) { Ability(ABILITY_GALE_WINGS); HP(100); MaxHP(100); Speed(1);} PLAYER(SPECIES_TALONFLAME) { Ability(ABILITY_GALE_WINGS); HP(100); MaxHP(100); Speed(1);}
@ -58,7 +59,6 @@ SINGLE_BATTLE_TEST("Gale Wings doesn't increase priority of Flying-type Natural
PARAMETRIZE { move = MOVE_JUDGMENT; heldItem = ITEM_SKY_PLATE; } PARAMETRIZE { move = MOVE_JUDGMENT; heldItem = ITEM_SKY_PLATE; }
PARAMETRIZE { move = MOVE_HIDDEN_POWER; heldItem = ITEM_NONE; } PARAMETRIZE { move = MOVE_HIDDEN_POWER; heldItem = ITEM_NONE; }
GIVEN { GIVEN {
ASSUME(B_GALE_WINGS >= GEN_7);
ASSUME(gMovesInfo[MOVE_NATURAL_GIFT].effect == EFFECT_NATURAL_GIFT); ASSUME(gMovesInfo[MOVE_NATURAL_GIFT].effect == EFFECT_NATURAL_GIFT);
ASSUME(gMovesInfo[MOVE_JUDGMENT].effect == EFFECT_CHANGE_TYPE_ON_ITEM); ASSUME(gMovesInfo[MOVE_JUDGMENT].effect == EFFECT_CHANGE_TYPE_ON_ITEM);
// IV combinations sourced from https://www.smogon.com/forums/threads/hidden-power-iv-combinations.78083/ // IV combinations sourced from https://www.smogon.com/forums/threads/hidden-power-iv-combinations.78083/

View file

@ -160,6 +160,7 @@ static void BattleTest_SetUp(void *data)
{ {
const struct BattleTest *test = data; const struct BattleTest *test = data;
memset(STATE, 0, sizeof(*STATE)); memset(STATE, 0, sizeof(*STATE));
TestInitConfigData();
InvokeTestFunction(test); InvokeTestFunction(test);
STATE->parameters = STATE->parametersCount; STATE->parameters = STATE->parametersCount;
if (STATE->parametersCount == 0 && test->resultsSize > 0) if (STATE->parametersCount == 0 && test->resultsSize > 0)
@ -1417,6 +1418,7 @@ static void BattleTest_TearDown(void *data)
// Free resources that aren't cleaned up when the battle was // Free resources that aren't cleaned up when the battle was
// aborted unexpectedly. // aborted unexpectedly.
ClearFlagAfterTest(); ClearFlagAfterTest();
TestFreeConfigData();
if (STATE->tearDownBattle) if (STATE->tearDownBattle)
TearDownBattle(); TearDownBattle();
} }
@ -1513,6 +1515,12 @@ void SetFlagForTest(u32 sourceLine, u16 flagId)
FlagSet(flagId); FlagSet(flagId);
} }
void TestSetConfig(u32 sourceLine, enum GenConfigTag configTag, u32 value)
{
INVALID_IF(!STATE->runGiven, "WITH_CONFIG outside of GIVEN");
SetGenConfig(configTag, value);
}
void ClearFlagAfterTest(void) void ClearFlagAfterTest(void)
{ {
if (DATA.flagId != 0) if (DATA.flagId != 0)