DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
menu_misc.cpp
1#pragma name_counter 2
2
3#include "menu_misc.hpp"
4
5#include <cstdio>
6#include <cstdlib>
7#include <cstring>
8
9#include "battlemenu.hpp"
10#include "bt_shot_effect.hpp"
11#include "btactstatus.hpp"
12#include "btmisc.hpp"
13#include "character.hpp"
14#include "clsmes.hpp"
15#include "dataalloc.hpp"
16#include "dataread.hpp"
17#include "dngstatusdata.hpp"
18#include "dun/gameloop.hpp"
19#include "editloop.hpp"
20#include "frame.hpp"
21#include "gamepad.hpp"
22#include "itemdata.hpp"
23#include "mainselect.hpp"
24#include "memcard.hpp"
25#include "menu_draw.hpp"
26#include "menu_dungeon.hpp"
27#include "menu_inventory.hpp"
28#include "menu_manual.hpp"
29#include "menuitemstep.hpp"
30#include "mglib.hpp"
31#include "rect.hpp"
32#include "savedata.hpp"
33#include "shot_effect.hpp"
34#include "snd.hpp"
35#include "texture.hpp"
36#include "userstatus.hpp"
37#include "weapon_buildup.hpp"
38#include "weaponeffect.hpp"
39#include "weaponlevelup.hpp"
40
41static 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};
42
43int MenuWeaponModelData[42];
44int MenuWeaponModelInfo[10][2];
45float MenuCharaOldAmbient[4];
46char MenureadFile[64];
47
48int MenuItemUseVolume;
49u_long128 *WeaponRead_Buf;
50s16 MenuCharaEffectReadFlag;
51s16 MenuCharaOldEffect;
52BT_SHOT_EFFECT *WepEffectMenuPt;
53u_long128 *WepEffectMenuReadBuf;
54u_long128 *MenuWeaponModelBuildBuffer;
55int CharaFileBGReadNo;
56s16 charachangeid;
57u_long128 *CharaChangeBaseBuf;
58u_long128 *menucharReadbuf;
59u_long128 *menud0wepReadBuf;
60u_long128 *menud1wepReadBuf;
61u_long128 *menud2wepReadBuf;
62u_long128 *MenuWepIconCharaChangePtr;
63u_long128 *MenuVoiceLoadPtr;
64ClsMes *CharaNameMes;
65ClsMes *DngMenuMes;
66s16 CharaNameDrawFlag;
67s16 CharaNameDrawCase;
68CTexture *DngEscapeTex;
69s16 DngEscapeBlock;
70s16 DngEscapeEndFlag;
71
73int MenuWeaponTestCase = 1;
74
76s16 DngEscapeAlpha = 0x80;
77
81s16 DngEscapeSelect = 1;
82
90int NowGetGameFlagForBtlMenu(int game_flag) {
91 switch (game_flag) {
92 case MENU_MOVE_DUNGEON_ESCAPE:
93 break;
94 case MENU_MOVE_WORLD_MAP_DIRECT:
95 case MENU_MOVE_WORLD_MAP:
96 if (EdInteriorFlag == 1) {
97 game_flag = MENU_MOVE_INTERIOR_OUT;
98 } else if (BtlMenuStatusPt->special_flag_238 == 0) {
99 if (SaveData->QuestDungeon(0, 0) == 0) {
100 game_flag = MENU_MOVE_LOCKED;
101 } else if (BtlMenuStatusPt->special_flag_238 == 0) {
102 game_flag = MENU_MOVE_FIRST_DUNGEON;
103 }
104 }
105
106 break;
107 }
108
109 return game_flag;
110}
111
112int GetMenuHebikiriFlag() {
113 return SaveData->GetGameFlag(0x30);
114}
115
123void EquipDefaultWeapon(int chara_no) {
124 CDngStatusData *status = SaveData->GetDngStatus();
125 WEAPON_HAVE *weapons = status->chara_weapons[chara_no];
126 int default_weapon_no = GetDefaultWeaponNo(chara_no);
127
128 for (int slot = 0; slot < 10; slot++) {
129 if (weapons[slot].item_no == default_weapon_no || weapons[slot].item_no == default_weapon_no + 1) {
130 status->equipped_weapon_slot[chara_no] = slot;
131 break;
132 }
133 }
134}
135
143void DrawMenuNothing(int x, int y, int width, int height, char *name, int custom, int alpha) {
144 CTexture *texture = TexManager.GetTexture(name, -1);
145 int inner_w = width - 0x24;
146 int inner_h = height - 0x24;
147 int u;
148 int v;
149
150 switch (custom) {
151 case 0:
152 u = 0xD4;
153 v = 0x159;
154 break;
155 }
156
157 DrawMenu2DSprite(texture, CRect_i_(x, y, 0x12, 0x12), CRect_i_(u, v, 0x12, 0x12), alpha);
158 DrawMenu2DSprite(texture, CRect_i_(x + 0x12, y, inner_w, 0x12), CRect_i_(u + 0x10, v, 4, 0x12), alpha);
159 DrawMenu2DSprite(texture, CRect_i_(x + 0x12 + inner_w, y, 0x12, 0x12), CRect_i_(u + 0x12, v, 0x12, 0x12), alpha);
160 DrawMenu2DSprite(texture, CRect_i_(x, y + 0x12, 0x12, inner_h), CRect_i_(u, v + 0xE, 0x12, 4), alpha);
161 DrawMenu2DSprite(texture, CRect_i_(x + 0x12 + inner_w, y + 0x12, 0x12, inner_h), CRect_i_(u + 0x12, v + 0xE, 0x12, 4), alpha);
162 DrawMenu2DSprite(texture, CRect_i_(x, y + 0x12 + inner_h, 0x12, 0x12), CRect_i_(u, v + 0x12, 0x12, 0x12), alpha);
163 DrawMenu2DSprite(texture, CRect_i_(x + 0x12, y + 0x12 + inner_h, inner_w, 0x12), CRect_i_(u + 0x10, v + 0x12, 4, 0x12), alpha);
164 DrawMenu2DSprite(texture, CRect_i_(x + 0x12 + inner_w, y + 0x12 + inner_h, 0x12, 0x12), CRect_i_(u + 0x12, v + 0x12, 0x12, 0x12), alpha);
165 DrawMenu2DSprite(texture, CRect_i_(x - 0x33 + (inner_w >> 1), y - 1 + (inner_h >> 1), 0x86, 0x22), CRect_i_(0xFA, 0x1D2, 0x86, 0x22), alpha);
166}
167
168int GetMenuItemUseVolume() {
169 return MenuItemUseVolume;
170}
171
172int ItemUseFunc(CUserStatus *status, int item_no, int chara, int target, WEAPON_HAVE *weapon) {
173 int used = 0;
174 WEAPON_HAVE level_up;
175
176 MenuItemUseVolume = 0;
177 int now_hp = status->hp[chara];
178 int max_hp = status->max_hp[chara];
179 int now_water = (int) status->water_now[chara];
180 float max_water = status->water_max[chara];
181 int old_condition = status->ailments[chara];
182 printf("trueNo = %d\n", item_no);
183 int value_no = 0;
184 ITEM_DATA *data = GetItemData(item_no);
185
186 if (data == NULL) {
187 return 0;
188 }
189
190 if ((data->kind_flags & ITEMKINDF_CONSUMABLE) && target == ITEM_USE_ON_CHARA) {
191 if (item_no != ITEM_MELLOW_BANANA) {
192 if ((data->use_flags & ITEMUSE_HEAL_HP) && 0 < now_hp && now_hp < max_hp) {
193 int add = (&data->vol)[value_no];
194 value_no++;
195 status->SetNextLife(chara, now_hp + add, 5.0f);
196 used = 1;
197 }
198
199 if ((data->use_flags & ITEMUSE_DRINK) && 2.0f + now_water < max_water) {
200 int add = (&data->vol)[value_no];
201 value_no++;
202 float limit;
203 float next = status->water_now[chara];
204 limit = status->water_max[chara];
205 next += add;
206
207 if (limit < next) {
208 next = limit;
209 }
210
211 status->water_now[chara] = next;
212 used = 1;
213 }
214 } else if (now_hp > 0 && now_hp < max_hp) {
215 value_no++;
216 status->SetNextLife(chara, now_hp + 200, 5.0f);
217 status->AddDrink(chara, -20, 1.0f);
218 used = 1;
219 }
220 }
221
222 if ((data->kind_flags & ITEMKINDF_RANDOM) && (data->use_flags & ITEMUSE_STATUS) && item_no >= ITEM_FLUFFY_DOUGHNUT && item_no < ITEM_DUMMY) {
223 if (chara == item_no - ITEM_FLUFFY_DOUGHNUT) {
224 int old = status->defense[chara];
225 int range = data->vol_range;
226
227 if (range <= 0) {
228 printf("value=0\n");
229 range = 1;
230 }
231
232 int add = data->vol + rand() % range;
233 MenuItemUseVolume = add;
234 old += add;
235
236 if (old >= 99) {
237 old = 99;
238 }
239
240 status->defense[chara] = old;
241 used = 1;
242 } else {
243 used = 0;
244 }
245 }
246
247 if (data->kind_flags & 1) {
248 if (target == ITEM_USE_ON_CHARA) {
249 if (data->use_flags & ITEMUSE_STATUS) {
250 switch (item_no) {
251 case ITEM_POCKET: {
252 int i;
253 int num;
254 ITEM_PACK *pack = &status->item_pack;
255 num = pack->num;
256
257 if (num < 0x60) {
258 pack->num += (&data->vol)[value_no];
259 MenuItemUseVolume = pack->num;
260
261 if (pack->num > 100) {
262 pack->num = 100;
263 }
264
265 for (i = num; i < pack->num; i++) {
266 if (pack->item[i] < ITEM_DUNGEON_START) {
267 pack->item[i] = -1;
268 }
269 }
270
271 used = 1;
272 }
273
274 break;
275 }
276 case ITEM_FRUIT_OF_EDEN: {
277 s16 limit[6] = {0xAA, 0x8C, 0xAA, 0x8C, 0xB4, 0xA0};
278
279 if ((old_condition & AILMENT_KNOCKED_OUT) || now_hp <= 0 || !((s16) max_hp < limit[chara])) {
280 used = 0;
281 } else {
282 status->max_hp[chara] = max_hp + (&data->vol)[value_no];
283 s16 next = status->max_hp[chara];
284
285 if (next >= limit[chara]) {
286 next = limit[chara];
287 status->max_hp[chara] = limit[chara];
288 }
289
290 status->SetNextLife(chara, next, 0.0f);
291 used = 1;
292 }
293
294 break;
295 }
296 case ITEM_GOURD:
297 if (max_water <= 90.0f) {
298 float next = max_water + (&data->vol)[value_no];
299 status->water_max[chara] = next;
300 status->water_now[chara] = next;
301 used = 1;
302 }
303
304 break;
305 }
306 }
307
308 printf("prev status = %d\n", old_condition);
309 u32 flags = data->use_flags;
310
311 if ((old_condition & AILMENT_KNOCKED_OUT) || now_hp <= 0) {
312 if (item_no == ITEM_REVIVAL_POWDER) {
313 status->ailments[chara] = 0;
314 status->hp[chara] = max_hp >> 1;
315 used = 1;
316 }
317 } else {
318 if ((flags & 0x4000) && (old_condition & AILMENT_FREEZE)) {
319 status->ailments[chara] ^= AILMENT_FREEZE;
320 used = 1;
321 }
322
323 if ((data->use_flags & 0x8000) && (old_condition & AILMENT_POISON)) {
324 status->ailments[chara] ^= AILMENT_POISON;
325 used = 1;
326 }
327
328 if ((data->use_flags & 0x10000) && (old_condition & AILMENT_CURSE)) {
329 status->ailments[chara] ^= AILMENT_CURSE;
330 used = 1;
331 }
332
333 if ((data->use_flags & 0x20000) && (old_condition & AILMENT_GOO)) {
334 status->ailments[chara] ^= AILMENT_GOO;
335 used = 1;
336 }
337
338 if (item_no == ITEM_MIGHTY_HEALING && (old_condition & (AILMENT_FREEZE | AILMENT_POISON | AILMENT_CURSE | AILMENT_GOO))) {
339 if (status->ailments[chara] & AILMENT_STAMINA) {
340 status->ailments[chara] = 0;
341 status->ailments[chara] |= AILMENT_STAMINA;
342 } else {
343 status->ailments[chara] = 0;
344 }
345
346 used = 1;
347 }
348
349 if (BtlMenuMode == BATTLE_MENU_MODE_DUNGEON && (data->use_flags & 0x1000)) {
350 int now = status->ailments[chara];
351
352 if (!(now & AILMENT_FREEZE)) {
353 status->ailments[chara] = now | AILMENT_STAMINA;
354 status->ailment_frames[chara] = 0x708;
355 used = 1;
356 }
357 }
358 }
359 }
360
361 if (target == ITEM_USE_ON_BOARD_WEAPON || target == ITEM_USE_ON_EQUIP_WEAPON) {
362 if (weapon == NULL) {
363 return used;
364 }
365
366 int default_no = GetDefaultWeaponNo(chara);
367
368 if (item_no == ITEM_REPAIR_POWDER) {
369 if (weapon->durability_f < weapon->durability) {
370 weapon->durability_f = weapon->durability;
371 int weapon_no = weapon->item_no;
372
373 if (weapon_no == default_no) {
374 weapon->item_no = weapon_no + 1;
375 WepDataListToHaveCopy(weapon->item_no, weapon);
376 }
377
378 used = 2;
379 }
380 }
381
382 if (item_no == ITEM_POWERUP_POWDER) {
383 if (weapon->item_no == ITEM_WEAPON_SERPENT_SWORD && GetMenuHebikiriFlag() == 0) {
384 return 0;
385 }
386
387 if (weapon->level >= 99) {
388 return 0;
389 }
390
391 if (weapon->item_no != default_no) {
392 int exp = weapon->experience;
393
394 if (exp < GetWeaponMaxExp(weapon)) {
395 WeaponLevelUpValueCalc(weapon, &level_up, 1, 0);
396 memcpy(weapon, &level_up, sizeof(WEAPON_HAVE));
397 weapon->level++;
398 memset(weapon->attach, 0, sizeof(weapon->attach));
399 used = 1;
400 }
401 }
402 }
403 }
404 }
405
406 if (BtlMenuMode == BATTLE_MENU_MODE_DUNGEON && !(old_condition & AILMENT_KNOCKED_OUT) && now_hp > 0 && (data->kind_flags & 2) && target == ITEM_USE_ON_CHARA) {
407 int before = status->ailments[chara];
408
409 if (data->use_flags & 0x100) {
410 if (old_condition & AILMENT_FREEZE) {
411 status->ailments[chara] = before ^ AILMENT_FREEZE;
412 } else {
413 status->ailments[chara] = before | AILMENT_FREEZE;
414 status->ailments[chara] &= ~(AILMENT_STAMINA | AILMENT_POISON | AILMENT_GOO);
415 status->ailment_frames[chara] = 300;
416 }
417
418 ComMenuSePlay(SE_STATUS_AILMENT);
419 }
420
421 if (data->use_flags & 0x200) {
422 int now = status->ailments[chara];
423
424 if (!(now & (AILMENT_FREEZE | AILMENT_STAMINA))) {
425 status->ailments[chara] = now | AILMENT_POISON;
426 status->ailments[chara] &= ~AILMENT_GOO;
427 ComMenuSePlay(SE_STATUS_AILMENT);
428 }
429 }
430
431 if (data->use_flags & 0x400) {
432 status->ailments[chara] |= AILMENT_CURSE;
433 ComMenuSePlay(SE_STATUS_AILMENT);
434 }
435
436 if (data->use_flags & 0x800) {
437 int now = status->ailments[chara];
438
439 if (!(now & (AILMENT_FREEZE | AILMENT_STAMINA | AILMENT_POISON))) {
440 status->ailments[chara] = now | AILMENT_GOO;
441 ComMenuSePlay(SE_STATUS_AILMENT);
442 }
443 }
444
445 if (before != status->ailments[chara]) {
446 used = 1;
447 }
448 }
449
450 return used;
451}
452
460float GetNowWeaponRate(WEAPON_HAVE *weapon) {
461 float rate = 1.0f;
462
463 if (weapon != NULL && weapon->item_no == ITEM_WEAPON_LAMB_S_SWORD && weapon->durability_f <= 0.2f * weapon->durability) {
464 rate = 1.5f;
465 }
466
467 return rate;
468}
469
470int WeaponStatusBreakEnable(WEAPON_HAVE *weapon) {
471 int enable;
472
473 if (weapon == NULL) {
474 return 0;
475 }
476
477 enable = false;
478
479 if (weapon->level >= 5) {
480 enable = true;
481 }
482
483 return enable;
484}
485
493int WeaponStatusBuildUp(WEAPON_HAVE *weapon, int &enabled_count) {
494 if (weapon == NULL) {
495 return 0;
496 }
497
498 WEP_BUILDUP_INFO build_info[8];
499 EnableBuildUpModel(build_info, weapon);
500
501 int total = 0;
502
503 while (build_info[total].weapon_no != -1 && total < 5) {
504 total++;
505 }
506
507 for (int i = 0; i < total; i++) {
508 if (build_info[i].enabled == 1) {
509 enabled_count++;
510 }
511 }
512
513 return total;
514}
515
516void MenuWeaponSpSet(CCharacter *chara, WEAPON_HAVE *weapon) {
517 if (chara == NULL || weapon == NULL) {
518 return;
519 }
520
521 if (weapon->item_no != ITEM_WEAPON_LAMB_S_SWORD) {
522 return;
523 }
524
525 CFrame *whole = chara->frame->SearchFrame("w15a");
526 CFrame *broken = chara->frame->SearchFrame("w15b");
527
528 if (whole == NULL || broken == NULL) {
529 return;
530 }
531
532 int show_broken;
533 int show_whole;
534
535 if (weapon->durability_f <= 0.2 * weapon->durability) {
536 show_broken = 1;
537 show_whole = 2;
538 } else {
539 show_broken = 2;
540 show_whole = 1;
541 }
542
543 whole->attr.draw_on = show_whole;
544 broken->attr.draw_on = show_broken;
545}
546
547void SetMenuCharaEffectReadFlag(int flag) {
548 MenuCharaEffectReadFlag = flag;
549}
550
551int GetMenuCharaEffectReadFlag() {
552 return MenuCharaEffectReadFlag;
553}
554
555BT_SHOT_EFFECT *GetDngWepEffectPointer() {
556 return WepEffectMenuPt;
557}
558
559u_long128 *GetWepEffectMenuReadBuf() {
560 return WepEffectMenuReadBuf;
561}
562
563void SetOldEffectKind(int kind) {
564 MenuCharaOldEffect = kind;
565}
566
574static void SetWepEffectMenuReadBuf(u_long128 *buffer) {
575 WepEffectMenuReadBuf = buffer;
576}
577
578BT_SHOT_EFFECT *DngWepEffectReadStart() {
579 char path[64];
580 int size;
581 CUserStatus *status = (CUserStatus *) BtlMenuStatusPt;
582 int chara = status->cur_chara;
583 int slot = status->equipped_weapon_slot[chara];
584 WEAPON_HAVE *weapons = status->chara_weapons[chara];
585 WEAPON_HAVE *equipped = &weapons[slot];
586
587 WepEffectMenuPt = Get_Main_EffectPtr(chara, equipped->best_elem);
588 sprintf(path, "dun/mainchara/wep_eff/%s.chr", WepEffectMenuPt);
589 WepEffectMenuReadBuf = GetWepEffectMenuReadBuf();
590 WepEffectMenuReadBuf = MenuCalcBufAlignment(WepEffectMenuReadBuf);
591 LoadFileBG(path, (u_long128 *) WepEffectMenuReadBuf, &size);
592 SetMenuCharaEffectReadFlag(1);
593 return GetDngWepEffectPointer();
594}
595
596void MenuWeaponEffectSet(int effect_no) {
597 SetMenuCharaEffectReadFlag(0);
598 MainChara_Effect((BT_SHOT_EFFECT *) WepEffectMenuPt, (unsigned int *) WepEffectMenuReadBuf, effect_no);
599}
600
601int GetNowTestNo() {
602 return MenuWeaponTestCase;
603}
604
605int StartReadWepMDS(u_long128 *buffer, int chara) {
606 if (ReadBGSync() == 1) {
607 BreakReadBG();
608 }
609
610 char path[64] = "commenu/c";
611 char *numbers[6] = {"01", "04", "06", "05", "10", "18"};
612 char image[64];
613 int size;
614
615 strcat(path, numbers[chara]);
616 strcat(path, "wtes.chr");
617 WeaponRead_Buf = MenuCalcBufAlignment(buffer);
618 StartReadBG();
619
620 if (LoadFileBG(path, buffer, &size) == 0) {
621 return 0;
622 }
623
624 buffer += (size >> 4) + 1;
625 buffer = MenuCalcBufAlignment(buffer);
626 GetPathReadDifferntLang(image);
627 char *names[6] = {"kgetoan", "kgesyao", "kgegoro", "kgeruby", "kgeunga", "kgeozu"};
628 strcat(image, names[chara]);
629 strcat(image, "2.img");
630
631 if (LoadFileBG(image, buffer, &size) == 0) {
632 return 0;
633 }
634
635 if (BtlMenuMode == BATTLE_MENU_MODE_DUNGEON) {
636 buffer += (size >> 4) + 1;
637 SetWepEffectMenuReadBuf(buffer);
638 DngWepEffectReadStart();
639 }
640
641 return 1;
642}
643
651static int *GetMenuWeaponModelData(int index) {
652 return &MenuWeaponModelData[index];
653}
654
662static void InitMenuWeaponModelData() {
663 memset(MenuWeaponModelData, 0, sizeof(MenuWeaponModelData));
664}
665
673static int *GetMenuWeaponModelInfo(int index) {
674 return MenuWeaponModelInfo[index];
675}
676
677void InitMenuWeaponModelReference() {
678 for (int i = 0; i < 12; i++) {
679 int *entry = GetMenuWeaponModelInfo(i);
680 entry[0] = -1;
681 entry[1] = -1;
682 }
683}
684
685void SetMenuWeaponModelReference(int index, int frame_no, int value) {
686 int *entry = GetMenuWeaponModelInfo(index);
687 entry[0] = frame_no;
688 entry[1] = value;
689}
690
691int GetMenuWeaponModelFrameNo(int index) {
692 return MenuWeaponModelInfo[index][0];
693}
694
702int EnterWeaponModel(int chara, int texture_block, int weapon_slot) {
703 BG_READ_INFO *pack = GetReadBGFile(0);
704 BG_READ_INFO *shadow = GetReadBGFile(1);
705 BG_READ_INFO *effect = GetReadBGFile(2);
706 // Built and indexed but never read.
707 char *shadows[6] = {"kagetoan", "kagesyao", "kagegoro", "kageruby", "kageunga", "kageozu"};
708 char *shadow_name = shadows[chara];
709 s16 weapon_max = MenuCharaWeaponMax[chara];
710 char *names[6] = {"c01", "c04", "c06", "c05", "c10", "c18"};
711 char order[42];
712 char image[32];
713 char model[32];
714 char chr[32];
715
716 switch (GetNowTestNo()) {
717 case 0:
718 break;
719 case 1: {
720 LOADTEXTURE_INFO2 texture[3] = {
721 {"#frame_menuwep_dmy#640#" SCREEN_HEIGHT_STR "#4", 0, 0},
722 {NULL, 0, 0},
723 {NULL, 0, 0},
724 };
725 texture[0].block_no = MenuShadowReadBlock;
726 texture[1].block_no = MenuShadowReadBlock;
727 texture[1].name = (char *) shadow->buffer;
728 TexManager.DeleteTextureBlock(MenuShadowReadBlock);
729 TexManager.CleanUpTextureList();
730 TexManager.LoadTextureBlockEX(-1, texture);
731 WepIcon = TexManager.GetTexture("wepicon", MenuShadowReadBlock);
732
733 for (int i = 0; i < weapon_max; i++) {
734 order[i] = i;
735 }
736
737 InitMenuWeaponModelData();
738
739 for (int i = 0; i < weapon_max; i++) {
740 char *name = names[chara];
741 strcpy(image, name);
742 strcpy(model, name);
743 strcpy(chr, name);
744 int weapon_no = order[i];
745
746 if (0 <= weapon_no && weapon_no <= 9) {
747 strcat(chr, "w0%d");
748 sprintf(chr, chr, weapon_no);
749 strcat(image, "w0%d");
750 sprintf(image, image, weapon_no);
751 strcat(model, "w0%d");
752 sprintf(model, model, weapon_no);
753 } else if (weapon_no >= 10) {
754 strcat(chr, "w%d");
755 sprintf(chr, chr, weapon_no);
756 strcat(image, "w%d");
757 sprintf(image, image, weapon_no);
758 strcat(model, "w%d");
759 sprintf(model, model, weapon_no);
760 } else {
761 strcat(chr, "w01");
762 strcat(image, "w01");
763 strcat(model, "w01d");
764 }
765
766 strcat(chr, ".chr");
767 strcat(image, ".img");
768 strcat(model, ".mds");
769 u_int *file = GetPackFile((u_int *) pack->buffer, chr, NULL);
770
771 if (file != NULL) {
772 *GetMenuWeaponModelData(i) = (int) file;
773 }
774 }
775
776 u_long128 *build;
777
778 if (effect != NULL) {
779 SetWepEffectMenuReadBuf(effect->buffer);
780 build = effect->buffer + 0x2D01;
781 } else {
782 build = shadow->buffer + (shadow->size >> 4) + 1;
783 }
784
785 MenuWeaponModelBuildBuffer = build;
786 WeaponModelBuildFunc(chara, texture_block);
787 break;
788 }
789 }
790
791 return 1;
792}
793
794void WeaponModelBuildFunc(int chara, int texture_block) {
795 printf("weapon model build func start\n");
796 InitMenuWeaponModelReference();
797 LOADTEXTURE_INFO2 textures[] = {
798 {(char *) "#frame_menuwep#640#" SCREEN_HEIGHT_STR "#4", texture_block, 0},
799 {NULL, 0, 0},
800 };
801 char name[32];
802 char cfg[32];
803 TexManager.DeleteTextureBlock(texture_block);
804 TexManager.CleanUpTextureList();
805 TexManager.LoadTextureBlockEX(-1, textures);
806 printf("modelbuildbuffer = %p\n", MenuWeaponModelBuildBuffer);
807 MenuExCashBuffer.base = (u_char *) MenuWeaponModelBuildBuffer;
808 MenuExCashBuffer.limit = 0xEC00;
809 MenuExCashBuffer.used = 0;
810 int default_no;
811 WEAPON_HAVE *weapons = ((CUserStatus *) BtlMenuStatusPt)->chara_weapons[chara];
812 default_no = GetDefaultWeaponNo(chara);
813 int next = 2;
814 u_int **data = (u_int **) GetMenuWeaponModelData(0);
815 BtGetWeaponNamePath2(name, cfg, chara, 0);
816 DngWeaponFrm[0].LoadPackData3(*data, cfg, &MenuExCashBuffer, texture_block, &MenuExCashBuffer, 1, 0);
817 data = (u_int **) GetMenuWeaponModelData(1);
818 BtGetWeaponNamePath2(name, cfg, chara, 1);
819 DngWeaponFrm[1].LoadPackData3(*data, cfg, &MenuExCashBuffer, texture_block, &MenuExCashBuffer, 1, 0);
820
821 for (int i = 0; i < 10; i++) {
822 WEAPON_HAVE *weapon = &weapons[i];
823
824 if (weapon == NULL) {
825 SetMenuWeaponModelReference(i, -2, -1);
826 continue;
827 }
828
829 int item_no = weapon->item_no;
830
831 if (item_no < ITEM_WEAPON_START) {
832 SetMenuWeaponModelReference(i, -2, -1);
833 continue;
834 }
835
836 unsigned int kind = item_no - default_no;
837
838 if (kind < 2U) {
839 SetMenuWeaponModelReference(i, kind, kind);
840 continue;
841 }
842
843 int found = 0;
844
845 for (int j = 0; j < 10; j++) {
846 int *info = GetMenuWeaponModelInfo(j);
847
848 if (info[1] == kind) {
849 found = 1;
850 SetMenuWeaponModelReference(i, info[0], info[1]);
851 break;
852 }
853 }
854
855 if (found == 0) {
856 u_int **pack = (u_int **) GetMenuWeaponModelData(kind);
857
858 if (*pack == NULL) {
859 printf("%d pack data is NULL\n", kind);
860 } else {
861 BtGetWeaponNamePath2(name, cfg, chara, kind);
862 DngWeaponFrm[next].LoadPackData3(*pack, cfg, &MenuExCashBuffer, texture_block, &MenuExCashBuffer, 1, 0);
863 SetMenuWeaponModelReference(i, next, kind);
864 next++;
865 }
866 }
867 }
868
869 WepMenuEffectReadBuf = (CWeaponLevelUp *) (MenuWeaponModelBuildBuffer + 0xEC01);
870 WepMenuEffectReadBuf = (CWeaponLevelUp *) MenuCalcBufAlignment((u_long128 *) WepMenuEffectReadBuf);
871 printf("read buffer = %p\n", read_buffer);
872 printf("model build buffer = %p\n", MenuWeaponModelBuildBuffer);
873 printf("WeaponBuffer Size = %d\n", (int) MenuExCashBuffer.limit);
874 printf("WeaponBuffer address = %p\n", MenuExCashBuffer.base + MenuExCashBuffer.used * 16);
875 printf("WepMenuEffectReadBuf = %p\n", WepMenuEffectReadBuf);
876}
877
878int DngWeaponEquipModelBuild(int chara, int texture_block, u_long128 *read_buffer) {
879 TexManager.DeleteTextureBlock(texture_block);
880 u_int **first = (u_int **) GetMenuWeaponModelData(0);
881 u_int **second = (u_int **) GetMenuWeaponModelData(1);
882 int kind = 0;
883
884 if (UserStatus != NULL) {
885 kind = UserStatus->chara_weapons[chara][UserStatus->equipped_weapon_slot[chara]].item_no;
886 kind -= GetDefaultWeaponNo(chara);
887 }
888
889 u_int **equipped = (u_int **) GetMenuWeaponModelData(kind);
890
891 if (equipped == NULL) {
892 equipped = second;
893 } else if (*equipped == NULL) {
894 *equipped = *second;
895 }
896
897 LoadWeapon2(*first, *second, *equipped, chara, 1);
898 MenuWeaponEffectSet(1);
899 return 1;
900}
901
909static int GetNowMotionStepCnt(int status) {
910 int step = 0;
911
912 if (status & 0x40) {
913 step = 1;
914 }
915
916 if ((status & 4) || (status & 2)) {
917 step = 2;
918 }
919
920 return step;
921}
922
930int GetNowActiveCharaStatus(int chara_no) {
931 if (BtlMenuStatusPt == NULL) {
932 return 0;
933 }
934
935 return BtlMenuStatusPt->GetActiveCharaStatus(chara_no);
936}
937
938void SetNowCharaMotionNo(int chara) {
939 int status = GetNowActiveCharaStatus(chara);
940 CUserStatus *user_status = (CUserStatus *) BtlMenuStatusPt;
941 float max_hp = user_status->max_hp[chara];
942 float hp = user_status->hp[chara];
943 int motion = MenuCharaFrame.motion_no;
944 float speed[3] = {0.1f, 0.05f, 0.0f};
945 int next = motion;
946
947 if (!(hp < 0.3f * max_hp)) {
948 next = 0;
949 }
950
951 if ((status & 0x10) || (status & 2) || hp < 0.3f * max_hp) {
952 next = 1;
953 }
954
955 if (next != motion) {
956 MenuCharaFrame.SetMotion(next, 0);
957 motion = next;
958 }
959
960 MOTION_INFO *info = MenuCharaFrame.GetMotionInfo(motion);
961 info->speed = speed[GetNowMotionStepCnt(status)];
962}
963
971void SetItemMenuColor(int chara) {
972 float red;
973 float green;
974 float blue;
975 int status;
976 int should_tint;
977
978 MGGetAmbient(MenuCharaOldAmbient);
979 status = GetNowActiveCharaStatus(chara);
980 should_tint = 0;
981
982 if (status & 4) {
983 red = 83.0f;
984 green = 104.0f;
985 blue = 95.0f;
986 should_tint = 1;
987 }
988
989 if (status & 0x40) {
990 red = 36.0f;
991 green = 148.0f;
992 blue = 195.0f;
993 should_tint = 1;
994 }
995
996 if (status & 0x10) {
997 red = 156.0f;
998 green = 122.0f;
999 blue = 182.0f;
1000 should_tint = 1;
1001 }
1002
1003 if (status & 0x20) {
1004 red = 171.0f;
1005 green = 40.0f;
1006 blue = 125.0f;
1007 should_tint = 1;
1008 }
1009
1010 if (status & 8) {
1011 red = 230.0f;
1012 green = 168.0f;
1013 blue = 92.0f;
1014 should_tint = 1;
1015 }
1016
1017 if (should_tint == 1) {
1018 float ambient[4];
1019 ambient[0] = red;
1020 ambient[1] = green;
1021 ambient[2] = blue;
1022 ambient[3] = 128.0f;
1023 MGSetAmbient(ambient);
1024 }
1025}
1026
1027void SetItemMenuOldAmbient() {
1028 MGSetAmbient(MenuCharaOldAmbient);
1029}
1030
1031int StartLoadCharaMDS(u_long128 *buffer, int chara, int read_no) {
1032 char path[64];
1033 char name[32];
1034 int size;
1035
1036 strcpy(path, GetMenuTextureDir());
1037 strcat(path, "dungeon/");
1038 sprintf(name, "c0%dmodel.pak", chara + 1);
1039 strcat(path, name);
1040 buffer = MenuCalcBufAlignment(buffer);
1041 CharaFileBGReadNo = read_no;
1042
1043 if (read_no == 0) {
1044 StartReadBG();
1045 }
1046
1047 if (LoadFileBG(path, buffer, &size) == 0) {
1048 return 1;
1049 }
1050
1051 return 0;
1052}
1053
1054void MenuCharaMDSBuild2(int chara, int texture_block) {
1055 char name[32];
1056 int size;
1057
1058 sprintf(name, "c0%ddmenu.img", chara + 1);
1059 LOADTEXTURE_INFO2 textures[3] = {
1060 {"#frame_menu_chara#640#" SCREEN_HEIGHT_STR "#4", 0, 0},
1061 {NULL, 0, 0},
1062 {NULL, 0, 0},
1063 };
1064 textures[0].block_no = texture_block;
1065 textures[1].block_no = texture_block;
1066 BG_READ_INFO *file = GetReadBGFile(CharaFileBGReadNo);
1067 textures[1].name = (char *) GetPackFile((u_int *) file->buffer, name, &size);
1068 TexManager.DeleteTextureBlock(texture_block);
1069 TexManager.CleanUpTextureList();
1070 TexManager.LoadTextureBlockEX(-1, textures);
1071 u_int *pack = (u_int *) file->buffer;
1072 u_char *model = (u_char *) ((u_long128 *) pack + (file->size >> 4) + 1);
1073 sprintf(name, "c0%ddmenu.cfg", chara + 1);
1074 MenuCharaFrame.Initialize();
1075 MenuExCashBuffer.base = model;
1076 MenuExCashBuffer.limit = 0xDC00;
1077 MenuExCashBuffer.used = 0;
1078 MenuCharaFrame.LoadPackData(pack, name, &MenuExCashBuffer, &MenuExCashBuffer, NULL);
1079 CFrameAttr attr;
1080 attr.fog_enable = true;
1081 attr.clip_enable = false;
1082 attr.program_option = 0;
1083
1084 if (MenuCharaFrame.frame != NULL) {
1085 MenuCharaFrame.frame->SetAttr(attr, 1, 4);
1086 }
1087
1088 sceVu0FVECTOR position[6] = {
1089 {-4.8f, -13.0f, 0.0f, 1.0f},
1090 {-5.2f, -12.8f, 0.0f, 1.0f},
1091 {-5.0f, -11.4f, 0.0f, 1.0f},
1092 {-5.0f, -15.0f, 0.0f, 1.0f},
1093 {-5.0f, -16.0f, 0.0f, 1.0f},
1094 {-5.0f, -15.0f, 0.0f, 1.0f}
1095 };
1096 float scale[6][3] = {
1097 {1.0f, 1.0f, 1.0f},
1098 {1.0f, 1.0f, 1.0f},
1099 {1.0f, 1.0f, 1.0f},
1100 {1.0f, 1.0f, 1.0f},
1101 {0.9f, 0.9f, 0.9f},
1102 {0.9f, 0.9f, 0.9f}
1103 };
1104 MenuCharaFrame.SetPosition(position[chara]);
1105 SetNowCharaMotionNo(chara);
1106 MenuCharaFrame.SetScale(scale[chara]);
1107 MenuCharaFrame.Step();
1108
1109 if (chara == 0) {
1110 MenuCharaFrame.ClothStep(-1);
1111 MenuCharaFrame.ClothStep(0);
1112 }
1113}
1114
1122static void GetCharaChangeReadCharaFilePath(char *path, int chara_no) {
1123 strcpy(path, readFilePath);
1124 strcat(path, charaFile[chara_no]);
1125 strcat(path, CharaFileExtension);
1126}
1127
1128const char MenuWepDir[64] = "commenu/weapon/";
1129
1130char readFilePath[0x40] = "dun/mainchara/c";
1131
1132const char *charaFile[6] = {"01d", "04b", "06b", "05a", "10b", "18a"};
1133
1134int CharaChangeInitToGL(u_long128 *buffer, int chara) {
1135 char path[64];
1136 char name[64];
1137 char cfg[16];
1138 char effect[40];
1139 int size;
1140
1141 CharaChangeBaseBuf = buffer;
1142 charachangeid = chara;
1143 GetCharaChangeReadCharaFilePath(MenureadFile, chara);
1144 CharaChangeBaseBuf = MenuCalcBufAlignment(CharaChangeBaseBuf);
1145 menucharReadbuf = CharaChangeBaseBuf;
1146 StartReadBG();
1147 LoadFileBG(MenureadFile, menucharReadbuf, &size);
1148 menud0wepReadBuf = menucharReadbuf + (size >> 4) + 1;
1149 menud0wepReadBuf = MenuCalcBufAlignment(menud0wepReadBuf);
1150 BtGetWeaponNamePath2(name, cfg, chara, 0);
1151 strcpy(path, MenuWepDir);
1152 strcat(path, name);
1153 LoadFileBG(path, menud0wepReadBuf, &size);
1154 menud1wepReadBuf = menud0wepReadBuf + (size >> 4) + 1;
1155 menud1wepReadBuf = MenuCalcBufAlignment(menud1wepReadBuf);
1156 BtGetWeaponNamePath2(name, cfg, chara, 1);
1157 strcpy(path, MenuWepDir);
1158 strcat(path, name);
1159 LoadFileBG(path, menud1wepReadBuf, &size);
1160 menud2wepReadBuf = menud1wepReadBuf + (size >> 4) + 1;
1161 menud2wepReadBuf = MenuCalcBufAlignment(menud2wepReadBuf);
1162 WEAPON_HAVE *equipped = &UserStatus->chara_weapons[chara][UserStatus->equipped_weapon_slot[chara]];
1163 int kind = equipped->item_no - (int) defWeapon[chara];
1164
1165 if (kind < 0) {
1166 kind = 0;
1167 }
1168
1169 BtGetWeaponNamePath2(name, cfg, chara, kind);
1170 strcpy(path, MenuWepDir);
1171 strcat(path, name);
1172 LoadFileBG(path, menud2wepReadBuf, &size);
1173 WepEffectMenuReadBuf = menud2wepReadBuf + (size >> 4) + 1;
1174 WepEffectMenuReadBuf = MenuCalcBufAlignment(WepEffectMenuReadBuf);
1175
1176 if (UserStatus == NULL) {
1177 printf("USerStatus is NULL\n", UserStatus);
1178 return -1;
1179 }
1180
1181 int slot = UserStatus->equipped_weapon_slot[charachangeid];
1182 WEAPON_HAVE *weapons = UserStatus->chara_weapons[charachangeid];
1183 WEAPON_HAVE *weapon = &weapons[slot];
1184 WepEffectMenuPt = Get_Main_EffectPtr(charachangeid, weapon->best_elem);
1185 sprintf(effect, "dun/mainchara/wep_eff/%s.chr", WepEffectMenuPt);
1186 LoadFileBG(effect, (u_long128 *) WepEffectMenuReadBuf, &size);
1187 return 1;
1188}
1189
1190void CharaChangeInitToGL2(int load_icon) {
1191 int size;
1192
1193 MenuWepIconCharaChangePtr = CharaChangeBaseBuf;
1194
1195 if (load_icon != 0) {
1196 MenuWepIconCharaChangePtr = MenuCalcBufAlignment(MenuWepIconCharaChangePtr);
1197 size = LoadFileBGMenuData("wepicon.img", (u_long128 *) MenuWepIconCharaChangePtr);
1198 MenuWepIconCharaChangePtr = MenuWepIconCharaChangePtr + (size >> 4) + 1;
1199 }
1200
1201 MenuVoiceLoadPtr = MenuWepIconCharaChangePtr;
1202 MenuVoiceLoadPtr = MenuCalcBufAlignment(MenuVoiceLoadPtr);
1203
1204 if (SndVoiceLoadBG(charachangeid, (u_int *) MenuVoiceLoadPtr, &size) == 0) {
1205 printf("*** voice read err \n");
1206 }
1207}
1208
1209void BtMenuLoadChara() {
1210 s8 chara = charachangeid;
1211 CUserStatus *status = UserStatus;
1212 status->cur_chara = chara;
1213 LoadChara2((s16) charachangeid, 0, (u_int *) menucharReadbuf, (u_int *) menud0wepReadBuf, (u_int *) menud1wepReadBuf, (u_int *) menud2wepReadBuf);
1214 SetWeaponAttachStatus(NowWeaponHave);
1215 CWeaponFx.InitSet(NowWeapon->frame, "dcol0", "dcol1");
1216 SetWeaponColor();
1217 MainChara_Effect(WepEffectMenuPt, (u_int *) WepEffectMenuReadBuf, 0);
1218}
1219
1220void BtMenuLoad2(int load_texture) {
1221 if (load_texture != 0) {
1222 BG_READ_INFO *file = GetReadBGFile(0);
1223 LOADTEXTURE_INFO2 textures[] = {
1224 {(char *) "#frame_image#640#" SCREEN_HEIGHT_STR "#4", MenuShadowReadBlock, 0},
1225 {(char *) file->buffer, MenuShadowReadBlock, 0},
1226 {NULL, 0, 0},
1227 };
1228 TexManager.DeleteTextureBlock(MenuShadowReadBlock);
1229 TexManager.LoadTextureBlockEX(-1, textures);
1230 MenuTextureReload(MenuShadowReadBlock);
1231 DngActiveWeaponTextureCopy();
1232 }
1233
1234 SndVoiceSyncBG();
1235 BtActStatus.player_visible = 1;
1236 BtActStatus.motion_no = 0;
1237 BtActStatus.action_on = 0;
1238}
1239
1247int EastKingCheckComplete() {
1248 if (SaveData == NULL) {
1249 return 0;
1250 }
1251
1252 int complete = 1;
1253
1254 for (int i = 0; i < 12; i++) {
1255 if (SaveData->GetGameFlag(i + 0xE6) == 0) {
1256 complete = 0;
1257 }
1258 }
1259
1260 return complete;
1261}
1262
1263void SetMonsterNameDrawFlag(int flag) {
1264 CharaNameDrawFlag = flag;
1265}
1266
1267int GetMonsterNameDrawFlag() {
1268 return CharaNameDrawFlag;
1269}
1270
1271void MonsterNameInit(ClsMes *mes, short *message_buffer, unsigned char *texture_buffer) {
1272 CharaNameMes = NULL;
1273
1274 if (mes == NULL) {
1275 printf("cls init failed\n");
1276 return;
1277 }
1278
1279 CharaNameMes = mes;
1280 mes->text_columns = MES_WIN_COLUMNS;
1281 mes->text_rows = 10;
1282 mes->text_len = 0;
1283 mes->text_width = 0;
1284 mes->text_height = 0;
1285 mes->fade = 0.0f;
1286 mes->fade_in = true;
1287 mes->text_rate = mes->text_rate_set;
1288 mes->waiting = false;
1289 mes->text_at = 0.0f;
1290 mes->text_no = 0;
1291 mes->text_from = 0;
1292 mes->page_from = 0;
1293 mes->InitMesWinTbl();
1294 mes->clut_now = mes->clut_default;
1295 mes->wait = 0;
1296 mes->blink = 0;
1297 mes->auto_page_wait = 0;
1298 mes->mes_made = -1;
1299 mes->edge_alpha = 0x80;
1300
1301 for (int i = 0; i < 10; i++) {
1302 mes->mes_no[i] = -1;
1303 }
1304
1305 for (int i = 0; i < 8; i++) {
1306 mes->values[i] = 0;
1307 }
1308
1309 mes->value = 0;
1310 mes->value_signed = false;
1311 mes->value_show = true;
1312 mes->value_narrow = false;
1313 mes->space_width = -1;
1314 mes->space_area = -1;
1315 mes->cursor_row = -1;
1316 mes->cursor_y = 0;
1317 mes->cursor_lit = false;
1318
1319 for (int i = 0; i < 10; i++) {
1320 mes->line_pos[i].x = -1;
1321 mes->line_pos[i].y = -1;
1322 }
1323
1324 CharaNameMes->Preset(MES_PRESET_NAME);
1325 CharaNameMes->tex_block = 0x1A;
1326 CharaNameMes->tex_buff = texture_buffer;
1327 CharaNameMes->rows = 1;
1328 CharaNameMes->SetBuff(message_buffer);
1329 CharaNameMes->SetBuff_system(SystemMes);
1330 CharaNameDrawFlag = 1;
1331 int *config = (int *) SaveData->GetConfigData();
1332
1333 if (config != NULL) {
1334 CharaNameDrawFlag = !config[8];
1335 }
1336
1337 CharaNameDrawCase = 0;
1338}
1339
1340void MonsterNameMake(int mes_no) {
1341 if (CharaNameMes != NULL) {
1342 int mes = mes_no + 3000;
1343
1344 if (CharaNameMes->mes_made != mes) {
1345 CharaNameMes->MakeMesWin(mes);
1346
1347 if (mes == 3000) {
1348 CharaNameMes->stay_frame = false;
1349 } else {
1350 CharaNameMes->stay_frame = true;
1351 }
1352 }
1353 }
1354}
1355
1356void MonsterNamePosSet(int x, int y) {
1357 if (CharaNameMes != NULL) {
1358 int columns = CharaNameMes->text_columns;
1359 CharaNameMes->text_x = x - columns * 14 / 2;
1360
1361 if (y % 2 != 0) {
1362 y++;
1363 }
1364
1365 CharaNameMes->text_y = y;
1366 }
1367}
1368
1369void MonsterNameDraw() {
1370 if (CharaNameMes == NULL || GetMonsterNameDrawFlag() == 0) {
1371 return;
1372 }
1373
1374 if (((int *) SaveData->GetConfigData())[8] == 0) {
1375 ClsMes *mes = CharaNameMes;
1376
1377 if (mes->mes_made >= 0) {
1378 int width = mes->text_columns;
1379 width = mes->char_width * width + 0x20;
1380
1381 if (mes->text_x < 0x22 || mes->text_x >= 0x26D || mes->text_y < 0x1E || mes->text_y >= 0x199 || width >= 0xFB || width < 10) {
1382 SetMonsterNameDrawFlag(0);
1383 return;
1384 }
1385
1386 mes->cursor_row = -1;
1387 MenuTextureReload(CharaNameMes->tex_block);
1388 setbilinear(0);
1389 CharaNameMes->Step();
1390 CharaNameMes->DrawMesWin();
1391 }
1392 }
1393}
1394
1402void DngEscapeMsgInit(ClsMes *title, ClsMes *choice, int dungeon) {
1403 char path[64];
1404 int file_size;
1405
1406 if (title == NULL || choice == NULL) {
1407 return;
1408 }
1409
1410 if (UserStatus == NULL) {
1411 return;
1412 }
1413
1414 int georama_no = UserStatus->cur_georama + 1;
1415 strcpy(path, GetMenuTextureDir());
1416 strcat(path, "d0%do.img");
1417 sprintf(path, path, georama_no);
1418 LoadFile(path, read_buffer, &file_size);
1419 int block = 0x17;
1420 char *image = (char *) read_buffer;
1421 LOADTEXTURE_INFO2 texture[3] = {
1422 {(char *) FrameImageTexture, block, 0},
1423 {image, block, 0},
1424 {NULL, 0, 0},
1425 };
1426 int size[4];
1427 TexManager.DeleteTextureBlock(block);
1428 TexManager.CleanUpTextureList();
1429 TexManager.LoadTextureBlockEX(-1, texture);
1430 GamePad.MenuModeOn(0x78);
1431 GamePad.SetAutoRepeat(PAD_DPAD, 0x1E, 5);
1432 char name[8] = "d0%do";
1433 sprintf(name, name, georama_no);
1434 DngEscapeTex = TexManager.GetTexture(name, -1);
1435 CharaNameMes = title;
1436 DngMenuMes = choice;
1437 int lang = GetMenuLangFlag();
1438 u_char title_x[7] = {0xB4, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0};
1439 CharaNameMes->text_x = title_x[lang];
1440 CharaNameMes->text_y = 0x8C;
1441 CharaNameMes->mes_made = -1;
1442 CharaNameMes->MakeMesWin(dungeon + 0x14);
1443 // Built but never read: the choice window is right-aligned by its measured width instead.
1444 s16 choice_x[7] = {0x154, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0};
1445 int right = 0x280;
1446 DngMenuMes->mes_made = -1;
1447 DngMenuMes->MakeMesWin(12);
1448 DngMenuMes->NeedMesWinWH(DngMenuMes->mes_made, size);
1449 right -= size[2];
1450 DngMenuMes->text_x = right - 0x26;
1451 DngMenuMes->text_y = 0x140;
1452 DngEscapeSelect = 1;
1453 DngEscapeEndFlag = 0;
1454 DngEscapeAlpha = 0x80;
1455 DngEscapeBlock = block;
1456}
1457
1458void DngEscapeMsgDraw() {
1459 AllFadeForMenu(0x80);
1460
1461 if (CharaNameMes == NULL || DngMenuMes == NULL) {
1462 return;
1463 }
1464
1465 MenuTextureReload(DngEscapeBlock);
1466 DrawFullSizePicture(DngEscapeTex, 0, 0, 0x80);
1467 MenuTextureReload(CharaNameMes->tex_block);
1468 setbilinear(0);
1469 CharaNameMes->stay_frame = true;
1470 CharaNameMes->Step();
1471 DngMenuMes->Step();
1472 CharaNameMes->DrawMesWin();
1473 DngMenuMes->DrawMesWin();
1474
1475 if (DngEscapeEndFlag != 0) {
1476 DngEscapeAlpha += 3;
1477
1478 if (DngEscapeAlpha > 0x80) {
1479 DngEscapeAlpha = 0x80;
1480 }
1481 } else {
1482 DngEscapeAlpha -= 3;
1483
1484 if (DngEscapeAlpha < 0) {
1485 DngEscapeAlpha = 0;
1486 }
1487 }
1488
1489 AllFadeForMenu(DngEscapeAlpha);
1490}
1491
1492int DngEscapeMsgLoop() {
1493 int result = 0;
1494
1495 if (DngEscapeEndFlag == 0) {
1496 if (GamePad.Down(PAD_UP | PAD_DOWN) != 0) {
1497 if (DngEscapeSelect == 2) {
1498 DngEscapeSelect = 1;
1499 } else if (DngEscapeSelect == 1) {
1500 DngEscapeSelect = 2;
1501 }
1502
1503 ComMenuSePlay(MENU_SOUND_CURSOR);
1504 }
1505
1506 int row = DngEscapeSelect - 1;
1507 ClsMes *mes = CharaNameMes;
1508 mes->cursor_row = row;
1509
1510 if (GamePad.Down(PAD_CROSS) != 0) {
1511 DngEscapeEndFlag = 1;
1512 ComMenuSePlay(MENU_SOUND_CONFIRM);
1513 }
1514
1515 if (GamePad.Down(PAD_CIRCLE) != 0) {
1516 ComMenuSePlay(MENU_SOUND_REFUSE);
1517 }
1518 } else if (DngEscapeAlpha >= 0x80) {
1519 result = DngEscapeSelect;
1520 GamePad.AutoRepeatOff();
1521 GamePad.MenuModeOff();
1522 ItemVolumeStep.CheckItemVolume();
1523 ClsMes *mes = CharaNameMes;
1524 mes->cursor_row = -1;
1525 }
1526
1527 ItemVolumeStep.LoopStep(0x3C);
1528 DngEscapeMsgDraw();
1529 return result;
1530}
1531
1532int CheckItemThrow(int *items, int *values) {
1533 int i;
1534 int any = 0;
1535 int found = 0;
1536 ITEM_PACK *pack;
1537 WEAPON_HAVE *weapons;
1538 int item_no;
1539 ATTACH_LIST *attachments;
1540
1541 pack = &((CUserStatus *) BtlMenuStatusPt)->item_pack;
1542
1543 for (i = 0; i < 3; i++) {
1544 item_no = pack->item[pack->num + i];
1545
1546 if (item_no >= ITEM_DUNGEON_START) {
1547 found++;
1548
1549 if (items != NULL) {
1550 items[i] = item_no;
1551 }
1552
1553 if (values != NULL) {
1554 values[i] = 0;
1555 }
1556 }
1557 }
1558
1559 for (i = 0; i < 6; i++) {
1560 weapons = ((CUserStatus *) BtlMenuStatusPt)->chara_weapons[i];
1561 item_no = weapons[10].item_no;
1562
1563 if (item_no >= ITEM_WEAPON_START) {
1564 found++;
1565
1566 if (items != NULL) {
1567 items[3] = item_no;
1568 }
1569
1570 if (values != NULL) {
1571 values[3] = weapons[10].level;
1572 }
1573
1574 break;
1575 }
1576 }
1577
1578 attachments = (ATTACH_LIST *) ((CUserStatus *) BtlMenuStatusPt)->consumable_items;
1579
1580 for (i = 0; i < 3; i++) {
1581 item_no = attachments[i + 40].item_no;
1582
1583 if (item_no >= ITEM_ATTACH_START) {
1584 found++;
1585
1586 if (items != NULL) {
1587 items[i + 4] = item_no;
1588 }
1589
1590 if (values != NULL && item_no >= ITEM_ATTACH_STAT_START && item_no < ITEM_ATTACH_GEM_START) {
1591 values[i + 4] = (&attachments[i + 40].item_no)[item_no - ITEM_ATTACH_STAT_START + 4];
1592 }
1593
1594 if (values != NULL && item_no == ITEM_ATTACH_SYNTHESIS_SPHERE) {
1595 values[i + 4] = attachments[i + 40].sphere_weapon_no;
1596 }
1597 }
1598 }
1599
1600 if (found > 0) {
1601 any = 1;
1602 }
1603
1604 return any;
1605}
1606
1607void SetWeaponElementStatus(WEAPON_HAVE *weapon) {
1608 if (weapon->best_elem >= 5) {
1609 weapon = (WEAPON_HAVE *) weapon;
1610 }
1611
1612 int best = 0;
1613
1614 for (int i = 1; i < 5; i++) {
1615 if (weapon->elem[i] > weapon->elem[best]) {
1616 best = i;
1617 }
1618 }
1619
1620 weapon->best_elem = best;
1621}
1622
1623int CheckWeaponOptionStatus(int options) {
1624 // Each pair of opposed options cancels out when both are set.
1625 if ((options & 2) && (options & 4)) {
1626 options &= ~6;
1627 }
1628
1629 if ((options & 8) && (options & 0x10)) {
1630 options &= ~0x18;
1631 }
1632
1633 if ((options & 0x100) && (options & 0x200)) {
1634 options &= ~0x300;
1635 }
1636
1637 if ((options & 0x400) && (options & 0x800)) {
1638 options &= ~0xC00;
1639 }
1640
1641 return options;
1642}
1643
1644int IsWeaponOptionGoodOrBad(int option) {
1645 // Whether each of the fourteen weapon options is a benefit (1) or a drawback (0).
1646 s16 good_or_bad[14] = {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1};
1647 return good_or_bad[option];
1648}
1649
1650int DefaultWeaponOptionSet(int weapon_no) {
1651 WEAPON_DATA *data = GetWeaponData(weapon_no);
1652
1653 if (data == NULL) {
1654 return 1;
1655 }
1656
1657 return data->flags;
1658}
1659
1660void WeaponOptionStatusDraw(WEAPON_HAVE *weapon, int x, int y, int alpha) {
1661 int draw_x = x;
1662 int draw_y = y;
1663 int flags = weapon->flags;
1664
1665 for (int i = 0; i < 6; i++) {
1666 int option = ((ATTACH_LIST *) &weapon->attach[i])->sphere_flags;
1667
1668 if (option != 0 && option != 1) {
1669 flags |= option;
1670 }
1671 }
1672
1673 flags = CheckWeaponOptionStatus(flags);
1674 CTexture *texture = TexManager.GetTexture("charaface", -1);
1675
1676 if (texture == NULL) {
1677 return;
1678 }
1679
1680 int count = 0;
1681 CRect_i_ source(0xEC, 0x50, 0x14, 0x14);
1682
1683 for (int bit = 1; bit <= 13; bit++) {
1684 if (bit == 8) {
1685 source.x -= source.width;
1686 }
1687
1688 if (flags & (1 << bit)) {
1689 int row = bit;
1690
1691 if (bit > 7) {
1692 row = bit - 7;
1693 }
1694
1695 if (bit == 8 && row == 1) {
1696 row++;
1697 }
1698
1699 if (bit == 9 && row == 2) {
1700 row--;
1701 }
1702
1703 source.y = source.height * (row - 1) + 0x50;
1704 DrawMenu2DSprite(texture, CRect_i_(draw_x, draw_y, 0x14, 0x15), source, alpha);
1705 draw_x += source.width;
1706 count++;
1707
1708 if (count == 5) {
1709 draw_x = x;
1710 draw_y += source.height;
1711 }
1712 }
1713 }
1714}
1715
1716void WeaponStarDraw(int x, int y, WEAPON_HAVE *weapon, int alpha) {
1717 if (weapon == NULL) {
1718 return;
1719 }
1720
1721 CTexture *texture = TexManager.GetTexture("wepstatus", -1);
1722 int stars = weapon->synthesis_count;
1723
1724 if (stars > 49) {
1725 stars = 49;
1726 }
1727
1728 int draw_x = x + 0x4C;
1729 CRect_i_ big_star(0x108, 0x176, 0x18, 0x18);
1730
1731 for (int i = 0; i < stars / 10; i++, draw_x += big_star.width) {
1732 DrawMenu2DSprite(texture, CRect_i_(draw_x, y, big_star.width, big_star.height), big_star, alpha);
1733 }
1734
1735 x -= 6;
1736
1737 for (int i = 0; i < stars % 10; i++, x += 0x14) {
1738 DrawMenu2DSprite(texture, CRect_i_(x, y + 0x16, 0x14, 0x14), CRect_i_(0x10A, 0x162, 0x14, 0x14), alpha);
1739 }
1740}
1741
1749static void LocalWeaponDataChange(char *values, int count, int base, int range) {
1750 if (values == NULL) {
1751 printf("target is NULL\n");
1752 return;
1753 }
1754
1755 int selected = rand() % count;
1756 int reduction = base + rand() % range;
1757 char *value = values;
1758 int i = 0;
1759
1760 while (i < count) {
1761 if (i == selected) {
1762 *value -= reduction;
1763
1764 if (*value < 0) {
1765 *value = 0;
1766 }
1767
1768 break;
1769 }
1770
1771 i++;
1772 value++;
1773 }
1774}
1775
1776int WeaponDataChangeByRGate(WEAPON_HAVE *weapon, int kind) {
1777 if (weapon == NULL) {
1778 return -1;
1779 }
1780
1781 int is_default = 0;
1782 int i;
1783
1784 for (i = 0; i < 6; i++) {
1785 if (weapon->item_no == defWeapon[i]) {
1786 is_default = 1;
1787 }
1788 }
1789
1790 switch (kind) {
1791 case RGATE_ABS_FULL:
1792 printf("abs full\n");
1793
1794 if (is_default == 1) {
1795 printf("this weapon default\n");
1796 } else {
1797 weapon->experience = GetWeaponMaxExp(weapon);
1798 }
1799
1800 break;
1801 case RGATE_STAT_DOWN:
1802 if (IsDefaultWeapon(weapon->item_no) >= 0) {
1803 printf("default Weapon\n");
1804 } else {
1805 int stat = rand() % 4;
1806 int loss = rand() % 3 + 2;
1807
1808 switch (stat) {
1809 case 0:
1810 weapon->attack -= loss;
1811
1812 if (weapon->attack <= 0) {
1813 weapon->attack = 1;
1814 }
1815
1816 break;
1817 case 1:
1818 weapon->endurance -= loss;
1819
1820 if (weapon->endurance < 0) {
1821 weapon->endurance = 0;
1822 }
1823
1824 break;
1825 case 2:
1826 weapon->speed -= loss;
1827
1828 if (weapon->speed < 0) {
1829 weapon->speed = 0;
1830 }
1831
1832 break;
1833 case 3:
1834 weapon->magic -= loss;
1835
1836 if (weapon->magic < 0) {
1837 weapon->magic = 0;
1838 }
1839
1840 break;
1841 }
1842
1843 LocalWeaponDataChange(weapon->elem, 5, 2, 3);
1844 LocalWeaponDataChange(weapon->vs_monster, 3, 2, 2);
1845 LocalWeaponDataChange(&weapon->vs_monster[3], 3, 2, 2);
1846 LocalWeaponDataChange(&weapon->vs_monster[6], 4, 2, 2);
1847 }
1848
1849 break;
1850 case RGATE_WHP_UP:
1851 if (IsDefaultWeapon(weapon->item_no) >= 0) {
1852 printf("this weapon No.%d is default\n", weapon->item_no);
1853 } else {
1854 int add = rand() % 3 + 3;
1855 weapon->durability += add;
1856
1857 if (weapon->durability > 99) {
1858 weapon->durability = 99;
1859 }
1860
1861 printf("WHp up is %d\n", add);
1862 printf("now MaxWHp is %d\n", weapon->durability);
1863 }
1864
1865 break;
1866 case RGATE_WHP_DOWN:
1867 if (IsDefaultWeapon(weapon->item_no) < 0) {
1868 int loss = rand() % 3 + 3;
1869 weapon->durability -= loss;
1870 float durability = weapon->durability;
1871
1872 if (durability < weapon->durability_f) {
1873 weapon->durability_f = durability;
1874 }
1875
1876 if (weapon->durability <= 0) {
1877 weapon->durability = 1;
1878 }
1879
1880 printf("WHp down is %d\n", loss);
1881 printf("now MaxWHp is %d\n", weapon->durability);
1882 }
1883
1884 break;
1885 case RGATE_WHP_CURE:
1886 printf("whp cure\n");
1887
1888 if (is_default == 1) {
1889 if (UserStatus != NULL) {
1890 int chara = UserStatus->cur_chara;
1891 EquipWeaponFrame(&DefaultWeapon, chara, CharaMainHandViewFlag);
1892
1893 if (chara == 5) {
1894 NowMainEffect = &CharaMainEffectCrash;
1895 BtActStatus.gun_type = 0;
1896 }
1897
1898 int slot = UserStatus->equipped_weapon_slot[chara];
1899 WEAPON_HAVE *weapons = UserStatus->chara_weapons[chara];
1900 MenuWeaponSpSet(&MainWeapon, &weapons[slot]);
1901 printf("equip default Weapon\n");
1902 }
1903 } else {
1904 weapon->durability_f = weapon->durability;
1905 }
1906
1907 break;
1908 case RGATE_WHP_QUARTER: {
1909 float durability = weapon->durability_f / 4.0f;
1910 weapon->durability_f = durability;
1911
1912 if (durability < 1.0f) {
1913 weapon->durability_f = 1.0f;
1914 }
1915
1916 break;
1917 }
1918 default:
1919 printf("now %d ??? \n");
1920 break;
1921 }
1922
1923 return 1;
1924}
void SetMotion(int no, int mode, float speed=-1.0f)
CFrame * frame
MOTION_INFO * GetMotionInfo(int motion_no)
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
virtual void SetScale(float x, float y, float z)
virtual void LoadPackData3(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int keep_textures, int visual_type)
virtual void Step()
virtual void Initialize()
virtual void SetPosition(float x, float y, float z)
virtual void ClothStep(int step)
s32 GetActiveCharaStatus(int chara_no)
short draw_on
Definition frame.hpp:27
char clip_enable
Definition frame.hpp:29
char program_option
Definition frame.hpp:32
char fog_enable
Definition frame.hpp:33
CFrameAttr attr
Definition frame.hpp:65
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
void AutoRepeatOff()
Definition gamepad.cpp:609
void CheckItemVolume()
void LoopStep(int interval)
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
int QuestDungeon(int dungeon_no, int add)
Definition savedata.cpp:535
int GetGameFlag(int flag_no)
Definition savedata.cpp:258
void * GetConfigData()
Definition savedata.cpp:33
s16 max_hp[6]
void SetNextLife(int chara_no, s16 value, float ratio)
ITEM_PACK item_pack
s32 ailments[6]
float water_max[6]
void AddDrink(int chara_no, s16 amount, float ratio)
float water_now[6]
WEAPON_HAVE chara_weapons[6][11]
s16 ailment_frames[6]
s8 equipped_weapon_slot[6]
void InitSet(CFrame *frame, char *root_name, char *tip_name)
s32 text_rows
Definition clsmes.hpp:158
s32 text_y
Definition clsmes.hpp:152
s32 text_from
Definition clsmes.hpp:198
s32 cursor_y
Definition clsmes.hpp:225
s32 text_x
Definition clsmes.hpp:151
float text_rate_set
Definition clsmes.hpp:193
void DrawMesWin()
Definition clsmes.cpp:2619
s32 wait
Definition clsmes.hpp:204
s32 text_no
Definition clsmes.hpp:197
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
void NeedMesWinWH(int mes_no, int *out)
Definition clsmes.cpp:1476
s32 page_from
Definition clsmes.hpp:199
s32 text_height
Definition clsmes.hpp:161
s32 text_width
Definition clsmes.hpp:160
s32 char_width
Definition clsmes.hpp:153
s32 text_columns
Definition clsmes.hpp:157
s32 text_len
Definition clsmes.hpp:159
s32 value
Definition clsmes.hpp:218
void InitMesWinTbl()
Definition clsmes.cpp:1265
s32 waiting
Definition clsmes.hpp:194
s32 cursor_lit
Definition clsmes.hpp:226
s32 auto_page_wait
Definition clsmes.hpp:206
s32 fade_in
Definition clsmes.hpp:188
s32 space_width
Definition clsmes.hpp:222
s32 clut_now
Definition clsmes.hpp:203
s32 blink
Definition clsmes.hpp:205
void * tex_buff
Definition clsmes.hpp:233
s32 cursor_row
Definition clsmes.hpp:224
float fade
Definition clsmes.hpp:187
void SetBuff(short *buff)
Definition clsmes.cpp:456
s32 mes_made
Definition clsmes.hpp:207
s32 values[8]
Definition clsmes.hpp:217
s32 value_narrow
Definition clsmes.hpp:221
s32 tex_block
Definition clsmes.hpp:227
s32 value_signed
Definition clsmes.hpp:219
float text_rate
Definition clsmes.hpp:192
s32 stay_frame
Definition clsmes.hpp:189
s32 edge_alpha
Definition clsmes.hpp:213
s32 clut_default
Definition clsmes.hpp:202
MES_LINE_POS line_pos[10]
Definition clsmes.hpp:228
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
s32 value_show
Definition clsmes.hpp:220
void SetBuff_system(short *buff)
Definition clsmes.cpp:462
void Preset(int style)
Definition clsmes.cpp:468
s32 rows
Definition clsmes.hpp:156
s32 space_area
Definition clsmes.hpp:223
float text_at
Definition clsmes.hpp:196
@ ITEMKINDF_RANDOM
Definition itemdata.hpp:556
@ ITEMKINDF_CONSUMABLE
Definition itemdata.hpp:554
@ ITEMUSE_HEAL_HP
Definition itemdata.hpp:543
@ ITEMUSE_DRINK
Definition itemdata.hpp:544
@ ITEMUSE_STATUS
Definition itemdata.hpp:542
s16 sphere_weapon_no
Definition itemdata.hpp:592
u_long128 * buffer
Definition dataread.hpp:29
s16 vol_range
Definition itemdata.hpp:530
s16 kind_flags
Definition itemdata.hpp:528
u32 use_flags
Definition itemdata.hpp:527
s16 item[103]
float durability_f
Definition itemdata.hpp:695
char vs_monster[10]
Definition itemdata.hpp:699
ATTACH_LIST attach[6]
Definition itemdata.hpp:701
s32 synthesis_count
Definition itemdata.hpp:704