DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
btsysscript.cpp
1#include "btsysscript.hpp"
2
3#include <cmath>
4#include <cstdio>
5#include <cstring>
6
7#include "btactstatus.hpp"
8#include "btitem.hpp"
9#include "btmisc.hpp"
10#include "camera.hpp"
11#include "camerafollow.hpp"
12#include "clsmes.hpp"
13#include "collisiondata.hpp"
14#include "dataalloc.hpp"
15#include "dataread.hpp"
16#include "dngstatusdata.hpp"
17#include "dun/gameloop.hpp"
18#include "dungeoneventman.hpp"
19#include "dungeonmap.hpp"
20#include "dungeonparts.hpp"
21#include "editloop.hpp"
22#include "editloop3.hpp"
23#include "frame.hpp"
24#include "itembombeffect.hpp"
25#ifdef PAL
26#include "mainselect.hpp"
27#endif
28#include "mathutil.hpp"
29#include "menu_dungeon.hpp"
30#include "menu_misc.hpp"
31#include "monstorunit.hpp"
32#include "nowload.hpp"
33#include "npcharacter.hpp"
34#include "runscript.hpp"
35#include "savedata.hpp"
36#include "shot_freefuncs.hpp"
37#include "snd.hpp"
38#include "userstatus.hpp"
39
40BT_EVENT_INFO BtEventInfo;
41BT_OBJ_HANDLE BtObjHdl[32];
42char BtLoadMapFileName[32];
43int BtMapJumpFloor;
44s32 BtLoadMapType;
45
46void BtSystemScriptEventInfoInit() {
47 BtEventInfo.script_no = -1;
48 BtEventInfo.running_script_no = -1;
49 BtEventInfo.init_flag_28 = 1;
50 BtEventInfo.ext_memory = false;
51 BtEventInfo.init_flag_20 = 1;
52 BtEventInfo.item_select_result = 0;
53 BtEventInfo.entrance_result = NULL;
54 BtEventInfo.escape_result = NULL;
55 BtEventInfo.request = BT_REQUEST_NONE;
56 BtEventInfo.chained_script_no = -1;
57 BtEventInfo.clear_script_no = -1;
58 BtEventInfo.clear_script_ext_memory = 0;
59 BtEventInfo.script_main_chr = -1;
60 BtEventInfo.floor_title_off = 0;
61 BtEventInfo.bee_npc = -1;
62 BtEventInfo.fade_on_start = true;
63 BtEventInfo.no_status_recover = 0;
64 EdEventInfo.projection = -1.0f;
65 EdEventInfo.main_character = &CharaMain;
66
67 for (int i = 0; i < 6; i++) {
68 NPCUnit[i].frame = NULL;
69 }
70
71 EdEventInfo.npcs = NPCUnit;
72 EdEventInfo.npc_texture_block = 32;
73 EdEventInfo.player_texture_block = 17;
74 EdEventInfo.npc_count = 6;
75 EdEventInfo.villagers = NULL;
76
77 for (int i = 0; i < 8; i++) {
78 EdEventInfo.messages[i] = NULL;
79 }
80
81 EdEventInfo.messages[1] = &BtEventMes0;
82 EdEventInfo.messages[2] = &BtEventMes1;
83 EdEventAllClear();
84}
85
86BT_OBJ_HANDLE *GetObjHDL(int index) {
87 if (index < 0 || index >= 32) {
88 printf("** obj hdl err **\n");
89 return NULL;
90 }
91
92 return &BtObjHdl[index];
93}
94
95void BtSystemScriptLoad(int floor) {
96#ifdef PAL
97 char path[32];
98 char mes_path[40];
99 int read_size;
100 int mes_size;
101 char *mes;
102
103 sprintf(path, "dun/script/d0%d/event.stb", floor + 1);
104 sprintf(mes_path, "dun/script/d0%d/d0%d_%d.mes", floor + 1, floor + 1, LanguageCode);
105 BtSystemScriptFileBuffer.used = 0;
106 BtEventData = (s32) (BtSystemScriptFileBuffer.base + BtSystemScriptFileBuffer.used * 0x10);
107 LoadFile(path, (void *) BtEventData, &read_size);
108 wait_now_loading_vsync();
109 BtSystemScriptFileBuffer.Alloc((read_size >> 4) + 1);
110 mes = (char *) (BtSystemScriptFileBuffer.base + BtSystemScriptFileBuffer.used * 0x10);
111 LoadFile(mes_path, mes, &mes_size);
112 wait_now_loading_vsync();
113 BtSystemScriptFileBuffer.Alloc((mes_size >> 4) + 1);
114 EdSetEventScript((char *) BtEventData, mes, &BtSystemScriptFileBuffer);
115 AddSystemEventScript();
116#else
117 char path[44];
118 int read_size;
119
120 sprintf(path, "dun/script/d0%d/event.stb", floor + 1);
121 BtSystemScriptFileBuffer.used = 0;
122 BtEventData = (s32) (BtSystemScriptFileBuffer.base + BtSystemScriptFileBuffer.used * 0x10);
123 LoadFile(path, (void *) BtEventData, &read_size);
124 wait_now_loading_vsync();
125 BtSystemScriptFileBuffer.Alloc((read_size >> 4) + 1);
126 EdSetEventScript((char *) BtEventData, NULL, &BtSystemScriptFileBuffer);
127 AddSystemEventScript();
128#endif
129}
130
131void BtSystemScriptInit() {
132 sceVu0FVECTOR pos;
133 sceVu0FVECTOR ref;
134 float text_rate;
135
136 BtEventMode = 1;
137 BtAllClear = 1;
138 NowCamera__3->GetPos(pos);
139 NowCamera__3->GetRef(ref);
140 SubCamera.FollowOff();
141 SubCamera.SetPos(pos);
142 SubCamera.SetRef(ref);
143 SubCamera.Step(-1);
144 NowCamera__3 = &SubCamera;
145 NowCamera__3->FollowOff();
146 CUserStatus *status = UserStatus;
147 status->step_disable = 1;
148 EdEventInfo.projection = -1.0f;
149 EdEventInfo.camera = NowCamera__3;
150 EdEventInfo.main_character = &CharaMain;
151
152 for (int i = 0; i < 6; i++) {
153 NPCUnit[i].frame = NULL;
154 }
155
156 EdEventInfo.npcs = NPCUnit;
157 EdEventInfo.npc_texture_block = 32;
158 EdEventInfo.player_texture_block = 17;
159 EdEventInfo.npc_count = 6;
160 EdEventInfo.villagers = NULL;
161
162 for (int i = 0; i < 8; i++) {
163 EdEventInfo.messages[i] = NULL;
164 }
165
166 EdEventInfo.messages[1] = &BtEventMes0;
167 EdEventInfo.messages[2] = &BtEventMes1;
168 EDIT_CONFIG_VIEW *config = (EDIT_CONFIG_VIEW *) SaveData->GetConfigData();
169
170 if (config->message_speed != 0) {
171 text_rate = 0.6f;
172 } else {
173 text_rate = 0.3f;
174 }
175
176 EdEventInfo.messages[1]->text_rate = text_rate;
177 EdEventInfo.messages[2]->text_rate = text_rate;
178 EdEventInfo.messages[1]->text_rate_set = text_rate;
179 EdEventInfo.messages[2]->text_rate_set = text_rate;
180
181 if (BtEventInfo.fade_on_start != 0) {
182 EdFadeInit();
183 }
184
185 BtEventInfo.fade_on_start = true;
186
187 for (int i = 0; i < 32; i++) {
188 BtObjHdl[i].frame = NULL;
189 BtObjHdl[i].character = NULL;
190 }
191
192 BtEventInfo.event_marker = false;
193 BtEventInfo.floor_title_off = 0;
194 BtEventInfo.no_reset_chara = 0;
195 BtActStatus.motion_no = 0;
196 BtActStatus.main_motion = -1;
197 BtActStatus.hand_motion = -1;
198 BtActStatus.action_no = 0;
199 BtActStatus.action_on = 0;
200 BtActStatus.unk_028 = 0;
201}
202
203void BtSystemScriptAfter() {
204 sceVu0FVECTOR pos;
205 sceVu0FVECTOR ref;
206
207 BtEventMode = 0;
208 BtAllClear = 0;
209 BtEventInfo.running_script_no = -1;
210 SetMIniMapStatus(1);
211 CharaMain.SetMotion(0, 0);
212 BtActStatus.motion_no = 0;
213 BtActStatus.main_motion = -1;
214 BtActStatus.hand_motion = -1;
215 BtActStatus.player_visible = 1;
216 BtActStatus.weapon_visible = 1;
217 BtActStatus.shadow_visible = true;
218 EdEventInfo.player_shadow_draw = true;
219 EdEventInfo.player_draw = true;
220 EdEventAllClear();
221 UserStatus->step_disable = 0;
222 BtMapJumpFloor = -1;
223
224 if (EdEventInfo.reset_camera_angle > 0) {
225 sceVu0CopyVector(pos, CharaMain.pos);
226 CharaMain.GetRotation(ref);
227 float angle = ref[1] + EdEventInfo.reset_camera_yaw;
228
229 if (!(angle <= PI_SHORT)) {
230 angle -= TWO_PI;
231 }
232
233 MainCamera__4.SetAngleSoon(angle);
234 MainCamera__4.SetFollow(pos[0], pos[1] + 16.0f - 3.0f, pos[2]);
235 MainCamera__4.Step(-1);
236 }
237
238 if (EdEventInfo.reset_camera_angle < 0) {
239 SubCamera.GetPos(pos);
240 SubCamera.GetRef(ref);
241 MainCamera__4.FollowOff();
242 MainCamera__4.SetPos(pos);
243 MainCamera__4.SetRef(ref);
244 MainCamera__4.Step(-1);
245 MainCamera__4.Step(1);
246 MainCamera__4.FollowOn();
247 MainCamera__4.SetHeight(pos[1] - ref[1]);
248 MainCamera__4.SetFollow(ref[0], ref[1], ref[2]);
249 MainCamera__4.SetAngleSoon(atan2(pos[0] - ref[0], pos[2] - ref[2]));
250 MainCamera__4.Step(-1);
251 MainCamera__4.Step(1);
252 }
253
254 NowCamera__3 = &MainCamera__4;
255}
256
257int BtSystemScriptRun(int event, CDataAlloc2<1> *arena) {
258 return EdEventInit(event, arena, (char *) BtEventData);
259}
260
261void BtSetMapJumpFloor(int floor) {
262 BtMapJumpFloor = floor;
263}
264
273static int GetStackInt(RS_STACKDATA *argument) {
274 if (argument->type == RS_FLOAT) {
275 return (int) argument->f;
276 }
277
278 return argument->i;
279}
280
289static float GetStackFloat(RS_STACKDATA *argument) {
290 if (argument->type == RS_INT) {
291 return (float) argument->i;
292 }
293
294 return argument->f;
295}
296
305static char *GetStackString(RS_STACKDATA *argument) {
306 return argument->s;
307}
308
317static void SetStack(RS_STACKDATA *argument, int value) {
318 if (argument->type == RS_PTR) {
319 argument->p->i = value;
320 }
321}
322
331static void SetStack(RS_STACKDATA *argument, float value) {
332 if (argument->type == RS_PTR) {
333 argument->p->f = value;
334 }
335}
336
337int _GET_FLOOR_LEVEL(RS_STACKDATA *stack, int argument_count) {
338 SetStack(stack, UserStatus->cur_floor);
339 return 1;
340}
341
342int _SET_FLOOR_LEVEL(RS_STACKDATA *stack, int argument_count) {
343 ((CDngStatusData *) UserStatus)->SetNowFloor(GetStackInt(stack));
344 return 1;
345}
346
347int _GET_OLD_FLOOR_LEVEL(RS_STACKDATA *stack, int argument_count) {
348 SetStack(stack, UserStatus->prev_floor);
349 return 1;
350}
351
352int _GET_ACTION_MODE(RS_STACKDATA *stack, int argument_count) {
353 SetStack(stack, BtEventInfo.action_mode);
354 return 1;
355}
356
357int _ITEM_USE_WINDOW(RS_STACKDATA *stack, int argument_count) {
358 if (stack->type != RS_PTR) {
359 return 0;
360 }
361
362 BtEventInfo.item_select_result = (s32) stack->p;
363 stack++;
364 int i;
365
366 for (i = 0; i < argument_count - 1; i++) {
367 BtEventInfo.item_select_list[i] = GetStackInt(stack++);
368 }
369
370 BtEventInfo.item_select_filtered = false;
371
372 if (argument_count > 1) {
373 BtEventInfo.item_select_filtered = true;
374 }
375
376 BtEventInfo.item_select_list[i] = -1;
377 BtEventInfo.request = BT_REQUEST_ITEM_WINDOW;
378 return 1;
379}
380
381int _CHECK_EVENT_FLG(RS_STACKDATA *stack, int argument_count) {
382 int flag_no = GetStackInt(stack++);
383 int flag = UserStatus->ChkEventFlag(flag_no);
384 SetStack(stack, flag);
385 return 1;
386}
387
388int _SET_EVENT_FLG(RS_STACKDATA *stack, int argument_count) {
389 int flag_no = GetStackInt(stack++);
390 int value = GetStackInt(stack);
391 CUserStatus *status = UserStatus;
392
393 if (flag_no >= 0 && flag_no < 50) {
394 status->event_flags[flag_no] = value;
395 }
396
397 return 1;
398}
399
400int _GET_OBJHDL(RS_STACKDATA *stack, int argument_count) {
401 int index = GetStackInt(stack++);
402 int parts_no = GetStackInt(stack++);
403 char *name = GetStackString(stack);
404 BT_OBJ_HANDLE *handle = GetObjHDL(index);
405
406 if (parts_no != -1) {
407 CDungeonMap *map = NowDngMap;
408 CFrame *frame = map->parts[parts_no].GetSearchFrame(name);
409
410 if (frame != NULL) {
411 handle->frame = frame;
412 handle->type = 0;
413 } else {
414 printf("******** Frame NotFount %s *******\n", name);
415 handle->frame = NULL;
416 handle->type = 0;
417 }
418 } else {
419 CFrame *frame = NowDngMap->GetFrameSearch(name);
420
421 if (frame != NULL) {
422 handle->frame = frame;
423 handle->type = 0;
424 } else {
425 printf("******** All Frame NotFount %s *******\n", name);
426 handle->frame = NULL;
427 handle->type = 0;
428 }
429 }
430
431 return 1;
432}
433
434int _SET_OBJHDL_POS(RS_STACKDATA *stack, int argument_count) {
435 int index = GetStackInt(stack++);
436 float x = GetStackFloat(stack++);
437 float y = GetStackFloat(stack++);
438 float z = GetStackFloat(stack);
439 BT_OBJ_HANDLE *handle = GetObjHDL(index);
440
441 if (handle->type == 0 && handle->frame != NULL) {
442 handle->frame->SetPosition(x, y, z);
443 }
444
445 if (handle->type == 1 && handle->character != NULL) {
446 handle->character->SetPosition(x, y, z);
447 }
448
449 return 1;
450}
451
452int _SET_OBJHDL_ROT(RS_STACKDATA *stack, int argument_count) {
453 int index = GetStackInt(stack++);
454 float x = GetStackFloat(stack++);
455 float y = GetStackFloat(stack++);
456 float z = GetStackFloat(stack);
457 BT_OBJ_HANDLE *handle = GetObjHDL(index);
458
459 if (handle->type == 0) {
460 CFrame *frame = handle->frame;
461
462 if (frame != NULL) {
463 frame->SetRotType(2);
464 frame->SetRotation(AngleLimit(x), AngleLimit(y), AngleLimit(z));
465 }
466 }
467
468 if (handle->type == 1) {
469 CCharacter *chara = handle->character;
470
471 if (chara != NULL) {
472 chara->SetRotation(AngleLimit(x), AngleLimit(y), AngleLimit(z));
473 }
474 }
475
476 return 1;
477}
478
479int _SET_OBJHDL_DRAW_FLAG(RS_STACKDATA *stack, int argument_count) {
480 int index = GetStackInt(stack++);
481 int draw = GetStackInt(stack);
482 BT_OBJ_HANDLE *handle = GetObjHDL(index);
483
484 if (handle->type == 0) {
485 CFrame *frame = handle->frame;
486
487 if (frame != NULL) {
488 int draw_on = 2;
489
490 if (draw) {
491 draw_on = 1;
492 }
493
494 frame->attr.draw_on = draw_on;
495 frame->flags = draw_on;
496 }
497 }
498
499 if (handle->type == 1) {
500 CCharacter *chara = handle->character;
501
502 if (chara != NULL) {
503 CFrame *frame = chara->frame;
504
505 if (frame != NULL) {
506 int draw_on = 2;
507
508 if (draw) {
509 draw_on = 1;
510 }
511
512 frame->attr.draw_on = draw_on;
513 }
514 }
515 }
516
517 return 1;
518}
519
520int _GET_OBJHDL_POS(RS_STACKDATA *stack, int argument_count) {
521 sceVu0FVECTOR local = {0.0f, 0.0f, 0.0f, 0.0f};
522 sceVu0FVECTOR pos;
523 BT_OBJ_HANDLE *handle = GetObjHDL(GetStackInt(stack++));
524
525 if (handle->type == 0) {
526 CFrame *frame = handle->frame;
527
528 if (frame != NULL) {
529 frame->GetWorldPosition(pos, local);
530 }
531 }
532
533 if (handle->type == 1) {
534 CCharacter *chara = handle->character;
535
536 if (chara != NULL) {
537 chara->GetPosition(pos);
538 }
539 }
540
541 SetStack(stack++, pos[0]);
542 SetStack(stack++, pos[1]);
543 SetStack(stack, pos[2]);
544 return 1;
545}
546
547int _GET_OBJHDL_ROT(RS_STACKDATA *stack, int argument_count) {
548 sceVu0FVECTOR rot = {0.0f, 0.0f, 0.0f, 1.0f};
549 sceVu0FMATRIX matrix;
550 BT_OBJ_HANDLE *handle = GetObjHDL(GetStackInt(stack++));
551
552 if (handle->type == 0) {
553 CFrame *frame = handle->frame;
554
555 if (frame != NULL) {
556 frame->GetLWMatrix(matrix);
557 rot[0] = 0.0f;
558 rot[1] = atan2f(matrix[2][0], matrix[2][2]);
559 rot[2] = 0.0f;
560 rot[3] = 1.0f;
561 }
562 }
563
564 if (handle->type == 1) {
565 CCharacter *chara = handle->character;
566
567 if (chara != NULL) {
568 chara->GetRotation(rot);
569 }
570 }
571
572 SetStack(stack++, rot[0]);
573 SetStack(stack++, rot[1]);
574 SetStack(stack, rot[2]);
575 return 1;
576}
577
578int _SET_URA_DUNGEON(RS_STACKDATA *stack, int argument_count) {
579 BtEventInfo.request = BT_REQUEST_URA_DUNGEON;
580 return 1;
581}
582
583int _GET_EVENT_POS(RS_STACKDATA *stack, int argument_count) {
584 SetStack(stack++, BtEventInfo.position[0]);
585 SetStack(stack++, BtEventInfo.position[1]);
586 SetStack(stack, BtEventInfo.position[2]);
587 return 1;
588}
589
590int _GET_EVENT_ROT(RS_STACKDATA *stack, int argument_count) {
591 SetStack(stack++, BtEventInfo.direction[0]);
592 SetStack(stack++, BtEventInfo.direction[1]);
593 SetStack(stack, BtEventInfo.direction[2]);
594 return 1;
595}
596
597int _OPEN_ENTRANCE_WINDOW(RS_STACKDATA *stack, int argument_count) {
598 if (stack->type != RS_PTR) {
599 return 0;
600 }
601
602 BtEventInfo.entrance_result = stack->p;
603 BtEventInfo.request = BT_REQUEST_ENTRANCE_WINDOW;
604 return 1;
605}
606
607int _OPEN_ESCAPE_WINDOW(RS_STACKDATA *stack, int argument_count) {
608 if (stack->type != RS_PTR) {
609 return 0;
610 }
611
612 BtEventInfo.escape_result = stack->p;
613 BtBattleMusic_Stop();
614 BtEventInfo.request = BT_REQUEST_ESCAPE_WINDOW;
615 return 1;
616}
617
618int _GO_DUNGEON(RS_STACKDATA *stack, int argument_count) {
619 BtEventInfo.request = BT_REQUEST_GO_DUNGEON;
620 return 1;
621}
622
623int _SET_DUNGEON_MAP(RS_STACKDATA *stack, int argument_count) {
624 char *map_file = GetStackString(stack++);
625 BtLoadMapType = GetStackInt(stack);
626 strcpy(BtLoadMapFileName, map_file);
627 MainDungeonMap.map_type = BtLoadMapType;
628 return 1;
629}
630
631int _LOAD_DUNGEON_MAP2(RS_STACKDATA *stack, int argument_count) {
632 CUserStatus *status = UserStatus;
633 status->res_limit_zone_current = RES_LIMIT_ZONE_NONE;
634 BtMapJumpLoad(BtLoadMapFileName);
635 return 1;
636}
637
638int _LOAD_MONSTOR(RS_STACKDATA *stack, int argument_count) {
639 BtLoadMonstor(0);
640 BtArrengeMonstor();
641 return 1;
642}
643
644int _SET_RANDOM_MAP(RS_STACKDATA *stack, int argument_count) {
645 if (NowDngMap->map_type == 1) {
646 BtCleatRandomMap();
647 } else {
648 BtCleatFreeMap();
649 }
650
651 return 1;
652}
653
654int _SET_EVENT_SW(RS_STACKDATA *stack, int argument_count) {
655 int script_no = GetStackInt(stack++);
656 NowEventMan->SearchDataSwitch(script_no, GetStackInt(stack));
657 return 1;
658}
659
660int _SET_MONSTOR_ID(RS_STACKDATA *stack, int argument_count) {
661 int model_no = GetStackInt(stack++);
662 int event_flag = -1;
663 float pos[3];
664
665 if (argument_count == 2) {
666 if (GetStackInt(stack++)) {
667 BtLoadMonstor(0);
668 NowMonstorUnit->CleanViewMonstor(0);
669 }
670 }
671
672 if (argument_count == 5) {
673 int clean = GetStackInt(stack++);
674 pos[0] = GetStackFloat(stack++);
675 pos[1] = GetStackFloat(stack++);
676 pos[2] = GetStackFloat(stack++);
677
678 if (clean) {
679 BtLoadMonstor(0);
680 NowMonstorUnit->CleanViewMonstor(0);
681 }
682 }
683
684 if (argument_count == 6) {
685 int clean = GetStackInt(stack++);
686 pos[0] = GetStackFloat(stack++);
687 pos[1] = GetStackFloat(stack++);
688 pos[2] = GetStackFloat(stack++);
689 event_flag = GetStackInt(stack);
690
691 if (clean) {
692 BtLoadMonstor(0);
693 NowMonstorUnit->CleanViewMonstor(0);
694 }
695 }
696
697 NowMonstorUnit->SetupViewMonstor(model_no, pos, event_flag);
698 return 1;
699}
700
701int _CHK_ATRA_HAVE(RS_STACKDATA *stack, int argument_count) {
702 int atra_no = GetStackInt(stack++);
703 int have = GetAtraTipNowHave(atra_no, UserStatus->cur_georama);
704
705 printf("%d,%d --> %d\n", atra_no, UserStatus->cur_georama, have);
706 SetStack(stack, have);
707 return 1;
708}
709
710int _SET_ATRA(RS_STACKDATA *stack, int argument_count) {
711 sceVu0FVECTOR pos;
712
713 pos[0] = GetStackFloat(stack++);
714 pos[1] = GetStackFloat(stack++);
715 pos[2] = GetStackFloat(stack++);
716 pos[3] = 1.0f;
717 NowDngMap->SetAtraBoll(pos, GetStackInt(stack));
718 return 1;
719}
720
721int _SET_IBOX(RS_STACKDATA *stack, int argument_count) {
722 sceVu0FVECTOR pos;
723
724 pos[0] = GetStackFloat(stack++);
725 pos[1] = GetStackFloat(stack++);
726 pos[2] = GetStackFloat(stack++);
727 pos[3] = 1.0f;
728 NowDngMap->SetTreasureBox(pos, GetStackInt(stack), TREASURE_BOX_SMALL, 0);
729 return 1;
730}
731
732int _GET_NOW_USER_ID(RS_STACKDATA *stack, int argument_count) {
733 int cur_chara = UserStatus->cur_chara;
734 printf("get id = %d\n", cur_chara);
735 SetStack(stack, cur_chara);
736 return 1;
737}
738
739int _RUN_SCRIPT_NO(RS_STACKDATA *stack, int argument_count) {
740 int script_no = GetStackInt(stack++);
741
742 BtEventInfo.ext_memory = false;
743
744 if (argument_count == 2) {
745 BtEventInfo.ext_memory = GetStackInt(stack++);
746 }
747
748 if (argument_count == 3) {
749 BtEventInfo.ext_memory = GetStackInt(stack++);
750 BtEventInfo.fade_on_start = GetStackInt(stack);
751 }
752
753 BtEventInfo.request = BT_REQUEST_RUN_SCRIPT;
754 BtEventInfo.chained_script_no = script_no;
755 return 1;
756}
757
758int _CLEAN_MONSTOR_SCRIPT_NO(RS_STACKDATA *stack, int argument_count) {
759 int script_no = GetStackInt(stack++);
760
761 BtEventInfo.clear_script_ext_memory = 0;
762
763 if (argument_count > 1) {
764 BtEventInfo.clear_script_ext_memory = GetStackInt(stack);
765 }
766
767 BtEventInfo.clear_script_no = script_no;
768 return 1;
769}
770
771int _GET_NPC_OBJHDL(RS_STACKDATA *stack, int argument_count) {
772 int index = GetStackInt(stack++);
773 int npc_no = GetStackInt(stack);
774 BT_OBJ_HANDLE *handle = GetObjHDL(index);
775
776 if (npc_no < 0 || npc_no > 3) {
777 printf("over err\n");
778 return 1;
779 }
780
781 CCharacter *chara = &NowDngMap->npc[npc_no].chara;
782
783 if (chara->frame != NULL) {
784 handle->character = chara;
785 handle->type = 1;
786 } else {
787 handle->character = NULL;
788 handle->type = 1;
789 }
790
791 return 1;
792}
793
794int _SET_MOTION_OBJHDL(RS_STACKDATA *stack, int argument_count) {
795 int npc_no = GetStackInt(stack++);
796 int motion_no = GetStackInt(stack++);
797 int speed = -1;
798 int mode = 0;
799
800 if (argument_count > 2) {
801 speed = GetStackFloat(stack++);
802 }
803
804 if (argument_count > 3) {
805 mode = GetStackInt(stack);
806 }
807
808 if (NowDngMap->npc[npc_no].chara.frame == NULL) {
809 return 1;
810 }
811
812 if (argument_count < 3) {
813 NowDngMap->NPCSetMotion(npc_no, motion_no);
814 } else {
815 NowDngMap->NPCSetMotion(npc_no, motion_no, speed, mode);
816 }
817
818 return 1;
819}
820
821int _SET_NPC_ON_OFF(RS_STACKDATA *stack, int argument_count) {
822 int npc_no = GetStackInt(stack++);
823 int enable = GetStackInt(stack);
824
825 if (NowDngMap->npc[npc_no].chara.frame == NULL) {
826 return 1;
827 }
828
829 NowDngMap->npc[npc_no].visible = enable;
830 return 1;
831}
832
833int _GET_GATEKEY_NO(RS_STACKDATA *stack, int argument_count) {
834 SetStack(stack, NowDngMap->gate_key_no);
835 return 1;
836}
837
838int _USER_WEAPON_DRAW(RS_STACKDATA *stack, int argument_count) {
839 if (argument_count != 1) {
840 return 1;
841 }
842
843 BtActStatus.weapon_visible = GetStackInt(stack);
844 return 1;
845}
846
847int _SET_MAIN_CHR2(RS_STACKDATA *stack, int argument_count) {
848 int chara = GetStackInt(stack++);
849 int reload = 0;
850
851 if (argument_count == 2) {
852 reload = GetStackInt(stack);
853 }
854
855 if (chara < 0 || chara > 5) {
856 return 1;
857 }
858
859 selectChrUnit(chara, reload);
860 BtEventInfo.script_main_chr = chara;
861 return 1;
862}
863
864int _RESET_MAIN_CHR(RS_STACKDATA *stack, int argument_count) {
865 if (BtEventInfo.script_main_chr == -1) {
866 return 1;
867 }
868
869 selectChrUnit(BtEventInfo.script_main_chr, 0);
870 BtEventInfo.script_main_chr = -1;
871 // Past the early exit the result is whatever selectChrUnit left behind.
872 PORT_RETURN(1);
873}
874
875int _SET_LIMMIT_ZONE(RS_STACKDATA *stack, int argument_count) {
876 UserStatus->res_limit_zone_current = GetStackInt(stack);
877 SndSPSeLoad(0x1B);
878 return 1;
879}
880
881int _SET_DEAD_FLAG(RS_STACKDATA *stack, int argument_count) {
882 ((CDngStatusData *) UserStatus)->SetDead();
883 return 1;
884}
885
886int _ALL_DRAW_FLAG(RS_STACKDATA *stack, int argument_count) {
887 if (argument_count == 1) {
888 BtAllDrawFlag = GetStackInt(stack);
889 }
890
891 return 1;
892}
893
894int _SET_FLOOR_TITLE(RS_STACKDATA *stack, int argument_count) {
895 FloorTitleOn();
896 return 1;
897}
898
899int _GET_RUBY_ELEMENT(RS_STACKDATA *stack, int argument_count) {
900 SetStack(stack, BtRubyDoorKey);
901 return 1;
902}
903
904int _SET_RUBY_ELEMENT(RS_STACKDATA *stack, int argument_count) {
905 GetStackInt(stack);
906 return 1;
907}
908
909int _SET_FLOOR_TITLE_OFF(RS_STACKDATA *stack, int argument_count) {
910 BtEventInfo.floor_title_off = 1;
911 return 1;
912}
913
914int _SET_RES_LIMMIT_ZONE(RS_STACKDATA *stack, int argument_count) {
915 ((CDngStatusData *) UserStatus)->SetResLimmitZone();
916
917 if (UserStatus->res_limit_zone_current != RES_LIMIT_ZONE_NONE) {
918 SndSPSeLoad(0x1B);
919 }
920
921 return 1;
922}
923
924int _CLEAR_DEAMON_SHAFT(RS_STACKDATA *stack, int argument_count) {
925 ((CDngStatusData *) UserStatus)->ClearDeamonShaft();
926 return 1;
927}
928
929int _INIT_BEE(RS_STACKDATA *stack, int argument_count) {
930 BtEventInfo.bee_npc = GetStackInt(stack);
931 InitBee(NPCUnit[BtEventInfo.bee_npc].frame, 15);
932 return 1;
933}
934
935int _END_BEE(RS_STACKDATA *stack, int argument_count) {
936 BtEventInfo.bee_npc = -1;
937 return 1;
938}
939
940int _EASTKING_COMPLETE(RS_STACKDATA *stack, int argument_count) {
941 SetStack(stack, EastKingCheckComplete());
942 return 1;
943}
944
945int _GET_ITEM_TRAPID(RS_STACKDATA *stack, int argument_count) {
946 int box = BtEventInfo.treasure_box;
947 SetStack(stack, NowDngMap->boxes[box].trap_no);
948 return 1;
949}
950
951int _RESET_ITEM_TRAP(RS_STACKDATA *stack, int argument_count) {
952 int box = BtEventInfo.treasure_box;
953 NowDngMap->boxes[box].trap_no = 0;
954 BtEventInfo.treasure_box = 0;
955 return 1;
956}
957
958int _BOM_SET(RS_STACKDATA *stack, int argument_count) {
959 sceVu0FVECTOR pos;
960 sceVu0FVECTOR push = {0.0f, 0.0f, 1.0f, 1.0f};
961 sceVu0FVECTOR direction;
962
963 sceVu0CopyVector(pos, CharaMain.pos);
964 pos[1] += 16.0f;
965 pos[2] -= 3.0f;
966 int bomb = SetBombEffect(pos, 1, selectMapNo * 20 + 20, 0.8f);
967
968 if (bomb != -1) {
969 CCollisionData *collision = NowColData;
970 sceVu0Normalize(direction, push);
971 sceVu0ScaleVectorXYZ(collision->hit[bomb].velocity, direction, 0.8f);
972 }
973
974 BtActStatus.event_block_frames = 30;
975 return 1;
976}
977
978int _SET_STATUS_ERR(RS_STACKDATA *stack, int argument_count) {
979 sceVu0FVECTOR pos;
980
981 BtSetStatusErr(GetStackInt(stack));
982 sceVu0CopyVector(pos, CharaMain.pos);
983 pos[1] += 16.0f;
984 NowColData->Set(pos, 2, 2, 5.0f, 0.0f, 1, 2, 0, 0);
985 return 1;
986}
987
988int _CHECK_MARDAN(RS_STACKDATA *stack, int argument_count) {
989 SetStack(stack, SaveData->GetMardanGareyanFlag());
990 return 1;
991}
992
993int _NO_RESET_CHARA_NO(RS_STACKDATA *stack, int argument_count) {
994 BtEventInfo.no_reset_chara = 1;
995 return 1;
996}
997
998int _CHECK_CHR_HELP(RS_STACKDATA *stack, int argument_count) {
999 SetStack(stack, BtEventInfo.chara_help);
1000 return 1;
1001}
1002
1003int _HOLD_ITEM_EVENT(RS_STACKDATA *stack, int argument_count) {
1004 int script_no = GetStackInt(stack);
1005 DngEventMan.SearchItemEventHold(script_no);
1006 UraEventMan.SearchItemEventHold(script_no);
1007 return 1;
1008}
1009
1010int _STOP_BATTLE_BGM(RS_STACKDATA *stack, int argument_count) {
1011 BtBattleMusic_Stop();
1012 return 1;
1013}
1014
1015int _NO_STATUS_RECOVER(RS_STACKDATA *stack, int argument_count) {
1016 BtEventInfo.no_status_recover = 1;
1017 return 1;
1018}
1019
1020int _SET_QUEST_DUNGEON(RS_STACKDATA *stack, int argument_count) {
1021 int dungeon_no = GetStackInt(stack++);
1022 SaveData->QuestDungeon(dungeon_no, GetStackInt(stack));
1023 return 1;
1024}
1025
1026int _GET_MAP_CODE(RS_STACKDATA *stack, int argument_count) {
1027 SetStack(stack, UserStatus->cur_georama + 1);
1028 return 1;
1029}
1030
1031int _SET_ACTIVE_ITEM_ICON(RS_STACKDATA *stack, int argument_count) {
1032 LoadActiveItemIcon();
1033 return 1;
1034}
1035
1036int _GET_ITEM_UNIT_NO(RS_STACKDATA *stack, int argument_count) {
1037 int item_no = GetStackInt(stack++);
1038 int owner = -1;
1039 int not_weapon = item_no < ITEM_WEAPON_START;
1040
1041 if (!not_weapon) {
1042 if (!not_weapon && item_no < ITEM_WEAPON_WOODENSLINGSHOT_BROKEN) {
1043 owner = 0;
1044 }
1045
1046 if (item_no >= ITEM_WEAPON_WOODENSLINGSHOT_BROKEN && item_no < ITEM_WEAPON_MALLET_BROKEN) {
1047 owner = 1;
1048 }
1049
1050 if (item_no >= ITEM_WEAPON_MALLET_BROKEN && item_no < ITEM_WEAPON_GOLD_RING_BROKEN) {
1051 owner = 2;
1052 }
1053
1054 if (item_no >= ITEM_WEAPON_GOLD_RING_BROKEN && item_no < ITEM_WEAPON_FIGHTING_STICK_BROKEN) {
1055 owner = 3;
1056 }
1057
1058 if (item_no >= ITEM_WEAPON_FIGHTING_STICK_BROKEN && item_no < ITEM_WEAPON_MACHINE_GUN_BROKEN) {
1059 owner = 4;
1060 }
1061
1062 if (item_no >= ITEM_WEAPON_MACHINE_GUN_BROKEN) {
1063 owner = 5;
1064 }
1065 }
1066
1067 SetStack(stack, owner);
1068 return 1;
1069}
1070
1071int _SET_IBOX_ANGLE(RS_STACKDATA *stack, int argument_count) {
1072 NowDngMap->boxes[BtEventInfo.treasure_box].lid_angle = GetStackFloat(stack);
1073 return 1;
1074}
1075
1076int _SET_IBOX_FINISH(RS_STACKDATA *stack, int argument_count) {
1077 NowDngMap->boxes[BtEventInfo.treasure_box].lid_angle = -30.0f;
1078 NowDngMap->boxes[BtEventInfo.treasure_box].closed = 0;
1079 return 1;
1080}
1081
1082int _GET_PIERO_ITEM(RS_STACKDATA *stack, int argument_count) {
1083 int item0, item1;
1084
1085 GetPieroItem(selectMapNo, BtUraDongeon, &item0, &item1);
1086 SetStack(stack++, item0);
1087 SetStack(stack, item1);
1088 return 1;
1089}
1090
1096
1098static BT_EVENT_EXTERNAL_FUNCTION ext_func_info[] = {
1099 {_GET_FLOOR_LEVEL, 1010},
1100 {_SET_FLOOR_LEVEL, 1011},
1101 {_GET_OLD_FLOOR_LEVEL, 1012},
1102 {_GET_ACTION_MODE, 1020},
1103 {_ITEM_USE_WINDOW, 1021},
1104 {_CHECK_EVENT_FLG, 1023},
1105 {_SET_EVENT_FLG, 1024},
1106 {_GET_OBJHDL, 1030},
1107 {_SET_OBJHDL_POS, 1031},
1108 {_SET_OBJHDL_ROT, 1032},
1109 {_SET_OBJHDL_DRAW_FLAG, 1033},
1110 {_GET_OBJHDL_POS, 1034},
1111 {_GET_OBJHDL_ROT, 1035},
1112 {_SET_URA_DUNGEON, 1036},
1113 {_GET_EVENT_POS, 1040},
1114 {_GET_EVENT_ROT, 1041},
1115 {_OPEN_ENTRANCE_WINDOW, 1022},
1116 {_OPEN_ESCAPE_WINDOW, 1070},
1117 {_GO_DUNGEON, 1050},
1118 {_SET_DUNGEON_MAP, 1051},
1119 {_LOAD_DUNGEON_MAP2, 1052},
1120 {_LOAD_MONSTOR, 1053},
1121 {_SET_RANDOM_MAP, 1054},
1122 {_SET_EVENT_SW, 1055},
1123 {_SET_MONSTOR_ID, 1056},
1124 {_CHK_ATRA_HAVE, 1057},
1125 {_SET_ATRA, 1058},
1126 {_SET_IBOX, 1059},
1127 {_GET_NOW_USER_ID, 1060},
1128 {_RUN_SCRIPT_NO, 1061},
1129 {_CLEAN_MONSTOR_SCRIPT_NO, 1066},
1130 {_GET_NPC_OBJHDL, 1062},
1131 {_SET_MOTION_OBJHDL, 1063},
1132 {_SET_NPC_ON_OFF, 1094},
1133 {_GET_GATEKEY_NO, 1064},
1134 {_USER_WEAPON_DRAW, 1065},
1135 {_SET_MAIN_CHR2, 1067},
1136 {_RESET_MAIN_CHR, 1071},
1137 {_SET_LIMMIT_ZONE, 1068},
1138 {_SET_DEAD_FLAG, 1069},
1139 {_ALL_DRAW_FLAG, 1072},
1140 {_SET_FLOOR_TITLE, 1073},
1141 {_GET_RUBY_ELEMENT, 1074},
1142 {_SET_RUBY_ELEMENT, 1088},
1143 {_SET_FLOOR_TITLE_OFF, 1076},
1144 {_INIT_BEE, 1077},
1145 {_END_BEE, 1078},
1146 {_EASTKING_COMPLETE, 1079},
1147 {_SET_RES_LIMMIT_ZONE, 1080},
1148 {_GET_ITEM_TRAPID, 1081},
1149 {_RESET_ITEM_TRAP, 1082},
1150 {_BOM_SET, 1083},
1151 {_SET_STATUS_ERR, 1084},
1152 {_CHECK_MARDAN, 1086},
1153 {_NO_RESET_CHARA_NO, 1087},
1154 {_CHECK_CHR_HELP, 1089},
1155 {_HOLD_ITEM_EVENT, 1090},
1156 {_STOP_BATTLE_BGM, 1091},
1157 {_NO_STATUS_RECOVER, 1092},
1158 {_SET_QUEST_DUNGEON, 1093},
1159 {_GET_MAP_CODE, 1095},
1160 {_SET_ACTIVE_ITEM_ICON, 1096},
1161 {_GET_ITEM_UNIT_NO, 1097},
1162 {_SET_IBOX_ANGLE, 1098},
1163 {_SET_IBOX_FINISH, 1099},
1164 {_GET_PIERO_ITEM, 1100},
1165 {_CLEAR_DEAMON_SHAFT, 1101},
1166 {NULL, -1 },
1167};
1168
1169void AddSystemEventScript() {
1170 for (int i = 0;; i++) {
1171 if (ext_func_info[i].function == NULL) {
1172 break;
1173 }
1174
1175 int j;
1176
1177 for (j = 0; j < i; j++) {
1178 if (ext_func_info[i].operation == ext_func_info[j].operation) {
1179 printf("same ext_func_no!!!\n");
1180
1181 while (1) {
1182 }
1183 }
1184 }
1185
1186 int operation = ext_func_info[i].operation;
1187
1188 if (operation < 0 || operation >= 1500) {
1189 printf("ext func over!!");
1190 } else {
1191 ext_func__2[operation] = ext_func_info[i].function;
1192 }
1193 }
1194}
void SetHeight(float height)
void SetFollow(float x, float y, float z)
void SetAngleSoon(float angle)
virtual void Step(int steps)
void GetRef(float *ref)
Definition camera.cpp:234
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
void GetPos(float *pos)
Definition camera.cpp:230
void SetMotion(int no, int mode, float speed=-1.0f)
CFrame * frame
virtual void GetPosition(float *out_position)
virtual void SetRotation(float x, float y, float z)
virtual void SetPosition(float x, float y, float z)
int Set(float *position, int damage, int life, float radius, float scale_rate, int target_mask, int kind, int flags, int attribute)
COLLISION_HIT hit[96]
void SearchItemEventHold(int script_no)
void SearchDataSwitch(int script_no, int enable)
CFrame * GetFrameSearch(char *name)
int SetTreasureBox(float *pos, int item_no, int kind, int trap_no)
MAP_NPC_MODEL npc[4]
TREASURE_BOX boxes[24]
void NPCSetMotion(int npc_no, int motion_no)
CDungeonParts parts[72]
void SetAtraBoll(float *pos, int atra_no)
CFrame * GetSearchFrame(char *name)
short draw_on
Definition frame.hpp:27
int flags
Definition frame.hpp:60
CFrameAttr attr
Definition frame.hpp:65
void CleanViewMonstor(int back_floor)
int SetupViewMonstor(int model_no, float *position, int event_flag)
virtual void GetRotation(float *out_rotation)
Definition object.cpp:116
float pos[4]
Definition object.hpp:18
s32 GetMardanGareyanFlag() const
Definition savedata.hpp:495
int QuestDungeon(int dungeon_no, int add)
Definition savedata.cpp:535
void * GetConfigData()
Definition savedata.cpp:33
s8 event_flags[50]
int ChkEventFlag(int flag_no)
s32 res_limit_zone_current
float text_rate_set
Definition clsmes.hpp:193
float text_rate
Definition clsmes.hpp:192
@ TREASURE_BOX_SMALL
int(* function)(RS_STACKDATA *, int)
s32 item_select_list[16]
Definition gameloop.hpp:146
sceVu0FVECTOR direction
Definition gameloop.hpp:138
s32 item_select_result
Definition gameloop.hpp:148
s32 no_status_recover
Definition gameloop.hpp:162
s32 clear_script_ext_memory
Definition gameloop.hpp:157
sceVu0FVECTOR position
Definition gameloop.hpp:137
s32 item_select_filtered
Definition gameloop.hpp:147
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
CCharacter * character
sceVu0FVECTOR velocity
s32 player_draw
Definition edit.hpp:164
s32 npc_count
Definition edit.hpp:176
CNPCharacter * npcs
Definition edit.hpp:162
s32 player_texture_block
Definition edit.hpp:168
ClsMes * messages[8]
Definition edit.hpp:178
s32 npc_texture_block
Definition edit.hpp:175
float projection
Definition edit.hpp:155
float reset_camera_yaw
Definition edit.hpp:158
s32 reset_camera_angle
Definition edit.hpp:157
s32 player_shadow_draw
Definition edit.hpp:165
CCharacter * main_character
Definition edit.hpp:159
VILLAGER_INFO * villagers
Definition edit.hpp:177
CCameraFollow * camera
Definition edit.hpp:156
CCharacter chara
RS_STACKDATA * p
Definition runscript.hpp:83