diff --git a/README.md b/README.md
index 9892944..2c63627 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
![Standard View](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/DR_Logo1.png)
-# Damage Report v2.31 (DU-DamageReport)
+# Damage Report v2.33 (DU-DamageReport)
### A multi-screen (and HUD) capable, touch enabled, easy to install ship damage reporting script for **Dual Universe**.
diff --git a/src/DamageReport_2_33_UnitStart.lua b/src/DamageReport_2_33_UnitStart.lua
new file mode 100644
index 0000000..30947d7
--- /dev/null
+++ b/src/DamageReport_2_33_UnitStart.lua
@@ -0,0 +1,1380 @@
+--[[
+ DamageReport v2.33
+ Created By Dorian Gray
+
+ Discord: Dorian Gray#2623
+ InGame: DorianGray
+ GitHub: https://github.com/DorianTheGrey/DU-DamageReport
+
+ GNU Public License 3.0. Use whatever you want, be so kind to leave credit.
+
+ Thanks to Jericho, Dmentia and Archaegeo for learning from their fine scripts.
+]]
+-----------------------------------------------
+-- CONFIG
+-----------------------------------------------
+UseMyElementNames = true --export: If you active this, the display will not show the element type of damaged/broken elements but the name you gave them (truncated to 25 characters)
+AllowElementHighlighting = true --export: Are you allowing damaged/broken elements to be highlighted in 3D space when selected in the HUD?
+UpdateInterval = 1 --export: Interval in seconds between updates of the calculations and (if anything changed) redrawing to the screen(s). You need to restart the script after changing this value.
+HighlightBlinkingInterval = 0.5 --export: If an element is marked, how fast do you want the arrows to blink?
+SimulationMode = false --export Randomize simluated damage on elements to check out the functionality of this script. And, no, your elements won't be harmed in the process :) You need to restart the script after changing this value.
+YourShipsName = "Enter here" --export Enter your ship name here if you want it displayed instead of the ship's ID. YOU NEED TO LEAVE THE QUOTATION MARKS.
+BackgroundColor = "1e1e1e" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.
+
+DebugMode = false -- Activate if you want some console messages
+VersionNumber = 2.33 -- Version number
+
+core = nil
+screens = {}
+
+shipID = 0
+forceRedraw = false
+SimulationActive = false
+
+clickAreas = {}
+DamagedSortingMode = 1 -- Define default sorting mode for damaged elements. 1 to sort by damage amount, 2 to sort by element id, 3 to sort by damage percent,
+BrokenSortingMode = 1 -- Define default sorting mode for broken elements. 1 to sort by damage amount, 2 to sort by element id
+
+HUDMode = false -- Is Hud active?
+hudSelectedIndex = 0 -- Which element is selected?
+hudSelectedType = 0 -- Is selected element damaged (1) or broken (2)
+hudArrowSticker = {}
+highlightOn = false
+highlightID = 0
+highlightX = 0
+highlightY = 0
+highlightZ = 0
+
+CurrentDamagedPage = 1
+CurrentBrokenPage = 1
+
+coreWorldOffset = 0
+totalShipHP = 0
+totalShipMaxHP = 0
+totalShipIntegrity = 100
+elementsId = {}
+damagedElements = {}
+brokenElements = {}
+ElementCounter = 0
+healthyElements = 0
+
+OkayCenterMessage = "All systems nominal."
+
+-----------------------------------------------
+-- FUNCTIONS
+-----------------------------------------------
+
+function GenerateCommaValue(amount)
+ local formatted = amount
+ while true do
+ formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
+ if (k == 0) then break end
+ end
+ return formatted
+end
+
+function PrintDebug(output, highlight)
+ highlight = highlight or false
+ if DebugMode then
+ if highlight then
+ system.print(
+ "------------------------------------------------------------------------")
+ end
+ system.print(output)
+ if highlight then
+ system.print(
+ "------------------------------------------------------------------------")
+ end
+ end
+end
+
+function PrintError(output) system.print(output) end
+
+function DrawCenteredText(output)
+ for i = 1, #screens, 1 do screens[i].setCenteredText(output) end
+end
+
+function DrawSVG(output) for i = 1, #screens, 1 do screens[i].setSVG(output) end end
+
+function ClearConsole() for i = 1, 10, 1 do PrintDebug() end end
+
+function SwitchScreens(state)
+ state = state or true
+ if #screens > 0 then
+ for i = 1, #screens, 1 do
+ if state==true then
+ screens[i].clear()
+ screens[i].activate()
+ else
+ screens[i].deactivate()
+ screens[i].clear()
+ end
+ end
+ end
+end
+
+function InitiateSlots()
+ for slot_name, slot in pairs(unit) do
+ if type(slot) == "table" and type(slot.export) == "table" and
+ slot.getElementClass then
+ if slot.getElementClass():lower():find("coreunit") then
+ core = slot
+ local coreHP = core.getMaxHitPoints()
+ if coreHP > 10000 then
+ coreWorldOffset = 128
+ elseif coreHP > 1000 then
+ coreWorldOffset = 64
+ elseif coreHP > 150 then
+ coreWorldOffset = 32
+ else
+ coreWorldOffset = 16
+ end
+ end
+ if slot.getElementClass():lower():find("screenunit") then
+ screens[#screens + 1] = slot
+ end
+ end
+ end
+end
+
+function AddClickArea(newEntry) table.insert(clickAreas, newEntry) end
+
+function RemoveFromClickAreas(candidate)
+ for k, v in pairs(clickAreas) do
+ if v.id == candidate then
+ clickAreas[k] = nil
+ break
+ end
+ end
+end
+
+function UpdateClickArea(candidate, newEntry)
+ for k, v in pairs(clickAreas) do
+ if v.id == candidate then
+ clickAreas[k] = newEntry
+ break
+ end
+ end
+end
+
+function DisableClickArea(candidate)
+ for k, v in pairs(clickAreas) do
+ if v.id == candidate then
+ UpdateClickArea(candidate, {
+ id = candidate,
+ x1 = -1,
+ x2 = -1,
+ y1 = -1,
+ y2 = -1
+ })
+ break
+ end
+ end
+end
+
+function InitiateClickAreas()
+ clickAreas = {}
+ AddClickArea({id = "DamagedDamage", x1 = 725, x2 = 870, y1 = 380, y2 = 415})
+ AddClickArea({id = "DamagedHealth", x1 = 520, x2 = 655, y1 = 380, y2 = 415})
+ AddClickArea({id = "DamagedID", x1 = 90, x2 = 150, y1 = 380, y2 = 415})
+ AddClickArea({id = "BrokenDamage", x1 = 1675, x2 = 1835, y1 = 380, y2 = 415})
+ AddClickArea({id = "BrokenID", x1 = 1050, x2 = 1110, y1 = 380, y2 = 415})
+ AddClickArea({id = "ToggleSimulation", x1 = 65, x2 = 660, y1 = 100, y2 = 145})
+ AddClickArea({id = "ToggleSimulation2", x1 = 1650, x2 = 1850, y1 = 75, y2 = 117})
+ AddClickArea({id = "ToggleElementLabel", x1 = 225, x2 = 460, y1 = 380, y2 = 415})
+ AddClickArea({id = "ToggleElementLabel2", x1 = 1185, x2 = 1440, y1 = 380, y2 = 415})
+ AddClickArea({id = "ToggleHudMode", x1 = 1650, x2 = 1850, y1 = 125, y2 = 167})
+ AddClickArea({id = "DamagedPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1})
+ AddClickArea({id = "DamagedPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1})
+ AddClickArea({id = "BrokenPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1})
+ AddClickArea({id = "BrokenPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1})
+end
+
+function FlushClickAreas() clickAreas = {} end
+
+function CheckClick(x, y, HitTarget)
+ HitTarget = HitTarget or ""
+ if HitTarget == "" then
+ for k, v in pairs(clickAreas) do
+ if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then
+ HitTarget = v.id
+ break
+ end
+ end
+ end
+ if HitTarget == "DamagedDamage" then
+ DamagedSortingMode = 1
+ CurrentDamagedPage = 1
+ SortTables()
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "DamagedHealth" then
+ DamagedSortingMode = 3
+ CurrentDamagedPage = 1
+ SortTables()
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "DamagedID" then
+ DamagedSortingMode = 2
+ CurrentDamagedPage = 1
+ SortTables()
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "BrokenDamage" then
+ BrokenSortingMode = 1
+ CurrentBrokenPage = 1
+ SortTables()
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "BrokenID" then
+ BrokenSortingMode = 2
+ CurrentBrokenPage = 1
+ SortTables()
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "DamagedPageDown" then
+ CurrentDamagedPage = CurrentDamagedPage + 1
+ if CurrentDamagedPage > math.ceil(#damagedElements / 12) then
+ CurrentDamagedPage = math.ceil(#damagedElements / 12)
+ end
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "DamagedPageUp" then
+ CurrentDamagedPage = CurrentDamagedPage - 1
+ if CurrentDamagedPage < 1 then CurrentDamagedPage = 1 end
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "BrokenPageDown" then
+ CurrentBrokenPage = CurrentBrokenPage + 1
+ if CurrentBrokenPage > math.ceil(#brokenElements / 12) then
+ CurrentBrokenPage = math.ceil(#brokenElements / 12)
+ end
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "BrokenPageUp" then
+ CurrentBrokenPage = CurrentBrokenPage - 1
+ if CurrentBrokenPage < 1 then CurrentBrokenPage = 1 end
+ HudDeselectElement()
+ DrawScreens()
+ elseif HitTarget == "ToggleHudMode" then
+ if HUDMode == true then
+ HUDMode = false
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ else
+ HUDMode = true
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ end
+ elseif HitTarget == "ToggleSimulation" or HitTarget == "ToggleSimulation2" then
+ CurrentDamagedPage = 1
+ CurrentBrokenPage = 1
+ if SimulationMode == true then
+ SimulationMode = false
+ SimulationActive = false
+ GenerateDamageData()
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ else
+ SimulationMode = true
+ SimulationActive = false
+ GenerateDamageData()
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ end
+ elseif HitTarget == "ToggleElementLabel" or HitTarget ==
+ "ToggleElementLabel2" then
+ if UseMyElementNames == true then
+ UseMyElementNames = false
+ SimulationActive = false
+ GenerateDamageData()
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ else
+ UseMyElementNames = true
+ SimulationActive = false
+ GenerateDamageData()
+ forceRedraw = true
+ HudDeselectElement()
+ DrawScreens()
+ end
+ end
+end
+
+function ToggleHUD()
+ HideHighlight()
+ CheckClick(nil, nil, "ToggleHudMode")
+end
+
+function HudDeselectElement()
+ if HUDMode == true then
+ hudSelectedType = 0
+ hudSelectedIndex = 0
+ HideHighlight()
+ DrawScreens()
+ end
+end
+
+function ChangeHudSelectedElement(step)
+ if HUDMode == true and (#damagedElements or #brokenElements) then
+ local damagedElementsHUD = 12
+ if #damagedElements < 12 then
+ damagedElementsHUD = #damagedElements
+ end
+ local brokenElementsHUD = 12
+ if #brokenElements < 12 then brokenElementsHUD = #brokenElements end
+ if step == 1 then
+ if hudSelectedIndex == 0 then
+ if damagedElementsHUD > 0 then
+ hudSelectedType = 1
+ hudSelectedIndex = 1
+ elseif brokenElementsHUD > 0 then
+ hudSelectedType = 2
+ hudSelectedIndex = 1
+ end
+ elseif hudSelectedType == 1 then
+ if damagedElementsHUD > hudSelectedIndex then
+ hudSelectedIndex = hudSelectedIndex + 1
+ elseif brokenElementsHUD > 0 then
+ hudSelectedType = 2
+ hudSelectedIndex = 1
+ elseif damagedElementsHUD > 0 then
+ hudSelectedIndex = 1
+ end
+ elseif hudSelectedType == 2 then
+ if brokenElementsHUD > hudSelectedIndex then
+ hudSelectedIndex = hudSelectedIndex + 1
+ elseif damagedElementsHUD > 0 then
+ hudSelectedType = 1
+ hudSelectedIndex = 1
+ elseif brokenElementsHUD > 0 then
+ hudSelectedIndex = 1
+ end
+ end
+ elseif step == -1 then
+ if hudSelectedIndex == 0 then
+ if brokenElementsHUD > 0 then
+ hudSelectedType = 2
+ hudSelectedIndex = 1
+ elseif damagedElementsHUD > 0 then
+ hudSelectedType = 1
+ hudSelectedIndex = 1
+ end
+ elseif hudSelectedType == 1 then
+ if hudSelectedIndex > 1 then
+ hudSelectedIndex = hudSelectedIndex - 1
+ elseif brokenElementsHUD > 0 then
+ hudSelectedType = 2
+ hudSelectedIndex = brokenElementsHUD
+ elseif damagedElementsHUD > 0 then
+ hudSelectedIndex = damagedElementsHUD
+ end
+ elseif hudSelectedType == 2 then
+ if hudSelectedIndex > 1 then
+ hudSelectedIndex = hudSelectedIndex - 1
+ elseif damagedElementsHUD > 0 then
+ hudSelectedType = 1
+ hudSelectedIndex = damagedElementsHUD
+ elseif brokenElementsHUD > 0 then
+ hudSelectedIndex = brokenElementsHUD
+ end
+ end
+ end
+ HighlightElement()
+ DrawScreens()
+ -- PrintDebug("-> Type: "..hudSelectedType.. " Index: "..hudSelectedIndex)
+ end
+end
+
+function HideHighlight()
+ if #hudArrowSticker > 0 then
+ for i in pairs(hudArrowSticker) do
+ core.deleteSticker(hudArrowSticker[i])
+ end
+ hudArrowSticker = {}
+ end
+end
+
+function ShowHighlight()
+ if highlightOn == true and highlightID > 0 then
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX + 2,
+ highlightY,
+ highlightZ, "north"))
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,
+ highlightY - 2,
+ highlightZ, "east"))
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX - 2,
+ highlightY,
+ highlightZ, "south"))
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,
+ highlightY + 2,
+ highlightZ, "west"))
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,
+ highlightY,
+ highlightZ - 2,
+ "up"))
+ table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,
+ highlightY,
+ highlightZ + 2,
+ "down"))
+ end
+end
+
+function ToggleHighlight()
+ if highlightOn == true then
+ highlightOn = false
+ HideHighlight()
+ else
+ highlightOn = true
+ ShowHighlight()
+ end
+end
+
+function HighlightElement(elementID)
+ elementID = elementID or 0
+ local targetElement = {}
+
+ if elementID == 0 then
+ if hudSelectedType == 1 then
+ elementID = damagedElements[(CurrentDamagedPage - 1) * 12 +
+ hudSelectedIndex].id
+ elseif hudSelectedType == 2 then
+ elementID = brokenElements[(CurrentBrokenPage - 1) * 12 +
+ hudSelectedIndex].id
+ end
+
+ if elementID ~= 0 then
+ local bFound = false
+ for k, v in pairs(damagedElements) do
+ if v.id == elementID then
+ targetElement = v
+ bFound = true
+ break
+ end
+ end
+ if bFound == false then
+ for k, v in pairs(brokenElements) do
+ if v.id == elementID then
+ targetElement = v
+ bFound = true
+ break
+ end
+ end
+ end
+
+ if bFound == true and AllowElementHighlighting == true then
+ HideHighlight()
+ elementPosition = vec3(targetElement.pos)
+ highlightX = elementPosition.x - coreWorldOffset
+ highlightY = elementPosition.y - coreWorldOffset
+ highlightZ = elementPosition.z - coreWorldOffset
+ highlightID = targetElement.id
+ highlightOn = true
+ ShowHighlight()
+ end
+ end
+ end
+end
+
+function SortTables()
+ -- Sort damaged elements descending by percent damaged according to setting
+ if DamagedSortingMode == 1 then
+ table.sort(damagedElements,
+ function(a, b) return a.missinghp > b.missinghp end)
+ elseif DamagedSortingMode == 2 then
+ table.sort(damagedElements, function(a, b) return a.id < b.id end)
+ else
+ table.sort(damagedElements,
+ function(a, b) return a.percent < b.percent end)
+ end
+
+ -- Sort broken elements descending according to setting
+ if BrokenSortingMode == 1 then
+ table.sort(brokenElements, function(a, b)
+ return a.maxhp > b.maxhp
+ end)
+ else
+ table.sort(brokenElements, function(a, b) return a.id < b.id end)
+ end
+end
+
+function GenerateDamageData()
+ if SimulationActive == true then return end
+
+ local formerTotalShipHP = totalShipHP
+ totalShipHP = 0
+ totalShipMaxHP = 0
+ totalShipIntegrity = 100
+ elementsId = {}
+ damagedElements = {}
+ brokenElements = {}
+ ElementCounter = 0
+ healthyElements = 0
+
+ elementsIdList = core.getElementIdList()
+
+ for _, id in pairs(elementsIdList) do
+ ElementCounter = ElementCounter + 1
+ idHP = core.getElementHitPointsById(id) or 0
+ idMaxHP = core.getElementMaxHitPointsById(id) or 0
+
+ if SimulationMode then
+ SimulationActive = true
+ local dice = math.random(0, 10)
+ if dice < 2 then
+ idHP = 0
+ elseif dice >= 2 and dice < 5 then
+ idHP = idMaxHP
+ else
+ idHP = math.random(1, math.ceil(idMaxHP))
+ end
+ end
+
+ totalShipHP = totalShipHP + idHP
+ totalShipMaxHP = totalShipMaxHP + idMaxHP
+
+ idName = core.getElementNameById(id)
+ idType = core.getElementTypeById(id)
+
+ -- Is element damaged?
+ if idMaxHP > idHP then
+ idPos = core.getElementPositionById(id)
+ if idHP > 0 then
+ table.insert(damagedElements, {
+ id = id,
+ name = idName,
+ type = idType,
+ counter = ElementCounter,
+ hp = idHP,
+ maxhp = idMaxHP,
+ missinghp = idMaxHP - idHP,
+ percent = math.ceil(100 / idMaxHP * idHP),
+ pos = idPos
+ })
+ -- if DebugMode then PrintDebug("Damaged: "..idName.." --- Type: "..idType.."") end
+ -- Is element broken?
+ else
+ table.insert(brokenElements, {
+ id = id,
+ name = idName,
+ type = idType,
+ counter = ElementCounter,
+ hp = idHP,
+ maxhp = idMaxHP,
+ missinghp = idMaxHP - idHP,
+ percent = 0,
+ pos = idPos
+ })
+ -- if DebugMode then PrintDebug("Broken: "..idName.." --- Type: "..idType.."") end
+ end
+ else
+ healthyElements = healthyElements + 1
+ if id == highlightID then
+ highlightID = 0
+ end
+ end
+ end
+
+ -- Sort tables by current settings
+ SortTables()
+
+ -- Update clickAreas
+
+ -- Determine total ship integrity
+ totalShipIntegrity = string.format("%2.0f",
+ 100 / totalShipMaxHP * totalShipHP)
+
+ -- Has anything changes since last check? If yes, force redrawing the screens
+ if formerTotalShipHP ~= totalShipHP then
+ forceRedraw = true
+ formerTotalShipHP = totalShipHP
+ else
+ forceRedraw = false
+ end
+end
+
+function GetAllSystemsNominalBackground()
+ local output = ""
+ output = output .. [[
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]
+ return output
+end
+
+function GetDRLogo()
+ output =
+ [[]]
+ return output
+end
+
+function GenerateHUDOutput()
+
+ local hudWidth = 300
+ local hudHeight = 125
+ if #damagedElements > 0 or #brokenElements > 0 then hudHeight = 780 end
+ local screenHeight = 1080
+
+ local healthyColor = "#00aa00"
+ local brokenColor = "#aa0000"
+ local damagedColor = "#aaaa00"
+ local integrityColor = "#aaaaaa"
+ local healthyTextColor = "white"
+ local brokenTextColor = "#ff4444"
+ local damagedTextColor = "#ffff44"
+ local integrityTextColor = "white"
+
+ if #damagedElements == 0 then
+ damagedColor = "#aaaaaa"
+ damagedTextColor = "white"
+ end
+ if #brokenElements == 0 then
+ brokenColor = "#aaaaaa"
+ brokenTextColor = "white"
+ end
+
+ local hudOutput = ""
+
+ -- Draw Header
+ hudOutput = hudOutput .. [[]]
+
+ return hudOutput
+end
+
+function DrawScreens()
+ if #screens > 0 then
+
+ local healthyColor = "#00aa00"
+ local brokenColor = "#aa0000"
+ local damagedColor = "#aaaa00"
+ local integrityColor = "#aaaaaa"
+ local healthyTextColor = "white"
+ local brokenTextColor = "#ff4444"
+ local damagedTextColor = "#ffff44"
+ local integrityTextColor = "white"
+
+ if #damagedElements == 0 then
+ damagedColor = "#aaaaaa"
+ damagedTextColor = "white"
+ end
+ if #brokenElements == 0 then
+ brokenColor = "#aaaaaa"
+ brokenTextColor = "white"
+ end
+
+ local screenOutput = ""
+
+ -- Draw Header
+ screenOutput = screenOutput ..
+ [[
+ ]]
+
+ -- Draw main background
+ screenOutput = screenOutput ..
+ [[
+
+
+
+
+
+
+
+
+
+
+
+ ]]
+
+ -- Draw Title and summary
+ if SimulationActive == true then
+ screenOutput = screenOutput ..
+ [[Simulated Report]]
+ else
+ screenOutput = screenOutput ..
+ [[Damage Report]]
+ end
+ if YourShipsName == nil or YourShipsName == "" or YourShipsName ==
+ "Enter here" then
+ screenOutput = screenOutput ..
+ [[SHIP ID ]] ..
+ shipID .. [[]]
+ else
+ screenOutput = screenOutput ..
+ [[]] ..
+ YourShipsName .. [[]]
+ end
+ screenOutput = screenOutput .. [[
+ Healthy
+ ]] .. healthyElements ..
+ [[
+
+ Damaged
+ ]] .. #damagedElements ..
+ [[
+
+ Broken
+ ]] .. #brokenElements ..
+ [[
+
+ Integrity
+ ]] .. totalShipIntegrity ..
+ [[%]]
+
+ -- Draw damage elements
+
+ if #damagedElements > 0 then
+ local damagedElementsToDraw = #damagedElements
+ if damagedElementsToDraw > 12 then
+ damagedElementsToDraw = 12
+ end
+ if CurrentDamagedPage == math.ceil(#damagedElements / 12) then
+ damagedElementsToDraw = #damagedElements % 12
+ end
+ screenOutput = screenOutput ..
+ [[]]
+ screenOutput = screenOutput ..
+ [[]]
+ if (DamagedSortingMode == 2) then
+ screenOutput = screenOutput ..
+ [[ID]]
+ else
+ screenOutput = screenOutput ..
+ [[ID]]
+ end
+ if UseMyElementNames == true then
+ screenOutput = screenOutput ..
+ [[Element Name]]
+ else
+ screenOutput = screenOutput ..
+ [[Element Type]]
+ end
+
+ if (DamagedSortingMode == 3) then
+ screenOutput = screenOutput ..
+ [[Health]]
+ else
+ screenOutput = screenOutput ..
+ [[Health]]
+ end
+ if (DamagedSortingMode == 1) then
+ screenOutput = screenOutput ..
+ [[Damage]]
+ else
+ screenOutput = screenOutput ..
+ [[Damage]]
+ end
+
+ local i = 0
+ for j = 1 + (CurrentDamagedPage - 1) * 12, damagedElementsToDraw +
+ (CurrentDamagedPage - 1) * 12, 1 do
+ i = i + 1
+ local DP = damagedElements[j]
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%03.0f", DP.id) .. [[]]
+ if UseMyElementNames == true then
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%.25s", DP.name) ..
+ [[]]
+ else
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%.25s", DP.type) ..
+ [[]]
+ end
+ screenOutput = screenOutput .. [[]] ..
+ DP.percent .. [[%]] ..
+ [[]] ..
+ GenerateCommaValue(
+ string.format("%.0f", DP.missinghp)) ..
+ [[]] ..
+ [[]]
+ end
+ screenOutput = screenOutput ..
+ [[
+
+ ]]
+
+ if #damagedElements > 12 then
+ screenOutput = screenOutput ..
+ [[Page ]] ..
+ CurrentDamagedPage .. " of " ..
+ math.ceil(#damagedElements / 12) ..
+ [[]]
+
+ if CurrentDamagedPage < math.ceil(#damagedElements / 12) then
+ screenOutput = screenOutput .. [[
+
+
+ ]]
+ UpdateClickArea("DamagedPageDown", {
+ id = "DamagedPageDown",
+ x1 = 70,
+ x2 = 270,
+ y1 = 350 + 11 + (damagedElementsToDraw + 1) * 50,
+ y2 = 350 + 11 + 50 + (damagedElementsToDraw + 1) * 50
+ })
+ else
+ DisableClickArea("DamagedPageDown")
+ end
+
+ if CurrentDamagedPage > 1 then
+ screenOutput = screenOutput .. [[
+
+
+ ]]
+ UpdateClickArea("DamagedPageUp", {
+ id = "DamagedPageUp",
+ x1 = 280,
+ x2 = 480,
+ y1 = 350 + 11 + (damagedElementsToDraw + 1) * 50,
+ y2 = 350 + 11 + 50 + (damagedElementsToDraw + 1) * 50
+ })
+ else
+ DisableClickArea("DamagedPageUp")
+ end
+ end
+ end
+
+ -- Draw broken elements
+ if #brokenElements > 0 then
+ local brokenElementsToDraw = #brokenElements
+ if brokenElementsToDraw > 12 then
+ brokenElementsToDraw = 12
+ end
+ if CurrentBrokenPage == math.ceil(#brokenElements / 12) then
+ brokenElementsToDraw = #brokenElements % 12
+ end
+ screenOutput = screenOutput ..
+ [[]]
+ screenOutput = screenOutput ..
+ [[]]
+ if (BrokenSortingMode == 2) then
+ screenOutput = screenOutput ..
+ [[ID]]
+ else
+ screenOutput = screenOutput ..
+ [[ID]]
+ end
+ if UseMyElementNames == true then
+ screenOutput = screenOutput ..
+ [[Element Name]]
+ else
+ screenOutput = screenOutput ..
+ [[Element Type]]
+ end
+ if (BrokenSortingMode == 1) then
+ screenOutput = screenOutput ..
+ [[Damage]]
+ else
+ screenOutput = screenOutput ..
+ [[Damage]]
+ end
+
+ local i = 0
+ for j = 1 + (CurrentBrokenPage - 1) * 12, brokenElementsToDraw +
+ (CurrentBrokenPage - 1) * 12, 1 do
+ i = i + 1
+ local DP = brokenElements[j]
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%03.0f", DP.id) .. [[]]
+ if UseMyElementNames == true then
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%.25s", DP.name) ..
+ [[]]
+ else
+ screenOutput = screenOutput .. [[]] ..
+ string.format("%.25s", DP.type) ..
+ [[]]
+ end
+ screenOutput = screenOutput .. [[]] ..
+ GenerateCommaValue(
+ string.format("%.0f", DP.missinghp)) ..
+ [[]] ..
+ [[]]
+ end
+
+ screenOutput = screenOutput ..
+ [[
+
+ ]]
+
+ if #brokenElements > 12 then
+ screenOutput = screenOutput ..
+ [[Page ]] ..
+ CurrentBrokenPage .. " of " ..
+ math.ceil(#brokenElements / 12) ..
+ [[]]
+
+ if CurrentBrokenPage > 1 then
+ screenOutput = screenOutput .. [[
+
+
+ ]]
+ UpdateClickArea("BrokenPageUp", {
+ id = "BrokenPageUp",
+ x1 = 1442,
+ x2 = 1642,
+ y1 = 350 + 11 + (brokenElementsToDraw + 1) * 50,
+ y2 = 350 + 11 + 50 + (brokenElementsToDraw + 1) * 50
+ })
+ else
+ DisableClickArea("BrokenPageUp")
+ end
+
+ if CurrentBrokenPage < math.ceil(#brokenElements / 12) then
+ screenOutput = screenOutput .. [[
+
+
+ ]]
+ UpdateClickArea("BrokenPageDown", {
+ id = "BrokenPageDown",
+ x1 = 1652,
+ x2 = 1852,
+ y1 = 350 + 11 + (brokenElementsToDraw + 1) * 50,
+ y2 = 350 + 11 + 50 + (brokenElementsToDraw + 1) * 50
+ })
+ else
+ DisableClickArea("BrokenPageDown")
+ end
+ end
+
+ end
+
+ -- Draw damage summary
+ if #damagedElements > 0 or #brokenElements > 0 then
+ screenOutput = screenOutput ..
+ [[]] ..
+ GenerateCommaValue(
+ string.format("%.0f",
+ totalShipMaxHP - totalShipHP)) ..
+ [[ HP damage in total]]
+ else
+ screenOutput = screenOutput .. [[]] ..
+ GetAllSystemsNominalBackground() .. [[]] ..
+ [[]] ..
+ OkayCenterMessage .. [[]] ..
+ [[Ship stands ]] ..
+ GenerateCommaValue(
+ string.format("%.0f", totalShipMaxHP)) ..
+ [[ HP strong.]]
+ end
+
+ -- Draw Sim Mode button
+ if SimulationMode == true then
+ screenOutput = screenOutput ..
+ [[]] ..
+ [[Sim Mode]]
+
+ else
+ screenOutput = screenOutput ..
+ [[]] ..
+ [[Sim Mode]]
+ end
+
+ -- Draw HUD Mode button
+ if HUDMode == true then
+ screenOutput = screenOutput ..
+ [[]] ..
+ [[HUD Mode]]
+
+ else
+ screenOutput = screenOutput ..
+ [[]] ..
+ [[HUD Mode]]
+ end
+
+ screenOutput = screenOutput .. [[]]
+
+ DrawSVG(screenOutput)
+
+ forceRedraw = false
+ end
+end
+
+-----------------------------------------------
+-- Execute
+-----------------------------------------------
+
+unit.hide()
+ClearConsole()
+PrintDebug("SCRIPT STARTED", true)
+
+InitiateSlots()
+SwitchScreens(true)
+InitiateClickAreas()
+
+if #screens ~= nil and #screens < 1 then
+ HUDMode = true
+end
+
+if core == nil then
+ DrawCenteredText("ERROR: No core connected.")
+ PrintError("ERROR: No core connected.")
+ goto exit
+else
+ shipID = core.getConstructId()
+end
+
+GenerateDamageData()
+if forceRedraw then DrawScreens() end
+
+unit.setTimer('UpdateData', UpdateInterval)
+unit.setTimer('UpdateHighlight', HighlightBlinkingInterval)
+
+::exit::