From c324d0ee25da4cac594e4b1c8d5ec231847a8de2 Mon Sep 17 00:00:00 2001 From: mcmlxxix <> Date: Fri, 27 Apr 2012 15:47:24 +0000 Subject: [PATCH] localize variables, clean up some seriously old, messy code (and hopefully fix the few bugs that remain) --- xtrn/dicewarz/ai.ini | 7 ++ xtrn/dicewarz/ai.js | 33 +++--- xtrn/dicewarz/dice.js | 212 +++++++++++++++++++------------------ xtrn/dicewarz/diceroll.js | 47 +++++--- xtrn/dicewarz/display.js | 25 ++--- xtrn/dicewarz/lock.js | 22 ++-- xtrn/dicewarz/maps.js | 154 +++++++++++++-------------- xtrn/dicewarz/menu.js | 22 ++-- xtrn/dicewarz/player.js | 4 +- xtrn/dicewarz/territory.js | 10 +- 10 files changed, 278 insertions(+), 258 deletions(-) diff --git a/xtrn/dicewarz/ai.ini b/xtrn/dicewarz/ai.ini index e1c093df38..8da948ba79 100644 --- a/xtrn/dicewarz/ai.ini +++ b/xtrn/dicewarz/ai.ini @@ -2,33 +2,40 @@ Sort=KillMost Check=ParanoidAICheck Quantity=Full +Forfeit=Alamo [Dweeble] Sort=Wild Check=Wild Quantity=Full +Forfeit=Coward [Deep Blue] Sort=GroupParanoid Check=UltraParanoid Quantity=Single +Forfeit=Normal [AutoDeuce] Sort=Paranoia Check=Paranoid Quantity=Full +Forfeit=Normal [Twitcher] Sort=RandomAI Check=Random Quantity=Random +Forfeit=Random [Hitler] Sort=Wild Check=Paranoid Quantity=Full +Forfeit=Alamo [Stalin] Sort=Random Check=Paranoid Quantity=Random +Forfeit=Alamo \ No newline at end of file diff --git a/xtrn/dicewarz/ai.js b/xtrn/dicewarz/ai.js index 62b02cd362..c86b05232d 100644 --- a/xtrn/dicewarz/ai.js +++ b/xtrn/dicewarz/ai.js @@ -52,8 +52,8 @@ function GroupAndParanoidAISort(a,b) var ret=0; var dirs=map.loadDirectional(location); - for(dir in dirs) { - current=dirs[dir]; + for(var dir in dirs) { + var current=dirs[dir]; if(map.grid[current]) { if(map.grid[current].player!=player) ret++; @@ -69,20 +69,24 @@ function GroupAndParanoidAISort(a,b) return(ParanoiaAISort(a,b)); return(aopts-bopts); } +function RandomAIForfeit() +{ + var f=new Array(AIForfeitValues.Coward,AIForfeitValues.Normal,AIForfeitValues.Alamo); + + return(f[random(f.length)]); +} /* Callbacks for deciding if a given attack should go into the targets array */ function RandomAICheck(gameNumber, playerNumber, base, target) { - g=games.gameData[gameNumber]; - computerPlayer=g.players[playerNumber]; + var g=games.gameData[gameNumber]; + var computerPlayer=g.players[playerNumber]; var rand=random(100); if(rand>10 && g.grid[base].dice>g.grid[target].dice) return(true); - if(g.grid[base].dice==g.grid[target].dice) - { - if(rand>50 || g.grid[target].dice==g.maxDice) - { + if(g.grid[base].dice==g.grid[target].dice) { + if(rand>50 || g.grid[target].dice==g.maxDice) { if(computerPlayer.territories.length>g.grid.length/6 || computerPlayer.reserve>=20) return(true); else { @@ -100,8 +104,8 @@ function RandomAICheck(gameNumber, playerNumber, base, target) } function ParanoidAICheck(gameNumber, playerNumber, base, target) { - g=games.gameData[gameNumber]; - computerPlayer=g.players[playerNumber]; + var g=games.gameData[gameNumber]; + var computerPlayer=g.players[playerNumber]; var rand=random(100); /* If we have an advantage, add to targets array */ @@ -138,8 +142,8 @@ function WildAndCrazyAICheck(gameNumber, playerNumber, base, target) } function UltraParanoidAICheck(gameNumber, playerNumber, base, target) { - g=games.gameData[gameNumber]; - computerPlayer=g.players[playerNumber]; + var g=games.gameData[gameNumber]; + var computerPlayer=g.players[playerNumber]; /* If we don't have our "fair share" of territories, use paranoid attack */ if(computerPlayer.territories.length <= g.playerTerr) { @@ -174,10 +178,10 @@ function UltraParanoidAICheck(gameNumber, playerNumber, base, target) return(false); /* Finally, check that we will still be at least equal after the capture */ - dirs=g.loadDirectional(target); + var dirs=g.loadDirectional(target); var troublecount=0; for(dir in dirs) { - current=dirs[dir]; + var current=dirs[dir]; if(current==base) continue; if(g.grid[current]) { @@ -212,3 +216,4 @@ function SingleAttackQuantity(tlen) var AISortFunctions={Random:RandomSort, Wild:WildAndCrazyAISort, KillMost:KillMostDiceAISort, Paranoia:ParanoiaAISort, RandomAI:RandomAISort, GroupParanoid:GroupAndParanoidAISort}; var AICheckFunctions={Random:RandomAICheck, Paranoid:ParanoidAICheck, Wild:WildAndCrazyAICheck, UltraParanoid:UltraParanoidAICheck}; var AIQtyFunctions={Random:RandomAttackQuantity, Full:FullAttackQuantity, Single:SingleAttackQuantity}; +var AIForfeitValues={Coward:.45,Normal:.25,Alamo:0,Random:RandomAIForfeit}; \ No newline at end of file diff --git a/xtrn/dicewarz/dice.js b/xtrn/dicewarz/dice.js index 74ddd2eb04..86502fcefa 100644 --- a/xtrn/dicewarz/dice.js +++ b/xtrn/dicewarz/dice.js @@ -60,7 +60,7 @@ var settings= new GameSettings(); var gamedice= loadDice(); var oldpass= console.ctrlkey_passthru; -js.on_exit("file_remove(userFileName);"); +js.on_exit("cleanUp();"); console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_"; bbs.sys_status|=SS_MOFF; @@ -69,32 +69,29 @@ function scanProximity(location) { var prox=[]; var odd=false; - offset=location%columns; - if((offset%2)==1) odd=true; + var offset=location%columns; + if((offset%2)==1) + odd=true; if(location>=columns) //if not in the first row prox[0]=(location-columns); //north if(location<(columns*(rows-1))) //if not in the last row prox[1]=(location+columns); //south - if(odd) - { + if(odd) { if(((location+1)%columns)!=1) //if not in the first column prox[2]=location-1; //northwest if(((location+1)%columns)!=0) //if not in the last column prox[3]=location+1; //northeast - if(location<(columns*(rows-1))) //if not in the last row - { + if(location<(columns*(rows-1))) { //if not in the last row if(((location+1)%columns)!=1) //if not in the first column prox[4]=prox[1]-1; //southwest if(((location+1)%columns)!=0) //if not in the last column prox[5]=prox[1]+1; //southeast } } - else - { - if(location>=columns) //if not in the first row - { + else { + if(location>=columns) { //if not in the first row if(((location+1)%columns)!=1) //if not in the first column prox[2]=prox[0]-1; //northwest if(((location+1)%columns)!=0) //if not in the last column @@ -118,12 +115,13 @@ function getNextGameNumber() function CountSparseArray(data) { var count=0; - for(tt in data) - { + for(var tt in data) { count++; } - if(count==0) return false; - else return count; + if(count==0) + return false; + else + return count; } function viewInstructions() { @@ -159,13 +157,12 @@ function viewRankings() printf(printPadded("\xB4",10,"\xC4","right")); console.crlf(); - for(hs in scoredata) - { + for(var hs in scoredata) { thisuser=scoredata[hs]; - if(scores[thisuser].score!=0 || scores[thisuser].wins>0 || scores[thisuser].losses>0 || scores[thisuser].kills>0) - { + if(scores[thisuser].score!=0 || scores[thisuser].wins>0 || scores[thisuser].losses>0 || scores[thisuser].kills>0) { var winPercentage=0; - if(scores[thisuser].wins>0) winPercentage=(scores[thisuser].wins/(scores[thisuser].wins+scores[thisuser].losses))*100; + if(scores[thisuser].wins>0) + winPercentage=(scores[thisuser].wins/(scores[thisuser].wins+scores[thisuser].losses))*100; printf("\1k\1h\xB3"); printf(printPadded("\1y\1h " + system.username(thisuser),26," ","left")); printf("\1k\1h\xB3"); @@ -196,8 +193,7 @@ function viewRankings() function sort(iiii) { var sorted=[]; - for(cc in iiii) - { + for(var cc in iiii) { sorted.push(cc); } sorted.sort(); @@ -225,9 +221,8 @@ function attackMessage(txt) function compressScores() { - compressed=[]; - for(score in scores) - { + var compressed=[]; + for(var score in scores) { compressed.push(score); } return compressed; @@ -236,13 +231,13 @@ function sortScores() { var data=compressScores(); var numScores=data.length; - for(n=0;n<numScores;n++) + for(var n=0;n<numScores;n++) { - for(m = 0; m < (numScores-1); m++) + for(var m = 0; m < (numScores-1); m++) { if(scores[data[m]].score < scores[data[m+1]].score) { - holder = data[m+1]; + var holder = data[m+1]; data[m+1] = data[m]; data[m] = holder; } @@ -278,8 +273,9 @@ function storeMessage(unum,msg) return false; else { var user_online=false; - for(n=0;n<system.node_list.length && !user_online;n++) { - if(system.node_list[n].useron==unum) user_online=true; + for(var n=0;n<system.node_list.length && !user_online;n++) { + if(system.node_list[n].useron==unum) + user_online=true; } if(!user_online) { file_remove(ufname); @@ -311,9 +307,7 @@ function splashStart() } function splashExit() { - console.ctrlkey_passthru=oldpass; - bbs.sys_status&=~SS_MOFF; - file_remove(userFileName); + cleanUp(); console.clear(); var splash_filename=root + "exit.bin"; if(!file_exists(splash_filename)) @@ -330,6 +324,12 @@ function splashExit() while(console.inkey(K_NOECHO|K_NOSPIN)===""); exit(); } +function cleanUp() +{ + console.ctrlkey_passthru=oldpass; + bbs.sys_status&=~SS_MOFF; + file_remove(userFileName); +} function gameMenu() { var gMenu=new Menu( "" ,1,19,"\1n\1g","\1g\1h"); @@ -398,10 +398,9 @@ function gameMenu() } function chooseGame() { - x=30; - y=19; - while(1) - { + var x=30; + var y=19; + while(1) { console.gotoxy(x,y); console.cleartoeol(); if(!games.gameData.length) { @@ -409,7 +408,7 @@ function chooseGame() break; } console.putmsg("\1n\1gEnter game number or [\1hQ\1n\1g]uit\1h: "); - game_num=console.getkeys("Q",settings.maxGames); + var game_num=console.getkeys("Q",settings.maxGames); if(game_num=="Q") return false; if(games.gameData[game_num]) { @@ -417,7 +416,7 @@ function chooseGame() var num=game_num; if(game_num<10) num="0" + num; - gamefile="game" + num; + var gamefile="game" + num; if(Locked(gamefile)) putMessage("\1r\1hThat game is in use by another node.",x,y); @@ -504,7 +503,7 @@ function askRemove(gameNumber,playerNumber) } function viewGameInfo(gameNumber) { - g=games.gameData[gameNumber]; + var g=games.gameData[gameNumber]; clearArea(3,1,14); console.gotoxy(2,4); console.putmsg("\1g[ \1hGAME: #" + gameNumber + " \1n\1g]\r\n"); @@ -516,7 +515,7 @@ function viewGameInfo(gameNumber) console.putmsg("\1n\1g Player names hidden: \1h" + g.hiddenNames + "\r\n"); console.putmsg("\1n\1g Players In This Game:\r\n"); - for(playerNumber=0;playerNumber<g.players.length;playerNumber++) { + for(var playerNumber=0;playerNumber<g.players.length;playerNumber++) { var player=g.players[playerNumber]; var name=getUserName(player,playerNumber); if(g.hiddenNames && name!=user.alias) @@ -541,7 +540,7 @@ function startGame(gameNumber) games.gameData[gameNumber].fileName = oldFn; games.gameData[gameNumber].singlePlayer = oldSp; games.gameData[gameNumber].hiddenNames = oldhn; - g=games.gameData[gameNumber]; + var g=games.gameData[gameNumber]; games.gameData[gameNumber].players=players; games.inProgress.push(gameNumber); games.gameData[gameNumber].init(); @@ -553,7 +552,7 @@ function startGame(gameNumber) var aifile=new File(root + "ai.ini"); aifile.open("r"); var possibleplayers=aifile.iniGetSections(); - for(i=0; i<g.players.length; i++) { + for(var i=0; i<g.players.length; i++) { if(g.players[i].user==-1) { if(possibleplayers.length > 0) { var p=random(possibleplayers.length); @@ -630,7 +629,8 @@ function createNewGame() console.cleartoeol(); return false; } - x=2; y=3; + x=2; + y=3; console.gotoxy(x,y); console.cleartoeol(); y++; @@ -705,7 +705,7 @@ function createNewGame() console.gotoxy(x,y); console.cleartoeol(); console.putmsg("\1n\1gHow many? [\1h1\1n\1g-\1h" + (maxNumPlayers-1) + "\1n\1g] or [\1hQ\1n\1g]uit: "); - cnum=console.getkeys("Q",maxNumPlayers-1); + var cnum=console.getkeys("Q",maxNumPlayers-1); if(cnum<=(maxNumPlayers-1) && cnum>0) { numComputerPlayers=cnum; break; @@ -718,7 +718,7 @@ function createNewGame() } games.gameData[gameNumber]=new NewGame(minNumPlayers,maxNumPlayers,gameNumber); games.gameData[gameNumber].fileName=getFileName(gameNumber); - for(cp=0;cp<numComputerPlayers;cp++) + for(var cp=0;cp<numComputerPlayers;cp++) games.gameData[gameNumber].addPlayer(-1, 1); //NO USER NUMBER, NO VOTE if(!singlePlayer) { if(hiddenNames) @@ -801,7 +801,7 @@ function selectTile(gameNumber,playerNumber,attackPosition,startPosition) } } } - dir=terr.location; + var dir=terr.location; while(1) { var key=console.getkey(K_NOECHO|K_NOCRLF|K_UPPER); @@ -870,7 +870,7 @@ function selectTile(gameNumber,playerNumber,attackPosition,startPosition) } if(terr.location != attackPosition) terr.displayBorder(border_color); if(attackpos) showSelected(attackpos,"\1n\1r\1h"); - terr=g.grid[dir]; + var terr=g.grid[dir]; showSelected(terr,"\1n\1w\1h"); } wipeCursor("left"); @@ -885,15 +885,19 @@ function attack(gameNumber,playerNumber) clearArea(16,menuColumn,8); attackMessage("from which to Attack,"); var attackFrom=selectTile(gameNumber,playerNumber,-1,games.gameData[gameNumber].lastMapPosition); - if(attackFrom==false) return false; + if(attackFrom==false) + return false; clearArea(16,menuColumn,8); attackMessage("to Attack,"); var attackTo=selectTile(gameNumber,playerNumber,attackFrom.location); - if(attackTo==false) return false; + if(attackTo==false) + return false; var tofrom=battle(attackFrom,attackTo,gameNumber); - if(tofrom=true) games.gameData[gameNumber].lastMapPosition=attackTo.location; - else games.gameData[gameNumber].lastMapPosition=attackFrom.location; + if(tofrom=true) + games.gameData[gameNumber].lastMapPosition=attackTo.location; + else + games.gameData[gameNumber].lastMapPosition=attackFrom.location; return true; } function battle(attackFrom,attackTo,gameNumber) @@ -934,7 +938,8 @@ function endTurn(gameNumber,pl) console.putmsg("\1r\1hPlaced " + placed.length + " reinforcements"); mswait(1000); clearArea(16,menuColumn,9); - for(place in placed) g.grid[placed[place]].show(); + for(var place in placed) + g.grid[placed[place]].show(); g.takingTurn=false; games.storeGame(gameNumber); } @@ -1111,34 +1116,34 @@ function playGame(gameNumber) } function takeTurnAI(gameNumber,playerNumber) { - g=games.gameData[gameNumber]; - computerPlayer=g.players[playerNumber]; - targets=[]; + var g=games.gameData[gameNumber]; + var computerPlayer=g.players[playerNumber]; + var targets=[]; /* if we are down to two players */ if(g.countActivePlayers().length == 2) { var perc = computerPlayer.countTerritory() / g.mapSize; - /* if this ai occupies less than a quarter of the map, forfeit the game */ - if(perc < 0.25) { + /* if this ai occupies less it's preferred threshold, forfeit the game */ + if(perc < AIForfeitValues[computerPlayer.AI.forfeit]) { forfeit(gameNumber,playerNumber); return false; } } /* For each owned territory */ - for(territory in computerPlayer.territories) { - base=computerPlayer.territories[territory]; + for(var territory in computerPlayer.territories) { + var base=computerPlayer.territories[territory]; /* If we have enough to attack */ if(g.grid[base].dice>1) { /* Find places we can attack */ - attackOptions=g.canAttack(playerNumber,base,computerPlayer,g); + var attackOptions=g.canAttack(playerNumber,base,computerPlayer,g); if(attackOptions!==false) { var basetargets=[]; /* Randomize the order to check in */ attackOptions.sort(RandomSort); - for(option in attackOptions) { - target=attackOptions[option]; + for(var option in attackOptions) { + var target=attackOptions[option]; /* Check if this is an acceptable attack */ if(AICheckFunctions[computerPlayer.AI.check](gameNumber, playerNumber, base, target)) basetargets.push({gameNumber:gameNumber, target:target, base:base, target_grid:g.grid[target], base_grid:g.grid[base]}); @@ -1153,13 +1158,13 @@ function takeTurnAI(gameNumber,playerNumber) } /* Randomize the targets array */ targets.sort(RandomSort); - attackQuantity=AIQtyFunctions[computerPlayer.AI.qty](targets.length); + var attackQuantity=AIQtyFunctions[computerPlayer.AI.qty](targets.length); if(attackQuantity < 1) return false; targets.sort(AISortFunctions[computerPlayer.AI.sort]); - for(attackNum=0;attackNum<attackQuantity;attackNum++) { - attackFrom=g.grid[targets[attackNum].base]; - attackTo=g.grid[targets[attackNum].target]; + for(var attackNum=0;attackNum<attackQuantity;attackNum++) { + var attackFrom=g.grid[targets[attackNum].base]; + var attackTo=g.grid[targets[attackNum].target]; if(attackFrom.dice>1 && attackTo.player!=playerNumber) { battle(attackFrom,attackTo,gameNumber); computerPlayer.AI.moves++; @@ -1243,7 +1248,7 @@ function GameStatusInfo() if(!Locked(scorefile,true)) { Lock(scorefile); sfile.open((file_exists(sfilename)?'r+':'w+'), true); - for(s in scores) { + for(var s in scores) { var score=scores[s]; var points=score.score>=settings.minScore?score.score:settings.minScore; sfile.iniSetValue(s,"score",points); @@ -1263,7 +1268,7 @@ function GameStatusInfo() var lfile=new File(sfilename); lfile.open('r',true); var plyrs=lfile.iniGetSections(); - for(p=0;p<plyrs.length;p++) { + for(var p=0;p<plyrs.length;p++) { var player=plyrs[p]; var score=parseInt(lfile.iniGetValue(player,"score"),10); var kills=parseInt(lfile.iniGetValue(player,"kills"),10); @@ -1283,7 +1288,7 @@ function GameStatusInfo() } this.winRound=function(player) { - hfilename=root+halloffame; + var hfilename=root+halloffame; var hfile=new File(hfilename); hfile.open('a'); hfile.writeln(" \1w\1h" + system.datestr() + "\1n: \1y" + system.username(player)); @@ -1320,13 +1325,13 @@ function GameStatusInfo() lgame.fileName=gamefile; if(minp==maxp) lgame.fixedPlayers=true; - for(nnn=0;!gfile.eof && nnn<maxp;nnn++) { + for(var nnn=0;!gfile.eof && nnn<maxp;nnn++) { userNumber=gfile.readln(); if(userNumber===null || userNumber===undefined || userNumber==="") break; else { - userNumber=parseInt(userNumber,10); - vote=gfile.readln(); + var userNumber=parseInt(userNumber,10); + var vote=gfile.readln(); lgame.addPlayer(userNumber,parseInt(vote,10)); if(userNumber>0 && !scores[userNumber]) scores[userNumber]={'score':0,'kills':0,'wins':0,'losses':0}; @@ -1351,13 +1356,13 @@ function GameStatusInfo() lgame.playerTerr=pt; lgame.hiddenNames=hn; - for(to=0;to<np;to++) { - ttoo=parseInt(gfile.readln()); + for(var to=0;to<np;to++) { + var ttoo=parseInt(gfile.readln()); lgame.turnOrder[to]=ttoo; } var aifile=new File(root + "ai.ini"); aifile.open("r"); - for(pl=0;pl<np;pl++) { + for(var pl=0;pl<np;pl++) { var uname=gfile.readln(); var u=-1; if(uname.search(/^[0-9]+$/) != -1) @@ -1379,9 +1384,10 @@ function GameStatusInfo() else { /* Set up computer players */ lgame.players[pl].AI.name=uname; - lgame.players[pl].AI.sort=aifile.iniGetValue(lgame.players[pl].AI.name, "sort", "Random"); + lgame.players[pl].AI.sort=aifile.iniGetValue(lgame.players[pl].AI.name, "Sort", "Random"); lgame.players[pl].AI.check=aifile.iniGetValue(lgame.players[pl].AI.name, "Check", "Random"); lgame.players[pl].AI.qty=aifile.iniGetValue(lgame.players[pl].AI.name, "Quantity", "Random"); + lgame.players[pl].AI.forfeit=aifile.iniGetValue(lgame.players[pl].AI.name, "Forfeit", "Random"); if(AISortFunctions[lgame.players[pl].AI.sort]==undefined) lgame.players[pl].AI.sort="Random"; if(AICheckFunctions[lgame.players[pl].AI.check]==undefined) @@ -1393,10 +1399,10 @@ function GameStatusInfo() aifile.close(); if(humans<2) lgame.singlePlayer=true; - for(sec=0;sec<ms;sec++) { - spot_player=parseInt(gfile.readln(),10); - spot_index=parseInt(gfile.readln(),10); - spot_dice=parseInt(gfile.readln(),10); + for(var sec=0;sec<ms;sec++) { + var spot_player=parseInt(gfile.readln(),10); + var spot_index=parseInt(gfile.readln(),10); + var spot_dice=parseInt(gfile.readln(),10); lgame.grid[spot_index]=new Territory(spot_index); lgame.used[spot_index]=true; lgame.grid[spot_index].assign(spot_player,lgame.players[spot_player]); @@ -1411,7 +1417,7 @@ function GameStatusInfo() } this.storeGame=function(gameNumber) { - g=this.gameData[gameNumber]; + var g=this.gameData[gameNumber]; var gamefullname=getFileName(gameNumber); var gfile=new File(gamefullname); gfile.open('w+',false); @@ -1421,7 +1427,7 @@ function GameStatusInfo() if(g.status<0) { gfile.writeln(g.minPlayers); gfile.writeln(g.maxPlayers); - for(nnn=0;nnn<g.players.length;nnn++) { + for(var nnn=0;nnn<g.players.length;nnn++) { gfile.writeln(g.players[nnn].user); gfile.writeln(g.players[nnn].vote); } @@ -1434,28 +1440,28 @@ function GameStatusInfo() gfile.writeln(g.rows); gfile.writeln(g.columns); gfile.writeln(g.playerTerr); - for(to=0;to<g.maxPlayers;to++) + for(var to=0;to<g.maxPlayers;to++) gfile.writeln(g.turnOrder[to]); - for(ply in g.players) { - p=g.players[ply]; + for(var ply in g.players) { + var p=g.players[ply]; if(p.user==-1) gfile.writeln(p.AI.name); else gfile.writeln(p.user); gfile.writeln(p.reserve); } - for(sector in g.used) { - location=sector; + for(var sector in g.used) { + var location=sector; gfile.writeln(g.grid[location].player); gfile.writeln(g.grid[location].location); gfile.writeln(g.grid[location].dice); - } + } gfile.close(); } this.updateGames=function() { var u=false; - for(gd in this.gameData) { + for(var gd in this.gameData) { var fileName=this.gameData[gd].fileName; var lastModified=file_date(fileName); @@ -1476,10 +1482,10 @@ function GameStatusInfo() this.sortArray=function(data) { var numItems=data.length; - for(n=0;n<numItems;n++) { - for(m = 0; m < (numItems-1); m++) { + for(var n=0;n<numItems;n++) { + for(var m = 0; m < (numItems-1); m++) { if(parseInt(data[m],10) > parseInt(data[m+1],10)) { - holder = data[m+1]; + var holder = data[m+1]; data[m+1] = data[m]; data[m] = holder; } @@ -1499,7 +1505,7 @@ function GameStatusInfo() this.yourTurn=[]; this.eliminated=[]; - for(ggg in this.gameData) { + for(var ggg in this.gameData) { var gm=this.gameData[ggg]; if(!file_exists(gm.fileName)) { Log("game file missing, removing data: " + gm.filename); @@ -1558,7 +1564,7 @@ function GameStatusInfo() { var open_list=directory(root + "game*.dat"); if(open_list.length) { - for(lg in open_list) { + for(var lg in open_list) { var temp_fname=file_getname(open_list[lg]); var lastModified=file_date(open_list[lg]); var daysOld=(time()-lastModified)/daySeconds; @@ -1574,16 +1580,16 @@ function GameStatusInfo() this.deleteOld=function() { Log("deleting old game data"); - for(oldgame in this.gameData) { - daysOld=(time()-this.gameData[oldgame].lastModified)/daySeconds; + for(var oldgame in this.gameData) { + var daysOld=(time()-this.gameData[oldgame].lastModified)/daySeconds; if(this.gameData[oldgame].singlePlayer===true && daysOld>=settings.keepGameData) { file_remove(this.gameData[oldgame].fileName); delete this.gameData[oldgame]; } } - for(completed in this.completed) { - gm=this.completed[completed]; - daysOld=(time()-this.gameData[gm].lastModified)/daySeconds; + for(var completed in this.completed) { + var gm=this.completed[completed]; + var daysOld=(time()-this.gameData[gm].lastModified)/daySeconds; if(this.gameData[gm].singlePlayer===true || daysOld>=settings.keepGameData) { file_remove(this.gameData[gm].fileName); delete this.gameData[gm]; @@ -1593,16 +1599,16 @@ function GameStatusInfo() this.updatePlayers=function() { Log("updating players"); - for(inp in this.inProgress) { + for(var inp in this.inProgress) { var gm=this.gameData[this.inProgress[inp]]; if(gm) { - daysOld=(time()-gm.lastModified)/daySeconds; + var daysOld=(time()-gm.lastModified)/daySeconds; if(settings.abortDays>0 && daysOld>=settings.abortDays) { Log("removing expired game: " + gm.fileName); file_remove(gm.fileName); } else if(settings.skipDays>0 && daysOld>=settings.skipDays && !gm.singlePlayer) { - nextTurnPlayer=gm.turnOrder[gm.nextTurn]; + var nextTurnPlayer=gm.turnOrder[gm.nextTurn]; deliverForfeitMessage(gm.players[nextTurnPlayer].user,gm.gameNumber); forfeit(gm.gameNumber,nextTurnPlayer); } diff --git a/xtrn/dicewarz/diceroll.js b/xtrn/dicewarz/diceroll.js index ea882be0cf..10b82385f5 100644 --- a/xtrn/dicewarz/diceroll.js +++ b/xtrn/dicewarz/diceroll.js @@ -5,14 +5,18 @@ function rollDice(a,b,dice) var x=menuColumn; var y=16; - bc=console.ansi(BG_RED); - fc=console.ansi(LIGHTGRAY); + var bc=console.ansi(BG_RED); + var fc=console.ansi(LIGHTGRAY); fancyRoll(a,x,y,fc,bc,dice); - xx=x; - yy=y; - for(aa=0;aa<a;aa++) { - rand=(random(6)+1); + var xx=x; + var yy=y; + + for(var aa=0;aa<a;aa++) { + var rand=random(6)+1; + if(!dice[rand]) { + log(LOG_ERROR,"dice error: " + rand); + } dice[rand].display(xx,yy,fc,bc); xx+=4; totals[0]+=rand; @@ -26,9 +30,12 @@ function rollDice(a,b,dice) fancyRoll(b,x,y,fc,bc,dice); xx=x; yy=y; - for(bb=0;bb<b;bb++) { - rand=(random(6)+1); + for(var bb=0;bb<b;bb++) { + var rand=random(6)+1; totals[1]+=rand; + if(!dice[rand]) { + log(LOG_ERROR,"dice error: " + rand); + } dice[rand].display(xx,yy,fc,bc); xx+=4; } @@ -39,11 +46,17 @@ function rollDice(a,b,dice) } function fancyRoll(qty,x,y,fc,bc,dice) { //"ROLLING DICE" DISPLAY - for(roll=0;roll<8;roll++) { - xx=x; - yy=y; - for(dr=0;dr<qty;dr++) { - dice[random(6)+1].display(xx,yy,fc,bc); + for(var roll=0;roll<8;roll++) { + var xx=x; + var yy=y; + for(var dr=0;dr<qty;dr++) { + var num = random(6) + 1; + while(num < 0 || num > 6) + num = random(6) + 1; + if(!dice[num]) { + log(LOG_ERROR,"dice error: " + num); + } + dice[num].display(xx,yy,fc,bc); xx+=4; } mswait(40); @@ -81,8 +94,8 @@ function Die(number) } function loadDice() { //INITIALIZE SIX SIDED DICE OBJECTS - var dice_=[]; - for(d=1;d<=6;d++) - dice_[d]=new Die(d); - return dice_; + var dice=[]; + for(var d=1;d<=6;d++) + dice[d]=new Die(d); + return dice; } diff --git a/xtrn/dicewarz/display.js b/xtrn/dicewarz/display.js index 15ee680ca9..f072631d15 100644 --- a/xtrn/dicewarz/display.js +++ b/xtrn/dicewarz/display.js @@ -10,8 +10,7 @@ function clearArea(fromRow,fromColumn,qty) var count; console.gotoxy(fromColumn, fromRow); - for(count=0;count < qty; count++) - { + for(var count=0;count < qty; count++) { console.cleartoeol(); console.down(); } @@ -26,9 +25,10 @@ function wrap(msg,lst) console.putmsg("\1w\1h: "); var col=32; var delimiter="\1n\1g,"; - for(aa=0;aa<lst.length;aa++) + for(var aa=0;aa<lst.length;aa++) { - if(aa==lst.length-1) delimiter=""; + if(aa==lst.length-1) + delimiter=""; var item=lst[aa]+delimiter; if((col + console.strlen(item))>79) { console.crlf(); @@ -70,8 +70,7 @@ function drawVerticalLine(color/*, side*/) { var ly=1; var lx=menuColumn-1; - for(;ly<=24;ly++) - { + for(;ly<=24;ly++) { console.gotoxy(lx,ly); console.putmsg(color + "\xBA"); } @@ -79,8 +78,12 @@ function drawVerticalLine(color/*, side*/) function wipeCursor(lr) //SEND CURSOR TO BOTTOM RIGHT CORNER OF SCREEN { - if(lr=="left") { side=1; row=console.screen_rows; } - else { side=console.screen_columns; row=1; } + var side = console.screen_columns; + var row = 1; + if(lr=="left") { + side=1; + row=console.screen_rows; + } console.gotoxy(side,row); } @@ -124,12 +127,10 @@ function showWinner(g) console.gotoxy(51,18); console.putmsg("\1n\1r\1hThis game was won by: "); console.gotoxy(53,19); - if(g.winner>=0) - { + if(g.winner>=0) { console.putmsg("\1n\1r\1h" + system.username(g.winner)); } - else - { + else { console.putmsg("\1n\1r\1hcomputer player"); } wipeCursor("left"); diff --git a/xtrn/dicewarz/lock.js b/xtrn/dicewarz/lock.js index 0ce10e2bdc..689ec51e55 100644 --- a/xtrn/dicewarz/lock.js +++ b/xtrn/dicewarz/lock.js @@ -5,16 +5,15 @@ function Locked(fileName,timeOut) { if(!timeOut) return true; var max_attempts=20; - for(attempt=0;attempt<max_attempts;attempt++) - { - if(file_exists(fname)) - { + for(var attempt=0;attempt<max_attempts;attempt++){ + if(file_exists(fname)) { mswait(250); } else return false; } } - else return false; + else + return false; return true; } function Lock(fileName) @@ -24,26 +23,23 @@ function Lock(fileName) lockfile.open('we', false); if(!lockfile.is_open) return false; - else - { + else { lockfile.close(); - activeGame=fileName; return fileName; } } function Unlock(fileName) { - if(fileName==-1 || !fileName) return; + if(fileName==-1 || !fileName) + return; var fname=(root+fileName+".lck"); file_remove(fname); } function UnlockAll() { var lockList=directory(root + "*.lck"); - if(lockList.length) - { - for(lf in lockList) - { + if(lockList.length) { + for(var lf in lockList) { file_remove(lockList[lf]); } } diff --git a/xtrn/dicewarz/maps.js b/xtrn/dicewarz/maps.js index 602f540370..7e9591353b 100644 --- a/xtrn/dicewarz/maps.js +++ b/xtrn/dicewarz/maps.js @@ -21,7 +21,7 @@ function NewGame(minp,maxp,n) this.tallyVotes=function() { var trueVotes=0; - for(v in this.players) { + for(var v in this.players) { if(this.players[v].user>0 && this.players[v].vote==1) { trueVotes++; } @@ -36,7 +36,7 @@ function NewGame(minp,maxp,n) this.countHumanPlayers=function() { var count=0; - for(pppp in this.players) { + for(var pppp in this.players) { if(this.players[pppp].user>0) count++; } @@ -45,7 +45,7 @@ function NewGame(minp,maxp,n) this.countPlayers=function() { var count=0; - for(pppp in this.players) { + for(var pppp in this.players) { count++; } return count; @@ -99,8 +99,8 @@ function Map(c,r,p,gn) //NOTIFY NEXT PLAYER OF TURN this.notify= function() //NOTIFY NEXT PLAYER OF TURN { - nextTurn=this.nextTurn; - nextTurnPlayer=this.players[this.turnOrder[nextTurn]].user; + var nextTurn=this.nextTurn; + var nextTurnPlayer=this.players[this.turnOrder[nextTurn]].user; if(this.status!=0 && !this.singlePlayer) { if(this.countActiveHumans<2) @@ -126,8 +126,7 @@ function Map(c,r,p,gn) } this.findDaysOld= function() //DETERMINE THE LAST TIME A GAME FILE WAS MODIFIED (LAST TURN TAKEN) { - daysOld=(time()-this.lastModified)/daySeconds; - return daysOld; + return((time()-this.lastModified)/daySeconds); } this.checkElimination= function() { @@ -145,7 +144,7 @@ function Map(c,r,p,gn) this.countActivePlayers= function() { var activePlayers=[]; - for(player in this.players) { + for(var player in this.players) { if(!this.players[player].eliminated) activePlayers.push(player); } @@ -153,8 +152,8 @@ function Map(c,r,p,gn) } this.countActiveHumans= function() { - count=0; - for(ply in this.players) { + var count=0; + for(var ply in this.players) { if(this.players[ply].user>0 && !this.players[ply].eliminated) count++; } @@ -215,7 +214,7 @@ function Map(c,r,p,gn) this.setEliminated= function() { //RUNS AT STARTUP, STORING GAME ELIMINATION DATA UPON LOADING EACH GAME this.eliminated=[]; - for(elp in this.players) { + for(var elp in this.players) { if(this.players[elp].territories.length<=0) { this.eliminated.push(elp); this.players[elp].eliminated=true; @@ -232,7 +231,7 @@ function Map(c,r,p,gn) this.nextTurn=0; else this.nextTurn++; - nextPlayer=this.turnOrder[this.nextTurn]; + var nextPlayer=this.turnOrder[this.nextTurn]; while(this.players[nextPlayer].eliminated) { if(this.nextTurn==this.maxPlayers-1) this.nextTurn=0; @@ -248,12 +247,12 @@ function Map(c,r,p,gn) } this.displayGrid= function() { //DISPLAYS THE LOCATION DATA FOR EACH COMPANY - for(uu in this.used) + for(var uu in this.used) this.grid[uu].displayBorder(border_color); } this.setGrid= function() { - for(uu in this.used) + for(var uu in this.used) this.grid[uu].setBorder(this.grid); } this.redraw= function() @@ -265,26 +264,26 @@ function Map(c,r,p,gn) } this.displayGame= function() { //DISPLAY EACH PLAYER'S TERRITORIES - for(ply in this.players) { - for(ter in this.players[ply].territories) { - territory=this.players[ply].territories[ter]; + for(var ply in this.players) { + for(var ter in this.players[ply].territories) { + var territory=this.players[ply].territories[ter]; this.grid[territory].show(); } } } this.getXY= function(place) { //TAKE A GRID INDEX, AND RETURNS THE CORRESPONDING X AND Y COORDINATES FOR DISPLAY - x=this.map_column; - y=this.map_row; + var x=this.map_column; + var y=this.map_row; x+=((place%this.columns)*2); y+=(parseInt(index/this.columns)); console.gotoxy(x,y); - return(0); + return; } this.reinforce= function(playerNumber) { - numDice=this.findConnected(playerNumber); - placed=this.placeDice(playerNumber,numDice); + var numDice=this.findConnected(playerNumber); + var placed=this.placeDice(playerNumber,numDice); if(this.winner<0) this.checkElimination(); this.getNextTurn(); @@ -297,11 +296,11 @@ function Map(c,r,p,gn) if(mapLocation>=0) { if(this.grid[mapLocation].player!=playerNumber) return false; - options=[]; + var options=[]; if(this.grid[mapLocation].dice>1) { - dirs=this.loadDirectional(mapLocation); + var dirs=this.loadDirectional(mapLocation); for(dir in dirs) { - current=dirs[dir]; + var current=dirs[dir]; if(this.grid[current]) { if(this.grid[current].player!=playerNumber) options.push(current); @@ -313,16 +312,15 @@ function Map(c,r,p,gn) else return false; } - else //OTHERWISE, SIMPLY DETERMINE WHETHER THE PLAYER CAN ATTACK AT ALL, AND RETURN TRUE OR FALSE - { + else { //OTHERWISE, SIMPLY DETERMINE WHETHER THE PLAYER CAN ATTACK AT ALL, AND RETURN TRUE OR FALSE if(this.players[playerNumber].territories.length==this.players[playerNumber].totalDice) return false; for(terr in this.players[playerNumber].territories) { - currentTerritory=this.players[playerNumber].territories[terr]; + var currentTerritory=this.players[playerNumber].territories[terr]; if(this.grid[currentTerritory].dice>1) { - dirs=this.loadDirectional(currentTerritory); + var dirs=this.loadDirectional(currentTerritory); for(dir in dirs) { - current=dirs[dir]; + var current=dirs[dir]; if(this.grid[current]) { if(this.grid[current].player!=playerNumber) return true; @@ -335,35 +333,34 @@ function Map(c,r,p,gn) } this.loadDirectional= function(mapLocation) { - current=this.grid[mapLocation]; - n=current.north; - s=current.south; - nw=current.northwest; - ne=current.northeast; - sw=current.southwest; - se=current.southeast; - dirs=[n,s,nw,ne,sw,se]; - return dirs; + var current=this.grid[mapLocation]; + var n=current.north; + var s=current.south; + var nw=current.northwest; + var ne=current.northeast; + var sw=current.southwest; + var se=current.southeast; + return [n,s,nw,ne,sw,se];; } this.findConnected= function(playerNumber) { //SCANS ENTIRE MAP AND RETURNS THE NUMBER EQUAL TO THE PLAYER'S LARGEST CLUSTER OF CONNECTED TILES - largest_cluster=1; - terr=this.players[playerNumber].territories; + var largest_cluster=1; + var terr=this.players[playerNumber].territories; var checked=[]; var counted=[]; var tocheck=[]; - y=10; + var y=10; for(tttt in terr) { - count=1; + var count=1; tocheck.push(terr[tttt]); while(tocheck.length) { - loc=tocheck.shift(); - current=this.grid[loc]; + var loc=tocheck.shift(); + var current=this.grid[loc]; if(!checked[current.location]) { - dirs=scanProximity(current.location); + var dirs=scanProximity(current.location); for(ddd in dirs) { - dir=dirs[ddd]; + var dir=dirs[ddd]; if(this.grid[dir] && !checked[dir]) { if(this.grid[dir].player==playerNumber) { tocheck.push(dir); @@ -413,7 +410,7 @@ function Map(c,r,p,gn) } this.ShufflePlayers= function() { //Generate TURN ORDER (this.turnOrder[]) - for(pp=0;pp<this.maxPlayers;pp++) { + for(var pp=0;pp<this.maxPlayers;pp++) { var rand=random(this.maxPlayers); if(this.turnOrder[rand]>=0) pp--; @@ -423,8 +420,8 @@ function Map(c,r,p,gn) } this.generatePlayers= function() { - for(pl=0;pl<this.maxPlayers;pl++) { - userNumber=this.players[pl].user; + for(var pl=0;pl<this.maxPlayers;pl++) { + var userNumber=this.players[pl].user; this.users[userNumber]=pl; this.players[pl].setColors(pl); this.players[pl].starting_territories=this.playerTerr; @@ -434,17 +431,18 @@ function Map(c,r,p,gn) this.generateMap= function() { //RANDOMLY Generate NEW LAND var unused=[]; - for(mi=0;mi<this.total;mi++) unused.push(mi); - randa=random(unused.length); - locationa=unused[randa]; + for(mi=0;mi<this.total;mi++) + unused.push(mi); + var randa=random(unused.length); + var locationa=unused[randa]; this.grid[locationa]=new Territory(locationa); this.used[locationa]=true; unused.splice(randa,1); - for(ms=1;ms<this.mapSize;ms++) { - randb=random(unused.length); - locationb=unused[randb]; - prox=scanProximity(locationb); + for(var ms=1;ms<this.mapSize;ms++) { + var randb=random(unused.length); + var locationb=unused[randb]; + var prox=scanProximity(locationb); if(this.landNearby(prox, this.used)) { this.grid[locationb]=new Territory(locationb); this.used[locationb]=true; @@ -454,12 +452,12 @@ function Map(c,r,p,gn) ms--; } var territories=[]; - for(mt in this.used) + for(var mt in this.used) territories.push(mt); - for(ply in this.players) { + for(var ply in this.players) { for(tt=0;tt < this.playerTerr; tt++) { - rand=random(territories.length); - location=territories[rand]; + var rand=random(territories.length); + var location=territories[rand]; if(this.grid[location].player>=0) tt--; else { @@ -473,8 +471,8 @@ function Map(c,r,p,gn) } this.landNearby= function(proximity) { //CHECK IMMEDIATE AREA FOR LAND - for(px in proximity) { - location=proximity[px]; + for(var px in proximity) { + var location=proximity[px]; if(this.used[location]) return true; } @@ -482,18 +480,20 @@ function Map(c,r,p,gn) } this.placeDice= function(playerNum, numDice) { //RANDOMLY PLACE X NUMBER OF DICE ON PLAYER TERRITORIES - playerNumber=parseInt(playerNum); + var playerNumber=Number(playerNum); this.countDice(playerNumber); - toPlace=numDice; - fulldice=false; - placed=[]; - for(sd=0;sd<numDice;sd++) { - rand=random(this.players[playerNumber].territories.length); - terr=this.players[playerNumber].territories[rand]; - + var toPlace=numDice; + var fulldice=false; + var placed=[]; + for(var sd=0;sd<numDice;sd++) { + var rand=random(this.players[playerNumber].territories.length); + var terr=this.players[playerNumber].territories[rand]; + if(!this.grid[terr]) { + log(LOG_ERROR,"corrupt tile: " + terr); + } if(this.players[playerNumber].totalDice==(this.players[playerNumber].territories.length*this.maxDice)) { fulldice=true; - reserveCap=(30-this.players[playerNumber].reserve); + var reserveCap=(30-this.players[playerNumber].reserve); if(reserveCap>0) { if(reserveCap>=toPlace) this.players[playerNumber].reserve+=toPlace; @@ -519,8 +519,8 @@ function Map(c,r,p,gn) fulldice=true; else { while(this.players[playerNumber].reserve>0) { - rand=random(this.players[playerNumber].territories.length); - terr=this.players[playerNumber].territories[rand]; + var rand=random(this.players[playerNumber].territories.length); + var terr=this.players[playerNumber].territories[rand]; if(this.grid[terr].dice<this.maxDice) { this.grid[terr].dice++; placed.push(terr); @@ -537,14 +537,14 @@ function Map(c,r,p,gn) this.countDice= function(playerNumber) { //COUNT DICE TOTALS FOR EACH PLAYER this.players[playerNumber].totalDice=0; - for(td in this.players[playerNumber].territories) { - terr=this.players[playerNumber].territories[td]; + for(var td in this.players[playerNumber].territories) { + var terr=this.players[playerNumber].territories[td]; this.players[playerNumber].totalDice+=this.grid[terr].dice; } } this.countDiceAll= function() { - for(ppp in this.players) + for(var ppp in this.players) this.countDice(ppp); } this.init= function() diff --git a/xtrn/dicewarz/menu.js b/xtrn/dicewarz/menu.js index afcded589e..0df059cf3e 100644 --- a/xtrn/dicewarz/menu.js +++ b/xtrn/dicewarz/menu.js @@ -20,8 +20,7 @@ function Menu(title,x,y,color,hkey_color) var clear=5; var cleared=0; - for(i in this.items) - { + for(var i in this.items) { if(this.items[i].enabled) { console.gotoxy(orig_x,yyyy); yyyy++; @@ -30,8 +29,7 @@ function Menu(title,x,y,color,hkey_color) cleared++; } } - for(i=cleared;i<clear;i++) - { + for(var i=cleared;i<clear;i++) { console.gotoxy(orig_x,yyyy); yyyy++; console.cleartoeol(); @@ -39,23 +37,20 @@ function Menu(title,x,y,color,hkey_color) } this.disable=function(items) { - for(item in items) - { + for(var item in items) { this.items[items[item]].enabled=false; } } this.enable=function(items) { - for(item in items) - { + for(ivar tem in items) { this.items[items[item]].enabled=true; } } this.add=function(items) { - for(i=0;i<items.length;i++) - { - hotkey=this.getHotKey(items[i]); + for(var i=0;i<items.length;i++) { + var hotkey=this.getHotKey(items[i]); this.items[hotkey]=new MenuItem(items[i],hotkey,color,hkey_color); this.items[hotkey].init(color,hkey_color); } @@ -66,15 +61,14 @@ function Menu(title,x,y,color,hkey_color) } this.getHotKey=function(item) { - keyindex=item.indexOf("~")+1; + var keyindex=item.indexOf("~")+1; return item.charAt(keyindex); } this.displayHorizontal=function() { clearLine(1,48); console.gotoxy(orig_x,orig_y); - for(i in this.items) - { + for(var i in this.items) { if(this.items[i].enabled) console.putmsg(this.items[i].text + " "); } } diff --git a/xtrn/dicewarz/player.js b/xtrn/dicewarz/player.js index 5384de5a07..9c01b052dc 100644 --- a/xtrn/dicewarz/player.js +++ b/xtrn/dicewarz/player.js @@ -20,7 +20,7 @@ function Player(userNumber, vote) } this.removeTerritory=function(territory) { - for(rem in this.territories) { + for(var rem in this.territories) { if(this.territories[rem]==territory) this.territories.splice(rem,1); } @@ -28,7 +28,7 @@ function Player(userNumber, vote) this.countTerritory=function() { var count=0; - for(tt in this.territories) + for(var tt in this.territories) count++; return count; } diff --git a/xtrn/dicewarz/territory.js b/xtrn/dicewarz/territory.js index c577549c58..90a39f2906 100644 --- a/xtrn/dicewarz/territory.js +++ b/xtrn/dicewarz/territory.js @@ -31,13 +31,11 @@ function Territory(location) this.northeast=proximity[3]; this.southwest=proximity[4]; this.southeast=proximity[5]; - if(!data[this.north]) - { + if(!data[this.north]) { if(!data[this.northwest]) this.topLeft="."; if(!data[this.northeast]) this.topRight="."; } - if(!data[this.south]) - { + if(!data[this.south]) { if(!data[this.southwest]) this.bottomleft="`"; if(!data[this.southeast]) this.bottomright="'"; } @@ -51,7 +49,7 @@ function Territory(location) } this.show= function() { //DISPLAY THIS TERRITORY ON THE MAP - display=(this.bfColor + "\xFE"+ blackbg + this.bColor + this.fColor + " " + this.dice + " " + blackbg + this.bfColor + "\xFE"); + var display=(this.bfColor + "\xFE"+ blackbg + this.bColor + this.fColor + " " + this.dice + " " + blackbg + this.bfColor + "\xFE"); console.gotoxy(this.x-1, this.y); console.putmsg(display); } @@ -89,7 +87,7 @@ function Territory(location) { //ASSIGN DISPLAY COORDINATES FOR MAP var startX=sc; var startY=sr; - offset=loc%columns; + var offset=loc%columns; if(offset%2==1) startY++; startX+=(offset*5); startY+=(parseInt(loc/columns)*2); -- GitLab