10#define CURVE_HEIGHT_FIXED(sample) ((sample) * (1 << CURVE_VALUE_SHIFT))
12#define CURVE_HEIGHT_FIXED(sample) ((sample) << CURVE_VALUE_SHIFT)
22 const s8 *samples = (
const s8 *)heightBytes;
29 const s8 *samples = (
const s8 *)heightBytes;
36 if (heightDelta < 0) {
39 return startHeight + (heightDelta >> 4);
45 const s8 *samples = (
const s8 *)heightBytes;
52 if (heightDelta < 0) {
55 return startHeight + (heightDelta >> 4);
62 const s8 *samples = (
const s8 *)heightBytes;
70 higherHeight = firstHeight;
71 if (secondHeight > firstHeight) {
72 higherHeight = secondHeight;
80 secondHeight = firstHeight;
89 const s8 *samples = (
const s8 *)heightBytes;
94 u32 biasedDifference = x;
98 higherHeight = firstHeight;
99 if (secondHeight > firstHeight) {
100 higherHeight = secondHeight;
104 pixelDifference = y - biasedDifference;
110 secondHeight = firstHeight;
119 const s8 *samples = (
const s8 *)heightBytes;
133 height = middleHeight;
150 const s8 *samples = (
const s8 *)heightBytes;
159 lastHeight = samples[1];
161 pixelDifference = y - x;
169 heightDelta = middleHeight - firstHeight;
170 pixelDifference = heightDelta * x;
171 if (pixelDifference < 0)
174 pixelDifference >>= 4;
175 return firstHeight + pixelDifference;
178 pixelDifference *= lastHeight - middleHeight;
179 if (pixelDifference < 0)
181 pixelDifference >>= 4;
182 return middleHeight + pixelDifference;
189 const s8 *samples = (
const s8 *)heightBytes;
202 const s8 *samples = (
const s8 *)heightBytes;
206 heightSample = samples[0];
208 heightSample = samples[1];
215 const s8 *samples = (
const s8 *)heightBytes;
219 heightSample = samples[0];
221 heightSample = samples[1];
230 const s8 *samples = (
const s8 *)heightBytes;
241 heightDelta = (middleHeight - endpointHeight) * cellX;
242 if (heightDelta < 0) {
245 return endpointHeight + (heightDelta >> 3);
249 s32 offsetPastMiddle;
252 offsetPastMiddle = cellX;
253 endpointHeight -= middleHeight;
255 heightDelta = endpointHeight * offsetPastMiddle;
256 if (heightDelta < 0) {
259 return middleHeight + (heightDelta >> 3);
268 const u8 *samples = heightBytes;
272 s32 offsetPastMiddle;
280 heightDelta = (middleHeight - endpointHeight) * cellY;
281 if (heightDelta < 0) {
284 return endpointHeight + (heightDelta >> 3);
288 offsetPastMiddle = cellY;
289 endpointHeight -= middleHeight;
291 tailDelta = endpointHeight * offsetPastMiddle;
295 return middleHeight + (tailDelta >> 3);
301 const s8 *samples = (
const s8 *)heightBytes;
313 const s8 *samples = (
const s8 *)heightBytes;
324 const s8 *samples = (
const s8 *)heightBytes;
330 const s8 *samples = (
const s8 *)heightBytes;
334#undef CURVE_HEIGHT_FIXED
357 cell += x / 16 + (y / 16 << 7);
362 u32 kind = *heightBytes++ & 15;
381 u32 heightAttributeIndex;
391 cells += cellX + (cellY << 7);
413 cell += x + (y << 7);
431 cell += x + (y << 7);
467 if (mapState ==
NULL)
475 cell += pixelX / 16 + (pixelZ / 16 << 7);
483 u32 kind = *heightBytes++ & 15;
490 heightBytes, pixelX & 15, pixelZ & 15);
493 stepHeight = targetGround -
object->terrainHeight;
494 if (stepHeight > 0x80000)
496 if (stepHeight < -0xc0000)
514 pixelX = position->
x / 65536;
516 pixelY = (position->
y - position->
height) / 65536;
518 if (mapState ==
NULL)
524 cell += cellX + cellY * 128;
536 s32 halfPixelX = position->
x >> 17;
538 s32 halfPixelY = y >> 17;
548 collisionCell = (((halfPixelY / 8) & 63) << 6) + ((halfPixelX / 8) & 63);
549 pixelOffset = (((halfPixelY / 2) & 3) << 1) + ((halfPixelX / 4) & 1);
556 if (packedCollisions != 0) {
558 result = packedCollisions >> 4;
560 result = packedCollisions & 15;
567 packedCollisions = *(
Ram_MapCollision + (collisionTile << 3) + pixelOffset);
568 if (packedCollisions != 0) {
570 result = packedCollisions >> 4;
572 result = packedCollisions & 15;
604 s32 behaviorBank = 0;
613 blockX = (x >> 21) & 31;
618 index = blockX + (((y >> 21) & 31) << 5);
622 if (((
u8 *)blockWord)[3] & 0x80)
626 *terrainKind = (*blockWord << 1) >> 25;
627 if (*terrainKind == 21)
@ CURVE_FULL_STEPS
pixels across a cell
@ CURVE_HALF_STEPS
pixels to the middle of a 16-pixel cell
const u8 gCurve_LerpWeightTable[256]
Height-curve tables, indexed by (row << 4) + column within a 16x16 cell.
const u8 gCurve_SampleIndexTable[256]
The sample Curve_LookupSampleByTable reads at each position: 0, 1 or 2, split along two diagonals.
What every part of the field object shares: its includes and the few names more than one part uses.
struct EffectStep gMapCellBuffer[]
Map cells; battle effects reuse this as a particle array.
#define BG_SCREEN_BLOCK(n)
const TerrainHeightFn gMap_TerrainHeightFunctions[16]
Terrain height functions, chosen by the low four bits of a cell's first collision byte and called wit...
const u8 gWorldMap_TerrainBehaviorTable[48]
World map terrain behaviour, indexed by the collision value plus 0x10 when the block word's top bit i...
#define Ram_MapCellBuffer
s32 z
16.16 fixed-point pixels
One cell of a map layer: its metatile and flags, its collision code and an attribute indexing the col...
u8 attributeB
Indexes the 4-byte collision entries (gMapCollision): terrain kind in the first byte's low four bits,...
u16 metatileAndFlags
bits: 15..12 flags (15..14 read by Map_GetCellHighFlags) | 11..0 metatile
u8 collisionCode
The step code: 1 to 239 scene events, 240 and 241 encounter ground, 250 hazard, 252 to 254 for Field_...
struct MapCell * cells
the layer's first cell (MapLayerScroll's cells)
The map work in heap slot 8 (struct MapScrollWork), seen as its tile animation channels,...
struct MapLayer layers[4]
Each layer's cells, at MapScrollWork's layers[i].cells; readers mask the layer with 3,...
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
u8 terrainId
the map layer its ground height is read from
A position on the world map, as its walkability check reads it.
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
s32 height
16.16 fixed-point pixels
s32 Curve_LerpTwoSamplesByTable(const u8 *heightBytes, s32 x, s32 y)
A raised or sunken rounded square: sample 1 where gCurve_LerpWeightTable is 1, sample 0 in the corner...
s32 Curve_LerpTwoSamplesB(const u8 *heightBytes, s32 pixelX, s32 pixelY)
A slope along y: from sample 0 at y = 0 towards sample 1 at y = 16.
s32 Curve_GetFirstSampleB(const u8 *heightBytes, s32 pixelX, s32 pixelY)
Flat, as Curve_GetFirstSampleA. Kind 14.
s32 Map_CheckObjectStep(struct ObjectRuntime *object, struct FieldPosition *position)
Returns whether an object can step to position: 2 when the cell there is a wall (collision code 0xff)...
s32 Curve_LookupSampleByTableReversed(const u8 *heightBytes, s32 pixelX, s32 pixelY)
The same, with the table mirrored left to right.
s32 Map_GetCellAttributeLowNibble(s32 layer, s32 x, s32 y)
Returns the terrain kind (the low four bits of the first collision byte) of a layer's cell at (x,...
s32 Curve_StepAtSummedPosition(const u8 *heightBytes, s32 x, s32 y)
A step across the diagonal x + y = 15: sample 0 before it, sample 1 after it and the higher of the tw...
s32 CheckWorldMapWalkable(s32 unused, struct WorldPosition *position)
Returns 0 when the world map at position can be walked on (collision 5 to 12), else -1.
s32 Curve_GetFirstSampleC(const u8 *heightBytes, s32 pixelX, s32 pixelY)
Flat, as Curve_GetFirstSampleA. Kind 15.
s32 Curve_LerpTwoSamples(const u8 *heightBytes, s32 pixelX, s32 pixelY)
A slope along x: from sample 0 at x = 0 towards sample 1 at x = 16.
UNUSED s32 Map_GetCellHighFlags(s32 x, s32 y)
Returns the top two bits of the block word of the cell at pixel (x, y).
s32 GetWorldMapCollision(struct WorldPosition *position)
Returns the world map's collision value (1-15) at position: from the upper collision layer where it h...
s32 Curve_StepAtHalfB(const u8 *heightBytes, s32 pixelX, s32 pixelY)
A step along y: sample 0 for y < 8, sample 1 from y = 8.
s32 Curve_LookupSampleByTable(const u8 *heightBytes, s32 pixelX, s32 pixelY)
The sample gCurve_SampleIndexTable picks for (x, y).
s32 Curve_GetFirstSampleA(const u8 *heightBytes, s32 pixelX, s32 pixelY)
The terrain height functions (gMap_TerrainHeightFunctions): each takes a cell's height samples after ...
s32 GetWorldMapTerrainBehavior(struct WorldPosition *position, s32 *terrainKind)
Returns the world map's terrain behaviour at position from gWorldMap_TerrainBehaviorTable,...
s32 Curve_LerpThreeSamplesAtHalf(const u8 *heightBytes, s32 pixelX, s32 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...
s32 Curve_StepAtHalf(const u8 *heightBytes, s32 pixelX, s32 pixelY)
A step along x: sample 0 for x < 8, sample 1 from x = 8.
s32 CheckMapPositionCellOccupied(struct WorldPosition *position)
Returns 0 when the cell under position (its x, and y less its height) in layer 2 is a wall (collision...
s32 Curve_StepAtDifferencePosition(const u8 *heightBytes, s32 x, s32 y)
A step across the diagonal x = y: sample 0 where y < x, sample 1 where y > x and the higher of the tw...
s32 GetMapCellCollision(s32 layer, s32 x, s32 y)
Returns the collision code of a layer's cell at (x, y) in 16.16 pixels.
#define CURVE_HEIGHT_FIXED(sample)
s32 Curve_LerpThreeSamplesAtDifference(const u8 *heightBytes, s32 x, s32 y)
A slope that bends on the diagonal x = y: from sample 0 at the top right corner to sample 1 on the di...
s32 Curve_LerpThreeSamplesByRatio(const u8 *heightBytes, s32 x, s32 y)
A slope that bends on the diagonal x + y = 15: from sample 0 at the top left corner to sample 1 on th...
void SetMapCellCollision(u32 layer, s32 x, s32 y, u32 collisionCode)
Sets the collision code of a layer's cell at (x, y) in 16.16 pixels.
s32 Curve_LerpThreeSamplesAtHalfB(const u8 *heightBytes, s32 pixelX, s32 pixelY)
A slope along y that bends at the middle, as kind 10 does along x.
s32 Map_GetTerrainHeight(s32 layer, s32 x, s32 y)
Returns the ground height of a layer at (x, y) in 16.16 pixels: the height function of the cell's ter...
A field coordinate, read whole or as its fraction and its whole pixels.
struct FieldCoordinate::@024321007066302143002254325121164243234242211074 part