DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
runscript_opcodes.cpp
2
3#include <cmath>
4#include <cstdio>
5#include <cstdlib>
6
7#include "btactstatus.hpp"
8#include "collision.hpp"
9#include "dataalloc.hpp"
10#include "dun/gameloop.hpp"
11#include "edit.hpp"
12#include "editloop3.hpp"
13#include "frame.hpp"
14#include "mathutil.hpp"
15#include "monstorunit.hpp"
16#include "runscript.hpp"
17#include "shot_freefuncs.hpp"
18#include "snd.hpp"
19#include "userstatus.hpp"
20
25 int (*function)(RS_STACKDATA *, int);
26 int operation;
27};
28
29int PUSH_INT_DATA[16][8];
30int GL_INT[10];
31int (*ext_func[256])(RS_STACKDATA *, int);
32
36static int bak_ColNo;
37
41static int GetStackInt(RS_STACKDATA *argument) {
42 if (argument->type == RS_FLOAT) {
43 return (int) argument->f;
44 }
45
46 return argument->i;
47}
48
52static float GetStackFloat(RS_STACKDATA *argument) {
53 if (argument->type == RS_INT) {
54 return (float) argument->i;
55 }
56
57 return argument->f;
58}
59
63static char *GetStackString(RS_STACKDATA *argument) {
64 return argument->s;
65}
66
70static void SetStack(RS_STACKDATA *argument, int value) {
71 if (argument->type == RS_PTR) {
72 argument->p->i = value;
73 }
74}
75
79static void SetStack(RS_STACKDATA *argument, float value) {
80 if (argument->type == RS_PTR) {
81 argument->p->f = value;
82 }
83}
84
85int _SET_MOTION(RS_STACKDATA *stack, int argc) {
86 int motion_id;
87 int monster_no = NowMonstorUnit->current_monster;
88 int half_speed;
89
90 motion_id = GetStackInt(stack++);
91
92 NowMonstorUnit->monster[monster_no].last_hit_damage = -1;
93 NowMonstorUnit->monster[monster_no].requested_motion_speed = -1.0f;
94 half_speed = 0;
95
96 if (NowMonstorUnit->monster[monster_no].slow_timer > 0) {
97 half_speed = 1;
98 }
99
100 if (argc == 1) {
101 float speed = NowMonstorUnit->chara[monster_no][0].motion_type.motion_info[motion_id].speed;
102
103 if (half_speed) {
104 speed *= 0.5f;
105 }
106
107 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, 0);
108 NowMonstorUnit->chara[monster_no][0].SetMotionSpeed(speed);
109 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
110 NowMonstorUnit->monster[monster_no].requested_motion_flags = 0;
111 NowMonstorUnit->monster[monster_no].requested_motion_speed = speed;
112
113 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
114 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, 0);
115 NowMonstorUnit->chara[monster_no][i + 1].SetMotionSpeed(speed);
116 }
117 }
118
119 if (argc == 2) {
120 float speed = GetStackFloat(stack++);
121
122 if (half_speed) {
123 speed *= 0.5f;
124 }
125
126 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, 0);
127 NowMonstorUnit->chara[monster_no][0].SetMotionSpeed(speed);
128 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
129 NowMonstorUnit->monster[monster_no].requested_motion_flags = 0;
130 NowMonstorUnit->monster[monster_no].requested_motion_speed = speed;
131
132 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
133 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, 0);
134 NowMonstorUnit->chara[monster_no][i + 1].SetMotionSpeed(speed);
135 }
136 }
137
138 if (argc == 3) {
139 float speed = GetStackFloat(stack++);
140
141 if (half_speed) {
142 speed *= 0.5f;
143 }
144
145 int mode = GetStackInt(stack++);
146 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, mode);
147 NowMonstorUnit->chara[monster_no][0].SetMotionSpeed(speed);
148 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
149 NowMonstorUnit->monster[monster_no].requested_motion_flags = mode;
150 NowMonstorUnit->monster[monster_no].requested_motion_speed = speed;
151
152 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
153 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, mode);
154 NowMonstorUnit->chara[monster_no][i + 1].SetMotionSpeed(speed);
155 }
156 }
157
158 return 1;
159}
160
161int _CHK_MOTION_FRM(RS_STACKDATA *stack, int argc) {
162 int monster_no = NowMonstorUnit->current_monster;
163 float current_frame = NowMonstorUnit->chara[monster_no][0].motion_type.state.time;
164 int motion_no = NowMonstorUnit->chara[monster_no][0].motion_no;
165 float end_frame = (float) NowMonstorUnit->chara[monster_no][0].motion_type.motion_info[motion_no].end;
166 int done = 0;
167
168 if (!(current_frame < end_frame - 1.0f) && current_frame < end_frame) {
169 done = 1;
170 }
171
172 SetStack(stack++, done);
173
174 if (argc == 2) {
175 SetStack(stack, current_frame);
176 }
177
178 return 1;
179}
180
181int _GET_MOTION_FRM(RS_STACKDATA *stack, int argc) {
182 int monster_no = NowMonstorUnit->current_monster;
183
184 SetStack(stack, NowMonstorUnit->chara[monster_no][0].motion_type.state.time);
185 return 1;
186}
187
188int _SET_MOTION_FRM(RS_STACKDATA *stack, int argc) {
189 int monster_no = NowMonstorUnit->current_monster;
190
191 NowMonstorUnit->chara[monster_no][0].motion_type.state.time = GetStackFloat(stack);
192 return 1;
193}
194
195int _GET_DISTANCE(RS_STACKDATA *stack, int argc) {
196 int monster_no = NowMonstorUnit->current_monster;
197 float monster_position[4];
198 float target_position[4];
199
200 NowMonstorUnit->chara[monster_no][0].GetPosition(monster_position);
201
202 if (argc == 1) {
203 sceVu0CopyVector(target_position, CharaMain.pos);
204 } else {
205 target_position[0] = GetStackFloat(stack++);
206 target_position[1] = GetStackFloat(stack++);
207 target_position[2] = GetStackFloat(stack++);
208 }
209
210 SetStack(stack, DistVector(monster_position, target_position));
211 return 1;
212}
213
214int _GET_POSITION(RS_STACKDATA *stack, int argc) {
215 int monster_no = NowMonstorUnit->current_monster;
216 int target = (int) GetStackFloat(stack++);
217 float position[4];
218
219 if (target == -1) {
220 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
221 }
222
223 if (target == -2) {
224 sceVu0CopyVector(position, CharaMain.pos);
225 }
226
227 SetStack(stack++, position[0]);
228 SetStack(stack++, position[1]);
229 SetStack(stack, position[2]);
230 return 1;
231}
232
233int _SET_ROTATION(RS_STACKDATA *stack, int argc) {
234 int monster_no = NowMonstorUnit->current_monster;
235
236 NowMonstorUnit->monster[monster_no].turn_target[0] = GetStackFloat(stack++);
237 NowMonstorUnit->monster[monster_no].turn_target[1] = GetStackFloat(stack++);
238 NowMonstorUnit->monster[monster_no].turn_target[2] = GetStackFloat(stack++);
239 NowMonstorUnit->monster[monster_no].turn_speed = GetStackFloat(stack);
240
241 if (NowMonstorUnit->monster[monster_no].turn_speed < 0.0f) {
242 float position[4];
243 float rotation[4];
244 float direction[4];
245
246 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
247 NowMonstorUnit->chara[monster_no][0].GetRotation(rotation);
248 sceVu0SubVector(direction, NowMonstorUnit->monster[monster_no].turn_target, position);
249 rotation[1] = atan2f(direction[0], direction[2]);
250 NowMonstorUnit->chara[monster_no][0].SetRotation(rotation);
251 NowMonstorUnit->monster[monster_no].turn_speed = 0.0f;
252 }
253
254 return 1;
255}
256
257int _CHK_ROTATION(RS_STACKDATA *stack, int argc) {
258 int monster_no = NowMonstorUnit->current_monster;
259 int done = 0;
260
261 if (NowMonstorUnit->monster[monster_no].turn_speed == 0.0f) {
262 done = 1;
263 }
264
265 SetStack(stack, done);
266 return 1;
267}
268
269int _CHK_MOVE(RS_STACKDATA *stack, int argc) {
270 int monster_no = NowMonstorUnit->current_monster;
271 int done = 0;
272
273 if (NowMonstorUnit->monster[monster_no].movement_speed == 0.0f) {
274 done = 1;
275 }
276
277 SetStack(stack++, done);
278
279 if (argc == 2) {
280 float position[4];
281
282 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
283 SetStack(stack, DistVector(NowMonstorUnit->monster[monster_no].movement, position));
284 }
285
286 return 1;
287}
288
289int _CHK_USER_INNER_PRODUCT(RS_STACKDATA *stack, int argc) {
290 int in_view;
291 int monster_no = NowMonstorUnit->current_monster;
292 float min_cosine;
293 float max_distance;
294 float position[4];
295 float rotation[4];
296 float player[4];
297 float away_from_player[4];
298
299 in_view = 0;
300 min_cosine = 1.0f - 0.011111111f * GetStackInt(stack++);
301 max_distance = 100000;
302
303 if (argc == 3) {
304 max_distance = GetStackFloat(stack++);
305 }
306
307 sceVu0CopyVector(player, CharaMain.pos);
308 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
309 NowMonstorUnit->chara[monster_no][0].GetRotation(rotation);
310 float direction[4] = {0.0f, 0.0f, 1.0f, 1.0f};
311 float identity[4][4];
312 float facing_matrix[4][4];
313
314 sceVu0UnitMatrix(identity);
315 sceVu0RotMatrixY(facing_matrix, identity, rotation[1]);
316 sceVu0ApplyMatrix(direction, facing_matrix, direction);
317 sceVu0Normalize(direction, direction);
318 away_from_player[0] = position[0] - player[0];
319 away_from_player[2] = position[2] - player[2];
320 away_from_player[1] = 0.0f;
321 away_from_player[3] = 1.0f;
322 sceVu0Normalize(away_from_player, away_from_player);
323
324 if (sceVu0InnerProduct(direction, away_from_player) >= min_cosine && DistVector(position, player) < max_distance) {
325 in_view = 1;
326 }
327
328 SetStack(stack, in_view);
329 PORT_RETURN(1);
330}
331
332int _GET_VECTOR(RS_STACKDATA *stack, int argc) {
333 int monster_no = NowMonstorUnit->current_monster;
334 float angle = 0.0f;
335 float direction[4];
336 float position[4];
337 float turn_matrix[4][4];
338 float identity[4][4];
339
340 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
341 direction[0] = GetStackFloat(stack++);
342 direction[1] = GetStackFloat(stack++);
343 direction[2] = GetStackFloat(stack++);
344 direction[3] = 1.0f;
345
346 if (argc == 7) {
347 angle = GetStackFloat(stack++);
348
349 if (angle >= 180.0f) {
350 angle -= 360.0f;
351 }
352
353 angle = DEG_TO_RAD * angle;
354
355 if (angle > TWO_PI) {
356 angle -= TWO_PI;
357 }
358
359 if (angle < -PI) {
360 angle += TWO_PI;
361 }
362 }
363
364 direction[0] -= position[0];
365 direction[1] -= position[1];
366 direction[2] -= position[2];
367 sceVu0Normalize(direction, direction);
368
369 if (argc == 7) {
370 sceVu0UnitMatrix(identity);
371 sceVu0RotMatrixY(turn_matrix, identity, angle);
372 sceVu0ApplyMatrix(direction, turn_matrix, direction);
373 }
374
375 SetStack(stack++, direction[0]);
376 SetStack(stack++, direction[1]);
377 SetStack(stack, direction[2]);
378 return 1;
379}
380
381int _GET_DIRECTION(RS_STACKDATA *stack, int argc) {
382 float rotation[4];
383 float facing_matrix[4][4];
384 float identity[4][4];
385
386 NowMonstorUnit->chara[NowMonstorUnit->current_monster][0].GetRotation(rotation);
387
388 if (argc == 4) {
389 float angle = GetStackFloat(stack++);
390
391 rotation[1] += DEG_TO_RAD * angle;
392
393 if (rotation[1] > PI) {
394 rotation[1] -= TWO_PI;
395 }
396
397 if (rotation[1] < -PI) {
398 rotation[1] += TWO_PI;
399 }
400 }
401
402 float direction[4] = {0.0f, 0.0f, 1.0f, 0.0f};
403 sceVu0UnitMatrix(identity);
404 sceVu0RotMatrixY(facing_matrix, identity, rotation[1]);
405 sceVu0ApplyMatrix(direction, facing_matrix, direction);
406 direction[3] = 1.0f;
407 sceVu0Normalize(direction, direction);
408 SetStack(stack++, direction[0]);
409 SetStack(stack++, direction[1]);
410 SetStack(stack, direction[2]);
411 return 1;
412}
413
414int _SET_MOVE(RS_STACKDATA *stack, int argc) {
415 int monster_no = NowMonstorUnit->current_monster;
416 float direction[4];
417 float position[4];
418 float speed;
419
420 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
421 direction[0] = GetStackFloat(stack++);
422 direction[1] = GetStackFloat(stack++);
423 direction[2] = GetStackFloat(stack++);
424 direction[0] -= position[0];
425 direction[1] -= position[1];
426 direction[2] -= position[2];
427 direction[3] = 1.0f;
428 sceVu0Normalize(NowMonstorUnit->monster[monster_no].movement, direction);
429 speed = GetStackFloat(stack);
430
431 if (NowMonstorUnit->monster[monster_no].slow_timer > 0) {
432 speed *= 0.5f;
433 }
434
435 NowMonstorUnit->monster[monster_no].movement_speed = speed;
436 return 1;
437}
438
439int _CHK_MOVE_INFO(RS_STACKDATA *stack, int argc) {
440 int clear;
441 int monster_no = NowMonstorUnit->current_monster;
442 float from[4];
443 float to[4];
444 float hit[4];
445
446 clear = 1;
447 NowMonstorUnit->chara[monster_no][0].GetPosition(from);
448 to[0] = GetStackFloat(stack++);
449 to[1] = GetStackFloat(stack++);
450 to[2] = GetStackFloat(stack++);
451 from[1] += 5.0f;
452 to[1] += 5.0f;
453
454 if (CheckHit(NowMonstorUnit->monster[monster_no].collision_poly, NowMonstorUnit->monster[monster_no].collision_poly_count, from, to, hit, 0, 0) >= 0) {
455 clear = 0;
456 }
457
458 SetStack(stack, clear);
459 return 1;
460}
461
462int _SET_MOVE_CANSEL(RS_STACKDATA *stack, int argc) {
463 NowMonstorUnit->monster[NowMonstorUnit->current_monster].movement_speed = 0.0f;
464 return 1;
465}
466
467int _SET_ROT_CANSEL(RS_STACKDATA *stack, int argc) {
468 NowMonstorUnit->monster[NowMonstorUnit->current_monster].turn_speed = 0.0f;
469 return 1;
470}
471
472int _SET_POSITION(RS_STACKDATA *stack, int argc) {
473 int monster_no = NowMonstorUnit->current_monster;
474 float x = GetStackFloat(stack++);
475 float y = GetStackFloat(stack++);
476 float z = GetStackFloat(stack);
477
478 NowMonstorUnit->chara[monster_no][0].SetPosition(x, y, z);
479 return 1;
480}
481
482int _STATUS_SET_FALL(RS_STACKDATA *stack, int argc) {
483 int monster_no = NowMonstorUnit->current_monster;
484
485 NowMonstorUnit->monster[monster_no].falls = GetStackInt(stack);
486 return 1;
487}
488
489int _STATUS_SET_MUTEKI(RS_STACKDATA *stack, int argc) {
490 int monster_no = NowMonstorUnit->current_monster;
491 int invincible = GetStackInt(stack);
492
493 if (NowMonstorUnit->monster[monster_no].hp > 0 && NowMonstorUnit->monster[monster_no].invincible_blocked != 0) {
494 invincible = 0;
495 }
496
497 NowMonstorUnit->monster[monster_no].invincible_timer = invincible;
498 return 1;
499}
500
501int _STATUS_SET_ALPHA(RS_STACKDATA *stack, int argc) {
502 int monster_no = NowMonstorUnit->current_monster;
503
504 NowMonstorUnit->monster[monster_no].palette_alpha_step = GetStackFloat(stack++);
505
506 if (argc == 2) {
507 NowMonstorUnit->monster[monster_no].palette_alpha_step = GetStackInt(stack);
508 } else {
509 NowMonstorUnit->monster[monster_no].palette_delay = 0;
510 }
511
512 return 1;
513}
514
515int _STATUS_CHK_ALPHA(RS_STACKDATA *stack, int argc) {
516 int done;
517 int monster_no = NowMonstorUnit->current_monster;
518 int fading_in;
519
520 done = 0;
521 fading_in = 0;
522
523 if (argc == 2) {
524 fading_in = GetStackInt(stack++);
525 }
526
527 if (fading_in == 0) {
528 if (NowMonstorUnit->monster[monster_no].palette_alpha <= 0.0f) {
529 done = 1;
530 }
531 } else if (NowMonstorUnit->monster[monster_no].palette_alpha >= 128.0f) {
532 done = 1;
533 }
534
535 SetStack(stack, done);
536 return 1;
537}
538
539int _STATUS_SET_DEAD(RS_STACKDATA *stack, int argc) {
540 int monster_no = NowMonstorUnit->current_monster;
541
542 NowMonstorUnit->monster[monster_no].state = -1;
543 NowMonstorUnit->alive_count--;
544 return 1;
545}
546
547int _STATUS_SET_EVENT(RS_STACKDATA *stack, int argc) {
548 NowMonstorUnit->requested_event = GetStackInt(stack);
549 return 1;
550}
551
552int _RUN_SCRIPT(RS_STACKDATA *stack, int argc) {
553 NowMonstorUnit->requested_event = GetStackInt(stack);
554 printf("run script !!\n");
555 return 1;
556}
557
558int _STATUS_SET_COL_OFF(RS_STACKDATA *stack, int argc) {
559 int monster_no = NowMonstorUnit->current_monster;
560
561 NowMonstorUnit->monster[monster_no].collision_off_timer = GetStackInt(stack);
562 return 1;
563}
564
565int _STATUS_GET_LIFE_RATE(RS_STACKDATA *stack, int argc) {
566 int monster_no = NowMonstorUnit->current_monster;
567 float max_hp = NowMonstorUnit->monster[monster_no].max_hp;
568 float hp = NowMonstorUnit->monster[monster_no].hp;
569
570 SetStack(stack, 100.0f * (hp / max_hp));
571 return 1;
572}
573
574int _STATUS_GET_USER_VECTOR(RS_STACKDATA *stack, int argc) {
575 int normalize = 0;
576 float angle;
577 float vector[4];
578
579 if (argc == 4) {
580 normalize = GetStackInt(stack++);
581 }
582
583 angle = 0.0f;
584 angle += DEG_TO_RAD * GetStackFloat(stack++);
585
586 if (angle > PI) {
587 angle -= TWO_PI;
588 }
589
590 if (angle < -PI) {
591 angle += TWO_PI;
592 }
593
594 getCharacterVector(vector, angle);
595
596 if (normalize != 0) {
597 sceVu0Normalize(vector, vector);
598 }
599
600 SetStack(stack++, vector[0]);
601 SetStack(stack++, vector[1]);
602 SetStack(stack, vector[2]);
603 return 1;
604}
605
606int _STATUS_GET_HEIGHT(RS_STACKDATA *stack, int argc) {
607 SetStack(stack, NowMonstorUnit->monster[NowMonstorUnit->current_monster].ground_distance);
608 return 1;
609}
610
611int _GET_RAND(RS_STACKDATA *stack, int argc) {
612 int bound = GetStackInt(stack++);
613
614 int roll = (float) bound * rand() / 2147483648.0f;
615
616 SetStack(stack, roll);
617 return 1;
618}
619
620int _GET_RANDF(RS_STACKDATA *stack, int argc) {
621 float bound = GetStackFloat(stack++);
622
623 SetStack(stack, (float) (int) (bound * rand() / 2147483648.0f));
624 return 1;
625}
626
627int _SIN_DEG(RS_STACKDATA *stack, int argc) {
628 float angle = GetStackFloat(stack++);
629
630 angle = DEG_TO_RAD * angle;
631 SetStack(stack, sinf(angle));
632 return 1;
633}
634
635int _COS_DEG(RS_STACKDATA *stack, int argc) {
636 float angle = GetStackFloat(stack++);
637
638 angle = DEG_TO_RAD * angle;
639 SetStack(stack, cosf(angle));
640 return 1;
641}
642
643// clang-format off
644int elmColor[6][3] = {
645 {230, 90, 0}, {0, 200, 255}, {255, 255, 0}, {0, 255, 0}, {255, 200, 255}, {255, 0, 0},
646};
647// clang-format on
648
649int _STATUS_SET_PALLET(RS_STACKDATA *stack, int argc) {
650 int monster_no = NowMonstorUnit->current_monster;
651
652 if (argc == 5) {
653 NowMonstorUnit->monster[monster_no].palette_target[0] = GetStackFloat(stack++);
654 NowMonstorUnit->monster[monster_no].palette_target[1] = GetStackFloat(stack++);
655 NowMonstorUnit->monster[monster_no].palette_target[2] = GetStackFloat(stack++);
656 } else {
657 int element = NowMonstorUnit->monster[monster_no].hit_element;
658
659 NowMonstorUnit->monster[monster_no].palette_target[0] = elmColor[element][0];
660 NowMonstorUnit->monster[monster_no].palette_target[1] = elmColor[element][1];
661 NowMonstorUnit->monster[monster_no].palette_target[2] = elmColor[element][2];
662 }
663
664 NowMonstorUnit->monster[monster_no].palette_cycles = GetStackInt(stack++);
665 NowMonstorUnit->monster[monster_no].palette_step = GetStackFloat(stack);
666 NowMonstorUnit->monster[monster_no].palette_blend = 0.0f;
667 return 1;
668}
669
670int _STATUS_SET_CLIPLEVEL(RS_STACKDATA *stack, int argc) {
671 int monster_no = NowMonstorUnit->current_monster;
672
673 NowMonstorUnit->monster[monster_no].clip_distance = GetStackFloat(stack);
674 return 1;
675}
676
677int _STATUS_GET_HITDMG_VOL(RS_STACKDATA *stack, int argc) {
678 SetStack(stack, NowMonstorUnit->monster[NowMonstorUnit->current_monster].last_hit_damage);
679 return 1;
680}
681
682int _STATUS_GET_MOTION_ID(RS_STACKDATA *stack, int argc) {
683 SetStack(stack, NowMonstorUnit->chara[NowMonstorUnit->current_monster][0].motion_no);
684 return 1;
685}
686
687int _STATUS_GET_DMG_ID(RS_STACKDATA *stack, int argc) {
688 SetStack(stack, NowMonstorUnit->monster[NowMonstorUnit->current_monster].last_hit_id);
689 return 1;
690}
691
692int _STATUS_SET_LOCKON_DIST(RS_STACKDATA *stack, int argc) {
693 int monster_no = NowMonstorUnit->current_monster;
694
695 NowMonstorUnit->monster[monster_no].lock_range = GetStackFloat(stack);
696 return 1;
697}
698
699int _STATUS_SET_SHADOW_LEN(RS_STACKDATA *stack, int argc) {
700 int monster_no = NowMonstorUnit->current_monster;
701
702 NowMonstorUnit->monster[monster_no].shadow_length = GetStackFloat(stack);
703 return 1;
704}
705
706int _STATUS_SET_LOCKON_TRG(RS_STACKDATA *stack, int argc) {
707 char *name;
708 int monster_no = NowMonstorUnit->current_monster;
709 float scale_x = 1.0f;
710 float scale_y = scale_x;
711 CFrame *frame;
712
713 name = GetStackString(stack++);
714
715 if (argc == 3) {
716 scale_x = GetStackFloat(stack++);
717 scale_y = GetStackFloat(stack);
718 }
719
720 frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
721
722 if (frame == NULL) {
723 printf("lock:NofFountNull %s\n", name);
724 } else {
725 NowMonstorUnit->monster[monster_no].lockon_frame = frame;
726 NowMonstorUnit->monster[monster_no].lockon_scale_x = scale_x;
727 NowMonstorUnit->monster[monster_no].lockon_scale_y = scale_y;
728 }
729
730 return 1;
731}
732
733int _SET_MOV_COL(RS_STACKDATA *stack, int argc) {
734 char *name = GetStackString(stack++);
735 float radius = GetStackFloat(stack);
736 int i;
737 int monster_no = NowMonstorUnit->current_monster;
738
739 for (i = 0; i < 12; i++) {
740 if (NowMonstorUnit->effect3[monster_no].timer[i] == 0) {
741 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
742
743 if (frame != NULL) {
744 NowMonstorUnit->effect3[monster_no].timer[i] = 1;
745 NowMonstorUnit->effect3[monster_no].frame[i] = frame;
746 NowMonstorUnit->effect3[monster_no].radius[i] = radius;
747 NowMonstorUnit->effect3[monster_no].count++;
748 break;
749 }
750
751 printf("[%d]mov col -> %s\n", NowMonstorUnit->monster[monster_no].base_model, name);
752 }
753 }
754
755 return 1;
756}
757
758int _SET_BODY_COL(RS_STACKDATA *stack, int argc) {
759 char *name = GetStackString(stack++);
760 float radius = GetStackFloat(stack++);
761 float start = 0.0f;
762 float end = 0.0f;
763 int i;
764 int monster_no;
765 int j;
766
767 if (argc == 4) {
768 start = GetStackFloat(stack++);
769 end = GetStackFloat(stack);
770 }
771
772 monster_no = NowMonstorUnit->current_monster;
773
774 for (i = 0; i < 16; i++) {
775 if (NowMonstorUnit->effect[monster_no].timer[i] == 0) {
776 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
777
778 if (frame != NULL) {
779 NowMonstorUnit->effect[monster_no].timer[i] = 1;
780 NowMonstorUnit->effect[monster_no].frame[i] = frame;
781 NowMonstorUnit->effect[monster_no].radius[i] = radius;
782 NowMonstorUnit->effect[monster_no].motion_start[i] = start;
783 NowMonstorUnit->effect[monster_no].motion_end[i] = end;
784
785 for (j = 0; j < 5; j++) {
786 NowMonstorUnit->effect[monster_no].body_parameter[i][j] = 100;
787 }
788
789 for (j = 0; j < 6; j++) {
790 NowMonstorUnit->effect[monster_no].parameter[i][j] = 100;
791 }
792
793 bak_ColNo = i;
794 break;
795 }
796
797 printf("[%d]body col -> %s\n", NowMonstorUnit->monster[monster_no].base_model, name);
798 bak_ColNo = -1;
799 }
800 }
801
802 return 1;
803}
804
805int _SET_BODY_COL_PARA(RS_STACKDATA *stack, int argc) {
806 int parameter_no = GetStackInt(stack++);
807 int value = GetStackInt(stack);
808 int monster_no = NowMonstorUnit->GetCurrentMonsterIndex();
809
810 if (bak_ColNo == -1) {
811 return 1;
812 }
813
814 if (parameter_no <= 9) {
815 NowMonstorUnit->effect[monster_no].body_parameter[bak_ColNo][parameter_no] = value;
816 }
817
818 if (parameter_no >= 10) {
819 NowMonstorUnit->effect[monster_no].parameter[bak_ColNo][parameter_no - 10] = value;
820 }
821
822 return 1;
823}
824
825int _SET_DMG_COL(RS_STACKDATA *stack, int argc) {
826 char *name = GetStackString(stack++);
827 float radius = GetStackFloat(stack++);
828 float start = GetStackFloat(stack++);
829 float end = GetStackFloat(stack);
830 int i;
831 int monster_no = NowMonstorUnit->current_monster;
832
833 for (i = 0; i < 16; i++) {
834 if (NowMonstorUnit->effect2[monster_no].active[i] == 0) {
835 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
836
837 if (frame != NULL) {
838 NowMonstorUnit->effect2[monster_no].active[i] = 1;
839 NowMonstorUnit->effect2[monster_no].frame[i] = frame;
840 NowMonstorUnit->effect2[monster_no].radius[i] = radius;
841 NowMonstorUnit->effect2[monster_no].motion_start[i] = start;
842 NowMonstorUnit->effect2[monster_no].motion_end[i] = end;
843 NowMonstorUnit->effect2[monster_no].last_slot = i;
844 break;
845 }
846
847 printf("[%d] dcol -> %s\n", NowMonstorUnit->monster[monster_no].base_model, name);
848 NowMonstorUnit->effect2[monster_no].last_slot = -1;
849 return 1;
850 }
851 }
852
853 return 1;
854}
855
856int _SET_DMG_PARA(RS_STACKDATA *stack, int argc) {
857 int monster_no = NowMonstorUnit->current_monster;
858 int slot = NowMonstorUnit->effect2[monster_no].last_slot;
859
860 if (slot != -1) {
861 NowMonstorUnit->effect2[monster_no].damage[slot] = GetStackInt(stack++);
862 NowMonstorUnit->effect2[monster_no].flags[slot] = GetStackInt(stack++);
863 NowMonstorUnit->effect2[monster_no].kind[slot] = GetStackInt(stack++);
864 NowMonstorUnit->effect2[monster_no].angle[slot] = 0.0f;
865
866 if (NowMonstorUnit->effect2[monster_no].kind[slot] == 3 && argc == 4) {
867 NowMonstorUnit->effect2[monster_no].angle[slot] = GetStackFloat(stack);
868 }
869 }
870
871 return 1;
872}
873
874int _SET_SHOT(RS_STACKDATA *stack, int argc) {
875 int monster_no = NowMonstorUnit->current_monster;
876 char *name;
877
878 if (NowMonstorUnit->monster[monster_no].shot_effect == -1) {
879 return 1;
880 }
881
882 name = GetStackString(stack++);
883 NowMonstorUnit->event[monster_no].local_position[0] = GetStackFloat(stack++);
884 NowMonstorUnit->event[monster_no].local_position[1] = GetStackFloat(stack++);
885 NowMonstorUnit->event[monster_no].local_position[2] = GetStackFloat(stack++);
886 NowMonstorUnit->event[monster_no].local_position[3] = 1.0f;
887
888 if (NowMonstorUnit->event[monster_no].timer == 0) {
889 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
890
891 if (frame == NULL) {
892 printf("not shot null !!\n");
893 return 1;
894 }
895
896 NowMonstorUnit->event[monster_no].frame = frame;
897 NowMonstorUnit->event[monster_no].timer = 1;
898 }
899
900 NowMonstorUnit->event[monster_no].damage_override = -1;
901
902 if (argc == 5) {
903 NowMonstorUnit->event[monster_no].damage_override = GetStackInt(stack);
904 }
905
906 return 1;
907}
908
909int _SET_SHOT2(RS_STACKDATA *stack, int argc) {
910 int monster_no = NowMonstorUnit->current_monster;
911 char *name;
912
913 if (NowMonstorUnit->monster[monster_no].shot_effect2 == -1) {
914 return 1;
915 }
916
917 printf("shot !!\n");
918 name = GetStackString(stack++);
919 NowMonstorUnit->event2[monster_no].local_position[0] = GetStackFloat(stack++);
920 NowMonstorUnit->event2[monster_no].local_position[1] = GetStackFloat(stack++);
921 NowMonstorUnit->event2[monster_no].local_position[2] = GetStackFloat(stack++);
922 NowMonstorUnit->event2[monster_no].local_position[3] = 1.0f;
923
924 if (NowMonstorUnit->event2[monster_no].timer == 0) {
925 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(name);
926
927 if (frame == NULL) {
928 printf("not shot null !!\n");
929 return 1;
930 }
931
932 NowMonstorUnit->event2[monster_no].frame = frame;
933 NowMonstorUnit->event2[monster_no].timer = 1;
934 }
935
936 NowMonstorUnit->event2[monster_no].damage_override = -1;
937
938 if (argc == 5) {
939 NowMonstorUnit->event2[monster_no].damage_override = GetStackInt(stack);
940 }
941
942 return 1;
943}
944
945int _SET_SND_FRM(RS_STACKDATA *stack, int argc) {
946 int slot;
947 int i;
948 int monster_no = NowMonstorUnit->current_monster;
949
950 slot = -1;
951
952 for (i = 0; i < 16; i++) {
953 if (NowMonstorUnit->sound[monster_no].id[i] == -1) {
954 if (NowMonstorUnit->sound[monster_no].cooldown[i] == 0) {
955 slot = i;
956 }
957
958 break;
959 }
960 }
961
962 if (slot == -1) {
963 return 1;
964 }
965
966 NowMonstorUnit->sound[monster_no].start[slot] = GetStackFloat(stack++);
967 NowMonstorUnit->sound[monster_no].end[slot] = GetStackFloat(stack++);
968 NowMonstorUnit->sound[monster_no].id[slot] = GetStackInt(stack);
969 return 1;
970}
971
972int _SET_LOOP_SND(RS_STACKDATA *stack, int argc) {
973 int monster_no = NowMonstorUnit->current_monster;
974
975 NowMonstorUnit->sound[monster_no].sequence_start = GetStackFloat(stack++);
976 NowMonstorUnit->sound[monster_no].sequence_end = GetStackFloat(stack++);
977 NowMonstorUnit->sound[monster_no].sequence_step = GetStackInt(stack++);
978 NowMonstorUnit->sound[monster_no].sequence_id = GetStackInt(stack);
979 return 1;
980}
981
982int _STOP_LOOP_SND(RS_STACKDATA *stack, int argc) {
983 int monster_no = NowMonstorUnit->current_monster;
984 int sound_id = NowMonstorUnit->sound[monster_no].sequence_id;
985
986 if (sound_id == -1) {
987 return 1;
988 }
989
990 NowMonstorUnit->sound[monster_no].sequence_id = -1;
991 SndSeStop(sound_id, monster_no * 2);
992 return 1;
993}
994
995int _DEL_LOOP_SND(RS_STACKDATA *stack, int argc) {
996 // The sound keeps playing; the monster just stops owning it.
997 int monster_no = NowMonstorUnit->current_monster;
998
999 NowMonstorUnit->sound[monster_no].sequence_id = -1;
1000 return 1;
1001}
1002
1003int _SET_SND_NOW(RS_STACKDATA *stack, int argc) {
1004 SndSePlay(GetStackInt(stack), -1, 0);
1005 return 1;
1006}
1007
1008int _STOP_SND_NOW(RS_STACKDATA *stack, int argc) {
1009 SndSeStop(GetStackInt(stack), 0);
1010 return 1;
1011}
1012
1013int _GET_CHR_ID(RS_STACKDATA *stack, int argc) {
1014 SetStack(stack, (int) UserStatus->cur_chara);
1015 return 1;
1016}
1017
1018int _GET_COL_HIT_ID(RS_STACKDATA *stack, int argc) {
1019 SetStack(stack, NowMonstorUnit->effect[NowMonstorUnit->current_monster].hit_slot);
1020 return 1;
1021}
1022
1023int _GET_SCRIPT_ID(RS_STACKDATA *stack, int argc) {
1024 SetStack(stack, NowMonstorUnit->current_monster);
1025 return 1;
1026}
1027
1028int _GET_MONSTOR_POS(RS_STACKDATA *stack, int argc) {
1029 float position[4];
1030
1031 NowMonstorUnit->chara[GetStackInt(stack++)][0].GetPosition(position);
1032 SetStack(stack++, position[0]);
1033 SetStack(stack++, position[1]);
1034 SetStack(stack, position[2]);
1035 return 1;
1036}
1037
1038int _GET_MONSTOR_FRM(RS_STACKDATA *stack, int argc) {
1039 int monster_no = GetStackInt(stack++);
1040
1041 float frame = NowMonstorUnit->chara[monster_no][0].motion_type.state.time;
1042
1043 SetStack(stack, frame);
1044 return 1;
1045}
1046
1047int _SET_MONSTOR_POS(RS_STACKDATA *stack, int argc) {
1048 int monster_no = GetStackInt(stack++);
1049 float position[4];
1050
1051 position[0] = GetStackFloat(stack++);
1052 position[1] = GetStackFloat(stack++);
1053 position[2] = GetStackFloat(stack);
1054 NowMonstorUnit->chara[monster_no][0].SetPosition(position);
1055 return 1;
1056}
1057
1058int _SET_MONSTOR_MOVE(RS_STACKDATA *stack, int argc) {
1059 int monster_no = GetStackInt(stack++);
1060 float direction[4];
1061 float position[4];
1062
1063 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1064 direction[0] = GetStackFloat(stack++);
1065 direction[1] = GetStackFloat(stack++);
1066 direction[2] = GetStackFloat(stack++);
1067 direction[0] -= position[0];
1068 direction[1] -= position[1];
1069 direction[2] -= position[2];
1070 direction[3] = 1.0f;
1071 sceVu0Normalize(NowMonstorUnit->monster[monster_no].movement, direction);
1072 NowMonstorUnit->monster[monster_no].movement_speed = GetStackFloat(stack);
1073 return 1;
1074}
1075
1076int _SET_MONSTOR_LINK_MOVE(RS_STACKDATA *stack, int argc) {
1077 int monster_no = GetStackInt(stack++);
1078 int leader_no = GetStackInt(stack);
1079
1080 sceVu0CopyVector(NowMonstorUnit->monster[monster_no].movement, NowMonstorUnit->monster[leader_no].movement);
1081 NowMonstorUnit->monster[monster_no].movement_speed = NowMonstorUnit->monster[leader_no].movement_speed;
1082 return 1;
1083}
1084
1085int _SET_MONSTOR_MOVE_CANSEL(RS_STACKDATA *stack, int argc) {
1086 int monster_no = GetStackInt(stack);
1087
1088 NowMonstorUnit->monster[monster_no].movement_speed = 0.0f;
1089 return 1;
1090}
1091
1092int _SET_LOCKON_DIST(RS_STACKDATA *stack, int argc) {
1093 int monster_no = NowMonstorUnit->current_monster;
1094
1095 NowMonstorUnit->monster[monster_no].lock_range = GetStackFloat(stack);
1096 return 1;
1097}
1098
1099int _SET_LOCKON_SW(RS_STACKDATA *stack, int argc) {
1100 int monster_no = NowMonstorUnit->current_monster;
1101
1102 NowMonstorUnit->monster[monster_no].lockon_enabled = GetStackInt(stack);
1103 return 1;
1104}
1105
1106int _SET_MONSTOR_MOTION(RS_STACKDATA *stack, int argc) {
1107 int monster_no = GetStackInt(stack++);
1108 int motion_id = GetStackInt(stack++);
1109
1110 NowMonstorUnit->monster[monster_no].last_hit_damage = -1;
1111 NowMonstorUnit->monster[monster_no].requested_motion_speed = -1.0f;
1112
1113 if (argc == 2) {
1114 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, 0);
1115 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
1116 NowMonstorUnit->monster[monster_no].requested_motion_flags = 0;
1117
1118 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
1119 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, 0);
1120 }
1121 }
1122
1123 if (argc == 3) {
1124 float speed = GetStackFloat(stack++);
1125
1126 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, 0);
1127 NowMonstorUnit->chara[monster_no][0].SetMotionSpeed(speed);
1128 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
1129 NowMonstorUnit->monster[monster_no].requested_motion_flags = 0;
1130 NowMonstorUnit->monster[monster_no].requested_motion_speed = speed;
1131
1132 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
1133 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, 0);
1134 NowMonstorUnit->chara[monster_no][i + 1].SetMotionSpeed(speed);
1135 }
1136 }
1137
1138 if (argc == 4) {
1139 float speed = GetStackFloat(stack++);
1140 int mode = GetStackInt(stack);
1141
1142 NowMonstorUnit->chara[monster_no][0].SetMotion(motion_id, mode);
1143 NowMonstorUnit->chara[monster_no][0].SetMotionSpeed(speed);
1144 NowMonstorUnit->monster[monster_no].requested_motion = motion_id;
1145 NowMonstorUnit->monster[monster_no].requested_motion_flags = mode;
1146 NowMonstorUnit->monster[monster_no].requested_motion_speed = speed;
1147
1148 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
1149 NowMonstorUnit->chara[monster_no][i + 1].SetMotion(motion_id, mode);
1150 NowMonstorUnit->chara[monster_no][i + 1].SetMotionSpeed(speed);
1151 }
1152 }
1153
1154 return 1;
1155}
1156
1157int _SET_GLOBAL_INT(RS_STACKDATA *stack, int argc) {
1158 int slot = GetStackInt(stack++);
1159
1160 GL_INT[slot] = GetStackInt(stack);
1161 return 1;
1162}
1163
1164int _GET_GLOBAL_INT(RS_STACKDATA *stack, int argc) {
1165 int slot = GetStackInt(stack++);
1166
1167 SetStack(stack++, GL_INT[slot]);
1168 return 1;
1169}
1170
1174static int _GET_OBJ_POS(RS_STACKDATA *stack, int argc) {
1175 int monster_no = NowMonstorUnit->current_monster;
1176 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame->SearchFrame(GetStackString(stack++));
1177 float local[4];
1178 float world[4];
1179
1180 sceVu0CopyVector(local, frame->position);
1181 frame->GetWorldPosition(world, local);
1182 SetStack(stack++, world[0]);
1183 SetStack(stack++, world[1]);
1184 SetStack(stack, world[2]);
1185 return 1;
1186}
1187
1188int _SET_ROTATION_X(RS_STACKDATA *stack, int argc) {
1189 int monster_no = NowMonstorUnit->current_monster;
1190 float position[4];
1191 float rotation[4];
1192 float direction[4];
1193
1194 NowMonstorUnit->monster[monster_no].turn_target[0] = GetStackFloat(stack++);
1195 NowMonstorUnit->monster[monster_no].turn_target[1] = GetStackFloat(stack++);
1196 NowMonstorUnit->monster[monster_no].turn_target[2] = GetStackFloat(stack);
1197 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1198 NowMonstorUnit->chara[monster_no][0].GetRotation(rotation);
1199 sceVu0SubVector(direction, NowMonstorUnit->monster[monster_no].turn_target, position);
1200 rotation[0] = -atan2f(direction[1], direction[2]);
1201 NowMonstorUnit->chara[monster_no][0].SetRotation(rotation);
1202 return 1;
1203}
1204
1205int _LOOKAT(RS_STACKDATA *stack, int argc) {
1206 int axis;
1207 int monster_no = NowMonstorUnit->current_monster;
1208 float position[4];
1209 float rotation[4];
1210 sceVu0FMATRIX matrix;
1211 float direction[4];
1212 float x_axis[4];
1213 float y_axis[4];
1214 float z_axis[4];
1215
1216 NowMonstorUnit->monster[monster_no].turn_target[0] = GetStackFloat(stack++);
1217 NowMonstorUnit->monster[monster_no].turn_target[1] = GetStackFloat(stack++);
1218 NowMonstorUnit->monster[monster_no].turn_target[2] = GetStackFloat(stack++);
1219 axis = GetStackInt(stack);
1220 sceVu0UnitMatrix(matrix);
1221 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1222 NowMonstorUnit->chara[monster_no][0].GetRotation(rotation);
1223 sceVu0CopyMatrix(matrix, NowMonstorUnit->chara[monster_no][0].frame->local);
1224 sceVu0SubVector(direction, NowMonstorUnit->monster[monster_no].turn_target, position);
1225
1226 if (axis == 0) {
1227 sceVu0Normalize(x_axis, direction);
1228 sceVu0OuterProduct(z_axis, x_axis, matrix[1]);
1229 sceVu0OuterProduct(y_axis, x_axis, z_axis);
1230 sceVu0CopyVector(matrix[0], x_axis);
1231 sceVu0CopyVector(matrix[1], y_axis);
1232 sceVu0CopyVector(matrix[2], z_axis);
1233 NowMonstorUnit->chara[monster_no][0].frame->SetTransMatrix(matrix);
1234 }
1235
1236 if (axis == 1) {
1237 sceVu0Normalize(y_axis, direction);
1238 sceVu0OuterProduct(x_axis, y_axis, matrix[2]);
1239 sceVu0OuterProduct(z_axis, x_axis, z_axis);
1240 sceVu0CopyVector(matrix[0], x_axis);
1241 sceVu0CopyVector(matrix[1], y_axis);
1242 sceVu0CopyVector(matrix[2], z_axis);
1243 NowMonstorUnit->chara[monster_no][0].frame->SetTransMatrix(matrix);
1244 }
1245
1246 if (axis == 2) {
1247 sceVu0Normalize(z_axis, direction);
1248 sceVu0OuterProduct(x_axis, z_axis, matrix[1]);
1249 sceVu0OuterProduct(y_axis, x_axis, z_axis);
1250 sceVu0CopyVector(matrix[0], x_axis);
1251 sceVu0CopyVector(matrix[1], y_axis);
1252 sceVu0CopyVector(matrix[2], z_axis);
1253 NowMonstorUnit->chara[monster_no][0].frame->SetTransMatrix(matrix);
1254 }
1255
1256 return 1;
1257}
1258
1259int _SET_MOTION_CHANGE_STEP(RS_STACKDATA *stack, int argc) {
1260 int monster_no = NowMonstorUnit->current_monster;
1261 float step = GetStackFloat(stack);
1262
1263 NowMonstorUnit->chara[monster_no][0].motion_type.state.blend_step = step;
1264
1265 for (int i = 0; i < NowMonstorUnit->monster[monster_no].attachment_count; i++) {
1266 NowMonstorUnit->chara[monster_no][i + 1].motion_type.state.blend_step = step;
1267 }
1268
1269 return 1;
1270}
1271
1272int _GET_MONSTOR_VECTOR(RS_STACKDATA *stack, int argc) {
1273 int monster_no = GetStackInt(stack++);
1274 float angle = 0.0f;
1275 float direction[4];
1276 float position[4];
1277 float turn_matrix[4][4];
1278 float identity[4][4];
1279
1280 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1281 direction[0] = GetStackFloat(stack++);
1282 direction[1] = GetStackFloat(stack++);
1283 direction[2] = GetStackFloat(stack++);
1284 direction[3] = 1.0f;
1285
1286 if (argc == 8) {
1287 angle = GetStackFloat(stack++);
1288
1289 if (angle >= 180.0f) {
1290 angle -= 360.0f;
1291 }
1292
1293 angle = DEG_TO_RAD * angle;
1294
1295 if (angle > TWO_PI) {
1296 angle -= TWO_PI;
1297 }
1298
1299 if (angle < -PI) {
1300 angle += TWO_PI;
1301 }
1302 }
1303
1304 direction[0] -= position[0];
1305 direction[1] -= position[1];
1306 direction[2] -= position[2];
1307 sceVu0Normalize(direction, direction);
1308
1309 if (argc == 8) {
1310 sceVu0UnitMatrix(identity);
1311 sceVu0RotMatrixY(turn_matrix, identity, angle);
1312 sceVu0ApplyMatrix(direction, turn_matrix, direction);
1313 }
1314
1315 SetStack(stack++, direction[0]);
1316 SetStack(stack++, direction[1]);
1317 SetStack(stack, direction[2]);
1318 return 1;
1319}
1320
1321int _STATUS_SET_LIFE(RS_STACKDATA *stack, int argc) {
1322 int monster_no = NowMonstorUnit->current_monster;
1323 float rate = GetStackFloat(stack);
1324
1325 NowMonstorUnit->monster[monster_no].hp = (int) (NowMonstorUnit->monster[monster_no].max_hp * rate);
1326 return 1;
1327}
1328
1329int _SET_BIN2(RS_STACKDATA *stack, int argc) {
1330 int monster_no = NowMonstorUnit->current_monster;
1331
1332 NowMonstorUnit->monster[monster_no].anger_timer = GetStackInt(stack);
1333 return 1;
1334}
1335
1336int _SET_STATUS_CHANGE(RS_STACKDATA *stack, int argc) {
1337 int kind = GetStackInt(stack++);
1338 int weight = GetStackInt(stack++);
1339 int monster_no = GetStackInt(stack);
1340
1341 if (monster_no < 0 || monster_no > 15) {
1342 return 1;
1343 }
1344
1345 if (kind < 0 || kind > 4) {
1346 kind = 0;
1347 }
1348
1349 NowMonstorUnit->monster[monster_no].attachment_weight[kind] = weight;
1350 return 1;
1351}
1352
1353int _SET_TEX_ANIME_SW(RS_STACKDATA *stack, int argc) {
1354 int anime_no = GetStackInt(stack++);
1355 int enable = GetStackInt(stack++);
1356 int monster_no = GetStackInt(stack);
1357
1358 if (monster_no < 0 || monster_no > 15) {
1359 return 2;
1360 }
1361
1362 if (enable) {
1363 NowMonstorUnit->chara[monster_no][0].TexAnimeOn(anime_no);
1364 printf("animOn %d\n", anime_no);
1365 } else {
1366 NowMonstorUnit->chara[monster_no][0].TexAnimeOff(anime_no);
1367 printf("animOff %d\n", anime_no);
1368 }
1369
1370 return 1;
1371}
1372
1373int _GET_STATUS_BIN2(RS_STACKDATA *stack, int argc) {
1374 int monster_no = NowMonstorUnit->current_monster;
1375 int flags = NowMonstorUnit->monster[monster_no].anger_timer;
1376
1377 NowMonstorUnit->monster[monster_no].anger_timer = flags;
1378 SetStack(stack, flags);
1379 return 1;
1380}
1381
1382int _SET_COLLISION_WIDTH(RS_STACKDATA *stack, int argc) {
1383 int monster_no = NowMonstorUnit->current_monster;
1384
1385 NowMonstorUnit->monster[monster_no].collision_radius = GetStackFloat(stack);
1386 return 1;
1387}
1388
1389int _GET_NEAR_MONSTER(RS_STACKDATA *stack, int argc) {
1390 int found;
1391 int i;
1392 int monster_no = NowMonstorUnit->current_monster;
1393 float nearest = 240.0f;
1394 float position[4];
1395 float other_position[4];
1396 float found_position[4];
1397
1398 found = -1;
1399 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1400
1401 for (i = 0; i < 16; i++) {
1402 if (i != monster_no && NowMonstorUnit->monster[i].state == 2) {
1403 NowMonstorUnit->chara[i][0].GetPosition(other_position);
1404 float distance = DistVector(position, other_position);
1405
1406 if (distance < nearest) {
1407 sceVu0CopyVector(found_position, other_position);
1408 nearest = distance;
1409 found = i;
1410 }
1411 }
1412 }
1413
1414 SetStack(stack++, found_position[0]);
1415 SetStack(stack++, found_position[1]);
1416 SetStack(stack++, found_position[2]);
1417 SetStack(stack, found);
1418 PORT_RETURN(1);
1419}
1420
1421int _BOSS_FADE_OUT(RS_STACKDATA *stack, int argc) {
1422 EdFadeInit();
1423 EdFadeOut(120, 0.0f, 0.0f, 0.0f);
1424 BtActStatus.can_act = 0;
1425 BtActStatus.movement_locked = 1;
1426 return 1;
1427}
1428
1429int _CHEKC_FADE_OUT(RS_STACKDATA *stack, int argc) {
1430 int done = EdFadeOutCheck();
1431
1432 SetStack(stack, done);
1433 return 1;
1434}
1435
1436int _SET_GRAVITY(RS_STACKDATA *stack, int argc) {
1437 int monster_no = NowMonstorUnit->current_monster;
1438
1439 NowMonstorUnit->monster[monster_no].free_fall = GetStackInt(stack);
1440 return 1;
1441}
1442
1443int _SET_GUARD_FRAME(RS_STACKDATA *stack, int argc) {
1444 int start;
1445 int monster_no = NowMonstorUnit->current_monster;
1446 int end;
1447 int slot;
1448
1449 start = (int) GetStackFloat(stack++);
1450 end = (int) GetStackFloat(stack);
1451 slot = -1;
1452
1453 for (int i = 0; i < 3; i++) {
1454 if (NowMonstorUnit->guard[monster_no].active[i] == 0) {
1455 slot = i;
1456 break;
1457 }
1458 }
1459
1460 if (slot == -1) {
1461 return 1;
1462 }
1463
1464 NowMonstorUnit->guard[monster_no].active[slot] = 1;
1465 NowMonstorUnit->guard[monster_no].motion_start[slot] = start;
1466 NowMonstorUnit->guard[monster_no].motion_end[slot] = end;
1467 return 1;
1468}
1469
1470int _GUARD_SEARCH(RS_STACKDATA *stack, int argc) {
1471 int monster_no = NowMonstorUnit->current_monster;
1472 float player[4];
1473 float position[4];
1474 float direction[4];
1475 float distance;
1476
1477 sceVu0CopyVector(player, CharaMain.pos);
1478 NowMonstorUnit->chara[monster_no][0].GetPosition(position);
1479 distance = DistVector(player, position);
1480 direction[0] = position[0] - player[0];
1481 direction[1] = 0.0f;
1482 direction[2] = position[2] - player[2];
1483 direction[3] = 1.0f;
1484 sceVu0Normalize(direction, direction);
1485
1486 if (sceVu0InnerProduct(BtActStatus.input_direction, direction) >= 0.35) {
1487 BtActStatus.frames_since_attack = 3600;
1488 }
1489
1490 SetStack(stack++, BtActStatus.frames_since_attack);
1491 SetStack(stack++, distance);
1492 SetStack(stack, UserStatus->cur_chara);
1493 return 1;
1494}
1495
1496int _GET_MOVE_VEC(RS_STACKDATA *stack, int argc) {
1497 SetStack(stack++, BtActStatus.script_move_vector[0]);
1498 SetStack(stack++, BtActStatus.script_move_vector[1]);
1499 SetStack(stack, BtActStatus.script_move_vector[2]);
1500 return 1;
1501}
1502
1503int _PUSH_IGLOBAL(RS_STACKDATA *stack, int argc) {
1504 int slot;
1505 int monster_no = NowMonstorUnit->current_monster;
1506
1507 slot = GetStackInt(stack++);
1508
1509 if (slot < 0 || slot > 7) {
1510 return 0;
1511 }
1512
1513 PUSH_INT_DATA[monster_no][slot] = GetStackInt(stack);
1514 return 1;
1515}
1516
1517int _POP_IGLOBAL(RS_STACKDATA *stack, int argc) {
1518 int slot;
1519 int monster_no = NowMonstorUnit->current_monster;
1520
1521 slot = GetStackInt(stack++);
1522
1523 if (slot < 0 || slot > 7) {
1524 return 0;
1525 }
1526
1527 SetStack(stack++, PUSH_INT_DATA[monster_no][slot]);
1528 return 1;
1529}
1530
1531int _GET_USER_STATUS(RS_STACKDATA *stack, int argc) {
1532 int kind = GetStackInt(stack++);
1533 int chara = UserStatus->cur_chara;
1534 int ailment = 0;
1535
1536 if (UserStatus->ailments[chara] != 0 && kind != 0) {
1537 ailment = UserStatus->ailment_frames[chara];
1538 }
1539
1540 SetStack(stack, ailment);
1541 return 1;
1542}
1543
1544int _SET_REFERENCE(RS_STACKDATA *stack, int argc) {
1545 int monster_no = NowMonstorUnit->current_monster;
1546 int target_no = GetStackInt(stack++);
1547 char *name = GetStackString(stack);
1548 CFrame *frame;
1549 CFrame *anchor;
1550
1551 if (name == NULL) {
1552 return 1;
1553 }
1554
1555 frame = NowMonstorUnit->chara[monster_no][0].frame;
1556 anchor = NowMonstorUnit->chara[target_no][0].frame->SearchFrame(name);
1557
1558 if (anchor == NULL) {
1559 return 1;
1560 }
1561
1562 frame->SetReference(anchor);
1563 return 1;
1564}
1565
1566int _DEL_REFERENCE(RS_STACKDATA *stack, int argc) {
1567 int monster_no = GetStackInt(stack);
1568 CFrame *frame = NowMonstorUnit->chara[monster_no][0].frame;
1569
1570 if (frame == NULL) {
1571 return 1;
1572 }
1573
1574 frame->DeleteReference();
1575 return 1;
1576}
1577
1578int _SET_SHADOW_FLAG(RS_STACKDATA *stack, int argc) {
1579 int monster_no = NowMonstorUnit->current_monster;
1580
1581 NowMonstorUnit->monster[monster_no].shadow_enabled = GetStackInt(stack);
1582 return 1;
1583}
1584
1585int BtSetEventScript(CRunScript *script, char *program, CDataAlloc2<1> *arena) {
1586 RS_STACKDATA *stack = (RS_STACKDATA *) arena->Alloc(64);
1587
1588 script->load((RS_PROG_HEADER *) program, stack, 128, (RS_CALLDATA *) arena->Alloc(384), 512);
1589 script->ext_func(ext_func, 256);
1590 return 1;
1591}
1592
1596static BT_EVENT_EXTERNAL_FUNCTION ext_func_info[] = {
1597 {_GET_DISTANCE, 10 },
1598 {_GET_POSITION, 11 },
1599 {_SET_ROTATION, 12 },
1600 {_CHK_ROTATION, 13 },
1601 {_CHK_MOVE, 14 },
1602 {_CHK_USER_INNER_PRODUCT, 15 },
1603 {_GET_VECTOR, 30 },
1604 {_GET_DIRECTION, 31 },
1605 {_SET_MOVE, 32 },
1606 {_CHK_MOVE_INFO, 33 },
1607 {_SET_MOVE_CANSEL, 34 },
1608 {_SET_ROT_CANSEL, 35 },
1609 {_SET_POSITION, 36 },
1610 {_STATUS_SET_FALL, 100},
1611 {_STATUS_SET_MUTEKI, 101},
1612 {_STATUS_SET_ALPHA, 102},
1613 {_STATUS_CHK_ALPHA, 103},
1614 {_STATUS_SET_DEAD, 104},
1615 {_STATUS_SET_PALLET, 105},
1616 {_GET_RAND, 180},
1617 {_GET_RANDF, 181},
1618 {_SIN_DEG, 182},
1619 {_COS_DEG, 183},
1620 {_STATUS_SET_CLIPLEVEL, 106},
1621 {_STATUS_SET_EVENT, 107},
1622 {_STATUS_SET_COL_OFF, 108},
1623 {_STATUS_GET_LIFE_RATE, 109},
1624 {_STATUS_GET_HEIGHT, 112},
1625 {_STATUS_GET_HITDMG_VOL, 113},
1626 {_STATUS_GET_MOTION_ID, 114},
1627 {_STATUS_GET_DMG_ID, 115},
1628 {_STATUS_SET_LOCKON_DIST, 116},
1629 {_STATUS_SET_SHADOW_LEN, 117},
1630 {_STATUS_SET_LOCKON_TRG, 118},
1631 {_STATUS_GET_USER_VECTOR, 110},
1632 {_SET_MOV_COL, 136},
1633 {_SET_BODY_COL, 130},
1634 {_SET_BODY_COL_PARA, 134},
1635 {_SET_DMG_COL, 131},
1636 {_SET_DMG_PARA, 132},
1637 {_SET_SHOT, 133},
1638 {_SET_SHOT2, 229},
1639 {_SET_SND_FRM, 140},
1640 {_SET_LOOP_SND, 230},
1641 {_STOP_LOOP_SND, 231},
1642 {_DEL_LOOP_SND, 232},
1643 {_SET_SND_NOW, 141},
1644 {_SET_MOTION, 200},
1645 {_CHK_MOTION_FRM, 201},
1646 {_GET_MOTION_FRM, 202},
1647 {_SET_MOTION_FRM, 203},
1648 {_GET_CHR_ID, 210},
1649 {_GET_COL_HIT_ID, 211},
1650 {_GET_SCRIPT_ID, 212},
1651 {_GET_MONSTOR_POS, 213},
1652 {_RUN_SCRIPT, 111},
1653 {_GET_MONSTOR_FRM, 214},
1654 {_SET_MONSTOR_POS, 215},
1655 {_SET_MONSTOR_MOVE, 216},
1656 {_SET_MONSTOR_LINK_MOVE, 217},
1657 {_SET_MONSTOR_MOVE_CANSEL, 218},
1658 {_SET_MONSTOR_MOTION, 219},
1659 {_SET_GLOBAL_INT, 220},
1660 {_GET_GLOBAL_INT, 221},
1661 {_GET_OBJ_POS, 222},
1662 {_SET_ROTATION_X, 223},
1663 {_SET_MOTION_CHANGE_STEP, 224},
1664 {_GET_MONSTOR_VECTOR, 225},
1665 {_SET_LOCKON_DIST, 226},
1666 {_SET_LOCKON_SW, 227},
1667 {_STOP_SND_NOW, 142},
1668 {_STATUS_SET_LIFE, 228},
1669 {_SET_BIN2, 209},
1670 {_SET_STATUS_CHANGE, 204},
1671 {_SET_TEX_ANIME_SW, 205},
1672 {_GET_STATUS_BIN2, 208},
1673 {_SET_COLLISION_WIDTH, 206},
1674 {_GET_NEAR_MONSTER, 207},
1675 {_BOSS_FADE_OUT, 240},
1676 {_CHEKC_FADE_OUT, 241},
1677 {_SET_GRAVITY, 242},
1678 {_SET_GUARD_FRAME, 244},
1679 {_GUARD_SEARCH, 245},
1680 {_GET_MOVE_VEC, 246},
1681 {_PUSH_IGLOBAL, 247},
1682 {_POP_IGLOBAL, 248},
1683 {_GET_USER_STATUS, 249},
1684 {_SET_REFERENCE, 250},
1685 {_DEL_REFERENCE, 251},
1686 {_LOOKAT, 252},
1687 {_SET_SHADOW_FLAG, 253},
1688 {NULL, -1 },
1689};
1690
1691void BtSetEventExtendTable() {
1692 int i;
1693
1694 for (i = 0; i < 256; i++) {
1695 ext_func[i] = NULL;
1696 }
1697
1698 for (i = 0;; i++) {
1699 if (ext_func_info[i].function == NULL) {
1700 break;
1701 }
1702
1703 int j;
1704
1705 for (j = 0; j < i; j++) {
1706 if (ext_func_info[i].operation == ext_func_info[j].operation) {
1707 printf("same ext_func_no!!!\n");
1708
1709 while (1) {
1710 }
1711 }
1712 }
1713
1714 int operation = ext_func_info[i].operation;
1715
1716 if (operation < 0 || operation >= 256) {
1717 printf("ext func over!!");
1718 } else {
1719 ext_func[operation] = ext_func_info[i].function;
1720 }
1721 }
1722}
sceVu0FVECTOR position
Definition frame.hpp:76
MONSTOR_EVENT_STATE event2[16]
int GetCurrentMonsterIndex()
MONSTOR_EFFECT_STATE effect[16]
MONSTOR_EFFECT_STATE2 effect2[16]
MONSTOR_GUARD_WINDOW guard[16]
CMonstorChara chara[16]
MONSTOR_EVENT_STATE event[16]
MONSTOR_SOUND sound[16]
MONSTOR monster[16]
MONSTOR_EFFECT_STATE3 effect3[16]
float pos[4]
Definition object.hpp:18
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)
s32 ailments[6]
s16 ailment_frames[6]
sceVu0FVECTOR input_direction
sceVu0FVECTOR script_move_vector
int(* function)(RS_STACKDATA *, int)
sceVu0FVECTOR local_position
float start[16]
s16 attachment_weight[5]
float palette_step
s32 invincible_timer
s32 last_hit_id
CCPoly * collision_poly
s16 shadow_enabled
s32 hit_element
sceVu0FVECTOR palette_target
s16 attachment_count
float requested_motion_speed
float palette_alpha_step
float lockon_scale_y
s32 invincible_blocked
s16 lockon_enabled
s32 slow_timer
s32 palette_delay
s32 collision_poly_count
CFrame * lockon_frame
float turn_speed
sceVu0FVECTOR movement
float shadow_length
float lockon_scale_x
float clip_distance
float movement_speed
s32 last_hit_damage
s16 shot_effect2
float lock_range
s32 base_model
float collision_radius
sceVu0FVECTOR turn_target
float palette_blend
s16 requested_motion
s32 anger_timer
float palette_alpha
s32 collision_off_timer
float ground_distance
s16 requested_motion_flags
s16 shot_effect
s32 palette_cycles
RS_STACKDATA * p
Definition runscript.hpp:83