Alchemy
Loading...
Searching...
No Matches

ply.c

Go to the documentation of this file.
1/// @file
2/// Ply.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Per-frame update: sways 4 pixels either side of anchorX, once every 128
8/// frames. The update of each spark BattleFx_RunSparkEmitter sheds; it writes
9/// the spark's x and advances its phase.
10void BattleFx_SwayParticle(union FieldObject *fieldObject) {
11 struct SparkObject *obj = (struct SparkObject *)fieldObject;
12 s16 *phase;
13
14 phase = &obj->phase;
15 obj->x = obj->anchorX + Iwram_MulQ16(4 << 16, Trig_Sin(*phase << 9));
16 (*phase)++;
17 *phase = (*phase + 128) % 128;
18}
19
20/// Per-frame update: spirals in on a point 10 pixels above the effect's
21/// position, at a radius of as many pixels as frames are left; released when
22/// timer reaches 0. The update of FieldFx_RunPly's eight spiralling particles;
23/// each one's work holds its starting angle.
25 struct FieldActor *particle = (struct FieldActor *)fieldObject;
26 struct BattleFxScene *scene = gEffectWork;
27 struct EffectVector pos;
28 s16 remainingFrames;
29 s32 decrementedTimer;
30
31 if (particle != NULL) {
32 decrementedTimer = (u16)particle->timer - 1;
33 particle->timer = decrementedTimer;
34 remainingFrames = decrementedTimer;
35 if (remainingFrames != 0) {
36 // The angle turns 1/32 of a circle (0x800) each frame left.
37 pos.x = scene->x;
38 pos.y = scene->y + (10 << 16);
39 pos.z = scene->z;
40 Vector_AddPolarOffset(remainingFrames << 16,
41 (s16)particle->work + (remainingFrames << 11),
42 &pos);
43 particle->x.fixed = pos.x;
44 particle->y.fixed = pos.y;
45 particle->z.fixed = pos.z;
46 } else {
49 }
50 }
51}
52
53/// Per-frame update: sways 6 pixels either side (a 64-frame cycle) 16 pixels
54/// above the effect's position, and every 3 frames sheds a spark that sways
55/// as it slowly falls. With phase -1 it stays where it is. The update
56/// FieldFx_RunPly gives the centre particle; spawns object 0x11d for each
57/// spark.
58void BattleFx_RunSparkEmitter(union FieldObject *fieldObject) {
59 struct SparkObject *emitter = (struct SparkObject *)fieldObject;
60 struct BattleFxScene *scene;
61 s16 *phase;
62 struct SparkObject *spark;
63 s32 pos[3];
64
65 phase = &emitter->phase;
66 scene = gEffectWork;
67 if (*phase != -1) {
68 SET_POSITION(emitter,
69 scene->x + Iwram_MulQ16(6 << 16, Trig_Sin(*phase << 10)),
70 scene->y + ABOVE, scene->z);
71 (*phase)++;
72 *phase = (*phase + 64) % 64;
73 }
74 if (gFrameCount % 3 == 0) {
75 // From 2 pixels up, 0 to 6 pixels in a random direction.
76 SET_VECTOR(pos, emitter->x, emitter->y + (2 << 16), emitter->z);
78 spark = (struct SparkObject *)Object_Spawn(0x11d, pos[0], pos[1], pos[2]);
79 if (spark != 0) {
81 spark->scaleX = spark->scaleY = 0x9999; // 0.6
82 spark->motionFlags = ACTOR_FALLS;
83 spark->gravity = 458;
84 spark->phase = Random16() >> 9;
85 spark->anchorX = spark->x;
87 spark->lifetime = 72;
90 }
91 }
92}
93
94/// Runs FieldFx_RunPly, then stops the caster's hook. Called by
95/// BattleFx_DispatchRequestKind.
96///
97/// Abilities: Ply, Ply Well, Pure Ply (field kind 3), cast on a target.
101}
102
103/// Eight particles spiral into the centre, where one appears, sheds sparks and
104/// flies far away. Called by BattleFx_Run and FieldFx_RunPlyOnTarget; frees
105/// the particles' shared sprite resource slot at the end and runs the effect
106/// scene's finishCallback.
107///
108/// Abilities: Ply, Ply Well, Pure Ply (field kind 3).
109void FieldFx_RunPly(void) {
110 struct BattleFxScene *scene = gEffectWork;
111 struct FieldActor *target = scene->mainObject;
112 struct FieldActor *object;
113 struct AnimationObject *last;
114 u8 resourceSlot;
115 s32 i;
116
118
119 // The spiralling particles: one a frame, each 1/8 turn on from the last.
120 last = 0;
121 for (i = 0; i < 8; i++) {
122 object = (struct FieldActor *)Object_Spawn(
123 233, target->x.fixed, target->y.fixed + 0x200000, target->z.fixed);
124 if (object != 0) {
125 object->scaleY = 0xb333; // 0.7
126 object->scaleX = 0xb333;
128 object->timer = 120;
129 object->work = i << 13;
130 object->motionFlags = 4;
131 last = Sprite_ShareVramCache(object->sprite, last);
132 }
133 WaitFrames(1);
134 }
135
136 // The particles share one sprite cache; keep its slot to free at the end.
137 // XXX: last is read with no check that any particle spawned; a scene with
138 // no free object slots would show whether this can be 0.
139 resourceSlot = last->slot;
141 // The last particle spawned 7 frames ago with 120 frames to live: wait
142 // until the spiral is nearly closed.
143 WaitFrames(110);
144
145 // The one in the centre.
146 target = (struct FieldActor *)Object_Spawn(233, 0, 0, 0);
147 object = target;
148 if (target != 0) {
149 target->scaleY = 0xb333;
150 target->scaleX = 0xb333;
151 target->x.fixed = scene->x;
152 target->y.fixed = scene->y + 0x100000;
153 target->z.fixed = scene->z;
154 target->motionFlags = 4;
156 }
157
159 WaitFrames(12);
160 if (target != 0) {
161 // Switch its sprite param every 2 frames (10 one time in 4).
162 for (i = 0; i < 30; i++) {
163 /* FAKEMATCH(temporary): a redundant copy keeps object as a second
164 * register copy of the spark (r5 beside r6); without it, 129 of 177
165 * instructions differ in tbs-en. */
166 target = object;
167 if (i & 3)
169 else
170 Animation_ApplyChildValuesFar((struct DispatchObject *)object, 10);
171 WaitFrames(2);
172 }
173 }
174
175 // Sparks.
178 if (object != 0) {
180 target->timer = 0;
181 // Cast on a target (enabled cleared by BattleFx_DispatchRequestKind), the
182 // sparks fall for 192 frames instead of 128.
183 if (scene->enabled != 0)
184 WaitFrames(128);
185 else
186 WaitFrames(192);
187 }
188
189 // Fly away: 192 pixels at angle 0xe800, and release it once it arrives.
190 if (target != 0) {
191 target->timer = -1;
192 target->speed = 0x50000;
193 target->acceleration = 0x6666;
194 target->steeringFlags = 0;
196 0xc00000, 0xe800);
199 }
200 // 0x60 is the VRAM cache's entry count, the value Resource_FindFreeEntry
201 // returns for no entry.
202 if (resourceSlot != 0x60)
203 Resource_ResetEntry(resourceSlot);
204 if (scene->finishCallback != 0)
205 scene->finishCallback();
207}
void ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
void FieldObject_WaitForMoveFar(void *fieldObject)
void AudioCommand_PlayFar(s32 id)
@ ACTOR_FALLS
falls by its gravity and bounces
Definition field_obj.h:161
s32 Trig_Sin(s32 angle)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
volatile u32 gFrameCount
Frames WaitFrames has finished.
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 Iwram_MulQ16(left, right)
Definition iwram_call.h:127
#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
#define SET_VECTOR(v, x, y, z)
Sets the x, y and z of a three-part vector: a position about to be projected, a per-frame step,...
Definition macros.h:12
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
struct AnimationObject * Sprite_ShareVramCache(struct AnimationObject *sourceSprite, struct AnimationObject *sharedSprite)
Makes sourceSprite share sharedSprite's VRAM block, releasing its own; with no sharedSprite it keeps ...
Definition dispatch.c:346
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
void EffectRuntime_StopCurrentObject(void)
Stops the caster's per-frame hook and restores its colours.
Definition setup.c:94
void FieldFx_RunPlyOnTarget(s32 unused)
Runs FieldFx_RunPly, then stops the caster's hook.
Definition ply.c:98
void FieldFx_RunPly(void)
Eight particles spiral into the centre, where one appears, sheds sparks and flies far away.
Definition ply.c:109
void BattleFx_RunSparkEmitter(union FieldObject *fieldObject)
Per-frame update: sways 6 pixels either side (a 64-frame cycle) 16 pixels above the effect's position...
Definition ply.c:58
void BattleFx_SwayParticle(union FieldObject *fieldObject)
Per-frame update: sways 4 pixels either side of anchorX, once every 128 frames.
Definition ply.c:10
void BattleFx_UpdateShrinkingOrbitObject(union FieldObject *fieldObject)
Per-frame update: spirals in on a point 10 pixels above the effect's position, at a radius of as many...
Definition ply.c:24
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define ABOVE
16 pixels up
#define SE_131
Definition songs.h:124
#define MUS_084
Definition songs.h:83
#define SE_130
Definition songs.h:123
#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
u8 slot
VRAM cache entry holding its tiles.
Definition animspr.h:112
The work of a Psynergy effect scene: its caster and target, where it takes place, the map state it re...
Definition fx_scene.h:31
s32 y
16.16 fixed-point pixels
Definition fx_scene.h:34
void(*) finishCallback(void)
run, when set, as Ply's effect ends
Definition fx_scene.h:48
void * mainObject
the caster's object
Definition fx_scene.h:36
s8 enabled
Set at the start: Force then aims in front of the caster; cleared once the target has been dispatched...
Definition fx_scene.h:44
s32 x
16.16 fixed-point pixels
Definition fx_scene.h:33
s32 z
16.16 fixed-point pixels
Definition fx_scene.h:35
A field object as the object dispatcher's far calls take it.
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
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s16 timer
The parameter its action script reads (a follow distance or an angle to face), the player's frames to...
Definition field_obj.h:109
s32 speed
speed limit, 16.16 fixed-point pixels per frame
Definition field_obj.h:55
u8 steeringFlags
ActorSteeringFlag bits.
Definition field_obj.h:92
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
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
Definition field_obj.h:58
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition field_obj.h:39
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition field_obj.h:40
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
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
A FieldActor seen with the halfword at 0x5e (its lifetime), which FieldActor does not name.
s16 phase
phase of the sway (128 frames a cycle)
s32 anchorX
centre of the sway (FieldActor's targetX)
s32 gravity
as in FieldActor
void(*) update(union FieldObject *object)
u8 motionFlags
as in FieldActor
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106