DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
menu_dungeon.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 639
4
5#include "menu_dungeon.hpp"
6
7#include <cmath>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11
12#include "battlemenu.hpp"
13#include "btactstatus.hpp"
14#include "btmisc.hpp"
15#include "camera.hpp"
16#include "clsmes.hpp"
17#include "dataalloc.hpp"
18#include "dataread.hpp"
19#include "debugfont.hpp"
20#include "dun/gameloop.hpp"
21#include "editatra.hpp"
22#include "gamepad.hpp"
23#include "itemdata.hpp"
24#include "mainitemmodel.hpp"
25#include "mainselect.hpp"
26#include "mds.hpp"
27#include "memcard.hpp"
28#include "memorycardaccess.hpp"
29#include "menu_inventory.hpp"
30#include "menu_misc.hpp"
31#include "menuetc.hpp"
32#include "menuitemstep.hpp"
33#include "mglib.hpp"
34#include "rect.hpp"
35#include "savedata.hpp"
36#include "shot_freefuncs.hpp"
37#include "snd.hpp"
38#include "texture.hpp"
39#include "userstatus.hpp"
40
44// clang-format off
45enum CharaChangeStep {
46 CHARA_CHANGE_SELECT = 0,
47 CHARA_CHANGE_TURNING = 1,
48 CHARA_CHANGE_ITEM_PROMPT = 2,
49 CHARA_CHANGE_BLOCKED = 3,
50 CHARA_CHANGE_UNK_4 = 4,
51 CHARA_CHANGE_LOADING = 5,
52 CHARA_CHANGE_LOADED = 6,
53 CHARA_CHANGE_UNK_7 = 7,
54};
55
56// clang-format on
57
58DUN_ENTER_MENU DEnterMenu;
59
67 s8 step;
68 float turn_frame;
69 float ring_pos[6][2];
70 s16 ring_slot[6];
73 u8 unk_4a[2];
74 s32 unk_4c;
75 u8 unk_50[2];
77 u8 unk_53;
78 float cursor_x;
79 float cursor_y;
80 s16 mode;
81 u8 unk_5e[2];
82};
83
84STATIC_ASSERT(sizeof(CHARA_CHANGE_MENU) == 0x60);
85
87static CHARA_CHANGE_MENU ChangeMenu;
88
89int MenuEtcErrCnt;
90
92CTexture *DunLogBoard;
93
95CTexture *DunLogBoard2;
96
97CDngStatusData *DEnterStatusPt;
98
100static int maxFloorTbl__4[7] = {15, 17, 18, 18, 15, 25, 100};
101
109static int DunEnterMenuKey();
110
118static void DunEnterDraw();
119
127static void DunEnterBoard(int x, int y, int alpha);
128
136static void DrawGetAtoraNumBoard(int floor, int x, int y, int top, int bottom, int alpha);
137
145static void DrawDunNumberClip(int x, int y, int top, int bottom, int digit, int alpha);
146
154static void DrawDunEnterBack(int alpha);
155
163static void DrawDunEnterFloorName(int x, int y, int floor, int top, int bottom, int alpha);
164
172static void DrawItemDataView(int item_no);
173
181static void PlusAttachmentVolume(ATTACH_LIST *base, ATTACH_LIST *add, float scale) {
182 int i;
183
184 for (i = 0; i < 4; i++) {
185 base->status[i] += add->status[i] * scale;
186 }
187
188 for (i = 0; i < 5; i++) {
189 base->elem[i] += add->elem[i] * scale;
190 }
191
192 for (i = 0; i < 10; i++) {
193 base->vs_monster[i] += add->vs_monster[i] * scale;
194 }
195}
196
197int GetWeaponAttachStatusUp(WEAPON_HAVE *weapon, int stat) {
198 int total;
199 int i;
200
201 if (GetWeaponData(weapon->item_no) == NULL || weapon->item_no < ITEM_WEAPON_START) {
202 return 0;
203 }
204
205 total = 0;
206
207 for (i = 0; i < 6; i++) {
208 if (weapon->attach[i].item_no - ITEM_ATTACH_START < 0) {
209 continue;
210 }
211
212 int multiplier = 1;
213
214 if (weapon->attach_kind[i] == 3) {
215 multiplier = 2;
216 }
217
218 ATTACH_LIST *attach = &weapon->attach[i];
219
220 if (stat < 5) {
221 total += attach->status[stat - 1] * multiplier;
222 } else if (stat >= 8 && stat < 0xD) {
223 total += attach->elem[stat - 8] * multiplier;
224 } else {
225 total += attach->vs_monster[stat - 14] * multiplier;
226 }
227 }
228
229 return total;
230}
231
232void SetWeaponAttachStatus(WEAPON_HAVE *result) {
233 if (result == NULL) {
234 return;
235 }
236
237 CDngStatusData *dng_status = SaveData->GetDngStatus();
238
239 if (dng_status == NULL) {
240 printf("cdng is NULL!!!!\n");
241 return;
242 }
243
244 int chara = dng_status->cur_chara;
245 int slot = dng_status->equipped_weapon_slot[chara];
246 WEAPON_HAVE *weapons = dng_status->chara_weapons[chara];
247 WEAPON_HAVE *equipped = &weapons[slot];
248
249 if (equipped == NULL) {
250 printf("actwep is NULL\n", chara);
251 return;
252 }
253
254 WeaponAllValueSet(equipped, result, 0);
255}
256
257void WeaponAllValueSet(WEAPON_HAVE *weapon, WEAPON_HAVE *result, int full) {
258 int i;
259 WEAPON_DATA *data;
260 int flags;
261 ATTACH_LIST *attaches;
262 ATTACH_LIST total;
263 float rate;
264 float scale;
265 int value;
266
267 data = GetWeaponData(weapon->item_no);
268
269 if (data == NULL) {
270 return;
271 }
272
273 attaches = weapon->attach;
274 memset(&total, 0, sizeof(ATTACH_LIST));
275 rate = GetNowWeaponRate(weapon);
276
277 if (full) {
278 rate = 1.0f;
279 }
280
281 flags = 0;
282 flags |= weapon->flags;
283 memcpy(result, weapon, sizeof(WEAPON_HAVE));
284
285 for (i = 0; i < GetWeaponHoleNum(weapon->item_no); i++) {
286 if (data->hole[i] <= 0) {
287 break;
288 }
289
290 scale = 1.0f;
291
292 if (weapon->attach_kind[i] == 3) {
293 scale = 2.0f;
294 }
295
296 PlusAttachmentVolume(&total, &attaches[i], scale);
297
298 if (attaches[i].item_no == ITEM_ATTACH_SYNTHESIS_SPHERE && attaches[i].sphere_flags != 0 && attaches[i].sphere_flags != 1) {
299 flags |= attaches[i].sphere_flags;
300 }
301 }
302
303 result->flags = CheckWeaponOptionStatus(flags);
304 int limit[4] = {data->attack_max, 99, 99, data->magic_max};
305 limit[0] *= rate;
306 limit[3] *= rate;
307 value = result->attack + total.status[0];
308 value *= rate;
309
310 if (limit[0] < value) {
311 result->attack = limit[0];
312 } else {
313 result->attack = value;
314 }
315
316 value = result->endurance + total.status[1];
317 value *= rate;
318
319 if (limit[1] < value) {
320 result->endurance = limit[1];
321 } else {
322 result->endurance = value;
323 }
324
325 value = result->speed + total.status[2];
326 value *= rate;
327
328 if (value >= limit[2]) {
329 result->speed = limit[2];
330 } else {
331 result->speed = value;
332 }
333
334 value = result->magic + total.status[3];
335 value *= rate;
336
337 if (limit[3] < value) {
338 result->magic = limit[3];
339 } else {
340 result->magic = value;
341 }
342
343 for (i = 0; i < 5; i++) {
344 value = result->elem[i] + total.elem[i];
345 value *= rate;
346
347 if (value >= 99) {
348 result->elem[i] = 99;
349 } else {
350 result->elem[i] = value;
351 }
352 }
353
354 for (i = 0; i < 10; i++) {
355 value = result->vs_monster[i] + total.vs_monster[i];
356 value *= rate;
357
358 if (value >= 99) {
359 result->vs_monster[i] = 99;
360 } else {
361 result->vs_monster[i] = value;
362 }
363 }
364}
365
366int SetAttachMentValue(int item_no, int slot, short level, ATTACH_LIST *unused) {
367 CDngStatusData *status;
368 ATTACH_LIST *attach;
369 ATTACH_DATA *data;
370 s16 held_no;
371
372 if (item_no < ITEM_ATTACH_START || item_no >= ITEM_DUNGEON_START) {
373 return -1;
374 }
375
376 status = SaveData->GetDngStatus();
377 DNG_CONSUMABLE *items = status->consumable_items;
378 attach = (ATTACH_LIST *) &items[slot];
379 data = GetAttachData(item_no);
380 held_no = attach->item_no;
381
382 if (held_no < ITEM_ATTACH_START || held_no >= ITEM_DUNGEON_START) {
383 return -1;
384 }
385
386 memset(attach, 0, sizeof(ATTACH_LIST));
387 attach->item_no = held_no;
388 memcpy(attach, data, sizeof(ATTACH_LIST));
389
390 if (level <= 0) {
391 level = 1;
392 }
393
394 if (level > 3) {
395 level = 3;
396 }
397
398 if (held_no >= ITEM_ATTACH_ATTACK && held_no <= ITEM_ATTACH_MAGICAL_POWER) {
399 attach->status[held_no - ITEM_ATTACH_ATTACK] += level;
400 }
401
402 return 0;
403}
404
405int GetAttachVolumeForMsg(ATTACH_LIST *attach) {
406 int volume;
407
408 if (attach == NULL) {
409 return 0;
410 }
411
412 volume = 0;
413
414 if (attach->item_no >= ITEM_ATTACH_STAT_START && attach->item_no < ITEM_ATTACH_GEM_START) {
415 volume = attach->status[attach->item_no - ITEM_ATTACH_STAT_START];
416 }
417
418 if (attach->item_no == ITEM_ATTACH_SYNTHESIS_SPHERE) {
419 volume = attach->sphere_level;
420 }
421
422 return volume;
423}
424
425int InitDunEnterMenu(int texture_block, int dungeon, int requested_floor) {
426#ifdef PAL
427 char path[108];
428#else
429 char path[76];
430#endif
431 int size;
432 u_long128 *buffer;
433 int first_open;
434 int floor;
435 s8 lines;
436
437 SaveData->QuestDungeon(dungeon, 1);
438 DEnterStatusPt = (CDngStatusData *) UserStatus;
439 StartReadBG();
440 buffer = (u_long128 *) read_buffer;
441 buffer = MenuCalcBufAlignment(buffer);
442 DEnterMenu.dungeon = dungeon;
443 GetPathReadDifferntLang(path);
444 strcat(path, "dunenter/dunenter%d.pak");
445 sprintf(path, path, DEnterMenu.dungeon);
446 LoadFileBG(path, buffer, &size);
447 ReadBG();
448 MenuEtcErrCnt = 0;
449 DEnterMenu.texture_block = texture_block;
450 DEnterMenu.textures_ready = 0;
451 DEnterMenu.loading = true;
452 DEnterMenu.counter = 0;
453 DEnterMenu.state = DUN_ENTER_FADE_IN;
454 DEnterMenu.requested_floor = requested_floor;
455
456 if (requested_floor >= 0) {
457 DEnterMenu.state = DUN_ENTER_DIRECT;
458 return 1;
459 }
460
461 first_open = -1;
462 floor = DEnterStatusPt->floor_reached[dungeon];
463
464 if (dungeon == 5) {
465 if (floor >= maxFloorTbl__4[dungeon]) {
466 floor = maxFloorTbl__4[dungeon] - 1;
467 }
468
469 printf("maxfloor = %d\n", floor);
470 }
471
472 if (floor >= 0) {
473 DEnterMenu.floor_count = floor + 1;
474 } else {
475 DEnterMenu.floor_count = 1;
476 }
477
478 for (floor = 0; floor < maxFloorTbl__4[dungeon]; floor++) {
479 DEnterMenu.max_atra[floor] = DEnterStatusPt->GetMaxAtraNum(dungeon, floor);
480 DEnterMenu.collected_atra[floor] = DEnterStatusPt->GetAtraNum(dungeon, floor);
481 DEnterMenu.kills[floor] = DEnterStatusPt->ChkKills(dungeon, floor);
482
483 if (DEnterMenu.kills[floor] > 999) {
484 DEnterMenu.kills[floor] = 999;
485 }
486
487 if (first_open == -1 && (u8) DEnterMenu.max_atra[floor] != (u8) DEnterMenu.collected_atra[floor]) {
488 first_open = floor;
489 }
490 }
491
492 DEnterMenu.selected_floor = DEnterMenu.floor_count - 1;
493 DEnterMenu.scroll_top = DEnterMenu.selected_floor;
494
495 if (first_open > -1) {
496 DEnterMenu.selected_floor = first_open;
497 DEnterMenu.scroll_top = DEnterMenu.selected_floor;
498 }
499
500 if (DEnterMenu.scroll_top > DEnterMenu.floor_count - 5) {
501 DEnterMenu.scroll_top = DEnterMenu.floor_count - 5;
502
503 if (DEnterMenu.scroll_top < 0) {
504 DEnterMenu.scroll_top = 0;
505 }
506 }
507
508 printf("DEnterMenu.select = %d\n", DEnterMenu.selected_floor);
509 printf("DEnterMenu.topline = %d\n", DEnterMenu.scroll_top);
510 DEnterMenu.list_y = 118.0f - 40.0f * DEnterMenu.scroll_top;
511 lines = DEnterMenu.floor_count;
512
513 if (lines < 5) {
514 lines = 5;
515 }
516
517 DEnterMenu.scroll_bar_y = 122.0f + 108.0f * DEnterMenu.scroll_top / lines;
518 GamePad.SetAutoRepeat(PAD_L2 | PAD_R2 | PAD_L1 | PAD_R1 | PAD_DPAD, 30, 5);
519 GamePad.MenuModeOn(0x78);
520 return 1;
521}
522
530static void ExitDunEnterMenu() {
531 GamePad.AutoRepeatOff();
532 GamePad.MenuModeOff();
533 MenuTextureReload(DEnterMenu.texture_block);
534 DngActiveItemTextureCopy();
535 DngActiveWeaponTextureCopy();
536 TexManager.DeleteTextureBlock(DEnterMenu.texture_block);
537}
538
539int DunEnterMenuLoop() {
540 rand();
541 ReadBG();
542 int result = DunEnterMenuKey();
543 DunEnterDraw();
544 ItemVolumeStep.LoopStep(60);
545
546 if (0 <= result) {
547 ExitDunEnterMenu();
548 ItemVolumeStep.CheckItemVolume();
549 result = DEnterMenu.result;
550 }
551
552 return result;
553}
554
555static int DunEnterMenuKey() {
556 int result;
557 int selected;
558 int scroll_top;
559 int count;
560 BG_READ_INFO *archive;
561
562 result = -1;
563
564 switch (DEnterMenu.state) {
565 case DUN_ENTER_FADE_IN:
566 case DUN_ENTER_DIRECT:
567 if (DEnterMenu.textures_ready == 0 && ReadBGSync() == 0) {
568 LOADTEXTURE_INFO2 textures[] = {
569 {(char *) "#frame_menu_enter#640#" SCREEN_HEIGHT_STR "#4", DEnterMenu.texture_block, 0},
570 {NULL, DEnterMenu.texture_block, 0},
571 {NULL, 0, 0},
572 };
573 archive = GetReadBGFile(0);
574 textures[1].name = (char *) GetPackFile((u_int *) archive->buffer, (char *) "dunenter.img", NULL);
575 TexManager.DeleteTextureBlock(DEnterMenu.texture_block);
576 TexManager.CleanUpTextureList();
577 TexManager.LoadTextureBlockEX(-1, textures);
578 DunLogBoard = TexManager.GetTexture("dunenter", DEnterMenu.texture_block);
579 DunLogBoard2 = TexManager.GetTexture("kaisou", DEnterMenu.texture_block);
580 InitMenuMesSet(MENU_MES_SET_DUNGEON_ENTER, (short *) GetPackFile((u_int *) archive->buffer, (char *) "dunlog.bin", NULL));
581 CommonMenuMes2.mes_made = -1;
582 CommonMenuMes2.MakeMesWin(10);
583 DEnterMenu.textures_ready = 1;
584 DEnterMenu.loading = false;
585 printf("tex enter end \n");
586 } else {
587 MenuEtcErrCnt++;
588 }
589
590 if (DEnterMenu.textures_ready != 0) {
591 DEnterMenu.counter++;
592 }
593
594 if (DEnterMenu.textures_ready != 0 && DEnterMenu.counter > 30) {
595 DEnterMenu.state = DUN_ENTER_SELECT;
596 DEnterMenu.counter = 0;
597
598 if (DEnterMenu.requested_floor >= 0) {
599 DEnterMenu.state = DUN_ENTER_FADE_OUT;
600 DEnterMenu.result = DEnterMenu.requested_floor;
601 result = 1;
602 }
603 }
604
605 break;
606 case DUN_ENTER_FADE_OUT:
607 DEnterMenu.counter++;
608
609 if (DEnterMenu.counter > 46) {
610 result = 1;
611 }
612
613 break;
614 case DUN_ENTER_SELECT:
615 selected = DEnterMenu.selected_floor;
616 scroll_top = DEnterMenu.scroll_top;
617
618 if (GamePad.Down(PAD_UP)) {
619 DEnterMenu.selected_floor--;
620
621 if (DEnterMenu.selected_floor < DEnterMenu.scroll_top) {
622 DEnterMenu.scroll_top--;
623 }
624 } else if (GamePad.Down(PAD_DOWN)) {
625 DEnterMenu.selected_floor++;
626
627 if (DEnterMenu.scroll_top + 4 < DEnterMenu.selected_floor) {
628 DEnterMenu.scroll_top++;
629 }
630 } else if (GamePad.Down(PAD_R2 | PAD_R1 | PAD_RIGHT)) {
631 DEnterMenu.scroll_top += 5;
632 DEnterMenu.selected_floor += 5;
633 } else if (GamePad.Down(PAD_L2 | PAD_L1 | PAD_LEFT)) {
634 DEnterMenu.scroll_top -= 5;
635 DEnterMenu.selected_floor -= 5;
636 }
637
638 if (DEnterMenu.scroll_top < 0 || DEnterMenu.selected_floor < 0) {
639 DEnterMenu.selected_floor = 0;
640 DEnterMenu.scroll_top = 0;
641 }
642
643 if (DEnterMenu.floor_count - 1 < DEnterMenu.selected_floor) {
644 DEnterMenu.selected_floor = DEnterMenu.floor_count - 1;
645 DEnterMenu.scroll_top = DEnterMenu.selected_floor - 4;
646
647 if (DEnterMenu.scroll_top < 0) {
648 DEnterMenu.scroll_top = 0;
649 }
650 }
651
652#ifdef PAL
653 if (DebugMode) {
654 if (GamePad.Down2(PAD_R1)) {
655 int max_floor = maxFloorTbl__4[DEnterMenu.dungeon];
656 DEnterMenu.floor_count = max_floor;
657
658 for (int floor = 0; floor < DEnterMenu.floor_count; floor++) {
659 DEnterMenu.max_atra[floor] = DEnterStatusPt->GetMaxAtraNum(DEnterMenu.dungeon, floor);
660 DEnterMenu.collected_atra[floor] = DEnterStatusPt->GetAtraNum(DEnterMenu.dungeon, floor);
661 }
662
663 ComMenuSePlay(MENU_SOUND_CONFIRM);
664 }
665
666 if (GamePad.On2(PAD_CROSS)) {
667 if (DEnterMenu.kills[DEnterMenu.selected_floor] < 999) {
668 DEnterMenu.kills[DEnterMenu.selected_floor]++;
669 }
670 }
671
672 if (GamePad.On2(PAD_CIRCLE)) {
673 if (0 < DEnterMenu.kills[DEnterMenu.selected_floor]) {
674 DEnterMenu.kills[DEnterMenu.selected_floor]--;
675 }
676 }
677 }
678
679#endif
680 if (DEnterMenu.selected_floor > DEnterMenu.floor_count - 1) {
681 DEnterMenu.selected_floor = DEnterMenu.floor_count - 1;
682 }
683
684 count = DEnterMenu.floor_count;
685
686 if (count > 5) {
687 if (DEnterMenu.scroll_top > count - 5) {
688 DEnterMenu.scroll_top = count - 5;
689
690 if (DEnterMenu.scroll_top < 0) {
691 DEnterMenu.scroll_top = 0;
692 DEnterMenu.selected_floor = 0;
693 }
694 }
695 } else if (DEnterMenu.selected_floor > count - 1 || DEnterMenu.scroll_top > count - 1) {
696 DEnterMenu.selected_floor = count - 1;
697 DEnterMenu.scroll_top = 0;
698 }
699
700 if (DEnterMenu.scroll_top < 0 || DEnterMenu.selected_floor < 0) {
701 DEnterMenu.scroll_top = 0;
702 DEnterMenu.selected_floor = 0;
703 }
704
705 if (abs(DEnterMenu.scroll_top - scroll_top) > 4) {
706 DEnterMenu.list_y = 118.0f - 40.0f * DEnterMenu.scroll_top;
707 DEnterMenu.scroll_bar_y = 122.0f + 108.0f * DEnterMenu.scroll_top / DEnterMenu.floor_count;
708 }
709
710 if (selected != DEnterMenu.selected_floor || scroll_top != DEnterMenu.scroll_top) {
711 ComMenuSePlay(MENU_SOUND_CURSOR);
712 }
713
714 if (GamePad.Down(PAD_CROSS)) {
715 DEnterMenu.result = DEnterMenu.selected_floor;
716 DEnterMenu.state = DUN_ENTER_FADE_OUT;
717 ComMenuSePlay(MENU_SOUND_CONFIRM);
718 }
719
720 if (GamePad.Down(PAD_CIRCLE)) {
721 ComMenuSePlay(MENU_SOUND_REFUSE);
722 }
723
724 break;
725 }
726
727 return result;
728}
729
730static void DunEnterDraw() {
731 int fade;
732 int alpha;
733 int cover;
734 int half_width;
735 int cursor_y;
736 int left;
737 int top;
738 int right;
739 int bottom;
740 float wave;
741
742 setbilinear(0);
743 CRect_i_ screen(0, 0, 0x2800, (SCREEN_HEIGHT << 4));
744 alpha = 0x80;
745 fade = alpha;
746
747 switch (DEnterMenu.state) {
748 case DUN_ENTER_FADE_IN:
749 if (DEnterMenu.textures_ready != 0) {
750 fade = DEnterMenu.counter * 6;
751 alpha = fade;
752 }
753
754 break;
755 }
756
757 if (alpha < 0) {
758 alpha = 0;
759 }
760
761 if (fade > 0x80) {
762 fade = 0x80;
763 }
764
765 if (alpha > 0x80) {
766 alpha = 0x80;
767 }
768
769 if (DEnterMenu.textures_ready != 0 && DEnterMenu.state != DUN_ENTER_DIRECT) {
770 MenuTextureReload(DEnterMenu.texture_block);
771 DrawDunEnterBack(alpha);
772 DunEnterBoard(0x46, 0x5A, alpha);
773 CursorVibeCnt++;
774
775 if (CursorVibeCnt > 0x107AC0) {
776 CursorVibeCnt = 0;
777 }
778
779 if (DEnterMenu.state == DUN_ENTER_SELECT) {
780 cursor_y = (DEnterMenu.selected_floor - DEnterMenu.scroll_top) * 40 + 0x74;
781 static int DunWakuCnt;
782 static s8 init;
783
784 if (init == 0) {
785 DunWakuCnt = 0;
786 init = 1;
787 }
788
789 wave = 0.2f * DunWakuCnt;
790 left = 94.0f + wave;
791 top = cursor_y + wave;
792 right = 204.0f - wave;
793 bottom = (cursor_y + 0x18) - wave;
794 RECT corner = {0x40, 0x60, 0x10, 0x10};
795 DrawMenu2DSprite(DunLogBoard, CRect_i_(left, top, corner.width, corner.height), CRect_i_(corner.x, corner.y, corner.width, corner.height), alpha);
796 DrawMenu2DSprite(DunLogBoard, CRect_i_(right, top, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y, corner.width, corner.height), alpha);
797 DrawMenu2DSprite(DunLogBoard, CRect_i_(left, bottom, corner.width, corner.height), CRect_i_(corner.x, corner.y + corner.height, corner.width, corner.height), alpha);
798 DrawMenu2DSprite(DunLogBoard, CRect_i_(right, bottom, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y + corner.height, corner.width, corner.height), alpha);
799 DunWakuCnt++;
800
801 if (DunWakuCnt < 0 || DunWakuCnt >= 30) {
802 DunWakuCnt = 0;
803 }
804
805 CRect_i_ cursor(0x20, 0x60, 0x20, 0x20);
806 DrawObjectVibe(0x49, cursor_y + 2, DunLogBoard, cursor, 0, alpha);
807 DrawObjectVibe(0x46, cursor_y, DunLogBoard, cursor, 0x80, alpha);
808 }
809
810 MenuTextureReload(CommonMenuMes2.tex_block);
811 CommonMenuMes2.stay_frame = true;
812 CommonMenuMes2.edge_alpha = alpha;
813#ifdef PAL
814 CommonMenuMes2.text_y = 0x16c;
815#else
816 CommonMenuMes2.text_y = 0x158;
817#endif
818 half_width = CommonMenuMes2.char_width >> 1;
819 GetMenuCommonPutXY(&CommonMenuMes2, 0x148 - half_width);
820 CommonMenuMes2.Step();
821 CommonMenuMes2.DrawMesWin();
822 } else {
823 MGFillBox(screen, 0, 0, 0, 0x80);
824 }
825
826 cover = 0x80;
827
828 switch (DEnterMenu.state) {
829 case DUN_ENTER_FADE_IN:
830 cover = 0x80 - DEnterMenu.counter * 6;
831 break;
832 case DUN_ENTER_FADE_OUT:
833 cover = DEnterMenu.counter * 9;
834 break;
835 }
836
837 if (cover < 0) {
838 cover = 0;
839 }
840
841 if (cover > 0x80) {
842 cover = 0x80;
843 }
844
845 switch (DEnterMenu.state) {
846 case DUN_ENTER_FADE_IN:
847 case DUN_ENTER_FADE_OUT:
848 MGFillBox(screen, 0, 0, 0, cover);
849 break;
850 }
851
852 setbilinear(1);
853}
854
862static void DunEnterBoardWaku(int x, int y, int alpha) {
863 int draw_x;
864 int draw_y;
865 int count;
866 int height;
867 int u;
868 int dungeon;
869 int icon;
870 int v;
871
872 DrawMenu2DSprite(DunLogBoard, CRect_i_(x, y - 1, 0x20, 0xFA), CRect_i_(0, 0, 0x20, 0xF8), alpha);
873 DrawMenu2DSprite(DunLogBoard, CRect_i_(x + 0x20, y, 0x1CC, 0x20), CRect_i_(0x20, 0, 0x1B8, 0x20), alpha);
874 DrawMenu2DSprite(DunLogBoard, CRect_i_(x + 0x1EC, y - 1, 0x28, 0xFA), CRect_i_(0x1D8, 0, 0x28, 0xF8), alpha);
875 DrawMenu2DSprite(DunLogBoard, CRect_i_(x + 0x20, y + 0xD9, 0x1CC, 0x20), CRect_i_(0x20, 0xD8, 0x1B8, 0x20), alpha);
876
877 // The scroll bar eases toward the list's scroll position and shrinks with a longer list.
878 count = DEnterMenu.floor_count;
879
880 if (count < 5) {
881 count = 5;
882 }
883
884 draw_x = x + 0x1FC;
885 draw_y = (int) (DEnterMenu.scroll_bar_y += ((int) (32.0f + y + 108.0f * DEnterMenu.scroll_top / count) - DEnterMenu.scroll_bar_y) / 4.0f);
886 height = (int) (540.0f / count);
887
888 while (y + 0x98 < draw_y + (height + 8)) {
889 height--;
890 }
891
892 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, draw_y, 8, 4), CRect_i_(0x60, 0x60, 8, 4), alpha);
893 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, draw_y + 4, 8, height), CRect_i_(0x60, 0x64, 8, 4), alpha);
894 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, draw_y + height + 4, 8, 4), CRect_i_(0x60, 0x68, 8, 4), alpha);
895
896 draw_x = x + 0x28;
897 draw_y = y - 0x14;
898 dungeon = DEnterMenu.dungeon;
899 icon = dungeon;
900
901 if (icon > 5) {
902 icon = 5;
903 }
904
905 u = (icon / 3) << 8;
906 v = (icon % 3) * 40 + 0x100;
907
908 if (dungeon == 6) {
909 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, draw_y, 0x80, 0x23), CRect_i_(0x20, 0x80, 0x80, 0x24), alpha);
910 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x + 0x80, draw_y, 0x80, 0x23), CRect_i_(0x20, 0xA4, 0x80, 0x24), alpha);
911 } else {
912 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, draw_y, 0x100, 0x28), CRect_i_(u, v, 0x100, 0x28), alpha);
913 }
914}
915
919static void DunEnterBoard(int x, int y, int alpha) {
920 float lane;
921 int top;
922 int row_y;
923 int bottom;
924 int dim;
925 int i;
926 int rule_x;
927 int column_x;
928
929 lane = x;
930 top = y + 0x19;
931 bottom = y + 0xEF;
932
933 // Short lists ease toward their scroll position; longer ones are placed by the scroll bar.
934 int rows = DEnterMenu.floor_count;
935
936 if (rows < 5) {
937 rows = 5;
938 }
939
940 int target = y + 0x1C - DEnterMenu.scroll_top * 40;
941 int step = (int) ((float) target - DEnterMenu.list_y);
942 DEnterMenu.list_y += step >> 2;
943
944 if (abs(step) < 2) {
945 DEnterMenu.list_y = target;
946 }
947
948 row_y = (int) DEnterMenu.list_y;
949
950 CRect_i_ rule_source(0x20, 0x20, 0x28, 7);
951 dim = (alpha * 80) >> 7;
952 rule_x = (int) (32.0f + lane);
953
954 if (DEnterMenu.scroll_top == 0) {
955 DrawMenu2DSprite(DunLogBoard, CRect_i_(rule_x - 10, 0x73, 10, 3), rule_source, dim);
956
957 for (int segment = 0; segment < 11; segment++) {
958 DrawMenu2DSprite(DunLogBoard, CRect_i_(rule_x, 0x73, 0x28, 3), rule_source, dim);
959 rule_x += 0x28;
960 }
961
962 DrawMenu2DSprite(DunLogBoard, CRect_i_(rule_x, 0x73, 10, 3), rule_source, dim);
963 }
964
965 int icon = DEnterMenu.dungeon;
966
967 if (icon > 5) {
968 icon = 5;
969 }
970
971 column_x = x + 0x20;
972
973 for (i = 0; i < 100; i++) {
974 int source = 0x20;
975 int length = 0x28;
976 int position = row_y;
977 lane = column_x;
978
979 if (!(row_y < bottom)) {
980 break;
981 }
982
983 if (row_y + 0x28 <= top) {
984 row_y += 0x28;
985 continue;
986 }
987
988 MenuTextureClip(position, source, length, top, bottom);
989 CRect_i_ edge_source(0x20, source, 10, length);
990 DrawMenu2DSprite(DunLogBoard, CRect_i_((int) (lane - 10.0f), position, 10, length), edge_source, dim);
991
992 for (int segment = 0; segment < 12; segment++) {
993 DrawMenu2DSprite(DunLogBoard, CRect_i_((int) lane, position, 0x28, length), CRect_i_(0x20, source, 0x28, length), dim);
994 lane += 40.0f;
995 }
996
997 DrawMenu2DSprite(DunLogBoard, CRect_i_((int) lane, position, 10, length), edge_source, dim);
998
999 if (DEnterMenu.floor_count - 1 < i) {
1000 row_y += 0x28;
1001 continue;
1002 }
1003
1004 position = row_y + 4;
1005 DrawDunEnterFloorName(column_x, position, i + 1, top, bottom, alpha);
1006 int dungeon = DEnterMenu.dungeon;
1007 int max_floor = maxFloorTbl__4[dungeon];
1008
1009 if (i == max_floor - 1) {
1010 int unused[6] = {20, 0, 30, 60, 20, 16};
1011 int draw_x = column_x + 0x82;
1012 position = row_y + 6;
1013 length = 0x18;
1014 source = dungeon * 24 + 0x20;
1015 MenuTextureClip(position, source, length, top, bottom);
1016
1017 if (position < bottom) {
1018 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, position, 0xDC, length), CRect_i_(0xFC, source, 0xDC, length), alpha);
1019 }
1020 } else if (dungeon < 6) {
1021 int draw_x = column_x + 0x72;
1022 position = row_y;
1023 length = 0x20;
1024 source = 0x20;
1025 MenuTextureClip(position, source, length, top - 10, bottom);
1026
1027 if (position < bottom) {
1028 int remaining = (u8) DEnterMenu.max_atra[i] - (u8) DEnterMenu.collected_atra[i];
1029
1030 for (int mark = 0; mark < remaining; mark++) {
1031 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, position, 0x20, length), CRect_i_(0x48, source, 0x20, length), alpha);
1032 draw_x += 0x1A;
1033 }
1034
1035 for (int mark = 0; mark < (u8) DEnterMenu.collected_atra[i]; mark++) {
1036 DrawMenu2DSprite(DunLogBoard, CRect_i_(draw_x, position, 0x20, length), CRect_i_(0x68, source, 0x20, length), alpha);
1037 draw_x += 0x1A;
1038 }
1039 }
1040 }
1041
1042 row_y += 0x28;
1043 }
1044
1045 MenuTextureReload(DunLogBoard->block);
1046 row_y = (int) DEnterMenu.list_y;
1047 row_y--;
1048
1049 for (int floor = 0; floor < 100; floor++) {
1050 if (floor == maxFloorTbl__4[DEnterMenu.dungeon] - 1) {
1051 break;
1052 }
1053
1054 if (DEnterMenu.floor_count - 1 < floor) {
1055 continue;
1056 }
1057
1058 int board_x = x + 0x16E;
1059
1060 if (row_y < bottom) {
1061 DrawGetAtoraNumBoard(floor, board_x, row_y, top, bottom, alpha);
1062 }
1063
1064 row_y += 0x28;
1065 }
1066
1067 DunEnterBoardWaku(x, y, alpha);
1068}
1069
1077static void DrawEnemyNum(int x, int y, int top, int bottom, int number, int alpha) {
1078 int digits;
1079 int position;
1080 int source;
1081 int length;
1082 int u;
1083 int digit;
1084
1085 for (digits = GetNumberKeta(number); 0 < digits; digits--) {
1086 position = y;
1087 digit = number % 10;
1088 x -= 11;
1089 u = digit * 12 + 0x20;
1090 source = 0x48;
1091 length = 12;
1092 MenuTextureClip(position, source, length, top, bottom);
1093 DrawMenu2DSprite(DunLogBoard, CRect_i_(x, position, 12, length - 1), CRect_i_(u, source, 12, length), alpha);
1094 number /= 10;
1095 }
1096}
1097
1101static inline int KillCountX(int x) {
1102 return x + 0x36;
1103}
1104
1105static void DrawGetAtoraNumBoard(int floor, int x, int y, int top, int bottom, int alpha) {
1106 int position = y;
1107 int source = 0x20;
1108 int length = 0x24;
1109
1110 if (!(top < y + 0x24) || bottom <= y) {
1111 return;
1112 }
1113
1114 MenuTextureClip(position, source, length, top, bottom);
1115 DrawMenu2DSprite(DunLogBoard, CRect_i_(x, position, 0x2B, length), CRect_i_(0x88, source, 0x2B, length), alpha);
1116
1117 position = y + 8;
1118 int collected = (u8) DEnterMenu.collected_atra[floor];
1119
1120 if (top < position) {
1121 DrawDunNumberClip(x + 5, position, top, bottom, collected, alpha);
1122 }
1123
1124 position = y + 0x10;
1125 int maximum = (u8) DEnterMenu.max_atra[floor];
1126 DrawDunNumberClip(x + 0x1B, position, top, bottom, maximum, alpha);
1127
1128 int kills = DEnterMenu.kills[floor];
1129 x = KillCountX(x);
1130 position = y + 1;
1131 source = 0x20;
1132 length = 0x23;
1133 MenuTextureClip(position, source, length, top, bottom);
1134
1135 if (position < bottom) {
1136 DrawMenu2DSprite(DunLogBoard, CRect_i_(x, position, 0x1E, length), CRect_i_(0xB3, source, 0x1E, length), alpha);
1137 }
1138
1139 position = y + 0x10;
1140
1141 if (position < bottom - 4) {
1142 DrawEnemyNum(x + 0x44, position, top, bottom - 6, kills, alpha);
1143 }
1144}
1145
1146static void DrawDunNumberClip(int x, int y, int top, int bottom, int digit, int alpha) {
1147 int position;
1148 int source;
1149 int length;
1150 int u;
1151
1152 position = y;
1153 u = digit * 12 + 0x20;
1154 source = 0x48;
1155 length = 12;
1156 MenuTextureClip(position, source, length, top, bottom);
1157
1158 if (position < bottom) {
1159 DrawMenu2DSprite(DunLogBoard, CRect_i_(x, position, 12, length), CRect_i_(u, source, 12, length), alpha);
1160 }
1161}
1162
1163static void DrawDunEnterBack(int alpha) {
1164#ifdef PAL
1165 DrawFullSizePicture(TexManager.GetTexture("frame", -1), 0, 0, 0x80);
1166#else
1167 DrawMenu2DSprite(TexManager.GetTexture("frame", -1), MenuDispRc, MenuDispRc, 0x80);
1168#endif
1169 MGFillBox(CRect_i_(0, 0, 0x2800, SCREEN_HEIGHT * 0x10), 10, 10, 10, (alpha * 4) >> 7);
1170}
1171
1175int QuickCharaPos[2];
1176
1180s16 CharaChangeTexBlock;
1181
1185s16 CharaChangeReadFlag;
1186
1190u_long128 *chara_change_buf;
1191
1195CTexture *QuickCharaTex;
1196
1200CDngStatusData *ChangeStatusDataPt;
1201
1202CFrame *ItemPolyView;
1203int MDebugItemPolyViewFlag;
1204int polyreadflag;
1205
1206char chara_change_frame_image[] __attribute__((section(".rodata"))) = "#frame_image#640#" SCREEN_HEIGHT_STR "#4";
1207
1208static void DrawDunEnterFloorName(int x, int y, int floor, int top, int bottom, int alpha) {
1209 int position = y;
1210 int height;
1211 int source;
1212 int u;
1213
1214 if (y < bottom) {
1215 height = 0x1C;
1216 u = 0;
1217 source = DEnterMenu.dungeon * 32;
1218
1219 if (DEnterMenu.dungeon >= 6) {
1220 u = 0x80;
1221 source = (DEnterMenu.dungeon - 6) * 32;
1222 }
1223
1224 MenuTextureClip(position, source, height, top, bottom);
1225
1226 if (position + height >= top) {
1227 DrawMenu2DSprite(DunLogBoard2, CRect_i_(x, position, 0x70, height), CRect_i_(u, source, 0x70, height), alpha);
1228 }
1229
1230 if (DEnterMenu.dungeon == 5) {
1231 floor = BtGetFloorLevel(floor - 1);
1232 }
1233
1234 int offset = 0;
1235
1236 if (floor < 10) {
1237 offset = -6;
1238 }
1239
1240 if (DEnterMenu.dungeon == 5 || DEnterMenu.dungeon == 6) {
1241 if (floor < 10) {
1242 offset = -12;
1243 }
1244
1245 if (floor >= 10 && floor < 100) {
1246 offset = -6;
1247 }
1248
1249 if (floor >= 100) {
1250 offset = 0;
1251
1252#ifdef PAL
1253 if (DEnterMenu.dungeon == 6 && GetMenuLangFlag() > LANG_JAPANESE) {
1254 offset += 8;
1255 }
1256#else
1257 if (DEnterMenu.dungeon == 6 && GetMenuLangFlag() == LANG_ENGLISH_US) {
1258 offset += 4;
1259 }
1260#endif
1261 }
1262 }
1263
1264#ifdef PAL
1265 s8 name_width[7][7] = {
1266 {0x50, 0x6E, 0x48, 0x68, 0x38, 0x30, 0x50},
1267 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1268 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1269 {0x52, 0x68, 0x60, 0x62, 0x38, 0x30, 0x66},
1270 {0x5C, 0x68, 0x60, 0x60, 0x2E, 0x30, 0x64},
1271 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1272 {0x52, 0x68, 0x60, 0x60, 0x38, 0x50, 0x64},
1273 };
1274#else
1275 s8 name_width[7][7] = {
1276 {0x50, 0x6E, 0x48, 0x68, 0x38, 0x30, 0x50},
1277 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1278 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1279 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1280 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1281 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1282 {0x52, 0x68, 0x60, 0x60, 0x38, 0x30, 0x64},
1283 };
1284#endif
1285 x = offset + (x + name_width[GetMenuLangFlag()][DEnterMenu.dungeon]);
1286 position = y;
1287 RECT digits = {0, 0xC0, 0x10, 0x1C};
1288
1289 if (y + height >= top) {
1290 DrawMenuNumber(floor, x, y, digits, DunLogBoard2, 0, top, bottom, alpha);
1291 }
1292 }
1293}
1294
1295float changeMenu_long = 60.0f;
1296
1300static inline void SetChangeMenuCursor() {
1301 ChangeMenu.cursor_x = CommonMenuMes3.text_x - 0x1C;
1302 ChangeMenu.cursor_y = CommonMenuMes3.text_y - 4 + ChangeMenu.cursor_row * 24;
1303}
1304
1305void StartQuickChange(u_long128 *buffer, int texture_block, int *positions, int mode) {
1306 LOADTEXTURE_INFO2 table[] = {
1307 {chara_change_frame_image, 0, 0},
1308 {NULL, 0, 0},
1309 };
1310 table[0].block_no = texture_block;
1311 TexManager.DeleteTextureBlock(texture_block);
1312 TexManager.CleanUpTextureList();
1313 TexManager.LoadTextureBlockEX(-1, table);
1314 chara_change_buf = buffer;
1315 chara_change_buf = MenuCalcBufAlignment(buffer);
1316 StartReadBG();
1317 LoadFileBGMenuData("quickchr.pac", chara_change_buf);
1318 CharaChangeReadFlag = 0;
1319 ReadBG();
1320 QuickCharaPos[0] = positions[0];
1321 QuickCharaPos[1] = positions[1];
1322 ChangeStatusDataPt = (CDngStatusData *) UserStatus;
1323
1324 if (ChangeStatusDataPt == NULL) {
1325 return;
1326 }
1327
1328 ChangeMenu.selected = ChangeStatusDataPt->cur_chara;
1329 ItemVolumeStep.CheckItemVolume();
1330 ChangeMenu.unk_4c = 0;
1331 StayTex = TexManager.GetTexture("stayframe", -1);
1332 CommonMenuMes3.text_x = 200;
1333 CommonMenuMes3.text_y = 190;
1334 changeMenu_long = 60.0f;
1335 ChangeMenu.mode = mode;
1336 ChangeMenu.cursor_row = 0;
1337 ChangeMenu.change_blocked = 0;
1338 CUserStatus *status = (CUserStatus *) ChangeStatusDataPt;
1339 int zone = status->res_limit_zone_current;
1340
1341 if (zone < 6 && zone >= 0) {
1342 ChangeMenu.change_blocked = 1;
1343 } else if (status->cur_chara == CHARA_OSMOND && BtActStatus.ground_kind == 10) {
1344 ChangeMenu.change_blocked = 2;
1345 }
1346
1347 if (ChangeMenu.mode != 0) {
1348 ChangeMenu.step = CHARA_CHANGE_ITEM_PROMPT;
1349 SetChangeMenuCursor();
1350 } else {
1351 ChangeMenu.step = CHARA_CHANGE_SELECT;
1352
1353 if (ChangeMenu.change_blocked == 1) {
1354 ChangeMenu.cursor_row = 1;
1355 SetChangeMenuCursor();
1356 } else if (ChangeMenu.change_blocked == 2) {
1357 printf(" not change area \n");
1358 ChangeMenu.cursor_row = 1;
1359 SetChangeMenuCursor();
1360 }
1361 }
1362
1363 ChangeMenu.party_size = ChangeStatusDataPt->party_size;
1364 ChangeMenu.reset_on_open = 0;
1365 float step = TWO_PI / ChangeMenu.party_size;
1366 int i;
1367
1368 if (ChangeMenu.turn_direction < 0.0f) {
1369 i = 0;
1370 }
1371
1372 for (i = 0; i < ChangeMenu.party_size; i++) {
1373 ChangeMenu.ring_slot[i] = i - ChangeMenu.selected;
1374
1375 if (ChangeMenu.ring_slot[i] < 0) {
1376 ChangeMenu.ring_slot[i] += ChangeMenu.party_size;
1377 }
1378
1379 float angle = PI + step * ChangeMenu.ring_slot[i];
1380 ChangeMenu.ring_pos[i][0] = changeMenu_long * cos(angle);
1381 ChangeMenu.ring_pos[i][1] = changeMenu_long * sin(angle);
1382 }
1383
1384 GamePad.SetAutoRepeat(PAD_DPAD, 30, 5);
1385 GamePad.MenuModeOn(0x78);
1386 CharaChangeTexBlock = texture_block;
1387}
1388
1389int CharaChangeLoop() {
1390 if (ReadBGSync() == 0 && CharaChangeReadFlag == 0) {
1391 LOADTEXTURE_INFO2 table[] = {
1392 {chara_change_frame_image, 0, 0},
1393 {NULL, 0, 0},
1394 {NULL, 0, 0},
1395 };
1396 table[0].block_no = CharaChangeTexBlock;
1397 table[1].block_no = CharaChangeTexBlock;
1398 BG_READ_INFO *file = GetReadBGFile(0);
1399
1400 if (file == NULL) {
1401 return 1;
1402 }
1403
1404 table[1].name = (char *) GetPackFile((u_int *) file->buffer, "quickchr.img", NULL);
1405 TexManager.DeleteTextureBlock(CharaChangeTexBlock);
1406 TexManager.CleanUpTextureList();
1407 TexManager.LoadTextureBlockEX(-1, table);
1408 QuickCharaTex = TexManager.GetTexture("quickchara", -1);
1409 chara_change_buf = file->buffer + (file->size >> 4) + 4;
1410 chara_change_buf = MenuCalcBufAlignment(chara_change_buf);
1411 CharaChangeReadFlag = 1;
1412 InitMenuMesSet(MENU_MES_SET_ALLMENU, (s16 *) GetPackFile((u_int *) file->buffer, "qchr.mes", NULL));
1413 CommonMenuMes3.auto_pos = MES_POS_NONE;
1414 CommonMenuMes3.Preset(MES_PRESET_SYSTEM);
1415 int message = 1;
1416
1417 if (ChangeMenu.change_blocked == 1) {
1418 message = 4;
1419 }
1420
1421 if (ChangeMenu.change_blocked == 2) {
1422 message = 5;
1423 }
1424
1425 CommonMenuMes3.MakeMesWin(message);
1426 CommonMenuMes1.Preset(MES_PRESET_SYSTEM);
1427 CommonMenuMes1.MakeMesWin(3);
1428 }
1429
1430 int result = 0;
1431
1432 if (CharaChangeReadFlag != 0) {
1433 result = CharaChangeKey();
1434 }
1435
1436 CharaChangeDraw();
1437 ItemVolumeStep.LoopStep(60);
1438
1439 if (result != 0) {
1440 MenuTextureReload(CharaChangeTexBlock);
1441 DngActiveWeaponTextureCopy();
1442 CharaChangeReadFlag = 0;
1443 ItemVolumeStep.CheckItemVolume();
1444 GamePad.MenuModeOff();
1445 GamePad.AutoRepeatOff();
1446 TexManager.DeleteTextureBlock(CharaChangeTexBlock);
1447 TexManager.CleanUpTextureList();
1448 LOADTEXTURE_INFO2 restore[] = {
1449 {chara_change_frame_image, 0, 0},
1450 {NULL, 0, 0},
1451 };
1452 restore[0].block_no = CharaChangeTexBlock;
1453 TexManager.LoadTextureBlockEX(-1, restore);
1454 }
1455
1456 return result;
1457}
1458
1462static inline void SetStatusChara(CDngStatusData *status, s8 chara) {
1463 status->cur_chara = chara;
1464}
1465
1466int CharaChangeKey() {
1467 int result = 0;
1468
1469 ReadBG();
1470
1471 switch (ChangeMenu.step) {
1472 case CHARA_CHANGE_LOADING:
1473 ChangeMenu.unk_4c++;
1474
1475 if (ReadBGSync() == 0 && ChangeMenu.unk_4c > 0x10) {
1476 BtMenuLoadChara();
1477 StartReadBG();
1478 CharaChangeInitToGL2(0);
1479 ChangeMenu.step = CHARA_CHANGE_LOADED;
1480 }
1481
1482 break;
1483 case CHARA_CHANGE_LOADED:
1484 ChangeMenu.unk_4c++;
1485
1486 if (ReadBGSync() == 0 && ChangeMenu.unk_4c > 0x10) {
1487 BtMenuLoad2(0);
1488 LockOffTargte();
1489 InitReadBG();
1490 return 1;
1491 }
1492
1493 break;
1494 case CHARA_CHANGE_BLOCKED:
1495 case CHARA_CHANGE_UNK_4: {
1496 int message = 1;
1497
1498 if (ChangeMenu.change_blocked == 1) {
1499 message = 4;
1500 }
1501
1502 if (ChangeMenu.change_blocked == 2) {
1503 message = 5;
1504 }
1505
1506 if (CommonMenuMes3.mes_made != message) {
1507 CommonMenuMes3.MakeMesWin(message);
1508 }
1509
1510 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS)) {
1511 if (ChangeMenu.mode != 0) {
1512 ChangeMenu.step = CHARA_CHANGE_ITEM_PROMPT;
1513 CommonMenuMes3.MakeMesWin(ChangeMenu.change_blocked == 0 ? 1 : 2);
1514 } else {
1515 ChangeMenu.step = CHARA_CHANGE_SELECT;
1516 }
1517
1518 ComMenuSePlay(MENU_SOUND_REFUSE);
1519 }
1520
1521 break;
1522 }
1523 case CHARA_CHANGE_TURNING:
1524 ChangeMenu.turn_frame += 1.0f;
1525
1526 if (ChangeMenu.turn_frame >= 21.0f) {
1527 if (ChangeMenu.turn_direction > 0.0f) {
1528 for (int i = 0; i < 6; i++) {
1529 ChangeMenu.ring_slot[i]++;
1530
1531 if (ChangeMenu.ring_slot[i] == ChangeMenu.party_size) {
1532 ChangeMenu.ring_slot[i] = 0;
1533 }
1534 }
1535 } else {
1536 for (int i = 0; i < ChangeMenu.party_size; i++) {
1537 ChangeMenu.ring_slot[i]--;
1538
1539 if (ChangeMenu.ring_slot[i] == -1) {
1540 ChangeMenu.ring_slot[i] = ChangeMenu.party_size - 1;
1541 }
1542 }
1543 }
1544
1545 ChangeMenu.step = CHARA_CHANGE_SELECT;
1546 ChangeMenu.turn_frame = 0.0f;
1547 ChangeMenu.turn_direction = 0.0f;
1548 }
1549
1550 break;
1551 case CHARA_CHANGE_ITEM_PROMPT: {
1552 int message = 1;
1553
1554 if (ChangeMenu.change_blocked == 1 || ChangeMenu.change_blocked == 2) {
1555 message = 2;
1556 }
1557
1558 if (CommonMenuMes3.mes_made != message) {
1559 CommonMenuMes3.MakeMesWin(message);
1560 }
1561
1562 if (GamePad.Down(PAD_UP | PAD_DOWN)) {
1563 if (ChangeMenu.cursor_row > 0) {
1564 ChangeMenu.cursor_row = 0;
1565 } else {
1566 ChangeMenu.cursor_row = 1;
1567 }
1568
1569 ComMenuSePlay(MENU_SOUND_CURSOR);
1570 }
1571
1572#ifdef PAL
1573 if (DebugMode && GamePad.Down2(PAD_CROSS)) {
1574 ChangeStatusDataPt->GetItem(ITEM_STAND_IN_POWDER, 0);
1575 }
1576
1577#endif
1578 if (GamePad.Down(PAD_CROSS)) {
1579 ITEM_PACK *pack = &ChangeStatusDataPt->item_pack;
1580 int count = GetNowItemNum(ITEM_STAND_IN_POWDER, pack);
1581
1582 if (ChangeMenu.cursor_row != 0) {
1583 result = 2;
1584 ComMenuSePlay(MENU_SOUND_CONFIRM);
1585 } else if (ChangeMenu.change_blocked == 1) {
1586 ComMenuSePlay(MENU_SOUND_REFUSE);
1587 ChangeMenu.step = CHARA_CHANGE_BLOCKED;
1588 return 0;
1589 } else if (ChangeMenu.change_blocked == 2) {
1590 ComMenuSePlay(MENU_SOUND_REFUSE);
1591 ChangeMenu.step = CHARA_CHANGE_BLOCKED;
1592 return 0;
1593 } else if (count > 0) {
1594 ChangeMenu.step = CHARA_CHANGE_SELECT;
1595 ComMenuSePlay(MENU_SOUND_CONFIRM);
1596 } else {
1597 ComMenuSePlay(MENU_SOUND_REFUSE);
1598 }
1599 } else if (GamePad.Down(PAD_CIRCLE)) {
1600 ComMenuSePlay(MENU_SOUND_REFUSE);
1601 }
1602
1603 break;
1604 }
1605 case CHARA_CHANGE_SELECT: {
1606 if (GamePad.Down(PAD_CROSS)) {
1607 if (ChangeMenu.selected > ChangeMenu.party_size - 1) {
1608 ComMenuSePlay(MENU_SOUND_REFUSE);
1609 ChangeMenu.step = CHARA_CHANGE_BLOCKED;
1610 return 0;
1611 }
1612
1613 if (ChangeMenu.change_blocked == 1) {
1614 ComMenuSePlay(MENU_SOUND_REFUSE);
1615 CommonMenuMes3.MakeMesWin(4);
1616 ChangeMenu.step = CHARA_CHANGE_BLOCKED;
1617 return 0;
1618 }
1619
1620 if (ChangeMenu.change_blocked == 2) {
1621 CommonMenuMes3.MakeMesWin(5);
1622 ChangeMenu.step = CHARA_CHANGE_BLOCKED;
1623 ComMenuSePlay(MENU_SOUND_REFUSE);
1624 return 0;
1625 }
1626
1627 CDngStatusData *status = ChangeStatusDataPt;
1628 int hp = status->hp[ChangeMenu.selected];
1629 int flags = status->GetActiveCharaStatus(ChangeMenu.selected);
1630
1631 if (hp <= 0 || (flags & AILMENT_KNOCKED_OUT)) {
1632 ComMenuSePlay(MENU_SOUND_REFUSE);
1633 return 0;
1634 }
1635
1636 if (ChangeMenu.selected != status->cur_chara) {
1637 ComMenuSePlay(MENU_SOUND_CONFIRM);
1638 SetStatusChara(ChangeStatusDataPt, ChangeMenu.selected);
1639
1640 if (ChangeMenu.mode == 1) {
1641 ChangeStatusDataPt->LostItem(ITEM_STAND_IN_POWDER);
1642 }
1643
1644 ChangeMenu.unk_4c = 0;
1645 ChangeMenu.step = CHARA_CHANGE_LOADING;
1646 ChangeMenu.mode = 0;
1647 return 0;
1648 }
1649
1650 ComMenuSePlay(MENU_SOUND_CONFIRM);
1651 } else if (GamePad.Down(PAD_CIRCLE)) {
1652 if (ChangeStatusDataPt->hp[ChangeStatusDataPt->cur_chara] < 0 || ChangeMenu.mode != 0) {
1653 ChangeMenu.step = CHARA_CHANGE_ITEM_PROMPT;
1654 ChangeMenu.cursor_row = 0;
1655 ChangeMenu.cursor_x = CommonMenuMes3.text_x - 0x1E;
1656 ChangeMenu.cursor_y = CommonMenuMes3.text_y + 0x10 + ChangeMenu.cursor_row * 24;
1657 } else {
1658 result = 1;
1659 }
1660
1661 ComMenuSePlay(MENU_SOUND_REFUSE);
1662 }
1663
1664 int previous = ChangeMenu.selected;
1665
1666 if (GamePad.Down(PAD_UP | PAD_RIGHT)) {
1667 ChangeMenu.turn_direction = 1.0f;
1668 ChangeMenu.selected--;
1669
1670 if (ChangeMenu.selected < 0) {
1671 ChangeMenu.selected = ChangeMenu.party_size - 1;
1672 }
1673 }
1674
1675 if (GamePad.Down(PAD_DOWN | PAD_LEFT)) {
1676 ChangeMenu.turn_direction = -1.0f;
1677 ChangeMenu.selected++;
1678
1679 if (ChangeMenu.party_size - 1 < ChangeMenu.selected) {
1680 ChangeMenu.selected = 0;
1681 }
1682 }
1683
1684 if (previous != ChangeMenu.selected) {
1685 ChangeMenu.step = CHARA_CHANGE_TURNING;
1686 BreakReadBG();
1687 u_long128 *buffer = chara_change_buf;
1688 CharaChangeInitToGL(buffer, ChangeMenu.selected);
1689 ComMenuSePlay(MENU_SOUND_CURSOR);
1690 }
1691
1692 break;
1693 }
1694 case CHARA_CHANGE_UNK_7:
1695 ChangeMenu.unk_4c += 7;
1696
1697 if (ChangeMenu.unk_4c > 0xFA) {
1698 result = 2;
1699 }
1700
1701 break;
1702 }
1703
1704 return result;
1705}
1706
1707void CharaChangeDraw() {
1708 int alpha;
1709 int i;
1710 int cursor_x;
1711 int cursor_y;
1712 float step;
1713 float turn;
1714 float angle;
1715
1716 setbilinear(0);
1717 FrameImageDraw(100, 0x80);
1718
1719 if (CharaChangeReadFlag != 0) {
1720 MenuTextureReload(CharaChangeTexBlock);
1721#ifdef PAL
1722 CTexture *frame = TexManager.GetTexture("stayframe", -1);
1723#else
1724 CTexture *frame = TexManager.GetTexture(stay_frame_name, -1);
1725#endif
1726 int frame_x = QuickCharaPos[0] - 2.0f * changeMenu_long;
1727 int frame_y = QuickCharaPos[1] - 1.4f * changeMenu_long;
1728 alpha = 0x80;
1729
1730 switch (ChangeMenu.step) {
1731 case CHARA_CHANGE_LOADED:
1732 case CHARA_CHANGE_LOADING:
1733 alpha = 0x80 - ChangeMenu.unk_4c * 4;
1734
1735 if (alpha < 0) {
1736 alpha = 0;
1737 }
1738
1739 break;
1740 }
1741
1742 step = TWO_PI / ChangeMenu.party_size;
1743
1744 switch (ChangeMenu.step) {
1745 case CHARA_CHANGE_LOADED:
1746 case CHARA_CHANGE_LOADING:
1747 changeMenu_long += ChangeMenu.unk_4c;
1748 turn = step / 20.0f;
1749
1750 if (ChangeMenu.turn_direction < 0.0f) {
1751 turn = -turn;
1752 }
1753
1754 for (i = 0; i < ChangeMenu.party_size; i++) {
1755 angle = PI + (step * ChangeMenu.ring_slot[i] + turn * ChangeMenu.unk_4c);
1756 ChangeMenu.ring_pos[i][0] = changeMenu_long * cos(angle);
1757 ChangeMenu.ring_pos[i][1] = changeMenu_long * sin(angle);
1758 }
1759
1760 break;
1761 case CHARA_CHANGE_TURNING:
1762 turn = step / 20.0f;
1763
1764 if (ChangeMenu.turn_direction < 0.0f) {
1765 turn = -turn;
1766 }
1767
1768 for (i = 0; i < ChangeMenu.party_size; i++) {
1769 angle = PI + (step * ChangeMenu.ring_slot[i] + turn * ChangeMenu.turn_frame);
1770 ChangeMenu.ring_pos[i][0] = changeMenu_long * cos(angle);
1771 ChangeMenu.ring_pos[i][1] = changeMenu_long * sin(angle);
1772 }
1773
1774 break;
1775 }
1776
1777 CTexture *portraits = QuickCharaTex;
1778
1779 for (int chara = 0; chara < ChangeMenu.party_size; chara++) {
1780 float x = QuickCharaPos[0] + ChangeMenu.ring_pos[chara][0];
1781 float y = QuickCharaPos[1] + ChangeMenu.ring_pos[chara][1];
1782 int shade = 0x80;
1783 int u = chara * 0x30;
1784 int v = 0;
1785
1786 if (chara > 2) {
1787 u = (chara - 3) * 0x30;
1788 v = 0x30;
1789 }
1790
1791 if (ChangeStatusDataPt != NULL && ChangeStatusDataPt->hp[chara] <= 0) {
1792 shade = 0x40;
1793 }
1794
1795 DrawMenu2DSprite(portraits, CRect_i_(x, y, 0x30, 0x30), CRect_i_(u, v, 0x30, 0x30), shade, shade, shade, alpha);
1796 }
1797
1798 if (ChangeMenu.step != CHARA_CHANGE_LOADED && ChangeMenu.step != CHARA_CHANGE_LOADING && ChangeMenu.step != CHARA_CHANGE_BLOCKED && ChangeMenu.step != CHARA_CHANGE_UNK_4) {
1799 DrawMenuWaku(QuickCharaPos[0] - changeMenu_long - 11.0f, QuickCharaPos[1] - 12, 0x34, 0x34, 0, StayTex, 0x80);
1800 }
1801
1802 if (ChangeMenu.step == CHARA_CHANGE_ITEM_PROMPT || ChangeMenu.step == CHARA_CHANGE_BLOCKED || ChangeMenu.step == CHARA_CHANGE_UNK_4) {
1803 AllFadeForMenu(0x40);
1804 CommonMenuMes3.stay_frame = true;
1805 CommonMenuMes3.auto_pos = MES_POS_CENTRE;
1806 MenuTextureReload(CommonMenuMes3.tex_block);
1807 CommonMenuMes3.Step();
1808 CommonMenuMes3.DrawMesWin();
1809 cursor_x = CommonMenuMes3.text_x - 0x1E;
1810 cursor_y = CommonMenuMes3.text_y + 0x10 + ChangeMenu.cursor_row * 0x18;
1811 ChangeMenu.cursor_x += (cursor_x - ChangeMenu.cursor_x) / 4.0f;
1812 ChangeMenu.cursor_y += (cursor_y - ChangeMenu.cursor_y) / 4.0f;
1813 cursor_x = ChangeMenu.cursor_x;
1814 cursor_y = ChangeMenu.cursor_y;
1815 } else {
1816 CommonMenuMes3.auto_pos = MES_POS_NONE;
1817 cursor_x = QuickCharaPos[0] - changeMenu_long - 32.0f;
1818 cursor_y = QuickCharaPos[1] + 6;
1819
1820 if (cursor_x < -40 || cursor_x > 640 || cursor_y < -40 || cursor_y > 450) {
1821 cursor_x = 650;
1822 cursor_y = 450;
1823 }
1824 }
1825
1826 CursorVibeCnt++;
1827
1828 if (CursorVibeCnt > 1080000) {
1829 CursorVibeCnt = 0;
1830 }
1831
1832#ifdef PAL
1833 if (ChangeMenu.mode != 0) {
1834 MenuTextureReload(CharaChangeTexBlock);
1835 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x5C, 0x138, 0x1A, 0x1B), CRect_i_(0xA6, 0, 0x1A, 0x1C), alpha);
1836 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x76, 0x138, 0x30, 0x1B), CRect_i_(0xC0, 0, 0x20, 0x1C), alpha);
1837 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0xA6, 0x138, 0x1A, 0x1B), CRect_i_(0xE0, 0, 0x1A, 0x1C), alpha);
1838 int value = (u16) ChangeStatusDataPt->money_signed;
1839 RECT value_digits = {0x70, 0x74, 0xC, 0xC};
1840 DrawMenuNumber(value, 0xB7, 0x140, QuickCharaTex, value_digits, 0, alpha);
1841 int lang = GetMenuLangFlag();
1842 float help_width[7] = {10.6f, 10.6f, 10.6f, 14.0f, 12.0f, 11.8f, 10.7f};
1843 MenuHelpWinDraw(100, 0x154, help_width[lang], 0.9f, alpha);
1844 u8 count_shift[7] = {0, 0, 0, 56, 28, 16, 0};
1845 int count_x = count_shift[lang];
1846 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x76, 0x164, 0x20, 0x20), CRect_i_(0, 0x60, 0x20, 0x20), alpha);
1847 DrawMenu2DSprite(QuickCharaTex, CRect_i_(count_x + 0x104, 0x16C, 0x10, 0x10), CRect_i_(0x20, 0x60, 0x10, 0x10), alpha);
1848 MenuTextureReload(CommonMenuMes1.tex_block);
1849
1850 if (lang == LANG_JAPANESE) {
1851 DrawMenuClsMes(&CommonMenuMes1, 0xA0, 0x154);
1852 } else {
1853 CommonMenuMes1.line_pos[0].x = 0xA0;
1854 CommonMenuMes1.line_pos[0].y = 0x15E;
1855 CommonMenuMes1.line_pos[1].x = 0xA6;
1856 CommonMenuMes1.line_pos[1].y = 0x172;
1857 CommonMenuMes1.Step();
1858 CommonMenuMes1.DrawMesWin();
1859 }
1860
1861 RECT count_digits = {0, 0x9E, 0xC, 0x12};
1862 ITEM_PACK *pack = &ChangeStatusDataPt->item_pack;
1863 int count = GetNowItemNum(ITEM_STAND_IN_POWDER, pack);
1864 count_x += 0x122;
1865 count_x += (count_digits.width >> 1) * GetNumberKeta(count);
1866 DrawMenuNumber(count, count_x, 0x16C, count_digits, StayTex, 0, 0, SCREEN_HEIGHT, alpha);
1867 }
1868
1869#else
1870 if (ChangeMenu.mode != 0) {
1871 MenuTextureReload(CharaChangeTexBlock);
1872 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x5C, 0x124, 0x1A, 0x1B), CRect_i_(0xA6, 0, 0x1A, 0x1C), alpha);
1873 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x76, 0x124, 0x30, 0x1B), CRect_i_(0xC0, 0, 0x20, 0x1C), alpha);
1874 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0xA6, 0x124, 0x1A, 0x1B), CRect_i_(0xE0, 0, 0x1A, 0x1C), alpha);
1875 int value = (u16) ChangeStatusDataPt->money_signed;
1876 RECT value_digits = {0x70, 0x74, 0xC, 0xC};
1877 DrawMenuNumber(value, 0xB7, 0x12C, QuickCharaTex, value_digits, 0, alpha);
1878 MenuHelpWinDraw(100, 0x140, 10.6f, 0.9f, alpha);
1879 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x76, 0x150, 0x20, 0x20), CRect_i_(0, 0x60, 0x20, 0x20), alpha);
1880 DrawMenu2DSprite(QuickCharaTex, CRect_i_(0x104, 0x158, 0x10, 0x10), CRect_i_(0x20, 0x60, 0x10, 0x10), alpha);
1881 MenuTextureReload(CommonMenuMes1.tex_block);
1882 CommonMenuMes1.line_pos[0].x = 0xA0;
1883 CommonMenuMes1.line_pos[0].y = 0x14A;
1884 CommonMenuMes1.line_pos[1].x = 0xAA;
1885 CommonMenuMes1.line_pos[1].y = 0x15E;
1886 CommonMenuMes1.Step();
1887 CommonMenuMes1.DrawMesWin();
1888 RECT count_digits = {0, 0x9E, 0xC, 0x12};
1889 ITEM_PACK *pack = &ChangeStatusDataPt->item_pack;
1890 int count = GetNowItemNum(ITEM_STAND_IN_POWDER, pack);
1891 int count_x = 0x122;
1892 count_x += (count_digits.width >> 1) * GetNumberKeta(count);
1893 DrawMenuNumber(count, count_x, 0x158, count_digits, StayTex, 0, 0, 0x1C0, alpha);
1894 }
1895
1896#endif
1897 if (ChangeMenu.step != CHARA_CHANGE_LOADED && ChangeMenu.step != CHARA_CHANGE_LOADING && ChangeMenu.step != CHARA_CHANGE_BLOCKED && ChangeMenu.step != CHARA_CHANGE_UNK_4) {
1898 DrawMenuObjectVibe(cursor_x, cursor_y, 1, 0x40);
1899 }
1900
1901 setbilinear(1);
1902 }
1903}
1904
1905int DngActItemModelReadStart(u_long128 *buffer) {
1906 char model_path[64];
1907 char texture_path[76];
1908 int size;
1909 u_long128 *model_buffer;
1910 u_long128 *texture_buffer;
1911 int i;
1912 ITEM_PACK *pack;
1913
1914 size = 0;
1915 pack = &BtlMenuStatusPt->item_pack;
1916
1917 if (pack == NULL) {
1918 return 1;
1919 }
1920
1921 model_buffer = MenuCalcBufAlignment(buffer);
1922 texture_buffer = model_buffer + 0xFA1;
1923 texture_buffer = MenuCalcBufAlignment(texture_buffer);
1924 StartReadBG();
1925
1926 for (i = 0; i < 3; i++) {
1927 if (pack->quick_item_slot[i] >= ITEM_DUNGEON_START) {
1928 printf("mds = %p\n", model_buffer);
1929 printf("img = %p\n", texture_buffer);
1930 BtGetItemNamePath(model_path, texture_path, pack->quick_item_slot[i]);
1931 LoadFileBG(model_path, model_buffer, &size);
1932 model_buffer += (((size >> 6) + 1) << 6) >> 4;
1933 LoadFileBG(texture_path, texture_buffer, &size);
1934 texture_buffer += (((size >> 6) + 1) << 6) >> 4;
1935 }
1936
1937 if (pack->quick_item_slot[i] < ITEM_DUNGEON_START) {
1938 pack->quick_item_slot[i] = -1;
1939 }
1940 }
1941
1942 return 0;
1943}
1944
1945int DngActItemModelBuild(int wait) {
1946 BG_READ_INFO *model;
1947 BG_READ_INFO *texture;
1948 u_int *model_buffer;
1949 u_int *texture_buffer;
1950 int texture_size;
1951 int read_index;
1952 int i;
1953
1954 if (ReadBGSync() != 0) {
1955 if (wait != 0) {
1956 while (ReadBGSync() != 0) {
1957 }
1958 } else {
1959 ReadBG();
1960 return 0;
1961 }
1962 }
1963
1964 ITEM_PACK *pack = &BtlMenuStatusPt->item_pack;
1965 int items[3] = {pack->quick_item_slot[0], pack->quick_item_slot[1], pack->quick_item_slot[2]};
1966 read_index = 0;
1967
1968 for (i = 0; i < 3; i++) {
1969 if (items[i] < ITEM_DUNGEON_START) {
1970 continue;
1971 }
1972
1973 model = GetReadBGFile(read_index * 2);
1974 texture = GetReadBGFile(read_index * 2 + 1);
1975 read_index++;
1976
1977 if (model != NULL) {
1978 model_buffer = (u_int *) model->buffer;
1979 }
1980
1981 if (texture != NULL) {
1982 texture_buffer = (u_int *) texture->buffer;
1983 texture_size = texture->size;
1984 }
1985
1986 if (model == NULL || texture == NULL) {
1987 continue;
1988 }
1989
1990 if (activeItem.model[i + 1] != -1) {
1991 activeItem.models->DeleteModel(activeItem.model[i + 1]);
1992 activeItem.model[i + 1] = -1;
1993 }
1994
1995 if (activeItem.model[i + 1] != -1) {
1996 activeItem.models->DeleteModel(activeItem.model[i + 1]);
1997 }
1998
1999 activeItem.model[i + 1] = activeItem.models->SetCashModel(items[i], model_buffer, texture_buffer, texture_size);
2000 activeItem.model[i + 5] = 0;
2001 activeItem.item[i + 1] = items[i];
2002 }
2003
2004 return 1;
2005}
2006
2007int DngActiveItemTextureCopy() {
2008 int i;
2009 ITEM_PACK *pack = &UserStatus->item_pack;
2010
2011 if (pack == NULL) {
2012 return -1;
2013 }
2014
2015 char source[] = "itemicon";
2016
2017 for (i = 0; i < 3; i++) {
2018 int item_no = pack->quick_item_slot[i];
2019
2020 if (item_no >= ITEM_DUNGEON_START) {
2021 COM_ITEM_INFO *info = GetCommonItemInfo(item_no);
2022
2023 if (info != NULL) {
2024 int icon = info->icon_index;
2025
2026 if (icon >= 0 && icon <= 256) {
2027 int u = (icon % 8) * 32;
2028 int v = (icon >> 3) * 32;
2029 setItemToReserved(source, u, v, "itempack", i * 32 + 32, 0);
2030 }
2031 }
2032 }
2033 }
2034
2035 return 1;
2036}
2037
2038char item_view_frame_image[] __attribute__((section(".rodata"))) = "#frame_menuwep#640#" SCREEN_HEIGHT_STR "#4";
2039#ifdef PAL
2043char debug_item_font_texture[] __attribute__((section(".rodata"))) = "dbgwork_menu";
2044#endif
2045char item_templete_no[] __attribute__((section(".rodata"))) = "ItemNo :%d\n";
2046char item_templete_type[] __attribute__((section(".rodata"))) = "type: :%s\n";
2047char item_templete_use[] __attribute__((section(".rodata"))) = "use :%s\n";
2048char item_templete_attribute[] __attribute__((section(".rodata"))) = "attribute:%s\n";
2049char item_templete_name_index[] __attribute__((section(".rodata"))) = "nameIndex:%d\n";
2050char item_templete_help_index[] __attribute__((section(".rodata"))) = "helpIndex:%d\n";
2051char item_templete_volume[] __attribute__((section(".rodata"))) = "volume[3]:%3d, %3d, %3d\n";
2052char item_templete_gold[] __attribute__((section(".rodata"))) = "gold :%d\n";
2053
2054int DngActiveWeaponTextureCopy() {
2055 int chara = UserStatus->cur_chara;
2056 char source[] = "wepicon";
2057 int slot = UserStatus->equipped_weapon_slot[chara];
2058 WEAPON_HAVE *owned = UserStatus->chara_weapons[chara];
2059 WEAPON_HAVE *weapon = &owned[slot];
2060 int default_no = GetDefaultWeaponNo(chara);
2061 s16 pos[3][2] = {
2062 {0, 0 },
2063 {0, 32},
2064 {32, 32}
2065 };
2066 s16 weapons[3] = {weapon->item_no, default_no + 1, default_no};
2067
2068 for (int i = 0; i < 3; i++) {
2069 COM_ITEM_INFO *info = GetCommonItemInfo(weapons[i]);
2070
2071 if (info != NULL) {
2072 int icon = info->icon_index;
2073 int u = (icon % 8) * 32;
2074 int v = (icon >> 3) * 32;
2075 setItemToReserved(source, u, v, "itempack", pos[i][0], pos[i][1]);
2076 }
2077 }
2078
2079 return 1;
2080}
2081
2082s32 GetWeaponMsgNo(WEAPON_HAVE *weapon) {
2083 s16 item_no;
2084
2085 if (weapon == NULL) {
2086 return 0;
2087 }
2088
2089 item_no = weapon->item_no;
2090
2091 if (item_no < ITEM_WEAPON_START) {
2092 return 0x3E7;
2093 }
2094
2095 return GetCommonItemInfo((s32) item_no)->msg + 0x64;
2096}
2097
2098int GetWeaponMsgNo2(s32 item_no) {
2099 COM_ITEM_INFO *info;
2100
2101 info = GetCommonItemInfo(item_no);
2102
2103 if (info != NULL) {
2104 return info->msg;
2105 }
2106
2107 return 0;
2108}
2109
2110void DrawWepAttach(int x, int y, WEAPON_HAVE *weapon, int selected, int alpha) {
2111 int holes;
2112 int item_no;
2113 int i;
2114 float size;
2115 CTexture *texture;
2116 int u;
2117 int v;
2118 int volume;
2119
2120 holes = GetWeaponHoleNum(weapon->item_no);
2121
2122 if (holes <= 0) {
2123 return;
2124 }
2125
2126 for (i = 0; i < holes; i++) {
2127 item_no = weapon->attach[i].item_no;
2128
2129 if (item_no >= ITEM_ATTACH_START) {
2130 size = 32.0f;
2131 texture = RetCTex(item_no, u, v);
2132 CRect_i_ src(u, v, 32, 32);
2133 CRect_i_ dest(x, y, size, size);
2134 DrawMenu2DSprite(texture, dest, src, alpha);
2135 volume = GetAttachVolumeForMsg(&weapon->attach[i]);
2136
2137 if (item_no == ITEM_ATTACH_SYNTHESIS_SPHERE) {
2138 volume = weapon->attach[i].sphere_weapon_no;
2139 }
2140
2141 DrawAttachNumberOrWeapon(x, y, 0, 0x280, item_no, volume, alpha, 0);
2142 }
2143
2144 x += 42.0f;
2145 }
2146}
2147
2151int GetAtraTipNowHave(int tip_no, int georama_no) {
2152 int have;
2153 int i;
2154 int plot;
2155 int slot;
2156 int id;
2157 s16 *elem;
2158 SV_EDIT_PARTS_INFO *info;
2159 EDIT_PARTS_ATRA *atra;
2160
2161 have = 0;
2162
2163 if (tip_no < 0x28) {
2164 SV_EDIT_PARTS_INFO *plot_info = SaveData->GetEditPartsInfo(georama_no, tip_no);
2165
2166 if (plot_info != NULL && plot_info->obtained != 0) {
2167 have = 1;
2168 }
2169 } else {
2170 elem = SaveData->GetElemData(georama_no);
2171
2172 for (i = 0; i < 0x80; i++, elem++) {
2173 if (*elem == tip_no - 0x28) {
2174 have = 1;
2175 break;
2176 }
2177 }
2178
2179 if (have == 0) {
2180 for (plot = 0; plot < 0x18; plot++) {
2181 info = SaveData->GetEditPartsInfo(georama_no, plot);
2182 atra = GetEditAtraPartsData(georama_no, plot);
2183
2184 for (slot = 0; slot < 6; slot++) {
2185 EDIT_CHIP_ATTACH_DATA *element = atra->elements + slot;
2186 id = element->id;
2187
2188 if (id >= 0 && id == tip_no - 0x28 && info->element_enabled[slot] != 0) {
2189 have = 1;
2190 }
2191 }
2192 }
2193 }
2194 }
2195
2196 return have;
2197}
2198
2199int GetDispVolumeForFloat(float volume) {
2200 int whole;
2201 int shown;
2202
2203 whole = (int) volume;
2204 shown = whole;
2205
2206 if (volume - (float) whole > 0.0) {
2207 shown += 1;
2208 }
2209
2210 return shown;
2211}
2212
2216int InitItemPolygonView(int item_no, u_long128 *buffer) {
2217 char model_path[64];
2218 char texture_path[76];
2219 int size;
2220 u_long128 *texture_buffer;
2221
2222 if (item_no < ITEM_ATTACH_START || item_no >= ITEM_WEAPON_START) {
2223 return 0;
2224 }
2225
2226 BtGetItemNamePath(model_path, texture_path, item_no);
2227 StartReadBG();
2228 MDebugItemPolyViewFlag = 0;
2229 buffer = MenuCalcBufAlignment(buffer);
2230
2231 if (LoadFileBG(model_path, buffer, &size) == 0) {
2232 return 1;
2233 }
2234
2235 texture_buffer = buffer + (size >> 4) + 1;
2236 texture_buffer = MenuCalcBufAlignment(texture_buffer);
2237
2238 if (LoadFileBG(texture_path, texture_buffer, &size) == 0) {
2239 return 1;
2240 }
2241
2242 ItemPolyView = NULL;
2243 return 0;
2244}
2245
2247float menudebugpos[4] = {4.0f, 0.0f, 0.0f, 1.0f};
2248
2250float menudebugrot[3] = {0.0f, 0.0f, 0.0f};
2251
2253float menudebugrscale[3] = {3.0f, 3.0f, 3.0f};
2254
2258CDataAlloc2<1> MenuItemCashBuffer(-1);
2259
2267static int EnterItemPolygonView() {
2268 BG_READ_INFO *model;
2269 BG_READ_INFO *texture;
2270
2271 if (ReadBGSync() == 0 && polyreadflag == 0 && MDebugItemPolyViewFlag == 0) {
2272 LOADTEXTURE_INFO2 table[] = {
2273 {item_view_frame_image, 0, 0},
2274 {NULL, 0, 0},
2275 {NULL, 0, 0},
2276 };
2277 table[0].block_no = BtlMenuExReadBlock;
2278 table[1].block_no = BtlMenuExReadBlock;
2279 model = GetReadBGFile(0);
2280 texture = GetReadBGFile(1);
2281 table[1].name = (char *) texture->buffer;
2282 TexManager.DeleteTextureBlock(BtlMenuExReadBlock);
2283 TexManager.CleanUpTextureList();
2284 TexManager.LoadTextureBlockEX(-1, table);
2285
2286 if (model == NULL) {
2287 return 0;
2288 }
2289
2290 if (texture == NULL) {
2291 return 0;
2292 }
2293
2294 MenuItemCashBuffer.base = (u_char *) (texture->buffer + (texture->size >> 4) + 1);
2295 MenuItemCashBuffer.limit = 0x6080;
2296 MenuItemCashBuffer.Reset();
2297 MDebugItemPolyViewFlag = 1;
2298 ItemPolyView = (CFrame *) LoadMDSFile((u_int *) model->buffer, &MenuItemCashBuffer, 0, NULL, NULL);
2299 sceVu0FVECTOR position = {4.0f, 0.0f, 0.0f, 1.0f};
2300 float rotation[3] = {0.0f, 0.0f, 0.0f};
2301 float scale[3] = {3.0f, 3.0f, 3.0f};
2302 // Each copy moves a whole vector, one float more than the rotation and scale hold.
2303 memcpy(menudebugpos, position, sizeof(sceVu0FVECTOR));
2304 memcpy(menudebugrot, rotation, sizeof(sceVu0FVECTOR));
2305 memcpy(menudebugrscale, scale, sizeof(sceVu0FVECTOR));
2306 return 1;
2307 }
2308
2309 return 0;
2310}
2311
2319static void LocalDrawItemPolygonView() {
2320 float turn;
2321 float tilt;
2322 int i;
2323
2324 if (MDebugItemPolyViewFlag != 0 && ItemPolyView != NULL && polyreadflag != 0) {
2325 turn = GamePad.GetRXf();
2326 tilt = GamePad.GetRYf();
2327 menudebugrot[0] += tilt / 32.0f;
2328 menudebugrot[1] += turn / 32.0f;
2329
2330 for (i = 0; i < 3; i++) {
2331 if (menudebugrot[i] < -PI) {
2332 menudebugrot[i] += TWO_PI;
2333 }
2334
2335 if (menudebugrot[i] > PI) {
2336 menudebugrot[i] -= TWO_PI;
2337 }
2338 }
2339
2340 if (GamePad.Down2(PAD_CIRCLE)) {
2341 MDebugItemPolyViewFlag = 0;
2342 }
2343
2344 if (GamePad.On2(PAD_TRIANGLE)) {
2345 for (i = 0; i < 3; i++) {
2346 if (menudebugrscale[i] <= 5.0f) {
2347 menudebugrscale[i] += 0.1f;
2348 }
2349 }
2350 }
2351
2352 if (GamePad.On2(PAD_SQUARE)) {
2353 for (i = 0; i < 3; i++) {
2354 if (0.1f < menudebugrscale[i]) {
2355 menudebugrscale[i] -= 0.1f;
2356 }
2357 }
2358 }
2359
2360 ItemPolyView->SetRotation(menudebugrot[0], menudebugrot[1], menudebugrot[2]);
2361 ItemPolyView->SetScale(menudebugrscale);
2362 ItemPolyView->SetPosition(menudebugpos);
2363 MGDraw(ItemPolyView);
2364 }
2365}
2366
2367void DrawItemPolygonView() {
2368 MenuTextureReload(BtlMenuExReadBlock);
2369 MenuPolygonDraw(0x80, LocalDrawItemPolygonView);
2370}
2371
2372#ifdef PAL
2373extern CDebugFont MenuDbgMsg;
2374
2375void InitDebugItemGet() {
2376 ItemAutoGet.selection = 0x6A;
2377 ItemAutoGet.page = ItemAutoGet.selection >> 6;
2378 ItemAutoGet.show_model = 0;
2379 MenuDbgMsg.length = 0;
2380 MenuDbgMsg.texture_name = debug_item_font_texture;
2381 MenuDbgMsg.x = 0x15E;
2382 MenuDbgMsg.y = 0x50;
2383 MenuDbgMsg.width = 0x100;
2384 MenuDbgMsg.height = 0xE0;
2385 MenuDbgMsg.alpha = 0x60;
2386}
2387#endif
2388
2396static int ConvDebugSelectToExcelListNo(int selection) {
2397 int item_no;
2398
2399 item_no = selection + 0x81;
2400
2401 if ((item_no > ITEM_WEAPON_SCORPION) && (item_no < ITEM_WEAPON_SUPER_STEVE)) {
2402 return -1;
2403 }
2404
2405 if ((selection >= 0xF8) && (selection < 0x120)) {
2406 item_no = selection - 0xA7;
2407 }
2408
2409 return item_no;
2410}
2411
2412int DebugItemGetKey() {
2413 int result;
2414 int selection;
2415 int page;
2416 int item_no;
2417 WEAPON_DATA *data;
2418 int count;
2419
2420 result = 0;
2421 selection = ItemAutoGet.selection;
2422 page = ItemAutoGet.page;
2423
2424 if (GamePad.Down(PAD_UP)) {
2425 ItemAutoGet.selection -= 8;
2426 }
2427
2428 if (GamePad.Down(PAD_DOWN)) {
2429 ItemAutoGet.selection += 8;
2430 }
2431
2432 if (GamePad.Down(PAD_RIGHT)) {
2433 ItemAutoGet.selection += 1;
2434 }
2435
2436 if (GamePad.Down(PAD_LEFT)) {
2437 ItemAutoGet.selection -= 1;
2438 }
2439
2440 if (GamePad.Down(PAD_SELECT)) {
2441 if (ItemAutoGet.show_model) {
2442 ItemAutoGet.show_model = 0;
2443 } else {
2444 ItemAutoGet.show_model = 1;
2445 }
2446
2447 polyreadflag = InitItemPolygonView(ConvDebugSelectToExcelListNo(ItemAutoGet.selection), BtlMenuReadBuf);
2448 }
2449
2450 if (GamePad.Down(PAD_L2 | PAD_L1)) {
2451 ItemAutoGet.selection -= 0x40;
2452 }
2453
2454 if (GamePad.Down(PAD_R2 | PAD_R1)) {
2455 ItemAutoGet.selection += 0x40;
2456 }
2457
2458 if (ItemAutoGet.selection < 0) {
2459 ItemAutoGet.selection += 0x140;
2460 }
2461
2462 if (ItemAutoGet.selection > 0x13F) {
2463 ItemAutoGet.selection -= 0x140;
2464 }
2465
2466 ItemAutoGet.page = ItemAutoGet.selection >> 6;
2467
2468 if (selection != ItemAutoGet.selection || page != ItemAutoGet.page) {
2469 ComMenuSePlay(MENU_SOUND_CURSOR);
2470 }
2471
2472 if (GamePad.Down(PAD_CROSS)) {
2473 ComMenuSePlay(MENU_SOUND_CONFIRM);
2474 count = rand() % 3 + 1;
2475 BtlMenuStatusPt->GetItem(ConvDebugSelectToExcelListNo(ItemAutoGet.selection), count);
2476 }
2477
2478 if (GamePad.Down(PAD_CIRCLE)) {
2479 result = -1;
2480 CommonMenuMes2.mes_made = result;
2481 ComMenuSePlay(MENU_SOUND_REFUSE);
2482 }
2483
2484 if (GamePad.Down2(PAD_CROSS)) {
2485 for (item_no = ITEM_WEAPON_START; item_no < ITEM_WEAPON_END; item_no++) {
2486 data = GetWeaponData(item_no);
2487
2488 if (data != NULL && data->flags != 0 && data->flags != 1) {
2489 BtlMenuStatusPt->GetItem(item_no, 0);
2490 }
2491 }
2492
2493 ComMenuSePlay(MENU_SOUND_CONFIRM);
2494 }
2495
2496 return result;
2497}
2498
2499void DebugItemGetDraw() {
2500 CTexture *sheets[5] = {ItemIcon, ItemIcon, WepIcon, WepIcon, WepIcon};
2501 int sheet_y[5] = {0, 0x100, 0, 0x100, 0x200};
2502 CTexture *sheet = sheets[ItemAutoGet.page];
2503 int y = sheet_y[ItemAutoGet.page];
2504 int height = 0x100;
2505
2506 if (ItemAutoGet.page == 4) {
2507 height = 0x80;
2508 }
2509
2510 if (sheet != NULL) {
2511 MenuTextureReload(sheet->block);
2512 }
2513
2514 MGFillBox(CRect_i_(0x460, 0x280, 0x1000, 0x800), 0, 0, 0, 0x60);
2515 DrawMenu2DSprite(sheet, CRect_i_(0x46, 0x50, 0x100, height), CRect_i_(0, y, 0x100, height), 0x80);
2516 int item_no = ConvDebugSelectToExcelListNo(ItemAutoGet.selection);
2517
2518 if (ItemAutoGet.show_model) {
2519 DrawItemDataView(item_no);
2520 }
2521
2522 int cell = ItemAutoGet.selection - ItemAutoGet.page * 64;
2523 DrawMenuObjectVibe((cell % 8) * 32 + 0x2E, (cell / 8) * 32 + 0x50, 1, 0x40);
2524 COM_ITEM_INFO *info = GetCommonItemInfo(item_no);
2525
2526 if (info != NULL) {
2527 int message = info->msg + 500;
2528
2529 if (CommonMenuMes2.mes_made != message) {
2530 CommonMenuMes2.MakeMesWin(message);
2531 }
2532 }
2533}
2534
2538CDebugFont MenuDbgMsg;
2539
2540ITEM_AUTO_GET ItemAutoGet;
2541
2542// clang-format off
2546char *ItemTemplete[8] = {
2547 item_templete_no, item_templete_type, item_templete_use, item_templete_attribute,
2548 item_templete_name_index, item_templete_help_index, item_templete_volume, item_templete_gold,
2549};
2550// clang-format on
2551
2552static void DrawItemDataView(int item_no) {
2553 int block;
2554
2555 switch (BtlMenuMode) {
2556 case BATTLE_MENU_MODE_DUNGEON:
2557 block = 0xC;
2558 break;
2559 case BATTLE_MENU_MODE_TOWN:
2560 block = 0x1F;
2561 break;
2562 }
2563
2564 MenuTextureReload(block);
2565 int line = 0;
2566 char type[128] = "";
2567
2568 if (0 <= item_no && item_no < ITEM_ATTACH_START) {
2569 return;
2570 }
2571
2572 // The attachment index computed here goes unused.
2573 if (item_no >= ITEM_ATTACH_START && item_no < ITEM_DUNGEON_END) {
2574 int index = item_no - ITEM_ATTACH_START;
2575
2576 if (index < 0) {
2577 index = 0;
2578 }
2579 }
2580
2581 if (MDebugItemPolyViewFlag == 0) {
2582 MenuDbgMsg.length += sprintf(&MenuDbgMsg.text[MenuDbgMsg.length], "-----ItemData View-----\n");
2583 MenuDbgMsg.length += sprintf(&MenuDbgMsg.text[MenuDbgMsg.length], ItemTemplete[line++], item_no);
2584 MenuDbgMsg.length += sprintf(&MenuDbgMsg.text[MenuDbgMsg.length], ItemTemplete[line], type);
2585 type[0] = '\0';
2586 }
2587
2588 if (GamePad.Down(PAD_TRIANGLE)) {
2589 polyreadflag = InitItemPolygonView(ConvDebugSelectToExcelListNo(ItemAutoGet.selection), BtlMenuReadBuf);
2590 }
2591
2592 if (polyreadflag == 0) {
2593 polyreadflag = EnterItemPolygonView();
2594 }
2595
2596 if (polyreadflag != 0) {
2597 DrawItemPolygonView();
2598 }
2599}
CMainItemModel * models
char * texture_name
Definition gameloop.cpp:164
char text[0x200]
Definition gameloop.cpp:167
s16 ChkKills(int georama_no, int floor)
int GetItem(int item_id, int qty)
int LostItem(int item_id)
int GetAtraNum(int georama_no, int floor)
int GetMaxAtraNum(int georama_no, int floor)
s32 GetActiveCharaStatus(int chara_no)
int On2(int mask)
Definition gamepad.cpp:575
int Down2(int mask)
Definition gamepad.cpp:601
float GetRYf()
Definition gamepad.cpp:537
int Down(int mask)
Definition gamepad.cpp:583
void MenuModeOff()
Definition gamepad.cpp:617
void MenuModeOn(int threshold)
Definition gamepad.cpp:613
void SetAutoRepeat(int mask, int initial_delay, int repeat_delay)
Definition gamepad.cpp:485
float GetRXf()
Definition gamepad.cpp:533
void AutoRepeatOff()
Definition gamepad.cpp:609
void DeleteModel(int model_no)
int SetCashModel(int item_no, unsigned int *model_data, unsigned int *texture_data, int texture_size)
void CheckItemVolume()
void LoopStep(int interval)
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
int QuestDungeon(int dungeon_no, int add)
Definition savedata.cpp:535
s16 * GetElemData(int georama_no)
Definition savedata.cpp:242
SV_EDIT_PARTS_INFO * GetEditPartsInfo(int georama_no, int plot_no)
Definition savedata.cpp:183
short block
Definition texture.hpp:52
ITEM_PACK item_pack
DNG_CONSUMABLE consumable_items[43]
s8 floor_reached[7]
WEAPON_HAVE chara_weapons[6][11]
s8 equipped_weapon_slot[6]
s32 res_limit_zone_current
s32 auto_pos
Definition clsmes.hpp:172
s32 text_y
Definition clsmes.hpp:152
s32 text_x
Definition clsmes.hpp:151
void DrawMesWin()
Definition clsmes.cpp:2619
void Step()
Definition clsmes.cpp:575
s32 char_width
Definition clsmes.hpp:153
s32 mes_made
Definition clsmes.hpp:207
s32 tex_block
Definition clsmes.hpp:227
s32 stay_frame
Definition clsmes.hpp:189
s32 edge_alpha
Definition clsmes.hpp:213
MES_LINE_POS line_pos[10]
Definition clsmes.hpp:228
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
void Preset(int style)
Definition clsmes.cpp:468
s16 sphere_weapon_no
Definition itemdata.hpp:592
s8 vs_monster[10]
Definition itemdata.hpp:598
s16 status[4]
Definition itemdata.hpp:596
u_long128 * buffer
Definition dataread.hpp:29
float ring_pos[6][2]
s8 collected_atra[100]
EDIT_CHIP_ATTACH_DATA elements[6]
s16 quick_item_slot[3]
Definition title.cpp:61
s32 width
Definition rect.hpp:36
s32 height
Definition rect.hpp:37
int y
Definition title.cpp:63
int x
Definition title.cpp:62
char vs_monster[10]
Definition itemdata.hpp:699
ATTACH_LIST attach[6]
Definition itemdata.hpp:701
s8 attach_kind[6]
Definition itemdata.hpp:702