From 2e09fce6a2d072dc4546e2988cfbb323dfece167 Mon Sep 17 00:00:00 2001 From: Rachel Date: Wed, 15 Jan 2025 14:28:59 -0800 Subject: [PATCH] Extract species-related structs to species.h --- include/constants/pokemon.h | 11 ----- include/pch/global_pch.h | 2 + include/pokemon.h | 48 +--------------------- include/struct_defs/species.h | 75 +++++++++++++++++++++++++++++++++++ src/pokemon.c | 12 ------ 5 files changed, 78 insertions(+), 70 deletions(-) create mode 100644 include/struct_defs/species.h diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index fc1a4d7470..8fe2d191ff 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -17,11 +17,6 @@ enum { STAT_MAX }; -#define MAX_ABILITIES 2 -#define MAX_EGG_GROUPS 2 -#define MAX_TYPES 2 -#define MAX_EVOLUTIONS 7 - #define MAX_PARTY_SIZE 6 #define NUM_BOOSTABLE_STATS 8 @@ -35,12 +30,6 @@ enum { #define MAX_POKEMON_MARKINGS 6 #define MAX_POKEMON_LEVEL 100 -#define LEARNSET_NO_MOVE_TO_LEARN 0 -#define MAX_LEARNSET_ENTRIES 20 -#define LEARNSET_MOVE_ALREADY_KNOWN 0xFFFE -#define LEARNSET_ALL_SLOTS_FILLED 0xFFFF -#define LEARNSET_SENTINEL_ENTRY 0xFFFF - #define EVOLVE_FRIENDSHIP_THRESHOLD 220 /** diff --git a/include/pch/global_pch.h b/include/pch/global_pch.h index fa77a9a3e4..8218d34b0d 100644 --- a/include/pch/global_pch.h +++ b/include/pch/global_pch.h @@ -16,6 +16,8 @@ #define NELEMS(a) (sizeof(a) / sizeof(*(a))) #define XtOffset(pointer_type, field) ((unsigned int)&(((pointer_type)NULL)->field)) +#define ALIGN_4 __attribute__((aligned(4))) + typedef struct { int x; int y; diff --git a/include/pokemon.h b/include/pokemon.h index 0c65cd449a..145c9970b7 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -14,6 +14,7 @@ #include "struct_defs/archived_sprite.h" #include "struct_defs/chatot_cry.h" #include "struct_defs/pokemon.h" +#include "struct_defs/species.h" #include "struct_defs/sprite_animation_frame.h" #include "overlay005/struct_ov5_021DE5D0.h" @@ -31,53 +32,6 @@ #define FACE_BACK 0 #define FACE_FRONT 2 -typedef struct SpeciesBaseStats { - u8 hp; - u8 attack; - u8 defense; - u8 speed; - u8 spAttack; - u8 spDefense; -} SpeciesBaseStats; - -typedef struct SpeciesEVYields { - u16 hp : 2; - u16 attack : 2; - u16 defense : 2; - u16 speed : 2; - u16 spAttack : 2; - u16 spDefense : 2; -} SpeciesEVYields; - -typedef struct SpeciesWildHeldItems { - u16 common; - u16 rare; -} SpeciesWildHeldItems; - -typedef struct SpeciesData { - SpeciesBaseStats baseStats; - u8 types[MAX_TYPES]; - u8 catchRate; - u8 baseExpReward; - SpeciesEVYields evYields; - SpeciesWildHeldItems wildHeldItems; - u8 genderRatio; - u8 hatchCycles; - u8 baseFriendship; - u8 expRate; - u8 eggGroups[MAX_EGG_GROUPS]; - u8 abilities[MAX_ABILITIES]; - u8 safariFleeRate; - u8 bodyColor : 7; - u8 flipSprite : 1; - // u16 padding; - - u32 tmLearnsetMask1; // Bitflags for whether this pokemon can learn a TM (TM1 -> TM32) - u32 tmLearnsetMask2; // Bitflags for whether this pokemon can learn a TM (TM33 -> TM64) - u32 tmLearnsetMask3; // Bitflags for whether this pokemon can learn a TM (TM65 -> TM92, HM1 -> HM4) - u32 tmLearnsetMask4; // Bitflags for whether this pokemon can learn a TM (HM5 -> HM8, rest unused) -} SpeciesData; - enum EvolutionClass { EVO_CLASS_BY_LEVEL = 0, EVO_CLASS_BY_TRADE, diff --git a/include/struct_defs/species.h b/include/struct_defs/species.h new file mode 100644 index 0000000000..69cc3a2793 --- /dev/null +++ b/include/struct_defs/species.h @@ -0,0 +1,75 @@ +#ifndef POKEPLATINUM_SPECIES_H +#define POKEPLATINUM_SPECIES_H + +#define MAX_ABILITIES 2 +#define MAX_EGG_GROUPS 2 +#define MAX_TYPES 2 + +#define MAX_EVOLUTIONS 7 + +#define MAX_LEARNSET_ENTRIES 20 +#define LEARNSET_NO_MOVE_TO_LEARN 0 +#define LEARNSET_MOVE_ALREADY_KNOWN 0xFFFE +#define LEARNSET_ALL_SLOTS_FILLED 0xFFFF +#define LEARNSET_SENTINEL_ENTRY 0xFFFF + +typedef struct SpeciesBaseStats { + u8 hp; + u8 attack; + u8 defense; + u8 speed; + u8 spAttack; + u8 spDefense; +} SpeciesBaseStats; + +typedef struct SpeciesEVYields { + u16 hp : 2; + u16 attack : 2; + u16 defense : 2; + u16 speed : 2; + u16 spAttack : 2; + u16 spDefense : 2; +} SpeciesEVYields; + +typedef struct SpeciesWildHeldItems { + u16 common; + u16 rare; +} SpeciesWildHeldItems; + +typedef struct SpeciesData { + SpeciesBaseStats baseStats; + u8 types[MAX_TYPES]; + u8 catchRate; + u8 baseExpReward; + SpeciesEVYields evYields; + SpeciesWildHeldItems wildHeldItems; + u8 genderRatio; + u8 hatchCycles; + u8 baseFriendship; + u8 expRate; + u8 eggGroups[MAX_EGG_GROUPS]; + u8 abilities[MAX_ABILITIES]; + u8 safariFleeRate; + u8 bodyColor : 7; + u8 flipSprite : 1; + // u16 padding; + + u32 tmLearnsetMask1; // Bitflags for whether this pokemon can learn a TM (TM1 -> TM32) + u32 tmLearnsetMask2; // Bitflags for whether this pokemon can learn a TM (TM33 -> TM64) + u32 tmLearnsetMask3; // Bitflags for whether this pokemon can learn a TM (TM65 -> TM92, HM1 -> HM4) + u32 tmLearnsetMask4; // Bitflags for whether this pokemon can learn a TM (HM5 -> HM8, rest unused) +} SpeciesData; + +typedef struct SpeciesEvolution { + u16 method; + u16 param; + u16 targetSpecies; +} SpeciesEvolution; + +// This struct is not explicitly used; it is provided to document and enforce the size of +// the learnset entries. +typedef struct SpeciesLearnset { + ALIGN_4 u16 entries[MAX_LEARNSET_ENTRIES + 1]; +} SpeciesLearnset; + +#endif // POKEPLATINUM_SPECIES_H diff --git a/src/pokemon.c b/src/pokemon.c index e494d9f52b..568e7504b1 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -92,18 +92,6 @@ static const s8 sNatureFlavorAffinities[][5] = { { 0x0, 0x0, 0x0, 0x0, 0x0 }, }; -typedef struct SpeciesEvolution { - u16 method; - u16 param; - u16 targetSpecies; -} SpeciesEvolution; - -// This struct is not explicitly used; it is provided to document and enforce the size of -// the learnset entries. -typedef struct SpeciesLearnset { - __attribute__((aligned(4))) u16 entries[MAX_LEARNSET_ENTRIES + 1]; -} SpeciesLearnset; - enum PokemonDataBlockID { DATA_BLOCK_A = 0, DATA_BLOCK_B,