Alchemy
Loading...
Searching...
No Matches

halt.c

Go to the documentation of this file.
1/// @file
2/// Halt.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Effect slot callback: state 0 heads for a point 40 to 70 pixels from where
8/// the particle appeared; state 1 waits to arrive, then goes on to 2; state 2
9/// heads for a point 4 pixels round 8 pixels above the effect's position on
10/// screen; state 3 frees the slot on arrival. Set on the 16 particles of
11/// BattleEffect_RunFallbackObjectTransition.
13 // A for/continue retry grows the native English callback 0x100 -> 0x104.
14 // Retain the immediate state-1-to-state-2 transition on arrival.
15 struct BattleFxScene *scene;
16 struct EffectVector pos;
17 s8 *statePointer;
18 s16 angle;
19 s32 state;
20
21 scene = gEffectWork;
22 statePointer = &effect->state;
23top:
24 state = *statePointer;
25 if (state == 0) {
26 pos.x = effect->originX;
27 pos.z = effect->originZ;
28 angle = Random16();
29 Vector_AddPolarOffset(Random16() * 30 + (40 << 16), (u16)angle, &pos);
30 effect->targetX = pos.x;
31 effect->targetZ = pos.z;
32 effect->acceleration = 4 << 16;
33 effect->maxSpeed = 4 << 16;
34 effect->limitTurnStep = state;
35 *statePointer = *statePointer + 1;
36 return;
37 }
38 if (state == 1) {
39 if (EffectSlot_HasPendingTarget(effect) != 0)
40 return;
41 *statePointer = *statePointer + 1;
42 goto top;
43 }
44 if (state == 2) {
45 pos.x = scene->x;
46 pos.y = scene->y + (8 << 16);
47 pos.z = scene->z;
49 Vector_AddPolarOffset(4 << 16, Random16(), &pos);
50 effect->targetX = pos.x;
51 effect->targetZ = pos.z;
52 effect->maxTurnStep = 0x1000;
53 effect->limitTurnStep = 1;
54 *statePointer = *statePointer + 1;
55 return;
56 }
57 if (state == 3 && EffectSlot_HasPendingTarget(effect) == 0)
59}
60
61/// Pauses the target (scene->child) and runs
62/// BattleEffect_RunFallbackObjectTransition. Called by BattleFx_Run and
63/// BattleFx_DispatchRequestKind for Halt on a target; sets the target's
64/// paused field.
66 struct FieldActor *target = ((struct BattleFxScene *)gEffectWork)->child;
67
68 target->paused = 1;
70}
71
72/// Throws an object from the caster to the effect's position over 10 frames
73/// and scatters it into 16 particles. Halt's visible effect: called by
74/// BattleFx_Run when no target with a talk event is near, and through
75/// BattleFx_MarkChildAndRunFallbackTransition otherwise. Fills effect slots 0
76/// to 15 and sets scene->y to the caster's height.
78 struct BattleFxScene *scene = gEffectWork;
79 struct MotionObject *caster = scene->mainObject;
80 struct MotionObject *orb;
81 struct EffectSlot *slot;
82 struct EffectVector pos;
83 struct EffectVector from;
84 struct EffectVector to;
85 s32 step;
86 s32 i;
87
88 scene->y = caster->y;
89 orb = (struct MotionObject *)Object_Spawn(250, 0, 0, 0);
90 step = 0;
92 if (orb == 0)
93 return;
94
95 // From 16 pixels above the caster to 8 pixels above the effect's position.
97 from.x = caster->x;
98 from.y = caster->y + (16 << 16);
99 from.z = caster->z;
100 to.x = scene->x;
101 to.y = scene->y + (8 << 16);
102 to.z = scene->z;
103 // Steps 0 to 10: the orb arrives on the 11th frame, grown to full size.
104 for (;;) {
105 s32 steps = 11;
106 s32 scale;
107
108 SET_POSITION(orb, from.x + (to.x - from.x) * step / 10,
109 from.y + (to.y - from.y) * step / 10,
110 from.z + (to.z - from.z) * step / 10);
111 scale = BattleFx_Interpolate(0x10000, 0x4000, step); // from 0.25 to full
112 orb->scaleX = scale;
113 orb->scaleY = scale;
114 WaitFrames(1);
115 step++;
116 if (step >= steps)
117 break;
118 }
119
120 // Three low tones and a high one, 10 frames apart, as the orb changes to
121 // its second animation.
122 WaitFrames(5);
125 WaitFrames(10);
127 WaitFrames(10);
129 WaitFrames(10);
131
132 // Particles 4 pixels round it fly out, then come back to the effect's
133 // position.
134 slot = &scene->slots[0];
135 for (i = 0; i < 16; i++) {
136 pos.x = orb->x;
137 pos.y = orb->y + (8 << 16);
138 pos.z = orb->z;
139 Camera_WorldToScreen((struct EffectVector *)&pos.x);
140 Vector_AddPolarOffset(4 << 16, Random16(), &pos.x);
141 EffectSlot_Initialize(slot, 285, pos.x, pos.z);
144 slot++;
145 }
146
147 pos.x = orb->x;
148 pos.y = orb->y + (8 << 16);
149 pos.z = orb->z;
150 WaitFrames(8);
152 WaitFrames(4);
153 WaitFrames(30);
155}
156
157/// Per-frame update of a paused object: gives its sprite one of the table's
158/// eight params at random. BattleEffect_PauseObject sets it, and
159/// BattleFx_ResumeObject looks for it to know the object was paused this way.
161 void *object = (void *)fieldObject;
163 s32 random = Random16();
164 Animation_ApplyChildValuesFar(object, table[(u32)(random * 8) >> 16]);
165}
166
167/// Pauses object id, keeping its per-frame update and, if it is animated, its
168/// first animation's param in gGameState. Called by BattleFx_Run and
169/// BattleFx_DispatchRequestKind for Halt, which then record the id in
170/// gGameState.pausedObject, and by the Colosso scenes to stop their operators.
171/// Sets gGameState.pausedUpdate and pausedPose, the object's update and paused
172/// fields, and stops its animation.
174 struct FieldActor *object;
175 struct AnimationEntry *entry;
176
177 object = ObjectTable_Get(actorId);
178 if (object != NULL) {
181 if (object->spriteStorageKind == 1) {
182 entry = object->sprite->entries[0];
183 if (entry != NULL) {
184 gGameState.pausedPose = entry->param;
185 }
186 }
188 object->paused = 1;
190 }
191}
192
193/// Resumes object id with the update and param kept by
194/// BattleEffect_PauseObject. Called for gGameState.pausedObject by BattleFx_Run
195/// and BattleFx_DispatchRequestKind before Halt stops another object, and by
196/// Scene_TalkToActor after talking to the paused actor. Clears
197/// gGameState.pausedUpdate and the object's paused field, and restarts its
198/// animation at speed 16.
200 struct FieldActor *object = ObjectTable_Get(actorId);
201 if (object != 0) {
203 struct GameState *state = &gGameState;
204 object->update = (void (*)(union FieldObject *))state->pausedUpdate;
205 state->pausedUpdate = 0;
207 state->pausedPose);
208 }
209 object->paused = 0;
211 }
212}
213
214/// Returns id, or -1 (no target) when the current effect's definition has
215/// flags 0xff. Called by BattleFx_Run on the nearest Halt target.
217 if (BattleFx_GetFlags(id) == 0xff)
218 return -1;
219 return id;
220}
void * ObjectTable_Get(u32 actorIndex)
Returns the actor in slot index (0 to 65), or NULL.
Definition actors.c:462
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 ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_SetAnimationSpeedFar(struct DispatchObject *obj, s32 val)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
void ObjectGroup_SetChildValueUnlessFifteenFar(void *raw_parent, u32 value)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
static __inline__ s32 BattleFx_Interpolate(s32 to, s32 from, s32 step)
Definition fx_scene.h:90
const s8 gBattleFx_RandomChildValues[8]
Definition fxdata.c:506
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
void BattleFx_UpdateRadialCamera(struct EffectSlot *effect)
Effect slot callback: state 0 heads for a point 40 to 70 pixels from where the particle appeared; sta...
Definition halt.c:12
void BattleFx_ResumeObject(s32 actorId)
Resumes object id with the update and param kept by BattleEffect_PauseObject.
Definition halt.c:199
s32 BattleFx_FilterObjectIdByFlags(s32 id)
Returns id, or -1 (no target) when the current effect's definition has flags 0xff.
Definition halt.c:216
void BattleEffect_RunFallbackObjectTransition(void)
Throws an object from the caster to the effect's position over 10 frames and scatters it into 16 part...
Definition halt.c:77
void BattleEffect_SetRandomTableValueOnObject(union FieldObject *fieldObject)
Per-frame update of a paused object: gives its sprite one of the table's eight params at random.
Definition halt.c:160
void BattleFx_MarkChildAndRunFallbackTransition(s32 unused)
Pauses the target (scene->child) and runs BattleEffect_RunFallbackObjectTransition.
Definition halt.c:65
void BattleEffect_PauseObject(s32 actorId)
Pauses object id, keeping its per-frame update and, if it is animated, its first animation's param in...
Definition halt.c:173
#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
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 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 SE_TRIPLE_TONE_HIGH
Definition songs.h:102
#define SE_TRIPLE_TONE_LOW
Definition songs.h:101
s32 BattleFx_GetFlags(s32 id)
Returns the definition flags of actor id's sprite, which choose its line when it has nothing to say.
Definition speakers.c:52
#define NULL
Definition bilibin.h:6
One animation layer of a sprite: its animation id, frames, running script and timer.
Definition animspr.h:37
u8 param
SpriteColorMode its pixels are drawn with; 0 when taken.
Definition animspr.h:45
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
struct EffectSlot slots[24]
Definition fx_scene.h:73
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.
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
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
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 paused
nonzero skips its script and motion, not its update
Definition field_obj.h:93
u8 spriteStorageKind
Zero hides sprites; one draws a single sprite, two draws a group.
Definition field_obj.h:78
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
Definition field_obj.h:116
The game's state: play time, coins, the scene and the leader's position, the active party and the opt...
Definition game_state.h:14
s8 pausedPose
Halt: the stopped object's first animation param.
Definition game_state.h:112
u32 pausedUpdate
Halt: the stopped object's update; not read by name.
Definition game_state.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 z
16.16 fixed-point pixels
Definition motobj.h:25
s32 y
16.16 fixed-point pixels
Definition motobj.h:24
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition motobj.h:28
s32 x
16.16 fixed-point pixels
Definition motobj.h:23
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
unsigned short u16
Definition types.h:13
An object on the field, read as an actor or as an effect.