include/field/map_grid.h
Map grids: their metatiles, layers, animations and blend scripts, and the map grid state.
#include "fixed_math.h"#include "static_assert.h"#include "types.h"#include "field/field.h"#include "system.h"#include "field/perspective.h"
Included by battle_internal.h, battle_effect_internal.h, field_engine_internal.h, field_internal.h, lucky_dice.c, lucky_wheels.c, map_grid_data.c, script_commands_internal.h, main_routine.c, credits.c, title_intro.c, altin_peak.c, bilibin_cave.c, colosseum_navampa_match.c, cottage_rooms_b.c, crossbone_isle_stepping_stones.c, file_screen.c, goma_cave_entrance.c, imil.c, imil_fuchin_falls.c, kalay.c, kolima_forest_floodgate.c, lemurian_ship.c, log_rooms_a.c, mercury_lighthouse.c, mercury_lighthouse_aerie.c, kolima_curse_dust.c, pushed_actor.c, sol_sanctum_statue.c, suhalla_desert.c, title.c, tolbi.c, tolbi_games.c, tolbi_ship_deck.c, tolbi_ship_mast.c, tree_rooms.c, tret_tree_branch.c, vale_plaza.c, vault_cave.c, venus_lighthouse.c, venus_lighthouse_aerie.c, screens_internal.h and window_selection.c.
Structures
| Name | Description | |
|---|---|---|
struct | MAP_GRID_METATILE | One metatile of a map layer: its metatile tiles and flags, its metatile behavior and its shape, an index into the shape table. |
struct | BLEND_SCRIPT_STATE | The map's running blend script, which sets the blend registers over time (fdBlendScriptRun, each tick from fdBlendScriptStart). |
struct | TILESET_ANIM | One of the 16 tileset animations, which copy tiles into VRAM by script (fdTilesetAnimationUpdate): groups of four halfwords, the source tile, the count, the destination tile and the ticks to wait. |
struct | WORLD_POS | A position on the world map, as its walkability check reads it. |
struct | MAP_RESOURCES | A row of MapsWork: a layout's resources, each counted from ResourceIdEmptyMap. |
struct | MAP_GRID_LAYER_SCROLL | One background layer of the field map: its scroll position, origin, parallax against the view, drift and wrap, and its first map metatile. |
struct | MAP_GRID_SCROLL_STATE | The field map's state: the followed position, screen shake, tileset animations, blend script, view and its bounds, and three scrolling layers. |
Macros
| Name | Description | |
|---|---|---|
#define | MAPGRID_METATILE_TILES_ID_MASK 0x00000fff | The number of the metatile tiles a map metatile draws, in its low 12 bits. |
#define | WORLD_MAP_BLOCK_SHIFT 21 | The World Map's 32-pixel blocks, 32 to a row of MetatileTiles, wrapping round: a 16.16 coordinate shifted down this far is a block. |
#define | WORLD_MAP_BLOCK_PIXELS 32 | |
#define | WORLD_MAP_BLOCKS_ACROSS 32 | |
#define | MAPGRID_SIZE 128 | The map grid: 128 by 128 metatiles, each 16 pixels square, wrapping at its edges. |
#define | MAPGRID_ROW_SHIFT 7 | A map grid row, MAPGRID_SIZE metatiles, as a shift. |
#define | MAPGRID_METATILE_PIXELS 16 | |
#define | MAPGRID_METATILES ((MAP_GRID_METATILE *)RamMapGridMetatileBuffer) | The map grid's metatiles, row by row, in RamMapGridMetatileBuffer (system/definitions.h): the metatile at column x, row y is MAPGRID_METATILES[y * MAPGRID_SIZE + x]. |
#define | MAPGRID_METATILE_PIXEL_MASK 0xfff0 | A whole pixel coordinate's map metatile, in pixels. |
#define | MAPGRID_SHAPE_KIND_MASK 0xf | The low four bits of a shape's first byte: its kind, which height function reads its samples (MapGridTerrainHeightFunctions). |
#define | WorldMapAffineStateWork | HEAP_SLOT_WORLD_MAP_AFFINE under its own name, which no code reads; the world map keeps its WORLD_MAP_AFFINE_STATE in the slot. |
Typedefs
| Name | Description | |
|---|---|---|
typedef Sint32 (* | TERRAIN_HEIGHT_FN )(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY); | A terrain kind's ground height: from a metatile's height samples and a pixel (pixelX, pixelY) within the 16 by 16 metatile, the height in 16.16 pixels. |
Enumerations
| Name | Description | |
|---|---|---|
enum | METATILE_BEHAVIOR { METATILE_BEHAVIOR_NORMAL, METATILE_BEHAVIOR_CUE_FIRST, METAT … } | A map metatile's metatile behavior (MAP_GRID_METATILE.behavior): what stepping on, pushing against or searching the metatile does. |
enum | MAP_GRID_LAYER_INDEX { MAPGRID_LAYER_GROUND, MAPGRID_LAYER_MIDDLE, MAPGRID_LAYER_OV … } | A layout's three layers, by what they hold. |
Functions
| Name | Description | |
|---|---|---|
static inline FIXED * | fdMapGridScrollStateView (MAP_GRID_SCROLL_STATE *grid) | The map's view position (MAP_GRID_SCROLL_STATE.view): its left and its top, x then y, in 16.16 fixed-point pixels. |
Variables
| Name | Description | |
|---|---|---|
extern Uint32 | MetatileTiles [] | The layout's metatile tiles, 32 KB of EWRAM at 0x02020000: each metatile's tiles 8 bytes, its four tile entries. |
extern Uint8 | MapGridAnimationTiles [] | The tileset animations' tiles, 16 KB of EWRAM at 0x02028000. |
extern Uint8 | MapGridShapes [] | The map's shape table, 16 KB of EWRAM at 0x0202c000: 4-byte entries that MAP_GRID_METATILE.shape indexes. |
extern Uint8 | BgTileBuffer [] | 32 KB of EWRAM at 0x02038000 holding background tiles, such as the world map's char blocks 2 and 3, which fdWorldMapEndStillImage copies back after the still image. |
extern const MAP_RESOURCES | MapsWork [] | Every layout's resources, by map number (src/map/resources.s). |
extern const TERRAIN_HEIGHT_FN | MapGridTerrainHeightFunctions [TERRAIN_KIND_COUNT] | Ground height functions, by TERRAIN_KIND, called with (the remaining samples, x within the metatile, y within the metatile). |
extern const Sint8 | WorldMapDirectionOffsets [8][2] | The eight compass directions as (x, y) offsets of radius 40. |
extern const Uint32 | WorldMapUnitScale [2] | Two 1.0s (16.16). |
Description
Map grids: their metatiles, layers, animations and blend scripts, and the map grid state.
Macros in detail
MAPGRID_METATILE_TILES_ID_MASK
#define MAPGRID_METATILE_TILES_ID_MASK 0x00000fff
The number of the metatile tiles a map metatile draws, in its low 12 bits.
Referenced by fdMapGridCopyMetatileAttributeRect(), fdMapGridCopyMetatileIndexRect(), fdMapGridCopyMetatileRect(), fdMapGridCopyMetatileTilesRect(), fdTileMapNumberPlaceholderMetatileTiles() and scMapGridDrawMetatilePanel().
Definition at line 75 of file map_grid.h.
WORLD_MAP_BLOCK_SHIFT
#define WORLD_MAP_BLOCK_SHIFT 21
The World Map's 32-pixel blocks, 32 to a row of MetatileTiles, wrapping
round: a 16.16 coordinate shifted down this far is a block.
Definition at line 123 of file map_grid.h.
WORLD_MAP_BLOCK_PIXELS
#define WORLD_MAP_BLOCK_PIXELS 32
Referenced by fdPsynergyCheckCloakTile() and fdWorldMapGetBattleEnvironment().
Definition at line 124 of file map_grid.h.
WORLD_MAP_BLOCKS_ACROSS
#define WORLD_MAP_BLOCKS_ACROSS 32
Referenced by fdPsynergyCheckCloakTile() and fdWorldMapGetBattleEnvironment().
Definition at line 125 of file map_grid.h.
MAPGRID_SIZE
#define MAPGRID_SIZE 128
The map grid: 128 by 128 metatiles, each 16 pixels square, wrapping at its edges.
Referenced by fdActorGetCueMetatileAheadOfCurrent(), fdActorMoveByKeys(), fdActorResetForLeader(), fdActorSystemPlaceSprites(), fdClimbDown(), fdClimbUp(), fdGetCollisionAheadOfLeader(), fdMapGridCheckCollision(), fdMapGridCopyMetatileAttributeRect(), fdMapGridCopyMetatileIndexRect(), fdMapGridCopyMetatileRect(), fdMapGridCopyMetatileTilesRect(), fdMapGridGetMetatileBehaviorAt(), fdMapGridGetMetatileHighFlags(), fdMapGridGetTerrainHeight(), fdMapGridGetTerrainKindAt(), fdMapGridIsWallAt(), fdMapGridLoadMap(), fdMapGridRenderMetatileTilesColumn(), fdMapGridRenderMetatileTilesRow(), fdMapGridSetCameraCenter(), fdMapGridSetMetatileBehaviorAt(), fdPsynergyCheckCloakTile(), fdTileMapNumberPlaceholderMetatileTiles(), fdUpdateWalking(), scKolimaForestFloodgateCheckLogFits(), scMapGridDrawMetatilePanel(), scMapGridFillCollisionRectangle(), scMercuryLighthouseHopAcrossPool() and scMercuryLighthouseRestoreLights().
Definition at line 141 of file map_grid.h.
MAPGRID_ROW_SHIFT
#define MAPGRID_ROW_SHIFT 7
A map grid row, MAPGRID_SIZE metatiles, as a shift.
Referenced by scCrossboneIsleSteppingStonesReadMapGridMetatile(), scCrossboneIsleSteppingStonesSetMetatileAttributes() and scKolimaForestFloodgateMarkLogMetatiles().
Definition at line 143 of file map_grid.h.
MAPGRID_METATILE_PIXELS
#define MAPGRID_METATILE_PIXELS 16
Referenced by fdActorGetCueMetatileAheadOfCurrent(), fdActorMoveByKeys(), fdActorResetForLeader(), fdClimbDown(), fdClimbUp(), fdEffectSpawnRevealMarkers(), fdGetCollisionAheadOfLeader(), fdMapGridCheckCollision(), fdMapGridGetMetatileHighFlags(), fdMapGridGetTerrainHeight(), fdMapGridGetTerrainKindAt(), fdMapGridIsWallAt(), fdPlaceTreasureSpots(), fdPsynergyCheckCloakTile(), fdTreasureSpotMoveLeaderAway(), fdUpdateWalking(), scGomaCaveEntrancePushWestPillar(), scLogRoomsAIsWithinHalfMetatileOfStop() and scLogRoomsAIsWithinMetatileOfStop().
Definition at line 144 of file map_grid.h.
MAPGRID_METATILES
#define MAPGRID_METATILES ((MAP_GRID_METATILE *)RamMapGridMetatileBuffer)
The map grid's metatiles, row by row, in RamMapGridMetatileBuffer
(system/definitions.h): the metatile at column x, row y is
MAPGRID_METATILES[y * MAPGRID_SIZE + x].
Referenced by fdActorResetForLeader(), fdClimbDown(), fdClimbUp() and scMercuryLighthouseHopAcrossPool().
Definition at line 148 of file map_grid.h.
MAPGRID_METATILE_PIXEL_MASK
#define MAPGRID_METATILE_PIXEL_MASK 0xfff0
A whole pixel coordinate's map metatile, in pixels.
Referenced by fdGroundMaskDrawMarks().
Definition at line 150 of file map_grid.h.
MAPGRID_SHAPE_KIND_MASK
#define MAPGRID_SHAPE_KIND_MASK 0xf
The low four bits of a shape's first byte: its kind, which height function
reads its samples (MapGridTerrainHeightFunctions).
Referenced by fdMapGridCheckCollision(), fdMapGridGetTerrainHeight() and fdMapGridGetTerrainKindAt().
Definition at line 153 of file map_grid.h.
WorldMapAffineStateWork
#define WorldMapAffineStateWork
HEAP_SLOT_WORLD_MAP_AFFINE under its own name, which no code reads; the world
map keeps its WORLD_MAP_AFFINE_STATE in the slot.
Definition at line 157 of file map_grid.h.
Typedefs in detail
TERRAIN_HEIGHT_FN
typedef Sint32 (*TERRAIN_HEIGHT_FN)(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY);
A terrain kind's ground height: from a metatile's height samples and a pixel (pixelX, pixelY) within the 16 by 16 metatile, the height in 16.16 pixels.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 175 of file map_grid.h.
Enumerations in detail
METATILE_BEHAVIOR
enum METATILE_BEHAVIOR
A map metatile's metatile behavior (MAP_GRID_METATILE.behavior): what
stepping on, pushing against or searching the metatile does.
| Enumerator | Value | Description |
|---|---|---|
METATILE_BEHAVIOR_NORMAL | 0 | Open ground: nothing happens there. |
METATILE_BEHAVIOR_CUE_FIRST | 1 | 1 to 239: the scene's own |
METATILE_BEHAVIOR_CUE_LAST | 239 | scripts, step cue or exit when stepped on (fdRunStepCueOrExit), examine cue when the player presses A facing the metatile. |
METATILE_BEHAVIOR_ENCOUNTER_GROUND_A | 240 | Ground with encounters of its |
METATILE_BEHAVIOR_ENCOUNTER_GROUND_B | 241 | own: grounds 1 and 2 of the map's zones. |
METATILE_BEHAVIOR_JAR | 242 | 242 to 247: examine cues with lines of their own, the same on every map (fdExamineMetatile, FieldExamineCueMessageOffsets). |
METATILE_BEHAVIOR_BARREL | 243 | |
METATILE_BEHAVIOR_WOODEN_BOX | 244 | |
METATILE_BEHAVIOR_GRAVE | 245 | |
METATILE_BEHAVIOR_BOOKS | 246 | |
METATILE_BEHAVIOR_WELL | 247 | |
METATILE_BEHAVIOR_JUMP_FORWARD_UNREACHED | 249 | Jumps forward like METATILE_BEHAVIOR_JUMP_FORWARD, but fdUpdateWalking never passes it to fdRunPushMetatile. |
METATILE_BEHAVIOR_DESERT_SAND | 250 | Ground that hurts the party over time: the Lamakan Desert's sand. |
METATILE_BEHAVIOR_CLOAK | 251 | Ground Cloak keeps the leader hidden on; stepping off it ends Cloak. |
METATILE_BEHAVIOR_LEDGE | 252 | Jumped down with Down held. |
METATILE_BEHAVIOR_CLIMB | 253 | Climbed up or down with Up or Down held. |
METATILE_BEHAVIOR_JUMP_FORWARD | 254 | Jumped across. |
METATILE_BEHAVIOR_WALL | 255 | Blocks whatever the heights. |
Definition at line 15 of file map_grid.h.
MAP_GRID_LAYER_INDEX
enum MAP_GRID_LAYER_INDEX
A layout's three layers, by what they hold. Most layouts give them priorities 3, 2 and 1.
| Enumerator | Value | Description |
|---|---|---|
MAPGRID_LAYER_GROUND | 0 | BG3: the ground, at the back |
MAPGRID_LAYER_MIDDLE | 1 | BG2: walls and edges, under the actors |
MAPGRID_LAYER_OVERHEAD | 2 | BG1: roofs and tree tops, over the actors |
MAPGRID_LAYER_COUNT | 3 |
Definition at line 100 of file map_grid.h.
Functions in detail
fdMapGridScrollStateView
static inline FIXED *fdMapGridScrollStateView(MAP_GRID_SCROLL_STATE *grid)
The map's view position (MAP_GRID_SCROLL_STATE.view): its left and its top, x
then y, in 16.16 fixed-point pixels.
Referenced by fdActorGetScreenPos(), fdActorSystemPlaceSprites(), fdGroundMaskDrawMarks(), fdMapGridGetScreenRelativePos(), fdMotesUpdate(), fdScreenTransitionUpdateScanlineTable(), fdWeatherUpdateRain() and scSolSanctumStatueUpdateScrollingSprites().
Definition at line 250 of file map_grid.h.
Variables in detail
MetatileTiles
extern Uint32 MetatileTiles[]
The layout's metatile tiles, 32 KB of EWRAM at 0x02020000: each metatile's
tiles 8 bytes, its four tile entries. fdMapGridLoadMap decodes them in.
Referenced by fdGetCollisionAheadOfLeader(), fdPsynergyCheckCloakTile(), fdTileMapDecodeStagedBuffer() and fdWorldMapGetBattleEnvironment().
Definition at line 120 of file map_grid.h.
MapGridAnimationTiles
extern Uint8 MapGridAnimationTiles[]
The tileset animations' tiles, 16 KB of EWRAM at 0x02028000.
Referenced by fdMapGridLoadMap() and fdWorldMapLoadGraphics().
Definition at line 128 of file map_grid.h.
MapGridShapes
extern Uint8 MapGridShapes[]
The map's shape table, 16 KB of EWRAM at 0x0202c000: 4-byte entries that
MAP_GRID_METATILE.shape indexes.
Referenced by scKolimaForestFloodgateCheckLogFits().
Definition at line 132 of file map_grid.h.
BgTileBuffer
extern Uint8 BgTileBuffer[]
32 KB of EWRAM at 0x02038000 holding background tiles, such as the world
map's char blocks 2 and 3, which fdWorldMapEndStillImage copies back after
the still image.
Referenced by fdTileMapDrawRowsFromRam(), fdWorldMapEndStillImage(), fdWorldMapLoadAreaGraphics() and fdWorldMapLoadGraphics().
Definition at line 137 of file map_grid.h.
MapsWork
extern const MAP_RESOURCES MapsWork[]
Every layout's resources, by map number (src/map/resources.s).
Referenced by fdMapGridLoadMap().
Definition at line 171 of file map_grid.h.