Alchemy
Loading...
Searching...
No Matches

force.c

Go to the documentation of this file.
1/// @file
2/// Force.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Runs Force cast on a target, through FieldFx_RunForce.
8///
9/// Abilities: Force (field kind 4), cast on a target.
11
12/// Writes the position 16 pixels above the actor.
13static __inline__ void
15 struct EffectVector *pos) {
16 SET_POSITION(pos, obj->x.fixed, obj->y.fixed + ABOVE, obj->z.fixed);
17}
18
19/// A shot appears in front of the caster, grows and flies forward with three
20/// afterimages; what it hits (scene->child) is pushed 16 pixels.
21///
22/// Abilities: Force (field kind 4).
23void FieldFx_RunForce(void) {
24 struct FieldActor *target;
25 s32 eventTarget;
26 struct FieldActor *copies[4];
27 struct EffectVector pos;
28 struct FieldActor *projectile;
29 struct FieldActor *copy;
30 struct FieldActor *caster;
31 struct BattleFxScene *scene;
32 struct EffectSlot *slot;
33 struct AnimationObject *sharedAnimation;
34 void *event;
35 s32 scale;
36 s32 i;
37 u8 resourceSlot;
38
39 scene = gEffectWork;
40 target = scene->child;
43 slot = scene->slots;
44
45 // 12 flashes burst from over the caster's head, one every 2 frames.
46 for (i = 0; i <= 11; i++) {
47 caster = scene->mainObject;
50 EffectSlot_Initialize(slot, 0x11c, pos.x, pos.z);
54 slot->scaleY = 0xb333; // 0.7
55 slot->scaleX = 0xb333;
56 WaitFrames(2);
57 slot++;
58 }
59
60 // The shot: 8 pixels in front of the caster, growing from 0.25 to full
61 // size.
62 caster = scene->mainObject;
63 pos.x = caster->x.fixed;
64 pos.y = caster->y.fixed + ABOVE;
65 pos.z = caster->z.fixed;
66 Vector_AddPolarOffset(8 << 16, scene->angle, &pos);
67 projectile = (struct FieldActor *)Object_Spawn(0xd7, pos.x, pos.y, pos.z);
68 if (projectile == NULL) {
70 return;
71 }
72 projectile->scaleY = 0x4000;
73 projectile->scaleX = 0x4000;
74 projectile->facing = scene->angle;
75 projectile->speed = 4 << 16;
76 projectile->acceleration = 4 << 16;
77 projectile->motionFlags = 0;
79 Animation_ApplyChildValuesFar((struct DispatchObject *)projectile, 3);
80 scale = projectile->scaleX;
81 if (scale < 0x10000) {
82 do {
83 scale += 0x500;
84 projectile->scaleY = scale;
85 projectile->scaleX = scale;
86 WaitFrames(1);
87 scale = projectile->scaleX;
88 } while (scale <= 0xffff);
89 }
90 WaitFrames(3);
91
92 // Three afterimages, sharing one set of graphics.
93 sharedAnimation = NULL;
94 for (i = 2; i >= 0; i--) {
95 copy = copies[i] = (struct FieldActor *)Object_Spawn(
96 0xd7, projectile->x.fixed, projectile->y.fixed, projectile->z.fixed);
97 if (copy != NULL) {
98 copy->scaleY = 0xf000;
99 copy->scaleX = 0xf000;
100 copy->facing = scene->angle;
101 copy->speed = 4 << 16;
102 copy->acceleration = 4 << 16;
103 copy->motionFlags = 0;
106 sharedAnimation = Sprite_ShareVramCache(
107 (struct AnimationObject *)copy->sprite, sharedAnimation);
108 }
109 }
110 resourceSlot = sharedAnimation->slot;
111
112 // Destination: 56 pixels in front of the caster with scene->enabled set,
113 // otherwise the effect's position.
114 if (scene->enabled != 0) {
115 caster = scene->mainObject;
116 pos.x = caster->x.fixed;
117 pos.y = caster->y.fixed + ABOVE;
118 pos.z = caster->z.fixed;
119 Vector_AddPolarOffset(56 << 16, scene->angle, &pos);
120 } else {
121 pos.x = scene->x;
122 pos.y = scene->y + ABOVE;
123 pos.z = scene->z;
124 }
125 Object_SetMoveTargetFar((struct ObjectRuntime *)projectile, pos.x, pos.y,
126 pos.z);
127 ObjectDispatch_InitializeFar((struct DispatchObject *)projectile,
129 for (i = 0; i < 3; i++) {
130 copy = copies[i];
131 if (copy != NULL) {
132 WaitFrames(3);
133 Object_SetMoveTargetFar((struct ObjectRuntime *)copy, pos.x, pos.y,
134 pos.z);
137 }
138 }
139
140 // Wait, at most 60 frames, for the shot's script to end.
141 for (i = 0;
142 i <= 59 && ((struct ScriptMotionObject *)projectile)->script != NULL;
143 i++)
144 WaitFrames(1);
145
146 // Push what was hit 16 pixels if nothing is in the way (it hops with
147 // childOption).
148 if (target != NULL && scene->childMode == 0) {
149 if (scene->childOption != 0)
150 target->velocityY = 8 << 16;
151 pos.x = target->x.fixed;
152 pos.y = target->y.fixed;
153 pos.z = target->z.fixed;
154 Vector_AddPolarOffset(16 << 16, scene->angle, &pos);
155 if (Map_CheckObjectStepFar((struct ObjectRuntime *)target,
156 (struct FieldPosition *)&pos) == 0 &&
158 (s32 *)&pos) == 0) {
159 target->acceleration = 1 << 16;
160 target->speed = 1 << 16;
161 Object_SetMoveTargetFar((struct ObjectRuntime *)target, pos.x, pos.y,
162 pos.z);
163 }
164 }
165
166 // Run the map's event for it, if there is one.
167 event = BattleFx_FindMatchingEvent(0x50000005, 4, &eventTarget);
168 if (event != NULL)
169 Field_RunEventAction(event, gGameState.selectedActor, eventTarget);
170 WaitFrames(10);
172 WaitFrames(20);
173 if (resourceSlot != 96)
174 Resource_ResetEntry(resourceSlot);
175}
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_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void Object_SetMoveTargetFar(struct ObjectRuntime *object, s32 x, s32 y, s32 z)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
void ObjectGroup_SetChildValueUnlessFifteenFar(void *raw_parent, u32 value)
s32 ScriptObject_CheckOverlapFar(struct ScriptObjectEntry *object, s32 *values)
s32 Map_CheckObjectStepFar(struct ObjectRuntime *object, struct FieldPosition *position)
void AudioCommand_PlayFar(s32 id)
void FieldFx_RunForce(void)
A shot appears in front of the caster, grows and flies forward with three afterimages; what it hits (...
Definition force.c:23
static __inline__ void BattleFx_GetPositionAboveActor(struct FieldActor *obj, struct EffectVector *pos)
Writes the position 16 pixels above the actor.
Definition force.c:14
void FieldFx_RunForceOnTarget(s32 unused)
Runs Force cast on a target, through FieldFx_RunForce.
Definition force.c:10
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
const s32 gBattleFx_BurstParticleObjectScript[]
Word +4 is gBattleFx_HeavyImpactScript.
Definition fxdata.c:476
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
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
#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
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 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
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 ABOVE
16 pixels up
#define SE_130
Definition songs.h:123
#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
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
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
s32 angle
1/65536 turns
Definition fx_scene.h:32
struct EffectSlot slots[24]
Definition fx_scene.h:73
s8 childMode
set by some scenes: Frost and Force leave the target be
Definition fx_scene.h:53
void * mainObject
the caster's object
Definition fx_scene.h:36
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 particle a Psynergy effect moves and draws: its sprite, its position and target,...
Definition effect_slot.h:18
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
s32 speed
speed limit, 16.16 fixed-point pixels per frame
Definition field_obj.h:55
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
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
s32 velocityY
16.16 fixed-point pixels per frame
Definition field_obj.h:53
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
u16 facing
1/65536 turns
Definition field_obj.h:34
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
Definition field_obj.h:58
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
A position on the field.
s32 z
16.16 fixed-point pixels
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 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
A field object as the motion code sees it: its script, position, motion toward a target,...
A field object as the script commands' overlap checks see it.
signed int s32
Definition types.h:14
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels
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