mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS
- Improved OPSTRANSPORT for LEGION assets.
This commit is contained in:
parent
c5af279730
commit
d7dae1366d
@ -1867,6 +1867,7 @@ function WAREHOUSE:New(warehouse, alias)
|
||||
else
|
||||
self.isunit=true
|
||||
if warehouse:IsShip() then
|
||||
env.info("FF warehouse is ship!")
|
||||
self.isShip=true
|
||||
end
|
||||
end
|
||||
@ -1925,7 +1926,6 @@ function WAREHOUSE:New(warehouse, alias)
|
||||
self:SetMarker(true)
|
||||
self:SetReportOff()
|
||||
self:SetRunwayRepairtime()
|
||||
--self:SetVerbosityLevel(0)
|
||||
|
||||
-- Add warehouse to database.
|
||||
_WAREHOUSEDB.Warehouses[self.uid]=self
|
||||
@ -5829,7 +5829,7 @@ function WAREHOUSE:_SpawnAssetGroundNaval(alias, asset, request, spawnzone, late
|
||||
-- Late activation.
|
||||
template.lateActivation=lateactivated
|
||||
|
||||
env.info("FF lateActivation="..tostring(template.lateActivation))
|
||||
--env.info("FF lateActivation="..tostring(template.lateActivation))
|
||||
|
||||
template.route.points[1].x = coord.x
|
||||
template.route.points[1].y = coord.z
|
||||
|
||||
@ -1968,9 +1968,10 @@ end
|
||||
-- @param #AUFTRAG self
|
||||
-- @param Core.Zone#ZONE DeployZone Zone where assets are deployed.
|
||||
-- @param Core.Zone#ZONE DisembarkZone Zone where assets are disembarked to.
|
||||
-- @param Core.Set#SET_OPSGROUP Carriers Set of carriers. Can also be a single group. Can also be added via the AddTransportCarriers functions.
|
||||
-- @param #number NcarriersMin Number of carriers *at least* required. Default 1.
|
||||
-- @param #number NcarriersMax Number of carriers *at most* used for transportation. Default is same as `NcarriersMin`.
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:SetTransportForAssets(DeployZone, DisembarkZone, Carriers)
|
||||
function AUFTRAG:SetTransportForAssets(DeployZone, DisembarkZone, NcarriersMin, NcarriersMax)
|
||||
|
||||
-- OPS transport from pickup to deploy zone.
|
||||
self.opstransport=OPSTRANSPORT:New(nil, nil, DeployZone)
|
||||
@ -1979,7 +1980,19 @@ function AUFTRAG:SetTransportForAssets(DeployZone, DisembarkZone, Carriers)
|
||||
self.opstransport:SetDisembarkZone(DisembarkZone)
|
||||
end
|
||||
|
||||
if Carriers then
|
||||
-- Set required carriers.
|
||||
self:SetRequiredCarriers(NcarriersMin, NcarriersMax)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add carriers for a transport of mission assets.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param Core.Set#SET_OPSGROUP Carriers Set of carriers. Can also be a single group.
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:AddTransportCarriers(Carriers)
|
||||
|
||||
if self.opstransport then
|
||||
if Carriers:IsInstanceOf("SET_OPSGROUP") then
|
||||
|
||||
for _,_carrier in pairs(Carriers.Set) do
|
||||
@ -1993,11 +2006,6 @@ function AUFTRAG:SetTransportForAssets(DeployZone, DisembarkZone, Carriers)
|
||||
|
||||
end
|
||||
|
||||
-- Set min/max number of carriers to be assigned.
|
||||
self.opstransport.nCarriersMin=self.nCarriersMin
|
||||
self.opstransport.nCarriersMax=self.nCarriersMax
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set number of required carrier groups if an OPSTRANSPORT assignment is required.
|
||||
@ -2347,9 +2355,11 @@ function AUFTRAG:AddOpsGroup(OpsGroup)
|
||||
if self.opstransport then
|
||||
for _,_tzc in pairs(self.opstransport.tzCombos) do
|
||||
local tzc=_tzc --Ops.OpsTransport#OPSTRANSPORT.TransportZoneCombo
|
||||
if tzc.uid~=self.opstransport.tzcDefault.uid then
|
||||
|
||||
if tzc.assetsCargo and tzc.assetsCargo[OpsGroup:GetName()] then
|
||||
self.opstransport:AddCargoGroups(OpsGroup, tzc)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -2544,15 +2554,6 @@ function AUFTRAG:IsReadyToGo()
|
||||
return false
|
||||
end
|
||||
|
||||
-- Ops transport at
|
||||
if self.opstransport then
|
||||
if #self.legions>0 then
|
||||
end
|
||||
if self.opstransport:IsPlanned() or self.opstransport:IsQueued() or self.opstransport:IsRequested() then
|
||||
--return false
|
||||
end
|
||||
end
|
||||
|
||||
-- All start conditions true?
|
||||
local startme=self:EvalConditionsAll(self.conditionStart)
|
||||
|
||||
|
||||
@ -52,6 +52,9 @@ BRIGADE.version="0.1.0"
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Spawn when hosting warehouse is a ship or oil rig or gas platform.
|
||||
-- TODO: Rearming zones.
|
||||
-- TODO: Retreat zones.
|
||||
-- DONE: Add weapon range.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -509,6 +509,23 @@ function CHIEF:AddStrateticZone(Zone)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add strategically important zone.
|
||||
-- @param #CHIEF self
|
||||
-- @param Ops.OpsZone#OPSZONE OpsZone OPS zone object.
|
||||
-- @return #CHIEF self
|
||||
function CHIEF:AddOpsZone(OpsZone)
|
||||
|
||||
-- Start ops zone.
|
||||
if OpsZone:IsStopped() then
|
||||
OpsZone:Start()
|
||||
end
|
||||
|
||||
-- Add to table.
|
||||
table.insert(self.zonequeue, OpsZone)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set border zone set.
|
||||
-- @param #CHIEF self
|
||||
@ -664,26 +681,6 @@ function CHIEF:onafterStatus(From, Event, To)
|
||||
|
||||
end
|
||||
|
||||
--[[
|
||||
local redalert=true
|
||||
if self.borderzoneset:Count()>0 then
|
||||
redalert=inred
|
||||
end
|
||||
|
||||
if redalert and threat and not contact.target then
|
||||
|
||||
-- Create a new TARGET of the contact group.
|
||||
local Target=TARGET:New(contact.group)
|
||||
|
||||
-- Set to contact.
|
||||
contact.target=Target
|
||||
|
||||
-- Add target to queue.
|
||||
self:AddTarget(Target)
|
||||
|
||||
end
|
||||
]]
|
||||
|
||||
end
|
||||
|
||||
---
|
||||
@ -706,6 +703,13 @@ function CHIEF:onafterStatus(From, Event, To)
|
||||
-- Check target queue and assign missions to new targets.
|
||||
self:CheckTargetQueue()
|
||||
|
||||
---
|
||||
-- Check Strategic Zone Queue
|
||||
---
|
||||
|
||||
-- Check target queue and assign missions to new targets.
|
||||
self:CheckOpsZoneQueue()
|
||||
|
||||
---
|
||||
-- Info General
|
||||
---
|
||||
@ -773,6 +777,23 @@ function CHIEF:onafterStatus(From, Event, To)
|
||||
self:I(self.lid..text)
|
||||
end
|
||||
|
||||
---
|
||||
-- Info Strategic Zones
|
||||
---
|
||||
|
||||
-- Loop over targets.
|
||||
if self.verbose>=4 and #self.zonequeue>0 then
|
||||
local text="Zone queue:"
|
||||
for i,_opszone in pairs(self.zonequeue) do
|
||||
local opszone=_opszone --Ops.OpsZone#OPSZONE
|
||||
|
||||
text=text..string.format("\n[%d] %s [%s]: owner=%d [%d]: Blue=%d, Red=%d, Neutral=%d", i, opszone.zone:GetName(), opszone:GetState(), opszone:GetOwner(), opszone:GetPreviousOwner(), opszone.Nblu, opszone.Nred, opszone.Nnut)
|
||||
|
||||
end
|
||||
self:I(self.lid..text)
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- Info Assets
|
||||
---
|
||||
@ -1111,6 +1132,63 @@ function CHIEF:CheckTargetQueue()
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Strategic Zone Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
--- Check strategic zone queue.
|
||||
-- @param #CHIEF self
|
||||
function CHIEF:CheckOpsZoneQueue()
|
||||
|
||||
-- Number of zones.
|
||||
local Nzones=#self.zonequeue
|
||||
|
||||
-- Treat special cases.
|
||||
if Nzones==0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Sort results table wrt ?.
|
||||
local function _sort(a, b)
|
||||
local taskA=a --Ops.Target#TARGET
|
||||
local taskB=b --Ops.Target#TARGET
|
||||
return (taskA.prio<taskB.prio)
|
||||
end
|
||||
--table.sort(self.zonequeue, _sort)
|
||||
|
||||
-- Get the lowest importance value (lower means more important).
|
||||
-- If a target with importance 1 exists, targets with importance 2 will not be assigned. Targets with no importance (nil) can still be selected.
|
||||
local vip=math.huge
|
||||
for _,_target in pairs(self.zonequeue) do
|
||||
local target=_target --Ops.Target#TARGET
|
||||
if target.importance and target.importance<vip then
|
||||
vip=target.importance
|
||||
end
|
||||
end
|
||||
|
||||
-- Loop over targets.
|
||||
for _,_opszone in pairs(self.zonequeue) do
|
||||
local opszone=_opszone --Ops.OpsZone#OPSZONE
|
||||
|
||||
-- Current owner of the zone.
|
||||
local ownercoalition=opszone:GetOwner()
|
||||
|
||||
local hasMission=opszone.missionPatrol and opszone.missionPatrol:IsNotOver() or false
|
||||
|
||||
if ownercoalition~=self.coalition and not hasMission then
|
||||
|
||||
env.info(string.format("Zone %s is owned by coalition %d", opszone.zone:GetName(), ownercoalition))
|
||||
|
||||
-- Recruit ground assets that
|
||||
local recruited, assets, legions=self:RecruitAssetsForZone(opszone, AUFTRAG.Type.PATROLZONE, 1, 3, {Group.Category.GROUND}, {GROUP.Attribute.GROUND_INFANTRY})
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Zone Check Functions
|
||||
@ -1367,10 +1445,12 @@ function CHIEF:_GetMissionTypeForGroupAttribute(Attribute)
|
||||
|
||||
end
|
||||
|
||||
--- Recruit assets for a given mission.
|
||||
--- Recruit assets for a given TARGET.
|
||||
-- @param #CHIEF self
|
||||
-- @param Ops.Target#TARGET Target The target.
|
||||
-- @param #string MissionType Mission Type.
|
||||
-- @param #number NassetsMin Min number of required assets.
|
||||
-- @param #number NassetsMax Max number of required assets.
|
||||
-- @return #boolean If `true` enough assets could be recruited.
|
||||
-- @return #table Assets that have been recruited from all legions.
|
||||
-- @return #table Legions that have recruited assets.
|
||||
@ -1380,10 +1460,18 @@ function CHIEF:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMa
|
||||
local Cohorts={}
|
||||
for _,_legion in pairs(self.commander.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
|
||||
-- Check that runway is operational.
|
||||
local Runway=legion:IsAirwing() and legion:IsRunwayOperational() or true
|
||||
|
||||
if legion:IsRunning() and Runway then
|
||||
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -1393,8 +1481,123 @@ function CHIEF:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMa
|
||||
-- Recruite assets.
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, MissionType, nil, NassetsMin, NassetsMax, TargetVec2)
|
||||
|
||||
return recruited, assets, legions
|
||||
|
||||
return recruited, assets, legions
|
||||
end
|
||||
|
||||
--- Recruit assets for a given OPS zone.
|
||||
-- @param #CHIEF self
|
||||
-- @param Ops.OpsZone#OPSZONE OpsZone The OPS zone
|
||||
-- @param #string MissionType Mission Type.
|
||||
-- @param #number NassetsMin Min number of required assets.
|
||||
-- @param #number NassetsMax Max number of required assets.
|
||||
-- @param #table Categories Group categories of the assets.
|
||||
-- @param #table Attributes Generalized group attributes.
|
||||
-- @return #boolean If `true` enough assets could be recruited.
|
||||
-- @return #table Assets that have been recruited from all legions.
|
||||
-- @return #table Legions that have recruited assets.
|
||||
function CHIEF:RecruitAssetsForZone(OpsZone, MissionType, NassetsMin, NassetsMax, Categories, Attributes)
|
||||
|
||||
-- Cohorts.
|
||||
local Cohorts={}
|
||||
for _,_legion in pairs(self.commander.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
|
||||
-- Check that runway is operational.
|
||||
local Runway=legion:IsAirwing() and legion:IsRunwayOperational() or true
|
||||
|
||||
if legion:IsRunning() and Runway then
|
||||
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Target position.
|
||||
local TargetVec2=OpsZone.zone:GetVec2()
|
||||
|
||||
-- Recruite assets.
|
||||
local recruitedInf, assetsInf, legionsInf=LEGION.RecruitCohortAssets(Cohorts, MissionType, nil, NassetsMin, NassetsMax, TargetVec2, nil, nil, nil, nil, Categories, Attributes)
|
||||
|
||||
if recruitedInf then
|
||||
|
||||
env.info(string.format("Recruited %d assets from for PATROL mission", #assetsInf))
|
||||
|
||||
-- Get max weight.
|
||||
local weightMax=nil
|
||||
for _,_asset in pairs(assetsInf) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
if weightMax==nil or weightMax<=asset.weight then
|
||||
weightMax=asset.weight
|
||||
end
|
||||
end
|
||||
|
||||
-- Recruite assets.
|
||||
local recruitedTrans, assetsTrans, legionsTrans=
|
||||
LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NassetsMin, NassetsMax, TargetVec2, nil, nil, nil, weightMax, {Group.Category.HELICOPTER, Group.Category.GROUND})
|
||||
|
||||
local transport=nil --Ops.OpsTransport#OPSTRANSPORT
|
||||
if recruitedTrans then
|
||||
env.info(string.format("Recruited %d assets for OPSTRANSPORT mission", #assetsTrans))
|
||||
|
||||
-- Create an OPSTRANSPORT assignment.
|
||||
transport=OPSTRANSPORT:New(nil, nil, OpsZone.zone)
|
||||
|
||||
-- Add cargo assets to transport.
|
||||
for _,_legion in pairs(legionsInf) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
local tpz=transport:AddTransportZoneCombo(legion.spawnzone, OpsZone.zone)
|
||||
for _,_asset in pairs(assetsInf) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
if asset.legion.alias==legion.alias then
|
||||
transport:AddAssetCargo(asset, tpz)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add carrier assets.
|
||||
for _,_asset in pairs(assetsTrans) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
transport:AddAsset(asset)
|
||||
end
|
||||
|
||||
|
||||
-- Assign TRANSPORT to legions. This also sends the request for the assets.
|
||||
for _,_legion in pairs(legionsTrans) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
self.commander:TransportAssign(legion, transport)
|
||||
end
|
||||
|
||||
else
|
||||
-- Uncrecruite
|
||||
LEGION.UnRecruitAssets(assetsTrans)
|
||||
end
|
||||
|
||||
-- Create Patrol zone mission.
|
||||
local mission=AUFTRAG:NewPATROLZONE(OpsZone.zone)
|
||||
|
||||
for _,asset in pairs(assetsInf) do
|
||||
mission:AddAsset(asset)
|
||||
end
|
||||
|
||||
mission.opstransport=transport
|
||||
|
||||
for _,_legion in pairs(legionsInf) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
self.commander:MissionAssign(legion, mission)
|
||||
end
|
||||
|
||||
OpsZone.missionPatrol=mission
|
||||
|
||||
else
|
||||
LEGION.UnRecruitAssets(assetsInf)
|
||||
end
|
||||
|
||||
return recruited, assets, legions
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
-- @field #string name Name of the cohort.
|
||||
-- @field #string templatename Name of the template group.
|
||||
-- @field #string aircrafttype Type of the units the cohort is using.
|
||||
-- @field #number category Group category of the assets: `Group.Category.AIRPLANE`, `Group.Category.HELICOPTER`, `Group.Category.GROUND`, `Group.Category.SHIP`, `Group.Category.TRAIN`.
|
||||
-- @field Wrapper.Group#GROUP templategroup Template group.
|
||||
-- @field #table assets Cohort assets.
|
||||
-- @field #table missiontypes Capabilities (mission types and performances) of the cohort.
|
||||
@ -124,6 +125,9 @@ function COHORT:New(TemplateGroupName, Ngroups, CohortName)
|
||||
-- Generalized attribute.
|
||||
self.attribute=self.templategroup:GetAttribute()
|
||||
|
||||
-- Group category.
|
||||
self.category=self.templategroup:GetCategory()
|
||||
|
||||
-- Aircraft type.
|
||||
self.aircrafttype=self.templategroup:GetTypeName()
|
||||
|
||||
|
||||
@ -118,13 +118,13 @@ function COMMANDER:New()
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "MissionAssign".
|
||||
--- Triggers the FSM event "MissionAssign". Mission is added to a LEGION mission queue and already requested. Needs assets to be added to the mission!
|
||||
-- @function [parent=#COMMANDER] MissionAssign
|
||||
-- @param #COMMANDER self
|
||||
-- @param Ops.Legion#LEGION Legion The Legion.
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
|
||||
--- Triggers the FSM event "MissionAssign" after a delay.
|
||||
--- Triggers the FSM event "MissionAssign" after a delay. Mission is added to a LEGION mission queue and already requested. Needs assets to be added to the mission!
|
||||
-- @function [parent=#COMMANDER] __MissionAssign
|
||||
-- @param #COMMANDER self
|
||||
-- @param #number delay Delay in seconds.
|
||||
@ -161,6 +161,12 @@ function COMMANDER:New()
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
|
||||
|
||||
--- Triggers the FSM event "TransportAssign".
|
||||
-- @function [parent=#COMMANDER] TransportAssign
|
||||
-- @param #COMMANDER self
|
||||
-- @param Ops.Legion#LEGION Legion The Legion.
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT Transport The transport.
|
||||
|
||||
--- Triggers the FSM event "TransportAssign" after a delay.
|
||||
-- @function [parent=#COMMANDER] __TransportAssign
|
||||
-- @param #COMMANDER self
|
||||
@ -227,7 +233,7 @@ end
|
||||
|
||||
--- Add an BRIGADE to the commander.
|
||||
-- @param #COMMANDER self
|
||||
-- @param Ops.Brigade#BRIGADE Briagde The brigade to add.
|
||||
-- @param Ops.Brigade#BRIGADE Brigade The brigade to add.
|
||||
-- @return #COMMANDER self
|
||||
function COMMANDER:AddBrigade(Brigade)
|
||||
|
||||
@ -511,7 +517,7 @@ end
|
||||
-- FSM Events
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- On after "MissionAssign" event. Mission is added to a LEGION mission queue.
|
||||
--- On after "MissionAssign" event. Mission is added to a LEGION mission queue and already requested. Needs assets to be added to the mission already.
|
||||
-- @param #COMMANDER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
@ -690,16 +696,89 @@ function COMMANDER:CheckMissionQueue()
|
||||
-- Add asset to mission.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
mission:AddAsset(asset)
|
||||
end
|
||||
|
||||
-- Recruit asset for escorting recruited mission assets.
|
||||
local EscortAvail=self:RecruitAssetsForEscort(mission, assets)
|
||||
|
||||
-- Transport available (or not required).
|
||||
local TransportAvail=true
|
||||
|
||||
-- Escort requested and available.
|
||||
if EscortAvail then
|
||||
|
||||
-- Check if mission assets need a transport.
|
||||
if mission.opstransport then
|
||||
|
||||
-- Weight of the heaviest cargo group. Necessary condition that this fits into on carrier unit!
|
||||
local weightGroup=0
|
||||
|
||||
-- Calculate the max weight of the cargo assets.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
local weight=asset.weight
|
||||
if weight>weightGroup then
|
||||
weightGroup=weight
|
||||
end
|
||||
end
|
||||
|
||||
env.info(string.format("FF mission requires transport for cargo weight %d", weightGroup))
|
||||
|
||||
-- Recruit transport assets.
|
||||
local TransportAvail, assetsTrans, legionsTrans=self:RecruitAssetsForTransport(mission.opstransport, weightGroup)
|
||||
|
||||
if TransportAvail then
|
||||
|
||||
env.info(string.format("FF Transport available with %d carrier assets", #assetsTrans))
|
||||
|
||||
-- Add cargo assets to transport.
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
|
||||
local pickupzone=legion.spawnzone
|
||||
if legion.airbase and legion:IsRunwayOperational() then
|
||||
pickupzone=ZONE_AIRBASE:New(legion.airbasename, 4000)
|
||||
end
|
||||
|
||||
-- Add TZC from legion spawn zone to deploy zone.
|
||||
local tpz=mission.opstransport:AddTransportZoneCombo(pickupzone, mission.opstransport:GetDeployZone())
|
||||
mission.opstransport:SetEmbarkZone(legion.spawnzone, tpz)
|
||||
|
||||
-- Add cargo assets to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
if asset.legion.alias==legion.alias then
|
||||
mission.opstransport:AddAssetCargo(asset, tpz)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add carrier assets.
|
||||
for _,_asset in pairs(assetsTrans) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
mission.opstransport:AddAsset(asset)
|
||||
end
|
||||
|
||||
|
||||
-- Assign TRANSPORT to legions. This also sends the request for the assets.
|
||||
for _,_legion in pairs(legionsTrans) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
self:TransportAssign(legion, mission.opstransport)
|
||||
end
|
||||
|
||||
else
|
||||
-- Uncrecruit transport assets.
|
||||
LEGION.UnRecruitAssets(assetsTrans)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Escort and transport must be available (or not required).
|
||||
if EscortAvail and TransportAvail then
|
||||
|
||||
-- Assign mission to legion(s).
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
@ -741,11 +820,14 @@ end
|
||||
-- @return #table Legions that have recruited assets.
|
||||
function COMMANDER:RecruitAssetsForMission(Mission)
|
||||
|
||||
-- Debug info.
|
||||
env.info(string.format("FF recruiting assets for mission %s [%s]", Mission:GetName(), Mission:GetType()))
|
||||
|
||||
-- Cohorts.
|
||||
local Cohorts=Mission.squadrons
|
||||
if not Cohorts then
|
||||
Cohorts={}
|
||||
for _,_legion in pairs(Mission.mylegions or self.legions) do
|
||||
for _,_legion in pairs(Mission.specialLegions or self.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
@ -781,7 +863,7 @@ function COMMANDER:RecruitAssetsForEscort(Mission, Assets)
|
||||
local Cohorts=Mission.squadrons
|
||||
if not Cohorts then
|
||||
Cohorts={}
|
||||
for _,_legion in pairs(Mission.mylegions or self.legions) do
|
||||
for _,_legion in pairs(Mission.specialLegions or self.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
@ -918,32 +1000,55 @@ function COMMANDER:CheckTransportQueue()
|
||||
-- 2. Assign mission to legions that have the best assets.
|
||||
---
|
||||
|
||||
-- Recruite assets from legions.
|
||||
local recruited, assets, legions=self:RecruitAssetsForTransport(transport)
|
||||
-- Get all undelivered cargo ops groups.
|
||||
local cargoOpsGroups=transport:GetCargoOpsGroups(false)
|
||||
|
||||
if recruited then
|
||||
-- Weight of the heaviest cargo group. Necessary condition that this fits into on carrier unit!
|
||||
local weightGroup=0
|
||||
|
||||
-- Add asset to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
transport:AddAsset(asset)
|
||||
-- Calculate the max weight so we know which cohorts can provide carriers.
|
||||
if #cargoOpsGroups>0 then
|
||||
for _,_opsgroup in pairs(cargoOpsGroups) do
|
||||
local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP
|
||||
local weight=opsgroup:GetWeightTotal()
|
||||
if weight>weightGroup then
|
||||
weightGroup=weight
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if weightGroup>0 then
|
||||
|
||||
-- Recruite assets from legions.
|
||||
local recruited, assets, legions=self:RecruitAssetsForTransport(transport, weightGroup)
|
||||
|
||||
if recruited then
|
||||
|
||||
-- Add asset to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
transport:AddAsset(asset)
|
||||
end
|
||||
|
||||
-- Assign transport to legion(s).
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
|
||||
-- Debug message.
|
||||
self:I(self.lid..string.format("Assigning transport UID=%d to legion %s", transport.uid, legion.alias))
|
||||
|
||||
-- Add mission to legion.
|
||||
self:TransportAssign(legion, transport)
|
||||
|
||||
end
|
||||
|
||||
-- Only ONE transport is assigned.
|
||||
return
|
||||
else
|
||||
-- Not recruited.
|
||||
LEGION.UnRecruitAssets(assets)
|
||||
end
|
||||
|
||||
-- Assign transport to legion(s).
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
|
||||
-- Debug message.
|
||||
self:I(self.lid..string.format("Assigning transport UID=%d to legion %s", transport.uid, legion.alias))
|
||||
|
||||
-- Add mission to legion.
|
||||
self:TransportAssign(legion, transport)
|
||||
|
||||
end
|
||||
|
||||
-- Only ONE transport is assigned.
|
||||
return
|
||||
end
|
||||
|
||||
else
|
||||
@ -964,37 +1069,29 @@ end
|
||||
-- @return #boolean If `true`, enough assets could be recruited.
|
||||
-- @return #table Recruited assets.
|
||||
-- @return #table Legions that have recruited assets.
|
||||
function COMMANDER:RecruitAssetsForTransport(Transport)
|
||||
function COMMANDER:RecruitAssetsForTransport(Transport, CargoWeight)
|
||||
|
||||
-- Get all undelivered cargo ops groups.
|
||||
local cargoOpsGroups=Transport:GetCargoOpsGroups(false)
|
||||
|
||||
local weightGroup=0
|
||||
|
||||
-- At least one group should be spawned.
|
||||
if #cargoOpsGroups>0 then
|
||||
|
||||
-- Calculate the max weight so we know which cohorts can provide carriers.
|
||||
for _,_opsgroup in pairs(cargoOpsGroups) do
|
||||
local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP
|
||||
local weight=opsgroup:GetWeightTotal()
|
||||
if weight>weightGroup then
|
||||
weightGroup=weight
|
||||
end
|
||||
end
|
||||
else
|
||||
if weightGroup==0 then
|
||||
-- No cargo groups!
|
||||
return false
|
||||
return false, {}, {}
|
||||
end
|
||||
|
||||
-- Cohorts.
|
||||
local Cohorts={}
|
||||
for _,_legion in pairs(self.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
|
||||
-- Check that runway is operational.
|
||||
local Runway=legion:IsAirwing() and legion:IsRunwayOperational() or true
|
||||
|
||||
if legion:IsRunning() and Runway then
|
||||
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -1006,7 +1103,7 @@ function COMMANDER:RecruitAssetsForTransport(Transport)
|
||||
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
|
||||
|
||||
-- Recruit assets and legions.
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, weightGroup)
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, CargoWeight)
|
||||
|
||||
return recruited, assets, legions
|
||||
end
|
||||
|
||||
@ -1864,10 +1864,11 @@ function FLIGHTGROUP:onafterArrived(From, Event, To)
|
||||
self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.ARRIVED)
|
||||
end
|
||||
|
||||
local airwing=self:GetAirWing()
|
||||
--TODO: Check that current base is airwing base.
|
||||
local airwing=self:GetAirWing() --airwing:GetAirbaseName()==self.currbase:GetName()
|
||||
|
||||
-- Check what to do.
|
||||
if airwing then
|
||||
if airwing and not (self:IsPickingup() or self:IsTransporting()) then
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Airwing asset group %s arrived ==> Adding asset back to stock of airwing %s", self.groupname, airwing.alias))
|
||||
|
||||
@ -275,7 +275,7 @@ function LEGION:AddMission(Mission)
|
||||
end
|
||||
|
||||
-- Add ops transport to transport Legions.
|
||||
if Mission.opstransport then
|
||||
if Mission.opstransport and false then
|
||||
|
||||
local PickupZone=self.spawnzone
|
||||
local DeployZone=Mission.opstransport.tzcDefault.DeployZone
|
||||
@ -622,7 +622,7 @@ function LEGION:onafterMissionRequest(From, Event, To, Mission)
|
||||
|
||||
-- Cancel the current ALERT 5 mission.
|
||||
if currM and currM.type==AUFTRAG.Type.ALERT5 then
|
||||
asset.flightgroup:MissionCancel(currM)
|
||||
asset.flightgroup:MissionCancel(currM)
|
||||
end
|
||||
|
||||
|
||||
@ -673,8 +673,8 @@ function LEGION:onafterMissionRequest(From, Event, To, Mission)
|
||||
|
||||
if request then
|
||||
if self.isShip then
|
||||
self:T(self.lid.."FF request late activated")
|
||||
request.lateActivation=true
|
||||
--self:T(self.lid.."FF request late activated")
|
||||
--request.lateActivation=true
|
||||
end
|
||||
end
|
||||
|
||||
@ -1793,7 +1793,7 @@ end
|
||||
-- Recruiting and Optimization Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Recruit assets from Cohorts for the given parameters.
|
||||
--- Recruit assets from Cohorts for the given parameters. **NOTE** that we set the `asset.isReserved=true` flag so it cant be recruited by anyone else.
|
||||
-- @param #table Cohorts Cohorts included.
|
||||
-- @param #string MissionTypeRecruit Mission type for recruiting the cohort assets.
|
||||
-- @param #string MissionTypeOpt Mission type for which the assets are optimized. Default is the same as `MissionTypeRecruit`.
|
||||
@ -1804,10 +1804,12 @@ end
|
||||
-- @param #number RangeMax Max range in meters.
|
||||
-- @param #number RefuelSystem Refuelsystem.
|
||||
-- @param #number CargoWeight Cargo weight for recruiting transport carriers.
|
||||
-- @param #table Categories Group categories.
|
||||
-- @param #table Attributes Group attributes. See `GROUP.Attribute.`
|
||||
-- @return #boolean If `true` enough assets could be recruited.
|
||||
-- @return #table Recruited assets.
|
||||
-- @return #table Recruited assets. **NOTE** that we set the `asset.isReserved=true` flag so it cant be recruited by anyone else.
|
||||
-- @return #table Legions of recruited assets.
|
||||
function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, NreqMin, NreqMax, TargetVec2, Payloads, RangeMax, RefuelSystem, CargoWeight)
|
||||
function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, NreqMin, NreqMax, TargetVec2, Payloads, RangeMax, RefuelSystem, CargoWeight, Categories, Attributes)
|
||||
|
||||
-- The recruited assets.
|
||||
local Assets={}
|
||||
@ -1815,10 +1817,39 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt,
|
||||
-- Legions of recruited assets.
|
||||
local Legions={}
|
||||
|
||||
-- Set MissionTypeOpt to Recruit if nil.
|
||||
if MissionTypeOpt==nil then
|
||||
MissionTypeOpt=MissionTypeRecruit
|
||||
end
|
||||
|
||||
--- Function to check category.
|
||||
local function CheckCategory(_cohort)
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
if Categories and #Categories>0 then
|
||||
for _,category in pairs(Categories) do
|
||||
if category==cohort.category then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--- Function to check attribute.
|
||||
local function CheckAttribute(_cohort)
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
if Attributes and #Attributes>0 then
|
||||
for _,attribute in pairs(Attributes) do
|
||||
if attribute==cohort.attribute then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(Cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
@ -1838,8 +1869,18 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt,
|
||||
-- Can carry the cargo?
|
||||
local CanCarry=CargoWeight and cohort.cargobayLimit>=CargoWeight or true
|
||||
|
||||
-- Right category.
|
||||
local RightCategory=CheckCategory(cohort)
|
||||
|
||||
-- Right attribute.
|
||||
local RightAttribute=CheckAttribute(cohort)
|
||||
|
||||
-- Debug info.
|
||||
cohort:I(cohort.lid..string.format("State=%s: Capable=%s, InRange=%s, Refuel=%s, CanCarry=%s, RightCategory=%s, RightAttribute=%s",
|
||||
cohort:GetState(), tostring(Capable), tostring(InRange), tostring(Refuel), tostring(CanCarry), tostring(RightCategory), tostring(RightAttribute)))
|
||||
|
||||
-- Check OnDuty, capable, in range and refueling type (if TANKER).
|
||||
if cohort:IsOnDuty() and Capable and InRange and Refuel and CanCarry then
|
||||
if cohort:IsOnDuty() and Capable and InRange and Refuel and CanCarry and RightCategory and RightAttribute then
|
||||
|
||||
-- Recruit assets from cohort.
|
||||
local assets, npayloads=cohort:RecruitAssets(MissionTypeRecruit, 999)
|
||||
@ -1893,6 +1934,7 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt,
|
||||
-- Add assets to mission.
|
||||
for i=1,Nassets do
|
||||
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
Legions[asset.legion.alias]=asset.legion
|
||||
end
|
||||
|
||||
|
||||
@ -3802,19 +3802,6 @@ function OPSGROUP:_GetNextMission()
|
||||
for _,_mission in pairs(self.missionqueue) do
|
||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||
|
||||
-- Local transport.
|
||||
local transport=true
|
||||
if mission.opstransport then
|
||||
local cargos=mission.opstransport:GetCargoOpsGroups(false) or {}
|
||||
for _,_opsgroup in pairs(cargos) do
|
||||
local opscargo=_opsgroup --Ops.OpsGroup#OPSGROUP
|
||||
if opscargo.groupname==self.groupname then
|
||||
transport=false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: One could think of opsgroup specific start conditions. A legion also checks if "ready" but it can be other criteria for the group to actually start the mission.
|
||||
-- Good example is the above transport. The legion should start the mission but the group should only start after the transport is finished.
|
||||
|
||||
@ -3827,11 +3814,23 @@ function OPSGROUP:_GetNextMission()
|
||||
end
|
||||
end
|
||||
|
||||
-- Local transport.
|
||||
local isTransport=true
|
||||
if mission.opstransport then
|
||||
local cargos=mission.opstransport:GetCargoOpsGroups(false) or {}
|
||||
for _,_opsgroup in pairs(cargos) do
|
||||
local opscargo=_opsgroup --Ops.OpsGroup#OPSGROUP
|
||||
if opscargo.groupname==self.groupname then
|
||||
isTransport=false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Conditons to start.
|
||||
local isScheduled=mission:GetGroupStatus(self)==AUFTRAG.GroupStatus.SCHEDULED
|
||||
local isReadyToGo=(mission:IsReadyToGo() or self.legion)
|
||||
local isImportant=(mission.importance==nil or mission.importance<=vip)
|
||||
local isTransport=transport
|
||||
|
||||
-- Check necessary conditions.
|
||||
if isScheduled and isReadyToGo and isImportant and isTransport and isEscort then
|
||||
|
||||
@ -168,6 +168,7 @@ OPSTRANSPORT.Status={
|
||||
-- @field #table DisembarkCarriers Carriers where the cargo is directly disembarked to.
|
||||
-- @field #boolean disembarkActivation If true, troops are spawned in late activated state when disembarked from carrier.
|
||||
-- @field #boolean disembarkInUtero If true, troops are disembarked "in utero".
|
||||
-- @field #boolean assets Cargo assets.
|
||||
|
||||
--- Path used for pickup or transport.
|
||||
-- @type OPSTRANSPORT.Path
|
||||
@ -1225,14 +1226,16 @@ end
|
||||
--- Add asset to transport.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset to be added.
|
||||
-- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:AddAsset(Asset)
|
||||
function OPSTRANSPORT:AddAsset(Asset, TransportZoneCombo)
|
||||
|
||||
-- Debug info
|
||||
self:T(self.lid..string.format("Adding asset \"%s\" to transport", tostring(Asset.spawngroupname)))
|
||||
self:T(self.lid..string.format("Adding asset carrier \"%s\" to transport", tostring(Asset.spawngroupname)))
|
||||
|
||||
-- Add asset to table.
|
||||
self.assets=self.assets or {}
|
||||
|
||||
table.insert(self.assets, Asset)
|
||||
|
||||
return self
|
||||
@ -1258,6 +1261,28 @@ function OPSTRANSPORT:DelAsset(Asset)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add cargo asset.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset to be added.
|
||||
-- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:AddAssetCargo(Asset, TransportZoneCombo)
|
||||
|
||||
-- Debug info
|
||||
self:T(self.lid..string.format("Adding asset cargo \"%s\" to transport and TZC=%s", tostring(Asset.spawngroupname), TransportZoneCombo and TransportZoneCombo.uid or "N/A"))
|
||||
|
||||
-- Add asset to table.
|
||||
self.assetsCargo=self.assetsCargo or {}
|
||||
|
||||
table.insert(self.assetsCargo, Asset)
|
||||
|
||||
TransportZoneCombo.assetsCargo=TransportZoneCombo.assetsCargo or {}
|
||||
|
||||
TransportZoneCombo.assetsCargo[Asset.spawngroupname]=Asset
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add LEGION to the transport.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Ops.Legion#LEGION Legion The legion.
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Monitor if zone is captured.
|
||||
-- * Monitor if a zone is captured.
|
||||
-- * Monitor if an airbase is captured.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
@ -17,6 +18,8 @@
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity of output.
|
||||
-- @field Core.Zone#ZONE zone The zone.
|
||||
-- @field Wrapper.Airbase#AIRBASE airbase The airbase that is monitored.
|
||||
-- @field #string airbaseName Name of the airbase that is monitored.
|
||||
-- @field #string zoneName Name of the zone.
|
||||
-- @field #number zoneRadius Radius of the zone in meters.
|
||||
-- @field #number ownerCurrent Coalition of the current owner of the zone.
|
||||
@ -30,7 +33,7 @@
|
||||
-- @field #number Tattacked Abs. mission time stamp when an attack was started.
|
||||
-- @field #number dTCapture Time interval in seconds until a zone is captured.
|
||||
-- @field #boolean neutralCanCapture Neutral units can capture. Default `false`.
|
||||
-- @field #drawZone If `true`, draw the zone on the F10 map.
|
||||
-- @field #boolean drawZone If `true`, draw the zone on the F10 map.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- Be surprised!
|
||||
@ -63,6 +66,7 @@ OPSZONE.version="0.1.0"
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Capture airbases.
|
||||
-- TODO: Pause/unpause evaluations.
|
||||
-- TODO: Capture time, i.e. time how long a single coalition has to be inside the zone to capture it.
|
||||
-- TODO: Can neutrals capture? No, since they are _neutral_!
|
||||
@ -113,17 +117,19 @@ function OPSZONE:New(Zone, CoalitionOwner)
|
||||
self:SetObjectCategories()
|
||||
self:SetUnitCategories()
|
||||
|
||||
self.drawZone=true
|
||||
|
||||
-- Status timer.
|
||||
self.timerStatus=TIMER:New(OPSZONE.Status, self)
|
||||
|
||||
|
||||
-- FMS start state is EMPTY.
|
||||
self:SetStartState("Empty")
|
||||
self:SetStartState("Stopped")
|
||||
|
||||
-- Add FSM transitions.
|
||||
-- From State --> Event --> To State
|
||||
self:AddTransition("*", "Start", "*") -- Start FSM.
|
||||
self:AddTransition("*", "Stop", "*") -- Stop FSM.
|
||||
self:AddTransition("Stopped", "Start", "Empty") -- Start FSM.
|
||||
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
||||
|
||||
self:AddTransition("*", "Captured", "Guarded") -- Zone was captured.
|
||||
self:AddTransition("*", "Empty", "Empty") -- No red or blue units inside the zone.
|
||||
@ -372,9 +378,16 @@ function OPSZONE:IsContested()
|
||||
return self.isContested
|
||||
end
|
||||
|
||||
--- Check if FMS is stopped.
|
||||
-- @param #OPSZONE self
|
||||
-- @return #boolean If `true`, FSM is stopped
|
||||
function OPSZONE:IsStopped()
|
||||
local is=self:is("Stopped")
|
||||
return is
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Start/Stop and Status Functions
|
||||
-- Start/Stop Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Start OPSZONE FSM.
|
||||
@ -395,6 +408,25 @@ function OPSZONE:onafterStart(From, Event, To)
|
||||
|
||||
end
|
||||
|
||||
--- Stop OPSZONE FSM.
|
||||
-- @param #OPSZONE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function OPSZONE:onafterStop(From, Event, To)
|
||||
|
||||
-- Info.
|
||||
self:I(self.lid..string.format("Stopping OPSZONE"))
|
||||
|
||||
-- Reinit the timer.
|
||||
self.timerStatus:Stop()
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Status Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Update status.
|
||||
-- @param #OPSZONE self
|
||||
function OPSZONE:Status()
|
||||
@ -445,7 +477,7 @@ end
|
||||
function OPSZONE:onafterEmpty(From, Event, To)
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Zone is empty now"))
|
||||
self:T(self.lid..string.format("Zone is empty EVENT"))
|
||||
|
||||
end
|
||||
|
||||
@ -462,19 +494,6 @@ function OPSZONE:onafterAttacked(From, Event, To, AttackerCoalition)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- On after "Empty" event.
|
||||
-- @param #OPSZONE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function OPSZONE:onafterEmpty(From, Event, To)
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Zone is empty now"))
|
||||
|
||||
end
|
||||
|
||||
--- On after "Defeated" event.
|
||||
-- @param #OPSZONE self
|
||||
-- @param #string From From state.
|
||||
@ -504,6 +523,14 @@ function OPSZONE:onenterGuarded(From, Event, To)
|
||||
-- Not attacked any more.
|
||||
self.Tattacked=nil
|
||||
|
||||
if self.drawZone then
|
||||
self.zone:UndrawZone()
|
||||
|
||||
local color=self:_GetZoneColor()
|
||||
|
||||
self.zone:DrawZone(nil, color, 1.0, color, 0.7)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- On enter "Guarded" state.
|
||||
@ -519,6 +546,34 @@ function OPSZONE:onenterAttacked(From, Event, To)
|
||||
-- Time stamp when the attack started.
|
||||
self.Tattacked=timer.getAbsTime()
|
||||
|
||||
if self.drawZone then
|
||||
self.zone:UndrawZone()
|
||||
|
||||
local color={1,1,1}
|
||||
|
||||
self.zone:DrawZone(nil, color, 1.0, color, 0.9)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- On enter "Empty" event.
|
||||
-- @param #OPSZONE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function OPSZONE:onenterEmpty(From, Event, To)
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Zone is empty now"))
|
||||
|
||||
if self.drawZone then
|
||||
self.zone:UndrawZone()
|
||||
|
||||
local color=self:_GetZoneColor()
|
||||
|
||||
self.zone:DrawZone(nil, color, 1.0, color, 0.2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -837,6 +892,49 @@ function OPSZONE:OnEventHit(EventData)
|
||||
|
||||
end
|
||||
|
||||
--- Monitor hit events.
|
||||
-- @param #OPSZONE self
|
||||
-- @param Core.Event#EVENTDATA EventData The event data.
|
||||
function OPSZONE:OnEventBaseCaptured(EventData)
|
||||
|
||||
if EventData and EventData.Place and self.airbase and self.airbaseName then
|
||||
|
||||
-- Place is the airbase that was captured.
|
||||
local airbase=EventData.Place --Wrapper.Airbase#AIRBASE
|
||||
|
||||
-- Check that this airbase belongs or did belong to this warehouse.
|
||||
if EventData.PlaceName==self.airbaseName then
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Misc Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Get RGB color of zone depending on current owner.
|
||||
-- @param #OPSZONE self
|
||||
-- @return #table RGB color.
|
||||
function OPSZONE:_GetZoneColor()
|
||||
|
||||
local color={0,0,0}
|
||||
|
||||
if self.ownerCurrent==coalition.side.NEUTRAL then
|
||||
color={0, 1, 0}
|
||||
elseif self.ownerCurrent==coalition.side.BLUE then
|
||||
color={1, 0, 0}
|
||||
elseif self.ownerCurrent==coalition.side.RED then
|
||||
color={0, 0, 1}
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
return color
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user