Alchemy
Loading...
Searching...
No Matches

flare.c

Go to the documentation of this file.
1/// @file
2/// Flare.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7#define FLARE_ARC_COUNT 9 ///< flames on the arc
8
9/// Flame arc: nine flames rise one after another, 4 frames apart, along a half
10/// circle, over 80 frames.
11///
12/// Abilities: Flare, Flare Wall, Flare Storm (kind 11).
13///
14/// Each target flashes red in turn, 8 frames apart from frame 16. Writes
15/// REG_BLDCNT and REG_BLDALPHA, and ends with the blitter freed, the transfer
16/// callback removed and the canvas layer closed.
17///
18/// effect: the targets. variant 1 adds a second flame 16 pixels above each
19/// one, variant 2 a third 32 pixels above (and longer trails).
21 u32 *slots;
22 u32 *cursor;
23 struct BattleEffectWork *work;
24 void *canvas;
25 s32 frame;
26 DrawRectangle draw;
27 s32 i;
28 s32 cell;
29 u32 width;
30 s32 direction;
31 s32 originX;
32 s32 angle;
33 s32 delay;
34 struct EffectStep *arcFlame;
35 struct EffectStep *flame;
36
37 // The work, the canvas, and BG1 and BG2 blended at 14:16.
39 cursor = slots;
40 work = (struct BattleEffectWork *)*cursor++;
41 canvas = (void *)*cursor;
42 work->effect = effect;
46 REG_BLDALPHA = BLEND_ALPHA(14, 16);
48 1);
52
53 // The arc: from -90 degrees in steps of 22.5, 32 pixels across and 16
54 // high. Against enemies (ids from 128) it runs from the left, otherwise
55 // from the right.
56 if (work->effect->actors[0] > 127) {
57 originX = 0;
58 direction = 1;
59 } else {
60 originX = 64;
61 direction = -1;
62 }
63 angle = -0x4000;
64 i = 0;
65 delay = 0;
66 // Each flame starts 4 frames after the one before: its variant counts up
67 // from a negative delay, and the flame shows from 0.
68 arcFlame = work->particles;
69 do {
70 arcFlame->x =
71 ((direction * (((Trig_Sin(angle) * 32)) >> 16)) + originX) + 20;
72 arcFlame->y = (((Trig_Cos(angle) * 16)) >> 16) + 40;
73 arcFlame->variant = delay;
74 angle += 0x1000;
75 delay -= 4;
76 i += 1;
77 arcFlame++;
78 } while (i != FLARE_ARC_COUNT);
79
80 // Trails keep half of each level, or three quarters for Flare Storm.
82 if (work->effect->variant == 2) {
83 work->transferValue = 75;
84 } else {
85 work->transferValue = 50;
86 }
90 frame = 0;
91 do {
92 // Frame 24 lets the battle show the damage, with SE_133 as the hit sound.
93 if (frame == 24) {
95 }
96
97 // Each flame shows six pictures, 4 frames each, and goes out; the last
98 // flame (delay -32) is out after frame 55. Each puff cell stands on its
99 // own baseline (gBattleFx_PuffArcCellBiasY) and is centred across x.
100 i = 0;
101 flame = work->particles;
102 do {
103 if ((flame->variant >= 0) && (flame->variant <= 23)) {
104 cell = flame->variant / 4;
105 // UB: width is assigned in one argument and read in another.
106#ifdef UBFIX
107 width = gBattleFx_PuffArcCellWidths[cell];
108 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
109 flame->x - (width >> 1),
110 flame->y + gBattleFx_PuffArcCellBiasY[cell], width,
112#else
113 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
114 flame->x - ((width = gBattleFx_PuffArcCellWidths[cell]) >> 1),
115 flame->y + gBattleFx_PuffArcCellBiasY[cell], width,
117#endif
118 if (work->effect->variant != 0) {
119#ifdef UBFIX
120 width = gBattleFx_PuffArcCellWidths[cell];
121 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
122 flame->x - (width >> 1),
123 (flame->y + gBattleFx_PuffArcCellBiasY[cell]) - 16, width,
125#else
126 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
127 flame->x - ((width = gBattleFx_PuffArcCellWidths[cell]) >> 1),
128 (flame->y + gBattleFx_PuffArcCellBiasY[cell]) - 16, width,
130#endif
131 }
132 if (work->effect->variant == 2) {
133#ifdef UBFIX
134 width = gBattleFx_PuffArcCellWidths[cell];
135 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
136 flame->x - (width >> 1),
137 (flame->y + gBattleFx_PuffArcCellBiasY[cell]) - 32, width,
139#else
140 draw(canvas, work->sheet + gBattleFx_PuffArcCells[cell],
141 flame->x - ((width = gBattleFx_PuffArcCellWidths[cell]) >> 1),
142 (flame->y + gBattleFx_PuffArcCellBiasY[cell]) - 32, width,
144#endif
145 }
146 }
147 i += 1;
148 flame->variant += 1;
149 flame++;
150 } while (i != FLARE_ARC_COUNT);
151
152 // The targets flash red, 8 frames apart from frame 16.
153 i = 0;
154 while (i != work->effect->count) {
155 if (frame == (i * 8) + 16) {
158 }
159 i += 1;
160 }
161 EFFECT_END_FRAME(work);
162 frame += 1;
163 } while (frame != 80);
167}
168
169/// List the indices within indexRadius of where currentValue sits in values,
170/// keeping only those from 0 to entryLimit - 1. Writes the indices to output
171/// and returns how many there are.
172///
173/// Only the first indexRadius * 2 + 1 values are searched, and with no match
174/// the window centres on index 0. Changes nothing but output. Nothing calls it.
176 s16 *output) {
177 s32 windowLength = window->indexRadius * 2 + 1;
178 s32 outputCount = 0;
179 s32 centerIndex = 0;
180 s32 windowIndex;
181
182 for (windowIndex = 0; windowIndex != windowLength; windowIndex++) {
183 if (window->currentValue == window->values[windowIndex]) {
184 centerIndex = windowIndex;
185 break;
186 }
187 }
188 for (windowIndex = 0; windowIndex != windowLength; windowIndex++) {
189 s32 index = centerIndex + windowIndex - window->indexRadius;
190
191 if (index >= 0 && index < window->entryLimit) {
192 output[outputCount++] = index;
193 }
194 }
195 return outputCount;
196}
197
198#undef FLARE_ARC_COUNT
@ SPRITE_COLOR_RED_TINT
red raised to full
Definition animspr.h:28
@ POSE_DAMAGE
taking damage
Definition battle.h:176
@ COMPOSITE_ADDITIVE
BattleEffectDrawRectangle DrawRectangle
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 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_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_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...
u16 gBattleFx_PuffArcCells[]
u8 gBattleFx_PuffArcCellHeights[]
u8 gBattleFx_PuffArcCellBiasY[]
u8 gBattleFx_PuffArcCellWidths[]
void AudioCommand_PlayFar(s32 id)
s32 Trig_Cos(s32 angle)
s32 Trig_Sin(s32 angle)
#define FLARE_ARC_COUNT
flames on the arc
Definition flare.c:7
void BattleFx_RunFlare(struct BattleEffectArgument *effect)
Flame arc: nine flames rise one after another, 4 frames apart, along a half circle,...
Definition flare.c:20
UNUSED s32 BattleFx_BuildCenteredIndexList(BattleEffectIndexWindow *window, s16 *output)
List the indices within indexRadius of where currentValue sits in values, keeping only those from 0 t...
Definition flare.c:175
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
@ HEAP_SLOT_BLITTER
Definition heap_state.h:46
#define BLDCNT_TGT1_BG2
Definition io_reg.h:125
#define BLDCNT_EFFECT_BLEND
weighted by REG_BLDALPHA
Definition io_reg.h:131
#define BLDCNT_TGT2_ALL
Definition io_reg.h:140
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
Definition io_reg.h:145
#define BLDCNT_TGT1_BG1
Definition io_reg.h:124
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_BLDCNT
Definition io_reg.h:119
void Runtime_ReleaseHeapBlock(s32 slot)
char ResourceId_EmberStreakSheet
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_133
Definition songs.h:126
#define SE_136
Definition songs.h:129
void * gWorkSlot[]
The command shared by an effect's caller, dispatcher and handlers.
s16 actors[8]
the targets' unit ids, count of them
s32 variant
the ability's size, from 0 (Quake, then Earthquake)
s32 count
targets in actors, at least 1
What BattleFx_BuildCenteredIndexList (unused) reads: a value to find in a list, and how many indices ...
Definition effect.h:209
s16 values[1]
indexRadius * 2 + 1 values, searched in order
Definition effect.h:215
s32 indexRadius
indices kept either side of where it sits
Definition effect.h:212
s32 currentValue
the value looked for in values
Definition effect.h:211
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
s32 transferMode
How the canvas transfer callbacks treat the canvas after each copy (enum CanvasTransferMode in effect...
s32 transferValue
The transfer mode's argument: the fill value, the share kept (50 or 75 percent) or the darken or brig...
struct BattleEffectArgument * effect
the command being run
struct EffectStep particles[64]
free while variant is -1
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 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
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
#define UNUSED
Definition types.h:22
#define EFFECT_CLIP_BOUNDS
Clips overflow on all four sides.
Definition effect.h:224