Compare commits

..

3 Commits

Author SHA1 Message Date
kaltokri
4c66fd7cab Renamed basic.md to concepts.md and added more text 2024-01-22 17:36:32 +01:00
kaltokri
80f76b26c2 Small fixes in advanced guide 2024-01-19 16:57:33 +01:00
kaltokri
4e956c3203 New guides added 2024-01-19 11:41:09 +01:00
82 changed files with 4644 additions and 12178 deletions

View File

@@ -5,8 +5,6 @@ on:
branches:
- master
- develop
- Apple/Develop
paths:
- 'Moose Setup/**/*.lua'
- 'Moose Development/**/*.lua'
@@ -49,7 +47,6 @@ jobs:
- name: Update apt-get (needed for act docker image)
run: |
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get -qq update
- name: Install tree

View File

@@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
@@ -43,7 +43,7 @@ jobs:
working-directory: docs/
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
uses: actions/configure-pages@v3
- name: Build with Jekyll
# Outputs to the './_site' directory by default
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
@@ -52,7 +52,7 @@ jobs:
working-directory: docs/
- name: Upload artifact
# Automatically uploads an artifact from the './_site' directory by default
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v1
with:
path: docs/_site/
@@ -66,13 +66,13 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v1
check:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v3
- run: npm install linkinator
- run: npx linkinator https://flightcontrol-master.github.io/MOOSE/ --verbosity error --timeout 5000 --recurse --skip "(java.com)" --retry-errors --retry-errors-count 3 --retry-errors-jitter

View File

@@ -1151,14 +1151,14 @@ do -- AI_A2A_DISPATCHER
local AirbaseName = EventData.PlaceName -- The name of the airbase that was captured.
self:T( "Captured " .. AirbaseName )
self:I( "Captured " .. AirbaseName )
-- Now search for all squadrons located at the airbase, and sanitize them.
for SquadronName, Squadron in pairs( self.DefenderSquadrons ) do
if Squadron.AirbaseName == AirbaseName then
Squadron.ResourceCount = -999 -- The base has been captured, and the resources are eliminated. No more spawning.
Squadron.Captured = true
self:T( "Squadron " .. SquadronName .. " captured." )
self:I( "Squadron " .. SquadronName .. " captured." )
end
end
end
@@ -1828,7 +1828,7 @@ do -- AI_A2A_DISPATCHER
self:SetSquadronCapInterval( SquadronName, self.DefenderDefault.CapLimit, self.DefenderDefault.CapMinSeconds, self.DefenderDefault.CapMaxSeconds, 1 )
self:T( { CAP = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, Zone, PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageAltType } } )
self:I( { CAP = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, Zone, PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageAltType } } )
-- Add the CAP to the EWR network.
@@ -2085,7 +2085,7 @@ do -- AI_A2A_DISPATCHER
Intercept.EngageCeilingAltitude = EngageCeilingAltitude
Intercept.EngageAltType = EngageAltType
self:T( { GCI = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { GCI = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
end
--- Set squadron GCI.
@@ -3000,17 +3000,17 @@ do -- AI_A2A_DISPATCHER
for FriendlyDistance, AIFriendly in UTILS.spairs( DefenderFriendlies or {} ) do
-- We only allow to ENGAGE targets as long as the Units on both sides are balanced.
if AttackerCount > DefenderCount then
--self:T("***** AI_A2A_DISPATCHER:CountDefendersToBeEngaged() *****\nThis is supposed to be a UNIT:")
--self:I("***** AI_A2A_DISPATCHER:CountDefendersToBeEngaged() *****\nThis is supposed to be a UNIT:")
if AIFriendly then
local classname = AIFriendly.ClassName or "No Class Name"
local unitname = AIFriendly.IdentifiableName or "No Unit Name"
--self:T("Class Name: " .. classname)
--self:T("Unit Name: " .. unitname)
--self:T({AIFriendly})
--self:I("Class Name: " .. classname)
--self:I("Unit Name: " .. unitname)
--self:I({AIFriendly})
end
local Friendly = nil
if AIFriendly and AIFriendly:IsAlive() then
--self:T("AIFriendly alive, getting GROUP")
--self:I("AIFriendly alive, getting GROUP")
Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP
end
@@ -3952,7 +3952,7 @@ end
do
-- @type AI_A2A_GCICAP
--- @type AI_A2A_GCICAP
-- @extends #AI_A2A_DISPATCHER
--- Create an automatic air defence system for a coalition setting up GCI and CAP air defenses.
@@ -4322,23 +4322,23 @@ do
-- Setup squadrons
self:T( { Airbases = AirbaseNames } )
self:I( { Airbases = AirbaseNames } )
self:T( "Defining Templates for Airbases ..." )
self:I( "Defining Templates for Airbases ..." )
for AirbaseID, AirbaseName in pairs( AirbaseNames ) do
local Airbase = _DATABASE:FindAirbase( AirbaseName ) -- Wrapper.Airbase#AIRBASE
local AirbaseName = Airbase:GetName()
local AirbaseCoord = Airbase:GetCoordinate()
local AirbaseZone = ZONE_RADIUS:New( "Airbase", AirbaseCoord:GetVec2(), 3000 )
local Templates = nil
self:T( { Airbase = AirbaseName } )
self:I( { Airbase = AirbaseName } )
for TemplateID, Template in pairs( self.Templates:GetSet() ) do
local Template = Template -- Wrapper.Group#GROUP
local TemplateCoord = Template:GetCoordinate()
if AirbaseZone:IsVec2InZone( TemplateCoord:GetVec2() ) then
Templates = Templates or {}
table.insert( Templates, Template:GetName() )
self:T( { Template = Template:GetName() } )
self:I( { Template = Template:GetName() } )
end
end
if Templates then
@@ -4354,13 +4354,13 @@ do
self.CAPTemplates:FilterPrefixes( CapPrefixes )
self.CAPTemplates:FilterOnce()
self:T( "Setting up CAP ..." )
self:I( "Setting up CAP ..." )
for CAPID, CAPTemplate in pairs( self.CAPTemplates:GetSet() ) do
local CAPZone = ZONE_POLYGON:New( CAPTemplate:GetName(), CAPTemplate )
-- Now find the closest airbase from the ZONE (start or center)
local AirbaseDistance = 99999999
local AirbaseClosest = nil -- Wrapper.Airbase#AIRBASE
self:T( { CAPZoneGroup = CAPID } )
self:I( { CAPZoneGroup = CAPID } )
for AirbaseID, AirbaseName in pairs( AirbaseNames ) do
local Airbase = _DATABASE:FindAirbase( AirbaseName ) -- Wrapper.Airbase#AIRBASE
local AirbaseName = Airbase:GetName()
@@ -4368,7 +4368,7 @@ do
local Squadron = self.DefenderSquadrons[AirbaseName]
if Squadron then
local Distance = AirbaseCoord:Get2DDistance( CAPZone:GetCoordinate() )
self:T( { AirbaseDistance = Distance } )
self:I( { AirbaseDistance = Distance } )
if Distance < AirbaseDistance then
AirbaseDistance = Distance
AirbaseClosest = Airbase
@@ -4376,7 +4376,7 @@ do
end
end
if AirbaseClosest then
self:T( { CAPAirbase = AirbaseClosest:GetName() } )
self:I( { CAPAirbase = AirbaseClosest:GetName() } )
self:SetSquadronCap( AirbaseClosest:GetName(), CAPZone, 6000, 10000, 500, 800, 800, 1200, "RADIO" )
self:SetSquadronCapInterval( AirbaseClosest:GetName(), CapLimit, 300, 600, 1 )
end
@@ -4384,14 +4384,14 @@ do
-- Setup GCI.
-- GCI is setup for all Squadrons.
self:T( "Setting up GCI ..." )
self:I( "Setting up GCI ..." )
for AirbaseID, AirbaseName in pairs( AirbaseNames ) do
local Airbase = _DATABASE:FindAirbase( AirbaseName ) -- Wrapper.Airbase#AIRBASE
local AirbaseName = Airbase:GetName()
local Squadron = self.DefenderSquadrons[AirbaseName]
self:F( { Airbase = AirbaseName } )
if Squadron then
self:T( { GCIAirbase = AirbaseName } )
self:I( { GCIAirbase = AirbaseName } )
self:SetSquadronGci( AirbaseName, 800, 1200 )
end
end

View File

@@ -904,14 +904,14 @@ do -- AI_A2G_DISPATCHER
-- @type AI_A2G_DISPATCHER.DefenseCoordinates
-- @map <#string,Core.Point#COORDINATE> A list of all defense coordinates mapped per defense coordinate name.
-- @field #AI_A2G_DISPATCHER.DefenseCoordinates DefenseCoordinates
--- @field #AI_A2G_DISPATCHER.DefenseCoordinates DefenseCoordinates
AI_A2G_DISPATCHER.DefenseCoordinates = {}
--- Enumerator for spawns at airbases.
-- @type AI_A2G_DISPATCHER.Takeoff
-- @extends Wrapper.Group#GROUP.Takeoff
-- @field #AI_A2G_DISPATCHER.Takeoff Takeoff
--- @field #AI_A2G_DISPATCHER.Takeoff Takeoff
AI_A2G_DISPATCHER.Takeoff = GROUP.Takeoff
--- Defines Landing location.
@@ -942,7 +942,7 @@ do -- AI_A2G_DISPATCHER
-- @type AI_A2G_DISPATCHER.DefenseQueue
-- @list<#AI_A2G_DISPATCHER.DefenseQueueItem> DefenseQueueItem A list of all defenses being queued ...
-- @field #AI_A2G_DISPATCHER.DefenseQueue DefenseQueue
--- @field #AI_A2G_DISPATCHER.DefenseQueue DefenseQueue
AI_A2G_DISPATCHER.DefenseQueue = {}
--- Defense approach types.
@@ -1136,7 +1136,7 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:onafterStart( From, Event, To )
self:GetParent( self ).onafterStart( self, From, Event, To )
@@ -1147,7 +1147,7 @@ do -- AI_A2G_DISPATCHER
for Resource = 1, DefenderSquadron.ResourceCount or 0 do
self:ResourcePark( DefenderSquadron )
end
self:T( "Parked resources for squadron " .. DefenderSquadron.Name )
self:I( "Parked resources for squadron " .. DefenderSquadron.Name )
end
end
@@ -1201,7 +1201,7 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:ResourcePark( DefenderSquadron )
local TemplateID = math.random( 1, #DefenderSquadron.Spawn )
local Spawn = DefenderSquadron.Spawn[ TemplateID ] -- Core.Spawn#SPAWN
@@ -1218,33 +1218,33 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_DISPATCHER:OnEventBaseCaptured( EventData )
local AirbaseName = EventData.PlaceName -- The name of the airbase that was captured.
self:T( "Captured " .. AirbaseName )
self:I( "Captured " .. AirbaseName )
-- Now search for all squadrons located at the airbase, and sanitize them.
for SquadronName, Squadron in pairs( self.DefenderSquadrons ) do
if Squadron.AirbaseName == AirbaseName then
Squadron.ResourceCount = -999 -- The base has been captured, and the resources are eliminated. No more spawning.
Squadron.Captured = true
self:T( "Squadron " .. SquadronName .. " captured." )
self:I( "Squadron " .. SquadronName .. " captured." )
end
end
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_DISPATCHER:OnEventCrashOrDead( EventData )
self.Detection:ForgetDetectedUnit( EventData.IniUnitName )
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_DISPATCHER:OnEventLand( EventData )
self:F( "Landed" )
@@ -1261,7 +1261,7 @@ do -- AI_A2G_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ResourcePark( Squadron )
self:ResourcePark( Squadron, Defender )
return
end
if DefenderUnit:GetLife() ~= DefenderUnit:GetLife0() then
@@ -1273,7 +1273,7 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_DISPATCHER:OnEventEngineShutdown( EventData )
local DefenderUnit = EventData.IniUnit
@@ -1289,7 +1289,7 @@ do -- AI_A2G_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ResourcePark( Squadron )
self:ResourcePark( Squadron, Defender )
end
end
end
@@ -1297,7 +1297,7 @@ do -- AI_A2G_DISPATCHER
do -- Manage the defensive behaviour
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param #string DefenseCoordinateName The name of the coordinate to be defended by A2G defenses.
-- @param Core.Point#COORDINATE DefenseCoordinate The coordinate to be defended by A2G defenses.
function AI_A2G_DISPATCHER:AddDefenseCoordinate( DefenseCoordinateName, DefenseCoordinate )
@@ -1305,19 +1305,19 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:SetDefenseReactivityLow()
self.DefenseReactivity = 0.05
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:SetDefenseReactivityMedium()
self.DefenseReactivity = 0.15
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:SetDefenseReactivityHigh()
self.DefenseReactivity = 0.5
end
@@ -1351,14 +1351,14 @@ do -- AI_A2G_DISPATCHER
-- 1. the **distance of the closest airbase to target**, being smaller than the **Defend Radius**.
-- 2. the **distance to any defense reference point**.
--
-- The **default** defense radius is defined as **40000** or **40km**. Override the default defense radius when the era of the warfare is early, or,
-- The **default** defense radius is defined as **400000** or **40km**. Override the default defense radius when the era of the warfare is early, or,
-- when you don't want to let the AI_A2G_DISPATCHER react immediately when a certain border or area is not being crossed.
--
-- Use the method @{#AI_A2G_DISPATCHER.SetDefendRadius}() to set a specific defend radius for all squadrons,
-- **the Defense Radius is defined for ALL squadrons which are operational.**
--
-- @param #AI_A2G_DISPATCHER self
-- @param #number DefenseRadius (Optional, Default = 20000) The defense radius to engage detected targets from the nearest capable and available squadron airbase.
-- @param #number DefenseRadius (Optional, Default = 200000) The defense radius to engage detected targets from the nearest capable and available squadron airbase.
-- @return #AI_A2G_DISPATCHER
-- @usage
--
@@ -1373,7 +1373,7 @@ do -- AI_A2G_DISPATCHER
--
function AI_A2G_DISPATCHER:SetDefenseRadius( DefenseRadius )
self.DefenseRadius = DefenseRadius or 40000
self.DefenseRadius = DefenseRadius or 100000
self.Detection:SetAcceptRange( self.DefenseRadius )
@@ -1868,7 +1868,7 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
-- @param #string SquadronName The squadron name.
-- @param #number TakeoffInterval Only Takeoff new units each specified interval in seconds in 10 seconds steps.
-- @usage
@@ -2144,7 +2144,7 @@ do -- AI_A2G_DISPATCHER
Sead.EngageAltType = EngageAltType
Sead.Defend = true
self:T( { SEAD = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { SEAD = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
return self
end
@@ -2234,7 +2234,7 @@ do -- AI_A2G_DISPATCHER
self:SetSquadronPatrolInterval( SquadronName, self.DefenderDefault.PatrolLimit, self.DefenderDefault.PatrolMinSeconds, self.DefenderDefault.PatrolMaxSeconds, 1, "SEAD" )
self:T( { SEAD = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { SEAD = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
end
@@ -2295,7 +2295,7 @@ do -- AI_A2G_DISPATCHER
Cas.EngageAltType = EngageAltType
Cas.Defend = true
self:T( { CAS = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { CAS = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
return self
end
@@ -2385,7 +2385,7 @@ do -- AI_A2G_DISPATCHER
self:SetSquadronPatrolInterval( SquadronName, self.DefenderDefault.PatrolLimit, self.DefenderDefault.PatrolMinSeconds, self.DefenderDefault.PatrolMaxSeconds, 1, "CAS" )
self:T( { CAS = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { CAS = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
end
@@ -2446,7 +2446,7 @@ do -- AI_A2G_DISPATCHER
Bai.EngageAltType = EngageAltType
Bai.Defend = true
self:T( { BAI = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { BAI = { SquadronName, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
return self
end
@@ -2536,7 +2536,7 @@ do -- AI_A2G_DISPATCHER
self:SetSquadronPatrolInterval( SquadronName, self.DefenderDefault.PatrolLimit, self.DefenderDefault.PatrolMinSeconds, self.DefenderDefault.PatrolMaxSeconds, 1, "BAI" )
self:T( { BAI = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
self:I( { BAI = { Zone:GetName(), PatrolMinSpeed, PatrolMaxSpeed, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolAltType, EngageMinSpeed, EngageMaxSpeed, EngageFloorAltitude, EngageCeilingAltitude, EngageAltType } } )
end
@@ -3369,7 +3369,7 @@ do -- AI_A2G_DISPATCHER
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:AddDefenderToSquadron( Squadron, Defender, Size )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
@@ -3380,7 +3380,7 @@ do -- AI_A2G_DISPATCHER
self:F( { DefenderName = DefenderName, SquadronResourceCount = Squadron.ResourceCount } )
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_DISPATCHER:RemoveDefenderFromSquadron( Squadron, Defender )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
@@ -3796,7 +3796,7 @@ do -- AI_A2G_DISPATCHER
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_Fsm:onafterLostControl( DefenderGroup, From, Event, To )
self:F({"LostControl", DefenderGroup:GetName()})
self:GetParent(self).onafterHome( self, DefenderGroup, From, Event, To )
@@ -3813,7 +3813,7 @@ do -- AI_A2G_DISPATCHER
end
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_Fsm:onafterHome( DefenderGroup, From, Event, To, Action )
self:F({"Home", DefenderGroup:GetName()})
self:GetParent(self).onafterHome( self, DefenderGroup, From, Event, To )
@@ -3894,15 +3894,11 @@ do -- AI_A2G_DISPATCHER
local Squadron = Dispatcher:GetSquadronFromDefender( DefenderGroup )
if Squadron then
local FirstUnit = AttackSetUnit:GetRandomSurely()
if FirstUnit then
local FirstUnit = AttackSetUnit:GetFirst()
local Coordinate = FirstUnit:GetCoordinate() -- Core.Point#COORDINATE
if self.SetSendPlayerMessages then
Dispatcher:MessageToPlayers( Squadron, DefenderName .. ", on route to ground target at " .. Coordinate:ToStringA2G( DefenderGroup ), DefenderGroup )
end
else
return
end
end
self:GetParent(self).onafterEngageRoute( self, DefenderGroup, From, Event, To, AttackSetUnit )
end
@@ -3937,7 +3933,7 @@ do -- AI_A2G_DISPATCHER
Dispatcher:ClearDefenderTaskTarget( DefenderGroup )
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_Fsm:onafterLostControl( DefenderGroup, From, Event, To )
self:F({"Defender LostControl", DefenderGroup:GetName()})
self:GetParent(self).onafterHome( self, DefenderGroup, From, Event, To )
@@ -3954,7 +3950,7 @@ do -- AI_A2G_DISPATCHER
end
end
-- @param #AI_A2G_DISPATCHER self
--- @param #AI_A2G_DISPATCHER self
function AI_A2G_Fsm:onafterHome( DefenderGroup, From, Event, To, Action )
self:F({"Defender Home", DefenderGroup:GetName()})
self:GetParent(self).onafterHome( self, DefenderGroup, From, Event, To )
@@ -4788,5 +4784,4 @@ end
Squadron.ResourceCount = Squadron.ResourceCount - Amount
end
self:T({Squadron = Squadron.Name,SquadronResourceCount = Squadron.ResourceCount})
end
end

View File

@@ -9,8 +9,7 @@
-- @module AI.AI_Air
-- @image MOOSE.JPG
---
-- @type AI_AIR
--- @type AI_AIR
-- @extends Core.Fsm#FSM_CONTROLLABLE
--- The AI_AIR class implements the core functions to operate an AI @{Wrapper.Group}.
@@ -265,7 +264,7 @@ function AI_AIR:New( AIGroup )
return self
end
-- @param Wrapper.Group#GROUP self
--- @param Wrapper.Group#GROUP self
-- @param Core.Event#EVENTDATA EventData
function GROUP:OnEventTakeoff( EventData, Fsm )
Fsm:Takeoff()
@@ -447,13 +446,13 @@ function AI_AIR:onafterReturn( Controllable, From, Event, To )
end
-- @param #AI_AIR self
--- @param #AI_AIR self
function AI_AIR:onbeforeStatus()
return self.CheckStatus
end
-- @param #AI_AIR self
--- @param #AI_AIR self
function AI_AIR:onafterStatus()
if self.Controllable and self.Controllable:IsAlive() then
@@ -466,7 +465,7 @@ function AI_AIR:onafterStatus()
local DistanceFromHomeBase = self.HomeAirbase:GetCoordinate():Get2DDistance( self.Controllable:GetCoordinate() )
if DistanceFromHomeBase > self.DisengageRadius then
self:T( self.Controllable:GetName() .. " is too far from home base, RTB!" )
self:I( self.Controllable:GetName() .. " is too far from home base, RTB!" )
self:Hold( 300 )
RTB = false
end
@@ -490,10 +489,10 @@ function AI_AIR:onafterStatus()
if Fuel < self.FuelThresholdPercentage then
if self.TankerName then
self:T( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... Refuelling at Tanker!" )
self:I( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... Refuelling at Tanker!" )
self:Refuel()
else
self:T( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... RTB!" )
self:I( self.Controllable:GetName() .. " is out of fuel: " .. Fuel .. " ... RTB!" )
local OldAIControllable = self.Controllable
local OrbitTask = OldAIControllable:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
@@ -519,7 +518,7 @@ function AI_AIR:onafterStatus()
-- Note that a group can consist of more units, so if one unit is damaged of a group, the mission may continue.
-- The damaged unit will RTB due to DCS logic, and the others will continue to engage.
if ( Damage / InitialLife ) < self.PatrolDamageThreshold then
self:T( self.Controllable:GetName() .. " is damaged: " .. Damage .. " ... RTB!" )
self:I( self.Controllable:GetName() .. " is damaged: " .. Damage .. " ... RTB!" )
self:Damaged()
RTB = true
self:SetStatusOff()
@@ -537,7 +536,7 @@ function AI_AIR:onafterStatus()
if Damage ~= InitialLife then
self:Damaged()
else
self:T( self.Controllable:GetName() .. " control lost! " )
self:I( self.Controllable:GetName() .. " control lost! " )
self:LostControl()
end
@@ -561,7 +560,7 @@ function AI_AIR:onafterStatus()
end
-- @param Wrapper.Group#GROUP AIGroup
--- @param Wrapper.Group#GROUP AIGroup
function AI_AIR.RTBRoute( AIGroup, Fsm )
AIGroup:F( { "AI_AIR.RTBRoute:", AIGroup:GetName() } )
@@ -572,7 +571,7 @@ function AI_AIR.RTBRoute( AIGroup, Fsm )
end
-- @param Wrapper.Group#GROUP AIGroup
--- @param Wrapper.Group#GROUP AIGroup
function AI_AIR.RTBHold( AIGroup, Fsm )
AIGroup:F( { "AI_AIR.RTBHold:", AIGroup:GetName() } )
@@ -599,7 +598,7 @@ function AI_AIR:SetRTBSpeedFactors(MinFactor,MaxFactor)
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Wrapper.Group#GROUP AIGroup
function AI_AIR:onafterRTB( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } )
@@ -618,10 +617,7 @@ function AI_AIR:onafterRTB( AIGroup, From, Event, To )
--- Calculate the target route point.
local FromCoord = AIGroup:GetCoordinate()
if not FromCoord then return end
local ToTargetCoord = self.HomeAirbase:GetCoordinate() -- coordinate is on land height(!)
local ToTargetVec3 = ToTargetCoord:GetVec3()
ToTargetVec3.y = ToTargetCoord:GetLandHeight()+3000 -- let's set this 1000m/3000 feet above ground
local ToTargetCoord2 = COORDINATE:NewFromVec3( ToTargetVec3 )
@@ -642,13 +638,13 @@ function AI_AIR:onafterRTB( AIGroup, From, Event, To )
local ToAirbaseCoord = ToTargetCoord2
if Distance < 5000 then
self:T( "RTB and near the airbase!" )
self:I( "RTB and near the airbase!" )
self:Home()
return
end
if not AIGroup:InAir() == true then
self:T( "Not anymore in the air, considered Home." )
self:I( "Not anymore in the air, considered Home." )
self:Home()
return
end
@@ -690,12 +686,12 @@ function AI_AIR:onafterRTB( AIGroup, From, Event, To )
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Wrapper.Group#GROUP AIGroup
function AI_AIR:onafterHome( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } )
self:T( "Group " .. self.Controllable:GetName() .. " ... Home! ( " .. self:GetState() .. " )" )
self:I( "Group " .. self.Controllable:GetName() .. " ... Home! ( " .. self:GetState() .. " )" )
if AIGroup and AIGroup:IsAlive() then
end
@@ -704,17 +700,15 @@ end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Wrapper.Group#GROUP AIGroup
function AI_AIR:onafterHold( AIGroup, From, Event, To, HoldTime )
self:F( { AIGroup, From, Event, To } )
self:T( "Group " .. self.Controllable:GetName() .. " ... Holding! ( " .. self:GetState() .. " )" )
self:I( "Group " .. self.Controllable:GetName() .. " ... Holding! ( " .. self:GetState() .. " )" )
if AIGroup and AIGroup:IsAlive() then
local Coordinate = AIGroup:GetCoordinate()
if Coordinate == nil then return end
local OrbitTask = AIGroup:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed, Coordinate )
local OrbitTask = AIGroup:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
local TimedOrbitTask = AIGroup:TaskControlled( OrbitTask, AIGroup:TaskCondition( nil, nil, nil, nil, HoldTime , nil ) )
local RTBTask = AIGroup:TaskFunction( "AI_AIR.RTBHold", self )
@@ -728,17 +722,17 @@ function AI_AIR:onafterHold( AIGroup, From, Event, To, HoldTime )
end
-- @param Wrapper.Group#GROUP AIGroup
--- @param Wrapper.Group#GROUP AIGroup
function AI_AIR.Resume( AIGroup, Fsm )
AIGroup:T( { "AI_AIR.Resume:", AIGroup:GetName() } )
AIGroup:I( { "AI_AIR.Resume:", AIGroup:GetName() } )
if AIGroup:IsAlive() then
Fsm:__RTB( Fsm.TaskDelay )
end
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Wrapper.Group#GROUP AIGroup
function AI_AIR:onafterRefuel( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } )
@@ -750,7 +744,7 @@ function AI_AIR:onafterRefuel( AIGroup, From, Event, To )
if Tanker and Tanker:IsAlive() and Tanker:IsAirPlane() then
self:T( "Group " .. self.Controllable:GetName() .. " ... Refuelling! State=" .. self:GetState() .. ", Refuelling tanker " .. self.TankerName )
self:I( "Group " .. self.Controllable:GetName() .. " ... Refuelling! State=" .. self:GetState() .. ", Refuelling tanker " .. self.TankerName )
local RefuelRoute = {}
@@ -804,13 +798,13 @@ end
-- @param #AI_AIR self
--- @param #AI_AIR self
function AI_AIR:onafterDead()
self:SetStatusOff()
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR:OnCrash( EventData )
@@ -821,7 +815,7 @@ function AI_AIR:OnCrash( EventData )
end
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR:OnEjection( EventData )
@@ -830,7 +824,7 @@ function AI_AIR:OnEjection( EventData )
end
end
-- @param #AI_AIR self
--- @param #AI_AIR self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR:OnPilotDead( EventData )

View File

@@ -900,14 +900,14 @@ do -- AI_AIR_DISPATCHER
-- @type AI_AIR_DISPATCHER.DefenseCoordinates
-- @map <#string,Core.Point#COORDINATE> A list of all defense coordinates mapped per defense coordinate name.
-- @field #AI_AIR_DISPATCHER.DefenseCoordinates DefenseCoordinates
--- @field #AI_AIR_DISPATCHER.DefenseCoordinates DefenseCoordinates
AI_AIR_DISPATCHER.DefenseCoordinates = {}
--- Enumerator for spawns at airbases
-- @type AI_AIR_DISPATCHER.Takeoff
-- @extends Wrapper.Group#GROUP.Takeoff
-- @field #AI_AIR_DISPATCHER.Takeoff Takeoff
--- @field #AI_AIR_DISPATCHER.Takeoff Takeoff
AI_AIR_DISPATCHER.Takeoff = GROUP.Takeoff
--- Defnes Landing location.
@@ -938,7 +938,7 @@ do -- AI_AIR_DISPATCHER
-- @type AI_AIR_DISPATCHER.DefenseQueue
-- @list<#AI_AIR_DISPATCHER.DefenseQueueItem> DefenseQueueItem A list of all defenses being queued ...
-- @field #AI_AIR_DISPATCHER.DefenseQueue DefenseQueue
--- @field #AI_AIR_DISPATCHER.DefenseQueue DefenseQueue
AI_AIR_DISPATCHER.DefenseQueue = {}
--- Defense approach types
@@ -1130,7 +1130,7 @@ do -- AI_AIR_DISPATCHER
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
function AI_AIR_DISPATCHER:onafterStart( From, Event, To )
self:GetParent( self ).onafterStart( self, From, Event, To )
@@ -1141,7 +1141,7 @@ do -- AI_AIR_DISPATCHER
for Resource = 1, DefenderSquadron.ResourceCount or 0 do
self:ResourcePark( DefenderSquadron )
end
self:T( "Parked resources for squadron " .. DefenderSquadron.Name )
self:I( "Parked resources for squadron " .. DefenderSquadron.Name )
end
end
@@ -1194,7 +1194,7 @@ do -- AI_AIR_DISPATCHER
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
function AI_AIR_DISPATCHER:ResourcePark( DefenderSquadron )
local TemplateID = math.random( 1, #DefenderSquadron.Spawn )
local Spawn = DefenderSquadron.Spawn[ TemplateID ] -- Core.Spawn#SPAWN
@@ -1211,31 +1211,31 @@ do -- AI_AIR_DISPATCHER
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR_DISPATCHER:OnEventBaseCaptured( EventData )
local AirbaseName = EventData.PlaceName -- The name of the airbase that was captured.
self:T( "Captured " .. AirbaseName )
self:I( "Captured " .. AirbaseName )
-- Now search for all squadrons located at the airbase, and sanitize them.
for SquadronName, Squadron in pairs( self.DefenderSquadrons ) do
if Squadron.AirbaseName == AirbaseName then
Squadron.ResourceCount = -999 -- The base has been captured, and the resources are eliminated. No more spawning.
Squadron.Captured = true
self:T( "Squadron " .. SquadronName .. " captured." )
self:I( "Squadron " .. SquadronName .. " captured." )
end
end
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR_DISPATCHER:OnEventCrashOrDead( EventData )
self.Detection:ForgetDetectedUnit( EventData.IniUnitName )
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR_DISPATCHER:OnEventLand( EventData )
self:F( "Landed" )
@@ -1252,7 +1252,7 @@ do -- AI_AIR_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ResourcePark( Squadron )
self:ResourcePark( Squadron, Defender )
return
end
if DefenderUnit:GetLife() ~= DefenderUnit:GetLife0() then
@@ -1263,7 +1263,7 @@ do -- AI_AIR_DISPATCHER
end
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR_DISPATCHER:OnEventEngineShutdown( EventData )
local DefenderUnit = EventData.IniUnit
@@ -1279,31 +1279,31 @@ do -- AI_AIR_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ResourcePark( Squadron )
self:ResourcePark( Squadron, Defender )
end
end
end
do -- Manage the defensive behaviour
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param #string DefenseCoordinateName The name of the coordinate to be defended by AIR defenses.
-- @param Core.Point#COORDINATE DefenseCoordinate The coordinate to be defended by AIR defenses.
function AI_AIR_DISPATCHER:AddDefenseCoordinate( DefenseCoordinateName, DefenseCoordinate )
self.DefenseCoordinates[DefenseCoordinateName] = DefenseCoordinate
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
function AI_AIR_DISPATCHER:SetDefenseReactivityLow()
self.DefenseReactivity = 0.05
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
function AI_AIR_DISPATCHER:SetDefenseReactivityMedium()
self.DefenseReactivity = 0.15
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
function AI_AIR_DISPATCHER:SetDefenseReactivityHigh()
self.DefenseReactivity = 0.5
end
@@ -1867,7 +1867,7 @@ do -- AI_AIR_DISPATCHER
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param #string SquadronName The squadron name.
-- @param #number TakeoffInterval Only Takeoff new units each specified interval in seconds in 10 seconds steps.
-- @usage
@@ -2769,7 +2769,7 @@ do -- AI_AIR_DISPATCHER
-- TODO: Need to model the resources in a squadron.
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param AI.AI_Air_Squadron#AI_AIR_SQUADRON Squadron
function AI_AIR_DISPATCHER:AddDefenderToSquadron( Squadron, Defender, Size )
self.Defenders = self.Defenders or {}
@@ -2782,7 +2782,7 @@ do -- AI_AIR_DISPATCHER
self:F( { DefenderName = DefenderName, SquadronResourceCount = Squadron.ResourceCount } )
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param AI.AI_Air_Squadron#AI_AIR_SQUADRON Squadron
function AI_AIR_DISPATCHER:RemoveDefenderFromSquadron( Squadron, Defender )
self.Defenders = self.Defenders or {}
@@ -2795,7 +2795,7 @@ do -- AI_AIR_DISPATCHER
self:F( { DefenderName = DefenderName, SquadronResourceCount = SquadronResourceCount } )
end
-- @param #AI_AIR_DISPATCHER self
--- @param #AI_AIR_DISPATCHER self
-- @param Wrapper.Group#GROUP Defender
-- @return AI.AI_Air_Squadron#AI_AIR_SQUADRON The Squadron.
function AI_AIR_DISPATCHER:GetSquadronFromDefender( Defender )

View File

@@ -13,8 +13,8 @@
-- @type AI_AIR_ENGAGE
-- @extends AI.AI_AIR#AI_AIR
--- @type AI_AIR_ENGAGE
-- @extends AI.AI_Air#AI_AIR
--- Implements the core functions to intercept intruders. Use the Engage trigger to intercept intruders.
@@ -351,7 +351,7 @@ function AI_AIR_ENGAGE:onafterAbort( AIGroup, From, Event, To )
end
-- @param #AI_AIR_ENGAGE self
--- @param #AI_AIR_ENGAGE self
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
@@ -361,7 +361,7 @@ function AI_AIR_ENGAGE:onafterAccomplish( AIGroup, From, Event, To )
--self:SetDetectionOff()
end
-- @param #AI_AIR_ENGAGE self
--- @param #AI_AIR_ENGAGE self
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
@@ -374,7 +374,7 @@ function AI_AIR_ENGAGE:onafterDestroy( AIGroup, From, Event, To, EventData )
end
end
-- @param #AI_AIR_ENGAGE self
--- @param #AI_AIR_ENGAGE self
-- @param Core.Event#EVENTDATA EventData
function AI_AIR_ENGAGE:OnEventDead( EventData )
self:F( { "EventDead", EventData } )
@@ -387,9 +387,9 @@ function AI_AIR_ENGAGE:OnEventDead( EventData )
end
-- @param Wrapper.Group#GROUP AIControllable
--- @param Wrapper.Group#GROUP AIControllable
function AI_AIR_ENGAGE.___EngageRoute( AIGroup, Fsm, AttackSetUnit )
Fsm:T(string.format("AI_AIR_ENGAGE.___EngageRoute: %s", tostring(AIGroup:GetName())))
Fsm:I(string.format("AI_AIR_ENGAGE.___EngageRoute: %s", tostring(AIGroup:GetName())))
if AIGroup and AIGroup:IsAlive() then
Fsm:__EngageRoute( Fsm.TaskDelay or 0.1, AttackSetUnit )
@@ -397,14 +397,14 @@ function AI_AIR_ENGAGE.___EngageRoute( AIGroup, Fsm, AttackSetUnit )
end
-- @param #AI_AIR_ENGAGE self
--- @param #AI_AIR_ENGAGE self
-- @param Wrapper.Group#GROUP DefenderGroup The GroupGroup managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param Core.Set#SET_UNIT AttackSetUnit Unit set to be attacked.
function AI_AIR_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, AttackSetUnit )
self:T( { DefenderGroup, From, Event, To, AttackSetUnit } )
self:I( { DefenderGroup, From, Event, To, AttackSetUnit } )
local DefenderGroupName = DefenderGroup:GetName()
@@ -426,13 +426,7 @@ function AI_AIR_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, Attac
local DefenderCoord = DefenderGroup:GetPointVec3()
DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetCoord = AttackSetUnit:GetRandomSurely():GetPointVec3()
if TargetCoord == nil then
self:Return()
return
end
local TargetCoord = AttackSetUnit:GetFirst():GetPointVec3()
TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
@@ -441,12 +435,12 @@ function AI_AIR_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, Attac
-- TODO: A factor of * 3 is way too close. This causes the AI not to engange until merged sometimes!
if TargetDistance <= EngageDistance * 9 then
--self:T(string.format("AI_AIR_ENGAGE onafterEngageRoute ==> __Engage - target distance = %.1f km", TargetDistance/1000))
--self:I(string.format("AI_AIR_ENGAGE onafterEngageRoute ==> __Engage - target distance = %.1f km", TargetDistance/1000))
self:__Engage( 0.1, AttackSetUnit )
else
--self:T(string.format("FF AI_AIR_ENGAGE onafterEngageRoute ==> Routing - target distance = %.1f km", TargetDistance/1000))
--self:I(string.format("FF AI_AIR_ENGAGE onafterEngageRoute ==> Routing - target distance = %.1f km", TargetDistance/1000))
local EngageRoute = {}
local AttackTasks = {}
@@ -478,16 +472,16 @@ function AI_AIR_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, Attac
end
else
-- TODO: This will make an A2A Dispatcher CAP flight to return rather than going back to patrolling!
self:T( DefenderGroupName .. ": No targets found -> Going RTB")
self:I( DefenderGroupName .. ": No targets found -> Going RTB")
self:Return()
end
end
-- @param Wrapper.Group#GROUP AIControllable
--- @param Wrapper.Group#GROUP AIControllable
function AI_AIR_ENGAGE.___Engage( AIGroup, Fsm, AttackSetUnit )
Fsm:T(string.format("AI_AIR_ENGAGE.___Engage: %s", tostring(AIGroup:GetName())))
Fsm:I(string.format("AI_AIR_ENGAGE.___Engage: %s", tostring(AIGroup:GetName())))
if AIGroup and AIGroup:IsAlive() then
local delay=Fsm.TaskDelay or 0.1
@@ -496,7 +490,7 @@ function AI_AIR_ENGAGE.___Engage( AIGroup, Fsm, AttackSetUnit )
end
-- @param #AI_AIR_ENGAGE self
--- @param #AI_AIR_ENGAGE self
-- @param Wrapper.Group#GROUP DefenderGroup The GroupGroup managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
@@ -522,7 +516,7 @@ function AI_AIR_ENGAGE:onafterEngage( DefenderGroup, From, Event, To, AttackSetU
local DefenderCoord = DefenderGroup:GetPointVec3()
DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetCoord = AttackSetUnit:GetRandomSurely():GetPointVec3()
local TargetCoord = AttackSetUnit:GetFirst():GetPointVec3()
if not TargetCoord then
self:Return()
return
@@ -553,12 +547,12 @@ function AI_AIR_ENGAGE:onafterEngage( DefenderGroup, From, Event, To, AttackSetU
local AttackUnitTasks = self:CreateAttackUnitTasks( AttackSetUnit, DefenderGroup, EngageAltitude ) -- Polymorphic
if #AttackUnitTasks == 0 then
self:T( DefenderGroupName .. ": No valid targets found -> Going RTB")
self:I( DefenderGroupName .. ": No valid targets found -> Going RTB")
self:Return()
return
else
local text=string.format("%s: Engaging targets at distance %.2f NM", DefenderGroupName, UTILS.MetersToNM(TargetDistance))
self:T(text)
self:I(text)
DefenderGroup:OptionROEOpenFire()
DefenderGroup:OptionROTEvadeFire()
DefenderGroup:OptionKeepWeaponsOnThreat()
@@ -575,13 +569,13 @@ function AI_AIR_ENGAGE:onafterEngage( DefenderGroup, From, Event, To, AttackSetU
end
else
-- TODO: This will make an A2A Dispatcher CAP flight to return rather than going back to patrolling!
self:T( DefenderGroupName .. ": No targets found -> returning.")
self:I( DefenderGroupName .. ": No targets found -> returning.")
self:Return()
return
end
end
-- @param Wrapper.Group#GROUP AIEngage
--- @param Wrapper.Group#GROUP AIEngage
function AI_AIR_ENGAGE.Resume( AIEngage, Fsm )
AIEngage:F( { "Resume:", AIEngage:GetName() } )

View File

@@ -13,7 +13,7 @@
-- @type AI_AIR_SQUADRON
--- @type AI_AIR_SQUADRON
-- @extends Core.Base#BASE
@@ -38,7 +38,7 @@ AI_AIR_SQUADRON = {
-- @return #AI_AIR_SQUADRON
function AI_AIR_SQUADRON:New( SquadronName, AirbaseName, TemplatePrefixes, ResourceCount )
self:T( { Air_Squadron = { SquadronName, AirbaseName, TemplatePrefixes, ResourceCount } } )
self:I( { Air_Squadron = { SquadronName, AirbaseName, TemplatePrefixes, ResourceCount } } )
local AI_Air_Squadron = BASE:New() -- #AI_AIR_SQUADRON

View File

@@ -9,7 +9,7 @@
-- @module AI.AI_Cargo
-- @image Cargo.JPG
-- @type AI_CARGO
--- @type AI_CARGO
-- @extends Core.Fsm#FSM_CONTROLLABLE
@@ -547,7 +547,7 @@ function AI_CARGO:onafterUnloaded( Carrier, From, Event, To, Cargo, CarrierUnit,
for _, CarrierUnit in pairs( Carrier:GetUnits() ) do
local CarrierUnit = CarrierUnit -- Wrapper.Unit#UNIT
local IsEmpty = CarrierUnit:IsCargoEmpty()
self:T({ IsEmpty = IsEmpty })
self:I({ IsEmpty = IsEmpty })
if not IsEmpty then
AllUnloaded = false
break

View File

@@ -116,7 +116,7 @@
-- @image AI_Cargo_Dispatcher.JPG
-- @type AI_CARGO_DISPATCHER
--- @type AI_CARGO_DISPATCHER
-- @field Core.Set#SET_GROUP CarrierSet The set of @{Wrapper.Group#GROUP} objects of carriers that will transport the cargo.
-- @field Core.Set#SET_CARGO CargoSet The set of @{Cargo.Cargo#CARGO} objects, which can be CARGO_GROUP, CARGO_CRATE, CARGO_SLINGLOAD objects.
-- @field Core.Zone#SET_ZONE PickupZoneSet The set of pickup zones, which are used to where the cargo can be picked up by the carriers. If nil, then cargo can be picked up everywhere.
@@ -1161,7 +1161,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
else
local text=string.format("WARNING: Cargo %s is too heavy to be loaded into transport. Cargo weight %.1f > %.1f load capacity of carrier %s.",
tostring(Cargo:GetName()), Cargo:GetWeight(), LargestLoadCapacity, tostring(Carrier:GetName()))
self:T(text)
self:I(text)
end
end
end

View File

@@ -556,7 +556,7 @@ function AI_ESCORT:SetFlightMenuFormation( Formation )
if MenuFormation then
local Arguments = MenuFormation.Arguments
--self:T({Arguments=unpack(Arguments)})
--self:I({Arguments=unpack(Arguments)})
local FlightMenuFormation = MENU_GROUP:New( self.PlayerGroup, "Formation", self.MainMenu )
local MenuFlightFormationID = MENU_GROUP_COMMAND:New( self.PlayerGroup, Formation, FlightMenuFormation,
function ( self, Formation, ... )

View File

@@ -15,7 +15,7 @@
-- @image MOOSE.JPG
-- @type AI_ESCORT_DISPATCHER
--- @type AI_ESCORT_DISPATCHER
-- @extends Core.Fsm#FSM
@@ -33,7 +33,7 @@ AI_ESCORT_DISPATCHER = {
ClassName = "AI_ESCORT_DISPATCHER",
}
-- @field #list
--- @field #list
AI_ESCORT_DISPATCHER.AI_Escorts = {}
@@ -102,7 +102,7 @@ function AI_ESCORT_DISPATCHER:onafterStart( From, Event, To )
end
-- @param #AI_ESCORT_DISPATCHER self
--- @param #AI_ESCORT_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_ESCORT_DISPATCHER:OnEventExit( EventData )
@@ -110,11 +110,11 @@ function AI_ESCORT_DISPATCHER:OnEventExit( EventData )
local PlayerGroup = EventData.IniGroup
local PlayerUnit = EventData.IniUnit
self:T({EscortAirbase= self.EscortAirbase } )
self:T({PlayerGroupName = PlayerGroupName } )
self:T({PlayerGroup = PlayerGroup})
self:T({FirstGroup = self.CarrierSet:GetFirst()})
self:T({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
self:I({EscortAirbase= self.EscortAirbase } )
self:I({PlayerGroupName = PlayerGroupName } )
self:I({PlayerGroup = PlayerGroup})
self:I({FirstGroup = self.CarrierSet:GetFirst()})
self:I({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
if self.CarrierSet:FindGroup( PlayerGroupName ) then
if self.AI_Escorts[PlayerGroupName] then
@@ -125,7 +125,7 @@ function AI_ESCORT_DISPATCHER:OnEventExit( EventData )
end
-- @param #AI_ESCORT_DISPATCHER self
--- @param #AI_ESCORT_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_ESCORT_DISPATCHER:OnEventBirth( EventData )
@@ -133,17 +133,17 @@ function AI_ESCORT_DISPATCHER:OnEventBirth( EventData )
local PlayerGroup = EventData.IniGroup
local PlayerUnit = EventData.IniUnit
self:T({EscortAirbase= self.EscortAirbase } )
self:T({PlayerGroupName = PlayerGroupName } )
self:T({PlayerGroup = PlayerGroup})
self:T({FirstGroup = self.CarrierSet:GetFirst()})
self:T({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
self:I({EscortAirbase= self.EscortAirbase } )
self:I({PlayerGroupName = PlayerGroupName } )
self:I({PlayerGroup = PlayerGroup})
self:I({FirstGroup = self.CarrierSet:GetFirst()})
self:I({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )})
if self.CarrierSet:FindGroup( PlayerGroupName ) then
if not self.AI_Escorts[PlayerGroupName] then
local LeaderUnit = PlayerUnit
local EscortGroup = self.EscortSpawn:SpawnAtAirbase( self.EscortAirbase, SPAWN.Takeoff.Hot )
self:T({EscortGroup = EscortGroup})
self:I({EscortGroup = EscortGroup})
self:ScheduleOnce( 1,
function( EscortGroup )

View File

@@ -652,15 +652,15 @@ function AI_PATROL_ZONE:onafterStart( Controllable, From, Event, To )
end
-- @param #AI_PATROL_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable+
--- @param #AI_PATROL_ZONE self
--- @param Wrapper.Controllable#CONTROLLABLE Controllable
function AI_PATROL_ZONE:onbeforeDetect( Controllable, From, Event, To )
return self.DetectOn and self.DetectActivated
end
-- @param #AI_PATROL_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
--- @param #AI_PATROL_ZONE self
--- @param Wrapper.Controllable#CONTROLLABLE Controllable
function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
local Detected = false
@@ -705,7 +705,7 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
end
-- @param Wrapper.Controllable#CONTROLLABLE AIControllable
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
-- This static method is called from the route path within the last task at the last waypoint of the Controllable.
-- Note that this method is required, as triggers the next route when patrolling for the Controllable.
function AI_PATROL_ZONE:_NewPatrolRoute( AIControllable )
@@ -822,13 +822,13 @@ function AI_PATROL_ZONE:onafterRoute( Controllable, From, Event, To )
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:onbeforeStatus()
return self.CheckStatus
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:onafterStatus()
self:F2()
@@ -838,7 +838,7 @@ function AI_PATROL_ZONE:onafterStatus()
local Fuel = self.Controllable:GetFuelMin()
if Fuel < self.PatrolFuelThresholdPercentage then
self:T( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
self:I( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
local OldAIControllable = self.Controllable
local OrbitTask = OldAIControllable:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
@@ -852,7 +852,7 @@ function AI_PATROL_ZONE:onafterStatus()
-- TODO: Check GROUP damage function.
local Damage = self.Controllable:GetLife()
if Damage <= self.PatrolDamageThreshold then
self:T( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
self:I( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
RTB = true
end
@@ -864,7 +864,7 @@ function AI_PATROL_ZONE:onafterStatus()
end
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:onafterRTB()
self:F2()
@@ -903,13 +903,13 @@ function AI_PATROL_ZONE:onafterRTB()
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:onafterDead()
self:SetDetectionOff()
self:SetStatusOff()
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_PATROL_ZONE:OnCrash( EventData )
@@ -920,7 +920,7 @@ function AI_PATROL_ZONE:OnCrash( EventData )
end
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_PATROL_ZONE:OnEjection( EventData )
@@ -929,7 +929,7 @@ function AI_PATROL_ZONE:OnEjection( EventData )
end
end
-- @param #AI_PATROL_ZONE self
--- @param #AI_PATROL_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_PATROL_ZONE:OnPilotDead( EventData )

View File

@@ -26,7 +26,7 @@
-- @module Core.Base
-- @image Core_Base.JPG
local _TraceOnOff = false -- default to no tracing
local _TraceOnOff = true
local _TraceLevel = 1
local _TraceAll = false
local _TraceClass = {}
@@ -34,12 +34,11 @@ local _TraceClassMethod = {}
local _ClassID = 0
--- Base class of everything
---
-- @type BASE
-- @field #string ClassName The name of the class.
-- @field #number ClassID The ID number of the class.
-- @field #string ClassNameAndID The name of the class concatenated with the ID number of the class.
-- @field Core.Scheduler#SCHEDULER Scheduler The scheduler object.
-- @field ClassName The name of the class.
-- @field ClassID The ID number of the class.
-- @field ClassNameAndID The name of the class concatenated with the ID number of the class.
--- BASE class
--
@@ -211,6 +210,14 @@ BASE._ = {
Schedules = {}, --- Contains the Schedulers Active
}
--- The Formation Class
-- @type FORMATION
-- @field Cone A cone formation.
FORMATION = {
Cone = "Cone",
Vee = "Vee",
}
--- BASE constructor.
--
-- This is an example how to use the BASE:New() constructor in a new class definition when inheriting from BASE.
@@ -734,31 +741,7 @@ do -- Event Handling
-- @function [parent=#BASE] OnEventPlayerEnterAircraft
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when a player creates a dynamic cargo object from the F8 ground crew menu.
-- *** NOTE *** this is a workarounf for DCS not creating these events as of Aug 2024.
-- @function [parent=#BASE] OnEventNewDynamicCargo
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when a player loads a dynamic cargo object with the F8 ground crew menu into a helo.
-- *** NOTE *** this is a workarounf for DCS not creating these events as of Aug 2024.
-- @function [parent=#BASE] OnEventDynamicCargoLoaded
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when a player unloads a dynamic cargo object with the F8 ground crew menu from a helo.
-- *** NOTE *** this is a workarounf for DCS not creating these events as of Aug 2024.
-- @function [parent=#BASE] OnEventDynamicCargoUnloaded
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when a dynamic cargo crate is removed.
-- *** NOTE *** this is a workarounf for DCS not creating these events as of Aug 2024.
-- @function [parent=#BASE] OnEventDynamicCargoRemoved
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
end
--- Creation of a Birth Event.
@@ -879,62 +862,6 @@ end
world.onEvent(Event)
end
--- Creation of a S_EVENT_NEW_DYNAMIC_CARGO event.
-- @param #BASE self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function BASE:CreateEventNewDynamicCargo(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.NewDynamicCargo,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_LOADED event.
-- @param #BASE self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function BASE:CreateEventDynamicCargoLoaded(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoLoaded,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_UNLOADED event.
-- @param #BASE self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function BASE:CreateEventDynamicCargoUnloaded(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoUnloaded,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_REMOVED event.
-- @param #BASE self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function BASE:CreateEventDynamicCargoRemoved(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoRemoved,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- The main event handling function... This function captures all events generated for the class.
-- @param #BASE self
@@ -1217,28 +1144,6 @@ function BASE:TraceClassMethod( Class, Method )
self:I( "Tracing method " .. Method .. " of class " .. Class )
end
--- (Internal) Serialize arguments
-- @param #BASE self
-- @param #table Arguments
-- @return #string Text
function BASE:_Serialize(Arguments)
local text = UTILS.PrintTableToLog({Arguments}, 0, true)
text = string.gsub(text,"(\n+)","")
text = string.gsub(text,"%(%(","%(")
text = string.gsub(text,"%)%)","%)")
text = string.gsub(text,"(%s+)"," ")
return text
end
----- (Internal) Serialize arguments
---- @param #BASE self
---- @param #table Arguments
---- @return #string Text
--function BASE:_Serialize(Arguments)
-- local text=UTILS.BasicSerialize(Arguments)
-- return text
--end
--- Trace a function call. This function is private.
-- @param #BASE self
-- @param Arguments A #table or any field.
@@ -1263,7 +1168,7 @@ function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if DebugInfoFrom then
LineFrom = DebugInfoFrom.currentline
end
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, BASE:_Serialize(Arguments) ) )
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "F", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) )
end
end
end
@@ -1273,7 +1178,7 @@ end
-- @param Arguments A #table or any field.
function BASE:F( Arguments )
if BASE.Debug and _TraceOnOff == true then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1288,7 +1193,7 @@ end
-- @param Arguments A #table or any field.
function BASE:F2( Arguments )
if BASE.Debug and _TraceOnOff == true and _TraceLevel >= 2 then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1303,7 +1208,7 @@ end
-- @param Arguments A #table or any field.
function BASE:F3( Arguments )
if BASE.Debug and _TraceOnOff == true and _TraceLevel >= 3 then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1337,7 +1242,7 @@ function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if DebugInfoFrom then
LineFrom = DebugInfoFrom.currentline
end
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s", LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, BASE:_Serialize(Arguments) ) )
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s", LineCurrent, LineFrom, "T", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) )
end
end
end
@@ -1347,7 +1252,7 @@ end
-- @param Arguments A #table or any field.
function BASE:T( Arguments )
if BASE.Debug and _TraceOnOff == true then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1362,7 +1267,7 @@ end
-- @param Arguments A #table or any field.
function BASE:T2( Arguments )
if BASE.Debug and _TraceOnOff == true and _TraceLevel >= 2 then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1377,7 +1282,7 @@ end
-- @param Arguments A #table or any field.
function BASE:T3( Arguments )
if BASE.Debug and _TraceOnOff == true and _TraceLevel >= 3 then
if BASE.Debug and _TraceOnOff then
local DebugInfoCurrent = BASE.Debug.getinfo( 2, "nl" )
local DebugInfoFrom = BASE.Debug.getinfo( 3, "l" )
@@ -1409,7 +1314,7 @@ function BASE:E( Arguments )
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "E", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) )
else
env.info( string.format( "%1s:%30s%05d(%s)", "E", self.ClassName, self.ClassID, UTILS.BasicSerialize(Arguments) ) )
env.info( string.format( "%1s:%30s%05d(%s)", "E", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) )
end
end
@@ -1436,8 +1341,39 @@ function BASE:I( Arguments )
env.info( string.format( "%6d(%6d)/%1s:%30s%05d.%s(%s)", LineCurrent, LineFrom, "I", self.ClassName, self.ClassID, Function, UTILS.BasicSerialize( Arguments ) ) )
else
env.info( string.format( "%1s:%30s%05d(%s)", "I", self.ClassName, self.ClassID, UTILS.BasicSerialize(Arguments)) )
env.info( string.format( "%1s:%30s%05d(%s)", "I", self.ClassName, self.ClassID, UTILS.BasicSerialize( Arguments ) ) )
end
end
--- old stuff
-- function BASE:_Destructor()
-- --self:E("_Destructor")
--
-- --self:EventRemoveAll()
-- end
-- THIS IS WHY WE NEED LUA 5.2 ...
-- function BASE:_SetDestructor()
--
-- -- TODO: Okay, this is really technical...
-- -- When you set a proxy to a table to catch __gc, weak tables don't behave like weak...
-- -- Therefore, I am parking this logic until I've properly discussed all this with the community.
--
-- local proxy = newproxy(true)
-- local proxyMeta = getmetatable(proxy)
--
-- proxyMeta.__gc = function ()
-- env.info("In __gc for " .. self:GetClassNameAndID() )
-- if self._Destructor then
-- self:_Destructor()
-- end
-- end
--
-- -- keep the userdata from newproxy reachable until the object
-- -- table is about to be garbage-collected - then the __gc hook
-- -- will be invoked and the destructor called
-- rawset( self, '__proxy', proxy )
--
-- end

View File

@@ -8,10 +8,6 @@
--
-- ===
--
-- ### [Demo Missions](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Core/Beacon)
--
-- ===
--
-- ### Authors: Hugues "Grey_Echo" Bousquet, funkyfranky
--
-- @module Core.Beacon
@@ -38,13 +34,11 @@
-- @type BEACON
-- @field #string ClassName Name of the class "BEACON".
-- @field Wrapper.Controllable#CONTROLLABLE Positionable The @{Wrapper.Controllable#CONTROLLABLE} that will receive radio capabilities.
-- @field #number UniqueName Counter to make the unique naming work.
-- @extends Core.Base#BASE
BEACON = {
ClassName = "BEACON",
Positionable = nil,
name = nil,
UniqueName = 0,
}
--- Beacon types supported by DCS.
@@ -292,7 +286,6 @@ end
-- myBeacon:AATACAN(20, "TEXACO", true) -- Activate the beacon
function BEACON:AATACAN(TACANChannel, Message, Bearing, BeaconDuration)
self:F({TACANChannel, Message, Bearing, BeaconDuration})
self:E("This method is DEPRECATED! Please use ActivateTACAN() instead.")
local IsValid = true
@@ -386,9 +379,7 @@ end
function BEACON:RadioBeacon(FileName, Frequency, Modulation, Power, BeaconDuration)
self:F({FileName, Frequency, Modulation, Power, BeaconDuration})
local IsValid = false
Modulation = Modulation or radio.modulation.AM
-- Check the filename
if type(FileName) == "string" then
if FileName:find(".ogg") or FileName:find(".wav") then
@@ -399,7 +390,7 @@ function BEACON:RadioBeacon(FileName, Frequency, Modulation, Power, BeaconDurati
end
end
if not IsValid then
self:E({"File name invalid. Maybe something wrong with the extension? ", FileName})
self:E({"File name invalid. Maybe something wrong with the extension ? ", FileName})
end
-- Check the Frequency
@@ -425,9 +416,7 @@ function BEACON:RadioBeacon(FileName, Frequency, Modulation, Power, BeaconDurati
if IsValid then
self:T2({"Activating Beacon on ", Frequency, Modulation})
-- Note that this is looped. I have to give this transmission a unique name, I use the class ID
BEACON.UniqueName = BEACON.UniqueName + 1
self.BeaconName = "MooseBeacon"..tostring(BEACON.UniqueName)
trigger.action.radioTransmission(FileName, self.Positionable:GetPositionVec3(), Modulation, true, Frequency, Power, self.BeaconName)
trigger.action.radioTransmission(FileName, self.Positionable:GetPositionVec3(), Modulation, true, Frequency, Power, tostring(self.ID))
if BeaconDuration then -- Schedule the stop of the BEACON if asked by the MD
SCHEDULER:New( nil,
@@ -435,8 +424,7 @@ function BEACON:RadioBeacon(FileName, Frequency, Modulation, Power, BeaconDurati
self:StopRadioBeacon()
end, {}, BeaconDuration)
end
end
return self
end
end
--- Stops the Radio Beacon
@@ -445,7 +433,7 @@ end
function BEACON:StopRadioBeacon()
self:F()
-- The unique name of the transmission is the class ID
trigger.action.stopRadioTransmission(self.BeaconName)
trigger.action.stopRadioTransmission(tostring(self.ID))
return self
end

View File

@@ -20,7 +20,6 @@
-- * Manage database of hits to units and statics.
-- * Manage database of destroys of units and statics.
-- * Manage database of @{Core.Zone#ZONE_BASE} objects.
-- * Manage database of @{Wrapper.DynamicCargo#DYNAMICCARGO} objects alive in the mission.
--
-- ===
--
@@ -38,9 +37,6 @@
-- @field #table Templates Templates: Units, Groups, Statics, ClientsByName, ClientsByID.
-- @field #table CLIENTS Clients.
-- @field #table STORAGES DCS warehouse storages.
-- @field #table STNS Used Link16 octal numbers for F16/15/18/AWACS planes.
-- @field #table SADL Used Link16 octal numbers for A10/C-II planes.
-- @field #table DYNAMICCARGO Dynamic Cargo objects.
-- @extends Core.Base#BASE
--- Contains collections of wrapper objects defined within MOOSE that reflect objects within the simulator.
@@ -56,7 +52,6 @@
-- * PLAYERS
-- * CARGOS
-- * STORAGES (DCS warehouses)
-- * DYNAMICCARGO
--
-- On top, for internal MOOSE administration purposes, the DATABASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
--
@@ -98,9 +93,6 @@ DATABASE = {
OPSZONES = {},
PATHLINES = {},
STORAGES = {},
STNS={},
SADL={},
DYNAMICCARGO={},
}
local _DATABASECoalition =
@@ -139,7 +131,7 @@ function DATABASE:New()
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
self:HandleEvent( EVENTS.RemoveUnit, self._EventOnDeadOrCrash )
self:HandleEvent( EVENTS.UnitLost, self._EventOnDeadOrCrash ) -- DCS 2.7.1 for Aerial units no dead event ATM
--self:HandleEvent( EVENTS.UnitLost, self._EventOnDeadOrCrash ) -- DCS 2.7.1 for Aerial units no dead event ATM
self:HandleEvent( EVENTS.Hit, self.AccountHits )
self:HandleEvent( EVENTS.NewCargo )
self:HandleEvent( EVENTS.DeleteCargo )
@@ -147,8 +139,6 @@ function DATABASE:New()
self:HandleEvent( EVENTS.DeleteZone )
--self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit ) -- This is not working anymore!, handling this through the birth event.
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
-- DCS 2.9.7 Moose own dynamic cargo events
self:HandleEvent( EVENTS.DynamicCargoRemoved, self._EventOnDynamicCargoRemoved)
self:_RegisterTemplates()
self:_RegisterGroupsAndUnits()
@@ -176,30 +166,24 @@ end
--- Adds a Unit based on the Unit Name in the DATABASE.
-- @param #DATABASE self
-- @param #string DCSUnitName Unit name.
-- @param #boolean force
-- @return Wrapper.Unit#UNIT The added unit.
function DATABASE:AddUnit( DCSUnitName, force )
local DCSunitName = DCSUnitName
if type(DCSunitName) == "number" then DCSunitName = string.format("%d",DCSUnitName) end
if not self.UNITS[DCSunitName] or force == true then
function DATABASE:AddUnit( DCSUnitName )
if not self.UNITS[DCSUnitName] then
-- Debug info.
self:T( { "Add UNIT:", DCSunitName } )
self:T( { "Add UNIT:", DCSUnitName } )
-- Register unit
self.UNITS[DCSunitName]=UNIT:Register(DCSunitName)
self.UNITS[DCSUnitName]=UNIT:Register(DCSUnitName)
end
return self.UNITS[DCSunitName]
return self.UNITS[DCSUnitName]
end
--- Deletes a Unit from the DATABASE based on the Unit Name.
-- @param #DATABASE self
function DATABASE:DeleteUnit( DCSUnitName )
self:T("DeleteUnit "..tostring(DCSUnitName))
self.UNITS[DCSUnitName] = nil
end
@@ -211,9 +195,10 @@ function DATABASE:AddStatic( DCSStaticName )
if not self.STATICS[DCSStaticName] then
self.STATICS[DCSStaticName] = STATIC:Register( DCSStaticName )
return self.STATICS[DCSStaticName]
end
return self.STATICS[DCSStaticName]
return nil
end
@@ -223,42 +208,16 @@ function DATABASE:DeleteStatic( DCSStaticName )
self.STATICS[DCSStaticName] = nil
end
--- Finds a STATIC based on the Static Name.
--- Finds a STATIC based on the StaticName.
-- @param #DATABASE self
-- @param #string StaticName Name of the static object.
-- @param #string StaticName
-- @return Wrapper.Static#STATIC The found STATIC.
function DATABASE:FindStatic( StaticName )
local StaticFound = self.STATICS[StaticName]
return StaticFound
end
--- Add a DynamicCargo to the database.
-- @param #DATABASE self
-- @param #string Name Name of the dynamic cargo.
-- @return Wrapper.DynamicCargo#DYNAMICCARGO The dynamic cargo object.
function DATABASE:AddDynamicCargo( Name )
if not self.DYNAMICCARGO[Name] then
self.DYNAMICCARGO[Name] = DYNAMICCARGO:Register(Name)
end
return self.DYNAMICCARGO[Name]
end
--- Finds a DYNAMICCARGO based on the Dynamic Cargo Name.
-- @param #DATABASE self
-- @param #string DynamicCargoName
-- @return Wrapper.DynamicCargo#DYNAMICCARGO The found DYNAMICCARGO.
function DATABASE:FindDynamicCargo( DynamicCargoName )
local StaticFound = self.DYNAMICCARGO[DynamicCargoName]
return StaticFound
end
--- Deletes a DYNAMICCARGO from the DATABASE based on the Dynamic Cargo Name.
-- @param #DATABASE self
function DATABASE:DeleteDynamicCargo( DynamicCargoName )
self.DYNAMICCARGO[DynamicCargoName] = nil
return self
end
--- Adds a Airbase based on the Airbase Name in the DATABASE.
-- @param #DATABASE self
-- @param #string AirbaseName The name of the airbase.
@@ -850,19 +809,14 @@ end
--- Adds a CLIENT based on the ClientName in the DATABASE.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client unit.
-- @param #boolean Force (optional) Force registration of client.
-- @return Wrapper.Client#CLIENT The client object.
function DATABASE:AddClient( ClientName, Force )
local DCSUnitName = ClientName
if type(DCSUnitName) == "number" then DCSUnitName = string.format("%d",ClientName) end
if not self.CLIENTS[DCSUnitName] or Force == true then
self.CLIENTS[DCSUnitName] = CLIENT:Register( DCSUnitName )
function DATABASE:AddClient( ClientName )
if not self.CLIENTS[ClientName] then
self.CLIENTS[ClientName] = CLIENT:Register( ClientName )
end
return self.CLIENTS[DCSUnitName]
return self.CLIENTS[ClientName]
end
@@ -873,25 +827,15 @@ end
function DATABASE:FindGroup( GroupName )
local GroupFound = self.GROUPS[GroupName]
if GroupFound == nil and GroupName ~= nil and self.Templates.Groups[GroupName] == nil then
-- see if the group exists in the API, maybe a dynamic slot
self:_RegisterDynamicGroup(GroupName)
return self.GROUPS[GroupName]
end
return GroupFound
end
--- Adds a GROUP based on the GroupName in the DATABASE.
-- @param #DATABASE self
-- @param #string GroupName
-- @param #boolean force
-- @return Wrapper.Group#GROUP The Group
function DATABASE:AddGroup( GroupName, force )
function DATABASE:AddGroup( GroupName )
if not self.GROUPS[GroupName] or force == true then
if not self.GROUPS[GroupName] then
self:T( { "Add GROUP:", GroupName } )
self.GROUPS[GroupName] = GROUP:Register( GroupName )
end
@@ -902,11 +846,9 @@ end
--- Adds a player based on the Player Name in the DATABASE.
-- @param #DATABASE self
function DATABASE:AddPlayer( UnitName, PlayerName )
if type(UnitName) == "number" then UnitName = string.format("%d",UnitName) end
if PlayerName then
self:I( { "Add player for unit:", UnitName, PlayerName } )
self:T( { "Add player for unit:", UnitName, PlayerName } )
self.PLAYERS[PlayerName] = UnitName
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
self.PLAYERSJOINED[PlayerName] = PlayerName
@@ -914,21 +856,6 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
end
--- Get a PlayerName by UnitName from PLAYERS in DATABASE.
-- @param #DATABASE self
-- @return #string PlayerName
-- @return Wrapper.Unit#UNIT PlayerUnit
function DATABASE:_FindPlayerNameByUnitName(UnitName)
if UnitName then
for playername,unitname in pairs(self.PLAYERS) do
if unitname == UnitName and self.PLAYERUNITS[playername] and self.PLAYERUNITS[playername]:IsAlive() then
return playername, self.PLAYERUNITS[playername]
end
end
end
return nil
end
--- Deletes a player from the DATABASE based on the Player Name.
-- @param #DATABASE self
function DATABASE:DeletePlayer( UnitName, PlayerName )
@@ -1001,7 +928,7 @@ function DATABASE:Spawn( SpawnTemplate )
SpawnTemplate.CountryID = nil
SpawnTemplate.CategoryID = nil
self:_RegisterGroupTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID, SpawnTemplate.name )
self:_RegisterGroupTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID )
self:T3( SpawnTemplate )
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
@@ -1078,7 +1005,7 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
self.Templates.Groups[GroupTemplateName].CategoryID = CategoryID
self.Templates.Groups[GroupTemplateName].CoalitionID = CoalitionSide
self.Templates.Groups[GroupTemplateName].CountryID = CountryID
local UnitNames = {}
for unit_num, UnitTemplate in pairs( GroupTemplate.units ) do
@@ -1102,31 +1029,10 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
self.Templates.ClientsByName[UnitTemplate.name].CountryID = CountryID
self.Templates.ClientsByID[UnitTemplate.unitId] = UnitTemplate
end
if UnitTemplate.AddPropAircraft then
if UnitTemplate.AddPropAircraft.STN_L16 then
local stn = UTILS.OctalToDecimal(UnitTemplate.AddPropAircraft.STN_L16)
if stn == nil or stn < 1 then
self:E("WARNING: Invalid STN "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name)
else
self.STNS[stn] = UnitTemplate.name
self:I("Register STN "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name)
end
end
if UnitTemplate.AddPropAircraft.SADL_TN then
local sadl = UTILS.OctalToDecimal(UnitTemplate.AddPropAircraft.SADL_TN)
if sadl == nil or sadl < 1 then
self:E("WARNING: Invalid SADL "..tostring(UnitTemplate.AddPropAircraft.SADL_TN).." for ".. UnitTemplate.name)
else
self.SADL[sadl] = UnitTemplate.name
self:I("Register SADL "..tostring(UnitTemplate.AddPropAircraft.SADL_TN).." for ".. UnitTemplate.name)
end
end
end
UnitNames[#UnitNames+1] = self.Templates.Units[UnitTemplate.name].UnitName
end
-- Debug info.
self:T( { Group = self.Templates.Groups[GroupTemplateName].GroupName,
Coalition = self.Templates.Groups[GroupTemplateName].CoalitionID,
@@ -1137,92 +1043,15 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
)
end
--- Get next (consecutive) free STN as octal number.
-- @param #DATABASE self
-- @param #number octal Starting octal.
-- @param #string unitname Name of the associated unit.
-- @return #number Octal
function DATABASE:GetNextSTN(octal,unitname)
local first = UTILS.OctalToDecimal(octal) or 0
if self.STNS[first] == unitname then return octal end
local nextoctal = 77777
local found = false
if 32767-first < 10 then
first = 0
end
for i=first+1,32767 do
if self.STNS[i] == nil then
found = true
nextoctal = UTILS.DecimalToOctal(i)
self.STNS[i] = unitname
self:T("Register STN "..tostring(nextoctal).." for ".. unitname)
break
end
end
if not found then
self:E(string.format("WARNING: No next free STN past %05d found!",octal))
-- cleanup
local NewSTNS = {}
for _id,_name in pairs(self.STNS) do
if self.UNITS[_name] ~= nil then
NewSTNS[_id] = _name
end
end
self.STNS = nil
self.STNS = NewSTNS
end
return nextoctal
end
--- Get next (consecutive) free SADL as octal number.
-- @param #DATABASE self
-- @param #number octal Starting octal.
-- @param #string unitname Name of the associated unit.
-- @return #number Octal
function DATABASE:GetNextSADL(octal,unitname)
local first = UTILS.OctalToDecimal(octal) or 0
if self.SADL[first] == unitname then return octal end
local nextoctal = 7777
local found = false
if 4095-first < 10 then
first = 0
end
for i=first+1,4095 do
if self.STNS[i] == nil then
found = true
nextoctal = UTILS.DecimalToOctal(i)
self.SADL[i] = unitname
self:T("Register SADL "..tostring(nextoctal).." for ".. unitname)
break
end
end
if not found then
self:E(string.format("WARNING: No next free SADL past %04d found!",octal))
-- cleanup
local NewSTNS = {}
for _id,_name in pairs(self.SADL) do
if self.UNITS[_name] ~= nil then
NewSTNS[_id] = _name
end
end
self.SADL = nil
self.SADL = NewSTNS
end
return nextoctal
end
--- Get group template.
-- @param #DATABASE self
-- @param #string GroupName Group name.
-- @return #table Group template table.
function DATABASE:GetGroupTemplate( GroupName )
local GroupTemplate=nil
if self.Templates.Groups[GroupName] then
GroupTemplate = self.Templates.Groups[GroupName].Template
GroupTemplate.SpawnCoalitionID = self.Templates.Groups[GroupName].CoalitionID
GroupTemplate.SpawnCategoryID = self.Templates.Groups[GroupName].CategoryID
GroupTemplate.SpawnCountryID = self.Templates.Groups[GroupName].CountryID
end
local GroupTemplate = self.Templates.Groups[GroupName].Template
GroupTemplate.SpawnCoalitionID = self.Templates.Groups[GroupName].CoalitionID
GroupTemplate.SpawnCategoryID = self.Templates.Groups[GroupName].CategoryID
GroupTemplate.SpawnCountryID = self.Templates.Groups[GroupName].CountryID
return GroupTemplate
end
@@ -1267,43 +1096,6 @@ function DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, Category
return self
end
--- Get a generic static cargo group template from scratch for dynamic cargo spawns register. Does not register the template!
-- @param #DATABASE self
-- @param #string Name Name of the static.
-- @param #string Typename Typename of the static. Defaults to "container_cargo".
-- @param #number Mass Mass of the static. Defaults to 0.
-- @param #number Coalition Coalition of the static. Defaults to coalition.side.BLUE.
-- @param #number Country Country of the static. Defaults to country.id.GERMANY.
-- @return #table Static template table.
function DATABASE:_GetGenericStaticCargoGroupTemplate(Name,Typename,Mass,Coalition,Country)
local StaticTemplate = {}
StaticTemplate.name = Name or "None"
StaticTemplate.units = { [1] = {
name = Name,
resourcePayload = {
["weapons"] = {},
["aircrafts"] = {},
["gasoline"] = 0,
["diesel"] = 0,
["methanol_mixture"] = 0,
["jet_fuel"] = 0,
},
["mass"] = Mass or 0,
["category"] = "Cargos",
["canCargo"] = true,
["type"] = Typename or "container_cargo",
["rate"] = 100,
["y"] = 0,
["x"] = 0,
["heading"] = 0,
}}
StaticTemplate.CategoryID = "static"
StaticTemplate.CoalitionID = Coalition or coalition.side.BLUE
StaticTemplate.CountryID = Country or country.id.GERMANY
--UTILS.PrintTableToLog(StaticTemplate)
return StaticTemplate
end
--- Get static group template.
-- @param #DATABASE self
-- @param #string StaticName Name of the static.
@@ -1377,11 +1169,7 @@ end
-- @param #string ClientName Name of the Client.
-- @return #number Coalition ID.
function DATABASE:GetCoalitionFromClientTemplate( ClientName )
if self.Templates.ClientsByName[ClientName] then
return self.Templates.ClientsByName[ClientName].CoalitionID
end
self:E("WARNING: Template does not exist for client "..tostring(ClientName))
return nil
return self.Templates.ClientsByName[ClientName].CoalitionID
end
--- Get category ID from client name.
@@ -1389,11 +1177,7 @@ end
-- @param #string ClientName Name of the Client.
-- @return #number Category ID.
function DATABASE:GetCategoryFromClientTemplate( ClientName )
if self.Templates.ClientsByName[ClientName] then
return self.Templates.ClientsByName[ClientName].CategoryID
end
self:E("WARNING: Template does not exist for client "..tostring(ClientName))
return nil
return self.Templates.ClientsByName[ClientName].CategoryID
end
--- Get country ID from client name.
@@ -1401,11 +1185,7 @@ end
-- @param #string ClientName Name of the Client.
-- @return #number Country ID.
function DATABASE:GetCountryFromClientTemplate( ClientName )
if self.Templates.ClientsByName[ClientName] then
return self.Templates.ClientsByName[ClientName].CountryID
end
self:E("WARNING: Template does not exist for client "..tostring(ClientName))
return nil
return self.Templates.ClientsByName[ClientName].CountryID
end
--- Airbase
@@ -1451,36 +1231,6 @@ function DATABASE:_RegisterPlayers()
return self
end
--- Private method that registers a single dynamic slot Group and Units within in the mission.
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:_RegisterDynamicGroup(Groupname)
local DCSGroup = Group.getByName(Groupname)
if DCSGroup and DCSGroup:isExist() then
-- Group name.
local DCSGroupName = DCSGroup:getName()
-- Add group.
self:I(string.format("Register Group: %s", tostring(DCSGroupName)))
self:AddGroup( DCSGroupName, true )
-- Loop over units in group.
for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do
-- Get unit name.
local DCSUnitName = DCSUnit:getName()
-- Add unit.
self:I(string.format("Register Unit: %s", tostring(DCSUnitName)))
self:AddUnit( tostring(DCSUnitName), true )
end
else
self:E({"Group does not exist: ", DCSGroup})
end
return self
end
--- Private method that registers all Groups and Units within in the mission.
-- @param #DATABASE self
@@ -1579,29 +1329,12 @@ end
-- @param DCS#Airbase airbase Airbase.
-- @return #DATABASE self
function DATABASE:_RegisterAirbase(airbase)
local IsSyria = UTILS.GetDCSMap() == "Syria" and true or false
local countHSyria = 0
if airbase then
-- Get the airbase name.
local DCSAirbaseName = airbase:getName()
-- DCS 2.9.8.1107 added 143 helipads all named H with the same object ID ..
if IsSyria and DCSAirbaseName == "H" and countHSyria > 0 then
--[[
local p = airbase:getPosition().p
local mgrs = COORDINATE:New(p.x,p.z,p.y):ToStringMGRS()
self:I("Airbase on Syria map named H @ "..mgrs)
countHSyria = countHSyria + 1
if countHSyria > 1 then return self end
--]]
return self
elseif IsSyria and DCSAirbaseName == "H" and countHSyria == 0 then
countHSyria = countHSyria + 1
end
-- This gave the incorrect value to be inserted into the airdromeID for DCS 2.5.6. Is fixed now.
local airbaseID=airbase:getID()
@@ -1641,7 +1374,7 @@ end
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:_EventOnBirth( Event )
self:T( { Event } )
self:F( { Event } )
if Event.IniDCSUnit then
@@ -1649,17 +1382,7 @@ function DATABASE:_EventOnBirth( Event )
-- Add static object to DB.
self:AddStatic( Event.IniDCSUnitName )
elseif Event.IniObjectCategory == Object.Category.CARGO and string.match(Event.IniUnitName,".+|%d%d:%d%d|PKG%d+") then
-- Add dynamic cargo object to DB
local cargo = self:AddDynamicCargo(Event.IniDCSUnitName)
self:I(string.format("Adding dynamic cargo %s", tostring(Event.IniDCSUnitName)))
self:CreateEventNewDynamicCargo( cargo )
else
if Event.IniObjectCategory == Object.Category.UNIT then
@@ -1680,9 +1403,9 @@ function DATABASE:_EventOnBirth( Event )
end
if Event.IniObjectCategory == Object.Category.UNIT then
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
-- Client
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
@@ -1698,10 +1421,10 @@ function DATABASE:_EventOnBirth( Event )
-- Debug info.
self:I(string.format("Player '%s' joined unit '%s' of group '%s'", tostring(PlayerName), tostring(Event.IniDCSUnitName), tostring(Event.IniDCSGroupName)))
-- Add client in case it does not exist already.
if client == nil or (client and client:CountPlayers() == 0) then
client=self:AddClient(Event.IniDCSUnitName, true)
if not client then
client=self:AddClient(Event.IniDCSUnitName)
end
-- Add player.
@@ -1711,19 +1434,14 @@ function DATABASE:_EventOnBirth( Event )
if not self.PLAYERS[PlayerName] then
self:AddPlayer( Event.IniUnitName, PlayerName )
end
local function SetPlayerSettings(self,PlayerName,IniUnit)
-- Player settings.
local Settings = SETTINGS:Set( PlayerName )
--Settings:SetPlayerMenu(Event.IniUnit)
Settings:SetPlayerMenu(IniUnit)
-- Create an event.
self:CreateEventPlayerEnterAircraft(IniUnit)
--self:CreateEventPlayerEnterAircraft(Event.IniUnit)
end
self:ScheduleOnce(1,SetPlayerSettings,self,PlayerName,Event.IniUnit)
-- Player settings.
local Settings = SETTINGS:Set( PlayerName )
Settings:SetPlayerMenu(Event.IniUnit)
-- Create an event.
self:CreateEventPlayerEnterAircraft(Event.IniUnit)
end
end
@@ -1737,6 +1455,7 @@ end
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:_EventOnDeadOrCrash( Event )
if Event.IniDCSUnit then
local name=Event.IniDCSUnitName
@@ -1744,7 +1463,7 @@ function DATABASE:_EventOnDeadOrCrash( Event )
if Event.IniObjectCategory == 3 then
---
-- STATICS
-- STATICS
---
if self.STATICS[Event.IniDCSUnitName] then
@@ -1754,7 +1473,7 @@ function DATABASE:_EventOnDeadOrCrash( Event )
---
-- Maybe a UNIT?
---
-- Delete unit.
if self.UNITS[Event.IniDCSUnitName] then
self:T("STATIC Event for UNIT "..tostring(Event.IniDCSUnitName))
@@ -1777,8 +1496,7 @@ function DATABASE:_EventOnDeadOrCrash( Event )
-- Delete unit.
if self.UNITS[Event.IniDCSUnitName] then
self:ScheduleOnce(1,self.DeleteUnit,self,Event.IniDCSUnitName)
--self:DeleteUnit(Event.IniDCSUnitName)
self:DeleteUnit(Event.IniDCSUnitName)
end
-- Remove client players.
@@ -1845,15 +1563,6 @@ function DATABASE:_EventOnPlayerEnterUnit( Event )
end
end
--- Handles the OnDynamicCargoRemoved event to clean the active dynamic cargo table.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:_EventOnDynamicCargoRemoved( Event )
self:T( { Event } )
if Event.IniDynamicCargoName then
self:DeleteDynamicCargo(Event.IniDynamicCargoName)
end
end
--- Handles the OnPlayerLeaveUnit event to clean the active players table.
-- @param #DATABASE self
@@ -1877,7 +1586,7 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event )
if Event.IniObjectCategory == 1 then
-- Try to get the player name. This can be buggy for multicrew aircraft!
local PlayerName = Event.IniPlayerName or Event.IniUnit:GetPlayerName() or FindPlayerName(Event.IniUnitName)
local PlayerName = Event.IniUnit:GetPlayerName() or FindPlayerName(Event.IniUnitName)
if PlayerName then
@@ -1895,7 +1604,6 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event )
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
if client then
client:RemovePlayer(PlayerName)
--self.PLAYERSETTINGS[PlayerName] = nil
end
end
@@ -2274,7 +1982,7 @@ function DATABASE:_RegisterTemplates()
for group_num, Template in pairs(obj_type_data.group) do
if obj_type_name ~= "static" and Template and Template.units and type(Template.units) == 'table' then --making sure again- this is a valid group
self:_RegisterGroupTemplate(Template, CoalitionSide, _DATABASECategory[string.lower(CategoryName)], CountryID)
else

View File

@@ -194,11 +194,6 @@ world.event.S_EVENT_NEW_ZONE_GOAL = world.event.S_EVENT_MAX + 1004
world.event.S_EVENT_DELETE_ZONE_GOAL = world.event.S_EVENT_MAX + 1005
world.event.S_EVENT_REMOVE_UNIT = world.event.S_EVENT_MAX + 1006
world.event.S_EVENT_PLAYER_ENTER_AIRCRAFT = world.event.S_EVENT_MAX + 1007
-- dynamic cargo
world.event.S_EVENT_NEW_DYNAMIC_CARGO = world.event.S_EVENT_MAX + 1008
world.event.S_EVENT_DYNAMIC_CARGO_LOADED = world.event.S_EVENT_MAX + 1009
world.event.S_EVENT_DYNAMIC_CARGO_UNLOADED = world.event.S_EVENT_MAX + 1010
world.event.S_EVENT_DYNAMIC_CARGO_REMOVED = world.event.S_EVENT_MAX + 1011
--- The different types of events supported by MOOSE.
@@ -266,29 +261,17 @@ EVENTS = {
SimulationStart = world.event.S_EVENT_SIMULATION_START or -1,
WeaponRearm = world.event.S_EVENT_WEAPON_REARM or -1,
WeaponDrop = world.event.S_EVENT_WEAPON_DROP or -1,
-- Added with DCS 2.9.x
--UnitTaskTimeout = world.event.S_EVENT_UNIT_TASK_TIMEOUT or -1,
UnitTaskComplete = world.event.S_EVENT_UNIT_TASK_COMPLETE or -1,
-- Added with DCS 2.9.0
UnitTaskTimeout = world.event.S_EVENT_UNIT_TASK_TIMEOUT or -1,
UnitTaskStage = world.event.S_EVENT_UNIT_TASK_STAGE or -1,
--MacSubtaskScore = world.event.S_EVENT_MAC_SUBTASK_SCORE or -1,
MacSubtaskScore = world.event.S_EVENT_MAC_SUBTASK_SCORE or -1,
MacExtraScore = world.event.S_EVENT_MAC_EXTRA_SCORE or -1,
MissionRestart = world.event.S_EVENT_MISSION_RESTART or -1,
MissionWinner = world.event.S_EVENT_MISSION_WINNER or -1,
RunwayTakeoff = world.event.S_EVENT_RUNWAY_TAKEOFF or -1,
RunwayTouch = world.event.S_EVENT_RUNWAY_TOUCH or -1,
MacLMSRestart = world.event.S_EVENT_MAC_LMS_RESTART or -1,
SimulationFreeze = world.event.S_EVENT_SIMULATION_FREEZE or -1,
SimulationUnfreeze = world.event.S_EVENT_SIMULATION_UNFREEZE or -1,
HumanAircraftRepairStart = world.event.S_EVENT_HUMAN_AIRCRAFT_REPAIR_START or -1,
HumanAircraftRepairFinish = world.event.S_EVENT_HUMAN_AIRCRAFT_REPAIR_FINISH or -1,
-- dynamic cargo
NewDynamicCargo = world.event.S_EVENT_NEW_DYNAMIC_CARGO or -1,
DynamicCargoLoaded = world.event.S_EVENT_DYNAMIC_CARGO_LOADED or -1,
DynamicCargoUnloaded = world.event.S_EVENT_DYNAMIC_CARGO_UNLOADED or -1,
DynamicCargoRemoved = world.event.S_EVENT_DYNAMIC_CARGO_REMOVED or -1,
PostponedTakeoff = world.event.S_EVENT_POSTPONED_TAKEOFF or -1,
PostponedLand = world.event.S_EVENT_POSTPONED_LAND or -1,
}
--- The Event structure
-- Note that at the beginning of each field description, there is an indication which field will be populated depending on the object type involved in the Event:
--
@@ -344,9 +327,6 @@ EVENTS = {
--
-- @field Core.Zone#ZONE Zone The zone object.
-- @field #string ZoneName The name of the zone.
--
-- @field Wrapper.DynamicCargo#DYNAMICCARGO IniDynamicCargo The dynamic cargo object.
-- @field #string IniDynamicCargoName The dynamic cargo unit name.
@@ -666,24 +646,24 @@ local _EVENTMETA = {
Text = "S_EVENT_WEAPON_DROP"
},
-- DCS 2.9
--[EVENTS.UnitTaskTimeout] = {
-- Order = 1,
-- Side = "I",
-- Event = "OnEventUnitTaskTimeout",
-- Text = "S_EVENT_UNIT_TASK_TIMEOUT "
--},
[EVENTS.UnitTaskTimeout] = {
Order = 1,
Side = "I",
Event = "OnEventUnitTaskTimeout",
Text = "S_EVENT_UNIT_TASK_TIMEOUT "
},
[EVENTS.UnitTaskStage] = {
Order = 1,
Side = "I",
Event = "OnEventUnitTaskStage",
Text = "S_EVENT_UNIT_TASK_STAGE "
},
--[EVENTS.MacSubtaskScore] = {
-- Order = 1,
--Side = "I",
--Event = "OnEventMacSubtaskScore",
--Text = "S_EVENT_MAC_SUBTASK_SCORE"
--},
[EVENTS.MacSubtaskScore] = {
Order = 1,
Side = "I",
Event = "OnEventMacSubtaskScore",
Text = "S_EVENT_MAC_SUBTASK_SCORE"
},
[EVENTS.MacExtraScore] = {
Order = 1,
Side = "I",
@@ -702,76 +682,20 @@ local _EVENTMETA = {
Event = "OnEventMissionWinner",
Text = "S_EVENT_MISSION_WINNER"
},
[EVENTS.RunwayTakeoff] = {
[EVENTS.PostponedTakeoff] = {
Order = 1,
Side = "I",
Event = "OnEventRunwayTakeoff",
Text = "S_EVENT_RUNWAY_TAKEOFF"
Event = "OnEventPostponedTakeoff",
Text = "S_EVENT_POSTPONED_TAKEOFF"
},
[EVENTS.RunwayTouch] = {
[EVENTS.PostponedLand] = {
Order = 1,
Side = "I",
Event = "OnEventRunwayTouch",
Text = "S_EVENT_RUNWAY_TOUCH"
},
[EVENTS.MacLMSRestart] = {
Order = 1,
Side = "I",
Event = "OnEventMacLMSRestart",
Text = "S_EVENT_MAC_LMS_RESTART"
},
[EVENTS.SimulationFreeze] = {
Order = 1,
Side = "I",
Event = "OnEventSimulationFreeze",
Text = "S_EVENT_SIMULATION_FREEZE"
},
[EVENTS.SimulationUnfreeze] = {
Order = 1,
Side = "I",
Event = "OnEventSimulationUnfreeze",
Text = "S_EVENT_SIMULATION_UNFREEZE"
},
[EVENTS.HumanAircraftRepairStart] = {
Order = 1,
Side = "I",
Event = "OnEventHumanAircraftRepairStart",
Text = "S_EVENT_HUMAN_AIRCRAFT_REPAIR_START"
},
[EVENTS.HumanAircraftRepairFinish] = {
Order = 1,
Side = "I",
Event = "OnEventHumanAircraftRepairFinish",
Text = "S_EVENT_HUMAN_AIRCRAFT_REPAIR_FINISH"
},
-- dynamic cargo
[EVENTS.NewDynamicCargo] = {
Order = 1,
Side = "I",
Event = "OnEventNewDynamicCargo",
Text = "S_EVENT_NEW_DYNAMIC_CARGO"
},
[EVENTS.DynamicCargoLoaded] = {
Order = 1,
Side = "I",
Event = "OnEventDynamicCargoLoaded",
Text = "S_EVENT_DYNAMIC_CARGO_LOADED"
},
[EVENTS.DynamicCargoUnloaded] = {
Order = 1,
Side = "I",
Event = "OnEventDynamicCargoUnloaded",
Text = "S_EVENT_DYNAMIC_CARGO_UNLOADED"
},
[EVENTS.DynamicCargoRemoved] = {
Order = 1,
Side = "I",
Event = "OnEventDynamicCargoRemoved",
Text = "S_EVENT_DYNAMIC_CARGO_REMOVED"
Event = "OnEventPostponedLand",
Text = "S_EVENT_POSTPONED_LAND"
},
}
--- The Events structure
-- @type EVENT.Events
-- @field #number IniUnit
@@ -1184,63 +1108,7 @@ do -- Event Creation
world.onEvent( Event )
end
--- Creation of a S_EVENT_NEW_DYNAMIC_CARGO event.
-- @param #EVENT self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function EVENT:CreateEventNewDynamicCargo(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.NewDynamicCargo,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_LOADED event.
-- @param #EVENT self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function EVENT:CreateEventDynamicCargoLoaded(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoLoaded,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_UNLOADED event.
-- @param #EVENT self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function EVENT:CreateEventDynamicCargoUnloaded(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoUnloaded,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
--- Creation of a S_EVENT_DYNAMIC_CARGO_REMOVED event.
-- @param #EVENT self
-- @param Wrapper.DynamicCargo#DYNAMICCARGO DynamicCargo the dynamic cargo object
function EVENT:CreateEventDynamicCargoRemoved(DynamicCargo)
self:F({DynamicCargo})
local Event = {
id = EVENTS.DynamicCargoRemoved,
time = timer.getTime(),
dynamiccargo = DynamicCargo,
initiator = DynamicCargo:GetDCSObject(),
}
world.onEvent( Event )
end
end
--- Main event function.
@@ -1329,7 +1197,6 @@ function EVENT:onEvent( Event )
end
Event.IniDCSGroupName = Event.IniUnit and Event.IniUnit.GroupName or ""
Event.IniGroupName=Event.IniDCSGroupName --At least set the group name because group might not exist any more
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
@@ -1356,13 +1223,7 @@ function EVENT:onEvent( Event )
Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
if string.match(Event.IniUnitName,".+|%d%d:%d%d|PKG%d+") then
Event.IniDynamicCargo = DYNAMICCARGO:FindByName(Event.IniUnitName)
Event.IniDynamicCargoName = Event.IniUnitName
Event.IniPlayerName = string.match(Event.IniUnitName,"^(.+)|%d%d:%d%d|PKG%d+")
else
Event.IniUnit = CARGO:FindByName( Event.IniDCSUnitName )
end
Event.IniUnit = CARGO:FindByName( Event.IniDCSUnitName )
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
@@ -1372,7 +1233,7 @@ function EVENT:onEvent( Event )
-- Scenery
---
Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit.getName and Event.IniDCSUnit:getName() or "Scenery no name "..math.random(1,20000)
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = SCENERY:Register( Event.IniDCSUnitName, Event.initiator )
Event.IniCategory = Event.IniDCSUnit:getDesc().category
@@ -1440,7 +1301,7 @@ function EVENT:onEvent( Event )
-- STATIC
---
Event.TgtDCSUnit = Event.target
if Event.target.isExist and Event.target:isExist() and Event.id ~= 33 then -- leave out ejected seat object, check that isExist exists (Kiowa Hellfire issue, Special K)
if Event.target:isExist() and Event.id ~= 33 then -- leave out ejected seat object
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
-- Workaround for borked target info on cruise missiles
if Event.TgtDCSUnitName and Event.TgtDCSUnitName ~= "" then
@@ -1474,26 +1335,24 @@ function EVENT:onEvent( Event )
-- SCENERY
---
Event.TgtDCSUnit = Event.target
Event.TgtDCSUnitName = Event.TgtDCSUnit.getName and Event.TgtDCSUnit.getName() or nil
if Event.TgtDCSUnitName~=nil then
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = SCENERY:Register( Event.TgtDCSUnitName, Event.target )
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = SCENERY:Register( Event.TgtDCSUnitName, Event.target )
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end
end
-- Weapon.
if Event.weapon and type(Event.weapon) == "table" and Event.weapon.isExist and Event.weapon:isExist() then
if Event.weapon then
Event.Weapon = Event.weapon
Event.WeaponName = Event.weapon:isExist() and Event.weapon:getTypeName() or "Unknown Weapon"
Event.WeaponName = Event.Weapon:getTypeName()
Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit!
Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon.getPlayerName and Event.Weapon:getPlayerName()
--Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon:getPlayerName()
Event.WeaponCoalition = Event.WeaponUNIT and Event.Weapon.getCoalition and Event.Weapon:getCoalition()
Event.WeaponCategory = Event.WeaponUNIT and Event.Weapon.getDesc and Event.Weapon:getDesc().category
Event.WeaponTypeName = Event.WeaponUNIT and Event.Weapon.getTypeName and Event.Weapon:getTypeName()
Event.WeaponCoalition = Event.WeaponUNIT and Event.Weapon:getCoalition()
Event.WeaponCategory = Event.WeaponUNIT and Event.Weapon:getDesc().category
Event.WeaponTypeName = Event.WeaponUNIT and Event.Weapon:getTypeName()
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
end
@@ -1519,7 +1378,6 @@ function EVENT:onEvent( Event )
Event.MarkCoordinate=COORDINATE:NewFromVec3(Event.pos)
Event.MarkText=Event.text
Event.MarkCoalition=Event.coalition
Event.IniCoalition=Event.coalition
Event.MarkGroupID = Event.groupID
end
@@ -1528,15 +1386,6 @@ function EVENT:onEvent( Event )
Event.Cargo = Event.cargo
Event.CargoName = Event.cargo.Name
end
-- Dynamic cargo Object
if Event.dynamiccargo then
Event.IniDynamicCargo = Event.dynamiccargo
Event.IniDynamicCargoName = Event.IniDynamicCargo.StaticName
if Event.IniDynamicCargo.Owner or Event.IniUnitName then
Event.IniPlayerName = Event.IniDynamicCargo.Owner or string.match(Event.IniUnitName or "None|00:00|PKG00","^(.+)|%d%d:%d%d|PKG%d+")
end
end
-- Zone object.
if Event.zone then

View File

@@ -17,7 +17,7 @@
-- ### Author: **Applevangelist**
--
-- Date: 5 May 2021
-- Last Update: Mar 2023
-- Last Update: Feb 2023
--
-- ===
---
@@ -50,7 +50,7 @@ MARKEROPS_BASE = {
ClassName = "MARKEROPS",
Tag = "mytag",
Keywords = {},
version = "0.1.3",
version = "0.1.1",
debug = false,
Casesensitive = true,
}
@@ -108,30 +108,23 @@ function MARKEROPS_BASE:New(Tagname,Keywords,Casesensitive)
--- On after "MarkAdded" event. Triggered when a Marker is added to the F10 map.
-- @function [parent=#MARKEROPS_BASE] OnAfterMarkAdded
-- @param #MARKEROPS_BASE self
-- @param #string From The From state.
-- @param #string Event The Event called.
-- @param #string To The To state.
-- @param #string Text The text on the marker.
-- @param #table Keywords Table of matching keywords found in the Event text.
-- @param #string From The From state
-- @param #string Event The Event called
-- @param #string To The To state
-- @param #string Text The text on the marker
-- @param #table Keywords Table of matching keywords found in the Event text
-- @param Core.Point#COORDINATE Coord Coordinate of the marker.
-- @param #number MarkerID Id of this marker.
-- @param #number CoalitionNumber Coalition of the marker creator.
-- @param #string PlayerName Name of the player creating/changing the mark. nil if it cannot be obtained.
-- @param Core.Event#EVENTDATA EventData the event data table.
--- On after "MarkChanged" event. Triggered when a Marker is changed on the F10 map.
-- @function [parent=#MARKEROPS_BASE] OnAfterMarkChanged
-- @param #MARKEROPS_BASE self
-- @param #string From The From state.
-- @param #string Event The Event called.
-- @param #string To The To state.
-- @param #string Text The text on the marker.
-- @param #table Keywords Table of matching keywords found in the Event text.
-- @param #string From The From state
-- @param #string Event The Event called
-- @param #string To The To state
-- @param #string Text The text on the marker
-- @param #table Keywords Table of matching keywords found in the Event text
-- @param Core.Point#COORDINATE Coord Coordinate of the marker.
-- @param #number MarkerID Id of this marker.
-- @param #number CoalitionNumber Coalition of the marker creator.
-- @param #string PlayerName Name of the player creating/changing the mark. nil if it cannot be obtained.
-- @param Core.Event#EVENTDATA EventData the event data table
-- @param #number idx DCS Marker ID
--- On after "MarkDeleted" event. Triggered when a Marker is deleted from the F10 map.
-- @function [parent=#MARKEROPS_BASE] OnAfterMarkDeleted
@@ -140,7 +133,7 @@ function MARKEROPS_BASE:New(Tagname,Keywords,Casesensitive)
-- @param #string Event The Event called
-- @param #string To The To state
--- "Stop" trigger. Used to stop the function an unhandle events
--- "Stop" trigger. Used to stop the function an unhandle events
-- @function [parent=#MARKEROPS_BASE] Stop
end
@@ -162,30 +155,29 @@ function MARKEROPS_BASE:OnEventMark(Event)
local text = tostring(Event.text)
local m = MESSAGE:New(string.format("Mark added at %s with text: %s",coordtext,text),10,"Info",false):ToAll()
end
local coalition = Event.MarkCoalition
-- decision
if Event.id==world.event.S_EVENT_MARK_ADDED then
self:T({event="S_EVENT_MARK_ADDED", carrier=Event.IniGroupName, vec3=Event.pos})
self:T({event="S_EVENT_MARK_ADDED", carrier=self.groupname, vec3=Event.pos})
-- Handle event
local Eventtext = tostring(Event.text)
if Eventtext~=nil then
if self:_MatchTag(Eventtext) then
local matchtable = self:_MatchKeywords(Eventtext)
self:MarkAdded(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event)
self:MarkAdded(Eventtext,matchtable,coord)
end
end
elseif Event.id==world.event.S_EVENT_MARK_CHANGE then
self:T({event="S_EVENT_MARK_CHANGE", carrier=Event.IniGroupName, vec3=Event.pos})
self:T({event="S_EVENT_MARK_CHANGE", carrier=self.groupname, vec3=Event.pos})
-- Handle event.
local Eventtext = tostring(Event.text)
if Eventtext~=nil then
if self:_MatchTag(Eventtext) then
local matchtable = self:_MatchKeywords(Eventtext)
self:MarkChanged(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event)
self:MarkChanged(Eventtext,matchtable,coord,Event.idx)
end
end
elseif Event.id==world.event.S_EVENT_MARK_REMOVED then
self:T({event="S_EVENT_MARK_REMOVED", carrier=Event.IniGroupName, vec3=Event.pos})
self:T({event="S_EVENT_MARK_REMOVED", carrier=self.groupname, vec3=Event.pos})
-- Hande event.
local Eventtext = tostring(Event.text)
if Eventtext~=nil then
@@ -238,10 +230,8 @@ end
-- @param #string To The To state
-- @param #string Text The text on the marker
-- @param #table Keywords Table of matching keywords found in the Event text
-- @param #number MarkerID Id of this marker
-- @param #number CoalitionNumber Coalition of the marker creator
-- @param Core.Point#COORDINATE Coord Coordinate of the marker.
function MARKEROPS_BASE:onbeforeMarkAdded(From,Event,To,Text,Keywords,Coord,MarkerID,CoalitionNumber)
function MARKEROPS_BASE:onbeforeMarkAdded(From,Event,To,Text,Keywords,Coord)
self:T({self.lid,From,Event,To,Text,Keywords,Coord:ToStringLLDDM()})
end
@@ -252,10 +242,8 @@ end
-- @param #string To The To state
-- @param #string Text The text on the marker
-- @param #table Keywords Table of matching keywords found in the Event text
-- @param #number MarkerID Id of this marker
-- @param #number CoalitionNumber Coalition of the marker creator
-- @param Core.Point#COORDINATE Coord Coordinate of the marker.
function MARKEROPS_BASE:onbeforeMarkChanged(From,Event,To,Text,Keywords,Coord,MarkerID,CoalitionNumber)
function MARKEROPS_BASE:onbeforeMarkChanged(From,Event,To,Text,Keywords,Coord)
self:T({self.lid,From,Event,To,Text,Keywords,Coord:ToStringLLDDM()})
end

File diff suppressed because it is too large Load Diff

View File

@@ -75,37 +75,35 @@ MESSAGE.Type = {
--- Creates a new MESSAGE object. Note that these MESSAGE objects are not yet displayed on the display panel. You must use the functions @{#MESSAGE.ToClient} or @{#MESSAGE.ToCoalition} or @{#MESSAGE.ToAll} to send these Messages to the respective recipients.
-- @param self
-- @param #string Text is the text of the Message.
-- @param #number Duration Duration in seconds how long the message text is shown.
-- @param #string Category (Optional) String expressing the "category" of the Message. The category will be shown as the first text in the message followed by a ": ".
-- @param #string MessageText is the text of the Message.
-- @param #number MessageDuration is a number in seconds of how long the MESSAGE should be shown on the display panel.
-- @param #string MessageCategory (optional) is a string expressing the "category" of the Message. The category will be shown as the first text in the message followed by a ": ".
-- @param #boolean ClearScreen (optional) Clear all previous messages if true.
-- @return #MESSAGE self
-- @return #MESSAGE
-- @usage
--
-- -- Create a series of new Messages.
-- -- MessageAll is meant to be sent to all players, for 25 seconds, and is classified as "Score".
-- -- MessageRED is meant to be sent to the RED players only, for 10 seconds, and is classified as "End of Mission", with ID "Win".
-- -- MessageClient1 is meant to be sent to a Client, for 25 seconds, and is classified as "Score", with ID "Score".
-- -- MessageClient1 is meant to be sent to a Client, for 25 seconds, and is classified as "Score", with ID "Score".
-- -- Create a series of new Messages.
-- -- MessageAll is meant to be sent to all players, for 25 seconds, and is classified as "Score".
-- -- MessageRED is meant to be sent to the RED players only, for 10 seconds, and is classified as "End of Mission", with ID "Win".
-- -- MessageClient1 is meant to be sent to a Client, for 25 seconds, and is classified as "Score", with ID "Score".
-- -- MessageClient1 is meant to be sent to a Client, for 25 seconds, and is classified as "Score", with ID "Score".
-- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", 25, "End of Mission" )
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty" )
-- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", 25, "Score" )
-- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", 25, "Score")
--
function MESSAGE:New( Text, Duration, Category, ClearScreen )
function MESSAGE:New( MessageText, MessageDuration, MessageCategory, ClearScreen )
local self = BASE:Inherit( self, BASE:New() )
self:F( { Text, Duration, Category } )
self:F( { MessageText, MessageDuration, MessageCategory } )
self.MessageType = nil
-- When no MessageCategory is given, we don't show it as a title...
if Category and Category ~= "" then
if Category:sub( -1 ) ~= "\n" then
self.MessageCategory = Category .. ": "
if MessageCategory and MessageCategory ~= "" then
if MessageCategory:sub( -1 ) ~= "\n" then
self.MessageCategory = MessageCategory .. ": "
else
self.MessageCategory = Category:sub( 1, -2 ) .. ":\n"
self.MessageCategory = MessageCategory:sub( 1, -2 ) .. ":\n"
end
else
self.MessageCategory = ""
@@ -116,9 +114,9 @@ function MESSAGE:New( Text, Duration, Category, ClearScreen )
self.ClearScreen = ClearScreen
end
self.MessageDuration = Duration or 5
self.MessageDuration = MessageDuration or 5
self.MessageTime = timer.getTime()
self.MessageText = Text:gsub( "^\n", "", 1 ):gsub( "\n$", "", 1 )
self.MessageText = MessageText:gsub( "^\n", "", 1 ):gsub( "\n$", "", 1 )
self.MessageSent = false
self.MessageGroup = false
@@ -179,22 +177,40 @@ end
--
-- -- Send the 2 messages created with the @{New} method to the Client Group.
-- -- Note that the Message of MessageClient2 is overwriting the Message of MessageClient1.
-- Client = CLIENT:FindByName("NameOfClientUnit")
-- ClientGroup = Group.getByName( "ClientGroup" )
--
-- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", 25, "Score" ):ToClient( Client )
-- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", 25, "Score" ):ToClient( Client )
-- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25, "Score" ):ToClient( ClientGroup )
-- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25, "Score" ):ToClient( ClientGroup )
-- or
-- MESSAGE:New( "Congratulations, you've just hit a target", 25, "Score"):ToClient( Client )
-- MESSAGE:New( "Congratulations, you've just killed a target", 25, "Score"):ToClient( Client )
-- MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25 ):ToClient( ClientGroup )
-- MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25 ):ToClient( ClientGroup )
-- or
-- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", 25, "Score")
-- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", 25, "Score")
-- MessageClient1:ToClient( Client )
-- MessageClient2:ToClient( Client )
-- MessageClient1 = MESSAGE:New( "Congratulations, you've just hit a target", "Score", 25 )
-- MessageClient2 = MESSAGE:New( "Congratulations, you've just killed a target", "Score", 25 )
-- MessageClient1:ToClient( ClientGroup )
-- MessageClient2:ToClient( ClientGroup )
--
function MESSAGE:ToClient( Client, Settings )
self:F( Client )
self:ToUnit(Client,Settings)
if Client and Client:GetClientGroupID() then
if self.MessageType then
local Settings = Settings or ( Client and _DATABASE:GetPlayerSettings( Client:GetPlayerName() ) ) or _SETTINGS -- Core.Settings#SETTINGS
self.MessageDuration = Settings:GetMessageTime( self.MessageType )
self.MessageCategory = "" -- self.MessageType .. ": "
end
local Unit = Client:GetClient()
if self.MessageDuration ~= 0 then
local ClientGroupID = Client:GetClientGroupID()
self:T( self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration )
--trigger.action.outTextForGroup( ClientGroupID, self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration , self.ClearScreen)
trigger.action.outTextForUnit( Unit:GetID(), self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration , self.ClearScreen)
end
end
return self
end
@@ -241,7 +257,6 @@ function MESSAGE:ToUnit( Unit, Settings )
if self.MessageDuration ~= 0 then
self:T( self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$","") .. " / " .. self.MessageDuration )
local ID = Unit:GetID()
trigger.action.outTextForUnit( Unit:GetID(), self.MessageCategory .. self.MessageText:gsub("\n$",""):gsub("\n$",""), self.MessageDuration, self.ClearScreen )
end
end
@@ -290,11 +305,11 @@ end
-- @usage
--
-- -- Send a message created with the @{New} method to the BLUE coalition.
-- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToBlue()
-- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", "Penalty", 25):ToBlue()
-- or
-- MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToBlue()
-- MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 ):ToBlue()
-- or
-- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", 25, "Penalty")
-- MessageBLUE = MESSAGE:New( "To the BLUE Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 )
-- MessageBLUE:ToBlue()
--
function MESSAGE:ToBlue()
@@ -311,11 +326,11 @@ end
-- @usage
--
-- -- Send a message created with the @{New} method to the RED coalition.
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToRed()
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 ):ToRed()
-- or
-- MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToRed()
-- MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 ):ToRed()
-- or
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty")
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 )
-- MessageRED:ToRed()
--
function MESSAGE:ToRed()
@@ -334,11 +349,11 @@ end
-- @usage
--
-- -- Send a message created with the @{New} method to the RED coalition.
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToCoalition( coalition.side.RED )
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 ):ToCoalition( coalition.side.RED )
-- or
-- MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty"):ToCoalition( coalition.side.RED )
-- MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 ):ToCoalition( coalition.side.RED )
-- or
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", 25, "Penalty")
-- MessageRED = MESSAGE:New( "To the RED Players: You receive a penalty because you've killed one of your own units", "Penalty", 25 )
-- MessageRED:ToCoalition( coalition.side.RED )
--
function MESSAGE:ToCoalition( CoalitionSide, Settings )
@@ -380,36 +395,29 @@ end
--- Sends a MESSAGE to all players.
-- @param #MESSAGE self
-- @param Core.Settings#Settings Settings (Optional) Settings for message display.
-- @param #number Delay (Optional) Delay in seconds before the message is send. Default instantly (`nil`).
-- @return #MESSAGE self
-- @return #MESSAGE
-- @usage
--
-- -- Send a message created to all players.
-- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", 25, "End of Mission"):ToAll()
-- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", "End of Mission", 25 ):ToAll()
-- or
-- MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", 25, "End of Mission"):ToAll()
-- MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", "End of Mission", 25 ):ToAll()
-- or
-- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", 25, "End of Mission")
-- MessageAll = MESSAGE:New( "To all Players: BLUE has won! Each player of BLUE wins 50 points!", "End of Mission", 25 )
-- MessageAll:ToAll()
--
function MESSAGE:ToAll( Settings, Delay )
function MESSAGE:ToAll( Settings )
self:F()
if Delay and Delay>0 then
self:ScheduleOnce(Delay, MESSAGE.ToAll, self, Settings, 0)
else
if self.MessageType then
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
self.MessageDuration = Settings:GetMessageTime( self.MessageType )
self.MessageCategory = "" -- self.MessageType .. ": "
end
if self.MessageType then
local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS
self.MessageDuration = Settings:GetMessageTime( self.MessageType )
self.MessageCategory = "" -- self.MessageType .. ": "
end
if self.MessageDuration ~= 0 then
self:T( self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ) .. " / " .. self.MessageDuration )
trigger.action.outText( self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ), self.MessageDuration, self.ClearScreen )
end
if self.MessageDuration ~= 0 then
self:T( self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ) .. " / " .. self.MessageDuration )
trigger.action.outText( self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ), self.MessageDuration, self.ClearScreen )
end
return self
@@ -501,10 +509,10 @@ function MESSAGE.SetMSRS(PathToSRS,Port,PathToCredentials,Frequency,Modulation,G
end
_MESSAGESRS.label = Label or MSRS.Label or "MESSAGE"
_MESSAGESRS.MSRS:SetLabel(_MESSAGESRS.label)
_MESSAGESRS.MSRS:SetLabel(Label or "MESSAGE")
_MESSAGESRS.port = Port or MSRS.port or 5002
_MESSAGESRS.MSRS:SetPort(_MESSAGESRS.port)
_MESSAGESRS.MSRS:SetPort(Port or 5002)
_MESSAGESRS.volume = Volume or MSRS.volume or 1
_MESSAGESRS.MSRS:SetVolume(_MESSAGESRS.volume)

View File

@@ -73,7 +73,7 @@ PATHLINE = {
--- PATHLINE class version.
-- @field #string version
PATHLINE.version="0.1.1"
PATHLINE.version="0.1.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@@ -237,14 +237,13 @@ end
--- Get COORDINATES of pathline. Note that COORDINATE objects are created when calling this function. That does involve deep copy calls and can have an impact on performance if done too often.
-- @param #PATHLINE self
-- @return <Core.Point#COORDINATE> List of COORDINATES points.
function PATHLINE:GetCoordinates()
function PATHLINE:GetCoordinats()
local vecs={}
for _,_point in pairs(self.points) do
local point=_point --#PATHLINE.Point
local coord=COORDINATE:NewFromVec3(point.vec3)
table.insert(vecs,coord)
end
return vecs
@@ -263,7 +262,7 @@ function PATHLINE:GetPointFromIndex(n)
local point=nil --#PATHLINE.Point
if n>=1 and n<=N then
point=self.points[n]
point=self.point[n]
else
self:E(self.lid..string.format("ERROR: No point in pathline for N=%s", tostring(n)))
end
@@ -368,4 +367,4 @@ end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -702,9 +702,8 @@ do -- COORDINATE
-- @param #COORDINATE PointVec2Reference The reference @{#COORDINATE}.
-- @return DCS#Distance The distance from the reference @{#COORDINATE} in meters.
function COORDINATE:DistanceFromPointVec2( PointVec2Reference )
self:F2( PointVec2Reference )
if not PointVec2Reference then return math.huge end
self:F2( PointVec2Reference )
local Distance = ( ( PointVec2Reference.x - self.x ) ^ 2 + ( PointVec2Reference.z - self.z ) ^2 ) ^ 0.5
self:T2( Distance )
@@ -2233,7 +2232,7 @@ do -- COORDINATE
-- local MarkGroup = GROUP:FindByName( "AttackGroup" )
-- local MarkID = TargetCoord:MarkToGroup( "This is a target for the attack group", AttackGroup )
-- <<< logic >>>
-- TargetCoord:RemoveMark( MarkID ) -- The mark is now removed
-- RemoveMark( MarkID ) -- The mark is now removed
function COORDINATE:RemoveMark( MarkID )
trigger.action.removeMark( MarkID )
end
@@ -2669,9 +2668,9 @@ do -- COORDINATE
local date=UTILS.GetDCSMissionDate()
-- Debug output.
--self:I(string.format("Sun rise at lat=%.3f long=%.3f on %s (DayOfYear=%d): %s (%s sec of the day) (GMT %d)", Latitude, Longitude, date, DayOfYear, tostring(UTILS.SecondsToClock(sunrise)), tonumber(sunrise) or "0", Tdiff))
--self:I(string.format("Sun rise at lat=%.3f long=%.3f on %s (DayOfYear=%d): %s (%d sec of the day) (GMT %d)", Latitude, Longitude, date, DayOfYear, tostring(UTILS.SecondsToClock(sunrise)), sunrise, Tdiff))
if InSeconds or type(sunrise) == "string" then
if InSeconds then
return sunrise
else
return UTILS.SecondsToClock(sunrise, true)
@@ -2747,10 +2746,7 @@ do -- COORDINATE
local sunrise=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, true, Tdiff)
local sunset=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, false, Tdiff)
if sunrise == "N/R" then return false end
if sunrise == "N/S" then return true end
local time=UTILS.ClockToSeconds(clock)
-- Check if time is between sunrise and sunset.
@@ -2837,9 +2833,9 @@ do -- COORDINATE
local date=UTILS.GetDCSMissionDate()
-- Debug output.
--self:I(string.format("Sun set at lat=%.3f long=%.3f on %s (DayOfYear=%d): %s (%s sec of the day) (GMT %d)", Latitude, Longitude, date, DayOfYear, tostring(UTILS.SecondsToClock(sunrise)), tostring(sunrise) or "0", Tdiff))
--self:I(string.format("Sun set at lat=%.3f long=%.3f on %s (DayOfYear=%d): %s (%d sec of the day) (GMT %d)", Latitude, Longitude, date, DayOfYear, tostring(UTILS.SecondsToClock(sunrise)), sunrise, Tdiff))
if InSeconds or type(sunrise) == "string" then
if InSeconds then
return sunrise
else
return UTILS.SecondsToClock(sunrise, true)
@@ -3151,18 +3147,17 @@ do -- COORDINATE
-- @param #string Northing Meters northing - string in order to allow for leading zeros, e.g. "12340". Should be 5 digits.
-- @return #COORDINATE self
function COORDINATE:NewFromMGRS( UTMZone, MGRSDigraph, Easting, Northing )
if string.len(Easting) < 5 then Easting = tostring(Easting..string.rep("0",5-string.len(Easting) )) end
if string.len(Northing) < 5 then Northing = tostring(Northing..string.rep("0",5-string.len(Northing) )) end
if string.len(Easting) < 5 then Easting = Easting..string.rep("0",5-string.len(Easting) )end
if string.len(Northing) < 5 then Northing = Northing..string.rep("0",5-string.len(Northing) )end
local MGRS = {
UTMZone = UTMZone,
MGRSDigraph = MGRSDigraph,
Easting = tostring(Easting),
Northing = tostring(Northing),
Easting = Easting,
Northing = Northing,
}
local lat, lon = coord.MGRStoLL(MGRS)
local point = coord.LLtoLO(lat, lon, 0)
local coord = COORDINATE:NewFromVec2({x=point.x,y=point.z})
return coord
end
--- Provides a coordinate string of the point, based on a coordinate format system:
@@ -3414,7 +3409,7 @@ do -- COORDINATE
-- @param #COORDINATE self
-- @param #number Radius (Optional) Radius to check around the coordinate, defaults to 50m (100m diameter)
-- @param #number Minelevation (Optional) Elevation from which on a area is defined as steep, defaults to 8% (8m height gain across 100 meters)
-- @return #boolean IsSteep If true, area is steep
-- @return #boolen IsSteep If true, area is steep
-- @return #number MaxElevation Elevation in meters measured over 100m
function COORDINATE:IsInSteepArea(Radius,Minelevation)
local steep = false
@@ -3446,7 +3441,7 @@ do -- COORDINATE
-- @param #COORDINATE self
-- @param #number Radius (Optional) Radius to check around the coordinate, defaults to 50m (100m diameter)
-- @param #number Minelevation (Optional) Elevation from which on a area is defined as steep, defaults to 8% (8m height gain across 100 meters)
-- @return #boolean IsFlat If true, area is flat
-- @return #boolen IsFlat If true, area is flat
-- @return #number MaxElevation Elevation in meters measured over 100m
function COORDINATE:IsInFlatArea(Radius,Minelevation)
local steep, elev = self:IsInSteepArea(Radius,Minelevation)

File diff suppressed because it is too large Load Diff

View File

@@ -29,9 +29,7 @@
-- @module Core.Settings
-- @image Core_Settings.JPG
---
-- @type SETTINGS
--- @type SETTINGS
-- @extends Core.Base#BASE
--- Takes care of various settings that influence the behavior of certain functionalities and classes within the MOOSE framework.
@@ -220,8 +218,7 @@ SETTINGS = {
SETTINGS.__Enum = {}
---
-- @type SETTINGS.__Enum.Era
--- @type SETTINGS.__Enum.Era
-- @field #number WWII
-- @field #number Korea
-- @field #number Cold
@@ -494,7 +491,7 @@ do -- SETTINGS
return (self.A2ASystem and self.A2ASystem == "MGRS") or (not self.A2ASystem and _SETTINGS:IsA2A_MGRS())
end
-- @param #SETTINGS self
--- @param #SETTINGS self
-- @param Wrapper.Group#GROUP MenuGroup Group for which to add menus.
-- @param #table RootMenu Root menu table
-- @return #SETTINGS
@@ -740,8 +737,8 @@ do -- SETTINGS
if _SETTINGS.ShowPlayerMenu == true then
local PlayerGroup = PlayerUnit:GetGroup()
local PlayerName = PlayerUnit:GetPlayerName() or "None"
--local PlayerNames = PlayerGroup:GetPlayerNames()
local PlayerName = PlayerUnit:GetPlayerName()
local PlayerNames = PlayerGroup:GetPlayerNames()
local PlayerMenu = MENU_GROUP:New( PlayerGroup, 'Settings "' .. PlayerName .. '"' )
@@ -948,49 +945,49 @@ do -- SETTINGS
return self
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:A2GMenuSystem( MenuGroup, RootMenu, A2GSystem )
self.A2GSystem = A2GSystem
MESSAGE:New( string.format( "Settings: Default A2G coordinate system set to %s for all players!", A2GSystem ), 5 ):ToAll()
self:SetSystemMenu( MenuGroup, RootMenu )
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:A2AMenuSystem( MenuGroup, RootMenu, A2ASystem )
self.A2ASystem = A2ASystem
MESSAGE:New( string.format( "Settings: Default A2A coordinate system set to %s for all players!", A2ASystem ), 5 ):ToAll()
self:SetSystemMenu( MenuGroup, RootMenu )
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuLL_DDM_Accuracy( MenuGroup, RootMenu, LL_Accuracy )
self.LL_Accuracy = LL_Accuracy
MESSAGE:New( string.format( "Settings: Default LL accuracy set to %s for all players!", LL_Accuracy ), 5 ):ToAll()
self:SetSystemMenu( MenuGroup, RootMenu )
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuMGRS_Accuracy( MenuGroup, RootMenu, MGRS_Accuracy )
self.MGRS_Accuracy = MGRS_Accuracy
MESSAGE:New( string.format( "Settings: Default MGRS accuracy set to %s for all players!", MGRS_Accuracy ), 5 ):ToAll()
self:SetSystemMenu( MenuGroup, RootMenu )
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuMWSystem( MenuGroup, RootMenu, MW )
self.Metric = MW
MESSAGE:New( string.format( "Settings: Default measurement format set to %s for all players!", MW and "Metric" or "Imperial" ), 5 ):ToAll()
self:SetSystemMenu( MenuGroup, RootMenu )
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuMessageTimingsSystem( MenuGroup, RootMenu, MessageType, MessageTime )
self:SetMessageTime( MessageType, MessageTime )
MESSAGE:New( string.format( "Settings: Default message time set for %s to %d.", MessageType, MessageTime ), 5 ):ToAll()
end
do
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupA2GSystem( PlayerUnit, PlayerGroup, PlayerName, A2GSystem )
--BASE:E( {PlayerUnit:GetName(), A2GSystem } )
self.A2GSystem = A2GSystem
@@ -1001,7 +998,7 @@ do -- SETTINGS
end
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupA2ASystem( PlayerUnit, PlayerGroup, PlayerName, A2ASystem )
self.A2ASystem = A2ASystem
MESSAGE:New( string.format( "Settings: A2A format set to %s for player %s.", A2ASystem, PlayerName ), 5 ):ToGroup( PlayerGroup )
@@ -1011,7 +1008,7 @@ do -- SETTINGS
end
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupLL_DDM_AccuracySystem( PlayerUnit, PlayerGroup, PlayerName, LL_Accuracy )
self.LL_Accuracy = LL_Accuracy
MESSAGE:New( string.format( "Settings: LL format accuracy set to %d decimal places for player %s.", LL_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup )
@@ -1021,7 +1018,7 @@ do -- SETTINGS
end
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupMGRS_AccuracySystem( PlayerUnit, PlayerGroup, PlayerName, MGRS_Accuracy )
self.MGRS_Accuracy = MGRS_Accuracy
MESSAGE:New( string.format( "Settings: MGRS format accuracy set to %d for player %s.", MGRS_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup )
@@ -1031,7 +1028,7 @@ do -- SETTINGS
end
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupMWSystem( PlayerUnit, PlayerGroup, PlayerName, MW )
self.Metric = MW
MESSAGE:New( string.format( "Settings: Measurement format set to %s for player %s.", MW and "Metric" or "Imperial", PlayerName ), 5 ):ToGroup( PlayerGroup )
@@ -1041,7 +1038,7 @@ do -- SETTINGS
end
end
-- @param #SETTINGS self
--- @param #SETTINGS self
function SETTINGS:MenuGroupMessageTimingsSystem( PlayerUnit, PlayerGroup, PlayerName, MessageType, MessageTime )
self:SetMessageTime( MessageType, MessageTime )
MESSAGE:New( string.format( "Settings: Default message time set for %s to %d.", MessageType, MessageTime ), 5 ):ToGroup( PlayerGroup )

File diff suppressed because it is too large Load Diff

View File

@@ -1,36 +1,36 @@
--- **Core** - Spawn statics.
--
--
-- ===
--
--
-- ## Features:
--
--
-- * Spawn new statics from a static already defined in the mission editor.
-- * Spawn new statics from a given template.
-- * Spawn new statics from a given type.
-- * Spawn with a custom heading and location.
-- * Spawn within a zone.
-- * Spawn statics linked to units, .e.g on aircraft carriers.
--
--
-- ===
--
--
-- # Demo Missions
--
-- ## [SPAWNSTATIC Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master/Core/SpawnStatic)
--
-- ## [SPAWNSTATIC Demo Missions](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Core/SpawnStatic)
--
--
--
-- ===
--
--
-- # YouTube Channel
--
--
-- ## No videos yet!
--
--
-- ===
--
--
-- ### Author: **FlightControl**
-- ### Contributions: **funkyfranky**
--
--
-- ===
--
--
-- @module Core.SpawnStatic
-- @image Core_Spawnstatic.JPG
@@ -58,37 +58,37 @@
--- Allows to spawn dynamically new @{Wrapper.Static}s into your mission.
--
-- Through creating a copy of an existing static object template as defined in the Mission Editor (ME), SPAWNSTATIC can retireve the properties of the defined static object template (like type, category etc),
--
-- Through creating a copy of an existing static object template as defined in the Mission Editor (ME), SPAWNSTATIC can retireve the properties of the defined static object template (like type, category etc),
-- and "copy" these properties to create a new static object and place it at the desired coordinate.
--
-- New spawned @{Wrapper.Static}s get **the same name** as the name of the template Static, or gets the given name when a new name is provided at the Spawn method.
--
-- New spawned @{Wrapper.Static}s get **the same name** as the name of the template Static, or gets the given name when a new name is provided at the Spawn method.
-- By default, spawned @{Wrapper.Static}s will follow a naming convention at run-time:
--
--
-- * Spawned @{Wrapper.Static}s will have the name _StaticName_#_nnn_, where _StaticName_ is the name of the **Template Static**, and _nnn_ is a **counter from 0 to 99999**.
--
--
-- # SPAWNSTATIC Constructors
--
--
-- Firstly, we need to create a SPAWNSTATIC object that will be used to spawn new statics into the mission. There are three ways to do this.
--
--
-- ## Use another Static
--
--
-- A new SPAWNSTATIC object can be created using another static by the @{#SPAWNSTATIC.NewFromStatic}() function. All parameters such as position, heading, country will be initialized
-- from the static.
--
--
-- ## From a Template
--
--
-- A SPAWNSTATIC object can also be created from a template table using the @{#SPAWNSTATIC.NewFromTemplate}(SpawnTemplate, CountryID) function. All parameters are taken from the template.
--
--
-- ## From a Type
--
--
-- A very basic method is to create a SPAWNSTATIC object by just giving the type of the static. All parameters must be initialized from the InitXYZ functions described below. Otherwise default values
-- are used. For example, if no spawn coordinate is given, the static will be created at the origin of the map.
--
--
-- # Setting Parameters
--
--
-- Parameters such as the spawn position, heading, country etc. can be set via :Init*XYZ* functions. Note that these functions must be given before the actual spawn command!
--
--
-- * @{#SPAWNSTATIC.InitCoordinate}(Coordinate) Sets the coordinate where the static is spawned. Statics are always spawnd on the ground.
-- * @{#SPAWNSTATIC.InitHeading}(Heading) sets the orientation of the static.
-- * @{#SPAWNSTATIC.InitLivery}(LiveryName) sets the livery of the static. Not all statics support this.
@@ -99,17 +99,17 @@
-- * @{#SPAWNSTATIC.InitLinkToUnit}(Unit, OffsetX, OffsetY, OffsetAngle) links the static to a unit, e.g. to an aircraft carrier.
--
-- # Spawning the Statics
--
--
-- Once the SPAWNSTATIC object is created and parameters are initialized, the spawn command can be given. There are different methods where some can be used to directly set parameters
-- such as position and heading.
--
--
-- * @{#SPAWNSTATIC.Spawn}(Heading, NewName) spawns the static with the set parameters. Optionally, heading and name can be given. The name **must be unique**!
-- * @{#SPAWNSTATIC.SpawnFromCoordinate}(Coordinate, Heading, NewName) spawn the static at the given coordinate. Optionally, heading and name can be given. The name **must be unique**!
-- * @{#SPAWNSTATIC.SpawnFromPointVec2}(PointVec2, Heading, NewName) spawns the static at a POINT_VEC2 coordinate. Optionally, heading and name can be given. The name **must be unique**!
-- * @{#SPAWNSTATIC.SpawnFromZone}(Zone, Heading, NewName) spawns the static at the center of a @{Core.Zone}. Optionally, heading and name can be given. The name **must be unique**!
--
--
-- @field #SPAWNSTATIC SPAWNSTATIC
--
--
SPAWNSTATIC = {
ClassName = "SPAWNSTATIC",
SpawnIndex = 0,
@@ -139,9 +139,9 @@ SPAWNSTATIC = {
function SPAWNSTATIC:NewFromStatic(SpawnTemplateName, SpawnCountryID)
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
local TemplateStatic, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate(SpawnTemplateName)
if TemplateStatic then
self.SpawnTemplatePrefix = SpawnTemplateName
self.TemplateStaticUnit = UTILS.DeepCopy(TemplateStatic.units[1])
@@ -166,11 +166,11 @@ end
function SPAWNSTATIC:NewFromTemplate(SpawnTemplate, CountryID)
local self = BASE:Inherit( self, BASE:New() ) -- #SPAWNSTATIC
self.TemplateStaticUnit = UTILS.DeepCopy(SpawnTemplate)
self.SpawnTemplatePrefix = SpawnTemplate.name
self.CountryID = CountryID or country.id.USA
return self
end
@@ -189,69 +189,13 @@ function SPAWNSTATIC:NewFromType(StaticType, StaticCategory, CountryID)
self.InitStaticCategory=StaticCategory
self.CountryID=CountryID or country.id.USA
self.SpawnTemplatePrefix=self.InitStaticType
self.TemplateStaticUnit = {}
self.InitStaticCoordinate=COORDINATE:New(0, 0, 0)
self.InitStaticHeading=0
return self
end
--- (Internal/Cargo) Init the resource table for STATIC object that should be spawned containing storage objects.
-- NOTE that you have to init many other parameters as the resources.
-- @param #SPAWNSTATIC self
-- @param #number CombinedWeight The weight this cargo object should have (some have fixed weights!), defaults to 1kg.
-- @return #SPAWNSTATIC self
function SPAWNSTATIC:_InitResourceTable(CombinedWeight)
if not self.TemplateStaticUnit.resourcePayload then
self.TemplateStaticUnit.resourcePayload = {
["weapons"] = {},
["aircrafts"] = {},
["gasoline"] = 0,
["diesel"] = 0,
["methanol_mixture"] = 0,
["jet_fuel"] = 0,
}
end
self:InitCargo(true)
self:InitCargoMass(CombinedWeight or 1)
return self
end
--- (User/Cargo) Add to resource table for STATIC object that should be spawned containing storage objects. Inits the object table if necessary and sets it to be cargo for helicopters.
-- @param #SPAWNSTATIC self
-- @param #string Type Type of cargo. Known types are: STORAGE.Type.WEAPONS, STORAGE.Type.LIQUIDS, STORAGE.Type.AIRCRAFT. Liquids are fuel.
-- @param #string Name Name of the cargo type. Liquids can be STORAGE.LiquidName.JETFUEL, STORAGE.LiquidName.GASOLINE, STORAGE.LiquidName.MW50 and STORAGE.LiquidName.DIESEL. The currently available weapon items are available in the `ENUMS.Storage.weapons`, e.g. `ENUMS.Storage.weapons.bombs.Mk_82Y`. Aircraft go by their typename.
-- @param #number Amount of tons (liquids) or number (everything else) to add.
-- @param #number CombinedWeight Combined weight to be set to this static cargo object. NOTE - some static cargo objects have fixed weights!
-- @return #SPAWNSTATIC self
function SPAWNSTATIC:AddCargoResource(Type,Name,Amount,CombinedWeight)
if not self.TemplateStaticUnit.resourcePayload then
self:_InitResourceTable(CombinedWeight)
end
if Type == STORAGE.Type.LIQUIDS and type(Name) == "string" then
self.TemplateStaticUnit.resourcePayload[Name] = Amount
else
self.TemplateStaticUnit.resourcePayload[Type] = {
[Name] = {
["amount"] = Amount,
}
}
end
UTILS.PrintTableToLog(self.TemplateStaticUnit)
return self
end
--- (User/Cargo) Resets resource table to zero for STATIC object that should be spawned containing storage objects. Inits the object table if necessary and sets it to be cargo for helicopters.
-- Handy if you spawn from cargo statics which have resources already set.
-- @param #SPAWNSTATIC self
-- @return #SPAWNSTATIC self
function SPAWNSTATIC:ResetCargoResources()
self.TemplateStaticUnit.resourcePayload = nil
self:_InitResourceTable()
return self
end
--- Initialize heading of the spawned static.
-- @param #SPAWNSTATIC self
-- @param Core.Point#COORDINATE Coordinate Position where the static is spawned.
@@ -347,7 +291,7 @@ function SPAWNSTATIC:InitCountry(CountryID)
return self
end
--- Initialize name prefix statics get. This will be appended by "#0001", "#0002" etc.
--- Initialize name prefix statics get. This will be appended by "#0001", "#0002" etc.
-- @param #SPAWNSTATIC self
-- @param #string NamePrefix Name prefix of statics spawned. Will append #0001, etc to the name.
-- @return #SPAWNSTATIC self
@@ -373,25 +317,6 @@ function SPAWNSTATIC:InitLinkToUnit(Unit, OffsetX, OffsetY, OffsetAngle)
return self
end
--- Allows to place a CallFunction hook when a new static spawns.
-- The provided method will be called when a new group is spawned, including its given parameters.
-- The first parameter of the SpawnFunction is the @{Wrapper.Static#STATIC} that was spawned.
-- @param #SPAWNSTATIC self
-- @param #function SpawnCallBackFunction The function to be called when a group spawns.
-- @param SpawnFunctionArguments A random amount of arguments to be provided to the function when the group spawns.
-- @return #SPAWNSTATIC self
function SPAWNSTATIC:OnSpawnStatic( SpawnCallBackFunction, ... )
self:F( "OnSpawnStatic" )
self.SpawnFunctionHook = SpawnCallBackFunction
self.SpawnFunctionArguments = {}
if arg then
self.SpawnFunctionArguments = arg
end
return self
end
--- Spawn a new STATIC object.
-- @param #SPAWNSTATIC self
-- @param #number Heading (Optional) The heading of the static, which is a number in degrees from 0 to 360. Default is the heading of the template.
@@ -402,13 +327,13 @@ function SPAWNSTATIC:Spawn(Heading, NewName)
if Heading then
self.InitStaticHeading=Heading
end
if NewName then
self.InitStaticName=NewName
end
return self:_SpawnStatic(self.TemplateStaticUnit, self.CountryID)
end
--- Creates a new @{Wrapper.Static} from a POINT_VEC2.
@@ -422,7 +347,7 @@ function SPAWNSTATIC:SpawnFromPointVec2(PointVec2, Heading, NewName)
local vec2={x=PointVec2:GetX(), y=PointVec2:GetY()}
local Coordinate=COORDINATE:NewFromVec2(vec2)
return self:SpawnFromCoordinate(Coordinate, Heading, NewName)
end
@@ -437,11 +362,11 @@ function SPAWNSTATIC:SpawnFromCoordinate(Coordinate, Heading, NewName)
-- Set up coordinate.
self.InitStaticCoordinate=Coordinate
if Heading then
self.InitStaticHeading=Heading
end
if NewName then
self.InitStaticName=NewName
end
@@ -460,7 +385,7 @@ function SPAWNSTATIC:SpawnFromZone(Zone, Heading, NewName)
-- Spawn the new static at the center of the zone.
local Static = self:SpawnFromPointVec2( Zone:GetPointVec2(), Heading, NewName )
return Static
end
@@ -474,45 +399,45 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
Template=Template or {}
local CountryID=CountryID or self.CountryID
if self.InitStaticType then
Template.type=self.InitStaticType
end
if self.InitStaticCategory then
Template.category=self.InitStaticCategory
end
if self.InitStaticCoordinate then
Template.x = self.InitStaticCoordinate.x
if self.InitStaticCoordinate then
Template.x = self.InitStaticCoordinate.x
Template.y = self.InitStaticCoordinate.z
Template.alt = self.InitStaticCoordinate.y
Template.alt = self.InitStaticCoordinate.y
end
if self.InitStaticHeading then
Template.heading = math.rad(self.InitStaticHeading)
Template.heading = math.rad(self.InitStaticHeading)
end
if self.InitStaticShape then
Template.shape_name=self.InitStaticShape
end
if self.InitStaticLivery then
Template.livery_id=self.InitStaticLivery
end
if self.InitStaticDead~=nil then
Template.dead=self.InitStaticDead
end
if self.InitStaticCargo~=nil then
Template.canCargo=self.InitStaticCargo
end
if self.InitStaticCargoMass~=nil then
Template.mass=self.InitStaticCargoMass
end
if self.InitLinkUnit then
Template.linkUnit=self.InitLinkUnit:GetID()
Template.linkOffset=true
@@ -521,43 +446,49 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
Template.offsets.x=self.InitOffsetX
Template.offsets.angle=self.InitOffsetAngle and math.rad(self.InitOffsetAngle) or 0
end
if self.InitFarp then
Template.heliport_callsign_id = self.InitFarpCallsignID
Template.heliport_frequency = self.InitFarpFreq
Template.heliport_modulation = self.InitFarpModu
Template.unitId=nil
end
-- Increase spawn index counter.
self.SpawnIndex = self.SpawnIndex + 1
-- Name of the spawned static.
Template.name = self.InitStaticName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex)
-- Add and register the new static.
local mystatic=_DATABASE:AddStatic(Template.name)
-- Debug output.
self:T(Template)
-- Add static to the game.
local Static=nil --DCS#StaticObject
if self.InitFarp then
local TemplateGroup={}
local TemplateGroup={}
TemplateGroup.units={}
TemplateGroup.units[1]=Template
TemplateGroup.visible=true
TemplateGroup.hidden=false
TemplateGroup.x=Template.x
TemplateGroup.y=Template.y
TemplateGroup.name=Template.name
self:T("Spawning FARP")
self:T("Spawning FARP")
self:T({Template=Template})
self:T({TemplateGroup=TemplateGroup})
-- ED's dirty way to spawn FARPS.
Static=coalition.addGroup(CountryID, -1, TemplateGroup)
-- Currently DCS 2.8 does not trigger birth events if FARPS are spawned!
-- Currently DCS 2.8 does not trigger birth events if FAPRS are spawned!
-- We create such an event. The airbase is registered in Core.Event
local Event = {
id = EVENTS.Birth,
@@ -568,32 +499,10 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
world.onEvent(Event)
else
self:T("Spawning Static")
self:T2({Template=Template})
self:T("Spawning Static")
self:T2({Template=Template})
Static=coalition.addStaticObject(CountryID, Template)
end
if Static then
self:T(string.format("Succesfully spawned static object \"%s\" ID=%d", Static:getName(), Static:getID()))
--[[
local static=StaticObject.getByName(Static:getName())
if static then
env.info(string.format("FF got static from StaticObject.getByName"))
else
env.error(string.format("FF error did NOT get static from StaticObject.getByName"))
end ]]
else
self:E(string.format("ERROR: DCS static object \"%s\" is nil!", tostring(Template.name)))
end
end
-- Add and register the new static.
local mystatic=_DATABASE:AddStatic(Template.name)
-- If there is a SpawnFunction hook defined, call it.
if self.SpawnFunctionHook then
-- delay calling this for .3 seconds so that it hopefully comes after the BIRTH event of the group.
self:ScheduleOnce(0.3, self.SpawnFunctionHook, mystatic, unpack(self.SpawnFunctionArguments))
end
return mystatic
end

View File

@@ -58,7 +58,7 @@ do -- UserFlag
--- Set the userflag to a given Number.
-- @param #USERFLAG self
-- @param #number Number The number value to set the flag to.
-- @param #number Number The number value to be checked if it is the same as the userflag.
-- @param #number Delay Delay in seconds, before the flag is set.
-- @return #USERFLAG The userflag instance.
-- @usage
@@ -104,4 +104,4 @@ do -- UserFlag
end
end
end

View File

@@ -46,10 +46,6 @@
--
-- ===
--
-- ### [Demo Missions](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Core/Zone)
--
-- ===
--
-- ### Author: **FlightControl**
-- ### Contributions: **Applevangelist**, **FunkyFranky**, **coconutcockpit**
--
@@ -330,14 +326,14 @@ function ZONE_BASE:GetRandomVec2()
return nil
end
--- Define a random @{Core.Point#POINT_VEC2} within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
-- @param #ZONE_BASE self
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
function ZONE_BASE:GetRandomPointVec2()
return nil
end
--- Define a random @{Core.Point#POINT_VEC3} within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec3 table.
--- Define a random @{Core.Point#POINT_VEC3} within the zone.
-- @param #ZONE_BASE self
-- @return Core.Point#POINT_VEC3 The PointVec3 coordinates.
function ZONE_BASE:GetRandomPointVec3()
@@ -903,8 +899,7 @@ function ZONE_RADIUS:BoundZone( Points, CountryID, UnBound )
local Point = {}
local Vec2 = self:GetVec2()
local countryID = CountryID or country.id.USA
Points = Points and Points or 360
local Angle
@@ -915,7 +910,7 @@ function ZONE_RADIUS:BoundZone( Points, CountryID, UnBound )
Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius()
Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius()
local CountryName = _DATABASE.COUNTRY_NAME[countryID]
local CountryName = _DATABASE.COUNTRY_NAME[CountryID]
local Tire = {
["country"] = CountryName,
@@ -930,7 +925,7 @@ function ZONE_RADIUS:BoundZone( Points, CountryID, UnBound )
["heading"] = 0,
} -- end of ["group"]
local Group = coalition.addStaticObject( countryID, Tire )
local Group = coalition.addStaticObject( CountryID, Tire )
if UnBound and UnBound == true then
Group:destroy()
end
@@ -1180,7 +1175,7 @@ function ZONE_RADIUS:RemoveJunk()
return n
end
--- Get a table of scanned units.
--- Count the number of different coalitions inside the zone.
-- @param #ZONE_RADIUS self
-- @return #table Table of DCS units and DCS statics inside the zone.
function ZONE_RADIUS:GetScannedUnits()
@@ -1203,7 +1198,7 @@ function ZONE_RADIUS:GetScannedSetUnit()
if FoundUnit then
SetUnit:AddUnit( FoundUnit )
else
local FoundStatic = STATIC:FindByName( UnitObject:getName(), false )
local FoundStatic = STATIC:FindByName( UnitObject:getName() )
if FoundStatic then
SetUnit:AddUnit( FoundStatic )
end
@@ -1215,7 +1210,7 @@ function ZONE_RADIUS:GetScannedSetUnit()
return SetUnit
end
--- Get a set of scanned groups.
--- Get a set of scanned units.
-- @param #ZONE_RADIUS self
-- @return Core.Set#SET_GROUP Set of groups.
function ZONE_RADIUS:GetScannedSetGroup()
@@ -1515,7 +1510,7 @@ function ZONE_RADIUS:GetRandomVec2(inner, outer, surfacetypes)
return point
end
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone.
-- @param #ZONE_RADIUS self
-- @param #number inner (optional) Minimal distance from the center of the zone. Default is 0.
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
@@ -1546,7 +1541,7 @@ function ZONE_RADIUS:GetRandomVec3( inner, outer )
end
--- Returns a @{Core.Point#POINT_VEC3} object reflecting a random 3D location within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec3 table.
--- Returns a @{Core.Point#POINT_VEC3} object reflecting a random 3D location within the zone.
-- @param #ZONE_RADIUS self
-- @param #number inner (optional) Minimal distance from the center of the zone. Default is 0.
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
@@ -1990,7 +1985,7 @@ function ZONE_GROUP:GetRandomVec2()
return Point
end
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone.
-- @param #ZONE_GROUP self
-- @param #number inner (optional) Minimal distance from the center of the zone. Default is 0.
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
@@ -2834,7 +2829,7 @@ function ZONE_POLYGON_BASE:GetRandomVec2()
end
end
--- Return a @{Core.Point#POINT_VEC2} object representing a random 2D point at landheight within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Return a @{Core.Point#POINT_VEC2} object representing a random 2D point at landheight within the zone.
-- @param #ZONE_POLYGON_BASE self
-- @return @{Core.Point#POINT_VEC2}
function ZONE_POLYGON_BASE:GetRandomPointVec2()
@@ -2847,7 +2842,7 @@ function ZONE_POLYGON_BASE:GetRandomPointVec2()
return PointVec2
end
--- Return a @{Core.Point#POINT_VEC3} object representing a random 3D point at landheight within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec3 table.
--- Return a @{Core.Point#POINT_VEC3} object representing a random 3D point at landheight within the zone.
-- @param #ZONE_POLYGON_BASE self
-- @return @{Core.Point#POINT_VEC3}
function ZONE_POLYGON_BASE:GetRandomPointVec3()
@@ -3076,25 +3071,9 @@ function ZONE_POLYGON:NewFromDrawing(DrawingName)
-- points for the drawings are saved in local space, so add the object's map x and y coordinates to get
-- world space points we can use
for _, point in UTILS.spairs(object["points"]) do
-- check if we want to skip adding a point
local skip = false
local p = {x = object["mapX"] + point["x"],
y = object["mapY"] + point["y"] }
-- Check if the same coordinates already exist in the list, skip if they do
-- This can happen when drawing a Polygon in Free mode, DCS adds points on
-- top of each other that are in the `mission` file, but not visible in the
-- Mission Editor
for _, pt in pairs(points) do
if pt.x == p.x and pt.y == p.y then
skip = true
end
end
-- if it's a unique point, add it
if not skip then
table.add(points, p)
end
table.add(points, p)
end
elseif object["polygonMode"] == "rect" then
-- the points for a rect are saved as local coordinates with an angle. To get the world space points from this
@@ -3112,7 +3091,6 @@ function ZONE_POLYGON:NewFromDrawing(DrawingName)
points = {p1, p2, p3, p4}
else
-- bring the Arrow code over from Shape/Polygon
-- something else that might be added in the future
end
end
@@ -3641,7 +3619,7 @@ do -- ZONE_ELASTIC
end
--- Create a convex hull.
--- Create a convec hull.
-- @param #ZONE_ELASTIC self
-- @param #table pl Points
-- @return #table Points
@@ -3852,18 +3830,18 @@ function ZONE_OVAL:GetRandomVec2()
return {x=rx, y=ry}
end
--- Define a random @{Core.Point#POINT_VEC2} within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
-- @param #ZONE_OVAL self
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
function ZONE_OVAL:GetRandomPointVec2()
return POINT_VEC2:NewFromVec2(self:GetRandomVec2())
end
--- Define a random @{Core.Point#POINT_VEC2} within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec3 table.
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
-- @param #ZONE_OVAL self
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
function ZONE_OVAL:GetRandomPointVec3()
return POINT_VEC3:NewFromVec3(self:GetRandomVec2())
return POINT_VEC2:NewFromVec3(self:GetRandomVec2())
end
--- Draw the zone on the F10 map.
@@ -4003,7 +3981,7 @@ do -- ZONE_AIRBASE
return ZoneVec2
end
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone. Note that this is actually a @{Core.Point#COORDINATE} type object, and not a simple Vec2 table.
--- Returns a @{Core.Point#POINT_VEC2} object reflecting a random 2D location within the zone.
-- @param #ZONE_AIRBASE self
-- @param #number inner (optional) Minimal distance from the center of the zone. Default is 0.
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.

View File

@@ -14,7 +14,6 @@ do -- world
-- @field #world.event event [https://wiki.hoggitworld.com/view/DCS_enum_world](https://wiki.hoggitworld.com/view/DCS_enum_world)
-- @field #world.BirthPlace BirthPlace The birthplace enumerator is used to define where an aircraft or helicopter has spawned in association with birth events.
-- @field #world.VolumeType VolumeType The volumeType enumerator defines the types of 3d geometery used within the [world.searchObjects](https://wiki.hoggitworld.com/view/DCS_func_searchObjects) function.
-- @field #world.weather weather Weather functions for fog etc.
--- The world singleton contains functions centered around two different but extremely useful functions.
-- * Events and event handlers are all governed within world.
@@ -26,68 +25,38 @@ do -- world
--- [https://wiki.hoggitworld.com/view/DCS_enum_world](https://wiki.hoggitworld.com/view/DCS_enum_world)
-- @type world.event
-- @field S_EVENT_INVALID = 0
-- @field S_EVENT_SHOT = 1
-- @field S_EVENT_HIT = 2
-- @field S_EVENT_TAKEOFF = 3
-- @field S_EVENT_LAND = 4
-- @field S_EVENT_CRASH = 5
-- @field S_EVENT_EJECTION = 6
-- @field S_EVENT_REFUELING = 7
-- @field S_EVENT_DEAD = 8
-- @field S_EVENT_PILOT_DEAD = 9
-- @field S_EVENT_BASE_CAPTURED = 10
-- @field S_EVENT_MISSION_START = 11
-- @field S_EVENT_MISSION_END = 12
-- @field S_EVENT_TOOK_CONTROL = 13
-- @field S_EVENT_REFUELING_STOP = 14
-- @field S_EVENT_BIRTH = 15
-- @field S_EVENT_HUMAN_FAILURE = 16
-- @field S_EVENT_DETAILED_FAILURE = 17
-- @field S_EVENT_ENGINE_STARTUP = 18
-- @field S_EVENT_ENGINE_SHUTDOWN = 19
-- @field S_EVENT_PLAYER_ENTER_UNIT = 20
-- @field S_EVENT_PLAYER_LEAVE_UNIT = 21
-- @field S_EVENT_PLAYER_COMMENT = 22
-- @field S_EVENT_SHOOTING_START = 23
-- @field S_EVENT_SHOOTING_END = 24
-- @field S_EVENT_MARK_ADDED = 25
-- @field S_EVENT_MARK_CHANGE = 26
-- @field S_EVENT_MARK_REMOVED = 27
-- @field S_EVENT_KILL = 28
-- @field S_EVENT_SCORE = 29
-- @field S_EVENT_UNIT_LOST = 30
-- @field S_EVENT_LANDING_AFTER_EJECTION = 31
-- @field S_EVENT_PARATROOPER_LENDING = 32 -- who's lending whom what? ;)
-- @field S_EVENT_DISCARD_CHAIR_AFTER_EJECTION = 33
-- @field S_EVENT_WEAPON_ADD = 34
-- @field S_EVENT_TRIGGER_ZONE = 35
-- @field S_EVENT_LANDING_QUALITY_MARK = 36
-- @field S_EVENT_BDA = 37 -- battle damage assessment
-- @field S_EVENT_AI_ABORT_MISSION = 38
-- @field S_EVENT_DAYNIGHT = 39
-- @field S_EVENT_FLIGHT_TIME = 40
-- @field S_EVENT_PLAYER_SELF_KILL_PILOT = 41
-- @field S_EVENT_PLAYER_CAPTURE_AIRFIELD = 42
-- @field S_EVENT_EMERGENCY_LANDING = 43
-- @field S_EVENT_UNIT_CREATE_TASK = 44
-- @field S_EVENT_UNIT_DELETE_TASK = 45
-- @field S_EVENT_SIMULATION_START = 46
-- @field S_EVENT_WEAPON_REARM = 47
-- @field S_EVENT_WEAPON_DROP = 48
-- @field S_EVENT_UNIT_TASK_COMPLETE = 49
-- @field S_EVENT_UNIT_TASK_STAGE = 50
-- @field S_EVENT_MAC_EXTRA_SCORE= 51 -- not sure what this is
-- @field S_EVENT_MISSION_RESTART= 52
-- @field S_EVENT_MISSION_WINNER = 53
-- @field S_EVENT_RUNWAY_TAKEOFF= 54
-- @field S_EVENT_RUNWAY_TOUCH= 55
-- @field S_EVENT_MAC_LMS_RESTART= 56 -- not sure what this is
-- @field S_EVENT_SIMULATION_FREEZE = 57
-- @field S_EVENT_SIMULATION_UNFREEZE = 58
-- @field S_EVENT_HUMAN_AIRCRAFT_REPAIR_START = 59
-- @field S_EVENT_HUMAN_AIRCRAFT_REPAIR_FINISH = 60
-- @field S_EVENT_MAX = 61
-- @field S_EVENT_INVALID
-- @field S_EVENT_SHOT [https://wiki.hoggitworld.com/view/DCS_event_shot](https://wiki.hoggitworld.com/view/DCS_event_shot)
-- @field S_EVENT_HIT [https://wiki.hoggitworld.com/view/DCS_event_hit](https://wiki.hoggitworld.com/view/DCS_event_hit)
-- @field S_EVENT_TAKEOFF [https://wiki.hoggitworld.com/view/DCS_event_takeoff](https://wiki.hoggitworld.com/view/DCS_event_takeoff)
-- @field S_EVENT_LAND [https://wiki.hoggitworld.com/view/DCS_event_land](https://wiki.hoggitworld.com/view/DCS_event_land)
-- @field S_EVENT_CRASH [https://wiki.hoggitworld.com/view/DCS_event_crash](https://wiki.hoggitworld.com/view/DCS_event_crash)
-- @field S_EVENT_EJECTION [https://wiki.hoggitworld.com/view/DCS_event_ejection](https://wiki.hoggitworld.com/view/DCS_event_ejection)
-- @field S_EVENT_REFUELING [https://wiki.hoggitworld.com/view/DCS_event_refueling](https://wiki.hoggitworld.com/view/DCS_event_refueling)
-- @field S_EVENT_DEAD [https://wiki.hoggitworld.com/view/DCS_event_dead](https://wiki.hoggitworld.com/view/DCS_event_dead)
-- @field S_EVENT_PILOT_DEAD [https://wiki.hoggitworld.com/view/DCS_event_pilot_dead](https://wiki.hoggitworld.com/view/DCS_event_pilot_dead)
-- @field S_EVENT_BASE_CAPTURED [https://wiki.hoggitworld.com/view/DCS_event_base_captured](https://wiki.hoggitworld.com/view/DCS_event_base_captured)
-- @field S_EVENT_MISSION_START [https://wiki.hoggitworld.com/view/DCS_event_mission_start](https://wiki.hoggitworld.com/view/DCS_event_mission_start)
-- @field S_EVENT_MISSION_END [https://wiki.hoggitworld.com/view/DCS_event_mission_end](https://wiki.hoggitworld.com/view/DCS_event_mission_end)
-- @field S_EVENT_TOOK_CONTROL
-- @field S_EVENT_REFUELING_STOP [https://wiki.hoggitworld.com/view/DCS_event_refueling_stop](https://wiki.hoggitworld.com/view/DCS_event_refueling_stop)
-- @field S_EVENT_BIRTH [https://wiki.hoggitworld.com/view/DCS_event_birth](https://wiki.hoggitworld.com/view/DCS_event_birth)
-- @field S_EVENT_HUMAN_FAILURE [https://wiki.hoggitworld.com/view/DCS_event_human_failure](https://wiki.hoggitworld.com/view/DCS_event_human_failure)
-- @field S_EVENT_ENGINE_STARTUP [https://wiki.hoggitworld.com/view/DCS_event_engine_startup](https://wiki.hoggitworld.com/view/DCS_event_engine_startup)
-- @field S_EVENT_ENGINE_SHUTDOWN [https://wiki.hoggitworld.com/view/DCS_event_engine_shutdown](https://wiki.hoggitworld.com/view/DCS_event_engine_shutdown)
-- @field S_EVENT_PLAYER_ENTER_UNIT [https://wiki.hoggitworld.com/view/DCS_event_player_enter_unit](https://wiki.hoggitworld.com/view/DCS_event_player_enter_unit)
-- @field S_EVENT_PLAYER_LEAVE_UNIT [https://wiki.hoggitworld.com/view/DCS_event_player_leave_unit](https://wiki.hoggitworld.com/view/DCS_event_player_leave_unit)
-- @field S_EVENT_PLAYER_COMMENT
-- @field S_EVENT_SHOOTING_START [https://wiki.hoggitworld.com/view/DCS_event_shooting_start](https://wiki.hoggitworld.com/view/DCS_event_shooting_start)
-- @field S_EVENT_SHOOTING_END [https://wiki.hoggitworld.com/view/DCS_event_shooting_end](https://wiki.hoggitworld.com/view/DCS_event_shooting_end)
-- @field S_EVENT_MARK ADDED [https://wiki.hoggitworld.com/view/DCS_event_mark_added](https://wiki.hoggitworld.com/view/DCS_event_mark_added) DCS>=2.5.1
-- @field S_EVENT_MARK CHANGE [https://wiki.hoggitworld.com/view/DCS_event_mark_change](https://wiki.hoggitworld.com/view/DCS_event_mark_change) DCS>=2.5.1
-- @field S_EVENT_MARK REMOVE [https://wiki.hoggitworld.com/view/DCS_event_mark_remove](https://wiki.hoggitworld.com/view/DCS_event_mark_remove) DCS>=2.5.1
-- @field S_EVENT_KILL [https://wiki.hoggitworld.com/view/DCS_event_kill](https://wiki.hoggitworld.com/view/DCS_event_kill) DCS>=2.5.6
-- @field S_EVENT_SCORE [https://wiki.hoggitworld.com/view/DCS_event_score](https://wiki.hoggitworld.com/view/DCS_event_score) DCS>=2.5.6
-- @field S_EVENT_UNIT_LOST [https://wiki.hoggitworld.com/view/DCS_event_unit_lost](https://wiki.hoggitworld.com/view/DCS_event_unit_lost) DCS>=2.5.6
-- @field S_EVENT_LANDING_AFTER_EJECTION [https://wiki.hoggitworld.com/view/DCS_event_landing_after_ejection](https://wiki.hoggitworld.com/view/DCS_event_landing_after_ejection) DCS>=2.5.6
-- @field S_EVENT_MAX
--- The birthplace enumerator is used to define where an aircraft or helicopter has spawned in association with birth events.
-- @type world.BirthPlace
@@ -133,36 +102,6 @@ do -- world
-- @function [parent=#world] getAirbases
-- @param #number coalitionId The coalition side number ID. Default is all airbases are returned.
-- @return #table Table of DCS airbase objects.
--- Weather functions.
-- @type world.weather
--- Fog animation data structure.
-- @type world.FogAnimation
-- @field #number time
-- @field #number visibility
-- @field #number thickness
--- Returns the current fog thickness.
-- @function [parent=#world.weather] getFogThickness Returns the fog thickness.
-- @return #number Fog thickness in meters. If there is no fog, zero is returned.
--- Sets the fog thickness instantly. Any current fog animation is discarded.
-- @function [parent=#world.weather] setFogThickness
-- @param #number thickness Fog thickness in meters. Set to zero to disable fog.
--- Returns the current fog visibility distance.
-- @function [parent=#world.weather] getFogVisibilityDistance Returns the current maximum visibility distance in meters. Returns zero if fog is not present.
--- Instantly sets the maximum visibility distance of fog at sea level when looking at the horizon. Any current fog animation is discarded. Set zero to disable the fog.
-- @function [parent=#world.weather] setFogVisibilityDistance
-- @param #number visibility Max fog visibility in meters. Set to zero to disable fog.
--- Sets fog animation keys. Time is set in seconds and relative to the current simulation time, where time=0 is the current moment.
-- Time must be increasing. Previous animation is always discarded despite the data being correct.
-- @function [parent=#world.weather] setFogAnimation
-- @param #world.FogAnimation animation List of fog animations
end -- world
@@ -438,7 +377,7 @@ do -- coalition
-- @param #table groupData Group data table.
-- @return DCS#Group The spawned Group object.
--- Dynamically spawns a static object. See [hoggit](https://wiki.hoggitworld.com/view/DCS_func_addStaticObject)
--- Dynamically spawns a static object. See [hoggit](https://wiki.hoggitworld.com/view/DCS_func_addGroup)
-- @function [parent=#coalition] addStaticObject
-- @param #number countryId Id of the country.
-- @param #table groupData Group data table.
@@ -451,7 +390,6 @@ end -- coalition
do -- Types
--- Descriptors.
-- @type Desc
-- @field #number speedMax0 Max speed in meters/second at zero altitude.
-- @field #number massEmpty Empty mass in kg.
@@ -1045,16 +983,14 @@ do -- Spot
end -- Spot
do -- Controller
--- Controller is an object that performs A.I.-tasks. Other words controller is an instance of A.I.. Controller stores current main task, active enroute tasks and behavior options. Controller performs commands. Please, read DCS A-10C GUI Manual EN.pdf chapter "Task Planning for Unit Groups", page 91 to understand A.I. system of DCS:A-10C.
--
-- This class has 2 types of functions:
--
-- * Tasks
-- * Commands: Commands are instant actions those required zero time to perform. Commands may be used both for control unit/group behavior and control game mechanics.
--
-- * Commands: Commands are instant actions those required zero time to perform. Commands may be used both for control unit/group behavior and control game mechanics.
-- @type Controller
-- @field #Controller.Detection Detection Enum contains identifiers of surface types.
-- @field #Controller.Detection Detection Enum contains identifiers of surface types.
--- Enables and disables the controller.
-- Note: Now it works only for ground / naval groups!
@@ -1113,18 +1049,18 @@ do -- Controller
-- Detection
--- Enum containing detection types.
--- Enum contains identifiers of surface types.
-- @type Controller.Detection
-- @field #number VISUAL Visual detection. Numeric value 1.
-- @field #number OPTIC Optical detection. Numeric value 2.
-- @field #number RADAR Radar detection. Numeric value 4.
-- @field #number IRST Infra-red search and track detection. Numeric value 8.
-- @field #number RWR Radar Warning Receiver detection. Numeric value 16.
-- @field #number DLINK Data link detection. Numeric value 32.
-- @field VISUAL
-- @field OPTIC
-- @field RADAR
-- @field IRST
-- @field RWR
-- @field DLINK
--- Detected target.
-- @type Controller.DetectedTarget
-- @field DCS#Object object The target
-- @type DetectedTarget
-- @field Wrapper.Object#Object object The target
-- @field #boolean visible The target is visible
-- @field #boolean type The target type is known
-- @field #boolean distance Distance to the target is known
@@ -1137,9 +1073,9 @@ do -- Controller
-- @param #Controller.Detection detection Controller.Detection detection1, Controller.Detection detection2, ... Controller.Detection detectionN
-- @return #boolean detected True if the target is detected.
-- @return #boolean visible Has effect only if detected is true. True if the target is visible now.
-- @return #boolean type Has effect only if detected is true. True if the target type is known.
-- @return #boolean distance Has effect only if detected is true. True if the distance to the target is known.
-- @return #ModelTime lastTime Has effect only if visible is false. Last time when target was seen.
-- @return #boolean type Has effect only if detected is true. True if the target type is known.
-- @return #boolean distance Has effect only if detected is true. True if the distance to the target is known.
-- @return #Vec3 lastPos Has effect only if visible is false. Last position of the target when it was seen.
-- @return #Vec3 lastVel Has effect only if visible is false. Last velocity of the target when it was seen.
@@ -1165,7 +1101,6 @@ end -- Controller
do -- Unit
--- Unit.
-- @type Unit
-- @extends #CoalitionObject
-- @field ID Identifier of an unit. It assigned to an unit by the Mission Editor automatically.
@@ -1730,7 +1665,6 @@ do -- AI
-- @field ALARM_STATE @{#AI.Option.Ground.val.ALARM_STATE}
-- @field ENGAGE_AIR_WEAPONS
-- @field AC_ENGAGEMENT_RANGE_RESTRICTION
-- @field EVASION_OF_ARM
---
-- @type AI.Option.Ground.mid -- Moose added

View File

@@ -18,7 +18,7 @@
-- ### Author: FlightControl - Framework Design & Programming
-- ### Refactoring to use the Runway auto-detection: Applevangelist
-- @date August 2022
-- Last Update Oct 2024
-- Last Update Nov 2023
--
-- ===
--
@@ -721,18 +721,14 @@ function ATC_GROUND_UNIVERSAL:_AirbaseMonitor()
if NotInRunwayZone then
local Taxi = Client:GetState( self, "Taxi" )
if IsOnGround then
local Taxi = Client:GetState( self, "Taxi" )
self:T( Taxi )
if Taxi == false then
local Velocity = VELOCITY:New( AirbaseMeta.KickSpeed or self.KickSpeed )
Client:Message( "Welcome to " .. AirbaseID .. ". The maximum taxiing speed is " ..
Velocity:ToString() , 20, "ATC" )
Client:SetState( self, "Taxi", true )
Client:SetState( self, "Speeding", false )
Client:SetState( self, "Warnings", 0 )
end
-- TODO: GetVelocityKMH function usage
@@ -741,7 +737,7 @@ function ATC_GROUND_UNIVERSAL:_AirbaseMonitor()
local IsAboveRunway = Client:IsAboveRunway()
self:T( {IsAboveRunway, IsOnGround, Velocity:Get() })
if IsOnGround and not Taxi then
if IsOnGround then
local Speeding = false
if AirbaseMeta.MaximumKickSpeed then
if Velocity:Get() > AirbaseMeta.MaximumKickSpeed then
@@ -753,17 +749,15 @@ function ATC_GROUND_UNIVERSAL:_AirbaseMonitor()
end
end
if Speeding == true then
--MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() ..
-- " has been kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
--Client:Destroy()
Client:SetState( self, "Speeding", true )
local SpeedingWarnings = Client:GetState( self, "Warnings" )
Client:SetState( self, "Warnings", SpeedingWarnings + 1 )
Client:Message( "Warning " .. SpeedingWarnings .. "/3! Airbase traffic rule violation! Slow down now! Your speed is " ..
Velocity:ToString(), 5, "ATC" )
MESSAGE:New( "Penalty! Player " .. Client:GetPlayerName() ..
" has been kicked, due to a severe airbase traffic rule violation ...", 10, "ATC" ):ToAll()
Client:Destroy()
Client:SetState( self, "Speeding", false )
Client:SetState( self, "Warnings", 0 )
end
end
if IsOnGround then
local Speeding = false
@@ -1041,23 +1035,23 @@ end
-- The following airbases are monitored at the Nevada region.
-- Use the @{Wrapper.Airbase#AIRBASE.Nevada} enumeration to select the airbases to be monitored.
--
-- * `AIRBASE.Nevada.Beatty`
-- * `AIRBASE.Nevada.Boulder_City`
-- * `AIRBASE.Nevada.Creech`
-- * `AIRBASE.Nevada.Beatty_Airport`
-- * `AIRBASE.Nevada.Boulder_City_Airport`
-- * `AIRBASE.Nevada.Creech_AFB`
-- * `AIRBASE.Nevada.Echo_Bay`
-- * `AIRBASE.Nevada.Groom_Lake`
-- * `AIRBASE.Nevada.Henderson_Executive`
-- * `AIRBASE.Nevada.Jean`
-- * `AIRBASE.Nevada.Laughlin`
-- * `AIRBASE.Nevada.Groom_Lake_AFB`
-- * `AIRBASE.Nevada.Henderson_Executive_Airport`
-- * `AIRBASE.Nevada.Jean_Airport`
-- * `AIRBASE.Nevada.Laughlin_Airport`
-- * `AIRBASE.Nevada.Lincoln_County`
-- * `AIRBASE.Nevada.McCarran_International`
-- * `AIRBASE.Nevada.McCarran_International_Airport`
-- * `AIRBASE.Nevada.Mesquite`
-- * `AIRBASE.Nevada.Mina`
-- * `AIRBASE.Nevada.Nellis`
-- * `AIRBASE.Nevada.Mina_Airport`
-- * `AIRBASE.Nevada.Nellis_AFB`
-- * `AIRBASE.Nevada.North_Las_Vegas`
-- * `AIRBASE.Nevada.Pahute_Mesa`
-- * `AIRBASE.Nevada.Tonopah`
-- * `AIRBASE.Nevada.Tonopah_Test_Range`
-- * `AIRBASE.Nevada.Pahute_Mesa_Airstrip`
-- * `AIRBASE.Nevada.Tonopah_Airport`
-- * `AIRBASE.Nevada.Tonopah_Test_Range_Airfield`
--
-- # Installation
--
@@ -1094,10 +1088,10 @@ end
--
-- -- Monitor specific airbases.
-- ATC_Ground = ATC_GROUND_NEVADA:New(
-- { AIRBASE.Nevada.Laughlin,
-- { AIRBASE.Nevada.Laughlin_Airport,
-- AIRBASE.Nevada.Lincoln_County,
-- AIRBASE.Nevada.North_Las_Vegas,
-- AIRBASE.Nevada.McCarran_International
-- AIRBASE.Nevada.McCarran_International_Airport
-- }
-- )
--
@@ -1336,33 +1330,33 @@ end
-- The following airbases are monitored at the PersianGulf region.
-- Use the @{Wrapper.Airbase#AIRBASE.PersianGulf} enumeration to select the airbases to be monitored.
--
-- * `AIRBASE.PersianGulf.Abu_Musa_Island`
-- * `AIRBASE.PersianGulf.Al_Dhafra_AFB`
-- * `AIRBASE.PersianGulf.Abu_Musa_Island_Airport`
-- * `AIRBASE.PersianGulf.Al_Dhafra_AB`
-- * `AIRBASE.PersianGulf.Al_Maktoum_Intl`
-- * `AIRBASE.PersianGulf.Al_Minhad_AFB`
-- * `AIRBASE.PersianGulf.Al_Minhad_AB`
-- * `AIRBASE.PersianGulf.Bandar_Abbas_Intl`
-- * `AIRBASE.PersianGulf.Bandar_Lengeh`
-- * `AIRBASE.PersianGulf.Dubai_Intl`
-- * `AIRBASE.PersianGulf.Fujairah_Intl`
-- * `AIRBASE.PersianGulf.Havadarya`
-- * `AIRBASE.PersianGulf.Kerman`
-- * `AIRBASE.PersianGulf.Kerman_Airport`
-- * `AIRBASE.PersianGulf.Khasab`
-- * `AIRBASE.PersianGulf.Lar`
-- * `AIRBASE.PersianGulf.Lar_Airbase`
-- * `AIRBASE.PersianGulf.Qeshm_Island`
-- * `AIRBASE.PersianGulf.Sharjah_Intl`
-- * `AIRBASE.PersianGulf.Shiraz_Intl`
-- * `AIRBASE.PersianGulf.Shiraz_International_Airport`
-- * `AIRBASE.PersianGulf.Sir_Abu_Nuayr`
-- * `AIRBASE.PersianGulf.Sirri_Island`
-- * `AIRBASE.PersianGulf.Tunb_Island_AFB`
-- * `AIRBASE.PersianGulf.Tunb_Kochak`
-- * `AIRBASE.PersianGulf.Sas_Al_Nakheel`
-- * `AIRBASE.PersianGulf.Bandar_e_Jask`
-- * `AIRBASE.PersianGulf.Abu_Dhabi_Intl`
-- * `AIRBASE.PersianGulf.Al_Bateen`
-- * `AIRBASE.PersianGulf.Kish_Intl`
-- * `AIRBASE.PersianGulf.Al_Ain_Intl`
-- * `AIRBASE.PersianGulf.Lavan_Island`
-- * `AIRBASE.PersianGulf.Jiroft`
-- * `AIRBASE.PersianGulf.Sas_Al_Nakheel_Airport`
-- * `AIRBASE.PersianGulf.Bandar_e_Jask_airfield`
-- * `AIRBASE.PersianGulf.Abu_Dhabi_International_Airport`
-- * `AIRBASE.PersianGulf.Al_Bateen_Airport`
-- * `AIRBASE.PersianGulf.Kish_International_Airport`
-- * `AIRBASE.PersianGulf.Al_Ain_International_Airport`
-- * `AIRBASE.PersianGulf.Lavan_Island_Airport`
-- * `AIRBASE.PersianGulf.Jiroft_Airport`
--
-- # Installation
--
@@ -1397,8 +1391,8 @@ end
-- AirbasePoliceCaucasus = ATC_GROUND_PERSIANGULF:New()
--
-- ATC_Ground = ATC_GROUND_PERSIANGULF:New(
-- { AIRBASE.PersianGulf.Kerman,
-- AIRBASE.PersianGulf.Al_Minhad_AFB
-- { AIRBASE.PersianGulf.Kerman_Airport,
-- AIRBASE.PersianGulf.Al_Minhad_AB
-- }
-- )
--

View File

@@ -45,7 +45,6 @@
-- @field #table currentMove Holds the current commanded move, if there is one assigned.
-- @field #number Nammo0 Initial amount total ammunition (shells+rockets+missiles) of the whole group.
-- @field #number Nshells0 Initial amount of shells of the whole group.
-- @field #number Narty0 Initial amount of artillery shells of the whole group.
-- @field #number Nrockets0 Initial amount of rockets of the whole group.
-- @field #number Nmissiles0 Initial amount of missiles of the whole group.
-- @field #number Nukes0 Initial amount of tactical nukes of the whole group. Default is 0.
@@ -416,7 +415,7 @@
-- arty set, battery "Paladin Alpha", rearming place
--
-- Setting the rearming group is independent of the position of the mark. Just create one anywhere on the map and type
-- arty set, battery "Mortar Bravo", rearming group "Ammo Truck M939"
-- arty set, battery "Mortar Bravo", rearming group "Ammo Truck M818"
-- Note that the name of the rearming group has to be given in quotation marks and spelt exactly as the group name defined in the mission editor.
--
-- ## Transporting
@@ -454,7 +453,7 @@
-- -- Creat a new ARTY object from a Paladin group.
-- paladin=ARTY:New(GROUP:FindByName("Blue Paladin"))
--
-- -- Define a rearming group. This is a Transport M939 truck.
-- -- Define a rearming group. This is a Transport M818 truck.
-- paladin:SetRearmingGroup(GROUP:FindByName("Blue Ammo Truck"))
--
-- -- Set the max firing range. A Paladin unit has a range of 20 km.
@@ -695,7 +694,7 @@ ARTY.db={
--- Arty script version.
-- @field #string version
ARTY.version="1.3.1"
ARTY.version="1.3.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -708,7 +707,7 @@ ARTY.version="1.3.1"
-- DONE: Add user defined rearm weapon types.
-- DONE: Check if target is in range. Maybe this requires a data base with the ranges of all arty units. <solved by user function>
-- DONE: Make ARTY move to rearming position.
-- DONE: Check that right rearming vehicle is specified. Blue M939, Red Ural-375. Are there more? <user needs to know!>
-- DONE: Check that right rearming vehicle is specified. Blue M818, Red Ural-375. Are there more? <user needs to know!>
-- DONE: Check if ARTY group is still alive.
-- DONE: Handle dead events.
-- DONE: Abort firing task if no shooting event occured with 5(?) minutes. Something went wrong then. Min/max range for example.
@@ -1533,7 +1532,7 @@ end
--- Assign a group, which is responsible for rearming the ARTY group. If the group is too far away from the ARTY group it will be guided towards the ARTY group.
-- @param #ARTY self
-- @param Wrapper.Group#GROUP group Group that is supposed to rearm the ARTY group. For the blue coalition, this is often a unarmed M939 transport whilst for red an unarmed Ural-375 transport can be used.
-- @param Wrapper.Group#GROUP group Group that is supposed to rearm the ARTY group. For the blue coalition, this is often a unarmed M818 transport whilst for red an unarmed Ural-375 transport can be used.
-- @return self
function ARTY:SetRearmingGroup(group)
self:F({group=group})
@@ -1888,7 +1887,7 @@ function ARTY:onafterStart(Controllable, From, Event, To)
MESSAGE:New(text, 5):ToAllIf(self.Debug)
-- Get Ammo.
self.Nammo0, self.Nshells0, self.Nrockets0, self.Nmissiles0, self.Narty0=self:GetAmmo(self.Debug)
self.Nammo0, self.Nshells0, self.Nrockets0, self.Nmissiles0=self:GetAmmo(self.Debug)
-- Init nuclear explosion parameters if they were not set by user.
if self.nukerange==nil then
@@ -2094,7 +2093,7 @@ function ARTY:_StatusReport(display)
end
-- Get Ammo.
local Nammo, Nshells, Nrockets, Nmissiles, Narty=self:GetAmmo()
local Nammo, Nshells, Nrockets, Nmissiles=self:GetAmmo()
local Nnukes=self.Nukes
local Nillu=self.Nillu
local Nsmoke=self.Nsmoke
@@ -2107,7 +2106,7 @@ function ARTY:_StatusReport(display)
text=text..string.format("Clock = %s\n", Clock)
text=text..string.format("FSM state = %s\n", self:GetState())
text=text..string.format("Total ammo count = %d\n", Nammo)
text=text..string.format("Number of shells = %d\n", Narty)
text=text..string.format("Number of shells = %d\n", Nshells)
text=text..string.format("Number of rockets = %d\n", Nrockets)
text=text..string.format("Number of missiles = %d\n", Nmissiles)
text=text..string.format("Number of nukes = %d\n", Nnukes)
@@ -2294,7 +2293,7 @@ function ARTY:OnEventShot(EventData)
end
-- Get current ammo.
local _nammo,_nshells,_nrockets,_nmissiles,_narty=self:GetAmmo()
local _nammo,_nshells,_nrockets,_nmissiles=self:GetAmmo()
-- Decrease available nukes because we just fired one.
if self.currentTarget.weapontype==ARTY.WeaponType.TacticalNukes then
@@ -2324,7 +2323,7 @@ function ARTY:OnEventShot(EventData)
-- Weapon type name for current target.
local _weapontype=self:_WeaponTypeName(self.currentTarget.weapontype)
self:T(self.lid..string.format("Group %s ammo: total=%d, shells=%d, rockets=%d, missiles=%d", self.groupname, _nammo, _narty, _nrockets, _nmissiles))
self:T(self.lid..string.format("Group %s ammo: total=%d, shells=%d, rockets=%d, missiles=%d", self.groupname, _nammo, _nshells, _nrockets, _nmissiles))
self:T(self.lid..string.format("Group %s uses weapontype %s for current target.", self.groupname, _weapontype))
-- Default switches for cease fire and relocation.
@@ -2772,7 +2771,7 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
self:_EventFromTo("onafterStatus", Event, From, To)
-- Get ammo.
local nammo, nshells, nrockets, nmissiles, narty=self:GetAmmo()
local nammo, nshells, nrockets, nmissiles=self:GetAmmo()
-- We have a cargo group ==> check if group was loaded into a carrier.
if self.iscargo and self.cargogroup then
@@ -2789,7 +2788,7 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- FSM state.
local fsmstate=self:GetState()
self:T(self.lid..string.format("Status %s, Ammo total=%d: shells=%d [smoke=%d, illu=%d, nukes=%d*%.3f kT], rockets=%d, missiles=%d", fsmstate, nammo, narty, self.Nsmoke, self.Nillu, self.Nukes, self.nukewarhead/1000000, nrockets, nmissiles))
self:T(self.lid..string.format("Status %s, Ammo total=%d: shells=%d [smoke=%d, illu=%d, nukes=%d*%.3f kT], rockets=%d, missiles=%d", fsmstate, nammo, nshells, self.Nsmoke, self.Nillu, self.Nukes, self.nukewarhead/1000000, nrockets, nmissiles))
if self.Controllable and self.Controllable:IsAlive() then
@@ -2872,19 +2871,20 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
if self.currentTarget then
self:CeaseFire(self.currentTarget)
end
if self:is("CombatReady") then
-- Open fire on timed target.
self:OpenFire(_timedTarget)
end
-- Open fire on timed target.
self:OpenFire(_timedTarget)
elseif _normalTarget then
if self:is("CombatReady") then
-- Open fire on normal target.
self:OpenFire(_normalTarget)
end
-- Open fire on normal target.
self:OpenFire(_normalTarget)
end
-- Get ammo.
--local nammo, nshells, nrockets, nmissiles=self:GetAmmo()
-- Check if we have a target in the queue for which weapons are still available.
local gotsome=false
if #self.targets>0 then
@@ -3045,14 +3045,14 @@ function ARTY:onafterOpenFire(Controllable, From, Event, To, target)
local range=Controllable:GetCoordinate():Get2DDistance(target.coord)
-- Get ammo.
local Nammo, Nshells, Nrockets, Nmissiles, Narty=self:GetAmmo()
local nfire=Narty
local Nammo, Nshells, Nrockets, Nmissiles=self:GetAmmo()
local nfire=Nammo
local _type="shots"
if target.weapontype==ARTY.WeaponType.Auto then
nfire=Narty
nfire=Nammo
_type="shots"
elseif target.weapontype==ARTY.WeaponType.Cannon then
nfire=Narty
nfire=Nshells
_type="shells"
elseif target.weapontype==ARTY.WeaponType.TacticalNukes then
nfire=self.Nukes
@@ -3337,7 +3337,7 @@ function ARTY:_CheckRearmed()
self:F2()
-- Get current ammo.
local nammo,nshells,nrockets,nmissiles,narty=self:GetAmmo()
local nammo,nshells,nrockets,nmissiles=self:GetAmmo()
-- Number of units still alive.
local units=self.Controllable:GetUnits()
@@ -3603,11 +3603,7 @@ function ARTY:_FireAtCoord(coord, radius, nshells, weapontype)
if weapontype==ARTY.WeaponType.TacticalNukes or weapontype==ARTY.WeaponType.IlluminationShells or weapontype==ARTY.WeaponType.SmokeShells then
weapontype=ARTY.WeaponType.Cannon
end
if group:HasTask() then
group:ClearTasks()
end
-- Set ROE to weapon free.
group:OptionROEOpenFire()
@@ -3618,7 +3614,7 @@ function ARTY:_FireAtCoord(coord, radius, nshells, weapontype)
local fire=group:TaskFireAtPoint(vec2, radius, nshells, weapontype)
-- Execute task.
group:SetTask(fire,1)
group:SetTask(fire)
end
--- Set task for attacking a group.
@@ -3635,11 +3631,7 @@ function ARTY:_AttackGroup(target)
if weapontype==ARTY.WeaponType.TacticalNukes or weapontype==ARTY.WeaponType.IlluminationShells or weapontype==ARTY.WeaponType.SmokeShells then
weapontype=ARTY.WeaponType.Cannon
end
if group:HasTask() then
group:ClearTasks()
end
-- Set ROE to weapon free.
group:OptionROEOpenFire()
@@ -3650,7 +3642,7 @@ function ARTY:_AttackGroup(target)
local fire=group:TaskAttackGroup(targetgroup, weapontype, AI.Task.WeaponExpend.ONE, 1)
-- Execute task.
group:SetTask(fire,1)
group:SetTask(fire)
end
@@ -3923,7 +3915,6 @@ end
-- @return #number Number of shells the group has left.
-- @return #number Number of rockets the group has left.
-- @return #number Number of missiles the group has left.
-- @return #number Number of artillery shells the group has left.
function ARTY:GetAmmo(display)
self:F3({display=display})
@@ -3937,7 +3928,6 @@ function ARTY:GetAmmo(display)
local nshells=0
local nrockets=0
local nmissiles=0
local nartyshells=0
-- Get all units.
local units=self.Controllable:GetUnits()
@@ -4040,8 +4030,7 @@ function ARTY:GetAmmo(display)
-- Add up all shells.
nshells=nshells+Nammo
local _,_,_,_,_,shells = unit:GetAmmunition()
nartyshells=nartyshells+shells
-- Debug info.
text=text..string.format("- %d shells of type %s\n", Nammo, _weaponName)
@@ -4087,7 +4076,7 @@ function ARTY:GetAmmo(display)
-- Total amount of ammunition.
nammo=nshells+nrockets+nmissiles
return nammo, nshells, nrockets, nmissiles, nartyshells
return nammo, nshells, nrockets, nmissiles
end
--- Returns a name of a missile category.
@@ -4838,10 +4827,7 @@ function ARTY:_CheckShootingStarted()
-- Check if we waited long enough and no shot was fired.
--if dt > self.WaitForShotTime and self.Nshots==0 then
self:T(string.format("dt = %d WaitTime = %d | shots = %d TargetShells = %d",dt,self.WaitForShotTime,self.Nshots,self.currentTarget.nshells))
if (dt > self.WaitForShotTime and self.Nshots==0) or (self.currentTarget.nshells <= self.Nshots) then --https://github.com/FlightControl-Master/MOOSE/issues/1356
if dt > self.WaitForShotTime and (self.Nshots==0 or self.currentTarget.nshells >= self.Nshots) then --https://github.com/FlightControl-Master/MOOSE/issues/1356
-- Debug info.
self:T(self.lid..string.format("%s, no shot event after %d seconds. Removing current target %s from list.", self.groupname, self.WaitForShotTime, name))
@@ -4903,7 +4889,7 @@ end
function ARTY:_CheckOutOfAmmo(targets)
-- Get current ammo.
local _nammo,_nshells,_nrockets,_nmissiles,_narty=self:GetAmmo()
local _nammo,_nshells,_nrockets,_nmissiles=self:GetAmmo()
-- Special weapon type requested ==> Check if corresponding ammo is empty.
local _partlyoutofammo=false
@@ -4915,7 +4901,7 @@ function ARTY:_CheckOutOfAmmo(targets)
self:T(self.lid..string.format("Group %s, auto weapon requested for target %s but all ammo is empty.", self.groupname, Target.name))
_partlyoutofammo=true
elseif Target.weapontype==ARTY.WeaponType.Cannon and _narty==0 then
elseif Target.weapontype==ARTY.WeaponType.Cannon and _nshells==0 then
self:T(self.lid..string.format("Group %s, cannons requested for target %s but shells empty.", self.groupname, Target.name))
_partlyoutofammo=true
@@ -4959,14 +4945,14 @@ end
function ARTY:_CheckWeaponTypeAvailable(target)
-- Get current ammo of group.
local Nammo, Nshells, Nrockets, Nmissiles, Narty=self:GetAmmo()
local Nammo, Nshells, Nrockets, Nmissiles=self:GetAmmo()
-- Check if enough ammo is there for the selected weapon type.
local nfire=Nammo
if target.weapontype==ARTY.WeaponType.Auto then
nfire=Nammo
elseif target.weapontype==ARTY.WeaponType.Cannon then
nfire=Narty
nfire=Nshells
elseif target.weapontype==ARTY.WeaponType.TacticalNukes then
nfire=self.Nukes
elseif target.weapontype==ARTY.WeaponType.IlluminationShells then

View File

@@ -1,687 +0,0 @@
--- **Functional** - Manage and track client slots easily to add your own client-based menus and modules to.
--
-- The @{#CLIENTWATCH} class adds a simplified way to create scripts and menus for individual clients. Instead of creating large algorithms and juggling multiple event handlers, you can simply provide one or more prefixes to the class and use the callback functions on spawn, despawn, and any aircraft related events to script to your hearts content.
--
-- ===
--
-- ## Features:
--
-- * Find clients by prefixes or by providing a Wrapper.CLIENT object
-- * Trigger functions when the client spawns and despawns
-- * Create multiple client instances without overwriting event handlers between instances
-- * More reliable aircraft lost events for when DCS thinks the aircraft id dead but a dead event fails to trigger
-- * Easily manage clients spawned in dynamic slots
--
-- ====
--
-- ### Author: **Statua**
--
-- ### Contributions: **FlightControl**: Wrapper.CLIENT
--
-- ====
-- @module Functional.ClientWatch
-- @image clientwatch.jpg
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- CLIENTWATCH class
-- @type CLIENTWATCH
-- @field #string ClassName Name of the class.
-- @field #boolean Debug Write Debug messages to DCS log file and send Debug messages to all players.
-- @field #string lid String for DCS log file.
-- @field #number FilterCoalition If not nil, will only activate for aircraft of the given coalition value.
-- @field #number FilterCategory If not nil, will only activate for aircraft of the given category value.
-- @extends Core.Fsm#FSM_CONTROLLABLE
--- Manage and track client slots easily to add your own client-based menus and modules to.
--
-- ## Creating a new instance
--
-- To start, you must first create a new instance of the client manager and provide it with either a Wrapper.Client#CLIENT object, a string prefix of the unit name, or a table of string prefixes for unit names. These are used to capture the client unit when it spawns and apply your scripted functions to it. Only fixed wing and rotary wing aircraft controlled by players can be used by this class.
-- **This will not work if the client aircraft is alive!**
--
-- ### Examples
--
-- -- Create an instance with a Wrapper.Client#CLIENT object
-- local heliClient = CLIENT:FindByName('Rotary1-1')
-- local clientInstance = CLIENTWATCH:New(heliClient)
--
-- -- Create an instance with part of the unit name in the Mission Editor
-- local clientInstance = CLIENTWATCH:New("Rotary")
--
-- -- Create an instance using prefixes for a few units as well as a FARP name for any dynamic spawns coming out of it
-- local clientInstance = CLIENTWATCH:New({"Rescue","UH-1H","FARP ALPHA"})
--
-- ## Applying functions and methods to client aircraft when they spawn
--
-- Once the instance is created, it will watch for birth events. If the unit name of the client aircraft matches the one provided in the instance, the callback method @{#CLIENTWATCH:OnAfterSpawn}() can be used to apply functions and methods to the client object.
--
-- In the OnAfterSpawn() callback method are four values. From, Event, To, and ClientObject. From,Event,To are standard FSM strings for the state changes. ClientObject is where the magic happens. This is a special object which you can use to access all the data of the client aircraft. The following entries in ClientObject are available for you to use:
--
-- * **ClientObject.Unit**: The Moose @{Wrapper.Unit#UNIT} of the client aircraft
-- * **ClientObject.Group**: The Moose @{Wrapper.Group#GRUP} of the client aircraft
-- * **ClientObject.Client**: The Moose @{Wrapper.Client#CLIENT} of the client aircraft
-- * **ClientObject.PlayerName**: A #string of the player controlling the aircraft
-- * **ClientObject.UnitName**: A #string of the client aircraft unit.
-- * **ClientObject.GroupName**: A #string of the client aircraft group.
--
-- ### Examples
--
-- -- Create an instance with a client unit prefix and send them a message when they spawn
-- local clientInstance = CLIENTWATCH:New("Rotary")
-- function clientInstance:OnAfterSpawn(From,Event,To,ClientObject,EventData)
-- MESSAGE:New("Welcome to your aircraft!",10):ToUnit(ClientObject.Unit)
-- end
--
-- ## Using event callbacks
--
-- In a normal setting, you can only use a callback function for a specific option in one location. If you have multiple scripts that rely on the same callback from the same object, this can get quite messy. With the ClientWatch module, these callbacks are isolated t the instances and therefore open the possibility to use many instances with the same callback doing different things. ClientWatch instances subscribe to all events that are applicable to player controlled aircraft and provides callbacks for each, forwarding the EventData in the callback function.
--
-- The following event callbacks can be used inside the OnAfterSpawn() callback:
--
-- * **:OnAfterDespawn(From,Event,To)**: Triggers whenever DCS no longer sees the aircraft as 'alive'. No event data is given in this callback as it is derived from other events
-- * **:OnAfterHit(From,Event,To,EventData)**: Triggers every time the aircraft takes damage or is struck by a weapon/explosion
-- * **:OnAfterKill(From,Event,To,EventData)**: Triggers after the aircraft kills something with its weapons
-- * **:OnAfterScore(From,Event,To,EventData)**: Triggers after accumulating score
-- * **:OnAfterShot(From,Event,To,EventData)**: Triggers after a single-shot weapon is released
-- * **:OnAfterShootingStart(From,Event,To,EventData)**: Triggers when an automatic weapon begins firing
-- * **:OnAfterShootingEnd(From,Event,To,EventData)**: Triggers when an automatic weapon stops firing
-- * **:OnAfterLand(From,Event,To,EventData)**: Triggers when an aircraft transitions from being airborne to on the ground
-- * **:OnAfterTakeoff(From,Event,To,EventData)**: Triggers when an aircraft transitions from being on the ground to airborne
-- * **:OnAfterRunwayTakeoff(From,Event,To,EventData)**: Triggers after lifting off from a runway
-- * **:OnAfterRunwayTouch(From,Event,To,EventData)**: Triggers when an aircraft's gear makes contact with a runway
-- * **:OnAfterRefueling(From,Event,To,EventData)**: Triggers when an aircraft begins taking on fuel
-- * **:OnAfterRefuelingStop(From,Event,To,EventData)**: Triggers when an aircraft stops taking on fuel
-- * **:OnAfterPlayerLeaveUnit(From,Event,To,EventData)**: Triggers when a player leaves an operational aircraft
-- * **:OnAfterCrash(From,Event,To,EventData)**: Triggers when an aircraft is destroyed (may fail to trigger if the aircraft is only partially destroyed)
-- * **:OnAfterDead(From,Event,To,EventData)**: Triggers when an aircraft is considered dead (may fail to trigger if the aircraft was partially destroyed first)
-- * **:OnAfterPilotDead(From,Event,To,EventData)**: Triggers when the pilot is killed (may fail to trigger if the aircraft was partially destroyed first)
-- * **:OnAfterUnitLost(From,Event,To,EventData)**: Triggers when an aircraft is lost for any reason (may fail to trigger if the aircraft was partially destroyed first)
-- * **:OnAfterEjection(From,Event,To,EventData)**: Triggers when a pilot ejects from an aircraft
-- * **:OnAfterHumanFailure(From,Event,To,EventData)**: Triggers when an aircraft or system is damaged from any source or action by the player
-- * **:OnAfterHumanAircraftRepairStart(From,Event,To,EventData)**: Triggers when an aircraft repair is started
-- * **:OnAfterHumanAircraftRepairFinish(From,Event,To,EventData)**: Triggers when an aircraft repair is completed
-- * **:OnAfterEngineStartup(From,Event,To,EventData)**: Triggers when the engine enters what DCS considers to be a started state. Parameters vary by aircraft
-- * **:OnAfterEngineShutdown(From,Event,To,EventData)**: Triggers when the engine enters what DCS considers to be a stopped state. Parameters vary by aircraft
-- * **:OnAfterWeaponAdd(From,Event,To,EventData)**: Triggers when an item is added to an aircraft's payload
-- * **:OnAfterWeaponDrop(From,Event,To,EventData)**: Triggers when an item is jettisoned or dropped from an aircraft (unconfirmed)
-- * **:OnAfterWeaponRearm(From,Event,To,EventData)**: Triggers when an item with internal supply is restored (unconfirmed)
--
-- ### Examples
--
-- -- Show a message to player when they take damage from a weapon
-- local clientInstance = CLIENTWATCH:New("Rotary")
-- function clientInstance:OnAfterSpawn(From,Event,To,ClientObject,EventData)
-- function ClientObject:OnAfterHit(From,Event,To,EventData)
-- local typeShooter = EventData.IniTypeName
-- local nameWeapon = EventData.weapon_name
-- MESSAGE:New("A "..typeShooter.." hit you with a "..nameWeapon,20):ToUnit(ClientObject.Unit)
-- end
-- end
--
-- @field #CLIENTWATCH
CLIENTWATCH = {}
CLIENTWATCH.ClassName = "CLIENTWATCH"
CLIENTWATCH.Debug = false
CLIENTWATCH.DebugEventData = false
CLIENTWATCH.lid = nil
-- @type CLIENTWATCHTools
-- @field #table Unit Wrapper.UNIT of the cient object
-- @field #table Group Wrapper.GROUP of the cient object
-- @field #table Client Wrapper.CLIENT of the cient object
-- @field #string PlayerName Name of the player controlling the client object
-- @field #string UnitName Name of the unit that is the client object
-- @field #string GroupName Name of the group the client object belongs to
CLIENTWATCHTools = {}
--- CLIENTWATCH version
-- @field #string version
CLIENTWATCH.version="1.0.1"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Creates a new instance of CLIENTWATCH to add scripts to. Can be used multiple times with the same client/prefixes if you need it for multiple scripts.
-- @param #CLIENTWATCH self
-- @param #string Will watch for clients whos UNIT NAME or GROUP NAME matches part of the #string as a prefix.
-- @param #table Put strings in a table to use multiple prefixes for the above method.
-- @param Wrapper.Client#CLIENT Provide a Moose CLIENT object to apply to that specific aircraft slot (static slots only!)
-- @param #nil Leave blank to activate for ALL CLIENTS
-- @return #CLIENTWATCH self
function CLIENTWATCH:New(client)
--Init FSM
local self=BASE:Inherit(self, FSM:New())
self:SetStartState( "Idle" )
self:AddTransition( "*", "Spawn", "*" )
self.FilterCoalition = nil
self.FilterCategory = nil
--- User function for OnAfter "Spawn" event.
-- @function [parent=#CLIENTWATCH] OnAfterSpawn
-- @param #CLIENTWATCH self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param #table clientObject Custom object that handles events and stores Moose object data. See top documentation for more details.
-- @param #table eventdata Data from EVENTS.Birth.
--Set up spawn tracking
if not client then
if self.Debug then self:I({"New client instance created. ClientType = All clients"}) end
self:HandleEvent(EVENTS.Birth)
function self:OnEventBirth(eventdata)
if (eventdata.IniCategory == 0 or eventdata.IniCategory == 1) and eventdata.IniPlayerName
and (not self.FilterCoalition or self.FilterCoalition == eventdata.IniCoalition)
and (not self.FilterCategory or self.FilterCategory == eventdata.IniCategory) then
if self.Debug then
self:I({"Client spawned in.",IniCategory = eventdata.IniCategory})
end
local clientWatchDebug = self.Debug
local clientObject = CLIENTWATCHTools:_newClient(clientWatchDebug,eventdata)
self:Spawn(clientObject,eventdata)
end
end
elseif type(client) == "table" or type(client) == "string" then
if type(client) == "table" then
--CLIENT TABLE
if client.ClassName == "CLIENT" then
if self.Debug then self:I({"New client instance created. ClientType = Wrapper.CLIENT",client}) end
self.ClientName = client:GetName()
self:HandleEvent(EVENTS.Birth)
function self:OnEventBirth(eventdata)
if (eventdata.IniCategory == 0 or eventdata.IniCategory == 1) and eventdata.IniPlayerName
and (not self.FilterCoalition or self.FilterCoalition == eventdata.IniCoalition)
and (not self.FilterCategory or self.FilterCategory == eventdata.IniCategory) then
if self.ClientName == eventdata.IniUnitName then
if self.Debug then
self:I({"Client spawned in.",IniCategory = eventdata.IniCategory})
end
local clientWatchDebug = self.Debug
local clientObject = CLIENTWATCHTools:_newClient(clientWatchDebug,eventdata)
self:Spawn(clientObject,eventdata)
end
end
end
--STRING TABLE
else
if self.Debug then self:I({"New client instance created. ClientType = Multiple Prefixes",client}) end
local tableValid = true
for _,entry in pairs(client) do
if type(entry) ~= "string" then
tableValid = false
self:E({"The base handler failed to start because at least one entry in param1's table is not a string!",InvalidEntry = entry})
return nil
end
end
if tableValid then
self:HandleEvent(EVENTS.Birth)
function self:OnEventBirth(eventdata)
for _,entry in pairs(client) do
if (eventdata.IniCategory == 0 or eventdata.IniCategory == 1) and eventdata.IniPlayerName
and (not self.FilterCoalition or self.FilterCoalition == eventdata.IniCoalition)
and (not self.FilterCategory or self.FilterCategory == eventdata.IniCategory) then
if string.match(eventdata.IniUnitName,entry) or string.match(eventdata.IniGroupName,entry) then
if self.Debug then
self:I({"Client spawned in.",IniCategory = eventdata.IniCategory})
end
local clientWatchDebug = self.Debug
local clientObject = CLIENTWATCHTools:_newClient(clientWatchDebug,eventdata)
self:Spawn(clientObject,eventdata)
break
end
end
end
end
end
end
else
if self.Debug then self:I({"New client instance created. ClientType = Single Prefix",client}) end
--SOLO STRING
self:HandleEvent(EVENTS.Birth)
function self:OnEventBirth(eventdata)
if (eventdata.IniCategory == 0 or eventdata.IniCategory == 1) and eventdata.IniPlayerName
and (not self.FilterCoalition or self.FilterCoalition == eventdata.IniCoalition)
and (not self.FilterCategory or self.FilterCategory == eventdata.IniCategory) then
if string.match(eventdata.IniUnitName,client) or string.match(eventdata.IniGroupName,client) then
if self.Debug then
self:I({"Client spawned in.",IniCategory = eventdata.IniCategory})
end
local clientWatchDebug = self.Debug
local clientObject = CLIENTWATCHTools:_newClient(clientWatchDebug,eventdata)
self:Spawn(clientObject,eventdata)
end
end
end
end
else
self:E({"The base handler failed to start because param1 is not a CLIENT object or a prefix string!",param1 = client})
return nil
end
return self
end
--- Filter out all clients not belonging to the provided coalition
-- @param #CLIENTWATCH self
-- @param #number Coalition number (1 = red, 2 = blue)
-- @param #string Coalition string ('red' or 'blue')
function CLIENTWATCH:FilterByCoalition(value)
if value == 1 or value == "red" then
self.FilterCoalition = 1
else
self.FilterCoalition = 2
end
return self
end
--- Filter out all clients that are not of the given category
-- @param #CLIENTWATCH self
-- @param #number Category number (0 = airplane, 1 = helicopter)
-- @param #string Category string ('airplane' or 'helicopter')
function CLIENTWATCH:FilterByCategory(value)
if value == 1 or value == "helicopter" then
self.FilterCategory = 1
else
self.FilterCategory = 0
end
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Internal function for creating a new client on birth. Do not use!!!.
-- @param #CLIENTWATCHTools self
-- @param #EVENTS.Birth EventData
-- @return #CLIENTWATCHTools self
function CLIENTWATCHTools:_newClient(clientWatchDebug,eventdata)
--Init FSM
local self=BASE:Inherit(self, FSM:New())
self:SetStartState( "Alive" )
self:AddTransition( "Alive", "Despawn", "Dead" )
self.Unit = eventdata.IniUnit
self.Group = self.Unit:GetGroup()
self.Client = self.Unit:GetClient()
self.PlayerName = self.Unit:GetPlayerName()
self.UnitName = self.Unit:GetName()
self.GroupName = self.Group:GetName()
--Event events
self:AddTransition( "*", "Hit", "*" )
self:AddTransition( "*", "Kill", "*" )
self:AddTransition( "*", "Score", "*" )
self:AddTransition( "*", "Shot", "*" )
self:AddTransition( "*", "ShootingStart", "*" )
self:AddTransition( "*", "ShootingEnd", "*" )
self:AddTransition( "*", "Land", "*" )
self:AddTransition( "*", "Takeoff", "*" )
self:AddTransition( "*", "RunwayTakeoff", "*" )
self:AddTransition( "*", "RunwayTouch", "*" )
self:AddTransition( "*", "Refueling", "*" )
self:AddTransition( "*", "RefuelingStop", "*" )
self:AddTransition( "*", "PlayerLeaveUnit", "*" )
self:AddTransition( "*", "Crash", "*" )
self:AddTransition( "*", "Dead", "*" )
self:AddTransition( "*", "PilotDead", "*" )
self:AddTransition( "*", "UnitLost", "*" )
self:AddTransition( "*", "Ejection", "*" )
self:AddTransition( "*", "HumanFailure", "*" )
self:AddTransition( "*", "HumanAircraftRepairFinish", "*" )
self:AddTransition( "*", "HumanAircraftRepairStart", "*" )
self:AddTransition( "*", "EngineShutdown", "*" )
self:AddTransition( "*", "EngineStartup", "*" )
self:AddTransition( "*", "WeaponAdd", "*" )
self:AddTransition( "*", "WeaponDrop", "*" )
self:AddTransition( "*", "WeaponRearm", "*" )
--Event Handlers
self:HandleEvent( EVENTS.Hit )
self:HandleEvent( EVENTS.Kill )
self:HandleEvent( EVENTS.Score )
self:HandleEvent( EVENTS.Shot )
self:HandleEvent( EVENTS.ShootingStart )
self:HandleEvent( EVENTS.ShootingEnd )
self:HandleEvent( EVENTS.Land )
self:HandleEvent( EVENTS.Takeoff )
self:HandleEvent( EVENTS.RunwayTakeoff )
self:HandleEvent( EVENTS.RunwayTouch )
self:HandleEvent( EVENTS.Refueling )
self:HandleEvent( EVENTS.RefuelingStop )
self:HandleEvent( EVENTS.PlayerLeaveUnit )
self:HandleEvent( EVENTS.Crash )
self:HandleEvent( EVENTS.Dead )
self:HandleEvent( EVENTS.PilotDead )
self:HandleEvent( EVENTS.UnitLost )
self:HandleEvent( EVENTS.Ejection )
self:HandleEvent( EVENTS.HumanFailure )
self:HandleEvent( EVENTS.HumanAircraftRepairFinish )
self:HandleEvent( EVENTS.HumanAircraftRepairStart )
self:HandleEvent( EVENTS.EngineShutdown )
self:HandleEvent( EVENTS.EngineStartup )
self:HandleEvent( EVENTS.WeaponAdd )
self:HandleEvent( EVENTS.WeaponDrop )
self:HandleEvent( EVENTS.WeaponRearm )
function self:OnEventHit(EventData)
if EventData.TgtUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered hit event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Hit(EventData)
end
end
function self:OnEventKill(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered kill event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Kill(EventData)
end
end
function self:OnEventScore(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered score event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Score(EventData)
end
end
function self:OnEventShot(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered shot event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Shot(EventData)
end
end
function self:OnEventShootingStart(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered shooting start event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:ShootingStart(EventData)
end
end
function self:OnEventShootingEnd(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered shooting end event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:ShootingEnd(EventData)
end
end
function self:OnEventLand(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered land event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Land(EventData)
end
end
function self:OnEventTakeoff(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered takeoff event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Takeoff(EventData)
end
end
function self:OnEventRunwayTakeoff(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered runway takeoff event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:RunwayTakeoff(EventData)
end
end
function self:OnEventRunwayTouch(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered runway touch event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:RunwayTouch(EventData)
end
end
function self:OnEventRefueling(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered refueling event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Refueling(EventData)
end
end
function self:OnEventRefuelingStop(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered refueling event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:RefuelingStop(EventData)
end
end
function self:OnEventPlayerLeaveUnit(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered leave unit event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:PlayerLeaveUnit(EventData)
self._deadRoutine()
end
end
function self:OnEventCrash(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered crash event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Crash(EventData)
self._deadRoutine()
end
end
function self:OnEventDead(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered dead event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Dead(EventData)
self._deadRoutine()
end
end
function self:OnEventPilotDead(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered pilot dead event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:PilotDead(EventData)
self._deadRoutine()
end
end
function self:OnEventUnitLost(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered unit lost event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:UnitLost(EventData)
self._deadRoutine()
end
end
function self:OnEventEjection(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered ejection event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:Ejection(EventData)
self._deadRoutine()
end
end
function self:OnEventHumanFailure(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered human failure event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:HumanFailure(EventData)
if not self.Unit:IsAlive() then
self._deadRoutine()
end
end
end
function self:OnEventHumanAircraftRepairFinish(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered repair finished event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:HumanAircraftRepairFinish(EventData)
end
end
function self:OnEventHumanAircraftRepairStart(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered repair start event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:HumanAircraftRepairStart(EventData)
end
end
function self:OnEventEngineShutdown(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered engine shutdown event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:EngineShutdown(EventData)
end
end
function self:OnEventEngineStartup(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered engine startup event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:EngineStartup(EventData)
end
end
function self:OnEventWeaponAdd(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered weapon add event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:WeaponAdd(EventData)
end
end
function self:OnEventWeaponDrop(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered weapon drop event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:WeaponDrop(EventData)
end
end
function self:OnEventWeaponRearm(EventData)
if EventData.IniUnitName == self.UnitName then
if clientWatchDebug then
self:I({"Client triggered weapon rearm event.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self:WeaponRearm(EventData)
end
end
--Fallback timer
self.FallbackTimer = TIMER:New(function()
if not self.Unit:IsAlive() then
if clientWatchDebug then
self:I({"Client is registered as dead without an event trigger. Running fallback dead routine.",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName})
end
self._deadRoutine()
end
end)
self.FallbackTimer:Start(5,5)
--Stop event handlers and trigger Despawn
function self._deadRoutine()
if clientWatchDebug then self:I({"Client dead routine triggered. Shutting down tracking...",Player = self.PlayerName,Group = self.GroupName,Unit = self.UnitName}) end
self:UnHandleEvent( EVENTS.Hit )
self:UnHandleEvent( EVENTS.Kill )
self:UnHandleEvent( EVENTS.Score )
self:UnHandleEvent( EVENTS.Shot )
self:UnHandleEvent( EVENTS.ShootingStart )
self:UnHandleEvent( EVENTS.ShootingEnd )
self:UnHandleEvent( EVENTS.Land )
self:UnHandleEvent( EVENTS.Takeoff )
self:UnHandleEvent( EVENTS.RunwayTakeoff )
self:UnHandleEvent( EVENTS.RunwayTouch )
self:UnHandleEvent( EVENTS.Refueling )
self:UnHandleEvent( EVENTS.RefuelingStop )
self:UnHandleEvent( EVENTS.PlayerLeaveUnit )
self:UnHandleEvent( EVENTS.Crash )
self:UnHandleEvent( EVENTS.Dead )
self:UnHandleEvent( EVENTS.PilotDead )
self:UnHandleEvent( EVENTS.UnitLost )
self:UnHandleEvent( EVENTS.Ejection )
self:UnHandleEvent( EVENTS.HumanFailure )
self:UnHandleEvent( EVENTS.HumanAircraftRepairFinish )
self:UnHandleEvent( EVENTS.HumanAircraftRepairStart )
self:UnHandleEvent( EVENTS.EngineShutdown )
self:UnHandleEvent( EVENTS.EngineStartup )
self:UnHandleEvent( EVENTS.WeaponAdd )
self:UnHandleEvent( EVENTS.WeaponDrop )
self:UnHandleEvent( EVENTS.WeaponRearm )
self.FallbackTimer:Stop()
self:Despawn()
end
self:I({"Detected client spawn and applied internal functions and events.", PlayerName = self.PlayerName, UnitName = self.UnitName, GroupName = self.GroupName})
return self
end

View File

@@ -184,7 +184,7 @@
do -- DESIGNATE
-- @type DESIGNATE
--- @type DESIGNATE
-- @extends Core.Fsm#FSM_PROCESS
--- Manage the designation of detected targets.
@@ -525,7 +525,7 @@ do -- DESIGNATE
self.AttackSet:ForEachGroupAlive(
-- @param Wrapper.Group#GROUP AttackGroup
--- @param Wrapper.Group#GROUP AttackGroup
function( AttackGroup )
self.FlashStatusMenu[AttackGroup] = FlashMenu
end
@@ -554,7 +554,7 @@ do -- DESIGNATE
self.AttackSet:ForEachGroupAlive(
-- @param Wrapper.Group#GROUP AttackGroup
--- @param Wrapper.Group#GROUP AttackGroup
function( AttackGroup )
self.FlashDetectionMessage[AttackGroup] = FlashDetectionMessage
end
@@ -826,7 +826,7 @@ do -- DESIGNATE
-- This Detection is obsolete, remove from the designate scope
self.Designating[DesignateIndex] = nil
self.AttackSet:ForEachGroupAlive(
-- @param Wrapper.Group#GROUP AttackGroup
--- @param Wrapper.Group#GROUP AttackGroup
function( AttackGroup )
if AttackGroup:IsAlive() == true then
local DetectionText = self.Detection:DetectedItemReportSummary( DetectedItem, AttackGroup ):Text( ", " )
@@ -903,7 +903,7 @@ do -- DESIGNATE
self.AttackSet:ForEachGroupAlive(
-- @param Wrapper.Group#GROUP GroupReport
--- @param Wrapper.Group#GROUP GroupReport
function( AttackGroup )
if self.FlashStatusMenu[AttackGroup] or ( MenuAttackGroup and ( AttackGroup:GetName() == MenuAttackGroup:GetName() ) ) then
@@ -1060,7 +1060,7 @@ do -- DESIGNATE
self.AttackSet:ForEachGroupAlive(
-- @param Wrapper.Group#GROUP GroupReport
--- @param Wrapper.Group#GROUP GroupReport
function( AttackGroup )
self:ScheduleOnce( Delay, self.SetMenu, self, AttackGroup )
@@ -1198,7 +1198,7 @@ do -- DESIGNATE
--local ReportTypes = REPORT:New()
--local ReportLaserCodes = REPORT:New()
--TargetSetUnit:Flush( self )
TargetSetUnit:Flush( self )
--self:F( { Recces = self.Recces } )
for TargetUnit, RecceData in pairs( self.Recces ) do
@@ -1229,12 +1229,10 @@ do -- DESIGNATE
end
end
if TargetSetUnit == nil then return end
if self.AutoLase or ( not self.AutoLase and ( self.LaseStart + Duration >= timer.getTime() ) ) then
TargetSetUnit:ForEachUnitPerThreatLevel( 10, 0,
-- @param Wrapper.Unit#UNIT SmokeUnit
--- @param Wrapper.Unit#UNIT SmokeUnit
function( TargetUnit )
self:F( { TargetUnit = TargetUnit:GetName() } )
@@ -1255,7 +1253,7 @@ do -- DESIGNATE
local RecceUnit = UnitData -- Wrapper.Unit#UNIT
local RecceUnitDesc = RecceUnit:GetDesc()
--self:F( { RecceUnit = RecceUnit:GetName(), RecceDescription = RecceUnitDesc } )x
--self:F( { RecceUnit = RecceUnit:GetName(), RecceDescription = RecceUnitDesc } )
if RecceUnit:IsLasing() == false then
--self:F( { IsDetected = RecceUnit:IsDetected( TargetUnit ), IsLOS = RecceUnit:IsLOS( TargetUnit ) } )
@@ -1277,10 +1275,9 @@ do -- DESIGNATE
local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration )
local AttackSet = self.AttackSet
local DesignateName = self.DesignateName
local typename = TargetUnit:GetTypeName()
function Spot:OnAfterDestroyed( From, Event, To )
self.Recce:MessageToSetGroup( "Target " ..typename .. " destroyed. " .. TargetSetUnit:CountAlive() .. " targets left.",
self.Recce:MessageToSetGroup( "Target " .. TargetUnit:GetTypeName() .. " destroyed. " .. TargetSetUnit:Count() .. " targets left.",
5, AttackSet, self.DesignateName )
end
@@ -1288,7 +1285,7 @@ do -- DESIGNATE
-- OK. We have assigned for the Recce a TargetUnit. We can exit the function.
MarkingCount = MarkingCount + 1
local TargetUnitType = TargetUnit:GetTypeName()
RecceUnit:MessageToSetGroup( "Marking " .. TargetUnitType .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.",
RecceUnit:MessageToSetGroup( "Marking " .. TargetUnit:GetTypeName() .. " with laser " .. RecceUnit:GetSpot().LaserCode .. " for " .. Duration .. "s.",
10, self.AttackSet, DesignateName )
if not MarkedTypes[TargetUnitType] then
MarkedTypes[TargetUnitType] = true
@@ -1395,7 +1392,7 @@ do -- DESIGNATE
local MarkedCount = 0
TargetSetUnit:ForEachUnitPerThreatLevel( 10, 0,
-- @param Wrapper.Unit#UNIT SmokeUnit
--- @param Wrapper.Unit#UNIT SmokeUnit
function( SmokeUnit )
if MarkedCount < self.MaximumMarkings then
@@ -1460,10 +1457,9 @@ do -- DESIGNATE
-- @param #DESIGNATE self
-- @return #DESIGNATE
function DESIGNATE:onafterDoneSmoking( From, Event, To, Index )
if self.Designating[Index] ~= nil then
self.Designating[Index] = string.gsub( self.Designating[Index], "S", "" )
self:SetDesignateMenu()
end
self.Designating[Index] = string.gsub( self.Designating[Index], "S", "" )
self:SetDesignateMenu()
end
--- DoneIlluminating
@@ -1476,3 +1472,5 @@ do -- DESIGNATE
end
end

View File

@@ -545,7 +545,7 @@ do -- DETECTION_BASE
-- @param #string To The To State string.
function DETECTION_BASE:onafterDetect( From, Event, To )
local DetectDelay = 0.15
local DetectDelay = 0.1
self.DetectionCount = 0
self.DetectionRun = 0
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
@@ -595,8 +595,7 @@ do -- DETECTION_BASE
return self
end
---
-- @param #DETECTION_BASE self
-- @param #string From The From State string.
-- @param #string Event The Event string.
@@ -605,7 +604,7 @@ do -- DETECTION_BASE
-- @param #number DetectionTimeStamp Time stamp of detection event.
function DETECTION_BASE:onafterDetection( From, Event, To, Detection, DetectionTimeStamp )
self:T( { DetectedObjects = self.DetectedObjects } )
-- self:F( { DetectedObjects = self.DetectedObjects } )
self.DetectionRun = self.DetectionRun + 1
@@ -613,14 +612,14 @@ do -- DETECTION_BASE
if Detection and Detection:IsAlive() then
self:T( { "DetectionGroup is Alive", Detection:GetName() } )
-- self:T( { "DetectionGroup is Alive", DetectionGroup:GetName() } )
local DetectionGroupName = Detection:GetName()
local DetectionUnit = Detection:GetFirstUnitAlive()
local DetectionUnit = Detection:GetUnit( 1 )
local DetectedUnits = {}
local DetectedTargets = DetectionUnit:GetDetectedTargets(
local DetectedTargets = Detection:GetDetectedTargets(
self.DetectVisual,
self.DetectOptical,
self.DetectRadar,
@@ -629,30 +628,28 @@ do -- DETECTION_BASE
self.DetectDLINK
)
--self:T( { DetectedTargets = DetectedTargets } )
--self:T(UTILS.PrintTableToLog(DetectedTargets))
for DetectionObjectID, Detection in pairs( DetectedTargets or {}) do
self:F( { DetectedTargets = DetectedTargets } )
for DetectionObjectID, Detection in pairs( DetectedTargets ) do
local DetectedObject = Detection.object -- DCS#Object
if DetectedObject and DetectedObject:isExist() and DetectedObject.id_ < 50000000 then -- and ( DetectedObject:getCategory() == Object.Category.UNIT or DetectedObject:getCategory() == Object.Category.STATIC ) then
local DetectedObjectName = DetectedObject:getName()
if not self.DetectedObjects[DetectedObjectName] then
self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {}
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
self.DetectedObjects[DetectedObjectName].Object = DetectedObject
end
end
end
for DetectionObjectName, DetectedObjectData in pairs( self.DetectedObjects or {}) do
for DetectionObjectName, DetectedObjectData in pairs( self.DetectedObjects ) do
local DetectedObject = DetectedObjectData.Object
if DetectedObject:isExist() then
local TargetIsDetected, TargetIsVisible, TargetKnowType, TargetKnowDistance, TargetLastTime, TargetLastPos, TargetLastVelocity = DetectionUnit:IsTargetDetected(
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity = DetectionUnit:IsTargetDetected(
DetectedObject,
self.DetectVisual,
self.DetectOptical,

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@
-- @module Functional.Mantis
-- @image Functional.Mantis.jpg
--
-- Last Update: Sep 2024
-- Last Update: Dec 2023
-------------------------------------------------------------------------
--- **MANTIS** class, extends Core.Base#BASE
@@ -58,8 +58,6 @@
-- @field #boolean ShoradLink If true, #MANTIS has #SHORAD enabled
-- @field #number ShoradTime Timer in seconds, how long #SHORAD will be active after a detection inside of the defense range
-- @field #number ShoradActDistance Distance of an attacker in meters from a Mantis SAM site, on which Shorad will be switched on. Useful to not give away Shorad sites too early. Default 15km. Should be smaller than checkradius.
-- @field #boolean checkforfriendlies If true, do not activate a SAM installation if a friendly aircraft is in firing range.
-- @field #table FilterZones Table of Core.Zone#ZONE Zones Consider SAM groups in this zone(s) only for this MANTIS instance, must be handed as #table of Zone objects.
-- @extends Core.Base#BASE
@@ -189,34 +187,29 @@
-- -- This is effectively a 3-stage filter allowing for zone overlap. A coordinate is accepted first when
-- -- it is inside any AcceptZone. Then RejectZones are checked, which enforces both borders, but also overlaps of
-- -- Accept- and RejectZones. Last, if it is inside a conflict zone, it is accepted.
-- mybluemantis:AddZones(AcceptZones,RejectZones,ConflictZones)
-- `mybluemantis:AddZones(AcceptZones,RejectZones,ConflictZones)`
--
--
-- ### 2.1.2 Change the number of long-, mid- and short-range systems going live on a detected target:
--
-- -- parameters are numbers. Defaults are 1,2,2,6 respectively
-- mybluemantis:SetMaxActiveSAMs(Short,Mid,Long,Classic)
-- `mybluemantis:SetMaxActiveSAMs(Short,Mid,Long,Classic)`
--
-- ### 2.1.3 SHORAD will automatically be added from SAM sites of type "short-range"
--
-- ### 2.1.4 Advanced features
--
-- -- switch off auto mode **before** you start MANTIS.
-- mybluemantis.automode = false
-- `mybluemantis.automode = false`
--
-- -- switch off auto shorad **before** you start MANTIS.
-- mybluemantis.autoshorad = false
-- `mybluemantis.autoshorad = false`
--
-- -- scale of the activation range, i.e. don't activate at the fringes of max range, defaults below.
-- -- also see engagerange below.
-- self.radiusscale[MANTIS.SamType.LONG] = 1.1
-- self.radiusscale[MANTIS.SamType.MEDIUM] = 1.2
-- self.radiusscale[MANTIS.SamType.SHORT] = 1.3
--
-- ### 2.1.5 Friendlies check in firing range
--
-- -- For some scenarios, like Cold War, it might be useful not to activate SAMs if friendly aircraft are around to avoid death by friendly fire.
-- mybluemantis.checkforfriendlies = true
-- ` self.radiusscale[MANTIS.SamType.LONG] = 1.1`
-- ` self.radiusscale[MANTIS.SamType.MEDIUM] = 1.2`
-- ` self.radiusscale[MANTIS.SamType.SHORT] = 1.3`
--
-- # 3. Default settings [both modes unless stated otherwise]
--
@@ -240,7 +233,7 @@
--
-- Use this option if you want to make use of or allow advanced SEAD tactics.
--
-- # 5. Integrate SHORAD [classic mode, not necessary in automode]
-- # 5. Integrate SHORAD [classic mode]
--
-- You can also choose to integrate Mantis with @{Functional.Shorad#SHORAD} for protection against HARMs and AGMs. When SHORAD detects a missile fired at one of MANTIS' SAM sites, it will activate SHORAD systems in
-- the given defense checkradius around that SAM site. Create a SHORAD object first, then integrate with MANTIS like so:
@@ -328,7 +321,6 @@ MANTIS = {
automode = true,
autoshorad = true,
ShoradGroupSet = nil,
checkforfriendlies = false,
}
--- Advanced state enumerator
@@ -355,17 +347,17 @@ MANTIS.SamType = {
-- @field #string Type #MANTIS.SamType of SAM, i.e. SHORT, MEDIUM or LONG (range)
-- @field #string Radar Radar typename on unit level (used as key)
MANTIS.SamData = {
["Hawk"] = { Range=35, Blindspot=0, Height=12, Type="Medium", Radar="Hawk" }, -- measures in km
["NASAMS"] = { Range=14, Blindspot=0, Height=7, Type="Short", Radar="NSAMS" }, -- AIM 120B
["Patriot"] = { Range=99, Blindspot=0, Height=25, Type="Long", Radar="Patriot" },
["Rapier"] = { Range=10, Blindspot=0, Height=3, Type="Short", Radar="rapier" },
["Hawk"] = { Range=44, Blindspot=0, Height=9, Type="Medium", Radar="Hawk" }, -- measures in km
["NASAMS"] = { Range=14, Blindspot=0, Height=3, Type="Short", Radar="NSAMS" },
["Patriot"] = { Range=99, Blindspot=0, Height=9, Type="Long", Radar="Patriot" },
["Rapier"] = { Range=6, Blindspot=0, Height=3, Type="Short", Radar="rapier" },
["SA-2"] = { Range=40, Blindspot=7, Height=25, Type="Medium", Radar="S_75M_Volhov" },
["SA-3"] = { Range=18, Blindspot=6, Height=18, Type="Short", Radar="5p73 s-125 ln" },
["SA-5"] = { Range=250, Blindspot=7, Height=40, Type="Long", Radar="5N62V" },
["SA-6"] = { Range=25, Blindspot=0, Height=8, Type="Medium", Radar="1S91" },
["SA-10"] = { Range=119, Blindspot=0, Height=18, Type="Long" , Radar="S-300PS 4"},
["SA-11"] = { Range=35, Blindspot=0, Height=20, Type="Medium", Radar="SA-11" },
["Roland"] = { Range=5, Blindspot=0, Height=5, Type="Short", Radar="Roland" },
["Roland"] = { Range=8, Blindspot=0, Height=3, Type="Short", Radar="Roland" },
["HQ-7"] = { Range=12, Blindspot=0, Height=3, Type="Short", Radar="HQ-7" },
["SA-9"] = { Range=4, Blindspot=0, Height=3, Type="Short", Radar="Strela" },
["SA-8"] = { Range=10, Blindspot=0, Height=5, Type="Short", Radar="Osa 9A33" },
@@ -384,7 +376,7 @@ MANTIS.SamData = {
["HQ-2"] = { Range=50, Blindspot=6, Height=35, Type="Medium", Radar="HQ_2_Guideline_LN" },
["SHORAD"] = { Range=3, Blindspot=0, Height=3, Type="Short", Radar="Igla" },
["TAMIR IDFA"] = { Range=20, Blindspot=0.6, Height=12.3, Type="Short", Radar="IRON_DOME_LN" },
["STUNNER IDFA"] = { Range=250, Blindspot=1, Height=45, Type="Long", Radar="DAVID_SLING_LN" },
["STUNNER IDFA"] = { Range=250, Blindspot=1, Height=45, Type="Long", Radar="DAVID_SLING_LN" },
}
--- SAM data HDS
@@ -439,50 +431,27 @@ MANTIS.SamDataSMA = {
-- @field #string Type #MANTIS.SamType of SAM, i.e. SHORT, MEDIUM or LONG (range)
-- @field #string Radar Radar typename on unit level (used as key)
MANTIS.SamDataCH = {
-- units from CH (Military Assets by Currenthill)
-- https://www.currenthill.com/
-- group name MUST contain CHM to ID launcher type correctly!
["2S38 CHM"] = { Range=8, Blindspot=0.5, Height=6, Type="Short", Radar="2S38" },
["PantsirS1 CHM"] = { Range=20, Blindspot=1.2, Height=15, Type="Short", Radar="PantsirS1" },
["PantsirS2 CHM"] = { Range=30, Blindspot=1.2, Height=18, Type="Medium", Radar="PantsirS2" },
["PGL-625 CHM"] = { Range=10, Blindspot=0.5, Height=5, Type="Short", Radar="PGL_625" },
["HQ-17A CHM"] = { Range=20, Blindspot=1.5, Height=10, Type="Short", Radar="HQ17A" },
["M903PAC2 CHM"] = { Range=160, Blindspot=3, Height=24.5, Type="Long", Radar="MIM104_M903_PAC2" },
["M903PAC3 CHM"] = { Range=120, Blindspot=1, Height=40, Type="Long", Radar="MIM104_M903_PAC3" },
["TorM2 CHM"] = { Range=12, Blindspot=1, Height=10, Type="Short", Radar="TorM2" },
["TorM2K CHM"] = { Range=12, Blindspot=1, Height=10, Type="Short", Radar="TorM2K" },
["TorM2M CHM"] = { Range=16, Blindspot=1, Height=10, Type="Short", Radar="TorM2M" },
["NASAMS3-AMRAAMER CHM"] = { Range=50, Blindspot=2, Height=35.7, Type="Medium", Radar="CH_NASAMS3_LN_AMRAAM_ER" },
["NASAMS3-AIM9X2 CHM"] = { Range=20, Blindspot=0.2, Height=18, Type="Short", Radar="CH_NASAMS3_LN_AIM9X2" },
["C-RAM CHM"] = { Range=2, Blindspot=0, Height=2, Type="Short", Radar="CH_Centurion_C_RAM" },
["PGZ-09 CHM"] = { Range=4, Blindspot=0, Height=3, Type="Short", Radar="CH_PGZ09" },
["S350-9M100 CHM"] = { Range=15, Blindspot=1.5, Height=8, Type="Short", Radar="CH_S350_50P6_9M100" },
["S350-9M96D CHM"] = { Range=150, Blindspot=2.5, Height=30, Type="Long", Radar="CH_S350_50P6_9M96D" },
["LAV-AD CHM"] = { Range=8, Blindspot=0.2, Height=4.8, Type="Short", Radar="CH_LAVAD" },
["HQ-22 CHM"] = { Range=170, Blindspot=5, Height=27, Type="Long", Radar="CH_HQ22_LN" },
["PGZ-95 CHM"] = { Range=2, Blindspot=0, Height=2, Type="Short", Radar="CH_PGZ95" },
["LD-3000 CHM"] = { Range=3, Blindspot=0, Height=3, Type="Short", Radar="CH_LD3000_stationary" },
["LD-3000M CHM"] = { Range=3, Blindspot=0, Height=3, Type="Short", Radar="CH_LD3000" },
["FlaRakRad CHM"] = { Range=8, Blindspot=1.5, Height=6, Type="Short", Radar="HQ17A" },
["IRIS-T SLM CHM"] = { Range=40, Blindspot=0.5, Height=20, Type="Medium", Radar="CH_IRIST_SLM" },
["M903PAC2KAT1 CHM"] = { Range=160, Blindspot=3, Height=24.5, Type="Long", Radar="CH_MIM104_M903_PAC2_KAT1" },
["Skynex CHM"] = { Range=3.5, Blindspot=0, Height=3.5, Type="Short", Radar="CH_SkynexHX" },
["Skyshield CHM"] = { Range=3.5, Blindspot=0, Height=3.5, Type="Short", Radar="CH_Skyshield_Gun" },
["WieselOzelot CHM"] = { Range=8, Blindspot=0.2, Height=4.8, Type="Short", Radar="CH_Wiesel2Ozelot" },
["BukM3-9M317M CHM"] = { Range=70, Blindspot=0.25, Height=35, Type="Medium", Radar="CH_BukM3_9A317M" },
["BukM3-9M317MA CHM"] = { Range=70, Blindspot=0.25, Height=35, Type="Medium", Radar="CH_BukM3_9A317MA" },
["SkySabre CHM"] = { Range=30, Blindspot=0.5, Height=10, Type="Medium", Radar="CH_SkySabreLN" },
["Stormer CHM"] = { Range=7.5, Blindspot=0.3, Height=7, Type="Short", Radar="CH_StormerHVM" },
["THAAD CHM"] = { Range=200, Blindspot=40, Height=150, Type="Long", Radar="CH_THAAD_M1120" },
["USInfantryFIM92K CHM"] = { Range=8, Blindspot=0.2, Height=4.8, Type="Short", Radar="CH_USInfantry_FIM92" },
["RBS98M CHM"] = { Range=20, Blindspot=0, Height=8, Type="Short", Radar="RBS-98" },
["RBS70 CHM"] = { Range=8, Blindspot=0, Height=5.5, Type="Short", Radar="RBS-70" },
["RBS90 CHM"] = { Range=8, Blindspot=0, Height=5.5, Type="Short", Radar="RBS-90" },
["RBS103A CHM"] = { Range=150, Blindspot=3, Height=24.5, Type="Long", Radar="LvS-103_Lavett103_Rb103A" },
["RBS103B CHM"] = { Range=35, Blindspot=0, Height=36, Type="Medium", Radar="LvS-103_Lavett103_Rb103B" },
["RBS103AM CHM"] = { Range=150, Blindspot=3, Height=24.5, Type="Long", Radar="LvS-103_Lavett103_HX_Rb103A" },
["RBS103BM CHM"] = { Range=35, Blindspot=0, Height=36, Type="Medium", Radar="LvS-103_Lavett103_HX_Rb103B" },
["Lvkv9040M CHM"] = { Range=4, Blindspot=0, Height=2.5, Type="Short", Radar="LvKv9040" },
-- units from CH (Military Assets by Currenthill)
-- https://www.currenthill.com/
-- group name MUST contain CHM to ID launcher type correctly!
["2S38 CH"] = { Range=8, Blindspot=0.5, Height=6, Type="Short", Radar="2S38" },
["PantsirS1 CH"] = { Range=20, Blindspot=1.2, Height=15, Type="Short", Radar="PantsirS1" },
["PantsirS2 CH"] = { Range=30, Blindspot=1.2, Height=18, Type="Medium", Radar="PantsirS2" },
["PGL-625 CH"] = { Range=10, Blindspot=0.5, Height=5, Type="Short", Radar="PGL_625" },
["HQ-17A CH"] = { Range=20, Blindspot=1.5, Height=10, Type="Short", Radar="HQ17A" },
["M903PAC2 CH"] = { Range=160, Blindspot=3, Height=24.5, Type="Long", Radar="MIM104_M903_PAC2" },
["M903PAC3 CH"] = { Range=120, Blindspot=1, Height=40, Type="Long", Radar="MIM104_M903_PAC3" },
["TorM2 CH"] = { Range=12, Blindspot=1, Height=10, Type="Short", Radar="TorM2" },
["TorM2K CH"] = { Range=12, Blindspot=1, Height=10, Type="Short", Radar="TorM2K" },
["TorM2M CH"] = { Range=16, Blindspot=1, Height=10, Type="Short", Radar="TorM2M" },
["NASAMS3-AMRAAMER CH"] = { Range=50, Blindspot=2, Height=35.7, Type="Medium", Radar="CH_NASAMS3_LN_AMRAAM_ER" },
["NASAMS3-AIM9X2 CH"] = { Range=20, Blindspot=0.2, Height=18, Type="Short", Radar="CH_NASAMS3_LN_AIM9X2" },
["C-RAM CH"] = { Range=2, Blindspot=0, Height=2, Type="Short", Radar="CH_Centurion_C_RAM" },
["PGZ-09 CH"] = { Range=4, Blindspot=0, Height=3, Type="Short", Radar="CH_PGZ09" },
["S350-9M100 CH"] = { Range=15, Blindspot=1.5, Height=8, Type="Short", Radar="CH_S350_50P6_9M100" },
["S350-9M96D CH"] = { Range=150, Blindspot=2.5, Height=30, Type="Long", Radar="CH_S350_50P6_9M96D" },
["LAV-AD CH"] = { Range=8, Blindspot=0.2, Height=4.8, Type="Short", Radar="CH_LAVAD" },
["HQ-22 CH"] = { Range=170, Blindspot=5, Height=27, Type="Long", Radar="CH_HQ22_LN" },
}
-----------------------------------------------------------------------
@@ -533,8 +502,7 @@ do
-- DONE: Treat Awacs separately, since they might be >80km off site
-- DONE: Allow tables of prefixes for the setup
-- DONE: Auto-Mode with range setups for various known SAM types.
self.name = name or "mymantis"
self.SAM_Templates_Prefix = samprefix or "Red SAM"
self.EWR_Templates_Prefix = ewrprefix or "Red EWR"
self.HQ_Template_CC = hq or nil
@@ -663,7 +631,7 @@ do
-- TODO Version
-- @field #string version
self.version="0.8.20"
self.version="0.8.16"
self:I(string.format("***** Starting MANTIS Version %s *****", self.version))
--- FSM Functions ---
@@ -1254,10 +1222,10 @@ do
function MANTIS:_PreFilterHeight(height)
self:T(self.lid.."_PreFilterHeight")
local set = {}
local dlink = self.Detection -- Ops.Intel#INTEL_DLINK
local dlink = self.Detection -- Ops.Intelligence#INTEL_DLINK
local detectedgroups = dlink:GetContactTable()
for _,_contact in pairs(detectedgroups) do
local contact = _contact -- Ops.Intel#INTEL.Contact
local contact = _contact -- Ops.Intelligence#INTEL.Contact
local grp = contact.group -- Wrapper.Group#GROUP
if grp:IsAlive() then
if grp:GetHeight(true) < height then
@@ -1287,10 +1255,6 @@ do
-- DEBUG
set = self:_PreFilterHeight(height)
end
local friendlyset -- Core.Set#SET_GROUP
if self.checkforfriendlies == true then
friendlyset = SET_GROUP:New():FilterCoalitions(self.Coalition):FilterCategories({"plane","helicopter"}):FilterFunction(function(grp) if grp and grp:InAir() then return true else return false end end):FilterOnce()
end
for _,_coord in pairs (set) do
local coord = _coord -- get current coord to check
-- output for cross-check
@@ -1315,16 +1279,8 @@ do
local m = MESSAGE:New(text,10,"Check"):ToAllIf(self.debug)
self:T(self.lid..text)
end
-- friendlies around?
local nofriendlies = true
if self.checkforfriendlies == true then
local closestfriend, distance = friendlyset:GetClosestGroup(samcoordinate)
if closestfriend and distance and distance < rad then
nofriendlies = false
end
end
-- end output to cross-check
if targetdistance <= rad and zonecheck == true and nofriendlies == true then
if targetdistance <= rad and zonecheck then
return true, targetdistance
end
end
@@ -1419,7 +1375,7 @@ do
-- @return #string type Long, medium or short range
-- @return #number blind "blind" spot
function MANTIS:_GetSAMDataFromUnits(grpname,mod,sma,chm)
self:T(self.lid.."_GetSAMDataFromUnits")
self:T(self.lid.."_GetSAMRangeFromUnits")
local found = false
local range = self.checkradius
local height = 3000
@@ -1472,7 +1428,7 @@ do
-- @return #string type Long, medium or short range
-- @return #number blind "blind" spot
function MANTIS:_GetSAMRange(grpname)
self:T(self.lid.."_GetSAMRange for "..tostring(grpname))
self:T(self.lid.."_GetSAMRange")
local range = self.checkradius
local height = 3000
local type = MANTIS.SamType.MEDIUM
@@ -1489,9 +1445,9 @@ do
elseif string.find(grpname,"CHM",1,true) then
CHMod = true
end
--if self.automode then
if self.automode then
for idx,entry in pairs(self.SamData) do
self:T("ID = " .. idx)
--self:I("ID = " .. idx)
if string.find(grpname,idx,1,true) then
local _entry = entry -- #MANTIS.SamData
type = _entry.Type
@@ -1499,21 +1455,18 @@ do
range = _entry.Range * 1000 * radiusscale -- max firing range
height = _entry.Height * 1000 -- max firing height
blind = _entry.Blindspot
self:T("Matching Groupname = " .. grpname .. " Range= " .. range)
--self:I("Matching Groupname = " .. grpname .. " Range= " .. range)
found = true
break
end
end
--end
end
-- secondary filter if not found
if (not found) or HDSmod or SMAMod or CHMod then
if (not found and self.automode) or HDSmod or SMAMod or CHMod then
range, height, type = self:_GetSAMDataFromUnits(grpname,HDSmod,SMAMod,CHMod)
elseif not found then
self:E(self.lid .. string.format("*****Could not match radar data for %s! Will default to midrange values!",grpname))
end
if string.find(grpname,"SHORAD",1,true) then
type = MANTIS.SamType.SHORT -- force short on match
end
return range, height, type, blind
end
@@ -1677,10 +1630,6 @@ do
function MANTIS:_CheckLoop(samset,detset,dlink,limit)
self:T(self.lid .. "CheckLoop " .. #detset .. " Coordinates")
local switchedon = 0
local statusreport = REPORT:New("\nMANTIS Status")
local instatusred = 0
local instatusgreen = 0
local SEADactive = 0
for _,_data in pairs (samset) do
local samcoordinate = _data[2]
local name = _data[1]
@@ -1703,7 +1652,7 @@ do
elseif (not self.UseEmOnOff) and switchedon < limit then
samgroup:OptionAlarmStateRed()
switchedon = switchedon + 1
switch = true
switch = true
end
if self.SamStateTracker[name] ~= "RED" and switch then
self:__RedState(1,samgroup)
@@ -1721,7 +1670,7 @@ do
-- debug output
if (self.debug or self.verbose) and switch then
local text = string.format("SAM %s in alarm state RED!", name)
--local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug
local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug)
if self.verbose then self:I(self.lid..text) end
end
end --end alive
@@ -1739,26 +1688,12 @@ do
end
if self.debug or self.verbose then
local text = string.format("SAM %s in alarm state GREEN!", name)
--local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug)
local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug)
if self.verbose then self:I(self.lid..text) end
end
end --end alive
end --end check
end --for loop
if self.debug then
for _,_status in pairs(self.SamStateTracker) do
if _status == "GREEN" then
instatusgreen=instatusgreen+1
elseif _status == "RED" then
instatusred=instatusred+1
end
end
statusreport:Add("+-----------------------------+")
statusreport:Add(string.format("+ SAM in RED State: %2d",instatusred))
statusreport:Add(string.format("+ SAM in GREEN State: %2d",instatusgreen))
statusreport:Add("+-----------------------------+")
MESSAGE:New(statusreport:Text(),10,nil,true):ToAll():ToLog()
end
end --end check
end --for for loop
return self
end
@@ -1842,7 +1777,7 @@ do
-- @return #MANTIS self
function MANTIS:_CheckDLinkState()
self:T(self.lid .. "_CheckDLinkState")
local dlink = self.Detection -- Ops.Intel#INTEL_DLINK
local dlink = self.Detection -- Ops.Intelligence#INTEL_DLINK
local TS = timer.getAbsTime()
if not dlink:Is("Running") and (TS - self.DLTimeStamp > 29) then
self.DLink = false
@@ -1872,7 +1807,7 @@ do
end
--]]
if self.autoshorad then
self.Shorad = SHORAD:New(self.name.."-SHORAD","SHORAD",self.SAM_Group,self.ShoradActDistance,self.ShoradTime,self.coalition,self.UseEmOnOff)
self.Shorad = SHORAD:New(self.name.."-SHORAD",self.name.."-SHORAD",self.SAM_Group,self.ShoradActDistance,self.ShoradTime,self.coalition,self.UseEmOnOff)
self.Shorad:SetDefenseLimits(80,95)
self.ShoradLink = true
self.Shorad.Groupset=self.ShoradGroupSet

View File

@@ -2052,10 +2052,6 @@ function RAT:_InitAircraft(DCSgroup)
self.aircraft.length=16
self.aircraft.height=5
self.aircraft.width=9
elseif DCStype == "Saab340" then -- <- These lines added
self.aircraft.length=19.73 -- <- These lines added
self.aircraft.height=6.97 -- <- These lines added
self.aircraft.width=21.44 -- <- These lines added
end
self.aircraft.box=math.max(self.aircraft.length,self.aircraft.width)

File diff suppressed because it is too large Load Diff

View File

@@ -78,8 +78,7 @@
-- ### Authors: **FlightControl**
--
-- ### Contributions:
--
-- * **Applevangelist**: Additional functionality, fixes.
--
-- * **Wingthor (TAW)**: Testing & Advice.
-- * **Dutch-Baron (TAW)**: Testing & Advice.
-- * **Whisper**: Testing and Advice.
@@ -117,13 +116,11 @@
-- Special targets can be set that will give extra scores to the players when these are destroyed.
-- Use the methods @{#SCORING.AddUnitScore}() and @{#SCORING.RemoveUnitScore}() to specify a special additional score for a specific @{Wrapper.Unit}s.
-- Use the methods @{#SCORING.AddStaticScore}() and @{#SCORING.RemoveStaticScore}() to specify a special additional score for a specific @{Wrapper.Static}s.
-- Use the method @{#SCORING.AddScoreSetGroup}() to specify a special additional score for a specific @{Wrapper.Group}s gathered in a @{Core.Set#SET_GROUP}.
-- Use the method @{#SCORING.SetGroupGroup}() to specify a special additional score for a specific @{Wrapper.Group}s.
--
-- local Scoring = SCORING:New( "Scoring File" )
-- Scoring:AddUnitScore( UNIT:FindByName( "Unit #001" ), 200 )
-- Scoring:AddStaticScore( STATIC:FindByName( "Static #1" ), 100 )
-- local GroupSet = SET_GROUP:New():FilterPrefixes("RAT"):FilterStart()
-- Scoring:AddScoreSetGroup( GroupSet, 100)
--
-- The above grants an additional score of 200 points for Unit #001 and an additional 100 points of Static #1 if these are destroyed.
-- Note that later in the mission, one can remove these scores set, for example, when the a goal achievement time limit is over.
@@ -229,7 +226,7 @@ SCORING = {
ClassID = 0,
Players = {},
AutoSave = true,
version = "1.18.4"
version = "1.17.1"
}
local _SCORINGCoalition = {
@@ -248,15 +245,13 @@ local _SCORINGCategory = {
--- Creates a new SCORING object to administer the scoring achieved by players.
-- @param #SCORING self
-- @param #string GameName The name of the game. This name is also logged in the CSV score file.
-- @param #string SavePath (Optional) Path where to save the CSV file, defaults to your **<User>\\Saved Games\\DCS\\Logs** folder.
-- @param #boolean AutoSave (Optional) If passed as `false`, then swith autosave off.
-- @return #SCORING self
-- @usage
--
-- -- Define a new scoring object for the mission Gori Valley.
-- ScoringObject = SCORING:New( "Gori Valley" )
--
function SCORING:New( GameName, SavePath, AutoSave )
function SCORING:New( GameName )
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() ) -- #SCORING
@@ -319,8 +314,7 @@ function SCORING:New( GameName, SavePath, AutoSave )
end )
-- Create the CSV file.
self.AutoSavePath = SavePath
self.AutoSave = AutoSave or true
self.AutoSave = true
self:OpenCSV( GameName )
return self
@@ -434,31 +428,6 @@ function SCORING:AddScoreGroup( ScoreGroup, Score )
return self
end
--- Specify a special additional score for a @{Core.Set#SET_GROUP}.
-- @param #SCORING self
-- @param Core.Set#SET_GROUP Set The @{Core.Set#SET_GROUP} for which each @{Wrapper.Unit} in each Group a Score is given.
-- @param #number Score The Score value.
-- @return #SCORING
function SCORING:AddScoreSetGroup(Set, Score)
local set = Set:GetSetObjects()
for _,_group in pairs (set) do
if _group and _group:IsAlive() then
self:AddScoreGroup(_group,Score)
end
end
local function AddScore(group)
self:AddScoreGroup(group,Score)
end
function Set:OnAfterAdded(From,Event,To,ObjectName,Object)
AddScore(Object)
end
return self
end
--- Add a @{Core.Zone} to define additional scoring when any object is destroyed in that zone.
-- Note that if a @{Core.Zone} with the same name is already within the scoring added, the @{Core.Zone} (type) and Score will be replaced!
-- This allows for a dynamic destruction zone evolution within your mission.
@@ -1061,11 +1030,11 @@ function SCORING:_EventOnHit( Event )
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit or 0
PlayerHit.TimeStamp = PlayerHit.TimeStamp or 0
PlayerHit.UNIT = PlayerHit.UNIT or TargetUNIT
-- After an instant kill we can't compute the threat level anymore. To fix this we compute at OnEventBirth
-- After an instant kill we can't compute the thread level anymore. To fix this we compute at OnEventBirth
if PlayerHit.UNIT.ThreatType == nil then
PlayerHit.ThreatLevel, PlayerHit.ThreatType = PlayerHit.UNIT:GetThreatLevel()
-- if this fails for some reason, set a good default value
if PlayerHit.ThreatType == nil or PlayerHit.ThreatType == "" then
if PlayerHit.ThreatType == nil then
PlayerHit.ThreatLevel = 1
PlayerHit.ThreatType = "Unknown"
end
@@ -1172,7 +1141,7 @@ function SCORING:_EventOnHit( Event )
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit or 0
PlayerHit.TimeStamp = PlayerHit.TimeStamp or 0
PlayerHit.UNIT = PlayerHit.UNIT or TargetUNIT
-- After an instant kill we can't compute the threat level anymore. To fix this we compute at OnEventBirth
-- After an instant kill we can't compute the thread level anymore. To fix this we compute at OnEventBirth
if PlayerHit.UNIT.ThreatType == nil then
PlayerHit.ThreatLevel, PlayerHit.ThreatType = PlayerHit.UNIT:GetThreatLevel()
-- if this fails for some reason, set a good default value
@@ -1319,17 +1288,17 @@ function SCORING:_EventOnDeadOrCrash( Event )
TargetDestroy.PenaltyDestroy = TargetDestroy.PenaltyDestroy + 1
--self:OnKillPvP(PlayerName, TargetPlayerName, true, TargetThreatLevel, Player.ThreatLevel, ThreatPenalty)
self:OnKillPvP(Player, TargetPlayerName, true, TargetThreatLevel, Player.ThreatLevel, ThreatPenalty)
if Player.HitPlayers[TargetPlayerName] then -- A player destroyed another player
self:OnKillPvP(PlayerName, TargetPlayerName, true)
self:OnKillPvP(Player, TargetPlayerName, true)
MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed friendly player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " ..
"Penalty: -" .. ThreatPenalty .. " = " .. Player.Score - Player.Penalty,
MESSAGE.Type.Information )
:ToAllIf( self:IfMessagesDestroy() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() )
else
self:OnKillPvE(PlayerName, TargetUnitName, true, TargetThreatLevel, Player.ThreatLevel, ThreatPenalty)
self:OnKillPvE(Player, TargetUnitName, true, TargetThreatLevel, Player.ThreatLevel, ThreatPenalty)
MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed friendly target " .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " ..
"Penalty: -" .. ThreatPenalty .. " = " .. Player.Score - Player.Penalty,
MESSAGE.Type.Information )
@@ -1357,14 +1326,14 @@ function SCORING:_EventOnDeadOrCrash( Event )
else
Player.PlayerKills = 1
end
self:OnKillPvP(PlayerName, TargetPlayerName, false, TargetThreatLevel, Player.ThreatLevel, ThreatScore)
self:OnKillPvP(Player, TargetPlayerName, false, TargetThreatLevel, Player.ThreatLevel, ThreatScore)
MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed enemy player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " ..
"Score: +" .. ThreatScore .. " = " .. Player.Score - Player.Penalty,
MESSAGE.Type.Information )
:ToAllIf( self:IfMessagesDestroy() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() )
else
self:OnKillPvE(PlayerName, TargetUnitName, false, TargetThreatLevel, Player.ThreatLevel, ThreatScore)
self:OnKillPvE(Player, TargetUnitName, false, TargetThreatLevel, Player.ThreatLevel, ThreatScore)
MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed enemy " .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " ..
"Score: +" .. ThreatScore .. " = " .. Player.Score - Player.Penalty,
MESSAGE.Type.Information )
@@ -1842,11 +1811,10 @@ end
function SCORING:OpenCSV( ScoringCSV )
self:F( ScoringCSV )
if lfs and io and os and self.AutoSave == true then
if lfs and io and os and self.AutoSave then
if ScoringCSV then
self.ScoringCSV = ScoringCSV
local path = self.AutoSavePath or lfs.writedir() .. [[Logs\]]
local fdir = path .. self.ScoringCSV .. " " .. os.date( "%Y-%m-%d %H-%M-%S" ) .. ".csv"
local fdir = lfs.writedir() .. [[Logs\]] .. self.ScoringCSV .. " " .. os.date( "%Y-%m-%d %H-%M-%S" ) .. ".csv"
self.CSVFile, self.err = io.open( fdir, "w+" )
if not self.CSVFile then
@@ -1967,23 +1935,23 @@ end
--- Handles the event when one player kill another player
-- @param #SCORING self
-- @param #string PlayerName The attacking player
-- @param #string TargetPlayerName The name of the killed player
-- @param #boolean IsTeamKill true if this kill was a team kill
-- @param #number TargetThreatLevel Threat level of the target
-- @param #number PlayerThreatLevel Threat level of the player
-- @param #PLAYER Player the ataching player
-- @param #string TargetPlayerName the name of the killed player
-- @param #bool IsTeamKill true if this kill was a team kill
-- @param #number TargetThreatLevel Thread level of the target
-- @param #number PlayerThreatLevelThread level of the player
-- @param #number Score The score based on both threat levels
function SCORING:OnKillPvP(PlayerName, TargetPlayerName, IsTeamKill, TargetThreatLevel, PlayerThreatLevel, Score)
function SCORING:OnKillPvP(Player, TargetPlayerName, IsTeamKill, TargetThreatLevel, PlayerThreatLevel, Score)
end
--- Handles the event when one player kill another player
-- @param #SCORING self
-- @param #string PlayerName The attacking player
-- @param #PLAYER Player the ataching player
-- @param #string TargetUnitName the name of the killed unit
-- @param #boolean IsTeamKill true if this kill was a team kill
-- @param #number TargetThreatLevel Threat level of the target
-- @param #number PlayerThreatLevel Threat level of the player
-- @param #bool IsTeamKill true if this kill was a team kill
-- @param #number TargetThreatLevel Thread level of the target
-- @param #number PlayerThreatLevelThread level of the player
-- @param #number Score The score based on both threat levels
function SCORING:OnKillPvE(PlayerName, TargetUnitName, IsTeamKill, TargetThreatLevel, PlayerThreatLevel, Score)
function SCORING:OnKillPvE(Player, TargetUnitName, IsTeamKill, TargetThreatLevel, PlayerThreatLevel, Score)
end
end

View File

@@ -19,7 +19,7 @@
--
-- ### Authors: **applevangelist**, **FlightControl**
--
-- Last Update: Oct 2024
-- Last Update: Dec 2023
--
-- ===
--
@@ -28,16 +28,6 @@
---
-- @type SEAD
-- @field #string ClassName The Class Name.
-- @field #table TargetSkill Table of target skills.
-- @field #table SEADGroupPrefixes Table of SEAD prefixes.
-- @field #table SuppressedGroups Table of currently suppressed groups.
-- @field #number EngagementRange Engagement Range.
-- @field #number Padding Padding in seconds.
-- @field #function CallBack Callback function for suppression plans.
-- @field #boolean UseCallBack Switch for callback function to be used.
-- @field #boolean debug Debug switch.
-- @field #boolen WeaponTrack Track switch, if true track weapon speed for 30 secs.
-- @extends Core.Base#BASE
--- Make SAM sites execute evasive and defensive behaviour when being fired upon.
@@ -66,11 +56,10 @@ SEAD = {
SEADGroupPrefixes = {},
SuppressedGroups = {},
EngagementRange = 75, -- default 75% engagement range Feature Request #1355
Padding = 15,
Padding = 10,
CallBack = nil,
UseCallBack = false,
debug = false,
WeaponTrack = false,
}
--- Missile enumerators
@@ -155,7 +144,7 @@ function SEAD:New( SEADGroupPrefixes, Padding )
self:AddTransition("*", "ManageEvasion", "*")
self:AddTransition("*", "CalculateHitZone", "*")
self:I("*** SEAD - Started Version 0.4.8")
self:I("*** SEAD - Started Version 0.4.6")
return self
end
@@ -331,6 +320,9 @@ function SEAD:onafterCalculateHitZone(From,Event,To,SEADWeapon,pos0,height,SEADG
end
local seadset = SET_GROUP:New():FilterPrefixes(self.SEADGroupPrefixes):FilterZones({targetzone}):FilterOnce()
local tgtcoord = targetzone:GetRandomPointVec2()
--if tgtcoord and tgtcoord.ClassName == "COORDINATE" then
--local tgtgrp = seadset:FindNearestGroupFromPointVec2(tgtcoord)
local tgtgrp = seadset:GetRandom()
local _targetgroup = nil
local _targetgroupname = "none"
@@ -382,7 +374,7 @@ function SEAD:onafterManageEvasion(From,Event,To,_targetskill,_targetgroup,SEADP
reach = wpndata[1] * 1.1
local mach = wpndata[2]
wpnspeed = math.floor(mach * 340.29)
if Weapon and Weapon:GetSpeed() > 0 then
if Weapon then
wpnspeed = Weapon:GetSpeed()
self:T(string.format("*** SEAD - Weapon Speed from WEAPON: %f m/s",wpnspeed))
end
@@ -463,30 +455,22 @@ end
-- @return #SEAD self
function SEAD:HandleEventShot( EventData )
self:T( { EventData.id } )
local SEADPlane = EventData.IniUnit -- Wrapper.Unit#UNIT
local SEADGroup = EventData.IniGroup -- Wrapper.Group#GROUP
local SEADPlanePos = SEADPlane:GetCoordinate() -- Core.Point#COORDINATE
local SEADUnit = EventData.IniDCSUnit
local SEADUnitName = EventData.IniDCSUnitName
local SEADWeapon = EventData.Weapon -- Identify the weapon fired
local SEADWeaponName = EventData.WeaponName or "None" -- return weapon type
if self:_CheckHarms(SEADWeaponName) then
local SEADPlane = EventData.IniUnit -- Wrapper.Unit#UNIT
if not SEADPlane then return self end -- case IniUnit is empty
local SEADGroup = EventData.IniGroup -- Wrapper.Group#GROUP
local SEADPlanePos = SEADPlane:GetCoordinate() -- Core.Point#COORDINATE
local SEADUnit = EventData.IniDCSUnit
local SEADUnitName = EventData.IniDCSUnitName
local WeaponWrapper = WEAPON:New(EventData.Weapon) -- Wrapper.Weapon#WEAPON
self:T( "*** SEAD - Missile Launched = " .. SEADWeaponName)
local SEADWeaponName = EventData.WeaponName -- return weapon type
local WeaponWrapper = WEAPON:New(EventData.Weapon)
--local SEADWeaponSpeed = WeaponWrapper:GetSpeed() -- mps
self:T( "*** SEAD - Missile Launched = " .. SEADWeaponName)
--self:T({ SEADWeapon })
if self:_CheckHarms(SEADWeaponName) then
self:T( '*** SEAD - Weapon Match' )
if self.WeaponTrack == true then
WeaponWrapper:SetFuncTrack(function(weapon) env.info(string.format("*** Weapon Speed: %d m/s",weapon:GetSpeed() or -1)) end)
WeaponWrapper:StartTrack(0.1)
WeaponWrapper:StopTrack(30)
end
local _targetskill = "Random"
local _targetgroupname = "none"
local _target = EventData.Weapon:getTarget() -- Identify target
@@ -539,7 +523,7 @@ function SEAD:HandleEventShot( EventData )
end
if SEADGroupFound == true then -- yes we are being attacked
if string.find(SEADWeaponName,"ADM_141",1,true) then
self:__ManageEvasion(2,_targetskill,_targetgroup,SEADPlanePos,SEADWeaponName,SEADGroup,2,WeaponWrapper)
self:__ManageEvasion(2,_targetskill,_targetgroup,SEADPlanePos,SEADWeaponName,SEADGroup,0,WeaponWrapper)
else
self:ManageEvasion(_targetskill,_targetgroup,SEADPlanePos,SEADWeaponName,SEADGroup,0,WeaponWrapper)
end

View File

@@ -1629,7 +1629,7 @@ WAREHOUSE = {
-- @field #boolean arrived If true, asset arrived at its destination.
--
-- @field #number damage Damage of asset group in percent.
-- @field Ops.Airwing#AIRWING.Payload payload The payload of the asset.
-- @field Ops.AirWing#AIRWING.Payload payload The payload of the asset.
-- @field Ops.OpsGroup#OPSGROUP flightgroup The flightgroup object.
-- @field Ops.Cohort#COHORT cohort The cohort this asset belongs to.
-- @field Ops.Legion#LEGION legion The legion this asset belonts to.
@@ -3414,7 +3414,7 @@ end
-- FSM states
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- On after Start event. Starts the warehouse. Adds event handlers and schedules status updates of reqests and queue.
--- On after Start event. Starts the warehouse. Addes event handlers and schedules status updates of reqests and queue.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
@@ -3595,7 +3595,6 @@ function WAREHOUSE:onafterStatus(From, Event, To)
local Trepair=self:GetRunwayRepairtime()
self:I(self.lid..string.format("Runway destroyed! Will be repaired in %d sec", Trepair))
if Trepair==0 then
self.runwaydestroyed = nil
self:RunwayRepaired()
end
end
@@ -5393,8 +5392,7 @@ function WAREHOUSE:onafterRunwayDestroyed(From, Event, To)
self:_InfoMessage(text)
self.runwaydestroyed=timer.getAbsTime()
return self
end
--- On after "RunwayRepaired" event.
@@ -5409,8 +5407,7 @@ function WAREHOUSE:onafterRunwayRepaired(From, Event, To)
self:_InfoMessage(text)
self.runwaydestroyed=nil
return self
end
@@ -6732,7 +6729,7 @@ end
-- @param Wrapper.Group#GROUP deadgroup Group of unit that died.
-- @param #WAREHOUSE.Pendingitem request Request that needs to be updated.
function WAREHOUSE:_UnitDead(deadunit, deadgroup, request)
--self:F(self.lid.."FF unit dead "..deadunit:GetName())
self:F(self.lid.."FF unit dead "..deadunit:GetName())
-- Find opsgroup.
local opsgroup=_DATABASE:FindOpsGroup(deadgroup)
@@ -7946,12 +7943,10 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
local clients=_DATABASE.CLIENTS
for clientname, client in pairs(clients) do
local template=_DATABASE:GetGroupTemplateFromUnitName(clientname)
if template then
local units=template.units
for i,unit in pairs(units) do
local coord=COORDINATE:New(unit.x, unit.alt, unit.y)
coords[unit.name]=coord
end
local units=template.units
for i,unit in pairs(units) do
local coord=COORDINATE:New(unit.x, unit.alt, unit.y)
coords[unit.name]=coord
end
end
end
@@ -8433,14 +8428,12 @@ function WAREHOUSE:_GetAttribute(group)
local attribute=WAREHOUSE.Attribute.OTHER_UNKNOWN --#WAREHOUSE.Attribute
if group then
local groupCat=group:GetCategory()
-----------
--- Air ---
-----------
-- Planes
local transportplane=group:HasAttribute("Transports") and group:HasAttribute("Planes") and groupCat==Group.Category.AIRPLANE
local transportplane=group:HasAttribute("Transports") and group:HasAttribute("Planes")
local awacs=group:HasAttribute("AWACS")
local fighter=group:HasAttribute("Fighters") or group:HasAttribute("Interceptors") or group:HasAttribute("Multirole fighters") or (group:HasAttribute("Bombers") and not group:HasAttribute("Strategic bombers"))
local bomber=group:HasAttribute("Strategic bombers")
@@ -8595,6 +8588,7 @@ end
-- @param #WAREHOUSE.Queueitem qitem Item of queue to be removed.
-- @param #table queue The queue from which the item should be deleted.
function WAREHOUSE:_DeleteQueueItem(qitem, queue)
self:F({qitem=qitem, queue=queue})
for i=1,#queue do
local _item=queue[i] --#WAREHOUSE.Queueitem

View File

@@ -48,7 +48,6 @@ __Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Wrapper/Marker.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Wrapper/Weapon.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Wrapper/Net.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Wrapper/Storage.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Wrapper/DynamicCargo.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Cargo/Cargo.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Cargo/CargoUnit.lua' )
@@ -78,7 +77,6 @@ __Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Functional/Warehouse.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Functional/Fox.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Functional/Mantis.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Functional/Shorad.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Functional/ClientWatch.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Ops/Airboss.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Ops/RecoveryTanker.lua' )
@@ -124,14 +122,6 @@ __Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Actions/Act_Route.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Actions/Act_Account.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Actions/Act_Assist.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/ShapeBase.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Circle.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Cube.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Line.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Oval.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Polygon.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Shapes/Triangle.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Sound/UserSound.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Sound/SoundOutput.lua' )
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Sound/Radio.lua' )

File diff suppressed because it is too large Load Diff

View File

@@ -255,7 +255,6 @@
-- @field #boolean skipperUturn U-turn on/off via menu.
-- @field #number skipperOffset Holding offset angle in degrees for Case II/III manual recoveries.
-- @field #number skipperTime Recovery time in min for manual recovery.
-- @field #boolean intowindold If true, use old into wind calculation.
-- @extends Core.Fsm#FSM
--- Be the boss!
@@ -2725,18 +2724,6 @@ function AIRBOSS:SetLSOCallInterval( TimeInterval )
return self
end
--- Set if old into wind calculation is used when carrier turns into the wind for a recovery.
-- @param #AIRBOSS self
-- @param #boolean SwitchOn If `true` or `nil`, use old into wind calculation.
-- @return #AIRBOSS self
function AIRBOSS:SetIntoWindLegacy( SwitchOn )
if SwitchOn==nil then
SwitchOn=true
end
self.intowindold=SwitchOn
return self
end
--- Airboss is a rather nice guy and not strictly following the rules. Fore example, he does allow you into the landing pattern if you are not coming from the Marshal stack.
-- @param #AIRBOSS self
-- @param #boolean Switch If true or nil, Airboss bends the rules a bit.
@@ -3614,7 +3601,7 @@ function AIRBOSS:onafterStart( From, Event, To )
-- Handle events.
self:HandleEvent( EVENTS.Birth )
self:HandleEvent( EVENTS.RunwayTouch )
self:HandleEvent( EVENTS.Land )
self:HandleEvent( EVENTS.EngineShutdown )
self:HandleEvent( EVENTS.Takeoff )
self:HandleEvent( EVENTS.Crash )
@@ -3654,12 +3641,6 @@ function AIRBOSS:onafterStatus( From, Event, To )
local pos = self:GetCoordinate()
local speed = self.carrier:GetVelocityKNOTS()
-- Update magnetic variation if we can get it from DCS.
if require then
self.magvar=pos:GetMagneticDeclination()
--env.info(string.format("FF magvar=%.1f", self.magvar))
end
-- Check water is ahead.
local collision = false -- self:_CheckCollisionCoord(pos:Translate(self.collisiondist, hdg))
@@ -4379,7 +4360,7 @@ function AIRBOSS:onafterStop( From, Event, To )
-- Unhandle events.
self:UnHandleEvent( EVENTS.Birth )
self:UnHandleEvent( EVENTS.RunwayTouch )
self:UnHandleEvent( EVENTS.Land )
self:UnHandleEvent( EVENTS.EngineShutdown )
self:UnHandleEvent( EVENTS.Takeoff )
self:UnHandleEvent( EVENTS.Crash )
@@ -5219,7 +5200,6 @@ function AIRBOSS:_InitVoiceOvers()
TOMCAT = { file = "PILOT-Tomcat", suffix = "ogg", loud = false, subtitle = "", duration = 0.66, subduration = 5 },
HORNET = { file = "PILOT-Hornet", suffix = "ogg", loud = false, subtitle = "", duration = 0.56, subduration = 5 },
VIKING = { file = "PILOT-Viking", suffix = "ogg", loud = false, subtitle = "", duration = 0.61, subduration = 5 },
GREYHOUND = { file = "PILOT-Greyhound", suffix = "ogg", loud = false, subtitle = "", duration = 0.61, subduration = 5 },
BALL = { file = "PILOT-Ball", suffix = "ogg", loud = false, subtitle = "", duration = 0.50, subduration = 5 },
BINGOFUEL = { file = "PILOT-BingoFuel", suffix = "ogg", loud = false, subtitle = "", duration = 0.80 },
GASATDIVERT = { file = "PILOT-GasAtDivert", suffix = "ogg", loud = false, subtitle = "", duration = 1.80 },
@@ -6494,7 +6474,7 @@ function AIRBOSS:_LandAI( flight )
or flight.actype == AIRBOSS.AircraftCarrier.RHINOF
or flight.actype == AIRBOSS.AircraftCarrier.GROWLER then
Speed = UTILS.KnotsToKmph( 200 )
elseif flight.actype == AIRBOSS.AircraftCarrier.E2D or flight.actype == AIRBOSS.AircraftCarrier.C2A then
elseif flight.actype == AIRBOSS.AircraftCarrier.E2D then
Speed = UTILS.KnotsToKmph( 150 )
elseif flight.actype == AIRBOSS.AircraftCarrier.F14A_AI or flight.actype == AIRBOSS.AircraftCarrier.F14A or flight.actype == AIRBOSS.AircraftCarrier.F14B then
Speed = UTILS.KnotsToKmph( 175 )
@@ -8289,7 +8269,7 @@ end
--- Airboss event handler for event land.
-- @param #AIRBOSS self
-- @param Core.Event#EVENTDATA EventData
function AIRBOSS:OnEventRunwayTouch( EventData )
function AIRBOSS:OnEventLand( EventData )
self:F3( { eventland = EventData } )
-- Nil checks.
@@ -9774,7 +9754,7 @@ function AIRBOSS:_Groove( playerData )
local glideslopeError = groovedata.GSE
local AoA = groovedata.AoA
if rho <= RXX and playerData.step == AIRBOSS.PatternStep.GROOVE_XX and (math.abs( groovedata.Roll ) <= 4.0 and playerData.unit:IsInZone( self:_GetZoneLineup() )) then
if rho <= RXX and playerData.step == AIRBOSS.PatternStep.GROOVE_XX and (math.abs( groovedata.Roll ) <= 4.0 or playerData.unit:IsInZone( self:_GetZoneLineup() )) then
-- Start time in groove
playerData.TIG0 = timer.getTime()
@@ -11495,7 +11475,7 @@ end
--- Get wind direction and speed at carrier position.
-- @param #AIRBOSS self
-- @param #number alt Altitude ASL in meters. Default 18 m.
-- @param #number alt Altitude ASL in meters. Default 15 m.
-- @param #boolean magnetic Direction including magnetic declination.
-- @param Core.Point#COORDINATE coord (Optional) Coordinate at which to get the wind. Default is current carrier position.
-- @return #number Direction the wind is blowing **from** in degrees.
@@ -11567,31 +11547,10 @@ end
--- Get true (or magnetic) heading of carrier into the wind. This accounts for the angled runway.
-- @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 )
if self.intowindold then
--env.info("FF use OLD into wind")
return self:GetHeadingIntoWind_old(vdeck, magnetic, coord)
else
--env.info("FF use NEW into wind")
return self:GetHeadingIntoWind_new(vdeck, magnetic, coord)
end
end
--- Get true (or magnetic) heading of carrier into the wind. This accounts for the angled runway.
-- @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.
function AIRBOSS:GetHeadingIntoWind_old( vdeck, magnetic, coord )
function AIRBOSS:GetHeadingIntoWind_old( magnetic, coord )
local function adjustDegreesForWindSpeed(windSpeed)
local degreesAdjustment = 0
@@ -11648,13 +11607,7 @@ function AIRBOSS:GetHeadingIntoWind_old( vdeck, magnetic, coord )
intowind = intowind + 360
end
-- Wind speed.
--local _, vwind = self:GetWind()
-- Speed of carrier in m/s but at least 4 knots.
local vtot = math.max(vdeck-UTILS.MpsToKnots(vwind), 4)
return intowind, vtot
return intowind
end
--- Get true (or magnetic) heading of carrier into the wind. This accounts for the angled runway.
@@ -11665,7 +11618,7 @@ end
-- @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_new( vdeck, magnetic, coord )
function AIRBOSS:GetHeadingIntoWind( vdeck, magnetic, coord )
-- Default offset angle.
local Offset=self.carrierparam.rwyangle or 0
@@ -12169,18 +12122,16 @@ function AIRBOSS:_LSOgrade( playerData )
local GIC, nIC = self:_Flightdata2Text( playerData, AIRBOSS.GroovePos.IC )
local GAR, nAR = self:_Flightdata2Text( playerData, AIRBOSS.GroovePos.AR )
-- VTOL approach, which is graded differently (currently only Harrier).
local vtol=playerData.actype==AIRBOSS.AircraftCarrier.AV8B
-- Put everything together.
local G = GXX .. " " .. GIM .. " " .. " " .. GIC .. " " .. GAR
-- Count number of minor/small nS, normal nN and major/large deviations nL.
-- Count number of minor, normal and major deviations.
local N=nXX+nIM+nIC+nAR
local Nv=nXX+nIM
local nL=count(G, '_')/2
local nS=count(G, '%(')
local nN=N-nS-nL
local nNv=Nv-nS-nL
-- Groove time 15-18.99 sec for a unicorn. Or 60-65 for V/STOL unicorn.
local Tgroove=playerData.Tgroove
@@ -12196,64 +12147,34 @@ function AIRBOSS:_LSOgrade( playerData )
G = "Unicorn"
else
if vtol then
-- Add AV-8B Harrier devation allowances due to lower groundspeed and 3x conventional groove time, this allows to maintain LSO tolerances while respecting the deviations are not unsafe.--Pene testing
-- Add AV-8B Harrier devation allowances due to lower groundspeed and 3x conventional groove time, this allows to maintain LSO tolerances while respecting the deviations are not unsafe.--Pene testing
-- Large devaitions still result in a No Grade, A Unicorn still requires a clean pass with no deviation.
if nL > 1 and playerData.actype==AIRBOSS.AircraftCarrier.AV8B then
-- Larger deviations ==> "No grade" 2.0 points.
grade="--"
points=2.0
elseif nNv >= 1 and playerData.actype==AIRBOSS.AircraftCarrier.AV8B then
-- Only average deviations ==> "Fair Pass" Pass with average deviations and corrections.
grade="(OK)"
points=3.0
elseif nNv < 1 and playerData.actype==AIRBOSS.AircraftCarrier.AV8B then
-- Only minor average deviations ==> "OK" Pass with minor deviations and corrections. (test nNv<=1 and)
grade="OK"
points=4.0
elseif nL > 0 then
-- Larger deviations ==> "No grade" 2.0 points.
grade="--"
points=2.0
elseif nN> 0 then
-- No larger but average deviations ==> "Fair Pass" Pass with average deviations and corrections.
grade="(OK)"
points=3.0
else
-- Only minor corrections
grade="OK"
points=4.0
end
-- Normal laning part at the beginning
local Gb = GXX .. " " .. GIM
-- Number of deviations that occurred at the the beginning of the landing (XX or IM). These are graded like in non-VTOL landings, i.e. on deviations is
local N=nXX+nIM
local nL=count(Gb, '_')/2
local nS=count(Gb, '%(')
local nN=N-nS-nL
-- VTOL part of the landing
local Gv = GIC .. " " .. GAR
-- Number of deviations that occurred at the the end (VTOL part) of the landing (IC or AR).
local Nv=nIC+nAR
local nLv=count(Gv, '_')/2
local nSv=count(Gv, '%(')
local nNv=Nv-nSv-nLv
if nL>0 or nLv>1 then
-- Larger deviations at XX or IM or at least one larger deviation IC or AR==> "No grade" 2.0 points.
-- In other words, we allow one larger deviation at IC+AR
grade="--"
points=2.0
elseif nN>0 or nNv>1 or nLv==1 then
-- Average deviations at XX+IM or more than one normal deviation IC or AR ==> "Fair Pass" Pass with average deviations and corrections.
grade="(OK)"
points=3.0
else
-- Only minor corrections
grade="OK"
points=4.0
end
else
-- This is a normal (non-VTOL) landing.
if nL > 0 then
-- Larger deviations ==> "No grade" 2.0 points.
grade="--"
points=2.0
elseif nN> 0 then
-- No larger but average/normal deviations ==> "Fair Pass" Pass with average deviations and corrections.
grade="(OK)"
points=3.0
else
-- Only minor corrections ==> "Okay pass" 4.0 points.
grade="OK"
points=4.0
end
end
end
-- Replace" )"( and "__"
@@ -14326,8 +14247,6 @@ function AIRBOSS:_GetACNickname( actype )
nickname = "Harrier"
elseif actype == AIRBOSS.AircraftCarrier.E2D then
nickname = "Hawkeye"
elseif actype == AIRBOSS.AircraftCarrier.C2A then
nickname = "Greyhound"
elseif actype == AIRBOSS.AircraftCarrier.F14A_AI or actype == AIRBOSS.AircraftCarrier.F14A or actype == AIRBOSS.AircraftCarrier.F14B then
nickname = "Tomcat"
elseif actype == AIRBOSS.AircraftCarrier.FA18C or actype == AIRBOSS.AircraftCarrier.HORNET then
@@ -14365,56 +14284,33 @@ function AIRBOSS:_GetOnboardNumbers( group, playeronly )
-- Debug text.
local text = string.format( "Onboard numbers of group %s:", groupname )
local template=group:GetTemplate()
-- Units of template group.
local units = group:GetTemplate().units
-- Get numbers.
local numbers = {}
if template then
for _, unit in pairs( units ) do
-- Units of template group.
local units = template.units
-- Onboard number and unit name.
local n = tostring( unit.onboard_num )
local name = unit.name
local skill = unit.skill or "Unknown"
-- Get numbers.
for _, unit in pairs( units ) do
-- Onboard number and unit name.
local n = tostring( unit.onboard_num )
local name = unit.name
local skill = unit.skill or "Unknown"
-- Debug text.
text = text .. string.format( "\n- unit %s: onboard #=%s skill=%s", name, n, tostring( skill ) )
if playeronly and skill == "Client" or skill == "Player" then
-- There can be only one player in the group, so we skip everything else.
return n
end
-- Table entry.
numbers[name] = n
end
-- Debug info.
self:T2( self.lid .. text )
else
if playeronly then
return 101
else
local units=group:GetUnits()
for i,_unit in pairs(units) do
local name=_unit:GetName()
numbers[name]=100+i
end
-- Debug text.
text = text .. string.format( "\n- unit %s: onboard #=%s skill=%s", name, n, tostring( skill ) )
if playeronly and skill == "Client" or skill == "Player" then
-- There can be only one player in the group, so we skip everything else.
return n
end
-- Table entry.
numbers[name] = n
end
-- Debug info.
self:T2( self.lid .. text )
return numbers
end
@@ -14678,7 +14574,7 @@ function AIRBOSS:_GetPlayerUnitAndName( _unitName )
-- Get DCS unit from its name.
local DCSunit = Unit.getByName( _unitName )
if DCSunit and DCSunit.getPlayerName then
if DCSunit then
-- Get player name if any.
local playername = DCSunit:getPlayerName()
@@ -15649,7 +15545,7 @@ function AIRBOSS:_Number2Sound( playerData, sender, number, delay )
end
-- Split string into characters.
local numbers = _split( tostring(number) )
local numbers = _split( number )
local wait = 0
for i = 1, #numbers do
@@ -15717,7 +15613,7 @@ function AIRBOSS:_Number2Radio( radio, number, delay, interval, pilotcall )
end
-- Split string into characters.
local numbers = _split( tostring(number) )
local numbers = _split( number )
local wait = 0
for i = 1, #numbers do
@@ -18085,7 +17981,7 @@ function AIRBOSS:_MarkCaseZones( _unitName, flare )
self:_GetZoneArcIn( case ):FlareZone( FLARECOLOR.White, 45 )
text = text .. "\n* arc turn in with WHITE flares"
self:_GetZoneArcOut( case ):FlareZone( FLARECOLOR.White, 45 )
text = text .. "\n* arc turn out with WHITE flares"
text = text .. "\n* arc trun out with WHITE flares"
end
end
@@ -18137,7 +18033,7 @@ function AIRBOSS:_MarkCaseZones( _unitName, flare )
self:_GetZoneArcIn( case ):SmokeZone( SMOKECOLOR.Blue, 45 )
text = text .. "\n* arc turn in with BLUE smoke"
self:_GetZoneArcOut( case ):SmokeZone( SMOKECOLOR.Blue, 45 )
text = text .. "\n* arc turn out with BLUE smoke"
text = text .. "\n* arc trun out with BLUE smoke"
end
end

View File

@@ -30,8 +30,8 @@
-- @module Ops.CSAR
-- @image OPS_CSAR.jpg
---
-- Last Update Sep 2024
-- Date: May 2023
-- Last: Update Dec 2024
-------------------------------------------------------------------------
--- **CSAR** class, extends Core.Base#BASE, Core.Fsm#FSM
@@ -41,7 +41,6 @@
-- @field #string lid Class id string for output to DCS log file.
-- @field #number coalition Coalition side number, e.g. `coalition.side.RED`.
-- @field Core.Set#SET_GROUP allheligroupset Set of CSAR heli groups.
-- @field Core.Set#SET_GROUP UserSetGroup Set of CSAR heli groups as designed by the mission designer (if any set).
-- @extends Core.Fsm#FSM
--- *Combat search and rescue (CSAR) are search and rescue operations that are carried out during war that are within or near combat zones.* (Wikipedia)
@@ -117,17 +116,8 @@
-- mycsar.topmenuname = "CSAR" -- set the menu entry name
-- mycsar.ADFRadioPwr = 1000 -- ADF Beacons sending with 1KW as default
-- mycsar.PilotWeight = 80 -- Loaded pilots weigh 80kgs each
-- mycsar.AllowIRStrobe = false -- Allow a menu item to request an IR strobe to find a downed pilot at night (requires NVGs to see it).
-- mycsar.IRStrobeRuntime = 300 -- If an IR Strobe is activated, it runs for 300 seconds (5 mins).
--
-- ## 2.1 Create own SET_GROUP to manage CTLD Pilot groups
--
-- -- Parameter: Set The SET_GROUP object created by the mission designer/user to represent the CSAR pilot groups.
-- -- Needs to be set before starting the CSAR instance.
-- local myset = SET_GROUP:New():FilterPrefixes("Helikopter"):FilterCoalitions("red"):FilterStart()
-- mycsar:SetOwnSetPilotGroups(myset)
--
-- ## 2.2 SRS Features and Other Features
-- ## 2.1 SRS Features and Other Features
--
-- mycsar.useSRS = false -- Set true to use FF\'s SRS integration
-- mycsar.SRSPath = "C:\\Progra~1\\DCS-SimpleRadio-Standalone\\" -- adjust your own path in your SRS installation -- server(!)
@@ -146,7 +136,6 @@
-- mycsar.csarUsePara = false -- If set to true, will use the LandingAfterEjection Event instead of Ejection. Requires mycsar.enableForAI to be set to true. --shagrat
-- mycsar.wetfeettemplate = "man in floating thingy" -- if you use a mod to have a pilot in a rescue float, put the template name in here for wet feet spawns. Note: in conjunction with csarUsePara this might create dual ejected pilots in edge cases.
-- mycsar.allowbronco = false -- set to true to use the Bronco mod as a CSAR plane
-- mycsar.CreateRadioBeacons = true -- set to false to disallow creating ADF radio beacons.
--
-- ## 3. Results
--
@@ -267,10 +256,6 @@ CSAR = {
topmenuname = "CSAR",
ADFRadioPwr = 1000,
PilotWeight = 80,
CreateRadioBeacons = true,
UserSetGroup = nil,
AllowIRStrobe = false,
IRStrobeRuntime = 300,
}
--- Downed pilots info.
@@ -287,7 +272,6 @@ CSAR = {
-- @field #number timestamp Timestamp for approach process.
-- @field #boolean alive Group is alive or dead/rescued.
-- @field #boolean wetfeet Group is spawned over (deep) water.
-- @field #string BeaconName Name of radio beacon - if any.
--- All slot / Limit settings
-- @type CSAR.AircraftType
@@ -306,14 +290,10 @@ CSAR.AircraftType["Bell-47"] = 2
CSAR.AircraftType["UH-60L"] = 10
CSAR.AircraftType["AH-64D_BLK_II"] = 2
CSAR.AircraftType["Bronco-OV-10A"] = 2
CSAR.AircraftType["MH-60R"] = 10
CSAR.AircraftType["OH-6A"] = 2
CSAR.AircraftType["OH58D"] = 2
CSAR.AircraftType["CH-47Fbl1"] = 31
--- CSAR class version.
-- @field #string version
CSAR.version="1.0.29"
CSAR.version="1.0.19"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
@@ -472,9 +452,6 @@ function CSAR:New(Coalition, Template, Alias)
-- added 1.0.16
self.PilotWeight = 80
-- Own SET_GROUP if any
self.UserSetGroup = nil
-- WARNING - here\'ll be dragons
-- for this to work you need to de-sanitize your mission environment in <DCS root>\Scripts\MissionScripting.lua
@@ -485,7 +462,7 @@ function CSAR:New(Coalition, Template, Alias)
self.SRSModulation = radio.modulation.AM -- modulation
self.SRSport = 5002 -- port
self.SRSCulture = "en-GB"
self.SRSVoice = MSRS.Voices.Google.Standard.en_GB_Standard_B
self.SRSVoice = nil
self.SRSGPathToCredentials = nil
self.SRSVolume = 1.0 -- volume 0.0 to 1.0
self.SRSGender = "male" -- male or female
@@ -653,7 +630,7 @@ end
-- @param #string Playername Name of Player (if applicable)
-- @param #boolean Wetfeet Ejected over water
-- @return #CSAR self.
function CSAR:_CreateDownedPilotTrack(Group,Groupname,Side,OriginalUnit,Description,Typename,Frequency,Playername,Wetfeet,BeaconName)
function CSAR:_CreateDownedPilotTrack(Group,Groupname,Side,OriginalUnit,Description,Typename,Frequency,Playername,Wetfeet)
self:T({"_CreateDownedPilotTrack",Groupname,Side,OriginalUnit,Description,Typename,Frequency,Playername})
-- create new entry
@@ -661,7 +638,7 @@ function CSAR:_CreateDownedPilotTrack(Group,Groupname,Side,OriginalUnit,Descript
DownedPilot.desc = Description or ""
DownedPilot.frequency = Frequency or 0
DownedPilot.index = self.downedpilotcounter
DownedPilot.name = Groupname or Playername or ""
DownedPilot.name = Groupname or ""
DownedPilot.originalUnit = OriginalUnit or ""
DownedPilot.player = Playername or ""
DownedPilot.side = Side or 0
@@ -670,7 +647,6 @@ function CSAR:_CreateDownedPilotTrack(Group,Groupname,Side,OriginalUnit,Descript
DownedPilot.timestamp = 0
DownedPilot.alive = true
DownedPilot.wetfeet = Wetfeet or false
DownedPilot.BeaconName = BeaconName
-- Add Pilot
local PilotTable = self.downedPilots
@@ -757,6 +733,7 @@ function CSAR:_SpawnPilotInField(country,point,frequency,wetfeet)
:NewWithAlias(template,alias)
:InitCoalition(coalition)
:InitCountry(country)
:InitAIOnOff(pilotcacontrol)
:InitDelayOff()
:SpawnFromCoordinate(point)
@@ -838,18 +815,8 @@ function CSAR:_AddCsar(_coalition , _country, _point, _typeName, _unitName, _pla
end
end
local BeaconName
if _playerName then
BeaconName = _playerName..math.random(1,10000)
elseif _unitName then
BeaconName = _unitName..math.random(1,10000)
else
BeaconName = "Ghost-1-1"..math.random(1,10000)
end
if (_freq and _freq ~= 0) then --shagrat only add beacon if _freq is NOT 0
self:_AddBeaconToGroup(_spawnedGroup, _freq, BeaconName)
self:_AddBeaconToGroup(_spawnedGroup, _freq)
end
self:_AddSpecialOptions(_spawnedGroup)
@@ -874,7 +841,7 @@ function CSAR:_AddCsar(_coalition , _country, _point, _typeName, _unitName, _pla
local _GroupName = _spawnedGroup:GetName() or _alias
self:_CreateDownedPilotTrack(_spawnedGroup,_GroupName,_coalition,_unitName,_text,_typeName,_freq,_playerName,wetfeet,BeaconName)
self:_CreateDownedPilotTrack(_spawnedGroup,_GroupName,_coalition,_unitName,_text,_typeName,_freq,_playerName,wetfeet)
self:_InitSARForPilot(_spawnedGroup, _unitName, _freq, noMessage, _playerName) --shagrat use unitName to have the aircraft callsign / descriptive "name" etc.
@@ -992,6 +959,7 @@ end
-- @param Core.Point#COORDINATE Point
-- @param #number Coalition Coalition.
-- @param #string Description (optional) Description.
-- @param #boolean addBeacon (optional) yes or no.
-- @param #boolean Nomessage (optional) If true, don\'t send a message to SAR.
-- @param #string Unitname (optional) Name of the lost unit.
-- @param #string Typename (optional) Type of plane.
@@ -1221,7 +1189,7 @@ function CSAR:_EventHandler(EventData)
if _place:GetCoalition() == self.coalition or _place:GetCoalition() == coalition.side.NEUTRAL then
self:__Landed(2,_event.IniUnitName, _place)
self:_ScheduledSARFlight(_event.IniUnitName,_event.IniGroupName,true,true)
self:_ScheduledSARFlight(_event.IniUnitName,_event.IniGroupName,true)
else
self:T(string.format("Airfield %d, Unit %d", _place:GetCoalition(), _unit:GetCoalition()))
end
@@ -1269,24 +1237,10 @@ function CSAR:_InitSARForPilot(_downedGroup, _GroupName, _freq, _nomessage, _pla
if not _nomessage then
if _freq ~= 0 then --shagrat
local _text = string.format("%s requests SAR at %s, beacon at %.2f KHz", _groupName, _coordinatesText, _freqk)--shagrat _groupName to prevent 'f15_Pilot_Parachute'
if self.coordtype ~= 2 then --not MGRS
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime)
else
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime,false,true)
local coordtext = UTILS.MGRSStringToSRSFriendly(_coordinatesText,true)
local _text = string.format("%s requests SAR at %s, beacon at %.2f kilo hertz", _groupName, coordtext, _freqk)
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime,true,false)
end
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime)
else --shagrat CASEVAC msg
local _text = string.format("Pickup Zone at %s.", _coordinatesText )
if self.coordtype ~= 2 then --not MGRS
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime)
else
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime,false,true)
local coordtext = UTILS.MGRSStringToSRSFriendly(_coordinatesText,true)
local _text = string.format("Pickup Zone at %s.", coordtext )
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime,true,false)
end
self:_DisplayToAllSAR(_text,self.coalition,self.messageTime)
end
end
@@ -1574,7 +1528,7 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
local _reset = true
if (_distance < 500) then
self:T(self.lid .. "[Pickup Debug] Helo closer than 500m: ".._lookupKeyHeli)
if self.heliCloseMessage[_lookupKeyHeli] == nil then
if self.autosmoke == true then
self:_DisplayMessageToSAR(_heliUnit, string.format("%s: %s. You\'re close now! Land or hover at the smoke.", self:_GetCustomCallSign(_heliName), _pilotName), self.messageTime,false,true)
@@ -1583,16 +1537,14 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
end
self.heliCloseMessage[_lookupKeyHeli] = true
end
self:T(self.lid .. "[Pickup Debug] Checking landed vs Hover for ".._lookupKeyHeli)
-- have we landed close enough?
if not _heliUnit:InAir() then
self:T(self.lid .. "[Pickup Debug] Helo landed: ".._lookupKeyHeli)
if self.pilotRuntoExtractPoint == true then
if (_distance < self.extractDistance) then
local _time = self.landedStatus[_lookupKeyHeli]
self:T(self.lid .. "[Pickup Debug] Check pilot running or arrived ".._lookupKeyHeli)
if _time == nil then
self:T(self.lid .. "[Pickup Debug] Pilot running not arrived yet ".._lookupKeyHeli)
self.landedStatus[_lookupKeyHeli] = math.floor( (_distance - self.loadDistance) / 3.6 )
_time = self.landedStatus[_lookupKeyHeli]
_woundedGroup:OptionAlarmStateGreen()
@@ -1603,15 +1555,11 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
self.landedStatus[_lookupKeyHeli] = _time
end
--if _time <= 0 or _distance < self.loadDistance then
self:T(self.lid .. "[Pickup Debug] Pilot close enough? ".._lookupKeyHeli)
if _distance < self.loadDistance + 5 or _distance <= 13 then
self:T(self.lid .. "[Pickup Debug] Pilot close enough - YES ".._lookupKeyHeli)
if self.pilotmustopendoors and (self:_IsLoadingDoorOpen(_heliName) == false) then
self:_DisplayMessageToSAR(_heliUnit, "Open the door to let me in!", self.messageTime, true, true)
self:T(self.lid .. "[Pickup Debug] Door closed, try again next loop ".._lookupKeyHeli)
return false
else
self:T(self.lid .. "[Pickup Debug] Pick up Pilot ".._lookupKeyHeli)
self.landedStatus[_lookupKeyHeli] = nil
self:_PickupUnit(_heliUnit, _pilotName, _woundedGroup, _woundedGroupName)
return true
@@ -1619,32 +1567,28 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
end
end
else
self:T(self.lid .. "[Pickup Debug] Helo landed, pilot NOT set to run to helo ".._lookupKeyHeli)
if (_distance < self.loadDistance) then
self:T(self.lid .. "[Pickup Debug] Helo close enough, door check ".._lookupKeyHeli)
if self.pilotmustopendoors and (self:_IsLoadingDoorOpen(_heliName) == false) then
self:T(self.lid .. "[Pickup Debug] Door closed, try again next loop ".._lookupKeyHeli)
self:_DisplayMessageToSAR(_heliUnit, "Open the door to let me in!", self.messageTime, true, true)
return false
else
self:T(self.lid .. "[Pickup Debug] Pick up Pilot ".._lookupKeyHeli)
self:_PickupUnit(_heliUnit, _pilotName, _woundedGroup, _woundedGroupName)
return true
end
end
end
else
self:T(self.lid .. "[Pickup Debug] Helo hovering".._lookupKeyHeli)
local _unitsInHelicopter = self:_PilotsOnboard(_heliName)
local _maxUnits = self.AircraftType[_heliUnit:GetTypeName()]
if _maxUnits == nil then
_maxUnits = self.max_units
end
self:T(self.lid .. "[Pickup Debug] Check capacity and close enough for winching ".._lookupKeyHeli)
if _heliUnit:InAir() and _unitsInHelicopter + 1 <= _maxUnits then
-- DONE - make variable
if _distance < self.rescuehoverdistance then
self:T(self.lid .. "[Pickup Debug] Helo hovering close enough ".._lookupKeyHeli)
--check height!
local leaderheight = _woundedLeader:GetHeight()
if leaderheight < 0 then leaderheight = 0 end
@@ -1652,7 +1596,7 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
-- DONE - make variable
if _height <= self.rescuehoverheight then
self:T(self.lid .. "[Pickup Debug] Helo hovering low enough ".._lookupKeyHeli)
local _time = self.hoverStatus[_lookupKeyHeli]
if _time == nil then
@@ -1662,28 +1606,22 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
_time = self.hoverStatus[_lookupKeyHeli] - 10
self.hoverStatus[_lookupKeyHeli] = _time
end
self:T(self.lid .. "[Pickup Debug] Check hover timer ".._lookupKeyHeli)
if _time > 0 then
self:T(self.lid .. "[Pickup Debug] Helo hovering not long enough ".._lookupKeyHeli)
self:_DisplayMessageToSAR(_heliUnit, "Hovering above " .. _pilotName .. ". \n\nHold hover for " .. _time .. " seconds to winch them up. \n\nIf the countdown stops you\'re too far away!", self.messageTime, true)
else
self:T(self.lid .. "[Pickup Debug] Helo hovering long enough - door check ".._lookupKeyHeli)
if self.pilotmustopendoors and (self:_IsLoadingDoorOpen(_heliName) == false) then
self:_DisplayMessageToSAR(_heliUnit, "Open the door to let me in!", self.messageTime, true, true)
self:T(self.lid .. "[Pickup Debug] Door closed, try again next loop ".._lookupKeyHeli)
return false
else
self.hoverStatus[_lookupKeyHeli] = nil
self:_PickupUnit(_heliUnit, _pilotName, _woundedGroup, _woundedGroupName)
self:T(self.lid .. "[Pickup Debug] Pilot picked up ".._lookupKeyHeli)
return true
end
end
_reset = false
else
self:T(self.lid .. "[Pickup Debug] Helo hovering too high ".._lookupKeyHeli)
self:_DisplayMessageToSAR(_heliUnit, "Too high to winch " .. _pilotName .. " \nReduce height and hover for 10 seconds!", self.messageTime, true,true)
self:T(self.lid .. "[Pickup Debug] Hovering too high, try again next loop ".._lookupKeyHeli)
return false
end
end
@@ -1708,8 +1646,7 @@ end
-- @param #string heliname Heli name
-- @param #string groupname Group name
-- @param #boolean isairport If true, EVENT.Landing took place at an airport or FARP
-- @param #boolean noreschedule If true, do not try to reschedule this is distances are not ok (coming from landing event)
function CSAR:_ScheduledSARFlight(heliname,groupname, isairport, noreschedule)
function CSAR:_ScheduledSARFlight(heliname,groupname, isairport)
self:T(self.lid .. " _ScheduledSARFlight")
self:T({heliname,groupname})
local _heliUnit = self:_GetSARHeli(heliname)
@@ -1729,29 +1666,20 @@ function CSAR:_ScheduledSARFlight(heliname,groupname, isairport, noreschedule)
local _dist = self:_GetClosestMASH(_heliUnit)
if _dist == -1 then
self:T(self.lid.."[Drop off debug] Check distance to MASH for "..heliname.." Distance can not be determined!")
return
return
end
self:T(self.lid.."[Drop off debug] Check distance to MASH for "..heliname.." Distance km: "..math.floor(_dist/1000))
if ( _dist < self.FARPRescueDistance or isairport ) and _heliUnit:InAir() == false then
self:T(self.lid.."[Drop off debug] Distance ok, door check")
if self.pilotmustopendoors and self:_IsLoadingDoorOpen(heliname) == false then
self:_DisplayMessageToSAR(_heliUnit, "Open the door to let me out!", self.messageTime, true, true)
self:T(self.lid.."[Drop off debug] Door closed, try again next loop")
else
self:T(self.lid.."[Drop off debug] Rescued!")
self:_RescuePilots(_heliUnit)
return
end
end
--queue up
if not noreschedule then
self:__Returning(5,heliname,_woundedGroupName, isairport)
self:ScheduleOnce(5,self._ScheduledSARFlight,self,heliname,groupname, isairport, noreschedule)
end
self:__Returning(-5,heliname,_woundedGroupName, isairport)
return self
end
@@ -1821,6 +1749,9 @@ function CSAR:_DisplayMessageToSAR(_unit, _text, _time, _clear, _speak, _overrid
end
_text = string.gsub(_text,"km"," kilometer")
_text = string.gsub(_text,"nm"," nautical miles")
--self.msrs:SetVoice(self.SRSVoice)
--self.SRSQueue:NewTransmission(_text,nil,self.msrs,nil,1)
self:I("Voice = "..self.SRSVoice)
self.SRSQueue:NewTransmission(_text,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,self.SRSVoice,volume,label,coord)
end
return self
@@ -1881,11 +1812,11 @@ function CSAR:_DisplayActiveSAR(_unitName)
else
distancetext = string.format("%.1fkm", _distance/1000.0)
end
if _value.frequency == 0 or self.CreateRadioBeacons == false then--shagrat insert CASEVAC without Frequency
table.insert(_csarList, { dist = _distance, msg = string.format("%s at %s - %s ", _value.desc, _coordinatesText, distancetext) })
else
table.insert(_csarList, { dist = _distance, msg = string.format("%s at %s - %.2f KHz ADF - %s ", _value.desc, _coordinatesText, _value.frequency / 1000, distancetext) })
end
if _value.frequency == 0 then--shagrat insert CASEVAC without Frequency
table.insert(_csarList, { dist = _distance, msg = string.format("%s at %s - %s ", _value.desc, _coordinatesText, distancetext) })
else
table.insert(_csarList, { dist = _distance, msg = string.format("%s at %s - %.2f KHz ADF - %s ", _value.desc, _coordinatesText, _value.frequency / 1000, distancetext) })
end
end
end
@@ -1966,7 +1897,7 @@ function CSAR:_SignalFlare(_unitName)
else
_distance = string.format("%.1fkm",_closest.distance/1000)
end
local _msg = string.format("%s - Firing signal flare at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance)
local _msg = string.format("%s - Popping signal flare at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance)
self:_DisplayMessageToSAR(_heli, _msg, self.messageTime, false, true, true)
local _coord = _closest.pilot:GetCoordinate()
@@ -1987,68 +1918,28 @@ end
--- (Internal) Display info to all SAR groups.
-- @param #CSAR self
-- @param #string _message Message to display.
-- @param #number _side Coalition of message.
-- @param #number _side Coalition of message.
-- @param #number _messagetime How long to show.
-- @param #boolean ToSRS If true or nil, send to SRS TTS
-- @param #boolean ToScreen If true or nil, send to Screen
function CSAR:_DisplayToAllSAR(_message, _side, _messagetime,ToSRS,ToScreen)
function CSAR:_DisplayToAllSAR(_message, _side, _messagetime)
self:T(self.lid .. " _DisplayToAllSAR")
local messagetime = _messagetime or self.messageTime
self:T({_message,ToSRS=ToSRS,ToScreen=ToScreen})
if self.msrs and (ToSRS == true or ToSRS == nil) then
if self.msrs then
local voice = self.CSARVoice or MSRS.Voices.Google.Standard.en_GB_Standard_F
if self.msrs:GetProvider() == MSRS.Provider.WINDOWS then
voice = self.CSARVoiceMS or MSRS.Voices.Microsoft.Hedda
end
--self:F("Voice = "..voice)
self:I("Voice = "..voice)
self.SRSQueue:NewTransmission(_message,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,voice,volume,label,self.coordinate)
end
if ToScreen == true or ToScreen == nil then
for _, _unitName in pairs(self.csarUnits) do
local _unit = self:_GetSARHeli(_unitName)
if _unit and not self.suppressmessages then
self:_DisplayMessageToSAR(_unit, _message, _messagetime)
end
for _, _unitName in pairs(self.csarUnits) do
local _unit = self:_GetSARHeli(_unitName)
if _unit and not self.suppressmessages then
self:_DisplayMessageToSAR(_unit, _message, _messagetime)
end
end
return self
end
---(Internal) Request IR Strobe at closest downed pilot.
--@param #CSAR self
--@param #string _unitName Name of the helicopter
function CSAR:_ReqIRStrobe( _unitName )
self:T(self.lid .. " _ReqIRStrobe")
local _heli = self:_GetSARHeli(_unitName)
if _heli == nil then
return
end
local smokedist = 8000
if smokedist < self.approachdist_far then smokedist = self.approachdist_far end
local _closest = self:_GetClosestDownedPilot(_heli)
if _closest ~= nil and _closest.pilot ~= nil and _closest.distance > 0 and _closest.distance < smokedist then
local _clockDir = self:_GetClockDirection(_heli, _closest.pilot)
local _distance = string.format("%.1fkm",_closest.distance/1000)
if _SETTINGS:IsImperial() then
_distance = string.format("%.1fnm",UTILS.MetersToNM(_closest.distance))
else
_distance = string.format("%.1fkm",_closest.distance/1000)
end
local _msg = string.format("%s - IR Strobe active at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance)
self:_DisplayMessageToSAR(_heli, _msg, self.messageTime, false, true, true)
_closest.pilot:NewIRMarker(true,self.IRStrobeRuntime or 300)
else
local _distance = string.format("%.1fkm",smokedist/1000)
if _SETTINGS:IsImperial() then
_distance = string.format("%.1fnm",UTILS.MetersToNM(smokedist))
else
_distance = string.format("%.1fkm",smokedist/1000)
end
self:_DisplayMessageToSAR(_heli, string.format("No Pilots within %s",_distance), self.messageTime, false, false, true)
end
return self
end
---(Internal) Request smoke at closest downed pilot.
--@param #CSAR self
--@param #string _unitName Name of the helicopter
@@ -2089,7 +1980,7 @@ end
--- (Internal) Determine distance to closest MASH.
-- @param #CSAR self
-- @param Wrapper.Unit#UNIT _heli Helicopter #UNIT
-- @return #CSAR self
-- @retunr
function CSAR:_GetClosestMASH(_heli)
self:T(self.lid .. " _GetClosestMASH")
local _mashset = self.mash -- Core.Set#SET_GROUP
@@ -2172,12 +2063,12 @@ function CSAR:_AddMedevacMenuItem()
local coalition = self.coalition
local allheligroupset = self.allheligroupset -- Core.Set#SET_GROUP
local _allHeliGroups = allheligroupset:GetSetObjects()
-- rebuild units table
local _UnitList = {}
for _key, _group in pairs (_allHeliGroups) do
local _unit = _group:GetFirstUnitAlive() -- Asume that there is only one unit in the flight for players
if _unit then
--self:T("Unitname ".._unit:GetName().." IsAlive "..tostring(_unit:IsAlive()).." IsPlayer "..tostring(_unit:IsPlayer()))
local _unit = _group:GetUnit(1) -- Asume that there is only one unit in the flight for players
if _unit then
if _unit:IsAlive() and _unit:IsPlayer() then
local unitName = _unit:GetName()
_UnitList[unitName] = unitName
@@ -2200,12 +2091,7 @@ function CSAR:_AddMedevacMenuItem()
local _rootMenu1 = MENU_GROUP_COMMAND:New(_group,"List Active CSAR",_rootPath, self._DisplayActiveSAR,self,_unitName)
local _rootMenu2 = MENU_GROUP_COMMAND:New(_group,"Check Onboard",_rootPath, self._CheckOnboard,self,_unitName)
local _rootMenu3 = MENU_GROUP_COMMAND:New(_group,"Request Signal Flare",_rootPath, self._SignalFlare,self,_unitName)
local _rootMenu4 = MENU_GROUP_COMMAND:New(_group,"Request Smoke",_rootPath, self._Reqsmoke,self,_unitName)
if self.AllowIRStrobe then
local _rootMenu5 = MENU_GROUP_COMMAND:New(_group,"Request IR Strobe",_rootPath, self._ReqIRStrobe,self,_unitName):Refresh()
else
_rootMenu4:Refresh()
end
local _rootMenu4 = MENU_GROUP_COMMAND:New(_group,"Request Smoke",_rootPath, self._Reqsmoke,self,_unitName):Refresh()
end
end
end
@@ -2296,13 +2182,9 @@ end
-- @param #CSAR self
-- @param Wrapper.Group#GROUP _group Group #GROUP object.
-- @param #number _freq Frequency to use
-- @param #string _name Beacon Name to use
-- @return #CSAR self
function CSAR:_AddBeaconToGroup(_group, _freq, _name)
function CSAR:_AddBeaconToGroup(_group, _freq)
self:T(self.lid .. " _AddBeaconToGroup")
if self.CreateRadioBeacons == false then return end
local _group = _group
if _group == nil then
--return frequency to pool of available
for _i, _current in ipairs(self.UsedVHFFrequencies) do
@@ -2317,35 +2199,31 @@ function CSAR:_AddBeaconToGroup(_group, _freq, _name)
if _group:IsAlive() then
local _radioUnit = _group:GetUnit(1)
if _radioUnit then
local name = _radioUnit:GetName()
local name = _radioUnit:GetName()
local Frequency = _freq -- Freq in Hertz
local name = _radioUnit:GetName()
local Sound = "l10n/DEFAULT/"..self.radioSound
local vec3 = _radioUnit:GetVec3() or _radioUnit:GetPositionVec3() or {x=0,y=0,z=0}
trigger.action.radioTransmission(Sound, vec3, 0, false, Frequency, self.ADFRadioPwr or 1000,_name) -- Beacon in MP only runs for exactly 30secs straight
trigger.action.radioTransmission(Sound, vec3, 0, false, Frequency, self.ADFRadioPwr or 1000,name..math.random(1,10000)) -- Beacon in MP only runs for exactly 30secs straight
end
end
return self
end
--- (Internal) Helper function to (re-)add beacon to downed pilot.
-- @param #CSAR self
-- @return #CSAR self
-- @param #table _args Arguments
function CSAR:_RefreshRadioBeacons()
self:T(self.lid .. " _RefreshRadioBeacons")
if self.CreateRadioBeacons == false then return end
if self:_CountActiveDownedPilots() > 0 then
local PilotTable = self.downedPilots
for _,_pilot in pairs (PilotTable) do
self:T({_pilot.name})
self:T({_pilot})
local pilot = _pilot -- #CSAR.DownedPilot
local group = pilot.group
local frequency = pilot.frequency or 0 -- thanks to @Thrud
local bname = pilot.BeaconName or pilot.name..math.random(1,100000)
trigger.action.stopRadioTransmission(bname)
if group and group:IsAlive() and frequency > 0 then
self:_AddBeaconToGroup(group,frequency,bname)
self:_AddBeaconToGroup(group,frequency)
end
end
end
@@ -2382,16 +2260,6 @@ function CSAR:_ReachedPilotLimit()
end
end
--- User - Function to add onw SET_GROUP Set-up for pilot filtering and assignment.
-- Needs to be set before starting the CSAR instance.
-- @param #CSAR self
-- @param Core.Set#SET_GROUP Set The SET_GROUP object created by the mission designer/user to represent the CSAR pilot groups.
-- @return #CSAR self
function CSAR:SetOwnSetPilotGroups(Set)
self.UserSetGroup = Set
return self
end
------------------------------
--- FSM internal Functions ---
------------------------------
@@ -2413,9 +2281,7 @@ function CSAR:onafterStart(From, Event, To)
self:HandleEvent(EVENTS.PlayerEnterUnit, self._EventHandler)
self:HandleEvent(EVENTS.PilotDead, self._EventHandler)
if self.UserSetGroup then
self.allheligroupset = self.UserSetGroup
elseif self.allowbronco then
if self.allowbronco then
local prefixes = self.csarPrefix or {}
self.allheligroupset = SET_GROUP:New():FilterCoalitions(self.coalitiontxt):FilterPrefixes(prefixes):FilterStart()
elseif self.useprefix then
@@ -2424,9 +2290,7 @@ function CSAR:onafterStart(From, Event, To)
else
self.allheligroupset = SET_GROUP:New():FilterCoalitions(self.coalitiontxt):FilterCategoryHelicopter():FilterStart()
end
self.mash = SET_GROUP:New():FilterCoalitions(self.coalitiontxt):FilterPrefixes(self.mashprefix):FilterStart() -- currently only GROUP objects, maybe support STATICs also?
if not self.coordinate then
local csarhq = self.mash:GetRandom()
if csarhq then
@@ -2636,7 +2500,7 @@ end
-- @param #boolean IsAirport True if heli has landed on an AFB (from event land).
function CSAR:onbeforeReturning(From, Event, To, Heliname, Woundedgroupname, IsAirPort)
self:T({From, Event, To, Heliname, Woundedgroupname})
--self:_ScheduledSARFlight(Heliname,Woundedgroupname, IsAirPort)
self:_ScheduledSARFlight(Heliname,Woundedgroupname, IsAirPort)
return self
end

File diff suppressed because it is too large Load Diff

View File

@@ -660,9 +660,9 @@ function RECOVERYTANKER:SetRecoveryAirboss(switch)
return self
end
--- Set that the group takes the role of an AWACS instead of a refueling tanker.
--- Set that the group takes the roll of an AWACS instead of a refueling tanker.
-- @param #RECOVERYTANKER self
-- @param #boolean switch If true or nil, set role AWACS.
-- @param #boolean switch If true or nil, set roll AWACS.
-- @param #boolean eplrs If true or nil, enable EPLRS. If false, EPLRS will be off.
-- @return #RECOVERYTANKER self
function RECOVERYTANKER:SetAWACS(switch, eplrs)

View File

@@ -1,260 +0,0 @@
--
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.CIRCLE
-- @image MOOSE.JPG
--- CIRCLE class.
-- @type CIRCLE
-- @field #string ClassName Name of the class.
-- @field #number Radius Radius of the circle
--- *It's NOT hip to be square* -- Someone, somewhere, probably
--
-- ===
--
-- # CIRCLE
-- CIRCLEs can be fetched from the drawings in the Mission Editor
---
-- This class has some of the standard CIRCLE functions you'd expect. One function of interest is CIRCLE:PointInSector() that you can use if a point is
-- within a certain sector (pizza slice) of a circle. This can be useful for many things, including rudimentary, "radar-like" searches from a unit.
--
-- CIRCLE class with properties and methods for handling circles.
-- @field #CIRCLE
CIRCLE = {
ClassName = "CIRCLE",
Radius = nil,
}
--- Finds a circle on the map by its name. The circle must have been added in the Mission Editor
-- @param #string shape_name Name of the circle to find
-- @return #CIRCLE The found circle, or nil if not found
function CIRCLE:FindOnMap(shape_name)
local self = BASE:Inherit(self, SHAPE_BASE:FindOnMap(shape_name))
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if string.find(object["name"], shape_name, 1, true) then
if object["polygonMode"] == "circle" then
self.Radius = object["radius"]
end
end
end
end
return self
end
--- Finds a circle by its name in the database.
-- @param #string shape_name Name of the circle to find
-- @return #CIRCLE The found circle, or nil if not found
function CIRCLE:Find(shape_name)
return _DATABASE:FindShape(shape_name)
end
--- Creates a new circle from a center point and a radius.
-- @param #table vec2 The center point of the circle
-- @param #number radius The radius of the circle
-- @return #CIRCLE The new circle
function CIRCLE:New(vec2, radius)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.CenterVec2 = vec2
self.Radius = radius
return self
end
--- Gets the radius of the circle.
-- @return #number The radius of the circle
function CIRCLE:GetRadius()
return self.Radius
end
--- Checks if a point is contained within the circle.
-- @param #table point The point to check
-- @return #bool True if the point is contained, false otherwise
function CIRCLE:ContainsPoint(point)
if ((point.x - self.CenterVec2.x) ^ 2 + (point.y - self.CenterVec2.y) ^ 2) ^ 0.5 <= self.Radius then
return true
end
return false
end
--- Checks if a point is contained within a sector of the circle. The start and end sector need to be clockwise
-- @param #table point The point to check
-- @param #table sector_start The start point of the sector
-- @param #table sector_end The end point of the sector
-- @param #table center The center point of the sector
-- @param #number radius The radius of the sector
-- @return #bool True if the point is contained, false otherwise
function CIRCLE:PointInSector(point, sector_start, sector_end, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
local function are_clockwise(v1, v2)
return -v1.x * v2.y + v1.y * v2.x > 0
end
local function is_in_radius(rp)
return rp.x * rp.x + rp.y * rp.y <= radius ^ 2
end
local rel_pt = {
x = point.x - center.x,
y = point.y - center.y
}
local rel_sector_start = {
x = sector_start.x - center.x,
y = sector_start.y - center.y,
}
local rel_sector_end = {
x = sector_end.x - center.x,
y = sector_end.y - center.y,
}
return not are_clockwise(rel_sector_start, rel_pt) and
are_clockwise(rel_sector_end, rel_pt) and
is_in_radius(rel_pt, radius)
end
--- Checks if a unit is contained within a sector of the circle. The start and end sector need to be clockwise
-- @param #string unit_name The name of the unit to check
-- @param #table sector_start The start point of the sector
-- @param #table sector_end The end point of the sector
-- @param #table center The center point of the sector
-- @param #number radius The radius of the sector
-- @return #bool True if the unit is contained, false otherwise
function CIRCLE:UnitInSector(unit_name, sector_start, sector_end, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
if self:PointInSector(UNIT:FindByName(unit_name):GetVec2(), sector_start, sector_end, center, radius) then
return true
end
return false
end
--- Checks if any unit of a group is contained within a sector of the circle. The start and end sector need to be clockwise
-- @param #string group_name The name of the group to check
-- @param #table sector_start The start point of the sector
-- @param #table sector_end The end point of the sector
-- @param #table center The center point of the sector
-- @param #number radius The radius of the sector
-- @return #bool True if any unit of the group is contained, false otherwise
function CIRCLE:AnyOfGroupInSector(group_name, sector_start, sector_end, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
for _, unit in pairs(GROUP:FindByName(group_name):GetUnits()) do
if self:PointInSector(unit:GetVec2(), sector_start, sector_end, center, radius) then
return true
end
end
return false
end
--- Checks if all units of a group are contained within a sector of the circle. The start and end sector need to be clockwise
-- @param #string group_name The name of the group to check
-- @param #table sector_start The start point of the sector
-- @param #table sector_end The end point of the sector
-- @param #table center The center point of the sector
-- @param #number radius The radius of the sector
-- @return #bool True if all units of the group are contained, false otherwise
function CIRCLE:AllOfGroupInSector(group_name, sector_start, sector_end, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
for _, unit in pairs(GROUP:FindByName(group_name):GetUnits()) do
if not self:PointInSector(unit:GetVec2(), sector_start, sector_end, center, radius) then
return false
end
end
return true
end
--- Checks if a unit is contained within a radius of the circle.
-- @param #string unit_name The name of the unit to check
-- @param #table center The center point of the radius
-- @param #number radius The radius to check
-- @return #bool True if the unit is contained, false otherwise
function CIRCLE:UnitInRadius(unit_name, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
if UTILS.IsInRadius(center, UNIT:FindByName(unit_name):GetVec2(), radius) then
return true
end
return false
end
--- Checks if any unit of a group is contained within a radius of the circle.
-- @param #string group_name The name of the group to check
-- @param #table center The center point of the radius
-- @param #number radius The radius to check
-- @return #bool True if any unit of the group is contained, false otherwise
function CIRCLE:AnyOfGroupInRadius(group_name, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
for _, unit in pairs(GROUP:FindByName(group_name):GetUnits()) do
if UTILS.IsInRadius(center, unit:GetVec2(), radius) then
return true
end
end
return false
end
--- Checks if all units of a group are contained within a radius of the circle.
-- @param #string group_name The name of the group to check
-- @param #table center The center point of the radius
-- @param #number radius The radius to check
-- @return #bool True if all units of the group are contained, false otherwise
function CIRCLE:AllOfGroupInRadius(group_name, center, radius)
center = center or self.CenterVec2
radius = radius or self.Radius
for _, unit in pairs(GROUP:FindByName(group_name):GetUnits()) do
if not UTILS.IsInRadius(center, unit:GetVec2(), radius) then
return false
end
end
return true
end
--- Returns a random Vec2 within the circle.
-- @return #table The random Vec2
function CIRCLE:GetRandomVec2()
local angle = math.random() * 2 * math.pi
local rx = math.random(0, self.Radius) * math.cos(angle) + self.CenterVec2.x
local ry = math.random(0, self.Radius) * math.sin(angle) + self.CenterVec2.y
return {x=rx, y=ry}
end
--- Returns a random Vec2 on the border of the circle.
-- @return #table The random Vec2
function CIRCLE:GetRandomVec2OnBorder()
local angle = math.random() * 2 * math.pi
local rx = self.Radius * math.cos(angle) + self.CenterVec2.x
local ry = self.Radius * math.sin(angle) + self.CenterVec2.y
return {x=rx, y=ry}
end
--- Calculates the bounding box of the circle. The bounding box is the smallest rectangle that contains the circle.
-- @return #table The bounding box of the circle
function CIRCLE:GetBoundingBox()
local min_x = self.CenterVec2.x - self.Radius
local min_y = self.CenterVec2.y - self.Radius
local max_x = self.CenterVec2.x + self.Radius
local max_y = self.CenterVec2.y + self.Radius
return {
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
}
end

View File

@@ -1,85 +0,0 @@
---
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.CUBE
-- @image MOOSE.JPG
--- LINE class.
-- @type CUBE
-- @field #string ClassName Name of the class.
-- @field #number Points points of the line
-- @field #number Coords coordinates of the line
--
-- ===
---
-- @field #CUBE
CUBE = {
ClassName = "CUBE",
Points = {},
Coords = {}
}
--- Points need to be added in the following order:
--- p1 -> p4 make up the front face of the cube
--- p5 -> p8 make up the back face of the cube
--- p1 connects to p5
--- p2 connects to p6
--- p3 connects to p7
--- p4 connects to p8
---
--- 8-----------7
--- /| /|
--- / | / |
--- 4--+--------3 |
--- | | | |
--- | | | |
--- | | | |
--- | 5--------+--6
--- | / | /
--- |/ |/
--- 1-----------2
---
function CUBE:New(p1, p2, p3, p4, p5, p6, p7, p8)
local self = BASE:Inherit(self, SHAPE_BASE)
self.Points = {p1, p2, p3, p4, p5, p6, p7, p8}
for _, point in spairs(self.Points) do
table.insert(self.Coords, COORDINATE:NewFromVec3(point))
end
return self
end
function CUBE:GetCenter()
local center = { x=0, y=0, z=0 }
for _, point in pairs(self.Points) do
center.x = center.x + point.x
center.y = center.y + point.y
center.z = center.z + point.z
end
center.x = center.x / 8
center.y = center.y / 8
center.z = center.z / 8
return center
end
function CUBE:ContainsPoint(point, cube_points)
cube_points = cube_points or self.Points
local min_x, min_y, min_z = math.huge, math.huge, math.huge
local max_x, max_y, max_z = -math.huge, -math.huge, -math.huge
-- Find the minimum and maximum x, y, and z values of the cube points
for _, p in ipairs(cube_points) do
if p.x < min_x then min_x = p.x end
if p.y < min_y then min_y = p.y end
if p.z < min_z then min_z = p.z end
if p.x > max_x then max_x = p.x end
if p.y > max_y then max_y = p.y end
if p.z > max_z then max_z = p.z end
end
return point.x >= min_x and point.x <= max_x and point.y >= min_y and point.y <= max_y and point.z >= min_z and point.z <= max_z
end

View File

@@ -1,333 +0,0 @@
---
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.LINE
-- @image MOOSE.JPG
--- LINE class.
-- @type LINE
-- @field #string ClassName Name of the class.
-- @field #number Points points of the line
-- @field #number Coords coordinates of the line
--
-- ===
---
-- @field #LINE
LINE = {
ClassName = "LINE",
Points = {},
Coords = {},
}
--- Finds a line on the map by its name. The line must be drawn in the Mission Editor
-- @param #string line_name Name of the line to find
-- @return #LINE The found line, or nil if not found
function LINE:FindOnMap(line_name)
local self = BASE:Inherit(self, SHAPE_BASE:FindOnMap(line_name))
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if object["name"] == line_name then
if object["primitiveType"] == "Line" then
for _, point in UTILS.spairs(object["points"]) do
local p = {x = object["mapX"] + point["x"],
y = object["mapY"] + point["y"] }
local coord = COORDINATE:NewFromVec2(p)
table.insert(self.Points, p)
table.insert(self.Coords, coord)
end
end
end
end
end
self:I(#self.Points)
if #self.Points == 0 then
return nil
end
self.MarkIDs = {}
return self
end
--- Finds a line by its name in the database.
-- @param #string shape_name Name of the line to find
-- @return #LINE The found line, or nil if not found
function LINE:Find(shape_name)
return _DATABASE:FindShape(shape_name)
end
--- Creates a new line from two points.
-- @param #table vec2 The first point of the line
-- @param #number radius The second point of the line
-- @return #LINE The new line
function LINE:New(...)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.Points = {...}
self:I(self.Points)
for _, point in UTILS.spairs(self.Points) do
table.insert(self.Coords, COORDINATE:NewFromVec2(point))
end
return self
end
--- Creates a new line from a circle.
-- @param #table center_point center point of the circle
-- @param #number radius radius of the circle, half length of the line
-- @param #number angle_degrees degrees the line will form from center point
-- @return #LINE The new line
function LINE:NewFromCircle(center_point, radius, angle_degrees)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.CenterVec2 = center_point
local angleRadians = math.rad(angle_degrees)
local point1 = {
x = center_point.x + radius * math.cos(angleRadians),
y = center_point.y + radius * math.sin(angleRadians)
}
local point2 = {
x = center_point.x + radius * math.cos(angleRadians + math.pi),
y = center_point.y + radius * math.sin(angleRadians + math.pi)
}
for _, point in pairs{point1, point2} do
table.insert(self.Points, point)
table.insert(self.Coords, COORDINATE:NewFromVec2(point))
end
return self
end
--- Gets the coordinates of the line.
-- @return #table The coordinates of the line
function LINE:Coordinates()
return self.Coords
end
--- Gets the start coordinate of the line. The start coordinate is the first point of the line.
-- @return #COORDINATE The start coordinate of the line
function LINE:GetStartCoordinate()
return self.Coords[1]
end
--- Gets the end coordinate of the line. The end coordinate is the last point of the line.
-- @return #COORDINATE The end coordinate of the line
function LINE:GetEndCoordinate()
return self.Coords[#self.Coords]
end
--- Gets the start point of the line. The start point is the first point of the line.
-- @return #table The start point of the line
function LINE:GetStartPoint()
return self.Points[1]
end
--- Gets the end point of the line. The end point is the last point of the line.
-- @return #table The end point of the line
function LINE:GetEndPoint()
return self.Points[#self.Points]
end
--- Gets the length of the line.
-- @return #number The length of the line
function LINE:GetLength()
local total_length = 0
for i=1, #self.Points - 1 do
local x1, y1 = self.Points[i]["x"], self.Points[i]["y"]
local x2, y2 = self.Points[i+1]["x"], self.Points[i+1]["y"]
local segment_length = math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
total_length = total_length + segment_length
end
return total_length
end
--- Returns a random point on the line.
-- @param #table points (optional) The points of the line or 2 other points if you're just using the LINE class without an object of it
-- @return #table The random point
function LINE:GetRandomPoint(points)
points = points or self.Points
local rand = math.random() -- 0->1
local random_x = points[1].x + rand * (points[2].x - points[1].x)
local random_y = points[1].y + rand * (points[2].y - points[1].y)
return { x= random_x, y= random_y }
end
--- Gets the heading of the line.
-- @param #table points (optional) The points of the line or 2 other points if you're just using the LINE class without an object of it
-- @return #number The heading of the line
function LINE:GetHeading(points)
points = points or self.Points
local angle = math.atan2(points[2].y - points[1].y, points[2].x - points[1].x)
angle = math.deg(angle)
if angle < 0 then
angle = angle + 360
end
return angle
end
--- Return each part of the line as a new line
-- @return #table The points
function LINE:GetIndividualParts()
local parts = {}
if #self.Points == 2 then
parts = {self}
end
for i=1, #self.Points -1 do
local p1 = self.Points[i]
local p2 = self.Points[i % #self.Points + 1]
table.add(parts, LINE:New(p1, p2))
end
return parts
end
--- Gets a number of points in between the start and end points of the line.
-- @param #number amount The number of points to get
-- @param #table start_point (Optional) The start point of the line, defaults to the object's start point
-- @param #table end_point (Optional) The end point of the line, defaults to the object's end point
-- @return #table The points
function LINE:GetPointsInbetween(amount, start_point, end_point)
start_point = start_point or self:GetStartPoint()
end_point = end_point or self:GetEndPoint()
if amount == 0 then return {start_point, end_point} end
amount = amount + 1
local points = {}
local difference = { x = end_point.x - start_point.x, y = end_point.y - start_point.y }
local divided = { x = difference.x / amount, y = difference.y / amount }
for j=0, amount do
local part_pos = {x = divided.x * j, y = divided.y * j}
-- add part_pos vector to the start point so the new point is placed along in the line
local point = {x = start_point.x + part_pos.x, y = start_point.y + part_pos.y}
table.insert(points, point)
end
return points
end
--- Gets a number of points in between the start and end points of the line.
-- @param #number amount The number of points to get
-- @param #table start_point (Optional) The start point of the line, defaults to the object's start point
-- @param #table end_point (Optional) The end point of the line, defaults to the object's end point
-- @return #table The points
function LINE:GetCoordinatesInBetween(amount, start_point, end_point)
local coords = {}
for _, pt in pairs(self:GetPointsInbetween(amount, start_point, end_point)) do
table.add(coords, COORDINATE:NewFromVec2(pt))
end
return coords
end
function LINE:GetRandomPoint(start_point, end_point)
start_point = start_point or self:GetStartPoint()
end_point = end_point or self:GetEndPoint()
local fraction = math.random()
local difference = { x = end_point.x - start_point.x, y = end_point.y - start_point.y }
local part_pos = {x = difference.x * fraction, y = difference.y * fraction}
local random_point = { x = start_point.x + part_pos.x, y = start_point.y + part_pos.y}
return random_point
end
function LINE:GetRandomCoordinate(start_point, end_point)
start_point = start_point or self:GetStartPoint()
end_point = end_point or self:GetEndPoint()
return COORDINATE:NewFromVec2(self:GetRandomPoint(start_point, end_point))
end
--- Gets a number of points on a sine wave between the start and end points of the line.
-- @param #number amount The number of points to get
-- @param #table start_point (Optional) The start point of the line, defaults to the object's start point
-- @param #table end_point (Optional) The end point of the line, defaults to the object's end point
-- @param #number frequency (Optional) The frequency of the sine wave, default 1
-- @param #number phase (Optional) The phase of the sine wave, default 0
-- @param #number amplitude (Optional) The amplitude of the sine wave, default 100
-- @return #table The points
function LINE:GetPointsBetweenAsSineWave(amount, start_point, end_point, frequency, phase, amplitude)
amount = amount or 20
start_point = start_point or self:GetStartPoint()
end_point = end_point or self:GetEndPoint()
frequency = frequency or 1 -- number of cycles per unit of x
phase = phase or 0 -- offset in radians
amplitude = amplitude or 100 -- maximum height of the wave
local points = {}
-- Returns the y-coordinate of the sine wave at x
local function sine_wave(x)
return amplitude * math.sin(2 * math.pi * frequency * (x - start_point.x) + phase)
end
-- Plot x-amount of points on the sine wave between point_01 and point_02
local x = start_point.x
local step = (end_point.x - start_point.x) / 20
for _=1, amount do
local y = sine_wave(x)
x = x + step
table.add(points, {x=x, y=y})
end
return points
end
--- Calculates the bounding box of the line. The bounding box is the smallest rectangle that contains the line.
-- @return #table The bounding box of the line
function LINE:GetBoundingBox()
local min_x, min_y, max_x, max_y = self.Points[1].x, self.Points[1].y, self.Points[2].x, self.Points[2].y
for i = 2, #self.Points do
local x, y = self.Points[i].x, self.Points[i].y
if x < min_x then
min_x = x
end
if y < min_y then
min_y = y
end
if x > max_x then
max_x = x
end
if y > max_y then
max_y = y
end
end
return {
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
}
end
--- Draws the line on the map.
-- @param #table points The points of the line
function LINE:Draw()
for i=1, #self.Coords -1 do
local c1 = self.Coords[i]
local c2 = self.Coords[i % #self.Coords + 1]
table.add(self.MarkIDs, c1:LineToAll(c2))
end
end
--- Removes the drawing of the line from the map.
function LINE:RemoveDraw()
for _, mark_id in pairs(self.MarkIDs) do
UTILS.RemoveMark(mark_id)
end
end

View File

@@ -1,213 +0,0 @@
---
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.OVAL
-- @image MOOSE.JPG
--- OVAL class.
-- @type OVAL
-- @field #string ClassName Name of the class.
-- @field #number MajorAxis The major axis (radius) of the oval
-- @field #number MinorAxis The minor axis (radius) of the oval
-- @field #number Angle The angle the oval is rotated on
--- *The little man removed his hat, what an egg shaped head he had* -- Agatha Christie
--
-- ===
--
-- # OVAL
-- OVALs can be fetched from the drawings in the Mission Editor
--
-- The major and minor axes define how elongated the shape of an oval is. This class has some basic functions that the other SHAPE classes have as well.
-- Since it's not possible to draw the shape of an oval while the mission is running, right now the draw function draws 2 cicles. One with the major axis and one with
-- the minor axis. It then draws a diamond shape on an angle where the corners touch the major and minor axes to give an indication of what the oval actually
-- looks like.
--
-- Using ovals can be handy to find an area on the ground that is actually an intersection of a cone and a plane. So imagine you're faking the view cone of
-- a targeting pod and
--- OVAL class with properties and methods for handling ovals.
-- @field #OVAL
OVAL = {
ClassName = "OVAL",
MajorAxis = nil,
MinorAxis = nil,
Angle = 0,
DrawPoly=nil
}
--- Finds an oval on the map by its name. The oval must be drawn on the map.
-- @param #string shape_name Name of the oval to find
-- @return #OVAL The found oval, or nil if not found
function OVAL:FindOnMap(shape_name)
local self = BASE:Inherit(self, SHAPE_BASE:FindOnMap(shape_name))
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if string.find(object["name"], shape_name, 1, true) then
if object["polygonMode"] == "oval" then
self.CenterVec2 = { x = object["mapX"], y = object["mapY"] }
self.MajorAxis = object["r1"]
self.MinorAxis = object["r2"]
self.Angle = object["angle"]
end
end
end
end
return self
end
--- Finds an oval by its name in the database.
-- @param #string shape_name Name of the oval to find
-- @return #OVAL The found oval, or nil if not found
function OVAL:Find(shape_name)
return _DATABASE:FindShape(shape_name)
end
--- Creates a new oval from a center point, major axis, minor axis, and angle.
-- @param #table vec2 The center point of the oval
-- @param #number major_axis The major axis of the oval
-- @param #number minor_axis The minor axis of the oval
-- @param #number angle The angle of the oval
-- @return #OVAL The new oval
function OVAL:New(vec2, major_axis, minor_axis, angle)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.CenterVec2 = vec2
self.MajorAxis = major_axis
self.MinorAxis = minor_axis
self.Angle = angle or 0
return self
end
--- Gets the major axis of the oval.
-- @return #number The major axis of the oval
function OVAL:GetMajorAxis()
return self.MajorAxis
end
--- Gets the minor axis of the oval.
-- @return #number The minor axis of the oval
function OVAL:GetMinorAxis()
return self.MinorAxis
end
--- Gets the angle of the oval.
-- @return #number The angle of the oval
function OVAL:GetAngle()
return self.Angle
end
--- Sets the major axis of the oval.
-- @param #number value The new major axis
function OVAL:SetMajorAxis(value)
self.MajorAxis = value
end
--- Sets the minor axis of the oval.
-- @param #number value The new minor axis
function OVAL:SetMinorAxis(value)
self.MinorAxis = value
end
--- Sets the angle of the oval.
-- @param #number value The new angle
function OVAL:SetAngle(value)
self.Angle = value
end
--- Checks if a point is contained within the oval.
-- @param #table point The point to check
-- @return #bool True if the point is contained, false otherwise
function OVAL:ContainsPoint(point)
local cos, sin = math.cos, math.sin
local dx = point.x - self.CenterVec2.x
local dy = point.y - self.CenterVec2.y
local rx = dx * cos(self.Angle) + dy * sin(self.Angle)
local ry = -dx * sin(self.Angle) + dy * cos(self.Angle)
return rx * rx / (self.MajorAxis * self.MajorAxis) + ry * ry / (self.MinorAxis * self.MinorAxis) <= 1
end
--- Returns a random Vec2 within the oval.
-- @return #table The random Vec2
function OVAL:GetRandomVec2()
local theta = math.rad(self.Angle)
local random_point = math.sqrt(math.random()) --> uniformly
--local random_point = math.random() --> more clumped around center
local phi = math.random() * 2 * math.pi
local x_c = random_point * math.cos(phi)
local y_c = random_point * math.sin(phi)
local x_e = x_c * self.MajorAxis
local y_e = y_c * self.MinorAxis
local rx = (x_e * math.cos(theta) - y_e * math.sin(theta)) + self.CenterVec2.x
local ry = (x_e * math.sin(theta) + y_e * math.cos(theta)) + self.CenterVec2.y
return {x=rx, y=ry}
end
--- Calculates the bounding box of the oval. The bounding box is the smallest rectangle that contains the oval.
-- @return #table The bounding box of the oval
function OVAL:GetBoundingBox()
local min_x = self.CenterVec2.x - self.MajorAxis
local min_y = self.CenterVec2.y - self.MinorAxis
local max_x = self.CenterVec2.x + self.MajorAxis
local max_y = self.CenterVec2.y + self.MinorAxis
return {
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
}
end
--- Draws the oval on the map, for debugging
-- @param #number angle (Optional) The angle of the oval. If nil will use self.Angle
function OVAL:Draw()
--for pt in pairs(self:PointsOnEdge(20)) do
-- COORDINATE:NewFromVec2(pt)
--end
self.DrawPoly = POLYGON:NewFromPoints(self:PointsOnEdge(20))
self.DrawPoly:Draw(true)
---- TODO: draw a better shape using line segments
--angle = angle or self.Angle
--local coor = self:GetCenterCoordinate()
--
--table.add(self.MarkIDs, coor:CircleToAll(self.MajorAxis))
--table.add(self.MarkIDs, coor:CircleToAll(self.MinorAxis))
--table.add(self.MarkIDs, coor:LineToAll(coor:Translate(self.MajorAxis, self.Angle)))
--
--local pt_1 = coor:Translate(self.MajorAxis, self.Angle)
--local pt_2 = coor:Translate(self.MinorAxis, self.Angle - 90)
--local pt_3 = coor:Translate(self.MajorAxis, self.Angle - 180)
--local pt_4 = coor:Translate(self.MinorAxis, self.Angle - 270)
--table.add(self.MarkIDs, pt_1:QuadToAll(pt_2, pt_3, pt_4), -1, {0, 1, 0}, 1, {0, 1, 0})
end
--- Removes the drawing of the oval from the map
function OVAL:RemoveDraw()
self.DrawPoly:RemoveDraw()
end
function OVAL:PointsOnEdge(num_points)
num_points = num_points or 20
local points = {}
local dtheta = 2 * math.pi / num_points
for i = 0, num_points - 1 do
local theta = i * dtheta
local x = self.CenterVec2.x + self.MajorAxis * math.cos(theta) * math.cos(self.Angle) - self.MinorAxis * math.sin(theta) * math.sin(self.Angle)
local y = self.CenterVec2.y + self.MajorAxis * math.cos(theta) * math.sin(self.Angle) + self.MinorAxis * math.sin(theta) * math.cos(self.Angle)
table.insert(points, {x = x, y = y})
end
return points
end

View File

@@ -1,458 +0,0 @@
---
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.POLYGON
-- @image MOOSE.JPG
--- POLYGON class.
-- @type POLYGON
-- @field #string ClassName Name of the class.
-- @field #table Points List of 3D points defining the shape, this will be assigned automatically if you're passing in a drawing from the Mission Editor
-- @field #table Coords List of COORDINATE defining the path, this will be assigned automatically if you're passing in a drawing from the Mission Editor
-- @field #table MarkIDs List any MARKIDs this class use, this will be assigned automatically if you're passing in a drawing from the Mission Editor
-- @field #table Triangles List of TRIANGLEs that make up the shape of the POLYGON after being triangulated
-- @extends Core.Base#BASE
--- *Polygons are fashionable at the moment* -- Trip Hawkins
--
-- ===
--
-- # POLYGON
-- POLYGONs can be fetched from the drawings in the Mission Editor if the drawing is:
-- * A closed shape made with line segments
-- * A closed shape made with a freehand line
-- * A freehand drawn polygon
-- * A rect
-- Use the POLYGON:FindOnMap() of POLYGON:Find() functions for this. You can also create a non existing polygon in memory using the POLYGON:New() function. Pass in a
-- any number of Vec2s into this function to define the shape of the polygon you want.
--
-- You can draw very intricate and complex polygons in the Mission Editor to avoid (or include) map objects. You can then generate random points within this complex
-- shape for spawning groups or checking positions.
--
-- When a POLYGON is made, it's automatically triangulated. The resulting triangles are stored in POLYGON.Triangles. This also immeadiately saves the surface area
-- of the POLYGON. Because the POLYGON is triangulated, it's possible to generate random points within this POLYGON without having to use a trial and error method to see if
-- the point is contained within the shape.
-- Using POLYGON:GetRandomVec2() will result in a truly, non-biased, random Vec2 within the shape. You'll want to use this function most. There's also POLYGON:GetRandomNonWeightedVec2
-- which ignores the size of the triangles in the polygon to pick a random points. This will result in more points clumping together in parts of the polygon where the triangles are
-- the smallest.
---
-- @field #POLYGON
POLYGON = {
ClassName = "POLYGON",
Points = {},
Coords = {},
Triangles = {},
SurfaceArea = 0,
TriangleMarkIDs = {},
OutlineMarkIDs = {},
Angle = nil, -- for arrows
Heading = nil -- for arrows
}
--- Finds a polygon on the map by its name. The polygon must be added in the mission editor.
-- @param #string shape_name Name of the polygon to find
-- @return #POLYGON The found polygon, or nil if not found
function POLYGON:FindOnMap(shape_name)
local self = BASE:Inherit(self, SHAPE_BASE:FindOnMap(shape_name))
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if object["name"] == shape_name then
if (object["primitiveType"] == "Line" and object["closed"] == true) or (object["polygonMode"] == "free") then
for _, point in UTILS.spairs(object["points"]) do
local p = {x = object["mapX"] + point["x"],
y = object["mapY"] + point["y"] }
local coord = COORDINATE:NewFromVec2(p)
self.Points[#self.Points + 1] = p
self.Coords[#self.Coords + 1] = coord
end
elseif object["polygonMode"] == "rect" then
local angle = object["angle"]
local half_width = object["width"] / 2
local half_height = object["height"] / 2
local p1 = UTILS.RotatePointAroundPivot({ x = self.CenterVec2.x - half_height, y = self.CenterVec2.y + half_width }, self.CenterVec2, angle)
local p2 = UTILS.RotatePointAroundPivot({ x = self.CenterVec2.x + half_height, y = self.CenterVec2.y + half_width }, self.CenterVec2, angle)
local p3 = UTILS.RotatePointAroundPivot({ x = self.CenterVec2.x + half_height, y = self.CenterVec2.y - half_width }, self.CenterVec2, angle)
local p4 = UTILS.RotatePointAroundPivot({ x = self.CenterVec2.x - half_height, y = self.CenterVec2.y - half_width }, self.CenterVec2, angle)
self.Points = {p1, p2, p3, p4}
for _, point in pairs(self.Points) do
self.Coords[#self.Coords + 1] = COORDINATE:NewFromVec2(point)
end
elseif object["polygonMode"] == "arrow" then
for _, point in UTILS.spairs(object["points"]) do
local p = {x = object["mapX"] + point["x"],
y = object["mapY"] + point["y"] }
local coord = COORDINATE:NewFromVec2(p)
self.Points[#self.Points + 1] = p
self.Coords[#self.Coords + 1] = coord
end
self.Angle = object["angle"]
self.Heading = UTILS.ClampAngle(self.Angle + 90)
end
end
end
end
if #self.Points == 0 then
return nil
end
self.CenterVec2 = self:GetCentroid()
self.Triangles = self:Triangulate()
self.SurfaceArea = self:__CalculateSurfaceArea()
self.TriangleMarkIDs = {}
self.OutlineMarkIDs = {}
return self
end
--- Creates a polygon from a zone. The zone must be defined in the mission.
-- @param #string zone_name Name of the zone
-- @return #POLYGON The polygon created from the zone, or nil if the zone is not found
function POLYGON:FromZone(zone_name)
for _, zone in pairs(env.mission.triggers.zones) do
if zone["name"] == zone_name then
return POLYGON:New(unpack(zone["verticies"] or {}))
end
end
end
--- Finds a polygon by its name in the database.
-- @param #string shape_name Name of the polygon to find
-- @return #POLYGON The found polygon, or nil if not found
function POLYGON:Find(shape_name)
return _DATABASE:FindShape(shape_name)
end
--- Creates a new polygon from a list of points. Each point is a table with 'x' and 'y' fields.
-- @param #table ... Points of the polygon
-- @return #POLYGON The new polygon
function POLYGON:New(...)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.Points = {...}
self.Coords = {}
for _, point in UTILS.spairs(self.Points) do
table.insert(self.Coords, COORDINATE:NewFromVec2(point))
end
self.Triangles = self:Triangulate()
self.SurfaceArea = self:__CalculateSurfaceArea()
return self
end
--- Calculates the centroid of the polygon. The centroid is the average of the 'x' and 'y' coordinates of the points.
-- @return #table The centroid of the polygon
function POLYGON:GetCentroid()
local function sum(t)
local total = 0
for _, value in pairs(t) do
total = total + value
end
return total
end
local x_values = {}
local y_values = {}
local length = table.length(self.Points)
for _, point in pairs(self.Points) do
table.insert(x_values, point.x)
table.insert(y_values, point.y)
end
local x = sum(x_values) / length
local y = sum(y_values) / length
return {
["x"] = x,
["y"] = y
}
end
--- Returns the coordinates of the polygon. Each coordinate is a COORDINATE object.
-- @return #table The coordinates of the polygon
function POLYGON:GetCoordinates()
return self.Coords
end
--- Returns the start coordinate of the polygon. The start coordinate is the first point of the polygon.
-- @return #COORDINATE The start coordinate of the polygon
function POLYGON:GetStartCoordinate()
return self.Coords[1]
end
--- Returns the end coordinate of the polygon. The end coordinate is the last point of the polygon.
-- @return #COORDINATE The end coordinate of the polygon
function POLYGON:GetEndCoordinate()
return self.Coords[#self.Coords]
end
--- Returns the start point of the polygon. The start point is the first point of the polygon.
-- @return #table The start point of the polygon
function POLYGON:GetStartPoint()
return self.Points[1]
end
--- Returns the end point of the polygon. The end point is the last point of the polygon.
-- @return #table The end point of the polygon
function POLYGON:GetEndPoint()
return self.Points[#self.Points]
end
--- Returns the points of the polygon. Each point is a table with 'x' and 'y' fields.
-- @return #table The points of the polygon
function POLYGON:GetPoints()
return self.Points
end
--- Calculates the surface area of the polygon. The surface area is the sum of the areas of the triangles that make up the polygon.
-- @return #number The surface area of the polygon
function POLYGON:GetSurfaceArea()
return self.SurfaceArea
end
--- Calculates the bounding box of the polygon. The bounding box is the smallest rectangle that contains the polygon.
-- @return #table The bounding box of the polygon
function POLYGON:GetBoundingBox()
local min_x, min_y, max_x, max_y = self.Points[1].x, self.Points[1].y, self.Points[1].x, self.Points[1].y
for i = 2, #self.Points do
local x, y = self.Points[i].x, self.Points[i].y
if x < min_x then
min_x = x
end
if y < min_y then
min_y = y
end
if x > max_x then
max_x = x
end
if y > max_y then
max_y = y
end
end
return {
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
}
end
--- Triangulates the polygon. The polygon is divided into triangles.
-- @param #table points (optional) Points of the polygon or other points if you're just using the POLYGON class without an object of it
-- @return #table The triangles of the polygon
function POLYGON:Triangulate(points)
points = points or self.Points
local triangles = {}
local function get_orientation(shape_points)
local sum = 0
for i = 1, #shape_points do
local j = i % #shape_points + 1
sum = sum + (shape_points[j].x - shape_points[i].x) * (shape_points[j].y + shape_points[i].y)
end
return sum >= 0 and "clockwise" or "counter-clockwise" -- sum >= 0, return "clockwise", else return "counter-clockwise"
end
local function ensure_clockwise(shape_points)
local orientation = get_orientation(shape_points)
if orientation == "counter-clockwise" then
-- Reverse the order of shape_points so they're clockwise
local reversed = {}
for i = #shape_points, 1, -1 do
table.insert(reversed, shape_points[i])
end
return reversed
end
return shape_points
end
local function is_clockwise(p1, p2, p3)
local cross_product = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x)
return cross_product < 0
end
local function divide_recursively(shape_points)
if #shape_points == 3 then
table.insert(triangles, TRIANGLE:New(shape_points[1], shape_points[2], shape_points[3]))
elseif #shape_points > 3 then -- find an ear -> a triangle with no other points inside it
for i, p1 in ipairs(shape_points) do
local p2 = shape_points[(i % #shape_points) + 1]
local p3 = shape_points[(i + 1) % #shape_points + 1]
local triangle = TRIANGLE:New(p1, p2, p3)
local is_ear = true
if not is_clockwise(p1, p2, p3) then
is_ear = false
else
for _, point in ipairs(shape_points) do
if point ~= p1 and point ~= p2 and point ~= p3 and triangle:ContainsPoint(point) then
is_ear = false
break
end
end
end
if is_ear then
-- Check if any point in the original polygon is inside the ear triangle
local is_valid_triangle = true
for _, point in ipairs(points) do
if point ~= p1 and point ~= p2 and point ~= p3 and triangle:ContainsPoint(point) then
is_valid_triangle = false
break
end
end
if is_valid_triangle then
table.insert(triangles, triangle)
local remaining_points = {}
for j, point in ipairs(shape_points) do
if point ~= p2 then
table.insert(remaining_points, point)
end
end
divide_recursively(remaining_points)
break
end
end
end
end
end
points = ensure_clockwise(points)
divide_recursively(points)
return triangles
end
function POLYGON:CovarianceMatrix()
local cx, cy = self:GetCentroid()
local covXX, covYY, covXY = 0, 0, 0
for _, p in ipairs(self.points) do
covXX = covXX + (p.x - cx)^2
covYY = covYY + (p.y - cy)^2
covXY = covXY + (p.x - cx) * (p.y - cy)
end
covXX = covXX / (#self.points - 1)
covYY = covYY / (#self.points - 1)
covXY = covXY / (#self.points - 1)
return covXX, covYY, covXY
end
function POLYGON:Direction()
local covXX, covYY, covXY = self:CovarianceMatrix()
-- Simplified calculation for the largest eigenvector's direction
local theta = 0.5 * math.atan2(2 * covXY, covXX - covYY)
return math.cos(theta), math.sin(theta)
end
--- Returns a random Vec2 within the polygon. The Vec2 is weighted by the areas of the triangles that make up the polygon.
-- @return #table The random Vec2
function POLYGON:GetRandomVec2()
local weights = {}
for _, triangle in pairs(self.Triangles) do
weights[triangle] = triangle.SurfaceArea / self.SurfaceArea
end
local random_weight = math.random()
local accumulated_weight = 0
for triangle, weight in pairs(weights) do
accumulated_weight = accumulated_weight + weight
if accumulated_weight >= random_weight then
return triangle:GetRandomVec2()
end
end
end
--- Returns a random non-weighted Vec2 within the polygon. The Vec2 is chosen from one of the triangles that make up the polygon.
-- @return #table The random non-weighted Vec2
function POLYGON:GetRandomNonWeightedVec2()
return self.Triangles[math.random(1, #self.Triangles)]:GetRandomVec2()
end
--- Checks if a point is contained within the polygon. The point is a table with 'x' and 'y' fields.
-- @param #table point The point to check
-- @param #table points (optional) Points of the polygon or other points if you're just using the POLYGON class without an object of it
-- @return #bool True if the point is contained, false otherwise
function POLYGON:ContainsPoint(point, polygon_points)
local x = point.x
local y = point.y
polygon_points = polygon_points or self.Points
local counter = 0
local num_points = #polygon_points
for current_index = 1, num_points do
local next_index = (current_index % num_points) + 1
local current_x, current_y = polygon_points[current_index].x, polygon_points[current_index].y
local next_x, next_y = polygon_points[next_index].x, polygon_points[next_index].y
if ((current_y > y) ~= (next_y > y)) and (x < (next_x - current_x) * (y - current_y) / (next_y - current_y) + current_x) then
counter = counter + 1
end
end
return counter % 2 == 1
end
--- Draws the polygon on the map. The polygon can be drawn with or without inner triangles. This is just for debugging
-- @param #bool include_inner_triangles Whether to include inner triangles in the drawing
function POLYGON:Draw(include_inner_triangles)
include_inner_triangles = include_inner_triangles or false
for i=1, #self.Coords do
local c1 = self.Coords[i]
local c2 = self.Coords[i % #self.Coords + 1]
table.add(self.OutlineMarkIDs, c1:LineToAll(c2))
end
if include_inner_triangles then
for _, triangle in ipairs(self.Triangles) do
triangle:Draw()
end
end
end
--- Removes the drawing of the polygon from the map.
function POLYGON:RemoveDraw()
for _, triangle in pairs(self.Triangles) do
triangle:RemoveDraw()
end
for _, mark_id in pairs(self.OutlineMarkIDs) do
UTILS.RemoveMark(mark_id)
end
end
--- Calculates the surface area of the polygon. The surface area is the sum of the areas of the triangles that make up the polygon.
-- @return #number The surface area of the polygon
function POLYGON:__CalculateSurfaceArea()
local area = 0
for _, triangle in pairs(self.Triangles) do
area = area + triangle.SurfaceArea
end
return area
end

View File

@@ -1,214 +0,0 @@
--- **Shapes** - Class that serves as the base shapes drawn in the Mission Editor
--
--
-- ### Author: **nielsvaes/coconutcockpit**
--
-- ===
-- @module Shapes.SHAPE_BASE
-- @image CORE_Pathline.png
--- SHAPE_BASE class.
-- @type SHAPE_BASE
-- @field #string ClassName Name of the class.
-- @field #string Name Name of the shape
-- @field #table CenterVec2 Vec2 of the center of the shape, this will be assigned automatically
-- @field #table Points List of 3D points defining the shape, this will be assigned automatically
-- @field #table Coords List of COORDINATE defining the path, this will be assigned automatically
-- @field #table MarkIDs List any MARKIDs this class use, this will be assigned automatically
-- @extends Core.Base#BASE
--- *I'm in love with the shape of you -- Ed Sheeran
--
-- ===
--
-- # SHAPE_BASE
-- The class serves as the base class to deal with these shapes using MOOSE. You should never use this class on its own,
-- rather use:
-- CIRCLE
-- LINE
-- OVAL
-- POLYGON
-- TRIANGLE (although this one's a bit special as well)
--
-- ===
-- The idea is that anything you draw on the map in the Mission Editor can be turned in a shape to work with in MOOSE.
-- This is the base class that all other shape classes are built on. There are some shared functions, most of which are overridden in the derived classes
--
-- @field #SHAPE_BASE
SHAPE_BASE = {
ClassName = "SHAPE_BASE",
Name = "",
CenterVec2 = nil,
Points = {},
Coords = {},
MarkIDs = {},
ColorString = "",
ColorRGBA = {}
}
--- Creates a new instance of SHAPE_BASE.
-- @return #SHAPE_BASE The new instance
function SHAPE_BASE:New()
local self = BASE:Inherit(self, BASE:New())
return self
end
--- Finds a shape on the map by its name.
-- @param #string shape_name Name of the shape to find
-- @return #SHAPE_BASE The found shape
function SHAPE_BASE:FindOnMap(shape_name)
local self = BASE:Inherit(self, BASE:New())
local found = false
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if object["name"] == shape_name then
self.Name = object["name"]
self.CenterVec2 = { x = object["mapX"], y = object["mapY"] }
self.ColorString = object["colorString"]
self.ColorRGBA = UTILS.HexToRGBA(self.ColorString)
found = true
end
end
end
if not found then
self:E("Can't find a shape with name " .. shape_name)
end
return self
end
function SHAPE_BASE:GetAllShapes(filter)
filter = filter or ""
local return_shapes = {}
for _, layer in pairs(env.mission.drawings.layers) do
for _, object in pairs(layer["objects"]) do
if string.contains(object["name"], filter) then
table.add(return_shapes, object)
end
end
end
return return_shapes
end
--- Offsets the shape to a new position.
-- @param #table new_vec2 The new position
function SHAPE_BASE:Offset(new_vec2)
local offset_vec2 = UTILS.Vec2Subtract(new_vec2, self.CenterVec2)
self.CenterVec2 = new_vec2
if self.ClassName == "POLYGON" then
for _, point in pairs(self.Points) do
point.x = point.x + offset_vec2.x
point.y = point.y + offset_vec2.y
end
end
end
--- Gets the name of the shape.
-- @return #string The name of the shape
function SHAPE_BASE:GetName()
return self.Name
end
function SHAPE_BASE:GetColorString()
return self.ColorString
end
function SHAPE_BASE:GetColorRGBA()
return self.ColorRGBA
end
function SHAPE_BASE:GetColorRed()
return self.ColorRGBA.R
end
function SHAPE_BASE:GetColorGreen()
return self.ColorRGBA.G
end
function SHAPE_BASE:GetColorBlue()
return self.ColorRGBA.B
end
function SHAPE_BASE:GetColorAlpha()
return self.ColorRGBA.A
end
--- Gets the center position of the shape.
-- @return #table The center position
function SHAPE_BASE:GetCenterVec2()
return self.CenterVec2
end
--- Gets the center coordinate of the shape.
-- @return #COORDINATE The center coordinate
function SHAPE_BASE:GetCenterCoordinate()
return COORDINATE:NewFromVec2(self.CenterVec2)
end
--- Gets the coordinate of the shape.
-- @return #COORDINATE The coordinate
function SHAPE_BASE:GetCoordinate()
return self:GetCenterCoordinate()
end
--- Checks if a point is contained within the shape.
-- @param #table _ The point to check
-- @return #bool True if the point is contained, false otherwise
function SHAPE_BASE:ContainsPoint(_)
self:E("This needs to be set in the derived class")
end
--- Checks if a unit is contained within the shape.
-- @param #string unit_name The name of the unit to check
-- @return #bool True if the unit is contained, false otherwise
function SHAPE_BASE:ContainsUnit(unit_name)
local unit = UNIT:FindByName(unit_name)
if unit == nil or not unit:IsAlive() then
return false
end
if self:ContainsPoint(unit:GetVec2()) then
return true
end
return false
end
--- Checks if any unit of a group is contained within the shape.
-- @param #string group_name The name of the group to check
-- @return #bool True if any unit of the group is contained, false otherwise
function SHAPE_BASE:ContainsAnyOfGroup(group_name)
local group = GROUP:FindByName(group_name)
if group == nil or not group:IsAlive() then
return false
end
for _, unit in pairs(group:GetUnits()) do
if self:ContainsPoint(unit:GetVec2()) then
return true
end
end
return false
end
--- Checks if all units of a group are contained within the shape.
-- @param #string group_name The name of the group to check
-- @return #bool True if all units of the group are contained, false otherwise
function SHAPE_BASE:ContainsAllOfGroup(group_name)
local group = GROUP:FindByName(group_name)
if group == nil or not group:IsAlive() then
return false
end
for _, unit in pairs(group:GetUnits()) do
if not self:ContainsPoint(unit:GetVec2()) then
return false
end
end
return true
end

View File

@@ -1,101 +0,0 @@
--- TRIANGLE class with properties and methods for handling triangles. This class is mostly used by the POLYGON class, but you can use it on its own as well
--
-- ### Author: **nielsvaes/coconutcockpit**
--
--
-- ===
-- @module Shapes.TRIANGLE
-- @image MOOSE.JPG
--- LINE class.
-- @type CUBE
-- @field #string ClassName Name of the class.
-- @field #number Points points of the line
-- @field #number Coords coordinates of the line
--
-- ===
---
-- @field #TRIANGLE
TRIANGLE = {
ClassName = "TRIANGLE",
Points = {},
Coords = {},
SurfaceArea = 0
}
--- Creates a new triangle from three points. The points need to be given as Vec2s
-- @param #table p1 The first point of the triangle
-- @param #table p2 The second point of the triangle
-- @param #table p3 The third point of the triangle
-- @return #TRIANGLE The new triangle
function TRIANGLE:New(p1, p2, p3)
local self = BASE:Inherit(self, SHAPE_BASE:New())
self.Points = {p1, p2, p3}
local center_x = (p1.x + p2.x + p3.x) / 3
local center_y = (p1.y + p2.y + p3.y) / 3
self.CenterVec2 = {x=center_x, y=center_y}
for _, pt in pairs({p1, p2, p3}) do
table.add(self.Coords, COORDINATE:NewFromVec2(pt))
end
self.SurfaceArea = math.abs((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y)) * 0.5
self.MarkIDs = {}
return self
end
--- Checks if a point is contained within the triangle.
-- @param #table pt The point to check
-- @param #table points (optional) The points of the triangle, or 3 other points if you're just using the TRIANGLE class without an object of it
-- @return #bool True if the point is contained, false otherwise
function TRIANGLE:ContainsPoint(pt, points)
points = points or self.Points
local function sign(p1, p2, p3)
return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y)
end
local d1 = sign(pt, self.Points[1], self.Points[2])
local d2 = sign(pt, self.Points[2], self.Points[3])
local d3 = sign(pt, self.Points[3], self.Points[1])
local has_neg = (d1 < 0) or (d2 < 0) or (d3 < 0)
local has_pos = (d1 > 0) or (d2 > 0) or (d3 > 0)
return not (has_neg and has_pos)
end
--- Returns a random Vec2 within the triangle.
-- @param #table points The points of the triangle, or 3 other points if you're just using the TRIANGLE class without an object of it
-- @return #table The random Vec2
function TRIANGLE:GetRandomVec2(points)
points = points or self.Points
local pt = {math.random(), math.random()}
table.sort(pt)
local s = pt[1]
local t = pt[2] - pt[1]
local u = 1 - pt[2]
return {x = s * points[1].x + t * points[2].x + u * points[3].x,
y = s * points[1].y + t * points[2].y + u * points[3].y}
end
--- Draws the triangle on the map, just for debugging
function TRIANGLE:Draw()
for i=1, #self.Coords do
local c1 = self.Coords[i]
local c2 = self.Coords[i % #self.Coords + 1]
table.add(self.MarkIDs, c1:LineToAll(c2))
end
end
--- Removes the drawing of the triangle from the map.
function TRIANGLE:RemoveDraw()
for _, mark_id in pairs(self.MarkIDs) do
UTILS.RemoveMark(mark_id)
end
end

View File

@@ -30,10 +30,6 @@
--
-- ===
--
-- ### [Demo Missions](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Sound/Radio)
--
-- ===
--
-- ### Authors: Hugues "Grey_Echo" Bousquet, funkyfranky
--
-- @module Sound.Radio
@@ -97,7 +93,6 @@ RADIO = {
Power = 100,
Loop = false,
alias = nil,
moduhasbeenset = false,
}
--- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast.
@@ -168,13 +163,12 @@ function RADIO:SetFrequency(Frequency)
self:F2(Frequency)
if type(Frequency) == "number" then
-- If frequency is in range
--if (Frequency >= 30 and Frequency <= 87.995) or (Frequency >= 108 and Frequency <= 173.995) or (Frequency >= 225 and Frequency <= 399.975) then
-- Convert frequency from MHz to Hz
self.Frequency = Frequency
self.HertzFrequency = Frequency * 1000000
self.Frequency = Frequency * 1000000
-- If the RADIO is attached to a UNIT or a GROUP, we need to send the DCS Command "SetFrequency" to change the UNIT or GROUP frequency
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
@@ -182,7 +176,7 @@ function RADIO:SetFrequency(Frequency)
local commandSetFrequency={
id = "SetFrequency",
params = {
frequency = self.HertzFrequency,
frequency = self.Frequency,
modulation = self.Modulation,
}
}
@@ -199,7 +193,7 @@ function RADIO:SetFrequency(Frequency)
return self
end
--- Set AM or FM modulation of the radio transmitter. Set this before you set a frequency!
--- Set AM or FM modulation of the radio transmitter.
-- @param #RADIO self
-- @param #number Modulation Modulation is either radio.modulation.AM or radio.modulation.FM.
-- @return #RADIO self
@@ -208,10 +202,6 @@ function RADIO:SetModulation(Modulation)
if type(Modulation) == "number" then
if Modulation == radio.modulation.AM or Modulation == radio.modulation.FM then --TODO Maybe make this future proof if ED decides to add an other modulation ?
self.Modulation = Modulation
if self.moduhasbeenset == false and Modulation == radio.modulation.FM then -- override default
self:SetFrequency(self.Frequency)
end
self.moduhasbeenset = true
return self
end
end

View File

@@ -268,7 +268,7 @@ function RADIOQUEUE:NewTransmission(filename, duration, path, tstart, interval,
return nil
end
if type(duration)~="number" then
self:E(self.lid..string.format("ERROR: Duration specified is NOT a number but type=%s. Filename=%s, duration=%s", type(duration), tostring(filename), tostring(duration)))
self:E(self.lid.."ERROR: Duration specified is NOT a number.")
return nil
end
@@ -361,7 +361,6 @@ end
-- @param #RADIOQUEUE self
-- @param #RADIOQUEUE.Transmission transmission The transmission.
function RADIOQUEUE:Broadcast(transmission)
self:T("Broadcast")
if ((transmission.soundfile and transmission.soundfile.useSRS) or transmission.soundtext) and self.msrs then
self:_BroadcastSRS(transmission)
@@ -426,7 +425,7 @@ function RADIOQUEUE:Broadcast(transmission)
else
-- Broadcasting from carrier. No subtitle possible. Need to send messages to players.
self:T(self.lid..string.format("Broadcasting via trigger.action.radioTransmission()"))
self:T(self.lid..string.format("Broadcasting via trigger.action.radioTransmission()."))
-- Position from where to transmit.
local vec3=nil
@@ -454,8 +453,6 @@ function RADIOQUEUE:Broadcast(transmission)
local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "")
MESSAGE:New(string.format(text, filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE "..self.alias):ToAll()
end
else
self:E("ERROR: Could not get vec3 to determine transmission origin! Did you specify a sender and is it still alive?")
end
end
@@ -485,6 +482,7 @@ end
--- Check radio queue for transmissions to be broadcasted.
-- @param #RADIOQUEUE self
function RADIOQUEUE:_CheckRadioQueue()
--env.info("FF check radio queue "..self.alias)
-- Check if queue is empty.
if #self.queue==0 then

View File

@@ -14,7 +14,7 @@
--
-- ===
--
-- ## Example Missions: [GitHub](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Sound/MSRS).
-- ## Example Missions: [GitHub](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Sound/MSRS).
--
-- ===
--
@@ -52,7 +52,6 @@
-- @field #table poptions Provider options. Each element is a data structure of type `MSRS.ProvierOptions`.
-- @field #string provider Provider of TTS (win, gcloud, azure, amazon).
-- @field #string backend Backend used as interface to SRS (MSRS.Backend.SRSEXE or MSRS.Backend.GRPC).
-- @field #boolean UsePowerShell Use PowerShell to execute the command and not cmd.exe
-- @extends Core.Base#BASE
--- *It is a very sad thing that nowadays there is so little useless information.* - Oscar Wilde
@@ -257,12 +256,11 @@ MSRS = {
ConfigFilePath = "Config\\",
ConfigLoaded = false,
poptions = {},
UsePowerShell = false,
}
--- MSRS class version.
-- @field #string version
MSRS.version="0.3.3"
MSRS.version="0.3.0"
--- Voices
-- @type MSRS.Voices
@@ -273,11 +271,11 @@ MSRS.Voices = {
["David"] = "Microsoft David Desktop", -- en-US
["Zira"] = "Microsoft Zira Desktop", -- en-US
["Hortense"] = "Microsoft Hortense Desktop", --fr-FR
["de_DE_Hedda"] = "Microsoft Hedda Desktop", -- de-DE
["en_GB_Hazel"] = "Microsoft Hazel Desktop", -- en-GB
["en_US_David"] = "Microsoft David Desktop", -- en-US
["en_US_Zira"] = "Microsoft Zira Desktop", -- en-US
["fr_FR_Hortense"] = "Microsoft Hortense Desktop", --fr-FR
["de-DE-Hedda"] = "Microsoft Hedda Desktop", -- de-DE
["en-GB-Hazel"] = "Microsoft Hazel Desktop", -- en-GB
["en-US-David"] = "Microsoft David Desktop", -- en-US
["en-US-Zira"] = "Microsoft Zira Desktop", -- en-US
["fr-FR-Hortense"] = "Microsoft Hortense Desktop", --fr-FR
},
MicrosoftGRPC = { -- en-US/GB voices only as of Jan 2024, working ones if using gRPC and MS, if voice packs are installed
--["Hedda"] = "Hedda", -- de-DE
@@ -306,7 +304,8 @@ MSRS.Voices = {
["en_CA_Linda"] = "Linda", --en-CA
["en_IN_Ravi"] = "Ravi", --en-IN
["en_IN_Heera"] = "Heera", --en-IN
["en_IR_Sean"] = "Sean", --en-IR
["en_IR_Sean"] = "Sean", --en-IR
--]]
},
Google = {
Standard = {
@@ -590,7 +589,7 @@ function MSRS:SetBackendSRSEXE()
end
--- Set the default backend.
-- @param #string Backend
-- @param #MSRS self
function MSRS.SetDefaultBackend(Backend)
MSRS.backend=Backend or MSRS.Backend.SRSEXE
end
@@ -825,7 +824,7 @@ function MSRS:SetVoiceProvider(Voice, Provider)
self:F( {Voice=Voice, Provider=Provider} )
self.poptions=self.poptions or {}
self.poptions[Provider or self:GetProvider()].voice=Voice
self.poptions[Provider or self:GetProvider()]=Voice
return self
end
@@ -1239,7 +1238,7 @@ function MSRS:PlayTextExt(Text, Delay, Frequencies, Modulations, Gender, Culture
self:T({Text, Delay, Frequencies, Modulations, Gender, Culture, Voice, Volume, Label, Coordinate} )
if Delay and Delay>0 then
self:ScheduleOnce(Delay, self.PlayTextExt, self, Text, 0, Frequencies, Modulations, Gender, Culture, Voice, Volume, Label, Coordinate)
self:ScheduleOnce(Delay, MSRS.PlayTextExt, self, Text, 0, Frequencies, Modulations, Gender, Culture, Voice, Volume, Label, Coordinate)
else
Frequencies = Frequencies or self:GetFrequencies()
@@ -1377,25 +1376,20 @@ function MSRS:_GetCommand(freqs, modus, coal, gender, voice, culture, volume, sp
modus=modus:gsub("1", "FM")
-- Command.
local pwsh = string.format('Start-Process -WindowStyle Hidden -WorkingDirectory \"%s\" -FilePath \"%s\" -ArgumentList \'-f "%s" -m "%s" -c %s -p %s -n "%s" -v "%.1f"', path, exe, freqs, modus, coal, port, label,volume )
local command=string.format('"%s\\%s" -f "%s" -m "%s" -c %s -p %s -n "%s" -v "%.1f"', path, exe, freqs, modus, coal, port, label,volume)
-- Set voice or gender/culture.
if voice and self.UsePowerShell ~= true then
if voice then
-- Use a specific voice (no need for gender and/or culture.
command=command..string.format(" --voice=\"%s\"", tostring(voice))
pwsh=pwsh..string.format(" --voice=\"%s\"", tostring(voice))
else
-- Add gender.
if gender and gender~="female" then
command=command..string.format(" -g %s", tostring(gender))
pwsh=pwsh..string.format(" -g %s", tostring(gender))
end
-- Add culture.
if culture and culture~="en-GB" then
command=command..string.format(" -l %s", tostring(culture))
pwsh=pwsh..string.format(" -l %s", tostring(culture))
end
end
@@ -1403,14 +1397,12 @@ function MSRS:_GetCommand(freqs, modus, coal, gender, voice, culture, volume, sp
if coordinate then
local lat,lon,alt=self:_GetLatLongAlt(coordinate)
command=command..string.format(" -L %.4f -O %.4f -A %d", lat, lon, alt)
pwsh=pwsh..string.format(" -L %.4f -O %.4f -A %d", lat, lon, alt)
end
-- Set provider options
if self.provider==MSRS.Provider.GOOGLE then
local pops=self:GetProviderOptions()
command=command..string.format(' --ssml -G "%s"', pops.credentials)
pwsh=pwsh..string.format(' --ssml -G "%s"', pops.credentials)
elseif self.provider==MSRS.Provider.WINDOWS then
-- Nothing to do.
else
@@ -1424,12 +1416,8 @@ function MSRS:_GetCommand(freqs, modus, coal, gender, voice, culture, volume, sp
-- Debug output.
self:T("MSRS command from _GetCommand="..command)
if self.UsePowerShell == true then
return pwsh
else
return command
end
return command
end
--- Execute SRS command to play sound using the `DCS-SR-ExternalAudio.exe`.
@@ -1437,7 +1425,7 @@ end
-- @param #string command Command to executer
-- @return #number Return value of os.execute() command.
function MSRS:_ExecCommand(command)
self:T2( {command=command} )
self:F( {command=command} )
-- Skip this function if _GetCommand was not able to find the executable
if string.find(command, "CommandNotFound") then return 0 end
@@ -1445,13 +1433,7 @@ function MSRS:_ExecCommand(command)
local batContent = command.." && exit"
-- Create a tmp file.
local filename=os.getenv('TMP').."\\MSRS-"..MSRS.uuid()..".bat"
if self.UsePowerShell == true then
filename=os.getenv('TMP').."\\MSRS-"..MSRS.uuid()..".ps1"
batContent = command .. "\'"
self:I({batContent=batContent})
end
local script=io.open(filename, "w+")
script:write(batContent)
script:close()
@@ -1460,7 +1442,7 @@ function MSRS:_ExecCommand(command)
self:T("MSRS batch content: "..batContent)
local res=nil
if self.UsePowerShell ~= true then
if true then
-- Create a tmp file.
local filenvbs = os.getenv('TMP') .. "\\MSRS-"..MSRS.uuid()..".vbs"
@@ -1488,20 +1470,23 @@ function MSRS:_ExecCommand(command)
timer.scheduleFunction(os.remove, filenvbs, timer.getTime()+1)
self:T("MSRS vbs and batch file removed")
elseif self.UsePowerShell == true then
elseif false then
-- Create a tmp file.
local filenvbs = os.getenv('TMP') .. "\\MSRS-"..MSRS.uuid()..".vbs"
-- VBS script
local script = io.open(filenvbs, "w+")
script:write(string.format('Set oShell = CreateObject ("Wscript.Shell")\n'))
script:write(string.format('Dim strArgs\n'))
script:write(string.format('strArgs = "cmd /c %s"\n', filename))
script:write(string.format('oShell.Run strArgs, 0, false'))
script:close()
local runvbs=string.format('cscript.exe //Nologo //B "%s"', filenvbs)
local pwsh = string.format('start /min "" powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -Command "%s"',filename)
--env.info("[MSRS] TextToSpeech Command :\n" .. pwsh.."\n")
if string.len(pwsh) > 255 then
self:E("[MSRS] - pwsh string too long")
end
-- Play file in 0.01 seconds
res=os.execute(pwsh)
-- Remove file in 1 second.
timer.scheduleFunction(os.remove, filename, timer.getTime()+1)
res=os.execute(runvbs)
else
-- Play command.
@@ -1575,8 +1560,8 @@ end
function MSRS:_DCSgRPCtts(Text, Frequencies, Gender, Culture, Voice, Volume, Label, Coordinate)
-- Debug info.
self:T("MSRS_BACKEND_DCSGRPC:_DCSgRPCtts()")
self:T({Text, Frequencies, Gender, Culture, Voice, Volume, Label, Coordinate})
self:F("MSRS_BACKEND_DCSGRPC:_DCSgRPCtts()")
self:F({Text, Frequencies, Gender, Culture, Voice, Volume, Label, Coordinate})
local options = {} -- #MSRS.GRPCOptions
@@ -1602,6 +1587,7 @@ function MSRS:_DCSgRPCtts(Text, Frequencies, Gender, Culture, Voice, Volume, Lab
-- Provider (win, gcloud, ...)
local provider = self.provider or MSRS.Provider.WINDOWS
self:F({provider=provider})
-- Provider options: voice, credentials
options.provider = {}
@@ -1609,7 +1595,7 @@ function MSRS:_DCSgRPCtts(Text, Frequencies, Gender, Culture, Voice, Volume, Lab
-- Voice
Voice=Voice or self:GetVoice(self.provider) or self.voice
if Voice then
-- We use a specific voice
options.provider[provider].voice = Voice

View File

@@ -24,7 +24,7 @@
do -- Sound Base
-- @type SOUNDBASE
--- @type SOUNDBASE
-- @field #string ClassName Name of the class.
-- @extends Core.Base#BASE
@@ -100,7 +100,7 @@ end
do -- Sound File
-- @type SOUNDFILE
--- @type SOUNDFILE
-- @field #string ClassName Name of the class
-- @field #string filename Name of the flag.
-- @field #string path Directory path, where the sound file is located. This includes the final slash "/".
@@ -160,7 +160,7 @@ do -- Sound File
-- @param #string FileName The name of the sound file, e.g. "Hello World.ogg".
-- @param #string Path The path of the directory, where the sound file is located. Default is "l10n/DEFAULT/" within the miz file.
-- @param #number Duration Duration in seconds, how long it takes to play the sound file. Default is 3 seconds.
-- @param #boolean UseSrs Set if SRS should be used to play this file. Default is false.
-- @param #bolean UseSrs Set if SRS should be used to play this file. Default is false.
-- @return #SOUNDFILE self
function SOUNDFILE:New(FileName, Path, Duration, UseSrs)
@@ -249,9 +249,6 @@ do -- Sound File
-- @param #string Duration Duration in seconds. Default 3 seconds.
-- @return #SOUNDFILE self
function SOUNDFILE:SetDuration(Duration)
if Duration and type(Duration)=="string" then
Duration=tonumber(Duration)
end
self.duration=Duration or 3
return self
end
@@ -292,7 +289,7 @@ end
do -- Text-To-Speech
-- @type SOUNDTEXT
--- @type SOUNDTEXT
-- @field #string ClassName Name of the class
-- @field #string text Text to speak.
-- @field #number duration Duration in seconds.
@@ -359,7 +356,7 @@ do -- Text-To-Speech
local self=BASE:Inherit(self, BASE:New()) -- #SOUNDTEXT
self:SetText(Text)
self:SetDuration(Duration or MSRS.getSpeechTime(Text))
self:SetDuration(Duration or STTS.getSpeechTime(Text))
--self:SetGender()
--self:SetCulture()

View File

@@ -21,7 +21,7 @@
do -- UserSound
-- @type USERSOUND
--- @type USERSOUND
-- @extends Core.Base#BASE

View File

@@ -175,19 +175,19 @@ do -- TASK_A2G
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Core.Set#SET_UNIT TargetSetUnit The set of targets.
function TASK_A2G:SetTargetSetUnit( TargetSetUnit )
self.TargetSetUnit = TargetSetUnit
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
function TASK_A2G:GetPlannedMenuText()
return self:GetStateString() .. " - " .. self:GetTaskName() .. " ( " .. self.TargetSetUnit:GetUnitTypesText() .. " )"
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Core.Point#COORDINATE RendezVousCoordinate The Coordinate object referencing to the 2D point where the RendezVous point is located on the map.
-- @param #number RendezVousRange The RendezVousRange that defines when the player is considered to have arrived at the RendezVous point.
-- @param Wrapper.Unit#UNIT TaskUnit
@@ -200,7 +200,7 @@ do -- TASK_A2G
ActRouteRendezVous:SetRange( RendezVousRange )
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Point#COORDINATE The Coordinate object referencing to the 2D point where the RendezVous point is located on the map.
-- @return #number The RendezVousRange that defines when the player is considered to have arrived at the RendezVous point.
@@ -212,7 +212,7 @@ do -- TASK_A2G
return ActRouteRendezVous:GetCoordinate(), ActRouteRendezVous:GetRange()
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Core.Zone#ZONE_BASE RendezVousZone The Zone object where the RendezVous is located on the map.
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_A2G:SetRendezVousZone( RendezVousZone, TaskUnit )
@@ -223,7 +223,7 @@ do -- TASK_A2G
ActRouteRendezVous:SetZone( RendezVousZone )
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Zone#ZONE_BASE The Zone object where the RendezVous is located on the map.
function TASK_A2G:GetRendezVousZone( TaskUnit )
@@ -234,7 +234,7 @@ do -- TASK_A2G
return ActRouteRendezVous:GetZone()
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Core.Point#COORDINATE TargetCoordinate The Coordinate object where the Target is located on the map.
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_A2G:SetTargetCoordinate( TargetCoordinate, TaskUnit )
@@ -245,7 +245,7 @@ do -- TASK_A2G
ActRouteTarget:SetCoordinate( TargetCoordinate )
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Point#COORDINATE The Coordinate object where the Target is located on the map.
function TASK_A2G:GetTargetCoordinate( TaskUnit )
@@ -256,7 +256,7 @@ do -- TASK_A2G
return ActRouteTarget:GetCoordinate()
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Core.Zone#ZONE_BASE TargetZone The Zone object where the Target is located on the map.
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_A2G:SetTargetZone( TargetZone, TaskUnit )
@@ -267,7 +267,7 @@ do -- TASK_A2G
ActRouteTarget:SetZone( TargetZone )
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Zone#ZONE_BASE The Zone object where the Target is located on the map.
function TASK_A2G:GetTargetZone( TaskUnit )
@@ -280,7 +280,7 @@ do -- TASK_A2G
function TASK_A2G:SetGoalTotal()
self.GoalTotal = self.TargetSetUnit:CountAlive()
self.GoalTotal = self.TargetSetUnit:Count()
end
function TASK_A2G:GetGoalTotal()
@@ -304,14 +304,14 @@ do -- TASK_A2G
function TASK_A2G:onafterGoal( TaskUnit, From, Event, To )
local TargetSetUnit = self.TargetSetUnit -- Core.Set#SET_UNIT
if TargetSetUnit:CountAlive() == 0 then
if TargetSetUnit:Count() == 0 then
self:Success()
end
self:__Goal( -10 )
end
-- @param #TASK_A2G self
--- @param #TASK_A2G self
function TASK_A2G:UpdateTaskInfo( DetectedItem )
if self:IsStatePlanned() or self:IsStateAssigned() then
@@ -328,7 +328,7 @@ do -- TASK_A2G
self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 10, "MOD", true )
if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:CountAlive()
local DetectedItemsCount = self.TargetSetUnit:Count()
local ReportTypes = REPORT:New()
local TargetTypes = {}
for TargetUnitName, TargetUnit in pairs( self.TargetSetUnit:GetSet() ) do
@@ -341,7 +341,7 @@ do -- TASK_A2G
self.TaskInfo:AddTargetCount( DetectedItemsCount, 11, "O", true )
self.TaskInfo:AddTargets( DetectedItemsCount, ReportTypes:Text( ", " ), 20, "D", true )
else
local DetectedItemsCount = self.TargetSetUnit:CountAlive()
local DetectedItemsCount = self.TargetSetUnit:Count()
local DetectedItemsTypes = self.TargetSetUnit:GetTypeNames()
self.TaskInfo:AddTargetCount( DetectedItemsCount, 11, "O", true )
self.TaskInfo:AddTargets( DetectedItemsCount, DetectedItemsTypes, 20, "D", true )

View File

@@ -580,18 +580,6 @@ ENUMS.Link16Power = {
--- Enums for the STORAGE class for stores - which need to be in ""
-- @type ENUMS.Storage
-- @type ENUMS.Storage.weapons
-- @type ENUMS.Storage.weapons.missiles
-- @type ENUMS.Storage.weapons.bombs
-- @type ENUMS.Storage.weapons.nurs
-- @type ENUMS.Storage.weapons.containers
-- @type ENUMS.Storage.weapons.droptanks
-- @type ENUMS.Storage.weapons.adapters
-- @type ENUMS.Storage.weapons.torpedoes
-- @type ENUMS.Storage.weapons.Gazelle
-- @type ENUMS.Storage.weapons.CH47
-- @type ENUMS.Storage.weapons.OH58
-- @type ENUMS.Storage.weapons.UH1H
-- @type ENUMS.Storage.weapons.AH64D
ENUMS.Storage = {
weapons = {
missiles = {}, -- Missiles
@@ -601,11 +589,6 @@ ENUMS.Storage = {
droptanks = {}, -- Droptanks
adapters = {}, -- Adapter
torpedoes = {}, -- Torpedoes
Gazelle = {}, -- Gazelle specifics
CH47 = {}, -- Chinook specifics
OH58 = {}, -- Kiowa specifics
UH1H = {}, -- Huey specifics
AH64D = {}, -- Huey specifics
}
}
@@ -1165,75 +1148,4 @@ ENUMS.Storage.weapons.bombs.BDU_50LD = "weapons.bombs.BDU_50LD"
ENUMS.Storage.weapons.bombs.AGM_62 = "weapons.bombs.AGM_62"
ENUMS.Storage.weapons.containers.US_M10_SMOKE_TANK_WHITE = "weapons.containers.{US_M10_SMOKE_TANK_WHITE}"
ENUMS.Storage.weapons.missiles.MICA_T = "weapons.missiles.MICA_T"
ENUMS.Storage.weapons.containers.HVAR_rocket = "weapons.containers.HVAR_rocket"
-- Gazelle
ENUMS.Storage.weapons.Gazelle.HMP400_100RDS = {4,15,46,1771}
ENUMS.Storage.weapons.Gazelle.HMP400_200RDS = {4,15,46,1770}
ENUMS.Storage.weapons.Gazelle.HMP400_400RDS = {4,15,46,1769}
ENUMS.Storage.weapons.Gazelle.GIAT_M261_AP = {4,15,46,1768}
ENUMS.Storage.weapons.Gazelle.GIAT_M261_SAPHEI = {4,15,46,1767}
ENUMS.Storage.weapons.Gazelle.GIAT_M261_HE = {4,15,46,1766}
ENUMS.Storage.weapons.Gazelle.GIAT_M261_HEAP = {4,15,46,1765}
ENUMS.Storage.weapons.Gazelle.GIAT_M261_APHE = {4,15,46,1764}
ENUMS.Storage.weapons.Gazelle.GAZELLE_IR_DEFLECTOR = {4,15,47,680}
ENUMS.Storage.weapons.Gazelle.GAZELLE_FAS_SANDFILTER = {4,15,47,679}
-- Chinook
ENUMS.Storage.weapons.CH47.CH47_PORT_M60D = {4,15,46,2476}
ENUMS.Storage.weapons.CH47.CH47_STBD_M60D = {4,15,46,2477}
ENUMS.Storage.weapons.CH47.CH47_AFT_M60D = {4,15,46,2478}
ENUMS.Storage.weapons.CH47.CH47_PORT_M134D = {4,15,46,2482}
ENUMS.Storage.weapons.CH47.CH47_STBD_M134D = {4,15,46,2483}
ENUMS.Storage.weapons.CH47.CH47_AFT_M3M = {4,15,46,2484}
ENUMS.Storage.weapons.CH47.CH47_PORT_M240H = {4,15,46,2479}
ENUMS.Storage.weapons.CH47.CH47_STBD_M240H = {4,15,46,2480}
ENUMS.Storage.weapons.CH47.CH47_AFT_M240H = {4,15,46,2481}
-- Huey
ENUMS.Storage.weapons.UH1H.M134_MiniGun_Right = {4,15,46,161}
ENUMS.Storage.weapons.UH1H.M134_MiniGun_Left = {4,15,46,160}
ENUMS.Storage.weapons.UH1H.M134_MiniGun_Right_Door = {4,15,46,175}
ENUMS.Storage.weapons.UH1H.M60_MG_Right_Door = {4,15,46,177}
ENUMS.Storage.weapons.UH1H.M134_MiniGun_Left_Door = {4,15,46,174}
ENUMS.Storage.weapons.UH1H.M60_MG_Left_Door = {4,15,46,176}
-- Kiowa
ENUMS.Storage.weapons.OH58.FIM92 = {4,4,7,449}
ENUMS.Storage.weapons.OH58.MG_M3P100 = {4,15,46,2608}
ENUMS.Storage.weapons.OH58.MG_M3P200 = {4,15,46,2607}
ENUMS.Storage.weapons.OH58.MG_M3P300 = {4,15,46,2606}
ENUMS.Storage.weapons.OH58.MG_M3P400 = {4,15,46,2605}
ENUMS.Storage.weapons.OH58.MG_M3P500 = {4,15,46,2604}
ENUMS.Storage.weapons.OH58.Smk_Grenade_Blue = {4,5,9,486}
ENUMS.Storage.weapons.OH58.Smk_Grenade_Green = {4,5,9,487}
ENUMS.Storage.weapons.OH58.Smk_Grenade_Red = {4,5,9,485}
ENUMS.Storage.weapons.OH58.Smk_Grenade_Violet = {4,5,9,488}
ENUMS.Storage.weapons.OH58.Smk_Grenade_White = {4,5,9,490}
ENUMS.Storage.weapons.OH58.Smk_Grenade_Yellow = {4,5,9,489}
-- Apache
ENUMS.Storage.weapons.AH64D.AN_APG78 = {4,15,44,2138}
ENUMS.Storage.weapons.AH64D.Internal_Aux_FuelTank = {1,3,43,1700}
---
-- @type ENUMS.FARPType
-- @field #string FARP
-- @field #string INVISIBLE
-- @field #string HELIPADSINGLE
-- @field #string PADSINGLE
ENUMS.FARPType = {
FARP = "FARP",
INVISIBLE = "INVISIBLE",
HELIPADSINGLE = "HELIPADSINGLE",
PADSINGLE = "PADSINGLE",
}
---
-- @type ENUMS.FARPObjectTypeNamesAndShape
-- @field #string FARP
-- @field #string INVISIBLE
-- @field #string HELIPADSINGLE
-- @field #string PADSINGLE
ENUMS.FARPObjectTypeNamesAndShape ={
[ENUMS.FARPType.FARP] = { TypeName="FARP", ShapeName="FARPS"},
[ENUMS.FARPType.INVISIBLE] = { TypeName="Invisible FARP", ShapeName="invisiblefarp"},
[ENUMS.FARPType.HELIPADSINGLE] = { TypeName="SINGLE_HELIPAD", ShapeName="FARP"},
[ENUMS.FARPType.PADSINGLE] = { TypeName="FARP_SINGLE_01", ShapeName="FARP_SINGLE_01"},
}
ENUMS.Storage.weapons.containers.HVAR_rocket = "weapons.containers.HVAR_rocket"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -201,13 +201,6 @@ function CLIENT:AddPlayer(PlayerName)
return self
end
--- Get number of associated players.
-- @param #CLIENT self
-- @return #number Count
function CLIENT:CountPlayers()
return #self.Players or 0
end
--- Get player name(s).
-- @param #CLIENT self
-- @return #table List of player names or an empty table `{}`.
@@ -313,7 +306,7 @@ function CLIENT:IsMultiSeated()
return false
end
--- Checks for a client alive event and calls a function on a continuous basis. Does **NOT** work for dynamic spawn client slots!
--- Checks for a client alive event and calls a function on a continuous basis.
-- @param #CLIENT self
-- @param #function CallBackFunction Create a function that will be called when a player joins the slot.
-- @param ... (Optional) Arguments for callback function as comma separated list.
@@ -332,7 +325,7 @@ end
-- @param #CLIENT self
function CLIENT:_AliveCheckScheduler( SchedulerName )
self:T2( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
self:F3( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
if self:IsAlive() then
@@ -615,3 +608,4 @@ function CLIENT:GetPlayerInfo(Attribute)
return nil
end
end

File diff suppressed because it is too large Load Diff

View File

@@ -1,506 +0,0 @@
--- **Wrapper** - Dynamic Cargo create from the F8 menu.
--
-- ## Main Features:
--
-- * Convenient access to DCS API functions
--
-- ===
--
-- ## Example Missions:
--
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Wrapper/Storage).
--
-- ===
--
-- ### Author: **Applevangelist**
--
-- ===
-- @module Wrapper.DynamicCargo
-- @image Wrapper_Storage.png
--- DYNAMICCARGO class.
-- @type DYNAMICCARGO
-- @field #string ClassName Name of the class.
-- @field #number verbose Verbosity level.
-- @field #string lid Class id string for output to DCS log file.
-- @field Wrapper.Storage#STORAGE warehouse The STORAGE object.
-- @field #string version.
-- @field #string CargoState.
-- @field #table DCS#Vec3 LastPosition.
-- @field #number Interval Check Interval. 20 secs default.
-- @field #boolean testing
-- @field Core.Timer#TIMER timer Timmer to run intervals
-- @field #string Owner The playername who has created, loaded or unloaded this cargo. Depends on state.
-- @extends Wrapper.Positionable#POSITIONABLE
--- *The capitalist cannot store labour-power in warehouses after he has bought it, as he may do with the raw material.* -- Karl Marx
--
-- ===
--
-- # The DYNAMICCARGO Concept
--
-- The DYNAMICCARGO class offers an easy-to-use wrapper interface to all DCS API functions of DCS dynamically spawned cargo crates.
-- We named the class DYNAMICCARGO, because the name WAREHOUSE is already taken by another MOOSE class..
--
-- # Constructor
--
-- @field #DYNAMICCARGO
DYNAMICCARGO = {
ClassName = "DYNAMICCARGO",
verbose = 0,
testing = false,
Interval = 10,
}
--- Liquid types.
-- @type DYNAMICCARGO.Liquid
-- @field #number JETFUEL Jet fuel (0).
-- @field #number GASOLINE Aviation gasoline (1).
-- @field #number MW50 MW50 (2).
-- @field #number DIESEL Diesel (3).
DYNAMICCARGO.Liquid = {
JETFUEL = 0,
GASOLINE = 1,
MW50 = 2,
DIESEL = 3,
}
--- Liquid Names for the static cargo resource table.
-- @type DYNAMICCARGO.LiquidName
-- @field #number JETFUEL "jet_fuel".
-- @field #number GASOLINE "gasoline".
-- @field #number MW50 "methanol_mixture".
-- @field #number DIESEL "diesel".
DYNAMICCARGO.LiquidName = {
GASOLINE = "gasoline",
DIESEL = "diesel",
MW50 = "methanol_mixture",
JETFUEL = "jet_fuel",
}
--- Storage types.
-- @type DYNAMICCARGO.Type
-- @field #number WEAPONS weapons.
-- @field #number LIQUIDS liquids. Also see #list<#DYNAMICCARGO.Liquid> for types of liquids.
-- @field #number AIRCRAFT aircraft.
DYNAMICCARGO.Type = {
WEAPONS = "weapons",
LIQUIDS = "liquids",
AIRCRAFT = "aircrafts",
}
--- State types
-- @type DYNAMICCARGO.State
-- @field #string NEW
-- @field #string LOADED
-- @field #string UNLOADED
-- @field #string REMOVED
DYNAMICCARGO.State = {
NEW = "NEW",
LOADED = "LOADED",
UNLOADED = "UNLOADED",
REMOVED = "REMOVED",
}
--- Helo types possible.
-- @type DYNAMICCARGO.AircraftTypes
DYNAMICCARGO.AircraftTypes = {
["CH-47Fbl1"] = "CH-47Fbl1",
}
--- Helo types possible.
-- @type DYNAMICCARGO.AircraftDimensions
DYNAMICCARGO.AircraftDimensions = {
-- CH-47 model start coordinate is quite exactly in the middle of the model, so half values here
["CH-47Fbl1"] = {
["width"] = 4,
["height"] = 6,
["length"] = 11,
["ropelength"] = 30,
},
}
--- DYNAMICCARGO class version.
-- @field #string version
DYNAMICCARGO.version="0.0.5"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: A lot...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Constructor
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Create a new DYNAMICCARGO object from the DCS static cargo object.
-- @param #DYNAMICCARGO self
-- @param #string CargoName Name of the Cargo.
-- @return #DYNAMICCARGO self
function DYNAMICCARGO:Register(CargoName)
-- Inherit everything from a BASE class.
local self=BASE:Inherit(self, POSITIONABLE:New(CargoName)) -- #DYNAMICCARGO
self.StaticName = CargoName
self.LastPosition = self:GetCoordinate()
self.CargoState = DYNAMICCARGO.State.NEW
self.Interval = DYNAMICCARGO.Interval or 10
local DCSObject = self:GetDCSObject()
if DCSObject then
local warehouse = STORAGE:NewFromDynamicCargo(CargoName)
self.warehouse = warehouse
end
self.lid = string.format("DYNAMICCARGO %s", CargoName)
self.Owner = string.match(CargoName,"^(.+)|%d%d:%d%d|PKG%d+") or "None"
self.timer = TIMER:New(DYNAMICCARGO._UpdatePosition,self)
self.timer:Start(self.Interval,self.Interval)
if not _DYNAMICCARGO_HELOS then
_DYNAMICCARGO_HELOS = SET_CLIENT:New():FilterAlive():FilterFunction(DYNAMICCARGO._FilterHeloTypes):FilterStart()
end
if self.testing then
BASE:TraceOn()
BASE:TraceClass("DYNAMICCARGO")
end
return self
end
--- Get DCS object.
-- @param #DYNAMICCARGO self
-- @return DCS static object
function DYNAMICCARGO:GetDCSObject()
local DCSStatic = Unit.getByName( self.StaticName )
if DCSStatic then
return DCSStatic
end
return nil
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- User API Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Get last known owner name of this DYNAMICCARGO
-- @param #DYNAMICCARGO self
-- @return #string Owner
function DYNAMICCARGO:GetLastOwner()
return self.Owner
end
--- Returns true if the cargo is new and has never been loaded into a Helo.
-- @param #DYNAMICCARGO self
-- @return #boolean Outcome
function DYNAMICCARGO:IsNew()
if self.CargoState and self.CargoState == DYNAMICCARGO.State.NEW then
return true
else
return false
end
end
--- Returns true if the cargo been loaded into a Helo.
-- @param #DYNAMICCARGO self
-- @return #boolean Outcome
function DYNAMICCARGO:IsLoaded()
if self.CargoState and self.CargoState == DYNAMICCARGO.State.LOADED then
return true
else
return false
end
end
--- Returns true if the cargo has been unloaded from a Helo.
-- @param #DYNAMICCARGO self
-- @return #boolean Outcome
function DYNAMICCARGO:IsUnloaded()
if self.CargoState and self.CargoState == DYNAMICCARGO.State.REMOVED then
return true
else
return false
end
end
--- Returns true if the cargo has been removed.
-- @param #DYNAMICCARGO self
-- @return #boolean Outcome
function DYNAMICCARGO:IsRemoved()
if self.CargoState and self.CargoState == DYNAMICCARGO.State.UNLOADED then
return true
else
return false
end
end
--- [CTLD] Get number of crates this DYNAMICCARGO consists of. Always one.
-- @param #DYNAMICCARGO self
-- @return #number crate number, always one
function DYNAMICCARGO:GetCratesNeeded()
return 1
end
--- [CTLD] Get this DYNAMICCARGO drop state. True if DYNAMICCARGO.State.UNLOADED
-- @param #DYNAMICCARGO self
-- @return #boolean Dropped
function DYNAMICCARGO:WasDropped()
return self.CargoState == DYNAMICCARGO.State.UNLOADED and true or false
end
--- [CTLD] Get CTLD_CARGO.Enum type of this DYNAMICCARGO
-- @param #DYNAMICCARGO self
-- @return #string Type, only one at the moment is CTLD_CARGO.Enum.GCLOADABLE
function DYNAMICCARGO:GetType()
return CTLD_CARGO.Enum.GCLOADABLE
end
--- Find last known position of this DYNAMICCARGO
-- @param #DYNAMICCARGO self
-- @return DCS#Vec3 Position in 3D space
function DYNAMICCARGO:GetLastPosition()
return self.LastPosition
end
--- Find current state of this DYNAMICCARGO
-- @param #DYNAMICCARGO self
-- @return string The current state
function DYNAMICCARGO:GetState()
return self.CargoState
end
--- Find a DYNAMICCARGO in the **_DATABASE** using the name associated with it.
-- @param #DYNAMICCARGO self
-- @param #string Name The dynamic cargo name
-- @return #DYNAMICCARGO self
function DYNAMICCARGO:FindByName( Name )
local storage = _DATABASE:FindDynamicCargo( Name )
return storage
end
--- Find the first(!) DYNAMICCARGO matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
-- @param #DYNAMICCARGO self
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
-- @return #DYNAMICCARGO The DYNAMICCARGO.
-- @usage
-- -- Find a dynamic cargo with a partial dynamic cargo name
-- local grp = DYNAMICCARGO:FindByMatching( "Apple" )
-- -- will return e.g. a dynamic cargo named "Apple|08:00|PKG08"
--
-- -- using a pattern
-- local grp = DYNAMICCARGO:FindByMatching( ".%d.%d$" )
-- -- will return the first dynamic cargo found ending in "-1-1" to "-9-9", but not e.g. "-10-1"
function DYNAMICCARGO:FindByMatching( Pattern )
local GroupFound = nil
for name,static in pairs(_DATABASE.DYNAMICCARGO) do
if string.match(name, Pattern ) then
GroupFound = static
break
end
end
return GroupFound
end
--- Find all DYNAMICCARGO objects matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
-- @param #DYNAMICCARGO self
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
-- @return #table Groups Table of matching #DYNAMICCARGO objects found
-- @usage
-- -- Find all dynamic cargo with a partial dynamic cargo name
-- local grptable = DYNAMICCARGO:FindAllByMatching( "Apple" )
-- -- will return all dynamic cargos with "Apple" in the name
--
-- -- using a pattern
-- local grp = DYNAMICCARGO:FindAllByMatching( ".%d.%d$" )
-- -- will return the all dynamic cargos found ending in "-1-1" to "-9-9", but not e.g. "-10-1" or "-1-10"
function DYNAMICCARGO:FindAllByMatching( Pattern )
local GroupsFound = {}
for name,static in pairs(_DATABASE.DYNAMICCARGO) do
if string.match(name, Pattern ) then
GroupsFound[#GroupsFound+1] = static
end
end
return GroupsFound
end
--- Get the #STORAGE object from this dynamic cargo.
-- @param #DYNAMICCARGO self
-- @return Wrapper.Storage#STORAGE Storage The #STORAGE object
function DYNAMICCARGO:GetStorageObject()
return self.warehouse
end
--- Get the weight in kgs from this dynamic cargo.
-- @param #DYNAMICCARGO self
-- @return #number Weight in kgs.
function DYNAMICCARGO:GetCargoWeight()
local DCSObject = self:GetDCSObject()
if DCSObject then
local weight = DCSObject:getCargoWeight()
return weight
else
return 0
end
end
--- Get the cargo display name from this dynamic cargo.
-- @param #DYNAMICCARGO self
-- @return #string The display name
function DYNAMICCARGO:GetCargoDisplayName()
local DCSObject = self:GetDCSObject()
if DCSObject then
local weight = DCSObject:getCargoDisplayName()
return weight
else
return self.StaticName
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Private Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- [Internal] _Get Possible Player Helo Nearby
-- @param #DYNAMICCARGO self
-- @param Core.Point#COORDINATE pos
-- @param #boolean loading If true measure distance for loading else for unloading
-- @return #boolean Success
-- @return Wrapper.Client#CLIENT Helo
-- @return #string PlayerName
function DYNAMICCARGO:_GetPossibleHeloNearby(pos,loading)
local set = _DYNAMICCARGO_HELOS:GetAliveSet()
local success = false
local Helo = nil
local Playername = nil
for _,_helo in pairs (set or {}) do
local helo = _helo -- Wrapper.Client#CLIENT
local name = helo:GetPlayerName() or _DATABASE:_FindPlayerNameByUnitName(helo:GetName()) or "None"
self:T(self.lid.." Checking: "..name)
local hpos = helo:GetCoordinate()
-- TODO Unloading via sling load?
--local inair = hpos.y-hpos:GetLandHeight() > 4.5 and true or false -- Standard FARP is 4.5m
local inair = helo:InAir()
self:T(self.lid.." InAir: AGL/InAir: "..hpos.y-hpos:GetLandHeight().."/"..tostring(inair))
local typename = helo:GetTypeName()
if hpos and typename and inair == false then
local dimensions = DYNAMICCARGO.AircraftDimensions[typename]
if dimensions then
local delta2D = hpos:Get2DDistance(pos)
local delta3D = hpos:Get3DDistance(pos)
if self.testing then
self:T(string.format("Cargo relative position: 2D %dm | 3D %dm",delta2D,delta3D))
self:T(string.format("Helo dimension: length %dm | width %dm | rope %dm",dimensions.length,dimensions.width,dimensions.ropelength))
end
if loading~=true and delta2D > dimensions.length or delta2D > dimensions.width or delta3D > dimensions.ropelength then
success = true
Helo = helo
Playername = name
end
if loading == true and delta2D < dimensions.length or delta2D < dimensions.width or delta3D < dimensions.ropelength then
success = true
Helo = helo
Playername = name
end
end
end
end
return success,Helo,Playername
end
--- [Internal] Update internal states.
-- @param #DYNAMICCARGO self
-- @return #DYNAMICCARGO self
function DYNAMICCARGO:_UpdatePosition()
self:T(self.lid.." _UpdatePositionAndState")
if self:IsAlive() then
local pos = self:GetCoordinate()
if self.testing then
self:T(string.format("Cargo position: x=%d, y=%d, z=%d",pos.x,pos.y,pos.z))
self:T(string.format("Last position: x=%d, y=%d, z=%d",self.LastPosition.x,self.LastPosition.y,self.LastPosition.z))
end
if UTILS.Round(UTILS.VecDist3D(pos,self.LastPosition),2) > 0.5 then
---------------
-- LOAD Cargo
---------------
if self.CargoState == DYNAMICCARGO.State.NEW then
local isloaded, client, playername = self:_GetPossibleHeloNearby(pos,true)
self:T(self.lid.." moved! NEW -> LOADED by "..tostring(playername))
self.CargoState = DYNAMICCARGO.State.LOADED
self.Owner = playername
_DATABASE:CreateEventDynamicCargoLoaded(self)
---------------
-- UNLOAD Cargo
---------------
elseif self.CargoState == DYNAMICCARGO.State.LOADED then
-- TODO add checker if we are in flight somehow
-- ensure not just the helo is moving
local count = _DYNAMICCARGO_HELOS:CountAlive()
-- Testing
local landheight = pos:GetLandHeight()
local agl = pos.y-landheight
agl = UTILS.Round(agl,2)
self:T(self.lid.." AGL: "..agl or -1)
local isunloaded = true
local client
local playername = self.Owner
if count > 0 and (agl > 0 or self.testing) then
self:T(self.lid.." Possible alive helos: "..count or -1)
if agl ~= 0 or self.testing then
isunloaded, client, playername = self:_GetPossibleHeloNearby(pos,false)
end
if isunloaded then
self:T(self.lid.." moved! LOADED -> UNLOADED by "..tostring(playername))
self.CargoState = DYNAMICCARGO.State.UNLOADED
self.Owner = playername
_DATABASE:CreateEventDynamicCargoUnloaded(self)
end
elseif count > 0 and agl == 0 then
self:T(self.lid.." moved! LOADED -> UNLOADED by "..tostring(playername))
self.CargoState = DYNAMICCARGO.State.UNLOADED
self.Owner = playername
_DATABASE:CreateEventDynamicCargoUnloaded(self)
end
end
self.LastPosition = pos
end
else
---------------
-- REMOVED Cargo
---------------
if self.timer and self.timer:IsRunning() then self.timer:Stop() end
self:T(self.lid.." dead! " ..self.CargoState.."-> REMOVED")
self.CargoState = DYNAMICCARGO.State.REMOVED
_DATABASE:CreateEventDynamicCargoRemoved(self)
end
return self
end
--- [Internal] Track helos for loaded/unloaded decision making.
-- @param Wrapper.Client#CLIENT client
-- @return #boolean IsIn
function DYNAMICCARGO._FilterHeloTypes(client)
if not client then return false end
local typename = client:GetTypeName()
local isinclude = DYNAMICCARGO.AircraftTypes[typename] ~= nil and true or false
return isinclude
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@@ -11,8 +11,7 @@
-- @module Wrapper.Identifiable
-- @image MOOSE.JPG
---
-- @type IDENTIFIABLE
--- @type IDENTIFIABLE
-- @extends Wrapper.Object#OBJECT
-- @field #string IdentifiableName The name of the identifiable.
@@ -112,28 +111,19 @@ end
-- * Object.Category.SCENERY = 5
-- * Object.Category.Cargo = 6
--
-- For UNITs this returns a second value, one of
--
-- Unit.Category.AIRPLANE = 0
-- Unit.Category.HELICOPTER = 1
-- Unit.Category.GROUND_UNIT = 2
-- Unit.Category.SHIP = 3
-- Unit.Category.STRUCTURE = 4
--
-- @param #IDENTIFIABLE self
-- @return DCS#Object.Category The category ID, i.e. a number.
-- @return DCS#Unit.Category The unit category ID, i.e. a number. For units only.
function IDENTIFIABLE:GetCategory()
self:F2( self.ObjectName )
local DCSObject = self:GetDCSObject()
if DCSObject then
local ObjectCategory, UnitCategory = DCSObject:getCategory()
local ObjectCategory = DCSObject:getCategory()
self:T3( ObjectCategory )
return ObjectCategory, UnitCategory
return ObjectCategory
end
return nil,nil
return nil
end

View File

@@ -43,7 +43,7 @@ do
-- @field #NET
NET = {
ClassName = "NET",
Version = "0.1.4",
Version = "0.1.3",
BlockTime = 600,
BlockedPilots = {},
BlockedUCIDs = {},
@@ -67,9 +67,6 @@ function NET:New()
self.KnownPilots = {}
self:SetBlockMessage()
self:SetUnblockMessage()
self.BlockedSides = {}
self.BlockedSides[1] = false
self.BlockedSides[2] = false
-- Start State.
self:SetStartState("Stopped")
@@ -163,12 +160,11 @@ end
-- @param #string PlayerSlot
-- @return #boolean IsBlocked
function NET:IsAnyBlocked(UCID,Name,PlayerID,PlayerSide,PlayerSlot)
self:T({UCID,Name,PlayerID,PlayerSide,PlayerSlot})
local blocked = false
local TNow = timer.getTime()
-- UCID
if UCID and self.BlockedUCIDs[UCID] and TNow < self.BlockedUCIDs[UCID] then
blocked = true
return true
end
-- ID/Name
if PlayerID and not Name then
@@ -176,18 +172,16 @@ function NET:IsAnyBlocked(UCID,Name,PlayerID,PlayerSide,PlayerSlot)
end
-- Name
if Name and self.BlockedPilots[Name] and TNow < self.BlockedPilots[Name] then
blocked = true
return true
end
-- Side
self:T({time = self.BlockedSides[PlayerSide]})
if PlayerSide and type(self.BlockedSides[PlayerSide]) == "number" and TNow < self.BlockedSides[PlayerSide] then
blocked = true
if PlayerSide and self.BlockedSides[PlayerSide] and TNow < self.BlockedSides[PlayerSide] then
return true
end
-- Slot
if PlayerSlot and self.BlockedSlots[PlayerSlot] and TNow < self.BlockedSlots[PlayerSlot] then
blocked = true
return true
end
self:T("IsAnyBlocked: "..tostring(blocked))
return blocked
end
@@ -206,27 +200,19 @@ function NET:_EventHandler(EventData)
local ucid = self:GetPlayerUCID(nil,name) or "none"
local PlayerID = self:GetPlayerIDByName(name) or "none"
local PlayerSide, PlayerSlot = self:GetSlot(data.IniUnit)
if not PlayerSide then PlayerSide = EventData.IniCoalition end
if not PlayerSlot then PlayerSlot = EventData.IniUnit:GetID() end
local TNow = timer.getTime()
self:T(self.lid.."Event for: "..name.." | UCID: "..ucid .. " | ID/SIDE/SLOT "..PlayerID.."/"..PlayerSide.."/"..PlayerSlot)
self:T(self.lid.."Event for: "..name.." | UCID: "..ucid)
-- Joining
if data.id == EVENTS.PlayerEnterUnit or data.id == EVENTS.PlayerEnterAircraft then
self:T(self.lid.."Pilot Joining: "..name.." | UCID: "..ucid.." | Event ID: "..data.id)
-- Check for blockages
local blocked = self:IsAnyBlocked(ucid,name,PlayerID,PlayerSide,PlayerSlot)
if blocked and PlayerID then -- and tonumber(PlayerID) ~= 1 then
self:T("Player blocked")
if blocked and PlayerID and tonumber(PlayerID) ~= 1 then
-- block pilot
local outcome = net.force_player_slot(tonumber(PlayerID), PlayerSide, data.IniUnit:GetID() )
self:T({Blocked_worked=outcome})
if outcome == false then
local unit = data.IniUnit
local sched = TIMER:New(unit.Destroy,unit,3):Start(3)
self:__PlayerBlocked(5,unit,name,1)
end
local outcome = net.force_player_slot(tonumber(PlayerID), 0, '' )
else
local client = CLIENT:FindByPlayerName(name) or data.IniUnit
if not self.KnownPilots[name] or (self.KnownPilots[name] and TNow-self.KnownPilots[name].timestamp > 3) then
@@ -239,7 +225,6 @@ function NET:_EventHandler(EventData)
slot = PlayerSlot,
timestamp = TNow,
}
--UTILS.PrintTableToLog(self.KnownPilots[name])
end
return self
end
@@ -365,10 +350,11 @@ end
--- Block a specific coalition side, does NOT automatically kick all players of that side or kick out joined players
-- @param #NET self
-- @param #number Side The side to block - 1 : Red, 2 : Blue
-- @param #number side The side to block - 1 : Red, 2 : Blue
-- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining.
-- @return #NET self
function NET:BlockSide(Side,Seconds)
self:T({Side,Seconds})
local addon = Seconds or self.BlockTime
if Side == 1 or Side == 2 then
self.BlockedSides[Side] = timer.getTime()+addon
@@ -381,9 +367,10 @@ end
-- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining.
-- @return #NET self
function NET:UnblockSide(Side,Seconds)
self:T({Side,Seconds})
local addon = Seconds or self.BlockTime
if Side == 1 or Side == 2 then
self.BlockedSides[Side] = false
self.BlockedSides[Side] = nil
end
return self
end
@@ -498,11 +485,8 @@ end
-- @param Wrapper.Client#CLIENT Client The client
-- @return #number PlayerID or nil
function NET:GetPlayerIDFromClient(Client)
self:T("GetPlayerIDFromClient")
self:T({Client=Client})
if Client then
local name = Client:GetPlayerName()
self:T({name=name})
local id = self:GetPlayerIDByName(name)
return id
else
@@ -544,7 +528,6 @@ function NET:SendChatToPlayer(Message, ToPlayer, FromPlayer)
return self
end
--[[ not in 2.97 MSE any longer
--- Load a specific mission.
-- @param #NET self
-- @param #string Path and Mission
@@ -567,7 +550,6 @@ function NET:LoadNextMission()
outcome = net.load_next_mission()
return outcome
end
--]]
--- Return a table of players currently connected to the server.
-- @param #NET self
@@ -698,19 +680,16 @@ end
-- @return #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue
-- @return #number SlotID
function NET:GetSlot(Client)
self:T("NET.GetSlot")
local PlayerID = self:GetPlayerIDFromClient(Client)
self:T("NET.GetSlot PlayerID = "..tostring(PlayerID))
if PlayerID then
local side,slot = net.get_slot(tonumber(PlayerID))
self:T("NET.GetSlot side, slot = "..tostring(side)..","..tostring(slot))
return side,slot
else
return nil,nil
end
end
--- Force the slot for a specific client. If this returns false, it didn't work via `net` (which is ALWAYS the case as of Nov 2024)!
--- Force the slot for a specific client.
-- @param #NET self
-- @param Wrapper.Client#CLIENT Client The client
-- @param #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue
@@ -718,22 +697,19 @@ end
-- @return #boolean Success
function NET:ForceSlot(Client,SideID,SlotID)
local PlayerID = self:GetPlayerIDFromClient(Client)
local SlotID = SlotID or Client:GetID()
if PlayerID then -- and tonumber(PlayerID) ~= 1 then
return net.force_player_slot(tonumber(PlayerID), SideID, SlotID )
if PlayerID and tonumber(PlayerID) ~= 1 then
return net.force_player_slot(tonumber(PlayerID), SideID, SlotID or '' )
else
return false
end
end
--- Force a client back to spectators. If this returns false, it didn't work via `net` (which is ALWAYS the case as of Nov 2024)!
--- Force a client back to spectators.
-- @param #NET self
-- @param Wrapper.Client#CLIENT Client The client
-- @return #boolean Succes
function NET:ReturnToSpectators(Client)
local outcome = self:ForceSlot(Client,0)
-- workaround
local sched = TIMER:New(Client.Destroy,Client,1):Start(1)
return outcome
end
@@ -747,7 +723,7 @@ end
--- Converts a JSON string to a lua value.
-- @param #string Json Anything JSON
-- @return #table Lua
function NET.Json2Lua(Json)
function NET.Lua2Json(Json)
return net.json2lua(Json)
end
@@ -803,7 +779,7 @@ function NET:onafterStatus(From,Event,To)
local function HouseHold(tavolo)
local TNow = timer.getTime()
for _,entry in pairs (tavolo) do
if type(entry) == "number" and entry >= TNow then entry = false end
if entry >= TNow then entry = nil end
end
end

View File

@@ -671,7 +671,7 @@ function POSITIONABLE:GetBoundingRadius( MinDist )
return math.max( math.max( CX, CZ ), boxmin )
end
BASE:T( { "Cannot GetBoundingRadius", Positionable = self, Alive = self:IsAlive() } )
BASE:E( { "Cannot GetBoundingRadius", Positionable = self, Alive = self:IsAlive() } )
return nil
end
@@ -1853,7 +1853,6 @@ do -- Cargo
["HL_KORD"] = 6*POSITIONABLE.DefaultInfantryWeight,
["HL_DSHK"] = 6*POSITIONABLE.DefaultInfantryWeight,
["CCKW_353"] = 16*POSITIONABLE.DefaultInfantryWeight, --GMC CCKW 2½-ton 6×6 truck, estimating 16 soldiers,
["MaxxPro_MRAP"] = 7*POSITIONABLE.DefaultInfantryWeight,
}
}

View File

@@ -123,38 +123,18 @@ end
--- Check if SCENERY Object is alive.
--@param #SCENERY self
--@param #number Threshold (Optional) If given, SCENERY counts as alive above this relative life in percent (1..100).
--@return #number life
function SCENERY:IsAlive(Threshold)
if not Threshold then
return self:GetLife() >= 1 and true or false
else
return self:GetRelativeLife() > Threshold and true or false
end
function SCENERY:IsAlive()
return self:GetLife() >= 1 and true or false
end
--- Check if SCENERY Object is dead.
--@param #SCENERY self
--@param #number Threshold (Optional) If given, SCENERY counts as dead below this relative life in percent (1..100).
--@return #number life
function SCENERY:IsDead(Threshold)
if not Threshold then
return self:GetLife() < 1 and true or false
else
return self:GetRelativeLife() <= Threshold and true or false
end
function SCENERY:IsDead()
return self:GetLife() < 1 and true or false
end
--- Get SCENERY relative life in percent, e.g. 75.
--@param #SCENERY self
--@return #number rlife
function SCENERY:GetRelativeLife()
local life = self:GetLife()
local life0 = self:GetLife0()
local rlife = math.floor((life/life0)*100)
return rlife
end
--- Get the threat level of a SCENERY object. Always 0 as scenery does not pose a threat to anyone.
--@param #SCENERY self
--@return #number Threat level 0.

View File

@@ -12,8 +12,7 @@
-- @image Wrapper_Static.JPG
---
-- @type STATIC
--- @type STATIC
-- @extends Wrapper.Positionable#POSITIONABLE
--- Wrapper class to handle Static objects.
@@ -61,8 +60,6 @@ function STATIC:Register( StaticName )
if DCSStatic then
local Life0 = DCSStatic:getLife() or 1
self.Life0 = Life0
else
self:E(string.format("Static object %s does not exist!", tostring(self.StaticName)))
end
return self
@@ -180,7 +177,7 @@ end
-- @param #STATIC self
-- @return DCS static object
function STATIC:GetDCSObject()
local DCSStatic = StaticObject.getByName( self.StaticName )
local DCSStatic = StaticObject.getByName( self.StaticName )
if DCSStatic then
return DCSStatic
@@ -239,7 +236,7 @@ function STATIC:SpawnAt(Coordinate, Heading, Delay)
end
--- Respawn the @{Wrapper.Static} at the same location with the same properties.
--- Respawn the @{Wrapper.Unit} at the same location with the same properties.
-- This is useful to respawn a cargo after it has been destroyed.
-- @param #STATIC self
-- @param DCS#country.id CountryID (Optional) The country ID used for spawning the new static. Default is same as currently.
@@ -251,7 +248,7 @@ function STATIC:ReSpawn(CountryID, Delay)
else
CountryID=CountryID or self:GetCountry()
local SpawnStatic=SPAWNSTATIC:NewFromStatic(self.StaticName, CountryID)
SpawnStatic:Spawn(nil, self.StaticName)
@@ -273,8 +270,8 @@ function STATIC:ReSpawnAt(Coordinate, Heading, Delay)
if Delay and Delay>0 then
SCHEDULER:New(nil, self.ReSpawnAt, {self, Coordinate, Heading}, Delay)
else
else
local SpawnStatic=SPAWNSTATIC:NewFromStatic(self.StaticName, self:GetCountry())
SpawnStatic:SpawnFromCoordinate(Coordinate, Heading, self.StaticName)
@@ -283,75 +280,3 @@ function STATIC:ReSpawnAt(Coordinate, Heading, Delay)
return self
end
--- Find the first(!) STATIC matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
-- @param #STATIC self
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
-- @return #STATIC The STATIC.
-- @usage
-- -- Find a static with a partial static name
-- local grp = STATIC:FindByMatching( "Apple" )
-- -- will return e.g. a static named "Apple-1-1"
--
-- -- using a pattern
-- local grp = STATIC:FindByMatching( ".%d.%d$" )
-- -- will return the first static found ending in "-1-1" to "-9-9", but not e.g. "-10-1"
function STATIC:FindByMatching( Pattern )
local GroupFound = nil
for name,static in pairs(_DATABASE.STATICS) do
if string.match(name, Pattern ) then
GroupFound = static
break
end
end
return GroupFound
end
--- Find all STATIC objects matching using patterns. Note that this is **a lot** slower than `:FindByName()`!
-- @param #STATIC self
-- @param #string Pattern The pattern to look for. Refer to [LUA patterns](http://www.easyuo.com/openeuo/wiki/index.php/Lua_Patterns_and_Captures_\(Regular_Expressions\)) for regular expressions in LUA.
-- @return #table Groups Table of matching #STATIC objects found
-- @usage
-- -- Find all static with a partial static name
-- local grptable = STATIC:FindAllByMatching( "Apple" )
-- -- will return all statics with "Apple" in the name
--
-- -- using a pattern
-- local grp = STATIC:FindAllByMatching( ".%d.%d$" )
-- -- will return the all statics found ending in "-1-1" to "-9-9", but not e.g. "-10-1" or "-1-10"
function STATIC:FindAllByMatching( Pattern )
local GroupsFound = {}
for name,static in pairs(_DATABASE.STATICS) do
if string.match(name, Pattern ) then
GroupsFound[#GroupsFound+1] = static
end
end
return GroupsFound
end
--- Get the Wrapper.Storage#STORAGE object of an static if it is used as cargo and has been set up as storage object.
-- @param #STATIC self
-- @return Wrapper.Storage#STORAGE Storage or `nil` if not fund or set up.
function STATIC:GetStaticStorage()
local name = self:GetName()
local storage = STORAGE:NewFromStaticCargo(name)
return storage
end
--- Get the Cargo Weight of a static object in kgs. Returns -1 if not found.
-- @param #STATIC self
-- @return #number Mass Weight in kgs.
function STATIC:GetCargoWeight()
local DCSObject = StaticObject.getByName(self.StaticName )
local mass = -1
if DCSObject then
mass = DCSObject:getCargoWeight() or 0
local masstxt = DCSObject:getCargoDisplayName() or "none"
--BASE:I("GetCargoWeight "..tostring(mass).." MassText "..masstxt)
end
return mass
end

View File

@@ -8,7 +8,7 @@
--
-- ## Example Missions:
--
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Wrapper/Storage).
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Wrapper/Storage).
--
-- ===
--
@@ -33,101 +33,97 @@
-- ===
--
-- # The STORAGE Concept
--
-- The STORAGE class offers an easy-to-use wrapper interface to all DCS API functions of DCS warehouses.
--
-- The STORAGE class offers an easy-to-use wrapper interface to all DCS API functions of DCS warehouses.
-- We named the class STORAGE, because the name WAREHOUSE is already taken by another MOOSE class.
--
--
-- This class allows you to add and remove items to a DCS warehouse, such as aircraft, liquids, weapons and other equipment.
--
--
-- # Constructor
--
--
-- A DCS warehouse is associated with an airbase. Therefore, a `STORAGE` instance is automatically created, once an airbase is registered and added to the MOOSE database.
--
-- You can get the `STORAGE` object from the
--
-- -- Create a STORAGE instance of the Batumi warehouse
--
-- You can get the `STORAGE` object from the
--
-- -- Create a STORAGE instance of the Batumi warehouse
-- local storage=STORAGE:FindByName("Batumi")
--
--
-- An other way to get the `STORAGE` object is to retrieve it from the AIRBASE function `AIRBASE:GetStorage()`
--
--
-- -- Get storage instance of Batumi airbase
-- local Batumi=AIRBASE:FindByName("Batumi")
-- local storage=Batumi:GetStorage()
--
--
-- # Aircraft, Weapons and Equipment
--
--
-- ## Adding Items
--
--
-- To add aircraft, weapons and/or othe equipment, you can use the @{#STORAGE.AddItem}() function
--
--
-- storage:AddItem("A-10C", 3)
-- storage:AddItem("weapons.missiles.AIM_120C", 10)
--
--
-- This will add three A-10Cs and ten AIM-120C missiles to the warehouse inventory.
--
--
-- ## Setting Items
--
--
-- You can also explicitly set, how many items are in the inventory with the @{#STORAGE.SetItem}() function.
--
--
-- ## Removing Items
--
--
-- Items can be removed from the inventory with the @{#STORAGE.RemoveItem}() function.
--
--
-- ## Getting Amount
--
--
-- The number of items currently in the inventory can be obtained with the @{#STORAGE.GetItemAmount}() function
--
--
-- local N=storage:GetItemAmount("A-10C")
-- env.info(string.format("We currently have %d A-10Cs available", N))
--
--
-- # Liquids
--
--
-- Liquids can be added and removed by slightly different functions as described below. Currently there are four types of liquids
--
--
-- * Jet fuel `STORAGE.Liquid.JETFUEL`
-- * Aircraft gasoline `STORAGE.Liquid.GASOLINE`
-- * MW 50 `STORAGE.Liquid.MW50`
-- * Diesel `STORAGE.Liquid.DIESEL`
--
--
-- ## Adding Liquids
--
--
-- To add a certain type of liquid, you can use the @{#STORAGE.AddItem}(Type, Amount) function
--
--
-- storage:AddLiquid(STORAGE.Liquid.JETFUEL, 10000)
-- storage:AddLiquid(STORAGE.Liquid.DIESEL, 20000)
--
--
-- This will add 10,000 kg of jet fuel and 20,000 kg of diesel to the inventory.
--
--
-- ## Setting Liquids
--
--
-- You can also explicitly set the amount of liquid with the @{#STORAGE.SetLiquid}(Type, Amount) function.
--
--
-- ## Removing Liquids
--
--
-- Liquids can be removed with @{#STORAGE.RemoveLiquid}(Type, Amount) function.
--
--
-- ## Getting Amount
--
--
-- The current amount of a certain liquid can be obtained with the @{#STORAGE.GetLiquidAmount}(Type) function
--
--
-- local N=storage:GetLiquidAmount(STORAGE.Liquid.DIESEL)
-- env.info(string.format("We currently have %d kg of Diesel available", N))
--
--
--
--
-- # Inventory
--
--
-- The current inventory of the warehouse can be obtained with the @{#STORAGE.GetInventory}() function. This returns three tables with the aircraft, liquids and weapons:
--
--
-- local aircraft, liquids, weapons=storage:GetInventory()
--
--
-- UTILS.PrintTableToLog(aircraft)
-- UTILS.PrintTableToLog(liquids)
-- UTILS.PrintTableToLog(weapons)
--
-- # Weapons Helper Enumerater
--
-- The currently available weapon items are available in the `ENUMS.Storage.weapons`, e.g. `ENUMS.Storage.weapons.bombs.Mk_82Y`.
--
-- @field #STORAGE
STORAGE = {
ClassName = "STORAGE",
@@ -147,33 +143,9 @@ STORAGE.Liquid = {
DIESEL = 3,
}
--- Liquid Names for the static cargo resource table.
-- @type STORAGE.LiquidName
-- @field #number JETFUEL "jet_fuel".
-- @field #number GASOLINE "gasoline".
-- @field #number MW50 "methanol_mixture".
-- @field #number DIESEL "diesel".
STORAGE.LiquidName = {
GASOLINE = "gasoline",
DIESEL = "diesel",
MW50 = "methanol_mixture",
JETFUEL = "jet_fuel",
}
--- Storage types.
-- @type STORAGE.Type
-- @field #number WEAPONS weapons.
-- @field #number LIQUIDS liquids. Also see #list<#STORAGE.Liquid> for types of liquids.
-- @field #number AIRCRAFT aircraft.
STORAGE.Type = {
WEAPONS = "weapons",
LIQUIDS = "liquids",
AIRCRAFT = "aircrafts",
}
--- STORAGE class version.
-- @field #string version
STORAGE.version="0.0.3"
STORAGE.version="0.0.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@@ -186,7 +158,7 @@ STORAGE.version="0.0.3"
-- Constructor
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Create a new STORAGE object from the DCS airbase object.
--- Create a new STORAGE object from the DCS weapon object.
-- @param #STORAGE self
-- @param #string AirbaseName Name of the airbase.
-- @return #STORAGE self
@@ -196,7 +168,7 @@ function STORAGE:New(AirbaseName)
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
self.airbase=Airbase.getByName(AirbaseName)
if Airbase.getWarehouse then
self.warehouse=self.airbase:getWarehouse()
end
@@ -206,48 +178,8 @@ function STORAGE:New(AirbaseName)
return self
end
--- Create a new STORAGE object from an DCS static cargo object.
-- @param #STORAGE self
-- @param #string StaticCargoName Unit name of the static.
-- @return #STORAGE self
function STORAGE:NewFromStaticCargo(StaticCargoName)
-- Inherit everything from BASE class.
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
self.airbase=StaticObject.getByName(StaticCargoName)
if Airbase.getWarehouse then
self.warehouse=Warehouse.getCargoAsWarehouse(self.airbase)
end
self.lid = string.format("STORAGE %s", StaticCargoName)
return self
end
--- Create a new STORAGE object from an DCS static cargo object.
-- @param #STORAGE self
-- @param #string DynamicCargoName Unit name of the dynamic cargo.
-- @return #STORAGE self
function STORAGE:NewFromDynamicCargo(DynamicCargoName)
-- Inherit everything from BASE class.
local self=BASE:Inherit(self, BASE:New()) -- #STORAGE
self.airbase=Unit.getByName(DynamicCargoName)
if Airbase.getWarehouse then
self.warehouse=Warehouse.getCargoAsWarehouse(self.airbase)
end
self.lid = string.format("STORAGE %s", DynamicCargoName)
return self
end
--- Airbases only - Find a STORAGE in the **_DATABASE** using the name associated airbase.
--- Find a STORAGE in the **_DATABASE** using the name associated airbase.
-- @param #STORAGE self
-- @param #string AirbaseName The Airbase Name.
-- @return #STORAGE self
@@ -390,7 +322,7 @@ end
function STORAGE:GetLiquidName(Type)
local name="Unknown"
if Type==STORAGE.Liquid.JETFUEL then
name = "Jet fuel"
elseif Type==STORAGE.Liquid.GASOLINE then
@@ -474,30 +406,30 @@ end
--- Returns whether a given type of aircraft, liquid, weapon is set to be unlimited.
-- @param #STORAGE self
-- @param #string Type Name of aircraft, weapon or equipment or type of liquid (as `#number`).
-- @return #boolean If `true` the given type is unlimited or `false` otherwise.
-- @return #boolen If `true` the given type is unlimited or `false` otherwise.
function STORAGE:IsUnlimited(Type)
-- Get current amount of type.
local N=self:GetAmount(Type)
local unlimited=false
if N>0 then
-- Remove one item.
self:RemoveAmount(Type, 1)
-- Get amount.
local n=self:GetAmount(Type)
-- If amount did not change, it is unlimited.
unlimited=unlimited or n > 2^29 or n==N
unlimited=n==N
-- Add item back.
if not unlimited then
self:AddAmount(Type, 1)
end
-- Debug info.
self:I(self.lid..string.format("Type=%s: unlimited=%s (N=%d n=%d)", tostring(Type), tostring(unlimited), N, n))
end
@@ -508,7 +440,7 @@ end
--- Returns whether a given type of aircraft, liquid, weapon is set to be limited.
-- @param #STORAGE self
-- @param #number Type Type of liquid or name of aircraft, weapon or equipment.
-- @return #boolean If `true` the given type is limited or `false` otherwise.
-- @return #boolen If `true` the given type is limited or `false` otherwise.
function STORAGE:IsLimited(Type)
local limited=not self:IsUnlimited(Type)
@@ -518,7 +450,7 @@ end
--- Returns whether aircraft are unlimited.
-- @param #STORAGE self
-- @return #boolean If `true` aircraft are unlimited or `false` otherwise.
-- @return #boolen If `true` aircraft are unlimited or `false` otherwise.
function STORAGE:IsUnlimitedAircraft()
-- We test with a specific type but if it is unlimited, than all aircraft are.
@@ -529,7 +461,7 @@ end
--- Returns whether liquids are unlimited.
-- @param #STORAGE self
-- @return #boolean If `true` liquids are unlimited or `false` otherwise.
-- @return #boolen If `true` liquids are unlimited or `false` otherwise.
function STORAGE:IsUnlimitedLiquids()
-- We test with a specific type but if it is unlimited, than all are.
@@ -540,7 +472,7 @@ end
--- Returns whether weapons and equipment are unlimited.
-- @param #STORAGE self
-- @return #boolean If `true` weapons and equipment are unlimited or `false` otherwise.
-- @return #boolen If `true` weapons and equipment are unlimited or `false` otherwise.
function STORAGE:IsUnlimitedWeapons()
-- We test with a specific type but if it is unlimited, than all are.
@@ -551,7 +483,7 @@ end
--- Returns whether aircraft are limited.
-- @param #STORAGE self
-- @return #boolean If `true` aircraft are limited or `false` otherwise.
-- @return #boolen If `true` aircraft are limited or `false` otherwise.
function STORAGE:IsLimitedAircraft()
-- We test with a specific type but if it is limited, than all are.
@@ -562,7 +494,7 @@ end
--- Returns whether liquids are limited.
-- @param #STORAGE self
-- @return #boolean If `true` liquids are limited or `false` otherwise.
-- @return #boolen If `true` liquids are limited or `false` otherwise.
function STORAGE:IsLimitedLiquids()
-- We test with a specific type but if it is limited, than all are.
@@ -573,7 +505,7 @@ end
--- Returns whether weapons and equipment are limited.
-- @param #STORAGE self
-- @return #boolean If `true` liquids are limited or `false` otherwise.
-- @return #boolen If `true` liquids are limited or `false` otherwise.
function STORAGE:IsLimitedWeapons()
-- We test with a specific type but if it is limited, than all are.
@@ -591,7 +523,7 @@ end
function STORAGE:GetInventory(Item)
local inventory=self.warehouse:getInventory(Item)
return inventory.aircraft, inventory.liquids, inventory.weapon
end

View File

@@ -219,7 +219,6 @@ function UNIT:Name()
return self.UnitName
end
--[[
--- Get the DCS unit object.
-- @param #UNIT self
-- @return DCS#Unit The DCS unit object.
@@ -231,36 +230,10 @@ function UNIT:GetDCSObject()
return DCSUnit
end
return nil
end
--]]
--- Returns the DCS Unit.
-- @param #UNIT self
-- @return DCS#Unit The DCS Group.
function UNIT:GetDCSObject()
-- FF: Added checks that DCSObject exists because otherwise there were problems when respawning the unit right after it was initially spawned (e.g. teleport in OPSGROUP).
-- Got "Unit does not exit" after coalition.addGroup() when trying to access unit data because LastCallDCSObject<=1.
if (not self.LastCallDCSObject) or (self.LastCallDCSObject and timer.getTime()-self.LastCallDCSObject>1) or (self.DCSObject==nil) or (self.DCSObject:isExist()==false) then
-- Get DCS group.
local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then
self.LastCallDCSObject = timer.getTime()
self.DCSObject = DCSUnit
return DCSUnit
else
self.DCSObject = nil
self.LastCallDCSObject = nil
end
--if self.DCSUnit then
--return self.DCSUnit
--end
else
return self.DCSObject
end
--self:E(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.UnitName)))
return nil
end
@@ -270,7 +243,7 @@ end
-- @return #number The height of the group or nil if is not existing or alive.
function UNIT:GetAltitude(FromGround)
local DCSUnit = self:GetDCSObject()
local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then
local altitude = 0
@@ -300,12 +273,12 @@ end
-- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawnAt( Coordinate, Heading )
--self:T( self:Name() )
self:T( self:Name() )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
--self:T( SpawnGroupTemplate )
self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup()
--self:T( { SpawnGroup = SpawnGroup } )
self:T( { SpawnGroup = SpawnGroup } )
if SpawnGroup then
@@ -313,10 +286,10 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.x = Coordinate.x
SpawnGroupTemplate.y = Coordinate.z
--self:F( #SpawnGroupTemplate.units )
self:F( #SpawnGroupTemplate.units )
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() or {} ) do
local GroupUnit = UnitData -- #UNIT
--self:F( GroupUnit:GetName() )
self:F( GroupUnit:GetName() )
if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading()
@@ -324,23 +297,23 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x
SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z
SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading
--self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } )
self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } )
end
end
end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
--self:T( { UnitTemplateData.name, self:Name() } )
self:T( { UnitTemplateData.name, self:Name() } )
SpawnGroupTemplate.units[UnitTemplateID].unitId = nil
if UnitTemplateData.name == self:Name() then
--self:T("Adjusting")
self:T("Adjusting")
SpawnGroupTemplate.units[UnitTemplateID].alt = Coordinate.y
SpawnGroupTemplate.units[UnitTemplateID].x = Coordinate.x
SpawnGroupTemplate.units[UnitTemplateID].y = Coordinate.z
SpawnGroupTemplate.units[UnitTemplateID].heading = Heading
--self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
else
--self:F( SpawnGroupTemplate.units[UnitTemplateID].name )
self:F( SpawnGroupTemplate.units[UnitTemplateID].name )
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT
if GroupUnit and GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3()
@@ -351,7 +324,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
UnitTemplateData.heading = GroupUnitHeading
else
if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then
--self:T("nilling")
self:T("nilling")
SpawnGroupTemplate.units[UnitTemplateID].delete = true
end
end
@@ -363,7 +336,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
while i <= #SpawnGroupTemplate.units do
local UnitTemplateData = SpawnGroupTemplate.units[i]
--self:T( UnitTemplateData.name )
self:T( UnitTemplateData.name )
if UnitTemplateData.delete then
table.remove( SpawnGroupTemplate.units, i )
@@ -374,7 +347,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.groupId = nil
--self:T( SpawnGroupTemplate )
self:T( SpawnGroupTemplate )
_DATABASE:Spawn( SpawnGroupTemplate )
end
@@ -385,7 +358,7 @@ end
-- @param #UNIT self
-- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive.
function UNIT:IsActive()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -422,7 +395,7 @@ end
-- @param #UNIT self
-- @return #boolean Returns `true` if Unit is alive and active, `false` if it exists but is not active and `nil` if the object does not exist or DCS `isExist` function returns false.
function UNIT:IsAlive()
--self:F3( self.UnitName )
self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit
@@ -445,7 +418,7 @@ end
-- @param #UNIT self
-- @return #string The Callsign of the Unit.
function UNIT:GetCallsign()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -457,7 +430,7 @@ function UNIT:GetCallsign()
return UnitCallSign
end
--self:F( self.ClassName .. " " .. self.UnitName .. " not found!" )
self:F( self.ClassName .. " " .. self.UnitName .. " not found!" )
return nil
end
@@ -472,18 +445,7 @@ function UNIT:IsPlayer()
if not group then return false end
-- Units of template group.
local template = group:GetTemplate()
if (template == nil) or (template.units == nil ) then
local DCSObject = self:GetDCSObject()
if DCSObject then
if DCSObject:getPlayerName() ~= nil then return true else return false end
else
return false
end
end
local units=template.units
local units=group:GetTemplate().units
-- Get numbers.
for _,unit in pairs(units) do
@@ -504,7 +466,7 @@ end
-- @return #string Player Name
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPlayerName()
--self:F( self.UnitName )
self:F( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit
@@ -578,7 +540,7 @@ end
-- @return #number The Unit number.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetNumber()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -595,7 +557,7 @@ end
-- @param #UNIT self
-- @return #number Speed in km/h.
function UNIT:GetSpeedMax()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local Desc = self:GetDesc()
@@ -612,7 +574,7 @@ end
-- @param #UNIT self
-- @return #number Range in meters.
function UNIT:GetRange()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local Desc = self:GetDesc()
@@ -634,7 +596,7 @@ end
-- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable").
-- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsRefuelable()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local refuelable=self:HasAttribute("Refuelable")
@@ -653,7 +615,7 @@ end
-- @return #boolean If true, unit is a tanker (checks for the attribute "Tankers").
-- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsTanker()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local tanker=self:HasAttribute("Tankers")
@@ -752,7 +714,7 @@ end
-- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist.
function UNIT:GetGroup()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local UnitGroup = GROUP:FindByName(self.GroupName)
if UnitGroup then
return UnitGroup
@@ -776,13 +738,13 @@ end
-- @return #string The name of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPrefix()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 )
--self:T3( UnitPrefix )
self:T3( UnitPrefix )
return UnitPrefix
end
@@ -793,7 +755,7 @@ end
-- @param #UNIT self
-- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table!
function UNIT:GetAmmo()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
--local status, unitammo = pcall(
@@ -827,13 +789,11 @@ end
--- Get the number of ammunition and in particular the number of shells, rockets, bombs and missiles a unit currently has.
-- @param #UNIT self
-- @return #number Total amount of ammo the unit has left. This is the sum of shells, rockets, bombs and missiles.
-- @return #number Number of shells left. Shells include MG ammunition, AP and HE shells, and artillery shells where applicable.
-- @return #number Number of shells left.
-- @return #number Number of rockets left.
-- @return #number Number of bombs left.
-- @return #number Number of missiles left.
-- @return #number Number of artillery shells left (with explosive mass, included in shells; HE will also be reported as artillery shells for tanks)
-- @return #number Number of tank AP shells left (for tanks, if applicable)
-- @return #number Number of tank HE shells left (for tanks, if applicable)
-- @return #number Number of artillery shells left (with explosive mass, included in shells; shells can also be machine gun ammo)
function UNIT:GetAmmunition()
-- Init counter.
@@ -843,8 +803,6 @@ function UNIT:GetAmmunition()
local nmissiles=0
local nbombs=0
local narti=0
local nAPshells = 0
local nHEshells = 0
local unit=self
@@ -886,14 +844,6 @@ function UNIT:GetAmmunition()
narti=narti+Nammo
end
if ammotable[w].desc.typeName and string.find(ammotable[w].desc.typeName,"_AP",1,true) then
nAPshells = nAPshells+Nammo
end
if ammotable[w].desc.typeName and string.find(ammotable[w].desc.typeName,"_HE",1,true) then
nHEshells = nHEshells+Nammo
end
elseif Category==Weapon.Category.ROCKET then
-- Add up all rockets.
@@ -930,62 +880,14 @@ function UNIT:GetAmmunition()
-- Total amount of ammunition.
nammo=nshells+nrockets+nmissiles+nbombs
return nammo, nshells, nrockets, nbombs, nmissiles, narti, nAPshells, nHEshells
end
--- Checks if a tank still has AP shells.
-- @param #UNIT self
-- @return #boolean HasAPShells
function UNIT:HasAPShells()
local _,_,_,_,_,_,shells = self:GetAmmunition()
if shells > 0 then return true else return false end
end
--- Get number of AP shells from a tank.
-- @param #UNIT self
-- @return #number Number of AP shells
function UNIT:GetAPShells()
local _,_,_,_,_,_,shells = self:GetAmmunition()
return shells or 0
end
--- Get number of HE shells from a tank.
-- @param #UNIT self
-- @return #number Number of HE shells
function UNIT:GetHEShells()
local _,_,_,_,_,_,_,shells = self:GetAmmunition()
return shells or 0
end
--- Checks if a tank still has HE shells.
-- @param #UNIT self
-- @return #boolean HasHEShells
function UNIT:HasHEShells()
local _,_,_,_,_,_,_,shells = self:GetAmmunition()
if shells > 0 then return true else return false end
end
--- Checks if an artillery unit still has artillery shells.
-- @param #UNIT self
-- @return #boolean HasArtiShells
function UNIT:HasArtiShells()
local _,_,_,_,_,shells = self:GetAmmunition()
if shells > 0 then return true else return false end
end
--- Get number of artillery shells from an artillery unit.
-- @param #UNIT self
-- @return #number Number of artillery shells
function UNIT:GetArtiShells()
local _,_,_,_,_,shells = self:GetAmmunition()
return shells or 0
return nammo, nshells, nrockets, nbombs, nmissiles, narti
end
--- Returns the unit sensors.
-- @param #UNIT self
-- @return DCS#Unit.Sensors Table of sensors.
function UNIT:GetSensors()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -1004,7 +906,7 @@ end
-- @param #UNIT self
-- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors.
function UNIT:HasSensors( ... )
--self:F2( arg )
self:F2( arg )
local DCSUnit = self:GetDCSObject()
@@ -1020,7 +922,7 @@ end
-- @param #UNIT self
-- @return #boolean returns true if the unit is SEADable.
function UNIT:HasSEAD()
--self:F2()
self:F2()
local DCSUnit = self:GetDCSObject()
@@ -1048,7 +950,7 @@ end
-- @return #boolean Indicates if at least one of the unit's radar(s) is on.
-- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
function UNIT:GetRadar()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -1064,7 +966,7 @@ end
-- @param #UNIT self
-- @return #number The relative amount of fuel (from 0.0 to 1.0) or *nil* if the DCS Unit is not existing or alive.
function UNIT:GetFuel()
--self:F3( self.UnitName )
self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -1081,14 +983,14 @@ end
-- @param #UNIT self
-- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}.
function UNIT:GetUnits()
--self:F3( { self.UnitName } )
self:F3( { self.UnitName } )
local DCSUnit = self:GetDCSObject()
local Units = {}
if DCSUnit then
Units[1] = UNIT:Find( DCSUnit )
-self:T3( Units )
self:T3( Units )
return Units
end
@@ -1100,7 +1002,7 @@ end
-- @param #UNIT self
-- @return #number The Unit's health value or -1 if unit does not exist any more.
function UNIT:GetLife()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -1116,7 +1018,7 @@ end
-- @param #UNIT self
-- @return #number The Unit's initial health value or 0 if unit does not exist any more.
function UNIT:GetLife0()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
@@ -1132,7 +1034,7 @@ end
-- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more.
function UNIT:GetLifeRelative()
--self:F2(self.UnitName)
self:F2(self.UnitName)
if self and self:IsAlive() then
local life0=self:GetLife0()
@@ -1147,7 +1049,7 @@ end
-- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more.
function UNIT:GetDamageRelative()
--self:F2(self.UnitName)
self:F2(self.UnitName)
if self and self:IsAlive() then
return 1-self:GetLifeRelative()
@@ -1185,7 +1087,7 @@ end
-- @param #UNIT self
-- @return #number Unit category from `getDesc().category`.
function UNIT:GetUnitCategory()
--self:F3( self.UnitName )
self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
@@ -1199,7 +1101,7 @@ end
-- @param #UNIT self
-- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship
function UNIT:GetCategoryName()
--self:F3( self.UnitName )
self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
@@ -1211,7 +1113,7 @@ function UNIT:GetCategoryName()
[Unit.Category.STRUCTURE] = "Structure",
}
local UnitCategory = DCSUnit:getDesc().category
--self:T3( UnitCategory )
self:T3( UnitCategory )
return CategoryNames[UnitCategory]
end
@@ -1290,17 +1192,17 @@ function UNIT:GetThreatLevel()
if self:IsGround() then
local ThreatLevels = {
[1] = "Unarmed",
[2] = "Infantry",
[3] = "Old Tanks & APCs",
[4] = "Tanks & IFVs without ATGM",
[5] = "Tanks & IFV with ATGM",
[6] = "Modern Tanks",
[7] = "AAA",
[8] = "IR Guided SAMs",
[9] = "SR SAMs",
[10] = "MR SAMs",
[11] = "LR SAMs"
"Unarmed",
"Infantry",
"Old Tanks & APCs",
"Tanks & IFVs without ATGM",
"Tanks & IFV with ATGM",
"Modern Tanks",
"AAA",
"IR Guided SAMs",
"SR SAMs",
"MR SAMs",
"LR SAMs"
}
@@ -1326,25 +1228,23 @@ function UNIT:GetThreatLevel()
if self:IsAir() then
local ThreatLevels = {
[1] = "Unarmed",
[2] = "Tanker",
[3] = "AWACS",
[4] = "Transport Helicopter",
[5] = "UAV",
[6] = "Bomber",
[7] = "Strategic Bomber",
[8] = "Attack Helicopter",
[9] = "Battleplane",
[10] = "Multirole Fighter",
[11] = "Fighter"
"Unarmed",
"Tanker",
"AWACS",
"Transport Helicopter",
"UAV",
"Bomber",
"Strategic Bomber",
"Attack Helicopter",
"Battleplane",
"Multirole Fighter",
"Fighter"
}
if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9
elseif Attributes["Interceptors"] then ThreatLevel = 9
elseif Attributes["Battleplanes"] then ThreatLevel = 8
elseif Attributes["Battle airplanes"] then ThreatLevel = 8
elseif Attributes["Attack helicopters"] then ThreatLevel = 7
elseif Attributes["Strategic bombers"] then ThreatLevel = 6
elseif Attributes["Bombers"] then ThreatLevel = 5
@@ -1370,17 +1270,17 @@ function UNIT:GetThreatLevel()
--["Unarmed ships"] = {"Ships","HeavyArmoredUnits",},
local ThreatLevels = {
[1] = "Unarmed ship",
[2] = "Light armed ships",
[3] = "Corvettes",
[4] = "",
[5] = "Frigates",
[6] = "",
[7] = "Cruiser",
[8] = "",
[9] = "Destroyer",
[10] = "",
[11] = "Aircraft Carrier"
"Unarmed ship",
"Light armed ships",
"Corvettes",
"",
"Frigates",
"",
"Cruiser",
"",
"Destroyer",
"",
"Aircraft Carrier"
}
@@ -1439,7 +1339,7 @@ end
-- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
--self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } )
self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } )
local DCSUnit = self:GetDCSObject()
@@ -1448,10 +1348,10 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
local AwaitUnitVec3 = AwaitUnit:GetVec3()
if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then
--self:T3( "true" )
self:T3( "true" )
return true
else
--self:T3( "false" )
self:T3( "false" )
return false
end
end
@@ -1469,17 +1369,17 @@ end
-- @param #UNIT self
-- @return #boolean IsFriendly evaluation result.
function UNIT:IsFriendly( FriendlyCoalition )
--self:F2()
self:F2()
local DCSUnit = self:GetDCSObject()
if DCSUnit then
local UnitCoalition = DCSUnit:getCoalition()
--self:T3( { UnitCoalition, FriendlyCoalition } )
self:T3( { UnitCoalition, FriendlyCoalition } )
local IsFriendlyResult = ( UnitCoalition == FriendlyCoalition )
--self:F( IsFriendlyResult )
self:F( IsFriendlyResult )
return IsFriendlyResult
end
@@ -1491,17 +1391,17 @@ end
-- @param #UNIT self
-- @return #boolean Ship category evaluation result.
function UNIT:IsShip()
--self:F2()
self:F2()
local DCSUnit = self:GetDCSObject()
if DCSUnit then
local UnitDescriptor = DCSUnit:getDesc()
--self:T3( { UnitDescriptor.category, Unit.Category.SHIP } )
self:T3( { UnitDescriptor.category, Unit.Category.SHIP } )
local IsShipResult = ( UnitDescriptor.category == Unit.Category.SHIP )
--self:T3( IsShipResult )
self:T3( IsShipResult )
return IsShipResult
end
@@ -1513,7 +1413,7 @@ end
-- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed.
-- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive.
function UNIT:InAir(NoHeloCheck)
--self:F2( self.UnitName )
self:F2( self.UnitName )
-- Get DCS unit object.
local DCSUnit = self:GetDCSObject() --DCS#Unit
@@ -1527,7 +1427,7 @@ function UNIT:InAir(NoHeloCheck)
local UnitCategory = DCSUnit:getDesc().category
-- If DCS says that it is in air, check if this is really the case, since we might have landed on a building where inAir()=true but actually is not.
-- This is a workaround since DCS currently does not acknowledge that helos land on buildings.
-- This is a workaround since DCS currently does not acknoledge that helos land on buildings.
-- Note however, that the velocity check will fail if the ground is moving, e.g. on an aircraft carrier!
if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER and (not NoHeloCheck) then
local VelocityVec3 = DCSUnit:getVelocity()
@@ -1540,7 +1440,7 @@ function UNIT:InAir(NoHeloCheck)
end
end
--self:T3( UnitInAir )
self:T3( UnitInAir )
return UnitInAir
end
@@ -1735,7 +1635,7 @@ end
-- @param #boolean switch If true, emission is enabled. If false, emission is disabled.
-- @return #UNIT self
function UNIT:EnableEmission(switch)
--self:F2( self.UnitName )
self:F2( self.UnitName )
local switch = switch or false
@@ -1754,12 +1654,9 @@ end
-- @param #UNIT self
-- @return #string Skill String of skill name.
function UNIT:GetSkill()
--self:F2( self.UnitName )
self:F2( self.UnitName )
local name = self.UnitName
local skill = "Random"
if _DATABASE.Templates.Units[name] and _DATABASE.Templates.Units[name].Template and _DATABASE.Templates.Units[name].Template.skill then
skill = _DATABASE.Templates.Units[name].Template.skill or "Random"
end
local skill = _DATABASE.Templates.Units[name].Template.skill or "Random"
return skill
end
@@ -1770,7 +1667,7 @@ end
-- @return #string VCN Voice Callsign Number or nil if not set/capable.
-- @return #string Lead If true, unit is Flight Lead, else false or nil.
function UNIT:GetSTN()
--self:F2(self.UnitName)
self:F2(self.UnitName)
local STN = nil -- STN/TN
local VCL = nil -- VoiceCallsignLabel
local VCN = nil -- VoiceCallsignNumber

View File

@@ -14,7 +14,7 @@
--
-- ## Additional Material:
--
-- * **Demo Missions:** [GitHub](https://github.com/FlightControl-Master/MOOSE_Demos/tree/master/Wrapper/Weapon)
-- * **Demo Missions:** [GitHub](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Wrapper/Weapon)
-- * **YouTube videos:** None
-- * **Guides:** None
--
@@ -40,7 +40,6 @@
-- @field #number coalition Coalition ID.
-- @field #number country Country ID.
-- @field DCS#Desc desc Descriptor table.
-- @field DCS#Desc guidance Missile guidance descriptor.
-- @field DCS#Unit launcher Launcher DCS unit.
-- @field Wrapper.Unit#UNIT launcherUnit Launcher Unit.
-- @field #string launcherName Name of launcher unit.
@@ -70,77 +69,77 @@
-- ===
--
-- # The WEAPON Concept
--
--
-- The WEAPON class offers an easy-to-use wrapper interface to all DCS API functions.
--
--
-- Probably, the most striking highlight is that the position of the weapon can be tracked and its impact position can be determined, which is not
-- possible with the native DCS scripting engine functions.
--
-- **Note** that this wrapper class is different from most others as weapon objects cannot be found with a DCS API function like `getByName()`.
-- They can only be found in DCS events like the "Shot" event, where the weapon object is contained in the event data.
--
--
-- # Tracking
--
--
-- The status of the weapon can be tracked with the @{#WEAPON.StartTrack} function. This function will try to determin the position of the weapon in (normally) relatively
-- small time steps. The time step can be set via the @{#WEAPON.SetTimeStepTrack} function and is by default set to 0.01 seconds.
--
--
-- Once the position cannot be retrieved any more, the weapon has impacted (or was destroyed otherwise) and the last known position is safed as the impact point.
-- The impact point can be accessed with the @{#WEAPON.GetImpactVec3} or @{#WEAPON.GetImpactCoordinate} functions.
--
--
-- ## Impact Point Marking
--
--
-- You can mark the impact point on the F10 map with @{#WEAPON.SetMarkImpact}.
--
--
-- You can also trigger coloured smoke at the impact point via @{#WEAPON.SetSmokeImpact}.
--
--
-- ## Callback functions
--
--
-- It is possible to define functions that are called during the tracking of the weapon and upon impact, which help you to customize further actions.
--
--
-- ### Callback on Impact
--
--
-- The function called on impact can be set with @{#WEAPON.SetFuncImpact}
--
--
-- ### Callback when Tracking
--
--
-- The function called each time the weapon status is tracked can be set with @{#WEAPON.SetFuncTrack}
--
--
-- # Target
--
-- If the weapon has a specific target, you can get it with the @{#WEAPON.GetTarget} function. Note that the object, which is returned can vary. Normally, it is a UNIT
--
-- If the weapon has a specific target, you can get it with the @{#WEAPON.GetTarget} function. Note that the object, which is returned can vary. Normally, it is a UNIT
-- but it could also be a STATIC object.
--
--
-- Also note that the weapon does not always have a target, it can loose a target and re-aquire it and the target might change to another unit.
--
--
-- You can get the target name with the @{#WEAPON.GetTargetName} function.
--
--
-- The distance to the target is returned by the @{#WEAPON.GetTargetDistance} function.
--
--
-- # Category
--
--
-- The category (bomb, rocket, missile, shell, torpedo) of the weapon can be retrieved with the @{#WEAPON.GetCategory} function.
--
-- You can check if the weapon is a
--
--
-- You can check if the weapon is a
--
-- * bomb with @{#WEAPON.IsBomb}
-- * rocket with @{#WEAPON.IsRocket}
-- * missile with @{#WEAPON.IsMissile}
-- * shell with @{#WEAPON.IsShell}
-- * torpedo with @{#WEAPON.IsTorpedo}
--
--
-- # Parameters
--
--
-- You can get various parameters of the weapon, *e.g.*
--
--
-- * position: @{#WEAPON.GetVec3}, @{#WEAPON.GetVec2 }, @{#WEAPON.GetCoordinate}
-- * speed: @{#WEAPON.GetSpeed}
-- * coalition: @{#WEAPON.GetCoalition}
-- * country: @{#WEAPON.GetCountry}
--
--
-- # Dependencies
--
--
-- This class is used (at least) in the MOOSE classes:
--
--
-- * RANGE (to determine the impact points of bombs and missiles)
-- * ARTY (to destroy and replace shells with smoke or illumination)
-- * FOX (to destroy the missile before it hits the target)
@@ -182,51 +181,48 @@ function WEAPON:New(WeaponObject)
-- Inherit everything from FSM class.
local self=BASE:Inherit(self, POSITIONABLE:New("Weapon")) -- #WEAPON
-- Set DCS weapon object.
self.weapon=WeaponObject
-- Descriptors containing a lot of info.
self.desc=WeaponObject:getDesc()
-- This gives the object category which is always Object.Category.WEAPON!
--self.category=WeaponObject:getCategory()
-- Weapon category: 0=SHELL, 1=MISSILE, 2=ROCKET, 3=BOMB (Weapon.Category.X)
self.category = self.desc.category
if self:IsMissile() and self.desc.missileCategory then
if self:IsMissile() and self.desc.missileCategory then
self.categoryMissile=self.desc.missileCategory
if self.desc.guidance then
self.guidance = self.desc.guidance
end
end
-- Get type name.
self.typeName=WeaponObject:getTypeName() or "Unknown Type"
-- Get name of object. Usually a number like "1234567".
self.name=WeaponObject:getName()
-- Get coaliton of weapon.
self.coalition=WeaponObject:getCoalition()
-- Get country of weapon.
self.country=WeaponObject:getCountry()
-- Get DCS unit of the launcher.
self.launcher=WeaponObject:getLauncher()
-- Get launcher of weapon.
self.launcherName="Unknown Launcher"
if self.launcher then
self.launcherName=self.launcher:getName()
self.launcherUnit=UNIT:Find(self.launcher)
end
-- Init the coordinate of the weapon from that of the launcher.
self.coordinate=COORDINATE:NewFromVec3(self.launcher:getPoint())
-- Set log ID.
self.lid=string.format("[%s] %s | ", self.typeName, self.name)
@@ -241,12 +237,12 @@ function WEAPON:New(WeaponObject)
-- Set default parameters
self:SetTimeStepTrack()
self:SetDistanceInterceptPoint()
-- Debug info.
local text=string.format("Weapon v%s\nName=%s, TypeName=%s, Category=%s, Coalition=%d, Country=%d, Launcher=%s",
local text=string.format("Weapon v%s\nName=%s, TypeName=%s, Category=%s, Coalition=%d, Country=%d, Launcher=%s",
self.version, self.name, self.typeName, self.category, self.coalition, self.country, self.launcherName)
self:T(self.lid..text)
-- Descriptors.
self:T2(self.desc)
@@ -316,13 +312,13 @@ function WEAPON:SetSmokeImpact(Switch, SmokeColor)
else
self.impactSmoke=true
end
self.impactSmokeColor=SmokeColor or SMOKECOLOR.Red
return self
end
--- Set callback function when weapon is tracked and still alive. The first argument will be the WEAPON object.
--- Set callback function when weapon is tracked and still alive. The first argument will be the WEAPON object.
-- Note that this can be called many times per second. So be careful for performance reasons.
-- @param #WEAPON self
-- @param #function FuncTrack Function called during tracking.
@@ -339,19 +335,19 @@ end
-- @param #function FuncImpact Function called once the weapon impacted.
-- @param ... Optional function arguments.
-- @return #WEAPON self
--
--
-- @usage
-- -- Function called on impact.
-- local function OnImpact(Weapon)
-- Weapon:GetImpactCoordinate():MarkToAll("Impact Coordinate of weapon")
-- end
--
--
-- -- Set which function to call.
-- myweapon:SetFuncImpact(OnImpact)
--
--
-- -- Start tracking.
-- myweapon:Track()
--
--
function WEAPON:SetFuncImpact(FuncImpact, ...)
self.impactFunc=FuncImpact
self.impactArg=arg or {}
@@ -372,39 +368,37 @@ end
function WEAPON:GetTarget()
local target=nil --Wrapper.Object#OBJECT
if self.weapon then
-- Get the DCS target object, which can be a Unit, Weapon, Static, Scenery, Airbase.
local object=self.weapon:getTarget()
if object then
-- Get object category.
local category=Object.getCategory(object)
--Target name
local name=object:getName()
-- Debug info.
self:T(self.lid..string.format("Got Target Object %s, category=%d", object:getName(), category))
if name then
if category==Object.Category.UNIT then
-- Debug info.
self:T(self.lid..string.format("Got Target Object %s, category=%d", name, category))
if category==Object.Category.UNIT then
target=UNIT:FindByName(name)
elseif category==Object.Category.STATIC then
target=STATIC:FindByName(name, false)
elseif category==Object.Category.SCENERY then
self:E(self.lid..string.format("ERROR: Scenery target not implemented yet!"))
else
self:E(self.lid..string.format("ERROR: Object category=%d is not implemented yet!", category))
end
target=UNIT:FindByName(name)
elseif category==Object.Category.STATIC then
target=STATIC:FindByName(name, false)
elseif category==Object.Category.SCENERY then
self:E(self.lid..string.format("ERROR: Scenery target not implemented yet!"))
else
self:E(self.lid..string.format("ERROR: Object category=%d is not implemented yet!", category))
end
end
end
@@ -419,25 +413,25 @@ function WEAPON:GetTargetDistance(ConversionFunction)
-- Get the target of the weapon.
local target=self:GetTarget() --Wrapper.Unit#UNIT
local distance=nil
if target then
-- Current position of target.
local tv3=target:GetVec3()
-- Current position of weapon.
local wv3=self:GetVec3()
if tv3 and wv3 then
distance=UTILS.VecDist3D(tv3, wv3)
if ConversionFunction then
distance=ConversionFunction(distance)
end
end
end
return distance
@@ -451,10 +445,10 @@ function WEAPON:GetTargetName()
-- Get the target of the weapon.
local target=self:GetTarget() --Wrapper.Unit#UNIT
local name="None"
if target then
name=target:GetName()
name=target:GetName()
end
return name
@@ -482,13 +476,13 @@ function WEAPON:GetSpeed(ConversionFunction)
if self.weapon then
local v=self:GetVelocityVec3()
speed=UTILS.VecNorm(v)
if ConversionFunction then
speed=ConversionFunction(speed)
end
end
return speed
@@ -514,11 +508,11 @@ end
function WEAPON:GetVec2()
local vec3=self:GetVec3()
if vec3 then
local vec2={x=vec3.x, y=vec3.z}
return vec2
end
@@ -527,28 +521,28 @@ end
--- Get type name.
-- @param #WEAPON self
-- @return #string The type name.
-- @return #string The type name.
function WEAPON:GetTypeName()
return self.typeName
end
--- Get coalition.
-- @param #WEAPON self
-- @return #number Coalition ID.
-- @return #number Coalition ID.
function WEAPON:GetCoalition()
return self.coalition
end
--- Get country.
-- @param #WEAPON self
-- @return #number Country ID.
-- @return #number Country ID.
function WEAPON:GetCountry()
return self.country
end
--- Get DCS object.
-- @param #WEAPON self
-- @return DCS#Weapon The weapon object.
-- @return DCS#Weapon The weapon object.
function WEAPON:GetDCSObject()
-- This polymorphic function is used in Wrapper.Identifiable#IDENTIFIABLE
return self.weapon
@@ -673,26 +667,6 @@ function WEAPON:IsTorpedo()
return self.category==Weapon.Category.TORPEDO
end
--- Check if weapon is a Fox One missile (Radar Semi-Active).
-- @param #WEAPON self
-- @return #boolean If `true`, is a Fox One.
function WEAPON:IsFoxOne()
return self.guidance==Weapon.GuidanceType.RADAR_SEMI_ACTIVE
end
--- Check if weapon is a Fox Two missile (IR guided).
-- @param #WEAPON self
-- @return #boolean If `true`, is a Fox Two.
function WEAPON:IsFoxTwo()
return self.guidance==Weapon.GuidanceType.IR
end
--- Check if weapon is a Fox Three missile (Radar Active).
-- @param #WEAPON self
-- @return #boolean If `true`, is a Fox Three.
function WEAPON:IsFoxThree()
return self.guidance==Weapon.GuidanceType.RADAR_ACTIVE
end
--- Destroy the weapon object.
-- @param #WEAPON self
@@ -701,23 +675,23 @@ end
function WEAPON:Destroy(Delay)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, WEAPON.Destroy, self, 0)
self:ScheduleOnce(Delay, WEAPON.Destroy, self, 0)
else
if self.weapon then
self:T(self.lid.."Destroying Weapon NOW!")
self:StopTrack()
self.weapon:destroy()
end
end
end
return self
end
--- Start tracking the weapon until it impacts or is destroyed otherwise.
-- The position of the weapon is monitored in small time steps. Once the position cannot be determined anymore, the monitoring is stopped and the last known position is
-- the (approximate) impact point. Of course, the smaller the time step, the better the position can be determined. However, this can hit the performance as many
-- The position of the weapon is monitored in small time steps. Once the position cannot be determined anymore, the monitoring is stopped and the last known position is
-- the (approximate) impact point. Of course, the smaller the time step, the better the position can be determined. However, this can hit the performance as many
-- calculations per second need to be carried out.
-- @param #WEAPON self
-- @param #WEAPON self
-- @param #number Delay Delay in seconds before the tracking starts. Default 0.001 sec.
-- @return #WEAPON self
function WEAPON:StartTrack(Delay)
@@ -726,8 +700,8 @@ function WEAPON:StartTrack(Delay)
Delay=math.max(Delay or 0.001, 0.001)
-- Debug info.
self:T(self.lid..string.format("Start tracking weapon in %.4f sec", Delay))
self:T(self.lid..string.format("Start tracking weapon in %.4f sec", Delay))
-- Weapon is not yet "alife" just yet. Start timer in 0.001 seconds.
self.trackScheduleID=timer.scheduleFunction(WEAPON._TrackWeapon, self, timer.getTime() + Delay)
@@ -736,7 +710,7 @@ end
--- Stop tracking the weapon by removing the scheduler function.
-- @param #WEAPON self
-- @param #WEAPON self
-- @param #number Delay (Optional) Delay in seconds before the tracking is stopped.
-- @return #WEAPON self
function WEAPON:StopTrack(Delay)
@@ -745,13 +719,13 @@ function WEAPON:StopTrack(Delay)
-- Delayed call.
self:ScheduleOnce(Delay, WEAPON.StopTrack, self, 0)
else
if self.trackScheduleID then
timer.removeFunction(self.trackScheduleID)
end
end
return self
@@ -788,10 +762,10 @@ function WEAPON:_TrackWeapon(time)
-- Update last known position.
self.pos3 = pos3
-- Update last known vec3.
self.vec3 = UTILS.DeepCopy(self.pos3.p)
-- Update coordinate.
self.coordinate:UpdateFromVec3(self.vec3)
@@ -800,70 +774,70 @@ function WEAPON:_TrackWeapon(time)
-- Keep on tracking by returning the next time below.
self.tracking=true
-- Callback function.
if self.trackFunc then
self.trackFunc(self, unpack(self.trackArg))
end
-- Verbose output.
if self.verbose>=5 then
-- Get vec2 of current position.
local vec2={x=self.vec3.x, y=self.vec3.z}
-- Land hight.
local height=land.getHeight(vec2)
-- Current height above ground level.
-- Current height above ground level.
local agl=self.vec3.y-height
-- Estimated IP (if any)
local ip=self:_GetIP(self.distIP)
-- Distance between positon and estimated impact.
local d=0
if ip then
d=UTILS.VecDist3D(self.vec3, ip)
end
-- Output.
self:I(self.lid..string.format("T=%.3f: Height=%.3f m AGL=%.3f m, dIP=%.3f", time, height, agl, d))
end
else
---------------------------
-- Weapon does NOT exist --
---------------------------
---------------------------
-- Get intercept point from position (p) and direction (x) in 50 meters.
local ip = self:_GetIP(self.distIP)
if self.verbose>=10 and ip then
-- Output.
self:I(self.lid.."Got intercept point!")
-- Coordinate of the impact point.
local coord=COORDINATE:NewFromVec3(ip)
-- Mark coordinate.
coord:MarkToAll("Intercept point")
coord:SmokeBlue()
-- Distance to last known pos.
local d=UTILS.VecDist3D(ip, self.vec3)
-- Output.
self:I(self.lid..string.format("FF d(ip, vec3)=%.3f meters", d))
end
-- Safe impact vec3.
self.impactVec3=ip or self.vec3
-- Safe impact coordinate.
self.impactCoord=COORDINATE:NewFromVec3(self.vec3)
@@ -874,22 +848,22 @@ function WEAPON:_TrackWeapon(time)
if self.impactMark then
self.impactCoord:MarkToAll(string.format("Impact point of weapon %s\ntype=%s\nlauncher=%s", self.name, self.typeName, self.launcherName))
end
-- Smoke on impact point.
if self.impactSmoke then
self.impactCoord:Smoke(self.impactSmokeColor)
end
-- Call callback function.
if self.impactFunc then
self.impactFunc(self, unpack(self.impactArg or {}))
end
-- Stop tracking by returning nil below.
self.tracking=false
end
-- Return next time the function is called or nil to stop the scheduler.
if self.tracking then
if self.dtTrack and self.dtTrack>=0.00001 then
@@ -911,12 +885,12 @@ function WEAPON:_GetIP(Distance)
Distance=Distance or 50
local ip=nil --DCS#Vec3
if Distance>0 and self.pos3 then
-- Get intercept point from position (p) and direction (x) in 20 meters.
ip = land.getIP(self.pos3.p, self.pos3.x, Distance or 20) --DCS#Vec3
end
return ip

View File

@@ -49,7 +49,6 @@ Wrapper/Marker.lua
Wrapper/Weapon.lua
Wrapper/Net.lua
Wrapper/Storage.lua
Wrapper/DynamicCargo.lua
Cargo/Cargo.lua
Cargo/CargoUnit.lua
@@ -79,7 +78,6 @@ Functional/Warehouse.lua
Functional/Fox.lua
Functional/Mantis.lua
Functional/Shorad.lua
Functional/ClientWatch.lua
Ops/Airboss.lua
Ops/RecoveryTanker.lua

View File

@@ -4,12 +4,6 @@ parent: Advanced
nav_order: 01
---
# Concepts
{: .no_toc }
1. Table of contents
{:toc}
If you want to get deeper into Moose, you will encounter a few terms and
concepts that we will explain here. You will need them for the later pages.
@@ -26,21 +20,21 @@ files on [GitHub] with a browser. But using [Git] will ease up the steps to keep
the Moose version on your hard disk up to date.
You will need to interact with [GitHub]. At least to download the Moose files.
For non-developers the page can be confusing. Take your time and read this
For non developers the page can be confusing. Take your time and read this
documentation. We are not able to explain every single detail on using [GitHub]
and [Git]. Especially because it is changing really quick and this documentation
and [Git]. Especially because it is changing really quick and this documentaion
will not. So try to use the help system of [GitHub] or find some videos on
[YouTube]. If you get stuck ask for help in the [Moose Discord].
Moose uses more than one repository on [GitHub] which doesn't exactly make it
Moose uses more then one repository on [GitHub] which doesn't exactly make it
any clearer. A list can be found on the [reposities] page.
# Branches: master & develop
As already explained in the [overview] two branches are used:
- Branch [master]: Stable release branch.
- Branch [develop]: Newest development with more OPS classes.
- [master]: Stable release branch.
- [develop]: Newest development with more OPS classes.
As a starter it is okay to begin your journey with the `master` branch.
If you are interested in some newer classes you need to use the `develop`
@@ -48,8 +42,8 @@ branch. The later one is also very stable, but it's missing more detailed
documentation and example missions for some of the new OPS classes.
You can switch between these branches with a drop down in the upper left corner
of the [GitHub] repository page. The list of branches is long. So it is a best
practice to save a bookmark in your browser with the links above.
of th [GitHub] repository page. The list of branches is long. So it is a best
practise to save a bookmark in your browser with the links above.
Both branches are available on most of the different repositories. But because
of a limitation of [GitHub pages], we had to split the documentation in two
different repositories:
@@ -61,7 +55,7 @@ different repositories:
Moose consists of more than 140 individual files with the file extension `.lua`.
They are places in a [directory tree], which makes it more organized and its
semantic is pre-defined for [IntelliSense] to work.
semantic is pre-defined for IntelliSense to work.
On every change which is pushed to [GitHub] a build job will combine all of
these files to a single file called `Moose.lua`. In a second step all
@@ -69,12 +63,12 @@ comments will be removed to decrease the file size and the result will be saved
as `Moose_.lua`. These both files are created for users of Moose to include in
your missions.
The individual `.lua` files are used by the Moose developers and power users.
The individual `.lua` files are used by the Mosse developers and power users.
It is complicated to use them, but in combination with an IDE and a debugger it
is very useful to analyze even complex problems or write new additions to the
is very usefull to analyse even complex problems or write new additions to the
Moose framework.
# Static loading
# Static loading vs. dynamic loading
If you add a script file with a `DO SCRIPT FILE` trigger, like we described in
[Create your own Hello world], the script file will be copied into the mission
@@ -84,159 +78,25 @@ with another file ending.
If you change the script file after adding it to the mission, the changes are
not available on mission start. You have to re-add the script after each change.
This can be very annoying and often leads to forgetting to add the change again.
Then you wonder why the mission does not deliver the desired result.
Then you wonder why the script does not deliver the desired result.
But when the mission is finished you can upload it to your dedicated DCS server
or give it to a friend and it should run without problems. This way of embedding
the scripts do we call `static loading` and the resulting mission is very
portable.
# Dynamic loading of mission scripts
The other way of loading scripts is by using `DO SCRIPT`. This time the mission
The other way on loading scripts is by using `DO SCRIPT`. This time the mission
editor don't show a file browse button. Instead you see a (very small) text
field to enter the code directly into it. It is only useful for very small
script snippets. But we can use it to load a file from your hard drive like
this:
field to enter the code directly into it. It is only usefull for very small
script snippets. But we can use it to load a file from our hard drive like this:
```lua
dofile('C:/MyScripts/hello-world.lua')
dofile('C:\\MyScripts\\hello-world.lua')
dofile([[C:\MyScripts\hello-world.lua]])
```
So all lines above do the same. In [Lua] you need to specify the path with
slashes, escape backslashes or use double square brackets around the string.
Double square brackets are usefull, because you can copy paste the path
without any modification.
If you upload a mission with this code, you need to create the folder
`C:\MyScripts\` on the server file system and upload the newest version of
`hello-world.lua`, too. The same applies, if you give the mission to a friend.
This makes the mission less portable, but on the other hand the mission uses the
file on the hard disk, without the need to add it to the mission again.
All you need to do is save the file and restart the mission.
The following can be used to increase portability:
```lua
dofile(lfs.writedir() .. '/Missions/hello-world.lua')
```
The function `lfs.writedir()` will return your [Saved Games folder].
So you place the scripts in the subfolder Missions. This way the folder
structure is already available on all target systems. But you need to ensure
mission and script are both in sync to avoid problems. If you changed both and
upload only one of them to your server, you may get trouble.
There is another method you may find useful to dynamically load scripts:
```lua
assert(loadfile('C:/MyScripts/hello-world.lua'))()
assert(loadfile('C:\\MyScripts\\hello-world.lua'))()
assert(loadfile([[C:\MyScripts\hello-world.lua]]))()
```
It is a little bit harder to read and write because of all these different
brackets. Especially the one on line 3. But it is a little safer than `dofile`.
Because of readability I prefer to use `dofile`.
# Dynamic loading of Moose
Of course you can use the same method to load Moose. This way you can place one
Moose file in your [Saved Games folder], which is used by multiple missions.
If you want to update Moose you just need to replace the file and all missions
will use the new version. But I prefer to add Moose by a `DO SCRIPT FILE`
trigger so I can add and test the new version for each mission step by step.
But we added two different ways to load the Moose source files automatically.
This is useful for Moose developers and it is a requirement to use a debugger.
This will be explained later in the [Debugger Guide].
# Automatic dynamic loading
With the code below you can have the advantages of both approaches.
- Copy the code into your mission script at the beginning.
- Save the mission script into the folder Missions in your [Saved Games folder].
- Change script filename in line 2 to match to your script.
- [De-Sanitize] your `MissionScripting.lua`.
Now the mission will use the script on your hard drive instead of the script
embedded in th MIZ file, as long as it is available. So you can chnge the
script, save it and restart the mission, without the need to readd it after each
change.
If you reach a stable state in your script development and want to upload the
mission to your server or give it to a friend, then just add the script again
like in the static method and save the mission.
{: .important }
> Do not forget to readd the script, prior uploading or sharing the mission,
> or it will run with an outdated version of your script and may fail if the
> objects in the mission don't match to this old version.
```lua
-- Use script file from hard disk instead of the one included in the .miz file
if lfs and io then
MissionScript = lfs.writedir() .. '/Missions/hello-world-autodyn.lua'
-- Check if the running skript is from temp directory to avoid an endless loop
if string.find( debug.getinfo(1).source, lfs.tempdir() ) then
local f=io.open(MissionScript,"r")
if f~=nil then
io.close(f)
env.info( '*** LOAD MISSION SCRIPT FROM HARD DISK *** ' )
dofile(MissionScript)
do return end
end
end
else
env.error( '*** LOAD MISSION SCRIPT FROM HARD DISK FAILED (Desanitize lfs and io)*** ' )
end
--
-- Simple example mission to show the very basics of MOOSE
--
MESSAGE:New( "Hello World! This messages is printed by MOOSE!", 35, "INFO" ):ToAll():ToLog()
aaa
```
# IDE vs. Notepad++
As a beginner you should start with a good text editor, which supports syntax
highlighting of [Lua] code. This must not be [Notepad++]. It can be any other
powerful editor of your choice. Do yourself a favor and don't use the Windows
editor.
If you are a developer of [Lua] or another programming language, then your are
most likely familiar with an IDE (Integrated Develop Environment).
Otherwise you should know, that an IDE may help you with code completion,
Refactoring, Autocorrection, Formatting Source Code, showing documentation
as popup on mouse hover over keywords and Debugging.
There are different IDEs available. And not all IDEs support all features.
The three most important for Moose are:
- [Eclipse LDT]
- [Visual Studio Code]
- [PyCharm] (or [IntelliJ IDEA])
Eclipse has the best support for hover documentation and [IntelliSense] with
Moose. The Inventor of Moose (FlightControl) did an amazing job by adding an
integration to Eclipse LDT (a special version for Lua).
Unfortunately Eclipse LDT is not maintained any longer (last release 2018).
And the debugger doesn't work anymore, since an update of DCS.
In Visual Studio Code the support of Lua can be added by an addon.
The debugger works with Moose and DCS, but showing the LuaDoc and [IntelliSense]
is very limited.
PyCharm supports Lua also with an addon. The debugger works with Moose and DCS,
but showing the LuaDoc and [IntelliSense] is very limited.
It is up to you to choose the IDE according to your taste. Guides on how to
setup Moose with different IDEs and Debuggers are provided later in this
documentation.
# What is a debugger (good for)
[Git]: https://en.wikipedia.org/wiki/Git
[GitHub]: https://github.com/
@@ -250,14 +110,3 @@ documentation.
[MOOSE_DOCS]: https://flightcontrol-master.github.io/MOOSE_DOCS/
[MOOSE_DOCS_DEVELOP]: https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/
[directory tree]: https://github.com/FlightControl-Master/MOOSE/tree/master/Moose%20Development/Moose
[Saved Games folder]: ../beginner/tipps-and-tricks.md#find-the-saved-games-folder
[Lua]: https://www.lua.org/
[Create your own Hello world]: ../beginner/hello-world-build.md
[Debugger Guide]: debugger.md
[IntelliSense]: https://en.wikipedia.org/wiki/IntelliSense
[De-Sanitize]: desanitize-dcs.md
[Notepad++]: https://notepad-plus-plus.org/downloads/
[Eclipse LDT]: https://projects.eclipse.org/projects/tools.ldt
[Visual Studio Code]: https://code.visualstudio.com/
[PyCharm]: https://www.jetbrains.com/pycharm/
[IntelliJ IDEA]: https://www.jetbrains.com/idea/

View File

@@ -1,8 +0,0 @@
---
title: Debugger
parent: Advanced
nav_order: 100
---
{: .warning }
> THIS DOCUMENT IS STILL WORK IN PROGRESS!

View File

@@ -35,24 +35,16 @@ Please remember when posting a question:
- Before posting anything follow the [troubleshooting steps].
- **Read your logs**.
### Formulate a good description
A post should contain the following:
- A description what you expected to happen and what actually happened.
- Do not use vague words this stuff is hard to help with! Be specific.
1. A describtion what you expected to happen and what actually happened.
- Do not use vague words this stuff is hard to help with! Be specific.
- Describe what happens instead.
- The less detail you offer, the less chance you can be helped.
- Don't say it doesn't work. Or is it broken. Say what it actually does.
2. Describe what happens instead.
- The less detail you offer, the less chance you can be helped.
- Dont say it doesnt work. Or is it broken. Say what it actually does.
### Format your code
The easier your code is to read, the more likely you are to get a helpful answer. If your code is hard to read, some
people who could help you may not even bother to read your code. Syntax Highlighting makes the code much clearer and
easier to understand. Therefore:
- Post your code in Discord as formatted code:
3. Post your code in Discord as formatted code:
- Wrap a single line of code in backticks \` like this:
@@ -62,31 +54,14 @@ easier to understand. Therefore:
![discord-multi-line-code.png](../images/beginner/discord-multi-line-code.png)
### Do not post a screenshot of your code
- Post your log lines with the error or warning messages. Format them like this:
Your code is easy to read on a screenshot if you are using a good text editor or IDE, but if someone discovers an error
in your code and wants to post a corrected version, they will have to type out the entire code. This could lead to them
not helping you because it's too much work for them.
### Post your log
If the error message in the `dcs.log` does not tell you anything, then post it in the Discord.
- Post the important log lines with the error or warning messages. Format them like this:
![discord-format-logs.png](../images/beginner/discord-format-logs.png)
### Send your mission when requested
Please don't just send your mission file. You have to manually extract the script from the file.
It is better to send your script code and log lines beforehand.
If this does not help, you may be asked to send your mission.
![discord-fomat-logs.png](../images/beginner/discord-fomat-logs.png)
- Some complex problems need the mission (.miz file) also.
- But post your mission only when requested.
- Try to simplify your mission if it is complex!
- Try to avoid or delete MODs, because could prevent people from helping you.
There are people in the Discord and in the forum, who spend their free time to
help you. <br />

View File

@@ -172,7 +172,7 @@ compftable in filtering these informations fast.
Now it is time to [create your own Hello world] mission.
[Saved Games folder]: ../beginner/tipps-and-tricks.md#find-the-saved-games-folder
[001-hello-world.miz]: https://raw.githubusercontent.com/FlightControl-Master/MOOSE_MISSIONS/master/Core/Message/001-hello-world.miz
[hello-world demo mission]: https://raw.githubusercontent.com/FlightControl-Master/MOOSE_MISSIONS/master/Core/Message/001-hello-world.miz
[Core.Message]: https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Core.Message.html
[Wikipedia:Class]: https://en.wikipedia.org/wiki/Class_(computer_programming)
[create your own Hello world]: hello-world-build.md

View File

@@ -11,14 +11,10 @@ nav_order: 05
## Something went wrong
If the mission shows not the expected behavior do the following steps:
If the mission shows not the expected behaviour do the following steps:
1. Double check if you added the changed mission script to the mission again!
1. Check if the triggers are configured as requested in the last sections:
- To load MOOSE: `4 MISSION START`, nothing on `CONDITIONS`, `DO SCRIPT FILE` to load `Moose_.lua`.
- To load mission script(s): `1 ONCE`, in `CONDITIONS` add `TIME MORE` = 1, `DO SCRIPT FILE` to load `yourscript.lua`.
1. Double check if you have the right version of MOOSE (some classes need the develop branch).
1. Try the newest version of MOOSE.
1. Check if the triggers are configured as requested in the last sections.
## Read the logs
@@ -26,7 +22,8 @@ The DCS log is a super important and useful log for the entire of DCS World.
All scripting and other errors are recorded here. It is the one stop shop for
things that occurred in your mission. It will tell you if there was a mistake.
1. Open the file `dcs.log` in the `Logs` subfolder in your DCS [Saved Games folder].
1. Open the file `dcs.log` in the `Logs` subfolder in your DCS
[Saved Games folder].
1. Search for the following line: `*** MOOSE INCLUDE END ***`
- If it is included in the log, Moose was loaded.

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB