Skip to Content
The Alchemy Project

include/field/map_grid.h

Map grids: their metatiles, layers, animations and blend scripts, and the map grid state.

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

NameDescription
structMAP_GRID_METATILEOne metatile of a map layer: its metatile tiles and flags, its metatile behavior and its shape, an index into the shape table.
structBLEND_SCRIPT_STATEThe map's running blend script, which sets the blend registers over time (fdBlendScriptRun, each tick from fdBlendScriptStart).
structTILESET_ANIMOne 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.
structWORLD_POSA position on the world map, as its walkability check reads it.
structMAP_RESOURCESA row of MapsWork: a layout's resources, each counted from ResourceIdEmptyMap.
structMAP_GRID_LAYER_SCROLLOne background layer of the field map: its scroll position, origin, parallax against the view, drift and wrap, and its first map metatile.
structMAP_GRID_SCROLL_STATEThe field map's state: the followed position, screen shake, tileset animations, blend script, view and its bounds, and three scrolling layers.

Macros

NameDescription
#defineMAPGRID_METATILE_TILES_ID_MASK 0x00000fffThe number of the metatile tiles a map metatile draws, in its low 12 bits.
#defineWORLD_MAP_BLOCK_SHIFT 21The 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.
#defineWORLD_MAP_BLOCK_PIXELS 32
#defineWORLD_MAP_BLOCKS_ACROSS 32
#defineMAPGRID_SIZE 128The map grid: 128 by 128 metatiles, each 16 pixels square, wrapping at its edges.
#defineMAPGRID_ROW_SHIFT 7A map grid row, MAPGRID_SIZE metatiles, as a shift.
#defineMAPGRID_METATILE_PIXELS 16
#defineMAPGRID_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].
#defineMAPGRID_METATILE_PIXEL_MASK 0xfff0A whole pixel coordinate's map metatile, in pixels.
#defineMAPGRID_SHAPE_KIND_MASK 0xfThe low four bits of a shape's first byte: its kind, which height function reads its samples (MapGridTerrainHeightFunctions).
#defineWorldMapAffineStateWorkHEAP_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

NameDescription
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

NameDescription
enumMETATILE_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.
enumMAP_GRID_LAYER_INDEX { MAPGRID_LAYER_GROUND, MAPGRID_LAYER_MIDDLE, MAPGRID_LAYER_OV … }A layout's three layers, by what they hold.

Functions

NameDescription
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

NameDescription
extern Uint32MetatileTiles []The layout's metatile tiles, 32 KB of EWRAM at 0x02020000: each metatile's tiles 8 bytes, its four tile entries.
extern Uint8MapGridAnimationTiles []The tileset animations' tiles, 16 KB of EWRAM at 0x02028000.
extern Uint8MapGridShapes []The map's shape table, 16 KB of EWRAM at 0x0202c000: 4-byte entries that MAP_GRID_METATILE.shape indexes.
extern Uint8BgTileBuffer []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_RESOURCESMapsWork []Every layout's resources, by map number (src/map/resources.s).
extern const TERRAIN_HEIGHT_FNMapGridTerrainHeightFunctions [TERRAIN_KIND_COUNT]Ground height functions, by TERRAIN_KIND, called with (the remaining samples, x within the metatile, y within the metatile).
extern const Sint8WorldMapDirectionOffsets [8][2]The eight compass directions as (x, y) offsets of radius 40.
extern const Uint32WorldMapUnitScale [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.

EnumeratorValueDescription
METATILE_BEHAVIOR_NORMAL0Open ground: nothing happens there.
METATILE_BEHAVIOR_CUE_FIRST11 to 239: the scene's own
METATILE_BEHAVIOR_CUE_LAST239scripts, step cue or exit when stepped on (fdRunStepCueOrExit), examine cue when the player presses A facing the metatile.
METATILE_BEHAVIOR_ENCOUNTER_GROUND_A240Ground with encounters of its
METATILE_BEHAVIOR_ENCOUNTER_GROUND_B241own: grounds 1 and 2 of the map's zones.
METATILE_BEHAVIOR_JAR242242 to 247: examine cues with lines of their own, the same on every map (fdExamineMetatile, FieldExamineCueMessageOffsets).
METATILE_BEHAVIOR_BARREL243
METATILE_BEHAVIOR_WOODEN_BOX244
METATILE_BEHAVIOR_GRAVE245
METATILE_BEHAVIOR_BOOKS246
METATILE_BEHAVIOR_WELL247
METATILE_BEHAVIOR_JUMP_FORWARD_UNREACHED249Jumps forward like METATILE_BEHAVIOR_JUMP_FORWARD, but fdUpdateWalking never passes it to fdRunPushMetatile.
METATILE_BEHAVIOR_DESERT_SAND250Ground that hurts the party over time: the Lamakan Desert's sand.
METATILE_BEHAVIOR_CLOAK251Ground Cloak keeps the leader hidden on; stepping off it ends Cloak.
METATILE_BEHAVIOR_LEDGE252Jumped down with Down held.
METATILE_BEHAVIOR_CLIMB253Climbed up or down with Up or Down held.
METATILE_BEHAVIOR_JUMP_FORWARD254Jumped across.
METATILE_BEHAVIOR_WALL255Blocks 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.

EnumeratorValueDescription
MAPGRID_LAYER_GROUND0BG3: the ground, at the back
MAPGRID_LAYER_MIDDLE1BG2: walls and edges, under the actors
MAPGRID_LAYER_OVERHEAD2BG1: roofs and tree tops, over the actors
MAPGRID_LAYER_COUNT3

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.