mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#UTILS - make LoadSetOfGroups save(r) for groups spawned with SpawnScheduled
This commit is contained in:
parent
9a8727f499
commit
a51176967c
@ -2477,6 +2477,12 @@ end
|
|||||||
function UTILS.LoadSetOfGroups(Path,Filename,Spawn,Structured,Cinematic,Effect,Density)
|
function UTILS.LoadSetOfGroups(Path,Filename,Spawn,Structured,Cinematic,Effect,Density)
|
||||||
|
|
||||||
local fires = {}
|
local fires = {}
|
||||||
|
local usedtemplates = {}
|
||||||
|
local spawn = true
|
||||||
|
if Spawn == false then spawn = false end
|
||||||
|
local filename = Filename or "SetOfGroups"
|
||||||
|
local setdata = SET_GROUP:New()
|
||||||
|
local datatable = {}
|
||||||
|
|
||||||
local function Smokers(name,coord,effect,density)
|
local function Smokers(name,coord,effect,density)
|
||||||
local eff = math.random(8)
|
local eff = math.random(8)
|
||||||
@ -2503,12 +2509,72 @@ function UTILS.LoadSetOfGroups(Path,Filename,Spawn,Structured,Cinematic,Effect,D
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local spawn = true
|
local function PostSpawn(args)
|
||||||
if Spawn == false then spawn = false end
|
local spwndgrp = args[1]
|
||||||
|
local size = args[2]
|
||||||
|
local structure = args[3]
|
||||||
|
|
||||||
|
setdata:AddObject(spwndgrp)
|
||||||
|
local actualsize = spwndgrp:CountAliveUnits()
|
||||||
|
if actualsize > size then
|
||||||
|
if Structured and 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(spwndgrp)
|
||||||
|
|
||||||
|
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(spwndgrp,_name,_number-loadednumber)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local reduction = actualsize-size
|
||||||
|
-- reduce existing group
|
||||||
|
local units = spwndgrp:GetUnits()
|
||||||
|
local units2 = UTILS.ShuffleTable(units) -- randomize table
|
||||||
|
for i=1,reduction do
|
||||||
|
units2[i]:Destroy(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function MultiUse(Data)
|
||||||
|
local template = Data.template
|
||||||
|
if template and usedtemplates[template] and usedtemplates[template].used and usedtemplates[template].used > 1 then
|
||||||
|
-- multispawn
|
||||||
|
if not usedtemplates[template].done then
|
||||||
|
local spwnd = 0
|
||||||
|
local spawngrp = SPAWN:New(template)
|
||||||
|
spawngrp:InitLimit(0,usedtemplates[template].used)
|
||||||
|
for _,_entry in pairs(usedtemplates[template].data) do
|
||||||
|
spwnd = spwnd + 1
|
||||||
|
local sgrp=spawngrp:SpawnFromCoordinate(_entry.coordinate,spwnd)
|
||||||
|
BASE:ScheduleOnce(0.5,PostSpawn,{sgrp,_entry.size,_entry.structure})
|
||||||
|
end
|
||||||
|
usedtemplates[template].done = true
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--BASE:I("Spawn = "..tostring(spawn))
|
--BASE:I("Spawn = "..tostring(spawn))
|
||||||
local filename = Filename or "SetOfGroups"
|
|
||||||
local setdata = SET_GROUP:New()
|
|
||||||
local datatable = {}
|
|
||||||
if UTILS.CheckFileExists(Path,filename) then
|
if UTILS.CheckFileExists(Path,filename) then
|
||||||
local outcome,loadeddata = UTILS.LoadFromFile(Path,Filename)
|
local outcome,loadeddata = UTILS.LoadFromFile(Path,Filename)
|
||||||
-- remove header
|
-- remove header
|
||||||
@ -2525,55 +2591,27 @@ function UTILS.LoadSetOfGroups(Path,Filename,Spawn,Structured,Cinematic,Effect,D
|
|||||||
local structure = dataset[7]
|
local structure = dataset[7]
|
||||||
local coordinate = COORDINATE:NewFromVec3({x=posx, y=posy, z=posz})
|
local coordinate = COORDINATE:NewFromVec3({x=posx, y=posy, z=posz})
|
||||||
local group=nil
|
local group=nil
|
||||||
local data = { groupname=groupname, size=size, coordinate=coordinate, template=template }
|
if size > 0 then
|
||||||
table.insert(datatable,data)
|
local data = { groupname=groupname, size=size, coordinate=coordinate, template=template, structure=structure }
|
||||||
if spawn then
|
table.insert(datatable,data)
|
||||||
local group = SPAWN:New(template)
|
if usedtemplates[template] then
|
||||||
:InitDelayOff()
|
usedtemplates[template].used = usedtemplates[template].used + 1
|
||||||
:OnSpawnGroup(
|
table.insert(usedtemplates[template].data,data)
|
||||||
function(spwndgrp)
|
else
|
||||||
setdata:AddObject(spwndgrp)
|
usedtemplates[template] = {
|
||||||
local actualsize = spwndgrp:CountAliveUnits()
|
data = {},
|
||||||
if actualsize > size then
|
used = 1,
|
||||||
if Structured and structure then
|
done = false,
|
||||||
--BASE:I("Reducing group structure!")
|
}
|
||||||
local loadedstructure = {}
|
table.insert(usedtemplates[template].data,data)
|
||||||
local strcset = UTILS.Split(structure,";")
|
end
|
||||||
for _,_data in pairs(strcset) do
|
end
|
||||||
local datasplit = UTILS.Split(_data,"==")
|
end
|
||||||
loadedstructure[datasplit[1]] = tonumber(datasplit[2])
|
for _id,_entry in pairs (datatable) do
|
||||||
end
|
if spawn and not MultiUse(_entry) and _entry.size > 0 then
|
||||||
--BASE:I({loadedstructure})
|
local group = SPAWN:New(_entry.template)
|
||||||
local originalstructure = UTILS.GetCountPerTypeName(spwndgrp)
|
local sgrp=group:SpawnFromCoordinate(_entry.coordinate)
|
||||||
--BASE:I({originalstructure})
|
BASE:ScheduleOnce(0.5,PostSpawn,{sgrp,_entry.size,_entry.structure})
|
||||||
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
|
|
||||||
|
|
||||||
--BASE:I(string.format("Looking at: %s | Original number: %d | Loaded number: %d | Reduce: %s",_name,_number,loadednumber,tostring(reduce)))
|
|
||||||
|
|
||||||
if reduce then
|
|
||||||
Cruncher(spwndgrp,_name,_number-loadednumber)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local reduction = actualsize-size
|
|
||||||
-- reduce existing group
|
|
||||||
local units = spwndgrp:GetUnits()
|
|
||||||
local units2 = UTILS.ShuffleTable(units) -- randomize table
|
|
||||||
for i=1,reduction do
|
|
||||||
units2[i]:Destroy(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
:SpawnFromCoordinate(coordinate)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user