Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
script_list.c
Go to the documentation of this file.
1#include "common.h"
2#include "hud_element.h"
3
5s32 IsUpdatingScripts = FALSE;
6f32 GlobalTimeRate = 1.0f;
7
8// script_list
18
19// evt
21
22// map_api
25
26// model_api
30
31// npc_api
34
35// msg_api
41
42// player_api
48
49// audio_api
53
54// item_api
56
57// why is this at the end? com section vs bss?
60
63
65
68
69s32 evt_execute_next_command(Evt* script);
70
71void sort_scripts(void) {
72 s32 temp_a0;
73 s32 temp_a1;
74 s32 tempID;
75 Evt* curScript;
76 ScriptList** currentScriptListPtr;
77 s32 i;
78 s32 j;
79 s32 x;
80 s32 numValidScripts = 0;
81 s32* scriptIndexList = gScriptIndexList;
82 s32* scriptIdList = gScriptIdList;
83
84 for (i = 0; i < MAX_SCRIPTS; i++) {
85 curScript = (*gCurrentScriptListPtr)[i];
86 if (curScript != NULL) {
87 if (curScript->stateFlags != 0) {
88 scriptIndexList[numValidScripts] = i;
89 scriptIdList[numValidScripts] = curScript->id;
90 numValidScripts++;
91 }
92 }
93 }
94
95 gScriptListCount = numValidScripts;
96 for (i = 0; i < (x = numValidScripts - 1); i++) {
97 scriptIndexList = gScriptIndexList;
98 currentScriptListPtr = &gCurrentScriptListPtr;
99 scriptIdList = gScriptIdList;
100 for (j = i + 1; j < numValidScripts; j++) {
101 temp_a1 = scriptIndexList[i];
102 temp_a0 = scriptIndexList[j];
103 x = i;
104 if ((**currentScriptListPtr)[temp_a1]->priority > (**currentScriptListPtr)[temp_a0]->priority) {
105 scriptIndexList[i] = temp_a0;
106 scriptIndexList[j] = temp_a1;
107 tempID = scriptIdList[i];
108 scriptIdList[i] = scriptIdList[j];
109 scriptIdList[j] = tempID;
110 }
111 }
112 }
113}
114
115void find_script_labels(Evt* script) {
116 Bytecode* curLine;
117 s32 type;
118 s32 label;
119 s32 numArgs;
120 s32 i;
121 s32 j;
122
123 for (i = 0; i < ARRAY_COUNT(script->labelIndices); i++) {
124 script->labelIndices[i] = -1;
125 script->labelPositions[i] = 0;
126 }
127
128 j = 0;
129 curLine = script->ptrNextLine;
130 while (j < ARRAY_COUNT(script->labelIndices)) {
131 type = *curLine++;
132 numArgs = *curLine++;
133 label = *curLine;
134 curLine += numArgs;
135
136 if (type == 1) {
137 return;
138 }
139
140 if (type == 3) {
141 script->labelIndices[j] = label;
142 script->labelPositions[j] = curLine;
143 j++;
144 }
145 }
146 PANIC();
147}
148
150 s32 i;
151
156 } else {
160 }
161
162 for (i = 0; i < MAX_SCRIPTS; i++) {
163 (*gCurrentScriptListPtr)[i] = NULL;
164 }
165
166 gNumScripts = 0;
168 IsUpdatingScripts = FALSE;
169
170 for (i = 0; i < MAX_MAPVARS; i++) {
171 gMapVars[i] = 0;
172 }
173
174 for (i = 0; i < MAX_MAPFLAGS; i++) {
175 gMapFlags[i] = 0;
176 }
177
180}
181
199
200// enforces current gTimeFreezeMode on newly created script
202 switch (gTimeFreezeMode) {
203 default:
204 case TIME_FREEZE_NONE:
205 case TIME_FREEZE_EXIT:
206 return;
209 return;
210 case TIME_FREEZE_FULL:
213 return;
214 }
215}
216
217Evt* start_script(EvtScript* source, s32 priority, s32 flags) {
218 Evt* newScript;
219 s32 scriptListCount;
220 s32 curScriptIndex;
221 s32 i;
222
223 for (i = 0; i < MAX_SCRIPTS; i++) {
224 if ((*gCurrentScriptListPtr)[i] == NULL) {
225 break;
226 }
227 }
228
229 ASSERT(i < MAX_SCRIPTS);
230 curScriptIndex = i;
231
232 (*gCurrentScriptListPtr)[curScriptIndex] = newScript = heap_malloc(sizeof(*newScript));
233 gNumScripts++;
234 ASSERT(newScript != NULL);
235
236 newScript->stateFlags = flags | EVT_FLAG_ACTIVE;
237 newScript->curOpcode = EVT_OP_INTERNAL_FETCH;
238 newScript->priority = priority;
239 newScript->id = UniqueScriptCounter++;
240 newScript->ptrNextLine = (Bytecode*)source;
241 newScript->ptrFirstLine = (Bytecode*)source;
242 newScript->ptrCurLine = (Bytecode*)source;
243 newScript->userData = NULL;
244 newScript->blockingParent = NULL;
245 newScript->childScript = NULL;
246 newScript->parentScript = NULL;
247 newScript->owner1.actorID = -1;
248 newScript->owner2.npcID = -1;
249 newScript->loopDepth = -1;
250 newScript->switchDepth = -1;
251 newScript->groupFlags = EVT_GROUP_NOT_BATTLE;
252 newScript->ptrSavedPos = NULL;
253 newScript->frameCounter = 0.0f;
254 newScript->unk_158 = 0;
255 newScript->timeScale = GlobalTimeRate;
256
257 scriptListCount = 0;
258
259 for (i = 0; i < ARRAY_COUNT(newScript->varTable); i++) {
260 newScript->varTable[i] = 0;
261 }
262
263 for (i = 0; i < ARRAY_COUNT(newScript->varFlags); i++) {
264 newScript->varFlags[i] = 0;
265 }
266
267 find_script_labels(newScript);
268
270 scriptListCount = gScriptListCount++;
271 gScriptIndexList[scriptListCount] = curScriptIndex;
272 gScriptIdList[scriptListCount] = newScript->id;
273 }
274
275 suspend_frozen_scripts(newScript);
276
277 if (UniqueScriptCounter == 0) {
279 }
280
281 return newScript;
282}
283
284Evt* start_script_in_group(EvtScript* source, u8 priority, u8 flags, u8 groupFlags) {
285 Evt* newScript;
286 s32 scriptListCount;
287 s32 curScriptIndex;
288 s32 i;
289
290 for (i = 0; i < MAX_SCRIPTS; i++) {
291 if ((*gCurrentScriptListPtr)[i] == NULL) {
292 break;
293 }
294 }
295
296 ASSERT(i < MAX_SCRIPTS);
297 curScriptIndex = i;
298
299 (*gCurrentScriptListPtr)[curScriptIndex] = newScript = heap_malloc(sizeof(*newScript));
300 gNumScripts++;
301 ASSERT(newScript != NULL);
302
303 newScript->stateFlags = flags | EVT_FLAG_ACTIVE;
304 newScript->curOpcode = EVT_OP_INTERNAL_FETCH;
305 newScript->priority = priority;
306 newScript->id = UniqueScriptCounter++;
307 newScript->ptrNextLine = (Bytecode*)source;
308 newScript->ptrFirstLine = (Bytecode*)source;
309 newScript->ptrCurLine = (Bytecode*)source;
310 newScript->userData = NULL;
311 newScript->blockingParent = NULL;
312 newScript->childScript = NULL;
313 newScript->parentScript = NULL;
314 newScript->owner1.actorID = -1;
315 newScript->owner2.npcID = -1;
316 newScript->loopDepth = -1;
317 newScript->switchDepth = -1;
318 newScript->groupFlags = groupFlags;
319 newScript->ptrSavedPos = NULL;
320 newScript->frameCounter = 0.0f;
321 newScript->unk_158 = 0;
322 newScript->timeScale = GlobalTimeRate;
323
324 scriptListCount = 0;
325
326 for (i = 0; i < ARRAY_COUNT(newScript->varTable); i++) {
327 newScript->varTable[i] = 0;
328 }
329 for (i = 0; i < ARRAY_COUNT(newScript->varFlags); i++) {
330 newScript->varFlags[i] = 0;
331 }
332
333 find_script_labels(newScript);
334
336 scriptListCount = gScriptListCount++;
337 gScriptIndexList[scriptListCount] = curScriptIndex;
338 gScriptIdList[scriptListCount] = newScript->id;
339 }
340
341 suspend_frozen_scripts(newScript);
342
343 if (UniqueScriptCounter == 0) {
345 }
346
347 return newScript;
348}
349
350Evt* start_child_script(Evt* parentScript, EvtScript* source, s32 flags) {
351 s32 curScriptIndex;
352 s32 scriptListCount;
353 Evt* child;
354 s32 i;
355
356 for (i = 0; i < MAX_SCRIPTS; i++) {
357 if ((*gCurrentScriptListPtr)[i] == NULL) {
358 break;
359 }
360 }
361
362 ASSERT(i < MAX_SCRIPTS);
363 curScriptIndex = i;
364
365 (*gCurrentScriptListPtr)[curScriptIndex] = child = heap_malloc(sizeof(*child));
366 gNumScripts++;
367 ASSERT(child != NULL);
368
369 parentScript->childScript = child;
370 parentScript->stateFlags |= EVT_FLAG_BLOCKED_BY_CHILD;
372 child->ptrCurLine = child->ptrFirstLine = child->ptrNextLine = (Bytecode*)source;
373
375 child->userData = NULL;
376 child->blockingParent = parentScript;
377 child->childScript = NULL;
378 child->parentScript = NULL;
379 child->priority = parentScript->priority + 1;
380 child->id = UniqueScriptCounter++;
381 child->owner1 = parentScript->owner1;
382 child->owner2 = parentScript->owner2;
383 child->loopDepth = -1;
384 child->switchDepth = -1;
385 child->groupFlags = parentScript->groupFlags;
386 child->ptrSavedPos = NULL;
387 child->array = parentScript->array;
388 child->flagArray = parentScript->flagArray;
389 child->timeScale = GlobalTimeRate;
390 child->frameCounter = 0.0f;
391 child->unk_158 = 0;
392
393 scriptListCount = 0;
394
395 for (i = 0; i < ARRAY_COUNT(child->varTable); i++) {
396 child->varTable[i] = parentScript->varTable[i];
397 }
398
399 for (i = 0; i < ARRAY_COUNT(child->varFlags); i++) {
400 child->varFlags[i] = parentScript->varFlags[i];
401 }
402
403 find_script_labels(child);
404 if (IsUpdatingScripts) {
405 scriptListCount = gScriptListCount++;
406 gScriptIndexList[scriptListCount] = curScriptIndex;
407 gScriptIdList[scriptListCount] = child->id;
408 }
409
411
412 if (UniqueScriptCounter == 0) {
414 }
415
416 return child;
417}
418
419Evt* func_802C39F8(Evt* parentScript, Bytecode* nextLine, s32 newState) {
420 Evt* child;
421 s32 curScriptIndex;
422 s32 i;
423 s32 scriptListCount;
424
425 for (i = 0; i < MAX_SCRIPTS; i++) {
426 if ((*gCurrentScriptListPtr)[i] == NULL) {
427 break;
428 }
429 }
430
431 ASSERT(i < MAX_SCRIPTS);
432 curScriptIndex = i;
433
434 (*gCurrentScriptListPtr)[curScriptIndex] = child = heap_malloc(sizeof(*child));
435 gNumScripts++;
436 ASSERT(child != NULL);
437
438 child->stateFlags = newState | EVT_FLAG_ACTIVE;
439 child->ptrNextLine = nextLine;
440 child->ptrFirstLine = nextLine;
441 child->ptrCurLine = nextLine;
443 child->userData = NULL;
444 child->blockingParent = NULL;
445 child->parentScript = parentScript;
446 child->childScript = NULL;
447 child->priority = parentScript->priority;
448 child->id = UniqueScriptCounter++;
449 child->owner1.actorID = parentScript->owner1.actorID;
450 child->owner2.npcID = parentScript->owner2.npcID;
451 child->loopDepth = -1;
452 child->switchDepth = -1;
453 child->groupFlags = parentScript->groupFlags;
454 child->ptrSavedPos = NULL;
455 child->array = parentScript->array;
456 child->flagArray = parentScript->flagArray;
457 child->timeScale = GlobalTimeRate;
458 child->frameCounter = 0.0f;
459 child->unk_158 = 0;
460
461 scriptListCount = 0;
462
463 for (i = 0; i < ARRAY_COUNT(child->varTable); i++) {
464 child->varTable[i] = parentScript->varTable[i];
465 }
466
467 for (i = 0; i < ARRAY_COUNT(child->varFlags); i++) {
468 child->varFlags[i] = parentScript->varFlags[i];
469 }
470
471 find_script_labels(child);
472 if (IsUpdatingScripts) {
473 scriptListCount = gScriptListCount++;
474 gScriptIndexList[scriptListCount] = curScriptIndex;
475 gScriptIdList[scriptListCount] = child->id;
476 }
477
478 if (UniqueScriptCounter == 0) {
480 }
481
483 return child;
484}
485
486Evt* func_802C3C10(Evt* script, Bytecode* line, s32 arg2) {
487 Evt* curScript;
488 s32 i;
489
490 script->ptrNextLine = line;
491 script->ptrFirstLine = line;
492 script->ptrCurLine = line;
494 script->frameCounter = 0;
495 script->stateFlags |= arg2;
496 script->timeScale = 1.0f;
497
498 if (script->userData != NULL) {
499 heap_free(script->userData);
500 script->userData = NULL;
501 }
502
503 if (script->childScript != 0) {
504 kill_script(script->childScript);
505 }
506
507 for (i = 0; i < MAX_SCRIPTS; i++) {
508 curScript = (*gCurrentScriptListPtr)[i];
509 if ((curScript != 0) && (curScript->parentScript == script)) {
510 kill_script(curScript);
511 }
512 }
513 script->loopDepth = -1;
514 script->switchDepth = -1;
515 script->blockingParent = NULL;
516 script->parentScript = NULL;
517 script->childScript = NULL;
518 script->frameCounter = 0.0f;
519 script->unk_158 = 0;
520 script->timeScale = GlobalTimeRate;
521 find_script_labels(script);
523
524 return script;
525}
526
528 Bytecode* ptrFirstLine = script->ptrFirstLine;
529
530 // frameCounter gets set to 0 twice which makes me think a macro is being used here
531 script->loopDepth = -1;
532 script->switchDepth = -1;
533 script->frameCounter = 0;
535
536 script->ptrNextLine = ptrFirstLine;
537 script->ptrCurLine = ptrFirstLine;
538 script->timeScale = 1.0f;
539 script->frameCounter = 0;
540 script->unk_158 = 0;
541
542 script->timeScale = GlobalTimeRate;
543
544 find_script_labels(script);
546
547 return script;
548}
549
550void update_scripts(void) {
551 s32 i;
552
554 return;
555 }
556
557 IsUpdatingScripts = TRUE;
558 sort_scripts();
559
560 for (i = 0; i < gScriptListCount; i++) {
561 Evt* script = (*gCurrentScriptListPtr)[gScriptIndexList[i]];
562
563 if (script != NULL &&
564 script->id == gScriptIdList[i] &&
565 script->stateFlags != 0 &&
567 {
568 s32 stop = FALSE;
569 s32 status;
570
571 script->frameCounter += script->timeScale;
572
573 do {
574 if (script->frameCounter < 1.0) {
575 // Continue to next script
576 break;
577 };
578
579 script->frameCounter -= 1.0;
580 status = evt_execute_next_command(script);
581 if (status == EVT_CMD_RESULT_ERROR) {
582 stop = TRUE;
583 break;
584 }
585 } while (status != EVT_CMD_RESULT_YIELD);
586
587 if (stop) {
588 break;
589 }
590 }
591 }
592 IsUpdatingScripts = FALSE;
593}
594
595// Does nothing, is cursed
596void func_802C3EE4(void) {
597 s32 temp;
598 s32 i;
599
600 for (i = 0; i < gScriptListCount; i++) {
601 temp = (s32) (*gCurrentScriptListPtr)[gScriptIndexList[i]];
602 temp = *((s32*) temp);
603 if (temp == gScriptIdList[i]) {
604 temp = 1;
605 }
606 }
607}
608
609void kill_script(Evt* instanceToKill) {
610 Evt* childScript;
611 Evt* blockingParent;
612 s32 j;
613 s32 i;
614
615 for (i = 0; i < MAX_SCRIPTS; i++) {
616 if ((*gCurrentScriptListPtr)[i] == instanceToKill) {
617 break;
618 }
619 }
620
621 if (i >= MAX_SCRIPTS) {
622 return;
623 }
624
625 childScript = instanceToKill->childScript;
626 if (childScript != NULL) {
627 kill_script(childScript);
628 }
629
630 for (j = 0; j < MAX_SCRIPTS; j++) {
631 Evt* tempScriptInstance = (*gCurrentScriptListPtr)[j];
632 if (tempScriptInstance != NULL) {
633 if (tempScriptInstance->parentScript == instanceToKill) {
634 kill_script(tempScriptInstance);
635 }
636 }
637 }
638
639 blockingParent = instanceToKill->blockingParent;
640 if (blockingParent != NULL) {
641 blockingParent->childScript = NULL;
642 blockingParent->stateFlags &= ~EVT_FLAG_BLOCKED_BY_CHILD;
643
644 for (j = 0; j < ARRAY_COUNT(blockingParent->varTable); j++) {
645 blockingParent->varTable[j] = instanceToKill->varTable[j];
646 }
647
648 for (j = 0; j < ARRAY_COUNT(blockingParent->varFlags); j++) {
649 blockingParent->varFlags[j] = instanceToKill->varFlags[j];
650 }
651 }
652
653 if (instanceToKill->userData != NULL) {
654 heap_free(instanceToKill->userData);
655 instanceToKill->userData = NULL;
656 }
657
659 (*gCurrentScriptListPtr)[i] = NULL;
660 gNumScripts--;
661}
662
663void kill_script_by_ID(s32 id) {
664 s32 i;
665 Evt* scriptContextPtr;
666
667 for (i = 0; i < MAX_SCRIPTS; i++) {
668 scriptContextPtr = (*gCurrentScriptListPtr)[i];
669 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
670 kill_script(scriptContextPtr);
671 }
672 }
673}
674
676 s32 i;
677 Evt* scriptContextPtr;
678
679 for (i = 0; i < MAX_SCRIPTS; i++) {
680 scriptContextPtr = (*gCurrentScriptListPtr)[i];
681 if (scriptContextPtr != NULL) {
682 kill_script(scriptContextPtr);
683 }
684 }
685}
686
687s32 does_script_exist(s32 id) {
688 s32 i;
689 Evt* scriptContextPtr;
690
691 for (i = 0; i < MAX_SCRIPTS; i++) {
692 scriptContextPtr = (*gCurrentScriptListPtr)[i];
693 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
694 return TRUE;
695 }
696 }
697 return FALSE;
698}
699
701 s32 i;
702
703 for (i = 0; i < MAX_SCRIPTS; i++) {
704 if (script == (*gCurrentScriptListPtr)[i]) {
705 return TRUE;
706 }
707 }
708 return FALSE;
709}
710
711void set_script_priority(Evt* script, s32 priority) {
712 script->priority = priority;
713}
714
715void set_script_timescale(Evt* script, f32 timescale) {
716 script->timeScale = timescale * GlobalTimeRate;
717}
718
719void set_global_timespace(f32 timeScale) {
720 GlobalTimeRate = timeScale;
721}
722
724 return GlobalTimeRate;
725}
726
727void set_script_group(Evt* script, s32 groupFlags) {
728 script->groupFlags = groupFlags;
729}
730
731Trigger* bind_trigger(EvtScript* script, s32 flags, s32 triggerFlagIndex, s32 triggerVar0, s32 triggerVar1,
732 s32 priority, s32 arg6) {
733 Trigger* trigger;
735
737 bp.colliderID = triggerFlagIndex;
738 bp.tattleMsg = 0;
740 bp.hasPlayerInteractPrompt = arg6;
741
742 trigger = create_trigger(&bp);
743 trigger->onTriggerEvt = script;
744 trigger->runningScript = NULL;
745 trigger->priority = priority;
746 trigger->varTable[0] = triggerVar0;
747 trigger->varTable[1] = triggerVar1;
748 return trigger;
749}
750
751Trigger* bind_trigger_1(EvtScript* script, s32 flags, s32 triggerFlagIndex, s32 triggerVar0, s32 triggerVar1,
752 s32 priority) {
753 return bind_trigger(script, flags, triggerFlagIndex, triggerVar0, triggerVar1, priority, 1);
754}
755
756void suspend_group_script(Evt* script, s32 groupFlags) {
757 Evt* childScript = script->childScript;
758 s32 i;
759
760 if (childScript != NULL) {
761 suspend_group_script(childScript, groupFlags);
762 }
763
764 for (i = 0; i < MAX_SCRIPTS; i++) {
765 Evt* scriptContextPtr = (*gCurrentScriptListPtr)[i];
766
767 if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) {
768 suspend_group_script(scriptContextPtr, groupFlags);
769 }
770 }
771
772 if ((script->groupFlags & groupFlags) != 0) {
773 script->stateFlags |= EVT_FLAG_PAUSED;
774 }
775}
776
777void resume_group_script(Evt* script, s32 groupFlags) {
778 Evt* childScript = script->childScript;
779 s32 i;
780
781 if (childScript != NULL) {
782 resume_group_script(childScript, groupFlags);
783 }
784
785 for (i = 0; i < MAX_SCRIPTS; i++) {
786 Evt* scriptContextPtr = (*gCurrentScriptListPtr)[i];
787
788 if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) {
789 suspend_group_script(scriptContextPtr, groupFlags);
790 }
791 }
792
793 if ((script->groupFlags & groupFlags) != 0) {
794 script->stateFlags &= ~EVT_FLAG_PAUSED;
795 }
796}
797
799 s32 i;
800
801 for (i = 0; i < MAX_SCRIPTS; i++) {
802 Evt* scriptContextPtr = (*gCurrentScriptListPtr)[i];
803
804 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
806 }
807 }
808}
809
810s32 resume_all_script(s32 id) {
811 s32 i;
812 Evt* scriptContextPtr;
813
814 for (i = 0; i < MAX_SCRIPTS; i++) {
815 scriptContextPtr = (*gCurrentScriptListPtr)[i];
816 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
817 resume_group_script(scriptContextPtr, EVT_GROUP_NOT_BATTLE);
818 }
819 }
820}
821
822void suspend_group_script_index(s32 id, s32 groupFlags) {
823 s32 i;
824 Evt* scriptContextPtr;
825
826 for (i = 0; i < MAX_SCRIPTS; i++) {
827 scriptContextPtr = (*gCurrentScriptListPtr)[i];
828 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
829 suspend_group_script(scriptContextPtr, groupFlags);
830 }
831 }
832}
833
834void resume_group_script_index(s32 id, s32 groupFlags) {
835 s32 i;
836 Evt* scriptContextPtr;
837
838 for (i = 0; i < MAX_SCRIPTS; i++) {
839 scriptContextPtr = (*gCurrentScriptListPtr)[i];
840 if (scriptContextPtr != NULL && scriptContextPtr->id == id) {
841 resume_group_script(scriptContextPtr, groupFlags);
842 }
843 }
844}
845
846void suspend_all_group(s32 groupFlags) {
847 s32 i;
848 Evt* scriptContextPtr;
849
850 for (i = 0; i < MAX_SCRIPTS; i++) {
851 scriptContextPtr = (*gCurrentScriptListPtr)[i];
852 if (scriptContextPtr != NULL) {
853 suspend_group_script(scriptContextPtr, groupFlags);
854 }
855 }
856}
857
858s32 resume_all_group(s32 groupFlags) {
859 s32 i;
860 Evt* scriptContextPtr;
861
862 for (i = 0; i < MAX_SCRIPTS; i++) {
863 scriptContextPtr = (*gCurrentScriptListPtr)[i];
864 if (scriptContextPtr != NULL) {
865 resume_group_script(scriptContextPtr, groupFlags);
866 }
867 }
868}
869
870void suspend_group_others(Evt* script, s32 groupFlags) {
871 s32 i;
872 Evt* scriptContextPtr;
873
874 for (i = 0; i < MAX_SCRIPTS; i++) {
875 scriptContextPtr = (*gCurrentScriptListPtr)[i];
876 if (scriptContextPtr != NULL && scriptContextPtr != script) {
877 suspend_group_script(scriptContextPtr, groupFlags);
878 }
879 }
880}
881
882void resume_group_others(Evt* script, s32 groupFlags) {
883 s32 i;
884 Evt* scriptContextPtr;
885
886 for (i = 0; i < MAX_SCRIPTS; i++) {
887 scriptContextPtr = (*gCurrentScriptListPtr)[i];
888 if (scriptContextPtr != NULL && scriptContextPtr != script) {
889 resume_group_script(scriptContextPtr, groupFlags);
890 }
891 }
892}
893
895 return (*gCurrentScriptListPtr)[index];
896}
897
899 s32 i;
900 Evt* scriptContextPtr;
901
902 for (i = 0; i < MAX_SCRIPTS; i++) {
903 if ((*gCurrentScriptListPtr)[i] != NULL) {
904 scriptContextPtr = (*gCurrentScriptListPtr)[i];
905 if (scriptContextPtr->id == id) {
906 return scriptContextPtr;
907 }
908 }
909 }
910 return 0;
911}
912
913void set_script_flags(Evt* script, s32 flags) {
914 Evt* childScript = script->childScript;
915 s32 i;
916
917 script->stateFlags |= flags;
918 if (childScript != NULL) {
919 set_script_flags(childScript, flags);
920 }
921
922 for (i = 0; i < MAX_SCRIPTS; i++) {
923 Evt* scriptContextPtr = (*gCurrentScriptListPtr)[i];
924
925 if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) {
927 }
928 }
929}
930
931void clear_script_flags(Evt* script, s32 flags) {
932 Evt* childScript = script->childScript;
933 s32 i;
934
935 script->stateFlags &= ~flags;
936 if (childScript != NULL) {
937 clear_script_flags(childScript, flags);
938 }
939
940 for (i = 0; i < MAX_SCRIPTS; i++) {
941 Evt* scriptContextPtr = (*gCurrentScriptListPtr)[i];
942
943 if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) {
944 clear_script_flags(scriptContextPtr, flags);
945 }
946 }
947}
Bytecode * ptrNextLine
u8 stateFlags
struct Evt * parentScript
u8 curOpcode
struct Evt * childScript
u8 groupFlags
Evt * ScriptList[128]
s8 labelIndices[16]
void * labelPositions[16]
struct Evt * blockingParent
s32 * flagArray
s8 switchDepth
s8 loopDepth
s32 * array
AnimatedModel * AnimatedModelList[16]
s32 unk_158
union Evt::@8 owner1
Initially -1.
Bytecode * ptrSavedPos
s32 varFlags[3]
Bytecode * ptrCurLine
VirtualEntity * VirtualEntityList[0x40]
union Evt::@9 owner2
Initially -1.
void * userData
Bytecode EvtScript[]
f32 frameCounter
Bytecode * ptrFirstLine
f32 timeScale
u8 priority
s8 flags
Definition demo_api.c:15
#define ASSERT(condition)
@ DEBUG_SCRIPTS_NO_UPDATE
Definition enums.h:4276
@ TIME_FREEZE_FULL
Definition enums.h:3466
@ TIME_FREEZE_POPUP_MENU
Definition enums.h:3467
@ TIME_FREEZE_PARTIAL
Definition enums.h:3465
@ TIME_FREEZE_NONE
Definition enums.h:3464
@ TIME_FREEZE_EXIT
Definition enums.h:3468
@ CONTEXT_WORLD
Definition enums.h:3529
@ TRIGGER_SCRIPT_BOUND
Definition enums.h:2691
@ EVT_OP_INTERNAL_FETCH
Definition evt.h:10
s32 Bytecode
Definition evt.h:7
@ EVT_GROUP_FLAG_MENUS
Definition evt.h:135
@ EVT_GROUP_NOT_BATTLE
Definition evt.h:147
@ EVT_GROUP_FLAG_INTERACT
Definition evt.h:134
@ EVT_CMD_RESULT_YIELD
Definition evt.h:123
@ EVT_CMD_RESULT_ERROR
Definition evt.h:125
@ EVT_FLAG_ACTIVE
Definition evt.h:158
@ EVT_FLAG_PAUSED
paused through suspend_group_script / resume_group_script
Definition evt.h:159
@ EVT_FLAG_RUN_IMMEDIATELY
don't wait for next update_scripts call
Definition evt.h:161
@ EVT_FLAG_BLOCKED_BY_CHILD
Definition evt.h:160
@ EVT_FLAG_SUSPENDED
doesn't affect child
Definition evt.h:163
void init_model_animators(void)
Definition model_api.c:278
void init_virtual_entity_list(void)
s32 evt_trigger_on_activate_exec_script(Trigger *trigger)
Definition evt.c:982
s32 heap_free(void *ptr)
Definition heap.c:42
void clear_virtual_entity_list(void)
Trigger * create_trigger(TriggerBlueprint *def)
Definition trigger.c:55
void reset_model_animators(void)
Definition model_api.c:258
void * heap_malloc(s32 size)
Definition heap.c:34
#define MAX_MAPFLAGS
Definition macros.h:82
#define MAX_SCRIPTS
Definition macros.h:90
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define MAX_MAPVARS
Definition macros.h:81
#define PANIC()
Definition macros.h:55
void clear_script_list(void)
s32 does_script_exist_by_ref(Evt *script)
BSS s32 LastSafeFloor
Definition script_list.c:24
void suspend_group_others(Evt *script, s32 groupFlags)
Evt * start_script_in_group(EvtScript *source, u8 priority, u8 flags, u8 groupFlags)
void kill_all_scripts(void)
void kill_script(Evt *instanceToKill)
void resume_group_script_index(s32 id, s32 groupFlags)
BSS u32 * gMapFlags
Definition script_list.c:9
BSS u32 gWorldMapFlags[MAX_MAPFLAGS]
Definition script_list.c:58
void resume_group_script(Evt *script, s32 groupFlags)
void sort_scripts(void)
Definition script_list.c:71
BSS u32 gBattleMapFlags[MAX_MAPFLAGS]
Definition script_list.c:59
void func_802C3EE4(void)
BSS s32 ShowMessageScreenOffsetX
Definition script_list.c:36
BSS AnimatedModelList gBattleMeshAnimationList
Definition script_list.c:27
Evt * func_802C3C10(Evt *script, Bytecode *line, s32 arg2)
s32 UniqueScriptCounter
Definition script_list.c:4
BSS u32 gBattleMapVars[MAX_MAPVARS]
Definition script_list.c:62
void set_script_group(Evt *script, s32 groupFlags)
BSS s32 wExtraPartnerNpcID
Definition script_list.c:33
BSS u32 gWorldMapVars[MAX_MAPVARS]
Definition script_list.c:61
BSS struct LavaReset * gLavaResetList
Definition script_list.c:23
BSS ScriptList gBattleScriptList
Definition script_list.c:13
BSS VirtualEntityList bBattleVirtualEntityList
Definition script_list.c:45
BSS char evtDebugPrintBuffer[0x100]
Definition script_list.c:20
BSS s32 gScriptListCount
Definition script_list.c:17
Evt * get_script_by_index(s32 index)
s32 resume_all_group(s32 groupFlags)
s32 suspend_all_script(s32 id)
BSS s32 gScriptIdList[MAX_SCRIPTS]
Definition script_list.c:16
void suspend_group_script(Evt *script, s32 groupFlags)
void find_script_labels(Evt *script)
BSS AnimatedModelList gWorldMeshAnimationList
Definition script_list.c:28
void update_scripts(void)
void set_script_flags(Evt *script, s32 flags)
BSS ScriptList gWorldScriptList
Definition script_list.c:12
void suspend_group_script_index(s32 id, s32 groupFlags)
BSS AnimatedModelList * gCurrentMeshAnimationListPtr
Definition script_list.c:29
f32 GlobalTimeRate
Definition script_list.c:6
BSS s32 DoorModelsSwingCCW[3]
Definition script_list.c:67
BSS s32 * gMapVars
Definition script_list.c:10
void clear_script_flags(Evt *script, s32 flags)
void set_global_timespace(f32 timeScale)
void resume_group_others(Evt *script, s32 groupFlags)
void kill_script_by_ID(s32 id)
void init_script_list(void)
BSS PopupMenu gItemChoicePopupMenu
Definition script_list.c:55
s32 evt_execute_next_command(Evt *script)
Definition evt.c:1351
void suspend_frozen_scripts(Evt *script)
BSS s32 gScriptIndexList[MAX_SCRIPTS]
Definition script_list.c:15
Evt * start_script(EvtScript *source, s32 priority, s32 flags)
BSS s32 D_802DB264
Definition script_list.c:40
void set_script_timescale(Evt *script, f32 timescale)
s32 IsUpdatingScripts
Definition script_list.c:5
BSS u16 PlayerImgFXFlags
Definition script_list.c:44
BSS Npc playerNpcData
Definition script_list.c:43
BSS VirtualEntityList * gCurrentVirtualEntityListPtr
Definition script_list.c:47
void set_script_priority(Evt *script, s32 priority)
BSS VirtualEntityList wWorldVirtualEntityList
Definition script_list.c:46
Evt * start_child_script(Evt *parentScript, EvtScript *source, s32 flags)
s32 resume_all_script(s32 id)
BSS MessagePrintState * D_802DB268
Definition script_list.c:39
s32 does_script_exist(s32 id)
BSS s32 DoorModelsSwingCW[3]
Definition script_list.c:66
BSS ScriptList * gCurrentScriptListPtr
Definition script_list.c:14
BSS MessagePrintState * gCurrentPrintContext
Definition script_list.c:38
BSS MusicEvent * MusicEventList
Definition script_list.c:50
BSS Evt * RunningMusicEvents[10]
Definition script_list.c:51
Trigger * bind_trigger(EvtScript *script, s32 flags, s32 triggerFlagIndex, s32 triggerVar0, s32 triggerVar1, s32 priority, s32 arg6)
BSS PushBlockGrid * wPushBlockGrids[8]
Definition script_list.c:64
f32 get_global_timespace(void)
Evt * get_script_by_id(s32 id)
BSS s32 gNumScripts
Definition script_list.c:11
void suspend_all_group(s32 groupFlags)
Trigger * bind_trigger_1(EvtScript *script, s32 flags, s32 triggerFlagIndex, s32 triggerVar0, s32 triggerVar1, s32 priority)
Evt * restart_script(Evt *script)
BSS s32 wExtraPartnerID
Definition script_list.c:32
BSS s32 ShowMessageScreenOffsetY
Definition script_list.c:37
BSS s32 RunningMusicEventIDs[10]
Definition script_list.c:52
Evt * func_802C39F8(Evt *parentScript, Bytecode *nextLine, s32 newState)
s32(* onActivateFunc)(struct Trigger *)
EvtScript * onTriggerEvt
struct Evt * runningScript
GameStatus * gGameStatusPtr
Definition main_loop.c:32
s32 gTimeFreezeMode
Definition main_loop.c:12