-
Notifications
You must be signed in to change notification settings - Fork 40
/
utility.lua
1737 lines (1498 loc) · 53.4 KB
/
utility.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
-------------------------------------------------------------------------------
--- AUTHOR: Nostrademous
--- CONTRIBUTOR: Many functions copied from work by Platinum_dota2
--- GITHUB REPO: https://github.com/Nostrademous/Dota2-FullOverwrite
-------------------------------------------------------------------------------
require( GetScriptDirectory().."/constants" )
local gHeroVar = require( GetScriptDirectory().."/global_hero_data" )
-------------------------------------------------------------------------------
-- Inits
-------------------------------------------------------------------------------
U = {}
-------------------------------------------------------------------------------
-- Declarations
-------------------------------------------------------------------------------
U.creeps = nil
U.Lanes={[1]=LANE_BOT,[2]=LANE_MID,[3]=LANE_TOP};
U.Locations = {
["RadiantShop"]= Vector(-4739,1263),
["DireShop"]= Vector(4559,-1554),
["BotShop"]= Vector(7253,-4128),
["TopShop"]= Vector(-7236,4444),
["RadiantBase"]= Vector(-7200,-6666),
["RBT1"]= Vector(4896,-6140),
["RBT2"]= Vector(-128,-6244),
["RBT3"]= Vector(-3966,-6110),
["RMT1"]= Vector(-1663,-1510),
["RMT2"]= Vector(-3559,-2783),
["RMT3"]= Vector(-4647,-4135),
["RTT1"]= Vector(-6202,1831),
["RTT2"]= Vector(-6157,-860),
["RTT3"]= Vector(-6591,-3397),
["RadiantTopShrine"]= Vector(-4229,1299),
["RadiantBotShrine"]= Vector(622,-2555),
["DireBase"]= Vector(7137,6548),
["DBT1"]= Vector(6215,-1639),
["DBT2"]= Vector(6242,400),
["DBT3"]= Vector(-6307,3043),
["DMT1"]= Vector(1002,330),
["DMT2"]= Vector(2477,2114),
["DMT3"]= Vector(4197,3756),
["DTT1"]= Vector(-4714,6016),
["DTT2"]= Vector(0,6020),
["DTT3"]= Vector(3512,5778),
["DireTopShrine"]= Vector(-139,2533),
["DireBotShrine"]= Vector(4173,-1613),
};
U["tableNeutralCamps"] = {
[constants.TEAM_RADIANT] = {
[1] = {
[constants.DIFFICULTY] = constants.CAMP_EASY,
[constants.VECTOR] = constants.RAD_SAFE_EASY,
[constants.STACK_TIME] = constants.RAD_SAFE_EASY_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_SAFE_EASY_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_SAFE_EASY_STACK
},
[2] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.RAD_SAFE_MEDIUM,
[constants.STACK_TIME] = constants.RAD_SAFE_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_SAFE_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_SAFE_MEDIUM_STACK
},
[3] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.RAD_MID_MEDIUM,
[constants.STACK_TIME] = constants.RAD_MID_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_MID_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_MID_MEDIUM_STACK
},
[4] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.RAD_OFF_MEDIUM,
[constants.STACK_TIME] = constants.RAD_OFF_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_OFF_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_OFF_MEDIUM_STACK
},
[5] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.RAD_OFF_HARD,
[constants.STACK_TIME] = constants.RAD_OFF_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_OFF_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_OFF_HARD_STACK
},
[6] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.RAD_MID_HARD,
[constants.STACK_TIME] = constants.RAD_MID_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_MID_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_MID_HARD_STACK
},
[7] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.RAD_SAFE_HARD,
[constants.STACK_TIME] = constants.RAD_SAFE_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_SAFE_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_SAFE_HARD_STACK
},
[8] = {
[constants.DIFFICULTY] = constants.CAMP_ANCIENT,
[constants.VECTOR] = constants.RAD_MID_ANCIENT,
[constants.STACK_TIME] = constants.RAD_MID_ANCIENT_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_MID_ANCIENT_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_MID_ANCIENT_STACK
},
[9] = {
[constants.DIFFICULTY] = constants.CAMP_ANCIENT,
[constants.VECTOR] = constants.RAD_OFF_ANCIENT,
[constants.STACK_TIME] = constants.RAD_OFF_ANCIENT_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.RAD_OFF_ANCIENT_PRESTACK,
[constants.STACK_VECTOR] = constants.RAD_OFF_ANCIENT_STACK
}
},
[constants.TEAM_DIRE] = {
[1] = {
[constants.DIFFICULTY] = constants.CAMP_EASY,
[constants.VECTOR] = constants.DIRE_SAFE_EASY,
[constants.STACK_TIME] = constants.DIRE_SAFE_EASY_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_SAFE_EASY_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_SAFE_EASY_STACK
},
[2] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.DIRE_SAFE_MEDIUM,
[constants.STACK_TIME] = constants.DIRE_SAFE_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_SAFE_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_SAFE_MEDIUM_STACK
},
[3] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.DIRE_MID_MEDIUM,
[constants.STACK_TIME] = constants.DIRE_MID_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_MID_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_MID_MEDIUM_STACK
},
[4] = {
[constants.DIFFICULTY] = constants.CAMP_MEDIUM,
[constants.VECTOR] = constants.DIRE_OFF_MEDIUM,
[constants.STACK_TIME] = constants.DIRE_OFF_MEDIUM_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_OFF_MEDIUM_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_OFF_MEDIUM_STACK
},
[5] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.DIRE_OFF_HARD,
[constants.STACK_TIME] = constants.DIRE_OFF_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_OFF_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_OFF_HARD_STACK
},
[6] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.DIRE_MID_HARD,
[constants.STACK_TIME] = constants.DIRE_MID_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_MID_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_MID_HARD_STACK
},
[7] = {
[constants.DIFFICULTY] = constants.CAMP_HARD,
[constants.VECTOR] = constants.DIRE_SAFE_HARD,
[constants.STACK_TIME] = constants.DIRE_SAFE_HARD_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_SAFE_HARD_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_SAFE_HARD_STACK
},
[8] = {
[constants.DIFFICULTY] = constants.CAMP_ANCIENT,
[constants.VECTOR] = constants.DIRE_MID_ANCIENT,
[constants.STACK_TIME] = constants.DIRE_MID_ANCIENT_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_MID_ANCIENT_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_MID_ANCIENT_STACK
},
[9] = {
[constants.DIFFICULTY] = constants.CAMP_ANCIENT,
[constants.VECTOR] = constants.DIRE_OFF_ANCIENT,
[constants.STACK_TIME] = constants.DIRE_OFF_ANCIENT_STACKTIME,
[constants.PRE_STACK_VECTOR] = constants.DIRE_OFF_ANCIENT_PRESTACK,
[constants.STACK_VECTOR] = constants.DIRE_OFF_ANCIENT_STACK
}
}
}
U.SIDE_SHOP_TOP = Vector(-7220,4430)
U.SIDE_SHOP_BOT = Vector(7249,-4113)
U.SECRET_SHOP_RADIANT = Vector(-4472,1328)
U.SECRET_SHOP_DIRE = Vector(4586,-1588)
U.ROSHAN = Vector(-2405, 1905)
U.MapSafeSpots = {
Vector(-7180, 4811),
Vector(-6237, 4985),
Vector(-6998, 3659),
Vector(-5255, 4484),
Vector(-6159, 3385),
Vector(-4433, 4719),
Vector(-3377, 5090),
Vector(-2825, 4122),
Vector(-3255, 5888),
Vector(-2217, 6228),
Vector(-1943, 4920),
Vector(-795, 4994),
Vector(-22, 4096),
Vector(-1547, 3720),
Vector(-934, 3393),
Vector(-1973, 2805),
Vector(-3560, 2460),
Vector(1521, 4209),
Vector(2843, 3738),
Vector(2104, 3646),
Vector(1817, 2787),
Vector(1039, 2342),
Vector(3990, 2831),
Vector(-196, 2329),
Vector(4173, 1950),
Vector(3599, 1042),
Vector(3160, -148),
Vector(5146, 1849),
Vector(1965, 571),
Vector(1982, -113),
Vector(2399, -1029),
Vector(1669, -816),
Vector(-335, 1282),
Vector(-300, 209),
Vector(-1743, 1195),
Vector(-2012, 462),
Vector(-2504, 9),
Vector(-3338, -1213),
Vector(-1221, -471),
Vector(-517, -1230),
Vector(-535, -2006),
Vector(-1274, -2486),
Vector(700, -2608),
Vector(2021, -2425),
Vector(2838, -2085),
Vector(4386, -1535),
Vector(4803, -131),
Vector(-4525, 1317),
Vector(-5003, 314),
Vector(-5994, 628),
Vector(-3447, -1117),
Vector(-4872, -1056),
Vector(-4412, -1884),
Vector(-2873, -2041),
Vector(-2417, -2465),
Vector(-2404, -2791),
Vector(-1908, -3027),
Vector(-1704, -3795),
Vector(-400, -4353),
Vector(1095, -4327),
Vector(-2817, -3969),
Vector(1469, -4745),
Vector(3269, -5295),
Vector(3156, -6132),
Vector(2025, -6211),
Vector(3703, -3768),
Vector(4486, -5033),
Vector(5972, -4964),
Vector(7354, -4144),
Vector(7467, -3149),
Vector(-3992, 3886),
Vector(-5444, 3999)
}
U.RadiantSafeSpots = {unpack(U.MapSafeSpots)}
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RadiantBase
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RBT1
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RBT2
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RBT3
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RMT1
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RMT2
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RMT3
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RTT1
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RTT2
U.RadiantSafeSpots[#U.RadiantSafeSpots+1] = U.Locations.RTT3
U.DireSafeSpots = {unpack(U.MapSafeSpots)}
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DireBase
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DBT1
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DBT2
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DBT3
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DMT1
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DMT2
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DMT3
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DTT1
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DTT2
U.DireSafeSpots[#U.DireSafeSpots+1] = U.Locations.DTT3
-------------------------------------------------------------------------------
-- Properties
-------------------------------------------------------------------------------
function setHeroVar(var, value)
local bot = GetBot()
gHeroVar.SetVar(bot:GetPlayerID(), var, value)
end
function getHeroVar(var)
local bot = GetBot()
return gHeroVar.GetVar(bot:GetPlayerID(), var)
end
-------------------------------------------------------------------------------
-- Functions
-------------------------------------------------------------------------------
function U.GetOppositeTeamTo(team)
if team == constants.TEAM_RADIANT then
return constants.TEAM_DIRE
else
return constants.TEAM_RADIANT
end
end
-------------------------------------------------------------------------------
-- Table Functions
-------------------------------------------------------------------------------
function U.InTable (tab, val)
if not tab then return false end
for index, value in ipairs (tab) do
if value == val then
return true
end
end
return false
end
function U.PosInTable(tab, val)
for index,value in ipairs(tab) do
if value == val then
return index
end
end
return -1
end
function U.Spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
function U.PairsByKeys(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function U.SortFunc(a , b)
if a < b then
return true
end
return false
end
function U.deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[U.deepcopy(orig_key)] = U.deepcopy(orig_value)
end
setmetatable(copy, U.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function U.clone(org)
return {unpack(org)}
end
-------------------------------------------------------------------------------
-- Math Functions
-------------------------------------------------------------------------------
function U.CheckFlag(bitfield, flag)
return ((bitfield/flag) % 2) >= 1
end
function U.GetDistance(s, t)
--print("S1: "..s[1]..", S2: "..s[2].." :: T1: "..t[1]..", T2: "..t[2]);
return math.sqrt((s[1]-t[1])*(s[1]-t[1]) + (s[2]-t[2])*(s[2]-t[2]));
end
function U.VectorTowards(start, towards, distance)
local facing = towards - start
local direction = facing / U.GetDistance(facing, Vector(0,0)) --normalized
return start + (direction * distance)
end
function U.VectorAway(start, towards, distance)
local facing = start - towards
local direction = facing / U.GetDistance(facing, Vector(0,0)) --normalized
return start + (direction * distance)
end
function U.Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function U.GetHeightDiff(hUnit1, hUnit2)
if not U.ValidTarget(hUnit1) then return 0 end
if type(hUnit2) == "number" then -- case for trees
return (hUnit1:GetLocation().z - hUnit2)
end
if not U.ValidTarget(hUnit2) then return 0 end
return (hUnit1:GetLocation().z - hUnit2:GetLocation().z)
end
function U.EnemyDistanceFromTheirAncient( hEnemy )
local locAncient = GetAncient(U.GetOtherTeam()):GetLocation()
if U.ValidTarget(hEnemy) then
return U.GetDistance( locAncient, hEnemy:GetLocation() )
end
return 0
end
function U.TimeForEnemyToGetIntoTheirBase( hEnemy )
local distFromBase = U.EnemyDistanceFromTheirAncient( hEnemy )
return distFromBase/hEnemy:GetCurrentMovementSpeed()
end
-- CONTRIBUTOR: Function below was coded by Platinum_dota2
function U.IsFacingLocation(hero, loc, delta)
if not U.ValidTarget(hero) then return false end
local facing = hero:GetFacing()
local moveVect = loc - hero:GetLocation()
moveVect = moveVect / (U.GetDistance(Vector(0,0), moveVect))
local moveAngle = math.atan2(moveVect.y, moveVect.x)/math.pi * 180
if moveAngle < 0 then
moveAngle = 360 + moveAngle
end
facing = (facing + 360) % 360
if (math.abs(moveAngle - facing) < delta or
math.abs(moveAngle + 360 - facing) < delta or
math.abs(moveAngle - 360 - facing) < delta) then
return true
end
return false
end
-- CONTRIBUTOR: Function below was coded by Platinum_dota2
function U.AreTreesBetweenMeAndLoc(loc, lineOfSightThickness)
local bot = GetBot()
local trees = bot:GetNearbyTrees(Min(1600, GetUnitToLocationDistance(bot, loc)))
--check if there are trees between us and location with line-of-sight thickness
for _, tree in pairs(trees) do
local x = GetTreeLocation(tree)
local y = bot:GetLocation()
local z = loc
if x ~= y then
local a = 1
local b = 1
local c = 0
if x.x - y.x == 0 then
b = 0
c = -x.x
else
a =- (x.y - y.y)/(x.x - y.x)
c =- (x.y + x.x*a)
end
local d = math.abs((a*z.x + b*z.y + c)/math.sqrt(a*a + b*b))
if d <= lineOfSightThickness and
GetUnitToLocationDistance(bot, loc) > (U.GetDistance(x,loc) + 50) then
return true
end
end
end
return false
end
-- CONTRIBUTOR: Function below was based off above function by Platinum_dota2
function U.GetEnemyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
local bot = GetBot()
local fCreepList = {}
local eCreeps = gHeroVar.GetNearbyEnemyCreep(bot, Min(1600, GetUnitToLocationDistance(bot, loc)))
--check if there are enemy creeps between us and location with line-of-sight thickness
for _, eCreep in pairs(eCreeps) do
if U.ValidTarget(eCreep) then
local x = eCreep:GetLocation()
local y = bot:GetLocation()
local z = loc
if x ~= y then
local a = 1
local b = 1
local c = 0
if x.x - y.x == 0 then
b = 0
c = -x.x
else
a =- (x.y - y.y)/(x.x - y.x)
c =- (x.y + x.x*a)
end
local d = math.abs((a*z.x + b*z.y + c)/math.sqrt(a*a + b*b))
if d <= lineOfSightThickness and
GetUnitToLocationDistance(bot, loc) > (U.GetDistance(x,loc) + 50) then
table.insert(fCreepList, eCreep)
end
end
end
end
return fCreepList
end
function U.AreEnemyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
return #U.GetEnemyCreepsBetweenMeAndLoc(loc, lineOfSightThickness) > 0
end
-- CONTRIBUTOR: Function below was based off above function by Platinum_dota2
function U.GetFriendlyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
local bot = GetBot()
local fCreepList = {}
local fCreeps = gHeroVar.GetNearbyAlliedCreep(bot, Min(1600, GetUnitToLocationDistance(bot, loc)))
--check if there are enemy creeps between us and location with line-of-sight thickness
for _, fCreep in pairs(fCreeps) do
if U.ValidTarget(fCreep) then
local x = fCreep:GetLocation()
local y = bot:GetLocation()
local z = loc
if x ~= y then
local a = 1
local b = 1
local c = 0
if x.x - y.x == 0 then
b = 0
c = -x.x
else
a =- (x.y - y.y)/(x.x - y.x)
c =- (x.y + x.x*a)
end
local d = math.abs((a*z.x + b*z.y + c)/math.sqrt(a*a + b*b))
if d <= lineOfSightThickness and
GetUnitToLocationDistance(bot, loc) > (U.GetDistance(x,loc) + 50) then
table.insert(fCreepList, fCreep)
end
end
end
end
return fCreepList
end
function U.AreFriendlyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
return #U.GetFriendlyCreepsBetweenMeAndLoc(loc, lineOfSightThickness) > 0
end
-- CONTRIBUTOR: Function below was based off above function by Platinum_dota2
function U.AreCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
if not U.AreEnemyCreepsBetweenMeAndLoc(loc, lineOfSightThickness) then
return U.AreFriendlyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
end
return true
end
function U.GetCreepsBetweenMeAndLoc(loc, lineOfSightThickness)
return { unpack(U.GetEnemyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)), unpack(U.GetFriendlyCreepsBetweenMeAndLoc(loc, lineOfSightThickness)) }
end
-- CONTRIBUTOR: Function below was based off above function by Platinum_dota2
function U.GetFriendlyHeroesBetweenMeAndLoc(loc, lineOfSightThickness)
local bot = GetBot()
local fHeroList = {}
local fHeroes = gHeroVar.GetNearbyAllies(bot, Min(1600, GetUnitToLocationDistance(bot, loc)))
--check if there are enemy creeps between us and location with line-of-sight thickness
for _, fHero in pairs(fHeroes) do
if U.ValidTarget(fHero) then
local x = fHero:GetLocation()
local y = bot:GetLocation()
local z = loc
if x ~= y then
local a = 1
local b = 1
local c = 0
if x.x - y.x == 0 then
b = 0
c = -x.x
else
a =- (x.y - y.y)/(x.x - y.x)
c =- (x.y + x.x*a)
end
local d = math.abs((a*z.x + b*z.y + c)/math.sqrt(a*a + b*b))
if d <= lineOfSightThickness and
GetUnitToLocationDistance(bot, loc) > (U.GetDistance(x,loc) + 50) then
table.insert(fHeroList, fHero)
end
end
end
end
return fHeroList
end
function U.GetEnemyHeroesBetweenMeAndLoc(loc, lineOfSightThickness)
local bot = GetBot()
local fHeroList = {}
local fHeroes = gHeroVar.GetNearbyEnemies(bot, Min(1600, GetUnitToLocationDistance(bot, loc)))
--check if there are enemy creeps between us and location with line-of-sight thickness
for _, fHero in pairs(fHeroes) do
if U.ValidTarget(fHero) then
local x = fHero:GetLocation()
local y = bot:GetLocation()
local z = loc
if x ~= y then
local a = 1
local b = 1
local c = 0
if x.x - y.x == 0 then
b = 0
c = -x.x
else
a =- (x.y - y.y)/(x.x - y.x)
c =- (x.y + x.x*a)
end
local d = math.abs((a*z.x + b*z.y + c)/math.sqrt(a*a + b*b))
if d <= lineOfSightThickness and
GetUnitToLocationDistance(bot, loc) > (U.GetDistance(x,loc) + 50) then
table.insert(fHeroList, fHero)
end
end
end
end
return fHeroList
end
-- use this only when movement stability is fairly high
function U.PredictPosition(hHero, fTime)
local loc = hHero:GetLocation()
local v = hHero:GetVelocity()
return Vector( loc.x + fTime * v.x, loc.y + fTime * v.y, loc.z )
end
-------------------------------------------------------------------------------
-- General Hero Functions
-------------------------------------------------------------------------------
function U.GetHeroName(bot)
local sName = bot:GetUnitName()
return string.sub(sName, 15, string.len(sName));
end
function U.IsBusy(bot)
if bot:IsChanneling() then return true end
if bot:NumQueuedActions() > 0 then return true end
if bot:IsCastingAbility() then
if bot.AbilityOnEntityUseTime and (GameTime() - bot.AbilityOnEntityUseTime) > 3.0 then return false end
return true
end
return false
end
function U.IsCore( hHero )
if not hHero:IsBot() then return true end
if gHeroVar.GetVar(hHero:GetPlayerID(), "Role") == constants.ROLE_HARDCARRY
or gHeroVar.GetVar(hHero:GetPlayerID(), "Role") == constants.ROLE_MID
or gHeroVar.GetVar(hHero:GetPlayerID(), "Role") == constants.ROLE_OFFLANE
or gHeroVar.GetVar(hHero:GetPlayerID(), "Role") == constants.ROLE_JUNGLER then
return true
end
return false
end
function U.IsMelee(hero)
--NOTE: Monkey King is considered Melee with a range of 300, typical melee heroes are range 150
return hero:GetAttackRange() < 320.0
end
function U.PartyChat(msg)
local bot = GetBot()
bot:ActionImmediate_Chat(msg, false)
end
function U.AllChat(msg)
local bot = GetBot()
bot:ActionImmediate_Chat(msg, true)
end
function U.ValidTarget(target)
if target and not target:IsNull() and target:IsAlive() then
return true
end
return false
end
function U.NotNilOrDead(unit)
if unit == nil or unit:IsNull() then
return false
end
if unit:IsAlive() then
return true
end
return false
end
function U.TimePassed(prevTime, amount)
if ( (GameTime() - prevTime) > amount ) then
return true, GameTime()
else
return false, GameTime()
end
end
function U.LevelUp(bot, AbilityPriority)
if ( GetGameState() ~= GAME_STATE_GAME_IN_PROGRESS and GetGameState() ~= GAME_STATE_PRE_GAME ) then return end
local ability = bot:GetAbilityByName(AbilityPriority[1])
if ( ability == nil ) then
U.myPrint(" FAILED AT Leveling " .. AbilityPriority[1] )
table.remove( AbilityPriority, 1 )
return
end
if ( ability:CanAbilityBeUpgraded() and ability:GetLevel() < ability:GetMaxLevel() ) then
bot:ActionImmediate_LevelAbility(AbilityPriority[1])
U.myPrint( " Leveling " .. ability:GetName() )
table.remove( AbilityPriority, 1 )
end
end
function U.GetOtherTeam()
if GetTeam() == TEAM_RADIANT then
return TEAM_DIRE
else
return TEAM_RADIANT
end
end
function U.TreadCycle(bot, stat)
--[[
local powerTreads = U.IsItemAvailable("item_power_treads")
if powerTreads then
local activeStat = powerTreads:GetPowerTreadsStat()
if activeState == stat then return end
for i = 0, 2, 1 do
activeStat = powerTreads:GetPowerTreadsStat()
gHeroVar.HeroUseAbility(bot, powerTreads)
if activeStat == stat then return end
end
end
--]]
return false
end
-------------------------------------------------------------------------------
-- Hero Movement Functions
-------------------------------------------------------------------------------
function U.PositionAlongLane(hUnit, lane)
local unitPos = hUnit:GetLocation()
local fAmount = GetAmountAlongLane(lane, unitPos)
local bInLane = false
if fAmount.distance <= 1600 then
bInLane = true
end
setHeroVar("IsInLane", bInLane)
return fAmount.amount
end
function U.NearestLane(hUnit)
local unitPos = hUnit:GetLocation()
for i = 1, 3, 1 do
local fAmount = GetAmountAlongLane(i, unitPos)
if fAmount.distance <= 1600 then return i end
end
return 0
end
function U.MoveSafelyToLocation(bot, dest)
gHeroVar.HeroMoveToLocation(bot, dest)
end
function U.IsInLane()
local bot = GetBot()
setHeroVar("RetreatLane", getHeroVar("CurLane"))
setHeroVar("RetreatPos", getHeroVar("LanePos"))
local minDis = 10000
for i = 1, #U.Lanes, 1 do
local lAmnt = U.PositionAlongLane(bot, U.Lanes[i])
local thisDis = U.GetDistance(GetLocationAlongLane(U.Lanes[i], lAmnt), bot:GetLocation())
if thisDis < minDis then
setHeroVar("RetreatLane", U.Lanes[i])
setHeroVar("RetreatPos", lAmnt)
end
end
return getHeroVar("IsInLane"), getHeroVar("RetreatLane")
end
function U.EnemiesNearLocation(bot, loc, dist)
if loc == nil then
return 0
end
local num = 0
local listEnemies = GetUnitList(UNIT_LIST_ENEMY_HEROES)
for _, enemy in pairs(listEnemies) do
if U.ValidTarget(enemy) and U.GetDistance(enemy:GetLocation(), loc) <= dist then
num = num + 1
end
end
return num
end
function U.GetWardingSpot(lane)
-- GOOD RESOURCE: http://devilesk.com/dota2/apps/interactivemap3/?x=426&y=96&zoom=0
local laneTower1 = U.GetLaneTower(U.GetOtherTeam(), lane, 1)
local laneTower2 = U.GetLaneTower(U.GetOtherTeam(), lane, 2)
if U.ValidTarget(laneTower1) then
--U.myPrint(" - WARDING - lane tower 1 still up, placing wards accordingly")
if GetTeam() == TEAM_RADIANT then
if lane == LANE_BOT then
return {Vector(3552, -1522), Vector(5684, -3228)}
elseif lane == LANE_MID then
return {Vector(-874, 1191)}
elseif lane == LANE_TOP then
return {Vector(-3069, 3873)}
end
else
if lane == LANE_TOP then
return {Vector(-5105, 2083)}
elseif lane == LANE_MID then
return {Vector(-130, -1047)}
elseif lane == LANE_BOT then
return {Vector(4199, -4763)}
end
end
elseif U.ValidTarget(laneTower2) then
if GetTeam() == TEAM_RADIANT then
if lane == LANE_BOT then
return {Vector(5072, 761), Vector(3096, -211)}
elseif lane == LANE_MID then
return {Vector(218, 2393)}
elseif lane == LANE_TOP then
return {Vector(1021, 4641)}
end
else
if lane == LANE_TOP then
return {Vector(-4380, -1283)}
elseif lane == LANE_MID then
return {Vector(-4380, -1283)}
elseif lane == LANE_BOT then
return {Vector(-1035, -4588)}
end
end
else
U.myPrint("WARDING: Not implemented past a tower dropping...")
return nil
end
return nil
end
-------------------------------------------------------------------------------
-- Neutral Functions
-------------------------------------------------------------------------------
function U.NextNeutralSpawn()
if DotaTime() < 30 then
return 30
else
local respawnFreq = 60
t = math.ceil((DotaTime() - 60) / respawnFreq) * respawnFreq + 60
--U.myPrint("Next spawn time is ", t)
return t
end
end
function U.NearestNeutralCamp( hUnit, tCamps )
local closestDistance = 1000000
local closestCamp = nil
local secondClosestCamp = nil
for k,v in ipairs(tCamps) do
if v ~= nil and GetUnitToLocationDistance( hUnit, v[constants.VECTOR] ) < closestDistance then
closestDistance = GetUnitToLocationDistance( hUnit, v[constants.VECTOR] )
if closestCamp ~= nil then secondClosestCamp = closestCamp end
closestCamp = v
--print(closestCamp..":"..closestDistance)
end
end
return closestCamp, secondClosestCamp
end
-------------------------------------------------------------------------------
-- Towers & Buildings Functions
-------------------------------------------------------------------------------
function U.GetTowerLocation(side, lane, n) --0 radiant 1 dire
if (side==0) then
if (lane==LANE_TOP) then
if (n==1) then
return U.Locations["RTT1"];
elseif (n==2) then
return U.Locations["RTT2"];
elseif (n==3) then
return U.Locations["RTT3"];
end
elseif (lane==LANE_MID) then
if (n==1) then
return U.Locations["RMT1"];
elseif (n==2) then
return U.Locations["RMT2"];
elseif (n==3) then
return U.Locations["RMT3"];
end
elseif (lane==LANE_BOT) then
if (n==1) then
return U.Locations["RBT1"];
elseif (n==2) then
return U.Locations["RBT2"];
elseif (n==3) then
return U.Locations["RBT3"];
end
end
elseif(side==1) then
if (lane==LANE_TOP) then
if (n==1) then
return U.Locations["DTT1"];
elseif (n==2) then
return U.Locations["DTT2"];
elseif (n==3) then
return U.Locations["DTT3"];
end
elseif (lane==LANE_MID) then
if (n==1) then