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