Alchemy
Loading...
Searching...
No Matches

douse.c

Go to the documentation of this file.
1/// @file
2/// Douse.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// A FieldActor seen with the halfword at 0x5e (here its phase), which
8/// FieldActor does not name.
11 s32 x, y, z;
12 s32 altitude; ///< the height it falls to
25 void (*callback)(union FieldObject *object); ///< per-frame update
26};
27
28/// Douse's effect work: the orb's destination (or the angle toward it), the
29/// target, and the flags that choose how the light falls.
31 s32 angle; ///< 1/65536 turns
32 s32 x, y, z; ///< the ground under the orb's destination
33 struct Object *target;
41};
42
43/// Per-frame update of a falling particle: on reaching altitude, it scatters
44/// three small particles.
46 struct Effect05Object *particle = (struct Effect05Object *)fieldObject;
47 s32 i;
48 struct Effect05Object *p;
49 s32 phase = 2;
50 s32 phase2;
51 s16 *pp;
52
53 if (particle->y <= particle->altitude) {
54 particle->phase = phase;
57 p = NULL;
58 particle->callback = NULL;
59
60 // Half size, hopping up at a pixel a frame, toward a random point 32 pixels
61 // away.
62 for (i = 0; i <= 2; i++) {
63 p = (struct Effect05Object *)Object_Spawn(0xf0, particle->x, particle->y,
64 particle->z);
65 if (p == NULL) {
66 break;
67 }
68 p->scaleY = 0x8000;
69 p->scaleX = 0x8000;
70 p->flag = 2;
71 p->velocityY = 1 << 16;
72 p->speed = Random16() + 0x13333;
74 32 << 16, Random16());
75 pp = &p->phase;
76 phase2 = 6;
77 *pp = phase2;
80 }
81 }
82}
83
84/// Per-frame update: drifts from side to side as it slowly falls, and is
85/// released on reaching the ground.
87 struct ObjectRuntime *particle = (struct ObjectRuntime *)fieldObject;
88 s32 drift;
89
90 particle->y -= 0x4ccc;
91 drift = Random16();
92 particle->x += drift - Random16();
93 if (particle->y <= particle->terrainHeight) {
96 }
97}
98
99/// Runs Douse cast on a target, through FieldFx_RunDouse.
100///
101/// Abilities: Douse (field kind 5), cast on a target.
103
104/// An orb of light rises from 16 pixels above the target to 32 pixels above the
105/// destination (80 with variant) over 10 frames, growing as it goes, rains
106/// particles, and returns.
107///
108/// Abilities: Douse (field kind 5).
109///
110/// With no destination yet, the destination is 16 pixels from the target toward
111/// angle.
113 struct EffectVector pos;
114 struct EffectVector start;
115 struct EffectVector end;
116 struct Effect05State *work = gEffectWork;
117 struct Object *target = work->target;
118 struct Effect05Object *lightOrb;
119 struct EffectVector *from;
120 struct EffectVector *to;
121 s32 step;
122 s32 steps = 11;
123 s32 count;
124 s32 y;
125 struct Effect05Object *particle;
126
127 lightOrb = (struct Effect05Object *)Object_Spawn(0xef, step = 0, 0, 0);
128 if (lightOrb == 0)
129 return;
132 if (work->initialized == 0) {
133 work->x = target->pos.x;
134 work->z = target->pos.z;
135 Vector_AddPolarOffset(16 << 16, work->angle,
136 (struct EffectVector *)&work->x);
137 work->y = Map_GetTerrainHeightFar(0, work->x, work->z);
138 }
139 from = &start;
140 SET_POSITION(from, target->pos.x, target->pos.y + (16 << 16), target->pos.z);
141 to = &end;
142 to->x = work->x;
143 y = work->y;
144 to->y = y + (32 << 16);
145 to->z = work->z;
146 if ((s8)work->variant != 0)
147 to->y = y + (80 << 16);
148
149 // Grow from a quarter to full size on the way.
150 for (; step < steps; step++) {
151 s32 scale;
152
153 {
154 struct EffectVector *a = &start;
155 struct EffectVector *b = &end;
156 s32 e, t;
157
158 e = b->x;
159 t = a->x;
160 t += step * (e - t) / 10;
161 lightOrb->x = t;
162 e = b->y;
163 t = a->y;
164 t += step * (e - t) / 10;
165 lightOrb->y = t;
166 e = b->z;
167 t = a->z;
168 t += step * (e - t) / 10;
169 lightOrb->z = t;
170 }
171 scale = BattleFx_Interpolate(0x10000, 0x4000, step);
172 lightOrb->scaleX = scale;
173 lightOrb->scaleY = scale;
174 WaitFrames(1);
175 }
176 WaitFrames(10);
177
178 if ((s8)work->alternate == 0) {
179 // Drop a particle every 6 frames from 3 to 8 pixels round the orb (the
180 // last right under it).
181 count = 10;
182 if ((s8)work->highArc == 0)
183 count = 24;
184 for (step = 0; step < count; step++) {
185 pos.x = lightOrb->x;
186 pos.y = lightOrb->y;
187 pos.z = lightOrb->z;
188 Vector_AddPolarOffset(Random16() * 5 + (3 << 16), Random16(), &pos);
189 if (step == count - 1) {
190 WaitFrames(25);
191 pos.x = lightOrb->x;
192 pos.y = lightOrb->y;
193 pos.z = lightOrb->z;
194 }
195 particle =
196 (struct Effect05Object *)Object_Spawn(0xf0, pos.x, pos.y, pos.z);
197 if (particle != 0) {
198 particle->altitude = pos.y - (32 << 16);
200 particle->flag = 2;
201 }
203 WaitFrames(6);
204 }
205 WaitFrames(10);
206 } else {
207 // Every 6 frames, a swaying particle falls from 3 to 8 pixels round the
208 // orb.
209 if ((s8)work->highArc != 0)
210 count = 10;
211 else
212 count = 30;
213 for (step = 0; step < count; step++) {
214 pos.x = lightOrb->x;
215 pos.y = lightOrb->y;
216 pos.z = lightOrb->z;
217 Vector_AddPolarOffset(Random16() * 5 + (3 << 16), Random16(), &pos);
218 particle =
219 (struct Effect05Object *)Object_Spawn(0x11c, pos.x, pos.y, pos.z);
220 if (particle != 0) {
222 particle->flag = 0;
223 particle->sprite->mode = 2;
225 Animation_ApplyChildValuesFar((struct DispatchObject *)particle, 7);
226 }
227 WaitFrames(6);
228 }
229 WaitFrames(70);
230 }
231
232 // Shrink back to a quarter on the way back over the target.
233 step = 0;
234 do {
235 s32 scale;
236
237 {
238 struct EffectVector *a = &end;
239 struct EffectVector *b = &start;
240 s32 e, t;
241
242 e = b->x;
243 t = a->x;
244 t += step * (e - t) / 10;
245 lightOrb->x = t;
246 e = b->y;
247 t = a->y;
248 t += step * (e - t) / 10;
249 lightOrb->y = t;
250 e = b->z;
251 t = a->z;
252 t += step * (e - t) / 10;
253 lightOrb->z = t;
254 }
255 scale = BattleFx_Interpolate(0x4000, 0x10000, step);
256 lightOrb->scaleX = scale;
257 lightOrb->scaleY = scale;
258 WaitFrames(1);
259 step++;
260 } while (step < steps);
261 ObjectDispatch_ReleaseFar((struct DispatchObject *)lightOrb);
263}
void FieldFx_SpawnRandomAngleTriplet(union FieldObject *fieldObject)
Per-frame update of a falling particle: on reaching altitude, it scatters three small particles.
Definition douse.c:45
void FieldFx_RunDouse(void)
An orb of light rises from 16 pixels above the target to 32 pixels above the destination (80 with var...
Definition douse.c:112
void BattleFx_UpdateDriftingFallObject(union FieldObject *fieldObject)
Per-frame update: drifts from side to side as it slowly falls, and is released on reaching the ground...
Definition douse.c:86
void FieldFx_RunDouseOnTarget(s32 unused)
Runs Douse cast on a target, through FieldFx_RunDouse.
Definition douse.c:102
void ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
s32 Map_GetTerrainHeightFar(s32 layer, s32 x, s32 y)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
static __inline__ s32 BattleFx_Interpolate(s32 to, s32 from, s32 step)
Definition fx_scene.h:90
const s32 gBattleFx_CommonParticleScript[]
[0] only frees the actor, +1 waits for it to arrive and frees it; +3 is gBattleFx_SourceHoldScript,...
Definition fxdata.c:444
void * gEffectWork
Slot 56: points to a scene-specific structure.
#define SET_POSITION(p, px, py, pz)
Sets the position or the velocity of a particle, a piece of debris or an object in one statement.
Definition macros.h:16
void Vector_AddPolarOffset(s32 radius, s32 angle, void *position)
Moves the point position by radius in direction angle on the ground plane: x by the cosine,...
Definition math.c:23
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
void Motion_SetTargetPositionFromMagnitudeAngle(struct ObjectRuntime *object, s32 magnitude, s32 angle)
Sends an object toward the point magnitude (16.16 pixels) away from it in direction angle: sets its m...
Definition dispatch.c:308
struct ObjectRuntime * Object_Spawn(s32 kind, s32 x, s32 y, s32 z)
Creates an object for an effect, at the caster's ground height, with sprite priority 0 and animation ...
Definition dispatch.c:371
void BattleEffect_InitializeSharedScene(void)
Saves the palettes for the effect (once, unless an effect is already shown) and fades them toward one...
Definition setup.c:236
void BattleFx_PrepareBufferInterpolation(void)
Fades the palettes back from an effect's colours to the saved ones (or to palette 0x10001 while an ef...
Definition setup.c:275
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define SE_132
Definition songs.h:125
#define SE_ITEM_BREAK
Definition songs.h:131
#define NULL
Definition bilibin.h:6
A field object as the object dispatcher's far calls take it.
A FieldActor seen with the halfword at 0x5e (here its phase), which FieldActor does not name.
Definition douse.c:9
u8 reserved20[8]
Definition douse.c:14
void(*) callback(union FieldObject *object)
per-frame update
Definition douse.c:25
u8 reserved34[0x1c]
Definition douse.c:18
u8 reserved56[8]
Definition douse.c:22
s32 altitude
the height it falls to
Definition douse.c:12
s32 velocityY
Definition douse.c:15
struct WaveFxSprite * sprite
Definition douse.c:19
u8 reserved60[0xc]
Definition douse.c:24
u8 reserved2c[4]
Definition douse.c:16
u8 reserved00[8]
Definition douse.c:10
u8 reserved54
Definition douse.c:20
Douse's effect work: the orb's destination (or the angle toward it), the target, and the flags that c...
Definition douse.c:30
struct Object * target
Definition douse.c:33
s32 z
the ground under the orb's destination
Definition douse.c:32
u8 alternate
Definition douse.c:40
u8 reserved21[0x13]
Definition douse.c:37
u8 reserved18[8]
Definition douse.c:35
s32 angle
1/65536 turns
Definition douse.c:31
s32 initialized
Definition douse.c:34
u8 reserved35[0x10]
Definition douse.c:39
A world position, as Camera_WorldToScreen converts it to the screen.
Definition battle.h:73
s32 y
16.16 fixed-point pixels
Definition battle.h:75
s32 z
16.16 fixed-point pixels
Definition battle.h:76
s32 x
16.16 fixed-point pixels
Definition battle.h:74
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 terrainHeight
16.16 fixed-point pixels
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
A field actor (struct FieldActor), seen with its position as one vector.
Definition run_scene.c:389
struct EffectVector pos
Definition run_scene.c:392
A particle's sprite, seen as the two fields Douse and Mind Read set on it.
signed int s32
Definition types.h:14
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
unsigned char u8
Definition types.h:11
An object on the field, read as an actor or as an effect.