mirror of
https://github.com/ciribob/DCS-CTLD.git
synced 2026-08-28 15:36:08 +00:00
Bug fix for AI Auto troop load
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
Contributors:
|
||||
- Steggles - https://github.com/Bob7heBuilder
|
||||
|
||||
Version: 1.41 - 11/11/2015 - Added new callback interface
|
||||
Version: 1.42 - 11/11/2015 - Added new callback interface
|
||||
- Added Different Pickup Groups for F10 and for the spawn group command
|
||||
- EWR now activates
|
||||
- Bug fix for AI Group Load
|
||||
|
||||
]]
|
||||
|
||||
@@ -1423,7 +1424,7 @@ function ctld.loadTroops(_heli, _troops, _numberOrTemplate)
|
||||
local _onboard = ctld.inTransitTroops[_heli:getName()]
|
||||
|
||||
--number doesnt apply to vehicles
|
||||
if _numberOrTemplate == nil then
|
||||
if _numberOrTemplate == nil or (type(_numberOrTemplate) ~= "table" and type(_numberOrTemplate) ~= "number") then
|
||||
_numberOrTemplate = ctld.numberOfTroops
|
||||
end
|
||||
|
||||
@@ -3848,20 +3849,22 @@ function ctld.checkAIStatus()
|
||||
|
||||
timer.scheduleFunction(ctld.checkAIStatus, nil, timer.getTime() + 2)
|
||||
|
||||
|
||||
for _, _unitName in pairs(ctld.transportPilotNames) do
|
||||
local status, error = pcall(function()
|
||||
|
||||
local _unit = ctld.getTransportUnit(_unitName)
|
||||
|
||||
-- no player name means AI!
|
||||
if _unit ~= nil and _unit:getPlayerName() == nil then
|
||||
local _zone = ctld.inPickupZone(_unit)
|
||||
|
||||
-- env.error("Checking.. ".._unit:getName())
|
||||
if _zone.inZone == true and not ctld.troopsOnboard(_unit, true) then
|
||||
|
||||
-- env.error("in zone, loading.. ".._unit:getName())
|
||||
ctld.loadTroopsFromZone({ _unitName, true,"",true })
|
||||
|
||||
elseif ctld.inDropoffZone(_unit) and ctld.troopsOnboard(_unit, true) then
|
||||
|
||||
-- env.error("in dropoff zone, unloading.. ".._unit:getName())
|
||||
ctld.unloadTroops( { _unitName, true })
|
||||
end
|
||||
|
||||
@@ -3877,10 +3880,17 @@ function ctld.checkAIStatus()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
if (not status) then
|
||||
env.error(string.format("Error with ai status: %s", error), false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- Adds menuitem to all heli units that are active
|
||||
function ctld.addF10MenuOptions()
|
||||
-- Loop through all Heli units
|
||||
@@ -5039,7 +5049,7 @@ end
|
||||
|
||||
timer.scheduleFunction(ctld.refreshSmoke, nil, timer.getTime() + 5)
|
||||
timer.scheduleFunction(ctld.addF10MenuOptions, nil, timer.getTime() + 5)
|
||||
timer.scheduleFunction(ctld.checkAIStatus, nil, timer.getTime() + 5)
|
||||
timer.scheduleFunction(ctld.checkAIStatus, nil, timer.getTime() + 1)
|
||||
timer.scheduleFunction(ctld.checkTransportStatus, nil, timer.getTime() + 5)
|
||||
timer.scheduleFunction(ctld.refreshRadioBeacons, nil, timer.getTime() + 5)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -15,7 +15,7 @@ mist = {}
|
||||
-- don't change these
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 0
|
||||
mist.build = 55
|
||||
mist.build = 57
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
-- the main area
|
||||
@@ -492,6 +492,7 @@ do
|
||||
newObj.name = staticObj.name
|
||||
newObj.dead = staticObj.dead
|
||||
newObj.country = staticObj.country
|
||||
newObj.countryId = staticObj.countryId
|
||||
newObj.clone = staticObj.clone
|
||||
newObj.shape_name = staticObj.shape_name
|
||||
newObj.canCargo = staticObj.canCargo
|
||||
@@ -508,21 +509,22 @@ do
|
||||
newObj.name = staticObj.units[1].name
|
||||
newObj.dead = staticObj.units[1].dead
|
||||
newObj.country = staticObj.units[1].country
|
||||
newObj.countryId = staticObj.units[1].countryId
|
||||
newObj.shape_name = staticObj.units[1].shape_name
|
||||
newObj.canCargo = staticObj.units[1].canCargo
|
||||
newObj.mass = staticObj.units[1].mass
|
||||
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
||||
end
|
||||
|
||||
|
||||
newObj.country = staticObj.country
|
||||
|
||||
if not newObj.country then
|
||||
return false
|
||||
end
|
||||
|
||||
local newCountry
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
local newCountry = newObj.country
|
||||
if newObj.countryId then
|
||||
newCountry = newObj.countryId
|
||||
end
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(newObj.country) == 'string' then
|
||||
if tostring(countryName) == string.upper(newObj.country) then
|
||||
newCountry = countryName
|
||||
@@ -577,12 +579,17 @@ do
|
||||
--
|
||||
|
||||
|
||||
--env.info('dynAdd')
|
||||
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupOrig.lua')
|
||||
local cntry = newGroup.country
|
||||
if newGroup.countryId then
|
||||
cntry = newGroup.countryId
|
||||
end
|
||||
|
||||
local groupType = newGroup.category
|
||||
local newCountry = ''
|
||||
-- validate data
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(cntry) == 'string' then
|
||||
if tostring(countryName) == string.upper(cntry) then
|
||||
newCountry = countryName
|
||||
@@ -616,7 +623,6 @@ do
|
||||
newCat = 'AIRPLANE'
|
||||
end
|
||||
end
|
||||
|
||||
local typeName
|
||||
if newCat == 'GROUND_UNIT' then
|
||||
typeName = ' gnd '
|
||||
@@ -629,7 +635,6 @@ do
|
||||
elseif newCat == 'BUILDING' then
|
||||
typeName = ' bld '
|
||||
end
|
||||
|
||||
if newGroup.clone or not newGroup.groupId then
|
||||
mistDynAddIndex = mistDynAddIndex + 1
|
||||
mistGpId = mistGpId + 1
|
||||
@@ -662,8 +667,9 @@ do
|
||||
newGroup.start_time = 0
|
||||
end
|
||||
end
|
||||
for unitIndex, unitData in pairs(newGroup.units) do
|
||||
|
||||
|
||||
for unitIndex, unitData in pairs(newGroup.units) do
|
||||
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
||||
if newGroup.clone or not unitData.unitId then
|
||||
mistUnitId = mistUnitId + 1
|
||||
@@ -720,7 +726,6 @@ do
|
||||
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
||||
end
|
||||
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
||||
|
||||
if newGroup.route and not newGroup.route.points then
|
||||
if not newGroup.route.points and newGroup.route[1] then
|
||||
local copyRoute = newGroup.route
|
||||
@@ -2034,6 +2039,10 @@ for coa_name, coa_data in pairs(mist.DBs.units) do
|
||||
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
|
||||
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(unit_data)
|
||||
--if Unit.getByName(unit_data.unitName) then
|
||||
-- mist.DBs.activeHumans[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2158,7 +2167,10 @@ do
|
||||
val['objectPos'] = pos.p
|
||||
end
|
||||
val['objectType'] = mist.DBs.aliveUnits[val.object.id_].category
|
||||
|
||||
--[[if mist.DBs.activeHumans[Unit.getName(val.object)] then
|
||||
--trigger.action.outText('remove via death: ' .. Unit.getName(val.object),20)
|
||||
mist.DBs.activeHumans[Unit.getName(val.object)] = nil
|
||||
end]]
|
||||
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
|
||||
--print('object found in old_alive_units')
|
||||
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||
@@ -2200,22 +2212,22 @@ do
|
||||
|
||||
mist.addEventHandler(addDeadObject)
|
||||
|
||||
|
||||
--[[local function addClientsToActive(event)
|
||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
||||
if not mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
||||
--[[
|
||||
local function addClientsToActive(event)
|
||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_BIRTH then
|
||||
env.info(mist.utils.tableShow(event))
|
||||
if Unit.getPlayerName(event.initiator) then
|
||||
env.info(Unit.getPlayerName(event.initiator))
|
||||
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
||||
newU.playerName = Unit.getPlayerName(event.initiator)
|
||||
end
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
||||
--trigger.action.outText('added: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT or event.id == world.event.S_EVENT_DEATH then
|
||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and event.initiator then
|
||||
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
||||
-- trigger.action.outText('removed via control: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
elseif event.id == world.event.S_EVENT_BIRTH then -- do client check
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3054,6 +3066,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
interval = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
zUnitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
||||
@@ -3068,15 +3081,24 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
local interval = vars.interval or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
local zUnitTableDef = vars.zUnitTableDef
|
||||
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
end
|
||||
|
||||
if not zone_units.processed then
|
||||
zUnitTableDef = mist.utils.deepCopy(zone_units)
|
||||
end
|
||||
|
||||
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
end
|
||||
|
||||
if (zone_units.processed and zone_units.processed < mist.getLastDBUpdateTime()) or not zone_units.processed then -- run unit table short cuts
|
||||
zone_units = mist.makeUnitTable(zUnitTableDef)
|
||||
end
|
||||
|
||||
if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||
|
||||
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
||||
@@ -3088,7 +3110,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
end
|
||||
-- do another check in case stopflag was set true by this function
|
||||
if (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle}}, timer.getTime() + interval)
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle, unitTableDef = unitTableDef, zUnitTableDef = zUnitTableDef}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3199,11 +3221,11 @@ toggle = boolean or nil
|
||||
end
|
||||
|
||||
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef1)
|
||||
unitset1 = mist.makeUnitTable(unitTableDef1)
|
||||
end
|
||||
|
||||
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef2)
|
||||
unitset2 = mist.makeUnitTable(unitTableDef2)
|
||||
end
|
||||
|
||||
|
||||
@@ -3919,7 +3941,7 @@ mist.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
|
||||
local pos = mist.getLeadPos(gpData)
|
||||
local fakeZone = {}
|
||||
fakeZone.radius = dist or math.random(300, 1000)
|
||||
fakeZone.point = {x = pos.x, y, pos.y, z = pos.z}
|
||||
fakeZone.point = {x = pos.x, y = pos.y, z = pos.z}
|
||||
mist.groupToRandomZone(gpData, fakeZone, form, heading, speed)
|
||||
|
||||
return
|
||||
@@ -4080,6 +4102,7 @@ do
|
||||
local caSlots = false
|
||||
local caMSGtoGroup = false
|
||||
|
||||
if env.mission.groundControl then -- just to be sure?
|
||||
for index, value in pairs(env.mission.groundControl) do
|
||||
if type(value) == 'table' then
|
||||
for roleName, roleVal in pairs(value) do
|
||||
@@ -4097,6 +4120,7 @@ do
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mistdisplayV5()
|
||||
--[[thoughts to improve upon
|
||||
@@ -4193,7 +4217,6 @@ do
|
||||
end
|
||||
if msgTableText['BLUE'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4339,8 +4362,6 @@ do
|
||||
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
||||
if listData == string.lower(coaData) or listData == 'all' then
|
||||
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
||||
--table.insert(newMsgFor, coaData)
|
||||
-- added redca or blueca to list
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5279,7 +5300,6 @@ end
|
||||
if string.lower(newGroupData.category) == 'static' then
|
||||
return mist.dynAddStatic(newGroupData)
|
||||
end
|
||||
|
||||
return mist.dynAdd(newGroupData)
|
||||
|
||||
end
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user