-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnolf.lua
More file actions
1481 lines (1229 loc) · 41.3 KB
/
snolf.lua
File metadata and controls
1481 lines (1229 loc) · 41.3 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
freeslot("SPR_SFST", "SPR_SFAH", "SPR_SFAV", "SPR_SFMR", "SPR_SFHX", "SPR_MSNF",
"SPR_LVBX", "SPR_INFL", "sfx_msnolf")
sfxinfo[sfx_msnolf].caption = "Anomalous Metal Snolf"
-- declare functions in advance so they can reference each other
-- without causing parsing errors
local shot_ready, horizontal_charge, vertical_charge, waiting_to_stop, at_rest,
take_a_mulligan, same_position, snolf_setup, reset_state, sinusoidal_scale,
get_charge_increment, in_black_core, allow_air_snolf, option_toggle,
snolfify_name, is_golf_setup, override_controls, are_touching, on_hit_boss,
calculate_weight, is_anyone_snolfing, reversed_gravity, print2, shot_charge,
draw_trajectory, update_state, is_snolf, is_snolfing, is_golfing,
is_anyone_snolf, update_hud, h_meter_limit, v_meter_limit, shoot, nudge_up
local options = {
everybodys_snolf = false,
snolf_hud_mode = 1,
snolf_inf_rings = false,
snolf_inf_lives = true,
snolf_inf_air = false,
snolf_death_mulligan = false,
snolf_ground_control = false,
snolf_air_shot = false,
snolf_save_states = false,
snolf_shot_guide = false,
snolf_fire_shield = true,
snolf_shot_on_hit_boss = true,
snolf_shot_on_hit_by_boss = true,
snolf_rings_on_hit_boss = true,
snolf_shot_on_touch_ground_when_in_boss = true,
snolf_shot_on_touch_wall_when_in_boss = false
}
local bosses_health = {}
local boss_level = false
local metal_snolf_race = nil
local metal_snolf_battle = nil
local oldmap = nil
---------------
-- constants --
---------------
local TICKS_FOR_MULLIGAN = 35 -- how long to hold down the spin button to take a mulligan
local BOUNCE_LIMIT = 10*FRACUNIT -- Snolf won't bounce if their vertical momentum is less than this
local BOUNCE_FACTOR = FRACUNIT/2 -- when Snolf bounces their momentum is multiplied by this factor
local SKIM_THRESHOLD = 10*FRACUNIT -- Snolf must be going at least this fast horizontally to skip across water
local SKIM_ANLGE = ANG20 -- Snolf will not skip if if angle of approach is greater than this
local SKIM_FACTOR = 4*FRACUNIT/5 -- when Snolf skims their momentum is multiplied by this factor
local STATE_WAITING, STATE_READY, STATE_CHARGE1, STATE_CHARGE2 = 1, 2, 3, 4
-- as it stands the max strength of a fully charged shot,
-- the charge meter period and the max displacement of the charge meter arrows
-- during the animation are all deterimned by these two constants, one each
-- for horizontal and vertical. ideally these should be six different constants
local H_METER_LENGTH = 50
local V_METER_LENGTH = 50
local WATER_AIR_TIMER = 1050
local SPACE_AIR_TIMER = 403
local button_names = {
spn = "SPIN",
jmp = "JUMP",
ca1 = "CUSTOM ACTION 1",
ca2 = "CUSTOM ACTION 2",
ca3 = "CUSTOM ACTION 3"
}
---------------
-- functions --
---------------
-- just prints to normal console and also chat
print2 = function(string)
print(string)
chatprint(string)
end
-- store all snolf-relevant state info in player_t.snolf
snolf_setup = function(player)
player.snolf = {
-- SRB2 data structures
p = player,
-- Snolf shot state
state = STATE_WAITING,
statetimer = 0,
hinttimer = 0,
hdrive = 0,
vdrive = 0,
chargegoingback = false,
verticalfirst = false,
-- previous tick state
prev = { momz = 0 },
-- controls
ctrl = { jmp = 0, spn = 0, up = 0, dn = 0, ca1 = 0, ca2 = 0, ca3 = 0 },
mull_button = 'spn',
-- mulligan points
mull_pts = {},
save_pts = {},
--stats
shotcount = 0,
mullcount = 0,
--collision check
collided = nil
}
end
-- resetting state to be used on death or level change
reset_state = function(snlf, leave_mulls)
boss_level = false
snlf.prev = { momz = 0 }
snlf.hdrive = 0
snlf.vdrive = 0
update_state(snlf, STATE_WAITING)
if not leave_mulls then
snlf.mull_pts = {}
end
end
-- Is this Snolf?
is_snolf = function(mo)
if not mo or not mo.player or not mo.skin then
return false
end
return mo.skin == "snolf"
end
-- Is this player Snolf or is Everybody's Snolf on?
is_snolfing = function(mo)
if not mo or not mo.player or not mo.skin then
return false
end
return is_snolf(mo) or options.everybodys_snolf
end
-- Is this player either of the above or are they playing as Kirby with the
-- Golf ability?
is_golfing = function(mo)
if not mo or not mo.player or not mo.skin then
return false
end
return is_snolfing(mo) or (mo.skin == "kirby" and kirby_snolf_ability
and mo.player.kvars.secretability
and mo.player.kvars.ability == kirby_snolf_ability)
end
is_anyone_snolf = function()
for p in players.iterate do
if is_snolf(p.mo) then
return true
end
end
return false
end
is_anyone_snolfing = function()
for p in players.iterate do
if is_snolfing(p.mo) then
return true
end
end
return false
end
reversed_gravity = function(mo)
return P_GetMobjGravity(mo) > 0
end
is_golf_setup = function(mo)
return is_golfing(mo) and mo.player.snolf
end
at_rest = function(snlf)
-- player is on the ground and not on a waterslide and not moving
local momx = snlf.p.mo.momx - snlf.p.cmomx
local momy = snlf.p.mo.momy - snlf.p.cmomy
return P_IsObjectOnGround(snlf.p.mo) and snlf.p.pflags & PF_SLIDING == 0 and
momx == 0 and momy == 0
end
take_a_mulligan = function(snlf, pts, dont_play_sound)
local lm = pts[#pts] -- last mulligan point
local mo = snlf.p.mo
-- if we're still at the last mulligan point remove it and go back one
if lm and same_position(lm, mo) and lm.momx == nil then
table.remove(pts, #pts)
lm = pts[#pts]
end
if lm then
if not dont_play_sound then
S_StartSound(mo, sfx_mixup)
end
if snlf.p.powers[pw_carry] == CR_MINECART then
mo.tracer.target = nil
P_KillMobj(mo.tracer, mo, mo)
end
mo.tracer = nil
snlf.p.powers[pw_carry] = 0
P_SetOrigin(mo, lm.x, lm.y, lm.z)
local momx, momy, momz = lm.momx or 0, lm.momy or 0, lm.momz or 0
mo.momx = momx
mo.momy = momy
P_SetObjectMomZ(mo, momz)
snlf.hinttimer = 0
if lm.rings ~= nil then snlf.p.rings = lm.rings end
if lm.state ~= nil then snlf.state = lm.state end
if lm.hdrive ~= nil then snlf.hdrive = lm.hdrive end
if lm.vdrive ~= nil then snlf.vdrive = lm.vdrive end
if lm.chargegoingback ~= nil then snlf.chargegoingback = lm.chargegoingback end
if lm.flags ~= nil then mo.flags = lm.flags end
if lm.flags2 ~= nil then mo.flags2 = lm.flags2 end
if lm.eflags ~= nil then mo.eflags = lm.eflags end
if lm.pflags ~= nil then
snlf.p.pflags = lm.pflags
else
snlf.p.pflags = $1 & ~PF_JUMPED & ~PF_THOKKED & ~ PF_SHIELDABILITY
end
if snlf.p.pflags & PF_FINISHED == 0 then
snlf.mullcount = $1 + 1
end
override_controls(snlf)
end
end
same_position = function(pt1, pt2)
return pt1.x == pt2.x and pt1.y == pt2.y and pt1.z == pt2.z
end
-- converts a value on a linear scale with min value 0 and max value m to a
-- sinusoidal scale with the same limits.
-- m/2(1-cos(pi*x/m))
sinusoidal_scale = function(x, m)
local xf, mf = x*FRACUNIT, m*FRACUNIT
-- is this this too computationally expensive?
local angle = FixedAngle(FixedDiv(FixedMul(AngleFixed(ANGLE_180),xf),mf))
return FixedRound(FixedMul(FRACUNIT - cos(angle),mf)/2) / FRACUNIT
end
get_charge_increment = function(snlf)
local increment = 1
if in_black_core() then
-- double charge rate for the last few bosses
increment = $1 * 2
end
if snlf.p.powers[pw_super] > 0 then
-- double charge rate for Super Snolf
increment = $1 * 2
if snlf.p.hyper and snlf.p.hyper.capable then
-- double again for Hyper Snolf
increment = $1 * 2
end
end
if snlf.p.powers[pw_sneakers] > 0 then
-- double charge rate for Speed Shoes
increment = $1 * 2
end
return increment
end
-- the last few bosses are very difficult
-- so I'm going to give the player a few bonuses if they've gotten that far
in_black_core = function()
local black_core_maps = {
[25]=true, -- Metal Sonic Race
[26]=true, -- Metal Sonic Fight
[27]=true} -- Metal Robotnik Fight
return black_core_maps[gamemap]
end
-- situations where we want Snolf to be able to shoot mid-air
allow_air_snolf = function(snlf)
if not is_snolfing(snlf.p.mo) then
return false
end
-- air snolf option
if options.snolf_air_shot then
return true
-- Super Snolf
elseif is_snolf(snlf.p.mo) and snlf.p.powers[pw_super] > 0 then
return true
-- in the vacuum of space
elseif snlf.p.powers[pw_spacetime] > 0 then
return true
end
-- for the last three bosses
return in_black_core()
end
override_controls = function(snlf)
local player = snlf.p
player.jumpfactor = 0 -- disable jump
if player.charability2 == CA2_SPINDASH then
player.charability2 = CA2_NONE --disable spindash
end
if options.snolf_ground_control and snlf.state == STATE_WAITING then
player.accelstart = 96
player.acceleration = 40
else
player.accelstart = 0
player.acceleration = 0
end
end
-- assume players are spheres of diameter = spinheight
are_touching = function(play1, play2)
local r1 = P_GetPlayerSpinHeight(play1)/2/FRACUNIT
local r2 = P_GetPlayerSpinHeight(play2)/2/FRACUNIT
local x = abs(play1.mo.x - play2.mo.x)/FRACUNIT
local y = abs(play1.mo.y - play2.mo.y)/FRACUNIT
local z = abs(play1.mo.z - play2.mo.z)/FRACUNIT
return x*x+y*y+z*z<r1*r1+r2*r2+2*r1*r2
end
option_toggle = function(option_name, arg, player)
local current_bool = options[option_name]
if arg == nil then
options[option_name] = not $1
elseif arg == "0" or arg == "off" or arg == "false" then
options[option_name] = false
elseif arg == "1" or arg == "on" or arg == "true" then
options[option_name] = true
else
CONS_Printf(player, option_name.." should be called with either 'on', 'off', or no argument")
return
end
print2(option_name.." has been "..(options[option_name] and "enabled" or "disabled")..".")
end
snolfify_name = function(orig_name)
orig_name = orig_name:lower()
-- bafflingly the game uses a control character in character names
local sep = string.char(30)
-- hardcoding some names for certain characters, including from other mods
local name_replacement = {
sonic = "Snolf",
knuckles = "Knolf",
knux = "Knolf",
tails = "Tolf",
shadow = "Shdolf",
silver = "Slolf",
rouge = "Roulfe",
robotnik = "Robotnolf"
}
for k, v in pairs(name_replacement) do
if orig_name:find(k) ~= nil then
return orig_name:gsub(k, v)
end
end
local name_lookup = {
amy = "Amy Rolf",
metal = "M"..sep.."Snolf",
gamma = "E-102 Golf",
dickkickem = "Dolf Snolfem",
steve = "Stove"}
name_lookup["k"..sep.."t"..sep.."e"] = "Knolf"
name_lookup["amy"..sep.."r"] = "Amy Rolf"
name_lookup["m"..sep.."k"] = "M"..sep.."Knolf"
name_lookup["egg robo"] = "Egg Robolf"
local consonants = "bcdfghjklmnpqrstvwxyz"
local name = name_lookup[orig_name]
if name ~= nil then
return name
end
local i = #orig_name
-- iterate backwards till we find a G
repeat
i = $1 - 1
until i == 0 or orig_name:sub(i,i) == "g"
if i > 0 then
return orig_name:sub(1, i) .. "olf"
end
i = #orig_name
-- iterate backwards till we find an O
repeat
i = $1 - 1
until i == 0 or orig_name:sub(i,i) == "o"
if i > 0 then
return orig_name:sub(1, i) .. "lf"
end
i = 0
-- iterate over letters till find a consonant
repeat
i = $1 + 1
until i > #orig_name or consonants:find(orig_name:sub(i,i)) ~= nil
-- then iterate until something that is not a consonant is found
repeat
i = $1 + 1
until i > #orig_name or consonants:find(orig_name:sub(i,i)) == nil
if i ~= #orig_name and i > 1 then
return orig_name:sub(1, i-1) .. "olf"
end
return orig_name
end
on_hit_boss = function(boss, pmo)
if options.snolf_shot_on_hit_boss and pmo.player and pmo.player.snolf
and is_snolfing(pmo) and pmo.player.snolf.state == STATE_WAITING then
update_state(pmo.player.snolf, STATE_READY)
end
end
-- Predict the trajectory of the currently charging shot
draw_trajectory = function(snlf)
local h = sinusoidal_scale(snlf.hdrive, h_meter_limit(snlf.p))
local v = sinusoidal_scale(snlf.vdrive, v_meter_limit(snlf.p))
local mo = snlf.p.mo
local x, y, z = mo.x, mo.y, mo.z -- current position
local mx = FixedMul(h*FRACUNIT, cos(mo.angle)) -- force we will take off with
local my = FixedMul(h*FRACUNIT, sin(mo.angle))
local mz = v*FRACUNIT
local slope = mo.standingslope
if slope then
local hcomp = FixedMul(mz, sin(slope.zangle))
mz = FixedMul($1, cos(slope.zangle))
mx = $1 - FixedMul(hcomp,cos(slope.xydirection))
my = $1 - FixedMul(hcomp,sin(slope.xydirection))
end
-- The full x and y force will only be applied once
x = $1 + mx
y = $1 + my
-- On the first frame friction will be applied to the player's momentum
-- Thereafter the player will airborne where there is no friction
mx = FixedMul($1, mo.friction)
my = FixedMul($1, mo.friction)
-- Hacky but this makes the path turn out correct
-- I think perhaps gravity is not applied on the first frame (on the ground)
-- sot his counteracts it?
local g = P_GetMobjGravity(mo)
local grev = reversed_gravity(mo)
local dummy = P_SpawnMobj(x, y, z, MT_PLAYER)
if grev then dummy.flags2 = $1 | MF2_OBJECTFLIP end
if grev then mz = -$1 end
mz = $1 - g
local blocked = false
-- Draw a shot trajectory
local i = 0
local prev_floorz = mo.floorz + 1
local prev_ceilingz = mo.ceilingz - 1
while not blocked and i < 200 do
g = P_GetMobjGravity(dummy)
-- according to the wiki gravity is applied twice if momz == 0
if mz == 0 then
mz = $1 + g
end
-- apply gravity
mz = $1 + g
dummy.z = $1 + mz
local hblocked = not P_TryMove(dummy, x+mx, y+my, true)
local fblocked = dummy.z <= prev_floorz
local cblocked = mo.height + dummy.z >= prev_ceilingz
blocked = hblocked or fblocked or cblocked
x = $1 + mx
y = $1 + my
z = $1 + mz
-- spawn a trail
local dot = P_SpawnMobj(x, y, z, MT_CYBRAKDEMON_TARGET_DOT)
i = $1+1
prev_ceilingz = dummy.ceilingz
prev_floorz = dummy.floorz
end
if blocked then
local reticule = P_SpawnMobj(dummy.x, dummy.y, dummy.z, MT_CYBRAKDEMON_TARGET_DOT)
reticule.sprite = SPR_TARG
reticule.rollangle = leveltime*ANG1*3
end
dummy.type = MT_NULL
P_KillMobj(dummy)
end
h_meter_limit = function(player)
if player.hyper and player.hyper.capable and player.powers[pw_super] then
return H_METER_LENGTH*2
end
return H_METER_LENGTH
end
v_meter_limit = function(player)
if player.hyper and player.hyper.capable and player.powers[pw_super] then
return V_METER_LENGTH*2
end
return V_METER_LENGTH
end
-- I wanted some characters to be considered heavier than others but weight is
-- not an attribute characters have. I have opted for some weird logic instead.
-- A character's mass is considered to be inverse of their jumpfactor.
-- So e.g. Knuckles is heavier than Sonic who is heavier than Amy.
calculate_weight = function(mo)
local jumpfactor = skins[mo.skin].jumpfactor
if jumpfactor == 0 then jumpfactor = FRACUNIT end -- default in case it's 0
local mass = FixedDiv(FRACUNIT, jumpfactor)
-- try to guess if the character is a robot, Robotnik or Milne
-- if so, double their weight
local skin = skins[mo.skin]
local name = string.lower(skin.realname)
if skin.flags & SF_MACHINE > 0 or string.find(name,'milne') or
string.find(name,'eggman') or string.find(name,'robotnik') then
mass = $1*2
end
--or if it it's Tails Doll (or anything else named doll) reduce the weight
if string.find(name, 'doll') ~= nil then
mass = $1/2
end
return mass
end
shot_charge = function(snlf, vertical)
local increment = get_charge_increment(snlf)
if snlf.chargegoingback then
increment = $1 * -1
end
snlf.p.pflags = $1 | PF_STARTDASH | PF_SPINNING -- force spindash state
local charge = vertical and snlf.vdrive or snlf.hdrive
local limit = vertical and h_meter_limit(snlf.p) or v_meter_limit(snlf.p)
if charge >= limit then
snlf.chargegoingback = true
elseif charge <= 0 then
if vertical then
snlf.vdrive = 0
else
snlf.hdrive = 0
end
snlf.chargegoingback = false
end
if vertical then
snlf.vdrive = $1 + increment
else
snlf.hdrive = $1 + increment
end
if options.snolf_shot_guide then
draw_trajectory(snlf)
end
end
update_state = function(snolf, state)
snolf.state = state
snolf.statetimer = 0
snolf.hinttimer = 0
end
shoot = function(snlf)
local p = snlf.p
local mo = p.mo
S_StartSound(mo, sfx_zoom)
local h = sinusoidal_scale(snlf.hdrive, h_meter_limit(p))
local v = sinusoidal_scale(snlf.vdrive, v_meter_limit(p))
P_InstaThrust(mo, mo.angle, h*FRACUNIT)
P_SetObjectMomZ(mo, v*FRACUNIT)
-- change some player state
if v > 0 then
p.pflags = $1 | PF_JUMPED
else
nudge_up(mo)
end
if p.pflags & PF_FINISHED == 0 then
snlf.shotcount = $1 + 1
end
mo.state = S_PLAY_ROLL
update_state(snlf, STATE_WAITING)
end
nudge_up = function(mo)
-- move slightly off the ground immediately so snolf doesn't
-- count as being classed as on the ground for the frame
-- hacky thing to make certain things work more smoothly
P_SetOrigin(mo, mo.x, mo.y, mo.z + (reversed_gravity(mo) and -1 or 1))
end
update_hud = function()
if options.snolf_hud_mode > 0 then
hud.disable("lives")
else
hud.enable("lives")
end
end
-------------------
-- HUD functions --
-------------------
-- shot meter
hud.add( function(v, player, camera)
if not is_golf_setup(player.mo) then return end
local snlf = player.snolf
local state = snlf.state
if state != STATE_CHARGE1 and state != STATE_CHARGE2 then return end
local meter = v.getSpritePatch(SPR_SFMR) -- shot meter sprite
local harrow = v.getSpritePatch(SPR_SFAH, 0, 4) -- shot meter arrow sprite 1
local varrow = v.getSpritePatch(SPR_SFAV, 0, 5) -- shot meter arrow sprite 2
local hpos = sinusoidal_scale(snlf.hdrive, h_meter_limit(player))
local vpos = sinusoidal_scale(snlf.vdrive, v_meter_limit(player))
if hpos < 1 then hpos = 1 end
if vpos < 1 then vpos = 1 end
v.draw(158, 103, meter)
if state == STATE_CHARGE2 or not snlf.verticalfirst then
v.draw(160+hpos, 151, harrow)
end
if state == STATE_CHARGE2 or snlf.verticalfirst then
v.draw(159, 150-vpos, varrow)
end
end, "game")
-- shots count
hud.add( function(v, player, camera)
if not is_golf_setup(player.mo) or not is_snolfing(player.mo) then return end
local hud_shots = v.getSpritePatch(SPR_SFST) -- SHOTS HUD element
local shotcount = player.snolf.shotcount + player.snolf.mullcount
if player.pflags & PF_FINISHED == 0 or player.exiting > 0 then
v.draw(16, 58, hud_shots, V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOTOP)
v.drawNum(96, 58, shotcount, V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOTOP)
end
end, "game")
-- tip for if you're stuck unable to take a shot
hud.add( function(v, player, camera)
if not is_golf_setup(player.mo) or not is_snolfing(player.mo)
or player.snolf.state ~= STATE_WAITING or not player.snolf.mull_button
or player.snolf.hinttimer < TICRATE*10 then
return
end
local bname = button_names[player.snolf.mull_button]
local hint = "Hold "..bname.." to retake shot"
local colourflag = (player.snolf.hinttimer/TICRATE)%2 == 0 and V_YELLOWMAP or V_REDMAP
v.drawString(16, 166 , hint, colourflag|V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "thin")
end, "game")
-- everybody's snolf life icon
hud.add ( function(v, player, camera)
if options.snolf_hud_mode == 1 and player.mo and player.mo.skin then
local mo = player.mo
local life_x = v.getSpritePatch(SPR_SFHX)
v.draw(38, 186 , life_x, V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
local life_icon_box = v.getSpritePatch(SPR_LVBX)
local life_icon = v.getSprite2Patch(mo.skin, SPR2_XTRA, player.powers[pw_super] > 0)
v.drawScaled(16*FRACUNIT, 176*FRACUNIT, FRACUNIT/2, life_icon_box,
V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
v.drawScaled(16*FRACUNIT, 176*FRACUNIT, FRACUNIT/2, life_icon,
V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM,
v.getColormap(mo.skin, mo.color))
if is_snolfing(mo) and options.snolf_inf_lives then
local infinity = v.getSpritePatch(SPR_INFL)
v.draw(63, 185, infinity, V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
else
v.drawString(74, 184, player.lives, V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "right" )
end
local hudname = skins[mo.skin].hudname
if is_snolfing(mo) and options.everybodys_snolf then
hudname = snolfify_name(hudname)
end
if #hudname > 7 then
v.drawString(34, 176, hudname, V_YELLOWMAP|V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "thin")
elseif #hudname > 6 then
v.drawString(74, 176, hudname, V_YELLOWMAP|V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "thin-right")
elseif #hudname == 6 then
v.drawString(34, 176, hudname, V_YELLOWMAP|V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "left")
elseif #hudname < 6 then
v.drawString(74, 176, hudname, V_YELLOWMAP|V_HUDTRANS|V_SNAPTOLEFT|V_SNAPTOBOTTOM, "right")
end
end
end, "game")
-----------
-- hooks --
-----------
-- main hook
addHook("PreThinkFrame", function()
for boss in pairs(bosses_health) do
if not boss or not boss.valid then
bosses_health[boss] = nil
end
end
for player in players.iterate do
-- don't do anything if we're not golfing
if not is_golfing(player.mo) then continue end
if player.snolf == nil then
snolf_setup(player)
end
-- set some local variables as shortcuts
local p, mo, snlf = player, player.mo, player.snolf
if p.playerstate == PST_DEAD then continue end
-- check controls
snlf.ctrl.jmp = p.cmd.buttons & BT_JUMP and $1+1 or 0
snlf.ctrl.spn = p.cmd.buttons & BT_SPIN and $1+1 or 0
snlf.ctrl.up = p.cmd.forwardmove > 20 and $1+1 or 0
snlf.ctrl.dn = p.cmd.forwardmove < -20 and $1+1 or 0
snlf.ctrl.ca1 = p.cmd.buttons & BT_CUSTOM1 and $1+1 or 0
snlf.ctrl.ca2 = p.cmd.buttons & BT_CUSTOM2 and $1+1 or 0
snlf.ctrl.ca3 = p.cmd.buttons & BT_CUSTOM3 and $1+1 or 0
local braking = snlf.ctrl.jmp > 0
-- skim across water
if mo.momz < 0 and p.speed > SKIM_THRESHOLD
and mo.eflags & MFE_TOUCHWATER > 0
and p.pflags & PF_SLIDING == 0
and R_PointToAngle2(0, 0, p.speed, -mo.momz) < SKIM_ANLGE then
mo.momx = FixedMul($1, SKIM_FACTOR)
mo.momy = FixedMul($1, SKIM_FACTOR)
P_SetObjectMomZ(mo, -mo.momz)
S_StartSound(mo, sfx_splish)
if boss_level and options.snolf_shot_on_touch_ground_when_in_boss
and snlf.state == STATE_WAITING and is_snolfing(mo) then
update_state(snlf, STATE_READY)
end
end
-- check if we landed this turn
if mo.eflags & MFE_JUSTHITFLOOR > 0
and p.mo.rollangle <= ANG60 and p.mo.rollangle >= ANG350 - ANG30 - ANG20 then --allow X Momentum faceplants
--makes bosses easier
if boss_level and options.snolf_shot_on_touch_ground_when_in_boss
and snlf.state == STATE_WAITING and is_snolfing(mo) then
update_state(snlf, STATE_READY)
end
-- if going fast enough when Snolf hits the ground, bounce
local bounce_l = BOUNCE_LIMIT
local bounce_f = BOUNCE_FACTOR
-- if player is holding jump they are braking so let them get out of bouncing easier
if braking then
bounce_l = BOUNCE_LIMIT * 2
bounce_f = BOUNCE_FACTOR * 2 / 3
end
if abs(snlf.prev.momz) > bounce_l and p.playerstate ~= PST_DEAD
and mo.state ~= S_PLAY_BOUNCE and mo.state ~= S_PLAY_BOUNCE_LANDING
and p.pflags & PF_SLIDING == 0
and not (p.gemmasmash and p.gemmasmash > 0) then
P_SetObjectMomZ(mo, FixedMul(snlf.prev.momz, bounce_f) * (reversed_gravity(mo) and 1 or -1))
snlf.p.pflags = $1 | PF_JUMPED | PF_THOKKED | PF_SHIELDABILITY
nudge_up(mo)
end
end
-- try to set a mulligan point
if at_rest(snlf) and not p.onconveyor and p.powers[pw_carry] == 0 then
local mo, mulls = snlf.p.mo, snlf.mull_pts
local lm = mulls[#mulls] -- last mulligan point
-- if we don't have a mulligan point yet
-- or if our last one does not match our current position
if not lm or not same_position(mo, lm) then
-- if there's already ten mulligan points stored then remove one
if #mulls > 9 then
table.remove(mulls, 1)
end
table.insert(mulls, {x = mo.x, y = mo.y, z = mo.z})
end
end
-- state dependent update
-- if being carried, just revert state to waiting
if p.powers[pw_carry] ~= 0 and snlf.state ~= STATE_WAITING then
update_state(snlf, STATE_WAITING)
-- waiting to come to rest
elseif snlf.state == STATE_WAITING then
--allow a shot to happen
if at_rest(snlf) or allow_air_snolf(snlf) then
update_state(snlf, STATE_READY)
override_controls(snlf)
end
-- ready to start taking a shot
elseif snlf.state == STATE_READY then
-- jump is pressed
if snlf.ctrl.jmp == 1 then
snlf.hdrive = 1
snlf.vdrive = 1
S_StartSoundAtVolume(mo, sfx_spndsh, 64)
snlf.chargegoingback = false
update_state(snlf, STATE_CHARGE1)
snlf.verticalfirst = snlf.ctrl.up > 0
end
-- choosing horizontal force
elseif snlf.state == STATE_CHARGE1 then
-- jump is pressed
if snlf.ctrl.jmp == 1 then
if snlf.ctrl.dn > 0 then
if snlf.verticalfirst then
snlf.hdrive = 0
else
snlf.vdrive = 0
end
shoot(snlf)
else
S_StartSoundAtVolume(mo, sfx_spndsh, 100)
snlf.chargegoingback = false
update_state(snlf, STATE_CHARGE2)
end
else
shot_charge(snlf, snlf.verticalfirst)
end
-- choosing vertical force
elseif snlf.state == STATE_CHARGE2 then
-- jump is pressed
if snlf.ctrl.jmp == 1 then
shoot(snlf)
else
shot_charge(snlf, not snlf.verticalfirst)
end
end
-- X Momentum trick failed
if is_snolf(mo) and player.isxmomentum and mo.state == S_PLAY_FACEPLANT then
-- stick Snolf in place
P_InstaThrust(mo,0,0)
end
-- enable jumping while on a water slide
if p.pflags & PF_SLIDING ~= 0 and p.jumpfactor == 0 then
p.jumpfactor = FRACUNIT
elseif P_IsObjectOnGround(mo) then
if player.milnekick and player.milnekick > 0 then
player.accelstart = 96
player.acceleration = 40
else
-- I don't like forcing stat changes every frame but other mods can
-- also mess with these values so we need to be defensive about it
-- to ensure Snolf works correctly with them
override_controls(snlf)
if mo.momx > 0 or mo.momy > 0 then
--braking
if braking
and snlf.state == STATE_WAITING
and snlf.statetimer > TICRATE/5 then
if p.skidtime == 0 then
p.pflags = $1 & ~PF_SPINNING
p.skidtime = TICRATE/2
S_StartSound(mo, sfx_skid)
elseif p.skidtime == 1
p.skidtime = $1 + 1
end
else
p.pflags = $1 | PF_SPINNING -- force spinning flag
end
end
end
elseif not P_IsObjectOnGround(mo) then
-- Give back jump when in the air. It will be taken away again on
-- landing. This is done so that players can jump off objects like
-- the rollout rocks in Red Volcano Zone
p.jumpfactor = skins[mo.skin].jumpfactor
end
-- eat jump inputs entirely so other characters can't use jump abilties
-- while taking a shot when using Everybody's Snolf
if snlf.state != STATE_WAITING or snlf.statetimer < TICRATE/5 then
p.cmd.buttons = $1 & (!BT_JUMP)
end
-- store certain state attributes so we can check for changes next tick
snlf.prev.momz = player.mo.momz
-- state timer
snlf.statetimer = $1 + 1
snlf.hinttimer = $1 + 1
-- don't display hint if player is on waterslide or rollout rock
if p.pflags & PF_SLIDING ~= 0 or mo.tracer then
snlf.hinttimer = 0
end
-- No Kirby zone!
-- Don't apply everything below here to Kirby with the golf ability
if not is_snolfing(mo) then continue end
-- take a mulligan
if snlf.ctrl[snlf.mull_button] == TICKS_FOR_MULLIGAN then
take_a_mulligan(snlf, snlf.mull_pts)
end
-- save and load player state manually
if options.snolf_save_states then
-- save player state
if snlf.ctrl.ca1 == 1 then
if #snlf.save_pts > 9 then
table.remove(snlf.save_pts, 1)
end
local state = {
x = mo.x,
y = mo.y,
z = mo.z,
momx = mo.momx,
momy = mo.momy,
momz = mo.momz,
rings = p.rings,
state = snlf.state,
hdrive = snlf.hdrive,
vdrive = snlf.vdrive,
chargegoingback = snlf.chargegoingback,
flags = mo.flags,
flags2 = mo.flags2,
eflags = mo.eflags,
pflags = p.pflags
}