1
1
local enabled = false
2
- local teams = Spring .GetTeamList ()
3
2
local SimpleAITeamIDs = {}
4
3
local SimpleAITeamIDsCount = 0
5
- -- local UDN = UnitDefNames
6
- local wind = Game .windMax
7
- local mapsizeX = Game .mapSizeX
8
- local mapsizeZ = Game .mapSizeZ
9
- local random = math.random
10
-
11
- -- Spring.Echo("tracy", tracy)
12
-
13
- local MakeHashedPosTable = VFS .Include (" luarules/utilities/damgam_lib/hashpostable.lua" )
14
- local HashPosTable = MakeHashedPosTable ()
15
-
16
- local positionCheckLibrary = VFS .Include (" luarules/utilities/damgam_lib/position_checks.lua" )
17
-
18
- -- team locals
19
4
local SimpleFactoriesCount = {}
20
5
local SimpleFactories = {}
21
6
local SimpleT1Mexes = {}
22
7
local SimpleFactoryDelay = {}
23
-
8
+ local teams = Spring . GetTeamList ()
24
9
for i = 1 , # teams do
25
10
local teamID = teams [i ]
26
11
local luaAI = Spring .GetTeamLuaAI (teamID )
27
12
if luaAI and luaAI ~= " " and (string.sub (luaAI , 1 , 8 ) == ' SimpleAI' or string.sub (luaAI , 1 , 15 ) == ' SimpleCheaterAI' or string.sub (luaAI , 1 , 16 ) == ' SimpleDefenderAI' or string.sub (luaAI , 1 , 19 ) == ' SimpleConstructorAI' ) then
28
13
enabled = true
29
14
SimpleAITeamIDsCount = SimpleAITeamIDsCount + 1
30
15
SimpleAITeamIDs [SimpleAITeamIDsCount ] = teamID
31
-
32
16
SimpleFactoriesCount [teamID ] = 0
33
17
SimpleFactories [teamID ] = {}
34
18
SimpleT1Mexes [teamID ] = 0
35
19
SimpleFactoryDelay [teamID ] = 0
36
20
end
37
21
end
22
+ teams = nil
38
23
39
24
function gadget :GetInfo ()
40
25
return {
@@ -48,6 +33,23 @@ function gadget:GetInfo()
48
33
}
49
34
end
50
35
36
+ -- Spring.Echo("tracy", tracy)
37
+
38
+ local wind = Game .windMax
39
+ local mapsizeX = Game .mapSizeX
40
+ local mapsizeZ = Game .mapSizeZ
41
+ local random = math.random
42
+ local min = math.min
43
+ local CMD_MOVE = CMD .MOVE
44
+ local CMD_RECLAIM = CMD .RECLAIM
45
+ local CMD_REPAIR = CMD .REPAIR
46
+ local CMD_FIGHT = CMD .FIGHT
47
+
48
+ local MakeHashedPosTable = VFS .Include (" luarules/utilities/damgam_lib/hashpostable.lua" )
49
+ local HashPosTable = MakeHashedPosTable ()
50
+
51
+ local positionCheckLibrary = VFS .Include (" luarules/utilities/damgam_lib/position_checks.lua" )
52
+
51
53
-- manually appoint units to avoid making
52
54
-- (note that transports, stockpilers and objects/walls are auto skipped)
53
55
local BadUnitsList = {}
@@ -100,6 +102,9 @@ for unitDefID, unitDef in pairs(UnitDefs) do
100
102
if unitDef .isBuilding then
101
103
isBuilding [unitDefID ] = {unitDef .xsize , unitDef .zsize }
102
104
end
105
+ if unitDef .customParams .iscommander then
106
+ isCommander [unitDefID ] = {unitDef .xsize , unitDef .zsize }
107
+ end
103
108
104
109
local skip = false
105
110
for a = 1 , # BadUnitsList do
@@ -137,7 +142,6 @@ for unitDefID, unitDef in pairs(UnitDefs) do
137
142
138
143
if not skip then
139
144
if unitDef .customParams .iscommander then
140
- isCommander [unitDefID ] = true
141
145
SimpleCommanderDefs [unitDefID ] = 1
142
146
elseif unitDef .isFactory and # unitDef .buildOptions > 0 then
143
147
SimpleFactoriesDefs [unitDefID ] = 1
@@ -240,14 +244,14 @@ local function SimpleBuildOrder(cUnitID, building)
240
244
local units = spGetUnitsInCylinder (cunitposx , cunitposz , searchRange , team )
241
245
if # units > 1 then
242
246
local gaveOrder = false
243
- for k = 1 ,math. min (# units , 5 + b2 * 2 ) do
247
+ for k = 1 ,min (# units , 5 + b2 * 2 ) do
244
248
numtests = numtests + 1
245
249
local buildnear = units [random (1 , # units )]
246
250
local refDefID = spGetUnitDefID (buildnear )
247
251
if isBuilding [unitDefID ] or isCommander [refDefID ] then
248
252
local refx , _ , refz = spGetUnitPosition (buildnear )
249
- local reffootx = isBuilding [refDefID ] and isBuilding [refDefID ][1 ] * 8 or 16
250
- local reffootz = isBuilding [refDefID ] and isBuilding [refDefID ][2 ] * 8 or 16
253
+ local reffootx = ( isBuilding [refDefID ] and isBuilding [refDefID ][1 ] or isCommander [ refDefID ][ 1 ]) * 8
254
+ local reffootz = ( isBuilding [refDefID ] and isBuilding [refDefID ][2 ] or isCommander [ refDefID ][ 2 ]) * 8
251
255
local spacing = random (64 , 128 )
252
256
local testspacing = spacing * 0.75
253
257
local buildingDefID = building
@@ -322,7 +326,7 @@ local function SimpleConstructionProjectSelection(unitID, unitDefID, unitTeam, u
322
326
-- local targetUnit = units[math.random(1,#units)]
323
327
-- if isBuilding[spGetUnitDefID(targetUnit)] then
324
328
-- local tUnitX, tUnitY, tUnitZ = spGetUnitPosition(targetUnit)
325
- -- spGiveOrderToUnit(unitID, CMD.MOVE , { tUnitX + math.random(-100, 100), tUnitY, tUnitZ + math.random(-100, 100) }, { "shift", "alt", "ctrl" })
329
+ -- spGiveOrderToUnit(unitID, CMD_MOVE , { tUnitX + math.random(-100, 100), tUnitY, tUnitZ + math.random(-100, 100) }, { "shift", "alt", "ctrl" })
326
330
-- success = true
327
331
-- break
328
332
-- end
@@ -373,7 +377,7 @@ local function SimpleConstructionProjectSelection(unitID, unitDefID, unitTeam, u
373
377
local targetUnit = units [random (1 ,# units )]
374
378
if isBuilding [spGetUnitDefID (targetUnit )] then
375
379
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnit )
376
- spGiveOrderToUnit (unitID , CMD . MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
380
+ spGiveOrderToUnit (unitID , CMD_MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
377
381
success = true
378
382
break
379
383
end
@@ -383,14 +387,14 @@ local function SimpleConstructionProjectSelection(unitID, unitDefID, unitTeam, u
383
387
local mapcenterZ = mapsizeZ / 2
384
388
local mapcenterY = spGetGroundHeight (mapcenterX , mapcenterZ )
385
389
local mapdiagonal = math.ceil (math.sqrt ((mapsizeX * mapsizeX )+ (mapsizeZ * mapsizeZ )))
386
- spGiveOrderToUnit (unitID , CMD . RECLAIM ,{mapcenterX + random (- 100 ,100 ),mapcenterY ,mapcenterZ + random (- 100 ,100 ),mapdiagonal }, 0 )
390
+ spGiveOrderToUnit (unitID , CMD_RECLAIM ,{mapcenterX + random (- 100 ,100 ),mapcenterY ,mapcenterZ + random (- 100 ,100 ),mapdiagonal }, 0 )
387
391
success = true
388
392
elseif r == 13 and type ~= " Commander" then
389
393
local mapcenterX = mapsizeX / 2
390
394
local mapcenterZ = mapsizeZ / 2
391
395
local mapcenterY = spGetGroundHeight (mapcenterX , mapcenterZ )
392
396
local mapdiagonal = math.ceil (math.sqrt ((mapsizeX * mapsizeX )+ (mapsizeZ * mapsizeZ )))
393
- spGiveOrderToUnit (unitID , CMD . REPAIR ,{mapcenterX + random (- 100 ,100 ),mapcenterY ,mapcenterZ + random (- 100 ,100 ),mapdiagonal }, 0 )
397
+ spGiveOrderToUnit (unitID , CMD_REPAIR ,{mapcenterX + random (- 100 ,100 ),mapcenterY ,mapcenterZ + random (- 100 ,100 ),mapdiagonal }, 0 )
394
398
success = true
395
399
else
396
400
local r2 = random (0 , 1 )
@@ -506,13 +510,13 @@ if gadgetHandler:IsSyncedCode() then
506
510
spGiveOrderToUnit (unitID , CMD .DGUN , {enemy }, {" shift" })
507
511
end
508
512
end
509
- spGiveOrderToUnit (unitID , CMD . MOVE , {unitposx , unitposy , unitposz }, {" shift" })
513
+ spGiveOrderToUnit (unitID , CMD_MOVE , {unitposx , unitposy , unitposz }, {" shift" })
510
514
elseif nearestEnemy then
511
515
for x = 1 ,10 do
512
516
local targetUnit = units [random (1 ,# units )]
513
517
if isBuilding [spGetUnitDefID (targetUnit )] then
514
518
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnit )
515
- spGiveOrderToUnit (unitID , CMD . MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, 0 )
519
+ spGiveOrderToUnit (unitID , CMD_MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, 0 )
516
520
break
517
521
end
518
522
end
@@ -524,13 +528,13 @@ if gadgetHandler:IsSyncedCode() then
524
528
local unitHealthPercentage = (unitHealth / unitMaxHealth )* 100
525
529
local nearestEnemy = spGetUnitNearestEnemy (unitID , 500 , true )
526
530
if nearestEnemy and unitHealthPercentage > 90 then
527
- spGiveOrderToUnit (unitID , CMD . RECLAIM , {nearestEnemy }, 0 )
531
+ spGiveOrderToUnit (unitID , CMD_RECLAIM , {nearestEnemy }, 0 )
528
532
elseif nearestEnemy then
529
533
for x = 1 ,100 do
530
534
local targetUnit = units [random (1 ,# units )]
531
535
if isBuilding [spGetUnitDefID (targetUnit )] then
532
536
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnit )
533
- spGiveOrderToUnit (unitID , CMD . MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, 0 )
537
+ spGiveOrderToUnit (unitID , CMD_MOVE , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, 0 )
534
538
break
535
539
end
536
540
end
@@ -560,20 +564,20 @@ if gadgetHandler:IsSyncedCode() then
560
564
local targetUnit = allunits [random (1 ,# allunits )]
561
565
if spGetUnitAllyTeam (targetUnit ) == allyTeamID then
562
566
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnit )
563
- spGiveOrderToUnit (unitID , CMD . FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
567
+ spGiveOrderToUnit (unitID , CMD_FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
564
568
break
565
569
end
566
570
end
567
571
else
568
572
local targetUnitNear = spGetUnitNearestEnemy (unitID , 2000 , false )
569
573
if targetUnitNear then
570
574
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnitNear )
571
- spGiveOrderToUnit (unitID , CMD . FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
575
+ spGiveOrderToUnit (unitID , CMD_FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
572
576
elseif n % 3600 <= 15 * SimpleAITeamIDsCount then
573
577
local targetUnit = spGetUnitNearestEnemy (unitID , 999999 , false )
574
578
if targetUnit then
575
579
local tUnitX , tUnitY , tUnitZ = spGetUnitPosition (targetUnit )
576
- spGiveOrderToUnit (unitID , CMD . FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
580
+ spGiveOrderToUnit (unitID , CMD_FIGHT , { tUnitX + random (- 100 , 100 ), tUnitY , tUnitZ + random (- 100 , 100 ) }, { " shift" , " alt" , " ctrl" })
577
581
end
578
582
end
579
583
end
0 commit comments