Update CTLD.lua (#1666)

Code formatting. Minor typos and text fixes.
This commit is contained in:
TommyC81
2021-12-17 12:07:24 +04:00
committed by GitHub
parent e8e790102a
commit 2694321256
+118 -69
View File
@@ -318,7 +318,8 @@ CTLD_CARGO = {
ClassName = "CTLD_CARGO", ClassName = "CTLD_CARGO",
ID = 0, ID = 0,
Name = "none", Name = "none",
Templates = {}, Templates = {
},
CargoType = "none", CargoType = "none",
HasBeenMoved = false, HasBeenMoved = false,
LoadDirectly = false, LoadDirectly = false,
@@ -348,7 +349,7 @@ CTLD_CARGO = {
-- @param #number ID ID of this #CTLD_CARGO -- @param #number ID ID of this #CTLD_CARGO
-- @param #string Name Name for menu. -- @param #string Name Name for menu.
-- @param #table Templates Table of #POSITIONABLE objects. -- @param #table Templates Table of #POSITIONABLE objects.
-- @param #CTLD_CARGO.Enum Sorte Enumerator of Type. -- @param #CTLD_CARGO.Enum SortEnum Enumerator of Type.
-- @param #boolean HasBeenMoved Flag for moving. -- @param #boolean HasBeenMoved Flag for moving.
-- @param #boolean LoadDirectly Flag for direct loading. -- @param #boolean LoadDirectly Flag for direct loading.
-- @param #number CratesNeeded Crates needed to build. -- @param #number CratesNeeded Crates needed to build.
@@ -357,14 +358,14 @@ CTLD_CARGO = {
-- @param #number PerCrateMass Mass in kg -- @param #number PerCrateMass Mass in kg
-- @param #number Stock Number of builds available, nil for unlimited -- @param #number Stock Number of builds available, nil for unlimited
-- @return #CTLD_CARGO self -- @return #CTLD_CARGO self
function CTLD_CARGO:New(ID, Name, Templates, Sorte, HasBeenMoved, LoadDirectly, CratesNeeded, Positionable, Dropped, PerCrateMass, Stock) function CTLD_CARGO:New( ID, Name, Templates, SortEnum, HasBeenMoved, LoadDirectly, CratesNeeded, Positionable, Dropped, PerCrateMass, Stock )
-- Inherit everything from BASE class. -- Inherit everything from BASE class.
local self = BASE:Inherit( self, BASE:New() ) -- #CTLD local self = BASE:Inherit( self, BASE:New() ) -- #CTLD
self:T({ID, Name, Templates, Sorte, HasBeenMoved, LoadDirectly, CratesNeeded, Positionable, Dropped}) self:T( { ID, Name, Templates, SortEnum, HasBeenMoved, LoadDirectly, CratesNeeded, Positionable, Dropped } )
self.ID = ID or math.random( 100000, 1000000 ) self.ID = ID or math.random( 100000, 1000000 )
self.Name = Name or "none" -- #string self.Name = Name or "none" -- #string
self.Templates = Templates or {} -- #table self.Templates = Templates or {} -- #table
self.CargoType = Sorte or "type" -- #CTLD_CARGO.Enum self.CargoType = SortEnum or "type" -- #CTLD_CARGO.Enum
self.HasBeenMoved = HasBeenMoved or false -- #boolean self.HasBeenMoved = HasBeenMoved or false -- #boolean
self.LoadDirectly = LoadDirectly or false -- #boolean self.LoadDirectly = LoadDirectly or false -- #boolean
self.CratesNeeded = CratesNeeded or 0 -- #number self.CratesNeeded = CratesNeeded or 0 -- #number
@@ -501,7 +502,9 @@ CTLD_CARGO = {
if self.Stock then -- Stock nil? if self.Stock then -- Stock nil?
local number = Number or 1 local number = Number or 1
self.Stock = self.Stock - number self.Stock = self.Stock - number
if self.Stock < 0 then self.Stock = 0 end if self.Stock < 0 then
self.Stock = 0
end
end end
return self return self
end end
@@ -554,7 +557,7 @@ do
-- @field #number coalition Coalition side number, e.g. `coalition.side.RED`. -- @field #number coalition Coalition side number, e.g. `coalition.side.RED`.
-- @extends Core.Fsm#FSM -- @extends Core.Fsm#FSM
--- *Combat Troop & Logistics Deployment (CTLD): Everyone wants to be a POG, until there\'s POG stuff to be done.* (Mil Saying) --- *Combat Troop & Logistics Deployment (CTLD): Everyone wants to be a POG, until there's POG stuff to be done.* (Mil Saying)
-- --
-- === -- ===
-- --
@@ -563,7 +566,7 @@ do
-- # CTLD Concept -- # CTLD Concept
-- --
-- * MOOSE-based CTLD for Players. -- * MOOSE-based CTLD for Players.
-- * Object oriented refactoring of Ciribob\'s fantastic CTLD script. -- * Object oriented refactoring of Ciribob's fantastic CTLD script.
-- * No need for extra MIST loading. -- * No need for extra MIST loading.
-- * Additional events to tailor your mission. -- * Additional events to tailor your mission.
-- * ANY late activated group can serve as cargo, either as troops, crates, which have to be build on-location, or static like ammo chests. -- * ANY late activated group can serve as cargo, either as troops, crates, which have to be build on-location, or static like ammo chests.
@@ -571,7 +574,7 @@ do
-- --
-- ## 0. Prerequisites -- ## 0. Prerequisites
-- --
-- You need to load an .ogg soundfile for the pilot\'s beacons into the mission, e.g. "beacon.ogg", use a once trigger, "sound to country" for that. -- You need to load an .ogg sound file for the pilot's beacons into the mission, e.g. "beacon.ogg", use a once trigger, "sound to country" for that.
-- Create the late-activated troops, vehicles (no statics at this point!) that will make up your deployable forces. -- Create the late-activated troops, vehicles (no statics at this point!) that will make up your deployable forces.
-- --
-- ## 1. Basic Setup -- ## 1. Basic Setup
@@ -598,7 +601,7 @@ do
-- my_ctld:AddTroopsCargo("Anti-Air",{"AA","AA2"},CTLD_CARGO.Enum.TROOPS,4,nil,2) -- my_ctld:AddTroopsCargo("Anti-Air",{"AA","AA2"},CTLD_CARGO.Enum.TROOPS,4,nil,2)
-- --
-- -- add an engineers unit called "Wrenches" using template "Engineers", of type ENGINEERS with size 2. Engineers can be loaded, dropped, -- -- add an engineers unit called "Wrenches" using template "Engineers", of type ENGINEERS with size 2. Engineers can be loaded, dropped,
-- -- and extracted like troops. However, they will seek to build and/or repair crates found in a given radius. Handy if you can\'t stay -- -- and extracted like troops. However, they will seek to build and/or repair crates found in a given radius. Handy if you can't stay
-- -- to build or repair or under fire. -- -- to build or repair or under fire.
-- my_ctld:AddTroopsCargo("Wrenches",{"Engineers"},CTLD_CARGO.Enum.ENGINEERS,4) -- my_ctld:AddTroopsCargo("Wrenches",{"Engineers"},CTLD_CARGO.Enum.ENGINEERS,4)
-- myctld.EngineerSearch = 2000 -- teams will search for crates in this radius. -- myctld.EngineerSearch = 2000 -- teams will search for crates in this radius.
@@ -619,7 +622,7 @@ do
-- my_ctld.repairtime = 300 -- takes 300 seconds to repair something -- my_ctld.repairtime = 300 -- takes 300 seconds to repair something
-- --
-- -- add static cargo objects, e.g ammo chests - the name needs to refer to a STATIC object in the mission editor, -- -- add static cargo objects, e.g ammo chests - the name needs to refer to a STATIC object in the mission editor,
-- -- here: it\'s the UNIT name (not the GROUP name!), the second parameter is the weight in kg. -- -- here: it's the UNIT name (not the GROUP name!), the second parameter is the weight in kg.
-- my_ctld:AddStaticsCargo("Ammunition",500) -- my_ctld:AddStaticsCargo("Ammunition",500)
-- --
-- ## 1.3 Add logistics zones -- ## 1.3 Add logistics zones
@@ -696,7 +699,6 @@ do
-- ["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18}, -- ["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18},
-- ["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25}, -- ["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25},
-- --
--
-- ### 2.1.2 Activate and deactivate zones -- ### 2.1.2 Activate and deactivate zones
-- --
-- Activate a zone: -- Activate a zone:
@@ -984,8 +986,7 @@ CTLD.UnitTypes = {
["Ka-50"] = { type = "Ka-50", crates = false, troops = false, cratelimit = 0, trooplimit = 0, length = 15 }, ["Ka-50"] = { type = "Ka-50", crates = false, troops = false, cratelimit = 0, trooplimit = 0, length = 15 },
["Mi-24P"] = { type = "Mi-24P", crates = true, troops = true, cratelimit = 2, trooplimit = 8, length = 18 }, ["Mi-24P"] = { type = "Mi-24P", crates = true, troops = true, cratelimit = 2, trooplimit = 8, length = 18 },
["Mi-24V"] = { type = "Mi-24V", crates = true, troops = true, cratelimit = 2, trooplimit = 8, length = 18 }, ["Mi-24V"] = { type = "Mi-24V", crates = true, troops = true, cratelimit = 2, trooplimit = 8, length = 18 },
["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25}, -- 19t cargo, 64 paratroopers. ["Hercules"] = { type = "Hercules", crates = true, troops = true, cratelimit = 7, trooplimit = 64, length = 25 }, -- 19t cargo, 64 paratroopers. Actually it's longer, but the center coord is off-center of the model.
--Actually it's longer, but the center coord is off-center of the model.
} }
--- CTLD class version. --- CTLD class version.
@@ -1349,7 +1350,6 @@ function CTLD:_GetUnitCapabilities(Unit)
return capabilities return capabilities
end end
--- (Internal) Function to generate valid UHF Frequencies --- (Internal) Function to generate valid UHF Frequencies
-- @param #CTLD self -- @param #CTLD self
function CTLD:_GenerateUHFrequencies() function CTLD:_GenerateUHFrequencies()
@@ -1454,13 +1454,19 @@ function CTLD:_LoadTroops(Group, Unit, Cargotype)
end end
if not inzone then if not inzone then
self:_SendMessage( "You are not close enough to a logistics zone!", 10, false, Group ) self:_SendMessage( "You are not close enough to a logistics zone!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
elseif not grounded and not hoverload then elseif not grounded and not hoverload then
self:_SendMessage( "You need to land or hover in position to load!", 10, false, Group ) self:_SendMessage( "You need to land or hover in position to load!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
elseif self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then elseif self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then
self:_SendMessage( "You need to open the door(s) to load troops!", 10, false, Group ) self:_SendMessage( "You need to open the door(s) to load troops!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
end end
-- load troops into heli -- load troops into heli
local group = Group -- Wrapper.Group#GROUP local group = Group -- Wrapper.Group#GROUP
@@ -1544,7 +1550,9 @@ function CTLD:_FindRepairNearby(Group, Unit, Repairtype)
end end
else else
if type( String ) == "string" then if type( String ) == "string" then
if string.find(String,Table) then match = true end if string.find( String, Table ) then
match = true
end
end end
end end
return match return match
@@ -1585,7 +1593,9 @@ function CTLD:_RepairObjectFromCrates(Group,Unit,Crates,Build,Number,Engineering
local NearestGroup, CargoType = self:_FindRepairNearby( Group, Unit, Repairtype ) -- Wrapper.Group#GROUP, #CTLD_CARGO local NearestGroup, CargoType = self:_FindRepairNearby( Group, Unit, Repairtype ) -- Wrapper.Group#GROUP, #CTLD_CARGO
-- self:I({Repairtype=Repairtype, CargoType=CargoType, NearestGroup=NearestGroup}) -- self:I({Repairtype=Repairtype, CargoType=CargoType, NearestGroup=NearestGroup})
if NearestGroup ~= nil then if NearestGroup ~= nil then
if self.repairtime < 2 then self.repairtime = 30 end -- noob catch if self.repairtime < 2 then
self.repairtime = 30
end -- noob catch
if not Engineering then if not Engineering then
self:_SendMessage( string.format( "Repair started using %s taking %d secs", build.Name, self.repairtime ), 10, false, Group ) self:_SendMessage( string.format( "Repair started using %s taking %d secs", build.Name, self.repairtime ), 10, false, Group )
end end
@@ -1603,7 +1613,9 @@ function CTLD:_RepairObjectFromCrates(Group,Unit,Crates,Build,Number,Engineering
object.CanBuild = true object.CanBuild = true
object.Type = ctype -- #CTLD_CARGO.Enum object.Type = ctype -- #CTLD_CARGO.Enum
self:_CleanUpCrates( Crates, Build, Number ) self:_CleanUpCrates( Crates, Build, Number )
local desttimer = TIMER:New(function() NearestGroup:Destroy(false) end, self) local desttimer = TIMER:New( function()
NearestGroup:Destroy( false )
end, self )
desttimer:Start( self.repairtime - 1 ) desttimer:Start( self.repairtime - 1 )
local buildtimer = TIMER:New( self._BuildObjectFromCrates, self, Group, Unit, object, true, NearestGroup:GetCoordinate() ) local buildtimer = TIMER:New( self._BuildObjectFromCrates, self, Group, Unit, object, true, NearestGroup:GetCoordinate() )
buildtimer:Start( self.repairtime ) buildtimer:Start( self.repairtime )
@@ -1630,11 +1642,15 @@ end
if not grounded and not hoverload then if not grounded and not hoverload then
self:_SendMessage( "You need to land or hover in position to load!", 10, false, Group ) self:_SendMessage( "You need to land or hover in position to load!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
end end
if self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then if self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then
self:_SendMessage( "You need to open the door(s) to extract troops!", 10, false, Group ) self:_SendMessage( "You need to open the door(s) to extract troops!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
end end
-- load troops into heli -- load troops into heli
local unit = Unit -- Wrapper.Unit#UNIT local unit = Unit -- Wrapper.Unit#UNIT
@@ -1681,7 +1697,11 @@ end
local Cargotype = nil local Cargotype = nil
for k, v in pairs( self.Cargo_Troops ) do for k, v in pairs( self.Cargo_Troops ) do
local comparison = "" local comparison = ""
if type(v.Templates) == "string" then comparison = v.Templates else comparison = v.Templates[1] end if type( v.Templates ) == "string" then
comparison = v.Templates
else
comparison = v.Templates[1]
end
if comparison == groupType then if comparison == groupType then
Cargotype = v Cargotype = v
break break
@@ -1751,7 +1771,7 @@ end
-- @param Wrapper.Unit#UNIT Unit -- @param Wrapper.Unit#UNIT Unit
-- @param #CTLD_CARGO Cargo -- @param #CTLD_CARGO Cargo
-- @param #number number Number of crates to generate (for dropping) -- @param #number number Number of crates to generate (for dropping)
-- @param #boolean drop If true we\'re dropping from heli rather than loading. -- @param #boolean drop If true we're dropping from heli rather than loading.
function CTLD:_GetCrates( Group, Unit, Cargo, number, drop ) function CTLD:_GetCrates( Group, Unit, Cargo, number, drop )
self:T( self.lid .. " _GetCrates" ) self:T( self.lid .. " _GetCrates" )
if not drop then if not drop then
@@ -1784,7 +1804,9 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
if not inzone then if not inzone then
self:_SendMessage( "You are not close enough to a logistics zone!", 10, false, Group ) self:_SendMessage( "You are not close enough to a logistics zone!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
end end
-- avoid crate spam -- avoid crate spam
@@ -1828,7 +1850,9 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
local cratealias = string.format( "%s-%d", cratetemplate, math.random( 1, 100000 ) ) local cratealias = string.format( "%s-%d", cratetemplate, math.random( 1, 100000 ) )
if not self.placeCratesAhead then if not self.placeCratesAhead then
cratedistance = (i - 1) * 2.5 + capabilities.length cratedistance = (i - 1) * 2.5 + capabilities.length
if cratedistance > self.CrateDistance then cratedistance = self.CrateDistance end if cratedistance > self.CrateDistance then
cratedistance = self.CrateDistance
end
-- altered heading logic -- altered heading logic
-- DONE: right standard deviation? -- DONE: right standard deviation?
rheading = UTILS.RandomGaussian( 0, 30, -90, 90, 100 ) rheading = UTILS.RandomGaussian( 0, 30, -90, 90, 100 )
@@ -1869,8 +1893,7 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
dist = dist - (20 + math.random( 1, 10 )) dist = dist - (20 + math.random( 1, 10 ))
local width = width / 2 local width = width / 2
local Offy = math.random( -width, width ) local Offy = math.random( -width, width )
self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType(basetype,"Cargos",self.cratecountry) self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType( basetype, "Cargos", self.cratecountry ) -- :InitCoordinate(cratecoord)
--:InitCoordinate(cratecoord)
:InitCargoMass( cgomass ) :InitCargoMass( cgomass )
:InitCargo( self.enableslingload ) :InitCargo( self.enableslingload )
:InitLinkToUnit( Ship, dist, Offy, 0 ) :InitLinkToUnit( Ship, dist, Offy, 0 )
@@ -1879,8 +1902,7 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType( basetype, "Cargos", self.cratecountry ) self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType( basetype, "Cargos", self.cratecountry )
:InitCoordinate( cratecoord ) :InitCoordinate( cratecoord )
:InitCargoMass( cgomass ) :InitCargoMass( cgomass )
:InitCargo(self.enableslingload) :InitCargo( self.enableslingload ) -- :InitLinkToUnit(Unit,OffsetX,OffsetY,OffsetAngle)
--:InitLinkToUnit(Unit,OffsetX,OffsetY,OffsetAngle)
:Spawn( 270, cratealias ) :Spawn( 270, cratealias )
end end
local templ = cargotype:GetTemplates() local templ = cargotype:GetTemplates()
@@ -2076,7 +2098,7 @@ function CTLD:_LoadCratesNearby(Group, Unit)
local grounded = not self:IsUnitInAir( Unit ) local grounded = not self:IsUnitInAir( Unit )
local canhoverload = self:CanHoverLoad( Unit ) local canhoverload = self:CanHoverLoad( Unit )
--- cases ------------------------------- --- cases -------------------------------
-- Chopper can\'t do crates - bark & return -- Chopper can't do crates - bark & return
-- Chopper can do crates - -- Chopper can do crates -
-- --> hover if forcedhover or bark and return -- --> hover if forcedhover or bark and return
-- --> hover or land if not forcedhover -- --> hover or land if not forcedhover
@@ -2396,7 +2418,9 @@ function CTLD:_UnloadTroops(Group, Unit)
local canunload = true local canunload = true
if self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then if self.pilotmustopendoors and not UTILS.IsLoadingDoorOpen( Unit:GetName() ) then
self:_SendMessage( "You need to open the door(s) to unload troops!", 10, false, Group ) self:_SendMessage( "You need to open the door(s) to unload troops!", 10, false, Group )
if not self.debug then return self end if not self.debug then
return self
end
end end
local inzone, zonename, zone, distance = self:IsUnitInZone( Unit, CTLD.CargoZoneType.LOAD ) local inzone, zonename, zone, distance = self:IsUnitInZone( Unit, CTLD.CargoZoneType.LOAD )
if not inzone then if not inzone then
@@ -2406,13 +2430,13 @@ function CTLD:_UnloadTroops(Group, Unit)
droppingatbase = true droppingatbase = true
end end
-- check for hover unload -- check for hover unload
local hoverunload = self:IsCorrectHover(Unit) --if true we\'re hovering in parameters local hoverunload = self:IsCorrectHover( Unit ) -- if true we're hovering in parameters
local IsHerc = self:IsHercules( Unit ) local IsHerc = self:IsHercules( Unit )
if IsHerc then if IsHerc then
-- no hover but airdrop here -- no hover but airdrop here
hoverunload = self:IsCorrectFlightParameters( Unit ) hoverunload = self:IsCorrectFlightParameters( Unit )
end end
-- check if we\'re landed -- check if we're landed
local grounded = not self:IsUnitInAir( Unit ) local grounded = not self:IsUnitInAir( Unit )
-- Get what we have loaded -- Get what we have loaded
local unitname = Unit:GetName() local unitname = Unit:GetName()
@@ -2490,7 +2514,9 @@ function CTLD:_UnloadTroops(Group, Unit)
if _troop.Name == name then if _troop.Name == name then
local stock = _troop:GetStock() local stock = _troop:GetStock()
-- avoid making unlimited stock limited -- avoid making unlimited stock limited
if stock and tonumber(stock) >= 0 then _troop:AddStock() end if stock and tonumber( stock ) >= 0 then
_troop:AddStock()
end
end end
end end
end end
@@ -2527,13 +2553,13 @@ function CTLD:_UnloadCrates(Group, Unit)
end end
end end
-- check for hover unload -- check for hover unload
local hoverunload = self:IsCorrectHover(Unit) --if true we\'re hovering in parameters local hoverunload = self:IsCorrectHover( Unit ) -- if true we're hovering in parameters
local IsHerc = self:IsHercules( Unit ) local IsHerc = self:IsHercules( Unit )
if IsHerc then if IsHerc then
-- no hover but airdrop here -- no hover but airdrop here
hoverunload = self:IsCorrectFlightParameters( Unit ) hoverunload = self:IsCorrectFlightParameters( Unit )
end end
-- check if we\'re landed -- check if we're landed
local grounded = not self:IsUnitInAir( Unit ) local grounded = not self:IsUnitInAir( Unit )
-- Get what we have loaded -- Get what we have loaded
local unitname = Unit:GetName() local unitname = Unit:GetName()
@@ -2633,7 +2659,7 @@ function CTLD:_BuildCrates(Group, Unit,Engineering)
self:T( { buildables = buildables } ) self:T( { buildables = buildables } )
end -- end dropped end -- end dropped
end -- end crate loop end -- end crate loop
-- ok let\'s list what we have -- ok let's list what we have
local report = REPORT:New( "Checklist Buildable Crates" ) local report = REPORT:New( "Checklist Buildable Crates" )
report:Add( "------------------------------------------------------------" ) report:Add( "------------------------------------------------------------" )
for _, _build in pairs( buildables ) do for _, _build in pairs( buildables ) do
@@ -2648,7 +2674,9 @@ function CTLD:_BuildCrates(Group, Unit,Engineering)
local text = string.format( "Type: %s | Required %d | Found %d | Can Build %s", name, needed, found, txtok ) local text = string.format( "Type: %s | Required %d | Found %d | Can Build %s", name, needed, found, txtok )
report:Add( text ) report:Add( text )
end -- end list buildables end -- end list buildables
if not foundbuilds then report:Add(" --- None Found ---") end if not foundbuilds then
report:Add( " --- None Found ---" )
end
report:Add( "------------------------------------------------------------" ) report:Add( "------------------------------------------------------------" )
local text = report:Text() local text = report:Text()
if not Engineering then if not Engineering then
@@ -2656,7 +2684,7 @@ function CTLD:_BuildCrates(Group, Unit,Engineering)
else else
self:T( text ) self:T( text )
end end
-- let\'s get going -- let's get going
if canbuild then if canbuild then
-- loop again -- loop again
for _, _build in pairs( buildables ) do for _, _build in pairs( buildables ) do
@@ -2668,7 +2696,9 @@ function CTLD:_BuildCrates(Group, Unit,Engineering)
end end
end end
else else
if not Engineering then self:_SendMessage(string.format("No crates within %d meters!",finddist), 10, false, Group) end if not Engineering then
self:_SendMessage( string.format( "No crates within %d meters!", finddist ), 10, false, Group )
end
end -- number > 0 end -- number > 0
return self return self
end end
@@ -2717,7 +2747,7 @@ function CTLD:_RepairCrates(Group, Unit, Engineering)
self:T( { repair = buildables } ) self:T( { repair = buildables } )
end -- end dropped end -- end dropped
end -- end crate loop end -- end crate loop
-- ok let\'s list what we have -- ok let's list what we have
local report = REPORT:New( "Checklist Repairs" ) local report = REPORT:New( "Checklist Repairs" )
report:Add( "------------------------------------------------------------" ) report:Add( "------------------------------------------------------------" )
for _, _build in pairs( buildables ) do for _, _build in pairs( buildables ) do
@@ -2732,7 +2762,9 @@ function CTLD:_RepairCrates(Group, Unit, Engineering)
local text = string.format( "Type: %s | Required %d | Found %d | Can Repair %s", name, needed, found, txtok ) local text = string.format( "Type: %s | Required %d | Found %d | Can Repair %s", name, needed, found, txtok )
report:Add( text ) report:Add( text )
end -- end list buildables end -- end list buildables
if not foundbuilds then report:Add(" --- None Found ---") end if not foundbuilds then
report:Add( " --- None Found ---" )
end
report:Add( "------------------------------------------------------------" ) report:Add( "------------------------------------------------------------" )
local text = report:Text() local text = report:Text()
if not Engineering then if not Engineering then
@@ -2740,7 +2772,7 @@ function CTLD:_RepairCrates(Group, Unit, Engineering)
else else
self:T( text ) self:T( text )
end end
-- let\'s get going -- let's get going
if canbuild then if canbuild then
-- loop again -- loop again
for _, _build in pairs( buildables ) do for _, _build in pairs( buildables ) do
@@ -2751,7 +2783,9 @@ function CTLD:_RepairCrates(Group, Unit, Engineering)
end end
end end
else else
if not Engineering then self:_SendMessage(string.format("No crates within %d meters!",finddist), 10, false, Group) end if not Engineering then
self:_SendMessage( string.format( "No crates within %d meters!", finddist ), 10, false, Group )
end
end -- number > 0 end -- number > 0
return self return self
end end
@@ -2772,7 +2806,9 @@ function CTLD:_BuildObjectFromCrates(Group,Unit,Build,Repair,RepairLocation)
local name = Build.Name local name = Build.Name
local ctype = Build.Type -- #CTLD_CARGO.Enum local ctype = Build.Type -- #CTLD_CARGO.Enum
local canmove = false local canmove = false
if ctype == CTLD_CARGO.Enum.VEHICLE then canmove = true end if ctype == CTLD_CARGO.Enum.VEHICLE then
canmove = true
end
if ctype == CTLD_CARGO.Enum.STATIC then if ctype == CTLD_CARGO.Enum.STATIC then
return self return self
end end
@@ -2867,7 +2903,9 @@ function CTLD:_CleanUpCrates(Crates,Build,Number)
nowcrate.Positionable = nil nowcrate.Positionable = nil
nowcrate.HasBeenDropped = false nowcrate.HasBeenDropped = false
end end
if found == numberdest then break end -- got enough if found == numberdest then
break
end -- got enough
end end
-- loop and remove from real world representation -- loop and remove from real world representation
self:_CleanupTrackedCrates( destIDs ) self:_CleanupTrackedCrates( destIDs )
@@ -3080,7 +3118,7 @@ end
function CTLD:ActivateZone( Name, ZoneType, NewState ) function CTLD:ActivateZone( Name, ZoneType, NewState )
self:T( self.lid .. " AddZone" ) self:T( self.lid .. " AddZone" )
local newstate = true local newstate = true
-- set optional in case we\'re deactivating -- set optional in case we're deactivating
if NewState ~= nil then if NewState ~= nil then
newstate = NewState newstate = NewState
end end
@@ -3107,7 +3145,6 @@ function CTLD:ActivateZone(Name,ZoneType,NewState)
return self return self
end end
--- User function - Deactivate Name #CTLD.CargoZoneType ZoneType for this CTLD instance. --- User function - Deactivate Name #CTLD.CargoZoneType ZoneType for this CTLD instance.
-- @param #CTLD self -- @param #CTLD self
-- @param #string Name Name of the zone to change in the ME. -- @param #string Name Name of the zone to change in the ME.
@@ -3179,7 +3216,6 @@ function CTLD:_GetVHFBeacon(Name)
return beacon return beacon
end end
--- User function - Crates and adds a #CTLD.CargoZone zone for this CTLD instance. --- User function - Crates and adds a #CTLD.CargoZone zone for this CTLD instance.
-- Zones of type LOAD: Players load crates and troops here. -- Zones of type LOAD: Players load crates and troops here.
-- Zones of type DROP: Players can drop crates here. Note that troops can be unloaded anywhere. -- Zones of type DROP: Players can drop crates here. Note that troops can be unloaded anywhere.
@@ -3289,7 +3325,9 @@ function CTLD:_RefreshRadioBeacons()
local zones = { [1] = self.pickupZones, [2] = self.wpZones, [3] = self.dropOffZones, [4] = self.shipZones } local zones = { [1] = self.pickupZones, [2] = self.wpZones, [3] = self.dropOffZones, [4] = self.shipZones }
for i = 1, 4 do for i = 1, 4 do
local IsShip = false local IsShip = false
if i == 4 then IsShip = true end if i == 4 then
IsShip = true
end
for index, cargozone in pairs( zones[i] ) do for index, cargozone in pairs( zones[i] ) do
-- Get Beacon object from zone -- Get Beacon object from zone
local czone = cargozone -- #CTLD.CargoZone local czone = cargozone -- #CTLD.CargoZone
@@ -3335,7 +3373,7 @@ function CTLD:IsUnitInZone(Unit,Zonetype)
else else
zonetable = self.wpZones -- #table zonetable = self.wpZones -- #table
end end
--- now see if we\'re in --- now see if we're in
local zonecoord = nil local zonecoord = nil
local colorret = nil local colorret = nil
local maxdist = 1000000 -- 100km local maxdist = 1000000 -- 100km
@@ -3430,15 +3468,19 @@ function CTLD:SmokeZoneNearBy(Unit, Flare)
local color = CZone.color local color = CZone.color
local distance = self:_GetDistance( zonecoord, unitcoord ) local distance = self:_GetDistance( zonecoord, unitcoord )
if distance < smokedistance and active then if distance < smokedistance and active then
-- smoke zone since we\'re nearby -- smoke zone since we're nearby
if not Flare then if not Flare then
zonecoord:Smoke( color or SMOKECOLOR.White ) zonecoord:Smoke( color or SMOKECOLOR.White )
else else
if color == SMOKECOLOR.Blue then color = FLARECOLOR.White end if color == SMOKECOLOR.Blue then
color = FLARECOLOR.White
end
zonecoord:Flare( color or FLARECOLOR.White ) zonecoord:Flare( color or FLARECOLOR.White )
end end
local txt = "smoking" local txt = "smoking"
if Flare then txt = "flaring" end if Flare then
txt = "flaring"
end
self:_SendMessage( string.format( "Roger, %s zone %s!", txt, zonename ), 10, false, Group ) self:_SendMessage( string.format( "Roger, %s zone %s!", txt, zonename ), 10, false, Group )
smoked = true smoked = true
end end
@@ -3546,7 +3588,9 @@ end
function CTLD:_ShowHoverParams( Group, Unit ) function CTLD:_ShowHoverParams( Group, Unit )
local inhover = self:IsCorrectHover( Unit ) local inhover = self:IsCorrectHover( Unit )
local htxt = "true" local htxt = "true"
if not inhover then htxt = "false" end if not inhover then
htxt = "false"
end
local text = "" local text = ""
if _SETTINGS:IsMetric() then if _SETTINGS:IsMetric() then
text = string.format( "Hover parameters (autoload/drop):\n - Min height %dm \n - Max height %dm \n - Max speed 2mps \n - In parameter: %s", self.minimumHoverHeight, self.maximumHoverHeight, htxt ) text = string.format( "Hover parameters (autoload/drop):\n - Min height %dm \n - Max height %dm \n - Max speed 2mps \n - In parameter: %s", self.minimumHoverHeight, self.maximumHoverHeight, htxt )
@@ -3566,7 +3610,9 @@ end
function CTLD:_ShowFlightParams( Group, Unit ) function CTLD:_ShowFlightParams( Group, Unit )
local inhover = self:IsCorrectFlightParameters( Unit ) local inhover = self:IsCorrectFlightParameters( Unit )
local htxt = "true" local htxt = "true"
if not inhover then htxt = "false" end if not inhover then
htxt = "false"
end
local text = "" local text = ""
if _SETTINGS:IsImperial() then if _SETTINGS:IsImperial() then
local minheight = UTILS.MetersToFeet( self.HercMinAngels ) local minheight = UTILS.MetersToFeet( self.HercMinAngels )
@@ -3581,14 +3627,15 @@ end
return self return self
end end
--- (Internal) Check if a unit is in a load zone and is hovering in parameters. --- (Internal) Check if a unit is in a load zone and is hovering in parameters.
-- @param #CTLD self -- @param #CTLD self
-- @param Wrapper.Unit#UNIT Unit -- @param Wrapper.Unit#UNIT Unit
-- @return #boolean Outcome -- @return #boolean Outcome
function CTLD:CanHoverLoad( Unit ) function CTLD:CanHoverLoad( Unit )
self:T( self.lid .. " CanHoverLoad" ) self:T( self.lid .. " CanHoverLoad" )
if self:IsHercules(Unit) then return false end if self:IsHercules( Unit ) then
return false
end
local outcome = self:IsUnitInZone( Unit, CTLD.CargoZoneType.LOAD ) and self:IsCorrectHover( Unit ) local outcome = self:IsUnitInZone( Unit, CTLD.CargoZoneType.LOAD ) and self:IsCorrectHover( Unit )
if not outcome then if not outcome then
outcome = self:IsUnitInZone( Unit, CTLD.CargoZoneType.SHIP ) -- and self:IsCorrectHover(Unit) outcome = self:IsUnitInZone( Unit, CTLD.CargoZoneType.SHIP ) -- and self:IsCorrectHover(Unit)
@@ -3654,7 +3701,9 @@ end
if self.hoverautoloading then if self.hoverautoloading then
for _, _pilot in pairs( self.CtldUnits ) do for _, _pilot in pairs( self.CtldUnits ) do
local Unit = UNIT:FindByName( _pilot ) local Unit = UNIT:FindByName( _pilot )
if self:CanHoverLoad(Unit) then self:AutoHoverLoad(Unit) end if self:CanHoverLoad( Unit ) then
self:AutoHoverLoad( Unit )
end
end end
end end
return self return self
@@ -3909,7 +3958,9 @@ end
local randomcoord = zone:GetRandomCoordinate( 10, 30 * factor ):GetVec2() local randomcoord = zone:GetRandomCoordinate( 10, 30 * factor ):GetVec2()
cargo:SetWasDropped( true ) cargo:SetWasDropped( true )
local canmove = false local canmove = false
if type == CTLD_CARGO.Enum.VEHICLE then canmove = true end if type == CTLD_CARGO.Enum.VEHICLE then
canmove = true
end
for _, _template in pairs( temptable ) do for _, _template in pairs( temptable ) do
self.TroopCounter = self.TroopCounter + 1 self.TroopCounter = self.TroopCounter + 1
local alias = string.format( "%s-%d", _template, math.random( 1, 100000 ) ) local alias = string.format( "%s-%d", _template, math.random( 1, 100000 ) )
@@ -4095,7 +4146,6 @@ end
return self return self
end end
--- (Internal) FSM Function onbeforeTroopsDeployed. --- (Internal) FSM Function onbeforeTroopsDeployed.
-- @param #CTLD self -- @param #CTLD self
-- @param #string From State. -- @param #string From State.
@@ -4246,12 +4296,13 @@ end
cargo = thiscargo cargo = thiscargo
end end
end end
if match then break end if match then
break
end
end end
return match, cargo return match, cargo
end end
-- local data = "LoadedData = {\n" -- local data = "LoadedData = {\n"
local data = "Group,x,y,z,CargoName,CargoTemplates,CargoType,CratesNeeded,CrateMass\n" local data = "Group,x,y,z,CargoName,CargoTemplates,CargoType,CratesNeeded,CrateMass\n"
local n = 0 local n = 0
@@ -4288,8 +4339,7 @@ end
end end
local location = group:GetVec3() local location = group:GetVec3()
local txt = string.format("%s,%d,%d,%d,%s,%s,%s,%d,%d\n" local txt = string.format( "%s,%d,%d,%d,%s,%s,%s,%d,%d\n", template, location.x, location.y, location.z, cgoname, cgotemp, cgotype, cgoneed, cgomass )
,template,location.x,location.y,location.z,cgoname,cgotemp,cgotype,cgoneed,cgomass)
data = data .. txt data = data .. txt
end end
end end
@@ -4314,8 +4364,7 @@ end
local cgomass = object.PerCrateMass local cgomass = object.PerCrateMass
local crateobj = object.Positionable local crateobj = object.Positionable
local location = crateobj:GetVec3() local location = crateobj:GetVec3()
local txt = string.format("%s,%d,%d,%d,%s,%s,%s,%d,%d\n" local txt = string.format( "%s,%d,%d,%d,%s,%s,%s,%d,%d\n", "STATIC", location.x, location.y, location.z, cgoname, cgotemp, cgotype, cgoneed, cgomass )
,"STATIC",location.x,location.y,location.z,cgoname,cgotemp,cgotype,cgoneed,cgomass)
data = data .. txt data = data .. txt
end end