Version 0.9986

baseCaptured
cloneZones embarkation
xFlags xCount
This commit is contained in:
Christian Franz 2022-04-28 13:37:20 +02:00
parent 64351c8229
commit 6d95355000
13 changed files with 375 additions and 93 deletions

Binary file not shown.

Binary file not shown.

145
modules/LZ.lua Normal file
View File

@ -0,0 +1,145 @@
LZ = {}
LZ.version = "0.0.0"
LZ.verbose = false
LZ.ups = 1
LZ.requiredLibs = {
"dcsCommon", -- always
"cfxZones", -- Zones, of course
}
LZ.LZs = {}
--[[--
Version History
1.0.0 - initial version
--]]--
function LZ.addLZ(theZone)
table.insert(LZ.LZs, theZone)
end
function LZ.getLZByName(aName)
for idx, aZone in pairs(LZ.LZs) do
if aName == aZone.name then return aZone end
end
if LZ.verbose then
trigger.action.outText("+++LZ: no LZ with name <" .. aName ..">", 30)
end
return nil
end
--
-- read zone
--
function LZ.createLZWithZone(theZone)
-- read main trigger
theZone.triggerLZFlag = cfxZones.getStringFromZoneProperty(theZone, "lz!", "*<none>")
-- TriggerMethod: common and specific synonym
theZone.lzMethod = cfxZones.getStringFromZoneProperty(theZone, "method", "inc")
if cfxZones.hasProperty(theZone, "lzTriggerMethod") then
theZone.lzMethod = cfxZones.getStringFromZoneProperty(theZone, "lzMethod", "change")
end
if LZ.verbose or theZone.verbose then
trigger.action.outText("+++LZ: new LZ <".. theZone.name ..">", 30)
end
end
--
-- MAIN ACTION
--
function LZ.processUpdate(theZone)
end
--
-- Event Handling
--
function LZ:onEvent(event)
-- only interested in S_EVENT_BASE_CAPTURED events
if event.id ~= world.event.S_EVENT_BASE_CAPTURED then
return
end
for idx, aZone in pairs(LZ.LZs) do
-- check if landed inside and of correct type, colition, name whatever
end
end
--
-- Update
--
function LZ.update()
-- call me in a second to poll triggers
timer.scheduleFunction(LZ.update, {}, timer.getTime() + 1/LZ.ups)
for idx, aZone in pairs(LZ.LZs) do
-- see if we are triggered
if cfxZones.testZoneFlag(aZone, aZone.triggerLZFlag, aZone.LZTriggerMethod, "lastTriggerLZValue") then
if LZ.verbose or theZone.verbose then
trigger.action.outText("+++LZ: triggered on main? for <".. aZone.name ..">", 30)
end
LZ.processUpdate(aZone)
end
end
end
--
-- Config & Start
--
function LZ.readConfigZone()
local theZone = cfxZones.getZoneByName("LZConfig")
if not theZone then
if LZ.verbose then
trigger.action.outText("+++LZ: NO config zone!", 30)
end
return
end
LZ.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false)
if LZ.verbose then
trigger.action.outText("+++LZ: read config", 30)
end
end
function LZ.start()
-- lib check
if not dcsCommon.libCheck then
trigger.action.outText("cfx LZ requires dcsCommon", 30)
return false
end
if not dcsCommon.libCheck("cfx LZ", LZ.requiredLibs) then
return false
end
-- read config
LZ.readConfigZone()
-- process LZ Zones
-- old style
local attrZones = cfxZones.getZonesWithAttributeNamed("lz!")
for k, aZone in pairs(attrZones) do
LZ.createLZWithZone(aZone) -- process attributes
LZ.addLZ(aZone) -- add to list
end
-- start update
LZ.update()
trigger.action.outText("cfx LZ v" .. LZ.version .. " started.", 30)
return true
end
-- let's go!
if not LZ.start() then
trigger.action.outText("cfx LZ aborted: missing libraries", 30)
LZ = nil
end

View File

@ -1,89 +1,100 @@
baseCaptured={} baseCaptured={}
baseCaptured.version = "1.0.1" baseCaptured.version = "1.0.0"
baseCaptured.verbose = false baseCaptured.verbose = false
baseCaptured.requiredLibs = { baseCaptured.requiredLibs = {
"dcsCommon", -- always "dcsCommon", -- always
"cfxZones", -- Zones, of course "cfxZones", -- Zones, of course
} }
--[[-- --[[--
baseCaptured - Detects when the assigned base has been captured baseCaptured - Detects when the assigned base has been captured, idea and first implementation by cloose
Properties
- baseCaptured Marks this as baseCaptured zone. The value is ignored.
The closest base (airdrome or helipad) is automatically assigned to this zone.
(MANDATORY)
- coalition The coalition that needs to capture the base. Accepts 0/all, 1/red, 2/blue.
captureCoalition Defaults to 0 (all)
- method DML Flag method for output. Use only one synonym per zone.
capturedMethod Defaults to "flip".
- f! The flag to bang! after the base matching above filter criteria has been captured.
captured! Use only one synonym per zone.
Configuration
- verbose Show debugging information. Default is false.
Version History Version History
1.0.0 - Initial version 1.0.0 - Initial version based on cloose's code
1.0.1 - Automatic Closest Base Assignment
--]]-- --]]--
baseCaptured.zones = {} baseCaptured.zones = {}
function baseCaptured.assignClosestBase(theZone)
local base = dcsCommon.getClosestAirbaseTo(theZone.point)
if base then
theZone.baseName = base:getName()
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("***basedCaptured: assigned <" .. theZone.name .. "> to base <" .. theZone.baseName .. ">", 30)
end
else
trigger.action.outText("***basedCaptured: unable to resolve base for <" .. theZone.name .. ">", 30)
end
end
function baseCaptured.createZone(theZone) function baseCaptured.createZone(theZone)
-- assign closest base -- find closest base
baseCaptured.assignClosestBase(theZone) theZone.theBase = dcsCommon.getClosestAirbaseTo(theZone.point)
theZone.baseName = theZone.theBase:getName()
-- coalition (1=red,2=blue,0=neutral/all) theZone.currentOwner = theZone.theBase:getCoalition()
theZone.captureCoalition = cfxZones.getCoalitionFromZoneProperty(theZone, "coalition", 0)
if cfxZones.hasProperty(theZone, "captureCoalition") then -- baseCaptured is the method
theZone.captureCoalition = cfxZones.getCoalitionFromZoneProperty(theZone, "captureCoalition", 0) theZone.capturedFlag = cfxZones.getStringFromZoneProperty(theZone, "baseCaptured!", "*none")
end
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("***basedCaptured: set coalition " .. theZone.captureCoalition .. " for <" .. theZone.name .. ">", 30)
end
-- get flag output method -- get flag output method
theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "method", "flip") theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "method", "inc")
if cfxZones.hasProperty(theZone, "capturedMethod") then if cfxZones.hasProperty(theZone, "capturedMethod") then
theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "capturedMethod", "flip") theZone.capturedMethod = cfxZones.getStringFromZoneProperty(theZone, "capturedMethod", "inc")
end end
-- get captured flag -- other outputs
if cfxZones.hasProperty(theZone, "f!") then if cfxZones.hasProperty(theZone, "blueCaptured!") then
theZone.capturedFlag = cfxZones.getStringFromZoneProperty(theZone, "f!", "*none") theZone.blueCap = cfxZones.getStringFromZoneProperty(theZone, "blueCaptured!", "*none")
end end
if cfxZones.hasProperty(theZone, "captured!") then
theZone.capturedFlag = cfxZones.getStringFromZoneProperty(theZone, "captured!", "*none") if cfxZones.hasProperty(theZone, "blue!") then
theZone.blueCap = cfxZones.getStringFromZoneProperty(theZone, "blue!", "*none")
end
if cfxZones.hasProperty(theZone, "redCaptured!") then
theZone.redCap = cfxZones.getStringFromZoneProperty(theZone, "blueCaptured!", "*none")
end
if cfxZones.hasProperty(theZone, "red!") then
theZone.redCap = cfxZones.getStringFromZoneProperty(theZone, "red!", "*none")
end
if cfxZones.hasProperty(theZone, "baseOwner") then
theZone.baseOwner = cfxZones.getStringFromZoneProperty(theZone, "baseOwner", "*none")
cfxZones.setFlagValueMult(theZone.baseOwner, theZone.currentOwner, theZone)
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("+++bCap: setting owner for <" .. theZone.name .. "> to " .. theZone.currentOwner, 30)
end
end
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("+++bCap: tracking base <" .. theZone.baseName .. "> with <" .. theZone.name .. ">", 30)
end end
end end
function baseCaptured.addZone(theZone) function baseCaptured.addBaseCaptureZone(theZone)
if not theZone.capturedFlag or theZone.capturedFlag == "*none" then
trigger.action.outText("***baseCaptured NOTE: " .. theZone.name .. " is missing a valid <f!> or <captured!> property", 30)
return
end
table.insert(baseCaptured.zones, theZone) table.insert(baseCaptured.zones, theZone)
end end
function baseCaptured.triggerZone(theZone) function baseCaptured.triggerZone(theZone)
local newOwner = theZone.theBase:getCoalition()
cfxZones.pollFlag(theZone.capturedFlag, theZone.capturedMethod, theZone) cfxZones.pollFlag(theZone.capturedFlag, theZone.capturedMethod, theZone)
if baseCaptured.verbose then if newOwner == 1 then -- red
trigger.action.outText("***baseCaptured: banging captured! with <" .. theZone.capturedMethod .. "> on <" .. theZone.capturedFlag .. "> for " .. theZone.baseName, 30) if theZone.redCap then
cfxZones.pollFlag(theZone.redCap, theZone.capturedMethod, theZone)
end
elseif newOwner == 2 then
if theZone.blueCap then
cfxZones.pollFlag(theZone.blueCap, theZone.capturedMethod, theZone)
end
else
-- possibly a new side? Neutral doesn't cap
end
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("+++bCap: <" .. theZone.baseName .. "> changed hands from <" .. theZone.currentOwner .. "> to <" .. newOwner .. ">", 30)
trigger.action.outText("+++bCap: banging captured! with <" .. theZone.capturedMethod .. "> on <" .. theZone.capturedFlag .. "> for " .. theZone.baseName, 30)
end end
-- change the ownership
theZone.currentOwner = newOwner
if theZone.baseOwner then
cfxZones.setFlagValueMult(theZone.baseOwner, newOwner, theZone)
if baseCaptured.verbose or theZone.verbose then
trigger.action.outText("+++bCap: owner is " .. newOwner, 30)
end
end
end end
-- world event callback -- world event callback
@ -92,14 +103,16 @@ function baseCaptured:onEvent(event)
if event.id ~= world.event.S_EVENT_BASE_CAPTURED then if event.id ~= world.event.S_EVENT_BASE_CAPTURED then
return return
end end
if not event.place then
trigger.action.outText("+++bCap: capture event without place, aborting.", 30)
return
end
local baseName = event.place:getName() local baseName = event.place:getName()
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 == baseName if aZone.baseName == baseName then
local hasCoalition = aZone.captureCoalition == 0 or aZone.captureCoalition == newCoalition
if hasName and hasCoalition then
baseCaptured.triggerZone(aZone) baseCaptured.triggerZone(aZone)
end end
end end
@ -115,7 +128,7 @@ function baseCaptured.readConfigZone()
baseCaptured.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false) baseCaptured.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false)
if baseCaptured.verbose then if baseCaptured.verbose then
trigger.action.outText("***baseCaptured: read configuration from zone", 30) trigger.action.outText("+++bCap: read configuration from zone", 30)
end end
end end
@ -133,10 +146,10 @@ function baseCaptured.start()
baseCaptured.readConfigZone() baseCaptured.readConfigZone()
-- process all baseCaptured zones -- process all baseCaptured zones
local zones = cfxZones.getZonesWithAttributeNamed("baseCaptured") local zones = cfxZones.getZonesWithAttributeNamed("baseCaptured!")
for k, aZone in pairs(zones) do for k, aZone in pairs(zones) do
baseCaptured.createZone(aZone) -- process zone attributes baseCaptured.createZone(aZone) -- process zone attributes
baseCaptured.addZone(aZone) -- add to list baseCaptured.addBaseCaptureZone(aZone) -- add to list
end end
-- listen for events -- listen for events

View File

@ -6,7 +6,7 @@
-- --
cfxZones = {} cfxZones = {}
cfxZones.version = "2.7.5" cfxZones.version = "2.7.6"
--[[-- VERSION HISTORY --[[-- VERSION HISTORY
- 2.2.4 - getCoalitionFromZoneProperty - 2.2.4 - getCoalitionFromZoneProperty
- getStringFromZoneProperty - getStringFromZoneProperty
@ -70,6 +70,7 @@ cfxZones.version = "2.7.5"
- evalFlagMethodImmediate() - evalFlagMethodImmediate()
- 2.7.4 - doPollFlag supports immediate number setting - 2.7.4 - doPollFlag supports immediate number setting
- 2.7.5 - more QoL checks when mixing up ? and ! for attributes - 2.7.5 - more QoL checks when mixing up ? and ! for attributes
- 2.7.6 - trim for getBoolFromZoneProperty and getStringFromZoneProperty
--]]-- --]]--
cfxZones.verbose = false cfxZones.verbose = false
@ -1417,7 +1418,7 @@ end
function cfxZones.testZoneFlag(theZone, theFlagName, theMethod, latchName) function cfxZones.testZoneFlag(theZone, theFlagName, theMethod, latchName)
-- returns two values: true/false method result, and curr value -- returns two values: true/false method result, and curr value
-- returns true if method contraints are met for flag theFlagName -- returns true if method constraints are met for flag theFlagName
-- as defined by theMethod -- as defined by theMethod
if not theMethod then if not theMethod then
theMethod = "change" theMethod = "change"
@ -1587,6 +1588,7 @@ function cfxZones.getStringFromZoneProperty(theZone, theProperty, default)
local p = cfxZones.getZoneProperty(theZone, theProperty) local p = cfxZones.getZoneProperty(theZone, theProperty)
if not p then return default end if not p then return default end
if type(p) == "string" then if type(p) == "string" then
p = dcsCommon.trim(p)
if p == "" then p = default end if p == "" then p = default end
return p return p
end end
@ -1714,6 +1716,7 @@ function cfxZones.getBoolFromZoneProperty(theZone, theProperty, defaultVal)
-- make sure we compare so default always works when -- make sure we compare so default always works when
-- answer isn't exactly the opposite -- answer isn't exactly the opposite
p = p:lower() p = p:lower()
p = dcsCommon.trim(p)
if defaultVal == false then if defaultVal == false then
-- only go true if exact match to yes or true -- only go true if exact match to yes or true
theBool = false theBool = false

View File

@ -1,5 +1,5 @@
civAir = {} civAir = {}
civAir.version = "1.5.0" civAir.version = "1.5.1"
--[[-- --[[--
1.0.0 initial version 1.0.0 initial version
1.1.0 exclude list for airfields 1.1.0 exclude list for airfields
@ -21,6 +21,7 @@ civAir.version = "1.5.0"
reading type array from config corrected reading type array from config corrected
massive simplifications: always between zoned airfieds massive simplifications: always between zoned airfieds
exclude list and include list exclude list and include list
1.5.1 added depart only and arrive only options for airfields
--]]-- --]]--
@ -41,8 +42,7 @@ civAir.maxTraffic = 10 -- number of flights at the same time
civAir.maxIdle = 8 * 60 -- seconds of ide time before it is removed after landing civAir.maxIdle = 8 * 60 -- seconds of ide time before it is removed after landing
civAir.trafficCenters = { civAir.trafficCenters = {}
}
-- place zones on the map and add a "civAir" attribute. -- place zones on the map and add a "civAir" attribute.
-- If the attribute's value is anything -- If the attribute's value is anything
-- but "exclude", the closest airfield to the zone -- but "exclude", the closest airfield to the zone
@ -52,8 +52,7 @@ civAir.trafficCenters = {
-- by zones, the list is automatically populated with all -- by zones, the list is automatically populated with all
-- airfields in the map -- airfields in the map
civAir.excludeAirfields = { civAir.excludeAirfields = {}
}
-- list all airfields that must NOT be included in -- list all airfields that must NOT be included in
-- civilian activities. Will be used for neither landing -- civilian activities. Will be used for neither landing
-- nor departure. overrides any airfield that was included -- nor departure. overrides any airfield that was included
@ -62,6 +61,9 @@ civAir.excludeAirfields = {
-- can be populated by zone on the map that have the -- can be populated by zone on the map that have the
-- 'civAir' attribute with value "exclude" -- 'civAir' attribute with value "exclude"
civAir.departOnly = {} -- use only to start from
civAir.landingOnly = {} -- use only to land at
civAir.requiredLibs = { civAir.requiredLibs = {
"dcsCommon", -- common is of course needed for everything "dcsCommon", -- common is of course needed for everything
"cfxZones", -- zones management foc CSAR and CSAR Mission zones "cfxZones", -- zones management foc CSAR and CSAR Mission zones
@ -113,8 +115,13 @@ function civAir.processZone(theZone)
local af = dcsCommon.getClosestAirbaseTo(theZone.point, 0) -- 0 = only airfields, not farp or ships local af = dcsCommon.getClosestAirbaseTo(theZone.point, 0) -- 0 = only airfields, not farp or ships
if af then if af then
local afName = af:getName() local afName = af:getName()
if value:lower() == "exclude" then value = value:lower()
if value == "exclude" then
table.insert(civAir.excludeAirfields, afName) table.insert(civAir.excludeAirfields, afName)
elseif dcsCommon.stringStartsWith(value, "depart") or dcsCommon.stringStartsWith(value, "start") then
table.insert(civAir.departOnly, afName)
elseif dcsCommon.stringStartsWith(value, "land") or dcsCommon.stringStartsWith(value, "arriv") then
table.insert(civAir.landingOnly, afName)
else else
table.insert(civAir.trafficCenters, afName) -- note that adding the same twice makes it more likely to be picked table.insert(civAir.trafficCenters, afName) -- note that adding the same twice makes it more likely to be picked
end end
@ -169,31 +176,40 @@ function civAir.getTwoAirbases()
local fAB -- first airbase to depart local fAB -- first airbase to depart
local sAB -- second airbase to fly to local sAB -- second airbase to fly to
-- remove all currently excluded air bases from available local departAB = dcsCommon.combineTables(civAir.trafficCenters, civAir.departOnly)
local filteredAB = civAir.filterAirfields(civAir.trafficCenters, civAir.excludeAirfields) -- remove all currently excluded air bases from departure
local filteredAB = civAir.filterAirfields(departAB, civAir.excludeAirfields)
-- if none left, error -- if none left, error
if #filteredAB < 1 then if #filteredAB < 1 then
trigger.action.outText("+++civA: too few airfields") trigger.action.outText("+++civA: too few departure airfields")
return nil, nil return nil, nil
end end
-- now pick the departure airfield
fAB = dcsCommon.pickRandom(filteredAB)
-- now generate list of landing airfields
local arriveAB = dcsCommon.combineTables(civAir.trafficCenters, civAir.landingOnly)
-- remove all currently excluded air bases from arrival
filteredAB = civAir.filterAirfields(arriveAB, civAir.excludeAirfields)
-- if one left use it twice, boring flight. -- if one left use it twice, boring flight.
if #filteredAB < 2 then if #filteredAB < 1 then
local fabName = filteredAB[1] trigger.action.outText("+++civA: too few arrival airfields")
fAB = dcsCommon.getAirbasesWhoseNameContains(fabName, 0) return nil, nil
return fAB, fAB -- same twice
end end
-- pick any two that are not the same -- pick any second that are not the same
fAB = dcsCommon.pickRandom(filteredAB) local tries = 0
repeat repeat
sAB = dcsCommon.pickRandom(filteredAB) sAB = dcsCommon.pickRandom(filteredAB)
until fAB ~= sAB tries = tries + 1 -- only try 10 times
until fAB ~= sAB or tries > 10
fAB = dcsCommon.getFirstAirbaseWhoseNameContains(fAB, 0) fAB = dcsCommon.getFirstAirbaseWhoseNameContains(fAB, 0)
sAB = dcsCommon.getFirstAirbaseWhoseNameContains(sAB, 0) sAB = dcsCommon.getFirstAirbaseWhoseNameContains(sAB, 0)
return fAB, sAB return fAB, sAB
end end
function civAir.parkingIsFree(fromWP) function civAir.parkingIsFree(fromWP)
@ -433,6 +449,20 @@ function civAir.listTrafficCenters()
for idx, aName in pairs(civAir.trafficCenters) do for idx, aName in pairs(civAir.trafficCenters) do
trigger.action.outText(aName, 30) trigger.action.outText(aName, 30)
end end
if #civAir.departOnly > 0 then
trigger.action.outText("Departure-Only:", 30)
for idx, aName in pairs(civAir.departOnly) do
trigger.action.outText(aName, 30)
end
end
if #civAir.landingOnly > 0 then
trigger.action.outText("Arrival/Landing-Only:", 30)
for idx, aName in pairs(civAir.landingOnly) do
trigger.action.outText(aName, 30)
end
end
end end
-- start -- start
@ -449,7 +479,9 @@ function civAir.start()
civAir.collectHubs() civAir.collectHubs()
-- make sure there is something in trafficCenters -- make sure there is something in trafficCenters
if #civAir.trafficCenters < 1 then if (#civAir.trafficCenters + #civAir.departOnly < 1) or
(#civAir.trafficCenters + #civAir.landingOnly < 1)
then
trigger.action.outText("+++civA: auto-populating", 30) trigger.action.outText("+++civA: auto-populating", 30)
-- simply add airfields on the map -- simply add airfields on the map
local allBases = dcsCommon.getAirbasesWhoseNameContains("*", 0) local allBases = dcsCommon.getAirbasesWhoseNameContains("*", 0)

View File

@ -1,5 +1,5 @@
cloneZones = {} cloneZones = {}
cloneZones.version = "1.4.2" cloneZones.version = "1.4.4"
cloneZones.verbose = false cloneZones.verbose = false
cloneZones.requiredLibs = { cloneZones.requiredLibs = {
"dcsCommon", -- always "dcsCommon", -- always
@ -40,6 +40,9 @@ cloneZones.uniqueCounter = 9200000 -- we start group numbering here
1.4.1 - trackWith: accepts list of trackers 1.4.1 - trackWith: accepts list of trackers
1.4.2 - onstart delays for 0.1 s to prevent static stacking 1.4.2 - onstart delays for 0.1 s to prevent static stacking
- turn bug for statics (bug in dcsCommon, resolved) - turn bug for statics (bug in dcsCommon, resolved)
1.4.3 - embark/disembark now works with cloners
1.4.4 - removed some debugging verbosity
--]]-- --]]--
@ -406,6 +409,8 @@ end
-- --
function cloneZones.resolveGroupID(gID, rawData, dataTable, reason) function cloneZones.resolveGroupID(gID, rawData, dataTable, reason)
if not reason then reason = "<default>" end
local resolvedID = gID local resolvedID = gID
local myOName = rawData.CZorigName local myOName = rawData.CZorigName
local groupName = cfxMX.groupNamesByID[gID] local groupName = cfxMX.groupNamesByID[gID]
@ -511,7 +516,55 @@ function cloneZones.resolveWPReferences(rawData, theZone, dataTable)
end end
-- resolve unit references in TASKS -- resolve EMBARK/DISEMBARK groupd references
if taskData.id and taskData.params and taskData.params.groupsForEmbarking
then
-- build new groupsForEmbarking
local embarkers = taskData.params.groupsForEmbarking
local newEmbarkers = {}
for grpIdx, gID in pairs(embarkers) do
local resolvedID = cloneZones.resolveGroupID(gID, rawData, dataTable, "embark")
table.insert(newEmbarkers, resolvedID)
trigger.action.outText("+++clnZ: resolved embark group id <" .. gID .. "> to <" .. resolvedID .. ">", 30)
end
-- replace old with new table
taskData.params.groupsForEmbarking = newEmbarkers
end
-- resolve DISTRIBUTION (embark) unit/group refs
if taskData.id and taskData.params and taskData.params.distribution then
local newDist = {} -- will replace old
for aUnit, aList in pairs(taskData.params.distribution) do
-- first, translate this unit's number
local newUnit = cloneZones.resolveUnitID(aUnit, rawData, dataTable, "transportID")
local embarkers = aList
local newEmbarkers = {}
for grpIdx, gID in pairs(embarkers) do
-- translate old to new
local resolvedID = cloneZones.resolveGroupID(gID, rawData, dataTable, "embark")
table.insert(newEmbarkers, resolvedID)
trigger.action.outText("+++clnZ: resolved distribute unit/group id <" .. aUnit .. "/" .. gID .. "> to <".. newUnit .. "/" .. resolvedID .. ">", 30)
end
-- store this as new group for
-- translated transportID
newDist[newUnit] = newEmbarkers
end
-- replace old distribution with new
taskData.params.distribution = newDist
trigger.action.outText("+++clnZ: rebuilt distribution", 30)
end
-- resolve selectedTransport unit reference
if taskData.id and taskData.params and taskData.params.selectedTransportt then
local tID = taskData.params.selectedTransport
local newTID = cloneZones.resolveUnitID(tID, rawData, dataTable, "transportID")
taskData.params.selectedTransport = newTID
rigger.action.outText("+++clnZ: resolved selected transport <" .. tID .. "> to <" .. newTID .. ">", 30)
end
-- note: we may need to process x and y as well
-- resolve UNIT references in TASKS
if taskData.id and taskData.params and taskData.params.unitId if taskData.id and taskData.params and taskData.params.unitId
then then
-- we don't look for keywords, we simply resolve -- we don't look for keywords, we simply resolve
@ -690,7 +743,7 @@ function cloneZones.spawnWithTemplateForZone(theZone, spawnZone)
-- now use raw data to spawn and see if it works outabox -- now use raw data to spawn and see if it works outabox
--local theCat = cfxMX.catText2ID(cat) -- will be "static" --local theCat = cfxMX.catText2ID(cat) -- will be "static"
trigger.action.outText("static object proccing", 30) -- trigger.action.outText("static object proccing", 30)
rawData.x = rawData.x + zoneDelta.x rawData.x = rawData.x + zoneDelta.x
rawData.y = rawData.y + zoneDelta.z -- !!! rawData.y = rawData.y + zoneDelta.z -- !!!

View File

@ -1,5 +1,5 @@
dcsCommon = {} dcsCommon = {}
dcsCommon.version = "2.6.1" dcsCommon.version = "2.6.2"
--[[-- VERSION HISTORY --[[-- VERSION HISTORY
2.2.6 - compassPositionOfARelativeToB 2.2.6 - compassPositionOfARelativeToB
- clockPositionOfARelativeToB - clockPositionOfARelativeToB
@ -71,6 +71,7 @@ dcsCommon.version = "2.6.1"
2.5.9 - string2ObjectCat() 2.5.9 - string2ObjectCat()
2.6.0 - unified uuid, removed uuIdent 2.6.0 - unified uuid, removed uuIdent
2.6.1 - removed bug in rotateUnitData: cy --> cz param passing 2.6.1 - removed bug in rotateUnitData: cy --> cz param passing
2.6.2 - new combineTables()
--]]-- --]]--
@ -199,6 +200,17 @@ dcsCommon.version = "2.6.1"
return array return array
end end
-- combine table. creates new
function dcsCommon.combineTables(inOne, inTwo)
local outTable = {}
for idx, element in pairs(inOne) do
table.insert(outTable, element)
end
for idx, element in pairs(inTwo) do
table.insert(outTable, element)
end
return outTable
end
-- --
-- A I R F I E L D S A N D F A R P S -- A I R F I E L D S A N D F A R P S
-- --

View File

@ -1,5 +1,5 @@
xFlags = {} xFlags = {}
xFlags.version = "1.2.1" xFlags.version = "1.3.0"
xFlags.verbose = false xFlags.verbose = false
xFlags.hiVerbose = false xFlags.hiVerbose = false
xFlags.ups = 1 -- overwritten in get config when configZone is present xFlags.ups = 1 -- overwritten in get config when configZone is present
@ -26,6 +26,8 @@ xFlags.requiredLibs = {
1.2.2 - on/off/suspend commands 1.2.2 - on/off/suspend commands
- hiVerbose option - hiVerbose option
- corrected bug in reset checksum - corrected bug in reset checksum
1.3.0 - xCount! flag
- "never" operator
--]]-- --]]--
xFlags.xFlagZones = {} xFlags.xFlagZones = {}
@ -94,7 +96,9 @@ function xFlags.createXFlagsWithZone(theZone)
theZone.xChange = cfxZones.getStringFromZoneProperty(theZone, "xChange!", "*<none>") theZone.xChange = cfxZones.getStringFromZoneProperty(theZone, "xChange!", "*<none>")
end end
theZone.xDirect = cfxZones.getStringFromZoneProperty(theZone, "xDirect!", "*<none>") theZone.xDirect = cfxZones.getStringFromZoneProperty(theZone, "xDirect", "*<none>")
theZone.xCount = cfxZones.getStringFromZoneProperty(theZone, "xCount", "*<none>")
theZone.inspect = cfxZones.getStringFromZoneProperty(theZone, "require", "or") -- same as any theZone.inspect = cfxZones.getStringFromZoneProperty(theZone, "require", "or") -- same as any
-- supported any/or, all/and, moreThan, atLeast, exactly -- supported any/or, all/and, moreThan, atLeast, exactly
@ -297,6 +301,7 @@ function xFlags.evaluateZone(theZone)
local hits, checkSum = xFlags.evaluateFlags(theZone) local hits, checkSum = xFlags.evaluateFlags(theZone)
-- depending on inspect see what the outcome is -- depending on inspect see what the outcome is
-- supported any/or, all/and, moreThan, atLeast, exactly -- supported any/or, all/and, moreThan, atLeast, exactly
-- if require = "never", we never trigger
local op = theZone.inspect local op = theZone.inspect
local evalResult = false local evalResult = false
if (op == "or" or op == "any" or op == "some") then if (op == "or" or op == "any" or op == "some") then
@ -327,6 +332,9 @@ function xFlags.evaluateZone(theZone)
-- warning: 'half' means really 'at least half" -- warning: 'half' means really 'at least half"
evalResult = true evalResult = true
end end
elseif op == "never" then
evalResult = false -- not required, just to be explicit
else else
trigger.action.outText("+++xFlg: WARNING: <" .. theZone.name .. "> has unknown requirement: <" .. op .. ">", 30) trigger.action.outText("+++xFlg: WARNING: <" .. theZone.name .. "> has unknown requirement: <" .. op .. ">", 30)
end end
@ -353,7 +361,7 @@ function xFlags.evaluateZone(theZone)
end end
-- now directly set the value of evalResult (0 = false, 1 = true) -- now directly set the value of evalResult (0 = false, 1 = true)
-- to "xDirect!". Always sets output to current result of evaluation -- to "xDirect". Always sets output to current result of evaluation
-- true (1)/false(0), no matter if changed or not -- true (1)/false(0), no matter if changed or not
if evalResult then if evalResult then
@ -362,6 +370,9 @@ function xFlags.evaluateZone(theZone)
cfxZones.setFlagValueMult(theZone.xDirect, 0, theZone) cfxZones.setFlagValueMult(theZone.xDirect, 0, theZone)
end end
-- directly set the xCount flag
cfxZones.setFlagValueMult(theZone.xCount, hits, theZone)
-- now see if we bang the output according to method -- now see if we bang the output according to method
if evalResult then if evalResult then
if xFlags.verbose or theZone.verbose then if xFlags.verbose or theZone.verbose then

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,13 @@
skel = {}
function skel:onEvent(event) -- event handler
end
function skel.update()
-- schedule next update invocation
timer.scheduleFunction(skel.update, {}, timer.getTime() + 1)
-- your own stuff and checks here
trigger.action.outText("DCS, this is Lua. Hello. Lua.", 30)
end
world.addEventHandler(skel) -- connect event hander
skel.update() -- start update cycle