mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-20 07:43:07 +00:00
misc
This commit is contained in:
@@ -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 )
|
||||||
|
|||||||
@@ -1251,7 +1251,8 @@ 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
|
||||||
|
local category=airbase:GetCategory()
|
||||||
if Category and Category==category or Category==nil then
|
if Category and Category==category or Category==nil then
|
||||||
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||||
if closest==nil then
|
if closest==nil then
|
||||||
@@ -1265,6 +1266,7 @@ do -- COORDINATE
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return closest,distmin
|
return closest,distmin
|
||||||
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,6 +3911,7 @@ 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("Spawngroup name= %s\n", asset.spawngroupname)
|
||||||
text=text..string.format("Template name = %s\n", asset.templatename)
|
text=text..string.format("Template name = %s\n", asset.templatename)
|
||||||
text=text..string.format("Unit type = %s\n", asset.unittype)
|
text=text..string.format("Unit type = %s\n", asset.unittype)
|
||||||
text=text..string.format("Attribute = %s\n", asset.attribute)
|
text=text..string.format("Attribute = %s\n", asset.attribute)
|
||||||
@@ -3920,7 +3926,7 @@ function WAREHOUSE:_AssetItemInfo(asset)
|
|||||||
text=text..string.format("Load radius = %s m\n", tostring(asset.loadradius))
|
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("Skill = %s\n", tostring(asset.skill))
|
||||||
text=text..string.format("Livery = %s", tostring(asset.livery))
|
text=text..string.format("Livery = %s", tostring(asset.livery))
|
||||||
self:T(self.wid..text)
|
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.
|
||||||
|
if asset then
|
||||||
wid=asset.wid
|
wid=asset.wid
|
||||||
rid=asset.rid
|
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)))
|
||||||
|
|||||||
@@ -221,12 +221,14 @@ function FLIGHTGROUP:New(groupname)
|
|||||||
|
|
||||||
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,9 +788,15 @@ function FLIGHTGROUP:OnEventEngineShutdown(EventData)
|
|||||||
local element=self:GetElementByName(unitname)
|
local element=self:GetElementByName(unitname)
|
||||||
|
|
||||||
if element then
|
if element then
|
||||||
|
|
||||||
|
if element.unit and element.unit:IsAlive() then
|
||||||
|
|
||||||
local coord=unit:GetCoordinate()
|
local coord=unit:GetCoordinate()
|
||||||
|
|
||||||
local airbase=coord:GetClosestAirbase()
|
local airbase=coord:GetClosestAirbase()
|
||||||
|
|
||||||
local _,_,dist,parking=coord:GetClosestParkingSpot(airbase)
|
local _,_,dist,parking=coord:GetClosestParkingSpot(airbase)
|
||||||
|
|
||||||
if dist and dist<10 and unit:InAir()==false then
|
if dist and dist<10 and unit:InAir()==false then
|
||||||
self:ElementArrived(element, airbase, parking)
|
self:ElementArrived(element, airbase, parking)
|
||||||
self:I(self.sid..string.format("Element %s shut down engines ==> arrived", element.name))
|
self:I(self.sid..string.format("Element %s shut down engines ==> arrived", element.name))
|
||||||
@@ -797,6 +804,15 @@ function FLIGHTGROUP:OnEventEngineShutdown(EventData)
|
|||||||
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 (in air) ==> dead", element.name))
|
||||||
self:ElementDead(element)
|
self:ElementDead(element)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user