Alchemy
Loading...
Searching...
No Matches

gathering_lights.c

Go to the documentation of this file.
1/// @file
2/// Demon Night, Rumble and Haunting.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7// The lights take 128 slots of PARTICLES per target, and ripple the effect
8// layer throughout through the HBlank DMA of BG2's affine origin.
9
10// Lights that scatter from the user and gather into each target.
11
12/// Sixteen pink lights burst out of the user and are pulled into each target,
13/// with the heavy impact sound.
14///
15/// Abilities: Demon Night (kind 50).
18}
19/// Eight lights in Mars Djinn colours burst out of the user and are pulled into
20/// each target.
21///
22/// Abilities: Rumble (kind 308).
25}
26/// Twelve lights in Mercury Djinn colours burst out of the user and are pulled
27/// into each target.
28///
29/// Abilities: Haunting (kind 351).
32}
33#define GATHERING_LIGHTS_SLOTS 128 ///< particles reserved for each target
34
35/// For each target in turn, 20 frames apart, lights burst out of the user,
36/// one every 2 frames; from 30 frames into the turn, one more each frame is
37/// pulled towards the middle of the target's body, and goes out when it is
38/// within 32 pixels across and in depth. Each light takes one of three
39/// images. Each target is struck 70 frames after its turn starts, and the
40/// battle shows the damage at frame 80. The effect layer ripples throughout.
41///
42/// Called by BattleFx_RunDemonNight, BattleFx_RunRumble and
43/// BattleFx_RunHaunting. Loads its colours over the first 64 of the
44/// background palette, uses PARTICLES 0 to 1023, writes work->bg2xLines each
45/// frame and adds BattleFx_ArmBg2AffineHBlankDma to feed it to BG2X; removes
46/// both its callbacks before it returns.
47///
48/// mode : the colours (0 pink, 1 Mars Djinn, 2 Mercury Djinn) and the row of
49/// gGatheringLights_Counts: lights per target and frames.
51 s32 mode) {
52 struct EffectPosition screenPosition;
53 BlitterPair draw;
54 void **slots;
55 void **cursor;
56 struct BattleEffectWork *work;
57 void *canvas;
58 s32 frame;
59 s32 k;
60 struct BattleCamera *camera;
61 s32 paletteId;
62 s32 i;
63
64 EFFECT_GET_SLOTS(slots, cursor, work, canvas);
65 camera = EFFECT_SLOT(slots, HEAP_SLOT_CAMERA);
66 work->effect = effect;
68 // Setup. The sheet is the first field of the work block, so the pictures
69 // decode to `work` itself: three 20x32 lights.
72 if (mode == 0)
73 paletteId = (s32)&ResourceId_PinkBurstSheet;
74 else if (mode == 1)
75 paletteId = (s32)&ResourceId_MarsDjinnSheet;
76 else
78 Iwram_CopyWords((void *)BG_PLTT, Resource_GetTableEntry(paletteId), 128);
80
81 // The lights start at the top of the user's body and fly off in any
82 // direction at up to 2 pixels a frame.
85 struct MotionObject *src =
88
89 for (i = 0; i != GATHERING_LIGHTS_SLOTS; i++) {
90 struct EffectStep *mote = &PARTICLES[k * GATHERING_LIGHTS_SLOTS + i];
91
92 SET_POSITION(mote, src->x, height, src->z);
93 SET_VELOCITY(mote, ((Random16() & 255) - 128) << 10,
94 ((Random16() & 255) - 128) << 10,
95 ((Random16() & 255) - 128) << 10);
96 mote->variant = 0;
97 }
98 }
99
102 // Trails keep 3/4 a frame.
105
106 for (frame = 0;
108 work->effect->count * 20;
109 frame++) {
110 s32 *row;
111
112 // Frame loop. The damage shows on frame 80 whatever the number of
113 // targets, with the mode's hit sound.
114 if (frame == 80) {
115 if (mode == 0)
117 else
119 }
121
122 // Ripple the canvas sideways, line by line: 4 texels either way about a
123 // 4-texel offset (16.16 >> 10 is a quarter in BG2X's 20.8).
124 row = work->bg2xLines;
125 for (i = 0; i != 160; i++)
126 *row++ = (0x100000 - Trig_Sin((frame + i) << 10) * 16) >> 10;
127
129 struct MotionObject *target =
131 s32 half = BattleUnit_GetEffectHeightFar(work->effect->actors[k]) / 2;
132
133 if (frame == k * 20 + 71) {
134 if (mode == 0)
136 else
138 }
139 if (frame == k * 20 + 70)
141 POSE_DAMAGE, k, 26);
142 if (frame > k * 20) {
143 for (i = 0; i != gGatheringLights_Counts[mode][GATHERING_LIGHTS_COUNT];
144 i++) {
145 struct EffectStep *mote = &PARTICLES[k * GATHERING_LIGHTS_SLOTS + i];
146
147 if (frame > (k * 10 + i) * 2 && mote->variant >= 0) {
148 EffectPosition_ProjectPoint(mote, &screenPosition);
149 screenPosition.x >>= 1;
150 draw[0](canvas, work->sheet + i % 3 * (20 * 32),
151 screenPosition.x - 10, screenPosition.y - 16, 20, 32);
153 // The pull: 1/512 of the distance added to the speed each frame.
154 if (frame > k * 20 + i + 30) {
155 s32 dx = (target->x - mote->x) >> 9;
156 s32 dy = (target->y + half - mote->y) >> 9;
157 s32 dz = (target->z - mote->z) >> 9;
158
159 mote->velocityX += dx;
160 mote->velocityY += dy;
161 mote->velocityZ += dz;
162 if ((dx >= -0xfff && dx <= 0xfff) &&
163 (dz >= -0xfff && dz <= 0xfff))
164 mote->variant = -1;
165 }
166 }
167 }
168 }
169 }
170 EFFECT_END_FRAME(work);
171 }
172
173 // Finish: the transfer goes before the blitters and the DMA callback
174 // before the layer closes.
179}
180
181#undef GATHERING_LIGHTS_SLOTS
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
@ POSE_DAMAGE
taking damage
Definition battle.h:176
#define EFFECT_FOR_EACH_TARGET(i, effect)
Loops i over the effect's targets, effect->actors[0] to effect->actors[effect->count - 1]: the loops ...
void BattleFx_ArmBg2AffineHBlankDma(void)
Arms DMA 0 to copy one word of gBattleFxWork's bg2xLines table into BG2X at each horizontal blank,...
void BattleFx_ProcessPendingGraphicsTransfer(void)
Copies the canvas to VRAM once the effect has finished drawing a frame (transferPending): the 128x128...
Definition canvas.c:103
void BattleFx_BeginCanvasLayer(s32 bgControl)
Opens the canvas layer: starts the background palette fade, makes BG2 the canvas, alpha-blended over ...
Definition canvas.c:314
void BattleFx_EndCanvasLayer(void)
Closes the canvas layer: plays the closing sound, restores BG1's scroll and the projection centre,...
Definition canvas.c:490
void ObjectGroup_UpdateMembers(s32 actorId, s32 palette, s32 animation, s32 timerSlot, s32 timerFrames)
Updates every animation group of one battler's object.
Definition dispatch.c:254
What every part of the battle effect object shares: its includes, macros and frame-loop helpers.
#define EFFECT_RELEASE_BLITTERS()
Frees the two blitters, the alternate first.
@ CANVAS_COPY_AND_FADE
copy, keeping 50% or 75% (transferValue) of each pixel in the canvas for the next frame
#define EFFECT_CALLBACK_ORDER
The scheduler order of every per-frame effect callback (Scheduler_AddOrUpdateCallback sorts the frame...
#define EFFECT_SLOT(slots, slot)
A work slot read through a pointer to the effect's own slot, gWorkSlot[HEAP_SLOT_BATTLE_EFFECT].
#define EFFECT_SHOW_DAMAGE(hitSound)
Lets the battle show the damage: resumes its paused playback, which plays hitSound (an SE_ id; 0 keep...
#define EFFECT_START_TRANSFER(work, mode, value)
Sets the transfer, then starts copying the canvas to VRAM once a frame.
#define EFFECT_FREE_PARTICLES(i, particles, count)
Marks particles[0] to particles[count - 1] free: a particle whose variant is -1 is not drawn or moved...
#define EFFECT_GET_SLOTS(slots, cursor, work, canvas)
Starts at the effect's entry in the whole work-slot array.
#define EFFECT_END_FRAME(work)
The usual end of an effect frame: counts down the targets' flash timers (ObjectGroup_TickMemberTimers...
#define EFFECT_VIEW_FROM_CAMERA(camera)
Starts a frame's 3D projection from the battle camera: resets the transform, then looks from camera->...
u8 gGatheringLights_Counts[][2]
Gathering lights (Demon Night, Rumble, Haunting), by mode: the lights per target and the frames befor...
@ GATHERING_LIGHTS_COUNT
lights for each target
@ GATHERING_LIGHTS_FRAMES
frames before the targets' turns
struct BattleObj * GetBattleObjectSlotFar(s32 objectId)
Far call to BattleObjGet.
s32 BattleUnit_GetEffectHeightFar(s32 id)
void AudioCommand_PlayFar(s32 id)
s32 Trig_Sin(s32 angle)
void BattleFx_RunRumble(struct BattleEffectArgument *effect)
Eight lights in Mars Djinn colours burst out of the user and are pulled into each target.
void BattleFx_RunDemonNight(struct BattleEffectArgument *effect)
Sixteen pink lights burst out of the user and are pulled into each target, with the heavy impact soun...
void BattleFx_RunHaunting(struct BattleEffectArgument *effect)
Twelve lights in Mercury Djinn colours burst out of the user and are pulled into each target.
void BattleFx_RunGatheringLights(struct BattleEffectArgument *effect, s32 mode)
For each target in turn, 20 frames apart, lights burst out of the user, one every 2 frames; from 30 f...
#define GATHERING_LIGHTS_SLOTS
particles reserved for each target
@ HEAP_SLOT_CAMERA
Definition heap_state.h:38
#define BG_PLTT
Definition io_reg.h:157
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
Definition iwram_call.h:85
#define SET_VELOCITY(p, vx, vy, vz)
Definition macros.h:18
#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
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
void BattleFx_FetchRectangleBlitters(s32 flip, BlitterPair out)
Builds the two usual routines that draw onto the 128x128 canvas, both clipped on both axes.
void EffectStep_AdvanceWithGravity3D(struct EffectStep *step, s32 damping, s32 gravity)
Moves a particle one frame in three dimensions: adds its velocity, then gravity to its vertical speed...
Definition positions.c:29
s32 EffectPosition_ProjectPoint(const void *point, struct EffectPosition *position)
Projects a point in the current transform onto the screen, 16 pixels higher, and returns the projecti...
Definition positions.c:64
char ResourceId_PinkBurstSheet
char ResourceId_MemberBurstImage
char ResourceId_MarsDjinnSheet
char ResourceId_MercuryDjinnSheet
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
Definition decompress.c:31
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
Definition scheduler.c:102
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
#define SE_146
Definition songs.h:139
#define SE_133
Definition songs.h:126
#define SE_HEAVY_IMPACT
Definition songs.h:127
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
The command shared by an effect's caller, dispatcher and handlers.
s32 actor
the user's unit id
s32 side
1 when the targets are the party, 0 for enemies
s16 actors[8]
the targets' unit ids, count of them
s32 count
targets in actors, at least 1
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
s32 frame
frame counter some effects keep, from 0
struct BattleEffectArgument * effect
the command being run
struct MotionObject * object
NULL once released.
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
s32 x
screen pixels
Definition effect_step.h:58
A moving point of an effect: its position, its velocity and a value each effect uses its own way (a s...
Definition effect_step.h:13
s32 velocityX
16.16 fixed-point pixels per frame
Definition effect_step.h:28
s32 z
16.16 fixed-point pixels
Definition effect_step.h:26
s32 variant
each effect's own: a size, a countdown, -1 for idle
Definition effect_step.h:31
s32 x
16.16 fixed-point pixels
Definition effect_step.h:24
s32 y
16.16 fixed-point pixels
Definition effect_step.h:25
s32 velocityY
16.16 fixed-point pixels per frame
Definition effect_step.h:29
s32 velocityZ
16.16 fixed-point pixels per frame
Definition effect_step.h:30
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
Definition motobj.h:20
s32 z
16.16 fixed-point pixels
Definition motobj.h:25
s32 y
16.16 fixed-point pixels
Definition motobj.h:24
u16 height
half the sprite's box height; FieldActor's radius
Definition motobj.h:29
s32 x
16.16 fixed-point pixels
Definition motobj.h:23
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
signed int s32
Definition types.h:14
#define PARTICLES
The map cell buffer (gMapCellBuffer), which the effects borrow, has two views here: Ram_MapCellBuffer...
Definition effect.h:221
DrawRectangle BlitterPair[2]
A blitter pair: [0] built in HEAP_SLOT_BLITTER and [1] in HEAP_SLOT_BLITTER_ALTERNATE (BattleFx_Fetch...
Definition effect.h:244