mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 08:11:54 +08:00
function for fire hut event and more
Effect of hut fire is associated with new Outside method .destroyHuts().
This commit is contained in:
committed by
Blake Grotewold
parent
09c070adfa
commit
cb717b41d0
@@ -79,10 +79,7 @@ Events.Outside = [
|
||||
notification: _('a fire has started'),
|
||||
blink: true,
|
||||
onLoad: function() {
|
||||
var population = $SM.get('game.population', true);
|
||||
var huts = $SM.get('game.buildings["hut"]', true);
|
||||
$SM.set('game.buildings["hut"]', (huts - 1));
|
||||
Outside.killVillagers(4);
|
||||
Outside.destroyHuts(1);
|
||||
},
|
||||
buttons: {
|
||||
'mourn': {
|
||||
|
||||
+32
-1
@@ -8,6 +8,7 @@ var Outside = {
|
||||
_GATHER_DELAY: 60,
|
||||
_TRAPS_DELAY: 90,
|
||||
_POP_DELAY: [0.5, 3],
|
||||
_HUT_ROOM: 4,
|
||||
|
||||
_INCOME: {
|
||||
'gatherer': {
|
||||
@@ -173,7 +174,7 @@ var Outside = {
|
||||
},
|
||||
|
||||
getMaxPopulation: function() {
|
||||
return $SM.get('game.buildings["hut"]', true) * 4;
|
||||
return $SM.get('game.buildings["hut"]', true) * Outside._HUT_ROOM;
|
||||
},
|
||||
|
||||
increasePopulation: function() {
|
||||
@@ -219,6 +220,36 @@ var Outside = {
|
||||
}
|
||||
},
|
||||
|
||||
destroyHuts: function(num, allowEmpty) {
|
||||
var dead = 0;
|
||||
for(var i = 0; i < num; i++){
|
||||
var population = $SM.get('game.population', true);
|
||||
var rate = population / Outside._HUT_ROOM;
|
||||
var full = Math.floor(rate);
|
||||
// by default this is used to destroy full or half-full huts
|
||||
// pass allowEmpty to include empty huts in the armageddon
|
||||
var huts = (allowEmpty) ? $SM.get('game.buildings["hut"]', true) : Math.ceil(rate);
|
||||
if(!huts) {
|
||||
break;
|
||||
}
|
||||
// random can be 0 but not 1; however, 0 as a target is useless
|
||||
var target = Math.floor(Math.random() * huts) + 1;
|
||||
var inhabitants = 0;
|
||||
if(target <= full){
|
||||
inhabitants = Outside._HUT_ROOM;
|
||||
} else if(target == full + 1){
|
||||
inhabitants = population % Outside._HUT_ROOM;
|
||||
}
|
||||
$SM.set('game.buildings["hut"]', ($SM.get('game.buildings["hut"]') - 1));
|
||||
if(inhabitants){
|
||||
Outside.killVillagers(inhabitants);
|
||||
dead += inhabitants;
|
||||
}
|
||||
}
|
||||
// this method returns the total number of victims, for further actions
|
||||
return dead;
|
||||
},
|
||||
|
||||
schedulePopIncrease: function() {
|
||||
var nextIncrease = Math.floor(Math.random()*(Outside._POP_DELAY[1] - Outside._POP_DELAY[0])) + Outside._POP_DELAY[0];
|
||||
Engine.log('next population increase scheduled in ' + nextIncrease + ' minutes');
|
||||
|
||||
Reference in New Issue
Block a user