From 2ad81ca49934fe09847114aeec026ea10993ee04 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 12 Oct 2020 00:09:02 +0200 Subject: [PATCH] Ops --- Moose Development/Moose/Ops/Airboss.lua | 10 ++-- Moose Development/Moose/Ops/ArmyGroup.lua | 68 ++++++++++++++--------- Moose Development/Moose/Ops/Auftrag.lua | 2 + Moose Development/Moose/Ops/NavyGroup.lua | 19 +++---- Moose Development/Moose/Ops/OpsGroup.lua | 38 ++++++++----- 5 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index c5fa5ce49..4b7c3fe3f 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1273,17 +1273,19 @@ AIRBOSS.AircraftCarrier={ --- Carrier types. -- @type AIRBOSS.CarrierType --- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) --- @field #string LINCOLN USS Abraham Lincoln (CVN-72) --- @field #string WASHINGTON USS George Washington (CVN-73) +-- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) [Super Carrier Module] +-- @field #string LINCOLN USS Abraham Lincoln (CVN-72) [Super Carrier Module] +-- @field #string WASHINGTON USS George Washington (CVN-73) [Super Carrier Module] -- @field #string STENNIS USS John C. Stennis (CVN-74) --- @field #string VINSON USS Carl Vinson (CVN-70) +-- @field #string TRUMAN USS Harry S. Trueman (CVN-75) [Super Carrier Module] +-- @field #string VINSON USS Carl Vinson (CVN-70) [Obsolete] -- @field #string TARAWA USS Tarawa (LHA-1) -- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5) AIRBOSS.CarrierType={ ROOSEVELT="CVN_71", LINCOLN="CVN_72", WASHINGTON="CVN_73", + TRUMAN="CVN_75", STENNIS="Stennis", VINSON="VINSON", TARAWA="LHA_Tarawa", diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index f655563f0..115607b46 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -40,7 +40,7 @@ ARMYGROUP = { --- Army Group version. -- @field #string version -ARMYGROUP.version="0.1.0" +ARMYGROUP.version="0.3.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -350,7 +350,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To) -- Set TACAN to default. self:_SwitchTACAN() - + -- Turn on the radio. if self.radioDefault then self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu) @@ -361,7 +361,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To) end -- Update route. - self:Cruise() + self:Cruise(nil, self.option.Formation or self.optionDefault.Formation) end @@ -394,7 +394,10 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) if Speed then wp.speed=UTILS.KnotsToMps(Speed) else - -- Take default waypoint speed. + -- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum. + if self.adinfinitum and wp.speed<0.1 then + wp.speed=UTILS.KmphToMps(self.speedCruise) + end end -- Formation. @@ -425,10 +428,15 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) -- Add waypoint. table.insert(waypoints, wp) - + + -- Apply formation at the current position or it will only be changed when reaching the next waypoint. + local formation=ENUMS.Formation.Vehicle.OffRoad + if wp.action~=ENUMS.Formation.Vehicle.OnRoad then + formation=wp.action + end -- Current point. - local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OffRoad) + local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), formation) table.insert(waypoints, 1, current) -- Insert a point on road. @@ -442,32 +450,31 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) for i,_wp in pairs(waypoints) do local wp=_wp local text=string.format("WP #%d UID=%d type=%s: Speed=%d m/s, alt=%d m, Action=%s", i, wp.uid and wp.uid or 0, wp.type, wp.speed, wp.alt, wp.action) - self:I(text) - if wp.coordinate then + self:T(text) + if false and wp.coordinate then wp.coordinate:MarkToAll(text) end end end - - if #waypoints>=2 then + if not self.passedfinalwp then -- Debug info. - self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Formation=%s", - self.currentwp, n, #self.waypoints, #waypoints-2, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) - + self:T(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Formation=%s", + self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) + -- Route group to all defined waypoints remaining. self:Route(waypoints) else - + --- - -- No waypoints left + -- Passed final WP ==> Full Stop --- - self:E(self.lid..string.format("WARNING: No waypoints left ==> Full Stop!")) - self:FullStop() - + self:E(self.lid..string.format("WARNING: Passed final WP ==> Full Stop!")) + self:FullStop() + end end @@ -746,8 +753,7 @@ function ARMYGROUP:_InitGroup() self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On) -- Set default formation from first waypoint. - self.option.Formation=self:GetWaypoint(1).action - self.optionDefault.Formation=self.option.Formation + self.optionDefault.Formation=self:GetWaypoint(1).action -- Default TACAN off. self:SetDefaultTACAN(nil, nil, nil, nil, true) @@ -815,10 +821,11 @@ end -- @param #ARMYGROUP self -- @param #number Formation New formation the group will fly in. Default is the setting of `SetDefaultFormation()`. -- @param #boolean Permanently If true, formation always used from now on. +-- @param #boolean NoRouteUpdate If true, route is not updated. -- @return #ARMYGROUP self -function ARMYGROUP:SwitchFormation(Formation, Permanently) +function ARMYGROUP:SwitchFormation(Formation, Permanently, NoRouteUpdate) - if self:IsAlive() then + if self:IsAlive() or self:IsInUtero() then Formation=Formation or self.optionDefault.Formation @@ -831,11 +838,20 @@ function ARMYGROUP:SwitchFormation(Formation, Permanently) -- Set current formation. self.option.Formation=Formation - -- Update route with the new formation. - self:__UpdateRoute(-1, nil, nil, Formation) + if self:IsInUtero() then + self:T(self.lid..string.format("Will switch formation to %s (permanently=%s) when group is spawned", self.option.Formation, tostring(Permanently))) + else - -- Debug info. - self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) + -- Update route with the new formation. + if NoRouteUpdate then + else + self:__UpdateRoute(-1, nil, nil, Formation) + end + + -- Debug info. + self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) + + end end diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index affd7e1b3..002509c7d 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -1166,6 +1166,8 @@ function AUFTRAG:NewARTY(Target, Nshots, Radius) mission.artyShots=Nshots or 3 mission.artyRadius=Radius or 100 + mission.engageWeaponType=ENUMS.WeaponFlag.Auto + mission.optionROE=ENUMS.ROE.OpenFire -- Ground/naval need open fire! mission.optionAlarm=0 diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index fad6bd75a..1ef4a3473 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -241,14 +241,15 @@ end -- @param #number Nshots Number of shots to fire. Default 3. -- @param #number WeaponType Type of weapon. Default auto. -- @param #number Prio Priority of the task. +-- @param #number Duration Duration in seconds after which the task is cancelled. Default *never*. -- @return Ops.OpsGroup#OPSGROUP.Task The task table. -function NAVYGROUP:AddTaskWaypointFireAtPoint(Coordinate, Waypoint, Radius, Nshots, WeaponType, Prio) +function NAVYGROUP:AddTaskWaypointFireAtPoint(Coordinate, Waypoint, Radius, Nshots, WeaponType, Prio, Duration) Waypoint=Waypoint or self:GetWaypointNext() local DCStask=CONTROLLABLE.TaskFireAtPoint(nil, Coordinate:GetVec2(), Radius, Nshots, WeaponType) - local task=self:AddTaskWaypoint(DCStask, Waypoint, nil, Prio) + local task=self:AddTaskWaypoint(DCStask, Waypoint, nil, Prio, Duration) return task end @@ -608,9 +609,6 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) -- Update route from this waypoint number onwards. n=n or self:GetWaypointIndexNext() - -- Debug info. - self:T(self.lid..string.format("Update route n=%d", n)) - -- Update waypoint tasks, i.e. inject WP tasks into waypoint table. self:_UpdateWaypointTasks(n) @@ -650,11 +648,10 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) table.insert(waypoints, 1, current) - if #waypoints>1 then - - self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Depth=%d m", - self.currentwp, n, #self.waypoints, #waypoints-1, UTILS.MpsToKnots(self.speedWp), wp.alt)) + if not self.passedfinalwp then + -- Debug info. + self:T(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Depth=%d m", self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), wp.alt)) -- Route group to all defined waypoints remaining. self:Route(waypoints) @@ -662,10 +659,10 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) else --- - -- No waypoints left ==> Full Stop + -- Passed final WP ==> Full Stop --- - self:E(self.lid..string.format("WARNING: No waypoints left ==> Full Stop!")) + self:E(self.lid..string.format("WARNING: Passed final WP ==> Full Stop!")) self:FullStop() end diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 9281907e0..733cdd056 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -479,11 +479,11 @@ function OPSGROUP:AddCheckZone(CheckZone) end ---- Add a zone that triggers and event if the group enters or leaves any of the zones. +--- Add a weapon range for ARTY auftrag. -- @param #OPSGROUP self --- @param #number RangeMin --- @param #number RangeMax --- @param #number BitType +-- @param #number RangeMin Minimum range in kilometers. Default 0 km. +-- @param #number RangeMax Maximum range in kilometers. Default 10 km. +-- @param #number BitType Bit mask of weapon type for which the given min/max ranges apply. Default is `ENUMS.WeaponFlag.Auto`, i.e. for all weapon types. -- @return #OPSGROUP self function OPSGROUP:AddWeaponRange(RangeMin, RangeMax, BitType) @@ -2565,9 +2565,14 @@ function OPSGROUP:RouteToMission(mission, delay) end end + + local formation=nil + if self.isGround and mission.optionFormation then + formation=mission.optionFormation + end -- Add waypoint. - local waypoint=self:AddWaypoint(waypointcoord, SpeedToMission, nil, nil, false) + local waypoint=self:AddWaypoint(waypointcoord, SpeedToMission, nil, formation, false) -- Add waypoint task. UpdateRoute is called inside. local waypointtask=self:AddTaskWaypoint(mission.DCStask, waypoint, mission.name, mission.prio, mission.duration) @@ -2595,7 +2600,7 @@ function OPSGROUP:RouteToMission(mission, delay) self:SwitchAlarmstate(mission.optionAlarm) end -- Formation - if mission.optionFormation then + if mission.optionFormation and self.isAircraft then self:SwitchFormation(mission.optionFormation) end -- Radio frequency and modulation. @@ -2697,8 +2702,10 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) -- Final waypoint reached? if wpindex==nil or wpindex==#self.waypoints then - -- Set switch to true. - self.passedfinalwp=true + -- Set switch to true. + if not self.adinfinitum or #self.waypoints<=1 then + self.passedfinalwp=true + end end @@ -2711,7 +2718,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) -- Debug info. local text=string.format("Group passed waypoint %s/%d ID=%d: final=%s detour=%s astar=%s", tostring(wpindex), #self.waypoints, Waypoint.uid, tostring(self.passedfinalwp), tostring(Waypoint.detour), tostring(Waypoint.astar)) - self:I(self.lid..text) + self:T(self.lid..text) end @@ -3091,7 +3098,7 @@ function OPSGROUP:_CheckGroupDone(delay) -- We only want to update the route if there are no more tasks to be done. if ntasks>0 then - self:T(self.lid..string.format("Still got %d tasks for the current waypoint UID=%d", ntasks, waypoint.uid)) + self:T(self.lid..string.format("Still got %d tasks for the current waypoint UID=%d ==> RETURN (no action)", ntasks, waypoint.uid)) return end end @@ -3135,7 +3142,7 @@ function OPSGROUP:_CheckGroupDone(delay) -- No further waypoints. Command a full stop. self:__FullStop(-1) - self:T(self.lid..string.format("Passed final WP, #WP>1, adinfinitum=FALSE ==> Full Stop")) + self:T(self.lid..string.format("Passed final WP, adinfinitum=FALSE ==> Full Stop")) else @@ -3295,17 +3302,18 @@ function OPSGROUP:InitWaypoints() self.waypoints={} for index,wp in pairs(self.waypoints0) do - - --local waypoint=self:_CreateWaypoint(wp) - --self:_AddWaypoint(waypoint) - + + -- Coordinate of the waypoint. local coordinate=COORDINATE:New(wp.x, wp.alt, wp.y) + + -- Speed at the waypoint. local speedknots=UTILS.MpsToKnots(wp.speed) if index==1 then self.speedWp=wp.speed end + -- Add waypoint. self:AddWaypoint(coordinate, speedknots, index-1, nil, false) end