Apply useful maps

Maps cost! Let's apply them where necessary.
World.testMap() checks if there's still something to explore.
World.seenAll is true when everything has been seen. It is updated by uncoverMap().
World.applyMap() chooses a random center, with the conditions that 

1. there's still something to explore
1. the center itself is an undiscovered area.

Buy Map is active only when a map is still useful.
This commit is contained in:
Andrea Rendine
2016-02-14 15:47:38 +01:00
parent f1656f9a4f
commit bee221093e
+29 -3
View File
@@ -162,6 +162,9 @@ var World = {
// compass tooltip text
Room.compassTooltip(World.dir);
// Check if everything has been seen
World.seenAll = World.testMap();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(World.handleStateUpdates);
},
@@ -615,12 +618,35 @@ var World = {
}
}
}
World.seenAll = World.testMap();
},
testMap: function() {
var dark;
if(!World.seenAll) {
var mask = $SM.get('game.world.mask');
loop:
for(var i = 0; i < mask.length; i++) {
for(var j = 0; j < mask[i].length; j++) {
if(!mask[i][j]) {
dark = true;
break loop;
}
}
}
}
return !dark;
},
applyMap: function() {
var x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
var y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
World.uncoverMap(x, y, 5, $SM.get('game.world.mask'));
if(!World.seenAll){
var x,y,mask = $SM.get('game.world.mask');
do {
x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
} while (mask[x][y]);
World.uncoverMap(x, y, 5, mask);
}
},
generateMap: function() {