Added callback interface

This commit is contained in:
Ciaran Fisher
2015-11-12 21:42:19 +00:00
parent f847f7c49d
commit 190c706a00
2 changed files with 64 additions and 11 deletions
+56 -3
View File
@@ -13,9 +13,7 @@
Contributors: Contributors:
- Steggles - https://github.com/Bob7heBuilder - Steggles - https://github.com/Bob7heBuilder
Version: 1.36 -01/11/2015 - Added ctld.loadTransport Mission Editor Function Version: 1.37 - 11/11/2015 - Added new callback interface
- Added ctld.countDroppedGroupsInZone(_zone, _blueFlag, _redFlag)
- Added ctld.countDroppedUnitsInZone(_zone, _blueFlag, _redFlag)
]] ]]
@@ -911,6 +909,12 @@ function ctld.loadTransport(_unitName)
end end
function ctld.addCallback(_callback)
table.insert(ctld.callbacks,_callback)
end
-- *************************************************************** -- ***************************************************************
-- **************** BE CAREFUL BELOW HERE ************************ -- **************** BE CAREFUL BELOW HERE ************************
-- *************************************************************** -- ***************************************************************
@@ -1250,6 +1254,9 @@ function ctld.deployTroops(_heli, _troops)
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " troops dropped from " .. _heli:getTypeName() .. " into combat", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " troops dropped from " .. _heli:getTypeName() .. " into combat", 10)
end end
ctld.processCallback({unit = _heli, unloaded = _droppedTroops, action = "dropped_troops"})
else else
--extract zone! --extract zone!
local _droppedCount = trigger.misc.getUserFlag(_extractZone.flag) local _droppedCount = trigger.misc.getUserFlag(_extractZone.flag)
@@ -1260,6 +1267,7 @@ function ctld.deployTroops(_heli, _troops)
ctld.inTransitTroops[_heli:getName()].troops = nil ctld.inTransitTroops[_heli:getName()].troops = nil
if ctld.inAir(_heli) then if ctld.inAir(_heli) then
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " troops fast-ropped from " .. _heli:getTypeName() .. " into " .. _extractZone.name, 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " troops fast-ropped from " .. _heli:getTypeName() .. " into " .. _extractZone.name, 10)
else else
@@ -1287,6 +1295,8 @@ function ctld.deployTroops(_heli, _troops)
ctld.inTransitTroops[_heli:getName()].vehicles = nil ctld.inTransitTroops[_heli:getName()].vehicles = nil
ctld.processCallback({unit = _heli, unloaded = _droppedVehicles, action = "dropped_vehicles"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " dropped vehicles from " .. _heli:getTypeName() .. " into combat", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " dropped vehicles from " .. _heli:getTypeName() .. " into combat", 10)
end end
end end
@@ -1369,12 +1379,15 @@ function ctld.loadTroops(_heli, _troops, _number)
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " loaded " .. _number .. " troops into " .. _heli:getTypeName(), 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " loaded " .. _number .. " troops into " .. _heli:getTypeName(), 10)
ctld.processCallback({unit = _heli, onboard = _onboard.troops, action = "load_troops"})
else else
_onboard.vehicles = ctld.generateVehiclesForTransport(_heli:getCoalition(), _heli:getCountry()) _onboard.vehicles = ctld.generateVehiclesForTransport(_heli:getCoalition(), _heli:getCountry())
local _count = #_list local _count = #_list
ctld.processCallback({unit = _heli, onboard = _onboard.vehicles, action = "load_vehicles"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " loaded " .. _count .. " vehicles into " .. _heli:getTypeName(), 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " loaded " .. _count .. " vehicles into " .. _heli:getTypeName(), 10)
end end
@@ -1557,10 +1570,16 @@ function ctld.loadUnloadTroops(_args)
if _troops then if _troops then
ctld.displayMessageToGroup(_heli, "Dropped troops back to base", 20) ctld.displayMessageToGroup(_heli, "Dropped troops back to base", 20)
ctld.processCallback({unit = _heli, unloaded = ctld.inTransitTroops[_heli:getName()].troops, action = "unload_troops_zone"})
ctld.inTransitTroops[_heli:getName()].troops = nil ctld.inTransitTroops[_heli:getName()].troops = nil
else else
ctld.displayMessageToGroup(_heli, "Dropped vehicles back to base", 20) ctld.displayMessageToGroup(_heli, "Dropped vehicles back to base", 20)
ctld.processCallback({unit = _heli, unloaded = ctld.inTransitTroops[_heli:getName()].vehicles, action = "unload_vehicles_zone"})
ctld.inTransitTroops[_heli:getName()].vehicles = nil ctld.inTransitTroops[_heli:getName()].vehicles = nil
end end
@@ -1611,6 +1630,8 @@ function ctld.extractTroops(_heli, _troops)
ctld.droppedTroopsBLUE[_extractTroops.group:getName()] = nil ctld.droppedTroopsBLUE[_extractTroops.group:getName()] = nil
end end
ctld.processCallback({unit = _heli, extracted = _extractTroops, action = "extract_troops"})
--remove --remove
_extractTroops.group:destroy() _extractTroops.group:destroy()
@@ -1646,6 +1667,7 @@ function ctld.extractTroops(_heli, _troops)
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " extracted vehicles in " .. _heli:getTypeName() .. " from combat", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " extracted vehicles in " .. _heli:getTypeName() .. " from combat", 10)
ctld.processCallback({unit = _heli, extracted = _extractVehicles, action = "extract_vehicles"})
--remove --remove
_extractVehicles.group:destroy() _extractVehicles.group:destroy()
_extracted = true _extracted = true
@@ -2199,6 +2221,8 @@ function ctld.unpackCrates(_arguments)
ctld.spawnedCratesBLUE[_crateName] = nil ctld.spawnedCratesBLUE[_crateName] = nil
end end
ctld.processCallback({unit = _heli, crate = _crate , spawnedGroup = _spawnedGroups, action = "unpack"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully deployed " .. _crate.details.desc .. " to the field", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully deployed " .. _crate.details.desc .. " to the field", 10)
if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then
@@ -2301,6 +2325,8 @@ function ctld.unpackFOBCrates(_crates, _heli)
local _txt = string.format("%s started building FOB using %d FOB crates, it will be finished in %d seconds.\nPosition marked with smoke.", ctld.getPlayerNameOrType(_heli), #_nearbyMultiCrates, ctld.buildTimeFOB) local _txt = string.format("%s started building FOB using %d FOB crates, it will be finished in %d seconds.\nPosition marked with smoke.", ctld.getPlayerNameOrType(_heli), #_nearbyMultiCrates, ctld.buildTimeFOB)
ctld.processCallback({unit = _heli, position = _centroid, action = "fob"})
trigger.action.smoke(_centroid, trigger.smokeColor.Green) trigger.action.smoke(_centroid, trigger.smokeColor.Green)
trigger.action.outTextForCoalition(_heli:getCoalition(), _txt, 10) trigger.action.outTextForCoalition(_heli:getCoalition(), _txt, 10)
@@ -2767,6 +2793,8 @@ function ctld.rearmAASystem(_heli, _nearestCrate, _nearbyCrates,_type)
ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type) ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type)
ctld.processCallback({unit = _heli, crate = _nearestCrate , spawnedGroup = _spawnedGroup, action = "rearm"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully rearmed a full "..string.upper(_type).." AA System in the field", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully rearmed a full "..string.upper(_type).." AA System in the field", 10)
if _heli:getCoalition() == 1 then if _heli:getCoalition() == 1 then
@@ -2956,6 +2984,8 @@ function ctld.unpackAASystem(_heli, _nearestCrate, _nearbyCrates,_type)
ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type) ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type)
ctld.processCallback({unit = _heli, crate = _nearestCrate , spawnedGroup = _spawnedGroup, action = "unpack"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully deployed a full "..string.upper(_type).." AA System to the field", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully deployed a full "..string.upper(_type).." AA System to the field", 10)
end end
@@ -2989,6 +3019,8 @@ function ctld.repairAASystem(_heli, _nearestCrate,_type)
ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type) ctld.completeAASystems[_spawnedGroup:getName()] = ctld.getAASystemDetails(_spawnedGroup,_type)
ctld.processCallback({unit = _heli, crate = _nearestCrate , spawnedGroup = _spawnedGroup, action = "repair"})
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully repaired a full "..string.upper(_type).." AA System in the field", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " successfully repaired a full "..string.upper(_type).." AA System in the field", 10)
if _heli:getCoalition() == 1 then if _heli:getCoalition() == 1 then
@@ -3075,6 +3107,8 @@ function ctld.unpackMultiCrate(_heli, _nearestCrate, _nearbyCrates)
local _spawnedGroup = ctld.spawnCrateGroup(_heli, { _point }, { _nearestCrate.details.unit }) local _spawnedGroup = ctld.spawnCrateGroup(_heli, { _point }, { _nearestCrate.details.unit })
ctld.processCallback({unit = _heli, crate = _nearestCrate , spawnedGroup = _spawnedGroup, action = "unpack"})
local _txt = string.format("%s successfully deployed %s to the field using %d crates", ctld.getPlayerNameOrType(_heli), _nearestCrate.details.desc, #_nearbyMultiCrates) local _txt = string.format("%s successfully deployed %s to the field using %d crates", ctld.getPlayerNameOrType(_heli), _nearestCrate.details.desc, #_nearbyMultiCrates)
trigger.action.outTextForCoalition(_heli:getCoalition(), _txt, 10) trigger.action.outTextForCoalition(_heli:getCoalition(), _txt, 10)
@@ -3636,6 +3670,22 @@ function ctld.updateZoneCounter(_index, _diff)
end end
end end
function ctld.processCallback(_callbackArgs)
for _, _callback in pairs(ctld.callbacks) do
local _status, _result = pcall(function()
_callback(_callbackArgs)
end)
if (not _status) then
env.error(string.format("CTLD Callback Error: %s", _result))
end
end
end
-- checks the status of all AI troop carriers and auto loads and unloads troops -- checks the status of all AI troop carriers and auto loads and unloads troops
-- as long as the troops are on the ground -- as long as the troops are on the ground
@@ -4709,6 +4759,9 @@ ctld.extractZones = {} -- stored extract zones
ctld.missionEditorCargoCrates = {} --crates added by mission editor for triggering cratesinzone ctld.missionEditorCargoCrates = {} --crates added by mission editor for triggering cratesinzone
ctld.hoverStatus = {} -- tracks status of a helis hover above a crate ctld.hoverStatus = {} -- tracks status of a helis hover above a crate
ctld.callbacks = {} -- function callback
-- Remove intransit troops when heli / cargo plane dies -- Remove intransit troops when heli / cargo plane dies
--ctld.eventHandler = {} --ctld.eventHandler = {}
--function ctld.eventHandler:onEvent(_event) --function ctld.eventHandler:onEvent(_event)
BIN
View File
Binary file not shown.