Skip to content

Commit

Permalink
Split NARC-related trainer structs from main Trainer struct
Browse files Browse the repository at this point in the history
  • Loading branch information
lhearachel committed Jan 31, 2025
1 parent ef66650 commit 38436e0
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 129 deletions.
2 changes: 1 addition & 1 deletion include/battle/ov16_0223DF00.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "struct_decls/struct_0200C704_decl.h"
#include "struct_decls/struct_020797DC_decl.h"
#include "struct_defs/chatot_cry.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/battle_context.h"
#include "battle/battle_message.h"
Expand Down
2 changes: 1 addition & 1 deletion include/field_battle_data_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "struct_decls/struct_0206D140_decl.h"
#include "struct_decls/struct_020797DC_decl.h"
#include "struct_defs/chatot_cry.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "field/field_system_decl.h"

Expand Down
2 changes: 1 addition & 1 deletion include/string_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "struct_decls/struct_020797DC_decl.h"
#include "struct_defs/pokemon.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "enums.h"
#include "savedata.h"
Expand Down
2 changes: 1 addition & 1 deletion include/struct_defs/battle_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "struct_decls/struct_020797DC_decl.h"
#include "struct_defs/chatot_cry.h"
#include "struct_defs/struct_0207C690.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/battle_context.h"
#include "battle/struct_ov16_0223E0C8.h"
Expand Down
2 changes: 1 addition & 1 deletion include/struct_defs/struct_0202FAA8.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef POKEPLATINUM_STRUCT_0202FAA8_H
#define POKEPLATINUM_STRUCT_0202FAA8_H

#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

typedef struct {
u32 unk_00;
Expand Down
19 changes: 19 additions & 0 deletions include/struct_defs/trainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef POKEPLATINUM_STRUCT_TRAINER_H
#define POKEPLATINUM_STRUCT_TRAINER_H

#include "constants/string.h"

#include "struct_defs/sentence.h"
#include "struct_defs/trainer_data.h"

#include "charcode.h"

typedef struct Trainer {
TrainerHeader header;

charcode_t name[TRAINER_NAME_LEN + 1];
Sentence winMsg;
Sentence loseMsg;
} Trainer;

#endif // POKEPLATINUM_STRUCT_TRAINER_H
94 changes: 37 additions & 57 deletions include/struct_defs/trainer_data.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#ifndef POKEPLATINUM_STRUCT_TRAINER_DATA_H
#define POKEPLATINUM_STRUCT_TRAINER_DATA_H

#include "constants/string.h"
/*
* Note: *most* source files should not include this header directly, and should
* instead including `struct_defs/trainer.h`. This header is held separately for
* use by data-packing routines.
*/

#include "struct_defs/sentence.h"
#include "constants/moves.h"

#include "strbuf.h"
#define MAX_TRAINER_ITEMS 4
#define MAX_DV 255

enum TrainerDataType {
TRDATATYPE_BASE = 0,
Expand All @@ -14,71 +19,46 @@ enum TrainerDataType {
TRDATATYPE_WITH_MOVES_AND_ITEM,
};

/**
* @brief Trainer data encapsulation. Contains all trainer-level data needed to instantiate a trainer battle.
*/
typedef struct Trainer {
u8 type; //< The data type of the trainer; controls which TrainerMon struct is used for the party.
u8 class; //< The trainer's class, e.g. "Youngster" or "Gym Leader."
u8 sprite; //< Which sprite ID the trainer uses.
u8 partySize; //< How many Pokemon the trainer has in their party.

u16 items[4]; //< Items that the trainer has in their bag.

u32 aiMask; //< Mask of AI flags to use for this trainer in battle.

u32 battleType; //< The type of battle to be instantiated.

charcode_t name[TRAINER_NAME_LEN + 1]; //< The trainer's name.
typedef struct TrainerHeader {
u8 monDataType;
u8 trainerType;
u8 sprite;
u8 partySize;
u16 items[MAX_TRAINER_ITEMS];
u32 aiMask;
u32 battleType;
} TrainerHeader;

Sentence winMsg; //< The message to display if the trainer wins.
Sentence loseMsg; //< The message to display if the trainer loses.
} Trainer;

#define MAX_DV 255

/**
* @brief The most basic Trainer Pokemon structure. No item is held, and moves are populated from the learnset.
*/
typedef struct TrainerMonBase {
u16 dv; //< Difficulty value; determines how many IVs the Pokemon will have in each stat.
u16 level; //< The Pokemon's level.
u16 species; //< Composite mask of the Pokemon's level (least-significant 10 bits) and form (most-significant 6 bits).
u16 cbSeal; //< Ball seal applied to the Pokemon.
u16 dv;
u16 level;
u16 species;
u16 cbSeal;
} TrainerMonBase;

/**
* @brief Trainer Pokemon that knows a certain set of moves.
*/
typedef struct TrainerMonWithMoves {
u16 dv; //< Difficulty value; determines how many IVs the Pokemon will have in each stat.
u16 level; //< The Pokemon's level.
u16 species; //< Composite mask of the Pokemon's level (least-significant 10 bits) and form (most-significant 6 bits).
u16 moves[4]; //< The Pokemon's known moves.
u16 cbSeal; //< Ball seal applied to the Pokemon.
u16 dv;
u16 level;
u16 species;
u16 moves[LEARNED_MOVES_MAX];
u16 cbSeal;
} TrainerMonWithMoves;

/**
* @brief Trainer Pokemon that has a specific held item.
*/
typedef struct TrainerMonWithItem {
u16 dv; //< Difficulty value; determines how many IVs the Pokemon will have in each stat.
u16 level; //< The Pokemon's level.
u16 species; //< Composite mask of the Pokemon's level (least-significant 10 bits) and form (most-significant 6 bits).
u16 item; //< The Pokemon's held item.
u16 cbSeal; //< Ball seal applied to the Pokemon.
u16 dv;
u16 level;
u16 species;
u16 item;
u16 cbSeal;
} TrainerMonWithItem;

/**
* @brief Trainer Pokemon that has a specific held item and knows a certain set of moves.
*/
typedef struct TrainerMonWithMovesAndItem {
u16 dv; //< Difficulty value; determines how many IVs the Pokemon will have in each stat.
u16 level; //< The Pokemon's level.
u16 species; //< Composite mask of the Pokemon's level (least-significant 10 bits) and form (most-significant 6 bits).
u16 item; //< The Pokemon's held item.
u16 moves[4]; //< The Pokemon's known moves.
u16 cbSeal; //< Ball seal applied to the Pokemon.
u16 dv;
u16 level;
u16 species;
u16 item;
u16 moves[LEARNED_MOVES_MAX];
u16 cbSeal;
} TrainerMonWithMovesAndItem;

#endif // POKEPLATINUM_STRUCT_TRAINER_DATA_H
4 changes: 2 additions & 2 deletions include/trainer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "constants/trainer.h"

#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "field_battle_data_transfer.h"
#include "savedata.h"
Expand Down Expand Up @@ -78,7 +78,7 @@ void Trainer_Load(int trainerID, Trainer *trdata);
*
* The struct pointer passed to this function will determine exactly how much
* data is loaded; see the definitions of the various TrainerMon... structs in
* struct_defs/trainer_data.h for exact specifications.
* struct_defs/trainer.h for exact specifications.
*
* @param trainerID ID of the trainer whose party is to be loaded.
* @param[out] trparty Struct which will contain the loaded trainer party data.
Expand Down
4 changes: 2 additions & 2 deletions src/battle/battle_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "generated/sdat.h"

#include "struct_decls/battle_system.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/ai_context.h"
#include "battle/battle_context.h"
Expand Down Expand Up @@ -4268,7 +4268,7 @@ static BOOL BattleController_CheckBattleOver(BattleSystem *battleSys, BattleCont
|| (battleResult == BATTLE_RESULT_WIN && (battleType & BATTLE_TYPE_FRONTIER) && (battleType & BATTLE_TYPE_LINK) == FALSE)) {
Trainer *trainer = BattleSystem_GetTrainer(battleSys, BATTLER_ENEMY_1);

switch (trainer->class) {
switch (trainer->header.trainerType) {
case TRAINER_CLASS_LEADER_ROARK:
case TRAINER_CLASS_LEADER_GARDENIA:
case TRAINER_CLASS_LEADER_WAKE:
Expand Down
4 changes: 2 additions & 2 deletions src/battle/battle_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "struct_defs/battle_io.h"
#include "struct_defs/sprite_animation_frame.h"
#include "struct_defs/struct_0200D0F4.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/battle_context.h"
#include "battle/battle_io.h"
Expand Down Expand Up @@ -554,7 +554,7 @@ void ov16_0225D360(BattleSystem *param0, BattlerData *param1, UnkStruct_ov16_022
{
Trainer *trainer = BattleSystem_GetTrainer(param0, param1->battler);
v0->unk_0B = 0;
v0->unk_0C = sub_020788D0(ov16_02264768(param0, param1->battler, trainer->class));
v0->unk_0C = sub_020788D0(ov16_02264768(param0, param1->battler, trainer->header.trainerType));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/battle/battle_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void BattleIO_SetTrainerEncounter(BattleSystem *param0, int param1)
UnkStruct_ov16_02265124 v0;

v0.unk_00 = 8;
v0.unk_02 = param0->trainers[param1].class;
v0.unk_02 = param0->trainers[param1].header.trainerType;
v0.unk_01 = param0->unk_A8[param1];

SendMessage(param0, 1, param1, &v0, sizeof(UnkStruct_ov16_02265124));
Expand Down Expand Up @@ -448,7 +448,7 @@ void BattleIO_SlideTrainerIn(BattleSystem *param0, int param1, int param2)
UnkStruct_ov16_022651A8 v0;

v0.unk_00 = 11;
v0.unk_02 = param0->trainers[param1].class;
v0.unk_02 = param0->trainers[param1].header.trainerType;
v0.unk_01 = param0->unk_A8[param1];
v0.unk_04 = param2;

Expand Down
18 changes: 9 additions & 9 deletions src/battle/battle_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "struct_defs/struct_0200D0F4.h"
#include "struct_defs/struct_020127E8.h"
#include "struct_defs/struct_0208737C.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/battle_context.h"
#include "battle/battle_controller.h"
Expand Down Expand Up @@ -3879,40 +3879,40 @@ static u32 BattleScript_CalcPrizeMoney(BattleSystem *battleSys, BattleContext *b
Trainer_Load(battleSys->trainerIDs[battler], &trainer);
Trainer_LoadParty(battleSys->trainerIDs[battler], rawParty);

switch (trainer.type) {
switch (trainer.header.monDataType) {
default:
case TRDATATYPE_BASE: {
TrainerMonBase *party = (TrainerMonBase *)rawParty;
lastLevel = party[trainer.partySize - 1].level;
lastLevel = party[trainer.header.partySize - 1].level;
break;
}

case TRDATATYPE_WITH_MOVES: {
TrainerMonWithMoves *party = (TrainerMonWithMoves *)rawParty;
lastLevel = party[trainer.partySize - 1].level;
lastLevel = party[trainer.header.partySize - 1].level;
break;
}

case TRDATATYPE_WITH_ITEM: {
TrainerMonWithItem *party = (TrainerMonWithItem *)rawParty;
lastLevel = party[trainer.partySize - 1].level;
lastLevel = party[trainer.header.partySize - 1].level;
break;
}

case TRDATATYPE_WITH_MOVES_AND_ITEM: {
TrainerMonWithMovesAndItem *party = (TrainerMonWithMovesAndItem *)rawParty;
lastLevel = party[trainer.partySize - 1].level;
lastLevel = party[trainer.header.partySize - 1].level;
break;
}
}

u32 prize;
if ((battleSys->battleType & BATTLE_TYPE_TAG) || battleSys->battleType == BATTLE_TYPE_TRAINER_WITH_AI_PARTNER) {
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * sTrainerClassPrizeMul[trainer.class];
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * sTrainerClassPrizeMul[trainer.header.trainerType];
} else if (battleSys->battleType & 0x2) {
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * 2 * sTrainerClassPrizeMul[trainer.class];
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * 2 * sTrainerClassPrizeMul[trainer.header.trainerType];
} else {
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * sTrainerClassPrizeMul[trainer.class];
prize = lastLevel * 4 * battleCtx->prizeMoneyMul * sTrainerClassPrizeMul[trainer.header.trainerType];
}

Heap_FreeToHeap(rawParty);
Expand Down
2 changes: 1 addition & 1 deletion src/battle/ov16_0223B140.c
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ static void ov16_0223C2C0(BattleSystem *param0, FieldBattleDTO *param1)
}

if (param0->battleType & 0x1) {
if ((ov16_0223CD3C(param0->trainers[1].class) == 1) || (ov16_0223CD3C(param0->trainers[3].class) == 1)) {
if ((ov16_0223CD3C(param0->trainers[1].header.trainerType) == 1) || (ov16_0223CD3C(param0->trainers[3].header.trainerType) == 1)) {
for (v0 = 0; v0 < Party_GetCurrentCount(param0->parties[0]); v0++) {
v3 = Party_GetPokemonBySlotIndex(param0->parties[0], v0);
Pokemon_UpdateFriendship(v3, 3, param0->unk_2404);
Expand Down
4 changes: 2 additions & 2 deletions src/battle/ov16_0223DF00.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "struct_defs/battle_system.h"
#include "struct_defs/chatot_cry.h"
#include "struct_defs/struct_0200D0F4.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "battle/battle_context.h"
#include "battle/battle_display.h"
Expand Down Expand Up @@ -1550,7 +1550,7 @@ int ov16_0223F6F0(BattleSystem *battleSystem, u16 param1)

u16 BattleSystem_TrainerItems(BattleSystem *battleSystem, int param1, int param2)
{
return battleSystem->trainers[param1].items[param2];
return battleSystem->trainers[param1].header.items[param2];
}

u32 BattleSystem_RecordingStopped(BattleSystem *battleSystem)
Expand Down
2 changes: 1 addition & 1 deletion src/battle/trainer_ai/trainer_ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void TrainerAI_Init(BattleSystem *battleSys, BattleContext *battleCtx, u8 battle
if (battleSys->battleType & BATTLE_TYPE_ROAMER) {
AI_CONTEXT.thinkingMask = AI_FLAG_ROAMING_POKEMON;
} else {
AI_CONTEXT.thinkingMask = battleSys->trainers[battler].aiMask;
AI_CONTEXT.thinkingMask = battleSys->trainers[battler].header.aiMask;
}

// force double-battle strategies, if applicable
Expand Down
2 changes: 1 addition & 1 deletion src/enc_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static u32 EncEffects_GetEffectPair(const FieldBattleDTO *dto)
u32 battleType = dto->battleType;

if (battleType & BATTLE_TYPE_TRAINER) {
u32 trainerEffect = EncEffects_TrainerClassEffect(dto->trainer[1].class);
u32 trainerEffect = EncEffects_TrainerClassEffect(dto->trainer[1].header.trainerType);

if (battleType & BATTLE_TYPE_FRONTIER) {
if (trainerEffect == ENCEFF_FRONTIER_BRAIN) {
Expand Down
6 changes: 3 additions & 3 deletions src/field_battle_data_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "struct_defs/chatot_cry.h"
#include "struct_defs/struct_0202610C.h"
#include "struct_defs/struct_0205EC34.h"
#include "struct_defs/trainer_data.h"
#include "struct_defs/trainer.h"

#include "applications/pokemon_summary_screen/main.h"
#include "field/field_system.h"
Expand Down Expand Up @@ -404,7 +404,7 @@ void FieldBattleDTO_InitWithPartyOrder(FieldBattleDTO *dto, const FieldSystem *f
int unionAppearance = TrainerInfo_Appearance(trainerInfo);
int unionGender = TrainerInfo_Gender(trainerInfo);

dto->trainer[BATTLER_PLAYER_1].class = sub_0205CA14(unionGender, unionAppearance, 1);
dto->trainer[BATTLER_PLAYER_1].header.trainerType = sub_0205CA14(unionGender, unionAppearance, 1);
CharCode_Copy(dto->trainer[BATTLER_PLAYER_1].name, TrainerInfo_Name(dto->trainerInfo[BATTLER_PLAYER_1]));
dto->trainer[BATTLER_PLAYER_2] = dto->trainer[BATTLER_PLAYER_1];
} else {
Expand Down Expand Up @@ -548,7 +548,7 @@ BOOL CheckPlayerDidNotCaptureWildMon(u32 battleResult)

void FieldBattleDTO_CopyPlayerInfoToTrainerData(FieldBattleDTO *dto)
{
dto->trainer[BATTLER_PLAYER_1].class = TrainerInfo_Gender(dto->trainerInfo[BATTLER_PLAYER_1]);
dto->trainer[BATTLER_PLAYER_1].header.trainerType = TrainerInfo_Gender(dto->trainerInfo[BATTLER_PLAYER_1]);
CharCode_Copy(dto->trainer[BATTLER_PLAYER_1].name, TrainerInfo_Name(dto->trainerInfo[BATTLER_PLAYER_1]));
dto->trainer[BATTLER_PLAYER_2] = dto->trainer[BATTLER_PLAYER_1];
}
Loading

0 comments on commit 38436e0

Please sign in to comment.