Skip to Content
The Alchemy Project

src/field/map_grid_data.c

Map ground: the height function of each metatile kind, the world map's battle environments and the sprite viewer's small tables after them; then the actor scripts the field starts by itself, the actor script command table and the work value handlers. More…

Macros

NameDescription
#defineENV (name) BATTLE_ENVIRONMENT_##nameENV(name) is BATTLE_ENVIRONMENT_name, to keep each row's sixteen short.

Typedefs

NameDescription
typedef Sint32 (*TERRAIN_HEIGHT_FN )();Each height function reads only the arguments it needs, so the type leaves them unspecified.

Functions

NameDescription
FIXEDfdTerrainGetStepDifferenceDiagonalHeight ()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.
FIXEDfdTerrainGetBendSumDiagonalHeight ()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.
FIXEDfdTerrainGetBendDifferenceDiagonalHeight ()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.
FIXEDfdTerrainGetRoundedSquareHeight ()A raised or sunken rounded square: sample 1 where TerrainRoundedSquareMask is 1, sample 0 in the corners.
FIXEDfdTerrainGetStepXHeight ()The height of a step across x at position (0 to 15 of the metatile): samples[0] on the metatile's first half, samples[1] on its second.
FIXEDfdTerrainGetStepYHeight ()A step along y: sample 0 above the middle, sample 1 below it.
FIXEDfdTerrainGetSampleTableTransposedHeight ()As fdTerrainGetSampleTableHeight with x and y swapped.
FIXEDfdTerrainGetSampleTableTransposedMirroredHeight ()As fdTerrainGetSampleTableMirroredHeight with x and y swapped.
FIXEDfdTerrainGetSampleTableMirroredHeight ()The same, with the table mirrored left to right.
FIXEDfdTerrainGetSplitTopStepHeight ()Above y 8 a step along x from the first sample to the second; below, the third.
FIXEDfdTerrainGetSplitBottomStepHeight ()Above y 8 the first sample; below, a step along x from the second to the third.
Sint32fdActorScriptWait ()SC_WAIT(n): waits n ticks; this tick counts as the first.
BoolfdActorScriptWaitForArrival ()SC_SYNC: waits until the actor arrives at its target, or until a solid actor has blocked it for SCRIPT_BLOCKED_MOVE_TICKS ticks (refused is the blocked count, which fdActorUpdateAllOnField raises), when its target is cleared.
Sint32fdActorScriptSetPosAndResetMotion ()SC_POSITION(x, y, z): places the actor at (x, y, z) and stops it; with y -1 an actor that follows the ground is raised by the ground height there.
Sint32fdActorScriptResetToOrigin ()SC_POSITION_ORIGIN: puts the actor at x and z 0, keeping its height, with no destination or speed; one that follows the ground then takes the ground height there.
Sint32fdActorScriptMove ()SC_MOVE(x, y, z): sends the actor towards (x, y, z).
Sint32fdActorScriptMoveBy ()SC_MOVE_BY(x, y, z): sends the actor towards its position plus (x, y, z).
Sint32fdActorScriptFaceWatched ()SC_FACE_WATCHED: turns the actor to face its watched actor, on the ground plane (x and z).
Sint32fdActorScriptMoveToWatched ()SC_MOVE_TO_WATCHED: sends the actor towards its watched actor.
Sint32fdActorScriptMoveLocal ()SC_MOVE_LOCAL(a, b): sends the actor towards its position plus an offset that is never filled in; the operands are skipped unread.
BoolfdActorWander ()SC_WANDER(base, range, limit): walks to a random point base to base + range away, within SCRIPT_WANDER_SIDE_ANGLE either side of its facing, that no solid actor or wall blocks, with clear ground SCRIPT_WANDER_PROBE_DISTANCE further at SCRIPT_WANDER_DIAGONAL_ANGLE either side, and within limit pixels of home.
Sint32fdActorScriptWanderNearHome ()SC_WANDER_HOME(base, range, limit): wanders as SC_WANDER does, testing more ground around the point, while it is within limit pixels of home; outside that, or when no point works, it heads back towards home.
BoolfdActorApproachWatchedActor ()SC_APPROACH_WATCHED: follows the watched actor at its speed.
Sint32fdCameraFollowLeaderInBounds ()SC_CAMERA: keeps the camera actor on its leader (watchedActor), clamped so the view stays on the map, and pushed out of the map's camera boxes, which the view may not show.
Sint32fdActorScriptRepeatOrJump ()SC_LOOP(n, to): jumps to label to until it has done so n - 1 times, then moves on; with n = SC_FOREVER it always jumps.
Sint32fdActorScriptJumpToLabel ()SC_JUMP(to): jumps to label to.
Uint32fdActorScriptJumpIfTrue ()SC_IF(to): jumps to label to when the last test was true.
Uint32fdActorScriptJumpIfFalse ()SC_IFNOT(to): jumps to label to when the last test was false.
Sint32fdActorScriptEnd ()SC_END: hands the actor back to the idle script, ActorScriptIdleScript, whose lone SC_END runs again each tick.
Sint32fdActorScriptTestFlag ()SC_FLAG_CHECK(f): tests game flag f.
Sint32fdActorScriptSetFlagAndTest ()SC_FLAG_ON(f): tests game flag f, then sets it.
Sint32fdActorScriptClearFlagAndTest ()SC_FLAG_OFF(f): tests game flag f, then clears it.
Sint32fdActorScriptToggleFlagAndTest ()SC_FLAG_REV(f): tests game flag f, then flips it.
Sint32fdActorScriptApplyOperandSet ()SC_SET(w, v): sets work value w to v.
Sint32fdActorScriptApplyOperandAdd ()SC_ADD(w, v): adds v to work value w.
Sint32fdActorScriptApplyOperandCompare ()SC_CMP(w, v): tests whether work value w equals v.
Sint32fdActorUpdatePlayerControl ()SC_PLAYER: moves the player on the field by the direction pad: walking or running, sliding around walls, pushing movable actors, turning, playing the matching animation and leaving footprints.
Sint32fdActorMoveOnWorldMap ()SC_WORLD: moves the player on the world map by the direction pad, as SC_PLAYER does on the field, and turns the world map camera with the pad.
Sint32fdActorMoveByKeys ()SC_KEYS (LEADER_MOVEMENT_KEYS), the leader's control on a climbable wall: moves it 8 pixels at a time by the direction pad, up and down changing its height rather than its depth, reaching east or west as it goes and clinging while the pad is not held.
Sint32fdActorCrossRope ()SC_ROPE (LEADER_MOVEMENT_ROPE), the leader crossing a tied rope hand over hand: the pad moves him from node to node along it, a half metatile a step, and sets the rope swinging.
Sint32fdActorCrossTightrope ()SC_TIGHTROPE (LEADER_MOVEMENT_TIGHTROPE): fdActorCrossRope on a tightrope, which the leader walks, the rope wobbling under him.
Sint32fdActorMoveAsSand ()SC_SAND (LEADER_MOVEMENT_SAND): the leader turned to sand by the Sand Psynergy, moved by the direction pad on a field map, leaving puffs of sand; up against a face, or down at a drop, he climbs it as sand.
Sint32fdActorSailOnMap ()SC_SAIL (LEADER_MOVEMENT_SHIP_ON_MAP): the ship moved by the direction pad on a field map, as the party's actor (MainRoutineStateWork.ownerOverride), as at Lemuria's entrance; A leaves the ship.
Sint32fdActorSailOnWorldMap ()SC_WORLD_SAIL (LEADER_MOVEMENT_SHIP): the ship sailing the world map.
Sint32fdActorFlyOnWorldMap ()SC_WORLD_FLY (LEADER_MOVEMENT_FLYING_SHIP): the ship with its wings on the world map, flying over the ground the sea alone would stop (fdWorldMapIsFlyable).
Sint32fdActorMoveAsSandOnWorldMap ()SC_WORLD_SAND (LEADER_MOVEMENT_WORLD_SAND): the leader as sand on the world map (the Sand Psynergy).
BoolfdActorUpdateHoverControl ()SC_HOVER: the leader hovering (the Hover Psynergy), moved by the direction pad over what lies below.
Sint32fdActorUpdateWalkingControl ()SC_WALK (LEADER_MOVEMENT_WALKING): the leader's control at one pace, a pixel a tick whatever the keys.
Sint32fdActorScriptCheckKeys ()SC_CHECK_KEYS: checks the configured keys (fdCheckConfiguredKeys) and steps the script on.
Sint32fdActorScriptRelease ()SC_RELEASE: releases the actor through fdActorRelease, which releases its sprites and zeroes its slot.
Sint32fdActorScriptSetAnimation ()SC_ANIMATION(v): switches the actor's sprites to animation v.
Sint32fdActorScriptNoOperation ()SC_NOP(v): does nothing with its operand.
Sint32fdActorScriptPlaySound ()SC_SE(n): sends sound command n.
Sint32fdActorScriptPlaySoundInView ()SC_SE_IN_VIEW(n): plays sound n when the actor is in view of the camera (fdActorPlaySoundInView).
BoolfdActorScriptInvokeCallback ()SC_CALL(fn): calls fn with the actor.
Sint32fdCameraFollowWatchedInBounds ()SC_CAMERA_IN_BOUNDS: as SC_CAMERA, clamped to the map alone, without its camera boxes.
Sint32fdActorScriptMoveXZ ()SC_MOVE_XZ(x, z): sends the actor towards (x, z), keeping its height.

Variables

NameDescription
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).
const Uint8WorldMapTerrainBehaviorTable [80]The world map's battle environments, sixteen by collision value in each set of rows (fdWorldMapGetBattleEnvironment): the plain rows; the beach rows for a metatile with its beach bit; the snowfield rows for the encounter regions from SNOWFIELD_REGION_FIRST; the desert rows for the regions round Air's Rock and north of Shaman Village; the blizzard rows for the region round Prox.
const Uint16SpriteViewerBackdropColors [8]The sprite viewer's backdrops, which B steps through: black, blue, green, red, dark grey, grey, white and dark red.
const Uint16SpriteViewerSkipStops [10]The sprite ids the sprite viewer's fast step (Start held with L or R) stops at, the first of each group of sprites: a skip forward goes to the next stop above the sprite shown, back to the last stop below it.
const Sint8WorldMapDirectionOffsets [8][2]Unused: nothing refers to it.
const Uint32WorldMapUnitScale [2]Unused: nothing refers to it.
const SPR_SCALESpriteViewerScaleThe sprite viewer's scale for its ring of copies: full size.
const Sint32ActorKeyCheckScript []Each runs one control command every tick: the command, SC_WAIT(1), SC_LOOP(SC_FOREVER, SC_TOP).
const Sint32ActorKeysScript []Climbing by the keys (fdActorMoveByKeys).
const Sint32ActorRopeScript []Crossing a tied rope (fdActorCrossRope).
const Sint32ActorTightropeScript []Crossing a tightrope (fdActorCrossTightrope).
const Sint32ActorSandScript []Moving as sand (fdActorMoveAsSand).
const Sint32ActorHoverScript []Hovering (fdActorUpdateHoverControl).
const Sint32ActorWalkingScript []Walking (fdActorUpdateWalkingControl).
const Sint32ActorPlayerScript []The leader on foot (fdActorUpdatePlayerControl).
const Sint32ActorWorldMapScript []The leader on the World Map (fdActorMoveOnWorldMap).
const Sint32ActorSailOnMapScript []Sailing on a map (fdActorSailOnMap).
const Sint32ActorSailScript []Sailing on the World Map (fdActorSailOnWorldMap).
const Sint32ActorFlyScript []Flying on the World Map (fdActorFlyOnWorldMap).
const Sint32ActorSandOnWorldMapScript []Moving as sand on the World Map (fdActorMoveAsSandOnWorldMap).
const Sint32ActorCameraScript []The camera following the leader within the map's bounds (fdCameraFollowLeaderInBounds).
const Sint32ActorApproachWatchedScript []Following the watched actor (fdActorApproachWatchedActor).
const Sint32ActorScriptEndScript []A script that ends at once.
const SCRIPT_COMMAND_FNActorScriptCommandTable [54]The handler of each command.
const OPERAND_FUNCActorScriptOperandHandlerTable [41]The handler of each work value (ACTOR_SCRIPT_VALUE in actor_script.h).

Description

Map ground: the height function of each metatile kind, the world map's battle environments and the sprite viewer's small tables after them; then the actor scripts the field starts by itself, the actor script command table and the work value handlers. Each map's resources follow in map/resources.s.

Macros in detail

ENV

#define ENV(name) BATTLE_ENVIRONMENT_##name

ENV(name) is BATTLE_ENVIRONMENT_name, to keep each row's sixteen short.

Referenced by WorldMapTerrainBehaviorTable.

Definition at line 58 of file map_grid_data.c.

Typedefs in detail

TERRAIN_HEIGHT_FN

typedef Sint32 (*TERRAIN_HEIGHT_FN)();

Each height function reads only the arguments it needs, so the type leaves them unspecified.

Referenced by MapGridTerrainHeightFunctions.

Definition at line 17 of file map_grid_data.c.

Variables in detail

MapGridTerrainHeightFunctions

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). Each reads only the arguments it needs.

References fdTerrainGetBendDifferenceDiagonalHeight(), fdTerrainGetBendSumDiagonalHeight(), fdTerrainGetFlatHeight(), fdTerrainGetRoundedSquareHeight(), fdTerrainGetSampleTableHeight(), fdTerrainGetSampleTableMirroredHeight(), fdTerrainGetSampleTableTransposedHeight(), fdTerrainGetSampleTableTransposedMirroredHeight(), fdTerrainGetSlopeXHeight(), fdTerrainGetSlopeYHeight(), fdTerrainGetSplitBottomStepHeight(), fdTerrainGetSplitTopStepHeight(), fdTerrainGetStepDifferenceDiagonalHeight(), fdTerrainGetStepSumDiagonalHeight(), fdTerrainGetStepXHeight() and fdTerrainGetStepYHeight().

Definition at line 34 of file map_grid_data.c.

WorldMapTerrainBehaviorTable

const Uint8 WorldMapTerrainBehaviorTable[80]

The world map's battle environments, sixteen by collision value in each set of rows (fdWorldMapGetBattleEnvironment): the plain rows; the beach rows for a metatile with its beach bit; the snowfield rows for the encounter regions from SNOWFIELD_REGION_FIRST; the desert rows for the regions round Air's Rock and north of Shaman Village; the blizzard rows for the region round Prox.

Referenced by fdWorldMapGetBattleEnvironment().

Definition at line 64 of file map_grid_data.c.

SpriteViewerBackdropColors

const Uint16 SpriteViewerBackdropColors[8]

The sprite viewer's backdrops, which B steps through: black, blue, green, red, dark grey, grey, white and dark red.

Referenced by fdSpriteViewerRun().

Definition at line 92 of file map_grid_data.c.

SpriteViewerSkipStops

const Uint16 SpriteViewerSkipStops[10]

The sprite ids the sprite viewer's fast step (Start held with L or R) stops at, the first of each group of sprites: a skip forward goes to the next stop above the sprite shown, back to the last stop below it. (Uint16)-1 ends the list.

Referenced by fdSpriteViewerStepSpriteId().

Definition at line 101 of file map_grid_data.c.

WorldMapDirectionOffsets

const Sint8 WorldMapDirectionOffsets[8][2]

Unused: nothing refers to it. Eight directions at a radius of 40 (x, y).

Definition at line 116 of file map_grid_data.c.

WorldMapUnitScale

const Uint32 WorldMapUnitScale[2]

Unused: nothing refers to it. A scale of 1 on both axes (16.16).

Definition at line 128 of file map_grid_data.c.

SpriteViewerScale

const SPR_SCALE SpriteViewerScale

The sprite viewer's scale for its ring of copies: full size.

Referenced by fdSpriteViewerPlaceRing().

Definition at line 134 of file map_grid_data.c.

ActorKeyCheckScript

const Sint32 ActorKeyCheckScript[]

Each runs one control command every tick: the command, SC_WAIT(1), SC_LOOP(SC_FOREVER, SC_TOP). The first checks the configured keys (fdActorScriptCheckKeys).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 189 of file map_grid_data.c.

ActorKeysScript

const Sint32 ActorKeysScript[]

Climbing by the keys (fdActorMoveByKeys).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 196 of file map_grid_data.c.

ActorRopeScript

const Sint32 ActorRopeScript[]

Crossing a tied rope (fdActorCrossRope).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 203 of file map_grid_data.c.

ActorTightropeScript

const Sint32 ActorTightropeScript[]

Crossing a tightrope (fdActorCrossTightrope).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 210 of file map_grid_data.c.

ActorSandScript

const Sint32 ActorSandScript[]

Moving as sand (fdActorMoveAsSand).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 217 of file map_grid_data.c.

ActorHoverScript

const Sint32 ActorHoverScript[]

Hovering (fdActorUpdateHoverControl).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 224 of file map_grid_data.c.

ActorWalkingScript

const Sint32 ActorWalkingScript[]

Walking (fdActorUpdateWalkingControl).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 231 of file map_grid_data.c.

ActorPlayerScript

const Sint32 ActorPlayerScript[]

The leader on foot (fdActorUpdatePlayerControl).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 238 of file map_grid_data.c.

ActorWorldMapScript

const Sint32 ActorWorldMapScript[]

The leader on the World Map (fdActorMoveOnWorldMap).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 245 of file map_grid_data.c.

ActorSailOnMapScript

const Sint32 ActorSailOnMapScript[]

Sailing on a map (fdActorSailOnMap).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 252 of file map_grid_data.c.

ActorSailScript

const Sint32 ActorSailScript[]

Sailing on the World Map (fdActorSailOnWorldMap).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 259 of file map_grid_data.c.

ActorFlyScript

const Sint32 ActorFlyScript[]

Flying on the World Map (fdActorFlyOnWorldMap).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 266 of file map_grid_data.c.

ActorSandOnWorldMapScript

const Sint32 ActorSandOnWorldMapScript[]

Moving as sand on the World Map (fdActorMoveAsSandOnWorldMap).

References Sint32.

Referenced by fdActorStartMovementModeScript().

Definition at line 273 of file map_grid_data.c.

ActorCameraScript

const Sint32 ActorCameraScript[]

The camera following the leader within the map's bounds (fdCameraFollowLeaderInBounds).

References Sint32.

Referenced by fdActorStartCamera().

Definition at line 281 of file map_grid_data.c.

ActorApproachWatchedScript

const Sint32 ActorApproachWatchedScript[]

Following the watched actor (fdActorApproachWatchedActor).

References Sint32.

Referenced by fdActorStartApproachWatched().

Definition at line 288 of file map_grid_data.c.

ActorScriptEndScript

const Sint32 ActorScriptEndScript[]

A script that ends at once.

References Sint32.

Referenced by fdActorCreate(), fdActorStartIdle() and fdActorStartMovementModeScript().

Definition at line 295 of file map_grid_data.c.

ActorScriptCommandTable

const SCRIPT_COMMAND_FN ActorScriptCommandTable[54]

The handler of each command. 0x31 to 0x35 repeat SC_END's.

References fdActorApproachWatchedActor(), fdActorCrossRope(), fdActorCrossTightrope(), fdActorFlyOnWorldMap(), fdActorMoveAsSand(), fdActorMoveAsSandOnWorldMap(), fdActorMoveByKeys(), fdActorMoveOnWorldMap(), fdActorSailOnMap(), fdActorSailOnWorldMap(), fdActorScriptApplyOperandAdd(), fdActorScriptApplyOperandCompare(), fdActorScriptApplyOperandSet(), fdActorScriptCheckKeys(), fdActorScriptClearFlagAndTest(), fdActorScriptEnd(), fdActorScriptFaceWatched(), fdActorScriptGoto(), fdActorScriptHideSprites(), fdActorScriptInvokeCallback(), fdActorScriptJumpIfFalse(), fdActorScriptJumpIfTrue(), fdActorScriptJumpToLabel(), fdActorScriptMove(), fdActorScriptMoveBy(), fdActorScriptMoveLocal(), fdActorScriptMoveToWatched(), fdActorScriptMoveXZ(), fdActorScriptNoOperation(), fdActorScriptPlaySound(), fdActorScriptPlaySoundInView(), fdActorScriptRelease(), fdActorScriptRepeatOrJump(), fdActorScriptResetToOrigin(), fdActorScriptSetAnimation(), fdActorScriptSetFlagAndTest(), fdActorScriptSetPosAndResetMotion(), fdActorScriptShowSprite(), fdActorScriptTestFlag(), fdActorScriptToggleFlagAndTest(), fdActorScriptWait(), fdActorScriptWaitForArrival(), fdActorScriptWanderNearHome(), fdActorUpdateHoverControl(), fdActorUpdatePlayerControl(), fdActorUpdateWalkingControl(), fdActorWander(), fdCameraFollowLeaderInBounds() and fdCameraFollowWatchedInBounds().

Referenced by fdActorUpdateAllOnField().

Definition at line 300 of file map_grid_data.c.

ActorScriptOperandHandlerTable

const OPERAND_FUNC ActorScriptOperandHandlerTable[41]

The handler of each work value (ACTOR_SCRIPT_VALUE in actor_script.h).

References fdActorScriptSetOrCompareAcceleration(), fdActorScriptSetOrCompareArrivalAxis(), fdActorScriptSetOrCompareBounce(), fdActorScriptSetOrCompareCollisionFlags(), fdActorScriptSetOrCompareConditionResult(), fdActorScriptSetOrCompareCursor(), fdActorScriptSetOrCompareFacing(), fdActorScriptSetOrCompareGravity(), fdActorScriptSetOrCompareMotionFlags(), fdActorScriptSetOrComparePaused(), fdActorScriptSetOrCompareRadius(), fdActorScriptSetOrCompareRepeatCount(), fdActorScriptSetOrCompareScaleX(), fdActorScriptSetOrCompareScaleY(), fdActorScriptSetOrCompareSceneByte(), fdActorScriptSetOrCompareSceneCount(), fdActorScriptSetOrCompareSceneWord(), fdActorScriptSetOrCompareScriptAddress(), fdActorScriptSetOrCompareSnapToTarget(), fdActorScriptSetOrCompareSpeedLimit(), fdActorScriptSetOrCompareSprite(), fdActorScriptSetOrCompareSpriteStorageKind(), fdActorScriptSetOrCompareSteeringFlags(), fdActorScriptSetOrCompareTargetX(), fdActorScriptSetOrCompareTargetY(), fdActorScriptSetOrCompareTargetZ(), fdActorScriptSetOrCompareTerrainHeight(), fdActorScriptSetOrCompareTimer(), fdActorScriptSetOrCompareUpdateAddress(), fdActorScriptSetOrCompareUserValue(), fdActorScriptSetOrCompareVelocityX(), fdActorScriptSetOrCompareVelocityY(), fdActorScriptSetOrCompareVelocityZ(), fdActorScriptSetOrCompareWait(), fdActorScriptSetOrCompareWatchedActor(), fdActorScriptSetOrCompareX(), fdActorScriptSetOrCompareY() and fdActorScriptSetOrCompareZ().

Referenced by fdActorScriptApplyOperandCommand().

Definition at line 358 of file map_grid_data.c.