15 Commits

Author SHA1 Message Date
Ciaran Fisher
55170e1ae3 Merge pull request #37 from dimpah/JTAC_LS
1.71 JTAC Laser/Smoke mod
2018-04-15 15:53:31 +01:00
Ciaran Fisher
844144f695 Added minimum distance from friendly logistics option 2018-04-15 15:51:44 +01:00
Ciaran Fisher
f12c67c5e0 Bug Fix
Bug fix for crate timing out
2018-02-18 17:16:40 +00:00
dimpah
b45d6a9ce3 1.71 JTAC Laser/Smoke mod
*Adds a new menu item under F10 menu named "JTAC command" when a JTAC is created. From there you can order them to change lasing codes and smoke color.
*Fixed a bug that script prevent you spawn new crates after a period of time (configured by "crateWaitTime" variable)
2018-02-05 13:56:30 +02:00
Ciaran Fisher
b5436bd6d2 Update 1.71 2018-01-18 21:54:27 +00:00
Ciaran Fisher
a10de260c7 Merge pull request #36 from ciribob/crateMove
Merge pull request #35 from ciribob/master
2018-01-18 21:50:48 +00:00
Ciaran Fisher
4d3ae4b5ee Update missions 2018-01-18 21:49:40 +00:00
Ciaran Fisher
f6efa0ec58 Merge pull request #34 from ciribob/jtac-optimisation
JTAC Target Optimisation
2018-01-18 21:47:12 +00:00
Ciaran Fisher
5452bc7539 Merge pull request #35 from ciribob/master
Merge pull request #33 from ciribob/crateMove
2018-01-18 21:47:03 +00:00
Ciaran Fisher
58acfbc152 JTAC Target Optimisation
Possible Fixes for JTAC priority
JTAC search optimised for high unit missions
Added JTAC "visual on" report
2018-01-18 21:45:13 +00:00
Ciaran Fisher
2a4c9ed91a Merge pull request #33 from ciribob/crateMove
Added force crate to be moved
2018-01-18 20:42:16 +00:00
Ciaran Fisher
a78dd40688 Added force crate to be moved
Added Wait time for requesting crates

Added per unit type optional group limits

Added per unit type allowable actions
2017-07-24 21:06:53 +01:00
Ciaran Fisher
44ff4d61da Version 2017-06-25 21:06:51 +01:00
Ciaran Fisher
196efb7bcb Added ability to set maximum group size
You can now set the maximum group size that'll fit in a helicopter.
Larger groups cant be picked up
2017-06-25 21:03:33 +01:00
Ciaran Fisher
38128b65c0 Release 1.64
Fixed bug where count in zone wouldn't work for Mission editor added
crates
Delayed config by a second so you can easily override options without
editing the file
2016-12-11 09:09:20 +00:00
8 changed files with 527 additions and 166 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.iml
.idea/encodings.xml
*.xml

684
CTLD.lua
View File

@@ -16,9 +16,15 @@
- jmontleon - https://github.com/jmontleon - jmontleon - https://github.com/jmontleon
- emilianomolina - https://github.com/emilianomolina - emilianomolina - https://github.com/emilianomolina
Version: 1.63 - 07/12/2016 Version: 1.72 - 18/02/2018
- Bug fix for crate spam
- Improved JTAC Performance - priority & targeting
- Added JTAC report for in view
- Added ability to set maximum group size that can be carried
- Added new sling load crates - Added new sling load crates
- Fixed bug where crates and / or groups would disappear - Fixed bug where crates and / or groups would disappear
- Fixed bug where count in zone wouldn't work for mission crates
- Delayed config of F10 menu and other scheduled functions so they can be overwritten by mission if a user wants
]] ]]
ctld = {} -- DONT REMOVE! ctld = {} -- DONT REMOVE!
@@ -46,7 +52,10 @@ ctld.maximumDistanceLogistic = 200 -- max distance from vehicle to logistics to
ctld.maximumSearchDistance = 4000 -- max distance for troops to search for enemy ctld.maximumSearchDistance = 4000 -- max distance for troops to search for enemy
ctld.maximumMoveDistance = 2000 -- max distance for troops to move from drop point if no enemy is nearby ctld.maximumMoveDistance = 2000 -- max distance for troops to move from drop point if no enemy is nearby
ctld.minimumDeployDistance = 1000 -- minimum distance from a friendly pickup zone where you can deploy a crate
ctld.numberOfTroops = 10 -- default number of troops to load on a transport heli or C-130 ctld.numberOfTroops = 10 -- default number of troops to load on a transport heli or C-130
-- also works as maximum size of group that'll fit into a helicopter unless overridden
ctld.enableFastRopeInsertion = true -- allows you to drop troops by fast rope ctld.enableFastRopeInsertion = true -- allows you to drop troops by fast rope
ctld.fastRopeMaximumHeight = 18.28 -- in meters which is 60 ft max fast rope (not rappell) safe height ctld.fastRopeMaximumHeight = 18.28 -- in meters which is 60 ft max fast rope (not rappell) safe height
@@ -72,6 +81,10 @@ ctld.troopPickupAtFOB = true -- if true, troops can also be picked up at a creat
ctld.buildTimeFOB = 120 --time in seconds for the FOB to be built ctld.buildTimeFOB = 120 --time in seconds for the FOB to be built
ctld.crateWaitTime = 120 -- time in seconds to wait before you can spawn another crate
ctld.forceCrateToBeMoved = true -- a crate must be picked up at least once and moved before it can be unpacked. Helps to reduce crate spam
ctld.radioSound = "beacon.ogg" -- the name of the sound file to use for the FOB radio beacons. If this isnt added to the mission BEACONS WONT WORK! ctld.radioSound = "beacon.ogg" -- the name of the sound file to use for the FOB radio beacons. If this isnt added to the mission BEACONS WONT WORK!
ctld.radioSoundFC3 = "beaconsilent.ogg" -- name of the second silent radio file, used so FC3 aircraft dont hear ALL the beacon noises... :) ctld.radioSoundFC3 = "beaconsilent.ogg" -- name of the second silent radio file, used so FC3 aircraft dont hear ALL the beacon noises... :)
@@ -104,6 +117,9 @@ ctld.AASystemLimitBLUE = 20 -- Blue side limit
--END AA SYSTEM CONFIG -- --END AA SYSTEM CONFIG --
-- ***************** JTAC CONFIGURATION ***************** -- ***************** JTAC CONFIGURATION *****************
ctld.laser_codes = { 1113, 1688, 1322} -- Put here the available laser codes. The first value is the default for RED and the second for BLUE
ctld.deployedJTACs = {} --Store deployed JTAC units here
ctld.JTACCommandMenuPath = {}
ctld.JTAC_LIMIT_RED = 10 -- max number of JTAC Crates for the RED Side ctld.JTAC_LIMIT_RED = 10 -- max number of JTAC Crates for the RED Side
ctld.JTAC_LIMIT_BLUE = 10 -- max number of JTAC Crates for the BLUE Side ctld.JTAC_LIMIT_BLUE = 10 -- max number of JTAC Crates for the BLUE Side
@@ -117,6 +133,7 @@ ctld.JTAC_smokeOn_BLUE = true -- enables marking of target with smoke for BLUE f
ctld.JTAC_smokeColour_RED = 4 -- RED side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4 ctld.JTAC_smokeColour_RED = 4 -- RED side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4
ctld.JTAC_smokeColour_BLUE = 1 -- BLUE side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4 ctld.JTAC_smokeColour_BLUE = 1 -- BLUE side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4
ctld.JTAC_smokeColous = {"Green", "Red", "White", "Orange", "Blue", "No smoke"}
ctld.JTAC_jtacStatusF10 = true -- enables F10 JTAC Status menu ctld.JTAC_jtacStatusF10 = true -- enables F10 JTAC Status menu
@@ -387,6 +404,49 @@ ctld.vehicleTransportEnabled = {
"C-130", "C-130",
} }
-- ************** Maximum Units SETUP for UNITS ******************
-- Put the name of the Unit you want to limit group sizes too
-- i.e
-- ["UH-1H"] = 10,
--
-- Will limit UH1 to only transport groups with a size 10 or less
-- Make sure the unit name is exactly right or it wont work
ctld.unitLoadLimits = {
-- Remove the -- below to turn on options
-- ["SA342Mistral"] = 4,
-- ["SA342L"] = 4,
-- ["SA342M"] = 4,
}
-- ************** Allowable actions for UNIT TYPES ******************
-- Put the name of the Unit you want to limit actions for
-- NOTE - the unit must've been listed in the transportPilotNames list above
-- This can be used in conjunction with the options above for group sizes
-- By default you can load both crates and troops unless overriden below
-- i.e
-- ["UH-1H"] = {crates=true, troops=false},
--
-- Will limit UH1 to only transport CRATES but NOT TROOPS
--
-- ["SA342Mistral"] = {crates=fales, troops=true},
-- Will allow Mistral Gazelle to only transport crates, not troops
ctld.unitActions = {
-- Remove the -- below to turn on options
-- ["SA342Mistral"] = {crates=true, troops=true},
-- ["SA342L"] = {crates=false, troops=true},
-- ["SA342M"] = {crates=false, troops=true},
}
-- ************** INFANTRY GROUPS FOR PICKUP ****************** -- ************** INFANTRY GROUPS FOR PICKUP ******************
-- Unit Types -- Unit Types
-- inf is normal infantry -- inf is normal infantry
@@ -1273,6 +1333,9 @@ ctld.AASystemTemplate = {
} }
ctld.crateWait = {}
ctld.crateMove = {}
---------------- INTERNAL FUNCTIONS ---------------- ---------------- INTERNAL FUNCTIONS ----------------
function ctld.getTransportUnit(_unitName) function ctld.getTransportUnit(_unitName)
@@ -1526,8 +1589,17 @@ function ctld.spawnCrate(_arguments)
local _position = _heli:getPosition() local _position = _heli:getPosition()
-- check crate spam
if _heli:getPlayerName() ~= nil and ctld.crateWait[_heli:getPlayerName()] and ctld.crateWait[_heli:getPlayerName()] > timer.getTime() then
-- trigger.action.outText("Spawn Crate".._args[1].." ".._args[2],10) ctld.displayMessageToGroup(_heli,"Sorry you must wait "..(ctld.crateWait[_heli:getPlayerName()] - timer.getTime()).. " seconds before you can get another crate", 20)
return
end
if _heli:getPlayerName() ~= nil then
ctld.crateWait[_heli:getPlayerName()] = timer.getTime() + ctld.crateWaitTime
end
-- trigger.action.outText("Spawn Crate".._args[1].." ".._args[2],10)
local _heli = ctld.getTransportUnit(_args[1]) local _heli = ctld.getTransportUnit(_args[1])
@@ -1541,6 +1613,9 @@ function ctld.spawnCrate(_arguments)
local _spawnedCrate = ctld.spawnCrateStatic(_heli:getCountry(), _unitId, _point, _name, _crateType.weight,_side) local _spawnedCrate = ctld.spawnCrateStatic(_heli:getCountry(), _unitId, _point, _name, _crateType.weight,_side)
-- add to move table
ctld.crateMove[_name] = _name
ctld.displayMessageToGroup(_heli, string.format("A %s crate weighing %s kg has been brought out and is at your 12 o'clock ", _crateType.desc, _crateType.weight), 20) ctld.displayMessageToGroup(_heli, string.format("A %s crate weighing %s kg has been brought out and is at your 12 o'clock ", _crateType.desc, _crateType.weight), 20)
else else
@@ -2177,8 +2252,21 @@ function ctld.extractTroops(_args)
_extractTroops = ctld.findNearestGroup(_heli, ctld.droppedTroopsBLUE) _extractTroops = ctld.findNearestGroup(_heli, ctld.droppedTroopsBLUE)
end end
if _extractTroops ~= nil then if _extractTroops ~= nil then
local _limit = ctld.getTransportLimit(_heli:getTypeName())
local _size = #_extractTroops.group:getUnits()
if _limit < #_extractTroops.group:getUnits() then
ctld.displayMessageToGroup(_heli, "Sorry - The group of ".._size.." is too large to fit. \n\nLimit is ".._limit.." for ".._heli:getTypeName(), 20)
return
end
_onboard.troops = _extractTroops.details _onboard.troops = _extractTroops.details
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " extracted troops in " .. _heli:getTypeName() .. " from combat", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " extracted troops in " .. _heli:getTypeName() .. " from combat", 10)
@@ -2355,6 +2443,9 @@ function ctld.checkHoverStatus()
ctld.hoverStatus[_transUnit:getName()] = nil ctld.hoverStatus[_transUnit:getName()] = nil
ctld.displayMessageToGroup(_transUnit, "Loaded " .. _crate.details.desc .. " crate!", 10,true) ctld.displayMessageToGroup(_transUnit, "Loaded " .. _crate.details.desc .. " crate!", 10,true)
--crates been moved once!
ctld.crateMove[_crate.crateUnit:getName()] = nil
if _transUnit:getCoalition() == 1 then if _transUnit:getCoalition() == 1 then
ctld.spawnedCratesRED[_crate.crateUnit:getName()] = nil ctld.spawnedCratesRED[_crate.crateUnit:getName()] = nil
else else
@@ -2415,6 +2506,8 @@ function ctld.loadNearbyCrate(_name)
ctld.spawnedCratesBLUE[_crate.crateUnit:getName()] = nil ctld.spawnedCratesBLUE[_crate.crateUnit:getName()] = nil
end end
ctld.crateMove[_crate.crateUnit:getName()] = nil
_crate.crateUnit:destroy() _crate.crateUnit:destroy()
local _copiedCrate = mist.utils.deepCopy(_crate.details) local _copiedCrate = mist.utils.deepCopy(_crate.details)
@@ -2801,6 +2894,16 @@ function ctld.unpackCrates(_arguments)
local _crates = ctld.getCratesAndDistance(_heli) local _crates = ctld.getCratesAndDistance(_heli)
local _crate = ctld.getClosestCrate(_heli, _crates) local _crate = ctld.getClosestCrate(_heli, _crates)
if ctld.inLogisticsZone(_heli) == true or ctld.farEnoughFromLogisticZone(_heli) == true then
ctld.displayMessageToGroup(_heli, "You can't unpack that here! Take it to where it's needed!", 20)
return
end
if _crate ~= nil and _crate.dist < 750 if _crate ~= nil and _crate.dist < 750
and (_crate.details.unit == "FOB" or _crate.details.unit == "FOB-SMALL") then and (_crate.details.unit == "FOB" or _crate.details.unit == "FOB-SMALL") then
@@ -2810,13 +2913,12 @@ function ctld.unpackCrates(_arguments)
elseif _crate ~= nil and _crate.dist < 200 then elseif _crate ~= nil and _crate.dist < 200 then
if ctld.inLogisticsZone(_heli) == true then if ctld.forceCrateToBeMoved and ctld.crateMove[_crate.crateUnit:getName()] then
ctld.displayMessageToGroup(_heli,"Sorry you must move this crate before you unpack it!", 20)
ctld.displayMessageToGroup(_heli, "You can't unpack that here! Take it to where it's needed!", 20)
return return
end end
local _aaTemplate = ctld.getAATemplate(_crate.details.unit) local _aaTemplate = ctld.getAATemplate(_crate.details.unit)
if _aaTemplate then if _aaTemplate then
@@ -2869,11 +2971,10 @@ function ctld.unpackCrates(_arguments)
if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then
local _code = table.remove(ctld.jtacGeneratedLaserCodes, 1) local _side = _heli:getCoalition()
--put to the end local _code = ctld.jtacGetLaserCodeBySide(_side)
table.insert(ctld.jtacGeneratedLaserCodes, _code)
ctld.JTACAutoLase(_spawnedGroups:getName(), _code) --(_jtacGroupName, _laserCode, _smoke, _lock, _colour) ctld.CreateJTAC(_spawnedGroups:getName(), _code)
end end
end end
@@ -4292,6 +4393,36 @@ function ctld.inLogisticsZone(_heli)
return false return false
end end
-- are far enough from a friendly logistics zone
function ctld.farEnoughFromLogisticZone(_heli)
if ctld.inAir(_heli) then
return false
end
local _heliPoint = _heli:getPoint()
local _farEnough = true
for _, _name in pairs(ctld.logisticUnits) do
local _logistic = StaticObject.getByName(_name)
if _logistic ~= nil and _logistic:getCoalition() == _heli:getCoalition() then
--get distance
local _dist = ctld.getDistance(_heliPoint, _logistic:getPoint())
if _dist <= ctld.minimumDeployDistance then
_farEnough = false
end
end
end
return _farEnough
end
function ctld.refreshSmoke() function ctld.refreshSmoke()
if ctld.disableAllSmoke == true then if ctld.disableAllSmoke == true then
@@ -4509,6 +4640,26 @@ function ctld.checkAIStatus()
end end
function ctld.getTransportLimit(_unitType)
if ctld.unitLoadLimits[_unitType] then
return ctld.unitLoadLimits[_unitType]
end
return ctld.numberOfTroops
end
function ctld.getUnitActions(_unitType)
if ctld.unitActions[_unitType] then
return ctld.unitActions[_unitType]
end
return {crates=true,troops=true}
end
-- Adds menuitem to all heli units that are active -- Adds menuitem to all heli units that are active
function ctld.addF10MenuOptions() function ctld.addF10MenuOptions()
@@ -4532,35 +4683,46 @@ function ctld.addF10MenuOptions()
local _rootPath = missionCommands.addSubMenuForGroup(_groupId, "CTLD") local _rootPath = missionCommands.addSubMenuForGroup(_groupId, "CTLD")
local _troopCommandsPath = missionCommands.addSubMenuForGroup(_groupId, "Troop Transport", _rootPath) local _unitActions = ctld.getUnitActions(_unit:getTypeName())
missionCommands.addCommandForGroup(_groupId, "Unload / Extract Troops", _troopCommandsPath, ctld.unloadExtractTroops, { _unitName })
missionCommands.addCommandForGroup(_groupId, "Check Cargo", _troopCommandsPath, ctld.checkTroopStatus, { _unitName }) if _unitActions.troops then
-- local _loadPath = missionCommands.addSubMenuForGroup(_groupId, "Load From Zone", _troopCommandsPath) local _troopCommandsPath = missionCommands.addSubMenuForGroup(_groupId, "Troop Transport", _rootPath)
for _,_loadGroup in pairs(ctld.loadableGroups) do
if not _loadGroup.side or _loadGroup.side == _unit:getCoalition() then missionCommands.addCommandForGroup(_groupId, "Unload / Extract Troops", _troopCommandsPath, ctld.unloadExtractTroops, { _unitName })
missionCommands.addCommandForGroup(_groupId, "Load ".._loadGroup.name, _troopCommandsPath, ctld.loadTroopsFromZone, { _unitName, true,_loadGroup,false })
missionCommands.addCommandForGroup(_groupId, "Check Cargo", _troopCommandsPath, ctld.checkTroopStatus, { _unitName })
-- local _loadPath = missionCommands.addSubMenuForGroup(_groupId, "Load From Zone", _troopCommandsPath)
for _,_loadGroup in pairs(ctld.loadableGroups) do
if not _loadGroup.side or _loadGroup.side == _unit:getCoalition() then
-- check size & unit
if ctld.getTransportLimit(_unit:getTypeName()) >= _loadGroup.total then
missionCommands.addCommandForGroup(_groupId, "Load ".._loadGroup.name, _troopCommandsPath, ctld.loadTroopsFromZone, { _unitName, true,_loadGroup,false })
end
end
end end
end
if ctld.unitCanCarryVehicles(_unit) then if ctld.unitCanCarryVehicles(_unit) then
local _vehicleCommandsPath = missionCommands.addSubMenuForGroup(_groupId, "Vehicle / FOB Transport", _rootPath) local _vehicleCommandsPath = missionCommands.addSubMenuForGroup(_groupId, "Vehicle / FOB Transport", _rootPath)
missionCommands.addCommandForGroup(_groupId, "Unload Vehicles", _vehicleCommandsPath, ctld.unloadTroops, { _unitName, false }) missionCommands.addCommandForGroup(_groupId, "Unload Vehicles", _vehicleCommandsPath, ctld.unloadTroops, { _unitName, false })
missionCommands.addCommandForGroup(_groupId, "Load / Extract Vehicles", _vehicleCommandsPath, ctld.loadTroopsFromZone, { _unitName, false,"",true }) missionCommands.addCommandForGroup(_groupId, "Load / Extract Vehicles", _vehicleCommandsPath, ctld.loadTroopsFromZone, { _unitName, false,"",true })
if ctld.enabledFOBBuilding and ctld.staticBugWorkaround == false then if ctld.enabledFOBBuilding and ctld.staticBugWorkaround == false then
missionCommands.addCommandForGroup(_groupId, "Load / Unload FOB Crate", _vehicleCommandsPath, ctld.loadUnloadFOBCrate, { _unitName, false }) missionCommands.addCommandForGroup(_groupId, "Load / Unload FOB Crate", _vehicleCommandsPath, ctld.loadUnloadFOBCrate, { _unitName, false })
end
missionCommands.addCommandForGroup(_groupId, "Check Cargo", _vehicleCommandsPath, ctld.checkTroopStatus, { _unitName })
end end
missionCommands.addCommandForGroup(_groupId, "Check Cargo", _vehicleCommandsPath, ctld.checkTroopStatus, { _unitName })
end end
if ctld.enableCrates then if ctld.enableCrates and _unitActions.crates then
if ctld.unitCanCarryVehicles(_unit) == false then if ctld.unitCanCarryVehicles(_unit) == false then
@@ -4590,7 +4752,8 @@ function ctld.addF10MenuOptions()
end end
end end
if ctld.enabledFOBBuilding or ctld.enableCrates then if (ctld.enabledFOBBuilding or ctld.enableCrates) and _unitActions.crates then
local _crateCommands = missionCommands.addSubMenuForGroup(_groupId, "CTLD Commands", _rootPath) local _crateCommands = missionCommands.addSubMenuForGroup(_groupId, "CTLD Commands", _rootPath)
if ctld.hoverPickup == false then if ctld.hoverPickup == false then
if ctld.slingLoad == false then if ctld.slingLoad == false then
@@ -4757,7 +4920,120 @@ ctld.jtacCurrentTargets = {}
ctld.jtacRadioAdded = {} --keeps track of who's had the radio command added ctld.jtacRadioAdded = {} --keeps track of who's had the radio command added
ctld.jtacGeneratedLaserCodes = {} -- keeps track of generated codes, cycles when they run out ctld.jtacGeneratedLaserCodes = {} -- keeps track of generated codes, cycles when they run out
ctld.jtacLaserPointCodes = {} ctld.jtacLaserPointCodes = {}
ctld.jtacColor = {}
function ctld.CreateJTAC(group, code)
local _side = ctld.getGroup(group)[1]:getCoalition()
ctld.jtacLaserPointCodes[group] = code
if _side == 1 then
ctld.jtacColor[group] = ctld.JTAC_smokeColour_RED
else
ctld.jtacColor[group] = ctld.JTAC_smokeColour_BLUE
end
ctld.JTACAutoLase(group, code)
if ctld.deployedJTACs[_side] == nil then
ctld.deployedJTACs[_side] = {}
end
table.insert(ctld.deployedJTACs[_side], group)
ctld.refreshJTACMenu(_side)
end
function ctld.changeLaserCode(_args)
local _SelectedLazingCode = tonumber(_args[2])
if tonumber(ctld.jtacLaserPointCodes[_args[1]]) ~= _SelectedLazingCode then
--TODO: check unit's life
ctld.JTACAutoLaseStop(_args[1])
local _smoke
if _args[3] == 1 then
_smoke = ctld.JTAC_smokeOn_RED
else
_smoke = ctld.JTAC_smokeOn_BLUE
end
timer.scheduleFunction(ctld.timerJTACAutoLase, { _args[1], _SelectedLazingCode, _smoke, ctld.JTAC_lock, ctld.jtacColor[_args[1]]}, timer.getTime() + 5) --TODO: check interval
ctld.notifyCoalition(_args[1]..": Changing laser code to ".. _SelectedLazingCode, 10, _args[3])
ctld.jtacLaserPointCodes[_args[1]] = _SelectedLazingCode
else
ctld.notifyCoalition(_args[1]..": I'm already lazing with code ".. _SelectedLazingCode, 10, _args[3])
end
end
function ctld.changeJTACColor(_args)
if ctld.GetColorName(ctld.jtacColor[_args[1]]) ~= _args[2] then
ctld.JTACAutoLaseStop(_args[1])
local _smoke
if _args[3] == 1 then
_smoke = ctld.JTAC_smokeOn_RED
else
_smoke = ctld.JTAC_smokeOn_BLUE
end
local _Color = -1 -- no smoke?
if _args[2] == "Green" then
_Color = 0
elseif _args[2] == "Red" then
_Color = 1
elseif _args[2] == "White" then
_Color = 2
elseif _args[2] == "Orange" then
_Color = 3
elseif _args[2] == "Blue" then
_Color = 4
end
timer.scheduleFunction(ctld.timerJTACAutoLase, { _args[1], ctld.jtacLaserPointCodes[_args[1]], _smoke, ctld.JTAC_lock, _Color }, timer.getTime() + 5) --TODO: check interval
ctld.notifyCoalition(_args[1]..": Changing color to ".._args[2], 10, _args[3])
ctld.jtacColor[_args[1]] = _Color
else
ctld.notifyCoalition(_args[1]..": Smoke color is already ".._args[2]..".", 10, _args[3])
end
end
function ctld.refreshJTACMenu(_side)
if ctld.JTACCommandMenuPath[tostring(_side)] ~= nil then
missionCommands.removeItemForCoalition(_side, ctld.JTACCommandMenuPath[tostring(_side)])
end
local _JTACMenu
if next(ctld.deployedJTACs[_side]) ~= nil then
_JTACMenu = missionCommands.addSubMenuForCoalition(_side, "JTAC Command", nil)
else
return
end
ctld.JTACCommandMenuPath[tostring(_side)] = _JTACMenu
local itemNo = 0
--Add one menu item foreach deployed JTAC unit?
local _JTACMenuItem = {}
local _JTACMenuItemLaser = {}
local _JTACMenuItemColor = {}
for _, _JTACGroup in pairs(ctld.deployedJTACs[_side]) do
_JTACMenuItem[itemNo] = missionCommands.addSubMenuForCoalition(_side, _JTACGroup, _JTACMenu)
--Add laser code submenus
_JTACMenuItemLaser[itemNo] = missionCommands.addSubMenuForCoalition(_side, "Change laser code", _JTACMenuItem[itemNo])
for _, _laseCode in pairs(ctld.laser_codes) do
missionCommands.addCommandForCoalition(_side, "to ".._laseCode, _JTACMenuItemLaser[itemNo], ctld.changeLaserCode, { _JTACGroup, _laseCode, _side})
end
--Add color change submenus
_JTACMenuItemColor[itemNo] = missionCommands.addSubMenuForCoalition(_side, "Change smoke color", _JTACMenuItem[itemNo])
for _, _smokeColor in pairs(ctld.JTAC_smokeColous) do
missionCommands.addCommandForCoalition(_side, "to ".._smokeColor, _JTACMenuItemColor[itemNo], ctld.changeJTACColor, { _JTACGroup, _smokeColor, _side})
end
itemNo = itemNo + 1
end
end
function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour) function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
@@ -4773,8 +5049,6 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
end end
ctld.jtacLaserPointCodes[_jtacGroupName] = _laserCode
local _jtacGroup = ctld.getGroup(_jtacGroupName) local _jtacGroup = ctld.getGroup(_jtacGroupName)
local _jtacUnit local _jtacUnit
@@ -4806,8 +5080,18 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
if ctld.jtacUnits[_jtacGroupName] ~= nil then if ctld.jtacUnits[_jtacGroupName] ~= nil then
ctld.notifyCoalition("JTAC Group " .. _jtacGroupName .. " KIA!", 10, ctld.jtacUnits[_jtacGroupName].side) local _side = ctld.jtacUnits[_jtacGroupName].side
end ctld.notifyCoalition("JTAC Group " .. _jtacGroupName .. " KIA!", 10, _side)
ctld.deployedJTACs[_side] = {}
for _jtacGroupName, _jtacDetails in pairs(ctld.jtacUnits) do
_jtacUnit = Unit.getByName(_jtacDetails.name)
if _jtacUnit ~= nil and _jtacUnit:getLife() > 0 and _jtacUnit:getCoalition() == _side then
table.insert(ctld.deployedJTACs[_side], _jtacGroupName)
end
end
ctld.refreshJTACMenu(ctld.jtacUnits[_jtacGroupName].side)
end
--remove from list --remove from list
ctld.jtacUnits[_jtacGroupName] = nil ctld.jtacUnits[_jtacGroupName] = nil
@@ -4890,7 +5174,7 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
-- store current target for easy lookup -- store current target for easy lookup
ctld.jtacCurrentTargets[_jtacGroupName] = { name = _enemyUnit:getName(), unitType = _enemyUnit:getTypeName(), unitId = _enemyUnit:getID() } ctld.jtacCurrentTargets[_jtacGroupName] = { name = _enemyUnit:getName(), unitType = _enemyUnit:getTypeName(), unitId = _enemyUnit:getID() }
ctld.notifyCoalition(_jtacGroupName .. " lasing new target " .. _enemyUnit:getTypeName() .. '. CODE: ' .. _laserCode .. ctld.getPositionString(_enemyUnit), 10, _jtacUnit:getCoalition()) ctld.notifyCoalition(_jtacGroupName .. " lasing new target " .. _enemyUnit:getTypeName() .. '. CODE: ' .. _laserCode .. ctld.getPositionString(_enemyUnit) .. ". Smoke: " .. ctld.GetColorName(_colour), 10, _jtacUnit:getCoalition())
-- create smoke -- create smoke
if _smoke == true then if _smoke == true then
@@ -5091,144 +5375,153 @@ end
-- Find nearest enemy to JTAC that isn't blocked by terrain -- Find nearest enemy to JTAC that isn't blocked by terrain
function ctld.findNearestVisibleEnemy(_jtacUnit, _targetType,_distance) function ctld.findNearestVisibleEnemy(_jtacUnit, _targetType,_distance)
--local startTime = os.clock()
local _maxDistance = _distance or ctld.JTAC_maxDistance local _maxDistance = _distance or ctld.JTAC_maxDistance
local _x = 1
local _i = 1
local _units = nil
local _groupName = nil
local _nearestUnit = nil
local _nearestDistance = _maxDistance local _nearestDistance = _maxDistance
local _enemyGroups local _jtacPoint = _jtacUnit:getPoint()
local _coa = _jtacUnit:getCoalition()
if _jtacUnit:getCoalition() == 1 then local _offsetJTACPos = { x = _jtacPoint.x, y = _jtacPoint.y + 2.0, z = _jtacPoint.z }
_enemyGroups = coalition.getGroups(2, Group.Category.GROUND)
else local _volume = {
_enemyGroups = coalition.getGroups(1, Group.Category.GROUND) id = world.VolumeType.SPHERE,
params = {
point = _offsetJTACPos,
radius = _maxDistance
}
}
local _unitList = {}
local _search = function(_unit, _coa)
pcall(function()
if _unit ~= nil
and _unit:getLife() > 0
and _unit:isActive()
and _unit:getCoalition() ~= _coa
and not _unit:inAir()
and not ctld.alreadyTarget(_jtacUnit,_unit) then
local _tempPoint = _unit:getPoint()
local _offsetEnemyPos = { x = _tempPoint.x, y = _tempPoint.y + 2.0, z = _tempPoint.z }
if land.isVisible(_offsetJTACPos,_offsetEnemyPos ) then
local _dist = ctld.getDistance(_offsetJTACPos, _offsetEnemyPos)
if _dist < _maxDistance then
table.insert(_unitList,{unit=_unit, dist=_dist})
end
end
end
end)
return true
end end
world.searchObjects(Object.Category.UNIT, _volume, _search, _coa)
--log.info(string.format("JTAC Search elapsed time: %.4f\n", os.clock() - startTime))
-- generate list order by distance & visible
-- first check
-- hpriority
-- priority
-- vehicle
-- unit
local _sort = function( a,b ) return a.dist < b.dist end
table.sort(_unitList,_sort)
-- sort list
-- check for hpriority
for _, _enemyUnit in ipairs(_unitList) do
local _enemyName = _enemyUnit.unit:getName()
if string.match(_enemyName, "hpriority") then
return _enemyUnit.unit
end
end
for _, _enemyUnit in ipairs(_unitList) do
local _enemyName = _enemyUnit.unit:getName()
if string.match(_enemyName, "priority") then
return _enemyUnit.unit
end
end
for _, _enemyUnit in ipairs(_unitList) do
local _enemyName = _enemyUnit.unit:getName()
if (_targetType == "vehicle" and ctld.isVehicle(_enemyUnit.unit)) or _targetType == "all" then
return _enemyUnit.unit
elseif (_targetType == "troop" and ctld.isInfantry(_enemyUnit.unit)) or _targetType == "all" then
return _enemyUnit.unit
end
end
return nil
end
function ctld.listNearbyEnemies(_jtacUnit)
local _maxDistance = ctld.JTAC_maxDistance
local _jtacPoint = _jtacUnit:getPoint() local _jtacPoint = _jtacUnit:getPoint()
local _jtacPosition = _jtacUnit:getPosition() local _coa = _jtacUnit:getCoalition()
local _tempPoint = nil local _offsetJTACPos = { x = _jtacPoint.x, y = _jtacPoint.y + 2.0, z = _jtacPoint.z }
local _tempPosition = nil
local _tempDist = nil local _volume = {
id = world.VolumeType.SPHERE,
params = {
point = _offsetJTACPos,
radius = _maxDistance
}
}
local _enemies = nil
-- finish this function local _search = function(_unit, _coa)
local _vhpriority = false pcall(function()
local _vpriority = false
local _thpriority = false if _unit ~= nil
local _tpriority = false and _unit:getLife() > 0
for _i = 1, #_enemyGroups do and _unit:isActive()
if _enemyGroups[_i] ~= nil then and _unit:getCoalition() ~= _coa
_groupName = _enemyGroups[_i]:getName() and not _unit:inAir() then
_units = ctld.getGroup(_groupName)
if #_units > 0 then local _tempPoint = _unit:getPoint()
for _y = 1, #_units do local _offsetEnemyPos = { x = _tempPoint.x, y = _tempPoint.y + 2.0, z = _tempPoint.z }
local _targeted = false
if not _distance then if land.isVisible(_offsetJTACPos,_offsetEnemyPos ) then
_targeted = ctld.alreadyTarget(_jtacUnit, _units[_x])
if not _enemies then
_enemies = {}
end end
-- calc distance _enemies[_unit:getTypeName()] = _unit:getTypeName()
_tempPoint = _units[_y]:getPoint()
_tempDist = ctld.getDistance(_tempPoint, _jtacPoint)
if _tempDist < _maxDistance and _tempDist < _nearestDistance then
local _offsetEnemyPos = { x = _tempPoint.x, y = _tempPoint.y + 2.0, z = _tempPoint.z }
local _offsetJTACPos = { x = _jtacPoint.x, y = _jtacPoint.y + 2.0, z = _jtacPoint.z }
-- calc visible
if land.isVisible(_offsetEnemyPos, _offsetJTACPos) and _targeted == false then
if (string.match(_units[_y]:getName(), "hpriority") ~= nil) and ctld.isVehicle(_units[_y]) then
_vhpriority = true
elseif (string.match(_units[_y]:getName(), "priority") ~= nil) and ctld.isVehicle(_units[_y]) then
_vpriority = true
elseif (string.match(_units[_y]:getName(), "hpriority") ~= nil) and ctld.isInfantry(_units[_y]) then
_thpriority = true
elseif (string.match(_units[_y]:getName(), "priority") ~= nil) and ctld.isInfantry(_units[_y]) then
_tpriority = true
end
end
end
end end
end end
end end)
return true
end end
for _i = 1, #_enemyGroups do world.searchObjects(Object.Category.UNIT, _volume, _search, _coa)
if _enemyGroups[_i] ~= nil then
_groupName = _enemyGroups[_i]:getName()
_units = ctld.getGroup(_groupName)
if #_units > 0 then
for _x = 1, #_units do return _enemies
--check to see if a JTAC has already targeted this unit only if a distance
--wasnt passed in
local _targeted = false
if not _distance then
_targeted = ctld.alreadyTarget(_jtacUnit, _units[_x])
end
local _allowedTarget = true
if _targetType == "vehicle" and _vhpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "hpriority") ~= nil) and ctld.isVehicle(_units[_x])
elseif _targetType == "vehicle" and _vpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "priority") ~= nil) and ctld.isVehicle(_units[_x])
elseif _targetType == "vehicle" then
_allowedTarget = ctld.isVehicle(_units[_x])
elseif _targetType == "troop" and _thpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "hpriority") ~= nil) and ctld.isInfantry(_units[_x])
elseif _targetType == "troop" and _tpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "priority") ~= nil) and ctld.isInfantry(_units[_x])
elseif _targetType == "troop" then
_allowedTarget = ctld.isInfantry(_units[_x])
elseif _vhpriority == true or _thpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "hpriority") ~= nil)
elseif _vpriority == true or _tpriority == true then
_allowedTarget = (string.match(_units[_x]:getName(), "priority") ~= nil)
else
_allowedTarget = true
end
if _units[_x]:isActive() == true and _targeted == false and _allowedTarget == true then
-- calc distance
_tempPoint = _units[_x]:getPoint()
_tempDist = ctld.getDistance(_tempPoint, _jtacPoint)
if _tempDist < _maxDistance and _tempDist < _nearestDistance then
local _offsetEnemyPos = { x = _tempPoint.x, y = _tempPoint.y + 2.0, z = _tempPoint.z }
local _offsetJTACPos = { x = _jtacPoint.x, y = _jtacPoint.y + 2.0, z = _jtacPoint.z }
-- calc visible
if land.isVisible(_offsetEnemyPos, _offsetJTACPos) then
_nearestDistance = _tempDist
_nearestUnit = _units[_x]
end
end
end
end
end
end
end
if _nearestUnit == nil then
return nil
end
return _nearestUnit
end end
-- tests whether the unit is targeted by another JTAC -- tests whether the unit is targeted by another JTAC
@@ -5309,6 +5602,8 @@ function ctld.getJTACStatus(_args)
local _enemyUnit = ctld.getCurrentUnit(_jtacUnit, _jtacGroupName) local _enemyUnit = ctld.getCurrentUnit(_jtacUnit, _jtacGroupName)
local _jtacColor = ctld.jtacColor[_jtacGroupName]
local _laserCode = ctld.jtacLaserPointCodes[_jtacGroupName] local _laserCode = ctld.jtacLaserPointCodes[_jtacGroupName]
if _laserCode == nil then if _laserCode == nil then
@@ -5316,7 +5611,19 @@ function ctld.getJTACStatus(_args)
end end
if _enemyUnit ~= nil and _enemyUnit:getLife() > 0 and _enemyUnit:isActive() == true then if _enemyUnit ~= nil and _enemyUnit:getLife() > 0 and _enemyUnit:isActive() == true then
_message = _message .. "" .. _jtacGroupName .. " targeting " .. _enemyUnit:getTypeName() .. " CODE: " .. _laserCode .. ctld.getPositionString(_enemyUnit) .. "\n" _message = _message .. "" .. _jtacGroupName .. " targeting " .. _enemyUnit:getTypeName() .. " CODE: " .. _laserCode .. ctld.getPositionString(_enemyUnit) ..". Visual indication: " .. ctld.GetColorName(_jtacColor).. " smoke." .. "\n"
local _list = ctld.listNearbyEnemies(_jtacUnit)
if _list then
_message = _message.."Visual On: "
for _,_type in pairs(_list) do
_message = _message.._type.." "
end
_message = _message.."\n"
end
else else
_message = _message .. "" .. _jtacGroupName .. " searching for targets" .. ctld.getPositionString(_jtacUnit) .. "\n" _message = _message .. "" .. _jtacGroupName .. " searching for targets" .. ctld.getPositionString(_jtacUnit) .. "\n"
end end
@@ -5331,7 +5638,21 @@ function ctld.getJTACStatus(_args)
ctld.notifyCoalition(_message, 10, _side) ctld.notifyCoalition(_message, 10, _side)
end end
function ctld.GetColorName(_Color)
local _ColorName = "No"
if _Color == 0 then
_ColorName = "Green"
elseif _Color == 1 then
_ColorName = "Red"
elseif _Color == 2 then
_ColorName = "White"
elseif _Color == 3 then
_ColorName = "Orange"
elseif _Color == 4 then
_ColorName = "Blue"
end
return _ColorName
end
function ctld.isInfantry(_unit) function ctld.isInfantry(_unit)
@@ -5395,6 +5716,10 @@ function ctld.generateLaserCode()
end end
end end
function ctld.jtacGetLaserCodeBySide(_side)
return ctld.laser_codes[_side]
end
function ctld.containsDigit(_number, _numberToFind) function ctld.containsDigit(_number, _numberToFind)
local _thisNumber = _number local _thisNumber = _number
@@ -5786,20 +6111,52 @@ if ctld.allowRandomAiTeamPickups == true then
end end
end end
-- add total count
-- Scheduled functions (run cyclically) for _,_loadGroup in pairs(ctld.loadableGroups) do
timer.scheduleFunction(ctld.refreshSmoke, nil, timer.getTime() + 5) _loadGroup.total = 0
timer.scheduleFunction(ctld.addF10MenuOptions, nil, timer.getTime() + 5) if _loadGroup.aa then
timer.scheduleFunction(ctld.checkAIStatus, nil, timer.getTime() + 1) _loadGroup.total = _loadGroup.aa + _loadGroup.total
timer.scheduleFunction(ctld.checkTransportStatus, nil, timer.getTime() + 5) end
timer.scheduleFunction(ctld.refreshRadioBeacons, nil, timer.getTime() + 5)
if _loadGroup.inf then
_loadGroup.total = _loadGroup.inf + _loadGroup.total
end
if _loadGroup.mg then
_loadGroup.total = _loadGroup.mg + _loadGroup.total
end
if _loadGroup.at then
_loadGroup.total = _loadGroup.at + _loadGroup.total
end
if _loadGroup.mortar then
_loadGroup.total = _loadGroup.mortar + _loadGroup.total
end
if ctld.enableCrates == true and ctld.slingLoad == false and ctld.hoverPickup == true then
timer.scheduleFunction(ctld.checkHoverStatus, nil, timer.getTime() + 1)
end end
-- Scheduled functions (run cyclically) -- but hold execution for a second so we can override parts
timer.scheduleFunction(ctld.checkAIStatus, nil, timer.getTime() + 1)
timer.scheduleFunction(ctld.checkTransportStatus, nil, timer.getTime() + 5)
timer.scheduleFunction(function()
timer.scheduleFunction(ctld.refreshRadioBeacons, nil, timer.getTime() + 5)
timer.scheduleFunction(ctld.refreshSmoke, nil, timer.getTime() + 5)
timer.scheduleFunction(ctld.addF10MenuOptions, nil, timer.getTime() + 5)
if ctld.enableCrates == true and ctld.slingLoad == false and ctld.hoverPickup == true then
timer.scheduleFunction(ctld.checkHoverStatus, nil, timer.getTime() + 1)
end
end,nil, timer.getTime()+1 )
--event handler for deaths --event handler for deaths
--world.addEventHandler(ctld.eventHandler) --world.addEventHandler(ctld.eventHandler)
@@ -5848,8 +6205,9 @@ for _coalitionName, _coalitionData in pairs(env.mission.coalition) do
if _group and _group.units and type(_group.units) == 'table' then if _group and _group.units and type(_group.units) == 'table' then
for _unitNum, _unit in pairs(_group.units) do for _unitNum, _unit in pairs(_group.units) do
if _unit.canCargo == true then if _unit.canCargo == true then
ctld.missionEditorCargoCrates[_unit.name] = _unit.name local _cargoName = env.getValueDictByKey(_unit.name)
env.info("Crate Found: " .. _unit.name) ctld.missionEditorCargoCrates[_cargoName] = _cargoName
env.info("Crate Found: " .. _unit.name.." - Unit: ".._cargoName)
end end
end end
end end

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.