Feature/scenery targets (#60)

* Added Scenery targets
* Documentation updates
This commit is contained in:
2025-07-17 19:50:57 +02:00
committed by GitHub
parent b6a1285bde
commit 1d4c0a8313
27 changed files with 833 additions and 182 deletions
+3
View File
@@ -14,3 +14,6 @@ do -- mission aliases
end
---@class KeyValuePair
---@field key string
---@field value any
+13 -2
View File
@@ -539,6 +539,7 @@ do -- INIT DCS_UTIL
---@field radius number
---@field verts Array<Vec2>
---@field zone_type SpearheadTriggerZoneType
---@field properties Array<KeyValuePair>?
---@type Array<SpearheadTriggerZone>
DCS_UTIL.__trigger_zones = {}
@@ -598,9 +599,18 @@ do -- INIT DCS_UTIL
zone_type = zoneType,
location = { x = trigger_zone.x, y = trigger_zone.y },
radius = trigger_zone.radius,
verts = verts
verts = verts,
properties = {}
}
if trigger_zone.properties then
for _, kvPair in pairs(trigger_zone.properties) do
local key = kvPair["key"]
local value = kvPair["value"]
zone.properties[#zone.properties + 1] = { key = key, value = value }
end
end
DCS_UTIL.__trigger_zones[zone.name] = zone
end
end
@@ -977,7 +987,8 @@ do -- INIT DCS_UTIL
end
end
end
---comment Get all units that are players
---@return Array<Unit> units
function DCS_UTIL.getAllPlayerUnits()
+57 -54
View File
@@ -7,6 +7,7 @@
---@field MissionZonesLocations table<string, Vec2> All Mission Zone Locations
---@field StageZonesByNumber table<string, Array<string>> Stage zones grouped by index number
---@field AllFarpZones Array<string>
---@field AllSceneryObjects Array<SpearheadSceneryObject> All scenery objects
---@field AllCapRoutes Array<string> All Cap route zone names
---@field AllInterceptZones Array<string> All intercept zones
---@field capZonesByCapZoneID table<string, CapRoute>
@@ -58,11 +59,9 @@
---@class MissionZoneData
---@field RedGroups Array<string>
---@field SceneryTargets Array<SpearheadSceneryObject>
---@field BlueGroups Array<string>
---@class MissionData
---@field Groups Array<string>
---@class FarpZoneData
---@field groups Array<string>
---@field padNames Array<string>
@@ -85,6 +84,7 @@ function Database.New(Logger)
AllCapRoutes = {},
capZonesByCapZoneID = {},
AllInterceptZones = {},
AllSceneryObjects = {},
interceptZonesByZoneID = {},
CarrierRouteZones = {},
MissionZones = {},
@@ -186,6 +186,19 @@ function Database.New(Logger)
if lowered == "supplyhub" then
table.insert(self._tables.SupplyHubZones, zone_name)
end
if zone_data.properties then
for _, kvPair in pairs(zone_data.properties) do
if kvPair.key and kvPair.key == "OBJECT ID" then
local objectID = tonumber(kvPair.value)
if objectID then
local sceneryObject = Spearhead.classes.stageClasses.Groups.SpearheadSceneryObject.New(objectID)
table.insert(self._tables.AllSceneryObjects, sceneryObject)
end
end
end
end
end
end
@@ -649,67 +662,57 @@ function Database:loadBlueSamUnits()
end
---@private
function Database:loadMissionzoneUnits()
function Database:LoadZoneData(missionZoneName)
local all_groups = getAvailableGroups()
for _, missionZoneName in pairs(self._tables.MissionZones) do
self._tables.MissionZoneData[missionZoneName] = {
RedGroups = {},
BlueGroups = {},
}
self._tables.MissionZoneData[missionZoneName] = {
RedGroups = {},
BlueGroups = {},
SceneryTargets = {}
}
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif object then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
else
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif object then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
else
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
end
is_group_taken[groupName] = true
end
for _, sceneryObject in pairs(self._tables.AllSceneryObjects) do
local point = sceneryObject:GetPoint()
if point then
if Spearhead.DcsUtil.isPositionInZone(point.x, point.z, missionZoneName) == true then
table.insert(self._tables.MissionZoneData[missionZoneName].SceneryTargets, sceneryObject)
end
is_group_taken[groupName] = true
end
end
end
---@private
function Database:loadMissionzoneUnits()
for _, missionZoneName in pairs(self._tables.MissionZones) do
self:LoadZoneData(missionZoneName)
end
end
---@private
function Database:loadRandomMissionzoneUnits()
local all_groups = getAvailableGroups()
for _, missionZoneName in pairs(self._tables.RandomMissionZones) do
self._tables.MissionZoneData[missionZoneName] = {
RedGroups = {},
BlueGroups = {},
}
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do
if Spearhead.classes.helpers.MizGroupsManager.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif object then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
else
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
end
is_group_taken[groupName] = true
end
self:LoadZoneData(missionZoneName)
end
end
@@ -0,0 +1,77 @@
---@class SpearheadSceneryObject
---@field private persistentName string The persistent name of the scenery object
---@field private objectID number The ID of the scenery object
---@field private internalObj table
---@field private isDead boolean Indicates if the scenery object is dead
local SpearheadSceneryObject = {}
SpearheadSceneryObject.__index = SpearheadSceneryObject
---comment
---@param objectID number
---@return SpearheadSceneryObject?
function SpearheadSceneryObject.New(objectID)
local self = setmetatable({}, SpearheadSceneryObject)
if objectID == nil then
return nil
end
self.persistentName = "SpearheadSceneryObject_" .. objectID
self.objectID = objectID
self.isDead = false
self.internalObj = {
["id_"] = objectID
}
return self
end
---@return boolean
function SpearheadSceneryObject:IsAlive()
if Object.isExist(self.internalObj) == false then
self:MarkDead()
return false
end
if SceneryObject.getLife(self.internalObj) <= 0.10 then
self:MarkDead()
return false
end
return true
end
---@private
function SpearheadSceneryObject:MarkDead()
if self.isDead == true then return end
self.isDead = true
Spearhead.classes.persistence.Persistence.UnitKilled(self.persistentName, self:GetPoint(), 0, "Scenery")
end
function SpearheadSceneryObject:UpdateStatePersistently()
if self.isDead == true then
return
end
local state = Spearhead.classes.persistence.Persistence.UnitState(self.persistentName)
if state and state.isDead == true then
trigger.action.explosion(self:GetPoint(), 1000)
self.isDead = true
end
end
function SpearheadSceneryObject:GetPersistentName()
return self.persistentName
end
function SpearheadSceneryObject:GetPoint()
return Object.getPoint(self.internalObj)
end
if not Spearhead.classes then Spearhead.classes = {} end
if not Spearhead.classes.stageClasses then Spearhead.classes.stageClasses = {} end
if not Spearhead.classes.stageClasses.Groups then Spearhead.classes.stageClasses.Groups = {} end
Spearhead.classes.stageClasses.Groups.SpearheadSceneryObject = SpearheadSceneryObject
+29 -1
View File
@@ -15,6 +15,7 @@ local ZoneMission = {}
--- @field blueGroups Array<SpearheadGroup>
--- @field unitsAlive table<string, table<string, boolean>>
--- @field targetsAlive table<string, table<string, boolean>>
--- @field sceneryTargets Array<SpearheadSceneryObject>
--- @field groupNamesPerunit table<string,string>
---@class ParsedMissionName
@@ -101,7 +102,8 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
unitsAlive = {},
targetsAlive = {},
hasTargets = false,
groupNamesPerunit = {}
groupNamesPerunit = {},
sceneryTargets = {}
}
self._parentStage = parentStage
@@ -127,6 +129,10 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage, spaw
local missionData = database:getMissionDataForZone(zoneName)
if not missionData then return end
self._missionGroups.sceneryTargets = missionData.SceneryTargets or {}
if Spearhead.Util.tableLength(self._missionGroups.sceneryTargets) > 0 then
self._missionGroups.hasTargets = true
end
for _, groupName in pairs(missionData.BlueGroups) do
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
@@ -288,6 +294,13 @@ function ZoneMission:UpdateState(checkHealth, messageIfDone)
end
end
for _, sceneryObject in pairs(self._missionGroups.sceneryTargets) do
total = total + 1
if sceneryObject:IsAlive() == true then
alive = alive + 1
end
end
local deadRatio = (total - alive) / total
if deadRatio >= self._completeAtIndex then
self._logger:debug("Dead ratio " .. self.zoneName .. deadRatio .. " >= " .. self._completeAtIndex)
@@ -327,6 +340,10 @@ function ZoneMission:SpawnPersistedState()
for _, group in pairs(self._missionGroups.redGroups) do
group:Spawn()
end
for _, object in pairs(self._missionGroups.sceneryTargets) do
object:UpdateStatePersistently()
end
end
---spawns the mission, but doesn't add
@@ -361,6 +378,10 @@ function ZoneMission:SpawnActive()
group:Spawn()
end
for _, sceneryObject in pairs(self._missionGroups.sceneryTargets) do
sceneryObject:UpdateStatePersistently()
end
if self._battleManager then
self._battleManager:Start()
end
@@ -404,6 +425,13 @@ function ZoneMission:PercentageComplete()
end
end
for _, sceneryObject in pairs(self._missionGroups.sceneryTargets) do
total = total + 1
if sceneryObject:IsAlive() == false then
dead = dead + 1
end
end
if total > 0 then
return math.floor((dead / total) * 100)
end