mirror of
https://github.com/weyne85/DML.git
synced 2025-10-29 16:57:49 +00:00
Version 0.9993
minor updates
This commit is contained in:
parent
bc5ac5771c
commit
ca1bbd8e66
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
cfxSpawnZones = {}
|
cfxSpawnZones = {}
|
||||||
cfxSpawnZones.version = "1.5.3"
|
cfxSpawnZones.version = "1.6.0"
|
||||||
cfxSpawnZones.requiredLibs = {
|
cfxSpawnZones.requiredLibs = {
|
||||||
"dcsCommon", -- common is of course needed for everything
|
"dcsCommon", -- common is of course needed for everything
|
||||||
-- pretty stupid to check for this since we
|
-- pretty stupid to check for this since we
|
||||||
@ -53,6 +53,7 @@ cfxSpawnZones.verbose = false
|
|||||||
-- - verbose
|
-- - verbose
|
||||||
-- 1.5.2 - activate?, pause? flag
|
-- 1.5.2 - activate?, pause? flag
|
||||||
-- 1.5.3 - spawn?, spawnUnits? flags
|
-- 1.5.3 - spawn?, spawnUnits? flags
|
||||||
|
-- 1.6.0 - trackwith interface for group tracker
|
||||||
--
|
--
|
||||||
-- new version requires cfxGroundTroops, where they are
|
-- new version requires cfxGroundTroops, where they are
|
||||||
--
|
--
|
||||||
@ -135,6 +136,13 @@ function cfxSpawnZones.createSpawner(inZone)
|
|||||||
local theSpawner = {}
|
local theSpawner = {}
|
||||||
theSpawner.zone = inZone
|
theSpawner.zone = inZone
|
||||||
theSpawner.name = inZone.name
|
theSpawner.name = inZone.name
|
||||||
|
|
||||||
|
-- interface to groupTracker
|
||||||
|
-- WARNING: attaches to ZONE, not spawner object
|
||||||
|
if cfxZones.hasProperty(inZone, "trackWith:") then
|
||||||
|
inZone.trackWith = cfxZones.getStringFromZoneProperty(inZone, "trackWith:", "<None>")
|
||||||
|
end
|
||||||
|
|
||||||
-- connect with ME if a trigger flag is given
|
-- connect with ME if a trigger flag is given
|
||||||
if cfxZones.hasProperty(inZone, "f?") then
|
if cfxZones.hasProperty(inZone, "f?") then
|
||||||
theSpawner.triggerFlag = cfxZones.getStringFromZoneProperty(inZone, "f?", "none")
|
theSpawner.triggerFlag = cfxZones.getStringFromZoneProperty(inZone, "f?", "none")
|
||||||
@ -306,11 +314,12 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner)
|
|||||||
aSpawner = cfxSpawnZones.getSpawnerForZoneNamed(aName)
|
aSpawner = cfxSpawnZones.getSpawnerForZoneNamed(aName)
|
||||||
end
|
end
|
||||||
if not aSpawner then return end
|
if not aSpawner then return end
|
||||||
|
local theZone = aSpawner.zone -- retrieve the zone that defined me
|
||||||
|
|
||||||
-- will NOT check if conditions are met. This forces a spawn
|
-- will NOT check if conditions are met. This forces a spawn
|
||||||
local unitTypes = {} -- build type names
|
local unitTypes = {} -- build type names
|
||||||
--local p = aSpawner.zone.point
|
--local p = aSpawner.zone.point
|
||||||
local p = cfxZones.getPoint(aSpawner.zone) -- aSpawner.zone.point
|
local p = cfxZones.getPoint(theZone) -- aSpawner.zone.point
|
||||||
|
|
||||||
-- split the conf.troopsOnBoardTypes into an array of types
|
-- split the conf.troopsOnBoardTypes into an array of types
|
||||||
unitTypes = dcsCommon.splitString(aSpawner.types, ",")
|
unitTypes = dcsCommon.splitString(aSpawner.types, ",")
|
||||||
@ -366,6 +375,12 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- track this if we are have a trackwith attribute
|
||||||
|
-- note that we retrieve trackwith from ZONE, not spawner
|
||||||
|
if theZone.trackWith then
|
||||||
|
cfxSpawnZones.handoffTracking(theGroup, theZone)
|
||||||
|
end
|
||||||
|
|
||||||
-- callback to all who want to know
|
-- callback to all who want to know
|
||||||
cfxSpawnZones.invokeCallbacksFor("spawned", theGroup, aSpawner)
|
cfxSpawnZones.invokeCallbacksFor("spawned", theGroup, aSpawner)
|
||||||
|
|
||||||
@ -382,6 +397,39 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function cfxSpawnZones.handoffTracking(theGroup, theZone)
|
||||||
|
-- note that this method works on theZone, not Spawner object
|
||||||
|
if not groupTracker then
|
||||||
|
trigger.action.outText("+++spawner: <" .. theZone.name .. "> trackWith requires groupTracker module", 30)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local trackerName = theZone.trackWith
|
||||||
|
--if trackerName == "*" then trackerName = theZone.name end
|
||||||
|
-- now assemble a list of all trackers
|
||||||
|
if cfxSpawnZones.verbose or theZone.verbose then
|
||||||
|
trigger.action.outText("+++spawner: spawn pass-off: " .. trackerName, 30)
|
||||||
|
end
|
||||||
|
|
||||||
|
local trackerNames = {}
|
||||||
|
if dcsCommon.containsString(trackerName, ',') then
|
||||||
|
trackerNames = dcsCommon.splitString(trackerName, ',')
|
||||||
|
else
|
||||||
|
table.insert(trackerNames, trackerName)
|
||||||
|
end
|
||||||
|
for idx, aTrk in pairs(trackerNames) do
|
||||||
|
local theName = dcsCommon.trim(aTrk)
|
||||||
|
if theName == "*" then theName = theZone.name end
|
||||||
|
local theTracker = groupTracker.getTrackerByName(theName)
|
||||||
|
if not theTracker then
|
||||||
|
trigger.action.outText("+++spawner: <" .. theZone.name .. ">: cannot find tracker named <".. theName .. ">", 30)
|
||||||
|
else
|
||||||
|
groupTracker.addGroupToTracker(theGroup, theTracker)
|
||||||
|
if cfxSpawnZones.verbose or theZone.verbose then
|
||||||
|
trigger.action.outText("+++spawner: added " .. theGroup:getName() .. " to tracker " .. theName, 30)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- U P D A T E
|
-- U P D A T E
|
||||||
|
|||||||
@ -1627,6 +1627,7 @@ end
|
|||||||
function cfxZones.getZoneProperty(cZone, theKey)
|
function cfxZones.getZoneProperty(cZone, theKey)
|
||||||
if not cZone then
|
if not cZone then
|
||||||
trigger.action.outText("+++zone: no zone in getZoneProperty", 30)
|
trigger.action.outText("+++zone: no zone in getZoneProperty", 30)
|
||||||
|
-- breek.here.noew = 1
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if not theKey then
|
if not theKey then
|
||||||
|
|||||||
@ -1112,5 +1112,4 @@
|
|||||||
- AFAC
|
- AFAC
|
||||||
- FAC Assign group
|
- FAC Assign group
|
||||||
- set freq for unit
|
- set freq for unit
|
||||||
- embark / disembark
|
|
||||||
--]]--
|
--]]--
|
||||||
160
modules/delicates.lua
Normal file
160
modules/delicates.lua
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
delicates = {}
|
||||||
|
delicates.version = "0.0.0"
|
||||||
|
delicates.verbose = false
|
||||||
|
delicates.ups = 1
|
||||||
|
delicates.requiredLibs = {
|
||||||
|
"dcsCommon", -- always
|
||||||
|
"cfxZones", -- Zones, of course
|
||||||
|
}
|
||||||
|
delicates.theDelicates = {}
|
||||||
|
|
||||||
|
--[[--
|
||||||
|
Version History
|
||||||
|
|
||||||
|
--]]--
|
||||||
|
function delicates.adddDelicates(theZone)
|
||||||
|
table.insert(delicates.theDelicates, theZone)
|
||||||
|
end
|
||||||
|
|
||||||
|
function delicates.getDelicatesByName(aName)
|
||||||
|
for idx, aZone in pairs(delicates.theDelicates) do
|
||||||
|
if aName == aZone.name then return aZone end
|
||||||
|
end
|
||||||
|
if delicates.verbose then
|
||||||
|
trigger.action.outText("+++deli: no delicates with name <" .. aName ..">", 30)
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- read zone
|
||||||
|
--
|
||||||
|
function delicates.objectHandler(theObject, theCollector)
|
||||||
|
table.insert(theCollector, theObject)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function delicates.seeZoneInventory(theZone)
|
||||||
|
-- run a diag which objects are in the zone, and which cat they are
|
||||||
|
-- set up args
|
||||||
|
local allCats = {1, 2, 3, 4, 5, 6}
|
||||||
|
-- Object.Category UNIT=1, WEAPON=2, STATIC=3, BASE=4, SCENERY=5, Cargo=6
|
||||||
|
delicates.inventory = ""
|
||||||
|
theZone.inventory = {}
|
||||||
|
for idx, aCat in pairs(allCats) do
|
||||||
|
local p = cfxZones.getPoint(theZone)
|
||||||
|
local lp = {x = p.x, y = p.z}
|
||||||
|
p.y = land.getHeight(lp)
|
||||||
|
local collector = {}
|
||||||
|
|
||||||
|
-- now build the search argument
|
||||||
|
local args = {
|
||||||
|
id = world.VolumeType.SPHERE,
|
||||||
|
params = {
|
||||||
|
point = p,
|
||||||
|
radius = theZone.radius
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- now call search
|
||||||
|
world.searchObjects(aCat, args, delicates.objectHandler, collector)
|
||||||
|
-- process results
|
||||||
|
if #collector>0 then
|
||||||
|
trigger.action.outText("+++deli: zone " .. theZone.name, 30)
|
||||||
|
for idy, anObject in pairs(collector) do
|
||||||
|
local oName = anObject:getName()
|
||||||
|
if type(oName) == 'number' then oName = tostring(oName) end
|
||||||
|
trigger.action.outText("+++deli: cat=".. aCat .. ":<" .. anObject:getName() .. ">", 30)
|
||||||
|
local uP = anObject:getPoint()
|
||||||
|
if cfxZones.isPointInsideZone(uP, theZone) then
|
||||||
|
table.insert(theZone.inventory, oName)
|
||||||
|
else
|
||||||
|
trigger.action.outText("+++deli: (dropped)", 30)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function delicates.createDelicatesWithZone(theZone)
|
||||||
|
-- read objects for this zone
|
||||||
|
-- may want to filter by objects, can be passed in delicates
|
||||||
|
delicates.seeZoneInventory(theZone)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if delicates.verbose or theZone.verbose then
|
||||||
|
trigger.action.outText("+++deli: new delicates zone <".. theZone.name ..">", 30)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- event handler
|
||||||
|
--
|
||||||
|
function delicates:onEvent(theEvent)
|
||||||
|
trigger.action.outText("yup", 30)
|
||||||
|
if not theEvent then return end
|
||||||
|
if theEvent.id ~= 2 and theEvent.id ~= 23 then return end -- only hit and shooting start events
|
||||||
|
if not theEvent.target then return end
|
||||||
|
|
||||||
|
trigger.action.outText("+++deli: we hit " .. theEvent.target:getName(), 30)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Config & Start
|
||||||
|
--
|
||||||
|
function delicates.readConfigZone()
|
||||||
|
local theZone = cfxZones.getZoneByName("delicatesConfig")
|
||||||
|
if not theZone then
|
||||||
|
if delicates.verbose then
|
||||||
|
trigger.action.outText("+++deli: NO config zone!", 30)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
delicates.verbose = cfxZones.getBoolFromZoneProperty(theZone, "verbose", false)
|
||||||
|
|
||||||
|
if delicates.verbose then
|
||||||
|
trigger.action.outText("+++deli: read config", 30)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function delicates.start()
|
||||||
|
-- lib check
|
||||||
|
if not dcsCommon.libCheck then
|
||||||
|
trigger.action.outText("cfx delicates requires dcsCommon", 30)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if not dcsCommon.libCheck("cfx delicates", delicates.requiredLibs) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- read config
|
||||||
|
delicates.readConfigZone()
|
||||||
|
|
||||||
|
-- process delicates Zones
|
||||||
|
-- old style
|
||||||
|
local attrZones = cfxZones.getZonesWithAttributeNamed("delicates")
|
||||||
|
for k, aZone in pairs(attrZones) do
|
||||||
|
delicates.createDelicatesWithZone(aZone) -- process attributes
|
||||||
|
delicates.adddDelicates(aZone) -- add to list
|
||||||
|
end
|
||||||
|
|
||||||
|
-- start update
|
||||||
|
--delicates.update()
|
||||||
|
|
||||||
|
-- listen for events
|
||||||
|
world.addEventHandler(delicates)
|
||||||
|
|
||||||
|
trigger.action.outText("cfx delicates v" .. delicates.version .. " started.", 30)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- let's go!
|
||||||
|
if not delicates.start() then
|
||||||
|
trigger.action.outText("cfx delicates aborted: missing libraries", 30)
|
||||||
|
delicates = nil
|
||||||
|
end
|
||||||
BIN
tutorial & demo missions/demo - moving spawners II.miz
Normal file
BIN
tutorial & demo missions/demo - moving spawners II.miz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user