diff --git a/DamageReport_2_1.json b/DamageReport_2_1.json new file mode 100644 index 0000000..dd6f61c --- /dev/null +++ b/DamageReport_2_1.json @@ -0,0 +1,339 @@ +{ + "slots": { + "0": { + "name": "core", + "type": { + "events": [], + "methods": [] + } + }, + "1": { + "name": "slot2", + "type": { + "events": [], + "methods": [] + } + }, + "2": { + "name": "slot3", + "type": { + "events": [], + "methods": [] + } + }, + "3": { + "name": "slot4", + "type": { + "events": [], + "methods": [] + } + }, + "4": { + "name": "slot5", + "type": { + "events": [], + "methods": [] + } + }, + "5": { + "name": "slot6", + "type": { + "events": [], + "methods": [] + } + }, + "6": { + "name": "slot7", + "type": { + "events": [], + "methods": [] + } + }, + "7": { + "name": "slot8", + "type": { + "events": [], + "methods": [] + } + }, + "8": { + "name": "slot9", + "type": { + "events": [], + "methods": [] + } + }, + "9": { + "name": "slot10", + "type": { + "events": [], + "methods": [] + } + }, + "-1": { + "name": "unit", + "type": { + "events": [], + "methods": [] + } + }, + "-2": { + "name": "system", + "type": { + "events": [], + "methods": [] + } + }, + "-3": { + "name": "library", + "type": { + "events": [], + "methods": [] + } + } + }, + "handlers": [ + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "1" + }, + "key": "0" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "2" + }, + "key": "1" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "3" + }, + "key": "2" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "4" + }, + "key": "3" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "5" + }, + "key": "4" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "6" + }, + "key": "5" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "7" + }, + "key": "6" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "8" + }, + "key": "7" + }, + { + "code": "clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "9" + }, + "key": "8" + }, + { + "code": "--[[\n DamageReport v2.1\n\n Created By Dorian Gray\n\n Discord: Dorian Gray#2623\n InGame: DorianGray\n GitHub: https://github.com/DorianTheGrey/DU-DamageReport\n\n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Jericho, Dmentia and Archaegeo for learning from their fine scripts.\n]] -----------------------------------------------\n-- CONFIG\n-----------------------------------------------\nUseMyElementNames = 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)\nAllowElementHighlighting = true -- export: Are you allowing damaged/broken elements to be highlighted in 3D space when selected in the HUD?\nUpdateInterval = 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.\nHighlightBlinkingInterval = 0.5 -- export: If an element is marked, how fast do you want the arrows to blink?\nSimulationMode = 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.\nYourShipsName = \"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.\n\nDebugMode = false -- Activate if you want some console messages\nVersionNumber = 2.1 -- Version number\n\ncore = nil\nscreens = {}\n\nshipID = 0\nforceRedraw = false\nSimulationActive = false\n\nclickAreas = {}\nDamagedSortingMode = 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, \nBrokenSortingMode = 1 -- Define default sorting mode for broken elements. 1 to sort by damage amount, 2 to sort by element id\n\nHUDMode = false -- Is Hud active?\nhudSelectedIndex = 0 -- Which element is selected?\nhudSelectedType = 0 -- Is selected element damaged (1) or broken (2)\nhudArrowSticker = {}\nhighlightOn = false\nhighlightX = 0\nhighlightY = 0\nhighlightZ = 0\n\nCurrentDamagedPage = 1\nCurrentBrokenPage = 1\n\ncoreWorldOffset = 0\ntotalShipHP = 0\ntotalShipMaxHP = 0\ntotalShipIntegrity = 100\nelementsId = {}\ndamagedElements = {}\nbrokenElements = {}\nElementCounter = 0\nhealthyElements = 0\n\nOkayCenterMessage = \"All systems nominal.\"\n\n-----------------------------------------------\n-- FUNCTIONS\n-----------------------------------------------\n\nfunction GenerateCommaValue(amount)\n local formatted = amount\n while true do\n formatted, k = string.gsub(formatted, \"^(-?%d+)(%d%d%d)\", '%1,%2')\n if (k == 0) then break end\n end\n return formatted\nend\n\nfunction PrintDebug(output, highlight)\n highlight = highlight or false\n if DebugMode then\n if highlight then\n system.print(\n \"------------------------------------------------------------------------\")\n end\n system.print(output)\n if highlight then\n system.print(\n \"------------------------------------------------------------------------\")\n end\n end\nend\n\nfunction PrintError(output) system.print(output) end\n\nfunction DrawCenteredText(output)\n for i = 1, #screens, 1 do screens[i].setCenteredText(output) end\nend\n\nfunction DrawSVG(output) for i = 1, #screens, 1 do screens[i].setSVG(output) end end\n\nfunction ClearConsole() for i = 1, 10, 1 do PrintDebug() end end\n\nfunction SwitchScreens(state)\n state = state or true\n if #screens > 0 then\n for i = 1, #screens, 1 do\n if state then\n screens[i].clear()\n screens[i].activate()\n else\n screens[i].deactivate()\n screens[i].clear()\n end\n end\n end\nend\n\nfunction InitiateSlots()\n for slot_name, slot in pairs(unit) do\n if type(slot) == \"table\" and type(slot.export) == \"table\" and\n slot.getElementClass then\n if slot.getElementClass():lower():find(\"coreunit\") then\n core = slot\n local coreHP = core.getMaxHitPoints()\n if coreHP > 10000 then\n coreWorldOffset = 128\n elseif coreHP > 1000 then\n coreWorldOffset = 64\n elseif coreHP > 150 then\n coreWorldOffset = 32\n else\n coreWorldOffset = 16\n end\n end\n if slot.getElementClass():lower():find(\"screenunit\") then\n screens[#screens + 1] = slot\n end\n end\n end\nend\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n AddClickArea({id = \"DamagedDamage\", x1 = 725, x2 = 870, y1 = 380, y2 = 415})\n AddClickArea({id = \"DamagedHealth\", x1 = 520, x2 = 655, y1 = 380, y2 = 415})\n AddClickArea({id = \"DamagedID\", x1 = 90, x2 = 150, y1 = 380, y2 = 415})\n AddClickArea({id = \"BrokenDamage\", x1 = 1675, x2 = 1835, y1 = 380, y2 = 415})\n AddClickArea({id = \"BrokenID\", x1 = 1050, x2 = 1110, y1 = 380, y2 = 415})\n AddClickArea({\n id = \"ToggleSimulation\",\n x1 = 65,\n x2 = 660,\n y1 = 100,\n y2 = 145\n })\n AddClickArea({\n id = \"ToggleElementLabel\",\n x1 = 225,\n x2 = 460,\n y1 = 380,\n y2 = 415\n })\n AddClickArea({\n id = \"ToggleElementLabel2\",\n x1 = 1185,\n x2 = 1440,\n y1 = 380,\n y2 = 415\n })\n AddClickArea({\n id = \"ToggleHudMode\",\n x1 = 1397,\n x2 = 1840,\n y1 = 133,\n y2 = 220\n })\n AddClickArea({id = \"DamagedPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"DamagedPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"BrokenPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"BrokenPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n if HitTarget == \"DamagedDamage\" then\n DamagedSortingMode = 1\n CurrentDamagedPage = 1\n SortTables()\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"DamagedHealth\" then\n DamagedSortingMode = 3\n CurrentDamagedPage = 1\n SortTables()\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"DamagedID\" then\n DamagedSortingMode = 2\n CurrentDamagedPage = 1\n SortTables()\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"BrokenDamage\" then\n BrokenSortingMode = 1\n CurrentBrokenPage = 1\n SortTables()\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"BrokenID\" then\n BrokenSortingMode = 2\n CurrentBrokenPage = 1\n SortTables()\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"DamagedPageDown\" then\n CurrentDamagedPage = CurrentDamagedPage + 1\n if CurrentDamagedPage > math.ceil(#damagedElements / 12) then\n CurrentDamagedPage = math.ceil(#damagedElements / 12)\n end\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"DamagedPageUp\" then\n CurrentDamagedPage = CurrentDamagedPage - 1\n if CurrentDamagedPage < 1 then CurrentDamagedPage = 1 end\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"BrokenPageDown\" then\n CurrentBrokenPage = CurrentBrokenPage + 1\n if CurrentBrokenPage > math.ceil(#brokenElements / 12) then\n CurrentBrokenPage = math.ceil(#brokenElements / 12)\n end\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"BrokenPageUp\" then\n CurrentBrokenPage = CurrentBrokenPage - 1\n if CurrentBrokenPage < 1 then CurrentBrokenPage = 1 end\n HudDeselectElement()\n DrawScreens()\n elseif HitTarget == \"ToggleHudMode\" then\n if HUDMode == true then\n HUDMode = false\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n else\n HUDMode = true\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n end\n elseif HitTarget == \"ToggleSimulation\" then\n CurrentDamagedPage = 1\n CurrentBrokenPage = 1\n if SimulationMode == true then\n SimulationMode = false\n SimulationActive = false\n GenerateDamageData()\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n else\n SimulationMode = true\n SimulationActive = false\n GenerateDamageData()\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n end\n elseif HitTarget == \"ToggleElementLabel\" or HitTarget ==\n \"ToggleElementLabel2\" then\n if UseMyElementNames == true then\n UseMyElementNames = false\n SimulationActive = false\n GenerateDamageData()\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n else\n UseMyElementNames = true\n SimulationActive = false\n GenerateDamageData()\n forceRedraw = true\n HudDeselectElement()\n DrawScreens()\n end\n end\nend\n\nfunction ToggleHUD()\n HideHighlight()\n CheckClick(nil, nil, \"ToggleHudMode\")\nend\n\nfunction HudDeselectElement()\n if HUDMode == true then\n hudSelectedType = 0\n hudSelectedIndex = 0\n HideHighlight()\n DrawScreens()\n end\nend\n\nfunction ChangeHudSelectedElement(step)\n if HUDMode == true and (#damagedElements or #brokenElements) then\n local damagedElementsHUD = 12\n if #damagedElements < 12 then\n damagedElementsHUD = #damagedElements\n end\n local brokenElementsHUD = 12\n if #brokenElements < 12 then brokenElementsHUD = #brokenElements end\n if step == 1 then\n if hudSelectedIndex == 0 then\n if damagedElementsHUD > 0 then\n hudSelectedType = 1\n hudSelectedIndex = 1\n elseif brokenElementsHUD > 0 then\n hudSelectedType = 2\n hudSelectedIndex = 1\n end\n elseif hudSelectedType == 1 then\n if damagedElementsHUD > hudSelectedIndex then\n hudSelectedIndex = hudSelectedIndex + 1\n elseif brokenElementsHUD > 0 then\n hudSelectedType = 2\n hudSelectedIndex = 1\n elseif damagedElementsHUD > 0 then\n hudSelectedIndex = 1\n end\n elseif hudSelectedType == 2 then\n if brokenElementsHUD > hudSelectedIndex then\n hudSelectedIndex = hudSelectedIndex + 1\n elseif damagedElementsHUD > 0 then\n hudSelectedType = 1\n hudSelectedIndex = 1\n elseif brokenElementsHUD > 0 then\n hudSelectedIndex = 1\n end\n end\n elseif step == -1 then\n if hudSelectedIndex == 0 then\n if brokenElementsHUD > 0 then\n hudSelectedType = 2\n hudSelectedIndex = 1\n elseif damagedElementsHUD > 0 then\n hudSelectedType = 1\n hudSelectedIndex = 1\n end\n elseif hudSelectedType == 1 then\n if hudSelectedIndex > 1 then\n hudSelectedIndex = hudSelectedIndex - 1\n elseif brokenElementsHUD > 0 then\n hudSelectedType = 2\n hudSelectedIndex = brokenElementsHUD\n elseif damagedElementsHUD > 0 then\n hudSelectedIndex = damagedElementsHUD\n end\n elseif hudSelectedType == 2 then\n if hudSelectedIndex > 1 then\n hudSelectedIndex = hudSelectedIndex - 1\n elseif damagedElementsHUD > 0 then\n hudSelectedType = 1\n hudSelectedIndex = damagedElementsHUD\n elseif brokenElementsHUD > 0 then\n hudSelectedIndex = brokenElementsHUD\n end\n end\n end\n HighlightElement()\n DrawScreens()\n -- PrintDebug(\"-> Type: \"..hudSelectedType.. \" Index: \"..hudSelectedIndex)\n end\nend\n\nfunction HideHighlight()\n if #hudArrowSticker > 0 then\n for i in pairs(hudArrowSticker) do\n core.deleteSticker(hudArrowSticker[i])\n end\n hudArrowSticker = {}\n end\nend\n\nfunction ShowHighlight()\n if highlightOn == true then\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX + 2,\n highlightY,\n highlightZ, \"north\"))\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,\n highlightY - 2,\n highlightZ, \"east\"))\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX - 2,\n highlightY,\n highlightZ, \"south\"))\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,\n highlightY + 2,\n highlightZ, \"west\"))\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,\n highlightY,\n highlightZ - 2,\n \"up\"))\n table.insert(hudArrowSticker, core.spawnArrowSticker(highlightX,\n highlightY,\n highlightZ + 2,\n \"down\"))\n end\nend\n\nfunction ToggleHighlight()\n if highlightOn == true then\n highlightOn = false\n HideHighlight()\n else\n highlightOn = true\n ShowHighlight()\n end\nend\n\nfunction HighlightElement(elementID)\n elementID = elementID or 0\n local targetElement = {}\n\n if elementID == 0 then\n if hudSelectedType == 1 then\n elementID = damagedElements[(CurrentDamagedPage - 1) * 12 +\n hudSelectedIndex].id\n elseif hudSelectedType == 2 then\n elementID = brokenElements[(CurrentBrokenPage - 1) * 12 +\n hudSelectedIndex].id\n end\n\n if elementID ~= 0 then\n local bFound = false\n for k, v in pairs(damagedElements) do\n if v.id == elementID then\n targetElement = v\n bFound = true\n break\n end\n end\n if bFound == false then\n for k, v in pairs(brokenElements) do\n if v.id == elementID then\n targetElement = v\n bFound = true\n break\n end\n end\n end\n\n if bFound == true and AllowElementHighlighting == true then\n HideHighlight()\n elementPosition = vec3(targetElement.pos)\n highlightX = elementPosition.x - coreWorldOffset\n highlightY = elementPosition.y - coreWorldOffset\n highlightZ = elementPosition.z - coreWorldOffset\n highlightOn = true\n ShowHighlight()\n end\n end\n end\nend\n\nfunction SortTables()\n -- Sort damaged elements descending by percent damaged according to setting\n if DamagedSortingMode == 1 then\n table.sort(damagedElements,\n function(a, b) return a.missinghp > b.missinghp end)\n elseif DamagedSortingMode == 2 then\n table.sort(damagedElements, function(a, b) return a.id < b.id end)\n else\n table.sort(damagedElements,\n function(a, b) return a.percent < b.percent end)\n end\n\n -- Sort broken elements descending according to setting\n if BrokenSortingMode == 1 then\n table.sort(brokenElements, function(a, b)\n return a.maxhp > b.maxhp\n end)\n else\n table.sort(brokenElements, function(a, b) return a.id < b.id end)\n end\nend\n\nfunction GenerateDamageData()\n if SimulationActive == true then return end\n\n local formerTotalShipHP = totalShipHP\n totalShipHP = 0\n totalShipMaxHP = 0\n totalShipIntegrity = 100\n elementsId = {}\n damagedElements = {}\n brokenElements = {}\n ElementCounter = 0\n healthyElements = 0\n\n elementsIdList = core.getElementIdList()\n\n for _, id in pairs(elementsIdList) do\n ElementCounter = ElementCounter + 1\n idHP = core.getElementHitPointsById(id) or 0\n idMaxHP = core.getElementMaxHitPointsById(id) or 0\n\n if SimulationMode then\n SimulationActive = true\n local dice = math.random(0, 10)\n if dice < 2 then\n idHP = 0\n elseif dice >= 2 and dice < 5 then\n idHP = idMaxHP\n else\n idHP = math.random(1, math.ceil(idMaxHP))\n end\n end\n\n totalShipHP = totalShipHP + idHP\n totalShipMaxHP = totalShipMaxHP + idMaxHP\n\n idName = core.getElementNameById(id)\n\n -- Is element damaged?\n if idMaxHP > idHP then\n idPos = core.getElementPositionById(id)\n idType = core.getElementTypeById(id)\n if idHP > 0 then\n table.insert(damagedElements, {\n id = id,\n name = idName,\n type = idType,\n counter = ElementCounter,\n hp = idHP,\n maxhp = idMaxHP,\n missinghp = idMaxHP - idHP,\n percent = math.ceil(100 / idMaxHP * idHP),\n pos = idPos\n })\n -- if DebugMode then PrintDebug(\"Damaged: \"..idName..\" --- Type: \"..idType..\"\") end\n -- Is element broken?\n else\n table.insert(brokenElements, {\n id = id,\n name = idName,\n type = idType,\n counter = ElementCounter,\n hp = idHP,\n maxhp = idMaxHP,\n missinghp = idMaxHP - idHP,\n percent = 0,\n pos = idPos\n })\n -- if DebugMode then PrintDebug(\"Broken: \"..idName..\" --- Type: \"..idType..\"\") end\n end\n else\n healthyElements = healthyElements + 1\n end\n end\n\n -- Sort tables by current settings \n SortTables()\n\n -- Update clickAreas\n\n -- Determine total ship integrity\n totalShipIntegrity = string.format(\"%2.0f\",\n 100 / totalShipMaxHP * totalShipHP)\n\n -- Has anything changes since last check? If yes, force redrawing the screens\n if formerTotalShipHP ~= totalShipHP then\n forceRedraw = true\n formerTotalShipHP = totalShipHP\n else\n forceRedraw = false\n end\nend\n\nfunction GetAllSystemsNominalBackground()\n local output = \"\"\n output = output .. [[\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ]]\n return output\nend\n\nfunction GetDRLogo()\n output =\n [[]]\n return output\nend\n\nfunction GenerateHUDOutput()\n\n local hudWidth = 300\n local hudHeight = 125\n if #damagedElements > 0 or #brokenElements > 0 then hudHeight = 780 end\n local screenHeight = 1080\n\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n\n if #damagedElements == 0 then\n damagedColor = \"#aaaaaa\"\n damagedTextColor = \"white\"\n end\n if #brokenElements == 0 then\n brokenColor = \"#aaaaaa\"\n brokenTextColor = \"white\"\n end\n\n local hudOutput = \"\"\n\n -- Draw Header\n hudOutput = hudOutput .. [[\n ]]\n\n hudOutput = hudOutput .. [[]] ..\n [[]] .. GetDRLogo() .. [[]]\n\n hudOutput = hudOutput .. [[\n \n ]] .. healthyElements ..\n [[\n \n ]] .. #damagedElements ..\n [[\n \n ]] .. #brokenElements ..\n [[]]\n if #damagedElements > 0 or #brokenElements > 0 then\n hudOutput = hudOutput ..\n [[ ]] ..\n [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", totalShipMaxHP - totalShipHP)) ..\n [[ HP damage in total]]\n else\n hudOutput = hudOutput .. [[]] ..\n OkayCenterMessage .. [[]] ..\n [[Ship stands ]] ..\n GenerateCommaValue(string.format(\"%.0f\", totalShipMaxHP)) ..\n [[ HP strong.]]\n\n end\n hudOutput = hudOutput .. [[]]\n\n hudRowDistance = 25\n if #damagedElements > 0 then\n local damagedElementsToDraw = #damagedElements\n if damagedElementsToDraw > 12 then damagedElementsToDraw = 12 end\n if CurrentDamagedPage == math.ceil(#damagedElements / 12) then\n damagedElementsToDraw = #damagedElements % 12\n end\n local i = 0\n hudOutput = hudOutput .. [[]] ..\n [[]]\n\n for j = 1 + (CurrentDamagedPage - 1) * 12, damagedElementsToDraw +\n (CurrentDamagedPage - 1) * 12, 1 do\n i = i + 1\n local DP = damagedElements[j]\n if (hudSelectedType == 1 and hudSelectedIndex == i) then\n hudOutput = hudOutput .. [[]]\n if UseMyElementNames == true then\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.name) ..\n [[]]\n else\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.type) ..\n [[]]\n end\n if (DamagedSortingMode == 3) then\n hudOutput = hudOutput .. [[]] .. DP.percent ..\n [[%]]\n else\n hudOutput = hudOutput .. [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]]\n end\n else\n if UseMyElementNames == true then\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.name) ..\n [[]]\n else\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.type) ..\n [[]]\n end\n if (DamagedSortingMode == 3) then\n hudOutput = hudOutput .. [[]] .. DP.percent ..\n [[%]]\n else\n hudOutput = hudOutput .. [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]]\n end\n hudOutput = hudOutput .. [[]]\n end\n end\n hudOutput = hudOutput .. [[]]\n end\n\n if #brokenElements > 0 then\n local brokenElementsToDraw = #brokenElements\n if brokenElementsToDraw > 12 then brokenElementsToDraw = 12 end\n if CurrentbrokenPage == math.ceil(#brokenElements / 12) then\n brokenElementsToDraw = #brokenElements % 12\n end\n local i = 0\n hudOutput = hudOutput .. [[]] ..\n [[]]\n\n for j = 1 + (CurrentBrokenPage - 1) * 12, brokenElementsToDraw +\n (CurrentBrokenPage - 1) * 12, 1 do\n i = i + 1\n local DP = brokenElements[j]\n if (hudSelectedType == 2 and hudSelectedIndex == i) then\n hudOutput = hudOutput .. [[]]\n if UseMyElementNames == true then\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.name) ..\n [[]]\n else\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.type) ..\n [[]]\n end\n if (brokenSortingMode == 3) then\n hudOutput = hudOutput .. [[]] .. DP.percent ..\n [[%]]\n else\n hudOutput = hudOutput .. [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]]\n end\n else\n if UseMyElementNames == true then\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.name) ..\n [[]]\n else\n hudOutput = hudOutput .. [[]] ..\n string.format(\"%.32s\", DP.type) ..\n [[]]\n end\n if (brokenSortingMode == 3) then\n hudOutput = hudOutput .. [[]] .. DP.percent ..\n [[%]]\n else\n hudOutput = hudOutput .. [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]]\n end\n hudOutput = hudOutput .. [[]]\n end\n end\n hudOutput = hudOutput .. [[]]\n end\n\n if #damagedElements or #brokenElements then\n hudOutput = hudOutput .. [[]] ..\n [[Use up/down arrows to select element to find.]] ..\n [[Use right arrow to deselect.]] ..\n [[Use left arrow to exit HUD mode.]] ..\n [[]]\n end\n\n hudOutput = hudOutput .. [[]]\n\n return hudOutput\nend\n\nfunction DrawScreens()\n if #screens > 0 then\n\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n\n if #damagedElements == 0 then\n damagedColor = \"#aaaaaa\"\n damagedTextColor = \"white\"\n end\n if #brokenElements == 0 then\n brokenColor = \"#aaaaaa\"\n brokenTextColor = \"white\"\n end\n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput ..\n [[\n ]]\n\n -- Draw main background\n screenOutput = screenOutput ..\n [[\n \n \n \n \n \n \n \n \n \n \n \n ]]\n\n -- Draw Title and summary\n if SimulationActive == true then\n screenOutput = screenOutput ..\n [[Simulated Report]]\n else\n screenOutput = screenOutput ..\n [[Damage Report]]\n end\n if YourShipsName == nil or YourShipsName == \"\" or YourShipsName ==\n \"Enter here\" then\n screenOutput = screenOutput ..\n [[SHIP ID ]] ..\n shipID .. [[]]\n else\n screenOutput = screenOutput ..\n [[]] ..\n YourShipsName .. [[]]\n end\n screenOutput = screenOutput .. [[\n Healthy\n ]] .. healthyElements ..\n [[\n\n Damaged\n ]] .. #damagedElements ..\n [[\n\n Broken\n ]] .. #brokenElements ..\n [[\n\n Integrity\n ]] .. totalShipIntegrity ..\n [[%]]\n\n -- Draw damage elements\n\n if #damagedElements > 0 then\n local damagedElementsToDraw = #damagedElements\n if damagedElementsToDraw > 12 then\n damagedElementsToDraw = 12\n end\n if CurrentDamagedPage == math.ceil(#damagedElements / 12) then\n damagedElementsToDraw = #damagedElements % 12\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]]\n if (DamagedSortingMode == 2) then\n screenOutput = screenOutput ..\n [[ID]]\n else\n screenOutput = screenOutput ..\n [[ID]]\n end\n if UseMyElementNames == true then\n screenOutput = screenOutput ..\n [[Element Name]]\n else\n screenOutput = screenOutput ..\n [[Element Type]]\n end\n\n if (DamagedSortingMode == 3) then\n screenOutput = screenOutput ..\n [[Health]]\n else\n screenOutput = screenOutput ..\n [[Health]]\n end\n if (DamagedSortingMode == 1) then\n screenOutput = screenOutput ..\n [[Damage]]\n else\n screenOutput = screenOutput ..\n [[Damage]]\n end\n\n local i = 0\n for j = 1 + (CurrentDamagedPage - 1) * 12, damagedElementsToDraw +\n (CurrentDamagedPage - 1) * 12, 1 do\n i = i + 1\n local DP = damagedElements[j]\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%03.0f\", DP.id) .. [[]]\n if UseMyElementNames == true then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%.25s\", DP.name) ..\n [[]]\n else\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%.25s\", DP.type) ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] ..\n DP.percent .. [[%]] ..\n [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]] ..\n [[]]\n end\n screenOutput = screenOutput ..\n [[\n \n ]]\n\n if #damagedElements > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentDamagedPage .. \" of \" ..\n math.ceil(#damagedElements / 12) ..\n [[]]\n\n if CurrentDamagedPage < math.ceil(#damagedElements / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"DamagedPageDown\", {\n id = \"DamagedPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 350 + 11 + (damagedElementsToDraw + 1) * 50,\n y2 = 350 + 11 + 50 + (damagedElementsToDraw + 1) * 50\n })\n else\n DisableClickArea(\"DamagedPageDown\")\n end\n\n if CurrentDamagedPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"DamagedPageUp\", {\n id = \"DamagedPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 350 + 11 + (damagedElementsToDraw + 1) * 50,\n y2 = 350 + 11 + 50 + (damagedElementsToDraw + 1) * 50\n })\n else\n DisableClickArea(\"DamagedPageUp\")\n end\n end\n end\n\n -- Draw broken elements\n if #brokenElements > 0 then\n local brokenElementsToDraw = #brokenElements\n if brokenElementsToDraw > 12 then\n brokenElementsToDraw = 12\n end\n if CurrentBrokenPage == math.ceil(#brokenElements / 12) then\n brokenElementsToDraw = #brokenElements % 12\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]]\n if (BrokenSortingMode == 2) then\n screenOutput = screenOutput ..\n [[ID]]\n else\n screenOutput = screenOutput ..\n [[ID]]\n end\n if UseMyElementNames == true then\n screenOutput = screenOutput ..\n [[Element Name]]\n else\n screenOutput = screenOutput ..\n [[Element Type]]\n end\n if (BrokenSortingMode == 1) then\n screenOutput = screenOutput ..\n [[Damage]]\n else\n screenOutput = screenOutput ..\n [[Damage]]\n end\n\n local i = 0\n for j = 1 + (CurrentBrokenPage - 1) * 12, brokenElementsToDraw +\n (CurrentBrokenPage - 1) * 12, 1 do\n i = i + 1\n local DP = brokenElements[j]\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%03.0f\", DP.id) .. [[]]\n if UseMyElementNames == true then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%.25s\", DP.name) ..\n [[]]\n else\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%.25s\", DP.type) ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", DP.missinghp)) ..\n [[]] ..\n [[]]\n end\n\n screenOutput = screenOutput ..\n [[\n \n ]]\n\n if #brokenElements > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentBrokenPage .. \" of \" ..\n math.ceil(#brokenElements / 12) ..\n [[]]\n\n if CurrentBrokenPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"BrokenPageUp\", {\n id = \"BrokenPageUp\",\n x1 = 1442,\n x2 = 1642,\n y1 = 350 + 11 + (brokenElementsToDraw + 1) * 50,\n y2 = 350 + 11 + 50 + (brokenElementsToDraw + 1) * 50\n })\n else\n DisableClickArea(\"BrokenPageUp\")\n end\n\n if CurrentBrokenPage < math.ceil(#brokenElements / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"BrokenPageDown\", {\n id = \"BrokenPageDown\",\n x1 = 1652,\n x2 = 1852,\n y1 = 350 + 11 + (brokenElementsToDraw + 1) * 50,\n y2 = 350 + 11 + 50 + (brokenElementsToDraw + 1) * 50\n })\n else\n DisableClickArea(\"BrokenPageDown\")\n end\n end\n\n end\n\n -- Draw damage summary\n if #damagedElements > 0 or #brokenElements > 0 then\n screenOutput = screenOutput ..\n [[]] ..\n GenerateCommaValue(\n string.format(\"%.0f\",\n totalShipMaxHP - totalShipHP)) ..\n [[ HP damage in total]]\n else\n screenOutput = screenOutput .. [[]] ..\n GetAllSystemsNominalBackground() .. [[]] ..\n [[]] ..\n OkayCenterMessage .. [[]] ..\n [[Ship stands ]] ..\n GenerateCommaValue(\n string.format(\"%.0f\", totalShipMaxHP)) ..\n [[ HP strong.]]\n end\n\n -- Draw HUD Mode button\n if HUDMode == true then\n screenOutput = screenOutput ..\n [[]] ..\n [[HUD Mode activated]]\n\n else\n screenOutput = screenOutput ..\n [[]] ..\n [[Activate HUD Mode]]\n end\n\n screenOutput = screenOutput .. [[]]\n\n if HUDMode == true then\n system.setScreen(GenerateHUDOutput())\n system.showScreen(1)\n else\n system.showScreen(0)\n end\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\n end\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nClearConsole()\nPrintDebug(\"SCRIPT STARTED\", true)\n\nInitiateSlots()\nSwitchScreens(true)\nInitiateClickAreas()\n\nif core == nil then\n DrawCenteredText(\"ERROR: No core connected.\")\n PrintError(\"ERROR: No core connected.\")\n goto exit\nelse\n shipID = core.getConstructId()\nend\n\nGenerateDamageData()\nif forceRedraw then DrawScreens() end\n\nunit.setTimer('UpdateData', UpdateInterval)\nunit.setTimer('UpdateHighlight', HighlightBlinkingInterval)\n\n::exit::\n", + "filter": { + "args": [], + "signature": "start()", + "slotKey": "-1" + }, + "key": "9" + }, + { + "code": "if #screens > 0 then\n for i=1,#screens,1 do\n screens[i].deactivate()\n screens[i].clear()\n end\nend", + "filter": { + "args": [], + "signature": "stop()", + "slotKey": "-1" + }, + "key": "10" + }, + { + "code": "GenerateDamageData()\nif forceRedraw then\n DrawScreens()\nend", + "filter": { + "args": [ + { + "value": "UpdateData" + } + ], + "signature": "tick(timerId)", + "slotKey": "-1" + }, + "key": "11" + }, + { + "code": "ToggleHighlight()", + "filter": { + "args": [ + { + "value": "UpdateHighlight" + } + ], + "signature": "tick(timerId)", + "slotKey": "-1" + }, + "key": "12" + }, + { + "code": "HudDeselectElement()", + "filter": { + "args": [ + { + "value": "straferight" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "13" + }, + { + "code": "ToggleHUD()", + "filter": { + "args": [ + { + "value": "strafeleft" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "14" + }, + { + "code": "ChangeHudSelectedElement(1)", + "filter": { + "args": [ + { + "value": "down" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "15" + }, + { + "code": "ChangeHudSelectedElement(-1)", + "filter": { + "args": [ + { + "value": "up" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "16" + } + ], + "methods": [], + "events": [] +} \ No newline at end of file diff --git a/README.md b/README.md index ec807db..d07944f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ ![Standard View](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/DR_Logo1.png) -# Damage Report v1.52 (DU-DamageReport) +# Damage Report v2.1 (DU-DamageReport) ### A multi-screen capable, touch enabled, easy to install ship damage reporting script for **Dual Universe**. -**Find that one damaged element faster. Have an eye on the elements of your ship which are hidden by honeycomb. Always know what has been damaged after hitting that tower due to lag near a marketplace. Don't get off your pilot seat to determine whether you need to land and repair immediatelly or have time until you arrived home at your base. Always have an overview during pvp which systems have been hit and have all the data to decide when it's time to run.** +**Find that one damaged element faster. Have an eye on the elements of your ship which are hidden by honeycomb. Always know what has been damaged after hitting that tower due to lag near a marketplace. Don't get off your pilot seat to determine whether you need to land and repair immediatelly or have time until you arrived home at your base. Always have an overview during pvp which systems have been hit and have all the data to decide when it's time to run. Highlight damaged or broken elements in 3D space through the HUD Mode to find what you want to repair much faster.** *Created By Dorian Gray* @@ -15,8 +15,10 @@ **Installation and usage description as well as the roadmap are below the images.** +![Activate HUD Mode Standard View](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/ActivateHUDMode.png) ![Standard View](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/StandardView.png) ![Cockpit](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/InstalledToShip2.png) +![HUD Mode](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/DamageReportHUD.png) ![All systems nominal](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/AllSystemsNominal2.png) ![Change Sorting](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/ChangeSorting.png) ![Simulation Mode](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/SimulatedView.png) @@ -34,7 +36,7 @@ ### Usage -1. The script simply displays your damage data of your ship onto 1 to X screens, separated by damaged modules as well as broken modules. You can click on the captions of any screen to change the sorting (by damage, by health or by id). If you click on the title ("Damage Report"), you can enter Simulation Mode (see 3.) +1. The script simply displays your damage data of your ship onto 1 to X screens, separated by damaged modules as well as broken modules. You can click on the captions of any screen to change the sorting (by damage, by health or by id). If you click on the title ("Damage Report"), you can enter Simulation Mode (see 3.). If you activate HUD mode (click on the screen), you can use the arrow-up and arrow-down keys to highlight elements, so that blinking markers in 3D space help you find it. 2. Rightclicking on your Programming Board -> Advanced -> Edit LUA parameters allows you to change four values: * [Optional] If you enable UseMyElementNames the display on the screens will not label damaged/broken elements by their type but by the name you gave them (truncated to 25 characters). Please note you can also click on the "Element Type" label on any connected screen to switch the mode. * [Optional] You can change the update interval in which the damage data of your ship will be scanned and processed. By default, this is 1 second. Please note that your screens will only refresh if your data changed. diff --git a/img/ActivateHUDMode.png b/img/ActivateHUDMode.png new file mode 100644 index 0000000..0a1afc6 Binary files /dev/null and b/img/ActivateHUDMode.png differ diff --git a/img/DamageReportHUD.png b/img/DamageReportHUD.png new file mode 100644 index 0000000..3f063bb Binary files /dev/null and b/img/DamageReportHUD.png differ diff --git a/src/DamageReport_2_1_UnitStart.lua b/src/DamageReport_2_1_UnitStart.lua new file mode 100644 index 0000000..ced1a02 --- /dev/null +++ b/src/DamageReport_2_1_UnitStart.lua @@ -0,0 +1,1388 @@ +--[[ + DamageReport v2.1 + + 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. + +DebugMode = false -- Activate if you want some console messages +VersionNumber = 2.1 -- 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 +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 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 = "ToggleElementLabel", + x1 = 225, + x2 = 460, + y1 = 380, + y2 = 415 + }) + AddClickArea({ + id = "ToggleElementLabel2", + x1 = 1185, + x2 = 1440, + y1 = 380, + y2 = 415 + }) + AddClickArea({ + id = "ToggleHudMode", + x1 = 1397, + x2 = 1840, + y1 = 133, + y2 = 220 + }) + 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" 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 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 + 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) + + -- Is element damaged? + if idMaxHP > idHP then + idPos = core.getElementPositionById(id) + idType = core.getElementTypeById(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 + 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 .. [[ + ]] + + hudOutput = hudOutput .. [[]] .. + [[]] .. GetDRLogo() .. [[]] + + hudOutput = hudOutput .. [[ + + ]] .. healthyElements .. + [[ + + ]] .. #damagedElements .. + [[ + + ]] .. #brokenElements .. + [[]] + if #damagedElements > 0 or #brokenElements > 0 then + hudOutput = hudOutput .. + [[ ]] .. + [[]] .. + GenerateCommaValue( + string.format("%.0f", totalShipMaxHP - totalShipHP)) .. + [[ HP damage in total]] + else + hudOutput = hudOutput .. [[]] .. + OkayCenterMessage .. [[]] .. + [[Ship stands ]] .. + GenerateCommaValue(string.format("%.0f", totalShipMaxHP)) .. + [[ HP strong.]] + + end + hudOutput = hudOutput .. [[]] + + hudRowDistance = 25 + 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 + local i = 0 + hudOutput = hudOutput .. [[]] .. + [[]] + + for j = 1 + (CurrentDamagedPage - 1) * 12, damagedElementsToDraw + + (CurrentDamagedPage - 1) * 12, 1 do + i = i + 1 + local DP = damagedElements[j] + if (hudSelectedType == 1 and hudSelectedIndex == i) then + hudOutput = hudOutput .. [[]] + if UseMyElementNames == true then + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.name) .. + [[]] + else + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.type) .. + [[]] + end + if (DamagedSortingMode == 3) then + hudOutput = hudOutput .. [[]] .. DP.percent .. + [[%]] + else + hudOutput = hudOutput .. [[]] .. + GenerateCommaValue( + string.format("%.0f", DP.missinghp)) .. + [[]] + end + else + if UseMyElementNames == true then + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.name) .. + [[]] + else + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.type) .. + [[]] + end + if (DamagedSortingMode == 3) then + hudOutput = hudOutput .. [[]] .. DP.percent .. + [[%]] + else + hudOutput = hudOutput .. [[]] .. + GenerateCommaValue( + string.format("%.0f", DP.missinghp)) .. + [[]] + end + hudOutput = hudOutput .. [[]] + end + end + hudOutput = hudOutput .. [[]] + end + + 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 + local i = 0 + hudOutput = hudOutput .. [[]] .. + [[]] + + for j = 1 + (CurrentBrokenPage - 1) * 12, brokenElementsToDraw + + (CurrentBrokenPage - 1) * 12, 1 do + i = i + 1 + local DP = brokenElements[j] + if (hudSelectedType == 2 and hudSelectedIndex == i) then + hudOutput = hudOutput .. [[]] + if UseMyElementNames == true then + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.name) .. + [[]] + else + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.type) .. + [[]] + end + if (brokenSortingMode == 3) then + hudOutput = hudOutput .. [[]] .. DP.percent .. + [[%]] + else + hudOutput = hudOutput .. [[]] .. + GenerateCommaValue( + string.format("%.0f", DP.missinghp)) .. + [[]] + end + else + if UseMyElementNames == true then + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.name) .. + [[]] + else + hudOutput = hudOutput .. [[]] .. + string.format("%.32s", DP.type) .. + [[]] + end + if (brokenSortingMode == 3) then + hudOutput = hudOutput .. [[]] .. DP.percent .. + [[%]] + else + hudOutput = hudOutput .. [[]] .. + GenerateCommaValue( + string.format("%.0f", DP.missinghp)) .. + [[]] + end + hudOutput = hudOutput .. [[]] + end + end + hudOutput = hudOutput .. [[]] + end + + if #damagedElements or #brokenElements then + hudOutput = hudOutput .. [[]] .. + [[Use up/down arrows to select element to find.]] .. + [[Use right arrow to deselect.]] .. + [[Use left arrow to exit HUD mode.]] .. + [[]] + end + + 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 HUD Mode button + if HUDMode == true then + screenOutput = screenOutput .. + [[]] .. + [[HUD Mode activated]] + + else + screenOutput = screenOutput .. + [[]] .. + [[Activate HUD Mode]] + end + + screenOutput = screenOutput .. [[]] + + if HUDMode == true then + system.setScreen(GenerateHUDOutput()) + system.showScreen(1) + else + system.showScreen(0) + end + + DrawSVG(screenOutput) + + forceRedraw = false + end +end + +----------------------------------------------- +-- Execute +----------------------------------------------- + +unit.hide() +ClearConsole() +PrintDebug("SCRIPT STARTED", true) + +InitiateSlots() +SwitchScreens(true) +InitiateClickAreas() + +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:: diff --git a/DamageReport_1_52.json b/versions/DamageReport_1_52.json similarity index 100% rename from DamageReport_1_52.json rename to versions/DamageReport_1_52.json