DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
itembombeffect.cpp
1#include "itembombeffect.hpp"
2
3#include <cmath>
4
5#include "camera.hpp"
6#include "collisiondata.hpp"
7#include "dun/gameloop.hpp"
8#include "itemdata.hpp"
9#include "mglib.hpp"
10#include "rect.hpp"
11#include "shot_freefuncs.hpp"
12#include "snd.hpp"
13#include "texture.hpp"
14#include "userstatus.hpp"
15
23int checkItemUsed(int slot) {
24 int character;
25 float water_now;
26 float water_max;
27 int condition;
28 s16 hp;
29 s16 max_hp;
30
31 character = UserStatus->cur_chara;
32 water_now = UserStatus->water_now[character];
33 water_max = UserStatus->water_max[character];
34 hp = UserStatus->hp[character];
35 max_hp = UserStatus->max_hp[character];
36 condition = UserStatus->ailments[character];
37 int usable = 1;
38 ITEM_PACK *pack = &UserStatus->item_pack;
39 s16 item = pack->quick_item_slot[slot];
40
41 if (item == -1) {
42 return 0;
43 }
44
45 switch (item) {
46 case ITEM_REGULAR_WATER:
47 case ITEM_TASTY_WATER:
48 case ITEM_PREMIUM_WATER:
49 if (!(0.2f + water_now < water_max)) {
50 usable = 0;
51 }
52
53 break;
54 case ITEM_ANTIDOTE_DRINK:
55 if ((condition & AILMENT_POISON) == 0) {
56 usable = 0;
57 }
58
59 break;
60 case ITEM_SOAP:
61 if ((condition & AILMENT_GOO) == 0) {
62 usable = 0;
63 }
64
65 break;
66 case ITEM_MIGHTY_HEALING:
67 if ((condition & (AILMENT_FREEZE | AILMENT_POISON | AILMENT_CURSE | AILMENT_GOO)) == 0) {
68 usable = 0;
69 }
70
71 break;
72 case ITEM_BREAD:
73 case ITEM_PREMIUM_CHICKEN:
74 case ITEM_CHEESE:
75 case ITEM_MELLOW_BANANA:
76 if (hp >= max_hp) {
77 usable = 0;
78 }
79
80 break;
81 }
82
83 return usable;
84}
85
93void usedActiveItem(CUserStatus *status, int item) {
94 int vol_index;
95 int character = status->cur_chara;
96
97 if (item == ITEM_MELLOW_BANANA) {
98 status->AddNowLife(character, 200, 100.0f);
99 status->AddDrink(status->cur_chara, -20, 5.0f);
100 return;
101 }
102
103 item -= ITEM_ATTACH_START;
104
105 if ((ITEM_LIST[item].kind_flags & ITEMKINDF_CONSUMABLE) != 0) {
106 vol_index = 0;
107
108 if ((ITEM_LIST[item].use_flags & ITEMUSE_HEAL_HP) != 0) {
109 s16 life = ITEM_LIST[item].vol;
110 status->AddNowLife(character, life, 100.0f);
111 vol_index++;
112 }
113
114 if ((ITEM_LIST[item].use_flags & ITEMUSE_DRINK) != 0) {
115 s16 drink = (&ITEM_LIST[item].vol)[vol_index];
116 status->AddDrink(status->cur_chara, drink, 5.0f);
117 }
118 }
119
120 if ((ITEM_LIST[item].kind_flags & 1) != 0) {
121 if ((ITEM_LIST[item].use_flags & 0x1000) != 0) {
122 BtSetStatusErr(AILMENT_STAMINA);
123 SndSePlay(SE_POWER_UP, -1, 0);
124 }
125
126 if ((ITEM_LIST[item].use_flags & 0x20000) != 0 && (UserStatus->ailments[character] & AILMENT_GOO) != 0) {
127 UserStatus->ailments[character] = 0;
128 }
129
130 if ((ITEM_LIST[item].use_flags & 0x8000) != 0 && (UserStatus->ailments[character] & AILMENT_POISON) != 0) {
131 UserStatus->ailments[character] = 0;
132 }
133
134 if ((ITEM_LIST[item].use_flags & 0x3C000) != 0 && (UserStatus->ailments[character] != 0 || UserStatus->ailments[character] != AILMENT_STAMINA)) {
135 UserStatus->ailments[character] = 0;
136 }
137 }
138}
139
147int SetBombEffect(float *position, int owner, int damage, float scale) {
148 int collision_slot = -1;
149
150 for (int bomb = 0; bomb < 3; bomb++) {
151 if (NowBombEffect[bomb].CheckBomb() != 0) {
152 continue;
153 }
154
155 NowBombEffect[bomb].SetBomb(position, scale);
156 SndSePlay(SE_EXPLOSION, -1, 0);
157 collision_slot = NowColData->Set(position, damage, (int) (45.0f * scale), 20.0f * scale, 0.0f, owner, 3, 0, 0);
158
159 if (collision_slot != -1) {
160 CCollisionData *collision = NowColData;
161 collision->hit[collision->now_hit].phase = 10;
162 collision->hit[collision->now_hit].ready_phase = 10;
163 }
164
165 if (scale > 1.0f) {
166 CShockWave *wave = NowShockWave;
167 sceVu0CopyVector(wave->position, position);
168 wave->position[3] = 1.0f;
169 wave->base_radius = wave->expand_radius = 30.0f * scale;
170 wave->radius = 0.0f;
171 wave->expand_steps = 15.0f * scale;
172 wave->phase = 0.0f;
173 wave->alpha = 0.0f;
174 wave->active = true;
175 }
176
177 break;
178 }
179
180 return collision_slot;
181}
182
191 static int uvTable[4][2] = {
192 {0, 0},
193 {0, 1},
194 {1, 0},
195 {1, 1}
196 };
197 sceVu0FVECTOR camera_position;
198 sceVu0FVECTOR direction;
199 sceVu0FVECTOR world;
200 int top_left[4];
201 int bottom_right[4];
202 int top_right[4];
203 int bottom_left[4];
204
205 camera->GetPos(camera_position);
206 sceGsAlpha alpha = mgAlpha;
207 alpha.bits.a = 0;
208 alpha.bits.b = 2;
209 alpha.bits.c = 0;
210 alpha.bits.d = 1;
211 MGSetGsALPHA(&alpha);
212 sceGsZbuf zbuffer = mgZBuffer;
213 zbuffer.bits.zmsk = 1;
214 MGSetGsZBUF(&zbuffer);
215
216 for (int i = 0; i < 5; i++) {
217 if (active[i] != 1 || counters[i] < 0) {
218 continue;
219 }
220
221 int cell = i;
222
223 if (cell >= 3) {
224 cell = 3;
225 }
226
227 int u = uvTable[cell][0] << 6;
228 int v = uvTable[cell][1] << 6;
229 direction[0] = camera_position[0] - positions[i][0];
230 float *up = &direction[1];
231 *up = 0.0f;
232 direction[2] = camera_position[2] - positions[i][2];
233 sceVu0Normalize(direction, direction);
234 direction[0] *= i * 5.0f + phases[i] * 2.0f;
235 direction[2] *= i * 5.0f + phases[i] * 2.0f;
236 world[0] = direction[0] + positions[i][0];
237 world[1] = *up + positions[i][1];
238 world[2] = direction[2] + positions[i][2];
239 world[3] = 1.0f;
240
241 float size = sizes[i] * scale;
242
243 if (MGRotTransPers3DSprite(top_left, bottom_right, world, size, size / 2.0f, 0) != 1) {
244 continue;
245 }
246
247 top_right[0] = bottom_right[0];
248 top_right[1] = top_left[1];
249 top_right[2] = top_left[2];
250 top_right[3] = top_left[3];
251 bottom_left[0] = top_left[0];
252 bottom_left[1] = bottom_right[1];
253 bottom_left[2] = bottom_right[2];
254 bottom_left[3] = bottom_right[3];
255 CRect_i_ source(u, v, 0x40, 0x40);
256 set3DSprite(Vif1Packet, TexManager.GetTexture("bomb_ex", -1), source, top_left, top_right, bottom_left, bottom_right, (u8) alphas[i]);
257 }
258
259 MGSetGsALPHA(NULL);
260 MGSetGsZBUF(NULL);
261}
262
271 for (int puff = 0; puff < 5; puff++) {
272 if (active[puff] != 1) {
273 continue;
274 }
275
276 switch (phases[puff]) {
277 case 0:
278 counters[puff]++;
279 sizes[puff] += 2.0f;
280 alphas[puff] += 8.0f;
281
282 if (counters[puff] >= 3) {
283 counters[puff] = 0;
284 phases[puff]++;
285 }
286
287 break;
288 case 1:
289 counters[puff]++;
290 sizes[puff] += 1.0f;
291 alphas[puff] += 8.0f;
292
293 if (counters[puff] >= 4) {
294 counters[puff] = 0;
295 phases[puff]++;
296 }
297
298 break;
299 case 2:
300 counters[puff]++;
301 sizes[puff] += 0.3f;
302 alphas[puff] -= 3.0f;
303
304 if (counters[puff] >= 20) {
305 counters[puff] = 0;
306 phases[puff]++;
307 }
308
309 break;
310 case 3:
311 counters[puff]++;
312 sizes[puff] += 0.1f;
313 alphas[puff] -= 2.0f;
314
315 if (counters[puff] >= 40) {
316 active[puff] = 0;
317 }
318
319 break;
320 }
321 }
322}
323
331void CItemBombEffect::SetBomb(float *position, float scale) {
332 for (int puff = 0; puff < 5; puff++) {
333 sceVu0CopyVector(positions[puff], position);
334 phases[puff] = 0;
335 counters[puff] = -(puff * 3);
336 alphas[puff] = 128.0f;
337 sizes[puff] = 20.0f;
338 active[puff] = 1;
339 }
340
341 this->scale = scale;
342 phases[0] = 2;
343 phases[1] = 1;
344}
345
354 for (int puff = 0; puff < 5; puff++) {
355 if (active[puff] != 0) {
356 return 1;
357 }
358 }
359
360 return 0;
361}
362
371 for (int puff = 0; puff < 5; puff++) {
372 active[puff] = 0;
373 }
374}
375
384 sceVu0FVECTOR corner0;
385 sceVu0FVECTOR corner1;
386 sceVu0FVECTOR corner2;
387 sceVu0FVECTOR corner3;
388 int screen0[4];
389 int screen1[4];
390 int screen2[4];
391 int screen3[4];
392 sceVu0FVECTOR camera_position;
393 sceVu0FVECTOR direction;
394
395 if (active == 0) {
396 return;
397 }
398
399 camera->GetPos(camera_position);
400 direction[0] = camera_position[0] - position[0];
401 float *up = &direction[1];
402 *up = 0.0f;
403 direction[2] = camera_position[2] - position[2];
404 sceVu0Normalize(direction, direction);
405 direction[0] *= 10.0f;
406 direction[2] *= 10.0f;
407
408 sceVu0CopyVector(corner0, position);
409 corner0[0] -= radius;
410 corner0[2] -= radius;
411 sceVu0CopyVector(corner1, position);
412 corner1[0] += radius;
413 corner1[2] -= radius;
414 sceVu0CopyVector(corner2, position);
415 corner2[0] -= radius;
416 corner2[2] += radius;
417 sceVu0CopyVector(corner3, position);
418 corner3[0] += radius;
419 corner3[2] += radius;
420
421 if (MGRotTransPers(screen0, corner0, 0) == 0) {
422 return;
423 }
424
425 if (MGRotTransPers(screen1, corner1, 0) == 0) {
426 return;
427 }
428
429 if (MGRotTransPers(screen2, corner2, 0) == 0) {
430 return;
431 }
432
433 if (MGRotTransPers(screen3, corner3, 0) == 0) {
434 return;
435 }
436
437 sceGsAlpha blend = mgAlpha;
438 blend.bits.a = 0;
439 blend.bits.b = 2;
440 blend.bits.c = 0;
441 blend.bits.d = 1;
442 MGSetGsALPHA(&blend);
443 sceGsZbuf zbuffer = mgZBuffer;
444 zbuffer.bits.zmsk = 1;
445 MGSetGsZBUF(&zbuffer);
446 CRect_i_ source(0x80, 0, 0x40, 0x40);
447 set3DSprite(Vif1Packet, TexManager.GetTexture("bomb_ex", -1), source, screen0, screen1, screen2, screen3, (u8) alpha);
448 MGSetGsALPHA(NULL);
449 MGSetGsZBUF(NULL);
450}
451
460 if (active == 0) {
461 return;
462 }
463
464 const float half_pi = HALF_PI;
465
466 if (phase < half_pi) {
467 phase += half_pi / expand_steps;
468 float envelope = sinf(phase);
469 alpha = 160.0f * envelope;
470 radius = base_radius + expand_radius * envelope;
471 }
472
473 if (phase >= half_pi) {
474 alpha -= 5.0f;
475
476 if (alpha <= 0.0f) {
477 alpha = 0.0f;
478 active = false;
479 }
480 }
481}
void GetPos(float *pos)
Definition camera.cpp:230
int Set(float *position, int damage, int life, float radius, float scale_rate, int target_mask, int kind, int flags, int attribute)
COLLISION_HIT hit[96]
void SetBomb(float *position, float scale)
sceVu0FVECTOR positions[5]
void Draw(CCamera *camera)
void Draw(CCamera *camera)
sceVu0FVECTOR position
s16 max_hp[6]
ITEM_PACK item_pack
s32 ailments[6]
float water_max[6]
void AddDrink(int chara_no, s16 amount, float ratio)
float water_now[6]
void AddNowLife(int chara_no, s16 amount, float ratio)
@ ITEMKINDF_CONSUMABLE
Definition itemdata.hpp:554
@ ITEMUSE_HEAL_HP
Definition itemdata.hpp:543
@ ITEMUSE_DRINK
Definition itemdata.hpp:544
s16 quick_item_slot[3]