From bee221093ed90eefbaa31f056ab04ad4349e92a7 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sun, 14 Feb 2016 15:47:38 +0100 Subject: [PATCH] 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. --- script/world.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/script/world.js b/script/world.js index f0f21d9..b36f93f 100644 --- a/script/world.js +++ b/script/world.js @@ -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() {