From cbbc4144e6b88ffe293b8795b8f9175c9d6151d1 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Wed, 15 Jun 2016 18:57:02 +0200 Subject: [PATCH] First version --- Moose Development/Moose/Detection.lua | 92 +++++++++++++++++++++++++++ Moose Development/Moose/Scheduler.lua | 1 + 2 files changed, 93 insertions(+) create mode 100644 Moose Development/Moose/Detection.lua diff --git a/Moose Development/Moose/Detection.lua b/Moose Development/Moose/Detection.lua new file mode 100644 index 000000000..6f6f1787f --- /dev/null +++ b/Moose Development/Moose/Detection.lua @@ -0,0 +1,92 @@ +--- This module contains the DETECTION classes. +-- +-- === +-- +-- 1) @{Detection#DETECTION_BASE} class, extends @{Base#BASE} +-- ===================================================== +-- The @{Detection#DETECTION_BASE} class defines the core functions to administer detected objects. +-- Detected objects are grouped in SETS of UNITS. +-- +-- @module Detection +-- @author Mechanic : Concept & Testing +-- @author FlightControl : Design & Programming + +--- DETECTION_BASE class +-- @type DETECTION_BASE +-- @field Group#GROUP FACGroup The GROUP in the Forward Air Controller role. +-- @field DCSTypes#Distance DetectionRange The range till which targets are accepted to be detected. +-- @field DCSTypes#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. +-- @extends Set#SET_BASE +DETECTION_BASE = { + ClassName = "DETECTION_BASE", + Sets = {}, + FACGroup = nil, + DetectionRange = nil, + DetectionZoneRange = nil, +} + +--- DETECTION constructor. +-- @param #DETECTION_BASE self +-- @return #DETECTION_BASE self +function DETECTION_BASE:New( FACGroup, DetectionRange, DetectionZoneRange ) + + -- Inherits from BASE + local self = BASE:Inherit( self, BASE:New() ) + + self.FACGroup = FACGroup + self.DetectionRange = DetectionRange + self.DetectionZoneRange = DetectionZoneRange + + self.DetectionScheduler = SCHEDULER:New(self, self._DetectionScheduler, { self, "Detection" }, 1, 30, 0.2 ) +end + +--- Form @{Set}s of detected @{Unit#UNIT}s in an array of @{Set#SET_UNIT}s. +-- @param #DETECTION_BASE self +function DETECTION_BASE:_DetectionScheduler( SchedulerName ) + self:F2( { SchedulerName } ) + + self.Sets = {} + + if self.FACGroup:IsAlive() then + local FACGroupName = self.FACGroup:GetName() + local FACDetectedTargets = self.FACGroup:GetDetectedTargets() + + for FACDetectedTargetID, FACDetectedTarget in pairs( FACDetectedTargets ) do + local FACObject = FACDetectedTarget.object + self:T2( FACObject ) + + if FACObject and FACObject:isExist() and FACObject.id_ < 50000000 then + + local FACDetectedTargetUnit = UNIT:Find( FACObject ) + local FACDetectedTargetUnitName = FACDetectedTargetUnit:GetName() + + local FACDetectedTargetUnitPositionVec3 = FACDetectedTargetUnit:GetPointVec3() + local FACGroupPositionVec3 = self.FACGroup:GetPointVec3() + local Distance = ( ( FACDetectedTargetUnitPositionVec3.x - FACGroupPositionVec3.x )^2 + + ( FACDetectedTargetUnitPositionVec3.y - FACGroupPositionVec3.y )^2 + + ( FACDetectedTargetUnitPositionVec3.z - FACGroupPositionVec3.z )^2 + ) ^ 0.5 / 1000 + + self:T( { self.FACGroup:GetName(), FACDetectedTargetUnit:GetName(), Distance } ) + + if Distance <= self then + + if not ClientEscortTargets[EscortTargetUnitName] then + ClientEscortTargets[EscortTargetUnitName] = {} + end + ClientEscortTargets[EscortTargetUnitName].AttackUnit = FACDetectedTargetUnit + ClientEscortTargets[EscortTargetUnitName].visible = EscortTarget.visible + ClientEscortTargets[EscortTargetUnitName].type = EscortTarget.type + ClientEscortTargets[EscortTargetUnitName].distance = EscortTarget.distance + else + if ClientEscortTargets[EscortTargetUnitName] then + ClientEscortTargets[EscortTargetUnitName] = nil + end + end + end + + end + + end + +end \ No newline at end of file diff --git a/Moose Development/Moose/Scheduler.lua b/Moose Development/Moose/Scheduler.lua index 545305774..d3d75fd95 100644 --- a/Moose Development/Moose/Scheduler.lua +++ b/Moose Development/Moose/Scheduler.lua @@ -20,6 +20,7 @@ -- @module Scheduler -- @author FlightControl + --- The SCHEDULER class -- @type SCHEDULER -- @field #number ScheduleID the ID of the scheduler.