2017-09-02 21:43:53 +02:00
# ifndef GUARD_GLOBAL_FIELDMAP_H
# define GUARD_GLOBAL_FIELDMAP_H
2022-01-19 16:15:32 +01:00
// Masks/shifts for blocks in the map grid
// Map grid blocks consist of a 10 bit metatile id, a 2 bit collision value, and a 4 bit elevation value
2022-01-21 05:26:39 +01:00
// This is the data stored in each data/layouts/*/map.bin file
2022-09-03 01:29:35 +02:00
# define MAPGRID_METATILE_ID_MASK 0x03FF // Bits 0-9
# define MAPGRID_COLLISION_MASK 0x0C00 // Bits 10-11
# define MAPGRID_ELEVATION_MASK 0xF000 // Bits 12-15
2022-01-19 16:15:32 +01:00
# define MAPGRID_COLLISION_SHIFT 10
# define MAPGRID_ELEVATION_SHIFT 12
// An undefined map grid block has all metatile id bits set and nothing else
# define MAPGRID_UNDEFINED MAPGRID_METATILE_ID_MASK
// Masks/shifts for metatile attributes
// Metatile attributes consist of an 8 bit behavior value, 4 unused bits, and a 4 bit layer type value
// This is the data stored in each data/tilesets/*/*/metatile_attributes.bin file
2022-09-03 01:29:35 +02:00
# define METATILE_ATTR_BEHAVIOR_MASK 0x00FF // Bits 0-7
# define METATILE_ATTR_LAYER_MASK 0xF000 // Bits 12-15
2022-01-19 16:15:32 +01:00
# define METATILE_ATTR_LAYER_SHIFT 12
2019-02-22 09:08:48 +01:00
2022-01-19 15:37:12 +01:00
enum {
METATILE_LAYER_TYPE_NORMAL , // Metatile uses middle and top bg layers
METATILE_LAYER_TYPE_COVERED , // Metatile uses bottom and middle bg layers
METATILE_LAYER_TYPE_SPLIT , // Metatile uses bottom and top bg layers
} ;
2019-06-11 18:07:31 +02:00
# define METATILE_ID(tileset, name) (METATILE_##tileset##_##name)
2021-10-25 21:51:04 +02:00
// Rows of metatiles do not actually have a strict width.
// This constant is used for calculations for finding the next row of metatiles
// for constructing large tiles, such as the Battle Pike's curtain tile.
# define METATILE_ROW_WIDTH 8
2017-09-02 21:43:53 +02:00
typedef void ( * TilesetCB ) ( void ) ;
struct Tileset
{
/*0x00*/ bool8 isCompressed ;
/*0x01*/ bool8 isSecondary ;
2022-09-27 21:15:32 +02:00
/*0x04*/ const u32 * tiles ;
2022-10-08 07:28:19 +02:00
/*0x08*/ const u16 ( * palettes ) [ 16 ] ;
2022-12-18 02:55:43 +01:00
/*0x0C*/ const u16 * metatiles ;
2022-09-27 21:15:32 +02:00
/*0x10*/ const u16 * metatileAttributes ;
2017-09-02 21:43:53 +02:00
/*0x14*/ TilesetCB callback ;
} ;
2018-06-21 00:41:51 +02:00
struct MapLayout
2017-09-02 21:43:53 +02:00
{
/*0x00*/ s32 width ;
/*0x04*/ s32 height ;
/*0x08*/ u16 * border ;
2022-12-18 02:55:43 +01:00
/*0x0C*/ u16 * map ;
2017-09-02 21:43:53 +02:00
/*0x10*/ struct Tileset * primaryTileset ;
/*0x14*/ struct Tileset * secondaryTileset ;
} ;
2018-06-21 00:41:51 +02:00
struct BackupMapLayout
2017-09-02 21:43:53 +02:00
{
s32 width ;
s32 height ;
u16 * map ;
} ;
2019-11-21 04:55:44 +01:00
struct ObjectEventTemplate
2017-09-02 21:43:53 +02:00
{
/*0x00*/ u8 localId ;
/*0x01*/ u8 graphicsId ;
2020-05-14 23:11:18 +02:00
/*0x02*/ u8 inConnection ; // Leftover from FRLG
2022-12-18 02:55:43 +01:00
/*0x03*/ //u8 padding1;
2017-09-02 21:43:53 +02:00
/*0x04*/ s16 x ;
/*0x06*/ s16 y ;
/*0x08*/ u8 elevation ;
/*0x09*/ u8 movementType ;
2019-12-10 22:34:56 +01:00
/*0x0A*/ u16 movementRangeX : 4 ;
u16 movementRangeY : 4 ;
2022-12-18 02:55:43 +01:00
//u16 padding2:8;
2018-06-11 17:34:51 +02:00
/*0x0C*/ u16 trainerType ;
/*0x0E*/ u16 trainerRange_berryTreeId ;
2017-09-11 16:46:26 +02:00
/*0x10*/ const u8 * script ;
2017-09-02 21:43:53 +02:00
/*0x14*/ u16 flagId ;
2022-12-18 02:55:43 +01:00
/*0x16*/ //u8 padding3[2];
2019-10-06 21:17:34 +02:00
} ;
2017-09-02 21:43:53 +02:00
struct WarpEvent
{
s16 x , y ;
2018-10-17 04:47:08 +02:00
u8 elevation ;
u8 warpId ;
2017-09-02 21:43:53 +02:00
u8 mapNum ;
2018-10-17 04:47:08 +02:00
u8 mapGroup ;
2017-09-02 21:43:53 +02:00
} ;
struct CoordEvent
{
s16 x , y ;
2018-10-17 04:47:08 +02:00
u8 elevation ;
2017-09-02 21:43:53 +02:00
u16 trigger ;
u16 index ;
u8 * script ;
} ;
struct BgEvent
{
u16 x , y ;
2018-10-17 04:47:08 +02:00
u8 elevation ;
2019-10-06 21:17:34 +02:00
u8 kind ; // The "kind" field determines how to access bgUnion union below.
union {
2017-09-02 21:43:53 +02:00
u8 * script ;
struct {
2018-10-17 04:47:08 +02:00
u16 item ;
2019-10-06 21:17:34 +02:00
u16 hiddenItemId ;
2017-09-02 21:43:53 +02:00
} hiddenItem ;
u32 secretBaseId ;
} bgUnion ;
} ;
struct MapEvents
{
2019-11-21 04:55:44 +01:00
u8 objectEventCount ;
2017-09-02 21:43:53 +02:00
u8 warpCount ;
u8 coordEventCount ;
u8 bgEventCount ;
2019-11-21 04:55:44 +01:00
struct ObjectEventTemplate * objectEvents ;
2017-09-02 21:43:53 +02:00
struct WarpEvent * warps ;
struct CoordEvent * coordEvents ;
struct BgEvent * bgEvents ;
} ;
struct MapConnection
{
2019-10-06 21:17:34 +02:00
u8 direction ;
u32 offset ;
u8 mapGroup ;
u8 mapNum ;
2017-09-02 21:43:53 +02:00
} ;
struct MapConnections
{
s32 count ;
struct MapConnection * connections ;
} ;
struct MapHeader
{
2018-06-21 00:41:51 +02:00
/* 0x00 */ const struct MapLayout * mapLayout ;
2018-02-14 00:58:22 +01:00
/* 0x04 */ const struct MapEvents * events ;
2018-02-15 23:09:52 +01:00
/* 0x08 */ const u8 * mapScripts ;
2018-02-14 00:58:22 +01:00
/* 0x0C */ const struct MapConnections * connections ;
2017-09-02 21:43:53 +02:00
/* 0x10 */ u16 music ;
2018-06-21 00:41:51 +02:00
/* 0x12 */ u16 mapLayoutId ;
2017-09-02 21:43:53 +02:00
/* 0x14 */ u8 regionMapSectionId ;
/* 0x15 */ u8 cave ;
/* 0x16 */ u8 weather ;
/* 0x17 */ u8 mapType ;
2018-12-31 01:59:57 +01:00
/* 0x18 */ u8 filler_18 [ 2 ] ;
2021-06-13 23:32:00 +02:00
// fields correspond to the arguments in the map_header_flags macro
/* 0x1A */ bool8 allowCycling : 1 ;
bool8 allowEscaping : 1 ; // Escape Rope and Dig
bool8 allowRunning : 1 ;
2021-08-25 00:59:32 +02:00
bool8 showMapName : 5 ; // the last 4 bits are unused
2021-06-13 23:32:00 +02:00
// but the 5 bit sized bitfield is required to match
2017-09-02 21:43:53 +02:00
/* 0x1B */ u8 battleType ;
} ;
2020-01-08 11:43:06 +01:00
2019-11-21 04:55:44 +01:00
struct ObjectEvent
2017-09-02 21:43:53 +02:00
{
/*0x00*/ u32 active : 1 ;
2018-06-11 16:19:17 +02:00
u32 singleMovementActive : 1 ;
u32 triggerGroundEffectsOnMove : 1 ;
u32 triggerGroundEffectsOnStop : 1 ;
u32 disableCoveringGroundEffects : 1 ;
u32 landingJump : 1 ;
u32 heldMovementActive : 1 ;
u32 heldMovementFinished : 1 ;
/*0x01*/ u32 frozen : 1 ;
u32 facingDirectionLocked : 1 ;
u32 disableAnim : 1 ;
u32 enableAnim : 1 ;
u32 inanimate : 1 ;
u32 invisible : 1 ;
u32 offScreen : 1 ;
u32 trackedByCamera : 1 ;
/*0x02*/ u32 isPlayer : 1 ;
u32 hasReflection : 1 ;
u32 inShortGrass : 1 ;
u32 inShallowFlowingWater : 1 ;
u32 inSandPile : 1 ;
u32 inHotSprings : 1 ;
u32 hasShadow : 1 ;
u32 spriteAnimPausedBackup : 1 ;
/*0x03*/ u32 spriteAffineAnimPausedBackup : 1 ;
u32 disableJumpLandingGroundEffect : 1 ;
u32 fixedPriority : 1 ;
2019-10-06 21:17:34 +02:00
u32 hideReflection : 1 ;
2022-12-18 02:55:43 +01:00
//u32 padding:4;
2017-09-02 21:43:53 +02:00
/*0x04*/ u8 spriteId ;
/*0x05*/ u8 graphicsId ;
2018-06-11 16:19:17 +02:00
/*0x06*/ u8 movementType ;
2017-09-02 21:43:53 +02:00
/*0x07*/ u8 trainerType ;
/*0x08*/ u8 localId ;
/*0x09*/ u8 mapNum ;
/*0x0A*/ u8 mapGroup ;
2018-06-11 16:19:17 +02:00
/*0x0B*/ u8 currentElevation : 4 ;
u8 previousElevation : 4 ;
/*0x0C*/ struct Coords16 initialCoords ;
/*0x10*/ struct Coords16 currentCoords ;
/*0x14*/ struct Coords16 previousCoords ;
2020-09-18 00:24:11 +02:00
/*0x18*/ u16 facingDirection : 4 ; // current direction?
u16 movementDirection : 4 ;
u16 rangeX : 4 ;
u16 rangeY : 4 ;
2018-06-11 16:19:17 +02:00
/*0x1A*/ u8 fieldEffectSpriteId ;
/*0x1B*/ u8 warpArrowSpriteId ;
/*0x1C*/ u8 movementActionId ;
2017-09-02 21:43:53 +02:00
/*0x1D*/ u8 trainerRange_berryTreeId ;
2018-06-11 16:19:17 +02:00
/*0x1E*/ u8 currentMetatileBehavior ;
/*0x1F*/ u8 previousMetatileBehavior ;
/*0x20*/ u8 previousMovementDirection ;
/*0x21*/ u8 directionSequenceIndex ;
2021-11-01 23:06:15 +01:00
/*0x22*/ u8 playerCopyableMovement ; // COPY_MOVE_*
2022-12-18 02:55:43 +01:00
/*0x23*/ //u8 padding2;
2017-09-02 21:43:53 +02:00
/*size = 0x24*/
} ;
2019-11-21 04:55:44 +01:00
struct ObjectEventGraphicsInfo
2017-09-02 21:43:53 +02:00
{
/*0x00*/ u16 tileTag ;
2020-11-23 20:12:07 +01:00
/*0x02*/ u16 paletteTag ;
/*0x04*/ u16 reflectionPaletteTag ;
2017-09-02 21:43:53 +02:00
/*0x06*/ u16 size ;
/*0x08*/ s16 width ;
/*0x0A*/ s16 height ;
/*0x0C*/ u8 paletteSlot : 4 ;
u8 shadowSize : 2 ;
u8 inanimate : 1 ;
u8 disableReflectionPaletteLoad : 1 ;
/*0x0D*/ u8 tracks ;
/*0x10*/ const struct OamData * oam ;
/*0x14*/ const struct SubspriteTable * subspriteTables ;
/*0x18*/ const union AnimCmd * const * anims ;
/*0x1C*/ const struct SpriteFrameImage * images ;
/*0x20*/ const union AffineAnimCmd * const * affineAnims ;
} ;
2019-04-01 18:05:58 +02:00
enum {
PLAYER_AVATAR_STATE_NORMAL ,
PLAYER_AVATAR_STATE_MACH_BIKE ,
PLAYER_AVATAR_STATE_ACRO_BIKE ,
PLAYER_AVATAR_STATE_SURFING ,
PLAYER_AVATAR_STATE_UNDERWATER ,
PLAYER_AVATAR_STATE_FIELD_MOVE ,
PLAYER_AVATAR_STATE_FISHING ,
PLAYER_AVATAR_STATE_WATERING ,
} ;
2021-10-26 19:27:20 +02:00
# define PLAYER_AVATAR_FLAG_ON_FOOT (1 << 0)
# define PLAYER_AVATAR_FLAG_MACH_BIKE (1 << 1)
# define PLAYER_AVATAR_FLAG_ACRO_BIKE (1 << 2)
# define PLAYER_AVATAR_FLAG_SURFING (1 << 3)
# define PLAYER_AVATAR_FLAG_UNDERWATER (1 << 4)
# define PLAYER_AVATAR_FLAG_CONTROLLABLE (1 << 5)
# define PLAYER_AVATAR_FLAG_FORCED_MOVE (1 << 6)
# define PLAYER_AVATAR_FLAG_DASH (1 << 7)
2017-09-02 21:43:53 +02:00
enum
{
ACRO_BIKE_NORMAL ,
ACRO_BIKE_TURNING ,
ACRO_BIKE_WHEELIE_STANDING ,
ACRO_BIKE_BUNNY_HOP ,
ACRO_BIKE_WHEELIE_MOVING ,
ACRO_BIKE_STATE5 ,
ACRO_BIKE_STATE6 ,
} ;
enum
{
2019-10-06 22:40:10 +02:00
COLLISION_NONE ,
COLLISION_OUTSIDE_RANGE ,
COLLISION_IMPASSABLE ,
COLLISION_ELEVATION_MISMATCH ,
2019-11-21 05:12:51 +01:00
COLLISION_OBJECT_EVENT ,
2019-10-06 22:40:10 +02:00
COLLISION_STOP_SURFING ,
COLLISION_LEDGE_JUMP ,
COLLISION_PUSHED_BOULDER ,
COLLISION_ROTATING_GATE ,
COLLISION_WHEELIE_HOP ,
COLLISION_ISOLATED_VERTICAL_RAIL ,
COLLISION_ISOLATED_HORIZONTAL_RAIL ,
COLLISION_VERTICAL_RAIL ,
COLLISION_HORIZONTAL_RAIL ,
2017-09-02 21:43:53 +02:00
} ;
2017-12-21 17:46:03 +01:00
// player running states
enum
{
NOT_MOVING ,
TURN_DIRECTION , // not the same as turning! turns your avatar without moving. also known as a turn frame in some circles
MOVING ,
} ;
// player tile transition states
enum
{
T_NOT_MOVING ,
T_TILE_TRANSITION ,
T_TILE_CENTER , // player is on a frame in which they are centered on a tile during which the player either stops or keeps their momentum and keeps going, changing direction if necessary.
} ;
struct PlayerAvatar
2017-09-02 21:43:53 +02:00
{
/*0x00*/ u8 flags ;
2020-04-01 08:54:26 +02:00
/*0x01*/ u8 transitionFlags ; // used to be named bike, but its definitely not that. seems to be some transition flags
2017-12-21 17:46:03 +01:00
/*0x02*/ u8 runningState ; // this is a static running state. 00 is not moving, 01 is turn direction, 02 is moving.
/*0x03*/ u8 tileTransitionState ; // this is a transition running state: 00 is not moving, 01 is transition between tiles, 02 means you are on the frame in which you have centered on a tile but are about to keep moving, even if changing directions. 2 is also used for a ledge hop, since you are transitioning.
2017-09-02 21:43:53 +02:00
/*0x04*/ u8 spriteId ;
2019-11-21 04:55:44 +01:00
/*0x05*/ u8 objectEventId ;
2017-12-21 17:46:03 +01:00
/*0x06*/ bool8 preventStep ;
2017-09-02 21:43:53 +02:00
/*0x07*/ u8 gender ;
2017-12-21 17:46:03 +01:00
/*0x08*/ u8 acroBikeState ; // 00 is normal, 01 is turning, 02 is standing wheelie, 03 is hopping wheelie
/*0x09*/ u8 newDirBackup ; // during bike movement, the new direction as opposed to player's direction is backed up here.
/*0x0A*/ u8 bikeFrameCounter ; // on the mach bike, when this value is 1, the bike is moving but not accelerating yet for 1 tile. on the acro bike, this acts as a timer for acro bike.
/*0x0B*/ u8 bikeSpeed ;
2018-12-07 14:01:59 +01:00
// acro bike only
2017-12-21 17:46:03 +01:00
/*0x0C*/ u32 directionHistory ; // up/down/left/right history is stored in each nybble, but using the field directions and not the io inputs.
/*0x10*/ u32 abStartSelectHistory ; // same as above but for A + B + start + select only
2018-12-07 14:01:59 +01:00
// these two are timer history arrays which [0] is the active timer for acro bike. every element is backed up to the next element upon update.
2017-12-21 17:46:03 +01:00
/*0x14*/ u8 dirTimerHistory [ 8 ] ;
/*0x1C*/ u8 abStartSelectTimerHistory [ 8 ] ;
2017-09-02 21:43:53 +02:00
} ;
struct Camera
{
2017-09-10 21:35:21 +02:00
bool8 active : 1 ;
2017-09-02 21:43:53 +02:00
s32 x ;
s32 y ;
} ;
2019-11-21 05:12:51 +01:00
extern struct ObjectEvent gObjectEvents [ OBJECT_EVENTS_COUNT ] ;
2019-11-21 04:55:44 +01:00
extern u8 gSelectedObjectEvent ;
2017-09-02 21:43:53 +02:00
extern struct MapHeader gMapHeader ;
extern struct PlayerAvatar gPlayerAvatar ;
2017-09-10 21:35:21 +02:00
extern struct Camera gCamera ;
2017-09-02 21:43:53 +02:00
# endif // GUARD_GLOBAL_FIELDMAP_H