Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
fire_breath.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09000A00_373DE0[];
5extern Gfx D_09000B88_373F68[];
6extern Gfx D_09000C00_373FE0[];
7extern Gfx D_09000C20_374000[];
8
11
15void fire_breath_appendGfx(void* effect);
16
18 s32 type,
19 f32 startX, f32 startY, f32 startZ,
20 f32 endX, f32 endY, f32 endZ,
21 s32 numExtra, s32 spawnDelay, s32 duration
22) {
24 FireBreathFXData* data;
25 EffectInstance* effect;
26 s32 numParts = 1;
27 s32* temp_a0;
28 f32 phi_f0;
29
30 bp.unk_00 = 0;
34 bp.renderUI = NULL;
35 bp.effectID = EFFECT_FIRE_BREATH;
36
37 effect = create_effect_instance(&bp);
38 effect->numParts = numParts;
39 data = effect->data.fireBreath = general_heap_malloc(numParts * sizeof(*data));
40 ASSERT(effect->data.fireBreath != NULL);
41
42 data->type = type;
43 data->numChildren = numExtra;
44 data->spawnDelay = spawnDelay;
45 data->pos.x = startX;
46 data->pos.y = startY;
47 data->pos.z = startZ;
48 data->initPos.x = startX;
49 data->initPos.y = startY;
50 data->initPos.z = startZ;
51 data->endPos.x = endX;
52 data->endPos.y = endY;
53 data->endPos.z = endZ;
54
55 if (type == FIRE_BREATH_LARGE) {
56 data->scale = 0.05f;
57 } else {
58 data->scale = 0.04f;
59 }
60
61 data->initialScale = data->scale;
62 data->duration = duration;
63 data->timeLeft = duration;
64 data->lifetime = 0;
65 data->alpha = 255;
66 data->animTime = 0.0f;
67 data->scaleChangeRate = 0.1f;
68 data->targetScale = data->initialScale;
69
70 if (type == FIRE_BREATH_LARGE) {
71 data->offsetPos.x = (endX - startX) * 0.2 * (effect_simple_rand(10, spawnDelay + 0) - 5) * 0.2;
72 data->offsetPos.y = (endY - startY) * 0.2 * (effect_simple_rand(10, spawnDelay + 1) - 5) * 0.2;
73 data->offsetPos.z = (endZ - startZ) * 0.2 * (effect_simple_rand(10, spawnDelay + 2) - 5) * 0.2;
74 } else {
75 data->offsetPos.x = (endX - startX) * 0.2 * (effect_simple_rand(10, spawnDelay + 3) - 5);
76 data->offsetPos.y = (endY - startY) * 0.2 * (effect_simple_rand(10, spawnDelay + 4) - 5);
77 data->offsetPos.z = (endZ - startZ) * 0.2 * (effect_simple_rand(10, spawnDelay + 5) - 5);
78 }
79
80 data->primR = 255;
81 data->primG = 170;
82 data->primB = 42;
83 data->velY = 0.0f;
84 data->envR = 243;
85 data->envG = 48;
86 data->envB = 0;
87
88 return effect;
89}
90
92}
93
95 FireBreathFXData* data = effect->data.fireBreath;
96 s32 duration;
97 s32 timeLeft;
98 s32 lifetime;
99
100 data->timeLeft--;
101 data->animTime = (data->lifetime * 4.0f) / 10.0f;
102 data->lifetime++;
103
104 if (data->timeLeft < 0) {
105 remove_effect(effect);
106 return;
107 }
108
109 timeLeft = data->timeLeft;
110 duration = data->duration;
111 lifetime = data->lifetime;
112
113 if (timeLeft >= 6 && data->type == FIRE_BREATH_LARGE) {
114 data->scale += (2.5 - data->scale) * 0.05;
115 }
116
117 data->pos.x = data->initPos.x + (((data->endPos.x - data->initPos.x + data->offsetPos.x) * lifetime) / duration);
118 data->pos.y = data->initPos.y + (((data->endPos.y - data->initPos.y + data->offsetPos.y) * lifetime) / duration);
119 data->pos.z = data->initPos.z + (((data->endPos.z - data->initPos.z + data->offsetPos.z) * lifetime) / duration);
120
121 if (data->type == FIRE_BREATH_SMALL) {
122 data->velY += (f32) lifetime * 0.01;
123 data->pos.y += data->velY;
124 }
125
126 if (lifetime == data->spawnDelay + 1 && data->numChildren > 0) {
127 EffectInstance* spawned;
128
129 load_effect(EFFECT_FIRE_BREATH);
130 spawned = fire_breath_main(
131 data->type, data->initPos.x, data->initPos.y, data->initPos.z, data->endPos.x, data->endPos.y,
132 data->endPos.z, data->numChildren - 1, data->spawnDelay, duration
133 );
134
135 spawned->data.fireBreath->primR = data->primR;
136 spawned->data.fireBreath->primG = data->primG;
137 spawned->data.fireBreath->primB = data->primB;
138 spawned->data.fireBreath->envR = data->envR;
139 spawned->data.fireBreath->envG = data->envG;
140 spawned->data.fireBreath->envB = data->envB;
141 spawned->data.fireBreath->initialScale = spawned->data.fireBreath->scale = data->initialScale;
142 spawned->data.fireBreath->targetScale = data->targetScale;
144 }
145
146 if (timeLeft < 10 && data->type == FIRE_BREATH_LARGE) {
147 data->alpha = timeLeft * 25;
148 }
149
150 if (data->type == FIRE_BREATH_SMALL) {
151 data->scale += (0.3 - data->scale) * 0.008;
152 data->alpha = (timeLeft * 224) / duration;
153 }
154
155 if (data->type == FIRE_BREATH_TINY) {
156 data->scale += (data->targetScale - data->scale) * data->scaleChangeRate;
157 data->alpha = (timeLeft * 224) / duration;
158 }
159}
160
162 FireBreathFXData* data = effect->data.fireBreath;
163 RenderTask renderTask;
164 RenderTask* retTask;
165 RenderTask* renderTaskPointer = &renderTask;
166
167 renderTask.appendGfx = fire_breath_appendGfx;
168 renderTask.appendGfxArg = effect;
169
171 renderTask.dist = data->pos.z + 1000.0f;
172 } else {
173 renderTask.dist = 0;
174 }
175
176 renderTaskPointer->renderMode = RENDER_MODE_CLOUD_NO_ZCMP;
177 retTask = queue_render_task(renderTaskPointer);
179}
180
181void fire_breath_appendGfx(void* effect) {
182 Matrix4f transformMtx;
183 Matrix4f tempMtx;
184 FireBreathFXData* data = ((EffectInstance*)effect)->data.fireBreath;
185 s32 type = data->type;
186 s32 envAlpha = (data->animTime - (s32)data->animTime) * 256.0f;
187 Gfx* dlist = D_E006EC00[type];
188 Gfx* dlist2 = D_E006EC0C[type];
189 s32 imgFrame = data->animTime;
190
191 gDPPipeSync(gMainGfxPos++);
192 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
193
194 if (type == FIRE_BREATH_SMALL) {
195 guTranslateF(transformMtx, data->initPos.x, data->initPos.y, data->initPos.z);
196 guRotateF(tempMtx, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
197 guMtxCatF(tempMtx, transformMtx, transformMtx);
199
201 G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
202 gSPDisplayList(gMainGfxPos++, D_09000C20_374000);
203 gSPDisplayList(gMainGfxPos++, D_09000C00_373FE0);
204 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
205 }
206
207 gSPDisplayList(gMainGfxPos++, dlist2);
208 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->primR, data->primG, data->primB, data->alpha);
209 gDPSetEnvColor(gMainGfxPos++, data->envR, data->envG, data->envB, envAlpha);
210 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, ((imgFrame * 32) + 0) * 4, 0, ((imgFrame * 32) + 32) * 4, 128);
211 gDPSetTileSize(gMainGfxPos++, 1, ((imgFrame * 32) + 32) * 4, 0, ((imgFrame * 32) + 64) * 4, 128);
212
213 guTranslateF(transformMtx, data->pos.x, data->pos.y, data->pos.z);
214 guRotateF(tempMtx, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
215 guMtxCatF(tempMtx, transformMtx, transformMtx);
216 guScaleF(tempMtx, data->scale, data->scale, 0.0f);
217 guMtxCatF(tempMtx, transformMtx, transformMtx);
219
221 G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
222 gSPDisplayList(gMainGfxPos++, dlist);
223 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
224}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define load_effect
#define create_effect_instance
#define guScaleF
struct FireBreathFXData * fireBreath
Definition effects.h:2519
@ FIRE_BREATH_TINY
Definition effects.h:2681
@ FIRE_BREATH_LARGE
Definition effects.h:2679
@ FIRE_BREATH_SMALL
Definition effects.h:2680
EffectData data
Definition effects.h:2605
s32 effect_simple_rand(s32, s32)
#define ASSERT(condition)
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ CONTEXT_BATTLE
Definition enums.h:3530
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void fire_breath_appendGfx(void *effect)
void fire_breath_update(EffectInstance *effect)
Definition fire_breath.c:94
Gfx D_09000C20_374000[]
Gfx * D_E006EC0C[]
Definition fire_breath.c:10
EffectInstance * fire_breath_main(s32 type, f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ, s32 numExtra, s32 spawnDelay, s32 duration)
Definition fire_breath.c:17
Gfx D_09000A00_373DE0[]
Gfx * D_E006EC00[]
Definition fire_breath.c:9
void fire_breath_render(EffectInstance *effect)
Gfx D_09000B88_373F68[]
void fire_breath_init(EffectInstance *effect)
Definition fire_breath.c:91
Gfx D_09000C00_373FE0[]
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
void(* renderUI)(EffectInstance *effectInst)
Definition effects.h:2655
void(* init)(EffectInstance *effectInst)
Definition effects.h:2652
void(* update)(EffectInstance *effectInst)
Definition effects.h:2653
void(* renderWorld)(EffectInstance *effectInst)
Definition effects.h:2654
void * appendGfxArg
void(* appendGfx)(void *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16