Alchemy
Loading...
Searching...
No Matches

mercury.c

Go to the documentation of this file.
1/// @file
2/// A Mercury Djinni joining the party.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7#define MERCURY_PARTICLE_MAX 24 ///< droplets (one an effect slot)
8#define MERCURY_AFTERIMAGE_MAX 8 ///< afterimages of the rising Djinni
9/// A Mercury Djinni joins the party: the screen is tinted blue, the Djinni
10/// bounces twice and hops three times ever higher, then rises 120 pixels out
11/// of sight trailing eight afterimages. The leader turns to the camera and
12/// plays animation 28 while 24 droplets rain round it, one a frame
13/// (BattleFx_UpdateRandomTargetParticle); then the colours return.
15 struct FieldActor *djinni;
16 struct FieldActor *copy;
17 struct FieldActor *previous;
18 struct AnimationObject *resource;
19 struct BattleFxScene *effectScene;
20 struct FieldActor **cursor;
21 struct FieldActor **list;
22 struct EffectSlot *slot;
23 s8 *slotState;
24 s32 kind;
25 s32 remaining;
26 s32 resourceId;
27 struct FieldActor *copies[MERCURY_AFTERIMAGE_MAX];
28 struct EffectVector position;
29
30 djinni = Object_GetById(djinniId);
31 if (djinni == NULL)
32 return;
33
34 // Tint the screen blue (red 4, green 4, blue 16).
36 effectScene = gEffectWork;
38 WaitFrames(30);
39 djinni->paused = 0;
41 Motion_SetVarCbAndRefresh(djinniId, 1);
43 Motion_SetVarCbAndRefresh(djinniId, 1);
44 WaitFrames(20);
45
46 // Three hops, at 3, 5 and 7 pixels a frame.
48 ObjectMotion_Launch(djinniId, 3, 14);
50 ObjectMotion_Launch(djinniId, 5, 16);
52 ObjectMotion_Launch(djinniId, 7, 18);
53 WaitFrames(20);
54
55 // Eight afterimages of the same sprite, each closing half the distance to
56 // the one before it every frame.
57 kind = djinni->sprite->entries[0]->animId;
58 resource = NULL;
59 previous = djinni;
60 cursor = copies;
61 for (remaining = MERCURY_AFTERIMAGE_MAX - 1; remaining >= 0; remaining--) {
62 copy = (struct FieldActor *)Object_CreateFar(
63 kind, djinni->x.fixed, djinni->y.fixed, djinni->z.fixed);
64 *cursor++ = copy;
65 if (copy != NULL) {
66 copy->scaleY = 0xf000;
67 copy->scaleX = 0xf000;
68 copy->motionFlags = 0;
69 copy->priorityFlags = 2;
70 copy->steeringFlags |= 1;
72 copy->facing = djinni->facing;
76 resource = Sprite_ShareVramCache(copy->sprite, resource);
77 copy->linkedObject = previous;
78 previous = copy;
79 }
80 }
81
82 // Rise 8 pixels a frame for 15 frames, then remove the Djinni and its
83 // afterimages (and their VRAM block, unless it is the shared block 96).
84 resourceId = resource->slot;
86 djinni->motionFlags = 0;
87 for (remaining = 14; remaining >= 0; remaining--) {
88 djinni->y.fixed += 8 << 16;
89 WaitFrames(1);
90 }
92 list = copies;
93 for (remaining = MERCURY_AFTERIMAGE_MAX - 1; remaining >= 0; remaining--)
94 ObjectDispatch_ReleaseFar((struct DispatchObject *)(*list++));
95 if (resourceId != 96)
96 Resource_ResetEntry(resourceId);
97 WaitFrames(10);
99 WaitFrames(20);
101 28);
102 WaitFrames(20);
103
104 // The droplets (object 240), one a frame, from where the Djinni was on
105 // screen (BattleFx_UpdateRandomTargetParticle moves them).
106 position.x = djinni->x.fixed;
107 position.y = djinni->y.fixed;
108 position.z = djinni->z.fixed;
109 Camera_WorldToScreen(&position);
110
111 slot = effectScene->slots;
112 remaining = MERCURY_PARTICLE_MAX - 1;
113 do {
114 EffectSlot_Initialize(slot, 240, position.x, position.z);
118 remaining--;
119 WaitFrames(1);
120 slot++;
121 } while (remaining >= 0);
122
123 // After 120 frames every droplet still in use goes on to state 2.
124 // Walking whole slots instead of their state bytes grows native English
125 // from 0x23c to 0x240 bytes.
126 WaitFrames(120);
127 {
128 s32 nextState;
129
130 nextState = 2;
131 slotState = (s8 *)effectScene;
132 slotState += offsetof(struct BattleFxScene, slots) +
133 offsetof(struct EffectSlot, state);
134 remaining = MERCURY_PARTICLE_MAX - 1;
135 do {
136 if (slotState[5] != 0) // active
137 slotState[0] = nextState;
138 remaining--;
139 slotState += sizeof(struct EffectSlot);
140 } while (remaining >= 0);
141 }
142
143 // Restore the colours.
144 WaitFrames(50);
147}
148
149#undef MERCURY_PARTICLE_MAX
150#undef MERCURY_AFTERIMAGE_MAX
void Motion_SetVarCbAndRefresh(u32 objectId, s32 count)
The event command "run repeated motion": as ObjectMotion_SetVariantCallback, then waits for it to end...
void ObjectMotion_Launch(u32 objectId, s32 speed, s32 frames)
The event command "actor jump": throws the actor upward at speed pixels per frame with a jump sound (...
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
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.
struct ObjectRuntime * Object_CreateFar(s32 id, s32 x, s32 y, s32 z)
Far call to FieldObject_Create.
void ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
void ObjectDispatch_SetSingleChildFlagsFar(struct DispatchObject *obj, u32 flags)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
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
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
#define RGB(r, g, b)
A 15-bit colour from its red, green and blue levels (0 to 31 each), as the palette stores it: blue in...
Definition io_reg.h:164
void BattleFx_RunMercuryDjinnCapture(s32 djinniId)
A Mercury Djinni joins the party: the screen is tinted blue, the Djinni bounces twice and hops three ...
Definition mercury.c:14
#define MERCURY_PARTICLE_MAX
droplets (one an effect slot)
Definition mercury.c:7
#define MERCURY_AFTERIMAGE_MAX
afterimages of the rising Djinni
Definition mercury.c:8
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 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
@ PALETTE_TRANSFORM_TINT
The brightness (2R + 4G + B) times the colour carried.
Definition palbuf.h:85
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define SE_173
Definition songs.h:168
#define SE_175
Definition songs.h:170
#define SE_JUMP
An actor jumps: ObjectMotion_Launch plays the high jump above 5 pixels a frame.
Definition songs.h:147
#define SE_HIGH_JUMP
Definition songs.h:148
#define NULL
Definition bilibin.h:6
#define offsetof(type, member)
Definition stddef.h:19
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
struct EffectSlot slots[24]
Definition fx_scene.h:73
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
void * object
the slot's sprite, released with the slot
Definition effect_slot.h:19
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
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
u8 paused
nonzero skips its script and motion, not its update
Definition field_obj.h:93
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 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
signed int s32
Definition types.h:14
signed char s8
Definition types.h:10
s32 fixed
16.16 fixed-point pixels
void BattleFx_UpdateRandomTargetParticle(struct EffectSlot *effect)
Effect slot callback of a Mercury Djinni's droplets: each falls from 100 pixels above to a random poi...
Definition venus.c:163
void BattleFx_HalveDistanceToTarget(union FieldObject *fieldObject)
Per-frame update of an afterimage: closes half the distance to the object it is linked to.
Definition venus.c:220
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