DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
shot_freefuncs.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#include "shot_freefuncs.hpp"
4
5#include "itemdata.hpp"
6
7// These tables precede the template of CharaHeight's inline table in .data, so they stand
8// above the header that defines it.
9
13static int maxFloorTbl[7] = {15, 17, 18, 18, 15, 25, 100};
14
18static int defWeapon[6] = {ITEM_WEAPON_DAGGER_BROKEN, ITEM_WEAPON_WOODENSLINGSHOT_BROKEN, ITEM_WEAPON_MALLET_BROKEN, ITEM_WEAPON_GOLD_RING_BROKEN, ITEM_WEAPON_FIGHTING_STICK_BROKEN, ITEM_WEAPON_MACHINE_GUN_BROKEN};
19
20#include <libvu0.h>
21
22#include <cmath>
23#include <cstdio>
24#include <cstdlib>
25#include <cstring>
26
27#include "btactstatus.hpp"
28#include "btmisc.hpp"
29#include "character.hpp"
30#include "charaheight.hpp"
31#include "clothread.hpp"
32#include "clsmes.hpp"
33#include "dataalloc.hpp"
34#include "dataread.hpp"
35#include "dranmapfield.hpp"
36#include "dun/gameloop.hpp"
37#include "dungeoneventman.hpp"
38#include "dungeonmap.hpp"
39#include "frame.hpp"
40#include "healeffect.hpp"
41#include "hitvalue.hpp"
42#include "mainselect.hpp"
43#include "mathutil.hpp"
44#include "menu_inventory.hpp"
45#include "mglib.hpp"
46#include "monstorunit.hpp"
47#include "motionmodel.hpp"
48#include "nowload.hpp"
49#include "rect.hpp"
50#include "snd.hpp"
51#include "texture.hpp"
52#include "userstatus.hpp"
53
54s32 DebugStatus[21];
55float StatusColor[3];
56
60CHECK_WATER_INFO CheckWaterInfo;
61
65WATER_WAVE_LING WaterWaveLing[6];
66
70char BtCfgCash[64];
71
75int WaterWaveLingWait;
76
80int healingSpeed;
81
85int healingSpeed_flg;
86
90int statusAlarmRate;
91
95float statusAlarmCounter;
96
100u8 statusRGBColor_life[4];
101
105u8 statusRGBColor_weapon[4];
106
110u8 statusRGBColor_30[4];
111
115u8 statusRGBColor_15[4];
116
120u8 statusRGBColor_life_2[4];
121
125u8 statusRGBColor_weapon_2[4];
126
130u8 statusRGBColor_30_2[4];
131
135u8 statusRGBColor_15_2[4];
136
144void WaterSplash_Init() {
145 int i;
146
147 Water_Splash_actFlag = 0;
148 CheckWaterInfo.in_water = false;
149
150 for (i = 0; i < 6; i++) {
151 WaterWaveLing[i].life = 0;
152 }
153
154 WaterWaveLingWait = 0;
155}
156
165int CheckHealingWater() {
166 float position[4];
167 float water_position[4];
168 PARTS_WATER *nearest_water;
169 float nearest_distance;
170 float water_x;
171 float water_y;
172 float water_z;
173 int row;
174 int column;
175
176 nearest_distance = 160.0f;
177 sceVu0CopyVector(position, CharaMain.pos);
178
179 for (row = 0; row < 16; row++) {
180 for (column = 0; column < 16; column++) {
181 int parts_no = NowDngMap->cells[row * 20 + column].parts_no;
182
183 if (parts_no != -1) {
184 CDungeonParts *part = &NowDngMap->parts[parts_no];
185 PARTS_WATER *water = &part->water;
186
187 if (part->water.used != 0) {
188 water_position[0] = 160.0f * column;
189 water_position[1] = water->vertex[0][1];
190 water_position[2] = 160.0f * row;
191
192 float distance = DistVector(position, water_position);
193
194 if (distance < nearest_distance) {
195 nearest_water = water;
196 nearest_distance = distance;
197 water_x = water_position[0];
198 water_y = water_position[1];
199 water_z = water_position[2];
200 }
201 }
202 }
203 }
204 }
205
206 if (nearest_distance < 160.0f && position[0] >= water_x + nearest_water->vertex[0][0] && position[0] < water_x + nearest_water->vertex[3][0] && position[2] >= water_z + nearest_water->vertex[0][2] && position[2] < water_z + nearest_water->vertex[3][2] && position[1] < water_y) {
207 position[1] = water_y;
208 sceVu0CopyVector(CheckWaterInfo.surface_position, position);
209 BtActStatus.in_water = true;
210
211 if (Water_Splash_actFlag == 0 && CheckWaterInfo.in_water == 0 && CheckWaterInfo.dry_position[1] - CheckWaterInfo.surface_position[1] > 0.5f) {
212 Water_Splash.SetPosition(CheckWaterInfo.surface_position);
213 Water_Splash.SetMotion(0, 6);
214 SndSePlay(SE_WATER_SPLASH, -1, 0);
215 Water_Splash_actFlag = 1;
216 }
217
218 CheckWaterInfo.in_water = true;
219 return 1;
220 }
221
222 sceVu0CopyVector(CheckWaterInfo.dry_position, position);
223 CheckWaterInfo.in_water = false;
224 return 0;
225}
226
230struct HEAL_ZONE {
231 float pos[4];
232 float width;
233 float depth;
234 s32 on;
235};
236
244int CheckHealZone() {
245 float position[4];
246 float center[4];
247 float low[4];
248 float high[4];
249 int column;
250 int row;
251 int parts_no;
252 int hit;
253 CDungeonParts *part;
254 HEAL_ZONE *zone;
255
256 sceVu0CopyVector(position, CharaMain.pos);
257 BtActStatus.in_water = false;
258
259 column = (80.0f + position[0]) / 160.0f;
260 row = (80.0f + position[2]) / 160.0f;
261 parts_no = NowDngMap->cells[row * 20 + column].parts_no;
262
263 if (parts_no == MAP_PARTS_NONE) {
264 return 0;
265 }
266
267 part = &NowDngMap->parts[parts_no];
268 zone = (HEAL_ZONE *) part->heal_pos;
269 hit = 0;
270
271 if (part->heal_on == 0) {
272 return 0;
273 }
274
275 sceVu0CopyVector(center, zone->pos);
276 center[0] += 160.0f * column;
277 center[2] += 160.0f * row;
278 sceVu0CopyVector(low, center);
279 sceVu0CopyVector(high, center);
280 low[0] -= zone->width / 2.0f;
281 low[2] -= zone->depth / 2.0f;
282 high[0] += zone->width / 2.0f;
283 high[2] += zone->depth / 2.0f;
284
285 if (position[0] >= low[0] && position[0] <= high[0] && position[2] >= low[2] && position[2] < high[2] && position[1] < center[1]) {
286 BtActStatus.in_water = true;
287 return 1;
288 }
289
290 if (zone == NULL) {
291 return 0;
292 }
293
294 return zone->on ? hit : 0;
295}
296
304void HealingWater() {
305 float position[4];
306 int chara;
307 int max_hp;
308 int now_hp;
309
310 if (CheckHealZone() || CheckHealingWater()) {
311 if (healingSpeed <= 0) {
312 chara = UserStatus->cur_chara;
313 UserStatus->AddDrink(chara, 0xFF, 255.0f);
314 UserStatus->AddNowLife(chara, 0xFF, 255.0f);
315 healingSpeed = 10;
316 } else {
317 healingSpeed--;
318 }
319
320 if (HealEffect.active == 0) {
321 max_hp = UserStatus->max_hp[UserStatus->cur_chara];
322 now_hp = UserStatus->hp[UserStatus->cur_chara];
323
324 if (!(now_hp == max_hp)) {
325 sceVu0CopyVector(position, CharaMain.pos);
326 HealEffect.Set(position);
327 SndSePlay(SE_CHARA_RECOVER, -1, 0);
328 healingSpeed_flg = 1;
329 }
330 } else if (healingSpeed_flg) {
331 setUnitAmbientAnime(60.0f, 1.0f, 0.0f, 122.0f, 208.0f);
332 healingSpeed_flg = 0;
333 }
334 }
335}
336
344void DrawWaterLing() {
345 float corner[4][4];
346 int screen[4][4];
347 sceGsAlpha alpha;
348 sceGsZbuf zbuf;
349 CTexture *ripple;
350 int i;
351 int visible;
352 int j;
353 float radius;
354 float x;
355 float y;
356 float near;
357 float left;
358 float z;
359 float right;
360 float far;
361
362 ripple = TexManager.GetTexture("d00e01", -1);
363
364 alpha = mgAlpha;
365 alpha.bits.a = 0;
366 alpha.bits.b = 2;
367 alpha.bits.c = 0;
368 alpha.bits.d = 1;
369 MGSetGsALPHA(&alpha);
370
371 zbuf = mgZBuffer;
372 zbuf.bits.zmsk = 1;
373 MGSetGsZBUF(&zbuf);
374
375 for (i = 0; i < 6; i++) {
376 if (WaterWaveLing[i].life > 0) {
377 radius = WaterWaveLing[i].radius;
378 x = WaterWaveLing[i].center[0];
379 left = x - radius;
380 corner[0][0] = left;
381 y = WaterWaveLing[i].center[1];
382 corner[0][1] = y;
383 z = WaterWaveLing[i].center[2];
384 near = z - radius;
385 corner[0][2] = near;
386 right = radius + x;
387 corner[1][0] = right;
388 corner[1][1] = y;
389 corner[1][2] = near;
390 corner[2][0] = left;
391 corner[2][1] = y;
392 far = radius + z;
393 corner[2][2] = far;
394 corner[3][0] = right;
395 corner[3][1] = y;
396 corner[3][2] = far;
397
398 visible = true;
399
400 for (j = 0; j < 4; j++) {
401 corner[j][3] = 1.0f;
402
403 if (MGRotTransPers(screen[j], corner[j], 0) == 0) {
404 visible = false;
405 }
406 }
407
408 if (visible) {
409 float fade = 2.8444445f * WaterWaveLing[i].life;
410 set3DSprite(Vif1Packet, ripple, CRect_i_(0, 64, 64, 64), screen[0], screen[1], screen[2], screen[3], fade);
411 }
412 }
413 }
414
415 MGSetGsALPHA(NULL);
416 MGSetGsZBUF(NULL);
417}
418
426void StepWaterLing() {
427 int i;
428
429 if (CheckWaterInfo.in_water != 0) {
430 WaterWaveLingWait++;
431
432 if (WaterWaveLingWait >= 20) {
433 WaterWaveLingWait = 0;
434
435 for (i = 0; i < 6; i++) {
436 if (WaterWaveLing[i].life == 0) {
437 sceVu0CopyVector(WaterWaveLing[i].center, CheckWaterInfo.surface_position);
438 WaterWaveLing[i].radius = 2.0f;
439 WaterWaveLing[i].life = 45;
440 break;
441 }
442 }
443 }
444 }
445
446 for (i = 0; i < 6; i++) {
447 if (WaterWaveLing[i].life > 0) {
448 WaterWaveLing[i].radius += 0.2f;
449 WaterWaveLing[i].life--;
450 }
451 }
452}
453
462void BtBattleMusic_Excg(float distance, float *field_volume, float *battle_volume);
463
464static inline int MonstorAliveCheck(int no, int alive) {
465 if (no >= 0 && no < 17) {
466 alive = NowMonstorUnit->monster[no].revealed;
467 }
468
469 return alive;
470}
471
472float SetBattleStyle(int map_no, int preserve_bgm) {
473 float nearest = 10000;
474 sceVu0FVECTOR position;
475 sceVu0FVECTOR player;
476 float bgm_volume;
477 float ambient_volume;
478 int alive;
479
480 sceVu0CopyVector(player, CharaMain.pos);
481
482 for (int i = 0; i < 16; i++) {
483 if (NowMonstorUnit->monster[i].state == -1) {
484 continue;
485 }
486
487 alive = MonstorAliveCheck(i, alive);
488
489 if (alive == 0) {
490 continue;
491 }
492
493 NowMonstorUnit->chara[i][0].GetPosition(position);
494 float distance = DistVector(player, position);
495
496 if (distance < nearest) {
497 nearest = distance;
498 }
499 }
500
501 if (map_no != 5) {
502 CUserStatus *status;
503 int floors = maxFloorTbl[map_no];
504 status = UserStatus;
505
506 if (status->cur_floor < floors - 1) {
507 BtBattleMusic_Excg(nearest, &bgm_volume, &ambient_volume);
508
509 if (ambient_volume > 0.0f) {
510 SndAmbientPlay(0);
511 }
512
513 if (preserve_bgm == 0) {
514 SndSetBgmVolf(bgm_volume);
515 }
516
517 SndAmbientSetVolf(ambient_volume);
518 }
519 }
520
521 return nearest;
522}
523
531int ValuePrint(int x, int y, int value, int palette, unsigned char alpha) {
532 CTexture *texture = TexManager.GetTexture("stayframe", -1);
533 int source_y = palette * 12 + 0xB0;
534 int hundreds_shown = 0;
535 int digit = value / 100;
536
537 if (digit > 0) {
538 set2DSprite(Vif1Packet, texture, CRect_i_(x, y, 12, 12), CRect_i_(digit * 12, source_y, 12, 12), alpha);
539 value -= digit * 100;
540 x += 12;
541 hundreds_shown++;
542 }
543
544 digit = value / 10;
545 set2DSprite(Vif1Packet, texture, CRect_i_(x, y, 12, 12), CRect_i_(digit * 12, source_y, 12, 12), alpha);
546 digit = value % 10;
547 set2DSprite(Vif1Packet, texture, CRect_i_(x + 12, y, 12, 12), CRect_i_(digit * 12, source_y, 12, 12), alpha);
548 return hundreds_shown + 2;
549}
550
558void BtStatusAlarmInit() {
559 statusAlarmRate = 128;
560 statusAlarmCounter = 0.0f;
561
562 statusRGBColor_life[0] = 0x40;
563 statusRGBColor_life[1] = 0xC1;
564 statusRGBColor_life[2] = 0x82;
565 statusRGBColor_life[3] = 0x80;
566
567 statusRGBColor_weapon[0] = 0xFF;
568 statusRGBColor_weapon[1] = 0x80;
569 statusRGBColor_weapon[2] = 0x00;
570 statusRGBColor_weapon[3] = 0x80;
571
572 statusRGBColor_30[0] = 0xFF;
573 statusRGBColor_30[1] = 0x00;
574 statusRGBColor_30[2] = 0xC6;
575 statusRGBColor_30[3] = 0x80;
576
577 statusRGBColor_15[0] = 0xFF;
578 statusRGBColor_15[1] = 0x00;
579 statusRGBColor_15[2] = 0x00;
580 statusRGBColor_15[3] = 0x80;
581
582 statusRGBColor_life_2[0] = 0x00;
583 statusRGBColor_life_2[1] = 0x81;
584 statusRGBColor_life_2[2] = 0xFF;
585 statusRGBColor_life_2[3] = 0x80;
586
587 statusRGBColor_weapon_2[0] = 0xFF;
588 statusRGBColor_weapon_2[1] = 0x20;
589 statusRGBColor_weapon_2[2] = 0x00;
590 statusRGBColor_weapon_2[3] = 0x80;
591
592 statusRGBColor_30_2[0] = 0x3F;
593 statusRGBColor_30_2[1] = 0x00;
594 statusRGBColor_30_2[2] = 0x31;
595 statusRGBColor_30_2[3] = 0x80;
596
597 statusRGBColor_15_2[0] = 0x3F;
598 statusRGBColor_15_2[1] = 0x00;
599 statusRGBColor_15_2[2] = 0x00;
600 statusRGBColor_15_2[3] = 0x80;
601}
602
610void BtStatusAlarmAnime() {
611 statusAlarmCounter += 0.10471976f;
612
613 if (!(statusAlarmCounter < PI)) {
614 statusAlarmCounter -= PI;
615 }
616
617 statusAlarmRate = 192 - (int) (2.0f * (64.0f * sinf(statusAlarmCounter)));
618 statusRGBColor_15[3] = 192 - (int) (2.0f * (64.0f * sinf(statusAlarmCounter)));
619}
620
628u8 *BtGetStatusPal(int bar, float max, float value) {
629 u8 *color;
630
631 if (!(value <= 0.2f * max)) {
632 if (bar == 0) {
633 color = statusRGBColor_life;
634 } else {
635 color = statusRGBColor_weapon;
636 }
637
638 return color;
639 }
640
641 if (value <= 0.3f * max && !(value <= 0.15f * max)) {
642 return statusRGBColor_30;
643 }
644
645 return statusRGBColor_15;
646}
647
655u8 *BtGetStatusPal2(int bar, float max, float value) {
656 u8 *color;
657
658 if (!(value <= 0.2f * max)) {
659 if (bar == 0) {
660 color = statusRGBColor_life_2;
661 } else {
662 color = statusRGBColor_weapon_2;
663 }
664
665 return color;
666 }
667
668 if (value <= 0.3f * max && !(value <= 0.15f * max)) {
669 return statusRGBColor_30_2;
670 }
671
672 return statusRGBColor_15_2;
673}
674
682void topStatusInfo(int y, int selected_item, int floor) {
683 int alpha;
684 CTexture *icons;
685 CTexture *frame;
686 int cells;
687 spRGBA *upper;
688 spRGBA *lower;
689 y -= 10;
690 y += BtActStatus.hud_shake_y;
691 icons = TexManager.GetTexture("itempack", -1);
692 frame = TexManager.GetTexture("stayframe", -1);
693
694 // Life: a frame stretched to the character's maximum, the bar, and "now/max".
695 float life = UserStatus->hp[UserStatus->cur_chara];
696 float life_max = UserStatus->max_hp[UserStatus->cur_chara];
697 int length = (int) (0.74f * life_max);
698
699 if (length < 2) {
700 length = 2;
701 }
702
703 cells = (length >> 2) + 1;
704
705 if (cells < 2) {
706 cells = 2;
707 }
708
709 alpha = 0x80;
710
711 if (life <= 0.2f * life_max) {
712 alpha = statusAlarmRate;
713 }
714
715 upper = (spRGBA *) BtGetStatusPal(0, life_max, life);
716 lower = (spRGBA *) BtGetStatusPal2(0, life_max, life);
717 set2DSprite(Vif1Packet, icons, CRect_i_(0x30, y, 4, 0x10), CRect_i_(0x68, 0x70, 4, 0x10), alpha);
718
719 for (int i = 0; i < cells - 2; i++) {
720 set2DSprite(Vif1Packet, icons, CRect_i_(i * 4 + 0x34, y, 4, 0x10), CRect_i_(0x6C, 0x70, 4, 0x10), alpha);
721 }
722
723 set2DSprite(Vif1Packet, icons, CRect_i_((cells - 1) * 4 + 0x30, y, 4, 0x10), CRect_i_(0x70, 0x70, 4, 0x10), alpha);
724
725 if (life > 0.0f) {
726 length = (int) (0.74f * life);
727 set2DSpriteC4(Vif1Packet, CRect_i_(0x34, y + 5, length - 2, 6), upper, lower, upper, lower);
728 }
729
730 cells = (cells - 1) * 4 + 0x38;
731 cells += ValuePrint(cells, y + 7, (int) life, 0, alpha) * 10;
732 set2DSprite(Vif1Packet, frame, CRect_i_(cells, y + 7, 0xC, 0xC), CRect_i_(0x78, 0xB0, 0xC, 0xC), alpha);
733 ValuePrint(cells + 10, y + 7, (int) life_max, 0, alpha);
734 set2DSprite(Vif1Packet, icons, CRect_i_(0x20, y, 0x10, 0x10), CRect_i_(0x40, 0xA0, 0x10, 0x10), alpha);
735
736 // Weapon durability and progress toward the next weapon level.
737 CUserStatus *user = UserStatus;
738 s8 wielder = user->cur_chara;
739 s8 *slots = user->equipped_weapon_slot;
740 float durability_max = ((CUserStatus *) user)->chara_weapons[user->cur_chara][slots[wielder]].durability;
741 float durability = ((CUserStatus *) user)->chara_weapons[wielder][(s8) slots[wielder]].durability_f;
742 float bar = 1.4949495f * durability_max;
743 length = (int) bar;
744
745 if (length < 2) {
746 length = 2;
747 }
748
749 cells = (length >> 2) + 2;
750
751 if (cells < 2) {
752 cells = 2;
753 }
754
755 alpha = 0x80;
756
757 if (durability <= 0.2f * durability_max) {
758 alpha = statusAlarmRate;
759 }
760
761 upper = (spRGBA *) BtGetStatusPal(1, durability_max, durability);
762 lower = (spRGBA *) BtGetStatusPal2(1, durability_max, durability);
763 set2DSprite(Vif1Packet, icons, CRect_i_(0x30, y + 0x11, 4, 0x10), CRect_i_(0x68, 0x70, 4, 0x10), alpha);
764
765 for (int i = 0; i < cells - 2; i++) {
766 set2DSprite(Vif1Packet, icons, CRect_i_(i * 4 + 0x34, y + 0x11, 4, 0x10), CRect_i_(0x6C, 0x70, 4, 0x10), alpha);
767 }
768
769 set2DSprite(Vif1Packet, icons, CRect_i_((cells - 1) * 4 + 0x30, y + 0x11, 4, 0x10), CRect_i_(0x70, 0x70, 4, 0x10), alpha);
770
771 if (durability > 0.0f) {
772 length = (int) (1.4949495f * durability);
773 set2DSpriteC4(Vif1Packet, CRect_i_(0x34, y + 0x16, length - 2, 6), upper, lower, upper, lower);
774 }
775
776 int width;
777 WEAPON_HAVE *weapon = &UserStatus->chara_weapons[UserStatus->cur_chara][UserStatus->equipped_weapon_slot[UserStatus->cur_chara]];
778 int exp_max = GetWeaponMaxExp(weapon);
779 width = (int) bar;
780 MGFillBox(CRect_i_(0x340, ((y + 0x1F) >> 1) * 16, (width - 1) * 16, 0x10), 0x40, 0x40, 0x40, alpha);
781
782 if (weapon->experience > 0) {
783 int filled = (int) ((float) weapon->experience * ((float) width / (float) exp_max));
784 MGFillBox(CRect_i_(0x340, ((y + 0x1F) >> 1) * 16, (filled - 1) * 16, 0x10), 0, 0xA2, 0xFF, alpha);
785 }
786
787 cells = (cells - 1) * 4 + 0x38;
788 int shown = (int) durability;
789
790 if (durability - (float) shown > 0.0f) {
791 shown++;
792 }
793
794 cells += ValuePrint(cells, y + 0x18, shown, 0, alpha) * 10;
795 set2DSprite(Vif1Packet, frame, CRect_i_(cells, y + 0x18, 0xC, 0xC), CRect_i_(0x78, 0xB0, 0xC, 0xC), alpha);
796 ValuePrint(cells + 10, y + 0x18, (int) durability_max, 0, alpha);
797 set2DSprite(Vif1Packet, icons, CRect_i_(0x20, y + 0x10, 0x10, 0x10), CRect_i_(0x40, 0xB0, 0x10, 0x10), alpha);
798
799 // Water: one drop for every ten, the empty drops behind the full ones.
800 float water_max = UserStatus->water_max[UserStatus->cur_chara];
801 float water = UserStatus->water_now[UserStatus->cur_chara];
802 alpha = 0x80;
803
804 if (water < 0.15f * water_max) {
805 alpha = statusAlarmRate;
806 }
807
808 set2DSprite(Vif1Packet, icons, CRect_i_(0x20, y + 0x22, 0x12, 0x14), CRect_i_(0x64, 0x84, 0x12, 0x14), alpha);
809 int drops = (int) water_max / 10;
810
811 for (cells = 0; cells < drops; cells++) {
812 set2DSprite(Vif1Packet, icons, CRect_i_(cells * 0x12 + 0x32, y + 0x22, 0x12, 0x14), CRect_i_(0x64, 0x98, 0x12, 0x14), alpha);
813 }
814
815 if ((int) water_max % 10 != 0) {
816 set2DSprite(Vif1Packet, icons, CRect_i_(drops * 0x12 + 0x32, y + 0x22, 0x12, 0x14), CRect_i_(0x64, 0xAC, 0x18, 0x14), alpha);
817 }
818
819 int full_drops = (int) water / 10;
820
821 for (cells = 0; cells < full_drops; cells++) {
822 set2DSprite(Vif1Packet, icons, CRect_i_(cells * 0x12 + 0x33, y + 0x22, 0x10, 0x14), CRect_i_(0, 0x48, 0x10, 0x14), 0x50);
823 }
824
825 int leftover = (int) water % 10;
826
827 if (leftover != 0) {
828 set2DSprite(Vif1Packet, icons, CRect_i_(full_drops * 0x12 + 0x33, y + 0x22, 0x10, 0x14), CRect_i_((3 - (int) ((float) leftover / 2.5f)) * 16, 0x48, 0x10, 0x14), 0x50);
829 }
830
831 // Quick-use items; a speed-up item pulses while it is in force.
833 static float popupYRate = -PI;
834 popupYRate += 0.20943952f;
835
836 if (!(popupYRate < PI)) {
837 popupYRate -= TWO_PI;
838 }
839
841 static float popupRGBRate = -PI;
842 popupRGBRate += SIXTEENTH_PI;
843
844 if (!(popupRGBRate < 0.0f)) {
845 popupRGBRate -= PI;
846 }
847
848 ITEM_PACK *pack = &UserStatus->item_pack;
849
850 for (int i = 0; i < 3; i++) {
851 int bob = 0;
852 int glow = 0;
853
854 if (BtBySpeedFlag != 0 && pack->quick_item_slot[i] == ITEM_UNUSED_156) {
855 glow = (int) (64.0f * sinf(popupRGBRate)) + 0x3F;
856 bob = 0;
857 }
858
859 set2DSprite(Vif1Packet, icons, CRect_i_(i * 40 + 0x126, y + 2, 0x24, 0x24), CRect_i_(0x24, 0x5C, 0x24, 0x24), glow + 0x80);
860
861 if (pack->quick_item_slot[i] != -1) {
862 set2DSprite(Vif1Packet, icons, CRect_i_(i * 40 + 0x128, y + 4 + bob, 0x1F, 0x1F), CRect_i_((i << 5) + 0x20, 0, 0x1F, 0x1F));
863
864 if (pack->quick_item_qty[i] > 1) {
865 int tens = pack->quick_item_qty[i] / 10;
866
867 if (tens > 0) {
868 set2DSprite(Vif1Packet, frame, CRect_i_(i * 40 + 0x12F, y + 0x17, 0xC, 0xC), CRect_i_(tens * 12, 0xD4, 0xC, 0xC));
869 }
870
871 set2DSprite(Vif1Packet, frame, CRect_i_(i * 40 + 0x13B, y + 0x17, 0xC, 0xC), CRect_i_(pack->quick_item_qty[i] % 10 * 12, 0xD4, 0xC, 0xC));
872 }
873 }
874 }
875
876 // Floor number, or the mark of the last floor.
877 set2DSprite(Vif1Packet, icons, CRect_i_(0x1FC, y, 0x66, 0x29), CRect_i_(0x9A, 1, 0x66, 0x29));
878
879 if (BtUraDongeon != 0) {
880 set2DSprite(Vif1Packet, icons, CRect_i_(0x23C, y, 0x26, 0x29), CRect_i_(0xDA, 0x2B, 0x26, 0x29));
881 }
882
883 if (BtEquipMasuisyou != 0) {
884 set2DSprite(Vif1Packet, icons, CRect_i_(0x1FE, y + 5, 0x20, 0x20), CRect_i_(0, 0xA0, 0x20, 0x20));
885 }
886
887 if (BtEquipMap != 0) {
888 set2DSprite(Vif1Packet, icons, CRect_i_(0x21E, y + 5, 0x20, 0x20), CRect_i_(0x20, 0xA0, 0x20, 0x20));
889 }
890
891 int last_floor = maxFloorTbl[UserStatus->cur_georama];
892
893 if (floor + 1 == last_floor) {
894 set2DSprite(Vif1Packet, frame, CRect_i_(0x23C, y + 0x12, 0x26, 0x11), CRect_i_(0x78, 0x9E, 0x26, 0x12));
895 } else {
896 int x;
897
898 if (floor + 1 >= 10) {
899 x = 0x245;
900 } else {
901 x = 0x23F;
902 }
903
904 if (floor + 1 >= 10) {
905#ifdef PAL
906 set2DSprite(Vif1Packet, frame, CRect_i_(x - 4, y + 0xA, 0xE, 0x11), CRect_i_((floor + 1) / 10 * 12, 0x9E, 0xC, 0x12));
907#else
908 set2DSprite(Vif1Packet, frame, CRect_i_(x - 4, y + 0x12, 0xE, 0x11), CRect_i_((floor + 1) / 10 * 12, 0x9E, 0xC, 0x12));
909#endif
910 }
911
912#ifdef PAL
913 set2DSprite(Vif1Packet, frame, CRect_i_(x + 9, y + 0xA, 0xE, 0x11), CRect_i_((floor + 1) % 10 * 12, 0x9E, 0xC, 0x12));
914#else
915 set2DSprite(Vif1Packet, frame, CRect_i_(x + 9, y + 0x12, 0xE, 0x11), CRect_i_((floor + 1) % 10 * 12, 0x9E, 0xC, 0x12));
916#endif
917 }
918
919 // Brackets enclose the selected quick-use item.
920 selected_item *= 40;
921 set2DSprite(Vif1Packet, frame, CRect_i_(selected_item + 0xFC, y, 0x10, 0x10), CRect_i_(0x4A, 0x48, 0x10, 0x10));
922 set2DSprite(Vif1Packet, frame, CRect_i_(selected_item + 0x113, y, 0x10, 0x10), CRect_i_(0x5A, 0x48, 0x10, 0x10));
923 set2DSprite(Vif1Packet, frame, CRect_i_(selected_item + 0xFC, y + 0x16, 0x10, 0x10), CRect_i_(0x4A, 0x58, 0x10, 0x10));
924 set2DSprite(Vif1Packet, frame, CRect_i_(selected_item + 0x113, y + 0x16, 0x10, 0x10), CRect_i_(0x5A, 0x58, 0x10, 0x10));
925
926 // The equipped weapon's portrait fades in with the panel.
927 y -= BtActStatus.hud_shake_y;
928 alpha = y + 0x6A;
929#ifdef PAL
930 set2DSprite(Vif1Packet, icons, CRect_i_(0x18, 0x1AC, 0x2A, 0x1D), CRect_i_(0x78, 0x37, 0x2A, 0x1D), alpha);
931 set2DSprite(Vif1Packet, icons, CRect_i_(0x45, 0x1A8, 0x2B, 0x10), CRect_i_(0xA2, 0x37, 0x2B, 0x10), alpha);
932#else
933 set2DSprite(Vif1Packet, icons, CRect_i_(0x18, 0x18C, 0x2A, 0x1D), CRect_i_(0x78, 0x37, 0x2A, 0x1D), alpha);
934 set2DSprite(Vif1Packet, icons, CRect_i_(0x45, 0x188, 0x2B, 0x10), CRect_i_(0xA2, 0x37, 0x2B, 0x10), alpha);
935#endif
936 int chara = UserStatus->cur_chara;
937 int u = 0;
938 int v = 0;
939 int item = UserStatus->chara_weapons[chara][UserStatus->equipped_weapon_slot[chara]].item_no;
940
941 if (item == defWeapon[UserStatus->cur_chara] + 1) {
942 v = 0x20;
943 }
944
945 if (item == defWeapon[UserStatus->cur_chara]) {
946 v = u = 0x20;
947 }
948
949#ifdef PAL
950 set2DSprite(Vif1Packet, icons, CRect_i_(0x1D, 0x1A4, 0x20, 0x20), CRect_i_(u, v, 0x20, 0x20), alpha);
951#else
952 set2DSprite(Vif1Packet, icons, CRect_i_(0x1D, 0x184, 0x20, 0x20), CRect_i_(u, v, 0x20, 0x20), alpha);
953#endif
954}
955
963int StatusErrCheck(int status) {
964 return (UserStatus->ailments[UserStatus->cur_chara] & status) ? 1 : 0;
965}
966
974int BtStatusErrColorSet() {
975 int status;
976 int ailing;
977
978 ailing = 0;
979 status = UserStatus->ailments[UserStatus->cur_chara];
980
981 if (status & AILMENT_FREEZE) {
982 StatusColor[0] = 127.5f;
983 StatusColor[1] = 127.5f;
984 StatusColor[2] = 127.5f;
985 ailing = 1;
986 }
987
988 if (status & AILMENT_GOO) {
989 StatusColor[0] = 50.0f;
990 StatusColor[1] = 75.0f;
991 StatusColor[2] = 127.5f;
992 ailing = 1;
993 }
994
995 if (status & AILMENT_POISON) {
996 StatusColor[0] = 47.0f;
997 StatusColor[1] = 0.5f;
998 StatusColor[2] = 63.75f;
999 ailing = 1;
1000 }
1001
1002 if (status & AILMENT_STAMINA) {
1003 StatusColor[0] = 127.5f;
1004 StatusColor[1] = 80.0f;
1005 StatusColor[2] = 15.0f;
1006 ailing = 1;
1007 }
1008
1009 return ailing;
1010}
1011
1015int poison_counter;
1016
1024void BtStatusErrStep() {
1025 int flags;
1026 CUserStatus *status = UserStatus;
1027 s8 *cur_chara = &status->cur_chara;
1028
1029 flags = status->ailments[*cur_chara];
1030 poison_counter++;
1031
1032 // Poison takes 4% of the character's max HP every 180 steps and shows the loss over them.
1033 if ((flags & AILMENT_POISON) && poison_counter >= 180) {
1034 int chara = *cur_chara;
1035 int max_hp = status->max_hp[chara];
1036 int damage = 0.04 * max_hp;
1037#ifdef PAL
1038 status->AddNowLife((s8) *cur_chara, -damage, 10.0f);
1039#else
1040 status->AddNowLife((s8) chara, -damage, 10.0f);
1041#endif
1042
1043 float position[4] = {0.0f, 0.0f, 0.0f, 1.0f};
1044 position[1] = CharaHeight(UserStatus);
1045 HitValueEntry(NowHitValue, position, damage, HIT_VALUE_PLAYER, CharaMain.frame);
1046 }
1047
1048 if (poison_counter >= 180) {
1049 poison_counter = 0;
1050 }
1051
1052 BtStatusErrColorSet();
1053#ifdef PAL
1054#pragma name_counter 551
1055#endif
1056}
1057
1065void BtSetStatusErr(int status) {
1066 int chara;
1067
1068 chara = UserStatus->cur_chara;
1069
1070 switch (status) {
1071 case AILMENT_FREEZE:
1072 UserStatus->ailments[chara] |= status;
1073 UserStatus->ailments[chara] &= ~(AILMENT_STAMINA | AILMENT_POISON | AILMENT_GOO);
1074 UserStatus->ailment_frames[chara] = 300;
1075 SndSePlay(SE_STATUS_AILMENT, -1, 0);
1076 break;
1077
1078 case AILMENT_STAMINA:
1079 if (!(UserStatus->ailments[chara] & AILMENT_FREEZE)) {
1080 UserStatus->ailments[chara] |= status;
1081 UserStatus->ailment_frames[chara] = 1800;
1082 }
1083
1084 break;
1085
1086 case AILMENT_POISON:
1087 if (!(UserStatus->ailments[chara] & (AILMENT_FREEZE | AILMENT_STAMINA))) {
1088 UserStatus->ailments[chara] |= status;
1089 UserStatus->ailments[chara] &= ~AILMENT_GOO;
1090 SndSePlay(SE_STATUS_AILMENT, -1, 0);
1091 }
1092
1093 break;
1094
1095 case AILMENT_CURSE:
1096 UserStatus->ailments[chara] |= status;
1097 SndSePlay(SE_STATUS_AILMENT, -1, 0);
1098 break;
1099
1100 case AILMENT_GOO:
1101 if (!(UserStatus->ailments[chara] & (AILMENT_FREEZE | AILMENT_STAMINA | AILMENT_POISON))) {
1102 UserStatus->ailments[chara] |= status;
1103 SndSePlay(SE_STATUS_AILMENT, -1, 0);
1104 }
1105
1106 break;
1107 }
1108}
1109
1117void BtStatusErrDraw(int y) {
1118 CTexture *texture = TexManager.GetTexture("itempack", -1);
1119 int status_flags[5] = {AILMENT_FREEZE, AILMENT_STAMINA, AILMENT_POISON, AILMENT_CURSE, AILMENT_GOO};
1120 int icon_cells[5][2] = {
1121 {1, 0},
1122 {0, 1},
1123 {1, 1},
1124 {1, 2},
1125 {0, 2}
1126 };
1127 int status = UserStatus->ailments[UserStatus->cur_chara];
1128
1129 for (int icon = 4; icon >= 0; icon--) {
1130 if (status & status_flags[icon]) {
1131 set2DSprite(Vif1Packet, texture, CRect_i_(430, y - 10, 62, 35), CRect_i_(icon_cells[icon][0] * 62 + 132, icon_cells[icon][1] * 36 + 84, 62, 36));
1132 }
1133 }
1134}
1135
1143void setItemToReserved(char *page_name, int x, int y, char *item_name, int dsax, int dsay) {
1144 CTexture *page;
1145 CTexture *item;
1146 int sbp;
1147 int sbw;
1148 int dbp;
1149 int dbw;
1150
1151 sceVif1PkCnt(Vif1Packet, 0);
1152 sceVif1PkOpenDirectCode(Vif1Packet, 0);
1153 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
1154 sceVif1PkAddGsAD(Vif1Packet, 0x3F, 0);
1155 sceVif1PkCloseGifTag(Vif1Packet);
1156 sceVif1PkCloseDirectCode(Vif1Packet);
1157
1158 page = TexManager.GetTexture(page_name, -1);
1159 item = TexManager.GetTexture(item_name, -1);
1160
1161 sbp = page->tex0 & 0x3FFF;
1162 dbp = item->tex0 & 0x3FFF;
1163 sbw = (page->tex0 >> 14) & 0x3F;
1164 dbw = (item->tex0 >> 14) & 0x3F;
1165
1166 MoveImageTest(Vif1Packet, sbp, sbw, 0x13, CRect_i_(x, y, 0x20, 0x20), dbp, dbw, 0x13, dsax, dsay, 0);
1167
1168 sceVif1PkCnt(Vif1Packet, 0);
1169 sceVif1PkOpenDirectCode(Vif1Packet, 0);
1170 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
1171 sceVif1PkAddGsAD(Vif1Packet, 0x3F, 0);
1172 sceVif1PkCloseGifTag(Vif1Packet);
1173 sceVif1PkCloseDirectCode(Vif1Packet);
1174}
1175
1179int BtCfgFlag;
1180
1184int BtSteebMsgNo;
1185
1193void BtMapJumpCashClear() {
1194 BtCfgCash[0] = '\0';
1195 BtCfgFlag = 0;
1196 BtSteebMsgNo = -1;
1197}
1198
1202static inline int ArenaLimit(CDataAlloc2<1> &arena) {
1203 return arena.limit;
1204}
1205
1215int BtMapJumpLoad(char *map_name) {
1216 char mpd_path[64];
1217 char cfg_path[64];
1218 char mes_path[64];
1219 int mes_size;
1220 int size;
1221
1222 CUserStatus *status = UserStatus;
1223 int msg_no = status->cur_georama;
1224 int floor = status->cur_floor;
1225
1226 // From dungeon 6 on, the message file also changes every twenty floors.
1227 if (msg_no >= 6) {
1228 if (floor >= 20) {
1229 msg_no++;
1230 }
1231
1232 if (floor >= 40) {
1233 msg_no++;
1234 }
1235
1236 if (floor >= 60) {
1237 msg_no++;
1238 }
1239
1240 if (floor >= 80) {
1241 msg_no++;
1242 }
1243 }
1244
1245 if (msg_no != BtSteebMsgNo) {
1246 BtSteebMesBuffer.used = 0;
1247 u_char *mes = BtSteebMesBuffer.base + BtSteebMesBuffer.used * 16;
1248
1249 if (status->cur_georama == 6) {
1250 sprintf(mes_path, "dun/message/ww_mes/steve07_%d_%d.mes", msg_no - 5, LanguageCode);
1251 } else {
1252 sprintf(mes_path, "dun/message/ww_mes/steve0%d_%d.mes", msg_no + 1, LanguageCode);
1253 }
1254
1255 LoadFile(mes_path, mes, &mes_size);
1256 wait_now_loading_vsync();
1257 DngMesStb.SetBuff((short *) mes);
1258 BtSteebMesBuffer.Alloc((((mes_size >> 6) + 1) << 6) >> 4);
1259 BtSteebMesBuffer.Align64();
1260 BtSteebMsgNo = msg_no;
1261 }
1262
1263 TexManager.DeleteTextureBlock(42);
1264 MainMonstorUnit.CleanViewMonstor(0);
1265 NowDngMap = &MainDungeonMap;
1266 NowEventMan = &DngEventMan;
1267
1268 if (strcmp(BtCfgCash, map_name) == 0 && BtCfgFlag != 0) {
1269 return 0;
1270 }
1271
1272 strcpy(BtCfgCash, map_name);
1273
1274 MapModelBuffer.used = 0;
1275 u_int *pack = read_buffer;
1276 read_buffer = old_read_buffer;
1277
1278 int i;
1279 DRAN_MAP_FIELD_SET *field_set = (DRAN_MAP_FIELD_SET *) NowDranMapField;
1280
1281 for (i = 0; i < 12; i++) {
1282 field_set->field[i].Initialize();
1283 field_set->collision[i] = NULL;
1284 field_set->state[i] = 3;
1285 }
1286
1287 field_set->field_count = 0;
1288 field_set->collision_count = 0;
1289
1290 MainDungeonMap.initSubmap(&MapModelBuffer);
1291
1292 for (int slot = 0; slot < 64; slot++) {
1293 CDungeonEvent *event = &DngEventMan.slot[slot];
1294 event->name[0] = '\0';
1295 event->script_no = -1;
1296 event->parts_id = -1;
1297 event->switch_on = false;
1298 event->enabled = false;
1299 }
1300
1301 for (int record = 0; record < 96; record++) {
1302 CDungeonEventData *data = &DngEventMan.event[record];
1303 data->event = NULL;
1304 data->switch_on = false;
1305 data->enabled = false;
1306 data->hold = 0;
1307 data->chara_done = -1;
1308 }
1309
1310 strcpy(mpd_path, "dun/mpd_pack/");
1311 strcat(mpd_path, map_name);
1312 strcat(mpd_path, ".mpd");
1313 strcpy(cfg_path, "dun/");
1314 strcat(cfg_path, map_name);
1315 strcat(cfg_path, ".cfg");
1316 TEIGIAnalyz(cfg_path);
1317
1318 size = 0;
1319 LoadFile(mpd_path, (void *) read_buffer, &size);
1320 wait_now_loading_vsync();
1321
1322 if (size >= 6400000) {
1323 printf("MAPDATA BUFFER OVER!! %d\n", size);
1324 exit__2(1);
1325 }
1326
1327 TEIGIImgLoad(read_buffer, &MapModelBuffer);
1328 TEIGIMdsLoad(read_buffer, 0);
1329
1330 CFrameAttr attr;
1331 attr.fog_enable = true;
1332 attr.clip_depth = 100.0f;
1333 attr.clip_enable = false;
1334 attr.program_option = 0;
1335 NowDngMap->box_body_model = LoadMDSFilePack(read_buffer, "ibox_0.mds", &MapModelBuffer);
1336 NowDngMap->box_lid_model = LoadMDSFilePack(read_buffer, "ibox_t.mds", &MapModelBuffer);
1337 NowDngMap->box_collision_model = LoadCollisionFilePack(read_buffer, "ibox_a.mds", &MapModelBuffer);
1338 NowDngMap->box_body_model->SetAttr(attr, 1, 0);
1339 NowDngMap->box_lid_model->SetAttr(attr, 1, 0);
1340 NowDngMap->chest_body_model = LoadMDSFilePack(read_buffer, "iboxs_0.mds", &MapModelBuffer);
1341 NowDngMap->chest_lid_model = LoadMDSFilePack(read_buffer, "iboxs_t.mds", &MapModelBuffer);
1342 NowDngMap->chest_collision_model = LoadCollisionFilePack(read_buffer, "iboxs_a.mds", &MapModelBuffer);
1343 NowDngMap->chest_body_model->SetAttr(attr, 1, 0);
1344 NowDngMap->chest_lid_model->SetAttr(attr, 1, 0);
1345
1346 itemOpenSmall.LoadPack(read_buffer, "dun/etc/itemget_s/d01i02m", &MapModelBuffer, &MapModelBuffer, &itemOpenSmall_info, 0);
1347 itemOpenBig.LoadPack(read_buffer, "dun/etc/itemget_b/d01i01m", &MapModelBuffer, &MapModelBuffer, &itemOpenBig_info, 0);
1348
1349 // The monsters get whatever the map left of its buffer.
1350 int map_used = MapModelBuffer.used;
1351 u_char *monster_base = MapModelBuffer.base + map_used * 16;
1352 long monster_size = 0xA7F80 - map_used;
1353 MonstorModelBuffer.base = monster_base;
1354 MonstorModelBuffer.limit = monster_size;
1355 MonstorModelBuffer.used = 0;
1356 read_buffer = pack;
1357
1358 printf("TotalMem = %d\n", 0xA7F80);
1359 printf("MapVisualData [%x] %d/%d\n", MapModelBuffer.base + MapModelBuffer.used * 16, MapModelBuffer.used, ArenaLimit(MapModelBuffer));
1360 printf("MonstorData [%x] %d/%d\n", MonstorModelBuffer.base + MonstorModelBuffer.used * 16, MonstorModelBuffer.used, ArenaLimit(MonstorModelBuffer));
1361 BtCfgFlag = 1;
1362 return 1;
1363}
1364
1372void BtSet3DCellModel(float *world, CTexture *texture, float size, int x, int y, int width, int height, int alpha) {
1373 int top_left[4];
1374 int top_right[4];
1375 int bottom_left[4];
1376 int bottom_right[4];
1377 CRect_i_ source;
1378
1379 world[3] = 1.0f;
1380
1381 if (MGRotTransPers3DSprite(top_left, bottom_right, world, size, size / 2.0f, 0) == 1) {
1382 top_right[0] = bottom_right[0];
1383 top_right[1] = top_left[1];
1384 top_right[2] = top_left[2];
1385 bottom_left[0] = top_left[0];
1386 bottom_left[1] = bottom_right[1];
1387 bottom_left[2] = bottom_right[2];
1388
1389 source.x = x;
1390 source.y = y;
1391 source.width = width;
1392 source.height = height;
1393
1394 set3DSprite(Vif1Packet, texture, source, top_left, top_right, bottom_left, bottom_right, alpha);
1395 }
1396}
void SetMotion(int no, int mode, float speed=-1.0f)
CFrame * frame
virtual void SetPosition(float x, float y, float z)
CDungeonEvent * event
CDungeonEvent slot[64]
CDungeonEventData event[96]
void initSubmap(CDataAlloc2< 1 > *alloc)
MAP_CELL cells[400]
CFrame * box_collision_model
CFrame * chest_collision_model
CFrame * box_body_model
CFrame * box_lid_model
CDungeonParts parts[72]
CFrame * chest_body_model
CFrame * chest_lid_model
PARTS_WATER water
char clip_enable
Definition frame.hpp:29
float clip_depth
Definition frame.hpp:28
char program_option
Definition frame.hpp:32
char fog_enable
Definition frame.hpp:33
void Set(float *world)
CMonstorChara chara[16]
void CleanViewMonstor(int back_floor)
MONSTOR monster[16]
void LoadPack(unsigned int *pack, char *base_name, CDataAlloc2< 1 > *model_arena, CDataAlloc2< 1 > *motion_arena, MOTION_INFO *motion_info, int initialize_frames)
float pos[4]
Definition object.hpp:18
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
u_long tex0
Definition texture.hpp:57
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)
WEAPON_HAVE chara_weapons[6][11]
s16 ailment_frames[6]
s8 equipped_weapon_slot[6]
void SetBuff(short *buff)
Definition clsmes.cpp:456
@ MAP_PARTS_NONE
CDranMapField field[12]
CFrame * collision[12]
s16 quick_item_slot[3]
s16 quick_item_qty[3]
float vertex[4][4]