From ca84fa11cdc779433bc3d6f721ef75a279b0981b Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 20 Sep 2023 17:17:12 +0200 Subject: [PATCH 1/9] #ATIS * Added Spanish TTS locale ("es") --- Moose Development/Moose/Ops/ATIS.lua | 66 ++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Ops/ATIS.lua b/Moose Development/Moose/Ops/ATIS.lua index 1c6f4e6bc..e0aea4bbd 100644 --- a/Moose Development/Moose/Ops/ATIS.lua +++ b/Moose Development/Moose/Ops/ATIS.lua @@ -386,7 +386,7 @@ -- -- atis=ATIS:New("Batumi", 305, radio.modulation.AM) -- atis:SetSRS("D:\\DCS\\_SRS\\", "female", "de_DE") --- atis:SetLocale("de") +-- atis:SetLocale("de") -- available locales from source are "en", "de" and "es" -- atis:Start() -- -- ## FARPS @@ -808,7 +808,67 @@ ATIS.Messages = { TACAN = "Tackan", FARP = "Farp", DELIMITER = "Komma", -- decimal delimiter - } + }, + -- Set ES Locale translations for ATIS thanks to @Ritu + ES = + { + HOURS = "horas", + TIME = "horas", + NOCLOUDINFO = "Información sobre capa de nubes no disponible", + OVERCAST = "Nublado", + BROKEN = "Nubes rotas", + SCATTERED = "Nubes dispersas", + FEWCLOUDS = "Ligeramente nublado", + NOCLOUDS = "Despejado", + AIRPORT = "Aeropuerto", + INFORMATION ="Informacion", + SUNRISEAT = "Amanecer a las %s hora local", + SUNSETAT = "Puesta de sol a las %s hora local", + WINDFROMMS = "Viento procedente de %s con %s m/s", + WINDFROMKNOTS = "Viento de %s con %s nudos", + GUSTING = "ráfagas", + VISIKM = "Visibilidad %s km", + VISISM = "Visibilidad %s millas", + RAIN = "Lluvia", + TSTORM = "Tormenta", + SNOW = "Nieve", + SSTROM = "Tormenta de nieve", + FOG = "Niebla", + DUST = "Polvo", + PHENOMENA = "Fenómenos meteorológicos", + CLOUDBASEM = "Capa de nubes de %s a %s metros", + CLOUDBASEFT = "Capa de nubes de %s a %s pies", + TEMPERATURE = "Temperatura", + DEWPOINT = "Punto de rocio", + ALTIMETER = "Altímetro", + ACTIVERUN = "Pista activa", + LEFT = "Izquierda", + RIGHT = "Derecha", + RWYLENGTH = "Longitud de pista", + METERS = "Metro", + FEET = "Pie", + ELEVATION = "Elevación", + TOWERFREQ = "Frecuencias de la torre de control", + ILSFREQ = "Fecuencia ILS", + OUTERNDB = "Frecuencia NDB externa", + INNERNDB = "Frecuencia NDB interior", + VORFREQ = "Frecuencia VOR", + VORFREQTTS = "Frecuencia V O R", + TACANCH = "Canal TACAN %d Xaver", + RSBNCH = "Canal RSBN", + PRMGCH = "Canal PRMG", + ADVISE = "Avise en el contacto inicial a torre de que tiene la informacion", + STATUTE = "Millas inglesas", + DEGREES = "Grados Celsius", + FAHRENHEIT = "Grados Fahrenheit", + INCHHG = "Pulgadas de mercurio", + MMHG = "Milímeteros de Mercurio", + HECTO = "Hectopascales", + METERSPER = "Metros por segundo", + TACAN = "Tacan", + FARP = "Farp", + DELIMITER = "Punto", -- decimal delimiter + }, } --- @@ -821,7 +881,7 @@ _ATIS = {} --- ATIS class version. -- @field #string version -ATIS.version = "0.10.1" +ATIS.version = "0.10.2" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list From 2efb6a624fc9f6a4366df7a826c8acdb345699de Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 25 Sep 2023 08:43:24 +0200 Subject: [PATCH 2/9] #SCORING * Rechtschreibung --- Moose Development/Moose/Functional/Scoring.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Functional/Scoring.lua b/Moose Development/Moose/Functional/Scoring.lua index ec95dc8a3..a7093f8c1 100644 --- a/Moose Development/Moose/Functional/Scoring.lua +++ b/Moose Development/Moose/Functional/Scoring.lua @@ -226,6 +226,7 @@ SCORING = { ClassID = 0, Players = {}, AutoSave = true, + version = "1.17.1" } local _SCORINGCoalition = { @@ -659,7 +660,7 @@ function SCORING:_AddPlayerFromUnit( UnitData ) self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + self.CoalitionChangePenalty or 50 self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1 MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' changed coalition from " .. _SCORINGCoalition[self.Players[PlayerName].UnitCoalition] .. " to " .. _SCORINGCoalition[UnitCoalition] .. - "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). ".. self.CoalitionChangePenalty .."Penalty points added.", + "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). ".. self.CoalitionChangePenalty .." penalty points added.", MESSAGE.Type.Information ):ToAll() self:ScoreCSV( PlayerName, "", "COALITION_PENALTY", 1, -1*self.CoalitionChangePenalty, self.Players[PlayerName].UnitName, _SCORINGCoalition[self.Players[PlayerName].UnitCoalition], _SCORINGCategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType, From 652df5570a09f0481982b6745954dc5feb037fe1 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 26 Sep 2023 13:07:41 +0200 Subject: [PATCH 3/9] #EasyGCICAP * initial release --- Moose Development/Moose/Modules.lua | 1 + Moose Development/Moose/Ops/EasyGCICAP.lua | 929 +++++++++++++++++++++ Moose Setup/Moose.files | 1 + 3 files changed, 931 insertions(+) create mode 100644 Moose Development/Moose/Ops/EasyGCICAP.lua diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index 2ab9ed094..709bfb0e4 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -114,6 +114,7 @@ __Moose.Include( 'Scripts/Moose/Ops/RecoveryTanker.lua' ) __Moose.Include( 'Scripts/Moose/Ops/RescueHelo.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Squadron.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Target.lua' ) +__Moose.Include( 'Scripts/Moose/Ops/EasyGCICAP.lua' ) __Moose.Include( 'Scripts/Moose/AI/AI_Balancer.lua' ) __Moose.Include( 'Scripts/Moose/AI/AI_Air.lua' ) diff --git a/Moose Development/Moose/Ops/EasyGCICAP.lua b/Moose Development/Moose/Ops/EasyGCICAP.lua new file mode 100644 index 000000000..935e517a3 --- /dev/null +++ b/Moose Development/Moose/Ops/EasyGCICAP.lua @@ -0,0 +1,929 @@ +------------------------------------------------------------------------- +-- Easy CAP/GCI Class, based on OPS classes +------------------------------------------------------------------------- +-- Documentation +-- +-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Ops.EasyGCICAP.html +-- +------------------------------------------------------------------------- +-- Date: September 2023 +------------------------------------------------------------------------- +---@diagnostic disable: cast-local-type +--- **Ops** - Easy GCI & CAP Manager +-- +-- === +-- +-- **Main Features:** +-- +-- * Automatically create and manage A2A CAP/GCI defenses using an @{Ops.AirWing#AIRWING} and Squadrons for one coalition +-- * Easy set-up +-- * Add additional AirWings on other airbases +-- * Each wing can have more than one Squadron - tasking to Squadrons is done on a random basis per AirWing +-- * Create borders and zones of engagement +-- * Detection can be ground based and/or via AWACS +-- +-- === +-- +-- ### AUTHOR: **applevangelist** +-- +-- @module Ops.EasyGCICAP +-- @image AI_Combat_Air_Patrol.JPG + + +--- EASYGCICAP Class +-- @type EASYGCICAP +-- @field #string ClassName +-- @field #number overhead +-- @field #number engagerange +-- @field #number capgrouping +-- @field #string airbasename +-- @field Wrapper.Airbase#AIRBASE airbase +-- @field #number coalition +-- @field #string alias +-- @field #table wings +-- @field Ops.Intelligence#INTEL Intel +-- @field #number resurrection +-- @field #number capspeed +-- @field #number capalt +-- @field #number capdir +-- @field #number capleg +-- @field #number capgrouping +-- @field #number maxinterceptsize +-- @field #number missionrange +-- @field #number noaltert5 +-- @field #table ManagedAW +-- @field #table ManagedSQ +-- @field #table ManagedCP +-- @field #table ManagedTK +-- @field #number MaxAliveMissions +-- @field #boolean debug +-- @extends Core.Fsm#FSM + +--- *“Airspeed, altitude, and brains. Two are always needed to successfully complete the flight.”* -- Unknown. +-- +-- === +-- +-- # The EasyGCICAP Concept +-- +-- The idea of this class is partially to make the OPS classes easier operational for an A2A CAP/GCI defense network, and to replace the legacy AI_A2A_Dispatcher system - not to it's +-- full extent, but make a basic system work very quickly. +-- +-- # Setup +-- +-- ## Basic understanding +-- +-- The basics are, there is **one** and only **one** AirWing per airbase. Each AirWing has **at least** one Squadron, who will do both CAP and GCI tasks. Squadrons will be randomly chosen for the task at hand. +-- Each AirWing has **at least** one CAP Point that it manages. CAP Points will be covered by the AirWing automatically as long as airframes are available. Detected intruders will be assigned to **one** +-- AirWing based on proximity (that is, if you have more than one). +-- +-- ## Assignment of tasks for intruders +-- +-- Either a CAP Plane or a newly spawned GCI plane will take care of the intruders. Standard overhead is 0.75, i.e. a group of 3 intrudes will +-- be managed by 2 planes from the assigned AirWing. There is an maximum missions limitation per AirWing, so we do not spam the skies. +-- +-- ## Basic set-up code +-- +-- ### Prerequisites +-- +-- You have to put a STATIC object on the airbase with the UNIT name according to the name of the airbase. E.g. for Kuitaisi this has to have the name Kutaisi. This object symbolizes the AirWing HQ. +-- Next put a late activated template group for your CAP/GCI Squadron on the map. Last, put a zone on the map for the CAP operations, let's name it "Blue Zone 1". Size of the zone plays no role. +-- Put an EW radar system on the map and name it aptly, like "Blue EWR". +-- +-- ### Code it +-- +-- -- Set up a basic system for the blue side, we'll reside on Kutaisi, and use GROUP objects with "Blue EWR" in the name as EW Radar Systems. +-- local mywing = EASYGCICAP:New("Blue CAP Operations",AIRBASE.Caucasus.Kutaisi,"blue","Blue EWR") +-- +-- -- Add a CAP patrol point belonging to our airbase, we'll be at 30k ft doing 400 kn, initial direction 90 degrees (East), leg 20NM +-- mywing:AddPatrolPointCAP(AIRBASE.Caucasus.Kutaisi,ZONE:FindByName("Blue Zone 1"):GetCoordinate(),30000,400,90,20) +-- +-- -- Add a Squadron with template "Blue Sq1 M2000c", 20 airframes, skill good, Modex starting with 102 and skin "Vendee Jeanne" +-- mywing:AddSquadron("Blue Sq1 M2000c","CAP Kutaisi",AIRBASE.Caucasus.Kutaisi,20,AI.Skill.GOOD,102,"ec1.5_Vendee_Jeanne_clean") +-- +-- -- Add a couple of zones +-- -- We'll defend our border +-- mywing:AddAcceptZone(ZONE_POLYGON:New( "Blue Border", GROUP:FindByName( "Blue Border" ) )) +-- -- We'll attack intruders also here +-- mywing:AddAcceptZone(ZONE_POLYGON:New("Red Defense Zone", GROUP:FindByName( "Red Defense Zone" ))) +-- -- We'll leave the reds alone on their turf +-- mywing:AddRejectZone(ZONE_POLYGON:New( "Red Border", GROUP:FindByName( "Red Border" ) )) +-- +-- -- Optional - Draw the borders on the map so we see what's going on +-- -- Set up borders on map +-- local BlueBorder = ZONE_POLYGON:New( "Blue Border", GROUP:FindByName( "Blue Border" ) ) +-- BlueBorder:DrawZone(-1,{0,0,1},1,FillColor,FillAlpha,1,true) +-- local BlueNoGoZone = ZONE_POLYGON:New("Red Defense Zone", GROUP:FindByName( "Red Defense Zone" )) +-- BlueNoGoZone:DrawZone(-1,{1,1,0},1,FillColor,FillAlpha,2,true) +-- local BlueNoGoZone2 = ZONE_POLYGON:New( "Red Border", GROUP:FindByName( "Red Border" ) ) +-- BlueNoGoZone2:DrawZone(-1,{1,0,0},1,FillColor,FillAlpha,4,true) +-- +-- ### Add a second airwing with squads and own CAP point (optional) +-- +-- -- Set this up at Sukhumi +-- mywing:AddAirwing(AIRBASE.Caucasus.Sukhumi_Babushara,"Blue CAP Sukhumi") +-- -- CAP Point "Blue Zone 2" +-- mywing:AddPatrolPointCAP(AIRBASE.Caucasus.Sukhumi_Babushara,ZONE:FindByName("Blue Zone 2"):GetCoordinate(),30000,400,90,20) +-- +-- -- This one has two squadrons to choose from +-- mywing:AddSquadron("Blue Sq3 F16","CAP Sukhumi II",AIRBASE.Caucasus.Sukhumi_Babushara,20,AI.Skill.GOOD,402,"JASDF 6th TFS 43-8526 Skull Riders") +-- mywing:AddSquadron("Blue Sq2 F15","CAP Sukhumi I",AIRBASE.Caucasus.Sukhumi_Babushara,20,AI.Skill.GOOD,202,"390th Fighter SQN") +-- +-- ### Add a tanker (optional) +-- +-- -- **Note** If you need different tanker types, i.e. Boom and Drogue, set them up at different AirWings! +-- -- Add a tanker point +-- mywing:AddPatrolPointTanker(AIRBASE.Caucasus.Kutaisi,ZONE:FindByName("Blue Zone Tanker"):GetCoordinate(),20000,280,270,50) +-- -- Add a tanker squad +-- mywing:AddTankerSquadron("Blue Tanker","Tanker Ops Kutaisi",AIRBASE.Caucasus.Kutaisi,20,AI.Skill.EXCELLENT,602) +-- +-- # Fine-Tuning +-- +-- ## Change Defaults +-- +-- * @{#EASYGCICAP.SetDefaultResurrection}: Set how many seconds the AirWing stays inoperable after the AirWing STATIC HQ ist destroyed, default 900 secs. +-- * @{#EASYGCICAP.SetDefaultCAPSpeed}: Set how many knots the CAP flights should do (will be altitude corrected), default 300 kn. +-- * @{#EASYGCICAP.SetDefaultCAPAlt}: Set at which altitude (ASL) the CAP planes will fly, default 25,000 ft. +-- * @{#EASYGCICAP.SetDefaultCAPDirection}: Set the initial direction from the CAP point the planes will fly in degrees, default is 90°. +-- * @{#EASYGCICAP.SetDefaultCAPLeg}: Set the length of the CAP leg, default is 15 NM. +-- * @{#EASYGCICAP.SetDefaultCAPGrouping}: Set how many planes will be spawned per mission (CVAP/GCI), defaults to 2. +-- * @{#EASYGCICAP.SetDefaultMissionRange}: Set how many NM the planes can go from the home base, defaults to 100. +-- * @{#EASYGCICAP.SetDefaultNumberAlter5Standby}: Set how many planes will be spawned on cold standby (Alert5), default 2. +-- * @{#EASYGCICAP.SetDefaultEngageRange}: Set max engage range for CAP flights if they detect intruders, defaults to 50. +-- * @{#EASYGCICAP.SetMaxAliveMissions}: Set max parallel missions can be done (CAP+GCI+Alert5+Tanker), defaults to 6. +-- +-- +-- @field #EASYGCICAP +EASYGCICAP = { + ClassName = "EASYGCICAP", + overhead = 0.75, + capgrouping = 2, + airbasename = nil, + airbase = nil, + coalition = "blue", + alias = nil, + wings = {}, + Intel = nil, + resurrection = 900, + capspeed = 300, + capalt = 25000, + capdir = 45, + capleg = 15, + capgrouping = 2, + maxinterceptsize = 2, + missionrange = 100, + noaltert5 = 4, + ManagedAW = {}, + ManagedSQ = {}, + ManagedCP = {}, + ManagedTK = {}, + MaxAliveMissions = 6, + debug = true, + engagerange = 50, +} + +--- Internal Squadron data type +-- @type EASYGCICAP.Squad +-- @field #string TemplateName +-- @field #string SquadName +-- @field #string AirbaseName +-- @field #number AirFrames +-- @field #string Skill +-- @field #string Modex +-- @field #string Livery +-- @field #boolean Tanker + +--- Internal Wing data type +-- @type EASYGCICAP.Wing +-- @field #string AirbaseName +-- @field #string Alias +-- @field #string CapZoneName + +--- Internal CapPoint data type +-- @type EASYGCICAP.CapPoint +-- @field #string AirbaseName +-- @field Core.Point#COORDINATE Coordinate +-- @field #number Altitude +-- @field #number Speed +-- @field #number Heading +-- @field #number LegLength + +--- EASYGCICAP class version. +-- @field #string version +EASYGCICAP.version="0.0.4" + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- TODO list +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +-- TODO: TBD + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Constructor +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Create a new GCICAP Manager +-- @param #EASYGCICAP self +-- @param #string Alias +-- @param #string AirbaseName +-- @param #string Coalition +-- @param #string EWRName +-- @return #EASYGCICAP self +function EASYGCICAP:New(Alias, AirbaseName, Coalition, EWRName) + -- Inherit everything from FSM class. + local self=BASE:Inherit(self, FSM:New()) -- #EASYGCICAP + + -- defaults + self.alias = Alias or AirbaseName.." CAP Wing" + self.coalitionname = string.lower(Coalition) or "blue" + self.coalition = self.coaltitionname == "blue" and coalition.side.BLUE or coalition.side.RED + self.wings = {} + self.EWRName = EWRName or self.coalitionname.." EWR" + --self.CapZoneName = CapZoneName + self.airbasename = AirbaseName + self.airbase = AIRBASE:FindByName(self.airbasename) + self.BlueGoZoneSet = SET_ZONE:New() + self.BlueNoGoZoneSet = SET_ZONE:New() + self.resurrection = 900 + self.capspeed = 300 + self.capalt = 25000 + self.capdir = 90 + self.capleg = 15 + self.capgrouping = 2 + self.missionrange = 100 + self.noaltert5 = 2 + self.MaxAliveMissions = 6 + self.engagerange = 50 + + -- Set some string id for output to DCS.log file. + self.lid=string.format("EASYGCICAP %s | ", self.alias) + + -- Add FSM transitions. + -- From State --> Event --> To State + self:SetStartState("Stopped") + self:AddTransition("Stopped", "Start", "Running") + self:AddTransition("Running", "Stop", "Stopped") + self:AddTransition("*", "Status", "*") + + self:AddAirwing(self.airbasename,self.alias,self.CapZoneName) + + self:I(self.lid.."Created new instance (v"..self.version..")") + + self:__Start(math.random(6,12)) + + return self +end + +------------------------------------------------------------------------- +-- Functions +------------------------------------------------------------------------- + + +--- Set Maximum of alive missions to stop airplanes spamming the map +-- @param #EASYGCICAP self +-- @param #number Maxiumum Maxmimum number of parallel missions allowed. Count is Cap-Missions + Intercept-Missions + Alert5-Missionsm default is 6 +-- @return #EASYGCICAP self +function EASYGCICAP:SetMaxAliveMissions(Maxiumum) + self:I(self.lid.."SetDefaultResurrection") + self.MaxAliveMissions = Maxiumum or 6 + return self +end + +--- Add default time to resurrect Airwing building if destroyed +-- @param #EASYGCICAP self +-- @param #number Seconds Seconds, defaults to 900 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultResurrection(Seconds) + self:I(self.lid.."SetDefaultResurrection") + self.resurrection = Seconds or 900 + return self +end + +--- Set default CAP Speed in knots +-- @param #EASYGCICAP self +-- @param #number Speed Speed defaults to 300 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultCAPSpeed(Speed) + self:I(self.lid.."SetDefaultSpeed") + self.capspeed = Speed or 300 + return self +end + +--- Set default CAP Altitude in feet +-- @param #EASYGCICAP self +-- @param #number Altitude Altitude defaults to 25000 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultCAPAlt(Altitude) + self:I(self.lid.."SetDefaultAltitude") + self.capalt = Altitude or 25000 + return self +end + +--- Set default CAP lieg initial direction in degrees +-- @param #EASYGCICAP self +-- @param #number Direction Direction defaults to 90 (East) +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultCAPDirection(Direction) + self:I(self.lid.."SetDefaultDirection") + self.capdir = Direction or 90 + return self +end + +--- Set default leg length in NM +-- @param #EASYGCICAP self +-- @param #number Leg Leg defaults to 15 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultCAPLeg(Leg) + self:I(self.lid.."SetDefaultLeg") + self.capleg = Leg or 15 + return self +end + +--- Set default grouping, i.e. how many airplanes per CAP point +-- @param #EASYGCICAP self +-- @param #number Grouping Grouping defaults to 2 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultCAPGrouping(Grouping) + self:I(self.lid.."SetDefaultCAPGrouping") + self.capgrouping = Grouping or 2 + return self +end + +--- Set default range planes can fly from their homebase in NM +-- @param #EASYGCICAP self +-- @param #number Range Range defaults to 100 NM +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultMissionRange(Range) + self:I(self.lid.."SetDefaultMissionRange") + self.missionrange = Range or 100 + return self +end + +--- Set default number of airframes standing by for intercept tasks (visible on the airfield) +-- @param #EASYGCICAP self +-- @param #number Airframes defaults to 2 +-- @return #EASYGCICAP selfAirframes +function EASYGCICAP:SetDefaultNumberAlter5Standby(Airframes) + self:I(self.lid.."SetDefaultNumberAlter5Standby") + self.noaltert5 = math.abs(Airframes) or 2 + return self +end + +--- Set default engage range for intruders detected by CAP flights in NM. +-- @param #EASYGCICAP self +-- @param #number Range defaults to 50NM +-- @return #EASYGCICAP selfAirframes +function EASYGCICAP:SetDefaultEngageRange(Range) + self:I(self.lid.."SetDefaultNumberAlter5Standby") + self.engagerange = Range or 50 + return self +end + +--- Add an AirWing to the manager +-- @param #EASYGCICAP self +-- @param #string Airbasename +-- @param #string Alias +-- @return #EASYGCICAP self +function EASYGCICAP:AddAirwing(Airbasename, Alias) + self:I(self.lid.."AddAirwing "..Airbasename) + + -- Create Airwing data entry + local AWEntry = {} -- #EASYGCICAP.Wing + AWEntry.AirbaseName = Airbasename + AWEntry.Alias = Alias + --AWEntry.CapZoneName = CapZoneName + + self.ManagedAW[Airbasename] = AWEntry + + return self +end + +--- (Internal) Create actual AirWings from the list +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:_CreateAirwings() + self:I(self.lid.."_CreateAirwings") + for airbase,data in pairs(self.ManagedAW) do + local wing = data -- #EASYGCICAP.Wing + local afb = wing.AirbaseName + local alias = wing.Alias + --local cz = wing.CapZoneName + self:_AddAirwing(airbase,alias) + end + return self +end + +--- (internal) Create and add another AirWing to the manager +-- @param #EASYGCICAP self +-- @param #string Airbasename +-- @param #string Alias +-- @return #EASYGCICAP self +function EASYGCICAP:_AddAirwing(Airbasename, Alias) + self:I(self.lid.."_AddAirwing "..Airbasename) + + -- Create Airwing + local CAP_Wing = AIRWING:New(Airbasename,Alias) + CAP_Wing:SetReportOff() + CAP_Wing:SetMarker(false) + CAP_Wing:SetAirbase(AIRBASE:FindByName(Airbasename)) + CAP_Wing:SetRespawnAfterDestroyed() + CAP_Wing:SetNumberCAP(self.capgrouping) + CAP_Wing:SetNumberTankerBoom(1) + CAP_Wing:SetNumberTankerProbe(1) + --local PatrolCoordinateKutaisi = ZONE:New(CapZoneName):GetCoordinate() + --CAP_Wing:AddPatrolPointCAP(PatrolCoordinateKutaisi,self.capalt,UTILS.KnotsToAltKIAS(self.capspeed,self.capalt),self.capdir,self.capleg) + CAP_Wing:SetTakeoffHot() + CAP_Wing:SetLowFuelThreshold(0.3) + CAP_Wing.RandomAssetScore = math.random(50,100) + CAP_Wing:Start() + + local Intel = self.Intel + + function CAP_Wing:OnAfterFlightOnMission(From, Event, To, Flightgroup, Mission) + local flightgroup = Flightgroup -- Ops.FlightGroup#FLIGHTGROUP + --flightgroup:SetDespawnAfterLanding() + flightgroup:SetDespawnAfterHolding() + flightgroup:SetDestinationbase(AIRBASE:FindByName(Airbasename)) + flightgroup:GetGroup():CommandEPLRS(true,5) + flightgroup:SetEngageDetectedOn(self.engagerange,{"Air"},self.BlueGoZoneSet,self.BlueNoGoZoneSet) + flightgroup:GetGroup():OptionROTEvadeFire() + flightgroup:SetOutOfAAMRTB() + flightgroup:SetFuelLowRTB(true) + Intel:AddAgent(flightgroup) + --function flightgroup:OnAfterHolding(From,Event,To) + --self:ClearToLand(5) + --end + + end + + if self.noaltert5 > 0 then + local alert = AUFTRAG:NewALERT5(AUFTRAG.Type.INTERCEPT) + alert:SetRequiredAssets(self.noaltert5) + alert:SetRepeat(99) + CAP_Wing:AddMission(alert) + end + + self.wings[Airbasename] = { CAP_Wing, AIRBASE:FindByName(Airbasename):GetZone(), Airbasename } + + return self +end + +--- Add a CAP patrol point to a Wing +-- @param #EASYGCICAP self +-- @param #string AirbaseName Name of the Wing's airbase +-- @param Core.Point#COORDINATE Coordinate. +-- @param #number Altitude Defaults to 25000 feet. +-- @param #number Speed Defaults to 300 knots. +-- @param #number Heading Defaults to 90 degrees (East). +-- @param #number LegLength Defaults to 15 NM. +-- @return #EASYGCICAP self +function EASYGCICAP:AddPatrolPointCAP(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) + self:I(self.lid.."AddPatrolPointCAP "..Coordinate:ToStringLLDDM()) + local EntryCAP = {} -- #EASYGCICAP.CapPoint + EntryCAP.AirbaseName = AirbaseName + EntryCAP.Coordinate = Coordinate + EntryCAP.Altitude = Altitude or 25000 + EntryCAP.Speed = Speed or 300 + EntryCAP.Heading = Heading or 90 + EntryCAP.LegLength = LegLength or 15 + self.ManagedCP[#self.ManagedCP+1] = EntryCAP + if self.debug then + local mark = MARKER:New(Coordinate,self.lid.."Patrol Point"):ToAll() + end + return self +end + +--- Add a TANKER patrol point to a Wing +-- @param #EASYGCICAP self +-- @param #string AirbaseName Name of the Wing's airbase +-- @param Core.Point#COORDINATE Coordinate. +-- @param #number Altitude Defaults to 25000 feet. +-- @param #number Speed Defaults to 300 knots. +-- @param #number Heading Defaults to 90 degrees (East). +-- @param #number LegLength Defaults to 15 NM. +-- @return #EASYGCICAP self +function EASYGCICAP:AddPatrolPointTanker(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) + self:I(self.lid.."AddPatrolPointTanker "..Coordinate:ToStringLLDDM()) + local EntryCAP = {} -- #EASYGCICAP.CapPoint + EntryCAP.AirbaseName = AirbaseName + EntryCAP.Coordinate = Coordinate + EntryCAP.Altitude = Altitude or 25000 + EntryCAP.Speed = Speed or 300 + EntryCAP.Heading = Heading or 90 + EntryCAP.LegLength = LegLength or 15 + self.ManagedTK[#self.ManagedTK+1] = EntryCAP + if self.debug then + local mark = MARKER:New(Coordinate,self.lid.."Patrol Point Tanker"):ToAll() + end + return self +end + +--- (Internal) Set actual Tanker Points from the list +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:_SetTankerPatrolPoints() + self:I(self.lid.."_SetTankerPatrolPoints") + for _,_data in pairs(self.ManagedTK) do + local data = _data --#EASYGCICAP.CapPoint + local Wing = self.wings[data.AirbaseName][1] -- Ops.AirWing#AIRWING + local Coordinate = data.Coordinate + local Altitude = data.Altitude + local Speed = data.Speed + local Heading = data.Heading + local LegLength = data.LegLength + Wing:AddPatrolPointTANKER(Coordinate,Altitude,Speed,Heading,LegLength) + end + + return self +end + +--- (Internal) Set actual PatrolPoints from the list +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:_SetCAPPatrolPoints() + self:I(self.lid.."_SetCAPPatrolPoints") + for _,_data in pairs(self.ManagedCP) do + local data = _data --#EASYGCICAP.CapPoint + local Wing = self.wings[data.AirbaseName][1] -- Ops.AirWing#AIRWING + local Coordinate = data.Coordinate + local Altitude = data.Altitude + local Speed = data.Speed + local Heading = data.Heading + local LegLength = data.LegLength + Wing:AddPatrolPointCAP(Coordinate,Altitude,Speed,Heading,LegLength) + end + + return self +end + +--- (Internal) Add a CAP patrol point to a Wing +-- @param #EASYGCICAP self +-- @param #string AirbaseName Name of the Wing's airbase +-- @param Core.Point#COORDINATE Coordinate. +-- @param #number Altitude Defaults to 25000 feet. +-- @param #number Speed Defaults to 300 knots. +-- @param #number Heading Defaults to 90 degrees (East). +-- @param #number LegLength Defaults to 15 NM. +-- @return #EASYGCICAP self +function EASYGCICAP:_AddPatrolPointCAP(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) + self:I(self.lid.."_AddPatrolPointCAP") + local airbasename = AirbaseName or self.airbasename + local coordinate = Coordinate + local Altitude = Altitude or 25000 + local Speed = Speed or 300 + local Heading = Heading or 90 + local LegLength = LegLength or 15 + local wing = self.wings[airbasename][1] -- Ops.AirWing#AIRWING + wing:AddPatrolPointCAP(coordinate,Altitude,Speed,Heading,LegLength) + return self +end + +--- (Internal) Create actual Squadrons from the list +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:_CreateSquads() + self:I(self.lid.."_CreateSquads") + for name,data in pairs(self.ManagedSQ) do + local squad = data -- #EASYGCICAP.Squad + local SquadName = name + local TemplateName = squad.TemplateName + local AirbaseName = squad.AirbaseName + local AirFrames = squad.AirFrames + local Skill = squad.Skill + local Modex = squad.Modex + local Livery = squad.Livery + if squad.Tanker then + self:_AddTankerSquadron(TemplateName,SquadName,AirbaseName,AirFrames,Skill,Modex,Livery) + else + self:_AddSquadron(TemplateName,SquadName,AirbaseName,AirFrames,Skill,Modex,Livery) + end + end + return self +end + +--- Add a Squadron to an Airwing of the manager +-- @param #EASYGCICAP self +-- @param #string TemplateName Name of the group template. +-- @param #string SquadName Squadron name - must be unique! +-- @param #string AirbaseName Name of the airbase the airwing resides on, e.g. AIRBASE.Caucasus.Kutaisi +-- @param #number AirFrames Number of available airframes, e.g. 20. +-- @param #string Skill(optional) Skill level, e.g. AI.Skill.AVERAGE +-- @param #string Modex (optional) Modex to be used,e.g. 402. +-- @param #string Livery (optional) Livery name to be used. +-- @return #EASYGCICAP self +function EASYGCICAP:AddSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) + self:I(self.lid.."AddSquadron "..SquadName) + -- Add Squadron Data + local EntrySQ = {} -- #EASYGCICAP.Squad + EntrySQ.TemplateName = TemplateName + EntrySQ.SquadName = SquadName + EntrySQ.AirbaseName = AirbaseName + EntrySQ.AirFrames = AirFrames or 20 + EntrySQ.Skill = Skill or AI.Skill.AVERAGE + EntrySQ.Modex = Modex or 402 + EntrySQ.Livery = Livery + + self.ManagedSQ[SquadName] = EntrySQ + + return self +end + +--- Add a Tanker Squadron to an Airwing of the manager +-- @param #EASYGCICAP self +-- @param #string TemplateName Name of the group template. +-- @param #string SquadName Squadron name - must be unique! +-- @param #string AirbaseName Name of the airbase the airwing resides on, e.g. AIRBASE.Caucasus.Kutaisi +-- @param #number AirFrames Number of available airframes, e.g. 20. +-- @param #string Skill(optional) Skill level, e.g. AI.Skill.AVERAGE +-- @param #string Modex (optional) Modex to be used,e.g. 402. +-- @param #string Livery (optional) Livery name to be used. +-- @return #EASYGCICAP self +function EASYGCICAP:AddTankerSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) + self:I(self.lid.."AddTankerSquadron "..SquadName) + -- Add Squadron Data + local EntrySQ = {} -- #EASYGCICAP.Squad + EntrySQ.TemplateName = TemplateName + EntrySQ.SquadName = SquadName + EntrySQ.AirbaseName = AirbaseName + EntrySQ.AirFrames = AirFrames or 20 + EntrySQ.Skill = Skill or AI.Skill.AVERAGE + EntrySQ.Modex = Modex or 402 + EntrySQ.Livery = Livery + EntrySQ.Tanker = true + + self.ManagedSQ[SquadName] = EntrySQ + + return self +end + +--- (Internal) Add a Squadron to an Airwing of the manager +-- @param #EASYGCICAP self +-- @param #string TemplateName Name of the group template. +-- @param #string SquadName Squadron name - must be unique! +-- @param #string AirbaseName Name of the airbase the airwing resides on, e.g. AIRBASE.Caucasus.Kutaisi +-- @param #number AirFrames Number of available airframes, e.g. 20. +-- @param #string Skill(optional) Skill level, e.g. AI.Skill.AVERAGE +-- @param #string Modex (optional) Modex to be used,e.g. 402. +-- @param #string Livery (optional) Livery name to be used. +-- @return #EASYGCICAP self +function EASYGCICAP:_AddSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) + self:I(self.lid.."_AddSquadron "..SquadName) + -- Add Squadrons + local Squadron_One = SQUADRON:New(TemplateName,AirFrames,SquadName) + Squadron_One:AddMissionCapability({AUFTRAG.Type.CAP, AUFTRAG.Type.GCICAP, AUFTRAG.Type.INTERCEPT, AUFTRAG.Type.ALERT5}) + --Squadron_One:SetFuelLowRefuel(true) + Squadron_One:SetFuelLowThreshold(0.3) + Squadron_One:SetTurnoverTime(10,20) + Squadron_One:SetModex(Modex) + Squadron_One:SetLivery(Livery) + Squadron_One:SetSkill(Skill or AI.Skill.AVERAGE) + Squadron_One:SetMissionRange(self.missionrange) + + local wing = self.wings[AirbaseName][1] -- Ops.AirWing#AIRWING + + wing:AddSquadron(Squadron_One) + wing:NewPayload(TemplateName,-1,{AUFTRAG.Type.CAP, AUFTRAG.Type.GCICAP, AUFTRAG.Type.INTERCEPT, AUFTRAG.Type.ALERT5},75) + + return self +end + +--- (Internal) Add a Tanker Squadron to an Airwing of the manager +-- @param #EASYGCICAP self +-- @param #string TemplateName Name of the group template. +-- @param #string SquadName Squadron name - must be unique! +-- @param #string AirbaseName Name of the airbase the airwing resides on, e.g. AIRBASE.Caucasus.Kutaisi +-- @param #number AirFrames Number of available airframes, e.g. 20. +-- @param #string Skill(optional) Skill level, e.g. AI.Skill.AVERAGE +-- @param #string Modex (optional) Modex to be used,e.g. 402. +-- @param #string Livery (optional) Livery name to be used. +-- @return #EASYGCICAP self +function EASYGCICAP:_AddTankerSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) + self:I(self.lid.."_AddTankerSquadron "..SquadName) + -- Add Squadrons + local Squadron_One = SQUADRON:New(TemplateName,AirFrames,SquadName) + Squadron_One:AddMissionCapability({AUFTRAG.Type.TANKER}) + --Squadron_One:SetFuelLowRefuel(true) + Squadron_One:SetFuelLowThreshold(0.3) + Squadron_One:SetTurnoverTime(10,20) + Squadron_One:SetModex(Modex) + Squadron_One:SetLivery(Livery) + Squadron_One:SetSkill(Skill or AI.Skill.AVERAGE) + Squadron_One:SetMissionRange(self.missionrange) + + local wing = self.wings[AirbaseName][1] -- Ops.AirWing#AIRWING + + wing:AddSquadron(Squadron_One) + wing:NewPayload(TemplateName,-1,{AUFTRAG.Type.TANKER},75) + + return self +end + +--- Add a zone to the accepted zones set. +-- @param #EASYGCICAP self +-- @param Core.Zone#ZONE_BASE Zone +-- @return #EASYGCICAP self +function EASYGCICAP:AddAcceptZone(Zone) + self:I(self.lid.."AddAcceptZone0") + self.BlueGoZoneSet:AddZone(Zone) + return self +end + +--- Add a zone to the rejected zones set. +-- @param #EASYGCICAP self +-- @param Core.Zone#ZONE_BASE Zone +-- @return #EASYGCICAP self +function EASYGCICAP:AddRejectZone(Zone) + self:I(self.lid.."AddRejectZone") + self.BlueNoGoZoneSet:AddZone(Zone) + return self +end + +--- (Internal) Start detection. +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:_StartIntel() + self:I(self.lid.."_StartIntel") + -- Border GCI Detection + local BlueAir_DetectionSetGroup = SET_GROUP:New() + BlueAir_DetectionSetGroup:FilterPrefixes( { self.EWRName } ) + BlueAir_DetectionSetGroup:FilterStart() + + -- Intel type detection + local BlueIntel = INTEL:New(BlueAir_DetectionSetGroup,self.coalitionname, self.EWRName) + BlueIntel:SetClusterAnalysis(true,false,false) + BlueIntel:SetForgetTime(300) + BlueIntel:SetAcceptZones(self.BlueGoZoneSet) + BlueIntel:SetRejectZones(self.BlueNoGoZoneSet) + BlueIntel:SetVerbosity(0) + BlueIntel:Start() + + if self.debug then + BlueIntel.debug = true + end + + -- Here, we'll decide if we need to launch an intercepting flight, and from where + + local overhead = self.overhead + local capspeed = self.capspeed + 100 + local capalt = self.capalt + local maxsize = self.maxinterceptsize + + local wings = self.wings + local ctlpts = self.ManagedCP + local MaxAliveMissions = self.MaxAliveMissions * self.capgrouping + + function BlueIntel:OnAfterNewCluster(From,Event,To,Cluster) + -- Aircraft? + if Cluster.ctype ~= INTEL.Ctype.AIRCRAFT then return end + -- Threatlevel 0..10 + local contact = self:GetHighestThreatContact(Cluster) + local name = contact.groupname --#string + local threat = contact.threatlevel --#number + local position = self:CalcClusterFuturePosition(Cluster,300) + -- calculate closest zone + local bestdistance = 2000*1000 -- 2000km + local targetairwing = nil -- Ops.AirWing#AIRWING + local targetawname = "" -- #string + local clustersize = self:ClusterCountUnits(Cluster) or 1 + local wingsize = math.abs(overhead * (clustersize+1)) + if wingsize > maxsize then wingsize = maxsize end + if (not Cluster.mission) and (wingsize > 0) then + MESSAGE:New(string.format("**** %s Interceptors need wingsize %d", UTILS.GetCoalitionName(self.coalition), wingsize),15,"CAPGCI"):ToAllIf(self.debug):ToLog() + for _,_data in pairs (wings) do + local airwing = _data[1] -- Ops.AirWing#AIRWING + local zone = _data[2] -- Core.Zone#ZONE + local zonecoord = zone:GetCoordinate() + local name = _data[3] -- #string + local distance = position:DistanceFromPointVec2(zonecoord) + local airframes = airwing:CountAssets(true) + if distance < bestdistance and airframes >= wingsize then + bestdistance = distance + targetairwing = airwing + targetawname = name + end + end + for _,_data in pairs (ctlpts) do + --local airwing = _data[1] -- Ops.AirWing#AIRWING + --local zone = _data[2] -- Core.Zone#ZONE + --local zonecoord = zone:GetCoordinate() + --local name = _data[3] -- #string + + local data = _data -- #EASYGCICAP.CapPoint + local name = data.AirbaseName + local zonecoord = data.Coordinate + local airwing = wings[name][1] + + local distance = position:DistanceFromPointVec2(zonecoord) + local airframes = airwing:CountAssets(true) + if distance < bestdistance and airframes >= wingsize then + bestdistance = distance + targetairwing = airwing + targetawname = name + end + end + local text = string.format("Closest Airwing is %s", targetawname) + local m = MESSAGE:New(text,10,"CAPGCI"):ToAll():ToLog() + -- Do we have a matching airwing? + if targetairwing then + local AssetCount = targetairwing:CountAssetsOnMission(MissionTypes,Cohort) + --local AssetCount = targetairwing:GetAssetsOnMission({AUFTRAG.Type.INTERCEPT}) + -- Enough airframes on mission already? + self:I(self.lid.." Assets on Mission "..AssetCount) + if AssetCount <= MaxAliveMissions then + local repeats = math.random(1,2) + local InterceptAuftrag = AUFTRAG:NewINTERCEPT(contact.group) + :SetMissionRange(150) + :SetPriority(1,true,1) + :SetRequiredAssets(wingsize) + :SetRepeatOnFailure(repeats) + :SetMissionSpeed(UTILS.KnotsToAltKIAS(capspeed,capalt)) + :SetMissionAltitude(capalt) + targetairwing:AddMission(InterceptAuftrag) + Cluster.mission = InterceptAuftrag + end + else + MESSAGE:New("**** Not enough airframes available or max mission limit reached!",15,"CAPGCI"):ToAllIf(self.debug):ToLog() + end + end + end +self.Intel = BlueIntel +return self +end + +------------------------------------------------------------------------- +-- FSM Functions +------------------------------------------------------------------------- + +--- (Internal) FSM Function onafterStart +-- @param #EASYGCICAP self +-- @param #string From +-- @param #string Event +-- @param #string To +-- @return #EASYGCICAP self +function EASYGCICAP:onafterStart(From,Event,To) + self:I({From,Event,To}) + self:_StartIntel() + self:_CreateAirwings() + self:_CreateSquads() + self:_SetCAPPatrolPoints() + self:_SetTankerPatrolPoints() + self:__Status(-10) + return self +end + +--- (Internal) FSM Function onbeforeStatus +-- @param #EASYGCICAP self +-- @param #string From +-- @param #string Event +-- @param #string To +-- @return #EASYGCICAP self +function EASYGCICAP:onbeforeStatus(From,Event,To) + self:T({From,Event,To}) + if self:GetState() == "Stopped" then return false end + return self +end + +--- (Internal) FSM Function onafterStatus +-- @param #EASYGCICAP self +-- @param #string From +-- @param #string Event +-- @param #string To +-- @return #EASYGCICAP self +function EASYGCICAP:onafterStatus(From,Event,To) + self:I({From,Event,To}) + -- Gather Some Stats + local function counttable(tbl) + local count = 0 + for _,_data in pairs(tbl) do + count = count + 1 + end + return count + end + local wings = counttable(self.ManagedAW) + local squads = counttable(self.ManagedSQ) + local caps = counttable(self.ManagedCP) + local assets = 0 + local instock = 0 + for _,_wing in pairs(self.wings) do + local count = _wing[1]:CountAssetsOnMission(MissionTypes,Cohort) + local count2 = _wing[1]:CountAssets(true,MissionTypes,Attributes) + assets = assets + count + instock = instock + count2 + end + if self.debug then + self:I(self.lid.."Wings: "..wings.." | Squads: "..squads.." | CapPoints: "..caps.." | Assets on Mission: "..assets.." | Assets in Stock: "..instock) + end + self:__Status(30) + return self +end + +--- (Internal) FSM Function onafterStop +-- @param #EASYGCICAP self +-- @param #string From +-- @param #string Event +-- @param #string To +-- @return #EASYGCICAP self +function EASYGCICAP:onafterStop(From,Event,To) + self:I({From,Event,To}) + self.Intel:Stop() + return self +end diff --git a/Moose Setup/Moose.files b/Moose Setup/Moose.files index 7ce1dbbcb..eb513c320 100644 --- a/Moose Setup/Moose.files +++ b/Moose Setup/Moose.files @@ -106,6 +106,7 @@ Ops/Operation.lua Ops/FlightControl.lua Ops/PlayerTask.lua Ops/PlayerRecce.lua +Ops/EasyGCICAP.lua AI/AI_Balancer.lua AI/AI_Air.lua From c4e8ad50c87284272b0f363a20ce7ede6fc9169a Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 26 Sep 2023 13:29:09 +0200 Subject: [PATCH 4/9] Docu adds --- Moose Development/Moose/Ops/EasyGCICAP.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Ops/EasyGCICAP.lua b/Moose Development/Moose/Ops/EasyGCICAP.lua index 935e517a3..e3cc625d8 100644 --- a/Moose Development/Moose/Ops/EasyGCICAP.lua +++ b/Moose Development/Moose/Ops/EasyGCICAP.lua @@ -8,14 +8,14 @@ ------------------------------------------------------------------------- -- Date: September 2023 ------------------------------------------------------------------------- ----@diagnostic disable: cast-local-type +-- --- **Ops** - Easy GCI & CAP Manager -- -- === -- -- **Main Features:** -- --- * Automatically create and manage A2A CAP/GCI defenses using an @{Ops.AirWing#AIRWING} and Squadrons for one coalition +-- * Automatically create and manage A2A CAP/GCI defenses using an AirWing and Squadrons for one coalition -- * Easy set-up -- * Add additional AirWings on other airbases -- * Each wing can have more than one Squadron - tasking to Squadrons is done on a random basis per AirWing From dfc7f17308c58795ad54485f7a0c961684391953 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 27 Sep 2023 10:57:12 +0200 Subject: [PATCH 5/9] NAVYGROUP - Improved heading into wind --- Moose Development/Moose/Ops/NavyGroup.lua | 123 ++++++++++++++++++---- 1 file changed, 104 insertions(+), 19 deletions(-) diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index a69e5f627..0b7823551 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -90,7 +90,7 @@ NAVYGROUP = { --- NavyGroup version. -- @field #string version -NAVYGROUP.version="1.0.1" +NAVYGROUP.version="1.0.2" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -586,7 +586,7 @@ end -- @param #string stoptime Stop time, e.g. "9:00" for nine o'clock. Default 90 minutes after start time. -- @param #number speed Wind speed on deck in knots during turn into wind leg. Default 20 knots. -- @param #boolean uturn If `true` (or `nil`), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint. --- @param #number offset Offset angle in degrees, e.g. to account for an angled runway. Default 0 deg. +-- @param #number offset Offset angle clock-wise in degrees, *e.g.* to account for an angled runway. Default 0 deg. Use around -9.1° for US carriers. -- @return #NAVYGROUP.IntoWind Turn into window data table. function NAVYGROUP:AddTurnIntoWind(starttime, stoptime, speed, uturn, offset) @@ -1277,25 +1277,20 @@ end -- @param #NAVYGROUP.IntoWind Into wind parameters. function NAVYGROUP:onafterTurnIntoWind(From, Event, To, IntoWind) - IntoWind.Heading=self:GetHeadingIntoWind(IntoWind.Offset) + -- Calculate heading and speed of ship. + local heading, speed=self:GetHeadingIntoWind(IntoWind.Offset, IntoWind.Speed) + IntoWind.Heading=heading IntoWind.Open=true + -- Get coordinate. IntoWind.Coordinate=self:GetCoordinate(true) + -- Set current into wind parameters. self.intowind=IntoWind - - -- Wind speed in m/s. - local _,vwind=self:GetWind() - - -- Convert to knots. - vwind=UTILS.MpsToKnots(vwind) - - -- Speed of carrier relative to wind but at least 4 knots. - local speed=math.max(IntoWind.Speed-vwind, 4) -- Debug info. - self:T(self.lid..string.format("Steaming into wind: Heading=%03d Speed=%.1f Vwind=%.1f Vtot=%.1f knots, Tstart=%d Tstop=%d", IntoWind.Heading, speed, vwind, speed+vwind, IntoWind.Tstart, IntoWind.Tstop)) + self:T(self.lid..string.format("Steaming into wind: Heading=%03d Speed=%.1f, Tstart=%d Tstop=%d", IntoWind.Heading, speed, IntoWind.Tstart, IntoWind.Tstop)) local distance=UTILS.NMToMeters(1000) @@ -2055,15 +2050,16 @@ end --- Get wind direction and speed at current position. -- @param #NAVYGROUP self +-- @param #number Altitude Altitude in meters above main sea level at which the wind is calculated. Default 18 meters. -- @return #number Direction the wind is blowing **from** in degrees. -- @return #number Wind speed in m/s. -function NAVYGROUP:GetWind() +function NAVYGROUP:GetWind(Altitude) -- Current position of the carrier or input. local coord=self:GetCoordinate() - -- Wind direction and speed. By default at 50 meters ASL. - local Wdir, Wspeed=coord:GetWind(50) + -- Wind direction and speed. By default at 18 meters ASL. + local Wdir, Wspeed=coord:GetWind(Altitude or 18) return Wdir, Wspeed end @@ -2072,7 +2068,7 @@ end -- @param #NAVYGROUP self -- @param #number Offset Offset angle in degrees, e.g. to account for an angled runway. -- @return #number Carrier heading in degrees. -function NAVYGROUP:GetHeadingIntoWind(Offset) +function NAVYGROUP:GetHeadingIntoWind_old(Offset) Offset=Offset or 0 @@ -2086,15 +2082,104 @@ function NAVYGROUP:GetHeadingIntoWind(Offset) if vwind<0.1 then intowind=self:GetHeading() end - + -- Adjust negative values. if intowind<0 then intowind=intowind+360 end - + return intowind end + +--- Get heading of group into the wind. This minimizes the cross wind for an angled runway. +-- Implementation based on [Mags & Bami](https://magwo.github.io/carrier-cruise/) work. +-- @param #NAVYGROUP self +-- @param #number Offset Offset angle in degrees, e.g. to account for an angled runway. +-- @param #number vdeck Desired wind speed on deck in Knots. +-- @return #number Carrier heading in degrees. +function NAVYGROUP:GetHeadingIntoWind(Offset, vdeck) + + -- Default offset angle. + Offset=Offset or 0 + + -- Get direction the wind is blowing from. + local windfrom, vwind=self:GetWind(18) + + -- Convert wind speed to knots. + vwind=UTILS.MpsToKnots(vwind) + + -- Wind to in knots. + local windto=(windfrom+180)%360 + + -- Offset angle in rad. We also define the rotation to be clock-wise, which requires a minus sign. + local alpha=math.rad(-Offset) + + -- Ships min/max speed. + local Vmin=4 + local Vmax=UTILS.KmphToKnots(self.speedMax) + + -- Constant. + local C = math.sqrt(math.cos(alpha)^2 / math.sin(alpha)^2 + 1) + + + -- Upper limit of desired speed due to max boat speed. + local vdeckMax=vwind + math.cos(alpha) * Vmax + + -- Lower limit of desired speed due to min boat speed. + local vdeckMin=vwind + math.cos(alpha) * Vmin + + + -- Speed of ship so it matches the desired speed. + local v=0 + + -- Angle wrt. to wind TO-direction + local theta=0 + + if vdeck>vdeckMax then + -- Boat cannot go fast enough + + -- Set max speed. + v=Vmax + + -- Calculate theta. + theta = math.asin(v/(vwind*C)) - math.asin(-1/C) + + elseif vdeckvwind then + -- Too little wind + + -- Set theta to 90° + theta=math.pi/2 + + -- Set speed. + v = math.sqrt(vdeck^2 - vwind^2) + + else + -- Normal case + theta = math.asin(vdeck * math.sin(alpha) / vwind) + v = vdeck * math.cos(alpha) - vwind * math.cos(theta) + end + + + -- Ship heading so cross wind is min for the given wind. + local intowind = (540 + (windto + math.deg(theta) )) % 360 + + -- Debug info. + self:T(self.lid..string.format("Heading into Wind: vship=%.1f, vwind=%.1f, WindTo=%03d°, Theta=%03d°, Heading=%03d", v, vwind, windto, theta, intowind)) + + return intowind, v +end + + --- Find free path to next waypoint. -- @param #NAVYGROUP self -- @return #boolean If true, a path was found. From 912c162eee594c021e7b183721c8afce90c8e27e Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 27 Sep 2023 15:41:52 +0200 Subject: [PATCH 6/9] Logic fixes for GetRandomCoordinateWithoutBuildings() --- Moose Development/Moose/Core/Zone.lua | 89 +++++++++++++++++++-------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index f38fe83c4..2d2ccaecb 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -53,7 +53,8 @@ -- @module Core.Zone -- @image Core_Zones.JPG ---- @type ZONE_BASE +--- +-- @type ZONE_BASE -- @field #string ZoneName Name of the zone. -- @field #number ZoneProbability A value between 0 and 1. 0 = 0% and 1 = 100% probability. -- @field #number DrawID Unique ID of the drawn zone on the F10 map. @@ -195,7 +196,7 @@ end --- Returns if a PointVec2 is within the zone. (Name is misleading, actually takes a #COORDINATE) -- @param #ZONE_BASE self --- @param Core.Point#COORDINATE PointVec2 The coordinate to test. +-- @param Core.Point#COORDINATE Coordinate The coordinate to test. -- @return #boolean true if the PointVec2 is within the zone. function ZONE_BASE:IsPointVec2InZone( Coordinate ) local InZone = self:IsVec2InZone( Coordinate:GetVec2() ) @@ -953,7 +954,7 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories ) local Include = false if not UnitCategories then - -- Anythink found is included. + -- Anything found is included. Include = true else -- Check if found object is in specified categories. @@ -984,9 +985,9 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories ) if ObjectCategory == Object.Category.SCENERY then local SceneryType = ZoneObject:getTypeName() local SceneryName = ZoneObject:getName() - --BASE:I("SceneryType "..SceneryType.."SceneryName"..SceneryName) + --BASE:I("SceneryType "..SceneryType.." SceneryName "..tostring(SceneryName)) self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {} - self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( SceneryName, ZoneObject ) + self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( tostring(SceneryName), ZoneObject) table.insert(self.ScanData.SceneryTable,self.ScanData.Scenery[SceneryType][SceneryName] ) self:T( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } ) end @@ -1442,8 +1443,11 @@ function ZONE_RADIUS:GetRandomCoordinateWithoutBuildings(inner,outer,distance,ma local T1 = timer.getTime() local buildings = {} + local buildingzones = {} + if self.ScanData and self.ScanData.BuildingCoordinates then buildings = self.ScanData.BuildingCoordinates + buildingzones = self.ScanData.BuildingZones else -- build table of buildings coordinates for _,_object in pairs (objects) do @@ -1455,28 +1459,32 @@ function ZONE_RADIUS:GetRandomCoordinateWithoutBuildings(inner,outer,distance,ma MARKER:New(scenery:GetCoordinate(),"Building"):ToAll() end buildings[#buildings+1] = scenery:GetCoordinate() + local bradius = scenery:GetBoundingRadius() or dist + local bzone = ZONE_RADIUS:New("Building-"..math.random(1,100000),scenery:GetVec2(),bradius,false) + buildingzones[#buildingzones+1] = bzone + --bzone:DrawZone(-1,{1,0,0},Alpha,FillColor,FillAlpha,1,ReadOnly) end end end self.ScanData.BuildingCoordinates = buildings + self.ScanData.BuildingZones = buildingzones end -- max 1000 tries local rcoord = nil - local found = false + local found = true local iterations = 0 for i=1,1000 do iterations = iterations + 1 rcoord = self:GetRandomCoordinate(inner,outer) - found = false - for _,_coord in pairs (buildings) do - local coord = _coord -- Core.Point#COORDINATE + found = true + for _,_coord in pairs (buildingzones) do + local zone = _coord -- Core.Zone#ZONE_RADIUS -- keep >50m dist from buildings - if coord:Get3DDistance(rcoord) > dist then - found = true - else + if zone:IsPointVec2InZone(rcoord) then found = false + break end end if found then @@ -1488,15 +1496,43 @@ function ZONE_RADIUS:GetRandomCoordinateWithoutBuildings(inner,outer,distance,ma end end + if not found then + -- max 1000 tries + local rcoord = nil + local found = true + local iterations = 0 + + for i=1,1000 do + iterations = iterations + 1 + rcoord = self:GetRandomCoordinate(inner,outer) + found = true + for _,_coord in pairs (buildings) do + local coord = _coord -- Core.Point#COORDINATE + -- keep >50m dist from buildings + if coord:Get3DDistance(rcoord) < dist then + found = false + end + end + if found then + -- we have a winner! + if markfinal then + MARKER:New(rcoord,"FREE"):ToAll() + end + break + end + end + end + T1=timer.getTime() - self:T(string.format("Found a coordinate: %s | Iterations: %d | Time: %d",tostring(found),iterations,T1-T0)) + self:T(string.format("Found a coordinate: %s | Iterations: %d | Time: %.3f",tostring(found),iterations,T1-T0)) if found then return rcoord else return nil end end ---- @type ZONE +--- +-- @type ZONE -- @extends #ZONE_RADIUS @@ -1580,8 +1616,8 @@ function ZONE:FindByName( ZoneName ) end - ---- @type ZONE_UNIT +--- +-- @type ZONE_UNIT -- @field Wrapper.Unit#UNIT ZoneUNIT -- @extends Core.Zone#ZONE_RADIUS @@ -1616,7 +1652,11 @@ function ZONE_UNIT:New( ZoneName, ZoneUNIT, Radius, Offset) if (Offset.dx or Offset.dy) and (Offset.rho or Offset.theta) then error("Cannot use (dx, dy) with (rho, theta)") end + end + local self = BASE:Inherit( self, ZONE_RADIUS:New( ZoneName, ZoneUNIT:GetVec2(), Radius, true ) ) + + if Offset then self.dy = Offset.dy or 0.0 self.dx = Offset.dx or 0.0 self.rho = Offset.rho or 0.0 @@ -1624,8 +1664,6 @@ function ZONE_UNIT:New( ZoneName, ZoneUNIT, Radius, Offset) self.relative_to_unit = Offset.relative_to_unit or false end - local self = BASE:Inherit( self, ZONE_RADIUS:New( ZoneName, ZoneUNIT:GetVec2(), Radius, true ) ) - self:F( { ZoneName, ZoneUNIT:GetVec2(), Radius } ) self.ZoneUNIT = ZoneUNIT @@ -1721,7 +1759,8 @@ function ZONE_UNIT:GetVec3( Height ) return Vec3 end ---- @type ZONE_GROUP +--- +-- @type ZONE_GROUP -- @extends #ZONE_RADIUS @@ -1807,7 +1846,8 @@ function ZONE_GROUP:GetRandomPointVec2( inner, outer ) end ---- @type ZONE_POLYGON_BASE +--- +-- @type ZONE_POLYGON_BASE -- @field #ZONE_POLYGON_BASE.ListVec2 Polygon The polygon defined by an array of @{DCS#Vec2}. -- @extends #ZONE_BASE @@ -2456,7 +2496,8 @@ function ZONE_POLYGON_BASE:Boundary(Coalition, Color, Radius, Alpha, Segments, C return self end ---- @type ZONE_POLYGON +--- +-- @type ZONE_POLYGON -- @extends #ZONE_POLYGON_BASE @@ -2584,7 +2625,7 @@ function ZONE_POLYGON:Scan( ObjectCategories, UnitCategories ) local minmarkcoord = COORDINATE:NewFromVec3(minVec3) local maxmarkcoord = COORDINATE:NewFromVec3(maxVec3) local ZoneRadius = minmarkcoord:Get2DDistance(maxmarkcoord)/2 - +-- self:I("Scan Radius:" ..ZoneRadius) local CenterVec3 = self:GetCoordinate():GetVec3() --[[ this a bit shaky in functionality it seems @@ -2907,7 +2948,7 @@ end do -- ZONE_ELASTIC - --- @type ZONE_ELASTIC + -- @type ZONE_ELASTIC -- @field #table points Points in 2D. -- @field #table setGroups Set of GROUPs. -- @field #table setOpsGroups Set of OPSGROUPS. @@ -3107,7 +3148,7 @@ end do -- ZONE_AIRBASE - --- @type ZONE_AIRBASE + -- @type ZONE_AIRBASE -- @field #boolean isShip If `true`, airbase is a ship. -- @field #boolean isHelipad If `true`, airbase is a helipad. -- @field #boolean isAirdrome If `true`, airbase is an airdrome. From 5dc57369764f6626b3e3b16a1a497f4be0096d0a Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 27 Sep 2023 18:07:50 +0200 Subject: [PATCH 7/9] #EasyGCICAP * Added success criteria if intruder leaves monitored zones --- Moose Development/Moose/Ops/EasyGCICAP.lua | 147 +++++++++++++++------ 1 file changed, 104 insertions(+), 43 deletions(-) diff --git a/Moose Development/Moose/Ops/EasyGCICAP.lua b/Moose Development/Moose/Ops/EasyGCICAP.lua index e3cc625d8..5d1d4c0a8 100644 --- a/Moose Development/Moose/Ops/EasyGCICAP.lua +++ b/Moose Development/Moose/Ops/EasyGCICAP.lua @@ -57,6 +57,10 @@ -- @field #table ManagedTK -- @field #number MaxAliveMissions -- @field #boolean debug +-- @field #number repeatsonfailure +-- @field Core.Set#SET_ZONE GoZoneSet +-- @field Core.Set#SET_ZONE NoGoZoneSet +-- @field #boolean Monitor -- @extends Core.Fsm#FSM --- *“Airspeed, altitude, and brains. Two are always needed to successfully complete the flight.”* -- Unknown. @@ -150,6 +154,7 @@ -- * @{#EASYGCICAP.SetDefaultNumberAlter5Standby}: Set how many planes will be spawned on cold standby (Alert5), default 2. -- * @{#EASYGCICAP.SetDefaultEngageRange}: Set max engage range for CAP flights if they detect intruders, defaults to 50. -- * @{#EASYGCICAP.SetMaxAliveMissions}: Set max parallel missions can be done (CAP+GCI+Alert5+Tanker), defaults to 6. +-- * @{#EASYGCICAP.SetDefaultRepeatOnFailure}: Set max repeats on failure for intercepting/killing intruders, defaults to 3. -- -- -- @field #EASYGCICAP @@ -177,8 +182,12 @@ EASYGCICAP = { ManagedCP = {}, ManagedTK = {}, MaxAliveMissions = 6, - debug = true, + debug = false, engagerange = 50, + repeatsonfailure = 3, + GoZoneSet = nil, + NoGoZoneSet = nil, + Monitor = false, } --- Internal Squadron data type @@ -209,7 +218,7 @@ EASYGCICAP = { --- EASYGCICAP class version. -- @field #string version -EASYGCICAP.version="0.0.4" +EASYGCICAP.version="0.0.7" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -241,8 +250,8 @@ function EASYGCICAP:New(Alias, AirbaseName, Coalition, EWRName) --self.CapZoneName = CapZoneName self.airbasename = AirbaseName self.airbase = AIRBASE:FindByName(self.airbasename) - self.BlueGoZoneSet = SET_ZONE:New() - self.BlueNoGoZoneSet = SET_ZONE:New() + self.GoZoneSet = SET_ZONE:New() + self.NoGoZoneSet = SET_ZONE:New() self.resurrection = 900 self.capspeed = 300 self.capalt = 25000 @@ -253,6 +262,8 @@ function EASYGCICAP:New(Alias, AirbaseName, Coalition, EWRName) self.noaltert5 = 2 self.MaxAliveMissions = 6 self.engagerange = 50 + self.repeatsonfailure = 3 + self.Monitor = false -- Set some string id for output to DCS.log file. self.lid=string.format("EASYGCICAP %s | ", self.alias) @@ -283,7 +294,7 @@ end -- @param #number Maxiumum Maxmimum number of parallel missions allowed. Count is Cap-Missions + Intercept-Missions + Alert5-Missionsm default is 6 -- @return #EASYGCICAP self function EASYGCICAP:SetMaxAliveMissions(Maxiumum) - self:I(self.lid.."SetDefaultResurrection") + self:T(self.lid.."SetDefaultResurrection") self.MaxAliveMissions = Maxiumum or 6 return self end @@ -293,17 +304,27 @@ end -- @param #number Seconds Seconds, defaults to 900 -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultResurrection(Seconds) - self:I(self.lid.."SetDefaultResurrection") + self:T(self.lid.."SetDefaultResurrection") self.resurrection = Seconds or 900 return self end +--- Add default repeat attempts if an Intruder intercepts fails. +-- @param #EASYGCICAP self +-- @param #number Retries Retries, defaults to 3 +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultRepeatOnFailure(Retries) + self:T(self.lid.."SetDefaultRepeatOnFailure") + self.repeatsonfailure = Retries or 3 + return self +end + --- Set default CAP Speed in knots -- @param #EASYGCICAP self -- @param #number Speed Speed defaults to 300 -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultCAPSpeed(Speed) - self:I(self.lid.."SetDefaultSpeed") + self:T(self.lid.."SetDefaultSpeed") self.capspeed = Speed or 300 return self end @@ -313,7 +334,7 @@ end -- @param #number Altitude Altitude defaults to 25000 -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultCAPAlt(Altitude) - self:I(self.lid.."SetDefaultAltitude") + self:T(self.lid.."SetDefaultAltitude") self.capalt = Altitude or 25000 return self end @@ -323,7 +344,7 @@ end -- @param #number Direction Direction defaults to 90 (East) -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultCAPDirection(Direction) - self:I(self.lid.."SetDefaultDirection") + self:T(self.lid.."SetDefaultDirection") self.capdir = Direction or 90 return self end @@ -333,7 +354,7 @@ end -- @param #number Leg Leg defaults to 15 -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultCAPLeg(Leg) - self:I(self.lid.."SetDefaultLeg") + self:T(self.lid.."SetDefaultLeg") self.capleg = Leg or 15 return self end @@ -343,7 +364,7 @@ end -- @param #number Grouping Grouping defaults to 2 -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultCAPGrouping(Grouping) - self:I(self.lid.."SetDefaultCAPGrouping") + self:T(self.lid.."SetDefaultCAPGrouping") self.capgrouping = Grouping or 2 return self end @@ -353,7 +374,7 @@ end -- @param #number Range Range defaults to 100 NM -- @return #EASYGCICAP self function EASYGCICAP:SetDefaultMissionRange(Range) - self:I(self.lid.."SetDefaultMissionRange") + self:T(self.lid.."SetDefaultMissionRange") self.missionrange = Range or 100 return self end @@ -363,7 +384,7 @@ end -- @param #number Airframes defaults to 2 -- @return #EASYGCICAP selfAirframes function EASYGCICAP:SetDefaultNumberAlter5Standby(Airframes) - self:I(self.lid.."SetDefaultNumberAlter5Standby") + self:T(self.lid.."SetDefaultNumberAlter5Standby") self.noaltert5 = math.abs(Airframes) or 2 return self end @@ -373,7 +394,7 @@ end -- @param #number Range defaults to 50NM -- @return #EASYGCICAP selfAirframes function EASYGCICAP:SetDefaultEngageRange(Range) - self:I(self.lid.."SetDefaultNumberAlter5Standby") + self:T(self.lid.."SetDefaultNumberAlter5Standby") self.engagerange = Range or 50 return self end @@ -384,7 +405,7 @@ end -- @param #string Alias -- @return #EASYGCICAP self function EASYGCICAP:AddAirwing(Airbasename, Alias) - self:I(self.lid.."AddAirwing "..Airbasename) + self:T(self.lid.."AddAirwing "..Airbasename) -- Create Airwing data entry local AWEntry = {} -- #EASYGCICAP.Wing @@ -401,7 +422,7 @@ end -- @param #EASYGCICAP self -- @return #EASYGCICAP self function EASYGCICAP:_CreateAirwings() - self:I(self.lid.."_CreateAirwings") + self:T(self.lid.."_CreateAirwings") for airbase,data in pairs(self.ManagedAW) do local wing = data -- #EASYGCICAP.Wing local afb = wing.AirbaseName @@ -418,7 +439,7 @@ end -- @param #string Alias -- @return #EASYGCICAP self function EASYGCICAP:_AddAirwing(Airbasename, Alias) - self:I(self.lid.."_AddAirwing "..Airbasename) + self:T(self.lid.."_AddAirwing "..Airbasename) -- Create Airwing local CAP_Wing = AIRWING:New(Airbasename,Alias) @@ -444,7 +465,7 @@ function EASYGCICAP:_AddAirwing(Airbasename, Alias) flightgroup:SetDespawnAfterHolding() flightgroup:SetDestinationbase(AIRBASE:FindByName(Airbasename)) flightgroup:GetGroup():CommandEPLRS(true,5) - flightgroup:SetEngageDetectedOn(self.engagerange,{"Air"},self.BlueGoZoneSet,self.BlueNoGoZoneSet) + flightgroup:SetEngageDetectedOn(self.engagerange,{"Air"},self.GoZoneSet,self.NoGoZoneSet) flightgroup:GetGroup():OptionROTEvadeFire() flightgroup:SetOutOfAAMRTB() flightgroup:SetFuelLowRTB(true) @@ -477,7 +498,7 @@ end -- @param #number LegLength Defaults to 15 NM. -- @return #EASYGCICAP self function EASYGCICAP:AddPatrolPointCAP(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) - self:I(self.lid.."AddPatrolPointCAP "..Coordinate:ToStringLLDDM()) + self:T(self.lid.."AddPatrolPointCAP "..Coordinate:ToStringLLDDM()) local EntryCAP = {} -- #EASYGCICAP.CapPoint EntryCAP.AirbaseName = AirbaseName EntryCAP.Coordinate = Coordinate @@ -502,7 +523,7 @@ end -- @param #number LegLength Defaults to 15 NM. -- @return #EASYGCICAP self function EASYGCICAP:AddPatrolPointTanker(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) - self:I(self.lid.."AddPatrolPointTanker "..Coordinate:ToStringLLDDM()) + self:T(self.lid.."AddPatrolPointTanker "..Coordinate:ToStringLLDDM()) local EntryCAP = {} -- #EASYGCICAP.CapPoint EntryCAP.AirbaseName = AirbaseName EntryCAP.Coordinate = Coordinate @@ -521,7 +542,7 @@ end -- @param #EASYGCICAP self -- @return #EASYGCICAP self function EASYGCICAP:_SetTankerPatrolPoints() - self:I(self.lid.."_SetTankerPatrolPoints") + self:T(self.lid.."_SetTankerPatrolPoints") for _,_data in pairs(self.ManagedTK) do local data = _data --#EASYGCICAP.CapPoint local Wing = self.wings[data.AirbaseName][1] -- Ops.AirWing#AIRWING @@ -540,7 +561,7 @@ end -- @param #EASYGCICAP self -- @return #EASYGCICAP self function EASYGCICAP:_SetCAPPatrolPoints() - self:I(self.lid.."_SetCAPPatrolPoints") + self:T(self.lid.."_SetCAPPatrolPoints") for _,_data in pairs(self.ManagedCP) do local data = _data --#EASYGCICAP.CapPoint local Wing = self.wings[data.AirbaseName][1] -- Ops.AirWing#AIRWING @@ -565,7 +586,7 @@ end -- @param #number LegLength Defaults to 15 NM. -- @return #EASYGCICAP self function EASYGCICAP:_AddPatrolPointCAP(AirbaseName,Coordinate,Altitude,Speed,Heading,LegLength) - self:I(self.lid.."_AddPatrolPointCAP") + self:T(self.lid.."_AddPatrolPointCAP") local airbasename = AirbaseName or self.airbasename local coordinate = Coordinate local Altitude = Altitude or 25000 @@ -581,7 +602,7 @@ end -- @param #EASYGCICAP self -- @return #EASYGCICAP self function EASYGCICAP:_CreateSquads() - self:I(self.lid.."_CreateSquads") + self:T(self.lid.."_CreateSquads") for name,data in pairs(self.ManagedSQ) do local squad = data -- #EASYGCICAP.Squad local SquadName = name @@ -611,7 +632,7 @@ end -- @param #string Livery (optional) Livery name to be used. -- @return #EASYGCICAP self function EASYGCICAP:AddSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) - self:I(self.lid.."AddSquadron "..SquadName) + self:T(self.lid.."AddSquadron "..SquadName) -- Add Squadron Data local EntrySQ = {} -- #EASYGCICAP.Squad EntrySQ.TemplateName = TemplateName @@ -638,7 +659,7 @@ end -- @param #string Livery (optional) Livery name to be used. -- @return #EASYGCICAP self function EASYGCICAP:AddTankerSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) - self:I(self.lid.."AddTankerSquadron "..SquadName) + self:T(self.lid.."AddTankerSquadron "..SquadName) -- Add Squadron Data local EntrySQ = {} -- #EASYGCICAP.Squad EntrySQ.TemplateName = TemplateName @@ -666,7 +687,7 @@ end -- @param #string Livery (optional) Livery name to be used. -- @return #EASYGCICAP self function EASYGCICAP:_AddSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) - self:I(self.lid.."_AddSquadron "..SquadName) + self:T(self.lid.."_AddSquadron "..SquadName) -- Add Squadrons local Squadron_One = SQUADRON:New(TemplateName,AirFrames,SquadName) Squadron_One:AddMissionCapability({AUFTRAG.Type.CAP, AUFTRAG.Type.GCICAP, AUFTRAG.Type.INTERCEPT, AUFTRAG.Type.ALERT5}) @@ -697,7 +718,7 @@ end -- @param #string Livery (optional) Livery name to be used. -- @return #EASYGCICAP self function EASYGCICAP:_AddTankerSquadron(TemplateName, SquadName, AirbaseName, AirFrames, Skill, Modex, Livery) - self:I(self.lid.."_AddTankerSquadron "..SquadName) + self:T(self.lid.."_AddTankerSquadron "..SquadName) -- Add Squadrons local Squadron_One = SQUADRON:New(TemplateName,AirFrames,SquadName) Squadron_One:AddMissionCapability({AUFTRAG.Type.TANKER}) @@ -722,8 +743,8 @@ end -- @param Core.Zone#ZONE_BASE Zone -- @return #EASYGCICAP self function EASYGCICAP:AddAcceptZone(Zone) - self:I(self.lid.."AddAcceptZone0") - self.BlueGoZoneSet:AddZone(Zone) + self:T(self.lid.."AddAcceptZone0") + self.GoZoneSet:AddZone(Zone) return self end @@ -732,8 +753,8 @@ end -- @param Core.Zone#ZONE_BASE Zone -- @return #EASYGCICAP self function EASYGCICAP:AddRejectZone(Zone) - self:I(self.lid.."AddRejectZone") - self.BlueNoGoZoneSet:AddZone(Zone) + self:T(self.lid.."AddRejectZone") + self.NoGoZoneSet:AddZone(Zone) return self end @@ -741,7 +762,7 @@ end -- @param #EASYGCICAP self -- @return #EASYGCICAP self function EASYGCICAP:_StartIntel() - self:I(self.lid.."_StartIntel") + self:T(self.lid.."_StartIntel") -- Border GCI Detection local BlueAir_DetectionSetGroup = SET_GROUP:New() BlueAir_DetectionSetGroup:FilterPrefixes( { self.EWRName } ) @@ -751,8 +772,8 @@ function EASYGCICAP:_StartIntel() local BlueIntel = INTEL:New(BlueAir_DetectionSetGroup,self.coalitionname, self.EWRName) BlueIntel:SetClusterAnalysis(true,false,false) BlueIntel:SetForgetTime(300) - BlueIntel:SetAcceptZones(self.BlueGoZoneSet) - BlueIntel:SetRejectZones(self.BlueNoGoZoneSet) + BlueIntel:SetAcceptZones(self.GoZoneSet) + BlueIntel:SetRejectZones(self.NoGoZoneSet) BlueIntel:SetVerbosity(0) BlueIntel:Start() @@ -766,10 +787,12 @@ function EASYGCICAP:_StartIntel() local capspeed = self.capspeed + 100 local capalt = self.capalt local maxsize = self.maxinterceptsize + local repeatsonfailure = self.repeatsonfailure local wings = self.wings local ctlpts = self.ManagedCP local MaxAliveMissions = self.MaxAliveMissions * self.capgrouping + local nogozoneset = self.NoGoZoneSet function BlueIntel:OnAfterNewCluster(From,Event,To,Cluster) -- Aircraft? @@ -816,20 +839,33 @@ function EASYGCICAP:_StartIntel() local airframes = airwing:CountAssets(true) if distance < bestdistance and airframes >= wingsize then bestdistance = distance - targetairwing = airwing + targetairwing = airwing -- Ops.AirWing#AIRWING targetawname = name end end local text = string.format("Closest Airwing is %s", targetawname) - local m = MESSAGE:New(text,10,"CAPGCI"):ToAll():ToLog() + local m = MESSAGE:New(text,10,"CAPGCI"):ToAllIf(self.debug):ToLog() -- Do we have a matching airwing? if targetairwing then local AssetCount = targetairwing:CountAssetsOnMission(MissionTypes,Cohort) - --local AssetCount = targetairwing:GetAssetsOnMission({AUFTRAG.Type.INTERCEPT}) + --[[ + local Assets = targetairwing:GetAssetsOnMission(AUFTRAG.Type.GCICAP) + for _,_asset in pairs(Assets) do + local asset = _asset -- Functional.Warehouse#WAREHOUSE.Assetitem + local fg = asset.flightgroup + local name = asset.spawngroupname + local mission = fg:GetMissionCurrent() + local mtype = mission.type + local distance = position:Get3DDistance(fg:GetCoordinate()) or 1000*1000 + distance = distance / 1000 + local text = string.format("FlightGroup %s on mission %s with distance %d km",name,mtype,distance) + local m = MESSAGE:New(text,15,"GCICAP"):ToAllIf(self.debug):ToLog() + end + --]] -- Enough airframes on mission already? - self:I(self.lid.." Assets on Mission "..AssetCount) + self:T(self.lid.." Assets on Mission "..AssetCount) if AssetCount <= MaxAliveMissions then - local repeats = math.random(1,2) + local repeats = repeatsonfailure local InterceptAuftrag = AUFTRAG:NewINTERCEPT(contact.group) :SetMissionRange(150) :SetPriority(1,true,1) @@ -837,6 +873,24 @@ function EASYGCICAP:_StartIntel() :SetRepeatOnFailure(repeats) :SetMissionSpeed(UTILS.KnotsToAltKIAS(capspeed,capalt)) :SetMissionAltitude(capalt) + + if nogozoneset:Count() > 0 then + InterceptAuftrag:AddConditionSuccess( + function(group,zoneset) + local success = false + if group and group:IsAlive() then + local coord = group:GetCoordinate() + if coord and zoneset:IsCoordinateInZone(coord) then + success = true + end + end + return success + end, + contact.group, + nogozoneset + ) + end + targetairwing:AddMission(InterceptAuftrag) Cluster.mission = InterceptAuftrag end @@ -860,7 +914,7 @@ end -- @param #string To -- @return #EASYGCICAP self function EASYGCICAP:onafterStart(From,Event,To) - self:I({From,Event,To}) + self:T({From,Event,To}) self:_StartIntel() self:_CreateAirwings() self:_CreateSquads() @@ -889,7 +943,7 @@ end -- @param #string To -- @return #EASYGCICAP self function EASYGCICAP:onafterStatus(From,Event,To) - self:I({From,Event,To}) + self:T({From,Event,To}) -- Gather Some Stats local function counttable(tbl) local count = 0 @@ -912,6 +966,13 @@ function EASYGCICAP:onafterStatus(From,Event,To) if self.debug then self:I(self.lid.."Wings: "..wings.." | Squads: "..squads.." | CapPoints: "..caps.." | Assets on Mission: "..assets.." | Assets in Stock: "..instock) end + if self.Monitor then + local threatcount = #self.Intel.Clusters or 0 + local text = "GCICAP "..self.alias + text = text.."\nWings: "..wings.."\nSquads: "..squads.."\nCapPoints: "..caps.."\nAssets on Mission: "..assets.."\nAssets in Stock: "..instock + text = text.."\nThreats:"..threatcount + MESSAGE:New(text,15,"GCICAP"):ToAll():ToLogIf(self.debug) + end self:__Status(30) return self end @@ -923,7 +984,7 @@ end -- @param #string To -- @return #EASYGCICAP self function EASYGCICAP:onafterStop(From,Event,To) - self:I({From,Event,To}) + self:T({From,Event,To}) self.Intel:Stop() return self end From 55fb8f20643f4bd96f194728220d953367600d22 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 27 Sep 2023 18:08:02 +0200 Subject: [PATCH 8/9] nil check added --- Moose Development/Moose/Core/Zone.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 2d2ccaecb..a6c975b79 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -190,6 +190,7 @@ end -- @param Core.Point#COORDINATE Coordinate The coordinate to test. -- @return #boolean true if the coordinate is within the zone. function ZONE_BASE:IsCoordinateInZone( Coordinate ) + if not Coordinate then return false end local InZone = self:IsVec2InZone( Coordinate:GetVec2() ) return InZone end From 04a7c912ea0984794c31d0fc3b89073ad5880454 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: [PATCH 9/9] Update Airboss.lua - Improved into wind --- Moose Development/Moose/Ops/Airboss.lua | 138 ++++++++++++++++++++---- 1 file changed, 119 insertions(+), 19 deletions(-) diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index ef510bcd2..a1616b965 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -4075,7 +4075,7 @@ function AIRBOSS:_CheckRecoveryTimes() -- Check that wind is blowing from a direction > 5° different from the current heading. local hdg = self:GetHeading() - local wind = self:GetHeadingIntoWind() + local wind = self:GetHeadingIntoWind(nextwindow.SPEED) local delta = self:_GetDeltaHeading( hdg, wind ) local uturn = delta > 5 @@ -6728,7 +6728,7 @@ function AIRBOSS:_AddMarshalGroup( flight, stack ) -- If the carrier is supposed to turn into the wind, we take the wind coordinate. if self.recoverywindow and self.recoverywindow.WIND then - brc = self:GetBRCintoWind() + brc = self:GetBRCintoWind(self.recoverywindow.SPEED) end -- Get charlie time estimate. @@ -11553,7 +11553,7 @@ end -- @param #boolean magnetic If true, calculate magnetic heading. By default true heading is returned. -- @param Core.Point#COORDINATE coord (Optional) Coordinate from which heading is calculated. Default is current carrier position. -- @return #number Carrier heading in degrees. -function AIRBOSS:GetHeadingIntoWind( magnetic, coord ) +function AIRBOSS:GetHeadingIntoWind_old( magnetic, coord ) local function adjustDegreesForWindSpeed(windSpeed) local degreesAdjustment = 0 @@ -11613,13 +11613,108 @@ function AIRBOSS:GetHeadingIntoWind( magnetic, coord ) return intowind end +--- Get true (or magnetic) heading of carrier into the wind. This accounts for the angled runway. +-- Implementation based on [Mags & Bambi](https://magwo.github.io/carrier-cruise/). +-- @param #AIRBOSS self +-- @param #number vdeck Desired wind velocity over deck in knots. +-- @param #boolean magnetic If true, calculate magnetic heading. By default true heading is returned. +-- @param Core.Point#COORDINATE coord (Optional) Coordinate from which heading is calculated. Default is current carrier position. +-- @return #number Carrier heading in degrees. +-- @return #number Carrier speed in knots to reach desired wind speed on deck. +function AIRBOSS:GetHeadingIntoWind( vdeck, magnetic, coord ) + + -- Default offset angle. + local Offset=self.carrierparam.rwyangle or 0 + + -- Get direction the wind is blowing from. + local windfrom, vwind=self:GetWind(18, nil ,coord) + + -- Ships min/max speed. + local Vmin=4 + local Vmax=UTILS.KmphToKnots(self.carrier:GetSpeedMax()) + + -- No wind. will stay on current heading. + if vwind<0.1 then + local h=self:GetHeading(magnetic) + return h, math.min(vdeck, Vmax) + end + + -- Convert wind speed to knots. + vwind=UTILS.MpsToKnots(vwind) + + -- Wind to in knots. + local windto=(windfrom+180)%360 + + -- Offset angle in rad. We also define the rotation to be clock-wise, which requires a minus sign. + local alpha=math.rad(-Offset) + + -- Constant. + local C = math.sqrt(math.cos(alpha)^2 / math.sin(alpha)^2 + 1) + + + -- Upper limit of desired speed due to max boat speed. + local vdeckMax=vwind + math.cos(alpha) * Vmax + + -- Lower limit of desired speed due to min boat speed. + local vdeckMin=vwind + math.cos(alpha) * Vmin + + + -- Speed of ship so it matches the desired speed. + local v=0 + + -- Angle wrt. to wind TO-direction + local theta=0 + + if vdeck>vdeckMax then + -- Boat cannot go fast enough + + -- Set max speed. + v=Vmax + + -- Calculate theta. + theta = math.asin(v/(vwind*C)) - math.asin(-1/C) + + elseif vdeckvwind then + -- Too little wind + + -- Set theta to 90° + theta=math.pi/2 + + -- Set speed. + v = math.sqrt(vdeck^2 - vwind^2) + + else + -- Normal case + theta = math.asin(vdeck * math.sin(alpha) / vwind) + v = vdeck * math.cos(alpha) - vwind * math.cos(theta) + end + + -- Magnetic heading. + local magvar= magnetic and self.magvar or 0 + + -- Ship heading so cross wind is min for the given wind. + local intowind = (540 + (windto - magvar + math.deg(theta) )) % 360 + + return intowind, v +end + --- Get base recovery course (BRC) when the carrier would head into the wind. -- This includes the current wind direction and accounts for the angled runway. -- @param #AIRBOSS self +-- @param #number vdeck Desired wind velocity over deck in knots. -- @return #number BRC into the wind in degrees. -function AIRBOSS:GetBRCintoWind() +function AIRBOSS:GetBRCintoWind(vdeck) -- BRC is the magnetic heading. - return self:GetHeadingIntoWind( true ) + return self:GetHeadingIntoWind(vdeck, true ) end --- Get final bearing (FB) of carrier. @@ -13525,28 +13620,32 @@ function AIRBOSS:CarrierTurnIntoWind( time, vdeck, uturn ) -- Wind speed. local _, vwind = self:GetWind() + -- Desired wind on deck in knots. + local vdeck=UTILS.MpsToKnots(vdeck) + + -- Get heading into the wind accounting for angled runway. + local hiw, speedknots = self:GetHeadingIntoWind(vdeck) + -- Speed of carrier in m/s but at least 4 knots. - local vtot = math.max( vdeck - vwind, UTILS.KnotsToMps( 4 ) ) + local vtot = UTILS.KnotsToMps(speedknots) -- Distance to travel local dist = vtot * time - -- Speed in knots - local speedknots = UTILS.MpsToKnots( vtot ) + -- Distance in NM. local distNM = UTILS.MetersToNM( dist ) - -- Debug output - self:I( self.lid .. string.format( "Carrier steaming into the wind (%.1f kts). Distance=%.1f NM, Speed=%.1f knots, Time=%d sec.", UTILS.MpsToKnots( vwind ), distNM, speedknots, time ) ) - - -- Get heading into the wind accounting for angled runway. - local hiw = self:GetHeadingIntoWind() - -- Current heading. local hdg = self:GetHeading() -- Heading difference. local deltaH = self:_GetDeltaHeading( hdg, hiw ) + -- Debug output + self:I( self.lid .. string.format( "Carrier steaming into the wind (%.1f kts). Heading=%03d-->%03d (Delta=%.1f), Speed=%.1f knots, Distance=%.1f NM, Time=%d sec", + UTILS.MpsToKnots( vwind ), hdg, hiw, deltaH, speedknots, distNM, speedknots, time ) ) + + -- Current coordinate. local Cv = self:GetCoordinate() local Ctiw = nil -- Core.Point#COORDINATE @@ -13560,7 +13659,7 @@ function AIRBOSS:CarrierTurnIntoWind( time, vdeck, uturn ) Csoo = Cv:Translate( 750, hdg ):Translate( 750, hiw ) -- Heading into wind from Csoo. - local hsw = self:GetHeadingIntoWind( false, Csoo ) + local hsw = self:GetHeadingIntoWind(vdeck, false, Csoo ) -- Into the wind coord. Ctiw = Csoo:Translate( dist, hsw ) @@ -13572,7 +13671,7 @@ function AIRBOSS:CarrierTurnIntoWind( time, vdeck, uturn ) Csoo = Cv:Translate( 900, hdg ):Translate( 900, hiw ) -- Heading into wind from Csoo. - local hsw = self:GetHeadingIntoWind( false, Csoo ) + local hsw = self:GetHeadingIntoWind(vdeck, false, Csoo ) -- Into the wind coord. Ctiw = Csoo:Translate( dist, hsw ) @@ -13584,7 +13683,7 @@ function AIRBOSS:CarrierTurnIntoWind( time, vdeck, uturn ) Csoo = Cv:Translate( 1100, hdg - 90 ):Translate( 1000, hiw ) -- Heading into wind from Csoo. - local hsw = self:GetHeadingIntoWind( false, Csoo ) + local hsw = self:GetHeadingIntoWind(vdeck, false, Csoo ) -- Into the wind coord. Ctiw = Csoo:Translate( dist, hsw ) @@ -13596,7 +13695,7 @@ function AIRBOSS:CarrierTurnIntoWind( time, vdeck, uturn ) Csoo = Cv:Translate( 1200, hdg - 90 ):Translate( 1000, hiw ) -- Heading into wind from Csoo. - local hsw = self:GetHeadingIntoWind( false, Csoo ) + local hsw = self:GetHeadingIntoWind(vdeck, false, Csoo ) -- Into the wind coord. Ctiw = Csoo:Translate( dist, hsw ) @@ -13809,7 +13908,8 @@ function AIRBOSS:_CheckCarrierTurning() local hdg if self.turnintowind then -- We are now steaming into the wind. - hdg = self:GetHeadingIntoWind( false ) + local vdeck=self.recoverywindow and self.recoverywindow.SPEED or 20 + hdg = self:GetHeadingIntoWind(vdeck, false) else -- We turn towards the next waypoint. hdg = self:GetCoordinate():HeadingTo( self:_GetNextWaypoint() )