Planets.nu Hover Prediction

NU Starmap-Plugin, that hovers more info for Planets, Ships and Minerals also for the next turn

  1. // ==UserScript==
  2. // @name Planets.nu Hover Prediction
  3. // @namespace quapla/Hover Prediction
  4. // @date 2016-05-26
  5. // @author Quapla
  6. // @grant none
  7. // @description NU Starmap-Plugin, that hovers more info for Planets, Ships and Minerals also for the next turn
  8. // @include http://planets.nu/home
  9. // @include http://planets.nu/games/*
  10. // @include http://play.planets.nu/*
  11. // @include http://*.planets.nu/*
  12. // @include http://planets.nu/*
  13. // @homepage https://greasyfork.org/de/scripts/19831-planets-nu-hover-prediction
  14. // @version 0.4.10
  15. // ==/UserScript==
  16.  
  17. // Reference Jim Clark's Planets.nu improved hover text (V2): https://greasyfork.org/en/scripts/2618-planets-nu-improved-hover-text
  18. // Reference Big Beefer's Planet.nu improved hovertext (V3): https://greasyfork.org/en/scripts/2618-planets-nu-improved-hover-text
  19. // Reference Stephen Piper's hoverTextbox: https://greasyfork.org/en/scripts/17959-hovertextbox
  20. // Reference helmet's Planets.nu ship predictor: http://userscripts-mirror.org/scripts/show/146137
  21. // Reference Kero van Gelder: Redraw and Filter: http://chmeee.org/ext/planets.nu/RedrawAndFilter.user.js
  22. // Colaboration kedalion's Enemy Ship List Plugin: https://greasyfork.org/en/scripts/5994-planets-nu-enemy-ship-list-plugin
  23.  
  24. /*------------------------------------------------------------------------------
  25. 0.1 Initial Workout
  26. 0.2 Impelemntation of Jim Clark's and Big Beefer's code
  27. 0.3 Implementation of Stephen Piper's code
  28. 0.3 New Layout and diferent point of views
  29. 0.4 Implementation of helmet's code - Official Beta Release to start communication
  30. 0.4.3 Changed views, planned planets/ships are now green, added more settings (take care to click the checkboxes!)
  31. 0.4.4 Fixed bdm/bum cases
  32. 0.4.8 Changed views, added Enemey-Ships, and VPA-style net cargo info in brackets. Colaboration with Enemy Ship
  33. 0.4.10 Bugfix, thanx to Frostriese
  34. ------------------------------------------------------------------------------*/
  35.  
  36. function wrapper() { // wrapper for injection
  37. // Functions for Show Hover
  38. function hitText() {}
  39.  
  40. hitText.prototype = {
  41. nativeTaxAmount : function (c, ntr) // How much do natives pay at 'c' with 'ntr'-taxrate - limited by natives/taxrate
  42. {
  43. var nt = 0;
  44. if (c.nativeclans > 0) {
  45. if (c.race == 6 && ntr > 20) { // borg == 6 can be taxed with 20% max
  46. ntr = 20;
  47. }
  48.  
  49. nt = (c.nativeclans / 100) * (ntr / 10) * (c.nativegovernment / 5);
  50.  
  51. nt = c.nativetype == 5 ? 0 : nt; // amorphous == 5 wont pay
  52. nt *= c.race == 1 ? 2 : 1; // feds == 1 pay twice
  53. nt *= c.nativetype == 6 ? 2 : 1; // insect == 6 pay twice
  54.  
  55. nt = Math.round(nt);
  56. }
  57. return nt;
  58. },
  59.  
  60. nativesupportedtax : function (c) // How taxes can we receive at 'c' - limited by clans
  61. {
  62. var ns = c.clans;
  63. ns *= c.race == 1 ? 2 : 1; // feds == 1
  64. ns *= c.nativetype == 6 ? 2 : 1; // insect == 6
  65. return ns;
  66. },
  67.  
  68. showMin : function (txt, surface, change, ground, chtxt) // Shows | 00000000 | TXT | CHTXT 0000 | (00000)
  69. {
  70. var showtxt = "<td style='text-align:right;'>" + addCommas(surface) + "&nbsp</td>";
  71. showtxt += "<td>" + txt + "&nbsp</td>";
  72. showtxt += "<td style='text-align:right;'>&nbsp" + chtxt + addCommas(change, true) + "&nbsp</td>";
  73. showtxt += "<td style='text-align:right;";
  74. if (ground < 100) {
  75. showtxt += " color:#ff0000;";
  76. } // Red
  77. else if (ground < 1000) {
  78. showtxt += " color:#ffa500;";
  79. } // Orange
  80. else if (ground > 10000) {
  81. showtxt += " color:#90ee90;";
  82. } // Green
  83. showtxt += "'>&nbsp(" + addCommas(ground) + ")</td>";
  84. return showtxt;
  85. },
  86.  
  87. // Reference: Redraw and Filter, Kero van Gelder, http://chmeee.org/ext/planets.nu/RedrawAndFilter.user.js
  88. shortHullName : function (hull) {
  89. var name;
  90. switch (hull.id) {
  91. case 15:
  92. return "SDSF";
  93. case 16:
  94. return "MDSF";
  95. case 17:
  96. return "LDSF";
  97. case 18:
  98. return "STF";
  99. case 28:
  100. return "Fearless";
  101. case 69:
  102. return "SSD";
  103. default:
  104. if (hull.id >= 1000)
  105. return hull.name;
  106. var hullName = hull.name;
  107. var m;
  108. if (m = hullName.match(/^(([^ ]+).*) Class /))
  109. name = m[2].match(/\d/) ? m[2] : m[1];
  110. else if (m = hullName.match(/^(([^ ]+) [^ ]+)/))
  111. name = m[2].match(/\d/) ? m[2] : hullName;
  112. else
  113. name = hullName;
  114. return name;
  115. }
  116. },
  117.  
  118. GetMaxPop : function (hit) // Gets max. Population on Planet hit
  119. {
  120. /// Population in popup text
  121. //////////////////////
  122. var planetOwner = null;
  123. var maxPop = 0;
  124.  
  125. // Do we have a temp scan?
  126. if (hit.temp >= 0 && hit.temp <= 100) {
  127. // Use your race if planet unowned
  128. if (hit.ownerid == 0)
  129. planetOwner = vgap.getPlayer(vgap.player.id);
  130. else
  131. planetOwner = vgap.getPlayer(hit.ownerid);
  132. // Find max pop
  133. // xtal
  134. if (planetOwner.raceid == 7) {
  135. maxPop = 1000 * hit.temp;
  136. } else {
  137. maxPop = Math.round(Math.sin(3.14 * (100 - hit.temp) / 100) * 100000);
  138. if (hit.temp > 84)
  139. maxPop = Math.floor((20099.9 - (200 * hit.temp)) / 10);
  140. if (hit.temp < 15)
  141. maxPop = Math.floor((299.9 + (200 * hit.temp)) / 10);
  142. // Cols, Rebles, Fascists, Bots
  143. if (hit.temp > 80 && (planetOwner.raceid == 4 || planetOwner.raceid == 9 || planetOwner.raceid == 10 || planetOwner.raceid == 11))
  144. maxPop = 60;
  145. // Rebels
  146. if (hit.temp <= 19 && planetOwner.raceid == 10)
  147. maxPop = 90000;
  148. }
  149.  
  150. if (hit.debrisdisk > 0) {
  151. maxPop = 0;
  152. if (vgap.getStarbase(maxPop.id) != null) {
  153. maxPop = 500;
  154. }
  155. }
  156. }
  157. return maxPop;
  158.  
  159. },
  160.  
  161. GetPopGrowth : function (hit) // Gets growth of Population
  162. {
  163. var planet = hit;
  164. var player = vgap.getPlayer(hit.ownerid);
  165. var raceId = player.raceid;
  166.  
  167. var colGrowth = 0;
  168. if ((planet.colonisthappypoints + vgap.colonistTaxChange(planet)) >= 70 && planet.clans > 0) {
  169. var colMax = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 100000);
  170.  
  171. //crystals like it hot
  172. if (raceId == 7) {
  173. colMax = 1000 * planet.temp;
  174. colGrowth = Math.round(((planet.temp / 100) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5))));
  175. if (vgap.advActive(47))
  176. colGrowth = Math.round((((planet.temp * planet.temp) / 4000) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5))));
  177. } else if (planet.temp >= 15 && planet.temp <= 84)
  178. colGrowth = Math.round(Math.sin(3.14 * ((100 - planet.temp) / 100)) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5)));
  179.  
  180. //slows down over 6,600,000
  181. if (planet.clans > 66000)
  182. colGrowth = Math.round(colGrowth / 2);
  183.  
  184. //planetoids do not have an atmosphere
  185. if (planet.debrisdisk > 0)
  186. colGrowth = 0;
  187.  
  188. //check against max
  189. if ((planet.clans + colGrowth) > colMax)
  190. colGrowth = colMax - planet.clans;
  191.  
  192. //100 and 0 degree planets
  193. if (colGrowth < 0)
  194. colGrowth = 0;
  195. }
  196.  
  197. if (colGrowth == 0)
  198. colGrowth = this.GetsmaxPop(hit, true);
  199.  
  200. if (planet.nativetype == 5) // angry Amorphs...
  201. if (hit.nativetaxrate + vgap.nativeTaxChange(planet) >= 70)
  202. colGrowth -= 5;
  203. else if (hit.nativetaxrate + vgap.nativeTaxChange(planet) >= 70)
  204. colGrowth -= 20;
  205. else
  206. colGrowth -= 40;
  207.  
  208. return colGrowth;
  209. },
  210.  
  211. GetMinPopGrow : function (hit) {
  212. var player = vgap.getPlayer(hit.ownerid);
  213. var raceId = player.raceid;
  214. var planet = hit;
  215. var grow = 1;
  216.  
  217. if (planet.nativetype == 5) // angry Amorphs...
  218. grow += 5;
  219.  
  220. for (i = 1; i<300; i++) {
  221. if (raceId == 7) {
  222. if (vgap.advActive(47))
  223. colGrowth = Math.round((((planet.temp * planet.temp) / 4000) * (i / 20) * (5 / (planet.colonisttaxrate + 5))));
  224. else
  225. colGrowth = Math.round(((planet.temp / 100) * (i / 20) * (5 / (planet.colonisttaxrate + 5))));
  226. } else {
  227. if (planet.temp >= 15 && planet.temp <= 84)
  228. colGrowth = Math.round(Math.sin(3.14 * ((100 - planet.temp) / 100)) * (i / 20) * (5 / (planet.colonisttaxrate + 5)));
  229. else {
  230. colGrowth = 0;
  231. break;
  232. }
  233. }
  234. if (colGrowth >= grow)
  235. break;
  236. }
  237. if (i >= 299 || colGrowth == 0)
  238. i = 0;
  239. return i;
  240. },
  241.  
  242. GetsmaxPop : function (hit, getGrowth) { // getGrows: TRUE Col growth, FALSE: max supported
  243. var player = vgap.getPlayer(hit.ownerid);
  244. var raceId = player.raceid;
  245. var planet = hit;
  246. var climateDeathRate = 10;
  247. var maxSupported = 0;
  248. var colGrowth = 0;
  249.  
  250. //crystal calculation
  251. if (raceId == 7)
  252. maxSupported = planet.temp * 1000;
  253. else {
  254. //all others
  255. maxSupported = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 100000);
  256. if (planet.temp > 84)
  257. maxSupported = Math.floor((20099.9 - (200 * planet.temp)) / climateDeathRate);
  258. else if (planet.temp < 15)
  259. maxSupported = Math.floor((299.9 + (200 * planet.temp)) / climateDeathRate);
  260. }
  261.  
  262. //Fascist, Robots, Rebels, Colonies can support a small colony of 60 clans on planets over 80 degrees
  263. if (raceId == 4 || raceId == 9 || raceId == 10 || raceId == 11) {
  264. if (planet.temp > 80)
  265. maxSupported = Math.max(maxSupported, 60);
  266. }
  267.  
  268. //rebel arctic planet advantage
  269. if (planet.temp <= 19 && raceId == 10)
  270. maxSupported = Math.max(maxSupported, 90000);
  271.  
  272. //planetoids do not have an atmosphere
  273. if (planet.debrisdisk > 0) {
  274. maxSupported = 0;
  275. if (vgap.getStarbase(planet.id) != null)
  276. maxSupported = 500;
  277. }
  278.  
  279. if (!getGrowth)
  280. return maxSupported;
  281.  
  282. //determine how much we are overpopulated
  283. var overPopulation = Math.ceil((planet.clans - maxSupported) * (climateDeathRate / 100));
  284. if (overPopulation > 0) {
  285. //recalculate maxsupported/overpopulation
  286. maxSupported = maxSupported + Math.round(planet.supplies * 10 / 40);
  287. overPopulation = Math.ceil((planet.clans - maxSupported) * (climateDeathRate / 100));
  288.  
  289. //update population
  290. colGrowth = -1 * Math.max(0, overPopulation);
  291. }
  292. return colGrowth;
  293. },
  294.  
  295. GetMinPop : function (hit) // Gets minimal Population on Hit
  296. {
  297. /// Population in popup text
  298. //////////////////////
  299. var planetOwner = null;
  300. var minPop = 0;
  301.  
  302. // Do we have a temp scan?
  303. if (hit.temp >= 0 && hit.temp <= 100) {
  304.  
  305. // Use your race if planet unowned
  306. if (hit.ownerid == 0)
  307. planetOwner = vgap.getPlayer(vgap.player.id);
  308. else
  309. planetOwner = vgap.getPlayer(hit.ownerid);
  310.  
  311. // Find min growth pop
  312. var targetGrowth = 1;
  313. // Worms!
  314. if (hit.nativetype == 5)
  315. targetGrowth = 6;
  316. // xtal
  317. if (planetOwner.raceid == 7) {
  318. minPop = Math.floor(targetGrowth * 11 / (hit.temp / 100));
  319. if (vgap.advActive(47)) {
  320. minPop = Math.floor(targetGrowth * 11 / hit.temp * hit.temp / 4000);
  321. }
  322. if (hit.temp < 15)
  323. minPop = 0;
  324.  
  325. } else {
  326. // This should just be a formula like: minPop = Math.floor(targetGrowth * 11 / Math.sin(3.14*(100-hit.temp)/100)));
  327. // But that is off but a bit. This seems more acurate, but is still slightly off the chart I was going off. Which may be wrong too!
  328. // ...
  329. for (minPop = 10; minPop < 300; minPop++) {
  330. var growth = Math.round(Math.sin(3.14 * ((100 - hit.temp) / 100)) * minPop / 20);
  331. if (growth >= targetGrowth)
  332. break;
  333. }
  334. if (hit.temp < 15 || hit.temp > 84)
  335. minPop = 0;
  336. if (minPop >= 299)
  337. minPop = 0;
  338. }
  339.  
  340. if (hit.debrisdisk > 0) {
  341. minPop = 0;
  342. }
  343.  
  344. }
  345. //////////////////////
  346. return minPop;
  347. },
  348.  
  349. miningRate(p, ground, density, mines) {
  350. m = vgap.miningRate(p, density, mines);
  351. m = m > ground ? ground : Math.round(m);
  352. return m;
  353. },
  354.  
  355. getDistQ : function (x1, y1, x2, y2) {
  356. var dx = x2 - x1;
  357. var dy = y2 - y1;
  358. return Math.sqrt((dx * dx) + (dy * dy));
  359. },
  360.  
  361. };
  362.  
  363. hitText.prototype.predictor = function (ship, forTowCalculation) { //be careful when calling 'this', needs the actual shipscreen!
  364. if (!ship)
  365. return;
  366. var hull = vgap.getHull(ship.hullid);
  367. var planet = vgap.planetAt(ship.x, ship.y);
  368. var starbase = null;
  369. if (planet)
  370. starbase = vgap.getStarbase(planet.id);
  371. var result = {
  372. ammo : 0,
  373. supplies : 0,
  374. neutronium : 0,
  375. duranium : 0,
  376. tritanium : 0,
  377. molybdenum : 0,
  378. megacredits : 0,
  379. damage : 0,
  380. crew : 0,
  381. cargo : 0
  382. };
  383. var getCargo = function () {
  384. result.cargo = result.ammo + result.supplies + result.duranium + result.tritanium + result.molybdenum;
  385. };
  386. var cloakFuel = function () {
  387. if ((ship.mission == 9 || (vgap.player.raceid == 3 && ship.mission == 8 && hull.cancloak)) && ship.hullid != 29 && ship.hullid != 31)
  388. return Math.max(5, Math.floor((hull.mass / 100) * 5));
  389. else
  390. return 0;
  391. }
  392.  
  393. //cloak - will it use fuel when it fails because of lack of fuel?
  394. result.neutronium -= Math.min(ship.neutronium + result.neutronium, cloakFuel());
  395.  
  396. //build fighters
  397. getCargo();
  398. if (ship.bays > 0 && vgap.player.raceid > 8) {
  399. var race = vgap.player.raceid;
  400. var loadedfighters = 0;
  401. //load
  402. if (planet != null && planet.ownerid == vgap.player.id && ship.friendlycode.toUpperCase() == "LFM" && ship.neutronium + result.neutronium > 0) {
  403. loadedfighters = Math.min(Math.floor(planet.molybdenum / 2), Math.floor(planet.tritanium / 3), Math.floor(planet.supplies / 5), Math.floor((hull.cargo - vgap.shipScreen.getTotalCargo(ship) - result.cargo) / 10));
  404. if (loadedfighters > 0) {
  405. result.molybdenum += loadedfighters * 2;
  406. result.tritanium += loadedfighters * 3;
  407. result.supplies += loadedfighters * 5;
  408. }
  409. }
  410. //build
  411. var builtfighters = 0;
  412. if ((ship.friendlycode.toUpperCase() == "LFM" && ship.neutronium + result.neutronium > 0) || ((race == 9 || race == 11) && ship.mission == 8)) {
  413. builtfighters = Math.min(Math.floor((ship.molybdenum + result.molybdenum) / 2), Math.floor((ship.tritanium + result.tritanium) / 3), Math.floor((ship.supplies + result.supplies) / 5));
  414. if (builtfighters > 0) {
  415. result.molybdenum -= builtfighters * 2;
  416. result.tritanium -= builtfighters * 3;
  417. result.supplies -= builtfighters * 5;
  418. result.ammo += builtfighters;
  419. }
  420. }
  421. }
  422.  
  423. //lady royale
  424. if (hull.id == 42 && ship.neutronium > 0) {
  425. result.megacredits += Math.min(10000 - (ship.megacredits + result.megacredits), ship.clans + result.clans);
  426. }
  427.  
  428. //borg repair
  429. if (vgap.player.raceid == 6 && ship.mission == 8 && ship.neutronium > 0 && ship.warp == 0)
  430. result.damage -= Math.min(ship.damage, 10);
  431.  
  432. //bdm -> Ship 0 gets 0 MC, Planet get all MC for later bum...
  433. var bdm = 0;
  434. if (planet != null) {
  435. if (ship.friendlycode.toUpperCase() == "BDM")
  436. result.megacredits -= (ship.megacredits + result.megacredits);
  437. var shipsAt = vgap.shipsAt(ship.x, ship.y);
  438. for (var i = 0; i < shipsAt.length; i++) {
  439. var s = shipsAt[i];
  440. if (s.ownerid != vgap.player.id && !s.allyupdate) // try (vgap.allied(s.ownerid))
  441. continue;
  442. if (s.friendlycode.toUpperCase() == "BDM") {
  443. bdm += s.megacredits;
  444. if (s.allyupdate && s.hullid == 42 && s.neutronium > 0)
  445. bdm += Math.min(10000 - s.megacredits, s.clans); //allied Lady Royale
  446. }
  447. }
  448. }
  449.  
  450. //bum
  451. if (planet != null && (planet.ownerid == 0 || planet.ownerid == vgap.player.id || planet.allyupdate) && planet.friendlycode.toUpperCase() == "BUM") {
  452. var bum = planet.megacredits + bdm;
  453. for (var i = 0; i < shipsAt.length; i++) {
  454. var s = shipsAt[i];
  455. if (s.id < ship.id && s.ownerid != vgap.player.id && !s.allyupdate) {
  456. bum = 0; //can't handle foreign ships
  457. break;
  458. }
  459. if (s.id < ship.id)
  460. bum -= Math.min(10000 - (s.friendlycode.toUpperCase() == "BDM" ? 0 : s.megacredits), bum);
  461. else
  462. break;
  463. }
  464. if (bum > 0)
  465. result.megacredits += bum;
  466. }
  467.  
  468. //gather missions (2do: other ships gathering before)
  469. getCargo();
  470. if (ship.neutronium > 0 && ship.mission > 9 && ship.mission < 15 && planet != null && (planet.ownerid == 0 || planet.ownerid == vgap.player.id)) { //2do? allied
  471. freecargo = hull.cargo - vgap.shipScreen.getTotalCargo(ship) - result.cargo;
  472. switch (ship.mission) {
  473. case 10:
  474. if (planet.neutronium > 0)
  475. result.neutronium += Math.min(hull.fueltank - ship.neutronium - result.neutronium, planet.neutronium);
  476. break;
  477. case 11:
  478. if (planet.duranium > 0)
  479. result.duranium += Math.min(freecargo, planet.duranium);
  480. break;
  481. case 12:
  482. if (planet.tritanium > 0)
  483. result.tritanium += Math.min(freecargo, planet.tritanium);
  484. break;
  485. case 13:
  486. if (planet.molybdenum > 0)
  487. result.molybdenum += Math.min(freecargo, planet.molybdenum);
  488. break;
  489. case 14:
  490. if (planet.supplies > 0)
  491. result.supplies += Math.min(freecargo, planet.supplies);
  492. break;
  493. default:
  494. break;
  495. }
  496. }
  497.  
  498. //alchemy
  499. if (hull.id == 105 && ship.friendlycode.toLowerCase() != "nal" && ship.neutronium > 0) //need fuel for that?
  500. {
  501. var alchemy = Math.floor((ship.supplies + result.supplies) / 9);
  502. result.supplies -= 9 * alchemy;
  503. switch (ship.friendlycode.toLowerCase()) {
  504. case "ald":
  505. result.duranium += 3 * alchemy;
  506. break;
  507. case "alt":
  508. result.tritanium += 3 * alchemy;
  509. break;
  510. case "alm":
  511. result.molybdenum += 3 * alchemy;
  512. break;
  513. default:
  514. result.duranium += alchemy;
  515. result.tritanium += alchemy;
  516. result.molybdenum += alchemy;
  517. break;
  518. }
  519. }
  520.  
  521. getCargo();
  522. //refinery NRS=104, Aries=97
  523. if ((hull.id == 104 || hull.id == 97) && ship.friendlycode.toLowerCase() != "nal" && ship.neutronium > 0) { //need fuel for that?
  524. var ref = Math.min(ship.duranium + result.duranium + ship.tritanium + result.tritanium + ship.molybdenum + result.molybdenum, hull.fueltank - (ship.neutronium + result.neutronium));
  525. if (hull.id == 104) {
  526. ref = Math.min(ref, ship.supplies);
  527. result.supplies -= ref;
  528. }
  529. result.neutronium += ref;
  530. //how it's done
  531. var now = Math.min(ship.duranium + result.duranium, ref);
  532. result.duranium -= now;
  533. ref -= now;
  534. now = Math.min(ship.tritanium + result.tritanium, ref);
  535. result.tritanium -= now;
  536. ref -= now;
  537. now = Math.min(ship.molybdenum + result.molybdenum, ref);
  538. result.molybdenum -= now;
  539. ref -= now;
  540. if (ref != 0) { //whoops, something went wrong
  541. }
  542.  
  543. /* that's how I'd do it...
  544. var a=[ship.duranium,ship.tritanium,ship.molybdenum];
  545. var k=0;
  546. while (ref>0) {
  547. if (a[k]>0) {a[k]--; ref--};
  548. k=(k+1)%3;
  549. }
  550.  
  551. result.duranium-=ship.duranium-a[0];
  552. result.tritanium-=ship.tritanium-a[1];
  553. result.molybdenum-=ship.molybdenum-a[2];
  554. */
  555. }
  556.  
  557. getCargo();
  558. //lay mines
  559. if (ship.mission == 2 || (vgap.getPlayer(ship.ownerid).raceid == 7 && ship.mission == 8))
  560. // result.ammo -= vgap.shipScreen.getMineLayTorps(ship); // Quapla to Todo: No function getMineLayTorps
  561. result.ammo = 0;
  562. getCargo();
  563.  
  564. //scoop mines
  565.  
  566. //create array of proposed minefields first
  567. if (ship.torps > 0 && ship.mission == 1 && ship.friendlycode.toLowerCase() == "msc") {
  568. var minefields = new Array();
  569. for (var j = 0; j < vgap.minefields.length; j++) {
  570. var mf = vgap.minefields[j];
  571. minefields.push({
  572. ownerid : mf.ownerid,
  573. x : mf.x,
  574. y : mf.y,
  575. radius : mf.radius,
  576. isweb : mf.isweb,
  577. units : mf.units,
  578. radiusPresweep : mf.radius
  579. });
  580. }
  581. //mine laying minefields (from preview)
  582. for (var i = 0; i < vgap.ships.length; i++) {
  583. var s = vgap.ships[i];
  584. if (s.ownerid != vgap.player.id && !s.allyupdate)
  585. continue;
  586. if (s.neutronium > 0 && s.ammo > 0 && s.torps > 0) {
  587. if (s.mission == 2 || (s.mission == 8 && vgap.player.raceid == 7)) {
  588. var isWeb = (s.mission == 8);
  589.  
  590. var fieldOwnerId = s.ownerid;
  591.  
  592. //miX friendlycode
  593. if (s.friendlycode.toLowerCase().indexOf("mi") === 0) {
  594. fieldOwnerId = vgap.getPlayerIdVal(s.friendlycode.toLowerCase().replace("mi", ""));
  595. if (fieldOwnerId == 0 || fieldOwnerId > vgap.game.slots)
  596. fieldOwnerId = s.ownerId;
  597. }
  598. var units = this.getMineUnits(s);
  599.  
  600. //determine if we are inside of one of our minefields
  601. var minefield = null;
  602. var closest = 10000.0;
  603. for (var j = 0; j < minefields.length; j++) {
  604. var closestField = minefields[j];
  605. if (closestField.isweb == isWeb && closestField.ownerid == fieldOwnerId) {
  606. var dist = parseFloat(hitText.prototype.getDistQ(s.x, s.y, closestField.x, closestField.y)); // Quapla Todo
  607. // var dist = 9999; // never in Minefield -> Check funktion getDist Quapla
  608. if (dist < closest) {
  609. minefield = closestField;
  610. closest = dist;
  611. }
  612. if (closest == 0)
  613. break;
  614. }
  615. }
  616. var newField = true;
  617. if (minefield != null) {
  618. if (closest <= minefield.radius)
  619. newField = false;
  620. }
  621. //new field
  622. if (newField) {
  623. minefield = {
  624. ownerid : fieldOwnerId,
  625. x : s.x,
  626. y : s.y,
  627. isweb : isWeb,
  628. units : 0
  629. };
  630. minefields.push(minefield);
  631. }
  632.  
  633. //add the units to the minefield
  634. minefield.units += units;
  635. minefield.changed = 1;
  636.  
  637. //max minefield, don't lay so many torps
  638. if (minefield.units > 22500)
  639. minefield.units = 22500;
  640.  
  641. minefield.radius = Math.sqrt(minefield.units);
  642.  
  643. }
  644. }
  645.  
  646. }
  647. var torp = vgap.getTorpedo(ship.torpedoid);
  648. getCargo();
  649. var openCargo = 0;
  650. var ammo = 0;
  651. //look for scooping ships
  652. for (var i = 0; i < vgap.ships.length; i++) {
  653. var s = vgap.ships[i];
  654. if (s.ownerid != vgap.player.id && !s.allyupdate)
  655. continue;
  656. if (s.friendlycode.toLowerCase() != "msc" || s.mission != 1 || s.torps < 1 || s.beams < 1 || s.neutronium < 1)
  657. continue;
  658. openCargo = vgap.getHull(s.hullid).cargo - vgap.shipScreen.getTotalCargo(s);
  659. if (s.id == ship.id)
  660. openCargo -= result.cargo; //2do? result for other ships
  661. for (var j = 0; j < minefields.length; j++) {
  662. var minefield = minefields[j];
  663. var dist = parseFloat(hitText.prototype.getDistQ(s.x, s.y, minefield.x, minefield.y));
  664. if (minefield.ownerid == s.ownerid && (dist - minefield.radius) <= 0) {
  665. //Mine scoop
  666. var unitsScooped = openCargo * s.torpedoid * s.torpedoid;
  667. if (vgap.player.raceid == 9)
  668. unitsScooped *= 4;
  669.  
  670. if (unitsScooped > minefield.units)
  671. unitsScooped = minefield.units;
  672.  
  673. if (unitsScooped > 0) {
  674. minefield.units -= unitsScooped;
  675. minefield.radius = Math.sqrt(minefield.units);
  676. minefield.swept = 1;
  677. if (minefield.units < 0)
  678. minefield.units = 0;
  679.  
  680. if (vgap.player.raceid == 9)
  681. unitsScooped /= 4;
  682.  
  683. ammo = Math.floor(unitsScooped / s.torpedoid / s.torpedoid);
  684.  
  685. openCargo -= ammo;
  686. if (s.id == ship.id)
  687. result.ammo += ammo;
  688. }
  689. }
  690. }
  691. if (s.id == ship.id)
  692. break;
  693. }
  694. }
  695.  
  696. //Starbase fix
  697. if (starbase && starbase.shipmission == 1 && starbase.targetshipid == ship.id) {
  698. result.damage -= ship.damage;
  699. result.crew += hull.crew - ship.crew;
  700. }
  701.  
  702. //repair with supplies
  703. if (ship.damage + result.damage > 0) {
  704. var rep = Math.floor(ship.supplies / 5);
  705. rep = Math.min(rep, ship.damage + result.damage);
  706. result.supplies -= rep * 5;
  707. result.damage -= rep;
  708. }
  709.  
  710. //mkt
  711. if (ship.torps > 0 && ship.friendlycode.toUpperCase() == "MKT") {
  712. var cost = vgap.getTorpedo(ship.torpedoid).torpedocost;
  713. var mkt = Math.min(ship.duranium + result.duranium, ship.tritanium + result.duranium, ship.molybdenum + result.molybdenum, Math.floor((ship.megacredits + result.megacredits) / cost));
  714. result.ammo += mkt;
  715. result.duranium -= mkt;
  716. result.tritanium -= mkt;
  717. result.molybdenum -= mkt;
  718. result.megacredits -= mkt * cost;
  719. }
  720. getCargo();
  721. if (forTowCalculation)
  722. return result;
  723.  
  724. //movement
  725. var x,
  726. y,
  727. dist;
  728. var a = vgap.getNextLoc(ship); //includes breakTow
  729. x = a[0],
  730. y = a[1],
  731. dist = a[2];
  732. var actFuel = ship.neutronium + result.neutronium;
  733. var actMass = hull.mass + vgap.shipScreen.getTotalCargo(ship) + result.cargo + actFuel;
  734. if (ship.warp > 0 && dist > 0) {
  735. actMass += (ship.beams > 0 ? vgap.getBeam(ship.beamid).mass * ship.beams : 0);
  736. actMass += (ship.torps > 0 ? vgap.getTorpedo(ship.torpedoid).mass * ship.torps : 0);
  737. if (ship.mission == 6 && ship.mission1target != 0 && actFuel > 0) {
  738. var towShip = vgap.getShip(ship.mission1target);
  739. var towTarget = vgap.isTowTarget(ship.id);
  740. if (towShip != null && (towTarget == null || towShip.id != towTarget.id)) { //towee towing the tower?
  741. if (towShip.ownerid == vgap.player.id || towShip.allyupdate) {
  742. if (!vgap.breakTow(ship, towShip)) {
  743. var resultTowship = this.predictor(towShip, true);
  744. var towMass = 0;
  745. towMass += vgap.getHull(towShip.hullid).mass + vgap.shipScreen.getTotalCargo(towShip) + resultTowship.cargo + towShip.neutronium + resultTowship.neutronium;
  746. towMass += (towShip.beams > 0 ? vgap.getBeam(towShip.beamid).mass * towShip.beams : 0);
  747. towMass += (towShip.torps > 0 ? vgap.getTorpedo(towShip.torpedoid).mass * towShip.torps : 0);
  748. actMass += 10 * Math.truncate(towMass / 10); //according to http://donovansvgap.com/help/details.htm#fuel2
  749. }
  750. } else
  751. actMass += 10 * Math.truncate(towShip.mass / 10);
  752. }
  753. }
  754. var speed = vgap.getSpeed(ship.warp, vgap.getHull(ship.hullid));
  755. var xv = (vgap.getEngine(ship.engineid)["warp" + ship.warp] || 0);
  756. var turnFuel = (vgap.isHyping(ship) || vgap.isChunnelling(ship) ? 50 : Math.floor(xv * Math.floor(actMass / 10) * ((Math.floor(dist) / speed) / 10000)));
  757. result.neutronium -= turnFuel;
  758. /* No need at Hover Quapla
  759. var color = "green";
  760. if (ship.neutronium + result.neutronium < 0 && !(vgap.isHyping(ship) || vgap.isChunnelling(ship))) { //correction for running out of fuel (experimental)
  761. result.neutronium = -ship.neutronium;
  762. var i = 0,
  763. f = 0;
  764.  
  765. /*while (f<actFuel+1) {
  766. dist=i;
  767. i+=1;
  768. f=Math.floor(xv * Math.floor(actMass / 10) * (i / speed) / 10000);
  769. //console.log("dist: "+i+" fuel: "+f)
  770. }*/
  771. /*
  772. dist = actFuel / turnFuel * dist;
  773. a = vgap.getNextLoc(ship, dist);
  774. x = a[0],
  775. y = a[1],
  776. dist = a[2];
  777. color = "red";
  778. } */
  779. /* if (ship.x == x && ship.y == y)
  780. color = "red";
  781. vgap.map.drawCircle(x, y, 3,{
  782. stroke : color,
  783. "stroke-width" : 1,
  784. "stroke-opacity" : "1"
  785. }
  786. ); // Quapla whats that? */
  787. }
  788. this.totalmass = actMass;
  789.  
  790. //ramscoop (cobol)
  791. if (hull.id == 96 && ship.warp > 0 && dist > 0) {
  792. result.neutronium += Math.min(Math.floor(dist) * 2, hull.fueltank - (ship.neutronium + result.neutronium));
  793. }
  794.  
  795. //radiation
  796. var radiation = vgap.shipScreen.getPathRadiation(ship);
  797. var crewDeath = vgap.shipScreen.radiationEffect(ship, radiation);
  798. if (crewDeath > 0)
  799. result.crew -= Math.min(crewDeath, ship.crew + result.crew);
  800.  
  801. //glory device
  802. var nextloc = vgap.getNextLoc(ship);
  803. var d = 0;
  804. for (i = 0; i < vgap.ships.length; i++) {
  805. var s = vgap.ships[i];
  806. if (s.ownerid != vgap.player.id && !s.allyupdate)
  807. continue;
  808. var nextloc1 = vgap.getNextLoc(s);
  809. if ((s.hullid == 39 || s.hullid == 41 || s.hullid == 1034 || s.hullid == 1039) && s.friendlycode.toUpperCase() == "POP" && nextloc[0] == nextloc1[0] && nextloc[1] == nextloc1[1]) {
  810. if (s.id == ship.id)
  811. result.damage = 100;
  812. var factor = 10000; //normal damage
  813. if (s.hullid % 1000 == 39 && s.ownerid == ship.ownerid)
  814. factor = 2000; //D19b, D19c (20%)
  815. if (s.hullid == 41 && s.ownerid == ship.ownerid)
  816. factor = 1000; //saber (10%)
  817. if (s.hullid == 1034) {
  818. if (s.ownerid == ship.ownerid)
  819. factor = 2000; //D7b (20%) 2do: "friendly ships" - whatever that is
  820. else
  821. factor = 5000; //50%
  822. }
  823. result.damage += Math.floor((factor) / (hull.mass + 1));
  824. d++;
  825. }
  826. if (ship.damage + result.damage > 100) {
  827. result.damage = 100 - ship.damage;
  828. break;
  829. };
  830. }
  831.  
  832. //repair if glory
  833. if (d > 0 && ship.damage + result.damage > 0 && ship.damage + result.damage < 100) {
  834. var rep = Math.floor(ship.supplies / 5);
  835. result.supplies -= rep * 5;
  836. result.damage -= rep;
  837. }
  838.  
  839. /* wait a minute, that's after movement (careful, needs to really get there!)
  840. var target=vgap.getPlanetAt(x,y);
  841. var targetStarbase=vgap.getStarbase(target.id);
  842. //starbase unload all freighters
  843. if (targetStarbase && targetStarbase.mission == 4) {
  844. result.duranium-=ship.duranium;
  845. result.tritanium-=ship.tritanium;
  846. result.molybdenum-=ship.molybdenum;
  847. result.supplies-=ship.supplies;
  848. result.clans-=ship.clans;
  849. result.megacredits-=ship.megacredits;
  850. }
  851.  
  852.  
  853. //starbase refuel - that means calculating fuel of all ships (with lower id with this as target
  854. //starbase load torps onto ships - similar here
  855. */
  856. getCargo();
  857. var prediction = {};
  858. prediction.neutronium = result.neutronium;
  859. prediction.duranium = result.duranium;
  860. prediction.tritanium = result.tritanium;
  861. prediction.molybdenum = result.molybdenum;
  862. prediction.megacredits = result.megacredits;
  863. prediction.damage = result.damage;
  864. prediction.crew = result.crew;
  865. prediction.ammo = result.ammo;
  866. prediction.supplies = result.supplies;
  867. prediction.cargo = result.cargo;
  868. prediction.x = x;
  869. prediction.y = y;
  870. hitText.prototype.prediction = prediction;
  871. return result;
  872. };
  873.  
  874. //Helpers for Prediction
  875.  
  876. vgaPlanets.prototype.getNextLoc = function (ship, maxDist) { //2do? include chunnelling?
  877. if (!ship)
  878. return;
  879. var curX = ship.x,
  880. curY = ship.y;
  881. var tower = vgap.isTowTarget(ship.id);
  882. if (tower != null && !vgap.breakTow(tower, ship) && ship.mission != 6) {
  883. var TowerLoc = this.getNextLoc(tower);
  884. TowerLoc[2] = 0; //didn't travel on own engine
  885. return TowerLoc;
  886. }
  887. if (vgap.isChunnelling(ship)) {
  888. var targetId = parseInt(ship.friendlycode, 10);
  889. var target = vgap.getShip(targetId);
  890. if (!target)
  891. return;
  892. return [target.x, target.y, 0];
  893. }
  894. if (vgap.isHyping(ship) && (!maxDist || maxDist != 350)) { //catch recursion
  895. var hypdist = hitText.prototype.getDistQ(ship.x, ship.y, ship.targetx, ship.targety);
  896. if (hypdist > 360.05 || hypdist < 339.95)
  897. return this.getNextLoc(ship, 350);
  898. else
  899. return [ship.targetx, ship.targety, hypdist];
  900. }
  901. var endX = ship.targetx;
  902. var endY = ship.targety;
  903. if (ship.mission == 7) { //intercept
  904. var interceptTarget = null;
  905. if (ship.mission1target != 0) {
  906. interceptTarget = vgap.getShip(ship.mission1target);
  907. if (interceptTarget.ownerid == vgap.player.id || interceptTarget.allyupdate) { //only ships that can be predicted correctly
  908. var a = this.getNextLoc(interceptTarget);
  909. endX = a[0];
  910. endY = a[1];
  911. }
  912. }
  913. }
  914. var diffX = endX - curX;
  915. var diffY = endY - curY;
  916. if (diffX == 0 && diffY == 0)
  917. return [curX, curY, 0];
  918. var totalDist = hitText.prototype.getDistQ(curX, curY, endX, endY);
  919. var speed = vgap.getSpeed(ship.warp, vgap.getHull(ship.hullid));
  920. if ((maxDist == null || maxDist > totalDist) && !(vgap.isHyping(ship) && maxDist == 350)) { //enough fuel and not indirecthyping
  921. if (vgap.isHyping(ship))
  922. speed = 359.55;
  923. if (totalDist < speed + 0.5) { //will arrive this turn
  924. var warpPlanet = vgap.warpWell(endX, endY);
  925. var hypThreeAway = vgap.isHyping(ship) && ((Math.abs(warpPlanet.x - endX) == 3) || (Math.abs(warpPlanet.y - endY) == 3));
  926. if (warpPlanet && speed > 1 && !hypThreeAway) {
  927. endX = warpPlanet.x;
  928. endY = warpPlanet.y;
  929. }
  930. return [endX, endY, totalDist];
  931. } else
  932. totalDist = speed; //waypoint is longer than speed
  933. } else
  934. totalDist = maxDist; //not enough fuel - experimental!!
  935.  
  936. var newX,
  937. newY;
  938. if (Math.abs(diffX) > Math.abs(diffY)) {
  939. var moveX = Math.floor((totalDist * diffX) / Math.sqrt((diffX * diffX) + (diffY * diffY)) + 0.5);
  940. var moveY = Math.floor(moveX * (diffY / diffX) + 0.5);
  941. newX = curX + moveX;
  942. newY = curY + moveY;
  943. } else {
  944. var moveY = Math.floor((totalDist * diffY) / Math.sqrt((diffX * diffX) + (diffY * diffY)) + 0.5);
  945. var moveX = Math.floor(moveY * (diffX / diffY) + 0.5);
  946. newY = curY + moveY;
  947. newX = curX + moveX
  948. }
  949. var actDist = Math.sqrt((moveX * moveX) + (moveY * moveY)); //actual distance travelled by own engine (for fuel calculation)
  950. var warpPlanet = vgap.warpWell(newX, newY);
  951. var hypThreeAway = vgap.isHyping(ship) && ((Math.abs(warpPlanet.x - newX) == 3) || (Math.abs(warpPlanet.y - newY) == 3));
  952. if (warpPlanet && speed > 1 && !hypThreeAway) {
  953. newX = warpPlanet.x;
  954. newY = warpPlanet.y;
  955. }
  956. return [newX, newY, actDist];
  957. };
  958.  
  959. vgaPlanets.prototype.warpWell = function (x, y) { // returns planet or false
  960. for (var i = 0; i < this.planets.length; i++) {
  961. var planet = this.planets[i];
  962. if (planet.debrisdisk > 0)
  963. continue;
  964. var dist = hitText.prototype.getDistQ(x, y, planet.x, planet.y);
  965. if (dist <= 3 && dist > 0)
  966. return planet;
  967. }
  968. return false;
  969. };
  970.  
  971. vgaPlanets.prototype.breakTow = function (tower, towee) {
  972. if (!tower || !towee)
  973. return;
  974. var towTarget = vgap.isTowTarget(towee.id)
  975. if (towTarget == null || tower.id != towTarget.id)
  976. return true; //2do: what if multiple ships tow? isTowTarget returns only the lowest id ship
  977. if (vgap.getHull(tower.hullid).engines == 1)
  978. return true;
  979. var f1 = ((tower.hullid == 44 || tower.hullid == 45 || tower.hullid == 46) ? 2 : 1);
  980. var f2 = ((towee.hullid == 44 || towee.hullid == 45 || towee.hullid == 46) ? 2 : 1);
  981. if (f1 * tower.warp < f2 * tower.warp && hitText.prototype.getDistQ(towee.x, towee.y, towee.targetx, towee.targety) > vgap.getSpeed(towee.warp, towee.hullid) && towee.neutronium >= 25)
  982. return true;
  983. return false;
  984. };
  985.  
  986. vgaPlanets.prototype.isChunnelling = function (ship) {
  987. if ((ship.hullid == 56 || ship.hullid == 1055) && ship.warp == 0 && ship.neutronium >= 50 && ship.mission != 6) {
  988. if (this.isTowTarget(ship.id) == null) {
  989. var RegExPattern = /([0-9])([0-9])([0-9])/;
  990. var matchExpression = ship.friendlycode;
  991. matchExpression = matchExpression.toString();
  992. if ((matchExpression.match(RegExPattern)) && (matchExpression != '')) {
  993. var targetId = parseInt(ship.friendlycode, 10);
  994. var target = vgap.getShip(targetId);
  995. if (target != null) {
  996. if (target.ownerid == ship.ownerid && (target.hullid == 56 || target.hullid == 1054 || (ship.hullid == 1055 && target.hullid == 51)) && target.warp == 0 && target.neutronium >= 1 && target.mission != 6 && hitText.prototype.getDistQ(ship.x, ship.y, target.x, target.y) >= 100 && this.isTowTarget(target.id) == null)
  997. return true;
  998. }
  999. }
  1000. }
  1001. }
  1002. return false;
  1003. };
  1004.  
  1005. // Pediction
  1006.  
  1007. vgaPlanets.prototype.setupAddOn = function (addOnName) {
  1008. if (vgaPlanets.prototype.addOns == null)
  1009. vgaPlanets.prototype.addOns = {};
  1010. vgaPlanets.prototype.addOns[addOnName] = {};
  1011. var settings = localStorage.getItem(addOnName + ".settings");
  1012. if (settings != null)
  1013. vgaPlanets.prototype.addOns[addOnName].settings = JSON.parse(settings);
  1014. else
  1015. vgaPlanets.prototype.addOns[addOnName].settings = {};
  1016. vgaPlanets.prototype.addOns[addOnName].saveSettings = function () {
  1017. localStorage.setItem(addOnName + ".settings", JSON.stringify(vgaPlanets.prototype.addOns[addOnName].settings));
  1018. }
  1019. };
  1020. vgaPlanets.prototype.setupAddOn("vgapHoverPrediction");
  1021.  
  1022. /*
  1023. if (vgaPlanets.prototype.addOns == null) vgaPlanets.prototype.addOns = {};
  1024. vgaPlanets.prototype.addOns.vgapHoverPrediction = {};
  1025. var settings = localStorage.getItem("vgapHoverPrediction.settings");
  1026. if (settings != null)
  1027. vgaPlanets.prototype.addOns.vgapHoverPrediction.settings = JSON.parse(settings);
  1028. else
  1029. vgaPlanets.prototype.addOns.vgapHoverPrediction.settings = {}; //{terseInfo: false};
  1030.  
  1031. vgaPlanets.prototype.addOns.vgapHoverPrediction.saveSettings = function () {
  1032. localStorage.setItem("vgapHoverPrediction.settings", JSON.stringify(vgaPlanets.prototype.addOns.vgapHoverPrediction.settings));
  1033. };
  1034. */
  1035.  
  1036. var old_hitTextBox = vgapMap.prototype.hitTextBox;
  1037. vgapMap.prototype.hitTextBox = function (hit) {
  1038. // replace completely, pretty sure i want to do this
  1039. // oldHitTextBox.apply(this, arguments);
  1040.  
  1041. var settings = vgap.addOns.vgapHoverPrediction.settings;
  1042. var txt = "";
  1043. var wtx = "";
  1044. var change = 0;
  1045. var html = '';
  1046. if (hit.isPlanet) { //planet
  1047. if (settings.tersePlanet) { // Show new Info
  1048. var predclans = (hit.clans > 0 ? hit.clans : 0);
  1049. var prednativeclans = (hit.nativeclans > 0 ? hit.nativeclans : 0);
  1050. var predsupplies = (hit.supplies > 0 ? hit.supplies : 0);
  1051. var predmegacredits = (hit.megacredits > 0 ? hit.megacredits : 0);
  1052. var predduranium = (hit.duranium > 0 ? hit.duranium : 0);
  1053. var predmolybdenum = (hit.molybdenum > 0 ? hit.molybdenum : 0);
  1054. var predtritanium = (hit.tritanium > 0 ? hit.tritanium : 0);
  1055. var predneutronium = (hit.neutronium > 0 ? hit.neutronium : 0);
  1056.  
  1057. // if (hit.id < 0) { hit = vgap.getPlanet(-hit.id); } // For what is that good? Quapla
  1058. // 8 Colomns
  1059. // AAAA | 00000000 | + 0000 | (00000') || BBBB | 00000000 | + 0000 | (00000')
  1060. // Cln: | 23450 | + 21 | (451') || Avi: | 23450 | + 21 | (451')
  1061.  
  1062. txt += "<div class='ItemSelectionBox minCorrection'>";
  1063. // txt += "<span>" + hit.id + ": " + hit.name;
  1064. // if (hit.temp != -1)
  1065. // txt += "<span style='float:right;'>Temp: " + hit.temp + "</span>";
  1066. // txt += "</span>";
  1067. txt += "<table style='table-layout:fixed' class='CleanTable'><colgroup span='8'></colgroup>";
  1068. if (hit.infoturn == 0) { //unknown planet
  1069. // txt += this.hitText(hit, hit.isPlanet).replace("&nbsp", ""); // Later for all Planets
  1070. txt += "<tr><td>" + hit.id + ": unknown</td></tr>";
  1071. } else {
  1072. // if (hit.nativeclans > 0) // Has natives
  1073. // {
  1074. // txt += "<tr><td colspan=8>" + addCommas(hit.nativeclans * 100) + " " + hit.nativeracename + " - " + hit.nativegovernmentname + "</td></tr>";
  1075. // }
  1076. //txt += "<div class='ItemSelectionBox minCorrection'>";
  1077. //txt += "<table class='CleanTable'>";
  1078. if (hit.ownerid != vgap.player.id)
  1079. wtx = " class='WarnText'";
  1080. else if (hit.readystatus == 0)
  1081. wtx = "";
  1082. else
  1083. wtx = " style='color:#90ee90;'"; // Planet ready, show green?
  1084. txt += "<tr><td" + wtx + ">" + hit.id + ": </td>";
  1085. txt += "<td colspan = '3'" + wtx + ">" + hit.name + "</td>";
  1086. txt += "<td style='text-align:right;'>FC:&nbsp</td><td>" + hit.friendlycode + "</td>";
  1087. if (hit.temp != -1) // Temperature known
  1088. {
  1089. if (hit.temp > 84 || hit.temp < 15)
  1090. wtx = " class='WarnText'";
  1091. else
  1092. wtx = ""; // Planet Hot/Cold?
  1093. txt += "<td style='text-align:right;' colspan='2'" + wtx + ">&nbsp;" + hit.temp + "°</td>";
  1094. }
  1095. txt += "</tr>";
  1096. // txt += "<td>Cln:&nbsp;</td><td>" + hit.clans + "&nbsp;</td><td style='float:right;'>+ " + (minPop == 0 ? "n/a" : minPop) + "+&nbsp;</td><td style='float:right;'>(" + maxPop + ")</td>";
  1097. if (hit.clans > 0)
  1098. wtx = "Clans";
  1099. else
  1100. wtx = "unowned";
  1101. var grows = hitText.prototype.GetPopGrowth(hit);
  1102. var maxcln = hitText.prototype.GetsmaxPop(hit, false); // Old function: hitText.prototype.GetMaxPop(hit);
  1103. var change = hitText.prototype.GetMinPopGrow(hit);
  1104. if (hit.clans < change || hit.clans < 1) // too little clans to grow
  1105. txt += "<tr>" + hitText.prototype.showMin(wtx, hit.clans, "[" + change + "]", maxcln, "");
  1106. else
  1107. txt += "<tr>" + hitText.prototype.showMin(wtx, hit.clans, (grows == 0 ? "n/a" : grows), maxcln, (grows < 0 ? "-" : "+"));
  1108. if (hit.ownerId = vgap.player.id)
  1109. predclans += grows; // Clans added
  1110. else
  1111. predclans = 0;
  1112.  
  1113. if (hit.nativeclans > 0) // Has Natives
  1114. {
  1115. txt += "<td style='text-align:right;'>&nbsp" + addCommas(hit.nativeclans) + "</td>";
  1116. txt += "<td>&nbsp" + hit.nativeracename.substr(0, 5) + "</td>";
  1117. if (hit.ownerid == vgap.player.id) {
  1118. if (hit.nativehappypoints < 40) {
  1119. wtx = "ff0000"; // Red
  1120. } else if (hit.nativehappypoints < 70) {
  1121. wtx = "ffa500"; // Orange
  1122. } else {
  1123. wtx = "90ee90"; // Green
  1124. }
  1125. }
  1126. txt += "<td style='color:#" + wtx + ";'>&nbsp;" + hit.nativehappypoints + "%</td>";
  1127. txt += "<td>&nbsp;" + hit.nativetaxrate + "%</td>";
  1128. }
  1129.  
  1130. txt += "</tr>";
  1131.  
  1132. // if (vgap.player.status == 7 && !hit) {
  1133. // var e = ["None", "Colonization", "Build Starbase", "Supply
  1134. // Starbase", "Exploration", "Build Special", "Attack", "Defend",
  1135. // "Move Fuel"];
  1136. // return "<tr><td colspan='" + a + "' class='WarnText'>" +
  1137. // e[b.goal] + "-" + b.goaltarget + "</td></tr>"
  1138. // }
  1139. var sp = hit.factories;
  1140. var cs = 0;
  1141. var nt = 0;
  1142. var cs10 = 0;
  1143. var nt10 = 0;
  1144. var sps = 0;
  1145. if (hit.nativeclans > 0) {
  1146. if (hit.nativetype == 2) { // bovinoid
  1147. spn = Math.floor(hit.nativeclans / 100);
  1148. sps = hit.clans - spn;
  1149. sp += sps > 0 ? spn : hit.clans;
  1150. }
  1151.  
  1152. nt = hitText.prototype.nativeTaxAmount(hit, hit.nativetaxrate); // Can pay max
  1153. ns = hitText.prototype.nativesupportedtax(hit); // Can get may
  1154. cs = ns - nt; // Won't get because lack of Clans
  1155. nt = Math.min(nt, ns);
  1156.  
  1157. nt10 = hitText.prototype.nativeTaxAmount(hit, 10);
  1158. ns10 = hitText.prototype.nativesupportedtax(hit);
  1159. cs10 = ns10 - nt10;
  1160. nt10 = Math.min(nt10, ns10);
  1161. }
  1162.  
  1163. ct = Math.round(hit.clans * hit.colonisttaxrate / 1000);
  1164.  
  1165. mn = hitText.prototype.miningRate(hit, hit.groundneutronium, hit.densityneutronium, hit.mines);
  1166. md = hitText.prototype.miningRate(hit, hit.groundduranium, hit.densityduranium, hit.mines);
  1167. mm = hitText.prototype.miningRate(hit, hit.groundmolybdenum, hit.densitymolybdenum, hit.mines);
  1168. mt = hitText.prototype.miningRate(hit, hit.groundtritanium, hit.densitytritanium, hit.mines);
  1169. var nText = hit.groundneutronium;
  1170. var dText = hit.groundduranium;
  1171. var tText = hit.groundtritanium;
  1172. var mText = hit.groundmolybdenum;
  1173. if (hit.totalneutronium > 0 && hit.groundneutronium < 0) { //"total" info available, surface/ground is not, enables display of dark sense and superspy info in hover text
  1174. nText = hit.totalneutronium;
  1175. dText = hit.totalduranium;
  1176. tText = hit.totaltritanium;
  1177. mText = hit.totalmolybdenum;
  1178. }
  1179.  
  1180. if (hit.groundneutronium > 0) {
  1181. txt += "<tr>" + hitText.prototype.showMin("Neut", hit.neutronium, mn, nText, "+");
  1182. predneutronium += mn;
  1183.  
  1184. txt += "<td style='text-align:right;'>" + addCommas(hit.supplies) + "</td><td>&nbspSupp</td>";
  1185. txt += "<td style='text-align:right;'>&nbsp+&nbsp" + sp;
  1186. if (sps < 0)
  1187. txt += "</td><td class='val' style='color:#f00;'>-" + (-sps);
  1188. txt += "</td></tr>";
  1189. predsupplies += sp;
  1190.  
  1191. txt += "<tr>" + hitText.prototype.showMin("Dura", hit.duranium, md, dText, "+");
  1192. predduranium += md;
  1193.  
  1194. txt += "<td style='text-align:right;'>" + addCommas(hit.megacredits) + "</td>";
  1195. txt += "<td style='text-align:center;'>MC</td><td style='text-align:right;'>&nbsp+&nbsp" + (nt + ct);
  1196. if (cs < 0)
  1197. txt += "</td><td class='val' style='color:#f00;'>-" + (-cs);
  1198. txt += "</td></tr>";
  1199. predmegacredits += (nt + ct);
  1200.  
  1201. txt += "<tr>" + hitText.prototype.showMin("Trit", hit.tritanium, mt, tText, "+");
  1202. predtritanium += mt;
  1203.  
  1204. txt += "<td style='text-align:right;'>" + addCommas(hit.megacredits + hit.supplies) + "</td>";
  1205. txt += "<td style='text-align:center;'>$</td>";
  1206. txt += "<td style='text-align:right;'>&nbsp+&nbsp" + (nt + ct + sp);
  1207. txt += "</td></tr>";
  1208. /* Not used if (hit.nativeclans > 0){
  1209. txt += "<td>&nbsp;10%:</td><td>&nbsp;</td><td>" + nt10 + "-&nbsp;";
  1210. if (cs10 < 0)
  1211. txt += "</td><td class='WarnText'>" + (-cs10);
  1212. } */
  1213. txt += "<tr>" + hitText.prototype.showMin("Moly", hit.molybdenum, mm, mText, "+");
  1214. predmolybdenum += mm;
  1215.  
  1216. txt += "<td>&nbsp&nbspM.&nbspF.&nbspD.</td><td style='text-align:right;'>&nbsp" + hit.mines + "</td><td style='text-align:right;'>|&nbsp" + hit.factories + "</td><td style='text-align:right;'>&nbsp|&nbsp" + hit.defense + "</td></tr>";
  1217.  
  1218. var sb = vgap.getStarbase(hit.id);
  1219. if (sb != null && (hit.ownerid == vgap.player.id || vgap.fullallied(hit.ownerid))) {
  1220. if (sb.starbasetype != 2) {
  1221. if (sb.isbuilding) {
  1222. txt += "<tr><td colspan='8'>Build:&nbsp;" + vgap.getHull(sb.buildhullid).name + "</td></tr>";
  1223. } else {
  1224. txt += "<tr><td colspan='8' class='WarnText'>Starbase is not building</td></tr>";
  1225. }
  1226. }
  1227. /// Add tech levels for SB
  1228. txt += "<tr><td colspan='2'>Defense: " + sb.defense + "</td><td colspan='2'>Fighters: " + sb.fighters + "</td>";
  1229. txt += "<td colspan='4'>Tech: H-" + sb.hulltechlevel + " E-" + sb.enginetechlevel + " B-" + sb.beamtechlevel;
  1230. txt += " T-" + sb.torptechlevel + "</td></tr>";
  1231. } else {
  1232. if (hit.duranium > 119 && hit.tritanium > 401 && hit.molybdenum > 339 && (hit.megacredits + hit.supplies) > 899)
  1233. txt += "<tr><td colspan='8' style='color:#0f0;'>Can build Starbase</td></tr>";
  1234. }
  1235. }
  1236. //known enemy planet
  1237. if (hit.ownerid != vgap.player.id && hit.ownerid != 0) {
  1238. var player = vgap.getPlayer(hit.ownerid);
  1239. var race = vgap.getRace(player.raceid);
  1240. txt += "<tr><td colspan='8' class='WarnText'>" + race.name + " (" + player.username + ")</td></tr>";
  1241. }
  1242. // txt += this.hitText(hit, hit.isPlanet).replace("&nbsp", "");
  1243. } // End of known Planets
  1244. wtx = this.hitText(hit, hit.isPlanet).replace("'4'", "'8'");
  1245. txt += wtx.replace("&nbsp", "");
  1246. txt += "</table></div>";
  1247.  
  1248. var change = 0;
  1249. if (settings.showShips) { // Show new Info
  1250. var dist;
  1251. html = "";
  1252. for (var i = 0; i < vgap.myships.length; i++) {
  1253. var ship = vgap.myships[i];
  1254. hitText.prototype.predictor(ship); // Get next Ressorces
  1255. var hull = vgap.getHull(ship.hullid);
  1256. // var dest = vgap.getDest(ship);
  1257. dist = Math.dist(hit.x, hit.y, hitText.prototype.prediction.x, hitText.prototype.prediction.y);
  1258. if (dist <= 3 && dist >= 0) {
  1259. change += 1;
  1260. html += "<tr><td>" + ship.id + ":</td>";
  1261. html += "<td colspan='4'>" + ship.name.substr(0, 15) + "&nbsp(" + hitText.prototype.shortHullName(hull) + ")</td>";
  1262. html += "<td colspan='3'>" + "E-" + ship.engineid;
  1263. if (ship.beams > 0) // Has Beams?
  1264. html += "&nbsp" + "B-" + ship.beamid;
  1265. if (ship.torps > 0) // Has Launchers?
  1266. html += "&nbsp" + "T-" + ship.torpedoid + ":";
  1267. if (ship.bays > 0) // Has Fighter-Bays?
  1268. html += "&nbspF-" + ":";
  1269. if (ship.bays > 0 || ship.torps > 0)
  1270. html += "&nbsp" + ship.ammo + "</td></tr>";
  1271. predclans += ship.clans;
  1272. predsupplies += ship.supplies + hitText.prototype.prediction.supplies;
  1273. predmegacredits += ship.megacredits + hitText.prototype.prediction.megacredits;
  1274. predduranium += ship.duranium + hitText.prototype.prediction.duranium;
  1275. predmolybdenum += ship.molybdenum + hitText.prototype.prediction.molybdenum;
  1276. predtritanium += ship.tritanium + hitText.prototype.prediction.tritanium;
  1277. predneutronium += ship.neutronium + hitText.prototype.prediction.neutronium;
  1278. // more to come here
  1279.  
  1280. }
  1281. }
  1282. if (change > 0) {
  1283. txt += "<div class='ItemSelectionBox minCorrection'>";
  1284. txt += "<table class='CleanTable' style='width: 100%'><colgroup span='8'></colgroup>"; // New Table
  1285. txt += "<tr><td colspan='8'>" + change + " ships here at next turn:</td></tr>";
  1286. txt += html;
  1287. txt += "</table></div>";
  1288. } // else no ships here no show
  1289. } // else nothing
  1290.  
  1291. if (settings.showRessources) { // Show next Ressources
  1292. html = "<div class='ItemSelectionBox minCorrection'>";
  1293. html += "<table class='CleanTable' style='width: 100%'><colgroup span='8'></colgroup>"; // New Table
  1294. html += "<tr><td colspan='8'>Ressources here at next turn:</td></tr>";
  1295. html += "<tr><td>&nbsp&nbspCln:</td><td style='text-align:right;'>" + addCommas(predclans) + "</td>";
  1296. if (prednativeclans > 0) {
  1297. html += "<td>&nbsp&nbsp" + hit.nativeracename.substr(0, 3) + ":</td><td style='text-align:right;'>" + addCommas(prednativeclans) + "</td>";
  1298. } else {
  1299. html += "<td colspan='2'>&nbsp</td>";
  1300. }
  1301. html += "<td>&nbsp&nbspSup:</td><td style='text-align:right;'>" + addCommas(predsupplies) + "</td>";
  1302. html += "<td>&nbsp&nbsp&nbspMC:</td><td style='text-align:right;'>" + addCommas(predmegacredits) + "</td></tr>";
  1303. html += "<tr><td>&nbsp&nbspNeu:</td><td style='text-align:right;'>" + addCommas(predneutronium) + "</td>";
  1304. html += "<td>&nbsp&nbspDur:</td><td style='text-align:right;'>" + addCommas(predduranium) + "</td>";
  1305. html += "<td>&nbsp&nbspTri:</td><td style='text-align:right;'>" + addCommas(predtritanium) + "</td>";
  1306. html += "<td>&nbsp&nbspMol:</td><td style='text-align:right;'>" + addCommas(predmolybdenum) + "</td>";
  1307. html += "</table></div>";
  1308. txt += html;
  1309. } // else nothing
  1310.  
  1311. // Show known Enemy Ships at X/Y
  1312. var efound = false;
  1313. if (vgap.plugins["enemyShipListPlugin"]) { // Plugin Loaded - find that Ship in List...
  1314. var eship;
  1315. var ship;
  1316. var wtx = "";
  1317. //see if the ship exist in the list
  1318. for (var j = 0; j < vgap.plugins["enemyShipListPlugin"].enemyShipList.length; j++) {
  1319. eship = vgap.plugins["enemyShipListPlugin"].enemyShipList[j];
  1320. if (eship.x == hit.x && eship.y == hit.y && eship.ownerid != (vgap.player.id || vgap.fullallied(eship.ownerid))) { // Enemy Ship at position
  1321. efound = true;
  1322. var eplayer = vgap.getPlayer(eship.ownerid);
  1323. var hull = vgap.getHull(eship.hullid);
  1324. var race = vgap.getRace(eplayer.raceid);
  1325. if (settings.terseShip) {
  1326. wtx += "<tr><td colspan='5' class='WarnText'>" + eship.id + ": " + eship.name.substr(0, 10) + "&nbsp(" + race.name + "'s " + hitText.prototype.shortHullName(hull) + ")</td>";
  1327. if (vgap.game.turn <= eship.infoturn) { //ignore info from future turns in case of history
  1328. wtx += "<td colspan='3'>" + "&nbspE-" + eship.engineid;
  1329. if (eship.beams > 0) // Has Beams?
  1330. wtx += "&nbsp" + "B-" + eship.beamid;
  1331. if (eship.torps > 0) // Has Launchers?
  1332. wtx += "&nbsp" + "T-" + eship.torpedoid + ":";
  1333. if (hull.fighterbays > 0) // Has Fighter-Bays?
  1334. wtx += "&nbspF-" + hull.fighterbays + ":";
  1335. if (hull.fighterbays > 0 || eship.torps > 0)
  1336. wtx += "&nbsp" + eship.ammo;
  1337. } else
  1338. wtx += "<td colspan='3'>Old info from turn: " + eship.infoturn + "</td>";
  1339. wtx += "</td></tr>";
  1340. wtx += "<tr><td>Heading:</td><td>&nbsp;" + gsv(eship.heading);
  1341. wtx += "</td><td>&nbsp;at Warp:</td><td>&nbsp;" + gsv(eship.warp);
  1342. wtx += "</td><td>&nbsp;Mass:</td><td>&nbsp;" + gsv(eship.mass);
  1343.  
  1344. var cargo = eship.mass - hull.mass;
  1345.  
  1346. var weappon = 0;
  1347. if (eship.beams > 0) {
  1348. var beam = vgap.getBeam(eship.beamid);
  1349. weappon += beam.mass * eship.beams;
  1350. }
  1351. if (eship.torps > 0) {
  1352. var torp = vgap.getTorpedo(eship.torpedoid);
  1353. weappon += torp.mass * eship.torps;
  1354. }
  1355. var wwtx = "";
  1356. if (weappon > 0)
  1357. if (cargo < weappon)
  1358. wwtx = "0-";
  1359. else
  1360. wwtx = (cargo - weappon) + "-";
  1361. wwtx += cargo;
  1362. wtx += "</td><td colspan='2'>&nbsp;(" + wwtx + ")</td></tr>";
  1363. } else {
  1364. wtx += "<tr><td colspan='2' class='BadText'>" + eship.id + ": " + eship.name + "</td></tr>";
  1365. wtx += "<tr><td colspan='2' class='BadText'>" + hull.name + "</td></tr>";
  1366. wtx += "<tr><td>Heading:</td><td>&nbsp;" + gsv(eship.heading) + " at Warp: " + gsv(eship.warp) + "</td></tr>";
  1367. wtx += "<tr><td>Mass: </td><td>&nbsp;" + gsv(eship.mass) + "</td></tr>";
  1368. wtx += "<tr><td colspan='2'>" + race.name + " (" + player.username + ")" + "</td></tr>";
  1369. //wtx += "<tr><td>Neutronium:</td><td>?/" + hull.fueltank + " </td><td>&nbsp;Total Cargo:</td><td>?/" + hull.cargo + "</td></tr>";
  1370. }
  1371. }
  1372. }
  1373. if (efound) {
  1374. html = "<div class='ItemSelectionBox minCorrection'>";
  1375. html += "<table class='CleanTable' style='width: 100%'><colgroup span='8'></colgroup>";
  1376. html += "<td colspan='8'>Known enemy ships here:</td>"
  1377. html += wtx;
  1378. html += "</table></div>";
  1379. txt += html;
  1380. }
  1381. } // 4 Tabs End if vgap.plugins
  1382. } else { // Call original function...
  1383. var txt = old_hitTextBox.apply(this, arguments);
  1384. }
  1385. } // End of Planets 2 Tabs
  1386. else { //ships
  1387. if (settings.terseShip) {
  1388. var wtx = "";
  1389. var ship = hit;
  1390. var hull = vgap.getHull(ship.hullid);
  1391. var totalCargo = ship.ammo + ship.duranium + ship.tritanium + ship.molybdenum + ship.supplies + ship.clans;
  1392. if (ship.ownerid == vgap.player.id || vgap.fullallied(ship.ownerid)) {
  1393. html = "<div class='ItemSelectionBox minCorrection'>";
  1394. var player = vgap.getPlayer(ship.ownerid);
  1395. var race = vgap.getRace(player.raceid);
  1396. html += "<table class='CleanTable' style='width: 100%'>"; // New Table
  1397. if (hit.readystatus == 0) // Why check this? hit.ownerid == vgap.player.id
  1398. wtx = "";
  1399. else
  1400. wtx = " style='color:#90ee90;'"; // Ship ready, show green?
  1401. if ((settings.showHullForAllies && vgap.fullallied(ship.ownerid)) || (settings.showHullForMine && ship.ownerid == vgap.player.id)) {
  1402. html += "<tr><td colspan='5'" + wtx + ">" + ship.id + ": " + ship.name.substr(0, 15) + "&nbsp(" + hitText.prototype.shortHullName(hull) + ")</td>";
  1403. html += "<td colspan='3'>" + "&nbspE-" + ship.engineid;
  1404. if (ship.beams > 0) // Has Beams?
  1405. html += "&nbsp" + "B-" + ship.beamid;
  1406. if (ship.torps > 0) // Has Launchers?
  1407. html += "&nbsp" + "T-" + ship.torpedoid + ":";
  1408. if (ship.bays > 0) // Has Fighter-Bays?
  1409. html += "&nbspF-" + ":";
  1410. if (ship.bays > 0 || ship.torps > 0)
  1411. html += "&nbsp" + ship.ammo;
  1412. } else
  1413. html += "<tr><td colspan='8'" + wtx + ">" + ship.id + ": " + ship.name;
  1414. html += "</td></tr>";
  1415. if (!settings.veryterseship) {
  1416. html += "<tr><td>Neu:</td><td>&nbsp;" + gsv(ship.neutronium) + " / " + hull.fueltank + " </td><td>&nbsp;&nbsp;&nbsp;Dur:</td><td>&nbsp;" + gsv(ship.duranium) + "</td><td>&nbsp;&nbsp;&nbsp;Tri:</td><td>&nbsp;" + gsv(ship.tritanium) + "</td><td>&nbsp;&nbsp;&nbsp;Mol:</td><td>&nbsp;" + gsv(ship.molybdenum) + "</td></tr>";
  1417. html += "<tr><td>MC:</td><td>&nbsp;" + gsv(ship.megacredits) + "</td><td>&nbsp;&nbsp;&nbspCln:</td><td>&nbsp;" + gsv(ship.clans) + "</td><td>&nbsp;&nbsp;&nbspSup:</td><td>&nbsp;" + gsv(ship.supplies) + "</td>";
  1418. if (ship.torps > 0 || ship.bays > 0) {
  1419. var ammoText = "&nbsp&nbsp&nbsp;Ftr";
  1420. if (ship.torps > 0)
  1421. ammoText = "&nbsp&nbsp&nbsp;Tor";
  1422. html += "<td>" + ammoText + ":</td><td>&nbsp;" + gsv(ship.ammo) + "</td></tr>";
  1423. }
  1424. } else { // Very Terse
  1425. html += "<tr><td>N:&nbsp;" + gsv(ship.neutronium) + "</td><td>&nbsp;D:&nbsp;" + gsv(ship.duranium) + "</td><td>&nbsp;T:&nbsp;" + gsv(ship.tritanium) + "</td><td>&nbsp;M:&nbsp;" + gsv(ship.molybdenum) + "</td>";
  1426. html += "<td>$:&nbsp;" + gsv(ship.megacredits) + "</td><td>&nbspC:&nbsp;" + gsv(ship.clans) + "</td><td>&nbspS:&nbsp;" + gsv(ship.supplies) + "</td>";
  1427. if (ship.torps > 0 || ship.bays > 0) {
  1428. var ammoText = "<td>&nbsp;F:&nbsp";
  1429. if (ship.torps > 0)
  1430. ammoText = "<td>&nbsp;T:&nbsp";
  1431. html += ammoText + gsv(ship.ammo) + "</td></tr>";
  1432. }
  1433. }
  1434. if (ship.ownerid == vgap.player.id || ship.allyupdate) {
  1435. html += "<tr>";
  1436. if (settings.showShipMission)
  1437. html += "<td colspan='2'>" + vgap.getShipMission(ship) + ((ship.mission == 6 || ship.mission == 7) && ship.mission1target > 0 ? " " + ship.mission1target : "") + "</td>";
  1438. else
  1439. html += "<td/><td/>";
  1440. if (ship.damage > 0)
  1441. html += "<td>&nbsp;&nbsp;&nbsp;Dmg:</td><td class='BadText'>&nbsp;" + ship.damage + "%</td>";
  1442. else if (ship.iscloaked)
  1443. html += "<td colspan='2' class='GoodText'>&nbsp;&nbsp;&nbsp;Cloaked</td>";
  1444. else
  1445. html += "<td/><td/>";
  1446. html += "<td colspan='2'>&nbsp;&nbsp;&nbsp;Warp " + ship.warp + "</td>"
  1447. html += "<td>&nbsp;&nbsp;&nbsp;FC:</td><td>&nbsp;" + ship.friendlycode + "</td></tr>";
  1448. }
  1449. if (settings.showPlayerForAllies && vgap.fullallied(ship.ownerid)) {
  1450. html += "<tr><td colspan='8'>" + race.name + " (" + player.username + ")" + "</td></tr>";
  1451. }
  1452. html += this.hitText(hit, hit.isPlanet).replace("&nbsp", "");
  1453. html += "</table></div>";
  1454. } else { //enemy
  1455. if (vgap.plugins["enemyShipListPlugin"] && (vgap.planetAt(hit.x, hit.y))) { // Plugin Loaded & no Planet - find that Ship in List...
  1456. }
  1457. // Nothing to do - ships already shown
  1458. else {
  1459. html = "<div class='ItemSelectionBox minCorrection'>";
  1460. var player = vgap.getPlayer(ship.ownerid);
  1461. var hull = vgap.getHull(ship.hullid);
  1462. var race = vgap.getRace(player.raceid);
  1463. var efound = false;
  1464. if (vgap.plugins["enemyShipListPlugin"]) { // Plugin Loaded & no Planet - find that Ship in List...
  1465. var eship = "";
  1466. //see if the ship exist in the list
  1467. for (var j = 0; j < vgap.plugins["enemyShipListPlugin"].enemyShipList.length; j++) {
  1468. eship = vgap.plugins["enemyShipListPlugin"].enemyShipList[j];
  1469. if (eship.id == ship.id) { // Ship in List!
  1470. //console.log("Ship in List: ID:-"+" j:"+j+" Ship-ID:"+ship.id+" eship-ID:"+eship.id+" Beams:"+eship.beams+" ID:"+eship.beamid);
  1471. //ship = vgap.plugins["enemyShipListPlugin"].enemyShipList[j];
  1472. efound = true;
  1473. break;
  1474. }
  1475. }
  1476. //}
  1477. }
  1478. // class='enemyShipStyle'
  1479. html += "<table class='CleanTable' style='width: 100%'><colgroup span='8'></colgroup>";
  1480. if (settings.terseShip) {
  1481. html += "<tr><td colspan='5' class='WarnText'>" + ship.id + ": " + ship.name.substr(0, 10) + "&nbsp(" + race.name + "'s " + hitText.prototype.shortHullName(hull) + ")</td>";
  1482. if (efound) {
  1483. if (vgap.game.turn <= eship.infoturn) { //ignore info from future turns in case of history
  1484.  
  1485. html += "<td colspan='3'>" + "&nbspE-" + eship.engineid;
  1486. if (eship.beams > 0) // Has Beams?
  1487. html += "&nbsp" + "B-" + eship.beamid;
  1488. if (eship.torps > 0) // Has Launchers?
  1489. html += "&nbsp" + "T-" + eship.torpedoid + ":";
  1490. if (hull.fighterbays > 0) // Has Fighter-Bays?
  1491. html += "&nbspF-" + hull.fighterbays + ":";
  1492. if (hull.fighterbays > 0 || eship.torps > 0)
  1493. html += "&nbsp" + eship.ammo;
  1494. } else
  1495. html += "<td colspan='3'>Old info from turn: " + eship.infoturn + "</td>";
  1496. }
  1497. html += "</td></tr>";
  1498. html += "<tr><td>Heading:</td><td>&nbsp;" + gsv(ship.heading);
  1499. html += "</td><td>&nbsp;at Warp:</td><td>&nbsp;" + gsv(ship.warp);
  1500. html += "</td><td>&nbsp;Mass:</td><td>&nbsp;" + gsv(ship.mass);
  1501. var cargo = ship.mass - hull.mass;
  1502. if (efound) {
  1503. var weappon = 0;
  1504. if (eship.beams > 0) {
  1505. var beam = vgap.getBeam(eship.beamid);
  1506. weappon += beam.mass * eship.beams;
  1507. }
  1508. if (eship.torps > 0) {
  1509. var torp = vgap.getTorpedo(eship.torpedoid);
  1510. weappon += torp.mass * eship.torps;
  1511. }
  1512. var wtx = "";
  1513. if (weappon > 0)
  1514. if (cargo < weappon)
  1515. wtx = "0-";
  1516. else
  1517. wtx = (cargo - weappon) + "-";
  1518. }
  1519. wtx += cargo;
  1520. html += "</td><td colspan='2'>&nbsp;(" + wtx + ")</td></tr>";
  1521. } else {
  1522. html += "<tr><td colspan='2' class='BadText'>" + ship.id + ": " + ship.name + "</td></tr>";
  1523. html += "<tr><td colspan='2' class='BadText'>" + hull.name + "</td></tr>";
  1524. html += "<tr><td>Heading:</td><td>&nbsp;" + gsv(ship.heading) + " at Warp: " + gsv(ship.warp) + "</td></tr>";
  1525. html += "<tr><td>Mass: </td><td>&nbsp;" + gsv(ship.mass) + "</td></tr>";
  1526. html += "<tr><td colspan='2'>" + race.name + " (" + player.username + ")" + "</td></tr>";
  1527. //html += "<tr><td>Neutronium:</td><td>?/" + hull.fueltank + " </td><td>&nbsp;Total Cargo:</td><td>?/" + hull.cargo + "</td></tr>";
  1528. }
  1529. html += this.hitText(hit, hit.isPlanet).replace("&nbsp", "");
  1530. html += "</table></div>";
  1531. }
  1532. }
  1533. txt = html;
  1534. } else { // Use original ship...
  1535. var txt = old_hitTextBox.apply(this, arguments);
  1536. }
  1537. }
  1538. return txt;
  1539. };
  1540.  
  1541. vgaPlanets.prototype.shipTransferView = function (ship, onclick) {
  1542. var hull = vgap.getHull(ship.hullid);
  1543. var totalCargo = ship.ammo + ship.duranium + ship.tritanium + ship.molybdenum + ship.supplies + ship.clans;
  1544. var html = "<div class='ItemSelection' onclick='" + onclick + "'>";
  1545. html += "<img src='" + hullImg(ship.hullid) + "'/>";
  1546. if (ship.ownerid == vgap.player.id || vgap.fullallied(ship.ownerid)) {
  1547. html += "<div " + (vgap.fullallied(ship.ownerid) ? "class='AllyText'" : "") + ">";
  1548. if (ship.ownerid != vgap.player.id)
  1549. html += vgap.raceName(ship.ownerid);
  1550. html += "<span>" + ship.id + ": " + ship.name + "</span>";
  1551. html += "<table class='CleanTable'>";
  1552. html += "<tr><td>Neutronium:</td><td>" + gsv(ship.neutronium) + "/" + hull.fueltank + " </td><td>Total Cargo:</td><td>" + gsv(totalCargo) + "/" + hull.cargo + "</td></tr>";
  1553. html += "<tr><td>Duranium:</td><td>" + gsv(ship.duranium) + "</td><td>Supplies:</td><td>" + gsv(ship.supplies) + "</td></tr>";
  1554. html += "<tr><td>Tritanium:</td><td>" + gsv(ship.tritanium) + "</td><td>Megacredits:</td><td>" + gsv(ship.megacredits) + "</td></tr>";
  1555. html += "<tr><td>Molybdenum:</td><td>" + gsv(ship.molybdenum) + "</td><td>Clans:</td><td>" + gsv(ship.clans) + "</td></tr>";
  1556. if (ship.torps > 0 || ship.bays > 0) {
  1557. var ammoText = "Fighters";
  1558. if (ship.torps > 0)
  1559. ammoText = "Torpedos";
  1560. html += "<tr><td>" + ammoText + ":</td><td>" + gsv(ship.ammo) + "</td></tr>";
  1561. } else
  1562. html += "<tr><td/><td/></tr>";
  1563. html += "</table></div>";
  1564. } else {
  1565. html += "<span class='BadText'>" + ship.id + ": " + ship.name + "</span>";
  1566. html += "<div class='BadText'>" + vgap.raceName(ship.ownerid);
  1567. html += "<table class='CleanTable'>";
  1568. html += "<tr><td>Neutronium:</td><td>?/" + hull.fueltank + " </td><td>Total Cargo:</td><td>?/" + hull.cargo + "</td></tr>";
  1569. html += "</table></div>";
  1570. }
  1571. html += "</div>";
  1572.  
  1573. // vgap.action added for the assistant (Alex):
  1574. // vgap.action();
  1575.  
  1576. return html;
  1577. };
  1578.  
  1579. vgaPlanets.prototype.shipFullInfoView = function (ship, onclick) {
  1580. var view = this.shipTransferView(ship, onclick);
  1581. var html = ""; //"<table class='CleanTable'>";
  1582. //html += "<tr>";
  1583. html += "<td>Friendly Code:</td><td>" + ship.friendlycode + "</td></tr>";
  1584. html += "<tr><td colspan='2'>Warp " + ship.warp + "</td>"
  1585. html += "<td colspan='2'>" + vgap.getShipMission(ship) + ((ship.mission == 6 || ship.mission == 7) && ship.mission1target > 0 ? " " + ship.mission1target : "") + "</td></tr>";
  1586. html += "<tr>";
  1587. if (ship.damage > 0)
  1588. html += "<td>Damage:</td><td class='BadText'>" + ship.damage + "</td>";
  1589. else if (ship.iscloaked)
  1590. html += "<td colspan='2' class='GoodText'>Cloaked</td>";
  1591. else
  1592. html += "<td/><td/>";
  1593. html += "</tr></table>";
  1594. //html += "</table>"
  1595.  
  1596. // vgap.action added for the assistant (Alex):
  1597. // vgap.action();
  1598.  
  1599. view = view.split("</tr></table>").join(html);
  1600. return view;
  1601.  
  1602. };
  1603.  
  1604. vgaPlanets.prototype.showHover = function (shipId) {
  1605. var ship = vgap.getShip(shipId);
  1606. var newheight = 100;
  1607. if (ship.ownerid == vgap.player.id || ship.allyupdate) {
  1608. this.hc.html(this.shipFullInfoView(ship, ""));
  1609. newheight = 120;
  1610. if (ship.allyupdate)
  1611. newheight += 10;
  1612. } else if (vgap.fullallied(ship.ownerid)) {
  1613. this.hc.html(this.shipTransferView(ship, ""));
  1614. newheight = 110
  1615. } else
  1616. this.hc.html(this.shipScan(ship, "")); //Quapla check
  1617. this.hc.show();
  1618. this.hc.height(newheight);
  1619.  
  1620. // vgap.action added for the assistant (Alex):
  1621. // vgap.action();
  1622.  
  1623. };
  1624. //*/
  1625.  
  1626. vgaPlanets.prototype.getShipMission = function (ship) {
  1627. var missions = new Array();
  1628. var mdesc = new Array();
  1629. var raceid = vgap.getPlayer(ship.ownerid).raceid;
  1630. missions.push("Exploration");
  1631. mdesc.push("Return information about planets you visit.");
  1632. missions.push("Mine Sweep");
  1633. mdesc.push("Sweep or detect enemy minefields.");
  1634. if (ship.torps > 0) {
  1635. missions.push("Lay Mines");
  1636. mdesc.push("Convert your torpedos to deep space mines.");
  1637. } else {
  1638. missions.push("");
  1639. mdesc.push("");
  1640. }
  1641. missions.push("Kill!!");
  1642. mdesc.push("Attack any enemy ship or planet you encounter.");
  1643. if (ship.hullid == 84 || ship.hullid == 96 || ship.hullid == 9) {
  1644. missions.push("Bio Scan");
  1645. mdesc.push("Search for native life on nearby planets.");
  1646. } else {
  1647. missions.push("Sensor Sweep");
  1648. mdesc.push("Search for enemy colonies on nearby planets.");
  1649. }
  1650. missions.push("Land and Disassemble");
  1651. mdesc.push("Dismantle this ship on an owned or unowned planet.");
  1652. //if (ships.length > 1 && this.hull.engines > 1) {
  1653. missions.push("Try to Tow");
  1654. mdesc.push("Try to tow another ship at this location.");
  1655. /*
  1656. }
  1657. else {
  1658. missions.push("");
  1659. mdesc.push("");
  1660. }
  1661. */
  1662. missions.push("Try to Intercept");
  1663. mdesc.push("Try to intercept the ship you have selected.");
  1664. if (raceid == 1) {
  1665. missions.push("Super Refit");
  1666. mdesc.push("Upgrade this ship to the best available parts. Must be at a starbase to work.");
  1667. } else if (raceid == 2) {
  1668. if (ship.beams > 0) {
  1669. missions.push("Hisssss!");
  1670. mdesc.push("Increase the happiness on the planet you orbit.");
  1671. } else {
  1672. missions.push("");
  1673. mdesc.push("");
  1674. }
  1675. } else if (raceid == 3) {
  1676. missions.push("Super Spy");
  1677. mdesc.push("Spy on an enemy planet for info or to change its friendly code.");
  1678. } else if (raceid == 4) {
  1679. if (ship.beams > 0) {
  1680. missions.push("Pillage Planet");
  1681. mdesc.push("Pillage a planet for supplies and money.");
  1682. } else {
  1683. missions.push("");
  1684. mdesc.push("");
  1685. }
  1686. } else if (raceid == 5) {
  1687. missions.push("Rob Ship");
  1688. mdesc.push("Rob an enemy ship of its fuel or cargo.");
  1689. } else if (raceid == 6) {
  1690. missions.push("Self Repair");
  1691. mdesc.push("Repair this ship by 10% / turn.");
  1692. } else if (raceid == 7) {
  1693. if (ship.torps > 0) {
  1694. missions.push("Lay Web Mines");
  1695. mdesc.push("Convert your torpedos to special fuel sucking mines.");
  1696. } else {
  1697. missions.push("");
  1698. mdesc.push("");
  1699. }
  1700. } else if (raceid == 8) {
  1701. missions.push("Dark Sense");
  1702. mdesc.push("Sense enemy colonies and starbases on nearby planets.");
  1703. } else if (raceid == 9 || raceid == 11) {
  1704. if (ship.bays > 0) {
  1705. missions.push("Build Fighters");
  1706. mdesc.push("Build fighters on your ship for 3 tritanium, 2 molybdenum and 5 supplies each.");
  1707. } else {
  1708. missions.push("");
  1709. mdesc.push("");
  1710. }
  1711. } else if (raceid == 10) {
  1712. missions.push("Rebel Ground Attack");
  1713. mdesc.push("Sabotage the planet to destroy buildings and kill colonists.");
  1714. }
  1715.  
  1716. if (vgap.getHull(ship.hullid).cancloak) {
  1717. missions.push("Cloak");
  1718. mdesc.push("Make this ship invisible to enemies.");
  1719. } else {
  1720. missions.push("");
  1721. mdesc.push("");
  1722. }
  1723. /*
  1724. if (this.planet != null) {
  1725. missions.push("Beam up Neutronium Fuel from " + this.planet.name);
  1726. mdesc.push("");
  1727. missions.push("Beam up Duranium from " + this.planet.name);
  1728. mdesc.push("");
  1729. missions.push("Beam up Tritanium from " + this.planet.name);
  1730. mdesc.push("");
  1731. missions.push("Beam up Molybdenum from " + this.planet.name);
  1732. mdesc.push("");
  1733. missions.push("Beam up Supplies from " + this.planet.name);
  1734. mdesc.push("");
  1735. } else {
  1736. */
  1737. missions.push("Beam up Fuel");
  1738. mdesc.push("");
  1739. missions.push("Beam up Duranium");
  1740. mdesc.push("");
  1741. missions.push("Beam up Tritanium");
  1742. mdesc.push("");
  1743. missions.push("Beam up Molybdenum");
  1744. mdesc.push("");
  1745. missions.push("Beam up Supplies");
  1746. mdesc.push("");
  1747. //}
  1748. return missions[ship.mission];
  1749. };
  1750.  
  1751. var old_showSettings = vgapDashboard.prototype.showSettings;
  1752. vgapDashboard.prototype.showSettings = function () {
  1753.  
  1754. old_showSettings.apply(this, arguments);
  1755.  
  1756. var settings = vgaPlanets.prototype.addOns.vgapHoverPrediction.settings;
  1757.  
  1758. var html = "";
  1759. html += "<div id='vgapHoverPredictionSettings'><table>";
  1760. html += "<tr><th colspan='4'>Add-On Settings: Quapla's Hover Prediction</th></tr>";
  1761. html += "<tr>";
  1762. html += "<td>Use terse planet prediction</td><td><input type='checkbox'" + (settings.tersePlanet ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.tersePlanet = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.tersePlanet; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1763. html += "<td>Use terse ship prediction</td><td><input type='checkbox'" + (settings.terseShip ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.terseShip = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.terseShip; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1764. html += "<td>Use very terse ship prediction</td><td><input type='checkbox'" + (settings.veryterseship ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.veryterseship = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.veryterseship; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1765. html += "</tr><tr>";
  1766. html += "<td>Show next ship prediction</td><td><input type='checkbox'" + (settings.showShips ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showShips = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showShips; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1767. html += "<td>Show next Ressources prediction</td><td><input type='checkbox'" + (settings.showRessources ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showRessources = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showRessources; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1768. html += "</tr><tr>";
  1769. html += "<td>Show player for allied ships</td><td><input type='checkbox'" + (settings.showPlayerForAllies ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showPlayerForAllies = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showPlayerForAllies; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1770. html += "<td>Show hull type for allied ships</td><td><input type='checkbox'" + (settings.showHullForAllies ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showHullForAllies = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showHullForAllies; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1771. html += "</tr><tr>";
  1772. html += "<td>Show hull type for my ships</td><td><input type='checkbox'" + (settings.showHullForMine ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showHullForMine = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showHullForMine; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1773. html += "<td>Show mission for ships</td><td><input type='checkbox'" + (settings.showShipMission ? "checked='true'" : "") + "onChange='vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showShipMission = !vgaPlanets.prototype.addOns.vgapHoverPrediction.settings.showShipMission; vgap.addOns.vgapHoverPrediction.saveSettings();'/></td>";
  1774. html += "</tr>";
  1775. html += "</table></div>";
  1776.  
  1777. $("#HoverSettings").after(html);
  1778. this.pane.jScrollPane();
  1779.  
  1780. };
  1781. /* //REPLACED MAP TOOL WITH PERSISTENT SETTING
  1782. var old_loadControls = vgapMap.prototype.loadControls;
  1783. vgapMap.prototype.loadControls = function () {
  1784.  
  1785. old_loadControls.apply(this, arguments);
  1786.  
  1787. var additem = "<li onclick='vgap.addOns.vgapHoverPrediction.settings.terseInfo = !vgap.addOns.vgapHoverPrediction.settings.terseInfo;'>Switch Info View</li>";
  1788.  
  1789. //$("#MapTools").append(additem);
  1790. $("#MapTools > li:contains('Connections (q)')").after(additem);
  1791.  
  1792. var height = this.controls.height() - this.toolsMenu.height();
  1793. this.controls.css("marginTop", "-" + this.controls.height() + "px");
  1794.  
  1795. };
  1796. */
  1797.  
  1798. }
  1799.  
  1800. var script = document.createElement("script");
  1801. script.type = "application/javascript";
  1802. script.textContent = "(" + wrapper + ")();";
  1803.  
  1804. document.body.appendChild(script);