diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 6c13547e2..392da5c86 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -1752,7 +1752,7 @@ _WAREHOUSEDB = { --- Warehouse class version. -- @field #string version -WAREHOUSE.version="0.9.6" +WAREHOUSE.version="0.9.6wip" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Warehouse todo list. @@ -3664,8 +3664,11 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu -- Get the original warehouse this group belonged to. local warehouse=self:FindWarehouseInDB(wid) + if warehouse then + local request=warehouse:_GetRequestOfGroup(group, warehouse.pending) + if request then -- Increase number of cargo delivered and transports home. @@ -3693,21 +3696,33 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu -- Get the asset from the global DB. local asset=self:FindAssetInDB(group) - -- Set livery. - if liveries then - asset.livery=liveries[math.random(#liveries)] - end - - -- Set skill. - asset.skill=skill - -- Note the group is only added once, i.e. the ngroups parameter is ignored here. -- This is because usually these request comes from an asset that has been transfered from another warehouse and hence should only be added once. 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) - table.insert(self.stock, asset) + 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.wid=self.wid + + -- No request associated with this asset. + asset.rid=nil + + -- Set livery. + if liveries then + asset.livery=liveries[math.random(#liveries)] + end + + -- Set skill. + asset.skill=skill + + -- Asset is not spawned. asset.spawned=false asset.spawngroupname=nil + + -- Add asset to stock. + table.insert(self.stock, asset) + + -- Trigger New asset event. self:NewAsset(asset, assignment or "") else self:_ErrorMessage(string.format("ERROR: Known asset could not be found in global warehouse db!"), 0) @@ -3726,7 +3741,12 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu -- Add created assets to stock of this warehouse. for _,asset in pairs(assets) do + + asset.wid=self.wid + asset.rid=nil + table.insert(self.stock, asset) + self:NewAsset(asset, assignment or "") end @@ -3863,6 +3883,8 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, end asset.skill=skill asset.assignment=assignment + asset.spawned=false + asset.spawngroupname=string.format("%s_AID-%d", templategroupname, asset.uid) if i==1 then self:_AssetItemInfo(asset) @@ -4170,11 +4192,15 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request) local _assetitem=_assetstock[i] --#WAREHOUSE.Assetitem -- Create an alias name with the UIDs for the sending warehouse, asset and request. - local _alias=self:_alias(_assetitem.unittype, self.uid, _assetitem.uid, Request.uid) + --local _alias=self:_alias(_assetitem.unittype, self.uid, _assetitem.uid, Request.uid) + + local _alias=_assetitem.spawngroupname + + _assetitem.rid=Request.uid -- Asset is transport. _assetitem.spawned=false - _assetitem.spawngroupname=nil + --_assetitem.spawngroupname=nil _assetitem.iscargo=false local spawngroup=nil --Wrapper.Group#GROUP @@ -5279,11 +5305,14 @@ function WAREHOUSE:_SpawnAssetRequest(Request) -- Set asset status to not spawned until we capture its birth event. asset.spawned=false - asset.spawngroupname=nil + --asset.spawngroupname=nil asset.iscargo=true + asset.rid=Request.uid -- Alias of the group. - local _alias=self:_Alias(asset, Request) + --local _alias=self:_Alias(asset, Request) + + local _alias=asset.spawngroupname -- Spawn an asset group. local _group=nil --Wrapper.Group#GROUP @@ -7556,6 +7585,72 @@ function WAREHOUSE:_GetIDsFromGroup(group) return _wid,_aid,_rid end + if group then + + -- Group name + local name=group:GetName() + + -- Get asset id from group name. + local wid,aid,rid=analyse(name) + + -- Get Asset. + local asset=self:GetAssetByID(aid) + + -- Get warehouse and request id from asset table. + wid=asset.wid + rid=asset.rid + + -- Debug info + self:T3(self.wid..string.format("Group Name = %s", tostring(name))) + self:T3(self.wid..string.format("Warehouse ID = %s", tostring(wid))) + self:T3(self.wid..string.format("Asset ID = %s", tostring(aid))) + self:T3(self.wid..string.format("Request ID = %s", tostring(rid))) + + return wid,aid,rid + else + self:E("WARNING: Group not found in GetIDsFromGroup() function!") + end + +end + + +--- Get warehouse id, asset id and request id from group name (alias). +-- @param #WAREHOUSE self +-- @param Wrapper.Group#GROUP group The group from which the info is gathered. +-- @return #number Warehouse ID. +-- @return #number Asset ID. +-- @return #number Request ID. +function WAREHOUSE:_GetIDsFromGroupOLD(group) + + ---@param #string text The text to analyse. + local function analyse(text) + + -- Get rid of #0001 tail from spawn. + local unspawned=UTILS.Split(text, "#")[1] + + -- Split keywords. + local keywords=UTILS.Split(unspawned, "_") + local _wid=nil -- warehouse UID + local _aid=nil -- asset UID + local _rid=nil -- request UID + + -- Loop over keys. + for _,keys in pairs(keywords) do + local str=UTILS.Split(keys, "-") + local key=str[1] + local val=str[2] + if key:find("WID") then + _wid=tonumber(val) + elseif key:find("AID") then + _aid=tonumber(val) + elseif key:find("RID") then + _rid=tonumber(val) + end + end + + return _wid,_aid,_rid + end + if group then -- Group name diff --git a/Moose Development/Moose/Ops/CarrierAirWing.lua b/Moose Development/Moose/Ops/CarrierAirWing.lua index e2616b9fe..3d6ca3dda 100644 --- a/Moose Development/Moose/Ops/CarrierAirWing.lua +++ b/Moose Development/Moose/Ops/CarrierAirWing.lua @@ -2,7 +2,7 @@ -- -- **Main Features:** -- --- * Nice stuff. +-- * Manage squadrons. -- -- === -- @@ -93,12 +93,12 @@ CVW.version="0.0.5" --- Create a new CVW class object for a specific aircraft carrier unit. -- @param #CVW self -- @param #string carriername Name of the carrier. --- @param #string squadronname Name of the squadron. +-- @param #string cvwname Name of the carrier air wing, e.g. "CVW-8". -- @return #CVW self -function CVW:New(carriername, squadronname) +function CVW:New(carriername, cvwname) -- Inherit everything from WAREHOUSE class. - local self=BASE:Inherit(self, WAREHOUSE:New(carriername, squadronname)) -- #CVW + local self=BASE:Inherit(self, WAREHOUSE:New(carriername, cvwname)) -- #CVW if not self then BASE:E(string.format("ERROR: Could not find carrier %s!", carriername)) diff --git a/Moose Development/Moose/Ops/Squadron.lua b/Moose Development/Moose/Ops/Squadron.lua index e69de29bb..efb7a5327 100644 --- a/Moose Development/Moose/Ops/Squadron.lua +++ b/Moose Development/Moose/Ops/Squadron.lua @@ -0,0 +1,139 @@ +--- **Ops** - (R2.5) - AI Squadron for Ops. +-- +-- **Main Features:** +-- +-- * Stuff +-- +-- === +-- +-- ### Author: **funkyfranky** +-- @module Ops.Squadron +-- @image OPS_Squadron.png + + +--- SQUADRON class. +-- @type SQUADRON +-- @field #string ClassName Name of the class. +-- @field #boolean Debug Debug mode. Messages to all about status. +-- @field #string sid Class id string for output to DCS log file. +-- @extends Core.Fsm#FSM + +--- Be surprised! +-- +-- === +-- +-- ![Banner Image](..\Presentations\CarrierAirWing\SQUADRON_Main.jpg) +-- +-- # The SQUADRON Concept +-- +-- +-- +-- @field #SQUADRON +SQUADRON = { + ClassName = "SQUADRON", + Debug = nil, + sid = nil, + assets = {}, + livery = nil, + tasks = {}, +} + + + +--- SQUADRON class version. +-- @field #string version +SQUADRON.version="0.0.1" + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- TODO list +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +-- TODO: Add tasks. +-- TODO: + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Constructor +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Create a new SQUADRON object and start the FSM. +-- @param #SQUADRON self +-- @param #string squadronname Name of the squadron, e.g. "VFA-37". +-- @param #table Table of squadron tasks, e.g. {SQUADRON.Task.INTERCEPT, SQUADRON.Task.SEAD}. +-- @return #SQUADRON self +function SQUADRON:New(squadronname, tasks) + + -- Inherit everything from WAREHOUSE class. + local self=BASE:Inherit(self, FSM:New()) -- #SQUADRON + + --self.flightgroup=AIGroup + self.squadronname=tostring(name) + + -- Set some string id for output to DCS.log file. + self.sid=string.format("SQUADRON %s | ", self.squadronname) + + -- Start State. + self:SetStartState("Stopped") + + -- Init set of detected units. + self.detectedunits=SET_UNIT:New() + + self.assets={} + + self.tasks=tasks or {} + + -- Add FSM transitions. + -- From State --> Event --> To State + self:AddTransition("Stopped", "Start", "Running") -- Start FSM. + + self:AddTransition("*", "FlightStatus", "*") -- SQUADRON status update + + ------------------------ + --- Pseudo Functions --- + ------------------------ + + --- Triggers the FSM event "Start". Starts the SQUADRON. Initializes parameters and starts event handlers. + -- @function [parent=#SQUADRON] Start + -- @param #SQUADRON self + + --- Triggers the FSM event "Start" after a delay. Starts the SQUADRON. Initializes parameters and starts event handlers. + -- @function [parent=#SQUADRON] __Start + -- @param #SQUADRON self + -- @param #number delay Delay in seconds. + + --- Triggers the FSM event "Stop". Stops the SQUADRON and all its event handlers. + -- @param #SQUADRON self + + --- Triggers the FSM event "Stop" after a delay. Stops the SQUADRON and all its event handlers. + -- @function [parent=#SQUADRON] __Stop + -- @param #SQUADRON self + -- @param #number delay Delay in seconds. + + --- Triggers the FSM event "FlightStatus". + -- @function [parent=#SQUADRON] FlightStatus + -- @param #SQUADRON self + + --- Triggers the FSM event "SkipperStatus" after a delay. + -- @function [parent=#SQUADRON] __FlightStatus + -- @param #SQUADRON self + -- @param #number delay Delay in seconds. + + + -- Debug trace. + if false then + self.Debug=true + BASE:TraceOnOff(true) + BASE:TraceClass(self.ClassName) + BASE:TraceLevel(1) + end + self.Debug=true + + + return self +end + + + + + + +