Working pre-activation and overhaul of drawings
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
local briefingMessageTime = nil
|
local briefingMessageTime = nil
|
||||||
|
|
||||||
---@class GlobalConfig
|
---@class GlobalConfig
|
||||||
---@field private _briefingTime number ;
|
---@field private _briefingTime number
|
||||||
|
---@field private _debugEnabled boolean
|
||||||
local GlobalConfig = {}
|
local GlobalConfig = {}
|
||||||
GlobalConfig.__index = GlobalConfig;
|
GlobalConfig.__index = GlobalConfig;
|
||||||
|
|
||||||
@@ -19,6 +20,13 @@ function GlobalConfig.New()
|
|||||||
if SpearheadConfig.briefingMessageDuration then
|
if SpearheadConfig.briefingMessageDuration then
|
||||||
self._briefingTime = SpearheadConfig.briefingMessageDuration
|
self._briefingTime = SpearheadConfig.briefingMessageDuration
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if SpearheadConfig.debugEnabled ~= nil then
|
||||||
|
self._debugEnabled = SpearheadConfig.debugEnabled
|
||||||
|
else
|
||||||
|
self._debugEnabled = false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -28,6 +36,10 @@ function GlobalConfig:getBriefingTime()
|
|||||||
return self._briefingTime or 60
|
return self._briefingTime or 60
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function GlobalConfig:isDebugEnabled()
|
||||||
|
return self._debugEnabled or false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return GlobalConfig
|
return GlobalConfig
|
||||||
|
|
||||||
|
|||||||
@@ -9,26 +9,38 @@
|
|||||||
--- @field AmountPreactivateStage integer
|
--- @field AmountPreactivateStage integer
|
||||||
local StageConfig = {};
|
local StageConfig = {};
|
||||||
|
|
||||||
|
local Logger = require("classes.util.Logger")
|
||||||
|
local _logger = Logger.new("StageConfig", Logger.LogLevel)
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@return StageConfig
|
---@return StageConfig
|
||||||
function StageConfig:new()
|
function StageConfig:new()
|
||||||
|
|
||||||
if SpearheadConfig == nil then SpearheadConfig = {} end
|
if SpearheadConfig == nil then
|
||||||
if SpearheadConfig.StageConfig == nil then SpearheadConfig.StageConfig = {} end
|
_logger:warn("SpearheadConfig is nil, creating default SpearheadConfig")
|
||||||
|
SpearheadConfig = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if SpearheadConfig.StageConfig == nil then
|
||||||
|
_logger:warn("SpearheadConfig.StageConfig is nil, creating default StageConfig")
|
||||||
|
SpearheadConfig.StageConfig = {}
|
||||||
|
end
|
||||||
|
|
||||||
---@type StageConfig
|
---@type StageConfig
|
||||||
local o = {
|
local o = {
|
||||||
isEnabled = SpearheadConfig.StageConfig.enabled or true,
|
isEnabled = SpearheadConfig.StageConfig.enabled ~= false,
|
||||||
isDrawStagesEnabled = SpearheadConfig.StageConfig.drawStages or true,
|
isDrawStagesEnabled = SpearheadConfig.StageConfig.drawStages ~= false,
|
||||||
isAutoStages = SpearheadConfig.StageConfig.autoStages or true,
|
isAutoStages = SpearheadConfig.StageConfig.autoStages ~= false,
|
||||||
startingStage = SpearheadConfig.StageConfig.startingStage or 1,
|
startingStage = SpearheadConfig.StageConfig.startingStage or 1,
|
||||||
maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage or 10,
|
maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage or 10,
|
||||||
isDrawPreActivatedEnabled = SpearheadConfig.StageConfig.drawPreActivated or true,
|
isDrawPreActivatedEnabled = SpearheadConfig.StageConfig.drawPreActivated ~= false,
|
||||||
AmountPreactivateStage = SpearheadConfig.StageConfig.preactivateStage or 1,
|
AmountPreactivateStage = SpearheadConfig.StageConfig.preactivateStage or 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
setmetatable(o, { __index = self })
|
setmetatable(o, { __index = self })
|
||||||
|
|
||||||
|
_logger:info("Successfully created StageConfig Object")
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ function Database.New(Logger)
|
|||||||
for key, layer_object in pairs(layer.objects) do
|
for key, layer_object in pairs(layer.objects) do
|
||||||
if Util.startswith(layer_object.name, "drawing_", true) then
|
if Util.startswith(layer_object.name, "drawing_", true) then
|
||||||
local object = layer_object --[[@as DrawingObject]]
|
local object = layer_object --[[@as DrawingObject]]
|
||||||
local customDrawing = CustomDrawing.New(object, nil, self._logger.LogLevel)
|
local customDrawing = CustomDrawing.New(object)
|
||||||
table.insert(self._tables.CustomDrawings, customDrawing)
|
table.insert(self._tables.CustomDrawings, customDrawing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ local Util = require("classes.util.Util")
|
|||||||
local DcsUtil = require("classes.util.DcsUtil")
|
local DcsUtil = require("classes.util.DcsUtil")
|
||||||
local SupplyUnitsTracker = require("classes.stageClasses.helpers.SupplyUnitsTracker")
|
local SupplyUnitsTracker = require("classes.stageClasses.helpers.SupplyUnitsTracker")
|
||||||
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
||||||
|
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
|
||||||
|
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||||
|
|
||||||
---@class SupplyHub
|
---@class SupplyHub
|
||||||
---@field private _database Database
|
---@field private _database Database
|
||||||
@@ -12,7 +14,7 @@ local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionComma
|
|||||||
---@field private _isCommmandAdded table<string, boolean>
|
---@field private _isCommmandAdded table<string, boolean>
|
||||||
---@field private _missionCommandsHelper MissionCommandsHelper
|
---@field private _missionCommandsHelper MissionCommandsHelper
|
||||||
---@field private _inZone table<string, boolean>
|
---@field private _inZone table<string, boolean>
|
||||||
---@field private _drawID number
|
---@field private _customDrawing CustomDrawing?
|
||||||
---@field private _cargoInUnits table<table<string, number>>
|
---@field private _cargoInUnits table<table<string, number>>
|
||||||
---@field private _activeAtStart boolean
|
---@field private _activeAtStart boolean
|
||||||
---@field private _active boolean
|
---@field private _active boolean
|
||||||
@@ -30,6 +32,7 @@ function SupplyHub.new(database, logger, zoneName)
|
|||||||
self._database = database
|
self._database = database
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
self._zoneName = zoneName
|
self._zoneName = zoneName
|
||||||
|
self._customDrawing = nil
|
||||||
|
|
||||||
local split = Util.split_string(zoneName, "_")
|
local split = Util.split_string(zoneName, "_")
|
||||||
if string.lower(split[2]) == "a" then
|
if string.lower(split[2]) == "a" then
|
||||||
@@ -72,13 +75,13 @@ function SupplyHub:Activate()
|
|||||||
self._logger:debug("Activating Supply Hub zone: " .. self._zoneName)
|
self._logger:debug("Activating Supply Hub zone: " .. self._zoneName)
|
||||||
|
|
||||||
local zone = DcsUtil.getZoneByName(self._zoneName)
|
local zone = DcsUtil.getZoneByName(self._zoneName)
|
||||||
if zone and self._drawID == nil then
|
if zone and self._customDrawing == nil then
|
||||||
---@type DrawColor
|
local fillColor = DrawingHelper.ColorTableToColorString({ 0, 1, 0, 0.2 })
|
||||||
local fillColor = { r=0, g=1, b=0, a=0.2 }
|
local lineColor = DrawingHelper.ColorTableToColorString({ 0, 1, 0, 1})
|
||||||
---@type DrawColor
|
|
||||||
local lineColor = { r=0, g=1, b=0, a=1}
|
|
||||||
local lineStyle = 1
|
local lineStyle = 1
|
||||||
self._drawID = DcsUtil.DrawZone(zone, lineColor, fillColor, lineStyle)
|
|
||||||
|
self._customDrawing = CustomDrawing.FromZone(zone, lineColor, fillColor, lineStyle, 6)
|
||||||
|
self._customDrawing:Draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
self._supplyUnitsTracker:RegisterHub(self)
|
self._supplyUnitsTracker:RegisterHub(self)
|
||||||
|
|||||||
@@ -45,18 +45,15 @@ local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelpe
|
|||||||
--- @field zoneName string
|
--- @field zoneName string
|
||||||
--- @field stageName string?
|
--- @field stageName string?
|
||||||
--- @field stageNumber number
|
--- @field stageNumber number
|
||||||
|
--- @field protected _currentStageState CurrentStageState
|
||||||
--- @field protected _missionCommandsHelper MissionCommandsHelper
|
--- @field protected _missionCommandsHelper MissionCommandsHelper
|
||||||
--- @field protected _isActive boolean
|
|
||||||
--- @field protected _isComplete boolean
|
|
||||||
--- @field protected _missionPriority MissionPriority
|
--- @field protected _missionPriority MissionPriority
|
||||||
--- @field protected _database Database
|
--- @field protected _database Database
|
||||||
--- @field protected _db StageData
|
--- @field protected _db StageData
|
||||||
--- @field protected _logger Logger
|
--- @field protected _logger Logger
|
||||||
--- @field protected _preActivated boolean
|
|
||||||
--- @field protected _activeStage integer
|
--- @field protected _activeStage integer
|
||||||
--- @field protected _stageConfig StageConfig
|
--- @field protected _stageConfig StageConfig
|
||||||
--- @field protected _stageDrawing DrawingObject
|
--- @field protected _customDrawing CustomDrawing
|
||||||
--- @field protected _currentDrawingId integer
|
|
||||||
--- @field protected _spawnedGroups Array<string>
|
--- @field protected _spawnedGroups Array<string>
|
||||||
--- @field protected _stageCompleteListeners Array<StageCompleteListener>
|
--- @field protected _stageCompleteListeners Array<StageCompleteListener>
|
||||||
--- @field protected CheckContinuousAsync fun(self:Stage, time:number) : number?
|
--- @field protected CheckContinuousAsync fun(self:Stage, time:number) : number?
|
||||||
@@ -66,11 +63,18 @@ local Stage = {}
|
|||||||
|
|
||||||
Stage.__index = Stage
|
Stage.__index = Stage
|
||||||
|
|
||||||
|
---@enum CurrentStageState
|
||||||
|
Stage.CurrentStageState = {
|
||||||
|
INACTIVE = 0,
|
||||||
|
PREACTIVATED = 1,
|
||||||
|
ACTIVE = 2,
|
||||||
|
BLUE = 3
|
||||||
|
}
|
||||||
|
|
||||||
Stage.StageColors = {
|
Stage.StageColors = {
|
||||||
INVISIBLE = { 0, 0, 0, 0 },
|
INVISIBLE = { 0, 0, 0, 0 },
|
||||||
RED_ACTIVE = { 1, 0, 0, 0.15 },
|
RED_ACTIVE = { 1, 0, 0, 0.20 },
|
||||||
RED_PREACTIVE = { 1, 0, 0, 0.10},
|
RED_PREACTIVE = { 1, 0, 0, 0.05},
|
||||||
BLUE = { 0, 0, 1, 0.10},
|
BLUE = { 0, 0, 1, 0.10},
|
||||||
GRAY = { 80/255, 80/255, 80/255, 0.10 }
|
GRAY = { 80/255, 80/255, 80/255, 0.10 }
|
||||||
}
|
}
|
||||||
@@ -86,12 +90,11 @@ Stage.StageColors = {
|
|||||||
function Stage:superNew(database, stageConfig, logger, initData, missionPriority, spawnManager)
|
function Stage:superNew(database, stageConfig, logger, initData, missionPriority, spawnManager)
|
||||||
|
|
||||||
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
|
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
|
||||||
|
self._currentStageState = Stage.CurrentStageState.INACTIVE
|
||||||
self.zoneName = initData.stageZoneName
|
self.zoneName = initData.stageZoneName
|
||||||
self.stageNumber = initData.stageNumber
|
self.stageNumber = initData.stageNumber
|
||||||
self._isActive = false
|
|
||||||
self._isComplete = false
|
|
||||||
self.stageName = initData.stageDisplayName
|
self.stageName = initData.stageDisplayName
|
||||||
|
self._currentStageState = Stage.CurrentStageState.INACTIVE
|
||||||
|
|
||||||
self.OnPostStageComplete = nil
|
self.OnPostStageComplete = nil
|
||||||
self.OnPostBlueActivated = nil
|
self.OnPostBlueActivated = nil
|
||||||
@@ -113,39 +116,18 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
|||||||
}
|
}
|
||||||
|
|
||||||
self._activeStage = -99
|
self._activeStage = -99
|
||||||
self._preActivated = false
|
|
||||||
self._stageConfig = stageConfig or {}
|
self._stageConfig = stageConfig or {}
|
||||||
self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
|
self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
|
||||||
|
|
||||||
local zone = DcsUtil.getZoneByName(self.zoneName)
|
local zone = DcsUtil.getZoneByName(self.zoneName)
|
||||||
if zone then
|
if zone then
|
||||||
if zone.zone_type == "Cilinder" then
|
|
||||||
---@type Circle
|
|
||||||
local drawing = {
|
|
||||||
colorString = DrawingHelper.ColorTableToColorString( Stage.StageColors.INVISIBLE),
|
|
||||||
mapX = zone.location.x,
|
|
||||||
mapY = zone.location.y,
|
|
||||||
radius = zone.radius,
|
|
||||||
name = "DRAWING_" .. zone.name,
|
|
||||||
polygonMode = "circle",
|
|
||||||
primitiveType = "Polygon",
|
|
||||||
thickness = 1,
|
|
||||||
fillColorString = DrawingHelper.ColorTableToColorString( Stage.StageColors.INVISIBLE),
|
|
||||||
visible = true,
|
|
||||||
style = "solid"
|
|
||||||
}
|
|
||||||
|
|
||||||
self._stageDrawing = drawing
|
local colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||||
else
|
local fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||||
local verts = {}
|
|
||||||
|
|
||||||
---@type Free
|
|
||||||
local drawing = {
|
|
||||||
mapX = zone.location.x,
|
|
||||||
mapY = zone.location.y,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
local customDrawing = CustomDrawing.FromZone(zone, colorString, fillColorString, 1, 5)
|
||||||
|
if customDrawing then
|
||||||
|
self._customDrawing = customDrawing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -291,7 +273,7 @@ end
|
|||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Stage:IsComplete()
|
function Stage:IsComplete()
|
||||||
if self._isComplete == true then return true end
|
if self._currentStageState == Stage.CurrentStageState.BLUE then return true end
|
||||||
|
|
||||||
for i, mission in pairs(self._db.sams) do
|
for i, mission in pairs(self._db.sams) do
|
||||||
local state = mission:getState()
|
local state = mission:getState()
|
||||||
@@ -307,13 +289,13 @@ function Stage:IsComplete()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self._isComplete = true
|
self._currentStageState = Stage.CurrentStageState.BLUE
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Stage:IsActive()
|
function Stage:IsActive()
|
||||||
return self._isActive == true
|
return self._currentStageState == Stage.CurrentStageState.ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
@@ -399,8 +381,8 @@ end
|
|||||||
|
|
||||||
---Activates all SAMS, Airbase units etc all at once.
|
---Activates all SAMS, Airbase units etc all at once.
|
||||||
function Stage:PreActivate()
|
function Stage:PreActivate()
|
||||||
if self._preActivated == false then
|
if self._currentStageState == Stage.CurrentStageState.INACTIVE then
|
||||||
self._preActivated = true
|
self._currentStageState = Stage.CurrentStageState.PREACTIVATED
|
||||||
for key, mission in pairs(self._db.sams) do
|
for key, mission in pairs(self._db.sams) do
|
||||||
if mission then
|
if mission then
|
||||||
mission:SpawnInactive()
|
mission:SpawnInactive()
|
||||||
@@ -412,40 +394,60 @@ function Stage:PreActivate()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:MarkStage(Stage.StageColors.RED_PREACTIVE)
|
self:MarkStage()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param stageColor DrawColor
|
function Stage:MarkStage()
|
||||||
function Stage:MarkStage(stageColor)
|
|
||||||
local lineColor = { r=stageColor.r, g=stageColor.g, b=stageColor.b, a=stageColor.a }
|
|
||||||
local fillColor = { r=stageColor.r, g=stageColor.g, b=stageColor.b, a=stageColor.a }
|
|
||||||
|
|
||||||
if stageColor.a > 0 then
|
self._logger:debug("Marking stage '" .. Util.toString(self.zoneName) .. "' with state: " .. self._currentStageState)
|
||||||
lineColor.a = 1
|
|
||||||
|
if self._customDrawing then
|
||||||
|
self._customDrawing:Remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
if stageColor == Stage.StageColors.RED_PREACTIVE then
|
if self._stageConfig.isDrawStagesEnabled == false then return end
|
||||||
lineColor.a = 0
|
if self._stageConfig.isDrawPreActivatedEnabled == false and self._currentStageState == Stage.CurrentStageState.PREACTIVATED then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self._stageDrawingId and self._stageConfig.isDrawStagesEnabled == true then
|
if self._customDrawing then
|
||||||
DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
|
self._customDrawing:UpdateDrawingObject(function(drawingObject)
|
||||||
DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
|
local drawing = drawingObject --[[@as Polygon]]
|
||||||
|
if self._currentStageState == Stage.CurrentStageState.ACTIVE then
|
||||||
|
drawing.fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.RED_ACTIVE)
|
||||||
|
drawing.colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.RED_ACTIVE)
|
||||||
|
drawing.style = "dot dash"
|
||||||
|
elseif self._currentStageState == Stage.CurrentStageState.PREACTIVATED then
|
||||||
|
drawing.fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.RED_PREACTIVE)
|
||||||
|
drawing.colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.RED_PREACTIVE)
|
||||||
|
drawing.style = "no line"
|
||||||
|
elseif self._currentStageState == Stage.CurrentStageState.BLUE then
|
||||||
|
drawing.fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.BLUE)
|
||||||
|
drawing.colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.BLUE)
|
||||||
|
drawing.style = "two dash"
|
||||||
|
else
|
||||||
|
drawing.fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||||
|
drawing.colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||||
|
drawing.style = "no line"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return drawing
|
||||||
|
end)
|
||||||
|
self._customDrawing:Draw()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Stage:ActivateStage()
|
function Stage:ActivateStage()
|
||||||
self._isActive = true;
|
self._currentStageState = Stage.CurrentStageState.ACTIVE
|
||||||
|
|
||||||
pcall(function()
|
|
||||||
self:MarkStage(Stage.StageColors.RED_ACTIVE)
|
|
||||||
end)
|
|
||||||
|
|
||||||
self:PreActivate()
|
self:PreActivate()
|
||||||
|
|
||||||
|
pcall(function()
|
||||||
|
self:MarkStage()
|
||||||
|
end)
|
||||||
|
|
||||||
self._logger:debug("Activating Misc groups for zone. Count: " .. Util.tableLength(self._db.miscGroups))
|
self._logger:debug("Activating Misc groups for zone. Count: " .. Util.tableLength(self._db.miscGroups))
|
||||||
for _, miscGroup in pairs(self._db.miscGroups) do
|
for _, miscGroup in pairs(self._db.miscGroups) do
|
||||||
miscGroup:Spawn()
|
miscGroup:Spawn()
|
||||||
@@ -589,7 +591,7 @@ end
|
|||||||
function Stage:ActivateBlueStage()
|
function Stage:ActivateBlueStage()
|
||||||
|
|
||||||
self._logger:debug("Setting stage '" .. Util.toString(self.zoneName) .. "' to blue")
|
self._logger:debug("Setting stage '" .. Util.toString(self.zoneName) .. "' to blue")
|
||||||
|
self._currentStageState = Stage.CurrentStageState.BLUE
|
||||||
for _, mission in pairs(self._db.missions) do
|
for _, mission in pairs(self._db.missions) do
|
||||||
mission:SpawnPersistedState()
|
mission:SpawnPersistedState()
|
||||||
end
|
end
|
||||||
@@ -605,7 +607,7 @@ function Stage:ActivateBlueStage()
|
|||||||
---@param self Stage
|
---@param self Stage
|
||||||
local ActivateBlueAsync = function(self)
|
local ActivateBlueAsync = function(self)
|
||||||
pcall(function()
|
pcall(function()
|
||||||
self:MarkStage(Stage.StageColors.BLUE)
|
self:MarkStage()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self:ActivateBlueGroups()
|
self:ActivateBlueGroups()
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
|
|||||||
|
|
||||||
self.OnPostBlueActivated = function (selfStage)
|
self.OnPostBlueActivated = function (selfStage)
|
||||||
|
|
||||||
selfStage:MarkStage(Stage.StageColors.GRAY)
|
selfStage:MarkStage()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.OnPostStageComplete = function (selfStage)
|
self.OnPostStageComplete = function (selfStage)
|
||||||
@@ -34,7 +34,7 @@ function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param self Stage
|
---@param self ExtraStage
|
||||||
---@param number integer
|
---@param number integer
|
||||||
function ExtraStage:OnStageNumberChanged(number)
|
function ExtraStage:OnStageNumberChanged(number)
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ function ExtraStage:OnStageNumberChanged(number)
|
|||||||
self:ActivateStage()
|
self:ActivateStage()
|
||||||
end
|
end
|
||||||
|
|
||||||
if self._isComplete == true then
|
if self._currentStageState == Stage.CurrentStageState.BLUE then
|
||||||
self:ActivateBlueStage()
|
self:ActivateBlueStage()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelpe
|
|||||||
local Util = require("classes.util.Util")
|
local Util = require("classes.util.Util")
|
||||||
local Logger = require("classes.util.Logger")
|
local Logger = require("classes.util.Logger")
|
||||||
|
|
||||||
|
|
||||||
|
local drawingLogger = Logger.new("CustomDrawing")
|
||||||
|
|
||||||
---@class CustomDrawing
|
---@class CustomDrawing
|
||||||
---@field private _id integer?
|
---@field private _id integer?
|
||||||
---@field private _drawingObject DrawingObject
|
---@field private _drawingObject DrawingObject
|
||||||
@@ -14,14 +17,12 @@ CustomDrawing.__index = CustomDrawing
|
|||||||
|
|
||||||
|
|
||||||
---@param drawingObject DrawingObject
|
---@param drawingObject DrawingObject
|
||||||
---@param id integer?
|
|
||||||
---@param loglevel LogLevel
|
|
||||||
---@return CustomDrawing
|
---@return CustomDrawing
|
||||||
function CustomDrawing.New(drawingObject, id, loglevel)
|
function CustomDrawing.New(drawingObject)
|
||||||
local self = setmetatable({}, CustomDrawing)
|
local self = setmetatable({}, CustomDrawing)
|
||||||
self._drawingObject = drawingObject
|
self._drawingObject = drawingObject
|
||||||
self._id = id
|
self._id = nil -- initiate ID as nil, when drawn it will be set to the ID returned by DrawingHelper.Draw
|
||||||
self._logger = Logger.new("CustomDrawing", loglevel)
|
self._logger = drawingLogger
|
||||||
|
|
||||||
local name = drawingObject.name
|
local name = drawingObject.name
|
||||||
local split = Util.split_string(name or "", "_")
|
local split = Util.split_string(name or "", "_")
|
||||||
@@ -32,6 +33,58 @@ function CustomDrawing.New(drawingObject, id, loglevel)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param zone SpearheadTriggerZone
|
||||||
|
---@param colorString string
|
||||||
|
---@param fillColorString string
|
||||||
|
---@param lineStyle LineType
|
||||||
|
---@param lineThickness number
|
||||||
|
---@return CustomDrawing?
|
||||||
|
function CustomDrawing.FromZone(zone, colorString, fillColorString, lineStyle, lineThickness)
|
||||||
|
if zone == nil then
|
||||||
|
drawingLogger:warn("CustomDrawing.FromZone called with nil zone")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if zone.zone_type == "Cilinder" then
|
||||||
|
---@type Circle
|
||||||
|
local drawingObject = {
|
||||||
|
mapX = zone.location.x,
|
||||||
|
mapY = zone.location.y,
|
||||||
|
radius = zone.radius,
|
||||||
|
name = zone.name .. "_drawing",
|
||||||
|
primitiveType = "Polygon",
|
||||||
|
polygonMode = "circle",
|
||||||
|
visible = true,
|
||||||
|
style = DrawingHelper.ToLineStyleString(lineStyle),
|
||||||
|
colorString = colorString,
|
||||||
|
fillColorString = fillColorString,
|
||||||
|
thickness = lineThickness,
|
||||||
|
}
|
||||||
|
|
||||||
|
return CustomDrawing.New(drawingObject)
|
||||||
|
end
|
||||||
|
|
||||||
|
if zone.zone_type == "Polygon" then
|
||||||
|
|
||||||
|
---@type Free
|
||||||
|
local drawingObject = {
|
||||||
|
mapX = 0,
|
||||||
|
mapY = 0,
|
||||||
|
points = zone.verts,
|
||||||
|
name = zone.name .. "_drawing",
|
||||||
|
primitiveType = "Polygon",
|
||||||
|
polygonMode = "free",
|
||||||
|
visible = true,
|
||||||
|
style = DrawingHelper.ToLineStyleString(lineStyle),
|
||||||
|
colorString = colorString,
|
||||||
|
fillColorString = fillColorString,
|
||||||
|
thickness = lineThickness,
|
||||||
|
}
|
||||||
|
|
||||||
|
return CustomDrawing.New(drawingObject)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function CustomDrawing:GetName()
|
function CustomDrawing:GetName()
|
||||||
return self._drawingObject.name
|
return self._drawingObject.name
|
||||||
@@ -61,4 +114,9 @@ function CustomDrawing:Remove()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param updateFunc fun(drawingObject:DrawingObject):DrawingObject
|
||||||
|
function CustomDrawing:UpdateDrawingObject(updateFunc)
|
||||||
|
self._drawingObject = updateFunc(self._drawingObject)
|
||||||
|
end
|
||||||
|
|
||||||
return CustomDrawing
|
return CustomDrawing
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
local Util = require("classes.util.Util")
|
local Util = require("classes.util.Util")
|
||||||
|
local Logger = require("classes.util.Logger")
|
||||||
|
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
||||||
|
|
||||||
|
---@type LogLevel
|
||||||
|
local level = "INFO"
|
||||||
|
if GlobalConfig:isDebugEnabled() then
|
||||||
|
level = "DEBUG"
|
||||||
|
end
|
||||||
|
|
||||||
|
local drawingLogger = Logger.new("DrawingHelper", level)
|
||||||
|
|
||||||
---@class DrawingHelper
|
---@class DrawingHelper
|
||||||
local DrawingHelper = {}
|
local DrawingHelper = {}
|
||||||
@@ -240,6 +250,13 @@ end
|
|||||||
---@param hexStr string
|
---@param hexStr string
|
||||||
---@return table
|
---@return table
|
||||||
function DrawingHelper.ColorToColorTable(hexStr)
|
function DrawingHelper.ColorToColorTable(hexStr)
|
||||||
|
|
||||||
|
if hexStr == nil then
|
||||||
|
drawingLogger:warn("ColorToColorTable called with nil hexStr, returning default color {0, 0, 0, 0}")
|
||||||
|
return { 0, 0, 0, 0 }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
hexStr = hexStr:gsub("0x", "")
|
hexStr = hexStr:gsub("0x", "")
|
||||||
local r = tonumber(hexStr:sub(1, 2), 16) / 255
|
local r = tonumber(hexStr:sub(1, 2), 16) / 255
|
||||||
local g = tonumber(hexStr:sub(3, 4), 16) / 255
|
local g = tonumber(hexStr:sub(3, 4), 16) / 255
|
||||||
@@ -282,6 +299,26 @@ function DrawingHelper.ToLineStyleInteger(lineStyle)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DrawingHelper.ToLineStyleString(lineStyle)
|
||||||
|
if lineStyle == 0 then
|
||||||
|
return "no line"
|
||||||
|
elseif lineStyle == 1 then
|
||||||
|
return "solid"
|
||||||
|
elseif lineStyle == 2 then
|
||||||
|
return "dashed"
|
||||||
|
elseif lineStyle == 3 then
|
||||||
|
return "dotted"
|
||||||
|
elseif lineStyle == 4 then
|
||||||
|
return "dot dash"
|
||||||
|
elseif lineStyle == 5 then
|
||||||
|
return "long dash"
|
||||||
|
elseif lineStyle == 6 then
|
||||||
|
return "two dash"
|
||||||
|
else
|
||||||
|
return "no line"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@class ARGB
|
---@class ARGB
|
||||||
---@field public a number
|
---@field public a number
|
||||||
---@field public r number
|
---@field public r number
|
||||||
|
|||||||
@@ -137,10 +137,6 @@ function BattleManager:LetUnitsShoot(groups, targetGroups)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if debugDrawing == true then
|
|
||||||
self:DrawDebugLine(point, unit)
|
|
||||||
end
|
|
||||||
|
|
||||||
local controller = unit:getController()
|
local controller = unit:getController()
|
||||||
if controller then
|
if controller then
|
||||||
controller:setTask(shootTask)
|
controller:setTask(shootTask)
|
||||||
@@ -245,42 +241,8 @@ function BattleManager:GetRandomPoint(origin, groupHulls)
|
|||||||
if not hull then return nil end
|
if not hull then return nil end
|
||||||
local shootPoints = Util.GetTangentHullPointsFromOrigin(hull, origin)
|
local shootPoints = Util.GetTangentHullPointsFromOrigin(hull, origin)
|
||||||
|
|
||||||
if debugDrawing == true then
|
|
||||||
self:DrawDebugZone({ hull })
|
|
||||||
end
|
|
||||||
|
|
||||||
return Util.randomFromList(shootPoints) --[[@as Vec2]]
|
return Util.randomFromList(shootPoints) --[[@as Vec2]]
|
||||||
end
|
end
|
||||||
|
|
||||||
do --DEBUG
|
|
||||||
|
|
||||||
---@param unit Unit
|
|
||||||
---@param target Vec2
|
|
||||||
function BattleManager:DrawDebugLine(target, unit)
|
|
||||||
local color = {r = 1, g = 0, b = 0, a = 1}
|
|
||||||
if unit:getCoalition() == 2 then
|
|
||||||
color = {r = 0, g = 0, b = 1, a = 1}
|
|
||||||
end
|
|
||||||
|
|
||||||
DcsUtil.DrawLine(unit:getPoint(), {x = target.x, y = 0, z = target.y}, color, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param hulls Array<Array<Vec2>>
|
|
||||||
function BattleManager:DrawDebugZone(hulls)
|
|
||||||
for _, drawHull in pairs(hulls) do
|
|
||||||
|
|
||||||
---@type SpearheadTriggerZone
|
|
||||||
local zone = {
|
|
||||||
name = "temp",
|
|
||||||
zone_type = "Polygon",
|
|
||||||
radius = 0,
|
|
||||||
verts = drawHull,
|
|
||||||
location = { x=drawHull[1].x, y=drawHull[1].y },
|
|
||||||
}
|
|
||||||
|
|
||||||
DcsUtil.DrawZone(zone, {r =0, g=0, b =1, a = 0.5} ,{r =0, g= 0, b =1, a = 0}, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end --DEBUG
|
|
||||||
|
|
||||||
return BattleManager
|
return BattleManager
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ local SupplyUnitsTracker = require("classes.stageClasses.helpers.SupplyUnitsTrac
|
|||||||
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
||||||
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
||||||
local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper")
|
local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper")
|
||||||
|
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
|
||||||
|
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||||
|
|
||||||
---@class BuildableMission : Mission, SupplyUnitEventListener
|
---@class BuildableMission : Mission, SupplyUnitEventListener
|
||||||
---@field private _requiredKilos number
|
---@field private _requiredKilos number
|
||||||
@@ -17,8 +19,8 @@ local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHel
|
|||||||
---@field private _supplyUnitsTracker SupplyUnitsTracker
|
---@field private _supplyUnitsTracker SupplyUnitsTracker
|
||||||
---@field private _noLandingZone SpearheadTriggerZone?
|
---@field private _noLandingZone SpearheadTriggerZone?
|
||||||
---@field private _dropOffZone SpearheadTriggerZone?
|
---@field private _dropOffZone SpearheadTriggerZone?
|
||||||
---@field private _noLandingZoneId number
|
---@field private _noLandingZoneDrawing CustomDrawing?
|
||||||
---@field private _dropOffZoneId number
|
---@field private _dropOffZoneDrawing CustomDrawing?
|
||||||
local BuildableMission = {}
|
local BuildableMission = {}
|
||||||
BuildableMission.__index = BuildableMission
|
BuildableMission.__index = BuildableMission
|
||||||
|
|
||||||
@@ -164,20 +166,20 @@ function BuildableMission:SpawnActive()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type DrawColor
|
local lineColor = DrawingHelper.ColorTableToColorString({ 230/255, 93/255, 49/255, 1})
|
||||||
local lineColor = { r=230/255, g=93/255, b=49/255, a=1}
|
local fillColor = DrawingHelper.ColorTableToColorString({ 230/255, 93/255, 49/255, 0.2})
|
||||||
---@type DrawColor
|
self._noLandingZoneDrawing = CustomDrawing.FromZone(self._noLandingZone, lineColor, fillColor, 2, 6)
|
||||||
local fillColor = { r=230/255, g=93/255, b=49/255, a=0.2}
|
self._noLandingZoneDrawing:Draw()
|
||||||
self._noLandingZoneId = DcsUtil.DrawZone(self._noLandingZone, lineColor, fillColor, 6)
|
|
||||||
|
|
||||||
if self._dropOffZone == nil then
|
if self._dropOffZone == nil then
|
||||||
self._logger:error("No drop off zone found for mission: " .. self.code)
|
self._logger:error("No drop off zone found for mission: " .. self.code)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local lineColor2 = { r=0, g=0, b=1, a=1}
|
local lineColor2 = DrawingHelper.ColorTableToColorString({ 0, 0, 1, 1})
|
||||||
local fillColor2 = { r=0, g=0, b=1, a=0}
|
local fillColor2 = DrawingHelper.ColorTableToColorString({ 0, 0, 1, 0})
|
||||||
self._dropOffZoneId = DcsUtil.DrawZone(self._dropOffZone, lineColor2, fillColor2, 6)
|
self._dropOffZoneDrawing = CustomDrawing.FromZone(self._dropOffZone, lineColor2, fillColor2, 2, 6)
|
||||||
|
self._dropOffZoneDrawing:Draw()
|
||||||
|
|
||||||
---@param selfA BuildableMission
|
---@param selfA BuildableMission
|
||||||
---@param time number
|
---@param time number
|
||||||
@@ -254,8 +256,8 @@ function BuildableMission:CheckCratesInZone()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self._droppedKilos >= self._requiredKilos then
|
if self._droppedKilos >= self._requiredKilos then
|
||||||
DcsUtil.RemoveMark(self._noLandingZoneId)
|
self._dropOffZoneDrawing:Remove()
|
||||||
DcsUtil.RemoveMark(self._dropOffZoneId)
|
self._noLandingZoneDrawing:Remove()
|
||||||
self:NotifyMissionComplete()
|
self:NotifyMissionComplete()
|
||||||
self._state = "COMPLETED"
|
self._state = "COMPLETED"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local Mission = require("classes.stageClasses.missions.baseMissions.Mission")
|
local Mission = require("classes.stageClasses.missions.baseMissions.Mission")
|
||||||
local Util = require("classes.util.Util")
|
local Util = require("classes.util.Util")
|
||||||
local DcsUtil = require("classes.util.DcsUtil")
|
local DcsUtil = require("classes.util.DcsUtil")
|
||||||
|
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||||
|
|
||||||
---@class RunwayStrikeMission : Mission
|
---@class RunwayStrikeMission : Mission
|
||||||
---@field runwayBombingTracker RunwayBombingTracker
|
---@field runwayBombingTracker RunwayBombingTracker
|
||||||
@@ -154,9 +155,22 @@ function RunwayStrikeMission:Draw()
|
|||||||
if runwaySection.drawID == nil then
|
if runwaySection.drawID == nil then
|
||||||
local zone = self:SectionToSpearheadZone(runwaySection)
|
local zone = self:SectionToSpearheadZone(runwaySection)
|
||||||
|
|
||||||
local color = { r=0, g=1, b=0, a=0.5 }
|
---@type Free
|
||||||
|
local drawObject = {
|
||||||
|
primitiveType = "Polygon",
|
||||||
|
polygonMode = "free",
|
||||||
|
mapX = 0,
|
||||||
|
mapY = 0,
|
||||||
|
points = zone.verts,
|
||||||
|
name = zone.name,
|
||||||
|
fillColorString = DrawingHelper.ColorTableToColorString(fillColor),
|
||||||
|
colorString = DrawingHelper.ColorTableToColorString(lineColor),
|
||||||
|
style = "solid",
|
||||||
|
thickness = 1,
|
||||||
|
visible = true,
|
||||||
|
}
|
||||||
|
|
||||||
runwaySection.drawID = DcsUtil.DrawZone(zone, color, color, 5)
|
runwaySection.drawID = DrawingHelper.Draw(drawObject)
|
||||||
else
|
else
|
||||||
DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
|
DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
|
||||||
DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
|
DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
|
||||||
|
|||||||
@@ -173,10 +173,6 @@ do -- INIT DCS_UTIL
|
|||||||
verts = enlargedPoints
|
verts = enlargedPoints
|
||||||
}
|
}
|
||||||
|
|
||||||
if SpearheadConfig and SpearheadConfig.debugEnabled == true then
|
|
||||||
DCS_UTIL.DrawZone(triggerZone, { r = 0, g = 1, b = 0, a = 1 }, { a = 0, r = 0, g = 1, b = 0 }, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
DCS_UTIL.__airbaseZonesByName[name] = triggerZone
|
DCS_UTIL.__airbaseZonesByName[name] = triggerZone
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
|
|
||||||
local Util = require("classes.util.Util")
|
local Util = require("classes.util.Util")
|
||||||
|
local SpearheadConfig = require("classes.configuration.GlobalConfig")
|
||||||
|
|
||||||
|
|
||||||
|
---@type LogLevel
|
||||||
|
local defaultLogLevel = "INFO"
|
||||||
|
|
||||||
|
if SpearheadConfig then
|
||||||
|
if SpearheadConfig:isDebugEnabled() then
|
||||||
|
defaultLogLevel = "DEBUG"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @class Logger
|
--- @class Logger
|
||||||
--- @field LoggerName string the name of the logger
|
--- @field LoggerName string the name of the logger
|
||||||
@@ -10,13 +22,13 @@ do
|
|||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param logger_name any
|
---@param logger_name any
|
||||||
---@param logLevel LogLevel
|
---@param logLevel LogLevel? override the default log level
|
||||||
---@return Logger
|
---@return Logger
|
||||||
function LOGGER.new(logger_name, logLevel)
|
function LOGGER.new(logger_name, logLevel)
|
||||||
LOGGER.__index = LOGGER
|
LOGGER.__index = LOGGER
|
||||||
local self = setmetatable({}, LOGGER)
|
local self = setmetatable({}, LOGGER)
|
||||||
self.LoggerName = logger_name or "(loggername not set)"
|
self.LoggerName = logger_name or "(loggername not set)"
|
||||||
self.LogLevel = logLevel or "INFO"
|
self.LogLevel = logLevel or defaultLogLevel
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user