-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateHomes.js
63 lines (52 loc) · 2.29 KB
/
updateHomes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Insures that each person in the population has up-to-date stats for health, shelter and education
var updateHomes = function(nextTurn) {
/* global MainGame */
var pop = MainGame.population;
var houseList = MainGame.board.findBuilding(null,null,"housing",null);
for(var houseIndex=0;houseIndex<houseList.length;++houseIndex){
var h=MainGame.board.at(houseList[houseIndex]).getBuilding();
if(h.name==="palace"){continue;}
updateHome(houseList[houseIndex]);
}
pop.update(nextTurn);
// Finally, check over all ministers. If they have an impending demotion, flag it now.
var ministers = pop.highList();
for (var i = 0; i < ministers.length; i++) {
var minister = ministers[i];
var home = MainGame.board.at(minister.home).getBuilding();
// Set the alert iff the home does not have the stats to support an Elite.
MainGame.board.at(minister.home).setAlert(home.health < 50 || home.shelter < 50 || home.culture < 50);
}
};
var updateHome = function(houseIndex){
var home = MainGame.board.at(houseIndex).building;
home.health = getEffectOutputInRangeByType(houseIndex, "health");
home.culture = getEffectOutputInRangeByType(houseIndex, "culture");
home.aoeFreedom = getEffectOutputInRangeByType(houseIndex, "freedom");
home.aoeUnrest = getEffectOutputInRangeByType(houseIndex, "unrest");
home.shelter = home.maxShelter;
MainGame.board.at(houseIndex).building=home;
};
var getEffectOutputInRangeByType = function(homeIndex, type) {
var totalOutput = 0;
var allBuildingIndexes = MainGame.board.findBuilding(null, null, null, type);
for (var index=0;index<allBuildingIndexes.length;++index) {
var buildingData = MainGame.board.at(allBuildingIndexes[index]).building;
// If the distance between the two buildings is <= the range of the eduBuilding, accumulate culture
var effectList = buildingData.effects;
for (var effectIndex=0;effectIndex<effectList.length;++effectIndex) {
var thisEffect = effectList[effectIndex];
if (thisEffect.type != type) continue;
if (MainGame.board.distanceOf(homeIndex, allBuildingIndexes[index]) <= thisEffect.range) {
var outPut = thisEffect.outputTable[buildingData.people];
totalOutput += outPut;
}
}
// If we've breached 100%, just stop counting
if (totalOutput >= 100) {
totalOutput = 100;
break;
}
}
return totalOutput;
};