mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#CTLD
* Update saving/loading to include structure
This commit is contained in:
parent
ad031a172d
commit
d5eb97863b
@ -1220,7 +1220,7 @@ CTLD.UnitTypes = {
|
|||||||
|
|
||||||
--- CTLD class version.
|
--- CTLD class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
CTLD.version="1.0.34"
|
CTLD.version="1.0.35"
|
||||||
|
|
||||||
--- Instantiate a new CTLD.
|
--- Instantiate a new CTLD.
|
||||||
-- @param #CTLD self
|
-- @param #CTLD self
|
||||||
@ -4731,6 +4731,7 @@ end
|
|||||||
-- @param Ops.CTLD#CTLD_CARGO Cargo The #CTLD_CARGO object to spawn.
|
-- @param Ops.CTLD#CTLD_CARGO Cargo The #CTLD_CARGO object to spawn.
|
||||||
-- @param #table Surfacetypes (Optional) Table of surface types. Can also be a single surface type. We will try max 1000 times to find the right type!
|
-- @param #table Surfacetypes (Optional) Table of surface types. Can also be a single surface type. We will try max 1000 times to find the right type!
|
||||||
-- @param #boolean PreciseLocation (Optional) Don't try to get a random position in the zone but use the dead center. Caution not to stack up stuff on another!
|
-- @param #boolean PreciseLocation (Optional) Don't try to get a random position in the zone but use the dead center. Caution not to stack up stuff on another!
|
||||||
|
-- @param #string Structure (Optional) String object describing the current structure of the injected group; mainly for load/save to keep current state setup.
|
||||||
-- @return #CTLD self
|
-- @return #CTLD self
|
||||||
-- @usage Use this function to pre-populate the field with Troops or Engineers at a random coordinate in a zone:
|
-- @usage Use this function to pre-populate the field with Troops or Engineers at a random coordinate in a zone:
|
||||||
-- -- create a matching #CTLD_CARGO type
|
-- -- create a matching #CTLD_CARGO type
|
||||||
@ -4739,7 +4740,7 @@ end
|
|||||||
-- local dropzone = ZONE:New("InjectZone") -- Core.Zone#ZONE
|
-- local dropzone = ZONE:New("InjectZone") -- Core.Zone#ZONE
|
||||||
-- -- and go:
|
-- -- and go:
|
||||||
-- my_ctld:InjectTroops(dropzone,InjectTroopsType,{land.SurfaceType.LAND})
|
-- my_ctld:InjectTroops(dropzone,InjectTroopsType,{land.SurfaceType.LAND})
|
||||||
function CTLD:InjectTroops(Zone,Cargo,Surfacetypes,PreciseLocation)
|
function CTLD:InjectTroops(Zone,Cargo,Surfacetypes,PreciseLocation,Structure)
|
||||||
self:T(self.lid.." InjectTroops")
|
self:T(self.lid.." InjectTroops")
|
||||||
local cargo = Cargo -- #CTLD_CARGO
|
local cargo = Cargo -- #CTLD_CARGO
|
||||||
|
|
||||||
@ -4757,6 +4758,49 @@ end
|
|||||||
return match
|
return match
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function Cruncher(group,typename,anzahl)
|
||||||
|
local units = group:GetUnits()
|
||||||
|
local reduced = 0
|
||||||
|
for _,_unit in pairs (units) do
|
||||||
|
local typo = _unit:GetTypeName()
|
||||||
|
if typename == typo then
|
||||||
|
_unit:Destroy(false)
|
||||||
|
reduced = reduced + 1
|
||||||
|
if reduced == anzahl then break end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function PostSpawn(args)
|
||||||
|
local group = args[1]
|
||||||
|
local structure = args[2]
|
||||||
|
if structure then
|
||||||
|
|
||||||
|
local loadedstructure = {}
|
||||||
|
local strcset = UTILS.Split(structure,";")
|
||||||
|
for _,_data in pairs(strcset) do
|
||||||
|
local datasplit = UTILS.Split(_data,"==")
|
||||||
|
loadedstructure[datasplit[1]] = tonumber(datasplit[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
local originalstructure = UTILS.GetCountPerTypeName(group)
|
||||||
|
|
||||||
|
for _name,_number in pairs(originalstructure) do
|
||||||
|
local loadednumber = 0
|
||||||
|
if loadedstructure[_name] then
|
||||||
|
loadednumber = loadedstructure[_name]
|
||||||
|
end
|
||||||
|
local reduce = false
|
||||||
|
if loadednumber < _number then reduce = true end
|
||||||
|
|
||||||
|
if reduce then
|
||||||
|
Cruncher(group,_name,_number-loadednumber)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not IsTroopsMatch(cargo) then
|
if not IsTroopsMatch(cargo) then
|
||||||
self.CargoCounter = self.CargoCounter + 1
|
self.CargoCounter = self.CargoCounter + 1
|
||||||
cargo.ID = self.CargoCounter
|
cargo.ID = self.CargoCounter
|
||||||
@ -4793,6 +4837,11 @@ end
|
|||||||
local grpname = self.DroppedTroops[self.TroopCounter]:GetName()
|
local grpname = self.DroppedTroops[self.TroopCounter]:GetName()
|
||||||
self.EngineersInField[self.Engineers] = CTLD_ENGINEERING:New(name, grpname)
|
self.EngineersInField[self.Engineers] = CTLD_ENGINEERING:New(name, grpname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Structure then
|
||||||
|
BASE:ScheduleOnce(0.5,PostSpawn,{self.DroppedTroops[self.TroopCounter],Structure})
|
||||||
|
end
|
||||||
|
|
||||||
if self.eventoninject then
|
if self.eventoninject then
|
||||||
self:__TroopsDeployed(1,nil,nil,self.DroppedTroops[self.TroopCounter],type)
|
self:__TroopsDeployed(1,nil,nil,self.DroppedTroops[self.TroopCounter],type)
|
||||||
end
|
end
|
||||||
@ -4806,6 +4855,7 @@ end
|
|||||||
-- @param Ops.CTLD#CTLD_CARGO Cargo The #CTLD_CARGO object to spawn.
|
-- @param Ops.CTLD#CTLD_CARGO Cargo The #CTLD_CARGO object to spawn.
|
||||||
-- @param #table Surfacetypes (Optional) Table of surface types. Can also be a single surface type. We will try max 1000 times to find the right type!
|
-- @param #table Surfacetypes (Optional) Table of surface types. Can also be a single surface type. We will try max 1000 times to find the right type!
|
||||||
-- @param #boolean PreciseLocation (Optional) Don't try to get a random position in the zone but use the dead center. Caution not to stack up stuff on another!
|
-- @param #boolean PreciseLocation (Optional) Don't try to get a random position in the zone but use the dead center. Caution not to stack up stuff on another!
|
||||||
|
-- @param #string Structure (Optional) String object describing the current structure of the injected group; mainly for load/save to keep current state setup.
|
||||||
-- @return #CTLD self
|
-- @return #CTLD self
|
||||||
-- @usage Use this function to pre-populate the field with Vehicles or FOB at a random coordinate in a zone:
|
-- @usage Use this function to pre-populate the field with Vehicles or FOB at a random coordinate in a zone:
|
||||||
-- -- create a matching #CTLD_CARGO type
|
-- -- create a matching #CTLD_CARGO type
|
||||||
@ -4814,7 +4864,7 @@ end
|
|||||||
-- local dropzone = ZONE:New("InjectZone") -- Core.Zone#ZONE
|
-- local dropzone = ZONE:New("InjectZone") -- Core.Zone#ZONE
|
||||||
-- -- and go:
|
-- -- and go:
|
||||||
-- my_ctld:InjectVehicles(dropzone,InjectVehicleType)
|
-- my_ctld:InjectVehicles(dropzone,InjectVehicleType)
|
||||||
function CTLD:InjectVehicles(Zone,Cargo,Surfacetypes,PreciseLocation)
|
function CTLD:InjectVehicles(Zone,Cargo,Surfacetypes,PreciseLocation,Structure)
|
||||||
self:T(self.lid.." InjectVehicles")
|
self:T(self.lid.." InjectVehicles")
|
||||||
local cargo = Cargo -- #CTLD_CARGO
|
local cargo = Cargo -- #CTLD_CARGO
|
||||||
|
|
||||||
@ -4832,6 +4882,49 @@ end
|
|||||||
return match
|
return match
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function Cruncher(group,typename,anzahl)
|
||||||
|
local units = group:GetUnits()
|
||||||
|
local reduced = 0
|
||||||
|
for _,_unit in pairs (units) do
|
||||||
|
local typo = _unit:GetTypeName()
|
||||||
|
if typename == typo then
|
||||||
|
_unit:Destroy(false)
|
||||||
|
reduced = reduced + 1
|
||||||
|
if reduced == anzahl then break end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function PostSpawn(args)
|
||||||
|
local group = args[1]
|
||||||
|
local structure = args[2]
|
||||||
|
if structure then
|
||||||
|
|
||||||
|
local loadedstructure = {}
|
||||||
|
local strcset = UTILS.Split(structure,";")
|
||||||
|
for _,_data in pairs(strcset) do
|
||||||
|
local datasplit = UTILS.Split(_data,"==")
|
||||||
|
loadedstructure[datasplit[1]] = tonumber(datasplit[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
local originalstructure = UTILS.GetCountPerTypeName(group)
|
||||||
|
|
||||||
|
for _name,_number in pairs(originalstructure) do
|
||||||
|
local loadednumber = 0
|
||||||
|
if loadedstructure[_name] then
|
||||||
|
loadednumber = loadedstructure[_name]
|
||||||
|
end
|
||||||
|
local reduce = false
|
||||||
|
if loadednumber < _number then reduce = true end
|
||||||
|
|
||||||
|
if reduce then
|
||||||
|
Cruncher(group,_name,_number-loadednumber)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not IsVehicMatch(cargo) then
|
if not IsVehicMatch(cargo) then
|
||||||
self.CargoCounter = self.CargoCounter + 1
|
self.CargoCounter = self.CargoCounter + 1
|
||||||
cargo.ID = self.CargoCounter
|
cargo.ID = self.CargoCounter
|
||||||
@ -4866,6 +4959,11 @@ end
|
|||||||
:InitDelayOff()
|
:InitDelayOff()
|
||||||
:SpawnFromVec2(randomcoord)
|
:SpawnFromVec2(randomcoord)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Structure then
|
||||||
|
BASE:ScheduleOnce(0.5,PostSpawn,{self.DroppedTroops[self.TroopCounter],Structure})
|
||||||
|
end
|
||||||
|
|
||||||
if self.eventoninject then
|
if self.eventoninject then
|
||||||
self:__CratesBuild(1,nil,nil,self.DroppedTroops[self.TroopCounter])
|
self:__CratesBuild(1,nil,nil,self.DroppedTroops[self.TroopCounter])
|
||||||
end
|
end
|
||||||
@ -5250,6 +5348,7 @@ end
|
|||||||
-- name matching a template in the table
|
-- name matching a template in the table
|
||||||
local match = false
|
local match = false
|
||||||
local cargo = nil
|
local cargo = nil
|
||||||
|
name = string.gsub(name,"-"," ")
|
||||||
for _ind,_cargo in pairs (table) do
|
for _ind,_cargo in pairs (table) do
|
||||||
local thiscargo = _cargo -- #CTLD_CARGO
|
local thiscargo = _cargo -- #CTLD_CARGO
|
||||||
local template = thiscargo:GetTemplates()
|
local template = thiscargo:GetTemplates()
|
||||||
@ -5257,6 +5356,7 @@ end
|
|||||||
template = { template }
|
template = { template }
|
||||||
end
|
end
|
||||||
for _,_name in pairs (template) do
|
for _,_name in pairs (template) do
|
||||||
|
_name = string.gsub(_name,"-"," ")
|
||||||
if string.find(name,_name) and _cargo:GetType() ~= CTLD_CARGO.Enum.REPAIR then
|
if string.find(name,_name) and _cargo:GetType() ~= CTLD_CARGO.Enum.REPAIR then
|
||||||
match = true
|
match = true
|
||||||
cargo = thiscargo
|
cargo = thiscargo
|
||||||
@ -5269,18 +5369,21 @@ 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,Structure\n"
|
||||||
local n = 0
|
local n = 0
|
||||||
for _,_grp in pairs(grouptable) do
|
for _,_grp in pairs(grouptable) do
|
||||||
local group = _grp -- Wrapper.Group#GROUP
|
local group = _grp -- Wrapper.Group#GROUP
|
||||||
if group and group:IsAlive() then
|
if group and group:IsAlive() then
|
||||||
-- get template name
|
-- get template name
|
||||||
local name = group:GetName()
|
local name = group:GetName()
|
||||||
local template = string.gsub(name,"-(.+)$","")
|
local template = name
|
||||||
|
|
||||||
if string.find(template,"#") then
|
if string.find(template,"#") then
|
||||||
template = string.gsub(name,"#(%d+)$","")
|
template = string.gsub(name,"#(%d+)$","")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local template = string.gsub(name,"-(%d+)$","")
|
||||||
|
|
||||||
local match, cargo = FindCargoType(template,cgotable)
|
local match, cargo = FindCargoType(template,cgotable)
|
||||||
if not match then
|
if not match then
|
||||||
match, cargo = FindCargoType(template,cgovehic)
|
match, cargo = FindCargoType(template,cgovehic)
|
||||||
@ -5293,6 +5396,11 @@ end
|
|||||||
local cgotype = cargo.CargoType
|
local cgotype = cargo.CargoType
|
||||||
local cgoneed = cargo.CratesNeeded
|
local cgoneed = cargo.CratesNeeded
|
||||||
local cgomass = cargo.PerCrateMass
|
local cgomass = cargo.PerCrateMass
|
||||||
|
local structure = UTILS.GetCountPerTypeName(group)
|
||||||
|
local strucdata = ""
|
||||||
|
for typen,anzahl in pairs (structure) do
|
||||||
|
strucdata = strucdata .. typen .. "=="..anzahl..";"
|
||||||
|
end
|
||||||
|
|
||||||
if type(cgotemp) == "table" then
|
if type(cgotemp) == "table" then
|
||||||
local templates = "{"
|
local templates = "{"
|
||||||
@ -5304,8 +5412,8 @@ 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,%s\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,strucdata)
|
||||||
data = data .. txt
|
data = data .. txt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -5460,7 +5568,7 @@ end
|
|||||||
|
|
||||||
for _id,_entry in pairs (loadeddata) do
|
for _id,_entry in pairs (loadeddata) do
|
||||||
local dataset = UTILS.Split(_entry,",")
|
local dataset = UTILS.Split(_entry,",")
|
||||||
-- 1=Group,2=x,3=y,4=z,5=CargoName,6=CargoTemplates,7=CargoType,8=CratesNeeded,9=CrateMass,10=SubCategory
|
-- 1=Group,2=x,3=y,4=z,5=CargoName,6=CargoTemplates,7=CargoType,8=CratesNeeded,9=CrateMass,10=Structure
|
||||||
local groupname = dataset[1]
|
local groupname = dataset[1]
|
||||||
local vec2 = {}
|
local vec2 = {}
|
||||||
vec2.x = tonumber(dataset[2])
|
vec2.x = tonumber(dataset[2])
|
||||||
@ -5474,14 +5582,19 @@ end
|
|||||||
cargotemplates = UTILS.Split(cargotemplates,";")
|
cargotemplates = UTILS.Split(cargotemplates,";")
|
||||||
local size = tonumber(dataset[8])
|
local size = tonumber(dataset[8])
|
||||||
local mass = tonumber(dataset[9])
|
local mass = tonumber(dataset[9])
|
||||||
|
local structure = nil
|
||||||
|
if dataset[10] then
|
||||||
|
structure = dataset[10]
|
||||||
|
structure = string.gsub(structure,",","")
|
||||||
|
end
|
||||||
-- inject at Vec2
|
-- inject at Vec2
|
||||||
local dropzone = ZONE_RADIUS:New("DropZone",vec2,20)
|
local dropzone = ZONE_RADIUS:New("DropZone",vec2,20)
|
||||||
if cargotype == CTLD_CARGO.Enum.VEHICLE or cargotype == CTLD_CARGO.Enum.FOB then
|
if cargotype == CTLD_CARGO.Enum.VEHICLE or cargotype == CTLD_CARGO.Enum.FOB then
|
||||||
local injectvehicle = CTLD_CARGO:New(nil,cargoname,cargotemplates,cargotype,true,true,size,nil,true,mass)
|
local injectvehicle = CTLD_CARGO:New(nil,cargoname,cargotemplates,cargotype,true,true,size,nil,true,mass)
|
||||||
self:InjectVehicles(dropzone,injectvehicle,self.surfacetypes,self.useprecisecoordloads)
|
self:InjectVehicles(dropzone,injectvehicle,self.surfacetypes,self.useprecisecoordloads,structure)
|
||||||
elseif cargotype == CTLD_CARGO.Enum.TROOPS or cargotype == CTLD_CARGO.Enum.ENGINEERS then
|
elseif cargotype == CTLD_CARGO.Enum.TROOPS or cargotype == CTLD_CARGO.Enum.ENGINEERS then
|
||||||
local injecttroops = CTLD_CARGO:New(nil,cargoname,cargotemplates,cargotype,true,true,size,nil,true,mass)
|
local injecttroops = CTLD_CARGO:New(nil,cargoname,cargotemplates,cargotype,true,true,size,nil,true,mass)
|
||||||
self:InjectTroops(dropzone,injecttroops,self.surfacetypes,self.useprecisecoordloads)
|
self:InjectTroops(dropzone,injecttroops,self.surfacetypes,self.useprecisecoordloads,structure)
|
||||||
end
|
end
|
||||||
elseif (type(groupname) == "string" and groupname == "STATIC") or cargotype == CTLD_CARGO.Enum.REPAIR then
|
elseif (type(groupname) == "string" and groupname == "STATIC") or cargotype == CTLD_CARGO.Enum.REPAIR then
|
||||||
local cargotemplates = dataset[6]
|
local cargotemplates = dataset[6]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user