DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
weaponelement.cpp
1#pragma argument_flag 0
2#pragma argument_flag_ones 71, 99, 109, 124, 144, 182, 223, 240, 274, 305
3#pragma literal_reload 0x3C23D70A
4
5#include "weaponelement.hpp"
6
7#include <libvu0.h>
8
9#include <cstdlib>
10
11#include "mglib.hpp"
12#include "rect.hpp"
13#include "snd.hpp"
14#include "texture.hpp"
15
17 int i;
18
19 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
20 size[i] = 1.0f;
21 alpha[i] = 1.0f;
22 }
23
24 on = 0;
25}
26
27void CWeaponElement::Set(sceVu0FVECTOR *origin, float *position, float power, int kind, float spread) {
28 this->power = 0.01f * (1.0f + power);
29 this->kind = kind;
30 this->spread = spread;
31 this->origin = origin;
32
33 switch (kind) {
34 default:
36 Init_Cold(position);
37 break;
39 Init_Wind(position);
40 break;
42 Init_Fire(position);
43 break;
45 Init_Thunder(position);
46 break;
48 Init_Holy(position);
49 break;
50 }
51
52 on = 1;
53}
54
56 if (on != 0) {
57 switch (kind) {
58 default:
60 Step_Cold();
61 break;
63 Step_Wind();
64 break;
66 Step_Fire();
67 break;
70 break;
72 Step_Holy();
73 break;
74 }
75 }
76}
77
79 if (on != 0) {
80 switch (kind) {
81 default:
83 Draw_Cold();
84 break;
86 Draw_Wind();
87 break;
89 Draw_Fire();
90 break;
93 break;
95 Draw_Holy();
96 break;
97 }
98 }
99}
100
101void CWeaponElement::Init_Holy(float *position) {
102 count = (int) (12.0f * power) + 2;
103 spawn_budget = (int) (20.0f * power) + 10;
104 spawn_delay_max = 6 - (int) (3.0f * power);
105 spawn_delay = 0;
106 frame_timer = 4;
107 spread = spread * (float) (0.8 + 0.4f * power);
108 scale = 0.5f + 0.7f * power;
109
110 for (int i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
111 shrink[i] = 0.0f;
112 alpha[i] = 0.0f;
113 }
114
115 for (int i = 0; i < count; i++) {
116 size[i] = 2.0f + 6.0f * rand() / 2147483648.0f;
117 shrink[i] = 1.0f;
118 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
119 fading[i] = 0;
120 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
121 offset[i][1] = spread * rand() / 2147483648.0f - spread / 2.0f;
122 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
123 offset[i][3] = 1.0f;
124 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
125 }
126}
127
129 int dead;
130 int i;
131
132 dead = 0;
133
134 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
135 if (alpha[i] <= 0.0f) {
136 dead++;
137 } else {
138 offset[i][1] += 0.5f;
139 shrink[i] -= 0.01f;
140
141 if (shrink[i] <= 0.0f) {
142 shrink[i] = 0.0f;
143 alpha[i] = 0.0f;
144 }
145
146 if (frame_timer == 4) {
147 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
148 }
149
150 if (fading[i] != 0) {
151 alpha[i] -= 8.0f;
152
153 if (alpha[i] <= 0.0f) {
154 alpha[i] = 0.0f;
155 }
156 } else {
157 alpha[i] += 16.0f;
158
159 if (!(alpha[i] < 128.0f)) {
160 fading[i] = 1;
161 }
162 }
163 }
164 }
165
167
168 if (frame_timer == 0) {
169 frame_timer = 4;
170 }
171
172 // While the budget lasts, a free slot is filled again every so often.
173 if (spawn_budget > 0) {
176
177 if (spawn_delay <= 0) {
178 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
179 if (alpha[i] == 0.0f) {
180 size[i] = 2.0f + 6.0f * rand() / 2147483648.0f;
181 shrink[i] = 1.0f;
182 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
183 fading[i] = 0;
184 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
185 offset[i][1] = spread * rand() / 2147483648.0f - spread / 2.0f;
186 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
187 offset[i][3] = 1.0f;
188 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
189 spawn_delay = (int) ((float) spawn_delay_max * rand() / 2147483648.0f) + 1;
190 break;
191 }
192 }
193 }
194 }
195
196 if (dead >= WEAPON_ELEMENT_SPARK_MAX) {
197 on = 0;
198 }
199}
200
202 // The four screen corners of one sprite: top left, top right, bottom
203 // left, bottom right.
204 int corner[4][4];
205 sceVu0FVECTOR base;
206 sceVu0FVECTOR pos;
207 CRect_i_ rect;
208 CTexture *texture;
209 int i;
210 float width;
211 int row;
212
213 texture = TexManager.GetTexture("element", -1);
214 sceVu0CopyVector(base, *origin);
215 pos[3] = 1.0f;
216
217 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
218 row = frame[i];
219
220 if (alpha[i] <= 0.0f) {
221 continue;
222 }
223
224 width = scale * (size[i] * shrink[i]);
225 pos[0] = base[0] + offset[i][0];
226 pos[1] = base[1] + offset[i][1];
227 pos[2] = base[2] + offset[i][2];
228
229 if (MGRotTransPers3DSprite(corner[0], corner[3], pos, width, width / 2.0f, 0) != 1) {
230 continue;
231 }
232
233 // The two corners that the sprite call gives back are opposite, so the
234 // other two take one part from each.
235 corner[1][0] = corner[3][0];
236 corner[1][1] = corner[0][1];
237 corner[1][2] = corner[0][2];
238 corner[2][0] = corner[0][0];
239 corner[2][1] = corner[3][1];
240 corner[2][2] = corner[3][2];
241
242 rect.x = 0xD0;
243 rect.y = row;
244 rect.width = 0x30;
245 rect.height = 0x30;
246 set3DSprite(Vif1Packet, texture, rect, corner[0], corner[1], corner[2], corner[3], (u8) alpha[i]);
247 }
248}
249
250void CWeaponElement::Init_Cold(float *position) {
251 count = (int) (12.0f * power) + 2;
252 spawn_budget = (int) (20.0f * power) + 10;
253 spawn_delay_max = 6 - (int) (3.0f * power);
254 spawn_delay = 0;
255 frame_timer = 4;
256 spread = spread * (float) (0.8 + 0.4f * power);
257 scale = 0.5f + 0.7f * power;
258
259 for (int i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
260 shrink[i] = 0.0f;
261 alpha[i] = 0.0f;
262 }
263
264 for (int i = 0; i < count; i++) {
265 size[i] = 3.0f + 6.0f * rand() / 2147483648.0f;
266 shrink[i] = 1.0f;
267 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
268 fading[i] = 0;
269 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
270 offset[i][1] = spread / 2.0f + spread * rand() / 2147483648.0f;
271 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
272 offset[i][3] = 1.0f;
273 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
274 }
275}
276
278 int dead;
279 int i;
280
281 dead = 0;
282
283 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
284 if (alpha[i] <= 0.0f) {
285 dead++;
286 } else {
287 offset[i][1] -= 0.1f + 0.3f * rand() / 2147483648.0f;
288 shrink[i] -= 0.01f;
289
290 if (shrink[i] <= 0.0f) {
291 shrink[i] = 0.0f;
292 alpha[i] = 0.0f;
293 }
294
295 if (frame_timer == 4) {
296 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
297 }
298
299 if (fading[i] != 0) {
300 alpha[i] -= 6.0f;
301
302 if (alpha[i] <= 0.0f) {
303 alpha[i] = 0.0f;
304 }
305 } else {
306 alpha[i] += 12.0f;
307
308 if (!(alpha[i] < 128.0f)) {
309 fading[i] = 1;
310 }
311 }
312 }
313 }
314
316
317 if (frame_timer == 0) {
318 frame_timer = 4;
319 }
320
321 if (spawn_budget > 0) {
324
325 if (spawn_delay <= 0) {
326 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
327 if (alpha[i] == 0.0f) {
328 size[i] = 3.0f + 6.0f * rand() / 2147483648.0f;
329 shrink[i] = 1.0f;
330 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
331 fading[i] = 0;
332 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
333 offset[i][1] = spread / 2.0f + spread * rand() / 2147483648.0f;
334 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
335 offset[i][3] = 1.0f;
336 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
337 spawn_delay = (int) ((float) spawn_delay_max * rand() / 2147483648.0f) + 1;
338 break;
339 }
340 }
341 }
342 }
343
344 if (dead >= WEAPON_ELEMENT_SPARK_MAX) {
345 on = 0;
346 }
347}
348
350 // The four screen corners of one sprite: top left, top right, bottom
351 // left, bottom right.
352 int corner[4][4];
353 sceVu0FVECTOR base;
354 sceVu0FVECTOR pos;
355 CRect_i_ rect;
356 CTexture *texture;
357 int i;
358 float width;
359 int row;
360
361 texture = TexManager.GetTexture("element", -1);
362 sceVu0CopyVector(base, *origin);
363 pos[3] = 1.0f;
364
365 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
366 row = frame[i];
367
368 if (alpha[i] <= 0.0f) {
369 continue;
370 }
371
372 width = scale * (size[i] * shrink[i]);
373 pos[0] = base[0] + offset[i][0];
374 pos[1] = base[1] + offset[i][1];
375 pos[2] = base[2] + offset[i][2];
376
377 if (MGRotTransPers3DSprite(corner[0], corner[3], pos, width, width / 2.0f, 0) != 1) {
378 continue;
379 }
380
381 // The two corners that the sprite call gives back are opposite, so the
382 // other two take one part from each.
383 corner[1][0] = corner[3][0];
384 corner[1][1] = corner[0][1];
385 corner[1][2] = corner[0][2];
386 corner[2][0] = corner[0][0];
387 corner[2][1] = corner[3][1];
388 corner[2][2] = corner[3][2];
389
390 rect.x = 0xA0;
391 rect.y = row;
392 rect.width = 0x30;
393 rect.height = 0x30;
394 set3DSprite(Vif1Packet, texture, rect, corner[0], corner[1], corner[2], corner[3], (u8) alpha[i]);
395 }
396}
397
398void CWeaponElement::Init_Wind(float *position) {
399 count = (int) (10.0f * power) + 1;
400 spawn_budget = (int) (20.0f * power) + 10;
401 spawn_delay_max = 8 - (int) (4.0f * power);
402 spawn_delay = 0;
403 frame_timer = 4;
404 spread = spread * (float) (0.8 + 0.4f * power);
405 scale = 0.5f + 1.3f * (0.7f * power);
406
407 for (int i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
408 shrink[i] = 0.0f;
409 alpha[i] = 0.0f;
410 }
411
412 for (int i = 0; i < count; i++) {
413 size[i] = 2.0f + 4.0f * rand() / 2147483648.0f;
414 shrink[i] = 1.0f;
415 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
416 fading[i] = 0;
417 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
418 offset[i][1] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
419 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
420 offset[i][3] = 1.0f;
421
422 // Each spark blows along the line it starts on, at its own speed.
423 sceVu0CopyVector(velocity[i], offset[i]);
424 sceVu0Normalize(velocity[i], velocity[i]);
425 sceVu0ScaleVector(velocity[i], velocity[i], 0.3f * rand() / 2147483648.0f);
426 spin[i] = 2.0f * (PI_SHORT * rand()) / 2147483648.0f - PI_SHORT;
427 spin_speed[i] = 0.09817475f + SIXTEENTH_PI_SHORT * rand() / 2147483648.0f;
428 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
429 }
430}
431
433 int dead;
434 int i;
435
436 dead = 0;
437
438 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
439 if (alpha[i] <= 0.0f) {
440 dead++;
441 } else {
442 if (fading[i] != 0) {
443 alpha[i] -= 4.0f;
444
445 if (alpha[i] <= 0.0f) {
446 alpha[i] = 0.0f;
447 }
448 } else {
449 alpha[i] += 32.0f;
450
451 if (!(alpha[i] < 128.0f)) {
452 fading[i] = 1;
453 }
454 }
455
456 if (frame_timer == 4) {
457 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
458 }
459
460 spin[i] += spin_speed[i];
461
462 if (!(spin[i] <= PI_SHORT)) {
463 spin[i] -= TWO_PI_SHORT;
464 }
465
466 offset[i][0] += velocity[i][0];
467 offset[i][1] += 0.2f;
468 offset[i][2] += velocity[i][2];
469 }
470 }
471
473
474 if (frame_timer == 0) {
475 frame_timer = 4;
476 }
477
478 if (spawn_budget > 0) {
481
482 if (spawn_delay <= 0) {
483 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
484 if (alpha[i] == 0.0f) {
485 size[i] = 2.0f + 4.0f * rand() / 2147483648.0f;
486 shrink[i] = 1.0f;
487 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
488 fading[i] = 0;
489 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
490 offset[i][1] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
491 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
492 offset[i][3] = 1.0f;
493 sceVu0CopyVector(velocity[i], offset[i]);
494 sceVu0Normalize(velocity[i], velocity[i]);
495 sceVu0ScaleVector(velocity[i], velocity[i], 0.3f * rand() / 2147483648.0f);
496 spin[i] = 2.0f * (PI_SHORT * rand()) / 2147483648.0f - PI_SHORT;
497 spin_speed[i] = 0.09817475f + SIXTEENTH_PI_SHORT * rand() / 2147483648.0f;
498 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
499 spawn_delay = (int) ((float) spawn_delay_max * rand() / 2147483648.0f) + 1;
500 break;
501 }
502 }
503 }
504 }
505
506 if (dead >= WEAPON_ELEMENT_SPARK_MAX) {
507 on = 0;
508 }
509}
510
512 // The four screen corners of one sprite: top left, top right, bottom
513 // left, bottom right.
514 int corner[4][4];
515 sceVu0FVECTOR base;
516 sceVu0FVECTOR pos;
517 sceVu0FMATRIX unit;
518 sceVu0FMATRIX turn;
519 CRect_i_ rect;
520 CTexture *texture;
521 int i;
522 float width;
523 int row;
524
525 texture = TexManager.GetTexture("element", -1);
526 sceVu0CopyVector(base, *origin);
527 pos[3] = 1.0f;
528
529 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
530 row = frame[i];
531
532 if (alpha[i] <= 0.0f) {
533 continue;
534 }
535
536 width = scale * (size[i] * shrink[i]);
537
538 // A wind spark is turned about the vertical by the spin it carries.
539 sceVu0UnitMatrix(unit);
540 sceVu0RotMatrixY(turn, unit, spin[i]);
541 sceVu0ApplyMatrix(pos, turn, offset[i]);
542 pos[0] += base[0];
543 pos[1] += base[1];
544 pos[2] += base[2];
545
546 if (MGRotTransPers3DSprite(corner[0], corner[3], pos, width, width / 2.0f, 0) != 1) {
547 continue;
548 }
549
550 // The two corners that the sprite call gives back are opposite, so the
551 // other two take one part from each.
552 corner[1][0] = corner[3][0];
553 corner[1][1] = corner[0][1];
554 corner[1][2] = corner[0][2];
555 corner[2][0] = corner[0][0];
556 corner[2][1] = corner[3][1];
557 corner[2][2] = corner[3][2];
558
559 rect.x = 0x60;
560 rect.y = row;
561 rect.width = 0x40;
562 rect.height = 0x30;
563 set3DSprite(Vif1Packet, texture, rect, corner[0], corner[1], corner[2], corner[3], (u8) alpha[i]);
564 }
565}
566
567void CWeaponElement::Init_Fire(float *position) {
568 count = (int) (12.0f * power) + 2;
569 spawn_budget = (int) (20.0f * power) + 10;
570 spawn_delay_max = 6 - (int) (3.0f * power);
571 spawn_delay = 0;
572 frame_timer = 4;
573 spread = spread * (float) (0.8 + 0.4f * power);
574 scale = 0.5f + 0.7f * power;
575
576 // Fire stays where it was lit rather than following the weapon.
577 sceVu0CopyVector(fire_pos, position);
578
579 for (int i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
580 shrink[i] = 0.0f;
581 alpha[i] = 0.0f;
582 }
583
584 for (int i = 0; i < count; i++) {
585 size[i] = 2.0f + 6.0f * rand() / 2147483648.0f;
586 shrink[i] = 1.0f;
587 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
588 fading[i] = 0;
589 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
590 offset[i][1] = spread * rand() / 2147483648.0f - spread / 2.0f;
591 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
592 offset[i][3] = 1.0f;
593 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
594 }
595}
596
598 int dead;
599 int i;
600
601 dead = 0;
602
603 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
604 if (alpha[i] <= 0.0f) {
605 dead++;
606 } else {
607 offset[i][1] += 0.01f + 0.6f * rand() / 2147483648.0f;
608 shrink[i] -= 0.01f;
609
610 if (shrink[i] <= 0.0f) {
611 shrink[i] = 0.0f;
612 alpha[i] = 0.0f;
613 }
614
615 if (frame_timer == 4) {
616 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
617 }
618
619 if (fading[i] != 0) {
620 alpha[i] -= 8.0f;
621
622 if (alpha[i] <= 0.0f) {
623 alpha[i] = 0.0f;
624 }
625 } else {
626 alpha[i] += 16.0f;
627
628 if (!(alpha[i] < 128.0f)) {
629 fading[i] = 1;
630 }
631 }
632 }
633 }
634
636
637 if (frame_timer == 0) {
638 frame_timer = 4;
639 }
640
641 if (spawn_budget > 0) {
644
645 if (spawn_delay <= 0) {
646 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
647 if (alpha[i] == 0.0f) {
648 size[i] = 2.0f + 6.0f * rand() / 2147483648.0f;
649 shrink[i] = 1.0f;
650 alpha[i] = 1.0f + 48.0f * rand() / 2147483648.0f;
651 fading[i] = 0;
652 offset[i][0] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
653 offset[i][1] = spread * rand() / 2147483648.0f - spread / 2.0f;
654 offset[i][2] = 2.0f * (spread * rand()) / 2147483648.0f - spread;
655 offset[i][3] = 1.0f;
656 frame[i] = (int) (5.0f * rand() / 2147483648.0f) * 0x30;
657 spawn_delay = (int) ((float) spawn_delay_max * rand() / 2147483648.0f) + 1;
658 break;
659 }
660 }
661 }
662 }
663
664 if (dead >= WEAPON_ELEMENT_SPARK_MAX) {
665 on = 0;
666 }
667}
668
670 // The four screen corners of one sprite: top left, top right, bottom
671 // left, bottom right.
672 int corner[4][4];
673 sceVu0FVECTOR base;
674 sceVu0FVECTOR pos;
675 CRect_i_ rect;
676 CTexture *texture;
677 int i;
678 float width;
679 int row;
680
681 texture = TexManager.GetTexture("element", -1);
682 sceVu0CopyVector(base, fire_pos);
683 pos[3] = 1.0f;
684
685 for (i = 0; i < WEAPON_ELEMENT_SPARK_MAX; i++) {
686 row = frame[i];
687
688 if (alpha[i] <= 0.0f) {
689 continue;
690 }
691
692 width = scale * (size[i] * shrink[i]);
693 pos[0] = base[0] + offset[i][0];
694 pos[1] = base[1] + offset[i][1];
695 pos[2] = base[2] + offset[i][2];
696
697 if (MGRotTransPers3DSprite(corner[0], corner[3], pos, width, width / 2.0f, 0) != 1) {
698 continue;
699 }
700
701 // The two corners that the sprite call gives back are opposite, so the
702 // other two take one part from each.
703 corner[1][0] = corner[3][0];
704 corner[1][1] = corner[0][1];
705 corner[1][2] = corner[0][2];
706 corner[2][0] = corner[0][0];
707 corner[2][1] = corner[3][1];
708 corner[2][2] = corner[3][2];
709
710 rect.x = 0x30;
711 rect.y = row;
712 rect.width = 0x30;
713 rect.height = 0x30;
714 set3DSprite(Vif1Packet, texture, rect, corner[0], corner[1], corner[2], corner[3], (u8) alpha[i]);
715 }
716}
717
718void CWeaponElement::Init_Thunder(float *position) {
719 sceVu0FVECTOR reach;
720 sceVu0FVECTOR dir;
721
722 count = (int) (18.0f * power) + 6;
723 bolt_count = (int) (7.0f * power) + 1;
724 spread = spread * (float) (0.8 + 0.4f * power);
725
726 for (int i = 0; i < count; i++) {
727 velocity[i][0] = 8.0f * rand() / 2147483648.0f - 4.0f;
728 velocity[i][1] = 4.0f * rand() / 2147483648.0f - 2.0f;
729 velocity[i][2] = 8.0f * rand() / 2147483648.0f - 4.0f;
730
731 // Each spark is thrown somewhere along the line it will travel.
732 sceVu0Normalize(dir, velocity[i]);
733 sceVu0ScaleVectorXYZ(reach, dir, spread);
734 offset[i][0] = position[0] + velocity[i][0] + reach[0] * rand() / 2147483648.0f;
735 offset[i][1] = position[1] + velocity[i][1] + reach[1] * rand() / 2147483648.0f;
736 offset[i][2] = position[2] + velocity[i][2] + reach[2] * rand() / 2147483648.0f;
737 offset[i][3] = 1.0f;
738 sceVu0ScaleVectorXYZ(velocity[i], dir, 0.3f * rand() / 2147483648.0f);
739 size[i] = 0.5f + 2.5f * rand() / 2147483648.0f;
740 shrink[i] = 1.0f;
741 alpha[i] = 96.0f + (int) (64.0f * rand() / 2147483648.0f);
742 }
743
744 for (int i = 0; i < bolt_count; i++) {
745 bolt_head[i] = (int) ((float) count * rand() / 2147483648.0f);
746 bolt_tail[i] = (int) ((float) count * rand() / 2147483648.0f);
747 bolt_timer[i] = (int) (6.0f * rand() / 2147483648.0f) * 3 + 3;
748 bolt_frame[i] = (int) (4.0f * rand() / 2147483648.0f);
749 }
750}
751
753 int dead;
754
755 dead = 0;
756
757 for (int i = 0; i < count; i++) {
758 if (alpha[i] <= 0.0f) {
759 dead++;
760 } else {
761 offset[i][0] += velocity[i][0];
762 offset[i][1] += velocity[i][1];
763 offset[i][2] += velocity[i][2];
764 shrink[i] -= 0.01f;
765 alpha[i] -= 4.0f;
766
767 if (alpha[i] <= 3.0f) {
768 alpha[i] = 0.0f;
769 }
770 }
771 }
772
773 if (dead >= count) {
774 on = 0;
775 return;
776 }
777
778 for (int i = 0; i < bolt_count; i++) {
779 bolt_timer[i] = bolt_timer[i] - 1;
780
781 if (bolt_timer[i] <= 0) {
782 bolt_head[i] = (int) ((float) count * rand() / 2147483648.0f);
783 bolt_tail[i] = (int) ((float) count * rand() / 2147483648.0f);
784 bolt_timer[i] = (int) (6.0f * rand() / 2147483648.0f) * 3 + 3;
785 bolt_frame[i] = (int) (4.0f * rand() / 2147483648.0f);
786 } else if (bolt_timer[i] % 3 == 0) {
787 bolt_frame[i] = bolt_frame[i] + 1;
788
789 if (bolt_frame[i] >= 4) {
790 bolt_frame[i] = 0;
791 }
792 }
793 }
794}
795
797 // The four screen corners of one sprite: top left, top right, bottom
798 // left, bottom right. A bolt uses the same four as the ends of its arc.
799 int corner[4][4];
800 sceVu0FVECTOR base;
801 CTexture *texture;
802 int i;
803 float width;
804
805 texture = TexManager.GetTexture("element", -1);
806 sceVu0CopyVector(base, *origin);
807
808 for (i = 0; i < count; i++) {
809 if (alpha[i] <= 0.0f) {
810 continue;
811 }
812
813 width = size[i] * shrink[i];
814
815 if (MGRotTransPers3DSprite(corner[0], corner[3], offset[i], width, width / 2.0f, 0) != 1) {
816 continue;
817 }
818
819 // The two corners that the sprite call gives back are opposite, so the
820 // other two take one part from each.
821 corner[1][0] = corner[3][0];
822 corner[1][1] = corner[0][1];
823 corner[1][2] = corner[0][2];
824 corner[2][0] = corner[0][0];
825 corner[2][1] = corner[3][1];
826 corner[2][2] = corner[3][2];
827
828 set3DSprite(Vif1Packet, texture, CRect_i_(0, 0, 0x30, 0x30), corner[0], corner[1], corner[2], corner[3], (u8) alpha[i]);
829 }
830
831 int bolt_uv[4][2] = {
832 {0x00, 0x30},
833 {0x18, 0x30},
834 {0x00, 0x98},
835 {0x00, 0x98}
836 };
837 sceVu0FVECTOR pos;
838
839 for (i = 0; i < bolt_count; i++) {
840 // A bolt is one tall sprite stood between the two sparks it arcs
841 // across, so each end gives a point above and a point below it.
842 sceVu0CopyVector(pos, offset[bolt_head[i]]);
843 pos[1] += 1.0f;
844 MGRotTransPers(corner[0], pos, 0);
845 pos[1] -= 2.0f;
846 MGRotTransPers(corner[1], pos, 0);
847 sceVu0CopyVector(pos, offset[bolt_tail[i]]);
848 pos[1] += 1.0f;
849 MGRotTransPers(corner[2], pos, 0);
850 pos[1] -= 2.0f;
851 MGRotTransPers(corner[3], pos, 0);
852
853 int shape = bolt_frame[i];
854 int u = bolt_uv[shape][0];
855 int v = bolt_uv[shape][1];
856
857 set3DSprite(Vif1Packet, texture, CRect_i_(u, v, 0x18, 0x68), corner[0], corner[1], corner[2], corner[3], (u8) (1.6f * alpha[bolt_head[i]]));
858 }
859}
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
void Init_Fire(float *position)
float alpha[WEAPON_ELEMENT_SPARK_MAX]
s16 bolt_frame[WEAPON_ELEMENT_BOLT_MAX]
void Init_Cold(float *position)
sceVu0FVECTOR offset[WEAPON_ELEMENT_SPARK_MAX]
sceVu0FVECTOR velocity[WEAPON_ELEMENT_SPARK_MAX]
float shrink[WEAPON_ELEMENT_SPARK_MAX]
s16 bolt_head[WEAPON_ELEMENT_BOLT_MAX]
s16 fading[WEAPON_ELEMENT_SPARK_MAX]
float spin[WEAPON_ELEMENT_SPARK_MAX]
void Init_Thunder(float *position)
sceVu0FVECTOR fire_pos
s16 bolt_timer[WEAPON_ELEMENT_BOLT_MAX]
void Set(sceVu0FVECTOR *origin, float *position, float power, int kind, float spread)
void Init_Wind(float *position)
s16 bolt_tail[WEAPON_ELEMENT_BOLT_MAX]
float spin_speed[WEAPON_ELEMENT_SPARK_MAX]
float size[WEAPON_ELEMENT_SPARK_MAX]
sceVu0FVECTOR * origin
s16 frame[WEAPON_ELEMENT_SPARK_MAX]
void Init_Holy(float *position)
#define WEAPON_ELEMENT_SPARK_MAX
@ WEAPON_ELEMENT_THUNDER
@ WEAPON_ELEMENT_HOLY
@ WEAPON_ELEMENT_WIND
@ WEAPON_ELEMENT_COLD
@ WEAPON_ELEMENT_FIRE