From 2d3ef543b3cea987665c81557f6229d3db573739 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 18 Feb 2020 16:45:07 +0100 Subject: [PATCH] Ops --- Moose Development/Moose/Ops/AirWing.lua | 152 +++++++++++++++++-- Moose Development/Moose/Ops/FlightGroup.lua | 2 +- Moose Development/Moose/Ops/Intelligence.lua | 70 ++++++++- 3 files changed, 203 insertions(+), 21 deletions(-) diff --git a/Moose Development/Moose/Ops/AirWing.lua b/Moose Development/Moose/Ops/AirWing.lua index 68281bd1d..6deb828fc 100644 --- a/Moose Development/Moose/Ops/AirWing.lua +++ b/Moose Development/Moose/Ops/AirWing.lua @@ -21,6 +21,7 @@ -- @field #table squadrons Table of squadrons. -- @field #table missionqueue Mission queue table. -- @field #table missioncounter Running index counting the added missions. +-- @field #table payloads Playloads for specific aircraft and mission types. -- @extends Functional.Warehouse#WAREHOUSE --- Be surprised! @@ -42,15 +43,17 @@ AIRWING = { squadrons = nil, missionqueue = {}, missioncounter = nil, + payloads = {}, } --- Squadron data. -- @type AIRWING.Squadron -- @field #string name Name of the squadron. -- @field #table assets Assets of the squadron. --- @field #table capabilities Mission types that the squadron can do. +-- @field #table missiontypes Mission types that the squadron can do. -- @field #string livery Livery of the squadron. -- @field #table menu The squadron menu entries. +-- @field #string skill Skill of squadron team members. --- Squadron asset. -- @type AIRWING.SquadronAsset @@ -64,6 +67,14 @@ AIRWING = { -- @field #number nassets Number of required assets. -- @extends Ops.FlightGroup#FLIGHTGROUP.Mission +--- Payload data. +-- @type AIRWING.Payload +-- @field #string aircrafttype Type of aircraft, which can use this payload. +-- @field #table missiontypes Mission types for which this payload can be used. +-- @field #table pylons Pylon data extracted for the unit template. +-- @field #number navail Number of available payloads of this type. + + --- AIRWING class version. -- @field #string version AIRWING.version="0.1.0" @@ -162,7 +173,7 @@ end -- User Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Add a squadron to the carrier air wing. +--- Add a squadron to the air wing. -- @param #AIRWING self -- @param #string name Name of the squadron, e.g. "VFA-37". -- @param #table tasks Table of tasks the squadron is supposed to do. @@ -174,7 +185,7 @@ function AIRWING:AddSquadron(SquadronName, MissionTypes, Livery) squadron.name=SquadronName squadron.assets={} - squadron.tasks=MissionTypes or {} + squadron.missiontypes=MissionTypes or {} squadron.livery=Livery self.squadrons[SquadronName]=squadron @@ -182,6 +193,55 @@ function AIRWING:AddSquadron(SquadronName, MissionTypes, Livery) return squadron end +--- Add a payload to air wing resources. +-- @param #AIRWING self +-- @param #string UnitName Name of the (template) unit from which the payload is extracted. +-- @param #number Npayloads Number of payloads to add to the airwing resources. Default 999. +-- @param #table MissionTypes Mission types this payload can be used for. +function AIRWING:AddPayload(UnitName, Npayloads, MissionTypes) + + local payload=self:GetPayloadByName(UnitName) + + if payload then + + -- Payload already exists. Increase the number. + payload.navail=payload.navail+Npayloads + + --TODO: maybe check if mission types given now are different from before. + + else + + local unit=UNIT:FindByName(UnitName) + + if unit then + + payload={} --#AIRWING.Payload + + payload.navail=Npayloads + payload.missiontypes=MissionTypes + payload.aircrafttype=unit:GetTypeName() + payload.pylons=unit:GetTemplatePylons() + + --TODO: maybe add fuel, chaff and gun? + + --table.insert(self.payloads, payload) + self.payloads[UnitName]=payload + + end + + end + +end + +--- Add a payload to air wing resources. +-- @param #AIRWING self +-- @param #string UnitName Name of the unit from which the payload was extracted. +-- @return #AIRWING.Payload +function AIRWING:GetPayloadByName(UnitName) + return self.payloads[UnitName] +end + + --- Add flight group(s) to squadron. -- @param #AIRWING self -- @param #AIRWING.Squadron SquadronName Name of the squadron. @@ -203,7 +263,7 @@ function AIRWING:AddAssetToSquadron(SquadronName, Group, Ngroups) local text=string.format("FF Adding asset %s to squadron %s", Group:GetName(), squadron.name) env.info(text) - self:AddAsset(Group, Ngroups, nil, nil, nil, nil, nil, {squadron.livery}, squadron.name) + self:AddAsset(Group, Ngroups, nil, nil, nil, nil, AI.Skill.EXCELLENT, squadron.livery, squadron.name) else self:E("ERROR: Group does not exist!") @@ -218,7 +278,7 @@ end --- Get squadron by name. -- @param #AIRWING self --- @param #string name Name of the squadron, e.g. "VFA-37". +-- @param #string SquadronName Name of the squadron, e.g. "VFA-37". -- @return #AIRWING self or nil. function AIRWING:GetSquadron(SquadronName) return self.squadrons[SquadronName] @@ -237,7 +297,7 @@ function AIRWING:SquadronCanMission(Squadron, MissionType, Nassets) local n=0 local gotit=false - for _,canmission in pairs(Squadron.capabilities) do + for _,canmission in pairs(Squadron.missiontypes) do if canmission==MissionType then gotit=true break @@ -319,9 +379,7 @@ function AIRWING:CreateMissionCAP(Altitude, SpeedOrbit, Heading, Leg) mission.speedOrbit=UTILS.KnotsToMps(SpeedOrbit or 350) mission.heading=Heading or 270 mission.leg=UTILS.NMToMeters(Leg or 10) - - mission.waypoint=1 - + return mission end @@ -341,6 +399,7 @@ function AIRWING:AddMission(Mission, Zone, WaypointIndex, ClockStart, ClockStop, local mission=FLIGHTGROUP.AddMission(self, Mission, Zone, WaypointIndex, ClockStart, ClockStop, Prio, Name) -- Mission needs the correct MID. + mission.mid=nil mission.MID=self.missioncounter return mission @@ -394,7 +453,7 @@ function AIRWING:onafterAirwingStatus(From, Event, To) local asset=_asset --#AIRWING.SquadronAsset local assignment=asset.assignment or "none" local name=asset.templatename - local task=asset.AIRWINGtask or "none" + local task=asset.mission and asset.mission.name or "none" local spawned=tostring(asset.spawned) local groupname=asset.spawngroupname local group=nil --Wrapper.Group#GROUP @@ -407,7 +466,7 @@ function AIRWING:onafterAirwingStatus(From, Event, To) end end - text=text..string.format("\n -[%d] %s*%d: spawned=%s, task=%s, fuel=%d", j, typename, asset.nunits, spawned, task, fuel) + text=text..string.format("\n -[%d] %s*%d: spawned=%s, mission=%s, fuel=%d", j, typename, asset.nunits, spawned, task, fuel) end end @@ -430,7 +489,7 @@ end --- Get next mission. -- @param #AIRWING self --- @return #AIRWING.Mission Next mission or *nil*. +-- @return #AIRWING.Missiondata Next mission or *nil*. function AIRWING:_GetNextMission() -- Number of missions. @@ -445,7 +504,7 @@ function AIRWING:_GetNextMission() local function _sort(a, b) local taskA=a --#AIRWING.Mission local taskB=b --#AIRWING.Mission - --TODO: probably sort by prio first and then by time as only missions for T>Tstart are executed. That would ensure that the highest prio mission is carried ot first! + --TODO: probably sort by prio first and then by time as only missions for T>Tstart are executed. That would ensure that the highest prio mission is carried out first! return (taskA.Tstart Update data. + --- + + + + else + --- + -- Detected item does not exist in our list yet. + --- + + end + + end + +end + +--- Create detected items. +-- @param #INTEL self +-- @param #string name Name of the detected item. +-- @return #INTEL.DetectedItem +function INTEL:GetDetectedItemByName(name) + + return self.DetectedItems[name] + end -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------