Advertisement
Guest User

Code-Istrolid

a guest
Nov 17th, 2019
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 70.99 KB | None | 0 0
  1. //DLC
  2. account.hasDLC = function(dlcName) { if (!dlcName) { return true; } return true;}; account.hasDLCBonus = function() { return true;}; account.DLCs['Paint Job'] = true;account.DLCs['Curves and Shadows'] = true;
  3.  
  4. //canJoinServer = () => true;
  5.  
  6. //GLASS EFFECT
  7. //www.istrolid.com/game.html?rootAddress=ws://108.172.118.65:8080
  8.  
  9. var myTheme = myTheme || {};
  10.  
  11. // Function to hook
  12. myTheme.hooks = myTheme.hooks || {
  13.     process: Interpolator.prototype.process,
  14.     drawSprite: Atlas.prototype.drawSprite
  15. };
  16. // Override functions
  17. Interpolator.prototype.process = function(data) {
  18.     var ret = myTheme.hooks.process.call(this, data);
  19.  
  20.  
  21.     mapping.themes[0] = {
  22.         spotColor: [0, 0, 0, 0],
  23.         fillColor: [0, 0, 0, 0],
  24.         rockColor: [0, 0, 0, 0]
  25.     };
  26.  
  27.     return ret;
  28. }
  29. // COPY SCRIPT
  30. BattleMode.prototype.copySelected = function(index) { var copy, spec, unit; if (commander.selection.length === 1) { unit = commander.selection[0]; spec = unit.spec; copy = new types.Unit(spec); buildBar.setSpec(index, copy.toSpec()); return control.savePlayer(); } };
  31. //Red Z COMMAND CIRCLE
  32. types.Unit.prototype.drawSelection = function () {
  33.             let alpha, angle, distance, i, j, len, order, orders, prev, results, target;
  34.             this.drawHPBar();
  35.             this.drawEnergyBar();
  36.             if (this.holdPosition) {
  37.                 baseAtlas.drawSprite("img/unitBar/rallyPoint.png", this.pos, [1, 1], 0, [255, 0, 0, 255]);
  38.             }
  39.             while (this.preOrders.length > 0 && this.preOrders[0].id < this.onOrderId) {
  40.                 this.preOrders.shift();
  41.             }
  42.             if (!battleMode.shiftOrder && battleMode.ordering) {
  43.                 return;
  44.             }
  45.             if (this.owner === commander.number) {
  46.                 prev = this.pos;
  47.                 orders = this.preOrders;
  48.                 results = [];
  49.                 for (i = j = 0, len = orders.length; j < len; i = ++j) {
  50.                     order = orders[i];
  51.                     if (order.type === "Move") {
  52.                         if (order.dest == null) {
  53.                             continue;
  54.                         }
  55.                         distance = v2.distance(order.dest, prev);
  56.                         if (i === 0 && distance < 255 + 10) {
  57.                             alpha = distance - 10;
  58.                         } else {
  59.                             alpha = 255;
  60.                         }
  61.                         angle = v2.angle(v2.sub(order.dest, prev, v2.create()));
  62.                         if (orders.length - 1 === i) {
  63.                             baseAtlas.drawSprite("img/arrow01.png", order.dest, [.9, .9], angle, [255, 255, 255, alpha]);
  64.                         } else {
  65.                             baseAtlas.drawSprite("img/arrow01.png", order.dest, [.8, .8], angle, [255, 255, 255, alpha]);
  66.                         }
  67.                         results.push(prev = order.dest);
  68.                     } else if (order.type === "Follow") {
  69.                         target = intp.things[order.targetId];
  70.                         if (target != null) {
  71.                             results.push(baseAtlas.drawSprite("img/unitBar/target.png", target.pos, [1, 1], 0, [255, 0, 0, 255]));
  72.                         } else {
  73.                             results.push(void 0);
  74.                         }
  75.                     } else {
  76.                         results.push(void 0);
  77.                     }
  78.                 }
  79.                 return results;
  80.             }
  81.         };
  82.  
  83. //SPAM AI
  84. //Powered by chenluo2006@gmail.com, made by KingKoncorde...
  85. if (window == top) {
  86.     window.addEventListener('keyup', doKeyPress, false);
  87. }
  88. counter = 1;
  89. change_colors = false;
  90. color_key = 65; //a
  91. toggle_key = 66; //b
  92. ai_key = 65; //a
  93. fleet_up = 38; //up arrow
  94. fleet_down = 40; //down arrow
  95. function randomInt(min, max) {
  96.     return Math.floor(Math.random() * (max - min)) + min;
  97. }
  98.  
  99. function colorChange() {
  100.    
  101. var aiBuildBar, aiName, col, fleetAis, i, row;
  102.         aiBuildBar = false;
  103.         fleetAis = commander.fleet.ais || {};
  104.         for (row in fleetAis) {
  105.           aiName = fleetAis[row];
  106.           if (name === aiName) {
  107.             aiBuildBar = [];
  108.             for (col = i = 0; i < 10; col = ++i) {
  109.               aiBuildBar.push(commander.fleet[row + "," + col]);
  110.             }
  111.             console.log("ai player from name", aiName, aiBuildBar);
  112.           }
  113.         }
  114.         if (!aiBuildBar) {
  115.           aiBuildBar = ais.all[name];
  116.         }
  117.         if (aiBuildBar) {
  118.           network.send("addAi", "His Sister", "beta", aiBuildBar);
  119.         }
  120. }
  121.  
  122. function colorChangee() {
  123.    
  124. var aiBuildBar, aiName, col, fleetAis, i, row;
  125.         aiBuildBar = false;
  126.         fleetAis = commander.fleet.ais || {};
  127.         for (row in fleetAis) {
  128.           aiName = fleetAis[row];
  129.           if (name === aiName) {
  130.             aiBuildBar = [];
  131.             for (col = i = 0; i < 10; col = ++i) {
  132.               aiBuildBar.push(commander.fleet[row + "," + col]);
  133.             }
  134.             console.log("ai player from name", aiName, aiBuildBar);
  135.           }
  136.         }
  137.         if (!aiBuildBar) {
  138.           aiBuildBar = ais.all[name];
  139.         }
  140.         if (aiBuildBar) {
  141.           network.send("addAi", "His Sister", "alpha", aiBuildBar);
  142.         }
  143. }
  144.  
  145. function recurse_colors() {
  146.     if (change_colors) {       
  147.         colorChange();     
  148.         setTimeout(recurse_colors, 1); 
  149.     }
  150. }
  151.  
  152. function recurse_colorss() {   
  153.     if (change_colors) {       
  154.         colorChangee();    
  155.         setTimeout(recurse_colorss, 1);
  156.     }
  157. }
  158.  
  159. function fleetLength() {
  160.     nrows = 6;
  161.     ref = commander.fleet;
  162.     for (k in ref) {
  163.         v = ref[k];
  164.         if (v) {
  165.             ref1 = k.split(","), r = ref1[0], c = ref1[1];
  166.             r = parseInt(r);
  167.             if (r + 4 > nrows) {
  168.                 nrows = r + 4;
  169.             }
  170.         }
  171.     }
  172.     return nrows;
  173. }
  174.  
  175. function doKeyPress(e) {
  176.     if (e.altKey) { //////////////////////////////////////////////////////////////////////////////////////////
  177.         if (e.keyCode == color_key) {  
  178.             change_colors = !change_colors;
  179.             if (change_colors) {       
  180.                 recurse_colorss();
  181.             }
  182.         } else if (e.keyCode == toggle_key) {  
  183.             change_colors = !change_colors;
  184.             if (change_colors) {       
  185.                 recurse_colors();
  186.             }
  187.         } else if (e.keyCode == ai_key) {
  188.             if (localStorage.useAi !== "true") {
  189.                 localStorage.useAi = "true";
  190.             } else {
  191.                 localStorage.useAi = "false";
  192.                 designMode.aiEdit = false;
  193.             }
  194.         } else if (e.keyCode == fleet_up) {
  195.             if ((commander.fleet.selection || 0) <= 0) {
  196.                 commander.fleet.selection = fleetLength();
  197.             }
  198.             commander.fleet.selection--;
  199.             account.save();
  200.         } else if (e.keyCode == fleet_down) {
  201.             if (!commander.fleet.selection || commander.fleet.selection >= fleetLength() - 1) {
  202.                 commander.fleet.selection = 0;
  203.             }
  204.             commander.fleet.selection++;
  205.             account.save();
  206.         }
  207.     }
  208. }
  209.  
  210.  
  211.  
  212. //More ship info
  213.     Turret.prototype.rawReloadTime = undefined;
  214.     Turret.prototype.getRawReloadTime = function() {
  215.       if (!this.rawReloadTime)
  216.         return this.reloadTime;
  217.       return this.rawReloadTime;
  218.     };
  219.  
  220.     Turret.prototype.applyBuffs = function() {
  221.       this.range *= this.weaponRange;
  222.       this.range += this.weaponRangeFlat;
  223.       this.damage *= this.weaponDamage;
  224.       this.energyDamage *= this.weaponDamage;
  225.       this.bulletSpeed *= this.weaponSpeed;
  226.       this.reloadTime *= this.weaponReload;
  227.       this.shotEnergy *= this.weaponEnergy;
  228.       this.rawReloadTime = this.reloadTime;
  229.       this.reloadTime = Math.ceil(this.reloadTime);
  230.       this.fireEnergy = this.shotEnergy / this.reloadTime;
  231.       return this.dps = this.damage / this.reloadTime;
  232.     };
  233.  
  234.  
  235.  
  236.  
  237. //from src/design.js
  238. // Generated by CoffeeScript 1.10.0
  239. (function() {
  240.   var NxN, SIZE, aiEditScreen, backToGalaxyButton, cell, divider, dragWhite, drawAddRule, drawAiParts, drawPart, drawParts, drawRule, drawRuleDD, drawRuleNumber, drawTab, editorButtons, finishDesignButton, has, hoverInfo, hoverTip, isBuildRule, lockScreen, partThumb, partThumbCache, powerBar, shareBox, smallTip, unitInfo, weaponInfo, white,
  241.     bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  242.  
  243.   eval(onecup["import"]());
  244.  
  245.   NxN = 24;
  246.  
  247.   SIZE = 20;
  248.  
  249.   white = [255, 255, 255, 255];
  250.  
  251.   dragWhite = [255, 255, 255, 200];
  252.  
  253.   window.DesignMode = (function() {
  254.     DesignMode.prototype.tab = "weapons";
  255.  
  256.     DesignMode.prototype.hoverOverPart = null;
  257.  
  258.     DesignMode.prototype.draggingPart = null;
  259.  
  260.     DesignMode.prototype.draggingPart2 = null;
  261.  
  262.     DesignMode.prototype.hoverTipPart = null;
  263.  
  264.     DesignMode.prototype.wiggle = 0;
  265.  
  266.     DesignMode.prototype.aiEdit = false;
  267.  
  268.     DesignMode.prototype.showAiTools = true;
  269.  
  270.     DesignMode.prototype.locked = false;
  271.  
  272.     function DesignMode() {
  273.       this.draw = bind(this.draw, this);
  274.       var badParts, ref;
  275.       this.zoom = .5;
  276.       this.focus = v2.create();
  277.       this.draggingPart = null;
  278.       this.draggingPart2 = null;
  279.       this.mouse = [0, 0];
  280.       this.pos = [0, 0];
  281.       this.unit = new types.Unit("{}");
  282.       this.dragUnit = new types.Unit("{}");
  283.       ref = computeGrid(commander, this.unit), this.grid = ref[0], badParts = ref[1];
  284.       this.fresh = true;
  285.     }
  286.  
  287.     DesignMode.prototype.fromSpec = function(spec) {
  288.       this.unit = new types.Unit(spec);
  289.       return this.refresh();
  290.     };
  291.  
  292.     DesignMode.prototype.clear = function() {
  293.       this.unit = new types.Unit("{}");
  294.       buildBar.setSpec(buildBar.selected, "");
  295.       control.savePlayer();
  296.       return this.refresh();
  297.     };
  298.  
  299.     DesignMode.prototype.partSpec = function() {
  300.       return this.unit.toSpec();
  301.     };
  302.  
  303.     DesignMode.prototype.toGameSpace = function(point) {
  304.       point[0] = point[0] - window.innerWidth / 2;
  305.       point[1] = (window.innerHeight - point[1]) - window.innerHeight / 2;
  306.       v2.scale(point, this.zoom * 2);
  307.       v2.sub(point, this.focus);
  308.       return point;
  309.     };
  310.  
  311.     DesignMode.prototype.rotatePart = function(part, way) {
  312.       if (way == null) {
  313.         way = 1;
  314.       }
  315.       if (account.hasDLCBonus()) {
  316.         if (part.canRotate) {
  317.           part.dir = (4 + part.dir + way) % 4;
  318.         } else {
  319.           this.wiggle = 10 * way;
  320.         }
  321.       } else {
  322.         this.wiggle = 10 * way;
  323.         part.dir = 0;
  324.       }
  325.       return part;
  326.     };
  327.  
  328.     DesignMode.prototype.shiftShip = function(shift) {
  329.       var j, len, p, ref;
  330.       ref = this.unit.parts;
  331.       for (j = 0, len = ref.length; j < len; j++) {
  332.         p = ref[j];
  333.         v2.add(p.pos, shift);
  334.       }
  335.       this.save();
  336.       return this.refresh();
  337.     };
  338.  
  339.     DesignMode.prototype.onkeyup = function(e) {
  340.       if (this.draggingPart) {
  341.         if (settings.key(e, "Zoom In")) {
  342.           this.draggingPart = this.rotatePart(this.draggingPart, 1);
  343.         }
  344.         if (settings.key(e, "Zoom Out")) {
  345.           return this.draggingPart = this.rotatePart(this.draggingPart, -1);
  346.         }
  347.       } else if (document.activeElement === document.body) {
  348.         if (!this.disabledEditing()) {
  349.           if (settings.key(e, "Up")) {
  350.             this.shiftShip([0, SIZE]);
  351.           }
  352.           if (settings.key(e, "Down")) {
  353.             this.shiftShip([0, -SIZE]);
  354.           }
  355.           if (settings.key(e, "Left")) {
  356.             this.shiftShip([-SIZE, 0]);
  357.           }
  358.           if (settings.key(e, "Right")) {
  359.             return this.shiftShip([SIZE, 0]);
  360.           }
  361.         }
  362.       }
  363.     };
  364.  
  365.     DesignMode.prototype.onmousemove = function(e) {
  366.       var b, x, y;
  367.       this.mouse = this.toGameSpace([e.clientX, e.clientY]);
  368.       this.uiMouse = [e.clientX, e.clientY];
  369.       if (designMode.smallTipBounds) {
  370.         b = designMode.smallTipBounds;
  371.         x = this.uiMouse[0];
  372.         y = this.uiMouse[1];
  373.         if (x < b.left || x > b.right || y < b.top || y > b.bottom) {
  374.           designMode.smallTipBounds = null;
  375.           return designMode.smallTip = null;
  376.         }
  377.       }
  378.     };
  379.  
  380.     DesignMode.prototype.disabledEditing = function() {
  381.       return designMode.aiEdit || designMode.locked || designMode.showShareBox;
  382.     };
  383.  
  384.     DesignMode.prototype.onmousedown = function(e) {
  385.       var className, j, len, p, part, ref, ref1, ref2, symmetryPos;
  386.       if (this.disabledEditing()) {
  387.         return;
  388.       }
  389.       if (e.which === 3 && this.draggingPart) {
  390.         this.draggingPart = this.rotatePart(this.draggingPart);
  391.         return;
  392.       }
  393.       if (this.draggingPart) {
  394.         return;
  395.       }
  396.       if (this.hoverOverPart) {
  397.         if (e.shiftKey) {
  398.           className = this.hoverOverPart.constructor.name;
  399.           this.draggingPart = new parts[className]();
  400.           this.draggingPart.pos = v2.create(this.hoverOverPart.pos);
  401.           this.draggingPart.dir = this.hoverOverPart.dir;
  402.           this.dragUnit.parts = [this.draggingPart];
  403.           this.draggingPart.unit = this.dragUnit;
  404.           return;
  405.         } else {
  406.           this.draggingPart = this.hoverOverPart;
  407.           this.dragUnit.parts = [this.draggingPart];
  408.           if (this.symmetryMode) {
  409.             symmetryPos = v2.create(this.draggingPart.pos);
  410.             symmetryPos[0] *= -1;
  411.             ref = this.unit.parts;
  412.             for (j = 0, len = ref.length; j < len; j++) {
  413.               part = ref[j];
  414.               if (v2.distance(part.pos, symmetryPos) < .1 && part.constructor.name === this.draggingPart.constructor.name && part !== this.draggingPart) {
  415.                 this.draggingPart2 = part;
  416.                 this.dragUnit.parts.push(this.draggingPart2);
  417.                 break;
  418.               }
  419.             }
  420.           }
  421.           this.unit.parts = (function() {
  422.             var l, len1, ref1, results;
  423.             ref1 = this.unit.parts;
  424.             results = [];
  425.             for (l = 0, len1 = ref1.length; l < len1; l++) {
  426.               p = ref1[l];
  427.               if (p !== this.draggingPart && p !== this.draggingPart2) {
  428.                 results.push(p);
  429.               }
  430.             }
  431.             return results;
  432.           }).call(this);
  433.           if (e.altKey && !((ref1 = sim.galaxyStar) != null ? ref1.noDesignTools : void 0)) {
  434.             this.draggingPart = null;
  435.             this.draggingPart2 = null;
  436.             this.dragUnit.parts = [];
  437.             this.save();
  438.             return;
  439.           }
  440.         }
  441.         e.preventDefault();
  442.       }
  443.       if (((ref2 = sim.galaxyStar) != null ? ref2.noDesignTools : void 0) === true) {
  444.         onecup.refresh();
  445.       }
  446.       return this.save();
  447.     };
  448.  
  449.     DesignMode.prototype.onmouseup = function(e) {
  450.       var placePart, ref;
  451.       if (e.which === 3 && this.draggingPart) {
  452.         return;
  453.       }
  454.       if (this.draggingPart) {
  455.         if (Math.abs(this.pos[0]) < NxN * 10 && Math.abs(this.pos[1]) < NxN * 10) {
  456.           placePart = (function(_this) {
  457.             return function(part) {
  458.               var p, ref;
  459.               part.pos = v2.create(part.pos);
  460.               if (!((ref = sim.galaxyStar) != null ? ref.noDesignTools : void 0)) {
  461.                 _this.unit.parts = (function() {
  462.                   var j, len, ref1, results;
  463.                   ref1 = this.unit.parts;
  464.                   results = [];
  465.                   for (j = 0, len = ref1.length; j < len; j++) {
  466.                     p = ref1[j];
  467.                     if (v2.distance(part.pos, p.pos) < .1 && part.constructor.name === p.constructor.name) {
  468.                       continue;
  469.                     }
  470.                     results.push(p);
  471.                   }
  472.                   return results;
  473.                 }).call(_this);
  474.               }
  475.               _this.unit.parts.push(part);
  476.               return part.unit = _this.unit;
  477.             };
  478.           })(this);
  479.           placePart(this.draggingPart);
  480.           if (this.symmetryMode && this.draggingPart2) {
  481.             placePart(this.draggingPart2);
  482.           }
  483.           playSound("sounds/ui/flick.wav");
  484.         } else {
  485.           if (((ref = sim.galaxyStar) != null ? ref.noDesignTools : void 0) === true) {
  486.             onecup.refresh();
  487.             return;
  488.           }
  489.           playSound("sounds/ui/shake.wav");
  490.         }
  491.         this.refresh();
  492.         this.save();
  493.         this.draggingPart = null;
  494.         this.dragUnit.parts = [];
  495.         e.preventDefault();
  496.         return onecup.refresh();
  497.       }
  498.     };
  499.  
  500.     DesignMode.prototype.refresh = function() {
  501.       this.refreshGrid();
  502.       return onecup.refresh();
  503.     };
  504.  
  505.     DesignMode.prototype.onbuildclick = function(e, index) {
  506.       return this.select(index);
  507.     };
  508.  
  509.     DesignMode.prototype.select = function(index) {
  510.       buildBar.selected = index;
  511.       this.fromSpec(commander.buildBar[index]);
  512.       return this.refresh();
  513.     };
  514.  
  515.     DesignMode.prototype.save = function() {
  516.       var spec;
  517.       spec = this.partSpec();
  518.       if (commander.side === "spectators") {
  519.         commander.validBar[buildBar.selected] = validSpec(commander, spec);
  520.       }
  521.       buildBar.setSpec(buildBar.selected, spec);
  522.       return control.savePlayer();
  523.     };
  524.  
  525.     DesignMode.prototype.tick = function() {};
  526.  
  527.     DesignMode.prototype.refreshGrid = function() {
  528.       var badPart, badParts, j, len, p, partScore, ref;
  529.       partScore = function(part) {
  530.         if (part.damage) {
  531.           return 1000 + part.damage;
  532.         } else if (part.decal) {
  533.           return 100;
  534.         } else {
  535.           return 0;
  536.         }
  537.       };
  538.       this.unit.parts.sort(function(a, b) {
  539.         return partScore(a) - partScore(b);
  540.       });
  541.       ref = computeGrid(commander, this.unit), this.grid = ref[0], badParts = ref[1];
  542.       if (badParts) {
  543.         for (j = 0, len = badParts.length; j < len; j++) {
  544.           badPart = badParts[j];
  545.           this.unit.parts = (function() {
  546.             var l, len1, ref1, results;
  547.             ref1 = this.unit.parts;
  548.             results = [];
  549.             for (l = 0, len1 = ref1.length; l < len1; l++) {
  550.               p = ref1[l];
  551.               if (p !== badPart) {
  552.                 results.push(p);
  553.               }
  554.             }
  555.             return results;
  556.           }).call(this);
  557.         }
  558.         return onecup.refresh();
  559.       }
  560.     };
  561.  
  562.     DesignMode.prototype.warpIn = 0;
  563.  
  564.     DesignMode.prototype.draw = function() {
  565.       var adjustAndDrawUnit, bg_zoom, className, color, flip, hoverOverPart, j, l, len, len1, len2, m, part, partNum, ref, ref1, ref2, row, s, size, t, th, tip, x, xoff, y, yoff, z;
  566.       if (designMode.locked) {
  567.         this.draggingPart = null;
  568.         this.hoverOverPart = null;
  569.       }
  570.       baseAtlas.beginSprites(this.focus, this.zoom);
  571.       if (this.fresh) {
  572.         this.select(buildBar.selected);
  573.         this.fresh = false;
  574.       }
  575.       color = commander.color;
  576.       bg_zoom = Math.max(window.innerWidth, window.innerHeight) / 128;
  577.       z = bg_zoom * this.zoom;
  578.       baseAtlas.drawSprite("img/newbg/fill.png", [-this.focus[0], -this.focus[1]], [z, z], 0, mapping.themes[0].fillColor);
  579.       baseAtlas.drawSprite("img/newbg/gradient.png", [-this.focus[0], -this.focus[1]], [z, z], 0, mapping.themes[0].spotColor);
  580.       hoverOverPart = null;
  581.       ref = this.unit.parts;
  582.       for (partNum = j = 0, len = ref.length; j < len; partNum = ++j) {
  583.         part = ref[partNum];
  584.         part.working = true;
  585.         size = part.flippedSize();
  586.         x = Math.abs(part.pos[0] - this.mouse[0]) < size[0] / 2 * SIZE;
  587.         y = Math.abs(part.pos[1] - this.mouse[1]) < size[1] / 2 * SIZE;
  588.         if (x && y) {
  589.           hoverOverPart = part;
  590.         }
  591.       }
  592.       if (this.hoverOverPart !== hoverOverPart) {
  593.         this.hoverOverPart = hoverOverPart;
  594.         if (hoverOverPart !== null) {
  595.           this.hoverTipPart = hoverOverPart;
  596.         }
  597.         onecup.refresh();
  598.       }
  599.       adjustAndDrawUnit = function(unit) {
  600.         var l, len1, ref1, weapon;
  601.         unit.rot = Math.PI;
  602.         ref1 = unit.weapons;
  603.         for (l = 0, len1 = ref1.length; l < len1; l++) {
  604.           weapon = ref1[l];
  605.           weapon.rot = Math.PI;
  606.         }
  607.         unit.computeCenter();
  608.         unit.pos[0] = unit.center[0];
  609.         unit.pos[1] = unit.center[1];
  610.         unit.warpIn = 1;
  611.         unit.shield = unit.maxShield;
  612.         unit.jump = 40;
  613.         unit.color = commander.color;
  614.         return unit.draw();
  615.       };
  616.       adjustAndDrawUnit(this.unit);
  617.       adjustAndDrawUnit(this.dragUnit);
  618.       if (ui.show) {
  619.         ref1 = this.grid;
  620.         for (x = l = 0, len1 = ref1.length; l < len1; x = ++l) {
  621.           row = ref1[x];
  622.           for (y = m = 0, len2 = row.length; m < len2; y = ++m) {
  623.             t = row[y];
  624.             if (t.bad) {
  625.               color = [255, 0, 0, 80 + Math.sin(Date.now() / 300) * 80];
  626.             } else if (t.exhaust) {
  627.               color = [255, 255, 255, 65];
  628.             } else if (t.attach && !t.solid) {
  629.               color = [0, 255, 0, 35];
  630.             } else if (t.solid) {
  631.               continue;
  632.             } else if ((NxN / 2 - 1 <= x && x <= NxN / 2) && (NxN / 2 - 1 <= y && y <= NxN / 2)) {
  633.               color = [0, 0, 0, 50];
  634.             } else {
  635.               color = [0, 0, 0, 25];
  636.             }
  637.             baseAtlas.drawSprite("parts/sel1x1.png", [(x - NxN / 2) * SIZE + SIZE / 2, (y - NxN / 2) * SIZE + SIZE / 2], [.8, .8], 0, color);
  638.           }
  639.         }
  640.       }
  641.       if (this.draggingPart) {
  642.         this.draggingPart.rot = Math.PI;
  643.         this.draggingPart.working = true;
  644.         if (this.mouse[0] < 0 && this.draggingPart.flip) {
  645.           flip = -1;
  646.         } else {
  647.           flip = 1;
  648.         }
  649.         s = SIZE;
  650.         if (this.draggingPart.size[0] % 2 === 1) {
  651.           xoff = .5 * s;
  652.         } else {
  653.           xoff = 0;
  654.         }
  655.         if (this.draggingPart.size[1] % 2 === 1) {
  656.           yoff = .5 * s;
  657.         } else {
  658.           yoff = 0;
  659.         }
  660.         if (this.draggingPart.dir % 2 === 1) {
  661.           ref2 = [yoff, xoff], xoff = ref2[0], yoff = ref2[1];
  662.         }
  663.         this.pos = [Math.floor(this.mouse[0] / s) * s + xoff, Math.floor(this.mouse[1] / s) * s + yoff];
  664.         this.wiggle *= .9;
  665.         th = Math.sin(this.wiggle / 50);
  666.         v2.set(this.pos, this.draggingPart.worldPos);
  667.         v2.set(this.pos, this.draggingPart.pos);
  668.         if (this.draggingPart.adjacent) {
  669.           s = 35 / 255;
  670.           baseAtlas.drawSprite("img/point02.png", [this.pos[0], this.pos[1]], [s, s], 0, white);
  671.         }
  672.       }
  673.       if (designMode.symmetryMode) {
  674.         if (this.draggingPart && !this.draggingPart2) {
  675.           className = this.draggingPart.constructor.name;
  676.           this.draggingPart2 = new parts[className]();
  677.           this.draggingPart2.unit = this.dragUnit;
  678.           this.dragUnit.parts.push(this.draggingPart2);
  679.         }
  680.         if (this.draggingPart && this.draggingPart2) {
  681.           v2.set(this.draggingPart.worldPos, this.draggingPart2.worldPos);
  682.           v2.set(this.draggingPart.pos, this.draggingPart2.pos);
  683.           this.draggingPart2.worldPos[0] *= -1;
  684.           this.draggingPart2.pos[0] *= -1;
  685.           this.draggingPart2.rot = this.draggingPart.rot;
  686.           this.draggingPart2.working = this.draggingPart.working;
  687.           if (this.draggingPart.noFlip) {
  688.             this.draggingPart2.dir = (1 + this.draggingPart.dir) % 4;
  689.           } else {
  690.             this.draggingPart2.dir = (4 - this.draggingPart.dir) % 4;
  691.           }
  692.         }
  693.         if (!this.draggingPart && this.draggingPart2) {
  694.           this.dragUnit.parts = [];
  695.           this.draggingPart2 = null;
  696.         }
  697.       }
  698.       baseAtlas.finishSprites();
  699.       tip = onecup.lookup("#smalltip");
  700.       if ((tip != null) && designMode.uiMouse) {
  701.         x = designMode.uiMouse[0];
  702.         y = designMode.uiMouse[1];
  703.         if (!this.smallTip) {
  704.           x = -1000;
  705.           y = -1000;
  706.         }
  707.         if (x > window.innerWidth - 400) {
  708.           x -= 10;
  709.           tip.style.left = null;
  710.           tip.style.right = (window.innerWidth - x) + "px";
  711.         } else {
  712.           x += 20;
  713.           tip.style.left = x + "px";
  714.           tip.style.right = null;
  715.         }
  716.         return tip.style.top = (y + 10) + "px";
  717.       }
  718.     };
  719.  
  720.     return DesignMode;
  721.  
  722.   })();
  723.  
  724.   partThumbCache = {};
  725.  
  726.   partThumb = function(part) {
  727.     var imageDataUrl, k, scale;
  728.     k = part.prototype.constructor.name + commander.color;
  729.     if (!partThumbCache[k]) {
  730.       baseAtlas.startOffscreenFrame();
  731.       scale = .5 * part.prototype.scale;
  732.       if (part.prototype.size[0] === 4 || part.prototype.size[1] === 4) {
  733.         scale *= 1.5;
  734.       }
  735.       baseAtlas.beginSprites([0, 0], scale, [0, 0, -baseAtlas.rtt.width, baseAtlas.rtt.height]);
  736.       if (part.prototype.stripe) {
  737.         baseAtlas.drawSprite("parts/gray-" + part.prototype.image, [0, 0], [-1, 1], 0, white);
  738.         baseAtlas.drawSprite("parts/red-" + part.prototype.image, [0, 0], [-1, 1], 0, commander.color);
  739.       } else if (part.prototype.decal) {
  740.         baseAtlas.drawSprite("parts/" + part.prototype.image, [0, 0], [-1, 1], 0, commander.color);
  741.       } else {
  742.         baseAtlas.drawSprite("parts/" + part.prototype.image, [0, 0], [-1, 1], 0, white);
  743.       }
  744.       baseAtlas.finishSprites(false);
  745.       imageDataUrl = baseAtlas.endOffscreenFrame();
  746.       partThumbCache[k] = imageDataUrl;
  747.       return imageDataUrl;
  748.     }
  749.     return partThumbCache[k];
  750.   };
  751.  
  752.   hoverTip = function(message) {
  753.     return onmouseover(function(e) {
  754.       designMode.smallTipBounds = e.target.getBoundingClientRect();
  755.       return designMode.smallTip = message;
  756.     });
  757.   };
  758.  
  759.   window.editorUI = function() {
  760.     var ref;
  761.     if (designMode.unit.spec !== commander.buildBar[buildBar.selected]) {
  762.       designMode.unit = new types.Unit(commander.buildBar[buildBar.selected]);
  763.       buildBar.setSpec(buildBar.selected, designMode.partSpec());
  764.       designMode.refreshGrid();
  765.     }
  766.     if (!designMode.unit) {
  767.       designMode.select(buildBar.selected);
  768.       designMode.fresh = false;
  769.     }
  770.     if (sim.galaxyStar && commander.galaxyDifficulty !== "captain" && commander.galaxyDifficulty !== "admiral") {
  771.       designMode.aiEdit = false;
  772.       designMode.showAiTools = false;
  773.     } else {
  774.       designMode.showAiTools = true;
  775.     }
  776.     if (((ref = sim.galaxyStar) != null ? ref.noDesignTools : void 0) === true) {
  777.       issueInfo();
  778.       finishDesignButton();
  779.       backToGalaxyButton();
  780.       return;
  781.     }
  782.     if (!ui.chatToggle) {
  783.       unitInfo();
  784.       editorButtons();
  785.     }
  786.     buildBar.draw();
  787.     hoverInfo();
  788.     issueInfo();
  789.     if (designMode.aiEdit) {
  790.       aiEditScreen();
  791.       drawAiParts();
  792.     } else {
  793.       drawParts();
  794.     }
  795.     smallTip();
  796.     if (designMode.showShareBox) {
  797.       shareBox();
  798.     }
  799.     if (designMode.locked) {
  800.       return lockScreen();
  801.     }
  802.   };
  803.  
  804.   shareBox = function() {
  805.     return textarea(function() {
  806.       position("absolute");
  807.       top(innerHeight / 2 - 300 / 2);
  808.       left(innerWidth / 2 - 300 / 2);
  809.       padding(20);
  810.       color("white");
  811.       font_size(6);
  812.       width(300);
  813.       height(300);
  814.       background_color("rgba(0,0,0,.8)");
  815.       resize("none");
  816.       text("ship" + btoa(designMode.unit.toSpec()));
  817.       return oninput(function(e) {
  818.         var spec, unit;
  819.         if (e.target.value.slice(0, 4) === "ship") {
  820.           try {
  821.             spec = atob(e.target.value.slice(4));
  822.           } catch (undefined) {}
  823.           if (spec && spec[0] === "{") {
  824.             unit = new types.Unit(spec);
  825.             if (unit.parts && unit.parts.length > 0) {
  826.               designMode.unit = unit;
  827.               designMode.refresh();
  828.             }
  829.           }
  830.         }
  831.         return designMode.save();
  832.       });
  833.     });
  834.   };
  835.  
  836.   lockScreen = function() {
  837.     return div(function() {
  838.       position("absolute");
  839.       top(64);
  840.       left(0);
  841.       right(0);
  842.       bottom(84);
  843.       background_color("rgba(0,0,0,.8)");
  844.       return div(function() {
  845.         position("absolute");
  846.         top(200);
  847.         right(0);
  848.         left(0);
  849.         height(100);
  850.         line_height(100);
  851.         background_color("rgba(200,0,0,.6)");
  852.         color("white");
  853.         text_align("center");
  854.         return text("You can't edit ships in 1v1 tournament mode");
  855.       });
  856.     });
  857.   };
  858.  
  859.   finishDesignButton = function() {
  860.     if (!hasIssue(commander, designMode.unit.spec) && designMode.draggingPart === null) {
  861.       return div(function() {
  862.         var quarterWidth;
  863.         quarterWidth = window.innerWidth / 4;
  864.         position("absolute");
  865.         left(quarterWidth);
  866.         width(quarterWidth * 2);
  867.         top(0);
  868.         height(64);
  869.         overflow("hidden");
  870.         text_align("center");
  871.         background_color("rgba(0,0,0,.6)");
  872.         color("white");
  873.         line_height(64);
  874.         font_size(18);
  875.         return div(".hover-black", function() {
  876.           position("absolute");
  877.           top(0);
  878.           left(0);
  879.           right(0);
  880.           bottom(0);
  881.           onclick(function() {
  882.             return ui.mode = "battle";
  883.           });
  884.           return text("Click here to start the battle.");
  885.         });
  886.       });
  887.     }
  888.   };
  889.  
  890.   backToGalaxyButton = function() {
  891.     return div(function() {
  892.       position("absolute");
  893.       top(0);
  894.       left(0);
  895.       return img(".hover-black", {
  896.         src: "img/ui/back.png",
  897.         width: 64,
  898.         height: 64
  899.       }, function() {
  900.         position("absolute");
  901.         top(0);
  902.         left(0);
  903.         return onclick(function() {
  904.           return ui.go("galaxy");
  905.         });
  906.       });
  907.     });
  908.   };
  909.  
  910.   smallTip = function() {
  911.     return div("#smalltip", function() {
  912.       position("absolute");
  913.       top(-1000);
  914.       max_width(400);
  915.       background_color("rgba(0,0,0,.6)");
  916.       padding(5);
  917.       color("white");
  918.       if (designMode.smallTip) {
  919.         return raw(designMode.smallTip);
  920.       }
  921.     });
  922.   };
  923.  
  924.   cell = function(icon, readout, tip) {
  925.     return div(".cell", function() {
  926.       display("inline-block");
  927.       width(90);
  928.       height(20);
  929.       margin("0 10px 10px 0");
  930.       font_size(12);
  931.       line_height(20);
  932.       vertical_align("middle");
  933.       img({
  934.         src: "img/ui/" + icon,
  935.         width: 20,
  936.         height: 20
  937.       }, function() {
  938.         display("block");
  939.         float("left");
  940.         return margin_right(10);
  941.       });
  942.       raw(readout);
  943.       return onmouseover(function(e) {
  944.         designMode.smallTipBounds = e.target.getBoundingClientRect();
  945.         return designMode.smallTip = readout + " " + tip;
  946.       });
  947.     });
  948.   };
  949.  
  950.   divider = function() {
  951.     return div(function() {
  952.       width("100%");
  953.       height(20);
  954.       return margin_bottom(10);
  955.     });
  956.   };
  957.  
  958.   window.unitInfoSmall = function(spec, valid) {
  959.     var ghostCopy, j, len, part, ref, u;
  960.     if (valid == null) {
  961.       valid = true;
  962.     }
  963.     u = buildBar.specToUnit(spec);
  964.     if (u.parts.length === 0) {
  965.       div(function() {
  966.         var ref;
  967.         text_align("center");
  968.         if (((ref = commander.selection) != null ? ref.length : void 0) === 1) {
  969.           return text("Click here to copy selected unit");
  970.         } else {
  971.           return text("Click here to design a unit");
  972.         }
  973.       });
  974.       return;
  975.     }
  976.     ghostCopy = false;
  977.     ref = u.parts;
  978.     for (j = 0, len = ref.length; j < len; j++) {
  979.       part = ref[j];
  980.       if (part.ghostCopy) {
  981.         ghostCopy = true;
  982.         break;
  983.       }
  984.     }
  985.     if (!ghostCopy && !valid) {
  986.       div(function() {
  987.         text_align("center");
  988.         return text("Click here to fix the design");
  989.       });
  990.       return;
  991.     }
  992.     div(function() {
  993.       text_align("center");
  994.       padding_bottom(15);
  995.       if (ghostCopy) {
  996.         color("#f39c12");
  997.         text("Copy Only");
  998.       } else if (!u.name) {
  999.         text("Build Unit");
  1000.       } else {
  1001.         text(u.name);
  1002.       }
  1003.       return text(" $" + u.cost);
  1004.     });
  1005.     cell("dps.png", ((16 * u.weaponDPS).toFixed(1)) + "dps");
  1006.     cell("armor.png", (u.hp.toFixed(0)) + "HP");
  1007.     cell("range.png", (u.weaponRange.toFixed(0)) + "m");
  1008.     cell("speed.png", ((u.maxSpeed * 16).toFixed(3)) + "m/s");
  1009.     cell("arc.png", u.weaponArc + "&deg;");
  1010.     cell("turnSpeed.png", ((u.turnSpeed * 16 / Math.PI * 180).toFixed(1)) + "&deg;/s");
  1011.     return powerBar(u);
  1012.   };
  1013.  
  1014.   unitInfo = function() {
  1015.     var u;
  1016.     u = designMode.unit;
  1017.     div(function() {
  1018.       position("absolute");
  1019.       top(64);
  1020.       right(0);
  1021.       width(240);
  1022.       height(50);
  1023.       background_color("rgba(0,0,0,.1)");
  1024.       color("#DDD");
  1025.       padding(10);
  1026.       padding_top(10);
  1027.       text_align("right");
  1028.       nbsp(3);
  1029.       return span(function() {
  1030.         font_size(24);
  1031.         return text("$" + u.cost);
  1032.       });
  1033.     });
  1034.     return div(function() {
  1035.       position("absolute");
  1036.       top(64 + 50);
  1037.       right(0);
  1038.       bottom(84);
  1039.       width(240);
  1040.       background_color("rgba(0,0,0,.4)");
  1041.       color("#DDD");
  1042.       overflow_y("auto");
  1043.       if (account.hasDLCBonus()) {
  1044.         input({
  1045.           placeholder: "Name your ship",
  1046.           value: designMode.unit.name
  1047.         }, function() {
  1048.           display("block");
  1049.           background_color("rgba(0,0,0,.4)");
  1050.           border("none");
  1051.           width(240);
  1052.           padding(10);
  1053.           font_size(16);
  1054.           color("white");
  1055.           return oninput(function(e) {
  1056.             designMode.unit.name = e.target.value;
  1057.             return designMode.save();
  1058.           });
  1059.         });
  1060.       } else {
  1061.         div(function() {
  1062.           display("block");
  1063.           background_color("rgba(0,0,0,.4)");
  1064.           border("none");
  1065.           width(240);
  1066.           padding(10);
  1067.           font_size(16);
  1068.           color("rgba(255,255,255,.1)");
  1069.           text("Name your ship");
  1070.           return onmouseover(function(e) {
  1071.             designMode.smallTipBounds = e.target.getBoundingClientRect();
  1072.             return designMode.smallTip = "Naming your ships is a bonus feature <br> and requires the Paint Job DLC.";
  1073.           });
  1074.         });
  1075.       }
  1076.       return div(function() {
  1077.         var j, len, ref, results, w;
  1078.         padding(10);
  1079.         padding_left(20);
  1080.         cell("dps.png", ((16 * u.weaponDPS).toFixed(1)) + "dps", "damage per second from all weapons");
  1081.         cell("armor.png", (u.hp.toFixed(0)) + "HP", "total armor hit points");
  1082.         if (u.shield) {
  1083.           cell("shield.png", u.shield + "sh", "+ shield hit points");
  1084.         }
  1085.         cell("range.png", (u.weaponRange.toFixed(0)) + "m", "max range of weapons");
  1086.         cell("speed.png", ((u.maxSpeed * 16).toFixed(2)) + "m/s", "max unit move speed");
  1087.         if (u.jumpDistance) {
  1088.           cell("jump.png", (u.jumpDistance.toFixed(1)) + "m", "jump distance (" + u.mass * 15 +"e min.)");
  1089.         }
  1090.         cell("arc.png", u.weaponArc + "&deg;", "max arc of weapons");
  1091.         cell("turnSpeed.png", ((u.turnSpeed * 16 / Math.PI * 180).toFixed(1)) + "&deg;/s", "turn rate");
  1092.         cell("mass.png", (u.mass.toFixed(1)) + "T", "ship total mass");
  1093.         cell("arc360.png", (u.radius.toFixed(6)) + "m", "ship size");
  1094.        
  1095.         if(u.fireEnergy > 0)
  1096.         {
  1097.             divider();
  1098.             cell("letters.png", (u.weaponDPS / u.fireEnergy ).toFixed(4) + " dee", ": dps energy efficiency");
  1099.             cell("ai.png", (u.weaponDPS / u.cost ).toFixed(4) + " dce", ": dps cost efficiency");
  1100.             cell("damage.png",  (u.weapons.map(x => x.damage).reduce((a,b) => a + b, 0)).toFixed(1) + " dmg", ": burst dmg");
  1101.             cell("mute.png",  (u.hp/ u.cost).toFixed(4) + " hce", ": hp cost efficiency");
  1102.            
  1103.         }
  1104.  
  1105.         divider();
  1106.        
  1107.         powerBar(u);
  1108.         cell("energyGen.png", "+" + ((u.genEnergy * 16).toFixed(0)) + "E", "energy generated per second");
  1109.         cell("energyMove.png", ((u.moveEnergy * 16).toFixed(0)) + "E", "energy needed to move per second");
  1110.         cell("energyStorage.png", (u.storeEnergy.toFixed(0)) + "E", "battery capacity");
  1111.         cell("energyFire.png", ((u.fireEnergy * 16).toFixed(0)) + "E", "energy needed to fire all weapons per second");
  1112.         divider();
  1113.         u.weapons.sort(function(a, b) {
  1114.           return b.dps - a.dps;
  1115.         });
  1116.         ref = u.weapons;
  1117.         results = [];
  1118.         for (j = 0, len = ref.length; j < len; j++) {
  1119.           w = ref[j];
  1120.           weaponInfo(w, false);
  1121.           results.push(divider());
  1122.         }
  1123.         return results;
  1124.       });
  1125.     });
  1126.   };
  1127.  
  1128.   powerBar = function(u) {
  1129.     return div(".cell", function() {
  1130.       var firePer, genPer, max, movePer, moveWidth, s, tip, w;
  1131.       position("relative");
  1132.       display("inline-block");
  1133.       width(200);
  1134.       height(20);
  1135.       margin("0 10px 10px 0");
  1136.       font_size(12);
  1137.       line_height(20);
  1138.       vertical_align("middle");
  1139.       genPer = (100 * u.genEnergy * 160 / u.storeEnergy).toFixed(1);
  1140.       movePer = (100 * u.moveEnergy * 160 / u.storeEnergy).toFixed(1);
  1141.       firePer = (100 * u.fireEnergy * 160 / u.storeEnergy).toFixed(1);
  1142.       tip = "In 10 seconds: <br>\n" + genPer + "% will be regenerated <br>\n" + movePer + "% will be used up while moving <br>\n" + firePer + "% will be used up while firing <br>";
  1143.       onmouseover(function(e) {
  1144.         designMode.smallTipBounds = e.target.getBoundingClientRect();
  1145.         return designMode.smallTip = tip;
  1146.       });
  1147.       img({
  1148.         src: "img/ui/energy.png",
  1149.         width: 20,
  1150.         height: 20
  1151.       }, function() {
  1152.         display("block");
  1153.         float("left");
  1154.         return margin_right(10);
  1155.       });
  1156.       w = 150;
  1157.       s = 160;
  1158.       max = Math.max(Math.max(s * u.genEnergy, u.storeEnergy), s * u.moveEnergy + s * u.fireEnergy);
  1159.       div(function() {
  1160.         position("absolute");
  1161.         top(3);
  1162.         left(31);
  1163.         height(12);
  1164.         width(Math.floor(s * w * u.genEnergy / max));
  1165.         return background("#9BBCE2");
  1166.       });
  1167.       div(function() {
  1168.         position("absolute");
  1169.         top(2);
  1170.         left(30);
  1171.         height(14);
  1172.         width(Math.floor(w * u.storeEnergy / max));
  1173.         return border("1px solid white");
  1174.       });
  1175.       moveWidth = Math.floor(s * w * u.moveEnergy / max) - 5;
  1176.       if (moveWidth < 0) {
  1177.         moveWidth = 0;
  1178.       }
  1179.       div(function() {
  1180.         position("absolute");
  1181.         top(5);
  1182.         left(30 + 3);
  1183.         height(8);
  1184.         width(moveWidth);
  1185.         background("#C6EDA0");
  1186.         return border("1px solid white");
  1187.       });
  1188.       return div(function() {
  1189.         position("absolute");
  1190.         top(5);
  1191.         left(30 + 5 + Math.max(moveWidth, 2));
  1192.         height(8);
  1193.         width(Math.floor(s * w * u.fireEnergy / max) - 4);
  1194.         background("#E59090");
  1195.         return border("1px solid white");
  1196.       });
  1197.     });
  1198.   };
  1199.  
  1200.   weaponInfo = function(w, extra) {
  1201.     var dps, ref, ref1, rt;
  1202.     div(function() {
  1203.       font_size(14);
  1204.       text(w.name);
  1205.       height(20);
  1206.       return margin_bottom(10);
  1207.     });
  1208.     if (extra) {
  1209.       div(function() {
  1210.         font_size(12);
  1211.         margin_bottom(10);
  1212.         return text(w.desc);
  1213.       });
  1214.       cell("armor.png", w.hp + "hp", "- adds hit points");
  1215.       cell("mass.png", (w.mass.toFixed(1)) + "T", "- adds mass");
  1216.     }
  1217.     rt = Math.max(w.reloadTime, 1);
  1218.     dps = w.dps || w.damage / rt;
  1219.     cell("dps.png", ((16 * dps).toFixed(1)) + "dps", "damage per second");
  1220.     if ((ref = w.bulletCls) != null ? ref.prototype.hitsMultiple : void 0) {
  1221.       cell("multihit.png", "MultiHit", "passes through and hits multiple ships");
  1222.     }
  1223.     cell("damage.png", (w.damage.toFixed(1)) + "d", "damage per shot");
  1224.     cell("range.png", (w.range.toFixed(1)) + "m", "weapon range");
  1225.     cell("reload.png", ((w.reloadTime / 16).toFixed(2)) + "s", "reload time sec");
  1226.     cell("reload.png", (w.getRawReloadTime().toFixed(2)) + " tix", "reload time tick");
  1227.     cell("energy.png", "-" + (w.shotEnergy.toFixed(1)) + "E", "energy per shot");
  1228.     cell("energy.png", (w.shotEnergy / w.damage * 100).toFixed(0) + "E/D", "energy per 100dmg");
  1229.    
  1230.     if (w.fireEnergy) {
  1231.       cell("energy.png", "-" + ((w.fireEnergy * 16).toFixed(1)) + "E", "energy per second");
  1232.     }
  1233.     if (!w.instant) {
  1234.       cell("speed.png", ((w.bulletSpeed * 16).toFixed(0)) + "m/s", "speed of the projectile");
  1235.     }
  1236.     if (w.aoe) {
  1237.       cell("aoe.png", w.aoe + "m", "area of effect");
  1238.     }
  1239.     if (w.instant) {
  1240.       cell("instant.png", "instant", "instahit weapon");
  1241.     }
  1242.     if (w.exactRange) {
  1243.       cell("exactRange.png", "exact", "timed explosion");
  1244.     }
  1245.     if ((ref1 = w.bulletCls) != null ? ref1.prototype.missile : void 0) {
  1246.       cell("missle.png", "Missile", "missile based, can be shot down by point defence");
  1247.     }
  1248.     if (w.hitsMissiles) {
  1249.       cell("antiMissle.png", "PD", "points defence, can shoot down missiles");
  1250.     }
  1251.     if (w.energyDamage) {
  1252.       cell("energyDamage.png", ((16 * w.energyDamage / rt).toFixed(1)) + "dps", "amount of energy drain per second");
  1253.     }
  1254.     if (w.energyDamage) {
  1255.       cell("energyDamage.png", (w.energyDamage.toFixed(1)) + "d", "amount of energy drain per shot");
  1256.     }
  1257.     if (w.dealsBurnDamage) {
  1258.       cell("burnDps.png", ((16 * dps * w.burnAmount).toFixed(1)) + "dps", "burn damage per second");
  1259.       cell("burnDamage.png", ((w.damage * w.burnAmount).toFixed(1)) + "d", "burn damage per shot");
  1260.       cell("burnDps.png", "3%", "of burn as damage per second");
  1261.     }
  1262.     if (w.minRange > 0) {
  1263.       return cell("minrange.png", (w.minRange.toFixed(1)) + "m", "minimum range");
  1264.     }
  1265.   };
  1266.  
  1267.   editorButtons = function() {
  1268.     return div(function() {
  1269.       var editorButton;
  1270.       position("absolute");
  1271.       right(260);
  1272.       top(80);
  1273.       width(620);
  1274.       text_align("right");
  1275.       color("#DDD");
  1276.       padding(0);
  1277.       editorButton = function(icon, tip, fn) {
  1278.         return div(".hover-black", function() {
  1279.           position("relative");
  1280.           display("inline-block");
  1281.           width(40);
  1282.           height(40);
  1283.           padding(10);
  1284.           if (icon) {
  1285.             img({
  1286.               src: icon,
  1287.               width: 20,
  1288.               height: 20
  1289.             }, function() {
  1290.               position("absolute");
  1291.               top(10);
  1292.               return left(10);
  1293.             });
  1294.           }
  1295.           if (tip) {
  1296.             hoverTip(tip);
  1297.           }
  1298.           return fn();
  1299.         });
  1300.       };
  1301.       if (designMode.clearQ) {
  1302.         editorButton(null, null, function() {
  1303.           padding("10px 0px");
  1304.           width(60);
  1305.           text_align("center");
  1306.           background("rgba(255,0,0,.2)");
  1307.           text("clear");
  1308.           return onclick(function() {
  1309.             designMode.clear();
  1310.             return designMode.clearQ = false;
  1311.           });
  1312.         });
  1313.         editorButton(null, null, function() {
  1314.           padding("10px 0px");
  1315.           width(60);
  1316.           text_align("center");
  1317.           text("cancel");
  1318.           return onclick(function() {
  1319.             return designMode.clearQ = false;
  1320.           });
  1321.         });
  1322.         return;
  1323.       }
  1324.       if (designMode.showAiTools) {
  1325.         editorButton("img/ui/ai.png", "AI mode", function() {
  1326.           if (localStorage.useAi === "true") {
  1327.             background("rgba(255,0,0,.2)");
  1328.           }
  1329.           return onclick(function() {
  1330.             if (localStorage.useAi !== "true") {
  1331.               localStorage.useAi = "true";
  1332.             } else {
  1333.               localStorage.useAi = "false";
  1334.               designMode.aiEdit = false;
  1335.             }
  1336.             return designMode.save();
  1337.           });
  1338.         });
  1339.         if (localStorage.useAi === "true") {
  1340.           editorButton("img/ui/aiRules.png", "AI editor", function() {
  1341.             if (designMode.aiEdit) {
  1342.               background("rgba(0,0,0,.2)");
  1343.             }
  1344.             return onclick(function() {
  1345.               return designMode.aiEdit = !designMode.aiEdit;
  1346.             });
  1347.           });
  1348.           if (intp.local) {
  1349.             editorButton("img/ui/aiBubbles.png", "AI debugging bubbles", function() {
  1350.               if (localStorage.aiGrid === "true") {
  1351.                 background("rgba(0,0,0,.2)");
  1352.               }
  1353.               return onclick(function() {
  1354.                 if (localStorage.aiGrid !== "true") {
  1355.                   return localStorage.aiGrid = "true";
  1356.                 } else {
  1357.                   return localStorage.aiGrid = "false";
  1358.                 }
  1359.               });
  1360.             });
  1361.           }
  1362.         }
  1363.       }
  1364.       editorButton("img/ui/symmetry.png", "Symmetry", function() {
  1365.         if (designMode.symmetryMode) {
  1366.           background("rgba(0,0,0,.2)");
  1367.         }
  1368.         return onclick(function() {
  1369.           return designMode.symmetryMode = !designMode.symmetryMode;
  1370.         });
  1371.       });
  1372.       editorButton("img/ui/share.png", "Share", function() {
  1373.         if (designMode.showShareBox) {
  1374.           background("rgba(0,0,0,.2)");
  1375.         }
  1376.         return onclick(function() {
  1377.           return designMode.showShareBox = !designMode.showShareBox;
  1378.         });
  1379.       });
  1380.       return editorButton("img/ui/clear.png", "Delete", function() {
  1381.         return onclick(function() {
  1382.           return designMode.clearQ = true;
  1383.         });
  1384.       });
  1385.     });
  1386.   };
  1387.  
  1388.   window.issueInfo = function() {
  1389.     var issue, u, warning;
  1390.     u = designMode.unit;
  1391.     issue = hasIssue(commander, u.spec);
  1392.     if (issue) {
  1393.       div(function() {
  1394.         position("relative");
  1395.         width(300);
  1396.         margin("0px auto");
  1397.         top(75);
  1398.         text_align("center");
  1399.         background_color("rgba(255,0,0,.5)");
  1400.         color("#EEE");
  1401.         padding(10);
  1402.         return raw(issue);
  1403.       });
  1404.       return;
  1405.     }
  1406.     if (u.spec.length >= 6) {
  1407.       if (intp.serverType === "1v1t" && u.aiRules.length > 0) {
  1408.         warning = "No AI in 1v1 tournament mode.";
  1409.       }
  1410.       if (u.moveEnergy * 160 > u.storeEnergy) {
  1411.         if (u.maxSpeed * 16 > 250) {
  1412.           warning = "Thrusters using too much energy, remove thrusters.";
  1413.         } else {
  1414.           warning = "Not enough energy for thrusters.";
  1415.         }
  1416.       }
  1417.       if (u.fireEnergy * 16 * 2 > u.storeEnergy) {
  1418.         warning = "Not enough energy for weapons, add batteries.";
  1419.       }
  1420.       if (u.maxSpeed < 5) {
  1421.         warning = "Movement speed is very slow, reduce weight.";
  1422.       }
  1423.       if (u.turnSpeed < .02) {
  1424.         warning = "Turn speed is very slow, add wings.";
  1425.       }
  1426.       if (u.jumpDistance > 0 && u.jumpDistance < 100) {
  1427.         warning = "Low jump distance.";
  1428.       }
  1429.     }
  1430.     if (warning) {
  1431.       return div(function() {
  1432.         position("relative");
  1433.         width(300);
  1434.         margin("0px auto");
  1435.         top(75);
  1436.         text_align("center");
  1437.         background_color("rgba(0, 0, 0, .5)");
  1438.         color("white");
  1439.         padding(10);
  1440.         return text("Note: ", warning);
  1441.       });
  1442.     }
  1443.   };
  1444.  
  1445.   hoverInfo = function() {
  1446.     var part;
  1447.     if (designMode.draggingPart) {
  1448.       part = designMode.draggingPart;
  1449.     } else if (designMode.hoverTipPart) {
  1450.       part = designMode.hoverTipPart;
  1451.     }
  1452.     if (!part) {
  1453.       return;
  1454.     }
  1455.     if (designMode.aiEdit) {
  1456.       return;
  1457.     }
  1458.     return div("#hoverInfo", function() {
  1459.       var pr;
  1460.       position("absolute");
  1461.       left(250);
  1462.       top(75);
  1463.       width(220);
  1464.       background_color("rgba(0,0,0,.5)");
  1465.       color("#DDD");
  1466.       padding(10);
  1467.       div(function() {
  1468.         float("right");
  1469.         return text("$" + part.cost);
  1470.       });
  1471.       if (part.bulletCls) {
  1472.         weaponInfo(part, true);
  1473.         return;
  1474.       }
  1475.       div(function() {
  1476.         font_size(14);
  1477.         text(part.name);
  1478.         height(20);
  1479.         return margin_bottom(10);
  1480.       });
  1481.       if (!account.hasDLC(part.dlc)) {
  1482.         div(function() {
  1483.           font_size(16);
  1484.           color("rgba(255,255,255,.5)");
  1485.           raw("Support Istrolid and get this part with the <a href='http://store.steampowered.com/app/449140' target='_blank'>" + part.dlc + " DLC</a>.");
  1486.           return margin_bottom(10);
  1487.         });
  1488.       }
  1489.       div(function() {
  1490.         font_size(12);
  1491.         margin_bottom(10);
  1492.         return text(part.desc);
  1493.       });
  1494.       if (!part.decal) {
  1495.         cell("armor.png", part.hp + "hp", "armor hit points");
  1496.         cell("mass.png", (part.mass.toFixed(1)) + "T", "mass");
  1497.       }
  1498.       if (part.thrust) {
  1499.         cell("speed.png", ((part.thrust * 16).toFixed(0)) + "kN", "thrust (in kilonewtons)");
  1500.       }
  1501.       if (part.turnSpeed) {
  1502.         cell("turnSpeed.png", ((part.turnSpeed / Math.PI * 180).toFixed(0)) + "&deg;/s", "+ turn speed (slowed down by mass)");
  1503.       }
  1504.       if (part.jumpCount) {
  1505.         cell("jump.png", ((part.jumpCount * 500).toFixed(0)) + "m", "jump distance (in meters)");
  1506.       }
  1507.       pr = function(percent) {
  1508.         if (percent > 0) {
  1509.           return "+" + percent + "%";
  1510.         } else {
  1511.           return percent + "%";
  1512.         }
  1513.       };
  1514.       if (part.weaponRange) {
  1515.         cell("range.png", pr(part.weaponRange), "range");
  1516.       }
  1517.       if (part.weaponRangeFlat) {
  1518.         cell("range.png", "+" + part.weaponRangeFlat + "m", "flat range");
  1519.       }
  1520.       if (part.weaponDamage) {
  1521.         cell("damage.png", pr(part.weaponDamage), "damage per hit");
  1522.       }
  1523.       if (part.weaponSpeed) {
  1524.         cell("speed.png", pr(part.weaponSpeed), "projectile speed");
  1525.       }
  1526.       if (part.weaponReload) {
  1527.         cell("reload.png", pr(part.weaponReload), "reload time");
  1528.       }
  1529.       if (part.weaponEnergy) {
  1530.         cell("energy.png", pr(part.weaponEnergy), "energy usage");
  1531.       }
  1532.       if (part.adjacent) {
  1533.         cell("stripes.png", "-15%", "reduced effectiveness per additional adjacent weapon");
  1534.       }
  1535.       if (part.genShield) {
  1536.         cell("shield.png", "+" + part.genShield * 16 + "sh/s", "recharges shield");
  1537.         cell("shield.png", "+" + (part.useEnergy / part.genShield).toFixed(1) + "e/sh", "recharges shield");
  1538.       }
  1539.       if (part.shield) {
  1540.         cell("shield.png", part.shield + "sh", "+ shield hit points");
  1541.       }
  1542.       if (part.energyLine) {
  1543.         cell("energyStorage.png", (part.energyLine * 100) + "%", "energy storage threshold for regeneration");
  1544.       }
  1545.       if (part.range) {
  1546.         cell("range.png", part.range + "m", "range");
  1547.       }
  1548.       if (part.trasferEnergy) {
  1549.         cell("energy.png", "-" + part.trasferEnergy * 16 + "E/s", "amount transfer per second per ship");
  1550.       }
  1551.       if (part.slow) {
  1552.         cell("speed.png", "-" + part.slow * 16 + "m/s", "Slows down ships in range");
  1553.         cell("decloak.png", "Decloaks", "units in range");
  1554.       }
  1555.       if (part.genCloak) {
  1556.         cell("cloak.png", "+" + part.genCloak * 16 * 2 + "T/s", "mass cloaked per second");
  1557.         cell("cloakMass.png", part.genCloak * 16 * 5 + "T", "while moving");
  1558.       }
  1559.       if (part.explodes) {
  1560.         if (part.damage) {
  1561.           cell("damage.png", part.damage + "d", "damage per explosion");
  1562.         }
  1563.         if (part.aoe) {
  1564.           cell("range.png", part.aoe + "m", "area of effect");
  1565.         }
  1566.         if (part.energyDamage) {
  1567.           cell("energyDamage.png", part.energyDamage + "d", "amount of energy drain per explosion");
  1568.         }
  1569.       }
  1570.       if (part.genEnergy) {
  1571.         cell("energyGen.png", "+" + (part.genEnergy * 16) + "E", "generates energy");
  1572.       }
  1573.       if (part.storeEnergy) {
  1574.         cell("energyStorage.png", part.storeEnergy + "E", "stores energy");
  1575.       }
  1576.       if (part.useEnergy) {
  1577.         cell("energy.png", "-" + (part.useEnergy * 16) + "E/s", "uses energy");
  1578.       }
  1579.       if (part.arc) {
  1580.         cell("arc.png", part.arc + "°", "firing arc");
  1581.       }
  1582.       if (part.rangeBuffMul) {
  1583.         return cell("range.png", pr(-100 + (part.rangeBuffMul * 100)), "range");
  1584.       }
  1585.     });
  1586.   };
  1587.  
  1588.   has = function(a, b) {
  1589.     if (a && b) {
  1590.       return a.toLowerCase().indexOf(b.toLowerCase()) !== -1;
  1591.     }
  1592.   };
  1593.  
  1594.   drawParts = function() {
  1595.     var minParts, p, totalParts;
  1596.     minParts = 3 * 8;
  1597.     if (sim.galaxyStar && !account.DLCbonus) {
  1598.       totalParts = 0;
  1599.       for (p in galaxyMode.unlockedParts) {
  1600.         totalParts += 1;
  1601.       }
  1602.     } else {
  1603.       totalParts = 100;
  1604.     }
  1605.     div("#partTabs", function() {
  1606.       position("absolute");
  1607.       top(64);
  1608.       left(0);
  1609.       width(240);
  1610.       color("#DDD");
  1611.       height(100);
  1612.       if (totalParts > minParts) {
  1613.         div(function() {
  1614.           drawTab("weapons", "dps.png");
  1615.           drawTab("energy", "energy.png");
  1616.           drawTab("armor1", "armor.png");
  1617.           drawTab("armor2", "armor3.png");
  1618.           return drawTab("armor3", "armor2.png");
  1619.         });
  1620.         return div(function() {
  1621.           drawTab("engines", "speed.png");
  1622.           drawTab("defence", "minrange.png");
  1623.           drawTab("decal", "decals.png");
  1624.           drawTab("letters", "letters.png");
  1625.           return drawTab("stripes", "stripes.png");
  1626.         });
  1627.       }
  1628.     });
  1629.     return div("#partArea", function() {
  1630.       var clsName, part, results;
  1631.       position("absolute");
  1632.       top(64 + 100);
  1633.       left(0);
  1634.       bottom(84);
  1635.       width(240);
  1636.       background_color("rgba(0,0,0,.4)");
  1637.       padding(10);
  1638.       overflow_y("auto");
  1639.       results = [];
  1640.       for (clsName in parts) {
  1641.         part = parts[clsName];
  1642.         if (totalParts > minParts) {
  1643.           if (part.prototype.tab !== designMode.tab) {
  1644.             continue;
  1645.           }
  1646.         }
  1647.         results.push(drawPart(clsName, part));
  1648.       }
  1649.       return results;
  1650.     });
  1651.   };
  1652.  
  1653.   drawAiParts = function() {
  1654.     div(function() {
  1655.       position("absolute");
  1656.       top(64);
  1657.       height(50);
  1658.       left(0);
  1659.       width(240);
  1660.       color("#DDD");
  1661.       drawTab("energy", "build.png");
  1662.       drawTab("engines", "movement.png");
  1663.       drawTab("weapons", "offence.png");
  1664.       return drawTab("armor", "defence.png");
  1665.     });
  1666.     return div(function() {
  1667.       var j, len, results, rule, rules;
  1668.       position("absolute");
  1669.       top(64 + 50);
  1670.       bottom(84);
  1671.       left(0);
  1672.       width(240);
  1673.       background_color("rgba(0,0,0,.4)");
  1674.       padding(10);
  1675.       overflow_y("auto");
  1676.       if (allAiRules[designMode.tab] == null) {
  1677.         designMode.tab = "energy";
  1678.       }
  1679.       rules = allAiRules[designMode.tab];
  1680.       results = [];
  1681.       for (j = 0, len = rules.length; j < len; j++) {
  1682.         rule = rules[j];
  1683.         results.push(drawAddRule(rule));
  1684.       }
  1685.       return results;
  1686.     });
  1687.   };
  1688.  
  1689.   drawAddRule = function(rule) {
  1690.     return div(function() {
  1691.       background_color("rgba(0,0,0,.4)");
  1692.       margin(5);
  1693.       return div(".hover-black", function() {
  1694.         var count, i, j, len, part, parts, rule_text;
  1695.         padding(5);
  1696.         color("white");
  1697.         rule_text = rule[0];
  1698.         parts = rule_text.split(/([\#\?\*]|\@\w+)/);
  1699.         count = 1;
  1700.         for (i = j = 0, len = parts.length; j < len; i = ++j) {
  1701.           part = parts[i];
  1702.           if (part === "#" || part === "?" || part === "*" || part[0] === "@") {
  1703.             span(function() {
  1704.               text(rule[count]);
  1705.               padding("1px 2px 1px 2px");
  1706.               border("1px solid #f39c12");
  1707.               background("rgba(0,0,0,.4)");
  1708.               color("#f39c12");
  1709.               return font_size(12);
  1710.             });
  1711.             count += 1;
  1712.           } else {
  1713.             span(function() {
  1714.               return text(part);
  1715.             });
  1716.           }
  1717.         }
  1718.         return onclick(function() {
  1719.           if (!designMode.unit.aiRules) {
  1720.             designMode.unit.aiRules = [];
  1721.           }
  1722.           designMode.unit.aiRules.push((function(func, args, ctor) {
  1723.             ctor.prototype = func.prototype;
  1724.             var child = new ctor, result = func.apply(child, args);
  1725.             return Object(result) === result ? result : child;
  1726.           })(Array, rule, function(){}));
  1727.           return designMode.save();
  1728.         });
  1729.       });
  1730.     });
  1731.   };
  1732.  
  1733.   drawTab = function(name, pic) {
  1734.     return div(function() {
  1735.       position("relative");
  1736.       display("inline-block");
  1737.       width(48);
  1738.       height(50);
  1739.       background_color("rgba(0,0,0,.4)");
  1740.       img({
  1741.         src: "img/ui/" + pic,
  1742.         width: 20,
  1743.         height: 20
  1744.       }, function() {
  1745.         return margin("15px 14px 0px 14px");
  1746.       });
  1747.       if (designMode.tab !== name) {
  1748.         opacity(".3");
  1749.       }
  1750.       return onclick(function() {
  1751.         return designMode.tab = name;
  1752.       });
  1753.     });
  1754.   };
  1755.  
  1756.   drawPart = function(clsName, part) {
  1757.     if (sim.galaxyStar && !galaxyMode.unlockedParts[clsName]) {
  1758.       if (!(part.prototype.dlc && account.hasDLC(part.prototype.dlc))) {
  1759.         return;
  1760.       }
  1761.     }
  1762.     if (part.prototype.hide || part.prototype.disable) {
  1763.       return;
  1764.     }
  1765.     if (part.prototype.faction && part.prototype.faction !== commander.faction) {
  1766.       return;
  1767.     }
  1768.     return div(".unitpic", function() {
  1769.       var image, j, len, ref, unlockName;
  1770.       position("relative");
  1771.       display("inline-block");
  1772.       width(52 + 16);
  1773.       height(52 + 16);
  1774.       margin(0);
  1775.       border_radius(5);
  1776.       overflow("hidden");
  1777.       if (sim.galaxyStar) {
  1778.         if (galaxyMode.justWon) {
  1779.           ref = galaxyMode.justWon.unlocks;
  1780.           for (j = 0, len = ref.length; j < len; j++) {
  1781.             unlockName = ref[j];
  1782.             if (clsName === unlockName) {
  1783.               animation("innerGlowPulse 1.2s infinite");
  1784.               animation_direction("alternate");
  1785.               div(function() {
  1786.                 width(70);
  1787.                 position("absolute");
  1788.                 right(-23);
  1789.                 top(5);
  1790.                 text_align("center");
  1791.                 transform("rotate(45deg)");
  1792.                 font_size(12);
  1793.                 color("white");
  1794.                 background_color("red");
  1795.                 return text("new");
  1796.               });
  1797.             }
  1798.           }
  1799.         }
  1800.       }
  1801.       image = partThumb(part);
  1802.       background_image("url('" + image + "')");
  1803.       background_size(52 + 16);
  1804.       background_position("center");
  1805.       background_repeat("no-repeat");
  1806.       onmouseover(function(e) {
  1807.         return designMode.hoverTipPart = part.prototype;
  1808.       });
  1809.       if (!account.hasDLC(part.prototype.dlc)) {
  1810.         return opacity(".5");
  1811.       } else {
  1812.         return onmousedown(function(e) {
  1813.           designMode.draggingPart = new part();
  1814.           designMode.draggingPart.unit = designMode.dragUnit;
  1815.           v2.set(designMode.pos, designMode.draggingPart.worldPos);
  1816.           v2.set(designMode.pos, designMode.draggingPart.pos);
  1817.           designMode.dragUnit.parts = [designMode.draggingPart];
  1818.           return e.preventDefault();
  1819.         });
  1820.       }
  1821.     });
  1822.   };
  1823.  
  1824.   isBuildRule = function(rule) {
  1825.     var j, len, r, ref;
  1826.     ref = allAiRules["energy"];
  1827.     for (j = 0, len = ref.length; j < len; j++) {
  1828.       r = ref[j];
  1829.       if (r[0] === rule[0]) {
  1830.         return true;
  1831.       }
  1832.     }
  1833.     return false;
  1834.   };
  1835.  
  1836.   aiEditScreen = function() {
  1837.     return div("#unitAiRules" + buildBar.selected, function() {
  1838.       var aiRuleSet, index, j, l, len, len1, results, rule;
  1839.       position("absolute");
  1840.       top(130);
  1841.       bottom(84);
  1842.       left(300);
  1843.       right(300);
  1844.       background("rgba(0,0,0,.7)");
  1845.       padding(50);
  1846.       overflow_y("auto");
  1847.       aiRuleSet = designMode.unit.aiRules;
  1848.       if (aiRuleSet.length > 0) {
  1849.         for (index = j = 0, len = aiRuleSet.length; j < len; index = ++j) {
  1850.           rule = aiRuleSet[index];
  1851.           if (!isBuildRule(rule)) {
  1852.             drawRule(rule, index);
  1853.           }
  1854.         }
  1855.         div(function() {
  1856.           return height(20);
  1857.         });
  1858.         results = [];
  1859.         for (index = l = 0, len1 = aiRuleSet.length; l < len1; index = ++l) {
  1860.           rule = aiRuleSet[index];
  1861.           if (isBuildRule(rule)) {
  1862.             results.push(drawRule(rule, index));
  1863.           } else {
  1864.             results.push(void 0);
  1865.           }
  1866.         }
  1867.         return results;
  1868.       } else {
  1869.         return div(function() {
  1870.           color("gray");
  1871.           return text("no rules yet, add some rules from the side");
  1872.         });
  1873.       }
  1874.     });
  1875.   };
  1876.  
  1877.   drawRuleNumber = function(rule, index, count) {
  1878.     return input({
  1879.       type: "text",
  1880.       value: rule[count]
  1881.     }, function() {
  1882.       display("inline-block");
  1883.       padding("2px 4px 2px 4px");
  1884.       border("1px solid #f39c12");
  1885.       background("rgba(0,0,0,.4)");
  1886.       color("#f39c12");
  1887.       font_size(16);
  1888.       text_align("center");
  1889.       line_height(20);
  1890.       width(60);
  1891.       vertical_align("baseline");
  1892.       return oninput(function(e) {
  1893.         rule[count] = parseInt(e.target.value);
  1894.         return designMode.save();
  1895.       });
  1896.     });
  1897.   };
  1898.  
  1899.   drawRuleDD = function(rule, index, count, options, w) {
  1900.     return div(function() {
  1901.       var j, len, type;
  1902.       display("inline-block");
  1903.       padding("3px 4px 1px 4px");
  1904.       border("1px solid #f39c12");
  1905.       background("rgba(0,0,0,.4)");
  1906.       color("#f39c12");
  1907.       font_size(16);
  1908.       line_height(20);
  1909.       vertical_align("baseline");
  1910.       for (j = 0, len = options.length; j < len; j++) {
  1911.         type = options[j];
  1912.         if (type.toLowerCase() === rule[count].toLowerCase()) {
  1913.           text(type);
  1914.         }
  1915.       }
  1916.       return onclick(function(e) {
  1917.         return ui.rmenu = {
  1918.           id: rid(),
  1919.           pos: [e.clientX, e.clientY],
  1920.           html: function() {
  1921.             var l, len1, results;
  1922.             results = [];
  1923.             for (l = 0, len1 = options.length; l < len1; l++) {
  1924.               type = options[l];
  1925.               results.push((function(type) {
  1926.                 return div(".hover-red", function() {
  1927.                   padding("4px 8px");
  1928.                   text(type);
  1929.                   return onmousedown(function() {
  1930.                     var ddopen;
  1931.                     rule[count] = type;
  1932.                     return ddopen = null;
  1933.                   });
  1934.                 });
  1935.               })(type));
  1936.             }
  1937.             return results;
  1938.           }
  1939.         };
  1940.       });
  1941.     });
  1942.   };
  1943.  
  1944.   drawRule = function(rule, index) {
  1945.     var aiRuleSet;
  1946.     aiRuleSet = designMode.unit.aiRules;
  1947.     return div(function() {
  1948.       var count, i, j, len, part, parts, rule_text;
  1949.       position("relative");
  1950.       background("rgba(0,0,0,.4)");
  1951.       padding("5px 10px");
  1952.       color("white");
  1953.       margin(10);
  1954.       padding_left(40);
  1955.       padding_right(40);
  1956.       min_height(40);
  1957.       line_height(36);
  1958.       vertical_align("baseline");
  1959.       rule_text = rule[0];
  1960.       if (!ais.goodRule(rule)) {
  1961.         background_color("rgba(255,0,0,.5)");
  1962.       }
  1963.       if (rule_text === "Code Block") {
  1964.         textarea(function() {
  1965.           border("none");
  1966.           background("rgba(0,0,0,.4)");
  1967.           padding(4);
  1968.           font_family("monospace");
  1969.           font_size(14);
  1970.           color("white");
  1971.           width("100%");
  1972.           height(200);
  1973.           return text(rule[1]);
  1974.         });
  1975.       } else {
  1976.         parts = rule_text.split(/(\#|\@\w+)/);
  1977.         count = 1;
  1978.         for (i = j = 0, len = parts.length; j < len; i = ++j) {
  1979.           part = parts[i];
  1980.           if (part === "#") {
  1981.             drawRuleNumber(rule, index, count);
  1982.             count += 1;
  1983.           } else if (part[0] === "@") {
  1984.             drawRuleDD(rule, index, count, ais[part.slice(1)], 120);
  1985.             count += 1;
  1986.           } else {
  1987.             span(function() {
  1988.               return text(part);
  1989.             });
  1990.           }
  1991.         }
  1992.       }
  1993.       img(".hover-fade", {
  1994.         src: "img/ui/upVote.png",
  1995.         width: 14,
  1996.         height: 14
  1997.       }, function() {
  1998.         position("absolute");
  1999.         top(4);
  2000.         left(10);
  2001.         return onclick(function() {
  2002.           if (index > 0) {
  2003.             aiRuleSet.splice(index, 0, aiRuleSet.splice(index - 1, 1)[0]);
  2004.             return designMode.save();
  2005.           }
  2006.         });
  2007.       });
  2008.       img(".hover-fade", {
  2009.         src: "img/ui/downVote.png",
  2010.         width: 14,
  2011.         height: 14
  2012.       }, function() {
  2013.         position("absolute");
  2014.         bottom(4);
  2015.         left(10);
  2016.         return onclick(function() {
  2017.           if (index < aiRuleSet.length - 1) {
  2018.             aiRuleSet.splice(index, 0, aiRuleSet.splice(index + 1, 1)[0]);
  2019.             return designMode.save();
  2020.           }
  2021.         });
  2022.       });
  2023.       return img(".hover-fade", {
  2024.         src: "img/ui/delete.png",
  2025.         width: 28,
  2026.         height: 28
  2027.       }, function() {
  2028.         position("absolute");
  2029.         top(6);
  2030.         right(6);
  2031.         return onclick(function() {
  2032.           aiRuleSet.splice(index, 1);
  2033.           return designMode.save();
  2034.         });
  2035.       });
  2036.     });
  2037.   };
  2038.  
  2039. }).call(this);
  2040. ;
  2041.  
  2042. //show ship info on click t to toggle
  2043. var ub_window_body = ub_window_body || window.body;
  2044. var ub_battlemode_onkeydown = ub_battlemode_onkeydown || battleMode.onkeydown;
  2045. var ub_enabled = false;
  2046.  
  2047. function ub_drawBubble() {
  2048.     let fmod = function(a,b) { return Number((a - (Math.floor(a / b) * b)).toPrecision(8)); };
  2049.     let wrapAngle = th => {
  2050.         let rst = fmod(th + Math.PI, 2 * Math.PI);
  2051.         return rst < 0 ? rst + Math.PI : rst - Math.PI;
  2052.     };
  2053.  
  2054.     if(ub_enabled && ui.mode === "battle" && commander.selection.length > 0) {
  2055.         onecup.div("#unit_bubble", () => {
  2056.             onecup.position("absolute");
  2057.             onecup.top(80);
  2058.             onecup.left(10);
  2059.             onecup.width(420);
  2060.             onecup.padding(15);
  2061.             onecup.font_size(14);
  2062.             onecup.color("white");
  2063.             onecup.background_color("rgba(30, 30, 30, 0.6)");
  2064.             onecup.border_radius(10);
  2065.  
  2066.             let statSum = {};
  2067.             let stat = (icon, unit, value, max = 0, opts = {hideZero: false, max: false, sum: true}) => {
  2068.                 if(opts.hideZero && value === 0) return;
  2069.                 if(!statSum[icon]) {
  2070.                     statSum[icon] = {
  2071.                         value: value,
  2072.                         max: max,
  2073.                         unit: unit,
  2074.                         count: 1
  2075.                     };
  2076.                 } else {
  2077.                     if(opts.max) {
  2078.                         statSum[icon].value = Math.max(statSum[icon].value, value);
  2079.                         statSum[icon].max = Math.max(statSum[icon].max, max);
  2080.                     } else {
  2081.                         statSum[icon].value += value;
  2082.                         statSum[icon].max += max;
  2083.                     }
  2084.                     if(!opts.sum) statSum[icon].count++;
  2085.                 }
  2086.             };
  2087.  
  2088.             let showStat = () => {
  2089.                 for(let icon in statSum) {
  2090.                     let count = statSum[icon].count;
  2091.                     let value = statSum[icon].value / count;
  2092.                     let max = statSum[icon].max / count;
  2093.                     let unit = statSum[icon].unit;
  2094.  
  2095.                     onecup.div(() => {
  2096.                         onecup.width(175);
  2097.                         onecup.float("left");
  2098.                         onecup.margin(10);
  2099.                         onecup.img({
  2100.                             src: "img/ui/" + icon,
  2101.                             width: 20
  2102.                         }, () => {
  2103.                             onecup.float("left");
  2104.                             onecup.margin_right(10);
  2105.                         });
  2106.                         onecup.text(value.toFixed(1));
  2107.                         if(max > 0)
  2108.                             onecup.text(" / " + max.toFixed(1));
  2109.                         onecup.text(" " + unit);
  2110.                     });
  2111.                 }
  2112.             };
  2113.             onecup.div(() => {
  2114.                 let units = commander.selection;
  2115.  
  2116.                 onecup.text("$" + units.reduce((a, b) => a + b.cost, 0));
  2117.  
  2118.                 if(units.filter(u => u.name === units[0].name).length === units.length) {
  2119.                     onecup.span(() => {
  2120.                         onecup.float("right");
  2121.                         onecup.i(() => onecup.text(units[0].spec.name || "Unnamed"));
  2122.                     });
  2123.                 }
  2124.  
  2125.                 onecup.hr();
  2126.  
  2127.                 for(let unit of units) {
  2128.                     stat("dps.png", "d/s", unit.weaponDPS * 16);
  2129.                     stat("damage.png", "d", unit.weaponDamage);
  2130.                     stat("mass.png", "kg", unit.mass);
  2131.                     stat("restart/battle.png", "dps·hp/$", unit.weaponDPS * 16 * unit.maxHP / unit.cost, {sum: false});
  2132.                     stat("range.png", "m", unit.weaponRange, 0, {max: true});
  2133.                     stat("arc.png", "°", unit.weaponArc, 0, {max: true});
  2134.                     stat("armor.png", "hp", unit.hp, unit.maxHP);
  2135.                     stat("energy.png", "e", unit.energy, unit.storeEnergy);
  2136.                     stat("speed.png", "m/s", v2.mag(unit.vel) * 16, unit.maxSpeed * 16, {sum: false});
  2137.                     stat("turnSpeed.png", "°/s", wrapAngle(unit.rot - unit._rot) * 180 / Math.PI * 16, unit.turnSpeed * 180 / Math.PI * 16, {sum: false});
  2138.                     stat("shield.png", "sh", unit.shield, unit.maxShield, {hideZero: true});
  2139.                     stat("burnDamage.png", "d", unit.burn, 0, {hideZero: true});
  2140.                     stat("jump.png", "m", unit.jumpDistance, 0, {hideZero: true, max: true});
  2141.                 }
  2142.  
  2143.                 showStat();
  2144.             });
  2145.         });
  2146.     }
  2147. }
  2148.  
  2149. window.body = function() {
  2150.     ub_window_body.apply(this, arguments);
  2151.     ub_drawBubble();
  2152. }
  2153.  
  2154. if(typeof(ub_intv) !== "undefined")
  2155.     clearInterval(ub_intv);
  2156. ub_intv = setInterval(onecup.refresh, 500);
  2157.  
  2158. battleMode.onkeydown = e => {
  2159.     if(e.key === "t") {
  2160.         ub_enabled = !ub_enabled;
  2161.     } else {
  2162.         return ub_battlemode_onkeydown.call(this, e);
  2163.     }
  2164. };
  2165.  
  2166.  
  2167.  
  2168. //ARTY COLOUR TWEAK
  2169.     types.ArtilleryBullet.prototype.draw = function() {
  2170.       var color, dist, size;
  2171.       types.ArtilleryBullet.__super__.draw.call(this);
  2172.       if (this.hitPos) {
  2173.         dist = Math.min(v2.distance(this.pos, this.hitPos), 1000);
  2174.         size = Math.pow(1.003, -dist) * this.aoe / 162;
  2175.         color = [255, 0, 0, 80];
  2176.         if (this && this.origin && this.origin.color)
  2177.             color = this.origin.color;
  2178.         baseAtlas.drawSprite("img/point02.png", this.hitPos, [this.aoe / 256, this.aoe / 256], 0, color);
  2179.         baseAtlas.drawSprite("img/fire02.png", this.hitPos, [size * 2, size * 2], 0, color);
  2180.       }
  2181.     };
  2182.  
  2183.  
  2184.  
  2185.    types.Bomb.prototype.draw = function() {
  2186.       var color, dist, size;
  2187.       if (!this.trail) {
  2188.         this.trail = new Trail(this.id, this.trailSize, this.trailTime, this.color, this.z);
  2189.       }
  2190.       this.trail.grow(this.pos);
  2191.       types.Bomb.__super__.draw.call(this);
  2192.       this.z = 1;
  2193.       this.trail.z = 1 - 0.0001;
  2194.       if (this.life === 28) {
  2195.         this.image = "parts/bombActive.png";
  2196.         playSound("sounds/weapons/wizzzz.wav");
  2197.       }
  2198.       if (this.hitPos) {
  2199.         dist = Math.min(v2.distance(this.pos, this.hitPos), 1000);
  2200.         size = Math.pow(1.003, -dist) * this.aoe / 162;
  2201.         color = [255, 0, 0, 80];
  2202.         if (this && this.origin && this.origin.color)
  2203.             color = this.origin.color;
  2204.         baseAtlas.drawSprite("img/point02.png", this.hitPos, [this.aoe / 256, this.aoe / 256], 0, color);
  2205.         baseAtlas.drawSprite("img/fire02.png", this.hitPos, [size * 2, size * 2], 0, color);
  2206.       }
  2207.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement