-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
1030 lines (804 loc) · 29.6 KB
/
Copy pathinit.lua
File metadata and controls
1030 lines (804 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---@type mod_calllbacks
local M = { api_version = 0, version = "1.1.0" }
---@type brain_function
_G["Vibrant_Biomes.plant"] = function(body)
---@type brain
local brain = {}
brain.rotation = rand_normal() - 0.1*body.angular_velocity
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Floating_Barge_brain"] = function(body)
---@type brain
local brain = {}
brain.rotation = rand_normal() - 0.1*body.angular_velocity
local wall_avoid_range = 60
avoid_walls(body, brain, wall_avoid_range)
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Linked_Generator_brain"] = function(body)
---@type brain
local brain = {}
brain.rotation = rand_normal() - 0.1*body.angular_velocity
if body.health >= body.max_health then
brain.ability = true
end
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Dark_Bouy_brain"] = function(body)
---@type brain
local randomadjustment = body.values[1] or 0.0 -- default to 0
if randomadjustment == 0.0 then
randomadjustment = rand_normal()
end
local brain = {}
brain.rotation = rand_normal() - 0.1*body.angular_velocity
local Increment = body.age + randomadjustment*60.0
if ( (Increment) % ( 240 ) < 40 ) then
brain.ability = true
end
brain.values = {}
brain.values[1] = randomadjustment
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Molusk_brain"] = function(body)
---@type brain
local Increment = body.values[1] or 0.0 -- default to 0
if Increment == 0.0 then
Increment = rand_normal()*60
end
local brain = {}
brain.rotation = rand_normal() - 0.1*body.angular_velocity
local Increment = Increment + 1 + (rand_normal()*.5)
if ( (Increment) % ( 300 ) < 30 ) then
brain.ability = true
end
brain.values = {}
brain.values[1] = Increment
return brain
end
---@type brain_function
_G["Vibrant_Biomes.drifter_brain"] = function(body)
local brain = {}
local ally_avoid_range = 10
local wall_avoid_range = 10
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
-- movement while not aggro'd
brain.movement = 1
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
local bodies = get_visible_bodies(body.id, 100, true)
for i, b in ipairs(bodies) do
avoid_body(body, brain, b, ally_avoid_range)
end
-- update our custom values
brain.values = {}
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Squid_brain"] = function(body)
local brain = {}
local ally_avoid_range = 20
local wall_avoid_range = 20
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
if body.health < body.max_health* .9 then
brain.ability = true
end
-- movement while not aggro'd
brain.movement = 1
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
local bodies = get_visible_bodies(body.id, 100, true)
for i, b in ipairs(bodies) do
avoid_body(body, brain, b, ally_avoid_range)
end
avoid_walls(body, brain, wall_avoid_range)
-- update our custom values
brain.values = {}
return brain
end
---@type brain_function
_G["Vibrant_Biomes.squishy_seeker_brain"] = function(body)--TODO not chasing player
local state = body.values[1] or 0
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local brain = {}
local ally_avoid_range = 10
local wall_avoid_range = 10
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 200 -- aggro range set to 200
local bodies = get_visible_bodies(body.id, 200, true)
for i, b in ipairs(bodies) do
--chases enemies
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
-- avoids allys
if b.team == body.team then
avoid_body(body, brain, b, ally_avoid_range)
end
end
if state == 0 then
-- movement while not aggro'd
brain.movement = 1
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
if closest_enemy then
state = 1
end
elseif state == 1 then -- goes to last known position for the chance of finding hte player
if closest_enemy then
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
end
if closest_enemy_id == 0 then
state = 2
aggro_timer = DEAGGRO_TIME
end
elseif state == 2 then
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_x - body.cost_center_x
local dir_y = target_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 1
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Jumping_Trapweed_brain"] = function(body)--TODO not chasing player
local state = body.values[1] or 0
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local brain = {}
local ally_avoid_range = 10
local wall_avoid_range = 10
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 200 -- aggro range set to 200
local bodies = get_visible_bodies(body.id, 200, true)
for i, b in ipairs(bodies) do
--chases enemies
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
-- avoids allys
if b.team == body.team then
avoid_body(body, brain, b, ally_avoid_range)
end
end
if state == 0 then
brain.ability = true
brain.rotation = rand_normal() - 0.1*body.angular_velocity
if closest_enemy then
state = 1
end
if (body.wall_dist > 30) then
brain.movement = 1
local target_x = body.cost_center_x + (body.wall_dx * -1200)
local target_y = body.cost_center_y + (body.wall_dy * -1200)
move_towards(body, brain, target_x, target_y)
end
if (body.wall_dist > 10) then
brain.rotation = .5
end
elseif state == 1 then -- goes to last known position for the chance of finding hte player
if closest_enemy then
brain.ability = false
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
brain.movement = 1
end
if (body.wall_dist < 10) then
brain.rotation = math.sin(body.age)
end
if closest_enemy_id == 0 then
state = 2
aggro_timer = DEAGGRO_TIME
end
elseif state == 2 then
brain.ability = false
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_y - body.cost_center_x
local dir_y = target_x - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
brain.movement = 1
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 1
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
return brain
end
---@type brain_function
_G["Vibrant_Biomes.Basher_brain"] = function(body)--TODO not chasing player
local state = body.values[1] or 0
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local brain = {}
local ally_avoid_range = 10
local wall_avoid_range = 10
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 200 -- aggro range set to 200
local bodies = get_visible_bodies(body.id, 200, true)
local PunchDistance = 200
for i, b in ipairs(bodies) do
--chases enemies
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
-- avoids allys
if b.team == body.team then
avoid_body(body, brain, b, ally_avoid_range)
end
end
if state == 0 then
-- movement while not aggro'd
brain.movement = 1
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
if closest_enemy then
state = 1
end
avoid_walls(body, brain, wall_avoid_range)
-- returns ball to center to heal
brain.grab_target_x = body.cost_center_x
brain.grab_target_y = body.cost_center_y
brain.grab_weight = 1
elseif state == 1 then -- goes to last known position for the chance of finding hte player
if closest_enemy then
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
if ( body.age > 240 ) and ( body.age % ( 120 ) < 60 ) and ( body.mass > 380 ) and (closest_dist < PunchDistance) then
-- returns ball to center to heal
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
end
if ( body.age % ( 120 ) >= 60 ) or ( body.mass < 380 ) or (closest_dist > PunchDistance) then
-- returns ball to center to heal
brain.grab_target_x = body.cost_center_x
brain.grab_target_y = body.cost_center_y
brain.grab_weight = 1
end
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
end
if closest_enemy_id == 0 then
state = 2
aggro_timer = DEAGGRO_TIME
end
elseif state == 2 then
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_x - body.cost_center_x
local dir_y = target_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 1
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
return brain
end
_G["Vibrant_Biomes.Broadside_brain"] = function(body)--TODO not chasing player
local state = body.values[1] or 0
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local brain = {}
local ally_avoid_range = 50
local wall_avoid_range = 70
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 200 -- aggro range set to 200
local bodies = get_visible_bodies(body.id, 200, true)
for i, b in ipairs(bodies) do
--chases enemies
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
-- avoids allys
if b.team == body.team then
avoid_body(body, brain, b, ally_avoid_range)
end
end
if state == 0 then
-- movement while not aggro'd
brain.movement = 1
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
if closest_enemy then
state = 1
end
avoid_walls(body, brain, wall_avoid_range)
elseif state == 1 then
if closest_enemy then
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
if ( body.age > 240 ) and ( body.age % ( 240 ) < 30 ) and ( health > max_health * 0.4 ) then
brain.ability = true
end
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
end
if closest_enemy_id == 0 then
state = 2
aggro_timer = DEAGGRO_TIME
end
elseif state == 2 then-- goes to last known position for the chance of finding hte player
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_x - body.cost_center_x
local dir_y = target_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 1
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
return brain
end
_G["Vibrant_Biomes.Canivorous_Barge_brain"] = function(body)--TODO not chasing player
local state = body.values[1] or 0
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local brain = {}
local ally_avoid_range = 50
local wall_avoid_range = 100
local health = body.health
local max_health = body.max_health
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 200 -- aggro range set to 200
local bodies = get_visible_bodies(body.id, 200, true)
for i, b in ipairs(bodies) do
--chases enemies
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
-- avoids allys
if b.team == body.team then
avoid_body(body, brain, b, ally_avoid_range)
end
end
if state == 0 then
-- movement while not aggro'd
brain.rotation = 0.5*rand_normal() + math.sin(0.15*body.age) --random turning + a wiggle
if closest_enemy then
state = 1
end
avoid_walls(body, brain, wall_avoid_range)
elseif state == 1 then
if closest_enemy then
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
if ( body.age > 240 ) and ( body.age % ( 240 ) < 30 ) and ( health > max_health * 0.4 ) then
brain.ability = true
end
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
end
if closest_enemy_id == 0 then
state = 2
aggro_timer = DEAGGRO_TIME
end
elseif state == 2 then-- goes to last known position for the chance of finding hte player
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_x - body.cost_center_x
local dir_y = target_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 1
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
return brain
end
-- fancy brain for the big guy who hides in the dark
_G["Vibrant_Biomes.Seeking_Destroyer_brain"] = function(body)
-- starts by staying still or very still (stalking)
--sees a guy in range to strike in a short distance (stalking)
--when it gets too close or far away switches to hunting state (hunting)
-- runs after playerat high speed (hunting)
--looks for last player position if it loses sight (hunting2)
-- if it cant find player returns to stalking (stalking)
local state = body.values[1] or 0 -- default to state 0 (stalking)
local aggro_timer = body.values[2] or 600 -- timer for giving up on its target
local target_x = body.values[3] or body.cost_center_x
local target_y = body.values[4] or body.cost_center_y
local ClosestGottenTo = body.values[5] or 600 -- intermediary so that far away players that get spotted arnt imidiatly chased after
local brain = {}
local wall_avoid_range = 30
local health = body.health
local max_health = body.max_health
local DEAGGRO_TIME = 5*120 -- 5 seconds
brain.movement = brain.movement or 0
brain.rotation = brain.rotation or 0
local bodies = get_visible_bodies(body.id, 600, true)
local closest_enemy, closest_enemy_id, closest_dist = nil, 0, 600 -- aggro range set to 600
for _, b in ipairs(bodies) do
if b.team ~= body.team then
closest_enemy = b
closest_enemy_id = b.id
closest_dist = b.dist
end
end
-- staying still to trick the player into thinking its a dark bouy
if state == 0 then
brain.rotation = 0
brain.movement = 0
if closest_enemy then
state = 1
ClosestGottenTo = 600
end
elseif state == 1 then -- if detecting a player look at them
-- slowly looks at player
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)*.1
if closest_dist < ClosestGottenTo then
ClosestGottenTo = closest_dist
end
if (closest_dist < 100) or ((closest_dist > 200) and (ClosestGottenTo < 200)) or (closest_enemy_id == 0 ) then
state = 2
end
elseif state == 2 then -- goes after enemies that are too far away
if closest_enemy then
target_x = closest_enemy.cost_center_x
target_y = closest_enemy.cost_center_y
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = closest_enemy.cost_center_x - body.cost_center_x
local dir_y = closest_enemy.cost_center_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
end
if closest_enemy_id == 0 then
state = 3
aggro_timer = DEAGGRO_TIME
end
elseif state == 3 then
-- uses mouse thing for better aim
brain.grab_target_x = target_x
brain.grab_target_y = target_y
brain.grab_weight = 1
local dir_x = target_x - body.cost_center_x
local dir_y = target_y - body.cost_center_y
dir_x, dir_y = normalize(dir_x, dir_y)
brain.rotation = cross(body.dir_x, body.dir_y, dir_x, dir_y)
move_towards(body, brain, target_x, target_y)
avoid_walls(body, brain, wall_avoid_range)
aggro_timer = aggro_timer-1
if closest_enemy_id ~= 0 then
state = 2
end
if aggro_timer <= 0 then
state = 0
end
end
-- update our custom values
brain.values = {}
brain.values[1] = state
brain.values[2] = aggro_timer
brain.values[3] = target_x
brain.values[4] = target_y
brain.values[5] = ClosestGottenTo
return brain
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--##################(end of brains)#####################################################################################################################################################################################################################
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---@type spawn_function
_G["Vibrant_Biomes.drifting"] = function(body_id, x, y)
give_mutation(body_id, MUT_DRIFTING)
return { nil, nil, x, y } -- this determines spawn extra info
end
---@type spawn_function
_G["Vibrant_Biomes.budding"] = function(body_id, x, y)
give_mutation(body_id, MUT_BUDDING)
return { nil, nil, x, y } -- this determines spawn extra info
end
-- post hook is for defining creatures
function M.post(api, config)
local Plant_SpawnRates = config.Plant_SpawnRates or 1.0
local Animal_SpawnRates = config.Plant_SpawnRates or 1.0
local Gyre_Animals = config.Plant_SpawnRates or true
-- we shadow the creature_list function to call our additional code after it
local old_creature_list = creature_list
creature_list = function(...)
-- call the original
local r = { old_creature_list(...) }
-- register our creatures
register_creature(
api.acquire_id("Vibrant_Biomes.Brain_Coral"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Brain_Coral.bod",
"Vibrant_Biomes.plant"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Little_grass"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Little_grass.bod",
"Vibrant_Biomes.plant"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Molusk"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Molusk.bod",
"Vibrant_Biomes.Molusk_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Squid"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Squid.bod",
"Vibrant_Biomes.Squid_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.drifter"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/drifter.bod",
"Vibrant_Biomes.drifter_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.squishy_seeker"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/squishy_seeker.bod",
"Vibrant_Biomes.squishy_seeker_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Bounce_Flower"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Bounce_Flower.bod",
"Vibrant_Biomes.plant"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Seeking_Destroyer"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Seeking_Destroyer.bod",
"Vibrant_Biomes.Seeking_Destroyer_brain",
"Vibrant_Biomes.drifting"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Dark_Bouy"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Dark_Bouy.bod",
"Vibrant_Biomes.Dark_Bouy_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Dark_Bouy_Large"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Dark_Bouy_Large.bod",
"Vibrant_Biomes.Dark_Bouy_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Dark_Bouy_Floating"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Dark_Bouy_Floating.bod",
"Vibrant_Biomes.Dark_Bouy_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Blood_Coral"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Blood_Coral.bod",
"Vibrant_Biomes.plant"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Linked_Generator"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Linked_Generator.bod",
"Vibrant_Biomes.Linked_Generator_brain",
"Vibrant_Biomes.budding"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Broadside"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Broadside.bod",
"Vibrant_Biomes.Broadside_brain",
"Vibrant_Biomes.budding"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Floating_Barge"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Floating_Barge.bod",
"Vibrant_Biomes.Floating_Barge_brain",
"Vibrant_Biomes.budding"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Canivorous_Barge"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Canivorous_Barge.bod",
"Vibrant_Biomes.Canivorous_Barge_brain",
"Vibrant_Biomes.budding"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Basher"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Basher.bod",
"Vibrant_Biomes.Basher_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Acid_Molusk"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Acid_Molusk.bod",
"Vibrant_Biomes.Molusk_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Angler_Weed"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Angler_Weed.bod",
"Vibrant_Biomes.plant"
)
register_creature(
api.acquire_id("Vibrant_Biomes.Jumping_Trapweed"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/Jumping_Trapweed.bod",
"Vibrant_Biomes.Jumping_Trapweed_brain"
)
register_creature(
api.acquire_id("Vibrant_Biomes.gyre_drifter"),
"data/scripts/lua_mods/mods/Vibrant_Biomes/bodies/gyre_drifter.bod",
"Vibrant_Biomes.drifter_brain"
)
-- return the result of the original, not strictly neccesary here but useful in some situations
return unpack(r)
end
-- shadow init_biomes function to call our stuff afterwards
local old_init_biomes = init_biomes
init_biomes = function(...)
local r = { old_init_biomes(...) }
-- add our creatures to the starting biome, if spawn_rates are too high you will start to see issues where only some creatures can spawn
-- to fix this make sure the sum isn't too high, i will perhaps add a prehook for compat with this in future
add_plant_spawn_chance("STRT", api.acquire_id("Vibrant_Biomes.Brain_Coral"), .02*Plant_SpawnRates, 2)
add_plant_spawn_chance("STRT", api.acquire_id("Vibrant_Biomes.Little_grass"), .02*Plant_SpawnRates, 2)
add_plant_spawn_chance("STRT", api.acquire_id("Vibrant_Biomes.Molusk"), .01*Plant_SpawnRates, 3)
add_creature_spawn_chance("STRT", api.acquire_id("Vibrant_Biomes.Squid"), .01*Animal_SpawnRates, 3)
add_plant_spawn_chance("TOXC", api.acquire_id("Vibrant_Biomes.Acid_Molusk"), .02*Plant_SpawnRates, 5)
add_plant_spawn_chance("TOXC", api.acquire_id("Vibrant_Biomes.Angler_Weed"), .08*Plant_SpawnRates, 5)
add_plant_spawn_chance("TOXC", api.acquire_id("Vibrant_Biomes.Jumping_Trapweed"), .08*Plant_SpawnRates, 5)