Fix/v5.0 (#46)
* fixed for static train carts having no category? * fixed issues with v5.0.0 --------- Co-authored-by: dutchie032 <dutchie032>
This commit is contained in:
committed by
GitHub
co-authored by
dutchie032 <dutchie032>
parent
d6178bcdd7
commit
ab8d667504
@@ -217,15 +217,17 @@ GlobalStageManager.printFullOverview = function ()
|
||||
local totalbai = 0
|
||||
local totaldead = 0
|
||||
local totalMissions = 0
|
||||
local totalCas = 0
|
||||
|
||||
for _, stage in pairs(stages) do
|
||||
|
||||
local strike, dead, bai = stage:GetStageStats()
|
||||
local strike, dead, bai, cas = stage:GetStageStats()
|
||||
|
||||
totalStrike = totalStrike + strike
|
||||
totalbai = totalbai + bai
|
||||
totaldead = totaldead + dead
|
||||
totalMissions = totalMissions + strike + dead + bai
|
||||
totalCas = totalCas + cas
|
||||
totalMissions = totalMissions + strike + dead + bai + cas
|
||||
end
|
||||
|
||||
local index = tonumber(stageIndex)
|
||||
@@ -233,7 +235,7 @@ GlobalStageManager.printFullOverview = function ()
|
||||
if index > max then
|
||||
max = index
|
||||
end
|
||||
lines[index] ="Stage# " .. tostring(stageIndex).. " | " .. totalStrike .. " strikes | " .. totaldead .. " dead | " .. totalbai .. " BAI | Total:" .. totalMissions
|
||||
lines[index] ="Stage# " .. tostring(stageIndex).. " | " .. totalStrike .. " strikes | " .. totaldead .. " dead | " .. totalbai .. " BAI | " .. totalCas .. " CAS | Total:" .. totalMissions
|
||||
else
|
||||
logger:warn("Stage index is not a number: " .. stageIndex)
|
||||
end
|
||||
|
||||
@@ -503,19 +503,23 @@ end
|
||||
---@return number strike
|
||||
---@return number dead
|
||||
---@return number bai
|
||||
---@return number cas
|
||||
function Stage:GetStageStats()
|
||||
|
||||
local strike = 0
|
||||
local dead = 0
|
||||
local bai = 0
|
||||
local cas = 0
|
||||
|
||||
for _, mission in pairs(self._db.missions) do
|
||||
if mission.missionType == "STRIKE" then
|
||||
strike = strike + 1
|
||||
elseif mission.missionType == "DEAD" then
|
||||
elseif mission.missionType == "DEAD" or mission.missionType == "SAM" then
|
||||
dead = dead + 1
|
||||
elseif mission.missionType == "BAI" then
|
||||
bai = bai + 1
|
||||
elseif mission.missionType == "CAS" then
|
||||
cas = cas + 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -523,7 +527,7 @@ function Stage:GetStageStats()
|
||||
dead = dead + 1
|
||||
end
|
||||
|
||||
return strike, dead, bai
|
||||
return strike, dead, bai, cas
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -245,14 +245,7 @@ function MissionCommandsHelper:updateCommandsForGroup(groupID)
|
||||
|
||||
self:ResetFolders(groupID)
|
||||
|
||||
for code, enabled in pairs(self.enabledByCode) do
|
||||
if enabled == true then
|
||||
local mission = self.missionsByCode[code]
|
||||
if mission then
|
||||
self:addMissionCommands(groupID, mission)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:AddAllMissionCommandsToGroup(groupID)
|
||||
|
||||
self:AddSupplyHubCommandsIfApplicable(groupID)
|
||||
self:AddCargoCommands(groupID)
|
||||
@@ -283,18 +276,60 @@ function MissionCommandsHelper:PinMission(mission, groupID)
|
||||
self:updateCommandsForGroup(groupID)
|
||||
end
|
||||
|
||||
function MissionCommandsHelper:AddAllMissionCommandsToGroup(groupID)
|
||||
|
||||
local perFolder = 9
|
||||
|
||||
do --- primary missions
|
||||
local count = 0
|
||||
local path = { [1] = folderNames.primary }
|
||||
for code, enabled in pairs(self.enabledByCode) do
|
||||
if enabled == true then
|
||||
local mission = self.missionsByCode[code]
|
||||
if mission and mission.priority == "primary" then
|
||||
count = count + 1
|
||||
if count <= perFolder then
|
||||
local copied = Spearhead.Util.copyTable(path)
|
||||
self:addMissionCommands(groupID, copied, mission)
|
||||
else
|
||||
local name = "Next Menu ..."
|
||||
missionCommands.addSubMenuForGroup(groupID, name, path)
|
||||
path[#path+1] = name
|
||||
count = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do --- secondary missions
|
||||
local count = 0
|
||||
local path = { [1] = folderNames.secondary }
|
||||
for code, enabled in pairs(self.enabledByCode) do
|
||||
if enabled == true then
|
||||
local mission = self.missionsByCode[code]
|
||||
if mission and mission.priority == "secondary" then
|
||||
count = count + 1
|
||||
if count <= perFolder then
|
||||
local copied = Spearhead.Util.copyTable(path)
|
||||
self:addMissionCommands(groupID, copied, mission)
|
||||
else
|
||||
local name = "Next Menu ..."
|
||||
missionCommands.addSubMenuForGroup(groupID, name, path)
|
||||
path[#path+1] = "more missions ..."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---comment
|
||||
---@private
|
||||
---@param groupId integer
|
||||
---@param path Array<string>
|
||||
---@param mission Mission
|
||||
function MissionCommandsHelper:addMissionCommands(groupId, mission)
|
||||
local path = nil
|
||||
|
||||
if mission.priority == "primary" then
|
||||
path = { [1] = folderNames.primary }
|
||||
elseif mission.priority == "secondary" then
|
||||
path = { [1] = folderNames.secondary }
|
||||
end
|
||||
function MissionCommandsHelper:addMissionCommands(groupId, path, mission)
|
||||
|
||||
if path then
|
||||
local missionFolderName = "[" .. mission.code .. "]" .. mission.name
|
||||
|
||||
@@ -9,6 +9,7 @@ env.info("Spearhead SupplyUnitsTracker loaded")
|
||||
---@field private _commandsHelper MissionCommandsHelper
|
||||
---@field private _droppedCrates table<string, StaticObject>
|
||||
---@field private _registeredHubs table<SupplyHub, boolean>
|
||||
---@field private _supplyUnitSpawnedListener Array<SupplyUnitSpawnedListener>
|
||||
local SupplyUnitsTracker = {}
|
||||
SupplyUnitsTracker.__index = SupplyUnitsTracker
|
||||
|
||||
@@ -67,7 +68,30 @@ function SupplyUnitsTracker:OnPlayerEntersUnit(unit)
|
||||
|
||||
if self:IsSupplyUnit(unit) == true then
|
||||
self._supplyUnitsByName[unit:getName()] = unit
|
||||
self._cargoInUnits[tostring(unit:getID())] = nil
|
||||
self._unitPositions[tostring(unit:getID())] = unit:getPoint()
|
||||
end
|
||||
|
||||
for _, listener in pairs(self._supplyUnitSpawnedListener) do
|
||||
pcall(function()
|
||||
listener:SupplyUnitSpawned(unit)
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
---@class SupplyUnitSpawnedListener
|
||||
---@field SupplyUnitSpawned fun(self:SupplyUnitSpawnedListener, unit:Unit)
|
||||
|
||||
---@param listener SupplyUnitSpawnedListener
|
||||
function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
|
||||
if listener == nil then return end
|
||||
|
||||
if self._supplyUnitSpawnedListener == nil then
|
||||
self._supplyUnitSpawnedListener = {}
|
||||
end
|
||||
|
||||
table.insert(self._supplyUnitSpawnedListener, listener)
|
||||
end
|
||||
|
||||
function SupplyUnitsTracker:Update()
|
||||
@@ -143,6 +167,20 @@ function SupplyUnitsTracker:RemoveCargoFromUnit(unitID, crateType)
|
||||
|
||||
end
|
||||
|
||||
function SupplyUnitsTracker:UpdateWeightForUnit(unitID)
|
||||
|
||||
local weight = 0
|
||||
if self._cargoInUnits[tostring(unitID)] then
|
||||
for crateType, count in pairs(self._cargoInUnits[tostring(unitID)]) do
|
||||
local crateConfig = Spearhead.classes.stageClasses.helpers.supplies.SupplyConfigHelper.getSupplyConfig(crateType)
|
||||
if crateConfig and count then
|
||||
weight = weight + (crateConfig.weight * count)
|
||||
end
|
||||
end
|
||||
end
|
||||
trigger.action.setUnitInternalCargo(unitID, weight)
|
||||
end
|
||||
|
||||
|
||||
function SupplyUnitsTracker:CheckUnitsInZones()
|
||||
|
||||
@@ -209,6 +247,7 @@ function SupplyUnitsTracker:UnloadRequested(unitID, crateType)
|
||||
end
|
||||
|
||||
self:RemoveCargoFromUnit(unitID, crateType)
|
||||
self:UpdateWeightForUnit(unitID)
|
||||
|
||||
local cargoConfig = Spearhead.classes.stageClasses.helpers.supplies.SupplyConfigHelper.getSupplyConfig(crateType)
|
||||
|
||||
@@ -228,7 +267,6 @@ function SupplyUnitsTracker:UnloadRequested(unitID, crateType)
|
||||
}
|
||||
|
||||
local spawned = coalition.addStaticObject(unit:getCoalition(), cargoSpawnObject)
|
||||
|
||||
self._droppedCrates[cargoSpawnObject.name] = spawned
|
||||
self._commandsHelper:updateCommandsForGroup(group:getID())
|
||||
end
|
||||
@@ -303,7 +341,7 @@ function SupplyUnitsTracker:TryLoadCrateInUnit(unit, crateType)
|
||||
|
||||
local crateConfigA = Spearhead.classes.stageClasses.helpers.supplies.SupplyConfigHelper.getSupplyConfig(crateType)
|
||||
if crateConfigA == nil then
|
||||
trigger.action.outText("Invalid crate type: " .. crateType, 5)
|
||||
trigger.action.outTextForUnit(unit:getID(), "Invalid crate type: " .. crateType, 5)
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -316,19 +354,19 @@ function SupplyUnitsTracker:TryLoadCrateInUnit(unit, crateType)
|
||||
|
||||
local unitConfig = Spearhead.classes.stageClasses.helpers.supplies.MaxLoadConfig[unit:getTypeName()]
|
||||
if unitConfig == nil then
|
||||
trigger.action.outText("Your unit type is not configured for logistics: " .. crateType, 5)
|
||||
trigger.action.outTextForUnit(unit:getID(), "Your unit type is not configured for logistics: " .. crateType, 5)
|
||||
self._logger:error("Invalid unit type: " .. unit:getTypeName())
|
||||
return false
|
||||
end
|
||||
local maxWeight = unitConfig.maxInternalLoad
|
||||
|
||||
if currentWeight + crateConfigA.weight > maxWeight then
|
||||
trigger.action.outText("Failed to load crate due to it overloading your max weight of: " .. maxWeight .. "kg", 5)
|
||||
trigger.action.outTextForUnit(unit:getID(), "Failed to load crate due to it overloading your max weight of: " .. maxWeight .. "kg", 5)
|
||||
return false
|
||||
end
|
||||
|
||||
trigger.action.setUnitInternalCargo(unit:getName(), crateConfigA.weight)
|
||||
self:AddCargoToUnit(unit:getID(), crateType)
|
||||
self:UpdateWeightForUnit(unit:getID())
|
||||
|
||||
local group = unit:getGroup()
|
||||
if group == nil then return false end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
---@class BuildableMission : Mission
|
||||
---@class BuildableMission : Mission, SupplyUnitSpawnedListener
|
||||
---@field private _requiredKilos number
|
||||
---@field private _droppedKilos number
|
||||
---@field private _crateType SupplyType
|
||||
@@ -124,6 +124,10 @@ end
|
||||
|
||||
function BuildableMission:MarkMissionAreaToGroup(groupID)
|
||||
|
||||
if self._markIDsPerGroup[groupID] then
|
||||
Spearhead.DcsUtil.RemoveMark(self._markIDsPerGroup[groupID])
|
||||
end
|
||||
|
||||
local text = "[" .. self.code .. "] " .. self.name
|
||||
local location = { x= self.location.x, y=land.getHeight(self.location), z=self.location.y }
|
||||
local markID = Spearhead.DcsUtil.AddMarkToGroup(groupID, text, location)
|
||||
@@ -188,13 +192,37 @@ function BuildableMission:SpawnActive()
|
||||
self._state = "ACTIVE"
|
||||
|
||||
self._missionCommandsHelper:AddMissionToCommands(self)
|
||||
self._supplyUnitsTracker:AddOnSupplyUnitSpawnedListener(self)
|
||||
|
||||
local units = self._supplyUnitsTracker:GetUnits()
|
||||
if units then
|
||||
for _, unit in pairs(units) do
|
||||
if unit and unit:isExist() then
|
||||
local group = unit:getGroup()
|
||||
if group then
|
||||
self:MarkMissionAreaToGroup(group:getID())
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BuildableMission:SpawnForwardUnits()
|
||||
|
||||
end
|
||||
|
||||
---@param unit Unit
|
||||
function BuildableMission:SupplyUnitSpawned(unit)
|
||||
|
||||
if self._state ~= "ACTIVE" then return end
|
||||
|
||||
local group = unit:getGroup()
|
||||
if group == nil then return end
|
||||
|
||||
self:MarkMissionAreaToGroup(unit:getGroup():getID())
|
||||
end
|
||||
|
||||
|
||||
function BuildableMission:CheckCratesInZone()
|
||||
|
||||
---@type Array<Object>
|
||||
@@ -226,6 +254,15 @@ function BuildableMission:CheckCratesInZone()
|
||||
self:NotifyMissionComplete()
|
||||
self._state = "COMPLETED"
|
||||
end
|
||||
|
||||
if self._state == "COMPLETED" then
|
||||
for groupID, markID in pairs(self._markIDsPerGroup) do
|
||||
if markID then
|
||||
Spearhead.DcsUtil.RemoveMark(markID)
|
||||
self._markIDsPerGroup[groupID] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ function ZoneMission:UpdateState(checkHealth, messageIfDone)
|
||||
end
|
||||
|
||||
if self._state == "COMPLETED" and self._lastContactMarkerID then
|
||||
Spearhead.DcsUtil.RemoveMarker(self._lastContactMarkerID)
|
||||
Spearhead.DcsUtil.RemoveMark(self._lastContactMarkerID)
|
||||
end
|
||||
|
||||
if self._state == "COMPLETED" and self._battleManager then
|
||||
|
||||
Reference in New Issue
Block a user