Fix/ pre activation #28
@@ -20,6 +20,10 @@
|
||||
- Fixed #9
|
||||
Changed order of checking mission briefings
|
||||
PR #19
|
||||
- Fixed Configuration defaulting to true for all booleans in StageConfig
|
||||
PR #28
|
||||
- Fixed Pre-Activated stages not always drawing or pre-activating correctly.
|
||||
PR #28
|
||||
|
||||
## [0.12.0] 2026-06
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
local briefingMessageTime = nil
|
||||
|
||||
---@class GlobalConfig
|
||||
---@field private _briefingTime number ;
|
||||
---@field private _briefingTime number
|
||||
---@field private _debugEnabled boolean
|
||||
local GlobalConfig = {}
|
||||
GlobalConfig.__index = GlobalConfig;
|
||||
|
||||
@@ -19,6 +20,13 @@ function GlobalConfig.New()
|
||||
if SpearheadConfig.briefingMessageDuration then
|
||||
self._briefingTime = SpearheadConfig.briefingMessageDuration
|
||||
end
|
||||
|
||||
if SpearheadConfig.debugEnabled ~= nil then
|
||||
self._debugEnabled = SpearheadConfig.debugEnabled
|
||||
else
|
||||
self._debugEnabled = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
@@ -28,6 +36,10 @@ function GlobalConfig:getBriefingTime()
|
||||
return self._briefingTime or 60
|
||||
end
|
||||
|
||||
function GlobalConfig:isDebugEnabled()
|
||||
return self._debugEnabled or false
|
||||
end
|
||||
|
||||
|
||||
return GlobalConfig
|
||||
|
||||
|
||||
@@ -9,26 +9,38 @@
|
||||
--- @field AmountPreactivateStage integer
|
||||
local StageConfig = {};
|
||||
|
||||
local Logger = require("classes.util.Logger")
|
||||
local _logger = Logger.new("StageConfig", Logger.LogLevel)
|
||||
|
||||
---comment
|
||||
---@return StageConfig
|
||||
function StageConfig:new()
|
||||
|
||||
if SpearheadConfig == nil then SpearheadConfig = {} end
|
||||
if SpearheadConfig.StageConfig == nil then SpearheadConfig.StageConfig = {} end
|
||||
if SpearheadConfig == nil then
|
||||
_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
|
||||
local o = {
|
||||
isEnabled = SpearheadConfig.StageConfig.enabled or true,
|
||||
isDrawStagesEnabled = SpearheadConfig.StageConfig.drawStages or true,
|
||||
isAutoStages = SpearheadConfig.StageConfig.autoStages or true,
|
||||
isEnabled = SpearheadConfig.StageConfig.enabled ~= false,
|
||||
isDrawStagesEnabled = SpearheadConfig.StageConfig.drawStages ~= false,
|
||||
isAutoStages = SpearheadConfig.StageConfig.autoStages ~= false,
|
||||
startingStage = SpearheadConfig.StageConfig.startingStage or 1,
|
||||
maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage or 10,
|
||||
isDrawPreActivatedEnabled = SpearheadConfig.StageConfig.drawPreActivated or true,
|
||||
isDrawPreActivatedEnabled = SpearheadConfig.StageConfig.drawPreActivated ~= false,
|
||||
AmountPreactivateStage = SpearheadConfig.StageConfig.preactivateStage or 1,
|
||||
}
|
||||
|
||||
setmetatable(o, { __index = self })
|
||||
|
||||
_logger:info("Successfully created StageConfig Object")
|
||||
|
||||
return o;
|
||||
end
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ function Database.New(Logger)
|
||||
for key, layer_object in pairs(layer.objects) do
|
||||
if Util.startswith(layer_object.name, "drawing_", true) then
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,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")
|
||||
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
|
||||
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||
|
||||
---@class SupplyHub
|
||||
---@field private _database Database
|
||||
@@ -12,7 +14,7 @@ local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionComma
|
||||
---@field private _isCommmandAdded table<string, boolean>
|
||||
---@field private _missionCommandsHelper MissionCommandsHelper
|
||||
---@field private _inZone table<string, boolean>
|
||||
---@field private _drawID number
|
||||
---@field private _customDrawing CustomDrawing?
|
||||
---@field private _cargoInUnits table<table<string, number>>
|
||||
---@field private _activeAtStart boolean
|
||||
---@field private _active boolean
|
||||
@@ -30,6 +32,7 @@ function SupplyHub.new(database, logger, zoneName)
|
||||
self._database = database
|
||||
self._logger = logger
|
||||
self._zoneName = zoneName
|
||||
self._customDrawing = nil
|
||||
|
||||
local split = Util.split_string(zoneName, "_")
|
||||
if string.lower(split[2]) == "a" then
|
||||
@@ -72,13 +75,13 @@ function SupplyHub:Activate()
|
||||
self._logger:debug("Activating Supply Hub zone: " .. 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}
|
||||
if zone and self._customDrawing == nil then
|
||||
local fillColor = DrawingHelper.ColorTableToColorString({ 0, 1, 0, 0.2 })
|
||||
local lineColor = DrawingHelper.ColorTableToColorString({ 0, 1, 0, 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
|
||||
|
||||
self._supplyUnitsTracker:RegisterHub(self)
|
||||
|
||||
@@ -11,6 +11,8 @@ 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")
|
||||
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
|
||||
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||
|
||||
---@alias StageColor
|
||||
---| "RED"
|
||||
@@ -43,17 +45,15 @@ local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
|
||||
--- @field zoneName string
|
||||
--- @field stageName string?
|
||||
--- @field stageNumber number
|
||||
--- @field protected _currentStageState CurrentStageState
|
||||
--- @field protected _missionCommandsHelper MissionCommandsHelper
|
||||
--- @field protected _isActive boolean
|
||||
--- @field protected _isComplete boolean
|
||||
--- @field protected _missionPriority MissionPriority
|
||||
--- @field protected _database Database
|
||||
--- @field protected _db StageData
|
||||
--- @field protected _logger Logger
|
||||
--- @field protected _preActivated boolean
|
||||
--- @field protected _activeStage integer
|
||||
--- @field protected _stageConfig StageConfig
|
||||
--- @field protected _stageDrawingId integer
|
||||
--- @field protected _customDrawing CustomDrawing
|
||||
--- @field protected _spawnedGroups Array<string>
|
||||
--- @field protected _stageCompleteListeners Array<StageCompleteListener>
|
||||
--- @field protected CheckContinuousAsync fun(self:Stage, time:number) : number?
|
||||
@@ -63,13 +63,20 @@ local Stage = {}
|
||||
|
||||
Stage.__index = Stage
|
||||
|
||||
---@enum CurrentStageState
|
||||
Stage.CurrentStageState = {
|
||||
INACTIVE = 0,
|
||||
PREACTIVATED = 1,
|
||||
ACTIVE = 2,
|
||||
BLUE = 3
|
||||
}
|
||||
|
||||
Stage.StageColors = {
|
||||
INVISIBLE = { r=0, g=0, b=0, a=0 },
|
||||
RED_ACTIVE = { r=1, g=0, b=0, a=0.15 },
|
||||
RED_PREACTIVE = { r=1, g=0, b=0, a=0.10},
|
||||
BLUE = { r=0, g=0, b=1, a=0.10},
|
||||
GRAY = { r=80/255, g=80/255, b=80/255, a=0.10 }
|
||||
INVISIBLE = { 0, 0, 0, 0 },
|
||||
RED_ACTIVE = { 1, 0, 0, 0.20 },
|
||||
RED_PREACTIVE = { 1, 0, 0, 0.05},
|
||||
BLUE = { 0, 0, 1, 0.10},
|
||||
GRAY = { 80/255, 80/255, 80/255, 0.10 }
|
||||
}
|
||||
|
||||
---comment
|
||||
@@ -83,12 +90,11 @@ Stage.StageColors = {
|
||||
function Stage:superNew(database, stageConfig, logger, initData, missionPriority, spawnManager)
|
||||
|
||||
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
|
||||
|
||||
self._currentStageState = Stage.CurrentStageState.INACTIVE
|
||||
self.zoneName = initData.stageZoneName
|
||||
self.stageNumber = initData.stageNumber
|
||||
self._isActive = false
|
||||
self._isComplete = false
|
||||
self.stageName = initData.stageDisplayName
|
||||
self._currentStageState = Stage.CurrentStageState.INACTIVE
|
||||
|
||||
self.OnPostStageComplete = nil
|
||||
self.OnPostBlueActivated = nil
|
||||
@@ -110,13 +116,19 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
}
|
||||
|
||||
self._activeStage = -99
|
||||
self._preActivated = false
|
||||
self._stageConfig = stageConfig or {}
|
||||
self._missionCommandsHelper = MissionCommandsHelper.getOrCreate(logger.LogLevel)
|
||||
|
||||
local zone = DcsUtil.getZoneByName(self.zoneName)
|
||||
if zone then
|
||||
self._stageDrawingId = DcsUtil.DrawZone(zone, Stage.StageColors.INVISIBLE, Stage.StageColors.INVISIBLE, 4)
|
||||
|
||||
local colorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||
local fillColorString = DrawingHelper.ColorTableToColorString(Stage.StageColors.INVISIBLE)
|
||||
|
||||
local customDrawing = CustomDrawing.FromZone(zone, colorString, fillColorString, 1, 5)
|
||||
if customDrawing then
|
||||
self._customDrawing = customDrawing
|
||||
end
|
||||
end
|
||||
|
||||
self._spawnedGroups = {}
|
||||
@@ -253,6 +265,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Events.AddStageNumberChangedListener(self)
|
||||
|
||||
return self
|
||||
@@ -260,7 +273,7 @@ end
|
||||
|
||||
---@return boolean
|
||||
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
|
||||
local state = mission:getState()
|
||||
@@ -276,13 +289,13 @@ function Stage:IsComplete()
|
||||
end
|
||||
end
|
||||
|
||||
self._isComplete = true
|
||||
self._currentStageState = Stage.CurrentStageState.BLUE
|
||||
return true
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
function Stage:IsActive()
|
||||
return self._isActive == true
|
||||
return self._currentStageState == Stage.CurrentStageState.ACTIVE
|
||||
end
|
||||
|
||||
---comment
|
||||
@@ -367,10 +380,9 @@ function Stage:AddStageCompleteListener(listener)
|
||||
end
|
||||
|
||||
---Activates all SAMS, Airbase units etc all at once.
|
||||
---@param draw boolean
|
||||
function Stage:PreActivate(draw)
|
||||
if self._preActivated == false then
|
||||
self._preActivated = true
|
||||
function Stage:PreActivate()
|
||||
if self._currentStageState == Stage.CurrentStageState.INACTIVE then
|
||||
self._currentStageState = Stage.CurrentStageState.PREACTIVATED
|
||||
for key, mission in pairs(self._db.sams) do
|
||||
if mission then
|
||||
mission:SpawnInactive()
|
||||
@@ -382,40 +394,60 @@ function Stage:PreActivate(draw)
|
||||
end
|
||||
end
|
||||
|
||||
if draw == true then
|
||||
self:MarkStage(Stage.StageColors.RED_PREACTIVE)
|
||||
end
|
||||
self:MarkStage()
|
||||
|
||||
end
|
||||
|
||||
---@param stageColor DrawColor
|
||||
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 }
|
||||
function Stage:MarkStage()
|
||||
|
||||
if stageColor.a > 0 then
|
||||
lineColor.a = 1
|
||||
self._logger:debug("Marking stage '" .. Util.toString(self.zoneName) .. "' with state: " .. self._currentStageState)
|
||||
|
||||
if self._customDrawing then
|
||||
self._customDrawing:Remove()
|
||||
end
|
||||
|
||||
if stageColor == Stage.StageColors.RED_PREACTIVE then
|
||||
lineColor.a = 0
|
||||
if self._stageConfig.isDrawStagesEnabled == false then return end
|
||||
if self._stageConfig.isDrawPreActivatedEnabled == false and self._currentStageState == Stage.CurrentStageState.PREACTIVATED then
|
||||
return
|
||||
end
|
||||
|
||||
if self._stageDrawingId and self._stageConfig.isDrawStagesEnabled == true then
|
||||
DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
|
||||
DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
|
||||
if self._customDrawing then
|
||||
self._customDrawing:UpdateDrawingObject(function(drawingObject)
|
||||
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
|
||||
|
||||
return drawing
|
||||
end)
|
||||
self._customDrawing:Draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function Stage:ActivateStage()
|
||||
self._isActive = true;
|
||||
self._currentStageState = Stage.CurrentStageState.ACTIVE
|
||||
|
||||
pcall(function()
|
||||
self:MarkStage(Stage.StageColors.RED_ACTIVE)
|
||||
self:PreActivate()
|
||||
|
||||
pcall(function()
|
||||
self:MarkStage()
|
||||
end)
|
||||
|
||||
self:PreActivate(false)
|
||||
|
||||
self._logger:debug("Activating Misc groups for zone. Count: " .. Util.tableLength(self._db.miscGroups))
|
||||
for _, miscGroup in pairs(self._db.miscGroups) do
|
||||
miscGroup:Spawn()
|
||||
@@ -462,9 +494,9 @@ 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)
|
||||
self:PreActivate()
|
||||
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
||||
self:PreActivate(false)
|
||||
self:PreActivate()
|
||||
end
|
||||
|
||||
if number == self.stageNumber then
|
||||
@@ -559,7 +591,7 @@ end
|
||||
function Stage:ActivateBlueStage()
|
||||
|
||||
self._logger:debug("Setting stage '" .. Util.toString(self.zoneName) .. "' to blue")
|
||||
|
||||
self._currentStageState = Stage.CurrentStageState.BLUE
|
||||
for _, mission in pairs(self._db.missions) do
|
||||
mission:SpawnPersistedState()
|
||||
end
|
||||
@@ -575,7 +607,7 @@ function Stage:ActivateBlueStage()
|
||||
---@param self Stage
|
||||
local ActivateBlueAsync = function(self)
|
||||
pcall(function()
|
||||
self:MarkStage(Stage.StageColors.BLUE)
|
||||
self:MarkStage()
|
||||
end)
|
||||
|
||||
self:ActivateBlueGroups()
|
||||
|
||||
@@ -23,7 +23,7 @@ function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
|
||||
|
||||
self.OnPostBlueActivated = function (selfStage)
|
||||
|
||||
selfStage:MarkStage(Stage.StageColors.GRAY)
|
||||
selfStage:MarkStage()
|
||||
end
|
||||
|
||||
self.OnPostStageComplete = function (selfStage)
|
||||
@@ -34,7 +34,7 @@ function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param self Stage
|
||||
---@param self ExtraStage
|
||||
---@param number integer
|
||||
function ExtraStage:OnStageNumberChanged(number)
|
||||
|
||||
@@ -47,16 +47,16 @@ 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)
|
||||
self:PreActivate()
|
||||
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
||||
self:PreActivate(false)
|
||||
self:PreActivate()
|
||||
end
|
||||
|
||||
if number == self.stageNumber then
|
||||
self:ActivateStage()
|
||||
end
|
||||
|
||||
if self._isComplete == true then
|
||||
if self._currentStageState == Stage.CurrentStageState.BLUE then
|
||||
self:ActivateBlueStage()
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelpe
|
||||
local Util = require("classes.util.Util")
|
||||
local Logger = require("classes.util.Logger")
|
||||
|
||||
|
||||
local drawingLogger = Logger.new("CustomDrawing")
|
||||
|
||||
---@class CustomDrawing
|
||||
---@field private _id integer?
|
||||
---@field private _drawingObject DrawingObject
|
||||
@@ -14,14 +17,12 @@ CustomDrawing.__index = CustomDrawing
|
||||
|
||||
|
||||
---@param drawingObject DrawingObject
|
||||
---@param id integer?
|
||||
---@param loglevel LogLevel
|
||||
---@return CustomDrawing
|
||||
function CustomDrawing.New(drawingObject, id, loglevel)
|
||||
function CustomDrawing.New(drawingObject)
|
||||
local self = setmetatable({}, CustomDrawing)
|
||||
self._drawingObject = drawingObject
|
||||
self._id = id
|
||||
self._logger = Logger.new("CustomDrawing", loglevel)
|
||||
self._id = nil -- initiate ID as nil, when drawn it will be set to the ID returned by DrawingHelper.Draw
|
||||
self._logger = drawingLogger
|
||||
|
||||
local name = drawingObject.name
|
||||
local split = Util.split_string(name or "", "_")
|
||||
@@ -32,6 +33,58 @@ function CustomDrawing.New(drawingObject, id, loglevel)
|
||||
return self
|
||||
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
|
||||
function CustomDrawing:GetName()
|
||||
return self._drawingObject.name
|
||||
@@ -61,4 +114,9 @@ function CustomDrawing:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
---@param updateFunc fun(drawingObject:DrawingObject):DrawingObject
|
||||
function CustomDrawing:UpdateDrawingObject(updateFunc)
|
||||
self._drawingObject = updateFunc(self._drawingObject)
|
||||
end
|
||||
|
||||
return CustomDrawing
|
||||
@@ -1,4 +1,14 @@
|
||||
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
|
||||
local DrawingHelper = {}
|
||||
@@ -149,7 +159,6 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
local firstPoint = points[1]
|
||||
|
||||
if firstPoint == nil or newPoint.x ~= firstPoint.x or newPoint.z ~= firstPoint.z then
|
||||
logger:debug("Drawing free polygon point " .. tostring(k) .. ": " .. tostring(free.points[k].x) .. ", " .. tostring(free.points[k].y))
|
||||
table.insert(points, newPoint)
|
||||
end
|
||||
end
|
||||
@@ -241,6 +250,13 @@ end
|
||||
---@param hexStr string
|
||||
---@return table
|
||||
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", "")
|
||||
local r = tonumber(hexStr:sub(1, 2), 16) / 255
|
||||
local g = tonumber(hexStr:sub(3, 4), 16) / 255
|
||||
@@ -250,6 +266,17 @@ function DrawingHelper.ColorToColorTable(hexStr)
|
||||
return { r, g , b , a }
|
||||
end
|
||||
|
||||
---@param rgba table
|
||||
---@return string
|
||||
function DrawingHelper.ColorTableToColorString(rgba)
|
||||
local r = string.format("%02X", math.floor(rgba[1] * 255))
|
||||
local g = string.format("%02X", math.floor(rgba[2] * 255))
|
||||
local b = string.format("%02X", math.floor(rgba[3] * 255))
|
||||
local a = string.format("%02X", math.floor(rgba[4] * 255))
|
||||
|
||||
return "0x" .. r .. g .. b .. a
|
||||
end
|
||||
|
||||
---@param lineStyle string
|
||||
function DrawingHelper.ToLineStyleInteger(lineStyle)
|
||||
lineStyle = lineStyle:lower()
|
||||
@@ -272,6 +299,26 @@ function DrawingHelper.ToLineStyleInteger(lineStyle)
|
||||
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
|
||||
---@field public a 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()
|
||||
if controller then
|
||||
controller:setTask(shootTask)
|
||||
@@ -245,42 +241,8 @@ function BattleManager:GetRandomPoint(origin, groupHulls)
|
||||
if not hull then return nil end
|
||||
local shootPoints = Util.GetTangentHullPointsFromOrigin(hull, origin)
|
||||
|
||||
if debugDrawing == true then
|
||||
self:DrawDebugZone({ hull })
|
||||
end
|
||||
|
||||
return Util.randomFromList(shootPoints) --[[@as Vec2]]
|
||||
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
|
||||
|
||||
@@ -5,6 +5,8 @@ local SupplyUnitsTracker = require("classes.stageClasses.helpers.SupplyUnitsTrac
|
||||
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
||||
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
||||
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
|
||||
---@field private _requiredKilos number
|
||||
@@ -17,8 +19,8 @@ local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHel
|
||||
---@field private _supplyUnitsTracker SupplyUnitsTracker
|
||||
---@field private _noLandingZone SpearheadTriggerZone?
|
||||
---@field private _dropOffZone SpearheadTriggerZone?
|
||||
---@field private _noLandingZoneId number
|
||||
---@field private _dropOffZoneId number
|
||||
---@field private _noLandingZoneDrawing CustomDrawing?
|
||||
---@field private _dropOffZoneDrawing CustomDrawing?
|
||||
local BuildableMission = {}
|
||||
BuildableMission.__index = BuildableMission
|
||||
|
||||
@@ -164,20 +166,20 @@ function BuildableMission:SpawnActive()
|
||||
return
|
||||
end
|
||||
|
||||
---@type DrawColor
|
||||
local lineColor = { r=230/255, g=93/255, b=49/255, a=1}
|
||||
---@type DrawColor
|
||||
local fillColor = { r=230/255, g=93/255, b=49/255, a=0.2}
|
||||
self._noLandingZoneId = DcsUtil.DrawZone(self._noLandingZone, lineColor, fillColor, 6)
|
||||
local lineColor = DrawingHelper.ColorTableToColorString({ 230/255, 93/255, 49/255, 1})
|
||||
local fillColor = DrawingHelper.ColorTableToColorString({ 230/255, 93/255, 49/255, 0.2})
|
||||
self._noLandingZoneDrawing = CustomDrawing.FromZone(self._noLandingZone, lineColor, fillColor, 2, 6)
|
||||
self._noLandingZoneDrawing:Draw()
|
||||
|
||||
if self._dropOffZone == nil then
|
||||
self._logger:error("No drop off zone found for mission: " .. self.code)
|
||||
return
|
||||
end
|
||||
|
||||
local lineColor2 = { r=0, g=0, b=1, a=1}
|
||||
local fillColor2 = { r=0, g=0, b=1, a=0}
|
||||
self._dropOffZoneId = DcsUtil.DrawZone(self._dropOffZone, lineColor2, fillColor2, 6)
|
||||
local lineColor2 = DrawingHelper.ColorTableToColorString({ 0, 0, 1, 1})
|
||||
local fillColor2 = DrawingHelper.ColorTableToColorString({ 0, 0, 1, 0})
|
||||
self._dropOffZoneDrawing = CustomDrawing.FromZone(self._dropOffZone, lineColor2, fillColor2, 2, 6)
|
||||
self._dropOffZoneDrawing:Draw()
|
||||
|
||||
---@param selfA BuildableMission
|
||||
---@param time number
|
||||
@@ -254,8 +256,8 @@ function BuildableMission:CheckCratesInZone()
|
||||
end
|
||||
|
||||
if self._droppedKilos >= self._requiredKilos then
|
||||
DcsUtil.RemoveMark(self._noLandingZoneId)
|
||||
DcsUtil.RemoveMark(self._dropOffZoneId)
|
||||
self._dropOffZoneDrawing:Remove()
|
||||
self._noLandingZoneDrawing:Remove()
|
||||
self:NotifyMissionComplete()
|
||||
self._state = "COMPLETED"
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local Mission = require("classes.stageClasses.missions.baseMissions.Mission")
|
||||
local Util = require("classes.util.Util")
|
||||
local DcsUtil = require("classes.util.DcsUtil")
|
||||
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||
|
||||
---@class RunwayStrikeMission : Mission
|
||||
---@field runwayBombingTracker RunwayBombingTracker
|
||||
@@ -154,9 +155,22 @@ function RunwayStrikeMission:Draw()
|
||||
if runwaySection.drawID == nil then
|
||||
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
|
||||
DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
|
||||
DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
|
||||
|
||||
@@ -350,7 +350,7 @@ function ZoneMission:SpawnPersistedState()
|
||||
end
|
||||
end
|
||||
|
||||
---spawns the mission, but doesn't add
|
||||
---spawns the mission, but doesn't add it to the mission commands.
|
||||
function ZoneMission:SpawnInactive()
|
||||
self._logger:info("PreActivating " .. self.name)
|
||||
|
||||
|
||||
@@ -173,10 +173,6 @@ do -- INIT DCS_UTIL
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -636,71 +632,6 @@ do -- INIT DCS_UTIL
|
||||
---@field b number
|
||||
---@field a number
|
||||
|
||||
local drawID = 400
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@param lineColor DrawColor
|
||||
---@param fillColor DrawColor
|
||||
---@param lineStyle LineType
|
||||
---@return number drawID
|
||||
function DCS_UTIL.DrawZone(zone, lineColor, fillColor, lineStyle)
|
||||
if lineStyle == nil then lineStyle = 4 end
|
||||
drawID = drawID + 1
|
||||
if zone.zone_type == "Cilinder" then
|
||||
trigger.action.circleToAll(-1, drawID, { x = zone.location.x, y = 0, z = zone.location.y }, zone.radius,
|
||||
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, lineStyle, true)
|
||||
else
|
||||
local functionString = "trigger.action.markupToAll(7, -1, " .. drawID .. ","
|
||||
for _, vecpoint in pairs(zone.verts) do
|
||||
functionString = functionString .. " { x=" .. vecpoint.x .. ", y=0,z=" .. vecpoint.y .. "},"
|
||||
end
|
||||
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, " .. lineStyle .. ")"
|
||||
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local f, err = loadstring(functionString)
|
||||
if f then
|
||||
f()
|
||||
else
|
||||
env.error("Something failed when drawing complex drawing" .. err)
|
||||
end
|
||||
end
|
||||
local fillColorMapped = {
|
||||
fillColor.r or 0,
|
||||
fillColor.g or 0,
|
||||
fillColor.b or 0,
|
||||
fillColor.a or 0.5
|
||||
}
|
||||
|
||||
local lineColorMapped = {
|
||||
lineColor.r or 0,
|
||||
lineColor.g or 0,
|
||||
lineColor.b or 0,
|
||||
lineColor.a or 1
|
||||
}
|
||||
|
||||
trigger.action.setMarkupColorFill(drawID, fillColorMapped)
|
||||
trigger.action.setMarkupColor(drawID, lineColorMapped)
|
||||
|
||||
return drawID
|
||||
end
|
||||
|
||||
---@param start Vec3
|
||||
---@param finish Vec3
|
||||
---@param lineColor DrawColor
|
||||
---@param lineStyle LineType
|
||||
function DCS_UTIL.DrawLine(start, finish, lineColor, lineStyle)
|
||||
if lineStyle == nil then lineStyle = 4 end
|
||||
drawID = drawID + 1
|
||||
|
||||
local lineColorMapped = {
|
||||
lineColor.r or 0,
|
||||
lineColor.g or 0,
|
||||
lineColor.b or 0,
|
||||
lineColor.a or 1
|
||||
}
|
||||
|
||||
trigger.action.lineToAll(-1, drawID, start, finish, lineColorMapped, lineStyle)
|
||||
return drawID
|
||||
end
|
||||
|
||||
---@param groupID number
|
||||
---@param text string
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
|
||||
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
|
||||
--- @field LoggerName string the name of the logger
|
||||
@@ -10,13 +22,13 @@ do
|
||||
|
||||
---comment
|
||||
---@param logger_name any
|
||||
---@param logLevel LogLevel
|
||||
---@param logLevel LogLevel? override the default log level
|
||||
---@return Logger
|
||||
function LOGGER.new(logger_name, logLevel)
|
||||
LOGGER.__index = LOGGER
|
||||
local self = setmetatable({}, LOGGER)
|
||||
self.LoggerName = logger_name or "(loggername not set)"
|
||||
self.LogLevel = logLevel or "INFO"
|
||||
self.LogLevel = logLevel or defaultLogLevel
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user