mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
RECOVERYTANKER v1.0.4
- Fixed PG airbase enumerator names - Rescuehelo v1.0.3 - minor stuff
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
-- Bankler was kind enough to allow me to add this to the class - thanks again!
|
||||
--
|
||||
-- @module Ops.Airboss
|
||||
-- @image MOOSE.JPG
|
||||
-- @image Ops_Airboss.png
|
||||
|
||||
--- AIRBOSS class.
|
||||
-- @type AIRBOSS
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
-- * Automatic respawning when tanker runs out of fuel for 24/7 operations.
|
||||
-- * Tanker can be spawned cold or hot on the carrier or at any other airbase or directly in air.
|
||||
-- * Automatic AA TACAN beacon setting.
|
||||
-- * Multiple tankers at different carriers due to object oriented approach.
|
||||
-- * Multiple tankers at the same carrier.
|
||||
-- * Multiple carriers due to object oriented approach.
|
||||
-- * Finite State Machine (FSM) implementation, which allows the mission designer to hook into certain events.
|
||||
--
|
||||
-- ===
|
||||
@@ -18,7 +19,7 @@
|
||||
-- ### Special thanks to **HighwaymanEd** for testing and suggesting improvements!
|
||||
--
|
||||
-- @module Ops.RecoveryTanker
|
||||
-- @image MOOSE.JPG
|
||||
-- @image Ops_RecoveryTanker.png
|
||||
|
||||
--- RECOVERYTANKER class.
|
||||
-- @type RECOVERYTANKER
|
||||
@@ -54,6 +55,7 @@
|
||||
-- @field DCS#Vec3 orientlast Orientation of the carrier for checking if carrier is currently turning.
|
||||
-- @field Core.Point#COORDINATE position Position of carrier. Used to monitor if carrier significantly changed its position and then update the tanker pattern.
|
||||
-- @field #string alias Alias of the spawn group.
|
||||
-- @field #number uid Unique ID of this tanker.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- Recovery Tanker.
|
||||
@@ -252,15 +254,16 @@ RECOVERYTANKER = {
|
||||
orientlast = nil,
|
||||
position = nil,
|
||||
alias = nil,
|
||||
uid = 0,
|
||||
}
|
||||
|
||||
--- Unique ID (global).
|
||||
-- @field #number uid Unique ID (global).
|
||||
RECOVERYTANKER.uid=0
|
||||
-- @field #number UID Unique ID (global).
|
||||
RECOVERYTANKER.UID=0
|
||||
|
||||
--- Class version.
|
||||
-- @field #string version
|
||||
RECOVERYTANKER.version="1.0.3"
|
||||
RECOVERYTANKER.version="1.0.4"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -305,14 +308,17 @@ function RECOVERYTANKER:New(carrierunit, tankergroupname)
|
||||
-- Tanker group name.
|
||||
self.tankergroupname=tankergroupname
|
||||
|
||||
-- Save self in static object. Easier to retrieve later.
|
||||
self.carrier:SetState(self.carrier, "RECOVERYTANKER", self)
|
||||
|
||||
-- Increase unique ID.
|
||||
RECOVERYTANKER.uid=RECOVERYTANKER.uid+1
|
||||
RECOVERYTANKER.UID=RECOVERYTANKER.UID+1
|
||||
|
||||
-- Unique ID of this tanker.
|
||||
self.uid=RECOVERYTANKER.UID
|
||||
|
||||
-- Save self in static object. Easier to retrieve later.
|
||||
self.carrier:SetState(self.carrier, string.format("RECOVERYTANKER_%d", self.uid) , self)
|
||||
|
||||
-- Set unique spawn alias.
|
||||
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.tankergroupname, RECOVERYTANKER.uid)
|
||||
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.tankergroupname, RECOVERYTANKER.UID)
|
||||
|
||||
-- Log ID.
|
||||
self.lid=string.format("RECOVERYTANKER %s |", self.alias)
|
||||
@@ -931,7 +937,6 @@ end
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function RECOVERYTANKER:onafterPatternUpdate(From, Event, To)
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Updating recovery tanker %s racetrack pattern.", self.tanker:GetName())
|
||||
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
|
||||
@@ -981,6 +986,7 @@ function RECOVERYTANKER:onafterPatternUpdate(From, Event, To)
|
||||
|
||||
-- Set update time.
|
||||
self.Tupdate=timer.getTime()
|
||||
|
||||
end
|
||||
|
||||
--- On after "RTB" event. Send tanker back to carrier.
|
||||
@@ -1149,9 +1155,9 @@ function RECOVERYTANKER:_InitPatternTaskFunction()
|
||||
|
||||
-- Task script.
|
||||
local DCSScript = {}
|
||||
DCSScript[#DCSScript+1] = string.format('local mycarrier = UNIT:FindByName(\"%s\") ', carriername) -- The carrier unit that holds the self object.
|
||||
DCSScript[#DCSScript+1] = string.format('local mytanker = mycarrier:GetState(mycarrier, \"RECOVERYTANKER\") ') -- Get the RECOVERYTANKER self object.
|
||||
DCSScript[#DCSScript+1] = string.format('mytanker:PatternUpdate()') -- Call the function, e.g. mytanker.(self)
|
||||
DCSScript[#DCSScript+1] = string.format('local mycarrier = UNIT:FindByName(\"%s\") ', carriername) -- The carrier unit that holds the self object.
|
||||
DCSScript[#DCSScript+1] = string.format('local mytanker = mycarrier:GetState(mycarrier, \"RECOVERYTANKER_%d\") ', self.uid) -- Get the RECOVERYTANKER self object.
|
||||
DCSScript[#DCSScript+1] = string.format('mytanker:PatternUpdate()') -- Call the function, e.g. mytanker.(self)
|
||||
|
||||
-- Create task.
|
||||
local DCSTask = CONTROLLABLE.TaskWrappedAction(self, CONTROLLABLE.CommandDoScript(self, table.concat(DCSScript)))
|
||||
@@ -1159,7 +1165,6 @@ function RECOVERYTANKER:_InitPatternTaskFunction()
|
||||
return DCSTask
|
||||
end
|
||||
|
||||
|
||||
--- Init waypoint after spawn. Tanker is first guided to a position astern the carrier and starts its racetrack pattern from there.
|
||||
-- @param #RECOVERYTANKER self
|
||||
-- @param #number dist Distance [NM] of initial waypoint astern carrier. Default 8 NM.
|
||||
@@ -1195,7 +1200,7 @@ function RECOVERYTANKER:_InitRoute(dist, delay)
|
||||
end
|
||||
|
||||
-- Task to update pattern when wp 2 is reached.
|
||||
local task=self:_InitPatternTaskFunction()
|
||||
local task=self:_InitPatternTaskFunction()
|
||||
|
||||
-- Waypoints.
|
||||
local wp={}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
-- ### Contributions: Flightcontrol (@{AI.AI_Formation} class being used here)
|
||||
--
|
||||
-- @module Ops.RescueHelo
|
||||
-- @image MOOSE.JPG
|
||||
-- @image Ops_RescueHelo.png
|
||||
|
||||
--- RESCUEHELO class.
|
||||
-- @type RESCUEHELO
|
||||
@@ -49,6 +49,7 @@
|
||||
-- @field #boolean rtb If true, Helo will be return to base on the next status check.
|
||||
-- @field #number hid Unit ID of the helo group. (Global) Running number.
|
||||
-- @field #string alias Alias of the spawn group.
|
||||
-- @field #number uid Unique ID of this helo.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- Rescue Helo
|
||||
@@ -217,22 +218,23 @@ RESCUEHELO = {
|
||||
rtb = nil,
|
||||
carrierstop = nil,
|
||||
alias = nil,
|
||||
uid = 0,
|
||||
}
|
||||
|
||||
--- Unique ID (global).
|
||||
-- @field #number uid Unique ID (global).
|
||||
RESCUEHELO.uid=0
|
||||
RESCUEHELO.UID=0
|
||||
|
||||
--- Class version.
|
||||
-- @field #string version
|
||||
RESCUEHELO.version="1.0.2"
|
||||
RESCUEHELO.version="1.0.3"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Add messages for rescue mission.
|
||||
-- TODO: Add option to stop carrier while rescue operation is in progress? Done but NOT working!
|
||||
-- NOPE: Add messages for rescue mission.
|
||||
-- NOPE: Add option to stop carrier while rescue operation is in progress? Done but NOT working. Postponed...
|
||||
-- DONE: Write documentation.
|
||||
-- DONE: Add option to deactivate the rescuing.
|
||||
-- DONE: Possibility to add already present/spawned aircraft, e.g. for warehouse.
|
||||
@@ -267,10 +269,16 @@ function RESCUEHELO:New(carrierunit, helogroupname)
|
||||
self.helogroupname=helogroupname
|
||||
|
||||
-- Increase ID.
|
||||
RESCUEHELO.uid=RESCUEHELO.uid+1
|
||||
RESCUEHELO.UID=RESCUEHELO.UID+1
|
||||
|
||||
-- Unique ID of this helo.
|
||||
self.uid=RESCUEHELO.UID
|
||||
|
||||
-- Save self in static object. Easier to retrieve later.
|
||||
self.carrier:SetState(self.carrier, string.format("RESCUEHELO_%d", self.uid) , self)
|
||||
|
||||
-- Set unique spawn alias.
|
||||
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.helogroupname, RESCUEHELO.uid)
|
||||
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.helogroupname, RESCUEHELO.UID)
|
||||
|
||||
-- Log ID.
|
||||
self.lid=string.format("RESCUEHELO %s |", self.alias)
|
||||
@@ -295,6 +303,7 @@ function RESCUEHELO:New(carrierunit, helogroupname)
|
||||
|
||||
-- Debug trace.
|
||||
if false then
|
||||
self.Debug=true
|
||||
BASE:TraceOnOff(true)
|
||||
BASE:TraceClass(self.ClassName)
|
||||
BASE:TraceLevel(1)
|
||||
@@ -687,7 +696,7 @@ function RESCUEHELO:OnEventLand(EventData)
|
||||
|
||||
if self:IsRescuing() then
|
||||
|
||||
self:T(string.format("Rescue helo %s returned from rescue operation.", groupname))
|
||||
self:T(self.lid..string.format("Rescue helo %s returned from rescue operation.", groupname))
|
||||
|
||||
end
|
||||
|
||||
@@ -696,20 +705,18 @@ function RESCUEHELO:OnEventLand(EventData)
|
||||
|
||||
if self:IsRescuing() then
|
||||
|
||||
self:T(string.format("Rescue helo %s returned from rescue operation.", groupname))
|
||||
self:T(self.lid..string.format("Rescue helo %s returned from rescue operation.", groupname))
|
||||
|
||||
-- Respawn helo at current airbase.
|
||||
--self.helo=group:RespawnAtCurrentAirbase()
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 3)
|
||||
|
||||
else
|
||||
|
||||
self:T2(string.format("WARNING: Rescue helo %s landed. This should not happen for Takeoff=Air or respawninair=true unless a rescue operation finished.", groupname))
|
||||
self:T2(self.lid..string.format("WARNING: Rescue helo %s landed. This should not happen for Takeoff=Air or respawninair=true unless a rescue operation finished.", groupname))
|
||||
|
||||
-- Respawn helo at current airbase anyway.
|
||||
if self.respawn then
|
||||
--self.helo=group:RespawnAtCurrentAirbase()
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 3)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -718,8 +725,7 @@ function RESCUEHELO:OnEventLand(EventData)
|
||||
|
||||
-- Respawn helo at current airbase.
|
||||
if self.respawn then
|
||||
--self.helo=group:RespawnAtCurrentAirbase()
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
|
||||
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 3)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -934,7 +940,7 @@ function RESCUEHELO:onafterStatus(From, Event, To)
|
||||
if self.respawn then
|
||||
|
||||
-- Respawn helo in air.
|
||||
self.helo:Respawn(nil, true)
|
||||
self.helo=self.helo:Respawn(nil, true)
|
||||
|
||||
end
|
||||
|
||||
@@ -952,7 +958,7 @@ function RESCUEHELO:onafterStatus(From, Event, To)
|
||||
if self.rtb then
|
||||
|
||||
-- Send helo back to base.
|
||||
self:RTB()
|
||||
--self:RTB()
|
||||
|
||||
-- Switch to false.
|
||||
self.rtb=false
|
||||
@@ -1017,14 +1023,27 @@ function RESCUEHELO:onafterRun(From, Event, To)
|
||||
end
|
||||
|
||||
|
||||
--- Function called when a group is passing a waypoint.
|
||||
--@param Wrapper.Group#GROUP group Group that passed the waypoint
|
||||
--@param #RESCUEHELO rescuehelo Rescue helo object.
|
||||
function RESCUEHELO._TaskRTB(group, rescuehelo)
|
||||
env.info(string.format("FF Executing TaskRTB for group %s.", group:GetName()))
|
||||
--- Task to send the helo RTB.
|
||||
-- @param #RESCUEHELO self
|
||||
-- @return DCS#Task DCS Task table.
|
||||
function RESCUEHELO:_TaskRTB()
|
||||
|
||||
-- Set RTB switch so on next status update, the helo is respawned with RTB waypoints.
|
||||
rescuehelo.rtb=true
|
||||
--rescuehelo.rtb=true
|
||||
|
||||
-- Name of the warehouse (static) object.
|
||||
local carriername=self.carrier:GetName()
|
||||
|
||||
-- Task script.
|
||||
local DCSScript = {}
|
||||
DCSScript[#DCSScript+1] = string.format('local mycarrier = UNIT:FindByName(\"%s\") ', carriername) -- The carrier unit that holds the self object.
|
||||
DCSScript[#DCSScript+1] = string.format('local myhelo = mycarrier:GetState(mycarrier, \"RESCUEHELO_%d\") ', self.uid) -- Get the RECOVERYTANKER self object.
|
||||
DCSScript[#DCSScript+1] = string.format('myhelo:RTB()') -- Call the function, e.g. myhelo.(self)
|
||||
|
||||
-- Create task.
|
||||
local DCSTask = CONTROLLABLE.TaskWrappedAction(self, CONTROLLABLE.CommandDoScript(self, table.concat(DCSScript)))
|
||||
|
||||
return DCSTask
|
||||
|
||||
-- This made DCS crash to desktop!
|
||||
--rescuehelo:RTB()
|
||||
@@ -1035,7 +1054,7 @@ end
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Point#COORDINATE RescueCoord Coordinate where the rescue should happen
|
||||
-- @param Core.Point#COORDINATE RescueCoord Coordinate where the rescue should happen.
|
||||
function RESCUEHELO:onafterRescue(From, Event, To, RescueCoord)
|
||||
|
||||
-- Debug message.
|
||||
@@ -1056,7 +1075,8 @@ function RESCUEHELO:onafterRescue(From, Event, To, RescueCoord)
|
||||
RescueTask.params.stopCondition={duration=self.rescueduration}
|
||||
|
||||
-- Passing waypoint taskfunction
|
||||
local TaskRTB=self.helo:TaskFunction("RESCUEHELO._TaskRTB", self)
|
||||
--local TaskRTB=self.helo:TaskFunction("RESCUEHELO._TaskRTB", self)
|
||||
local TaskRTB=self:_TaskRTB()
|
||||
|
||||
-- Rescue speed 90% of max possible.
|
||||
local speed=self.helo:GetSpeedMax()*0.9
|
||||
@@ -1132,7 +1152,7 @@ function RESCUEHELO:onafterRTB(From, Event, To, airbase)
|
||||
end
|
||||
|
||||
-- Route helo back home. It is respawned! But this is the only way to ensure that it actually lands at the airbase.
|
||||
self.helo:RouteRTB(airbase)
|
||||
self:RouteRTB(airbase)
|
||||
end
|
||||
|
||||
--- On after Stop event. Unhandle events and stop status updates.
|
||||
@@ -1147,6 +1167,42 @@ function RESCUEHELO:onafterStop(From, Event, To)
|
||||
self:UnHandleEvent(EVENTS.Ejection)
|
||||
end
|
||||
|
||||
|
||||
--- Route helo back to its home base.
|
||||
-- @param #RESCUEHELO self
|
||||
-- @param Wrapper.Airbase#AIRBASE RTBAirbase
|
||||
-- @param #number Speed Speed.
|
||||
function RESCUEHELO:RouteRTB(RTBAirbase, Speed)
|
||||
|
||||
-- If speed is not given take 80% of max speed.
|
||||
local Speed=Speed or self.helo:GetSpeedMax()*0.8
|
||||
|
||||
-- Curent (from) waypoint.
|
||||
local coord=self.helo:GetCoordinate()
|
||||
local PointFrom=coord:WaypointAirTurningPoint(nil, Speed)
|
||||
|
||||
-- Airbase coordinate.
|
||||
local PointAirbase=RTBAirbase:GetCoordinate():SetAltitude(100):WaypointAirTurningPoint(nil ,Speed)
|
||||
|
||||
-- Landing waypoint. More general than prev version since it should also work with FAPRS and ships.
|
||||
local PointLanding=RTBAirbase:GetCoordinate():SetAltitude(20):WaypointAirLanding(Speed, RTBAirbase)
|
||||
|
||||
-- Waypoint table.
|
||||
local Points={PointFrom, PointLanding}
|
||||
|
||||
-- Get group template.
|
||||
local Template=self.helo:GetTemplate()
|
||||
|
||||
-- Set route points.
|
||||
Template.route.points=Points
|
||||
|
||||
-- Respawn the group.
|
||||
self.helo=self.helo:Respawn(Template, true)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user