var autoUpdate, autoLock, onMainPage = false; var allies, fleets, locations, players, myself; var fAutoId = 0; var listLocations, listMode, fDispMode, alliesMode; var sType, sText; var ppList, apList, opList, mfList, wfList; var fSel, fDisp, splitParam; var orderFleets, moveTo, moveToLoc, orderMode, waitTime, selCanHS, guessOrders, gDest, gWait, sMovex, sMovey; var dMapX, dMapY, newDest, map, loadingMap = false, readingMoveLocation = false; var mapCType, mapParm; var trajectories, lTraj, trajLock; var fleetTrajectory, sales; var mapRemember = false; var mFleetSelectable, mFleetSelected; var wFleetSelectable, wFleetSelected; function Ally(id, isMe, fSpace, gSpace, cHaul, bHaul, gaPop, canSell) { this.id = id; this.isMe = isMe; this.gSpace = gSpace; this.fSpace = fSpace; this.cHaul = cHaul; this.bHaul = bHaul; this.gaPop = gaPop; this.canSell = canSell; this.getName = Ally_getName; this.planets = new Array(); this.fleets = new Array(); this.gasAt = new Hashtable(); if (isMe) myself = this; } function Ally_getName() { return players.get(this.id); } function Fleet(id, owner, gaships, fighters, cruisers, bcruisers, power, mode, upkeep, name) { this.id = (id == "" ? ("a" + (++fAutoId)) : id); this.owner = owner; this.ships = [gaships,fighters,cruisers,bcruisers]; this.power = power; this.upkeep = upkeep; this.mode = mode; this.name = name; this.selected = false; this.orders = null; } function FLocation(id, canMove) { this.oType = 0; this.locId = id; this.loc = null; this.canMove = canMove; } function FMove(to, from, now, eta, hs, reroute) { this.oType = 1; this.fromId = from; this.from = null; this.toId = to; this.to = null; this.curId = now; this.cur = null; this.eta = eta; this.wait = null; this.hyperspace = (hs == '1'); this.reroute = parseInt(reroute,10); } function FWait(loc, from, left, spent, minLoss, maxLoss) { this.oType = 2; this.fromId = from; this.from = null; this.locId = loc; this.loc = null; this.spent = spent; this.left = left; this.minLoss = minLoss; this.maxLoss = maxLoss; } function FOnSale(loc, sale, ib) { this.oType = 3; this.locId = loc; this.loc = null; this.saleId = sale; this.inBundle = (ib == 1); } function FSold(loc, sale, soldTo, timeLeft, ib) { this.oType = 4; this.locId = loc; this.loc = null; this.soldTo = soldTo; this.timeLeft = timeLeft; this.saleId = sale; this.inBundle = (ib == 1); } function FleetLocation(id, opacity, x, y, orbit, name) { this.id = id; this.opacity = opacity; this.x = x; this.y = y; this.orbit = orbit; this.name = name; this.fleets = new Array(); this.details = null; this.updateSelection = function () { var e = document.getElementById('fsel-p-' + this.id); if (!e) { return; } if (this.selectableFleets == 0) { e.innerHTML = ' '; return; } e.innerHTML = ''; }; this.selectAll = function () { if (autoLock) { setTimeout('locations.get(' + this.id + ').selectAll()', 500); return; } autoLock = true; if (this.selectableFleets == 0) { autoLock = false; return; } for (var i in this.fleets) { var e = document.getElementById('fsel' + this.fleets[i].id); if (!e) { continue; } e.checked = this.fleets[i].selected = !(this.selectableFleets == this.selectedFleets); } if (this.selectableFleets == this.selectedFleets) { this.selectedFleets = 0; } else { this.selectedFleets = this.selectableFleets; } updateActions(); autoLock = false; }; } function PlanetDetails(owner, turrets, tPower, pop, vacation, protection, tag) { this.owner = owner; this.turrets = turrets; this.tPower = tPower; this.pop = pop; this.vacation = (vacation == 1); this.protection = (protection == 1); this.tag = tag; } function FilteredLocation(id) { this.id = id; this.fleetLocation = locations.get(id); this.fleets = new Array(); } function MapSystem(x, y, opacity, prot) { this.x = x; this.y = y; this.opacity = opacity; this.protection = prot; this.locations = new Array(); } function MapLocation(id, x, y, orbit, opacity, ally, name) { this.id = id; this.x = x; this.y = y; this.orbit = orbit; this.color = parseInt(opacity, 10); if (this.color != 0) this.color += 2; else this.color = parseInt(ally); this.name = name; } function WayPoint(x, y, orbit, eta, name) { this.name = name; this.coords = "(" + x + "," + y + "," + orbit + ")"; this.eta = eta; } function FleetTrajectory(fid, from, to, changed, left, hs, wait) { this.fleetId = fid; this.fleet = fleets.get(fid); this.from = from; this.to = to; this.changed = parseInt(changed,10); this.left = parseInt(left,10); this.hyperspace = (hs == '1'); this.wait = parseInt(wait,10); this.waypoints = new Array(); } function FleetWayPoint(id, eta, sys, orb, op, name) { this.id = id; this.eta = parseInt(eta,10); this.system = sys; this.orbit = orb; this.opacity = op; this.name = name; } function FleetSale(loc) { this.id = loc; this.fleetLocation = locations.get(loc); this.mode = 0; this.player = ''; this.price = 0; this.priceText = ''; this.expires = 0; this.isValid = false; this.error = -1; this.fleets = new Array(); this.drawForm = FleetSale_drawForm; this.update = FleetSale_update; this.validate = FleetSale_validate; this.setMode = FleetSale_setMode; this.setExpire = FleetSale_setExpire; } function FleetSale_setMode(m) { this.mode = m; this.update(); this.validate(); } function FleetSale_setExpire(x) { this.expires = x; this.validate(); } function FleetSale_update() { var id = 's' + this.id, c0 = 'sales.get('+this.id+').validate();return true', code = ' onChange="'+c0+'" onKeyUp="'+c0+'" onClick="'+c0+'" ';; switch (this.mode) { case 0: if (document.getElementById(id+'price')) document.getElementById(id+'pril').innerHTML = document.getElementById(id+'pri').innerHTML = ' '; if (!document.getElementById(id+'target')) { document.getElementById(id+'tar').innerHTML = ''; document.getElementById(id+'tarl').innerHTML = ''; } document.getElementById(id+'target').value = this.player; break; case 1: if (!document.getElementById(id+'price')) document.getElementById(id+'pri').innerHTML = ''; if (!document.getElementById(id+'target')) { document.getElementById(id+'tar').innerHTML = ''; document.getElementById(id+'tarl').innerHTML = ''; } document.getElementById(id+'pril').innerHTML = ''; document.getElementById(id+'target').value = this.player; document.getElementById(id+'price').value = this.priceText; break; case 2: case 3: if (!document.getElementById(id+'price')) document.getElementById(id+'pri').innerHTML = ''; if (document.getElementById(id+'target')) document.getElementById(id+'tar').innerHTML = document.getElementById(id+'tarl').innerHTML = ' '; document.getElementById(id+'pril').innerHTML = ''; document.getElementById(id+'price').value = this.priceText; break; } } function FleetSale_validate() { this.isValid = false; this.error = -1; if (document.getElementById('s'+this.id+'target')) this.player = document.getElementById('s'+this.id+'target').value; if (document.getElementById('s'+this.id+'price')) { this.priceText = document.getElementById('s'+this.id+'price').value; this.price = parseInt(this.priceText, 10); } if (this.mode < 2 && this.player == '') { this.error = 1; drawSellLinks(false); return; } if (this.mode != 0 && (isNaN(this.price) || this.price <= 0)) { this.error = 2; drawSellLinks(false); return; } if (this.mode == 3 && this.expires == 0) { this.error = 3; drawSellLinks(false); return; } this.isValid = true; checkAllSales(); } function getTrajectory(fleet, to) { var fLoc = (fleet.orders.oType != 1 ? fleet.orders.loc : fleet.orders.cur); var key = fLoc.id + ';' + ((fleet.ships[2] != 0 || (fleet.ships[2] == 0 && fleet.ships[3] == 0)) ? 1 : 0) + ';' + fleet.owner + ';' + to.id; if (trajectories.containsKey(key)) return trajectories.get(key); if (('#' + lTraj.join('#') + '#').indexOf('#' + key + '#') == -1) { lTraj.push(key); x_getTrajectory(key, gotTrajectory); } return null; } function gotTrajectory(data) { if (data == "") return; while (trajLock); trajLock = true; var l = data.split('\n'); var t = new Array(), key = l.shift(), a, w, eta = 0; while (l.length) { a = l.shift().split('#'); w = new WayPoint(a.shift(), a.shift(), a.shift(), (eta += parseInt(a.shift(), 10)), a.join('#')); t.push(w); } trajectories.put(key, t); t = new Array(); for (a=0;a 2 && fDispMode - 2 == f.orders.oType ) && ( alliesMode == 0 || alliesMode == 1 && f.owner == myself.id || alliesMode == 2 && f.owner != myself.id && allies.get(f.owner) || alliesMode == 3 && !allies.get(f.owner) ) && ( sType == 1 || sType == 0 && (sText == '' || f.name.toLowerCase().indexOf(sText.toLowerCase()) != -1) || sType == 2 && (sText == '' || players.get(f.owner).toLowerCase().indexOf(sText.toLowerCase()) != -1) ) ) flt.push(keys[i]); } if (fDispMode < 3) { if (listLocations < 2) for (i=0;i'; } function selectAllWaitingFleets () { if (autoLock) { setTimeout('selectAllWaitingFleets()', 500); return; } autoLock = true; if (wFleetSelectable == 0) { autoLock = false; return; } for (var i in wfList) { var e = document.getElementById('fsel' + wfList[i].id); if (!e) { continue; } e.checked = wfList[i].selected = !(wFleetSelectable == wFleetSelected); } if (wFleetSelectable == wFleetSelected) { wFleetSelected = 0; } else { wFleetSelected = wFleetSelectable; } updateActions(); autoLock = false; } function updateMovingSelection () { var e = document.getElementById('f-move-sel'); if (!e) { return; } if (mFleetSelectable == 0) { e.innerHTML = ' '; return; } e.innerHTML = ''; } function selectAllMovingFleets () { if (autoLock) { setTimeout('selectAllMovingFleets()', 500); return; } autoLock = true; if (mFleetSelectable == 0) { autoLock = false; return; } for (var i in mfList) { var e = document.getElementById('fsel' + mfList[i].id); if (!e) { continue; } e.checked = mfList[i].selected = !(mFleetSelectable == mFleetSelected); } if (mFleetSelectable == mFleetSelected) { mFleetSelected = 0; } else { mFleetSelected = mFleetSelectable; } updateActions(); autoLock = false; } function updateActions() { var cRen = false, cTraj = true, cMove = true, cSwitch = true, cMerge = true, cDisband = true, cSell = myself.canSell, cCancelSale = myself.canSell; var i, n, ns; for (i=n=ns=0;i' + ' - ' + actionText[1] + ''; if (cTraj && n == 1) i += ' - ' + actionText[8] + ''; if (cMove) i += ' - ' + actionText[2] + ''; if (cSwitch) i += ' - ' + actionText[3] + ''; if (cMerge && n > 1) i += ' - ' + actionText[5] + ''; if (cMerge && n == 1 && ns > 1) i += ' - ' + actionText[4] + ''; if (cSell) i += ' - ' + actionText[6] + ''; if (cCancelSale) { if (n == 1) i += ' - ' + actionText[11] + ''; i += ' - ' + actionText[10] + ''; } if (cDisband) i += ' - ' + actionText[7] + ''; document.getElementById('factions').innerHTML = i; } function drawFleetLine(fleet,type,hasSel) { var o = allies.get(fleet.owner); var i, str = ''; var sc = ''; if (hasSel) { str += ''; if (o && (fleet.orders.oType != 3 && fleet.orders.oType != 4 || !fleet.orders.inBundle)) { str += ''; fDisp.push(fleet); sc = ' onclick="with (document.getElementById(\'fsel'+fleet.id+'\')) { checked = !checked; };' + 'selectFleet('+fleet.id+');return true" '; var loc = fleet.orders.loc; loc.selectableFleets ++; loc.selectedFleets += (fleet.selected ? 1 : 0); } else { str += ' '; } str += ''; } str += ''; } else { str += sc + '>'; } str += players.get(fleet.owner); str += ''; if (o) { var used = fleet.ships[0] * o.gSpace + fleet.ships[1] * o.fSpace; var haul = fleet.ships[2] * o.cHaul + fleet.ships[3] * o.bHaul; if (haul == 0) str += 'N/A'; else { var hp = Math.round(used * 100 / haul); str += (hp > 200) ? '>200%' : (hp + '%'); } } else str += ' '; str += ''; for (i=0;i<4;i++) str += ''+formatNumber(fleet.ships[i])+''; str += ''+formatNumber(fleet.power)+''; if (fleet.orders.oType == 0) str += (fleet.mode == 1 ? statusText[0] : statusText[1]) + ', ' + (fleet.orders.canMove == 'Y' ? statusText[2] : statusText[3]); else if (fleet.orders.oType == 3) str += statusText[4] + (fleet.orders.inBundle ? statusText[6] : ''); else if (fleet.orders.oType == 4) str += statusText[5]; str += ''; return str; } function drawMovingFleetLine(fleet, hasSel) { var o = allies.get(fleet.owner); var i, str = ''; var sc = ''; str += ''; if (hasSel) { str += ''; mFleetSelectable ++; mFleetSelected += (fleet.selected ? 1 : 0); fDisp.push(fleet); sc = ' onclick="with (document.getElementById(\'fsel'+fleet.id+'\')) { checked = !checked; };' + 'selectFleet('+fleet.id+');return true" '; } str += ''; for (i=0;i<4;i++) str += ''; str += ''; str += ''; str += ''; str += '
'; } else { str += sc + '>'; } str += players.get(fleet.owner); if (myself.id != fleet.owner) str += ''; str += ''; var used = fleet.ships[0] * o.gSpace + fleet.ships[1] * o.fSpace; var haul = fleet.ships[2] * o.cHaul + fleet.ships[3] * o.bHaul; if (haul == 0) str += 'N/A'; else { var hp = Math.round(used * 100 / haul); str += (hp > 200) ? '>200%' : (hp + '%'); } str += ''+formatNumber(fleet.ships[i])+''+formatNumber(fleet.power)+'' + (fleet.mode == 1 ? statusText[0] : statusText[1]) + '
' + fleet.orders.cur.name + ''; if (fleet.orders.cur.details && fleet.orders.cur.details.tag != '') { str += ' [' + fleet.orders.cur.details.tag + ']'; } str += '' + fleet.orders.to.name + ''; if (fleet.orders.to.details && fleet.orders.to.details.tag != '') { str += ' [' + fleet.orders.to.details.tag + ']'; } str += '' + fleet.orders.eta + ' min'; if (fleet.orders.wait) { str += fleet.orders.wait.left + 'h ('; if (fleet.orders.wait.maxLoss == 0) str += '0%'; else str += fleet.orders.wait.minLoss + '% - ' + fleet.orders.wait.maxLoss + '%'; str += ')'; } else str += 'N/A'; str += '
'; return str; } function drawWaitingFleetLine(fleet,hasSel) { var o = allies.get(fleet.owner); var i, str = ''; var sc = ''; str += ''; if (hasSel) { str += ''; wFleetSelectable ++; wFleetSelected += (fleet.selected ? 1 : 0); fDisp.push(fleet); sc = ' onclick="with (document.getElementById(\'fsel'+fleet.id+'\')) { checked = !checked; };' + 'selectFleet('+fleet.id+');return true" '; } str += ''; for (i=0;i<4;i++) str += ''+formatNumber(fleet.ships[i])+''; str += ''+formatNumber(fleet.power)+''; str += '' + (fleet.mode == 1 ? statusText[0] : statusText[1]) + ''; str += '' + '' + fleet.orders.spent + 'h' + fleet.orders.left + 'h'; if (fleet.orders.maxLoss == 0) str += '0%'; else str += fleet.orders.minLoss + '% - ' + fleet.orders.maxLoss + '%'; str += '
'; } else { str += sc + '>'; } str += players.get(fleet.owner); if (myself.id != fleet.owner) str += ''; str += ''; var used = fleet.ships[0] * o.gSpace + fleet.ships[1] * o.fSpace; var haul = fleet.ships[2] * o.cHaul + fleet.ships[3] * o.bHaul; if (haul == 0) str += 'N/A'; else { var hp = Math.round(used * 100 / haul); str += (hp > 200) ? '>200%' : (hp + '%'); } str += '
' + fleet.orders.loc.name + ''; if (fleet.orders.loc.details && fleet.orders.loc.details.tag != '') { str += ' [' + fleet.orders.loc.details.tag + ']'; } str += '
'; return str; } function drawMainContents() { fDisp = new Array(); if (ppList.size() == 0 && apList.size() == 0 && opList.size() == 0 && mfList.length == 0 && wfList.length == 0) { document.getElementById('fmain').innerHTML = '
'+noFleetsFound+'
'; return; } var i,sz,keys,j,p,f,str = ''; if ((sz = ppList.size()) != 0) { str += '

'+sectionTitles[0]+'

'; keys = ppList.keys(); keys.sort(sortPPList); for (i=0;i'; keys = apList.keys(); keys.sort(sortAPList); for (i=0;i'; keys = opList.keys(); keys.sort(sortOPList); for (i=0;i'; str += ''; mfList.sort(sortMovingFleets); for (j=0;j'; str += '
' + drawMovingHeader(true) + '
'; wfList.sort(sortWaitingFleets); for (j=0;j 64) { alertFleetName(1); str = ""; } else if (str.length < 3) { alertFleetName(2); str = ""; } } x_renameFleets(id, str, renameCallback); } function renameSelected() { if (autoLock) { setTimeout('renameSelected()', 500); return; } lockUpdate(); var str = ""; while (str == "") { str = getNewFleetName(false); if (typeof str == 'object' && !str) { unlockUpdate(); return; } if (str == "") alertFleetName(0); else if (str.length > 64) { alertFleetName(1); str = ""; } else if (str.length < 3) { alertFleetName(2); str = ""; } } var s = new Array(); for (i=0;i 64) { alertFleetMerge(0); str = " "; } else if (str.length < 3 && str != '') { alertFleetMerge(1); str = " "; } } var i, s = new Array(); for (i=0;i1)) x_disbandFleets(s.join('#'), disbandCallback); else unlockUpdate(); } function disbandCallback(str) { if (str.indexOf('ERR#') == 0) { var l = str.split('#'); alertFleetDisband(parseInt(l[1], 10)); unlockUpdate(); } else { prepareUpdate(); parseMainData(str); } } function splitSelected() { if (autoLock) { setTimeout('splitSelected()', 500); return; } lockUpdate(); splitParam = new Array(); for (var i=0;i 0 || splitParam[0].ships[3] > 0) { splitParam[7] = ships[0] * o.gSpace + ships[1] * o.fSpace; splitParam[8] = ships[2] * o.cHaul + ships[3] * o.bHaul; document.getElementById('hused').innerHTML = splitParam[7]; document.getElementById('havail').innerHTML = splitParam[8]; } var s=0; for (i=0;i<4;i++) s += ships[i]; var canSplit = (s > 0); if (splitParam[0].orders.oType == 2 || splitParam[0].orders.oType == 1 && splitParam[0].orders.hyperspace) canSplit = canSplit && (splitParam[7] <= splitParam[8]); document.getElementById('bsplit').disabled = !canSplit; } function setSplitCount(amount) { splitParam[2] = amount; if (splitParam[1] == 0) { updateSplitHaul(); updateSplitOk(); } else updateAutoSplit(); } function setSplitShips(type,amount) { var flds = ['sgas','sfgt','scru','sbcr']; if (amount < 0 || isNaN(amount)) return; splitParam[type+3] = amount; updateSplitHaul(); updateSplitOk(); } function updateSplitHaul() { if (splitParam[0].ships[2] == 0 && splitParam[0].ships[3] == 0) { splitParam[7] = splitParam[8] = 0; return; } var o = allies.get(splitParam[0].owner); splitParam[7] = splitParam[3] * o.gSpace + splitParam[4] * o.fSpace; splitParam[8] = splitParam[5] * o.cHaul + splitParam[6] * o.bHaul; document.getElementById('hused').innerHTML = splitParam[7]; document.getElementById('havail').innerHTML = splitParam[8]; } function updateSplitOk() { var ships = [0,0,0,0]; var diffs = [0,0,0,0]; var i,s1=0,s2=0,neg=false; for (i=0;i<4;i++) { ships[i] = splitParam[i+3] * splitParam[2]; s1 += ships[i]; diffs[i] = splitParam[0].ships[i] - ships[i]; neg = neg || (diffs[i] < 0); s2 += diffs[i]; } var canSplit = (s1 > 0 && !neg && s2 > 0); if (splitParam[0].orders.oType == 2 || splitParam[0].orders.oType == 1 && splitParam[0].orders.hyperspace) { var ou, os, o = allies.get(splitParam[0].owner); ou = diffs[0] * o.gSpace + diffs[1] * o.fSpace; os = diffs[2] * o.cHaul + diffs[3] * o.bHaul; canSplit = canSplit && (splitParam[7] <= splitParam[8]) && (ou <= os); } document.getElementById('bsplit').disabled = !canSplit; } function cancelSplit() { prepareUpdate(); x_getFleetsList(parseMainData); } function doFleetSplit() { document.getElementById('bsplit').disabled = true; if (splitParam[1] == 0) x_manualSplit(splitParam[0].id, splitParam[9], splitParam[2], splitParam[3], splitParam[4], splitParam[5], splitParam[6], splitCallback); else x_autoSplit(splitParam[0].id, splitParam[9], splitParam[2], splitCallback); } function splitCallback(str) { if (str.indexOf('ERR#') == 0) { var l = str.split('#'); alertFleetSplit(parseInt(l[1], 10)); document.getElementById('bsplit').disabled = false; } else { clearSelection(); prepareUpdate(); parseMainData(str); } } function moveSelected() { if (autoLock) { setTimeout('moveSelected()', 500); return; } lockUpdate(); orderFleets = new Array(); for (var i=0;i' + actionText[0] + '

'; } var i,str = '
' + drawWaitingHeader(true) + '
' + foSelHeader + ''; selCanHS = true; gWait = gDest = -2; var n = new Array(); sMovex = null; sMovey = null; orderFleets.sort(sortOrderFleets); for (i=0;i 0 && !f.orders.wait || f.orders.wait && gWait != f.orders.wait.left) gWait = gDest = -1; } else if (f.orders.oType == 2) { if (gWait == -2 && gDest == -2) { gDest = -1; gWait = f.orders.left; } else if (gDest > 0 || f.orders.left != gWait) gWait = gDest = -1; } else gWait = gDest = -1; orderMode = parseInt(f.mode, 10); } var oc = ' onClick="removeOrdersSelection('+f.id+')"'; str += '' + f.name + ''; if (haul == 0) str += 'N/A'; else { var hp = Math.round(used * 100 / haul); str += (hp > 200) ? '>200%' : (hp + '%'); } str += '' + formatNumber(f.ships[0]) + ' / ' + formatNumber(f.ships[1]) + ' / '; str += formatNumber(f.ships[2]) + ' / ' + formatNumber(f.ships[3]) + ''; str += formatNumber(f.power) + ''; } orderFleets = n; str += '
' + players.get(f.owner) + ' 
'; guessOrders = false; if (gWait > 0) waitTime = gWait; if (gDest > 0) { moveTo = gDest; moveToLoc = locations.get(moveTo); } return str; } function getOAvailFleets() { // Fleets are available if: // they are not selected // AND ( they are idling AND can move // OR they are moving // OR they are waiting in HS ) // AND ( there is a destination // AND ( the fleet is HS capable // OR the fleet is not HS capable AND the target is in the same system ) // OR there is no destination ) // AND ( there are HS stand-by orders AND the fleet is HS capable // OR there are no HS stand-by orders ) var i, sst = '#' + orderFleets.join('#') + '#'; var afl = new Array(), fk = fleets.keys(); for (i=0;i= 3 ) continue; afl.push(f); } if (!afl.length) return '

' + noFleetsFound + '

'; var i,str = '' + foAvaHeader + ''; afl.sort(sortAvailFleets); for (i=0;i'; } str += '
'; str += players.get(f.owner) + '' + f.name + ''; if (haul == 0) str += 'N/A'; else { var hp = Math.round(used * 100 / haul); str += (hp > 200) ? '>200%' : (hp + '%'); } str += '' + formatNumber(f.ships[0]) + ' / ' + formatNumber(f.ships[1]) + ' / '; str += formatNumber(f.ships[2]) + ' / ' + formatNumber(f.ships[3]) + ''; str += formatNumber(f.power) + ''; var m = parseInt(f.mode, 10); if (f.orders.oType == 0) str += curOrdersTxt[m] + f.orders.loc.name + curOrdersTxt[2 + m]; else if (f.orders.oType == 1) str += curOrdersTxt[m+4] + f.orders.to.name + curOrdersTxt[m+6]; else str += curOrdersTxt[m+8] + f.orders.loc.name + curOrdersTxt[m+10]; str += '
'; return str; } function removeOrdersSelection(id) { var n = new Array(), i; for (i=0;i 48) { fleetDelayError(2); str = ""; } } waitTime = nt; updateOrdersPage(); } function cancelOrdersDelay() { waitTime = -1; updateOrdersPage(); } function removeOrdersDestination() { moveTo = -1; updateOrdersPage(); } function gotLocation(data) { var l = data.split("\n"); var a, o; a = l.shift().split('#'); moveToLoc = new FleetLocation(a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.join('#')); if (moveToLoc.opacity == 0) { a = l.shift().split('#'); moveToLoc.details = new PlanetDetails(a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.join('#')); } readingMoveLocation = false; updateOrdersPage(); } function setOrdersDestination() { if (mapRemember && typeof sMovex == 'object') { } else if (moveTo == -1) { var ok = false; if (typeof sMovex != 'object') { dMapX = parseInt(sMovex,10); dMapY = parseInt(sMovey,10); ok = true; } else { if (orderFleets.length) { var f = fleets.get(orderFleets[0]); if (f) { var fLoc = (f.orders.oType != 1 ? f.orders.loc : f.orders.cur); dMapX = parseInt(fLoc.x, 10); dMapY = parseInt(fLoc.y, 10); ok = true; } } } if (! ok) { if (myself.planets.length) { dMapX = parseInt(myself.planets[0].x,10); dMapY = parseInt(myself.planets[0].y,10); } else { var i = 0, j, k = allies.keys(); while (i < k.length) { var a = allies.get(k[i]); if (!a.isMe && a.planets.length) { dMapX = parseInt(a.planets[0].x,10); dMapY = parseInt(a.planets[0].y,10); break; } i++; } if (i == k.length) dMapX = dMapY = 0; } } } else { dMapX = parseInt(moveToLoc.x,10); dMapY = parseInt(moveToLoc.y,10); } newDest = moveTo; mapCType = 0; drawDestinationSelection(); if (!map.containsKey(dMapX + ';' + dMapY)) { loadingMap = true; x_getMapData(dMapX, dMapY, gotMapData); } else { loadingMap = false; updateDestinationSelection(); } } function gotMapData(data) { if (data == "ERR") alertMap(); else { var l = data.split('\n'); var a = l.shift().split("#"), i; dMapX = parseInt(a[0], 10); dMapY = parseInt(a[1], 10); var system = new MapSystem(dMapX, dMapY, a[2], a[3] == '1'); for (i=0;i<6;i++) { if (system.opacity != -1) { a = l.shift().split('#'); var loc = new MapLocation(a.shift(), dMapX, dMapY, i+1, a.shift(), a.shift(), a.join('#')); system.locations.push(loc); map.put("p" + loc.id, loc); map.put("pn-" + loc.name.toLowerCase(), loc); } else system.locations.push(null); } map.put(dMapX + ";" + dMapY, system); } updateDestinationSelection(); loadingMap = false; } function updateDestinationSelection() { updateDestLine(); if (typeof sMovex == 'object') { drawGalacticMap(); } else { drawSystemMap(); } } function updateDestLine() { if (newDest == -1) document.getElementById('cursel').innerHTML = noSelection; else { var d = map.get("p" + newDest); document.getElementById('cursel').innerHTML = d.name + " (" + d.x + "," + d.y + "," + d.orbit + ")"; } } function drawSystemMap() { var sys = map.get(dMapX + ";" + dMapY); var str = "'; } else { str += ""; } } str += '
"; var i; for (i = 0; i < 6; i ++) { var loc = sys.locations[i]; if (sys.opacity == 0) { var img = (loc.color == 4) ? "prem_s" : ("pl/s/"+loc.id); str += "
[P]" + loc.name + '
" + loc.name + "

' + smapCoordTxt + '' + dMapX + ' , ' + dMapY + '

'; if (sys.protection) { str = '' + str + ''; } document.getElementById('sdmap').innerHTML = str; } function drawGalacticMap() { var sys = map.get(dMapX + ";" + dMapY); var op = sys.opacity == -1 ? 0 : sys.opacity; var str = "" + "" + "" +"
 " + ""+dirTxt[0]+" 
" + ""+dirTxt[1]+"" + (sys.protection ? '' : '') + ""; var i; for (i=0;i<6;i++) { var loc = sys.locations[i]; if (loc && sys.opacity == 0) { var img = (loc.color == 4) ? "prem_s" : ("pl/s/"+loc.id); str += "'; } else if (loc) str += ""; else str += ''; } str += "
[P]" + loc.name + '
"+loc.name+"
'+unchartedTxt+'
" + (sys.protection ? '
' : '') + "
"+dirTxt[2]+"
 "+dirTxt[3]+" 
"; str += drawMapControls(); document.getElementById('sdmap').innerHTML = str; } function updateGalacticMap() { if (loadingMap) return; var e; if (document.getElementById('mct0').checked) { var x = parseInt(document.getElementById('cx').value, 10); var y = parseInt(document.getElementById('cy').value, 10); mapCType = 0; if (isNaN(x) || isNaN(y)) return moveMapTo(x,y); } else if (document.getElementById('mct1').checked) { e = document.getElementById('mcpo'); var p = e.options[e.selectedIndex].value; mapCType = 1; if (p == 0) return; mapParm = p; if (map.containsKey('p'+p)) { var po = map.get('p'+p); moveMapTo(parseInt(po.x,10), parseInt(po.y,10)); } else { loadingMap = true; x_moveMapToId(p, gotMapData); } } else { e = document.getElementById('mcpn').value; mapCType = 2; if (e == "") return; mapParm = e; if (map.containsKey('pn-'+e.toLowerCase())) { var po = map.get('pn-'+e.toLowerCase()); moveMapTo(parseInt(po.x,10), parseInt(po.y,10)); } else { loadingMap = true; x_moveMapToName(e, gotMapData); } } } function moveMap(dx,dy) { if (loadingMap) return; mapCType = 0; moveMapTo(dMapX + dx, dMapY + dy); } function moveMapTo(nx, ny) { if (map.containsKey(nx + ';' + ny)) { dMapX = nx; dMapY = ny; drawGalacticMap(); } else { loadingMap = true; x_getMapData(nx, ny, gotMapData); } } function setDestination(id) { if (id == newDest) return; newDest = id; document.getElementById('sdok').disabled = (newDest == moveTo); updateDestLine(); } function confirmSetDestination() { moveTo = newDest; if (locations.containsKey(moveTo)) moveToLoc = locations.get(moveTo); else moveToLoc = null; cancelSetDestination(); } function cancelSetDestination() { drawOrdersPage(); updateOrdersPage(); } function viewTrajectory() { if (autoLock) { setTimeout('viewTrajectory()', 500); return; } lockUpdate(); var i, f = null; for (i=0;i1)) x_cancelSales(s.join('#'), salesCanceled); else unlockUpdate(); } function salesCanceled(str) { if (str.indexOf('ERR#') == 0) { var l = str.split('#'); alertCancelSales(parseInt(l[1], 10)); unlockUpdate(); } else { prepareUpdate(); parseMainData(str); } } function viewSaleSelected() { if (autoLock) { setTimeout('viewSaleSelected()', 500); return; } lockUpdate(); var id = null; for (i=0;i pb.toLowerCase() ? 1 : -1)))); } function sortPPList(ia,ib) { var a=ppList.get(ia).fleetLocation,b=ppList.get(ib).fleetLocation; return (a.x!=b.x ?(parseInt(a.x,10)-parseInt(b.x,10)) :(a.y!=b.y ?(parseInt(a.y,10)-parseInt(b.y,10)) :(parseInt(a.orbit,10)-parseInt(b.orbit,10)) ) ); } function sortAPList(ia,ib) { var a=apList.get(ia).fleetLocation,b=apList.get(ib).fleetLocation; return (a.details.owner==b.details.owner ?(a.x!=b.x ?(parseInt(a.x,10)-parseInt(b.x,10)) :(a.y!=b.y ?(parseInt(a.y,10)-parseInt(b.y,10)) :(parseInt(a.orbit,10)-parseInt(b.orbit,10)) ) ):(players.get(a.details.owner).toLowerCase()>players.get(b.details.owner).toLowerCase()?1:-1)); } function sortOPList(ia,ib) { var a=opList.get(ia).fleetLocation,b=opList.get(ib).fleetLocation; return (a.x!=b.x ?(parseInt(a.x,10)-parseInt(b.x,10)) :(a.y!=b.y ?(parseInt(a.y,10)-parseInt(b.y,10)) :(parseInt(a.orbit,10)-parseInt(b.orbit,10)) ) ); } function sortPlanetFleets(ia,ib) { var a=fleets.get(ia),b=fleets.get(ib); return (a.owner == b.owner ? (parseInt(b.power,10)-parseInt(a.power,10)) : (a.owner == myself.id ? -1 : (b.owner == myself.id ? 1 : (a.mode == 0 && b.mode == 1 ? -1 : (a.mode == 1 && b.mode == 0 ? 1 : (players.get(a.owner).toLowerCase()>players.get(b.owner).toLowerCase() ? 1 : -1) )) )) ); } function sortMovingFleets(a,b) { return (a.owner == b.owner ? (a.orders.eta == b.orders.eta ? (parseInt(b.power,10)-parseInt(a.power,10)) : (parseInt(a.orders.eta,10)-parseInt(b.orders.eta,10)) ) : (a.owner == myself.id ? -1 : (b.owner == myself.id ? 1 : (players.get(a.owner).toLowerCase()>players.get(b.owner).toLowerCase() ? 1 : -1) )) ); } function sortWaitingFleets(a,b) { return (a.owner == b.owner ? (a.orders.left == b.orders.left ? (parseInt(b.power,10)-parseInt(a.power,10)) : (parseInt(a.orders.left,10)-parseInt(b.orders.left,10)) ) : (a.owner == myself.id ? -1 : (b.owner == myself.id ? 1 : (players.get(a.owner).toLowerCase()>players.get(b.owner).toLowerCase() ? 1 : -1) )) ); } function sortOrderFleets(ia,ib) { var a=fleets.get(ia),b=fleets.get(ib); return (a.owner == b.owner ? (parseInt(b.power,10)-parseInt(a.power,10)) : (a.owner == myself.id ? -1 : (b.owner == myself.id ? 1 : (players.get(a.owner).toLowerCase()>players.get(b.owner).toLowerCase() ? 1 : -1) )) ); } function sortAvailFleets(a,b) { return (a.owner == b.owner ? (a.orders.oType == b.orders.oType && a.mode == b.mode ? (parseInt(b.power,10)-parseInt(a.power,10)) : (a.orders.oType * 2 + parseInt(a.mode,10) - b.orders.oType * 2 - parseInt(b.mode,10)) ) : (a.owner == myself.id ? -1 : (b.owner == myself.id ? 1 : (players.get(a.owner).toLowerCase()>players.get(b.owner).toLowerCase() ? 1 : -1) )) ); } function sortSalesKeys(ia,ib) { var a=locations.get(ia),b=locations.get(ib); return (a.x!=b.x ?(parseInt(a.x,10)-parseInt(b.x,10)) :(a.y!=b.y ?(parseInt(a.y,10)-parseInt(b.y,10)) :(parseInt(a.orbit,10)-parseInt(b.orbit,10)) )); }