Alchemy
Loading...
Searching...
No Matches

goma_cave_waterway.c

Go to the documentation of this file.
1/// @file
2/// Goma Cave: the waterway rooms, where a stump leaps away under Move.
3#include "game_state.h"
8#include "unit/field/field.h"
9#include "field_obj.h"
10#include "types.h"
11#include "field_event.h"
12#include "battle.h"
13#include "debug.h"
14#include "field.h"
15#include "game.h"
16#include "graphics.h"
17#include "menu.h"
18#include "minigame.h"
19#include "sound.h"
20#include "system.h"
21#include "mapcopy.h"
22#include "field_scene.h"
23#include "scene_ids.h"
24#include "call.h"
25#include "fixed_math.h"
26#include "objcmd.h"
27#include "flags.h"
28#include "songs.h"
29#include "event.h"
30#include "item_ids.h"
31#include "ability_ids.h"
32#include "vector3.h"
33
34#define STUMP 8
35
36// Forward declarations.
37static void GomaCaveWaterway_LeapStump(s32 no);
38
40#include "common/effect_spawn.h"
41
42const struct SceneEntrance *Scene_GetEntrances(void) {
45 }
47}
48
49const struct SceneRegion *Scene_GetRegions(void) { return 0; }
50
52
56 }
58}
59
60/// Move on the stump: from column 24 it spins, leaps away and lies where it
61/// lands.
62static void Event_MoveStump(void) {
63 struct FieldActor *stump;
64 struct FieldActor *landed;
65 s32 column;
66
67 stump = Object_GetById(STUMP);
68 column = stump->x.fixed / PIXELS(16);
69 if (column == 24) {
72 Map_CopyCellAttributes(19, 74, 9, 3, 19, 17);
73 landed = Object_GetById(STUMP);
76 }
77}
78
79const struct SceneEvent *Scene_GetEvents(void) {
82 }
84}
85
86/// Arriving by entrance 5 shows no place name; otherwise the stump lies
87/// where the party moved it.
89 struct FieldActor *stump;
90
93 if (gGameState.entrance == 5) {
95 } else {
99 stump = Object_GetById(STUMP);
102 OBJ_MODE(STUMP, 2);
103 Map_CopyCellAttributes(19, 74, 9, 3, 19, 17);
104 }
105 }
106 }
107 return 0;
108}
109
110/// The leaping stump's update hook turns its sprite a fixed amount per frame.
111static void GomaCaveWaterway_SpinStump(union FieldObject *object) {
112 struct AnimationObject *sprite = object->actor.sprite;
113
114 sprite->rotation -= 0x800;
115}
116
118
119/// The stump spins in place, leaps and lands with a shake and a ring of dust,
120/// then comes to rest a little further on.
122 struct FieldActor *work;
123 u32 cnt;
124 struct Vector3 vec;
125 struct EffectOptions opt;
126
127 work = Object_GetById(no);
128 work->motionFlags = 0;
129 for (cnt = 0; cnt < 18; cnt++) {
131 work->sprite->rotation -= 256;
132 work->x.fixed -= Trig_Cos(work->sprite->rotation) / 2;
133 work->targetX = ACTOR_NO_TARGET;
134 }
136 OBJ_SPEED(no, PIXELS(3), 3 * PIXELS(1) / 2);
137 Actor_SetDestination(no, 376, 288);
138 work->gravity = 0xcccc;
139 work->motionFlags = 3;
140 work->terrainId = 0;
144 Map_SetShake(0x50000, 0x50000, 0x10000);
146 Map_SetShake(-1, -1, 0xe666);
147 for (cnt = 0; cnt < 17; cnt++) {
148 vec.x = Trig_Cos(cnt << 12);
149 vec.y = 0;
150 vec.z = Trig_Sin(cnt << 12);
151 vec.x -= vec.x / 4;
152 vec.z -= vec.z / 2;
153 Effect_Spawn(work->x.fixed, work->y.fixed, work->z.fixed, vec.x, vec.y,
154 vec.z, 0, NULL);
155 }
156 work->velocityY = 0x50000;
157 Actor_SetDestination(no, 346, 292);
160 // UB: the native integer store aliases the update pointer. A typed clear
161 // swaps this store with the following sprite-pointer load.
162#ifdef UBFIX
163 work->update = NULL;
164#else
165 *(u32 *)&work->update = 0;
166#endif
167 work->sprite->rotation = 0x1000;
168 opt.type = 214;
169 opt.startScaleX = 0x8000;
170 opt.startScaleY = 0xcccc;
171 opt.targetScaleX = 0x18000;
172 opt.targetScaleY = 0x13333;
173 Effect_Spawn(work->x.fixed, work->y.fixed, work->z.fixed, 0, 0, 0, 0x1c0000,
174 &opt);
176 OBJ_MODE(no, 3);
178}
179
181 SC_WAIT(1), SC_LOOP(22, SC_TOP), SC_WAIT(1),
182 SC_POS(0, 0, 0), SC_WAIT(1), SC_FREE,
183};
184
186 SC_WAIT(1), SC_LOOP(44, SC_TOP), SC_WAIT(1),
187 SC_POS(0, 0, 0), SC_WAIT(1), SC_FREE,
188};
189
191 SC_WAIT(1), SC_LOOP(126, SC_TOP), SC_WAIT(1),
192 SC_POS(0, 0, 0), SC_WAIT(1), SC_FREE,
193};
194
195const s32 *gEffectScripts[] = {
199};
200
202 {0, CONDITION_ALWAYS, 172, 0, 149, FACING_SOUTH, 0, -1, -1, -1, -1, 0},
203 {1, CONDITION_ALWAYS, 376, 0, 776, FACING_NORTH, 0, 88, 8, 664, 832, 0},
204 {2, CONDITION_ALWAYS, 168, 0, 552, FACING_SOUTH, 0, 88, 8, 664, 832, 0},
205 {3, CONDITION_ALWAYS, 600, 0, 520, FACING_SOUTH, 0, 88, 8, 664, 832, 0},
206 {4, CONDITION_ALWAYS, 376, 0, 168, FACING_SOUTH, 0, 88, 8, 664, 832, 0},
207 {5, CONDITION_ALWAYS, 614, 0, 848, FACING_NORTH, 0, 480, 605, 720, 900, 0},
208 {99, CONDITION_ALWAYS, 424, 0, 280, FACING_WEST, 0, 88, 8, 664, 832, 0},
210};
211
213 {1, CONDITION_ALWAYS, 154, 0, 350, FACING_NORTH, 0, 16, 48, 632, 360, 0},
214 {2, CONDITION_ALWAYS, 552, 0, 312, FACING_NORTH, 0, 16, 48, 632, 360, 0},
216};
217
219 SCENE_EXITS(28), SCENE_EXIT(1, 25, 2), SCENE_EXIT(2, 27, 1),
220 SCENE_EXIT(3, 27, 2), SCENE_EXIT(4, 29, 1), SCENE_EXIT(5, 5, 11),
221 SCENE_EXIT(0, 29, 0), SCENE_EXIT(1, 28, 4), SCENE_EXIT(2, 2, 40),
223};
224
225// clang-format off
228 PIXELS(400), 0, PIXELS(288), FACING_SOUTH, TALK_KEEP_FACING, 0 },
229 { SCENE_TABLE_END },
230};
231// clang-format on
232
235};
236
240 {0x31, 6, CONDITION_ALWAYS, 2},
241 {0x31, 7, CONDITION_ALWAYS, 3},
247};
248
253};
Ability numbers, named from the English release.
@ ABILITY_MOVE
Definition ability_ids.h:15
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
const struct ScenePlacement * Scene_GetPlacements(void)
const struct SceneEntrance * Scene_GetEntrances(void)
const struct SceneEvent * Scene_GetEvents(void)
const u32 * Scene_GetExits(void)
Both scenes share one exit table.
const struct SceneRegion * Scene_GetRegions(void)
s32 Scene_Initialize(void)
Sets up whichever scene is being entered and runs its arrival events.
s32 gEffectScript0[]
const s32 * gEffectScripts[]
s32 gEffectScript1[]
s32 gEffectScript2[]
Calls through a function pointer, by argument count.
void Engine_ActorSetSpriteFlags(struct FieldActor *, s32)
The engine calls the debug menus import, and their palette swatch tiles.
Scene commands: the all-caps macros the scene scripts are written in.
#define OBJ_MODE(no, m)
Definition event.h:18
#define OBJ_SPEED(no, s, a)
Definition event.h:15
void Map_WaitForShakeToSettle(void)
Waits until both shake amplitudes are below 1/256 pixel, with a 300-frame limit for a shake whose dec...
Definition view.c:36
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
static void Actor_SetDestination(s32 actor, s32 x, s32 z)
void Engine_GameFlagSet(s32 flag)
void Engine_GameFlagClear(s32 flag)
void Engine_ActorWaitForMove(s32 actor)
static void Map_CopyCellAttributes(s32 srcX, s32 srcY, s32 width, s32 height, s32 destX, s32 destY)
static void Map_SetShake(s32 horizontal, s32 vertical, s32 decay)
Sets shake amplitudes in fixed-point pixels and the per-frame decay factor.
s32 Engine_GameFlagIsSet(s32 flag)
Field objects and actors, and the scene transition styles.
@ TRANSITION_WINDOW
Definition field_obj.h:17
@ ACTOR_PRIORITY_UNDERFOOT
The depth sort treats it as 320 pixels higher on the screen.
Definition field_obj.h:155
#define ACTOR_NO_TARGET
A target coordinate that is not set: the object has no target.
Definition field_obj.h:145
#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
#define FIND_ITEM(item)
@ EVENT_EXIT
#define SCENE_EXITS(scene)
Definition field_scene.h:72
#define SCENE_EXIT(exit, scene, entrance)
Definition field_scene.h:73
@ SCENE_TABLE_END
Definition field_scene.h:43
@ CONDITION_ALWAYS
Definition field_scene.h:44
@ TALK_KEEP_FACING
#define PSYNERGY_ON_ACTOR(ability)
#define EVENT_SCRIPT(script)
@ ACTOR_STAND
#define SEARCH(target)
#define SCENE_EXITS_END
Definition field_scene.h:77
@ FACING_NORTH
Definition field_scene.h:32
@ FACING_SOUTH
Definition field_scene.h:28
@ FACING_WEST
Definition field_scene.h:30
#define PIXELS(value)
@ SEARCH_CHEST
16.16 fixed-point constants, sine and cosine, and the library division.
s32 Trig_Cos(s32 angle)
s32 Trig_Sin(s32 angle)
Game flags, named where their meaning is shown.
#define FLAG_SHOW_LOCATION_NAME
Definition flags.h:94
#define FLAG_GOMA_CAVE_WATERWAY_STUMP_MOVED
Definition flags.h:597
GameState, the game's state: play time, coins, the scene and the leader's position,...
struct GameState gGameState
static void Event_MoveStump(void)
Move on the freed stump: from column 11 it spins, leaps away and lies where it lands.
#define STUMP
static void GomaCaveWaterway_SpinStump(union FieldObject *object)
The leaping stump's update hook turns its sprite a fixed amount per frame.
struct SceneEvent gGomaCaveWaterwayEvents2[]
struct SceneEntrance gGomaCaveWaterwayEntrances2[]
struct ScenePlacement gGomaCaveWaterwayPlacementsOther[]
struct ScenePlacement gGomaCaveWaterwayPlacements2[]
struct SceneEvent gGomaCaveWaterwayEventsOther[]
static void GomaCaveWaterway_LeapStump(s32 no)
The stump spins in place, leaps and lands with a shake and a ring of dust, then comes to rest a littl...
struct SceneEntrance gGomaCaveWaterwayEntrancesOther[]
u32 gGomaCaveWaterwayExits[]
The screen blend's globals and the graphics routines.
Item numbers, named from the English release.
@ ITEM_POWER_BREAD
Definition item_ids.h:50
Declares nothing of its own: it only includes edition.h and types.h.
The reel game's title lettering.
Field object scripts: one s32 command word, then its operands, as gScriptObject_CommandTable runs the...
#define SC_LOOP(n, to)
Repeat up to n times.
Definition objcmd.h:28
#define SC_POS(x, y, z)
Set position.
Definition objcmd.h:18
#define SC_FREE
Release.
Definition objcmd.h:43
#define SC_WAIT(n)
Wait n frames.
Definition objcmd.h:16
#define SC_TOP
Script start.
Definition objcmd.h:13
static void SceneActor_WaitObjectBelowHeight(struct FieldActor *object, s32 height)
Waits until the object has come down to height (16.16), a second at most.
Scene numbers, named after their places.
char SceneId_GomaCaveWaterway2
char SceneId_GomaCaveWaterway1
Song and sound effect ids, indices into gSound_SongTable.
#define SE_CAST
Definition songs.h:149
#define SE_188
Definition songs.h:183
#define SE_141
Definition songs.h:134
struct EventWork * gEventWork
void Engine_ActorSetPosition(u32 actor, s32 x, s32 z)
void Engine_AudioPlayCue()
void Engine_TaskWait()
#define NULL
Definition bilibin.h:6
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
u16 rotation
1/65536 turns
Definition animspr.h:118
The options of a spawned field effect, each used when its EFFECT_USE_ flag (or EFFECT_SCALE_TO_TARGET...
s16 type
the object type to create; 222 without the flag
s32 targetScaleY
16.16 fixed point, 0x10000 full size
s32 targetScaleX
16.16 fixed point, 0x10000 full size
s32 startScaleY
16.16 fixed point, 0x10000 full size
s32 startScaleX
16.16 fixed point, 0x10000 full size
s32 startTransition
SCENE_TRANSITION(style, variant).
Definition event_work.h:43
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s32 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:59
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
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
u8 priorityFlags
ActorPriorityFlag bits, read by the scrolling camera.
Definition field_obj.h:51
s32 velocityY
16.16 fixed-point pixels per frame
Definition field_obj.h:53
s32 gravity
Taken off the vertical velocity each frame while it is above the ground, in 16.16 fixed-point pixels ...
Definition field_obj.h:68
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
Definition field_obj.h:116
u16 work
The side of the player's next footprint (2 after a stop), or scene scratch.
Definition field_obj.h:112
u8 collisionFlags
bits: 7 refuses to move into a solid object | 4 nearer for Psynergy targets | 3 never a talk or Psyne...
Definition field_obj.h:91
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
s16 entrance
Definition game_state.h:37
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...
Three coordinates, x, y and z: a position, a velocity or a direction.
Definition vector3.h:11
s32 z
Definition vector3.h:24
s32 x
Definition vector3.h:22
s32 y
Definition vector3.h:23
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.
Vector3, a three-coordinate vector.