checkReady

draw a ring around planets and ships that are not marked ready

  1. // ==UserScript==
  2. // @name checkReady
  3. // @description draw a ring around planets and ships that are not marked ready
  4. // can't move ships marked ready
  5. //
  6. // @include http://play.planets.nu/*
  7. // @include http://test.planets.nu/*
  8. // @include http://planets.nu/*
  9. // @version 3.0.0
  10. // @homepage https://greasyfork.org/en/users/32642-stephen-piper
  11. // @namespace https://greasyfork.org/en/users/32642-stephen-piper
  12. // ==/UserScript==
  13.  
  14. function wrapper() {
  15. var showReady = false;
  16. var showBldg = false;
  17. var showHull = false;
  18. var selectedShip = null;
  19. var showShips = false;
  20. var showNatives = false;
  21. var showProduction = false;
  22. var displayLine = 0;
  23.  
  24. function checkReady() {
  25. }
  26. checkReady.prototype = {
  27. loadControls : function() {
  28.  
  29. this.clearData();
  30.  
  31. // if (vgapMap.prototype.spMenuItem != undefined) {
  32. vgaPlanets.prototype.spMenuItem("Check Ready", "checkReady", function() {
  33. state = !showReady;
  34. checkReady.prototype.clearShow();
  35. showReady = state;
  36. vgap.map.draw();
  37. });
  38.  
  39. vgaPlanets.prototype.spMenuItem("Show Buildings", "checkReady", function() {
  40. state = !showBldg;
  41. checkReady.prototype.clearShow();
  42. showBldg = state;
  43. vgap.map.draw();
  44. });
  45.  
  46. vgaPlanets.prototype.spMenuItem("SB Production", "checkReady", function() {
  47. state = !showProduction;
  48. checkReady.prototype.clearShow();
  49. showProduction = state;
  50. vgap.map.draw();
  51. });
  52.  
  53. vgaPlanets.prototype.spMenuItem("Show Natives", "checkReady", function() {
  54. state = !showNatives;
  55. checkReady.prototype.clearShow();
  56. showNatives = state;
  57. vgap.map.draw();
  58. });
  59.  
  60. vgaPlanets.prototype.spMenuItem("All Ships", "checkReady", function() {
  61. state = !showShips;
  62. checkReady.prototype.clearShow();
  63. showShips = state;
  64. vgap.map.draw();
  65. });
  66.  
  67. vgaPlanets.prototype.spMenuItem("Clear", "_massClear", function() {
  68. checkReady.prototype.clearData();
  69. });
  70. // }
  71. },
  72.  
  73. clearShow : function() {
  74. showReady = false;
  75. showBldg = false;
  76. showHull = false;
  77. showShips = false;
  78. showNatives = false;
  79. showProduction = false;
  80. },
  81.  
  82. clearData : function() {
  83. this.clearShow();
  84. selectedShip = null;
  85. displayLine = 0;
  86. },
  87.  
  88. nativeTaxAmount : function(c, ntr) {
  89. var nt = 0;
  90. if (c.nativeclans > 0) {
  91. if (c.race == 6 && ntr > 20) { // borg == 6
  92. ntr = 20;
  93. }
  94.  
  95. var nt = (c.nativeclans / 100) * (ntr / 10) * (c.nativegovernment / 5);
  96.  
  97. nt = c.nativetype == 5 ? 0 : nt; // amorphous == 5
  98. nt = c.nativetype == 6 ? 2 * nt : nt; // insect == 6
  99. nt = c.race == 1 ? 2 * nt : nt; // feds == 1
  100.  
  101. nt = Math.round(nt);
  102. }
  103. return nt;
  104. },
  105.  
  106. nativetaxsupport : function(c) {
  107. ns = c.clans;
  108. ns *= c.race == 1 ? 2 : 1; // feds == 1
  109. ns *= c.nativetype == 6 ? 2 : 1; // insect == 6
  110. return ns;
  111. },
  112. };
  113.  
  114.  
  115. var oldDraw = vgapMap.prototype.draw;
  116. vgapMap.prototype.draw = function(fast, ctx, skipUserContent, secondCanvas) {
  117. oldDraw.apply(this, arguments);
  118. if (!ctx)
  119. ctx = this.ctx;
  120.  
  121. // have to redraw ships because normal draw
  122. // copies the planets over the ships
  123. // draw ships not ready
  124. displayLine = -1;
  125.  
  126. for (var k = 0; k < vgap.ships.length; ++k) {
  127. var ship = vgap.ships[k];
  128. this.drawShip(ship, ctx)
  129. }
  130.  
  131. };
  132.  
  133. var oldDrawPlanet = vgapMap.prototype.drawPlanet;
  134. vgapMap.prototype.drawPlanet = function(planet, ctx, fullrender) {
  135. oldDrawPlanet.apply(this, arguments);
  136.  
  137. var x = this.screenX(planet.x);
  138. var y = this.screenY(planet.y);
  139. x2 = this.screenX(planet.x + 7.5 * 1.5);
  140. y2 = this.screenY(planet.y - (-1) * 6 * 1.5);
  141.  
  142.  
  143. // draw planets not ready
  144. if (planet.infoturn > 0) {
  145. if (vgap.player.id == planet.ownerid) {
  146. if (showBldg) {
  147. ctx.fillStyle = "lightgreen";
  148. ctx.fillText("m:" + planet.mines + " f:" + planet.factories + " d:" + planet.defense, x2, y2);
  149. }
  150. if (showReady) {
  151. if (planet.readystatus == 0) {
  152.  
  153. this.drawCircle(ctx, x, y, 13 * this.zoom, "orange", 2);
  154. }
  155.  
  156. var n = vgap.getStarbase(planet.id);
  157. if (n != null && n.readystatus == 0) {
  158.  
  159. this.drawCircle(ctx, x, y, 11 * this.zoom, "red", 2);
  160. }
  161. }
  162. if (showProduction) {
  163. if (planet.buildingstarbase) {
  164. ctx.fillStyle = "lightgreen";
  165. ctx.fillText("building starbase", x2, y2);
  166. }
  167. else if (planet.isbase) {
  168. var n = vgap.getStarbase(planet.id);
  169. if (n != null && n.isbuilding) {
  170.  
  171. ctx.fillStyle = "lightgreen";
  172. ctx.fillText(vgap.getHull(n.buildhullid).name, x2, y2);
  173. }
  174. }
  175. }
  176. if (showNatives && planet.nativeclans > 0) {
  177. if (planet.nativehappypoints < 30)
  178. ctx.fillStyle = "red";
  179. else if (planet.nativehappypoints < 70)
  180. ctx.fillStyle = "orange";
  181. else
  182. ctx.fillStyle = "lightgreen";
  183.  
  184. nt = checkReady.prototype.nativeTaxAmount(planet, planet.nativetaxrate);
  185. ns = checkReady.prototype.nativetaxsupport(planet);
  186. t = Math.min(nt, ns);
  187.  
  188. ctx.fillText(planet.nativeracename + " $" + t, x2, y2);
  189. }
  190. }
  191. if (showNatives && planet.nativeclans > 0) {
  192. ctx.fillStyle = "orange";
  193. ctx.fillText(planet.nativeracename, x2, y2);
  194. }
  195. }
  196. };
  197.  
  198. var oldDrawShip = vgapMap.prototype.drawShip;
  199. vgapMap.prototype.drawShip = function(ship, ctx) {
  200. oldDrawShip.apply(this, arguments);
  201.  
  202. // draw ships not ready had to redraw in draw()
  203. // because drawplanet() wrote over them
  204. if (showReady && ship.readystatus == 0 && vgap.player.id == ship.ownerid) {
  205. this.drawCircle(ctx, this.screenX(ship.x), this.screenY(ship.y), 16 * this.zoom, "yellow", 2);
  206. }
  207.  
  208. // if(showSelected) {
  209. // var use = vgap.shipScreen.ship;
  210. // if (use.ownerid != vgap.player.id) {
  211. // }
  212.  
  213. if (showHull && selectedShip != null && selectedShip.hullid == ship.hullid)
  214. this.drawCircle(ctx, this.screenX(ship.x), this.screenY(ship.y), 13 * this.zoom, "lightgreen", 2);
  215. if (showShips) {
  216. if (vgap.player.id == ship.ownerid)
  217. ctx.fillStyle = "lightgreen";
  218. else
  219. ctx.fillStyle = "red";
  220. x2 = this.screenX(ship.x + 7.5 * 1.5);
  221. y2 = this.screenY(ship.y - displayLine++ * 6 * 1.5);
  222. ctx.fillText(ship.id + ":" + vgap.getHull(ship.hullid).name, x2, y2);
  223. }
  224. };
  225.  
  226. var oldShipSelectorClick = vgapMap.prototype.shipSelectorClick;
  227. vgapMap.prototype.shipSelectorClick = function(event) {
  228.  
  229. var e = this.activeShip;
  230. if (e.readystatus > 0) // can't move ships marked ready
  231. return;
  232.  
  233. oldShipSelectorClick.apply(this, arguments);
  234. };
  235.  
  236. var oldLoadControls = vgapMap.prototype.loadControls;
  237. vgapMap.prototype.loadControls = function() {
  238. oldLoadControls.apply(this, arguments);
  239.  
  240. checkReady.prototype.loadControls();
  241. };
  242. }
  243.  
  244. var script = document.createElement("script");
  245. script.type = "application/javascript";
  246. script.textContent = "(" + wrapper + ")();";
  247.  
  248. document.body.appendChild(script);