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",
"Lua.workspace.library": [
"/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 InterceptGroup = require("classes.capClasses.airGroups.InterceptGroup")
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")
---@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
---@field AllZoneNames Array<string> All Zone Names
---@field StageZoneNames Array<string> All Stage Zone Names
@@ -112,13 +119,13 @@ function Database.New(Logger)
self._logger:debug("Initiating 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
---@type Vec2
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)
if string.lower(split_string[1]) == "missionstage" then
@@ -188,7 +195,7 @@ function Database.New(Logger)
end
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
table.insert(self._tables.AllSceneryObjects, sceneryObject)
end
@@ -202,7 +209,7 @@ function Database.New(Logger)
for i, layer in pairs(env.mission.drawings.layers) do
if string.lower(layer.name) == "author" then
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)
if airbaseData then
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
if string.lower(layer.name) == "author" then
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 customDrawing = Spearhead.classes.stageClasses.drawings.CustomDrawing.New(object)
local customDrawing = CustomDrawing.New(object)
table.insert(self._tables.CustomDrawings, customDrawing)
end
end
@@ -248,10 +255,10 @@ function Database.New(Logger)
for i, layer in pairs(env.mission.drawings.layers) do
if string.lower(layer.name) == "author" then
for key, layer_object in pairs(layer.objects) do
if Spearhead.Util.startswith(string.lower(layer_object.name), "stagebriefing_", true) == true then
local zone = Spearhead.DcsUtil.getZoneByName(stageZoneName)
if Util.startswith(string.lower(layer_object.name), "stagebriefing_", true) == true then
local zone = DcsUtil.getZoneByName(stageZoneName)
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
if description and description ~= "" then
stageData.StageBriefing = description
@@ -265,18 +272,18 @@ function Database.New(Logger)
-- fill blue sams
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)
end
end
--- fill farp zones
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)
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)
if farpZoneData then
table.insert(farpZoneData.supplyHubNames, hubZoneName)
@@ -291,15 +298,15 @@ function Database.New(Logger)
for _, airbase in pairs(world.getAirbases()) do
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
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
local zone = Spearhead.DcsUtil.getZoneByName(hubZoneName)
local zone = DcsUtil.getZoneByName(hubZoneName)
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())
if airbaseData then
table.insert(airbaseData.supplyHubNames, hubZoneName)
@@ -314,14 +321,14 @@ function Database.New(Logger)
-- fill supply hubs
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)
end
end
for _, farpZoneName in pairs(stageData.FarpZones) 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
end
end
@@ -329,14 +336,14 @@ function Database.New(Logger)
-- fill missions
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)
end
end
-- fill random missions
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)
end
end
@@ -345,13 +352,13 @@ function Database.New(Logger)
for _, missionZone in pairs(self._tables.MissionZones) do
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
for _, missionZone in pairs(self._tables.RandomMissionZones) do
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
@@ -368,7 +375,7 @@ function Database.New(Logger)
}
end
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)
end
end
@@ -387,7 +394,7 @@ function Database.New(Logger)
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]
if zoneID then
@@ -398,7 +405,7 @@ function Database.New(Logger)
}
end
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone)
local zone = DcsUtil.getZoneByName(cap_route_zone)
if zone then
table.insert(tables.capZonesByCapZoneID[zoneID].zones, zone)
end
@@ -406,7 +413,7 @@ function Database.New(Logger)
end
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]
if zoneID then
@@ -414,7 +421,7 @@ function Database.New(Logger)
tables.interceptZonesByZoneID[zoneID] = {}
end
local zone = Spearhead.DcsUtil.getZoneByName(interceptZone)
local zone = DcsUtil.getZoneByName(interceptZone)
if zone then
table.insert(tables.interceptZonesByZoneID[zoneID], zone)
end
@@ -443,12 +450,12 @@ function Database.New(Logger)
if missions == 0 then missions = 1 end
self._logger:info("initiated the database with amount of zones: ")
self._logger:info("Stages: " .. Spearhead.Util.tableLength(self._tables.StageZones))
self._logger:info("Total Missions: " .. Spearhead.Util.tableLength(self._tables.MissionZoneData))
self._logger:info("Stages: " .. Util.tableLength(self._tables.StageZones))
self._logger:info("Total Missions: " .. Util.tableLength(self._tables.MissionZoneData))
self._logger:info("Average units per mission: " .. totalUnits / missions)
self._logger:info("Random Missions: " .. Spearhead.Util.tableLength(self._tables.RandomMissionZones))
self._logger:info("Farps: " .. Spearhead.Util.tableLength(self._tables.AllFarpZones))
self._logger:info("Airbases: " .. Spearhead.Util.tableLength(self._tables.AirbaseDataPerAirfield))
self._logger:info("Random Missions: " .. Util.tableLength(self._tables.RandomMissionZones))
self._logger:info("Farps: " .. Util.tableLength(self._tables.AllFarpZones))
self._logger:info("Airbases: " .. Util.tableLength(self._tables.AirbaseDataPerAirfield))
return self
@@ -470,7 +477,7 @@ end
local getAvailableCAPGroups = function()
local result = {}
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)
end
end
@@ -480,7 +487,7 @@ end
---@private
function Database:initAvailableUnits()
do
local all_groups = Spearhead.classes.helpers.MizGroupsManager.getAllGroupNames()
local all_groups = MizGroupsManager.getAllGroupNames()
for _, value in pairs(all_groups) do
is_group_taken[value] = false
end
@@ -492,9 +499,9 @@ end
---@return AirbaseData?
function Database:getAirbaseDataForDrawLayer(layer_object)
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())
end
end
@@ -555,7 +562,7 @@ function Database:loadCapUnits()
local point = airbase:getPoint()
---@type SpearheadTriggerZone?
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName())
local zone = DcsUtil.getAirbaseZoneByName(airbase:getName())
if zone == nil then
zone = {
@@ -569,15 +576,15 @@ function Database:loadCapUnits()
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
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)
elseif Spearhead.Util.startswith(groupName, "CAP_I", true) then
elseif Util.startswith(groupName, "CAP_I", true) then
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)
end
end
@@ -588,19 +595,19 @@ end
---@private
function Database:loadBlueSamUnits()
local all_groups = Spearhead.classes.helpers.MizGroupsManager.getAllGroupNames()
local all_groups = MizGroupsManager.getAllGroupNames()
for _, blueSamZone in pairs(self._tables.BlueSams) do
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
is_group_taken[groupName] = true
table.insert(samData.groups, groupName)
end
local triggerZone = Spearhead.DcsUtil.getZoneByName(blueSamZone)
local triggerZone = DcsUtil.getZoneByName(blueSamZone)
if triggerZone then
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)
if number and number > 0 then
samData.buildingKilos = number
@@ -631,9 +638,9 @@ function Database:LoadZoneData(missionZoneName)
dependsOn = {}
}
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
local groups = DcsUtil.getGroupsInZone(all_groups, missionZoneName)
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)
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
local point = sceneryObject:GetPoint()
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)
end
end
end
-- 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
for _, kvPair in pairs(triggerZone.properties) do
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)
elseif Spearhead.Util.startswith(key, "completeat") == true then
elseif Util.startswith(key, "completeat") == true then
local value = tonumber(kvPair.value)
if value then
if value > 1 and value <= 100 then
value = value / 100
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
self._tables.MissionZoneData[missionZoneName].completeAt = value
end
@@ -690,8 +697,8 @@ function Database:LoadZoneData(missionZoneName)
for key, layer_object in pairs(layer.objects) do
local vec2 = { x = layer_object.mapX, y = layer_object.mapY }
if triggerZone and Spearhead.Util.is2dPointInZone(vec2, triggerZone) then
if layer_object.name and Spearhead.Util.startswith(layer_object.name, "briefing_", true) then
if triggerZone and Util.is2dPointInZone(vec2, triggerZone) then
if layer_object.name and Util.startswith(layer_object.name, "briefing_", true) then
local description = layer_object.text
if description and description ~= "" then
self._tables.MissionZoneData[missionZoneName].description = description
@@ -725,16 +732,16 @@ function Database:loadFarpData()
for _, farpZone in pairs(self._tables.AllFarpZones) do
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
is_group_taken[groupName] = true
table.insert(farpzoneData.groups, groupName)
end
local triggerZone = Spearhead.DcsUtil.getZoneByName(farpZone)
local triggerZone = DcsUtil.getZoneByName(farpZone)
if triggerZone then
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)
if number and number > 0 then
farpzoneData.buildingKilos = number
@@ -754,7 +761,7 @@ function Database:loadAirbaseGroups()
if base then
local basedata = self:getOrCreateAirbaseData(baseName)
local point = base:getPoint()
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(baseName)
local airbaseZone = DcsUtil.getAirbaseZoneByName(baseName)
if airbaseZone == nil then
airbaseZone = {
@@ -768,9 +775,9 @@ function Database:loadAirbaseGroups()
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
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then
if MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object then
if object:getCoalition() == coalition.side.RED then
@@ -806,9 +813,9 @@ function Database:loadMiscGroupsInStages()
for _, stageZone in pairs(self._tables.StageZones) do
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
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then
if MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() ~= coalition.side.NEUTRAL then
is_group_taken[groupName] = true
@@ -846,14 +853,14 @@ function Database:GetCapZoneForZoneID(zoneID)
if capZonesForID and capZonesForID.zones then
local count = Spearhead.Util.tableLength(capZonesForID.zones)
local count = Util.tableLength(capZonesForID.zones)
if count == 0 then
self._logger:warn("Tried to get cap zone for zoneID: " .. zoneID .. " but cap zones were empty for this ID")
return nil
end
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
end
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
local SpearheadEvents = {}
do
@@ -7,10 +11,9 @@ do
---@param logLevel LogLevel
SpearheadEvents.Init = function(logLevel)
logger = Spearhead.LoggerTemplate.new("Events", logLevel)
logger = Logger.new("Events", logLevel)
end
local warn = function(text)
if logger then
logger:warn(text)
@@ -50,7 +53,7 @@ do
---@param newStageNumber number
SpearheadEvents.PublishStageNumberChanged = function(newStageNumber)
pcall(function ()
Spearhead.classes.persistence.Persistence.SetActiveStage(newStageNumber)
Persistence.SetActiveStage(newStageNumber)
end)
for _, callable in pairs(OnStageNumberChangedListeners) do
@@ -68,8 +71,7 @@ do
logError(err)
end
end
Spearhead.LoggerTemplate.new("Events", "INFO"):info("Published stage number changed to: " .. tostring(newStageNumber))
Spearhead.StageNumber = newStageNumber
Logger.new("Events", "INFO"):info("Published stage number changed to: " .. tostring(newStageNumber))
end
end
@@ -349,7 +351,7 @@ do
end
if event.id == world.event.S_EVENT_MISSION_END then
Spearhead.classes.persistence.Persistence.UpdateNow()
Persistence.UpdateNow()
end
local AI_GROUPS = {}
@@ -370,7 +372,7 @@ do
return false
end
local players = Spearhead.DcsUtil.getAllPlayerUnits()
local players = DcsUtil.getAllPlayerUnits()
local unitName = unit:getName()
for i, unit in pairs(players) do
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
local ROUTE_UTIL = {}
do --setup route util
@@ -23,7 +26,7 @@ do --setup route util
---@return table task
local RtbTask = function(airdromeId, basePoint, speed)
if basePoint == nil then
basePoint = Spearhead.Util.getAirbaseById(airdromeId):getPoint()
basePoint = DcsUtil.getAirbaseById(airdromeId):getPoint()
end
return {
@@ -215,7 +218,7 @@ do --setup route util
---@param deviationDistance number
---@return table? route
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
return nil
end
@@ -295,7 +298,7 @@ do --setup route util
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
return nil, "No airbase found for ID " .. tostring(airdromeId)
end
@@ -308,7 +311,7 @@ do --setup route util
end
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]
if unit and unit:isExist() == true and unit:inAir() == true then
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 = {}
@@ -29,7 +36,7 @@ GlobalStageManager.getCurrentStage = function() return currentStage end
---@param spawnManager SpawnManager
---@return nil
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)
local self = setmetatable({}, GlobalStageManager)
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
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 split = Spearhead.Util.split_string(stageName, "_")
if Spearhead.Util.tableLength(split) < 2 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a order number or valid format")
local split = Util.split_string(stageName, "_")
if Util.tableLength(split) < 2 then
MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a order number or valid format")
valid = false
end
if Spearhead.Util.tableLength(split) < 3 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a stage name")
if Util.tableLength(split) < 3 then
MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a stage name")
end
local orderNumber = nil
local isSideStage = false
if valid == true then
local orderNumberString = string.lower(split[2])
if Spearhead.Util.startswith(orderNumberString, "x") == true then
if Util.startswith(orderNumberString, "x") == true then
isSideStage = true
orderNumberString = string.gsub(orderNumberString, "x", "")
@@ -79,13 +86,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
end
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
end
end
local stageDisplayName = split[3]
local stagelogger = Spearhead.LoggerTemplate.new(stageName, logLevel)
local stagelogger = Logger.new(stageName, logLevel)
if valid == true and orderNumber then
---@type StageInitData
@@ -96,13 +103,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
}
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)
if SideStageByIndex[tostring(orderNumber)] == nil then SideStageByIndex[tostring(orderNumber)] = {} end
table.insert(SideStageByIndex[tostring(orderNumber)], stage)
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)
if StagesByIndex[tostring(orderNumber)] == nil then StagesByIndex[tostring(orderNumber)] = {} end
@@ -111,13 +118,13 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
end
end
if Spearhead.Util.startswith(stageName, "waitingstage", true) then
if Util.startswith(stageName, "waitingstage", true) then
local valid = true
local split = Spearhead.Util.split_string(stageName, "_")
local split = Util.split_string(stageName, "_")
if Spearhead.Util.tableLength(split) < 3 then
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a order number or valid format")
if Util.tableLength(split) < 3 then
MissionEditorWarnings.Add("Stage zone with name " .. stageName .. " does not have a order number or valid format")
valid = false
end
@@ -126,19 +133,19 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
local stageIndex = tonumber(stageIndexString)
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
end
local waitingSecondsString = split[3]
local waitingSeconds = tonumber(waitingSecondsString)
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
end
if valid == true then
local stagelogger = Spearhead.LoggerTemplate.new(stageName, logLevel)
local stagelogger = Logger.new(stageName, logLevel)
---@type WaitingStageInitData
local initData = {
@@ -147,7 +154,7 @@ function GlobalStageManager.NewAndStart(database, stageConfig, logLevel, spawnMa
stageZoneName = stageName,
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
WaitingStagesByIndex[tostring(stageIndex)] = {}
@@ -203,7 +210,7 @@ function GlobalStageManager:OnStageComplete(stage)
local newStageNumber = currentStage + 1
self:UpdateDrawings(newStageNumber)
self.logger:debug("Setting next stage to: " .. tostring(newStageNumber))
Spearhead.Events.PublishStageNumberChanged(newStageNumber)
Events.PublishStageNumberChanged(newStageNumber)
end
end
end
@@ -224,7 +231,7 @@ end
GlobalStageManager.printFullOverview = function ()
local logger = Spearhead.LoggerTemplate.new("StageOverview", "INFO")
local logger = Logger.new("StageOverview", "INFO")
logger:info("Stage overview:")
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
---@field Activate fun(self: BlueSam)
@@ -20,7 +24,7 @@ BlueSam.__index = BlueSam
---@return BlueSam?
function BlueSam.New(database, logger, zoneName, spawnManager)
setmetatable(BlueSam, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
setmetatable(BlueSam, BuildableZone)
local self = setmetatable({}, BlueSam)
self._database = database
@@ -53,39 +57,39 @@ function BlueSam.New(database, logger, zoneName, spawnManager)
end
for _, groupName in pairs(blueSamData.groups) do
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true)
if SpearheadGroup then
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
if spearheadGroup then
if SpearheadGroup:GetCoalition() == 2 or SpearheadGroup:GetCoalition() == 0 then
table.insert(self._blueGroups, SpearheadGroup)
if spearheadGroup:GetCoalition() == 2 or spearheadGroup:GetCoalition() == 0 then
table.insert(self._blueGroups, spearheadGroup)
end
for _, unit in pairs(SpearheadGroup:GetObjects()) do
if SpearheadGroup:GetCoalition() == 1 then
for _, unit in pairs(spearheadGroup:GetObjects()) do
if spearheadGroup:GetCoalition() == 1 then
table.insert(blueUnitsPos, unit:getPoint())
elseif SpearheadGroup:GetCoalition() == 2 then
elseif spearheadGroup:GetCoalition() == 2 then
table.insert(redUnitsPos, unit:getPoint())
end
end
end
SpearheadGroup:Destroy()
spearheadGroup:Destroy()
end
--Cleanup units
local cleanup_distance = 5
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) 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
self._cleanupUnits[redUnitName] = true
end
end
end
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
local zone = DcsUtil.getZoneByName(zoneName)
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
return self
@@ -104,9 +108,9 @@ function BlueSam:GetNoLandingZone()
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
self._logger:error("Zone not found: " .. self._zoneName)
return nil
@@ -136,7 +140,7 @@ end
function BlueSam:SpawnGroups()
for unitName, needsCleanup in pairs(self._cleanupUnits) do
Spearhead.DcsUtil.DestroyUnit(unitName)
DcsUtil.DestroyUnit(unitName)
end
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
---@field private _startingFarp boolean
@@ -18,14 +22,14 @@ FarpZone.__index = FarpZone
---@param spawnManager SpawnManager
---@return FarpZone
function FarpZone.New(database, logger, zoneName, spawnManager)
setmetatable(FarpZone, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
setmetatable(FarpZone, BuildableZone)
local self = setmetatable({}, FarpZone)
self._database = database
self._logger = logger
self._zoneName = zoneName
local split = Spearhead.Util.split_string(zoneName, "_")
local split = Util.split_string(zoneName, "_")
if string.lower(split[2]) == "a" then
self._startingFarp = true
else
@@ -44,7 +48,7 @@ function FarpZone.New(database, logger, zoneName, spawnManager)
self._padNames = farpData.padNames
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
table.insert(self._supplyHubs, supplyHub)
end
@@ -52,15 +56,15 @@ function FarpZone.New(database, logger, zoneName, spawnManager)
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)
group:Destroy()
end
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
local zone = DcsUtil.getZoneByName(zoneName)
if zone then
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
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
---@field private _database Database
---@field private _logger Logger
@@ -21,7 +27,7 @@ StageBase.__index = StageBase
---@param spawnManager SpawnManager
---@return StageBase?
function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
setmetatable(StageBase, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
setmetatable(StageBase, BuildableZone)
local self = setmetatable({}, StageBase)
self._database = databaseManager
@@ -33,7 +39,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
self._supplyHubs = {}
self._airbase = Airbase.getByName(airbaseName)
self._initialSide = Spearhead.DcsUtil.getStartingCoalition(self._airbase)
self._initialSide = DcsUtil.getStartingCoalition(self._airbase)
do --init
local airbaseData = databaseManager:getAirbaseDataForZone(airbaseName)
@@ -49,7 +55,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
local blueUnitsPos = {}
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)
for _, unit in pairs(shGroup:GetObjects()) do
@@ -60,7 +66,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end
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)
for _, unit in pairs(shGroup:GetObjects()) do
@@ -71,7 +77,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end
for _, supplyHubName in pairs(airbaseData.supplyHubNames) do
local supplyHub = Spearhead.classes.stageClasses.SpecialZones.SupplyHub.new(databaseManager, logger,
local supplyHub = SupplyHub.new(databaseManager, logger,
supplyHubName)
if supplyHub then
table.insert(self._supplyHubs, supplyHub)
@@ -86,7 +92,7 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) 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
self._cleanup_units[redUnitName] = true
end
@@ -94,9 +100,9 @@ function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
end
end
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbaseName)
local zone = DcsUtil.getAirbaseZoneByName(airbaseName)
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
@@ -126,8 +132,8 @@ function StageBase:CleanRedUnits()
for unitName, shouldClean in pairs(self._cleanup_units) do
if shouldClean == true then
Spearhead.DcsUtil.DestroyUnit(unitName)
Spearhead.DcsUtil.CleanCorpse(unitName)
DcsUtil.DestroyUnit(unitName)
DcsUtil.CleanCorpse(unitName)
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
---@field private _database Database
---@field private _logger Logger
@@ -26,18 +31,18 @@ function SupplyHub.new(database, logger, zoneName)
self._logger = logger
self._zoneName = zoneName
local split = Spearhead.Util.split_string(zoneName, "_")
local split = Util.split_string(zoneName, "_")
if string.lower(split[2]) == "a" then
self._activeAtStart = true
else
self._activeAtStart = false
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._missionCommandsHelper = Spearhead.classes.stageClasses.helpers.MissionCommandsHelper.getOrCreate(logger.LogLevel)
self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
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)
local zone = Spearhead.DcsUtil.getZoneByName(self._zoneName)
local zone = DcsUtil.getZoneByName(self._zoneName)
if zone and self._drawID == nil then
---@type DrawColor
local fillColor = { r=0, g=1, b=0, a=0.2 }
---@type DrawColor
local lineColor = { r=0, g=1, b=0, a=1}
local lineStyle = 1
self._drawID = Spearhead.DcsUtil.DrawZone(zone, lineColor, fillColor, lineStyle)
self._drawID = DcsUtil.DrawZone(zone, lineColor, fillColor, lineStyle)
end
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
---@field protected _targetZone SpearheadTriggerZone
@@ -22,11 +25,11 @@ function BuildableZone:New(targetZone, kilosRequired, crateType, buildableGroup
self._requiredKilos = kilosRequired or 0
self._buildableGroups = buildableGroups or {}
self._buildableLogger = logger
local totalGroups = Spearhead.Util.tableLength(self._buildableGroups)
local totalGroups = Util.tableLength(self._buildableGroups)
self._groupsPerKilo = totalGroups / self._requiredKilos
self._receivedBuildingKilos = 0
local persistedKilos = Spearhead.classes.persistence.Persistence.GetZoneDeliveredKilos(targetZone.name)
local persistedKilos = Persistence.GetZoneDeliveredKilos(targetZone.name)
if persistedKilos and persistedKilos > 0 then
self._buildableLogger:debug("Zone " .. targetZone.name .. " already has " .. persistedKilos .. " kilos delivered")
self._receivedBuildingKilos = persistedKilos
@@ -66,7 +69,7 @@ function BuildableZone:New(targetZone, kilosRequired, crateType, buildableGroup
local noLandingZone = self:GetNoLandingZone()
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)
else
self._buildableMission = nil
@@ -138,7 +141,7 @@ end
---@param kilos number
function BuildableZone:FinaliseCrate(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
self:OnBuildingComplete()
end
@@ -157,7 +160,7 @@ function BuildableZone:GetNoLandingZone()
end
end
local vecs = Spearhead.Util.getConvexHull(points)
local vecs = Util.getConvexHull(points)
---@type SpearheadTriggerZone
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
---| "RED"
@@ -71,8 +84,6 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup
self.zoneName = initData.stageZoneName
self.stageNumber = initData.stageNumber
self._isActive = false
@@ -101,11 +112,11 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
self._activeStage = -99
self._preActivated = false
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
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
self._spawnedGroups = {}
@@ -114,13 +125,13 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
local farpNames = database:getFarpNamesInStage(self.zoneName)
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)
end
local supplyHubNames = database:getSupplyHubsInStage(self.zoneName)
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)
end
@@ -144,17 +155,17 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
do -- load tables
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
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
self._db.missionsByCode[mission.code] = mission
if mission.name and self._db.missionsByName[mission.name] == nil then
self._db.missionsByName[mission.name] = mission
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
if mission.missionType == "SAM" then
@@ -170,7 +181,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
---@type table<string, Array<Mission>>
local randomMissionByName = {}
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 randomMissionByName[mission.name] == nil then
randomMissionByName[mission.name] = {}
@@ -181,18 +192,18 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
for missionName, missions in pairs(randomMissionByName) do
local missionZonePicked = Spearhead.classes.persistence.Persistence.GetPickedRandomMission(missionName)
local missionZonePicked = Persistence.GetPickedRandomMission(missionName)
if missionZonePicked == nil then
local mission = Spearhead.Util.randomFromList(missions) --[[@as Mission]]
local mission = Util.randomFromList(missions) --[[@as Mission]]
if mission then
Spearhead.classes.persistence.Persistence.RegisterPickedRandomMission(mission.name, mission.zoneName)
Persistence.RegisterPickedRandomMission(mission.name, mission.zoneName)
self._db.missionsByCode[mission.code] = mission
if mission.name and self._db.missionsByName[mission.name] == nil then
self._db.missionsByName[mission.name] = mission
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
if mission.missionType == "SAM" then
@@ -223,13 +234,13 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
local airbaseNames = database:getAirbaseNamesInStage(self.zoneName)
if airbaseNames ~= nil and type(airbaseNames) == "table" then
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)
end
end
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)
end
@@ -242,7 +253,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
end
end
Spearhead.Events.AddStageNumberChangedListener(self)
Events.AddStageNumberChangedListener(self)
return self
end
@@ -304,14 +315,14 @@ function Stage:CheckAndUpdateSelf()
end
local max = dbTables.maxMissions
local availableMissionsCount = Spearhead.Util.tableLength(getAvailableMissions())
local availableMissionsCount = Util.tableLength(getAvailableMissions())
local activeCount = getActiveMissionsCount()
if activeCount < max and availableMissionsCount > 0 then
for i = activeCount+1, max do
if availableMissionsCount == 0 then
i = max+1 --exits this loop
else
local mission = Spearhead.Util.randomFromList(getAvailableMissions()) --[[@as Mission]]
local mission = Util.randomFromList(getAvailableMissions()) --[[@as Mission]]
if mission then
mission:SpawnActive()
activeCount = activeCount + 1;
@@ -391,8 +402,8 @@ function Stage:MarkStage(stageColor)
end
if self._stageDrawingId and self._stageConfig.isDrawStagesEnabled == true then
Spearhead.DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
Spearhead.DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
end
end
@@ -405,7 +416,7 @@ function Stage:ActivateStage()
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
miscGroup:Spawn()
end
@@ -452,7 +463,7 @@ function Stage:OnStageNumberChanged(number)
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
self:PreActivate(true)
elseif Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
self:PreActivate(false)
end
@@ -547,7 +558,7 @@ end
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
mission:SpawnPersistedState()
@@ -1,4 +1,7 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
---@class ExtraStage : Stage
local ExtraStage = {}
ExtraStage.__index = ExtraStage
@@ -13,7 +16,6 @@ ExtraStage.__index = ExtraStage
---@return ExtraStage
function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(ExtraStage, Stage)
local self = setmetatable({}, { __index = ExtraStage }) --[[@as ExtraStage]]
@@ -46,7 +48,7 @@ function ExtraStage:OnStageNumberChanged(number)
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
self:PreActivate(true)
elseif Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
self:PreActivate(false)
end
@@ -1,4 +1,6 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
---@class PrimaryStage : Stage
local PrimaryStage = {}
@@ -13,7 +15,6 @@ PrimaryStage.__index = PrimaryStage
---@return PrimaryStage
function PrimaryStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(PrimaryStage, Stage)
local self = setmetatable({}, { __index = PrimaryStage }) --[[@as PrimaryStage]]
@@ -1,3 +1,4 @@
local Stage = require("classes.stageClasses.Stages.BaseStage.Stage")
---@class WaitingStage : Stage
---@field private _waitTimeSeconds integer
@@ -18,8 +19,6 @@ local WaitingStageInitData = {}
---@param spawnManager SpawnManager
---@return WaitingStage
function WaitingStage.New(database, stageConfig, logger, initData, spawnManager)
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
setmetatable(WaitingStage, Stage)
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 MaxLoadConfig = require("classes.stageClasses.helpers.MaxLoadConfig")
env.info("Spearhead SupplyUnitsTracker loaded")
---@class SupplyUnitEventListener
---@field supplyUnitSpawned fun(self:SupplyUnitEventListener, unit:Unit) | 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
---@field runwayBombingTracker RunwayBombingTracker
---@field private _runway Runway
@@ -23,7 +27,6 @@ local RunwayStrikeMission = {}
---@return RunwayStrikeMission?
function RunwayStrikeMission.new(runway, airbaseName, database, logger, runwayBombingTracker)
local Mission = Spearhead.classes.stageClasses.missions.baseMissions.Mission
RunwayStrikeMission.__index = RunwayStrikeMission
setmetatable(RunwayStrikeMission, Mission)
local self = setmetatable({}, RunwayStrikeMission)
@@ -82,7 +85,7 @@ function RunwayStrikeMission:RunwayHit(impactPoint, explosiveMass)
for _, section in pairs(self._runwaySections) do
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
section.kilosHit = 0
end
@@ -153,10 +156,10 @@ function RunwayStrikeMission:Draw()
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
Spearhead.DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
Spearhead.DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
end
end
@@ -342,7 +345,7 @@ local repairStaticConfigs = {
---@private
---@param section RunwaySection
function RunwayStrikeMission:AddOrUpdateRepairStatics(section)
if Spearhead.Util.tableLength(section.repairGroups) > 0 then
if Util.tableLength(section.repairGroups) > 0 then
return
end
@@ -351,7 +354,7 @@ function RunwayStrikeMission:AddOrUpdateRepairStatics(section)
y = section.center.y,
}
local repairGroup = Spearhead.Util.randomFromList(repairStaticConfigs)
local repairGroup = Util.randomFromList(repairStaticConfigs)
for _, repairStatic in pairs(repairGroup) do
repairStatic.x = location.x + repairStatic.x
@@ -369,7 +372,7 @@ end
---@private
---@param section RunwaySection
function RunwayStrikeMission:RemoveRepairStatics(section)
if Spearhead.Util.tableLength(section.repairGroups) == 0 then
if Util.tableLength(section.repairGroups) == 0 then
return
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
---@class ZoneMission : Mission, OnUnitLostListener
---@field private _state MissionState
@@ -26,13 +34,13 @@ local ZoneMission = {}
---@param input string
---@return ParsedMissionName?
local function ParseZoneName(input)
local split_name = Spearhead.Util.split_string(input, "_")
local split_length = Spearhead.Util.tableLength(split_name)
if Spearhead.Util.startswith(input, "RANDOMMISSION") == true and split_length < 4 then
Spearhead.AddMissionEditorWarning("Random Mission with zonename " .. input .. " not in right format")
local split_name = Util.split_string(input, "_")
local split_length = Util.tableLength(split_name)
if Util.startswith(input, "RANDOMMISSION") == true and split_length < 4 then
MissionEditorWarnings.Add("Random Mission with zonename " .. input .. " not in right format")
return nil
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
end
@@ -47,7 +55,7 @@ local function ParseZoneName(input)
if inputType == "sam" then parsedType = "SAM" end
if parsedType == "nil" then
Spearhead.AddMissionEditorWarning("Mission with zonename '" ..
MissionEditorWarnings.Add("Mission with zonename '" ..
input .. "' has an unsupported type '" .. (type or "nil"))
return nil
end
@@ -69,7 +77,6 @@ MINIMAL_UNITS_ALIVE_RATIO = 0.21
---@param spawnManager SpawnManager
---@return ZoneMission?
function ZoneMission.new(zoneName, priority, database, logger, parentStage, spawnManager)
local Mission = Spearhead.classes.stageClasses.missions.baseMissions.Mission
ZoneMission.__index = ZoneMission
setmetatable(ZoneMission, Mission)
@@ -112,8 +119,6 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
self._parentStage = parentStage
self._dependencies = {}
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup
if missionData.dependsOn then
for _, dependency in pairs(missionData.dependsOn) do
self._dependencies[dependency] = false
@@ -129,7 +134,7 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
end
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
end
@@ -145,10 +150,10 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
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
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
self._missionGroups.unitsAlive[groupName] = {}
@@ -167,18 +172,18 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
self._missionGroups.targetsAlive[groupName][unitName] = true
end
Spearhead.Events.addOnUnitLostEventListener(unitName, self)
Events.addOnUnitLostEventListener(unitName, self)
end
spearheadGroup:Destroy()
end
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
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
end
@@ -327,7 +332,7 @@ function ZoneMission:UpdateState(checkHealth, messageIfDone)
end
if self._state == "COMPLETED" and self._lastContactMarkerID then
Spearhead.DcsUtil.RemoveMark(self._lastContactMarkerID)
DcsUtil.RemoveMark(self._lastContactMarkerID)
end
if self._state == "COMPLETED" and self._battleManager then
@@ -511,10 +516,10 @@ function ZoneMission:MarkLastContact(unit)
if self._lastContactMarkerID then
Spearhead.DcsUtil.RemoveMark(self._lastContactMarkerID)
DcsUtil.RemoveMark(self._lastContactMarkerID)
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
return ZoneMission
+2 -1
View File
@@ -1,4 +1,5 @@
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.
---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
object:hasAttribute("Buildings")
then
local obj = Spearhead.classes.stageClasses.Groups.SpearheadSceneryObject.New(object["id_"])
local obj = SpearheadSceneryObject.New(object["id_"])
table.insert(sceneryObjects, obj)
end
end