wip
This commit is contained in:
@@ -11,6 +11,8 @@ local StageBase = require("classes.stageClasses.SpecialZones.StageBase")
|
|||||||
local BlueSam = require("classes.stageClasses.SpecialZones.BlueSam")
|
local BlueSam = require("classes.stageClasses.SpecialZones.BlueSam")
|
||||||
local Events = require("classes.spearhead_events")
|
local Events = require("classes.spearhead_events")
|
||||||
local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
|
local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
|
||||||
|
local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing")
|
||||||
|
local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper")
|
||||||
|
|
||||||
---@alias StageColor
|
---@alias StageColor
|
||||||
---| "RED"
|
---| "RED"
|
||||||
@@ -53,7 +55,8 @@ local GlobalCapManager = require("classes.capClasses.GlobalCapManager")
|
|||||||
--- @field protected _preActivated boolean
|
--- @field protected _preActivated boolean
|
||||||
--- @field protected _activeStage integer
|
--- @field protected _activeStage integer
|
||||||
--- @field protected _stageConfig StageConfig
|
--- @field protected _stageConfig StageConfig
|
||||||
--- @field protected _stageDrawingId integer
|
--- @field protected _stageDrawing DrawingObject
|
||||||
|
--- @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?
|
||||||
@@ -65,11 +68,11 @@ Stage.__index = Stage
|
|||||||
|
|
||||||
|
|
||||||
Stage.StageColors = {
|
Stage.StageColors = {
|
||||||
INVISIBLE = { r=0, g=0, b=0, a=0 },
|
INVISIBLE = { 0, 0, 0, 0 },
|
||||||
RED_ACTIVE = { r=1, g=0, b=0, a=0.15 },
|
RED_ACTIVE = { 1, 0, 0, 0.15 },
|
||||||
RED_PREACTIVE = { r=1, g=0, b=0, a=0.10},
|
RED_PREACTIVE = { 1, 0, 0, 0.10},
|
||||||
BLUE = { r=0, g=0, b=1, a=0.10},
|
BLUE = { 0, 0, 1, 0.10},
|
||||||
GRAY = { r=80/255, g=80/255, b=80/255, a=0.10 }
|
GRAY = { 80/255, 80/255, 80/255, 0.10 }
|
||||||
}
|
}
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
@@ -116,7 +119,34 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
|||||||
|
|
||||||
local zone = DcsUtil.getZoneByName(self.zoneName)
|
local zone = DcsUtil.getZoneByName(self.zoneName)
|
||||||
if zone then
|
if zone then
|
||||||
self._stageDrawingId = DcsUtil.DrawZone(zone, Stage.StageColors.INVISIBLE, Stage.StageColors.INVISIBLE, 4)
|
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
|
||||||
|
else
|
||||||
|
local verts = {}
|
||||||
|
|
||||||
|
---@type Free
|
||||||
|
local drawing = {
|
||||||
|
mapX = zone.location.x,
|
||||||
|
mapY = zone.location.y,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self._spawnedGroups = {}
|
self._spawnedGroups = {}
|
||||||
@@ -253,6 +283,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
Events.AddStageNumberChangedListener(self)
|
Events.AddStageNumberChangedListener(self)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -367,8 +398,7 @@ function Stage:AddStageCompleteListener(listener)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Activates all SAMS, Airbase units etc all at once.
|
---Activates all SAMS, Airbase units etc all at once.
|
||||||
---@param draw boolean
|
function Stage:PreActivate()
|
||||||
function Stage:PreActivate(draw)
|
|
||||||
if self._preActivated == false then
|
if self._preActivated == false then
|
||||||
self._preActivated = true
|
self._preActivated = true
|
||||||
for key, mission in pairs(self._db.sams) do
|
for key, mission in pairs(self._db.sams) do
|
||||||
@@ -382,9 +412,7 @@ function Stage:PreActivate(draw)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if draw == true then
|
self:MarkStage(Stage.StageColors.RED_PREACTIVE)
|
||||||
self:MarkStage(Stage.StageColors.RED_PREACTIVE)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -405,6 +433,8 @@ function Stage:MarkStage(stageColor)
|
|||||||
DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
|
DcsUtil.SetLineColor(self._stageDrawingId, lineColor)
|
||||||
DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
|
DcsUtil.SetFillColor(self._stageDrawingId, fillColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Stage:ActivateStage()
|
function Stage:ActivateStage()
|
||||||
@@ -414,7 +444,7 @@ function Stage:ActivateStage()
|
|||||||
self:MarkStage(Stage.StageColors.RED_ACTIVE)
|
self:MarkStage(Stage.StageColors.RED_ACTIVE)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self:PreActivate(false)
|
self:PreActivate()
|
||||||
|
|
||||||
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
|
||||||
@@ -462,9 +492,9 @@ function Stage:OnStageNumberChanged(number)
|
|||||||
|
|
||||||
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
|
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
|
||||||
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
|
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
|
||||||
self:PreActivate(true)
|
self:PreActivate()
|
||||||
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
||||||
self:PreActivate(false)
|
self:PreActivate()
|
||||||
end
|
end
|
||||||
|
|
||||||
if number == self.stageNumber then
|
if number == self.stageNumber then
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ function ExtraStage:OnStageNumberChanged(number)
|
|||||||
|
|
||||||
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
|
if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then
|
||||||
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
|
self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number)
|
||||||
self:PreActivate(true)
|
self:PreActivate()
|
||||||
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
||||||
self:PreActivate(false)
|
self:PreActivate()
|
||||||
end
|
end
|
||||||
|
|
||||||
if number == self.stageNumber then
|
if number == self.stageNumber then
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
|||||||
local firstPoint = points[1]
|
local firstPoint = points[1]
|
||||||
|
|
||||||
if firstPoint == nil or newPoint.x ~= firstPoint.x or newPoint.z ~= firstPoint.z then
|
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)
|
table.insert(points, newPoint)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -250,6 +249,17 @@ function DrawingHelper.ColorToColorTable(hexStr)
|
|||||||
return { r, g , b , a }
|
return { r, g , b , a }
|
||||||
end
|
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
|
---@param lineStyle string
|
||||||
function DrawingHelper.ToLineStyleInteger(lineStyle)
|
function DrawingHelper.ToLineStyleInteger(lineStyle)
|
||||||
lineStyle = lineStyle:lower()
|
lineStyle = lineStyle:lower()
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ function ZoneMission:SpawnPersistedState()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---spawns the mission, but doesn't add
|
---spawns the mission, but doesn't add it to the mission commands.
|
||||||
function ZoneMission:SpawnInactive()
|
function ZoneMission:SpawnInactive()
|
||||||
self._logger:info("PreActivating " .. self.name)
|
self._logger:info("PreActivating " .. self.name)
|
||||||
|
|
||||||
|
|||||||
@@ -636,71 +636,6 @@ do -- INIT DCS_UTIL
|
|||||||
---@field b number
|
---@field b number
|
||||||
---@field a 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 groupID number
|
||||||
---@param text string
|
---@param text string
|
||||||
|
|||||||
Reference in New Issue
Block a user