-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcivilian.js
186 lines (161 loc) · 4.51 KB
/
civilian.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* CIVILIAN */
function birthf() {
let total
total = pop * birthRate
if(total < 0) {
pop += Math.ceil(total)
}else {
pop += Math.floor(total)
}
}
//unused
function birthdf(){
if(birthd > 1) {
birthd--
pop++
}
}
function popAmount(x) {
return Math.floor(x * pop)
}
function harvest() {
let total
let event = harvestEvent()
let famAmount = Math.floor(popAmount(arrFarmer[1]) / 6)
let harvested
let reqGoods = famAmount
total = Math.floor(famAmount * 11) * harvestRate
arrFarmer[3] = Math.floor(total * event)
if(arrFarmer[4] > reqGoods && arrFarmer[6] < (popAmount(arrFarmer[1])*10)) {
arrFarmer[4] -= reqGoods
} else{
arrFarmer = buyGoods(reqGoods, arrFarmer)
}
}
function harvestEvent() {
let ch = randomInt(0, 3)
if(ch == 0) {
switch(randomInt(0, 2)) {
case 0:
notif("A flood destroyed most of the field. The people experience harvest failure")
return 0.1
break;
case 1:
notif("Some of the crops can't be harvested due to disease")
return 0.8
break;
case 2:
notif("Good weather makes the crops produce more wheat")
return 1.2
break;
}
}else {
return 1
}
}
function produce() {
let total
let reqMat = Math.floor(popAmount(arrArtisan[1]) * 3)
let remain = invMerchant[2] - reqMat
total = popAmount(arrArtisan[1]) * produceRate
if(arrArtisan[4] > 2000) {
arrArtisan[4] += 0
}else if(arrArtisan[5] < reqMat) {
//if not enough material
if(invMerchant[2] < reqMat && arrArtisan[6] < (popAmount(arrArtisan[1])*10)) {
//if merchant not enough material
arrArtisan = buyMaterial((reqMat - remain), arrArtisan)
arrArtisan[5] += forage((reqMat - remain))
arrArtisan[5] -= reqMat
arrArtisan[4] += total
}else if(invMerchant[2] > reqMat && arrArtisan[6] < (popAmount(arrArtisan[1])*10)) {
arrArtisan = buyMaterial(reqMat, arrArtisan)
arrArtisan[5] -= reqMat
arrArtisan[4] += total
}else if(invMerchant[2] < reqMat && arrArtisan[6] > (popAmount(arrArtisan[1])*10)) {
arrArtisan[5] -= 0
arrArtisan[4] += Math.floor(total / 2)
}else if(invMerchant[2] > reqMat && arrArtisan[6] > (popAmount(arrArtisan[1])*10)) {
arrArtisan[5] -= 0
arrArtisan[4] += Math.floor(total / 2)
}
}else {
arrArtisan[5] -= reqMat
arrArtisan[4] += total
}
}
function gather() {
let gathered
let total
total = popAmount(arrGatherer[1]) * gatherRate
if(arrGatherer[5] > 5000) {
arrGatherer[5] += 0
}else {
arrGatherer[5] += total
}
}
function forage(x) {
let foraged
let min = x
let max = x * 1.2
foraged = randomInt(min, max)
return foraged
}
function eat(arr) {
let liest = arr
let eaten
let remaining
let totalPop = popAmount(arr[1])
let wheatPop = arr[3]
let costBuy
eaten = totalPop * consumRate
remaining = wheatPop - Math.ceil(eaten)
if(remaining < 0) {
outStock = remaining + invMerchant[0]
if(outStock < 0) {
wheatPop += forage(Math.abs(remaining))
wheatPop -= Math.ceil(eaten)
}else if(outStock > 0 && arr[6] < (popAmount(arr[1])*10)){
liest = buyWheat(Math.abs(remaining),arr)
wheatPop -= Math.ceil(eaten)
}else {
wheatPop += forage(Math.abs(remaining))
wheatPop -= Math.ceil(eaten)
}
}else {
wheatPop -= Math.ceil(eaten)
}
liest[3] = wheatPop
return liest
}
//ROT/BREAK
function minGoods(arr) {
let liest = arr
let min = Math.floor(popAmount(arr[1]) / 6) * 10
let amount = Math.floor(invMerchant[1] / 3)
if(arr[4] < min && arr[6] < (popAmount(arr[1])*10)) {
liest = buyGoods(amount, liest)
}
return liest
}
function goodsBreak(arr) {
let liest = arr
let goods = arr[4]
goods -= Math.ceil(goods * 0.01)
liest[4] = goods
return liest
}
function wheatRot(arr) {
let liest = arr
let wheat = arr[3]
wheat -= Math.ceil(wheat * 0.01)
liest[3] = wheat
return liest
}
/* function happiness() {
if(happiness < 3) {
migrate()
}else if(happiness < 1){
revolt()
}
} */