forked from HarbourMasters/Ghostship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel_update.c
More file actions
1323 lines (1108 loc) · 44.6 KB
/
Copy pathlevel_update.c
File metadata and controls
1323 lines (1108 loc) · 44.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <libultraship.h>
#include "sm64.h"
#include "seq_ids.h"
#include "dialog_ids.h"
#include "audio/external.h"
#include "level_update.h"
#include "game_init.h"
#include "level_update.h"
#include "main.h"
#include "engine/math_util.h"
#include "engine/graph_node.h"
#include "area.h"
#include "save_file.h"
#include "sound_init.h"
#include "mario.h"
#include "camera.h"
#include "object_list_processor.h"
#include "ingame_menu.h"
#include "obj_behaviors.h"
#include "save_file.h"
#include "debug_course.h"
#ifdef VERSION_EU
#include "memory.h"
#include "eu_translation.h"
#include "segment_symbols.h"
#endif
#include "level_table.h"
#include "course_table.h"
#include "rumble_init.h"
#include "port/hooks/list/EngineEvent.h"
#include "port/mods/PortEnhancements.h"
#define PLAY_MODE_NORMAL 0
#define PLAY_MODE_PAUSED 2
#define PLAY_MODE_CHANGE_AREA 3
#define PLAY_MODE_CHANGE_LEVEL 4
#define PLAY_MODE_FRAME_ADVANCE 5
#define WARP_TYPE_NOT_WARPING 0
#define WARP_TYPE_CHANGE_LEVEL 1
#define WARP_TYPE_CHANGE_AREA 2
#define WARP_TYPE_SAME_AREA 3
#define WARP_NODE_F0 0xF0
#define WARP_NODE_DEATH 0xF1
#define WARP_NODE_F2 0xF2
#define WARP_NODE_WARP_FLOOR 0xF3
#define WARP_NODE_CREDITS_START 0xF8
#define WARP_NODE_CREDITS_NEXT 0xF9
#define WARP_NODE_CREDITS_END 0xFA
#define WARP_NODE_CREDITS_MIN 0xF8
// TODO: Make these ifdefs better
const char *credits01[] = { "1GAME DIRECTOR", "SHIGERU MIYAMOTO" };
const char *credits02[] = { "2ASSISTANT DIRECTORS", "YOSHIAKI KOIZUMI", "TAKASHI TEZUKA" };
const char *credits03[] = { "2SYSTEM PROGRAMMERS", "YASUNARI NISHIDA", "YOSHINORI TANIMOTO" };
const char *credits04[] = { "3PROGRAMMERS", "HAJIME YAJIMA", "DAIKI IWAMOTO", "TOSHIO IWAWAKI" };
#if defined(VERSION_JP) || defined(VERSION_SH)
const char *credits05[] = { "1CAMERA PROGRAMMER", "TAKUMI KAWAGOE" };
const char *credits06[] = { "1MARIO FACE PROGRAMMER", "GILES GODDARD" };
const char *credits07[] = { "2COURSE DIRECTORS", "YOICHI YAMADA", "YASUHISA YAMAMURA" };
const char *credits08[] = { "2COURSE DESIGNERS", "KENTA USUI", "NAOKI MORI" };
const char *credits09[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", "KATSUHIKO KANNO" };
const char *credits10[] = { "1SOUND COMPOSER", "KOJI KONDO" };
#ifdef VERSION_JP
const char *credits11[] = { "1SOUND EFFECTS", "YOJI INAGAKI" };
const char *credits12[] = { "1SOUND PROGRAMMER", "HIDEAKI SHIMIZU" };
const char *credits13[] = { "23D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" };
const char *credits14[] = { "1CG DESIGNER", "MASANAO ARIMOTO" };
const char *credits15[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" };
const char *credits16[] = { "1TECHNICAL SUPPORT", "SGI. 64PROJECT STAFF" };
const char *credits17[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" };
#else // VERSION_SH
// Shindou combines sound effects and sound programmer in order to make room for Mario voice and Peach voice
const char *credits11[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", "HIDEAKI SHIMIZU" };
const char *credits12[] = { "23D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" };
const char *credits13[] = { "1CG DESIGNER", "MASANAO ARIMOTO" };
const char *credits14[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" };
const char *credits15[] = { "1TECHNICAL SUPPORT", "SGI. 64PROJECT STAFF" };
const char *credits16[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" };
#endif
#else // VERSION_US || VERSION_EU
// US and EU combine camera programmer and Mario face programmer...
const char *credits05[] = { "4CAMERA PROGRAMMER", "MARIO FACE PROGRAMMER", "TAKUMI KAWAGOE", "GILES GODDARD" };
const char *credits06[] = { "2COURSE DIRECTORS", "YOICHI YAMADA", "YASUHISA YAMAMURA" };
const char *credits07[] = { "2COURSE DESIGNERS", "KENTA USUI", "NAOKI MORI" };
const char *credits08[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", "KATSUHIKO KANNO" };
#ifdef VERSION_US
const char *credits09[] = { "1SOUND COMPOSER", "KOJI KONDO" };
// ...as well as sound effects and sound programmer in order to make room for screen text writer, Mario voice, and Peach voice
const char *credits10[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", "HIDEAKI SHIMIZU" };
const char *credits11[] = { "23-D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" };
const char *credits12[] = { "1ADDITIONAL GRAPHICS", "MASANAO ARIMOTO" };
const char *credits13[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" };
const char *credits14[] = { "1TECHNICAL SUPPORT", "SGI N64 PROJECT STAFF" };
const char *credits15[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" };
const char *credits16[] = { "5SCREEN TEXT WRITER", "TRANSLATION", "LESLIE SWAN", "MINA AKINO", "HIRO YAMADA" };
#else // VERSION_EU
// ...as well as sound composer, sound effects, and sound programmer, and...
const char *credits09[] = { "7SOUND COMPOSER", "SOUND EFFECTS", "SOUND PROGRAMMER", "KOJI KONDO", "YOJI INAGAKI", "HIDEAKI SHIMIZU" };
// ...3D animators and additional graphics in order to make room for screen text writer(s), Mario voice, and Peach voice
const char *credits10[] = { "63-D ANIMATORS", "ADDITIONAL GRAPHICS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA", "MASANAO ARIMOTO" };
const char *credits11[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" };
const char *credits12[] = { "1TECHNICAL SUPPORT", "SGI N64 PROJECT STAFF" };
const char *credits13[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" };
const char *credits14[] = { "5SCREEN TEXT WRITER", "ENGLISH TRANSLATION", "LESLIE SWAN", "MINA AKINO", "HIRO YAMADA" };
const char *credits15[] = { "4SCREEN TEXT WRITER", "FRENCH TRANSLATION", "JULIEN BARDAKOFF", "KENJI HARAGUCHI" };
const char *credits16[] = { "4SCREEN TEXT WRITER", "GERMAN TRANSLATION", "THOMAS GOERG", "THOMAS SPINDLER" };
#endif
#endif
#ifndef VERSION_JP
const char *credits17[] = { "4MARIO VOICE", "PEACH VOICE", "CHARLES MARTINET", "LESLIE SWAN" };
#endif
#if defined(VERSION_JP) || defined(VERSION_SH)
const char *credits18[] = { "3SPECIAL THANKS TO", "JYOHO KAIHATUBU", "ALL NINTENDO", "MARIO CLUB STAFF" };
#elif defined(VERSION_US)
const char *credits18[] = { "3SPECIAL THANKS TO", "EAD STAFF", "ALL NINTENDO PERSONNEL", "MARIO CLUB STAFF" };
#else // VERSION_EU
const char *credits18[] = { "3SPECIAL THANKS TO", "EAD STAFF", "ALL NINTENDO PERSONNEL", "SUPER MARIO CLUB STAFF" };
#endif
const char *credits19[] = { "1PRODUCER", "SHIGERU MIYAMOTO" };
const char *credits20[] = { "1EXECUTIVE PRODUCER", "HIROSHI YAMAUCHI" };
struct CreditsEntry sCreditsSequence[] = {
{ LEVEL_CASTLE_GROUNDS, 1, 1, -128, { 0, 8000, 0 }, NULL },
{ LEVEL_BOB, 1, 1, 117, { 713, 3918, -3889 }, credits01 },
{ LEVEL_WF, 1, 50, 46, { 347, 5376, 326 }, credits02 },
{ LEVEL_JRB, 1, 18, 22, { 3800, -4840, 2727 }, credits03 },
{ LEVEL_CCM, 2, 34, 25, { -5464, 6656, -6575 }, credits04 },
{ LEVEL_BBH, 1, 1, 60, { 257, 1922, 2580 }, credits05 },
{ LEVEL_HMC, 1, -15, 123, { -6469, 1616, -6054 }, credits06 },
{ LEVEL_THI, 3, 17, -32, { 508, 1024, 1942 }, credits07 },
{ LEVEL_LLL, 2, 33, 124, { -73, 82, -1467 }, credits08 },
{ LEVEL_SSL, 1, 65, 98, { -5906, 1024, -2576 }, credits09 },
{ LEVEL_DDD, 1, 50, 47, { -4884, -4607, -272 }, credits10 },
{ LEVEL_SL, 1, 17, -34, { 1925, 3328, 563 }, credits11 },
{ LEVEL_WDW, 1, 33, 105, { -537, 1850, 1818 }, credits12 },
{ LEVEL_TTM, 1, 2, -33, { 2613, 313, 1074 }, credits13 },
{ LEVEL_THI, 1, 51, 54, { -2609, 512, 856 }, credits14 },
{ LEVEL_TTC, 1, 17, -72, { -1304, -71, -967 }, credits15 },
{ LEVEL_RR, 1, 33, 64, { 1565, 1024, -148 }, credits16 },
{ LEVEL_SA, 1, 1, 24, { -1050, -1330, -1559 }, credits17 },
{ LEVEL_COTMC, 1, 49, -16, { -254, 415, -6045 }, credits18 },
{ LEVEL_DDD, 2, -111, -64, { 3948, 1185, -104 }, credits19 },
{ LEVEL_CCM, 1, 33, 31, { 3169, -4607, 5240 }, credits20 },
{ LEVEL_CASTLE_GROUNDS, 1, 1, -128, { 0, 906, -1200 }, NULL },
{ LEVEL_NONE, 0, 1, 0, { 0, 0, 0 }, NULL },
};
struct MarioState gMarioStates[1];
struct HudDisplay gHudDisplay;
s16 sCurrPlayMode;
u16 D_80339ECA;
s16 sTransitionTimer;
void (*sTransitionUpdate)(s16 *);
struct WarpDest sWarpDest;
s16 D_80339EE0;
s16 sDelayedWarpOp;
s16 sDelayedWarpTimer;
s16 sSourceWarpNodeId;
s32 sDelayedWarpArg;
#if defined(VERSION_EU) || defined(VERSION_SH)
s16 unusedEULevelUpdateBss1;
#endif
s8 sTimerRunning;
bool gNeverEnteredCastle;
struct MarioState *gMarioState = &gMarioStates[0];
u8 unused1[4] = { 0 };
s8 sWarpCheckpointActive = FALSE;
u8 unused2[4];
u8 unused3[2];
u16 level_control_timer(s32 timerOp) {
switch (timerOp) {
case TIMER_CONTROL_SHOW:
gHudDisplay.flags |= HUD_DISPLAY_FLAG_TIMER;
sTimerRunning = FALSE;
gHudDisplay.timer = 0;
break;
case TIMER_CONTROL_START:
sTimerRunning = TRUE;
break;
case TIMER_CONTROL_STOP:
sTimerRunning = FALSE;
break;
case TIMER_CONTROL_HIDE:
gHudDisplay.flags &= ~HUD_DISPLAY_FLAG_TIMER;
sTimerRunning = FALSE;
gHudDisplay.timer = 0;
break;
}
return gHudDisplay.timer;
}
u32 pressed_pause(void) {
u32 dialogActive = get_dialog_id() >= 0;
u32 intangible = (gMarioState->action & ACT_FLAG_INTANGIBLE) != 0;
if (!intangible && !dialogActive && !gWarpTransition.isActive && sDelayedWarpOp == WARP_OP_NONE
&& (gPlayer1Controller->buttonPressed & START_BUTTON)) {
return TRUE;
}
return FALSE;
}
void set_play_mode(s16 playMode) {
sCurrPlayMode = playMode;
D_80339ECA = 0;
}
void warp_special(s32 arg) {
sCurrPlayMode = PLAY_MODE_CHANGE_LEVEL;
D_80339ECA = 0;
D_80339EE0 = arg;
}
void fade_into_special_warp(u32 arg, u32 color) {
if (color != 0) {
color = 0xFF;
}
fadeout_music(190);
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x10, color, color, color);
level_set_transition(30, NULL);
warp_special(arg);
}
void stub_level_update_1(void) {
}
void load_level_init_text(u32 arg) {
s32 gotAchievement;
u32 dialogID = gCurrentArea->dialog[arg];
switch (dialogID) {
case DIALOG_129:
gotAchievement = save_file_get_flags() & SAVE_FLAG_HAVE_VANISH_CAP;
break;
case DIALOG_130:
gotAchievement = save_file_get_flags() & SAVE_FLAG_HAVE_METAL_CAP;
break;
case DIALOG_131:
gotAchievement = save_file_get_flags() & SAVE_FLAG_HAVE_WING_CAP;
break;
case (u8)DIALOG_NONE: // 255, cast value to u8 to match (-1)
gotAchievement = TRUE;
break;
default:
gotAchievement =
save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum));
break;
}
if (!gotAchievement) {
level_set_transition(-1, NULL);
create_dialog_box(dialogID);
}
}
void init_door_warp(struct SpawnInfo *spawnInfo, u32 arg1) {
if (arg1 & 0x00000002) {
spawnInfo->startAngle[1] += 0x8000;
}
spawnInfo->startPos[0] += 300.0f * sins(spawnInfo->startAngle[1]);
spawnInfo->startPos[2] += 300.0f * coss(spawnInfo->startAngle[1]);
}
void set_mario_initial_cap_powerup(struct MarioState *m) {
u32 capCourseIndex = gCurrCourseNum - COURSE_CAP_COURSES;
switch (capCourseIndex) {
case COURSE_COTMC - COURSE_CAP_COURSES:
m->flags |= MARIO_METAL_CAP | MARIO_CAP_ON_HEAD;
m->capTimer = 600;
break;
case COURSE_TOTWC - COURSE_CAP_COURSES:
m->flags |= MARIO_WING_CAP | MARIO_CAP_ON_HEAD;
m->capTimer = 1200;
break;
case COURSE_VCUTM - COURSE_CAP_COURSES:
m->flags |= MARIO_VANISH_CAP | MARIO_CAP_ON_HEAD;
m->capTimer = 600;
break;
}
}
void set_mario_initial_action(struct MarioState *m, u32 spawnType, u32 actionArg) {
switch (spawnType) {
case MARIO_SPAWN_DOOR_WARP:
set_mario_action(m, ACT_WARP_DOOR_SPAWN, actionArg);
break;
case MARIO_SPAWN_UNKNOWN_02:
set_mario_action(m, ACT_IDLE, 0);
break;
case MARIO_SPAWN_UNKNOWN_03:
set_mario_action(m, ACT_EMERGE_FROM_PIPE, 0);
break;
case MARIO_SPAWN_TELEPORT:
set_mario_action(m, ACT_TELEPORT_FADE_IN, 0);
break;
case MARIO_SPAWN_INSTANT_ACTIVE:
set_mario_action(m, ACT_IDLE, 0);
break;
case MARIO_SPAWN_AIRBORNE:
set_mario_action(m, ACT_SPAWN_NO_SPIN_AIRBORNE, 0);
break;
case MARIO_SPAWN_HARD_AIR_KNOCKBACK:
set_mario_action(m, ACT_HARD_BACKWARD_AIR_KB, 0);
break;
case MARIO_SPAWN_SPIN_AIRBORNE_CIRCLE:
set_mario_action(m, ACT_SPAWN_SPIN_AIRBORNE, 0);
break;
case MARIO_SPAWN_DEATH:
set_mario_action(m, ACT_FALLING_DEATH_EXIT, 0);
break;
case MARIO_SPAWN_SPIN_AIRBORNE:
set_mario_action(m, ACT_SPAWN_SPIN_AIRBORNE, 0);
break;
case MARIO_SPAWN_FLYING:
set_mario_action(m, ACT_FLYING, 2);
break;
case MARIO_SPAWN_SWIMMING:
set_mario_action(m, ACT_WATER_IDLE, 1);
break;
case MARIO_SPAWN_PAINTING_STAR_COLLECT:
set_mario_action(m, ACT_EXIT_AIRBORNE, 0);
break;
case MARIO_SPAWN_PAINTING_DEATH:
set_mario_action(m, ACT_DEATH_EXIT, 0);
break;
case MARIO_SPAWN_AIRBORNE_STAR_COLLECT:
set_mario_action(m, ACT_FALLING_EXIT_AIRBORNE, 0);
break;
case MARIO_SPAWN_AIRBORNE_DEATH:
set_mario_action(m, ACT_UNUSED_DEATH_EXIT, 0);
break;
case MARIO_SPAWN_LAUNCH_STAR_COLLECT:
set_mario_action(m, ACT_SPECIAL_EXIT_AIRBORNE, 0);
break;
case MARIO_SPAWN_LAUNCH_DEATH:
set_mario_action(m, ACT_SPECIAL_DEATH_EXIT, 0);
break;
}
set_mario_initial_cap_powerup(m);
}
void init_mario_after_warp(void) {
struct ObjectWarpNode *spawnNode = area_get_warp_node(sWarpDest.nodeId);
u32 marioSpawnType = get_mario_spawn_type(spawnNode->object);
if (gMarioState->action != ACT_UNINITIALIZED) {
gPlayerSpawnInfos[0].startPos[0] = (s16) spawnNode->object->oPosX;
gPlayerSpawnInfos[0].startPos[1] = (s16) spawnNode->object->oPosY;
gPlayerSpawnInfos[0].startPos[2] = (s16) spawnNode->object->oPosZ;
gPlayerSpawnInfos[0].startAngle[0] = 0;
gPlayerSpawnInfos[0].startAngle[1] = spawnNode->object->oMoveAngleYaw;
gPlayerSpawnInfos[0].startAngle[2] = 0;
if (marioSpawnType == MARIO_SPAWN_DOOR_WARP) {
init_door_warp(&gPlayerSpawnInfos[0], sWarpDest.arg);
}
if (sWarpDest.type == WARP_TYPE_CHANGE_LEVEL || sWarpDest.type == WARP_TYPE_CHANGE_AREA) {
gPlayerSpawnInfos[0].areaIndex = sWarpDest.areaIdx;
load_mario_area();
}
init_mario();
set_mario_initial_action(gMarioState, marioSpawnType, sWarpDest.arg);
gMarioState->interactObj = spawnNode->object;
gMarioState->usedObj = spawnNode->object;
}
reset_camera(gCurrentArea->camera);
sWarpDest.type = WARP_TYPE_NOT_WARPING;
sDelayedWarpOp = WARP_OP_NONE;
switch (marioSpawnType) {
case MARIO_SPAWN_UNKNOWN_03:
play_transition(WARP_TRANSITION_FADE_FROM_STAR, 0x10, 0x00, 0x00, 0x00);
break;
case MARIO_SPAWN_DOOR_WARP:
play_transition(WARP_TRANSITION_FADE_FROM_CIRCLE, 0x10, 0x00, 0x00, 0x00);
break;
case MARIO_SPAWN_TELEPORT:
play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 0x14, 0xFF, 0xFF, 0xFF);
break;
case MARIO_SPAWN_SPIN_AIRBORNE:
play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 0x1A, 0xFF, 0xFF, 0xFF);
break;
case MARIO_SPAWN_SPIN_AIRBORNE_CIRCLE:
play_transition(WARP_TRANSITION_FADE_FROM_CIRCLE, 0x10, 0x00, 0x00, 0x00);
break;
case MARIO_SPAWN_UNKNOWN_27:
play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 0x10, 0x00, 0x00, 0x00);
break;
default:
play_transition(WARP_TRANSITION_FADE_FROM_STAR, 0x10, 0x00, 0x00, 0x00);
break;
}
if (gCurrDemoInput == NULL) {
set_background_music(gCurrentArea->musicParam, gCurrentArea->musicParam2, 0);
if (gMarioState->flags & MARIO_METAL_CAP) {
play_cap_music(SEQUENCE_ARGS(4, SEQ_EVENT_METAL_CAP));
}
if (gMarioState->flags & (MARIO_VANISH_CAP | MARIO_WING_CAP)) {
play_cap_music(SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP));
}
if (CVarGetInteger("gEnhancements.FixKoopaRaceMusic", 0) == 1 && gCurrLevelNum == LEVEL_BOB
&& get_current_background_music() != SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE) && sTimerRunning) {
play_music(SEQ_PLAYER_LEVEL, SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE), 0);
}
if (sWarpDest.levelNum == LEVEL_CASTLE && sWarpDest.areaIdx == 1
&& ( ROM_JP ? sWarpDest.nodeId == 31 : (sWarpDest.nodeId == 31 || sWarpDest.nodeId == 32))
) {
play_sound(SOUND_MENU_MARIO_CASTLE_WARP, gGlobalSoundSource);
}
if (!ROM_JP && sWarpDest.levelNum == LEVEL_CASTLE_GROUNDS && sWarpDest.areaIdx == 1
&& (sWarpDest.nodeId == 7 || sWarpDest.nodeId == 10 || sWarpDest.nodeId == 20
|| sWarpDest.nodeId == 30)) {
play_sound(SOUND_MENU_MARIO_CASTLE_WARP, gGlobalSoundSource);
}
}
}
// used for warps inside one level
void warp_area(void) {
if (sWarpDest.type != WARP_TYPE_NOT_WARPING) {
if (sWarpDest.type == WARP_TYPE_CHANGE_AREA) {
level_control_timer(TIMER_CONTROL_HIDE);
unload_mario_area();
load_area(sWarpDest.areaIdx);
}
init_mario_after_warp();
}
}
// used for warps between levels
void warp_level(void) {
gCurrLevelNum = sWarpDest.levelNum;
level_control_timer(TIMER_CONTROL_HIDE);
load_area(sWarpDest.areaIdx);
init_mario_after_warp();
}
void warp_credits(void) {
s32 marioAction;
switch (sWarpDest.nodeId) {
case WARP_NODE_CREDITS_START:
marioAction = ACT_END_PEACH_CUTSCENE;
break;
case WARP_NODE_CREDITS_NEXT:
marioAction = ACT_CREDITS_CUTSCENE;
break;
case WARP_NODE_CREDITS_END:
marioAction = ACT_END_WAVING_CUTSCENE;
break;
}
gCurrLevelNum = sWarpDest.levelNum;
load_area(sWarpDest.areaIdx);
vec3s_set(gPlayerSpawnInfos[0].startPos, gCurrCreditsEntry->marioPos[0],
gCurrCreditsEntry->marioPos[1], gCurrCreditsEntry->marioPos[2]);
vec3s_set(gPlayerSpawnInfos[0].startAngle, 0, 0x100 * gCurrCreditsEntry->marioAngle, 0);
gPlayerSpawnInfos[0].areaIndex = sWarpDest.areaIdx;
load_mario_area();
init_mario();
set_mario_action(gMarioState, marioAction, 0);
reset_camera(gCurrentArea->camera);
sWarpDest.type = WARP_TYPE_NOT_WARPING;
sDelayedWarpOp = WARP_OP_NONE;
play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 0x14, 0x00, 0x00, 0x00);
if (gCurrCreditsEntry == NULL || gCurrCreditsEntry == sCreditsSequence) {
set_background_music(gCurrentArea->musicParam, gCurrentArea->musicParam2, 0);
}
}
void check_instant_warp(void) {
s16 cameraAngle;
struct Surface *floor;
if (gCurrLevelNum == LEVEL_CASTLE
&& save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 70) {
return;
}
if ((floor = gMarioState->floor) != NULL) {
s32 index = floor->type - SURFACE_INSTANT_WARP_1B;
if (index >= INSTANT_WARP_INDEX_START && index < INSTANT_WARP_INDEX_STOP
&& gCurrentArea->instantWarps != NULL) {
struct InstantWarp *warp = &gCurrentArea->instantWarps[index];
if (warp->id != 0) {
gMarioState->pos[0] += warp->displacement[0];
gMarioState->pos[1] += warp->displacement[1];
gMarioState->pos[2] += warp->displacement[2];
gMarioState->marioObj->oPosX = gMarioState->pos[0];
gMarioState->marioObj->oPosY = gMarioState->pos[1];
gMarioState->marioObj->oPosZ = gMarioState->pos[2];
cameraAngle = gMarioState->area->camera->yaw;
change_area(warp->area);
gMarioState->area = gCurrentArea;
warp_camera(warp->displacement[0], warp->displacement[1], warp->displacement[2]);
gMarioState->area->camera->yaw = cameraAngle;
}
}
}
}
s16 music_changed_through_warp(s16 arg) {
struct ObjectWarpNode *warpNode = area_get_warp_node(arg);
s16 levelNum = warpNode->node.destLevel & 0x7F;
if(CVarGetInteger("gEnhancements.FixKoopaRaceMusic", 0) == 1) {
s16 destArea = warpNode->node.destArea;
s16 val4 = TRUE;
s16 sp2C;
if (levelNum == LEVEL_BOB && levelNum == gCurrLevelNum && destArea == gCurrAreaIndex) {
sp2C = get_current_background_music();
if (sp2C == SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP | SEQ_VARIATION)
|| sp2C == SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP)) {
val4 = FALSE;
}
} else {
u16 val8 = gAreas[destArea].musicParam;
u16 val6 = gAreas[destArea].musicParam2;
val4 = levelNum == gCurrLevelNum && val8 == gCurrentArea->musicParam
&& val6 == gCurrentArea->musicParam2;
if (get_current_background_music() != val6) {
val4 = FALSE;
}
}
return val4;
}
u16 val8 = gAreas[warpNode->node.destArea].musicParam;
u16 val6 = gAreas[warpNode->node.destArea].musicParam2;
s16 val4 = levelNum == gCurrLevelNum && val8 == gCurrentArea->musicParam
&& val6 == gCurrentArea->musicParam2;
if (get_current_background_music() != val6) {
val4 = FALSE;
}
return val4;
}
/**
* Set the current warp type and destination level/area/node.
*/
void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg3) {
if (destWarpNode >= WARP_NODE_CREDITS_MIN) {
sWarpDest.type = WARP_TYPE_CHANGE_LEVEL;
} else if (destLevel != gCurrLevelNum) {
sWarpDest.type = WARP_TYPE_CHANGE_LEVEL;
} else if (destArea != gCurrentArea->index) {
sWarpDest.type = WARP_TYPE_CHANGE_AREA;
} else {
sWarpDest.type = WARP_TYPE_SAME_AREA;
}
sWarpDest.levelNum = destLevel;
sWarpDest.areaIdx = destArea;
sWarpDest.nodeId = destWarpNode;
sWarpDest.arg = arg3;
}
// From Surface 0xD3 to 0xFC
#define PAINTING_WARP_INDEX_START 0x00 // Value greater than or equal to Surface 0xD3
#define PAINTING_WARP_INDEX_FA 0x2A // THI Huge Painting index left
#define PAINTING_WARP_INDEX_END 0x2D // Value less than Surface 0xFD
/**
* Check if Mario is above and close to a painting warp floor, and return the
* corresponding warp node.
*/
struct WarpNode *get_painting_warp_node(void) {
struct WarpNode *warpNode = NULL;
s32 paintingIndex = gMarioState->floor->type - SURFACE_PAINTING_WARP_D3;
if (paintingIndex >= PAINTING_WARP_INDEX_START && paintingIndex < PAINTING_WARP_INDEX_END) {
if (paintingIndex < PAINTING_WARP_INDEX_FA
|| gMarioState->pos[1] - gMarioState->floorHeight < 80.0f) {
warpNode = &gCurrentArea->paintingWarpNodes[paintingIndex];
}
}
return warpNode;
}
/**
* Check is Mario has entered a painting, and if so, initiate a warp.
*/
void initiate_painting_warp(void) {
if (gCurrentArea->paintingWarpNodes != NULL && gMarioState->floor != NULL) {
struct WarpNode warpNode;
struct WarpNode *pWarpNode = get_painting_warp_node();
if (pWarpNode != NULL) {
if (gMarioState->action & ACT_FLAG_INTANGIBLE) {
play_painting_eject_sound();
} else if (pWarpNode->id != 0) {
warpNode = *pWarpNode;
if (!(warpNode.destLevel & 0x80)) {
sWarpCheckpointActive = check_warp_checkpoint(&warpNode);
}
initiate_warp(warpNode.destLevel & 0x7F, warpNode.destArea, warpNode.destNode, 0);
check_if_should_set_warp_checkpoint(&warpNode);
play_transition_after_delay(WARP_TRANSITION_FADE_INTO_COLOR, 30, 255, 255, 255, 45);
level_set_transition(74, basic_update);
set_mario_action(gMarioState, ACT_DISAPPEARED, 0);
gMarioState->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource);
fadeout_music(398);
#if ENABLE_RUMBLE
queue_rumble_data(80, 70);
func_sh_8024C89C(1);
#endif
}
}
}
}
/**
* If there is not already a delayed warp, schedule one. The source node is
* based on the warp operation and sometimes Mario's used object.
* Return the time left until the delayed warp is initiated.
*/
s16 level_trigger_warp(struct MarioState *m, s32 warpOp) {
s32 val04 = TRUE;
if (sDelayedWarpOp == WARP_OP_NONE) {
m->invincTimer = -1;
sDelayedWarpArg = 0;
sDelayedWarpOp = warpOp;
switch (warpOp) {
case WARP_OP_DEMO_NEXT:
case WARP_OP_DEMO_END: sDelayedWarpTimer = 20; // Must be one line to match on -O2
sSourceWarpNodeId = WARP_NODE_F0;
gSavedCourseNum = COURSE_NONE;
val04 = FALSE;
play_transition(WARP_TRANSITION_FADE_INTO_STAR, 0x14, 0x00, 0x00, 0x00);
break;
case WARP_OP_CREDITS_END:
sDelayedWarpTimer = 60;
sSourceWarpNodeId = WARP_NODE_F0;
val04 = FALSE;
gSavedCourseNum = COURSE_NONE;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x3C, 0x00, 0x00, 0x00);
break;
case WARP_OP_STAR_EXIT:
sDelayedWarpTimer = 32;
sSourceWarpNodeId = WARP_NODE_F0;
gSavedCourseNum = COURSE_NONE;
play_transition(WARP_TRANSITION_FADE_INTO_MARIO, 0x20, 0x00, 0x00, 0x00);
break;
case WARP_OP_DEATH:
if (m->numLives == 0) {
sDelayedWarpOp = WARP_OP_GAME_OVER;
}
sDelayedWarpTimer = 48;
sSourceWarpNodeId = WARP_NODE_DEATH;
play_transition(WARP_TRANSITION_FADE_INTO_BOWSER, 0x30, 0x00, 0x00, 0x00);
play_sound(SOUND_MENU_BOWSER_LAUGH, gGlobalSoundSource);
break;
case WARP_OP_WARP_FLOOR:
sSourceWarpNodeId = WARP_NODE_WARP_FLOOR;
if (area_get_warp_node(sSourceWarpNodeId) == NULL) {
if (m->numLives == 0) {
sDelayedWarpOp = WARP_OP_GAME_OVER;
} else {
sSourceWarpNodeId = WARP_NODE_DEATH;
}
}
sDelayedWarpTimer = 20;
play_transition(WARP_TRANSITION_FADE_INTO_CIRCLE, 0x14, 0x00, 0x00, 0x00);
break;
case WARP_OP_UNKNOWN_01: // enter totwc
sDelayedWarpTimer = 30;
sSourceWarpNodeId = WARP_NODE_F2;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x1E, 0xFF, 0xFF, 0xFF);
if(!ROM_JP) {
play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource);
}
break;
case WARP_OP_UNKNOWN_02: // bbh enter
sDelayedWarpTimer = 30;
sSourceWarpNodeId = (m->usedObj->oBehParams & 0x00FF0000) >> 16;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x1E, 0xFF, 0xFF, 0xFF);
break;
case WARP_OP_TELEPORT:
sDelayedWarpTimer = 20;
sSourceWarpNodeId = (m->usedObj->oBehParams & 0x00FF0000) >> 16;
val04 = !music_changed_through_warp(sSourceWarpNodeId);
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x14, 0xFF, 0xFF, 0xFF);
break;
case WARP_OP_WARP_DOOR:
sDelayedWarpTimer = 20;
sDelayedWarpArg = m->actionArg;
sSourceWarpNodeId = (m->usedObj->oBehParams & 0x00FF0000) >> 16;
val04 = !music_changed_through_warp(sSourceWarpNodeId);
play_transition(WARP_TRANSITION_FADE_INTO_CIRCLE, 0x14, 0x00, 0x00, 0x00);
break;
case WARP_OP_WARP_OBJECT:
sDelayedWarpTimer = 20;
sSourceWarpNodeId = (m->usedObj->oBehParams & 0x00FF0000) >> 16;
val04 = !music_changed_through_warp(sSourceWarpNodeId);
play_transition(WARP_TRANSITION_FADE_INTO_STAR, 0x14, 0x00, 0x00, 0x00);
break;
case WARP_OP_CREDITS_START:
sDelayedWarpTimer = 30;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x1E, 0x00, 0x00, 0x00);
break;
case WARP_OP_CREDITS_NEXT:
if (gCurrCreditsEntry == &sCreditsSequence[0]) {
sDelayedWarpTimer = 60;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x3C, 0x00, 0x00, 0x00);
} else {
sDelayedWarpTimer = 20;
play_transition(WARP_TRANSITION_FADE_INTO_COLOR, 0x14, 0x00, 0x00, 0x00);
}
val04 = FALSE;
break;
}
if (val04 && gCurrDemoInput == NULL) {
fadeout_music((3 * sDelayedWarpTimer / 2) * 8 - 2);
}
}
return sDelayedWarpTimer;
}
/**
* If a delayed warp is ready, initiate it.
*/
void initiate_delayed_warp(void) {
struct ObjectWarpNode *warpNode;
s32 destWarpNode;
if (sDelayedWarpOp != WARP_OP_NONE && --sDelayedWarpTimer == 0) {
reset_dialog_render_state();
if (gDebugLevelSelect && (sDelayedWarpOp & WARP_OP_TRIGGERS_LEVEL_SELECT)) {
warp_special(-9);
} else if (gCurrDemoInput != NULL) {
if (sDelayedWarpOp == WARP_OP_DEMO_END) {
warp_special(-8);
} else {
warp_special(-2);
}
} else {
switch (sDelayedWarpOp) {
case WARP_OP_GAME_OVER:
save_file_reload();
warp_special(-3);
break;
case WARP_OP_CREDITS_END:
warp_special(-1);
sound_banks_enable(SEQ_PLAYER_SFX,
SOUND_BANKS_ALL & ~SOUND_BANKS_DISABLED_AFTER_CREDITS);
break;
case WARP_OP_DEMO_NEXT:
warp_special(-2);
break;
case WARP_OP_CREDITS_START:
gCurrCreditsEntry = &sCreditsSequence[0];
initiate_warp(gCurrCreditsEntry->levelNum, gCurrCreditsEntry->areaIndex,
WARP_NODE_CREDITS_START, 0);
break;
case WARP_OP_CREDITS_NEXT:
sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_ALL);
gCurrCreditsEntry++;
gCurrActNum = gCurrCreditsEntry->unk02 & 0x07;
if ((gCurrCreditsEntry + 1)->levelNum == LEVEL_NONE) {
destWarpNode = WARP_NODE_CREDITS_END;
} else {
destWarpNode = WARP_NODE_CREDITS_NEXT;
}
initiate_warp(gCurrCreditsEntry->levelNum, gCurrCreditsEntry->areaIndex,
destWarpNode, 0);
break;
default:
warpNode = area_get_warp_node(sSourceWarpNodeId);
initiate_warp(warpNode->node.destLevel & 0x7F, warpNode->node.destArea,
warpNode->node.destNode, sDelayedWarpArg);
check_if_should_set_warp_checkpoint(&warpNode->node);
if (sWarpDest.type != WARP_TYPE_CHANGE_LEVEL) {
level_set_transition(2, NULL);
}
break;
}
}
}
}
void update_hud_values(void) {
if (gCurrCreditsEntry == NULL) {
s16 numHealthWedges = gMarioState->health > 0 ? gMarioState->health >> 8 : 0;
if (gCurrCourseNum >= COURSE_MIN) {
gHudDisplay.flags |= HUD_DISPLAY_FLAG_COIN_COUNT;
} else {
gHudDisplay.flags &= ~HUD_DISPLAY_FLAG_COIN_COUNT;
}
if (gHudDisplay.coins < gMarioState->numCoins) {
if (gGlobalTimer & 1) {
u32 coinSound;
if (gMarioState->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER)) {
coinSound = SOUND_GENERAL_COIN_WATER;
} else {
coinSound = SOUND_GENERAL_COIN;
}
gHudDisplay.coins++;
play_sound(coinSound, gMarioState->marioObj->header.gfx.cameraToObject);
}
}
if (gMarioState->numLives > 100) {
gMarioState->numLives = 100;
}
#if BUGFIX_MAX_LIVES
if (gMarioState->numCoins > 999) {
gMarioState->numCoins = 999;
}
if (gHudDisplay.coins > 999) {
gHudDisplay.coins = 999;
}
#else
if (gMarioState->numCoins > 999) {
gMarioState->numLives = (s8) 999; //! Wrong variable
}
#endif
gHudDisplay.stars = gMarioState->numStars;
gHudDisplay.lives = gMarioState->numLives;
gHudDisplay.keys = gMarioState->numKeys;
if (numHealthWedges > gHudDisplay.wedges) {
play_sound(SOUND_MENU_POWER_METER, gGlobalSoundSource);
}
gHudDisplay.wedges = numHealthWedges;
if (gMarioState->hurtCounter > 0) {
gHudDisplay.flags |= HUD_DISPLAY_FLAG_EMPHASIZE_POWER;
} else {
gHudDisplay.flags &= ~HUD_DISPLAY_FLAG_EMPHASIZE_POWER;
}
}
}
/**
* Update objects, HUD, and camera. This update function excludes things like
* endless staircase, warps, pausing, etc. This is used when entering a painting,
* presumably to allow painting and camera updating while avoiding triggering the
* warp twice.
*/
void basic_update(UNUSED s16 *arg) {
area_update_objects();
update_hud_values();
if (gCurrentArea != NULL) {
update_camera(gCurrentArea->camera);
}
}
s32 play_mode_normal(void) {
if (gCurrDemoInput != NULL) {
print_intro_text();
if (gPlayer1Controller->buttonPressed & END_DEMO) {
level_trigger_warp(gMarioState,
gCurrLevelNum == LEVEL_PSS ? WARP_OP_DEMO_END : WARP_OP_DEMO_NEXT);
} else if (!gWarpTransition.isActive && sDelayedWarpOp == WARP_OP_NONE
&& (gPlayer1Controller->buttonPressed & START_BUTTON)) {
level_trigger_warp(gMarioState, WARP_OP_DEMO_NEXT);
}
}
warp_area();
check_instant_warp();
if (sTimerRunning && gHudDisplay.timer < 17999) {
gHudDisplay.timer++;
}
area_update_objects();
update_hud_values();
if (gCurrentArea != NULL) {
update_camera(gCurrentArea->camera);
}
initiate_painting_warp();
initiate_delayed_warp();
// If either initiate_painting_warp or initiate_delayed_warp initiated a
// warp, change play mode accordingly.
if (sCurrPlayMode == PLAY_MODE_NORMAL) {
if (sWarpDest.type == WARP_TYPE_CHANGE_LEVEL) {
set_play_mode(PLAY_MODE_CHANGE_LEVEL);
} else if (sTransitionTimer != 0) {
set_play_mode(PLAY_MODE_CHANGE_AREA);
} else if (pressed_pause()) {
lower_background_noise(1);
#if ENABLE_RUMBLE
cancel_rumble();
#endif
gCameraMovementFlags |= CAM_MOVE_PAUSE_SCREEN;