Skip to content

Commit

Permalink
Implemented task force group destinations
Browse files Browse the repository at this point in the history
Groups will now move through previously captured zones when advancing as
described in #20.
  • Loading branch information
birgersp committed Jan 8, 2017
1 parent ad13c74 commit 5bb164c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
15 changes: 15 additions & 0 deletions autogft/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ autogft_debugMode = false

-- Utility function definitions

---
-- @param DCSUnit#Unit unit
-- @param DCSZone#Zone zone
-- @return #boolean
function autogft_unitIsWithinZone(unit, zone)
local pos = unit:getPosition().p
local dx = zone.point.x - pos.x
local dy = zone.point.z - pos.z
local radiusSquared = zone.radius * zone.radius
if (dx*dx + dy*dy) <= radiusSquared then
return true
end
return false
end

---
-- @param #list<DCSUnit#Unit> units
-- @param #string type
Expand Down
39 changes: 37 additions & 2 deletions autogft/taskforcegroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- @field #list<unitspec#autogft_UnitSpec> unitSpecs
-- @field taskforce#autogft_TaskForce taskForce
-- @field DCSGroup#Group dcsGroup
-- @field #number destination
autogft_TaskForceGroup = {}

---
Expand All @@ -16,9 +17,41 @@ function autogft_TaskForceGroup:new(taskForce)
self = setmetatable({}, {__index = autogft_TaskForceGroup})
self.unitSpecs = {}
self.taskForce = taskForce
self:setDCSGroup(nil)
return self
end

---
-- @param #autogft_TaskForceGroup self
-- @return #autogft_TaskForceGroup
function autogft_TaskForceGroup:updateDestination()

if self.dcsGroup then
local units = self.dcsGroup:getUnits()
if #units > 0 then
-- Get group lead
local groupLead
local unitIndex = 1
while unitIndex <= #units and not groupLead do
if units[unitIndex]:isExist() then groupLead = units[unitIndex] end
end

-- Check location of group lead
if groupLead then
local destinationZone = trigger.misc.getZone(self.taskForce.targetZones[self.destination].name)
if autogft_unitIsWithinZone(groupLead, destinationZone) then
-- If destination reached, update target
if self.destination < self.taskForce.target then
self.destination = self.destination + 1
elseif self.destination > self.taskForce.target then
self.destination = self.destination - 1
end
end
end
end
end
end

---
-- @param #autogft_TaskForceGroup self
-- @return #autogft_TaskForceGroup
Expand Down Expand Up @@ -61,9 +94,10 @@ end
-- @param #autogft_TaskForceGroup self
-- @return #autogft_TaskForceGroup
function autogft_TaskForceGroup:advance()

if self:exists() then
local destinationZone = trigger.misc.getZone(self.taskForce.targetZones[self.taskForce.target].name)
self:updateDestination()

local destinationZone = trigger.misc.getZone(self.taskForce.targetZones[self.destination].name)
local destinationZonePos2 = {
x = destinationZone.point.x,
y = destinationZone.point.z
Expand Down Expand Up @@ -117,5 +151,6 @@ end
-- @return #autogft_TaskForceGroup
function autogft_TaskForceGroup:setDCSGroup(newGroup)
self.dcsGroup = newGroup
self.destination = 1
return self
end

0 comments on commit 5bb164c

Please sign in to comment.