Feature/briefing coords (#28)

* added coordinates replacement
This commit is contained in:
2025-05-09 03:03:35 +02:00
committed by GitHub
parent eba7931824
commit d0bd36ea4e
5 changed files with 111 additions and 3 deletions
+22 -1
View File
@@ -54,7 +54,7 @@
<li><a href="#waiting-stages" class="side-nav-h3">Waiting Stages</a></li>
<li><a href="#mission-zones" class="side-nav-h3">Mission Zones</a></li>
<li><a href="#cap-routes" class="side-nav-h3">CAP Routes</a></li>
<li><a href="#cap-zones" class="side-nav-h3">CAP Zones</a></li>
<li><a href="#farp-zones" class="side-nav-h3">FARP Zones</a></li>
</ul>
</li>
<li><a href="#mission-types" class="side-nav-h2">Mission Types</a>
@@ -65,6 +65,11 @@
<li><a href="#strike" class="side-nav-h3">STRIKE</a></li>
</ul>
</li>
<li><a href="#mission-briefings" class="side-nav-h2">Mission Briefings</a>
<ul>
<li><a href="#special-fields" class="side-nav-h3">Special Fields</a></li>
</ul>
</li>
<li><a href="#cap-configuration" class="side-nav-h2">CAP Configuration</a>
<ul>
<li><a href="#cap-group-naming" class="side-nav-h3">CAP Group Naming</a></li>
@@ -73,6 +78,7 @@
</ul>
</li>
<li><a href="#randomization" class="side-nav-h2">Randomization</a></li>
<li><a href="#runway-bombing" class="side-nav-h2">Runway Bombing</a></li>
</ul>
</div>
@@ -260,6 +266,21 @@
<strong>Completion Logic:</strong> Destroy all designated targets in the zone.
</p>
<h2 id="mission-briefings">Mission Briefings</h2>
<p>
Mission briefings are text boxes (draw layer) inside of the trigger zone of the mission. <br />
</p>
<h3 id ="special-fields">Special Fields</h3>
<p>
Special fields are used to display information in the mission briefings. <br />
They are replaced with the corresponding values at the time a briefing is requested and can therefore show real time data. <br/>
<strong>Field:</strong> <span class="inline-lua"><span class="lua-variable">{{coords}}</span></span><br/>
Coords are taken from the location of the trigger zone. Then converted to the aircrafts preferred format. <br/>
</p>
<h2 id="cap-configuration">CAP Configuration</h2>
<p>
CAP (Combat Air Patrol) units are managed using specific naming conventions and configurations.
Binary file not shown.
+72 -1
View File
@@ -50,6 +50,18 @@ do -- INIT UTIL
return list[random]
end
---@param str string
---@param find string
---@param replace string
---@return string
function UTIL.replaceString(str, find, replace)
if str == nil then return "" end
if find == nil or replace == nil then return str end
local result = str:gsub(find, replace)
return result
end
local function table_print(tt, indent, done)
done = done or {}
indent = indent or 0
@@ -372,7 +384,7 @@ do -- INIT DCS_UTIL
group = staticObj
end
if skippable == false then
table.insert(DCS_UTIL.__groupNames, name)
DCS_UTIL.__miz_groups[name] =
@@ -454,6 +466,8 @@ do -- INIT DCS_UTIL
for _, airbase in pairs(airbases) do
local name = airbase:getName()
airbase:autoCapture(false)
DCS_UTIL.__airbaseNamesById[tostring(airbase:getID())] = name
if name then
@@ -733,6 +747,63 @@ do -- INIT DCS_UTIL
return nil;
end
---@param location Vec2
---@param unitType string
function DCS_UTIL.convertVec2ToUnitUsableType(location, unitType)
local height = land.getHeight(location)
local vec3 = { x = location.x, y = height, z = location.y }
if unitType == "AH-64D_BLK_II" then
return DCS_UTIL.convertToDisplayCoord(vec3, "MGRS")
end
return DCS_UTIL.convertToDisplayCoord(vec3, "DDM")
end
---@alias CoordType
---| "MGRS"
---| "DDM"
---@param location Vec3
---@param coordType CoordType
function DCS_UTIL.convertToDisplayCoord(location, coordType)
local lattitude, longitude, altitude = coord.LOtoLL(location)
if coordType == "MGRS" then
local mgrs = coord.LLtoMGRS(lattitude, longitude)
return string.format("%s %s %s %s", mgrs.UTMZone, mgrs.MGRSDigraph, mgrs.Northing, mgrs.Easting)
end
-- Convert DD to DDM (Degrees Decimal Minutes)
local function dd_to_ddm(dd)
local degrees = math.floor(math.abs(dd))
local minutes = (math.abs(dd) - degrees) * 60
local sign = dd >= 0 and 1 or -1
return degrees * sign, minutes
end
local lat_deg, lat_min = dd_to_ddm(lattitude)
local lon_deg, lon_min = dd_to_ddm(longitude)
local lat_hemisphere = lattitude >= 0 and "N" or "S"
local lon_hemisphere = longitude >= 0 and "E" or "W"
return string.format("%d° %.3f' %s %d° %.3f' %s %d ft",
math.abs(lat_deg), lat_min, lat_hemisphere,
math.abs(lon_deg), lon_min, lon_hemisphere,
altitude * 3,28084)
end
---@param group Group
function DCS_UTIL.getUnitTypeFromGroup(group)
for _, unit in pairs(group:getUnits()) do
if unit and unit:isExist() then
return unit:getTypeName()
end
end
end
--- get the group config as per start of the mission
--- group = {
--- category,
@@ -57,6 +57,8 @@ function RunwayStrikeMission.new(runway, airbaseName, database, logger, runwayBo
return nil
end
self.location = { x= runway.position.x, y = runway.position.z }
runwayBombingTracker:RegisterRunway(runway, self)
return self
@@ -73,10 +73,24 @@ function Mission:StartCheckingContinuous() end
---comment
---@param groupId number
function Mission:ShowBriefing(groupId)
local group = Spearhead.DcsUtil.GetPlayerGroupByGroupID(groupId)
if group == nil then return end
local unitType = Spearhead.DcsUtil.getUnitTypeFromGroup(group)
local coords = Spearhead.DcsUtil.convertVec2ToUnitUsableType(self.location, unitType)
self._logger:debug("Coords converted: " .. coords)
local stateString = self:ToStateString()
if self._missionBriefing == nil or self._missionBriefing == "" then self._missionBriefing = "No briefing available" end
local briefing = self._missionBriefing
briefing = Spearhead.Util.replaceString(briefing, "{{coords}}", coords)
briefing = Spearhead.Util.replaceString(briefing, "{{ coords }}", coords)
local text = "Mission [" ..
self.code .. "] " .. self.name .. "\n \n" .. self._missionBriefing .. " \n \n" .. stateString
self.code .. "] " .. self.name .. "\n \n" .. briefing .. " \n \n" .. stateString
trigger.action.outTextForGroup(groupId, text, 30);
end