// ==UserScript==
// @name Planets.nu Fleet UI
// @description Planets.nu Fleet UI for Ship Screen
// @include http://planets.nu/home
// @include http://planets.nu/games/*
// @include http://play.planets.nu/*
// @include http://*.planets.nu/*
// @include http://test.planets.nu/*
// @include http://planets.nu/*
// @version 0.91
// @namespace https://greasyfork.org/users/2860
// @downloadURL https://update.greasyfork.org/scripts/2596/Planetsnu%20Fleet%20UI.user.js
// @updateURL https://update.greasyfork.org/scripts/2596/Planetsnu%20Fleet%20UI.meta.js
// ==/UserScript==
// 0.1 First version - adds new Fleet tab to ship screen view, and the Set Fleet Movement button.
// 0.2 Sets speed for all non-towed ships to the same speed as the current ship
// 0.3 Keeps track of number of ships at that location, and displays the total cargo for all ships combined
// 0.4 Add in buttons that let you move forward and backwards among the ships of the fleet.
// 0.5 Checks fuel when setting group destination, adds button to display only ships with low fuel warnings
// 0.6 Now supports use of [] tags for fleet names. [] tagged ships are treated as fleets.
// 0.7 Adds minesweep, minelay, fighter, and torp information for fleet.
// 0.8 Improved fleet information.
// 0.9 Ready all/Unready all (ignores double checked ships), modified formatting to fit more info, added hook into fleet view mod
function wrapper () { // wrapper for injection
var fleetNames=new Array();
var fleetFlagships=new Array();
var fleetSizes=new Array();
var oldLoad = vgapShipScreen.prototype.load;
vgapShipScreen.prototype.load = function (ship) {
oldLoad.apply(this, arguments);
$("
Set Speed
Set Destination
").appendTo("#ShipScreen");
this.Fleet = $("").appendTo("#ShipScreen");
this.loadFleet();
vgap.shipScreen.draw();
};
vgapShipScreen.prototype.loadFleet = function () {
//this.Fleet.empty();
var ship = this.ship;
var html = "
";
var ship_count=0;
var supply_count=0;
var moly_count=0;
var clan_count=0;
var dur_count=0;
var tri_count=0;
var mc_count = 0;
var neut_count=0;
var mine_sweep=0;
var fighter_count=0;
var mine_count=0;
var minelay_torp_count=0;
var total_cargo=0;
var total_cargo_used=0;
var total_fuel=0;
var low_fuel_count=0;
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
{
for (var i = 0; i < vgap.myships.length; i++)
if(returnFleetName(vgap.myships[i])==fleetName)
{
var hull = vgap.getHull(vgap.myships[i].hullid);
supply_count+=vgap.myships[i].supplies;
moly_count+=vgap.myships[i].molybdenum;
clan_count+=vgap.myships[i].clans;
dur_count+=vgap.myships[i].duranium;
tri_count+=vgap.myships[i].tritanium;
mc_count +=vgap.myships[i].megacredits;
neut_count+=vgap.myships[i].neutronium;
if (vgap.myships[i].neutronium 0)
fighter_count+=vgap.myships[i].ammo;
if (vgap.myships[i].beams > 0)
mine_sweep+=(vgap.myships[i].beams * vgap.myships[i].beamid * vgap.myships[i].beamid);
if (vgap.myships[i].torps > 0)
{
minelay_torp_count+=vgap.myships[i].minelaytorps;
mine_count+=vgapShipScreen.prototype.getMineUnits(vgap.myships[i]);
}
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);
total_cargo+=hull.cargo;
total_fuel+=hull.fueltank;
}
$("#FleetTitle").text("Fleet: "+ fleetName + " - " +returnFleetSize(fleetName)+ " ships");
}
else //unlabeled group at a location
{
for (var i = 0; i < vgap.myships.length; i++)
if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
{
var hull = vgap.getHull(vgap.myships[i].hullid);
ship_count++;
supply_count+=vgap.myships[i].supplies;
moly_count+=vgap.myships[i].molybdenum;
clan_count+=vgap.myships[i].clans;
dur_count+=vgap.myships[i].duranium;
tri_count+=vgap.myships[i].tritanium;
mc_count +=vgap.myships[i].megacredits;
neut_count+=vgap.myships[i].neutronium;
if (vgap.myships[i].neutronium 0)
fighter_count+=vgap.myships[i].ammo;
if (vgap.myships[i].beams > 0)
mine_sweep+=(vgap.myships[i].beams * vgap.myships[i].beamid * vgap.myships[i].beamid);
if (vgap.myships[i].torps > 0)
{
minelay_torp_count+=vgap.myships[i].ammo;
mine_count+=vgapShipScreen.prototype.getMineUnits(vgap.myships[i]);
}
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);
total_cargo+=hull.cargo;
total_fuel+=hull.fueltank;
}
$("#FleetTitle").text("Fleet: "+ ship_count+ " at location");
}
var html;
html="";
html+="";
html+="";
html+="";
//alert("hi");
html += "
";
if (vgaPlanets.prototype.version<3)
html += "
Neutronium:
" + neut_count + "/" + total_fuel + " kt
Fuel Warnings:
";
else
html += "
Neutronium:
" + neut_count + "/" + total_fuel + " kt
Fuel Warnings:
";
html += "
";
html += "
";
html += "
CARGO:
" + total_cargo_used +"/"+total_cargo + "
Fighters:
" + fighter_count + "
Torps:
" + minelay_torp_count + "
";
html += "
Dur:
" + dur_count + " kt
Tri:
" + tri_count + " kt
Moly:
" + moly_count + " kt
";
html += "
MCs:
" + mc_count + "
Sup:
" + supply_count + " kt
Clans:
" + clan_count + "
";
html += "
";
html += "
";
html += "
Minelay:
" + mine_count + " Mines
Minesweep:
" + mine_sweep*4 + " /"+ mine_sweep*3 + " Web
";
html += "
";
$(html).appendTo("#FleetCommands");
};
shipBack = function(passed)
{
var ship=vgap.getShip(passed.id);
var last=ship;
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
{
for (var i = 0; i < vgap.myships.length; i++)
if(returnFleetName(vgap.myships[i])==fleetName)
if (vgap.myships[i].id==ship.id)
if (ship.id!=last.id)
vgap.map.selectShip(last.id);
else
break;
else
last=vgap.myships[i];
}
else //in an unlabeled group
for (var i = 0; i < vgap.myships.length; i++)
{
var fleet=returnFleetName(vgap.myships[i]);
if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y)&&(fleet==-1))
if (vgap.myships[i].id==ship.id)
if (ship.id!=last.id)
vgap.map.selectShip(last.id);
else
break;
else
last=vgap.myships[i];
}
//vgap.map.selectShip(id);
};
shipNext = function(passed)
{
var ship=vgap.getShip(passed.id);
var last=ship;
var number=vgap.myships.length-1;
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
{
for (var i = number; i>=0 ; i--)
if(returnFleetName(vgap.myships[i])==fleetName)
if (vgap.myships[i].id==ship.id)
if (ship.id!=last.id)
vgap.map.selectShip(last.id);
else
break;
else
last=vgap.myships[i];
}
else //in an unlabeled group
for (var i = number; i>=0 ; i--)
{
var fleet=returnFleetName(vgap.myships[i]);
if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y)&&(fleet==-1))
if (vgap.myships[i].id==ship.id)
if (ship.id!=last.id)
vgap.map.selectShip(last.id);
else
break;
else
last=vgap.myships[i];
}
};
setFleetSpeed = function(passed)
{
//alert ("hey!");
var towed_ships=0;
var count=0;
var ship = vgap.getShip(passed.id);
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
for (var i = 0; i < vgap.myships.length; i++)
{
if (returnFleetName(vgap.myships[i])==fleetName)
if (vgap.isTowTarget(vgap.myships[i].id))
{
towed_ships++;
vgap.myships[i].warp=0;
}
else
{
count++;
vgap.myships[i].warp = ship.warp;
}
}
else //unlabeled group at location
for (var i = 0; i < vgap.myships.length; i++)
{
//alert("its "+ i);
if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
{
//alert("hi!");
if (vgap.isTowTarget(vgap.myships[i].id))
{
towed_ships++;
vgap.myships[i].warp=0;
}
else
{
count++;
vgap.myships[i].warp = ship.warp;
}
}
}
alert("Set " + count + " ships to warp " + ship.warp + ", and set " + towed_ships + " towed ships to warp 0");
if (vgaPlanets.prototype.version<3)
vgap.map.updateZoom();
else
{
vgap.loadWaypoints();
vgap.shipScreen.screen.refresh();
}
vgap.map.draw();
};
readyFleet = function(passed)
{
var count=0;
var notReady=0;
var ship = vgap.getShip(passed.id);
//alert(checkFuel(ship));
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
for (var i = 0; i < vgap.myships.length; i++)
{
if (returnFleetName(vgap.myships[i])==fleetName)
{
if (vgap.myships[i].readystatus!=2)
{
vgap.myships[i].readystatus = ship.readystatus;
count++;
}
else
notReady++;
}
}
else //unlabeled group at location
for (var i = 0; i < vgap.myships.length; i++)
{
//alert("its "+ i);
if((vgap.myships[i].x==ship.x)&&(vgap.myships[i].y==ship.y))
{
//alert("hi!");
if (vgap.myships[i].readystatus!=2)
{
vgap.myships[i].readystatus = ship.readystatus;
count++;
}
else
notReady++;
}
}
if (notReady>0) alert ("Updated Readiness for " + count + " ships. " + notReady + " ships were skipped");
else
alert("Updated Readiness for " + count + " ships");
if (vgaPlanets.prototype.version<3)
vgap.map.updateZoom();
else
{
vgap.loadWaypoints();
vgap.shipScreen.screen.refresh();
}
vgap.map.draw();
};
moveFleet = function(passed)
{
var count=0;
var lowFuel=0;
var ship = vgap.getShip(passed.id);
//alert(checkFuel(ship));
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
for (var i = 0; i < vgap.myships.length; i++)
{
if (returnFleetName(vgap.myships[i])==fleetName)
{
count++;
if (vgap.myships[i].neutronium0) alert ("Updated destination for " + count + " ships. " + lowFuel + " ships have insufficient fuel!");
else
alert("Updated destination for " + count + " ships");
if (vgaPlanets.prototype.version<3)
vgap.map.updateZoom();
else
{
vgap.loadWaypoints();
vgap.shipScreen.screen.refresh();
}
vgap.map.draw();
};
showShips2 = function (passed) {
var data = passed.id.split(",");
var ship = vgap.getShip(data[0]);
var inMore = vgap.shipScreenOpen;
var ships;
var title = "";
var html = "
";
if (data[2]!=0)
ships = vgap.shipsAt(ship.x, ship.y);
else
{
shipArray=new Array();
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
for (var i = 0; i < vgap.myships.length; i++)
{
if (returnFleetName(vgap.myships[i])==fleetName)
if (vgap.myships[i].neutronium 0) {
if (title != "")
title += ", ";
title += ships.length + " ships";
}
html += "
";
if (inMore) {
html = "
Ships with Fuel Warnings: " + title + "
" + html;
html += "OK";
vgap.more.empty();
$(html).appendTo(vgap.more);
$("#SelectLocation").height($(window).height() - 100);
vgap.showMore(300);
}
else {
html = "
Scan:" + title + "
" + html;
vgap.map.centerMap(ship.x, ship.y);
vgap.lc.empty();
$(html).appendTo(vgap.lc);
vgap.openLeft();
$("#SelectLocation").height($(window).height() - 40);
$("#SelectLocation").width(380);
}
$("#SelectLocation").jScrollPane();
};
showShips3 = function (passed) {
var data = passed.id.split(",");
var ship = vgap.getShip(data[0]);
var inMore = vgap.shipScreenOpen;
if (data[2]!=0)
ships = vgap.shipsAt(ship.x, ship.y);
else
{
shipArray=new Array();
var fleetName=returnFleetName(ship);
if (fleetName!=-1) //in a labeled fleet
for (var i = 0; i < vgap.myships.length; i++)
{
if (returnFleetName(vgap.myships[i])==fleetName)
if (vgap.myships[i].neutronium" + html;
vgap.more.empty();
$(html).appendTo(vgap.more);
shtml.moreBack();
}
else {
var lc = new leftContent("ScanScreen", "Scan: ", null, function () { vgap.closeLeft(); });
vgap.map.centerMap(ship.x, ship.y);
$(html).appendTo(vgap.lc);
}
for (var i = 0; i < ships.length; i++) {
var scan = $(shtml.shipScan(ships[i])).appendTo("#SelectLocation");
scan.click(function (e) { vgap.map.selectShip($(this).data("id")); });
}
if (ships.length > 0) {
if (title != "")
title += ", ";
title += ships.length + " Ships with Fuel warnings";
}
if (inMore) {
$("#ScanTitle").text(title);
//$("#SelectLocation").height($(window).height() - 100);
vgap.showMore(330);
}
else {
$("#ScanScreen .TopTitle").text(title);
vgap.openLeft();
//$("#SelectLocation").height($(window).height() - 40);
$("#SelectLocation").width(380);
}
if ($("#SelectLocation").height() > ($(window).height() - 40)) {
$("#SelectLocation").height($(window).height() - 40);
$("#SelectLocation").jScrollPane();
}
};
saveShipID=function(passed)
{
set_cookie("currentShipID",passed.id);
};
//====================FLEET FUNCTIONS=================================
buildFleetList=function()
{
fleetNames.length=0;
fleetFlagships.length=0;
fleetSizes.length=0;
for (var i = 0; i < vgap.myships.length; i++)
{
if (vgap.myships[i].name.charAt(0)=='[')
if (vgap.myships[i].name.indexOf(']')!=-1)
{
var name=vgap.myships[i].name.substring(1,vgap.myships[i].name.indexOf(']'));
var position=fleetNames.indexOf(name);
if (position==-1) //fleet is new
{
fleetNames.push(name);
fleetFlagships.push(vgap.myships[i].id);
fleetSizes.push(1);
// position=(fleetNames.length)-1;//for testing only
}
else
fleetSizes[position]++;
//alert(name+' '+fleetSizes[position]);
}
//alert(vgap.myships[i].name.charAt(1));
}
};
returnFleetName = function(ship)
{
if (ship.name.charAt(0)=='[')
if (ship.name.indexOf(']')!=-1)
return(ship.name.substring(1,ship.name.indexOf(']')));
return(-1)
};
returnFlagshipID = function(fleet_name)
{
var index=fleetNames.indexOf(fleet_name);
return(fleetFlagships[index]);
};
returnFleetSize = function(fleet_name)
{
var index=fleetNames.indexOf(fleet_name);
return (fleetSizes[index]);
};
fleetBack = function(passed)
{
var ship=vgap.getShip(passed.id);
var fleetName=returnFleetName(ship);
var index;
if (fleetName!=-1)
{
index=fleetNames.indexOf(fleetName);
if(index>0) vgap.map.selectShip(fleetFlagships[index-1]);
if(index==0) vgap.map.selectShip(fleetFlagships[fleetFlagships.length-1]);
}
else if (typeof fleetFlagShips[0] != 'undefined')
vgap.map.selectShip(fleetFlagships[0]);
};
fleetNext = function(passed)
{
var ship=vgap.getShip(passed.id);
var fleetName=returnFleetName(ship);
var index;
if (fleetName!=-1)
{
index=fleetNames.indexOf(fleetName);
var number=fleetFlagships.length;
number--;
//alert(fleetFlagships.length + " " + index + " " + number);
if(index turndistance) {
distanceremaining -= turndistance;
var turnfuel = turnFuel2(turndistance, mass, xv, turndistance,ship);
fuel += turnfuel;
ship.neutronium -= turnfuel;
if (ship.neutronium < 0) {
turnfuel = ship.neutronium;
ship.neutronium = 0;
}
mass -= turnfuel;
var pa = vgap.planetAt(x2, y2);
if (distanceremaining < 3 && pa != null) {
distanceremaining = 0;
}
}
if (distanceremaining > 0)
fuel += turnFuel2(distanceremaining, mass, xv, turndistance,ship);
//Return fuel back to correct value
ship.neutronium = currentfuel;
return fuel;
}
getFuelUsage3 = function (ship, x1, y1, x2, y2) {
var engine = vgap.getEngine(ship.engineid);
var distance = Math.dist(x1, y1, x2, y2);
if (ship.warp == 0)
return 0;
if (vgap.isHyping(ship))
return 50;
var xv = vgap.getXV(engine, ship.warp);
//Save fuel value to update during the calculation
var currentfuel = ship.neutronium;
var fuel = 0;
var turndistance = vgap.getSpeed(ship.warp, ship.hullid);
var distanceremaining = distance;
var mass = vgap.getMass(ship, true);
//tow
if (ship.mission == 6 && ship.mission1target != 0) {
var towship = vgap.getShip(ship.mission1target);
if (towship != null)
mass += vgap.getMass(towship, true);
}
var warp = ship.warp;
while (distanceremaining > turndistance) {
distanceremaining -= turndistance;
var turnfuel = vgap.turnFuel(turndistance, mass, xv, turndistance, vgap.cloakFuel(ship));
fuel += turnfuel;
ship.neutronium -= turnfuel;
if (ship.neutronium < 0) {
turnfuel = ship.neutronium;
ship.neutronium = 0;
}
mass -= turnfuel;
var pa = vgap.planetAt(x2, y2);
if (distanceremaining < 3 && pa != null) {
distanceremaining = 0;
}
}
if (distanceremaining > 0)
fuel += vgap.turnFuel(distanceremaining, mass, xv, turndistance, vgap.cloakFuel(ship));
//Return fuel back to correct value
ship.neutronium = currentfuel;
return fuel;
}
//==========================END FUEL FUNCTIONS=======================================
set_cookie=function( name, value, exp_y, exp_m, exp_d, path, domain, secure )
//name=cookie name (required)
//value=cookie value (required)
//exp_y,M,d is expiration year, month, day (if blank cookie will delete when browser closes)
//path=path within site this applies to (can be blank)
//domain=apply only to websites in this domain (can be blank)
//secure=use SSL (leave blank)
{
var cookie_string = name + "=" + escape ( value );
if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}
if ( path )
cookie_string += "; path=" + escape ( path );
if ( domain )
cookie_string += "; domain=" + escape ( domain );
if ( secure )
cookie_string += "; secure";
document.cookie = cookie_string;
};
get_cookie =function( cookie_name )
{
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
if ( results )
return ( unescape ( results[2] ) );
else
return null;
};
/*var oldLoadCargo = vgapShipScreen.prototype.loadCargo;
vgapShipScreen.prototype.loadCargo = function () {
oldLoadCargo.apply(this, arguments);
this.loadFleet();
};
*/
}
var script = document.createElement("script");
script.type = "application/javascript";
script.textContent = "(" + wrapper + ")();";
document.body.appendChild(script);