mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-16 22:22:25 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8f5214e0b | |||
| b6ea6606fc | |||
| e4c7e809cb | |||
| aab16dd966 | |||
| 8b356f0913 | |||
| 5005203206 | |||
| a3455855b8 | |||
| d1e4dd3fe9 | |||
| c3086b0265 | |||
| 599a2ba6fb |
@@ -92,6 +92,8 @@ DATABASE = {
|
||||
ZONES_GOAL = {},
|
||||
WAREHOUSES = {},
|
||||
FLIGHTGROUPS = {},
|
||||
COHORTS={},
|
||||
LEGIONS={},
|
||||
FLIGHTCONTROLS = {},
|
||||
OPSZONES = {},
|
||||
PATHLINES = {},
|
||||
@@ -2087,6 +2089,40 @@ function DATABASE:FindOpsGroupFromUnit(unitname)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
|
||||
--- Add an OPS COHORT (SQUADRON, PLATOON, FLOTILLA) to the data base.
|
||||
-- @param #DATABASE self
|
||||
-- @param Ops.Cohort#COHORT cohort The cohort added to the DB.
|
||||
function DATABASE:AddCohort(cohort)
|
||||
self.COHORTS[cohort.name]=cohort
|
||||
end
|
||||
|
||||
--- Find an OPS COHORT (SQUADRON, PLATOON, FLOTILLA) in the data base.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string cohortname Name of the cohort.
|
||||
-- @return Ops.Cohort#COHORT Cohort object.
|
||||
function DATABASE:FindCohort(cohortname)
|
||||
return self.COHORTS[cohortname]
|
||||
end
|
||||
|
||||
--- Add an OPS LEGION (AIRWING, BRIGADE, FLEET) to the data base.
|
||||
-- @param #DATABASE self
|
||||
-- @param Ops.Legion#LEGION legion The legion added to the DB.
|
||||
function DATABASE:AddLegion(legion)
|
||||
self.LEGIONS[legion.alias]=legion
|
||||
end
|
||||
|
||||
--- Find an OPS LEGION (AIRWING, BRIGADE, FLEET) in the data base.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string legionname Name of the legion.
|
||||
-- @return Ops.Legion#LEGION Legion object.
|
||||
function DATABASE:FindLegion(legionname)
|
||||
return self.LEGIONS[legionname]
|
||||
end
|
||||
|
||||
--
|
||||
|
||||
--- Add a flight control to the data base.
|
||||
-- @param #DATABASE self
|
||||
-- @param OPS.FlightControl#FLIGHTCONTROL flightcontrol
|
||||
|
||||
@@ -1453,7 +1453,11 @@ function EVENT:onEvent( Event )
|
||||
-- Weapon.
|
||||
if Event.weapon and type(Event.weapon) == "table" and Event.weapon.isExist and Event.weapon:isExist() then
|
||||
Event.Weapon = Event.weapon
|
||||
Event.WeaponName = Event.weapon:isExist() and Event.weapon.getTypeName and Event.weapon:getTypeName() or "Unknown Weapon"
|
||||
if Event.weapon_name == "ZELL Booster" then
|
||||
Event.WeaponName = "ZELL Booster"
|
||||
else
|
||||
Event.WeaponName = Event.weapon:isExist() and Event.weapon.getTypeName and Event.weapon:getTypeName() or "Unknown Weapon"
|
||||
end
|
||||
if Event.weapon_name == "ZELL Booster" then Event.WeaponName = "ZELL Booster" end
|
||||
Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit!
|
||||
Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon.getPlayerName and Event.Weapon:getPlayerName()
|
||||
|
||||
@@ -246,11 +246,11 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
||||
-- self:T3( { Repeat = CallID, CurrentTime, ScheduleTime, ScheduleArguments } )
|
||||
return ScheduleTime -- returns the next time the function needs to be called.
|
||||
else
|
||||
self:Stop( Scheduler, CallID )
|
||||
self:_Reclaim( Scheduler, CallID )
|
||||
end
|
||||
|
||||
else
|
||||
self:Stop( Scheduler, CallID )
|
||||
self:_Reclaim( Scheduler, CallID )
|
||||
end
|
||||
else
|
||||
self:I( "<<<>" .. Name .. ":" .. Line .. " (" .. Source .. ")" )
|
||||
@@ -375,3 +375,13 @@ function SCHEDULEDISPATCHER:NoTrace( Scheduler )
|
||||
Scheduler.ShowTrace = false
|
||||
end
|
||||
|
||||
--- Helper for memory cleanup for self stopping schedulers
|
||||
-- @param #SCHEDULEDISPATCHER self
|
||||
-- @param Core.Scheduler#SCHEDULER Scheduler Scheduler object.
|
||||
-- @param #string CallID (Optional) Scheduler Call ID.
|
||||
function SCHEDULEDISPATCHER:_Reclaim( Scheduler, CallID )
|
||||
self:Stop( Scheduler, CallID ) -- remove DCS timer, nil ScheduleID
|
||||
if self.Schedule[Scheduler] then self.Schedule[Scheduler][CallID] = nil end
|
||||
self.ObjectSchedulers[CallID] = nil
|
||||
self.PersistentSchedulers[CallID] = nil
|
||||
end
|
||||
|
||||
@@ -290,6 +290,9 @@ function AIRWING:New(warehousename, airwingname)
|
||||
-- @param Ops.FlightGroup#FLIGHTGROUP FlightGroup The FLIGHTGROUP on mission.
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
|
||||
-- Add legion to DB
|
||||
_DATABASE:AddLegion(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -541,6 +544,47 @@ function AIRWING:AddPayloadCapability(Payload, MissionTypes, Performance)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Filter available payloads for a given aircraft type and mission type.
|
||||
-- @param #AIRWING self
|
||||
-- @param #string UnitType The type of the unit.
|
||||
-- @param #string MissionType The mission type.
|
||||
-- @param #table Payloads Specific payloads only to be considered.
|
||||
-- @return #AIRWING.Payload Payload table or *nil*.
|
||||
function AIRWING:_FilterPlayloads(UnitType, MissionType, Payloads)
|
||||
|
||||
local function _checkPayloads(payload)
|
||||
if Payloads then
|
||||
for _,Payload in pairs(Payloads) do
|
||||
if Payload.uid==payload.uid then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Payload was not specified.
|
||||
return nil
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Pre-selection: filter out only those payloads that are valid for the airframe and mission type and are available.
|
||||
local payloads={}
|
||||
|
||||
for _,_payload in pairs(self.payloads) do
|
||||
local payload=_payload --#AIRWING.Payload
|
||||
|
||||
local specialpayload=_checkPayloads(payload)
|
||||
local compatible=AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities)
|
||||
|
||||
local goforit = specialpayload or (specialpayload==nil and compatible)
|
||||
|
||||
if payload.aircrafttype==UnitType and payload.navail>0 and goforit then
|
||||
table.insert(payloads, payload)
|
||||
end
|
||||
end
|
||||
|
||||
return payloads
|
||||
end
|
||||
|
||||
--- Fetch a payload from the airwing resources for a given unit and mission type.
|
||||
-- The payload with the highest priority is preferred.
|
||||
-- @param #AIRWING self
|
||||
@@ -589,34 +633,7 @@ function AIRWING:FetchPayloadFromStock(UnitType, MissionType, Payloads)
|
||||
end
|
||||
end
|
||||
|
||||
local function _checkPayloads(payload)
|
||||
if Payloads then
|
||||
for _,Payload in pairs(Payloads) do
|
||||
if Payload.uid==payload.uid then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Payload was not specified.
|
||||
return nil
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Pre-selection: filter out only those payloads that are valid for the airframe and mission type and are available.
|
||||
local payloads={}
|
||||
for _,_payload in pairs(self.payloads) do
|
||||
local payload=_payload --#AIRWING.Payload
|
||||
|
||||
local specialpayload=_checkPayloads(payload)
|
||||
local compatible=AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities)
|
||||
|
||||
local goforit = specialpayload or (specialpayload==nil and compatible)
|
||||
|
||||
if payload.aircrafttype==UnitType and payload.navail>0 and goforit then
|
||||
table.insert(payloads, payload)
|
||||
end
|
||||
end
|
||||
local payloads=self:_FilterPlayloads(UnitType, MissionType, Payloads)
|
||||
|
||||
-- Debug.
|
||||
if self.verbose>=4 then
|
||||
|
||||
@@ -4201,13 +4201,16 @@ function AIRBOSS:_CheckRecoveryTimes()
|
||||
-- Time into the wind 1 day or if longer recovery time + the 5 min early.
|
||||
local t = math.max( nextwindow.STOP - nextwindow.START + self.dTturn, 60 * 60 * 24 )
|
||||
|
||||
-- Recovery wind on deck in knots.
|
||||
-- Recovery wind on deck in knots.
|
||||
-- NOTE: Do NOT clamp the desired wind-over-deck (WOD) to the carrier's max hull
|
||||
-- speed here. WOD = carrier speed + headwind, so a WOD target above the hull's
|
||||
-- top speed is achievable whenever there is wind. CarrierTurnIntoWind ->
|
||||
-- GetHeadingIntoWind already converts the WOD target into the required hull
|
||||
-- speed and caps THAT at the carrier's max speed (Vmax) internally. Clamping the
|
||||
-- WOD target itself capped achievable WOD at ~30 kts (the supercarrier's max
|
||||
-- hull speed) even in strong wind, which made high-WOD recovery windows fall
|
||||
-- short of their requested value.
|
||||
local v = UTILS.KnotsToMps( nextwindow.SPEED )
|
||||
|
||||
-- Check that we do not go above max possible speed.
|
||||
local vmax = self.carrier:GetSpeedMax() / 3.6 -- convert to m/s
|
||||
v = math.min( v, vmax )
|
||||
|
||||
-- Route carrier into the wind. Sets self.turnintowind=true
|
||||
self:CarrierTurnIntoWind( t, v, uturn )
|
||||
|
||||
|
||||
@@ -5120,7 +5120,6 @@ end
|
||||
-- FSM Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
--- On after "Planned" event.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param #string From From state.
|
||||
|
||||
@@ -150,6 +150,9 @@ function BRIGADE:New(WarehouseName, BrigadeName)
|
||||
-- @param Ops.ArmyGroup#ARMYGROUP ArmyGroup The ARMYGROUP on mission.
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
|
||||
-- Add legion to DB
|
||||
_DATABASE:AddLegion(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -167,6 +167,9 @@ function FLEET:New(WarehouseName, FleetName)
|
||||
-- @param Ops.NavyGroup#NAVYGROUP NavyGroup The NAVYGROUP on mission.
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
|
||||
-- Add legion to DB
|
||||
_DATABASE:AddLegion(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ function FLOTILLA:New(TemplateGroupName, Ngroups, FlotillaName)
|
||||
-- Get initial ammo.
|
||||
self.ammo=self:_CheckAmmo()
|
||||
|
||||
-- Add cohort to DB
|
||||
_DATABASE:AddCohort(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -306,7 +306,6 @@ function LEGION:New(WarehouseName, LegionName)
|
||||
-- @param Ops.Cohort#COHORT Cohort The cohort the asset belongs to.
|
||||
-- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset that returned.
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -71,6 +71,9 @@ function PLATOON:New(TemplateGroupName, Ngroups, PlatoonName)
|
||||
|
||||
-- Get ammo.
|
||||
self.ammo=self:_CheckAmmo()
|
||||
|
||||
-- Add cohort to DB
|
||||
_DATABASE:AddCohort(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -116,6 +116,9 @@ function SQUADRON:New(TemplateGroupName, Ngroups, SquadronName)
|
||||
|
||||
-- See COHORT class
|
||||
|
||||
-- Add cohort to DB
|
||||
_DATABASE:AddCohort(self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ _TARGETID=0
|
||||
|
||||
--- TARGET class version.
|
||||
-- @field #string version
|
||||
TARGET.version="0.7.1"
|
||||
TARGET.version="0.8.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -206,6 +206,9 @@ function TARGET:New(TargetObject)
|
||||
self:AddTransition("*", "Status", "*") -- Status update.
|
||||
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
||||
|
||||
self:AddTransition("*", "ElementDestroyed", "*") -- A target element was destroyed.
|
||||
self:AddTransition("*", "ElementDead", "*") -- A target element is dead (destroyed or despawned).
|
||||
|
||||
self:AddTransition("*", "ObjectDamaged", "*") -- A target object was damaged.
|
||||
self:AddTransition("*", "ObjectDestroyed", "*") -- A target object was destroyed.
|
||||
self:AddTransition("*", "ObjectDead", "*") -- A target object is dead (destroyed or despawned).
|
||||
@@ -245,6 +248,19 @@ function TARGET:New(TargetObject)
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "ElementDestroyed".
|
||||
-- @function [parent=#TARGET] ElementDestroyed
|
||||
-- @param #TARGET self
|
||||
-- @param #string ElementName Name of the element.
|
||||
-- @param #TARGET.Object Target Target object.
|
||||
|
||||
--- Triggers the FSM event "ElementDead".
|
||||
-- @function [parent=#TARGET] ElementDead
|
||||
-- @param #TARGET self
|
||||
-- @param #string ElementName Name of the element.
|
||||
-- @param #TARGET.Object Target Target object.
|
||||
|
||||
|
||||
--- Triggers the FSM event "ObjectDamaged".
|
||||
-- @function [parent=#TARGET] ObjectDamaged
|
||||
-- @param #TARGET self
|
||||
@@ -642,6 +658,19 @@ function TARGET:onafterStatus(From, Event, To)
|
||||
|
||||
-- FSM state.
|
||||
local fsmstate=self:GetState()
|
||||
|
||||
-- First we check any target has been destroyed and the dead/unitlost event was not fired
|
||||
for i,_target in pairs(self.targets) do
|
||||
local target=_target --#TARGET.Object
|
||||
local life=self:GetTargetLife(target)
|
||||
if life<1 and target.Status~=TARGET.ObjectStatus.DEAD then
|
||||
self:E(self.lid..string.format("FF life is zero but no object dead event fired ==> waiting for target object %s events!", tostring(target.Name)))
|
||||
-- We wait 60 seconds for the events to occur
|
||||
self:__Status(-60)
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Update damage.
|
||||
local damaged=false
|
||||
@@ -736,6 +765,61 @@ end
|
||||
-- FSM Events
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- On after "ElementDestroyed" event.
|
||||
-- @param #TARGET self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #string Name Name of the element.
|
||||
-- @param #TARGET.Object Target Target object.
|
||||
function TARGET:onafterElementDestroyed(From, Event, To, Name, Target)
|
||||
-- Debug message.
|
||||
self:T(self.lid..string.format("Element %s of target object %s destroyed", Name, Target.Name))
|
||||
|
||||
-- Increase destroyed counter.
|
||||
Target.Ndestroyed=Target.Ndestroyed+1
|
||||
|
||||
-- Increase dead counter.
|
||||
self.Ndestroyed=self.Ndestroyed+1
|
||||
|
||||
self:ElementDead(Name, Target)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- On after "ElementDead" event.
|
||||
-- @param #TARGET self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #string Name Name of the element.
|
||||
-- @param #TARGET.Object Target Target object.
|
||||
function TARGET:onafterElementDead(From, Event, To, Name, Target)
|
||||
-- Debug message.
|
||||
self:T(self.lid..string.format("Element %s of target object %s dead", Name, Target.Name))
|
||||
|
||||
-- Increase dead counter.
|
||||
Target.Ndead=Target.Ndead+1
|
||||
|
||||
-- Increase dead counter.
|
||||
self.Ndead=self.Ndead+1
|
||||
|
||||
-- All dead ==> Trigger event.
|
||||
if Target.Ndestroyed==Target.N0 then
|
||||
|
||||
self:ObjectDestroyed(Target)
|
||||
|
||||
elseif Target.Ndead==Target.N0 then
|
||||
|
||||
self:ObjectDead(Target)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- On after "ObjectDamaged" event.
|
||||
-- @param #TARGET self
|
||||
-- @param #string From From state.
|
||||
@@ -761,11 +845,6 @@ function TARGET:onafterObjectDestroyed(From, Event, To, Target)
|
||||
-- Debug message.
|
||||
self:T(self.lid..string.format("Object %s destroyed", Target.Name))
|
||||
|
||||
-- Increase destroyed counter.
|
||||
self.Ndestroyed=self.Ndestroyed+1
|
||||
|
||||
Target.Ndestroyed=Target.Ndestroyed+1
|
||||
|
||||
Target.Life=0
|
||||
|
||||
-- Call object dead event.
|
||||
@@ -787,16 +866,10 @@ function TARGET:onafterObjectDead(From, Event, To, Target)
|
||||
|
||||
-- Set target status.
|
||||
Target.Status=TARGET.ObjectStatus.DEAD
|
||||
|
||||
-- Increase dead object counter
|
||||
Target.Ndead=Target.Ndead+1
|
||||
|
||||
|
||||
-- Set target object life to 0.
|
||||
Target.Life=0
|
||||
|
||||
-- Increase dead counter.
|
||||
self.Ndead=self.Ndead+1
|
||||
|
||||
|
||||
-- Check if anyone is alive?
|
||||
local dead=true
|
||||
for _,_target in pairs(self.targets) do
|
||||
@@ -889,54 +962,21 @@ function TARGET:OnEventUnitDeadOrLost(EventData)
|
||||
-- Add to the list of casualties.
|
||||
table.insert(self.casualties, Name)
|
||||
|
||||
-- Try to get target Group.
|
||||
local target=self:GetTargetByName(EventData.IniGroupName)
|
||||
|
||||
-- Try unit target.
|
||||
if not target then
|
||||
target=self:GetTargetByName(EventData.IniUnitName)
|
||||
end
|
||||
-- Get target from Group or Unit.
|
||||
local target=self:GetTargetByName(EventData.IniGroupName) or self:GetTargetByName(EventData.IniUnitName)
|
||||
|
||||
-- Check if we could find a target object.
|
||||
if target then
|
||||
|
||||
local Ndead=target.Ndead
|
||||
local Ndestroyed=target.Ndestroyed
|
||||
-- Increase dead/destroyed counter
|
||||
if EventData.id==EVENTS.RemoveUnit then
|
||||
Ndead=Ndead+1
|
||||
self:ElementDead(Name, target)
|
||||
else
|
||||
Ndestroyed=Ndestroyed+1
|
||||
Ndead=Ndead+1
|
||||
end
|
||||
|
||||
|
||||
-- Check if ALL objects are dead
|
||||
if Ndead==target.N0 then
|
||||
|
||||
if Ndestroyed>=target.N0 then
|
||||
|
||||
-- Debug message.
|
||||
self:T2(self.lid..string.format("EVENT ID=%d: target %s dead/lost ==> destroyed", EventData.id, tostring(target.Name)))
|
||||
|
||||
target.Life = 0
|
||||
|
||||
-- Trigger object destroyed event. This sets the Life to zero and increases Ndestroyed
|
||||
self:ObjectDestroyed(target)
|
||||
|
||||
else
|
||||
|
||||
-- Debug message.
|
||||
self:T2(self.lid..string.format("EVENT ID=%d: target %s removed ==> dead", EventData.id, tostring(target.Name)))
|
||||
|
||||
target.Life = 0
|
||||
|
||||
-- Trigger object dead event. This sets the Life to zero and increases Ndead counter
|
||||
self:ObjectDead(target)
|
||||
|
||||
end
|
||||
|
||||
self:ElementDestroyed(Name, target)
|
||||
end
|
||||
|
||||
else
|
||||
self:E(self.lid..string.format("ERROR: Could not get target from IniGroup or IniUnit name when event Dead or UnitLost occured! Stats are not correctly updated :("))
|
||||
end -- Event belongs to this TARGET
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user