diff --git a/_miz/SPEARHEADDEV.miz b/_miz/SPEARHEADDEV.miz index 63e9caa..aa7e076 100644 Binary files a/_miz/SPEARHEADDEV.miz and b/_miz/SPEARHEADDEV.miz differ diff --git a/classes/spearhead_db.lua b/classes/spearhead_db.lua index 9330072..7d583e7 100644 --- a/classes/spearhead_db.lua +++ b/classes/spearhead_db.lua @@ -1,4 +1,3 @@ - ---@class DatabaseTables ---@field AllZoneNames Array All Zone Names ---@field StageZoneNames Array All Stage Zone Names @@ -17,13 +16,13 @@ ---@field BlueSamDataPerZone table ---@field MissionZoneData table ---@field FarpZoneData table ----@field missionCodes table +---@field missionCodes table ---@class CapData ---@field routes Array ---@field current integer ----@class CapRoute +---@class CapRoute ---@field point1 Vec3 ---@field point2 Vec3? @@ -57,14 +56,13 @@ ---@class Database ---@field private _tables DatabaseTables ----@field private _logger Logger +---@field private _logger Logger local Database = {} ---comment ---@param Logger Logger ---@return Database function Database.New(Logger) - ---@type DatabaseTables local tables = { AllZoneNames = {}, @@ -98,7 +96,7 @@ function Database.New(Logger) do -- INIT ZONE TABLES for zone_ind, zone_data in pairs(Spearhead.DcsUtil.__trigger_zones) do local zone_name = zone_data.name - + ---@type Vec2 local zoneLocation = { x = zone_data.location.x, y = zone_data.location.y } @@ -167,13 +165,13 @@ 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, "stagebriefing", true) then + if Spearhead.Util.startswith(layer_object.name, "stagebriefing", true) then --[[ TODO: Stage Briefings ]] else - local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY, self._tables.MissionZones) + local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY, + self._tables.MissionZones) if Spearhead.Util.tableLength(inZone) >= 1 then local name = inZone[1] if name ~= nil then @@ -190,8 +188,6 @@ function Database.New(Logger) end end end - - end end end @@ -201,7 +197,6 @@ function Database.New(Logger) for _, stageZoneName in pairs(self._tables.StageZoneNames) do local stageData = self._tables.StageZones[stageZoneName] if stageData then - -- fill blue sams for _, blueSamStageName in pairs(self._tables.BlueSams) do if Spearhead.DcsUtil.isZoneInZone(blueSamStageName, stageZoneName) == true then @@ -233,33 +228,30 @@ function Database.New(Logger) -- fill airbases for _, airbase in pairs(world.getAirbases()) do local point = airbase:getPoint() - - if Spearhead.DcsUtil.isPositionInZone(point.x, point.z, stageZoneName) == true then + + if Spearhead.DcsUtil.isPositionInZone(point.x, point.z, stageZoneName) == true then if airbase:getDesc().category == 0 then table.insert(stageData.AirbaseNames, airbase:getName()) end end end - - for _, missionZone in pairs(self._tables.MissionZones) do - if self._tables.DescriptionsByMission[missionZone] == nil then - Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") - end - end - - for _, missionZone in pairs(self._tables.RandomMissionZones) do - if self._tables.DescriptionsByMission[missionZone] == nil then - Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") - end - end - end end - - for _, farpZoneName in pairs(self._tables.AllFarpZones) do - - for _, airbase in pairs(world.getAirbases()) do + for _, missionZone in pairs(self._tables.MissionZones) do + if self._tables.DescriptionsByMission[missionZone] == nil then + Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") + end + end + + for _, missionZone in pairs(self._tables.RandomMissionZones) do + if self._tables.DescriptionsByMission[missionZone] == nil then + Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing") + end + end + + for _, farpZoneName in pairs(self._tables.AllFarpZones) do + for _, airbase in pairs(world.getAirbases()) do if airbase:getDesc().category == Airbase.Category.HELIPAD then local name = airbase:getName() @@ -270,7 +262,7 @@ function Database.New(Logger) } end local position = airbase:getPoint() - if Spearhead.DcsUtil.isPositionInZone(position.x, position.z, farpZoneName) == true then + if Spearhead.DcsUtil.isPositionInZone(position.x, position.z, farpZoneName) == true then table.insert(self._tables.FarpZoneData[farpZoneName].padNames, name) end end @@ -302,16 +294,14 @@ function Database.New(Logger) self:loadAirbaseGroups() self:loadMiscGroupsInStages() - - for _, zoneData in pairs(self._tables.StageZones) do + for _, zoneData in pairs(self._tables.StageZones) do local number = zoneData.StageIndex for _, cap_route_zone in pairs(self._tables.CapRoutes) do if Spearhead.DcsUtil.isZoneInZone(cap_route_zone, zoneData.StageZoneName) == true then local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone) if zone then - ---@type CapData local capData = self._tables.CapDataPerStageNumber[number] if capData == nil then @@ -321,12 +311,12 @@ function Database.New(Logger) } self._tables.CapDataPerStageNumber[number] = capData end - + if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then - table.insert(capData.routes, { point1 = { x = zone.location.x, z = zone.location.y, y = 0 }, point2 = nil }) + table.insert(capData.routes, + { point1 = { x = zone.location.x, z = zone.location.y, y = 0 }, point2 = nil }) else - local biggest = nil local biggestA = nil local biggestB = nil @@ -382,10 +372,8 @@ function Database.New(Logger) return self - end - local is_group_taken = {} local getAvailableGroups = function() @@ -419,8 +407,6 @@ function Database:initAvailableUnits() end end - - ---@private function Database:loadCapUnits() local all_groups = getAvailableCAPGroups() @@ -432,13 +418,13 @@ function Database:loadCapUnits() local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName()) if zone == nil then - zone = { - location = {x = point.x, y = point.z} , + zone = { + location = { x = point.x, y = point.z }, radius = 4000, name = "temp_zone", verts = {}, zone_type = "Cilinder" - } + } end @@ -503,7 +489,6 @@ end function Database:loadFarpGroups() local all_groups = getAvailableGroups() for _, farpZone in pairs(self._tables.AllFarpZones) do - if self._tables.FarpZoneData[farpZone] == nil then self._tables.FarpZoneData[farpZone] = { groups = {}, @@ -520,10 +505,8 @@ function Database:loadFarpGroups() end function Database:loadAirbaseGroups() - local all_groups = getAvailableGroups() for _, stageZone in pairs(self._tables.StageZones) do - for _, baseName in pairs(stageZone.AirbaseNames) do local base = Airbase.getByName(baseName) @@ -533,13 +516,13 @@ function Database:loadAirbaseGroups() local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(baseName) if airbaseZone == nil then - airbaseZone = { - location = {x = point.x, y = point.z} , + airbaseZone = { + location = { x = point.x, y = point.z }, radius = 4000, name = "temp_zone", verts = {}, zone_type = "Cilinder" - } + } end @@ -601,7 +584,6 @@ function Database:loadMiscGroupsInStages() end end - function Database:GetDescriptionForMission(missionZoneName) return self._tables.DescriptionsByMission[missionZoneName] end @@ -642,16 +624,15 @@ function Database:getCapRouteInZone(stageNumber, baseName) local stageZoneName = Spearhead.Util.randomFromList(self._tables.StageZonesByNumber[stageNumber]) or "none" local stagezone = Spearhead.DcsUtil.getZoneByName(stageZoneName) if stagezone then - ---@type Airbase? local base = Airbase.getByName(baseName) if base then local closest = nil if stagezone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then - closest = GetClosestPointOnCircle({ x = stagezone.location.x, z = stagezone.location.y }, stagezone.radius, + closest = GetClosestPointOnCircle({ x = stagezone.location.x, z = stagezone.location.y }, + stagezone.radius, base:getPoint()) else - local closestDistance = -1 for _, vert in pairs(stagezone.verts) do local pos = base:getPoint() @@ -676,7 +657,6 @@ function Database:getCapRouteInZone(stageNumber, baseName) end end - ---@return Array result a list of stage zone names function Database:getStagezoneNames() return self._tables.StageZoneNames @@ -715,7 +695,6 @@ end ---@param stageName string ---@return table result airbase Names function Database:getAirbaseNamesInStage(stageName) - local stageData = self._tables.StageZones[stageName] if not stageData then return {} end @@ -735,8 +714,6 @@ function Database:getFarpDataForZone(farpZoneName) return farpData end - - ---@param airbaseName string ---@return Array function Database:getCapGroupsAtAirbase(airbaseName) @@ -801,6 +778,5 @@ function Database:GetNewMissionCode() ]] end - if not Spearhead then Spearhead = {} end Spearhead.DB = Database diff --git a/classes/stageClasses/GlobalStageManager.lua b/classes/stageClasses/GlobalStageManager.lua index 015a885..c92d75c 100644 --- a/classes/stageClasses/GlobalStageManager.lua +++ b/classes/stageClasses/GlobalStageManager.lua @@ -208,6 +208,9 @@ GlobalStageManager.printFullOverview = function () local logger = Spearhead.LoggerTemplate.new("StageOverview", "INFO") logger:info("Stage overview:") + + local max = 0 + local lines = {} for stageIndex, stages in pairs(StagesByIndex) do local totalStrike = 0 @@ -224,9 +227,23 @@ GlobalStageManager.printFullOverview = function () totaldead = totaldead + dead totalMissions = totalMissions + strike + dead + bai end - logger:info("Stage# " .. tostring(stageIndex).. " | " .. totalStrike .. " strikes | " .. totaldead .. " dead | " .. totalbai .. " BAI | Total:" .. totalMissions) + + local index = tonumber(stageIndex) + if index then + if index > max then + max = index + end + lines[index] ="Stage# " .. tostring(stageIndex).. " | " .. totalStrike .. " strikes | " .. totaldead .. " dead | " .. totalbai .. " BAI | Total:" .. totalMissions + else + logger:warn("Stage index is not a number: " .. stageIndex) + end end + for i = 1, max do + if lines[i] then + logger:info(lines[i]) + end + end end diff --git a/config.lua b/config.lua index 1a6a57c..b7fbe2d 100644 --- a/config.lua +++ b/config.lua @@ -1,6 +1,7 @@ SpearheadConfig = { + ---DEBUG LOGGING debugEnabled = false, -- default false CapConfig = { @@ -60,9 +61,6 @@ SpearheadConfig = { -- Amount of stages that are pre-activated on top of the current active stage. -- In Pre-activated the missions are not listed, but SAMs and Airbase groups are spawned. preactivateStage = 1, -- default 1 - - ---DEBUG logging. Consider keeping this disabled - debugEnabled = false }, Persistence = { --- io and lfs cannot be sanitized in the MissionScripting.lua