forked from djoslin0/sm64ex-coop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextended-moveset.lua
1470 lines (1163 loc) · 47 KB
/
extended-moveset.lua
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
-- name: Extended Moveset
-- incompatible: moveset
-- description: Adds various new moves from games like Sunshine and Odyssey without replacing any existing ones.\n\nOriginal author: TheGag96
------------------------
-- initialize actions --
------------------------
ACT_SPIN_POUND_LAND = allocate_mario_action(ACT_GROUP_STATIONARY | ACT_FLAG_STATIONARY | ACT_FLAG_ATTACKING)
ACT_ROLL = allocate_mario_action(ACT_GROUP_MOVING | ACT_FLAG_MOVING | ACT_FLAG_BUTT_OR_STOMACH_SLIDE)
ACT_GROUND_POUND_JUMP = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_SPIN_JUMP = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_SPIN_POUND = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ATTACKING)
ACT_LEDGE_PARKOUR = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR)
ACT_ROLL_AIR = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_WALL_SLIDE = allocate_mario_action(ACT_GROUP_AIRBORNE | ACT_FLAG_AIR | ACT_FLAG_MOVING | ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)
ACT_WATER_GROUND_POUND = allocate_mario_action(ACT_GROUP_SUBMERGED | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT | ACT_FLAG_ATTACKING)
ACT_WATER_GROUND_POUND_LAND = allocate_mario_action(ACT_GROUP_SUBMERGED | ACT_FLAG_STATIONARY | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT)
ACT_WATER_GROUND_POUND_STROKE = allocate_mario_action(ACT_GROUP_SUBMERGED | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT)
ACT_WATER_GROUND_POUND_JUMP = allocate_mario_action(ACT_GROUP_SUBMERGED | ACT_FLAG_MOVING | ACT_FLAG_SWIMMING | ACT_FLAG_SWIMMING_OR_FLYING | ACT_FLAG_WATER_OR_TEXT)
-----------------------------
-- initialize extra fields --
-----------------------------
ANGLE_QUEUE_SIZE = 9
SPIN_TIMER_SUCCESSFUL_INPUT = 4
gMarioStateExtras = {}
for i=0,(MAX_PLAYERS-1) do
gMarioStateExtras[i] = {}
local m = gMarioStates[i]
local e = gMarioStateExtras[i]
e.angleDeltaQueue = {}
for j=0,(ANGLE_QUEUE_SIZE-1) do e.angleDeltaQueue[j] = 0 end
e.rotAngle = 0
e.boostTimer = 0
e.stickLastAngle = 0
e.spinDirection = 0
e.spinBufferTimer = 0
e.spinInput = 0
e.lastIntendedMag = 0
e.lastPos = {}
e.lastPos.x = m.pos.x
e.lastPos.y = m.pos.y
e.lastPos.z = m.pos.z
e.fakeSavedAction = 0
e.fakeSavedPrevAction = 0
e.fakeSavedActionTimer = 0
e.fakeWroteAction = 0
e.fakeSaved = false
e.savedWallSlideHeight = 0
e.savedWallSlide = false
end
function limit_angle(a)
return (a + 0x8000) % 0x10000 - 0x8000
end
----------
-- roll --
----------
function update_roll_sliding_angle(m, accel, lossFactor)
local floor = m.floor
local slopeAngle = atan2s(floor.normal.z, floor.normal.x)
local steepness = math.sqrt(floor.normal.x * floor.normal.x + floor.normal.z * floor.normal.z)
m.slideVelX = m.slideVelX + accel * steepness * sins(slopeAngle)
m.slideVelZ = m.slideVelZ + accel * steepness * coss(slopeAngle)
m.slideVelX = m.slideVelX * lossFactor
m.slideVelZ = m.slideVelZ * lossFactor
m.slideYaw = atan2s(m.slideVelZ, m.slideVelX)
local facingDYaw = limit_angle(m.faceAngle.y - m.slideYaw)
local newFacingDYaw = facingDYaw
if newFacingDYaw > 0 and newFacingDYaw <= 0x8000 then
newFacingDYaw = newFacingDYaw - 0x800
if newFacingDYaw < 0 then newFacingDYaw = 0 end
elseif newFacingDYaw >= -0x8000 and newFacingDYaw < 0 then
newFacingDYaw = newFacingDYaw + 0x800
if newFacingDYaw > 0 then newFacingDYaw = 0 end
end
m.faceAngle.y = limit_angle(m.slideYaw + newFacingDYaw)
m.vel.x = m.slideVelX
m.vel.y = 0.0
m.vel.z = m.slideVelZ
mario_update_moving_sand(m)
mario_update_windy_ground(m)
--! Speed is capped a frame late (butt slide HSG)
m.forwardVel = math.sqrt(m.slideVelX * m.slideVelX + m.slideVelZ * m.slideVelZ)
if m.forwardVel > 100.0 then
m.slideVelX = m.slideVelX * 100.0 / m.forwardVel
m.slideVelZ = m.slideVelZ * 100.0 / m.forwardVel
end
end
function update_roll_sliding(m, stopSpeed)
local stopped = 0
local intendedDYaw = m.intendedYaw - m.slideYaw
local forward = coss(intendedDYaw)
local sideward = sins(intendedDYaw)
--! 10k glitch
if forward < 0.0 and m.forwardVel >= 0.0 then
forward = forward * (0.5 + 0.5 * m.forwardVel / 100.0)
end
local accel = 4.0
local lossFactor = 0.994
local oldSpeed = math.sqrt(m.slideVelX * m.slideVelX + m.slideVelZ * m.slideVelZ)
--! This is uses trig derivatives to rotate Mario's speed.
-- In vanilla, it was slightly off/asymmetric since it uses the new X speed, but the old
-- Z speed. I've gone and fixed it here.
local angleChange = (m.intendedMag / 32.0) * 0.6
local modSlideVelX = m.slideVelZ * angleChange * sideward * 0.05
local modSlideVelZ = m.slideVelX * angleChange * sideward * 0.05
m.slideVelX = m.slideVelX + modSlideVelX
m.slideVelZ = m.slideVelZ - modSlideVelZ
local newSpeed = math.sqrt(m.slideVelX * m.slideVelX + m.slideVelZ * m.slideVelZ)
if oldSpeed > 0.0 and newSpeed > 0.0 then
m.slideVelX = m.slideVelX * oldSpeed / newSpeed
m.slideVelZ = m.slideVelZ * oldSpeed / newSpeed
end
update_roll_sliding_angle(m, accel, lossFactor)
if m.playerIndex == 0 and mario_floor_is_slope(m) == 0 and m.forwardVel * m.forwardVel < stopSpeed * stopSpeed then
mario_set_forward_vel(m, 0.0)
stopped = 1
end
return stopped
end
function act_roll(m)
local e = gMarioStateExtras[m.playerIndex]
local MAX_NORMAL_ROLL_SPEED = 50.0
local ROLL_BOOST_GAIN = 10.0
local ROLL_CANCEL_LOCKOUT_TIME = 10
local BOOST_LOCKOUT_TIME = 20
-- e.rotAngle is used for Mario's rotation angle during the roll (persists when going into ACT_ROLL_AIR and back)
-- e.boostTimer is used for the boost lockout timer (persists when going into ACT_ROLL_AIR and back)
-- m.actionTimer is used to lockout walk canceling out of rollout (reset each action switch)
if m.actionTimer == 0 then
if m.prevAction ~= ACT_ROLL_AIR then
e.rotAngle = 0
e.boostTimer = 0
end
elseif m.actionTimer >= ROLL_CANCEL_LOCKOUT_TIME or m.actionArg == 1 then
if (m.input & INPUT_Z_DOWN) == 0 then
return set_mario_action(m, ACT_WALKING, 0)
end
end
if (m.input & INPUT_B_PRESSED) ~= 0 then
queue_rumble_data_mario(m, 5, 80)
return set_jumping_action(m, ACT_FORWARD_ROLLOUT, 0)
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
return set_jumping_action(m, ACT_LONG_JUMP, 0)
end
if (m.controller.buttonPressed & X_BUTTON) ~= 0 and m.actionTimer > 0 then
m.vel.y = 19.0
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0)
if e.boostTimer >= BOOST_LOCKOUT_TIME then
e.boostTimer = 0
if m.forwardVel < MAX_NORMAL_ROLL_SPEED then
mario_set_forward_vel(m, math.min(m.forwardVel + ROLL_BOOST_GAIN, MAX_NORMAL_ROLL_SPEED))
end
m.particleFlags = m.particleFlags | PARTICLE_HORIZONTAL_STAR
-- ! playing this after the call to play_mario_sound seems to matter in making this sound play
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
end
return set_mario_action(m, ACT_ROLL_AIR, m.actionArg)
end
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
if update_roll_sliding(m, 10.0) ~= 0 then
return set_mario_action(m, ACT_CROUCH_SLIDE, 0)
end
common_slide_action(m, ACT_CROUCH_SLIDE, ACT_ROLL_AIR, MARIO_ANIM_FORWARD_SPINNING)
e.rotAngle = e.rotAngle + (0x80 * m.forwardVel)
if e.rotAngle > 0x10000 then
e.rotAngle = e.rotAngle - 0x10000
end
set_anim_to_frame(m, 10 * e.rotAngle / 0x10000)
e.boostTimer = e.boostTimer + 1
m.actionTimer = m.actionTimer + 1
return 0
end
function act_roll_air(m)
local e = gMarioStateExtras[m.playerIndex]
local MAX_NORMAL_ROLL_SPEED = 50.0
local ROLL_AIR_CANCEL_LOCKOUT_TIME = 15
if m.actionTimer == 0 then
if m.prevAction ~= ACT_ROLL then
e.rotAngle = 0
e.boostTimer = 0
end
end
if (m.input & INPUT_Z_DOWN) == 0 and m.actionTimer >= ROLL_AIR_CANCEL_LOCKOUT_TIME then
return set_mario_action(m, ACT_FREEFALL, 0)
end
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
local air_step = perform_air_step(m, 0)
if air_step == AIR_STEP_LANDED then
if check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP, 0)
return set_mario_action(m, ACT_ROLL, m.actionArg)
end
elseif air_step == AIR_STEP_HIT_WALL then
queue_rumble_data_mario(m, 5, 40)
mario_bonk_reflection(m, false)
m.faceAngle.y = m.faceAngle.y + 0x8000
if m.vel.y > 0.0 then
m.vel.y = 0.0
end
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
return set_mario_action(m, ACT_BACKWARD_AIR_KB, 0)
end
e.rotAngle = e.rotAngle + 0x80 * m.forwardVel
if e.rotAngle > 0x10000 then
e.rotAngle = e.rotAngle - 0x10000
end
set_anim_to_frame(m, 10 * e.rotAngle / 0x10000)
e.boostTimer = e.boostTimer + 1
m.actionTimer = m.actionTimer + 1
return false
end
function update_roll(m)
if m.action == ACT_DIVE_SLIDE then
if (m.input & INPUT_ABOVE_SLIDE) == 0 then
if (m.input & INPUT_Z_DOWN) ~= 0 and m.actionTimer < 2 then
return set_mario_action(m, ACT_ROLL, 1)
end
end
m.actionTimer = m.actionTimer + 1
end
if m.action == ACT_LONG_JUMP_LAND then
if (m.input & INPUT_Z_DOWN) ~= 0 and m.forwardVel > 15.0 and m.actionTimer < 1 then
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING)
return set_mario_action(m, ACT_ROLL, 1)
end
end
if m.action == ACT_CROUCHING then
if (m.controller.buttonPressed & X_BUTTON) ~= 0 then
m.vel.y = 19.0
mario_set_forward_vel(m, 32.0)
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0)
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
return set_mario_action(m, ACT_ROLL_AIR, 0)
end
end
if m.action == ACT_CROUCH_SLIDE then
if (m.controller.buttonPressed & X_BUTTON) ~= 0 then
m.vel.y = 19.0
mario_set_forward_vel(m, math.max(32, m.forwardVel))
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0)
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
return set_mario_action(m, ACT_ROLL_AIR, 0)
end
end
if m.action == ACT_GROUND_POUND_LAND then
if (m.controller.buttonPressed & X_BUTTON) ~= 0 then
mario_set_forward_vel(m, 60)
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
return set_mario_action(m, ACT_ROLL, 0)
end
end
end
----------
-- spin --
----------
function mario_update_spin_input(m)
local e = gMarioStateExtras[m.playerIndex]
local rawAngle = atan2s(-m.controller.stickY, m.controller.stickX)
e.spinInput = 0
-- prevent issues due to the frame going out of the dead zone registering the last angle as 0
if e.lastIntendedMag > 0.5 and m.intendedMag > 0.5 then
local angleOverFrames = 0
local thisFrameDelta = 0
local i = 0
local newDirection = e.spinDirection
local signedOverflow = 0
if rawAngle < e.stickLastAngle then
if e.stickLastAngle - rawAngle > 0x8000 then
signedOverflow = 1
end
if signedOverflow ~= 0 then
newDirection = 1
else
newDirection = -1
end
elseif rawAngle > e.stickLastAngle then
if rawAngle - e.stickLastAngle > 0x8000 then
signedOverflow = 1
end
if signedOverflow ~= 0 then
newDirection = -1
else
newDirection = 1
end
end
if e.spinDirection ~= newDirection then
for i=0,(ANGLE_QUEUE_SIZE-1) do
e.angleDeltaQueue[i] = 0
end
e.spinDirection = newDirection
else
for i=(ANGLE_QUEUE_SIZE-1),1,-1 do
e.angleDeltaQueue[i] = e.angleDeltaQueue[i-1]
angleOverFrames = angleOverFrames + e.angleDeltaQueue[i]
end
end
if e.spinDirection < 0 then
if signedOverflow ~= 0 then
thisFrameDelta = math.floor((1.0*e.stickLastAngle + 0x10000) - rawAngle)
else
thisFrameDelta = e.stickLastAngle - rawAngle
end
elseif e.spinDirection > 0 then
if signedOverflow ~= 0 then
thisFrameDelta = math.floor(1.0*rawAngle + 0x10000 - e.stickLastAngle)
else
thisFrameDelta = rawAngle - e.stickLastAngle
end
end
e.angleDeltaQueue[0] = thisFrameDelta
angleOverFrames = angleOverFrames + thisFrameDelta
if angleOverFrames >= 0xA000 then
e.spinBufferTimer = SPIN_TIMER_SUCCESSFUL_INPUT
end
-- allow a buffer after a successful input so that you can switch directions
if e.spinBufferTimer > 0 then
e.spinInput = 1
e.spinBufferTimer = e.spinBufferTimer - 1
end
else
e.spinDirection = 0
e.spinBufferTimer = 0
end
e.stickLastAngle = rawAngle
e.lastIntendedMag = m.intendedMag
end
function act_spin_jump(m)
local e = gMarioStateExtras[m.playerIndex]
if m.actionTimer == 0 then
-- determine clockwise/counter-clockwise spin
if e.spinDirection < 0 then
m.actionState = 1
end
elseif m.actionTimer == 1 or m.actionTimer == 4 then
play_sound(SOUND_ACTION_TWIRL, m.marioObj.header.gfx.cameraToObject)
end
local spinDirFactor = 1 -- negative for clockwise, positive for counter-clockwise
if m.actionState == 1 then
spinDirFactor = -1
end
if (m.input & INPUT_B_PRESSED) ~= 0 then
return set_mario_action(m, ACT_DIVE, 0)
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
play_sound(SOUND_ACTION_TWIRL, m.marioObj.header.gfx.cameraToObject)
m.vel.y = -50.0
mario_set_forward_vel(m, 0.0)
-- choose which direction to be facing on land (practically random if no input)
if (m.input & INPUT_NONZERO_ANALOG) ~= 0 then
m.faceAngle.y = m.intendedYaw
else
m.faceAngle.y = limit_angle(e.rotAngle)
end
return set_mario_action(m, ACT_SPIN_POUND, m.actionState)
end
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, CHAR_SOUND_YAHOO)
common_air_action_step(m, ACT_DOUBLE_JUMP_LAND, MARIO_ANIM_TWIRL,
AIR_STEP_CHECK_HANG)
e.rotAngle = e.rotAngle + 0x2867
if (e.rotAngle > 0x10000) then e.rotAngle = e.rotAngle - 0x10000 end
if (e.rotAngle < -0x10000) then e.rotAngle = e.rotAngle + 0x10000 end
m.marioObj.header.gfx.angle.y = limit_angle(m.marioObj.header.gfx.angle.y + (e.rotAngle * spinDirFactor))
m.actionTimer = m.actionTimer + 1
return false
end
function act_spin_jump_gravity(m)
if (m.flags & MARIO_WING_CAP) ~= 0 and m.vel.y < 0.0 and (m.input & INPUT_A_DOWN) ~= 0 then
m.marioBodyState.wingFlutter = 1
m.vel.y = m.vel.y - 0.7
if m.vel.y < -37.5 then
m.vel.y = m.vel.y + 1.4
if m.vel.y > -37.5 then
m.vel.y = -37.5
end
end
else
if m.vel.y > 0 then
m.vel.y = m.vel.y - 4
else
m.vel.y = m.vel.y - 1.4
end
if m.vel.y < -75.0 then
m.vel.y = -75.0
end
end
return 0
end
function act_spin_pound(m)
local e = gMarioStateExtras[m.playerIndex]
if m.actionTimer == 0 then
m.actionState = m.actionArg
end
local spinDirFactor = 1 -- negative for clockwise, positive for counter-clockwise
if m.actionState == 1 then spinDirFactor = -1 end
set_mario_animation(m, MARIO_ANIM_TWIRL)
if (m.input & INPUT_B_PRESSED) ~= 0 then
mario_set_forward_vel(m, 10.0)
m.vel.y = 35
set_mario_action(m, ACT_DIVE, 0)
end
local stepResult = perform_air_step(m, 0)
if stepResult == AIR_STEP_LANDED then
if should_get_stuck_in_ground(m) ~= 0 then
queue_rumble_data_mario(m, 5, 80)
play_sound(CHAR_SOUND_OOOF2, m.marioObj.header.gfx.cameraToObject)
m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE
set_mario_action(m, ACT_BUTT_STUCK_IN_GROUND, 0)
else
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING)
if check_fall_damage(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR
set_mario_action(m, ACT_SPIN_POUND_LAND, 0)
end
end
set_camera_shake_from_hit(SHAKE_GROUND_POUND)
elseif stepResult == AIR_STEP_HIT_WALL then
mario_set_forward_vel(m, -16.0)
if m.vel.y > 0.0 then
m.vel.y = 0.0
end
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0)
end
-- set facing direction
-- not part of original Extended Moveset
local yawDiff = m.faceAngle.y - m.intendedYaw
e.rotAngle = limit_angle(e.rotAngle + yawDiff)
m.faceAngle.y = m.intendedYaw
e.rotAngle = e.rotAngle + 0x3053
if e.rotAngle > 0x10000 then e.rotAngle = e.rotAngle - 0x10000 end
if e.rotAngle < -0x10000 then e.rotAngle = e.rotAngle + 0x10000 end
m.marioObj.header.gfx.angle.y = limit_angle(m.marioObj.header.gfx.angle.y + e.rotAngle * spinDirFactor)
m.actionTimer = m.actionTimer + 1
return 0
end
function act_spin_pound_land(m)
m.actionState = 1
if m.actionTimer <= 8 then
if (m.input & INPUT_UNKNOWN_10) ~= 0 then
return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0)
end
if (m.input & INPUT_OFF_FLOOR) ~= 0 then
return set_mario_action(m, ACT_FREEFALL, 0)
end
if (m.input & INPUT_ABOVE_SLIDE) ~= 0 then
return set_mario_action(m, ACT_BUTT_SLIDE, 0)
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
return set_jumping_action(m, ACT_GROUND_POUND_JUMP, 0)
end
if (m.controller.buttonPressed & X_BUTTON) ~= 0 then
mario_set_forward_vel(m, 60)
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
return set_mario_action(m, ACT_ROLL, 0)
end
stationary_ground_step(m)
set_mario_animation(m, MARIO_ANIM_LAND_FROM_DOUBLE_JUMP)
else
if (m.input & INPUT_UNKNOWN_10) ~= 0 then
return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0)
end
if (m.input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) ~= 0 then
return check_common_action_exits(m)
end
stopping_step(m, MARIO_ANIM_LAND_FROM_DOUBLE_JUMP, ACT_IDLE)
end
m.actionTimer = m.actionTimer + 1
return 0
end
----------------
-- wall slide --
----------------
function act_wall_slide(m)
local e = gMarioStateExtras[m.playerIndex]
e.savedWallSlideHeight = m.pos.y
e.savedWallSlide = true
if (m.input & INPUT_A_PRESSED) ~= 0 then
m.vel.y = 52.0
-- m.faceAngle.y = limit_angle(m.faceAngle.y + 0x8000)
return set_mario_action(m, ACT_WALL_KICK_AIR, 0)
end
-- attempt to stick to the wall a bit. if it's 0, sometimes you'll get kicked off of slightly sloped walls
mario_set_forward_vel(m, -1.0)
m.particleFlags = m.particleFlags | PARTICLE_DUST
play_sound(SOUND_MOVING_TERRAIN_SLIDE + m.terrainSoundAddend, m.marioObj.header.gfx.cameraToObject)
set_mario_animation(m, MARIO_ANIM_START_WALLKICK)
if perform_air_step(m, 0) == AIR_STEP_LANDED then
mario_set_forward_vel(m, 0.0)
if check_fall_damage_or_get_stuck(m, ACT_HARD_BACKWARD_GROUND_KB) == 0 then
return set_mario_action(m, ACT_FREEFALL_LAND, 0)
end
end
m.actionTimer = m.actionTimer + 1
if m.wall == nil and m.actionTimer > 2 then
mario_set_forward_vel(m, 0.0)
return set_mario_action(m, ACT_FREEFALL, 0)
end
return 0
end
function act_wall_slide_gravity(m)
m.vel.y = m.vel.y - 2
if m.vel.y < -15 then
m.vel.y = -15
end
end
function act_air_hit_wall(m)
if m.heldObj ~= 0 then
mario_drop_held_object(m)
end
m.actionTimer = m.actionTimer + 1
if m.actionTimer <= 1 and (m.input & INPUT_A_PRESSED) ~= 0 then
m.vel.y = 52.0
m.faceAngle.y = limit_angle(m.faceAngle.y + 0x8000)
return set_mario_action(m, ACT_WALL_KICK_AIR, 0)
elseif m.forwardVel >= 38.0 then
m.wallKickTimer = 5
if m.vel.y > 0.0 then
m.vel.y = 0.0
end
m.particleFlags = m.particleFlags | PARTICLE_VERTICAL_STAR
return set_mario_action(m, ACT_BACKWARD_AIR_KB, 0)
else
m.faceAngle.y = limit_angle(m.faceAngle.y + 0x8000)
return set_mario_action(m, ACT_WALL_SLIDE, 0)
end
--! Missing return statement (in original C code). The returned value is the result of the call
-- to set_mario_animation. In practice, this value is nonzero.
-- This results in this action "cancelling" into itself. It is supposed to
-- execute three times, each on a separate frame, but instead it executes
-- three times on the same frame.
-- This results in firsties only being possible for a single frame, instead
-- of three.
return set_mario_animation(m, MARIO_ANIM_START_WALLKICK)
end
------------------------
-- water ground pound --
------------------------
function act_water_ground_pound(m)
local GROUND_POUND_STROKE_SPEED = 27
local GROUND_POUND_TIMER = 30
local stepResult = 0
if m.actionTimer == 0 then
-- coming into action from normal ground pound
if m.actionArg == 1 then
-- copied from water plunge code
play_sound(SOUND_ACTION_UNKNOWN430, m.marioObj.header.gfx.cameraToObject)
if m.peakHeight - m.pos.y > 1150.0 then
play_sound(CHAR_SOUND_HAHA_2, m.marioObj.header.gfx.cameraToObject)
end
m.particleFlags = m.particleFlags | PARTICLE_WATER_SPLASH
if (m.prevAction & ACT_FLAG_AIR) ~= 0 then
queue_rumble_data_mario(m, 5, 80)
end
end
m.actionState = m.actionArg
elseif m.actionTimer == 1 then
play_sound(SOUND_ACTION_SWIM, m.marioObj.header.gfx.cameraToObject)
end
if m.actionState == 0 then
if m.actionTimer == 0 then
m.vel.y = 0.0
mario_set_forward_vel(m, 0.0)
end
m.faceAngle.x = 0
m.faceAngle.z = 0
set_mario_animation(m, MARIO_ANIM_START_GROUND_POUND)
if m.actionTimer == 0 then
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
end
m.actionTimer = m.actionTimer + 1
if (m.actionTimer >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd + 4) then
-- play_sound(CHAR_SOUND_GROUND_POUND_WAH, m.marioObj.header.gfx.cameraToObject)
play_sound(SOUND_ACTION_SWIM_FAST, m.marioObj.header.gfx.cameraToObject)
m.vel.y = -45.0
m.actionState = 1
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
mario_set_forward_vel(m, GROUND_POUND_STROKE_SPEED)
m.vel.y = 0
return set_mario_action(m, ACT_WATER_GROUND_POUND_STROKE, 0)
end
-- make current apply
stepResult = perform_water_step(m)
else
set_mario_animation(m, MARIO_ANIM_GROUND_POUND)
m.particleFlags = m.particleFlags | PARTICLE_PLUNGE_BUBBLE
local nextPos = {}
nextPos.x = m.pos.x + m.vel.x
nextPos.y = m.pos.y + m.vel.y
nextPos.z = m.pos.z + m.vel.z
-- call this one to make current NOT apply
stepResult = perform_water_full_step(m, nextPos)
vec3f_copy(m.marioObj.header.gfx.pos, m.pos)
vec3s_set(m.marioObj.header.gfx.angle, -m.faceAngle.x, m.faceAngle.y, m.faceAngle.z)
if stepResult == WATER_STEP_HIT_FLOOR then
play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING)
m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE | PARTICLE_HORIZONTAL_STAR
set_mario_action(m, ACT_WATER_GROUND_POUND_LAND, 0)
set_camera_shake_from_hit(SHAKE_GROUND_POUND)
else
if (m.input & INPUT_A_PRESSED) ~= 0 then
mario_set_forward_vel(m, GROUND_POUND_STROKE_SPEED)
m.vel.y = 0
return set_mario_action(m, ACT_WATER_GROUND_POUND_STROKE, 0)
end
m.vel.y = approach_f32(m.vel.y, 0, 2.0, 2.0)
mario_set_forward_vel(m, 0.0)
if m.actionTimer >= GROUND_POUND_TIMER or m.vel.y >= 0.0 then
set_mario_action(m, ACT_WATER_ACTION_END, 0)
end
end
m.actionTimer = m.actionTimer + 1
end
return 0
end
function act_water_ground_pound_land(m)
local GROUND_POUND_JUMP_VEL = 40.0
m.actionState = 1
if (m.input & INPUT_OFF_FLOOR) ~= 0 then
return set_mario_action(m, ACT_WATER_IDLE, 0)
end
if (m.input & INPUT_A_PRESSED) ~= 0 then
m.vel.y = GROUND_POUND_JUMP_VEL
play_sound(SOUND_ACTION_SWIM_FAST, m.marioObj.header.gfx.cameraToObject)
return set_mario_action(m, ACT_WATER_GROUND_POUND_JUMP, 0)
end
m.vel.y = 0.0
m.pos.y = m.floorHeight
mario_set_forward_vel(m, 0.0)
vec3f_copy(m.marioObj.header.gfx.pos, m.pos)
vec3s_set(m.marioObj.header.gfx.angle, 0, m.faceAngle.y, 0)
set_mario_animation(m, MARIO_ANIM_GROUND_POUND_LANDING)
if is_anim_at_end(m) ~= 0 then
return set_mario_action(m, ACT_SWIMMING_END, 0)
end
perform_water_step(m)
return 0
end
function act_water_ground_pound_stroke(m)
local GROUND_POUND_STROKE_TIMER = 20
local GROUND_POUND_STROKE_DECAY = 0.3
local stepResult = 0
set_mario_animation(m, MARIO_ANIM_SWIM_PART1)
if m.actionTimer == 0 then
play_sound(SOUND_ACTION_SWIM_FAST, m.marioObj.header.gfx.cameraToObject)
end
stepResult = perform_water_step(m)
if stepResult == WATER_STEP_HIT_WALL then
return set_mario_action(m, ACT_BACKWARD_WATER_KB, 0)
end
if m.actionTimer >= GROUND_POUND_STROKE_TIMER then
if (m.input & INPUT_A_DOWN) ~= 0 then
return set_mario_action(m, ACT_FLUTTER_KICK, 0)
else
return set_mario_action(m, ACT_SWIMMING_END, 0)
end
end
m.actionTimer = m.actionTimer + 1
mario_set_forward_vel(m, approach_f32(m.forwardVel, 0.0, GROUND_POUND_STROKE_DECAY, GROUND_POUND_STROKE_DECAY))
float_surface_gfx(m)
set_swimming_at_surface_particles(m, PARTICLE_WAVE_TRAIL)
return 0
end
function act_water_ground_pound_jump(m)
local e = gMarioStateExtras[m.playerIndex]
local GROUND_POUND_JUMP_TIMER = 20
local GROUND_POUND_JUMP_DECAY = 1.4
-- set_mario_animation(m, MARIO_ANIM_SWIM_PART1)
set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP)
m.particleFlags = m.particleFlags | PARTICLE_PLUNGE_BUBBLE
if m.actionTimer == 0 then
e.rotAngle = 0
end
local step = {}
vec3f_copy(step, m.vel)
apply_water_current(m, step)
local nextPos = {}
nextPos.x = m.pos.x + step.x
nextPos.y = m.pos.y + step.y
nextPos.z = m.pos.z + step.z
local stepResult = perform_water_full_step(m, nextPos)
vec3f_copy(m.marioObj.header.gfx.pos, m.pos)
vec3s_set(m.marioObj.header.gfx.angle, -m.faceAngle.x, m.faceAngle.y, m.faceAngle.z)
if m.pos.y > m.waterLevel - 80 then
return set_mario_action(m, ACT_WATER_JUMP, 0)
end
if m.actionTimer >= GROUND_POUND_JUMP_TIMER then
mario_set_forward_vel(m, m.vel.y) -- normal swim routines will use forwardVel to calculate y speed
m.faceAngle.x = 0x3EFF
if (m.input & INPUT_A_DOWN) ~= 0 then
return set_mario_action(m, ACT_FLUTTER_KICK, 0)
else
return set_mario_action(m, ACT_SWIMMING_END, 0)
end
end
m.actionTimer = m.actionTimer + 1
mario_set_forward_vel(m, 0.0)
m.vel.y = approach_f32(m.vel.y, 0.0, GROUND_POUND_JUMP_DECAY, GROUND_POUND_JUMP_DECAY)
-- m.faceAngle.x = 0x3EFF
float_surface_gfx(m)
set_swimming_at_surface_particles(m, PARTICLE_WAVE_TRAIL)
e.rotAngle = e.rotAngle + (0x10000*1.0 - e.rotAngle) / 5.0
m.marioObj.header.gfx.angle.y = limit_angle(m.marioObj.header.gfx.angle.y - e.rotAngle)
return 0
end
-------------------
-- ledge parkour --
-------------------
function act_ledge_parkour(m)
set_mario_animation(m, MARIO_ANIM_SLIDEFLIP)
local animFrame = m.marioObj.header.gfx.animInfo.animFrame
if m.actionTimer == 0 then
play_sound(CHAR_SOUND_HAHA_2, m.marioObj.header.gfx.cameraToObject)
elseif m.actionTimer == 1 then
play_sound(SOUND_ACTION_SIDE_FLIP_UNK, m.marioObj.header.gfx.cameraToObject)
end
update_air_without_turn(m)
local step = perform_air_step(m, AIR_STEP_CHECK_LEDGE_GRAB)
if step == AIR_STEP_NONE then
-- play the side flip animation at double speed for a portion of it
if animFrame < 15 then
animFrame = animFrame + 2
elseif animFrame > 23 then
animFrame = 23
else
animFrame = animFrame + 1
end
set_anim_to_frame(m, animFrame)
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
elseif step == AIR_STEP_LANDED then
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
set_mario_action(m, ACT_FREEFALL_LAND_STOP, 0)
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING)
elseif step == AIR_STEP_HIT_WALL then
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
mario_set_forward_vel(m, 0.0)
elseif step == AIR_STEP_HIT_LAVA_WALL then
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
lava_boost_on_wall(m)
end
m.actionTimer = m.actionTimer + 1
return 0
end
function act_ground_pound_jump(m)
local e = gMarioStateExtras[m.playerIndex]
if check_kick_or_dive_in_air(m) ~= 0 then
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + e.rotAngle
return 1
end
if (m.input & INPUT_Z_PRESSED) ~= 0 then
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + e.rotAngle
return set_mario_action(m, ACT_GROUND_POUND, 0)
end
if e.spinInput ~= 0 then
return set_mario_action(m, ACT_SPIN_JUMP, 1)
end
if m.actionTimer == 0 then
e.rotAngle = 0
elseif m.actionTimer == 1 then
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
end
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, CHAR_SOUND_YAHOO)
common_air_action_step(m, ACT_JUMP_LAND, MARIO_ANIM_SINGLE_JUMP,
AIR_STEP_CHECK_LEDGE_GRAB | AIR_STEP_CHECK_HANG)
e.rotAngle = e.rotAngle + (0x10000*1.0 - e.rotAngle) / 5.0
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y - e.rotAngle
m.actionTimer = m.actionTimer + 1
return 0
end
-------------------------------------
-- dive slide patched for dive hop --
-------------------------------------
function act_dive_slide(m)
if (m.input & INPUT_ABOVE_SLIDE) == 0 and (m.input & INPUT_A_PRESSED) ~= 0 then
queue_rumble_data_mario(m, 5, 80)
if m.forwardVel > 0 then
return set_mario_action(m, ACT_FORWARD_ROLLOUT, 0)
else
return set_mario_action(m, ACT_BACKWARD_ROLLOUT, 0)
end
end
if (m.input & INPUT_ABOVE_SLIDE) == 0 then