Alchemy
Loading...
Searching...
No Matches

frost.c

Go to the documentation of this file.
1/// @file
2/// Frost.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Per-frame update: flashes (animation 2) for 2 frames in every 8.
9 struct FieldActor *particle = (struct FieldActor *)fieldObject;
10 s32 frame = gFrameCount & 7;
11 if (frame == 0) {
12 Animation_ApplyChildValuesFar((struct DispatchObject *)particle, 2);
13 } else if (frame == 2) {
14 Animation_ApplyChildValuesFar((struct DispatchObject *)particle, 0);
15 }
16}
17
18/// Per-frame update: shrinks by 1/16 a frame and is released at 1/16.
20 struct FieldActor *particle = (struct FieldActor *)fieldObject;
21 s32 scale;
22
23 if (particle != NULL) {
24 scale = particle->scaleX - 0x1000;
25 particle->scaleY -= 0x1000;
26 particle->scaleX = scale;
27 if (scale <= 0x1000)
30 }
31}
32
33/// Both winding directions share the countdown and position update. timer is
34/// initialized to 60; preserve its halfword narrowing before computing radius.
35static inline void FieldFx_UpdateSpiralParticle(union FieldObject *fieldObject,
36 s32 clockwise) {
37 struct FieldActor *particle = (struct FieldActor *)fieldObject;
38 struct EffectVector position;
39 s16 remainingFrames;
40 s32 decrementedTimer;
41
42 if (particle != NULL) {
43 decrementedTimer = (u16)particle->timer - 1;
44 particle->timer = decrementedTimer;
45 remainingFrames = decrementedTimer;
46 if (remainingFrames != 0) {
47 position.x = particle->targetX;
48 position.y = particle->targetY;
49 position.z = particle->targetZ;
50 Vector_AddPolarOffset(remainingFrames << 17,
51 clockwise
52 ? (s16)particle->work - (remainingFrames << 11)
53 : (s16)particle->work + (remainingFrames << 11),
54 &position);
55 particle->x.fixed = position.x;
56 particle->y.fixed = position.y;
57 particle->z.fixed = position.z;
58 } else {
60 }
61 }
62}
63
64/// Spirals anticlockwise at twice the frames left in pixels, then fades.
66 FieldFx_UpdateSpiralParticle(fieldObject, 0);
67}
68
69/// Per-frame update: as BattleFx_UpdateOrbitingParticleLeft, clockwise.
71 FieldFx_UpdateSpiralParticle(fieldObject, 1);
72}
73
74/// Runs Frost cast on a target.
75///
76/// Abilities: Frost (field kind 6), cast on a target (scene->child).
77///
78/// With childMode the target is left as it is and only the particles appear.
80 struct BattleFxScene *scene = gEffectWork;
81 struct FieldActor *target = scene->child;
82
83 if (target != 0) {
84 if (scene->childMode != 0) {
85 scene->enabled = 1;
86 }
89 }
90}
91
92/// 16 particles spiral in on the effect's position and make the target flash 16
93/// times; without childOption the target takes mode 2.
94///
95/// Abilities: Frost (field kind 6).
96void FieldFx_RunFrost(void) {
97 s32 eventTarget;
98 struct EffectVector pos;
99 struct EffectVector *p;
100 struct BattleFxScene *scene;
101 struct FieldActor *target;
102 struct FieldActor *particle;
103 void *event;
104 s32 remainingCycles;
105
106 scene = gEffectWork;
107 target = scene->child;
110
111 // A particle every 3 frames, 0.5 to 1 size, turning either way at random,
112 // centred 2 to 6 pixels from the effect's position.
113 p = &pos;
114 remainingCycles = 15;
115 do {
116 particle = (struct FieldActor *)Object_Spawn(0xe8, 0, 0, 0);
117 if (particle != NULL) {
118 u32 scale;
119 s32 radius;
120
121 scale = (Random16() >> 1) + 0x8000;
122 particle->scaleY = scale;
123 particle->scaleX = scale;
124 if ((Random16() & 1) != 0)
126 else
128
129 particle->facing = Random16();
130 particle->timer = 60;
131 particle->work = Random16();
132 Animation_ApplyChildValuesFar((struct DispatchObject *)particle, 9);
133
134 SET_POSITION(p, scene->x, scene->y, scene->z);
135 radius = (Random16() << 2) + (2 << 16);
137 particle->targetX = p->x;
138 particle->targetY = p->y;
139 particle->targetZ = p->z;
140 }
141
142 WaitFrames(3);
143 remainingCycles--;
144 } while (remainingCycles >= 0);
145
146 WaitFrames(10);
148 WaitFrames(50);
149
150 if (target != NULL && scene->enabled == 0) {
152
153 // Flash for 1 frame in every 5.
154 remainingCycles = 15;
155 do {
157 WaitFrames(1);
159 WaitFrames(4);
160 remainingCycles--;
161 } while (remainingCycles >= 0);
162
163 if (scene->childOption == 0) {
166 }
167
169 event = BattleFx_FindMatchingEvent(0x50000005, 6, &eventTarget);
170 if (event != NULL) {
171 Field_RunEventAction(event, gGameState.selectedActor, eventTarget);
172 }
173 WaitFrames(20);
174 }
175
177}
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)
@ ACTOR_PRIORITY_UNDERFOOT
The depth sort treats it as 320 pixels higher on the screen.
Definition field_obj.h:155
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
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
void * BattleFx_FindMatchingEvent(s32 eventFlags, s32 group, void *target)
Returns the scene's Psynergy event (kind 5) for Psynergy of the given group that applies to what the ...
Definition items.c:206
#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
s32 Field_RunEventAction(const void *event, s32 param, s32 target)
Runs the event tied to an effect: a result below 0x10000 is a message, shown at target; a larger one ...
Definition dispatch.c:242
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 BattleFx_UpdateOrbitingParticleLeft(union FieldObject *fieldObject)
Spirals anticlockwise at twice the frames left in pixels, then fades.
Definition frost.c:65
static void FieldFx_UpdateSpiralParticle(union FieldObject *fieldObject, s32 clockwise)
Both winding directions share the countdown and position update.
Definition frost.c:35
void FieldFx_RunFrost(void)
16 particles spiral in on the effect's position and make the target flash 16 times; without childOpti...
Definition frost.c:96
void FieldFx_RunFrostOnTarget(s32 unused)
Runs Frost cast on a target.
Definition frost.c:79
void BattleFx_UpdateOrbitingParticleMain(union FieldObject *fieldObject)
Per-frame update: flashes (animation 2) for 2 frames in every 8.
Definition frost.c:8
void BattleFx_UpdateOrbitingParticleFade(union FieldObject *fieldObject)
Per-frame update: shrinks by 1/16 a frame and is released at 1/16.
Definition frost.c:19
void BattleFx_UpdateOrbitingParticleRight(union FieldObject *fieldObject)
Per-frame update: as BattleFx_UpdateOrbitingParticleLeft, clockwise.
Definition frost.c:70
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_220
Definition songs.h:215
#define SE_115
Definition songs.h:108
#define SE_212
Definition songs.h:207
#define NULL
Definition bilibin.h:6
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
s8 childOption
Set by some scenes before an effect; Carry, Frost, Force and Reveal treat the target differently with...
Definition fx_scene.h:52
s8 childMode
set by some scenes: Frost and Force leave the target be
Definition fx_scene.h:53
void * child
the target's object, or NULL
Definition fx_scene.h:37
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 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:59
u16 radius
Collision radius in pixels: 16, or half the sprite metadata's boxY, when created; the overlap checks ...
Definition field_obj.h:43
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
s32 targetZ
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:61
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
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
u16 facing
1/65536 turns
Definition field_obj.h:34
s32 targetY
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:60
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
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
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
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.