mirror of
https://github.com/weyne85/DML.git
synced 2025-10-29 16:57:49 +00:00
Simplify baseCaptured Module
Reduce functionality to "coalition has captured closest base".
This commit is contained in:
parent
c0824fc43a
commit
eabb94b11f
@ -1,24 +1,19 @@
|
|||||||
baseCaptured={}
|
baseCaptured={}
|
||||||
baseCaptured.version = "1.0.1"
|
baseCaptured.version = "1.0.1"
|
||||||
baseCaptured.verbose = false
|
baseCaptured.verbose = false
|
||||||
baseCaptured.autoAssignClosestBase = true
|
|
||||||
baseCaptured.requiredLibs = {
|
baseCaptured.requiredLibs = {
|
||||||
"dcsCommon", -- always
|
"dcsCommon", -- always
|
||||||
"cfxZones", -- Zones, of course
|
"cfxZones", -- Zones, of course
|
||||||
}
|
}
|
||||||
--[[--
|
--[[--
|
||||||
baseCaptured - Detects when a base has been captured
|
baseCaptured - Detects when the assigned base has been captured
|
||||||
|
|
||||||
Properties
|
Properties
|
||||||
- baseCaptured Marks this as baseCaptured zone. The value is ignored. (MANDATORY)
|
- baseCaptured Marks this as baseCaptured zone. The value is ignored.
|
||||||
- baseName Name for the airdrome or helipad. In case of a helipad, it's the unit name.
|
The closest base (airdrome or helipad) is automatically assigned to this zone.
|
||||||
If no name is set then the behavior depends on the configuration autoAssignClosestBase.
|
(MANDATORY)
|
||||||
If autoAssignClosestBase is true, then the closest base is automatically assigned.
|
|
||||||
If autoAssignClosestBase is false, then the associated captured flag is triggered for all bases.
|
|
||||||
- coalition The coalition that needs to capture the base. Accepts 0/all, 1/red, 2/blue.
|
- coalition The coalition that needs to capture the base. Accepts 0/all, 1/red, 2/blue.
|
||||||
captureCoalition Defaults to 0 (all)
|
captureCoalition Defaults to 0 (all)
|
||||||
- filterFor Which base categories to look for. Accepts 0/airdrome,1/helipad and 3/all.
|
|
||||||
Defaults to 3 (all)
|
|
||||||
- method DML Flag method for output. Use only one synonym per zone.
|
- method DML Flag method for output. Use only one synonym per zone.
|
||||||
capturedMethod Defaults to "flip".
|
capturedMethod Defaults to "flip".
|
||||||
- f! The flag to bang! after the base matching above filter criteria has been captured.
|
- f! The flag to bang! after the base matching above filter criteria has been captured.
|
||||||
@ -26,8 +21,6 @@ baseCaptured.requiredLibs = {
|
|||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
- verbose Show debugging information. Default is false.
|
- verbose Show debugging information. Default is false.
|
||||||
- autoAssignClosestBase Automatically assign the closest base to a zone if no explicit baseName has been provided.
|
|
||||||
Default is true.
|
|
||||||
|
|
||||||
Version History
|
Version History
|
||||||
1.0.0 - Initial version
|
1.0.0 - Initial version
|
||||||
@ -36,31 +29,6 @@ baseCaptured.requiredLibs = {
|
|||||||
|
|
||||||
baseCaptured.zones = {}
|
baseCaptured.zones = {}
|
||||||
|
|
||||||
function baseCaptured.getAirbaseCategoryFromZoneProperty(theZone, theProperty, default)
|
|
||||||
if not default then default = 3 end
|
|
||||||
|
|
||||||
local p = cfxZones.getZoneProperty(theZone, theProperty)
|
|
||||||
if not p then
|
|
||||||
return default
|
|
||||||
end
|
|
||||||
|
|
||||||
p = dcsCommon.trim(p:lower())
|
|
||||||
|
|
||||||
local num = tonumber(p)
|
|
||||||
if num then
|
|
||||||
if num < 0 then num = 0 end
|
|
||||||
if num > 3 then num = 3 end
|
|
||||||
return num
|
|
||||||
end
|
|
||||||
|
|
||||||
num = default
|
|
||||||
if p == "airdrome" then num = Airbase.Category.AIRDROME end
|
|
||||||
if p == "helipad" then num = Airbase.Category.HELIPAD end
|
|
||||||
if p == "all" then num = 3 end
|
|
||||||
|
|
||||||
return num
|
|
||||||
end
|
|
||||||
|
|
||||||
function baseCaptured.assignClosestBase(theZone)
|
function baseCaptured.assignClosestBase(theZone)
|
||||||
local base = dcsCommon.getClosestAirbaseTo(theZone.point)
|
local base = dcsCommon.getClosestAirbaseTo(theZone.point)
|
||||||
if base then
|
if base then
|
||||||
@ -74,11 +42,8 @@ function baseCaptured.assignClosestBase(theZone)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function baseCaptured.createZone(theZone)
|
function baseCaptured.createZone(theZone)
|
||||||
-- assigned base
|
-- assign closest base
|
||||||
theZone.baseName = cfxZones.getStringFromZoneProperty(theZone, "baseName", "<none>")
|
baseCaptured.assignClosestBase(theZone)
|
||||||
if baseCaptured.autoAssignClosestBase and theZone.baseName == "<none>" then
|
|
||||||
baseCaptured.assignClosestBase(theZone)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- coalition (1=red,2=blue,0=neutral/all)
|
-- coalition (1=red,2=blue,0=neutral/all)
|
||||||
theZone.captureCoalition = cfxZones.getCoalitionFromZoneProperty(theZone, "coalition", 0)
|
theZone.captureCoalition = cfxZones.getCoalitionFromZoneProperty(theZone, "coalition", 0)
|
||||||
@ -90,15 +55,6 @@ function baseCaptured.createZone(theZone)
|
|||||||
trigger.action.outText("***basedCaptured: set coalition " .. theZone.captureCoalition .. " for <" .. theZone.name .. ">", 30)
|
trigger.action.outText("***basedCaptured: set coalition " .. theZone.captureCoalition .. " for <" .. theZone.name .. ">", 30)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- category filter (0=airdrome,1=helipad,2=ship,3=all)
|
|
||||||
if cfxZones.hasProperty(theZone, "filterFor") then
|
|
||||||
theZone.filterFor = baseCaptured.getAirbaseCategoryFromZoneProperty(theZone, "filterFor", 3)
|
|
||||||
|
|
||||||
if baseCaptured.verbose or theZone.verbose then
|
|
||||||
trigger.action.outText("***basedCaptured: set category filter " .. theZone.filterFor .. " for <" .. theZone.name .. ">", 30)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get flag output method
|
-- get flag output method
|
||||||
theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "method", "flip")
|
theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "method", "flip")
|
||||||
if cfxZones.hasProperty(theZone, "capturedMethod") then
|
if cfxZones.hasProperty(theZone, "capturedMethod") then
|
||||||
@ -138,14 +94,12 @@ function baseCaptured:onEvent(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local baseName = event.place:getName()
|
local baseName = event.place:getName()
|
||||||
local baseCategory = event.place:getDesc().category
|
|
||||||
local newCoalition = event.place:getCoalition()
|
local newCoalition = event.place:getCoalition()
|
||||||
|
|
||||||
for idx, aZone in pairs(baseCaptured.zones) do
|
for idx, aZone in pairs(baseCaptured.zones) do
|
||||||
local hasName = aZone.baseName == "<none>" or aZone.baseName == baseName
|
local hasName = aZone.baseName == baseName
|
||||||
local hasCoalition = aZone.captureCoalition == 0 or aZone.captureCoalition == newCoalition
|
local hasCoalition = aZone.captureCoalition == 0 or aZone.captureCoalition == newCoalition
|
||||||
local hasCategory = not aZone.filterFor or aZone.filterFor > 2 or aZone.filterFor == baseCategory
|
if hasName and hasCoalition then
|
||||||
if hasName and hasCoalition and hasCategory then
|
|
||||||
baseCaptured.triggerZone(aZone)
|
baseCaptured.triggerZone(aZone)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -159,7 +113,6 @@ function baseCaptured.readConfigZone()
|
|||||||
end
|
end
|
||||||
|
|
||||||
baseCaptured.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false)
|
baseCaptured.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false)
|
||||||
baseCaptured.autoAssignClosestBase = cfxZones.getBoolFromZoneProperty(theZone, "autoAssignClosestBase", true)
|
|
||||||
|
|
||||||
if baseCaptured.verbose then
|
if baseCaptured.verbose then
|
||||||
trigger.action.outText("***baseCaptured: read configuration from zone", 30)
|
trigger.action.outText("***baseCaptured: read configuration from zone", 30)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user