This commit is contained in:
Frank
2019-12-05 17:06:58 +01:00
parent b9cb19e8e0
commit 88e7302838
+33 -33
View File
@@ -22,7 +22,7 @@
-- @field #string ClassName Name of the class. -- @field #string ClassName Name of the class.
-- @field #boolean Debug Debug mode. Messages to all about status. -- @field #boolean Debug Debug mode. Messages to all about status.
-- @field #string lid Class id string for output to DCS log file. -- @field #string lid Class id string for output to DCS log file.
-- @field #table Qspawn Queue of ratcraft to spawn. -- @field #table Qcraft Table of rat crafts.
-- @extends Core.Fsm#FSM -- @extends Core.Fsm#FSM
--- Be surprised! --- Be surprised!
@@ -40,8 +40,7 @@ RAT2 = {
ClassName = "RAT2", ClassName = "RAT2",
Debug = false, Debug = false,
lid = nil, lid = nil,
Qflights = {}, Qcraft = {},
Qspawn = {},
} }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -74,7 +73,7 @@ end
function RAT2:AddAircraft(ratcraft) function RAT2:AddAircraft(ratcraft)
-- Add ratcraft to spawn queue. -- Add ratcraft to spawn queue.
table.insert(self.Qspawn, ratcraft) table.insert(self.Qcraft, ratcraft)
return self return self
end end
@@ -93,7 +92,7 @@ function RAT2:onafterStatus(From, Event, To)
-- Check queue of aircraft to spawn. -- Check queue of aircraft to spawn.
self:_CheckQueueSpawn() self:_CheckQueueSpawn()
self:__Status(-30) self:__Status(-10)
end end
@@ -101,25 +100,24 @@ end
-- @param #RAT2 self -- @param #RAT2 self
function RAT2:_CheckQueueSpawn() function RAT2:_CheckQueueSpawn()
for i,_ratcraft in pairs(self.Qspawn) do for i,_ratcraft in pairs(self.Qcraft) do
local ratcraft=_ratcraft --Functional.RatCraft#RATCRAFT local ratcraft=_ratcraft --Functional.RatCraft#RATCRAFT
--ratcraft.actype -- Check if new groups should be spawned.
if ratcraft.nspawned<ratcraft.Nspawn then
local departure, parking=ratcraft:GetDeparture() local departure, parking=ratcraft:GetDeparture()
local destination=ratcraft:GetDestination(departure) local destination=ratcraft:GetDestination(departure)
--- Check if
-- Time has passed.
-- Already enough aircraft are alive
-- Try to spawn a ratcraft group. -- Try to spawn a ratcraft group.
local spawned=self:_TrySpawnRatcraft(ratcraft) local group=self:_SpawnRatcraft(ratcraft)
-- Remove queue item and break loop.
if group then
ratcraft.nspawned=ratcraft.nspawned+1
break
end
-- Remove queue item and break loop.
if spawned then
table.remove(self.Qspawn, i)
break
end end
end end
@@ -132,20 +130,23 @@ end
--- Spawn an aircraft asset (plane or helo) at the airbase associated with the warehouse. --- Spawn an aircraft asset (plane or helo) at the airbase associated with the warehouse.
-- @param #RAT2 self -- @param #RAT2 self
-- @param #RATAC ratcraft Ratcraft to spawn. -- @param #RATAC ratcraft Ratcraft to spawn.
-- @param #table parking Parking data for this asset. -- @param #RAT2.Departure departure Departure.
-- @param #boolean uncontrolled Spawn aircraft in uncontrolled state. -- @param #RAT2.Destination destination Destination.
-- @param #table parking Parking data for this group.
-- @return Wrapper.Group#GROUP The spawned group or nil if the group could not be spawned. -- @return Wrapper.Group#GROUP The spawned group or nil if the group could not be spawned.
function RAT2:_SpawnRatcraft(ratcraft, departure, destination, parking, uncontrolled) function RAT2:_SpawnRatcraft(ratcraft, departure, destination, parking)
-- Prepare the spawn template. -- Prepare the spawn template.
local template=self:_SpawnAssetPrepareTemplate(ratcraft, alias) local template=self:_SpawnAssetPrepareTemplate(ratcraft)
-- Get flight path if the group goes to another warehouse by itself. -- Get flight path if the group goes to another warehouse by itself.
template.route.points=self:_GetFlightplan(ratcraft, departure, destination) template.route.points=self:_GetFlightplan(ratcraft, departure, destination)
local airbase=self:_GetAirbase(departure)
-- Get airbase ID and category. -- Get airbase ID and category.
local AirbaseID = self.airbase:GetID() local AirbaseID = airbase:GetID()
local AirbaseCategory = self:GetAirbaseCategory() local AirbaseCategory = airbase:GetAirbaseCategory()
-- Check enough parking spots. -- Check enough parking spots.
if AirbaseCategory==Airbase.Category.HELIPAD or AirbaseCategory==Airbase.Category.SHIP then if AirbaseCategory==Airbase.Category.HELIPAD or AirbaseCategory==Airbase.Category.SHIP then
@@ -171,7 +172,7 @@ function RAT2:_SpawnRatcraft(ratcraft, departure, destination, parking, uncontro
if AirbaseCategory == Airbase.Category.HELIPAD or AirbaseCategory == Airbase.Category.SHIP then if AirbaseCategory == Airbase.Category.HELIPAD or AirbaseCategory == Airbase.Category.SHIP then
-- Helipads we take the position of the airbase location, since the exact location of the spawn point does not make sense. -- Helipads we take the position of the airbase location, since the exact location of the spawn point does not make sense.
local coord=self.airbase:GetCoordinate() local coord=airbase:GetCoordinate()
unit.x=coord.x unit.x=coord.x
unit.y=coord.z unit.y=coord.z
@@ -198,11 +199,11 @@ function RAT2:_SpawnRatcraft(ratcraft, departure, destination, parking, uncontro
end end
if asset.livery then if ratcraft.livery then
unit.livery_id = asset.livery unit.livery_id = ratcraft.livery
end end
if asset.skill then if ratcraft.skill then
unit.skill= asset.skill unit.skill= ratcraft.skill
end end
end end
@@ -212,7 +213,7 @@ function RAT2:_SpawnRatcraft(ratcraft, departure, destination, parking, uncontro
template.y = template.units[1].y template.y = template.units[1].y
-- Uncontrolled spawning. -- Uncontrolled spawning.
template.uncontrolled=uncontrolled template.uncontrolled=ratcraft.uncontrolled
-- Debug info. -- Debug info.
self:T2({airtemplate=template}) self:T2({airtemplate=template})
@@ -227,15 +228,14 @@ end
--- Prepare a spawn template for the asset. Deep copy of asset template, adjusting template and unit names, nillifying group and unit ids. --- Prepare a spawn template for the asset. Deep copy of asset template, adjusting template and unit names, nillifying group and unit ids.
-- @param #RAT2 self -- @param #RAT2 self
-- @param #RATAC ratcraft Aircraft that will be spawned. -- @param #RATAC ratcraft Aircraft that will be spawned.
-- @param #string alias Alias name of the group.
-- @return #table Prepared new spawn template. -- @return #table Prepared new spawn template.
function RAT2:_SpawnAssetPrepareTemplate(ratcraft, alias) function RAT2:_SpawnAssetPrepareTemplate(ratcraft)
-- Create an own copy of the template! -- Create an own copy of the template!
local template=UTILS.DeepCopy(ratcraft.template) local template=UTILS.DeepCopy(ratcraft.template)
-- Set unique name. -- Set unique name.
template.name=alias template.name=ratcraft.alias
-- Set current(!) coalition and country. -- Set current(!) coalition and country.
template.CoalitionID=ratcraft.coalition template.CoalitionID=ratcraft.coalition