Planets.nu Fleet UI

Planets.nu Fleet UI for Ship Screen

  1. // ==UserScript==
  2. // @name Planets.nu Fleet UI
  3. // @description Planets.nu Fleet UI for Ship Screen
  4. // @include http://planets.nu/home
  5. // @include http://planets.nu/games/*
  6. // @include http://play.planets.nu/*
  7. // @include http://*.planets.nu/*
  8. // @include http://test.planets.nu/*
  9. // @include http://planets.nu/*
  10. // @version 0.91
  11. // @namespace https://greasyfork.org/users/2860
  12. // ==/UserScript==
  13. // 0.1 First version - adds new Fleet tab to ship screen view, and the Set Fleet Movement button.
  14. // 0.2 Sets speed for all non-towed ships to the same speed as the current ship
  15. // 0.3 Keeps track of number of ships at that location, and displays the total cargo for all ships combined
  16. // 0.4 Add in buttons that let you move forward and backwards among the ships of the fleet.
  17. // 0.5 Checks fuel when setting group destination, adds button to display only ships with low fuel warnings
  18. // 0.6 Now supports use of [] tags for fleet names. [] tagged ships are treated as fleets.
  19. // 0.7 Adds minesweep, minelay, fighter, and torp information for fleet.
  20. // 0.8 Improved fleet information.
  21. // 0.9 Ready all/Unready all (ignores double checked ships), modified formatting to fit more info, added hook into fleet view mod
  22.  
  23. function wrapper () { // wrapper for injection
  24. var fleetNames=new Array();
  25. var fleetFlagships=new Array();
  26. var fleetSizes=new Array();
  27. var oldLoad = vgapShipScreen.prototype.load;
  28.  
  29. vgapShipScreen.prototype.load = function (ship) {
  30.  
  31.  
  32. oldLoad.apply(this, arguments);
  33. $("<div class='SepBar'><div class='SepButton' id='"+ship.id+"' title='Use this Ships warp for all non-towed ships at this location' onclick='setFleetSpeed(this);'>Set Speed</div><div class='SepButton' id='"+ship.id+"' title='Use this Ships waypoints for all ships at this location' onclick='moveFleet(this);'>Set Destination</div><div class='SepTitle' id='FleetTitle' onclick=\"vgap.septoggle('FleetCommands');\"></div></div>").appendTo("#ShipScreen");
  34. this.Fleet = $("<div class='SepContainer' id='FleetCommands'/>").appendTo("#ShipScreen");
  35. this.loadFleet();
  36. vgap.shipScreen.draw();
  37.  
  38. };
  39.  
  40. vgapShipScreen.prototype.loadFleet = function () {
  41. //this.Fleet.empty();
  42. var ship = this.ship;
  43. var html = "<table width='100%'>";
  44. var ship_count=0;
  45. var supply_count=0;
  46. var moly_count=0;
  47. var clan_count=0;
  48. var dur_count=0;
  49. var tri_count=0;
  50. var mc_count = 0;
  51. var neut_count=0;
  52. var mine_sweep=0;
  53. var fighter_count=0;
  54. var mine_count=0;
  55. var minelay_torp_count=0;
  56. var total_cargo=0;
  57. var total_cargo_used=0;
  58. var total_fuel=0;
  59. var low_fuel_count=0;
  60. var fleetName=returnFleetName(ship);
  61. if (fleetName!=-1) //in a labeled fleet
  62. {
  63. for (var i = 0; i < vgap.myships.length; i++)
  64. if(returnFleetName(vgap.myships[i])==fleetName)
  65. {
  66. var hull = vgap.getHull(vgap.myships[i].hullid);
  67. supply_count+=vgap.myships[i].supplies;
  68. moly_count+=vgap.myships[i].molybdenum;
  69. clan_count+=vgap.myships[i].clans;
  70. dur_count+=vgap.myships[i].duranium;
  71. tri_count+=vgap.myships[i].tritanium;
  72. mc_count +=vgap.myships[i].megacredits;
  73. neut_count+=vgap.myships[i].neutronium;
  74. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i])) low_fuel_count++;
  75. if (vgap.myships[i].bays > 0)
  76. fighter_count+=vgap.myships[i].ammo;
  77. if (vgap.myships[i].beams > 0)
  78. mine_sweep+=(vgap.myships[i].beams * vgap.myships[i].beamid * vgap.myships[i].beamid);
  79. if (vgap.myships[i].torps > 0)
  80. {
  81. minelay_torp_count+=vgap.myships[i].minelaytorps;
  82. mine_count+=vgapShipScreen.prototype.getMineUnits(vgap.myships[i]);
  83. }
  84. total_cargo_used+=(vgap.myships[i].ammo + vgap.myships[i].duranium + vgap.myships[i].tritanium + vgap.myships[i].molybdenum + vgap.myships[i].supplies + vgap.myships[i].clans);
  85. total_cargo+=hull.cargo;
  86. total_fuel+=hull.fueltank;
  87. }
  88. $("#FleetTitle").text("Fleet: "+ fleetName + " - " +returnFleetSize(fleetName)+ " ships");
  89.  
  90. }
  91. else //unlabeled group at a location
  92. {
  93. for (var i = 0; i < vgap.myships.length; i++)
  94. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  95. {
  96. var hull = vgap.getHull(vgap.myships[i].hullid);
  97. ship_count++;
  98. supply_count+=vgap.myships[i].supplies;
  99. moly_count+=vgap.myships[i].molybdenum;
  100. clan_count+=vgap.myships[i].clans;
  101. dur_count+=vgap.myships[i].duranium;
  102. tri_count+=vgap.myships[i].tritanium;
  103. mc_count +=vgap.myships[i].megacredits;
  104. neut_count+=vgap.myships[i].neutronium;
  105. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i])) low_fuel_count++;
  106. if (vgap.myships[i].bays > 0)
  107. fighter_count+=vgap.myships[i].ammo;
  108. if (vgap.myships[i].beams > 0)
  109. mine_sweep+=(vgap.myships[i].beams * vgap.myships[i].beamid * vgap.myships[i].beamid);
  110. if (vgap.myships[i].torps > 0)
  111. {
  112. minelay_torp_count+=vgap.myships[i].ammo;
  113. mine_count+=vgapShipScreen.prototype.getMineUnits(vgap.myships[i]);
  114. }
  115. total_cargo_used+=(vgap.myships[i].ammo + vgap.myships[i].duranium + vgap.myships[i].tritanium + vgap.myships[i].molybdenum + vgap.myships[i].supplies + vgap.myships[i].clans);
  116. total_cargo+=hull.cargo;
  117. total_fuel+=hull.fueltank;
  118. }
  119. $("#FleetTitle").text("Fleet: "+ ship_count+ " at location");
  120. }
  121. var html;
  122. html="<button id='"+ship.id+"' onclick='fleetBack(this);'>< Fleet</button><button id='"+ship.id+"' onclick='fleetNext(this);'>Fleet ></button>";
  123. html+="<button id='"+ship.id+"' onclick='shipBack(this);'>< Ship</button><button id='"+ship.id+"' onclick='shipNext(this);'>Ship ></button>";
  124. html+="<button id='"+ship.id+"' onclick='readyFleet(this);'>Set Ready</button>";
  125. html+="<button id='"+ship.id+"' onclick='saveShipID(this);vgap.showDashboard();vgap.dash.showShips(5);'>List</button>";
  126. //alert("hi");
  127. html += "<table width='100%'>";
  128. if (vgaPlanets.prototype.version<3)
  129. html += "<tr><td>Neutronium:</td><td style='color:#006600;font-weight:bold;'>" + neut_count + "/" + total_fuel + " kt</td><td> Fuel Warnings:<button id='"+ship.id+","+low_fuel_count+",0' onclick='showShips2(this);'> " + low_fuel_count + "</button></td></tr>";
  130. else
  131. html += "<tr><td>Neutronium:</td><td style='color:#006600;font-weight:bold;'>" + neut_count + "/" + total_fuel + " kt</td><td> Fuel Warnings:<button id='"+ship.id+","+low_fuel_count+",0' onclick='showShips3(this);'> " + low_fuel_count + "</button></td></tr>";
  132. html += "</table>";
  133. html += "<table width='100%'>";
  134. html += "<tr><td class='head'>CARGO:</td><td class='val'>" + total_cargo_used +"/"+total_cargo + "</td><td class='head'>Fighters:</td><td class='val'>" + fighter_count + "</td><td class='head'>Torps:</td><td class='val'>" + minelay_torp_count + "</td></tr>";
  135. html += "<tr><td class='head'>Dur:</td><td class='val'>" + dur_count + " kt</td><td class='head'>Tri:</td><td class='val'>" + tri_count + " kt</td><td class='head'>Moly:</td><td class='val'>" + moly_count + " kt</td></tr>";
  136. html += "<tr><td class='head'>MCs:</td><td class='val'>" + mc_count + "</td><td class='head'>Sup:</td><td class='val'>" + supply_count + " kt</td><td class='head'>Clans:</td><td class='val'>" + clan_count + "</td></tr>";
  137. html += "</table>";
  138. html += "<table width='100%'>";
  139. html += "<tr><td>Minelay:</td><td style='color:#006600;font-weight:bold;' >" + mine_count + " Mines</td><td>Minesweep:</td><td style='color:#006600;font-weight:bold;' >" + mine_sweep*4 + " /"+ mine_sweep*3 + " Web</td></tr>";
  140. html += "</table>";
  141. $(html).appendTo("#FleetCommands");
  142. };
  143.  
  144. shipBack = function(passed)
  145. {
  146. var ship=vgap.getShip(passed.id);
  147. var last=ship;
  148. var fleetName=returnFleetName(ship);
  149. if (fleetName!=-1) //in a labeled fleet
  150. {
  151. for (var i = 0; i < vgap.myships.length; i++)
  152. if(returnFleetName(vgap.myships[i])==fleetName)
  153. if (vgap.myships[i].id==ship.id)
  154. if (ship.id!=last.id)
  155. vgap.map.selectShip(last.id);
  156. else
  157. break;
  158. else
  159. last=vgap.myships[i];
  160. }
  161. else //in an unlabeled group
  162. for (var i = 0; i < vgap.myships.length; i++)
  163. {
  164. var fleet=returnFleetName(vgap.myships[i]);
  165. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y)&&(fleet==-1))
  166. if (vgap.myships[i].id==ship.id)
  167. if (ship.id!=last.id)
  168. vgap.map.selectShip(last.id);
  169. else
  170. break;
  171. else
  172. last=vgap.myships[i];
  173. }
  174. //vgap.map.selectShip(id);
  175. };
  176.  
  177. shipNext = function(passed)
  178. {
  179. var ship=vgap.getShip(passed.id);
  180. var last=ship;
  181. var number=vgap.myships.length-1;
  182. var fleetName=returnFleetName(ship);
  183. if (fleetName!=-1) //in a labeled fleet
  184. {
  185. for (var i = number; i>=0 ; i--)
  186. if(returnFleetName(vgap.myships[i])==fleetName)
  187. if (vgap.myships[i].id==ship.id)
  188. if (ship.id!=last.id)
  189. vgap.map.selectShip(last.id);
  190. else
  191. break;
  192. else
  193. last=vgap.myships[i];
  194. }
  195. else //in an unlabeled group
  196. for (var i = number; i>=0 ; i--)
  197. {
  198. var fleet=returnFleetName(vgap.myships[i]);
  199. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y)&&(fleet==-1))
  200. if (vgap.myships[i].id==ship.id)
  201. if (ship.id!=last.id)
  202. vgap.map.selectShip(last.id);
  203. else
  204. break;
  205. else
  206. last=vgap.myships[i];
  207. }
  208. };
  209.  
  210. setFleetSpeed = function(passed)
  211. {
  212. //alert ("hey!");
  213. var towed_ships=0;
  214. var count=0;
  215. var ship = vgap.getShip(passed.id);
  216. var fleetName=returnFleetName(ship);
  217. if (fleetName!=-1) //in a labeled fleet
  218. for (var i = 0; i < vgap.myships.length; i++)
  219. {
  220. if (returnFleetName(vgap.myships[i])==fleetName)
  221. if (vgap.isTowTarget(vgap.myships[i].id))
  222. {
  223. towed_ships++;
  224. vgap.myships[i].warp=0;
  225. }
  226. else
  227. {
  228. count++;
  229. vgap.myships[i].warp = ship.warp;
  230. }
  231. }
  232. else //unlabeled group at location
  233. for (var i = 0; i < vgap.myships.length; i++)
  234. {
  235. //alert("its "+ i);
  236. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  237. {
  238. //alert("hi!");
  239. if (vgap.isTowTarget(vgap.myships[i].id))
  240. {
  241. towed_ships++;
  242. vgap.myships[i].warp=0;
  243. }
  244. else
  245. {
  246. count++;
  247. vgap.myships[i].warp = ship.warp;
  248. }
  249. }
  250. }
  251. alert("Set " + count + " ships to warp " + ship.warp + ", and set " + towed_ships + " towed ships to warp 0");
  252. if (vgaPlanets.prototype.version<3)
  253. vgap.map.updateZoom();
  254. else
  255. {
  256. vgap.loadWaypoints();
  257. vgap.shipScreen.screen.refresh();
  258. }
  259. vgap.map.draw();
  260. };
  261. readyFleet = function(passed)
  262. {
  263. var count=0;
  264. var notReady=0;
  265. var ship = vgap.getShip(passed.id);
  266. //alert(checkFuel(ship));
  267. var fleetName=returnFleetName(ship);
  268. if (fleetName!=-1) //in a labeled fleet
  269. for (var i = 0; i < vgap.myships.length; i++)
  270. {
  271. if (returnFleetName(vgap.myships[i])==fleetName)
  272. {
  273. if (vgap.myships[i].readystatus!=2)
  274. {
  275. vgap.myships[i].readystatus = ship.readystatus;
  276. count++;
  277. }
  278. else
  279. notReady++;
  280. }
  281. }
  282. else //unlabeled group at location
  283. for (var i = 0; i < vgap.myships.length; i++)
  284. {
  285. //alert("its "+ i);
  286. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  287. {
  288. //alert("hi!");
  289. if (vgap.myships[i].readystatus!=2)
  290. {
  291. vgap.myships[i].readystatus = ship.readystatus;
  292. count++;
  293. }
  294. else
  295. notReady++;
  296. }
  297. }
  298. if (notReady>0) alert ("Updated Readiness for " + count + " ships. " + notReady + " ships were skipped");
  299. else
  300. alert("Updated Readiness for " + count + " ships");
  301.  
  302. if (vgaPlanets.prototype.version<3)
  303. vgap.map.updateZoom();
  304. else
  305. {
  306. vgap.loadWaypoints();
  307. vgap.shipScreen.screen.refresh();
  308. }
  309. vgap.map.draw();
  310. };
  311. moveFleet = function(passed)
  312. {
  313. var count=0;
  314. var lowFuel=0;
  315. var ship = vgap.getShip(passed.id);
  316. //alert(checkFuel(ship));
  317. var fleetName=returnFleetName(ship);
  318. if (fleetName!=-1) //in a labeled fleet
  319. for (var i = 0; i < vgap.myships.length; i++)
  320. {
  321. if (returnFleetName(vgap.myships[i])==fleetName)
  322. {
  323. count++;
  324. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i])) lowFuel++;
  325. vgap.myships[i].targetx = ship.targetx;
  326. vgap.myships[i].targety = ship.targety;
  327. vgap.myships[i].waypoints = ship.waypoints;
  328. var dest = vgap.getDest(vgap.myships[i]);
  329. vgap.myships[i].target = vgap.getTarget(dest.x, dest.y);
  330. }
  331. }
  332. else //unlabeled group at location
  333. for (var i = 0; i < vgap.myships.length; i++)
  334. {
  335. //alert("its "+ i);
  336. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  337. {
  338. //alert("hi!");
  339. count++;
  340. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i])) lowFuel++;
  341. vgap.myships[i].targetx = ship.targetx;
  342. vgap.myships[i].targety = ship.targety;
  343. vgap.myships[i].waypoints = ship.waypoints;
  344. var dest = vgap.getDest(vgap.myships[i]);
  345. vgap.myships[i].target = vgap.getTarget(dest.x, dest.y);
  346. }
  347. }
  348. if (lowFuel>0) alert ("Updated destination for " + count + " ships. " + lowFuel + " ships have insufficient fuel!");
  349. else
  350. alert("Updated destination for " + count + " ships");
  351.  
  352. if (vgaPlanets.prototype.version<3)
  353. vgap.map.updateZoom();
  354. else
  355. {
  356. vgap.loadWaypoints();
  357. vgap.shipScreen.screen.refresh();
  358. }
  359. vgap.map.draw();
  360. };
  361.  
  362. showShips2 = function (passed) {
  363. var data = passed.id.split(",");
  364. var ship = vgap.getShip(data[0]);
  365. var inMore = vgap.shipScreenOpen;
  366. var ships;
  367. var title = "";
  368. var html = "<div id='SelectLocation'>";
  369. if (data[2]!=0)
  370. ships = vgap.shipsAt(ship.x, ship.y);
  371. else
  372. {
  373. shipArray=new Array();
  374. var fleetName=returnFleetName(ship);
  375. if (fleetName!=-1) //in a labeled fleet
  376. for (var i = 0; i < vgap.myships.length; i++)
  377. {
  378. if (returnFleetName(vgap.myships[i])==fleetName)
  379. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i]))
  380. shipArray.push(vgap.myships[i]);
  381. }
  382. else //unlabeled group at location
  383. for (var i = 0; i < vgap.myships.length; i++)
  384. {
  385. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  386. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i]))
  387. shipArray.push(vgap.myships[i]);
  388. }
  389. ships=shipArray;
  390. }
  391. for (var i = 0; i < ships.length; i++) {
  392. html += vgap.shipScan(ships[i], "vgap.map.selectShip(" + ships[i].id + ");");
  393. }
  394. if (ships.length > 0) {
  395. if (title != "")
  396. title += ", ";
  397. title += ships.length + " ships";
  398. }
  399.  
  400. html += "</div>";
  401.  
  402. if (inMore) {
  403. html = "<h1>Ships with Fuel Warnings: " + title + "</h1>" + html;
  404. html += "<a class='MoreBack' onclick='vgap.closeMore();return false;'>OK</a>";
  405. vgap.more.empty();
  406. $(html).appendTo(vgap.more);
  407.  
  408. $("#SelectLocation").height($(window).height() - 100);
  409. vgap.showMore(300);
  410. }
  411. else {
  412. html = "<div class='TitleBar'><div class='CloseScreen' onclick='vgap.closeLeft();'></div><div class='TopTitle'>Scan:" + title + "</div></div>" + html;
  413. vgap.map.centerMap(ship.x, ship.y);
  414. vgap.lc.empty();
  415. $(html).appendTo(vgap.lc);
  416. vgap.openLeft();
  417. $("#SelectLocation").height($(window).height() - 40);
  418. $("#SelectLocation").width(380);
  419. }
  420. $("#SelectLocation").jScrollPane();
  421. };
  422. showShips3 = function (passed) {
  423. var data = passed.id.split(",");
  424. var ship = vgap.getShip(data[0]);
  425. var inMore = vgap.shipScreenOpen;
  426.  
  427. if (data[2]!=0)
  428. ships = vgap.shipsAt(ship.x, ship.y);
  429. else
  430. {
  431. shipArray=new Array();
  432. var fleetName=returnFleetName(ship);
  433. if (fleetName!=-1) //in a labeled fleet
  434. for (var i = 0; i < vgap.myships.length; i++)
  435. {
  436. if (returnFleetName(vgap.myships[i])==fleetName)
  437. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i]))
  438. shipArray.push(vgap.myships[i]);
  439. }
  440. else //unlabeled group at location
  441. for (var i = 0; i < vgap.myships.length; i++)
  442. {
  443. if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
  444. if (vgap.myships[i].neutronium<checkFuel(vgap.myships[i]))
  445. shipArray.push(vgap.myships[i]);
  446. }
  447. ships=shipArray;
  448. }
  449. var title = "";
  450. var html = "<div id='SelectLocation'></div>";
  451.  
  452. if (inMore) {
  453. html = "<h1 id='ScanTitle'>Ships with Fuel Warnings: " + title + "</h1>" + html;
  454. vgap.more.empty();
  455. $(html).appendTo(vgap.more);
  456. shtml.moreBack();
  457. }
  458. else {
  459. var lc = new leftContent("ScanScreen", "Scan: ", null, function () { vgap.closeLeft(); });
  460. vgap.map.centerMap(ship.x, ship.y);
  461. $(html).appendTo(vgap.lc);
  462. }
  463. for (var i = 0; i < ships.length; i++) {
  464. var scan = $(shtml.shipScan(ships[i])).appendTo("#SelectLocation");
  465. scan.click(function (e) { vgap.map.selectShip($(this).data("id")); });
  466. }
  467. if (ships.length > 0) {
  468. if (title != "")
  469. title += ", ";
  470. title += ships.length + " Ships with Fuel warnings";
  471. }
  472.  
  473. if (inMore) {
  474. $("#ScanTitle").text(title);
  475. //$("#SelectLocation").height($(window).height() - 100);
  476. vgap.showMore(330);
  477. }
  478. else {
  479. $("#ScanScreen .TopTitle").text(title);
  480. vgap.openLeft();
  481. //$("#SelectLocation").height($(window).height() - 40);
  482. $("#SelectLocation").width(380);
  483. }
  484. if ($("#SelectLocation").height() > ($(window).height() - 40)) {
  485. $("#SelectLocation").height($(window).height() - 40);
  486. $("#SelectLocation").jScrollPane();
  487. }
  488.  
  489. };
  490. saveShipID=function(passed)
  491. {
  492. set_cookie("currentShipID",passed.id);
  493. };
  494. //====================FLEET FUNCTIONS=================================
  495. buildFleetList=function()
  496. {
  497. fleetNames.length=0;
  498. fleetFlagships.length=0;
  499. fleetSizes.length=0;
  500.  
  501. for (var i = 0; i < vgap.myships.length; i++)
  502. {
  503. if (vgap.myships[i].name.charAt(0)=='[')
  504. if (vgap.myships[i].name.indexOf(']')!=-1)
  505. {
  506. var name=vgap.myships[i].name.substring(1,vgap.myships[i].name.indexOf(']'));
  507. var position=fleetNames.indexOf(name);
  508. if (position==-1) //fleet is new
  509. {
  510. fleetNames.push(name);
  511. fleetFlagships.push(vgap.myships[i].id);
  512. fleetSizes.push(1);
  513. // position=(fleetNames.length)-1;//for testing only
  514. }
  515. else
  516. fleetSizes[position]++;
  517. //alert(name+' '+fleetSizes[position]);
  518. }
  519. //alert(vgap.myships[i].name.charAt(1));
  520. }
  521. };
  522.  
  523. returnFleetName = function(ship)
  524. {
  525. if (ship.name.charAt(0)=='[')
  526. if (ship.name.indexOf(']')!=-1)
  527. return(ship.name.substring(1,ship.name.indexOf(']')));
  528. return(-1)
  529. };
  530.  
  531. returnFlagshipID = function(fleet_name)
  532. {
  533. var index=fleetNames.indexOf(fleet_name);
  534. return(fleetFlagships[index]);
  535. };
  536.  
  537. returnFleetSize = function(fleet_name)
  538. {
  539. var index=fleetNames.indexOf(fleet_name);
  540. return (fleetSizes[index]);
  541. };
  542.  
  543. fleetBack = function(passed)
  544. {
  545. var ship=vgap.getShip(passed.id);
  546. var fleetName=returnFleetName(ship);
  547. var index;
  548. if (fleetName!=-1)
  549. {
  550. index=fleetNames.indexOf(fleetName);
  551. if(index>0) vgap.map.selectShip(fleetFlagships[index-1]);
  552. if(index==0) vgap.map.selectShip(fleetFlagships[fleetFlagships.length-1]);
  553. }
  554. else if (typeof fleetFlagShips[0] != 'undefined')
  555. vgap.map.selectShip(fleetFlagships[0]);
  556. };
  557.  
  558. fleetNext = function(passed)
  559. {
  560. var ship=vgap.getShip(passed.id);
  561. var fleetName=returnFleetName(ship);
  562. var index;
  563. if (fleetName!=-1)
  564. {
  565. index=fleetNames.indexOf(fleetName);
  566. var number=fleetFlagships.length;
  567. number--;
  568. //alert(fleetFlagships.length + " " + index + " " + number);
  569. if(index<number) vgap.map.selectShip(fleetFlagships[index+1]);
  570. if(index==number)
  571. vgap.map.selectShip(fleetFlagships[0]);
  572. }
  573. else if (typeof fleetFlagShips[0] != 'undefined')
  574. vgap.map.selectShip(fleetFlagships[0]);
  575. }
  576.  
  577. var oldchangeShipName=vgapShipScreen.prototype.changeShipName;
  578.  
  579. vgapShipScreen.prototype.changeShipName = function () {
  580. oldchangeShipName.apply(this, arguments);
  581. buildFleetList();
  582. };
  583.  
  584. var oldprocessLoad=vgaPlanets.prototype.processLoad;
  585.  
  586. vgaPlanets.prototype.processLoad = function (result){
  587. oldprocessLoad.apply(this,arguments);
  588. buildFleetList();
  589. };
  590.  
  591.  
  592. //================END FLEET FUNCTIONS=================================
  593. //====================FUEL FUNCTIONS==================================
  594. checkFuel = function(ship)
  595. {
  596. var fuel=0;
  597. var path = vgap.getPath(ship);
  598. for (var i = 0; i < path.length; i++) {
  599. if (vgaPlanets.prototype.version<3)
  600. fuel += getFuelUsage2(ship,path[i].x1, path[i].y1, path[i].x2, path[i].y2);
  601. else
  602. fuel += getFuelUsage3(ship,path[i].x1, path[i].y1, path[i].x2, path[i].y2);
  603. }
  604. if (fuel == 0)
  605. fuel += cloakedFuel(ship);
  606. return(fuel);
  607. };
  608.  
  609. cloakedFuel = function (ship) {
  610. var hull = vgap.getHull(ship.hullid);
  611. if ((ship.mission == 9 || (vgap.player.raceid == 3 && ship.mission == 8 && hull.cancloak)) && ship.hullid != 29 && ship.hullid != 31)
  612. return Math.max(5, Math.floor((hull.mass / 100) * 5));
  613. else
  614. return 0;
  615. };
  616.  
  617. turnFuel2 = function (distance, mass, xv, turndistance,ship) {
  618. return Math.floor(xv * Math.floor(mass / 10) * ((Math.floor(distance) / turndistance) / 10000)) + cloakedFuel(ship);
  619. },
  620. getFuelUsage2 = function (ship, x1, y1, x2, y2) {
  621. var engine = vgap.getEngine(ship.engineid);
  622. var distance = vgap.map.getDist(x1, y1, x2, y2);
  623.  
  624. if (ship.warp == 0)
  625. return 0;
  626.  
  627. var xv = 0;
  628. switch (ship.warp) {
  629. case 1:
  630. xv = engine.warp1;
  631. break;
  632. case 2:
  633. xv = engine.warp2;
  634. break;
  635. case 3:
  636. xv = engine.warp3;
  637. break;
  638. case 4:
  639. xv = engine.warp4;
  640. break;
  641. case 5:
  642. xv = engine.warp5;
  643. break;
  644. case 6:
  645. xv = engine.warp6;
  646. break;
  647. case 7:
  648. xv = engine.warp7;
  649. break;
  650. case 8:
  651. xv = engine.warp8;
  652. break;
  653. case 9:
  654. xv = engine.warp9;
  655. break;
  656. }
  657. //Save fuel value to update during the calculation
  658. var currentfuel = ship.neutronium;
  659.  
  660. var fuel = 0;
  661. var turndistance = vgap.getSpeed(ship.warp, ship.hullid);
  662.  
  663. var distanceremaining = distance;
  664. var mass = vgapShipScreen.prototype.getMass(ship, true);
  665.  
  666. //tow
  667. if (ship.mission == 6 && ship.mission1target != 0) {
  668. var towship = vgap.getShip(ship.mission1target);
  669. if (towship != null)
  670. mass += vgapShipScreen.prototype.getMass(towship, true);
  671. }
  672.  
  673. var warp = ship.warp;
  674. while (distanceremaining > turndistance) {
  675. distanceremaining -= turndistance;
  676. var turnfuel = turnFuel2(turndistance, mass, xv, turndistance,ship);
  677. fuel += turnfuel;
  678. ship.neutronium -= turnfuel;
  679. if (ship.neutronium < 0) {
  680. turnfuel = ship.neutronium;
  681. ship.neutronium = 0;
  682. }
  683. mass -= turnfuel;
  684. var pa = vgap.planetAt(x2, y2);
  685. if (distanceremaining < 3 && pa != null) {
  686. distanceremaining = 0;
  687. }
  688. }
  689. if (distanceremaining > 0)
  690. fuel += turnFuel2(distanceremaining, mass, xv, turndistance,ship);
  691.  
  692. //Return fuel back to correct value
  693. ship.neutronium = currentfuel;
  694.  
  695. return fuel;
  696. }
  697. getFuelUsage3 = function (ship, x1, y1, x2, y2) {
  698. var engine = vgap.getEngine(ship.engineid);
  699. var distance = Math.dist(x1, y1, x2, y2);
  700.  
  701. if (ship.warp == 0)
  702. return 0;
  703.  
  704. if (vgap.isHyping(ship))
  705. return 50;
  706.  
  707. var xv = vgap.getXV(engine, ship.warp);
  708.  
  709. //Save fuel value to update during the calculation
  710. var currentfuel = ship.neutronium;
  711.  
  712. var fuel = 0;
  713. var turndistance = vgap.getSpeed(ship.warp, ship.hullid);
  714.  
  715. var distanceremaining = distance;
  716. var mass = vgap.getMass(ship, true);
  717.  
  718. //tow
  719. if (ship.mission == 6 && ship.mission1target != 0) {
  720. var towship = vgap.getShip(ship.mission1target);
  721. if (towship != null)
  722. mass += vgap.getMass(towship, true);
  723. }
  724.  
  725. var warp = ship.warp;
  726. while (distanceremaining > turndistance) {
  727. distanceremaining -= turndistance;
  728. var turnfuel = vgap.turnFuel(turndistance, mass, xv, turndistance, vgap.cloakFuel(ship));
  729. fuel += turnfuel;
  730. ship.neutronium -= turnfuel;
  731. if (ship.neutronium < 0) {
  732. turnfuel = ship.neutronium;
  733. ship.neutronium = 0;
  734. }
  735. mass -= turnfuel;
  736. var pa = vgap.planetAt(x2, y2);
  737. if (distanceremaining < 3 && pa != null) {
  738. distanceremaining = 0;
  739. }
  740. }
  741. if (distanceremaining > 0)
  742. fuel += vgap.turnFuel(distanceremaining, mass, xv, turndistance, vgap.cloakFuel(ship));
  743.  
  744. //Return fuel back to correct value
  745. ship.neutronium = currentfuel;
  746.  
  747. return fuel;
  748. }
  749. //==========================END FUEL FUNCTIONS=======================================
  750.  
  751. set_cookie=function( name, value, exp_y, exp_m, exp_d, path, domain, secure )
  752. //name=cookie name (required)
  753. //value=cookie value (required)
  754. //exp_y,M,d is expiration year, month, day (if blank cookie will delete when browser closes)
  755. //path=path within site this applies to (can be blank)
  756. //domain=apply only to websites in this domain (can be blank)
  757. //secure=use SSL (leave blank)
  758.  
  759. {
  760. var cookie_string = name + "=" + escape ( value );
  761.  
  762. if ( exp_y )
  763. {
  764. var expires = new Date ( exp_y, exp_m, exp_d );
  765. cookie_string += "; expires=" + expires.toGMTString();
  766. }
  767.  
  768. if ( path )
  769. cookie_string += "; path=" + escape ( path );
  770.  
  771. if ( domain )
  772. cookie_string += "; domain=" + escape ( domain );
  773. if ( secure )
  774. cookie_string += "; secure";
  775. document.cookie = cookie_string;
  776. };
  777.  
  778. get_cookie =function( cookie_name )
  779. {
  780. var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  781.  
  782. if ( results )
  783. return ( unescape ( results[2] ) );
  784. else
  785. return null;
  786. };
  787.  
  788. /*var oldLoadCargo = vgapShipScreen.prototype.loadCargo;
  789.  
  790. vgapShipScreen.prototype.loadCargo = function () {
  791. oldLoadCargo.apply(this, arguments);
  792. this.loadFleet();
  793. };
  794. */
  795. }
  796. var script = document.createElement("script");
  797. script.type = "application/javascript";
  798. script.textContent = "(" + wrapper + ")();";
  799.  
  800. document.body.appendChild(script);