From f1656f9a4f9f470ac7e9e1a563f5c20bfa210b49 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sun, 14 Feb 2016 13:46:26 +0100 Subject: [PATCH 1/5] Buy map when needed Maps cost! And casual gamers could possibly forget whether they've explored everything. The Buy map button is now disabled if the whole map has been seen (yes, even a single uncovered tile is enough). --- script/events/room.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/script/events/room.js b/script/events/room.js index 9a503df..32f766a 100644 --- a/script/events/room.js +++ b/script/events/room.js @@ -433,6 +433,20 @@ Events.Room = [ 'buyMap': { text: _('buy map'), cost: { 'fur': 200, 'scales': 10 }, + available: function() { + var mask = $SM.get('game.world.mask'); + var dark = false; + 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; + }, notification: _('the map uncovers a bit of the world'), onChoose: World.applyMap }, From bee221093ed90eefbaa31f056ab04ad4349e92a7 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sun, 14 Feb 2016 15:47:38 +0100 Subject: [PATCH 2/5] 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() { From 3b66f5cad5bca107e4b1b8d749eb27a3b90aff29 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sun, 14 Feb 2016 15:54:59 +0100 Subject: [PATCH 3/5] Buy map when needed Buy map button availability depends on the fact that there are still unexplored parts of the map. --- script/events/room.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/script/events/room.js b/script/events/room.js index 32f766a..6710b25 100644 --- a/script/events/room.js +++ b/script/events/room.js @@ -434,18 +434,7 @@ Events.Room = [ text: _('buy map'), cost: { 'fur': 200, 'scales': 10 }, available: function() { - var mask = $SM.get('game.world.mask'); - var dark = false; - 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; + return !World.seenAll; }, notification: _('the map uncovers a bit of the world'), onChoose: World.applyMap From 28cdca600316bed3d017e3f5f5dca1a6efa49212 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sun, 14 Feb 2016 16:09:15 +0100 Subject: [PATCH 4/5] Update world map on return World.seenAll must be updated only when committing state changes (i.e., on return home safe), not during exploration. --- script/world.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/world.js b/script/world.js index b36f93f..e97302d 100644 --- a/script/world.js +++ b/script/world.js @@ -618,7 +618,6 @@ var World = { } } } - World.seenAll = World.testMap(); }, testMap: function() { @@ -898,6 +897,8 @@ var World = { goHome: function() { // Home safe! Commit the changes. $SM.setM('game.world', World.state); + World.seenAll = World.testMap(); + if(World.state.sulphurmine && $SM.get('game.buildings["sulphur mine"]', true) === 0) { $SM.add('game.buildings["sulphur mine"]', 1); Engine.event('progress', 'sulphur mine'); From a3b1fea4243bd4371be02ba56a1fa92cc116436a Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Sat, 20 Feb 2016 13:17:45 +0100 Subject: [PATCH 5/5] Method and property fix World.testMap() sets World.seenAll. The latter is true when the whole map has been explored. World.testMap() is called: * on world init * on return home (when the map is updated) * on applyMap() (when the map is bought from the scout) --- script/world.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/script/world.js b/script/world.js index e97302d..df99fd6 100644 --- a/script/world.js +++ b/script/world.js @@ -163,7 +163,7 @@ var World = { Room.compassTooltip(World.dir); // Check if everything has been seen - World.seenAll = World.testMap(); + World.testMap(); //subscribe to stateUpdates $.Dispatch('stateUpdate').subscribe(World.handleStateUpdates); @@ -621,8 +621,8 @@ var World = { }, testMap: function() { - var dark; if(!World.seenAll) { + var dark; var mask = $SM.get('game.world.mask'); loop: for(var i = 0; i < mask.length; i++) { @@ -633,8 +633,8 @@ var World = { } } } + World.seenAll = !dark; } - return !dark; }, applyMap: function() { @@ -646,6 +646,7 @@ var World = { } while (mask[x][y]); World.uncoverMap(x, y, 5, mask); } + World.testMap(); }, generateMap: function() { @@ -897,7 +898,7 @@ var World = { goHome: function() { // Home safe! Commit the changes. $SM.setM('game.world', World.state); - World.seenAll = World.testMap(); + World.testMap(); if(World.state.sulphurmine && $SM.get('game.buildings["sulphur mine"]', true) === 0) { $SM.add('game.buildings["sulphur mine"]', 1);