//-------------------------------------------------------------------- // Initialisation code var page; function initPage() { var e = document.getElementById('pinit'); if (!e) return; page = new Page(e.innerHTML); page.action(['update']); } //-------------------------------------------------------------------- // Page management function Page(cPage) { this.action = Page_action; this.init = Page_init; this.update = Page_update; this.updated = Page_updated; this.drawLayout = Page_drawLayout; this.startTimer = Page_startTimer; this.setPage = Page_setPage; this.lockLock = false; this.timerLock = false; this.timer = null; this.menu = new Menu(cPage); this.page = null; this.init(); this.drawLayout(); } function Page_action(args) { var tl = true; while (tl) { while (this.lockLock) ; this.lockLock = true; tl = this.timerLock; if (!tl) { clearTimeout(this.timer); this.timerLock = true; } this.lockLock = false; } var x = 'this.' + args.shift() + '(', i; for (i=0;i0?',':'') + 'args[' + i + ']'; eval(x + ')'); } function Page_setPage(nPage) { this.menu.cPage = nPage; this.init(); // this.menu.draw(); this.drawLayout(); this.update(); } function Page_init() { var classes = [/*'PolicyPage',*/ 'BeaconsPage']; var i; for (i=0;i 0) str += ' - '; if (this.cPage == this.ids[i]) str += ''; else str += ''; str += this.titles[i] + (this.cPage == this.ids[i] ? "" : ""); } document.getElementById('prmenu').innerHTML = str; } //-------------------------------------------------------------------- // Policy page function PolicyPage(main) { this.error = PolicyPage_error; this.drawLayout = PolicyPage_drawLayout; this.updateEmpire = PolicyPage_updateEmpire; this.updatePlanetList = PolicyPage_updatePlanetList; this.updatePlanet = PolicyPage_updatePlanet; this.parsePolicy = function(s) { var p=new Array(),i; for(i=0;i<4;i++) p[i]=s.charAt(i); return p; }; this.parse = PolicyPage_parse; this.parseMain = PolicyPage_parseMain; this.setEmpPolicy = PolicyPage_setEmpPolicy; this.setPlPolicy = PolicyPage_setPlPolicy; this.togglePlanet = PolicyPage_togglePlanet; this.main = main; this.policy = null; this.planets = null; this.updateHeader = false; this.pLines = ['ta', 'am', 'ot', 'en']; } function PolicyPage_parse(data) { var l = data.split('\n'); var t = l.shift(); if (t == "0") this.parseMain(l); else if (t == "1") { this.policy = this.parsePolicy(l[0]); this.updateEmpire(); } else if (t == "2") { var i; t = l[0].split('#'); for (i=0;i 0) { a = l.shift().split('#'); var p = new Array(); p[0] = a.shift(); p[1] = '' + a.shift() + ',' + a.shift() + ',' + a.shift(); if (a[0] == "") a.shift(); else p[3] = this.parsePolicy(a.shift()); p[2] = a.join('#'); this.planets.push(p); nPlanets --; } this.updateEmpire(); this.updatePlanetList(); for (a=0;a

'; for (i=0;i0) str += '
'; var j, idpfx = "ep" + this.pLines[i]; for (j=3;j>0;j--) str += ' '; str += polTexts[i] } str += '

' + plaPolTitle + '

 
'; return str; } function PolicyPage_updateEmpire() { var i; for (i=0;i'; else { for (i=0;i' + p[2] + ' (' + p[1] + ')' + ' '; } } document.getElementById('plapol').innerHTML = str; } function PolicyPage_updatePlanet(index) { var i, j, p = this.planets[index], pfx = "pl" + p[0], up = (typeof p[3] == "object" && p[3]), e, ht; document.getElementById(pfx + 'up').checked = up; ht = (document.getElementById(pfx+'t').innerHTML != ' '); e = document.getElementById(pfx+'ta0'); if (up && !(e && ht)) { var str = '

'; for (i=0;i0) str += '
'; for (j=3;j>0;j--) str += ' '; str += polTexts[i]; } document.getElementById(pfx+'t').innerHTML = str + '

'; } else if (!up && (e || !ht)) document.getElementById(pfx+'t').innerHTML = '

' + polUseEmpire + '

'; if (!up) return; for (i=0;i,"+orbit; this.cLevel = parseInt(current,10); this.upgrade = (upgrade == "" ? "" : formatNumber(upgrade)); this.built = (built == 1); this.nHS = parseInt(nHs,10); this.nMv = parseInt(nMv,10); this.hsFleets = new Array(); this.hsMove = new Array(); } //-------------------------------------------------------------------- // Beacons page function BeaconsPage(main) { this.error = BeaconsPage_error; this.drawLayout = function() { return ""; }; this.parse = BeaconsPage_parse; this.parsePlanet = BeaconsPage_parsePlanet; this.drawAll = BeaconsPage_drawAll; this.drawPlanet = BeaconsPage_drawPlanet; this.upgrade = BeaconsPage_upgrade; this.confirmUpgrade = BeaconsPage_confirmUpgrade; this.main = main; this.planets = new Hashtable(); this.techLevel = 0; } function BeaconsPage_parse(data) { var l = data.split("\n"); var mode = l.shift(); if (mode == "0") { var a = l.shift().split('#'); this.techLevel = parseInt(a.shift(), 10); a = parseInt(a.shift(), 10); while (a > 0) { this.parsePlanet(l); a --; } this.drawAll(); } else if (mode == "1") { var id = this.parsePlanet(l); this.drawPlanet(id); } } function BeaconsPage_parsePlanet(data) { var a = data.shift().split('#'); var p = new BP_Planet(a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.shift(),a.join('#')); this.planets.put(p.id, p); if (p.nHS > 0) { for (var i = 0; i < p.nHS; i ++) { var f = {}; a = data.shift().split('#'); f.level = parseInt(a.shift(), 10); f.size = a.shift(); f.ownerID = a.shift(); f.ownerName = a.shift(); p.hsFleets.push(f); } } return p.id; } function BeaconsPage_drawAll() { var i, keys = this.planets.keys(); var str = ''; for (i=0;i '; document.getElementById('prpage').innerHTML = str; for (i=0;i' + p.name + ' (' + p.coords + ')' + bcnCurrent[p.cLevel] + ''; if (p.nHS > 0) { str += 'Fleets detected!' + 'Information levelFleet sizeFleet owner'; for (var i = 0; i < p.nHS; i ++) { var f = p.hsFleets[i]; str += '' + bcnInfoLevel[f.level] + '' + (f.size == '' ? bcnUnknown : formatNumber(f.size)) + '' + (f.ownerID == '' ? bcnUnknown : ( '' + f.ownerName + '')) + ''; } } str += ''; if (p.upgrade == "") str += bcnNoUpgrade; else if (p.built) str += bcnAlreadyBuilt; else { var u = bcnUpgrade; u = u.replace(/__B__/, bcnCurrent[p.cLevel+1]); u = u.replace(/__C__/, p.upgrade); str += u + ' '; } str += ''; e.innerHTML = str; } function BeaconsPage_upgrade(id) { var p = this.planets.get(id); if (!(p && this.confirmUpgrade(p))) { this.main.startTimer(); return; } this.main.updateHeader = true; x_upgradeBeacon(id, ajaxCallback); }