Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
damage_indicator.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09001D40_351F60[];
5extern Gfx D_09001DE0_352000[];
6extern Gfx D_09001E50_352070[];
7extern Gfx D_09001E90_3520B0[];
8extern Gfx D_09001ED0_3520F0[];
9extern Gfx D_09001F10_352130[];
10extern Gfx D_09001F50_352170[];
11extern Gfx D_09001F90_3521B0[];
12extern Gfx D_09001FD0_3521F0[];
13extern Gfx D_09002010_352230[];
14extern Gfx D_09002050_352270[];
15extern Gfx D_09002090_3522B0[];
16extern Gfx D_090020D0_3522F0[];
17extern Gfx D_09002110_352330[];
18extern Gfx D_09002150_352370[];
19extern Gfx D_09002160_352380[];
20extern Gfx D_09002170_352390[];
21extern Gfx D_09002180_3523A0[];
22extern Gfx D_09002190_3523B0[];
23extern Gfx D_090021A8_3523C8[];
24extern Gfx D_090021C0_3523E0[];
25extern Gfx D_090021E0_352400[];
26extern Gfx D_09002200_352420[];
27
33
34u8 D_E003CCD0[] = {
35 0x32, 0x37, 0x3C, 0x46, 0x50, 0x64, 0x96, 0xDC,
36 0xF0, 0xC8, 0x8C, 0x64, 0x8C, 0xA0, 0x8C, 0x96,
37 0x9B, 0x96, 0x94, 0x96, 0x96, 0x96, 0x96, 0x96,
38 0x96, 0x96, 0x96, 0x96, 0x96, 0x96, 0x9B, 0xA0,
39 0x9B, 0x91, 0x82, 0x6E, 0x55, 0x37, 0x19, 0x00
40};
41
42u8 D_E003CCF8[] = {
43 254, 172, 172,
44 254, 172, 213,
45 254, 180, 154,
46 213, 180, 254,
47 180, 180, 254,
48 180, 221, 254,
49 180, 254, 254,
50 180, 254, 213,
51 180, 254, 180,
52 213, 254, 180,
53 254, 254, 180,
54 254, 213, 172
55};
56
57f32 D_E003CD1C[] = {
58 0.0f,
59 0.1f,
60 0.2f,
61 0.3f,
62 0.4f,
63 0.5f,
64 0.6f,
65 0.7f,
66 0.8f
67};
68
74
75void damage_indicator_main(s32 arg0, f32 posX, f32 posY, f32 posZ, f32 starsRadius, f32 starsAngle, s32 damageAmt, EffectInstance** effectOut) {
77 EffectBlueprint* bpPtr = &bp;
78 EffectInstance* effect;
79 f32 angle;
81 s32 trueDamageAmt = damageAmt;
82 s32 i;
83
84 // limit number of stars that can appear
85 if (damageAmt > 20) {
86 damageAmt = 20;
87 }
88 damageAmt++;
89
94 bp.unk_00 = 0;
95 bp.effectID = EFFECT_DAMAGE_INDICATOR;
96
97 effect = create_effect_instance(bpPtr);
98 effect->numParts = damageAmt;
99
100 effect->data.damageIndicator = part = general_heap_malloc(damageAmt * sizeof(*part));
101 ASSERT(effect->data.damageIndicator != NULL);
102
103 part->unk_00 = arg0;
104 part->basePos.x = posX;
105 part->basePos.y = posY;
106 part->basePos.z = posZ;
107 part->radius = starsRadius;
108 part->timeLeft = 100;
109 part->lifetime = 0;
110 part->damageAmt = trueDamageAmt;
111
112 part++;
113 for (i = 1; i < damageAmt; i++, part++) {
114 part->basePos.x = 0.0f;
115 part->basePos.y = 0.0f;
116 part->basePos.z = 0.0f;
117 part->curPos.x = part->basePos.x;
118 part->curPos.y = part->basePos.y;
119 part->curPos.z = part->basePos.z;
120 angle = starsAngle + (((s32) ((((i % 2) * 2) - 1) * i) / 2) * (30.0f - damageAmt));
121 part->scale = 0.2f;
122 part->relPos.x = -sin_deg(angle) * starsRadius * 1.5;
123 part->relPos.y = cos_deg(angle) * starsRadius * 1.5;
124 part->relPos.z = 0;
125 part->alpha = 255;
126 }
127 *effectOut = effect;
128}
129
132
135 s32 temp_a2;
136 s32 temp_t0;
137 s32 timeLeft;
138 f32 phi_f12;
139 s32 i;
140
141 if (part->timeLeft < 100) {
142 part->timeLeft--;
143 }
144
145 temp_a2 = part->lifetime++;
146 temp_t0 = part->lifetime;
147 timeLeft = part->timeLeft;
148
149 if (timeLeft < 0) {
150 remove_effect(effect);
151 return;
152 }
153
154 part++;
155 for (i = 1; i < effect->numParts; i++, part++) {
156 f32 x, y, z;
157
158 if (timeLeft > 5) {
159 part->relPos.x = part->relPos.x * 0.75;
160 part->relPos.y = part->relPos.y * 0.75;
161 part->relPos.z = part->relPos.z * 0.75;
162 }
163 if (timeLeft < 5) {
164 part->alpha = part->alpha * 0.6;
165 part->relPos.x = part->relPos.x * 0.7;
166 part->relPos.y = part->relPos.y * 0.7;
167 part->relPos.z = part->relPos.z * 0.7;
168 }
169 phi_f12 = 1.0f;
170 if (temp_a2 < 9) {
171 phi_f12 = D_E003CD1C[temp_a2];
172 }
173 part->curPos.x = part->basePos.x * phi_f12;
174 part->curPos.y = part->basePos.y * phi_f12;
175 part->curPos.z = part->basePos.z * phi_f12;
176 part->basePos.x += part->relPos.x;
177 part->basePos.y += part->relPos.y;
178 part->basePos.z += part->relPos.z;
179
180 if (temp_t0 <= 40) {
181 part->scale = (f32)D_E003CCD0[temp_a2] * 0.01;
182 } else {
183 part->scale = 0.0f;
184 }
185 }
186}
187
190
194
197 Matrix4f mtxTransform;
198 Matrix4f mtxTemp;
199 s32 spA0;
200 s32 lastPartIdx;
201 s32 numParts = part->damageAmt;
202 s32 i;
203
204 gDPPipeSync(gMainGfxPos++);
205 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(effect->graphics->data));
206
207 guTranslateF(mtxTransform, part->basePos.x, part->basePos.y, part->basePos.z);
208 guRotateF(mtxTemp, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
209 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
211
212 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
213
214 spA0 = part->lifetime - 1;
215 lastPartIdx = effect->numParts - 1;
216 part = &(effect->data.damageIndicator)[effect->numParts - 1];
217
218 if (part->alpha == 255) {
219 gDPSetRenderMode(gMainGfxPos++, G_RM_AA_TEX_EDGE, G_RM_AA_TEX_EDGE2);
221 } else {
222 gDPSetRenderMode(gMainGfxPos++, G_RM_CLD_SURF, G_RM_CLD_SURF2);
224 }
225
226 for(i = 1; i < effect->numParts; i++, part--) {
227 s32 rIdx = ((i + spA0) % 12) * 3;
228
229 gDPSetPrimColor(gMainGfxPos++, 0, 0, D_E003CCF8[rIdx], D_E003CCF8[rIdx + 1], D_E003CCF8[rIdx + 2], part->alpha);
230 gSPDisplayList(gMainGfxPos++, D_09001D40_351F60);
231
232 if (i == lastPartIdx) {
233 guPositionF(mtxTransform, 0.0f, 0.0f, 0.0f, part->scale, part->curPos.x, part->curPos.y, part->curPos.z);
235
236 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
237 gSPDisplayList(gMainGfxPos++, D_09002150_352370);
238 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
239
240 guPositionF(mtxTransform, 0.0f, 0.0f, 0.0f, part->scale,
241 (part->curPos.x + part->basePos.x) * 0.5,
242 (part->curPos.y + part->basePos.y) * 0.5,
243 (part->curPos.z + part->basePos.z) * 0.5);
245
246 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
247 gSPDisplayList(gMainGfxPos++, D_09002160_352380);
248 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
249 }
250
251 gSPDisplayList(gMainGfxPos++, D_09001D40_351F60);
252
253 guTranslateF(mtxTransform, part->basePos.x, part->basePos.y, part->basePos.z);
255
256 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
257
258 guScaleF(mtxTransform, part->scale, part->scale, 1.0f);
260
261 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
262
263 if (i == lastPartIdx) {
264 gSPDisplayList(gMainGfxPos++, D_09002170_352390);
265 } else {
266 gSPDisplayList(gMainGfxPos++, D_09002180_3523A0);
267 }
268
269 if (i == lastPartIdx) {
270 gSPDisplayList(gMainGfxPos++, D_090021A8_3523C8);
271 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
272 gSPDisplayList(gMainGfxPos++, D_09001DE0_352000);
273 if (numParts < 10) {
274 gSPDisplayList(gMainGfxPos++, D_E003CCA0[i]);
275 gSPDisplayList(gMainGfxPos++, D_090021C0_3523E0);
276 } else {
277 s32 onesDigit = numParts % 10;
278 s32 tensDigit = numParts / 10;
279 gSPDisplayList(gMainGfxPos++, D_E003CCA0[onesDigit]); // GfxLoadDigitTex
280 gSPDisplayList(gMainGfxPos++, D_09002200_352420); // GfxDrawOnesQuad
281 gSPDisplayList(gMainGfxPos++, D_E003CCA0[tensDigit]);
282 gSPDisplayList(gMainGfxPos++, D_090021E0_352400); // GfxDrawTensQuad
283 }
284 } else {
285 gSPDisplayList(gMainGfxPos++, D_09002190_3523B0);
286 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
287 }
288
289 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
290 }
291
292 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
293}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
void damage_indicator_init(EffectInstance *effect)
Gfx D_09002190_3523B0[]
u8 D_E003CCF8[]
Gfx D_09002010_352230[]
u8 D_E003CCD0[]
Gfx D_09001F90_3521B0[]
Gfx D_09001DE0_352000[]
Gfx D_090021E0_352400[]
Gfx D_09001ED0_3520F0[]
void damage_indicator_render(EffectInstance *effect)
Gfx D_09001FD0_3521F0[]
Gfx D_09001E90_3520B0[]
Gfx D_09002110_352330[]
Gfx D_09001F50_352170[]
Gfx D_090021C0_3523E0[]
Gfx D_09001D40_351F60[]
Gfx D_09002050_352270[]
Gfx * D_E003CCA0[]
void damage_indicator_update(EffectInstance *effect)
Gfx D_090020D0_3522F0[]
Gfx D_09001F10_352130[]
f32 D_E003CD1C[]
void damage_indicator_render_impl(EffectInstance *effect)
Gfx D_09002160_352380[]
Gfx D_09002170_352390[]
Gfx D_09002090_3522B0[]
Gfx D_09002150_352370[]
Gfx D_090021A8_3523C8[]
Gfx D_09002200_352420[]
void damage_indicator_render_ui(EffectInstance *effect)
void damage_indicator_main(s32 arg0, f32 posX, f32 posY, f32 posZ, f32 starsRadius, f32 starsAngle, s32 damageAmt, EffectInstance **effectOut)
Gfx D_09001E50_352070[]
Gfx D_09002180_3523A0[]
#define general_heap_malloc
#define guRotateF
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define guPositionF
#define cos_deg
#define create_effect_instance
#define guScaleF
struct DamageIndicatorFXData * damageIndicator
Definition effects.h:2494
struct EffectGraphics * graphics
Definition effects.h:2606
EffectData data
Definition effects.h:2605
#define ASSERT(condition)
#define PM_CC_DAMAGE_INDICATOR
Definition macros.h:431
#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
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