var pdUpdate; var orbit; var planet; var plId; var pdIsOwn; var miSel; var miDir = -1; var mlSel = -1; //--------------------------------------------------------------------------- // PLANET LIST //--------------------------------------------------------------------------- var plUpdate; function drawPlanetList(data) { var cs = document.getElementById('oid').value; var str, i, a, n, f; a = data.split('\n'); n = parseInt(a.shift(),10); if (n > 0) { str = ''; f = false; for (i=0;i'; } str = ''; } else str = '---'; document.getElementById('psel').innerHTML = str; plUpdate = setTimeout('x_getPlanetList(drawPlanetList)', 600000); } //--------------------------------------------------------------------------- // GENERIC ORBIT OBJECT //--------------------------------------------------------------------------- function Orbit(type,id,x,y,orbit,name) { this.type = type; this.id = id; this.x = x; this.y = y; this.orbit = orbit; this.name = name; this.fleets = null; this.spec = null; this.drawAll = Orbit_drawAll; this.draw = Orbit_draw; this.drawCoords = Orbit_drawCoords; this.drawFleets = Orbit_drawFleetSummary; } function Orbit_drawAll() { if (!this.spec) return this.spec.drawLayout(); this.draw(); } function Orbit_draw() { this.drawFleets(); if (!this.spec.draw) return this.spec.draw(); } function Orbit_drawCoords() { return ''+this.x+','+this.y+','+this.orbit; } //--------------------------------------------------------------------------- // NEBULA OBJECT //--------------------------------------------------------------------------- function Nebula(orbit,opacity) { this.orbit = orbit; this.opacity = opacity; this.drawLayout = Nebula_drawLayout; } //--------------------------------------------------------------------------- // REMAINS OBJECT //--------------------------------------------------------------------------- function Remains(orbit) { this.orbit = orbit; this.drawLayout = Remains_drawLayout; } //--------------------------------------------------------------------------- // PLANET OBJECT //--------------------------------------------------------------------------- function Planet(orbit) { this.orbit = orbit; this.bq = new Array(); this.sellForm = null; this.drawLayout = Planet_drawLayout; this.draw = Planet_draw; this.drawBuildQueue = Planet_drawQueue; } function BQItem() { this.selected = false; } function parsePlanetData(planet, l) { var a = l.shift().split('#'); planet.isOwn = (a.shift() == '1'); planet.vacation = (a.shift() == '1'); planet.protection = (a.shift() == '1'); planet.turrets = a.shift(); planet.population = a.shift(); planet.tFactories = a.shift(); planet.iFactories = a.shift(); planet.mFactories = a.shift(); planet.happiness = a.shift(); planet.corruption = a.shift(); planet.profit = a.shift(); planet.tag = a.join('#'); if (!planet.isOwn) return; // Actions and capabilities a = l.shift().split('#'); planet.cAction = a.shift(); if (planet.cAction == '0') { planet.canRename = (a.shift() == '1'); planet.canSell = (a.shift() == '1'); planet.canDestroy = (a.shift() == '1'); planet.canAbandon = (a.shift() == '1'); } else if (planet.cAction == '1') { planet.time = a.shift(); planet.sellId = a.shift(); planet.sellName = a.shift(); } else planet.time = a.shift(); planet.caps = l.shift().split('#'); // Build queue var i = 0, obq = planet.bq; planet.bq = new Array(); while (l.length) { var bqi = (i'; str += '' + getBQItemName(this.bq[i].type, (this.bq[i].qt > 1)) + ''; str += '' + this.bq[i].ttb + 'h'; str += '' + this.bq[i].cttb + 'h'; str += ''; } str += ''; return str; } //--------------------------------------------------------------------------- // PLANET SALE //--------------------------------------------------------------------------- function SellForm() { this.mode = 0; this.player = ''; this.price = 0; this.expires = 0; this.fleets = new Array(); this.validate = SellForm_validate; } function SellForm_validate() { if (this.mode < 2) { this.player = document.getElementById('pstarget').value; if (this.player == '') return 1; } if (this.mode != 0) { this.price = parseInt(document.getElementById('psprice').value, 10); if (isNaN(this.price) || this.price <= 0) return 2; } if (this.mode == 3 && this.expires == 0) return 3; return 0; } function sellPlanet() { x_getSellableFleets(orbit.id, gotFleetsList); } function gotFleetsList(data) { if (data != "ERR#-1") { orbit.spec.sellForm = new SellForm(); if (data != "") { var l = data.split('\n'); while (l.length) { var a = l.shift().split('#'); var b = new Array(); b.push(a.shift()); b.push(a.shift()); b.push(a.shift()); b.push(a.shift()); b.push(a.shift()); b.push(a.shift()); b.push(a.join('#')); b.push(false); orbit.spec.sellForm.fleets.push(b); } } } orbit.draw(); } function closeSaleForm() { orbit.spec.sellForm = null; orbit.draw(); } function confirmSale() {with(orbit.spec.sellForm){ var e = validate(); if (e) { saleError(e); return; } var a = new Array(); for (e=0;e= 2) orbit.spec = new Nebula(orbit, t - 1); else if (t == 1) orbit.spec = new Remains(orbit); else { orbit.spec = new Planet(orbit); parsePlanetData(orbit.spec, l); } orbit.drawAll(); } startUpdate(); } //--------------------------------------------------------------------------- // ACTIONS //--------------------------------------------------------------------------- function renamePlanet() { if (!lockUpdate()) return; var nn = promptNewName(); if (typeof nn == 'object' && !nn) { startUpdate(); return; } x_rename(plId, nn, plExecuteOk); } function factAction(ta, tf) { var n, str; if (!lockUpdate()) return; str = (tf == 1) ? 'mfc' : 'ifc'; n = parseInt(document.getElementById(str).value, 10); if (isNaN(n) || n <= 0) { plError(3); startUpdate(); return; } if (!factoryConfirm(ta, tf, n)) { startUpdate(); return; } x_factoryAction(plId, ta, n, tf, plExecuteOk); } function addToQueue() { if (!lockUpdate()) return; if (mlSel == -1) { plError(1); startUpdate(); return; } var n = parseInt(document.getElementById('bwfq').value, 10); if (isNaN(n) || n <= 0) { plError(2); startUpdate(); return; } x_addToQueue(plId, n, mlSel, plExecuteOk); } function getSelectedItems() { var j, s = new Array(); for (j=0;j