CTLD - added factor for troops extraction, making Destroy()s silent for scoring, refined autohoverload messaging

This commit is contained in:
Applevangelist 2021-07-26 09:24:35 +02:00
parent 52d494f573
commit f0037151e6

View File

@ -659,6 +659,7 @@ function CTLD:New(Coalition, Prefixes, Alias)
-- setup -- setup
self.CrateDistance = 30 -- list/load crates in this radius self.CrateDistance = 30 -- list/load crates in this radius
self.ExtractFactor = 3.33 -- factor for troops extraction, i.e. CrateDistance * Extractfactor
self.prefixes = Prefixes or {"Cargoheli"} self.prefixes = Prefixes or {"Cargoheli"}
--self.I({prefixes = self.prefixes}) --self.I({prefixes = self.prefixes})
self.useprefix = true self.useprefix = true
@ -1116,8 +1117,10 @@ end
nearestDistance = distance nearestDistance = distance
end end
end end
if nearestGroup == nil or nearestDistance > self.CrateDistance then local extractdistance = self.CrateDistance * self.ExtractFactor
if nearestGroup == nil or nearestDistance > extractdistance then
self:_SendMessage("No units close enough to extract!", 10, false, Group) self:_SendMessage("No units close enough to extract!", 10, false, Group)
return self return self
end end
@ -1165,7 +1168,7 @@ end
-- clean up: -- clean up:
table.remove(self.DroppedTroops, nearestGroupIndex) table.remove(self.DroppedTroops, nearestGroupIndex)
nearestGroup:Destroy() nearestGroup:Destroy(false)
end end
return self return self
end end
@ -1390,8 +1393,13 @@ function CTLD:_LoadCratesNearby(Group, Unit)
-- get nearby crates -- get nearby crates
local finddist = self.CrateDistance or 30 local finddist = self.CrateDistance or 30
local nearcrates,number = self:_FindCratesNearby(Group,Unit,finddist) -- #table local nearcrates,number = self:_FindCratesNearby(Group,Unit,finddist) -- #table
if number == 0 or numberonboard == cratelimit then if number == 0 and self.hoverautoloading then
self:_SendMessage("Sorry no loadable crates nearby or fully loaded!", 10, false, Group) return -- exit
elseif number == 0 then
self:_SendMessage("Sorry no loadable crates nearby!", 10, false, Group)
return -- exit
elseif numberonboard == cratelimit then
self:_SendMessage("Sorry no fully loaded!", 10, false, Group)
return -- exit return -- exit
else else
-- go through crates and load -- go through crates and load
@ -1415,7 +1423,7 @@ function CTLD:_LoadCratesNearby(Group, Unit)
table.insert(loaded.Cargo, crate) table.insert(loaded.Cargo, crate)
table.insert(crateidsloaded,crate:GetID()) table.insert(crateidsloaded,crate:GetID())
-- destroy crate -- destroy crate
crate:GetPositionable():Destroy() crate:GetPositionable():Destroy(false)
crate.Positionable = nil crate.Positionable = nil
self:_SendMessage(string.format("Crate ID %d for %s loaded!",crate:GetID(),crate:GetName()), 10, false, Group) self:_SendMessage(string.format("Crate ID %d for %s loaded!",crate:GetID(),crate:GetName()), 10, false, Group)
self:_UpdateUnitCargoMass(Unit) self:_UpdateUnitCargoMass(Unit)
@ -1967,7 +1975,7 @@ function CTLD:_CleanUpCrates(Crates,Build,Number)
if name == nametype then -- matching crate type if name == nametype then -- matching crate type
table.insert(destIDs,thisID) table.insert(destIDs,thisID)
found = found + 1 found = found + 1
nowcrate:GetPositionable():Destroy() nowcrate:GetPositionable():Destroy(false)
nowcrate.Positionable = nil nowcrate.Positionable = nil
end end
if found == numberdest then break end -- got enough if found == numberdest then break end -- got enough
@ -2651,7 +2659,7 @@ 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)
self:AutoHoverLoad(Unit) if self:CanHoverLoad(Unit) then self:AutoHoverLoad(Unit) end
end end
end end
return self return self