Alchemy
Loading...
Searching...
No Matches

mars.c

Go to the documentation of this file.
1/// @file
2/// A Mars Djinni joining the party.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// A Mars Djinni joins the party: it turns to the camera, bounces three times,
8/// spins ever faster and shrinks away in a fountain of 24 sparks
9/// (BattleEffect_UpdatePhasedRadialParticle). The leader turns to the camera
10/// and plays animation 28, the sparks swarm the leader, who pulses for 100
11/// frames, and the sparks vanish. Called by Djinn_JoinParty for a Mars Djinni,
12/// which then clears the Djinni's actor slot. Uses all 24 effect slots, tints
13/// the field palette red and fades it back at the end.
15 struct EffectVector position;
16 s32 scale;
17 s32 remaining;
18 struct FieldActor *djinni;
19 struct BattleFxScene *effectScene;
20 struct FieldActor *leader;
21 struct EffectSlot *slot;
22 s8 *slotState;
23
24 djinni = Object_GetById(djinniId);
26 if (djinni == NULL)
27 return;
28
30 effectScene = gEffectWork;
31 // Tint the screen red: PALETTE_TRANSFORM_TINT | RGB(16, 4, 4), the form
32 // mercury.c spells out for its blue.
34 WaitFrames(30);
35 // Turn to face the camera (angle 0x4000), then bounce three times, a rising
36 // note on each.
37 ObjectMotion_ArmCallback(djinniId, 0x4000, 0);
38 WaitFrames(20);
40 Motion_SetVarCbAndRefresh(djinniId, 1);
42 Motion_SetVarCbAndRefresh(djinniId, 1);
44 Motion_SetVarCbAndRefresh(djinniId, 1);
45 // Spin up for 80 frames, then spin and shrink away.
46 WaitFrames(20);
49 djinni->timer = 0;
50 WaitFrames(80);
53
54 // The sparks start where the Djinni is on screen.
55 position.x = djinni->x.fixed;
56 position.y = djinni->y.fixed;
57 position.z = djinni->z.fixed;
58 Camera_WorldToScreen(&position);
59
60 // One spark a frame into each of the 24 effect slots.
61 slot = effectScene->slots;
62 remaining = 23;
63 do {
64 EffectSlot_Initialize(slot, 284, position.x, position.z);
68 scale = Random16() / 3 + 0x10000; // 1.0 to 1.33
69 slot->scaleY = scale;
70 slot->scaleX = scale;
71 remaining--;
72 WaitFrames(1);
73 slot++;
74 } while (remaining >= 0);
75
76 WaitFrames(60);
78 WaitFrames(20);
80 28);
81
82 // Every spark still in use stops its fountain (state 2). The cursor walks
83 // the slots' state bytes; a slot's active flag is 5 bytes after its state.
84 {
85 s32 nextState;
86
87 WaitFrames(20);
88 nextState = 2;
89 slotState = &effectScene->slots[0].state;
90 remaining = 23;
91 do {
92 if (slotState[5] != 0)
93 slotState[0] = nextState;
94 remaining--;
95 slotState += sizeof(struct EffectSlot);
96 } while (remaining >= 0);
97 }
98
99 // The leader pulses while the sparks swarm it.
100 WaitFrames(60);
102 WaitFrames(100);
103
104 // Every spark still in use goes (state 5). This loop's cursor starts as
105 // the scene plus 152, the first slot's state: written as above, the
106 // cursor's two loads swap (differ 22).
107 {
108 s32 nextState;
109
110 slotState = (s8 *)effectScene;
111 nextState = 5;
112 slotState += offsetof(struct BattleFxScene, slots) +
113 offsetof(struct EffectSlot, state);
114 remaining = 23;
115 do {
116 if (slotState[5] != 0)
117 slotState[0] = nextState;
118 remaining--;
119 slotState += sizeof(struct EffectSlot);
120 } while (remaining >= 0);
121 }
122
123 // The leader stops pulsing. Storing NULL through the cleared slot cursor,
124 // as the bytes do: a plain NULL store differs by 9.
125 WaitFrames(10);
126 slot = NULL;
127 leader->update = (void *)slot;
128 leader->scaleX = 0x10000;
129 leader->scaleY = 0x10000;
130 // Fade the palette back from the tint and free the effect slots.
131 WaitFrames(30);
134}
135
136/// Spins and shrinks an object by 0x400 a frame, then releases it.
138
139/// Per-frame update of a Venus Djinni's falling motes: each circles the
140/// leader on a shrinking spiral (radius timer * 0.4 pixels) while it sinks a
141/// pixel a frame, and is released 20 pixels above the leader's feet. Set by
142/// BattleFx_RunVenusDjinnCapture in venus.c.
144 struct DescendingOrbitObject *mote =
145 (struct DescendingOrbitObject *)fieldObject;
146 struct EffectVector position;
147 struct DescendingOrbitObject *leader;
148 s32 timer;
149 s16 frames;
150 s32 y;
151
152 leader =
154 timer = mote->timer - 1;
155 mote->timer = timer;
156 frames = mote->timer;
157 position.x = leader->x;
158 position.z = leader->z;
159 Vector_AddPolarOffset(frames * 0x6666, (frames << 11) + mote->angle,
160 &position);
161 mote->x = position.x;
162 mote->z = position.z;
163 y = mote->y + 0xFFFF0000;
164 mote->y = y;
165 if (y < leader->y + 0x140000)
167}
168
169/// Effect slot callback of a Venus Djinni's particles: each starts on screen
170/// at a random point 10 to 20 pixels round the leader and flies 120 pixels up
171/// the screen, over and over (states 0 and 1); set to 2, it is freed once it
172/// arrives. Set by BattleFx_RunVenusDjinnCapture in venus.c; a particle
173/// that starts on an odd frame plays SE_144.
175 struct EffectVector position;
176 struct ObjectRuntime *source;
177 s32 state;
178 u32 random;
179
181 state = effect->state;
182
183 if (state == 0) {
184 position.x = source->x;
185 position.y = source->y;
186 position.z = source->z;
187
188 random = Random16() * 10 + 0xa0000;
189 Vector_AddPolarOffset(random, Random16(), &position);
190 Camera_WorldToScreen(&position);
191
192 effect->originX = position.x;
193 effect->originZ = position.z;
194 effect->x = position.x;
195 effect->z = position.z;
196 position.x = effect->x;
197 position.z = effect->z;
198
199 Vector_AddPolarOffset(0x780000, 0xc000, &position);
200 effect->targetX = position.x;
201 effect->targetZ = position.z;
202 effect->acceleration = 0x10000;
203 effect->maxSpeed = 0x50000;
204 effect->limitTurnStep = state;
205 effect->state++;
206
207 if ((gFrameTick & 1) != 0)
209 } else if (state == 1) {
210 if (EffectSlot_HasPendingTarget(effect) == 0)
211 effect->state--;
212 } else if (state == 2) {
213 if (EffectSlot_HasPendingTarget(effect) == 0)
215 }
216}
void Motion_SetVarCbAndRefresh(u32 objectId, s32 count)
The event command "run repeated motion": as ObjectMotion_SetVariantCallback, then waits for it to end...
void ObjectMotion_ArmCallback(s32 objectId, s32 angle, s32 wait)
The event command "actor face direction": the actor turns toward angle (0x10000 a full turn; ObjectMo...
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
void BattleFx_InitializeSlots(void)
Allocates and clears the effect slots (heap block 56) and starts their update callback.
Definition djinni.c:261
void BattleFx_ClearActiveSlotsAndScheduleUpdates(void)
Stops the effect slots: removes their callback, frees every slot still in use and releases their heap...
Definition djinni.c:271
u32 EffectSlot_HasPendingTarget(struct EffectSlot *effect)
Returns nonzero while an effect slot that stops at its target still has one (it has not arrived),...
void BattleFx_ClearOwnedSlot(struct EffectSlot *slot)
Frees an effect slot and its sprite.
void EffectSlot_Initialize(struct EffectSlot *effect, s32 kind, s32 x, s32 z)
Fills an effect slot with a new sprite of kind at (x, z): stopping at its target, top speed 2,...
void EffectSlot_SetCallback(struct EffectSlot *effect, EffectCallback callback)
Gives an effect slot its per-frame callback, starting at state 0.
void EffectSlot_SetObjectMode(struct EffectSlot *effect, s32 mode)
Sets the animation of an effect slot's sprite.
void ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectGroup_SetChildValueUnlessFifteenFar(void *raw_parent, u32 value)
void Shop_RestoreFieldPaletteFar(void)
void Shop_SaveAndTintFieldPaletteFar(s32 layer)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
u32 gFrameTick
Counted up by every VBlank.
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
void BattleFx_SetObjectAlternatingWords(union FieldObject *fieldObject)
Per-frame update: makes an object pulse, switching its scale between the two values of gBattleFx_Puls...
Definition jupiter.c:86
void BattleEffect_UpdatePhasedRadialParticle(struct EffectSlot *effect)
Effect slot callback of a Mars Djinni's sparks.
Definition jupiter.c:117
void BattleFx_ShrinkObjectAndDestroySlow(union FieldObject *fieldObject)
Spins and shrinks an object by 0x1c0 a frame, then releases it.
Definition jupiter.c:110
void BattleFx_AdvanceAngleWithRamp(union FieldObject *fieldObject)
Per-frame update: spins an object ever faster, from 1/16 turn a frame up to 1/8.
Definition jupiter.c:97
void BattleFx_ShrinkObjectAndDestroyFast(union FieldObject *fieldObject)
Spins and shrinks an object by 0x400 a frame, then releases it.
Definition mars.c:137
void BattleFx_UpdateDescendingOrbitObject(union FieldObject *fieldObject)
Per-frame update of a Venus Djinni's falling motes: each circles the leader on a shrinking spiral (ra...
Definition mars.c:143
void Djinn_RunMarsJoinEffect(s32 djinniId)
A Mars Djinni joins the party: it turns to the camera, bounces three times, spins ever faster and shr...
Definition mars.c:14
void BattleFx_UpdateRadialSpread(struct EffectSlot *effect)
Effect slot callback of a Venus Djinni's particles: each starts on screen at a random point 10 to 20 ...
Definition mars.c:174
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 Camera_WorldToScreen(struct EffectVector *position)
Converts a world position (16.16 pixels) to the screen: x and z receive the screen's x and y and y be...
Definition setup.c:293
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define DEFINE_SHRINK_AND_DESTROY(name, step)
Defines a per-frame update that spins an object 1/8 turn a frame while its scale changes by step,...
#define SE_144
Definition songs.h:137
#define SE_173
Definition songs.h:168
#define SE_174
Definition songs.h:169
#define SE_175
Definition songs.h:170
#define SE_140
Definition songs.h:133
#define NULL
Definition bilibin.h:6
#define offsetof(type, member)
Definition stddef.h:19
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
struct EffectSlot slots[24]
Definition fx_scene.h:73
A FieldActor seen with the halfword at 0x64 unsigned and the one at 0x66 signed, as the bytes read th...
A field object as the object dispatcher's far calls take it.
A particle a Psynergy effect moves and draws: its sprite, its position and target,...
Definition effect_slot.h:18
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition effect_slot.h:30
s8 state
the callback's own step; 0 when it is given
Definition effect_slot.h:38
void * object
the slot's sprite, released with the slot
Definition effect_slot.h:19
s32 originX
16.16 fixed-point pixels; where the slot started
Definition effect_slot.h:24
s32 z
16.16 fixed-point pixels
Definition effect_slot.h:21
s32 x
16.16 fixed-point pixels
Definition effect_slot.h:20
s8 limitTurnStep
Clamp steering to maxTurnStep; zero faces the target directly.
Definition effect_slot.h:40
s32 originZ
16.16 fixed-point pixels; where the slot started
Definition effect_slot.h:25
s32 targetZ
16.16 fixed-point pixels; EFFECT_NO_TARGET at rest
Definition effect_slot.h:23
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition effect_slot.h:29
s32 targetX
16.16 fixed-point pixels; EFFECT_NO_TARGET at rest
Definition effect_slot.h:22
s32 maxSpeed
16.16 fixed-point pixels per frame
Definition effect_slot.h:27
s32 acceleration
16.16 fixed-point pixels per frame, each frame
Definition effect_slot.h:28
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
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 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
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.