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
--
cfxZones = {}
cfxZones.version = "2.7.7"
cfxZones.version = "2.7.8"
--[[-- VERSION HISTORY
- 2.2.4 - getCoalitionFromZoneProperty
- getStringFromZoneProperty
@ -72,6 +72,13 @@ cfxZones.version = "2.7.7"
- 2.7.6 - trim for getBoolFromZoneProperty and getStringFromZoneProperty
- 2.7.7 - randomInRange()
- 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
@ -1079,6 +1086,41 @@ end
--
-- 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)
if cfxZones.verbose then
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)
end
elseif dcsCommon.stringStartsWith(method, "pulse") then
cfxZones.pulseFlag(theFlag, method, theZone)
else
if method ~= "on" and method ~= "f=1" then
trigger.action.outText("+++zones: unknown method <" .. method .. "> - using 'on'", 30)
@ -1353,11 +1398,21 @@ function cfxZones.testFlagByMethodForZone(currVal, lastVal, theMethod, theZone)
end
if lMethod == "inc" or lMethod == "+1" then
return currVal == lastVal+1
-- return currVal == lastVal+1 -- better: test for greater than
return currVal > lastVal
end
if lMethod == "dec" or lMethod == "-1" then
return currVal == lastVal-1
--return currVal == lastVal-1
return currVal < lastVal
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

View File

@ -15,6 +15,8 @@ changer.changers = {}
- not
- bool
- value
- min, max as separate params
--]]--
@ -37,9 +39,9 @@ end
-- read zone
--
function changer.createChangerWithZone(theZone)
theZone.triggerChangerFlag = cfxZones.getStringFromZoneProperty(theZone, "change?", "*<none>")
-- if theZone.triggerChangerFlag then
theZone.lastTriggerChangeValue = cfxZones.getFlagValue(theZone.triggerChangerFlag, theZone)
theZone.changerInputFlag = cfxZones.getStringFromZoneProperty(theZone, "change?", "*<none>")
-- if theZone.changerInputFlag then
theZone.lastTriggerChangeValue = cfxZones.getFlagValue(theZone.changerInputFlag, theZone)
-- end
-- triggerChangerMethod
@ -48,7 +50,7 @@ function changer.createChangerWithZone(theZone)
theZone.triggerChangerMethod = cfxZones.getStringFromZoneProperty(theZone, "triggerChangeMethod", "change")
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
@ -89,6 +91,19 @@ function changer.createChangerWithZone(theZone)
trigger.action.outText("+++chgr: new changer zone <".. theZone.name ..">", 30)
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
--
@ -96,7 +111,7 @@ end
--
function changer.process(theZone)
-- read the line
local inVal = cfxZones.getFlagValue(theZone.triggerChangerFlag, theZone)
local inVal = cfxZones.getFlagValue(theZone.changerInputFlag, theZone)
currVal = inVal
if theZone.inEval then
currVal = cfxZones.evalFlagMethodImmediate(currVal, theZone.triggerChangerMethod, theZone)
@ -111,15 +126,42 @@ function changer.process(theZone)
-- process and write outflag
if op == "bool" then
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
-- 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
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
-- 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
cfxZones.setFlagValueMult(theZone.changeOut, res, theZone)
if changer.verbose or theZone.verbose then
@ -143,23 +185,29 @@ function changer.update()
-- process the pause/unpause flags
-- see if we should suspend
if cfxZones.testZoneFlag(theZone, theZone.changerOn, "change", "lastChangerOnValue") then
if changer.verbose or theZone.verbose then
trigger.action.outText("+++chgr: enabling " .. theZone.name, 30)
if cfxZones.testZoneFlag(aZone, aZone.changerOn, "change", "lastChangerOnValue") then
if changer.verbose or aZone.verbose then
trigger.action.outText("+++chgr: enabling " .. aZone.name, 30)
end
theZone.changerPaused = false
aZone.changerPaused = false
end
if cfxZones.testZoneFlag(theZone, theZone.changerOff, "change", "lastChangerOffValue") then
if changer.verbose or theZone.verbose then
trigger.action.outText("+++chgr: DISabling " .. theZone.name, 30)
if cfxZones.testZoneFlag(aZone, aZone.changerOff, "change", "lastChangerOffValue") then
if changer.verbose or aZone.verbose then
trigger.action.outText("+++chgr: DISabling " .. aZone.name, 30)
end
theZone.changerPaused = true
aZone.changerPaused = true
end
-- do processing if not paused
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
@ -222,6 +270,5 @@ end
--[[--
Possible expansions
- rnd
- min, max minmax 2,3, cap to left right values,
--]]--

View File

@ -1,5 +1,5 @@
cloneZones = {}
cloneZones.version = "1.4.5"
cloneZones.version = "1.4.6"
cloneZones.verbose = false
cloneZones.requiredLibs = {
"dcsCommon", -- always
@ -44,6 +44,7 @@
1.4.4 - removed some debugging verbosity
1.4.5 - randomizeLoc, rndLoc keyword
- 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
local firstPoint = thePoints[1]
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 = {}
loc.x = firstPoint.x
loc.y = 0
loc.z = firstPoint.y
local bestAirbase = dcsCommon.getClosestAirbaseTo(loc)
firstPoint.airdromeId = bestAirbase:getID()
trigger.action.outText("first: adjusted to " .. firstPoint.airdromeId, 30)
-- trigger.action.outText("first: adjusted to " .. firstPoint.airdromeId, 30)
end
-- adjust last point (landing)
if #thePoints > 1 then
local lastPoint = thePoints[#thePoints]
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 = {}
loc.x = lastPoint.x
loc.y = 0
loc.z = lastPoint.y
local bestAirbase = dcsCommon.getClosestAirbaseTo(loc)
lastPoint.airdromeId = bestAirbase:getID()
trigger.action.outText("last: adjusted to " .. lastPoint.airdromeId, 30)
-- trigger.action.outText("last: adjusted to " .. lastPoint.airdromeId, 30)
end
end

View File

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

Binary file not shown.