diff --git a/DamageReport_3_03.conf b/DamageReport_3_03.conf new file mode 100644 index 0000000..d79d38a --- /dev/null +++ b/DamageReport_3_03.conf @@ -0,0 +1,452 @@ +{ + "slots": { + "0": { + "name": "slot1", + "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": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "0" + }, + "key": "0" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "2" + }, + "key": "1" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "3" + }, + "key": "2" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "4" + }, + "key": "3" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "5" + }, + "key": "4" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "6" + }, + "key": "5" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "7" + }, + "key": "6" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "8" + }, + "key": "7" + }, + { + "code": "CheckClick(x, y)", + "filter": { + "args": [ + { + "variable": "*" + }, + { + "variable": "*" + } + ], + "signature": "mouseDown(x,y)", + "slotKey": "9" + }, + "key": "8" + }, + { + "code": "function GenerateCommaValue(a,b,c)b=b or false;c=c or 1;local d=a;if b==true then if string.len(a)>=4 then d=string.format(\"%.\"..c..\"fk\",a/1000)else d=string.format(\"%.\"..c..\"f\",a)end else while true do d,k=string.gsub(d,\"^(-?%d+)(%d%d%d)\",'%1,%2')if k==0 then break end end end;return d end;function PrintConsole(e,f)f=f or false;if f then system.print(\"------------------------------------------------------------------------\")end;system.print(e)if f then system.print(\"------------------------------------------------------------------------\")end end;function DrawCenteredText(e)if screens~=nil and#screens>0 then for g=1,#screens,1 do screens[g].element.setCenteredText(e)end end end;function ClearConsole()for g=1,10,1 do PrintConsole()end end;function SwitchScreens(h)h=h or\"on\"if screens~=nil and#screens>0 then for g=1,#screens,1 do if h==\"on\"then screens[g].element.clear()screens[g].element.activate()screens[g].active=true else screens[g].element.clear()screens[g].element.deactivate()screens[g].active=false end end end end;function GetSecondsString(i)local i=tonumber(i)if i==nil or i<=0 then return\"-\"else days=string.format(\"%2.f\",math.floor(i/(3600*24)))hours=string.format(\"%2.f\",math.floor(i/3600-days*24))mins=string.format(\"%2.f\",math.floor(i/60-hours*60-days*24*60))secs=string.format(\"%2.f\",math.floor(i-hours*3600-days*24*60*60-mins*60))str=\"\"if tonumber(days)>0 then str=str..days..\"d \"end;if tonumber(hours)>0 then str=str..hours..\"h \"end;if tonumber(mins)>0 then str=str..mins..\"m \"end;if tonumber(secs)>0 then str=str..secs..\"s\"end;return str end end;function replace_char(j,str,l)return str:sub(1,j-1)..l..str:sub(j+1)end;function epochTime()function rZ(m)if string.len(m)<=1 then return\"0\"..m else return m end end;function dPoint(n)if not(n==math.floor(n))then return true else return false end end;function lYear(year)if not dPoint(year/4)then if dPoint(year/100)then return true else if not dPoint(year/400)then return true else return false end end else return false end end;local o=5;local p=3600;local q=86400;local r=31536000;local s=31622400;local t=2419200;local g=2505600;local u=2592000;local k=2678400;local w={4,6,9,11}local x={1,3,5,7,8,10,12}local y=0;local z=1506816000;local A=system.getTime()_G[\"formerTime\"]=A;if AddSummertimeHour==true then A=A+3600 end;now=math.floor(A+z)year=1970;secs=0;y=0;while secs+s]]..hour..\":\"..minute..[[]]..[[]]..year..\"/\"..month..\"/\"..day..[[]]end;function ToggleHUD()if HUDMode==true then HUDMode=false;forceDamageRedraw=true;hudSelectedIndex=0;highlightID=0;HideHighlight()SetRefresh()RenderScreens()else HUDMode=true;forceDamageRedraw=true;hudSelectedIndex=0;highlightID=0;HideHighlight()SetRefresh()RenderScreens()end end;function HudDeselectElement()hudSelectedIndex=0;hudStartIndex=1;highlightID=0;HideHighlight()if HUDMode==true then SetRefresh(\"damage\")SetRefresh(\"damageoutline\")RenderScreens()end end;function ChangeHudSelectedElement(B)if HUDMode==true and#rE>0 then hudSelectedIndex=hudSelectedIndex+B;if hudSelectedIndex<1 then hudSelectedIndex=1 elseif hudSelectedIndex>#rE then hudSelectedIndex=#rE end;if hudSelectedIndex>9 then hudStartIndex=hudSelectedIndex-9 end;if hudSelectedIndex~=0 then highlightID=rE[hudSelectedIndex].id;if highlightID~=nil and highlightID~=0 then HideHighlight()elementPosition=vec3(rE[hudSelectedIndex].pos)highlightX=elementPosition.x-coreWorldOffset;highlightY=elementPosition.y-coreWorldOffset;highlightZ=elementPosition.z-coreWorldOffset;highlightOn=true;ShowHighlight()end end;SetRefresh(\"damage\")SetRefresh(\"damageoutline\")RenderScreens()end end;function HideHighlight()if#hudArrowSticker>0 then for g in pairs(hudArrowSticker)do core.deleteSticker(hudArrowSticker[g])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 SortDamageTables()table.sort(damagedElements,function(m,n)return m.missinghp>n.missinghp end)table.sort(brokenElements,function(m,n)return m.maxhp>n.maxhp end)end;function getScraps(C,D)D=D or false;C=C-SkillRepairToolOptimization*0.05*C;local E=math.ceil(C/(10*5^(ScrapTier-1)))if D==true then return GenerateCommaValue(string.format(\"%.0f\",E),false)else return E end end;function getRepairTime(C,F)F=F or false;C=C-SkillRepairToolOptimization*0.05*C;local E=math.ceil(C/ScrapTierRepairTimes[ScrapTier])E=E-SkillRepairToolEfficiency*0.1*E;if F==true then return GetSecondsString(string.format(\"%.0f\",E))else return E end end;function UpdateDataDamageoutline()dmgoElements={}for g,G in ipairs(brokenElements)do if#dmgoElementsShipXmax then ShipXmax=H end;if I>ShipYmax then ShipYmax=I end;if J>ShipZmax then ShipZmax=J end;table.insert(dmgoElements,{id=G.id,type=\"b\",size=G.maxhp,x=H,y=I,z=J,xp=0,yp=0,zp=0,u=0,v=0})end end;if#dmgoElementsShipXmax then ShipXmax=H end;if I>ShipYmax then ShipYmax=I end;if J>ShipZmax then ShipZmax=J end;table.insert(dmgoElements,{id=G.id,type=\"d\",size=G.maxhp,x=H,y=I,z=J,xp=0,yp=0,zp=0,u=0,v=0})end end end;if#dmgoElementsShipXmax then ShipXmax=H end;if I>ShipYmax then ShipYmax=I end;if J>ShipZmax then ShipZmax=J end;table.insert(dmgoElements,{id=G.id,type=\"h\",size=G.maxhp,x=H,y=I,z=J,xp=0,yp=0,zp=0,u=0,v=0})end end end;ShipX=math.abs(ShipXmax-ShipXmin)ShipY=math.abs(ShipYmax-ShipYmin)ShipZ=math.abs(ShipZmax-ShipZmin)for g,G in ipairs(dmgoElements)do dmgoElements[g].xp=math.abs(100/(ShipXmax-ShipXmin)*(G.x-ShipXmin))dmgoElements[g].yp=math.abs(100/(ShipYmax-ShipYmin)*(G.y-ShipYmin))dmgoElements[g].zp=math.abs(100/(ShipZmax-ShipZmin)*(G.z-ShipZmin))end end;function UpdateViewDamageoutline(K)UFrame=40;VFrame=40;UStart=20+UFrame;VStart=180+VFrame;UDim=1880-2*UFrame;VDim=840-2*VFrame;if K.submode==\"top\"then if DMGOStretch==false then local L=UDim/(ShipYmax-ShipYmin)local M=VDim/(ShipXmax-ShipXmin)if L>=M then local N=L/M;local O=math.floor(UDim/N)UStart=UStart+(UDim-O)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100/N*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100*G.xp+VStart)end else local N=M/L;local P=math.floor(VDim/N)VStart=VStart+(VDim-P)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100/N*G.xp+VStart)end end else for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100*G.xp+VStart)end end elseif K.submode==\"front\"then if DMGOStretch==false then local L=UDim/(ShipXmax-ShipXmin)local M=VDim/(ShipZmax-ShipZmin)if L>=M then local N=L/M;local O=math.floor(UDim/N)UStart=UStart+(UDim-O)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100/N*G.xp+UStart)dmgoElements[g].v=math.floor(VDim/100*(100-G.zp)+VStart)end else local N=M/L;local P=math.floor(VDim/N)VStart=VStart+(VDim-P)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.xp+UStart)dmgoElements[g].v=math.floor(VDim/100/N*(100-G.zp)+VStart)end end else for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.xp+UStart)dmgoElements[g].v=math.floor(VDim/100*(100-G.zp)+VStart)end end elseif K.submode==\"side\"then if DMGOStretch==false then local L=UDim/(ShipYmax-ShipYmin)local M=VDim/(ShipXmax-ShipZmin)if L>=M then local N=L/M;local O=math.floor(UDim/N)UStart=UStart+(UDim-O)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100/N*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100*(100-G.zp)+VStart)end else local N=M/L;local P=math.floor(VDim/N)VStart=VStart+(VDim-P)/2;for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100/N*(100-G.zp)+VStart)end end else for g,G in ipairs(dmgoElements)do dmgoElements[g].u=math.floor(UDim/100*G.yp+UStart)dmgoElements[g].v=math.floor(VDim/100*(100-G.zp)+VStart)end end else DrawCenteredText(\"ERROR: non-existing DMGO mode set.\")PrintConsole(\"ERROR: non-existing DMGO mode set.\")unit.exit()end end;function GetDamageoutlineShip()local e=\"\"for g,G in ipairs(dmgoElements)do local Q=\"\"local R=1;if G.type==\"h\"then Q=\"ch\"elseif G.type==\"d\"then Q=\"cw\"else Q=\"cc\"end;if G.id==highlightID then Q=\"f2\"end;if G.size>0 and G.size<1000 then R=5 elseif G.size>=1000 and G.size<2000 then R=8 elseif G.size>=2000 and G.size<5000 then R=12 elseif G.size>=5000 and G.size<10000 then R=15 elseif G.size>=10000 and G.size<20000 then R=20 elseif G.size>=20000 then R=30 end;e=e..[[]]if G.id==highlightID then e=e..[[]]e=e..[[]]end end;return e end;function GetContentClickareas(K)local e=\"\"if K~=nil and K.ClickAreas~=nil and#K.ClickAreas>0 then for g,S in ipairs(K.ClickAreas)do e=e..[[]]end end;return e end;function GetElement1(H,I,T,U)H=H or 0;I=I or 0;T=T or 600;U=U or 600;local e=\"\"e=e..[[\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ]]return e end;function GetElement2(H,I)H=H or 0;I=I or 0;local e=\"\"e=e..[[]]return e end;function GetElementLogo(H,I,V,W,X)H=H or 812;I=I or 380;V=V or\"f\"W=W or\"f2\"X=X or\"f3\"local e=\"\"e=e..[[\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 e end;function GetHeader(Y)Y=Y or\"ERROR: UNDEFINED\"local e=\"\"e=e..[[\n ]]..Y..[[]]return e end;function GetContentBackground(Z,_)bgColor=ColorBackgroundPattern;local e=\"\"if Z==\"dots\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E\");]]elseif Z==\"rain\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg width='12' height='16' viewBox='0 0 12 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 .99C4 .445 4.444 0 5 0c.552 0 1 .45 1 .99v4.02C6 5.555 5.556 6 5 6c-.552 0-1-.45-1-.99V.99zm6 8c0-.546.444-.99 1-.99.552 0 1 .45 1 .99v4.02c0 .546-.444.99-1 .99-.552 0-1-.45-1-.99V8.99z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E\");]]elseif Z==\"plus\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E\");]]elseif Z==\"signal\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg width='84' height='48' viewBox='0 0 84 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h12v6H0V0zm28 8h12v6H28V8zm14-8h12v6H42V0zm14 0h12v6H56V0zm0 8h12v6H56V8zM42 8h12v6H42V8zm0 16h12v6H42v-6zm14-8h12v6H56v-6zm14 0h12v6H70v-6zm0-16h12v6H70V0zM28 32h12v6H28v-6zM14 16h12v6H14v-6zM0 24h12v6H0v-6zm0 8h12v6H0v-6zm14 0h12v6H14v-6zm14 8h12v6H28v-6zm-14 0h12v6H14v-6zm28 0h12v6H42v-6zm14-8h12v6H56v-6zm0-8h12v6H56v-6zm14 8h12v6H70v-6zm0 8h12v6H70v-6zM14 24h12v6H14v-6zm14-8h12v6H28v-6zM14 8h12v6H14V8zM0 8h12v6H0V8z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E\");]]elseif Z==\"deathstar\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='105' viewBox='0 0 80 105'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath d='M20 10a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V10zm15 35a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zM20 75a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V75zm30-65a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V10zm0 65a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V75zM35 10a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10zM5 45a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zm0-35a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10zm60 35a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zm0-35a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10z' /%3E%3C/g%3E%3C/g%3E%3C/svg%3E\");]]elseif Z==\"diamond\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='32' viewBox='0 0 16 32'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath fill-rule='evenodd' d='M0 24h4v2H0v-2zm0 4h6v2H0v-2zm0-8h2v2H0v-2zM0 0h4v2H0V0zm0 4h2v2H0V4zm16 20h-6v2h6v-2zm0 4H8v2h8v-2zm0-8h-4v2h4v-2zm0-20h-6v2h6V0zm0 4h-4v2h4V4zm-2 12h2v2h-2v-2zm0-8h2v2h-2V8zM2 8h10v2H2V8zm0 8h10v2H2v-2zm-2-4h14v2H0v-2zm4-8h6v2H4V4zm0 16h6v2H4v-2zM6 0h2v2H6V0zm0 24h2v2H6v-2z'/%3E%3C/g%3E%3C/svg%3E\");]]elseif Z==\"hexagon\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg id='hexagons' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='nonzero'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E\");]]elseif Z==\"capsule\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg width='32' height='26' viewBox='0 0 32 26' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 0v3.994C14 7.864 10.858 11 7 11c-3.866 0-7-3.138-7-7.006V0h2v4.005C2 6.765 4.24 9 7 9c2.756 0 5-2.236 5-4.995V0h2zm0 26v-5.994C14 16.138 10.866 13 7 13c-3.858 0-7 3.137-7 7.006V26h2v-6.005C2 17.235 4.244 15 7 15c2.76 0 5 2.236 5 4.995V26h2zm2-18.994C16 3.136 19.142 0 23 0c3.866 0 7 3.138 7 7.006v9.988C30 20.864 26.858 24 23 24c-3.866 0-7-3.138-7-7.006V7.006zm2-.01C18 4.235 20.244 2 23 2c2.76 0 5 2.236 5 4.995v10.01C28 19.765 25.756 22 23 22c-2.76 0-5-2.236-5-4.995V6.995z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E\");]]elseif Z==\"diagonal\"then e=[[background-image: url(\"data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E\");]]end;return e end;function GetContentDamageHUDOutput()local a0=300;local a1=165;if#damagedElements>0 or#brokenElements>0 then a1=510 end;local e=\"\"e=e..[[\n \n ]]e=e..[[]]..[[]]..[[]]..[[]]..(YourShipsName==\"Enter here\"and\"Ship ID \"..ShipID or YourShipsName)..[[]]..[[]]if#brokenElements>0 then e=e..[[]]elseif#damagedElements>0 then e=e..[[]]else e=e..[[]]end;if#damagedElements>0 or#brokenElements>0 then e=e..[[Total Damage]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",totalShipMaxHP-totalShipHP))..[[]]e=e..[[T]]..ScrapTier..[[ Scrap Needed]]..[[]]..getScraps(totalShipMaxHP-totalShipHP,true)..[[]]e=e..[[Repair Time]]..[[]]..getRepairTime(totalShipMaxHP-totalShipHP,true)..[[]]e=e..[[]]..[[]]..[[]]..#healthyElements..[[]]..[[]]..[[]]..#damagedElements..[[]]..[[]]..[[]]..#brokenElements..[[]]local u=0;for a2=hudStartIndex,hudStartIndex+9,1 do if rE[a2]~=nil then v=rE[a2]if v.hp>0 then e=e..[[]]..[[]]..string.format(\"%.30s\",v.name)..[[]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",v.missinghp))..[[]]if v.id==highlightID then e=e..[[]]..[[]]..string.format(\"%.30s\",v.name)..[[]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",v.missinghp))..[[]]end else e=e..[[]]..[[]]..string.format(\"%.30s\",v.name)..[[]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",v.missinghp))..[[]]if v.id==highlightID then highlightX=elementPosition.x-coreWorldOffset;highlightY=elementPosition.y-coreWorldOffset;highlightZ=elementPosition.z-coreWorldOffset;e=e..[[]]..[[]]..string.format(\"%.30s\",v.name)..[[]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",v.missinghp))..[[]]end end;u=u+1 end end;e=e..[[]]..[[]]..[[]]..[[]]..[[Up/down arrows to highlight]]..[[CTRL + arrows to move HUD]]..[[Left arrow to toggle HUD Mode]]..[[ALT+1-4 to set Scrap Tier]]..[[ALT+8 to reset HUD position]]..[[ALT+9 to shut script off]]..[[]]..[[]]else e=e..[[]]..OkayCenterMessage..[[]]..[[]]..#healthyElements..[[ elements / ]]..GenerateCommaValue(string.format(\"%.0f\",totalShipMaxHP))..[[ HP.]]..[[]]..[[]]..[[]]..[[]]..[[Left arrow to toggle HUD Mode]]..[[CTRL + arrows to move HUD]]..[[ALT+8 to reset HUD position]]..[[ALT+9 to shut script off]]..[[]]..[[]]end;e=e..[[]]return e end;function GetContentDamageScreen()local a3=\"\"if#damagedElements>0 then local a4=#damagedElements;if a4>DamagePageSize then a4=DamagePageSize end;if CurrentDamagedPage==math.ceil(#damagedElements/DamagePageSize)then a4=#damagedElements%DamagePageSize+12;if a4>12 then a4=a4-12 end end;a3=a3 ..[[]]a3=a3 ..[[]]if UseMyElementNames==true then a3=a3 ..[[Damaged Name]]else a3=a3 ..[[Damaged Type]]end;a3=a3 ..[[HLTHDMG]]a3=a3 ..[[T]]..ScrapTier..[[ SCRREPTIME]]AddClickArea(\"damage\",{id=\"SwitchScrapTier\",mode=\"damage\",x1=650,x2=775,y1=315,y2=360})local g=0;for u=1+(CurrentDamagedPage-1)*DamagePageSize,a4+(CurrentDamagedPage-1)*DamagePageSize,1 do g=g+1;local a5=damagedElements[u]if UseMyElementNames==true then a3=a3 ..[[]]..string.format(\"%.23s\",a5.name)..[[]]else a3=a3 ..[[]]..string.format(\"%.23s\",a5.type)..[[]]end;a3=a3 ..[[]]..a5.percent..[[%]]..[[]]..GenerateCommaValue(string.format(\"%.0f\",a5.missinghp),true)..[[]]..[[]]..getScraps(a5.missinghp,true)..[[]]..[[]]..getRepairTime(a5.missinghp,true)..[[]]..[[]]end;if#damagedElements>DamagePageSize then a3=a3 ..[[Page ]]..CurrentDamagedPage..\" of \"..math.ceil(#damagedElements/DamagePageSize)..[[]]if CurrentDamagedPage\n \n \n ]]AddClickArea(\"damage\",{id=\"DamagedPageDown\",mode=\"damage\",x1=65,x2=260,y1=290+(a4+1)*50,y2=290+50+(a4+1)*50})else DisableClickArea(\"DamagedPageDown\",\"damage\")end;if CurrentDamagedPage>1 then a3=a3 ..[[\n \n \n ]]AddClickArea(\"damage\",{id=\"DamagedPageUp\",mode=\"damage\",x1=750,x2=950,y1=290+(a4+1)*50,y2=290+50+(a4+1)*50})else DisableClickArea(\"DamagedPageUp\",\"damage\")end end end;if#brokenElements>0 then local a6=#brokenElements;if a6>DamagePageSize then a6=DamagePageSize end;if CurrentBrokenPage==math.ceil(#brokenElements/DamagePageSize)then a6=#brokenElements%DamagePageSize+12;if a6>12 then a6=a6-12 end end;a3=a3 ..[[]]a3=a3 ..[[]]if UseMyElementNames==true then a3=a3 ..[[Broken Name]]else a3=a3 ..[[Broken Type]]end;a3=a3 ..[[DMG]]a3=a3 ..[[T]]..ScrapTier..[[ SCRREPTIME]]AddClickArea(\"damage\",{id=\"SwitchScrapTier2\",mode=\"damage\",x1=1570,x2=1690,y1=315,y2=360})local g=0;for u=1+(CurrentBrokenPage-1)*DamagePageSize,a6+(CurrentBrokenPage-1)*DamagePageSize,1 do g=g+1;local a5=brokenElements[u]if UseMyElementNames==true then a3=a3 ..[[]]..string.format(\"%.30s\",a5.name)..[[]]else a3=a3 ..[[]]..string.format(\"%.30s\",a5.type)..[[]]end;a3=a3 ..[[]]..GenerateCommaValue(string.format(\"%.0f\",a5.missinghp),true)..[[]]..[[]]..getScraps(a5.missinghp,true)..[[]]..[[]]..getRepairTime(a5.missinghp,true)..[[]]..[[]]end;if#brokenElements>DamagePageSize then a3=a3 ..[[Page ]]..CurrentBrokenPage..\" of \"..math.ceil(#brokenElements/DamagePageSize)..[[]]if CurrentBrokenPage>1 then a3=a3 ..[[\n \n \n ]]AddClickArea(\"damage\",{id=\"BrokenPageUp\",mode=\"damage\",x1=1665,x2=1865,y1=290+(a6+1)*50,y2=290+50+(a6+1)*50})else DisableClickArea(\"BrokenPageUp\",\"damage\")end;if CurrentBrokenPage\n \n \n ]]AddClickArea(\"damage\",{id=\"BrokenPageDown\",mode=\"damage\",x1=980,x2=1180,y1=290+(a6+1)*50,y2=290+50+(a6+1)*50})else DisableClickArea(\"BrokenPageDown\",\"damage\")end end end;if#damagedElements>0 or#brokenElements>0 then local a7=math.floor(1878/#elementsIdList*#damagedElements)local a8=math.floor(1878/#elementsIdList*#brokenElements)local a9=1878-a7-a8+1;a3=a3 ..[[]]a3=a3 ..[[]]a3=a3 ..[[]]a3=a3 ..[[]]if#damagedElements>0 then a3=a3 ..[[]]..#damagedElements..[[]]end;if#healthyElements>0 then a3=a3 ..[[]]..#healthyElements..[[]]end;if#brokenElements>0 then a3=a3 ..[[]]..#brokenElements..[[]]end;a3=a3 ..[[]]a3=a3 ..[[]]..GenerateCommaValue(string.format(\"%.0f\",totalShipMaxHP-totalShipHP))..[[ HP damage in total ]]..getScraps(totalShipMaxHP-totalShipHP,true)..[[ T]]..ScrapTier..[[ scraps needed. ]]..getRepairTime(totalShipMaxHP-totalShipHP,true)..[[ projected repair time.]]else a3=a3 ..GetElementLogo(812,380,\"ch\",\"ch\",\"ch\")..[[]]..OkayCenterMessage..[[]]..[[]]..#healthyElements..[[ elements stand ]]..GenerateCommaValue(string.format(\"%.0f\",totalShipMaxHP))..[[ HP strong.]]end;forceDamageRedraw=false;return a3 end;function ActionStopengines()ToggleHUD()end;function ActionStrafeRight()if KeyCTRLPressed==true then if HUDShiftU<4000 then HUDShiftU=HUDShiftU+50;SaveToDatabank()RenderScreens()end else HudDeselectElement()end end;function ActionStrafeLeft()if KeyCTRLPressed==true then if HUDShiftU>=50 then HUDShiftU=HUDShiftU-50;SaveToDatabank()RenderScreens()end else ToggleHUD()end end;function ActionDown()if KeyCTRLPressed==true then if HUDShiftV<4000 then HUDShiftV=HUDShiftV+50;SaveToDatabank()RenderScreens()end else ChangeHudSelectedElement(1)end end;function ActionUp()if KeyCTRLPressed==true then if HUDShiftV>=50 then HUDShiftV=HUDShiftV-50;SaveToDatabank()RenderScreens()end else ChangeHudSelectedElement(-1)end end;function ActionOption1()ScrapTier=1;SetRefresh(\"damage\")RenderScreens(\"damage\")end;function ActionOption2()ScrapTier=2;SetRefresh(\"damage\")RenderScreens(\"damage\")end;function ActionOption3()ScrapTier=3;SetRefresh(\"damage\")RenderScreens(\"damage\")end;function ActionOption4()ScrapTier=4;SetRefresh(\"damage\")RenderScreens(\"damage\")end;function ActionOption8()HUDShiftU=0;HUDShiftV=0;SetRefresh(\"damage\")RenderScreens(\"damage\")end;function ActionOption9()SaveToDatabank()SwitchScreens(\"off\")unit.exit()end", + "filter": { + "args": [], + "signature": "start()", + "slotKey": "-1" + }, + "key": "9" + }, + { + "code": "SaveToDatabank()\nSwitchScreens(\"off\")", + "filter": { + "args": [], + "signature": "stop()", + "slotKey": "-1" + }, + "key": "10" + }, + { + "code": "OnTickData()\n", + "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": "--[[\n Damage Report 3.03\n A LUA script for Dual Universe\n\n Created By Dorian Gray\n Ingame: DorianGray\n Discord: Dorian Gray#2623\n\n You can find/update this script on GitHub. Explanations, installation and usage information as well as screenshots can be found there too.\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 Credits & thanks: \n Thanks to NovaQuark for creating the MMO of the century.\n Thanks to Jericho, Dmentia and Archaegeo for learning a lot from their fine scripts.\n Thanks to TheBlacklist for testing and wonderful suggestions.\n SVG patterns by Hero Patterns.\n DU atlas data from Jayle Break.\n \n]]\n\n--[[ 1. USER DEFINED VARIABLES ]]\n\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\nSkillRepairToolEfficiency = 0 --export Enter (0-5) your talent \"Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency\"\nSkillRepairToolOptimization = 0 --export Enter your talent \"Mining and Inventory -> Equipment Manager -> Repair Tool Optimization\"\n\nStatAtmosphericFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED ATMOSPHERIC FUEL TANKS (from the builders talent \"Piloting -> Atmospheric Flight Technician -> Atmospheric Fuel-Tank Handling\")\nStatSpaceFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL SPACE TANKS (from the builders talent \"Piloting -> Atmospheric Engine Technician -> Space Fuel-Tank Handling\")\nStatRocketFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL ROCKET TANKS (from the builders talent \"Piloting -> Rocket Scientist -> Rocket Booster Fuel Tank Handling\")\nStatFuelTankOptimization = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL TANKS \"from the builders talent Mining and Inventory -> Stock Control -> Fuel Tank Optimization\"\n\nShowWelcomeMessage = true --export Do you want the welcome message on the start screen with your name?\nAddSummertimeHour = false --export: Is summertime currently enabled in your location? (Adds one hour.)\n\nUpdateDataInterval=1.0;HighlightBlinkingInterval=0.5;ColorPrimary=\"FF6700\"ColorSecondary=\"FFFFFF\"ColorTertiary=\"000000\"ColorHealthy=\"00FF00\"ColorWarning=\"FFFF00\"ColorCritical=\"FF0000\"ColorBackground=\"000000\"ColorBackgroundPattern=\"4F4F4F\"ColorFuelAtmospheric=\"004444\"ColorFuelSpace=\"444400\"ColorFuelRocket=\"440044\"VERSION=3.03;DebugMode=false;DebugRenderClickareas=true;DBData={}core=nil;db=nil;screens={}dscreens={}Warnings={}screenModes={[\"flight\"]={id=\"flight\"},[\"damage\"]={id=\"damage\"},[\"damageoutline\"]={id=\"damageoutline\"},[\"fuel\"]={id=\"fuel\"},[\"cargo\"]={id=\"cargo\"},[\"agg\"]={id=\"agg\"},[\"map\"]={id=\"map\"},[\"time\"]={id=\"time\",activetoggle=\"true\"},[\"settings1\"]={id=\"settings1\"},[\"startup\"]={id=\"startup\"}}backgroundModes={\"deathstar\",\"capsule\",\"rain\",\"signal\",\"hexagon\",\"diagonal\",\"diamond\",\"plus\",\"dots\"}BackgroundMode=\"deathstar\"BackgroundSelected=1;BackgroundModeOpacity=0.25;SaveVars={\"dscreens\",\"ColorPrimary\",\"ColorSecondary\",\"ColorTertiary\",\"ColorHealthy\",\"ColorWarning\",\"ColorCritical\",\"ColorBackground\",\"ColorBackgroundPattern\",\"ScrapTier\",\"HUDMode\",\"SimulationMode\",\"DMGOStretch\",\"HUDShiftU\",\"HUDShiftV\",\"colorIDIndex\",\"colorIDTable\",\"BackgroundMode\",\"BackgroundSelected\",\"BackgroundModeOpacity\"}HUDMode=false;HUDShiftU=0;HUDShiftV=0;hudSelectedIndex=0;hudStartIndex=1;hudArrowSticker={}highlightOn=false;highlightID=0;highlightX=0;highlightY=0;highlightZ=0;SimulationMode=false;OkayCenterMessage=\"All systems nominal.\"CurrentDamagedPage=1;CurrentBrokenPage=1;DamagePageSize=12;ScrapTier=1;totalScraps=0;ScrapTierRepairTimes={10,50,250,1250}coreWorldOffset=0;totalShipHP=0;formerTotalShipHP=-1;totalShipMaxHP=0;totalShipIntegrity=100;elementsId={}elementsIdList={}damagedElements={}brokenElements={}rE={}healthyElements={}typeElements={}ElementCounter=0;UseMyElementNames=true;dmgoElements={}DMGOMaxElements=250;DMGOStretch=false;ShipXmin=99999999;ShipXmax=-99999999;ShipYmin=99999999;ShipYmax=-99999999;ShipZmin=99999999;ShipZmax=-99999999;totalShipMass=0;formerTotalShipMass=-1;formerTime=-1;FuelAtmosphericTanks={}FuelSpaceTanks={}FuelRocketTanks={}FuelAtmosphericTotal=0;FuelSpaceTotal=0;FuelRocketTotal=0;FuelAtmosphericCurrent=0;FuelSpaceTotalCurrent=0;FuelRocketTotalCurrent=0;formerFuelAtmosphericTotal=-1;formerFuelSpaceTotal=-1;formerFuelRocketTotal=-1;hexTable={\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"}colorIDIndex=1;colorIDTable={[1]={id=\"ColorPrimary\",desc=\"Main HUD Color\",basec=\"FF6700\",newc=\"FF6700\"},[2]={id=\"ColorSecondary\",desc=\"Secondary HUD Color\",basec=\"FFFFFF\",newc=\"FFFFFF\"},[3]={id=\"ColorTertiary\",desc=\"Tertiary HUD Color\",basec=\"000000\",newc=\"000000\"},[4]={id=\"ColorHealthy\",desc=\"Color code for Healthy/Okay\",basec=\"00FF00\",newc=\"00FF00\"},[5]={id=\"ColorWarning\",desc=\"Color code for Damaged/Warning\",basec=\"FFFF00\",newc=\"FFFF00\"},[6]={id=\"ColorCritical\",desc=\"Color code for Broken/Critical\",basec=\"FF0000\",newc=\"FF0000\"},[7]={id=\"ColorBackground\",desc=\"Background Color\",basec=\"000000\",newc=\"000000\"},[8]={id=\"ColorBackgroundPattern\",desc=\"Background Pattern Color\",basec=\"4F4F4F\",newc=\"4F4F4F\"},[9]={id=\"ColorFuelAtmospheric\",desc=\"Color for Atmo Fuel/Elements\",basec=\"004444\",newc=\"004444\"},[10]={id=\"ColorFuelSpace\",desc=\"Color for Space Fuel/Elements\",basec=\"444400\",newc=\"444400\"},[11]={id=\"ColorFuelRocket\",desc=\"Color for Rocket Fuel/Elements\",basec=\"440044\",newc=\"440044\"}}function InitiateSlots()for a,b in pairs(unit)do if type(b)==\"table\"and type(b.export)==\"table\"and b.getElementClass then local c=b.getElementClass():lower()if c:find(\"coreunit\")then core=b;local d=core.getMaxHitPoints()if d>10000 then coreWorldOffset=128 elseif d>1000 then coreWorldOffset=64 elseif d>150 then coreWorldOffset=32 else coreWorldOffset=16 end elseif c=='databankunit'then db=b elseif c==\"screenunit\"then local e=\"startup\"screens[#screens+1]={element=b,id=b.getId(),mode=e,submode=\"\",ClickAreas={},refresh=true,active=false,fuelA=true,fuelS=true,fuelR=true,fuelIndex=1}end end end end;function LoadFromDatabank()if db==nil then return else for f,g in pairs(SaveVars)do if db.hasKey(g)then local h=json.decode(db.getStringValue(g))if h~=nil then if g==\"YourShipsName\"or g==\"AddSummertimeHour\"or g==\"UpdateDataInterval\"or g==\"HighlightBlinkingInterval\"or g==\"SkillRepairToolEfficiency\"or g==\"SkillRepairToolOptimization\"or g==\"SkillAtmosphericFuelEfficiency\"or g==\"SkillSpaceFuelEfficiency\"or g==\"SkillRocketFuelEfficiency\"or g==\"StatAtmosphericFuelTankHandling\"or g==\"StatSpaceFuelTankHandling\"or g==\"StatRocketFuelTankHandling\"then else _G[g]=h end end end end;for i,j in ipairs(screens)do for k,l in ipairs(dscreens)do if screens[i].id==dscreens[k].id then screens[i].mode=dscreens[k].mode;screens[i].submode=dscreens[k].submode;screens[i].active=dscreens[k].active;screens[i].refresh=true;screens[i].fuelA=dscreens[k].fuelA;screens[i].fuelS=dscreens[k].fuelS;screens[i].fuelR=dscreens[k].fuelR;screens[i].fuelIndex=dscreens[k].fuelIndex end end end end end;function SaveToDatabank()if db==nil then return else dscreens={}for i,m in ipairs(screens)do dscreens[i]={}dscreens[i].id=m.id;dscreens[i].mode=m.mode;dscreens[i].submode=m.submode;dscreens[i].active=m.active;dscreens[i].fuelA=m.fuelA;dscreens[i].fuelS=m.fuelS;dscreens[i].fuelR=m.fuelR;dscreens[i].fuelIndex=m.fuelIndex end;db.clear()for f,g in pairs(SaveVars)do db.setStringValue(g,json.encode(_G[g]))end end end;function InitiateScreens()if screens~=nil and#screens>0 then for i=1,#screens,1 do screens[i]=CreateClickAreasForScreen(screens[i])end end end;function UpdateTypeData()FuelAtmosphericTanks={}FuelSpaceTanks={}FuelRocketTanks={}FuelAtmosphericTotal=0;FuelAtmosphericCurrent=0;FuelSpaceTotal=0;FuelSpaceCurrent=0;FuelRocketCurrent=0;FuelRocketTotal=0;local n=4;local o=6;local p=0.8;if StatFuelTankOptimization>0 then n=n-0.09*StatFuelTankOptimization*n;o=o-0.09*StatFuelTankOptimization*o;p=p-0.09*StatFuelTankOptimization*p end;for i,q in ipairs(typeElements)do local r=core.getElementNameById(q)or\"\"local s=core.getElementTypeById(q)or\"\"local t=core.getElementPositionById(q)or 0;local u=core.getElementHitPointsById(q)or 0;local v=core.getElementMaxHitPointsById(q)or 0;local w=core.getElementMassById(q)or 0;local x=\"\"local y=0;local z=0;local A=0;local B=0;if s==\"atmospheric fuel-tank\"then if v>10000 then x=\"L\"z=5480;y=12800 elseif v>1300 then x=\"M\"z=988.67;y=1600 elseif v>150 then x=\"S\"z=182.67;y=400 else x=\"XS\"z=35.03;y=100 end;if StatAtmosphericFuelTankHandling>0 then y=0.2*StatAtmosphericFuelTankHandling*y+y end;A=w-z;if A<=10 then A=0 end;B=string.format(\"%.0f\",A/n)cPercent=string.format(\"%.1f\",math.floor(100/y*tonumber(B)))table.insert(FuelAtmosphericTanks,{type=1,id=q,name=r,maxhp=v,hp=GetHPforElement(q),pos=t,size=x,mass=z,vol=y,cvol=B,percent=cPercent})if u>0 then FuelAtmosphericCurrent=FuelAtmosphericCurrent+B end;FuelAtmosphericTotal=FuelAtmosphericTotal+y elseif s==\"space fuel-tank\"then if v>10000 then x=\"L\"z=5480;y=12800 elseif v>1300 then x=\"M\"z=988.67;y=1600 else x=\"S\"z=182.67;y=400 end;if StatSpaceFuelTankHandling>0 then y=0.2*StatSpaceFuelTankHandling*y+y end;A=w-z;if A<=10 then A=0 end;B=string.format(\"%.0f\",A/o)cPercent=string.format(\"%.1f\",100/y*tonumber(B))table.insert(FuelSpaceTanks,{type=2,id=q,name=r,maxhp=v,hp=GetHPforElement(q),pos=t,size=x,mass=z,vol=y,cvol=B,percent=cPercent})if u>0 then FuelSpaceCurrent=FuelSpaceCurrent+B end;FuelSpaceTotal=FuelSpaceTotal+y elseif s==\"rocket fuel-tank\"then if v>65000 then x=\"L\"z=25740;y=50000 elseif v>6000 then x=\"M\"z=4720;y=6400 elseif v>700 then x=\"S\"z=886.72;y=800 else x=\"XS\"z=173.42;y=400 end;if StatRocketFuelTankHandling>0 then y=0.2*StatRocketFuelTankHandling*y+y end;A=w-z;if A<=10 then A=0 end;B=string.format(\"%.0f\",A/p)cPercent=string.format(\"%.1f\",100/y*tonumber(B))table.insert(FuelRocketTanks,{type=3,id=q,name=r,maxhp=v,hp=GetHPforElement(q),pos=t,size=x,mass=z,vol=y,cvol=B,percent=cPercent})if u>0 then FuelRocketCurrent=FuelRocketCurrent+B end;FuelRocketTotal=FuelRocketTotal+y end end;if FuelAtmosphericCurrent~=formerFuelAtmosphericCurrent then SetRefresh(\"fuel\")formerFuelAtmosphericCurrent=FuelAtmosphericCurrent end;if FuelSpaceCurrent~=formerFuelSpaceCurrent then SetRefresh(\"fuel\")formerFuelSpaceCurrent=FuelSpaceCurrent end;if FuelRocketCurrent~=formerFuelRocketCurrent then SetRefresh(\"fuel\")formerFuelRocketCurrent=FuelRocketCurrent end end;function UpdateDamageData(C)C=C or false;if SimulationActive==true then return end;local formerTotalShipHP=totalShipHP;totalShipHP=0;totalShipMaxHP=0;totalShipIntegrity=100;damagedElements={}brokenElements={}healthyElements={}ElementCounter=0;elementsIdList=core.getElementIdList()for i,q in pairs(elementsIdList)do ElementCounter=ElementCounter+1;local r=core.getElementNameById(q)local s=core.getElementTypeById(q)local t=core.getElementPositionById(q)local u=core.getElementHitPointsById(q)local v=core.getElementMaxHitPointsById(q)if SimulationMode==true then SimulationActive=true;local D=math.random(0,10)if D<2 and#brokenElements<30 then u=0 elseif D>=2 and D<4 and#damagedElements<30 then u=math.random(1,math.ceil(v))else u=v end end;totalShipHP=totalShipHP+u;totalShipMaxHP=totalShipMaxHP+v;if v-u>constants.epsilon then if u>0 then table.insert(damagedElements,{id=q,name=r,type=s,counter=ElementCounter,hp=u,maxhp=v,missinghp=v-u,percent=math.ceil(100/v*u),pos=t})else table.insert(brokenElements,{id=q,name=r,type=s,counter=ElementCounter,hp=u,maxhp=v,missinghp=v-u,percent=0,pos=t})end else table.insert(healthyElements,{id=q,name=r,type=s,counter=ElementCounter,hp=u,maxhp=v,pos=t})if q==highlightID then highlightID=0;highlightOn=false;HideHighlight()hudSelectedIndex=0 end end;if C==true then if s==\"atmospheric fuel-tank\"or s==\"space fuel-tank\"or s==\"rocket fuel-tank\"then table.insert(typeElements,q)end end end;SortDamageTables()rE={}if#brokenElements>0 then for f,j in ipairs(brokenElements)do table.insert(rE,{id=j.id,missinghp=j.missinghp,hp=j.hp,name=j.name,type=j.type,pos=j.pos})end end;if#damagedElements>0 then for f,j in ipairs(damagedElements)do table.insert(rE,{id=j.id,missinghp=j.missinghp,hp=j.hp,name=j.name,type=j.type,pos=j.pos})end end;if#rE>0 then table.sort(rE,function(E,F)return E.missinghp>F.missinghp end)end;totalShipIntegrity=string.format(\"%2.0f\",100/totalShipMaxHP*totalShipHP)if formerTotalShipHP~=totalShipHP then forceDamageRedraw=true;formerTotalShipHP=totalShipHP else forceDamageRedraw=false end end;function GetHPforElement(q)for i,j in ipairs(brokenElements)do if j.id==q then return 0 end end;for i,j in ipairs(damagedElements)do if j.id==q then return j.hp end end;for i,j in ipairs(healthyElements)do if j.id==q then return j.maxhp end end end;function UpdateClickArea(G,H,I)for i,m in ipairs(screens)do for J,j in pairs(screens[i].ClickAreas)do if j.id==G and j.mode==I then screens[i].ClickAreas[J]=H end end end end;function AddClickArea(I,H)for i,m in ipairs(screens)do if screens[i].mode==I then table.insert(screens[i].ClickAreas,H)end end end;function AddClickAreaForScreenID(K,H)for i,m in ipairs(screens)do if screens[i].id==K then table.insert(screens[i].ClickAreas,H)end end end;function DisableClickArea(G,I)UpdateClickArea(G,{id=G,mode=I,x1=-1,x2=-1,y1=-1,y2=-1})end;function SetRefresh(I,L)I=I or\"all\"L=L or\"all\"if screens~=nil and#screens>0 then for i=1,#screens,1 do if screens[i].mode==I or I==\"all\"then if screens[i].submode==L or L==\"all\"then screens[i].refresh=true end end end end end;function WipeClickAreasForScreen(m)m.ClickAreas={}return m end;function CreateBaseClickAreas(m)table.insert(m.ClickAreas,{mode=\"all\",id=\"ToggleHudMode\",x1=1537,x2=1728,y1=1015,y2=1075})table.insert(m.ClickAreas,{mode=\"all\",id=\"ButtonPress\",param=\"damage\",x1=193,x2=384,y1=1015,y2=1075})table.insert(m.ClickAreas,{mode=\"all\",id=\"ButtonPress\",param=\"damageoutline\",x1=385,x2=576,y1=1015,y2=1075})table.insert(m.ClickAreas,{mode=\"all\",id=\"ButtonPress\",param=\"fuel\",x1=577,x2=768,y1=1015,y2=1075})table.insert(m.ClickAreas,{mode=\"all\",id=\"ButtonPress\",param=\"time\",x1=0,x2=192,y1=1015,y2=1075})table.insert(m.ClickAreas,{mode=\"all\",id=\"ButtonPress\",param=\"settings1\",x1=1729,x2=1920,y1=1015,y2=1075})return m end;function CreateClickAreasForScreen(m)if m==nil then return{}end;if m.mode==\"flight\"then elseif m.mode==\"damage\"then table.insert(m.ClickAreas,{mode=\"damage\",id=\"ToggleElementLabel\",x1=70,x2=425,y1=325,y2=355})table.insert(m.ClickAreas,{mode=\"damage\",id=\"ToggleElementLabel2\",x1=980,x2=1400,y1=325,y2=355})elseif m.mode==\"damageoutline\"then table.insert(m.ClickAreas,{mode=\"damageoutline\",id=\"DMGOChangeView\",param=\"top\",x1=60,x2=439,y1=150,y2=200})table.insert(m.ClickAreas,{mode=\"damageoutline\",id=\"DMGOChangeView\",param=\"side\",x1=440,x2=824,y1=150,y2=200})table.insert(m.ClickAreas,{mode=\"damageoutline\",id=\"DMGOChangeView\",param=\"front\",x1=825,x2=1215,y1=150,y2=200})table.insert(m.ClickAreas,{mode=\"damageoutline\",id=\"DMGOChangeStretch\",x1=1530,x2=1580,y1=150,y2=200})elseif m.mode==\"fuel\"then elseif m.mode==\"cargo\"then elseif m.mode==\"agg\"then elseif m.mode==\"map\"then elseif m.mode==\"time\"then elseif m.mode==\"settings1\"then table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ToggleBackground\",x1=75,x2=860,y1=170,y2=215})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"PreviousBackground\",x1=75,x2=460,y1=235,y2=285})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"NextBackground\",x1=480,x2=860,y1=235,y2=285})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"DecreaseOpacity\",x1=75,x2=460,y1=300,y2=350})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"IncreaseOpacity\",x1=480,x2=860,y1=300,y2=350})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ResetColors\",x1=75,x2=860,y1=370,y2=415})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"PreviousColorID\",x1=90,x2=140,y1=500,y2=550})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"NextColorID\",x1=795,x2=845,y1=500,y2=550})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"1\",x1=210,x2=290,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"2\",x1=300,x2=380,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"3\",x1=385,x2=465,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"4\",x1=470,x2=550,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"5\",x1=560,x2=640,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosUp\",param=\"6\",x1=645,x2=725,y1=655,y2=700})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"1\",x1=210,x2=290,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"2\",x1=300,x2=380,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"3\",x1=385,x2=465,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"4\",x1=470,x2=550,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"5\",x1=560,x2=640,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ColorPosDown\",param=\"6\",x1=645,x2=725,y1=740,y2=780})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ResetPosColor\",x1=160,x2=340,y1=885,y2=935})table.insert(m.ClickAreas,{mode=\"settings1\",id=\"ApplyPosColor\",x1=355,x2=780,y1=885,y2=935})elseif m.mode==\"startup\"then end;m=CreateBaseClickAreas(m)return m end;function CheckClick(M,N,O)M=M*1920;N=N*1120;O=O or\"\"HitPayload={}if screens~=nil and#screens>0 then for i=1,#screens,1 do if screens[i].active==true and screens[i].element.getMouseX()~=-1 and screens[i].element.getMouseY()~=-1 then if O==\"\"then for J,j in pairs(screens[i].ClickAreas)do if j~=nil and M>=j.x1 and M<=j.x2 and N>=j.y1 and N<=j.y2 then O=j.id;HitPayload=j;break end end end;if O==\"ButtonPress\"then if screens[i].mode==HitPayload.param then screens[i].mode=\"startup\"else screens[i].mode=HitPayload.param end;if screens[i].mode==\"damageoutline\"then if screens[i].submode==\"\"then screens[i].submode=\"top\"end end;screens[i].refresh=true;screens[i].ClickAreas={}SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"ToggleBackground\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if BackgroundMode==\"\"then BackgroundSelected=1;BackgroundMode=backgroundModes[BackgroundSelected]else BackgroundSelected=1;BackgroundMode=\"\"end;for J,m in pairs(screens)do screens[J].refresh=true end;SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"PreviousBackground\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if BackgroundMode==\"\"then BackgroundSelected=1;BackgroundMode=backgroundModes[BackgroundSelected]else if BackgroundSelected<=1 then BackgroundSelected=#backgroundModes else BackgroundSelected=BackgroundSelected-1 end;BackgroundMode=backgroundModes[BackgroundSelected]end;for J,m in pairs(screens)do screens[J].refresh=true end;SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"NextBackground\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if BackgroundMode==\"\"then BackgroundSelected=1;BackgroundMode=backgroundModes[BackgroundSelected]else if BackgroundSelected>=#backgroundModes then BackgroundSelected=1 else BackgroundSelected=BackgroundSelected+1 end;BackgroundMode=backgroundModes[BackgroundSelected]end;for J,m in pairs(screens)do screens[J].refresh=true end;SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"DecreaseOpacity\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if BackgroundModeOpacity>0.1 then BackgroundModeOpacity=BackgroundModeOpacity-0.05;for J,m in pairs(screens)do screens[J].refresh=true end;SaveToDatabank()SetRefresh()RenderScreens()end elseif O==\"IncreaseOpacity\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if BackgroundModeOpacity<1.0 then BackgroundModeOpacity=BackgroundModeOpacity+0.05;for J,m in pairs(screens)do screens[J].refresh=true end;SaveToDatabank()SetRefresh()RenderScreens()end elseif O==\"ResetColors\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then db.clear()ColorPrimary=\"FF6700\"ColorSecondary=\"FFFFFF\"ColorTertiary=\"000000\"ColorHealthy=\"00FF00\"ColorWarning=\"FFFF00\"ColorCritical=\"FF0000\"ColorBackground=\"000000\"ColorBackgroundPattern=\"4f4f4f\"BackgroundMode=\"deathstar\"BackgroundSelected=1;BackgroundModeOpacity=0.25;colorIDTable={[1]={id=\"ColorPrimary\",desc=\"Main HUD Color\",basec=\"FF6700\",newc=\"FF6700\"},[2]={id=\"ColorSecondary\",desc=\"Secondary HUD Color\",basec=\"FFFFFF\",newc=\"FFFFFF\"},[3]={id=\"ColorTertiary\",desc=\"Tertiary HUD Color\",basec=\"000000\",newc=\"000000\"},[4]={id=\"ColorHealthy\",desc=\"Color code for Healthy/Okay\",basec=\"00FF00\",newc=\"00FF00\"},[5]={id=\"ColorWarning\",desc=\"Color code for Damaged/Warning\",basec=\"FFFF00\",newc=\"FFFF00\"},[6]={id=\"ColorCritical\",desc=\"Color code for Broken/Critical\",basec=\"FF0000\",newc=\"FF0000\"},[7]={id=\"ColorBackground\",desc=\"Background Color\",basec=\"000000\",newc=\"000000\"},[8]={id=\"ColorBackgroundPattern\",desc=\"Background Pattern Color\",basec=\"4F4F4F\",newc=\"4F4F4F\"},[9]={id=\"ColorFuelAtmospheric\",desc=\"Color for Atmo Fuel/Elements\",basec=\"004444\",newc=\"004444\"},[10]={id=\"ColorFuelSpace\",desc=\"Color for Space Fuel/Elements\",basec=\"444400\",newc=\"444400\"},[11]={id=\"ColorFuelRocket\",desc=\"Color for Rocket Fuel/Elements\",basec=\"440044\",newc=\"440044\"}}SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"PreviousColorID\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then colorIDIndex=colorIDIndex-1;if colorIDIndex<1 then colorIDIndex=#colorIDTable end;SaveToDatabank()SetRefresh(\"settings1\")RenderScreens(\"settings1\")elseif O==\"NextColorID\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then colorIDIndex=colorIDIndex+1;if colorIDIndex>#colorIDTable then colorIDIndex=1 end;SaveToDatabank()SetRefresh(\"settings1\")RenderScreens(\"settings1\")elseif O==\"ColorPosUp\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then local P=tonumber(string.sub(colorIDTable[colorIDIndex].newc,HitPayload.param,HitPayload.param),16)P=P+1;if P>15 then P=0 end;colorIDTable[colorIDIndex].newc=replace_char(HitPayload.param,colorIDTable[colorIDIndex].newc,hexTable[P+1])SaveToDatabank()SetRefresh(\"settings1\")RenderScreens(\"settings1\")elseif O==\"ColorPosDown\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then local P=tonumber(string.sub(colorIDTable[colorIDIndex].newc,HitPayload.param,HitPayload.param),16)P=P-1;if P<0 then P=15 end;colorIDTable[colorIDIndex].newc=replace_char(HitPayload.param,colorIDTable[colorIDIndex].newc,hexTable[P+1])SaveToDatabank()SetRefresh(\"settings1\")RenderScreens(\"settings1\")elseif O==\"ResetPosColor\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then colorIDTable[colorIDIndex].newc=colorIDTable[colorIDIndex].basec;_G[colorIDTable[colorIDIndex].id]=colorIDTable[colorIDIndex].basec;SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"ApplyPosColor\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then _G[colorIDTable[colorIDIndex].id]=colorIDTable[colorIDIndex].newc;SaveToDatabank()SetRefresh()RenderScreens()elseif O==\"DamagedPageDown\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then CurrentDamagedPage=CurrentDamagedPage+1;if CurrentDamagedPage>math.ceil(#damagedElements/DamagePageSize)then CurrentDamagedPage=math.ceil(#damagedElements/DamagePageSize)end;HudDeselectElement()SaveToDatabank()SetRefresh(\"damage\")RenderScreens(\"damage\")elseif O==\"DamagedPageUp\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then CurrentDamagedPage=CurrentDamagedPage-1;if CurrentDamagedPage<1 then CurrentDamagedPage=1 end;HudDeselectElement()SaveToDatabank()SetRefresh(\"damage\")RenderScreens(\"damage\")elseif O==\"BrokenPageDown\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then CurrentBrokenPage=CurrentBrokenPage+1;if CurrentBrokenPage>math.ceil(#brokenElements/DamagePageSize)then CurrentBrokenPage=math.ceil(#brokenElements/DamagePageSize)end;HudDeselectElement()SaveToDatabank()SetRefresh(\"damage\")RenderScreens(\"damage\")elseif O==\"BrokenPageUp\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then CurrentBrokenPage=CurrentBrokenPage-1;if CurrentBrokenPage<1 then CurrentBrokenPage=1 end;HudDeselectElement()SaveToDatabank()SetRefresh(\"damage\")RenderScreens(\"damage\")elseif O==\"DMGOChangeView\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then screens[i].submode=HitPayload.param;UpdateViewDamageoutline(screens[i])SaveToDatabank()SetRefresh(\"damageoutline\",screens[i].submode)RenderScreens(\"damageoutline\",screens[i].submode)elseif O==\"DMGOChangeStretch\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if DMGOStretch==true then DMGOStretch=false else DMGOStretch=true end;UpdateViewDamageoutline(screens[i])SaveToDatabank()SetRefresh(\"damageoutline\")RenderScreens(\"damageoutline\")elseif O==\"ToggleDisplayAtmosphere\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if screens[i].fuelA==true then screens[i].fuelA=false else screens[i].fuelA=true end;screens[i].fuelIndex=1;SaveToDatabank()SetRefresh(\"fuel\")RenderScreens(\"fuel\")elseif O==\"ToggleDisplaySpace\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if screens[i].fuelS==true then screens[i].fuelS=false else screens[i].fuelS=true end;screens[i].fuelIndex=1;SaveToDatabank()SetRefresh(\"fuel\")RenderScreens(\"fuel\")elseif O==\"ToggleDisplayRocket\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if screens[i].fuelR==true then screens[i].fuelR=false else screens[i].fuelR=true end;screens[i].fuelIndex=1;SaveToDatabank()SetRefresh(\"fuel\")RenderScreens(\"fuel\")elseif O==\"DecreaseFuelIndex\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then screens[i].fuelIndex=screens[i].fuelIndex-1;if screens[i].fuelIndex<1 then screens[i].fuelIndex=1 end;SaveToDatabank()SetRefresh(\"fuel\")RenderScreens(\"fuel\")elseif O==\"IncreaseFuelIndex\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then screens[i].fuelIndex=screens[i].fuelIndex+1;SaveToDatabank()SetRefresh(\"fuel\")RenderScreens(\"fuel\")elseif O==\"ToggleHudMode\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if HUDMode==true then HUDMode=false;forceDamageRedraw=true;HudDeselectElement()SaveToDatabank()SetRefresh()RenderScreens()else HUDMode=true;forceDamageRedraw=true;HudDeselectElement()SaveToDatabank()SetRefresh()RenderScreens()end elseif O==\"ToggleSimulation\"and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then CurrentDamagedPage=1;CurrentBrokenPage=1;if SimulationMode==true then SimulationMode=false;SimulationActive=false;UpdateDamageData()UpdateTypeData()forceDamageRedraw=true;HudDeselectElement()SetRefresh(\"damage\")SetRefresh(\"damageoutline\")SetRefresh(\"settings1\")SetRefresh(\"fuel\")SaveToDatabank()RenderScreens()else SimulationMode=true;SimulationActive=false;UpdateDamageData()UpdateTypeData()forceDamageRedraw=true;HudDeselectElement()SetRefresh(\"damage\")SetRefresh(\"damageoutline\")SetRefresh(\"settings1\")SetRefresh(\"fuel\")SaveToDatabank()RenderScreens()end elseif(O==\"ToggleElementLabel\"or O==\"ToggleElementLabel2\")and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then if UseMyElementNames==true then UseMyElementNames=false;SetRefresh(\"damage\")RenderScreens(\"damage\")else UseMyElementNames=true;SetRefresh(\"damage\")RenderScreens(\"damage\")end elseif(O==\"SwitchScrapTier\"or O==\"SwitchScrapTier2\")and(HitPayload.mode==screens[i].mode or HitPayload.mode==\"all\")then ScrapTier=ScrapTier+1;if ScrapTier>4 then ScrapTier=1 end;SetRefresh(\"damage\")RenderScreens(\"damage\")end end end end end;function GetContentFlight()local Q=\"\"Q=Q..GetHeader(\"Flight Data Report\")..[[\n \n ]]return Q end;function GetContentDamage()local Q=\"\"if SimulationMode==true then Q=Q..GetHeader(\"Damage Report (Simulated damage)\")..[[]]else Q=Q..GetHeader(\"Damage Report\")..[[]]end;Q=Q..GetContentDamageScreen()return Q end;function GetContentDamageoutline(m)UpdateDataDamageoutline()UpdateViewDamageoutline(m)local Q=\"\"Q=Q..GetHeader(\"Damage Ship Outline Report\")..GetDamageoutlineShip()..[[]]if m.submode==\"top\"then Q=Q..[[\n \n Top View\n \n Side View\n \n Front View\n ]]elseif m.submode==\"side\"then Q=Q..[[\n \n Top View\n \n Side View\n \n Front View\n ]]elseif m.submode==\"front\"then Q=Q..[[\n \n Top View\n \n Side View\n \n Front View\n ]]else end;Q=Q..[[]]..#dmgoElements..[[ of ]]..ElementCounter..[[ shown]]Q=Q..[[]]if DMGOStretch==true then Q=Q..[[]]end;Q=Q..[[Stretch both axis]]return Q end;function GetContentFuel(m)if#FuelAtmosphericTanks<1 and#FuelSpaceTanks<1 and#FuelRocketTanks<1 then return\"\"end;local R=0;local Q=\"\"local S={}FuelDisplay={m.fuelA,m.fuelS,m.fuelR}if FuelDisplay[1]==true and#FuelAtmosphericTanks>0 then table.insert(S,\"Atmospheric\")R=R+1 end;if FuelDisplay[2]==true and#FuelSpaceTanks>0 then table.insert(S,\"Space\")R=R+1 end;if FuelDisplay[3]==true and#FuelRocketTanks>0 then table.insert(S,\"Rocket\")R=R+1 end;Q=Q..GetHeader(\"Fuel Report (\"..table.concat(S,\", \")..\")\")..[[\n ]]local T=150;local U=0;local V=0;if FuelDisplay[1]==true and#FuelAtmosphericTanks>0 then if R==1 then V=50 elseif R==2 then V=6 elseif R==3 then V=0 end;Q=Q..[[\n \n \n \n ]]Q=Q..[[]]..GenerateCommaValue(FuelAtmosphericCurrent,true)..[[ of ]]..GenerateCommaValue(FuelAtmosphericTotal,true)..[[ | Total Atmospheric Fuel in ]]..#FuelAtmosphericTanks..[[ tank]]..(#FuelAtmosphericTanks==1 and\"\"or\"s\")..[[ (]]..math.floor(100/FuelAtmosphericTotal*FuelAtmosphericCurrent)..[[%)]]U=U+1 end;if FuelDisplay[2]==true and#FuelSpaceTanks>0 then if R==1 then V=50 elseif R==2 then V=6 elseif R==3 then V=0 end;Q=Q..[[\n \n \n \n ]]Q=Q..[[]]..GenerateCommaValue(FuelSpaceCurrent,true)..[[ of ]]..GenerateCommaValue(FuelSpaceTotal,true)..[[ | Total Space Fuel in ]]..#FuelSpaceTanks..[[ tank]]..(#FuelSpaceTanks==1 and\"\"or\"s\")..[[ (]]..math.floor(100/FuelSpaceTotal*FuelSpaceCurrent)..[[%)]]U=U+1 end;if FuelDisplay[3]==true and#FuelRocketTanks>0 then if R==1 then V=50 elseif R==2 then V=6 elseif R==3 then V=0 end;Q=Q..[[\n \n \n \n ]]Q=Q..[[]]..GenerateCommaValue(FuelRocketCurrent,true)..[[ of ]]..GenerateCommaValue(FuelRocketTotal,true)..[[ | Total Rocket Fuel in ]]..#FuelRocketTanks..[[ tank]]..(#FuelRocketTanks==1 and\"\"or\"s\")..[[ (]]..math.floor(100/FuelRocketTotal*FuelRocketCurrent)..[[%)]]end;Q=Q..[[\n \n \n \n ]]local W={}if m.fuelIndex==nil or m.fuelIndex<1 then m.fuelIndex=1 end;if FuelDisplay[1]==true then for f,j in ipairs(FuelAtmosphericTanks)do table.insert(W,j)end end;if FuelDisplay[2]==true then for f,j in ipairs(FuelSpaceTanks)do table.insert(W,j)end end;if FuelDisplay[3]==true then for f,j in ipairs(FuelRocketTanks)do table.insert(W,j)end end;table.sort(W,function(E,F)return E.type\n \n \n ]]if Y.hp==0 then Q=Q..[[]]elseif Y.maxhp-Y.hp>constants.epsilon then Q=Q..[[]]else Q=Q..[[]]end;if Y.hp==0 then Q=Q..[[]]..Y.size..[[]]else Q=Q..[[]]..Y.size..[[]]end;if Y.hp==0 then Q=Q..[[Broken]]..[[0 of ]]..GenerateCommaValue(Y.vol)..[[]]elseif tonumber(Y.percent)<10 then Q=Q..[[]]..Y.percent..[[%]]..[[]]..GenerateCommaValue(Y.cvol)..[[ of ]]..GenerateCommaValue(Y.vol)..[[]]elseif tonumber(Y.percent)<30 then Q=Q..[[]]..Y.percent..[[%]]..[[]]..GenerateCommaValue(Y.cvol)..[[ of ]]..GenerateCommaValue(Y.vol)..[[]]else Q=Q..[[]]..Y.percent..[[%]]..[[]]..GenerateCommaValue(Y.cvol)..[[ of ]]..GenerateCommaValue(Y.vol)..[[]]end;Q=Q..[[]]..Y.name..[[]]Q=Q..[[]]end end;if#FuelAtmosphericTanks>0 then Q=Q..[[]]if FuelDisplay[1]==true then Q=Q..[[]]end;Q=Q..[[ATM]]AddClickAreaForScreenID(m.id,{mode=\"fuel\",id=\"ToggleDisplayAtmosphere\",x1=50,x2=100,y1=270,y2=320})end;if#FuelSpaceTanks>0 then Q=Q..[[]]if FuelDisplay[2]==true then Q=Q..[[]]end;Q=Q..[[SPC]]AddClickAreaForScreenID(m.id,{mode=\"fuel\",id=\"ToggleDisplaySpace\",x1=200,x2=250,y1=270,y2=320})end;if#FuelRocketTanks>0 then Q=Q..[[]]if FuelDisplay[3]==true then Q=Q..[[]]end;Q=Q..[[RKT]]AddClickAreaForScreenID(m.id,{mode=\"fuel\",id=\"ToggleDisplayRocket\",x1=350,x2=400,y1=270,y2=320})end;if m.fuelIndex>1 then Q=Q..[[\n \n \n ]]AddClickAreaForScreenID(m.id,{mode=\"fuel\",id=\"DecreaseFuelIndex\",x1=1470,x2=1670,y1=270,y2=320})end;if m.fuelIndex+X-1<#W then Q=Q..[[\n \n \n ]]AddClickAreaForScreenID(m.id,{mode=\"fuel\",id=\"IncreaseFuelIndex\",x1=1680,x2=1880,y1=270,y2=320})end;if X>0 then Q=Q..[[]]..#W..[[ Tank]]..(#W==1 and\"\"or\"s\")..[[ (Showing ]]..m.fuelIndex..[[ to ]]..m.fuelIndex+X-1 ..[[)]]end;return Q end;function GetContentCargo()local Q=\"\"Q=Q..GetHeader(\"Cargo Report\")..[[\n \n ]]return Q end;function GetContentAGG()local Q=\"\"Q=Q..GetHeader(\"Anti-Grav Control\")..[[\n \n ]]return Q end;function GetContentMap()local Q=\"\"Q=Q..GetHeader(\"Map Overview\")..[[\n \n ]]return Q end;function GetContentTime()local Q=\"\"Q=Q..GetHeader(\"Time\")..epochTime()Q=Q..[[\n \n \n \n \n \n \n \n \n \n \n \n \n ]]return Q end;function GetContentSettings1()local Q=\"\"Q=Q..GetHeader(\"Settings\")..[[]]if BackgroundMode==\"\"then Q=Q..[[Activate background]]else Q=Q..[[Deactivate background (']]..BackgroundMode..[[', ]]..string.format(\"%.0f\",BackgroundModeOpacity*100)..[[%)]]end;Q=Q..[[\n \n Previous background\n \n Next background\n\n \n Decrease Opacity\n \n Increase Opacity\n ]]Q=Q..[[]]..[[Reset background and all colors]]Q=Q..[[]]..[[]]..[[]]..[[Select and change any of the ]]..#colorIDTable..[[ HUD colors]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..colorIDTable[colorIDIndex].desc..[[]]..[[]]..[[Current color]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[#]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,1,1)..[[]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,2,2)..[[]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,3,3)..[[]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,4,4)..[[]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,5,5)..[[]]..[[]]..[[]]..string.sub(colorIDTable[colorIDIndex].newc,6,6)..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[]]..[[New color]]..[[]]..[[Apply new color]]..[[]]..[[Reset]]..[[]]Q=Q..[[]]..[[]]..[[]]..[[Explanation / Hints]]..[[Coming soon.]]Q=Q..[[]]if SimulationMode==true then Q=Q..[[Simulating Damage to elements]]AddClickArea(\"settings1\",{id=\"ToggleSimulation\",mode=\"settings1\",x1=940,x2=1850,y1=919,y2=969})else Q=Q..[[Simulate Damage to elements]]AddClickArea(\"settings1\",{id=\"ToggleSimulation\",mode=\"settings1\",x1=940,x2=1850,y1=919,y2=969})end;return Q end;function GetContentStartup()local Q=\"\"Q=Q..GetElementLogo(812,380,\"f\",\"f\",\"f\")if YourShipsName==\"Enter here\"then Q=Q..[[Spaceship ID ]]..ShipID..[[]]else Q=Q..[[]]..YourShipsName..[[]]end;if ShowWelcomeMessage==true then Q=Q..[[Greetings, Commander ]]..PlayerName..[[.]]end;if#Warnings>0 then Q=Q..[[Warning: ]]..table.concat(Warnings,\" \")..[[]]end;Q=Q..[[Damage Report v]]..VERSION..[[, by Scion Interstellar, DorianGray - Discord: Dorian Gray#2623. Under GNU Public License 3.0.]]return Q end;function RenderScreen(m,a0)if a0==nil then PrintConsole(\"ERROR: contentToRender is nil.\")unit.exit()end;CreateClickAreasForScreen(m)local Q=\"\"Q=Q..[[\n \n \n ]]Q=Q..a0;if m.mode==\"startup\"then Q=Q..[[]]else Q=Q..[[]]end;Q=Q..[[\n \n \n \n TIME\n DMG\n DMGO\n FUEL]]Q=Q..[[\n HUD\n SETS\n \n \n \n ]]..[[\n ]]if HUDMode==true then Q=Q..[[\n \n HUD\n ]]end;if m.mode==\"damage\"then Q=Q..[[\n \n DMG\n ]]elseif m.mode==\"damageoutline\"then Q=Q..[[\n \n DMGO\n ]]elseif m.mode==\"fuel\"then Q=Q..[[\n \n FUEL\n ]]elseif m.mode==\"flight\"then Q=Q..[[\n \n FLGT\n ]]elseif m.mode==\"cargo\"then Q=Q..[[\n \n CRGO\n ]]elseif m.mode==\"agg\"then Q=Q..[[\n \n AGG\n ]]elseif m.mode==\"map\"then Q=Q..[[\n \n MAP\n ]]elseif m.mode==\"time\"then Q=Q..[[\n \n TIME\n ]]elseif m.mode==\"settings1\"then Q=Q..[[\n \n SETS\n ]]end;Q=Q..[[]]Q=Q..[[]]local a1=string.len(Q)m.element.setSVG(Q)end;function RenderScreens(a2,a3)a2=a2 or\"all\"a3=a3 or\"all\"if screens~=nil and#screens>0 then local a4=\"\"local a5=\"\"local a6=\"\"local a7=\"\"local a8=\"\"local a9=\"\"local aa=\"\"local ab=\"\"local ac=\"\"local ad=\"\"local ae=\"\"local af=\"\"for J,m in pairs(screens)do if m.refresh==true then local a0=\"\"if m.mode==\"flight\"and(a2==\"flight\"or a2==\"all\")then if a4==\"\"then a4=GetContentFlight()end;a0=a4 elseif m.mode==\"damage\"and(a2==\"damage\"or a2==\"all\")then if a5==\"\"then a5=GetContentDamage()end;a0=a5 elseif m.mode==\"damageoutline\"and(a2==\"damageoutline\"or a2==\"all\")then if m.submode==\"\"then m.submode=\"top\"screens[J].submode=\"top\"end;if m.submode==\"top\"and(a3==\"top\"or a3==\"all\")then if a6==\"\"then a6=GetContentDamageoutline(m)end;a0=a6 end;if m.submode==\"side\"and(a3==\"side\"or a3==\"all\")then if a7==\"\"then a7=GetContentDamageoutline(m)end;a0=a7 end;if m.submode==\"front\"and(a3==\"front\"or a3==\"all\")then if a8==\"\"then a8=GetContentDamageoutline(m)end;a0=a8 end elseif m.mode==\"fuel\"and(a2==\"fuel\"or a2==\"all\")then m=WipeClickAreasForScreen(screens[J])a0=GetContentFuel(m)elseif m.mode==\"cargo\"and(a2==\"cargo\"or a2==\"all\")then if aa==\"\"then aa=GetContentCargo()end;a0=aa elseif m.mode==\"agg\"and(a2==\"agg\"or a2==\"all\")then if ab==\"\"then ab=GetContentAGG()end;a0=ab elseif m.mode==\"map\"and(a2==\"map\"or a2==\"all\")then if ac==\"\"then ac=GetContentMap()end;a0=ac elseif m.mode==\"time\"and(a2==\"time\"or a2==\"all\")then if ad==\"\"then ad=GetContentTime()end;a0=ad elseif m.mode==\"settings1\"and(a2==\"settings1\"or a2==\"all\")then if ae==\"\"then ae=GetContentSettings1()end;a0=ae elseif m.mode==\"startup\"and(a2==\"startup\"or a2==\"all\")then if af==\"\"then af=GetContentStartup()end;a0=af else a0=\"Invalid screen mode. ('\"..m.mode..\"')\"end;if a0~=\"\"then RenderScreen(m,a0)else DrawCenteredText(\"ERROR: No contentToRender delivered for \"..m.mode)PrintConsole(\"ERROR: No contentToRender delivered for \"..m.mode)unit.exit()end;screens[J].refresh=false end end end;if HUDMode==true then system.setScreen(GetContentDamageHUDOutput())system.showScreen(1)else system.showScreen(0)end end;function OnTickData(C)if formerTime+605 or SkillRepairToolOptimization>5 or StatFuelTankOptimization>5 or StatAtmosphericFuelTankHandling>5 or StatSpaceFuelTankHandling>5 or StatRocketFuelTankHandling>5 then PrintConsole(\"ERROR: Talents/stats can only range from 0 to 5. Please set correctly in LUA settings and reactivate script.\")unit.exit()end;if screens==nil or#screens==0 then HUDMode=true;PrintConsole(\"Warning: No screens connected. Entering HUD mode only.\")end;OnTickData(true)unit.setTimer('UpdateData',UpdateDataInterval)unit.setTimer('UpdateHighlight',HighlightBlinkingInterval)", + "filter": { + "args": [], + "signature": "start()", + "slotKey": "-1" + }, + "key": "13" + }, + { + "code": "ActionUp()", + "filter": { + "args": [ + { + "value": "up" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "14" + }, + { + "code": "ActionDown()", + "filter": { + "args": [ + { + "value": "down" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "15" + }, + { + "code": "ActionStrafeLeft()", + "filter": { + "args": [ + { + "value": "strafeleft" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "16" + }, + { + "code": "ActionStrafeRight()", + "filter": { + "args": [ + { + "value": "straferight" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "17" + }, + { + "code": "KeyCTRLPressed = true", + "filter": { + "args": [ + { + "value": "brake" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "18" + }, + { + "code": "KeyCTRLPressed = false", + "filter": { + "args": [ + { + "value": "brake" + } + ], + "signature": "actionStop(action)", + "slotKey": "-2" + }, + "key": "19" + }, + { + "code": "ActionOption1()", + "filter": { + "args": [ + { + "value": "option1" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "20" + }, + { + "code": "ActionOption2()", + "filter": { + "args": [ + { + "value": "option2" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "21" + }, + { + "code": "ActionOption3()", + "filter": { + "args": [ + { + "value": "option3" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "22" + }, + { + "code": "ActionOption4()", + "filter": { + "args": [ + { + "value": "option4" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "23" + }, + { + "code": "ActionOption9()", + "filter": { + "args": [ + { + "value": "option9" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "24" + }, + { + "code": "ActionOption8()", + "filter": { + "args": [ + { + "value": "option8" + } + ], + "signature": "actionStart(action)", + "slotKey": "-2" + }, + "key": "25" + } + ], + "methods": [], + "events": [] +} \ No newline at end of file diff --git a/README.md b/README.md index efa9a71..230c301 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 v3.02 (DU-DamageReport) +# Damage Report v3.03 (DU-DamageReport) ### A multi-screen (and HUD) capable, touch enabled, easy to install ship damage reporting script for **Dual Universe**. @@ -25,10 +25,12 @@ Very soon we will be linking a YouTube video here explaning the installation and ![5](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/5.png) ![6](https://github.com/DorianTheGrey/DU-DamageReport/blob/main/img/6.png) -### Important Note +### Important Notes This script is comparably intense in regards to DU CPU resources required. Using many screens, using it on a ship with many (1000+) elements, clicking rapidly on the settings page, and/or having many damaged elements will most likely cause a script shutdown due to the limited CPU time we get. Using less screens and clicking a tiny bit slower during color selection will help. For now, I am not limiting the number of screens you can use (up to 8), but you will see that 1-3 screens works a lot smoother than more. - Finally, all scripts you run in parallel share one CPU limit, so I advise to switch this script off while you are using e.g. a heavy flight hud script. You have been warned. :) +The "Fuel Tank Optimization" talent in "Stock Control" is currently not doing what it says. It should reduce the weight of your fuel by 5 percent, but it's more like 9.1-something percent. As we do not know the exact number, we put 9 percent into the formula. Your tanks will seem a tiny bit emptier than they actually are, this will be fixed as soon as I know the exact data. + Having said all of this, I successfully used the script on a 1100 element L core ship (on one screen) without problems. ### Installation diff --git a/src/DamageReport_3_02_UnitStart_2.lua b/src/DamageReport_3_02_UnitStart_2.lua index 38ae7d7..0200de8 100644 --- a/src/DamageReport_3_02_UnitStart_2.lua +++ b/src/DamageReport_3_02_UnitStart_2.lua @@ -359,6 +359,12 @@ function UpdateTypeData() local weightSpaceFuel = 6 local weightRocketFuel = 0.8 + if StatFuelTankOptimization > 0 then + weightAtmosphericFuel = weightAtmosphericFuel - 0.09 * StatFuelTankOptimization * weightAtmosphericFuel + weightSpaceFuel = weightSpaceFuel - 0.09 * StatFuelTankOptimization * weightSpaceFuel + weightRocketFuel = weightRocketFuel - 0.09 * StatFuelTankOptimization * weightRocketFuel + end + for i, id in ipairs(typeElements) do local idName = core.getElementNameById(id) or "" local idType = core.getElementTypeById(id) or "" @@ -396,12 +402,7 @@ function UpdateTypeData() baseVol = 0.2 * StatAtmosphericFuelTankHandling * baseVol + baseVol end cMass = idMass - baseMass - if cMass <=10 then cMass = 0 - else - if StatFuelTankOptimization > 0 then - cMass = 0.05 * StatFuelTankOptimization * cMass + cMass - end - end + if cMass <=10 then cMass = 0 end cVol = string.format("%.0f", cMass / weightAtmosphericFuel) cPercent = string.format("%.1f", math.floor(100/baseVol * tonumber(cVol))) table.insert(FuelAtmosphericTanks, { @@ -435,19 +436,11 @@ function UpdateTypeData() baseMass = 182.67 baseVol = 400 end - if StatFuelTankOptimization > 0 then - cMass = 0.05 * StatFuelTankOptimization * cMass + cMass - end if StatSpaceFuelTankHandling > 0 then baseVol = 0.2 * StatSpaceFuelTankHandling * baseVol + baseVol end cMass = idMass - baseMass - if cMass <=10 then cMass = 0 - else - if StatFuelTankOptimization > 0 then - cMass = 0.05 * StatFuelTankOptimization * cMass + cMass - end - end + if cMass <=10 then cMass = 0 end cVol = string.format("%.0f", cMass / weightSpaceFuel) cPercent = string.format("%.1f", (100/baseVol * tonumber(cVol))) table.insert(FuelSpaceTanks, { @@ -489,12 +482,6 @@ function UpdateTypeData() baseVol = 0.2 * StatRocketFuelTankHandling * baseVol + baseVol end cMass = idMass - baseMass - if cMass <=10 then cMass = 0 - else - if StatFuelTankOptimization > 0 then - cMass = 0.05 * StatFuelTankOptimization * cMass + cMass - end - end if cMass <=10 then cMass = 0 end cVol = string.format("%.0f", cMass / weightRocketFuel) cPercent = string.format("%.1f", (100/baseVol * tonumber(cVol))) diff --git a/src/DamageReport_3_03_UnitStart_1.lua b/src/DamageReport_3_03_UnitStart_1.lua new file mode 100644 index 0000000..159aa90 --- /dev/null +++ b/src/DamageReport_3_03_UnitStart_1.lua @@ -0,0 +1,1277 @@ +--[[ + Damage Report 3.03 + A LUA script for Dual Universe + + Created By Dorian Gray + Ingame: DorianGray + Discord: Dorian Gray#2623 + + You can find/update this script on GitHub. Explanations, installation and usage information as well as screenshots can be found there too. + GitHub: https://github.com/DorianTheGrey/DU-DamageReport + + GNU Public License 3.0. Use whatever you want, be so kind to leave credit. + + Credits & thanks: + Thanks to NovaQuark for creating the MMO of the century. + Thanks to Jericho, Dmentia and Archaegeo for learning a lot from their fine scripts. + Thanks to TheBlacklist for testing and wonderful suggestions. + SVG patterns by Hero Patterns. + DU atlas data from Jayle Break. + +]] + +--[[ 1. HELPER FUNCTIONS ]] + +function GenerateCommaValue(amount, kify, postcomma) + kify = kify or false + postcomma = postcomma or 1 + local formatted = amount + if kify == true then + if string.len(amount)>=4 then + formatted = string.format("%."..postcomma.."fk", amount/1000) + else + formatted = string.format("%."..postcomma.."f", amount) + end + else + while true do + formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') + if (k == 0) then break end + end + end + return formatted +end + +function PrintConsole(output, highlight) + highlight = highlight or false + if highlight then + system.print( + "------------------------------------------------------------------------") + end + system.print(output) + if highlight then + system.print( + "------------------------------------------------------------------------") + end +end + +function DrawCenteredText(output) + if screens ~= nil and #screens > 0 then + for i = 1, #screens, 1 do + screens[i].element.setCenteredText(output) + end + end +end + +function ClearConsole() + for i = 1, 10, 1 do + PrintConsole() + end +end + +function SwitchScreens(state) + state = state or "on" + if screens ~= nil and #screens > 0 then + for i = 1, #screens, 1 do + if state == "on" then + screens[i].element.clear() + screens[i].element.activate() + screens[i].active = true + else + screens[i].element.clear() + screens[i].element.deactivate() + screens[i].active = false + end + end + end +end + +--[[ Convert seconds to string (by Jericho) ]] +function GetSecondsString(seconds) + local seconds = tonumber(seconds) + + if seconds == nil or seconds <= 0 then + return "-"; + else + days = string.format("%2.f", math.floor(seconds/(3600*24))); + hours = string.format("%2.f", math.floor(seconds/3600 - (days*24))); + mins = string.format("%2.f", math.floor(seconds/60 - (hours*60) - (days*24*60))); + secs = string.format("%2.f", math.floor(seconds - hours*3600 - (days*24*60*60) - mins *60)); + str = "" + if tonumber(days) > 0 then str = str .. days.."d " end + if tonumber(hours) > 0 then str = str .. hours.."h " end + if tonumber(mins) > 0 then str = str .. mins.."m " end + if tonumber(secs) > 0 then str = str .. secs .."s" end + return str + end +end + +function replace_char(pos, str, r) + return str:sub(1, pos-1) .. r .. str:sub(pos+1) +end + +--[[ 2. RENDER HELPER FUNCTIONS ]] + +--[[ epochTime function by Leodr (clock script), enhanced by Jericho (DU Industry script) ]] +function epochTime() + function rZ(a) + if string.len(a) <= 1 then + return "0" .. a + else + return a + end + end + function dPoint(b) + if not (b == math.floor(b)) then + return true + else + return false + end + end + function lYear(year) + if not dPoint(year / 4) then + if dPoint(year / 100) then + return true + else + if not dPoint(year / 400) then + return true + else + return false + end + end + else + return false + end + end + local c = 5; + local d = 3600; + local e = 86400; + local f = 31536000; + local g = 31622400; + local h = 2419200; + local i = 2505600; + local j = 2592000; + local k = 2678400; + local l = {4, 6, 9, 11} + local m = {1, 3, 5, 7, 8, 10, 12} + local n = 0; + local o = 1506816000; + local q = system.getTime() + _G["formerTime"] = q + if AddSummertimeHour == true then q = q + 3600 end + now = math.floor(q + o) + year = 1970; + secs = 0; + n = 0; + while secs + g < now or secs + f < now do + if lYear(year + 1) then + if secs + g < now then + secs = secs + g; + year = year + 1; + n = n + 366 + end + else + if secs + f < now then + secs = secs + f; + year = year + 1; + n = n + 365 + end + end + end + secondsRemaining = now - secs; + monthSecs = 0; + yearlYear = lYear(year) + month = 1; + while monthSecs + h < secondsRemaining or monthSecs + j < secondsRemaining or + monthSecs + k < secondsRemaining do + if month == 1 then + if monthSecs + k < secondsRemaining then + month = 2; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 2 then + if not yearlYear then + if monthSecs + h < secondsRemaining then + month = 3; + monthSecs = monthSecs + h; + n = n + 28 + else + break + end + else + if monthSecs + i < secondsRemaining then + month = 3; + monthSecs = monthSecs + i; + n = n + 29 + else + break + end + end + end + if month == 3 then + if monthSecs + k < secondsRemaining then + month = 4; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 4 then + if monthSecs + j < secondsRemaining then + month = 5; + monthSecs = monthSecs + j; + n = n + 30 + else + break + end + end + if month == 5 then + if monthSecs + k < secondsRemaining then + month = 6; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 6 then + if monthSecs + j < secondsRemaining then + month = 7; + monthSecs = monthSecs + j; + n = n + 30 + else + break + end + end + if month == 7 then + if monthSecs + k < secondsRemaining then + month = 8; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 8 then + if monthSecs + k < secondsRemaining then + month = 9; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 9 then + if monthSecs + j < secondsRemaining then + month = 10; + monthSecs = monthSecs + j; + n = n + 30 + else + break + end + end + if month == 10 then + if monthSecs + k < secondsRemaining then + month = 11; + monthSecs = monthSecs + k; + n = n + 31 + else + break + end + end + if month == 11 then + if monthSecs + j < secondsRemaining then + month = 12; + monthSecs = monthSecs + j; + n = n + 30 + else + break + end + end + end + day = 1; + daySecs = 0; + daySecsRemaining = secondsRemaining - monthSecs; + while daySecs + e < daySecsRemaining do + day = day + 1; + daySecs = daySecs + e; + n = n + 1 + end + hour = 0; + hourSecs = 0; + hourSecsRemaining = daySecsRemaining - daySecs; + while hourSecs + d < hourSecsRemaining do + hour = hour + 1; + hourSecs = hourSecs + d + end + minute = 0; + minuteSecs = 0; + minuteSecsRemaining = hourSecsRemaining - hourSecs; + while minuteSecs + 60 < minuteSecsRemaining do + minute = minute + 1; + minuteSecs = minuteSecs + 60 + end + second = math.floor(now % 60) + year = rZ(year) + month = rZ(month) + day = rZ(day) + hour = rZ(hour) + minute = rZ(minute) + second = rZ(second) + + return [[]]..hour..":".. minute..[[]].. + [[]]..year.."/".. month.."/"..day..[[]] +end + + +function ToggleHUD() + if HUDMode == true then + HUDMode = false + forceDamageRedraw = true + hudSelectedIndex = 0 + highlightID = 0 + HideHighlight() + SetRefresh() + RenderScreens() + else + HUDMode = true + forceDamageRedraw = true + hudSelectedIndex = 0 + highlightID = 0 + HideHighlight() + SetRefresh() + RenderScreens() + end +end + +function HudDeselectElement() + hudSelectedIndex = 0 + hudStartIndex = 1 + highlightID = 0 + HideHighlight() + if HUDMode == true then + SetRefresh("damage") + SetRefresh("damageoutline") + RenderScreens() + end +end + +function ChangeHudSelectedElement(step) + if HUDMode == true and #rE > 0 then + + hudSelectedIndex = hudSelectedIndex + step + if hudSelectedIndex < 1 then hudSelectedIndex = 1 + elseif hudSelectedIndex > #rE then hudSelectedIndex = #rE + end + + if hudSelectedIndex > 9 then + hudStartIndex = hudSelectedIndex-9 + end + if hudSelectedIndex ~= 0 then + highlightID = rE[hudSelectedIndex].id + if highlightID ~=nil and highlightID ~= 0 then + -- PrintConsole("CHSE: hudSelectedIndex: "..hudSelectedIndex.." / hudStartIndex: "..hudStartIndex.." / highlightID: "..highlightID) + HideHighlight() + elementPosition = vec3(rE[hudSelectedIndex].pos) + highlightX = elementPosition.x - coreWorldOffset + highlightY = elementPosition.y - coreWorldOffset + highlightZ = elementPosition.z - coreWorldOffset + highlightOn = true + ShowHighlight() + end + end + + SetRefresh("damage") + SetRefresh("damageoutline") + RenderScreens() + + 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 SortDamageTables() + table.sort(damagedElements, function(a, b) return a.missinghp > b.missinghp end) + table.sort(brokenElements, function(a, b) return a.maxhp > b.maxhp end) +end + +function getScraps(damage,commaval) + commaval = commaval or false + damage = damage - SkillRepairToolOptimization * 0.05 * damage + local res = math.ceil( damage / ( 10 * 5^(ScrapTier-1) ) ) + if commaval ==true then + return GenerateCommaValue(string.format("%.0f", res ), false) + else + return res + end +end + +function getRepairTime(damage,buildstring) + buildstring = buildstring or false + damage = damage - SkillRepairToolOptimization * 0.05 * damage + local res = math.ceil(damage / ScrapTierRepairTimes[ScrapTier]) + res = res - ( SkillRepairToolEfficiency * 0.1 * res ) + if buildstring == true then + return GetSecondsString(string.format("%.0f", res ) ) + else + return res + end +end + +function UpdateDataDamageoutline() + + dmgoElements = {} + + for i,element in ipairs(brokenElements) do + if #dmgoElements < DMGOMaxElements then + local elementPosition = vec3(element.pos) + local x = elementPosition.x - coreWorldOffset + local y = elementPosition.y - coreWorldOffset + local z = elementPosition.z - coreWorldOffset + if x < ShipXmin then ShipXmin = x end + if y < ShipYmin then ShipYmin = y end + if z < ShipZmin then ShipZmin = z end + if x > ShipXmax then ShipXmax = x end + if y > ShipYmax then ShipYmax = y end + if z > ShipZmax then ShipZmax = z end + table.insert( dmgoElements, { + id = element.id, + type = "b", + size = element.maxhp, + x = x, y = y, z = z, + xp = 0, yp = 0, zp = 0, + u = 0, v = 0 + }) + end + end + + if #dmgoElements < DMGOMaxElements then + for i,element in ipairs(damagedElements) do + if #dmgoElements < DMGOMaxElements then + local elementPosition = vec3(element.pos) + local x = elementPosition.x - coreWorldOffset + local y = elementPosition.y - coreWorldOffset + local z = elementPosition.z - coreWorldOffset + if x < ShipXmin then ShipXmin = x end + if y < ShipYmin then ShipYmin = y end + if z < ShipZmin then ShipZmin = z end + if x > ShipXmax then ShipXmax = x end + if y > ShipYmax then ShipYmax = y end + if z > ShipZmax then ShipZmax = z end + table.insert( dmgoElements, { + id = element.id, + type = "d", + size = element.maxhp, + x = x, y = y, z = z, + xp = 0, yp = 0, zp = 0, + u = 0, v = 0 + }) + end + end + end + + if #dmgoElements < DMGOMaxElements then + for i,element in ipairs(healthyElements) do + if #dmgoElements < DMGOMaxElements then + local elementPosition = vec3(element.pos) + local x = elementPosition.x - coreWorldOffset + local y = elementPosition.y - coreWorldOffset + local z = elementPosition.z - coreWorldOffset + if x < ShipXmin then ShipXmin = x end + if y < ShipYmin then ShipYmin = y end + if z < ShipZmin then ShipZmin = z end + if x > ShipXmax then ShipXmax = x end + if y > ShipYmax then ShipYmax = y end + if z > ShipZmax then ShipZmax = z end + table.insert( dmgoElements, { + id = element.id, + type = "h", + size = element.maxhp, + x = x, y = y, z = z, + xp = 0, yp = 0, zp = 0, + u = 0, v = 0 + }) + end + end + end + + ShipX = math.abs(ShipXmax-ShipXmin) + ShipY = math.abs(ShipYmax-ShipYmin) + ShipZ = math.abs(ShipZmax-ShipZmin) + + --[[ + PrintConsole( + "ShipXmin: "..string.format("%.2f",ShipXmin).. + " - ShipYmin: "..string.format("%.2f",ShipYmin).. + " - ShipZmin: "..string.format("%.2f",ShipZmin).. + " - ShipXmax: "..string.format("%.2f",ShipXmax).. + " - ShipYmax: "..string.format("%.2f",ShipYmax).. + " - ShipZmax: "..string.format("%.2f",ShipZmax) + ) + + PrintConsole( + "ShipX: "..string.format("%.2f",ShipX).. + " - ShipY: "..string.format("%.2f",ShipY).. + " - ShipZ: "..string.format("%.2f",ShipZ) + ) + ]] + + for i,element in ipairs(dmgoElements) do + dmgoElements[i].xp = math.abs(100/(ShipXmax-ShipXmin)*(element.x-ShipXmin)) + dmgoElements[i].yp = math.abs(100/(ShipYmax-ShipYmin)*(element.y-ShipYmin)) + dmgoElements[i].zp = math.abs(100/(ShipZmax-ShipZmin)*(element.z-ShipZmin)) + -- PrintConsole(i..". "..element.id..": "..string.format("%.2f",element.x).."/"..string.format("%.2f",element.y).."/"..string.format("%.2f",element.z).." - XP: "..dmgoElements[i].xp.." - YP: "..dmgoElements[i].yp.." - ZP: "..dmgoElements[i].zp) + end + +end + +function UpdateViewDamageoutline(screen) + -- Full Width of virtual screen: + -- UStart = 20 + -- VStart = 180 + -- UDim = 1880 + -- VDim = 840 + -- Adding frames: + UFrame = 40 + VFrame = 40 + + UStart = 20 + UFrame + VStart = 180 + VFrame + UDim = 1880 - 2*UFrame + VDim = 840 - 2*VFrame + + if screen.submode == "top" then + if DMGOStretch == false then + local UFactor = UDim/(ShipYmax-ShipYmin) + local VFactor = VDim/(ShipXmax-ShipXmin) + if UFactor>=VFactor then + local cFactor = UFactor/VFactor + local newUDim = math.floor(UDim/cFactor) + UStart = UStart+(UDim-newUDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100/cFactor*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100*element.xp+VStart) + end + else + local cFactor = VFactor/UFactor + local newVDim = math.floor(VDim/cFactor) + VStart = VStart+(VDim-newVDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100/cFactor*element.xp+VStart) + end + end + else + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100*element.xp+VStart) + end + end + + + elseif screen.submode == "front" then + if DMGOStretch == false then + local UFactor = UDim/(ShipXmax-ShipXmin) + local VFactor = VDim/(ShipZmax-ShipZmin) + if UFactor>=VFactor then + local cFactor = UFactor/VFactor + local newUDim = math.floor(UDim/cFactor) + UStart = UStart+(UDim-newUDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100/cFactor*element.xp+UStart) + dmgoElements[i].v = math.floor(VDim/100*(100-element.zp)+VStart) + end + else + local cFactor = VFactor/UFactor + local newVDim = math.floor(VDim/cFactor) + VStart = VStart+(VDim-newVDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.xp+UStart) + dmgoElements[i].v = math.floor(VDim/100/cFactor*(100-element.zp)+VStart) + end + end + else + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.xp+UStart) + dmgoElements[i].v = math.floor(VDim/100*(100-element.zp)+VStart) + end + end + + elseif screen.submode == "side" then + if DMGOStretch == false then + local UFactor = UDim/(ShipYmax-ShipYmin) + local VFactor = VDim/(ShipXmax-ShipZmin) + if UFactor>=VFactor then + local cFactor = UFactor/VFactor + local newUDim = math.floor(UDim/cFactor) + UStart = UStart+(UDim-newUDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100/cFactor*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100*(100-element.zp)+VStart) + end + else + local cFactor = VFactor/UFactor + local newVDim = math.floor(VDim/cFactor) + VStart = VStart+(VDim-newVDim)/2 + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100/cFactor*(100-element.zp)+VStart) + end + end + else + for i,element in ipairs(dmgoElements) do + dmgoElements[i].u = math.floor(UDim/100*element.yp+UStart) + dmgoElements[i].v = math.floor(VDim/100*(100-element.zp)+VStart) + end + end + else + DrawCenteredText("ERROR: non-existing DMGO mode set.") + PrintConsole("ERROR: non-existing DMGO mode set.") + unit.exit() + end +end + +function GetDamageoutlineShip() + local output = "" + + for i,element in ipairs(dmgoElements) do + local cclass = "" + local size = 1 + + if element.type == "h" then + cclass ="ch" + elseif element.type == "d" then + cclass = "cw" + else + cclass = "cc" + end + if element.id == highlightID then + cclass = "f2" + end + + if element.size > 0 and element.size < 1000 then + size = 5 + elseif element.size >= 1000 and element.size < 2000 then + size = 8 + elseif element.size >= 2000 and element.size < 5000 then + size = 12 + elseif element.size >= 5000 and element.size < 10000 then + size = 15 + elseif element.size >= 10000 and element.size < 20000 then + size = 20 + elseif element.size >= 20000 then + size = 30 + end + output = output .. [[]] + if element.id == highlightID then + output = output .. [[]] + output = output .. [[]] + end + end + + return output +end + +function GetContentClickareas(screen) + local output = "" + if screen ~= nil and screen.ClickAreas ~= nil and #screen.ClickAreas > 0 then + for i,ca in ipairs(screen.ClickAreas) do + output = output .. + [[]] + end + end + return output +end + +function GetElement1(x, y, width, height) + x = x or 0 + y = y or 0 + width = width or 600 + height = height or 600 + local output = "" + output = output .. + [[ + + + + + + + + + + + + + + + + + ]] + return output +end + +function GetElement2(x, y) + x = x or 0 + y = y or 0 + local output = "" + output = output .. [[]] + return output +end + +function GetElementLogo(x, y, primaryC, secondaryC, tertiaryC) + x = x or 812 + y = y or 380 + primaryC = primaryC or "f" + secondaryC = secondaryC or "f2" + tertiaryC = tertiaryC or "f3" + local output = "" + output = output .. [[ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ]] + return output +end + +function GetHeader(headertext) + headertext = headertext or "ERROR: UNDEFINED" + local output = "" + output = output .. + [[ + ]]..headertext..[[]] + return output +end + +function GetContentBackground(candidate, bgcolor) + bgColor = ColorBackgroundPattern + + local output = "" + + if candidate == "dots" then + output=[[background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E");]] + elseif candidate == "rain" then + output=[[background-image: url("data:image/svg+xml,%3Csvg width='12' height='16' viewBox='0 0 12 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 .99C4 .445 4.444 0 5 0c.552 0 1 .45 1 .99v4.02C6 5.555 5.556 6 5 6c-.552 0-1-.45-1-.99V.99zm6 8c0-.546.444-.99 1-.99.552 0 1 .45 1 .99v4.02c0 .546-.444.99-1 .99-.552 0-1-.45-1-.99V8.99z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E");]] + elseif candidate == "plus" then + output=[[background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");]] + elseif candidate == "signal" then + output=[[background-image: url("data:image/svg+xml,%3Csvg width='84' height='48' viewBox='0 0 84 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h12v6H0V0zm28 8h12v6H28V8zm14-8h12v6H42V0zm14 0h12v6H56V0zm0 8h12v6H56V8zM42 8h12v6H42V8zm0 16h12v6H42v-6zm14-8h12v6H56v-6zm14 0h12v6H70v-6zm0-16h12v6H70V0zM28 32h12v6H28v-6zM14 16h12v6H14v-6zM0 24h12v6H0v-6zm0 8h12v6H0v-6zm14 0h12v6H14v-6zm14 8h12v6H28v-6zm-14 0h12v6H14v-6zm28 0h12v6H42v-6zm14-8h12v6H56v-6zm0-8h12v6H56v-6zm14 8h12v6H70v-6zm0 8h12v6H70v-6zM14 24h12v6H14v-6zm14-8h12v6H28v-6zM14 8h12v6H14V8zM0 8h12v6H0V8z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E");]] + elseif candidate == "deathstar" then + output=[[background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='105' viewBox='0 0 80 105'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath d='M20 10a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V10zm15 35a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zM20 75a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V75zm30-65a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V10zm0 65a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V75zM35 10a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10zM5 45a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zm0-35a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10zm60 35a5 5 0 0 1 10 0v50a5 5 0 0 1-10 0V45zm0-35a5 5 0 0 1 10 0v20a5 5 0 0 1-10 0V10z' /%3E%3C/g%3E%3C/g%3E%3C/svg%3E");]] + elseif candidate == "diamond" then + output=[[background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='32' viewBox='0 0 16 32'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[['%3E%3Cpath fill-rule='evenodd' d='M0 24h4v2H0v-2zm0 4h6v2H0v-2zm0-8h2v2H0v-2zM0 0h4v2H0V0zm0 4h2v2H0V4zm16 20h-6v2h6v-2zm0 4H8v2h8v-2zm0-8h-4v2h4v-2zm0-20h-6v2h6V0zm0 4h-4v2h4V4zm-2 12h2v2h-2v-2zm0-8h2v2h-2V8zM2 8h10v2H2V8zm0 8h10v2H2v-2zm-2-4h14v2H0v-2zm4-8h6v2H4V4zm0 16h6v2H4v-2zM6 0h2v2H6V0zm0 24h2v2H6v-2z'/%3E%3C/g%3E%3C/svg%3E");]] + elseif candidate == "hexagon" then + output=[[background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg id='hexagons' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='nonzero'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");]] + elseif candidate == "capsule" then + output=[[background-image: url("data:image/svg+xml,%3Csvg width='32' height='26' viewBox='0 0 32 26' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 0v3.994C14 7.864 10.858 11 7 11c-3.866 0-7-3.138-7-7.006V0h2v4.005C2 6.765 4.24 9 7 9c2.756 0 5-2.236 5-4.995V0h2zm0 26v-5.994C14 16.138 10.866 13 7 13c-3.858 0-7 3.137-7 7.006V26h2v-6.005C2 17.235 4.244 15 7 15c2.76 0 5 2.236 5 4.995V26h2zm2-18.994C16 3.136 19.142 0 23 0c3.866 0 7 3.138 7 7.006v9.988C30 20.864 26.858 24 23 24c-3.866 0-7-3.138-7-7.006V7.006zm2-.01C18 4.235 20.244 2 23 2c2.76 0 5 2.236 5 4.995v10.01C28 19.765 25.756 22 23 22c-2.76 0-5-2.236-5-4.995V6.995z' fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'/%3E%3C/svg%3E");]] + elseif candidate == "diagonal" then + output=[[background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23]]..bgColor..[[' fill-opacity=']]..BackgroundModeOpacity..[[' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E");]] + end + return output; +end + +function GetContentDamageHUDOutput() + local hudWidth = 300 + local hudHeight = 165 + if #damagedElements > 0 or #brokenElements > 0 then hudHeight = 510 end + local output = "" + + output = output .. [[ + + ]] + output = output .. [[]] .. + [[]] .. + [[]] .. + [[]]..(YourShipsName=="Enter here" and ("Ship ID "..ShipID) or YourShipsName) .. [[]] .. + [[]] + if #brokenElements > 0 then + output = output .. [[]] + elseif #damagedElements > 0 then + output = output .. [[]] + else + output = output .. [[]] + end + + if #damagedElements > 0 or #brokenElements > 0 then + + output = output .. [[Total Damage]] .. + [[]]..GenerateCommaValue(string.format("%.0f", totalShipMaxHP - totalShipHP))..[[]] + output = output .. [[T]]..ScrapTier..[[ Scrap Needed]] .. + [[]]..getScraps(totalShipMaxHP - totalShipHP, true)..[[]] + output = output .. [[Repair Time]] .. + [[]]..getRepairTime(totalShipMaxHP - totalShipHP, true)..[[]] + + output = output .. [[]] .. + [[]] .. + [[]]..#healthyElements..[[]] .. + [[]] .. + [[]]..#damagedElements..[[]] .. + [[]] .. + [[]]..#brokenElements..[[]] + local j=0 + + for currentIndex=hudStartIndex,hudStartIndex+9,1 do + if rE[currentIndex] ~= nil then + v = rE[currentIndex] + if v.hp > 0 then + output = output .. [[]] .. + [[]]..string.format("%.30s", v.name)..[[]] .. + [[]]..GenerateCommaValue(string.format("%.0f", v.missinghp))..[[]] + if v.id == highlightID then + output = output .. [[]] .. + [[]]..string.format("%.30s", v.name)..[[]] .. + [[]]..GenerateCommaValue(string.format("%.0f", v.missinghp))..[[]] + end + else + output = output .. [[]] .. + [[]]..string.format("%.30s", v.name)..[[]] .. + [[]]..GenerateCommaValue(string.format("%.0f", v.missinghp))..[[]] + if v.id == highlightID then + highlightX = elementPosition.x - coreWorldOffset + highlightY = elementPosition.y - coreWorldOffset + highlightZ = elementPosition.z - coreWorldOffset + output = output .. [[]] .. + [[]]..string.format("%.30s", v.name)..[[]] .. + [[]]..GenerateCommaValue(string.format("%.0f", v.missinghp))..[[]] + end + end + j=j+1 + end + end + output = output .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[Up/down arrows to highlight]] .. + [[CTRL + arrows to move HUD]] .. + [[Left arrow to toggle HUD Mode]] .. + [[ALT+1-4 to set Scrap Tier]] .. + [[ALT+8 to reset HUD position]] .. + [[ALT+9 to shut script off]] .. + [[]] .. + [[]] + else + output = output .. + [[]] .. OkayCenterMessage .. [[]] .. + [[]]..#healthyElements..[[ elements / ]] .. GenerateCommaValue(string.format("%.0f", totalShipMaxHP)) .. [[ HP.]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[Left arrow to toggle HUD Mode]] .. + [[CTRL + arrows to move HUD]] .. + [[ALT+8 to reset HUD position]] .. + [[ALT+9 to shut script off]] .. + [[]] .. + [[]] + end + output = output .. [[]] + return output +end + +function GetContentDamageScreen() + + local screenOutput = "" + + -- Draw damage elements + if #damagedElements > 0 then + local damagedElementsToDraw = #damagedElements + if damagedElementsToDraw > DamagePageSize then + damagedElementsToDraw = DamagePageSize + end + if CurrentDamagedPage == math.ceil(#damagedElements / DamagePageSize) then + damagedElementsToDraw = #damagedElements % DamagePageSize + 12 + if damagedElementsToDraw > 12 then damagedElementsToDraw = damagedElementsToDraw - 12 end + end + screenOutput = screenOutput .. [[]] + screenOutput = screenOutput .. [[]] + + if UseMyElementNames == true then screenOutput = screenOutput .. [[Damaged Name]] + else screenOutput = screenOutput .. [[Damaged Type]] + end + + screenOutput = screenOutput .. [[HLTHDMG]] + screenOutput = screenOutput .. [[T]]..ScrapTier..[[ SCRREPTIME]] + + AddClickArea("damage", { + id = "SwitchScrapTier", + mode ="damage", + x1 = 650, + x2 = 775, + y1 = 315, + y2 = 360 + }) + + local i = 0 + for j = 1 + (CurrentDamagedPage - 1) * DamagePageSize, damagedElementsToDraw + (CurrentDamagedPage - 1) * DamagePageSize, 1 do + i = i + 1 + local DP = damagedElements[j] + if UseMyElementNames == true then screenOutput = screenOutput .. [[]] .. string.format("%.23s", DP.name) .. [[]] + else screenOutput = screenOutput .. [[]] .. string.format("%.23s", DP.type) .. [[]] + end + screenOutput = screenOutput .. [[]] .. DP.percent .. [[%]] .. + [[]] .. GenerateCommaValue(string.format("%.0f", DP.missinghp), true) .. [[]] .. + [[]] .. getScraps(DP.missinghp, true) .. [[]] .. + [[]] .. getRepairTime(DP.missinghp, true) .. [[]] .. + [[]] + end + + if #damagedElements > DamagePageSize then + screenOutput = screenOutput .. + [[Page ]] .. CurrentDamagedPage .. " of " .. math.ceil(#damagedElements / DamagePageSize) ..[[]] + + if CurrentDamagedPage < math.ceil(#damagedElements / DamagePageSize) then + screenOutput = screenOutput .. [[ + + + ]] + AddClickArea("damage", { + id = "DamagedPageDown", + mode ="damage", + x1 = 65, + x2 = 260, + y1 = 290 + (damagedElementsToDraw + 1) * 50, + y2 = 290 + 50 + (damagedElementsToDraw + 1) * 50 + }) + else + DisableClickArea("DamagedPageDown","damage") + end + + if CurrentDamagedPage > 1 then + screenOutput = screenOutput .. [[ + + + ]] + AddClickArea("damage", { + id = "DamagedPageUp", + mode ="damage", + x1 = 750, + x2 = 950, + y1 = 290 + (damagedElementsToDraw + 1) * 50, + y2 = 290 + 50 + (damagedElementsToDraw + 1) * 50 + }) + else + DisableClickArea("DamagedPageUp","damage") + end + end + end + + -- Draw broken elements + if #brokenElements > 0 then + local brokenElementsToDraw = #brokenElements + if brokenElementsToDraw > DamagePageSize then + brokenElementsToDraw = DamagePageSize + end + if CurrentBrokenPage == math.ceil(#brokenElements / DamagePageSize) then + brokenElementsToDraw = #brokenElements % DamagePageSize + 12 + if brokenElementsToDraw > 12 then brokenElementsToDraw = brokenElementsToDraw - 12 end + end + screenOutput = screenOutput .. [[]] + screenOutput = screenOutput .. [[]] + + if UseMyElementNames == true then screenOutput = screenOutput .. [[Broken Name]] + else screenOutput = screenOutput .. [[Broken Type]] + end + + screenOutput = screenOutput .. [[DMG]] + screenOutput = screenOutput .. [[T]]..ScrapTier..[[ SCRREPTIME]] + + AddClickArea("damage", { + id = "SwitchScrapTier2", + mode ="damage", + x1 = 1570, + x2 = 1690, + y1 = 315, + y2 = 360 + }) + + local i = 0 + for j = 1 + (CurrentBrokenPage - 1) * DamagePageSize, brokenElementsToDraw + (CurrentBrokenPage - 1) * DamagePageSize, 1 do + i = i + 1 + local DP = brokenElements[j] + if UseMyElementNames == true then screenOutput = screenOutput .. [[]] .. string.format("%.30s", DP.name) .. [[]] + else screenOutput = screenOutput .. [[]] .. string.format("%.30s", DP.type) .. [[]] + end + screenOutput = screenOutput .. [[]] .. GenerateCommaValue(string.format("%.0f", DP.missinghp), true) .. [[]] .. + [[]] .. getScraps(DP.missinghp, true) .. [[]] .. + [[]] .. getRepairTime(DP.missinghp, true) .. [[]] .. + [[]] + end + + + + if #brokenElements > DamagePageSize then + screenOutput = screenOutput .. + [[Page ]] .. CurrentBrokenPage .. " of " .. math.ceil(#brokenElements / DamagePageSize) .. [[]] + + if CurrentBrokenPage > 1 then + screenOutput = screenOutput .. [[ + + + ]] + AddClickArea("damage", { + id = "BrokenPageUp", + mode ="damage", + x1 = 1665, + x2 = 1865, + y1 = 290 + (brokenElementsToDraw + 1) * 50, + y2 = 290 + 50 + (brokenElementsToDraw + 1) * 50 + }) + else + DisableClickArea("BrokenPageUp", "damage") + end + + if CurrentBrokenPage < math.ceil(#brokenElements / DamagePageSize) then + screenOutput = screenOutput .. [[ + + + ]] + AddClickArea("damage", { + id = "BrokenPageDown", + mode ="damage", + x1 = 980, + x2 = 1180, + y1 = 290 + (brokenElementsToDraw + 1) * 50, + y2 = 290 + 50 + (brokenElementsToDraw + 1) * 50 + }) + else + DisableClickArea("BrokenPageDown", "damage") + end + end + + end + + -- Draw summary + if #damagedElements > 0 or #brokenElements > 0 then + local dWidth = math.floor(1878/#elementsIdList*#damagedElements) + local bWidth = math.floor(1878/#elementsIdList*#brokenElements) + local hWidth = 1878-dWidth-bWidth+1 + + screenOutput = screenOutput .. [[]] + screenOutput = screenOutput .. [[]] + screenOutput = screenOutput .. [[]] + screenOutput = screenOutput .. [[]] + + if #damagedElements > 0 then + screenOutput = screenOutput .. [[]]..#damagedElements..[[]] + end + if #healthyElements > 0 then + screenOutput = screenOutput .. [[]]..#healthyElements..[[]] + end + if #brokenElements > 0 then + screenOutput = screenOutput .. [[]]..#brokenElements..[[]] + end + + screenOutput = screenOutput .. [[]] + + screenOutput = screenOutput .. [[]] .. + GenerateCommaValue(string.format("%.0f", totalShipMaxHP - totalShipHP)) .. [[ HP damage in total ]] .. + getScraps(totalShipMaxHP - totalShipHP, true) .. [[ T]]..ScrapTier..[[ scraps needed. ]] .. + getRepairTime(totalShipMaxHP - totalShipHP, true) .. [[ projected repair time.]] + else + screenOutput = screenOutput .. GetElementLogo(812, 380, "ch", "ch", "ch") .. + [[]] .. OkayCenterMessage .. [[]] .. + [[]]..#healthyElements..[[ elements stand ]] .. GenerateCommaValue(string.format("%.0f", totalShipMaxHP)) .. [[ HP strong.]] + end + + forceDamageRedraw = false + + return screenOutput +end + +function ActionStopengines() + ToggleHUD() +end + +function ActionStrafeRight() + if KeyCTRLPressed == true then + if HUDShiftU < 4000 then + HUDShiftU = HUDShiftU + 50 + SaveToDatabank() + RenderScreens() + end + else + HudDeselectElement() + end +end + +function ActionStrafeLeft() + if KeyCTRLPressed == true then + if HUDShiftU >= 50 then + HUDShiftU = HUDShiftU - 50 + SaveToDatabank() + RenderScreens() + end + else + ToggleHUD() + end +end + +function ActionDown() + if KeyCTRLPressed == true then + if HUDShiftV < 4000 then + HUDShiftV = HUDShiftV + 50 + SaveToDatabank() + RenderScreens() + end + else + ChangeHudSelectedElement(1) + end +end + +function ActionUp() + if KeyCTRLPressed == true then + if HUDShiftV >= 50 then + HUDShiftV = HUDShiftV - 50 + SaveToDatabank() + RenderScreens() + end + else + ChangeHudSelectedElement(-1) + end +end + +function ActionOption1() + ScrapTier = 1 + SetRefresh("damage") + RenderScreens("damage") +end + +function ActionOption2() + ScrapTier = 2 + SetRefresh("damage") + RenderScreens("damage") +end + +function ActionOption3() + ScrapTier = 3 + SetRefresh("damage") + RenderScreens("damage") +end + +function ActionOption4() + ScrapTier = 4 + SetRefresh("damage") + RenderScreens("damage") +end + +function ActionOption8() + HUDShiftU=0 + HUDShiftV=0 + SetRefresh("damage") + RenderScreens("damage") +end + +function ActionOption9() + SaveToDatabank() + SwitchScreens("off") + unit.exit() +end diff --git a/src/DamageReport_3_03_UnitStart_2.lua b/src/DamageReport_3_03_UnitStart_2.lua new file mode 100644 index 0000000..c186e51 --- /dev/null +++ b/src/DamageReport_3_03_UnitStart_2.lua @@ -0,0 +1,2030 @@ +--[[ + Damage Report 3.03 + A LUA script for Dual Universe + + Created By Dorian Gray + Ingame: DorianGray + Discord: Dorian Gray#2623 + + You can find/update this script on GitHub. Explanations, installation and usage information as well as screenshots can be found there too. + GitHub: https://github.com/DorianTheGrey/DU-DamageReport + + GNU Public License 3.0. Use whatever you want, be so kind to leave credit. + + Credits & thanks: + Thanks to NovaQuark for creating the MMO of the century. + Thanks to Jericho, Dmentia and Archaegeo for learning a lot from their fine scripts. + Thanks to TheBlacklist for testing and wonderful suggestions. + SVG patterns by Hero Patterns. + DU atlas data from Jayle Break. + +]] + +--[[ 1. USER DEFINED VARIABLES ]] + +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. + +SkillRepairToolEfficiency = 0 --export Enter (0-5) your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency" +SkillRepairToolOptimization = 0 --export Enter your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Optimization" + +-- SkillAtmosphericFuelEfficiency = 0 --export Enter (0-5) your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency" +-- SkillSpaceFuelEfficiency = 0 --export Enter (0-5) your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency" +-- SkillRocketFuelEfficiency = 0 --export Enter (0-5) your talent "Mining and Inventory -> Equipment Manager -> Repair Tool Efficiency" + +StatAtmosphericFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED ATMOSPHERIC FUEL TANKS (from the builders talent "Piloting -> Atmospheric Flight Technician -> Atmospheric Fuel-Tank Handling") +StatSpaceFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL SPACE TANKS (from the builders talent "Piloting -> Atmospheric Engine Technician -> Space Fuel-Tank Handling") +StatRocketFuelTankHandling = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL ROCKET TANKS (from the builders talent "Piloting -> Rocket Scientist -> Rocket Booster Fuel Tank Handling") +StatFuelTankOptimization = 0 --export (0-5) Enter the LEVEL OF YOUR PLACED FUEL TANKS "from the builders talent Mining and Inventory -> Stock Control -> Fuel Tank Optimization" + +ShowWelcomeMessage = true --export Do you want the welcome message on the start screen with your name? +AddSummertimeHour = false --export: Is summertime currently enabled in your location? (Adds one hour.) + +--[[ 2. GLOBAL VARIABLES ]] + +UpdateDataInterval = 1.0 -- How often shall the data be updated? (Increase if running into CPU issues.) +HighlightBlinkingInterval = 0.5 -- How fast shall highlight arrows of marked elements blink? + +ColorPrimary = "FF6700" -- Enter the hexcode of the main color to be used by all views. +ColorSecondary = "FFFFFF" -- Enter the hexcode of the secondary color to be used by all views. +ColorTertiary = "000000" -- Enter the hexcode of the tertiary color to be used by all views. +ColorHealthy = "00FF00" -- Enter the hexcode of the 'healthy' color to be used by all views. +ColorWarning = "FFFF00" -- Enter the hexcode of the 'warning' color to be used by all views. +ColorCritical = "FF0000" -- Enter the hexcode of the 'critical' color to be used by all views. +ColorBackground = "000000" -- Enter the hexcode of the background color to be used by all views. +ColorBackgroundPattern = "4F4F4F" -- Enter the hexcode of the background color to be used by all views. +ColorFuelAtmospheric = "004444" -- Enter the hexcode of the atmospheric fuel color. +ColorFuelSpace = "444400" -- Enter the hexcode of the space fuel color. +ColorFuelRocket = "440044" -- Enter the hexcode of the rocket fuel color. + +VERSION = 3.03 +DebugMode = false +DebugRenderClickareas = true + +DBData = {} + +core = nil +db = nil +screens = {} +dscreens = {} + +Warnings = {} + +screenModes = { + ["flight"] = { id="flight" }, + ["damage"] = { id="damage" }, + ["damageoutline"] = { id="damageoutline" }, + ["fuel"] = { id="fuel" }, + ["cargo"] = { id="cargo" }, + ["agg"] = { id="agg" }, + ["map"] = { id="map" }, + ["time"] = { id="time", activetoggle="true" }, + ["settings1"] = { id="settings1" }, + ["startup"] = { id="startup" } +} + +backgroundModes = { "deathstar", "capsule", "rain", "signal", "hexagon", "diagonal", "diamond", "plus", "dots" } +BackgroundMode ="deathstar" +BackgroundSelected = 1 +BackgroundModeOpacity = 0.25 + +SaveVars = { "dscreens", + "ColorPrimary", "ColorSecondary", "ColorTertiary", + "ColorHealthy", "ColorWarning", "ColorCritical", + "ColorBackground", "ColorBackgroundPattern", + "ScrapTier", "HUDMode", "SimulationMode", "DMGOStretch", + "HUDShiftU", "HUDShiftV", "colorIDIndex", "colorIDTable", + "BackgroundMode", "BackgroundSelected", "BackgroundModeOpacity" } + +HUDMode = false +HUDShiftU = 0 +HUDShiftV = 0 +hudSelectedIndex = 0 +hudStartIndex = 1 +hudArrowSticker = {} +highlightOn = false +highlightID = 0 +highlightX = 0 +highlightY = 0 +highlightZ = 0 + +SimulationMode = false +OkayCenterMessage = "All systems nominal." +CurrentDamagedPage = 1 +CurrentBrokenPage = 1 +DamagePageSize = 12 +ScrapTier = 1 +totalScraps = 0 +ScrapTierRepairTimes = { 10, 50, 250, 1250 } + +coreWorldOffset = 0 +totalShipHP = 0 +formerTotalShipHP = -1 +totalShipMaxHP = 0 +totalShipIntegrity = 100 +elementsId = {} +elementsIdList = {} +damagedElements = {} +brokenElements = {} +rE = {} +healthyElements = {} +typeElements = {} +ElementCounter = 0 +UseMyElementNames = true +dmgoElements = {} +DMGOMaxElements = 250 +DMGOStretch = false +ShipXmin = 99999999 +ShipXmax = -99999999 +ShipYmin = 99999999 +ShipYmax = -99999999 +ShipZmin = 99999999 +ShipZmax = -99999999 + +totalShipMass = 0 +formerTotalShipMass = -1 + +formerTime = -1 + +FuelAtmosphericTanks = {} +FuelSpaceTanks = {} +FuelRocketTanks = {} +FuelAtmosphericTotal = 0 +FuelSpaceTotal = 0 +FuelRocketTotal = 0 +FuelAtmosphericCurrent = 0 +FuelSpaceTotalCurrent = 0 +FuelRocketTotalCurrent = 0 +formerFuelAtmosphericTotal = -1 +formerFuelSpaceTotal = -1 +formerFuelRocketTotal = -1 + +hexTable = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"} +colorIDIndex = 1 +colorIDTable = { + [1] = { + id="ColorPrimary", + desc="Main HUD Color", + basec = "FF6700", + newc = "FF6700" + }, + [2] = { + id="ColorSecondary", + desc="Secondary HUD Color", + basec = "FFFFFF", + newc = "FFFFFF" + }, + [3] = { + id="ColorTertiary", + desc="Tertiary HUD Color", + basec = "000000", + newc = "000000" + }, + [4] = { + id="ColorHealthy", + desc="Color code for Healthy/Okay", + basec = "00FF00", + newc = "00FF00" + }, + [5] = { + id="ColorWarning", + desc="Color code for Damaged/Warning", + basec = "FFFF00", + newc = "FFFF00" + }, + [6] = { + id="ColorCritical", + desc="Color code for Broken/Critical", + basec = "FF0000", + newc = "FF0000" + }, + [7] = { + id="ColorBackground", + desc="Background Color", + basec = "000000", + newc = "000000" + }, + [8] = { + id="ColorBackgroundPattern", + desc="Background Pattern Color", + basec = "4F4F4F", + newc = "4F4F4F" + }, + [9] = { + id="ColorFuelAtmospheric", + desc="Color for Atmo Fuel/Elements", + basec = "004444", + newc = "004444" + }, + [10] = { + id="ColorFuelSpace", + desc="Color for Space Fuel/Elements", + basec = "444400", + newc = "444400" + }, + [11] = { + id="ColorFuelRocket", + desc="Color for Rocket Fuel/Elements", + basec = "440044", + newc = "440044" + } +} + + +--[[ 3. PROCESSING FUNCTIONS ]] + +function InitiateSlots() + for slot_name, slot in pairs(unit) do + if type(slot) == "table" and type(slot.export) == "table" and + slot.getElementClass then + local elementClass = slot.getElementClass():lower() + if elementClass: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 + elseif elementClass == 'databankunit' then + db = slot + elseif elementClass == "screenunit" then + local iScreenMode = "startup" + screens[#screens + 1] = { + element = slot, + id = slot.getId(), + mode = iScreenMode, + submode = "", + ClickAreas = {}, + refresh = true, + active = false, + fuelA = true, + fuelS = true, + fuelR = true, + fuelIndex = 1 + } + end + end + end +end + +function LoadFromDatabank() + if db == nil then + return + else + for _, data in pairs(SaveVars) do + if db.hasKey(data) then + local jData = json.decode( db.getStringValue(data) ) + if jData ~= nil then + if data == "YourShipsName" or data == "AddSummertimeHour" or data == "UpdateDataInterval" or data == "HighlightBlinkingInterval" or + data == "SkillRepairToolEfficiency" or data == "SkillRepairToolOptimization" or data == "SkillAtmosphericFuelEfficiency" or + data == "SkillSpaceFuelEfficiency" or data == "SkillRocketFuelEfficiency" or data == "StatAtmosphericFuelTankHandling" or + data == "StatSpaceFuelTankHandling" or data == "StatRocketFuelTankHandling" + then + -- Nada + else + _G[data] = jData + end + end + end + end + + for i,v in ipairs(screens) do + for j,dv in ipairs(dscreens) do + if screens[i].id == dscreens[j].id then + screens[i].mode = dscreens[j].mode + screens[i].submode = dscreens[j].submode + screens[i].active = dscreens[j].active + screens[i].refresh = true + screens[i].fuelA = dscreens[j].fuelA + screens[i].fuelS = dscreens[j].fuelS + screens[i].fuelR = dscreens[j].fuelR + screens[i].fuelIndex = dscreens[j].fuelIndex + end + end + end + end +end + +function SaveToDatabank() + if db == nil then + return + else + dscreens = {} + for i,screen in ipairs(screens) do + dscreens[i] = {} + dscreens[i].id = screen.id + dscreens[i].mode = screen.mode + dscreens[i].submode = screen.submode + dscreens[i].active = screen.active + dscreens[i].fuelA = screen.fuelA + dscreens[i].fuelS = screen.fuelS + dscreens[i].fuelR = screen.fuelR + dscreens[i].fuelIndex = screen.fuelIndex + end + + db.clear() + + for _, data in pairs(SaveVars) do + db.setStringValue(data, json.encode(_G[data])) + end + + end +end + +function InitiateScreens() + if screens ~= nil and #screens > 0 then + for i = 1, #screens, 1 do + screens[i] = CreateClickAreasForScreen(screens[i]) + end + end +end + +function UpdateTypeData() + FuelAtmosphericTanks = {} + FuelSpaceTanks = {} + FuelRocketTanks = {} + + FuelAtmosphericTotal = 0 + FuelAtmosphericCurrent = 0 + FuelSpaceTotal = 0 + FuelSpaceCurrent = 0 + FuelRocketCurrent = 0 + FuelRocketTotal = 0 + + local weightAtmosphericFuel = 4 + local weightSpaceFuel = 6 + local weightRocketFuel = 0.8 + + if StatFuelTankOptimization > 0 then + weightAtmosphericFuel = weightAtmosphericFuel - 0.09 * StatFuelTankOptimization * weightAtmosphericFuel + weightSpaceFuel = weightSpaceFuel - 0.09 * StatFuelTankOptimization * weightSpaceFuel + weightRocketFuel = weightRocketFuel - 0.09 * StatFuelTankOptimization * weightRocketFuel + end + + for i, id in ipairs(typeElements) do + local idName = core.getElementNameById(id) or "" + local idType = core.getElementTypeById(id) or "" + -- local idTypeClean = idType:gsub("[%s%-]+", ""):lower() + local idPos = core.getElementPositionById(id) or 0 + local idHP = core.getElementHitPointsById(id) or 0 + local idMaxHP = core.getElementMaxHitPointsById(id) or 0 + local idMass = core.getElementMassById(id) or 0 + + local baseSize = "" + local baseVol = 0 + local baseMass = 0 + local cMass = 0 + local cVol = 0 + + if idType == "atmospheric fuel-tank" then + if idMaxHP > 10000 then + baseSize = "L" + baseMass = 5480 + baseVol = 12800 + elseif idMaxHP > 1300 then + baseSize = "M" + baseMass = 988.67 + baseVol = 1600 + elseif idMaxHP > 150 then + baseSize = "S" + baseMass = 182.67 + baseVol = 400 + else + baseSize = "XS" + baseMass = 35.03 + baseVol = 100 + end + if StatAtmosphericFuelTankHandling > 0 then + baseVol = 0.2 * StatAtmosphericFuelTankHandling * baseVol + baseVol + end + cMass = idMass - baseMass + if cMass <=10 then cMass = 0 end + cVol = string.format("%.0f", cMass / weightAtmosphericFuel) + cPercent = string.format("%.1f", math.floor(100/baseVol * tonumber(cVol))) + table.insert(FuelAtmosphericTanks, { + type = 1, + id = id, + name = idName, + maxhp = idMaxHP, + hp = GetHPforElement(id), + pos = idPos, + size = baseSize, + mass = baseMass, + vol = baseVol, + cvol = cVol, + percent = cPercent + }) + if idHP > 0 then + FuelAtmosphericCurrent = FuelAtmosphericCurrent + cVol + end + FuelAtmosphericTotal = FuelAtmosphericTotal + baseVol + elseif idType == "space fuel-tank" then + if idMaxHP > 10000 then + baseSize = "L" + baseMass = 5480 + baseVol = 12800 + elseif idMaxHP > 1300 then + baseSize = "M" + baseMass = 988.67 + baseVol = 1600 + else + baseSize = "S" + baseMass = 182.67 + baseVol = 400 + end + if StatSpaceFuelTankHandling > 0 then + baseVol = 0.2 * StatSpaceFuelTankHandling * baseVol + baseVol + end + cMass = idMass - baseMass + if cMass <=10 then cMass = 0 end + cVol = string.format("%.0f", cMass / weightSpaceFuel) + cPercent = string.format("%.1f", (100/baseVol * tonumber(cVol))) + table.insert(FuelSpaceTanks, { + type = 2, + id = id, + name = idName, + maxhp = idMaxHP, + hp = GetHPforElement(id), + pos = idPos, + size = baseSize, + mass = baseMass, + vol = baseVol, + cvol = cVol, + percent = cPercent + }) + if idHP > 0 then + FuelSpaceCurrent = FuelSpaceCurrent + cVol + end + FuelSpaceTotal = FuelSpaceTotal + baseVol + elseif idType == "rocket fuel-tank" then + if idMaxHP > 65000 then + baseSize = "L" + baseMass = 25740 + baseVol = 50000 + elseif idMaxHP > 6000 then + baseSize = "M" + baseMass = 4720 + baseVol = 6400 + elseif idMaxHP > 700 then + baseSize = "S" + baseMass = 886.72 + baseVol = 800 + else + baseSize = "XS" + baseMass = 173.42 + baseVol = 400 + end + if StatRocketFuelTankHandling > 0 then + baseVol = 0.2 * StatRocketFuelTankHandling * baseVol + baseVol + end + cMass = idMass - baseMass + if cMass <=10 then cMass = 0 end + cVol = string.format("%.0f", cMass / weightRocketFuel) + cPercent = string.format("%.1f", (100/baseVol * tonumber(cVol))) + table.insert(FuelRocketTanks, { + type = 3, + id = id, + name = idName, + maxhp = idMaxHP, + hp = GetHPforElement(id), + pos = idPos, + size = baseSize, + mass = baseMass, + vol = baseVol, + cvol = cVol, + percent = cPercent + }) + if idHP > 0 then + FuelRocketCurrent = FuelRocketCurrent + cVol + end + FuelRocketTotal = FuelRocketTotal + baseVol + end + + end + + if FuelAtmosphericCurrent ~= formerFuelAtmosphericCurrent then + SetRefresh("fuel") + formerFuelAtmosphericCurrent = FuelAtmosphericCurrent + end + if FuelSpaceCurrent ~= formerFuelSpaceCurrent then + SetRefresh("fuel") + formerFuelSpaceCurrent = FuelSpaceCurrent + end + if FuelRocketCurrent ~= formerFuelRocketCurrent then + SetRefresh("fuel") + formerFuelRocketCurrent = FuelRocketCurrent + end + +end + +function UpdateDamageData(initial) + + initial = initial or false + + if SimulationActive == true then return end + + local formerTotalShipHP = totalShipHP + totalShipHP = 0 + totalShipMaxHP = 0 + totalShipIntegrity = 100 + damagedElements = {} + brokenElements = {} + healthyElements = {} + ElementCounter = 0 + + elementsIdList = core.getElementIdList() + + for i, id in pairs(elementsIdList) do + + ElementCounter = ElementCounter + 1 + + local idName = core.getElementNameById(id) + + local idType = core.getElementTypeById(id) + -- local idTypeClean = idType:gsub("[%s%-]+", ""):lower() + local idPos = core.getElementPositionById(id) + local idHP = core.getElementHitPointsById(id) + local idMaxHP = core.getElementMaxHitPointsById(id) + -- local idMass = core.getElementMassById(id) + + if SimulationMode == true then + SimulationActive = true + local dice = math.random(0, 10) + if dice < 2 and #brokenElements < 30 then + idHP = 0 + elseif dice >= 2 and dice < 4 and #damagedElements < 30 then + idHP = math.random(1, math.ceil(idMaxHP)) + else + idHP = idMaxHP + end + end + + totalShipHP = totalShipHP + idHP + totalShipMaxHP = totalShipMaxHP + idMaxHP + + if idMaxHP - idHP > constants.epsilon then + + 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 + }) + else + table.insert(brokenElements, { + id = id, + name = idName, + type = idType, + counter = ElementCounter, + hp = idHP, + maxhp = idMaxHP, + missinghp = idMaxHP - idHP, + percent = 0, + pos = idPos + }) + end + else + table.insert(healthyElements, { + id = id, + name = idName, + type = idType, + counter = ElementCounter, + hp = idHP, + maxhp = idMaxHP, + pos = idPos + }) + if id == highlightID then + highlightID = 0 + highlightOn = false + HideHighlight() + hudSelectedIndex = 0 + end + end + + if initial == true then + if + idType == "atmospheric fuel-tank" or + idType == "space fuel-tank" or + idType == "rocket fuel-tank" + then + table.insert(typeElements, id) + end + end + end + + SortDamageTables() + + rE = {} + if #brokenElements > 0 then + for _,v in ipairs(brokenElements) do + table.insert(rE, {id=v.id, missinghp=v.missinghp, hp=v.hp, name=v.name, type=v.type, pos=v.pos}) + end + end + if #damagedElements > 0 then + for _,v in ipairs(damagedElements) do + table.insert(rE, {id=v.id, missinghp=v.missinghp, hp=v.hp, name=v.name, type=v.type, pos=v.pos}) + end + end + if #rE > 0 then + table.sort(rE, function(a,b) return a.missinghp>b.missinghp end) + end + + totalShipIntegrity = string.format("%2.0f", 100 / totalShipMaxHP * totalShipHP) + + if formerTotalShipHP ~= totalShipHP then + forceDamageRedraw = true + formerTotalShipHP = totalShipHP + else + forceDamageRedraw = false + end +end + +function GetHPforElement(id) + for i,v in ipairs(brokenElements) do + if v.id == id then + return 0 + end + end + for i,v in ipairs(damagedElements) do + if v.id == id then + return v.hp + end + end + for i,v in ipairs(healthyElements) do + if v.id == id then + return v.maxhp + end + end +end + +function UpdateClickArea(candidate, newEntry, mode) + for i, screen in ipairs(screens) do + for k, v in pairs(screens[i].ClickAreas) do + if v.id == candidate and v.mode == mode then + screens[i].ClickAreas[k] = newEntry + end + end + end +end + +function AddClickArea(mode, newEntry) + for i, screen in ipairs(screens) do + if screens[i].mode == mode then + table.insert(screens[i].ClickAreas, newEntry) + end + end +end + +function AddClickAreaForScreenID(screenid, newEntry) + for i, screen in ipairs(screens) do + if screens[i].id == screenid then + table.insert(screens[i].ClickAreas, newEntry) + end + end +end + +function DisableClickArea(candidate, mode) + UpdateClickArea(candidate, { + id = candidate, + mode = mode, + x1 = -1, + x2 = -1, + y1 = -1, + y2 = -1 + }) +end + +function SetRefresh(mode, submode) + mode = mode or "all" + submode = submode or "all" + if screens ~= nil and #screens > 0 then + for i = 1, #screens, 1 do + if screens[i].mode == mode or mode == "all" then + if screens[i].submode == submode or submode =="all" then + screens[i].refresh = true + end + end + end + end +end + +function WipeClickAreasForScreen(screen) + screen.ClickAreas = {} + return screen +end + +function CreateBaseClickAreas(screen) + table.insert(screen.ClickAreas, {mode = "all", id = "ToggleHudMode", x1 = 1537, x2 = 1728, y1 = 1015, y2 = 1075} ) + table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "damage", x1 = 193, x2 = 384, y1 = 1015, y2 = 1075} ) + table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "damageoutline", x1 = 385, x2 = 576, y1 = 1015, y2 = 1075} ) + table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "fuel", x1 = 577, x2 = 768, y1 = 1015, y2 = 1075} ) + -- table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "flight", x1 = 769, x2 = 960, y1 = 1015, y2 = 1075} ) + -- table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "cargo", x1 = 961, x2 = 1152, y1 = 1015, y2 = 1075} ) + -- table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "agg", x1 = 1153, x2 = 1344, y1 = 1015, y2 = 1075} ) + -- table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "map", x1 = 1345, x2 = 1536, y1 = 1015, y2 = 1075} ) + table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "time", x1 = 0, x2 = 192, y1 = 1015, y2 = 1075} ) + table.insert(screen.ClickAreas, {mode = "all", id = "ButtonPress", param = "settings1", x1 = 1729, x2 = 1920, y1 = 1015, y2 = 1075} ) + return screen +end + +function CreateClickAreasForScreen(screen) + + if screen == nil then return {} end + + if screen.mode == "flight" then + elseif screen.mode == "damage" then + table.insert( screen.ClickAreas, {mode = "damage", id = "ToggleElementLabel", x1 = 70, x2 = 425, y1 = 325, y2 = 355} ) + table.insert( screen.ClickAreas, {mode = "damage", id = "ToggleElementLabel2", x1 = 980, x2 = 1400, y1 = 325, y2 = 355} ) + elseif screen.mode == "damageoutline" then + table.insert(screen.ClickAreas, {mode = "damageoutline", id = "DMGOChangeView", param = "top", x1 = 60, x2 = 439, y1 = 150, y2 = 200} ) + table.insert(screen.ClickAreas, {mode = "damageoutline", id = "DMGOChangeView", param = "side", x1 = 440, x2 = 824, y1 = 150, y2 = 200} ) + table.insert(screen.ClickAreas, {mode = "damageoutline", id = "DMGOChangeView", param = "front", x1 = 825, x2 = 1215, y1 = 150, y2 = 200} ) + table.insert(screen.ClickAreas, {mode = "damageoutline", id = "DMGOChangeStretch", x1 = 1530, x2 = 1580, y1 = 150, y2 = 200} ) + elseif screen.mode == "fuel" then + elseif screen.mode == "cargo" then + elseif screen.mode == "agg" then + elseif screen.mode == "map" then + elseif screen.mode == "time" then + elseif screen.mode == "settings1" then + table.insert( screen.ClickAreas, {mode = "settings1", id = "ToggleBackground", x1 = 75, x2 = 860, y1 = 170, y2 = 215} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "PreviousBackground", x1 = 75, x2 = 460, y1 = 235, y2 = 285} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "NextBackground", x1 = 480, x2 = 860, y1 = 235, y2 = 285} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "DecreaseOpacity", x1 = 75, x2 = 460, y1 = 300, y2 = 350} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "IncreaseOpacity", x1 = 480, x2 = 860, y1 = 300, y2 = 350} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ResetColors", x1 = 75, x2 = 860, y1 = 370, y2 = 415} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "PreviousColorID", x1 = 90, x2 = 140, y1 = 500, y2 = 550} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "NextColorID", x1 = 795, x2 = 845, y1 = 500, y2 = 550} ) + + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="1", x1 = 210, x2 = 290, y1 = 655, y2 = 700} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="2", x1 = 300, x2 = 380, y1 = 655, y2 = 700} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="3", x1 = 385, x2 = 465, y1 = 655, y2 = 700} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="4", x1 = 470, x2 = 550, y1 = 655, y2 = 700} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="5", x1 = 560, x2 = 640, y1 = 655, y2 = 700} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosUp", param="6", x1 = 645, x2 = 725, y1 = 655, y2 = 700} ) + + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="1", x1 = 210, x2 = 290, y1 = 740, y2 = 780} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="2", x1 = 300, x2 = 380, y1 = 740, y2 = 780} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="3", x1 = 385, x2 = 465, y1 = 740, y2 = 780} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="4", x1 = 470, x2 = 550, y1 = 740, y2 = 780} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="5", x1 = 560, x2 = 640, y1 = 740, y2 = 780} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ColorPosDown", param="6", x1 = 645, x2 = 725, y1 = 740, y2 = 780} ) + + table.insert( screen.ClickAreas, {mode = "settings1", id = "ResetPosColor", x1 = 160, x2 = 340, y1 = 885, y2 = 935} ) + table.insert( screen.ClickAreas, {mode = "settings1", id = "ApplyPosColor", x1 = 355, x2 = 780, y1 = 885, y2 = 935} ) + + elseif screen.mode == "startup" then + end + + screen = CreateBaseClickAreas(screen) + + return screen +end + +function CheckClick(x, y, HitTarget) + x = x*1920 + y = y*1120 + HitTarget = HitTarget or "" + HitPayload = {} + -- PrintConsole("Clicked: "..x.." / "..y) + if screens ~= nil and #screens > 0 then + for i = 1, #screens, 1 do + if screens[i].active == true and screens[i].element.getMouseX() ~= -1 and screens[i].element.getMouseY() ~= -1 then + if HitTarget == "" then + for k, v in pairs(screens[i].ClickAreas) do + if v ~=nil and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then + HitTarget = v.id + HitPayload = v + break + end + end + end + if HitTarget == "ButtonPress" then + if screens[i].mode == HitPayload.param then + screens[i].mode = "startup" + else + screens[i].mode = HitPayload.param + end + + if screens[i].mode == "damageoutline" then + if screens[i].submode == "" then + screens[i].submode = "top" + end + end + screens[i].refresh = true + screens[i].ClickAreas = {} + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "ToggleBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if BackgroundMode == "" then + BackgroundSelected = 1 + BackgroundMode = backgroundModes[BackgroundSelected] + else + BackgroundSelected = 1 + BackgroundMode = "" + end + for k, screen in pairs(screens) do + screens[k].refresh = true + end + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "PreviousBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if BackgroundMode == "" then + BackgroundSelected = 1 + BackgroundMode = backgroundModes[BackgroundSelected] + else + if BackgroundSelected <= 1 then + BackgroundSelected = #backgroundModes + else + BackgroundSelected = BackgroundSelected - 1 + end + BackgroundMode = backgroundModes[BackgroundSelected] + end + for k, screen in pairs(screens) do + screens[k].refresh = true + end + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "NextBackground" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if BackgroundMode == "" then + BackgroundSelected = 1 + BackgroundMode = backgroundModes[BackgroundSelected] + else + if BackgroundSelected >= #backgroundModes then + BackgroundSelected = 1 + else + BackgroundSelected = BackgroundSelected + 1 + end + BackgroundMode = backgroundModes[BackgroundSelected] + end + for k, screen in pairs(screens) do + screens[k].refresh = true + end + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "DecreaseOpacity" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if BackgroundModeOpacity>0.1 then + BackgroundModeOpacity = BackgroundModeOpacity - 0.05 + for k, screen in pairs(screens) do + screens[k].refresh = true + end + SaveToDatabank() + SetRefresh() + RenderScreens() + end + elseif HitTarget == "IncreaseOpacity" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if BackgroundModeOpacity<1.0 then + BackgroundModeOpacity = BackgroundModeOpacity + 0.05 + for k, screen in pairs(screens) do + screens[k].refresh = true + end + SaveToDatabank() + SetRefresh() + RenderScreens() + end + elseif HitTarget == "ResetColors" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + db.clear() + ColorPrimary = "FF6700" + ColorSecondary = "FFFFFF" + ColorTertiary = "000000" + ColorHealthy = "00FF00" + ColorWarning = "FFFF00" + ColorCritical = "FF0000" + ColorBackground = "000000" + ColorBackgroundPattern = "4f4f4f" + BackgroundMode = "deathstar" + BackgroundSelected = 1 + BackgroundModeOpacity = 0.25 + colorIDTable = { + [1] = { + id="ColorPrimary", + desc="Main HUD Color", + basec = "FF6700", + newc = "FF6700" + }, + [2] = { + id="ColorSecondary", + desc="Secondary HUD Color", + basec = "FFFFFF", + newc = "FFFFFF" + }, + [3] = { + id="ColorTertiary", + desc="Tertiary HUD Color", + basec = "000000", + newc = "000000" + }, + [4] = { + id="ColorHealthy", + desc="Color code for Healthy/Okay", + basec = "00FF00", + newc = "00FF00" + }, + [5] = { + id="ColorWarning", + desc="Color code for Damaged/Warning", + basec = "FFFF00", + newc = "FFFF00" + }, + [6] = { + id="ColorCritical", + desc="Color code for Broken/Critical", + basec = "FF0000", + newc = "FF0000" + }, + [7] = { + id="ColorBackground", + desc="Background Color", + basec = "000000", + newc = "000000" + }, + [8] = { + id="ColorBackgroundPattern", + desc="Background Pattern Color", + basec = "4F4F4F", + newc = "4F4F4F" + }, + [9] = { + id="ColorFuelAtmospheric", + desc="Color for Atmo Fuel/Elements", + basec = "004444", + newc = "004444" + }, + [10] = { + id="ColorFuelSpace", + desc="Color for Space Fuel/Elements", + basec = "444400", + newc = "444400" + }, + [11] = { + id="ColorFuelRocket", + desc="Color for Rocket Fuel/Elements", + basec = "440044", + newc = "440044" + } + } + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "PreviousColorID" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + colorIDIndex = colorIDIndex - 1 + if colorIDIndex < 1 then colorIDIndex = #colorIDTable end + SaveToDatabank() + SetRefresh("settings1") + RenderScreens("settings1") + elseif HitTarget == "NextColorID" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + colorIDIndex = colorIDIndex + 1 + if colorIDIndex > #colorIDTable then colorIDIndex = 1 end + SaveToDatabank() + SetRefresh("settings1") + RenderScreens("settings1") + elseif HitTarget == "ColorPosUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + local s = tonumber(string.sub(colorIDTable[colorIDIndex].newc, HitPayload.param, HitPayload.param),16) + s = s + 1 + if s > 15 then s = 0 end + colorIDTable[colorIDIndex].newc = replace_char(HitPayload.param, colorIDTable[colorIDIndex].newc, hexTable[s+1]) + SaveToDatabank() + SetRefresh("settings1") + RenderScreens("settings1") + elseif HitTarget == "ColorPosDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + local s = tonumber(string.sub(colorIDTable[colorIDIndex].newc, HitPayload.param, HitPayload.param),16) + s = s - 1 + if s < 0 then s = 15 end + colorIDTable[colorIDIndex].newc = replace_char(HitPayload.param, colorIDTable[colorIDIndex].newc, hexTable[s+1]) + SaveToDatabank() + SetRefresh("settings1") + RenderScreens("settings1") + elseif HitTarget == "ResetPosColor" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + colorIDTable[colorIDIndex].newc = colorIDTable[colorIDIndex].basec + _G[colorIDTable[colorIDIndex].id] = colorIDTable[colorIDIndex].basec + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "ApplyPosColor" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + _G[colorIDTable[colorIDIndex].id] = colorIDTable[colorIDIndex].newc + SaveToDatabank() + SetRefresh() + RenderScreens() + elseif HitTarget == "DamagedPageDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + CurrentDamagedPage = CurrentDamagedPage + 1 + if CurrentDamagedPage > math.ceil(#damagedElements / DamagePageSize) then + CurrentDamagedPage = math.ceil(#damagedElements / DamagePageSize) + end + HudDeselectElement() + SaveToDatabank() + SetRefresh("damage") + RenderScreens("damage") + elseif HitTarget == "DamagedPageUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + CurrentDamagedPage = CurrentDamagedPage - 1 + if CurrentDamagedPage < 1 then CurrentDamagedPage = 1 end + HudDeselectElement() + SaveToDatabank() + SetRefresh("damage") + RenderScreens("damage") + elseif HitTarget == "BrokenPageDown" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + CurrentBrokenPage = CurrentBrokenPage + 1 + if CurrentBrokenPage > math.ceil(#brokenElements / DamagePageSize) then + CurrentBrokenPage = math.ceil(#brokenElements / DamagePageSize) + end + HudDeselectElement() + SaveToDatabank() + SetRefresh("damage") + RenderScreens("damage") + elseif HitTarget == "BrokenPageUp" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + CurrentBrokenPage = CurrentBrokenPage - 1 + if CurrentBrokenPage < 1 then CurrentBrokenPage = 1 end + HudDeselectElement() + SaveToDatabank() + SetRefresh("damage") + RenderScreens("damage") + elseif HitTarget == "DMGOChangeView" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + screens[i].submode = HitPayload.param + UpdateViewDamageoutline(screens[i]) + SaveToDatabank() + SetRefresh("damageoutline", screens[i].submode) + RenderScreens("damageoutline", screens[i].submode) + elseif HitTarget == "DMGOChangeStretch" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if DMGOStretch == true then + DMGOStretch = false + else + DMGOStretch = true + end + UpdateViewDamageoutline(screens[i]) + SaveToDatabank() + SetRefresh("damageoutline") + RenderScreens("damageoutline") + elseif HitTarget == "ToggleDisplayAtmosphere" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if screens[i].fuelA == true then + screens[i].fuelA = false + else + screens[i].fuelA = true + end + screens[i].fuelIndex = 1 + SaveToDatabank() + SetRefresh("fuel") + RenderScreens("fuel") + elseif HitTarget == "ToggleDisplaySpace" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if screens[i].fuelS == true then + screens[i].fuelS = false + else + screens[i].fuelS = true + end + screens[i].fuelIndex = 1 + SaveToDatabank() + SetRefresh("fuel") + RenderScreens("fuel") + elseif HitTarget == "ToggleDisplayRocket" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if screens[i].fuelR == true then + screens[i].fuelR = false + else + screens[i].fuelR = true + end + screens[i].fuelIndex = 1 + SaveToDatabank() + SetRefresh("fuel") + RenderScreens("fuel") + elseif HitTarget == "DecreaseFuelIndex" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + screens[i].fuelIndex = screens[i].fuelIndex - 1 + if screens[i].fuelIndex < 1 then screens[i].fuelIndex = 1 end + SaveToDatabank() + SetRefresh("fuel") + RenderScreens("fuel") + elseif HitTarget == "IncreaseFuelIndex" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + screens[i].fuelIndex = screens[i].fuelIndex + 1 + SaveToDatabank() + SetRefresh("fuel") + RenderScreens("fuel") + elseif HitTarget == "ToggleHudMode" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if HUDMode == true then + HUDMode = false + forceDamageRedraw = true + HudDeselectElement() + SaveToDatabank() + SetRefresh() + RenderScreens() + else + HUDMode = true + forceDamageRedraw = true + HudDeselectElement() + SaveToDatabank() + SetRefresh() + RenderScreens() + end + elseif HitTarget == "ToggleSimulation" and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + CurrentDamagedPage = 1 + CurrentBrokenPage = 1 + if SimulationMode == true then + SimulationMode = false + SimulationActive = false + UpdateDamageData() + UpdateTypeData() + forceDamageRedraw = true + HudDeselectElement() + SetRefresh("damage") + SetRefresh("damageoutline") + SetRefresh("settings1") + SetRefresh("fuel") + SaveToDatabank() + RenderScreens() + else + SimulationMode = true + SimulationActive = false + UpdateDamageData() + UpdateTypeData() + forceDamageRedraw = true + HudDeselectElement() + SetRefresh("damage") + SetRefresh("damageoutline") + SetRefresh("settings1") + SetRefresh("fuel") + SaveToDatabank() + RenderScreens() + end + elseif (HitTarget == "ToggleElementLabel" or HitTarget == "ToggleElementLabel2") and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + if UseMyElementNames == true then + UseMyElementNames = false + SetRefresh("damage") + RenderScreens("damage") + else + UseMyElementNames = true + SetRefresh("damage") + RenderScreens("damage") + end + elseif (HitTarget == "SwitchScrapTier" or HitTarget == "SwitchScrapTier2") and (HitPayload.mode == screens[i].mode or HitPayload.mode == "all") then + ScrapTier = ScrapTier + 1 + if ScrapTier > 4 then ScrapTier = 1 end + SetRefresh("damage") + RenderScreens("damage") + end + + + end + end + end +end + +--[[ 4. RENDERING FUNCTIONS ]] + +function GetContentFlight() + local output = "" + output = output .. GetHeader("Flight Data Report") .. + [[ + + ]] + return output +end + +function GetContentDamage() + local output = "" + if SimulationMode == true then + output = output .. GetHeader("Damage Report (Simulated damage)") .. [[]] + else + output = output .. GetHeader("Damage Report") .. [[]] + end + output = output .. GetContentDamageScreen() + return output +end + +function GetContentDamageoutline(screen) + UpdateDataDamageoutline() + UpdateViewDamageoutline(screen) + local output = "" + output = output .. GetHeader("Damage Ship Outline Report") .. + GetDamageoutlineShip() .. + [[]] + + if screen.submode=="top" then + output = output .. + [[ + + Top View + + Side View + + Front View + ]] + elseif screen.submode=="side" then + output = output .. + [[ + + Top View + + Side View + + Front View + ]] + elseif screen.submode=="front" then + output = output .. + [[ + + Top View + + Side View + + Front View + ]] + else + end + output = output .. [[]]..#dmgoElements..[[ of ]]..ElementCounter..[[ shown]] + output = output .. [[]] + if DMGOStretch == true then + output = output .. [[]] + end + output = output .. [[Stretch both axis]] + return output +end + +function GetContentFuel(screen) + + if #FuelAtmosphericTanks < 1 and #FuelSpaceTanks < 1 and #FuelRocketTanks < 1 then return "" end + + local FuelTypes = 0 + local output = "" + local addHeadline = {} + + FuelDisplay = { screen.fuelA, screen.fuelS, screen.fuelR } + + if FuelDisplay[1] == true and #FuelAtmosphericTanks > 0 then + table.insert(addHeadline, "Atmospheric") + FuelTypes = FuelTypes + 1 + end + if FuelDisplay[2] == true and #FuelSpaceTanks > 0 then + table.insert(addHeadline, "Space") + FuelTypes = FuelTypes + 1 + end + if FuelDisplay[3] == true and #FuelRocketTanks > 0 then + table.insert(addHeadline, "Rocket") + FuelTypes = FuelTypes + 1 + end + + output = output .. GetHeader("Fuel Report ("..table.concat(addHeadline, ", ")..")") .. + [[ + ]] + + local totalH = 150 + local counter = 0 + local tOffset = 0 + + if FuelDisplay[1] == true and #FuelAtmosphericTanks > 0 then + + if FuelTypes == 1 then tOffset = 50 + elseif FuelTypes == 2 then tOffset = 6 + elseif FuelTypes == 3 then tOffset = 0 + end + + output = output .. [[ + + + + ]] + + output = output .. + [[]].. + GenerateCommaValue(FuelAtmosphericCurrent, true).. + [[ of ]]..GenerateCommaValue(FuelAtmosphericTotal, true).. + [[ | Total Atmospheric Fuel in ]]..#FuelAtmosphericTanks..[[ tank]]..(#FuelAtmosphericTanks==1 and "" or "s")..[[ (]]..math.floor(100/FuelAtmosphericTotal*FuelAtmosphericCurrent)..[[%)]] + counter = counter + 1 + end + + if FuelDisplay[2] == true and #FuelSpaceTanks > 0 then + + if FuelTypes == 1 then tOffset = 50 + elseif FuelTypes == 2 then tOffset = 6 + elseif FuelTypes == 3 then tOffset = 0 + end + + output = output .. [[ + + + + ]] + + output = output .. + [[]].. + GenerateCommaValue(FuelSpaceCurrent, true).. + [[ of ]]..GenerateCommaValue(FuelSpaceTotal, true).. + [[ | Total Space Fuel in ]]..#FuelSpaceTanks..[[ tank]]..(#FuelSpaceTanks==1 and "" or "s")..[[ (]]..math.floor(100/FuelSpaceTotal*FuelSpaceCurrent)..[[%)]] + counter = counter + 1 + end + + if FuelDisplay[3] == true and #FuelRocketTanks > 0 then + + if FuelTypes == 1 then tOffset = 50 + elseif FuelTypes == 2 then tOffset = 6 + elseif FuelTypes == 3 then tOffset = 0 + end + + output = output .. [[ + + + + ]] + + output = output .. + [[]].. + GenerateCommaValue(FuelRocketCurrent, true).. + [[ of ]]..GenerateCommaValue(FuelRocketTotal, true).. + [[ | Total Rocket Fuel in ]]..#FuelRocketTanks..[[ tank]]..(#FuelRocketTanks==1 and "" or "s")..[[ (]]..math.floor(100/FuelRocketTotal*FuelRocketCurrent)..[[%)]] + end + + output = output .. [[ + + + + ]] + + local DisplayTable = {} + if screen.fuelIndex == nil or screen.fuelIndex < 1 then + screen.fuelIndex = 1 + end + + if FuelDisplay[1] == true then + for _,v in ipairs(FuelAtmosphericTanks) do + table.insert(DisplayTable, v) + end + end + if FuelDisplay[2] == true then + for _,v in ipairs(FuelSpaceTanks) do + table.insert(DisplayTable, v) + end + end + if FuelDisplay[3] == true then + for _,v in ipairs(FuelRocketTanks) do + table.insert(DisplayTable, v) + end + end + + table.sort(DisplayTable, function(a,b) return a.type + + + ]] + if tank.hp == 0 then + output = output .. [[]] + elseif tank.maxhp - tank.hp > constants.epsilon then + output = output .. [[]] + else + output = output .. [[]] + end + if tank.hp == 0 then output = output .. [[]]..tank.size..[[]] + else output = output .. [[]]..tank.size..[[]] + end + + if tank.hp == 0 then + output = output .. [[Broken]] .. + [[0 of ]]..GenerateCommaValue(tank.vol)..[[]] + elseif tonumber(tank.percent) < 10 then + output = output .. [[]]..tank.percent..[[%]] .. + [[]]..GenerateCommaValue(tank.cvol)..[[ of ]]..GenerateCommaValue(tank.vol)..[[]] + elseif tonumber(tank.percent) < 30 then + output = output .. [[]]..tank.percent..[[%]] .. + [[]]..GenerateCommaValue(tank.cvol)..[[ of ]]..GenerateCommaValue(tank.vol)..[[]] + else output = + output .. [[]]..tank.percent..[[%]] .. + [[]]..GenerateCommaValue(tank.cvol)..[[ of ]]..GenerateCommaValue(tank.vol)..[[]] + end + + output = output ..[[]]..tank.name..[[]] + + output = output .. [[]] + + end + end + + + + if #FuelAtmosphericTanks > 0 then + output = output .. [[]] + if FuelDisplay[1] == true then + output = output .. [[]] + end + output = output .. [[ATM]] + AddClickAreaForScreenID(screen.id, {mode = "fuel", id = "ToggleDisplayAtmosphere", x1 = 50, x2 = 100, y1 = 270, y2 = 320} ) + end + + if #FuelSpaceTanks > 0 then + output = output .. [[]] + if FuelDisplay[2] == true then + output = output .. [[]] + end + output = output .. [[SPC]] + AddClickAreaForScreenID(screen.id, {mode = "fuel", id = "ToggleDisplaySpace", x1 = 200, x2 = 250, y1 = 270, y2 = 320} ) + end + + if #FuelRocketTanks > 0 then + output = output .. [[]] + if FuelDisplay[3] == true then + output = output .. [[]] + end + output = output .. [[RKT]] + AddClickAreaForScreenID(screen.id, {mode = "fuel", id = "ToggleDisplayRocket", x1 = 350, x2 = 400, y1 = 270, y2 = 320} ) + end + + if screen.fuelIndex > 1 then + output = output .. [[ + + + ]] + AddClickAreaForScreenID(screen.id, {mode = "fuel", id = "DecreaseFuelIndex", x1 = 1470, x2 = 1670, y1 = 270, y2 = 320} ) + end + + if screen.fuelIndex+cCounter-1 < #DisplayTable then + output = output .. [[ + + + ]] + AddClickAreaForScreenID(screen.id, {mode = "fuel", id = "IncreaseFuelIndex", x1 = 1680, x2 = 1880, y1 = 270, y2 = 320} ) + end + + if cCounter > 0 then + output = output .. [[]].. + #DisplayTable.. + [[ Tank]]..(#DisplayTable == 1 and "" or "s").. + [[ (Showing ]]..screen.fuelIndex..[[ to ]]..(screen.fuelIndex+cCounter-1)..[[)]] + end + + return output +end + +function GetContentCargo() + local output = "" + output = output .. GetHeader("Cargo Report") .. + [[ + + ]] + return output +end + +function GetContentAGG() + local output = "" + output = output .. GetHeader("Anti-Grav Control") .. + [[ + + ]] + return output +end + +function GetContentMap() + local output = "" + output = output .. GetHeader("Map Overview") .. + [[ + + ]] + return output +end + +function GetContentTime() + local output = "" + output = output .. GetHeader("Time") .. epochTime() + output = output .. + [[ + + + + + + + + + + + + + ]] + return output +end + +function GetContentSettings1() + local output = "" + output = output .. GetHeader("Settings") .. [[]] + if BackgroundMode=="" then + output = output ..[[Activate background]] + else + output = output ..[[Deactivate background (']]..BackgroundMode..[[', ]]..string.format("%.0f",BackgroundModeOpacity*100)..[[%)]] + end + output = output ..[[ + + Previous background + + Next background + + + Decrease Opacity + + Increase Opacity + ]] + + output = output .. + [[]] .. + [[Reset background and all colors]] + + output = output .. + [[]] .. + [[]] .. + [[]] .. + [[Select and change any of the ]]..#colorIDTable..[[ HUD colors]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]]..colorIDTable[colorIDIndex].desc..[[]] .. + [[]] .. + [[Current color]] .. + [[]] .. + + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + + [[#]] .. + + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,1,1)..[[]] .. + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,2,2)..[[]] .. + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,3,3)..[[]] .. + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,4,4)..[[]] .. + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,5,5)..[[]] .. + [[]] .. + [[]]..string.sub(colorIDTable[colorIDIndex].newc,6,6)..[[]] .. + + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + [[]] .. + + [[]] .. + [[]] .. + [[New color]] .. + [[]] .. + [[Apply new color]] .. + [[]] .. + [[Reset]] .. + [[]] + + output = output .. + [[]] .. + [[]] .. + [[]] .. + [[Explanation / Hints]] .. + [[Coming soon.]] + + + output = output .. [[]] + + if SimulationMode == true then + output = output .. [[Simulating Damage to elements]] + AddClickArea("settings1", { id = "ToggleSimulation", mode ="settings1", x1 = 940, x2 = 1850, y1 = 919, y2 = 969 }) + else + output = output .. [[Simulate Damage to elements]] + AddClickArea("settings1", { id = "ToggleSimulation", mode ="settings1", x1 = 940, x2 = 1850, y1 = 919, y2 = 969 }) + end + + return output +end + +function GetContentStartup() + local output = "" + output = output .. GetElementLogo(812, 380, "f", "f", "f") + if YourShipsName == "Enter here" then + output = output .. [[Spaceship ID ]]..ShipID..[[]] + else + output = output .. [[]]..YourShipsName..[[]] + end + if ShowWelcomeMessage == true then output = output .. [[Greetings, Commander ]]..PlayerName..[[.]] end + if #Warnings > 0 then + output = output .. [[Warning: ]]..(table.concat(Warnings, " "))..[[]] + end + output = output .. [[Damage Report v]]..VERSION..[[, by Scion Interstellar, DorianGray - Discord: Dorian Gray#2623. Under GNU Public License 3.0.]] + return output +end + +function RenderScreen(screen, contentToRender) + if contentToRender == nil then + PrintConsole("ERROR: contentToRender is nil.") + unit.exit() + end + + CreateClickAreasForScreen(screen) + + local output ="" + output = output .. [[ + + + ]] + + output = output .. contentToRender + + if screen.mode == "startup" then + output = output .. [[]] + else + output = output .. [[]] + end + + output = output .. [[ + + + + TIME + DMG + DMGO + FUEL]] + + --[[ + FUEL + FLGT + CRGO + AGG + MAP + ]] + + output = output .. [[ + HUD + SETS + + + + ]] .. + -- [[ + -- + ---]] .. + [[ + ]] + if HUDMode == true then + output = output .. [[ + + HUD + ]] + end + if screen.mode == "damage" then + output = output .. [[ + + DMG + ]] + elseif screen.mode == "damageoutline" then + output = output .. [[ + + DMGO + ]] + elseif screen.mode == "fuel" then + output = output .. [[ + + FUEL + ]] + elseif screen.mode == "flight" then + output = output .. [[ + + FLGT + ]] + elseif screen.mode == "cargo" then + output = output .. [[ + + CRGO + ]] + elseif screen.mode == "agg" then + output = output .. [[ + + AGG + ]] + elseif screen.mode == "map" then + output = output .. [[ + + MAP + ]] + elseif screen.mode == "time" then + output = output .. [[ + + TIME + ]] + elseif screen.mode == "settings1" then + output = output .. [[ + + SETS + ]] + end + output = output .. [[]] + output = output .. [[]] + + -- Center: + + -- + -- + -- + -- + + local outputLength = string.len(output) + -- PrintConsole("Render: "..screen.mode.." ("..outputLength.." chars)") + screen.element.setSVG(output) +end + +function RenderScreens(onlymode, onlysubmode) + + onlymode = onlymode or "all" + onlysubmode = onlysubmode or "all" + + if screens ~= nil and #screens > 0 then + + local contentFlight = "" + local contentDamage = "" + local contentDamageoutlineTop = "" + local contentDamageoutlineSide = "" + local contentDamageoutlineFront = "" + local contentFuel = "" + local contentCargo = "" + local contentAGG = "" + local contentMap = "" + local contentTime = "" + local contentSettings1 = "" + local contentStartup = "" + + for k,screen in pairs(screens) do + if screen.refresh == true then + local contentToRender = "" + + if screen.mode == "flight" and (onlymode =="flight" or onlymode =="all") then + if contentFlight == "" then contentFlight = GetContentFlight() end + contentToRender = contentFlight + elseif screen.mode == "damage" and (onlymode =="damage" or onlymode =="all") then + if contentDamage == "" then contentDamage = GetContentDamage() end + contentToRender = contentDamage + elseif screen.mode == "damageoutline" and (onlymode =="damageoutline" or onlymode =="all") then + if screen.submode == "" then + screen.submode = "top" + screens[k].submode = "top" + end + if screen.submode == "top" and (onlysubmode == "top" or onlysubmode == "all") then + if contentDamageoutlineTop == "" then contentDamageoutlineTop = GetContentDamageoutline(screen) end + contentToRender = contentDamageoutlineTop + end + if screen.submode == "side" and (onlysubmode == "side" or onlysubmode == "all") then + if contentDamageoutlineSide == "" then contentDamageoutlineSide = GetContentDamageoutline(screen) end + contentToRender = contentDamageoutlineSide + end + if screen.submode == "front" and (onlysubmode == "front" or onlysubmode == "all") then + if contentDamageoutlineFront == "" then contentDamageoutlineFront = GetContentDamageoutline(screen) end + contentToRender = contentDamageoutlineFront + end + elseif screen.mode == "fuel" and (onlymode =="fuel" or onlymode =="all") then + screen = WipeClickAreasForScreen(screens[k]) + contentToRender = GetContentFuel(screen) + elseif screen.mode == "cargo" and (onlymode =="cargo" or onlymode =="all") then + if contentCargo == "" then contentCargo = GetContentCargo() end + contentToRender = contentCargo + elseif screen.mode == "agg" and (onlymode =="agg" or onlymode =="all") then + if contentAGG == "" then contentAGG = GetContentAGG() end + contentToRender = contentAGG + elseif screen.mode == "map" and (onlymode =="map" or onlymode =="all") then + if contentMap == "" then contentMap = GetContentMap() end + contentToRender = contentMap + elseif screen.mode == "time" and (onlymode =="time" or onlymode =="all") then + if contentTime == "" then contentTime = GetContentTime() end + contentToRender = contentTime + elseif screen.mode == "settings1" and (onlymode =="settings1" or onlymode =="all") then + if contentSettings1 == "" then contentSettings1 = GetContentSettings1() end + contentToRender = contentSettings1 + elseif screen.mode == "startup" and (onlymode =="startup" or onlymode =="all") then + if contentStartup == "" then contentStartup = GetContentStartup() end + contentToRender = contentStartup + else + contentToRender = "Invalid screen mode. ('"..screen.mode.."')" + end + + if contentToRender ~= "" then + RenderScreen(screen, contentToRender) + else + DrawCenteredText("ERROR: No contentToRender delivered for "..screen.mode) + PrintConsole("ERROR: No contentToRender delivered for "..screen.mode) + unit.exit() + end + screens[k].refresh = false + end + end + end + + if HUDMode == true then + system.setScreen(GetContentDamageHUDOutput()) + system.showScreen(1) + else + system.showScreen(0) + end + +end + +function OnTickData(initial) + if formerTime + 60 < system.getTime() then + SetRefresh("time") + end + totalShipMass = core.getConstructMass() + if formerTotalShipMass ~= totalShipMass then + UpdateDamageData(true) + UpdateTypeData() + SetRefresh() + formerTotalShipMass = totalShipMass + else + UpdateDamageData(initial) + UpdateTypeData() + end + RenderScreens() +end + +--[[ 5. EXECUTION ]] + +unit.hide() +ClearConsole() +PrintConsole("DAMAGE REPORT v"..VERSION.." STARTED", true) +InitiateSlots() +LoadFromDatabank() +SwitchScreens("on") +InitiateScreens() + +if core == nil then + PrintConsole("ERROR: Connect the core to the programming board.") + unit.exit() +else + OperatorID = unit.getMasterPlayerId() + OperatorData = database.getPlayer(OperatorID) + PlayerName = OperatorData["name"] + ShipID = core.getConstructId() +end + +if db == nil then + table.insert(Warnings, "No databank connected, won't save/load settings.") +end + +if YourShipsName == "Enter here" then + table.insert(Warnings, "No ship name set in LUA settings.") +end + +if SkillRepairToolEfficiency == 0 and SkillRepairToolOptimization == 0 and StatFuelTankOptimization == 0 and + StatAtmosphericFuelTankHandling == 0 and StatSpaceFuelTankHandling == 0 and StatRocketFuelTankHandling ==0 then + table.insert(Warnings, "No talents/stats set in LUA settings.") +end + +if SkillRepairToolEfficiency < 0 or SkillRepairToolOptimization < 0 or StatFuelTankOptimization < 0 or + StatAtmosphericFuelTankHandling < 0 or StatSpaceFuelTankHandling < 0 or StatRocketFuelTankHandling < 0 or + SkillRepairToolEfficiency > 5 or SkillRepairToolOptimization > 5 or StatFuelTankOptimization > 5 or + StatAtmosphericFuelTankHandling > 5 or StatSpaceFuelTankHandling > 5 or StatRocketFuelTankHandling > 5 then + PrintConsole("ERROR: Talents/stats can only range from 0 to 5. Please set correctly in LUA settings and reactivate script.") + unit.exit() +end + +if screens == nil or #screens == 0 then + HUDMode = true + PrintConsole("Warning: No screens connected. Entering HUD mode only.") +end + +OnTickData(true) + +unit.setTimer('UpdateData', UpdateDataInterval) +unit.setTimer('UpdateHighlight', HighlightBlinkingInterval) \ No newline at end of file diff --git a/DamageReport_3_02.conf b/versions/DamageReport_3_02.conf similarity index 100% rename from DamageReport_3_02.conf rename to versions/DamageReport_3_02.conf