src/field/field_terrain.c
Ground heights, and the collision of metatiles and the world map. More…
Included by field.c.
Macros
| Name | Description | |
|---|---|---|
#define | CURVE_HEIGHT_FIXED (sample) ((sample) * (1 << CURVE_VALUE_SHIFT)) | A sample is in eight-pixel units. |
#define | TERRAIN_DEFINE_SLOPE (name, along) | The slopes along one axis: from sample 0 where along, the pixel's coordinate on that axis, is 0, towards sample 1 where it is 16, rounded towards zero as dividing by 16 would. |
#define | TERRAIN_DEFINE_STEP (name, along) | The steps along one axis: sample 0 where along, the pixel's coordinate on that axis, is below 8, sample 1 from 8. |
#define | WORLD_MAP_LOWER_COLLISION_MAP BG_SCREEN_BLOCK(8) | The world map's collision: each tile of a terrain layer's map has a tile of 4-bit collision values, 8 bytes, two values a byte. |
#define | WORLD_MAP_UPPER_COLLISION_MAP BG_SCREEN_BLOCK(10) | |
#define | WORLD_MAP_COLLISION_TILE_BYTES 8 | |
#define | WORLD_MAP_UPPER_COLLISION_TILES (256 * WORLD_MAP_COLLISION_TILE_BYTES) | |
#define | WORLD_MAP_COLLISION_BITS 4 | |
#define | WORLD_MAP_COLLISION_MASK ((1 << WORLD_MAP_COLLISION_BITS) - 1) | |
#define | WORLD_MAP_BLOCK_SECOND_BANK (1 << (31 - 24)) | A block word's bit 31, in its top byte: the second bank of battle environments. |
#define | WORLD_MAP_BLOCK_REGION (word) (((word) << 1) >> 25) | A block word's encounter region, its bits 24 to 30. |
#define | WORLD_MAP_ENVIRONMENT_BANK 16 | The battle environments of WorldMapBattleEnvironments come in banks of one for each collision value. |
Functions
| Name | Description | |
|---|---|---|
FIXED | fdTerrainGetFlatHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | The ground height functions (MapGridTerrainHeightFunctions): each takes a metatile's height samples after its kind byte and a pixel (x, y) within the 16x16 metatile, and returns the ground height there in 16.16 pixels. |
FIXED | fdTerrainGetStepSumDiagonalHeight (const Uint8 *heightBytes, Sint32 x, Sint32 y) | A step across the diagonal x + y = 15: sample 0 before it, sample 1 after it and the higher of the two on it. |
FIXED | fdTerrainGetStepDifferenceDiagonalHeight (const Uint8 *heightBytes, Sint32 x, Sint32 y) | A step across the diagonal x = y: sample 0 where y < x, sample 1 where y > x and the higher of the two on it. |
FIXED | fdTerrainGetBendSumDiagonalHeight (const Uint8 *heightBytes, Sint32 x, Sint32 y) | A slope that bends on the diagonal x + y = 15: from sample 0 at the top left corner to sample 1 on the diagonal to sample 2 at the bottom right. |
FIXED | fdTerrainGetBendDifferenceDiagonalHeight (const Uint8 *heightBytes, Sint32 x, Sint32 y) | A slope that bends on the diagonal x = y: from sample 0 at the top right corner to sample 1 on the diagonal to sample 2 at the bottom left. |
FIXED | fdTerrainGetRoundedSquareHeight (const Uint8 *heightBytes, Sint32 x, Sint32 y) | A raised or sunken rounded square: sample 1 where TerrainRoundedSquareMask is 1, sample 0 in the corners. |
FIXED | fdTerrainGetBendXHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | A slope along x that bends at the middle: sample 0 at x = 0, sample 1 at x = 8, towards sample 2 at x = 16. |
FIXED | fdTerrainGetBendYHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | A slope along y that bends at the middle, as TERRAIN_BEND_X does along x. |
FIXED | fdTerrainGetSampleTableHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | The sample TerrainSampleIndexTable picks for (x, y). |
FIXED | fdTerrainGetSampleTableMirroredHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | The same, with the table mirrored left to right. |
FIXED | fdTerrainGetFlatBHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | Flat, as fdTerrainGetFlatHeight, for TERRAIN_FLAT_B. |
FIXED | fdTerrainGetFlatCHeight (const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY) | Flat, as fdTerrainGetFlatHeight, for TERRAIN_FLAT_C. |
FIXED | fdMapGridGetTerrainHeight (Sint32 layer, FIXED x, FIXED y) | Returns the ground height of a layer at (x, y) in 16.16 pixels: the height function of the metatile's terrain kind applied to its samples. y is the map's down axis, an actor's z. |
Sint32 | fdMapGridGetTerrainKindAt (Sint32 layer, FIXED x, FIXED y) | Returns the terrain kind (TERRAIN_KIND) of a layer's metatile at (x, y) in 16.16 pixels. |
Sint32 | fdMapGridGetMetatileBehaviorAt (Sint32 layer, FIXED x, FIXED y) | Returns the metatile behavior of a layer's metatile at (x, y) in 16.16 pixels. |
void | fdMapGridSetMetatileBehaviorAt (Uint32 layer, FIXED x, FIXED y, Uint32 behavior) | Sets the metatile behavior of a layer's metatile at (x, y) in 16.16 pixels. |
Sint32 | fdMapGridGetMetatileHighFlags (Sint32 x, Sint32 y) | Unused: returns the top two bits of the metatile tiles halfword of the metatile at pixel (x, y). |
Sint32 | fdMapGridCheckCollision (ACTOR *actor, FIELD_POS *pos) | Returns whether an actor can step to position, a COLLISION: whether the metatile there is a wall, or the ground too high or too low for a step from the actor's. |
Sint32 | fdMapGridIsWallAt (WORLD_POS *pos) | Returns -1 when the metatile under position (its x, and y less its height) in MAPGRID_LAYER_OVERHEAD is a wall (METATILE_BEHAVIOR_WALL), else 0; also 0 before the map state exists. |
Sint32 | fdWorldMapGetCollision (WORLD_POS *pos) | Returns the world map's collision value (1-15) at position: from the upper collision layer where it has one, else the lower, else WORLD_MAP_COLLISION_DEFAULT. |
Sint32 | fdWorldMapIsWalkable (Sint32 unused, WORLD_POS *pos) | Returns 0 when the world map at position can be walked on (collision WORLD_MAP_COLLISION_WALKABLE_FIRST to WORLD_MAP_COLLISION_WALKABLE_LAST), else -1. |
Sint32 | fdWorldMapGetBattleEnvironment (WORLD_POS *pos, Sint32 *region) | Returns the world map's battle environment at position from WorldMapBattleEnvironments, and stores the block's encounter region in *region. |
Description
Ground heights, and the collision of metatiles and the world map. Part of
field.c.
Macros in detail
CURVE_HEIGHT_FIXED
#define CURVE_HEIGHT_FIXED(sample) ((sample) * (1 << CURVE_VALUE_SHIFT))
A sample is in eight-pixel units.
Referenced by fdTerrainGetBendDifferenceDiagonalHeight(), fdTerrainGetBendSumDiagonalHeight(), fdTerrainGetBendXHeight(), fdTerrainGetBendYHeight(), fdTerrainGetFlatBHeight(), fdTerrainGetFlatCHeight(), fdTerrainGetFlatHeight(), fdTerrainGetRoundedSquareHeight(), fdTerrainGetSampleTableHeight(), fdTerrainGetSampleTableMirroredHeight(), fdTerrainGetStepDifferenceDiagonalHeight() and fdTerrainGetStepSumDiagonalHeight().
Definition at line 7 of file field_terrain.c.
TERRAIN_DEFINE_SLOPE
#define TERRAIN_DEFINE_SLOPE(name, along)
The slopes along one axis: from sample 0 where along, the pixel's
coordinate on that axis, is 0, towards sample 1 where it is 16, rounded
towards zero as dividing by 16 would.
Definition at line 23 of file field_terrain.c.
TERRAIN_DEFINE_STEP
#define TERRAIN_DEFINE_STEP(name, along)
The steps along one axis: sample 0 where along, the pixel's coordinate on
that axis, is below 8, sample 1 from 8.
Definition at line 195 of file field_terrain.c.
WORLD_MAP_LOWER_COLLISION_MAP
#define WORLD_MAP_LOWER_COLLISION_MAP BG_SCREEN_BLOCK(8)
The world map's collision: each tile of a terrain layer's map has a tile of 4-bit collision values, 8 bytes, two values a byte. The lower layer's map is in screen block 8, the upper's in screen block 10, and the upper's collision tiles follow the lower's 256 in the buffer.
Referenced by fdWorldMapGetCollision().
Definition at line 513 of file field_terrain.c.
WORLD_MAP_UPPER_COLLISION_MAP
#define WORLD_MAP_UPPER_COLLISION_MAP BG_SCREEN_BLOCK(10)
Referenced by fdWorldMapGetCollision().
Definition at line 514 of file field_terrain.c.
WORLD_MAP_COLLISION_TILE_BYTES
#define WORLD_MAP_COLLISION_TILE_BYTES 8
Referenced by fdWorldMapGetCollision().
Definition at line 515 of file field_terrain.c.
WORLD_MAP_UPPER_COLLISION_TILES
#define WORLD_MAP_UPPER_COLLISION_TILES (256 * WORLD_MAP_COLLISION_TILE_BYTES)
Referenced by fdWorldMapGetCollision().
Definition at line 516 of file field_terrain.c.
WORLD_MAP_COLLISION_BITS
#define WORLD_MAP_COLLISION_BITS 4
Referenced by fdWorldMapGetCollision().
Definition at line 517 of file field_terrain.c.
WORLD_MAP_COLLISION_MASK
#define WORLD_MAP_COLLISION_MASK ((1 << WORLD_MAP_COLLISION_BITS) - 1)
Referenced by fdWorldMapGetCollision().
Definition at line 518 of file field_terrain.c.
WORLD_MAP_BLOCK_SECOND_BANK
#define WORLD_MAP_BLOCK_SECOND_BANK (1 << (31 - 24))
A block word's bit 31, in its top byte: the second bank of battle environments.
Referenced by fdWorldMapGetBattleEnvironment().
Definition at line 522 of file field_terrain.c.
WORLD_MAP_BLOCK_REGION
#define WORLD_MAP_BLOCK_REGION(word) (((word) << 1) >> 25)
A block word's encounter region, its bits 24 to 30.
Referenced by fdWorldMapGetBattleEnvironment().
Definition at line 524 of file field_terrain.c.
WORLD_MAP_ENVIRONMENT_BANK
#define WORLD_MAP_ENVIRONMENT_BANK 16
The battle environments of WorldMapBattleEnvironments come in banks of one
for each collision value.
Referenced by fdWorldMapGetBattleEnvironment().
Definition at line 527 of file field_terrain.c.
Functions in detail
fdTerrainGetFlatHeight
FIXED fdTerrainGetFlatHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
The ground height functions (MapGridTerrainHeightFunctions): each takes a
metatile's height samples after its kind byte and a pixel (x, y) within the
16x16 metatile, and returns the ground height there in 16.16 pixels.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 12 of file field_terrain.c.
fdTerrainGetStepSumDiagonalHeight
FIXED fdTerrainGetStepSumDiagonalHeight(const Uint8 *heightBytes, Sint32 x, Sint32 y)
A step across the diagonal x + y = 15: sample 0 before it, sample 1 after it and the higher of the two on it.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 40 of file field_terrain.c.
fdTerrainGetStepDifferenceDiagonalHeight
FIXED fdTerrainGetStepDifferenceDiagonalHeight(const Uint8 *heightBytes, Sint32 x, Sint32 y)
A step across the diagonal x = y: sample 0 where y < x, sample 1 where y > x and the higher of the two on it.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 72 of file field_terrain.c.
fdTerrainGetBendSumDiagonalHeight
FIXED fdTerrainGetBendSumDiagonalHeight(const Uint8 *heightBytes, Sint32 x, Sint32 y)
A slope that bends on the diagonal x + y = 15: from sample 0 at the top left corner to sample 1 on the diagonal to sample 2 at the bottom right.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 107 of file field_terrain.c.
fdTerrainGetBendDifferenceDiagonalHeight
FIXED fdTerrainGetBendDifferenceDiagonalHeight(const Uint8 *heightBytes, Sint32 x, Sint32 y)
A slope that bends on the diagonal x = y: from sample 0 at the top right corner to sample 1 on the diagonal to sample 2 at the bottom left.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 143 of file field_terrain.c.
fdTerrainGetRoundedSquareHeight
FIXED fdTerrainGetRoundedSquareHeight(const Uint8 *heightBytes, Sint32 x, Sint32 y)
A raised or sunken rounded square: sample 1 where TerrainRoundedSquareMask is
1, sample 0 in the corners.
References Sint32 and TerrainRoundedSquareMask.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 178 of file field_terrain.c.
fdTerrainGetBendXHeight
FIXED fdTerrainGetBendXHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
A slope along x that bends at the middle: sample 0 at x = 0, sample 1 at x = 8, towards sample 2 at x = 16.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 212 of file field_terrain.c.
fdTerrainGetBendYHeight
FIXED fdTerrainGetBendYHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
A slope along y that bends at the middle, as TERRAIN_BEND_X does along x.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 233 of file field_terrain.c.
fdTerrainGetSampleTableHeight
FIXED fdTerrainGetSampleTableHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
The sample TerrainSampleIndexTable picks for (x, y).
References Sint32 and TerrainSampleIndexTable.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 263 of file field_terrain.c.
fdTerrainGetSampleTableMirroredHeight
FIXED fdTerrainGetSampleTableMirroredHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
The same, with the table mirrored left to right.
References Sint32 and TerrainSampleIndexTable.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 274 of file field_terrain.c.
fdTerrainGetFlatBHeight
FIXED fdTerrainGetFlatBHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
Flat, as fdTerrainGetFlatHeight, for TERRAIN_FLAT_B.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 286 of file field_terrain.c.
fdTerrainGetFlatCHeight
FIXED fdTerrainGetFlatCHeight(const Uint8 *heightBytes, Sint32 pixelX, Sint32 pixelY)
Flat, as fdTerrainGetFlatHeight, for TERRAIN_FLAT_C.
References Sint32.
Referenced by MapGridTerrainHeightFunctions.
Definition at line 295 of file field_terrain.c.
fdMapGridGetTerrainHeight
FIXED fdMapGridGetTerrainHeight(Sint32 layer, FIXED x, FIXED y)
Returns the ground height of a layer at (x, y) in 16.16 pixels: the height function of the metatile's terrain kind applied to its samples. y is the map's down axis, an actor's z.
References MapGridTerrainHeightFunctions and Sint32.
Referenced by fdActorMoveByKeys(), fdActorUpdateAllOnField(), scAltinPeakAdvanceCart(), scAltinPeakRollCart(), scBabiLighthouseFindMetatileAhead(), scColosseumAzartMatchUpdateRockMetatiles(), scColosseumNavampaMatchUpdateLogAreaStoneMetatiles(), scCrossboneIsleSteppingStonesJumpOrPushStackedPillar(), scCrossboneIsleSteppingStonesLowerActorToLedge(), scInit(), scKolimaForestFloodgateCreateLogs(), scLeaderSlideOnIce() and scTretTreeBranchShiftLeaderAndCameraByMetatiles().
Definition at line 310 of file field_terrain.c.
fdMapGridGetTerrainKindAt
Sint32 fdMapGridGetTerrainKindAt(Sint32 layer, FIXED x, FIXED y)
Returns the terrain kind (TERRAIN_KIND) of a layer's metatile at (x, y) in
16.16 pixels.
References MapGridMetatileBuffer and Sint32.
Definition at line 349 of file field_terrain.c.
fdMapGridGetMetatileBehaviorAt
Sint32 fdMapGridGetMetatileBehaviorAt(Sint32 layer, FIXED x, FIXED y)
Returns the metatile behavior of a layer's metatile at (x, y) in 16.16 pixels.
References MapGridMetatileBuffer and Sint32.
Referenced by scAltinPeakRollCart(), scColosseumNavampaMatchCheckLongLogMetatile(), scCrossboneIsleSteppingStonesMovePillar() and scLeaderSlideOnIce().
Definition at line 374 of file field_terrain.c.
fdMapGridSetMetatileBehaviorAt
void fdMapGridSetMetatileBehaviorAt(Uint32 layer, FIXED x, FIXED y, Uint32 behavior)
Sets the metatile behavior of a layer's metatile at (x, y) in 16.16 pixels. Writes the metatile in the map's grid; does nothing before the map is set up.
Referenced by fdSetMetatileBehaviorAt(), scAltinPeakWallOffPuddle(), scColosseumNavampaMatchUpdateEastEndCollision(), scCrossboneIsleGrowFourthPlant(), scCrossboneIsleGrowPlant(), scVenusLighthouseMoveCarryPillar() and scVenusLighthouseUnblockCarryPillarMetatiles().
Definition at line 394 of file field_terrain.c.
fdMapGridGetMetatileHighFlags
Sint32 fdMapGridGetMetatileHighFlags(Sint32 x, Sint32 y)
Unused: returns the top two bits of the metatile tiles halfword of the metatile at pixel (x, y).
References MapGridMetatileBuffer and Sint32.
Definition at line 415 of file field_terrain.c.
fdMapGridCheckCollision
Sint32 fdMapGridCheckCollision(ACTOR *actor, FIELD_POS *pos)
Returns whether an actor can step to position, a COLLISION: whether the
metatile there is a wall, or the ground too high or too low for a step from
the actor's.
References MapGridTerrainHeightFunctions and Sint32.
Referenced by fdActorScriptWanderNearHome(), fdActorUpdatePlayerControl(), fdActorWander() and scFieldActorCheckMovementCollision().
Definition at line 429 of file field_terrain.c.
fdMapGridIsWallAt
Sint32 fdMapGridIsWallAt(WORLD_POS *pos)
Returns -1 when the metatile under position (its x, and y less its height) in
MAPGRID_LAYER_OVERHEAD is a wall (METATILE_BEHAVIOR_WALL), else 0; also 0
before the map state exists.
References Sint32.
Referenced by fdActorMoveByKeys().
Definition at line 485 of file field_terrain.c.
fdWorldMapGetCollision
Sint32 fdWorldMapGetCollision(WORLD_POS *pos)
Returns the world map's collision value (1-15) at position: from the upper
collision layer where it has one, else the lower, else
WORLD_MAP_COLLISION_DEFAULT.
References Sint32.
Referenced by fdActorMoveOnWorldMap(), fdWorldMapGetBattleEnvironment() and fdWorldMapIsWalkable().
Definition at line 532 of file field_terrain.c.
fdWorldMapIsWalkable
Sint32 fdWorldMapIsWalkable(Sint32 unused, WORLD_POS *pos)
Returns 0 when the world map at position can be walked on (collision
WORLD_MAP_COLLISION_WALKABLE_FIRST to WORLD_MAP_COLLISION_WALKABLE_LAST),
else -1.
References fdWorldMapGetCollision() and Sint32.
Referenced by fdActorMoveOnWorldMap().
Definition at line 585 of file field_terrain.c.
fdWorldMapGetBattleEnvironment
Sint32 fdWorldMapGetBattleEnvironment(WORLD_POS *pos, Sint32 *region)
Returns the world map's battle environment at position from
WorldMapBattleEnvironments, and stores the block's encounter region in
*region.
References fdWorldMapGetCollision(), MetatileTiles, Sint32 and WorldMapBattleEnvironments.
Definition at line 600 of file field_terrain.c.