Alchemy
Loading...
Searching...
No Matches

player_control.c File Reference

Player control: the configured keys and moving objects by the pad. More...

Go to the source code of this file.

Macros

#define FIELD_SHORTCUT_KEYS   gKeysPressed
#define WORLD_MAP_PROBE_RADIUS   0x70000

Functions

static __inline__ void Field_StoreHalfword (s16 *address, s32 value)
 Stores value in a halfword of the event work.
UNUSED void ObjectDispatch_SetUpdateValue (void *rawObject, s32 value)
 Stores value as a word at the object's unk6c.
u32 Field_RequestShortcut (u32 encodedAssignment)
 Handles a shortcut key's assignment: its top two bits choose what it requests (0 Psynergy, 1 an item) and the low 14 bits which one.
s32 Field_CheckConfiguredKeys (void)
 Checks the keys the player has configured: Select, A and Start set their flag in the event work and return 1; the two shortcut keys pass on their assignment (Field_RequestShortcut).
s32 Runtime_CheckRadiusOverlap (s32 *firstPosition, s32 radiusA, s32 *secondPosition, s32 radiusB)
 Returns 0 when two spheres overlap: at positions a and b (16.16 pixels) with radii radiusA and radiusB (pixels); -1 otherwise.
s32 FieldObject_UpdatePlayerControl (struct ScriptInterpreter *interpreter)
 SC_PLAYER: moves the player on the field by the direction pad: walking or running, sliding around walls, pushing movable objects, turning, playing the matching animation and leaving footprints.
s32 Object_MoveOnWorldMap (struct ScriptInterpreter *interpreter)
 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.
s32 Field_CheckConfiguredKeysAndCount (struct ScriptInterpreter *interpreter)
 SC_KEY_COUNT: checks the configured keys (Field_CheckConfiguredKeys).
s32 Object_MoveByKeys (struct ScriptInterpreter *interpreter)
 SC_KEYS: moves an object 8 pixels at a time by the direction pad, with up and down changing its height (y) rather than its depth.

Detailed Description

Player control: the configured keys and moving objects by the pad.

Part of field.c, the field object, compiled only through it.

Definition in file player_control.c.

Macro Definition Documentation

◆ FIELD_SHORTCUT_KEYS

#define FIELD_SHORTCUT_KEYS   gKeysPressed

Definition at line 12 of file player_control.c.

Referenced by Field_RequestShortcut().

◆ WORLD_MAP_PROBE_RADIUS

#define WORLD_MAP_PROBE_RADIUS   0x70000

Definition at line 13 of file player_control.c.

Referenced by Object_MoveOnWorldMap().

Function Documentation

◆ Field_StoreHalfword()

__inline__ void Field_StoreHalfword ( s16 * address,
s32 value )
static

Stores value in a halfword of the event work.

XXX: why the stores go through a helper rather than plain assignment; whether the assignment form changes Field_RequestShortcut's bytes would settle it.

Definition at line 23 of file player_control.c.

Referenced by Field_RequestShortcut(), and Field_StoreHalfword().

◆ ObjectDispatch_SetUpdateValue()

UNUSED void ObjectDispatch_SetUpdateValue ( void * rawObject,
s32 value )

Stores value as a word at the object's unk6c.

Definition at line 28 of file player_control.c.

Referenced by ObjectDispatch_SetUpdateValue().

◆ Field_RequestShortcut()

u32 Field_RequestShortcut ( u32 encodedAssignment)

Handles a shortcut key's assignment: its top two bits choose what it requests (0 Psynergy, 1 an item) and the low 14 bits which one.

With flag 0x107 set it raises event 250 instead, as the menu key does then; on the world map (mode 3) R raises event -888 (0xfc88), the world map picture, and L -889 (0xfc87), the visibility transition. Returns the request.

Called by Field_CheckConfiguredKeys. Sets fieldWork->command, fieldWork->item or fieldWork->event, which the scene loop (run_scene.c) acts on.

Definition at line 44 of file player_control.c.

Referenced by Field_CheckConfiguredKeys(), and Field_RequestShortcut().

◆ Field_CheckConfiguredKeys()

s32 Field_CheckConfiguredKeys ( void )

Checks the keys the player has configured: Select, A and Start set their flag in the event work and return 1; the two shortcut keys pass on their assignment (Field_RequestShortcut).

Returns 0 when none is pressed. Only the first configured key pressed this frame counts, in that order.

Called each frame by the leader's control commands: SC_PLAYER, SC_WORLD and SC_KEY_COUNT. Sets fieldWork->menu, examine or start.

Definition at line 78 of file player_control.c.

Referenced by Field_CheckConfiguredKeys(), Field_CheckConfiguredKeysAndCount(), FieldObject_UpdatePlayerControl(), and Object_MoveOnWorldMap().

◆ Runtime_CheckRadiusOverlap()

s32 Runtime_CheckRadiusOverlap ( s32 * firstPosition,
s32 radiusA,
s32 * secondPosition,
s32 radiusB )

Returns 0 when two spheres overlap: at positions a and b (16.16 pixels) with radii radiusA and radiusB (pixels); -1 otherwise.

Called by SC_PLAYER's push test, ScriptObject_CheckOverlap and ScriptObject_FindOverlappingEntry.

Definition at line 105 of file player_control.c.

Referenced by FieldObject_UpdatePlayerControl(), Runtime_CheckRadiusOverlap(), ScriptObject_CheckOverlap(), and ScriptObject_FindOverlappingEntry().

◆ FieldObject_UpdatePlayerControl()

s32 FieldObject_UpdatePlayerControl ( struct ScriptInterpreter * interpreter)

SC_PLAYER: moves the player on the field by the direction pad: walking or running, sliding around walls, pushing movable objects, turning, playing the matching animation and leaving footprints.

Also checks the configured keys. Returns 1.

Run each frame by gObjectDispatch_PlayerScript, which the scene loop (run_scene.c) starts on the leader through ObjectDispatch_StartPlayerControl when it hands control back on the field. Sets the leader's speed, target, velocity, angle and action, moves the objects it pushes, counts gEventWork->blockedSteps and creates the footprint objects.

Definition at line 139 of file player_control.c.

Referenced by FieldObject_UpdatePlayerControl().

◆ Object_MoveOnWorldMap()

s32 Object_MoveOnWorldMap ( struct ScriptInterpreter * interpreter)

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.

Shallow water (terrain 6) leaves a ripple and terrain 9 hides the shadow.

Run each frame by gObjectDispatch_WorldMapScript, which the scene loop (run_scene.c) starts on the leader through ObjectDispatch_StartWorldMapControl on the world map. Sets the leader's speed, target, velocity, angle and action, turns the perspective work's yaw, counts gEventWork->blockedSteps and creates the ripple objects.

Definition at line 505 of file player_control.c.

Referenced by Object_MoveOnWorldMap().

◆ Field_CheckConfiguredKeysAndCount()

s32 Field_CheckConfiguredKeysAndCount ( struct ScriptInterpreter * interpreter)

SC_KEY_COUNT: checks the configured keys (Field_CheckConfiguredKeys).

Returns 1. Run each frame by gObjectDispatch_KeyCheckScript, which the scene loop starts on the leader in movement mode 2, where the pad does not move it.

Definition at line 807 of file player_control.c.

Referenced by Field_CheckConfiguredKeysAndCount().

◆ Object_MoveByKeys()

s32 Object_MoveByKeys ( struct ScriptInterpreter * interpreter)

SC_KEYS: moves an object 8 pixels at a time by the direction pad, with up and down changing its height (y) rather than its depth.

Refuses steps into an occupied cell, across a change of collision code, or onto ground too high (up) or too low (down). Returns 1.

Run each frame by gObjectDispatch_KeysScript, which the scene loop starts on the leader in movement mode 1 (climbing). Sets the leader's speed, angle, target or velocity, and counts gEventWork->blockedSteps.

Definition at line 823 of file player_control.c.

Referenced by Object_MoveByKeys().