Binary file not shown.
+36
-60
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
---@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
|
||||||
@@ -17,13 +16,13 @@
|
|||||||
---@field BlueSamDataPerZone table<string, BlueSamData>
|
---@field BlueSamDataPerZone table<string, BlueSamData>
|
||||||
---@field MissionZoneData table<string, MissionZoneData>
|
---@field MissionZoneData table<string, MissionZoneData>
|
||||||
---@field FarpZoneData table<string,FarpZoneData>
|
---@field FarpZoneData table<string,FarpZoneData>
|
||||||
---@field missionCodes table<string, boolean>
|
---@field missionCodes table<string, boolean>
|
||||||
|
|
||||||
---@class CapData
|
---@class CapData
|
||||||
---@field routes Array<CapRoute>
|
---@field routes Array<CapRoute>
|
||||||
---@field current integer
|
---@field current integer
|
||||||
|
|
||||||
---@class CapRoute
|
---@class CapRoute
|
||||||
---@field point1 Vec3
|
---@field point1 Vec3
|
||||||
---@field point2 Vec3?
|
---@field point2 Vec3?
|
||||||
|
|
||||||
@@ -57,14 +56,13 @@
|
|||||||
|
|
||||||
---@class Database
|
---@class Database
|
||||||
---@field private _tables DatabaseTables
|
---@field private _tables DatabaseTables
|
||||||
---@field private _logger Logger
|
---@field private _logger Logger
|
||||||
local Database = {}
|
local Database = {}
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param Logger Logger
|
---@param Logger Logger
|
||||||
---@return Database
|
---@return Database
|
||||||
function Database.New(Logger)
|
function Database.New(Logger)
|
||||||
|
|
||||||
---@type DatabaseTables
|
---@type DatabaseTables
|
||||||
local tables = {
|
local tables = {
|
||||||
AllZoneNames = {},
|
AllZoneNames = {},
|
||||||
@@ -98,7 +96,7 @@ function Database.New(Logger)
|
|||||||
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(Spearhead.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 }
|
||||||
|
|
||||||
@@ -167,13 +165,13 @@ 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, "stagebriefing", true) then
|
||||||
if Spearhead.Util.startswith(layer_object.name, "stagebriefing", true) then
|
|
||||||
--[[
|
--[[
|
||||||
TODO: Stage Briefings
|
TODO: Stage Briefings
|
||||||
]]
|
]]
|
||||||
else
|
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
|
if Spearhead.Util.tableLength(inZone) >= 1 then
|
||||||
local name = inZone[1]
|
local name = inZone[1]
|
||||||
if name ~= nil then
|
if name ~= nil then
|
||||||
@@ -190,8 +188,6 @@ function Database.New(Logger)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -201,7 +197,6 @@ function Database.New(Logger)
|
|||||||
for _, stageZoneName in pairs(self._tables.StageZoneNames) do
|
for _, stageZoneName in pairs(self._tables.StageZoneNames) do
|
||||||
local stageData = self._tables.StageZones[stageZoneName]
|
local stageData = self._tables.StageZones[stageZoneName]
|
||||||
if stageData then
|
if stageData then
|
||||||
|
|
||||||
-- 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 Spearhead.DcsUtil.isZoneInZone(blueSamStageName, stageZoneName) == true then
|
||||||
@@ -233,33 +228,30 @@ function Database.New(Logger)
|
|||||||
-- fill airbases
|
-- fill airbases
|
||||||
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 Spearhead.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())
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
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
|
if airbase:getDesc().category == Airbase.Category.HELIPAD then
|
||||||
local name = airbase:getName()
|
local name = airbase:getName()
|
||||||
|
|
||||||
@@ -270,7 +262,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 Spearhead.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
|
||||||
@@ -302,16 +294,14 @@ function Database.New(Logger)
|
|||||||
self:loadAirbaseGroups()
|
self:loadAirbaseGroups()
|
||||||
self:loadMiscGroupsInStages()
|
self:loadMiscGroupsInStages()
|
||||||
|
|
||||||
|
|
||||||
for _, zoneData in pairs(self._tables.StageZones) do
|
|
||||||
|
|
||||||
|
for _, zoneData in pairs(self._tables.StageZones) do
|
||||||
local number = zoneData.StageIndex
|
local number = zoneData.StageIndex
|
||||||
|
|
||||||
for _, cap_route_zone in pairs(self._tables.CapRoutes) do
|
for _, cap_route_zone in pairs(self._tables.CapRoutes) do
|
||||||
if Spearhead.DcsUtil.isZoneInZone(cap_route_zone, zoneData.StageZoneName) == true then
|
if Spearhead.DcsUtil.isZoneInZone(cap_route_zone, zoneData.StageZoneName) == true then
|
||||||
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone)
|
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone)
|
||||||
if zone then
|
if zone then
|
||||||
|
|
||||||
---@type CapData
|
---@type CapData
|
||||||
local capData = self._tables.CapDataPerStageNumber[number]
|
local capData = self._tables.CapDataPerStageNumber[number]
|
||||||
if capData == nil then
|
if capData == nil then
|
||||||
@@ -321,12 +311,12 @@ function Database.New(Logger)
|
|||||||
}
|
}
|
||||||
self._tables.CapDataPerStageNumber[number] = capData
|
self._tables.CapDataPerStageNumber[number] = capData
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
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
|
else
|
||||||
|
|
||||||
local biggest = nil
|
local biggest = nil
|
||||||
local biggestA = nil
|
local biggestA = nil
|
||||||
local biggestB = nil
|
local biggestB = nil
|
||||||
@@ -382,10 +372,8 @@ function Database.New(Logger)
|
|||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local is_group_taken = {}
|
local is_group_taken = {}
|
||||||
|
|
||||||
local getAvailableGroups = function()
|
local getAvailableGroups = function()
|
||||||
@@ -419,8 +407,6 @@ function Database:initAvailableUnits()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function Database:loadCapUnits()
|
function Database:loadCapUnits()
|
||||||
local all_groups = getAvailableCAPGroups()
|
local all_groups = getAvailableCAPGroups()
|
||||||
@@ -432,13 +418,13 @@ function Database:loadCapUnits()
|
|||||||
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName())
|
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbase:getName())
|
||||||
|
|
||||||
if zone == nil then
|
if zone == nil then
|
||||||
zone = {
|
zone = {
|
||||||
location = {x = point.x, y = point.z} ,
|
location = { x = point.x, y = point.z },
|
||||||
radius = 4000,
|
radius = 4000,
|
||||||
name = "temp_zone",
|
name = "temp_zone",
|
||||||
verts = {},
|
verts = {},
|
||||||
zone_type = "Cilinder"
|
zone_type = "Cilinder"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -503,7 +489,6 @@ end
|
|||||||
function Database:loadFarpGroups()
|
function Database:loadFarpGroups()
|
||||||
local all_groups = getAvailableGroups()
|
local all_groups = getAvailableGroups()
|
||||||
for _, farpZone in pairs(self._tables.AllFarpZones) do
|
for _, farpZone in pairs(self._tables.AllFarpZones) do
|
||||||
|
|
||||||
if self._tables.FarpZoneData[farpZone] == nil then
|
if self._tables.FarpZoneData[farpZone] == nil then
|
||||||
self._tables.FarpZoneData[farpZone] = {
|
self._tables.FarpZoneData[farpZone] = {
|
||||||
groups = {},
|
groups = {},
|
||||||
@@ -520,10 +505,8 @@ function Database:loadFarpGroups()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Database:loadAirbaseGroups()
|
function Database:loadAirbaseGroups()
|
||||||
|
|
||||||
local all_groups = getAvailableGroups()
|
local all_groups = getAvailableGroups()
|
||||||
for _, stageZone in pairs(self._tables.StageZones) do
|
for _, stageZone in pairs(self._tables.StageZones) do
|
||||||
|
|
||||||
for _, baseName in pairs(stageZone.AirbaseNames) do
|
for _, baseName in pairs(stageZone.AirbaseNames) do
|
||||||
local base = Airbase.getByName(baseName)
|
local base = Airbase.getByName(baseName)
|
||||||
|
|
||||||
@@ -533,13 +516,13 @@ function Database:loadAirbaseGroups()
|
|||||||
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(baseName)
|
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneByName(baseName)
|
||||||
|
|
||||||
if airbaseZone == nil then
|
if airbaseZone == nil then
|
||||||
airbaseZone = {
|
airbaseZone = {
|
||||||
location = {x = point.x, y = point.z} ,
|
location = { x = point.x, y = point.z },
|
||||||
radius = 4000,
|
radius = 4000,
|
||||||
name = "temp_zone",
|
name = "temp_zone",
|
||||||
verts = {},
|
verts = {},
|
||||||
zone_type = "Cilinder"
|
zone_type = "Cilinder"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -601,7 +584,6 @@ function Database:loadMiscGroupsInStages()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Database:GetDescriptionForMission(missionZoneName)
|
function Database:GetDescriptionForMission(missionZoneName)
|
||||||
return self._tables.DescriptionsByMission[missionZoneName]
|
return self._tables.DescriptionsByMission[missionZoneName]
|
||||||
end
|
end
|
||||||
@@ -642,16 +624,15 @@ function Database:getCapRouteInZone(stageNumber, baseName)
|
|||||||
local stageZoneName = Spearhead.Util.randomFromList(self._tables.StageZonesByNumber[stageNumber]) or "none"
|
local stageZoneName = Spearhead.Util.randomFromList(self._tables.StageZonesByNumber[stageNumber]) or "none"
|
||||||
local stagezone = Spearhead.DcsUtil.getZoneByName(stageZoneName)
|
local stagezone = Spearhead.DcsUtil.getZoneByName(stageZoneName)
|
||||||
if stagezone then
|
if stagezone then
|
||||||
|
|
||||||
---@type Airbase?
|
---@type Airbase?
|
||||||
local base = Airbase.getByName(baseName)
|
local base = Airbase.getByName(baseName)
|
||||||
if base then
|
if base then
|
||||||
local closest = nil
|
local closest = nil
|
||||||
if stagezone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
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())
|
base:getPoint())
|
||||||
else
|
else
|
||||||
|
|
||||||
local closestDistance = -1
|
local closestDistance = -1
|
||||||
for _, vert in pairs(stagezone.verts) do
|
for _, vert in pairs(stagezone.verts) do
|
||||||
local pos = base:getPoint()
|
local pos = base:getPoint()
|
||||||
@@ -676,7 +657,6 @@ function Database:getCapRouteInZone(stageNumber, baseName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@return Array<string> result a list of stage zone names
|
---@return Array<string> result a list of stage zone names
|
||||||
function Database:getStagezoneNames()
|
function Database:getStagezoneNames()
|
||||||
return self._tables.StageZoneNames
|
return self._tables.StageZoneNames
|
||||||
@@ -715,7 +695,6 @@ end
|
|||||||
---@param stageName string
|
---@param stageName string
|
||||||
---@return table result airbase Names
|
---@return table result airbase Names
|
||||||
function Database:getAirbaseNamesInStage(stageName)
|
function Database:getAirbaseNamesInStage(stageName)
|
||||||
|
|
||||||
local stageData = self._tables.StageZones[stageName]
|
local stageData = self._tables.StageZones[stageName]
|
||||||
if not stageData then return {} end
|
if not stageData then return {} end
|
||||||
|
|
||||||
@@ -735,8 +714,6 @@ function Database:getFarpDataForZone(farpZoneName)
|
|||||||
return farpData
|
return farpData
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---@param airbaseName string
|
---@param airbaseName string
|
||||||
---@return Array<string>
|
---@return Array<string>
|
||||||
function Database:getCapGroupsAtAirbase(airbaseName)
|
function Database:getCapGroupsAtAirbase(airbaseName)
|
||||||
@@ -801,6 +778,5 @@ function Database:GetNewMissionCode()
|
|||||||
]]
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if not Spearhead then Spearhead = {} end
|
if not Spearhead then Spearhead = {} end
|
||||||
Spearhead.DB = Database
|
Spearhead.DB = Database
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ GlobalStageManager.printFullOverview = function ()
|
|||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate.new("StageOverview", "INFO")
|
local logger = Spearhead.LoggerTemplate.new("StageOverview", "INFO")
|
||||||
logger:info("Stage overview:")
|
logger:info("Stage overview:")
|
||||||
|
|
||||||
|
local max = 0
|
||||||
|
local lines = {}
|
||||||
for stageIndex, stages in pairs(StagesByIndex) do
|
for stageIndex, stages in pairs(StagesByIndex) do
|
||||||
|
|
||||||
local totalStrike = 0
|
local totalStrike = 0
|
||||||
@@ -224,9 +227,23 @@ GlobalStageManager.printFullOverview = function ()
|
|||||||
totaldead = totaldead + dead
|
totaldead = totaldead + dead
|
||||||
totalMissions = totalMissions + strike + dead + bai
|
totalMissions = totalMissions + strike + dead + bai
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
for i = 1, max do
|
||||||
|
if lines[i] then
|
||||||
|
logger:info(lines[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
SpearheadConfig = {
|
SpearheadConfig = {
|
||||||
|
|
||||||
|
---DEBUG LOGGING
|
||||||
debugEnabled = false, -- default false
|
debugEnabled = false, -- default false
|
||||||
|
|
||||||
CapConfig = {
|
CapConfig = {
|
||||||
@@ -60,9 +61,6 @@ SpearheadConfig = {
|
|||||||
-- Amount of stages that are pre-activated on top of the current active stage.
|
-- 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.
|
-- In Pre-activated the missions are not listed, but SAMs and Airbase groups are spawned.
|
||||||
preactivateStage = 1, -- default 1
|
preactivateStage = 1, -- default 1
|
||||||
|
|
||||||
---DEBUG logging. Consider keeping this disabled
|
|
||||||
debugEnabled = false
|
|
||||||
},
|
},
|
||||||
Persistence = {
|
Persistence = {
|
||||||
--- io and lfs cannot be sanitized in the MissionScripting.lua
|
--- io and lfs cannot be sanitized in the MissionScripting.lua
|
||||||
|
|||||||
Reference in New Issue
Block a user