DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
editloop3.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 338
4
5#include "common.h"
6
7#include <libgraph.h>
8#include <libpkt.h>
9#include <libvu0.h>
10#include <sifdev.h>
11
12#include <cmath>
13#include <cstdio>
14#include <cstdlib>
15#include <cstring>
16
17#include "actionseq.hpp"
18#include "battlemenu.hpp"
19#include "boxvu0.hpp"
20#include "btmisc.hpp"
21#include "btsysscript.hpp"
22#include "camera.hpp"
23#include "camerafollow.hpp"
24#include "character.hpp"
25#include "clsmes.hpp"
26#include "dataalloc.hpp"
27#include "dataread.hpp"
28#include "debugfont.hpp"
29#include "dngstatusdata.hpp"
30#include "ebattle.hpp"
31#include "editground.hpp"
32#include "editloop.hpp"
33#include "editloop3.hpp"
34#include "editpartsinfo.hpp"
35#include "effect.hpp"
36#include "fishing.hpp"
37#include "frame.hpp"
38#include "framevu1.hpp"
39#include "gamemode.hpp"
40#include "gamepad.hpp"
41#include "gameutil.hpp"
42#include "mainselect.hpp"
43#include "mapparts.hpp"
44#include "mathutil.hpp"
45#include "mdt.hpp"
46#include "menu_draw.hpp"
47#include "menu_misc.hpp"
48#include "menu_save.hpp"
49#include "mglib.hpp"
50#include "nowload.hpp"
51#include "npcharacter.hpp"
52#include "objanime.hpp"
53#include "rect.hpp"
54#include "runscript.hpp"
55#include "savedata.hpp"
56#include "snd.hpp"
57#include "spritetable.hpp"
58#include "sysmes.hpp"
59#include "textureanime.hpp"
60#include "visualvu1.hpp"
61
62/* Retail editloop3.cpp: editor event points, villagers, script opcodes and talk handling. */
63
67// clang-format off
68enum VillagerAppearAction {
69 VILLAGER_APPEAR_DEFAULT = 0,
70 VILLAGER_APPEAR_IN = 1,
71 VILLAGER_APPEAR_OUT = 2,
72 VILLAGER_APPEAR_OFF = 3,
73 VILLAGER_APPEAR_ON = 4,
74};
75
76// clang-format on
77
81// clang-format off
82enum TalkModeState {
83 TALK_MODE_SELECT = 0,
84 TALK_MODE_MESSAGE = 1,
85};
86
87// clang-format on
88
89ED_EVENT_POINT *GetNewEventPoint(CMapParts *parts, EPARTS_FUNC_DATA *function, ED_EVENT_POINT *points, int count) {
90 ED_EVENT_POINT *point = GetNewEventPoint(points, count);
91
92 if (point == NULL) {
93 printf("event over!!\n");
94 return NULL;
95 }
96
97 point->enabled = true;
98
99 if (parts->parts_no >= 0) {
100 point->map_object = NULL;
101 point->parts_no = parts->parts_no;
102 } else {
103 point->map_object = parts;
104 point->parts_no = -1;
105 }
106
107 sceVu0CopyVector(point->position, function->position);
108 sceVu0CopyVector(point->rotation, function->rotation);
109 point->start_time = ConvertTime(function->start_time);
110 point->end_time = ConvertTime(function->end_time);
111 point->completion_flag = function->completion_flag;
112 CFrame *frame = parts->frame[0];
113 point->frame = NULL;
114
115 if (frame != NULL) {
116 point->frame = frame->SearchFrame(function->frame_name);
117 }
118
119 return point;
120}
121
122int EdInitEventPoint(CMapParts *parts, short *indices, EPARTS_FUNC_DATA *functions, int function_count, ED_EVENT_POINT *points, int point_count) {
123 int has_extent;
124 int created;
125 int j;
126
127 for (int i = 0; i < 8 && indices != NULL; i++) {
128 int point_index = indices[i];
129
130 if (point_index <= 0) {
131 continue;
132 }
133
134 ED_EVENT_POINT *point = &points[point_index];
135
136 if (point->event_type != ED_EVENT_POINT_DOOR) {
137 continue;
138 }
139
140 point->enabled = true;
141
142 if (parts->parts_no >= 0) {
143 point->map_object = NULL;
144 point->parts_no = parts->parts_no;
145 } else {
146 point->map_object = parts;
147 point->parts_no = -1;
148 }
149
150 has_extent = 0;
151 EPARTS_FUNC_DATA *function = functions;
152
153 for (int j = 0; j < function_count; j++, function++) {
154 int kind = function->kind;
155
156 if (kind != EPARTS_FUNC_DOOR_EXTENT && kind != EPARTS_FUNC_DOOR_SIDE_B && kind != EPARTS_FUNC_DOOR_SIDE_A && kind != EPARTS_FUNC_DOOR) {
157 kind = function->kind;
158 } else if (function->link_id == points[point_index].map_no) {
159 if (kind == EPARTS_FUNC_DOOR) {
160 sceVu0CopyVector(point->position, function->position);
161 sceVu0CopyVector(point->rotation, function->rotation);
162 point->trigger_range[2] = 10.0f;
163 point->trigger_range[1] = 10.0f;
164 point->trigger_range[0] = 10.0f;
165 point->minimum_progress = (int) function->values[0];
166 point->start_time = ConvertTime(function->start_time);
167 point->end_time = ConvertTime(function->end_time);
168 point->completion_flag = function->completion_flag;
169
170 if (has_extent == 0) {
171 sceVu0FVECTOR offset = {40.0f, 50.0f, -80.0f, 1.0f};
172 sceVu0FMATRIX matrix;
173 sceVu0UnitMatrix(matrix);
174 sceVu0RotMatrixY(matrix, matrix, point->rotation[1]);
175 sceVu0ApplyMatrix(offset, matrix, offset);
176 sceVu0AddVector(point->extent, offset, point->position);
177 }
178 }
179
180 if (function->kind == EPARTS_FUNC_DOOR_EXTENT) {
181 sceVu0CopyVector(point->extent, function->position);
182 has_extent = 1;
183 }
184
185 if (function->kind == EPARTS_FUNC_DOOR_SIDE_A) {
186 point->side = 1;
187 }
188
189 if (function->kind == EPARTS_FUNC_DOOR_SIDE_B) {
190 point->side = -1;
191 }
192
193 if (function->kind == EPARTS_FUNC_DOOR_SIDE_A || function->kind == EPARTS_FUNC_DOOR_SIDE_B) {
194 point->linked_value = (int) function->values[0];
195 }
196 }
197 }
198 }
199
200 created = 0;
201 EPARTS_FUNC_DATA *function = functions;
202
203 for (int i = 0; i < function_count; i++, function++) {
204 ED_EVENT_POINT *point = NULL;
205
206 switch (function->kind) {
207 case EPARTS_FUNC_ITEM_BOX:
208 point = GetNewEventPoint(parts, function, points, point_count);
209
210 if (point != NULL) {
211 point->event_type = ED_EVENT_POINT_ITEM_BOX;
212 point->trigger_range[2] = 15.0f;
213 point->trigger_range[1] = 15.0f;
214 point->trigger_range[0] = 15.0f;
215 point->side = (int) function->values[0];
216 point->linked_value = (int) function->values[1];
217 point->minimum_progress = (int) function->values[2];
218 point->secondary_progress = (int) function->values[3];
219 }
220
221 break;
222 case EPARTS_FUNC_EVENT:
223 if ((int) function->values[0] > 0) {
224 point = GetNewEventPoint(parts, function, points, point_count);
225
226 if (point != NULL) {
227 point->event_type = ED_EVENT_POINT_EVENT;
228 sceVu0CopyVector(point->trigger_range, function->parameters);
229 point->side = (int) function->values[0];
230 point->linked_value = (int) function->values[1];
231 }
232 }
233
234 break;
235 case EPARTS_FUNC_LADDER_BOTTOM:
236 point = GetNewEventPoint(parts, function, points, point_count);
237
238 if (point != NULL) {
239 point->event_type = ED_EVENT_POINT_LADDER_BOTTOM;
240 point->trigger_range[2] = 6.0f;
241 point->trigger_range[1] = 6.0f;
242 point->trigger_range[0] = 6.0f;
243 point->trigger_range[3] = function->values[0];
244 point->side = (int) function->values[1];
245
246 for (j = 0; j < function_count; j++) {
247 EPARTS_FUNC_DATA *other = &functions[j];
248
249 if (other->kind == EPARTS_FUNC_LADDER_TOP && other->link_id == function->link_id) {
250 sceVu0CopyVector(point->extent, other->position);
251 point->linked_value = (int) other->values[1];
252 break;
253 }
254 }
255 }
256
257 break;
258 case EPARTS_FUNC_LADDER_TOP:
259 point = GetNewEventPoint(parts, function, points, point_count);
260
261 if (point != NULL) {
262 point->event_type = ED_EVENT_POINT_LADDER_TOP;
263 point->trigger_range[2] = 6.0f;
264 point->trigger_range[1] = 6.0f;
265 point->trigger_range[0] = 6.0f;
266 point->trigger_range[3] = function->values[0];
267 point->linked_value = (int) function->values[1];
268
269 for (j = 0; j < function_count; j++) {
270 EPARTS_FUNC_DATA *other = &functions[j];
271
272 if (other->kind == EPARTS_FUNC_LADDER_BOTTOM && other->link_id == function->link_id) {
273 sceVu0CopyVector(point->extent, other->position);
274 point->side = (int) other->values[1];
275 break;
276 }
277 }
278 }
279
280 break;
281 }
282
283 if (point != NULL) {
284 created++;
285 }
286 }
287
288 return created;
289}
290
291int EdGetEvent(ED_EVENT_POINT *points, int count, ED_EVENT_PARAM *param, float *position, float *rotation, float time) {
292 CEditGround *ground = EdExchangeInfo.ground;
293 int i;
294 ED_EVENT_POINT *point = points;
295 float nearest = -1.0f;
296
297 for (i = 0; i < count; i++, point++) {
298 if (!CheckEventPoint(point, time)) {
299 continue;
300 }
301
302 sceVu0FVECTOR event_position;
303 sceVu0FVECTOR event_rotation;
304 sceVu0FVECTOR camera_position;
305 sceVu0FVECTOR camera_rotation;
306 sceVu0CopyVector(event_position, point->position);
307 sceVu0CopyVector(camera_position, point->extent);
308 sceVu0CopyVector(event_rotation, point->rotation);
309 sceVu0CopyVector(camera_rotation, point->rotation);
310
311 CMapObject *object = point->map_object;
312
313 if (point->parts_no >= 0) {
314 object = ground->GetPartsObject(point->parts_no);
315
316 if (object == NULL) {
317 continue;
318 }
319
320 GetPosRot(object, event_position, event_rotation);
321 GetPosRot(object, camera_position, camera_rotation);
322 } else {
323 if (object != NULL) {
324 GetPosRot(object, event_position, event_rotation);
325 }
326
327 if (object != NULL) {
328 GetPosRot(object, camera_position, camera_rotation);
329 }
330 }
331
332 float distance;
333
334 if (point->event_type == ED_EVENT_POINT_ITEM_BOX) {
335 sceVu0FVECTOR delta;
336 sceVu0SubVector(delta, event_position, position);
337 delta[1] = 0.0f;
338 distance = DistVector(delta);
339
340 if (event_position[1] < position[1] - 1.0f || !(event_position[1] <= position[1] + 20.0f)) {
341 distance = 1000000.0f;
342 }
343 } else {
344 distance = DistVector(event_position, position);
345 }
346
347 int selected = 0;
348
349 if (distance < point->trigger_range[0]) {
350 selected = 1;
351
352 switch (point->event_type) {
353 case ED_EVENT_POINT_LADDER_BOTTOM:
354 case ED_EVENT_POINT_DOOR:
355 if (AngleCmp(rotation[1], event_rotation[1], 0.8f)) {
356 selected = 0;
357 }
358
359 break;
360 case ED_EVENT_POINT_LADDER_TOP:
361 if (AngleCmp(AngleLimit(rotation[1] - 3.14f), event_rotation[1], 0.8f)) {
362 selected = 0;
363 }
364
365 break;
366 }
367 }
368
369 if (selected && (nearest < 0.0f || !(nearest <= point->trigger_range[0]))) {
370 nearest = point->trigger_range[0];
371 param->kind = point->event_type;
372 param->parts_no = point->parts_no;
373 sceVu0CopyVector(param->position, event_position);
374 sceVu0CopyVector(param->camera_pos, camera_position);
375 sceVu0CopyVector(param->rotation, event_rotation);
376 sceVu0FVECTOR offset = {40.0f, 50.0f, -80.0f, 1.0f};
377 sceVu0FMATRIX matrix;
378 sceVu0UnitMatrix(matrix);
379 sceVu0RotMatrixY(matrix, matrix, event_rotation[1]);
380 sceVu0ApplyMatrix(offset, matrix, offset);
381 sceVu0AddVector(offset, offset, event_position);
382 sceVu0CopyVector((float *) param->unk_40, offset);
383 param->point = point;
384 }
385 }
386
387 if (nearest > 0.0f) {
388 return 1;
389 }
390
391 return 0;
392}
393
394void EdEventPointDraw(ED_EVENT_POINT *points, int count, float time) {
395 if (EdDrawOffMap != 0) {
396 return;
397 }
398
399 CEditGround *ground = EdExchangeInfo.ground;
400 CFrame *marker = EdExchangeInfo.event_marker;
401 C3DSprite *effect = EdExchangeInfo.system_effect;
402 ED_EVENT_POINT *point = points;
403 static float roty = 0.0f;
404 roty += 0.05f;
405
406 if (roty > PI_SHORT) {
407 roty -= TWO_PI;
408 }
409
410 static float sys_eff_sc = 0.0f;
411 static int sys_eff_cnt = 0;
412
413 if (sys_eff_sc > 1.0f) {
414 sys_eff_sc = 0.0f;
415 sys_eff_cnt = rand() % 20 + 10;
416 }
417
418 if (sys_eff_cnt < 0) {
419 sys_eff_sc += 0.3f;
420 sys_eff_cnt = 0;
421 }
422
423 sys_eff_cnt--;
424
425 for (int i = 0; i < count; i++, point++) {
426 if (CheckEventPoint(point, time) == 0) {
427 continue;
428 }
429
430 switch (point->event_type) {
431 case ED_EVENT_POINT_ITEM_BOX:
432 break;
433 case ED_EVENT_POINT_EVENT:
434 if (point->linked_value <= 0) {
435 continue;
436 }
437
438 break;
439 default:
440 continue;
441 }
442
443 sceVu0FVECTOR position;
444 sceVu0FVECTOR rotation;
445 sceVu0CopyVector(position, point->position);
446 sceVu0CopyVector(rotation, point->rotation);
447 CMapObject *object = point->map_object;
448
449 if (point->parts_no >= 0) {
450 object = ground->GetPartsObject(point->parts_no);
451
452 if (object == NULL) {
453 continue;
454 }
455
456 GetPosRot(object, position, rotation);
457 } else if (object != NULL) {
458 GetPosRot(object, position, rotation);
459 }
460
461 if (point->event_type == ED_EVENT_POINT_ITEM_BOX && marker != NULL) {
462 marker->SetPosition(position);
463 marker->SetRotation(0.0f, rotation[1], 0.0f);
464 MGDraw(marker);
465 }
466
467 if (point->event_type == ED_EVENT_POINT_EVENT) {
468 sceVu0CopyVector(effect->position, position);
469 effect->half_width = 2.0f * sys_eff_sc;
470 effect->half_height = sys_eff_sc;
471 effect->position[1] += 1.0f;
472 effect->Draw();
473 }
474 }
475}
476
477int EdEventPointCpPoly(float *position, ED_EVENT_POINT *points, int count, CCPoly *polygons, float time) {
478 CEditGround *ground = EdExchangeInfo.ground;
479 static CCharacter chara;
480 chara.body_width = 3.0f;
481 int i;
482 int found = 0;
483
484 for (i = 0; i < count; i++, points++) {
485 if (points->event_type == ED_EVENT_POINT_ITEM_BOX && CheckEventPoint(points, time)) {
486 sceVu0FVECTOR event_position;
487 sceVu0FVECTOR event_rotation;
488 sceVu0CopyVector(event_position, points->position);
489 sceVu0CopyVector(event_rotation, points->rotation);
490 CMapObject *object = points->map_object;
491
492 if (points->parts_no >= 0) {
493 object = ground->GetPartsObject(points->parts_no);
494
495 if (object == NULL) {
496 continue;
497 }
498
499 GetPosRot(object, event_position, event_rotation);
500 } else if (object != NULL) {
501 GetPosRot(object, event_position, event_rotation);
502 }
503
504 chara.SetPosition(event_position);
505 found += chara.PickUpPoly(position, polygons);
506 }
507 }
508
509 return found;
510}
511
512int EdSearchEvent(ED_EVENT_PARAM *param, char *name, int map_no, float time) {
513 int i;
514 CEditGround *ground = EdExchangeInfo.ground;
515 ED_EVENT_POINT *point = EditMapInfo->work.events.points;
516
517 for (i = 0; i < 256; i++, point++) {
518 if (CheckEventPoint(point, time) && strcmp(point->destination, name) == 0 && point->map_no == map_no) {
519 sceVu0FVECTOR event_position;
520 sceVu0FVECTOR event_rotation;
521 sceVu0FVECTOR camera_position;
522 sceVu0FVECTOR camera_rotation;
523 sceVu0CopyVector(event_position, point->position);
524 sceVu0CopyVector(camera_position, point->extent);
525 sceVu0CopyVector(event_rotation, point->rotation);
526 sceVu0CopyVector(camera_rotation, point->rotation);
527 CMapObject *object = point->map_object;
528
529 if (point->parts_no >= 0) {
530 object = ground->GetPartsObject(point->parts_no);
531
532 if (object != NULL) {
533 GetPosRot(object, event_position, event_rotation);
534 }
535
536 if (object != NULL) {
537 GetPosRot(object, camera_position, camera_rotation);
538 }
539 } else {
540 if (object != NULL) {
541 GetPosRot(object, event_position, event_rotation);
542 }
543
544 if (object != NULL) {
545 GetPosRot(object, camera_position, camera_rotation);
546 }
547 }
548
549 param->kind = point->event_type;
550 param->parts_no = point->parts_no;
551 sceVu0CopyVector(param->position, event_position);
552 sceVu0CopyVector(param->camera_pos, camera_position);
553 sceVu0CopyVector(param->rotation, event_rotation);
554 param->point = point;
555 return 1;
556 }
557 }
558
559 return 0;
560}
561
562void EdMapJump(int kind, char *name) {
563 if (name == NULL || *name == '\0') {
564 return;
565 }
566
567 int index;
568
569 if (kind >= 3) {
570 index = kind;
571 }
572
573 char *extensions[5] = {"m", "e", "n", "", ""};
574 StartReadBG();
575 u_long128 *buffer = (u_long128 *) read_buffer;
576 char filename[64];
577 int size;
578 sprintf(filename, "%s.scn", name);
579
580 if (LoadFileBG(filename, buffer, &size) == 0) {
581 name[strlen(name) - 1] = '\0';
582 sprintf(filename, "%s.scn", name);
583
584 if (LoadFileBG(filename, buffer, &size) == 0) {
585 return;
586 }
587 }
588
589 buffer += (((size >> 6) + 1) << 6) >> 4;
590 sprintf(filename, "%s.cfg", name);
591 LoadFileBG(filename, buffer, &size);
592 buffer = (u_long128 *) (EdNPCBuffer.base + EdNPCBuffer.used * 16);
593 sprintf(filename, "%s.pak", name);
594
595 if (LoadFileBG(filename, buffer, &size) == 0) {
596 sprintf(filename, "%s.img", name);
597
598 if (LoadFileBG(filename, buffer, &size) == 0) {
599 return;
600 }
601 }
602
603 if (size > 0x200000) {
604 printf("img size over!!!\n");
605
606 while (1) {
607 }
608 }
609}
610
611void EdPartsObjectOnOff(CMapParts *parts, EDITPARTS_INFO *info, int mode) {
612 char storage[32][32];
613 char *names[32];
614 int draw_flag[2] = {2, 1};
615 int hide_flag[2] = {4, 1};
616
617 for (int element = 0; element < 6; element++) {
618 if (info->elements[element].id < 0 || info->elements[element].id >= 36) {
619 continue;
620 }
621
622 int enabled = info->elements[element].enabled != 0;
623
624 for (int i = 0; i < 32; i++) {
625 names[i] = storage[i];
626 names[i][0] = '\0';
627 }
628
629 GetElementObjName(info, names, element, mode);
630
631 char prefix;
632
633 for (int i = 0; (prefix = names[i][0]) != '\0'; i++) {
634 if (prefix == '*') {
635 if (enabled) {
636 parts->FrameObjectOnOff(names[i] + 1, draw_flag[1]);
637 } else {
638 parts->FrameObjectOnOff(names[i] + 1, 0);
639 }
640 }
641
642 if (names[i][0] == '-') {
643 parts->FrameObjectOnOff(names[i] + 1, draw_flag[!enabled]);
644 } else {
645 parts->FrameObjectOnOff(names[i], draw_flag[enabled]);
646 }
647 }
648 }
649}
650
657
658static int appear_table[10];
659
660static int select_table[10];
661
663static VILLAGER_APPEAR_STATE appear[16];
664
665void EdInitVillagerControl() {
666 for (int i = 0; i < 16; i++) {
667 appear[i].action = VILLAGER_APPEAR_DEFAULT;
668 appear[i].destination = -1;
669 appear[i].priority = -1;
670 }
671}
672
673void EdCreateVillagerTable(EDIT_MAP_INFO *info) {
674 int candidates[16];
675 int i;
676 int period;
677 int candidate_count = 0;
678
679 for (i = 0; i < 16; i++) {
680 candidates[i] = -1;
681 }
682
683 for (i = 0; i < 15; i++) {
684 int villager = info->people_list[i];
685
686 if (villager >= 0) {
687 candidates[candidate_count++] = villager;
688 }
689 }
690
691 if (candidate_count > 0) {
692 for (period = 0; period < 4; period++) {
693 for (i = 0; i < 100; i++) {
694 int first = rand() % candidate_count;
695 int second = rand() % candidate_count;
696 int value = candidates[first];
697 candidates[first] = candidates[second];
698 candidates[second] = value;
699 }
700
701 for (i = 0; i < 10; i++) {
702 info->time_tables[0][period][i] = candidates[i];
703 }
704 }
705 }
706}
707
708void EdInitVillagerTable(float clock, EDIT_MAP_INFO *info) {
709 for (int i = 0; i < 10; i++) {
710 appear_table[i] = info->time_tables[0][EdGetTime(clock)][i];
711 }
712}
713
715static VILLAGER_INFO restore_info[10];
716
717void EdVillagerAppearOut(int index, int priority) {
718 if (index < 0 || index >= 16) {
719 return;
720 }
721
722 if (appear[index].priority > priority) {
723 return;
724 }
725
726 appear[index].action = VILLAGER_APPEAR_OUT;
727 appear[index].priority = priority;
728}
729
730void EdVillagerAppearIn(int index, int priority) {
731 if (index < 0 || index >= 16) {
732 return;
733 }
734
735 if (appear[index].priority > priority) {
736 return;
737 }
738
739 appear[index].action = VILLAGER_APPEAR_IN;
740 appear[index].priority = priority;
741}
742
743void EdVillagerAppearOff(int index, int priority) {
744 if (index < 0 || index >= 16) {
745 return;
746 }
747
748 if (appear[index].priority > priority) {
749 return;
750 }
751
752 appear[index].action = VILLAGER_APPEAR_OFF;
753 appear[index].priority = priority;
754}
755
756void EdVillagerAppearOn(int index, int priority) {
757 if (index < 0 || index >= 16) {
758 return;
759 }
760
761 if (appear[index].priority > priority) {
762 return;
763 }
764
765 appear[index].action = VILLAGER_APPEAR_ON;
766 appear[index].priority = priority;
767}
768
769void EdVillagerAppearMove(int index, int destination, int priority) {
770 if (index < 0 || index >= 16) {
771 return;
772 }
773
774 if (appear[index].priority > priority) {
775 return;
776 }
777
778 appear[index].destination = destination;
779}
780
781static void RestoreVillagerInfo(VILLAGER_INFO *villagers) {
782 for (int i = 0; i < 10; i++) {
783 villagers[i] = restore_info[i];
784 }
785}
786
795int EdSelectVillager(VILLAGER_INFO *villagers, float clock, EDIT_MAP_INFO *map_info) {
796 EdInitVillagerTable(clock, map_info);
797 EdGetTime(clock);
798
799 int i;
800
801 for (i = 0; i < 10; i++) {
802 select_table[i] = -1;
803 }
804
805 int selected_count = 0;
806
807 for (i = 0; i < 16 && selected_count < 6; i++) {
808 int action = appear[i].action;
809
810 if (action == VILLAGER_APPEAR_ON || action == VILLAGER_APPEAR_OUT) {
811 select_table[selected_count++] = i;
812 }
813 }
814
815 for (i = 0; i < 10 && selected_count < 6; i++) {
816 int j;
817 int duplicate;
818 int index = appear_table[i];
819
820 if (index < 0) {
821 break;
822 }
823
824 int action = appear[index].action;
825
826 if (action == VILLAGER_APPEAR_OFF || action == VILLAGER_APPEAR_IN) {
827 continue;
828 }
829
830 duplicate = 0;
831
832 for (j = 0; j < selected_count; j++) {
833 int selected = select_table[j];
834
835 if (selected == index) {
836 duplicate = 1;
837 break;
838 }
839 }
840
841 if (duplicate == 0) {
842 select_table[selected_count++] = index;
843 }
844 }
845
846 for (i = 0; i < 10; i++) {
847 int index = select_table[i];
848
849 if (index < 0) {
850 villagers[i].name[0] = '\0';
851 } else {
852 villagers[i] = map_info->villagers[index];
853 VILLAGER_APPEAR_STATE *state = &appear[select_table[i]];
854
855 if (state->action != VILLAGER_APPEAR_DEFAULT && state->destination >= 0) {
856 villagers[i].initial_motion = state->destination;
857 }
858
859 restore_info[i] = villagers[i];
860 }
861 }
862
863 if (i < 9) {
864 villagers[i].name[0] = '\0';
865 }
866
867 return i;
868}
869
870int EdCheckVillagerIn(int index, VILLAGER_INFO *villager) {
871 if (index < 0 || index >= 16) {
872 return 0;
873 }
874
875 switch (appear[index].action) {
876 case VILLAGER_APPEAR_OFF:
877 case VILLAGER_APPEAR_OUT:
878 return 0;
879 case VILLAGER_APPEAR_DEFAULT:
880 for (int i = 0; i < 10; i++) {
881 if (index == select_table[i]) {
882 return 0;
883 }
884 }
885 case VILLAGER_APPEAR_IN: {
886 int parts_no = villager->character_no;
887
888 if (parts_no < 0) {
889 return 1;
890 }
891
892 EDITPARTS_INFO *parts = EditPartsInfo.GetPartsInfo(parts_no);
893
894 if (parts == NULL) {
895 return 0;
896 }
897
898 int model = villager->model_no;
899
900 if (model < 0) {
901 return 0;
902 }
903
904 return parts->elements[model].enabled != 0 ? 1 : 0;
905 }
906 default:
907 return 0;
908 }
909}
910
911int EdCheckVillager(int index, VILLAGER_INFO *villager, CEditGround *ground) {
912 if (index < 0 || index >= 16) {
913 return 0;
914 }
915
916 if (ground == NULL) {
917 return 0;
918 }
919
920 int parts_no = villager->character_no;
921
922 if (parts_no < 0) {
923 return 1;
924 }
925
926 EDITPARTS_INFO *parts = EditPartsInfo.GetPartsInfo(parts_no);
927
928 if (parts == NULL) {
929 return 0;
930 }
931
932 if (ground->GetPartsObject(villager->character_no) == NULL) {
933 return 0;
934 }
935
936 int model = villager->model_no;
937
938 if (model < 0) {
939 return 0;
940 }
941
942 return parts->elements[model].enabled != 0 ? 1 : 0;
943}
944
945static int GetRandomVillager(VILLAGER_INFO *villagers) {
946 int candidates[10] = {-1};
947 int count = 0;
948 int i;
949
950 for (i = 0; i < 10; i++) {
951 if (villagers[i].placed == 0 && villagers[i].name[0] != '\0') {
952 candidates[count++] = i;
953 }
954 }
955
956 if (count <= 0) {
957 return -1;
958 }
959
960 return candidates[rand() % count];
961}
962
963static int GetRandomMoveVillager(VILLAGER_INFO *villagers) {
964 int candidates[10] = {-1};
965 int count = 0;
966 int i;
967
968 for (i = 0; i < 10; i++) {
969 if (villagers[i].placed == 0 && villagers[i].name[0] != '\0' && villagers[i].initial_motion != 0) {
970 candidates[count++] = i;
971 }
972 }
973
974 if (count <= 0) {
975 return -1;
976 }
977
978 return candidates[rand() % count];
979}
980
981void EdInitVilager(VILLAGER_INFO *villagers, CEditGround *ground, u_long128 *buffer) {
982 VILLAGER_INFO *info[10];
983 char path[64];
984 char directory[64];
985 int size;
986 int i;
987 u_long128 *load_buffer = (u_long128 *) read_buffer;
988
989 if (buffer != NULL) {
990 load_buffer = buffer;
991 }
992
993 for (i = 0; i < 10; i++) {
994 info[i] = &villagers[i];
995 villagers[i].placed = false;
996 EdVillager[i].Initialize();
997 EdVillager[i].texture_block = i + 54;
998 strcpy(EdVillager[i].resource_name, info[i]->name);
999 GetEditDataDir(directory);
1000 sprintf(path, "%schara/%s.chr", directory, info[i]->name);
1001
1002 if (buffer != NULL) {
1003 LoadFileBG(path, load_buffer, &size);
1004 load_buffer += (((size >> 6) + 1) << 6) >> 4;
1005 } else {
1006 EdLoadVillager(info[i]->name, &EdVillager[i], &EdVillagerBuffer);
1007 }
1008 }
1009}
1010
1011int EdLoadVillager(u_int *pack, char *name, CNPCharacter *villager, CDataAlloc2<1> *arena) {
1012 char copied_name[32];
1013 char config_name[32];
1014 int texture_set = villager->texture_block;
1015 strcpy(copied_name, name);
1016 villager->texture_block = texture_set;
1017 strcpy(villager->resource_name, copied_name);
1018
1019 if (GetPackFile(pack, "info.cfg", NULL) != NULL) {
1020 sprintf(config_name, "info.cfg");
1021 } else {
1022 sprintf(config_name, "%s.cfg", name);
1023 }
1024
1025 villager->LoadPackData2(pack, config_name, arena, texture_set, arena, 0);
1026
1027 if (villager->frame != NULL) {
1028 CFrameAttr attr;
1029 attr.clip_enable = false;
1030 attr.fog_enable = true;
1031 villager->frame->SetAttr(attr, 1, 4);
1032 }
1033
1034 villager->initialized = true;
1035 villager->alpha_step = 8;
1036
1037 if (MapNo > 10) {
1038 villager->initialized = true;
1039 villager->draw_enabled = true;
1040 villager->event_status = 0;
1041 villager->ambient_offset[3] = 128.0f;
1042 sceVu0FVECTOR origin = {0.0f, 0.0f, 0.0f, 0.0f};
1043 sceVu0FVECTOR no_rotation = {0.0f, 0.0f, 0.0f, 0.0f};
1044 villager->SetPosition(origin);
1045 villager->SetRotation(no_rotation);
1046 villager->motion_no = 0;
1047 villager->motion_flags = 0;
1048 villager->motion_speed = -1.0f;
1049 }
1050
1051 villager->texture_block = texture_set;
1052 return 1;
1053}
1054
1055int EdLoadVillager(char *name, CNPCharacter *villager, CDataAlloc2<1> *arena) {
1056 char path[64];
1057 char directory[64];
1058
1059 if (name == NULL || *name == '\0') {
1060 return 0;
1061 }
1062
1063 GetEditDataDir(directory);
1064 sprintf(path, "%schara/%s.chr", directory, name);
1065
1066 if (LoadFile2(path, (void *) read_buffer, NULL, 0) != 0) {
1067 return EdLoadVillager(read_buffer, name, villager, arena);
1068 }
1069
1070 return 0;
1071}
1072
1073void EdInitVillagerOnOff(CNPCharacter *characters, VILLAGER_INFO *villagers, CEditGround *ground) {
1074 for (int i = 0; i < 10; i++) {
1075 VILLAGER_INFO *villager = &villagers[i];
1076
1077 if (villager->placed != 0) {
1078 int draw = false;
1079 int parts_no = villager->character_no;
1080
1081 if (parts_no >= 0 && characters[i].villager_id >= 0) {
1082 characters[i].map_parts_no = parts_no;
1083
1084 if (ground->GetPartsObject(villager->character_no) != NULL) {
1085 EDITPARTS_INFO *parts = EditPartsInfo.GetPartsInfo(villager->character_no);
1086
1087 if (parts->obtained > 0 && parts->elements[villager->model_no].enabled != 0) {
1088 draw = true;
1089 }
1090
1091 if (EditPartsInfo.CheckComplete(villager->character_no) != 0 && EditPartsInfo.GetCompEvent(villager->character_no) == 0 && villager->hide_when_complete != 0) {
1092 draw = false;
1093 }
1094 }
1095 } else {
1096 characters[i].map_parts_no = parts_no;
1097 draw = true;
1098 }
1099
1100 characters[i].draw_enabled = draw;
1101 }
1102 }
1103}
1104
1105void EdInitVilagerPosition(CNPCharacter *villagers, VILLAGER_INFO *info, CEditGround *ground, float (*transform)[4]) {
1106 int i;
1107
1108 if (MapNo > 10) {
1109 RestoreVillagerInfo(info);
1110
1111 for (i = 0; i < 10; i++) {
1112 int draw = true;
1113
1114 if (info[i].index >= 0) {
1115 VILLAGER_INFO *entry = &info[i];
1116 sceVu0FVECTOR position;
1117 sceVu0FVECTOR rotation;
1118 sceVu0FVECTOR people_position;
1119
1120 if (ground->GetPeoplePos(entry->index, people_position) != 0) {
1121 rotation[2] = 0.0f;
1122 rotation[0] = 0.0f;
1123 rotation[1] = people_position[3];
1124 people_position[3] = 1.0f;
1125 entry->placed = true;
1126 sceVu0CopyVector(position, people_position);
1127 sceVu0CopyVector(entry->position, position);
1128 sceVu0CopyVector(entry->rotation, rotation);
1129 } else {
1130 draw = false;
1131 }
1132
1133 villagers[i].ClearSeq();
1134 villagers[i].event_status = 0;
1135 villagers[i].villager_id = entry->index;
1136 villagers[i].SetPosition(position);
1137 villagers[i].SetRotation(rotation[0], rotation[1], rotation[2]);
1138 villagers[i].draw_enabled = draw;
1139 }
1140 }
1141
1142 return;
1143 }
1144
1145 int villager_count = 0;
1146
1147 while (info[villager_count].name[0] != '\0') {
1148 villager_count++;
1149 }
1150
1151 RestoreVillagerInfo(info);
1152 int stationary_target = villager_count >> 1;
1153 int moving_target = villager_count - stationary_target;
1154 int random_state = rand();
1155
1156 for (i = 0; i < 10; i++) {
1157 info[i].placed = false;
1158 }
1159
1160 while (info[villager_count].name[0] != '\0') {
1161 villager_count++;
1162 }
1163
1164 int stationary_count = 0;
1165
1166 for (i = 0; i < 10; i++) {
1167 if (info[i].placed == 0 && info[i].initial_motion == 0) {
1168 stationary_count++;
1169 info[i].placed = true;
1170
1171 if (stationary_count >= stationary_target) {
1172 break;
1173 }
1174 }
1175 }
1176
1177 while (stationary_count < stationary_target) {
1178 int index = GetRandomVillager(info);
1179 info[index].placed = true;
1180 info[index].initial_motion = 0;
1181 stationary_count++;
1182 }
1183
1184 int moving_count = 0;
1185
1186 while (moving_count < moving_target) {
1187 int selected = GetRandomMoveVillager(info);
1188
1189 if (selected < 0) {
1190 break;
1191 }
1192
1193 info[selected].placed = true;
1194 info[selected].initial_motion = 1;
1195 int failed = 0;
1196 int avoid_count = 0;
1197 sceVu0FVECTOR avoid_positions[11];
1198
1199 if (transform != NULL) {
1200 sceVu0CopyVector(avoid_positions[avoid_count++], *transform);
1201 }
1202
1203 for (i = 0; i < 10; i++) {
1204 if (info[selected].initial_motion != 0) {
1205 sceVu0CopyVector(avoid_positions[avoid_count++], info[i].position);
1206 }
1207 }
1208
1209 for (i = 0; i < avoid_count; i++) {
1210 avoid_positions[i][3] = 200.0f;
1211 }
1212
1213 sceVu0FVECTOR random_position;
1214 sceVu0FVECTOR reference;
1215 reference[3] = -1.0f;
1216 CMapObject *object = ground->GetPartsObject(info[selected].character_no);
1217
1218 if (object != NULL) {
1219 sceVu0CopyVector(reference, object->pos);
1220 reference[3] = 200.0f;
1221 }
1222
1223 for (;;) {
1224 if (ground->GetRandomPlanePos(random_position, avoid_positions, avoid_count, reference) != 0) {
1225 sceVu0CopyVector(info[selected].position, random_position);
1226 break;
1227 }
1228
1229 if (reference[3] > 500.0f) {
1230 reference[3] = -1.0f;
1231
1232 if (ground->GetRandomPlanePos(random_position, avoid_positions, avoid_count, reference) != 0) {
1233 sceVu0CopyVector(info[selected].position, random_position);
1234 break;
1235 }
1236
1237 failed = 1;
1238 break;
1239 }
1240
1241 reference[3] += 100.0f;
1242 }
1243
1244 if (failed != 0) {
1245 info[selected].placed = false;
1246 }
1247
1248 moving_count++;
1249 }
1250
1251 int selected = GetRandomVillager(info);
1252
1253 while (selected >= 0) {
1254 info[selected].placed = true;
1255 info[selected].initial_motion = 0;
1256 selected = GetRandomVillager(info);
1257 }
1258
1259 for (i = 0; i < 10; i++) {
1260 VILLAGER_INFO *entry = &info[i];
1261
1262 if (entry->placed != 0) {
1263 sceVu0FVECTOR position;
1264 sceVu0FVECTOR rotation;
1265 sceVu0CopyVector(position, entry->position);
1266 sceVu0CopyVector(rotation, entry->rotation);
1267 int draw = false;
1268 int parts_no = entry->character_no;
1269
1270 if (parts_no >= 0) {
1271 villagers[i].map_parts_no = parts_no;
1272
1273 if (ground->GetPartsObject(entry->character_no) != NULL) {
1274 EDITPARTS_INFO *parts = EditPartsInfo.GetPartsInfo(entry->character_no);
1275
1276 if (parts->obtained > 0 && parts->elements[entry->model_no].enabled != 0) {
1277 draw = true;
1278 }
1279
1280 if (EditPartsInfo.CheckComplete(entry->character_no) != 0 && EditPartsInfo.GetCompEvent(entry->character_no) == 0 && entry->hide_when_complete != 0) {
1281 draw = false;
1282 }
1283 }
1284 } else {
1285 villagers[i].map_parts_no = parts_no;
1286 draw = true;
1287 }
1288
1289 if (entry->initial_motion == 0) {
1290 sceVu0FVECTOR people_position;
1291
1292 if (ground->GetPeoplePos(entry->index, people_position) != 0) {
1293 rotation[2] = 0.0f;
1294 rotation[0] = 0.0f;
1295 rotation[1] = people_position[3];
1296 people_position[3] = 1.0f;
1297 sceVu0CopyVector(position, people_position);
1298 sceVu0CopyVector(entry->position, position);
1299 sceVu0CopyVector(entry->rotation, rotation);
1300 } else {
1301 draw = false;
1302 }
1303 }
1304
1305 CNPCharacter *character = &villagers[i];
1306 character->ClearSeq();
1307 villagers[i].event_status = entry->initial_motion;
1308 villagers[i].villager_id = entry->index;
1309 character->SetPosition(position);
1310 character->SetRotation(rotation[0], rotation[1], rotation[2]);
1311 villagers[i].draw_enabled = draw;
1312 villagers[i].SetMotion(0, 0);
1313 }
1314 }
1315
1316 srand(random_state);
1317}
1318
1319static void GetNearVill(CCamera *camera, CCharacter *player, CNPCharacter *villagers, int *indices, float *distances) {
1320 sceVu0FVECTOR player_position;
1321 sceVu0FVECTOR camera_direction;
1322 sceVu0FVECTOR camera_offset;
1323 sceVu0FVECTOR camera_position;
1324 sceVu0FVECTOR villager_position;
1325
1326 player->GetPosition(player_position);
1327 camera->GetDir(camera_direction);
1328 camera->GetPos(camera_position);
1329 int i;
1330
1331 for (i = 0; i < 10; i++) {
1332 indices[i] = i;
1333 distances[i] = -1.0f;
1334
1335 if (villagers[i].near_camera != 0) {
1336 villagers[i].near_camera = false;
1337 villagers[i].GetPosition(villager_position);
1338 sceVu0SubVector(camera_offset, villager_position, camera_position);
1339
1340 if (sceVu0InnerProduct(camera_offset, camera_direction) > 0.0f) {
1341 distances[i] = DistVector(player_position, villager_position);
1342 }
1343 }
1344 }
1345
1346 i = 0;
1347
1348 while (i < 9) {
1349 int compare_index = i + 1;
1350
1351 while (compare_index < 10) {
1352 if (distances[compare_index] >= 0.0f) {
1353 if (distances[i] > distances[compare_index] || distances[i] < 0.0f) {
1354 int index = indices[i];
1355 indices[i] = indices[compare_index];
1356 indices[compare_index] = index;
1357 float distance = distances[i];
1358 distances[i] = distances[compare_index];
1359 distances[compare_index] = distance;
1360 }
1361 }
1362
1363 compare_index++;
1364 }
1365
1366 i++;
1367 }
1368}
1369
1370static void EdSetVillagerNextPos(CNPCharacter *villager, VILLAGER_INFO *info, CEditGround *ground);
1371
1379void EdMoveVillager(VILLAGER_INFO *villagers) {
1380 CEditGround *ground = EdExchangeInfo.ground;
1381 CCharacter *player = EdExchangeInfo.player;
1382 CCamera *camera = EdExchangeInfo.camera;
1383 int i;
1384
1385 for (i = 0; i < 10; i++) {
1386 int offset;
1387 s32 *near_camera;
1388 sceVu0FVECTOR position;
1389 sceVu0FVECTOR rotation;
1390 offset = i * (int) sizeof(CNPCharacter);
1391 near_camera = (s32 *) ((char *) &EdVillager->near_camera + offset);
1392 *near_camera = false;
1393 VILLAGER_INFO *info = &villagers[i];
1394
1395 if (info->placed == 0) {
1396 continue;
1397 }
1398
1399 sceVu0CopyVector(position, info->position);
1400 sceVu0CopyVector(rotation, info->rotation);
1401
1402 if (info->character_no >= 0 && (*(s32 *) ((char *) &EdVillager->draw_enabled + offset)) == 0) {
1403 continue;
1404 }
1405
1406 if (info->character_no >= 0 && info->initial_motion == 0) {
1407 EDITPARTS_INFO *parts = EditPartsInfo.GetPartsInfo(info->character_no);
1408
1409 if (parts->obtained == 0 || parts->elements[info->model_no].enabled == 0) {
1410 continue;
1411 }
1412
1413 *near_camera = true;
1414 sceVu0CopyVector(position, info->position);
1415 sceVu0CopyVector(rotation, info->rotation);
1416 } else {
1417 *near_camera = true;
1418 sceVu0CopyVector(position, info->position);
1419 sceVu0CopyVector(rotation, info->rotation);
1420 }
1421
1422 if (info->initial_motion == 0) {
1423 ((CCharacter *) ((char *) EdVillager + offset))->CCharacter::SetPosition(position);
1424 ((CCharacter *) ((char *) EdVillager + offset))->CCharacter::SetRotation(rotation[0], rotation[1], rotation[2]);
1425 } else {
1426 sceVu0FVECTOR player_position;
1427 sceVu0FVECTOR villager_position;
1428 player->GetPosition(player_position);
1429 CNPCharacter *npc = (CNPCharacter *) ((char *) EdVillager + offset);
1430 sceVu0CopyVector(villager_position, npc->pos);
1431 float distance = DistVector(player_position, villager_position);
1432 (*(s32 *) ((char *) &EdVillager->sequence_enabled + offset)) = 1;
1433
1434 if (distance < 20.0f) {
1435 (*(s32 *) ((char *) &EdVillager->sequence_enabled + offset)) = 0;
1436 *(s32 *) ((char *) &EdVillager->motion_no + offset) = 0;
1437 *(s32 *) ((char *) &EdVillager->motion_flags + offset) = 0;
1438 *(float *) ((char *) &EdVillager->motion_speed + offset) = -1.0f;
1439 }
1440
1441 EdSetVillagerNextPos(npc, info, ground);
1442 }
1443 }
1444
1445 int indices[10];
1446 float distances[10];
1447 GetNearVill(camera, player, EdVillager, indices, distances);
1448
1449 for (int j = 0; j < 2; j++) {
1450 if (distances[j] < 0.0f) {
1451 break;
1452 }
1453
1454 if (distances[j] < 150.0f) {
1455 EdVillager[indices[j]].near_camera = true;
1456 }
1457 }
1458
1459 for (i = 0; i < 10; i++) {
1460 EdVillager[i].Step();
1461 EdVillager[i].ShadowStep();
1462 EdVillager[i].ClothStep(0);
1463
1464 if (EdVillager[i].event_status != 0) {
1465 sceVu0FVECTOR position;
1466 sceVu0FVECTOR hit;
1467 sceVu0CopyVector(position, EdVillager[i].pos);
1468 float altitude = ground->GetAlt(position[0], position[1], position[2]);
1469 EdVillager[i].SetPosition(position[0], altitude, position[2]);
1470 EdVillager[i].FootSoundEnable(0);
1471
1472 if (EdVillager[i].CheckDraw()) {
1473 EdVillager[i].FootSoundEnable(1);
1474 WorkBuffer__2->used = 0;
1475 CCPoly *polys = (CCPoly *) WorkBuffer__2->Alloc(2000);
1476 int count = ground->PickUpEditAreaPoly(polys, position[0], position[1], position[2]);
1477 CMapParts *parts = ground->GetParts(position[0], position[1], position[2]);
1478
1479 if (parts != NULL) {
1480 CBoxVu0 box;
1481 box.max[0] = position[0] + 20.0f;
1482 box.min[0] = position[0] - 20.0f;
1483 box.max[2] = position[2] + 20.0f;
1484 box.min[2] = position[2] - 20.0f;
1485 box.max[1] = 1000.0f;
1486 box.min[1] = -1000.0f;
1487 CFrame *frame = parts->GetCollisionFrame();
1488
1489 if (frame != NULL) {
1490 count += frame->PickUpNearPoly(polys + count, box);
1491 }
1492 }
1493
1494 if (count > 0) {
1495 CCPoly poly;
1496 position[1] += 30.0f;
1497
1498 if (GetFootPoly(position, 1000.0f, &poly, hit, polys, count, 0)) {
1499 altitude = hit[1];
1500 EdVillager[i].SetFootSoundID(poly.attr.foot_sound);
1501 }
1502 }
1503
1504 position[1] = altitude;
1505 EdVillager[i].SetPosition(position);
1506 }
1507 }
1508 }
1509}
1510
1511void EdMoveVillagerSubMap(VILLAGER_INFO *villagers) {
1512 CCharacter *player = EdExchangeInfo.player;
1513 CCamera *camera = EdExchangeInfo.camera;
1514 int i;
1515
1516 for (i = 0; i < 10; i++) {
1517 if (EdVillager[i].villager_id >= 0) {
1518 EdVillager[i].near_camera = false;
1519 EdVillager[i].SetPosition(villagers[i].position);
1520 EdVillager[i].SetRotation(villagers[i].rotation);
1521
1522 if (EdVillager[i].frame != NULL) {
1523 EdVillager[i].near_camera = true;
1524 }
1525 }
1526 }
1527
1528 int indices[10];
1529 float distances[10];
1530 GetNearVill(camera, player, EdVillager, indices, distances);
1531
1532 for (int i = 0; i < 2; i++) {
1533 if (distances[i] < 0.0f) {
1534 break;
1535 }
1536
1537 if (distances[i] < 150.0f) {
1538 EdVillager[indices[i]].near_camera = true;
1539 }
1540 }
1541
1542 for (i = 0; i < 10; i++) {
1543 if (EdVillager[i].villager_id < 0) {
1544 EdVillager[i].near_camera = true;
1545 }
1546
1547 EdVillager[i].Step();
1548 EdVillager[i].ShadowStep();
1549 EdVillager[i].ClothStep(0);
1550 }
1551}
1552
1553static void EdSetVillagerNextPos(CNPCharacter *villager, VILLAGER_INFO *info, CEditGround *ground) {
1554 if (villager->CheckSeq() != 0) {
1555 return;
1556 }
1557
1558 sceVu0FVECTOR rotation;
1559 sceVu0FVECTOR position;
1560 sceVu0FVECTOR nearby_positions[10];
1561 sceVu0FVECTOR nearby_offsets[10];
1562 float nearby_distances[10];
1563 sceVu0FVECTOR directions[4] = {
1564 {0.0f, 0.0f, 100.0f, 0.0f},
1565 {100.0f, 0.0f, 0.0f, 0.0f},
1566 {0.0f, 0.0f, -100.0f, 0.0f},
1567 {-100.0f, 0.0f, 0.0f, 0.0f},
1568 };
1569 int weights[5];
1570 int i;
1571 villager->GetPosition(position);
1572 villager->GetRotation(rotation);
1573
1574 int nearby_count = 0;
1575
1576 for (i = 0; i < 10; i++) {
1577 CNPCharacter *other = &EdVillager[i];
1578
1579 if (villager != other) {
1580 int active = other->initialized != 0 && other->draw_enabled != 0;
1581
1582 if (active && other->event_status != 0) {
1583 other->GetPosition(nearby_positions[nearby_count]);
1584 sceVu0SubVector(nearby_offsets[nearby_count], nearby_positions[nearby_count], position);
1585 float distance = DistVector(nearby_offsets[nearby_count]);
1586 float *slot = &nearby_distances[nearby_count];
1587 *slot = distance;
1588
1589 if (distance <= 210.0f) {
1590 nearby_count++;
1591 }
1592 }
1593 }
1594 }
1595
1596 int facing = 0;
1597
1598 if (rotation[1] >= -QUARTER_PI_SHORT && rotation[1] < QUARTER_PI_SHORT) {
1599 facing = 0;
1600 }
1601
1602 if (rotation[1] >= QUARTER_PI_SHORT && rotation[1] < 2.356194f) {
1603 facing = 1;
1604 }
1605
1606 if (rotation[1] >= 2.356194f || rotation[1] < -2.356194f) {
1607 facing = 2;
1608 }
1609
1610 if (rotation[1] >= -2.356194f && rotation[1] < -QUARTER_PI_SHORT) {
1611 facing = 3;
1612 }
1613
1614 weights[0] = 40;
1615 weights[1] = 20;
1616 weights[2] = 5;
1617 weights[3] = 20;
1618 weights[4] = 15;
1619 int total = weights[4];
1620 CMapParts *current_parts = ground->GetParts(position[0], position[1], position[2]);
1621
1622 for (i = 0; i < 4; i++) {
1623 int blocked;
1624 int direction = i + facing;
1625
1626 if (direction > 3) {
1627 direction -= 4;
1628 }
1629
1630 float *offset = directions[direction];
1631 sceVu0FVECTOR destination;
1632 sceVu0AddVector(destination, position, offset);
1633 int weight = weights[i];
1634 weights[i] = 0;
1635 blocked = 0;
1636
1637 for (int j = 0; j < nearby_count; j++) {
1638 if ((float) (int) sceVu0InnerProduct(nearby_offsets[j], offset) > 0.0f) {
1639 blocked = 1;
1640 break;
1641 }
1642 }
1643
1644 if (blocked == 0) {
1645 CBoxVu0 box;
1646 ground->GetPartsBox(&box, destination[0], destination[1], destination[2]);
1647 box.max[0] += 200.0f;
1648 box.max[2] += 200.0f;
1649 box.min[0] -= 200.0f;
1650 box.min[2] -= 200.0f;
1651
1652 if (destination[0] <= box.max[0] && destination[0] >= box.min[0] && destination[2] <= box.max[2] && destination[2] >= box.min[2]) {
1653 CMapParts *next_parts = ground->GetParts(destination[0], destination[1], destination[2]);
1654
1655 if (next_parts == NULL && ground->GetAreaCode(destination[0], destination[1], destination[2]) >= 0) {
1656 weight /= 5;
1657
1658 if (weight <= 0) {
1659 weight = 1;
1660 }
1661
1662 total += weight;
1663 weights[i] = weight;
1664 }
1665
1666 if (next_parts != NULL && (next_parts->subtype == MAP_PARTS_SUBTYPE_ROAD || (current_parts != NULL && current_parts->subtype != MAP_PARTS_SUBTYPE_BRIDGE && next_parts->subtype == MAP_PARTS_SUBTYPE_BRIDGE))) {
1667 total += weight;
1668 weights[i] = weight;
1669 }
1670 }
1671 }
1672 }
1673
1674 for (i = 0; i < 5; i++) {
1675 weights[i] = weights[i] * 100 / total;
1676 }
1677
1678 for (i = 1; i < 5; i++) {
1679 weights[i] = weights[i] + weights[i - 1];
1680 }
1681
1682 for (i = 0; i < 5; i++) {
1683 if (weights[i] == 0) {
1684 weights[i] = -1;
1685 }
1686 }
1687
1688 int random = rand() % 100;
1689
1690 for (i = 0; i < 4; i++) {
1691 if (random < weights[i]) {
1692 break;
1693 }
1694 }
1695
1696 if (i < 4) {
1697 int direction = i + facing;
1698
1699 if (direction > 3) {
1700 direction -= 4;
1701 }
1702
1703 sceVu0FVECTOR destination;
1704 sceVu0AddVector(destination, position, directions[direction]);
1705 villager->SetSeq(destination, info->move_speed);
1706 return;
1707 }
1708
1709 villager->SetWait(60);
1710}
1711
1712int EdCheckTime(float time, float start, float end) {
1713 if (!(start <= end) && !(start <= time) && end <= time) {
1714 return 0;
1715 }
1716
1717 if (start < end && (!(start <= time) || end <= time)) {
1718 return 0;
1719 }
1720
1721 return 1;
1722}
1723
1724int EdGetTime(float time) {
1725 int period;
1726 float period_end;
1727
1728 period = (int) (time / 3.0f);
1729
1730 if (EdCheckTime(time, 11.5f, 2.5f) != 0) {
1731 period = ED_TIME_DAY;
1732 }
1733
1734 if (EdCheckTime(time, 2.5f, 5.5f) != 0) {
1735 period = ED_TIME_EVENING;
1736 }
1737
1738 if (EdCheckTime(time, 5.5f, 8.5f) != 0) {
1739 period = ED_TIME_NIGHT;
1740 }
1741
1742 if (EdCheckTime(time, 8.5f, 11.5f) != 0) {
1743 period = ED_TIME_MORNING;
1744 }
1745
1746 return period;
1747}
1748
1749void EdLimitShadowLight(float light[][4], float scale) {
1750 light[1][0] = light[1][0] * scale;
1751
1752 if (light[1][0] < 1.0f) {
1753 light[1][0] = 1.0f;
1754 }
1755}
1756
1757void EdDrawSky(float clock, CFrameVu1 **sky, CFrame **sun, CFrameVu1 *clouds, CCamera *camera, int *follow_axes) {
1758 sceVu0FVECTOR ambient;
1759 sceVu0FVECTOR old_ambient;
1760 sceVu0FMATRIX identity;
1761 sceVu0FVECTOR position;
1762 sceVu0FVECTOR cloud_position;
1763
1764 sceVu0UnitMatrix(identity);
1765 identity[3][1] = 2100.0f;
1766
1767 CFrameVu1 *current_sky;
1768 CFrameVu1 *following_sky;
1769 int transition;
1770 int sky_index;
1771 int next_sky;
1772 int next_sun;
1773 CFrame *current_sun;
1774 CFrame *moon;
1775 int sun_index;
1776 CFrame *following_sun;
1777 int previous_sky;
1778
1779 sky_index = (int) (clock / 3.0f);
1780 next_sky = sky_index + 1;
1781 previous_sky = sky_index - 1;
1782
1783 if (EditMapInfo->time_stop != 0) {
1784 clock = 0.0f;
1785 sky_index = 0;
1786 next_sky = 0;
1787 previous_sky = 0;
1788 }
1789
1790 if (next_sky > 3) {
1791 next_sky = 0;
1792 }
1793
1794 if (previous_sky < 0) {
1795 previous_sky = (int) previous_sky;
1796 }
1797
1798 current_sky = sky[sky_index];
1799 following_sky = sky[next_sky];
1800
1801 if (current_sky != NULL && following_sky == NULL) {
1802 following_sky = (CFrameVu1 *) following_sky;
1803 }
1804
1805 camera->GetPos(position);
1806
1807 if (follow_axes[0] == 0) {
1808 position[0] = 0.0f;
1809 }
1810
1811 if (follow_axes[1] == 0) {
1812 position[1] = 0.0f;
1813 }
1814
1815 if (follow_axes[2] == 0) {
1816 position[2] = 0.0f;
1817 }
1818
1819 sceVu0CopyVector(cloud_position, position);
1820 cloud_position[1] -= 50.0f;
1821
1822 mgRenderInfo.unlit = 1;
1823
1824 if (clouds != NULL) {
1825 clouds->SetPosition(cloud_position);
1826 }
1827
1828 if (clouds != NULL) {
1829 clouds->SetScale(1.0f, 1.0f, 1.0f);
1830 }
1831
1832 MGDraw(clouds);
1833
1834 if (clouds != NULL) {
1835 clouds->SetPosition(cloud_position);
1836 }
1837
1838 if (clouds != NULL) {
1839 clouds->SetScale(1.0f, -1.0f, 1.0f);
1840 }
1841
1842 MGDraw(clouds);
1843 mgRenderInfo.unlit = 0;
1844
1845 MGGetAmbient(old_ambient);
1846 sceVu0CopyVector(ambient, old_ambient);
1847 transition = 0;
1848 sun_index = 2;
1849
1850 if (clock >= 9.0f && clock < 12.0f) {
1851 sun_index = 3;
1852 }
1853
1854 if (clock >= 0.0f && clock < 3.5f) {
1855 sun_index = 0;
1856 }
1857
1858 if (clock >= 3.5f && clock < 5.5f) {
1859 sun_index = 1;
1860 }
1861
1862 next_sun = sun_index + 1;
1863
1864 if (next_sun > 3) {
1865 next_sun = 0;
1866 }
1867
1868 current_sun = sun[sun_index];
1869 following_sun = sun[next_sun];
1870 moon = sun[2];
1871
1872 if (EditMapInfo->time_stop != 0) {
1873 next_sun = 0;
1874 sun_index = 0;
1875 following_sun = sun[0];
1876 current_sun = following_sun;
1877 moon = following_sun;
1878 }
1879
1880 if (current_sun != NULL && following_sun != NULL && moon == NULL) {
1881 moon = (CFrame *) moon;
1882 }
1883
1884 if (clock > 11.5f && clock < 12.0f) {
1885 ambient[3] = 2.0f * (128.0f * (12.0f - clock));
1886 transition = 1;
1887 }
1888
1889 if (clock > 3.0f && clock < 3.5f) {
1890 ambient[3] = 2.0f * (128.0f * (3.5f - clock));
1891 transition = 1;
1892 }
1893
1894 float *ambient_alpha = &ambient[3];
1895 float alpha = *ambient_alpha;
1896 float adjusted_clock = clock;
1897
1898 if (clock > 10.0f) {
1899 adjusted_clock = clock - 12.0f;
1900 }
1901
1902 float sun_rotation = PI_SHORT * ((2.0f + adjusted_clock) / 6.0f) - HALF_PI;
1903
1904 if (sun_rotation > PI_SHORT) {
1905 sun_rotation -= TWO_PI_SHORT;
1906 }
1907
1908 float moon_rotation = 1.2f * (PI_SHORT * ((clock - 4.0f) / 6.0f) - HALF_PI);
1909
1910 if (sun_index != 2) {
1911 float absolute_rotation = sun_rotation < 0.0f ? -sun_rotation : sun_rotation;
1912
1913 if (absolute_rotation < 1.57f) {
1914 TexManager.ReloadTexture(Vif1Packet, 7);
1915
1916 if (transition != 0) {
1917 *ambient_alpha = 128.0f - alpha;
1918 MGSetAmbient(ambient);
1919
1920 if (next_sun != 2 && following_sun != NULL) {
1921 following_sun->SetTransMatrix(identity);
1922 following_sun->SetRotation(0.0f, 0.0f, sun_rotation);
1923 following_sun->SetPosition(position);
1924 MGDraw(following_sun);
1925 }
1926 }
1927
1928 *ambient_alpha = alpha;
1929
1930 if (sun_index != 2 && current_sun != NULL) {
1931 current_sun->SetTransMatrix(identity);
1932 MGSetAmbient(ambient);
1933 current_sun->SetRotation(0.0f, 0.0f, sun_rotation);
1934 current_sun->SetPosition(position);
1935 MGDraw(current_sun);
1936 }
1937 }
1938 }
1939
1940 mgRenderInfo.unlit = 1;
1941
1942 if (clouds != NULL) {
1943 clouds->SetPosition(cloud_position);
1944 }
1945
1946 if (clouds != NULL) {
1947 clouds->SetScale(1.0f, -1.0f, 1.0f);
1948 }
1949
1950 MGDraw(clouds);
1951 mgRenderInfo.unlit = 0;
1952
1953 *ambient_alpha = 128.0f;
1954 transition = 0;
1955
1956 if (clock > 2.0f && clock < 3.0f) {
1957 *ambient_alpha = 128.0f * (3.0f - clock);
1958 transition = 1;
1959 }
1960
1961 if (clock > 5.0f && clock < 6.0f) {
1962 *ambient_alpha = 128.0f * (6.0f - clock);
1963 transition = 1;
1964 }
1965
1966 if (clock > 8.0f && clock < 9.0f) {
1967 *ambient_alpha = 128.0f * (9.0f - clock);
1968 transition = 1;
1969 }
1970
1971 if (clock > 11.0f) {
1972 *ambient_alpha = 128.0f * (12.0f - clock);
1973 transition = 1;
1974 }
1975
1976 float sky_alpha = ambient[3];
1977
1978 if (transition != 0) {
1979 *ambient_alpha = 128.0f - sky_alpha;
1980 MGSetAmbient(ambient);
1981 TexManager.ReloadTexture(Vif1Packet, next_sky + 3);
1982
1983 if (following_sky != NULL) {
1984 following_sky->SetPosition(position);
1985 }
1986
1987 MGDraw(following_sky);
1988 }
1989
1990 *ambient_alpha = sky_alpha;
1991 MGSetAmbient(ambient);
1992 TexManager.ReloadTexture(Vif1Packet, sky_index + 3);
1993
1994 if (current_sky != NULL) {
1995 current_sky->SetPosition(position);
1996 }
1997
1998 MGDraw(current_sky);
1999 MGSetAmbient(old_ambient);
2000
2001 if (sun_index == 2 && moon != NULL) {
2002 *ambient_alpha = 0.0f;
2003
2004 if (clock > 5.5f && clock < 9.0) {
2005 TexManager.ReloadTexture(Vif1Packet, 7);
2006 *ambient_alpha = 128.0f;
2007
2008 if (clock > 5.5f && clock < 6.0f) {
2009 *ambient_alpha = 128.0f - 2.0f * (128.0f * (6.0f - clock));
2010 }
2011
2012 if (clock > 8.5f && clock < 9.0f) {
2013 *ambient_alpha = 2.0f * (128.0f * (9.0f - clock));
2014 }
2015
2016 MGSetAmbient(ambient);
2017 moon->SetTransMatrix(identity);
2018 moon->SetRotation(0.0f, 0.0f, moon_rotation);
2019 moon->SetPosition(position);
2020 MGDraw(moon);
2021 }
2022 }
2023
2024 MGSetAmbient(old_ambient);
2025}
2026
2027void EdDrawLensFlare(float time, CFrame **sky) {
2028 int sky_index = (int) (time / 3.0f);
2029
2030 if (!EdCheckTime(time, (0, 10.0f), 4.0f)) {
2031 return;
2032 }
2033
2034 CFrame **sky_slot = &sky[sky_index];
2035
2036 if (*sky_slot == NULL) {
2037 return;
2038 }
2039
2040 sceVu0FVECTOR position;
2041 int screen[4];
2042 sceVu0FVECTOR origin = {0.0f, 0.0f, 0.0f, 1.0f};
2043 CFrame *light = NULL;
2044
2045 if (sky_index == 0) {
2046 light = (*sky_slot)->SearchFrame("sun1");
2047 }
2048
2049 if (sky_index == 1) {
2050 light = (*sky_slot)->SearchFrame("sun2");
2051 }
2052
2053 if (sky_index == 3) {
2054 light = (*sky_slot)->SearchFrame("moon");
2055 }
2056
2057 if (light != NULL) {
2058 light->GetWorldPosition(position, origin);
2059 }
2060
2061 if (position[1] < -100.0f) {
2062 return;
2063 }
2064
2065 float fraction = time - (int) time;
2066 float inverse = 1.0f - fraction;
2067 int current = (int) time;
2068 int next = current + 1;
2069
2070 if (next >= 12) {
2071 next = 0;
2072 }
2073
2074 static float color[12][3] = {
2075 {255.0f, 255.0f, 255.0f},
2076 {255.0f, 255.0f, 255.0f},
2077 {255.0f, 255.0f, 255.0f},
2078 {255.0f, 128.0f, 0.0f },
2079 {255.0f, 128.0f, 0.0f },
2080 {255.0f, 128.0f, 0.0f },
2081 {255.0f, 255.0f, 255.0f},
2082 {255.0f, 255.0f, 255.0f},
2083 {255.0f, 255.0f, 255.0f},
2084 {255.0f, 255.0f, 255.0f},
2085 {255.0f, 255.0f, 255.0f},
2086 {255.0f, 255.0f, 255.0f}
2087 };
2088 unsigned char red = (unsigned char) (color[current][0] * inverse + color[next][0] * fraction);
2089 unsigned char green = (unsigned char) (color[current][1] * inverse + color[next][1] * fraction);
2090 unsigned char blue = (unsigned char) (color[current][2] * inverse + color[next][2] * fraction);
2091
2092 if (!MGRotTransPers2D(screen, position, 0)) {
2093 return;
2094 }
2095
2096 mgPickZBuff->enable = true;
2097 mgPickZBuff->x = screen[0];
2098 mgPickZBuff->y = screen[1];
2099
2100 if (mgPickZBuff->z >= 0) {
2101 if (mgPickZBuff->z > screen[2] + 100) {
2102 return;
2103 }
2104
2105 TexManager.ReloadTexture(GetVif1Packet(), 23);
2106 CTexture *texture = TexManager.GetTexture("lensfler", 23);
2107
2108 if (texture != NULL) {
2109 LensFlare(texture, position, red, green, blue);
2110 }
2111 }
2112}
2113
2114void EdSetLightParam(float clock, int fixed, EDIT_MAP_INFO *info, CFrameVu1 *sky) {
2115 int current = (int) clock;
2116 int next = (int) clock + 1;
2117
2118 if (info->time_stop != 0) {
2119 next = current;
2120 }
2121
2122 float current_weight = (float) next - clock;
2123 float next_weight = 1.0f - current_weight;
2124
2125 if (next >= 12) {
2126 next = 0;
2127 }
2128
2129 EDIT_FOG_INFO fixed_fog;
2130 EDIT_FOG_INFO *current_fog;
2131 EDIT_FOG_INFO *next_fog;
2132 sceVu0FVECTOR background;
2133 sceVu0FVECTOR current_background;
2134 sceVu0FVECTOR next_background;
2135
2136 if (fixed != 0) {
2137 float zero = 0.0f;
2138 MGSetBGColor(zero, zero, zero, zero = 0.0f);
2139 fixed_fog = info->fog[current];
2140 fixed_fog.far_distance *= 10.0f;
2141 fixed_fog.near_distance *= 10.0f;
2142 current_fog = &fixed_fog;
2143 next_fog = current_fog;
2144 } else {
2145 current_fog = &info->fog[current];
2146 next_fog = &info->fog[next];
2147 sceVu0CopyVector(current_background, info->background_colour[current]);
2148 sceVu0CopyVector(next_background, info->background_colour[next]);
2149 sceVu0ScaleVector(current_background, current_background, current_weight);
2150 sceVu0ScaleVector(next_background, next_background, next_weight);
2151 sceVu0AddVector(background, current_background, next_background);
2152 MGSetBGColor(background[0], background[1], background[2], background[3]);
2153 }
2154
2155 float fog_near = current_fog->near_distance * current_weight + next_fog->near_distance * next_weight;
2156 float fog_far = current_fog->far_distance * current_weight + next_fog->far_distance * next_weight;
2157 float fog_red = current_fog->red * current_weight + next_fog->red * next_weight;
2158 float fog_green = current_fog->green * current_weight + next_fog->green * next_weight;
2159 float fog_blue = current_fog->blue * current_weight + next_fog->blue * next_weight;
2160 (unsigned char) fog_red;
2161 (unsigned char) fog_green;
2162 (unsigned char) fog_blue;
2163 float fog_intensity = current_fog->intensity * current_weight + next_fog->intensity * next_weight;
2164 float fog_exponent = current_fog->exponent * current_weight + next_fog->exponent * next_weight;
2165 MGSetFogParm(fog_near, fog_far, (unsigned char) fog_red, (unsigned char) fog_green, (unsigned char) fog_blue, fog_intensity, fog_exponent);
2166
2167 sceVu0FVECTOR ambient;
2168 sceVu0FVECTOR current_ambient;
2169 sceVu0FVECTOR next_ambient;
2170 sceVu0CopyVector(current_ambient, info->ambient[current]);
2171 sceVu0CopyVector(next_ambient, info->ambient[next]);
2172 sceVu0ScaleVector(current_ambient, current_ambient, current_weight);
2173 sceVu0ScaleVector(next_ambient, next_ambient, next_weight);
2174 sceVu0AddVector(ambient, current_ambient, next_ambient);
2175 MGSetAmbient(ambient);
2176
2177 sceVu0FMATRIX direction;
2178 sceVu0FMATRIX current_direction;
2179 sceVu0FMATRIX next_direction;
2180 sceVu0FMATRIX colour;
2181 sceVu0FMATRIX current_colour;
2182 sceVu0FMATRIX next_colour;
2183 sceVu0CopyMatrix(current_colour, info->light_colour[current]);
2184 sceVu0CopyMatrix(next_colour, info->light_colour[next]);
2185 sceVu0TransposeMatrix(current_direction, info->light_direction[current]);
2186 sceVu0TransposeMatrix(next_direction, info->light_direction[next]);
2187
2188 for (int i = 0; i < 4; i++) {
2189 sceVu0ScaleVector(current_colour[i], current_colour[i], current_weight);
2190 sceVu0ScaleVector(next_colour[i], next_colour[i], next_weight);
2191 sceVu0AddVector(colour[i], current_colour[i], next_colour[i]);
2192 sceVu0ScaleVector(current_direction[i], current_direction[i], current_weight);
2193 sceVu0ScaleVector(next_direction[i], next_direction[i], next_weight);
2194 sceVu0AddVector(direction[i], current_direction[i], next_direction[i]);
2195 }
2196
2197 sceVu0Normalize(direction[0], direction[0]);
2198 sceVu0Normalize(direction[1], direction[1]);
2199 sceVu0Normalize(direction[2], direction[2]);
2200 sceVu0Normalize(direction[3], direction[3]);
2201 sceVu0TransposeMatrix(direction, direction);
2202 MGSetPLight(direction, colour);
2203
2204 if (sky != NULL) {
2205 CVisualVu1 *visual = sky->GetVisual();
2206
2207 if (visual != NULL) {
2208 MDT_HEADER *model = (MDT_HEADER *) visual->GetMDTDataAddress();
2209
2210 if (model != NULL && model->colour_count != 0) {
2211 sceVu0FVECTOR *vertices = (sceVu0FVECTOR *) ((char *) model + model->colour_ofs);
2212 sceVu0FVECTOR primary;
2213 sceVu0FVECTOR secondary;
2214 sceVu0FVECTOR second_current;
2215 sceVu0FVECTOR second_next;
2216 MGGetBGColor(primary);
2217 sceVu0CopyVector(second_current, info->background_colour_2[current]);
2218 sceVu0CopyVector(second_next, info->background_colour_2[next]);
2219 sceVu0ScaleVector(second_current, second_current, current_weight);
2220 sceVu0ScaleVector(second_next, second_next, next_weight);
2221 sceVu0AddVector(secondary, second_current, second_next);
2222 primary[0] /= 128.0f;
2223 primary[1] /= 128.0f;
2224 primary[2] /= 128.0f;
2225 secondary[0] /= 128.0f;
2226 secondary[1] /= 128.0f;
2227 secondary[2] /= 128.0f;
2228
2229 for (int i = 0; i < 32; i++) {
2230 if (i % 4 < 2) {
2231 vertices[i][0] = primary[0];
2232 vertices[i][1] = primary[1];
2233 vertices[i][2] = primary[2];
2234 vertices[i][3] = 1.0f;
2235 } else {
2236 vertices[i][0] = secondary[0];
2237 vertices[i][1] = secondary[1];
2238 vertices[i][2] = secondary[2];
2239 vertices[i][3] = 1.0f;
2240 }
2241 }
2242
2243 sky->attr.remake_pending = 1;
2244 }
2245 }
2246 }
2247}
2248
2249int EdInitToEPInfo(INIT_PARTSINFO *init, EPARTS_INFO_HEADER *header) {
2250 header->header_size = 0x78;
2251 header->width = init->width;
2252 header->height = init->height;
2253 header->kind = init->kind;
2254 header->cell = NULL;
2255
2256 for (int i = 0; i < 6; i++) {
2257 header->element_id[i] = init->element_id[i];
2258 header->element_name[i] = NULL;
2259 }
2260
2261 u8 *write = (u8 *) header + header->header_size;
2262 header->cell = write;
2263
2264 for (int i = 0; i < header->width * header->height; i++) {
2265 *write++ = init->cell[i][0];
2266 }
2267
2268 for (int i = 0; i < 6; i++) {
2269 header->element_name[i] = (char *) write;
2270 strcpy((char *) write, init->element_name[i]);
2271 write += strlen(init->element_name[i]);
2272 *write++ = '\0';
2273 *write++ = '\0';
2274 }
2275
2276 header->data_size = write - (u8 *) header;
2277 return header->data_size;
2278}
2279
2281static float fade_col[4];
2282
2284static int fade_in_out;
2285
2287static int fade_end;
2288
2290static float fade_step;
2291
2292ED_EVENT_INFO EdEventInfo;
2293
2294OBJ_HANDLE ObjHandle[32];
2295
2296void EdFadeInit() {
2297 fade_col[3] = 0.0f;
2298 fade_col[2] = 0.0f;
2299 fade_col[1] = 0.0f;
2300 fade_col[0] = 0.0f;
2301 fade_in_out = 0;
2302 fade_step = 0.0f;
2303 fade_end = 0;
2304}
2305
2306/* A negative frame count means no step at all: the alpha is forced to the end this call starts
2307 from and stays there, which is how a colour is held over the screen rather than faded through. */
2308void EdFadeIn(int frames, float red, float green, float blue) {
2309 if (fade_in_out == 0 || frames < 0) {
2310 fade_col[3] = 128.0f;
2311 }
2312
2313 fade_in_out = 1;
2314 fade_end = 0;
2315
2316 if (frames < 0) {
2317 fade_step = 0.0f;
2318 } else {
2319 fade_step = 128.0f / (float) frames;
2320 }
2321
2322 fade_col[0] = red;
2323 fade_col[1] = green;
2324 fade_col[2] = blue;
2325}
2326
2327void EdFadeOut(int frames, float red, float green, float blue) {
2328 if (fade_in_out == 0 || frames < 0) {
2329 fade_col[3] = 0.0f;
2330 }
2331
2332 fade_in_out = -1;
2333 fade_end = 0;
2334
2335 if (frames < 0) {
2336 fade_step = 0.0f;
2337 } else {
2338 fade_step = 128.0f / (float) frames;
2339 }
2340
2341 fade_col[0] = red;
2342 fade_col[1] = green;
2343 fade_col[2] = blue;
2344}
2345
2346int EdFadeOutCheck() {
2347 return fade_end;
2348}
2349
2350void EdGetFadeColor(float *colour) {
2351 colour[0] = fade_col[0];
2352 colour[1] = fade_col[1];
2353 colour[2] = fade_col[2];
2354 colour[3] = fade_col[3];
2355}
2356
2357/* The rectangle is in the sixteenths of a pixel the coordinate registers count in, which is what
2358 the multiplications are; why the cover is 70 boxes rather than one the code does not say. */
2359void EdFadeInOut() {
2360 int red;
2361 int green;
2362 int blue;
2363 int alpha;
2364 int x;
2365 int y;
2366 CRect_i_ rect;
2367
2368 if (fade_in_out == 0) {
2369 return;
2370 }
2371
2372 red = (int) fade_col[0];
2373 green = (int) fade_col[1];
2374 blue = (int) fade_col[2];
2375 alpha = (int) fade_col[3];
2376
2377 if (fade_in_out > 0) {
2378 fade_col[3] -= fade_step;
2379
2380 if (fade_col[3] <= 0.0f) {
2381 fade_col[3] = 0.0f;
2382 fade_in_out = 0;
2383 fade_end = 1;
2384 }
2385 } else {
2386 fade_col[3] += fade_step;
2387
2388 if (fade_col[3] >= 128.0f) {
2389 fade_col[3] = 128.0f;
2390 fade_end = 1;
2391 }
2392 }
2393
2394 for (x = 0; x < 640; x += 64) {
2395 for (y = 0; y < SCREEN_HALF_HEIGHT; y += 32) {
2396 rect.x = x * 16;
2397 rect.y = y * 16;
2398 rect.width = 1024;
2399 rect.height = 512;
2400 MGFillBox(rect, red, green, blue, alpha);
2401 }
2402 }
2403}
2404
2405static float GetMaxHeightCursor(float *position) {
2406 int height = 0;
2407 int count;
2408
2409 for (count = 0; count < 8; count++) {
2410 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[count];
2411
2412 if (area->maximum[0] == area->minimum[0] || area->maximum[2] == area->minimum[0]) {
2413 break;
2414 }
2415 }
2416
2417 if (count == 0) {
2418 return 0.0f;
2419 }
2420
2421 for (int i = 0; i < count; i++) {
2422 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[i];
2423
2424 if (position[0] <= area->maximum[0] && position[2] <= area->maximum[2] && position[0] >= area->minimum[0] && position[2] >= area->minimum[2] && height < area->minimum[1]) {
2425 height = area->minimum[1];
2426 }
2427 }
2428
2429 return height;
2430}
2431
2432void LimitEditCursorPos(float *position, float *movement) {
2433 sceVu0FVECTOR previous;
2434 sceVu0FVECTOR clamped;
2435 sceVu0FVECTOR displacement;
2436
2437 sceVu0CopyVector(previous, position);
2438 sceVu0AddVector(position, position, movement);
2439
2440 int count;
2441
2442 for (count = 0; count < 8; count++) {
2443 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[count];
2444
2445 if (area->maximum[0] == area->minimum[0] || area->maximum[2] == area->minimum[0]) {
2446 break;
2447 }
2448 }
2449
2450 if (count == 0) {
2451 position[1] = 0.0f;
2452 return;
2453 }
2454
2455 for (int i = 0; i < count; i++) {
2456 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[i];
2457
2458 if (position[0] <= area->maximum[0] && position[2] <= area->maximum[2] && position[0] >= area->minimum[0] && position[2] >= area->minimum[2]) {
2459 position[1] = GetMaxHeightCursor(position);
2460 return;
2461 }
2462 }
2463
2464 float nearest_distance = -1.0f;
2465 int nearest = -1;
2466
2467 for (int i = 0; i < count; i++) {
2468 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[i];
2469
2470 if (previous[0] <= area->maximum[0] && previous[2] <= area->maximum[2] && previous[0] >= area->minimum[0] && previous[2] >= area->minimum[2]) {
2471 VectorMin(clamped, position, area->maximum);
2472 VectorMax(clamped, clamped, area->minimum);
2473 sceVu0SubVector(displacement, clamped, position);
2474 displacement[1] = 0.0f;
2475 float distance = DistVector(displacement);
2476
2477 if (nearest < 0) {
2478 nearest = i;
2479 nearest_distance = distance;
2480 } else if (distance < nearest_distance) {
2481 nearest = i;
2482 nearest_distance = distance;
2483 }
2484 }
2485 }
2486
2487 if (nearest >= 0) {
2488 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[nearest];
2489 VectorMin(position, position, area->maximum);
2490 VectorMax(position, position, area->minimum);
2491 position[1] = GetMaxHeightCursor(position);
2492 return;
2493 }
2494
2495 nearest = 0;
2496 EDIT_AREA_RECT_INFO *area = &EditMapInfo->edit_area_rects[0];
2497 float max_x_distance;
2498 float min_x_distance;
2499 float min_z_distance;
2500 float max_z_distance;
2501 float x = position[0];
2502 max_x_distance = x - area->maximum[0];
2503
2504 if (max_x_distance < 0.0f) {
2505 max_x_distance = -max_x_distance;
2506 } else {
2507 max_x_distance = max_x_distance;
2508 }
2509
2510 min_x_distance = x - area->minimum[0];
2511
2512 if (min_x_distance < 0.0f) {
2513 min_x_distance = -min_x_distance;
2514 } else {
2515 min_x_distance = min_x_distance;
2516 }
2517
2518 float z = position[2];
2519 max_z_distance = z - area->maximum[2];
2520
2521 if (max_z_distance < 0.0f) {
2522 max_z_distance = -max_z_distance;
2523 } else {
2524 max_z_distance = max_z_distance;
2525 }
2526
2527 min_z_distance = z - area->minimum[2];
2528
2529 if (min_z_distance < 0.0f) {
2530 min_z_distance = -min_z_distance;
2531 } else {
2532 min_z_distance = min_z_distance;
2533 }
2534
2535 if (max_z_distance < min_z_distance) {
2536 max_z_distance = max_z_distance;
2537 } else {
2538 max_z_distance = min_z_distance;
2539 }
2540
2541 if (max_x_distance < min_x_distance) {
2542 max_x_distance = max_x_distance;
2543 } else {
2544 max_x_distance = min_x_distance;
2545 }
2546
2547 nearest_distance = max_x_distance + max_z_distance;
2548
2549 for (int i = 1; i < count; i++) {
2550 area = &EditMapInfo->edit_area_rects[i];
2551 max_x_distance = x - area->maximum[0];
2552
2553 if (max_x_distance < 0.0f) {
2554 max_x_distance = -max_x_distance;
2555 } else {
2556 max_x_distance = max_x_distance;
2557 }
2558
2559 min_x_distance = x - area->minimum[0];
2560
2561 if (min_x_distance < 0.0f) {
2562 min_x_distance = -min_x_distance;
2563 } else {
2564 min_x_distance = min_x_distance;
2565 }
2566
2567 max_z_distance = z - area->maximum[2];
2568
2569 if (max_z_distance < 0.0f) {
2570 max_z_distance = -max_z_distance;
2571 } else {
2572 max_z_distance = max_z_distance;
2573 }
2574
2575 min_z_distance = z - area->minimum[2];
2576
2577 if (min_z_distance < 0.0f) {
2578 min_z_distance = -min_z_distance;
2579 } else {
2580 min_z_distance = min_z_distance;
2581 }
2582
2583 if (max_z_distance < min_z_distance) {
2584 max_z_distance = max_z_distance;
2585 } else {
2586 max_z_distance = min_z_distance;
2587 }
2588
2589 if (max_x_distance < min_x_distance) {
2590 max_x_distance = max_x_distance;
2591 } else {
2592 max_x_distance = min_x_distance;
2593 }
2594
2595 float distance = max_x_distance + max_z_distance;
2596
2597 if (distance < nearest_distance) {
2598 nearest_distance = distance;
2599 nearest = i;
2600 }
2601 }
2602
2603 area = &EditMapInfo->edit_area_rects[nearest];
2604 VectorMin(position, position, area->maximum);
2605 VectorMax(position, position, area->minimum);
2606 position[1] = GetMaxHeightCursor(position);
2607}
2608
2609void EdSePlay(ED_SOUND_ID sound, int pan) {
2610 if (sound < 0 || sound >= ED_SOUND_COUNT) {
2611 return;
2612 }
2613
2614 SndSePlay(sound, pan, 0);
2615}
2616
2618static ED_SPRITE Sprite[16];
2619
2620static ED_SPRITE *GetSprite(int index) {
2621 if (index < 0 || index >= 16) {
2622 return NULL;
2623 }
2624
2625 return &Sprite[index];
2626}
2627
2628static void InitSprite(ED_SPRITE *sprite) {
2629 if (sprite == NULL) {
2630 return;
2631 }
2632
2633 memset(sprite, 0, sizeof(ED_SPRITE));
2634 sprite->alpha = 128;
2635 sprite->blue = 128;
2636 sprite->green = 128;
2637 sprite->red = 128;
2638 sprite->height = -1;
2639 sprite->width = -1;
2640}
2641
2643static OBJ_ANIME_SEQ obj_anime[16];
2644
2645static OBJ_ANIME_SEQ *GetObjAnime(int index) {
2646 if (index < 0 || index >= 16) {
2647 return NULL;
2648 }
2649
2650 return &obj_anime[index];
2651}
2652
2653static void ClearObjAnime(int index) {
2654 if (index < 0) {
2655 for (int i = 0; i < 16; i++) {
2656 obj_anime[i].property = OBJ_ANIME_PROPERTY_NONE;
2657 }
2658
2659 return;
2660 }
2661
2662 OBJ_ANIME_SEQ *anime = GetObjAnime(index);
2663
2664 if (anime != NULL) {
2665 anime->property = OBJ_ANIME_PROPERTY_NONE;
2666 }
2667}
2668
2670int simple_event;
2671
2673static int event_enable;
2674
2676static int run_system_event;
2677
2679static int not_wait_load;
2680
2682static int motion_stop_flag;
2683
2685static int menu_mode;
2686
2688static int menu_mode_status;
2689
2691static char *p_use_item;
2692
2694static int p_jump_map_no;
2695
2697static int event_stop;
2698
2700static int event_pause;
2701
2703static int skip_enable;
2704
2706static int set_wl_matrix;
2707
2709static CCharacter *follow_chara;
2710
2712static CCharacter *sync_camera_ref_chara;
2713
2715static OBJ_HANDLE *sync_camera_ref_obj;
2716
2718static OBJ_HANDLE *sync_camera_pos_obj;
2719
2721static u_int *BaseBuffer;
2722
2724static int actv_file;
2725
2727static int actv_buffer;
2728
2729#ifdef PAL
2730void EdEventStopPlay() {
2731 event_stop = !event_stop;
2732}
2733#endif
2734
2735void EdEventPause() {
2736 event_pause = !event_pause;
2737}
2738
2739#ifdef PAL
2740int EdCheckEventPause() {
2741 return event_pause;
2742}
2743#endif
2744
2746static char CurrentDir[0x40];
2747
2749static sceVu0FVECTOR world_pos;
2750
2752static sceVu0FVECTOR world_rot;
2753
2755static sceVu0FMATRIX world_local;
2756
2758static sceVu0FMATRIX local_world;
2759
2761static sceVu0FVECTOR sync_camera_ref_offset;
2762
2764static int work_flag[32];
2765
2767static ACT_SEQ asq_table[266];
2768
2770static CActionSeq ActSeq[10];
2771
2773static CTexAnimeData anime_data[320];
2774
2778static SPRITE_TABLE sprite_table[32];
2779
2781static CSpriteTable SpriteTable;
2782
2784static CSpriteTable SpriteTableBack;
2785
2786CCharacter SceneData;
2787
2788CCamera DmmyCamera(4.0f);
2789
2791static CRunScript EdEventScript;
2792
2793CRunScript SystemEventScript;
2794
2796static u_int *chr_file[16];
2797
2799static sceVu0FMATRIX save_l[2];
2800
2802static sceVu0FMATRIX save_c[2];
2803
2805static sceVu0FVECTOR save_a[2];
2806
2807int (*ext_func__2[1500])(RS_STACKDATA *, int);
2808
2814
2815void EdDrawOffAll();
2816void EdDrawOnAll();
2817
2818static int SetWorkFlag(int index, int value) {
2819 if (index < 0 || index >= 32) {
2820 return 0;
2821 }
2822
2823 work_flag[index] = value;
2824 return 1;
2825}
2826
2827static int GetWorkFlag(int index) {
2828 if (index < 0 || index >= 32) {
2829 return 0;
2830 }
2831
2832 return work_flag[index];
2833}
2834
2838static int GetStackInt(RS_STACKDATA *stack) {
2839 if (stack->type == RS_FLOAT) {
2840 return (int) stack->f;
2841 }
2842
2843 return stack->i;
2844}
2845
2849static float GetStackFloat(RS_STACKDATA *stack) {
2850 if (stack->type == RS_INT) {
2851 return (float) stack->i;
2852 }
2853
2854 return stack->f;
2855}
2856
2860static char *GetStackString(RS_STACKDATA *stack) {
2861 return stack->s;
2862}
2863
2867static void SetStack(RS_STACKDATA *stack, int value) {
2868 if (stack->type == RS_PTR) {
2869 stack->p->i = value;
2870 }
2871}
2872
2876static void SetStack(RS_STACKDATA *stack, float value) {
2877 if (stack->type == RS_PTR) {
2878 stack->p->f = value;
2879 }
2880}
2881
2882static void PrintMemory() {
2883}
2884
2885static OBJ_HANDLE *GetObjHandle(int index) {
2886 if (index < 0 || index >= 32) {
2887 return NULL;
2888 }
2889
2890 return &ObjHandle[index];
2891}
2892
2893static int SetObjHandle(int index, CMapParts *map_parts, char *frame_name) {
2894 OBJ_HANDLE *handle = GetObjHandle(index);
2895
2896 if (handle == NULL) {
2897 return 0;
2898 }
2899
2900 if (map_parts == NULL) {
2901 return 0;
2902 }
2903
2904 if (frame_name == NULL) {
2905 return 0;
2906 }
2907
2908 memset(handle, 0, sizeof(OBJ_HANDLE));
2909 int i = 0;
2910 handle->frames[0] = map_parts->frame[0];
2911 handle->frames[1] = map_parts->frame[1];
2912 handle->frames[2] = map_parts->frame[2];
2913 handle->frames[3] = map_parts->frame[3];
2914 handle->frames[4] = map_parts->GetCollisionFrame();
2915 handle->frames[5] = map_parts->shadow_frame;
2916 handle->frames[6] = map_parts->shade_frame;
2917 CFrame *extra_frame;
2918
2919 if (map_parts->camera_frame == NULL) {
2920 extra_frame = NULL;
2921 } else {
2922 map_parts->camera_frame->SetPosition(map_parts->pos[0], map_parts->pos[1], map_parts->pos[2]);
2923 map_parts->camera_frame->SetRotation(map_parts->rotation.x, map_parts->rotation.y, map_parts->rotation.z);
2924 extra_frame = map_parts->camera_frame;
2925 }
2926
2927 handle->frames[7] = extra_frame;
2928 handle->frames[8] = map_parts->ripple_frame;
2929 i += 9;
2930
2931 for (; i < 12; i++) {
2932 handle->frames[i] = NULL;
2933 }
2934
2935 if (frame_name[0] != '\0') {
2936 for (i = 0; i < 12; i++) {
2937 if (handle->frames[i] != NULL) {
2938 handle->frames[i] = handle->frames[i]->SearchFrame(frame_name);
2939 }
2940 }
2941
2942 handle->map_parts = NULL;
2943 } else {
2944 handle->map_parts = map_parts;
2945 }
2946
2947 return 1;
2948}
2949
2950static int SetObjHandle(int index, CCharacter *character, char *frame_name) {
2951 OBJ_HANDLE *handle = GetObjHandle(index);
2952
2953 if (handle == NULL) {
2954 return 0;
2955 }
2956
2957 if (character == NULL) {
2958 return 0;
2959 }
2960
2961 if (frame_name == NULL) {
2962 return 0;
2963 }
2964
2965 memset(handle, 0, sizeof(OBJ_HANDLE));
2966 int i = 0;
2967 handle->frames[0] = character->frame;
2968 handle->frames[1] = character->shadow_frame;
2969 i += 2;
2970
2971 for (; i < 12; i++) {
2972 handle->frames[i] = NULL;
2973 }
2974
2975 if (frame_name[0] != '\0') {
2976 for (i = 0; i < 12; i++) {
2977 if (handle->frames[i] != NULL) {
2978 handle->frames[i] = handle->frames[i]->SearchFrame(frame_name);
2979 }
2980 }
2981
2982 handle->map_parts = NULL;
2983 } else {
2984 handle->character = character;
2985 }
2986
2987 return 1;
2988}
2989
2990static int SetObjHandle(int index, CFrame *frame) {
2991 OBJ_HANDLE *handle = GetObjHandle(index);
2992
2993 if (frame == NULL) {
2994 return 0;
2995 }
2996
2997 memset(handle, 0, sizeof(OBJ_HANDLE));
2998 handle->frames[0] = frame;
2999 return 1;
3000}
3001
3002static void obj_draw(OBJ_HANDLE *handle, int draw) {
3003 if (handle == NULL) {
3004 return;
3005 }
3006
3007 int frame_draw = 2;
3008 int frame_flags = 4;
3009
3010 if (draw != 0) {
3011 frame_draw = 1;
3012 frame_flags = 1;
3013 }
3014
3015 if (handle->map_parts != NULL) {
3016 handle->map_parts->draw_on = draw;
3017 return;
3018 }
3019
3020 for (int i = 0; i < 12; i++) {
3021 if (handle->frames[i] != NULL) {
3022 handle->frames[i]->attr.draw_on = frame_draw;
3023 handle->frames[i]->flags = frame_flags;
3024 }
3025 }
3026}
3027
3028static void set_obj_pos(OBJ_HANDLE *handle, float *position) {
3029 if (handle->map_parts != NULL) {
3030 handle->map_parts->SetPosition(position);
3031 return;
3032 }
3033
3034 if (handle->character != NULL) {
3035 handle->character->SetPosition(position);
3036 return;
3037 }
3038
3039 for (int i = 0; i < 12; i++) {
3040 if (handle->frames[i] != NULL) {
3041 handle->frames[i]->SetPosition(position);
3042 }
3043 }
3044}
3045
3046static void get_obj_pos(OBJ_HANDLE *handle, float *out_position) {
3047 if (handle->map_parts != NULL) {
3048 handle->map_parts->GetPosition(out_position);
3049 return;
3050 }
3051
3052 if (handle->character != NULL) {
3053 handle->character->GetPosition(out_position);
3054 return;
3055 }
3056
3057 for (int i = 0; i < 12; i++) {
3058 if (handle->frames[i] != NULL) {
3059 sceVu0CopyVector(out_position, handle->frames[i]->position);
3060 return;
3061 }
3062 }
3063}
3064
3065static void get_obj_world_pos(OBJ_HANDLE *handle, float *out_position) {
3066 if (handle->map_parts != NULL) {
3067 handle->map_parts->GetPosition(out_position);
3068 return;
3069 }
3070
3071 if (handle->character != NULL) {
3072 handle->character->GetPosition(out_position);
3073 return;
3074 }
3075
3076 sceVu0FVECTOR origin = {0.0f, 0.0f, 0.0f, 1.0f};
3077
3078 for (int i = 0; i < 12; i++) {
3079 if (handle->frames[i] != NULL) {
3080 handle->frames[i]->GetWorldPosition(out_position, origin);
3081 return;
3082 }
3083 }
3084}
3085
3086static void set_obj_rot(OBJ_HANDLE *handle, float *rotation) {
3087 if (handle->map_parts != NULL) {
3088 handle->map_parts->SetRotation(rotation[0], rotation[1], rotation[2]);
3089 return;
3090 }
3091
3092 if (handle->character != NULL) {
3093 handle->character->SetRotation(rotation[0], rotation[1], rotation[2]);
3094 return;
3095 }
3096
3097 for (int i = 0; i < 12; i++) {
3098 if (handle->frames[i] != NULL) {
3099 handle->frames[i]->SetRotType(2);
3100 handle->frames[i]->SetRotation(rotation[0], rotation[1], rotation[2]);
3101 }
3102 }
3103}
3104
3105static void get_obj_rot(OBJ_HANDLE *handle, float *out_rotation) {
3106 if (handle->map_parts != NULL) {
3107 handle->map_parts->GetRotation(out_rotation);
3108 return;
3109 }
3110
3111 if (handle->character != NULL) {
3112 handle->character->GetRotation(out_rotation);
3113 return;
3114 }
3115
3116 for (int i = 0; i < 12; i++) {
3117 if (handle->frames[i] != NULL) {
3118 handle->frames[i]->GetRotation(out_rotation);
3119 return;
3120 }
3121 }
3122}
3123
3124static void set_obj_scale(OBJ_HANDLE *handle, float *scale) {
3125 if (handle->map_parts != NULL) {
3126 handle->map_parts->SetScale(scale);
3127 return;
3128 }
3129
3130 if (handle->character != NULL) {
3131 handle->character->SetScale(scale);
3132 return;
3133 }
3134
3135 for (int i = 0; i < 12; i++) {
3136 if (handle->frames[i] != NULL) {
3137 handle->frames[i]->SetScale(scale);
3138 }
3139 }
3140}
3141
3142static void get_obj_scale(OBJ_HANDLE *handle, float *out_scale) {
3143 if (handle->map_parts != NULL) {
3144 handle->map_parts->GetScale(out_scale);
3145 return;
3146 }
3147
3148 if (handle->character != NULL) {
3149 handle->character->GetScale(out_scale);
3150 return;
3151 }
3152
3153 for (int i = 0; i < 12; i++) {
3154 CFrame *frame = handle->frames[i];
3155
3156 if (frame != NULL) {
3157 out_scale[0] = frame->scale[0];
3158 out_scale[1] = frame->scale[1];
3159 out_scale[2] = frame->scale[2];
3160 return;
3161 }
3162 }
3163}
3164
3165static int init_obj_anime(int anime_index, int handle_index, int type, int number, float *offset, float *range, float *speed) {
3166 OBJ_ANIME_SEQ *anime = GetObjAnime(anime_index);
3167 OBJ_HANDLE *handle = GetObjHandle(handle_index);
3168
3169 if (anime == NULL || handle == NULL) {
3170 return 0;
3171 }
3172
3173 anime->property = type;
3174 anime->mode = number;
3175 anime->frame_name[0] = '\0';
3176 sceVu0CopyVector(anime->step, offset);
3177 sceVu0CopyVector(anime->from, range);
3178 sceVu0CopyVector(anime->to, speed);
3179 InitObjAnime(handle->frames, 12, anime);
3180 PORT_RETURN(1);
3181}
3182
3183static void sync_obj_obj(OBJ_HANDLE *source, OBJ_HANDLE *targets) {
3184 CFrame *reference = NULL;
3185 int i;
3186
3187 for (i = 0; i < 12; i++) {
3188 if (source->frames[i] != NULL) {
3189 reference = source->frames[i];
3190 break;
3191 }
3192 }
3193
3194 if (reference != NULL) {
3195 for (i = 0; i < 12; i++) {
3196 if (targets->frames[i] != NULL) {
3197 targets->frames[i]->SetReference(reference);
3198 }
3199 }
3200 }
3201}
3202
3203static void release_obj_obj(OBJ_HANDLE *handle) {
3204 for (int i = 0; i < 12; i++) {
3205 if (handle->frames[i] != NULL) {
3206 handle->frames[i]->DeleteReference();
3207 }
3208 }
3209}
3210
3211static void set_attr_obj(OBJ_HANDLE *handle, CFrameAttr &attr, int children, int mask) {
3212 if (handle->character != NULL) {
3213 if (handle->character->frame != NULL) {
3214 handle->character->frame->SetAttr(attr, children, mask);
3215 }
3216 } else {
3217 for (int i = 0; i < 12; i++) {
3218 if (handle->frames[i] != NULL) {
3219 handle->frames[i]->SetAttr(attr, children, mask);
3220 }
3221 }
3222 }
3223}
3224
3225static CActionSeq *GetActSeq(int index) {
3226 if (index < 0 || index >= 10) {
3227 return NULL;
3228 }
3229
3230 return &ActSeq[index];
3231}
3232
3233void turn_chara(CCharacter *character, float *position, float speed) {
3234 sceVu0FVECTOR current_position;
3235 sceVu0FVECTOR rotation;
3236 sceVu0FVECTOR direction;
3237 character->GetPosition(current_position);
3238 character->GetRotation(rotation);
3239 sceVu0SubVector(direction, position, current_position);
3240 float angle = atan2f(direction[0], direction[2]);
3241 float *yaw = &rotation[1];
3242 *yaw = AngleInterpolate(*yaw, angle, speed, INTERPOLATE_STEP);
3243 character->SetRotation(rotation);
3244}
3245
3246static CCharacter *GetScene(int index) {
3247 return &SceneData;
3248}
3249
3250static CNPCharacter *GetNPC(int index) {
3251 if (index < 0 || index >= EdEventInfo.npc_count) {
3252 return NULL;
3253 }
3254
3255 return &EdEventInfo.npcs[index];
3256}
3257
3258static CCharacter *GetChara(int index) {
3259 if (index == -1) {
3260 return EdEventInfo.main_character;
3261 }
3262
3263 if (index < 0 || index >= EdEventInfo.npc_count) {
3264 return NULL;
3265 }
3266
3267 return &EdEventInfo.npcs[index];
3268}
3269
3270static CFrame *GetItemFrame(int index) {
3271 if (index < 0 || index > 0) {
3272 return NULL;
3273 }
3274
3275 return EdEventInfo.item_frame[index];
3276}
3277
3278static void DeleteItemFrame(int index) {
3279 if (index < 0 || index > 0) {
3280 return;
3281 }
3282
3283 CFrameVu1 **frames = EdEventInfo.item_frame;
3284 CFrameVu1 **frame = &frames[index];
3285
3286 if (*frame != NULL) {
3287 (*frame)->DeleteReference();
3288 *frame = NULL;
3289 }
3290}
3291
3292static VILLAGER_INFO *GetVillagerInfo(int index) {
3293 if (index < 0 || index >= 16) {
3294 return NULL;
3295 }
3296
3297 return &EdEventInfo.villagers[index];
3298}
3299
3300static void SetWorldCoord(float *position, float *rotation) {
3301 sceVu0CopyVector(world_pos, position);
3302 world_pos[3] = 1.0f;
3303 sceVu0CopyVector(world_rot, rotation);
3304 world_rot[3] = 0.0f;
3305 sceVu0UnitMatrix(world_local);
3306 sceVu0RotMatrixY(world_local, world_local, world_rot[1]);
3307 sceVu0CopyVector(world_local[3], world_pos);
3308 sceVu0InversMatrix(local_world, world_local);
3309 set_wl_matrix = 1;
3310}
3311
3312static void GetWorldPos(float *out, float *position) {
3313 if (set_wl_matrix == 0) {
3314 sceVu0CopyVector(out, position);
3315 return;
3316 }
3317
3318 position[3] = 1.0f;
3319 sceVu0ApplyMatrix(out, world_local, position);
3320}
3321
3322static float GetWorldRotY(float rotation) {
3323 rotation += world_rot[1];
3324
3325 if (rotation > PI_SHORT) {
3326 rotation -= TWO_PI_SHORT;
3327 }
3328
3329 if (rotation < -PI_SHORT) {
3330 rotation += TWO_PI_SHORT;
3331 }
3332
3333 return rotation;
3334}
3335
3336static void GetWorldRot(float *out, float *rotation) {
3337 sceVu0CopyVector(out, rotation);
3338 out[1] = GetWorldRotY(out[1]);
3339}
3340
3341static void GetLocalPos(float *out, float *position) {
3342 if (set_wl_matrix == 0) {
3343 sceVu0CopyVector(out, position);
3344 return;
3345 }
3346
3347 position[3] = 1.0f;
3348 sceVu0ApplyMatrix(out, local_world, position);
3349}
3350
3351static float GetLocalRotY(float rotation) {
3352 rotation -= world_rot[1];
3353
3354 if (rotation > PI_SHORT) {
3355 rotation -= TWO_PI_SHORT;
3356 }
3357
3358 if (rotation < -PI_SHORT) {
3359 rotation += TWO_PI_SHORT;
3360 }
3361
3362 return rotation;
3363}
3364
3365static void GetLocalRot(float *out, float *rotation) {
3366 sceVu0CopyVector(out, rotation);
3367 out[1] = GetLocalRotY(out[1]);
3368}
3369
3370static void GetPosition(RS_STACKDATA *stack, float *position) {
3371 position[0] = GetStackFloat(stack++);
3372 position[1] = GetStackFloat(stack++);
3373 position[2] = GetStackFloat(stack);
3374 position[3] = 1.0f;
3375 GetWorldPos(position, position);
3376}
3377
3378static void SetPosition(RS_STACKDATA *stack, float *position) {
3379 position[3] = 1.0f;
3380 GetLocalPos(position, position);
3381 SetStack(stack++, position[0]);
3382 SetStack(stack++, position[1]);
3383 SetStack(stack, position[2]);
3384}
3385
3386static void GetRotation(RS_STACKDATA *stack, float *rotation) {
3387 rotation[0] = GetStackFloat(stack++);
3388 rotation[1] = GetStackFloat(stack++);
3389 rotation[2] = GetStackFloat(stack);
3390 rotation[3] = 0.0f;
3391 GetWorldRot(rotation, rotation);
3392}
3393
3394static void SetRotation(RS_STACKDATA *stack, float *rotation) {
3395 rotation[3] = 0.0f;
3396 GetLocalRot(rotation, rotation);
3397 SetStack(stack++, rotation[0]);
3398 SetStack(stack++, rotation[1]);
3399 SetStack(stack, rotation[2]);
3400}
3401
3402static void GetFileName(char *destination, char *name) {
3403 if (name[0] == '/') {
3404 strcpy(destination, name + 1);
3405 return;
3406 }
3407
3408 strcpy(destination, CurrentDir);
3409 strcat(destination, name);
3410}
3411
3412static int _TEST(RS_STACKDATA *stack, int argument_count) {
3413 return 1;
3414}
3415
3416static int exch_ok_cancel(int buttons) {
3417 int confirm = buttons & ED_PAD_CONFIRM;
3418 int cancel = buttons & ED_PAD_CANCEL;
3419 buttons &= ~(ED_PAD_CONFIRM | ED_PAD_CANCEL);
3420
3421 if (confirm) {
3422 buttons |= ED_PAD_CANCEL;
3423 }
3424
3425 if (cancel) {
3426 buttons |= ED_PAD_CONFIRM;
3427 }
3428
3429 return buttons;
3430}
3431
3432static int _GET_PADON(RS_STACKDATA *stack, int argument_count) {
3433 if (argument_count <= 0) {
3434 return 0;
3435 }
3436
3437 SetStack(stack, exch_ok_cancel(GamePad.GetPadOn()));
3438 return 1;
3439}
3440
3441static int _GET_PADDOWN(RS_STACKDATA *stack, int argument_count) {
3442 if (argument_count <= 0) {
3443 return 0;
3444 }
3445
3446 SetStack(stack, exch_ok_cancel(GamePad.GetPadDown()));
3447 return 1;
3448}
3449
3450static int _GET_PADUP(RS_STACKDATA *stack, int argument_count) {
3451 if (argument_count <= 0) {
3452 return 0;
3453 }
3454
3455 SetStack(stack, exch_ok_cancel(GamePad.GetPadUp()));
3456 return 1;
3457}
3458
3459static int _GET_APAD(RS_STACKDATA *stack, int argument_count) {
3460 if (argument_count > 0) {
3461 SetStack(stack++, GamePad.GetLXf());
3462 }
3463
3464 if (argument_count > 1) {
3465 SetStack(stack++, GamePad.GetLYf());
3466 }
3467
3468 if (argument_count > 2) {
3469 SetStack(stack++, GamePad.GetRXf());
3470 }
3471
3472 if (argument_count > 3) {
3473 SetStack(stack, GamePad.GetRYf());
3474 }
3475
3476 return 1;
3477}
3478
3479static int _GET_RANDOM(RS_STACKDATA *stack, int argument_count) {
3480 if (argument_count <= 0) {
3481 return 0;
3482 }
3483
3484 SetStack(stack, rand());
3485 return 1;
3486}
3487
3488static int _SET_RETURN_CODE(RS_STACKDATA *stack, int argument_count) {
3489 EdEventInfo.return_code = GetStackInt(stack);
3490 return 1;
3491}
3492
3493static int _NEXT_EVENT(RS_STACKDATA *stack, int argument_count) {
3494 EdEventInfo.next_event = GetStackInt(stack);
3495 return 1;
3496}
3497
3498static int _GOTO_INTERIOR(RS_STACKDATA *stack, int argument_count) {
3499 EdEventInfo.interior_entrance = GetStackInt(stack++);
3500 char *destination = GetStackString(stack++);
3501 strcpy(EdEventInfo.interior_name, destination);
3502
3503 if (argument_count > 2) {
3504 EdEventInfo.interior_start_event = GetStackInt(stack);
3505 } else {
3506 EdEventInfo.interior_start_event = -1;
3507 }
3508
3509 return EdEventInfo.return_code = ED_EVENT_RETURN_INTERIOR;
3510}
3511
3512static int _SET_WORLD_COORD(RS_STACKDATA *stack, int argument_count) {
3513 if (argument_count == 6) {
3514 world_pos[0] = GetStackFloat(stack++);
3515 world_pos[1] = GetStackFloat(stack++);
3516 world_pos[2] = GetStackFloat(stack++);
3517 world_pos[3] = 1.0f;
3518 world_rot[0] = GetStackFloat(stack++);
3519 world_rot[1] = GetStackFloat(stack++);
3520 world_rot[2] = GetStackFloat(stack);
3521 world_rot[3] = 0.0f;
3522 SetWorldCoord(world_pos, world_rot);
3523 } else {
3524 world_pos[0] = world_pos[1] = world_pos[2] = 0.0f;
3525 world_rot[0] = world_rot[1] = world_rot[2] = 0.0f;
3526 sceVu0UnitMatrix(world_local);
3527 sceVu0UnitMatrix(local_world);
3528 set_wl_matrix = 0;
3529 }
3530
3531 return 1;
3532}
3533
3534static int _INITIALIZE(RS_STACKDATA *stack, int argument_count) {
3535 EdInitEventParam();
3536 return 1;
3537}
3538
3539static int _EXIT_CODE(RS_STACKDATA *stack, int argument_count) {
3540 EdEventInfo.exit_code = GetStackInt(stack);
3541 return 1;
3542}
3543
3544static int _DRAW_EXCLAMATION_MARK(RS_STACKDATA *stack, int argument_count) {
3545 EdEventInfo.draw_exclamation_mark = true;
3546 return 1;
3547}
3548
3549static int _GOTO_USE_ITEM(RS_STACKDATA *stack, int argument_count) {
3550 int items[32];
3551
3552 if (stack->type != RS_PTR) {
3553 return 0;
3554 }
3555
3556 p_use_item = stack->s;
3557 stack++;
3558 int i;
3559
3560 for (i = 0; i < argument_count - 1; i++) {
3561 items[i] = GetStackInt(stack++);
3562 }
3563
3564 items[i] = -1;
3565 EdUseItemInit();
3566 EdSetUseItem(items);
3567 menu_mode = ED_MENU_USE_ITEM;
3568 return 1;
3569}
3570
3571static int _NAME_REGISTRY(RS_STACKDATA *stack, int argument_count) {
3572 EdSetNameRegChara(GetStackInt(stack));
3573 menu_mode = ED_MENU_NAME_REGISTRY;
3574 return 1;
3575}
3576
3577static int _WORLD_MAP(RS_STACKDATA *stack, int argument_count) {
3578 if (stack->type != RS_PTR) {
3579 return 0;
3580 }
3581
3582 p_jump_map_no = stack->i;
3583 menu_mode = ED_MENU_WORLD_MAP;
3584 return 1;
3585}
3586
3587static int _SKIP(RS_STACKDATA *stack, int argument_count) {
3588 skip_enable = GetStackInt(stack);
3589 return 1;
3590}
3591
3592static int _GOTO_OUTSIDE(RS_STACKDATA *stack, int argument_count) {
3593 EdEventInfo.outside_map_no = GetStackInt(stack);
3595 return 1;
3596}
3597
3598static int _FINISH(RS_STACKDATA *stack, int argument_count) {
3599 EdEventAllClear();
3600 return 1;
3601}
3602
3603static int _MAP_JUMP(RS_STACKDATA *stack, int argument_count) {
3604 int map = GetStackInt(stack++) - 1;
3605 int event = -1;
3606
3607 if (argument_count >= 2) {
3608 event = GetStackInt(stack);
3609 }
3610
3611 MapJump(map, event);
3613 return 1;
3614}
3615
3616static int _GET_OLD_MAPNO(RS_STACKDATA *stack, int argument_count) {
3617 SetStack(stack, OldMapNo + 1);
3618 return 1;
3619}
3620
3621static int _SET_DUNGEON_FLOOR(RS_STACKDATA *stack, int argument_count) {
3622 BtSetMapJumpFloor(GetStackInt(stack));
3623 return 1;
3624}
3625
3626static int _GET_DUNGEON_FLOOR(RS_STACKDATA *stack, int argument_count) {
3627 SetStack(stack, BtMapJumpFloor);
3628 return 1;
3629}
3630
3631static int _FADEOUT_TO_EVENT(RS_STACKDATA *stack, int argument_count) {
3632 EdEventInfo.fadeout_event_no = GetStackInt(stack);
3633 return 1;
3634}
3635
3636static int _MAP_JUMP_BGM_STOP(RS_STACKDATA *stack, int argument_count) {
3637 EdEventInfo.map_jump_bgm_stop = GetStackInt(stack);
3638 return 1;
3639}
3640
3641static int _MAP_JUMP_BGM_PLAY(RS_STACKDATA *stack, int argument_count) {
3642 EdEventInfo.map_jump_bgm_play = GetStackInt(stack);
3643 return 1;
3644}
3645
3646static int _GOTO_FP_CHANGE(RS_STACKDATA *stack, int argument_count) {
3647 menu_mode = ED_MENU_FISHING_EXCHANGE;
3648 return 1;
3649}
3650
3651static int _GOTO_FISH_RANKING(RS_STACKDATA *stack, int argument_count) {
3652 menu_mode = ED_MENU_FISH_RANKING;
3653 return 1;
3654}
3655
3656static int _GOTO_CHANGE_ESA(RS_STACKDATA *stack, int argument_count) {
3657 if (stack->type != RS_PTR) {
3658 return 0;
3659 }
3660
3661 p_use_item = stack->s;
3662 int items[32] = {ITEM_EVY, ITEM_MIMI, ITEM_PRICKLY, ITEM_THROBBING_CHERRY, ITEM_GOOEY_PEACH, ITEM_BOMB_NUTS, ITEM_POISONOUS_APPLE, ITEM_MELLOW_BANANA, ITEM_CARROT, ITEM_POTATO_CAKE, ITEM_MINON, ITEM_BATTAN, ITEM_PETITE_FISH, -1};
3663 EdUseItemInit();
3664 EdSetUseItem(items);
3665 menu_mode = ED_MENU_CHANGE_ESA;
3666 return 1;
3667}
3668
3669static int _SET_CURRENT_DIR(RS_STACKDATA *stack, int argument_count) {
3670 char *directory = GetStackString(stack);
3671
3672 if (directory == NULL) {
3673 return 0;
3674 }
3675
3676 strcpy(CurrentDir, directory);
3677 return 1;
3678}
3679
3680static u_int *get_pack_file() {
3681 return chr_file[actv_file];
3682}
3683
3684static CDataAlloc2<1> *get_buffer() {
3685 if (actv_buffer == 1) {
3686 return &EdEventExBuffer;
3687 }
3688
3689 return &EdEventBuffer;
3690}
3691
3692static int _ACTIVE_FILE_BUFFER(RS_STACKDATA *stack, int argument_count) {
3693 actv_file = GetStackInt(stack++);
3694 actv_buffer = GetStackInt(stack);
3695
3696 if (actv_file < 0 || actv_file >= 16) {
3697 actv_file = 0;
3698 }
3699
3700 return 1;
3701}
3702
3703static int _LOAD_CHR_FILE(RS_STACKDATA *stack, int argument_count) {
3704 char path[128];
3705 int size;
3706 StartReadBG();
3707 u_long128 *buffer = (u_long128 *) read_buffer;
3708 int i;
3709
3710 for (i = 0; i < 16; i++) {
3711 chr_file[i] = NULL;
3712 }
3713
3714 for (i = 0; i < argument_count; i++) {
3715 char *name = GetStackString(stack++);
3716
3717 if (name != NULL) {
3718 GetFileName(path, name);
3719 printf("%s\n", path);
3720 chr_file[i] = (u_int *) buffer;
3721 LoadFileBG(path, (u_long128 *) chr_file[i], &size);
3722 buffer += (((size >> 6) + 1) << 6) >> 4;
3723 }
3724 }
3725
3726 return not_wait_load = 1;
3727}
3728
3729static int _LOAD_SYNC(RS_STACKDATA *stack, int argument_count) {
3730 if (argument_count <= 0) {
3731 return 0;
3732 }
3733
3734 SetStack(stack, ReadBGSync());
3735 not_wait_load = 0;
3736 return 1;
3737}
3738
3739static int _LOAD_CHARA(RS_STACKDATA *stack, int argument_count) {
3740 RS_STACKDATA *name_stack = stack + 1;
3741 int index = GetStackInt(stack);
3742
3743 if (index == -1) {
3744 CCharacter *character = EdEventInfo.main_character;
3745 char *name = GetStackString(name_stack);
3746
3747 if (name == NULL) {
3748 return 0;
3749 }
3750
3751 u_int *pack = get_pack_file();
3752
3753 if (pack == NULL) {
3754 return 0;
3755 }
3756
3757 CDataAlloc2<1> *first = get_buffer();
3758 CDataAlloc2<1> *second = get_buffer();
3759 character->LoadPackData2(pack, name, first, EdEventInfo.player_texture_block, second, 0);
3760 character->SetMotionCamera(EdEventInfo.camera);
3761 PrintMemory();
3762 return 1;
3763 }
3764
3765 CNPCharacter *npc = GetNPC(index);
3766
3767 if (npc == NULL) {
3768 return 0;
3769 }
3770
3771 char *name = GetStackString(name_stack);
3772
3773 if (name == NULL) {
3774 return 0;
3775 }
3776
3777 u_int *pack = get_pack_file();
3778
3779 if (pack == NULL) {
3780 return 0;
3781 }
3782
3783 CDataAlloc2<1> *first = get_buffer();
3784 CDataAlloc2<1> *second = get_buffer();
3785 npc->LoadPackData2(pack, name, first, EdEventInfo.npc_texture_block + index, second, 0);
3786 npc->texture_block = EdEventInfo.npc_texture_block + index;
3787 npc->initialized = true;
3788 npc->draw_enabled = true;
3789 npc->near_camera = true;
3790 npc->ambient_offset[3] = 128.0f;
3791 CFrameAttr attr;
3792 attr.clip_enable = false;
3793 attr.fog_enable = true;
3794 EdEventInfo.npc_draw[index] = 1;
3795 EdEventInfo.npc_shadow_draw[index] = 1;
3796 npc->SetMotionCamera(EdEventInfo.camera);
3797
3798 if (npc->frame != NULL) {
3799 npc->frame->SetAttr(attr, 1, 4);
3800 }
3801
3802 PrintMemory();
3803 return 1;
3804}
3805
3806static int _LOAD_CHARA_TEXTURE(RS_STACKDATA *stack, int argument_count) {
3807 LOADTEXTURE_INFO2 textures[16];
3808 int size;
3809 int index = GetStackInt(stack++);
3810 CNPCharacter *npc = GetNPC(index);
3811
3812 if (npc == NULL) {
3813 return 0;
3814 }
3815
3816 if (npc->images[0] != NULL) {
3817 return 1;
3818 }
3819
3820 int block = EdEventInfo.npc_texture_block + index;
3821 int i;
3822 u_int *pack = get_pack_file();
3823
3824 if (pack == NULL) {
3825 return 0;
3826 }
3827
3828 for (i = 0; i < argument_count - 1; i++) {
3829 u_int *file = GetPackFile(pack, GetStackString(stack++), &size);
3830
3831 if (file != NULL) {
3832 void *copy = get_buffer()->Alloc((size >> 4) + 1);
3833 memcpy(copy, file, size);
3834 textures[i].block_no = block;
3835 textures[i].mipmap = false;
3836 textures[i].name = (char *) copy;
3837 }
3838 }
3839
3840 textures[i].name = NULL;
3841 TexManager.DeleteTextureBlock(block);
3842 TexManager.CleanUpBuffer();
3843 TexManager.LoadTextureBlockEX(block, textures);
3844 npc->texture_block = block;
3845 return 1;
3846}
3847
3848static int _LOAD_SPRITE_TEXTURE(RS_STACKDATA *stack, int argument_count) {
3849 LOADTEXTURE_INFO2 textures[16];
3850 int size;
3851 int i;
3852 u_int *pack = get_pack_file();
3853
3854 if (pack == NULL) {
3855 return 0;
3856 }
3857
3858 for (i = 0; i < argument_count; i++) {
3859 u_int *file = GetPackFile(pack, GetStackString(stack++), &size);
3860
3861 if (file != NULL) {
3862 void *copy = get_buffer()->Alloc((size >> 4) + 1);
3863 memcpy(copy, file, size);
3864 textures[i].block_no = 45;
3865 textures[i].mipmap = false;
3866 textures[i].name = (char *) copy;
3867 }
3868 }
3869
3870 textures[i].name = NULL;
3871 TexManager.DeleteTextureBlock(45);
3872 TexManager.CleanUpBuffer();
3873 TexManager.LoadTextureBlockEX(45, textures);
3874 return 1;
3875}
3876
3877static int _LOAD_BG_SPRITE_TEXTURE(RS_STACKDATA *stack, int argument_count) {
3878 LOADTEXTURE_INFO2 textures[16];
3879 int size;
3880 int i;
3881 u_int *pack = get_pack_file();
3882
3883 if (pack == NULL) {
3884 return 0;
3885 }
3886
3887 for (i = 0; i < argument_count; i++) {
3888 u_int *file = GetPackFile(pack, GetStackString(stack++), &size);
3889
3890 if (file != NULL) {
3891 void *copy = get_buffer()->Alloc((size >> 4) + 1);
3892 memcpy(copy, file, size);
3893 textures[i].block_no = 46;
3894 textures[i].mipmap = false;
3895 textures[i].name = (char *) copy;
3896 }
3897 }
3898
3899 textures[i].name = NULL;
3900 TexManager.DeleteTextureBlock(46);
3901 TexManager.CleanUpBuffer();
3902 TexManager.LoadTextureBlockEX(46, textures);
3903 return 1;
3904}
3905
3906static int _LOAD_TEXTURE(RS_STACKDATA *stack, int argument_count) {
3907 LOADTEXTURE_INFO2 textures[16];
3908 int size;
3909 int block = GetStackInt(stack++) + 45;
3910
3911 if (block > 49 || block < 45) {
3912 return 0;
3913 }
3914
3915 int i;
3916 u_int *pack = get_pack_file();
3917
3918 if (pack == NULL) {
3919 return 0;
3920 }
3921
3922 for (i = 0; i < argument_count - 1; i++) {
3923 u_int *file = GetPackFile(pack, GetStackString(stack++), &size);
3924
3925 if (file != NULL) {
3926 void *copy = get_buffer()->Alloc((size >> 4) + 1);
3927 memcpy(copy, file, size);
3928 textures[i].block_no = block;
3929 textures[i].mipmap = false;
3930 textures[i].name = (char *) copy;
3931 }
3932 }
3933
3934 textures[i].name = NULL;
3935 TexManager.DeleteTextureBlock(block);
3936 TexManager.CleanUpBuffer();
3937 TexManager.LoadTextureBlockEX(block, textures);
3938 return 1;
3939}
3940
3948static int _LOAD_IN_VILLAGER(RS_STACKDATA *stack, int argument_count) {
3949 int index = GetStackInt(stack++);
3950 CNPCharacter *npc = GetNPC(index);
3951
3952 if (npc == NULL) {
3953 return 0;
3954 }
3955
3956 VILLAGER_INFO *villager = GetVillagerInfo(GetStackInt(stack++));
3957 char *name = GetStackString(stack++);
3958
3959 if (name == NULL) {
3960 return 0;
3961 }
3962
3963 npc->texture_block = index + 54;
3964 EdLoadVillager(name, npc, &EdVillagerBuffer);
3965
3966 if (villager == NULL) {
3967 npc->map_parts_no = -1;
3968 npc->villager_id = -1;
3969 } else {
3970 memcpy(&EdVillagerInfo[index], villager, sizeof(VILLAGER_INFO));
3971 npc->map_parts_no = villager->character_no;
3972 npc->villager_id = villager->index;
3973 }
3974
3975 npc->near_camera = true;
3976 npc->initialized = true;
3977 npc->draw_enabled = true;
3978 npc->event_status = 1;
3979 npc->ambient_offset[3] = 128.0f;
3980 sceVu0FVECTOR position = {0.0f, 0.0f, 0.0f, 0.0f};
3981 sceVu0FVECTOR rotation = {0.0f, 0.0f, 0.0f, 0.0f};
3982
3983 if (argument_count > 3) {
3984 GetPosition(stack, position);
3985 stack += 3;
3986 rotation[1] = GetStackFloat(stack++);
3987 rotation[2] = 0.0f;
3988 rotation[0] = 0.0f;
3989 GetWorldRot(rotation, rotation);
3990 }
3991
3992 npc->SetPosition(position);
3993 npc->SetRotation(rotation);
3994 npc->SetMotion(0, 0);
3995 return 1;
3996}
3997
4005static int _LOAD_OUT_VILLAGER(RS_STACKDATA *stack, int argument_count) {
4006 int index = GetStackInt(stack++);
4007 CNPCharacter *npc = GetNPC(index);
4008
4009 if (npc == NULL) {
4010 return 0;
4011 }
4012
4013 VILLAGER_INFO *villager = GetVillagerInfo(GetStackInt(stack++));
4014 char *name = GetStackString(stack++);
4015
4016 if (name == NULL) {
4017 return 0;
4018 }
4019
4020 npc->texture_block = index + 54;
4021 EdLoadVillager(name, npc, &EdVillagerBuffer);
4022 npc->map_parts_no = -1;
4023 npc->villager_id = -1;
4024
4025 if (villager != NULL) {
4026 villager->index = -1;
4027 }
4028
4029 npc->near_camera = true;
4030 npc->initialized = true;
4031 npc->draw_enabled = true;
4032 npc->event_status = 0;
4033 npc->ambient_offset[3] = 128.0f;
4034 sceVu0FVECTOR position = {0.0f, 0.0f, 0.0f, 0.0f};
4035 sceVu0FVECTOR rotation = {0.0f, 0.0f, 0.0f, 0.0f};
4036
4037 if (argument_count > 3) {
4038 GetPosition(stack, position);
4039 stack += 3;
4040 rotation[1] = GetStackFloat(stack++);
4041 rotation[2] = 0.0f;
4042 rotation[0] = 0.0f;
4043 GetWorldRot(rotation, rotation);
4044 }
4045
4046 npc->SetPosition(position);
4047 npc->SetRotation(rotation);
4048 npc->SetMotion(0, 0);
4049 return 1;
4050}
4051
4052static int _LOAD_VILLAGER(RS_STACKDATA *stack, int argument_count) {
4053 EdVillagerBuffer.used = 0;
4054 EdSelectVillager(EdVillagerInfo, EdEventInfo.current_time, EditMapInfo);
4055 EdInitVilager(EdVillagerInfo, EdEventInfo.edit_ground, NULL);
4056 EdInitVilagerPosition(EdVillager, EdVillagerInfo, EdEventInfo.edit_ground, NULL);
4057 return 1;
4058}
4059
4060static int _CHECK_IN_VILLAGER(RS_STACKDATA *stack, int argument_count) {
4061 int index = GetStackInt(stack++);
4062 int in = EdCheckVillagerIn(index, &EdEventInfo.villagers[index]);
4063 SetStack(stack, in);
4064 return 1;
4065}
4066
4067static int _APPEAR_VILLAGER_ON(RS_STACKDATA *stack, int argument_count) {
4068 EdVillagerAppearOn(GetStackInt(stack), 1);
4069 return 1;
4070}
4071
4072static int _APPEAR_VILLAGER_OFF(RS_STACKDATA *stack, int argument_count) {
4073 EdVillagerAppearOff(GetStackInt(stack), 1);
4074 return 1;
4075}
4076
4077static int _APPEAR_VILLAGER_OUT(RS_STACKDATA *stack, int argument_count) {
4078 EdVillagerAppearOut(GetStackInt(stack), 1);
4079 return 1;
4080}
4081
4082static int _APPEAR_VILLAGER_IN(RS_STACKDATA *stack, int argument_count) {
4083 EdVillagerAppearIn(GetStackInt(stack), 1);
4084 return 1;
4085}
4086
4087static int _APPEAR_VILLAGER_MOVE(RS_STACKDATA *stack, int argument_count) {
4088 RS_STACKDATA *next = (0, stack + 1);
4089 int index = GetStackInt(stack);
4090 EdVillagerAppearMove(index, GetStackInt(next), 1);
4091 return 1;
4092}
4093
4094static int _DELETE_CHARA(RS_STACKDATA *stack, int argument_count) {
4095 int index = GetStackInt(stack);
4096 CNPCharacter *npc = GetNPC(index);
4097
4098 if (npc == NULL) {
4099 return 0;
4100 }
4101
4102 TexManager.DeleteTextureBlock(npc->texture_block);
4103 npc->Initialize();
4104 EdEventInfo.npc_draw[index] = 0;
4105 EdEventInfo.npc_shadow_draw[index] = 0;
4106 return 1;
4107}
4108
4109static int _INIT_CHARA(RS_STACKDATA *stack, int argument_count) {
4110 for (int i = 0; i < argument_count; i++) {
4111 CNPCharacter *npc = GetNPC(GetStackInt(stack++));
4112
4113 if (npc != NULL) {
4114 npc->Initialize();
4115 }
4116 }
4117
4118 return 1;
4119}
4120
4121static int _CLEAR_VILLAGER_BUFF(RS_STACKDATA *stack, int argument_count) {
4122 CDataAlloc2<1> *arena = (CDataAlloc2<1> *) BaseBuffer;
4123 int used = arena->used;
4124 u_char *base = arena->base + used * 16;
4125 int limit = arena->limit - used;
4126 EdVillagerBuffer.base = base;
4127 EdVillagerBuffer.limit = limit;
4128 EdVillagerBuffer.used = 0;
4129 return 1;
4130}
4131
4132static int _CLEAR_EVENT_BUFF(RS_STACKDATA *stack, int argument_count) {
4133 int used = EdVillagerBuffer.used;
4134 u_char *base = EdVillagerBuffer.base + used * 16;
4135 int limit = EdVillagerBuffer.limit - used;
4136 EdEventBuffer.base = base;
4137 EdEventBuffer.limit = limit;
4138 EdEventBuffer.used = 0;
4139 return 1;
4140}
4141
4142static int _CLEAR_EVENT_EXBUFF(RS_STACKDATA *stack, int argument_count) {
4143 int used = EdEventBuffer.used;
4144 u_char *base = EdEventBuffer.base + used * 16;
4145 int limit = EdEventBuffer.limit - used;
4146 EdEventExBuffer.base = base;
4147 EdEventExBuffer.limit = limit;
4148 EdEventExBuffer.used = 0;
4149 return 1;
4150}
4151
4152static int _LOAD_SCENE(RS_STACKDATA *stack, int argument_count) {
4153 CCharacter *scene = GetScene(GetStackInt(stack++));
4154
4155 if (scene == NULL) {
4156 return 0;
4157 }
4158
4159 char *name = GetStackString(stack++);
4160
4161 if (name == NULL) {
4162 return 0;
4163 }
4164
4165 u_int *pack = get_pack_file();
4166
4167 if (pack == NULL) {
4168 return 0;
4169 }
4170
4171 CDataAlloc2<1> *first = get_buffer();
4172 CDataAlloc2<1> *second = get_buffer();
4173 scene->LoadPackData(pack, name, first, second);
4174 scene->motion_type.state.camera = &DmmyCamera;
4175
4176 if (argument_count >= 3) {
4177 scene->motion_speed = GetStackFloat(stack);
4178 }
4179
4180 return 1;
4181}
4182
4183static int _SYNC_SCENE_CHARA(RS_STACKDATA *stack, int argument_count) {
4184 CCharacter *scene = GetScene(GetStackInt(stack++));
4185
4186 if (scene == NULL) {
4187 return 0;
4188 }
4189
4190 char *name = GetStackString(stack++);
4191 int index = GetStackInt(stack);
4192 CCharacter *character = EdEventInfo.main_character;
4193
4194 if (index >= 0) {
4195 character = GetNPC(index);
4196 }
4197
4198 if (character == NULL) {
4199 return 0;
4200 }
4201
4202 if (scene->frame == NULL) {
4203 return 0;
4204 }
4205
4206 CFrame *reference = scene->frame->SearchFrame(name);
4207
4208 if (reference == NULL) {
4209 return 0;
4210 }
4211
4212 if (character->frame == NULL) {
4213 return 0;
4214 }
4215
4216 character->frame->SetReference(reference);
4217
4218 if (character->shadow_frame != NULL) {
4219 character->shadow_frame->SetReference(reference);
4220 }
4221
4222 return 1;
4223}
4224
4225static int _SYNC_SCENE_CAMERA(RS_STACKDATA *stack, int argument_count) {
4226 CCharacter *scene = GetScene(GetStackInt(stack));
4227
4228 if (scene == NULL) {
4229 return 0;
4230 }
4231
4232 if (EdEventInfo.camera != NULL) {
4233 EdEventInfo.camera->FollowOff();
4234 scene->motion_type.state.camera = EdEventInfo.camera;
4235 }
4236
4237 return 1;
4238}
4239
4240static int _RELEASE_SCENE_CHARA(RS_STACKDATA *stack, int argument_count) {
4241 int index = GetStackInt(stack);
4242 CCharacter *character = EdEventInfo.main_character;
4243
4244 if (index >= 0) {
4245 character = GetNPC(index);
4246 }
4247
4248 if (character == NULL) {
4249 return 0;
4250 }
4251
4252 if (character->frame != NULL) {
4253 character->frame->DeleteReference();
4254 }
4255
4256 if (character->shadow_frame != NULL) {
4257 character->shadow_frame->DeleteReference();
4258 }
4259
4260 return 1;
4261}
4262
4263static int _RELEASE_SCENE_CAMERA(RS_STACKDATA *stack, int argument_count) {
4264 CCharacter *scene = GetScene(GetStackInt(stack));
4265
4266 if (scene == NULL) {
4267 return 0;
4268 }
4269
4270 scene->motion_type.state.camera = &DmmyCamera;
4271 return 1;
4272}
4273
4274static int _SET_SCENE_POS(RS_STACKDATA *stack, int argument_count) {
4275 CCharacter *scene = GetScene(GetStackInt(stack++));
4276
4277 if (scene == NULL) {
4278 return 0;
4279 }
4280
4281 sceVu0FVECTOR position;
4282 GetPosition(stack, position);
4283 scene->SetPosition(position);
4284 return 1;
4285}
4286
4287static int _SET_SCENE_ROT(RS_STACKDATA *stack, int argument_count) {
4288 CCharacter *scene = GetScene(GetStackInt(stack++));
4289
4290 if (scene == NULL) {
4291 return 0;
4292 }
4293
4294 sceVu0FVECTOR rotation;
4295 GetRotation(stack, rotation);
4296 scene->SetRotation(rotation);
4297 return 1;
4298}
4299
4300static int _LOAD_ITEM_FILE(RS_STACKDATA *stack, int argument_count) {
4301 char model_path[128];
4302 char texture_path[128];
4303 int size;
4304 EdGetItemFile(GetStackInt(stack), model_path, texture_path);
4305
4306 if (model_path[0] == '\0' || texture_path[0] == '\0') {
4307 return 0;
4308 }
4309
4310 StartReadBG();
4311 u_long128 *buffer = (u_long128 *) read_buffer;
4312 LoadFileBG(texture_path, buffer, &size);
4313 buffer += (((size >> 6) + 1) << 6) >> 4;
4314 LoadFileBG(model_path, buffer, &size);
4315 return 1;
4316}
4317
4318static int _LOAD_ITEM(RS_STACKDATA *stack, int argument_count) {
4319 int index = GetStackInt(stack);
4320
4321 if (index < 0 || index > 0) {
4322 return 0;
4323 }
4324
4325 BG_READ_INFO *read = GetReadBGFile(0);
4326
4327 if (read == NULL) {
4328 return 0;
4329 }
4330
4331 int size = read->size;
4332 u_long128 *source = read->buffer;
4333 void *copy = get_buffer()->Alloc((size >> 4) + 1);
4334 memcpy(copy, source, size);
4335 LOADTEXTURE_INFO2 textures[2];
4336 textures[0].block_no = 40;
4337 textures[0].mipmap = false;
4338 textures[0].name = (char *) copy;
4339 textures[1].name = NULL;
4340 TexManager.DeleteTextureBlock(40);
4341 TexManager.LoadTextureBlockEX(40, textures);
4342 read = GetReadBGFile(1);
4343
4344 if (read == NULL) {
4345 return 0;
4346 }
4347
4348 EdEventInfo.item_frame[index] = LoadMDSFile((u_int *) read->buffer, get_buffer(), 0, NULL, NULL);
4349 return EdEventInfo.item_frame[index] != NULL ? 1 : 0;
4350}
4351
4352static int _SYNC_CHARA_ITEM(RS_STACKDATA *stack, int argument_count) {
4353 CCharacter *character = GetChara(GetStackInt(stack++));
4354 char *name = GetStackString(stack++);
4355 CFrame *reference = NULL;
4356
4357 if (name != NULL && name[0] != '\0') {
4358 reference = character->frame->SearchFrame(name);
4359 }
4360
4361 if (reference == NULL) {
4362 reference = character->frame;
4363 }
4364
4365 CFrame *item = GetItemFrame(GetStackInt(stack));
4366
4367 if (item == NULL) {
4368 return 0;
4369 }
4370
4371 item->SetReference(reference);
4372 return 1;
4373}
4374
4375static int _RELEASE_CHARA_ITEM(RS_STACKDATA *stack, int argument_count) {
4376 CFrame *frame = GetItemFrame(GetStackInt(stack));
4377
4378 if (frame != NULL) {
4379 frame->DeleteReference();
4380 }
4381
4382 return 1;
4383}
4384
4385static int _DELETE_ITEM(RS_STACKDATA *stack, int argument_count) {
4386 DeleteItemFrame(GetStackInt(stack));
4387 TexManager.DeleteTextureBlock(40);
4388 return 1;
4389}
4390
4391static int _SYNC_CHARA_CHARA(RS_STACKDATA *stack, int argument_count) {
4392 CCharacter *source = GetChara(GetStackInt(stack++));
4393
4394 if (source == NULL) {
4395 return 0;
4396 }
4397
4398 char *name = GetStackString(stack++);
4399
4400 if (name == NULL) {
4401 return 0;
4402 }
4403
4404 CFrame *reference;
4405
4406 if (name[0] != '\0') {
4407 reference = source->frame->SearchFrame(name);
4408 } else {
4409 reference = source->frame;
4410 }
4411
4412 if (reference == NULL) {
4413 return 0;
4414 }
4415
4416 CCharacter *target = GetChara(GetStackInt(stack));
4417
4418 if (target == NULL) {
4419 return 0;
4420 }
4421
4422 if (target->frame == NULL) {
4423 return 0;
4424 }
4425
4426 target->frame->SetReference(reference);
4427
4428 if (target->shadow_frame != NULL) {
4429 target->shadow_frame->SetReference(reference);
4430 }
4431
4432 return 1;
4433}
4434
4435static int _RELEASE_CHARA_CHARA(RS_STACKDATA *stack, int argument_count) {
4436 CCharacter *character = GetChara(GetStackInt(stack));
4437
4438 if (character == NULL) {
4439 return 0;
4440 }
4441
4442 if (character->frame != NULL) {
4443 character->frame->DeleteReference();
4444 }
4445
4446 if (character->shadow_frame != NULL) {
4447 character->shadow_frame->DeleteReference();
4448 }
4449
4450 return 1;
4451}
4452
4453static int _GET_CHARA_POS(RS_STACKDATA *stack, int argument_count) {
4454 sceVu0FVECTOR position;
4455
4456 if (argument_count < 3) {
4457 return 0;
4458 }
4459
4460 EdEventInfo.main_character->GetPosition(position);
4461 SetPosition(stack, position);
4462 return 1;
4463}
4464
4465static int _GET_CHARA_TALK_POS(RS_STACKDATA *stack, int argument_count) {
4466 int position[2];
4467
4468 if (argument_count < 2) {
4469 return 0;
4470 }
4471
4472 GetScrPosFromChar(EdEventInfo.main_character, position);
4473 SetStack(stack++, position[0]);
4474 SetStack(stack, position[1]);
4475 return 1;
4476}
4477
4478static int _SET_CHARA_POS(RS_STACKDATA *stack, int argument_count) {
4479 sceVu0FVECTOR position;
4480 GetPosition(stack, position);
4481 EdEventInfo.main_character->SetPosition(position);
4482 return 1;
4483}
4484
4485static int _SET_CHARA_ROT(RS_STACKDATA *stack, int argument_count) {
4486 sceVu0FVECTOR rotation;
4487
4488 if (argument_count == 3) {
4489 GetRotation(stack, rotation);
4490 stack += 3;
4491 }
4492
4493 if (argument_count == 1) {
4494 rotation[2] = 0.0f;
4495 rotation[0] = 0.0f;
4496 rotation[1] = GetStackFloat(stack);
4497 GetWorldRot(rotation, rotation);
4498 }
4499
4500 EdEventInfo.main_character->SetRotation(rotation);
4501 return 1;
4502}
4503
4504static int _GET_CHARA_ROT(RS_STACKDATA *stack, int argument_count) {
4505 sceVu0FVECTOR rotation;
4506
4507 if (argument_count < 3) {
4508 return 0;
4509 }
4510
4511 EdEventInfo.main_character->GetRotation(rotation);
4512 SetRotation(stack, rotation);
4513 return 1;
4514}
4515
4516int _TURN_CHARA(RS_STACKDATA *stack, int argument_count) {
4517 sceVu0FVECTOR position;
4518 GetPosition(stack, position);
4519 turn_chara(EdEventInfo.main_character, position, GetStackFloat(stack += 3));
4520 return 1;
4521}
4522
4523static int _GET_NPC_TALK_POS(RS_STACKDATA *stack, int argument_count) {
4524 int position[2];
4525
4526 if (argument_count < 2) {
4527 return 0;
4528 }
4529
4530 RS_STACKDATA *result = (0, stack + 1);
4531 int index = GetStackInt(stack);
4532
4533 if (index == -1) {
4534 return _GET_CHARA_TALK_POS(result, argument_count - 1);
4535 }
4536
4537 if (index < 0 || index >= EdEventInfo.npc_count) {
4538 return 0;
4539 }
4540
4541 GetScrPosFromChar(&EdEventInfo.npcs[index], position);
4542 SetStack(result++, position[0]);
4543 SetStack(result, position[1]);
4544 return 1;
4545}
4546
4547static int _GET_NPC_POS(RS_STACKDATA *stack, int argument_count) {
4548 sceVu0FVECTOR position;
4549
4550 if (argument_count < 4) {
4551 return 0;
4552 }
4553
4554 RS_STACKDATA *result = (0, stack + 1);
4555 CCharacter *character = GetChara(GetStackInt(stack));
4556
4557 if (character == NULL) {
4558 return 0;
4559 }
4560
4561 character->GetPosition(position);
4562
4563 if (character->frame != NULL && character->frame->parent != NULL) {
4564 SetStack(result++, position[0]);
4565 SetStack(result++, position[1]);
4566 SetStack(result, position[2]);
4567 return 1;
4568 }
4569
4570 SetPosition(result, position);
4571 return 1;
4572}
4573
4574static int _SET_NPC_POS(RS_STACKDATA *stack, int argument_count) {
4575 sceVu0FVECTOR position;
4576 RS_STACKDATA *argument = (0, stack + 1);
4577 CCharacter *character = GetChara(GetStackInt(stack));
4578
4579 if (character == NULL) {
4580 return 0;
4581 }
4582
4583 if (character->frame != NULL && character->frame->parent != NULL) {
4584 position[0] = GetStackFloat(argument++);
4585 position[1] = GetStackFloat(argument++);
4586 position[2] = GetStackFloat(argument);
4587 position[3] = 1.0f;
4588 character->SetPosition(position);
4589 return 1;
4590 }
4591
4592 GetPosition(argument, position);
4593 character->SetPosition(position);
4594 return 1;
4595}
4596
4597static int _SET_NPC_ROT(RS_STACKDATA *stack, int argument_count) {
4598 sceVu0FVECTOR rotation;
4599 CCharacter *character = GetChara(GetStackInt(stack++));
4600
4601 if (character == NULL) {
4602 return 0;
4603 }
4604
4605 CFrame *parent = NULL;
4606
4607 if (character->frame != NULL) {
4608 parent = character->frame->parent;
4609 }
4610
4611 if (argument_count == 4) {
4612 if (parent != NULL) {
4613 rotation[0] = GetStackFloat(stack++);
4614 rotation[1] = GetStackFloat(stack++);
4615 rotation[2] = GetStackFloat(stack++);
4616 } else {
4617 GetRotation(stack, rotation);
4618 stack += 3;
4619 }
4620 }
4621
4622 if (argument_count == 2) {
4623 rotation[2] = 0.0f;
4624 rotation[0] = 0.0f;
4625 rotation[1] = GetStackFloat(stack);
4626
4627 if (parent == NULL) {
4628 GetWorldRot(rotation, rotation);
4629 }
4630 }
4631
4632 character->SetRotation(rotation);
4633 return 1;
4634}
4635
4636static int _GET_NPC_ROT(RS_STACKDATA *stack, int argument_count) {
4637 sceVu0FVECTOR rotation;
4638
4639 if (argument_count < 4) {
4640 return 0;
4641 }
4642
4643 RS_STACKDATA *result = (0, stack + 1);
4644 CCharacter *character = GetChara(GetStackInt(stack));
4645
4646 if (character == NULL) {
4647 return 0;
4648 }
4649
4650 character->GetRotation(rotation);
4651
4652 if (character->frame != NULL && character->frame->parent != NULL) {
4653 SetStack(result++, rotation[0]);
4654 SetStack(result++, rotation[1]);
4655 SetStack(result, rotation[2]);
4656 return 1;
4657 }
4658
4659 SetRotation(result, rotation);
4660 return 1;
4661}
4662
4663static int _SET_NPC_SCALE(RS_STACKDATA *stack, int argument_count) {
4664 CCharacter *character = GetChara(GetStackInt(stack++));
4665
4666 if (character == NULL) {
4667 return 0;
4668 }
4669
4670 float x = GetStackFloat(stack++);
4671
4672 if (argument_count == 2) {
4673 character->SetScale(x, x, x);
4674 } else {
4675 float y = GetStackFloat(stack++);
4676 float z = GetStackFloat(stack);
4677 character->SetScale(x, y, z);
4678 }
4679
4680 return 1;
4681}
4682
4683static int _GET_NPC_SCALE(RS_STACKDATA *stack, int argument_count) {
4684 sceVu0FVECTOR scale;
4685 RS_STACKDATA *result = (0, stack + 1);
4686 CCharacter *character = GetChara(GetStackInt(stack));
4687
4688 if (character == NULL) {
4689 return 0;
4690 }
4691
4692 character->GetScale(scale);
4693 SetStack(result++, scale[0]);
4694 SetStack(result++, scale[1]);
4695 SetStack(result, scale[2]);
4696 return 1;
4697}
4698
4699static int _NPC_POS_INIT(RS_STACKDATA *stack, int argument_count) {
4700 sceVu0FVECTOR transform = {0.0f, 0.0f, 0.0f, 0.0f};
4701
4702 for (int i = 0; i < argument_count; i++) {
4703 CCharacter *character = GetChara(GetStackInt(stack++));
4704
4705 if (character != NULL) {
4706 character->SetPosition(transform);
4707 character->SetRotation(transform);
4708 }
4709 }
4710
4711 return 1;
4712}
4713
4714static int _GET_NPC_PARTS_NO(RS_STACKDATA *stack, int argument_count) {
4715 if (argument_count < 2) {
4716 return 0;
4717 }
4718
4719 int index = GetStackInt(stack++);
4720
4721 if (index < 0 || index >= 16) {
4722 return 0;
4723 }
4724
4725 SetStack(stack++, EdEventInfo.villagers[index].character_no);
4726 return 1;
4727}
4728
4729static int _SET_NPC_MOTION(RS_STACKDATA *stack, int argument_count) {
4730 int index = GetStackInt(stack++);
4731 CCharacter *character;
4732
4733 if (index == -1) {
4734 character = EdEventInfo.main_character;
4735 } else {
4736 character = GetNPC(index);
4737 }
4738
4739 if (character == NULL) {
4740 return 0;
4741 }
4742
4743 int motion = GetStackInt(stack++);
4744 float speed = -1.0f;
4745
4746 if (argument_count >= 3) {
4747 speed = GetStackFloat(stack++);
4748 }
4749
4750 if (argument_count == 4) {
4751 character->SetMotion(motion, GetStackInt(stack));
4752 } else {
4753 character->SetMotion(motion, 0);
4754 }
4755
4756 if (speed > 0.0f) {
4757 character->SetMotionSpeed(speed);
4758 }
4759
4760 return 1;
4761}
4762
4763static int _SET_NPC_ANIME(RS_STACKDATA *stack, int argument_count) {
4764 int index = GetStackInt(stack++);
4765 CCharacter *character;
4766
4767 if (index == -1) {
4768 character = EdEventInfo.main_character;
4769 } else {
4770 character = GetNPC(index);
4771 }
4772
4773 if (character == NULL) {
4774 return 0;
4775 }
4776
4777 int animation = GetStackInt(stack++);
4778 int enable = true;
4779
4780 if (argument_count == 3) {
4781 enable = GetStackInt(stack);
4782 }
4783
4784 if (animation == -1 && enable == 0) {
4785 character->ClearTexAnime();
4786 }
4787
4788 if (enable != 0) {
4789 character->TexAnimeOn(animation);
4790 } else {
4791 character->TexAnimeOff(animation);
4792 }
4793
4794 return 1;
4795}
4796
4797static int _TURN_NPC(RS_STACKDATA *stack, int argument_count) {
4798 sceVu0FVECTOR position;
4799 int index = GetStackInt(stack++);
4800
4801 if (index == -1) {
4802 return _TURN_CHARA(stack, argument_count - 1);
4803 }
4804
4805 CCharacter *character = GetNPC(index);
4806
4807 if (character == NULL) {
4808 return 0;
4809 }
4810
4811 GetPosition(stack, position);
4812 turn_chara(character, position, GetStackFloat(stack += 3));
4813 return 1;
4814}
4815
4816int _NPC_DRAW(RS_STACKDATA *stack, int argument_count) {
4817 int draw = GetStackInt(stack++);
4818
4819 for (int i = 0; i < argument_count - 1; i++) {
4820 int index = GetStackInt(stack++);
4821
4822 if (GetChara(index) != NULL) {
4823 if (index < 0) {
4824 EdEventInfo.player_draw = draw;
4825 }
4826
4827 if (index >= 0 && index < 16) {
4828 EdEventInfo.npc_draw[index] = draw;
4829 }
4830 }
4831 }
4832
4833 return 1;
4834}
4835
4836int _NPC_DRAW_SHADOW(RS_STACKDATA *stack, int argument_count) {
4837 int draw = GetStackInt(stack++);
4838
4839 for (int i = 0; i < argument_count - 1; i++) {
4840 int index = GetStackInt(stack++);
4841
4842 if (GetChara(index) != NULL) {
4843 if (index < 0) {
4844 EdEventInfo.player_shadow_draw = draw;
4845 }
4846
4847 if (index >= 0 && index < 16) {
4848 EdEventInfo.npc_shadow_draw[index] = draw;
4849 }
4850 }
4851 }
4852
4853 return 1;
4854}
4855
4856int _SET_NPC_FOOT_SOUND(RS_STACKDATA *stack, int argument_count) {
4857 int mode = GetStackInt(stack++);
4858
4859 for (int i = 0; i < argument_count - 1; i++) {
4860 int index = GetStackInt(stack++);
4861 CCharacter *character = GetChara(index);
4862
4863 if (character != NULL) {
4864 if (index < 0) {
4865 EdEventInfo.player_foot_sound = mode;
4866 }
4867
4868 if (index >= 0 && index < 16) {
4869 EdEventInfo.npc_foot_sound[index] = mode;
4870 }
4871
4872 if (mode == 2) {
4873 character->FootSoundEnable(1);
4874 }
4875 }
4876 }
4877
4878 return 1;
4879}
4880
4881static int _SET_NPC_FLOOR_ID(RS_STACKDATA *stack, int argument_count) {
4882 RS_STACKDATA *argument = (0, stack + 1);
4883 CCharacter *character = GetChara(GetStackInt(stack));
4884
4885 if (character == NULL) {
4886 return 0;
4887 }
4888
4889 character->SetFootSoundID(GetStackInt(argument));
4890 return 1;
4891}
4892
4900static s32 _NPC_STEP(RS_STACKDATA *stack, s32 argument_count) {
4901 return 1;
4902}
4903
4904static int _NPC_COL(RS_STACKDATA *stack, int argument_count) {
4905 int collision = GetStackInt(stack++);
4906
4907 for (int i = 0; i < argument_count - 1; i++) {
4908 int index = GetStackInt(stack++);
4909
4910 if (index >= 0) {
4911 EdEventInfo.npc_collision[index] = collision;
4912 }
4913
4914 if (index == -1) {
4915 EdEventInfo.player_collision = collision;
4916 }
4917 }
4918
4919 return 1;
4920}
4921
4922static int _NPC_STOP(RS_STACKDATA *stack, int argument_count) {
4923 int stopped = GetStackInt(stack++);
4924
4925 for (int i = 0; i < argument_count - 1; i++) {
4926 int index = GetStackInt(stack++);
4927
4928 if (index >= 0) {
4929 EdEventInfo.npc_stop[index] = stopped;
4930 }
4931
4932 if (index == -1) {
4933 EdEventInfo.player_stop = stopped;
4934 }
4935 }
4936
4937 return 1;
4938}
4939
4940static int _NPC_DRAW_BEFORE(RS_STACKDATA *stack, int argument_count) {
4941 int order = GetStackInt(stack++);
4942 int i = 0;
4943
4944 while (i < argument_count - 1) {
4945 int index = GetStackInt(stack++);
4946
4947 if (index >= 0) {
4948 EdEventInfo.npc_draw_before[index] = order;
4949 }
4950
4951 i++;
4952 }
4953
4954 return 1;
4955}
4956
4957static int _INIT_NPC_CLOTH(RS_STACKDATA *stack, int argument_count) {
4958 int index = GetStackInt(stack);
4959 CCharacter *character;
4960
4961 if (index == -1) {
4962 character = EdEventInfo.main_character;
4963 } else {
4964 character = GetNPC(index);
4965 }
4966
4967 if (character == NULL) {
4968 return 0;
4969 }
4970
4971 character->ClothStep(-1);
4972 return 1;
4973}
4974
4975static int _NPC_CLOTH_FLOOR(RS_STACKDATA *stack, int argument_count) {
4976 RS_STACKDATA *argument = (0, stack + 1);
4977 CCharacter *character = GetChara(GetStackInt(stack));
4978
4979 if (character == NULL) {
4980 return 0;
4981 }
4982
4983 character->ClothFloor(GetStackInt(argument));
4984 return 1;
4985}
4986
4987static int _NPC_CLOTH_STEP(RS_STACKDATA *stack, int argument_count) {
4988 CCharacter *character = GetChara(GetStackInt(stack++));
4989
4990 if (character == NULL) {
4991 return 0;
4992 }
4993
4994 int steps = 1;
4995
4996 if (argument_count > 1) {
4997 steps = GetStackInt(stack);
4998 }
4999
5000 for (int i = 0; i < steps; i++) {
5001 character->ClothStep(0);
5002 }
5003
5004 return 1;
5005}
5006
5007static int _SET_NPC_AMBIENT(RS_STACKDATA *stack, int argument_count) {
5008 CCharacter *character = GetChara(GetStackInt(stack++));
5009
5010 if (character == NULL) {
5011 return 0;
5012 }
5013
5014 sceVu0FVECTOR ambient = {0.0f, 0.0f, 0.0f, 128.0f};
5015
5016 if (argument_count == 1) {
5017 sceVu0CopyVector(character->ambient_offset, ambient);
5018 return 1;
5019 }
5020
5021 if ((unsigned int) (argument_count - 2) < 2) {
5022 float value = GetStackInt(stack++);
5023 character->ambient_offset[0] = value;
5024 character->ambient_offset[1] = value;
5025 character->ambient_offset[2] = value;
5026 }
5027
5028 if (argument_count >= 4) {
5029 character->ambient_offset[0] = GetStackInt(stack++);
5030 character->ambient_offset[1] = GetStackInt(stack++);
5031 character->ambient_offset[2] = GetStackInt(stack++);
5032 }
5033
5034 if (argument_count >= 5) {
5035 character->ambient_offset[3] = GetStackInt(stack);
5036 }
5037
5038 return 1;
5039}
5040
5041static int _SET_NPC_BODY_SIZE(RS_STACKDATA *stack, int argument_count) {
5042 CCharacter *character = GetChara(GetStackInt(stack++));
5043
5044 if (character == NULL) {
5045 return 0;
5046 }
5047
5048 if (argument_count > 1) {
5049 character->body_width = GetStackFloat(stack++);
5050 }
5051
5052 if (argument_count > 2) {
5053 character->body_height = GetStackFloat(stack++);
5054 }
5055
5056 if (argument_count > 3) {
5057 character->body_depth = GetStackFloat(stack);
5058 }
5059
5060 return 1;
5061}
5062
5063static int _GET_NPC_BODY_SIZE(RS_STACKDATA *stack, int argument_count) {
5064 CCharacter *character = GetChara(GetStackInt(stack++));
5065
5066 if (character == NULL) {
5067 return 0;
5068 }
5069
5070 if (argument_count > 1) {
5071 SetStack(stack++, character->body_width);
5072 }
5073
5074 if (argument_count > 2) {
5075 SetStack(stack++, character->body_height);
5076 }
5077
5078 if (argument_count > 3) {
5079 SetStack(stack, character->body_depth);
5080 }
5081
5082 return 1;
5083}
5084
5085static int _NPC_PLIGHT_INIT(RS_STACKDATA *stack, int argument_count) {
5086 CCharacter *character = GetChara(GetStackInt(stack));
5087
5088 if (character == NULL) {
5089 return 0;
5090 }
5091
5092 character->ClearPointLight();
5093 return 1;
5094}
5095
5096static int _SET_NPC_PLIGHT(RS_STACKDATA *stack, int argument_count) {
5097 sceVu0FVECTOR position;
5098 float light[5];
5099 CCharacter *character = GetChara(GetStackInt(stack++));
5100
5101 if (character == NULL) {
5102 return 0;
5103 }
5104
5105 GetPosition(stack, position);
5106 stack += 3;
5107
5108 for (int i = 0; i < 5; i++) {
5109 light[i] = GetStackFloat(stack++);
5110 }
5111
5112 return character->SetPointLight(position, light[0], light[1], light[2], light[3], light[4], 128.0f);
5113}
5114
5115static int _SGET_NPC_TALK_MES(RS_STACKDATA *stack, int argument_count) {
5116 if (argument_count < 2) {
5117 return 0;
5118 }
5119
5120 RS_STACKDATA *result = (0, stack + 1);
5121 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(NowEditMap, GetStackInt(stack));
5122
5123 if (npc == NULL) {
5124 return 0;
5125 }
5126
5127 SetStack(result, npc->talk_message);
5128 return 1;
5129}
5130
5131static int _SSET_NPC_TALK_MES(RS_STACKDATA *stack, int argument_count) {
5132 RS_STACKDATA *next = (0, stack + 1);
5133 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(NowEditMap, GetStackInt(stack));
5134
5135 if (npc == NULL) {
5136 return 0;
5137 }
5138
5139 npc->talk_message = GetStackInt(next);
5140 return 1;
5141}
5142
5143static ClsMes *GetMes(int index) {
5144 if (index < 0 || index >= 8) {
5145 return NULL;
5146 }
5147
5148 return EdEventInfo.messages[index];
5149}
5150
5151static int _MES_MAKE(RS_STACKDATA *stack, int argument_count) {
5152 ClsMes *message = GetMes(GetStackInt(stack++));
5153
5154 if (message == NULL) {
5155 return 0;
5156 }
5157
5158 if (EdEventInfo.camera != NULL) {
5159 sceVu0FMATRIX view;
5160 sceVu0FVECTOR eye;
5161 EdEventInfo.camera->GetCameraMatrix(view);
5162 EdEventInfo.camera->GetPos(eye);
5163 MGSetViewMatrix(view, eye);
5164 }
5165
5166 int message_no = GetStackInt(stack++);
5167
5168 if (argument_count >= 3) {
5169 message->value = GetStackInt(stack++);
5170 }
5171
5172 if (argument_count >= 4) {
5173 for (int i = 0; i < 4; i++) {
5174 message->mes_no[i] = -1;
5175 }
5176
5177 for (int i = 4; argument_count >= i; i++) {
5178 int slot_message = GetStackInt(stack++);
5179 message->mes_no[i - 4] = slot_message;
5180 printf("%d %d\n", i - 4, slot_message);
5181 }
5182 }
5183
5184 message->MakeMesWin(message_no);
5185 return 1;
5186}
5187
5188static int _MES_CLOSE(RS_STACKDATA *stack, int argument_count) {
5189 ClsMes *message = GetMes(GetStackInt(stack));
5190
5191 if (message == NULL) {
5192 return 0;
5193 }
5194
5195 message->text_rate = message->text_rate_set;
5196 message->mes_made = -1;
5197 message->fade_in = false;
5198 return 1;
5199}
5200
5201static int _MES_NEXTPAGE(RS_STACKDATA *stack, int argument_count) {
5202 ClsMes *message = GetMes(GetStackInt(stack));
5203
5204 if (message == NULL) {
5205 return 0;
5206 }
5207
5208 message->GoNextPage();
5209 return 1;
5210}
5211
5212int _SET_MES_AUTOSET(RS_STACKDATA *stack, int argument_count) {
5213 ClsMes *message = GetMes(GetStackInt(stack++));
5214
5215 if (message == NULL) {
5216 return 0;
5217 }
5218
5219 if (EdEventInfo.camera != NULL) {
5220 sceVu0FMATRIX view;
5221 sceVu0FVECTOR eye;
5222 EdEventInfo.camera->GetCameraMatrix(view);
5223 EdEventInfo.camera->GetPos(eye);
5224 MGSetViewMatrix(view, eye);
5225 }
5226
5227 int position[4];
5228 int talk_position[4];
5229
5230 if (argument_count == 5) {
5231 for (int i = 0; i < 4; i++) {
5232 position[i] = GetStackInt(stack++);
5233 }
5234
5235 message->AutoSet(position);
5236 return 1;
5237 }
5238
5239 if (argument_count == 3) {
5240 int first_index = GetStackInt(stack++);
5241 int second_index = GetStackInt(stack);
5242 CCharacter *speaker = first_index == -1 ? EdEventInfo.main_character : GetNPC(first_index);
5243 CCharacter *listener = second_index == -1 ? EdEventInfo.main_character : GetNPC(second_index);
5244 message->AutoSetSub(speaker, listener, talk_position);
5245 message->AutoSet(talk_position);
5246 return 1;
5247 }
5248
5249 return 0;
5250}
5251
5252static int _SET_MES_SHIPPO(RS_STACKDATA *stack, int argument_count) {
5253 ClsMes *message = GetMes(GetStackInt(stack++));
5254
5255 if (message == NULL) {
5256 return 0;
5257 }
5258
5259 message->tail_on = GetStackInt(stack++);
5260
5261 if (argument_count > 2) {
5262 message->tail_length = GetStackInt(stack++);
5263 }
5264
5265 if (argument_count > 3) {
5266 message->tail_half_width = GetStackInt(stack);
5267 }
5268
5269 return 1;
5270}
5271
5272static int _SET_MES_POS(RS_STACKDATA *stack, int argument_count) {
5273 RS_STACKDATA *next = (0, stack + 1);
5274 ClsMes *message = GetMes(GetStackInt(stack));
5275
5276 if (message == NULL) {
5277 return 0;
5278 }
5279
5280 message->auto_pos = GetStackInt(next);
5281 return 1;
5282}
5283
5284static int _SET_MES_DRAWSPEED(RS_STACKDATA *stack, int argument_count) {
5285 RS_STACKDATA *next = (0, stack + 1);
5286 ClsMes *message = GetMes(GetStackInt(stack));
5287
5288 if (message == NULL) {
5289 return 0;
5290 }
5291
5292 message->text_rate = GetStackFloat(next);
5293 return 1;
5294}
5295
5296static int _SET_MES_CURSOR(RS_STACKDATA *stack, int argument_count) {
5297 RS_STACKDATA *next = (0, stack + 1);
5298 ClsMes *message = GetMes(GetStackInt(stack));
5299
5300 if (message == NULL) {
5301 return 0;
5302 }
5303
5304 message->cursor_row = GetStackInt(next);
5305 return 1;
5306}
5307
5308static int _SET_MES_OKURI(RS_STACKDATA *stack, int argument_count) {
5309 RS_STACKDATA *next = (0, stack + 1);
5310 ClsMes *message = GetMes(GetStackInt(stack));
5311
5312 if (message == NULL) {
5313 return 0;
5314 }
5315
5316 message->page_arrow = GetStackInt(next);
5317 return 1;
5318}
5319
5320static int _SET_MES_WIN_FLAG(RS_STACKDATA *stack, int argument_count) {
5321 RS_STACKDATA *next = (0, stack + 1);
5322 ClsMes *message = GetMes(GetStackInt(stack));
5323
5324 if (message == NULL) {
5325 return 0;
5326 }
5327
5328 message->stay_frame = GetStackInt(next);
5329 return 1;
5330}
5331
5332static int _CHECK_MES_COMPLETE(RS_STACKDATA *stack, int argument_count) {
5333 if (argument_count < 2) {
5334 return 0;
5335 }
5336
5337 RS_STACKDATA *result = (0, stack + 1);
5338 ClsMes *message = GetMes(GetStackInt(stack));
5339
5340 if (message == NULL) {
5341 return 0;
5342 }
5343
5344 SetStack(result, message->State() == CLSMES_SHOWN);
5345 return 1;
5346}
5347
5348static int _CHECK_MES_WAIT(RS_STACKDATA *stack, int argument_count) {
5349 if (argument_count < 2) {
5350 return 0;
5351 }
5352
5353 RS_STACKDATA *result = (0, stack + 1);
5354 ClsMes *message = GetMes(GetStackInt(stack));
5355
5356 if (message == NULL) {
5357 return 0;
5358 }
5359
5360 SetStack(result, message->State() == CLSMES_PAGE_WAIT);
5361 return 1;
5362}
5363
5364static int _CHECK_MES(RS_STACKDATA *stack, int argument_count) {
5365 if (argument_count < 2) {
5366 return 0;
5367 }
5368
5369 RS_STACKDATA *result = (0, stack + 1);
5370 ClsMes *message = GetMes(GetStackInt(stack));
5371
5372 if (message == NULL) {
5373 return 0;
5374 }
5375
5376 SetStack(result, message->State() == CLSMES_CLOSED);
5377 return 1;
5378}
5379
5380static int _SET_MES_FUKIDASHI(RS_STACKDATA *stack, int argument_count) {
5381 RS_STACKDATA *next = (0, stack + 1);
5382 ClsMes *message = GetMes(GetStackInt(stack));
5383
5384 if (message == NULL) {
5385 return 0;
5386 }
5387
5388 message->SetMesFukidashi(GetStackInt(next));
5389 return 1;
5390}
5391
5392static int _ITEM_GET_MES(RS_STACKDATA *stack, int argument_count) {
5393 int item = GetStackInt(stack++);
5394 int attachment = -1;
5395
5396 if (GetAddAttachItem(item) != 0) {
5397 attachment = 3;
5398 }
5399
5400 if (argument_count == 2) {
5401 attachment = GetStackInt(stack);
5402 }
5403
5404 ItemGetMes(item, attachment, 40, 1);
5405 return 1;
5406}
5407
5408static int _INIT_SYS_MES(RS_STACKDATA *stack, int argument_count) {
5409 ClearSystemMes();
5410 return 1;
5411}
5412
5413static int _SKILL_GET_MES(RS_STACKDATA *stack, int argument_count) {
5414 TecGetMes(GetStackInt(stack), 40);
5415 return 1;
5416}
5417
5418static int _ADD_MAXITEM_MES(RS_STACKDATA *stack, int argument_count) {
5419 int amount = GetStackInt(stack);
5420
5421 if (amount < 0) {
5422 amount = EdAddMaxItem(0);
5423 }
5424
5425 MaxUpMes(amount, 40);
5426 return 1;
5427}
5428
5429static int _CHECK_COMPLETE_PARTS(RS_STACKDATA *stack, int argument_count) {
5430 if (argument_count < 2) {
5431 return 0;
5432 }
5433
5434 RS_STACKDATA *result = (0, stack + 1);
5435 SetStack(result, (0, EditPartsInfo.CheckComplete(GetStackInt(stack))));
5436 return 1;
5437}
5438
5439static int _GET_EDIT_PARTS_POS(RS_STACKDATA *stack, int argument_count) {
5440 sceVu0FVECTOR position;
5441 sceVu0FVECTOR rotation;
5442 CMapParts *parts = EdEventInfo.edit_ground->GetPartsObject(GetStackInt(stack++));
5443
5444 if (parts == NULL) {
5445 return 0;
5446 }
5447
5448 if (argument_count < 4) {
5449 return 0;
5450 }
5451
5452 parts->GetPosition(position);
5453 parts->GetRotation(rotation);
5454 SetStack(stack++, position[0]);
5455 SetStack(stack++, position[1]);
5456 SetStack(stack++, position[2]);
5457
5458 if (argument_count == 7) {
5459 SetStack(stack++, rotation[0]);
5460 SetStack(stack++, rotation[1]);
5461 SetStack(stack, rotation[2]);
5462 }
5463
5464 return 1;
5465}
5466
5467static int _GET_NOW_TIME(RS_STACKDATA *stack, int argument_count) {
5468 SetStack(stack, (0, EdGetTime(EdEventInfo.current_time)));
5469 return 1;
5470}
5471
5472static int _SET_CLOCK(RS_STACKDATA *stack, int argument_count) {
5473 EdSetClock(GetStackFloat(stack));
5474 return 1;
5475}
5476
5477static int _GET_CLOCK(RS_STACKDATA *stack, int argument_count) {
5478 SetStack(stack, EdGetClock());
5479 return 1;
5480}
5481
5482static int _SGET_CMP_EVENT(RS_STACKDATA *stack, int argument_count) {
5483 RS_STACKDATA *result = (0, stack + 1);
5484 int event = GetStackInt(stack);
5485 SetStack(result, (0, EditPartsInfo.GetCompEvent(event)));
5486 return 1;
5487}
5488
5489static int _SSET_CMP_EVENT(RS_STACKDATA *stack, int argument_count) {
5490 RS_STACKDATA *next = (0, stack + 1);
5491 int event = GetStackInt(stack);
5492 EditPartsInfo.SetCompEvent(event, GetStackInt(next));
5493 return 1;
5494}
5495
5496static int _SCHECK_REQUEST(RS_STACKDATA *stack, int argument_count) {
5497 RS_STACKDATA *result = (0, stack + 1);
5498 int request = GetStackInt(stack);
5499 SetStack(result, (0, EditPartsInfo.GetRequest(request)));
5500 return 1;
5501}
5502
5503static int _CHECK_PLACE(RS_STACKDATA *stack, int argument_count) {
5504 SetStack(stack, EdInteriorFlag);
5505 return 1;
5506}
5507
5508static int _CHECK_VILLAGER(RS_STACKDATA *stack, int argument_count) {
5509 RS_STACKDATA *result = (0, stack + 1);
5510 int index = GetStackInt(stack);
5511 SetStack(result, EdCheckVillager(index, &EdEventInfo.villagers[index], EdEventInfo.edit_ground));
5512 return 1;
5513}
5514
5515static int _DELETE_ROBO_PARTS(RS_STACKDATA *stack, int argument_count) {
5516 EdDeleteE05RoboParts();
5517 return 1;
5518}
5519
5520static int _HOBJ_FIXPARTS(RS_STACKDATA *stack, int argument_count) {
5521 if (EdEventInfo.fixed_parts == NULL) {
5522 return 1;
5523 }
5524
5525 if (EdEventInfo.fixed_parts_count <= 0) {
5526 return 1;
5527 }
5528
5529 int handle = GetStackInt(stack++);
5530 int index = GetStackInt(stack++);
5531
5532 if (index < 0 || index >= EdEventInfo.fixed_parts_count) {
5533 return 0;
5534 }
5535
5536 int result = 1;
5537 return SetObjHandle(handle, &EdEventInfo.fixed_parts[index], GetStackString(stack)) ? result : 0;
5538}
5539
5540static int _HOBJ_EDITPARTS(RS_STACKDATA *stack, int argument_count) {
5541 if (EdEventInfo.edit_parts == NULL) {
5542 return 1;
5543 }
5544
5545 if (EdEventInfo.edit_parts_count <= 0) {
5546 return 1;
5547 }
5548
5549 int handle = GetStackInt(stack++);
5550 int index = GetStackInt(stack++);
5551
5552 if (index < 0 || index >= EdEventInfo.edit_parts_count) {
5553 return 0;
5554 }
5555
5556 int result = 1;
5557 return SetObjHandle(handle, &EdEventInfo.edit_parts[index], GetStackString(stack)) ? result : 0;
5558}
5559
5560static int _HOBJ_INTERIORPARTS(RS_STACKDATA *stack, int argument_count) {
5561 if (EdEventInfo.interior_parts == NULL) {
5562 return 1;
5563 }
5564
5565 if (EdEventInfo.interior_parts_count <= 0) {
5566 return 1;
5567 }
5568
5569 int handle = GetStackInt(stack++);
5570 int index = GetStackInt(stack++);
5571
5572 if (index < 0 || index >= EdEventInfo.interior_parts_count) {
5573 return 0;
5574 }
5575
5576 int result = 1;
5577 return SetObjHandle(handle, &EdEventInfo.interior_parts[index], GetStackString(stack)) ? result : 0;
5578}
5579
5580static int _HOBJ_CHARA(RS_STACKDATA *stack, int argument_count) {
5581 int handle_index = GetStackInt(stack++);
5582 CCharacter *character = GetChara(GetStackInt(stack++));
5583
5584 if (character == NULL) {
5585 return 0;
5586 }
5587
5588 return SetObjHandle(handle_index, character, GetStackString(stack)) != 0 ? 1 : 0;
5589}
5590
5591static int _HOBJ_BT_HOBJ(RS_STACKDATA *stack, int argument_count) {
5592 OBJ_HANDLE *handle;
5593 int i;
5594 int count;
5595 count = argument_count;
5596 handle = GetObjHandle(GetStackInt(stack++));
5597
5598 if (handle == NULL) {
5599 return 0;
5600 }
5601
5602 memset(handle, 0, sizeof(OBJ_HANDLE));
5603
5604 if (12 < count) {
5605 count = 12;
5606 }
5607
5608 for (i = 0; i < count - 1; i++) {
5609 BT_OBJ_HANDLE *object = GetObjHDL(GetStackInt(stack++));
5610
5611 if (object == NULL) {
5612 return 0;
5613 }
5614
5615 if (object->type == 1) {
5616 if (2 < count) {
5617 return 0;
5618 }
5619
5620 handle->character = object->character;
5621 }
5622
5623 if (object->type == 0) {
5624 handle->frames[i] = object->frame;
5625 }
5626 }
5627
5628 return 1;
5629}
5630
5631static int _HOBJ_ITEM(RS_STACKDATA *stack, int argument_count) {
5632 RS_STACKDATA *next = (0, stack + 1);
5633 int handle_index = GetStackInt(stack);
5634 CFrame *frame = GetItemFrame(GetStackInt(next));
5635
5636 if (frame == NULL) {
5637 return 0;
5638 }
5639
5640 return SetObjHandle(handle_index, frame) != 0 ? 1 : 0;
5641}
5642
5643static int _OBJ_DRAW(RS_STACKDATA *stack, int argument_count) {
5644 int draw = GetStackInt(stack++);
5645
5646 for (int i = 0; i < argument_count - 1; i++) {
5647 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5648
5649 if (handle != NULL) {
5650 obj_draw(handle, draw);
5651 }
5652 }
5653
5654 return 1;
5655}
5656
5657static int _SET_OBJ_POS(RS_STACKDATA *stack, int argument_count) {
5658 sceVu0FVECTOR position;
5659 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5660
5661 if (handle == NULL) {
5662 return 0;
5663 }
5664
5665 position[0] = GetStackFloat(stack++);
5666 position[1] = GetStackFloat(stack++);
5667 position[2] = GetStackFloat(stack);
5668 position[3] = 1.0f;
5669 set_obj_pos(handle, position);
5670 return 1;
5671}
5672
5673static int _GET_OBJ_POS(RS_STACKDATA *stack, int argument_count) {
5674 sceVu0FVECTOR position;
5675 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5676
5677 if (handle == NULL) {
5678 return 0;
5679 }
5680
5681 if (argument_count < 4) {
5682 return 0;
5683 }
5684
5685 get_obj_pos(handle, position);
5686 SetStack(stack++, position[0]);
5687 SetStack(stack++, position[1]);
5688 SetStack(stack, position[2]);
5689 return 1;
5690}
5691
5692static int _SET_OBJ_ROT(RS_STACKDATA *stack, int argument_count) {
5693 sceVu0FVECTOR rotation;
5694 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5695
5696 if (handle == NULL) {
5697 return 0;
5698 }
5699
5700 rotation[0] = AngleLimit(GetStackFloat(stack++));
5701 rotation[1] = AngleLimit(GetStackFloat(stack++));
5702 rotation[2] = AngleLimit(GetStackFloat(stack));
5703 rotation[3] = 0.0f;
5704 set_obj_rot(handle, rotation);
5705 return 1;
5706}
5707
5708static int _GET_OBJ_ROT(RS_STACKDATA *stack, int argument_count) {
5709 sceVu0FVECTOR rotation;
5710 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5711
5712 if (handle == NULL) {
5713 return 0;
5714 }
5715
5716 if (argument_count < 4) {
5717 return 0;
5718 }
5719
5720 get_obj_rot(handle, rotation);
5721 SetStack(stack++, rotation[0]);
5722 SetStack(stack++, rotation[1]);
5723 SetStack(stack, rotation[2]);
5724 return 1;
5725}
5726
5727static int _SET_OBJ_SCALE(RS_STACKDATA *stack, int argument_count) {
5728 RS_STACKDATA *arguments = (0, stack + 1);
5729 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack));
5730
5731 if (handle == NULL) {
5732 return 0;
5733 }
5734
5735 sceVu0FVECTOR scale;
5736 scale[0] = GetStackFloat(arguments++);
5737 scale[1] = GetStackFloat(arguments++);
5738 scale[2] = GetStackFloat(arguments);
5739 scale[3] = 0.0f;
5740 set_obj_scale(handle, scale);
5741 return 1;
5742}
5743
5744static int _GET_OBJ_SCALE(RS_STACKDATA *stack, int argument_count) {
5745 sceVu0FVECTOR scale;
5746 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5747
5748 if (handle == NULL) {
5749 return 0;
5750 }
5751
5752 if (argument_count < 4) {
5753 return 0;
5754 }
5755
5756 get_obj_scale(handle, scale);
5757 SetStack(stack++, scale[0]);
5758 SetStack(stack++, scale[1]);
5759 SetStack(stack, scale[2]);
5760 return 1;
5761}
5762
5763static int _SYNC_OBJ_OBJ(RS_STACKDATA *stack, int argument_count) {
5764 RS_STACKDATA *next = (0, stack + 1);
5765 OBJ_HANDLE *source = GetObjHandle(GetStackInt(stack));
5766
5767 if (source == NULL) {
5768 return 0;
5769 }
5770
5771 OBJ_HANDLE *target = GetObjHandle(GetStackInt(next));
5772
5773 if (target == NULL) {
5774 return 0;
5775 }
5776
5777 sync_obj_obj(source, target);
5778 return 1;
5779}
5780
5781static int _RELEASE_OBJ_OBJ(RS_STACKDATA *stack, int argument_count) {
5782 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack));
5783
5784 if (handle == NULL) {
5785 return 0;
5786 }
5787
5788 release_obj_obj(handle);
5789 return 1;
5790}
5791
5792static int _SET_OBJ_FOG(RS_STACKDATA *stack, int argument_count) {
5793 OBJ_HANDLE *handle = GetObjHandle(GetStackInt(stack++));
5794
5795 if (handle == NULL) {
5796 return 0;
5797 }
5798
5799 CFrameAttr attr;
5800 attr.fog_enable = GetStackInt(stack++);
5801 set_attr_obj(handle, attr, GetStackInt(stack), 0x40);
5802 return 1;
5803}
5804
5805static int _GET_TALKNPC_INFO_ID(RS_STACKDATA *stack, int argument_count) {
5806 if (argument_count <= 0) {
5807 return 0;
5808 }
5809
5810 SetStack(stack, EdNowTalkCharaInfoID());
5811 return 1;
5812}
5813
5814static int _GET_TALKNPC_ID(RS_STACKDATA *stack, int argument_count) {
5815 if (argument_count <= 0) {
5816 return 0;
5817 }
5818
5819 SetStack(stack, EdEventInfo.talk_npc_id);
5820 return 1;
5821}
5822
5830static int _GET_TALKNPC_STATUS(RS_STACKDATA *stack, int argument_count) {
5831 int index = EdEventInfo.talk_npc_id;
5832 int status = 0;
5833
5834 if (index >= 0 && index < EdEventInfo.npc_count) {
5835 CNPCharacter *npc = &EdEventInfo.npcs[index];
5836 status = npc->event_status;
5837 }
5838
5839 SetStack(stack, status);
5840 return 1;
5841}
5842
5843static int _SET_TALK_CAMERA(RS_STACKDATA *stack, int argument_count) {
5847 static sceVu0FVECTOR vv[3] = {
5848 {-18.8f, 7.1f, -21.3f, 1.0f},
5849 {21.0f, 6.5f, -5.7f, 1.0f},
5850 {22.6f, 6.9f, 16.5f, 1.0f},
5851 };
5852
5853 int view = GetStackInt(stack);
5854 sceVu0FVECTOR player_position;
5855 sceVu0FVECTOR npc_position;
5856 sceVu0FVECTOR direction;
5857 EdEventInfo.main_character->GetPosition(player_position);
5858 EdEventInfo.npcs[EdEventInfo.talk_npc_id].GetPosition(npc_position);
5859
5860 if (EdEventInfo.npcs[EdEventInfo.talk_npc_id].event_status == 0) {
5861 view = 0;
5862 }
5863
5864 sceVu0SubVector(direction, npc_position, player_position);
5865 float angle = atan2f(direction[0], direction[2]);
5866 sceVu0FVECTOR midpoint;
5867 sceVu0AddVector(midpoint, player_position, npc_position);
5868 sceVu0ScaleVector(midpoint, midpoint, 0.5f);
5869 midpoint[1] += 15.0f;
5870 CCameraFollow *camera = EdEventInfo.camera;
5871
5872 if (camera != NULL) {
5873 camera->FollowOff();
5874 camera->SetNextRef(NULL, midpoint[0], midpoint[1], midpoint[2]);
5875 camera->SetRef(midpoint);
5876 }
5877
5878 sceVu0FVECTOR camera_position;
5879 sceVu0FMATRIX rotation;
5880 sceVu0UnitMatrix(rotation);
5881 sceVu0RotMatrixY(rotation, rotation, angle);
5882 sceVu0ApplyMatrix(camera_position, rotation, vv[view]);
5883 sceVu0AddVector(camera_position, midpoint, camera_position);
5884
5885 if (camera != NULL) {
5886 camera->SetPos(camera_position);
5887 }
5888
5889 if (camera != NULL) {
5890 camera->SetNextPos(NULL, camera_position[0], camera_position[1], camera_position[2]);
5891 }
5892
5893 if (camera != NULL) {
5894 sceVu0FMATRIX view_matrix;
5895 sceVu0FVECTOR eye;
5896 camera->GetCameraMatrix(view_matrix);
5897 camera->GetPos(eye);
5898 MGSetViewMatrix(view_matrix, eye);
5899 }
5900
5901 return 1;
5902}
5903
5904static int _SET_TALK_MES(RS_STACKDATA *stack, int argument_count) {
5905 for (int i = 0; i < 16; i++) {
5906 EdEventInfo.talk_messages[i] = -1;
5907 }
5908
5909 for (int i = 0; i < argument_count; i++) {
5910 if (i >= 16) {
5911 return 0;
5912 }
5913
5914 EdEventInfo.talk_messages[i] = GetStackInt(stack++);
5915 }
5916
5917 return 1;
5918}
5919
5920static int _SET_TALK_SELECT_MES(RS_STACKDATA *stack, int argument_count) {
5921 RS_STACKDATA *next = (0, stack + 1);
5922 EdEventInfo.talk_select_prompt = GetStackInt(stack);
5923 EdEventInfo.talk_select_message = GetStackInt(next);
5924 return 1;
5925}
5926
5927static int _EVERY_TALK_EVENT(RS_STACKDATA *stack, int argument_count) {
5928 int villager_id = GetStackInt(stack++);
5929
5930 if (villager_id < 0 || villager_id >= 16) {
5931 return 0;
5932 }
5933
5934 int event_no = villager_id + 0x104;
5935
5936 if (argument_count > 1) {
5937 event_no = GetStackInt(stack);
5938 }
5939
5940 for (int i = 0; i < EdEventInfo.npc_count; i++) {
5941 CNPCharacter *npc = GetNPC(i);
5942
5943 if (npc->villager_id == villager_id) {
5944 npc->recurring_talk_event = event_no;
5945 }
5946 }
5947
5948 return 1;
5949}
5950
5951static CCameraFollow *GetCamera() {
5952 CCameraFollow *camera = EdEventInfo.camera;
5953
5954 if (camera == NULL) {
5955 return NULL;
5956 }
5957
5958 camera->FollowOff();
5959 return camera;
5960}
5961
5962static int _SET_CAMERA(RS_STACKDATA *stack, int argument_count) {
5963 sceVu0FVECTOR position;
5964 sceVu0FVECTOR reference;
5965 CCameraFollow *camera = EdEventInfo.camera;
5966
5967 if (camera == NULL) {
5968 return 0;
5969 }
5970
5971 GetPosition(stack, position);
5972 GetPosition(stack + 3, reference);
5973 float speed = GetStackFloat(stack += 6);
5974 follow_chara = NULL;
5975 camera->FollowOff();
5976 camera->SetNextPos(NULL, position[0], position[1], position[2]);
5977 camera->SetNextRef(NULL, reference[0], reference[1], reference[2]);
5978 camera->SetSpeed(speed);
5979
5980 if (speed <= 1.0f) {
5981 camera->SetPos(position);
5982 camera->SetRef(reference);
5983 camera->Step(-1);
5984 }
5985
5986 return 1;
5987}
5988
5989static int _SET_CAMERA_POS(RS_STACKDATA *stack, int argument_count) {
5990 CCameraFollow *camera = EdEventInfo.camera;
5991
5992 if (camera == NULL) {
5993 return 0;
5994 }
5995
5996 follow_chara = NULL;
5997 camera->FollowOff();
5998 sceVu0FVECTOR position;
5999 GetPosition(stack, position);
6000 camera->SetNextPos(NULL, position[0], position[1], position[2]);
6001 return 1;
6002}
6003
6004static int _GET_CAMERA_POS(RS_STACKDATA *stack, int argument_count) {
6005 if (argument_count < 3) {
6006 return 0;
6007 }
6008
6009 if (EdEventInfo.camera == NULL) {
6010 return 0;
6011 }
6012
6013 sceVu0FVECTOR position;
6014 EdEventInfo.camera->GetPos(position);
6015 SetPosition(stack, position);
6016 return 1;
6017}
6018
6019static int _SET_CAMERA_REF(RS_STACKDATA *stack, int argument_count) {
6020 CCameraFollow *camera = EdEventInfo.camera;
6021
6022 if (camera == NULL) {
6023 return 0;
6024 }
6025
6026 follow_chara = NULL;
6027 camera->FollowOff();
6028 sceVu0FVECTOR position;
6029 GetPosition(stack, position);
6030 camera->SetNextRef(NULL, position[0], position[1], position[2]);
6031 return 1;
6032}
6033
6034static int _GET_CAMERA_REF(RS_STACKDATA *stack, int argument_count) {
6035 if (argument_count < 3) {
6036 return 0;
6037 }
6038
6039 if (EdEventInfo.camera == NULL) {
6040 return 0;
6041 }
6042
6043 sceVu0FVECTOR position;
6044 EdEventInfo.camera->GetRef(position);
6045 SetPosition(stack, position);
6046 return 1;
6047}
6048
6049static int _SET_CAMERA_SPEED(RS_STACKDATA *stack, int argument_count) {
6050 CCameraFollow *camera = EdEventInfo.camera;
6051
6052 if (camera == NULL) {
6053 return 0;
6054 }
6055
6056 camera->SetSpeed((float) GetStackInt(stack));
6057 return 1;
6058}
6059
6060static int _SET_FOLLOW_CAMERA(RS_STACKDATA *stack, int argument_count) {
6061 CCameraFollow *camera = EdEventInfo.camera;
6062
6063 if (camera == NULL) {
6064 return 0;
6065 }
6066
6067 float values[4];
6068 sceVu0FVECTOR position[2];
6069
6070 if (stack->type == RS_INT) {
6071 int index = GetStackInt(stack++);
6072
6073 if (index == -1) {
6074 follow_chara = EdEventInfo.main_character;
6075 } else {
6076 follow_chara = GetNPC(index);
6077 }
6078
6079 if (follow_chara != NULL) {
6080 follow_chara->GetPosition(position[1]);
6081 }
6082 } else {
6083 GetPosition(stack, position[1]);
6084 stack += 3;
6085 follow_chara = NULL;
6086 }
6087
6088 for (int i = 0; i < 4; i++) {
6089 values[i] = GetStackFloat(stack++);
6090 }
6091
6092 sceVu0FVECTOR rotation;
6093 rotation[1] = values[2];
6094 GetWorldRot(rotation, rotation);
6095 camera->FollowOn();
6096 camera->SetFollow(position[1][0], position[1][1], position[1][2]);
6097 camera->SetHeight(values[0]);
6098 camera->SetDistance(values[1]);
6099 camera->SetAngle(rotation[1]);
6100 camera->SetAngleSoon(rotation[1]);
6101 camera->SetSpeed(values[3]);
6102
6103 if (values[3] <= 1.0f) {
6104 camera->Step(-1);
6105 }
6106
6107 camera->FollowOn();
6108 return 1;
6109}
6110
6111static int _ADD_CAMERA_ANGLE(RS_STACKDATA *stack, int argument_count) {
6112 CCameraFollow *camera = EdEventInfo.camera;
6113
6114 if (camera == NULL) {
6115 return 0;
6116 }
6117
6118 camera->AddAngle(GetStackFloat(stack));
6119 camera->FollowOn();
6120 return 1;
6121}
6122
6123static int _ADD_CAMERA_HEIGHT(RS_STACKDATA *stack, int argument_count) {
6124 CCameraFollow *camera = EdEventInfo.camera;
6125
6126 if (camera == NULL) {
6127 return 0;
6128 }
6129
6130 camera->AddHeight(GetStackFloat(stack));
6131 camera->FollowOn();
6132 return 1;
6133}
6134
6135static int _ADD_CAMERA_DIST(RS_STACKDATA *stack, int argument_count) {
6136 CCameraFollow *camera = EdEventInfo.camera;
6137
6138 if (camera == NULL) {
6139 return 0;
6140 }
6141
6142 camera->AddDistance(GetStackFloat(stack));
6143 camera->FollowOn();
6144 return 1;
6145}
6146
6147static int _CAMERA_STEP(RS_STACKDATA *stack, int argument_count) {
6148 CCameraFollow *camera = EdEventInfo.camera;
6149
6150 if (camera == NULL) {
6151 return 1;
6152 }
6153
6154 if (follow_chara != NULL) {
6155 sceVu0FVECTOR position;
6156 follow_chara->GetPosition(position);
6157 camera->SetFollow(position[0], position[1] + 0.8f * follow_chara->body_height, position[2]);
6158 }
6159
6160 return 1;
6161}
6162
6163static int _SET_PROJECTION(RS_STACKDATA *stack, int argument_count) {
6164 EdEventInfo.projection = GetStackFloat(stack);
6165 return 1;
6166}
6167
6168static int _ITEM_GET_CAMERA(RS_STACKDATA *stack, int argument_count) {
6169 CCameraFollow *camera = EdEventInfo.camera;
6170
6171 if (camera == NULL) {
6172 return 0;
6173 }
6174
6175 float distance = GetStackFloat(stack);
6176
6177 if (distance < 0.0f) {
6178 return 1;
6179 }
6180
6181 if (distance < 10.0f) {
6182 distance = 10.0f;
6183 }
6184
6185 camera->FollowOff();
6186 CCharacter *character = GetChara(-1);
6187 sceVu0FVECTOR character_position;
6188 sceVu0FVECTOR character_rotation;
6189 character->GetPosition(character_position);
6190 character_position[3] = 1.0f;
6191 character->GetRotation(character_rotation);
6192 sceVu0FMATRIX rotation;
6193 sceVu0UnitMatrix(rotation);
6194 sceVu0RotMatrixY(rotation, rotation, character_rotation[1]);
6195 sceVu0CopyVector(rotation[3], character_position);
6196 sceVu0FVECTOR camera_position = {0.0f, 16.0f, distance, 1.0f};
6197 sceVu0FVECTOR camera_reference = {0.0f, 15.0f, 0.0f, 1.0f};
6198 sceVu0ApplyMatrix(camera_position, rotation, camera_position);
6199 sceVu0ApplyMatrix(camera_reference, rotation, camera_reference);
6200 camera->SetPos(camera_position);
6201 camera->SetNextPos(NULL, camera_position[0], camera_position[1], camera_position[2]);
6202 camera->SetRef(camera_reference);
6203 camera->SetNextRef(NULL, camera_reference[0], camera_reference[1], camera_reference[2]);
6204 return 1;
6205}
6206
6207static int _SET_CAMERA_ANGLE(RS_STACKDATA *stack, int argument_count) {
6208 CCamera *camera = GetCamera();
6209
6210 if (camera == NULL) {
6211 return 0;
6212 }
6213
6214 float yaw = AngleLimit(GetStackFloat(stack++));
6215 yaw = GetLocalRotY(yaw);
6216 sceVu0FVECTOR position;
6217 sceVu0FVECTOR reference;
6218 sceVu0FVECTOR direction;
6219 camera->GetPos(position);
6220 camera->GetRef(reference);
6221 sceVu0SubVector(direction, reference, position);
6222
6223 if (argument_count == 1) {
6224 direction[1] = 0.0f;
6225 }
6226
6227 float distance = DistVector(direction);
6228 float pitch = 0.0f;
6229
6230 if (argument_count == 2) {
6231 pitch = AngleLimit(GetStackFloat(stack));
6232 }
6233
6234 sceVu0FVECTOR offset = {0.0f, 0.0f, distance, 0.0f};
6235 sceVu0FMATRIX matrix;
6236 sceVu0FMATRIX rotation;
6237 sceVu0UnitMatrix(matrix);
6238 sceVu0RotMatrixX(rotation, matrix, pitch);
6239 sceVu0RotMatrixY(rotation, rotation, yaw);
6240 sceVu0ApplyMatrix(offset, rotation, offset);
6241 sceVu0AddVector(offset, offset, position);
6242 reference[0] = offset[0];
6243 reference[2] = offset[2];
6244
6245 if (argument_count == 2) {
6246 reference[1] = offset[1];
6247 }
6248
6249 camera->SetRef(reference);
6250 return 1;
6251}
6252
6253static int _GET_CAMERA_ANGLE(RS_STACKDATA *stack, int argument_count) {
6254 CCamera *camera = GetCamera();
6255
6256 if (camera == NULL) {
6257 return 0;
6258 }
6259
6260 sceVu0FVECTOR position;
6261 sceVu0FVECTOR reference;
6262 sceVu0FVECTOR direction;
6263 sceVu0FVECTOR horizontal;
6264 camera->GetPos(position);
6265 camera->GetRef(reference);
6266 sceVu0SubVector(direction, reference, position);
6267 horizontal[0] = direction[0];
6268 horizontal[1] = 0.0f;
6269 horizontal[2] = direction[2];
6270 horizontal[3] = 0.0f;
6271 float distance = DistVector(horizontal);
6272 sceVu0Normalize(horizontal, horizontal);
6273 float yaw = atan2f(horizontal[0], horizontal[2]);
6274 float pitch = -atan2f(direction[1], distance);
6275
6276 if (argument_count > 0) {
6277 SetStack(stack++, GetLocalRotY(yaw));
6278 }
6279
6280 if (argument_count >= 2) {
6281 SetStack(stack, pitch);
6282 }
6283
6284 return 1;
6285}
6286
6287static int _SET_CAMERA_ROTATE(RS_STACKDATA *stack, int argument_count) {
6288 CCamera *camera = GetCamera();
6289
6290 if (camera == NULL) {
6291 return 0;
6292 }
6293
6294 float yaw = AngleLimit(GetStackFloat(stack));
6295 yaw = GetWorldRotY(yaw);
6296 sceVu0FVECTOR position;
6297 sceVu0FVECTOR reference;
6298 sceVu0FVECTOR direction;
6299 camera->GetPos(position);
6300 camera->GetRef(reference);
6301 sceVu0SubVector(direction, reference, position);
6302 direction[1] = 0.0f;
6303 float distance = DistVector(direction);
6304 sceVu0FVECTOR offset = {0.0f, 0.0f, distance, 0.0f};
6305 sceVu0FMATRIX matrix;
6306 sceVu0FMATRIX rotation;
6307 sceVu0UnitMatrix(matrix);
6308 sceVu0RotMatrixY(rotation, matrix, yaw);
6309 sceVu0ApplyMatrix(offset, rotation, offset);
6310 sceVu0AddVector(offset, offset, reference);
6311 position[0] = offset[0];
6312 position[2] = offset[2];
6313 camera->SetPos(position);
6314 return 1;
6315}
6316
6317static int _GET_CAMERA_ROTATE(RS_STACKDATA *stack, int argument_count) {
6318 sceVu0FVECTOR position;
6319 sceVu0FVECTOR reference;
6320 sceVu0FVECTOR direction;
6321 CCameraFollow *camera = GetCamera();
6322
6323 if (camera == NULL) {
6324 return 0;
6325 }
6326
6327 camera->GetPos(position);
6328 camera->GetRef(reference);
6329 sceVu0SubVector(direction, position, reference);
6330 SetStack(stack, GetLocalRotY(atan2f(direction[0], direction[2])));
6331 return 1;
6332}
6333
6341static int _RESET_CAMERA(RS_STACKDATA *stack, int argument_count) {
6342 EdEventInfo.reset_camera_angle = GetStackInt(stack);
6343 EdEventInfo.reset_camera_yaw = PI_SHORT;
6344 return 1;
6345}
6346
6347static int _RESET_CAMERA_ANGLE(RS_STACKDATA *stack, int argument_count) {
6348 EdEventInfo.reset_camera_angle = 1;
6349 EdEventInfo.reset_camera_yaw = AngleLimit(GetStackFloat(stack));
6350 return 1;
6351}
6352
6353static int _SYNC_CAMERA_REF_CHARA(RS_STACKDATA *stack, int argument_count) {
6354 sync_camera_ref_chara = GetChara(GetStackInt(stack++));
6355
6356 if (argument_count == 4) {
6357 sync_camera_ref_offset[0] = GetStackFloat(stack++);
6358 sync_camera_ref_offset[1] = GetStackFloat(stack++);
6359 sync_camera_ref_offset[2] = GetStackFloat(stack);
6360 } else {
6361 sync_camera_ref_offset[0] = 0.0f;
6362 sync_camera_ref_offset[1] = 0.0f;
6363 sync_camera_ref_offset[2] = 0.0f;
6364 }
6365
6366 return 1;
6367}
6368
6369static int _RELEASE_CAMERA_REF_CHARA(RS_STACKDATA *stack, int argument_count) {
6370 sync_camera_ref_chara = NULL;
6371 return 1;
6372}
6373
6374static int _SYNC_CAMERA_REF_OBJ(RS_STACKDATA *stack, int argument_count) {
6375 sync_camera_ref_obj = GetObjHandle(GetStackInt(stack++));
6376
6377 if (argument_count == 4) {
6378 sync_camera_ref_offset[0] = GetStackFloat(stack++);
6379 sync_camera_ref_offset[1] = GetStackFloat(stack++);
6380 sync_camera_ref_offset[2] = GetStackFloat(stack);
6381 } else {
6382 sync_camera_ref_offset[0] = 0.0f;
6383 sync_camera_ref_offset[1] = 0.0f;
6384 sync_camera_ref_offset[2] = 0.0f;
6385 }
6386
6387 return 1;
6388}
6389
6390static int _RELEASE_CAMERA_REF_OBJ(RS_STACKDATA *stack, int argument_count) {
6391 sync_camera_ref_obj = NULL;
6392 return 1;
6393}
6394
6395static int _SYNC_CAMERA_POS_OBJ(RS_STACKDATA *stack, int argument_count) {
6396 sync_camera_pos_obj = GetObjHandle(GetStackInt(stack));
6397 return 1;
6398}
6399
6400static int _RELEASE_CAMERA_POS_OBJ(RS_STACKDATA *stack, int argument_count) {
6401 sync_camera_pos_obj = NULL;
6402 return 1;
6403}
6404
6405static int _SET_CAMERA_ROLL(RS_STACKDATA *stack, int argument_count) {
6406 CCameraFollow *camera = GetCamera();
6407
6408 if (camera == NULL) {
6409 return 0;
6410 }
6411
6412 camera->SetRoll(GetStackFloat(stack));
6413 return 1;
6414}
6415
6416static int _GET_CAMERA_ROLL(RS_STACKDATA *stack, int argument_count) {
6417 CCameraFollow *camera = GetCamera();
6418
6419 if (camera == NULL) {
6420 return 0;
6421 }
6422
6423 SetStack(stack, camera->GetRoll());
6424 return 1;
6425}
6426
6427static int _FADE_IN(RS_STACKDATA *stack, int argument_count) {
6428 int red;
6429 int frames = (0, GetStackInt(stack++));
6430 int blue = 0;
6431 int green = 0;
6432 red = 0;
6433
6434 if (argument_count == 4) {
6435 red = GetStackInt(stack++);
6436 green = GetStackInt(stack++);
6437 blue = GetStackInt(stack);
6438 }
6439
6440 EdFadeIn(frames, (float) red, (float) green, (float) blue);
6441 return 1;
6442}
6443
6444static int _FADE_OUT(RS_STACKDATA *stack, int argument_count) {
6445 int red;
6446 int frames = (0, GetStackInt(stack++));
6447 int blue = 0;
6448 int green = 0;
6449 red = 0;
6450
6451 if (argument_count == 4) {
6452 red = GetStackInt(stack++);
6453 green = GetStackInt(stack++);
6454 blue = GetStackInt(stack);
6455 }
6456
6457 EdFadeOut(frames, (float) red, (float) green, (float) blue);
6458 return 1;
6459}
6460
6461static int _CHECK_FADE(RS_STACKDATA *stack, int argument_count) {
6462 if (argument_count <= 0) {
6463 return 0;
6464 }
6465
6466 SetStack(stack, EdFadeOutCheck());
6467 return 1;
6468}
6469
6470static int _INIT_SPRITE(RS_STACKDATA *stack, int argument_count) {
6471 SpriteTable.ClearPointer();
6472 SpriteTableBack.ClearPointer();
6473 return 1;
6474}
6475
6476static int _DRAW_SPRITE(RS_STACKDATA *stack, int argument_count) {
6477 RECT source;
6478 int x = GetStackInt(stack++);
6479 int y = GetStackInt(stack++);
6480 char *name = GetStackString(stack++);
6481 source.x = GetStackInt(stack++);
6482 source.y = GetStackInt(stack++);
6483 source.width = GetStackInt(stack++);
6484 source.height = GetStackInt(stack);
6485 CTexture *texture = TexManager.GetTexture(name, -1);
6486
6487 if (texture == NULL) {
6488 return 0;
6489 }
6490
6491 SpriteTable.AddTable(x, y, (sceGsTex0 *) &texture->tex0, &source, 0, 0);
6492 return 1;
6493}
6494
6495static int _DRAW_BG_SPRITE(RS_STACKDATA *stack, int argument_count) {
6496 RECT source;
6497 int x = GetStackInt(stack++);
6498 int y = GetStackInt(stack++);
6499 char *name = GetStackString(stack++);
6500 source.x = GetStackInt(stack++);
6501 source.y = GetStackInt(stack++);
6502 source.width = GetStackInt(stack++);
6503 source.height = GetStackInt(stack);
6504 CTexture *texture = TexManager.GetTexture(name, -1);
6505
6506 if (texture == NULL) {
6507 return 0;
6508 }
6509
6510 SpriteTableBack.AddTable(x, y, (sceGsTex0 *) &texture->tex0, &source, 0, 0);
6511 return 1;
6512}
6513
6514static int _DRAW_BACK(RS_STACKDATA *stack, int argument_count) {
6515 EdEventInfo.suppress_background = ((GetStackInt(stack++) != 0) ^ 1) & 0xFF;
6516 float red = -1.0f;
6517
6518 if (argument_count > 1) {
6519 red = GetStackFloat(stack++);
6520 }
6521
6522 float blue = red;
6523 float green = red;
6524
6525 if (argument_count == 4) {
6526 green = GetStackFloat(stack++);
6527 blue = GetStackFloat(stack);
6528 }
6529
6530 EdEventInfo.background_color[0] = red;
6531 EdEventInfo.background_color[1] = green;
6532 EdEventInfo.background_color[2] = blue;
6533 return 1;
6534}
6535
6536static int _DRAW_SHADOW(RS_STACKDATA *stack, int argument_count) {
6537 EdEventInfo.suppress_shadows = ((GetStackInt(stack) != 0) ^ 1) & 0xFF;
6538 return 1;
6539}
6540
6548static int _SET_CLIP_POINT(RS_STACKDATA *stack, int argument_count) {
6549 sceVu0FVECTOR plane;
6550 GetPosition(stack, plane);
6551 stack += 3;
6552
6553 if (EdEventInfo.edit_ground != NULL) {
6554 float distance = GetStackFloat(stack++);
6555 CEditGround *ground = EdEventInfo.edit_ground;
6556 sceVu0CopyVector(ground->clip_plane, plane);
6557 ground->clip_plane[3] = distance;
6558 }
6559
6560 return 1;
6561}
6562
6563static int _DRAW_EDIT_WATER(RS_STACKDATA *stack, int argument_count) {
6564 if (EdEventInfo.edit_ground != NULL) {
6565 EdEventInfo.edit_ground->suppress_water = ((GetStackInt(stack) != 0) ^ 1) & 0xFF;
6566 }
6567
6568 return 1;
6569}
6570
6571static int _DRAW_WATER_SURFACE(RS_STACKDATA *stack, int argument_count) {
6572 int draw = GetStackInt(stack++);
6573
6574 for (int i = 0; i < argument_count - 1; i++) {
6575 if (EdEventInfo.edit_ground != NULL) {
6576 int index = GetStackInt(stack++);
6577
6578 if (index >= 0 && index < 4) {
6579 EdEventInfo.edit_ground->water_surfaces[index].draw = draw;
6580 }
6581 }
6582 }
6583
6584 return 1;
6585}
6586
6587static int _SCREEN_FILTER(RS_STACKDATA *stack, int argument_count) {
6588 int red = GetStackInt(stack++);
6589
6590 if (red < 0) {
6591 EdEventInfo.screen_filter = false;
6592 return 1;
6593 }
6594
6595 int green = GetStackInt(stack++);
6596 int blue = GetStackInt(stack++);
6597 int alpha = GetStackInt(stack);
6598
6599 if (alpha < 0) {
6600 EdEventInfo.screen_filter = false;
6601 return 1;
6602 }
6603
6604 EdEventInfo.screen_filter = true;
6605 EdEventInfo.screen_filter_color[0] = red;
6606 EdEventInfo.screen_filter_color[1] = green;
6607 EdEventInfo.screen_filter_color[2] = blue;
6608 EdEventInfo.screen_filter_color[3] = alpha;
6609 return 1;
6610}
6611
6612static int _DRAW_THUNDER(RS_STACKDATA *stack, int argument_count) {
6613 EdThunderEffectFlag = GetStackInt(stack);
6614 return 1;
6615}
6616
6617static int _SET_LIGHT(RS_STACKDATA *stack, int argument_count) {
6618 EdEventInfo.lighting_override = true;
6619 int index = GetStackInt(stack++);
6620
6621 if (index < 0 || index > 3) {
6622 return 0;
6623 }
6624
6625 sceVu0FVECTOR direction;
6626 direction[0] = GetStackFloat(stack++);
6627 direction[1] = GetStackFloat(stack++);
6628 direction[2] = GetStackFloat(stack++);
6629 direction[3] = 0.0f;
6630 sceVu0Normalize(direction, direction);
6631 EdEventInfo.light_direction[0][index] = direction[0];
6632 EdEventInfo.light_direction[1][index] = direction[1];
6633 EdEventInfo.light_direction[2][index] = direction[2];
6634
6635 if (argument_count > 4) {
6636 EdEventInfo.light_color[index][0] = GetStackFloat(stack++);
6637 EdEventInfo.light_color[index][1] = GetStackFloat(stack++);
6638 EdEventInfo.light_color[index][2] = GetStackFloat(stack);
6639 }
6640
6641 return 1;
6642}
6643
6644static int _SET_LIGHT_COLOR(RS_STACKDATA *stack, int argument_count) {
6645 EdEventInfo.lighting_override = true;
6646 int index = GetStackInt(stack++);
6647
6648 if (index < 0 || index > 3) {
6649 return 0;
6650 }
6651
6652 EdEventInfo.light_color[index][0] = GetStackFloat(stack++);
6653 EdEventInfo.light_color[index][1] = GetStackFloat(stack++);
6654 EdEventInfo.light_color[index][2] = GetStackFloat(stack);
6655 return 1;
6656}
6657
6658static int _SET_AMBIENT(RS_STACKDATA *stack, int argument_count) {
6659 EdEventInfo.lighting_override = true;
6660 EdEventInfo.ambient_color[0] = GetStackFloat(stack++);
6661 EdEventInfo.ambient_color[1] = GetStackFloat(stack++);
6662 EdEventInfo.ambient_color[2] = GetStackFloat(stack++);
6663 EdEventInfo.ambient_color[3] = 128.0f;
6664
6665 if (argument_count > 3) {
6666 EdEventInfo.ambient_color[3] = GetStackFloat(stack);
6667 }
6668
6669 return 1;
6670}
6671
6672static int _SAVE_LIGHT(RS_STACKDATA *stack, int argument_count) {
6673 int slot = GetStackInt(stack);
6674
6675 if (slot < 0 || slot > 1) {
6676 return 0;
6677 }
6678
6679 sceVu0CopyMatrix(save_l[slot], EdEventInfo.light_direction);
6680 sceVu0CopyMatrix(save_c[slot], EdEventInfo.light_color);
6681 sceVu0CopyVector(save_a[slot], EdEventInfo.ambient_color);
6682 return 1;
6683}
6684
6685static int _LOAD_LIGHT(RS_STACKDATA *stack, int argument_count) {
6686 int slot = GetStackInt(stack);
6687
6688 if (slot < 0) {
6689 MGGetPLight(EdEventInfo.light_direction, EdEventInfo.light_color);
6690 MGGetAmbient(EdEventInfo.ambient_color);
6691 return 1;
6692 }
6693
6694 if (slot > 1) {
6695 return 0;
6696 }
6697
6698 sceVu0CopyMatrix(EdEventInfo.light_direction, save_l[slot]);
6699 sceVu0CopyMatrix(EdEventInfo.light_color, save_c[slot]);
6700 sceVu0CopyVector(EdEventInfo.ambient_color, save_a[slot]);
6701 return 1;
6702}
6703
6704static int _SET_DOF_LEVEL(RS_STACKDATA *stack, int argument_count) {
6705 EdSetDOFLevel(GetStackInt(stack));
6706 return 1;
6707}
6708
6709static int _SP_INIT(RS_STACKDATA *stack, int argument_count) {
6710 int index = GetStackInt(stack);
6711
6712 if (index < 0) {
6713 for (int i = 0;; i++) {
6714 ED_SPRITE *sprite = GetSprite(i);
6715
6716 if (sprite == NULL) {
6717 break;
6718 }
6719
6720 InitSprite(sprite);
6721 }
6722
6723 return 1;
6724 }
6725
6726 ED_SPRITE *sprite = GetSprite(index);
6727
6728 if (sprite == NULL) {
6729 return 0;
6730 }
6731
6732 InitSprite(sprite);
6733 return 1;
6734}
6735
6736static int _SP_SET_TEX(RS_STACKDATA *stack, int argument_count) {
6737 ED_SPRITE *sprite = GetSprite(GetStackInt(stack++));
6738
6739 if (sprite == NULL) {
6740 return 0;
6741 }
6742
6743 sprite->enabled = true;
6744 char *name = GetStackString(stack++);
6745 sprite->source_x = GetStackInt(stack++);
6746 sprite->source_y = GetStackInt(stack++);
6747 sprite->source_width = GetStackInt(stack++);
6748 sprite->source_height = GetStackInt(stack++);
6749
6750 if (argument_count > 6) {
6751 sprite->bilinear = GetStackInt(stack);
6752 }
6753
6754 CTexture *texture = TexManager.GetTexture(name, -1);
6755
6756 if (texture == NULL) {
6757 return 0;
6758 }
6759
6760 sprite->texture = *texture;
6761 return 1;
6762}
6763
6764static int _SP_SET_POS(RS_STACKDATA *stack, int argument_count) {
6765 ED_SPRITE *sprite = GetSprite(GetStackInt(stack++));
6766
6767 if (sprite == NULL) {
6768 return 0;
6769 }
6770
6771 sprite->x = (float) GetStackInt(stack++);
6772 sprite->y = (float) GetStackInt(stack++);
6773 sprite->height = -1;
6774 sprite->width = -1;
6775
6776 if (argument_count > 3) {
6777 sprite->width = GetStackInt(stack++);
6778 }
6779
6780 if (argument_count > 4) {
6781 sprite->height = GetStackInt(stack);
6782 }
6783
6784 return 1;
6785}
6786
6787static int _SP_SET_RGBA(RS_STACKDATA *stack, int argument_count) {
6788 ED_SPRITE *sprite = GetSprite(GetStackInt(stack++));
6789
6790 if (sprite == NULL) {
6791 return 0;
6792 }
6793
6794 sprite->red = GetStackInt(stack++);
6795 sprite->green = GetStackInt(stack++);
6796 sprite->blue = GetStackInt(stack++);
6797 sprite->alpha = 128;
6798
6799 if (argument_count > 4) {
6800 sprite->alpha = GetStackInt(stack);
6801 }
6802
6803 return 1;
6804}
6805
6806static int _SP_SET_ROT(RS_STACKDATA *stack, int argument_count) {
6807 ED_SPRITE *sprite;
6808 RS_STACKDATA *arguments = (0, stack + 1);
6809 sprite = GetSprite(GetStackInt(stack));
6810
6811 if (sprite == NULL) {
6812 return 0;
6813 }
6814
6815 sprite->rotated = true;
6816 sprite->rotation_x = GetStackInt(arguments++);
6817 sprite->rotation_y = GetStackInt(arguments++);
6818 sprite->rotation = GetStackFloat(arguments);
6819 return 1;
6820}
6821
6822static int _SP_SET_MOVE(RS_STACKDATA *stack, int argument_count) {
6823 RS_STACKDATA *arguments = (0, stack + 1);
6824 ED_SPRITE *sprite = GetSprite(GetStackInt(stack));
6825
6826 if (sprite == NULL) {
6827 return 0;
6828 }
6829
6830 sprite->move_x = GetStackFloat(arguments++);
6831 sprite->move_y = GetStackFloat(arguments);
6832 return 1;
6833}
6834
6835static int _SP_DRAW(RS_STACKDATA *stack, int argument_count) {
6836 int layer = GetStackInt(stack++);
6837
6838 for (int i = 0; i < argument_count - 1; i++) {
6839 ED_SPRITE *sprite = GetSprite(GetStackInt(stack++));
6840
6841 if (sprite != NULL) {
6842 sprite->layer = layer;
6843 }
6844 }
6845
6846 return 1;
6847}
6848
6849static int _INIT_DRAW_DAY(RS_STACKDATA *stack, int argument_count) {
6850 EdInitDrawDay();
6851 return 1;
6852}
6853
6854static int _DRAW_DAY(RS_STACKDATA *stack, int argument_count) {
6855 EdStartDrawDay();
6856 return 1;
6857}
6858
6859static int _MAP_TITLE_OFF(RS_STACKDATA *stack, int argument_count) {
6860 now_loading_off();
6861 return 1;
6862}
6863
6864static int _SET_WIND(RS_STACKDATA *stack, int argument_count) {
6865 EdEventInfo.wind[0] = GetStackFloat(stack++);
6866 EdEventInfo.wind[1] = GetStackFloat(stack++);
6867 EdEventInfo.wind[2] = GetStackFloat(stack++);
6868 EdEventInfo.wind[3] = GetStackFloat(stack);
6869 return 1;
6870}
6871
6872static int _ASQ_INIT(RS_STACKDATA *stack, int argument_count) {
6873 int index = GetStackInt(stack);
6874
6875 if (index < 0) {
6876 for (int i = 0; i < 10; i++) {
6877 CActionSeq *sequence = GetActSeq(index);
6878
6879 if (sequence != NULL) {
6880 sequence->ClearSeq();
6881 }
6882 }
6883
6884 return 1;
6885 }
6886
6887 CActionSeq *sequence = GetActSeq(index);
6888
6889 if (sequence == NULL) {
6890 return 0;
6891 }
6892
6893 sequence->ClearSeq();
6894 return 1;
6895}
6896
6897int _ASQ_SYNC_CHARA(RS_STACKDATA *stack, int argument_count) {
6898 int sequence_index = GetStackInt(stack++);
6899 int character_index = GetStackInt(stack);
6900 CActionSeq *sequence = GetActSeq(sequence_index);
6901
6902 if (sequence == NULL) {
6903 return 0;
6904 }
6905
6906 CCharacter *character = GetNPC(character_index);
6907
6908 if (character_index == -1) {
6909 character = EdEventInfo.main_character;
6910 }
6911
6912 if (character == NULL) {
6913 return 0;
6914 }
6915
6916 sequence->SyncChara(character);
6917 return 1;
6918}
6919
6920static int _ASQ_SET_POS(RS_STACKDATA *stack, int argument_count) {
6921 RS_STACKDATA *arguments = (0, stack + 1);
6922 CActionSeq *sequence = GetActSeq(GetStackInt(stack));
6923
6924 if (sequence == NULL) {
6925 return 0;
6926 }
6927
6928 sceVu0FVECTOR position;
6929 GetPosition(arguments, position);
6930 sequence->SetPos(position);
6931 return 1;
6932}
6933
6934static int _ASQ_MOVE(RS_STACKDATA *stack, int argument_count) {
6935 sceVu0FVECTOR position;
6936 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
6937
6938 if (sequence == NULL) {
6939 return 0;
6940 }
6941
6942 if (argument_count == 5) {
6943 GetPosition(stack, position);
6944 stack += 3;
6945 sequence->MoveSeq(position, GetStackInt(stack++));
6946 }
6947
6948 if (argument_count == 2) {
6949 sequence->MoveSeq(GetStackInt(stack));
6950 }
6951
6952 return 1;
6953}
6954
6955int _ASQ_MOVE_STEP(RS_STACKDATA *stack, int argument_count) {
6956 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
6957
6958 if (sequence == NULL) {
6959 return 0;
6960 }
6961
6962 sceVu0FVECTOR position;
6963 GetPosition(stack, position);
6964 sequence->MoveSeq(position, GetStackFloat(stack += 3));
6965 return 1;
6966}
6967
6968int _ASQ_ROT_REF(RS_STACKDATA *stack, int argument_count) {
6969 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
6970
6971 if (sequence == NULL) {
6972 return 0;
6973 }
6974
6975 sceVu0FVECTOR position;
6976 GetPosition(stack, position);
6977 sequence->RotRefSeq(position, GetStackFloat(stack += 3));
6978 return 1;
6979}
6980
6981static int _ASQ_ROT_ANGLE(RS_STACKDATA *stack, int argument_count) {
6982 sceVu0FVECTOR rotation;
6983 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
6984
6985 if (sequence == NULL) {
6986 return 0;
6987 }
6988
6989 rotation[3] = 0.0f;
6990 rotation[2] = 0.0f;
6991 rotation[0] = 0.0f;
6992 rotation[1] = GetStackFloat(stack++);
6993 GetWorldRot(rotation, rotation);
6994 sequence->RotAngleSeq(rotation[1], GetStackFloat(stack));
6995 return 1;
6996}
6997
6998static int _ASQ_CLEAR_ROT(RS_STACKDATA *stack, int argument_count) {
6999 CActionSeq *sequence = GetActSeq(GetStackInt(stack));
7000
7001 if (sequence == NULL) {
7002 return 0;
7003 }
7004
7005 sequence->ClearRotSeq();
7006 return 1;
7007}
7008
7009static int _ASQ_WAIT_ROT(RS_STACKDATA *stack, int argument_count) {
7010 CActionSeq *sequence = GetActSeq(GetStackInt(stack));
7011
7012 if (sequence == NULL) {
7013 return 0;
7014 }
7015
7016 sequence->WaitRotSeq();
7017 return 1;
7018}
7019
7020static int _ASQ_ROT_MOVE(RS_STACKDATA *stack, int argument_count) {
7021 RS_STACKDATA *next = (0, stack + 1);
7022 CActionSeq *sequence = GetActSeq(GetStackInt(stack));
7023
7024 if (sequence == NULL) {
7025 return 0;
7026 }
7027
7028 sequence->RotMoveSeq(GetStackFloat(next));
7029 return 1;
7030}
7031
7032static int _ASQ_SET_ROT(RS_STACKDATA *stack, int argument_count) {
7033 sceVu0FVECTOR rotation;
7034 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7035
7036 if (sequence == NULL) {
7037 return 0;
7038 }
7039
7040 if (argument_count == 4) {
7041 GetRotation(stack, rotation);
7042 stack += 3;
7043 }
7044
7045 if (argument_count == 2) {
7046 rotation[2] = 0.0f;
7047 rotation[0] = 0.0f;
7048 rotation[1] = GetStackFloat(stack);
7049 GetWorldRot(rotation, rotation);
7050 }
7051
7052 sequence->SetRot(rotation);
7053 return 1;
7054}
7055
7056static int _ASQ_DELAY_ROT(RS_STACKDATA *stack, int argument_count) {
7057 RS_STACKDATA *next = (0, stack + 1);
7058 CActionSeq *sequence = GetActSeq(GetStackInt(stack));
7059
7060 if (sequence == NULL) {
7061 return 0;
7062 }
7063
7064 sequence->SetDelayRot(GetStackInt(next));
7065 return 1;
7066}
7067
7068static int _ASQ_MOTION_TRG(RS_STACKDATA *stack, int argument_count) {
7069 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7070
7071 if (sequence == NULL) {
7072 return 0;
7073 }
7074
7075 int trigger = 0;
7076
7077 if (argument_count == 2) {
7078 trigger = GetStackInt(stack);
7079 }
7080
7081 sequence->MotionTrg(trigger);
7082 return 1;
7083}
7084
7085static int asq_motion_play(int mode, RS_STACKDATA *stack, int argument_count) {
7086 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7087
7088 if (sequence == NULL) {
7089 return 0;
7090 }
7091
7092 int motion = GetStackInt(stack++);
7093 float speed = -1.0f;
7094
7095 if (argument_count >= 3) {
7096 speed = GetStackFloat(stack++);
7097 }
7098
7099 int flags = 0;
7100
7101 if (argument_count >= 4) {
7102 flags = (int) GetStackFloat(stack);
7103 }
7104
7105 flags &= 4;
7106 sequence->MotionSeq(motion, mode, speed, flags);
7107 return 1;
7108}
7109
7110static int _ASQ_MOTION_PLAY(RS_STACKDATA *stack, int argument_count) {
7111 asq_motion_play(5, stack, argument_count);
7112 PORT_RETURN(1);
7113}
7114
7115static int _ASQ_MOTION_STOP(RS_STACKDATA *stack, int argument_count) {
7116 asq_motion_play(6, stack, argument_count);
7117 PORT_RETURN(1);
7118}
7119
7120static int _ASQ_MOTION_NEXT(RS_STACKDATA *stack, int argument_count) {
7121 asq_motion_play(7, stack, argument_count);
7122 PORT_RETURN(1);
7123}
7124
7125static int _ASQ_ANIME_TRG(RS_STACKDATA *stack, int argument_count) {
7126 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7127
7128 if (sequence == NULL) {
7129 return 0;
7130 }
7131
7132 int trigger = 0;
7133
7134 if (argument_count == 2) {
7135 trigger = GetStackInt(stack);
7136 }
7137
7138 sequence->AnimeTrg(trigger);
7139 return 1;
7140}
7141
7142static int _ASQ_ANIME(RS_STACKDATA *stack, int argument_count) {
7143 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7144
7145 if (sequence == NULL) {
7146 return 0;
7147 }
7148
7149 int enable = true;
7150 int start = 0;
7151 int end = 0;
7152 int animation = GetStackInt(stack++);
7153
7154 if (argument_count >= 3) {
7155 enable = GetStackInt(stack++);
7156 }
7157
7158 if (argument_count >= 4) {
7159 start = GetStackInt(stack++);
7160 }
7161
7162 if (argument_count >= 5) {
7163 end = GetStackInt(stack);
7164 }
7165
7166 sequence->AnimeSeq(animation, enable, start, end);
7167 return 1;
7168}
7169
7177static int _ASQ_CHECK(RS_STACKDATA *stack, int argument_count) {
7178 CActionSeq *sequence = GetActSeq(GetStackInt(stack++));
7179
7180 if (sequence == NULL) {
7181 return 0;
7182 }
7183
7184 int end = sequence->CheckEnd();
7185 SetStack(stack++, ((end != 0) ^ 1) & 0xFF);
7186 return 1;
7187}
7188
7189static int _OBJ_ANIME_INIT(RS_STACKDATA *stack, int argument_count) {
7190 for (int i = 0; i < argument_count; i++) {
7191 ClearObjAnime(GetStackInt(stack++));
7192 }
7193
7194 return 1;
7195}
7196
7204static int _OBJ_ANIME(RS_STACKDATA *stack, int argument_count) {
7205 int anime_index = GetStackInt(stack++);
7206 int handle_index = GetStackInt(stack++);
7207 int angle_mode = GetStackInt(stack++);
7208 int playback_mode = GetStackInt(stack++);
7209 sceVu0FVECTOR offset = {0.0f, 0.0f, 0.0f, 0.0f};
7210 sceVu0FVECTOR range;
7211 sceVu0FVECTOR speed;
7212 sceVu0CopyVector(range, offset);
7213 sceVu0CopyVector(speed, offset);
7214
7215 offset[0] = GetStackFloat(stack++);
7216 offset[1] = GetStackFloat(stack++);
7217 offset[2] = GetStackFloat(stack++);
7218
7219 if (angle_mode == 0) {
7220 offset[0] = 180.0f * offset[0] / PI_SHORT;
7221 offset[1] = 180.0f * offset[1] / PI_SHORT;
7222 offset[2] = 180.0f * offset[2] / PI_SHORT;
7223 }
7224
7225 if (argument_count >= 10) {
7226 range[0] = GetStackFloat(stack++);
7227 range[1] = GetStackFloat(stack++);
7228 range[2] = GetStackFloat(stack++);
7229
7230 if (angle_mode == 0) {
7231 range[0] = 180.0f * range[0] / PI_SHORT;
7232 range[1] = 180.0f * range[1] / PI_SHORT;
7233 range[2] = 180.0f * range[2] / PI_SHORT;
7234 }
7235 }
7236
7237 if (argument_count >= 13) {
7238 speed[0] = GetStackFloat(stack++);
7239 speed[1] = GetStackFloat(stack++);
7240 speed[2] = GetStackFloat(stack);
7241
7242 if (angle_mode == 0) {
7243 speed[0] = 180.0f * speed[0] / PI_SHORT;
7244 speed[1] = 180.0f * speed[1] / PI_SHORT;
7245 speed[2] = 180.0f * speed[2] / PI_SHORT;
7246 }
7247 }
7248
7249 init_obj_anime(anime_index, handle_index, angle_mode, playback_mode, offset, range, speed);
7250 return 1;
7251}
7252
7253static int _SSET_GAME_FLAG(RS_STACKDATA *stack, int argument_count) {
7254 if (argument_count != 2) {
7255 return 0;
7256 }
7257
7258 RS_STACKDATA *next = (0, stack + 1);
7259 int flag = GetStackInt(stack);
7260 SaveData->SetGameFlag(flag, GetStackInt(next));
7261 return 1;
7262}
7263
7264static int _SGET_GAME_FLAG(RS_STACKDATA *stack, int argument_count) {
7265 if (argument_count != 2) {
7266 return 0;
7267 }
7268
7269 RS_STACKDATA *result = (0, stack + 1);
7270 int flag = GetStackInt(stack);
7271 SetStack(result, SaveData->GetGameFlag(flag));
7272 return 1;
7273}
7274
7275static int _SSET_GAME_INT_FLAG(RS_STACKDATA *stack, int argument_count) {
7276 if (argument_count != 2) {
7277 return 0;
7278 }
7279
7280 RS_STACKDATA *next = (0, stack + 1);
7281 int flag = GetStackInt(stack);
7282 SaveData->SetGameIntFlag(flag, GetStackInt(next));
7283 return 1;
7284}
7285
7286static int _SGET_GAME_INT_FLAG(RS_STACKDATA *stack, int argument_count) {
7287 if (argument_count != 2) {
7288 return 0;
7289 }
7290
7291 RS_STACKDATA *result = (0, stack + 1);
7292 int flag = GetStackInt(stack);
7293 SetStack(result, SaveData->GetGameIntFlag(flag));
7294 return 1;
7295}
7296
7297static int _SITEM_GET(RS_STACKDATA *stack, int argument_count) {
7298 int attachment = -1;
7299 int item = GetStackInt(stack);
7300
7301 if (GetAddAttachItem(item) != 0) {
7302 attachment = 3;
7303 }
7304
7305 EdGetItem(item, 1, attachment);
7306 return 1;
7307}
7308
7309static int _SSET_MAP_FLAG(RS_STACKDATA *stack, int argument_count) {
7310 RS_STACKDATA *next = (0, stack + 1);
7311 int flag = GetStackInt(stack);
7312 EdSetMapFlag(flag, ((GetStackInt(next) != 0) ^ 1) & 0xFF);
7313 return 1;
7314}
7315
7316static int _SGET_MAP_FLAG(RS_STACKDATA *stack, int argument_count) {
7317 RS_STACKDATA *result = (0, stack + 1);
7318 int flag = GetStackInt(stack);
7319 SetStack(result, ((EdGetMapFlag(flag) != 0) ^ 1) & 0xFF);
7320 return 1;
7321}
7322
7323static int _SET_WORK_FLAG(RS_STACKDATA *stack, int argument_count) {
7324 RS_STACKDATA *next = (0, stack + 1);
7325 int flag = GetStackInt(stack);
7326 SetWorkFlag(flag, GetStackInt(next));
7327 PORT_RETURN(1);
7328}
7329
7330static int _GET_WORK_FLAG(RS_STACKDATA *stack, int argument_count) {
7331 RS_STACKDATA *result = (0, stack + 1);
7332 int flag = GetStackInt(stack);
7333 SetStack(result, (0, GetWorkFlag(flag)));
7334 return 1;
7335}
7336
7337static int _SITEM_CHECK(RS_STACKDATA *stack, int argument_count) {
7338 RS_STACKDATA *result = (0, stack + 1);
7339 int item = GetStackInt(stack);
7340 SetStack(result, EdCheckItem(item));
7341 return 1;
7342}
7343
7344static int _SITEM_CHECK_ALL(RS_STACKDATA *stack, int argument_count) {
7345 RS_STACKDATA *result = (0, stack + 1);
7346 int item = GetStackInt(stack);
7347 SetStack(result, PlayerAllItemCheck(item));
7348 return 1;
7349}
7350
7351static int _SGET_DUNGEON_STATUS(RS_STACKDATA *stack, int argument_count) {
7352 CDngStatusData *status = SaveData->GetDngStatus();
7353 int dungeon = GetStackInt(stack++);
7354
7355 if (dungeon < 0 || dungeon >= 6) {
7356 return 0;
7357 }
7358
7359 SetStack(stack++, SaveData->QuestDungeon(dungeon, 0));
7360 SetStack(stack, status->floor_reached[dungeon]);
7361 return 1;
7362}
7363
7367static int _SGET_PARTY_NUM(RS_STACKDATA *stack, int argument_count) {
7368 CDngStatusData *status = SaveData->GetDngStatus();
7369 SetStack(stack++, status->party_size);
7370 return 1;
7371}
7372
7373static int _SSET_PARTY_NUM(RS_STACKDATA *stack, int argument_count) {
7374 CDngStatusData *status = SaveData->GetDngStatus();
7375 int party_size = GetStackInt(stack);
7376 status->SetPartySize(party_size);
7377 return 1;
7378}
7379
7380static int _SSET_REQUEST_EVENT_FLAG(RS_STACKDATA *stack, int argument_count) {
7381 RS_STACKDATA *next = (0, stack + 1);
7382 SV_GEORAMA_DATA *georama = SaveData->GetGrdData(GetStackInt(stack) - 1);
7383
7384 if (georama == NULL) {
7385 return 0;
7386 }
7387
7388 georama->request_event_flag = GetStackInt(next);
7389 return 1;
7390}
7391
7399static int _SADD_VISIT_MAP(RS_STACKDATA *stack, int argument_count) {
7400 int map = GetStackInt(stack++) - 1;
7401 int add = 1;
7402
7403 if (argument_count > 1) {
7404 add = GetStackInt(stack++);
7405 }
7406
7407 int visits = map < 200 ? SaveData->VisitMap(map, add) : SaveData->QuestDungeon(map, add);
7408
7409 if (argument_count > 2) {
7410 SetStack(stack, visits);
7411 }
7412
7413 return 1;
7414}
7415
7416static int _SSKILL_GET(RS_STACKDATA *stack, int argument_count) {
7417 CDngStatusData *status = SaveData->GetDngStatus();
7418 int character = GetStackInt(stack);
7419
7420 if (character < 0 || character >= 6) {
7421 return 0;
7422 }
7423
7424 status->skill_owned[character] = 1;
7425 return 1;
7426}
7427
7428static int _SGET_EQUIP_WEAPON(RS_STACKDATA *stack, int argument_count) {
7429 CDngStatusData *status = SaveData->GetDngStatus();
7430 int character = GetStackInt(stack++);
7431
7432 if (character < 0 || character >= 6) {
7433 return 0;
7434 }
7435
7436 SetStack(stack, TransWepNoNewToOld(status->chara_weapons[character][status->equipped_weapon_slot[character]].item_no));
7437 return 1;
7438}
7439
7440static int _SADD_MAXITEM(RS_STACKDATA *stack, int argument_count) {
7441 EdAddMaxItem(GetStackInt(stack));
7442 return 1;
7443}
7444
7445static int _SITEM_LOST(RS_STACKDATA *stack, int argument_count) {
7446 CDngStatusData *status = SaveData->GetDngStatus();
7447 status->LostItem(GetStackInt(stack));
7448 return 1;
7449}
7450
7451static int _SATRA_PARTS_GET(RS_STACKDATA *stack, int argument_count) {
7452 RS_STACKDATA *next = (0, stack + 1);
7453 int georama = GetStackInt(stack) - 1;
7454 SaveData->AtraPartsGet(georama, GetStackInt(next));
7455 PORT_RETURN(1);
7456}
7457
7458static int _SATRA_CHIP_GET(RS_STACKDATA *stack, int argument_count) {
7459 RS_STACKDATA *next = (0, stack + 1);
7460 int georama = GetStackInt(stack) - 1;
7461 SaveData->AtraChipGet(georama, GetStackInt(next));
7462 PORT_RETURN(1);
7463}
7464
7465int _SGET_REQUEST(RS_STACKDATA *stack, int argument_count) {
7466 RS_STACKDATA *result = (0, stack + 1);
7467 SV_GEORAMA_DATA *georama = SaveData->GetGrdData(GetStackInt(stack) - 1);
7468
7469 if (georama == NULL) {
7470 SetStack(result, 0);
7471 return 0;
7472 }
7473
7474 int i;
7475 int completed = 0;
7476 i = 0;
7477
7478 while (i < 24) {
7479 if (georama->request_complete[i] != 0) {
7480 completed++;
7481 }
7482
7483 i++;
7484 }
7485
7486 int total = georama->request_count;
7487
7488 if (completed == total) {
7489 SetStack(result, 100);
7490 } else {
7491 SetStack(result++, completed * 100 / total);
7492 }
7493
7494 return 1;
7495}
7496
7497static int _SGET_ATRA_PARTS_NUM(RS_STACKDATA *stack, int argument_count) {
7498 int count = 0;
7499 RS_STACKDATA *result = (0, stack + 1);
7500 int georama = GetStackInt(stack) - 1;
7501
7502 for (int i = 0; i < 24; i++) {
7503 SV_EDIT_PARTS_INFO *part = SaveData->GetEditPartsInfo(georama, i);
7504
7505 if (part != NULL && part->obtained != 0) {
7506 count++;
7507 }
7508 }
7509
7510 SetStack(result, count);
7511 return 1;
7512}
7513
7514static int _SGET_DAY(RS_STACKDATA *stack, int argument_count) {
7515 SetStack(stack, SaveData->GetDay());
7516 return 1;
7517}
7518
7519static int _SSET_TIME(RS_STACKDATA *stack, int argument_count) {
7520 SaveData->SetNowTime(GetStackFloat(stack));
7521 return 1;
7522}
7523
7524static int _SGET_TIME(RS_STACKDATA *stack, int argument_count) {
7525 SetStack(stack, SaveData->GetNowTime());
7526 return 1;
7527}
7528
7529static int _SADD_TIME(RS_STACKDATA *stack, int argument_count) {
7530 SaveData->AddNowTime(GetStackFloat(stack));
7531 return 1;
7532}
7533
7534static int _SEQUIP_DEFAULT_WEAPON(RS_STACKDATA *stack, int argument_count) {
7535 EquipDefaultWeapon(GetStackInt(stack));
7536 return 1;
7537}
7538
7539static int _LOAD_SND_SYNC(RS_STACKDATA *stack, int argument_count) {
7540 SetStack(stack, SndSyncBG());
7541 return 1;
7542}
7543
7544static int _LOAD_SOUND_SET(RS_STACKDATA *stack, int argument_count) {
7545 StartReadBG();
7546 SndSoundLoadBG(GetStackInt(stack), read_buffer, NULL);
7547 PORT_RETURN(1);
7548}
7549
7550static int _LOAD_VOICE_SET(RS_STACKDATA *stack, int argument_count) {
7551 StartReadBG();
7552 SndVoiceLoadBG(GetStackInt(stack), read_buffer, NULL);
7553 PORT_RETURN(1);
7554}
7555
7556static int _LOAD_BGM(RS_STACKDATA *stack, int argument_count) {
7557 StartReadBG();
7558 SndBgmLoadBG(GetStackInt(stack), read_buffer, NULL);
7559 PORT_RETURN(1);
7560}
7561
7562static int _DELETE_BGM(RS_STACKDATA *stack, int argument_count) {
7563 SndBgmStop();
7564 SndBgmInit();
7565 return 1;
7566}
7567
7568static int _PLAY_BGM(RS_STACKDATA *stack, int argument_count) {
7569 SndBgmPlay(GetStackInt(stack));
7570 return 1;
7571}
7572
7573static int _STOP_BGM(RS_STACKDATA *stack, int argument_count) {
7574 SndBgmStop();
7575 return 1;
7576}
7577
7578static int _SET_BGM_VOL(RS_STACKDATA *stack, int argument_count) {
7579 SndSetBgmVol(GetStackInt(stack));
7580 return 1;
7581}
7582
7583static int _SET_BGM_VOLF(RS_STACKDATA *stack, int argument_count) {
7584 SndSetBgmVolf(GetStackFloat(stack));
7585 return 1;
7586}
7587
7588static int _GET_BGM_VOL(RS_STACKDATA *stack, int argument_count) {
7589 SetStack(stack, SndGetBgmVol());
7590 return 1;
7591}
7592
7593static int _GET_BGM_NO(RS_STACKDATA *stack, int argument_count) {
7594 SetStack(stack, SndGetBgmNo());
7595 return 1;
7596}
7597
7598static int _SET_OUT_BGM_NO(RS_STACKDATA *stack, int argument_count) {
7599 EdBeforeInBgmNo = GetStackInt(stack);
7600 return 1;
7601}
7602
7603static int _GET_OUT_BGM_NO(RS_STACKDATA *stack, int argument_count) {
7604 SetStack(stack, EdBeforeInBgmNo);
7605 return 1;
7606}
7607
7608static int _BGM_FADE_IN(RS_STACKDATA *stack, int argument_count) {
7609 int bgm = GetStackInt(stack++);
7610 int frames = -1;
7611 int mode = 0;
7612
7613 if (argument_count > 1) {
7614 frames = GetStackInt(stack++);
7615 }
7616
7617 if (argument_count > 2) {
7618 mode = GetStackInt(stack);
7619 }
7620
7621 SndBgmFadeIn(bgm, frames, mode);
7622 return 1;
7623}
7624
7625static int _BGM_FADE_OUT(RS_STACKDATA *stack, int argument_count) {
7626 int bgm = GetStackInt(stack++);
7627 int frames = 0;
7628
7629 if (argument_count > 1) {
7630 frames = GetStackInt(stack);
7631 }
7632
7633 SndBgmFadeOut(bgm, frames);
7634 return 1;
7635}
7636
7637static int _CHECK_BGM_FADE(RS_STACKDATA *stack, int argument_count) {
7638 SetStack(stack, SndCheckFade());
7639 return 1;
7640}
7641
7642static int _PLAY_AMB_BGM(RS_STACKDATA *stack, int argument_count) {
7643 SndAmbientPlay(GetStackInt(stack));
7644 return 1;
7645}
7646
7647static int _STOP_AMB_BGM(RS_STACKDATA *stack, int argument_count) {
7648 SndAmbientStop();
7649 return 1;
7650}
7651
7652static int _SET_AMB_VOLF(RS_STACKDATA *stack, int argument_count) {
7653 SndAmbientSetVolf(GetStackFloat(stack));
7654 return 1;
7655}
7656
7657static int _PLAY_SE(RS_STACKDATA *stack, int argument_count) {
7658 int sound = GetStackInt(stack++);
7659
7660 if (argument_count >= 4) {
7661 float position[4];
7662 GetPosition(stack, position);
7663 stack += 3;
7664 float near = -1.0f;
7665 float far = -1.0f;
7666
7667 if (argument_count >= 5) {
7668 near = GetStackFloat(stack++);
7669 }
7670
7671 if (argument_count >= 6) {
7672 far = GetStackFloat(stack);
7673 }
7674
7675 SndSePlay(sound, position, near, far);
7676 } else {
7677 int voice = -1;
7678
7679 if (argument_count == 2) {
7680 voice = GetStackInt(stack);
7681 }
7682
7683 SndSePlay(sound, voice, 0);
7684 }
7685
7686 return 1;
7687}
7688
7689static int _STOP_SE(RS_STACKDATA *stack, int argument_count) {
7690 SndSeStop(GetStackInt(stack), 0);
7691 return 1;
7692}
7693
7694static int _SET_SE_VOL(RS_STACKDATA *stack, int argument_count) {
7695 RS_STACKDATA *next = (0, stack + 1);
7696 int sound = GetStackInt(stack);
7697 SndSetSeVol(sound, GetStackInt(next), 0);
7698 return 1;
7699}
7700
7701static int _LOAD_SPECIAL_SE(RS_STACKDATA *stack, int argument_count) {
7702 StartReadBG();
7703 SndSPSeLoadBG(GetStackInt(stack), read_buffer, NULL);
7704 return 1;
7705}
7706
7707static int _PLAY_SPECIAL_SE(RS_STACKDATA *stack, int argument_count) {
7708 int sound = GetStackInt(stack++);
7709 int voice = -1;
7710
7711 if (argument_count >= 2) {
7712 voice = GetStackInt(stack);
7713 }
7714
7715 SndSPSePlay(sound, voice);
7716 return 1;
7717}
7718
7719static int _STOP_SPECIAL_SE(RS_STACKDATA *stack, int argument_count) {
7720 SndSPSeStop(GetStackInt(stack));
7721 return 1;
7722}
7723
7724static int _SET_SPECIAL_SE_VOL(RS_STACKDATA *stack, int argument_count) {
7725 int sound = GetStackInt(stack++);
7726 float position[4];
7727 GetPosition(stack, position);
7728 stack += 3;
7729 float near = 10.0f;
7730 float far = 500.0f;
7731
7732 if (argument_count >= 5) {
7733 near = GetStackFloat(stack++);
7734 }
7735
7736 if (argument_count >= 6) {
7737 far = GetStackFloat(stack);
7738 }
7739
7740 float volume;
7741 float pan;
7742 SndGetVolPan(&volume, &pan, position, near, far);
7743 SndSetSPSeVolf(sound, volume);
7744 SndSetSPSePanf(sound, pan);
7745 return 1;
7746}
7747
7748static int _SOUND_OFF_COUNT(RS_STACKDATA *stack, int argument_count) {
7749 EdEventInfo.sound_off_count = GetStackInt(stack);
7750
7751 if (EdEventInfo.sound_off_count > 10) {
7752 EdEventInfo.sound_off_count = 10;
7753 }
7754
7755 EdSetSoundOffCount(EdEventInfo.sound_off_count);
7756 return 1;
7757}
7758
7759static int _GET_V_ARG(RS_STACKDATA *stack, int argument_count) {
7760 int index = GetStackInt(stack++);
7761
7762 if (index < 0 || index >= 4) {
7763 return 0;
7764 }
7765
7766 for (int i = 0; i < argument_count - 1; i++) {
7767 SetStack(stack++, EdEventInfo.vector_arguments[index][i]);
7768 }
7769
7770 return 1;
7771}
7772
7773static int _GET_I_ARG(RS_STACKDATA *stack, int argument_count) {
7774 int index = GetStackInt(stack++);
7775
7776 if (index < 0 || index >= 8) {
7777 return 0;
7778 }
7779
7780 SetStack(stack++, EdEventInfo.integer_arguments[index]);
7781 return 1;
7782}
7783
7784static int _GET_F_ARG(RS_STACKDATA *stack, int argument_count) {
7785 int index = GetStackInt(stack++);
7786
7787 if (index < 0 || index >= 8) {
7788 return 0;
7789 }
7790
7791 SetStack(stack++, EdEventInfo.flag_arguments[index]);
7792 return 1;
7793}
7794
7795static int _EB_INIT(RS_STACKDATA *stack, int argument_count) {
7796 EBInit(GetStackFloat(stack));
7797 return 1;
7798}
7799
7800static int _EB_SET_MOTION(RS_STACKDATA *stack, int argument_count) {
7801 int motions[128];
7802
7803 if (argument_count < 2) {
7804 return 0;
7805 }
7806
7807 CCharacter *character = GetChara(GetStackInt(stack++));
7808 int i = 0;
7809
7810 while (i < argument_count - 1) {
7811 motions[i++] = GetStackInt(stack++);
7812 }
7813
7814 motions[i] = -1;
7815 EBSetMotion(character, motions);
7816 return 1;
7817}
7818
7819static int _EB_SET_KEY(RS_STACKDATA *stack, int argument_count) {
7820 float time = GetStackFloat(stack++);
7821 int key = GetStackInt(stack++);
7822 int mode = 0;
7823
7824 if (argument_count >= 3) {
7825 mode = GetStackInt(stack);
7826 }
7827
7828 EBSetKey(time, key, mode);
7829 return 1;
7830}
7831
7832static int _EB_LOOP(RS_STACKDATA *stack, int argument_count) {
7833 SetStack(stack, EBLoop());
7834 return 1;
7835}
7836
7837static int _EB_INTRO_START(RS_STACKDATA *stack, int argument_count) {
7838#ifdef PAL
7839 EBInitialize();
7840#endif
7841 EBInitIntro();
7842 return 1;
7843}
7844
7845static int _EB_INTRO_LOOP(RS_STACKDATA *stack, int argument_count) {
7846 SetStack(stack, EBIntroLoop());
7847 return 1;
7848}
7849
7850static int _EB_INTRO_END(RS_STACKDATA *stack, int argument_count) {
7851 EBExit();
7852 return 1;
7853}
7854
7855static int _EB_DEBUG(RS_STACKDATA *stack, int argument_count) {
7856 EBDebug(GetStackInt(stack));
7857 return 1;
7858}
7859
7860static int _EB_FINISH_SOUND(RS_STACKDATA *stack, int argument_count) {
7861 RS_STACKDATA *next = (0, stack + 1);
7862 int fade_bgm = GetStackInt(stack);
7863 EBFinishSound(fade_bgm, GetStackInt(next));
7864 return 1;
7865}
7866
7867static int _LOAD_MAIN_CHARA(RS_STACKDATA *stack, int argument_count) {
7868 char *model = GetStackString(stack++);
7869 char *motion = GetStackString(stack++);
7870 int use_villager_arena = GetStackInt(stack);
7871 CDataAlloc2<1> *arena = NULL;
7872
7873 if (use_villager_arena == 1) {
7874 arena = &EdVillagerBuffer;
7875 }
7876
7877 EdLoadMainChara(model, motion, arena);
7878 return 1;
7879}
7880
7881static int _LOAD_FISHING_DATA(RS_STACKDATA *stack, int argument_count) {
7882 int fish_set = GetStackInt(stack++);
7883 FishingInit();
7884 FishingLoad(&EdVillagerBuffer, 8);
7885 FishingLoadFish(fish_set, &EdVillagerBuffer, 54);
7886
7887 CBoxVu0 bounds;
7888 bounds.min[0] = GetStackFloat(stack++);
7889 bounds.min[1] = -1000.0f;
7890 bounds.min[2] = GetStackFloat(stack++);
7891 bounds.max[0] = GetStackFloat(stack++);
7892 bounds.max[1] = 1000.0f;
7893 bounds.max[2] = GetStackFloat(stack++);
7894 FishingSetRect(bounds);
7895 float water_near = GetStackFloat(stack++);
7896 FishingSetWaterLevel(water_near, GetStackFloat(stack));
7897
7898 CCPoly polygons[1024];
7899 int polygon_count = 0;
7900
7901 if (EdEventInfo.edit_ground != NULL) {
7902 polygon_count = EdEventInfo.edit_ground->PickUpPoly(polygons, bounds, 0);
7903 printf("poly_num = %d\n", polygon_count);
7904
7905 if (polygon_count > 1024) {
7906 printf("CPOLY OVER *****************\n");
7907
7908 while (1) {
7909 }
7910 }
7911 }
7912
7913 FishingSetCPoly(polygons, polygon_count);
7914 return 1;
7915}
7916
7921static sceVu0FVECTOR fishing_line_origin = {0.0f, 0.0f, 0.0f, 1.0f};
7922
7923static int _GOTO_FISHING(RS_STACKDATA *stack, int argument_count) {
7924 CCharacter *character = GetChara(-1);
7925
7926 if (character == NULL) {
7927 return 0;
7928 }
7929
7930 sceVu0FVECTOR position;
7931 character->GetPosition(position);
7932
7933 if (character->frame != NULL) {
7935 struct FishingOrigin {
7936 sceVu0FVECTOR value;
7937 };
7938
7939 FishingOrigin origin = *(FishingOrigin *) fishing_line_origin;
7940 CFrame *rod = character->frame->SearchFrame("sao");
7941
7942 if (rod != NULL) {
7943 rod->GetWorldPosition(position, origin.value);
7944 }
7945
7946 FishLineInit(position);
7947 }
7948
7950 return 1;
7951}
7952
7953static int _INIT_FISH(RS_STACKDATA *stack, int argument_count) {
7954 CBoxVu0 bounds;
7955 bounds.min[0] = GetStackFloat(stack++);
7956 bounds.min[1] = 0.0f;
7957 bounds.min[2] = GetStackFloat(stack++);
7958 bounds.max[0] = GetStackFloat(stack++);
7959 // Retail redundantly clears the first bound's Y coordinate here.
7960 bounds.min[1] = 0.0f;
7961 bounds.max[2] = GetStackFloat(stack);
7962 FishingInitFish(bounds);
7963 return 1;
7964}
7965
7966static int _EXIT_FISHING(RS_STACKDATA *stack, int argument_count) {
7967 FishingExit();
7968 return 1;
7969}
7970
7971static int _SET_FISHING_ESA(RS_STACKDATA *stack, int argument_count) {
7972 int item = GetStackInt(stack);
7973 FishingLoadEsa(item, EdEventInfo.item_frame[0], 40);
7974 return 1;
7975}
7976
7977#ifdef PAL
7978static int _GET_TV_MODE(RS_STACKDATA *stack, int argument_count) {
7979 // 1 is PAL's 50 Hz, which makes the scripts shorten their frame counts by 5/6.
7980#ifdef PAL_TIMING
7981 SetStack(stack, 1);
7982#else
7983 SetStack(stack, 0);
7984#endif
7985 return 1;
7986}
7987
7988static int _GET_LANG_CODE(RS_STACKDATA *stack, int argument_count) {
7989 SetStack(stack, LanguageCode);
7990 return 1;
7991}
7992#endif
7993
7995static ED_EVENT_EXTERNAL_FUNCTION ext_func_info[] = {
7996 {_GET_PADON, 0 },
7997 {_GET_PADDOWN, 1 },
7998 {_GET_PADUP, 2 },
7999 {_GET_APAD, 903 },
8000 {_SET_RETURN_CODE, 3 },
8001 {_GET_RANDOM, 4 },
8002 {_NEXT_EVENT, 5 },
8003 {_GOTO_INTERIOR, 6 },
8004 {_SET_WORLD_COORD, 7 },
8005 {_INITIALIZE, 8 },
8006 {_EXIT_CODE, 9 },
8007 {_DRAW_EXCLAMATION_MARK, 10 },
8008 {_GOTO_USE_ITEM, 11 },
8009 {_SKIP, 12 },
8010 {_GOTO_OUTSIDE, 13 },
8011 {_FINISH, 14 },
8012 {_GET_OLD_MAPNO, 16 },
8013 {_MAP_JUMP, 15 },
8014 {_SET_DUNGEON_FLOOR, 21 },
8015 {_GET_DUNGEON_FLOOR, 22 },
8016 {_FADEOUT_TO_EVENT, 17 },
8017 {_NAME_REGISTRY, 18 },
8018 {_WORLD_MAP, 20 },
8019 {_MAP_JUMP_BGM_STOP, 23 },
8020 {_MAP_JUMP_BGM_PLAY, 27 },
8021 {_GOTO_FP_CHANGE, 24 },
8022 {_GOTO_CHANGE_ESA, 25 },
8023 {_GOTO_FISH_RANKING, 26 },
8024 {_SET_CURRENT_DIR, 32 },
8025 {_ACTIVE_FILE_BUFFER, 44 },
8026 {_LOAD_CHR_FILE, 33 },
8027 {_LOAD_SYNC, 34 },
8028 {_LOAD_CHARA, 35 },
8029 {_DELETE_CHARA, 47 },
8030 {_INIT_CHARA, 48 },
8031 {_LOAD_SPRITE_TEXTURE, 56 },
8032 {_LOAD_BG_SPRITE_TEXTURE, 72 },
8033 {_LOAD_TEXTURE, 74 },
8034 {_LOAD_CHARA_TEXTURE, 36 },
8035 {_LOAD_IN_VILLAGER, 37 },
8036 {_LOAD_OUT_VILLAGER, 71 },
8037 {_LOAD_VILLAGER, 57 },
8038 {_CHECK_IN_VILLAGER, 58 },
8039 {_APPEAR_VILLAGER_ON, 59 },
8040 {_APPEAR_VILLAGER_OFF, 60 },
8041 {_APPEAR_VILLAGER_OUT, 61 },
8042 {_APPEAR_VILLAGER_IN, 62 },
8043 {_APPEAR_VILLAGER_MOVE, 70 },
8044 {_CLEAR_VILLAGER_BUFF, 38 },
8045 {_CLEAR_EVENT_BUFF, 39 },
8046 {_CLEAR_EVENT_EXBUFF, 40 },
8047 {_SYNC_SCENE_CHARA, 42 },
8048 {_LOAD_SCENE, 41 },
8049 {_SYNC_SCENE_CAMERA, 43 },
8050 {_RELEASE_SCENE_CHARA, 45 },
8051 {_RELEASE_SCENE_CAMERA, 46 },
8052 {_SET_SCENE_POS, 73 },
8053 {_SET_SCENE_ROT, 75 },
8054 {_LOAD_ITEM_FILE, 49 },
8055 {_LOAD_ITEM, 50 },
8056 {_SYNC_CHARA_ITEM, 51 },
8057 {_RELEASE_CHARA_ITEM, 52 },
8058 {_DELETE_ITEM, 53 },
8059 {_SYNC_CHARA_CHARA, 54 },
8060 {_RELEASE_CHARA_CHARA, 55 },
8061 {_GET_CHARA_POS, 64 },
8062 {_GET_CHARA_TALK_POS, 65 },
8063 {_TURN_CHARA, 66 },
8064 {_SET_CHARA_POS, 67 },
8065 {_SET_CHARA_ROT, 68 },
8066 {_GET_CHARA_ROT, 69 },
8067 {_GET_NPC_TALK_POS, 130 },
8068 {_GET_NPC_POS, 131 },
8069 {_GET_NPC_PARTS_NO, 132 },
8070 {_SET_NPC_MOTION, 133 },
8071 {_SGET_NPC_TALK_MES, 134 },
8072 {_SSET_NPC_TALK_MES, 135 },
8073 {_TURN_NPC, 136 },
8074 {_SET_NPC_POS, 137 },
8075 {_SET_NPC_ROT, 138 },
8076 {_GET_NPC_ROT, 139 },
8077 {_SET_NPC_SCALE, 147 },
8078 {_GET_NPC_SCALE, 148 },
8079 {_NPC_POS_INIT, 153 },
8080 {_NPC_DRAW, 140 },
8081 {_NPC_STEP, 141 },
8082 {_NPC_COL, 142 },
8083 {_INIT_NPC_CLOTH, 143 },
8084 {_NPC_CLOTH_STEP, 160 },
8085 {_NPC_DRAW_SHADOW, 144 },
8086 {_SET_NPC_ANIME, 145 },
8087 {_SET_NPC_AMBIENT, 146 },
8088 {_SET_NPC_FOOT_SOUND, 149 },
8089 {_SET_NPC_FLOOR_ID, 152 },
8090 {_NPC_STOP, 150 },
8091 {_NPC_DRAW_BEFORE, 151 },
8092 {_SET_NPC_BODY_SIZE, 154 },
8093 {_GET_NPC_BODY_SIZE, 155 },
8094 {_NPC_CLOTH_FLOOR, 156 },
8095 {_NPC_PLIGHT_INIT, 158 },
8096 {_SET_NPC_PLIGHT, 159 },
8097 {_MES_MAKE, 192 },
8098 {_MES_CLOSE, 193 },
8099 {_MES_NEXTPAGE, 194 },
8100 {_SET_MES_AUTOSET, 195 },
8101 {_SET_MES_SHIPPO, 196 },
8102 {_SET_MES_POS, 197 },
8103 {_SET_MES_DRAWSPEED, 198 },
8104 {_SET_MES_CURSOR, 199 },
8105 {_SET_MES_OKURI, 203 },
8106 {_SET_MES_FUKIDASHI, 204 },
8107 {_CHECK_MES_COMPLETE, 200 },
8108 {_CHECK_MES_WAIT, 201 },
8109 {_CHECK_MES, 202 },
8110 {_ITEM_GET_MES, 206 },
8111 {_INIT_SYS_MES, 207 },
8112 {_SKILL_GET_MES, 208 },
8113 {_SET_MES_WIN_FLAG, 205 },
8114 {_ADD_MAXITEM_MES, 209 },
8115 {_CHECK_COMPLETE_PARTS, 256 },
8116 {_GET_EDIT_PARTS_POS, 257 },
8117 {_GET_NOW_TIME, 258 },
8118 {_SET_CLOCK, 261 },
8119 {_GET_CLOCK, 262 },
8120 {_SGET_CMP_EVENT, 259 },
8121 {_SSET_CMP_EVENT, 260 },
8122 {_CHECK_PLACE, 263 },
8123 {_CHECK_VILLAGER, 267 },
8124 {_SCHECK_REQUEST, 268 },
8125 {_DELETE_ROBO_PARTS, 269 },
8126 {_HOBJ_FIXPARTS, 320 },
8127 {_HOBJ_EDITPARTS, 321 },
8128 {_HOBJ_INTERIORPARTS, 322 },
8129 {_HOBJ_CHARA, 330 },
8130 {_HOBJ_BT_HOBJ, 332 },
8131 {_HOBJ_ITEM, 336 },
8132 {_OBJ_DRAW, 323 },
8133 {_SET_OBJ_POS, 324 },
8134 {_GET_OBJ_POS, 325 },
8135 {_SET_OBJ_ROT, 326 },
8136 {_GET_OBJ_ROT, 327 },
8137 {_SET_OBJ_SCALE, 328 },
8138 {_GET_OBJ_SCALE, 329 },
8139 {_SYNC_OBJ_OBJ, 333 },
8140 {_RELEASE_OBJ_OBJ, 334 },
8141 {_SET_OBJ_FOG, 335 },
8142 {_GET_TALKNPC_INFO_ID, 384 },
8143 {_GET_TALKNPC_ID, 385 },
8144 {_GET_TALKNPC_STATUS, 389 },
8145 {_SET_TALK_CAMERA, 386 },
8146 {_SET_TALK_MES, 387 },
8147 {_SET_TALK_SELECT_MES, 388 },
8148 {_EVERY_TALK_EVENT, 390 },
8149 {_SET_CAMERA, 416 },
8150 {_SET_FOLLOW_CAMERA, 417 },
8151 {_ADD_CAMERA_ANGLE, 418 },
8152 {_ADD_CAMERA_HEIGHT, 419 },
8153 {_ADD_CAMERA_DIST, 420 },
8154 {_CAMERA_STEP, 421 },
8155 {_SET_CAMERA_POS, 422 },
8156 {_GET_CAMERA_POS, 423 },
8157 {_SET_CAMERA_REF, 424 },
8158 {_GET_CAMERA_REF, 425 },
8159 {_SET_CAMERA_SPEED, 426 },
8160 {_SET_PROJECTION, 427 },
8161 {_ITEM_GET_CAMERA, 428 },
8162 {_SET_CAMERA_ANGLE, 429 },
8163 {_GET_CAMERA_ANGLE, 430 },
8164 {_SET_CAMERA_ROTATE, 431 },
8165 {_GET_CAMERA_ROTATE, 432 },
8166 {_RESET_CAMERA, 433 },
8167 {_RESET_CAMERA_ANGLE, 436 },
8168 {_SYNC_CAMERA_REF_CHARA, 434 },
8169 {_RELEASE_CAMERA_REF_CHARA, 435 },
8170 {_SYNC_CAMERA_REF_OBJ, 437 },
8171 {_RELEASE_CAMERA_REF_OBJ, 438 },
8172 {_SYNC_CAMERA_POS_OBJ, 439 },
8173 {_RELEASE_CAMERA_POS_OBJ, 440 },
8174 {_SET_CAMERA_ROLL, 441 },
8175 {_GET_CAMERA_ROLL, 442 },
8176 {_FADE_IN, 500 },
8177 {_FADE_OUT, 501 },
8178 {_CHECK_FADE, 502 },
8179 {_INIT_SPRITE, 503 },
8180 {_DRAW_SPRITE, 504 },
8181 {_DRAW_BG_SPRITE, 516 },
8182 {_DRAW_BACK, 505 },
8183 {_DRAW_SHADOW, 506 },
8184 {_SET_CLIP_POINT, 507 },
8185 {_DRAW_EDIT_WATER, 508 },
8186 {_DRAW_WATER_SURFACE, 509 },
8187 {_SCREEN_FILTER, 510 },
8188 {_DRAW_THUNDER, 528 },
8189 {_SET_LIGHT, 511 },
8190 {_SET_LIGHT_COLOR, 512 },
8191 {_SET_AMBIENT, 513 },
8192 {_SAVE_LIGHT, 514 },
8193 {_LOAD_LIGHT, 515 },
8194 {_SET_DOF_LEVEL, 517 },
8195 {_SP_INIT, 518 },
8196 {_SP_SET_TEX, 519 },
8197 {_SP_SET_POS, 520 },
8198 {_SP_SET_RGBA, 521 },
8199 {_SP_SET_ROT, 522 },
8200 {_SP_SET_MOVE, 526 },
8201 {_SP_DRAW, 523 },
8202 {_INIT_DRAW_DAY, 524 },
8203 {_DRAW_DAY, 525 },
8204 {_MAP_TITLE_OFF, 527 },
8205 {_SET_WIND, 529 },
8206 {_ASQ_INIT, 600 },
8207 {_ASQ_SYNC_CHARA, 601 },
8208 {_ASQ_SET_POS, 602 },
8209 {_ASQ_MOVE, 603 },
8210 {_ASQ_MOVE_STEP, 604 },
8211 {_ASQ_ROT_REF, 605 },
8212 {_ASQ_CLEAR_ROT, 606 },
8213 {_ASQ_WAIT_ROT, 607 },
8214 {_ASQ_ROT_MOVE, 608 },
8215 {_ASQ_ROT_ANGLE, 618 },
8216 {_ASQ_SET_ROT, 609 },
8217 {_ASQ_DELAY_ROT, 610 },
8218 {_ASQ_CHECK, 611 },
8219 {_ASQ_MOTION_TRG, 612 },
8220 {_ASQ_MOTION_PLAY, 613 },
8221 {_ASQ_MOTION_STOP, 614 },
8222 {_ASQ_MOTION_NEXT, 615 },
8223 {_ASQ_ANIME_TRG, 616 },
8224 {_ASQ_ANIME, 617 },
8225 {_OBJ_ANIME_INIT, 650 },
8226 {_OBJ_ANIME, 651 },
8227 {_SSET_GAME_FLAG, 700 },
8228 {_SGET_GAME_FLAG, 701 },
8229 {_SSET_GAME_INT_FLAG, 711 },
8230 {_SGET_GAME_INT_FLAG, 712 },
8231 {_SITEM_GET, 702 },
8232 {_SSET_MAP_FLAG, 703 },
8233 {_SGET_MAP_FLAG, 704 },
8234 {_SET_WORK_FLAG, 705 },
8235 {_GET_WORK_FLAG, 706 },
8236 {_SITEM_CHECK, 707 },
8237 {_SITEM_CHECK_ALL, 724 },
8238 {_SGET_DUNGEON_STATUS, 708 },
8239 {_SGET_PARTY_NUM, 709 },
8240 {_SSET_PARTY_NUM, 710 },
8241 {_SSET_REQUEST_EVENT_FLAG, 713 },
8242 {_SADD_VISIT_MAP, 714 },
8243 {_SSKILL_GET, 715 },
8244 {_SGET_EQUIP_WEAPON, 716 },
8245 {_SADD_MAXITEM, 717 },
8246 {_SITEM_LOST, 718 },
8247 {_SATRA_PARTS_GET, 719 },
8248 {_SATRA_CHIP_GET, 720 },
8249 {_SGET_REQUEST, 264 },
8250 {_SGET_ATRA_PARTS_NUM, 265 },
8251 {_SGET_DAY, 266 },
8252 {_SSET_TIME, 721 },
8253 {_SGET_TIME, 722 },
8254 {_SADD_TIME, 723 },
8255 {_SEQUIP_DEFAULT_WEAPON, 725 },
8256 {_LOAD_SND_SYNC, 800 },
8257 {_LOAD_SOUND_SET, 816 },
8258 {_LOAD_VOICE_SET, 822 },
8259 {_LOAD_BGM, 801 },
8260 {_DELETE_BGM, 815 },
8261 {_PLAY_BGM, 802 },
8262 {_STOP_BGM, 803 },
8263 {_SET_BGM_VOL, 804 },
8264 {_SET_BGM_VOLF, 825 },
8265 {_GET_BGM_VOL, 805 },
8266 {_GET_BGM_NO, 806 },
8267 {_SET_OUT_BGM_NO, 813 },
8268 {_GET_OUT_BGM_NO, 814 },
8269 {_BGM_FADE_IN, 817 },
8270 {_BGM_FADE_OUT, 818 },
8271 {_CHECK_BGM_FADE, 819 },
8272 {_PLAY_AMB_BGM, 820 },
8273 {_STOP_AMB_BGM, 821 },
8274 {_SET_AMB_VOLF, 824 },
8275 {_PLAY_SE, 807 },
8276 {_STOP_SE, 808 },
8277 {_SET_SE_VOL, 809 },
8278 {_LOAD_SPECIAL_SE, 810 },
8279 {_PLAY_SPECIAL_SE, 811 },
8280 {_STOP_SPECIAL_SE, 812 },
8281 {_SET_SPECIAL_SE_VOL, 823 },
8282 {_SOUND_OFF_COUNT, 826 },
8283 {_GET_V_ARG, 900 },
8284 {_GET_I_ARG, 901 },
8285 {_GET_F_ARG, 902 },
8286 {_TEST, 1000},
8287 {_EB_INIT, 950 },
8288 {_EB_SET_KEY, 951 },
8289 {_EB_LOOP, 952 },
8290 {_EB_SET_MOTION, 953 },
8291 {_EB_DEBUG, 954 },
8292 {_EB_INTRO_START, 955 },
8293 {_EB_INTRO_LOOP, 956 },
8294 {_EB_INTRO_END, 957 },
8295 {_EB_FINISH_SOUND, 958 },
8296 {_LOAD_MAIN_CHARA, 999 },
8297 {_LOAD_FISHING_DATA, 998 },
8298 {_GOTO_FISHING, 997 },
8299 {_INIT_FISH, 996 },
8300 {_EXIT_FISHING, 995 },
8301 {_SET_FISHING_ESA, 994 },
8302#ifdef PAL
8303 {_GET_TV_MODE, 1001},
8304 {_GET_LANG_CODE, 1002},
8305#endif
8306 {NULL, -1 },
8307};
8308
8309int EdSetEventScript(char *common_script, char *map_script, CDataAlloc2<1> *allocator) {
8310 if (common_script == NULL) {
8311 event_enable = 0;
8312 return 0;
8313 }
8314
8315 event_enable = 1;
8316 RS_STACKDATA *stack = (RS_STACKDATA *) allocator->Alloc(64);
8317 RS_CALLDATA *calls = (RS_CALLDATA *) allocator->Alloc(384);
8318 EdEventScript.load((RS_PROG_HEADER *) common_script, stack, 128, calls, 512);
8319
8320 if (map_script == NULL) {
8321 map_script = common_script + ((int *) common_script)[5];
8322 }
8323
8324 if (EdEventInfo.messages[1] != NULL) {
8325 EdEventInfo.messages[1]->SetBuff((short *) map_script);
8326 }
8327
8328 int i;
8329
8330 for (i = 0; i < 1500; i++) {
8331 ext_func__2[i] = NULL;
8332 }
8333
8334 for (i = 0;; i++) {
8335 if (ext_func_info[i].function == NULL) {
8336 break;
8337 }
8338
8339 int j;
8340
8341 for (j = 0; j < i; j++) {
8342 if (ext_func_info[i].operation == ext_func_info[j].operation) {
8343 printf("same ext_func_no!!!\n");
8344
8345 while (1) {
8346 }
8347 }
8348 }
8349
8350 int operation = ext_func_info[i].operation;
8351
8352 if (operation < 0 || operation >= 1500) {
8353 printf("ext func over!!");
8354 } else {
8355 ext_func__2[operation] = ext_func_info[i].function;
8356 }
8357 }
8358
8359 EdEventScript.ext_func(ext_func__2, 1500);
8360 simple_event = 0;
8361 return 1;
8362}
8363
8364int EdInitEventParamSimple() {
8365 int i;
8366 EdEventInfo.next_event = -1;
8367 EdEventInfo.fadeout_event_no = -1;
8368 EdEventInfo.interior_entrance = -1;
8369 EdEventInfo.projection = -1.0f;
8370 EdEventInfo.return_code = ED_EVENT_RETURN_NONE;
8371 motion_stop_flag = 0;
8372 menu_mode = ED_MENU_NONE;
8373 CurrentDir[0] = '\0';
8374 actv_file = 0;
8375 actv_buffer = 0;
8376 follow_chara = NULL;
8377 sync_camera_ref_chara = NULL;
8378 sync_camera_ref_obj = NULL;
8379 sync_camera_pos_obj = NULL;
8380 sync_camera_ref_offset[0] = 0.0f;
8381 sync_camera_ref_offset[1] = 0.0f;
8382 sync_camera_ref_offset[2] = 0.0f;
8383 EdEventInfo.player_collision = false;
8384 EdEventInfo.player_draw = true;
8385 EdEventInfo.player_shadow_draw = true;
8386 EdEventInfo.player_foot_sound = 1;
8387 EdEventInfo.player_stop = false;
8388
8389 for (i = 0; i < 16; i++) {
8390 EdEventInfo.npc_collision[i] = 0;
8391 EdEventInfo.npc_draw[i] = 1;
8392 EdEventInfo.npc_shadow_draw[i] = 1;
8393 EdEventInfo.npc_foot_sound[i] = 1;
8394 EdEventInfo.npc_stop[i] = 0;
8395 EdEventInfo.npc_draw_before[i] = 0;
8396 }
8397
8398 for (i = 0; i < 266; i++) {
8399 asq_table[i].operation = ACT_SEQ_UNUSED;
8400 asq_table[i].next = NULL;
8401 }
8402
8403 for (i = 0; i < 10; i++) {
8404 ActSeq[i].Initialize(asq_table, 266);
8405 }
8406
8407 SpriteTable.Initialize(sprite_table, 32, 4);
8408 SpriteTable.ClearPointer();
8409 SpriteTableBack.Initialize(sprite_table, 32, 4);
8410 SpriteTableBack.ClearPointer();
8411
8412 for (i = 45; i <= 49; i++) {
8413 TexManager.DeleteTextureBlock(i);
8414 }
8415
8416 memset(ObjHandle, 0, sizeof(ObjHandle));
8417 event_stop = 0;
8418 event_pause = 0;
8419
8420 for (i = 0; i <= 0; i++) {
8421 EdEventInfo.item_frame[i] = NULL;
8422 }
8423
8424 SceneData.Initialize();
8425
8426 for (i = 0; i < 16; i++) {
8427 ED_SPRITE *sprite = GetSprite(i);
8428
8429 if (sprite != NULL) {
8430 InitSprite(sprite);
8431 } else {
8432 break;
8433 }
8434 }
8435
8436 ClearObjAnime(-1);
8437 EdEventInfo.wind[3] = -1.0f;
8438 EdEventInfo.sound_off_count = 0;
8439 return 1;
8440}
8441
8442int EdInitEventParam() {
8443 EdInitEventParamSimple();
8444 CDataAlloc2<1> *allocator = (CDataAlloc2<1> *) BaseBuffer;
8445
8446 if (allocator != NULL) {
8447 int used = allocator->used;
8448 u_char *base = allocator->base + used * 16;
8449 int limit = allocator->limit - used;
8450 EdVillagerBuffer.base = base;
8451 EdVillagerBuffer.limit = limit;
8452 EdVillagerBuffer.used = 0;
8453 }
8454
8455 for (int i = 0; i < 320; i++) {
8456 anime_data[i].Initialize();
8457 }
8458
8459 if (EdEventInfo.main_texture_animation == NULL) {
8460 EdEventInfo.main_character->InitializeTexAnime(anime_data, 320);
8461 }
8462
8463 for (int i = 0; i < EdEventInfo.npc_count; i++) {
8464 EdEventInfo.npcs[i].Initialize();
8465 EdEventInfo.npcs[i].InitializeTexAnime(anime_data, 320);
8466 TexManager.DeleteTextureBlock(EdEventInfo.npc_texture_block + i);
8467 }
8468
8469 if (EdEventInfo.main_character != NULL) {
8470 EdEventInfo.main_character->SetMotion(0, 0);
8471 }
8472
8473 return 1;
8474}
8475
8483int EdRunEvent(int program, CDataAlloc2<1> *arena);
8484
8485int EdEventInit(int event_number, CDataAlloc2<1> *arena, char *program) {
8486 if (program == NULL) {
8487 return 0;
8488 }
8489
8490 run_system_event = 0;
8491
8492 for (int i = 0; i < 8; i++) {
8493 ClsMes *message = EdEventInfo.messages[i];
8494
8495 if (message == NULL) {
8496 continue;
8497 }
8498
8499 message->text_columns = MES_WIN_COLUMNS;
8500 message->text_rows = 10;
8501 message->text_len = 0;
8502 message->text_width = 0;
8503 message->text_height = 0;
8504 message->fade = 0.0f;
8505 message->fade_in = true;
8506 message->text_rate = message->text_rate_set;
8507 message->waiting = false;
8508 message->text_at = 0.0f;
8509 message->text_no = 0;
8510 message->text_from = 0;
8511 message->page_from = 0;
8512 message->InitMesWinTbl();
8513 message->clut_now = message->clut_default;
8514 message->wait = 0;
8515 message->blink = 0;
8516 message->auto_page_wait = 0;
8517 message->mes_made = -1;
8518 message->edge_alpha = 0x80;
8519
8520 for (int j = 0; j < 10; j++) {
8521 message->mes_no[j] = -1;
8522 }
8523
8524 for (int j = 0; j < 8; j++) {
8525 message->values[j] = 0;
8526 }
8527
8528 message->value = 0;
8529 message->value_signed = false;
8530 message->value_show = true;
8531 message->value_narrow = false;
8532 message->space_width = -1;
8533 message->space_area = -1;
8534 message->cursor_row = -1;
8535 message->cursor_y = 0;
8536 message->cursor_lit = false;
8537
8538 for (int j = 0; j < 10; j++) {
8539 message->line_pos[j].x = -1;
8540 message->line_pos[j].y = -1;
8541 }
8542 }
8543
8544 EdEventScript.reload((RS_PROG_HEADER *) program);
8545 EdEventInfo.return_code = ED_EVENT_RETURN_NONE;
8546 EdEventInfo.event_no = event_number;
8547 EdEventInfo.exit_code = 0;
8548 EdEventInfo.draw_exclamation_mark = false;
8549 EdEventInfo.reset_camera_angle = 0;
8550 EdEventInfo.outside_map_no = -1;
8551 EdEventInfo.suppress_background = false;
8552 EdEventInfo.screen_filter = false;
8553 EdEventInfo.lighting_override = false;
8554 EdEventInfo.suppress_shadows = false;
8555 EdEventInfo.return_code = ED_EVENT_RETURN_NONE;
8556 EdEventInfo.map_jump_bgm_stop = true;
8557 EdEventInfo.map_jump_bgm_play = true;
8558 MGGetPLight(EdEventInfo.light_direction, EdEventInfo.light_color);
8559 MGGetAmbient(EdEventInfo.ambient_color);
8560
8561 if (event_enable == 0) {
8562 return 0;
8563 }
8564
8565 EdInitEventParamSimple();
8566 BaseBuffer = (u_int *) arena;
8567
8568 if (EdRunEvent(event_number, arena) <= 0) {
8569 simple_event = 1;
8570 GamePad.AutoRepeatOff();
8571 GamePad.MenuModeOff();
8572 return 0;
8573 }
8574
8575 simple_event = 0;
8576 skip_enable = 0;
8577 return 1;
8578}
8579
8583void RunEvent(CRunScript *script, int program, CDataAlloc2<1> *arena) {
8584 int used = arena->used;
8585 u_char *base = arena->base + used * 16;
8586 int limit = arena->limit - used;
8587 EdEventBuffer.base = base;
8588 EdEventBuffer.limit = limit;
8589 EdEventBuffer.used = 0;
8590 world_rot[3] = 0.0f;
8591 world_rot[2] = 0.0f;
8592 world_rot[1] = 0.0f;
8593 world_rot[0] = 0.0f;
8594 sceVu0CopyVector(world_pos, world_rot);
8595 sceVu0UnitMatrix(world_local);
8596 sceVu0UnitMatrix(local_world);
8597 set_wl_matrix = 0;
8598 script->run(program);
8599}
8600
8604int EdRunEvent(int program, CDataAlloc2<1> *arena) {
8605 RunEvent(&EdEventScript, program, arena);
8606}
8607
8608int EdResumeEvent() {
8609 EdEventScript.resume();
8610 return 1;
8611}
8612
8613int EdEventSkip() {
8614 EdEventScript.skip();
8615 return 1;
8616}
8617
8618int EdEventAllClear() {
8619 EdEventInfo.main_character->ClearTexAnime();
8620
8621 if (EdEventInfo.main_texture_animation != NULL) {
8622 for (int i = 0; i < EdEventInfo.main_texture_animation_count; i++) {
8623 EdEventInfo.main_texture_animation[i].Initialize();
8624 }
8625
8627 }
8628
8630 EdEventInfo.main_character->DeleteExtendMotion();
8631 EdEventInfo.main_character->SetMotion(0, 0);
8632
8633 for (int i = 0; i < EdEventInfo.npc_count; i++) {
8634 CNPCharacter *npc = GetNPC(i);
8635
8636 if (npc != NULL) {
8637 if (npc->texture_block >= 54) {
8638 TexManager.DeleteTextureBlock(npc->texture_block);
8639 }
8640
8641 npc->Initialize();
8642 npc->InitializeTexAnime(NULL, 0);
8643 }
8644 }
8645
8646 EdEventInfo.main_character->SetMotionCamera(EdEventInfo.camera);
8647
8648 for (int i = 0; i <= 0; i++) {
8649 DeleteItemFrame(i);
8650 }
8651
8652 SceneData.Initialize();
8653
8654 for (int i = 45; i <= 49; i++) {
8655 TexManager.DeleteTextureBlock(i);
8656 }
8657
8658 for (int i = 0; i < 10; i++) {
8659 ActSeq[i].ClearSeq();
8660 }
8661
8662 return 1;
8663}
8664
8665int EdEventFinish() {
8666 EdEventInfo.suppress_background = false;
8667 EdEventInfo.suppress_shadows = false;
8668 EdEventInfo.screen_filter = false;
8669 EdEventInfo.lighting_override = false;
8670 EdEventInfo.wind[3] = -1.0f;
8671 EdEventInfo.main_character->frame->DeleteReference();
8672 CFrame *shadow = EdEventInfo.main_character->shadow_frame;
8673
8674 if (shadow != NULL) {
8675 shadow->DeleteReference();
8676 }
8677
8678 return 1;
8679}
8680
8688int EdEventMode(CCameraFollow *camera, int kind) {
8689 int result;
8690
8691#ifdef PAL
8692 // Debug builds toggle the event debugger with one button and pause the event with another.
8693 if (DebugMode != 0 && GamePad.Down(PAD_R3) != 0) {
8694 EdEventStopPlay();
8695 }
8696
8697 if (DebugMode != 0 && menu_mode == ED_MENU_NONE && GamePad.Down(PAD_START) != 0) {
8698 if (EdCheckEventPause() == 0) {
8699 SndBgmPause();
8700 } else {
8701 SndBgmRePlay();
8702 }
8703
8704 EdEventPause();
8705 }
8706
8707#endif
8708 if (event_stop != 0) {
8709 static int mode = 0;
8710 static char *mode_name[] = {"! CAMERA POS\n", "# CAMERA REF\n", "$ CHARACTER\n"};
8711 static int select_chara = -1;
8712 sceVu0FVECTOR position;
8713 sceVu0FVECTOR reference;
8714 char text[128];
8715 sceVu0FVECTOR chara_position;
8716 sceVu0FVECTOR chara_rotation;
8717 int *collision;
8718 CCharacter *chara;
8719
8720 EdDDebug(1);
8721 collision = &EdEventInfo.player_collision;
8722
8723 if (select_chara >= 0) {
8724 collision = &EdEventInfo.npc_collision[select_chara];
8725 }
8726
8727 camera->GetPos(position);
8728 camera->GetRef(reference);
8729
8730 switch (mode) {
8731 case 0:
8732 camera->FollowOff();
8733 EdDMoveCamera(position, reference);
8734 camera->SetPos(position);
8735 camera->SetRef(reference);
8736 break;
8737 case 1:
8738 camera->FollowOff();
8739 EdDMoveCameraRef(position, reference);
8740 camera->SetPos(position);
8741 camera->SetRef(reference);
8742 break;
8743 case 2:
8744 if (GamePad.Down(PAD_RIGHT) != 0) {
8745 select_chara++;
8746
8747 if (select_chara >= EdEventInfo.npc_count) {
8748 select_chara = -1;
8749 }
8750 }
8751
8752 if (GamePad.Down(PAD_LEFT) != 0) {
8753 select_chara--;
8754
8755 if (select_chara < -1) {
8756 select_chara = EdEventInfo.npc_count - 1;
8757 }
8758 }
8759
8760 if (select_chara == -1) {
8761 EdDMoveChara(EdEventInfo.main_character, camera);
8762 } else {
8763 EdDMoveChara(&EdEventInfo.npcs[select_chara], camera);
8764 }
8765
8766 if (GamePad.Down(PAD_CROSS) != 0) {
8767 *collision = !*collision;
8768 }
8769
8770 break;
8771 }
8772
8773 EdDPrint(mode_name[mode]);
8774 chara = EdEventInfo.main_character;
8775
8776 if (select_chara >= 0) {
8777 chara = &EdEventInfo.npcs[select_chara];
8778 }
8779
8780 chara->GetPosition(chara_position);
8781 chara->GetRotation(chara_rotation);
8782 GetLocalPos(chara_position, chara_position);
8783 GetLocalRot(chara_rotation, chara_rotation);
8784 sprintf(text, "select chara %d\ncollision %d\n", select_chara, *collision);
8785 EdDPrint(text);
8786 EdDPrintVector(" pos = ", chara_position);
8787 EdDPrintVector(" rot = ", chara_rotation);
8788 sprintf(text, " amb %5.1f %5.1f %5.1f %5.1f\n", chara->ambient_offset[0], chara->ambient_offset[1], chara->ambient_offset[2], chara->ambient_offset[3]);
8789 EdDPrint(text);
8790 EdDPrint("camera\n");
8791 GetLocalPos(position, position);
8792 GetLocalPos(reference, reference);
8793 EdDPrintVector(" pos = ", position);
8794 EdDPrintVector(" ref = ", reference);
8795 float angle = camera->GetAngle();
8796 chara_rotation[2] = 0.0f;
8797 chara_rotation[0] = 0.0f;
8798 chara_rotation[1] = angle;
8799 GetLocalRot(chara_rotation, chara_rotation);
8800 sprintf(text, " angle = %4.3f\n", chara_rotation[1]);
8801 EdDPrint(text);
8802 sprintf(text, " height = %6.2f\n", position[1] - reference[1]);
8803 EdDPrint(text);
8804 position[1] = 0.0f;
8805 reference[1] = 0.0f;
8806 sprintf(text, " distance = %6.2f\n", DistVector(position, reference));
8807 EdDPrint(text);
8808 sprintf(text, " projection = %7.1f\n", MGGetProjection());
8809 EdDPrint(text);
8810 EdDCheck();
8811
8812 if (GamePad.Down(PAD_SELECT) != 0) {
8813 EdOutPutFile();
8814 }
8815
8816 if (GamePad.Down(PAD_UP) != 0) {
8817 mode--;
8818 }
8819
8820 if (GamePad.Down(PAD_DOWN) != 0) {
8821 mode++;
8822 }
8823
8824 if (mode < 0) {
8825 mode = 2;
8826 }
8827
8828 if (mode > 2) {
8829 mode = 0;
8830 }
8831
8832 if (EdEventInfo.projection > 0.0f) {
8833 MGSetProjection(EdEventInfo.projection);
8834 }
8835
8836 if (EdEventInfo.suppress_background != 0 && EdEventInfo.background_color[0] >= 0.0f) {
8837 MGSetBGColor(EdEventInfo.background_color[0], EdEventInfo.background_color[1], EdEventInfo.background_color[2], 128.0f);
8838 }
8839
8840 return 0;
8841 }
8842
8843 if (event_pause != 0) {
8844 EdPauseFlag = 1;
8847 ObjAnimeAllStop();
8849
8850 if (GamePad.Down2(PAD_CROSS) != 0 && menu_mode == ED_MENU_NONE) {
8851 SndBgmRePlay();
8852 BreakReadBG();
8853 EdEventSkip();
8854 EdEventPause();
8855 }
8856
8857 if (EdEventInfo.projection > 0.0f) {
8858 MGSetProjection(EdEventInfo.projection);
8859 }
8860
8861 if (EdEventInfo.suppress_background != 0 && EdEventInfo.background_color[0] >= 0.0f) {
8862 MGSetBGColor(EdEventInfo.background_color[0], EdEventInfo.background_color[1], EdEventInfo.background_color[2], 128.0f);
8863 }
8864
8865 if (GamePad.Down(PAD_CIRCLE) != 0) {
8866 SndBgmRePlay();
8867 EdEventPause();
8868 }
8869
8870 return 0;
8871 }
8872
8873 EdPauseFlag = 0;
8874
8875 if (motion_stop_flag != 0) {
8878 ObjAnimeAllStop();
8880 } else {
8883 ObjAnimeAllStart();
8885 }
8886
8887 ReadBG();
8888 EdEventInfo.camera = camera;
8889
8890 if (EdEventInfo.world_coord_enable != 0) {
8891 SetWorldCoord((float *) &EdEventInfo.world_coord[8], (float *) &EdEventInfo.world_coord[24]);
8892 }
8893
8894 for (int i = 0; i < 8; i++) {
8895 if (EdEventInfo.messages[i] != NULL) {
8896 EdEventInfo.messages[i]->Step();
8897 }
8898 }
8899
8900 if (SceneData.frame != NULL) {
8901 float speed = SceneData.motion_speed;
8902 SceneData.SetMotion(0, 0);
8903 SceneData.motion_speed = speed;
8904#ifdef PAL_TIMING
8905 SceneData.motion_speed = 6.0f * speed / 5.0f;
8906#endif
8907 SceneData.Step();
8908 }
8909
8910 if (menu_mode == ED_MENU_NONE) {
8911 menu_mode_status = -1;
8912 EdResumeEvent();
8913
8914 if (menu_mode != ED_MENU_NONE) {
8915 menu_mode_status = 0;
8916
8917 if (EdInitMenu(menu_mode) == 0) {
8918 menu_mode = ED_MENU_NONE;
8919 }
8920
8921 motion_stop_flag = 1;
8922 }
8923 } else {
8924 switch (menu_mode_status) {
8925 case 0:
8926 motion_stop_flag = 1;
8927
8928 if (EdInitModeFinish(EdEventInfo.camera, TexManager.GetTexture("frame_image", -1)) != 0) {
8929 menu_mode_status = 1;
8930 motion_stop_flag = 0;
8931 MenuMapJumpMode = -1;
8932 }
8933
8934 break;
8935 case 1:
8936 case 2:
8937 EdDrawOffAll();
8938
8939 if (EdMenuMode() != 0) {
8940 switch (menu_mode) {
8941 case ED_MENU_USE_ITEM:
8942 case ED_MENU_CHANGE_ESA: {
8943 int item = EdGetUseItem();
8944
8945 if (p_use_item != NULL) {
8946 ((RS_STACKDATA *) p_use_item)->i = item;
8947 }
8948
8949 p_use_item = NULL;
8950 break;
8951 }
8953 break;
8954 case ED_MENU_WORLD_MAP:
8955 if (p_jump_map_no != 0) {
8956 ((RS_STACKDATA *) p_jump_map_no)->i = MenuMapJumpMode + 1;
8957 }
8958
8959 p_jump_map_no = 0;
8960 break;
8961 }
8962
8963 menu_mode = ED_MENU_NONE;
8964 EdDrawOnAll();
8965 EdExitMenu();
8966 }
8967
8968 break;
8969 }
8970 }
8971
8972 for (int i = 0; i < 10; i++) {
8973 ActSeq[i].Play();
8974 }
8975
8976 for (int i = 0; i < 16; i++) {
8977 ObjAnimePlay(&obj_anime[i]);
8978 }
8979
8980 result = EdEventInfo.return_code;
8981
8982 if (result > 0) {
8983 EdEventFinish();
8984 GamePad.AutoRepeatOff();
8985 GamePad.MenuModeOff();
8986 }
8987
8988 if (EdEventInfo.projection > 0.0f) {
8989 MGSetProjection(EdEventInfo.projection);
8990 }
8991
8992 if (EdEventInfo.suppress_background != 0 && EdEventInfo.background_color[0] >= 0.0f) {
8993 MGSetBGColor(EdEventInfo.background_color[0], EdEventInfo.background_color[1], EdEventInfo.background_color[2], 128.0f);
8994 }
8995
8996 if (camera != NULL) {
8997 if (follow_chara != NULL) {
8998 sceVu0FVECTOR position;
8999 follow_chara->GetPosition(position);
9000 camera->SetFollow(position[0], position[1] + 0.8f * follow_chara->body_height, position[2]);
9001 }
9002
9003 if (sync_camera_ref_chara != NULL) {
9004 sceVu0FVECTOR reference = {0.0f, 0.0f, 0.0f, 1.0f};
9005 sync_camera_ref_chara->GetPosition(reference);
9006 sceVu0AddVector(reference, reference, sync_camera_ref_offset);
9007 camera->SetRef(reference[0], reference[1] + 0.8f * sync_camera_ref_chara->body_height, reference[2]);
9008 }
9009
9010 if (sync_camera_ref_obj != NULL) {
9011 sceVu0FVECTOR reference;
9012 get_obj_world_pos(sync_camera_ref_obj, reference);
9013 sceVu0AddVector(reference, reference, sync_camera_ref_offset);
9014 camera->SetRef(reference[0], reference[1], reference[2]);
9015 }
9016
9017 if (sync_camera_pos_obj != NULL) {
9018 sceVu0FVECTOR position;
9019 get_obj_world_pos(sync_camera_pos_obj, position);
9020 camera->SetPos(position);
9021 }
9022 }
9023
9024 if (result == 0 && EdEventScript.IsEnd() != 0) {
9025 EdEventFinish();
9026 GamePad.AutoRepeatOff();
9027 GamePad.MenuModeOff();
9028 result = 1;
9029 }
9030
9031 return result;
9032}
9033
9034int EdEventNPCStep() {
9035 int wind = EdEventInfo.main_character->wind;
9036
9037 if (EdEventInfo.player_stop == 0) {
9038 CVector3_f_ velocity;
9039 velocity.x = 0.0f;
9040 velocity.y = 0.0f;
9041 velocity.z = 0.0f;
9042 EdEventInfo.main_character->SetVelocity(velocity);
9043 EdEventInfo.main_character->Step();
9044 EdEventInfo.main_character->ShadowStep();
9045 }
9046
9047 for (int i = 0; i < EdEventInfo.npc_count; i++) {
9048 EdEventInfo.npcs[i].wind = wind;
9049
9050 if (EdEventInfo.npc_stop[i] == 0) {
9051 ((CNPCharacter *) EdEventInfo.npcs)[i].sequence_enabled = 0;
9052 EdEventInfo.npcs[i].Step();
9053 EdEventInfo.npcs[i].ShadowStep();
9054 }
9055 }
9056
9057 if (EdEventInfo.player_stop == 0) {
9058 EdEventInfo.main_character->ClothStep(0);
9059 }
9060
9061 for (int i = 0; i < EdEventInfo.npc_count; i++) {
9062 EdEventInfo.npcs[i].wind = wind;
9063
9064 if (EdEventInfo.npc_stop[i] == 0) {
9065 EdEventInfo.npcs[i].ClothStep(0);
9066 }
9067 }
9068
9069 return 1;
9070}
9071
9072int EdEventSpriteDraw() {
9073 for (int block = 45; block <= 49; block++) {
9074 int texture_loaded = 0;
9075
9076 for (int i = 0; i < 16; i++) {
9077 ED_SPRITE *sprite = GetSprite(i);
9078
9079 if (sprite == NULL) {
9080 break;
9081 }
9082
9083 if (sprite->enabled == 0 || sprite->layer == 0) {
9084 continue;
9085 }
9086
9087 CRect_i_ screen;
9088 CRect_i_ texel;
9089 screen.x = screen.y = screen.width = screen.height = 0;
9090 texel.x = texel.y = texel.width = texel.height = 0;
9091 screen.x = (int) sprite->x;
9092 screen.y = (int) sprite->y;
9093 screen.width = sprite->width;
9094 screen.height = sprite->height;
9095 texel.x = sprite->source_x;
9096 texel.y = sprite->source_y;
9097 texel.width = sprite->source_width;
9098 texel.height = sprite->source_height;
9099
9100 if (screen.width < 0) {
9101 screen.width = texel.width;
9102 }
9103
9104 if (screen.height < 0) {
9105 screen.height = texel.height;
9106 }
9107
9108 if (sprite->texture.block != block) {
9109 continue;
9110 }
9111
9112 if (texture_loaded == 0) {
9113 TexManager.ReloadTexture(GetVif1Packet(), block);
9114 texture_loaded = 1;
9115 }
9116
9117 setbilinear(sprite->bilinear);
9118 sprite->x += sprite->move_x;
9119 sprite->y += sprite->move_y;
9120
9121 if (sprite->rotated == 0) {
9122 set2DSprite(GetVif1Packet(), &sprite->texture, screen, texel, (u_char) sprite->red, (u_char) sprite->green, (u_char) sprite->blue, (u_char) sprite->alpha);
9123 } else {
9124 set2DSpriteRot(GetVif1Packet(), &sprite->texture, screen, texel, sprite->rotation_x, sprite->rotation_y, sprite->rotation, (u_char) sprite->red, (u_char) sprite->green, (u_char) sprite->blue, (u_char) sprite->alpha);
9125 }
9126 }
9127 }
9128
9129 TexManager.ReloadTexture(GetVif1Packet(), 45);
9130 SpriteTable.DrawTable();
9131 return 1;
9132}
9133
9134int EdEventBackSpriteDraw() {
9135 TexManager.ReloadTexture(GetVif1Packet(), 46);
9136 SpriteTableBack.DrawTable();
9137 return 1;
9138}
9139
9140int EdSearchNearNPC(CCharacter *character, CNPCharacter *npcs, int count) {
9141 sceVu0FVECTOR direction;
9142 sceVu0FVECTOR character_rotation;
9143 sceVu0FVECTOR npc_rotation;
9144 sceVu0FVECTOR character_position;
9145 sceVu0FVECTOR npc_position;
9146 int i;
9147 int nearest = -1;
9148 float nearest_distance = 0.0f;
9149 character->GetRotation(character_rotation);
9150
9151 for (i = 0; i < count; i++) {
9152 if (npcs[i].villager_id < 0) {
9153 continue;
9154 }
9155
9156 int available = npcs[i].initialized != 0 && npcs[i].draw_enabled != 0;
9157
9158 if (!available) {
9159 continue;
9160 }
9161
9162 npcs[i].talk_target = false;
9163 character->GetPosition(character_position);
9164 npcs[i].GetPosition(npc_position);
9165 float height = character_position[1] - npc_position[1];
9166
9167 if (height < 0.0f) {
9168 height = -height;
9169 } else {
9170 height = height;
9171 }
9172
9173 if (height > character->body_height) {
9174 continue;
9175 }
9176
9177 npc_position[1] = 0.0f;
9178 character_position[1] = 0.0f;
9179 float distance = DistVector(character_position, npc_position);
9180
9181 if (distance > 5.0f + 1.2f * npcs[i].body_width) {
9182 continue;
9183 }
9184
9185 character->GetDir(npcs[i], direction);
9186 float character_angle = atan2f(direction[0], direction[2]);
9187 npcs[i].GetDir(*character, direction);
9188 float npc_angle = atan2f(direction[0], direction[2]);
9189 npcs[i].GetRotation(npc_rotation);
9190 int talk_direction = EdEventInfo.villagers[npcs[i].villager_id].talk_direction;
9191
9192 if (AngleCmp(npc_angle, npc_rotation[1], HALF_PI_SHORT) != 0 && talk_direction == 0 && npcs[i].event_status == 0) {
9193 continue;
9194 }
9195
9196 if (nearest < 0) {
9197 nearest_distance = distance;
9198 nearest = i;
9199 } else if (distance < nearest_distance) {
9200 nearest_distance = distance;
9201 nearest = i;
9202 }
9203 }
9204
9205 return nearest;
9206}
9207
9209static CNPCharacter *talk_villager__2;
9210
9212static int talk_chara_info_id;
9213
9215static int talk_camera;
9216
9218static int talk_mode;
9219
9221static int talk_select;
9222
9224static int TalkMesMake;
9225
9227static int TalkMesNo;
9228
9229int EdTalkModeInit(CNPCharacter *villager, int character_info_id) {
9230 if (villager->villager_id < 0) {
9231 return 0;
9232 }
9233
9234 talk_villager__2 = villager;
9235
9236 if (character_info_id < 0) {
9237 talk_chara_info_id = villager->villager_id;
9238 } else {
9239 talk_chara_info_id = character_info_id;
9240 }
9241
9242 talk_mode = TALK_MODE_SELECT;
9243 TalkMesMake = 1;
9244 TalkMesNo = 0;
9245 talk_camera = 0;
9246
9247 if (villager->event_status != 0) {
9248 talk_camera = rand() % 3;
9249 }
9250
9251 talk_select = 0;
9252 EdEventInfo.talk_npc_id = (villager - EdVillager);
9253 EdEventInfo.talk_select_prompt = -1;
9254 return 1;
9255}
9256
9257CNPCharacter *EdNowTalkChara() {
9258 return talk_villager__2;
9259}
9260
9261int EdNowTalkCharaInfoID() {
9262 return talk_chara_info_id;
9263}
9264
9268static inline void EdCloseTalkMes() {
9269 EditMes1.text_rate = EditMes1.text_rate_set;
9270 EditMes1.mes_made = -1;
9271 EditMes1.fade_in = false;
9272 EditMes1.text_columns = MES_WIN_COLUMNS;
9273 EditMes1.text_rows = 0xA;
9274 EditMes1.text_len = 0;
9275 EditMes1.text_width = 0;
9276 EditMes1.text_height = 0;
9277 EditMes1.fade = 0.0f;
9278 EditMes1.fade_in = true;
9279 EditMes1.text_rate = EditMes1.text_rate_set;
9280 EditMes1.waiting = false;
9281 EditMes1.text_at = 0.0f;
9282 EditMes1.text_no = 0;
9283 EditMes1.text_from = 0;
9284 EditMes1.page_from = 0;
9285 EditMes1.InitMesWinTbl();
9286 EditMes1.clut_now = EditMes1.clut_default;
9287 EditMes1.wait = 0;
9288 EditMes1.blink = 0;
9289 EditMes1.auto_page_wait = 0;
9290 EditMes1.mes_made = -1;
9291 EditMes1.edge_alpha = 0x80;
9292
9293 for (int i = 0; i < 10; i++) {
9294 EditMes1.mes_no[i] = -1;
9295 }
9296
9297 for (int i = 0; i < 8; i++) {
9298 EditMes1.values[i] = 0;
9299 }
9300
9301 EditMes1.value = 0;
9302 EditMes1.value_signed = false;
9303 EditMes1.value_show = true;
9304 EditMes1.value_narrow = false;
9305 EditMes1.space_width = -1;
9306 EditMes1.space_area = -1;
9307 EditMes1.cursor_row = -1;
9308 EditMes1.cursor_y = 0;
9309 EditMes1.cursor_lit = false;
9310
9311 for (int i = 0; i < 10; i++) {
9312 EditMes1.line_pos[i].x = -1;
9313 EditMes1.line_pos[i].y = -1;
9314 }
9315}
9316
9324int EdTalkMode(CCharacter *player, CCameraFollow *camera, int mode, int *selection) {
9328 static sceVu0FVECTOR vv[3] = {
9329 {-18.8f, 7.1f, -21.3f, 1.0f},
9330 {21.0f, 6.5f, -5.7f, 1.0f},
9331 {22.6f, 6.9f, 16.5f, 1.0f},
9332 };
9333
9334 GamePad.MenuModeOn(0x78);
9335 ReadBG();
9336
9337 if (camera != NULL) {
9338 camera->FollowOff();
9339 }
9340
9341 EditMes1.Step();
9342
9343 CNPCharacter *villager = talk_villager__2;
9344 villager->near_camera = true;
9345 sceVu0FVECTOR player_position;
9346 sceVu0FVECTOR villager_position;
9347 sceVu0FVECTOR player_rotation;
9348 sceVu0FVECTOR villager_rotation;
9349 sceVu0FVECTOR direction;
9350 player->GetPosition(player_position);
9351 player->GetRotation(player_rotation);
9352 villager->GetPosition(villager_position);
9353 villager->GetRotation(villager_rotation);
9354 sceVu0SubVector(direction, villager_position, player_position);
9355 float player_yaw = atan2f(direction[0], direction[2]);
9356 float villager_yaw = atan2f(-direction[0], -direction[2]);
9357 player_rotation[1] = AngleInterpolate(player_rotation[1], player_yaw, 0.1f, INTERPOLATE_STEP);
9358 player->SetRotation(player_rotation);
9359 villager_rotation[1] = AngleInterpolate(villager_rotation[1], villager_yaw, 0.1f, INTERPOLATE_STEP);
9360
9361 if (EdInteriorFlag == 0 || EdEventInfo.villagers[talk_chara_info_id].talk_rotation == 0) {
9362 villager->SetRotation(villager_rotation);
9363 }
9364
9365 sceVu0FVECTOR reference;
9366 sceVu0AddVector(reference, player_position, villager_position);
9367 sceVu0ScaleVector(reference, reference, 0.5f);
9368 reference[1] += 15.0f;
9369
9370 if (camera != NULL) {
9371 camera->FollowOff();
9372 camera->SetRef(reference);
9373 }
9374
9375 sceVu0FVECTOR camera_position;
9376 sceVu0FMATRIX rotation;
9377 sceVu0UnitMatrix(rotation);
9378 sceVu0RotMatrixY(rotation, rotation, player_yaw);
9379 sceVu0ApplyMatrix(camera_position, rotation, vv[talk_camera]);
9380 sceVu0AddVector(camera_position, reference, camera_position);
9381
9382 if (camera != NULL) {
9383 camera->SetPos(camera_position);
9384 }
9385
9386 if (camera != NULL) {
9387 sceVu0FMATRIX view;
9388 sceVu0FVECTOR eye;
9389 camera->GetCameraMatrix(view);
9390 camera->GetPos(eye);
9391 MGSetViewMatrix(view, eye);
9392 }
9393
9394 if (EdEventInfo.talk_select_prompt < 0) {
9395 talk_mode = TALK_MODE_MESSAGE;
9396 TalkMesNo = EdEventInfo.talk_messages[0];
9397 } else {
9398 TalkMesNo = EdEventInfo.talk_select_message;
9399 }
9400
9401 int choice_count = 0;
9402
9403 for (;;) {
9404 if (EdEventInfo.talk_messages[choice_count] < 0) {
9405 break;
9406 }
9407
9408 choice_count++;
9409 }
9410
9411 SaveData->GetGrdNPCData(MapNo, EdNowTalkCharaInfoID());
9412
9413 switch (talk_mode) {
9414 case TALK_MODE_MESSAGE:
9415 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0) {
9416 if (EditMes1.State() == CLSMES_SHOWN) {
9417 EdCloseTalkMes();
9418
9419 if (camera != NULL) {
9420 camera->FollowOn();
9421 }
9422
9423 villager->SetMotion(0, 0);
9424 GamePad.AutoRepeatOff();
9425 GamePad.MenuModeOff();
9426 return 1;
9427 }
9428
9429 if (EditMes1.State() == CLSMES_PAGE_WAIT) {
9430 EditMes1.GoNextPage();
9431 } else {
9432 EditMes1.text_rate = 0.0f;
9433 }
9434 }
9435
9436 EditMes1.cursor_row = -1;
9437 villager->SetMotion(3, 0);
9438 break;
9439 case TALK_MODE_SELECT:
9440 if (GamePad.Down(PAD_UP) != 0) {
9441 talk_select--;
9442
9443 if (talk_select < 0) {
9444 talk_select = choice_count - 1;
9445 }
9446 }
9447
9448 if (GamePad.Down(PAD_DOWN) != 0) {
9449 talk_select++;
9450
9451 if (talk_select > choice_count - 1) {
9452 talk_select = 0;
9453 }
9454 }
9455
9456 if (GamePad.Down(PAD_CROSS) != 0) {
9457 if (EditMes1.State() == CLSMES_SHOWN) {
9458 talk_mode = TALK_MODE_MESSAGE;
9459 TalkMesMake = 1;
9460 TalkMesNo = EdEventInfo.talk_messages[talk_select];
9461
9462 if (EdEventInfo.talk_select_prompt == 0 && talk_select == 3) {
9463 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(MapNo, EdNowTalkCharaInfoID());
9464
9465 if (npc != NULL) {
9466 npc->flags |= 2;
9467 }
9468 }
9469
9470 if ((talk_select == 0 && EdEventInfo.talk_select_prompt > 0 && EdEventInfo.talk_select_prompt != 4) || (talk_select > 0 && EdEventInfo.talk_select_prompt == 4)) {
9471 EdCloseTalkMes();
9472
9473 if (camera != NULL) {
9474 camera->FollowOn();
9475 }
9476
9477 villager->SetMotion(0, 0);
9478 GamePad.AutoRepeatOff();
9479 GamePad.MenuModeOff();
9480
9481 if (EdEventInfo.talk_select_prompt == 4) {
9482 EdSetShopNo(EdEventInfo.talk_messages[talk_select]);
9483
9484 if (talk_select == 1) {
9485 return 2;
9486 }
9487
9488 if (talk_select == 2) {
9489 return 3;
9490 }
9491
9492 if (talk_select == 3) {
9493 return 2;
9494 }
9495
9496 if (talk_select == 4) {
9497 return 2;
9498 }
9499 }
9500
9501 EdSetShopNo(EdEventInfo.talk_messages[0]);
9502
9503 if (EdEventInfo.talk_select_prompt == 1) {
9504 return 2;
9505 }
9506
9507 if (EdEventInfo.talk_select_prompt == 2) {
9508 return 3;
9509 }
9510
9511 if (EdEventInfo.talk_select_prompt == 3) {
9512 if (selection != NULL) {
9513 *selection = EdEventInfo.talk_messages[0];
9514 }
9515
9516 return 4;
9517 }
9518
9519 return 1;
9520 }
9521 } else {
9522 EditMes1.text_rate = 0.0f;
9523 }
9524 }
9525
9526 if (GamePad.Down(PAD_CIRCLE) != 0) {
9527 GamePad.AutoRepeatOff();
9528 GamePad.MenuModeOff();
9529 EdCloseTalkMes();
9530
9531 if (camera != NULL) {
9532 camera->FollowOn();
9533 }
9534
9535 villager->SetMotion(0, 0);
9536 return 1;
9537 }
9538
9539 EditMes1.cursor_row = talk_select;
9540 villager->SetMotion(0, 0);
9541 break;
9542 }
9543
9544 int talk_position[4];
9545
9546 if (talk_mode == TALK_MODE_SELECT) {
9547 if (mode != 0) {
9548 EditMes1.tail_on = false;
9549 EditMes1.auto_pos = MES_POS_BOTTOM;
9550 }
9551
9552 EditMes1.AutoSetSub(player, villager, talk_position);
9553 EditMes1.AutoSet(talk_position);
9554 } else {
9555 EditMes1.tail_on = true;
9556 EditMes1.auto_pos = MES_POS_AUTO;
9557 EditMes1.AutoSetSub(villager, player, talk_position);
9558 EditMes1.AutoSet(talk_position);
9559 }
9560
9561 switch (talk_mode) {
9562 case TALK_MODE_SELECT:
9563 if (TalkMesMake != 0) {
9564 EditMes1.text_rate = 0.0f;
9565 TalkMesMake = EditMes1.MakeMesWin(TalkMesNo);
9566 }
9567
9568 break;
9569 case TALK_MODE_MESSAGE:
9570 if (TalkMesMake != 0) {
9571 TalkMesMake = EditMes1.MakeMesWin(TalkMesNo);
9572 }
9573
9574 break;
9575 }
9576
9577 return 0;
9578}
9579
9582
9583int CheckPartsInfo(EDITPARTS_INFO *info) {
9584 if (info->obtained == 0) {
9585 return 0;
9586 }
9587
9588 if (info->stock <= 0) {
9589 return 0;
9590 }
9591
9592 return 1;
9593}
float position[4]
Definition effect.hpp:165
float half_width
Definition effect.hpp:166
float half_height
Definition effect.hpp:167
void Draw()
Definition effect.cpp:14
void SetDelayRot(int delay)
void ClearSeq()
Definition actionseq.cpp:19
void MotionSeq(int motion, int mode, float speed, int flags)
void Initialize(ACT_SEQ *records, int count)
Definition actionseq.cpp:9
void SyncChara(CCharacter *target)
Definition actionseq.cpp:55
void AnimeTrg(int delay)
void RotAngleSeq(float angle, float speed)
int CheckEnd()
void SetPos(float *destination)
void SetRot(float *angles)
void AnimeSeq(int animation, int enabled, int frames, int disable_after)
void MoveSeq(float *destination, int frames)
void RotMoveSeq(float speed)
void MotionTrg(int delay)
void ClearRotSeq()
void RotRefSeq(float *reference, float speed)
void Play()
void WaitRotSeq()
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
s16 foot_sound
Definition collision.hpp:56
void SetHeight(float height)
void AddDistance(float delta)
void SetFollow(float x, float y, float z)
void SetAngleSoon(float angle)
void AddAngle(float delta)
void SetDistance(float distance)
virtual void Step(int steps)
void SetAngle(float angle)
void AddHeight(float delta)
void SetNextRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:141
static s32 StopCamera
Definition camera.hpp:38
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
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
void SetSpeed(float speed)
Definition camera.cpp:222
float GetRoll()
Definition camera.cpp:242
void GetPos(float *pos)
Definition camera.cpp:230
void SetNextPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:118
void GetDir(float *dir)
Definition camera.cpp:147
void SetRoll(float roll)
Definition camera.cpp:226
void TexAnimeOn(int no)
void SetMotion(int no, int mode, float speed=-1.0f)
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)
void ClearPointLight()
void DeleteExtendMotion()
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
virtual void SetScale(float x, float y, float z)
void InitializeTexAnime(CTexAnimeData *data, int count)
void SetFootSoundID(int id)
void SetMotionCamera(CCamera *camera)
virtual void Step()
sceVu0FVECTOR ambient_offset
void SetMotionSpeed(float speed)
virtual void ShadowStep()
tagMOTION_TYPE motion_type
void ClearTexAnime()
static s32 MotionStopFlag
virtual void SetRotation(float x, float y, float z)
void FootSoundEnable(int on)
virtual void ClothFloor(int floor)
void DeleteExtendTexture(int block_no)
virtual void Initialize()
CFrame * shadow_frame
void TexAnimeOff(int no)
u_int * images[4]
float body_height
float body_depth
float motion_speed
float body_width
virtual void SetPosition(float x, float y, float z)
virtual int PickUpPoly(float *position, CCPoly *polygons)
int SetPointLight(float *pos, float inner_range, float outer_range, float red, float green, float blue, float alpha)
virtual void ClothStep(int step)
u_char * base
Definition dataalloc.hpp:24
int LostItem(int item_id)
void SetPartySize(s8 size)
float GetAlt(float x, float y, float z)
int GetAreaCode(float x, float y, float z)
CMapParts * GetParts(float x, float y, float z)
void GetPartsBox(CBoxVu0 *out_box, float x, float y, float z)
sceVu0FVECTOR clip_plane
int PickUpPoly(CCPoly *polygons, float x, float y, float z)
CMapParts * GetPartsObject(int parts_no)
int GetRandomPlanePos(sceVu0FVECTOR out_position, sceVu0FVECTOR avoid[], int avoid_count, sceVu0FVECTOR bounds)
CGroundWater water_surfaces[4]
EPARTS_FUNC_DATA * GetPeoplePos(int villager, float *out_position)
int PickUpEditAreaPoly(CCPoly *polygons, float x, float y, float z)
int GetCompEvent(int index)
int GetRequest(int index)
int CheckComplete(int index)
void SetCompEvent(int index, int completed)
EDITPARTS_INFO * GetPartsInfo(int index)
short draw_on
Definition frame.hpp:27
char clip_enable
Definition frame.hpp:29
char remake_pending
Definition frame.hpp:31
char fog_enable
Definition frame.hpp:33
CVisualVu1 * GetVisual()
Definition frame.cpp:1337
int flags
Definition frame.hpp:60
CFrameAttr attr
Definition frame.hpp:65
sceVu0FVECTOR scale
Definition frame.hpp:75
sceVu0FVECTOR position
Definition frame.hpp:76
CFrame * parent
Definition frame.hpp:66
int GetPadDown()
Definition gamepad.cpp:517
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
int GetPadOn()
Definition gamepad.cpp:509
int GetPadUp()
Definition gamepad.cpp:525
float GetLXf()
Definition gamepad.cpp:541
void MenuModeOn(int threshold)
Definition gamepad.cpp:613
float GetLYf()
Definition gamepad.cpp:545
float GetRXf()
Definition gamepad.cpp:533
void AutoRepeatOff()
Definition gamepad.cpp:609
CFrameVu1 * shadow_frame
Definition op_b.cpp:91
CFrameVu1 * shade_frame
Definition op_b.cpp:92
CFrame * GetCollisionFrame()
Definition mapobject.cpp:12
CFrameVu1 * camera_frame
Definition op_b.cpp:93
s32 parts_no
Definition mapparts.hpp:51
virtual void SetPosition(float *position)
Definition mapparts.cpp:20
CFrame * ripple_frame
Definition mapparts.hpp:56
s32 subtype
Definition mapparts.hpp:61
virtual void SetRotation(float x, float y, float z)
Definition mapparts.cpp:30
virtual void FrameObjectOnOff(char *name, int on)
Definition mapparts.cpp:80
void GetPosition(float *out_position)
Definition mapparts.cpp:16
int SetSeq(float *destination, float speed)
virtual void Step()
s32 recurring_talk_event
virtual void Initialize()
char resource_name[0x20]
int SetWait(int frames)
virtual void ShadowStep()
CFrameVu1 * frame[4]
Definition op_b.cpp:76
s32 draw_on
Definition op_b.cpp:78
virtual void GetRotation(float *out_rotation)
Definition object.cpp:116
virtual void GetScale(float *out_scale)
Definition object.cpp:174
CVector3_f_ rotation
Definition object.hpp:23
virtual void SetScale(float x, float y, float z)
Definition object.cpp:162
void GetDir(CObject &other, float *out_direction)
Definition object.cpp:25
virtual void SetVelocity(CVector3_f_ velocity)
Definition object.cpp:50
float pos[4]
Definition object.hpp:18
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
void skip()
void reload(RS_PROG_HEADER *prog)
void resume()
int run(int no)
void ext_func(int(**table)(RS_STACKDATA *, int), int count)
void load(RS_PROG_HEADER *prog, RS_STACKDATA *stack, int stack_num, RS_CALLDATA *call, int call_num)
SV_GRD_NPC * GetGrdNPCData(int map_no, int npc_no)
Definition savedata.cpp:215
float GetNowTime()
Definition savedata.cpp:61
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
void SetNowTime(float time)
Definition savedata.cpp:57
int QuestDungeon(int dungeon_no, int add)
Definition savedata.cpp:535
int GetGameFlag(int flag_no)
Definition savedata.cpp:258
int SetGameFlag(int flag_no, int value)
Definition savedata.cpp:279
int GetGameIntFlag(int flag_no)
Definition savedata.cpp:310
int GetDay()
Definition savedata.cpp:96
int VisitMap(int map_no, int add)
Definition savedata.cpp:521
void AddNowTime(float add)
Definition savedata.cpp:65
SV_GEORAMA_DATA * GetGrdData(int georama_no)
Definition savedata.cpp:175
SV_EDIT_PARTS_INFO * GetEditPartsInfo(int georama_no, int plot_no)
Definition savedata.cpp:183
int AtraPartsGet(int georama_no, int plot_no)
Definition savedata.cpp:455
int SetGameIntFlag(int flag_no, int value)
Definition savedata.cpp:318
int AtraChipGet(int georama_no, int chip_id)
Definition savedata.cpp:494
void DrawTable()
void ClearPointer()
void AddTable(int x, int y, MG_SPRITE *sprite, int layer, int align_flags)
void Initialize(SPRITE_TABLE *new_pool, int entry_count, int layer_count)
static s32 stop_anime
short block
Definition texture.hpp:52
u_long tex0
Definition texture.hpp:57
s32 skill_owned[6]
s8 floor_reached[7]
WEAPON_HAVE chara_weapons[6][11]
s8 equipped_weapon_slot[6]
s32 text_rows
Definition clsmes.hpp:158
s32 auto_pos
Definition clsmes.hpp:172
s32 text_from
Definition clsmes.hpp:198
s32 cursor_y
Definition clsmes.hpp:225
s32 tail_on
Definition clsmes.hpp:173
float text_rate_set
Definition clsmes.hpp:193
void AutoSetSub(CCharacter *first, CCharacter *second, int *out_pos)
Definition clsmes.cpp:168
s32 wait
Definition clsmes.hpp:204
s32 text_no
Definition clsmes.hpp:197
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
s32 page_from
Definition clsmes.hpp:199
s32 page_arrow
Definition clsmes.hpp:209
s32 text_height
Definition clsmes.hpp:161
s32 text_width
Definition clsmes.hpp:160
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 tail_length
Definition clsmes.hpp:179
s32 auto_page_wait
Definition clsmes.hpp:206
s32 fade_in
Definition clsmes.hpp:188
void GoNextPage()
Definition clsmes.cpp:663
s32 space_width
Definition clsmes.hpp:222
s32 clut_now
Definition clsmes.hpp:203
void AutoSet(int *pos)
Definition clsmes.cpp:173
s32 tail_half_width
Definition clsmes.hpp:178
s32 blink
Definition clsmes.hpp:205
s32 cursor_row
Definition clsmes.hpp:224
float fade
Definition clsmes.hpp:187
void SetBuff(short *buff)
Definition clsmes.cpp:456
s32 mes_made
Definition clsmes.hpp:207
s32 values[8]
Definition clsmes.hpp:217
s32 value_narrow
Definition clsmes.hpp:221
s32 value_signed
Definition clsmes.hpp:219
void SetMesFukidashi(int style)
Definition clsmes.cpp:511
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
int State()
Definition clsmes.cpp:637
s32 space_area
Definition clsmes.hpp:223
float text_at
Definition clsmes.hpp:196
char frame_name[0x10]
Definition objanime.hpp:122
sceVu0FVECTOR from
Definition objanime.hpp:126
sceVu0FVECTOR step
Definition objanime.hpp:128
sceVu0FVECTOR to
Definition objanime.hpp:127
CDataAlloc2< 1 > * WorkBuffer__2
Definition dataread.hpp:250
ED_SOUND_ID
Definition edit.hpp:132
@ ED_EVENT_RETURN_FISHING
Definition edit.hpp:21
@ ED_EVENT_RETURN_NONE
Definition edit.hpp:13
@ ED_EVENT_RETURN_MAP_JUMP
Definition edit.hpp:18
@ ED_EVENT_RETURN_INTERIOR
Definition edit.hpp:14
@ ED_EVENT_RETURN_OUTSIDE
Definition edit.hpp:17
@ ED_MENU_CHANGE_ESA
Definition edit.hpp:41
@ ED_MENU_FISHING_EXCHANGE
Definition edit.hpp:40
@ ED_MENU_USE_ITEM
Definition edit.hpp:37
@ ED_MENU_NAME_REGISTRY
Definition edit.hpp:38
@ ED_MENU_FISH_RANKING
Definition edit.hpp:42
@ ED_MENU_WORLD_MAP
Definition edit.hpp:39
@ ED_MENU_NONE
Definition edit.hpp:32
@ MAP_PARTS_SUBTYPE_ROAD
Definition mapparts.hpp:19
@ MAP_PARTS_SUBTYPE_BRIDGE
Definition mapparts.hpp:21
@ INTERPOLATE_STEP
Definition mathutil.hpp:15
ACT_SEQ_OPERATION operation
Definition actionseq.hpp:32
ACT_SEQ * next
Definition actionseq.hpp:35
u_long128 * buffer
Definition dataread.hpp:29
EDITPARTS_ELEMENT elements[6]
sceVu0FVECTOR minimum
Definition editloop.hpp:153
sceVu0FVECTOR maximum
Definition editloop.hpp:152
float near_distance
Definition editloop.hpp:227
float far_distance
Definition editloop.hpp:228
EDIT_AREA_RECT_INFO edit_area_rects[8]
Definition editloop.hpp:333
float background_colour[12][4]
Definition editloop.hpp:319
int time_tables[7][12][16]
Definition editloop.hpp:347
int people_list[16]
Definition editloop.hpp:348
EDIT_MAP_WORK_INFO work
Definition editloop.hpp:355
float background_colour_2[12][4]
Definition editloop.hpp:320
float light_colour[12][4][4]
Definition editloop.hpp:318
float ambient[12][4]
Definition editloop.hpp:316
EDIT_FOG_INFO fog[12]
Definition editloop.hpp:321
float light_direction[12][4][4]
Definition editloop.hpp:317
VILLAGER_INFO villagers[16]
Definition editloop.hpp:346
int(* function)(RS_STACKDATA *, int)
s32 outside_map_no
Definition edit.hpp:197
float current_time
Definition edit.hpp:179
s32 npc_foot_sound[16]
Definition edit.hpp:172
s32 interior_entrance
Definition edit.hpp:194
s32 talk_messages[16]
Definition edit.hpp:191
s32 fadeout_event_no
Definition edit.hpp:215
s32 player_draw
Definition edit.hpp:164
s32 integer_arguments[8]
Definition edit.hpp:213
s32 npc_stop[16]
Definition edit.hpp:173
sceVu0FMATRIX light_color
Definition edit.hpp:210
s32 npc_count
Definition edit.hpp:176
s32 npc_draw[16]
Definition edit.hpp:170
s32 edit_parts_count
Definition edit.hpp:185
s32 npc_collision[16]
Definition edit.hpp:169
CMapParts * interior_parts
Definition edit.hpp:188
CNPCharacter * npcs
Definition edit.hpp:162
s32 player_texture_block
Definition edit.hpp:168
ClsMes * messages[8]
Definition edit.hpp:178
s32 main_texture_animation_count
Definition edit.hpp:161
s32 npc_shadow_draw[16]
Definition edit.hpp:171
sceVu0FVECTOR screen_filter_color
Definition edit.hpp:206
s32 talk_select_prompt
Definition edit.hpp:193
float background_color[3]
Definition edit.hpp:202
s32 player_stop
Definition edit.hpp:167
sceVu0FVECTOR wind
Definition edit.hpp:181
CTexAnimeData * main_texture_animation
Definition edit.hpp:160
s32 suppress_shadows
Definition edit.hpp:200
s32 npc_texture_block
Definition edit.hpp:175
s32 world_coord_enable
Definition edit.hpp:150
s32 screen_filter
Definition edit.hpp:204
float projection
Definition edit.hpp:155
CMapParts * edit_parts
Definition edit.hpp:186
s32 player_collision
Definition edit.hpp:163
s32 sound_off_count
Definition edit.hpp:154
s32 player_foot_sound
Definition edit.hpp:166
float reset_camera_yaw
Definition edit.hpp:158
s32 lighting_override
Definition edit.hpp:207
u8 world_coord[0x28]
Definition edit.hpp:151
s32 reset_camera_angle
Definition edit.hpp:157
s32 interior_start_event
Definition edit.hpp:196
s32 fixed_parts_count
Definition edit.hpp:183
char interior_name[0x20]
Definition edit.hpp:195
s32 map_jump_bgm_stop
Definition edit.hpp:152
s32 interior_parts_count
Definition edit.hpp:187
CMapParts * fixed_parts
Definition edit.hpp:184
s32 draw_exclamation_mark
Definition edit.hpp:198
s32 suppress_background
Definition edit.hpp:199
s32 player_shadow_draw
Definition edit.hpp:165
CCharacter * main_character
Definition edit.hpp:159
s32 exit_code
Definition edit.hpp:218
s32 flag_arguments[8]
Definition edit.hpp:214
s32 next_event
Definition edit.hpp:216
CFrameVu1 * item_frame[1]
Definition edit.hpp:189
VILLAGER_INFO * villagers
Definition edit.hpp:177
s32 npc_draw_before[16]
Definition edit.hpp:174
s32 map_jump_bgm_play
Definition edit.hpp:153
s32 return_code
Definition edit.hpp:217
CCameraFollow * camera
Definition edit.hpp:156
sceVu0FVECTOR vector_arguments[4]
Definition edit.hpp:212
s32 talk_npc_id
Definition edit.hpp:190
s32 talk_select_message
Definition edit.hpp:192
sceVu0FMATRIX light_direction
Definition edit.hpp:209
CEditGround * edit_ground
Definition edit.hpp:182
sceVu0FVECTOR ambient_color
Definition edit.hpp:211
sceVu0FVECTOR position
Definition edit.hpp:72
sceVu0FVECTOR camera_pos
Definition edit.hpp:73
ED_EVENT_POINT * point
Definition edit.hpp:76
sceVu0FVECTOR rotation
Definition edit.hpp:74
sceVu0FVECTOR position
Definition editloop.hpp:257
sceVu0FVECTOR rotation
Definition editloop.hpp:259
CMapObject * map_object
Definition editloop.hpp:246
CCamera * camera
Definition editloop3.hpp:42
C3DSprite * system_effect
Definition editloop3.hpp:41
CEditGround * ground
Definition editloop3.hpp:39
CFrame * event_marker
Definition editloop3.hpp:40
CCharacter * player
Definition editloop3.hpp:37
float move_y
float rotation
s16 source_width
s16 source_height
float move_x
CTexture texture
sceVu0FVECTOR position
Definition objanime.hpp:107
char frame_name[0x10]
Definition objanime.hpp:106
sceVu0FVECTOR parameters
Definition objanime.hpp:109
sceVu0FVECTOR rotation
Definition objanime.hpp:108
sceVu0FVECTOR values
Definition objanime.hpp:110
char element_name[6][0x20]
int colour_ofs
Definition mdt.hpp:17
int colour_count
Definition mdt.hpp:16
s32 z
Definition mglib.hpp:27
s32 x
Definition mglib.hpp:25
s32 enable
Definition mglib.hpp:24
s32 y
Definition mglib.hpp:26
CCamera * camera
Definition gameutil.hpp:196
CCharacter * character
CFrame * frames[12]
CMapParts * map_parts
Definition title.cpp:61
s32 width
Definition rect.hpp:36
s32 height
Definition rect.hpp:37
int y
Definition title.cpp:63
int x
Definition title.cpp:62
RS_STACKDATA * p
Definition runscript.hpp:83
s32 request_complete[24]
Definition savedata.hpp:97
s32 talk_message
Definition savedata.hpp:89
char name[0x40]
Definition editloop.hpp:203
sceVu0FVECTOR position
Definition editloop.hpp:216
sceVu0FVECTOR rotation
Definition editloop.hpp:217
int hide_when_complete
Definition editloop.hpp:211
MOTION_STATE state
Definition gameutil.hpp:273
ED_EVENT_POINT points[256]
Definition editloop.hpp:282