Planets.nu - improved Planet List View

Miscellaneous Improvements to the Planet List View

  1. // ==UserScript==
  2. // @name Planets.nu - improved Planet List View
  3. // @description Miscellaneous Improvements to the Planet List View
  4. // @include http://planets.nu/home
  5. // @include http://play.planets.nu/*
  6. // @include http://planets.nu/*
  7. // @include http://test.planets.nu/*
  8. // @version 0.51
  9. // @namespace https://greasyfork.org/users/2860
  10. // ==/UserScript==
  11. // 0.1 - Includes warnings about unhappiness levels on the planet, dangerous planetary fc's, show how close planets are to producing SBs, What's Interesting View to highlight problems
  12. // 0.2 - Planets at dangerous temperatures are flagged in red or blue (hot/cold). New Notes Tab
  13. // 0.3 - Added Production View
  14. // 0.4 - Made headers more understandable (I hope). Added ground (not surface) mineral totals in tooltips
  15. // 0.5 - Adds compatibility with new Horwasp view
  16. // 0.51 - Fixed bug in Production View
  17. function wrapper () { // wrapper for injection
  18. oldShowPlanets = vgapDashboard.prototype.showPlanets;
  19.  
  20.  
  21. vgapDashboard.prototype.showPlanets = function (view) {
  22.  
  23. vgap.playSound("button");
  24.  
  25. vgap.closeSecond();
  26. this.content.empty();
  27.  
  28. //filter messages
  29. var html = "";
  30.  
  31. if (!view)
  32. view = 0;
  33.  
  34. var filterMenu = $("<ul class='FilterMenu'></ul>").appendTo(this.content);
  35. $("<li " + (view == 0 ? "class='SelectedFilter'" : "") + ">Colony View</li>").tclick(function() { vgap.dash.showPlanets(0); }).appendTo(filterMenu);
  36. $("<li " + (view == 1 ? "class='SelectedFilter'" : "") + ">Resource View</li>").tclick(function() { vgap.dash.showPlanets(1); }).appendTo(filterMenu);
  37. if (vgap.player.raceid == 12)
  38. $("<li " + (view == 2 ? "class='SelectedFilter'" : "") + ">Ship Building</li>").tclick(function () { vgap.dash.showPlanets(12); }).appendTo(filterMenu);
  39. $("<li " + (view == 2 ? "class='SelectedFilter'" : "") + ">Notes View</li>").tclick(function() { vgap.dash.showPlanets(2); }).appendTo(filterMenu);
  40. $("<li " + (view == 3 ? "class='SelectedFilter'" : "") + ">Production View</li>").tclick(function() { vgap.dash.showPlanets(3); }).appendTo(filterMenu);
  41. $("<li " + (view == 5 ? "class='SelectedFilter'" : "") + ">What's Interesting</li>").tclick(function() { vgap.dash.showPlanets(5); }).appendTo(filterMenu);
  42. //loop through all planets and show the ones owned by this player
  43. html = "<div class='DashPane' style='height:" + ($("#DashboardContent").height() - 70) + "px;'>";
  44.  
  45. html += "<table id='PlanetTable' align='left' class='CleanTable' border='0' width='100%' style='cursor:pointer;'><thead>";
  46. html += "<th></th><th align='left'>Id</th><th align='left'>Name</th>";
  47. if (view == 1)
  48. html += "<th title='Megacredits' align='left'>MC</th><th title='Supplies' align='left'>S</th><th title='Neutronium' align='left'>N</th><th title='Duranium' align='left'>D</th><th title='Tritanium' align='left'>T</th><th title='Molybdenum' align='left'>M</th><th title='Ground Neutronium (unmined)' align='left'>GN</th><th title='Ground Duranium (unmined)' align='left'>GD</th><th title='Ground Tritanium (unmined)' align='left'>GT</th><th title='Ground Molybdenum (unmined)' align='left'>GM</th><th title='Neutronium Density' align='left'>DN</th><th title='Duranium Density' align='left'>DD</th><th title='Tritanium Density' align='left'>DT</th><th title='Molybdenum Density' align='left'>DM</th>";
  49. if ((view == 0)||(view==5))
  50. html += "<th title='Starbase' align='left'>SB</th><th align='left' class=\"{sorter: 'text'}\">FC</th><th title='Temperature' align='left'>T</th><th title='Colonists' align='left'>Cols</th><th title='Colonist Tax Rate' align='left'>Tx</th><th title='Colonist Happiness' align='left'>Hp</th><th title='Colonist Happiness Change' align='left'>+/-</th><th title='Natives' align='left'>Natives</th><th title='Native Government' align='left'>Gov</th><th title='Native Population' align='left'>Pop</th><th title='Native Tax Rate' align='left'>Tx</th><th title='Native Happiness' align='left'>Hp</th><th title='Native Happiness Change' align='left'>+/-</th><th title='Ready Checkbox Status' align='left'>R</th>";
  51. if (view==2)
  52. html += "<th title='Starbase' align='left'>SB</th><th align='left' class=\"{sorter: 'text'}\">FC</th><th title='Colonists' align='left'>Cols</th><th title='Natives' align='left'>Natives</th><th title='Native Population' align='left'>Pop</th><th title='Notes' align='left'>Notes</th><th title='Ready Checkbox Status' align='left'>R</th>";
  53. if (view==3)
  54. html += "<th title='Starbase' align='left'>SB</th><th title='Total MC Generated per Turn' align='left'>MC/T</th><th title='Total Supplies Generated per Turn' align='left'>Supplies/T</th><th title='Total Supplies + MC Generated per Turn' align='left'>S+MC/T</th><th title='Neutronium Produced per Turn' align='left'>Neut/T</th><th title='Duranium Produced per Turn' align='left'>Dur/T</th><th title='Tritanium Produced per Turn' align='left'>Tri/T</th><th title='Molybdenum Produced per Turn' align='left'>Moly/T</th><th title='Ready Checkbox Status' align='left'>R</th>";
  55. if (view == 12)
  56. html += "<th title='Hull Image' align='left'></th><th title='Hull' align='left'>Hull</th><th title='Cargo' align='left'>Cargo</th><th title='Speed' align='left'>Speed</th><th title='Target' align='left'>Target</th><th title='Accelerator' align='left'>Accelerator</th>";
  57.  
  58. html += "</thead><tbody id='PlanetRows'></tbody></table></div>";
  59.  
  60. this.pane = $(html).appendTo(this.content);
  61.  
  62. for (var i = 0; i < vgap.myplanets.length; i++) {
  63. var planet = vgap.myplanets[i];
  64. //var base = vgap.getStarbase(planet.id) != null ? "X" : "";
  65. var base;
  66. var show=0; //for what's interesting view
  67. var temphtml="";
  68. temphtml += "<tr class='RowSelect'><td><img class='TinyIcon' src='" + planet.img + "'/></td><td>" + planet.id + "</td><td>" + planet.name + "</td>";
  69. if (view == 1)
  70. temphtml += "<td>" + planet.megacredits + "</td><td>" + planet.supplies + "</td><td>" + planet.neutronium + "</td><td>" + planet.duranium + "</td><td>" + planet.tritanium + "</td><td>" + planet.molybdenum + "</td><td>" + planet.groundneutronium + "</td><td>" + planet.groundduranium + "</td><td>" + planet.groundtritanium + "</td><td>" + planet.groundmolybdenum + "</td><td>" + planet.densityneutronium + "</td><td>" + planet.densityduranium + "</td><td>" + planet.densitytritanium + "</td><td>" + planet.densitymolybdenum + "</td></tr>";
  71. if (view ==2)
  72. {
  73. if (vgap.getStarbase(planet.id) != null)
  74. temphtml += "<td style='color:white' title='Planet has SB'>" + "X" + "</td>";
  75. else
  76. temphtml += "<td>" + "" + "</td>";
  77. temphtml += "<td>" + planet.friendlycode + "</td><td>" + planet.clans * 100 + "</td>";
  78. if (planet.nativeclans > 0)
  79. temphtml += "<td>" + planet.nativeracename + "</td><td>" + planet.nativeclans * 100 + "</td>";
  80. else
  81. temphtml += "<td></td><td></td>";
  82. var note = vgap.getNote(planet.id, 1);
  83. if (note != null)
  84. temphtml += '<td>' + note.body.replace(/\n/g, "<br/>") + '</td>';
  85. else
  86. temphtml += '<td></td>';
  87. temphtml += "<td>" + (planet.readystatus > 0 ? (planet.readystatus == 1 ? "-" : "+") : "") + "</td></tr>";
  88. }
  89. if (view == 12) {
  90. if (planet.podhullid > 0) {
  91. var hull = vgap.getHull(planet.podhullid);
  92. var targettext = "Deep Space";
  93. if (planet.target)
  94. targettext = planet.target.id + ": " + planet.target.name;
  95. targettext += " (" + planet.targetx + ", " + planet.targety + ")";
  96. html += "<td><img class='TinyIcon' src='" + hullImg(planet.podhullid) + "'/></td><td>" + hull.name + "</td>";
  97. if (nu.isHullPod(planet.podhullid)) {
  98. html += "<td>" + planet.podcargo + " / " + hull.cargo + "</td><td>" + planet.podspeed + "</td><td>" + targettext + "</td>";
  99. if (planet.builtdefense > 0) { //accelerator target
  100. var acc = vgap.getShip(planet.builtdefense);
  101. html += "<td>" + acc.id + " (" + acc.x + ", " + acc.y + ")</td>";
  102. }
  103. else
  104. html += "<td/>";
  105. }
  106. else
  107. html += "<td/><td/><td/><td/>";
  108. }
  109. else
  110. html += "<td/><td/><td/><td/><td/><td/>";
  111. html += "</tr>";
  112. }
  113. if (view == 3)
  114. {
  115. if (vgap.getStarbase(planet.id) != null)
  116. temphtml += "<td style='color:white' title='Planet has SB'>" + "X" + "</td>";
  117. else
  118. temphtml += "<td>" + "" + "</td>";
  119. var SuppliesTotal=planet.factories;
  120. //--------------------------MC Produced-----------------------------------
  121. var colTax = MyColTaxAmount(planet);
  122. var nativeTax = myNativeTaxAmount(planet);
  123.  
  124. temphtml += "<td>" + (colTax+nativeTax) + "</td>";
  125. //--------------------------MC Produced-----------------------------------
  126. //--------------------------Supplies Produced-----------------------------------
  127. if (planet.nativeracename=="Bovinoid")
  128. {
  129. var BovSupplies=Math.floor(planet.nativeclans/100);
  130. SuppliesTotal=((planet.clans>BovSupplies)?BovSupplies:planet.clans)+planet.factories;
  131. }
  132. temphtml += "<td>" + SuppliesTotal + "</td>";
  133. //--------------------------Supplies Produced-----------------------------------
  134. temphtml += "<td>" + (SuppliesTotal+colTax+nativeTax) + "</td>";
  135. var neutRate=0;
  136. var durRate=0;
  137. var tritRate=0;
  138. var molyRate=0;
  139. if (planet.mines>0)
  140. {
  141. var neutText=vgap.miningText(planet, planet.groundneutronium, planet.densityneutronium, planet.mines);
  142. var durText=vgap.miningText(planet, planet.groundduranium, planet.densityduranium, planet.mines);
  143. var tritText=vgap.miningText(planet, planet.groundtritanium, planet.densitytritanium, planet.mines);
  144. var molyText=vgap.miningText(planet, planet.groundmolybdenum, planet.densitymolybdenum, planet.mines);
  145. neutRate=neutText.slice(7,-5);
  146. durRate=durText.slice(7,-5);
  147. tritRate=tritText.slice(7,-5);
  148. molyRate=molyText.slice(7,-5);
  149. }
  150. if (planet.groundneutronium==neutRate && neutRate<6)
  151. temphtml += "<td style='color:grey' title='mining at subsistence level. Ground minerals " + planet.groundneutronium +"'>" + neutRate + "</td>";
  152. else if (planet.groundneutronium<(neutRate*2))
  153. {
  154. temphtml += "<td style='color:red' title='only 1 turn left of full mining at this rate. Ground minerals " + planet.groundneutronium +"'>" + neutRate + "</td>";
  155. show=1;
  156. }
  157. else if (planet.groundneutronium<(neutRate*5))
  158. temphtml += "<td style='color:yellow' title='only 5 turn left of mining at this rate. Ground minerals " + planet.groundneutronium +"'>" + neutRate + "</td>";
  159. else temphtml += "<td title='Ground minerals " + planet.groundneutronium +"'>" + neutRate + "</td>";
  160.  
  161. if (planet.groundduranium==durRate && durRate<6)
  162. temphtml += "<td style='color:grey' title='mining at subsistence level. Ground minerals " + planet.groundduranium +"'>" + durRate + "</td>";
  163. else if (planet.groundduranium<(durRate*2))
  164. {
  165. temphtml += "<td style='color:red' title='only 1 turn left of full mining at this rate. Ground minerals " + planet.groundduranium +"'>" + durRate + "</td>";
  166. show=1;
  167. }
  168. else if (planet.groundduranium<(durRate*5))
  169. temphtml += "<td style='color:yellow' title='only 5 turn left of mining at this rate. Ground minerals " + planet.groundduranium +"'>" + durRate + "</td>";
  170. else temphtml += "<td title='Ground minerals " + planet.groundduranium +"'>" + durRate + "</td>";
  171.  
  172. if (planet.groundtritanium==tritRate && tritRate<6)
  173. temphtml += "<td style='color:grey' title='mining at subsistence level. Ground minerals " + planet.groundtritanium +"'>" + tritRate + "</td>";
  174. else if (planet.groundtritanium<(tritRate*2))
  175. {
  176. temphtml += "<td style='color:red' title='only 1 turn left of full mining at this rate. Ground minerals " + planet.groundtritanium +"'>" + tritRate + "</td>";
  177. show=1;
  178. }
  179. else if (planet.groundtritanium<(tritRate*5))
  180. temphtml += "<td style='color:yellow' title='only 5 turn left of mining at this rate. Ground minerals " + planet.groundtritanium +"'>" + tritRate + "</td>";
  181. else temphtml += "<td title='Ground minerals " + planet.groundtritanium +"'>" + tritRate + "</td>";
  182.  
  183. if (planet.groundmolybdenum==molyRate && molyRate<6)
  184. temphtml += "<td style='color:grey' title='mining at subsistence level. Ground minerals " + planet.groundmolybdenum +"'>" + molyRate + "</td>";
  185. else if (planet.groundmolybdenum<(molyRate*2))
  186. {
  187. temphtml += "<td style='color:red' title='only 1 turn left of full mining at this rate. Ground minerals " + planet.groundmolybdenum +"'>" + molyRate + "</td>";
  188. show=1;
  189. }
  190. else if (planet.groundmolybdenum<(molyRate*5))
  191. temphtml += "<td style='color:yellow' title='only 5 turn left of mining at this rate. Ground minerals " + planet.groundmolybdenum +"'>" + molyRate + "</td>";
  192. else temphtml += "<td title='Ground minerals " + planet.groundmolybdenum +"'>" + molyRate + "</td>";
  193.  
  194. temphtml += "<td>" + (planet.readystatus > 0 ? (planet.readystatus == 1 ? "-" : "+") : "") + "</td></tr>";
  195. }
  196. if ((view == 0)||(view==5)) {
  197. //-------------------Star Base-------------------------
  198. if (vgap.getStarbase(planet.id) != null)
  199. temphtml += "<td style='color:white' title='Planet has SB'>" + "X" + "</td>";
  200. else
  201. {
  202. var count=5;
  203. if ((planet.megacredits+planet.supplies)>=900) count--;
  204. if (planet.duranium>=120) count--;
  205. if (planet.tritanium>=402) count--;
  206. if (planet.molybdenum>=340) count--;
  207. if (count==1)
  208. {
  209. temphtml += "<td style='color:green' title='Planet has resources to produce SB'>" + "*" + "</td>";
  210. show=1;
  211. }
  212. else if (count==2)
  213. temphtml += "<td style='color:yellow' title='Planet is missing only one resource to produce SB'>" + "*" + "</td>";
  214. else if (count==3)
  215. temphtml += "<td style='color:red' title='Planet is missing only two resources to produce SB'>" + "*" + "</td>";
  216. else
  217. temphtml += "<td>" + "" + "</td>";
  218. }
  219. //-------------------Star Base-------------------------
  220. //-------------------Dangerous FCs---------------------
  221. if (((planet.friendlycode.charAt(0)=='m') || (planet.friendlycode.charAt(0)=='M')) && ((planet.friendlycode.charAt(1)=='f') || (planet.friendlycode.charAt(1)=='F')))
  222. {
  223. temphtml += "<td style='color:red' title='WARNING: MFx Friendly Code set. This can leave minefield vulnerable to enemies'>" + planet.friendlycode + "</td>";
  224. show=1;
  225. }
  226. else if (((planet.friendlycode.charAt(0)=='b') || (planet.friendlycode.charAt(0)=='B')) && ((planet.friendlycode.charAt(1)=='u') || (planet.friendlycode.charAt(1)=='U')) && ((planet.friendlycode.charAt(2)=='m') || (planet.friendlycode.charAt(2)=='M')))
  227. {
  228. temphtml += "<td style='color:yellow' title='WARNING: BUM Friendly Code set. This will beam up money to all ships in orbit'>" + planet.friendlycode + "</td>";
  229. show=1;
  230. }
  231. else
  232. temphtml += "<td>" + planet.friendlycode + "</td>";
  233. //-------------------Dangerous FCs---------------------
  234. //-------------------Dangerous Temps-------------------
  235. if (planet.temp<15) temphtml += "<td style='color:aqua' title='Planet is Arctic temperature'>" + planet.temp + "</td>";
  236. else if (planet.temp>84) temphtml += "<td style='color:red' title='Planet is Desert temperature'>" + planet.temp + "</td>";
  237. else temphtml += "<td>" + planet.temp + "</td>";
  238. //-------------------Dangerous Temps-------------------
  239. temphtml +="<td>" + planet.clans * 100 + "</td><td>" + planet.colonisttaxrate + "</td>";
  240. //-------------------Unhappy Colonists---------------------
  241. if (((planet.colonisthappypoints<70)&&(planet.colhappychange < 0)) || (planet.colonisthappypoints<40)) show=1;
  242. if (planet.colonisthappypoints<40)
  243. temphtml += "<td style='color:red' title='Colonists are destroying the planet!'>" + planet.colonisthappypoints + "</td>";
  244. else if (planet.colonisthappypoints<70)
  245. temphtml += "<td style='color:yellow' title='Colonists are getting dangerously unhappy, and will no longer grow in population'>" + planet.colonisthappypoints + "</td>";
  246. else
  247. //-------------------Unhappy Colonists---------------------
  248. temphtml += "<td>" + planet.colonisthappypoints + "</td>";
  249. temphtml += "<td" + (planet.colhappychange < 0 ? " class='WarnText' " : "") + ">" + planet.colhappychange + "</td>";
  250. if (planet.nativeclans > 0)
  251. {
  252. temphtml += "<td>" + planet.nativeracename + "</td><td>" + planet.nativegovernmentname + "</td><td>" + planet.nativeclans * 100 + "</td><td>" + planet.nativetaxrate + "</td>";
  253. //-------------------Unhappy Natives---------------------
  254. if (((planet.nativehappypoints<70)&&(planet.nativehappychange<0)) || (planet.nativehappypoints<40)) show=1;
  255. if (planet.nativehappypoints<40)
  256. temphtml += "<td style='color:red' title='Natives are destroying the planet!'>" + planet.nativehappypoints + "</td>";
  257. if (planet.nativehappypoints<70)
  258. temphtml += "<td style='color:yellow' title='Natives are getting dangerously unhappy, and will no longer grow in population'>" + planet.nativehappypoints + "</td>";
  259. else
  260. //-------------------Unhappy Natives---------------------
  261. temphtml += "<td>" + planet.nativehappypoints + "</td>";
  262. temphtml += "<td" + (planet.nativehappychange < 0 ? " class='WarnText' " : "") + ">" + planet.nativehappychange + "</td>";
  263.  
  264. }
  265. else
  266. temphtml += "<td></td><td></td><td></td><td></td><td></td><td></td>";
  267. temphtml += "<td>" + (planet.readystatus > 0 ? (planet.readystatus == 1 ? "-" : "+") : "") + "</td></tr>";
  268. }
  269. if ((view!=5)||(show==1))
  270. {
  271. var select = function(id) { return function() { vgap.map.selectPlanet(id); }; };
  272. $(temphtml).click(select(planet.id)).appendTo("#PlanetRows");
  273. }
  274. }
  275. //this.content.fadeIn();
  276. $("#PlanetTable").tablesorter();
  277. this.pane.jScrollPane();
  278.  
  279. // vgap.action added for the assistant (Alex):
  280. vgap.CurrentView = "showPlanets";
  281. vgap.showPlanetsViewed = 1;
  282. };
  283.  
  284. myNativeTaxAmount= function (planet) {
  285.  
  286. //amorph none
  287. if (planet.nativetype == 5)
  288. return 0;
  289.  
  290. //cyborg max 20%
  291. var nativetaxrate = planet.nativetaxrate;
  292. var player = vgap.getPlayer(planet.ownerid);
  293. if (player != null) {
  294. if (player.raceid == 6 && nativetaxrate > 20)
  295. nativetaxrate = 20;
  296. }
  297.  
  298. var val = Math.round(nativetaxrate * planet.nativetaxvalue / 100 * planet.nativeclans / 1000);
  299.  
  300. if (val > planet.clans)
  301. val = planet.clans;
  302.  
  303. //player tax rate (fed bonus)
  304. var taxbonus = 1;
  305. if (vgap.advActive(2))
  306. taxbonus = 2;
  307. val = val * taxbonus;
  308.  
  309. //insectoid bonus
  310. if (planet.nativetype == 6)
  311. val = val * 2;
  312.  
  313. if (val > 5000)
  314. val = 5000;
  315.  
  316. return val;
  317. };
  318. MyColTaxAmount= function (planet) {
  319. var colTax = Math.round(planet.colonisttaxrate * planet.clans / 1000);
  320. //player tax rate (fed bonus)
  321. var taxbonus = 1;
  322. if (vgap.advActive(2))
  323. taxbonus = 2;
  324. colTax = colTax * taxbonus;
  325.  
  326. if (colTax > 5000)
  327. colTax = 5000;
  328. return (colTax)
  329. };
  330. } //wrapper for injection
  331.  
  332. var script = document.createElement("script");
  333. script.type = "application/javascript";
  334. script.textContent = "(" + wrapper + ")();";
  335.  
  336. document.body.appendChild(script);