Skip to Content
The Alchemy Project

src/field/script_commands_map_screen.c

The map screen R shows on the World Map: its area markers, the cursor and the name of the area nearest it. More…

Included by script_commands.c.

Structures

NameDescription
structMAP_SCREEN_STATEThe map screen's state while fdMapScreenShow owns MapGridMetatileBuffer.

Macros

NameDescription
#defineMAP_SCREEN_MARKER_TILES 4The generated marker pictures: four 16-colour 8 by 8 tiles, 32 bytes each.
#defineMAP_SCREEN_MARKER_TILE_BYTES (MAP_SCREEN_MARKER_TILES * TILE_SIZE_4BPP)
#defineMAP_SCREEN_MARKER_ROW (p0, p1, p2, p3, p4)The first five of a marker tile row's eight 4-bit pixels, the leftmost in the low bits; the rest are 0.
#defineMAP_SCREEN_AREA_MARKER_TILE (row) ((row) >> 16)The marker tile a MAP_SCREEN_MARKER row (AREA_MARKER or LIGHTHOUSE_MARKER) holds above its flag in its first word.
#defineMAP_SCREEN_WIDTH 240The image's width and height, the screen's.
#defineMAP_SCREEN_HEIGHT 160
#defineMAP_SCREEN_PALETTE_BYTES (14 * PALETTE_COLORS * 2)The image resource: its 14 palettes of BG colours, then its pixels.
#defineWORLD_MAP_WORLD_SIZE 4096The World Map's size in field pixels each way, which the image shows at 240 by 160.
#defineWORLD_MAP_X_ORIGIN toFIXED(4096)Field x of the image's left edge.
#defineWORLD_MAP_FIRST_AREA_ACTOR 11The first ordinary area actor, the first slot with a row of MapScreenAreaMarkers whatever the leader is.
#defineMAP_SCREEN_MARKER_CAPACITY 66One marker per actor slot.
#defineMAP_SCREEN_CURSOR_PART MAP_SCREEN_MARKER_CAPACITYThe cursor's sprite entry, after the markers'.
#defineMAP_SCREEN_CURSOR_DEPTH (OAM_DEPTH_WINDOW + 6)The cursor's depth slot, among the windows' and in front of every marker, whose slot is its y on the image.
#defineMAP_SCREEN_CURSOR_MIN_SPEED toFIXED(1)Cursor speed limits, in screen pixels a tick.
#defineMAP_SCREEN_CURSOR_MAX_SPEED toFIXED(6)
#defineMAP_SCREEN_CURSOR_ACCELERATION (toFIXED(1) / 8)Added to the cursor's speed each tick the d-pad is held.
#defineMAP_SCREEN_MARKER_BLEND_STEPS 32WorldMapMarkerBlendCycle's rows.
#defineMAP_SCREEN_CURSOR_MIN_X 16The cursor's limits, in screen pixels; y goes from 0.
#defineMAP_SCREEN_CURSOR_MAX_X (MAP_SCREEN_WIDTH - 1)
#defineMAP_SCREEN_CURSOR_MAX_Y 141
#defineMAP_SCREEN_MARKER_ALLOCATION_SIZEBUG: the marker tiles' size is reserved in words, though the heap counts bytes, so 128 bytes are written and uploaded from 32; BUGFIX reserves the whole tile buffer.
#defineMAP_SCREEN_CURSOR_SNAPS 1The cursor snaps to the nearest area when the d-pad is released.
#defineMAP_SCREEN_NAME_RANGE
#defineMAP_SCREEN_NAME_LEFT 3how far left of its marker the name goes

Functions

NameDescription
voidfdMapScreenInit (void)Sets up the map screen: the marker tiles and their OAM entries, the cursor where the leader is on the map (or mid-screen when the area is not on it), and the name window.
voidfdMapScreenRelease (void)Closes the map screen: returns its VRAM blocks and removes the name window.
voidfdMapScreenUpdateMarkers (void)Event of the map screen: shows a marker at each area whose flag is set, moves the cursor with the d-pad (to the current area while L or R is held) and shows the name of the marker nearest the cursor.
voidfdMapScreenShow (Sint32 picture)The map screen, shown over the World Map when the player presses R, until A or B closes it; it borrows the map-metatile buffer for its pixels.
voidfdUpdateActorVisibilityBounds (void)On the World Map, shows only the scene's actors within 320 pixels sideways, 600 above and 400 below the camera.
voidfdWorldMapZoomOutWhileLHeld (void)On the World Map, zooms the view out to toFIXED(1) * 8 / 13 while L is held, then back.

Description

The map screen R shows on the World Map: its area markers, the cursor and the name of the area nearest it. Part of script_commands.c.

Macros in detail

MAP_SCREEN_MARKER_TILES

#define MAP_SCREEN_MARKER_TILES 4

The generated marker pictures: four 16-colour 8 by 8 tiles, 32 bytes each.

Definition at line 7 of file script_commands_map_screen.c.

MAP_SCREEN_MARKER_TILE_BYTES

#define MAP_SCREEN_MARKER_TILE_BYTES (MAP_SCREEN_MARKER_TILES * TILE_SIZE_4BPP)

Referenced by fdMapScreenInit().

Definition at line 8 of file script_commands_map_screen.c.

MAP_SCREEN_MARKER_ROW

#define MAP_SCREEN_MARKER_ROW(p0, p1, p2, p3, p4)

The first five of a marker tile row's eight 4-bit pixels, the leftmost in the low bits; the rest are 0.

Referenced by fdMapScreenInit().

Definition at line 11 of file script_commands_map_screen.c.

MAP_SCREEN_AREA_MARKER_TILE

#define MAP_SCREEN_AREA_MARKER_TILE(row) ((row) >> 16)

The marker tile a MAP_SCREEN_MARKER row (AREA_MARKER or LIGHTHOUSE_MARKER) holds above its flag in its first word.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 15 of file script_commands_map_screen.c.

MAP_SCREEN_WIDTH

#define MAP_SCREEN_WIDTH 240

The image's width and height, the screen's.

Referenced by fdMapScreenInit(), fdMapScreenShow() and fdMapScreenUpdateMarkers().

Definition at line 17 of file script_commands_map_screen.c.

MAP_SCREEN_HEIGHT

#define MAP_SCREEN_HEIGHT 160

Referenced by fdMapScreenInit(), fdMapScreenShow() and fdMapScreenUpdateMarkers().

Definition at line 18 of file script_commands_map_screen.c.

MAP_SCREEN_PALETTE_BYTES

#define MAP_SCREEN_PALETTE_BYTES (14 * PALETTE_COLORS * 2)

The image resource: its 14 palettes of BG colours, then its pixels.

Referenced by fdMapScreenShow().

Definition at line 20 of file script_commands_map_screen.c.

WORLD_MAP_WORLD_SIZE

#define WORLD_MAP_WORLD_SIZE 4096

The World Map's size in field pixels each way, which the image shows at 240 by 160.

Referenced by fdMapScreenInit() and fdMapScreenUpdateMarkers().

Definition at line 23 of file script_commands_map_screen.c.

WORLD_MAP_X_ORIGIN

#define WORLD_MAP_X_ORIGIN toFIXED(4096)

Field x of the image's left edge.

Referenced by fdMapScreenInit() and fdMapScreenUpdateMarkers().

Definition at line 25 of file script_commands_map_screen.c.

WORLD_MAP_FIRST_AREA_ACTOR

#define WORLD_MAP_FIRST_AREA_ACTOR 11

The first ordinary area actor, the first slot with a row of MapScreenAreaMarkers whatever the leader is.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 28 of file script_commands_map_screen.c.

MAP_SCREEN_MARKER_CAPACITY

#define MAP_SCREEN_MARKER_CAPACITY 66

One marker per actor slot.

Referenced by fdMapScreenInit(), fdMapScreenUpdateMarkers() and fdUpdateActorVisibilityBounds().

Definition at line 30 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_PART

#define MAP_SCREEN_CURSOR_PART MAP_SCREEN_MARKER_CAPACITY

The cursor's sprite entry, after the markers'.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 32 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_DEPTH

#define MAP_SCREEN_CURSOR_DEPTH (OAM_DEPTH_WINDOW + 6)

The cursor's depth slot, among the windows' and in front of every marker, whose slot is its y on the image.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 35 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_MIN_SPEED

#define MAP_SCREEN_CURSOR_MIN_SPEED toFIXED(1)

Cursor speed limits, in screen pixels a tick.

Referenced by fdMapScreenInit() and fdMapScreenUpdateMarkers().

Definition at line 37 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_MAX_SPEED

#define MAP_SCREEN_CURSOR_MAX_SPEED toFIXED(6)

Referenced by fdMapScreenUpdateMarkers().

Definition at line 38 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_ACCELERATION

#define MAP_SCREEN_CURSOR_ACCELERATION (toFIXED(1) / 8)

Added to the cursor's speed each tick the d-pad is held.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 40 of file script_commands_map_screen.c.

MAP_SCREEN_MARKER_BLEND_STEPS

#define MAP_SCREEN_MARKER_BLEND_STEPS 32

WorldMapMarkerBlendCycle's rows.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 42 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_MIN_X

#define MAP_SCREEN_CURSOR_MIN_X 16

The cursor's limits, in screen pixels; y goes from 0.

Referenced by fdMapScreenUpdateMarkers().

Definition at line 44 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_MAX_X

#define MAP_SCREEN_CURSOR_MAX_X (MAP_SCREEN_WIDTH - 1)

Referenced by fdMapScreenUpdateMarkers().

Definition at line 45 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_MAX_Y

#define MAP_SCREEN_CURSOR_MAX_Y 141

Referenced by fdMapScreenUpdateMarkers().

Definition at line 46 of file script_commands_map_screen.c.

MAP_SCREEN_MARKER_ALLOCATION_SIZE

#define MAP_SCREEN_MARKER_ALLOCATION_SIZE

BUG: the marker tiles' size is reserved in words, though the heap counts bytes, so 128 bytes are written and uploaded from 32; BUGFIX reserves the whole tile buffer.

Referenced by fdMapScreenInit().

Definition at line 51 of file script_commands_map_screen.c.

MAP_SCREEN_CURSOR_SNAPS

#define MAP_SCREEN_CURSOR_SNAPS 1

#define MAP_SCREEN_CURSOR_SNAPS 0

The cursor snaps to the nearest area when the d-pad is released.

Definition at lines 181 and 187 of file script_commands_map_screen.c.

MAP_SCREEN_NAME_RANGE

#define MAP_SCREEN_NAME_RANGE

#define MAP_SCREEN_NAME_RANGE 100

Referenced by fdMapScreenUpdateMarkers().

Definition at lines 182 and 188 of file script_commands_map_screen.c.

MAP_SCREEN_NAME_LEFT

#define MAP_SCREEN_NAME_LEFT 3

#define MAP_SCREEN_NAME_LEFT 1

how far left of its marker the name goes

Referenced by fdMapScreenUpdateMarkers().

Definition at lines 185 and 189 of file script_commands_map_screen.c.

Functions in detail

fdMapScreenInit

void fdMapScreenInit(void)

Sets up the map screen: the marker tiles and their OAM entries, the cursor where the leader is on the map (or mid-screen when the area is not on it), and the name window.

References fdActorGetById(), gmFlagGetStub(), MainRoutineStateWork, MapGridMetatileBuffer, mnPointingHandLoadIntoFreeSlotStub(), mnWindowCreateStub(), Sint32, state, syHeapAllocateEWRAM(), syHeapRelease(), syVRAMCacheFindFreeEntry(), syVRAMCacheLoad() and VramCacheEntries.

Referenced by fdMapScreenShow().

Definition at line 84 of file script_commands_map_screen.c.

fdMapScreenRelease

void fdMapScreenRelease(void)

Closes the map screen: returns its VRAM blocks and removes the name window.

References MapGridMetatileBuffer, mnWindowCloseStub(), state and syVRAMCacheFreeEntry().

Referenced by fdMapScreenShow().

Definition at line 193 of file script_commands_map_screen.c.

fdMapScreenUpdateMarkers

void fdMapScreenUpdateMarkers(void)

Event of the map screen: shows a marker at each area whose flag is set, moves the cursor with the d-pad (to the current area while L or R is held) and shows the name of the marker nearest the cursor.

References fdActorLookup(), fdAreaGetNameIndex(), gmFlagGetStub(), MainRoutineStateWork, MapScreenAreaMarkers, mnTextDrawMessageStub(), mnTextMeasureMessageStub(), mnWindowSpritePrepareForRedrawStub(), PerData, Sint32, state, syAtan(), syOAMAddSpriteAtDepth(), syVectorAddPolarOffset(), TickCount, VramCacheEntries, width, WorldMapCursorDirectionAngles and WorldMapMarkerBlendCycle.

Referenced by fdMapScreenShow().

Definition at line 205 of file script_commands_map_screen.c.

fdMapScreenShow

void fdMapScreenShow(Sint32 picture)

The map screen, shown over the World Map when the player presses R, until A or B closes it; it borrows the map-metatile buffer for its pixels.

References fdMapScreenInit(), fdMapScreenRelease(), fdMapScreenUpdateMarkers(), fdScriptFinishScreenTransition(), fdScriptStartScreenTransition(), fdScriptWaitTransitionTicks(), fdWorldMapLoadAreaGraphicsStub(), gmFlagGetStub(), MapGridMetatileBuffer, mnFieldMessageShowStub(), PerRepeat, Sint32, state, syCloseEvent(), syDecompressTaggedLZ(), syDMAXCopy(), syHeapSlotAllocateEWRAM(), syResourceGetTableEntry(), sySetEvent() and sySynch().

Referenced by fdEngineRun().

Definition at line 463 of file script_commands_map_screen.c.

fdUpdateActorVisibilityBounds

void fdUpdateActorVisibilityBounds(void)

On the World Map, shows only the scene's actors within 320 pixels sideways, 600 above and 400 below the camera.

References fdActorGetById(), fdActorLookup() and MainRoutineStateWork.

Referenced by fdWorldMapZoomOutWhileLHeld().

Definition at line 551 of file script_commands_map_screen.c.

fdWorldMapZoomOutWhileLHeld

void fdWorldMapZoomOutWhileLHeld(void)

On the World Map, zooms the view out to toFIXED(1) * 8 / 13 while L is held, then back.

References fdLeaderStopMoving(), fdUpdateActorVisibilityBounds(), fdWorldMapStartZoom(), PerData, state, syHeapSlotAllocateEWRAM(), syResumeOverlayEvents(), sySuspendOverlayEvents() and sySynch().

Referenced by fdEngineRun().

Definition at line 596 of file script_commands_map_screen.c.