Refactored everything for Lua Compile Tool

This commit is contained in:
2026-04-07 13:05:58 +02:00
parent 62fbb35f96
commit a4b87bee31
19 changed files with 264 additions and 203 deletions
+1 -1
View File
@@ -19,5 +19,5 @@
"livePreview.serverRoot": "/_docs", "livePreview.serverRoot": "/_docs",
"Lua.workspace.library": [ "Lua.workspace.library": [
"/Users/ex61wi/Developer/personal/DcsMissionScriptingTools/dutchies-dcs-scripting-tools/lua-addons" "/Users/ex61wi/Developer/personal/DcsMissionScriptingTools/dutchies-dcs-scripting-tools/lua-addons"
] ],
} }
+1 -1
View File
@@ -3,7 +3,7 @@ local CapGroup = require("classes.capClasses.airGroups.CapGroup")
local SweepGroup = require("classes.capClasses.airGroups.SweepGroup") local SweepGroup = require("classes.capClasses.airGroups.SweepGroup")
local InterceptGroup = require("classes.capClasses.airGroups.InterceptGroup") local InterceptGroup = require("classes.capClasses.airGroups.InterceptGroup")
local RunwayBombingTracker = require("classes.capClasses.runwayBombing.RunwayBombingTracker") local RunwayBombingTracker = require("classes.capClasses.runwayBombing.RunwayBombingTracker")
local SpearheadEvents = require("classes.util.SpearheadEvents") local SpearheadEvents = require("classes.spearhead_events")
local RunwayStrikeMission = require("classes.stageClasses.missions.RunwayStrikeMission") local RunwayStrikeMission = require("classes.stageClasses.missions.RunwayStrikeMission")
---@class CapBase : OnStageChangedListener ---@class CapBase : OnStageChangedListener
+71 -64
View File
@@ -1,3 +1,10 @@
local Util = require("classes.util.Util")
local DcsUtil = require("classes.util.DcsUtil")
local MissionEditorWarnings = require("classes.util.MissionEditorWarnings")
local MizGroupsManager = require("classes.helpers.MizGroupsManager")
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
---@class DatabaseTables ---@class DatabaseTables
---@field AllZoneNames Array<string> All Zone Names ---@field AllZoneNames Array<string> All Zone Names
---@field StageZoneNames Array<string> All Stage Zone Names ---@field StageZoneNames Array<string> All Stage Zone Names
@@ -112,13 +119,13 @@ function Database.New(Logger)
self._logger:debug("Initiating tables") self._logger:debug("Initiating tables")
do -- INIT ZONE TABLES do -- INIT ZONE TABLES
for zone_ind, zone_data in pairs(Spearhead.DcsUtil.__trigger_zones) do for zone_ind, zone_data in pairs(DcsUtil.__trigger_zones) do
local zone_name = zone_data.name local zone_name = zone_data.name
---@type Vec2 ---@type Vec2
local zoneLocation = { x = zone_data.location.x, y = zone_data.location.y } local zoneLocation = { x = zone_data.location.x, y = zone_data.location.y }
local split_string = Spearhead.Util.split_string(zone_name, "_") local split_string = Util.split_string(zone_name, "_")
table.insert(self._tables.AllZoneNames, zone_name) table.insert(self._tables.AllZoneNames, zone_name)
if string.lower(split_string[1]) == "missionstage" then if string.lower(split_string[1]) == "missionstage" then
@@ -188,7 +195,7 @@ function Database.New(Logger)
end end
if lowered == "scenerytarget" or lowered == "scenerytargets" then if lowered == "scenerytarget" or lowered == "scenerytargets" then
local sceneryObjects = Spearhead.DcsUtil.getSceneryObjectsInZone(zone_data) local sceneryObjects = DcsUtil.getSceneryObjectsInZone(zone_data)
for _, sceneryObject in pairs(sceneryObjects) do for _, sceneryObject in pairs(sceneryObjects) do
table.insert(self._tables.AllSceneryObjects, sceneryObject) table.insert(self._tables.AllSceneryObjects, sceneryObject)
end end
@@ -202,7 +209,7 @@ function Database.New(Logger)
for i, layer in pairs(env.mission.drawings.layers) do for i, layer in pairs(env.mission.drawings.layers) do
if string.lower(layer.name) == "author" then if string.lower(layer.name) == "author" then
for key, layer_object in pairs(layer.objects) do for key, layer_object in pairs(layer.objects) do
if Spearhead.Util.startswith(string.lower(layer_object.name), "buildable", true) == true then if Util.startswith(string.lower(layer_object.name), "buildable", true) == true then
local airbaseData = self:getAirbaseDataForDrawLayer(layer_object) local airbaseData = self:getAirbaseDataForDrawLayer(layer_object)
if airbaseData then if airbaseData then
self._logger:debug("found airbase data for " .. layer_object.name) self._logger:debug("found airbase data for " .. layer_object.name)
@@ -222,9 +229,9 @@ function Database.New(Logger)
for i, layer in pairs(env.mission.drawings.layers) do for i, layer in pairs(env.mission.drawings.layers) do
if string.lower(layer.name) == "author" then if string.lower(layer.name) == "author" then
for key, layer_object in pairs(layer.objects) do for key, layer_object in pairs(layer.objects) do
if Spearhead.Util.startswith(layer_object.name, "drawing_", true) then if Util.startswith(layer_object.name, "drawing_", true) then
local object = layer_object --[[@as DrawingObject]] local object = layer_object --[[@as DrawingObject]]
local customDrawing = Spearhead.classes.stageClasses.drawings.CustomDrawing.New(object) local customDrawing = CustomDrawing.New(object)
table.insert(self._tables.CustomDrawings, customDrawing) table.insert(self._tables.CustomDrawings, customDrawing)
end end
end end
@@ -248,10 +255,10 @@ function Database.New(Logger)
for i, layer in pairs(env.mission.drawings.layers) do for i, layer in pairs(env.mission.drawings.layers) do
if string.lower(layer.name) == "author" then if string.lower(layer.name) == "author" then
for key, layer_object in pairs(layer.objects) do for key, layer_object in pairs(layer.objects) do
if Spearhead.Util.startswith(string.lower(layer_object.name), "stagebriefing_", true) == true then if Util.startswith(string.lower(layer_object.name), "stagebriefing_", true) == true then
local zone = Spearhead.DcsUtil.getZoneByName(stageZoneName) local zone = DcsUtil.getZoneByName(stageZoneName)
local vec2 = { x = layer_object.mapX, y = layer_object.mapY } local vec2 = { x = layer_object.mapX, y = layer_object.mapY }
if zone and Spearhead.Util.is2dPointInZone(vec2, zone) == true then if zone and Util.is2dPointInZone(vec2, zone) == true then
local description = layer_object.text local description = layer_object.text
if description and description ~= "" then if description and description ~= "" then
stageData.StageBriefing = description stageData.StageBriefing = description
@@ -265,18 +272,18 @@ function Database.New(Logger)
-- fill blue sams -- fill blue sams
for _, blueSamStageName in pairs(self._tables.BlueSams) do for _, blueSamStageName in pairs(self._tables.BlueSams) do
if Spearhead.DcsUtil.isZoneInZone(blueSamStageName, stageZoneName) == true then if DcsUtil.isZoneInZone(blueSamStageName, stageZoneName) == true then
table.insert(stageData.BlueSamZones, blueSamStageName) table.insert(stageData.BlueSamZones, blueSamStageName)
end end
end end
--- fill farp zones --- fill farp zones
for _, farpZoneName in pairs(self._tables.AllFarpZones) do for _, farpZoneName in pairs(self._tables.AllFarpZones) do
if Spearhead.DcsUtil.isZoneInZone(farpZoneName, stageZoneName) then if DcsUtil.isZoneInZone(farpZoneName, stageZoneName) then
table.insert(stageData.FarpZones, farpZoneName) table.insert(stageData.FarpZones, farpZoneName)
for hubZoneName, available in pairs(availableSupplyHubs) do for hubZoneName, available in pairs(availableSupplyHubs) do
if available == true and Spearhead.DcsUtil.isZoneInZone(hubZoneName, farpZoneName) == true then if available == true and DcsUtil.isZoneInZone(hubZoneName, farpZoneName) == true then
local farpZoneData = self:getOrCreateFarpDataForZone(farpZoneName) local farpZoneData = self:getOrCreateFarpDataForZone(farpZoneName)
if farpZoneData then if farpZoneData then
table.insert(farpZoneData.supplyHubNames, hubZoneName) table.insert(farpZoneData.supplyHubNames, hubZoneName)
@@ -291,15 +298,15 @@ function Database.New(Logger)
for _, airbase in pairs(world.getAirbases()) do for _, airbase in pairs(world.getAirbases()) do
local point = airbase:getPoint() local point = airbase:getPoint()
if Spearhead.DcsUtil.isPositionInZone(point.x, point.z, stageZoneName) == true then if DcsUtil.isPositionInZone(point.x, point.z, stageZoneName) == true then
if airbase:getDesc().category == 0 then if airbase:getDesc().category == 0 then
table.insert(stageData.AirbaseNames, airbase:getName()) table.insert(stageData.AirbaseNames, airbase:getName())
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName()) local airbaseZone = DcsUtil.getAirbaseZoneByName(airbase:getName())
for hubZoneName, available in pairs(availableSupplyHubs) do for hubZoneName, available in pairs(availableSupplyHubs) do
local zone = Spearhead.DcsUtil.getZoneByName(hubZoneName) local zone = DcsUtil.getZoneByName(hubZoneName)
if zone and airbaseZone then if zone and airbaseZone then
if available == true and Spearhead.Util.is2dPointInZone(zone.location, airbaseZone) == true then if available == true and Util.is2dPointInZone(zone.location, airbaseZone) == true then
local airbaseData = self:getOrCreateAirbaseData(airbase:getName()) local airbaseData = self:getOrCreateAirbaseData(airbase:getName())
if airbaseData then if airbaseData then
table.insert(airbaseData.supplyHubNames, hubZoneName) table.insert(airbaseData.supplyHubNames, hubZoneName)
@@ -314,14 +321,14 @@ function Database.New(Logger)
-- fill supply hubs -- fill supply hubs
for supplyHubZone, available in pairs(availableSupplyHubs) do for supplyHubZone, available in pairs(availableSupplyHubs) do
if available == true and Spearhead.DcsUtil.isZoneInZone(supplyHubZone, stageZoneName) == true then if available == true and DcsUtil.isZoneInZone(supplyHubZone, stageZoneName) == true then
table.insert(stageData.SupplyHubZones, supplyHubZone) table.insert(stageData.SupplyHubZones, supplyHubZone)
end end
end end
for _, farpZoneName in pairs(stageData.FarpZones) do for _, farpZoneName in pairs(stageData.FarpZones) do
for _, supplyHubZone in pairs(self._tables.SupplyHubZones) do for _, supplyHubZone in pairs(self._tables.SupplyHubZones) do
if Spearhead.DcsUtil.isZoneInZone(supplyHubZone, farpZoneName) == true then if DcsUtil.isZoneInZone(supplyHubZone, farpZoneName) == true then
stageData.SupplyHubZonesInFarp[supplyHubZone] = farpZoneName stageData.SupplyHubZonesInFarp[supplyHubZone] = farpZoneName
end end
end end
@@ -329,14 +336,14 @@ function Database.New(Logger)
-- fill missions -- fill missions
for key, missionZone in pairs(self._tables.MissionZones) do for key, missionZone in pairs(self._tables.MissionZones) do
if Spearhead.DcsUtil.isZoneInZone(missionZone, stageZoneName) == true then if DcsUtil.isZoneInZone(missionZone, stageZoneName) == true then
table.insert(stageData.MissionZones, missionZone) table.insert(stageData.MissionZones, missionZone)
end end
end end
-- fill random missions -- fill random missions
for key, missionZone in pairs(self._tables.RandomMissionZones) do for key, missionZone in pairs(self._tables.RandomMissionZones) do
if Spearhead.DcsUtil.isZoneInZone(missionZone, stageZoneName) == true then if DcsUtil.isZoneInZone(missionZone, stageZoneName) == true then
table.insert(stageData.RandomMissionZones, missionZone) table.insert(stageData.RandomMissionZones, missionZone)
end end
end end
@@ -345,13 +352,13 @@ function Database.New(Logger)
for _, missionZone in pairs(self._tables.MissionZones) do for _, missionZone in pairs(self._tables.MissionZones) do
if self._tables.MissionZoneData[missionZone] == nil or self._tables.MissionZoneData[missionZone].description == nil then if self._tables.MissionZoneData[missionZone] == nil or self._tables.MissionZoneData[missionZone].description == nil then
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") MissionEditorWarnings.Add("Mission with zonename: " .. missionZone .. " does not have a briefing")
end end
end end
for _, missionZone in pairs(self._tables.RandomMissionZones) do for _, missionZone in pairs(self._tables.RandomMissionZones) do
if self._tables.MissionZoneData[missionZone] == nil or self._tables.MissionZoneData[missionZone].description == nil then if self._tables.MissionZoneData[missionZone] == nil or self._tables.MissionZoneData[missionZone].description == nil then
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") MissionEditorWarnings.Add("Mission with zonename: " .. missionZone .. " does not have a briefing")
end end
end end
@@ -368,7 +375,7 @@ function Database.New(Logger)
} }
end end
local position = airbase:getPoint() local position = airbase:getPoint()
if Spearhead.DcsUtil.isPositionInZone(position.x, position.z, farpZoneName) == true then if DcsUtil.isPositionInZone(position.x, position.z, farpZoneName) == true then
table.insert(self._tables.FarpZoneData[farpZoneName].padNames, name) table.insert(self._tables.FarpZoneData[farpZoneName].padNames, name)
end end
end end
@@ -387,7 +394,7 @@ function Database.New(Logger)
for _, cap_route_zone in pairs(self._tables.AllCapRoutes) do for _, cap_route_zone in pairs(self._tables.AllCapRoutes) do
local split = Spearhead.Util.split_string(cap_route_zone, "_") local split = Util.split_string(cap_route_zone, "_")
local zoneID = split[2] local zoneID = split[2]
if zoneID then if zoneID then
@@ -398,7 +405,7 @@ function Database.New(Logger)
} }
end end
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone) local zone = DcsUtil.getZoneByName(cap_route_zone)
if zone then if zone then
table.insert(tables.capZonesByCapZoneID[zoneID].zones, zone) table.insert(tables.capZonesByCapZoneID[zoneID].zones, zone)
end end
@@ -406,7 +413,7 @@ function Database.New(Logger)
end end
for _, interceptZone in pairs(self._tables.AllInterceptZones) do for _, interceptZone in pairs(self._tables.AllInterceptZones) do
local split = Spearhead.Util.split_string(interceptZone, "_") local split = Util.split_string(interceptZone, "_")
local zoneID = split[2] local zoneID = split[2]
if zoneID then if zoneID then
@@ -414,7 +421,7 @@ function Database.New(Logger)
tables.interceptZonesByZoneID[zoneID] = {} tables.interceptZonesByZoneID[zoneID] = {}
end end
local zone = Spearhead.DcsUtil.getZoneByName(interceptZone) local zone = DcsUtil.getZoneByName(interceptZone)
if zone then if zone then
table.insert(tables.interceptZonesByZoneID[zoneID], zone) table.insert(tables.interceptZonesByZoneID[zoneID], zone)
end end
@@ -443,12 +450,12 @@ function Database.New(Logger)
if missions == 0 then missions = 1 end if missions == 0 then missions = 1 end
self._logger:info("initiated the database with amount of zones: ") self._logger:info("initiated the database with amount of zones: ")
self._logger:info("Stages: " .. Spearhead.Util.tableLength(self._tables.StageZones)) self._logger:info("Stages: " .. Util.tableLength(self._tables.StageZones))
self._logger:info("Total Missions: " .. Spearhead.Util.tableLength(self._tables.MissionZoneData)) self._logger:info("Total Missions: " .. Util.tableLength(self._tables.MissionZoneData))
self._logger:info("Average units per mission: " .. totalUnits / missions) self._logger:info("Average units per mission: " .. totalUnits / missions)
self._logger:info("Random Missions: " .. Spearhead.Util.tableLength(self._tables.RandomMissionZones)) self._logger:info("Random Missions: " .. Util.tableLength(self._tables.RandomMissionZones))
self._logger:info("Farps: " .. Spearhead.Util.tableLength(self._tables.AllFarpZones)) self._logger:info("Farps: " .. Util.tableLength(self._tables.AllFarpZones))
self._logger:info("Airbases: " .. Spearhead.Util.tableLength(self._tables.AirbaseDataPerAirfield)) self._logger:info("Airbases: " .. Util.tableLength(self._tables.AirbaseDataPerAirfield))
return self return self
@@ -470,7 +477,7 @@ end
local getAvailableCAPGroups = function() local getAvailableCAPGroups = function()
local result = {} local result = {}
for name, value in pairs(is_group_taken) do for name, value in pairs(is_group_taken) do
if value == false and Spearhead.Util.startswith(name, "CAP") then if value == false and Util.startswith(name, "CAP") then
table.insert(result, name) table.insert(result, name)
end end
end end
@@ -480,7 +487,7 @@ end
---@private ---@private
function Database:initAvailableUnits() function Database:initAvailableUnits()
do do
local all_groups = Spearhead.classes.helpers.MizGroupsManager.getAllGroupNames() local all_groups = MizGroupsManager.getAllGroupNames()
for _, value in pairs(all_groups) do for _, value in pairs(all_groups) do
is_group_taken[value] = false is_group_taken[value] = false
end end
@@ -492,9 +499,9 @@ end
---@return AirbaseData? ---@return AirbaseData?
function Database:getAirbaseDataForDrawLayer(layer_object) function Database:getAirbaseDataForDrawLayer(layer_object)
for _, airbase in pairs(world.getAirbases()) do for _, airbase in pairs(world.getAirbases()) do
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName()) local zone = DcsUtil.getAirbaseZoneByName(airbase:getName())
if zone and Spearhead.Util.is2dPointInZone({ x = layer_object.mapX, y = layer_object.mapY }, zone) == true then if zone and Util.is2dPointInZone({ x = layer_object.mapX, y = layer_object.mapY }, zone) == true then
return self:getOrCreateAirbaseData(airbase:getName()) return self:getOrCreateAirbaseData(airbase:getName())
end end
end end
@@ -555,7 +562,7 @@ function Database:loadCapUnits()
local point = airbase:getPoint() local point = airbase:getPoint()
---@type SpearheadTriggerZone? ---@type SpearheadTriggerZone?
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName()) local zone = DcsUtil.getAirbaseZoneByName(airbase:getName())
if zone == nil then if zone == nil then
zone = { zone = {
@@ -569,15 +576,15 @@ function Database:loadCapUnits()
local baseData = self:getOrCreateAirbaseData(airbase:getName()) local baseData = self:getOrCreateAirbaseData(airbase:getName())
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, zone) local groups = DcsUtil.areGroupsInCustomZone(all_groups, zone)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
is_group_taken[groupName] = true is_group_taken[groupName] = true
if Spearhead.Util.startswith(groupName, "CAP_A", true) or Spearhead.Util.startswith(groupName, "CAP_B", true) then if Util.startswith(groupName, "CAP_A", true) or Util.startswith(groupName, "CAP_B", true) then
table.insert(baseData.CapGroups, groupName) table.insert(baseData.CapGroups, groupName)
elseif Spearhead.Util.startswith(groupName, "CAP_I", true) then elseif Util.startswith(groupName, "CAP_I", true) then
table.insert(baseData.InterceptGroups, groupName) table.insert(baseData.InterceptGroups, groupName)
elseif Spearhead.Util.startswith(groupName, "CAP_S", true) then elseif Util.startswith(groupName, "CAP_S", true) then
table.insert(baseData.SweepGroups, groupName) table.insert(baseData.SweepGroups, groupName)
end end
end end
@@ -588,19 +595,19 @@ end
---@private ---@private
function Database:loadBlueSamUnits() function Database:loadBlueSamUnits()
local all_groups = Spearhead.classes.helpers.MizGroupsManager.getAllGroupNames() local all_groups = MizGroupsManager.getAllGroupNames()
for _, blueSamZone in pairs(self._tables.BlueSams) do for _, blueSamZone in pairs(self._tables.BlueSams) do
local samData = self:getOrCreateBlueSamDataForZone(blueSamZone) local samData = self:getOrCreateBlueSamDataForZone(blueSamZone)
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, blueSamZone) local groups = DcsUtil.getGroupsInZone(all_groups, blueSamZone)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
is_group_taken[groupName] = true is_group_taken[groupName] = true
table.insert(samData.groups, groupName) table.insert(samData.groups, groupName)
end end
local triggerZone = Spearhead.DcsUtil.getZoneByName(blueSamZone) local triggerZone = DcsUtil.getZoneByName(blueSamZone)
if triggerZone then if triggerZone then
for _, kvPair in pairs(triggerZone.properties) do for _, kvPair in pairs(triggerZone.properties) do
if kvPair.key and Spearhead.Util.startswith(kvPair.key, "buildable") then if kvPair.key and Util.startswith(kvPair.key, "buildable") then
local number = tonumber(kvPair.value) local number = tonumber(kvPair.value)
if number and number > 0 then if number and number > 0 then
samData.buildingKilos = number samData.buildingKilos = number
@@ -631,9 +638,9 @@ function Database:LoadZoneData(missionZoneName)
dependsOn = {} dependsOn = {}
} }
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName) local groups = DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then if MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName) local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then if object and object:getCoalition() == coalition.side.RED then
@@ -656,26 +663,26 @@ function Database:LoadZoneData(missionZoneName)
for _, sceneryObject in pairs(self._tables.AllSceneryObjects) do for _, sceneryObject in pairs(self._tables.AllSceneryObjects) do
local point = sceneryObject:GetPoint() local point = sceneryObject:GetPoint()
if point then if point then
if Spearhead.DcsUtil.isPositionInZone(point.x, point.z, missionZoneName) == true then if DcsUtil.isPositionInZone(point.x, point.z, missionZoneName) == true then
table.insert(self._tables.MissionZoneData[missionZoneName].SceneryTargets, sceneryObject) table.insert(self._tables.MissionZoneData[missionZoneName].SceneryTargets, sceneryObject)
end end
end end
end end
-- Check for properties and adds the settings to the mission data -- Check for properties and adds the settings to the mission data
local triggerZone = Spearhead.DcsUtil.getZoneByName(missionZoneName) local triggerZone = DcsUtil.getZoneByName(missionZoneName)
if triggerZone and triggerZone.properties then if triggerZone and triggerZone.properties then
for _, kvPair in pairs(triggerZone.properties) do for _, kvPair in pairs(triggerZone.properties) do
local key = kvPair.key local key = kvPair.key
if Spearhead.Util.startswith(key, "dependson", true) == true then if Util.startswith(key, "dependson", true) == true then
table.insert(self._tables.MissionZoneData[missionZoneName].dependsOn, kvPair.value) table.insert(self._tables.MissionZoneData[missionZoneName].dependsOn, kvPair.value)
elseif Spearhead.Util.startswith(key, "completeat") == true then elseif Util.startswith(key, "completeat") == true then
local value = tonumber(kvPair.value) local value = tonumber(kvPair.value)
if value then if value then
if value > 1 and value <= 100 then if value > 1 and value <= 100 then
value = value / 100 value = value / 100
elseif value > 100 then elseif value > 100 then
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZoneName .. " has a complete at value of " .. value .. " which is higher than 100, this will not work as intended") MissionEditorWarnings.Add("Mission with zonename: " .. missionZoneName .. " has a complete at value of " .. value .. " which is higher than 100, this will not work as intended")
end end
self._tables.MissionZoneData[missionZoneName].completeAt = value self._tables.MissionZoneData[missionZoneName].completeAt = value
end end
@@ -690,8 +697,8 @@ function Database:LoadZoneData(missionZoneName)
for key, layer_object in pairs(layer.objects) do for key, layer_object in pairs(layer.objects) do
local vec2 = { x = layer_object.mapX, y = layer_object.mapY } local vec2 = { x = layer_object.mapX, y = layer_object.mapY }
if triggerZone and Spearhead.Util.is2dPointInZone(vec2, triggerZone) then if triggerZone and Util.is2dPointInZone(vec2, triggerZone) then
if layer_object.name and Spearhead.Util.startswith(layer_object.name, "briefing_", true) then if layer_object.name and Util.startswith(layer_object.name, "briefing_", true) then
local description = layer_object.text local description = layer_object.text
if description and description ~= "" then if description and description ~= "" then
self._tables.MissionZoneData[missionZoneName].description = description self._tables.MissionZoneData[missionZoneName].description = description
@@ -725,16 +732,16 @@ function Database:loadFarpData()
for _, farpZone in pairs(self._tables.AllFarpZones) do for _, farpZone in pairs(self._tables.AllFarpZones) do
local farpzoneData = self:getOrCreateFarpDataForZone(farpZone) local farpzoneData = self:getOrCreateFarpDataForZone(farpZone)
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, farpZone) local groups = DcsUtil.getGroupsInZone(all_groups, farpZone)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
is_group_taken[groupName] = true is_group_taken[groupName] = true
table.insert(farpzoneData.groups, groupName) table.insert(farpzoneData.groups, groupName)
end end
local triggerZone = Spearhead.DcsUtil.getZoneByName(farpZone) local triggerZone = DcsUtil.getZoneByName(farpZone)
if triggerZone then if triggerZone then
for _, kvPair in pairs(triggerZone.properties) do for _, kvPair in pairs(triggerZone.properties) do
if kvPair.key and Spearhead.Util.startswith(kvPair.key, "buildable", true) == true then if kvPair.key and Util.startswith(kvPair.key, "buildable", true) == true then
local number = tonumber(kvPair.value) local number = tonumber(kvPair.value)
if number and number > 0 then if number and number > 0 then
farpzoneData.buildingKilos = number farpzoneData.buildingKilos = number
@@ -754,7 +761,7 @@ function Database:loadAirbaseGroups()
if base then if base then
local basedata = self:getOrCreateAirbaseData(baseName) local basedata = self:getOrCreateAirbaseData(baseName)
local point = base:getPoint() local point = base:getPoint()
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(baseName) local airbaseZone = DcsUtil.getAirbaseZoneByName(baseName)
if airbaseZone == nil then if airbaseZone == nil then
airbaseZone = { airbaseZone = {
@@ -768,9 +775,9 @@ function Database:loadAirbaseGroups()
if airbaseZone and base:getDesc().category == Airbase.Category.AIRDROME then if airbaseZone and base:getDesc().category == Airbase.Category.AIRDROME then
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, airbaseZone) local groups = DcsUtil.areGroupsInCustomZone(all_groups, airbaseZone)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then if MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName) local object = StaticObject.getByName(groupName)
if object then if object then
if object:getCoalition() == coalition.side.RED then if object:getCoalition() == coalition.side.RED then
@@ -806,9 +813,9 @@ function Database:loadMiscGroupsInStages()
for _, stageZone in pairs(self._tables.StageZones) do for _, stageZone in pairs(self._tables.StageZones) do
stageZone.MiscGroups = {} stageZone.MiscGroups = {}
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, stageZone.StageZoneName) local groups = DcsUtil.getGroupsInZone(all_groups, stageZone.StageZoneName)
for _, groupName in pairs(groups) do for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then if MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName) local object = StaticObject.getByName(groupName)
if object and object:getCoalition() ~= coalition.side.NEUTRAL then if object and object:getCoalition() ~= coalition.side.NEUTRAL then
is_group_taken[groupName] = true is_group_taken[groupName] = true
@@ -846,14 +853,14 @@ function Database:GetCapZoneForZoneID(zoneID)
if capZonesForID and capZonesForID.zones then if capZonesForID and capZonesForID.zones then
local count = Spearhead.Util.tableLength(capZonesForID.zones) local count = Util.tableLength(capZonesForID.zones)
if count == 0 then if count == 0 then
self._logger:warn("Tried to get cap zone for zoneID: " .. zoneID .. " but cap zones were empty for this ID") self._logger:warn("Tried to get cap zone for zoneID: " .. zoneID .. " but cap zones were empty for this ID")
return nil return nil
end end
capZonesForID.current = capZonesForID.current + 1 capZonesForID.current = capZonesForID.current + 1
if Spearhead.Util.tableLength(capZonesForID.zones) < capZonesForID.current then if Util.tableLength(capZonesForID.zones) < capZonesForID.current then
capZonesForID.current = 1 capZonesForID.current = 1
end end
return capZonesForID.zones[capZonesForID.current] return capZonesForID.zones[capZonesForID.current]
+9 -7
View File
@@ -1,3 +1,7 @@
local Logger = require("classes.util.Logger")
local Persistence = require("classes.persistence.Persistence")
local DcsUtil = require("classes.util.DcsUtil")
---@class SpearheadEvents ---@class SpearheadEvents
local SpearheadEvents = {} local SpearheadEvents = {}
do do
@@ -7,10 +11,9 @@ do
---@param logLevel LogLevel ---@param logLevel LogLevel
SpearheadEvents.Init = function(logLevel) SpearheadEvents.Init = function(logLevel)
logger = Spearhead.LoggerTemplate.new("Events", logLevel) logger = Logger.new("Events", logLevel)
end end
local warn = function(text) local warn = function(text)
if logger then if logger then
logger:warn(text) logger:warn(text)
@@ -50,7 +53,7 @@ do
---@param newStageNumber number ---@param newStageNumber number
SpearheadEvents.PublishStageNumberChanged = function(newStageNumber) SpearheadEvents.PublishStageNumberChanged = function(newStageNumber)
pcall(function () pcall(function ()
Spearhead.classes.persistence.Persistence.SetActiveStage(newStageNumber) Persistence.SetActiveStage(newStageNumber)
end) end)
for _, callable in pairs(OnStageNumberChangedListeners) do for _, callable in pairs(OnStageNumberChangedListeners) do
@@ -68,8 +71,7 @@ do
logError(err) logError(err)
end end
end end
Spearhead.LoggerTemplate.new("Events", "INFO"):info("Published stage number changed to: " .. tostring(newStageNumber)) Logger.new("Events", "INFO"):info("Published stage number changed to: " .. tostring(newStageNumber))
Spearhead.StageNumber = newStageNumber
end end
end end
@@ -349,7 +351,7 @@ do
end end
if event.id == world.event.S_EVENT_MISSION_END then if event.id == world.event.S_EVENT_MISSION_END then
Spearhead.classes.persistence.Persistence.UpdateNow() Persistence.UpdateNow()
end end
local AI_GROUPS = {} local AI_GROUPS = {}
@@ -370,7 +372,7 @@ do
return false return false
end end
local players = Spearhead.DcsUtil.getAllPlayerUnits() local players = DcsUtil.getAllPlayerUnits()
local unitName = unit:getName() local unitName = unit:getName()
for i, unit in pairs(players) do for i, unit in pairs(players) do
if unit:getName() == unitName then if unit:getName() == unitName then
+7 -4
View File
@@ -1,3 +1,6 @@
local DcsUtil = require("classes.util.DcsUtil")
local Util = require("classes.util.Util")
---@class SpearheadRouteUtil ---@class SpearheadRouteUtil
local ROUTE_UTIL = {} local ROUTE_UTIL = {}
do --setup route util do --setup route util
@@ -23,7 +26,7 @@ do --setup route util
---@return table task ---@return table task
local RtbTask = function(airdromeId, basePoint, speed) local RtbTask = function(airdromeId, basePoint, speed)
if basePoint == nil then if basePoint == nil then
basePoint = Spearhead.Util.getAirbaseById(airdromeId):getPoint() basePoint = DcsUtil.getAirbaseById(airdromeId):getPoint()
end end
return { return {
@@ -215,7 +218,7 @@ do --setup route util
---@param deviationDistance number ---@param deviationDistance number
---@return table? route ---@return table? route
ROUTE_UTIL.createCapMission = function(groupName, airdromeId, capPoint, racetrackSecondPoint, altitude, speed, durationOnStation, attackHelos, deviationDistance) ROUTE_UTIL.createCapMission = function(groupName, airdromeId, capPoint, racetrackSecondPoint, altitude, speed, durationOnStation, attackHelos, deviationDistance)
local baseName = Spearhead.DcsUtil.getAirbaseName(airdromeId) local baseName = DcsUtil.getAirbaseName(airdromeId)
if baseName == nil then if baseName == nil then
return nil return nil
end end
@@ -295,7 +298,7 @@ do --setup route util
TODO: Test the creation and pubishing of event and the timing of said event TODO: Test the creation and pubishing of event and the timing of said event
]] -- ]] --
local base = Spearhead.DcsUtil.getAirbaseById(airdromeId) local base = DcsUtil.getAirbaseById(airdromeId)
if base == nil then if base == nil then
return nil, "No airbase found for ID " .. tostring(airdromeId) return nil, "No airbase found for ID " .. tostring(airdromeId)
end end
@@ -308,7 +311,7 @@ do --setup route util
end end
local units = group:getUnits() local units = group:getUnits()
while pos == nil and i <= Spearhead.Util.tableLength(units) do while pos == nil and i <= Util.tableLength(units) do
local unit = units[i] local unit = units[i]
if unit and unit:isExist() == true and unit:inAir() == true then if unit and unit:isExist() == true and unit:inAir() == true then
pos = unit:getPoint() pos = unit:getPoint()
+30 -23
View File
@@ -1,4 +1,11 @@
local Events = require("classes.spearhead_events")
local Util = require("classes.util.Util")
local Logger = require("classes.util.Logger")
local MissionEditorWarnings = require("classes.util.MissionEditorWarnings")
local ExtraStage = require("classes.stageClasses.Stages.ExtraStage")
local PrimaryStage = require("classes.stageClasses.Stages.PrimaryStage")
local WaitingStage = require("classes.stageClasses.Stages.WaitingStage")
local StagesByName = {} local StagesByName = {}
@@ -29,7 +36,7 @@ GlobalStageManager.getCurrentStage = function() return currentStage end
---@param spawnManager SpawnManager ---@param spawnManager SpawnManager
---@return nil ---@return nil
function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnManager) function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnManager)
local logger = Spearhead.LoggerTemplate.new("StageManager", logLevel) local logger = Logger.new("StageManager", logLevel)
logger:info("Using Stage Log Level: " .. logLevel) logger:info("Using Stage Log Level: " .. logLevel)
local self = setmetatable({}, GlobalStageManager) local self = setmetatable({}, GlobalStageManager)
self.database = database self.database = database
@@ -48,28 +55,28 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
} }
Spearhead.Events.AddStageNumberChangedListener(OnStageNumberChangedListener) Events.AddStageNumberChangedListener(OnStageNumberChangedListener)
for _, stageName in pairs(database:getStagezoneNames()) do for _, stageName in pairs(database:getStagezoneNames()) do
logger:debug("Found stage zone with name: " .. stageName) logger:debug("Found stage zone with name: " .. stageName)
if Spearhead.Util.startswith(stageName, "missionstage", true) then if Util.startswith(stageName, "missionstage", true) then
local valid = true local valid = true
local split = Spearhead.Util.split_string(stageName, "_") local split = Util.split_string(stageName, "_")
if Spearhead.Util.tableLength(split) < 2 then if Util.tableLength(split) < 2 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a order number or valid format") MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a order number or valid format")
valid = false valid = false
end end
if Spearhead.Util.tableLength(split) < 3 then if Util.tableLength(split) < 3 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a stage name") MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a stage name")
end end
local orderNumber = nil local orderNumber = nil
local isSideStage = false local isSideStage = false
if valid == true then if valid == true then
local orderNumberString = string.lower(split[2]) local orderNumberString = string.lower(split[2])
if Spearhead.Util.startswith(orderNumberString, "x") == true then if Util.startswith(orderNumberString, "x") == true then
isSideStage = true isSideStage = true
orderNumberString = string.gsub(orderNumberString, "x", "") orderNumberString = string.gsub(orderNumberString, "x", "")
@@ -79,13 +86,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
end end
if orderNumber == nil then if orderNumber == nil then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a valid order number : " .. split[2]) MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a valid order number : " .. split[2])
valid = false valid = false
end end
end end
local stageDisplayName = split[3] local stageDisplayName = split[3]
local stagelogger = Spearhead.LoggerTemplate.new(stageName, logLevel) local stagelogger = Logger.new(stageName, logLevel)
if valid == true and orderNumber then if valid == true and orderNumber then
---@type StageInitData ---@type StageInitData
@@ -96,13 +103,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
} }
if isSideStage == true then if isSideStage == true then
local stage = Spearhead.classes.stageClasses.Stages.ExtraStage.New(database, stageConfig, stagelogger, initData, spawnManager) local stage = ExtraStage.New(database, stageConfig, stagelogger, initData, spawnManager)
stage:AddStageCompleteListener(self) stage:AddStageCompleteListener(self)
if SideStageByIndex[tostring(orderNumber)] == nil then SideStageByIndex[tostring(orderNumber)] = {} end if SideStageByIndex[tostring(orderNumber)] == nil then SideStageByIndex[tostring(orderNumber)] = {} end
table.insert(SideStageByIndex[tostring(orderNumber)], stage) table.insert(SideStageByIndex[tostring(orderNumber)], stage)
else else
local stage = Spearhead.classes.stageClasses.Stages.PrimaryStage.New(database, stageConfig, stagelogger, initData, spawnManager) local stage = PrimaryStage.New(database, stageConfig, stagelogger, initData, spawnManager)
stage:AddStageCompleteListener(self) stage:AddStageCompleteListener(self)
if StagesByIndex[tostring(orderNumber)] == nil then StagesByIndex[tostring(orderNumber)] = {} end if StagesByIndex[tostring(orderNumber)] == nil then StagesByIndex[tostring(orderNumber)] = {} end
@@ -111,13 +118,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
end end
end end
if Spearhead.Util.startswith(stageName, "waitingstage", true) then if Util.startswith(stageName, "waitingstage", true) then
local valid = true local valid = true
local split = Spearhead.Util.split_string(stageName, "_") local split = Util.split_string(stageName, "_")
if Spearhead.Util.tableLength(split) < 3 then if Util.tableLength(split) < 3 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a order number or valid format") MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a order number or valid format")
valid = false valid = false
end end
@@ -126,19 +133,19 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
local stageIndex = tonumber(stageIndexString) local stageIndex = tonumber(stageIndexString)
if not stageIndex then if not stageIndex then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a valid order number") MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a valid order number")
valid = false valid = false
end end
local waitingSecondsString = split[3] local waitingSecondsString = split[3]
local waitingSeconds = tonumber(waitingSecondsString) local waitingSeconds = tonumber(waitingSecondsString)
if not waitingSeconds then if not waitingSeconds then
Spearhead.AddMissionEditorWarning("Waiting Stage zone with name " .. stageName .. " does not have a valid amount of seconds parameter") MissionEditorWarnings.Add("Waiting Stage zone with name " .. stageName .. " does not have a valid amount of seconds parameter")
valid = false valid = false
end end
if valid == true then if valid == true then
local stagelogger = Spearhead.LoggerTemplate.new(stageName, logLevel) local stagelogger = Logger.new(stageName, logLevel)
---@type WaitingStageInitData ---@type WaitingStageInitData
local initData = { local initData = {
@@ -147,7 +154,7 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
stageZoneName = stageName, stageZoneName = stageName,
waitingSeconds = waitingSeconds --[[@as integer]] waitingSeconds = waitingSeconds --[[@as integer]]
} }
local waitingStage = Spearhead.classes.stageClasses.Stages.WaitingStage.New(database, stageConfig, stagelogger, initData, spawnManager) local waitingStage = WaitingStage.New(database, stageConfig, stagelogger, initData, spawnManager)
if WaitingStagesByIndex[tostring(stageIndex)] == nil then if WaitingStagesByIndex[tostring(stageIndex)] == nil then
WaitingStagesByIndex[tostring(stageIndex)] = {} WaitingStagesByIndex[tostring(stageIndex)] = {}
@@ -203,7 +210,7 @@ function GlobalStageManager:OnStageComplete(stage)
local newStageNumber = currentStage + 1 local newStageNumber = currentStage + 1
self:UpdateDrawings(newStageNumber) self:UpdateDrawings(newStageNumber)
self.logger:debug("Setting next stage to: " .. tostring(newStageNumber)) self.logger:debug("Setting next stage to: " .. tostring(newStageNumber))
Spearhead.Events.PublishStageNumberChanged(newStageNumber) Events.PublishStageNumberChanged(newStageNumber)
end end
end end
end end
@@ -224,7 +231,7 @@ end
GlobalStageManager.printFullOverview = function () GlobalStageManager.printFullOverview = function ()
local logger = Spearhead.LoggerTemplate.new("StageOverview", "INFO") local logger = Logger.new("StageOverview", "INFO")
logger:info("Stage overview:") logger:info("Stage overview:")
local max = 0 local max = 0
@@ -1,3 +1,7 @@
local BuildableZone = require("classes.stageClasses.SpecialZones.abstract.BuildableZone")
local SpearheadGroup = require("classes.stageClasses.Groups.SpearheadGroup")
local Util = require("classes.util.Util")
local DcsUtil = require("classes.util.DcsUtil")
---@class BlueSam : BuildableZone ---@class BlueSam : BuildableZone
---@field Activate fun(self: BlueSam) ---@field Activate fun(self: BlueSam)
@@ -20,7 +24,7 @@ BlueSam.__index = BlueSam
---@return BlueSam? ---@return BlueSam?
function BlueSam.New(database, logger, zoneName, spawnManager) function BlueSam.New(database, logger, zoneName, spawnManager)
setmetatable(BlueSam, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone) setmetatable(BlueSam, BuildableZone)
local self = setmetatable({}, BlueSam) local self = setmetatable({}, BlueSam)
self._database = database self._database = database
@@ -53,39 +57,39 @@ function BlueSam.New(database, logger, zoneName, spawnManager)
end end
for _, groupName in pairs(blueSamData.groups) do for _, groupName in pairs(blueSamData.groups) do
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true) local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
if SpearheadGroup then if spearheadGroup then
if SpearheadGroup:GetCoalition() == 2 or SpearheadGroup:GetCoalition() == 0 then if spearheadGroup:GetCoalition() == 2 or spearheadGroup:GetCoalition() == 0 then
table.insert(self._blueGroups, SpearheadGroup) table.insert(self._blueGroups, spearheadGroup)
end end
for _, unit in pairs(SpearheadGroup:GetObjects()) do for _, unit in pairs(spearheadGroup:GetObjects()) do
if SpearheadGroup:GetCoalition() == 1 then if spearheadGroup:GetCoalition() == 1 then
table.insert(blueUnitsPos, unit:getPoint()) table.insert(blueUnitsPos, unit:getPoint())
elseif SpearheadGroup:GetCoalition() == 2 then elseif spearheadGroup:GetCoalition() == 2 then
table.insert(redUnitsPos, unit:getPoint()) table.insert(redUnitsPos, unit:getPoint())
end end
end end
end end
SpearheadGroup:Destroy() spearheadGroup:Destroy()
end end
--Cleanup units --Cleanup units
local cleanup_distance = 5 local cleanup_distance = 5
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do
for redUnitName, redUnitPos in pairs(redUnitsPos) do for redUnitName, redUnitPos in pairs(redUnitsPos) do
local distance = Spearhead.Util.VectorDistance3d(blueUnitPos, redUnitPos) local distance = Util.VectorDistance3d(blueUnitPos, redUnitPos)
if distance <= cleanup_distance then if distance <= cleanup_distance then
self._cleanupUnits[redUnitName] = true self._cleanupUnits[redUnitName] = true
end end
end end
end end
local zone = Spearhead.DcsUtil.getZoneByName(zoneName) local zone = DcsUtil.getZoneByName(zoneName)
if zone then if zone then
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, self._buildableCrateKilos or 0, "SAM_CRATE", self._blueGroups, logger, database) BuildableZone.New(self, zone, self._buildableCrateKilos or 0, "SAM_CRATE", self._blueGroups, logger, database)
end end
return self return self
@@ -104,9 +108,9 @@ function BlueSam:GetNoLandingZone()
end end
end end
local vecs = Spearhead.Util.getConvexHull(points) local vecs = Util.getConvexHull(points)
local zone = Spearhead.DcsUtil.getZoneByName(self._zoneName) local zone = DcsUtil.getZoneByName(self._zoneName)
if zone == nil then if zone == nil then
self._logger:error("Zone not found: " .. self._zoneName) self._logger:error("Zone not found: " .. self._zoneName)
return nil return nil
@@ -136,7 +140,7 @@ end
function BlueSam:SpawnGroups() function BlueSam:SpawnGroups()
for unitName, needsCleanup in pairs(self._cleanupUnits) do for unitName, needsCleanup in pairs(self._cleanupUnits) do
Spearhead.DcsUtil.DestroyUnit(unitName) DcsUtil.DestroyUnit(unitName)
end end
for _, group in pairs(self._blueGroups) do for _, group in pairs(self._blueGroups) do
@@ -1,4 +1,8 @@
local BuildableZone = require("classes.stageClasses.SpecialZones.abstract.BuildableZone")
local Util = require("classes.util.Util")
local DcsUtil = require("classes.util.DcsUtil")
local SupplyHub = require("classes.stageClasses.SpecialZones.SupplyHub")
local SpearheadGroup = require("classes.stageClasses.Groups.SpearheadGroup")
---@class FarpZone: BuildableZone ---@class FarpZone: BuildableZone
---@field private _startingFarp boolean ---@field private _startingFarp boolean
@@ -18,14 +22,14 @@ FarpZone.__index = FarpZone
---@param spawnManager SpawnManager ---@param spawnManager SpawnManager
---@return FarpZone ---@return FarpZone
function FarpZone.New(database, logger, zoneName, spawnManager) function FarpZone.New(database, logger, zoneName, spawnManager)
setmetatable(FarpZone, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone) setmetatable(FarpZone, BuildableZone)
local self = setmetatable({}, FarpZone) local self = setmetatable({}, FarpZone)
self._database = database self._database = database
self._logger = logger self._logger = logger
self._zoneName = zoneName self._zoneName = zoneName
local split = Spearhead.Util.split_string(zoneName, "_") local split = Util.split_string(zoneName, "_")
if string.lower(split[2]) == "a" then if string.lower(split[2]) == "a" then
self._startingFarp = true self._startingFarp = true
else else
@@ -44,7 +48,7 @@ function FarpZone.New(database, logger, zoneName, spawnManager)
self._padNames = farpData.padNames self._padNames = farpData.padNames
for _, supplyHubName in pairs(farpData.supplyHubNames) do for _, supplyHubName in pairs(farpData.supplyHubNames) do
local supplyHub = Spearhead.classes.stageClasses.SpecialZones.SupplyHub.new(database, logger, supplyHubName) local supplyHub = SupplyHub.new(database, logger, supplyHubName)
if supplyHub then if supplyHub then
table.insert(self._supplyHubs, supplyHub) table.insert(self._supplyHubs, supplyHub)
end end
@@ -52,15 +56,15 @@ function FarpZone.New(database, logger, zoneName, spawnManager)
for _, groupName in pairs(farpData.groups) do for _, groupName in pairs(farpData.groups) do
local group = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true) local group = SpearheadGroup.New(groupName, spawnManager, true)
table.insert(self._groups, group) table.insert(self._groups, group)
group:Destroy() group:Destroy()
end end
local zone = Spearhead.DcsUtil.getZoneByName(zoneName) local zone = DcsUtil.getZoneByName(zoneName)
if zone then if zone then
self._logger:debug("Creating Buildable zone: " .. zoneName .. " with " .. (farpData.buildingKilos or "nil") .. " kilos") self._logger:debug("Creating Buildable zone: " .. zoneName .. " with " .. (farpData.buildingKilos or "nil") .. " kilos")
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, farpData.buildingKilos or 0, "FARP_CRATE", self._groups, logger, database) BuildableZone.New(self, zone, farpData.buildingKilos or 0, "FARP_CRATE", self._groups, logger, database)
end end
end end
self:Deactivate() self:Deactivate()
@@ -1,3 +1,9 @@
local BuildableZone = require("classes.stageClasses.SpecialZones.abstract.BuildableZone")
local DcsUtil = require("classes.util.DcsUtil")
local SpearheadGroup = require("classes.stageClasses.Groups.SpearheadGroup")
local SupplyHub = require("classes.stageClasses.SpecialZones.SupplyHub")
local Util = require("classes.util.Util")
---@class StageBase : BuildableZone ---@class StageBase : BuildableZone
---@field private _database Database ---@field private _database Database
---@field private _logger Logger ---@field private _logger Logger
@@ -21,7 +27,7 @@ StageBase.__index = StageBase
---@param spawnManager SpawnManager ---@param spawnManager SpawnManager
---@return StageBase? ---@return StageBase?
function StageBase.New(databaseManager, logger, airbaseName, spawnManager) function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
setmetatable(StageBase, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone) setmetatable(StageBase, BuildableZone)
local self = setmetatable({}, StageBase) local self = setmetatable({}, StageBase)
self._database = databaseManager self._database = databaseManager
@@ -33,7 +39,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
self._supplyHubs = {} self._supplyHubs = {}
self._airbase = Airbase.getByName(airbaseName) self._airbase = Airbase.getByName(airbaseName)
self._initialSide = Spearhead.DcsUtil.getStartingCoalition(self._airbase) self._initialSide = DcsUtil.getStartingCoalition(self._airbase)
do --init do --init
local airbaseData = databaseManager:getAirbaseDataForZone(airbaseName) local airbaseData = databaseManager:getAirbaseDataForZone(airbaseName)
@@ -49,7 +55,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
local blueUnitsPos = {} local blueUnitsPos = {}
for _, groupName in pairs(airbaseData.RedGroups) do for _, groupName in pairs(airbaseData.RedGroups) do
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true) local shGroup = SpearheadGroup.New(groupName, spawnManager, true)
table.insert(self._red_groups, shGroup) table.insert(self._red_groups, shGroup)
for _, unit in pairs(shGroup:GetObjects()) do for _, unit in pairs(shGroup:GetObjects()) do
@@ -60,7 +66,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end end
for _, groupName in pairs(airbaseData.BlueGroups) do for _, groupName in pairs(airbaseData.BlueGroups) do
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true) local shGroup = SpearheadGroup.New(groupName, spawnManager, true)
table.insert(self._blue_groups, shGroup) table.insert(self._blue_groups, shGroup)
for _, unit in pairs(shGroup:GetObjects()) do for _, unit in pairs(shGroup:GetObjects()) do
@@ -71,7 +77,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end end
for _, supplyHubName in pairs(airbaseData.supplyHubNames) do for _, supplyHubName in pairs(airbaseData.supplyHubNames) do
local supplyHub = Spearhead.classes.stageClasses.SpecialZones.SupplyHub.new(databaseManager, logger, local supplyHub = SupplyHub.new(databaseManager, logger,
supplyHubName) supplyHubName)
if supplyHub then if supplyHub then
table.insert(self._supplyHubs, supplyHub) table.insert(self._supplyHubs, supplyHub)
@@ -86,7 +92,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do
for redUnitName, redUnitPos in pairs(redUnitsPos) do for redUnitName, redUnitPos in pairs(redUnitsPos) do
local distance = Spearhead.Util.VectorDistance3d(blueUnitPos, redUnitPos) local distance = Util.VectorDistance3d(blueUnitPos, redUnitPos)
if distance <= cleanup_distance then if distance <= cleanup_distance then
self._cleanup_units[redUnitName] = true self._cleanup_units[redUnitName] = true
end end
@@ -94,9 +100,9 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end end
end end
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbaseName) local zone = DcsUtil.getAirbaseZoneByName(airbaseName)
if zone then if zone then
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, airbaseData.buildingKilos or 0, "AIRBASE_CRATE", self._blue_groups, logger, databaseManager) BuildableZone.New(self, zone, airbaseData.buildingKilos or 0, "AIRBASE_CRATE", self._blue_groups, logger, databaseManager)
end end
end end
@@ -126,8 +132,8 @@ function StageBase:CleanRedUnits()
for unitName, shouldClean in pairs(self._cleanup_units) do for unitName, shouldClean in pairs(self._cleanup_units) do
if shouldClean == true then if shouldClean == true then
Spearhead.DcsUtil.DestroyUnit(unitName) DcsUtil.DestroyUnit(unitName)
Spearhead.DcsUtil.CleanCorpse(unitName) DcsUtil.CleanCorpse(unitName)
end end
end end
end end
@@ -1,3 +1,8 @@
local Util = require("classes.util.Util")
local DcsUtil = require("classes.util.DcsUtil")
local SupplyUnitsTracker = require("classes.stageClasses.helpers.SupplyUnitsTracker")
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
---@class SupplyHub ---@class SupplyHub
---@field private _database Database ---@field private _database Database
---@field private _logger Logger ---@field private _logger Logger
@@ -26,18 +31,18 @@ function SupplyHub.new(database, logger, zoneName)
self._logger = logger self._logger = logger
self._zoneName = zoneName self._zoneName = zoneName
local split = Spearhead.Util.split_string(zoneName, "_") local split = Util.split_string(zoneName, "_")
if string.lower(split[2]) == "a" then if string.lower(split[2]) == "a" then
self._activeAtStart = true self._activeAtStart = true
else else
self._activeAtStart = false self._activeAtStart = false
end end
self._zone = Spearhead.DcsUtil.getZoneByName(zoneName) self._zone = DcsUtil.getZoneByName(zoneName)
self._supplyUnitsTracker = Spearhead.classes.stageClasses.helpers.SupplyUnitsTracker.getOrCreate(logger.LogLevel) self._supplyUnitsTracker = SupplyUnitsTracker.getOrCreate(logger.LogLevel)
self._inZone = {} self._inZone = {}
self._missionCommandsHelper = Spearhead.classes.stageClasses.helpers.MissionCommandsHelper.getOrCreate(logger.LogLevel) self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
self._logger:debug("Creating Supply Hub zone: " .. self._zoneName) self._logger:debug("Creating Supply Hub zone: " .. self._zoneName)
@@ -66,14 +71,14 @@ function SupplyHub:Activate()
self._logger:debug("Activating Supply Hub zone: " .. self._zoneName) self._logger:debug("Activating Supply Hub zone: " .. self._zoneName)
local zone = Spearhead.DcsUtil.getZoneByName(self._zoneName) local zone = DcsUtil.getZoneByName(self._zoneName)
if zone and self._drawID == nil then if zone and self._drawID == nil then
---@type DrawColor ---@type DrawColor
local fillColor = { r=0, g=1, b=0, a=0.2 } local fillColor = { r=0, g=1, b=0, a=0.2 }
---@type DrawColor ---@type DrawColor
local lineColor = { r=0, g=1, b=0, a=1} local lineColor = { r=0, g=1, b=0, a=1}
local lineStyle = 1 local lineStyle = 1
self._drawID = Spearhead.DcsUtil.DrawZone(zone, lineColor, fillColor, lineStyle) self._drawID = DcsUtil.DrawZone(zone, lineColor, fillColor, lineStyle)
end end
self._supplyUnitsTracker:RegisterHub(self) self._supplyUnitsTracker:RegisterHub(self)
@@ -1,3 +1,6 @@
local Util = require("classes.util.Util")
local Persistence = require("classes.persistence.Persistence")
local BuildableMission = require("classes.stageClasses.missions.BuildableMission")
---@class BuildableZone : OnCrateDroppedListener ---@class BuildableZone : OnCrateDroppedListener
---@field protected _targetZone SpearheadTriggerZone ---@field protected _targetZone SpearheadTriggerZone
@@ -22,11 +25,11 @@ function BuildableZone:New(targetZone, kilosRequired, crateType, buildableGroup
self._requiredKilos = kilosRequired or 0 self._requiredKilos = kilosRequired or 0
self._buildableGroups = buildableGroups or {} self._buildableGroups = buildableGroups or {}
self._buildableLogger = logger self._buildableLogger = logger
local totalGroups = Spearhead.Util.tableLength(self._buildableGroups) local totalGroups = Util.tableLength(self._buildableGroups)
self._groupsPerKilo = totalGroups / self._requiredKilos self._groupsPerKilo = totalGroups / self._requiredKilos
self._receivedBuildingKilos = 0 self._receivedBuildingKilos = 0
local persistedKilos = Spearhead.classes.persistence.Persistence.GetZoneDeliveredKilos(targetZone.name) local persistedKilos = Persistence.GetZoneDeliveredKilos(targetZone.name)
if persistedKilos and persistedKilos > 0 then if persistedKilos and persistedKilos > 0 then
self._buildableLogger:debug("Zone " .. targetZone.name .. " already has " .. persistedKilos .. " kilos delivered") self._buildableLogger:debug("Zone " .. targetZone.name .. " already has " .. persistedKilos .. " kilos delivered")
self._receivedBuildingKilos = persistedKilos self._receivedBuildingKilos = persistedKilos
@@ -66,7 +69,7 @@ function BuildableZone:New(targetZone, kilosRequired, crateType, buildableGroup
local noLandingZone = self:GetNoLandingZone() local noLandingZone = self:GetNoLandingZone()
if kilosRequired and kilosRequired > 0 then if kilosRequired and kilosRequired > 0 then
self._buildableMission = Spearhead.classes.stageClasses.missions.BuildableMission.new(database, logger, targetZone, noLandingZone, kilosRequired, crateType) self._buildableMission = BuildableMission.new(database, logger, targetZone, noLandingZone, kilosRequired, crateType)
self._buildableMission:AddOnCrateDroppedOfListener(self) self._buildableMission:AddOnCrateDroppedOfListener(self)
else else
self._buildableMission = nil self._buildableMission = nil
@@ -138,7 +141,7 @@ end
---@param kilos number ---@param kilos number
function BuildableZone:FinaliseCrate(kilos) function BuildableZone:FinaliseCrate(kilos)
self._receivedBuildingKilos = self._receivedBuildingKilos + kilos self._receivedBuildingKilos = self._receivedBuildingKilos + kilos
Spearhead.classes.persistence.Persistence.SetZoneDeliveredKilos(self._targetZone.name, self._receivedBuildingKilos) Persistence.SetZoneDeliveredKilos(self._targetZone.name, self._receivedBuildingKilos)
if self._receivedBuildingKilos >= self._requiredKilos then if self._receivedBuildingKilos >= self._requiredKilos then
self:OnBuildingComplete() self:OnBuildingComplete()
end end
@@ -157,7 +160,7 @@ function BuildableZone:GetNoLandingZone()
end end
end end
local vecs = Spearhead.Util.getConvexHull(points) local vecs = Util.getConvexHull(points)
---@type SpearheadTriggerZone ---@type SpearheadTriggerZone
local spearheadZone = { local spearheadZone = {
@@ -1,3 +1,16 @@
local SpearheadGroup = require("classes.stageClasses.Groups.SpearheadGroup")
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
local DcsUtil = require("classes.util.DcsUtil")
local FarpZone = require("classes.stageClasses.SpecialZones.FarpZone")
local SupplyHub = require("classes.stageClasses.SpecialZones.SupplyHub")
local Util = require("classes.util.Util")
local ZoneMission = require("classes.stageClasses.missions.ZoneMission")
local MissionEditorWarnings = require("classes.util.MissionEditorWarnings")
local Persistence = require("classes.persistence.Persistence")
local StageBase = require("classes.stageClasses.SpecialZones.StageBase")
local BlueSam = require("classes.stageClasses.SpecialZones.BlueSam")
local Events = require("classes.spearhead_events")
local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
---@alias StageColor ---@alias StageColor
---| "RED" ---| "RED"
@@ -71,8 +84,6 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName) logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup
self.zoneName = initData.stageZoneName self.zoneName = initData.stageZoneName
self.stageNumber = initData.stageNumber self.stageNumber = initData.stageNumber
self._isActive = false self._isActive = false
@@ -101,11 +112,11 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
self._activeStage = -99 self._activeStage = -99
self._preActivated = false self._preActivated = false
self._stageConfig = stageConfig or {} self._stageConfig = stageConfig or {}
self._missionCommandsHelper = Spearhead.classes.stageClasses.helpers.MissionCommandsHelper.getOrCreate(logger.LogLevel) self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
local zone = Spearhead.DcsUtil.getZoneByName(self.zoneName) local zone = DcsUtil.getZoneByName(self.zoneName)
if zone then if zone then
self._stageDrawingId = Spearhead.DcsUtil.DrawZone(zone, Stage.StageColors.INVISIBLE, Stage.StageColors.INVISIBLE, 4) self._stageDrawingId = DcsUtil.DrawZone(zone, Stage.StageColors.INVISIBLE, Stage.StageColors.INVISIBLE, 4)
end end
self._spawnedGroups = {} self._spawnedGroups = {}
@@ -114,13 +125,13 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
local farpNames = database:getFarpNamesInStage(self.zoneName) local farpNames = database:getFarpNamesInStage(self.zoneName)
for _, farpName in pairs(farpNames) do for _, farpName in pairs(farpNames) do
local farp = Spearhead.classes.stageClasses.SpecialZones.FarpZone.New(database, logger, farpName, spawnManager) local farp = FarpZone.New(database, logger, farpName, spawnManager)
table.insert(self._db.farps, farp) table.insert(self._db.farps, farp)
end end
local supplyHubNames = database:getSupplyHubsInStage(self.zoneName) local supplyHubNames = database:getSupplyHubsInStage(self.zoneName)
for _, supplyHubName in pairs(supplyHubNames) do for _, supplyHubName in pairs(supplyHubNames) do
local supplyHub = Spearhead.classes.stageClasses.SpecialZones.SupplyHub.new(database, logger, supplyHubName) local supplyHub = SupplyHub.new(database, logger, supplyHubName)
table.insert(self._db.supplyHubs, supplyHub) table.insert(self._db.supplyHubs, supplyHub)
end end
@@ -144,17 +155,17 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
do -- load tables do -- load tables
local missionZones = database:getMissionsForStage(self.zoneName) local missionZones = database:getMissionsForStage(self.zoneName)
self._logger:debug("Found " .. Spearhead.Util.tableLength(missionZones) .. " mission zones for stage: " .. self.zoneName) self._logger:debug("Found " .. Util.tableLength(missionZones) .. " mission zones for stage: " .. self.zoneName)
for _, missionZone in pairs(missionZones) do for _, missionZone in pairs(missionZones) do
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZone, self._missionPriority, database, logger, self, spawnManager) local mission = ZoneMission.new(missionZone, self._missionPriority, database, logger, self, spawnManager)
if mission then if mission then
self._db.missionsByCode[mission.code] = mission self._db.missionsByCode[mission.code] = mission
if mission.name and self._db.missionsByName[mission.name] == nil then if mission.name and self._db.missionsByName[mission.name] == nil then
self._db.missionsByName[mission.name] = mission self._db.missionsByName[mission.name] = mission
else else
Spearhead.AddMissionEditorWarning("DUPLICATE MISSION NAME ALERT: " .. mission.name .. " in zone: " .. self.zoneName) MissionEditorWarnings.Add("DUPLICATE MISSION NAME ALERT: " .. mission.name .. " in zone: " .. self.zoneName)
end end
if mission.missionType == "SAM" then if mission.missionType == "SAM" then
@@ -170,7 +181,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
---@type table<string, Array<Mission>> ---@type table<string, Array<Mission>>
local randomMissionByName = {} local randomMissionByName = {}
for _, missionZoneName in pairs(randomMissionNames) do for _, missionZoneName in pairs(randomMissionNames) do
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZoneName, self._missionPriority, database, logger, self, spawnManager) local mission = ZoneMission.new(missionZoneName, self._missionPriority, database, logger, self, spawnManager)
if mission then if mission then
if randomMissionByName[mission.name] == nil then if randomMissionByName[mission.name] == nil then
randomMissionByName[mission.name] = {} randomMissionByName[mission.name] = {}
@@ -181,18 +192,18 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
for missionName, missions in pairs(randomMissionByName) do for missionName, missions in pairs(randomMissionByName) do
local missionZonePicked = Spearhead.classes.persistence.Persistence.GetPickedRandomMission(missionName) local missionZonePicked = Persistence.GetPickedRandomMission(missionName)
if missionZonePicked == nil then if missionZonePicked == nil then
local mission = Spearhead.Util.randomFromList(missions) --[[@as Mission]] local mission = Util.randomFromList(missions) --[[@as Mission]]
if mission then if mission then
Spearhead.classes.persistence.Persistence.RegisterPickedRandomMission(mission.name, mission.zoneName) Persistence.RegisterPickedRandomMission(mission.name, mission.zoneName)
self._db.missionsByCode[mission.code] = mission self._db.missionsByCode[mission.code] = mission
if mission.name and self._db.missionsByName[mission.name] == nil then if mission.name and self._db.missionsByName[mission.name] == nil then
self._db.missionsByName[mission.name] = mission self._db.missionsByName[mission.name] = mission
else else
Spearhead.AddMissionEditorWarning("DUPLICATE MISSION NAME ALERT: " .. mission.name .. " in zone: " .. self.zoneName) MissionEditorWarnings.Add("DUPLICATE MISSION NAME ALERT: " .. mission.name .. " in zone: " .. self.zoneName)
end end
if mission.missionType == "SAM" then if mission.missionType == "SAM" then
@@ -223,13 +234,13 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
local airbaseNames = database:getAirbaseNamesInStage(self.zoneName) local airbaseNames = database:getAirbaseNamesInStage(self.zoneName)
if airbaseNames ~= nil and type(airbaseNames) == "table" then if airbaseNames ~= nil and type(airbaseNames) == "table" then
for _, airbaseName in pairs(airbaseNames) do for _, airbaseName in pairs(airbaseNames) do
local airbase = Spearhead.classes.stageClasses.SpecialZones.StageBase.New(database, logger, airbaseName, spawnManager) local airbase = StageBase.New(database, logger, airbaseName, spawnManager)
table.insert(self._db.airbases, airbase) table.insert(self._db.airbases, airbase)
end end
end end
for _, samZoneName in pairs(database:getBlueSamsInStage(self.zoneName)) do for _, samZoneName in pairs(database:getBlueSamsInStage(self.zoneName)) do
local blueSam = Spearhead.classes.stageClasses.SpecialZones.BlueSam.New(database, logger, samZoneName, spawnManager) local blueSam = BlueSam.New(database, logger, samZoneName, spawnManager)
table.insert(self._db.blueSams, blueSam) table.insert(self._db.blueSams, blueSam)
end end
@@ -242,7 +253,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
end end
end end
Spearhead.Events.AddStageNumberChangedListener(self) Events.AddStageNumberChangedListener(self)
return self return self
end end
@@ -304,14 +315,14 @@ function Stage:CheckAndUpdateSelf()
end end
local max = dbTables.maxMissions local max = dbTables.maxMissions
local availableMissionsCount = Spearhead.Util.tableLength(getAvailableMissions()) local availableMissionsCount = Util.tableLength(getAvailableMissions())
local activeCount = getActiveMissionsCount() local activeCount = getActiveMissionsCount()
if activeCount < max and availableMissionsCount > 0 then if activeCount < max and availableMissionsCount > 0 then
for i = activeCount+1, max do for i = activeCount+1, max do
if availableMissionsCount == 0 then if availableMissionsCount == 0 then
i = max+1 --exits this loop i = max+1 --exits this loop
else else
local mission = Spearhead.Util.randomFromList(getAvailableMissions()) --[[@as Mission]] local mission = Util.randomFromList(getAvailableMissions()) --[[@as Mission]]
if mission then if mission then
mission:SpawnActive() mission:SpawnActive()
activeCount = activeCount + 1; activeCount = activeCount + 1;
@@ -391,8 +402,8 @@ function Stage:MarkStage(stageColor)
end end
if self._stageDrawingId and self._stageConfig.isDrawStagesEnabled == true then if self._stageDrawingId and self._stageConfig.isDrawStagesEnabled == true then
Spearhead.DcsUtil.SetLineColor(self._stageDrawingId, lineColor) DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
Spearhead.DcsUtil.SetFillColor(self._stageDrawingId, fillColor) DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
end end
end end
@@ -405,7 +416,7 @@ function Stage:ActivateStage()
self:PreActivate(false) self:PreActivate(false)
self._logger:debug("Activating Misc groups for zone. Count: " .. Spearhead.Util.tableLength(self._db.miscGroups)) self._logger:debug("Activating Misc groups for zone. Count: " .. Util.tableLength(self._db.miscGroups))
for _, miscGroup in pairs(self._db.miscGroups) do for _, miscGroup in pairs(self._db.miscGroups) do
miscGroup:Spawn() miscGroup:Spawn()
end end
@@ -452,7 +463,7 @@ function Stage:OnStageNumberChanged(number)
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number) self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
self:PreActivate(true) self:PreActivate(true)
elseif Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
self:PreActivate(false) self:PreActivate(false)
end end
@@ -547,7 +558,7 @@ end
function Stage:ActivateBlueStage() function Stage:ActivateBlueStage()
self._logger:debug("Setting stage '" .. Spearhead.Util.toString(self.zoneName) .. "' to blue") self._logger:debug("Setting stage '" .. Util.toString(self.zoneName) .. "' to blue")
for _, mission in pairs(self._db.missions) do for _, mission in pairs(self._db.missions) do
mission:SpawnPersistedState() mission:SpawnPersistedState()
@@ -1,4 +1,7 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
---@class ExtraStage : Stage ---@class ExtraStage : Stage
local ExtraStage = {} local ExtraStage = {}
ExtraStage.__index = ExtraStage ExtraStage.__index = ExtraStage
@@ -13,7 +16,6 @@ ExtraStage.__index = ExtraStage
---@return ExtraStage ---@return ExtraStage
function ExtraStage.New(database, stageConfig, logger, initData, spawnManager) function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(ExtraStage, Stage) setmetatable(ExtraStage, Stage)
local self = setmetatable({}, { __index = ExtraStage }) --[[@as ExtraStage]] local self = setmetatable({}, { __index = ExtraStage }) --[[@as ExtraStage]]
@@ -46,7 +48,7 @@ function ExtraStage:OnStageNumberChanged(number)
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number) self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
self:PreActivate(true) self:PreActivate(true)
elseif Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
self:PreActivate(false) self:PreActivate(false)
end end
@@ -1,4 +1,6 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
---@class PrimaryStage : Stage ---@class PrimaryStage : Stage
local PrimaryStage = {} local PrimaryStage = {}
@@ -13,7 +15,6 @@ PrimaryStage.__index = PrimaryStage
---@return PrimaryStage ---@return PrimaryStage
function PrimaryStage.New(database, stageConfig, logger, initData, spawnManager) function PrimaryStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(PrimaryStage, Stage) setmetatable(PrimaryStage, Stage)
local self = setmetatable({}, { __index = PrimaryStage }) --[[@as PrimaryStage]] local self = setmetatable({}, { __index = PrimaryStage }) --[[@as PrimaryStage]]
@@ -1,3 +1,4 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
---@class WaitingStage : Stage ---@class WaitingStage : Stage
---@field private _waitTimeSeconds integer ---@field private _waitTimeSeconds integer
@@ -18,8 +19,6 @@ local WaitingStageInitData = {}
---@param spawnManager SpawnManager ---@param spawnManager SpawnManager
---@return WaitingStage ---@return WaitingStage
function WaitingStage.New(database, stageConfig, logger, initData, spawnManager) function WaitingStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(WaitingStage, Stage) setmetatable(WaitingStage, Stage)
local self = setmetatable({}, { __index = WaitingStage }) --[[@as WaitingStage]] local self = setmetatable({}, { __index = WaitingStage }) --[[@as WaitingStage]]
@@ -5,8 +5,6 @@ local SpearheadEvents = require("classes.spearhead_events")
local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper") local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper")
local MaxLoadConfig = require("classes.stageClasses.helpers.MaxLoadConfig") local MaxLoadConfig = require("classes.stageClasses.helpers.MaxLoadConfig")
env.info("Spearhead SupplyUnitsTracker loaded")
---@class SupplyUnitEventListener ---@class SupplyUnitEventListener
---@field supplyUnitSpawned fun(self:SupplyUnitEventListener, unit:Unit) | nil ---@field supplyUnitSpawned fun(self:SupplyUnitEventListener, unit:Unit) | nil
---@field enteredSupplyHub fun(self:SupplyUnitEventListener, unit:Unit, hub:SupplyHub) | nil ---@field enteredSupplyHub fun(self:SupplyUnitEventListener, unit:Unit, hub:SupplyHub) | nil
@@ -1,3 +1,7 @@
local Mission = require("classes.stageClasses.missions.baseMissions.Mission")
local Util = require("classes.util.Util")
local DcsUtil = require("classes.util.DcsUtil")
---@class RunwayStrikeMission : Mission ---@class RunwayStrikeMission : Mission
---@field runwayBombingTracker RunwayBombingTracker ---@field runwayBombingTracker RunwayBombingTracker
---@field private _runway Runway ---@field private _runway Runway
@@ -22,8 +26,7 @@ local RunwayStrikeMission = {}
---@param runwayBombingTracker RunwayBombingTracker ---@param runwayBombingTracker RunwayBombingTracker
---@return RunwayStrikeMission? ---@return RunwayStrikeMission?
function RunwayStrikeMission.new(runway, airbaseName, database, logger, runwayBombingTracker) function RunwayStrikeMission.new(runway, airbaseName, database, logger, runwayBombingTracker)
local Mission = Spearhead.classes.stageClasses.missions.baseMissions.Mission
RunwayStrikeMission.__index = RunwayStrikeMission RunwayStrikeMission.__index = RunwayStrikeMission
setmetatable(RunwayStrikeMission, Mission) setmetatable(RunwayStrikeMission, Mission)
local self = setmetatable({}, RunwayStrikeMission) local self = setmetatable({}, RunwayStrikeMission)
@@ -82,7 +85,7 @@ function RunwayStrikeMission:RunwayHit(impactPoint, explosiveMass)
for _, section in pairs(self._runwaySections) do for _, section in pairs(self._runwaySections) do
local zone = self:SectionToSpearheadZone(section) local zone = self:SectionToSpearheadZone(section)
if Spearhead.Util.is3dPointInZone({ x = impactPoint.x, z = impactPoint.y, y = 0 }, zone) then if Util.is3dPointInZone({ x = impactPoint.x, z = impactPoint.y, y = 0 }, zone) then
if section.kilosHit == nil then if section.kilosHit == nil then
section.kilosHit = 0 section.kilosHit = 0
end end
@@ -153,10 +156,10 @@ function RunwayStrikeMission:Draw()
local color = { r=0, g=1, b=0, a=0.5 } local color = { r=0, g=1, b=0, a=0.5 }
runwaySection.drawID = Spearhead.DcsUtil.DrawZone(zone, color, color, 5) runwaySection.drawID = DcsUtil.DrawZone(zone, color, color, 5)
else else
Spearhead.DcsUtil.SetFillColor(runwaySection.drawID, fillColor) DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
Spearhead.DcsUtil.SetLineColor(runwaySection.drawID, lineColor) DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
end end
end end
@@ -342,7 +345,7 @@ local repairStaticConfigs = {
---@private ---@private
---@param section RunwaySection ---@param section RunwaySection
function RunwayStrikeMission:AddOrUpdateRepairStatics(section) function RunwayStrikeMission:AddOrUpdateRepairStatics(section)
if Spearhead.Util.tableLength(section.repairGroups) > 0 then if Util.tableLength(section.repairGroups) > 0 then
return return
end end
@@ -351,7 +354,7 @@ function RunwayStrikeMission:AddOrUpdateRepairStatics(section)
y = section.center.y, y = section.center.y,
} }
local repairGroup = Spearhead.Util.randomFromList(repairStaticConfigs) local repairGroup = Util.randomFromList(repairStaticConfigs)
for _, repairStatic in pairs(repairGroup) do for _, repairStatic in pairs(repairGroup) do
repairStatic.x = location.x + repairStatic.x repairStatic.x = location.x + repairStatic.x
@@ -369,7 +372,7 @@ end
---@private ---@private
---@param section RunwaySection ---@param section RunwaySection
function RunwayStrikeMission:RemoveRepairStatics(section) function RunwayStrikeMission:RemoveRepairStatics(section)
if Spearhead.Util.tableLength(section.repairGroups) == 0 then if Util.tableLength(section.repairGroups) == 0 then
return return
end end
@@ -1,3 +1,11 @@
local Util = require("classes.util.Util")
local MissionEditorWarnings = require("classes.util.MissionEditorWarnings")
local Mission = require("classes.stageClasses.missions.baseMissions.Mission")
local SpearheadGroup = require("classes.stageClasses.Groups.SpearheadGroup")
local Events = require("classes.spearhead_events")
local BattleManager = require("classes.stageClasses.helpers.BattleManager")
local DcsUtil = require("classes.util.DcsUtil")
--- ZoneMission is missions that are defined by zones in the ME --- ZoneMission is missions that are defined by zones in the ME
---@class ZoneMission : Mission, OnUnitLostListener ---@class ZoneMission : Mission, OnUnitLostListener
---@field private _state MissionState ---@field private _state MissionState
@@ -26,13 +34,13 @@ local ZoneMission = {}
---@param input string ---@param input string
---@return ParsedMissionName? ---@return ParsedMissionName?
local function ParseZoneName(input) local function ParseZoneName(input)
local split_name = Spearhead.Util.split_string(input, "_") local split_name = Util.split_string(input, "_")
local split_length = Spearhead.Util.tableLength(split_name) local split_length = Util.tableLength(split_name)
if Spearhead.Util.startswith(input, "RANDOMMISSION") == true and split_length < 4 then if Util.startswith(input, "RANDOMMISSION") == true and split_length < 4 then
Spearhead.AddMissionEditorWarning("Random Mission with zonename " .. input .. " not in right format") MissionEditorWarnings.Add("Random Mission with zonename " .. input .. " not in right format")
return nil return nil
elseif split_length < 3 then elseif split_length < 3 then
Spearhead.AddMissionEditorWarning("Mission with zonename" .. input .. " not in right format") MissionEditorWarnings.Add("Mission with zonename" .. input .. " not in right format")
return nil return nil
end end
@@ -47,7 +55,7 @@ local function ParseZoneName(input)
if inputType == "sam" then parsedType = "SAM" end if inputType == "sam" then parsedType = "SAM" end
if parsedType == "nil" then if parsedType == "nil" then
Spearhead.AddMissionEditorWarning("Mission with zonename '" .. MissionEditorWarnings.Add("Mission with zonename '" ..
input .. "' has an unsupported type '" .. (type or "nil")) input .. "' has an unsupported type '" .. (type or "nil"))
return nil return nil
end end
@@ -69,7 +77,6 @@ MINIMAL_UNITS_ALIVE_RATIO = 0.21
---@param spawnManager SpawnManager ---@param spawnManager SpawnManager
---@return ZoneMission? ---@return ZoneMission?
function ZoneMission.new(zoneName, priority, database, logger, parentStage, spawnManager) function ZoneMission.new(zoneName, priority, database, logger, parentStage, spawnManager)
local Mission = Spearhead.classes.stageClasses.missions.baseMissions.Mission
ZoneMission.__index = ZoneMission ZoneMission.__index = ZoneMission
setmetatable(ZoneMission, Mission) setmetatable(ZoneMission, Mission)
@@ -112,8 +119,6 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
self._parentStage = parentStage self._parentStage = parentStage
self._dependencies = {} self._dependencies = {}
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup
if missionData.dependsOn then if missionData.dependsOn then
for _, dependency in pairs(missionData.dependsOn) do for _, dependency in pairs(missionData.dependsOn) do
self._dependencies[dependency] = false self._dependencies[dependency] = false
@@ -129,7 +134,7 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
end end
self._missionGroups.sceneryTargets = missionData.SceneryTargets or {} self._missionGroups.sceneryTargets = missionData.SceneryTargets or {}
if Spearhead.Util.tableLength(self._missionGroups.sceneryTargets) > 0 then if Util.tableLength(self._missionGroups.sceneryTargets) > 0 then
self._missionGroups.hasTargets = true self._missionGroups.hasTargets = true
end end
@@ -145,10 +150,10 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true) local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
table.insert(self._missionGroups.redGroups, spearheadGroup) table.insert(self._missionGroups.redGroups, spearheadGroup)
local isGroupTarget = Spearhead.Util.startswith(string.lower(groupName), "tgt_") local isGroupTarget = Util.startswith(string.lower(groupName), "tgt_")
for _, unit in pairs(spearheadGroup:GetObjects()) do for _, unit in pairs(spearheadGroup:GetObjects()) do
local unitName = unit:getName() local unitName = unit:getName()
local isUnitTarget = Spearhead.Util.startswith(string.lower(unitName), "tgt_") local isUnitTarget = Util.startswith(string.lower(unitName), "tgt_")
if self._missionGroups.unitsAlive[groupName] == nil then if self._missionGroups.unitsAlive[groupName] == nil then
self._missionGroups.unitsAlive[groupName] = {} self._missionGroups.unitsAlive[groupName] = {}
@@ -167,18 +172,18 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
self._missionGroups.targetsAlive[groupName][unitName] = true self._missionGroups.targetsAlive[groupName][unitName] = true
end end
Spearhead.Events.addOnUnitLostEventListener(unitName, self) Events.addOnUnitLostEventListener(unitName, self)
end end
spearheadGroup:Destroy() spearheadGroup:Destroy()
end end
if self.missionType == "CAS" then if self.missionType == "CAS" then
self._battleManager = Spearhead.classes.stageClasses.helpers.BattleManager.New(self._missionGroups.redGroups, self._missionGroups.blueGroups, self.zoneName, self._logger.LogLevel) self._battleManager = BattleManager.New(self._missionGroups.redGroups, self._missionGroups.blueGroups, self.zoneName, self._logger.LogLevel)
end end
self._logger:debug("Mission " .. self.name .. " group count: " .. Spearhead.Util.tableLength(missionData.RedGroups)) self._logger:debug("Mission " .. self.name .. " group count: " .. Util.tableLength(missionData.RedGroups))
return self return self
end end
@@ -327,7 +332,7 @@ function ZoneMission:UpdateState(checkHealth, messageIfDone)
end end
if self._state == "COMPLETED" and self._lastContactMarkerID then if self._state == "COMPLETED" and self._lastContactMarkerID then
Spearhead.DcsUtil.RemoveMark(self._lastContactMarkerID) DcsUtil.RemoveMark(self._lastContactMarkerID)
end end
if self._state == "COMPLETED" and self._battleManager then if self._state == "COMPLETED" and self._battleManager then
@@ -511,10 +516,10 @@ function ZoneMission:MarkLastContact(unit)
if self._lastContactMarkerID then if self._lastContactMarkerID then
Spearhead.DcsUtil.RemoveMark(self._lastContactMarkerID) DcsUtil.RemoveMark(self._lastContactMarkerID)
end end
self._lastContactMarkerID = Spearhead.DcsUtil.AddMarkToAll("Last Contact: " .. self.name .. " [" .. self.code .. "]", point) self._lastContactMarkerID = DcsUtil.AddMarkToAll("Last Contact: " .. self.name .. " [" .. self.code .. "]", point)
end end
return ZoneMission return ZoneMission
+2 -1
View File
@@ -1,4 +1,5 @@
local Util = require("classes.util.Util") local Util = require("classes.util.Util")
local SpearheadSceneryObject = require("classes.stageClasses.Groups.SpearheadSceneryObject")
---DCS UTIL Takes inspiration from MIST but only takes the things it needs, changes for DCS updates and different vision for advanced mission scripting stuff. ---DCS UTIL Takes inspiration from MIST but only takes the things it needs, changes for DCS updates and different vision for advanced mission scripting stuff.
---It also adds functions that make the other TDCS scripts easier without taking too much "control" away like MOOSE can sometimes. ---It also adds functions that make the other TDCS scripts easier without taking too much "control" away like MOOSE can sometimes.
@@ -552,7 +553,7 @@ do -- INIT DCS_UTIL
if object and object:isExist() and if object and object:isExist() and
object:hasAttribute("Buildings") object:hasAttribute("Buildings")
then then
local obj = Spearhead.classes.stageClasses.Groups.SpearheadSceneryObject.New(object["id_"]) local obj = SpearheadSceneryObject.New(object["id_"])
table.insert(sceneryObjects, obj) table.insert(sceneryObjects, obj)
end end
end end