Version 0.999

Changer, pulse, lohi, hilo
This commit is contained in:
Christian Franz 2022-05-12 12:30:45 +02:00
parent cc46e5fb10
commit 964a00dbbd
7 changed files with 143 additions and 29 deletions

Binary file not shown.

Binary file not shown.

View File

@ -5,7 +5,7 @@
-- Copyright (c) 2021, 2022 by Christian Franz and cf/x AG -- Copyright (c) 2021, 2022 by Christian Franz and cf/x AG
-- --
cfxZones = {} cfxZones = {}
cfxZones.version = "2.7.7" cfxZones.version = "2.7.8"
--[[-- VERSION HISTORY --[[-- VERSION HISTORY
- 2.2.4 - getCoalitionFromZoneProperty - 2.2.4 - getCoalitionFromZoneProperty
- getStringFromZoneProperty - getStringFromZoneProperty
@ -72,6 +72,13 @@ cfxZones.version = "2.7.7"
- 2.7.6 - trim for getBoolFromZoneProperty and getStringFromZoneProperty - 2.7.6 - trim for getBoolFromZoneProperty and getStringFromZoneProperty
- 2.7.7 - randomInRange() - 2.7.7 - randomInRange()
- show number of zones - show number of zones
- 2.7.8 - inc method now triggers if curr value > last value
- dec method noew triggers when curr value < last value
- testFlagByMethodForZone supports lohi, hilo transitions
- doPollFlag supports 'pulse'
- pulseFlag
- unpulse
--]]-- --]]--
cfxZones.verbose = false cfxZones.verbose = false
@ -1079,6 +1086,41 @@ end
-- --
-- Flag Pulling -- Flag Pulling
-- --
function cfxZones.pulseFlag(theFlag, method, theZone)
local args = {}
args.theFlag = theFlag
args.method = method
args.theZone = theZone
local delay = 3
if dcsCommon.containsString(method, ",") then
local parts = dcsCommon.splitString(method, ",")
delay = parts[2]
if delay then delay = tonumber(delay) end
end
if not delay then delay = 3 end
if theZone.verbose then
trigger.action.outText("+++zne: RAISING pulse t="..delay.." for flag <" .. theFlag .. "> in zone <" .. theZone.name ..">", 30)
end
local newVal = 1
cfxZones.setFlagValue(theFlag, newVal, theZone)
-- schedule second half of pulse
timer.scheduleFunction(cfxZones.unPulseFlag, args, timer.getTime() + delay)
end
function cfxZones.unPulseFlag(args)
local theZone = args.theZone
local method = args.method
local theFlag = args.theFlag
local newVal = 0
-- we may later use method to determine pulse direction / newVal
-- for now, we always go low
if theZone.verbose then
trigger.action.outText("+++zne: DOWNPULSE pulse for flag <" .. theFlag .. "> in zone <" .. theZone.name ..">", 30)
end
cfxZones.setFlagValue(theFlag, newVal, theZone)
end
function cfxZones.doPollFlag(theFlag, method, theZone) function cfxZones.doPollFlag(theFlag, method, theZone)
if cfxZones.verbose then if cfxZones.verbose then
trigger.action.outText("+++zones: polling flag " .. theFlag .. " with " .. method, 30) trigger.action.outText("+++zones: polling flag " .. theFlag .. " with " .. method, 30)
@ -1123,6 +1165,9 @@ function cfxZones.doPollFlag(theFlag, method, theZone)
cfxZones.setFlagValue(theFlag, 1, theZone) cfxZones.setFlagValue(theFlag, 1, theZone)
end end
elseif dcsCommon.stringStartsWith(method, "pulse") then
cfxZones.pulseFlag(theFlag, method, theZone)
else else
if method ~= "on" and method ~= "f=1" then if method ~= "on" and method ~= "f=1" then
trigger.action.outText("+++zones: unknown method <" .. method .. "> - using 'on'", 30) trigger.action.outText("+++zones: unknown method <" .. method .. "> - using 'on'", 30)
@ -1353,13 +1398,23 @@ function cfxZones.testFlagByMethodForZone(currVal, lastVal, theMethod, theZone)
end end
if lMethod == "inc" or lMethod == "+1" then if lMethod == "inc" or lMethod == "+1" then
return currVal == lastVal+1 -- return currVal == lastVal+1 -- better: test for greater than
return currVal > lastVal
end end
if lMethod == "dec" or lMethod == "-1" then if lMethod == "dec" or lMethod == "-1" then
return currVal == lastVal-1 --return currVal == lastVal-1
return currVal < lastVal
end end
if lMethod == "lohi" or lMethod == "pulse" then
return (lastVal <= 0 and currVal > 0)
end
if lMethod == "hilo" then
return (lastVal > 0 and currVal <= 0)
end
-- number constraints -- number constraints
-- or flag constraints -- or flag constraints
-- ONLY RETURN TRUE IF CHANGE AND CONSTRAINT MET -- ONLY RETURN TRUE IF CHANGE AND CONSTRAINT MET

View File

@ -15,6 +15,8 @@ changer.changers = {}
- not - not
- bool - bool
- value - value
- min, max as separate params
--]]-- --]]--
@ -37,9 +39,9 @@ end
-- read zone -- read zone
-- --
function changer.createChangerWithZone(theZone) function changer.createChangerWithZone(theZone)
theZone.triggerChangerFlag = cfxZones.getStringFromZoneProperty(theZone, "change?", "*<none>") theZone.changerInputFlag = cfxZones.getStringFromZoneProperty(theZone, "change?", "*<none>")
-- if theZone.triggerChangerFlag then -- if theZone.changerInputFlag then
theZone.lastTriggerChangeValue = cfxZones.getFlagValue(theZone.triggerChangerFlag, theZone) theZone.lastTriggerChangeValue = cfxZones.getFlagValue(theZone.changerInputFlag, theZone)
-- end -- end
-- triggerChangerMethod -- triggerChangerMethod
@ -48,7 +50,7 @@ function changer.createChangerWithZone(theZone)
theZone.triggerChangerMethod = cfxZones.getStringFromZoneProperty(theZone, "triggerChangeMethod", "change") theZone.triggerChangerMethod = cfxZones.getStringFromZoneProperty(theZone, "triggerChangeMethod", "change")
end end
theZone.inEval = cfxZones.getBoolFromZoneProperty(theZone, "inEval", true) -- yes/no to pre-process, default is yes theZone.inEval = cfxZones.getBoolFromZoneProperty(theZone, "inEval", false) -- yes/no to pre-process, default is no, we read value
theZone.changeTo = cfxZones.getStringFromZoneProperty(theZone, "to", "val") -- val, not, bool theZone.changeTo = cfxZones.getStringFromZoneProperty(theZone, "to", "val") -- val, not, bool
@ -89,6 +91,19 @@ function changer.createChangerWithZone(theZone)
trigger.action.outText("+++chgr: new changer zone <".. theZone.name ..">", 30) trigger.action.outText("+++chgr: new changer zone <".. theZone.name ..">", 30)
end end
if cfxZones.hasProperty(theZone, "min") then
theZone.changeMin = cfxZones.getNumberFromZoneProperty(theZone, "min", 0)
end
if cfxZones.hasProperty(theZone, "max") then
theZone.changeMax = cfxZones.getNumberFromZoneProperty(theZone, "max", 1)
end
if cfxZones.hasProperty(theZone, "On/Off?") then
theZone.changerOnOff = cfxZones.getStringFromZoneProperty(theZone, "On/Off?", "*<none>", 1)
end
if cfxZones.hasProperty(theZone, "changeOn/Off?") then
theZone.changerOnOff = cfxZones.getStringFromZoneProperty(theZone, "changeOn/Off?", "*<none>", 1)
end
end end
-- --
@ -96,7 +111,7 @@ end
-- --
function changer.process(theZone) function changer.process(theZone)
-- read the line -- read the line
local inVal = cfxZones.getFlagValue(theZone.triggerChangerFlag, theZone) local inVal = cfxZones.getFlagValue(theZone.changerInputFlag, theZone)
currVal = inVal currVal = inVal
if theZone.inEval then if theZone.inEval then
currVal = cfxZones.evalFlagMethodImmediate(currVal, theZone.triggerChangerMethod, theZone) currVal = cfxZones.evalFlagMethodImmediate(currVal, theZone.triggerChangerMethod, theZone)
@ -111,15 +126,42 @@ function changer.process(theZone)
-- process and write outflag -- process and write outflag
if op == "bool" then if op == "bool" then
if currVal == 0 then res = 0 else res = 1 end if currVal == 0 then res = 0 else res = 1 end
elseif op == "not" then
if currVal == 0 then res = 1 else res = 0 end
elseif op == "val" or op == "direct" then elseif op == "val" or op == "direct" then
-- do nothing -- do nothing
elseif op == "not" then
if currVal == 0 then res = 1 else res = 0 end
elseif op == "sign" or op == "sgn" then
if currVal < 0 then res = -1 else res = 1 end
elseif op == "inv" or op == "invert" or op == "neg" or op == "negative" then
res = -res
elseif op == "abs" then
res = math.abs(res)
else else
trigger.action.outText("+++chgr: unsupported changeTo operation <" .. .. "> in zone <" .. .. ">, using 'val'", 30) trigger.action.outText("+++chgr: unsupported changeTo operation <" .. op .. "> in zone <" .. theZone.name .. ">, using 'val' instead", 30)
end end
-- illegal ops drop through after warning, functioning as 'val' -- illegal ops drop through after warning, functioning as 'val'
-- min / max handling
if theZone.changeMin then
if theZone.verbose then
trigger.action.outText("+++chgr: applying min " .. theZone.changeMin .. " to curr val: " .. res, 30)
end
if res < theZone.changeMin then res = theZone.changeMin end
end
if theZone.changeMax then
if theZone.verbose then
trigger.action.outText("+++chgr: applying max " .. theZone.changeMax .. " to curr val: " .. res, 30)
end
if res > theZone.changeMax then res = theZone.changeMax end
end
-- write out -- write out
cfxZones.setFlagValueMult(theZone.changeOut, res, theZone) cfxZones.setFlagValueMult(theZone.changeOut, res, theZone)
if changer.verbose or theZone.verbose then if changer.verbose or theZone.verbose then
@ -143,23 +185,29 @@ function changer.update()
-- process the pause/unpause flags -- process the pause/unpause flags
-- see if we should suspend -- see if we should suspend
if cfxZones.testZoneFlag(theZone, theZone.changerOn, "change", "lastChangerOnValue") then if cfxZones.testZoneFlag(aZone, aZone.changerOn, "change", "lastChangerOnValue") then
if changer.verbose or theZone.verbose then if changer.verbose or aZone.verbose then
trigger.action.outText("+++chgr: enabling " .. theZone.name, 30) trigger.action.outText("+++chgr: enabling " .. aZone.name, 30)
end end
theZone.changerPaused = false aZone.changerPaused = false
end end
if cfxZones.testZoneFlag(theZone, theZone.changerOff, "change", "lastChangerOffValue") then if cfxZones.testZoneFlag(aZone, aZone.changerOff, "change", "lastChangerOffValue") then
if changer.verbose or theZone.verbose then if changer.verbose or aZone.verbose then
trigger.action.outText("+++chgr: DISabling " .. theZone.name, 30) trigger.action.outText("+++chgr: DISabling " .. aZone.name, 30)
end end
theZone.changerPaused = true aZone.changerPaused = true
end end
-- do processing if not paused -- do processing if not paused
if not aZone.changerPaused then if not aZone.changerPaused then
changer.process(aZone) if aZone.changerOnOff then
if cfxZones.getFlagValue(aZone.changerOnOff, aZone) > 0 then
changer.process(aZone)
end
else
changer.process(aZone)
end
end end
end end
end end
@ -222,6 +270,5 @@ end
--[[-- --[[--
Possible expansions Possible expansions
- rnd - rnd
- min, max minmax 2,3, cap to left right values,
--]]-- --]]--

View File

@ -1,5 +1,5 @@
cloneZones = {} cloneZones = {}
cloneZones.version = "1.4.5" cloneZones.version = "1.4.6"
cloneZones.verbose = false cloneZones.verbose = false
cloneZones.requiredLibs = { cloneZones.requiredLibs = {
"dcsCommon", -- always "dcsCommon", -- always
@ -44,6 +44,7 @@
1.4.4 - removed some debugging verbosity 1.4.4 - removed some debugging verbosity
1.4.5 - randomizeLoc, rndLoc keyword 1.4.5 - randomizeLoc, rndLoc keyword
- cargo manager integration - pass cargo objects when present - cargo manager integration - pass cargo objects when present
1.4.6 - removed some verbosity for spawned aircraft with airfields on their routes
--]]-- --]]--
@ -340,28 +341,28 @@
-- adjust for closest location -- adjust for closest location
local firstPoint = thePoints[1] local firstPoint = thePoints[1]
if firstPoint.airdromeId then if firstPoint.airdromeId then
trigger.action.outText("first: airdrome adjust for " .. theData.name .. " now is " .. firstPoint.airdromeId, 30) -- trigger.action.outText("first: airdrome adjust for " .. theData.name .. " now is " .. firstPoint.airdromeId, 30)
local loc = {} local loc = {}
loc.x = firstPoint.x loc.x = firstPoint.x
loc.y = 0 loc.y = 0
loc.z = firstPoint.y loc.z = firstPoint.y
local bestAirbase = dcsCommon.getClosestAirbaseTo(loc) local bestAirbase = dcsCommon.getClosestAirbaseTo(loc)
firstPoint.airdromeId = bestAirbase:getID() firstPoint.airdromeId = bestAirbase:getID()
trigger.action.outText("first: adjusted to " .. firstPoint.airdromeId, 30) -- trigger.action.outText("first: adjusted to " .. firstPoint.airdromeId, 30)
end end
-- adjust last point (landing) -- adjust last point (landing)
if #thePoints > 1 then if #thePoints > 1 then
local lastPoint = thePoints[#thePoints] local lastPoint = thePoints[#thePoints]
if firstPoint.airdromeId then if firstPoint.airdromeId then
trigger.action.outText("last: airdrome adjust for " .. theData.name .. " now is " .. lastPoint.airdromeId, 30) -- trigger.action.outText("last: airdrome adjust for " .. theData.name .. " now is " .. lastPoint.airdromeId, 30)
local loc = {} local loc = {}
loc.x = lastPoint.x loc.x = lastPoint.x
loc.y = 0 loc.y = 0
loc.z = lastPoint.y loc.z = lastPoint.y
local bestAirbase = dcsCommon.getClosestAirbaseTo(loc) local bestAirbase = dcsCommon.getClosestAirbaseTo(loc)
lastPoint.airdromeId = bestAirbase:getID() lastPoint.airdromeId = bestAirbase:getID()
trigger.action.outText("last: adjusted to " .. lastPoint.airdromeId, 30) -- trigger.action.outText("last: adjusted to " .. lastPoint.airdromeId, 30)
end end
end end

View File

@ -1,5 +1,5 @@
unitZone={} unitZone={}
unitZone.version = "1.2.1" unitZone.version = "1.2.2"
unitZone.verbose = false unitZone.verbose = false
unitZone.ups = 1 unitZone.ups = 1
unitZone.requiredLibs = { unitZone.requiredLibs = {
@ -13,6 +13,7 @@ unitZone.requiredLibs = {
- method/uzMethod - method/uzMethod
1.2.0 - uzOn?, uzOff?, triggerMethod 1.2.0 - uzOn?, uzOff?, triggerMethod
1.2.1 - uzDirect 1.2.1 - uzDirect
1.2.2 - uzDirectInv
--]]-- --]]--
@ -101,6 +102,9 @@ function unitZone.createUnitZone(theZone)
if cfxZones.hasProperty(theZone, "uzDirect") then if cfxZones.hasProperty(theZone, "uzDirect") then
theZone.uzDirect = cfxZones.getStringFromZoneProperty(theZone, "uzDirect", "*<none>") theZone.uzDirect = cfxZones.getStringFromZoneProperty(theZone, "uzDirect", "*<none>")
end end
if cfxZones.hasProperty(theZone, "uzDirectInv") then
theZone.uzDirectInv = cfxZones.getStringFromZoneProperty(theZone, "uzDirectInv", "*<none>")
end
-- on/off flags -- on/off flags
theZone.uzPaused = false -- we are turned on theZone.uzPaused = false -- we are turned on
@ -267,7 +271,7 @@ function unitZone.update()
aZone.lastStatus = newState aZone.lastStatus = newState
end end
-- output direct state -- output direct state suite
if aZone.uzDirect then if aZone.uzDirect then
if newState then if newState then
cfxZones.setFlagValueMult(aZone.uzDirect, 1, aZone) cfxZones.setFlagValueMult(aZone.uzDirect, 1, aZone)
@ -275,6 +279,13 @@ function unitZone.update()
cfxZones.setFlagValueMult(aZone.uzDirect, 0, aZone) cfxZones.setFlagValueMult(aZone.uzDirect, 0, aZone)
end end
end end
if aZone.uzDirectInv then
if newState then
cfxZones.setFlagValueMult(aZone.uzDirectInv, 0, aZone)
else
cfxZones.setFlagValueMult(aZone.uzDirectInv, 1, aZone)
end
end
end end
end end
end end

Binary file not shown.