Alchemy
Loading...
Searching...
No Matches

eruption.c

Go to the documentation of this file.
1/// @file
2/// Smoke Bomb and Blast.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7/// A fountain of grey motes and puffs of smoke bursts up beside the targets and
8/// falls back, flashing each target.
9///
10/// Abilities: Smoke Bomb, Sleep Bomb (kind 380).
11///
12/// It always uses the second row of gEruption_Counts: 32 motes, 16 puffs, 80
13/// frames.
15 BattleFx_RunEruption(effect, 1);
16}
17/// A fountain of fire-coloured motes and puffs of smoke bursts up beside the
18/// targets and falls back, flashing each target and making it recoil.
19///
20/// Abilities: Blast, Mad Blast, Fiery Blast (kind 14).
22 BattleFx_RunEruption(effect, 0);
23}
24/// The columns of a gEruption_Counts row.
25enum {
26 ERUPTION_FIELD_MOTES, ///< motes thrown
27 ERUPTION_FIELD_PUFFS, ///< puffs of smoke thrown
28 ERUPTION_FIELD_FRAMES ///< frames in the whole effect
29};
30
31/// The mote pictures in the sheet: two sets, MOTE_SET_BYTES apart.
32#define ERUPTION_FIELD_MOTE_CELLS 0x3200
33
34/// A fountain of motes and puffs of smoke bursts up beside the targets and
35/// falls back, hitting the targets one frame apart from frame 6.
36///
37/// Called by BattleFx_RunBlast (mode 0) and BattleFx_RunSmokeBomb (mode 1).
38/// A sound and a 6-frame screen shake start on frame 2, and the battle shows
39/// the damage 48 frames before the end. Writes the first 64 BG colours, sets
40/// work->shakeFrames, and ends with the transfer callback removed, the
41/// blitter freed and the canvas layer closed.
42///
43/// effect: the targets.
44/// mode: 0 burns (the fire streak palette, the effect's variant picks the
45/// counts, and the targets recoil); 1 is grey (a ramp of greys,
46/// variant 1's counts).
47void BattleFx_RunEruption(struct BattleEffectArgument *effect, s32 mode) {
48 void **cursor;
49 struct BattleEffectWork *work;
50 void *canvas;
51 /* FAKEMATCH: only draw[0] is used; the unused second word fills four bytes
52 * of the frame; as one DrawRectangle, 20 instructions differ in tbs-en, each
53 * a frame offset. */
54 BlitterPair draw;
55 s32 variant;
56 struct EffectPosition screen;
57 s32 frame;
58 s32 i;
59
60 cursor = gBattleFxWork;
61 EFFECT_GET_WORK_AND_CANVAS(cursor, work, canvas);
62 work->effect = effect;
65 // Smoke Bomb's palette is a ramp of greys, two levels to each step of
66 // brightness, 0 to 31; Blast takes the fire streak's.
67 if (mode == 1) {
68 for (i = 0; i != 64; i++) {
69 s32 level = i / 2;
70
71 BG_PLTT[i] = RGB(level, level, level);
72 }
73 variant = 1;
74 } else {
77 128);
78 variant = work->effect->variant;
79 }
80
81 // The puffs and the motes start 50 pixels to the side and scatter up;
82 // the motes leave at up to twice the puffs' speed. All 32 puffs and 1024
83 // motes are placed, more than any row of gEruption_Counts uses.
84 for (i = 0; i != 32; i++) {
85 struct EffectStep *puff = &work->particles[i];
86
87 if (work->effect->side == 1)
88 puff->x = 200 << 14;
89 else
90 puff->x = -(200 << 14);
91 puff->y = 0;
92 puff->z = 0;
93 SET_VELOCITY(puff, ((Random16() & 63) - 32) << 13,
94 ((Random16() & 63) + 16) << 12,
95 ((Random16() & 63) - 32) << 13);
96 puff->variant = 0;
97 }
98 for (i = 0; i != 1024; i++) {
99 struct EffectStep *mote = &PARTICLES[i];
100
101 if (work->effect->side == 1)
102 mote->x = 200 << 14;
103 else
104 mote->x = -(200 << 14);
105 mote->y = 0;
106 mote->z = 0;
107 SET_VELOCITY(mote, ((Random16() & 63) - 32) << 13,
108 ((Random16() & 31) + 8) << 13, ((Random16() & 63) - 32) << 13);
109 mote->variant = 0;
110 }
111
115
116 for (frame = 0; frame != gEruption_Counts[variant][ERUPTION_FIELD_FRAMES];
117 frame++) {
118 struct BattleCamera *camera;
119
120 camera = gCameraWork;
122 if (frame == 2)
124 if (frame == gEruption_Counts[variant][ERUPTION_FIELD_FRAMES] - 48)
126
127 // The motes still above the ground, sized 9 down to 1 over depths 160
128 // to 799, alternating the two mote sets. The half-width x is shifted 16
129 // pixels left, or right on side 1.
130 for (i = 0; i != gEruption_Counts[variant][ERUPTION_FIELD_MOTES]; i++) {
131 struct EffectStep *mote = &PARTICLES[i];
132
133 if (mote->y >= 0) {
134 s32 size;
135
136 EffectPosition_ProjectPoint(mote, &screen);
137 screen.x >>= 1;
138 screen.x += work->effect->side * 32 - 16;
139 CLAMP(screen.depth, 160, 799);
140 size = 9 - (screen.depth - 160) / 64;
141 draw[0](canvas,
142 work->sheet +
143 (gBattleFx_MoteCells[size - 1] + (i & 1) * MOTE_SET_BYTES) +
145 screen.x - size / 2, screen.y - size, size, size * 2);
146 EffectStep_AdvanceWithGravity3D(mote, 64, -0x2000);
147 }
148 }
149
150 // The puffs, from frame 3: puff i starts once the frame passes i and
151 // plays seven pictures, 3 frames each, while above the ground.
152 if (frame > 2) {
153 for (i = 0; i != gEruption_Counts[variant][ERUPTION_FIELD_PUFFS]; i++) {
154 struct EffectStep *puff = &work->particles[i];
155
156 if (i < frame && puff->y >= 0) {
157 EffectPosition_ProjectPoint(puff, &screen);
158 screen.x >>= 1;
159 screen.x += work->effect->side * 32 - 16;
160 if (puff->variant >= 0 && puff->variant <= 20) {
161 s32 cell = puff->variant / 3;
162 u32 width;
163
164 // UB: width is assigned in one argument and read in another.
165#ifdef UBFIX
166 width = gEruption_PuffSizes[cell];
167 draw[0](canvas, work->sheet + gEruption_PuffCells[cell],
168 screen.x - (width >> 1), screen.y - (width >> 1), width,
169 width);
170#else
171 draw[0](canvas, work->sheet + gEruption_PuffCells[cell],
172 screen.x - ((width = gEruption_PuffSizes[cell]) >> 1),
173 screen.y - (width >> 1), width, width);
174#endif
175 }
176 if (puff->variant <= 20)
177 puff->variant++;
178 EffectStep_AdvanceWithGravity3D(puff, 64, -0x2000);
179 }
180 }
181 }
182
183 // The hits, one target a frame from frame 6; Blast's targets also recoil
184 // (battle motion 2).
185 if (mode == 0) {
187 if (frame == i + 6) {
189 POSE_DAMAGE, i, 10);
191 }
192 }
193 } else {
195 if (frame == i + 6)
197 POSE_DAMAGE, i, 10);
198 }
199 }
200 if (frame == 2)
201 work->shakeFrames = 6;
202 Camera_ApplyShake(16, 16);
203 EFFECT_END_FRAME(work);
204 }
205
207}
208
209/// Creates the effect's animation objects in gBattleFxWork's objects.
210///
211/// Called by the summon scenes (Ramses, Nereid, Kirin, Atalanta, Cybele,
212/// Neptune, Tiamat, Procne, Boreas, Thor), Judgment and the particle streams.
213/// Fills work->objects[0] to [entryCount - 1]: object n plays animation n,
214/// with its flags cleared and its sprite priority set. A slot whose object
215/// could not be created is left NULL.
216///
217/// entryCount: how many objects to create.
218/// source: the resource object every one of them is made from.
219/// priority: the sprite priority they take.
220void BattleFx_SpawnObjects(s32 entryCount, s32 source, u32 priority) {
222 s32 entryIndex = 0;
223
224 if (entryCount == 0) {
225 return;
226 }
227 do {
228 struct AnimationObject *object = ResourceObject_CreateFar(source);
229
230 work->objects[entryIndex] = object;
231 if (object != 0) {
232 object->flags = 0;
233 AnimationObjects_SelectAnimationFar(object, entryIndex);
234 work->objects[entryIndex]->image.priority = priority;
235 }
236 entryIndex++;
237 } while (entryIndex != entryCount);
238}
239
240/// Does nothing. BattleFx_CallDoNothing calls it in a loop, 10000 times for
241/// Annihilation, a busy wait.
243
244#undef ERUPTION_FIELD_MOTE_CELLS
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
void * gBattleFxWork[]
@ POSE_DAMAGE
taking damage
Definition battle.h:176
struct BattleCamera * gCameraWork
@ COMPOSITE_MAX
BattleEffectDrawRectangle DrawRectangle
#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_BeginCanvasLayer(s32 bgControl)
Opens the canvas layer: starts the background palette fade, makes BG2 the canvas, alpha-blended over ...
Definition canvas.c:314
void Resource_LoadAndDecompress(s32 id, void *dst, s32 skipPalette, s32 copyPalette)
Decompresses a resource whose first 128 bytes may be a palette.
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.
@ CANVAS_COPY_AND_FADE
copy, keeping 50% or 75% (transferValue) of each pixel in the canvas for the next frame
#define EFFECT_GET_WORK_AND_CANVAS(cursor, work, canvas)
The work block and canvas occupy adjacent slots, starting at HEAP_SLOT_BATTLE_EFFECT.
#define MOTE_SET_BYTES
The bytes of one set of the ten mote cells: 2 * (1 + 4 + ... + 100).
#define EFFECT_FINISH_CANVAS_ONE_BLITTER()
The same for an effect that drew through one blitter.
#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_LOAD_BLITTER(slot, flags, mode)
Builds a blitter for the 128x128 canvas (1 << 7 pixels each way) in work slot slot: BattleFx_BuildBli...
#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 gEruption_Counts[][3]
Motes, puffs of smoke and frames, for each variant.
u16 gBattleFx_MoteCells[]
Mote cells: particle sheets hold ten, cell n (from 0) n + 1 pixels wide and twice that tall.
u16 gEruption_PuffCells[]
u16 gEruption_PuffSizes[]
void BattleFx_RunSmokeBomb(struct BattleEffectArgument *effect)
A fountain of grey motes and puffs of smoke bursts up beside the targets and falls back,...
Definition eruption.c:14
void BattleFx_SpawnObjects(s32 entryCount, s32 source, u32 priority)
Creates the effect's animation objects in gBattleFxWork's objects.
Definition eruption.c:220
#define ERUPTION_FIELD_MOTE_CELLS
The mote pictures in the sheet: two sets, MOTE_SET_BYTES apart.
Definition eruption.c:32
@ ERUPTION_FIELD_MOTES
motes thrown
Definition eruption.c:26
@ ERUPTION_FIELD_PUFFS
puffs of smoke thrown
Definition eruption.c:27
@ ERUPTION_FIELD_FRAMES
frames in the whole effect
Definition eruption.c:28
void BattleFx_DoNothing(void)
Does nothing.
Definition eruption.c:242
void BattleFx_RunBlast(struct BattleEffectArgument *effect)
A fountain of fire-coloured motes and puffs of smoke bursts up beside the targets and falls back,...
Definition eruption.c:21
void BattleFx_RunEruption(struct BattleEffectArgument *effect, s32 mode)
A fountain of motes and puffs of smoke bursts up beside the targets and falls back,...
Definition eruption.c:47
void BattleMotion_ApplyVariantMotionFar(s32 id, s32 variant)
s32 AnimationObjects_SelectAnimationFar(struct AnimationObject *state, s32 flags)
struct AnimationObject * ResourceObject_CreateFar(s32 id)
void AudioCommand_PlayFar(s32 id)
void Camera_ApplyShake(s32 rangeX, u32 rangeY)
Shakes the battle view while gBattleFxWork's shakeFrames lasts, moving BG1 and the projection centre ...
Definition hail.c:364
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
@ HEAP_SLOT_BLITTER
Definition heap_state.h:46
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
Definition heap_state.h:14
#define RGB(r, g, b)
A 15-bit colour from its red, green and blue levels (0 to 31 each), as the palette stores it: blue in...
Definition io_reg.h:164
#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 CLAMP(v, low, high)
Keeps v within low to high, the low bound tested first.
Definition macros.h:23
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
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_FireStreakSheet
char ResourceId_BlastSheet
#define SE_144
Definition songs.h:137
#define SE_133
Definition songs.h:126
void * gWorkSlot[]
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
u16 priority
2 when created
Definition animspr.h:100
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 side
1 when the targets are the party, 0 for enemies
s16 actors[8]
the targets' unit ids, count of them
s32 variant
the ability's size, from 0 (Quake, then Earthquake)
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
s32 shakeFrames
shake frames left; Camera_ApplyShake counts down
struct AnimationObject * objects[16]
the effect's animation objects
struct BattleEffectArgument * effect
the command being run
struct EffectStep particles[64]
free while variant is -1
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
s32 depth
projected depth, larger further away
Definition effect_step.h:60
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 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
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
unsigned int u32
Definition types.h:15
#define EFFECT_CLIP_BOUNDS
Clips overflow on all four sides.
Definition effect.h:224
#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