diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index fe60fed48..4f9d6216b 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -413,6 +413,8 @@ function CHIEF:New(Coalition, AgentSet, Alias) self:AddTransition("*", "DefconChange", "*") -- Change defence condition. self:AddTransition("*", "StrategyChange", "*") -- Change strategy condition. + self:AddTransition("*", "LegionLost", "*") -- Out of our legions was lost to the enemy. + ------------------------ --- Pseudo Functions --- ------------------------ @@ -647,6 +649,33 @@ function CHIEF:New(Coalition, AgentSet, Alias) -- @param #string To To state. -- @param Ops.OpsZone#OPSZONE OpsZone Zone that is being attacked. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#CHIEF] LegionLost + -- @param #CHIEF self + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#CHIEF] __LegionLost + -- @param #CHIEF self + -- @param #number delay Delay in seconds. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- On after "LegionLost" event. + -- @function [parent=#CHIEF] OnAfterLegionLost + -- @param #CHIEF self + -- @param #string From From state. + -- @param #string Event Event. + -- @param #string To To state. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + return self end @@ -1115,6 +1144,21 @@ function CHIEF:AddLegion(Legion) return self end +--- Remove a LEGION to the chief's commander. +-- @param #CHIEF self +-- @param Ops.Legion#LEGION Legion The legion to add. +-- @return #CHIEF self +function CHIEF:RemoveLegion(Legion) + + -- Set chief of the legion. + Legion.chief=nil + + -- Add legion to the commander. + self.commander:RemoveLegion(Legion) + + return self +end + --- Add mission to mission queue of the COMMANDER. -- @param #CHIEF self diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index 022fc2678..2126a90de 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -209,6 +209,8 @@ function COMMANDER:New(Coalition, Alias) self:AddTransition("*", "TransportCancel", "*") -- COMMANDER cancels a Transport. self:AddTransition("*", "OpsOnMission", "*") -- An OPSGROUP was send on a Mission (AUFTRAG). + + self:AddTransition("*", "LegionLost", "*") -- Out of our legions was lost to the enemy. ------------------------ --- Pseudo Functions --- @@ -351,6 +353,32 @@ function COMMANDER:New(Coalition, Alias) -- @param Ops.OpsGroup#OPSGROUP OpsGroup The OPS group on mission. -- @param Ops.Auftrag#AUFTRAG Mission The mission. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#COMMANDER] LegionLost + -- @param #COMMANDER self + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- Triggers the FSM event "LegionLost". + -- @function [parent=#COMMANDER] __LegionLost + -- @param #COMMANDER self + -- @param #number delay Delay in seconds. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + + --- On after "LegionLost" event. + -- @function [parent=#COMMANDER] OnAfterLegionLost + -- @param #COMMANDER self + -- @param #string From From state. + -- @param #string Event Event. + -- @param #string To To state. + -- @param Ops.Legion#LEGION Legion The legion that was lost. + -- @param DCS#coalition.side Coalition which captured the warehouse. + -- @param DCS#country.id Country which has captured the warehouse. + return self end @@ -442,6 +470,23 @@ function COMMANDER:AddLegion(Legion) return self end +--- Remove a LEGION to the commander. +-- @param #COMMANDER self +-- @param Ops.Legion#LEGION Legion The legion to be removed. +-- @return #COMMANDER self +function COMMANDER:RemoveLegion(Legion) + + for i,_legion in pairs(self.legions) do + local legion=_legion --Ops.Legion#LEGION + if legion.alias==Legion.alias then + table.remove(self.legions, i) + Legion.commander=nil + end + end + + return self +end + --- Add mission to mission queue. -- @param #COMMANDER self -- @param Ops.Auftrag#AUFTRAG Mission Mission to be added. diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 80fdf1e9e..76e0f641f 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -553,6 +553,13 @@ function LEGION:IsCohort(CohortName) return false end +--- Get name of legion. This is the alias of the warehouse. +-- @param #LEGION self +-- @return #string Name of legion. +function LEGION:GetName() + return self.alias +end + --- Get cohort of an asset. -- @param #LEGION self -- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset. @@ -1631,6 +1638,34 @@ function LEGION:onafterRequestSpawned(From, Event, To, Request, CargoGroupSet, T end +--- On after "Captured" event. +-- @param #LEGION self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param DCS#coalition.side Coalition which captured the warehouse. +-- @param DCS#country.id Country which has captured the warehouse. +function LEGION:onafterCaptured(From, Event, To, Coalition, Country) + + -- Call parent warehouse function. + self:GetParent(self, LEGION).onafterCaptured(self, From, Event, To, Coalition, Country) + + + if self.chief then + -- Trigger event for chief and commander. + self.chief.commander:LegionLost(self, Coalition, Country) + self.chief:LegionLost(self, Coalition, Country) + -- Remove legion from chief and commander. + self.chief:RemoveLegion(self) + elseif self.commander then + -- Trigger event. + self.commander:LegionLost(self, Coalition,Country) + -- Remove legion from commander. + self.commander:RemoveLegion(self) + end + +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Mission Functions -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------