Alchemy
Loading...
Searching...
No Matches

lift.c

Go to the documentation of this file.
1/// @file
2/// Lift.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// An object appears 32 pixels to either side, each moves 14 pixels in, and
8/// they lift the target 32 pixels with them. Called by
9/// BattleFx_DispatchRequestKind; leaves the target raised, with its update set
10/// to ObjectGroup_ApplyRandomChildValues.
11///
12/// Abilities: Lift (field kind 7), cast on a target.
14 struct BattleFxScene *work;
15 struct DispatchObject *caster;
16 struct FieldActor *target;
17 struct MotionObject *pair[2];
18 s32 pos[3];
19 s32 x, y, z;
20 s32 handIndex;
21 s32 startY;
22
23 work = gEffectWork;
24 target = work->child;
25 caster = work->mainObject;
26 if (target == NULL)
27 return;
28
30 // The caster's script starts 3 words into the common particle script, with
31 // the target as its argument.
32 caster->argument = (s32)target;
34
35 x = work->x;
36 pos[0] = x;
37 y = work->y + 0x100000; // 16 pixels up
38 pos[1] = y;
39 z = work->z;
40 pos[2] = z;
41 pair[0] = BattleFx_SpawnItemBreakMode3(x + 0x200000, y, z, 0x8000);
42 pair[1] = BattleFx_SpawnItemBreakMode3(pos[0] - 0x200000, pos[1], pos[2], 0);
43
44 // Each hand faces the target (angle 0x8000 on the right, 0 on the left) and
45 // moves 14 pixels that way.
46 WaitFrames(15);
47 for (handIndex = 0; handIndex < 2; handIndex++) {
48 struct MotionObject *hand = pair[handIndex];
49 if (hand != NULL)
51 0xe0000, hand->angle);
52 }
53
57 target->motionFlags = 4;
58
59 // Lift 32 pixels, a quarter pixel at a time.
60 startY = target->y.fixed;
61 if (pair[0] != NULL && pair[1] != NULL && startY <= startY + 0x200000) {
62 do {
63 pair[0]->y += 0x4000;
64 pair[1]->y += 0x4000;
65 target->y.fixed += 0x4000;
66 WaitFrames(1);
67 } while (target->y.fixed <= startY + 0x200000);
68 }
69
70 // The hands burst into particles; the target stays up.
74}
75
76/// Lift cast with no target: objects appear above the caster and to either
77/// side, move apart and scatter into shards.
78///
79/// Abilities: Lift (field kind 7), cast with no target. Called by
80/// BattleFx_Run.
82
83/// Spawns object 215 and grows it, spinning, from a quarter to full size over
84/// 24 frames; angle is the way it faces once grown. Makes Lift's two hands,
85/// for FieldFx_RunLiftOnTarget and FieldFx_RunLift; returns NULL when no object
86/// could be spawned.
88 s32 angle) {
89 struct MotionObject *fragment;
90 s32 scale;
91
93 fragment = (struct MotionObject *)Object_Spawn(215, x, y, z);
94 if (fragment != NULL) {
95 fragment->scaleX = fragment->scaleY = 0x4000;
96 fragment->acceleration = fragment->speedLimit = 0x30000; // 3 pixels a frame
97 ((struct AnimationObject *)fragment->records)->image.priority = 0;
99 scale = fragment->scaleX;
100 if (scale < 0x10000) {
101 do {
102 scale += 0x800;
103 fragment->scaleY = scale;
104 fragment->scaleX = scale;
105 fragment->angle += 0x2000; // 1/8 turn
106 WaitFrames(1);
107 scale = fragment->scaleX;
108 } while (scale <= 0xffff);
109 }
110 fragment->angle = angle;
111 }
112 return fragment;
113}
114
115/// Effect slot callback of a particle that scatters 25 pixels from its origin
116/// in a random direction, then gathers beside the main object and is freed.
117/// Set on Force's 12 flashes by FieldFx_RunForceOnTarget in force.c.
119 // A for/continue retry keeps the same states but grows the native English
120 // callback from 0xf8 to 0xfc bytes. State 1 must enter state 2 immediately.
121 struct BattleFxScene *scene = gEffectWork;
122 struct EffectVector pos;
123 s32 state;
124
125again:
126 state = slot->state;
127 if (state == 0) {
128 // 25 pixels from the origin, in a random direction.
129 pos.x = slot->originX;
130 pos.z = slot->originZ;
131 Vector_AddPolarOffset(25 << 16, (u16)Random16(), &pos);
132 slot->targetX = pos.x;
133 slot->targetZ = pos.z;
134 slot->acceleration = 3 << 16;
135 slot->maxSpeed = 3 << 16;
136 slot->limitTurnStep = 0;
137 slot->state++;
138 return;
139 }
140
141 if (state == 1) {
142 // On arrival, go straight on.
143 if (EffectSlot_HasPendingTarget(slot) == 0) {
144 slot->state++;
145 goto again;
146 }
147 return;
148 }
149
150 if (state == 2) {
151 // 8 pixels toward scene->angle from 16 pixels above the main object, on
152 // screen, give or take 4 pixels.
153 struct MotionObject *caster = scene->mainObject;
154
155 pos.x = caster->x;
156 pos.y = caster->y + (16 << 16);
157 pos.z = caster->z;
158 Vector_AddPolarOffset(8 << 16, scene->angle, &pos);
160 Vector_AddPolarOffset(4 << 16, Random16(), &pos);
161 slot->targetX = pos.x;
162 slot->targetZ = pos.z;
163 slot->maxTurnStep = 0x800;
164 slot->limitTurnStep = 1;
165 slot->state++;
166 return;
167 }
168
169 if (state == 3 && EffectSlot_HasPendingTarget(slot) == 0)
171}
172
173/// A heavy impact: places object 0x11b 32 pixels below the source and scatters
174/// 12 shards from it. Reached through SC_CALL in gBattleFx_HeavyImpactScript
175/// (fxdata.c), where the interpreter is the object running the script.
176/// Returns 0.
178 struct MotionObject *source = (struct MotionObject *)interpreter;
179 struct EffectVector pos;
180 struct ObjectRuntime *impact;
181 struct ObjectRuntime *fragment;
182 s32 fragmentIndex;
183
185 pos.x = source->x;
186 pos.y = source->y;
187 pos.z = source->z;
188 impact = Object_Spawn(0x11b, pos.x, pos.y - (32 << 16), pos.z);
189 if (impact != NULL) {
190 impact->flags = 0;
191 impact->wait = 20;
194 }
195
196 // Shards: 1 to 2 pixels a frame, 8 to 32 pixels in a random direction.
197 for (fragmentIndex = 0; fragmentIndex < 12; fragmentIndex++) {
198 fragment = Object_Spawn(0x11d, pos.x, pos.y, pos.z);
199 if (fragment != NULL) {
202 fragment->speedLimit = Random16() + (1 << 16);
203 fragment->acceleration = 1 << 16;
204 fragment->flags = 0;
206 fragment, Random16() * 24 + (8 << 16), Random16());
207 }
208 }
209 return 0;
210}
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 ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void FieldObject_WaitForMoveFar(void *fieldObject)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
const s32 gBattleFx_FragmentScript[]
Definition fxdata.c:456
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.
void FieldFx_RunLift(void)
Lift cast with no target: objects appear above the caster and to either side, move apart and scatter ...
Definition lift.c:81
s32 SpawnHeavyImpactEffect(struct ScriptInterpreter *interpreter)
A heavy impact: places object 0x11b 32 pixels below the source and scatters 12 shards from it.
Definition lift.c:177
void FieldFx_RunLiftOnTarget(s32 unused)
An object appears 32 pixels to either side, each moves 14 pixels in, and they lift the target 32 pixe...
Definition lift.c:13
struct MotionObject * BattleFx_SpawnItemBreakMode3(s32 x, s32 y, s32 z, s32 angle)
Spawns object 215 and grows it, spinning, from a quarter to full size over 24 frames; angle is the wa...
Definition lift.c:87
void BattleFx_UpdateRadialBurst(struct EffectSlot *slot)
Effect slot callback of a particle that scatters 25 pixels from its origin in a random direction,...
Definition lift.c:118
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 UpdateRisingParticleBurst(void *object)
Per-frame update: the object spins as it rises for 31 frames, shrinks, and bursts into 8 particles.
Definition move.c:397
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 ObjectGroup_ApplyRandomChildValues(union FieldObject *fieldObject)
Per-frame update: sets every part of an object's sprite to param frame % 6, which cycles its colours.
Definition dispatch.c:270
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 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_ITEM_BREAK_EFFECT(name, spawn)
Defines an effect cast with no target: spawn makes an object 16 pixels above the effect's position an...
#define SE_130
Definition songs.h:123
#define SE_ITEM_BREAK
Definition songs.h:131
#define SE_HEAVY_IMPACT
Definition songs.h:127
#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
struct AnimationSpritePart image
Definition animspr.h:109
u8 slot
VRAM cache entry holding its tiles.
Definition animspr.h:112
s32 scale
16.16 fixed point, 0x10000 full size
Definition animspr.h:111
u16 priority
2 when created
Definition animspr.h:100
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
s32 angle
1/65536 turns
Definition fx_scene.h:32
void * mainObject
the caster's object
Definition fx_scene.h:36
void * child
the target's object, or NULL
Definition fx_scene.h:37
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.
s32 argument
the linked object a script approaches or follows
A particle a Psynergy effect moves and draws: its sprite, its position and target,...
Definition effect_slot.h:18
s8 state
the callback's own step; 0 when it is given
Definition effect_slot.h:38
s32 originX
16.16 fixed-point pixels; where the slot started
Definition effect_slot.h:24
s16 maxTurnStep
1/65536 turns a frame
Definition effect_slot.h:32
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 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
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
Definition field_obj.h:116
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
Definition motobj.h:20
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition motobj.h:27
s32 speedLimit
16.16 fixed-point pixels per frame
Definition motobj.h:34
s32 z
16.16 fixed-point pixels
Definition motobj.h:25
s32 y
16.16 fixed-point pixels
Definition motobj.h:24
u16 angle
1/65536 turns
Definition motobj.h:22
void * records
one sprite, or a table of up to four (recordStorageKind)
Definition motobj.h:50
s32 acceleration
Horizontal speed gained each frame towards the target, or lost braking without one,...
Definition motobj.h:37
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition motobj.h:28
s32 x
16.16 fixed-point pixels
Definition motobj.h:23
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
u8 flags
FieldActor.motionFlags: 3 when created, 4 for a placed actor above the ground; zero is free flight in...
u16 wait
the object script's wait, in frames
The prefix that command handlers read from a field object's 0x70-byte slot.
Definition script.h:16
signed int s32
Definition types.h:14
unsigned short u16
Definition types.h:13
s32 fixed
16.16 fixed-point pixels