Update CTLD 110 - Caucasus - Build and Move.lua

Make code mor efficient
This commit is contained in:
Thomas 2022-11-13 16:52:43 +01:00 committed by GitHub
parent 3b8dda38e8
commit a80dc24dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ _SETTINGS:SetPlayerMenuOff()
local my_ctld = CTLD:New(coalition.side.BLUE,{"Helicargo"},"Lufttransportbrigade I")
my_ctld.forcehoverload = false
my_ctld.movetroopsdistance = 6000
my_ctld.dropcratesanywhere = true
my_ctld.debug = false
my_ctld.buildtime = 30
my_ctld:__Start(5)
@ -35,34 +36,37 @@ local dropzone = ZONE:FindByName("Dropzone"):DrawZone(-1,{0,0,1},1,{0,0,1},0.25,
-- update unit capabilities for testing
my_ctld:UnitCapabilities("SA342L", true, true, 1, 6, 12, 1000)
-- We're using OnBefore ... to add a MOVE zone
function my_ctld:OnBeforeTroopsDeployed(From,Event,To,Group,Unit,Troops)
-- Cache new MOVE zones here
local RedMoveZones = {}
function BuildMoveZones(Group,Unit,Troops)
-- find baddies near by with a ZONE filter
local zone = ZONE_GROUP:New(Group:GetName(),Group,6000)
local enemyset = SET_GROUP:New():FilterCoalitions("red"):FilterCategoryGround():FilterZones({zone}):FilterOnce()
if enemyset:Count() > 0 then
MESSAGE:New(string.format("Found %d enemy group nearby!", enemyset:Count()),15):ToAll()
-- baddies found, add zone around them
local zonename = "Baddies-"..math.random(1,10000)
local redzone = ZONE_RADIUS:New(zonename,enemyset:GetRandom():GetCoordinate():GetVec2(),200)
redzone:DrawZone(-1,{1,0.6,0},1,{1,0.6,0},0.25,4)
my_ctld:AddCTLDZone(zonename,CTLD.CargoZoneType.MOVE,SMOKECOLOR.Orange,true,false)
MESSAGE:New(string.format("Found %d enemy group(s) nearby!", enemyset:Count()),15):ToBlue()
for _,_redgrp in pairs(enemyset.Set) do
local redgrp = _redgrp -- Wrapper.Group#GROUP
if not RedMoveZones[redgrp:GetName()] then
-- baddies found, add zone around them
local zonename = "Baddies-"..math.random(1,10000)
local redzone = ZONE_GROUP:New(zonename,redgrp,200)
redzone:DrawZone(-1,{1,0.6,0},1,{1,0.6,0},0.25,4)
my_ctld:AddCTLDZone(zonename,CTLD.CargoZoneType.MOVE,SMOKECOLOR.Orange,true,false)
RedMoveZones[redgrp:GetName()] = redzone
end
end
end
end
-- We're using OnBefore ... to add a MOVE zone
function my_ctld:OnBeforeTroopsDeployed(From,Event,To,Group,Unit,Troops)
BuildMoveZones(Group,Unit,Troops)
return self
end
-- We're using OnBefore ... to add a MOVE zone
-- We're using OnBefore ... to add a MOVE zone
function my_ctld:OnBeforeCratesBuild(From,Event,To,Group,Unit,Vehicle)
-- find baddies near by with a ZONE filter
local zone = ZONE_GROUP:New(Group:GetName(),Group,6000)
local enemyset = SET_GROUP:New():FilterCoalitions("red"):FilterCategoryGround():FilterZones({zone}):FilterOnce()
if enemyset:Count() > 0 then
MESSAGE:New(string.format("Found %d enemy group nearby!", enemyset:Count()),15):ToAll()
-- baddies found, add zone around them
local zonename = "Baddies-"..math.random(1,10000)
local redzone = ZONE_RADIUS:New(zonename,enemyset:GetRandom():GetCoordinate():GetVec2(),200)
redzone:DrawZone(-1,{1,0.6,0},1,{1,0.6,0},0.25,4)
my_ctld:AddCTLDZone(zonename,CTLD.CargoZoneType.MOVE,SMOKECOLOR.Orange,true,false)
end
BuildMoveZones(Group,Unit,Vehicle)
return self
end
end