Alchemy
Loading...
Searching...
No Matches

requests.c

Go to the documentation of this file.
1/// @file
2/// Battles and destinations an event requests, and the queued sound.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7#define AERIE 98 ///< encounter table fought before the Aerie's storm
8/// Sets up a battle with enemy group slot of encounter table zone. On the
9/// world map (mode 3) the terrain under the leader picks the battle backdrop.
10/// Sets the field work's battle request, which the scene loop then handles,
11/// and the battle cue; zone 98's first slot also sets gGameState.special to
12/// the Aerie's storm backdrop. About 35 scenes reach it through
13/// Field_RequestBattleFromEncounterTableFar, and the lobby calls it directly.
15 s32 zone = zoneNo;
16 s32 slot = slotNo;
17 struct FieldWork *field = (struct FieldWork *)gEventWork;
18
19 field->battle = Encounter_GetEnemyGroupAtSlot(zone, slot); // enemy group
20 if (zone == AERIE && slot == 0)
22 if (field->mode == MODE_WORLD_MAP) {
24
26 }
27 BattleFx_SelectBattleCue(zone, slot);
28}
29
30/// Sets up the battle with Djinni number `no`. The low 8 bits of flag are the
31/// Djinni's actor, which hops first unless DJINN_NO_HOP is set. Djinn are
32/// numbered 20 to an element (Djinn_ResolvePendingEvent). Sets
33/// gGameState.pendingDjinnEvent and the field work's battle request. About
34/// 20 scenes reach it through Field_RequestDjinnBattleFar.
36 struct FieldWork *field;
37 struct GameState *gameState;
38 s32 skipHop;
39
40 field = (struct FieldWork *)gEventWork;
41 skipHop = flag & DJINN_NO_HOP;
42 flag &= 0xff;
43
44 if (skipHop == 0)
46
47 gameState = &gGameState;
48 gameState->pendingDjinnEvent = (no + DJINNI_0) | skipHop;
49 field->battle = Encounter_GetDjinnEnemyGroup(no); // the Djinni's enemy group
50 if (field->mode == MODE_WORLD_MAP) {
51 struct ObjectRuntime *leader = ObjectTable_Get(gameState->selectedActor);
52
54 }
56}
57
58/// Sets the scene and entrance that the field goes to next
59/// (gGameState.nextScene and nextEntrance). About 30 scenes and the lobby
60/// reach it through Event_SetNextDestinationFar.
61void Event_SetNextDestination(s32 scene, s32 entrance) {
62 gGameState.nextScene = scene;
63 gGameState.nextEntrance = entrance;
64}
65
66/// Sets where the party wakes up after losing a battle
67/// (gGameState.defeatScene and defeatEntrance). The scenes before scripted
68/// battles (Colosso, the Vault, Vale, the Aerie) and the lobby reach it
69/// through Event_SetDefeatDestinationFar.
70void Event_SetDefeatDestination(s32 scene, s32 entrance) {
71 gGameState.defeatScene = scene;
72 gGameState.defeatEntrance = entrance;
73}
74
75/// Makes the event leave for entrance entrance of scene scene: sets
76/// gGameState.scene and entrance and raises the exit request EXIT_NONE (999),
77/// so the scene loop leaves on its next pass. Only Tolbi's spring reaches it,
78/// through Event_RequestDestinationFar.
79void Event_RequestDestination(u16 scene, u16 entrance) {
80 struct FieldWork *work = (struct FieldWork *)gEventWork;
81 gGameState.scene = scene;
82 gGameState.entrance = entrance;
83 work->exit = 999;
84}
85
86/// Plays SE_298, then soundId (SE_289 for -1), and remembers
87/// soundId for BattleFx_PlayQueuedSound in the field work's queuedSound.
88/// About 30 scenes reach it through the far alias, and the ground particles
89/// (weather.c) queue SE_170 with it.
91 ((struct FieldWork *)gEventWork)->queuedSound = soundId;
92 if ((s16)soundId == -1) {
93 soundId = SE_289;
94 }
96 AudioCommand_PlayFar(soundId);
97}
98
99/// Plays the sound BattleFx_SetQueuedSoundAndPlay remembered, if any. Called
100/// by scenes, by the event runner (object/events.c), by setup.c and by an
101/// actor's landing (actor_commands.c).
103 s16 soundId = ((struct FieldWork *)gEventWork)->queuedSound;
104
105 if (soundId != -1)
106 AudioCommand_PlayFar(soundId);
107}
108
109#undef AERIE
void * ObjectTable_Get(u32 actorIndex)
Returns the actor in slot index (0 to 65), or NULL.
Definition actors.c:462
void Djinn_RunBattleStartHop(s32 djinniId)
A Djinni's battle start: the Djinni (actor id) bounces twice, turns to face the leader,...
Definition djinni.c:17
void AudioCommand_PlayFar(s32 id)
struct GameState gGameState
s32 Encounter_ResolveWorldMapZoneAndBackdrop(void *pos)
Returns the world map encounter zone for the terrain at pos (0 for none), and chooses the battle back...
Definition encounter.c:103
u16 Encounter_GetEnemyGroupAtSlot(s32 zone, s32 slot)
Returns the enemy group in slot (0 to 7) of zone; 14 halfwords make a zone.
Definition encounter.c:244
void BattleFx_SelectBattleCue(s32 zone, s32 slot)
Chooses the battle music for slot of zone (gGameState.sceneCue).
Definition encounter.c:439
s16 Encounter_GetDjinnEnemyGroup(s32 djinni)
Returns the enemy group of Djinni battle djinni, which the table gives as a zone and slot.
Definition encounter.c:251
#define DJINN_NO_HOP
Field_RequestDjinnBattle's flag: the Djinni does not hop first.
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define DJINNI_0
gGameState.pendingDjinnEvent of Djinni 0 (requests.c, djinni.c).
void Field_RequestBattleFromEncounterTable(s32 zoneNo, s32 slotNo)
Sets up a battle with enemy group slot of encounter table zone.
Definition requests.c:14
#define AERIE
encounter table fought before the Aerie's storm
Definition requests.c:7
void Event_SetDefeatDestination(s32 scene, s32 entrance)
Sets where the party wakes up after losing a battle (gGameState.defeatScene and defeatEntrance).
Definition requests.c:70
void Event_SetNextDestination(s32 scene, s32 entrance)
Sets the scene and entrance that the field goes to next (gGameState.nextScene and nextEntrance).
Definition requests.c:61
void BattleFx_PlayQueuedSound(void)
Plays the sound BattleFx_SetQueuedSoundAndPlay remembered, if any.
Definition requests.c:102
void Field_RequestDjinnBattle(s32 flag, s32 no)
Sets up the battle with Djinni number no.
Definition requests.c:35
void BattleFx_SetQueuedSoundAndPlay(s32 soundId)
Plays SE_298, then soundId (SE_289 for -1), and remembers soundId for BattleFx_PlayQueuedSound in the...
Definition requests.c:90
void Event_RequestDestination(u16 scene, u16 entrance)
Makes the event leave for entrance entrance of scene scene: sets gGameState.scene and entrance and ra...
Definition requests.c:79
char ResourceId_VenusLighthouseAerieStormBackdrop
#define SE_298
Definition songs.h:287
#define SE_289
Definition songs.h:282
struct EventWork * gEventWork
Full event work allocated by Field_RunScene (heap slot 27).
s16 exit
the exit taken, which ends the scene
s16 queuedSound
a sound BattleFx_PlayQueuedSound plays; -1 for none
s16 battle
the enemy group of a random encounter
s16 mode
MODE_WORLD_MAP (3) on the world map.
The game's state: play time, coins, the scene and the leader's position, the active party and the opt...
Definition game_state.h:14
s16 nextScene
where the event sends the party next; -1 for none
Definition game_state.h:43
s16 special
the battle backdrop chosen for the scene or terrain
Definition game_state.h:47
s16 nextEntrance
where the event sends the party next; -1 for none
Definition game_state.h:44
s16 pendingDjinnEvent
The Djinni battle pending (DJINNI_0 plus its number, flags in bits 15 to 11), resolved on returning t...
Definition game_state.h:103
s16 defeatEntrance
where a defeat returns to; -1 for none
Definition game_state.h:46
s16 defeatScene
where a defeat returns to; -1 for none
Definition game_state.h:45
s16 entrance
Definition game_state.h:37
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 x
16.16 fixed-point pixels
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
#define MODE_WORLD_MAP
the world map
Definition object.h:78