sovereignx/test/battle/trainer_control.c

116 lines
4.8 KiB
C
Raw Normal View History

#include "global.h"
#include "test/test.h"
#include "battle.h"
#include "battle_main.h"
#include "data.h"
#include "malloc.h"
2023-10-23 13:37:40 +01:00
#include "random.h"
#include "string_util.h"
#include "constants/item.h"
#include "constants/abilities.h"
#include "constants/trainers.h"
#include "constants/battle.h"
Competitive-formatted parties (#3545) $ python3 migration_scripts/convert_parties.py src/data/trainers.h src/data/trainer_parties.h src/data/npc_trainers.party Is available to convert Trainer Control-formatted trainers/parties into Competitive-formatted ones. Multiple '#include's can be placed in the trainer section of src/data.c to support spreading the trainers across multiple .party files. trainerproc does not interpret the values, leaving that job to the C compiler, so we use '#line' to associate those errors with the lines in the .party file(s). Because the columns don't make sense we use -fno-show-column and -fno-diagostics-show-caret. We might want to move gTrainers into its own file so that the rest of src/data.c isn't affected by those flags. Extensions (misfeatures, imo): - .party files are passed through cpp, so '#define's are supported, and so are '// ...' and '/* ... */' comments. - .party files also support writing, e.g. 'SPECIES_PIKACHU' instead of 'Pikachu'. This allows people to write constants explicitly if they like. Pragmas: - '#pragma trainerproc ivs explicit' requires an explicit 'IVs:' line rather than defaulting to 31s. - '#pragma trainerproc ivs <IVs>' changes the default IVs. - '#pragma trainerproc level explicit' requires an explicit 'Level:' line rather than defaulting to 100. - '#pragma trainerproc level <level>' changes the default level. Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
2024-04-06 19:05:15 +01:00
static const struct Trainer sTestTrainers[] =
{
Competitive-formatted parties (#3545) $ python3 migration_scripts/convert_parties.py src/data/trainers.h src/data/trainer_parties.h src/data/npc_trainers.party Is available to convert Trainer Control-formatted trainers/parties into Competitive-formatted ones. Multiple '#include's can be placed in the trainer section of src/data.c to support spreading the trainers across multiple .party files. trainerproc does not interpret the values, leaving that job to the C compiler, so we use '#line' to associate those errors with the lines in the .party file(s). Because the columns don't make sense we use -fno-show-column and -fno-diagostics-show-caret. We might want to move gTrainers into its own file so that the rest of src/data.c isn't affected by those flags. Extensions (misfeatures, imo): - .party files are passed through cpp, so '#define's are supported, and so are '// ...' and '/* ... */' comments. - .party files also support writing, e.g. 'SPECIES_PIKACHU' instead of 'Pikachu'. This allows people to write constants explicitly if they like. Pragmas: - '#pragma trainerproc ivs explicit' requires an explicit 'IVs:' line rather than defaulting to 31s. - '#pragma trainerproc ivs <IVs>' changes the default IVs. - '#pragma trainerproc level explicit' requires an explicit 'Level:' line rather than defaulting to 100. - '#pragma trainerproc level <level>' changes the default level. Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
2024-04-06 19:05:15 +01:00
#include "trainer_control.h"
};
TEST("CreateNPCTrainerPartyForTrainer generates customized Pokémon")
{
struct Pokemon *testParty = Alloc(6 * sizeof(struct Pokemon));
u8 nickBuffer[20];
Competitive-formatted parties (#3545) $ python3 migration_scripts/convert_parties.py src/data/trainers.h src/data/trainer_parties.h src/data/npc_trainers.party Is available to convert Trainer Control-formatted trainers/parties into Competitive-formatted ones. Multiple '#include's can be placed in the trainer section of src/data.c to support spreading the trainers across multiple .party files. trainerproc does not interpret the values, leaving that job to the C compiler, so we use '#line' to associate those errors with the lines in the .party file(s). Because the columns don't make sense we use -fno-show-column and -fno-diagostics-show-caret. We might want to move gTrainers into its own file so that the rest of src/data.c isn't affected by those flags. Extensions (misfeatures, imo): - .party files are passed through cpp, so '#define's are supported, and so are '// ...' and '/* ... */' comments. - .party files also support writing, e.g. 'SPECIES_PIKACHU' instead of 'Pikachu'. This allows people to write constants explicitly if they like. Pragmas: - '#pragma trainerproc ivs explicit' requires an explicit 'IVs:' line rather than defaulting to 31s. - '#pragma trainerproc ivs <IVs>' changes the default IVs. - '#pragma trainerproc level explicit' requires an explicit 'Level:' line rather than defaulting to 100. - '#pragma trainerproc level <level>' changes the default level. Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
2024-04-06 19:05:15 +01:00
CreateNPCTrainerPartyFromTrainer(testParty, &sTestTrainers[0], TRUE, BATTLE_TYPE_TRAINER);
EXPECT(IsMonShiny(&testParty[0]));
EXPECT(!IsMonShiny(&testParty[1]));
EXPECT(GetMonData(&testParty[0], MON_DATA_POKEBALL, 0) == ITEM_MASTER_BALL);
EXPECT(GetMonData(&testParty[1], MON_DATA_POKEBALL, 0) == ITEM_POKE_BALL);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPECIES, 0) == SPECIES_WOBBUFFET);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPECIES, 0) == SPECIES_WOBBUFFET);
EXPECT(GetMonAbility(&testParty[0]) == ABILITY_TELEPATHY);
EXPECT(GetMonAbility(&testParty[1]) == ABILITY_SHADOW_TAG);
EXPECT(GetMonAbility(&testParty[2]) == ABILITY_SHADOW_TAG);
EXPECT(GetMonData(&testParty[0], MON_DATA_FRIENDSHIP, 0) == 42);
EXPECT(GetMonData(&testParty[1], MON_DATA_FRIENDSHIP, 0) == 0);
EXPECT(GetMonData(&testParty[0], MON_DATA_HELD_ITEM, 0) == ITEM_ASSAULT_VEST);
EXPECT(GetMonData(&testParty[1], MON_DATA_HELD_ITEM, 0) == ITEM_NONE);
EXPECT(GetMonData(&testParty[0], MON_DATA_HP_IV, 0) == 25);
EXPECT(GetMonData(&testParty[0], MON_DATA_ATK_IV, 0) == 26);
EXPECT(GetMonData(&testParty[0], MON_DATA_DEF_IV, 0) == 27);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPEED_IV, 0) == 28);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPATK_IV, 0) == 29);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPDEF_IV, 0) == 30);
EXPECT(GetMonData(&testParty[1], MON_DATA_HP_IV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_ATK_IV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_DEF_IV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPEED_IV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPATK_IV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPDEF_IV, 0) == 0);
EXPECT(GetMonData(&testParty[0], MON_DATA_HP_EV, 0) == 252);
EXPECT(GetMonData(&testParty[0], MON_DATA_ATK_EV, 0) == 0);
EXPECT(GetMonData(&testParty[0], MON_DATA_DEF_EV, 0) == 0);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPEED_EV, 0) == 252);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPATK_EV, 0) == 4);
EXPECT(GetMonData(&testParty[0], MON_DATA_SPDEF_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_HP_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_ATK_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_DEF_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPEED_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPATK_EV, 0) == 0);
EXPECT(GetMonData(&testParty[1], MON_DATA_SPDEF_EV, 0) == 0);
EXPECT(GetMonData(&testParty[0], MON_DATA_LEVEL, 0) == 67);
EXPECT(GetMonData(&testParty[1], MON_DATA_LEVEL, 0) == 5);
EXPECT(GetMonData(&testParty[0], MON_DATA_MOVE1, 0) == MOVE_AIR_SLASH);
EXPECT(GetMonData(&testParty[0], MON_DATA_MOVE2, 0) == MOVE_BARRIER);
EXPECT(GetMonData(&testParty[0], MON_DATA_MOVE3, 0) == MOVE_SOLAR_BEAM);
EXPECT(GetMonData(&testParty[0], MON_DATA_MOVE4, 0) == MOVE_EXPLOSION);
GetMonData(&testParty[0], MON_DATA_NICKNAME, nickBuffer);
EXPECT(StringCompare(nickBuffer, COMPOUND_STRING("Bubbles")) == 0);
GetMonData(&testParty[1], MON_DATA_NICKNAME, nickBuffer);
EXPECT(StringCompare(nickBuffer, COMPOUND_STRING("Wobbuffet")) == 0);
EXPECT(GetMonGender(&testParty[0]) == MON_FEMALE);
EXPECT(GetNature(&testParty[0]) == NATURE_HASTY);
EXPECT(GetNature(&testParty[1]) == NATURE_HARDY);
EXPECT_EQ(GetMonData(&testParty[0], MON_DATA_DYNAMAX_LEVEL), 5);
Competitive-formatted parties (#3545) $ python3 migration_scripts/convert_parties.py src/data/trainers.h src/data/trainer_parties.h src/data/npc_trainers.party Is available to convert Trainer Control-formatted trainers/parties into Competitive-formatted ones. Multiple '#include's can be placed in the trainer section of src/data.c to support spreading the trainers across multiple .party files. trainerproc does not interpret the values, leaving that job to the C compiler, so we use '#line' to associate those errors with the lines in the .party file(s). Because the columns don't make sense we use -fno-show-column and -fno-diagostics-show-caret. We might want to move gTrainers into its own file so that the rest of src/data.c isn't affected by those flags. Extensions (misfeatures, imo): - .party files are passed through cpp, so '#define's are supported, and so are '// ...' and '/* ... */' comments. - .party files also support writing, e.g. 'SPECIES_PIKACHU' instead of 'Pikachu'. This allows people to write constants explicitly if they like. Pragmas: - '#pragma trainerproc ivs explicit' requires an explicit 'IVs:' line rather than defaulting to 31s. - '#pragma trainerproc ivs <IVs>' changes the default IVs. - '#pragma trainerproc level explicit' requires an explicit 'Level:' line rather than defaulting to 100. - '#pragma trainerproc level <level>' changes the default level. Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
2024-04-06 19:05:15 +01:00
EXPECT_EQ(GetMonData(&testParty[1], MON_DATA_DYNAMAX_LEVEL), 10);
Free(testParty);
}
TEST("CreateNPCTrainerPartyForTrainer generates different personalities for different mons")
{
struct Pokemon *testParty = Alloc(6 * sizeof(struct Pokemon));
Competitive-formatted parties (#3545) $ python3 migration_scripts/convert_parties.py src/data/trainers.h src/data/trainer_parties.h src/data/npc_trainers.party Is available to convert Trainer Control-formatted trainers/parties into Competitive-formatted ones. Multiple '#include's can be placed in the trainer section of src/data.c to support spreading the trainers across multiple .party files. trainerproc does not interpret the values, leaving that job to the C compiler, so we use '#line' to associate those errors with the lines in the .party file(s). Because the columns don't make sense we use -fno-show-column and -fno-diagostics-show-caret. We might want to move gTrainers into its own file so that the rest of src/data.c isn't affected by those flags. Extensions (misfeatures, imo): - .party files are passed through cpp, so '#define's are supported, and so are '// ...' and '/* ... */' comments. - .party files also support writing, e.g. 'SPECIES_PIKACHU' instead of 'Pikachu'. This allows people to write constants explicitly if they like. Pragmas: - '#pragma trainerproc ivs explicit' requires an explicit 'IVs:' line rather than defaulting to 31s. - '#pragma trainerproc ivs <IVs>' changes the default IVs. - '#pragma trainerproc level explicit' requires an explicit 'Level:' line rather than defaulting to 100. - '#pragma trainerproc level <level>' changes the default level. Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
2024-04-06 19:05:15 +01:00
CreateNPCTrainerPartyFromTrainer(testParty, &sTestTrainers[0], TRUE, BATTLE_TYPE_TRAINER);
EXPECT(testParty[0].box.personality != testParty[1].box.personality);
Free(testParty);
}
2023-10-23 13:37:40 +01:00
TEST("ModifyPersonalityForNature can set any nature")
{
u32 personality = 0, nature = 0, j = 0, k = 0;
2023-10-23 13:37:40 +01:00
for (j = 0; j < 64; j++)
{
for (k = 0; k < NUM_NATURES; k++)
{
PARAMETRIZE { personality = Random32(); nature = k; }
}
}
ModifyPersonalityForNature(&personality, nature);
EXPECT_EQ(GetNatureFromPersonality(personality), nature);
}