Alchemy
Loading...
Searching...
No Matches

psynergy_effects_internal.h

Go to the documentation of this file.
1#ifndef ALCHEMY_PSYNERGY_EFFECTS_INTERNAL_H
2#define ALCHEMY_PSYNERGY_EFFECTS_INTERNAL_H
3
4/// @file
5/// What every part of psynergy_effects.c shares: its includes and the macros
6/// and types more than one part uses. psynergy_effects.c includes it before the
7/// parts, and each part includes it too, so that a part read on its own
8/// resolves. It places no bytes.
9
10#include "vram_tab.h"
11#include "unit/object/object.h"
14#include "types.h"
15#include "scene.h"
16#include "battle_type.h"
17#include "game_state.h"
18#include "field_runtime.h"
19#include "battle_system.h"
20#include "battle.h"
21#include "battle_unit.h"
22#include "debug.h"
23#include "field.h"
24#include "game.h"
25#include "graphics.h"
26#include "menu.h"
27#include "minigame.h"
28#include "sound.h"
29#include "system.h"
30#include "mem.h"
31#include "dma.h"
32#include "scene_ids.h"
33#include "io_reg.h"
34#include "iowrite.h"
35#include "irq.h"
36#include "callback_scheduler.h"
37#include "flags.h"
38#include "iwram_call.h"
39#include "event_work.h"
40#include "resource_ids.h"
42#include "resource.h"
43#include "field_scene.h"
44#include "map.h"
45#include "map_scroll.h"
46#include "ram_buffer.h"
47#include "global_cells.h"
48#include "object_runtime.h"
50#include "animspr.h"
51#include "field_obj.h"
52#include "object_dispatch.h"
53#include "field_event.h"
54#include "heap_state.h"
55#include "keystate.h"
56#include "owner_value.h"
57#include "party_state.h"
58#include "songs.h"
59#include "fixed_math.h"
60#include "item_gift.h"
61#include "battle_calc.h"
62#include "display_transition.h"
63#include "text/msg_ids.h"
64#include "object_lookup.h"
65#include "objdisp.h"
66#include "object_effect.h"
67#include "item.h"
68#include "motobj.h"
69#include "static_assert.h"
70#include "frame.h"
71#include "io_write_queue.h"
72#include "palbuf.h"
73#include "vram_block.h"
74#include "item_ids.h"
75#include "inventory.h"
76#include "ui.h"
77#include "window.h"
78#include "battle_party.h"
79#include "b5_context.h"
80#include "edition.h"
81#include "facing_object.h"
82#include "script_motion.h"
83#include "tbs_edition.h"
84#include "metadata_lookup.h"
85#include "field_coordinate.h"
86#include "scroll.h"
87#include "fxblend.h"
88#include "fx_scene.h"
89#include "effect_slot.h"
91#include "menu_list.h"
92#include "field_effect.h"
96#include "macros.h"
97#include "ability_ids.h"
98
99/// The effect slots of a Psynergy effect's scene (gEffectWork->slots).
100#define PSYNERGY_EFFECT_SLOT_COUNT 24
101
102/// gGameState.pendingDjinnEvent of Djinni 0 (requests.c, djinni.c).
103#define DJINNI_0 300
104
105/// A FieldActor seen with its position as one vector, to pass it whole. The
106/// gaps are FieldActor fields this view does not use.
107struct Object {
108 u8 pad0[6];
109 u16 angle;
110 struct EffectVector pos;
111 u8 pad1[14];
112 u8 kind;
113 u8 pad2[0x2d];
114 struct AnimationObject *sprite;
115};
116
117/// Per-frame update of an afterimage: closes half the distance to the object
118/// it is linked to, on all three axes.
119static inline void
121 struct FieldActor *afterimage = (struct FieldActor *)fieldObject;
122 struct FieldActor *target = afterimage->linkedObject;
123
124 afterimage->x.fixed += (target->x.fixed - afterimage->x.fixed) / 2;
125 afterimage->y.fixed += (target->y.fixed - afterimage->y.fixed) / 2;
126 afterimage->z.fixed += (target->z.fixed - afterimage->z.fixed) / 2;
127}
128
129/// Runs the update of each of the 24 effect slots.
130static __inline__ void FieldFx_UpdateSceneSlots(void) {
131 struct EffectSlot *slot;
132 s32 remainingSlots;
133
134 slot = ((struct BattleFxScene *)gEffectWork)->slots;
135 remainingSlots = PSYNERGY_EFFECT_SLOT_COUNT - 1;
136 do {
137 remainingSlots -= 1;
138 EffectSlot_Update(slot);
139 slot++;
140 } while (remainingSlots >= 0);
141}
142
143/// A FieldActor seen with the halfword at 0x64 unsigned and the one at 0x66
144/// signed, as the bytes read them (FieldActor's own types change the code).
153};
154
155/// A FieldActor seen with the halfword at 0x5e (lifetime), which FieldActor
156/// does not name.
179 void (*callback)(union FieldObject *object);
180};
181
182/// Defines a per-frame update that spins an object 1/8 turn a frame while its
183/// scale changes by step, releasing the object once the scale falls below
184/// 0x3000.
185#define DEFINE_SHRINK_AND_DESTROY(name, step) \
186 void name(union FieldObject *fieldObject) { \
187 void *obj = fieldObject; \
188 s32 scale; \
189 \
190 scale = ((struct MotionObject *)obj)->scaleX + step; \
191 ((struct MotionObject *)obj)->scaleY = \
192 ((struct MotionObject *)obj)->scaleY + step; \
193 ((struct MotionObject *)obj)->angle = \
194 ((struct MotionObject *)obj)->angle + 0x2000; \
195 ((struct MotionObject *)obj)->scaleX = scale; \
196 if (scale < 0x3000) { \
197 ObjectDispatch_ReleaseFar(obj); \
198 } \
199 }
200
201/// the Psynergy effect's work (gWorkSlot[56], gEffectWork)
202#define HEAP_SLOT_FX 56
203
204/// A particle's sprite, seen as the two fields Douse and Mind Read set on it.
211 u8 unk0a[0x1c];
213};
214
215/// A FieldActor seen with the halfword at 0x5e (its lifetime), which
216/// FieldActor does not name.
224};
225
226/// Both item fragments and Lift shed the same short-lived falling particle.
227static inline void
229 // Spawn and choose its position at the call site: combining the spawn here
230 // moves the kind load after the coordinate loads in the native English build.
231 if (fragment != NULL) {
232 fragment->motionFlags = ACTOR_FALLS;
233 fragment->gravity = 0x1999;
235 fragment->lifetime = 12;
238 }
239}
240
241/// The shards DEFINE_ITEM_BREAK_EFFECT's effects scatter.
242#define ITEM_BREAK_SHARD_MAX 24
243
244/// Defines an effect cast with no target: spawn makes an object 16 pixels
245/// above the effect's position and 32 pixels to either side; each moves 24
246/// pixels its way, then 24 shards scatter 8 to 32 pixels.
247#define DEFINE_ITEM_BREAK_EFFECT(name, spawn) \
248 void name(void) { \
249 struct BattleFxScene *work; \
250 struct MotionObject *obj; \
251 struct MotionObject *pair[2]; \
252 struct ScatterPosition pos; \
253 struct MotionObject **walk; \
254 s32 n; \
255 s32 dist; \
256 \
257 work = gEffectWork; \
258 BattleEffect_InitializeSharedScene(); \
259 pos.x = work->x; \
260 pos.y = work->y + 0x100000; \
261 pos.z = work->z; \
262 pair[0] = spawn(pos.x + 0x200000, pos.y, pos.z, 0x8000); \
263 pair[1] = spawn(pos.x - 0x200000, pos.y, pos.z, 0); \
264 \
265 WaitFrames(15); \
266 walk = pair; \
267 for (n = 0; n < 2; n++) { \
268 obj = *walk++; \
269 if (obj != 0) \
270 Motion_SetTargetPositionFromMagnitudeAngle( \
271 (struct ObjectRuntime *)obj, 0x180000, obj->angle); \
272 } \
273 \
274 FieldObject_WaitForMoveFar(pair[0]); \
275 AudioCommand_PlayFar(SE_HEAVY_IMPACT); \
276 for (n = 0; n < ITEM_BREAK_SHARD_MAX; n++) { \
277 pos.x = work->x; \
278 pos.y = work->y + 0x100000; \
279 pos.z = work->z; \
280 obj = (struct MotionObject *)Object_Spawn(285, pos.x, pos.y, pos.z); \
281 if (obj != 0) { \
282 ObjectDispatch_InitializeFar((struct DispatchObject *)obj, \
283 gBattleFx_FragmentScript); \
284 obj->speedLimit = Random16() + 0x20000; \
285 obj->acceleration = 0x20000; \
286 obj->motionFlags = 0; \
287 dist = Random16() * 24 + 0x80000; \
288 Motion_SetTargetPositionFromMagnitudeAngle( \
289 (struct ObjectRuntime *)obj, dist, Random16()); \
290 } \
291 } \
292 \
293 ObjectDispatch_ReleaseFar((struct DispatchObject *)pair[0]); \
294 ObjectDispatch_ReleaseFar((struct DispatchObject *)pair[1]); \
295 BattleFx_PrepareBufferInterpolation(); \
296 }
297
298#define ABOVE (16 << 16) ///< 16 pixels up
299
300/// A FieldActor seen with the halfword at 0x5e (its lifetime), which
301/// FieldActor does not name.
311 s32 anchorX; ///< centre of the sway (FieldActor's targetX)
313 s32 gravity; ///< as in FieldActor
315 u8 motionFlags; ///< as in FieldActor
319 s16 phase; ///< phase of the sway (128 frames a cycle)
321 void (*update)(union FieldObject *object);
322};
323
324#endif
Ability numbers, named from the English release.
Animated sprites: their layers, frames and colour modes, and the resource slots they draw from.
B5Context, the object context a battle routine reads; most of its fields are still unnamed.
The battle calculation tables: hit chances, HP and PP damage and recovery.
The battle animation state, render objects and effect entries, and the palette buffer work.
Which units are in a battle, and the Djinn recovery list.
BattleUnit_Recalculate, which recalculates a unit's stats.
BattlePlan, an action planned for its targets: the hits, criticals and multipliers rolled.
BattleUnit, a party member's or enemy's battle state, with the elements, abilities and actions it use...
The task scheduler: tasks, their order and the scheduler's state.
The engine calls the debug menus import, and their palette swatch tiles.
The display transition's frames, windows and state.
DMA channel registers, and the DMA and CPU fills.
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
void EffectSlot_Update(struct EffectSlot *effect)
Updates one effect slot: counts its age, runs its callback (after any delay), moves it and draws it.
Definition effect_slot.c:9
Effect slots: the particles Psynergy effects move and draw.
EventWork, the running scene's event work.
FacingObject, the view of an object that turns to face a target.
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
FieldCoordinate, a position on the field.
Field effects, their scripts and the flags that spawn them.
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
Field objects and actors, and the scene transition styles.
@ ACTOR_FALLS
falls by its gravity and bounces
Definition field_obj.h:161
The field's runtime work: map cells, scene records and regions, map markers and FieldWork.
The scene table formats: entrances, exits, placements and events, and the macros that write them.
16.16 fixed-point constants, sine and cosine, and the library division.
FixedPointPosition, a position in 16.16 fixed point.
Game flags, named where their meaning is shown.
The frame loop's globals: lag counts, the CPU load display and the VBlank flags.
BattleFxScene, the work of a battle or field Psynergy effect scene, and its arc objects.
FieldBlendWork, the field's colour blend work.
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
GameState, the game's state: play time, coins, the scene and the leader's position,...
The work slots of gWorkSlot, read through their own names.
void * gEffectWork
Slot 56: points to a scene-specific structure.
The screen blend's globals and the graphics routines.
The heap's work slots and HeapState.
gOverflowItem, an item slot the spoils code uses when items are handed out.
The hardware's I/O registers and their bits, as pret names them.
The register write queue that VBlank carries out after each finished frame.
Io_Write16, a 16-bit write to a register or memory.
The hardware's interrupt sources and the interrupt handler table.
Items: their definitions, types, flags and effects.
Declares nothing of its own: it only includes types.h, edition.h and farcall.h.
Item numbers, named from the English release.
The IWRAM call layer: the routines the game keeps resident in IWRAM, each at its fixed address,...
The keypad state the VBlank interrupt keeps.
Small statement macros both games use for positions, velocities and bounds.
Maps: their cells, layers, animations and blend scripts, and the map state.
The map layers' scroll work and the background scroll values.
The heaps: allocating and freeing blocks.
Menu lists: sprites, cursors, the party status window and paged selections.
Animation metadata and its lookup by resource.
The reel game's title lettering.
MotionObject, an effect object that moves and draws one sprite.
The object dispatcher's forward declaration.
The object dispatcher's scripts: key checks, the player, the world map and the camera.
The fade overlay, the weather particles and the actor effect work.
The object scripts effects give their particles and fragments.
Declares nothing: an empty header kept for the files that include it.
ObjectRuntime, a field object's runtime state, and the object snapshots.
Declares nothing of its own: it only includes types.h, edition.h and farcall.h.
Palette fades, the battle effect palette buffers and the colour channel curves.
Declares nothing of its own: it only includes static_assert.h and game_state.h.
static void BattleFx_InitializeFallingFragment(struct ItemBreakFragmentObject *fragment)
Both item fragments and Lift shed the same short-lived falling particle.
static void BattleFx_MoveAfterimageHalfway(union FieldObject *fieldObject)
Per-frame update of an afterimage: closes half the distance to the object it is linked to,...
static __inline__ void FieldFx_UpdateSceneSlots(void)
Runs the update of each of the 24 effect slots.
#define PSYNERGY_EFFECT_SLOT_COUNT
The effect slots of a Psynergy effect's scene (gEffectWork->slots).
The work pointers in the gWorkSlot table, by name.
Resource numbers, named where their contents are known.
FIELD_AT_OFFSET and the entity and camera views older scene code reads.
Scene numbers, named after their places.
ScriptMotionObject, an object moved by a field script.
ScriptObjectRuntime, the work of an object a script moves.
The display scroll work, the HBlank scroll work and its wave.
Song and sound effect ids, indices into gSound_SongTable.
#define NULL
Definition bilibin.h:6
STATIC_ASSERT, a compile-time check that emits nothing.
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
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 0x5e (lifetime), which FieldActor does not name.
struct FieldActor * linkedObject
void(*) callback(union FieldObject *object)
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
A world position, as Camera_WorldToScreen converts it to the screen.
Definition battle.h:73
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
struct FieldActor * linkedObject
The object its action script follows or faces.
Definition field_obj.h:114
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
A FieldActor seen with the halfword at 0x5e (its lifetime), which FieldActor does not name.
A field actor (struct FieldActor), seen with its position as one vector.
Definition run_scene.c:389
u8 pad2[0x2d]
Definition run_scene.c:395
u8 kind
Definition run_scene.c:394
struct EffectVector pos
Definition run_scene.c:392
struct AnimationObject * sprite
Definition run_scene.c:396
u8 pad1[14]
Definition run_scene.c:393
u8 pad0[6]
Definition run_scene.c:390
u16 angle
Definition run_scene.c:391
A FieldActor seen with the halfword at 0x5e (its lifetime), which FieldActor does not name.
s16 phase
phase of the sway (128 frames a cycle)
s32 anchorX
centre of the sway (FieldActor's targetX)
s32 gravity
as in FieldActor
void(*) update(union FieldObject *object)
u8 motionFlags
as in FieldActor
A particle's sprite, seen as the two fields Douse and Mind Read set on it.
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
Values that differ by patch level or language, chosen once for their code.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
UiWork, the window system's work, and the status screen's cursors.
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
The sprite VRAM block cache and its owners.
The window renderer's work.