-
Notifications
You must be signed in to change notification settings - Fork 1
/
telib.mod.gml
6980 lines (5826 loc) · 205 KB
/
telib.mod.gml
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
/*
Don't call scripts from this file directly, instead use the global LWO "scr", like so:
scr = mod_variable_get("mod", "teassets", "scr")
script_ref_call(scr.name, ...args)
To get NTTE object's instance list, use the global LWO "obj", like so:
obj = mod_variable_get("mod", "teassets", "obj")
with(instances_matching_ne(obj.Cat, "id")){
// Instances are not guaranteed to exist, so either prune the list using some form of instances_matching or check each one manually with instance_exists
}
To get an NTTE asset's index, use the global LWOs "spr" and "snd", like so:
snd = mod_variable_get("mod", "teassets", "snd")
spr = mod_variable_get("mod", "teassets", "spr")
sprite_index = spr.PalankingIdle
mask_index = spr.msk.Palanking
snd_hurt = snd.PalankingHurt
sound_play_music(snd.mus.SealKing)
*/
#define init
mod_script_call("mod", "teassets", "ntte_init", script_ref_create(init));
// Compile Script References:
for(var i = 1; true; i++){
var _scrName = script_get_name(i);
if(_scrName != undefined){
if(_scrName not in scr){
lq_set(scr, _scrName, script_ref_create(i));
}
}
else break;
}
// Bind Events:
global.rad_path_bind = script_bind(CustomEndStep, rad_path_step, 0, false);
global.floor_reveal_bind = script_bind(CustomDraw, floor_reveal_draw, -8, false);
// Custom Object Related:
obj_create_event_ref_map = mod_variable_get("mod", "teassets", "obj_create_event_ref_map");
obj_event_index_list_map = mod_variable_get("mod", "teassets", "obj_event_index_list_map");
obj_parent_map = mod_variable_get("mod", "teassets", "obj_parent_map");
obj_search_bind_map = mod_variable_get("mod", "teassets", "obj_search_bind_map");
event_obj_list_map = mod_variable_get("mod", "teassets", "event_obj_list_map");
depth_obj_draw_event_instance_map = mod_variable_get("mod", "teassets", "depth_obj_draw_event_instance_map");
object_event_index_list_map = mod_variable_get("mod", "teassets", "object_event_index_list_map");
event_varname_list = mod_variable_get("mod", "teassets", "event_varname_list");
// Lag Debugging:
lag_bind = ds_map_create();
// Projectile Sprite Team Variants:
var _spriteTeamVariantTable = mod_variable_get("mod", "teassets", "sprite_team_variant_table");
sprite_team_map = ds_map_create(); // Sprite -> Team
sprite_team_sprite_list_map = ds_map_create(); // Sprite -> [Enemy Sprite, Ally Sprite, Popo Sprite]
obj_sprite_team_obj_list_table = ds_map_create(); // Object -> (Sprite -> [Enemy Object, Ally Object, Popo Object])
with(_spriteTeamVariantTable){
var _teamVariantList = self,
_teamVariantCount = array_length(_teamVariantList),
_teamSpriteList = array_create(_teamVariantCount, -1),
_teamObjList = array_create(_teamVariantCount, -1);
// Populate Sprite & Object Lists:
for(var _team = 0; _team < _teamVariantCount; _team++){
var _variant = _teamVariantList[_team];
if(array_length(_variant)){
_teamSpriteList[_team] = (is_string(_variant[0]) ? lq_get(spr, _variant[0]) : _variant[0]);
if(array_length(_variant) > 1){
_teamObjList[_team] = _variant[1];
}
}
}
// Compile Sprite Team Maps:
with(_teamSpriteList){
var _sprite = self;
if(sprite_exists(_sprite)){
if(!ds_map_exists(sprite_team_sprite_list_map, _sprite)){
sprite_team_sprite_list_map[? _sprite] = _teamSpriteList;
}
if(!ds_map_exists(sprite_team_map, _sprite)){
sprite_team_map[? _sprite] = sprite_start_team + array_find_index(_teamSpriteList, _sprite);
}
}
}
// Compile Sprite Team Object Table:
with(_teamObjList){
var _obj = self;
if(!is_real(_obj) || object_exists(_obj)){
if(!ds_map_exists(obj_sprite_team_obj_list_table, _obj)){
var _spriteTeamObjListMap = ds_map_create();
with(_spriteTeamVariantTable){
var _tVariantList = self,
_tVariantCount = array_length(_tVariantList),
_tSpriteList = array_create(_tVariantCount, -1),
_tObjList = array_create(_tVariantCount, -1);
// Populate Sprite & Object Lists:
for(var _team = 0; _team < _tVariantCount; _team++){
var _variant = _tVariantList[_team];
if(array_length(_variant)){
_tSpriteList[_team] = (is_string(_variant[0]) ? lq_get(spr, _variant[0]) : _variant[0]);
if(array_length(_variant) > 1){
_tObjList[_team] = _variant[1];
}
}
}
// Add Object Lists to Sprite Map:
for(var _team = 0; _team < _tVariantCount; _team++){
if(_tObjList[_team] == _obj){
var _sprite = _tSpriteList[_team];
if(!ds_map_exists(_spriteTeamObjListMap, _sprite)){
_spriteTeamObjListMap[? _sprite] = _tObjList;
}
}
}
}
obj_sprite_team_obj_list_table[? _obj] = _spriteTeamObjListMap;
}
}
}
}
// sleep_max():
global.sleep_max = 0;
#define cleanup
mod_script_call("mod", "teassets", "ntte_cleanup", script_ref_create(cleanup));
#macro lag_bind global.debug_lag_bind
#macro obj_create_event_ref_map global.obj_create_event_ref_map
#macro obj_event_index_list_map global.obj_event_index_list_map
#macro obj_parent_map global.obj_parent_map
#macro obj_search_bind_map global.obj_search_bind_map
#macro event_obj_list_map global.event_obj_list_map
#macro depth_obj_draw_event_instance_map global.depth_obj_draw_event_instance_map
#macro object_event_index_list_map global.object_event_index_list_map
#macro event_varname_list global.event_varname_list
#macro sprite_start_team 1
#macro sprite_team_map global.sprite_team_map
#macro sprite_team_sprite_list_map global.sprite_team_sprite_list_map
#macro obj_sprite_team_obj_list_table global.obj_sprite_team_obj_list_table
#macro projectile_tag_data_is_setup ("ntte_projectile_tag_data" in GameCont)
#macro projectile_tag_data GameCont.ntte_projectile_tag_data
#macro projectile_tag_key_list projectile_tag_data.key_list
#macro projectile_tag_list projectile_tag_data.list
#macro projectile_tag_frame projectile_tag_data.frame
#define pass // context, ref, ...args
/*
Used to manually pass a context through 'script_ref_call' / 'call', as NTT versions before 9943 don't do it correctly
Args:
context - An instance to pass as the 'self', or an array for '[self, other]'
ref - The script reference to call
args - Arguments to pass to the script call
Ex:
call(scr.pass, [self, other], scr.weapon_get, "red", wep)
*/
var _context = argument[0],
_ref = argument[1];
if(_context != undefined){
// Collect Arguments:
if(argument_count > 2){
_ref = array_clone(_ref);
for(var i = 2; i < argument_count; i++){
array_push(_ref, argument[i]);
}
}
// Set Context & Call Script:
var _self = _context,
_other = _context;
if(is_array(_context)){
_self = _context[0];
_other = _context[1];
}
if(self != _self || other != _other){
with([_other]){
with([_self]){
return mod_script_call("mod", mod_current, "pass", undefined, _ref);
}
}
}
}
// Call Script:
return script_ref_call(_ref);
#define obj_add(_createEventRef)
/*
Adds an object to NT:TE's stored objects
Accepts a script reference to the given object's create event
*/
var _modType = _createEventRef[0],
_modName = _createEventRef[1],
_modScrtName = _createEventRef[2],
_name = string_copy(_modScrtName, 1, string_length(_modScrtName) - 7);
if(string_delete(_modScrtName, 1, string_length(_name)) == "_create"){
var _eventIndex = 0,
_eventIndexList = [];
// Store Events:
with(event_varname_list){
var _eventName = ((self == "script") ? self : string_delete(self, 1, 3));
if(mod_script_exists(_modType, _modName, _name + "_" + _eventName)){
array_push(_eventIndexList, _eventIndex);
}
_eventIndex++;
}
obj_create_event_ref_map[? _name] = _createEventRef;
obj_event_index_list_map[? _name] = _eventIndexList;
// Instance List:
if(_name not in obj){
lq_set(obj, _name, []);
}
return true;
}
return false;
#define obj_create(_x, _y, _name)
/*
Creates an NT:TE object, or a base game object if the name is an index for convenience
*/
// Normal Object:
if(is_real(_name) && object_exists(_name)){
return instance_create(_x, _y, _name);
}
// NT:TE Object:
if(ds_map_exists(obj_create_event_ref_map, _name)){
var _scrt = obj_create_event_ref_map[? _name],
_inst = script_ref_call(_scrt, _x, _y);
// No Return Value:
if(_inst == undefined || _inst == 0){
_inst = noone;
}
// Auto Assign Things:
if(is_real(_inst) && instance_exists(_inst)){
with(_inst){
var _modType = _scrt[0],
_modName = _scrt[1],
_isCustom = ds_map_exists(object_event_index_list_map, object_index),
_eventIndexList = obj_event_index_list_map[? _name];
// Set Name:
if(
!instance_is(self, WepPickup)
&& !instance_is(self, CarVenusFixed)
&& !instance_is(self, IceFlower)
&& !instance_is(self, Van)
&& !instance_is(self, mutbutton)
){
name = "NTTE" + _name;
}
if(!ds_map_exists(obj_parent_map, _name) && "ntte_name" in self && ntte_name != _name){
obj_parent_map[? _name] = ntte_name;
}
ntte_name = _name;
// Custom Objects:
if(_isCustom){
// Bind Events:
with(_eventIndexList){
var _eventVarName = event_varname_list[self];
if(variable_instance_get(other, _eventVarName) == undefined){
variable_instance_set(
other,
_eventVarName,
script_ref_create_ext(
_modType,
_modName,
_name + "_" + ((_eventVarName == "script") ? _eventVarName : string_delete(_eventVarName, 1, 3))
)
);
}
}
// Automatic Hittable Stuff:
if(instance_is(self, hitme)){
// Default Events:
if(instance_is(self, CustomHitme) || instance_is(self, CustomEnemy)){
if(on_hurt == undefined){
on_hurt = enemy_hurt; // Default doesn't set 'image_index = 0'
}
if(on_draw == undefined && instance_is(self, CustomEnemy)){
on_draw = draw_self_enemy; // Default doesn't face 'right'
}
}
// Fill HP:
if(my_health == 1){
if(instance_is(self, CustomHitme) || instance_is(self, CustomProp)){
my_health = maxhealth;
}
}
// Set Sprite:
if(sprite_index == -1 && "spr_idle" in self){
sprite_index = spr_idle;
}
}
}
// Bind Non-Custom Events:
else with(["begin_step", "step", "end_step", "draw"]){
var _eventName = self,
_eventVarName = "on_" + _eventName;
if(array_find_index(_eventIndexList, array_find_index(event_varname_list, _eventVarName)) >= 0){
if(_eventVarName not in other || variable_instance_get(other, _eventVarName) == undefined){
// Bind Draw Event:
if(_eventName == "draw"){
other.depth = floor(other.depth);
var _objDrawEventInstance = ds_map_find_value(depth_obj_draw_event_instance_map, other.depth - 1);
if(is_undefined(_objDrawEventInstance) || !instance_exists(_objDrawEventInstance)){
with(script_bind_draw(obj_draw, other.depth - 1)){
depth_obj_draw_event_instance_map[? depth] = self;
persistent = true;
}
}
}
// Add to Object List:
if(!ds_map_exists(event_obj_list_map, _eventName)){
event_obj_list_map[? _eventName] = [];
}
var _nameList = event_obj_list_map[? _eventName];
if(array_find_index(_nameList, _name) < 0){
array_push(_nameList, _name);
}
}
}
}
// Add Self to Object List:
var _objList = lq_get(obj, _name);
if(array_find_index(_objList, self) < 0){
array_push(_objList, self);
}
// Bind Object Search Script:
var _objSearchKey = _name + ":" + object_get_name(object_index);
if(!ds_map_exists(obj_search_bind_map, _objSearchKey)){
obj_search_bind_map[? _objSearchKey] = call(scr.ntte_bind_setup, script_ref_create(ntte_setup_obj_search, _name, object_index), object_index);
}
//return id;
}
}
return _inst;
}
// Return List of Objects:
if(_name == undefined){
var _list = [];
for(var i = lq_size(obj) - 1; i >= 0; i--){
array_push(_list, lq_get_key(obj, i));
}
return _list;
}
return noone;
#define ntte_setup_obj_search(_name, _object, _inst)
var _nameInst = instances_matching(_inst, "ntte_name", _name),
_gameIsUnpaused = !(instance_exists(PauseButton) || instance_exists(BackMainMenu) || UberCont.alarm2 > 0);
// Manage Object Instance Lists:
for(var _objName = _name; _objName != undefined; _objName = ds_map_find_value(obj_parent_map, _objName)){
// Prune Destroyed Instances:
var _objList = (
_gameIsUnpaused
? instances_matching_ne(lq_get(obj, _objName), "id")
: lq_get(obj, _objName)
);
lq_set(obj, _objName, _objList);
// Store New Instances, 'instance_copy()' Fix:
if(array_length(_nameInst)){
with(_nameInst){
if(array_find_index(_objList, self) < 0){
array_push(_objList, self);
}
}
}
}
// Stop Searching:
if(!array_length(lq_get(obj, _name))){
var _objSearchKey = _name + ":" + object_get_name(_object);
call(scr.ntte_unbind, obj_search_bind_map[? _objSearchKey]);
ds_map_delete(obj_search_bind_map, _objSearchKey);
}
#define ntte_begin_step
// sleep_max():
if(global.sleep_max > 0){
sleep(global.sleep_max);
global.sleep_max = 0;
}
// Bound Begin Step Events:
if(!obj_event_call("begin_step")){
ds_map_delete(event_obj_list_map, "begin_step");
}
// Lag Debugging:
lag_bind_call("begin_step");
// Intercept 'player_fire_at' Burst Controllers:
if("ntte_player_fire_at_burst_list" in GameCont && array_length(GameCont.ntte_player_fire_at_burst_list)){
GameCont.ntte_player_fire_at_burst_list = instances_matching_ne(GameCont.ntte_player_fire_at_burst_list, "id");
// Intercept Burst Controller Alarm Events:
if(current_frame_active){
var _inst = instances_matching_le(instances_matching_gt(GameCont.ntte_player_fire_at_burst_list, "alarm0", 0), "alarm0", 2);
if(array_length(_inst)){
with(_inst){
alarm0 = 0;
player_fire_at_call(player_fire_at_vars, script_ref_create(player_fire_at_call_event_perform, self, ev_alarm, 0), true, "", undefined);
if(instance_exists(self)){
if(alarm0 > 0){
alarm0 += 2;
}
if("delay" in self){
delay = max(delay, current_time_scale) + current_time_scale;
}
}
}
}
}
}
#define ntte_step
// Bound Step Events:
if(!obj_event_call("step")){
ds_map_delete(event_obj_list_map, "step");
}
// Lag Debugging:
lag_bind_call("step");
// Intercept 'player_fire_at' Burst Controllers:
if("ntte_player_fire_at_burst_list" in GameCont && array_length(GameCont.ntte_player_fire_at_burst_list)){
GameCont.ntte_player_fire_at_burst_list = instances_matching_ne(GameCont.ntte_player_fire_at_burst_list, "id");
// Set Laser Cannon Variables:
if(instance_exists(LaserCannon)){
var _inst = instances_matching(GameCont.ntte_player_fire_at_burst_list, "object_index", LaserCannon);
if(array_length(_inst)){
var _lastTimeScale = current_time_scale;
current_time_scale = epsilon;
with(_inst){
player_fire_at_call(player_fire_at_vars, script_ref_create(player_fire_at_call_event_perform, self, ev_step, ev_step_normal), true, "", undefined);
}
current_time_scale = _lastTimeScale;
}
}
// Intercept Burst Controller Step Events:
var _inst = instances_matching_le(GameCont.ntte_player_fire_at_burst_list, "delay", 2 * current_time_scale);
if(array_length(_inst)){
with(_inst){
delay = current_time_scale;
player_fire_at_call(player_fire_at_vars, script_ref_create(player_fire_at_call_event_perform, self, ev_step, ev_step_normal), true, "", undefined);
if(instance_exists(self)){
delay = max(delay, current_time_scale) + (2 * current_time_scale);
}
}
}
}
// Manage Projectile Trackers:
if(projectile_tag_data_is_setup && array_length(projectile_tag_list)){
var _tagData = projectile_tag_data,
_tagFrame = projectile_tag_frame,
_tagObjectList = undefined,
_tagIndex = 0;
with(_tagData.list){
if(end_frame <= _tagFrame){
if(child_tag_list == undefined){
var _tagNotUsed = true;
// Check if Tag is Used:
if(_tagObjectList == undefined){
_tagObjectList = [projectile, PlasmaImpact, CustomObject, CustomHitme, CustomProp, CustomEnemy, CustomScript, Burst, GoldBurst, HeavyBurst, HyperBurst, RogueBurst, SawBurst, SplinterBurst, NadeBurst, DragonBurst, ToxicBurst, FlameBurst, WaveBurst, SlugBurst, PopBurst, IonBurst, LaserCannon, SentryGun];
}
var _tagInstanceList = instances_matching(instances_matching(_tagObjectList, "creator", creator), "team", team);
if(array_length(_tagInstanceList)){
var _tagRawTeam = round(team),
_tagNum = 1 / (team - _tagRawTeam);
with(_tagInstanceList){
if(1 / (team - _tagRawTeam) == _tagNum){
_tagNotUsed = false;
break;
}
}
}
// Destroy Tag if Unused:
if(_tagNotUsed){
var _tagIndex = array_find_index(_tagData.list, self);
_tagData.key_list = array_delete(_tagData.key_list, _tagIndex);
_tagData.list = array_delete(_tagData.list, _tagIndex);
// Remove From Parent Tag's Child List:
if(parent_tag != undefined){
with(parent_tag){
if(child_tag_list != undefined){
child_tag_list = array_delete_value(child_tag_list, other);
if(!array_length(child_tag_list)){
child_tag_list = undefined;
}
}
}
}
}
}
}
// Early Exit (Sorted by End Frame):
else break;
}
// Projectile Tracking Frame:
projectile_tag_frame += current_time_scale;
}
#define ntte_end_step
// Bound End Step Events:
if(!obj_event_call("end_step")){
ds_map_delete(event_obj_list_map, "end_step");
}
// Lag Debugging:
lag_bind_call("end_step");
#define obj_draw
if(lag) trace_time();
// Bound Draw Events:
if(!obj_event_call("draw")){
ds_map_delete(depth_obj_draw_event_instance_map, depth);
if(!ds_map_size(depth_obj_draw_event_instance_map)){
ds_map_delete(event_obj_list_map, "draw");
}
instance_destroy();
exit;
}
if(lag) trace_time(`obj_draw, ${depth}`);
#define obj_event_call(_event)
/*
Calls the given event for the instances bound to it
*/
var _active = false;
if(ds_map_exists(event_obj_list_map, _event)){
with(event_obj_list_map[? _event]){
var _objName = self,
_objModRef = obj_create_event_ref_map[? _objName],
_objModType = _objModRef[0],
_objModName = _objModRef[1],
_objModScrt = _objName + "_" + _event;
if(mod_script_exists(_objModType, _objModName, _objModScrt)){
var _objList = lq_get(obj, _objName);
switch(_event){
case "draw": // Match Depth
var _objDepth = other.depth + 1,
_objDepthList = instances_matching(_objList, "depth", _objDepth);
// Instance Depth Changed:
if("depth_list_last" not in other || !array_equals(_objDepthList, other.depth_list_last)){
with(instances_matching_ne(_objList, "depth", _objDepth)){
depth = floor(depth);
if(depth == _objDepth){
array_push(_objDepthList, self);
}
else{
var _objDrawEventInstance = ds_map_find_value(depth_obj_draw_event_instance_map, depth - 1);
if(is_undefined(_objDrawEventInstance) || !instance_exists(_objDrawEventInstance)){
with(script_bind_draw(obj_draw, depth - 1)){
depth_obj_draw_event_instance_map[? depth] = self;
persistent = true;
}
}
}
}
}
other.depth_list_last = _objDepthList;
_objList = _objDepthList;
break;
default: // Prune Instance List
_objList = instances_matching_ne(_objList, "id");
lq_set(obj, _objName, _objList);
}
// Call Events:
if(array_length(_objList)){
_active = true;
// Drawing Visibility:
if(_event == "draw"){
_objList = instances_matching(_objList, "visible", true);
}
// GMS2:
try{
if(!null){
var _ref = script_ref_create_ext(_objModType, _objModName, _objModScrt);
with(_objList){
script_ref_call(_ref);
}
}
}
// GMS1:
catch(_error){
with(_objList){
mod_script_call_self(_objModType, _objModName, _objModScrt);
}
}
_active = true;
}
}
}
}
return _active;
#define lag_bind_call(_event)
/*
Overrides all "Custom" object step events for debugging lag
*/
if((ds_map_exists(lag_bind, _event) && lag_bind[? _event]) || lag){
lag_bind[? _event] = lag;
var _obj = [CustomObject, CustomHitme, CustomEnemy, CustomProp, CustomProjectile];
if(lag){
trace_time("pre-on_" + _event);
// Enable Events:
with(instances_matching_ne(_obj, "ntte_lag_" + _event, null)){
variable_instance_set(self, "on_" + _event, variable_instance_get(self, "ntte_lag_" + _event));
}
// Call Events:
var _inst = instances_matching_ne(_obj, "on_" + _event, null);
if(array_length(_inst)){
trace_time();
switch(_event){
case "begin_step" : with(_inst) event_perform(ev_step, ev_step_begin); break;
case "step" : with(_inst) event_perform(ev_step, ev_step_normal); break;
case "end_step" : with(_inst) event_perform(ev_step, ev_step_end); break;
}
trace_time(`on_${_event} (${array_length(_inst)})`);
// Disable Events:
with(instances_matching_ne(_inst, "id")){
variable_instance_set(self, "ntte_lag_" + _event, variable_instance_get(self, "on_" + _event));
variable_instance_set(self, "on_" + _event, []);
}
}
trace_time();
}
// Reset Events:
else with(instances_matching_ne(_obj, "ntte_lag_" + _event, null)){
variable_instance_set(self, "on_" + _event, variable_instance_get(self, "ntte_lag_" + _event));
variable_instance_set(self, "ntte_lag_" + _event, null);
}
}
/// SCRIPTS
#define draw_weapon(_sprite, _image, _x, _y, _angle, _angleMelee, _kick, _flip, _blend, _alpha)
/*
Drawing weapon sprites
Ex:
draw_weapon(sprBanditGun, gunshine, x, y, gunangle, 0, wkick, right, image_blend, image_alpha)
draw_weapon(sprPipe, 0, x, y, gunangle, wepangle, wkick, wepflip, image_blend, image_alpha)
*/
// Context Fix:
if(!is_real(self) || !instance_exists(self)){
with(UberCont){
return draw_weapon(_sprite, _image, _x, _y, _angle, _angleMelee, _kick, _flip, _blend, _alpha);
}
}
// Melee Offset:
if(_angleMelee != 0){
_angle += _angleMelee * (1 - (_kick / 20));
}
// Kick:
if(_kick != 0){
_x -= lengthdir_x(_kick, _angle);
_y -= lengthdir_y(_kick, _angle);
}
// Draw:
draw_sprite_ext(_sprite, _image, _x, _y, 1, _flip, _angle, _blend, _alpha);
#define draw_lasersight // x, y, dir, disMax=1000, width=1
/*
Performs hitscan and draws a laser sight line
Returns the line's ending position
Args:
x, y - The laser's starting position
dir - The laser's hitscan direction
disMax - How far the laser can travel, defaults to 1000
width - The laser's width, defaults to 1
*/
var _x = argument[0],
_y = argument[1],
_dir = argument[2],
_disMax = ((argument_count > 3) ? argument[3] : 1000),
_width = ((argument_count > 4) ? argument[4] : 1),
_dis = _disMax,
_disX = dcos(_dir),
_disY = -dsin(_dir),
_endX = _x + (_dis * _disX),
_endY = _y + (_dis * _disY);
// Context Fix:
if(!is_real(self) || !instance_exists(self)){
with(UberCont){
return draw_lasersight(_x, _y, _dir, _disMax, _width);
}
}
// Binary Collision Line Search:
var _wall = collision_line(_x, _y, _endX, _endY, Wall, false, false);
if(_wall){
while(_dis >= 1){
_dis /= 2;
if(_wall){
_endX -= _dis * _disX;
_endY -= _dis * _disY;
}
else{
_endX += _dis * _disX;
_endY += _dis * _disY;
}
_wall = collision_line(_x, _y, _endX, _endY, Wall, false, false);
}
}
// Draw:
draw_line_width(_x - 1, _y - 1, _endX - 1, _endY - 1, _width);
return [_endX, _endY];
#define draw_surface_scale(_surf, _x, _y, _scale)
/*
Draws a given surface at a given position with a given scale
Useful when working with surfaces that support pixel scaling
*/
draw_surface_ext(_surf, _x, _y, _scale, _scale, 0, c_white, draw_get_alpha());
#define string_split_nt(_string)
/*
Returns an array of the given string split into 'draw_text_nt()' tags and normal text
Ex:
string_split_nt("Cool@rBandit@2(sprBanditIdle:-0.4)") == [["", "Cool"], ["r", "Bandit"], ["2(sprBanditIdle:-0.4)", ""]]
*/
var _splitCharacter = "@",
_splitStringTagIsBlank = true,
_NTSplitStringList = [];
with(string_split(_string, _splitCharacter)){
var _splitString = self,
_splitStringTag = "";
if(_splitStringTagIsBlank){
_splitStringTagIsBlank = false;
}
else{
_splitStringTag = string_char_at(_splitString, 1);
switch(string_lower(_splitStringTag)){
case "": // CANCEL
_splitStringTagIsBlank = true;
break;
case "w":
case "s":
case "d":
case "r":
case "y":
case "g":
case "b":
case "p":
case "q": // BASIC
_splitString = string_delete(_splitString, 1, 1);
break;
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "(": // ADVANCED
var _splitStringTagStartPos = string_pos("(", _splitString),
_splitStringTagEndPos = string_pos(")", _splitString);
if(
_splitStringTagStartPos < _splitStringTagEndPos
&& (_splitStringTagStartPos == 1 || _splitStringTagStartPos == 2)
){
_splitStringTag = string_copy (_splitString, 1, _splitStringTagEndPos);
_splitString = string_delete(_splitString, 1, _splitStringTagEndPos);
}
else{
_splitStringTag = "";
}
break;
default: // NONE
_splitStringTag = "";
}
}
// Add to List:
if(_splitStringTag == "" && !_splitStringTagIsBlank && array_length(_NTSplitStringList)){
_NTSplitStringList[array_length(_NTSplitStringList) - 1][@ 1] += _splitCharacter + _splitString;
}
else{
array_push(_NTSplitStringList, [_splitStringTag, _splitString]);
}
}
return _NTSplitStringList;
#define string_delete_nt(_string)
/*
Returns a string of the given string without 'draw_text_nt()' tags
Ex:
string_delete_nt("@2(sprBanditIdle:0)@rBandit") == " Bandit"
string_width(string_delete_nt("@rHey")) == 3
*/
var _rawString = "";
with(string_split_nt(_string)){
var _tag = self[0],
_tagCharacter = string_char_at(_tag, 1);
// Fill Alignment Tags:
switch(_tagCharacter){
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
var _spr = string_split(string_copy(_tag, 2, string_pos(")", _tag) - 2), ":")[0];
if(
real(_spr) > 0
|| sprite_exists(asset_get_index(_spr))
|| sprite_exists(asset_get_index("spr" + _spr))
|| _spr == "sprButSmall"
|| _spr == "sprButBig"
){
if(string_width(" ") != 0){
// draw_text_nt uses width of "A" instead of " ", so this is slightly off on certain fonts
_rawString += string_repeat(" ", real(_tagCharacter) * (string_width("A") / string_width(" ")));
}
}
break;
}
// Add to String:
_rawString += self[1];
}
return _rawString;
#define string_space(_string)
/*
Returns the given string with spaces inserted between numbers<->letters, letters<->numbers, and lowercase<->uppercase
Ex:
string_space("CoolGuy123") == "Cool Guy 123"
*/
var _char = "",
_charLast = "",
_charNext = "";
for(var i = 0; i <= string_length(_string); i++){
_charNext = string_char_at(_string, i + 1);
if(
(_char != string_lower(_char) && (_charLast != string_upper(_charLast) || (_charLast != string_lower(_charLast) && _charNext != string_upper(_charNext))))
|| (string_digits(_char) != "" && string_letters(_charLast) != "")
|| (string_letters(_char) != "" && string_digits(_charLast) != "")
){
_string = string_insert(" ", _string, i);
i++;
}
_charLast = _char;
_char = _charNext;
}
return _string;
#define projectile_create // x, y, obj, dir=0, spd=0
/*
Creates a given projectile with the given motion applied
Automatically sets 'team', 'creator', and 'hitid' based on the calling instance
Automatically applies Euphoria to the projectile if the creator is an enemy
Ex:
projectile_create(x, y, Bullet2, gunangle + orandom(30 * accuracy), 16)
projectile_create(x, y, "DiverHarpoon", gunangle, 7)
projectile_create(x, y, Explosion)
*/
var _x = argument[0],
_y = argument[1],
_obj = argument[2],
_dir = ((argument_count > 3) ? argument[3] : 0),
_spd = ((argument_count > 4) ? argument[4] : 0),
_proj = obj_create(_x, _y, _obj);
with(_proj){