DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
gameloop.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 885
4#ifndef PAL
5#pragma argument_flag_free 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609
6#pragma argument_flag_free 3610, 3611, 3612, 3613, 3614, 3615, 3616, 3617, 3618, 3619
7#pragma argument_flag_free 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629
8#pragma argument_flag_free 3630, 3631, 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639
9#pragma argument_flag_free 3640, 3641, 3642, 3643, 3644, 3645, 3646, 3647, 3648, 3649
10#pragma argument_flag_free 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659
11#pragma argument_flag_free 3660, 3661, 3662, 3663, 3664, 3665, 3666, 3667, 3668, 3669
12#pragma argument_flag_free 3670, 3671, 3672, 3673, 3674, 3675, 3676, 3677, 3678, 3679
13#pragma argument_flag_free 3680, 3681, 3682, 3683, 3684, 3685, 3686, 3687, 3688, 3689
14#pragma argument_flag_free 3690, 3691, 3692, 3693, 3694, 3695, 3696, 3697, 3698, 3699
15#pragma argument_flag_free 3700, 3701, 3702, 3703, 3704, 3705, 3706, 3707, 3708, 3709
16#pragma argument_flag_free 3710, 3711, 3712, 3713, 3714, 3715, 3716, 3717, 3718, 3719
17#pragma argument_flag_free 3720, 3721, 3722, 3723, 3724, 3725, 3726, 3727, 3728, 3729
18#pragma argument_flag_free 3730, 3731, 3732, 3733, 3734, 3735, 3736, 3737, 3738, 3739
19#pragma argument_flag_free 3740, 3741, 3742, 3743, 3744, 3745, 3746, 3747, 3748, 3749
20#pragma argument_flag_free 3750, 3751, 3752, 3753, 3754, 3755, 3756, 3757, 3758, 3759
21#pragma argument_flag_free 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3768, 3769
22#pragma argument_flag_free 3770, 3771, 3772, 3773, 3774, 3775, 3776, 3777, 3778, 3779
23#pragma argument_flag_free 3780, 3781, 3782, 3783, 3784, 3785, 3786, 3787, 3788, 3789
24#pragma argument_flag_free 3790, 3791, 3792, 3793, 3794, 3795, 3796, 3797, 3798, 3799
25#pragma argument_flag_free 3800, 3801, 3802, 3803, 3804, 3805, 3806, 3807, 3808, 3809
26#pragma argument_flag_free 3810, 3811, 3812, 3813, 3814, 3815, 3816, 3817, 3818, 3819
27#pragma argument_flag_free 3820, 3821, 3822, 3823, 3824, 3825, 3826, 3827, 3828, 3829
28#pragma argument_flag_free 3830, 3831, 3832, 3833, 3834, 3835, 3836, 3837, 3838, 3839
29#pragma argument_flag_free 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3848, 3849
30#pragma argument_flag_free 3850, 3851, 3852, 3853, 3854, 3855, 3856, 3857, 3858, 3859
31#pragma argument_flag_free 3860, 3861, 3862, 3863, 3864, 3865, 3866, 3867, 3868, 3869
32#pragma argument_flag_free 3870, 3871, 3872, 3873, 3874, 3875, 3876, 3877, 3878, 3879
33#pragma argument_flag_free 3880
34#pragma argument_flag_ones 154, 451, 493, 573, 574, 575, 591, 592, 593, 594
35#pragma argument_flag_ones 1155, 1173, 1174, 1175, 1176, 1239, 1249, 1250, 1285, 1289
36#pragma argument_flag_ones 1314, 1318, 1326, 1330, 1339, 1364, 1366, 1411, 1456, 1459
37#pragma argument_flag_ones 1460, 1464, 1471, 1473, 1489, 1491, 1505, 1755, 1756, 1810
38#pragma argument_flag_ones 1811, 1815, 1816, 1817, 1877, 1880, 1906, 1937, 1988, 2045
39#pragma argument_flag_ones 2197, 2243, 2244, 2362, 2411, 2426, 2433, 2444, 2450, 2473
40#pragma argument_flag_ones 2474, 2475, 2476, 2477, 2521, 2578, 2581, 2582, 2614, 2624
41#pragma argument_flag_ones 2700, 2897, 3024, 3309, 3337, 3513, 3515, 3587, 3589, 3684
42#pragma argument_flag_ones 3685, 3687, 3688, 3891, 3911, 3922, 3943, 3946, 3947, 3999
43#pragma argument_flag_ones 4058, 4069, 4077, 4097, 4100, 4135, 4142, 4157, 4160, 4185
44#pragma argument_flag_ones 4213, 4220, 4234, 4253, 4265, 4269, 4270, 4340, 4346, 4355
45#pragma argument_flag_ones 4367, 4393, 4415, 4422, 4429, 4701, 4702, 4703, 4746, 4749
46#pragma argument_flag_ones 4810, 4811, 4813
47#pragma argument_flag 0
48#endif
49
50#include "dun/gameloop.hpp"
51
52#include <libvu0.h>
53
54#include <cmath>
55#include <cstdio>
56#include <cstdlib>
57#include <cstring>
58
59#include "battlemenu.hpp"
60#include "btactstatus.hpp"
61#include "btitem.hpp"
62#include "btmisc.hpp"
63#include "btsysscript.hpp"
64#include "camera.hpp"
65#include "camerafollow.hpp"
66#include "character.hpp"
67#include "clothread.hpp"
68#include "clsmes.hpp"
69#include "collision.hpp"
70#include "collisiondata.hpp"
71#include "dataalloc.hpp"
72#include "dataread.hpp"
73#include "dataset.hpp"
74#include "dispctrl.hpp"
75#include "dngmessageman.hpp"
76#include "dngstatusdata.hpp"
77#include "dranmapfield.hpp"
78#include "dungeoneventman.hpp"
79#include "dungeonmap.hpp"
80#include "edit.hpp"
81#include "editloop3.hpp"
82#include "frame.hpp"
83#include "frameattr.hpp"
84#include "gamemode.hpp"
85#include "gamepad.hpp"
86#include "gameutil.hpp"
87#include "healeffect.hpp"
88#include "hit_machingun_effect.hpp"
89#include "hitmark.hpp"
90#include "hitvalue.hpp"
91#include "itembombeffect.hpp"
92#include "itemdata.hpp"
93#include "main.hpp"
94#include "mainitemmodel.hpp"
95#include "mainselect.hpp"
96#include "mathutil.hpp"
97#include "mds.hpp"
98#include "menu_draw.hpp"
99#include "menu_dungeon.hpp"
100#include "menu_misc.hpp"
101#include "menu_save.hpp"
102#include "menuitemstep.hpp"
103#include "mglib.hpp"
104#include "monstorunit.hpp"
105#include "motionmodel.hpp"
106#include "nowload.hpp"
107#include "npcharacter.hpp"
108#include "objanime.hpp"
109#include "randomitem.hpp"
110#include "rect.hpp"
111#include "runeffect.hpp"
112#include "runscript_opcodes.hpp"
113#include "savedata.hpp"
114#include "shot_effect.hpp"
115#include "shot_effect_pack.hpp"
116#include "shot_firebar.hpp"
117#include "shot_freefuncs.hpp"
118#include "snd.hpp"
119#include "stealitem.hpp"
120#include "texture.hpp"
121#include "textureanime.hpp"
122#include "userstatus.hpp"
123#include "vutext.hpp"
124#include "weaponeffect.hpp"
125#include "weaponelement.hpp"
126#include "wind.hpp"
127
133 s32 life;
134 s32 x;
135 s32 y;
136 s32 on;
137 s32 draw;
138};
139
140STATIC_ASSERT(sizeof(ENEMY_LIFE_GAGE) == 0x18);
141
145struct BOMB_INFO {
146 sceVu0FVECTOR pos;
147 s32 unk_10;
148 s32 aiming;
150 s32 unk_1C;
151};
152
153STATIC_ASSERT(sizeof(BOMB_INFO) == 0x20);
154
159public:
160 s32 x;
161 s32 y;
162 s32 width;
163 s32 height;
165 s32 alpha;
166 s32 length;
167 char text[0x200];
175 void Draw();
176};
177
178STATIC_ASSERT(sizeof(CDebugFont) == 0x21C);
179
180/* The weapon each character starts with. */
181s32 defWeapon__6[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};
182
186static inline float CharaRangeRate(CUserStatus *status) {
187 float range_rate[6] = {1.2f, 1.4f, 1.1f, 1.5f, 1.0f, 1.8f};
188
189 return range_rate[status->cur_chara];
190}
191
195static inline float CharaHeight(CUserStatus *status) {
196 float chara_height[6] = {16.0f, 14.0f, 16.0f, 16.0f, 18.0f, 15.0f};
197
198 return chara_height[status->cur_chara];
199}
200
208
214int keyCtrl(float x, float y, MOTION_INFO *motion);
215
221void SetSystemMes(int mes_no, int frames, int x, int y, int *result, int *unk);
222
228void NotGetAtraMes(int chara, int frames);
229
235void DeadMes(int chara, int frames);
236
242void AllDeadMes(int frames);
243
249int DebugInfomationIF();
250
256void SndSeSeqAllStop();
257
261int BtMiniChrSelect_Loop();
262
266int BtEscape_Loop();
267
273void BtGetTreasureboxBig_Init();
274
278int BtGetTreasureboxBig_Loop();
279
285void BtGetTreasureboxSmall_Init(int dungeon);
286
290int BtGetTreasureboxSmall_Loop();
291
297void BtAtraGetShort_Init();
298
302int BtAtraGetShort_Loop(int dungeon, int floor);
303
307int BtGetGateKey_Loop();
308
314void ToanKey_On();
315
319void ToanKey_Play();
320
324void GoroKey_On();
325
329void GoroKey_Play();
330
334void UngagaKey_On();
335
339void UngagaKey_Play();
340
346void ClearSystemMes();
347
353void BtSetActiveItemModel(unsigned int *pack);
354
360void ClearGateKeyStack();
361
365void SndAmbientSetVol(int volume);
366
372void BtBattleMusic_Init();
373
379void BtAtraListMake(int dungeon);
380
386void DebugInfomationInit();
387
395static void LoadData();
396
397/* The overlay's large data, in the order retail's link lays it out. */
398
399/* The battle status of every character in the party. */
400BT_ACT_STATUS BtActStatus;
401
402/* The cameras the dungeon draws through. */
403CCameraFollow MainCamera__4(20.0f, 15.0f, 0.0f, 8.0f);
404CCameraFollow SubCamera(60.0f, 20.0f, 0.0f, 4.0f);
405
406/* The fade the dungeon draws over the picture. */
407CDispCtrl DispFade__3;
408
409/* The dungeon floor that the player is on. */
410CDungeonMap MainDungeonMap;
411
412/* The back dungeon's floor. */
413CDungeonMap UraDungeonMap;
414
415/* The Dran fields of the floor that the player is on. */
416DRAN_MAP_FIELD_SET DranMapField;
417
418/* The events of the floor that the player is on. */
419CDungeonEventMan DngEventMan;
420
421/* The events of the back dungeon's floor. */
422CDungeonEventMan UraEventMan;
423
424/* The lighting the dungeon draws the field and the models under. */
425sceVu0FMATRIX main_light;
426sceVu0FMATRIX main_lightcolor;
427sceVu0FVECTOR main_ambientlight;
428sceVu0FMATRIX sub_light;
429sceVu0FMATRIX sub_lightcolor;
430sceVu0FVECTOR sub_ambientlight;
431
432/* The monsters of the floor that the player is on. */
433CMonstorUnit MainMonstorUnit;
434
435/* The life gauge of the enemy the player has locked on to. */
436ENEMY_LIFE_GAGE EnemyLifeGage;
437
438/* The trail that the player's weapon leaves as it swings. */
439CWeaponEffect CWeaponFx;
440
441/* The element trails the player's weapon leaves. */
442CWeaponElement CWeaponElFx[4];
443
444/* The five Atlamillia effects. */
445CSHOT_EFFECT MasekiEffect[5];
446
447/* The effect the player's own character shoots. */
448CSHOT_EFFECT CharaMainEffect;
449
450/* The effect the player's own character breaks things with. */
451CSHOT_EFFECT CharaMainEffectCrash;
452
453/* The character that the player controls. */
454CCharacter CharaMain;
455
456/* The hand that the player's character holds an item out with. */
457CCharacter CharaHand;
458
459/* The weapon models the player's character can hold. */
460CCharacter MainWeapon;
461CCharacter DefaultWeapon;
462CCharacter CrashWeapon;
463
464/* The weapon that the player has equipped. */
465WEAPON_HAVE WeaponHave;
466
467/* The messages the dungeon shows over the picture. */
468CDngMessageMan DngMessMan;
469
470/* The items lying on the floor that the player is on. */
471CRandomItem MainRandomItem;
472
473/* The items lying on the matching floor of the back dungeon. */
474CRandomItem SubRandomItem;
475
476/* The item that a monster stole. */
477CStealItem StealItem;
478
479/* The characters that walk the dungeon alongside the player. */
480CNPCharacter NPCUnit[6];
481
482/* The splash the player's feet throw up in water. */
483CCharacter Water_Splash;
484
485/* The circle a trap draws on the floor, and its texture animations. */
486CCharacter Trap_Circle;
487CTexAnimeData Trap_Circle_TexAnim[16];
488
489/* The effect that plays as the player escapes the dungeon. */
490CCharacter EscapeEffect;
491
492/* The alpha of each of the three floor-title logos. */
493s32 rogoAlphaA[3];
494
495/* How long each of the three floor-title logos stays at full brightness. */
496s32 rogoAlphaW[3];
497
498/* The effect that plays as the player changes character. */
499CCharacter NewChangeFx;
500
501/* Where the player took the Atlamillia they last picked up. */
502sceVu0FVECTOR atraGetPos;
503
504/* Which way the player faced as they took it. */
505sceVu0FVECTOR atraGetRot;
506
507/* The effect that a short Atlamillia use lights the player with. */
508CCharacter shortAtraEffect;
509
510/* The models an opened treasure box shows, and the effects that play over them. */
511CMotionModel itemOpenSmall;
512CMotionModel itemOpenSmallFx;
513CMotionModel itemOpenBig;
514CMotionModel itemOpenBigFx;
515
516/* The debug text window the dungeon draws. */
517CDebugFont DbgMsg;
518
519/* Where the item the player is about to throw will land. */
520BOMB_INFO BombInfo;
521
522/* The dust the player kicks up as they run. */
523CRunEffect CRunFx__2;
524
525/* The wind that blows across the dungeon. */
526CWind kaze;
527
528/* Where the marker over an event stands. */
529sceVu0FVECTOR iventPos;
530
531/* The message windows the dungeon draws over the picture. */
532ClsMes DngMes1;
533ClsMes DngMes2;
534ClsMes DngMesStb;
535ClsMes BtEventMes0;
536ClsMes BtEventMes1;
537
538/* The marks that a weapon throws off as it breaks. */
539CHitMark WeaponCrashEffect;
540
541/* The marks the dungeon throws off a hit. */
542CHitMark HitMark[16];
543CHitPointMark HitPointMark[16];
544
545/* The marks that the hits the player took have left. */
546CHitPointMark MyHitPointMark[16];
547
548/* The effect that heals the player. */
549CHealEffect HealEffect;
550
551/* The models of the items lying on the floor. */
552CMainItemModel mainItemModel;
553
554/* The models of the items the player is running. */
555CActiveItemPack activeItem;
556
557/* How square on to the player each monster of the floor stands. */
558float MonstorPicupInner[36];
559
560/* The damage numbers the dungeon draws. */
561CHitValue HitValue[32];
562
563/* The shots the player's character has in the air. */
564CSHOT ShotData;
565
566/* The shot effects the dungeon can run. */
567CSHOT_EFFECT_PACK ShotEffect;
568
569/* The machine gun that Osmond's rapid-fire action shoots. */
570CSHOT_MACHINGUN OzumondShot;
571
572/* The flame that Osmond's flamethrower action shoots. */
573CSHOT_FIREBAR OzumondFire;
574
575/* The bullets that Osmond's machine gun shoots. */
576CHIT_MACHINGUN_EFFECT OzumondShotEffect;
577
578/* The collisions of the floor the player is on. */
579CCollisionData CColData;
580
581/* The bombs the player has thrown. */
582CItemBombEffect CBomb__2[3];
583
584/* The shock wave the dungeon can run. */
585CShockWave ShockWave;
586
587/* How fast the player fell the frame before. */
588sceVu0FVECTOR veloOld;
589
590/* The texture animations every dungeon texture runs. */
591CTextureAnime BtTexAnime;
592CTexAnimeData BtTexAnimeData[96];
593
594/* The texture animations of each character that walks the dungeon. */
595CTexAnimeData BtNPCTexAnimeData[4][32];
596
597/* One texture animation for every texture the player's model draws. */
598CTexAnimeData CharaMainTexAnim[64];
599
600/* The buffers the dungeon loads its models, messages and scripts into. */
601CDataAlloc2<1> MainModelBuffer(-1);
602CDataAlloc2<1> MapModelBuffer(-1);
603CDataAlloc2<1> CharaModelBuffer(-1);
604CDataAlloc2<1> WeaponModelBuffer(-1);
605CDataAlloc2<1> WEffectModelBuffer(-1);
606CDataAlloc2<1> MasekiModelBuffer(-1);
607CDataAlloc2<1> BtMesBuffer(-1);
608CDataAlloc2<1> BtSteebMesBuffer(-1);
609CDataAlloc2<1> BtStartLogoBuffer(-1);
610CDataAlloc2<1> MonstorModelBuffer(-1);
611
612/* Script working memory, one block per monster on the floor. */
613CDataAlloc2<1> MonstorScriptBuffer[16];
614
615/* The buffers the dungeon's item cache and battle scripts run out of. */
616CDataAlloc2<1> BtItemCashArea[6];
617CDataAlloc2<1> BtScriptWorkBuffer(-1);
618CDataAlloc2<1> BtCashBuffer(-1);
619CDataAlloc2<1> BtScriptBuffer(-1);
620CDataAlloc2<1> BtSystemScriptFileBuffer(-1);
621
622/* The name of the texture that the floor number draws with. */
623char floor_name[32];
624
625/* Where the camera looks, relative to what it follows. */
626sceVu0FVECTOR ref_off;
627
628/* Where Ruby's shot starts, and the way it flies. */
629sceVu0FVECTOR ruby_effect_pos;
630sceVu0FVECTOR ruby_effect_vec;
631
632/* The colour the ambient-colour animation drives the player's model to. */
633float unitAmbientAnime_rgb[3];
634
635/* The debug message overlay. */
636CDebugFont CDbgMsg;
637
638/* The overlay's initialised data, in the order retail's link lays it out. */
639
640// clang-format off
641/* The effect each playable character, and each of Ruby's and Osmond's forms, draws. */
642BT_SHOT_EFFECT MyEntryEffect_TOAN = {
643 "c01_fuusya", 0, 0,
644 {0.0f, 0.0f, 0.0f, 0.0f}, {20.0f, 0.0f, 0.0f, 0.0f},
645 160, 8, 8, 2, 2,
646 {0, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
647 {-1, -1, -1, -1},
648};
649// clang-format on
650
651// clang-format off
652BT_SHOT_EFFECT MyEntryEffect_SYAO = {
653 "mgan01", 0, 0,
654 {0.0f, 0.0f, 0.0f, 0.0f}, {1.5f, 0.0f, 0.0f, 0.0f},
655 160, 8, 0, 2, 2,
656 {0, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
657 {-1, -1, -1, -1},
658};
659// clang-format on
660
661// clang-format off
662BT_SHOT_EFFECT MyEntryEffect_GORO = {
663 "c06a_tameex", 0, 0,
664 {0.0f, 0.0f, 0.0f, 0.0f}, {15.0f, 0.0f, 0.0f, 0.0f},
665 160, 8, 0, 2, 2,
666 {0, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
667 {-1, -1, -1, -1},
668};
669// clang-format on
670
671// clang-format off
672BT_SHOT_EFFECT MyEntryEffect_RUBY_F1 = {
673 "c05_f03", 0, 1,
674 {2.5f, 2.5f, 0.0f, 0.0f}, {5.0f, 5.0f, 0.0f, 0.0f},
675 180, 8, 1, 3, 2,
676 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
677 {-1, -1, 101, -1},
678};
679// clang-format on
680
681// clang-format off
682BT_SHOT_EFFECT MyEntryEffect_RUBY_C1 = {
683 "c05_r03", 0, 1,
684 {2.5f, 2.5f, 0.0f, 0.0f}, {5.0f, 5.0f, 0.0f, 0.0f},
685 180, 8, 2, 3, 2,
686 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
687 {-1, -1, 102, -1},
688};
689// clang-format on
690
691// clang-format off
692BT_SHOT_EFFECT MyEntryEffect_RUBY_T1 = {
693 "c05_t03", 0, 1,
694 {2.5f, 2.5f, 0.0f, 0.0f}, {5.0f, 5.0f, 0.0f, 0.0f},
695 180, 8, 4, 3, 2,
696 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
697 {-1, -1, 103, -1},
698};
699// clang-format on
700
701// clang-format off
702BT_SHOT_EFFECT MyEntryEffect_RUBY_W1 = {
703 "c05_e03", 0, 1,
704 {2.5f, 2.5f, 0.0f, 0.0f}, {5.0f, 5.0f, 0.0f, 0.0f},
705 180, 8, 8, 3, 2,
706 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
707 {-1, -1, 104, -1},
708};
709// clang-format on
710
711// clang-format off
712BT_SHOT_EFFECT MyEntryEffect_RUBY_H1 = {
713 "c05_h03", 0, 1,
714 {2.5f, 2.5f, 0.0f, 0.0f}, {5.0f, 5.0f, 0.0f, 0.0f},
715 180, 8, 16, 3, 2,
716 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
717 {-1, -1, 105, -1},
718};
719// clang-format on
720
721// clang-format off
722BT_SHOT_EFFECT MyEntryEffect_UNGAGA = {
723 "c10a_ex", 0, 1,
724 {0.2f, 0.9f, 0.2f, 0.2f}, {8.0f, 8.0f, 6.0f, 6.0f},
725 90, 20, 8, 3, 2,
726 {0, 1, 2, 2}, -1, {0, 0}, 0.0f, 0,
727 {-1, -1, -1, -1},
728};
729// clang-format on
730
731// clang-format off
732BT_SHOT_EFFECT MyEntryEffect_OZUMOND_M = {
733 "mgan01", 0, 0,
734 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f},
735 10, 8, 0, 3, 2,
736 {1, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
737 {-1, -1, -1, -1},
738};
739// clang-format on
740
741// clang-format off
742BT_SHOT_EFFECT MyEntryEffect_OZUMOND_H = {
743 "rgan01", 0, 1,
744 {3.5f, 3.5f, 0.2f, 0.2f}, {0.0f, 4.5f, 0.0f, 0.0f},
745 180, 8, 0, 3, 2,
746 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
747 {-1, -1, -1, -1},
748};
749// clang-format on
750
751// clang-format off
752BT_SHOT_EFFECT MyEntryEffect_OZUMOND_H2 = {
753 "rgan02", 0, 1,
754 {3.5f, 3.5f, 0.2f, 0.2f}, {0.0f, 4.5f, 0.0f, 0.0f},
755 180, 8, 0, 3, 2,
756 {0, 1, 2, -1}, -1, {0, 0}, 0.0f, 0,
757 {-1, -1, -1, -1},
758};
759// clang-format on
760
761// clang-format off
762BT_SHOT_EFFECT MyEntryEffect_OZUMOND_V2 = {
763 "mgan02", 0, 0,
764 {0.0f, 0.5f, 0.2f, 0.2f}, {0.0f, 1.5f, 0.0f, 0.0f},
765 10, 8, 0, 3, 2,
766 {1, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
767 {-1, -1, -1, -1},
768};
769// clang-format on
770
771// clang-format off
772BT_SHOT_EFFECT MyEntryEffect_OZUMOND_G = {
773 "mgan03", 0, 0,
774 {0.0f, 0.5f, 0.2f, 0.2f}, {0.0f, 1.5f, 0.0f, 0.0f},
775 10, 8, 0, 3, 2,
776 {1, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
777 {-1, -1, -1, -1},
778};
779// clang-format on
780
781// clang-format off
782BT_SHOT_EFFECT MyEntryEffect_OZUMOND_S = {
783 "mgan04", 0, 0,
784 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f},
785 10, 8, 0, 3, 2,
786 {1, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
787 {-1, -1, -1, -1},
788};
789// clang-format on
790
791/* The effect table each playable character draws its own effects from. */
792BT_SHOT_EFFECT *MyEffectEntry_Tbl[15] = {
793 &MyEntryEffect_TOAN,
794 &MyEntryEffect_SYAO,
795 &MyEntryEffect_GORO,
796 &MyEntryEffect_RUBY_F1,
797 &MyEntryEffect_RUBY_C1,
798 &MyEntryEffect_RUBY_T1,
799 &MyEntryEffect_RUBY_W1,
800 &MyEntryEffect_RUBY_H1,
801 &MyEntryEffect_UNGAGA,
802 &MyEntryEffect_OZUMOND_M,
803 &MyEntryEffect_OZUMOND_H,
804 &MyEntryEffect_OZUMOND_H2,
805 &MyEntryEffect_OZUMOND_V2,
806 &MyEntryEffect_OZUMOND_G,
807 &MyEntryEffect_OZUMOND_S,
808};
809
810// clang-format off
811/* The effect each of the five Atlamillia draws as it is taken. */
812BT_SHOT_EFFECT MyEntryEffect_Maseki00 = {
813 "maseki_ex", 0, 1,
814 {0.0f, 0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f, 0.0f},
815 3, 35, 1, 3, 2,
816 {0, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
817 {-1, -1, -1, -1},
818};
819// clang-format on
820
821// clang-format off
822BT_SHOT_EFFECT MyEntryEffect_Maseki01 = {
823 "maseki_ex", 0, 1,
824 {0.0f, 0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f, 0.0f},
825 3, 35, 2, 3, 2,
826 {1, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
827 {-1, -1, -1, -1},
828};
829// clang-format on
830
831// clang-format off
832BT_SHOT_EFFECT MyEntryEffect_Maseki02 = {
833 "maseki_ex", 0, 1,
834 {0.0f, 0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f, 0.0f},
835 3, 35, 4, 3, 2,
836 {3, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
837 {-1, -1, -1, -1},
838};
839// clang-format on
840
841// clang-format off
842BT_SHOT_EFFECT MyEntryEffect_Maseki03 = {
843 "maseki_ex", 0, 1,
844 {0.0f, 0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f, 0.0f},
845 3, 35, 8, 3, 2,
846 {2, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
847 {-1, -1, -1, -1},
848};
849// clang-format on
850
851// clang-format off
852BT_SHOT_EFFECT MyEntryEffect_Maseki04 = {
853 "maseki_ex", 0, 1,
854 {0.0f, 0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f, 0.0f},
855 3, 35, 16, 3, 2,
856 {4, -1, -1, -1}, -1, {0, 0}, 0.0f, 0,
857 {-1, -1, -1, -1},
858};
859// clang-format on
860
861/* A matrix of zeros, which every light of a field starts from. */
862sceVu0FMATRIX ZeroMatrix = {
863 {0.0f, 0.0f, 0.0f, 0.0f},
864 {0.0f, 0.0f, 0.0f, 0.0f},
865 {0.0f, 0.0f, 0.0f, 0.0f},
866 {0.0f, 0.0f, 0.0f, 0.0f}
867};
868
869/* How far the fog reaches and how it thickens, on the front and the back floors. */
870float main_fogRate[4] = {1000.0f, 3500.0f, 0.0f, 255.0f};
871float sub_fogRate[4] = {1000.0f, 3500.0f, 0.0f, 255.0f};
872
873/* The ambient light every field starts from. */
874sceVu0FVECTOR def_ambientlight = {64.0f, 64.0f, 64.0f, 128.0f};
875
876/* The light colours every field starts from. */
877sceVu0FMATRIX def_lightcolor = {
878 {120.0f, 120.0f, 120.0f, 128.0f},
879 {0.0f, 0.0f, 0.0f, 0.0f },
880 {0.0f, 0.0f, 0.0f, 0.0f },
881 {0.0f, 0.0f, 0.0f, 0.0f }
882};
883
884/* How the treasure-box models, and the effects over them, play their opening motions. */
885MOTION_INFO itemOpenSmall_info = {10, 80, 0.5f, 0};
886MOTION_INFO itemOpenSmallFx_info = {10, 80, 0.5f, 0};
887MOTION_INFO itemOpenBig_info = {10, 80, 0.5f, 0};
888MOTION_INFO itemOpenBigFx_info = {10, 80, 0.5f, 0};
889
890/* How fast the player is being thrown. */
891sceVu0FVECTOR velo__2 = {0.0f, 0.0f, 0.0f, 0.0f};
892
893/* Where the right stick is pushing the camera. */
894sceVu0FVECTOR velo2 = {0.0f, 0.0f, 0.0f, 0.0f};
895
896/* The way the last blow throws the player. */
897sceVu0FVECTOR blowVelo = {0.0f, 0.0f, 0.0f, 0.0f};
898
899/* Every texture the dungeon loads on its way in, and the block each goes to. */
900LOADTEXTURE_INFO2 texdata__2[] = {
901 {"#frame_image#640#" SCREEN_HEIGHT_STR "#4", 1, 0},
902 {"dun/etc/cursor.img", 1, 0},
903 {"gatekey00.img", 1, 0},
904 {"#water#640#" HALF_BUFFER_HEIGHT_STR "#4", 13, 0},
905 {"dun/etc/atrtx.img", 22, 0},
906 {"wepready.img", 2, 0},
907 {"#shadow_buf#640#" HALF_BUFFER_HEIGHT_STR "#3", 15, 0},
908 {"dun/effect/basefx00.img", 18, 0},
909 {"basefx01.img", 18, 0},
910 {"dun/d01/effect/fx_foot.img", 18, 0},
911 {"dun/effect/bombfx00.img", 19, 0},
912 {"pause.img", 7, 0},
913 {"#dbgwork#640#" SCREEN_HEIGHT_STR "#3", 12, 0},
914 {"check/ankfont.img", 12, 0},
915#ifndef PAL
916 {"#mes_frame_buff#640#448#4", 26, 0},
917 {"#fontbase#512#256#1", 26, 0},
918 {"#fukidashibase#640#224#4", 26, 0},
919 {"meswin/syst04.img", 26, 0},
920 {"meswin/gaiji.img", 26, 0},
921 {"meswin/fuki256.img", 26, 0},
922#endif
923 {"element.img", 18, 0},
924 {"igetfx.img", 22, 0},
925 {0, 0, 0},
926};
927
928/* The textures the loading screen itself draws with. */
929LOADTEXTURE_INFO texdata2[3] = {
930 {"#dbgwork#640#" SCREEN_HEIGHT_STR "#3", 12, 0},
931 {"check/ankfont.img", 12, 0},
932 {"", 0, 0},
933};
934
935/* The overlay's initialised small data, in the order retail's link lays it out. */
936
937/* How far the camera is allowed to pull back. */
938s32 camera_dist_mode__3 = 1;
939
940/* The colour the fog draws, on the front and the back floors. */
941u8 main_fogColor[3] = {0x60, 0xA0, 0xEF};
942u8 sub_fogColor[3] = {0x60, 0xA0, 0xEF};
943
944/* How long the floor title has been on screen, in frames. */
945s32 startCnt2 = -1;
946
947/* Which character the menu had the cursor on when it opened. */
948s32 oldUnitNow = -1;
949
950/* Distances the camera keeps from what it follows. */
951float camera_up_near_dist = 60.0f;
952float camera_near_dist__2 = 10.0f;
953float camera_far_dist__2 = 80.0f;
954
955/* The colours the enemy life gauge draws the life it has left with. */
956spRGBA ELife1 = {0xFF, 0x00, 0x00, 0x80};
957spRGBA ELife2 = {0xFF, 0xB4, 0x00, 0x80};
958
959/* The colours the enemy life gauge draws its border with. */
960spRGBA ELifeB1 = {0x80, 0x9B, 0xFF, 0x80};
961spRGBA ELifeB2 = {0x80, 0x9B, 0xFF, 0x80};
962
963/* The colour the enemy life gauge draws the life it has lost with. */
964spRGBA ELifeN1 = {0x00, 0x00, 0x20, 0x80};
965
966/* The overlay's own small data, in the order retail's link lays it out. */
967
968/* What the dungeon hands the Georama editor to follow. */
969GAME_ENV GameEnv;
970
971/* The player's dungeon progress and party. */
972CUserStatus *UserStatus;
973
974/* How long the dungeon has been waiting for the player, in frames. */
975s32 timeOutCount;
976s32 BtRubyDoorKey;
977
978/* Whether the debug overlay draws. */
979s32 BtDebugFlag;
980
981/* Whether the game is playing itself for the attract loop. */
982s32 autoDemo;
983
984/* Whether the player has finished every floor of the dungeon. */
985s32 BtAllClear;
986s32 oldMsgNo;
987s32 oldMsgNo2;
988
989/* Polygons the step test has picked up this frame. */
990s32 colPolyNum;
991
992/* Whether the player is pressing the button that fires an action. */
993s32 PadInput_OK;
994
995/* Which button fires an action and which cancels one. */
996s32 PadInput_NO;
997
998/* The shot effect Ruby's charge is running, or -1 for none. */
999s32 ruby_effect_id;
1000
1001/* The camera that the dungeon draws through. */
1002CCameraFollow *NowCamera__3;
1003
1004/* The heading the eye camera looks along. */
1005float viewAngleH__2;
1006
1007/* The pitch the eye camera looks along. */
1008float viewAngleV__2;
1009
1010/* Which way the player is looking. */
1011s32 viewMode__2;
1012s32 faceEyeCount;
1013s32 cameraAuto;
1014
1015/* Whether the camera was moving itself before that. */
1016s32 cameraAutoOld;
1017
1018/* Whether the player is in the back dungeon rather than the main one. */
1019s32 BtUraDongeon;
1020
1022CDungeonMap *NowDngMap;
1023
1024/* The Dran field being drawn. */
1025CDranMapField *NowDranMapField;
1026
1027/* The events of the floor the dungeon is drawing. */
1028CDungeonEventMan *NowEventMan;
1029u8 main_bgColor[3];
1030u8 sub_bgColor[3];
1031
1032/* Which lighting the field draws under. */
1033s32 lightingMode;
1034
1035/* The monsters of the floor that the player is on. */
1036CMonstorUnit *NowMonstorUnit;
1037
1038/* Whether an effect is held over from the floor the player came from. */
1039s32 CEffectHold;
1040
1041/* Whether the effects are hidden this frame. */
1042s32 CEffectHyde;
1043
1044/* Whether a monster is held over from the floor the player came from. */
1045s32 CMonUnitHold;
1046
1047/* Whether the monsters are hidden this frame. */
1048s32 CMonUnitHyde;
1049
1050/* Whether the player's character holds an item out. */
1051s32 CharaMainHandViewFlag;
1052
1053/* Whether the monsters draw this frame. */
1054s32 MonstorViewFlag;
1055
1056/* The effect the player's character is shooting now. */
1057CSHOT_EFFECT *NowMainEffect;
1058
1059/* The model of the weapon that the player has equipped. */
1060CCharacter *NowWeapon;
1061
1062/* The weapon that the player has equipped. */
1063WEAPON_HAVE *NowWeaponHave;
1064
1065/* The items lying on the floor the dungeon is drawing. */
1066CRandomItem *RandomItem;
1067
1069CFrameVu1 *StealModel;
1070
1071/* The frame that the player's model hangs off. */
1072CFrameVu1 *CharaFrame;
1073
1074/* Whether the water splash is playing. */
1075s32 Water_Splash_actFlag;
1076
1077/* Whether the player is escaping the dungeon. */
1078s32 EscapeFlag;
1079
1080/* Whether the floor title is on screen. */
1081s32 rogoSwitch2;
1082
1083/* Where the floor title stood before the menu took the screen. */
1084s32 oldRogoY3;
1085
1086/* The vertical position of the floor title, in screen pixels. */
1087s32 rogoY3;
1088
1089/* Whether the character-change effect is playing. */
1090s32 NewChangeFxFlag;
1091
1092/* Which short Atlamillia use is running. */
1093s32 atraShortGetType;
1094float atraGetStatusRate__2;
1095s32 atraGetStatus;
1096
1097/* Whether the Atlamillia message board is up. */
1098s32 atraGetMsgBord;
1099float atraGetMsgBordRate;
1100u_int *shortAtraEffectPtr;
1101float itemNormalScale;
1102s32 itemOpenSmallFlag;
1103s32 itemOpenItemMds;
1104s32 itemOpenItemImg;
1105u_int *itemOpenItemChr;
1106
1107/* The model the item a gate holds draws with. */
1108CFrame *itemBoxModel;
1109float itemWeponScale;
1110s32 itemOpenBigFlag;
1111
1112/* How long the dungeon has waited before it opens the menu, in frames. */
1113s32 battleMenuWait;
1114
1115/* Which item the mini item menu has the cursor on. */
1116s32 miniItemSelNo;
1117
1118/* Which of the dungeon's loops runs this frame, as a BtGameMode. */
1119s32 BtGameModeFlag;
1120
1121/* Whether the dungeon draws anything at all this frame. */
1122s32 BtAllDrawFlag;
1123
1124/* Whether the models hold their step this frame. */
1125s32 driveStepHold;
1126
1127/* Whether the picture is being captured this frame. */
1128s32 frameCaputer;
1129
1130/* Whether the player's model skips interpolation on its next drive step. */
1131s32 driveNoInterpolate;
1132
1133/* Which character the player is walking as. */
1134s32 nowUnitNow;
1135CFrame *cursorFrame;
1136CFrame *bombCursorFrame;
1137CFrame *bicCursorFrame;
1138
1139/* Whether the lock-on cursor draws. */
1140s32 lockOnTargetDraw;
1141
1142/* Which monster is locked on, or -1 for none. */
1143s32 lockOnTargetNo;
1144
1145/* Whether an enemy is locked on. */
1146s32 lockOnTargetFlag;
1147
1148/* Which way the player is shifting the lock-on cursor, or -1 for neither. */
1149s32 targetCursorShiftNo;
1150
1151/* How many monsters the player could lock on to. */
1152s32 targetCursorShiftRot;
1153
1154/* The floor the player chose. */
1155s32 selectMapNo;
1156
1157/* Which of the running items the mini item menu has the cursor on. */
1158s32 itemNowSel;
1159
1160/* Whether the player has the map of this floor equipped. */
1161s32 BtEquipMap;
1162
1163/* Whether the player has a sun stone equipped. */
1164s32 BtEquipMasuisyou;
1165s32 iventInfo;
1166s32 iventMarker;
1167
1168/* Which event the player is standing on, or -1 for none. */
1169s32 iventActive;
1170
1171/* Whether the mini-map draws; SetMIniMapStatus takes it away and gives it back. */
1172s32 infoMap;
1173
1174/* What the mini-map drew before SetMIniMapStatus took it away. */
1175s32 infoMapOld;
1176
1177/* How hard the player is pushing the stick. */
1178float stickVector;
1179
1180/* How hard the player is pushing the right stick. */
1181float stickVector2;
1182
1183/* Whether the player is running on a speed boost. */
1184s32 BtBySpeedFlag;
1185
1186/* Whether the player asked to leave through the menu. */
1187s32 exitMenuFlag;
1188
1189/* Whether the item list the menu caches is still good. */
1190s32 BtItemListCashFlag;
1191
1192/* Which item that event holds, or -1 for none. */
1193s32 BtEventItemNo;
1194
1195/* The damage numbers the dungeon draws. */
1196CHitValue *NowHitValue;
1197
1198/* The shots the player's character has in the air. */
1199CSHOT *NowShotData;
1200
1201/* The shot effects the dungeon has running. */
1202CSHOT_EFFECT_PACK *NowShotEffect;
1203
1204/* The effect data Osmond's default weapon shoots. */
1205unsigned int *ozumond_default_effect;
1206
1207/* The collisions the dungeon tests against. */
1208CCollisionData *NowColData;
1209
1210/* The bombs the dungeon has running. */
1211CItemBombEffect *NowBombEffect;
1212
1213/* The shock wave the dungeon has running. */
1214CShockWave *NowShockWave;
1215
1216/* What the game is doing now, as a GameTask. */
1217s32 gameTask;
1218
1219/* Why the dungeon is being left, or zero while the player is still in it. */
1220s32 existFlag;
1221
1222/* Whether the player is leaving the trial dungeon. */
1223s32 tryalExit;
1224s32 DeadKeyWait;
1225s32 DeadKeyStartWait;
1226s32 BtEventData;
1227
1228/* Where the pack file the dungeon read last went. */
1229unsigned int *old_read_buffer;
1230
1231/* Which dungeon event is playing, or zero while the player has control. */
1232s32 BtEventMode;
1233
1234/* The texture that the floor number draws with. */
1235CTexture *TEX_Floor1;
1236CTexture *TEX_WepGage;
1237CTexture *TEX_Stayframe;
1238CTexture *TEX_Shadow;
1239
1240/* The texture a dropped pile of gold draws with. */
1241CTexture *GoldTex;
1242
1243/* How long the camera waits before it moves itself, in frames. */
1244s32 defCameraWait;
1245
1246/* Whether the monster names are hidden. */
1247s32 MonstorNameOff;
1248
1249#ifdef PAL
1250void LoadBaseTexture() {
1251 LOADTEXTURE_INFO2 info[96];
1252 int size;
1253 int i;
1254 char *name;
1255
1256 sprintf(texdata__2[2].name, "gatekey0%d.img", selectMapNo + 1);
1257
1258 char path[64] = "dun/pack/dun/pack/teximg2.pac";
1259
1260 if (LanguageCode > LANG_JAPANESE) {
1261 sprintf(path, "dun/pack/teximg2_%d.pac", LanguageCode);
1262 }
1263
1264 LoadFile(path, (void *) read_buffer, NULL);
1265 wait_now_loading_vsync();
1266
1267 i = 0;
1268
1269 while ((name = texdata__2[i].name) != NULL) {
1270 // A name that starts with '#' asks the manager for a blank page of
1271 // that size rather than for a file inside the pack.
1272 if (name[0] == '#') {
1273 info[i].name = name;
1274 } else {
1275 u_int *found = GetPackFile(read_buffer, name, &size);
1276
1277 if (found != NULL) {
1278 info[i].name = (char *) found;
1279 } else {
1280 printf("Error::Pack->FileNotFound [%d]%s!!\n", i, name);
1281 exit__2(-1);
1282 }
1283 }
1284
1285 info[i].block_no = texdata__2[i].block_no;
1286 i++;
1287 }
1288
1289 info[i].name = NULL;
1290 TexManager.LoadTextureBlock(-1, info);
1291
1292 // The message window's pages, and the three images the language's own
1293 // pack supplies in place of the names written here.
1294 LOADTEXTURE_INFO2 mes_info[8] = {
1295 {"#mes_frame_buff#640#480#4", 0x1A, 0},
1296 {"#fukidashibase#640#224#4", 0x1A, 0},
1297 {"#fontbase#512#256#1", 0x1A, 0},
1298 {"meswin/gaiji.img", 0x1A, 0},
1299 {"meswin/fuki256.img", 0x1A, 0},
1300 {"meswin/syst04.img", 0x1A, 0},
1301 };
1302 char mes_path[64] = "meswin/mes_tex.pak";
1303
1304 if (LanguageCode > LANG_JAPANESE) {
1305 sprintf(mes_path, "meswin/mes_tex_%d.pak", LanguageCode);
1306 }
1307
1308 LoadFile(mes_path, read_buffer, NULL);
1309 wait_now_loading_vsync();
1310 mes_info[3].name = (char *) GetPackFile(read_buffer, "gaiji.img", NULL);
1311 mes_info[4].name = (char *) GetPackFile(read_buffer, "fuki256.img", NULL);
1312 mes_info[5].name = (char *) GetPackFile(read_buffer, "syst04.img", NULL);
1313 TexManager.LoadTextureBlock(-1, mes_info);
1314}
1315#else
1316void LoadBaseTexture() {
1317 LOADTEXTURE_INFO2 info[97];
1318 int size;
1319 int i;
1320 char *name;
1321
1322 sprintf(texdata__2[2].name, "gatekey0%d.img", selectMapNo + 1);
1323
1324 unsigned int *pack = read_buffer;
1325
1326 LoadFile("dun/pack/teximg2.pac", pack, NULL);
1327 wait_now_loading_vsync();
1328
1329 i = 0;
1330
1331 while ((name = texdata__2[i].name) != NULL) {
1332 // A name that starts with '#' asks the manager for a blank page of
1333 // that size rather than for a file inside the pack.
1334 if (name[0] == '#') {
1335 info[i].name = name;
1336 } else {
1337 u_int *found = GetPackFile(read_buffer, name, &size);
1338
1339 if (found != NULL) {
1340 info[i].name = (char *) found;
1341 } else {
1342 printf("Error::Pack->FileNotFound [%d]%s!!\n", i, name);
1343 exit__2(-1);
1344 }
1345 }
1346
1347 info[i].block_no = texdata__2[i].block_no;
1348 i++;
1349 }
1350
1351 info[i].name = NULL;
1352 TexManager.LoadTextureBlock(-1, info);
1353}
1354#endif
1355
1356int LoadTempTexture(char **files, int block, char *buffer) {
1357 LOADTEXTURE_INFO2 info[7] = {0};
1358 int i;
1359 int total;
1360 int size;
1361
1362 i = 0;
1363 total = 0;
1364
1365 while (files[i] != NULL) {
1366 LoadFile(files[i], buffer, &size);
1367 wait_now_loading_vsync();
1368 total += size;
1369 info[i].block_no = block;
1370 info[i].name = buffer;
1371 buffer += ((size >> 6) + 1) << 6;
1372 i++;
1373 }
1374
1375 TexManager.DeleteTextureBlock(block);
1376 TexManager.LoadTextureBlockEX(block, info);
1377 return total;
1378}
1379
1380void SetTempTexture(int block, char *name) {
1381 LOADTEXTURE_INFO2 info[2] = {0};
1382
1383 info[0].block_no = block;
1384 info[0].name = name;
1385 TexManager.DeleteTextureBlock(block);
1386 TexManager.LoadTextureBlockEX(block, info);
1387}
1388
1389void MemoryMapDump() {
1390 printf("MainVisualData \t%d/%d\n", MainModelBuffer.used, 0x9470);
1391 printf("MotionData \t%d/%d\n", MotionData.used, 10000);
1392 printf("CharaModelBuffer\t%d/%d\n", CharaModelBuffer.used, 0x33450);
1393 printf("MasekiModelBuffer\t%d/%d\n", MasekiModelBuffer.used, 0xFDE8);
1394 printf("MapVisualData \t%d/%d\n", MapModelBuffer.used, 0xA7F80);
1395 s32 monster_size = MonstorModelBuffer.limit;
1396
1397 printf("MonstorModelBuffer\t%d/%d\n", MonstorModelBuffer.used, monster_size);
1398 printf("SystemScriptBuffer\t%d/%d\n", BtSystemScriptFileBuffer.used, 0x88B8);
1399 printf("StartLogoBuffer\t %d/%d\n", BtStartLogoBuffer.used, 5000);
1400 printf("BtMesBuffer\t %d/%d\n", BtMesBuffer.used, 0x2904);
1401 printf("BtSteebMesBuffer\t%d/%d\n", BtSteebMesBuffer.used, 0xDAC);
1402 TexManager.print_buff_info();
1403}
1404
1405void GameInit() {
1406 int size;
1407 char name[64];
1408 char gate_name[32];
1409 short *mes;
1410
1411 BtDebugFlag = 0;
1412 exitMenuFlag = 0;
1413 BtAllDrawFlag = 0;
1414 selectMapNo = main_select_menu_no;
1415 UserStatus = (CUserStatus *) SaveData->GetDngStatus();
1416 UserStatus->Init();
1417
1418 if (BtEventInfo.no_status_recover != 1) {
1419 int i;
1420 CUserStatus *status = UserStatus;
1421
1422 for (i = 0; i < 6; i++) {
1423 status->hp[i] = status->max_hp[i];
1424 status->ailments[i] = 0;
1425 status->ailment_frames[i] = 0;
1426 }
1427
1428 status->res_limit_zone_current = RES_LIMIT_ZONE_NONE;
1429 }
1430
1431 int map = selectMapNo;
1432 CUserStatus *status = UserStatus;
1433
1434 status->cur_georama = map;
1435
1436 sceVu0CopyMatrix(main_light, ZeroMatrix);
1437 sceVu0CopyMatrix(main_lightcolor, def_lightcolor);
1438 sceVu0CopyVector(main_ambientlight, def_ambientlight);
1439 sceVu0CopyMatrix(sub_light, ZeroMatrix);
1440 sceVu0CopyMatrix(sub_lightcolor, def_lightcolor);
1441 sceVu0CopyVector(sub_ambientlight, def_ambientlight);
1442
1443 InitializeDataBuffer();
1444 SetDataBuffer(&MainModelBuffer, 0x9470);
1445 SetDataBuffer(&MotionData, 10000);
1446 SetDataBuffer(&CharaModelBuffer, 0x33450);
1447 SetDataBuffer(&MasekiModelBuffer, 0xFDE8);
1448 SetDataBuffer(&TextureData, 0xB3B0);
1449 SetDataBuffer(&BtSystemScriptFileBuffer, 0x88B8);
1450 SetDataBuffer(&BtMesBuffer, 0x2904);
1451 SetDataBuffer(&BtSteebMesBuffer, 0xDAC);
1452 SetDataBuffer(&BtStartLogoBuffer, 5000);
1453 SetDataBuffer(&BtScriptWorkBuffer, 100000);
1454
1455 for (int i = 0; i < 6; i++) {
1456 SetDataBuffer(&BtItemCashArea[i], 2501);
1457 }
1458
1459 for (int i = 0; i < 16; i++) {
1460 SetDataBuffer(&MonstorScriptBuffer[i], 1875);
1461 }
1462
1463 SetDataBuffer(&MapModelBuffer, 0xA7F80);
1464 SetPacketReadBuffer(0x9344, 0x445C0);
1465 old_read_buffer = read_buffer;
1466
1467 MainCamera__4.SetDistance(60.0f);
1468 MainCamera__4.SetHeight(0.0f);
1469 MainCamera__4.SetFollow(0.0f, 0.0f, 0.0f);
1470 MainCamera__4.Step(10);
1471 MainCamera__4.SetSpeed(8.0f);
1472 MainCamera__4.FollowOn();
1473 SubCamera.SetDistance(60.0f);
1474 SubCamera.SetHeight(0.0f);
1475 SubCamera.SetFollow(0.0f, 0.0f, 0.0f);
1476 SubCamera.Step(10);
1477 SubCamera.SetSpeed(8.0f);
1478 SubCamera.FollowOn();
1479 NowCamera__3 = &MainCamera__4;
1480
1481 NowDngMap = &MainDungeonMap;
1482 NowDngMap->initalize();
1483 BtTexAnime.Initialize(BtTexAnimeData, 96);
1484
1485 for (int i = 0; i < 64; i++) {
1486 CDungeonEvent *slot = &DngEventMan.slot[i];
1487
1488 slot->name[0] = '\0';
1489 slot->script_no = -1;
1490 slot->parts_id = -1;
1491 slot->switch_on = false;
1492 slot->enabled = false;
1493 }
1494
1495 for (int i = 0; i < 96; i++) {
1496 CDungeonEventData *state = &DngEventMan.event[i];
1497
1498 state->event = NULL;
1499 state->switch_on = false;
1500 state->enabled = false;
1501 state->hold = 0;
1502 state->chara_done = -1;
1503 }
1504
1505 NowEventMan = &DngEventMan;
1506 lightingMode = 0;
1507
1508 for (int i = 0; i < 12; i++) {
1509 CDranMapField *field = &DranMapField.field[i];
1510
1511 field->Initialize();
1512 DranMapField.collision[i] = 0;
1513 DranMapField.state[i] = 3;
1514 }
1515
1516 DranMapField.field_count = 0;
1517 DranMapField.collision_count = 0;
1518 NowDranMapField = DranMapField.field;
1519 NowColData = &CColData;
1520
1521 for (int i = 0; i < 12; i++) {
1522 ShotData.used[i] = 0;
1523 }
1524
1525 NowShotData = &ShotData;
1526 HealEffect.active = false;
1527 WaterSplash_Init();
1528
1529 for (int i = 0; i < 5; i++) {
1530 ShotEffect.effect[i].Initialize();
1531 }
1532
1533 NowShotEffect = &ShotEffect;
1534
1535 for (int i = 0; i < 5; i++) {
1536 MasekiEffect[i].Initialize();
1537 }
1538
1539 for (int i = 0; i < 16; i++) {
1540 OzumondShot.damage[i] = 1;
1541 OzumondShot.age[i] = 0;
1542 }
1543
1544 for (int i = 0; i < 64; i++) {
1545 OzumondFire.damage[i] = 1;
1546 OzumondFire.state[i] = -1;
1547 }
1548
1549 OzumondFire.start_index = 0;
1550 EscapeFlag = 0;
1551 WeaponCrashEffect.Initialize();
1552
1553 for (int i = 0; i < 16; i++) {
1554 HitMark[i].Initialize();
1555 }
1556
1557 for (int i = 0; i < 16; i++) {
1558 OzumondShotEffect.timer[i] = -1;
1559 }
1560
1561 NewChangeFxFlag = 0;
1562
1563 for (int i = 0; i < 32; i++) {
1564 HitValue[i].active = false;
1565 HitValue[i].frame = NULL;
1566 }
1567
1568 NowHitValue = HitValue;
1569
1570 MainMonstorUnit.model_count = 0;
1571 MainMonstorUnit.current_monster = 0;
1572
1573 for (int i = 0; i < 16; i++) {
1574 MainMonstorUnit.script[i] = &MonstorScriptBuffer[i];
1575 }
1576
1577 MainMonstorUnit.requested_event = -1;
1578 MainMonstorUnit.CleanViewMonstor(0);
1579 BtSetEventExtendTable();
1580 NowMonstorUnit = &MainMonstorUnit;
1581 NowWeaponHave = &WeaponHave;
1582 SetWeaponAttachStatus(NowWeaponHave);
1583 BtEventMode = 0;
1584 EdEventInfo.projection = -1.0f;
1585 EdEventInfo.screen_filter = false;
1586 EdFadeInit();
1587 ClearGateKeyStack();
1588 TexManager.Initialize(0x3FE0);
1589 LoadBaseTexture();
1590
1591 LoadFileMenuData("itempack.img", (unsigned int *) read_buffer);
1592 wait_now_loading_vsync();
1593 TexManager.EnterIMGFile((unsigned char *) read_buffer, -1, 0, 0);
1594 LoadFileMenuData("stayframe.img", (unsigned int *) read_buffer);
1595 wait_now_loading_vsync();
1596 TexManager.EnterFixTextureZ((unsigned char *) read_buffer);
1597
1598 mainItemModel.Initialize();
1599
1600 for (int i = 0; i < 4; i++) {
1601 activeItem.item[i] = -1;
1602 activeItem.model[i] = -1;
1603 }
1604
1605 activeItem.model[8] = -1;
1606 activeItem.now = 1;
1607 activeItem.models = &mainItemModel;
1608 BtSetActiveItemModel(read_buffer);
1609
1610 BtActStatus.action_on = 0;
1611 BtActStatus.main_motion = -1;
1612 BtActStatus.hand_motion = -1;
1613 BtActStatus.motion_no = 0;
1614 BtActStatus.jumping = 0;
1615 BtActStatus.action_gauge = 100.0f;
1616 BtActStatus.gauge_exhausted = 0;
1617 BtActStatus.gauge_flash = 0;
1618 BtActStatus.recoil_frames = 0;
1619 BtActStatus.invincible_frames = 0;
1620 BtActStatus.shadow_visible = true;
1621 BtActStatus.weapon_visible = 1;
1622 BtActStatus.charge_level = 0;
1623 BtActStatus.guard_mode = 0;
1624 BtActStatus.can_act = 1;
1625 BtActStatus.unk_066 = 1;
1626 BtActStatus.slow_walking = 0;
1627 BtActStatus.camera_hold = 0;
1628 BtActStatus.action_busy = 0;
1629 BtActStatus.movement_locked = 0;
1630 BtActStatus.in_presentation = 0;
1631 BtActStatus.in_water = false;
1632 BtActStatus.action_no = 0;
1633 BtActStatus.gauge_exhausted = 0;
1634 BtActStatus.refill_frames = 10;
1635 BtActStatus.swapped_on_death = 0;
1636 BtActStatus.combo_window = 0;
1637 BtActStatus.combo_queued = 0;
1638 BtActStatus.move_vector[0] = 0.0f;
1639 BtActStatus.move_vector[1] = 0.0f;
1640 BtActStatus.move_vector[2] = 0.0f;
1641 BtActStatus.move_vector[3] = 0.0f;
1642 BtActStatus.move_power = 0.0f;
1643 BtActStatus.move_power_decay = 0.0f;
1644 BtActStatus.hud_shake_frames = 0;
1645 BtActStatus.hud_shake_y = 0;
1646 BtActStatus.frames_since_attack = 3600;
1647 BtActStatus.camera_shake_frames = 0;
1648 BtActStatus.fast_camera_frames = 0;
1649 BtActStatus.event_block_frames = 0;
1650 BtActStatus.swinging = 0;
1651 EdEventInfo.player_draw = true;
1652 EdEventInfo.player_shadow_draw = true;
1653 camera_dist_mode__3 = 2;
1654 cameraAuto = 0;
1655 faceEyeCount = 0;
1656 DispFade__3.FadeInit(128.0f);
1657 DispFade__3.FadeInStart(1.0f);
1658
1659 switch (LanguageCode) {
1660 case LANG_JAPANESE:
1661 PadInput_OK = 0x20;
1662 PadInput_NO = 0x40;
1663 break;
1664 case LANG_ENGLISH_US:
1665 default:
1666 PadInput_OK = 0x40;
1667 PadInput_NO = 0x20;
1668 break;
1669 }
1670
1671 DngMes1.Preset(MES_PRESET_SYSTEM);
1672 DngMes1.page_arrow = false;
1673 DngMes1.centre_rows = true;
1674 DngMes1.tex_block = 26;
1675 DngMes1.stay_frame = true;
1676 DngMes1.columns = 15;
1677 DngMes1.rows = 3;
1678 DngMes1.text_x = 48;
1679 DngMes1.text_y = 368;
1680 DngMes1.char_width = 11;
1681 DngMes1.char_height = 22;
1682 DngMes1.style = MES_EDGE_NONE;
1683 DngMes1.tex_buff = MesWinTexBuff_01;
1684
1685 DngMes2.Preset(MES_PRESET_SYSTEM);
1686 DngMes2.page_arrow = false;
1687 DngMes2.centre_rows = true;
1688 DngMes2.tex_block = 26;
1689 DngMes2.stay_frame = false;
1690 DngMes2.columns = 15;
1691 DngMes2.rows = 3;
1692 DngMes2.text_x = 320;
1693 DngMes2.text_y = 346;
1694 DngMes2.char_width = 11;
1695 DngMes2.char_height = 22;
1696 DngMes2.tex_buff = MesWinTexBuff_02;
1697
1698 DngMesStb.text_columns = MES_WIN_COLUMNS;
1699 DngMesStb.text_rows = 10;
1700 DngMesStb.text_len = 0;
1701 DngMesStb.text_width = 0;
1702 DngMesStb.text_height = 0;
1703 DngMesStb.fade = 0;
1704 DngMesStb.fade_in = true;
1705 DngMesStb.text_rate = DngMesStb.text_rate_set;
1706 DngMesStb.waiting = false;
1707 DngMesStb.text_at = 0;
1708 DngMesStb.text_no = 0;
1709 DngMesStb.text_from = 0;
1710 DngMesStb.page_from = 0;
1711 DngMesStb.InitMesWinTbl();
1712 DngMesStb.clut_now = DngMesStb.clut_default;
1713 DngMesStb.wait = 0;
1714 DngMesStb.blink = 0;
1715 DngMesStb.auto_page_wait = 0;
1716 DngMesStb.mes_made = -1;
1717 DngMesStb.edge_alpha = 128;
1718
1719 for (int i = 0; i < 10; i++) {
1720 DngMesStb.mes_no[i] = -1;
1721 }
1722
1723 for (int i = 0; i < 8; i++) {
1724 DngMesStb.values[i] = 0;
1725 }
1726
1727 DngMesStb.value = 0;
1728 DngMesStb.value_signed = false;
1729 DngMesStb.value_show = true;
1730 DngMesStb.value_narrow = false;
1731 DngMesStb.space_width = -1;
1732 DngMesStb.space_area = -1;
1733 DngMesStb.cursor_row = -1;
1734 DngMesStb.cursor_y = 0;
1735 DngMesStb.cursor_lit = false;
1736
1737 for (int i = 0; i < 10; i++) {
1738 DngMesStb.line_pos[i].x = -1;
1739 DngMesStb.line_pos[i].y = -1;
1740 }
1741
1742 DngMesStb.Preset(MES_PRESET_NAME);
1743 DngMesStb.columns = 21;
1744 DngMesStb.rows = 4;
1745 DngMesStb.text_rate = 1.0f;
1746 DngMesStb.text_rate_set = 1.0f;
1747 DngMesStb.fade_speed = 1.0f;
1748 DngMesStb.page_arrow = false;
1749 DngMesStb.tex_block = 26;
1750 DngMesStb.tail_on = false;
1751 DngMesStb.clut_now = Color2Clut(FONT_COLOR_WHITE) & 0xFF;
1752 DngMesStb.columns = 15;
1753 DngMesStb.char_width = 12;
1754 DngMesStb.char_height = 24;
1755 DngMesStb.tex_buff = MesWinTexBuff_11;
1756
1757 BtEventMes0.char_width = 12;
1758 BtEventMes0.char_height = 20;
1759 BtEventMes0.columns = 21;
1760 BtEventMes0.rows = 4;
1761 BtEventMes0.text_rate = 0.3f;
1762 BtEventMes0.text_rate_set = 0.3f;
1763 BtEventMes0.tex_block = 26;
1764 BtEventMes0.style = MES_EDGE_NONE;
1765 BtEventMes0.page_arrow = false;
1766 BtEventMes0.centre_rows = true;
1767 BtEventMes0.fade_speed = 0.1f;
1768 BtEventMes0.page_arrow = true;
1769 BtEventMes0.tex_buff = MesWinTexBuff_01;
1770
1771 BtEventMes1.columns = 22;
1772 BtEventMes1.rows = 5;
1773 BtEventMes1.char_width = 12;
1774 BtEventMes1.char_height = 24;
1775 BtEventMes1.text_rate = 0.3f;
1776 BtEventMes1.text_rate_set = 0.3f;
1777 BtEventMes1.tex_block = 26;
1778 BtEventMes1.style = MES_EDGE_NONE;
1779 BtEventMes1.page_arrow = false;
1780 BtEventMes1.centre_rows = true;
1781 BtEventMes1.fade_speed = 0.1f;
1782 BtEventMes1.page_arrow = true;
1783 BtEventMes1.tex_buff = MesWinTexBuff_02;
1784
1785 mes = (short *) (BtMesBuffer.base + BtMesBuffer.used * 16);
1786 sprintf(name, "dun/message/ww_mes/dunmsd00_%d.mes", LanguageCode);
1787 LoadFile(name, mes, &size);
1788 wait_now_loading_vsync();
1789 DngMes1.SetBuff(mes);
1790 DngMes2.SetBuff(mes);
1791 MonsterNameInit(&DngMes2, mes, MesWinTexBuff_02);
1792 BtEventMes0.SetBuff(mes);
1793 BtMesBuffer.Alloc((((size >> 6) + 1) << 6) >> 4);
1794 BtMesBuffer.Align64();
1795
1796 mes = (short *) (BtMesBuffer.base + BtMesBuffer.used * 16);
1797 sprintf(name, "dun/message/ww_mes/font18_%d.mes", LanguageCode);
1798 LoadFile(name, mes, &size);
1799 wait_now_loading_vsync();
1800 BtEventMes1.SetBuff(mes);
1801 BtMesBuffer.Alloc((((size >> 6) + 1) << 6) >> 4);
1802 BtMesBuffer.Align64();
1803
1804 mes = (short *) (BtMesBuffer.base + BtMesBuffer.used * 16);
1805 LoadFile("meswin/system14e.bin", mes, &size);
1806 wait_now_loading_vsync();
1807 BtMesBuffer.Alloc((size >> 4) + 1);
1808 DngMes1.SetBuff_system(SystemMes);
1809 DngMes2.SetBuff_system(SystemMes);
1810 BtEventMes0.SetBuff_system(mes);
1811 ClearSystemMes();
1812
1813 DngMessMan.message = -1;
1814 DngMessMan.timer = 0;
1815 DngMessMan.enabled = true;
1816 oldMsgNo = -1;
1817 oldMsgNo2 = -1;
1818
1819 MainWeapon.Initialize();
1820 DefaultWeapon.Initialize();
1821 CrashWeapon.Initialize();
1822
1823 for (int i = 0; i < 32; i++) {
1824 CWeaponFx.used[i] = 0;
1825 }
1826
1827 CWeaponFx.colour[0].r = CWeaponFx.colour[2].r = 0x40;
1828 CWeaponFx.colour[0].g = CWeaponFx.colour[2].g = 0x40;
1829 CWeaponFx.colour[0].b = CWeaponFx.colour[2].b = 0x40;
1830 CWeaponFx.colour[1].r = CWeaponFx.colour[3].r = 6;
1831 CWeaponFx.colour[1].g = CWeaponFx.colour[3].g = 6;
1832 CWeaponFx.colour[1].b = CWeaponFx.colour[3].b = 6;
1833 CWeaponFx.cursor = 0;
1834 CWeaponFx.timer = 0;
1835
1836 for (int i = 0; i < 4; i++) {
1837 CWeaponElFx[i].Initialize();
1838 }
1839
1840 SndSetReadBuffer(read_buffer);
1841
1842 if (EdEventInfo.map_jump_bgm_play != 0) {
1843 SndBgmLoad(selectMapNo + 100);
1844 SndBgmPlay(0);
1845 }
1846
1847 SndSoundLoad(selectMapNo + 100);
1848
1849 if (selectMapNo == DUNGEON_DEMON_SHAFT) {
1850 SndSePlay(SE_AMBIENT_DUNGEON_HISS, 0, 0);
1851 }
1852
1853 if (selectMapNo == DUNGEON_DIVINE_BEAST_CAVE) {
1854 SndSePlay(SE_AMBIENT_DUNGEON_HISS, 0, 0);
1855 SndSePlay(SE_AMBIENT_CAVE_DRIPS, 0, 0);
1856 }
1857
1858 if (selectMapNo == DUNGEON_SHIPWRECK) {
1859 SndSePlay(SE_AMBIENT_SHIPWRECK, 0, 0);
1860 }
1861
1862 if (selectMapNo >= DUNGEON_SUN_MOON_TEMPLE) {
1863 SndSePlay(SE_AMBIENT_DEEP_DUNGEON, 0, 0);
1864 }
1865
1866 SndAmbientPlay(0);
1867 SndAmbientSetVol(0);
1868 BtBattleMusic_Init();
1869
1870 LoadData();
1871 LoadStartLogo(selectMapNo);
1872 initBlendCnt(8, 1.0f);
1873 atraGetStatus = 0;
1874 atraGetStatusRate__2 = 0.0f;
1875 atraGetMsgBord = 0;
1876 CMonUnitHold = 0;
1877 CMonUnitHyde = 0;
1878 CEffectHold = 0;
1879 CEffectHyde = 0;
1880 itemOpenSmallFlag = 0;
1881 itemOpenBigFlag = 0;
1882 gateItemFlag = 0;
1883 driveStepHold = 0;
1884 driveNoInterpolate = 0;
1885 int dungeon = selectMapNo;
1886
1887 if (UserStatus->floor_reached[dungeon] == -1) {
1888 BtAtraListMake(dungeon);
1889 }
1890
1891 UserStatus->water_drain_disable = 0;
1892 UserStatus->step_disable = 0;
1893 nowUnitNow = UserStatus->cur_chara;
1894 rogoY3 = 32;
1895 BtStatusAlarmInit();
1896
1897 for (int i = 0; i < 3; i++) {
1898 CBomb__2[i].Initialize();
1899 }
1900
1901 NowBombEffect = CBomb__2;
1902 ShockWave.active = false;
1903 NowShockWave = &ShockWave;
1904 BombInfo.aiming = false;
1905 frameCaputer = 0;
1906 BtActStatus.player_visible = 1;
1907 viewMode__2 = 0;
1908 itemNowSel = 1;
1909 iventInfo = DNG_EVENT_NONE;
1910 iventMarker = 0;
1911 int minimap = UserStatus->minimap_status;
1912
1913 if (minimap != 3) {
1914 infoMap = 1;
1915 infoMapOld = 1;
1916 } else {
1917 infoMap = 0;
1918 infoMapOld = 0;
1919 }
1920
1921 BtActStatus.player_visible = 1;
1922 CharaMainHandViewFlag = 0;
1923 MonstorViewFlag = 1;
1924 RsetUnitAmbientAnime();
1925 GamePad.AutoRepeatOff();
1926 GamePad.MenuModeOff();
1927 lockOnTargetFlag = 0;
1928 lockOnTargetNo = -1;
1929 EnemyLifeGage.on = 0;
1930 EnemyLifeGage.draw = true;
1931 existFlag = 0;
1932 tryalExit = 0;
1933 timeOutCount = 0;
1934 TEX_WepGage = TexManager.GetTexture("wepready", -1);
1935 TEX_Stayframe = TexManager.GetTexture("stayframe", -1);
1936 TEX_Shadow = TexManager.GetTexture("shadow_buf", -1);
1937 sprintf(gate_name, "gatekey0%d", selectMapNo + 1);
1938 GoldTex = TexManager.GetTexture(gate_name, -1);
1939
1940 if (GoldTex == NULL) {
1941 printf("******** ERR\n");
1942 }
1943
1944 BtMapJumpCashClear();
1945
1946 CDungeonMap *map_now = NowDngMap;
1947
1948 map_now->draw_dist_scale = 4.0f;
1949 ((CDngStatusData *) UserStatus)->SetNowFloor(0);
1950
1951 CUserStatus *status_now = UserStatus;
1952
1953 status_now->prev_floor = -1;
1954
1955 DbgMsg.texture_name = "dbgwork";
1956 DbgMsg.x = 32;
1957 DbgMsg.y = 80;
1958 DbgMsg.width = 256;
1959 DbgMsg.height = 224;
1960 DbgMsg.alpha = 96;
1961 DebugInfomationInit();
1962 EdDSetFont(&DbgMsg);
1963 StealItem.Initialize(StealModel);
1964 BtItemListCashFlag = 0;
1965 defCameraWait = 0;
1966 MonstorNameOff = 0;
1967 BtSystemScriptEventInfoInit();
1968 BtSystemScriptInit();
1969 BtSystemScriptLoad(selectMapNo);
1970 MemoryMapDump();
1971 BtGameModeFlag = BT_GAME_MODE_PLAY;
1972 BtEventInfo.script_no = 100;
1973 BtEventInfo.ext_memory = false;
1974 gameTask = GAME_TASK_SCRIPT_START;
1975}
1976
1977int GameLoop() {
1978 float fade[4];
1979 int i;
1980
1981 switch (BtGameModeFlag) {
1982 case BT_GAME_MODE_PLAY:
1983 MoveChara();
1984 break;
1985 case BT_GAME_MODE_BATTLE_MENU:
1986 if (BattleMenuCursor() == 0) {
1987 BtGameModeFlag = BT_GAME_MODE_PLAY;
1988 }
1989
1990 break;
1991 }
1992
1993 switch (BtGameModeFlag) {
1994 case BT_GAME_MODE_PLAY:
1995 MainDraw();
1996 break;
1997 case BT_GAME_MODE_BATTLE_MENU:
1998 BattleMenuDraw();
1999 break;
2000 case BT_GAME_MODE_ITEM_SELECT:
2001 if (EventItemSelectLoop(&miniItemSelNo) != 0) {
2002 BtGameModeFlag = BT_GAME_MODE_PLAY;
2003 }
2004
2005 break;
2006 case BT_GAME_MODE_ENTRANCE_MENU: {
2007 int floor = DunEnterMenuLoop();
2008
2009 if (floor != -1) {
2010 if (BtEventInfo.entrance_result != NULL) {
2011 BtEventInfo.entrance_result->i = floor;
2012 }
2013
2014 BtEventInfo.entrance_result = NULL;
2015 ((CDngStatusData *) UserStatus)->SetNowFloor(floor);
2016 BtGameModeFlag = BT_GAME_MODE_PLAY;
2017 }
2018
2019 break;
2020 }
2021 case BT_GAME_MODE_ESCAPE_MSG: {
2022 int answer = DngEscapeMsgLoop();
2023
2024 if (answer > 0) {
2025 if (BtEventInfo.escape_result != NULL) {
2026 BtEventInfo.escape_result->i = answer;
2027 }
2028
2029 BtEventInfo.escape_result = NULL;
2030 BtGameModeFlag = BT_GAME_MODE_PLAY;
2031 }
2032
2033 break;
2034 }
2035 case BT_GAME_MODE_CHARA_CHANGE: {
2036 int chara = CharaChangeLoop();
2037
2038 BtMiniChrSelectNo = chara;
2039
2040 if (chara != 0) {
2041 BtGameModeFlag = BT_GAME_MODE_PLAY;
2042 }
2043
2044 break;
2045 }
2046 }
2047
2048 if (existFlag != 0) {
2049 while (ReadBGSync() == 1) {
2050 }
2051
2052 // A floor the player is thrown out of keeps its music; one they leave
2053 // on their own starts the town music again.
2054 if (EdEventInfo.map_jump_bgm_stop != 0) {
2055 SndExit();
2056 SndBgmInit();
2057 } else {
2058 SndStopAllSe();
2059 }
2060
2061 EdGetFadeColor(fade);
2062 MGSetBGColor(fade);
2063 ((CDngStatusData *) UserStatus)->LostGateKey();
2064
2065 if (BtEventInfo.no_status_recover == 0) {
2066 CUserStatus *status = UserStatus;
2067
2068 for (i = 0; i < 6; i++) {
2069 status->hp[i] = status->max_hp[i];
2070 status->ailments[i] = 0;
2071 status->ailment_frames[i] = 0;
2072 }
2073
2074 status->res_limit_zone_current = RES_LIMIT_ZONE_NONE;
2075 }
2076
2077 UserStatus->cur_chara = CHARA_TOAN;
2078
2079 CUserStatus *leaving = UserStatus;
2080
2081 leaving->prev_floor = -1;
2082 return existFlag;
2083 }
2084
2085#ifdef PAL
2086 // In debug mode, Start pressed while Select is held leaves the dungeon.
2087 if (DebugMode != 0 && GamePad.On(PAD_SELECT) != 0 && GamePad.Down(PAD_START) != 0) {
2088 while (ReadBGSync() == 1) {
2089 }
2090
2091 SndExit();
2092
2093 CUserStatus *leaving = UserStatus;
2094
2095 leaving->prev_floor = -1;
2096 return 1;
2097 }
2098#endif
2099
2100 if (tryalExit != 0) {
2101 while (ReadBGSync() == 1) {
2102 }
2103
2104 SndExit();
2105
2106 CUserStatus *leaving = UserStatus;
2107
2108 leaving->prev_floor = -1;
2109 return 1;
2110 }
2111
2112 SndStep();
2113 return 0;
2114}
2115
2116void Draw_MainUnitShadow() {
2117 float light[4][4];
2118 float colour[4][4];
2119 float saved[4][4];
2120 int i;
2121
2122 // The shadows are drawn under a dimmed light and the real one goes back
2123 // afterwards.
2124 MGGetPLight(light, colour);
2125 sceVu0CopyMatrix(saved, light);
2126 light[0][0] *= 0.2f;
2127 light[2][0] *= 0.2f;
2128 MGSetPLight(light, colour);
2129
2130 TexManager.ReloadTexture(Vif1Packet, 15);
2131 MGBeginDrawShadow(*(sceGsTex0 *) &TexManager.GetTexture("shadow_buf", -1)->tex0);
2132
2133 if (BtActStatus.shadow_visible != 0 && EdEventInfo.player_shadow_draw != 0 && EdEventInfo.player_draw != 0 && BtActStatus.player_visible != 0) {
2134 CharaMain.DrawShadow();
2135 }
2136
2137 if (CMonUnitHyde == 0 && BtEventMode == 0) {
2138 NowMonstorUnit->DrawShadowMonstor();
2139 }
2140
2141 if (BtEventMode != 0) {
2142 for (i = 0; i < 6; i++) {
2143 if (EdEventInfo.npc_shadow_draw[i] != 0 && EdEventInfo.npc_draw[i] != 0) {
2144 NPCUnit[i].DrawShadow();
2145 }
2146 }
2147 }
2148
2149 MGEndDrawShadow(0x40);
2150 sceVu0CopyMatrix(light, saved);
2151 MGSetPLight(light, colour);
2152}
2153
2154void Draw_MainUnit() {
2155 float light[4][4];
2156 float colour[4][4];
2157 float saved_light[4][4];
2158 float saved_colour[4][4];
2159 sceVu0FVECTOR up;
2160 sceVu0FVECTOR stood;
2161 sceVu0FVECTOR towards;
2162 sceVu0FVECTOR world;
2163 sceVu0FMATRIX place;
2164 sceVu0FVECTOR ambient;
2165 sceVu0FVECTOR saved_ambient;
2166
2167 if (BtActStatus.player_visible == 0 && EdEventInfo.player_draw != 0 && EdEventInfo.player_shadow_draw != 0) {
2168 return;
2169 }
2170
2171 MGGetPLight(light, colour);
2172 sceVu0CopyMatrix(saved_light, light);
2173 sceVu0CopyMatrix(saved_colour, colour);
2174
2175 // The Atlamillia lights the player from wherever its effect stands.
2176 if (atraGetStatus != 0) {
2177 CFrame *lamp = shortAtraEffect.frame->SearchFrame("light01");
2178
2179 sceVu0CopyMatrix(place, lamp->local);
2180 up[0] = place[3][0];
2181 up[1] = place[3][1];
2182 up[2] = place[3][2];
2183 lamp->GetWorldPosition(world, up);
2184 sceVu0CopyVector(stood, CharaFrame->position);
2185
2186 towards[0] = world[0] - stood[0];
2187 towards[1] = world[1] - stood[1] - 12.0f;
2188 towards[2] = world[2] - stood[2];
2189
2190 float dist = sqrt(towards[0] * towards[0] + towards[1] * towards[1] + towards[2] * towards[2]);
2191
2192 if (dist <= 10.0f) {
2193 dist = 10.0f;
2194 }
2195
2196 float power = 5.0f * (100.0f / (dist * dist));
2197
2198 sceVu0Normalize(towards, towards);
2199 towards[0] *= power;
2200 towards[1] *= power;
2201 towards[2] *= power;
2202 towards[3] = 0.0f;
2203
2204 light[0][3] = towards[0];
2205 light[1][3] = towards[1];
2206 light[2][3] = towards[2];
2207 light[3][3] = 0.0f;
2208
2209 colour[3][0] = 0.8359375f * atraGetStatusRate__2;
2210 colour[3][1] = 0.9765625f * atraGetStatusRate__2;
2211 colour[3][2] = 0.66015625f * atraGetStatusRate__2;
2212 colour[3][3] = 0.5f * atraGetStatusRate__2;
2213 }
2214
2215 MGSetPLight(light, colour);
2216 MGGetAmbient(saved_ambient);
2217 MGGetAmbient(ambient);
2218
2219 if (BtEventMode == 0 && BtActStatus.in_presentation == 0) {
2220 // A speed boost pulses the model blue.
2221 if (BtBySpeedFlag != 0) {
2222 static float rate = 0.0f;
2223
2224 if (rate >= PI) {
2225 rate -= PI;
2226 } else {
2227 rate += 0.09817477f;
2228 }
2229
2230 ambient[0] = 96.0f;
2231 ambient[1] = 96.0f;
2232 ambient[2] = 96.0f + 96.0f * sinf(rate);
2233 }
2234
2235 if (BtStatusErrColorSet() != 0) {
2236 ambient[0] = StatusColor[0];
2237 ambient[1] = StatusColor[1];
2238 ambient[2] = StatusColor[2];
2239 }
2240
2241 float damage = setUnitDamageColor(0);
2242
2243 if (damage != 128.0f) {
2244 ambient[0] = damage;
2245 ambient[1] = damage;
2246 ambient[2] = damage;
2247 ambient[3] = 128.0f;
2248 }
2249
2250 unitAmbientAnime(ambient);
2251 }
2252
2253 MGSetAmbient(ambient);
2254 TexManager.ReloadTexture(Vif1Packet, 0x11);
2255 CharaMain.TextureAnime(0x11);
2256 CharaMain.Draw();
2257
2258 if (NowWeapon != NULL && NowWeapon->frame != NULL && BtActStatus.weapon_visible != 0) {
2259 TexManager.ReloadTexture(Vif1Packet, 0x1D);
2260 NowWeapon->Draw();
2261 }
2262
2263 MGSetAmbient(saved_ambient);
2264 sceVu0CopyMatrix(light, saved_light);
2265 sceVu0CopyMatrix(colour, saved_colour);
2266 MGSetPLight(light, colour);
2267}
2268
2269void MainDraw() {
2270 sceVu0FMATRIX camera;
2271 sceVu0FVECTOR eye;
2272 sceVu0FMATRIX view;
2273 sceVu0FMATRIX unit;
2274 sceGsTex0 frame_tex;
2275 sceGsTex0 water_tex;
2276 int i;
2277
2278 EdEventInfo.main_texture_animation = NULL;
2279 NowCamera__3->GetPos(eye);
2280 NowCamera__3->GetCameraMatrix(camera);
2281 sceVu0UnitMatrix(unit);
2282 sceVu0MulMatrix(view, unit, camera);
2283 MGSetViewMatrix(view, eye);
2284 SndSetCamera(NowCamera__3);
2285 sceVif1PkCall(Vif1Packet, (u_long128 *) Vu_prog0f, 0);
2286
2287 if (BtAllDrawFlag == 0) {
2288 if (BtItemListCashFlag != 0) {
2289 TexManager.ReloadTexture(Vif1Packet, 0x28);
2290 DngActiveItemTextureCopy();
2291 DngActiveWeaponTextureCopy();
2292 BtItemListCashFlag = 0;
2293 }
2294
2295 EdFadeInOut();
2296 return;
2297 }
2298
2299 if (lightingMode == 0) {
2300 MGSetPLight(main_light, main_lightcolor);
2301 MGSetAmbient(main_ambientlight);
2302 MGSetBGColor(main_bgColor[0], main_bgColor[1], main_bgColor[2], 128.0f);
2303 MGSetFogParm(main_fogRate[0], main_fogRate[1], main_fogColor[0], main_fogColor[1], main_fogColor[2], main_fogRate[2], main_fogRate[3]);
2304 } else {
2305 MGSetPLight(sub_light, sub_lightcolor);
2306 MGSetAmbient(sub_ambientlight);
2307 MGSetBGColor(sub_bgColor[0], sub_bgColor[1], sub_bgColor[2], 128.0f);
2308 MGSetFogParm(sub_fogRate[0], sub_fogRate[1], sub_fogColor[0], sub_fogColor[1], sub_fogColor[2], sub_fogRate[2], sub_fogRate[3]);
2309 }
2310
2311 if (BtItemListCashFlag != 0) {
2312 TexManager.ReloadTexture(Vif1Packet, 0x28);
2313 DngActiveItemTextureCopy();
2314 DngActiveWeaponTextureCopy();
2315 BtItemListCashFlag = 0;
2316 }
2317
2318 TexManager.ReloadTexture(Vif1Packet, 3);
2319 BtTexAnime.TexAnime(3);
2320 NowDngMap->DrawBGModel(NowCamera__3);
2321 NowDngMap->DrawDummyModel(NowCamera__3);
2322
2323 if (NowDngMap->map_type == 1) {
2324 NowDngMap->DrawMap(NowCamera__3, CharaFrame);
2325 } else {
2326 NowDngMap->DrawMapFreeStyle();
2327 }
2328
2329 // The map field's own draw, not the virtual one it inherits: retail binds
2330 // this call at compile time.
2331 NowDranMapField->CDranMapField::Draw();
2332
2333 if (itemOpenSmallFlag == 0 && itemOpenBigFlag == 0) {
2334 sceVu0FVECTOR box_pos;
2335
2336 sceVu0CopyVector(box_pos, CharaFrame->position);
2337 NowDngMap->DrawItemBox(box_pos);
2338 } else {
2339 if (itemOpenSmallFlag != 0) {
2340 itemOpenSmall.Draw();
2341 }
2342
2343 if (itemOpenBigFlag != 0) {
2344 itemOpenBig.Draw();
2345 }
2346 }
2347
2348 if (BtEventMode != 0) {
2349 sceVu0FVECTOR focus = {200.0f, 500.0f, 0.0f, 0.0f};
2350
2351 DepthOfField(focus, 3, 0x40, 0);
2352 }
2353
2354 if (atraGetStatus == 0) {
2355 sceVu0FVECTOR atra_pos;
2356
2357 TexManager.ReloadTexture(Vif1Packet, 0x16);
2358 sceVu0CopyVector(atra_pos, CharaFrame->position);
2359 NowDngMap->DrawAtraBoll(atra_pos);
2360 }
2361
2362 Draw_MainUnitShadow();
2363
2364 if (BtActStatus.player_visible != 0 && EdEventInfo.player_draw != 0) {
2365 Draw_MainUnit();
2366 }
2367
2368 if (CMonUnitHyde == 0 && BtEventMode == 0) {
2369 NowMonstorUnit->DrawMonstor();
2370 }
2371
2372 if (CharaMainHandViewFlag != 0) {
2373 TexManager.ReloadTexture(Vif1Packet, 0x11);
2374
2375 if (UserStatus->cur_chara == CHARA_XIAO) {
2376 CharaHand.Draw();
2377 }
2378
2379 if (NowWeapon != NULL && UserStatus->cur_chara == CHARA_XIAO && NowWeapon->frame != NULL && BtActStatus.weapon_visible != 0) {
2380 TexManager.ReloadTexture(Vif1Packet, 0x1D);
2381 NowWeapon->Draw();
2382 }
2383 }
2384
2385 if (BtEventMode != 0) {
2386 for (i = 0; i < 6; i++) {
2387 if (EdEventInfo.npc_draw[i] != 0) {
2388 TexManager.ReloadTexture(Vif1Packet, i + 0x20);
2389 NPCUnit[i].TextureAnime(NPCUnit[i].texture_block);
2390 NPCUnit[i].Draw();
2391
2392 if (i == BtEventInfo.bee_npc) {
2393 DrawBee(NPCUnit[BtEventInfo.bee_npc].frame, 0xF);
2394 }
2395 }
2396 }
2397 }
2398
2399 NowDngMap->DrawNPCDraw();
2400 mainItemModel.Draw();
2401 TexManager.ReloadTexture(Vif1Packet, 6);
2402 DrawWaterLing();
2403
2404 if (Water_Splash_actFlag != 0) {
2405 Water_Splash.Draw();
2406 }
2407
2408 if (NowDngMap->map_type == 1) {
2409 CRect_i_ area;
2410 sceVu0FVECTOR water_pos;
2411
2412 TexManager.ReloadTexture(Vif1Packet, 0xD);
2413 MGGetFBuffTex(&frame_tex);
2414 area.x = 0;
2415 area.y = 0;
2416 area.width = 0x280;
2417 area.height = SCREEN_HALF_HEIGHT;
2418 water_tex = *(sceGsTex0 *) &TexManager.GetTexture("water", -1)->tex0;
2419 MGMoveImage(&frame_tex, area, &water_tex, 0, 0, 0);
2420 sceVu0CopyVector(water_pos, CharaFrame->position);
2421 NowDngMap->DrawWater(water_pos, driveStepHold);
2422 }
2423
2424 if (CEffectHyde == 0 && BtEventMode == 0) {
2425 TexManager.ReloadTexture(Vif1Packet, 0x13);
2426 NowShockWave->Draw(NowCamera__3);
2427
2428 for (i = 0; i < 3; i++) {
2429 CBomb__2[i].Draw(NowCamera__3);
2430 }
2431
2432 for (i = 0; i < 5; i++) {
2433 MasekiEffect[i].Draw();
2434 }
2435
2436 CSHOT_EFFECT *shot = NowShotEffect->effect;
2437
2438 for (i = 0; i < 5; i++) {
2439 shot[i].Draw();
2440 }
2441
2442 NowMainEffect->Draw();
2443 }
2444
2445 sceVu0FVECTOR raster_pos;
2446
2447 sceVu0CopyVector(raster_pos, CharaFrame->position);
2448 TexManager.ReloadTexture(Vif1Packet, 0xE);
2449 NowDngMap->DrawRaster(CharaFrame);
2450
2451 if (NowDngMap->map_type == 1) {
2452 NowDngMap->DrawFire(CharaFrame, NowCamera__3);
2453 } else {
2454 NowDngMap->DrawFireFreeStyle(CharaFrame, NowCamera__3);
2455 }
2456
2457 if (atraGetStatus != 0 && atraShortGetType != 0) {
2458 TexManager.ReloadTexture(Vif1Packet, 0x1C);
2459 shortAtraEffect.Draw();
2460 }
2461
2462 if (gateItemFlag != 0) {
2463 TexManager.ReloadTexture(Vif1Packet, 0x1C);
2464 MGDraw(itemBoxModel);
2465 }
2466
2467 if (itemOpenSmallFlag != 0) {
2468 sceVu0FVECTOR ambient;
2469 sceVu0FVECTOR lift;
2470 sceVu0FVECTOR held;
2471
2472 MGGetAmbient(ambient);
2473 TexManager.ReloadTexture(Vif1Packet, 0x16);
2474 itemOpenSmallFx.Draw();
2475 TexManager.ReloadTexture(Vif1Packet, 0x1C);
2476 sceVu0CopyVector(lift, itemBoxModel->position);
2477 sceVu0CopyVector(held, lift);
2478
2479 static float itemposr = -PI;
2480
2481 itemposr += 0.10471976f;
2482
2483 if (itemposr >= PI) {
2484 itemposr -= TWO_PI;
2485 }
2486
2487 lift[1] += 0.5f * sinf(itemposr);
2488 itemBoxModel->SetPosition(lift);
2489 MGDraw(itemBoxModel);
2490 MGSetAmbient(ambient);
2491 itemBoxModel->SetPosition(held);
2492 }
2493
2494 if (itemOpenBigFlag != 0) {
2495 sceVu0FVECTOR lift;
2496 sceVu0FVECTOR held;
2497
2498 TexManager.ReloadTexture(Vif1Packet, 0x16);
2499 MGDraw(itemOpenBigFx.frame);
2500 sceVu0CopyVector(lift, itemBoxModel->position);
2501 sceVu0CopyVector(held, lift);
2502
2503 static float itemposr = -PI;
2504
2505 itemposr += 0.10471976f;
2506
2507 if (itemposr >= PI) {
2508 itemposr -= TWO_PI;
2509 }
2510
2511 lift[1] += 0.03f * sinf(itemposr);
2512 itemBoxModel->SetPosition(lift);
2513 TexManager.ReloadTexture(Vif1Packet, 0x1C);
2514 MGDraw(itemBoxModel);
2515 }
2516
2517 if (NewChangeFxFlag != 0) {
2518 sceVu0FVECTOR pos;
2519 sceVu0FVECTOR rot;
2520
2521 TexManager.ReloadTexture(Vif1Packet, 0xB);
2522 sceVu0CopyVector(pos, CharaMain.pos);
2523 CharaMain.GetRotation(rot);
2524 NewChangeFx.SetPosition(pos);
2525 NewChangeFx.SetRotation(rot);
2526 NewChangeFx.Draw();
2527 }
2528
2529 if (EscapeFlag != 0) {
2530 TexManager.ReloadTexture(Vif1Packet, 0x1C);
2531 EscapeEffect.Draw();
2532 }
2533
2534 NowDngMap->DrawTrapCircle();
2535 TexManager.ReloadTexture(Vif1Packet, 1);
2536
2537 if (CMonUnitHyde == 0 && BtEventMode == 0) {
2538 NowMonstorUnit->DrawMonstorCursor();
2539 }
2540
2541 if (BtEventInfo.event_marker != 0) {
2542 sceVu0FVECTOR mark;
2543
2544 sceVu0CopyVector(mark, CharaMain.pos);
2545 mark[1] += 22.0f;
2546
2547 static float bic_posr = -PI_SHORT;
2548
2549 bic_posr += 0.104719736f;
2550
2551 if (bic_posr >= PI_SHORT) {
2552 bic_posr -= TWO_PI_SHORT;
2553 }
2554
2555 mark[1] += 0.5f * sinf(bic_posr);
2556
2557 mark[1] += CharaHeight(UserStatus) - 15.0f;
2558 bicCursorFrame->SetPosition(mark);
2559 MGDraw(bicCursorFrame);
2560 BtEventInfo.event_marker = false;
2561 }
2562
2563 if (BtAllClear == 0 && DebugStatus[10] == 0) {
2564 int shift;
2565 int floor_no;
2566 int digit_x;
2567
2568 setbilinear(0);
2569
2570 if (autoDemo == 0 && CMonUnitHyde == 0) {
2571 setTargetCursor(lockOnTargetFlag);
2572
2573 if (lockOnTargetDraw != 0) {
2574 MGDraw(cursorFrame);
2575 lockOnTargetDraw = 0;
2576 }
2577
2578 setbilinear(0);
2579 }
2580
2581 if (iventInfo != DNG_EVENT_NONE && iventMarker != 0) {
2582 sceVu0CopyVector(iventPos, CharaMain.pos);
2583 iventPos[1] += 22.0f;
2584
2585 static float bic_posr = -PI_SHORT;
2586
2587 bic_posr += 0.104719736f;
2588
2589 if (bic_posr >= PI_SHORT) {
2590 bic_posr -= TWO_PI_SHORT;
2591 }
2592
2593 iventPos[1] += 0.5f * sinf(bic_posr);
2594
2595 iventPos[1] += CharaHeight(UserStatus) - 15.0f;
2596 bicCursorFrame->SetPosition(iventPos);
2597 }
2598
2599 if (BombInfo.aiming != 0) {
2600 bombCursorFrame->SetPosition(BombInfo.pos);
2601 MGDraw(bombCursorFrame);
2602 }
2603
2604 if (CEffectHyde == 0 && BtEventMode == 0) {
2605 MGSetGsZBUF(NULL);
2606 RandomItem->Draw();
2607 StealItem.Draw();
2608 }
2609
2610 if (autoDemo == 0) {
2611 sceGsAlpha blend;
2612 sceGsZbuf depth;
2613
2614 TexManager.ReloadTexture(Vif1Packet, 0x12);
2615
2616 blend = mgAlpha;
2617 blend.bits.a = 0;
2618 blend.bits.b = 2;
2619 blend.bits.c = 0;
2620 blend.bits.d = 1;
2621 MGSetGsALPHA(&blend);
2622
2623 depth = mgZBuffer;
2624 depth.bits.zmsk = 1;
2625 MGSetGsZBUF(&depth);
2626
2627 for (i = 0; i < 4; i++) {
2628 CWeaponElFx[i].Draw();
2629 }
2630
2631 WeaponCrashEffect.Draw();
2632
2633 for (i = 0; i < 16; i++) {
2634 HitMark[i].Draw();
2635 HitPointMark[i].Draw();
2636 MyHitPointMark[i].Draw();
2637 }
2638
2639 HealEffect.Draw();
2640
2641 if (CEffectHyde == 0 && BtEventMode == 0) {
2642 NowShotData->draw();
2643 OzumondShotEffect.Draw();
2644 OzumondFire.Draw();
2645 }
2646
2647 CWeaponFx.Draw();
2648 CRunFx__2.Step();
2649 CRunFx__2.Draw();
2650 MGSetGsALPHA(NULL);
2651 MGSetGsZBUF(NULL);
2652 }
2653
2654#ifdef PAL
2655 if (rogoSwitch2 == 1 && BtEventInfo.floor_title_off == 0) {
2656 TEX_Floor1 = TexManager.GetTexture(floor_name, -1);
2657 floor_no = 0;
2658
2659 if (UserStatus->cur_floor >= 9) {
2660 floor_no = -0x24;
2661 }
2662
2663 TexManager.ReloadTexture(Vif1Packet, 8);
2664 StartMessageDraw(TEX_Floor1, selectMapNo, UserStatus->cur_floor, BtUraDongeon, rogoAlphaA[2]);
2665 }
2666#else
2667 if (rogoSwitch2 == 1 && BtEventInfo.floor_title_off == 0) {
2668 TEX_Floor1 = TexManager.GetTexture(floor_name, -1);
2669 shift = 0;
2670 floor_no = 0;
2671
2672 if (UserStatus->cur_floor >= 9) {
2673 floor_no = -0x24;
2674 }
2675
2676 TexManager.ReloadTexture(Vif1Packet, 8);
2677
2678 if (LanguageCode == LANG_JAPANESE) {
2679 switch (selectMapNo) {
2680 case DUNGEON_DIVINE_BEAST_CAVE:
2681 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xE2, 0xAA, 0x72, 0x32), CRect_i_(0, 0, 0x72, 0x32), rogoAlphaA[2]);
2682 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x17D, 0xAA, 0x4C, 0x32), CRect_i_(0x72, 0, 0x4C, 0x32), rogoAlphaA[2]);
2683 break;
2684 case DUNGEON_WISE_OWL_FOREST:
2685 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xBE, 0xAA, 0xBE, 0x32), CRect_i_(0, 0, 0xBE, 0x32), rogoAlphaA[2]);
2686 shift = 0x40;
2687 break;
2688 case DUNGEON_SHIPWRECK:
2689 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xF5, 0xAA, 0x4C, 0x32), CRect_i_(0, 0, 0x4C, 0x32), rogoAlphaA[2]);
2690 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x159, 0xAA, 0x4C, 0x32), CRect_i_(0x4C, 0, 0x4C, 0x32), rogoAlphaA[2]);
2691 shift = -0x24;
2692 break;
2693 case DUNGEON_SUN_MOON_TEMPLE:
2694 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xE8, 0xAA, 0x98, 0x32), CRect_i_(0, 0, 0x98, 0x32), rogoAlphaA[2]);
2695 shift = 0x40;
2696 break;
2697 case DUNGEON_MOON_SEA:
2698 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xD7, 0xAA, 0x4C, 0x32), CRect_i_(0, 0, 0x4C, 0x32), rogoAlphaA[2]);
2699 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x13B, 0xAA, 0xBE, 0x32), CRect_i_(0x4C, 0, 0xBE, 0x32), rogoAlphaA[2]);
2700 shift = -0x40;
2701 break;
2702 case DUNGEON_GALLERY_OF_TIME:
2703 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x135, 0xAA, 0x98, 0x32), CRect_i_(0, 0, 0x98, 0x32), rogoAlphaA[2]);
2704 shift = -0x40;
2705 break;
2706 }
2707
2708 if (BtUraDongeon != 0) {
2709 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x120, 0xE6, 0x40, 0x38), CRect_i_(0x13A, 0x78, 0x40, 0x38), rogoAlphaA[2]);
2710 } else if (UserStatus->res_limit_zone_current >= 0) {
2711 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xD4, 0xE6, 0xD8, 0x30), CRect_i_(0, 0x78, 0xD8, 0x30), rogoAlphaA[2]);
2712 }
2713 }
2714
2715 if (LanguageCode > LANG_JAPANESE) {
2716 switch (selectMapNo) {
2717 case DUNGEON_DIVINE_BEAST_CAVE:
2718 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0x122, 0xAA, 0x2D, 0x32), CRect_i_(0, 0, 0x2D, 0x32), rogoAlphaA[2]);
2719 shift = -0x14;
2720 break;
2721 case DUNGEON_WISE_OWL_FOREST:
2722 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xA0, 0xAA, 0xDA, 0x32), CRect_i_(0, 0, 0xDA, 0x32), rogoAlphaA[2]);
2723 shift = 0x40;
2724
2725 if (UserStatus->cur_floor < 9) {
2726 shift = 0x20;
2727 }
2728
2729 break;
2730 case DUNGEON_SHIPWRECK:
2731 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xC8, 0xAA, 0x91, 0x32), CRect_i_(0, 0, 0x91, 0x32), rogoAlphaA[2]);
2732
2733 if (UserStatus->cur_floor >= 9) {
2734 shift = 0x20;
2735 }
2736
2737 break;
2738 case DUNGEON_SUN_MOON_TEMPLE:
2739 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xDC, 0xAA, 0x8E, 0x32), CRect_i_(0, 0, 0x8E, 0x32), rogoAlphaA[2]);
2740 shift = 0x10;
2741 break;
2742 case DUNGEON_MOON_SEA:
2743 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xC3, 0xAA, 0x4B, 0x32), CRect_i_(0, 0, 0x4B, 0x32), rogoAlphaA[2]);
2744 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x13B, 0xAA, 0xC0, 0x32), CRect_i_(0x60, 0, 0xC0, 0x32), rogoAlphaA[2]);
2745 shift = -0x40;
2746 break;
2747 case DUNGEON_GALLERY_OF_TIME:
2748 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x108, 0xAA, 0xE1, 0x32), CRect_i_(0, 0, 0xE1, 0x32), rogoAlphaA[2]);
2749 shift = -0x80;
2750 break;
2751 case DUNGEON_DEMON_SHAFT:
2752 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(floor_no + 0xDC, 0xAA, 0x8E, 0x32), CRect_i_(0, 0, 0x8E, 0x32), rogoAlphaA[2]);
2753 shift = 0x10;
2754 break;
2755 }
2756
2757 if (BtUraDongeon != 0) {
2758 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0x110, 0xE6, 0x60, 0x38), CRect_i_(0x110, 0x78, 0x60, 0x38), rogoAlphaA[2]);
2759 } else if (UserStatus->res_limit_zone_current >= 0) {
2760 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(0xD4, 0xE6, 0xF0, 0x30), CRect_i_(0, 0x78, 0xF0, 0x30), rogoAlphaA[2]);
2761 }
2762 }
2763
2764 floor_no = UserStatus->cur_floor + 1;
2765
2766 if (selectMapNo == DUNGEON_GALLERY_OF_TIME) {
2767 floor_no = BtGetFloorLevel(floor_no - 1);
2768 }
2769
2770 if (floor_no < 10) {
2771 digit_x = floor_no % 10 * 0x26;
2772 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x15A, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2773 }
2774
2775 if (floor_no >= 10 && floor_no < 100) {
2776 digit_x = floor_no / 10 * 0x26;
2777 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x136, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2778 digit_x = floor_no % 10 * 0x26;
2779 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x15A, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2780 }
2781
2782 if (floor_no >= 100) {
2783 int digit = floor_no / 100;
2784
2785 digit_x = digit * 0x26;
2786 floor_no -= digit * 100;
2787 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x112, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2788 digit_x = floor_no / 10 * 0x26;
2789 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x136, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2790 digit_x = floor_no % 10 * 0x26;
2791 set2DSprite(Vif1Packet, TEX_Floor1, CRect_i_(shift + 0x15A, 0xAA, 0x26, 0x32), CRect_i_(digit_x, 0x32, 0x26, 0x32), rogoAlphaA[2]);
2792 }
2793 }
2794
2795#endif
2796
2797 TexManager.ReloadTexture(Vif1Packet, 2);
2798
2799 int gauge_alpha = rogoY3 + 0x60;
2800
2801 if ((int) BtActStatus.action_gauge >= 100) {
2802 if (BtActStatus.gauge_flash == 0) {
2803 set2DSprite(Vif1Packet, TEX_WepGage, CRect_i_(0x28, SCREEN_HEIGHT - 0x34, 0x80, 0x1C), CRect_i_(0, 0, 0x80, 0x1C), gauge_alpha);
2804 } else {
2805 set2DSprite(Vif1Packet, TEX_WepGage, CRect_i_(0x28, SCREEN_HEIGHT - 0x34, 0x80, 0x1C), CRect_i_(0, 0x1C, 0x80, 0x1C), gauge_alpha);
2806 }
2807 }
2808
2809 float wear = BtActStatus.action_gauge;
2810
2811 if ((int) wear < 100) {
2812 int left = (int) wear;
2813
2814 set2DSprite(Vif1Packet, TEX_WepGage, CRect_i_(0x28, SCREEN_HEIGHT - 0x34, 0x80, 0x1C), CRect_i_(0, 0x54, 0x80, 0x1C), gauge_alpha);
2815 set2DSprite(Vif1Packet, TEX_WepGage, CRect_i_(0x42, SCREEN_HEIGHT - 0x34, left, 0x1C), CRect_i_(0x1A, 0x38, left, 0x1C), gauge_alpha);
2816 }
2817
2818 if (infoMap != 0 && NowDngMap->map_type == 1) {
2819 sceVu0FVECTOR map_pos;
2820 sceVu0FVECTOR map_rot;
2821
2822 TexManager.ReloadTexture(Vif1Packet, 0x1F);
2823 sceVu0CopyVector(map_pos, CharaFrame->position);
2824 CharaFrame->GetRotation(map_rot);
2825 NowDngMap->DrawMiniMap(map_pos, map_rot[1]);
2826 NowMonstorUnit->DrawMapSymbol(map_pos);
2827 RandomItem->MapSymbolDraw();
2828 }
2829
2830 topStatusInfo(rogoY3, itemNowSel, UserStatus->cur_floor);
2831 BtStatusErrDraw(rogoY3);
2832
2833 for (i = 0; i < 32; i++) {
2834 HitValue[i].Draw();
2835 }
2836
2837 if (exitMenuFlag != 0) {
2838 TexManager.ReloadTexture(Vif1Packet, 7);
2839 set2DSprite(Vif1Packet, TexManager.GetTexture("pause", -1), CRect_i_(0x100, 0xCC, 0x80, 0x28), 0, 0);
2840 }
2841
2842 setbilinear(1);
2843 }
2844
2845 if (MonstorNameOff == 0) {
2846 MonsterNameDraw();
2847 }
2848
2849 SetMonsterNameDrawFlag(0);
2850
2851 if (EdEventInfo.screen_filter != 0) {
2852 sceVu0FVECTOR fade;
2853
2854 sceVu0CopyVector(fade, EdEventInfo.screen_filter_color);
2855 MGFillBox(CRect_i_(0, 0, 0x2800, 0xE00), (int) fade[0], (int) fade[1], (int) fade[2], (int) fade[3]);
2856 }
2857
2858 if (BtEventMode != 0) {
2859 EdEventSpriteDraw();
2860 EBDraw();
2861 TexManager.ReloadTexture(Vif1Packet, 0x1A);
2862 BtEventMes0.DrawMesWin();
2863 BtEventMes1.DrawMesWin();
2864 }
2865
2866 for (i = 0; i < 1; i++) {
2867 if (EdEventInfo.item_frame[i] != NULL) {
2868 TexManager.ReloadTexture(Vif1Packet, i + 0x28);
2869 MGDraw(EdEventInfo.item_frame[i]);
2870 }
2871 }
2872
2873 setbilinear(0);
2874 TexManager.ReloadTexture(Vif1Packet, 0x1A);
2875 SystemMesStep();
2876 SystemMesDraw();
2877
2878 int showing;
2879
2880 if (DngMessMan.hide_timer > 0) {
2881 showing = 0;
2882 } else {
2883 showing = DngMessMan.enabled;
2884 }
2885
2886 if (showing != 0) {
2887 if (DngMessMan.steev_window == 0) {
2888 int mes_no = DngMessMan.message;
2889
2890 DngMes1.mes_no[0] = DngMessMan.insert_mes_1;
2891 DngMes1.mes_no[1] = DngMessMan.insert_mes_2;
2892 DngMes1.values[0] = DngMessMan.insert_value_1;
2893 DngMes1.values[1] = DngMessMan.insert_value_2;
2894 DngMes1.value_signed = true;
2895 DngMes1.value_show = false;
2896
2897 if (mes_no != oldMsgNo) {
2898 oldMsgNo = mes_no;
2899 Mes1MakeFlg = 1;
2900 }
2901
2902 if (Mes1MakeFlg != 0) {
2903 Mes1MakeFlg = DngMes1.MakeMesWin(mes_no);
2904 }
2905
2906 if (mes_no != -1) {
2907 DngMes1.text_x = 0x136;
2908 DngMes1.text_y = 0x154;
2909 DngMes1.auto_pos = MES_POS_BOTTOM_RIGHT;
2910 DngMes1.DrawMesWin();
2911 }
2912 } else {
2913 int mes_no = DngMessMan.message;
2914 int pos[4];
2915
2916 DngMesStb.value_signed = true;
2917 DngMesStb.value_show = false;
2918
2919 if (mes_no != oldMsgNo) {
2920 oldMsgNo = mes_no;
2921 Mes1MakeFlg = 1;
2922 }
2923
2924 if (Mes1MakeFlg != 0) {
2925 Mes1MakeFlg = DngMesStb.MakeMesWin(mes_no);
2926 }
2927
2928 if (mes_no != -1) {
2929 DngMesStb.auto_pos = MES_POS_BOTTOM;
2930 DngMesStb.AutoSet(pos);
2931 DngMesStb.DrawMesWin();
2932 }
2933 }
2934 }
2935
2936 if (BtEventMode != 0) {
2937 if (DebugStatus[4] != 0) {
2938 TexManager.ReloadTexture(Vif1Packet, 0xC);
2939 EdDDrawFont();
2940 }
2941 } else {
2942 TexManager.ReloadTexture(Vif1Packet, 0xC);
2943 DebugInfomationDraw();
2944 }
2945
2946 DispFade__3.FadeIn(Vif1Packet);
2947 DispFade__3.FadeOut(Vif1Packet);
2948 EdFadeInOut();
2949
2950 if (frameCaputer != 0) {
2951 sceGsSyncPath(0, 0);
2952 TexManager.ReloadTexture(Vif1Packet, 0x17);
2953 MGMoveFrameBuffImage((sceGsTex0 *) &TexManager.GetTexture("frame_image", -1)->tex0, 0, 0, 0);
2954 }
2955}
2956
2957float oldCameraHeight;
2958float oldCameraAngle;
2959
2960/* How hard the player is turning the camera. */
2961float inputH1;
2962
2966static inline void DeleteItemModel(int slot) {
2967 if (activeItem.model[slot] != -1) {
2968 activeItem.models->DeleteModel(activeItem.model[slot]);
2969 activeItem.model[slot] = -1;
2970 }
2971}
2972
2979void MoveChara() {
2980 /* Where the camera looks relative to what it follows, before the floor's
2981 own offset is added. */
2982 static sceVu0FVECTOR reference = {0.0f, 7.5f, 0.0f, 0.0f};
2983 sceVu0FVECTOR pos;
2984 float move_z;
2985 float move_x;
2986 float ly;
2987 float lx;
2988 float angle;
2989 float rx;
2990 float ry;
2991 CFrame *collision;
2992 int entry_no;
2993
2994 // An event that sets its own draw distance keeps it; anything else draws
2995 // the whole floor.
2996 if (BtEventMode != 0 && EdEventInfo.projection > 0.0f) {
2997 MGSetRenderInfo(EdEventInfo.projection, 1.0f, (float) 0xFFFF);
2998 } else {
2999 MGSetRenderInfo(800.0f, 1.0f, (float) 0xFFFF);
3000 }
3001
3002 sceVu0CopyVector(pos, CharaFrame->position);
3003 angle = NowCamera__3->GetAngleH();
3004 GameEnv.camera = NowCamera__3;
3005 GameEnv.frame = CharaFrame;
3006 lx = GamePad.GetLXf();
3007 inputH1 = lx;
3008 ly = GamePad.GetLYf();
3009 rx = GamePad.GetRXf();
3010 ry = GamePad.GetRYf();
3011 {
3012 sceVu0FVECTOR forward = {0.0f, 0.0f, 1.0f, 1.0f};
3013 sceVu0FVECTOR rotation;
3014 sceVu0FVECTOR dir;
3015 sceVu0FMATRIX rot_matrix;
3016
3017 CharaMain.frame->GetRotation(rotation);
3018 sceVu0UnitMatrix(rot_matrix);
3019 sceVu0RotMatrixY(rot_matrix, rot_matrix, rotation[1]);
3020 sceVu0ApplyMatrix(dir, rot_matrix, forward);
3021 sceVu0Normalize(BtActStatus.input_direction, dir);
3022 }
3023 // The stick is read in screen space, so it turns with the camera before
3024 // anything acts on it.
3025 BtActStatus.input_direction[0] = lx * cos(angle) + ly * sinf(angle);
3026 BtActStatus.input_direction[2] = ly * cos(angle) - lx * sinf(angle);
3027 BtActStatus.input_direction[1] = 0.0f;
3028 BtActStatus.input_direction[3] = 1.0f;
3029
3030 if (GamePad.Down2(PAD_CROSS) != 0) {
3031 driveStepHold ^= 1;
3032 }
3033
3034 if (GamePad.Down2(PAD_SQUARE) != 0) {
3035 BtAllClear ^= 1;
3036 MesAbsDrawOff = BtAllClear;
3037 }
3038
3039 GamePad.Down(PAD_SELECT);
3040
3041 switch (gameTask) {
3042 case GAME_TASK_PLAY:
3043 if (CheckTrialEnd() != 0) {
3044 tryalExit = 1;
3045 } else if (GamePad.Down(PAD_START) != 0) {
3046 printf("pause!!\n");
3047 exitMenuFlag = 1;
3048 driveStepHold = 1;
3049 CMonUnitHold = 1;
3050 CEffectHold = 1;
3051 PlayTimeCountFlag(0);
3052 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3053 gameTask = GAME_TASK_PAUSE;
3054 } else {
3055 move_x = lx * cos(angle) + ly * sinf(angle);
3056 BtActStatus.move_x = move_x;
3057 move_z = ly * cos(angle) - lx * sinf(angle);
3058 BtActStatus.move_z = move_z;
3059
3060 if (StatusErrCheck(AILMENT_GOO) != 0) {
3061 move_x /= 2.0f;
3062 move_z /= 2.0f;
3063 }
3064
3065 BtActStatus.movement_locked = 0;
3066
3067 if (StatusErrCheck(AILMENT_FREEZE) != 0) {
3068 lx = 0.0f;
3069 move_x = 0.0f;
3070 ly = 0.0f;
3071 move_z = 0.0f;
3072 BtActStatus.movement_locked = 1;
3073 }
3074
3075 velo__2[0] = move_x;
3076 velo__2[2] = move_z;
3077 velo2[0] = rx * cos(angle) + ry * sinf(angle);
3078 velo2[2] = ry * cos(angle) - rx * sinf(angle);
3079 stickVector = DistVector(velo__2);
3080 BtActStatus.stick_strength = stickVector;
3081 stickVector2 = DistVector(velo__2);
3082 BtActStatus.guard_mode = 0;
3083
3084 if (lockOnTargetFlag != 0) {
3085 velo__2[0] = move_x;
3086 velo__2[2] = move_z;
3087
3088 if (BtActStatus.fast_camera_frames > 0) {
3089 NowCamera__3->SetSpeed(32.0f);
3090 } else {
3091 NowCamera__3->SetSpeed(14.0f);
3092 }
3093 } else {
3094 NowCamera__3->SetSpeed(8.0f);
3095 defCameraWait = 0;
3096
3097 if (BtBySpeedFlag != 0) {
3098 run_speed = 3.0f;
3099 } else {
3100 run_speed = 1.45f;
3101 }
3102
3103 velo__2[0] = move_x * run_speed;
3104 velo__2[2] = move_z * run_speed;
3105 }
3106
3107#ifdef PAL
3108 // In debug mode, Select outside an event opens the debug menu.
3109 if (DebugMode != 0 && GamePad.Down(PAD_R3) != 0 && BtEventMode == 0) {
3110 DebugStatus[0] = 1;
3111 gameTask = GAME_TASK_DEBUG_OPEN;
3112 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3113 break;
3114 }
3115
3116#endif
3117 if (stickVector <= 0.01f) {
3118 CUserStatus *drain = UserStatus;
3119
3120 drain->water_drain_disable = 1;
3121 } else {
3122 UserStatus->water_drain_disable = 0;
3123 }
3124
3125 if (UserStatus->overflow_flag != 0) {
3126 UserStatus->overflow_flag = false;
3127 gameTask = GAME_TASK_MENU_OPEN;
3128 EnemyLifeGage.draw = false;
3129 driveStepHold = 1;
3130 SetMIniMapStatus(0);
3131 iventInfo = DNG_EVENT_NONE;
3132 rogoSwitch2 = 0;
3133 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3134 } else if (GamePad.Down(PAD_TRIANGLE) != 0) {
3135 int ok = 0;
3136
3137 if (move_x == 0.0f && move_z == 0.0f && BtActStatus.action_on == 0) {
3138 ok = 1;
3139 }
3140
3141 if (UserStatus->hp[UserStatus->cur_chara] <= 0) {
3142 ok = 0;
3143 }
3144
3145 if (BtActStatus.movement_locked != 0) {
3146 ok = 1;
3147 }
3148
3149 if (ok != 0) {
3150 UserStatus->overflow_flag = false;
3151 gameTask = GAME_TASK_MENU_OPEN;
3152 EnemyLifeGage.draw = false;
3153 driveStepHold = 1;
3154 SetMIniMapStatus(0);
3155 iventInfo = DNG_EVENT_NONE;
3156 rogoSwitch2 = 0;
3157 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3158 } else {
3159 goto walk;
3160 }
3161 } else {
3162 walk:
3163 if ((move_x != 0.0f || move_z != 0.0f) && (BtActStatus.action_on == 0 || UserStatus->cur_chara == CHARA_OSMOND)) {
3164 CharaFrame->SetRotation(0.0f, unitRotation(CharaFrame, atan2f(move_x, move_z)), 0.0f);
3165 }
3166 CharaMain.motion_type.motion_info->speed = 0.05f;
3167 BtActStatus.motion_no = keyCtrl(lx, ly, CharaMain.motion_type.motion_info);
3168
3169 if (UserStatus->hp[UserStatus->cur_chara] <= 0) {
3170 BtActStatus.motion_no = 0x17;
3171 }
3172
3173 if (BtActStatus.recoil_frames != 0) {
3174 if (stickVector >= 0.8f && UserStatus->cur_chara == CHARA_TOAN) {
3175 BtActStatus.motion_no = 0x1D;
3176 }
3177
3178 BtActStatus.recoil_frames--;
3179 }
3180
3181 if (BtActStatus.invincible_frames > 0) {
3182 BtActStatus.invincible_frames--;
3183 }
3184
3185 if (GamePad.Down(PAD_SELECT) != 0 && UserStatus->party_size >= 2 && BtActStatus.action_on == 0) {
3186 DngMessMan.enabled = false;
3187 DngMessMan.message = -1;
3188 DngMessMan.timer = 0;
3189 DngMessMan.steev_window = false;
3190 DngMessMan.steev_index = 0;
3191 DngMessMan.hide_timer = 0;
3192 MonstorNameOff = 0;
3193 EnemyLifeGage.draw = false;
3194 BtMiniChrSelect_Init(0);
3195 oldUnitNow = UserStatus->cur_chara;
3196 gameTask = GAME_TASK_CHARA_SELECT_LOOP;
3197 autoCamTrial();
3198 } else {
3199 static int cnt;
3200 static char init;
3201 sceVu0FVECTOR mask_pos;
3202
3203 if (init == 0) {
3204 cnt = 0;
3205 init = 1;
3206 }
3207
3208 sceVu0CopyVector(mask_pos, CharaFrame->position);
3209
3210 if (cnt >= 5) {
3211 NowDngMap->checkMask(mask_pos[0], mask_pos[2]);
3212 cnt = 0;
3213 }
3214
3215 cnt++;
3216
3217 if (BtActStatus.action_on == 0) {
3218 if (GamePad.Down(PAD_LEFT) != 0) {
3219 SndSePlay(MENU_SOUND_CURSOR, -1, 0);
3220
3221 if (itemNowSel < 2) {
3222 itemNowSel = 3;
3223 } else {
3224 itemNowSel--;
3225 }
3226
3227 activeItem.now = itemNowSel;
3228 }
3229
3230 if (GamePad.Down(PAD_RIGHT) != 0) {
3231 SndSePlay(MENU_SOUND_CURSOR, -1, 0);
3232
3233 if (itemNowSel >= 3) {
3234 itemNowSel = 1;
3235 } else {
3236 itemNowSel++;
3237 }
3238
3239 activeItem.now = itemNowSel;
3240 }
3241 }
3242
3243 if (GamePad.Down(PadInput_NO) != 0) {
3244 if (lockOnTargetNo == -1) {
3245 sceVu0FMATRIX look;
3246
3247 CharaFrame->GetLWMatrix(look);
3248 NowCamera__3->SetAngle(atan2f(look[2][0], look[2][2]) - PI_D);
3249 } else if (lockOnTargetFlag == 0) {
3250 if (lockOnTargetNo != -1) {
3251 lockOnTargetFlag = 1;
3252 SndSePlay(SE_LOCK_ON, -1, 0);
3253 }
3254 } else {
3255 lockOnTargetFlag = 0;
3256 SndSePlay(MENU_SOUND_REFUSE, -1, 0);
3257 }
3258 }
3259
3260 if (GamePad.Down(PAD_L1) != 0 && BtActStatus.movement_locked == 0 && lockOnTargetFlag != 0) {
3261 if (targetCursorShiftNo >= targetCursorShiftRot - 1) {
3262 targetCursorShiftNo = 0;
3263 targetCursorShiftRot = SetNearLockOnTarget(0, 0);
3264 SndSePlay(SE_LOCK_ON, -1, 0);
3265 } else {
3266 targetCursorShiftNo++;
3267 targetCursorShiftRot = SetNearLockOnTarget(targetCursorShiftNo, 0);
3268 SndSePlay(SE_LOCK_ON, -1, 0);
3269 }
3270 }
3271
3272 if (SetBattleStyle(selectMapNo, 0) <= 60.0f && move_x == 0.0f && move_z == 0.0f) {
3273 BtActStatus.motion_no = 0x12;
3274 }
3275
3276 if (lockOnTargetFlag != 0) {
3277 CCharacter *locked = &NowMonstorUnit->chara[lockOnTargetNo][0];
3278 sceVu0FVECTOR target;
3279 float face;
3280
3281 locked->GetPosition(target);
3282 atan2f(pos[0] - target[0], pos[2] - target[2]);
3283 face = atan2f(target[0] - pos[0], target[2] - pos[2]);
3284
3285 if (BtActStatus.stick_strength > 0.0f) {
3286 CharaFrame->SetRotation(0.0f, face, 0.0f);
3287 } else {
3288 CharaFrame->SetRotation(0.0f, unitRotation(CharaFrame, face), 0.0f);
3289 }
3290
3291 if (BtActStatus.action_on == 0) {
3292 float turn;
3293 float rate;
3294 int motion;
3295
3296 BtActStatus.motion_no = 0x12;
3297 CharaMain.motion_type.motion_info[18].speed = 0.2f;
3298 turn = atan2f(move_x, move_z);
3299 turn = face - turn;
3300
3301 if (turn < -PI_SHORT) {
3302 turn += TWO_PI_SHORT;
3303 }
3304
3305 if (turn > PI_SHORT) {
3306 turn -= TWO_PI_SHORT;
3307 }
3308
3309 // Which strafe motion plays comes from the angle
3310 // between the way the character faces and the way
3311 // the stick points, in five bands around it.
3312 motion = 0x12;
3313
3314 if (turn > -1.2f && turn < 1.2f) {
3315 motion = 0x15;
3316 }
3317
3318 if (turn < -2.6f || turn > 2.6f) {
3319 motion = 0x16;
3320 }
3321
3322 if (turn > 1.2f && turn < 2.6f) {
3323 motion = 0x13;
3324 }
3325
3326 if (turn < -1.2f && turn > -2.6f) {
3327 motion = 0x14;
3328 }
3329
3330 if (BtActStatus.stick_strength > 0.0f) {
3331 BtActStatus.motion_no = motion;
3332 rate = 0.2f + BtActStatus.stick_strength;
3333
3334 if (rate >= 1.0f) {
3335 rate = 1.0f;
3336 }
3337
3338 CharaMain.motion_type.motion_info[motion].speed = rate;
3339 }
3340 }
3341 }
3342
3343 if (UserStatus->cur_chara == CHARA_XIAO && BtActStatus.action_no == 0xC && (move_x != 0.0f || move_z != 0.0f)) {
3344 CharaFrame->SetRotation(0.0f, unitRotation(CharaFrame, atan2f(move_x, move_z)), 0.0f);
3345 }
3346
3347 if (GamePad.On(PAD_R1) != 0 && lockOnTargetFlag != 0 && BtActStatus.movement_locked == 0 && BtActStatus.in_water == 0 && BtActStatus.action_on == 0) {
3348 BtActStatus.action_on = 6;
3349 BtActStatus.action_no = 8;
3350 driveNoInterpolate = 1;
3351 }
3352
3353 if (BtActStatus.action_on == 6) {
3354 float end;
3355
3356 if (lockOnTargetFlag == 0) {
3357 BtActStatus.action_on = 0;
3358 BtActStatus.action_no = 0x12;
3359 }
3360
3361 if (BtActStatus.action_no == 8) {
3362 BtActStatus.motion_no = 8;
3363 end = CharaMain.motion_type.motion_info[8].end;
3364
3365 if (CharaMain.motion_type.state.time >= end - 1.0f && CharaMain.motion_type.state.time < end) {
3366 BtActStatus.action_no = 9;
3367 BtActStatus.motion_no = 9;
3368 driveNoInterpolate = 1;
3369 }
3370 }
3371
3372 if (BtActStatus.action_no == 9) {
3373 BtActStatus.motion_no = 9;
3374 BtActStatus.guard_mode = 5;
3375
3376 if (GamePad.On(PAD_R1) == 0) {
3377 BtActStatus.action_no = 0xA;
3378 BtActStatus.motion_no = 0xA;
3379 driveNoInterpolate = 1;
3380 }
3381 }
3382
3383 if (BtActStatus.action_no == 0xA) {
3384 BtActStatus.motion_no = 0xA;
3385 end = CharaMain.motion_type.motion_info[10].end;
3386
3387 if (CharaMain.motion_type.state.time >= end - 1.5f && CharaMain.motion_type.state.time < end) {
3388 BtActStatus.action_on = 0;
3389 }
3390 }
3391 }
3392
3393 int script;
3394
3395 if (NowMonstorUnit->requested_event != -1) {
3396 BtEventInfo.script_no = NowMonstorUnit->requested_event;
3397 BtEventInfo.ext_memory = true;
3398 ResetStatusInfo();
3399 driveStepHold = 1;
3400 EdFadeInit();
3401 float r, g, b;
3402#ifdef PAL
3403 b = g = r = 0.0f;
3404#else
3405 r = g = b = 0.0f;
3406#endif
3407 EdFadeOut(0x78, r, g, b);
3408 BtEventInfo.fade_on_start = false;
3409 gameTask = GAME_TASK_FLOOR_FADE_RESET;
3410 } else if (UserStatus->CheckLife() != 0 && BtActStatus.action_on == 0 && (script = NowMonstorUnit->CheckEventFlag2()) != -1) {
3411 BtEventInfo.script_no = script;
3412 BtEventInfo.ext_memory = false;
3413 gameTask = GAME_TASK_SCRIPT_START;
3414 } else if (UserStatus->CheckLife() != 0 && BtActStatus.action_on == 0 && NowMonstorUnit->GetMonstorNum() <= 0 && (script = BtEventInfo.clear_script_no) != -1) {
3415 BtEventInfo.script_no = script;
3416 BtEventInfo.ext_memory = BtEventInfo.clear_script_ext_memory;
3417 BtEventInfo.clear_script_no = -1;
3418 BtEventInfo.clear_script_ext_memory = 0;
3419 printf("dead script !!\n");
3420 gameTask = GAME_TASK_SCRIPT_START;
3421 } else {
3422 MAP_TRAP_CIRCLE *trap = NowDngMap->DistTrapCircle();
3423 int event;
3424
3425 if (trap != NULL) {
3426 SetSystemMes(Run_TrapCircle(trap) + 0x12C, 0x96, MES_POS_BOTTOM, 0, NULL, NULL);
3427 DngMessMan.hide_timer = 0x96;
3428 }
3429
3430 if (UserStatus->CheckLife() != 0) {
3431 event = RandomItem->checkErr();
3432
3433 if (event != 0) {
3434 ClearSystemMes();
3435
3436 if (event == 1) {
3437 SetSystemMes(0x48, 0x78, MES_POS_BOTTOM, 0, NULL, NULL);
3438 }
3439
3440 if (event == 2) {
3441 SetSystemMes(0x51, 0x78, MES_POS_BOTTOM, 0, NULL, NULL);
3442 }
3443
3444 DngMessMan.hide_timer = 0x78;
3445 } else {
3446 event = RandomItem->checkEvent();
3447
3448 if (event != -1) {
3449 switch (event) {
3450 case ITEM_DRAN_S_CREST:
3451 case ITEM_SHINY_STONE:
3452 case ITEM_RED_BERRY:
3453 case ITEM_HOOK:
3454 case ITEM_KING_S_SLATE:
3455 case ITEM_GUN_POWDER:
3456 case ITEM_CLOCK_HANDS:
3457 case ITEM_POINTY_CHESTNUT:
3458 case ITEM_BLACK_KNIGHT_CREST:
3459 ((CDngStatusData *) UserStatus)->GetItem(event, 0);
3460 BtGetGateKey_Init(event);
3461 gameTask = GAME_TASK_GATE_KEY_LOOP;
3462 break;
3463 default:
3464 BtGetAttach_Init(selectMapNo, event);
3465 DngMessMan.hide_timer = 0x78;
3466 SndSePlay(SE_ITEM_GET, -1, 0);
3467 autoCamTrial();
3468 break;
3469 }
3470 }
3471
3472 goto steal;
3473 }
3474 } else {
3475 steal:
3476 if (UserStatus->CheckLife() != 0) {
3477 int stolen = StealItem.checkEvent();
3478
3479 if (stolen != -1) {
3480 BtGetAttach_Init(selectMapNo, stolen);
3481 DngMessMan.hide_timer = 0x78;
3482 SndSePlay(SE_ITEM_GET, -1, 0);
3483 autoCamTrial();
3484 }
3485 }
3486
3487 if (BtActStatus.can_act != 0 && BtActStatus.movement_locked == 0) {
3488 CDungeonEventData *state = NowEventMan->SearchDataSlotPos2(pos);
3489 sceVu0FVECTOR slot_pos;
3490 sceVu0FVECTOR slot_dir;
3491
3492 if (state != NULL && state->event->chara_no != -1) {
3493 s8 chara = UserStatus->cur_chara;
3494 int done = state->chara_done;
3495
3496 if (done == chara) {
3497 state = NULL;
3498 }
3499 }
3500
3501 BtEventInfo.script_no = -1;
3502
3503 if (state != NULL && state->event->script_no != -1) {
3504 BtEventInfo.script_no = state->event->script_no;
3505 BtEventInfo.ext_memory = state->event->ext_mem;
3506 BtEventInfo.event_marker = true;
3507 BtEventInfo.action_mode = 0;
3508 sceVu0CopyVector(slot_pos, state->pos);
3509 sceVu0CopyVector(slot_dir, state->dir);
3510 sceVu0CopyVector(BtEventInfo.position, slot_pos);
3511 sceVu0CopyVector(BtEventInfo.direction, slot_dir);
3512 }
3513
3514 if (BtEventInfo.script_no != -1) {
3515 if (state->event->chara_no != -1 && GamePad.Down(PadInput_OK) != 0) {
3516 if (UserStatus->cur_chara == state->event->chara_no) {
3517 state->chara_done = UserStatus->cur_chara;
3518 }
3519
3520 gameTask = GAME_TASK_SCRIPT_START;
3521 BtEventInfo.action_mode = 0;
3522 BtEventInfo.chara_help = true;
3523 }
3524
3525 if (state->event->fade != 0) {
3526 EdFadeInit();
3527 EdFadeOut(0x78, 0.0f, 0.0f, 0.0f);
3528 BtEventInfo.event_marker = false;
3529 gameTask = GAME_TASK_SCRIPT_RESTART;
3530 } else if (state->hold != 0 && GamePad.Down(PAD_SQUARE) != 0) {
3531 gameTask = GAME_TASK_SCRIPT_START;
3532 BtEventInfo.action_mode = 2;
3533 } else if (GamePad.Down(PadInput_OK) != 0) {
3534 gameTask = GAME_TASK_SCRIPT_START;
3535 BtEventInfo.action_mode = 1;
3536 } else {
3537 goto action;
3538 }
3539 } else {
3540 goto action;
3541 }
3542 } else {
3543 action:
3544 if (BtActStatus.in_water != 0) {
3545 BtActStatus.action_on = 0;
3546 BtActStatus.unk_028 = 0;
3547 BtActStatus.jumping = 0;
3548 BtActStatus.action_busy = 0;
3549 BtActStatus.can_act = 1;
3550 BtActStatus.action_no = 0;
3551 BtActStatus.action_gauge = 100.0f;
3552 BtActStatus.gauge_exhausted = 0;
3553 ResetMovePower();
3554 }
3555
3556 if (GamePad.Down(PadInput_OK | 0x80) != 0 && BtActStatus.movement_locked == 0 && BtActStatus.in_water != 0) {
3557 SetSystemMes(0x47, 0x5A, MES_POS_BOTTOM, 0, NULL, NULL);
3558 DngMessMan.hide_timer = 0x5A;
3559 autoCamTrial();
3560 BtActStatus.action_on = 0;
3561 BtActStatus.unk_028 = 0;
3562 BtActStatus.jumping = 0;
3563 BtActStatus.action_busy = 0;
3564 BtActStatus.can_act = 1;
3565 BtActStatus.action_gauge = 100.0f;
3566 BtActStatus.gauge_exhausted = 0;
3567 ResetMovePower();
3568 } else if (GamePad.Down(PadInput_OK) != 0 && BtActStatus.ground_kind == 0xA && BtActStatus.movement_locked == 0 && UserStatus->cur_chara == CHARA_OSMOND) {
3569 SetSystemMes(0x50, 0x5A, MES_POS_BOTTOM, 0, NULL, NULL);
3570 DngMessMan.hide_timer = 0x5A;
3571 autoCamTrial();
3572 } else {
3573 BtEventItemNo = -1;
3574
3575 if ((iventActive = NowDngMap->GetActiveIvent(CharaFrame)) != -1 && BtActStatus.can_act != 0 && BtActStatus.movement_locked == 0) {
3576 iventInfo = NowDngMap->events[iventActive].kind;
3577 BtEventInfo.event_marker = true;
3578 iventMarker = 1;
3579 } else {
3580 iventActive = -1;
3581 iventInfo = DNG_EVENT_NONE;
3582 iventMarker = 0;
3583 }
3584
3585 if (GamePad.Down(PadInput_OK) != 0 && BtActStatus.movement_locked == 0 && BtActStatus.event_block_frames == 0) {
3586 if (iventActive != -1 && BtActStatus.recoil_frames == 0) {
3587 int done = 0;
3588
3589 switch (NowDngMap->events[iventActive].kind) {
3591 BtActStatus.motion_no = 0;
3592 entry_no = NowDngMap->events[iventActive].index;
3593
3594 if (NowDngMap->boxes[entry_no].kind == TREASURE_BOX_LARGE) {
3595 if (NowDngMap->boxes[entry_no].trap_no == 0) {
3596 gameTask = GAME_TASK_BOX_BIG_INIT;
3597 done = 1;
3598 goto opened;
3599 }
3600
3601 if (NowDngMap->boxes[entry_no].trap_no == 5) {
3602 sceVu0FVECTOR box_pos;
3603 sceVu0FVECTOR box_dir = {0.0f, 0.0f,
3604 0.0f, 1.0f};
3605
3606 sceVu0CopyVector(box_pos, NowDngMap->events[iventActive].pos);
3607 sceVu0CopyVector(BtEventInfo.position, box_pos);
3608 sceVu0CopyVector(BtEventInfo.direction, box_dir);
3609 NowDngMap->events[iventActive].kind = DNG_EVENT_NONE;
3610 BtEventInfo.script_no = 0x10;
3611 BtEventInfo.ext_memory = false;
3612 BtEventInfo.treasure_box = entry_no;
3613 BtEventInfo.action_mode = 1;
3614 gameTask = GAME_TASK_SCRIPT_START;
3615 ResetMovePower();
3616 done = 1;
3617 } else {
3618 BtEventInfo.script_no = 0xF;
3619 BtEventInfo.ext_memory = false;
3620 BtEventInfo.treasure_box = entry_no;
3621 BtEventInfo.action_mode = 1;
3622 gameTask = GAME_TASK_SCRIPT_START;
3623 ResetMovePower();
3624 done = 1;
3625 }
3626 } else {
3627 done = 1;
3628 gameTask = GAME_TASK_BOX_SMALL_INIT;
3629 opened:
3630 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3631 }
3632
3633 break;
3634 case DNG_EVENT_ATRA:
3635 BtActStatus.motion_no = 0;
3636 entry_no = NowDngMap->events[iventActive].index;
3637
3638 if (NowDngMap->atra[entry_no].used != 0) {
3639 s8 chara = UserStatus->cur_chara;
3640
3641 if (UserStatus->cur_chara == CHARA_TOAN) {
3642 gameTask = GAME_TASK_ATRA_GET_INIT;
3643 done = 1;
3644 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
3645 } else {
3646 NotGetAtraMes(chara, 0x5A);
3647 DngMessMan.hide_timer = 0x5A;
3648 }
3649 }
3650
3651 break;
3652 case DNG_EVENT_MIMIC:
3653 entry_no = NowDngMap->events[iventActive].index;
3654
3655 int item_no = NowDngMap->boxes[entry_no].item_no;
3656 CMonstorUnit *unit = NowMonstorUnit;
3657
3658 if (item_no >= 0 && item_no < 0x11) {
3659 unit->monster[item_no].revealed = 1;
3660 }
3661
3662 NowDngMap->boxes[entry_no].used = 0;
3663 NowDngMap->events[iventActive].kind = DNG_EVENT_NONE;
3664 done = 1;
3665 break;
3666 }
3667
3668 if (done != 0) {
3669 break;
3670 }
3671
3672 goto play;
3673 } else {
3674 switch (UserStatus->cur_chara) {
3675 case CHARA_TOAN:
3676 ToanKey_On();
3677 break;
3678 case CHARA_XIAO:
3679 BattleActionOn_Jinn();
3680 break;
3681 case CHARA_GORO:
3682 GoroKey_On();
3683 break;
3684 case CHARA_RUBY:
3685 BattleActionOn_Ruby();
3686 break;
3687 case CHARA_UNGAGA:
3688 UngagaKey_On();
3689 break;
3690 case CHARA_OSMOND:
3691 if (BtActStatus.gun_type == 0) {
3692 BattleActionOn_Ozumond();
3693 }
3694
3695 if (BtActStatus.gun_type == 1) {
3696 BattleActionOn_Ozumond_H();
3697 }
3698
3699 if (BtActStatus.gun_type == 2) {
3700 BattleActionOn_Ozumond_F();
3701 }
3702
3703 break;
3704 }
3705
3706 goto play;
3707 }
3708 } else {
3709 play:
3710 if (BtActStatus.action_on == 1) {
3711 switch (UserStatus->cur_chara) {
3712 case CHARA_TOAN:
3713 ToanKey_Play();
3714 break;
3715 case CHARA_XIAO:
3716 BattleActionPlay_Jinn(&CharaMain, 0);
3717 break;
3718 case CHARA_GORO:
3719 GoroKey_Play();
3720 break;
3721 case CHARA_RUBY:
3722 BattleActionPlay_Ruby(&CharaMain, 0);
3723 break;
3724 case CHARA_UNGAGA:
3725 UngagaKey_Play();
3726 break;
3727 case CHARA_OSMOND:
3728 if (BtActStatus.gun_type == 0) {
3729 BattleActionPlay_Ozumond(0);
3730 }
3731
3732 if (BtActStatus.gun_type == 1) {
3733 BattleActionPlay_Ozumond_H(0);
3734 }
3735
3736 if (BtActStatus.gun_type == 2) {
3737 BattleActionPlay_Ozumond_F(0);
3738 }
3739
3740 break;
3741 }
3742 }
3743 BtBySpeedFlag = 0;
3744
3745 if (GamePad.On(PAD_SQUARE) != 0 && BtActStatus.movement_locked == 0 && lockOnTargetFlag == 0) {
3746 if (DebugStatus[5] == 0) {
3747 BtBySpeedFlag = 1;
3748 }
3749
3750 if (BtActStatus.action_on == 0 && gameTask != GAME_TASK_UNK_F0 && BtActStatus.can_act != 0) {
3751 s16 *slots = UserStatus->active_item;
3752
3753 if (activeItem.CheckStatusType() == ACTIVE_ITEM_FEATHER && slots[itemNowSel + 3] > 0) {
3754 // A running item that
3755 // boosts is spent by the
3756 // frame while the button
3757 // is held.
3758 BtBySpeedFlag = 1;
3759 int slot = itemNowSel - 1;
3760 int left = UserStatus->active_item_vol[slot] - 1;
3761
3762 UserStatus->active_item_vol[slot] = left;
3763
3764 if (left <= 0) {
3765 DelActiveItem(itemNowSel);
3766 DngMessMan.message = 0xB6;
3767 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(-1);
3768 DngMessMan.timer = 0xB4;
3769 DngMessMan.steev_window = false;
3770 }
3771 }
3772 }
3773 }
3774
3775 if (GamePad.Down(PAD_SQUARE) != 0 && BtActStatus.movement_locked == 0 && BtActStatus.action_on == 0 && gameTask != GAME_TASK_UNK_F0 && BtActStatus.can_act != 0) {
3776 int used;
3777 s16 *slots = UserStatus->active_item;
3778
3779 used = checkItemUsed(itemNowSel - 1);
3780
3781 if (activeItem.CheckStatusType() == ACTIVE_ITEM_DRINK && used != 0 && slots[itemNowSel + 3] > 0) {
3782 CMonUnitHold = 1;
3783 CEffectHold = 1;
3784 BtActStatus.action_on = 3;
3785 BtActStatus.can_act = 0;
3786 BtActStatus.action_busy = 1;
3787
3788 if (activeItem.model[8] == -1) {
3789 activeItem.model[8] = activeItem.models->SetHandModel(activeItem.model[activeItem.now]);
3790 }
3791 }
3792
3793 if (activeItem.CheckStatusType() == ACTIVE_ITEM_EAT && used != 0 && slots[itemNowSel + 3] > 0) {
3794 setUnitAmbientAnime(64.0f, 1.0f, 0.0f, 122.0f, 208.0f);
3795 SndSePlay(SE_EFFECT_CHIME, -1, 0);
3796
3797 s32 taken = activeItem.item[activeItem.now];
3798
3799 usedActiveItem(UserStatus, taken);
3800
3801 s16 *inner = UserStatus->active_item;
3802
3803 if (inner[itemNowSel + 3] == 1) {
3804 inner[itemNowSel] = -1;
3805 inner[itemNowSel + 3] = 0;
3806 DeleteItemModel(itemNowSel);
3807 } else {
3808 inner[itemNowSel + 3]--;
3809 }
3810
3811 SndSePlay(SE_CHARA_RECOVER, -1, 0);
3812 }
3813
3814 if (activeItem.CheckStatusType() == ACTIVE_ITEM_ACTION && BtActStatus.can_act != 0 && used != 0 && BtActStatus.action_on != 2 && slots[itemNowSel + 3] > 0) {
3815 printf("throw !!\n");
3816
3817 if (lockOnTargetFlag == 0) {
3818 sceVu0FVECTOR hand;
3819
3820 BtActStatus.action_on = 2;
3821 BombInfo.aiming = true;
3822 BombInfo.throw_step = -1;
3823 sceVu0CopyVector(hand, CharaMain.pos);
3824 getCharacterVector(BombInfo.pos, 0.0f);
3825 BombInfo.pos[0] += hand[0] + 30.0f * BombInfo.pos[0];
3826 BombInfo.pos[1] = hand[1];
3827 BombInfo.pos[2] += hand[2] + 30.0f * BombInfo.pos[2];
3828 BtActStatus.motion_no = 0x1A;
3829 BtActStatus.can_act = 0;
3830 BtActStatus.action_busy = 1;
3831
3832 if (activeItem.model[8] == -1) {
3833 activeItem.model[8] = activeItem.models->SetHandModel(activeItem.model[activeItem.now]);
3834 }
3835 } else {
3836 BombInfo.throw_step = 1;
3837 BtActStatus.action_on = 2;
3838 BtActStatus.motion_no = 0x1B;
3839 BtActStatus.can_act = 0;
3840 BtActStatus.action_busy = 1;
3841
3842 if (activeItem.model[8] == -1) {
3843 activeItem.model[8] = activeItem.models->SetHandModel(activeItem.model[activeItem.now]);
3844 }
3845 }
3846 }
3847 }
3848
3849 {
3850 CDungeonEventData *state = NowEventMan->SearchDataSlotPos(pos);
3851 sceVu0FVECTOR slot_pos;
3852 sceVu0FVECTOR slot_dir;
3853
3854 if (state != NULL && BtActStatus.can_act != 0 && state->event->chara_no != -1) {
3855 BtEventInfo.script_no = -1;
3856
3857 if (state->event->script_no != -1) {
3858 BtEventInfo.script_no = state->event->script_no;
3859 BtEventInfo.ext_memory = state->event->ext_mem;
3860 BtEventInfo.action_mode = 0;
3861 sceVu0CopyVector(slot_pos, state->pos);
3862 sceVu0CopyVector(slot_dir, state->dir);
3863 sceVu0CopyVector(BtEventInfo.position, slot_pos);
3864 sceVu0CopyVector(BtEventInfo.direction, slot_dir);
3865 }
3866
3867 if (BtEventInfo.script_no != -1) {
3868 gameTask = GAME_TASK_SCRIPT_START;
3869 BtEventInfo.action_mode = 1;
3870 BtEventInfo.chara_help = false;
3871 } else {
3872 goto step;
3873 }
3874 } else {
3875 step:
3876 BattleActionThlow();
3877 BattleActionDrink();
3878
3879 int ok = 1;
3880
3881 if (BtActStatus.action_on != 0) {
3882 ok = 0;
3883 }
3884
3885 BtActStatus.slow_walking = 0;
3886
3887 if (BtActStatus.action_on == 1) {
3888 int slow = 0;
3889
3890 if (BtActStatus.action_no == 0xE && UserStatus->cur_chara == CHARA_TOAN) {
3891 slow = 1;
3892 }
3893
3894 if (BtActStatus.action_no == 0xD && UserStatus->cur_chara == CHARA_GORO) {
3895 slow = 1;
3896 }
3897
3898 if (slow != 0) {
3899 if (stickVector >= 0.1f) {
3900 velo__2[0] *= 0.4f;
3901 velo__2[2] *= 0.4f;
3902 BtActStatus.motion_no = 0x1E;
3903 CharaMain.motion_type.motion_info[30]
3904 .speed = 0.2f + stickVector / 2.0f;
3905 }
3906
3907 ok = 1;
3908 BtActStatus.slow_walking = 1;
3909 }
3910 }
3911
3912 if (BtActStatus.guard_mode == 5) {
3913 if (stickVector >= 0.1f) {
3914 velo__2[0] *= 0.4f;
3915 velo__2[2] *= 0.4f;
3916 BtActStatus.motion_no = 0x21;
3917 CharaMain.motion_type.motion_info[33]
3918 .speed = 0.2f + stickVector / 2.0f;
3919 }
3920
3921 ok = 1;
3922 BtActStatus.slow_walking = 1;
3923 }
3924
3925 if (UserStatus->cur_chara == CHARA_OSMOND) {
3926 ok = 1;
3927 }
3928
3929 if (ok == 0 || BtActStatus.can_act == 0) {
3930 velo__2[2] = 0.0f;
3931 velo__2[1] = 0.0f;
3932 velo__2[0] = 0.0f;
3933 }
3934
3935 BtCheckDamageProc();
3936
3937 if (BtActStatus.action_on == 4) {
3938 float end = CharaMain.motion_type.motion_info[4].end;
3939
3940 if (CharaMain.motion_type.state.time >= end - 2.0f && CharaMain.motion_type.state.time <= end) {
3941 BtActStatus.action_on = 0;
3942 } else {
3943 BtActStatus.motion_no = 4;
3944 }
3945 }
3946
3947 if (BtActStatus.action_on == 5) {
3948 float end = CharaMain.motion_type.motion_info[6].end;
3949
3950 if (CharaMain.motion_type.state.time >= end - 2.0f && CharaMain.motion_type.state.time <= end) {
3951 BtActStatus.action_on = 0;
3952 } else {
3953 BtActStatus.motion_no = 6;
3954 }
3955 }
3956
3957 if (UserStatus->CheckLife() <= 0 && BtActStatus.invincible_frames == 0 && BtActStatus.action_on != 5) {
3958 UserStatus->hp[UserStatus->cur_chara] = 0;
3959 DeadKeyWait = 0x168;
3960 DeadKeyStartWait = 0x3C;
3961 BtActStatus.movement_locked = 0;
3962 UserStatus->ailments[UserStatus->cur_chara] = 0;
3963 UserStatus->ailment_frames[UserStatus->cur_chara] = 0;
3964 LockOffTargte();
3965 gameTask = GAME_TASK_DEAD;
3966 } else {
3967 if (BtActStatus.action_on == 5) {
3968 velo__2[0] = blowVelo[0];
3969 velo__2[2] = blowVelo[2];
3970
3971 for (int i = 0; i < 3; i++) {
3972 float speed = blowVelo[i];
3973
3974 float step = 0.018f;
3975
3976 if (speed < 0.0f) {
3977 blowVelo[i] = speed + step;
3978
3979 if (blowVelo[i] >= -0.01f) {
3980 blowVelo[i] = 0.0f;
3981 }
3982 } else {
3983 blowVelo[i] = speed - 0.018f;
3984
3985 if (blowVelo[i] <= 0.01f) {
3986 blowVelo[i] = 0.0f;
3987 }
3988 }
3989 }
3990 }
3991
3992 if (BtActStatus.jumping > 0 && BtActStatus.jumping == 1) {
3993 velo__2[0] += BtActStatus.jump_velocity_x;
3994 velo__2[1] += BtActStatus.jump_velocity_y;
3995 velo__2[2] += BtActStatus.jump_velocity_z;
3996 BtActStatus.jump_velocity_y -= 0.1f;
3997 }
3998
3999 if (BtActStatus.move_power > 0.0f) {
4000 sceVu0FVECTOR push;
4001
4002 sceVu0ScaleVectorXYZ(push, BtActStatus.move_vector, BtActStatus.move_power);
4003 velo__2[0] += push[0];
4004 velo__2[2] += push[2];
4005 BtActStatus.move_power -= BtActStatus.move_power_decay;
4006
4007 if (BtActStatus.move_power <= 0.0f) {
4008 BtActStatus.move_power = 0.0f;
4009 }
4010 }
4011
4012 BtActStatus.ground_kind = 0;
4013
4014 if (DebugStatus[5] != 0) {
4015 if (NowDngMap->map_type != 1) {
4016 sceVu0FVECTOR moved;
4017 MoveCheckInfo info;
4018 sceVu0FVECTOR parts_pos;
4019 CBoxVu0 bound;
4020 CCPoly foot;
4021 CCPoly *polys;
4022 int mode;
4023
4024 WorkBuffer__2->used = 0;
4025 polys = (CCPoly *) WorkBuffer__2->Alloc(0x7D0);
4026 bound.max[0] = 20.0f + pos[0];
4027 bound.max[1] = 20.0f + pos[1];
4028 bound.max[2] = 20.0f + pos[2];
4029 bound.min[0] = pos[0] - 20.0f;
4030 bound.min[1] = pos[1] - 40.0f;
4031 bound.min[2] = pos[2] - 20.0f;
4032 // A random floor
4033 // is built from map
4034 // parts, so the
4035 // polygons come off
4036 // each part's own
4037 // collision model.
4038 int i = 0;
4039
4040 colPolyNum = 0;
4041
4042 for (; NowDngMap->parts[i].frame[0] != NULL; i++) {
4043 int turn;
4044
4045 collision = i == -1 ? NULL : NowDngMap->parts[i].collision;
4046
4047 if (collision != NULL) {
4048 CDungeonParts *part = &NowDngMap->parts[i];
4049
4050 sceVu0CopyVector(parts_pos, part->frame_offset[0]);
4051
4052 CDungeonMap *map = NowDngMap;
4053 CDungeonParts *turn_part = &map->parts[i];
4054
4055 turn = (int) turn_part->frame_turn[0];
4056 turn += turn_part->collision_turn;
4057
4058 if (turn > 3) {
4059 turn -= 3;
4060 }
4061
4062 if (turn == 3) {
4063 turn = -1;
4064 }
4065
4066 float rot = PI * (-90.0f * turn) / 180.0f;
4067
4068 collision->SetRotation(0.0f, rot, 0.0f);
4069 collision->SetPosition(parts_pos);
4070 colPolyNum += collision->PickUpNearPoly(&polys[colPolyNum], bound);
4071 }
4072 }
4073
4074 for (entry_no = 0; entry_no < 24; entry_no++) {
4075 if (NowDngMap->boxes[entry_no].used != 0) {
4076 collision = NowDngMap->box_collision_model;
4077
4078 collision->SetPosition(NowDngMap->boxes[entry_no].pos);
4079 colPolyNum += collision->PickUpNearPoly(&polys[colPolyNum], bound);
4080 }
4081 }
4082
4083 colPolyNum = NowDngMap->CreateCollision(polys, bound, colPolyNum);
4084 colPolyNum = NowDranMapField->AddCollision(polys, colPolyNum, bound);
4085 NowMonstorUnit->MoveCheck(pos, velo__2, lockOnTargetFlag);
4086 mode = 1;
4087
4088 if (UserStatus->cur_chara == CHARA_OSMOND) {
4089 mode = 8;
4090 }
4091
4092 MoveCheck(pos, velo__2, moved, &info, polys, colPolyNum, mode);
4093
4094 if (colPolyNum >= 0x190) {
4095 printf("er -> %d\n", colPolyNum);
4096 }
4097
4098 sceVu0SubVector(ref_off, moved, pos);
4099 veloOld[1] = velo__2[1];
4100 velo__2[1] -= 0.1f;
4101
4102 if (velo__2[1] < -10.0f) {
4103 velo__2[1] = -10.0f;
4104 }
4105
4106 sceVu0CopyVector(pos, moved);
4107
4108 if (info.landed != 0) {
4109 velo__2[1] = 0.0f;
4110 foot = info.poly;
4111 BtActStatus.foot_sound = foot.attr.foot_sound;
4112 BtActStatus.ground_kind = foot.attr.ground_kind;
4113 }
4114
4115 if (info.ground_found != 0) {
4116 BtActStatus.ground_height = pos[1] - info.ground_point[1];
4117 }
4118 } else {
4119 sceVu0FVECTOR moved;
4120 MoveCheckInfo info;
4121 CBoxVu0 bound;
4122 CCPoly foot;
4123 int mode;
4124 int x;
4125 int z;
4126 CFrame *collision;
4127
4128 WorkBuffer__2->used = 0;
4129 CCPoly *polys = (CCPoly *) WorkBuffer__2->Alloc(0x7D0);
4130 bound.max[0] = 20.0f + pos[0];
4131 bound.max[1] = 20.0f + pos[1];
4132 bound.max[2] = 20.0f + pos[2];
4133 bound.min[0] = pos[0] - 20.0f;
4134 bound.min[1] = pos[1] - 40.0f;
4135 bound.min[2] = pos[2] - 20.0f;
4136 colPolyNum = 0;
4137
4138 for (z = 0; z < 20; z++) {
4139 for (x = 0; x < 20; x++) {
4140 CDungeonMap *cmap = NowDngMap;
4141 int parts_no = cmap->cells[x + z * 20]
4142 .parts_no;
4143 MAP_CELL *cell;
4144 int turn;
4145
4146 collision = parts_no == -1 ? NULL : NowDngMap->parts[parts_no].collision;
4147 cell = &NowDngMap
4148 ->cells[x + z * 20];
4149
4150 if (selectMapNo == DUNGEON_GALLERY_OF_TIME && parts_no >= 0x28 && parts_no < 0x2C) {
4151 cell->camera_dist -= 160.0f;
4152 }
4153
4154 if (collision != NULL && cell->camera_dist <= 240.0f) {
4155 int dir = NowDngMap->cells[x + z * 20].direction;
4156 int base = parts_no == -1 ? 0 : NowDngMap->parts[parts_no].collision_turn;
4157
4158 turn = dir;
4159 turn += base;
4160
4161 if (turn > 3) {
4162 turn -= 3;
4163 }
4164
4165 if (turn == 3) {
4166 turn = -1;
4167 }
4168
4169 float rot = PI * (-90.0f * turn) / 180.0f;
4170
4171 collision->SetRotation(0.0f, rot, 0.0f);
4172 collision->SetPosition(160.0f * x, 0.0f, 160.0f * z);
4173 colPolyNum += collision
4174 ->PickUpNearPoly(&polys[colPolyNum], bound);
4175 }
4176 }
4177 }
4178
4179 for (int i = 0; i < 24; i++) {
4180 if (NowDngMap->boxes[i].used != 0) {
4181 collision = NowDngMap->box_collision_model;
4182
4183 collision->SetPosition(NowDngMap->boxes[i].pos);
4184 colPolyNum += collision->PickUpNearPoly(&polys[colPolyNum], bound);
4185 }
4186 }
4187
4188 colPolyNum = NowDngMap->CreateCollision(polys, bound, colPolyNum);
4189 NowMonstorUnit->MoveCheck(pos, velo__2, lockOnTargetFlag);
4190 mode = 1;
4191
4192 if (UserStatus->cur_chara == CHARA_OSMOND) {
4193 mode = 8;
4194 }
4195
4196 MoveCheck(pos, velo__2, moved, &info, polys, colPolyNum, mode);
4197
4198 if (colPolyNum >= 0x190) {
4199 printf("er -> %d\n", colPolyNum);
4200 }
4201
4202 sceVu0SubVector(ref_off, moved, pos);
4203 veloOld[1] = velo__2[1];
4204 velo__2[1] -= 0.1f;
4205
4206 if (velo__2[1] < -10.0f) {
4207 velo__2[1] = -10.0f;
4208 }
4209
4210 sceVu0CopyVector(pos, moved);
4211
4212 if (info.landed != 0) {
4213 velo__2[1] = 0.0f;
4214 foot = info.poly;
4215 BtActStatus.foot_sound = foot.attr.foot_sound;
4216 BtActStatus.ground_kind = foot.attr.ground_kind;
4217 }
4218
4219 if (info.ground_found != 0) {
4220 BtActStatus.ground_height = pos[1] - info.ground_point[1];
4221 }
4222 }
4223 } else {
4224 pos[0] += velo__2[0];
4225 pos[1] += velo__2[1];
4226 pos[2] += velo__2[2];
4227 }
4228
4229 if (UserStatus->cur_chara != CHARA_OSMOND) {
4230 CharaMain.FootSoundEnable(1);
4231 CharaMain.EventEnable(1);
4232 CharaMain.SetFootSoundID(BtActStatus.foot_sound);
4233 } else {
4234 static int snd_cnt;
4235 static char init;
4236 static int id_cnt;
4237 static char init2;
4238
4239 if (init == 0) {
4240 snd_cnt = 0;
4241 init = 1;
4242 }
4243
4244 if (init2 == 0) {
4245 id_cnt = 0;
4246 init2 = 1;
4247 }
4248
4249 snd_cnt++;
4250
4251 if (snd_cnt >= 5) {
4252 SndSeSeqPlayStop(0x1CC, 5, id_cnt);
4253 snd_cnt = 0;
4254 id_cnt++;
4255
4256 if (id_cnt >= 0xA) {
4257 id_cnt = 0;
4258 }
4259 }
4260 }
4261
4262 if (pos[1] <= -30.0f && selectMapNo == DUNGEON_DIVINE_BEAST_CAVE) {
4263 UserStatus->AddNowLife(UserStatus->cur_chara, -0x28, 10.0f);
4264 setUnitAmbientAnime(120.0f, 1.0f, 255.0f, 0.0f, 0.0f);
4265 ResetStatusInfo();
4266 BtEventInfo.script_no = 5;
4267 BtEventInfo.ext_memory = false;
4268 EdFadeOut(0x78, 0.0f, 0.0f, 0.0f);
4269 gameTask = GAME_TASK_SCRIPT_RESTART;
4270 } else {
4271 float time;
4272
4273 if (CharaMain.motion_type.state.time >= (float) 0x12F && CharaMain.motion_type.state.time <= 318.0f) {
4274 sceVu0FVECTOR run_pos;
4275
4276 sceVu0CopyVector(run_pos, CharaFrame->position);
4277 CRunFx__2.Set(run_pos);
4278 }
4279
4280 if (BtActStatus.movement_locked == 0) {
4281 int dust = 0;
4282
4283 time = CharaMain.motion_type.state.time;
4284
4285 if (time >= 75.0f && time <= 76.0f) {
4286 dust = 1;
4287 }
4288
4289 if (time >= 77.0f && time <= 78.0f) {
4290 dust = 1;
4291 }
4292
4293 if (time >= 85.0f && time <= 86.0f) {
4294 dust = 1;
4295 }
4296
4297 if (time >= 87.0f && time <= 88.0f) {
4298 dust = 1;
4299 }
4300
4301 if (CharaMain.motion_no == 2) {
4302 if (DistVector(velo__2) >= 0.4f) {
4303 if (time >= 38.0f && time <= 39.0f) {
4304 dust = 1;
4305 }
4306
4307 if (time >= 45.0f && time <= 46.0f) {
4308 dust = 1;
4309 }
4310 } else {
4311 dust = 0;
4312 }
4313 }
4314
4315 if (dust != 0) {
4316 sceVu0FVECTOR step_pos;
4317
4318 sceVu0CopyVector(step_pos, CharaFrame->position);
4319
4320 if (UserStatus->cur_chara != CHARA_OSMOND) {
4321 CRunFx__2.Set(step_pos);
4322 }
4323 }
4324 }
4325
4326 HealingWater();
4327 float turn = GamePad.GetRXf();
4328
4329 NowCamera__3->AddHeight(-GamePad.GetRYf());
4330
4331 if (NowCamera__3->GetHeight() >= 30.0f) {
4332 NowCamera__3->SetHeight(30.0f);
4333 }
4334
4335 NowCamera__3->AddAngle(0.04f * -turn);
4336
4337 if (lockOnTargetFlag == 0) {
4338 if (GamePad.On(PAD_R1) != 0) {
4339 NowCamera__3->AddAngle(-0.034906585f);
4340 }
4341
4342 if (GamePad.On(PAD_L1) != 0) {
4343 NowCamera__3->AddAngle(0.034906585f);
4344 }
4345 }
4346
4347 if (GamePad.On(PAD_L2) != 0) {
4348 sceVu0FMATRIX look;
4349
4350 CharaFrame->GetLWMatrix(look);
4351 NowCamera__3->SetAngle(atan2f(look[2][0], look[2][2]) - PI_D);
4352 }
4353
4354 if (GamePad.Down(PAD_R2) != 0 && BtActStatus.recoil_frames == 0 && BtActStatus.action_busy == 0) {
4355 oldCameraAngle = NowCamera__3->GetAngle();
4356 oldCameraHeight = NowCamera__3->GetHeight();
4357 NowCamera__3->FollowOff();
4358 BtActStatus.player_visible = 0;
4359 viewMode__2 = 1;
4360 InitEyeCamera();
4361
4362 if (UserStatus->cur_chara == CHARA_XIAO) {
4363 EquipReAttach(NowWeapon, 1);
4364 }
4365
4366 BtActStatus.unk_028 = 0;
4367 BtActStatus.motion_no = 0;
4368 BtActStatus.action_on = 0;
4369 BtActStatus.action_no = 0;
4370 LockOffTargte();
4371 ResetMovePower();
4372
4373 if (ruby_effect_id != -1 && UserStatus->cur_chara == CHARA_RUBY) {
4374 NowMainEffect->OffEffect(ruby_effect_id);
4375 ruby_effect_id = -1;
4376 }
4377
4378 gameTask = GAME_TASK_EYE_CAMERA;
4379 } else {
4380 sceVu0FVECTOR follow;
4381
4382 if (pos[1] < -100.0f) {
4383 pos[1] += 200.0f;
4384 }
4385
4386 CharaFrame->SetPosition(pos[0], pos[1], pos[2]);
4387 sceVu0CopyVector(follow, pos);
4388 follow[0] += 7.0f * ref_off[0];
4389 follow[1] += BtActStatus.camera_shake_offset + (6.0f + (2.0f * ref_off[1] + reference[1]));
4390 follow[2] += 7.0f * ref_off[2];
4391 NowCamera__3->SetFollow(follow[0], follow[1], follow[2]);
4392
4393 if (lockOnTargetFlag != 0) {
4394 CCharacter *locked = &NowMonstorUnit
4395 ->chara[lockOnTargetNo][0];
4396 sceVu0FVECTOR to_target;
4397 sceVu0FVECTOR target;
4398 float dist;
4399
4400 locked->GetPosition(target);
4401 dist = DistVector(target, pos);
4402 to_target[0] = target[0] - pos[0];
4403 to_target[1] = target[1] - pos[1];
4404 to_target[2] = target[2] - pos[2];
4405 to_target[3] = 1.0f;
4406
4407 if (dist >= 20.0f) {
4408 dist = 20.0f;
4409 }
4410
4411 sceVu0Normalize(to_target, to_target);
4412 sceVu0ScaleVectorXYZ(to_target, to_target, dist);
4413 to_target[1] = 0.0f;
4414 NowCamera__3->SetFollow(pos[0] + to_target[0], BtActStatus.camera_shake_offset + (to_target[1] + (6.0f + pos[1] + reference[1])), pos[2] + to_target[2]);
4415 }
4416
4417 autoCamTrial();
4418 }
4419 }
4420 }
4421 }
4422 }
4423 }
4424 }
4425 }
4426 }
4427 }
4428 }
4429 }
4430 }
4431
4432 break;
4433 case GAME_TASK_SCRIPT_RESTART:
4434 gameTask = GAME_TASK_SCRIPT_START;
4435 break;
4436 case GAME_TASK_FLOOR_FADE_RESET:
4437 if (EdFadeOutCheck() != 0) {
4438 int i;
4439 CSHOT_EFFECT *effects = NowShotEffect->effect;
4440
4441 for (i = 0; i < 5; i++) {
4442 effects[i].Initialize();
4443 }
4444
4445 NowMonstorUnit->CleanViewMonstor(BtUraDongeon);
4446
4447 CMonstorUnit *unit = (CMonstorUnit *) NowMonstorUnit;
4448
4449 unit->requested_event = -1;
4450 driveStepHold = 0;
4451 gameTask = GAME_TASK_SCRIPT_START;
4452 }
4453
4454 break;
4455 case GAME_TASK_SCRIPT_START:
4456 LockOffTargte();
4457 CharaMain.motion_no = 0;
4458 CharaMain.motion_flags = 0;
4459 CharaMain.motion_speed = -1.0f;
4460 BtActStatus.action_on = 0;
4461 DngMessMan.enabled = false;
4462 DngMessMan.message = -1;
4463 DngMessMan.timer = 0;
4464 DngMessMan.steev_window = false;
4465 DngMessMan.steev_index = 0;
4466 DngMessMan.hide_timer = 0;
4467 DngMes1.mes_made = -1;
4468 DngMes2.mes_made = -1;
4469 DngMesStb.mes_made = -1;
4470 BtEventInfo.running_script_no = BtEventInfo.script_no;
4471 BtEventInfo.script_no = -1;
4472 ResetMovePower();
4473 BtSystemScriptInit();
4474
4475 if (BtEventInfo.ext_memory == 0) {
4476 printf("********** system mem !!!\n");
4477 BtCashBuffer.base = BtScriptWorkBuffer.base;
4478 BtCashBuffer.limit = 0x186A0;
4479 BtCashBuffer.used = 0;
4480 }
4481
4482 if (BtEventInfo.ext_memory != 0) {
4483 int i;
4484 CSHOT_EFFECT *effects;
4485
4486 printf("********** ext mem !!!\n");
4487 TexManager.DeleteTextureBlock(0x2A);
4488 TexManager.DeleteTextureBlock(0x26);
4489 TexManager.CleanUpBuffer();
4490 TexManager.CleanUpTextureList();
4491 effects = NowShotEffect->effect;
4492
4493 for (i = 0; i < 5; i++) {
4494 effects[i].Initialize();
4495 }
4496
4497 MainMonstorUnit.CleanViewMonstor(BtUraDongeon);
4498 MonstorModelBuffer.used = 0;
4499 u8 *cash = MonstorModelBuffer.base;
4500 u32 cash_size = MonstorModelBuffer.limit;
4501
4502 BtCashBuffer.base = cash;
4503 BtCashBuffer.limit = cash_size + 0x88B8;
4504 BtCashBuffer.used = 0;
4505 read_buffer = old_read_buffer + 0x88B80 / 4;
4506 }
4507
4508 if (BtSystemScriptRun(BtEventInfo.running_script_no, &BtCashBuffer) == 0) {
4509 BtSystemScriptAfter();
4510 gameTask = GAME_TASK_PLAY;
4511 } else {
4512 gameTask++;
4513 }
4514
4515 break;
4516 case GAME_TASK_SCRIPT_RUN:
4517 if (EdEventMode(NowCamera__3, 0) > 0) {
4518 BtSystemScriptAfter();
4519 read_buffer = old_read_buffer;
4520 DngMes1.mes_made = -1;
4521 DngMes2.mes_made = -1;
4522 DngMesStb.mes_made = -1;
4523 Mes1MakeFlg = 1;
4524 Mes2MakeFlg = 1;
4525 DngMessMan.message = -1;
4526 DngMessMan.timer = 0;
4527 DngMessMan.steev_window = false;
4528 DngMessMan.steev_index = 0;
4529 DngMessMan.hide_timer = 0;
4530 DngMessMan.enabled = true;
4531 gameTask = GAME_TASK_PLAY;
4532 printf("exit script\n");
4533
4534 if (EdEventInfo.return_code == ED_EVENT_RETURN_MAP_JUMP) {
4535 existFlag = 1;
4536 }
4537 }
4538
4539 SetBattleStyle(selectMapNo, 1);
4540
4541 switch (BtEventInfo.request) {
4542 case BT_REQUEST_ITEM_WINDOW:
4543 BtEventInfo.request = BT_REQUEST_NONE;
4544 BtMiniItemSelect();
4545 gameTask = GAME_TASK_SCRIPT_ITEM_SELECT;
4546 break;
4547 case BT_REQUEST_URA_DUNGEON:
4548 BtEventInfo.request = BT_REQUEST_NONE;
4549 gameTask = GAME_TASK_URA_SWAP;
4550 break;
4551 case BT_REQUEST_ENTRANCE_WINDOW:
4552 BtEventInfo.request = BT_REQUEST_NONE;
4553 InitDunEnterMenu(0x17, selectMapNo, -1);
4554 BtGameModeFlag = BT_GAME_MODE_ENTRANCE_MENU;
4555 break;
4556 case BT_REQUEST_ESCAPE_WINDOW:
4557 BtEventInfo.request = BT_REQUEST_NONE;
4558 DngEscapeMsgInit(&DngMes2, &DngMes1, 0);
4559 BtGameModeFlag = BT_GAME_MODE_ESCAPE_MSG;
4560 break;
4561 case BT_REQUEST_GO_DUNGEON:
4562 BtEventInfo.request = BT_REQUEST_NONE;
4563 BtSystemScriptAfter();
4564 read_buffer = old_read_buffer;
4565 ClearGateKeyStack();
4566 SaveData->AddNowTime(1.0f);
4567 DngMes1.mes_made = -1;
4568 DngMes2.mes_made = -1;
4569 DngMesStb.mes_made = -1;
4570 Mes1MakeFlg = 1;
4571 Mes2MakeFlg = 1;
4572 DngMessMan.message = -1;
4573 DngMessMan.timer = 0;
4574 DngMessMan.steev_window = false;
4575 DngMessMan.steev_index = 0;
4576 DngMessMan.hide_timer = 0;
4577 DngMessMan.enabled = true;
4578
4579 if (UserStatus->res_limit_zone_current != RES_LIMIT_ZONE_NONE) {
4580 DngMessMan.LimmitZone();
4581 SndSPSePlay(0x1B, -1);
4582 }
4583
4584 if (UserStatus->CheckLife() <= 0) {
4585 s8 chara = UserStatus->cur_chara;
4586
4587 UserStatus->hp[chara] = 1;
4588 }
4589
4590 rogoSwitch2 = 1;
4591 infoMap = 0;
4592 infoMapOld = 0;
4593 rogoY3 = -0x60;
4594 startCnt2 = 0;
4595 gameTask = GAME_TASK_PLAY;
4596 printf("go dungeon\n");
4597 break;
4598 case BT_REQUEST_RUN_SCRIPT:
4599 BtEventInfo.request = BT_REQUEST_NONE;
4600 BtSystemScriptAfter();
4601 BtEventInfo.script_no = BtEventInfo.chained_script_no;
4602 gameTask = GAME_TASK_SCRIPT_START;
4603 break;
4604 }
4605
4606 break;
4607 case GAME_TASK_SCRIPT_ITEM_SELECT:
4608 if (BtMiniItemSelect_Loop() != 0) {
4609 gameTask = GAME_TASK_SCRIPT_RUN;
4610 DngMes1.mes_made = -1;
4611 DngMes2.mes_made = -1;
4612 DngMesStb.mes_made = -1;
4613 }
4614
4615 break;
4616 case GAME_TASK_URA_SWAP: {
4617 int ura = BtUraDongeon;
4618 CMonstorUnit *unit = NowMonstorUnit;
4619
4620 unit->model_count = 0;
4621 unit->current_monster = 0;
4622
4623 for (int i = 0; i < 16; i++) {
4624 unit->script[i] = &MonstorScriptBuffer[i];
4625 }
4626
4627 unit->requested_event = -1;
4628 unit->CleanViewMonstor(ura);
4629 BtSetEventExtendTable();
4630
4631 if (BtUraDongeon == 0) {
4632 BtUraDongeon = 1;
4633 NowDngMap = &UraDungeonMap;
4634 NowEventMan = &UraEventMan;
4635 NowDngMap->RsetMimicEvent();
4636 RandomItem = &SubRandomItem;
4637 NowMonstorUnit->CleanViewMonstor(BtUraDongeon);
4638
4639 int ura = BtUraDongeon;
4640 CMonstorUnit *unit_now = NowMonstorUnit;
4641
4642 unit_now->model_count = 0;
4643 unit_now->current_monster = 0;
4644
4645 for (int i = 0; i < 16; i++) {
4646 unit_now->script[i] = &MonstorScriptBuffer[i];
4647 }
4648
4649 unit_now->requested_event = -1;
4650 unit_now->CleanViewMonstor(ura);
4651 BtSetEventExtendTable();
4652 BtLoadMonstor(1);
4653 NowMonstorUnit->ArrangementPos(&UraDungeonMap, 8, -1, 0);
4654 NowDngMap->DrawMapCalc(NowDngMap->map_type);
4655 lightingMode = 1;
4656 } else {
4657 BtUraDongeon = 0;
4658 NowDngMap = &MainDungeonMap;
4659 NowEventMan = &DngEventMan;
4660 NowMonstorUnit = &MainMonstorUnit;
4661 NowDngMap->RsetMimicEvent();
4662 RandomItem = &MainRandomItem;
4663 MainMonstorUnit.CleanViewMonstor(BtUraDongeon);
4664
4665 int ura = BtUraDongeon;
4666
4667 MainMonstorUnit.model_count = 0;
4668 MainMonstorUnit.current_monster = 0;
4669
4670 for (int i = 0; i < 16; i++) {
4671 MainMonstorUnit.script[i] = &MonstorScriptBuffer[i];
4672 }
4673
4674 MainMonstorUnit.requested_event = -1;
4675 MainMonstorUnit.CleanViewMonstor(ura);
4676 BtSetEventExtendTable();
4677 BtLoadMonstor(0);
4678 MainMonstorUnit.ArrangementPos(&MainDungeonMap, 0xF, -1, 0);
4679 NowDngMap->DrawMapCalc(NowDngMap->map_type);
4680 lightingMode = 0;
4681 }
4682
4683 gameTask = GAME_TASK_SCRIPT_RUN;
4684 break;
4685 }
4686 case GAME_TASK_DEBUG_OPEN:
4687 driveStepHold = 1;
4688 CMonUnitHold = 1;
4689 CEffectHold = 1;
4690 DebugStatus[0] = 1;
4691 GamePad.SetAutoRepeat(PAD_L2 | PAD_R2 | PAD_L1 | PAD_R1 | PAD_DPAD, 0x14, 3);
4692 gameTask++;
4693 break;
4694 case GAME_TASK_DEBUG_MENU:
4695 switch (DebugInfomationIF()) {
4696 case DEBUG_INFO_UNK_28:
4697 GamePad.AutoRepeatOff();
4698 driveStepHold = 0;
4699 CMonUnitHold = 0;
4700 CEffectHold = 0;
4701 gameTask++;
4702 break;
4703 case DEBUG_INFO_UNK_3C:
4704 GamePad.AutoRepeatOff();
4705 driveStepHold = 0;
4706 CMonUnitHold = 0;
4707 CEffectHold = 0;
4708 gameTask = GAME_TASK_DEBUG_RELOAD_MONSTER;
4709 break;
4710 case DEBUG_INFO_RELOAD_ENEMY:
4711 GamePad.AutoRepeatOff();
4712 driveStepHold = 0;
4713 CMonUnitHold = 0;
4714 CEffectHold = 0;
4715 gameTask = GAME_TASK_DEBUG_RELOAD_MONSTER_SET;
4716 break;
4717 case DEBUG_INFO_SET_CHR_KEY:
4718 GamePad.AutoRepeatOff();
4719 driveStepHold = 0;
4720 CMonUnitHold = 0;
4721 CEffectHold = 0;
4722 gameTask = GAME_TASK_PLAY;
4723 break;
4724 case DEBUG_INFO_CLOSE:
4725 GamePad.AutoRepeatOff();
4726 driveStepHold = 0;
4727 CMonUnitHold = 0;
4728 CEffectHold = 0;
4729 lightingMode = DebugStatus[16];
4730 gameTask = GAME_TASK_PLAY;
4731 break;
4732 case DEBUG_INFO_FLOOR_ATRA_GET:
4733 GamePad.AutoRepeatOff();
4734
4735 for (int i = 0; i < 8; i++) {
4736 int atra_no = NowDngMap->atra[i].atra_no;
4737
4738 if (atra_no != -1) {
4739 int atra = UserStatus->atra_registry[selectMapNo][atra_no].id;
4740
4741 getAtraToSaveData(atra, atra_no, SaveData, selectMapNo, UserStatus->cur_floor);
4742 }
4743 }
4744
4745 driveStepHold = 0;
4746 CMonUnitHold = 0;
4747 CEffectHold = 0;
4748 gameTask = GAME_TASK_PLAY;
4749 break;
4750 case DEBUG_INFO_EVENT_TEST:
4751 GamePad.AutoRepeatOff();
4752 driveStepHold = 0;
4753 CMonUnitHold = 0;
4754 CEffectHold = 0;
4755 gameTask++;
4756 break;
4757 case DEBUG_INFO_SET_STATUS:
4758 GamePad.AutoRepeatOff();
4759
4760 switch (DebugStatus[17]) {
4761 case 0:
4762 UserStatus->ailments[UserStatus->cur_chara] = 0;
4763 UserStatus->ailment_frames[UserStatus->cur_chara] = 0;
4764 break;
4765 case 1:
4766 BtSetStatusErr(AILMENT_FREEZE);
4767 break;
4768 case 2:
4769 BtSetStatusErr(AILMENT_STAMINA);
4770 break;
4771 case 3:
4772 BtSetStatusErr(AILMENT_POISON);
4773 break;
4774 case 4:
4775 BtSetStatusErr(AILMENT_CURSE);
4776 break;
4777 case 5:
4778 BtSetStatusErr(AILMENT_GOO);
4779 break;
4780 }
4781
4782 driveStepHold = 0;
4783 CMonUnitHold = 0;
4784 CEffectHold = 0;
4785 gameTask = GAME_TASK_PLAY;
4786 break;
4787 }
4788
4789 break;
4790 case GAME_TASK_DEBUG_RUN_EVENT:
4791 BtEventInfo.script_no = DebugStatus[11];
4792 BtEventInfo.ext_memory = DebugStatus[12];
4793 BtEventInfo.action_mode = 0;
4794 BtSystemScriptLoad(selectMapNo);
4795 gameTask = GAME_TASK_SCRIPT_START;
4796 break;
4797 case GAME_TASK_DEBUG_RELOAD_MONSTER: {
4798 int ura = BtUraDongeon;
4799 CMonstorUnit *unit = NowMonstorUnit;
4800
4801 unit->model_count = 0;
4802 unit->current_monster = 0;
4803
4804 for (int i = 0; i < 16; i++) {
4805 unit->script[i] = &MonstorScriptBuffer[i];
4806 }
4807
4808 unit->requested_event = -1;
4809 unit->CleanViewMonstor(ura);
4810 BtSetEventExtendTable();
4811 BtLoadMonstor(0);
4812 NowMonstorUnit->CleanViewMonstor(BtUraDongeon);
4813 NowMonstorUnit->ArrangementPos(NowDngMap, DebugStatus[13], -1, 0);
4814 gameTask = GAME_TASK_PLAY;
4815 break;
4816 }
4817 case GAME_TASK_DEBUG_RELOAD_MONSTER_SET: {
4818 int ura = BtUraDongeon;
4819 CMonstorUnit *unit = NowMonstorUnit;
4820
4821 unit->model_count = 0;
4822 unit->current_monster = 0;
4823
4824 for (int i = 0; i < 16; i++) {
4825 unit->script[i] = &MonstorScriptBuffer[i];
4826 }
4827
4828 unit->requested_event = -1;
4829 unit->CleanViewMonstor(ura);
4830 BtSetEventExtendTable();
4831 BtLoadMonstor(0);
4832 NowMonstorUnit->CleanViewMonstor(BtUraDongeon);
4833 NowMonstorUnit->ArrangementPos(NowDngMap, DebugStatus[15], DebugStatus[14], 0);
4834 gameTask = GAME_TASK_PLAY;
4835 break;
4836 }
4837 case GAME_TASK_PAUSE:
4838 if (GamePad.Down(PAD_START) != 0) {
4839 driveStepHold = 0;
4840 exitMenuFlag = 0;
4841 CMonUnitHold = 0;
4842 CEffectHold = 0;
4843 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
4844 PlayTimeCountFlag(1);
4845
4846 if (viewMode__2 != 0) {
4847 gameTask = GAME_TASK_EYE_CAMERA;
4848 } else {
4849 gameTask = GAME_TASK_PLAY;
4850 }
4851 }
4852
4853 break;
4854 case GAME_TASK_MAPJUMP_FADE_START:
4855 DispFade__3.FadeInit(0.0f);
4856 DispFade__3.FadeOutStart(8.0f);
4857 autoCamTrial();
4858 gameTask++;
4859 break;
4860 case GAME_TASK_MAPJUMP_FADE_WAIT:
4861 autoCamTrial();
4862
4863 if (DispFade__3.GetRate() >= 128.0f) {
4864 MapJump(0x320, -1);
4865 existFlag = 1;
4866 }
4867
4868 break;
4869 case GAME_TASK_ESCAPE_INIT:
4870 BtEscape_Init();
4871 gameTask++;
4872 break;
4873 case GAME_TASK_ESCAPE_LOOP:
4874 if (BtEscape_Loop() != 0) {
4875 DispFade__3.FadeInit(128.0f);
4876 gameTask = GAME_TASK_EXIT_FADE_WAIT;
4877 }
4878
4879 break;
4880 case GAME_TASK_EXIT_FADE_START:
4881 DispFade__3.FadeInit(0.0f);
4882 DispFade__3.FadeOutStart(8.0f);
4883 autoCamTrial();
4884 gameTask++;
4885 break;
4886 case GAME_TASK_EXIT_FADE_WAIT:
4887 autoCamTrial();
4888
4889 if (DispFade__3.GetRate() >= 128.0f) {
4890 int map_no;
4891
4892 switch (selectMapNo) {
4893 case DUNGEON_DIVINE_BEAST_CAVE:
4894 map_no = 0;
4895 break;
4896 case DUNGEON_WISE_OWL_FOREST:
4897 map_no = 1;
4898 break;
4899 case DUNGEON_SHIPWRECK:
4900 map_no = 0x13;
4901 break;
4902 case DUNGEON_SUN_MOON_TEMPLE:
4903 map_no = 0x2A;
4904 break;
4905 case DUNGEON_MOON_SEA:
4906 map_no = 0x17;
4907 break;
4908 case DUNGEON_GALLERY_OF_TIME:
4909 map_no = 0x26;
4910 break;
4911 case DUNGEON_DEMON_SHAFT:
4912 map_no = 0x3C;
4913 break;
4914 }
4915
4916 MapJump(map_no, -1);
4917 existFlag = 2;
4918 }
4919
4920 break;
4921 case GAME_TASK_SYSMES_WAIT:
4922 if (GamePad.Down(PadInput_OK | PadInput_NO) != 0) {
4923 ClearSystemMes();
4924 driveStepHold = 0;
4925 CMonUnitHold = 0;
4926 CMonUnitHyde = 0;
4927 CEffectHold = 0;
4928 CEffectHyde = 0;
4929 gameTask = GAME_TASK_PLAY;
4930 }
4931
4932 autoCamTrial();
4933 break;
4934 case GAME_TASK_GATE_KEY_LOOP:
4935 if (BtGetGateKey_Loop() != 0) {
4936 gameTask = GAME_TASK_PLAY;
4937 }
4938
4939 autoCamTrial();
4940 break;
4941 case GAME_TASK_ATTACH_LOOP:
4942 if (BtGetAttach_Loop() != 0) {
4943 gameTask = GAME_TASK_PLAY;
4944 }
4945
4946 break;
4947 case GAME_TASK_EYE_CAMERA:
4948 EyeCamera();
4949
4950 if (GamePad.Down(PAD_START) != 0) {
4951 exitMenuFlag = 1;
4952 driveStepHold = 1;
4953 CMonUnitHold = 1;
4954 CEffectHold = 1;
4955 PlayTimeCountFlag(0);
4956 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
4957 gameTask = GAME_TASK_PAUSE;
4958 } else {
4959 int next_task;
4960 int leaving;
4961 int hand_ok;
4962
4963 if (StatusErrCheck(AILMENT_FREEZE) != 0) {
4964 BtActStatus.movement_locked = 1;
4965 }
4966
4967 HealingWater();
4968
4969 CUserStatus *drain_status = UserStatus;
4970
4971 hand_ok = 1;
4972 drain_status->water_drain_disable = 1;
4973 next_task = GAME_TASK_PLAY;
4974 leaving = 0;
4975
4976 if (NowDngMap->map_type != 1 && selectMapNo == DUNGEON_DIVINE_BEAST_CAVE) {
4977 sceVu0FVECTOR moved;
4978 MoveCheckInfo info;
4979 sceVu0FVECTOR parts_pos;
4980 CBoxVu0 bound;
4981 CCPoly foot;
4982 CCPoly *polys;
4983 int mode;
4984
4985 sceVu0CopyVector(pos, CharaMain.pos);
4986 velo__2[2] = 0.0f;
4987 velo__2[0] = 0.0f;
4988 WorkBuffer__2->used = 0;
4989 polys = (CCPoly *) WorkBuffer__2->Alloc(0x7D0);
4990 bound.max[0] = 20.0f + pos[0];
4991 bound.max[1] = 20.0f + pos[1];
4992 bound.max[2] = 20.0f + pos[2];
4993 bound.min[0] = pos[0] - 20.0f;
4994 bound.min[1] = pos[1] - 40.0f;
4995 bound.min[2] = pos[2] - 20.0f;
4996 int i = 0;
4997 int offset;
4998 unsigned int address;
4999
5000 colPolyNum = 0;
5001
5002 for (; (address = (unsigned int) NowDngMap, offset = i * (int) sizeof(CDungeonParts), ((CDungeonMap *) (offset + address))->parts[0].frame[0] != NULL); i++) {
5003 CFrame *collision;
5004 int turn;
5005
5006 collision = i == -1 ? NULL : (address = (unsigned int) NowDngMap, ((CDungeonMap *) (offset + address))->parts[0].collision);
5007
5008 if (collision != NULL) {
5009 CDungeonParts *part = &((CDungeonMap *) ((char *) NowDngMap + offset))->parts[0];
5010
5011 sceVu0CopyVector(parts_pos, part->frame_offset[0]);
5012
5013 CDungeonParts *turn_part = &((CDungeonMap *) ((char *) NowDngMap + offset))->parts[0];
5014
5015 turn = (int) turn_part->frame_turn[0];
5016 turn += turn_part->collision_turn;
5017
5018 if (turn > 3) {
5019 turn -= 3;
5020 }
5021
5022 if (turn == 3) {
5023 turn = -1;
5024 }
5025
5026 float rot = PI * (-90.0f * turn) / 180.0f;
5027
5028 collision->SetRotation(0.0f, rot, 0.0f);
5029 collision->SetPosition(parts_pos);
5030 colPolyNum += collision->PickUpNearPoly(&polys[colPolyNum], bound);
5031 }
5032 }
5033
5034 colPolyNum = NowDranMapField->AddCollision(polys, colPolyNum, bound);
5035 mode = 1;
5036
5037 if (UserStatus->cur_chara == CHARA_OSMOND) {
5038 mode = 8;
5039 }
5040
5041 MoveCheck(pos, velo__2, moved, &info, polys, colPolyNum, mode);
5042
5043 if (colPolyNum >= 0x190) {
5044 printf("er -> %d\n", colPolyNum);
5045 }
5046
5047 sceVu0SubVector(ref_off, moved, pos);
5048 veloOld[1] = velo__2[1];
5049 velo__2[1] -= 0.1f;
5050
5051 if (velo__2[1] < -10.0f) {
5052 velo__2[1] = -10.0f;
5053 }
5054
5055 sceVu0CopyVector(pos, moved);
5056
5057 if (info.landed != 0) {
5058 velo__2[1] = 0.0f;
5059 foot = info.poly;
5060 BtActStatus.foot_sound = foot.attr.foot_sound;
5061 BtActStatus.ground_kind = foot.attr.ground_kind;
5062 }
5063
5064 if (info.ground_found != 0) {
5065 BtActStatus.ground_height = pos[1] - info.ground_point[1];
5066 }
5067
5068 CharaMain.SetPosition(pos);
5069
5070 if (pos[1] <= -30.0f) {
5071 leaving = 1;
5072 }
5073 }
5074
5075 if (GamePad.Down(PadInput_OK) != 0 && BtActStatus.movement_locked == 0 && BtActStatus.in_water != 0) {
5076 SetSystemMes(0x47, 0x5A, MES_POS_BOTTOM, 0, NULL, NULL);
5077 DngMessMan.hide_timer = 0x5A;
5078 hand_ok = 0;
5079 }
5080
5081 if (GamePad.Down(PadInput_OK) != 0 && BtActStatus.ground_kind == 0xA && BtActStatus.movement_locked == 0 && UserStatus->cur_chara == CHARA_OSMOND) {
5082 SetSystemMes(0x50, 0x5A, MES_POS_BOTTOM, 0, NULL, NULL);
5083 DngMessMan.hide_timer = 0x5A;
5084 hand_ok = 0;
5085 }
5086
5087 s8 who = UserStatus->cur_chara;
5088
5089 if ((UserStatus->cur_chara == CHARA_XIAO || who == CHARA_RUBY || who == CHARA_OSMOND) && hand_ok != 0 && BtActStatus.movement_locked == 0) {
5090 float head = viewAngleH__2;
5091
5092 if (head - PI <= -PI) {
5093 head = viewAngleH__2;
5094 }
5095
5096 CharaHand.SetRotation(viewAngleV__2, head, 0.0f);
5097 CharaMainHandViewFlag = 1;
5098
5099 switch (UserStatus->cur_chara) {
5100 case CHARA_XIAO:
5101 if (GamePad.Down(PadInput_OK) != 0) {
5102 BattleActionOn_Jinn();
5103 }
5104
5105 break;
5106 case CHARA_RUBY:
5107 if (GamePad.Down(PadInput_OK) != 0) {
5108 BattleActionOn_Ruby();
5109 }
5110
5111 break;
5112 case CHARA_OSMOND:
5113 if (GamePad.Down(PadInput_OK) != 0) {
5114 if (BtActStatus.gun_type == 0) {
5115 BattleActionOn_Ozumond();
5116 }
5117
5118 if (BtActStatus.gun_type == 1) {
5119 BattleActionOn_Ozumond_H();
5120 }
5121
5122 if (BtActStatus.gun_type == 2) {
5123 BattleActionOn_Ozumond_F();
5124 }
5125 }
5126
5127 break;
5128 }
5129
5130 if (BtActStatus.action_on == 1) {
5131 switch (UserStatus->cur_chara) {
5132 case CHARA_XIAO:
5133 BattleActionPlay_Jinn(&CharaHand, 1);
5134 break;
5135 case CHARA_RUBY:
5136 BattleActionPlay_Ruby(&CharaHand, 1);
5137 break;
5138 case CHARA_OSMOND:
5139 if (BtActStatus.gun_type == 0) {
5140 BattleActionPlay_Ozumond(1);
5141 }
5142
5143 if (BtActStatus.gun_type == 1) {
5144 BattleActionPlay_Ozumond_H(1);
5145 }
5146
5147 if (BtActStatus.gun_type == 2) {
5148 BattleActionPlay_Ozumond_F(1);
5149 }
5150
5151 break;
5152 }
5153 }
5154 }
5155
5156 SetBattleStyle(selectMapNo, 0);
5157
5158 if (GamePad.Down(PAD_TRIANGLE) != 0) {
5159 int ok = 1;
5160
5161 if (BtActStatus.action_on != 0) {
5162 ok = 0;
5163 }
5164
5165 if (BtActStatus.movement_locked != 0) {
5166 ok = 1;
5167 }
5168
5169 if (UserStatus->hp[UserStatus->cur_chara] <= 0) {
5170 ok = 0;
5171 }
5172
5173 if (ok != 0) {
5174 gameTask = GAME_TASK_MENU_OPEN;
5175 driveStepHold = 1;
5176 SetMIniMapStatus(0);
5177 iventInfo = DNG_EVENT_NONE;
5178 rogoSwitch2 = 0;
5179 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
5180 } else {
5181 goto eye_event;
5182 }
5183 } else {
5184 CDungeonEventData *state;
5185
5186 eye_event:
5187 state = NowEventMan->SearchDataSlotPos(pos);
5188
5189 if (state != NULL && state->event->chara_no != -1) {
5190 sceVu0FVECTOR slot_pos;
5191 sceVu0FVECTOR slot_dir;
5192
5193 BtEventInfo.script_no = -1;
5194
5195 if (state->event->script_no != -1) {
5196 BtEventInfo.script_no = state->event->script_no;
5197 BtEventInfo.ext_memory = state->event->ext_mem;
5198 BtEventInfo.event_marker = true;
5199 BtEventInfo.action_mode = 0;
5200 sceVu0CopyVector(slot_pos, state->pos);
5201 sceVu0CopyVector(slot_dir, state->dir);
5202 sceVu0CopyVector(BtEventInfo.position, slot_pos);
5203 sceVu0CopyVector(BtEventInfo.direction, slot_dir);
5204 }
5205
5206 if (BtEventInfo.script_no != -1) {
5207 leaving = 1;
5208 BtEventInfo.action_mode = 1;
5209 BtEventInfo.chara_help = false;
5210 next_task = GAME_TASK_SCRIPT_START;
5211 }
5212 }
5213
5214 if (NowMonstorUnit->requested_event != -1) {
5215 BtEventInfo.script_no = NowMonstorUnit->requested_event;
5216 BtEventInfo.ext_memory = true;
5217 ResetStatusInfo();
5218 driveStepHold = 1;
5219 EdFadeInit();
5220 EdFadeOut(0x78, 0.0f, 0.0f, 0.0f);
5221 BtEventInfo.fade_on_start = false;
5222 next_task = GAME_TASK_FLOOR_FADE_RESET;
5223 leaving = 1;
5224 }
5225
5226 if (UserStatus->CheckLife() != 0) {
5227 int event = NowMonstorUnit->CheckEventFlag2();
5228
5229 if (event != -1) {
5230 BtEventInfo.script_no = event;
5231 BtEventInfo.ext_memory = false;
5232 BtActStatus.action_busy = 0;
5233 next_task = GAME_TASK_SCRIPT_START;
5234 leaving = 1;
5235 }
5236 }
5237
5238 if (UserStatus->CheckLife() != 0 && NowMonstorUnit->GetMonstorNum() <= 0) {
5239 if (BtEventInfo.clear_script_no != -1) {
5240 BtEventInfo.script_no = BtEventInfo.clear_script_no;
5241 BtEventInfo.ext_memory = BtEventInfo.clear_script_ext_memory;
5242 BtEventInfo.clear_script_no = -1;
5243 BtEventInfo.clear_script_ext_memory = 0;
5244 BtActStatus.action_busy = 0;
5245 printf("dead script !!\n");
5246 next_task = GAME_TASK_SCRIPT_START;
5247 leaving = 1;
5248 }
5249 }
5250
5251 if (UserStatus->CheckLife() != 0) {
5252 int stolen = StealItem.checkEvent();
5253
5254 if (stolen != -1) {
5255 BtGetAttach_Init(selectMapNo, stolen);
5256 DngMessMan.hide_timer = 0x78;
5257 SndSePlay(SE_ITEM_GET, -1, 0);
5258 }
5259 }
5260
5261 if (UserStatus->CheckLife() <= 0 && BtActStatus.invincible_frames == 0) {
5262 UserStatus->hp[UserStatus->cur_chara] = 0;
5263 DeadKeyWait = 0x168;
5264 DeadKeyStartWait = 0x3C;
5265 LockOffTargte();
5266 next_task = GAME_TASK_DEAD;
5267 leaving = 1;
5268 }
5269
5270 entry_no = BtCheckDamageProc();
5271
5272 if (entry_no != 0) {
5273 leaving = 1;
5274 }
5275
5276 if (GamePad.Down(PAD_R2) != 0 || GamePad.Down(PAD_L1) != 0 || GamePad.Down(PadInput_NO) != 0 || leaving != 0) {
5277 sceVu0FVECTOR chara_rot;
5278
5279 CharaMainHandViewFlag = 0;
5280 NowCamera__3->FollowOn();
5281 NowCamera__3->SetHeight(oldCameraHeight);
5282 NowCamera__3->SetSpeed(1.0f);
5283 NowCamera__3->Step(1);
5284 NowCamera__3->SetSpeed(8.0f);
5285 CharaMain.GetRotation(chara_rot);
5286 chara_rot[1] = viewAngleH__2;
5287 CharaMain.SetRotation(chara_rot);
5288 BtActStatus.player_visible = 1;
5289 viewMode__2 = 0;
5290 cameraAuto = cameraAutoOld;
5291
5292 if (UserStatus->cur_chara == CHARA_XIAO) {
5293 EquipReAttach(NowWeapon, 0);
5294 }
5295
5296 if (ruby_effect_id != -1 && UserStatus->cur_chara == CHARA_RUBY) {
5297 NowMainEffect->OffEffect(ruby_effect_id);
5298 ruby_effect_id = -1;
5299 }
5300
5301 if (entry_no == 0) {
5302 BtActStatus.unk_028 = 0;
5303 BtActStatus.motion_no = 0;
5304 BtActStatus.action_on = 0;
5305 }
5306
5307 gameTask = next_task;
5308 }
5309 }
5310 }
5311
5312 break;
5313 case GAME_TASK_MENU_OPEN:
5314 oldRogoY3 = rogoY3;
5315 rogoY3 = -0x60;
5316 iventInfo = DNG_EVENT_NONE;
5317 oldMsgNo2 = -1;
5318 oldMsgNo = -1;
5319 battleMenuWait = 0;
5320 MonstorNameOff = 1;
5321 NowCamera__3->SetSpeed(0.0f);
5322 DngMessMan.enabled = false;
5323 DngMessMan.message = -1;
5324 DngMessMan.timer = 0;
5325 DngMessMan.steev_window = false;
5326 DngMessMan.steev_index = 0;
5327 DngMessMan.hide_timer = 0;
5328 ClearSystemMes();
5329 driveStepHold = 1;
5330 gameTask++;
5331 break;
5332 case GAME_TASK_MENU_WAIT_FRAME:
5333 if (battleMenuWait < 3) {
5334 battleMenuWait++;
5335 } else {
5336 frameCaputer = 1;
5337 gameTask += 2;
5338 }
5339
5340 break;
5341 case GAME_TASK_MENU_SKIP:
5342 gameTask++;
5343 break;
5344 case GAME_TASK_MENU_INIT: {
5345 frameCaputer = 0;
5346
5347#ifdef PAL
5348 s32 menu[6] = {0x17, 0x18, 0x19, 0x28, 0x29};
5349#else
5350 s32 menu[5] = {0x17, 0x18, 0x19, 0x28, 0x29};
5351#endif
5352
5353 BattleMenuInit(menu, BATTLE_MENU_MODE_DUNGEON);
5354 BtGameModeFlag = BT_GAME_MODE_BATTLE_MENU;
5355 oldUnitNow = nowUnitNow;
5356 NowCamera__3->SetSpeed(8.0f);
5357 driveStepHold = 0;
5358 rogoY3 = 0x20;
5359 DngMes1.mes_made = -1;
5360 DngMes2.mes_made = -1;
5361 DngMesStb.mes_made = -1;
5362 Mes1MakeFlg = 1;
5363 Mes2MakeFlg = 1;
5364 DngMessMan.enabled = true;
5365 DngMessMan.message = -1;
5366 DngMessMan.timer = 0;
5367 DngMessMan.steev_window = false;
5368 DngMessMan.steev_index = 0;
5369 DngMessMan.hide_timer = 0xA;
5370 MonstorNameOff = 0;
5371 EnemyLifeGage.draw = true;
5372 autoCamTrial();
5373 gameTask++;
5374 break;
5375 }
5376 case GAME_TASK_MENU_CLOSE:
5377 if (MenuMapJumpMode != 0) {
5378 gameTask = GAME_TASK_ESCAPE_INIT;
5379 autoCamTrial();
5380 } else {
5381 if (UserStatus->minimap_status != 3) {
5382 infoMap = 1;
5383 infoMapOld = 1;
5384 } else {
5385 infoMap = 0;
5386 infoMapOld = 0;
5387 }
5388
5389 nowUnitNow = UserStatus->cur_chara;
5390
5391 if (oldUnitNow != nowUnitNow) {
5392 gameTask = GAME_TASK_CHARA_CHANGED;
5393 autoCamTrial();
5394
5395 if (viewMode__2 != 0) {
5396 sceVu0FVECTOR chara_rot;
5397
5398 CharaMainHandViewFlag = 0;
5399 NowCamera__3->FollowOn();
5400 NowCamera__3->SetHeight(oldCameraHeight);
5401 NowCamera__3->SetSpeed(1.0f);
5402 NowCamera__3->Step(1);
5403 NowCamera__3->SetSpeed(8.0f);
5404 CharaMain.GetRotation(chara_rot);
5405 chara_rot[1] = viewAngleH__2;
5406 CharaMain.SetRotation(chara_rot);
5407 BtActStatus.player_visible = 1;
5408 viewMode__2 = 0;
5409 cameraAuto = cameraAutoOld;
5410
5411 if (UserStatus->cur_chara == CHARA_XIAO) {
5412 EquipReAttach(NowWeapon, 0);
5413 }
5414 }
5415 } else {
5416 CWeaponFx.InitSet(NowWeapon->frame, "dcol0", "dcol1");
5417 SetWeaponAttachStatus(NowWeaponHave);
5418 SetWeaponColor();
5419 autoCamTrial();
5420
5421 if (viewMode__2 != 0) {
5422 gameTask = GAME_TASK_EYE_CAMERA;
5423 } else {
5424 gameTask = GAME_TASK_PLAY;
5425 }
5426 }
5427 }
5428
5429 break;
5430 case GAME_TASK_CHARA_CHANGED:
5431 BtActStatus.action_on = 0;
5432 BtActStatus.motion_no = 0;
5433 gameTask = GAME_TASK_PLAY;
5434 NewChangeFx.motion_no = 0;
5435 NewChangeFx.motion_flags = 6;
5436 NewChangeFx.motion_speed = -1.0f;
5437 NewChangeFx.motion_type.state.time = 1.0f;
5438 NewChangeFxFlag = 1;
5439 SndSeSeqAllStop();
5440 printf("se stop !!\n");
5441
5442 if (BtActStatus.swapped_on_death != 0) {
5443 BtActStatus.invincible_frames = 0xA0;
5444 setUnitAmbientAnime(160.0f, 1.0f, 255.0f, 0.0f, 0.0f);
5445 SndSePlay(SE_SPARKLE, -1, 0);
5446 } else {
5447 setUnitAmbientAnime(90.0f, 1.0f, 250.0f, 250.0f, 250.0f);
5448 SndSePlay(SE_SPARKLE, -1, 0);
5449 }
5450
5451 BtActStatus.swapped_on_death = 0;
5452 autoCamTrial();
5453 break;
5454 case GAME_TASK_UNK_123:
5455 break;
5456 case GAME_TASK_CHARA_SELECT_LOOP:
5457 if (BtMiniChrSelect_Loop() != 0) {
5458 if (BtMiniChrSelectNo == 2) {
5459 ClearSystemMes();
5460 driveStepHold = 1;
5461 gameTask = GAME_TASK_EXIT_FADE_START;
5462 ((CDngStatusData *) UserStatus)->SetDead();
5463 } else {
5464 if (oldUnitNow == nowUnitNow) {
5465 DngMes1.mes_made = -1;
5466 DngMes2.mes_made = -1;
5467 DngMesStb.mes_made = -1;
5468 Mes1MakeFlg = 1;
5469 Mes2MakeFlg = 1;
5470 DngMessMan.enabled = true;
5471 MonstorNameOff = 0;
5472 EnemyLifeGage.draw = true;
5473 gameTask = GAME_TASK_PLAY;
5474 } else {
5475 DngMes1.mes_made = -1;
5476 DngMes2.mes_made = -1;
5477 DngMesStb.mes_made = -1;
5478 Mes1MakeFlg = 1;
5479 Mes2MakeFlg = 1;
5480 DngMessMan.enabled = true;
5481 MonstorNameOff = 0;
5482 EnemyLifeGage.draw = true;
5483 gameTask = GAME_TASK_CHARA_CHANGED;
5484 }
5485
5486 goto chr_selected;
5487 }
5488 } else {
5489 chr_selected:
5490 autoCamTrial();
5491 }
5492
5493 break;
5494 case GAME_TASK_BOX_BIG_INIT:
5495 BtGetTreasureboxBig_Init();
5496 gameTask++;
5497 break;
5498 case GAME_TASK_BOX_BIG_LOOP:
5499 if (BtGetTreasureboxBig_Loop() != 0) {
5500 gameTask = GAME_TASK_PLAY;
5501 }
5502
5503 break;
5504 case GAME_TASK_BOX_SMALL_INIT:
5505 BtGetTreasureboxSmall_Init(selectMapNo);
5506 gameTask++;
5507 break;
5508 case GAME_TASK_BOX_SMALL_LOOP:
5509 if (BtGetTreasureboxSmall_Loop() != 0) {
5510 gameTask = GAME_TASK_PLAY;
5511 }
5512
5513 break;
5514 case GAME_TASK_ATRA_GET_INIT:
5515 BtAtraGetShort_Init();
5516 iventMarker = 0;
5517 gameTask++;
5518 break;
5519 case GAME_TASK_ATRA_GET_LOOP:
5520 if (BtAtraGetShort_Loop(selectMapNo, UserStatus->cur_floor) == 1) {
5521 gameTask = GAME_TASK_PLAY;
5522 }
5523
5524 break;
5525 case GAME_TASK_ATRA_REFUSE_INIT: {
5526 CMonUnitHold = 1;
5527 CEffectHold = 1;
5528
5529 CUserStatus *user = UserStatus;
5530
5531 user->step_disable = 1;
5532 DngMessMan.enabled = false;
5533 NotGetAtraMes(UserStatus->cur_chara, -1);
5534 gameTask++;
5535 break;
5536 }
5537 case GAME_TASK_ATRA_REFUSE_WAIT:
5538 if (GamePad.Down(PadInput_OK | PadInput_NO) != 0) {
5539 CMonUnitHold = 0;
5540 CEffectHold = 0;
5541 UserStatus->step_disable = 0;
5542 DngMessMan.enabled = true;
5543 ClearSystemMes();
5544 gameTask = GAME_TASK_PLAY;
5545 }
5546
5547 break;
5548 case GAME_TASK_DEAD: {
5549 int slot;
5550
5551 CUserStatus *step_status = UserStatus;
5552
5553 step_status->step_disable = 1;
5554 BtActStatus.camera_hold = 1;
5555 DngMessMan.enabled = false;
5556
5557 if (ruby_effect_id != -1 && UserStatus->cur_chara == CHARA_RUBY) {
5558 NowMainEffect->OffEffect(ruby_effect_id);
5559 ruby_effect_id = -1;
5560 }
5561
5562 slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_REVIVAL_POWDER);
5563
5564 if (slot != -1) {
5565 s8 chara;
5566
5567 setUnitAmbientAnime(64.0f, 1.0f, 0.0f, 122.0f, 208.0f);
5568 chara = UserStatus->cur_chara;
5569 UserStatus->hp[chara] = UserStatus->max_hp[chara] >> 1;
5570 UserStatus->ailments[UserStatus->cur_chara] = 0;
5571 UserStatus->ailment_frames[UserStatus->cur_chara] = 0;
5572 SetSystemMes(0x3E, -1, MES_POS_BOTTOM, 0, NULL, NULL);
5573 BombInfo.aiming = false;
5574 BombInfo.throw_step = -1;
5575 BtActStatus.can_act = 1;
5576 BtActStatus.action_on = 0;
5577 BtActStatus.action_busy = 0;
5578
5579 if (activeItem.model[8] != -1) {
5580 activeItem.models->AllReleasItem();
5581 activeItem.model[8] = -1;
5582 }
5583
5584 BtActStatus.motion_no = 0;
5585 BtActStatus.camera_hold = 0;
5586 DngMessMan.enabled = false;
5587 CMonUnitHold = 1;
5588 CEffectHold = 1;
5589 printf("itemno = %d\n", slot);
5590 gameTask = GAME_TASK_REVIVE_WAIT;
5591 DelActiveItem(slot + 1);
5592 autoCamTrial();
5593 } else {
5594 BtActStatus.motion_no = 0x17;
5595
5596 float start = CharaMain.motion_type.motion_info[23].start;
5597 float end = CharaMain.motion_type.motion_info[23].end;
5598
5599 if (CharaMain.motion_type.state.time >= 2.0f + start && CharaMain.motion_type.state.time < 2.3f + start) {
5600 SndSePlay(SE_CHARA_KNOCKED_OUT, -1, 0);
5601 }
5602
5603 if (CharaMain.motion_type.state.time >= end - 2.0f && CharaMain.motion_type.state.time <= end) {
5604 CharaMain.motion_no = BtActStatus.motion_no;
5605 CharaMain.motion_flags = 1;
5606 CharaMain.motion_speed = -1.0f;
5607 BombInfo.aiming = false;
5608 BombInfo.throw_step = -1;
5609 BtActStatus.can_act = 1;
5610 BtActStatus.action_on = 0;
5611 BtActStatus.action_busy = 0;
5612
5613 if (activeItem.model[8] != -1) {
5614 activeItem.models->AllReleasItem();
5615 activeItem.model[8] = -1;
5616 }
5617
5618 if (((CDngStatusData *) UserStatus)->GetLiveUnit() != 0 && UserStatus->party_size > 1) {
5619 gameTask += 2;
5620 } else {
5621 gameTask++;
5622 }
5623 }
5624
5625 autoCamTrial();
5626 }
5627
5628 break;
5629 }
5630 case GAME_TASK_DEAD_GAMEOVER:
5631 DeadKeyWait--;
5632
5633 if (DeadKeyStartWait > 0) {
5634 DeadKeyStartWait--;
5635
5636 if (DeadKeyStartWait == 0) {
5637 if (UserStatus->party_size == 1) {
5638 DeadMes(UserStatus->cur_chara, 0x168);
5639 } else {
5640 AllDeadMes(0x168);
5641 }
5642 }
5643 }
5644
5645 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0 || DeadKeyWait <= 0) {
5646 ClearSystemMes();
5647 BtActStatus.camera_hold = 0;
5648
5649#ifdef PAL
5650 // In debug mode the party gets up again at full life.
5651 if (DebugMode != 0) {
5652 CUserStatus *status = UserStatus;
5653
5654 status->hp[status->cur_chara] = status->max_hp[status->cur_chara];
5655 BtActStatus.motion_no = 0;
5656 UserStatus->step_disable = 0;
5657 DngMessMan.enabled = true;
5658 gameTask = GAME_TASK_PLAY;
5659 CMonUnitHold = 0;
5660 CEffectHold = 0;
5661 } else {
5662 gameTask = GAME_TASK_EXIT_FADE_START;
5663 ((CDngStatusData *) UserStatus)->SetDead();
5664 }
5665#else
5666 gameTask = GAME_TASK_EXIT_FADE_START;
5667 ((CDngStatusData *) UserStatus)->SetDead();
5668#endif
5669 }
5670
5671 autoCamTrial();
5672 break;
5673 case GAME_TASK_DEAD_CHANGE_CHARA:
5674 BtActStatus.motion_no = 0x17;
5675
5676 if (DeadKeyStartWait > 0) {
5677 DeadKeyStartWait--;
5678
5679 if (DeadKeyStartWait == 0) {
5680 DeadMes(UserStatus->cur_chara, 0x168);
5681 }
5682 }
5683
5684 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0 || DeadKeyWait <= 0) {
5685 ClearSystemMes();
5686 BtMiniChrSelect_Init(1);
5687 UserStatus->step_disable = 0;
5688 oldUnitNow = UserStatus->cur_chara;
5689 BtActStatus.camera_hold = 0;
5690 BtActStatus.swapped_on_death = 1;
5691 gameTask = GAME_TASK_CHARA_SELECT_LOOP;
5692 }
5693
5694 autoCamTrial();
5695 break;
5696 case GAME_TASK_REVIVE_WAIT: {
5697 s8 chara = UserStatus->cur_chara;
5698
5699 s16 max_hp = UserStatus->max_hp[chara];
5700
5701 if (!(UserStatus->hp[chara] < (max_hp >> 1))) {
5702 CUserStatus *stepper = UserStatus;
5703
5704 stepper->step_disable = 1;
5705 gameTask++;
5706 }
5707
5708 autoCamTrial();
5709 break;
5710 }
5711 case GAME_TASK_REVIVE_DONE:
5712 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0) {
5713 ClearSystemMes();
5714 UserStatus->step_disable = 0;
5715 DngMessMan.enabled = true;
5716 CMonUnitHold = 0;
5717 CEffectHold = 0;
5718 gameTask = GAME_TASK_PLAY;
5719 BtActStatus.invincible_frames = 0xA0;
5720 setUnitAmbientAnime(160.0f, 1.0f, 255.0f, 0.0f, 0.0f);
5721 }
5722
5723 autoCamTrial();
5724 break;
5725 }
5726
5727 if (rogoSwitch2 != 0) {
5728 switch (startCnt2) {
5729 case 0:
5730 if (rogoAlphaA[2] < 0x80) {
5731 rogoAlphaA[2] += 4;
5732 } else {
5733 rogoAlphaW[2] = 0x78;
5734 startCnt2++;
5735 }
5736
5737 if (rogoY3 < 0x20) {
5738 rogoY3 += 2;
5739 }
5740
5741 break;
5742 case 1:
5743 if (rogoAlphaW[2] > 0) {
5744 rogoAlphaW[2]--;
5745 } else {
5746 startCnt2++;
5747 }
5748
5749 if (rogoY3 < 0x20) {
5750 rogoY3 += 2;
5751 }
5752
5753 break;
5754 case 2:
5755 if (rogoAlphaA[2] > 0) {
5756 rogoAlphaA[2] -= 4;
5757 } else if (rogoY3 >= 0x20) {
5758 startCnt2++;
5759 }
5760
5761 if (rogoY3 < 0x20) {
5762 rogoY3 += 2;
5763 }
5764
5765 break;
5766 case 3:
5767 rogoSwitch2 = 0;
5768 startCnt2 = -1;
5769 break;
5770 case -1:
5771 break;
5772 }
5773
5774 if (rogoY3 >= 0x20 && UserStatus->minimap_status != 3) {
5775 infoMap = 1;
5776 infoMapOld = 1;
5777 }
5778 }
5779
5780 motionDrive();
5781}
5782
5783void motionDrive() {
5784 sceVu0FVECTOR pos;
5785 sceVu0FVECTOR rotation;
5786 sceVu0FVECTOR hand;
5787 int chara = UserStatus->cur_chara;
5788 int i;
5789
5790 if (BtAllDrawFlag == 0) {
5791 return;
5792 }
5793
5794 if (BtEventMode == 0) {
5795 NowMonstorUnit->Step(driveStepHold | CMonUnitHold);
5796 }
5797
5798 if (BtActStatus.player_visible != 0 && EdEventInfo.player_draw != 0) {
5799 sceVu0CopyVector(pos, CharaFrame->position);
5800 CharaFrame->GetRotation(rotation);
5801 CharaMain.SetPosition(pos);
5802 CharaMain.SetRotation(rotation[0], rotation[1], rotation[2]);
5803
5804 int blend = 0;
5805
5806 if (driveNoInterpolate != 0) {
5807 blend = 4;
5808 driveNoInterpolate = 0;
5809 }
5810
5811 // A held step, an event or a status ailment restarts the motion
5812 // outright; otherwise it only changes where it differs.
5813 if (driveStepHold != 0 || EdEventInfo.player_stop != 0 || BtActStatus.movement_locked != 0) {
5814 CharaMain.motion_no = BtActStatus.motion_no;
5815 CharaMain.motion_flags = 1;
5816 CharaMain.motion_speed = -1.0f;
5817
5818 if (chara == CHARA_XIAO) {
5819 CCharacter *weapon = NowWeapon;
5820
5821 weapon->motion_no = BtActStatus.motion_no;
5822 weapon->motion_flags = 1;
5823 weapon->motion_speed = -1.0f;
5824 }
5825
5826 BtActStatus.main_motion = -1;
5827 } else if (BtActStatus.main_motion != BtActStatus.motion_no) {
5828 CharaMain.motion_no = BtActStatus.motion_no;
5829 CharaMain.motion_flags = blend;
5830 CharaMain.motion_speed = -1.0f;
5831
5832 if (chara == CHARA_XIAO) {
5833 CCharacter *weapon = NowWeapon;
5834
5835 weapon->motion_no = BtActStatus.motion_no;
5836 weapon->motion_flags = blend;
5837 weapon->motion_speed = -1.0f;
5838 }
5839
5840 BtActStatus.main_motion = BtActStatus.motion_no;
5841 }
5842
5843 // Osmond's tail keeps turning on its own.
5844 if (UserStatus->cur_chara == CHARA_OSMOND) {
5845 CFrame *tail = CharaMain.frame->SearchFrame("tukene1");
5846 CFrame *tail_shadow = CharaMain.shadow_frame->SearchFrame("obj46");
5847
5848 if (tail != NULL) {
5849 static float y = 0.0f;
5850
5851 y += 0.35699910f;
5852
5853 if (!(y < PI_SHORT)) {
5854 y = y - TWO_PI_SHORT;
5855 }
5856
5857 tail->SetRotType(2);
5858 tail->SetRotation(0.0f, AngleLimit(y), 0.0f);
5859
5860 if (tail_shadow != NULL) {
5861 tail_shadow->SetRotType(2);
5862 tail_shadow->SetRotation(0.0f, AngleLimit(y), 0.0f);
5863 }
5864 }
5865 }
5866
5867 if (lockOnTargetFlag != 0 && UserStatus->cur_chara == CHARA_XIAO && CharaMainHandViewFlag == 0) {
5868 CharaMain.motion_type.state.look_frame = (CFrameVu1 *) CharaFrame->SearchFrame("jnt2_1");
5869 sceVu0CopyVector(CharaMain.motion_type.state.look_position, BtActStatus.target_position);
5870 CharaMain.motion_type.state.look_at = true;
5871 CharaMain.motion_type.state.look_constraint = FRAME_CONSTRAINT_X;
5872 } else {
5873 CharaMain.motion_type.state.look_at = false;
5874 }
5875
5876 CharaMain.Step();
5877
5878 if (chara == CHARA_XIAO) {
5879 NowWeapon->Step();
5880 }
5881
5882 if (BtActStatus.shadow_visible != 0) {
5883 CharaMain.ShadowStep();
5884 }
5885 }
5886
5887 if ((CharaMainHandViewFlag != 0 && UserStatus->cur_chara == CHARA_XIAO) || UserStatus->cur_chara == CHARA_RUBY) {
5888 sceVu0CopyVector(hand, CharaFrame->position);
5889
5890 float height = CharaHeight(UserStatus);
5891
5892 hand[1] += height - 3.0f;
5893 CharaHand.SetPosition(hand);
5894
5895 int blend = 0;
5896
5897 if (driveNoInterpolate != 0) {
5898 blend = 4;
5899 driveNoInterpolate = 0;
5900 }
5901
5902 if (driveStepHold != 0 || BtActStatus.movement_locked != 0) {
5903 CharaHand.motion_no = BtActStatus.motion_no;
5904 CharaHand.motion_flags = 1;
5905 CharaHand.motion_speed = -1.0f;
5906
5907 if (chara == CHARA_XIAO) {
5908 CCharacter *weapon = NowWeapon;
5909
5910 weapon->motion_no = BtActStatus.motion_no;
5911 weapon->motion_flags = 1;
5912 weapon->motion_speed = -1.0f;
5913 }
5914
5915 BtActStatus.hand_motion = -1;
5916 } else if (BtActStatus.hand_motion != BtActStatus.motion_no) {
5917 CharaHand.motion_no = BtActStatus.motion_no;
5918 CharaHand.motion_flags = blend;
5919 CharaHand.motion_speed = -1.0f;
5920
5921 if (chara == CHARA_XIAO) {
5922 CCharacter *weapon = NowWeapon;
5923
5924 weapon->motion_no = BtActStatus.motion_no;
5925 weapon->motion_flags = blend;
5926 weapon->motion_speed = -1.0f;
5927 }
5928
5929 BtActStatus.hand_motion = BtActStatus.motion_no;
5930 }
5931
5932 if (chara == CHARA_XIAO) {
5933 NowWeapon->Step();
5934 }
5935
5936 CharaHand.Step();
5937 }
5938
5939 if (BtEventMode != 0) {
5940 for (int i = 0; i < 6; i++) {
5941 if (EdEventInfo.npc_stop[i] == 0) {
5942 NPCUnit[i].ShadowStep();
5943 NPCUnit[i].Step();
5944 }
5945 }
5946 }
5947
5948 if (driveStepHold == 1) {
5949 return;
5950 }
5951
5952 if (BtActStatus.event_block_frames > 0) {
5953 BtActStatus.event_block_frames--;
5954 }
5955
5956 // A weapon that is nearly broken keeps saying so.
5957 if (BtEventMode == 0) {
5958 WEAPON_HAVE *weapon;
5959 CUserStatus *status;
5960 s8 *slots;
5961 s8 *check_slots;
5962 s8 owner;
5963 s8 check_owner;
5964
5965 status = UserStatus;
5966 owner = check_owner = status->cur_chara;
5967 slots = status->equipped_weapon_slot;
5968 check_slots = status->equipped_weapon_slot;
5969 weapon = &status->chara_weapons[owner][(s8) slots[owner]];
5970
5971 if (weapon->durability_f <= 10.0f && status->chara_weapons[check_owner][(s8) check_slots[check_owner]].item_no != defWeapon__6[(s8) owner]) {
5972 static int warning_cnt;
5973 static char init;
5974 int wait;
5975
5976 if (init == 0) {
5977 warning_cnt = 0;
5978 init = 1;
5979 }
5980
5981 wait = (int) weapon->durability_f * 10;
5982
5983 if (wait < 11) {
5984 wait = 10;
5985 }
5986
5987 if (warning_cnt <= 0) {
5988 warning_cnt = wait;
5989 SndSePlay(SE_WARNING, -1, 0);
5990 } else {
5991 warning_cnt--;
5992 }
5993 }
5994 }
5995
5996 if (BtActStatus.player_visible != 0 && EdEventInfo.player_draw != 0) {
5997 CharaMain.ClothStep(0);
5998 }
5999
6000 if (BtActStatus.camera_hold == 0) {
6001 NowCamera__3->Step(1);
6002 }
6003
6004 if (Water_Splash_actFlag != 0) {
6005 Water_Splash.Step();
6006
6007 float end = (float) Water_Splash.motion_type.motion_info[0].end;
6008
6009 if (Water_Splash.motion_type.state.time >= end - 0.5f && Water_Splash.motion_type.state.time < end) {
6010 Water_Splash_actFlag = 0;
6011 }
6012 }
6013
6014 StepWaterLing();
6015 NowDngMap->StepTrapCircle();
6016 Trap_Circle.Step();
6017
6018 if (EscapeFlag != 0) {
6019 EscapeEffect.Step();
6020 }
6021
6022 ItemVolumeStep.LoopStep(60);
6023 NowDngMap->StepNPC();
6024 NowDranMapField->CDranMapField::Step();
6025 DngMesStb.Step();
6026
6027 if (DngMessMan.timer > 0) {
6028 DngMessMan.timer--;
6029
6030 if (DngMessMan.timer == 0) {
6031 DngMessMan.steev_window = false;
6032 DngMessMan.message = -1;
6033 }
6034 }
6035
6036 if (DngMessMan.hide_timer > 0) {
6037 DngMessMan.hide_timer--;
6038 } else {
6039 DngMessMan.hide_timer = 0;
6040 }
6041
6042 // Every hit that is still in the air counts down and drifts.
6043 CCollisionData *collision = NowColData;
6044
6045 for (i = 0; i < 96; i++) {
6046 if (collision->active[i] == 0) {
6047 continue;
6048 }
6049
6050 if (collision->hit[i].phase > 0) {
6051 collision->hit[i].phase--;
6052 } else {
6053 collision->hit[i].phase = collision->hit[i].ready_phase;
6054 }
6055
6056 collision->hit[i].life--;
6057
6058 if (collision->hit[i].life <= 0) {
6059 collision->active[i] = 0;
6060 collision->hit[i].scale_rate = 0.0f;
6061 continue;
6062 }
6063
6064 collision->hit[i].radius += collision->hit[i].unk_40;
6065
6066 if (collision->hit[i].scale_rate != 0.0f) {
6067 sceVu0ScaleVectorXYZ(collision->hit[i].base_point, collision->hit[i].base_point, collision->hit[i].scale_rate);
6068 }
6069 }
6070
6071 if (StatusErrCheck(AILMENT_FREEZE) != 0 || StatusErrCheck(AILMENT_STAMINA) != 0) {
6072 CUserStatus *status = UserStatus;
6073 s8 owner = status->cur_chara;
6074 s16 *left = status->ailment_frames;
6075
6076 if (left[status->cur_chara] > 0) {
6077 left[owner]--;
6078
6079 CUserStatus *now = UserStatus;
6080 s8 who = now->cur_chara;
6081
6082 if (now->ailment_frames[now->cur_chara] == 0) {
6083 now->ailments[who] = 0;
6084 BtActStatus.movement_locked = 0;
6085 }
6086 }
6087 }
6088
6089 if (BtActStatus.special_cooldown > 0) {
6090 BtActStatus.special_cooldown--;
6091 }
6092
6093 // The action gauge fills back up at a rate the weapon sets.
6094 if ((int) BtActStatus.action_gauge < 100) {
6095 if (BtActStatus.refill_frames < 10) {
6096 BtActStatus.refill_frames++;
6097 }
6098
6099 float gain = (float) NowWeaponHave->speed / 30.0f;
6100
6101 if (StatusErrCheck(AILMENT_GOO) != 0) {
6102 gain /= 2.0f;
6103 }
6104
6105 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
6106 gain *= 2.0f;
6107 }
6108
6109 if (gain < 1.0f) {
6110 gain = 1.0f;
6111 }
6112
6113 CUserStatus *status = UserStatus;
6114 s8 *who_ref = &status->cur_chara;
6115
6116 if (status->cur_chara == CHARA_TOAN) {
6117 if (BtActStatus.swinging == 0) {
6118 gain *= 0.25f;
6119 } else {
6120 gain = 0.0f;
6121 }
6122
6123 BtActStatus.swinging = 0;
6124 }
6125
6126 if (*who_ref == CHARA_UNGAGA) {
6127 if (BtActStatus.swinging == 0) {
6128 gain *= 0.25f;
6129 } else {
6130 gain = 0.0f;
6131 }
6132
6133 BtActStatus.swinging = 0;
6134 }
6135
6136 s8 who = *who_ref;
6137 s8 who_copy = *who_ref;
6138
6139 if (*who_ref == CHARA_OSMOND) {
6140 if (BtActStatus.gun_type != 1) {
6141 if (BtActStatus.gauge_exhausted == 0) {
6142 gain = 0.0f;
6143 } else {
6144 gain *= 0.5f;
6145 }
6146 } else {
6147 gain *= 1.5f;
6148 }
6149 }
6150
6151 if (who == CHARA_XIAO) {
6152 gain *= 1.5f;
6153 }
6154
6155 if (who_copy == CHARA_RUBY) {
6156 gain *= 1.5f;
6157 }
6158
6159 BtActStatus.action_gauge += gain;
6160
6161 if (!((int) BtActStatus.action_gauge < 100)) {
6162 BtActStatus.action_gauge = 100.0f;
6163 BtActStatus.gauge_flash = 10;
6164 BtActStatus.gauge_exhausted = 0;
6165 }
6166 } else if (BtActStatus.gauge_flash > 0) {
6167 BtActStatus.gauge_flash--;
6168 }
6169
6170 if (BtActStatus.hud_shake_frames > 0) {
6171 BtActStatus.hud_shake_y = (int) (16.0f * (float) rand() / 2147483648.0f) - 8;
6172 BtActStatus.hud_shake_frames--;
6173 }
6174
6175 BtActStatus.frames_since_attack++;
6176
6177 if (!(BtActStatus.frames_since_attack < 3600)) {
6178 BtActStatus.frames_since_attack = 3600;
6179 }
6180
6181 if (UserStatus->step_disable == 0) {
6182 BtStatusErrStep();
6183 }
6184
6185 CUserStatus *status = UserStatus;
6186 s8 *healed_ref = &status->cur_chara;
6187 float water_max = status->water_max[*healed_ref];
6188 float water_now = status->water_now[*healed_ref];
6189 static int heal_counter = 0;
6190
6191 heal_counter++;
6192
6193 if (!(heal_counter < 240)) {
6194 if ((NowWeaponHave->flags & 0x800) && status->hp[*healed_ref] > 0) {
6195 status->AddNowLife((s8) *healed_ref, 1, 255.0f);
6196 }
6197
6198 heal_counter = 0;
6199 }
6200
6201 UserStatus->Step(0);
6202 float dry = UserStatus->water_now[UserStatus->cur_chara];
6203
6204 DngMessMan.SetStatus_Dry(water_max, water_now, dry);
6205 BtStatusAlarmAnime();
6206
6207 for (int i = 0; i < FrameObjAnimCnt; i++) {
6208 ObjAnimePlay(&FrameObjAnim[i]);
6209 }
6210
6211 CDungeonMap *map = NowDngMap;
6212
6213 map->fire.FireStep();
6214 map->fire.RasterStep();
6215 CWeaponFx.Step();
6216
6217 for (int i = 0; i < 4; i++) {
6218 CWeaponElFx[i].Step();
6219 }
6220
6221 for (int i = 0; i < 32; i++) {
6222 HitValue[i].Step();
6223 }
6224
6225 mainItemModel.Step();
6226 WeaponCrashEffect.Step();
6227
6228 for (int i = 0; i < 16; i++) {
6229 HitMark[i].Step();
6230 HitPointMark[i].Step();
6231 MyHitPointMark[i].Step();
6232 }
6233
6234 if (NewChangeFxFlag != 0) {
6235 NewChangeFx.Step();
6236
6237 float end = (float) NewChangeFx.motion_type.motion_info[0].end;
6238
6239 if (NewChangeFx.motion_type.state.time >= end - 0.3f && NewChangeFx.motion_type.state.time < end) {
6240 NewChangeFxFlag = 0;
6241 }
6242 }
6243
6244 if (atraShortGetType != 0 && atraGetStatus != 0) {
6245 shortAtraEffect.Step();
6246 }
6247
6248 if (itemOpenSmallFlag == 1) {
6249 itemOpenSmall.Step();
6250 itemOpenSmallFx.Step();
6251 }
6252
6253 if (itemOpenBigFlag == 1) {
6254 itemOpenBig.Step();
6255 itemOpenBigFx.Step();
6256 }
6257
6258 if (CEffectHold != 0 || BtEventMode != 0) {
6259 return;
6260 }
6261
6262 if (BtActStatus.camera_shake_frames > 0) {
6263 float shake = BtActStatus.camera_shake;
6264
6265 BtActStatus.camera_shake_offset = 2.0f * (shake * (float) rand()) / 2147483648.0f - shake;
6266 BtActStatus.camera_shake -= BtActStatus.camera_shake_decay;
6267 BtActStatus.camera_shake_frames--;
6268 } else {
6269 BtActStatus.camera_shake_offset = 0.0f;
6270 }
6271
6272 if (BtActStatus.fast_camera_frames > 0) {
6273 BtActStatus.fast_camera_frames--;
6274 }
6275
6276 int picked_up = RandomItem->CheckPosition();
6277 CUserStatus *collector = UserStatus;
6278 int total = collector->money + picked_up;
6279
6280 if (!(total < 0xFFFF)) {
6281 collector->money = 0xFFFF;
6282 } else {
6283 collector->money = total;
6284 }
6285
6286 RandomItem->Step();
6287 StealItem.Step();
6288
6289 for (int i = 0; i < 3; i++) {
6290 CBomb__2[i].Step();
6291 }
6292
6293 for (int i = 0; i < 5; i++) {
6294 MasekiEffect[i].Step();
6295 }
6296
6297 NowShockWave->Step();
6298
6299 CSHOT_EFFECT *effects = NowShotEffect->effect;
6300
6301 for (i = 0; i < 5; i++) {
6302 effects[i].Step();
6303 }
6304
6305 OzumondShot.Step();
6306 OzumondFire.Step();
6307 OzumondShotEffect.Step();
6308 NowMainEffect->Step();
6309 NowShotData->step();
6310 HealEffect.Step();
6311}
6312
6313void BtCleatRandomMap() {
6314 CTexture *gold;
6315 int i;
6316 int item_slot;
6317 int j;
6318 int k;
6319 CDungeonEventMan *man;
6320 CDungeonMap *map;
6321
6322 NowDngMap = &MainDungeonMap;
6323 NowEventMan = &DngEventMan;
6324 ((CDngStatusData *) UserStatus)->LostGateKey();
6325
6326 man = NowEventMan;
6327
6328 for (i = 0; i < 96; i++) {
6329 CDungeonEventData *slot = &man->event[i];
6330
6331 slot->event = NULL;
6332 slot->switch_on = false;
6333 slot->enabled = false;
6334 slot->hold = 0;
6335 slot->chara_done = -1;
6336 }
6337
6338 map = NowDngMap;
6339
6340 for (i = 0; i < 48; i++) {
6341 map->events[i].kind = DNG_EVENT_NONE;
6342 map->events[i].reset_flag = 0;
6343 }
6344
6345 for (i = 0; i < 24; i++) {
6346 map->boxes[i].used = 0;
6347 map->boxes[i].lid_angle = 0.0f;
6348 map->boxes[i].trap_no = 0;
6349 }
6350
6351 map->box_num = 0;
6352
6353 for (i = 0; i < 8; i++) {
6354 map->atra[i].used = 0;
6355 }
6356
6357 map->atra_num = 0;
6358
6359 for (i = 0; i < 4; i++) {
6360 map->room_link[i].used = 0;
6361 }
6362
6363 gold = GoldTex;
6364
6365 for (item_slot = 0; item_slot < 32; item_slot++) {
6366 MainRandomItem.id[item_slot] = -1;
6367 MainRandomItem.pickup_event[item_slot] = -1;
6368 MainRandomItem.pickup_blocked[item_slot] = 0;
6369 }
6370
6371 MainRandomItem.gold_texture = gold;
6372
6373 for (item_slot = 0; item_slot < 32; item_slot++) {
6374 SubRandomItem.id[item_slot] = -1;
6375 SubRandomItem.pickup_event[item_slot] = -1;
6376 SubRandomItem.pickup_blocked[item_slot] = 0;
6377 }
6378
6379 SubRandomItem.gold_texture = GoldTex;
6380 RandomItem = &MainRandomItem;
6381
6382 NowDngMap->buildRandomMap(6, 1);
6383
6384 s32 map_no = NowDngMap->map_type;
6385
6386 NowDngMap->buildEventData(UserStatus->cur_floor, map_no, 1);
6387 NowDngMap->FlushCheckMask();
6388 NowDngMap->DrawMapCalc(NowDngMap->map_type);
6389
6390 s32 event_no = NowDngMap->map_type;
6391
6392 NowEventMan->SetupEvent(NowDngMap, event_no);
6393
6394 NowDngMap = &UraDungeonMap;
6395 NowEventMan = &UraEventMan;
6396 UraDungeonMap = MainDungeonMap;
6397 UraEventMan = DngEventMan;
6398
6399 for (k = 0; k < 96; k++) {
6400 CDungeonEventData *slot = &UraEventMan.event[k];
6401
6402 slot->event = NULL;
6403 slot->switch_on = false;
6404 slot->enabled = false;
6405 slot->hold = 0;
6406 slot->chara_done = -1;
6407 }
6408
6409 for (j = 0; j < 48; j++) {
6410 UraDungeonMap.events[j].kind = DNG_EVENT_NONE;
6411 UraDungeonMap.events[j].reset_flag = 0;
6412 }
6413
6414 for (j = 0; j < 24; j++) {
6415 UraDungeonMap.boxes[j].used = 0;
6416 UraDungeonMap.boxes[j].lid_angle = 0.0f;
6417 UraDungeonMap.boxes[j].trap_no = 0;
6418 }
6419
6420 UraDungeonMap.box_num = 0;
6421
6422 for (j = 0; j < 8; j++) {
6423 UraDungeonMap.atra[j].used = 0;
6424 }
6425
6426 UraDungeonMap.atra_num = 0;
6427
6428 for (j = 0; j < 4; j++) {
6429 UraDungeonMap.room_link[j].used = 0;
6430 }
6431
6432 UraDungeonMap.buildRandomMap(6, 0);
6433
6434 s32 ura_map_no = UraDungeonMap.map_type;
6435
6436 UraDungeonMap.buildEventData(UserStatus->cur_floor, ura_map_no, 0);
6437 UraDungeonMap.FlushCheckMask();
6438 s32 ura_draw_no = UraDungeonMap.map_type;
6439
6440 UraDungeonMap.DrawMapCalc(ura_draw_no);
6441
6442 s32 ura_event_no = UraDungeonMap.map_type;
6443
6444 UraEventMan.SetupEvent(&UraDungeonMap, ura_event_no);
6445
6446 NowDngMap = &MainDungeonMap;
6447 NowEventMan = &DngEventMan;
6448 UserStatus->ClearEventFlag();
6449 BtUraDongeon = 0;
6450 BtEquipMap = 0;
6451 BtEquipMasuisyou = 0;
6452}
6453
6454void BtCleatFreeMap() {
6455 int i;
6456 s32 map_no = MainDungeonMap.map_type;
6457
6458 MainDungeonMap.buildEventData(UserStatus->cur_floor, map_no, 1);
6459 MainDungeonMap.FlushCheckMask();
6460 s32 draw_no = MainDungeonMap.map_type;
6461
6462 MainDungeonMap.DrawMapCalc(draw_no);
6463
6464 s32 event_no = MainDungeonMap.map_type;
6465
6466 DngEventMan.SetupEvent(&MainDungeonMap, event_no);
6467
6468 CTexture *gold = GoldTex;
6469
6470 for (i = 0; i < 32; i++) {
6471 MainRandomItem.id[i] = -1;
6472 MainRandomItem.pickup_event[i] = -1;
6473 MainRandomItem.pickup_blocked[i] = 0;
6474 }
6475
6476 MainRandomItem.gold_texture = gold;
6477 RandomItem = &MainRandomItem;
6478
6479 UserStatus->ClearEventFlag();
6480 BtUraDongeon = 0;
6481 NowDngMap = &MainDungeonMap;
6482 NowEventMan = &DngEventMan;
6483 BtEquipMap = 0;
6484 BtEquipMasuisyou = 0;
6485}
6486
6487void BtArrengeMonstor() {
6488 NowMonstorUnit->CleanViewMonstor(BtUraDongeon);
6489 NowMonstorUnit->ArrangementPos(&MainDungeonMap, 15, -1, 0);
6490}
6491
6492void BtLoadMonstor(int ura) {
6493 int count;
6494 BT_ENEMY_FLOOR *layout;
6495 int monster;
6496 int i;
6497 int slot;
6498
6499 MonstorModelBuffer.used = 0;
6500
6501 s32 ura_dungeon = BtUraDongeon;
6502 CMonstorUnit *unit = NowMonstorUnit;
6503
6504 unit->model_count = 0;
6505 unit->current_monster = 0;
6506
6507 for (slot = 0; slot < 16; slot++) {
6508 unit->script[slot] = &MonstorScriptBuffer[slot];
6509 }
6510
6511 unit->requested_event = -1;
6512 unit->CleanViewMonstor(ura_dungeon);
6513 BtSetEventExtendTable();
6514
6515 for (i = 0; i < 320; i++) {
6516 MonsterTexAnim[i].Initialize();
6517 }
6518
6519 TexManager.DeleteTextureBlock(0x2A);
6520 TexManager.DeleteTextureBlock(0x26);
6521 TexManager.CleanUpBuffer();
6522 TexManager.CleanUpTextureList();
6523
6524 LoadFile("dun/etc/atrcol.mds", read_buffer, NULL);
6525 wait_now_loading_vsync();
6526 NowMonstorUnit->collision = LoadCollisionFile(read_buffer, &MonstorModelBuffer);
6527
6528 CSHOT_EFFECT *effects = NowShotEffect->effect;
6529
6530 for (i = 0; i < 5; i++) {
6531 effects[i].Initialize();
6532 }
6533
6534 count = 0;
6535
6536 if (ura == 0) {
6537 layout = BtEnemyLayoutList[selectMapNo];
6538 } else {
6539 layout = BtUraEnemyLayoutList[selectMapNo];
6540 }
6541
6542 layout += UserStatus->cur_floor;
6543
6544 for (monster = 0; monster < 9; monster++) {
6545 if (layout->monster[monster].monster_no == -1) {
6546 break;
6547 }
6548
6549 count += NowMonstorUnit->SetupBaseModel(count, layout->monster[monster].monster_no, 0x26, &MonstorModelBuffer);
6550 }
6551
6552 MemoryMapDump();
6553}
6554
6555void EquipReAttach(CCharacter *equipment, int held_out) {
6556 CFrame *hand;
6557
6558 if (held_out != 0) {
6559 hand = CharaHand.frame->SearchFrame("pati1");
6560 } else {
6561 hand = CharaMain.frame->SearchFrame("weapon");
6562 }
6563
6564 equipment->SetPosition(0.0f, 0.0f, 0.0f);
6565 equipment->SetRotation(0.0f, 0.0f, 0.0f);
6566 equipment->frame->SetReference(hand);
6567}
6568
6569void EquipWeaponFrame(CCharacter *weapon, int chara, int held_out) {
6570 CFrame *hand;
6571 int i;
6572
6573 NowWeapon = weapon;
6574
6575 if (held_out != 0 && chara == CHARA_XIAO) {
6576 hand = CharaHand.frame->SearchFrame("pati1");
6577 } else {
6578 hand = CharaMain.frame->SearchFrame("weapon");
6579 }
6580
6581 if (hand == NULL) {
6582 printf("no weapon frame !!\n");
6583 return;
6584 }
6585
6586 float zero = 0.0f;
6587
6588 NowWeapon->SetPosition(zero, zero, zero);
6589 NowWeapon->SetRotation(zero, zero, zero);
6590 NowWeapon->frame->SetReference(hand);
6591 NowWeapon->Step();
6592
6593 for (i = 0; i < 32; i++) {
6594 CWeaponFx.used[i] = 0;
6595 }
6596
6597 CWeaponFx.colour[0].r = CWeaponFx.colour[2].r = 0x40;
6598 CWeaponFx.colour[0].g = CWeaponFx.colour[2].g = 0x40;
6599 CWeaponFx.colour[0].b = CWeaponFx.colour[2].b = 0x40;
6600 CWeaponFx.colour[1].r = CWeaponFx.colour[3].r = 6;
6601 CWeaponFx.colour[1].g = CWeaponFx.colour[3].g = 6;
6602 CWeaponFx.colour[1].b = CWeaponFx.colour[3].b = 6;
6603 CWeaponFx.cursor = 0;
6604 CWeaponFx.timer = 0;
6605 CWeaponFx.InitSet(NowWeapon->frame, "dcol0", "dcol1");
6606 SetWeaponColor();
6607}
6608
6609void LoadWeapon2(unsigned int *crash_data, unsigned int *default_data, unsigned int *main_data, int chara, int reload) {
6610 int weapon_kind[6] = {1, 4, 6, 5, 10, 7};
6611 int weapon_first[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};
6612 char weapon_name[64];
6613 char weapon_model_path[64];
6614 // The kind each character's weapon counts as; nothing reads it any more.
6615 int *kind = &weapon_kind[chara];
6616
6617 // A reload gives the weapon blocks back before the new models go in.
6618 if (reload != 0) {
6619 TexManager.DeleteTextureBlock(0x1D);
6620 TexManager.DeleteTextureBlock(0x10);
6621 TexManager.CleanUpBuffer();
6622 TexManager.CleanUpTextureList();
6623 WeaponModelBuffer.used = 0;
6624 WEffectModelBuffer.used = 0;
6625 }
6626
6627 BtGetWeaponNamePath2(weapon_name, weapon_model_path, chara, 0);
6628 CrashWeapon.Initialize();
6629 CrashWeapon.LoadPackData3(crash_data, weapon_model_path, &WeaponModelBuffer, 0x1D, &WeaponModelBuffer, 1, 0);
6630
6631 BtGetWeaponNamePath2(weapon_name, weapon_model_path, chara, 1);
6632 DefaultWeapon.Initialize();
6633 DefaultWeapon.LoadPackData3(default_data, weapon_model_path, &WeaponModelBuffer, 0x1D, &WeaponModelBuffer, 1, 0);
6634
6635 CUserStatus *status = UserStatus;
6636 s8 owner = status->cur_chara;
6637
6638 // The weapon's item number, counted from its character's first weapon.
6639 int model_no = status->chara_weapons[owner][status->equipped_weapon_slot[owner]].item_no;
6640
6641 model_no -= weapon_first[chara];
6642 BtGetWeaponNamePath2(weapon_name, weapon_model_path, chara, model_no);
6643 MainWeapon.Initialize();
6644 MainWeapon.LoadPackData3(main_data, weapon_model_path, &WeaponModelBuffer, 0x1D, &WeaponModelBuffer, 1, 0);
6645 EquipWeaponFrame(&MainWeapon, chara, CharaMainHandViewFlag);
6646
6647 // The effect models take whatever the weapon models leave.
6648 u8 *free_start;
6649 u8 *weapon_end;
6650 int used = WeaponModelBuffer.used;
6651
6652 weapon_end = WeaponModelBuffer.base + used * 16;
6653 free_start = weapon_end;
6654 s64 free_size = 0x33450 - CharaModelBuffer.used - used;
6655
6656 WEffectModelBuffer.base = free_start;
6657 WEffectModelBuffer.limit = free_size;
6658 WEffectModelBuffer.used = 0;
6659
6660 CUserStatus *equipped = UserStatus;
6661 s8 chara_no = equipped->cur_chara;
6662
6663 WEAPON_HAVE *have = &equipped->chara_weapons[chara_no][equipped->equipped_weapon_slot[chara_no]];
6664
6665 MenuWeaponSpSet(NowWeapon, have);
6666 BtActStatus.action_gauge = 100.0f;
6667 BtActStatus.gauge_exhausted = 0;
6668}
6669
6670void SwordDmgCheck1(float amount, int kind) {
6671 int broke;
6672 CUserStatus *status = UserStatus;
6673 s8 chara = status->cur_chara;
6674 WEAPON_HAVE *weapon = &status->chara_weapons[chara][status->equipped_weapon_slot[chara]];
6675 float was = weapon->durability_f;
6676 float warn = (float) (weapon->durability * 0.2);
6677
6678 broke = BattleSubWeaponDmg(amount, kind);
6679
6680 // The Chronicle sword says so once, as its durability crosses a fifth.
6681 if (weapon->item_no == ITEM_WEAPON_LAMB_S_SWORD && weapon->durability_f <= warn && was >= warn) {
6682 SetWeaponAttachStatus(NowWeaponHave);
6683 DngMessMan.message = 0xB8;
6684 DngMessMan.timer = 0xF0;
6685 DngMessMan.steev_window = false;
6686 SndSePlay(SE_POWER_UP, -1, 0);
6687 MenuWeaponSpSet(NowWeapon, weapon);
6688 }
6689
6690 if (broke == 0) {
6691 return;
6692 }
6693
6694 float spread[4] = {0.0f, 1.0f, 0.0f, 1.0f};
6695 float offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
6696 sceVu0FVECTOR world;
6697 sceVu0FVECTOR pos;
6698
6699 sceVu0CopyVector(pos, CharaMain.pos);
6700
6701 CFrame *hand = CharaMain.frame->SearchFrame("weapon");
6702
6703 if (hand != NULL) {
6704 hand->GetWorldPosition(world, offset);
6705 WeaponCrashEffect.Set(world, spread, 4, 1.5f, 0.01f, 0.01f, 0.3f, 0x20, pos[1]);
6706 }
6707
6708 if (broke == 1) {
6709 EquipWeaponFrame(&CrashWeapon, UserStatus->cur_chara, CharaMainHandViewFlag);
6710 s8 owner = UserStatus->cur_chara;
6711
6712 if (owner == 5 || (s8) owner == 3) {
6713 NowMainEffect = &CharaMainEffectCrash;
6714 BtActStatus.gun_type = 0;
6715 BtActStatus.action_on = 0;
6716 }
6717 }
6718
6719 if (broke == 2) {
6720 EquipWeaponFrame(&DefaultWeapon, UserStatus->cur_chara, CharaMainHandViewFlag);
6721 s8 owner = UserStatus->cur_chara;
6722
6723 if (owner == 5 || (s8) owner == 3) {
6724 NowMainEffect = &CharaMainEffectCrash;
6725 BtActStatus.gun_type = 0;
6726 BtActStatus.action_on = 0;
6727 }
6728 }
6729}
6730
6731// clang-format off
6732/* The colour each weapon element gives the trail the weapon leaves. */
6733u8 wep_rgb[5][3] = {
6734 {0xFF, 0x3C, 0x00}, {0x64, 0xC8, 0xFF}, {0xFF, 0xFF, 0x64}, {0x8A, 0xFF, 0xBC}, {0xE3, 0x96, 0xAD},
6735};
6736// clang-format on
6737
6738void SetWeaponColor() {
6739 u8 red, green, blue;
6740 s8 element = NowWeaponHave->best_elem;
6741
6742 if (element == WEAPON_ELEMENT_NONE) {
6743 CWeaponFx.colour[0].r = CWeaponFx.colour[2].r = 0x40;
6744 CWeaponFx.colour[0].g = CWeaponFx.colour[2].g = 0x40;
6745 CWeaponFx.colour[0].b = CWeaponFx.colour[2].b = 0x40;
6746 CWeaponFx.colour[1].r = CWeaponFx.colour[3].r = 6;
6747 CWeaponFx.colour[1].g = CWeaponFx.colour[3].g = 6;
6748 CWeaponFx.colour[1].b = CWeaponFx.colour[3].b = 6;
6749 } else if (element >= 0 && element < 6) {
6750 blue = wep_rgb[element][2] >> 2;
6751 green = wep_rgb[element][1] >> 2;
6752 red = wep_rgb[element][0] >> 2;
6753
6754 CWeaponFx.colour[0].r = CWeaponFx.colour[2].r = red;
6755 CWeaponFx.colour[0].g = CWeaponFx.colour[2].g = green;
6756 CWeaponFx.colour[0].b = CWeaponFx.colour[2].b = blue;
6757 CWeaponFx.colour[1].r = CWeaponFx.colour[3].r = red / 10.0f;
6758 CWeaponFx.colour[1].g = CWeaponFx.colour[3].g = green / 10.0f;
6759 CWeaponFx.colour[1].b = CWeaponFx.colour[3].b = blue / 10.0f;
6760 }
6761}
6762
6763BT_SHOT_EFFECT *Get_Main_EffectPtr(int chara, int form) {
6764 switch (chara) {
6765 case CHARA_TOAN:
6766 return MyEffectEntry_Tbl[0];
6767 case CHARA_XIAO:
6768 return MyEffectEntry_Tbl[1];
6769 case CHARA_GORO:
6770 return MyEffectEntry_Tbl[2];
6771 case CHARA_RUBY:
6772 // Ruby draws a different set for each of her forms.
6773 if (form < 0 || form > 4) {
6774 form = 0;
6775 }
6776
6777 return MyEffectEntry_Tbl[3 + form];
6778 case CHARA_UNGAGA:
6779 return MyEffectEntry_Tbl[8];
6780 case CHARA_OSMOND: {
6781 // Osmond draws from the weapon he has equipped rather than a form.
6782 s32 weapon = UserStatus->chara_weapons[chara][UserStatus->equipped_weapon_slot[chara]].item_no;
6783 int entry = 0;
6784
6785 BtActStatus.gun_type = 0;
6786
6787 if (weapon == ITEM_WEAPON_JACKAL) {
6788 entry = 3;
6789 BtActStatus.gun_type = 0;
6790 }
6791
6792 if (weapon == ITEM_WEAPON_BLESSING_GUN) {
6793 entry = 0;
6794 BtActStatus.gun_type = 2;
6795 }
6796
6797 if (weapon == ITEM_WEAPON_SKUNK) {
6798 entry = 0;
6799 BtActStatus.gun_type = 2;
6800 }
6801
6802 if (weapon == ITEM_WEAPON_G_CRUSHER) {
6803 entry = 4;
6804 BtActStatus.gun_type = 0;
6805 }
6806
6807 if (weapon == ITEM_WEAPON_HEXA_BLASTER) {
6808 entry = 1;
6809 BtActStatus.gun_type = 1;
6810 }
6811
6812 if (weapon == ITEM_WEAPON_STAR_BREAKER) {
6813 entry = 5;
6814 BtActStatus.gun_type = 0;
6815 }
6816
6817 if (weapon == ITEM_WEAPON_SUPERNOVA) {
6818 entry = 2;
6819 BtActStatus.gun_type = 1;
6820 }
6821
6822 if (weapon == ITEM_WEAPON_SNAIL) {
6823 entry = 2;
6824 BtActStatus.gun_type = 1;
6825 }
6826
6827 return MyEffectEntry_Tbl[9 + entry];
6828 }
6829 }
6830
6831 return NULL;
6832}
6833
6834void MainChara_Effect(BT_SHOT_EFFECT *effect, unsigned int *data, int reload) {
6835 CharaMainEffect.Initialize();
6836 CharaMainEffectCrash.Initialize();
6837
6838 if (effect == NULL) {
6839 return;
6840 }
6841
6842 // A reload gives the effect block back before the new models go in.
6843 if (reload != 0) {
6844 TexManager.DeleteTextureBlock(0x10);
6845 TexManager.CleanUpBuffer();
6846 TexManager.CleanUpTextureList();
6847 WEffectModelBuffer.used = 0;
6848 }
6849
6850 if (CharaMainEffect.Entry2(effect, data, 0x10, &WEffectModelBuffer, 6) == 0) {
6851 printf("effect entry err!!\n");
6852 } else {
6853 printf("set eff sucsess !\n");
6854 }
6855
6856 if (UserStatus->cur_chara == CHARA_OSMOND) {
6857 unsigned int *crash = ozumond_default_effect;
6858
6859 CharaMainEffectCrash.Entry2(MyEffectEntry_Tbl[9], crash, 0x10, &WEffectModelBuffer, 6);
6860 }
6861
6862 if (UserStatus->cur_chara == CHARA_RUBY) {
6863 unsigned int *crash = ozumond_default_effect;
6864
6865 CharaMainEffectCrash.Entry2(MyEffectEntry_Tbl[3], crash, 0x10, &WEffectModelBuffer, 6);
6866 }
6867
6868 NowMainEffect = &CharaMainEffect;
6869}
6870
6871void LoadChara2(int chara, int keep_place, unsigned int *chara_data, unsigned int *crash_data, unsigned int *default_data, unsigned int *main_data) {
6872 CFrameAttr frame_attr;
6873 sceVu0FVECTOR pos;
6874 sceVu0FVECTOR rotation;
6875 int i;
6876
6877 frame_attr.fog_enable = true;
6878 frame_attr.clip_enable = false;
6879 frame_attr.program_option = 0;
6880
6881 // The model goes back where the one it replaces stood.
6882 if (keep_place == 0) {
6883 sceVu0CopyVector(pos, CharaFrame->position);
6884 CharaFrame->GetRotation(rotation);
6885 }
6886
6887 TexManager.DeleteTextureBlock(0x11);
6888 TexManager.DeleteTextureBlock(0x1D);
6889 TexManager.DeleteTextureBlock(0x10);
6890 TexManager.CleanUpBuffer();
6891 TexManager.CleanUpTextureList();
6892 CharaModelBuffer.used = 0;
6893
6894 CharaMain.Initialize();
6895
6896 for (i = 0; i < 64; i++) {
6897 CharaMainTexAnim[i].Initialize();
6898 }
6899
6900 CharaMain.InitializeTexAnime(CharaMainTexAnim, 64);
6901 CharaMain.LoadPackData2(chara_data, "base.cfg", &CharaModelBuffer, 0x11, &CharaModelBuffer, 0);
6902 NowWeapon = NULL;
6903 CharaHand.Initialize();
6904
6905 if (chara == CHARA_XIAO) {
6906 CFrameAttr hand_attr;
6907
6908 hand_attr.clip_enable = true;
6909 hand_attr.unk_09 = 0;
6910 CharaHand.LoadPackData(chara_data, "hand_up.cfg", &CharaModelBuffer, &CharaModelBuffer, NULL);
6911 CharaHand.frame->SetAttr(hand_attr, 1, 0);
6912 }
6913
6914 if (chara == CHARA_RUBY) {
6915 CFrameAttr hand_attr;
6916
6917 hand_attr.clip_enable = true;
6918 hand_attr.unk_09 = 0;
6919 CharaHand.LoadPackData(chara_data, "hand_up.cfg", &CharaModelBuffer, &CharaModelBuffer, NULL);
6920 CharaHand.frame->SetAttr(hand_attr, 1, 0);
6921 }
6922
6923 CharaMain.frame->SetAttr(frame_attr, 1, 4);
6924
6925 if (keep_place == 0) {
6926 CharaMain.frame->SetPosition(pos);
6927 CharaMain.frame->SetRotation(rotation[0], rotation[1], rotation[2]);
6928 CharaMain.SetPosition(pos);
6929 CharaMain.SetRotation(rotation[0], rotation[1], rotation[2]);
6930 }
6931
6932 CharaFrame = (CFrameVu1 *) CharaMain.frame;
6933
6934 if (chara == CHARA_OSMOND) {
6935 LOADTEXTURE_INFO2 info[2] = {
6936 {NULL, 0x46, 0},
6937 {NULL, 0x46, 0}
6938 };
6939 int size;
6940
6941 u_int *hand_texture = GetPackFile(chara_data, "c05w_h.img", &size);
6942 u8 *at = CharaModelBuffer.base + CharaModelBuffer.used * 16;
6943
6944 memcpy(at, hand_texture, size);
6945 size = (((size >> 6) + 1) << 6) >> 4;
6946 CharaModelBuffer.Alloc(size);
6947 info[0].name = (char *) at;
6948 TexManager.DeleteTextureBlock(0x46);
6949 TexManager.LoadTextureBlockEX(0x46, info);
6950
6951 u_int *effect = GetPackFile(chara_data, "mgan01.chr", &size);
6952
6953 ozumond_default_effect = (unsigned int *) (CharaModelBuffer.base + CharaModelBuffer.used * 16);
6954 memcpy(ozumond_default_effect, effect, size);
6955 size = (((size >> 6) + 1) << 6) >> 4;
6956 CharaModelBuffer.Alloc(size);
6957 }
6958
6959 if (chara == CHARA_RUBY) {
6960 int size;
6961 u_int *effect = GetPackFile(chara_data, "c05_f03.chr", &size);
6962
6963 ozumond_default_effect = (unsigned int *) (CharaModelBuffer.base + CharaModelBuffer.used * 16);
6964 memcpy(ozumond_default_effect, effect, size);
6965 size = (((size >> 6) + 1) << 6) >> 4;
6966 CharaModelBuffer.Alloc(size);
6967 }
6968
6969 // The weapon models take whatever the character models leave.
6970 s32 used = CharaModelBuffer.used;
6971 u8 *free_start = CharaModelBuffer.base + used * 16;
6972 s64 free_size = 0x33450 - used;
6973
6974 WeaponModelBuffer.base = free_start;
6975 WeaponModelBuffer.limit = free_size;
6976 WeaponModelBuffer.used = 0;
6977 LoadWeapon2(crash_data, default_data, main_data, chara, 0);
6978 MemoryMapDump();
6979}
6980
6981static void LoadData() {
6982 CFrameAttr frame_attr;
6983 char weapon_model_path[64];
6984 char weapon_name[64];
6985 char weapon_effect_name[64];
6986 char steal_model_name[64];
6987 int character_size;
6988 int weapon_0_size;
6989 int weapon_1_size;
6990 int equipped_weapon_size;
6991
6992 // Configure the model attributes used by the loaded dungeon objects.
6993 frame_attr.fog_enable = true;
6994 frame_attr.clip_depth = 100.0f;
6995 frame_attr.clip_enable = false;
6996 frame_attr.program_option = 0;
6997
6998 UserStatus->cur_chara = 0;
6999 BtGetWeaponNamePath3(weapon_name, weapon_effect_name, UserStatus->chara_weapons[0][UserStatus->equipped_weapon_slot[0]].item_no);
7000 printf("[%d] %s\n", UserStatus->chara_weapons[0][UserStatus->equipped_weapon_slot[0]].item_no, weapon_name);
7001
7002 strcpy(weapon_model_path, "commenu/weapon/");
7003 strcat(weapon_model_path, weapon_name);
7004
7005 // Load the character and weapon data into consecutive 64-byte regions.
7006 LoadFile("dun/mainchara/c01d.chr", read_buffer, &character_size);
7007 unsigned int aligned_size = ((character_size >> 6) + 1) << 6;
7008 unsigned int *weapon_data_0 = read_buffer + (aligned_size >> 2);
7009
7010 LoadFile("commenu/weapon/c01w00.chr", weapon_data_0, &weapon_0_size);
7011 aligned_size = ((weapon_0_size >> 6) + 1) << 6;
7012 unsigned int *weapon_data_1 = weapon_data_0 + (aligned_size >> 2);
7013
7014 LoadFile("commenu/weapon/c01w01.chr", weapon_data_1, &weapon_1_size);
7015 aligned_size = ((weapon_1_size >> 6) + 1) << 6;
7016 unsigned int *equipped_weapon_data = weapon_data_1 + (aligned_size >> 2);
7017
7018 LoadFile(weapon_model_path, equipped_weapon_data, &equipped_weapon_size);
7019 wait_now_loading_vsync();
7020 LoadChara2(UserStatus->cur_chara, 1, read_buffer, weapon_data_0, weapon_data_1, equipped_weapon_data);
7021 float chara_z = 150.0f;
7022
7023 CharaFrame->SetPosition(200.0f, 0.0f, chara_z);
7024
7025 BT_SHOT_EFFECT *main_effect = Get_Main_EffectPtr(UserStatus->cur_chara, 0);
7026 LoadFile("dun/mainchara/wep_eff/c01_fuusya.chr", read_buffer, NULL);
7027 wait_now_loading_vsync();
7028 MainChara_Effect(main_effect, read_buffer, 0);
7029
7030 if (SndVoiceLoad(0) != 0) {
7031 printf("voice err \n");
7032 } else {
7033 printf("snd load\n");
7034 }
7035
7036 // Load the shared dungeon pack and its models.
7037 unsigned int *main_pack = read_buffer;
7038
7039 LoadFile("dun/pack/maindat.pac", main_pack, NULL);
7040 wait_now_loading_vsync();
7041 cursorFrame = LoadMDSFilePack(read_buffer, "dun/etc/cursor.mds", &MainModelBuffer);
7042 bombCursorFrame = LoadMDSFilePack(read_buffer, "dun/etc/bomblock.mds", &MainModelBuffer);
7043 bicCursorFrame = LoadMDSFilePack(read_buffer, "dun/etc/bic.mds", &MainModelBuffer);
7044 bicCursorFrame->SetScale(0.7f, 0.7f, 0.7f);
7045
7046 NowDngMap->atra_model = LoadMDSFilePack(read_buffer, "dun/etc/atr.mds", &MainModelBuffer);
7047 NowDngMap->collision_model = LoadCollisionFilePack(read_buffer, "dun/etc/atrcol.mds", &MainModelBuffer);
7048 NowDngMap->atra_model->SetAttr(frame_attr, 1, 0);
7049
7050 NewChangeFx.LoadPackData2((unsigned int *) GetPackFile(read_buffer, "ceffe_s.chr", NULL), "info.cfg", &MainModelBuffer, 11, &MainModelBuffer, 0);
7051 itemOpenSmallFx.LoadPack(read_buffer, "igetfx", &MainModelBuffer, &MotionData, &itemOpenSmallFx_info, 0);
7052 itemOpenBigFx.LoadPack(read_buffer, "igetfxb", &MainModelBuffer, &MotionData, &itemOpenBigFx_info, 0);
7053
7054 Water_Splash.LoadPackData2((unsigned int *) GetPackFile(read_buffer, "water_sp.chr", NULL), "info.cfg", &MainModelBuffer, 6, &MainModelBuffer, 0);
7055
7056 unsigned int *effect_data = (unsigned int *) GetPackFile(read_buffer, "trap01.chr", NULL);
7057 Trap_Circle.InitializeTexAnime(Trap_Circle_TexAnim, 16);
7058 Trap_Circle.LoadPackData2(effect_data, "info.cfg", &MainModelBuffer, 71, &MainModelBuffer, 0);
7059 Trap_Circle.frame->SetAttr(frame_attr, 1, 0x40);
7060
7061 sprintf(steal_model_name, "kara0%d.mds", selectMapNo + 1);
7062 unsigned int *steal_model_data = (unsigned int *) GetPackFile(read_buffer, steal_model_name, NULL);
7063 StealModel = (CFrameVu1 *) LoadMDSFile(steal_model_data, &MainModelBuffer, 0, NULL, NULL);
7064
7065 MasekiModelBuffer.used = 0;
7066 LoadFile("dun/effect/maseki_ex.chr", read_buffer, NULL);
7067 wait_now_loading_vsync();
7068 MasekiEffect[0].Entry2(&MyEntryEffect_Maseki00, read_buffer, 6, &MasekiModelBuffer, 3);
7069
7070 memcpy(&MasekiEffect[1], &MasekiEffect[0], sizeof(CSHOT_EFFECT));
7071 MasekiEffect[1].ReEntry(&MyEntryEffect_Maseki01, &MasekiModelBuffer);
7072 memcpy(&MasekiEffect[2], &MasekiEffect[0], sizeof(CSHOT_EFFECT));
7073 MasekiEffect[2].ReEntry(&MyEntryEffect_Maseki02, &MasekiModelBuffer);
7074 memcpy(&MasekiEffect[3], &MasekiEffect[0], sizeof(CSHOT_EFFECT));
7075 MasekiEffect[3].ReEntry(&MyEntryEffect_Maseki03, &MasekiModelBuffer);
7076 memcpy(&MasekiEffect[4], &MasekiEffect[0], sizeof(CSHOT_EFFECT));
7077 MasekiEffect[4].ReEntry(&MyEntryEffect_Maseki04, &MasekiModelBuffer);
7078}
7079
7080int BtCheckDamageProc() {
7081 sceVu0FVECTOR pos;
7082 sceVu0FVECTOR from;
7083 sceVu0FVECTOR blow;
7084 int taken = 0;
7085 int blown = 0;
7086
7087 static int dmgSnd = 0;
7088
7089 if (dmgSnd > 0) {
7090 dmgSnd--;
7091 }
7092
7093 // The debug menu can hold the player at full health.
7094 if (DebugStatus[20] == 2) {
7095 CUserStatus *status = UserStatus;
7096
7097 status->hp[status->cur_chara] = status->max_hp[status->cur_chara];
7098 return 0;
7099 }
7100
7101 if (BtActStatus.recoil_frames == 0 && BtActStatus.invincible_frames == 0) {
7102 sceVu0CopyVector(pos, CharaMain.pos);
7103
7104 int hit_no = NowColData->CheckHitUser(pos, 1, CharaHeight(UserStatus));
7105
7106 if (hit_no != -1) {
7107 taken = 1;
7108
7109 if (BtActStatus.action_on == 6) {
7110 blown = taken;
7111 }
7112
7113 BombInfo.aiming = false;
7114 BombInfo.throw_step = -1;
7115 BtActStatus.can_act = 1;
7116 BtActStatus.action_on = 0;
7117 BtActStatus.action_busy = 0;
7118
7119 if (activeItem.model[8] != -1) {
7120 activeItem.models->AllReleasItem();
7121 activeItem.model[8] = -1;
7122 }
7123
7124 BtActStatus.move_power = 0.0f;
7125 BtActStatus.gauge_exhausted = 0;
7126 BtActStatus.action_gauge = 100.0f;
7127 CMonUnitHold = 0;
7128 CEffectHold = 0;
7129
7130 if (ruby_effect_id != -1 && UserStatus->cur_chara == CHARA_RUBY) {
7131 NowMainEffect->OffEffect(ruby_effect_id);
7132 ruby_effect_id = -1;
7133 }
7134
7135 int damage = NowColData->Get(hit_no)->damage;
7136 int guard = UserStatus->defense[UserStatus->cur_chara];
7137 int monster;
7138 int roll;
7139 COLLISION_HIT *hit = &NowColData->hit[hit_no];
7140
7141 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
7142 guard *= 2;
7143 }
7144
7145 damage -= guard;
7146
7147 if (damage <= 0) {
7148 damage = 0;
7149 }
7150
7151 int owner = NowColData->hit[hit_no].owner;
7152
7153 monster = -1;
7154
7155 if (owner != -1) {
7156 monster = (owner - 200) / 5;
7157 CMonstorUnit *unit = NowMonstorUnit;
7158
7159 if (monster >= 0 && monster < 16) {
7160 unit->monster[monster].last_hit_damage = damage;
7161 }
7162
7163 NowMonstorUnit->chara[monster][0].GetPosition(from);
7164 }
7165
7166 roll = (int) (100.0f * (float) rand() / 2147483648.0f);
7167
7168 // A hit that drains takes a fifth of the player's money and gives it to
7169 // whatever landed it.
7170 if ((hit->flags & 0x40000) && roll < 20 && monster != -1) {
7171 u16 *wallet = &UserStatus->money;
7172 u16 had = UserStatus->money;
7173
7174 if (had > 10) {
7175 int drained = had / 5;
7176
7177 *wallet -= drained;
7178 SndSePlay(SE_ITEM_GET, -1, 0);
7179 NowMonstorUnit->monster[monster].stolen_money += drained;
7180 DngMessMan.message = 0xB5;
7181 DngMessMan.timer = 0xB4;
7182 DngMessMan.steev_window = false;
7183 }
7184 }
7185
7186 if ((hit->flags & 0x1000) && roll < 0x41) {
7187 BtSetStatusErr(AILMENT_STAMINA);
7188 }
7189
7190 if (hit->flags & 0x100000) {
7191 BtSetStatusErr(AILMENT_FREEZE);
7192 }
7193
7194 if ((hit->flags & 0x100) && roll < 0x41) {
7195 int slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_ANTI_FREEZE_AMULET);
7196
7197 if (slot == -1) {
7198 BtSetStatusErr(AILMENT_FREEZE);
7199 } else {
7200 // &who->active_item_vol[slot], spelled so the index is added first.
7201 CUserStatus *who = UserStatus;
7202 unsigned int address = slot * sizeof(s32);
7203
7204 address += (unsigned int) who;
7205 s32 *vol = &((CUserStatus *) address)->active_item_vol[0];
7206
7207 if (--(*vol) <= 0) {
7208 DelActiveItem(slot + 1);
7209 DngMessMan.message = 0xB7;
7210 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(ITEM_ANTI_FREEZE_AMULET);
7211 DngMessMan.timer = 0xB4;
7212 DngMessMan.steev_window = false;
7213 }
7214 }
7215 }
7216
7217 if ((hit->flags & 0x200) && roll < 0x41 && (UserStatus->ailments[UserStatus->cur_chara] & AILMENT_POISON) == 0) {
7218 int slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_ANTIDOTE_AMULET);
7219
7220 if (slot == -1) {
7221 BtSetStatusErr(AILMENT_POISON);
7222 DngMessMan.message = 0xBB;
7223 DngMessMan.timer = 0xB4;
7224 DngMessMan.steev_window = false;
7225 } else {
7226 CUserStatus *who = UserStatus;
7227 unsigned int address = slot * sizeof(s32);
7228
7229 address += (unsigned int) who;
7230 s32 *vol = &((CUserStatus *) address)->active_item_vol[0];
7231
7232 if (--(*vol) <= 0) {
7233 DelActiveItem(slot + 1);
7234 DngMessMan.message = 0xB7;
7235 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(ITEM_ANTIDOTE_AMULET);
7236 DngMessMan.timer = 0xB4;
7237 DngMessMan.steev_window = false;
7238 }
7239 }
7240 }
7241
7242 if ((hit->flags & 0x400) && roll < 0x41 && (UserStatus->ailments[UserStatus->cur_chara] & AILMENT_CURSE) == 0) {
7243 int slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_ANTICURSEAMULET);
7244
7245 if (slot == -1) {
7246 BtSetStatusErr(AILMENT_CURSE);
7247 DngMessMan.message = 0xB9;
7248 DngMessMan.timer = 0xB4;
7249 DngMessMan.steev_window = false;
7250 } else {
7251 CUserStatus *who = UserStatus;
7252 unsigned int address = slot * sizeof(s32);
7253
7254 address += (unsigned int) who;
7255 s32 *vol = &((CUserStatus *) address)->active_item_vol[0];
7256
7257 if (--(*vol) <= 0) {
7258 DelActiveItem(slot + 1);
7259 DngMessMan.message = 0xB7;
7260 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(ITEM_ANTICURSEAMULET);
7261 DngMessMan.timer = 0xB4;
7262 DngMessMan.steev_window = false;
7263 }
7264 }
7265 }
7266
7267 if ((hit->flags & 0x800) && roll < 0x41 && (UserStatus->ailments[UserStatus->cur_chara] & AILMENT_GOO) == 0) {
7268 int slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_ANTIGOO_AMULET);
7269
7270 if (slot == -1) {
7271 BtSetStatusErr(AILMENT_GOO);
7272 DngMessMan.message = 0xBA;
7273 DngMessMan.timer = 0xB4;
7274 DngMessMan.steev_window = false;
7275 } else {
7276 CUserStatus *who = UserStatus;
7277 unsigned int address = slot * sizeof(s32);
7278
7279 address += (unsigned int) who;
7280 s32 *vol = &((CUserStatus *) address)->active_item_vol[0];
7281
7282 if (--(*vol) <= 0) {
7283 DelActiveItem(slot + 1);
7284 DngMessMan.message = 0xB7;
7285 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(ITEM_ANTIGOO_AMULET);
7286 DngMessMan.timer = 0xB4;
7287 DngMessMan.steev_window = false;
7288 }
7289 }
7290 }
7291
7292 // A hit that halves takes half of what the player can hold.
7293 if (hit->flags & 0x80000) {
7294 damage = UserStatus->max_hp[UserStatus->cur_chara] >> 1;
7295 }
7296
7297 if (NowColData->hit[hit_no].kind == 3) {
7298 sceVu0CopyVector(blow, NowColData->hit[hit_no].pos);
7299 GamePad.SetVibration(1, 0xE6, 0x16);
7300
7301 if (BtActStatus.action_no == 9) {
7302 sceVu0CopyVector(blowVelo, NowColData->hit[hit_no].velocity);
7303 velo__2[0] = blowVelo[0] / 10.0f;
7304 velo__2[2] = blowVelo[2] / 10.0f;
7305
7306 if (NowColData->hit[hit_no].target_mask != 3) {
7307 NowColData->active[hit_no] = 0;
7308 }
7309
7310 if (dmgSnd <= 0) {
7311 SndSePlay(SE_HIT_BLOCKED, -1, 0);
7312 dmgSnd = 30;
7313 }
7314 } else {
7315 SndSePlay(SE_CHARA_HURT, -1, 0);
7316 SndSePlay(SE_PLAYER_HIT, -1, 0);
7317 BtActStatus.hud_shake_frames = 15;
7318 setUnitAmbientAnime(160.0f, 1.0f, 255.0f, 0.0f, 0.0f);
7319 UserStatus->AddNowLife(UserStatus->cur_chara, -damage, 10.0f);
7320
7321 float number_pos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7322
7323 number_pos[1] = CharaHeight(UserStatus);
7324 HitValueEntry(NowHitValue, number_pos, damage, HIT_VALUE_PLAYER, CharaMain.frame);
7325
7326 sceVu0CopyVector(blowVelo, NowColData->hit[hit_no].velocity);
7327 unitBlowActionRot(blowVelo);
7328
7329 if (NowColData->hit[hit_no].target_mask != 3) {
7330 NowColData->active[hit_no] = 0;
7331 }
7332
7333 if (damage < UserStatus->hp[UserStatus->cur_chara]) {
7334 BtActStatus.action_on = 5;
7335 BtActStatus.motion_no = 6;
7336 CharaMain.motion_type.state.time = (float) CharaMain.motion_type.motion_info[6].start;
7337 } else {
7338 BtActStatus.action_on = 4;
7339 BtActStatus.motion_no = 4;
7340 CharaMain.motion_type.state.time = (float) CharaMain.motion_type.motion_info[4].start;
7341 }
7342
7343 driveNoInterpolate = 1;
7344 lockOnTargetFlag = 0;
7345 BtActStatus.recoil_frames = 0xA0;
7346 }
7347 }
7348
7349 COLLISION_HIT *hits = NowColData->hit;
7350 int kind = hits[hit_no].kind;
7351
7352 if (kind == 2 || hits[hit_no].kind == 4) {
7353 sceVu0FVECTOR at;
7354 sceVu0FVECTOR away;
7355
7356 sceVu0CopyVector(at, hits[hit_no].pos);
7357 GamePad.SetVibration(1, 0xDC, 0xC);
7358
7359 if (blown != 0) {
7360 sceVu0CopyVector(away, CharaMain.pos);
7361
7362 if (monster != -1) {
7363 away[0] -= from[0];
7364 away[1] = 0.0f;
7365 away[2] -= from[2];
7366 } else {
7367 away[0] -= at[0];
7368 away[1] = 0.0f;
7369 away[2] -= at[2];
7370 }
7371
7372 sceVu0CopyVector(MyHitPointMark[0].pos, at);
7373 MyHitPointMark[0].on = 1;
7374 MyHitPointMark[0].blink = 0;
7375 MyHitPointMark[0].timer = 0x10;
7376 velo__2[0] = away[0] / 2.0f;
7377 velo__2[2] = away[2] / 2.0f;
7378
7379 if (NowColData->hit[hit_no].target_mask != 3) {
7380 NowColData->active[hit_no] = 0;
7381 }
7382
7383 if (dmgSnd <= 0) {
7384 SndSePlay(SE_HIT_BLOCKED, -1, 0);
7385 dmgSnd = 30;
7386 }
7387 } else {
7388 SndSePlay(SE_CHARA_HURT_HEAVY, -1, 0);
7389 SndSePlay(SE_PLAYER_HIT, -1, 0);
7390 BtActStatus.hud_shake_frames = 25;
7391 setUnitAmbientAnime(80.0f, 1.0f, 255.0f, 0.0f, 0.0f);
7392 UserStatus->AddNowLife(UserStatus->cur_chara, -damage, 10.0f);
7393
7394 if (NowColData->hit[hit_no].target_mask != 3) {
7395 NowColData->active[hit_no] = 0;
7396 }
7397
7398 float heavy_number_pos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7399
7400 heavy_number_pos[1] = CharaHeight(UserStatus);
7401 HitValueEntry(NowHitValue, heavy_number_pos, damage, HIT_VALUE_PLAYER, CharaMain.frame);
7402
7403 static int cnt = 0;
7404 CHitPointMark *spot = &MyHitPointMark[cnt];
7405
7406 sceVu0CopyVector(spot->pos, at);
7407 spot->on = 1;
7408 spot->blink = 0;
7409 spot->timer = 0x10;
7410
7411 if (cnt >= 15) {
7412 cnt = 0;
7413 } else {
7414 cnt++;
7415 }
7416
7417 if (!(stickVector < 0.8f)) {
7418 BtActStatus.action_on = 0;
7419 BtActStatus.motion_no = 0x1D;
7420 } else {
7421 BtActStatus.action_on = 4;
7422 BtActStatus.motion_no = 4;
7423 CharaMain.motion_type.state.time = (float) CharaMain.motion_type.motion_info[4].start;
7424 }
7425
7426 driveNoInterpolate = 1;
7427 BtActStatus.recoil_frames = 0x50;
7428
7429 if (NowColData->hit[hit_no].kind == 4) {
7430 BtActStatus.recoil_frames = 8;
7431 setUnitAmbientAnime(10.0f, 1.0f, 255.0f, 0.0f, 0.0f);
7432 } else {
7433 setUnitAmbientAnime(80.0f, 1.0f, 255.0f, 0.0f, 0.0f);
7434 }
7435 }
7436 }
7437 }
7438 }
7439
7440 if (DebugStatus[20] > 0) {
7441 CUserStatus *status = UserStatus;
7442
7443 status->hp[status->cur_chara] = status->max_hp[status->cur_chara];
7444 }
7445
7446 return taken;
7447}
7448
7449void BattleActionThlow() {
7450 sceVu0FVECTOR stood;
7451 sceVu0FVECTOR aim;
7452
7453 float facing = NowCamera__3->GetAngle();
7454
7455 if (BtActStatus.action_on != 2) {
7456 return;
7457 }
7458
7459 // The stick walks the landing point around while the button is held.
7460 if (BombInfo.aiming != 0) {
7461 if (GamePad.On(PAD_SQUARE) != 0) {
7462 float stick_x = GamePad.GetLXf();
7463 float stick_y = GamePad.GetLYf();
7464
7465 sceVu0CopyVector(stood, CharaMain.pos);
7466 aim[0] = BombInfo.pos[0] + stick_x * cos(facing) + stick_y * sinf(facing);
7467 aim[2] = BombInfo.pos[2] + stick_y * cos(facing) - stick_x * sinf(facing);
7468 aim[1] = BombInfo.pos[1];
7469 aim[3] = 1.0f;
7470
7471 float away = DistVector(aim, stood);
7472
7473 if (!(away < 30.0f) && away <= 120.0f) {
7474 sceVu0CopyVector(BombInfo.pos, aim);
7475 }
7476
7477 float heading = atan2f(aim[0] - stood[0], aim[2] - stood[2]);
7478 float turned = unitRotation((CFrameVu1 *) CharaFrame, heading);
7479 float zero = 0.0f;
7480
7481 CharaFrame->SetRotation(zero, turned, zero);
7482 BtActStatus.motion_no = 0x1A;
7483 } else {
7484 BombInfo.aiming = false;
7485 BombInfo.throw_step = 1;
7486 BtActStatus.motion_no = 0x1B;
7487 }
7488 }
7489
7490 if (BombInfo.throw_step == 1) {
7491 float throw_frame[6] = {548.0f, 452.0f, 267.0f, 347.0f, 188.0f, 321.0f};
7492 float end = (float) CharaMain.motion_type.motion_info[27].end;
7493 float start = throw_frame[UserStatus->cur_chara];
7494
7495 if (CharaMain.motion_type.state.time >= start && CharaMain.motion_type.state.time <= end) {
7496 SndSePlay(SE_THROW, -1, 0);
7497
7498 s16 *slots = UserStatus->active_item;
7499
7500 if (slots[itemNowSel + 3] == 1) {
7501 slots[itemNowSel] = -1;
7502 slots[itemNowSel + 3] = 0;
7503 } else {
7504 slots[itemNowSel + 3]--;
7505 }
7506
7507 if (lockOnTargetFlag == 0) {
7508 sceVu0FVECTOR vector;
7509 sceVu0FVECTOR from;
7510
7511 if (activeItem.model[8] != -1) {
7512 activeItem.models->DeleteModel(activeItem.model[8]);
7513 }
7514
7515 activeItem.model[8] = -1;
7516
7517 float offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7518
7519 CharaMain.frame->SearchFrame("item")->GetWorldPosition(from, offset);
7520 DistVector(from, BombInfo.pos);
7521 ParabolicInitialVector(vector, from, BombInfo.pos, 0.12f, 20.0f);
7522 sceVu0ScaleVectorXYZ(vector, vector, 0.8f);
7523
7524 if (activeItem.model[8] == -1) {
7525 activeItem.models->SetThrowModel(activeItem.model[activeItem.now], from, vector);
7526 }
7527
7528 BombInfo.throw_step++;
7529 } else {
7530 sceVu0FVECTOR lock_vector;
7531 sceVu0FVECTOR lock_from;
7532
7533 if (activeItem.model[8] != -1) {
7534 activeItem.models->DeleteModel(activeItem.model[8]);
7535 }
7536
7537 activeItem.model[8] = -1;
7538
7539 float lock_offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7540 CFrame *hand = CharaMain.frame->SearchFrame("item");
7541
7542 if (hand != NULL) {
7543 hand->GetWorldPosition(lock_from, lock_offset);
7544 }
7545
7546 lock_vector[0] = BtActStatus.target_position[0] - lock_from[0];
7547 lock_vector[1] = 5.0f + (BtActStatus.target_position[1] - lock_from[1]);
7548 lock_vector[2] = BtActStatus.target_position[2] - lock_from[2];
7549 sceVu0Normalize(lock_vector, lock_vector);
7550 lock_vector[0] *= 4.5f;
7551 lock_vector[1] *= 4.5f;
7552 lock_vector[2] *= 4.5f;
7553
7554 if (activeItem.model[8] == -1) {
7555 activeItem.models->SetThrowModel(activeItem.model[activeItem.now], lock_from, lock_vector);
7556 }
7557
7558 BombInfo.throw_step++;
7559 }
7560 }
7561
7562 BtActStatus.motion_no = 0x1B;
7563 }
7564
7565 if (BombInfo.throw_step == 2) {
7566 BtActStatus.motion_no = 0x1B;
7567
7568 float end = (float) CharaMain.motion_type.motion_info[27].end;
7569 float now = CharaMain.motion_type.state.time;
7570
7571 if (now >= end - 2.0f && now <= end) {
7572 BtActStatus.action_on = 0;
7573 BtActStatus.can_act = 1;
7574 BtActStatus.unk_028 = 0;
7575 driveNoInterpolate = 1;
7576
7577 if (lockOnTargetFlag != 0) {
7578 BtActStatus.motion_no = 0x12;
7579 }
7580
7581 BtActStatus.action_busy = 0;
7582 BtActStatus.motion_no = 0;
7583 }
7584 }
7585}
7586
7587void BattleActionDrink() {
7588 float frame;
7589 float now;
7590
7591 if (BtActStatus.action_on != 3) {
7592 return;
7593 }
7594
7595 float drink_frame[6] = {628.0f, 474.0f, 285.0f, 474.0f, 474.0f, 474.0f};
7596
7597 BtActStatus.motion_no = 0x1C;
7598 frame = drink_frame[UserStatus->cur_chara];
7599 now = CharaMain.motion_type.state.time;
7600
7601 if (now >= frame && now < frame + 0.3f) {
7602 SndSePlay(SE_DRINK, -1, 0);
7603 }
7604
7605 if (now >= frame + 10.0f && now < frame + 10.3f) {
7606 setUnitAmbientAnime(64.0f, 1.0f, 0.0f, 122.0f, 208.0f);
7607 SndSePlay(SE_EFFECT_CHIME, -1, 0);
7608 }
7609
7610 float end = (float) CharaMain.motion_type.motion_info[28].end;
7611
7612 if (CharaMain.motion_type.state.time >= end - 1.0f && CharaMain.motion_type.state.time <= end) {
7613 s32 running = activeItem.item[activeItem.now];
7614
7615 usedActiveItem(UserStatus, running);
7616
7617 s16 *slots = UserStatus->active_item;
7618
7619 // The last use takes the item away; anything else just spends one.
7620 if (slots[itemNowSel + 3] == 1) {
7621 slots[itemNowSel] = -1;
7622 slots[itemNowSel + 3] = 0;
7623 } else {
7624 slots[itemNowSel + 3]--;
7625 }
7626
7627 if (activeItem.model[8] != -1) {
7628 activeItem.models->DeleteModel(activeItem.model[8]);
7629 }
7630
7631 activeItem.model[8] = -1;
7632 SndSePlay(SE_CHARA_RECOVER, -1, 0);
7633
7634 BtActStatus.action_on = 0;
7635 BtActStatus.can_act = 1;
7636 driveNoInterpolate = 1;
7637 BtActStatus.action_busy = 0;
7638 BtActStatus.motion_no = 0;
7639 CMonUnitHold = 0;
7640 CEffectHold = 0;
7641 DngMessMan.message = -1;
7642 DngMessMan.timer = 0;
7643 DngMessMan.steev_window = false;
7644 DngMessMan.steev_index = 0;
7645 DngMessMan.hide_timer = 0;
7646 }
7647}
7648
7649/* How long until Ozumond's action plays its sound again, in frames. */
7650s32 ozumond_snd_cnt;
7651
7652/* How long until the player can be damaged again, in frames. */
7653s32 dmg_check_wait;
7654
7655void BattleActionOn_Jinn() {
7656 if (BtActStatus.action_on == 0 && (s32) BtActStatus.action_gauge == 100) {
7657 BtActStatus.action_step = 0;
7658 BtActStatus.charge_time = 0.0f;
7659 BtActStatus.action_no = 11;
7660 BtActStatus.action_on = 1;
7661 BtActStatus.action_gauge = 0.0f;
7662 driveNoInterpolate = 1;
7663 SndSePlay(SE_CHARA_ACTION, -1, 0);
7664 }
7665}
7666
7667void BattleActionPlay_Jinn(CCharacter *chara, int aimed) {
7668 float now = chara->motion_type.state.time;
7669 int damage = NowWeaponHave->attack;
7670 int i;
7671
7672 // A poisoned weapon hits twice as hard.
7673 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
7674 damage *= 2;
7675 }
7676
7677 if (BtActStatus.action_no == 11) {
7678 if (GamePad.On(PadInput_OK) == 0) {
7679 BtActStatus.action_step = 1;
7680 }
7681
7682 BtActStatus.motion_no = 11;
7683
7684 float end = (float) chara->motion_type.motion_info[11].end;
7685
7686 // Letting go before the wind-up ends holds the swing; keeping it
7687 // pressed goes straight on to the throw.
7688 if (now >= end - 2.0f && now <= end) {
7689 if (BtActStatus.action_step == 0) {
7690 BtActStatus.action_no = 12;
7691 } else {
7692 BtActStatus.action_no = 13;
7693 }
7694 }
7695 }
7696
7697 if (BtActStatus.action_no == 13) {
7698 BtActStatus.motion_no = 13;
7699
7700 if (aimed == 0) {
7701 if (now > 251.0f && now < 252.0f) {
7702 SndSePlay(SE_CHARA_ACTION_2, -1, 0);
7703 SndSePlay(SE_CHARA_SHOUT_2, -1, 0);
7704
7705 sceVu0FVECTOR world;
7706 sceVu0FVECTOR vector;
7707 float offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7708 CFrame *hand = NowWeapon->frame->SearchFrame("eff30");
7709
7710 if (hand != NULL) {
7711 hand->GetWorldPosition(world, offset);
7712
7713 if (lockOnTargetFlag == 0) {
7714 float y = CharaMain.GetRotation()->y;
7715
7716 setShotVector(vector, 5.0f, y, 0.0f);
7717 } else {
7718 vector[0] = BtActStatus.target_position[0] - world[0];
7719 vector[1] = BtActStatus.target_position[1] - world[1];
7720 vector[2] = BtActStatus.target_position[2] - world[2];
7721 sceVu0Normalize(vector, vector);
7722 vector[0] *= 5.0f;
7723 vector[1] *= 5.0f;
7724 vector[2] *= 5.0f;
7725 }
7726
7727 CSHOT *shots = NowShotData;
7728
7729 for (i = 0; i < 12; i++) {
7730 if (shots->used[i] == 0) {
7731 sceVu0CopyVector(shots->pos[i], world);
7732 sceVu0CopyVector(shots->vector[i], vector);
7733 shots->life[i] = 0x78;
7734 shots->damage[i] = damage;
7735 shots->size[i] = 1.0f;
7736 shots->halted[i] = 0;
7737 shots->start_flag[i] = 0;
7738 shots->used[i] = 1;
7739 break;
7740 }
7741 }
7742
7743 BtActStatus.frames_since_attack = 0;
7744 }
7745
7746 SwordDmgCheck1(1.0f, 0);
7747 }
7748 } else {
7749#ifdef PAL_TIMING
7750 if (now > 21.0f && now < 21.8f) {
7751#else
7752 if (now > 21.0f && now < 21.5f) {
7753#endif
7754 SndSePlay(SE_CHARA_ACTION_2, -1, 0);
7755 SndSePlay(SE_CHARA_SHOUT_2, -1, 0);
7756
7757 sceVu0FVECTOR world;
7758 sceVu0FVECTOR vector;
7759 float offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7760 CFrame *hand = NowWeapon->frame->SearchFrame("eff30");
7761
7762 if (hand != NULL) {
7763 hand->GetWorldPosition(world, offset);
7764 setShotVector(vector, 3.5f, viewAngleH__2, viewAngleV__2);
7765
7766 CSHOT *shots = NowShotData;
7767
7768 for (i = 0; i < 12; i++) {
7769 if (shots->used[i] == 0) {
7770 sceVu0CopyVector(shots->pos[i], world);
7771 sceVu0CopyVector(shots->vector[i], vector);
7772 shots->life[i] = 0x78;
7773 shots->damage[i] = damage;
7774 shots->size[i] = 1.0f;
7775 shots->halted[i] = 0;
7776 shots->start_flag[i] = 0;
7777 shots->used[i] = 1;
7778 break;
7779 }
7780 }
7781
7782 BtActStatus.frames_since_attack = 0;
7783 }
7784
7785 SwordDmgCheck1(1.0f, 0);
7786 }
7787 }
7788
7789 float end = (float) chara->motion_type.motion_info[13].end;
7790
7791 if (now >= end - 2.0f && now <= end) {
7792 BtActStatus.unk_028 = 0;
7793 BtActStatus.motion_no = 0;
7794 BtActStatus.action_on = 0;
7795
7796 if (lockOnTargetFlag != 0) {
7797 BtActStatus.motion_no = 0x12;
7798 }
7799
7800 // Retail tests the task here and does nothing with the answer.
7801 if (gameTask == GAME_TASK_EYE_CAMERA) {
7802 now = now;
7803 }
7804 }
7805 }
7806
7807 if (BtActStatus.action_no == 12) {
7808 if (GamePad.On(PadInput_OK) == 0) {
7809 BtActStatus.action_step = 1;
7810 }
7811
7812 BtActStatus.motion_no = 12;
7813 driveNoInterpolate = 1;
7814
7815 if (BtActStatus.action_step != 0) {
7816 driveNoInterpolate = 1;
7817 BtActStatus.action_no = 13;
7818 }
7819 }
7820}
7821
7822void BattleActionOn_Ruby() {
7823 if (BtActStatus.action_on == 0 && (s32) BtActStatus.action_gauge == 100) {
7824 BtActStatus.action_step = 0;
7825 BtActStatus.action_no = 11;
7826 BtActStatus.action_on = 1;
7827 BtActStatus.action_gauge = 0.0f;
7828 BtActStatus.charge_time = 0.0f;
7829 driveNoInterpolate = 1;
7830 }
7831}
7832
7833void BattleActionShotRuby(CCharacter *chara, int aimed, float scale, int repeat) {
7834 WEAPON_HAVE *weapon = NowWeaponHave;
7835 int element = weapon->best_elem;
7836 int damage = (weapon->attack >> 1) + (weapon->magic >> 1);
7837
7838 damage = (int) ((float) damage * scale);
7839
7840 // A poisoned weapon hits twice as hard.
7841 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
7842 damage *= 2;
7843 }
7844
7845 // A repeat shot reuses the start and the way the first one took.
7846 if (repeat != 0) {
7847 if (NowMainEffect->Set(ruby_effect_pos, ruby_effect_vec, 3, element, 0, NULL, 1) != -1) {
7848 NowMainEffect->SetWepStatus(NowWeaponHave->flags);
7849 NowMainEffect->SetVsMonster(NowWeaponHave->vs_monster);
7850 NowMainEffect->SetDmg(damage);
7851 NowMainEffect->SetRandomRate(2.0f);
7852 NowMainEffect->SetNoSound();
7853 }
7854
7855 return;
7856 }
7857
7858 if (aimed == 0) {
7859 int shot_no;
7860
7861 getFramePos((CFrameVu1 *) chara->frame, "weapon", ruby_effect_pos);
7862
7863 if (lockOnTargetFlag == 0) {
7864 getCharacterVector(ruby_effect_vec, 0.0f);
7865 ruby_effect_vec[0] += ruby_effect_pos[0];
7866 ruby_effect_vec[1] += ruby_effect_pos[1];
7867 ruby_effect_vec[2] += ruby_effect_pos[2];
7868 shot_no = NowMainEffect->Set(ruby_effect_pos, ruby_effect_vec, 3, element, 0, NULL, 1);
7869 } else {
7870 sceVu0CopyVector(ruby_effect_vec, BtActStatus.target_position);
7871 shot_no = NowMainEffect->Set(ruby_effect_pos, ruby_effect_vec, 3, element, 0, NULL, 1);
7872 }
7873
7874 if (shot_no == -1) {
7875 return;
7876 }
7877
7878 NowMainEffect->SetWepStatus(NowWeaponHave->flags);
7879 NowMainEffect->SetVsMonster(NowWeaponHave->vs_monster);
7880 NowMainEffect->SetDmg(damage);
7881 return;
7882 }
7883
7884 float offset[4] = {0.0f, 0.0f, 0.0f, 1.0f};
7885
7886 chara->frame->SearchFrame("weapon")->GetWorldPosition(ruby_effect_pos, offset);
7887 setShotVector(ruby_effect_vec, 3.5f, viewAngleH__2, viewAngleV__2);
7888 ruby_effect_vec[0] += ruby_effect_pos[0];
7889 ruby_effect_vec[1] += ruby_effect_pos[1];
7890 ruby_effect_vec[2] += ruby_effect_pos[2];
7891
7892 if (NowMainEffect->Set(ruby_effect_pos, ruby_effect_vec, 3, element, 0, NULL, 1) != -1) {
7893 NowMainEffect->SetWepStatus(NowWeaponHave->flags);
7894 NowMainEffect->SetVsMonster(NowWeaponHave->vs_monster);
7895 NowMainEffect->SetDmg(damage);
7896 }
7897}
7898
7899void BattleActionPlay_Ruby(CCharacter *chara, int aimed) {
7900 float now = chara->motion_type.state.time;
7901 int element = NowWeaponHave->best_elem;
7902
7903 if (BtActStatus.action_no == 11) {
7904 if (GamePad.On(PadInput_OK) == 0) {
7905 BtActStatus.action_step = 1;
7906 }
7907
7908 BtActStatus.motion_no = 11;
7909 ruby_effect_id = -1;
7910
7911 if (aimed == 0) {
7912#ifdef PAL_TIMING
7913 if (now >= 125.5f && now <= 126.5f && BtActStatus.action_step == 0) {
7914#else
7915 if (now >= 126.0f && now < 126.3f && BtActStatus.action_step == 0) {
7916#endif
7917 sceVu0FVECTOR pos;
7918 sceVu0FVECTOR aim;
7919
7920 BtActStatus.motion_no = 14;
7921 BtActStatus.action_no = 14;
7922 BtActStatus.charge_time = 0.0f;
7923 ruby_effect_id = NowMainEffect->Set(pos, aim, 3, element, 0, chara->frame->SearchFrame("item"), 0);
7924 NowMainEffect->SetLoop(1);
7925 }
7926
7927#ifdef PAL_TIMING
7928 if (now >= 128.0f && now < 128.4f) {
7929#else
7930 if (now >= 128.0f && now < 128.3f) {
7931#endif
7932 BattleActionShotRuby(chara, aimed, 1.0f, 0);
7933 BtActStatus.frames_since_attack = 0;
7934 SwordDmgCheck1(0.8f, 0);
7935 SndSePlay(SE_CHARA_ACTION, -1, 0);
7936 SndSePlay(SE_CHARA_SHOUT, -1, 0);
7937 }
7938 } else {
7939#ifdef PAL_TIMING
7940 if (now >= 126.0f && now <= 126.5f && BtActStatus.action_step == 0) {
7941#else
7942 if (now >= 126.0f && now < 126.3f && BtActStatus.action_step == 0) {
7943#endif
7944 sceVu0FVECTOR pos;
7945 sceVu0FVECTOR aim;
7946
7947 BtActStatus.motion_no = 14;
7948 BtActStatus.action_no = 14;
7949 BtActStatus.charge_time = 0.0f;
7950 ruby_effect_id = NowMainEffect->Set(pos, aim, 3, element, 0, chara->frame->SearchFrame("item"), 0);
7951 NowMainEffect->SetLoop(1);
7952 }
7953
7954#ifdef PAL_TIMING
7955 if (now >= 128.0f && now < 128.4f) {
7956#else
7957 if (now >= 128.0f && now < 128.3f) {
7958#endif
7959 BattleActionShotRuby(chara, aimed, 1.0f, 0);
7960 BtActStatus.frames_since_attack = 0;
7961 SwordDmgCheck1(0.8f, 0);
7962 SndSePlay(SE_CHARA_ACTION, -1, 0);
7963 SndSePlay(SE_CHARA_SHOUT, -1, 0);
7964 }
7965 }
7966
7967 float end = (float) chara->motion_type.motion_info[11].end;
7968
7969 if (now >= end - 1.0f && now <= end) {
7970 BtActStatus.unk_028 = 0;
7971 BtActStatus.motion_no = 0;
7972 BtActStatus.action_on = 0;
7973
7974 if (lockOnTargetFlag != 0 && aimed == 0) {
7975 BtActStatus.motion_no = 0x12;
7976 }
7977 }
7978 }
7979
7980 if (BtActStatus.action_no == 14) {
7981 if (GamePad.On(PadInput_OK) == 0) {
7982 BtActStatus.action_step = 1;
7983 }
7984
7985 BtActStatus.motion_no = 14;
7986 SndSeSeqPlayStop(0x193, 5, 0);
7987
7988 BtActStatus.charge_time += 1.0f;
7989
7990 if (BtActStatus.charge_time >= 60.0f) {
7991 BtActStatus.charge_time = 60.0f;
7992 }
7993
7994 if (BtActStatus.charge_time >= 58.0f && BtActStatus.charge_time < 58.5f) {
7995 setUnitAmbientAnime(15.0f, 1.0f, 0.0f, 122.0f, 208.0f);
7996 }
7997
7998 if (BtActStatus.action_step != 0) {
7999 BtActStatus.action_no = 16;
8000 BtActStatus.action_gauge = 0.0f;
8001 }
8002 }
8003
8004 if (BtActStatus.action_no == 16) {
8005 BtActStatus.motion_no = 16;
8006
8007 // A full charge throws two shots; a short one throws a single
8008 // stronger shot a little later.
8009 if (BtActStatus.charge_time >= 60.0f) {
8010 if (now >= 216.0f && now < 217.5f && ruby_effect_id != -1) {
8011 NowMainEffect->OffEffect(ruby_effect_id);
8012 ruby_effect_id = -1;
8013 }
8014
8015 if (aimed == 0) {
8016#ifdef PAL_TIMING
8017 if (now >= 216.0f && now < 216.5f) {
8018#else
8019 if (now >= 216.0f && now < 216.4f) {
8020#endif
8021 BattleActionShotRuby(chara, aimed, 2.2f, 0);
8022 BattleActionShotRuby(chara, aimed, 2.2f, 1);
8023 BtActStatus.frames_since_attack = 0;
8024 SwordDmgCheck1(1.8f, 0);
8025 SndSePlay(SE_CHARA_ACTION, -1, 0);
8026 SndSePlay(SE_CHARA_SHOUT_3, -1, 0);
8027 }
8028 } else {
8029#ifdef PAL_TIMING
8030 if (now >= 216.0f && now < 216.5f) {
8031#else
8032 if (now >= 216.0f && now < 216.3f) {
8033#endif
8034 BattleActionShotRuby(chara, aimed, 2.2f, 0);
8035 BattleActionShotRuby(chara, aimed, 2.2f, 1);
8036 BtActStatus.frames_since_attack = 0;
8037 SwordDmgCheck1(1.8f, 0);
8038 SndSePlay(SE_CHARA_ACTION, -1, 0);
8039 SndSePlay(SE_CHARA_SHOUT_3, -1, 0);
8040 }
8041 }
8042 } else {
8043 if (now >= 216.5f && now < 217.5f && ruby_effect_id != -1) {
8044 NowMainEffect->OffEffect(ruby_effect_id);
8045 ruby_effect_id = -1;
8046 }
8047
8048 if (now >= 216.5f && now < 216.9f) {
8049 BattleActionShotRuby(chara, aimed, 1.5f, 0);
8050 BtActStatus.frames_since_attack = 0;
8051 SwordDmgCheck1(1.2f, 0);
8052 SndSePlay(SE_CHARA_ACTION, -1, 0);
8053 SndSePlay(SE_CHARA_SHOUT_3, -1, 0);
8054 }
8055 }
8056
8057 float end = (float) chara->motion_type.motion_info[16].end;
8058
8059 if (now >= end - 1.0f && now <= end) {
8060 BtActStatus.unk_028 = 0;
8061 BtActStatus.motion_no = 0;
8062 BtActStatus.action_on = 0;
8063
8064 if (lockOnTargetFlag != 0 && aimed == 0) {
8065 BtActStatus.motion_no = 0x12;
8066 }
8067 }
8068 }
8069}
8070
8071void BattleActionOn_Ozumond() {
8072 if (BtActStatus.action_on == 0 && BtActStatus.gauge_exhausted == 0) {
8073 BtActStatus.action_no = 11;
8074 BtActStatus.action_on = 1;
8075 BtActStatus.action_step = 0;
8076 BtActStatus.charge_level = 0;
8077 BtActStatus.charge_time = 1.0f;
8078 driveNoInterpolate = 1;
8079 SndSePlay(SE_CHARA_SHOUT, -1, 0);
8080 ozumond_snd_cnt = 30;
8081 }
8082}
8083
8084void BattleActionOn_Ozumond_H() {
8085 if (BtActStatus.action_on == 0 && (s32) BtActStatus.action_gauge == 100) {
8086 BtActStatus.action_no = 11;
8087 BtActStatus.action_on = 1;
8088 BtActStatus.action_step = 0;
8089 BtActStatus.charge_level = 0;
8090 BtActStatus.action_gauge = 0.0f;
8091 BtActStatus.charge_time = 30.0f;
8092 driveNoInterpolate = 1;
8093 SndSePlay(SE_CHARA_SHOUT, -1, 0);
8094 ozumond_snd_cnt = 30;
8095 }
8096}
8097
8098void BattleActionOn_Ozumond_F() {
8099 if (BtActStatus.action_on == 0 && BtActStatus.gauge_exhausted == 0) {
8100 BtActStatus.action_no = 0;
8101 BtActStatus.action_on = 1;
8102 BtActStatus.action_step = 0;
8103 BtActStatus.charge_level = 0;
8104 driveNoInterpolate = 1;
8105 dmg_check_wait = 0;
8106 SndSePlay(SE_CHARA_SHOUT, -1, 0);
8107 ozumond_snd_cnt = 30;
8108 }
8109}
8110
8111void BattleActionPlay_Ozumond(int aimed) {
8112 sceVu0FVECTOR pos;
8113 sceVu0FVECTOR aim;
8114 sceVu0FVECTOR shot;
8115 float drain;
8116
8117 WEAPON_HAVE *weapon = NowWeaponHave;
8118 int damage = (weapon->attack >> 1) + (weapon->magic >> 1);
8119
8120 // A poisoned weapon hits twice as hard.
8121 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
8122 damage *= 2;
8123 }
8124
8125 drain = 1.5f - 0.01f * (float) NowWeaponHave->speed;
8126
8127 if (BtActStatus.action_no != 11) {
8128 return;
8129 }
8130
8131 if (GamePad.On(PadInput_OK) == 0) {
8132 BtActStatus.action_step = 1;
8133 }
8134
8135 SndSeSeqPlayStop(0x190, 5, 0);
8136
8137 // The action runs until the gauge the weapon drains runs out.
8138 BtActStatus.action_gauge -= drain;
8139
8140 if (BtActStatus.action_gauge <= 0.0f) {
8141 BtActStatus.unk_028 = 0;
8142 BtActStatus.motion_no = 0;
8143 BtActStatus.action_on = 0;
8144 BtActStatus.gauge_exhausted = 1;
8145
8146 if (lockOnTargetFlag != 0) {
8147 BtActStatus.motion_no = 0x12;
8148 }
8149 }
8150
8151 BtActStatus.motion_no = 11;
8152
8153 if (aimed == 0) {
8154 getFramePos((CFrameVu1 *) NowWeapon->frame, "dcol0", pos);
8155 getCharacterVector(aim, 0.0f);
8156 } else {
8157 setShotVector(aim, 3.5f, viewAngleH__2, viewAngleV__2);
8158 sceVu0CopyVector(pos, CharaMain.pos);
8159 pos[1] += 10.0f;
8160 }
8161
8162 sceVu0CopyVector(shot, aim);
8163 aim[0] += pos[0];
8164 aim[1] += pos[1];
8165 aim[2] += pos[2];
8166
8167 if (lockOnTargetFlag != 0) {
8168 shot[0] = BtActStatus.target_position[0] - pos[0];
8169 shot[1] = BtActStatus.target_position[1] - pos[1];
8170 shot[2] = BtActStatus.target_position[2] - pos[2];
8171 }
8172
8173 static int s_cnt = 0;
8174
8175 s_cnt++;
8176
8177 if (s_cnt >= 10) {
8178 s_cnt = 0;
8179
8180 if (aimed == 0) {
8181 NowMainEffect->Set(pos, aim, -1, -1, 0, NowWeapon->frame->SearchFrame("dcol0"), -1);
8182 }
8183 }
8184
8185 static int msg_cnt = 0;
8186
8187 msg_cnt++;
8188
8189 if (msg_cnt >= 10) {
8190 msg_cnt = 0;
8191 sceVu0Normalize(shot, shot);
8192 sceVu0ScaleVectorXYZ(shot, shot, 10.0f);
8193 OzumondShot.Set(pos, shot, damage, 0);
8194 BtActStatus.frames_since_attack = 0;
8195 SwordDmgCheck1(0.5f, 0);
8196 }
8197
8198 if (BtActStatus.action_step == 1) {
8199 BtActStatus.unk_028 = 0;
8200 BtActStatus.motion_no = 0;
8201 BtActStatus.action_on = 0;
8202
8203 if (lockOnTargetFlag != 0) {
8204 BtActStatus.motion_no = 0x12;
8205 }
8206
8207 NowMainEffect->OffEffect(-1);
8208 }
8209}
8210
8211void BattleActionPlay_Ozumond_H(int aimed) {
8212 static int wait_cnt;
8213 sceVu0FVECTOR pos;
8214 sceVu0FVECTOR aim;
8215 sceVu0FVECTOR shot;
8216
8217 WEAPON_HAVE *weapon = NowWeaponHave;
8218 int element = weapon->best_elem;
8219 int damage = weapon->attack;
8220
8221 // A poisoned weapon hits twice as hard.
8222 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
8223 damage *= 2;
8224 }
8225
8226 if (BtActStatus.action_no != 11) {
8227 return;
8228 }
8229
8230 if (GamePad.On(PadInput_OK) == 0) {
8231 BtActStatus.action_step = 1;
8232 wait_cnt = 10;
8233 }
8234
8235 BtActStatus.motion_no = 11;
8236
8237 wait_cnt++;
8238
8239 if (wait_cnt >= 10) {
8240 wait_cnt = 0;
8241 SndSeSeqPlayStop(0x199, 5, 0);
8242
8243 if (aimed == 0) {
8244 getFramePos((CFrameVu1 *) NowWeapon->frame, "dcol0", pos);
8245 getCharacterVector(aim, 0.0f);
8246 } else {
8247 setShotVector(aim, 3.5f, viewAngleH__2, viewAngleV__2);
8248 sceVu0CopyVector(pos, CharaMain.pos);
8249 pos[1] += 10.0f;
8250 }
8251
8252 sceVu0CopyVector(shot, aim);
8253 aim[0] += pos[0];
8254 aim[1] += pos[1];
8255 aim[2] += pos[2];
8256
8257 int shot_no;
8258
8259 if (lockOnTargetFlag != 0) {
8260 shot_no = NowMainEffect->Set(pos, BtActStatus.target_position, 5, element, 0, NULL, -1);
8261 } else {
8262 shot_no = NowMainEffect->Set(pos, aim, 5, element, 0, NULL, -1);
8263 }
8264
8265 if (shot_no != -1) {
8266 NowMainEffect->SetVsMonster(NowWeaponHave->vs_monster);
8267 NowMainEffect->SetWepStatus(NowWeaponHave->flags);
8268 NowMainEffect->SetAttribute(GetWeaponElementAttr(NowWeaponHave->best_elem));
8269 NowMainEffect->SetDmg(damage);
8270 }
8271
8272 BtActStatus.action_step = 1;
8273 BtActStatus.frames_since_attack = 0;
8274 SwordDmgCheck1(2.0f, 0);
8275 }
8276
8277 if (BtActStatus.action_step == 1) {
8278 BtActStatus.unk_028 = 0;
8279 BtActStatus.motion_no = 0;
8280 BtActStatus.action_on = 0;
8281
8282 if (lockOnTargetFlag != 0) {
8283 BtActStatus.motion_no = 0x12;
8284 }
8285 }
8286}
8287
8288void BattleActionPlay_Ozumond_F(int aimed) {
8289 static int wait_cnt = 0;
8290 sceVu0FVECTOR start;
8291 sceVu0FVECTOR start_dir;
8292 sceVu0FVECTOR pos;
8293 sceVu0FVECTOR aim;
8294
8295 GetWeaponElementAttr(NowWeaponHave->best_elem);
8296
8297 int damage = NowWeaponHave->attack;
8298
8299 // A poisoned weapon hits twice as hard.
8300 if (StatusErrCheck(AILMENT_STAMINA) != 0) {
8301 damage *= 2;
8302 }
8303
8304 if (BtActStatus.action_no == 0) {
8305 BtActStatus.motion_no = 11;
8306 dmg_check_wait++;
8307
8308 if (dmg_check_wait >= 8) {
8309 dmg_check_wait = 0;
8310 SwordDmgCheck1(1.5f, 0);
8311 BtActStatus.action_no = 1;
8312 BtActStatus.frames_since_attack = 0;
8313
8314 if (aimed == 0) {
8315 getFramePos((CFrameVu1 *) NowWeapon->frame, "dcol0", start);
8316 getCharacterVector(start_dir, 0.0f);
8317 } else {
8318 setShotVector(start_dir, 1.0f, viewAngleH__2, viewAngleV__2);
8319 sceVu0CopyVector(start, CharaMain.pos);
8320 start[1] += 10.0f;
8321 }
8322
8323 OzumondFire.Init(start, start_dir, 0, 0);
8324 }
8325
8326 if (GamePad.On(PadInput_OK) == 0) {
8327 BtActStatus.unk_028 = 0;
8328 BtActStatus.motion_no = 0;
8329 BtActStatus.action_on = 0;
8330
8331 if (lockOnTargetFlag != 0) {
8332 BtActStatus.motion_no = 0x12;
8333 }
8334
8335 wait_cnt = 10;
8336 }
8337 }
8338
8339 if (BtActStatus.action_no != 1) {
8340 return;
8341 }
8342
8343 BtActStatus.motion_no = 11;
8344 SndSeSeqPlayStop(0x194, 5, 0);
8345
8346 // The action runs until the gauge the weapon drains runs out.
8347 BtActStatus.action_gauge -= 0.5f;
8348
8349 if (BtActStatus.action_gauge <= 0.0f) {
8350 BtActStatus.unk_028 = 0;
8351 BtActStatus.motion_no = 0;
8352 BtActStatus.action_on = 0;
8353 BtActStatus.gauge_exhausted = 1;
8354
8355 if (lockOnTargetFlag != 0) {
8356 BtActStatus.motion_no = 0x12;
8357 }
8358 }
8359
8360 if (aimed == 0) {
8361 getFramePos((CFrameVu1 *) NowWeapon->frame, "dcol0", pos);
8362 getCharacterVector(aim, 0.0f);
8363 } else {
8364 setShotVector(aim, 3.5f, viewAngleH__2, viewAngleV__2);
8365 sceVu0CopyVector(pos, CharaMain.pos);
8366 pos[1] += 10.0f;
8367 }
8368
8369 OzumondFire.Set(pos, aim, damage, NowWeaponHave->best_elem);
8370
8371 dmg_check_wait++;
8372
8373 if (dmg_check_wait >= 30) {
8374 dmg_check_wait = 0;
8375 SwordDmgCheck1(2.2f, 0);
8376 BtActStatus.frames_since_attack = 0;
8377 }
8378
8379 if (GamePad.On(PadInput_OK) == 0) {
8380 BtActStatus.unk_028 = 0;
8381 BtActStatus.motion_no = 0;
8382 BtActStatus.action_on = 0;
8383
8384 if (lockOnTargetFlag != 0) {
8385 BtActStatus.motion_no = 0x12;
8386 }
8387
8388 OzumondFire.Rset();
8389 wait_cnt = 10;
8390 dmg_check_wait = 0;
8391 }
8392}
8393
8394float camera_far_dist_limmit;
8395
8396/* The overlay's own copy of the camera walk is static, so only `autoCamTrial`
8397 * names it. It compiles to retail's code exactly, but while that caller is
8398 * still supplied by its marker the marker's `jal` needs the disambiguated
8399 * global the reference dump carries, so both flip together. */
8400static void CameraAutoMove(CCameraFollow *camera, CCPoly *poly, float *position, float from, float to) {
8401 float reference[4];
8402 float offset[4];
8403 float step;
8404
8405 camera->GetRef(reference);
8406 offset[0] = position[0] - reference[0];
8407 offset[2] = position[2] - reference[2];
8408 offset[1] = 0.0f;
8409 camera->SetDistance(0.1f + DistVector(offset));
8410
8411 step = 0.0f;
8412 float over = camera->GetDistance() - camera_near_dist__2;
8413
8414 if (over < step) {
8415 step = -over / 20.0f;
8416 }
8417
8418 if (over > 0.0f) {
8419 step = over / 30.0f;
8420 }
8421
8422 if (step > 2.0f) {
8423 step = 2.0f;
8424 }
8425
8426 if (step < 0.05f) {
8427 step = 0.05f;
8428 }
8429
8430 if (over < 0.0f) {
8431 step *= 2.0f;
8432 }
8433
8434 NowCamera__3->SetAngle(atan2f(offset[0], offset[2]));
8435
8436 if (from < to) {
8437 NowCamera__3->AddAngle(0.2f * -step);
8438 } else {
8439 NowCamera__3->AddAngle(0.2f * step);
8440 }
8441
8442 if (camera->GetDistance() < 0.8f * camera_near_dist__2) {
8443 camera->AddHeight(1.0f);
8444 }
8445}
8446
8447void autoCamTrial() {
8448 static int cameraDilay = 0;
8449 sceVu0FVECTOR eye;
8450 sceVu0FVECTOR look;
8451 sceVu0FVECTOR along;
8452 CBoxVu0 box;
8453 sceVu0FVECTOR pos;
8454 sceVu0FVECTOR at;
8455 sceVu0FVECTOR ref;
8456 sceVu0FVECTOR reach;
8457 sceVu0FVECTOR forward;
8458 sceVu0FVECTOR towards;
8459 int hit_poly[32];
8460 float hit_point[32][4];
8461 sceVu0FVECTOR facing;
8462 sceVu0FVECTOR facing_last;
8463 sceVu0FVECTOR stood;
8464 sceVu0FVECTOR chara;
8465 sceVu0FVECTOR near_chara;
8466 sceVu0FVECTOR locked;
8467 float world[4][4];
8468 CCPoly *poly;
8469 int i;
8470 int count;
8471
8472 if (DebugStatus[5] == 0) {
8473 return;
8474 }
8475
8476 NowCamera__3->GetPos(eye);
8477 NowCamera__3->GetRef(look);
8478
8479 along[0] = look[0] - eye[0];
8480 along[1] = look[1] - eye[1];
8481 along[2] = look[2] - eye[2];
8482 along[3] = 1.0f;
8483 sceVu0Normalize(along, along);
8484 along[0] *= 30.0f;
8485 along[1] *= 30.0f;
8486 along[2] *= 30.0f;
8487
8488 // Every polygon the floor puts near the camera goes into one list, which
8489 // the line from the eye to what it looks at is then tested against.
8490 WorkBuffer__2->used = 0;
8491
8492 poly = (CCPoly *) WorkBuffer__2->Alloc(0x280);
8493
8494 count = 0;
8495
8496 box.max[0] = look[0] > eye[0] ? look[0] : eye[0];
8497 box.max[1] = look[1] > eye[1] ? look[1] : eye[1];
8498 box.max[2] = look[2] > eye[2] ? look[2] : eye[2];
8499 box.min[0] = look[0] < eye[0] ? look[0] : eye[0];
8500 box.min[1] = look[1] < eye[1] ? look[1] : eye[1];
8501 box.min[2] = look[2] < eye[2] ? look[2] : eye[2];
8502
8503 if (NowDngMap->map_type != 1) {
8504 CFrame *frame;
8505 int i;
8506
8507 i = 0;
8508
8509 while (NowDngMap->parts[i].frame[0] != NULL) {
8510 if (i == -1) {
8511 frame = NULL;
8512 } else {
8513 frame = NowDngMap->parts[i].camera_collision;
8514 }
8515
8516 if (frame != NULL) {
8517 CDungeonParts *part = &NowDngMap->parts[i];
8518
8519 sceVu0CopyVector(eye, part->frame_offset[0]);
8520
8521 CDungeonMap *map = NowDngMap;
8522 int turn = (int) ((CDungeonMap *) map)->parts[i].frame_turn[0];
8523
8524 turn += i == -1 ? 0 : map->parts[i].camera_collision_turn;
8525
8526 if (turn > 3) {
8527 turn -= 3;
8528 }
8529
8530 if (turn == 3) {
8531 turn = -1;
8532 }
8533
8534 frame->SetRotation(0.0f, PI * (-90.0f * turn) / 180.0f, 0.0f);
8535 frame->SetPosition(eye);
8536 count += frame->PickUpNearPoly(&poly[count], box);
8537 }
8538
8539 i++;
8540 }
8541 } else {
8542 CFrame *frame;
8543 int i;
8544 int j;
8545
8546 for (j = 0; j < 20; j++) {
8547 for (i = 0; i < 20; i++) {
8548 CDungeonMap *map = NowDngMap;
8549 s32 parts_no = map->cells[i + j * 20].parts_no;
8550
8551 if (parts_no == -1) {
8552 frame = NULL;
8553 } else {
8554 frame = map->parts[parts_no].camera_collision;
8555 }
8556
8557 MAP_CELL *cell = &map->cells[i + j * 20];
8558
8559 if (frame == NULL) {
8560 continue;
8561 }
8562
8563 if (!(cell->camera_dist <= 240.0f)) {
8564 continue;
8565 }
8566
8567 int turn = map->cells[i + j * 20].direction;
8568
8569 turn += parts_no == -1 ? 0 : map->parts[parts_no].camera_collision_turn;
8570
8571 if (turn > 3) {
8572 turn -= 3;
8573 }
8574
8575 if (turn == 3) {
8576 turn = -1;
8577 }
8578
8579 frame->SetRotation(0.0f, PI * (-90.0f * turn) / 180.0f, 0.0f);
8580 frame->SetPosition(160.0f * i, 0.0f, 160.0f * j);
8581 count += frame->PickUpNearPoly(&poly[count], box);
8582 }
8583 }
8584 }
8585
8586 static int cnt = 0;
8587
8588 cnt++;
8589
8590 if (cnt > 60) {
8591 cnt = 0;
8592 }
8593
8594 NowCamera__3->GetPos(pos);
8595 NowCamera__3->GetRef(ref);
8596 sceVu0SubVector(forward, ref, pos);
8597 sceVu0SubVector(reach, pos, forward);
8598 sceVu0SubVector(reach, pos, ref);
8599 sceVu0Normalize(reach, reach);
8600 sceVu0ScaleVectorXYZ(reach, reach, 80.0f);
8601 reach[0] += ref[0];
8602 reach[1] += ref[1];
8603 reach[2] += ref[2];
8604
8605 int hits = CheckHits(poly, count, ref, reach, 32, hit_poly, hit_point, 1, 0);
8606
8607 camera_far_dist_limmit = 80.0f;
8608
8609 if (hits > 0) {
8610 camera_far_dist_limmit = DistVector(ref, hit_point[0]);
8611 }
8612
8613 if (hits > 0) {
8614 int last;
8615
8616 sceVu0InnerProduct(forward, poly[hit_poly[0]].normal);
8617 last = -1;
8618
8619 for (i = 0; i < hits; i++) {
8620 sceVu0SubVector(towards, hit_point[i], pos);
8621
8622 if (sceVu0InnerProduct(forward, towards) < 0.0f) {
8623 break;
8624 }
8625
8626 last = i;
8627 }
8628
8629 if (last >= 0) {
8630 sceVu0CopyVector(facing, poly[hit_poly[last]].normal);
8631
8632 if (sceVu0InnerProduct(forward, facing) > 0.0f) {
8633 if (last + 1 < hits) {
8634 float away = DistVector(pos, hit_point[last + 1]);
8635
8636 if (away - DistVector(pos, hit_point[last]) < 0.0f) {
8637 CameraAutoMove(NowCamera__3, &poly[hit_poly[last + 1]], hit_point[last + 1], 1000000.0f, 1000000.0f);
8638 } else {
8639 CameraAutoMove(NowCamera__3, &poly[hit_poly[last]], hit_point[last], 1000000.0f, 1000000.0f);
8640 }
8641 } else if (camera_far_dist_limmit >= camera_near_dist__2 && camera_far_dist_limmit < camera_far_dist__2) {
8642 NowCamera__3->SetPos(hit_point[0]);
8643 } else {
8644 CameraAutoMove(NowCamera__3, &poly[hit_poly[last]], hit_point[last], 1000000.0f, 1000000.0f);
8645 }
8646 }
8647 } else {
8648 sceVu0CopyVector(facing_last, poly[hit_poly[0]].normal);
8649
8650 if (sceVu0InnerProduct(forward, facing_last) < 0.0f) {
8651 CameraAutoMove(NowCamera__3, &poly[hit_poly[0]], hit_point[0], 1000000.0f, 1000000.0f);
8652 }
8653 }
8654 }
8655
8656 // The camera keeps its head above whatever floor is under it.
8657 sceVu0CopyVector(reach, pos);
8658 reach[1] += 20.0f;
8659
8660 if (CheckHitVertical(poly, count, reach, -100.0f, at, 0) >= 0) {
8661 if (pos[1] - at[1] < 25.0f) {
8662 pos[1] = 25.0f + at[1];
8663 NowCamera__3->SetHeight(pos[1] - ref[1] - 0.01f);
8664 }
8665 }
8666
8667 sceVu0CopyVector(chara, CharaMain.pos);
8668 NowCamera__3->GetPos(stood);
8669
8670 if (DistVector(chara, stood) < camera_up_near_dist) {
8671 NowCamera__3->AddHeight(0.5f);
8672
8673 if (NowCamera__3->GetHeight() <= 1.6f) {
8674 NowCamera__3->SetHeight(1.6f);
8675 }
8676 } else {
8677 if (NowCamera__3->GetHeight() <= 1.6f) {
8678 NowCamera__3->SetHeight(1.6f);
8679 }
8680
8681 if (!(NowCamera__3->GetHeight() <= 5.0f)) {
8682 float rate = 0.05f;
8683 float over = NowCamera__3->GetHeight() - 5.0f;
8684 float step = over * rate;
8685
8686 if (step < 0.15f) {
8687 step = 0.15f;
8688 }
8689
8690 if (!(step <= 0.5f)) {
8691 step = 0.5f;
8692 }
8693
8694 NowCamera__3->AddHeight(-step);
8695 }
8696 }
8697
8698 if (!(NowCamera__3->GetDistance() <= camera_far_dist__2)) {
8699 NowCamera__3->AddDistance(-(NowCamera__3->GetDistance() - camera_far_dist__2) / 10.0f);
8700 }
8701
8702 if (NowCamera__3->GetDistance() < camera_near_dist__2) {
8703 NowCamera__3->AddDistance(-(NowCamera__3->GetDistance() - camera_near_dist__2) / 10.0f);
8704 }
8705
8706 if (NowCamera__3->GetDistance() < camera_far_dist_limmit) {
8707 NowCamera__3->AddDistance(-(NowCamera__3->GetDistance() - camera_far_dist_limmit) / 10.0f);
8708 }
8709
8710 if (BtActStatus.slow_walking == 0 && NowCamera__3->GetDistance() < camera_far_dist__2) {
8711 float turn = inputH1;
8712
8713 inputH1 = inputH1 * (DistVector(ref_off) / 1.3f / 2.0f);
8714
8715 if (!(inputH1 <= 0.1f)) {
8716 if (turn < 0.4f) {
8717 turn = 0.4f;
8718 }
8719
8720 if (!(turn <= 1.0f)) {
8721 turn = 1.0f;
8722 }
8723
8724 NowCamera__3->AddAngle(2.5f * (-DEG_TO_RAD * turn));
8725 }
8726
8727 if (inputH1 < -0.1f) {
8728 if (!(turn <= -0.4f)) {
8729 turn = -0.4f;
8730 }
8731
8732 if (turn < -1.0f) {
8733 turn = -1.0f;
8734 }
8735
8736 NowCamera__3->AddAngle(2.5f * (-DEG_TO_RAD * turn));
8737 }
8738 }
8739
8740 // A locked-on monster pulls the camera round behind the player.
8741 if (lockOnTargetFlag != 0) {
8742 sceVu0CopyVector(near_chara, CharaMain.pos);
8743 NowMonstorUnit->chara[lockOnTargetNo][0].GetPosition(locked);
8744
8745 float away = DistVector(near_chara, locked);
8746
8747 if (!(away <= 30.0f)) {
8748 CharaMain.frame->GetLWMatrix(world);
8749
8750 float want = (float) (atan2f(world[2][0], world[2][2]) - PI_D);
8751
8752 if (!(want <= PI_SHORT)) {
8753 want -= TWO_PI_SHORT;
8754 }
8755
8756 if (want < -PI_SHORT) {
8757 want += TWO_PI_SHORT;
8758 }
8759
8760 float angle = NowCamera__3->GetAngle();
8761 float range = 70.0f * ((60.0f - away) / 30.0f);
8762
8763 range += 20.0f;
8764
8765 if (!(range < 90.0f)) {
8766 range = 90.0f;
8767 }
8768
8769 if (range < 0.0f) {
8770 range = 0.0f;
8771 }
8772
8773 if (!(away <= 80.0f)) {
8774 range = 10.0f;
8775 }
8776
8777 if (AngleCmp(want, angle, DEG_TO_RAD_SHORT * range) != 0) {
8778 angle = AngleInterpolate(angle, want, EIGHTH_PI_SHORT, INTERPOLATE_STEP);
8779 NowCamera__3->SetAngle(angle);
8780
8781 if (AngleCmp(want, angle, HALF_PI_SHORT) != 0) {
8782 NowCamera__3->SetSpeed(8.0f);
8783 }
8784 }
8785 }
8786 }
8787}
8788
8789void DelActiveItem(int slot) {
8790 // The two arrays are adjacent, and retail walks the second one off the
8791 // first rather than off the save data again.
8792 s16 *slots = UserStatus->active_item;
8793
8794 // The last use takes the item away; anything else just spends one.
8795 if (slots[slot + 3] == 1) {
8796 slots[slot] = -1;
8797 slots[slot + 3] = 0;
8798
8799 if (activeItem.model[slot] != -1) {
8800 activeItem.models->DeleteModel(activeItem.model[slot]);
8801 activeItem.model[slot] = -1;
8802 }
8803 } else {
8804 slots[slot + 3]--;
8805 }
8806}
8807
8808#define CHARA_WEAPONS_OFFSET 0x450c
8809STATIC_ASSERT((int) &((CUserStatus *) 0)->chara_weapons == CHARA_WEAPONS_OFFSET);
8810
8811#pragma opt_propagation off
8812
8813int Run_TrapCircle(MAP_TRAP_CIRCLE *trap) {
8814 if (trap == NULL) {
8815 return;
8816 }
8817
8818 int element;
8819 int se;
8820 int kind;
8821 WEAPON_HAVE *weapon;
8822 CUserStatus *status;
8823 int had;
8824 u16 *wallet;
8825 s8 chara;
8826 s8 *slots;
8827 s8 slot;
8828
8829 status = UserStatus;
8830 wallet = &status->money;
8831 had = status->money;
8832 int had_copy = *wallet;
8833 chara = status->cur_chara;
8834 slots = status->equipped_weapon_slot;
8835 slot = slots[chara];
8836 int slot_bytes = slot * (int) sizeof(WEAPON_HAVE);
8837 int row_bytes = chara * (int) sizeof(status->chara_weapons[0]);
8838 weapon = (WEAPON_HAVE *) ((char *) status + row_bytes + slot_bytes + CHARA_WEAPONS_OFFSET);
8839 element = -1;
8840 se = 0;
8841 kind = trap->kind;
8842
8843 s16 item_no = status->chara_weapons[status->cur_chara][slot].item_no;
8844
8845 if (item_no == defWeapon__6[chara] || item_no == defWeapon__6[chara] + 1) {
8846 kind = TRAP_CIRCLE_STAMINA;
8847 }
8848
8849 switch (kind) {
8851 BtSetStatusErr(AILMENT_STAMINA);
8852 se = 0xE1;
8853 break;
8854 case TRAP_CIRCLE_MONEY_UP: {
8855 had_copy *= 1.2f;
8856 int added = had_copy + 10;
8857
8858 if (had + added >= 0xFFFF) {
8859 status->money = 0xFFFF;
8860 } else {
8861 status->money += added;
8862 }
8863
8864 se = 0xE1;
8865 break;
8866 }
8868 element = RGATE_ABS_FULL;
8869 se = 0xE1;
8870 break;
8871 case TRAP_CIRCLE_WHP_UP:
8872 element = RGATE_WHP_UP;
8873 se = 0xE1;
8874 break;
8876 element = RGATE_WHP_CURE;
8877 se = 0xE1;
8878 break;
8880 NowMonstorUnit->AllBin2();
8881 se = 0xE2;
8882 break;
8884 had_copy = (int) (had_copy - 0.2f * had_copy);
8885
8886 if (had_copy <= 0) {
8887 had_copy = 0;
8888 }
8889
8890 *wallet = had_copy;
8891 se = 0xE2;
8892 break;
8893 }
8895 element = RGATE_STAT_DOWN;
8896 se = 0xE2;
8897 break;
8899 element = RGATE_WHP_DOWN;
8900 se = 0xE2;
8901 break;
8903 element = RGATE_WHP_QUARTER;
8904 se = 0xE2;
8905 break;
8906 }
8907
8908 if (element != -1) {
8909 WeaponDataChangeByRGate(weapon, element);
8910 SetWeaponAttachStatus(NowWeaponHave);
8911 }
8912
8913 SndSePlay(se, -1, 0);
8914 return kind;
8915}
8916
8917#pragma opt_propagation reset
8918
8919void LockOffTargte() {
8920 lockOnTargetDraw = 0;
8921 lockOnTargetNo = -1;
8922 lockOnTargetFlag = 0;
8923 targetCursorShiftNo = -1;
8924 targetCursorShiftRot = 0.0f;
8925 EnemyLifeGage.on = 0;
8926}
8927
8928void DrawTargetLife() {
8929 CRect_i_ border;
8930 CRect_i_ ground;
8931 CRect_i_ life;
8932 s32 x;
8933 s32 width;
8934
8935 if (EnemyLifeGage.on == 0) {
8936 return;
8937 }
8938
8939 if (EnemyLifeGage.draw == 0) {
8940 return;
8941 }
8942
8943 if (((s32 *) SaveData->GetConfigData())[11] != 0) {
8944 return;
8945 }
8946
8947 x = EnemyLifeGage.x - 32;
8948 EnemyLifeGage.y = (EnemyLifeGage.y >> 1) << 1;
8949 width = (s32) (64.0f / EnemyLifeGage.life_max * EnemyLifeGage.life);
8950
8951 if (x >= 577 || x < 0) {
8952 return;
8953 }
8954
8955 if (EnemyLifeGage.y >= 481 || EnemyLifeGage.y < 0) {
8956 return;
8957 }
8958
8959 s32 top = EnemyLifeGage.y - 1;
8960
8961 border.x = x - 1;
8962 border.y = top;
8963 border.width = 66;
8964 border.height = 6;
8965 set2DSpriteC4(Vif1Packet, border, &ELifeB1, &ELifeB2, &ELifeB1, &ELifeB2);
8966
8967 s32 ground_top = EnemyLifeGage.y;
8968
8969 ground.x = x;
8970 ground.y = ground_top;
8971 ground.width = 64;
8972 ground.height = 4;
8973 set2DSpriteC4(Vif1Packet, ground, &ELifeN1, &ELifeN1, &ELifeN1, &ELifeN1);
8974
8975 s32 life_top = EnemyLifeGage.y;
8976
8977 life.x = x;
8978 life.y = life_top;
8979 life.width = width;
8980 life.height = 4;
8981 set2DSpriteC4(Vif1Packet, life, &ELife1, &ELife2, &ELife1, &ELife2);
8982}
8983
8984/* How long the lock-on cursor stays on screen, in frames. */
8985float targetCursorCnt;
8986
8987void DrawtargetCursor(float *world, float width, float height, float alpha) {
8988 int top_left[4];
8989 int bottom_right[4];
8990 CTexture *texture;
8991
8992 texture = TexManager.GetTexture("d01e04", -1);
8993 setbilinear(0);
8994 world[3] = 1.0f;
8995
8996 if (MGRotTransPers3DSprite(top_left, bottom_right, world, width, height, 0) != 0) {
8997 // The two corners arrive in the fixed-point screen space the sprite
8998 // calls take, so they come back to pixels here.
8999 top_left[0] -= 0x6C08;
9000 top_left[1] -= (GS_Y_OFFSET + 8);
9001 bottom_right[0] -= 0x6C08;
9002 bottom_right[1] -= (GS_Y_OFFSET + 8);
9003 top_left[0] >>= 4;
9004 top_left[1] >>= 3;
9005 bottom_right[0] >>= 4;
9006 bottom_right[1] >>= 3;
9007
9008 static int rate = (int) (16.0f * alpha);
9009
9010 set2DSprite(Vif1Packet, texture, CRect_i_(top_left[0], top_left[1], 0x10, 0x10), CRect_i_(0, 0x20, 0x10, 0x10), rate);
9011 set2DSprite(Vif1Packet, texture, CRect_i_(bottom_right[0], top_left[1], 0x10, 0x10), CRect_i_(0, 0, 0x10, 0x10), rate);
9012 set2DSprite(Vif1Packet, texture, CRect_i_(top_left[0], bottom_right[1], 0x10, 0x10), CRect_i_(0, 0x30, 0x10, 0x10), rate);
9013 set2DSprite(Vif1Packet, texture, CRect_i_(bottom_right[0], bottom_right[1], 0x10, 0x10), CRect_i_(0, 0x10, 0x10, 0x10), rate);
9014 }
9015
9016 setbilinear(1);
9017 DrawTargetLife();
9018}
9019
9020int SetNearLockOnTarget(int from, int nearest_only) {
9021 CUserStatus *status = UserStatus;
9022 sceVu0FVECTOR at;
9023 sceVu0FVECTOR towards;
9024 sceVu0FVECTOR pos[16];
9025 float dist[16];
9026 int found[16];
9027 float away;
9028 float rate;
9029 int place;
9030 int i;
9031 int count;
9032 int slot;
9033 int nearest;
9034 int other;
9035
9036 rate = CharaRangeRate(status);
9037
9038 CharaFrame->GetRotation(at);
9039
9040 // Declared here rather than with the rest: mwcc emits a local array's
9041 // template copy where the declaration stands, and retail's lands after
9042 // the two calls above, not before them. The slots still come out where
9043 // they do above, because everything ahead of these is still ahead of them.
9044 sceVu0FVECTOR forward = {0.0f, 0.0f, 1.0f, 1.0f};
9045 sceVu0FMATRIX unit;
9046 sceVu0FMATRIX turn;
9047 int order[16];
9048 int screen[4];
9049
9050 sceVu0UnitMatrix(unit);
9051 sceVu0RotMatrixY(turn, unit, at[1]);
9052 sceVu0ApplyMatrix(forward, turn, forward);
9053 sceVu0Normalize(forward, forward);
9054
9055 count = 0;
9056 sceVu0CopyVector(at, CharaFrame->position);
9057
9058 for (i = 0; i < 16; i++) {
9059 found[i] = -1;
9060 }
9061
9062 for (i = 0; i < 16; i++) {
9063 int on;
9064
9065 MonstorPicupInner[i] = 0.0f;
9066
9067 CMonstorUnit *monsters = NowMonstorUnit;
9068
9069 if (monsters->monster[i].state != 2) {
9070 continue;
9071 }
9072
9073 if (monsters->monster[i].hp <= 0) {
9074 continue;
9075 }
9076
9077 if (i >= 0 && i < 17) {
9078 on = monsters->monster[i].revealed;
9079 }
9080
9081 if (on == 0) {
9082 continue;
9083 }
9084
9085 if (monsters->monster[i].lockon_enabled == 0) {
9086 continue;
9087 }
9088
9089 monsters->chara[i][0].GetPosition(pos[i]);
9090
9091 away = DistVector(at, pos[i]);
9092
9093 if (!(away < NowMonstorUnit->monster[i].lock_range * rate)) {
9094 continue;
9095 }
9096
9097 towards[0] = pos[i][0] - at[0];
9098 towards[2] = pos[i][2] - at[2];
9099 towards[1] = 0.0f;
9100 towards[3] = 1.0f;
9101 sceVu0Normalize(towards, towards);
9102
9103 MonstorPicupInner[i] = sceVu0InnerProduct(forward, towards);
9104
9105 if (MonstorPicupInner[i] < 0.25f) {
9106 continue;
9107 }
9108
9109 found[count] = i;
9110 dist[count] = away;
9111 count++;
9112 }
9113
9114 if (count == 0) {
9115 LockOffTargte();
9116 return 0;
9117 }
9118
9119 // Split from the loop below: mwcc emits the initialisation where the
9120 // statement stands, which is ahead of the loop that clears order[].
9121 place = 0;
9122
9123 for (slot = 0; slot < 16; slot++) {
9124 order[slot] = -1;
9125 }
9126
9127 // The nearest one that is still free goes into each place in turn.
9128 for (; place < count; place++) {
9129 nearest = 0;
9130
9131 while (found[nearest] == -1) {
9132 nearest++;
9133 }
9134
9135 float best = dist[nearest];
9136
9137 for (other = 0; other < count; other++) {
9138 if (other == place) {
9139 continue;
9140 }
9141
9142 if (found[other] == -1) {
9143 continue;
9144 }
9145
9146 if (dist[other] < best) {
9147 best = dist[other];
9148 nearest = other;
9149 }
9150 }
9151
9152 order[place] = found[nearest];
9153 found[nearest] = -1;
9154 }
9155
9156 int target;
9157
9158 if (nearest_only == 0) {
9159 if (count == 1) {
9160 target = order[0];
9161 } else {
9162 if (from >= count) {
9163 from = 0;
9164 }
9165
9166 if (lockOnTargetNo == order[from]) {
9167 from++;
9168 }
9169
9170 if (from >= count) {
9171 from = 0;
9172 }
9173
9174 target = order[from];
9175 }
9176 } else {
9177 target = order[0];
9178 }
9179
9180 if (target == -1) {
9181 LockOffTargte();
9182 return 0;
9183 }
9184
9185 if (lockOnTargetNo == target && nearest_only == 0) {
9186 return count;
9187 }
9188
9189 if (target != -1) {
9190 NowMonstorUnit->chara[target][0].GetPosition(at);
9191 at[1] += NowMonstorUnit->chara[target][0].body_height;
9192 cursorFrame->SetPosition(at);
9193 lockOnTargetDraw = 1;
9194 targetCursorCnt = 8.0f;
9195 at[3] = 1.0f;
9196
9197 if (MGRotTransPers(screen, at, 0) != 0) {
9198 SetMonsterNameDrawFlag(1);
9199 MonsterNamePosSet((screen[0] - 0x6C00) >> 4, (screen[1] - GS_Y_OFFSET) >> 4);
9200 EnemyLifeGage.x = (screen[0] - 0x6C00) >> 4;
9201 EnemyLifeGage.y = ((screen[1] - GS_Y_OFFSET) >> 4) + 42;
9202 } else {
9203 SetMonsterNameDrawFlag(0);
9204 EnemyLifeGage.on = 0;
9205 }
9206
9207 if (lockOnTargetNo != target) {
9208 DngMes2.mes_made = -1;
9209 MonsterNameMake(NowMonstorUnit->monster[target].name_no);
9210 }
9211 }
9212
9213 lockOnTargetNo = target;
9214 return count;
9215}
9216
9217void setTargetCursor(int on) {
9218 CUserStatus *status = UserStatus;
9219 sceVu0FVECTOR target;
9220 sceVu0FVECTOR stood;
9221 sceVu0FVECTOR flat_stood;
9222 sceVu0FVECTOR flat_target;
9223 int screen[4];
9224 float width;
9225 float height;
9226 int keep;
9227
9228 float rate = CharaRangeRate(status);
9229
9230 if (on != 0) {
9231 keep = 1;
9232
9233 if (NowMonstorUnit->monster[lockOnTargetNo].state != 2 || NowMonstorUnit->monster[lockOnTargetNo].hp <= 0) {
9234 keep = 0;
9235 }
9236
9237 if (NowMonstorUnit->monster[lockOnTargetNo].lockon_enabled == 0) {
9238 keep = 0;
9239 }
9240
9241 sceVu0CopyVector(stood, CharaFrame->position);
9242 NowMonstorUnit->chara[lockOnTargetNo][0].GetPosition(target);
9243
9244 float away = DistVector(stood, target);
9245
9246 if (!(away < NowMonstorUnit->monster[lockOnTargetNo].lock_range * rate)) {
9247 keep = 0;
9248 }
9249
9250 // A monster the player stands well above stays locked on only while it is
9251 // near enough on the floor.
9252 if (NowMonstorUnit->monster[lockOnTargetNo].kind != MONSTER_KIND_NO_LOCK_ON) {
9253 sceVu0CopyVector(flat_stood, stood);
9254 sceVu0CopyVector(flat_target, target);
9255 flat_target[1] = 0.0f;
9256 flat_stood[1] = 0.0f;
9257
9258 if (DistVector(flat_stood, flat_target) <= 8.0f + NowMonstorUnit->monster[lockOnTargetNo].body_radius && !(stood[1] <= 10.0f + target[1])) {
9259 keep = 0;
9260 }
9261
9262 float drop = stood[1] - target[1];
9263
9264 drop = drop < 0.0f ? -drop : drop;
9265
9266 if (!(drop < 80.0f)) {
9267 keep = 0;
9268 }
9269 }
9270
9271 target[1] += 8.0f;
9272 target[3] = 1.0f;
9273
9274 if (NowMonstorUnit->monster[lockOnTargetNo].lockon_frame != 0) {
9275 sceVu0CopyVector(target, NowMonstorUnit->monster[lockOnTargetNo].lockon_position);
9276 }
9277
9278 sceVu0CopyVector(BtActStatus.target_position, target);
9279
9280 width = (12.0f + targetCursorCnt) * NowMonstorUnit->monster[lockOnTargetNo].lockon_scale_x;
9281 height = (6.0f + targetCursorCnt / 2.0f) * NowMonstorUnit->monster[lockOnTargetNo].lockon_scale_y;
9282
9283 if (NowMonstorUnit->monster[lockOnTargetNo].name_no > 0 && NowMonstorUnit->monster[lockOnTargetNo].kind != MONSTER_KIND_NO_LOCK_ON) {
9284 EnemyLifeGage.life_max = NowMonstorUnit->monster[lockOnTargetNo].max_hp;
9285 EnemyLifeGage.life = NowMonstorUnit->monster[lockOnTargetNo].hp;
9286 EnemyLifeGage.on = 1;
9287 EnemyLifeGage.x = 0x280;
9288 EnemyLifeGage.y = 0;
9289 }
9290
9291 target[1] += 10.0f;
9292 target[3] = 1.0f;
9293
9294 if (MGRotTransPers(screen, target, 0) != 0) {
9295 MonsterNameMake(NowMonstorUnit->monster[lockOnTargetNo].name_no);
9296 MonsterNamePosSet((screen[0] - 0x6C00) >> 4, (screen[1] - GS_Y_OFFSET) >> 4);
9297 EnemyLifeGage.x = (screen[0] - 0x6C00) >> 4;
9298 EnemyLifeGage.y = ((screen[1] - GS_Y_OFFSET) >> 4) + 42;
9299 SetMonsterNameDrawFlag(1);
9300 } else {
9301 SetMonsterNameDrawFlag(0);
9302 EnemyLifeGage.on = 0;
9303 }
9304
9305 DrawtargetCursor(BtActStatus.target_position, width, height, targetCursorCnt);
9306
9307 // Steve says something about the monster now and then, but only while the
9308 // player holds a weapon that talks to him.
9309 s16 weapon = NowWeaponHave->item_no;
9310
9311 if ((weapon == ITEM_WEAPON_STEVE || weapon == ITEM_WEAPON_SUPER_STEVE) && lockOnTargetFlag != 0 && NowMonstorUnit->monster[lockOnTargetNo].name_no > 0 && (int) (100.0f * (float) rand() / 2147483648.0f) < 3) {
9312 DngMessMan.SetSteevMes(NowMonstorUnit->monster[lockOnTargetNo].name_no * 10 + 4000);
9313 }
9314
9315 if (keep != 0) {
9316 if (targetCursorCnt > 0.0f) {
9317 targetCursorCnt -= 0.5f;
9318 } else {
9319 targetCursorCnt = 0.0f;
9320 }
9321 } else {
9322 if (targetCursorCnt < 8.0f) {
9323 targetCursorCnt += 0.25f;
9324 } else {
9325 SndSePlay(MENU_SOUND_REFUSE, -1, 0);
9326 targetCursorShiftNo = 0;
9327 targetCursorShiftRot = 0;
9328 lockOnTargetFlag = 0;
9329 lockOnTargetNo = -1;
9330 EnemyLifeGage.on = 0;
9331 return;
9332 }
9333 }
9334
9335 return;
9336 }
9337
9338 targetCursorShiftRot = SetNearLockOnTarget(0, 1);
9339}
9340
9341void unitBlowActionRot(float *velocity) {
9342 sceVu0FVECTOR rotation;
9343
9344 CharaFrame->GetRotation(rotation);
9345 rotation[1] = atan2f(velocity[0], velocity[2]);
9346 rotation[1] -= PI;
9347
9348 if (rotation[1] <= -PI) {
9349 rotation[1] += TWO_PI;
9350 }
9351
9352 CharaFrame->SetRotation(rotation[0], rotation[1], rotation[2]);
9353}
9354
9355float setUnitDamageColor(int hit) {
9356 static float dmgColor = 128.0f;
9357 static float dmgVec = 0.0f;
9358 static int dmgFlag;
9359
9360 if (hit != 0) {
9361 dmgFlag = 1;
9362 dmgVec = 0.0f;
9363 }
9364
9365 if (dmgFlag != 0) {
9366 dmgVec += EIGHTH_PI;
9367 dmgColor = 128.0f + 80.0f * sinf(dmgVec);
9368
9369 // The flash runs for three full turns of the sine and then stops.
9370 if (dmgVec >= 9.424778f) {
9371 dmgFlag = 0;
9372 dmgColor = 128.0f;
9373 }
9374 }
9375
9376 return dmgColor;
9377}
9378
9379/* How fast the ambient-colour animation runs. */
9380float unitAmbientAnime_Speed;
9381
9382/* How far through the ambient-colour animation the player's model is. */
9383float unitAmbientAnime_Count;
9384
9385/* How long the ambient-colour animation runs for, in frames. */
9386s32 unitAmbientAnime_Timer;
9387
9388/* Whether the ambient-colour animation is running on the player's model. */
9389s32 unitAmbientAnime_flag;
9390
9391void RsetUnitAmbientAnime() {
9392 unitAmbientAnime_flag = 0;
9393}
9394
9395void setUnitAmbientAnime(float speed, float time, float red, float green, float blue) {
9396 unitAmbientAnime_rgb[0] = red;
9397 unitAmbientAnime_rgb[1] = green;
9398 unitAmbientAnime_rgb[2] = blue;
9399 unitAmbientAnime_Count = 0;
9400 unitAmbientAnime_Speed = speed;
9401 unitAmbientAnime_Timer = (s32) time;
9402 unitAmbientAnime_flag = 1;
9403}
9404
9405int unitAmbientAnime(float *colour) {
9406 if (unitAmbientAnime_flag == 0) {
9407 return 0;
9408 }
9409
9410 colour[0] = 64.0f + unitAmbientAnime_rgb[0] * sinf(unitAmbientAnime_Count);
9411 colour[1] = 64.0f + unitAmbientAnime_rgb[1] * sinf(unitAmbientAnime_Count);
9412 colour[2] = 64.0f + unitAmbientAnime_rgb[2] * sinf(unitAmbientAnime_Count);
9413 colour[3] = 128.0f;
9414
9415 unitAmbientAnime_Count += PI / unitAmbientAnime_Speed;
9416
9417 if (unitAmbientAnime_Count > PI) {
9418 unitAmbientAnime_Timer--;
9419
9420 if (unitAmbientAnime_Timer <= 0) {
9421 unitAmbientAnime_flag = 0;
9422 } else {
9423 unitAmbientAnime_Count -= PI;
9424 unitAmbientAnime_Timer--;
9425 }
9426 }
9427
9428 return 1;
9429}
9430
9431int LoadStartLogo(int map) {
9432 char *dungeon_name[7] = {
9433 "dname00.img",
9434 "dname01.img",
9435 "dname02.img",
9436 "dname03.img",
9437 "dname04.img",
9438 "dname05.img",
9439 "dname06.img",
9440 };
9441 char *floor_texture[7] = {
9442 "floor00",
9443 "floor01",
9444 "floor02",
9445 "floor03",
9446 "floor04",
9447 "floor05",
9448 "floor06",
9449 };
9450 char *files[5];
9451 int size;
9452 int blocks;
9453
9454 // Only the one texture is loaded; the NULL after it ends the list.
9455 files[0] = NameExchg(dungeon_name[map], 0);
9456 files[1] = NULL;
9457 BtStartLogoBuffer.used = 0;
9458 size = LoadTempTexture(files, 8, (char *) BtStartLogoBuffer.base);
9459 blocks = (((size >> 6) + 1) << 6) >> 4;
9460 BtStartLogoBuffer.Alloc(blocks);
9461
9462 char *name = floor_texture[map];
9463
9464 TEX_Floor1 = TexManager.GetTexture(name, -1);
9465 strcpy(floor_name, name);
9466 return blocks;
9467}
9468
9469// clang-format off
9470/* The map info file each dungeon loads its floors from. */
9471char *MapInfoNameArea[7] = {
9472 "Cave of the Sacred Beast", "Forest of the Own", "Sunken Ship", "Shrine of Sun and Moon", "MoonOcean",
9473 "DarkHeven Castle", "Deamon Shaft",
9474};
9475// clang-format on
9476
9477void FloorTitleOn() {
9478 rogoAlphaA[2] = 0;
9479 rogoSwitch2 = 1;
9480 rogoY3 = -96;
9481 startCnt2 = 0;
9482}
9483
9484void SetMIniMapStatus(int on) {
9485 switch (on) {
9486 case 0:
9487 infoMapOld = infoMap;
9488 infoMap = 0;
9489 break;
9490 case 1:
9491 infoMap = infoMapOld;
9492 break;
9493 }
9494}
9495
9496void ResetStatusInfo() {
9497 BtActStatus.action_on = 0;
9498 BtActStatus.main_motion = -1;
9499 BtActStatus.hand_motion = -1;
9500 BtActStatus.motion_no = 0;
9501 BtActStatus.jumping = 0;
9502 BtActStatus.gauge_flash = 0;
9503 BtActStatus.recoil_frames = 0;
9504 BtActStatus.invincible_frames = 0;
9505 BtActStatus.charge_level = 0;
9506 BtActStatus.guard_mode = 0;
9507 BtActStatus.can_act = 1;
9508 BtActStatus.unk_066 = 1;
9509 BtActStatus.slow_walking = 0;
9510 BtActStatus.camera_hold = 0;
9511 BtActStatus.action_busy = 0;
9512 BtActStatus.movement_locked = 0;
9513 BtActStatus.action_no = 0;
9514 BtActStatus.frames_since_attack = 3600;
9515 BtActStatus.combo_window = 0;
9516 BtActStatus.combo_queued = 0;
9517 BtActStatus.move_power = 0.0f;
9518 BtActStatus.move_power_decay = 0.0f;
9519 BtActStatus.camera_shake_frames = 0;
9520 BtActStatus.refill_frames = 10;
9521 CMonUnitHold = 0;
9522 CEffectHold = 0;
9523 BtActStatus.hud_shake_frames = 0;
9524 BtActStatus.hud_shake_y = 0;
9525 BtActStatus.event_block_frames = 0;
9526}
9527
9528void ResetMovePower() {
9529 BtActStatus.move_power = 0.0f;
9530 BtActStatus.move_power_decay = 0.0f;
9531}
9532
9533void LoaderInit() {
9534 BufferAllClear();
9535 MGSetBGColor(32.0f, 96.0f, 12.0f, 128.0f);
9536 TexManager.Initialize(0x3FE0);
9537 TexManager.EnterTextureFile(texdata2);
9538 TexManager.LoadTextureBlock(-1, read_buffer);
9539
9540 CDbgMsg.texture_name = "dbgwork";
9541 CDbgMsg.x = 32;
9542 CDbgMsg.y = 16;
9543 CDbgMsg.width = 256;
9544 CDbgMsg.height = 224;
9545 CDbgMsg.alpha = 96;
9546 EdEventInfo.map_jump_bgm_play = true;
9547}
9548
9549int LoaderLoop() {
9550 char name[96];
9551 int i;
9552 int chosen = 0;
9553 static int nowCursor = 0;
9554
9555 CDbgMsg.length = sprintf(&CDbgMsg.text[CDbgMsg.length], "- MapInfomationFile Loader -\n");
9556
9557 for (i = 0; i < 7; i++) {
9558 strcpy(name, MapInfoNameArea[i]);
9559
9560 if (nowCursor == i) {
9561 CDbgMsg.length += sprintf(&CDbgMsg.text[CDbgMsg.length], ">>[%2d] %s\n", i + 1, name);
9562 } else {
9563 CDbgMsg.length += sprintf(&CDbgMsg.text[CDbgMsg.length], " [%2d] %s\n", i + 1, name);
9564 }
9565 }
9566
9567 if (GamePad.Down(PAD_UP) != 0 && nowCursor != 0) {
9568 nowCursor--;
9569 }
9570
9571 if (GamePad.Down(PAD_DOWN) != 0 && nowCursor != 6) {
9572 nowCursor++;
9573 }
9574
9575 if (GamePad.Down(PAD_START) != 0 || GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0) {
9576 selectMapNo = nowCursor;
9577 main_select_menu_no = nowCursor;
9578 MapJump(selectMapNo + 200, -1);
9579 MGSetBGColor(0.0f, 0.0f, 0.0f, 128.0f);
9580 chosen = 1;
9581 }
9582
9583 sceVif1PkCall(Vif1Packet, (u_long128 *) Vu_prog0f, 0);
9584 sceVif1PkTerminate(Vif1Packet);
9585 TexManager.ReloadTexture(Vif1Packet, 12);
9586 CDbgMsg.Draw();
9587 return chosen;
9588}
9589
9590void InitEyeCamera() {
9591 sceVu0FVECTOR pos;
9592
9593 viewAngleH__2 = CharaMain.GetRotation()->y;
9594 viewAngleV__2 = 0.0f;
9595 sceVu0CopyVector(pos, CharaMain.pos);
9596}
9597
9598void EyeCamera() {
9599 sceVu0FVECTOR pos;
9600 sceVu0FVECTOR ref;
9601 sceVu0FMATRIX rotation;
9602 sceVu0FMATRIX unit;
9603 float stick_x;
9604 float stick_y;
9605
9606 stick_x = GamePad.GetLXf();
9607 stick_y = -GamePad.GetLYf();
9608
9609 // The heading wraps at half a turn either way; the pitch stops short of
9610 // straight up and straight down.
9611 if (stick_x > 0.0f) {
9612 float rate = 0.02f;
9613
9614 viewAngleH__2 -= stick_x * rate;
9615
9616 if (viewAngleH__2 < -PI) {
9617 viewAngleH__2 += TWO_PI;
9618 }
9619 }
9620
9621 if (stick_x < -0.0f) {
9622 float rate = 0.02f;
9623
9624 viewAngleH__2 -= stick_x * rate;
9625
9626 if (viewAngleH__2 > PI) {
9627 viewAngleH__2 -= TWO_PI;
9628 }
9629 }
9630
9631 if (stick_y > 0.0f) {
9632 if (viewAngleV__2 < 0.65f) {
9633 float rate = 0.02f;
9634
9635 viewAngleV__2 += stick_y * rate;
9636 }
9637 }
9638
9639 if (stick_y < -0.0f) {
9640 if (viewAngleV__2 > -1.0f) {
9641 float rate = 0.02f;
9642
9643 viewAngleV__2 += stick_y * rate;
9644 }
9645 }
9646
9647 ref[0] = 0.0f;
9648 ref[1] = 0.0f;
9649 ref[2] = 10.0f;
9650 ref[3] = 0.0f;
9651
9652 sceVu0UnitMatrix(unit);
9653 sceVu0RotMatrixX(rotation, unit, viewAngleV__2);
9654 sceVu0RotMatrixY(rotation, rotation, viewAngleH__2);
9655 sceVu0ApplyMatrix(ref, rotation, ref);
9656 sceVu0CopyVector(pos, CharaMain.pos);
9657
9658 CUserStatus *status = UserStatus;
9659 float height = CharaHeight(status);
9660
9661 pos[1] += height - 1.5f;
9662 ref[0] += pos[0];
9663 ref[1] += pos[1];
9664 ref[2] += pos[2];
9665
9666 NowCamera__3->SetPos(pos);
9667 NowCamera__3->SetRef(ref);
9668}
CMainItemModel * models
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
s16 foot_sound
Definition collision.hpp:56
s16 ground_kind
Definition collision.hpp:55
void SetHeight(float height)
void AddDistance(float delta)
void SetFollow(float x, float y, float z)
void AddAngle(float delta)
void SetDistance(float distance)
virtual void Step(int steps)
void SetAngle(float angle)
void AddHeight(float delta)
void GetCameraMatrix(float(*matrix)[4])
Definition camera.cpp:153
void GetRef(float *ref)
Definition camera.cpp:234
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
float GetAngleH()
Definition camera.cpp:238
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
void SetSpeed(float speed)
Definition camera.cpp:222
void GetPos(float *pos)
Definition camera.cpp:230
CFrame * frame
virtual void GetPosition(float *out_position)
virtual void LoadPackData2(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int visual_type)
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
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)
void InitializeTexAnime(CTexAnimeData *data, int count)
void SetFootSoundID(int id)
virtual void Step()
void EventEnable(int on)
virtual void ShadowStep()
tagMOTION_TYPE motion_type
virtual void SetRotation(float x, float y, float z)
void FootSoundEnable(int on)
void TextureAnime(int step)
virtual void DrawShadow()
virtual void Initialize()
CFrame * shadow_frame
float motion_speed
virtual void Draw()
virtual void SetPosition(float x, float y, float z)
virtual void ClothStep(int step)
int CheckHitUser(float *position, int mask, float height)
COLLISION_HIT hit[96]
COLLISION_HIT * Get(int index)
void Draw()
Definition dispctrl.cpp:60
char * texture_name
Definition gameloop.cpp:164
char text[0x200]
Definition gameloop.cpp:167
void FadeInit(float start_rate)
Definition dispctrl.cpp:251
void FadeOutStart(float fade_speed)
Definition dispctrl.cpp:239
float GetRate()
Definition dispctrl.cpp:256
float FadeOut(sceVif1Packet *packet)
Definition dispctrl.cpp:260
float FadeIn(sceVif1Packet *packet)
Definition dispctrl.cpp:294
void FadeInStart(float fade_speed)
Definition dispctrl.cpp:245
void SetSteevMes(int first)
void SetStatus_Dry(float water_max, float water_before, float water_now)
int AddCollision(CCPoly *poly, int count, CBoxVu0 box)
CDungeonEvent * event
CDungeonEvent slot[64]
CDungeonEventData * SearchDataSlotPos2(float *position)
CDungeonEventData event[96]
void SetupEvent(CDungeonMap *map, int mode)
CDungeonEventData * SearchDataSlotPos(float *position)
ROOM_LINK_RESULT room_link[4]
void DrawFire(CFrameVu1 *frame, CCameraFollow *camera)
void DrawFireFreeStyle(CFrameVu1 *frame, CCameraFollow *camera)
MAP_TRAP_CIRCLE * DistTrapCircle()
void DrawItemBox(float *pos)
void DrawMapFreeStyle()
void DrawRaster(CFrameVu1 *frame)
TREASURE_BOX boxes[24]
void DrawWater(float *pos, int mute)
void DrawBGModel(CCamera *camera)
CFireOmni fire
int CreateCollision(CCPoly *poly, CBoxVu0 box, int num)
MAP_CELL cells[400]
float draw_dist_scale
ATRA_BOLL atra[8]
CFrame * box_collision_model
DUNGEON_EVENT events[48]
void FlushCheckMask()
void DrawDummyModel(CCamera *camera)
int GetActiveIvent(CFrameVu1 *frame)
void DrawMap(CCameraFollow *camera, CFrameVu1 *player)
CFrame * collision_model
void DrawMiniMap(float *pos, float angle)
CFrame * atra_model
void DrawNPCDraw()
void StepTrapCircle()
void buildEventData(int floor_no, int enabled, int place_atla)
CDungeonParts parts[72]
void RsetMimicEvent()
void checkMask(float x, float z)
void DrawMapCalc(int mode)
void DrawTrapCircle()
void buildRandomMap(int room_max, int first_build)
void DrawAtraBoll(float *pos)
CFrame * camera_collision
float frame_offset[5][4]
float frame_turn[6]
CFrame * frame[6]
void RasterStep()
Definition fireomni.cpp:197
char clip_enable
Definition frame.hpp:29
float clip_depth
Definition frame.hpp:28
char program_option
Definition frame.hpp:32
char fog_enable
Definition frame.hpp:33
sceVu0FMATRIX local
Definition frame.hpp:74
sceVu0FVECTOR position
Definition frame.hpp:76
int On(int mask)
Definition gamepad.cpp:557
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
float GetLXf()
Definition gamepad.cpp:541
float GetLYf()
Definition gamepad.cpp:545
void SetVibration(int motor, int intensity, int duration)
Definition gamepad.cpp:621
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 Draw()
Definition hitmark.cpp:50
void Initialize()
Definition hitmark.cpp:177
virtual void Step()
Definition hitmark.cpp:140
void Set(float *position, float *direction, int kind, float spread, float shrink, float gravity, float speed, int count, float floor_y)
Definition hitmark.cpp:16
float pos[4]
Definition hitmark.hpp:95
void Draw()
Definition hitvalue.cpp:235
CFrame * frame
Definition hitvalue.hpp:30
void Step()
Definition hitvalue.cpp:283
void Draw(CCamera *camera)
void DeleteModel(int model_no)
int SetHandModel(int source_no)
int SetThrowModel(int source_no, float *position, float *heading)
void LoopStep(int interval)
void DrawMapSymbol(float *offset)
void DrawMonstorCursor()
void DrawShadowMonstor()
CFrame * collision
int SetupBaseModel(int slot, int model_no, int texture_block, CDataAlloc2< 1 > *alloc)
CDataAlloc2< 1 > * script[16]
void ArrangementPos(CDungeonMap *map, int count, int model_no, int unused)
CMonstorChara chara[16]
int CheckEventFlag2()
void Step(int pause)
void CleanViewMonstor(int back_floor)
MONSTOR monster[16]
void MoveCheck(float *position, float *movement, int flat)
CFrame * frame
void LoadPack(unsigned int *pack, char *base_name, CDataAlloc2< 1 > *model_arena, CDataAlloc2< 1 > *motion_arena, MOTION_INFO *motion_info, int initialize_frames)
virtual void Step()
virtual void DrawShadow()
virtual void Draw()
virtual void ShadowStep()
virtual void GetRotation(float *out_rotation)
Definition object.cpp:116
float pos[4]
Definition object.hpp:18
int CheckPosition()
void MapSymbolDraw()
int checkEvent()
CTexture * gold_texture
s32 pickup_blocked[32]
s32 pickup_event[32]
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
void Step()
void Set(float *position)
void Draw()
CSHOT_EFFECT effect[5]
void SetVsMonster(char *effectiveness)
void SetWepStatus(int status)
int ReEntry(BT_SHOT_EFFECT *description, CDataAlloc2< 1 > *allocator)
void SetDmg(int damage)
void OffEffect(int slot)
void SetRandomRate(float rate)
void SetLoop(int loop)
int Entry2(BT_SHOT_EFFECT *description, unsigned int *pack, int tex_block, CDataAlloc2< 1 > *allocator, int slots)
void SetAttribute(int attribute)
int Set(float *position, float *target, int owner, int sub_id, int source, CFrame *parent, int initial_phase)
int Init(float *origin, float *direction, int collision_damage, int element)
int Set(float *origin, float *direction, int collision_damage, int element)
int Set(float *origin, float *direction, int damage, int element)
void step()
s32 damage[12]
float size[12]
void draw()
s32 halted[12]
s32 used[12]
s32 life[12]
sceVu0FVECTOR vector[12]
sceVu0FVECTOR pos[12]
s32 start_flag[12]
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
void * GetConfigData()
Definition savedata.cpp:33
void AddNowTime(float add)
Definition savedata.cpp:65
void Draw(CCamera *camera)
void Initialize(CFrameVu1 *model)
Definition stealitem.cpp:15
int checkEvent()
void Draw()
void Step()
Definition stealitem.cpp:47
void Initialize(CTexAnimeData *records, int count)
void TexAnime(int texture_block)
u_long tex0
Definition texture.hpp:57
s16 max_hp[6]
void ClearEventFlag()
s32 water_drain_disable
s32 ailments[6]
s16 active_item[3]
float water_max[6]
float water_now[6]
void AddNowLife(int chara_no, s16 amount, float ratio)
s8 floor_reached[7]
WEAPON_HAVE chara_weapons[6][11]
s16 ailment_frames[6]
s32 active_item_vol[3]
s8 equipped_weapon_slot[6]
s32 res_limit_zone_current
ATRA_SAVE atra_registry[6][100]
void Step(int mode)
void InitSet(CFrame *frame, char *root_name, char *tip_name)
spRGBA colour[4]
s32 used[WEAPON_EFFECT_STEP_MAX]
Definition wind.hpp:12
s32 text_rows
Definition clsmes.hpp:158
s32 auto_pos
Definition clsmes.hpp:172
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
s32 tail_on
Definition clsmes.hpp:173
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
s32 char_height
Definition clsmes.hpp:154
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
s32 page_from
Definition clsmes.hpp:199
s32 page_arrow
Definition clsmes.hpp:209
float fade_speed
Definition clsmes.hpp:186
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 centre_rows
Definition clsmes.hpp:211
s32 fade_in
Definition clsmes.hpp:188
s32 space_width
Definition clsmes.hpp:222
s32 clut_now
Definition clsmes.hpp:203
void AutoSet(int *pos)
Definition clsmes.cpp:173
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 columns
Definition clsmes.hpp:155
s32 mes_made
Definition clsmes.hpp:207
s32 values[8]
Definition clsmes.hpp:217
s32 style
Definition clsmes.hpp:208
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
CDataAlloc2< 1 > * WorkBuffer__2
Definition dataread.hpp:250
@ TREASURE_BOX_LARGE
@ DNG_EVENT_ATRA
@ DNG_EVENT_TREASURE_BOX
@ DNG_EVENT_MIMIC
@ DNG_EVENT_NONE
@ TRAP_CIRCLE_WHP_CURE
@ TRAP_CIRCLE_MONEY_UP
@ TRAP_CIRCLE_ABS_FULL
@ TRAP_CIRCLE_STAT_DOWN
@ TRAP_CIRCLE_WHP_DOWN
@ TRAP_CIRCLE_WHP_QUARTER
@ TRAP_CIRCLE_STAMINA
@ TRAP_CIRCLE_WHP_UP
@ TRAP_CIRCLE_MONEY_DOWN
@ TRAP_CIRCLE_ALL_MONSTER_STAMINA
@ ED_EVENT_RETURN_MAP_JUMP
Definition edit.hpp:18
@ FONT_COLOR_WHITE
Definition gameutil.hpp:15
@ INTERPOLATE_STEP
Definition mathutil.hpp:15
s32 throw_step
Definition gameloop.cpp:149
sceVu0FVECTOR pos
Definition gameloop.cpp:146
sceVu0FVECTOR target_position
float jump_velocity_z
float move_power_decay
sceVu0FVECTOR input_direction
float jump_velocity_y
sceVu0FVECTOR move_vector
float camera_shake_offset
float jump_velocity_x
float camera_shake_decay
BT_ENEMY_LAYOUT monster[9]
sceVu0FVECTOR direction
Definition gameloop.hpp:138
s32 no_status_recover
Definition gameloop.hpp:162
s32 clear_script_ext_memory
Definition gameloop.hpp:157
sceVu0FVECTOR position
Definition gameloop.hpp:137
RS_STACKDATA * escape_result
Definition gameloop.hpp:150
RS_STACKDATA * entrance_result
Definition gameloop.hpp:149
s32 running_script_no
Definition gameloop.hpp:143
s32 chained_script_no
Definition gameloop.hpp:155
sceVu0FVECTOR pos
sceVu0FVECTOR base_point
sceVu0FVECTOR velocity
CDranMapField field[12]
CFrame * collision[12]
s32 player_draw
Definition edit.hpp:164
s32 npc_stop[16]
Definition edit.hpp:173
s32 npc_draw[16]
Definition edit.hpp:170
s32 npc_shadow_draw[16]
Definition edit.hpp:171
sceVu0FVECTOR screen_filter_color
Definition edit.hpp:206
s32 player_stop
Definition edit.hpp:167
CTexAnimeData * main_texture_animation
Definition edit.hpp:160
s32 screen_filter
Definition edit.hpp:204
float projection
Definition edit.hpp:155
s32 map_jump_bgm_stop
Definition edit.hpp:152
s32 player_shadow_draw
Definition edit.hpp:165
CFrameVu1 * item_frame[1]
Definition edit.hpp:189
s32 map_jump_bgm_play
Definition edit.hpp:153
s32 return_code
Definition edit.hpp:217
CFrame * frame
Definition gameloop.cpp:205
CCamera * camera
Definition gameloop.cpp:206
s32 direction
float camera_dist
float lockon_scale_y
sceVu0FVECTOR lockon_position
s16 lockon_enabled
float body_radius
CFrame * lockon_frame
float lockon_scale_x
s32 stolen_money
s32 last_hit_damage
CFrameVu1 * look_frame
Definition gameutil.hpp:198
_FRAMECONSTRAINT look_constraint
Definition gameutil.hpp:201
sceVu0FVECTOR look_position
Definition gameutil.hpp:200
sceVu0FVECTOR ground_point
Definition gameutil.hpp:475
sceVu0FVECTOR pos
float durability_f
Definition itemdata.hpp:695
char vs_monster[10]
Definition itemdata.hpp:699
u8 b
Definition rect.hpp:48
u8 g
Definition rect.hpp:47
u8 r
Definition rect.hpp:46
MOTION_INFO * motion_info
Definition gameutil.hpp:275
MOTION_STATE state
Definition gameutil.hpp:273
@ WEAPON_ELEMENT_NONE