Alchemy
Loading...
Searching...
No Matches

tret_tree_branch.c

Go to the documentation of this file.
1/// @file
2/// A branch of Tret, the great tree, where Breeze, a Jupiter Djinni, waits;
3/// touch triggers move the leader and the camera along the branch.
4
8#include "unit/field/field.h"
10#include "battle.h"
11#include "keystate.h"
12#include "debug.h"
13#include "field.h"
14#include "game.h"
15#include "graphics.h"
16#include "menu.h"
17#include "minigame.h"
18#include "sound.h"
19#include "system.h"
20#include "global_cells.h"
21#include "types.h"
22#include "callback_scheduler.h"
23#include "scene.h"
24#include "resource_397.h"
25#include "io_reg.h"
26#include "irq.h"
27#include "game_state.h"
28#include "ability_ids.h"
29#include "field_event.h"
30#include "engine_call.h"
31#include "field_scene.h"
32#include "djinn_ids.h"
33#include "display_transition.h"
34#include "map_scroll.h"
35#include "flags.h"
36#include "songs.h"
37#include "event.h"
38
39/// Breeze, the Jupiter Djinni on the branch: Djinni 61 is the name message
40/// "Breeze", and its placement is gone once its flag (FLAG_DJINNI_0 + 61) is
41/// set.
43
44/// Starts the scanline-dependent BG3 scroll callbacks.
45static void TretTreeBranch_StartBg3Split(void);
46
48static u8 sTransferData[96];
52
53/// Talking to Breeze: the Djinni hops and its battle starts.
54static void Event_TalkToBreeze(void) {
56}
57
60}
61
62const struct SceneRegion *TretTreeBranch_GetRegions(void) { return NULL; }
63
65
68}
69
70/// Moves the leader and camera by signed 16-pixel cell offsets, placing each
71/// at the terrain height of its destination.
73 s32 cellOffsetZ) {
74 struct EventWork *state = gEventWork;
75 struct FieldActor *actor;
76 s32 offsetX = cellOffsetX;
77 s32 offsetZ = cellOffsetZ;
79
81 // Multiplication keeps negative cell offsets defined; every caller is within
82 // six cells, so the fixed-point result fits in s32.
83 offsetX *= PIXELS(16);
84 offsetZ *= PIXELS(16);
85
86 // Shift the selected actor before the separate camera object.
87 if (actor != 0) {
88 actor->x.fixed += offsetX;
89 actor->z.fixed += offsetZ;
91 Map_GetTerrainHeight(actor->terrainId, actor->x.fixed, actor->z.fixed);
92 actor->y.fixed = terrainHeight;
94 }
95
96 actor = state->viewCenter;
97 if (actor != 0) {
98 actor->x.fixed += offsetX;
99 actor->z.fixed += offsetZ;
101 Map_GetTerrainHeight(actor->terrainId, actor->x.fixed, actor->z.fixed);
102 actor->y.fixed = terrainHeight;
104 }
105}
106
107/// Touch trigger 10: the leader and camera move 80 pixels south at once.
108static void Event_ShiftSouthFiveCells(void) {
110}
111
112/// Touch trigger 11: the leader and camera move 80 pixels north at once.
113static void Event_ShiftNorthFiveCells(void) {
115}
116
117/// Touch trigger 12: the same 80-pixel move south as trigger 10.
120}
121
122/// Touch trigger 13: the same 80-pixel move north as trigger 11.
125}
126
127/// Touch trigger 14: the leader and camera move 96 pixels south at once.
128static void Event_ShiftSouthSixCells(void) {
130}
131
132/// Touch trigger 15: the leader and camera move 96 pixels north at once.
133static void Event_ShiftNorthSixCells(void) {
135}
136
137/// Walking into one of exits 1 to 8: the exit sound plays and the party
138/// leaves by the exit touched.
139static void Event_TakeTouchedExit(void) {
140 struct EventWork *state = gEventWork;
141 s16 *touchedExit;
142
144 touchedExit = &state->touchedTrigger;
145 Engine_EventRequestExit(*touchedExit);
146}
147
148/// Selects the same mask and window parameters for Reveal and scene entry.
149static inline void
151 state->mask = 0x3f3f;
152 state->active = 31;
153 state->value = 10;
154}
155
156/// Casting Reveal on the branch (its phase 2): the window transition and BG1's
157/// blend over the rest of the screen are set again, as when the scene opened.
158static void Event_CastReveal(void) {
159 struct DisplayTransitionState *transition;
160
162
164 REG_BLDALPHA = BLEND_ALPHA(4, 12);
165
166 transition = gDisplayTransition;
168}
169
170/// Returns the touch, talk, exit and Reveal events for this branch.
173}
174
175/// Unused event hook: begins and immediately ends an event.
177 EV_BEGIN();
178 EV_END();
179}
180
182
184
185/// Unused exchange callback: puts held/repeated keys in the transfer header.
187 u16 *header = sTransferHeader;
188
189 header[0] = gKeysHeld;
190 header[1] = gKeysRepeat;
192}
193
194/// Initializes the backdrop transition and installs BG3's scanline scroll
195/// split. Returns 0 for the overlay initialization entry point.
197#ifndef UBFIX
198 u8 **eventSlot = (u8 **)&gEventWork;
199#endif
200 struct DisplayTransitionState *transition;
201
203
205
207 REG_BLDALPHA = BLEND_ALPHA(4, 12);
208
209 // UB: slot 31 lies past scalar gEventWork. Its named load adds six
210 // bytes in the native EN trial (0x6a to 0x70).
211#ifdef UBFIX
212 transition = gDisplayTransition;
213#else
214 transition = (struct DisplayTransitionState *)eventSlot[4];
215#endif
217
219 return 0;
220}
221
222/// HBlank selects BG3's horizontal offset for the next scanline.
224 u16 *scrollOffset;
225 u32 horizontalScroll;
226
227 if (REG_VCOUNT >= sSplitLine) {
228 scrollOffset = &sHofsAtOrAfterSplit;
229 } else {
230 scrollOffset = &sHofsBeforeSplit;
231 }
232 horizontalScroll = *scrollOffset;
233 REG_BG3HOFS = horizontalScroll;
234}
235
236/// Updates the split from the first map layer's pixel position. Before the
237/// split, scroll subtracts one pixel for every four elapsed frames.
239 struct MapLayerScroll *layer =
240 &((struct MapScrollWork *)gMapWork[0])->layers[0];
241 s32 horizontalOffset;
242
243 sSplitLine = 192 - (s16)(layer->y >> 16);
244 sHofsAtOrAfterSplit = horizontalOffset = (s16)(layer->x >> 16);
245 sHofsBeforeSplit = horizontalOffset - (gFrameCount >> 2);
246}
247
248/// Runs the BG3 scroll selection at every HBlank, updating the split each
249/// frame.
254}
255
257 {0, CONDITION_ALWAYS, 100, 0, 100, FACING_SOUTH, 0, -1, -1, -1, -1, 0},
258 {1, CONDITION_ALWAYS, 328, 0, 424, FACING_WEST, 0, -1, -1, -1, -1, 0},
259 {2, CONDITION_ALWAYS, 424, 0, 440, FACING_EAST, 0, -1, -1, -1, -1, 0},
260 {3, CONDITION_ALWAYS, 376, 0, 360, FACING_SOUTH, 0, -1, -1, -1, -1, 0},
261 {4, CONDITION_ALWAYS, 424, 0, 328, FACING_EAST, 0, -1, -1, -1, -1, 0},
262 {5, CONDITION_ALWAYS, 376, 0, 264, FACING_SOUTH, 0, -1, -1, -1, -1, 0},
263 {6, CONDITION_ALWAYS, 328, 0, 248, FACING_WEST, 0, -1, -1, -1, -1, 0},
264 {7, CONDITION_ALWAYS, 328, 0, 152, FACING_WEST, 0, -1, -1, -1, -1, 0},
265 {8, CONDITION_ALWAYS, 424, 0, 136, FACING_EAST, 0, -1, -1, -1, -1, 0},
267};
268
270 SCENE_EXITS(46), SCENE_EXIT(1, 45, 2), SCENE_EXIT(2, 45, 3),
271 SCENE_EXIT(3, 45, 4), SCENE_EXIT(4, 45, 5), SCENE_EXIT(5, 45, 7),
272 SCENE_EXIT(6, 45, 6), SCENE_EXIT(7, 45, 8), SCENE_EXIT(8, 45, 9),
274};
275
276// clang-format off
279 PIXELS(648), 0, PIXELS(88), FACING_WEST, TALK_FACE_PARTY, 0 },
280 { SCENE_TABLE_END },
281};
282// clang-format on
283
308};
309
311 MAP_CELL_STEP(0, 96, 2, 2, 2),
312 MAP_CELL_STEP(2, 96, 2, 2, 2),
314};
Ability numbers, named from the English release.
@ ABILITY_REVEAL
Definition ability_ids.h:19
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
The task scheduler: tasks, their order and the scheduler's state.
The engine calls the debug menus import, and their palette swatch tiles.
The display transition's frames, windows and state.
Djinn numbers, named from the English release.
@ DJINNI_BREEZE
Definition djinn_ids.h:33
The engine call layer: one typed inline for each of the thirteen main-image routines below that the s...
static s32 FieldScheduler_AddCallback(SchedulerCallback callback, s32 priority)
Registers a main-image scheduler callback.
Definition engine_call.h:36
Scene commands: the all-caps macros the scene scripts are written in.
#define EV_BEGIN()
Definition event.h:30
#define EV_END()
Definition event.h:31
#define SE(n)
Definition event.h:28
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
#define MAP_CELL_STEP(srcX, srcY, width, height, frames)
Definition field_event.h:59
#define MAP_CELL_STEPS_END
Definition field_event.h:61
@ TASK_PRIORITY_SCENE
Definition field_event.h:40
@ TRANSITION_BACKDROP_FADE
Definition field_obj.h:16
#define SCENE_TRANSITION(style, variant)
Definition field_obj.h:20
The scene table formats: entrances, exits, placements and events, and the macros that write them.
#define SCENE_EVENTS_END
@ EVENT_TOUCH
@ EVENT_TALK
#define SCENE_EXITS(scene)
Definition field_scene.h:72
#define PSYNERGY_IN_AREA(ability, phase)
#define SCENE_EXIT(exit, scene, entrance)
Definition field_scene.h:73
@ ACTOR_FIRST_PLACED
@ SCENE_TABLE_END
Definition field_scene.h:43
@ CONDITION_ALWAYS
Definition field_scene.h:44
@ TALK_FACE_PARTY
#define EVENT_SCRIPT(script)
@ ACTOR_STAND
#define SCENE_EXITS_END
Definition field_scene.h:77
@ FACING_EAST
Definition field_scene.h:26
@ FACING_SOUTH
Definition field_scene.h:28
@ FACING_WEST
Definition field_scene.h:30
#define PIXELS(value)
Game flags, named where their meaning is shown.
#define FLAG_DJINNI_0
the flag of Djinni 0, set once it is caught
Definition flags.h:15
void Runtime_SetIrqHandler(u32 irq, s32 vcount, InterruptHandler handler)
Installs handler for interrupt irq and enables that interrupt, or with a null handler disables it and...
Definition frame.c:37
volatile u32 gFrameCount
Frames WaitFrames has finished.
GameState, the game's state: play time, coins, the scene and the leader's position,...
struct GameState gGameState
The work slots of gWorkSlot, read through their own names.
void * gMapWork[]
struct DisplayTransitionState * gDisplayTransition
Slot 31.
The screen blend's globals and the graphics routines.
The hardware's I/O registers and their bits, as pret names them.
#define REG_VCOUNT
Definition io_reg.h:19
#define REG_BG3HOFS
Definition io_reg.h:53
#define BLDCNT_EFFECT_BLEND
weighted by REG_BLDALPHA
Definition io_reg.h:131
#define BLDCNT_TGT2_ALL
Definition io_reg.h:140
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
Definition io_reg.h:145
#define BLDCNT_TGT1_BG1
Definition io_reg.h:124
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_BLDCNT
Definition io_reg.h:119
The hardware's interrupt sources and the interrupt handler table.
@ IRQ_HBLANK
Definition irq.h:14
The keypad state the VBlank interrupt keeps.
volatile u32 gKeysHeld
Keys down now.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
The map layers' scroll work and the background scroll values.
The reel game's title lettering.
void DisplayTransition_InitializeBattleEffectState(s32 mode)
Starts window transition mode at value 0, with no duration: the caller moves it.
Definition transition.c:559
void Field_RequestDjinnBattle(s32 flag, s32 no)
Sets up the battle with Djinni number no.
Definition requests.c:35
Declares nothing: an empty header kept for the files that include it.
FIELD_AT_OFFSET and the entity and camera views older scene code reads.
s32 SerialRuntime_PollAndTransfer(void *send, void *receive)
Looks for the link partner and, once connected, does one exchange (as SerialRuntime_ExchangePayloads)...
Definition serial.c:113
Song and sound effect ids, indices into gSound_SongTable.
#define SE_MAP_EXIT
Definition songs.h:116
struct EventWork * gEventWork
void Engine_EventRequestExit()
#define NULL
Definition bilibin.h:6
The display transition state (heap block 31): two pages of window edges for every line,...
u16 value
The progress, moved from start to end over duration frames: bit 5 says whether the transition opens o...
s16 active
WININ, or WINOUT by mode: 1 when a transition starts.
s16 mask
WINOUT, or WININ by mode: 0x3f3f or 63 when a transition starts.
The running scene's event work: its placement and event tables, its actors, the triggers and exit it ...
Definition event_work.h:20
struct FieldActor * viewCenter
the object the map view follows
Definition event_work.h:49
s32 startTransition
SCENE_TRANSITION(style, variant).
Definition event_work.h:43
s16 touchedTrigger
the step event a touch or exit event answers
Definition event_work.h:26
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
s32 terrainHeight
16.16 fixed-point pixels
Definition field_obj.h:38
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
u8 terrainId
The map layer (0 to 3) its ground height is read from, which the scrolling camera updates from the ce...
Definition field_obj.h:47
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
One background layer of the field map: its scroll position, origin, parallax against the view,...
Definition map_scroll.h:14
s32 y
16.16 fixed-point pixels
Definition map_scroll.h:15
The field map's work: the followed position, screen shake, tile animations, blend script,...
Definition map_scroll.h:27
struct MapLayerScroll layers[3]
BG3, BG2 and BG1, in that order.
Definition map_scroll.h:49
A scene entrance: where and facing which way the party arrives, and the camera's bounds there (-1 for...
Definition field_scene.h:54
A scene event: its kind and detail, the trigger it answers, its condition and its value (a message or...
An actor a scene places: its sprite, the condition for placing it, how it behaves,...
Definition field_scene.h:81
A scene's exit region: the box that, while its condition holds, takes the party leader out through it...
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
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...
Definition terrain.c:343
u32 gTretTreeBranch_Exits[]
static void Event_ShiftNorthSixCells(void)
Touch trigger 15: the leader and camera move 96 pixels north at once.
static void UNUSED TretTreeBranch_ExchangeInputPacket(void)
Unused exchange callback: puts held/repeated keys in the transfer header.
static u16 sHofsAtOrAfterSplit
static u16 sTransferHeader[16]
struct ScenePlacement gTretTreeBranch_Placements[]
static void TretTreeBranch_UpdateBg3ScrollSplit(void)
Updates the split from the first map layer's pixel position.
s32 TretTreeBranch_Initialize(void)
Initializes the backdrop transition and installs BG3's scanline scroll split.
static void UNUSED TretTreeBranch_UnusedHookFirst(void)
static void TretTreeBranch_SetRevealWindow(struct DisplayTransitionState *state)
Selects the same mask and window parameters for Reveal and scene entry.
static u16 sHofsBeforeSplit
static void Event_ShiftSouthFiveCellsSecond(void)
Touch trigger 12: the same 80-pixel move south as trigger 10.
u16 gTretTreeBranch_CellSteps[]
const struct ScenePlacement * TretTreeBranch_GetPlacements(void)
static void TretTreeBranch_ApplyBg3ScrollAtScanline(void)
HBlank selects BG3's horizontal offset for the next scanline.
static void Event_ShiftNorthFiveCells(void)
Touch trigger 11: the leader and camera move 80 pixels north at once.
static void TretTreeBranch_ShiftLeaderAndCameraByCells(s32 cellOffsetX, s32 cellOffsetZ)
Moves the leader and camera by signed 16-pixel cell offsets, placing each at the terrain height of it...
static void Event_CastReveal(void)
Casting Reveal on the branch (its phase 2): the window transition and BG1's blend over the rest of th...
static void Event_TalkToBreeze(void)
Talking to Breeze: the Djinni hops and its battle starts.
static s32 sSplitLine
@ ACTOR_BREEZE
@ SPRITE_JUPITER_DJINNI
static void TretTreeBranch_StartBg3Split(void)
Starts the scanline-dependent BG3 scroll callbacks.
struct SceneEntrance gTretTreeBranch_Entrances[]
const u32 * TretTreeBranch_GetExits(void)
const struct SceneEntrance * TretTreeBranch_GetEntrances(void)
static void UNUSED TretTreeBranch_RunEmptyEvent(void)
Unused event hook: begins and immediately ends an event.
static void Event_ShiftSouthSixCells(void)
Touch trigger 14: the leader and camera move 96 pixels south at once.
static void Event_TakeTouchedExit(void)
Walking into one of exits 1 to 8: the exit sound plays and the party leaves by the exit touched.
static u8 sTransferData[96]
struct SceneEvent gTretTreeBranch_Events[]
static void Event_ShiftSouthFiveCells(void)
Touch trigger 10: the leader and camera move 80 pixels south at once.
const struct SceneEvent * TretTreeBranch_GetEvents(void)
Returns the touch, talk, exit and Reveal events for this branch.
static void UNUSED TretTreeBranch_UnusedHookSecond(void)
static void Event_ShiftNorthFiveCellsSecond(void)
Touch trigger 13: the same 80-pixel move north as trigger 11.
const struct SceneRegion * TretTreeBranch_GetRegions(void)
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels