This commit is contained in:
Frank
2019-08-30 23:48:41 +02:00
parent 3531b6a3e6
commit 1ecbf22f0a
4 changed files with 83 additions and 54 deletions
+3 -2
View File
@@ -549,8 +549,9 @@ end
-- This method is used by the SPAWN class.
-- @param #DATABASE self
-- @param #table SpawnTemplate Template of the group to spawn.
-- @param #string Groupname (Optional) Name of the group.
-- @return Wrapper.Group#GROUP Spawned group.
function DATABASE:Spawn( SpawnTemplate )
function DATABASE:Spawn( SpawnTemplate, Groupname )
self:F( SpawnTemplate.name )
self:T( { SpawnTemplate.SpawnCountryID, SpawnTemplate.SpawnCategoryID } )
@@ -565,7 +566,7 @@ function DATABASE:Spawn( SpawnTemplate )
SpawnTemplate.CountryID = nil
SpawnTemplate.CategoryID = nil
self:_RegisterGroupTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID )
self:_RegisterGroupTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID, Groupname )
self:T3( SpawnTemplate )
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
+11 -9
View File
@@ -1251,17 +1251,19 @@ do -- COORDINATE
-- Loop over all airbases.
for _,_airbase in pairs(airbases) do
local airbase=_airbase --Wrapper.Airbase#AIRBASE
local category=airbase:GetDesc().category
if Category and Category==category or Category==nil then
local dist=self:Get2DDistance(airbase:GetCoordinate())
if closest==nil then
distmin=dist
closest=airbase
else
if dist<distmin then
if airbase then
local category=airbase:GetCategory()
if Category and Category==category or Category==nil then
local dist=self:Get2DDistance(airbase:GetCoordinate())
if closest==nil then
distmin=dist
closest=airbase
end
else
if dist<distmin then
distmin=dist
closest=airbase
end
end
end
end
end
@@ -3701,7 +3701,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
if asset~=nil then
self:_DebugMessage(string.format("Warehouse %s: Adding KNOWN asset uid=%d with attribute=%s to stock.", self.alias, asset.uid, asset.attribute), 5)
-- Set warehouse ID
-- Asset now belongs to this warehouse. Set warehouse ID.
asset.wid=self.wid
-- No request associated with this asset.
@@ -3723,7 +3723,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
table.insert(self.stock, asset)
-- Trigger New asset event.
self:NewAsset(asset, assignment or "")
self:__NewAsset(0.1, asset, assignment or "")
else
self:_ErrorMessage(string.format("ERROR: Known asset could not be found in global warehouse db!"), 0)
end
@@ -3741,13 +3741,18 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
-- Add created assets to stock of this warehouse.
for _,asset in pairs(assets) do
-- Asset belongs to this warehouse. Set warehouse ID.
asset.wid=self.wid
-- No request associated with this asset.
asset.rid=nil
-- Add asset to stock.
table.insert(self.stock, asset)
self:NewAsset(asset, assignment or "")
-- Trigger NewAsset event. Delay a bit for OnAfterNewAsset functions to work properly.
self:__NewAsset(0.1, asset, assignment or "")
end
end
@@ -3906,21 +3911,22 @@ end
function WAREHOUSE:_AssetItemInfo(asset)
-- Info about asset:
local text=string.format("\nNew asset with id=%d for warehouse %s:\n", asset.uid, self.alias)
text=text..string.format("Template name = %s\n", asset.templatename)
text=text..string.format("Unit type = %s\n", asset.unittype)
text=text..string.format("Attribute = %s\n", asset.attribute)
text=text..string.format("Category = %d\n", asset.category)
text=text..string.format("Units # = %d\n", asset.nunits)
text=text..string.format("Speed max = %5.2f km/h\n", asset.speedmax)
text=text..string.format("Range max = %5.2f km\n", asset.range/1000)
text=text..string.format("Size max = %5.2f m\n", asset.size)
text=text..string.format("Weight total = %5.2f kg\n", asset.weight)
text=text..string.format("Cargo bay tot = %5.2f kg\n", asset.cargobaytot)
text=text..string.format("Cargo bay max = %5.2f kg\n", asset.cargobaymax)
text=text..string.format("Load radius = %s m\n", tostring(asset.loadradius))
text=text..string.format("Skill = %s\n", tostring(asset.skill))
text=text..string.format("Livery = %s", tostring(asset.livery))
self:T(self.wid..text)
text=text..string.format("Spawngroup name= %s\n", asset.spawngroupname)
text=text..string.format("Template name = %s\n", asset.templatename)
text=text..string.format("Unit type = %s\n", asset.unittype)
text=text..string.format("Attribute = %s\n", asset.attribute)
text=text..string.format("Category = %d\n", asset.category)
text=text..string.format("Units # = %d\n", asset.nunits)
text=text..string.format("Speed max = %5.2f km/h\n", asset.speedmax)
text=text..string.format("Range max = %5.2f km\n", asset.range/1000)
text=text..string.format("Size max = %5.2f m\n", asset.size)
text=text..string.format("Weight total = %5.2f kg\n", asset.weight)
text=text..string.format("Cargo bay tot = %5.2f kg\n", asset.cargobaytot)
text=text..string.format("Cargo bay max = %5.2f kg\n", asset.cargobaymax)
text=text..string.format("Load radius = %s m\n", tostring(asset.loadradius))
text=text..string.format("Skill = %s\n", tostring(asset.skill))
text=text..string.format("Livery = %s", tostring(asset.livery))
self:I(self.wid..text)
self:T({DCSdesc=asset.DCSdesc})
self:T3({Template=asset.template})
end
@@ -5581,6 +5587,8 @@ function WAREHOUSE:_SpawnAssetPrepareTemplate(asset, alias)
-- Set unique name.
template.name=alias
env.info(string.format("FF template name %s", alias))
-- Set current(!) coalition and country.
template.CoalitionID=self:GetCoalition()
@@ -7597,8 +7605,10 @@ function WAREHOUSE:_GetIDsFromGroup(group)
local asset=self:GetAssetByID(aid)
-- Get warehouse and request id from asset table.
wid=asset.wid
rid=asset.rid
if asset then
wid=asset.wid
rid=asset.rid
end
-- Debug info
self:T3(self.wid..string.format("Group Name = %s", tostring(name)))
+38 -22
View File
@@ -211,22 +211,24 @@ function FLIGHTGROUP:New(groupname)
self:AddTransition("*", "QueueUpdate", "*") -- Update task queue.
self:AddTransition("*", "DetectedUnit", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedUnit", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedUnitNew", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedUnitKnown", "*") -- Add a newly detected unit to the detected units set.
self:AddTransition("*", "DetectedUnitLost", "*") -- Group lost a detected target.
self:AddTransition("*", "RTB", "Returning") -- Group is returning to base.
self:AddTransition("*", "Orbit", "Orbiting") -- Group is holding position.
self:AddTransition("*", "RTB", "Returning") -- Group is returning to base.
self:AddTransition("*", "Orbit", "Orbiting") -- Group is holding position.
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
self:AddTransition("*", "PassingWaypoint", "*") -- Group passed a waypoint.
self:AddTransition("*", "OutOfFuel", "*") -- Group is out of fuel
self:AddTransition("*", "OutOfAmmo", "*") -- Group is out of ammo
self:AddTransition("*", "OutOfGuns", "*") -- Group is out of ammo
self:AddTransition("*", "OutOfRockets", "*") -- Group is out of ammo
self:AddTransition("*", "OutOfBombs", "*") -- Group is out of ammo
self:AddTransition("*", "OutOfMissiles", "*") -- Group is out of ammo
self:AddTransition("*", "FuelLow", "*") -- Fuel state of group is low. Default ~25%.
self:AddTransition("*", "FuelCritical", "*") -- Fuel state of group is critical. Default ~10%.
self:AddTransition("*", "OutOfAmmo", "*") -- Group is completely out of ammo.
self:AddTransition("*", "OutOfGuns", "*") -- Group is out of gun shells.
self:AddTransition("*", "OutOfRockets", "*") -- Group is out of rockets.
self:AddTransition("*", "OutOfBombs", "*") -- Group is out of bombs.
self:AddTransition("*", "OutOfMissiles", "*") -- Group is out of missiles.
self:AddTransition("*", "TaskExecute", "*") -- Group will execute a task.
self:AddTransition("*", "TaskDone", "*") -- Group finished a task.
@@ -251,8 +253,6 @@ function FLIGHTGROUP:New(groupname)
self:AddTransition("*", "FlightArrived", "Arrived") -- The whole flight group has arrived.
self:AddTransition("*", "FlightDead", "Dead") -- The whole flight group is dead.
self:AddTransition("*", "FlightOutOfAmmo", "*") -- Flight is completely out of ammo.
------------------------
--- Pseudo Functions ---
------------------------
@@ -405,7 +405,8 @@ end
-- @param #boolean rtb If true, RTB on low fuel event.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:SetFuelLowThreshold(threshold, rtb)
self.fuellow=threshold or 15
self.fuellowthresh=threshold or 15
self.fuellow=false
self.fuellowrtb=rtb
return self
end
@@ -595,7 +596,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
self:I(self.sid..text)
if fuelmin<self.fuellowthresh and not self.fuellow then
self:FuelLow(self.flightgroup)
self:FuelLow()
end
-- Task queue.
@@ -787,16 +788,31 @@ function FLIGHTGROUP:OnEventEngineShutdown(EventData)
local element=self:GetElementByName(unitname)
if element then
local coord=unit:GetCoordinate()
local airbase=coord:GetClosestAirbase()
local _,_,dist,parking=coord:GetClosestParkingSpot(airbase)
if dist and dist<10 and unit:InAir()==false then
self:ElementArrived(element, airbase, parking)
self:I(self.sid..string.format("Element %s shut down engines ==> arrived", element.name))
if element.unit and element.unit:IsAlive() then
local coord=unit:GetCoordinate()
local airbase=coord:GetClosestAirbase()
local _,_,dist,parking=coord:GetClosestParkingSpot(airbase)
if dist and dist<10 and unit:InAir()==false then
self:ElementArrived(element, airbase, parking)
self:I(self.sid..string.format("Element %s shut down engines ==> arrived", element.name))
else
self:I(self.sid..string.format("Element %s shut down engines (in air) ==> dead", element.name))
self:ElementDead(element)
end
else
self:I(self.sid..string.format("Element %s shut down engines (in air) ==> dead", element.name))
self:ElementDead(element)
self:I(self.sid..string.format("Element %s shut down engines (bug is not alive) ==> dead", element.name))
self:ElementDead(element)
end
else
end
end