mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-23 08:29:30 +00:00
Ops & MARKER
This commit is contained in:
@@ -37,7 +37,7 @@ __Moose.Include( 'Scripts/Moose/Wrapper/Client.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Static.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Airbase.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Scenery.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Mark.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/Marker.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Wrapper/DCSTask.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Cargo/Cargo.lua' )
|
||||
|
||||
@@ -196,9 +196,9 @@ function AIRWING:AddSquadron(Squadron)
|
||||
|
||||
-- Tanker and AWACS get unlimited payloads.
|
||||
if Squadron.attribute==GROUP.Attribute.AIR_AWACS then
|
||||
self:NewPayload(Squadron.templategroup, AUFTRAG.Type.AWACS, 1, true)
|
||||
self:NewPayload(Squadron.templategroup, -1, AUFTRAG.Type.AWACS)
|
||||
elseif Squadron.attribute==GROUP.Attribute.AIR_TANKER then
|
||||
self:NewPayload(Squadron.templategroup, AUFTRAG.Type.TANKER, 1, true)
|
||||
self:NewPayload(Squadron.templategroup, -1, AUFTRAG.Type.TANKER)
|
||||
end
|
||||
|
||||
-- Set airwing to squadron.
|
||||
@@ -215,12 +215,11 @@ end
|
||||
--- Add a **new** payload to the airwing resources.
|
||||
-- @param #AIRWING self
|
||||
-- @param Wrapper.Unit#UNIT Unit The unit, the payload is extracted from. Can also be given as *#string* name of the unit.
|
||||
-- @param #number Npayloads Number of payloads to add to the airwing resources. Default 99 (which should be enough for most scenarios). Set to -1 for unlimited.
|
||||
-- @param #table MissionTypes Mission types this payload can be used for.
|
||||
-- @param #number Npayloads Number of payloads to add to the airwing resources. Default 99 (which should be enough for most scenarios).
|
||||
-- @param #boolean Unlimited If true, this payload is unlimited.
|
||||
-- @param #number Performance A number between 0 (worst) and 100 (best) to describe the performance of the loadout for the given mission types. Default is 50.
|
||||
-- @return #AIRWING.Payload The payload table or nil if the unit does not exist.
|
||||
function AIRWING:NewPayload(Unit, MissionTypes, Npayloads, Unlimited, Performance)
|
||||
function AIRWING:NewPayload(Unit, Npayloads, MissionTypes, Performance)
|
||||
|
||||
-- Default performance.
|
||||
Performance=Performance or 50
|
||||
@@ -249,10 +248,11 @@ function AIRWING:NewPayload(Unit, MissionTypes, Npayloads, Unlimited, Performanc
|
||||
payload.unitname=Unit:GetName()
|
||||
payload.aircrafttype=Unit:GetTypeName()
|
||||
payload.pylons=Unit:GetTemplatePayload()
|
||||
payload.navail=Npayloads or 99
|
||||
payload.unlimited=Unlimited
|
||||
if Unlimited then
|
||||
payload.unlimited=Npayloads<0
|
||||
if payload.unlimited then
|
||||
payload.navail=1
|
||||
else
|
||||
payload.navail=Npayloads or 99
|
||||
end
|
||||
|
||||
payload.capabilities={}
|
||||
@@ -886,7 +886,19 @@ end
|
||||
--- Check how many AWACS missions are assigned and add number of missing missions.
|
||||
-- @param #AIRWING self
|
||||
-- @return #AIRWING self
|
||||
function AIRWING:CheckRecoveryTanker()
|
||||
function AIRWING:CheckRescuhelo()
|
||||
|
||||
local N=self:CountMissionsInQueue({AUFTRAG.Type.RESCUEHELO})
|
||||
|
||||
for i=1,self.nflightsRescuehelo-N do
|
||||
|
||||
local mission=AUFTRAG:NewRESCUEHELO(self.airbase)
|
||||
|
||||
self:AddMission(mission)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -404,12 +404,15 @@ end
|
||||
|
||||
--- Create a RESCUE HELO mission.
|
||||
-- @param #AUFTRAG self
|
||||
-- @param Wrapper.UnitUNIT Carrier The carrier unit.
|
||||
-- @param Wrapper.Unit#UNIT Carrier The carrier unit.
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:NewRESCUEHELO(Carrier)
|
||||
|
||||
local mission=AUFTRAG:New(AUFTRAG.Type.RESCUEHELO)
|
||||
|
||||
mission.engageTarget=mission:_TargetFromObject(Carrier)
|
||||
|
||||
--[[
|
||||
mission.engageTarget=mission:_TargetFromObject(Target)
|
||||
mission.engageWeaponType=ENUMS.WeaponFlag.Auto
|
||||
|
||||
@@ -417,6 +420,7 @@ function AUFTRAG:NewRESCUEHELO(Carrier)
|
||||
mission.missionFraction=0.4
|
||||
mission.optionROE=ENUMS.ROE.OpenFire
|
||||
mission.optionROT=ENUMS.ROT.EvadeFire
|
||||
]]
|
||||
|
||||
mission.DCStask=mission:GetDCSMissionTask()
|
||||
|
||||
@@ -2027,7 +2031,8 @@ function AUFTRAG:GetTargetName()
|
||||
if self.engageTarget then
|
||||
if self.engageTarget.Type==AUFTRAG.TargetType.COORDINATE then
|
||||
local coord=self.engageTarget.Target --Core.Point#COORDINATE
|
||||
return coord:ToStringLLDMS()
|
||||
return coord:ToStringMGRS()
|
||||
--return coord:ToStringLLDMS()
|
||||
else
|
||||
return self.engageTarget.Target:GetName()
|
||||
end
|
||||
@@ -2315,11 +2320,11 @@ function AUFTRAG:GetDCSMissionTask()
|
||||
DCStask.id="Formation"
|
||||
|
||||
local param={}
|
||||
param.unitname=""
|
||||
param.unitname=self:GetTargetName()
|
||||
param.offsetX=20
|
||||
param.offsetY=20
|
||||
param.offsetZ=20
|
||||
param.alitude=70
|
||||
param.altitude=70
|
||||
|
||||
DCStask.params=param
|
||||
|
||||
|
||||
@@ -1138,10 +1138,11 @@ function FLIGHTGROUP:StartUncontrolled(delay)
|
||||
|
||||
if self:IsAlive() then
|
||||
--TODO: check Alive==true and Alive==false ==> Activate first
|
||||
self:T(self.lid.."Starting uncontrolled group")
|
||||
self:I(self.lid.."Starting uncontrolled group")
|
||||
self.group:StartUncontrolled(delay)
|
||||
else
|
||||
self:E(self.lid.."ERROR: Could not start uncontrolled group as it is NOT alive (yet)!")
|
||||
self.group:StartUncontrolled(delay)
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -3641,6 +3642,9 @@ function FLIGHTGROUP:onbeforeMissionStart(From, Event, To, Mission)
|
||||
-- Startup group if it is uncontrolled.
|
||||
if self:IsParking() and self:IsUncontrolled() then
|
||||
self:StartUncontrolled(delay)
|
||||
else
|
||||
env.info("FF hallo!")
|
||||
self:StartUncontrolled(1)
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
@@ -1,345 +0,0 @@
|
||||
--- **Wrapper** - Markers On the F10 map.
|
||||
--
|
||||
--
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Manage aircraft recovery.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
-- @module Wrapper.Marker
|
||||
-- @image Wrapper_Marker.png
|
||||
|
||||
|
||||
--- Marker class.
|
||||
-- @type MARKER
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #boolean Debug Debug mode. Messages to all about status.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #number mid Marker ID.
|
||||
-- @field Core.Point#COORDINATE coordinate Coordinate of the mark.
|
||||
-- @field #string text Text displayed in the mark panel.
|
||||
-- @field #string message Message dispayed when the mark is added.
|
||||
-- @field #boolean readonly Marker is read-only.
|
||||
-- @field #number coalition Coalition to which the marker is displayed.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- **Ground Control**: Airliner X, Good news, you are clear to taxi to the active.
|
||||
-- **Pilot**: Roger, What's the bad news?
|
||||
-- **Ground Control**: No bad news at the moment, but you probably want to get gone before I find any.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- # The MARKER Concept
|
||||
--
|
||||
--
|
||||
--
|
||||
-- @field #MARKER
|
||||
MARKER = {
|
||||
ClassName = "MARKER",
|
||||
Debug = false,
|
||||
lid = nil,
|
||||
mid = nil,
|
||||
coordinate = nil,
|
||||
text = nil,
|
||||
message = nil,
|
||||
readonly = nil,
|
||||
coalition = nil,
|
||||
}
|
||||
|
||||
--- Holding point
|
||||
-- @type MARKER.HoldingPoint
|
||||
-- @field Core.Point#COORDINATE pos0 First poosition of racetrack holding point.
|
||||
-- @field Core.Point#COORDINATE pos1 Second position of racetrack holding point.
|
||||
-- @field #number angelsmin Smallest holding altitude in angels.
|
||||
-- @field #number angelsmax Largest holding alitude in angels.
|
||||
|
||||
|
||||
--- Marker class version.
|
||||
-- @field #string version
|
||||
MARKER.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Handle events.
|
||||
-- TODO: Some more...
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new MARKER class object.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate Coordinate where to place the marker.
|
||||
-- @param #string Text Text displayed on the mark panel.
|
||||
-- @return #MARKER self
|
||||
function MARKER:New(Coordinate, Text)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #MARKER
|
||||
|
||||
self.coordinate=Coordinate
|
||||
|
||||
self.text=Text
|
||||
|
||||
-- Defaults
|
||||
self.readonly=false
|
||||
self.message=""
|
||||
|
||||
-- Get ID.
|
||||
self.mid=UTILS.GetMarkID()
|
||||
|
||||
-- Start State.
|
||||
self:SetStartState("Stopped")
|
||||
|
||||
-- Add FSM transitions.
|
||||
-- From State --> Event --> To State
|
||||
self:AddTransition("*", "Added", "Shown") -- Marker was added.
|
||||
self:AddTransition("*", "Removed", "Shown") -- Marker was added.
|
||||
|
||||
self:AddTransition("*", "Change", "*") -- Update status.
|
||||
|
||||
-- Handle events.
|
||||
self:HandleEvent(EVENTS.MarkAdded)
|
||||
self:HandleEvent(EVENTS.MarkRemoved)
|
||||
self:HandleEvent(EVENTS.MarkChange)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User API Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Marker is readonly.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ReadOnly()
|
||||
|
||||
self.readonly=true
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Marker is readonly.
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text Message displayed when the marker is added.
|
||||
-- @return #MARKER self
|
||||
function MARKER:Message(Text)
|
||||
|
||||
self.message=Text or ""
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for everyone.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToAll()
|
||||
|
||||
self.toall=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToAll(self.mid, self.text, self.coordinate:GetVec3(), self.readonly, self.message)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for a specific coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Coalition Coalition 1=Red, 2=Blue, 0=Neutral. See `coaliton.side.RED`.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToCoalition(Coalition)
|
||||
|
||||
self.coalition=Coalition
|
||||
|
||||
self.tocoaliton=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToCoalition(self.mid, self.text, self.coordinate:GetVec3(), self.coalition, self.readonly, self.message)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the blue coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToBlue()
|
||||
self:ToCoalition(coalition.side.BLUE)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the blue coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToRed()
|
||||
self:ToCoalition(coalition.side.RED)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the neutral coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToNeutral()
|
||||
self:ToCoalition(coalition.side.NEUTRAL)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Place marker visible for a specific group only.
|
||||
-- @param #MARKER self
|
||||
-- @param Wrapper.Group#GROUP Group The group to which te
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToGroup(Group)
|
||||
|
||||
-- Check if group exists.
|
||||
if Group and Group:IsAlive()~=nil then
|
||||
|
||||
self.groupid=Group:GetID()
|
||||
|
||||
if self.groupid then
|
||||
|
||||
self.groupname=Group:GetName()
|
||||
|
||||
self.togroup=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToGroup(self.mid, self.text, self.coordinate:GetVec3(), self.groupid, self.readonly, self.message)
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
--TODO: Warning!
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Update the text displayed on the mark panel.
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text Updated text.
|
||||
-- @return #MARKER self
|
||||
function MARKER:UpdateText(Text)
|
||||
|
||||
self.text=Text
|
||||
|
||||
self:Refresh()
|
||||
|
||||
end
|
||||
|
||||
--- Update the coordinate where the marker is displayed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate The new coordinate.
|
||||
-- @return #MARKER self
|
||||
function MARKER:UpdateCoordinate(Coordinate)
|
||||
|
||||
self.coordinate=Coordinate
|
||||
|
||||
self:Refresh()
|
||||
|
||||
end
|
||||
|
||||
--- Refresh the marker.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:Refresh()
|
||||
|
||||
if self.toall then
|
||||
|
||||
self:ToAll()
|
||||
|
||||
elseif self.tocoaliton then
|
||||
|
||||
self:ToCoalition(self.coalition)
|
||||
|
||||
elseif self.togroup then
|
||||
|
||||
local group=GROUP:FindByName(self.groupname)
|
||||
|
||||
self:ToGroup(group)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Remove a marker.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:Remove()
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.removeMark(self.mid)
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Event Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Event function when a MARKER is added.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkAdded(EventData)
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
self.shown=true
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Event function when a MARKER is removed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkRemoved(EventData)
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
self.shown=false
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Event function when a MARKER changed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkChange(EventData)
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,687 @@
|
||||
--- **Wrapper** - Markers On the F10 map.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Convenient handling of markers via multiple user API functions.
|
||||
-- * Update text and position of marker easily via scripting.
|
||||
-- * Delay creation and removal of markers via (optional) parameters.
|
||||
-- * Retrieve data such as text and coordinate.
|
||||
-- * Marker specific FSM events when a marker is added, removed or changed.
|
||||
-- * Additional FSM events when marker text or position is changed.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
-- @module Wrapper.Marker
|
||||
-- @image Wrapper_Marker.png
|
||||
|
||||
|
||||
--- Marker class.
|
||||
-- @type MARKER
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #boolean Debug Debug mode. Messages to all about status.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #number mid Marker ID.
|
||||
-- @field Core.Point#COORDINATE coordinate Coordinate of the mark.
|
||||
-- @field #string text Text displayed in the mark panel.
|
||||
-- @field #string message Message dispayed when the mark is added.
|
||||
-- @field #boolean readonly Marker is read-only.
|
||||
-- @field #number coalition Coalition to which the marker is displayed.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- **Ground Control**: Airliner X, Good news, you are clear to taxi to the active.
|
||||
-- **Pilot**: Roger, What's the bad news?
|
||||
-- **Ground Control**: No bad news at the moment, but you probably want to get gone before I find any.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- # The MARKER Class Idea
|
||||
--
|
||||
-- # Creat a Marker
|
||||
--
|
||||
-- ## For Everyone
|
||||
--
|
||||
-- ## For a Coaliton
|
||||
--
|
||||
-- ## For a Group
|
||||
--
|
||||
--
|
||||
-- # Update a Marker
|
||||
--
|
||||
-- ## Update Text
|
||||
--
|
||||
-- ## Update Coordinate
|
||||
--
|
||||
--
|
||||
-- # Retrieve Data
|
||||
--
|
||||
-- ## Text
|
||||
--
|
||||
-- ## Coordinate
|
||||
--
|
||||
--
|
||||
-- # FSM Events
|
||||
--
|
||||
-- ## Added
|
||||
--
|
||||
-- ## Changed
|
||||
--
|
||||
-- ## Removed
|
||||
--
|
||||
--
|
||||
-- # Examples
|
||||
--
|
||||
--
|
||||
-- @field #MARKER
|
||||
MARKER = {
|
||||
ClassName = "MARKER",
|
||||
Debug = false,
|
||||
lid = nil,
|
||||
mid = nil,
|
||||
coordinate = nil,
|
||||
text = nil,
|
||||
message = nil,
|
||||
readonly = nil,
|
||||
coalition = nil,
|
||||
}
|
||||
|
||||
--- Marker ID. Running number.
|
||||
_MARKERID=0
|
||||
|
||||
--- Marker class version.
|
||||
-- @field #string version
|
||||
MARKER.version="0.1.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: User "Get" functions. E.g., :GetCoordinate()
|
||||
-- DONE: Add delay to user functions.
|
||||
-- DONE: Handle events.
|
||||
-- DONE: Create FSM events.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new MARKER class object.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate Coordinate where to place the marker.
|
||||
-- @param #string Text Text displayed on the mark panel.
|
||||
-- @return #MARKER self
|
||||
function MARKER:New(Coordinate, Text)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #MARKER
|
||||
|
||||
self.coordinate=Coordinate
|
||||
|
||||
self.text=Text
|
||||
|
||||
-- Defaults
|
||||
self.readonly=false
|
||||
self.message=""
|
||||
|
||||
-- New marker ID. This is not the one of the actual marker.
|
||||
_MARKERID=_MARKERID+1
|
||||
|
||||
self.myid=_MARKERID
|
||||
|
||||
-- Log ID.
|
||||
self.lid=string.format("Marker #%d | ", self.myid)
|
||||
|
||||
-- Start State.
|
||||
self:SetStartState("Invisible")
|
||||
|
||||
-- Add FSM transitions.
|
||||
-- From State --> Event --> To State
|
||||
self:AddTransition("Invisible", "Added", "Visible") -- Marker was added.
|
||||
self:AddTransition("Visible", "Removed", "Invisible") -- Marker was removed.
|
||||
self:AddTransition("*", "Changed", "*") -- Marker was changed.
|
||||
|
||||
self:AddTransition("*", "TextUpdate", "*") -- Text updated.
|
||||
self:AddTransition("*", "CoordUpdate", "*") -- Coordinates updated.
|
||||
|
||||
--- Triggers the FSM event "Added".
|
||||
-- @function [parent=#MARKER] Added
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- Triggers the delayed FSM event "Added".
|
||||
-- @function [parent=#MARKER] __Added
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- On after "Added" event user function.
|
||||
-- @function [parent=#MARKER] OnAfterAdded
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Removed".
|
||||
-- @function [parent=#MARKER] Removed
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- Triggers the delayed FSM event "Removed".
|
||||
-- @function [parent=#MARKER] __Removed
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- On after "Removed" event user function.
|
||||
-- @function [parent=#MARKER] OnAfterRemoved
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Changed".
|
||||
-- @function [parent=#MARKER] Changed
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- Triggers the delayed FSM event "Changed".
|
||||
-- @function [parent=#MARKER] __Changed
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
--- On after "Changed" event user function.
|
||||
-- @function [parent=#MARKER] OnAfterChanged
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
|
||||
|
||||
--- Triggers the FSM event "TextUpdate".
|
||||
-- @function [parent=#MARKER] TextUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text The new text.
|
||||
|
||||
--- Triggers the delayed FSM event "TextUpdate".
|
||||
-- @function [parent=#MARKER] __TextUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text The new text.
|
||||
|
||||
--- On after "TextUpdate" event user function.
|
||||
-- @function [parent=#MARKER] OnAfterTextUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #string Text The new text.
|
||||
|
||||
|
||||
--- Triggers the FSM event "CoordUpdate".
|
||||
-- @function [parent=#MARKER] CoordUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate The new Coordinate.
|
||||
|
||||
--- Triggers the delayed FSM event "CoordUpdate".
|
||||
-- @function [parent=#MARKER] __CoordUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate The updated Coordinate.
|
||||
|
||||
--- On after "CoordUpdate" event user function.
|
||||
-- @function [parent=#MARKER] OnAfterCoordUpdate
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Point#COORDINATE Coordinate The updated Coordinate.
|
||||
|
||||
|
||||
-- Handle events.
|
||||
self:HandleEvent(EVENTS.MarkAdded)
|
||||
self:HandleEvent(EVENTS.MarkRemoved)
|
||||
self:HandleEvent(EVENTS.MarkChange)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User API Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Marker is readonly. Text cannot be changed and marker cannot be removed.
|
||||
-- @param #MARKER self
|
||||
-- @return #MARKER self
|
||||
function MARKER:ReadOnly()
|
||||
|
||||
self.readonly=true
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set message that is displayed on screen if the marker is added.
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text Message displayed when the marker is added.
|
||||
-- @return #MARKER self
|
||||
function MARKER:Message(Text)
|
||||
|
||||
self.message=Text or ""
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for everyone.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToAll(Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.ToAll, self)
|
||||
else
|
||||
|
||||
self.toall=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
self.mid=UTILS.GetMarkID()
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToAll(self.mid, self.text, self.coordinate:GetVec3(), self.readonly, self.message)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for a specific coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Coalition Coalition 1=Red, 2=Blue, 0=Neutral. See `coaliton.side.RED`.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToCoalition(Coalition, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.ToCoalition, self, Coalition)
|
||||
else
|
||||
|
||||
self.coalition=Coalition
|
||||
|
||||
self.tocoaliton=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
self.mid=UTILS.GetMarkID()
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToCoalition(self.mid, self.text, self.coordinate:GetVec3(), self.coalition, self.readonly, self.message)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the blue coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToBlue(Delay)
|
||||
self:ToCoalition(coalition.side.BLUE, Delay)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the blue coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToRed(Delay)
|
||||
self:ToCoalition(coalition.side.RED, Delay)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Place marker visible for the neutral coalition only.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToNeutral(Delay)
|
||||
self:ToCoalition(coalition.side.NEUTRAL, Delay)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Place marker visible for a specific group only.
|
||||
-- @param #MARKER self
|
||||
-- @param Wrapper.Group#GROUP Group The group to which the marker is displayed.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:ToGroup(Group, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.ToGroup, self, Group)
|
||||
else
|
||||
|
||||
-- Check if group exists.
|
||||
if Group and Group:IsAlive()~=nil then
|
||||
|
||||
self.groupid=Group:GetID()
|
||||
|
||||
if self.groupid then
|
||||
|
||||
self.groupname=Group:GetName()
|
||||
|
||||
self.togroup=true
|
||||
|
||||
-- First remove an existing mark.
|
||||
if self.shown then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
self.mid=UTILS.GetMarkID()
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.markToGroup(self.mid, self.text, self.coordinate:GetVec3(), self.groupid, self.readonly, self.message)
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
--TODO: Warning!
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Update the text displayed on the mark panel.
|
||||
-- @param #MARKER self
|
||||
-- @param #string Text Updated text.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:UpdateText(Text, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.UpdateText, self, Text)
|
||||
else
|
||||
|
||||
self.text=tostring(Text)
|
||||
|
||||
self:Refresh()
|
||||
|
||||
self:TextUpdate(tostring(Text))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Update the coordinate where the marker is displayed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Point#COORDINATE Coordinate The new coordinate.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:UpdateCoordinate(Coordinate, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.UpdateCoordinate, self, Coordinate)
|
||||
else
|
||||
|
||||
self.coordinate=Coordinate
|
||||
|
||||
self:Refresh()
|
||||
|
||||
self:CoordUpdate(Coordinate)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Refresh the marker.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:Refresh(Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.Refresh, self)
|
||||
else
|
||||
|
||||
if self.toall then
|
||||
|
||||
self:ToAll()
|
||||
|
||||
elseif self.tocoaliton then
|
||||
|
||||
self:ToCoalition(self.coalition)
|
||||
|
||||
elseif self.togroup then
|
||||
|
||||
local group=GROUP:FindByName(self.groupname)
|
||||
|
||||
self:ToGroup(group)
|
||||
|
||||
else
|
||||
self:E(self.lid.."ERROR: unknown To in :Refresh()!")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Remove a marker.
|
||||
-- @param #MARKER self
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the marker is created.
|
||||
-- @return #MARKER self
|
||||
function MARKER:Remove(Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MARKER.Remove, self)
|
||||
else
|
||||
|
||||
-- Call DCS function.
|
||||
trigger.action.removeMark(self.mid)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Get position of the marker.
|
||||
-- @param #MARKER self
|
||||
-- @return Core.Point#COORDINATE The coordinate of the marker.
|
||||
function MARKER:GetCoordinate()
|
||||
return self.coordinate
|
||||
end
|
||||
|
||||
--- Get text that is dispayed in the marker panal.
|
||||
-- @param #MARKER self
|
||||
-- @return #string Marker text.
|
||||
function MARKER:GetText()
|
||||
return self.text
|
||||
end
|
||||
|
||||
|
||||
--- Check if marker is currently visible on the F10 map.
|
||||
-- @param #MARKER self
|
||||
-- @return #boolean True if the marker is currently visible.
|
||||
function MARKER:IsVisible()
|
||||
return self:Is("Visible")
|
||||
end
|
||||
|
||||
--- Check if marker is currently invisible on the F10 map.
|
||||
-- @param #MARKER self
|
||||
-- @return
|
||||
function MARKER:IsInvisible()
|
||||
return self:Is("Invisible")
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Event Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Event function when a MARKER is added.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkAdded(EventData)
|
||||
|
||||
if EventData and EventData.MarkID then
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
self:T3(self.lid..string.format("Captured event MarkAdded for Mark ID=%s", tostring(MarkID)))
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
self.shown=true
|
||||
|
||||
self:Added(EventData)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Event function when a MARKER is removed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkRemoved(EventData)
|
||||
|
||||
if EventData and EventData.MarkID then
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
self:T3(self.lid..string.format("Captured event MarkAdded for Mark ID=%s", tostring(MarkID)))
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
self.shown=false
|
||||
|
||||
self:Removed(EventData)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Event function when a MARKER changed.
|
||||
-- @param #MARKER self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function MARKER:OnEventMarkChange(EventData)
|
||||
|
||||
if EventData and EventData.MarkID then
|
||||
|
||||
local MarkID=EventData.MarkID
|
||||
|
||||
self:T3(self.lid..string.format("Captured event MarkChange for Mark ID=%s", tostring(MarkID)))
|
||||
|
||||
if MarkID==self.mid then
|
||||
|
||||
self:Changed(EventData)
|
||||
|
||||
self:TextChanged(tostring(EventData.MarkText))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- FSM Event Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- On after "Added" event.
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
function MARKER:onafterAdded(From, Event, To, EventData)
|
||||
|
||||
-- Debug info.
|
||||
local text=string.format("Captured event MarkAdded for myself:\n")
|
||||
text=text..string.format("Marker ID = %s\n", tostring(EventData.MarkID))
|
||||
text=text..string.format("Coalition = %s\n", tostring(EventData.MarkCoalition))
|
||||
text=text..string.format("Group ID = %s\n", tostring(EventData.MarkGroupID))
|
||||
text=text..string.format("Initiator = %s\n", EventData.IniUnit and EventData.IniUnit:GetName() or "Nobody")
|
||||
text=text..string.format("Coordinate = %s\n", EventData.MarkCoordinate and EventData.MarkCoordinate:ToStringLLDMS() or "Nowhere")
|
||||
text=text..string.format("Text: \n%s", tostring(EventData.MarkText))
|
||||
self:T2(self.lid..text)
|
||||
|
||||
end
|
||||
|
||||
--- On after "Removed" event.
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
function MARKER:onafterRemoved(From, Event, To, EventData)
|
||||
|
||||
-- Debug info.
|
||||
local text=string.format("Captured event MarkRemoved for myself:\n")
|
||||
text=text..string.format("Marker ID = %s\n", tostring(EventData.MarkID))
|
||||
text=text..string.format("Coalition = %s\n", tostring(EventData.MarkCoalition))
|
||||
text=text..string.format("Group ID = %s\n", tostring(EventData.MarkGroupID))
|
||||
text=text..string.format("Initiator = %s\n", EventData.IniUnit and EventData.IniUnit:GetName() or "Nobody")
|
||||
text=text..string.format("Coordinate = %s\n", EventData.MarkCoordinate and EventData.MarkCoordinate:ToStringLLDMS() or "Nowhere")
|
||||
text=text..string.format("Text: \n%s", tostring(EventData.MarkText))
|
||||
self:T2(self.lid..text)
|
||||
|
||||
end
|
||||
|
||||
--- On after "Changed" event.
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Event#EVENTDATA EventData Event data table.
|
||||
function MARKER:onafterChanged(From, Event, To, EventData)
|
||||
|
||||
-- Debug info.
|
||||
local text=string.format("Captured event MarkChange for myself:\n")
|
||||
text=text..string.format("Marker ID = %s\n", tostring(EventData.MarkID))
|
||||
text=text..string.format("Coalition = %s\n", tostring(EventData.MarkCoalition))
|
||||
text=text..string.format("Group ID = %s\n", tostring(EventData.MarkGroupID))
|
||||
text=text..string.format("Initiator = %s\n", EventData.IniUnit and EventData.IniUnit:GetName() or "Nobody")
|
||||
text=text..string.format("Coordinate = %s\n", EventData.MarkCoordinate and EventData.MarkCoordinate:ToStringLLDMS() or "Nowhere")
|
||||
text=text..string.format("Text: \n%s", tostring(EventData.MarkText))
|
||||
self:T2(self.lid..text)
|
||||
|
||||
end
|
||||
|
||||
--- On after "TextUpdate" event.
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #string Text The updated text, displayed in the mark panel.
|
||||
function MARKER:onafterTextUpdate(From, Event, To, Text)
|
||||
|
||||
self:I(self.lid..string.format("New Marker Text:\n%s", Text))
|
||||
|
||||
end
|
||||
|
||||
--- On after "CoordUpdate" event.
|
||||
-- @param #MARKER self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Core.Point#COORDINATE Coordinate The updated coordinates.
|
||||
function MARKER:onafterCoordUpdate(From, Event, To, Coordinate)
|
||||
|
||||
self:I(self.lid..string.format("New Marker Coordinate in LL DMS: %s", Coordinate:ToStringLLDMS()))
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -33,6 +33,7 @@ Wrapper/Client.lua
|
||||
Wrapper/Static.lua
|
||||
Wrapper/Airbase.lua
|
||||
Wrapper/Scenery.lua
|
||||
Wrapper/Marker.lua
|
||||
|
||||
Cargo/Cargo.lua
|
||||
Cargo/CargoUnit.lua
|
||||
@@ -62,7 +63,6 @@ Functional/Fox.lua
|
||||
Functional/RAT2.lua
|
||||
Functional/RatCraft.lua
|
||||
Functional/FlightModelData.lua
|
||||
Functional/SWAPR.lua
|
||||
|
||||
Ops/Airboss.lua
|
||||
Ops/RecoveryTanker.lua
|
||||
|
||||
Reference in New Issue
Block a user