diff --git a/Doc/DML Documentation.pdf b/Doc/DML Documentation.pdf index 82a95c3..cd05cfd 100644 Binary files a/Doc/DML Documentation.pdf and b/Doc/DML Documentation.pdf differ diff --git a/Doc/DML Quick Reference.pdf b/Doc/DML Quick Reference.pdf index 4d03ae5..2d268cf 100644 Binary files a/Doc/DML Quick Reference.pdf and b/Doc/DML Quick Reference.pdf differ diff --git a/modules/cfxSpawnZones.lua b/modules/cfxSpawnZones.lua index e6b935e..255d2d3 100644 --- a/modules/cfxSpawnZones.lua +++ b/modules/cfxSpawnZones.lua @@ -1,5 +1,5 @@ cfxSpawnZones = {} -cfxSpawnZones.version = "1.5.3" +cfxSpawnZones.version = "1.6.0" cfxSpawnZones.requiredLibs = { "dcsCommon", -- common is of course needed for everything -- pretty stupid to check for this since we @@ -53,6 +53,7 @@ cfxSpawnZones.verbose = false -- - verbose -- 1.5.2 - activate?, pause? flag -- 1.5.3 - spawn?, spawnUnits? flags +-- 1.6.0 - trackwith interface for group tracker -- -- new version requires cfxGroundTroops, where they are -- @@ -135,6 +136,13 @@ function cfxSpawnZones.createSpawner(inZone) local theSpawner = {} theSpawner.zone = inZone 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:", "") + end + -- connect with ME if a trigger flag is given if cfxZones.hasProperty(inZone, "f?") then theSpawner.triggerFlag = cfxZones.getStringFromZoneProperty(inZone, "f?", "none") @@ -306,11 +314,12 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner) aSpawner = cfxSpawnZones.getSpawnerForZoneNamed(aName) 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 local unitTypes = {} -- build type names --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 unitTypes = dcsCommon.splitString(aSpawner.types, ",") @@ -366,6 +375,12 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner) 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 cfxSpawnZones.invokeCallbacksFor("spawned", theGroup, aSpawner) @@ -382,6 +397,39 @@ function cfxSpawnZones.spawnWithSpawner(aSpawner) 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 diff --git a/modules/cfxZones.lua b/modules/cfxZones.lua index 0a2b60c..9e5333a 100644 --- a/modules/cfxZones.lua +++ b/modules/cfxZones.lua @@ -1627,6 +1627,7 @@ end function cfxZones.getZoneProperty(cZone, theKey) if not cZone then trigger.action.outText("+++zone: no zone in getZoneProperty", 30) +-- breek.here.noew = 1 return nil end if not theKey then diff --git a/modules/cloneZone.lua b/modules/cloneZone.lua index 9cf33d6..f75db4b 100644 --- a/modules/cloneZone.lua +++ b/modules/cloneZone.lua @@ -1112,5 +1112,4 @@ - AFAC - FAC Assign group - set freq for unit - - embark / disembark --]]-- \ No newline at end of file diff --git a/modules/delicates.lua b/modules/delicates.lua new file mode 100644 index 0000000..d23abcc --- /dev/null +++ b/modules/delicates.lua @@ -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 \ No newline at end of file diff --git a/tutorial & demo missions/demo - moving spawners II.miz b/tutorial & demo missions/demo - moving spawners II.miz new file mode 100644 index 0000000..ff175b4 Binary files /dev/null and b/tutorial & demo missions/demo - moving spawners II.miz differ