-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjobs.py
435 lines (299 loc) · 12.9 KB
/
jobs.py
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
import copy
import math
import random
import database as d
from conversation import Convo
#not all jobs, but all jobs you can create (not manager, priest)
def all_jobs():
job_list = [Baker, Brewer, Carrier, Farmer, Miller, Lumberjack, Carpenter]
return job_list
class Job(object):
jobType = "Generic_job"
jobVerb = "Genericking"
naturalWage = 0
def __init__(self, slots, business, unit, salary):
# slots is an int, number of employee slots available
equipLength = len(d.getEquipment())
self.slots = slots
self.business = business
self.unit = unit
self.equipment = [0 for equip in range(equipLength)]
self.employees = []
self.salary = salary
self.business.addJob(self)
self.unit.addJob(self)
self.locality = self.unit.getLocality()
self.idlers = []
@property
def name(self):
return self.jobType
def getBusiness(self):
return self.business
def getEquipment(self):
return self.equipment
def getSalary(self):
return self.salary
def getSlots(self):
return self.slots
def getUnit(self):
return self.unit
def getJobType(self):
return self.jobType
def incrementSlots(self):
self.slots += 1
def decrementSlots(self):
self.slots -= 1
def setSlots(self, slots):
self.slots = slots
def getEmployees(self):
return self.employees
def get_emp_dict(self):
empDict = {}
empDict[self] = copy.copy(self.employees)
return empDict
def takeIdlers(self, amount):
if amount != 0:
workers = self.idlers[-amount:]
self.idlers = self.idlers[:-amount]
else:
workers = []
return workers
def resetIdlers(self):
self.idlers = copy.copy(self.employees)
def craft(self, productIndex, amount):
components = d.getComponents(productIndex)
tech = self.unit.getTech(productIndex)
DMClist = self.unit.getDMC()
productDMC = 0
#reduce to components
for component in components:
materialIndex = component[0]
inStock = self.unit.getStock(materialIndex)
ratio = component[1]
enoughFor = inStock / ratio
if amount > (enoughFor):
amount = enoughFor
#DMC
componentDMC = DMClist[materialIndex]
productDMC += componentDMC * ratio
#reduce to available employees
capability = (len(self.idlers) * tech)
if amount > capability:
amount = capability
#take employees from idlers (so they can't do anything else today)
working = math.ceil(amount / tech)
workers = self.takeIdlers(working)
#take components
for component in components:
materialIndex = component[0]
ratio = component[1]
used = amount * ratio
self.unit.addStock(materialIndex, -used)
#add product- goes to stock for assembly lines. Crafted is for natural price calculation.
self.unit.addCrafted(productIndex, amount)
self.unit.addStock(productIndex, amount)
#set product DMC
self.unit.setDMC(productIndex, productDMC)
for craftsman in workers:
craftsman.think("We crafted " + str(amount) + " " + d.getMaterials()[productIndex] + " today.")
def plant(self, productIndex, amount):
product = d.getMaterials()[productIndex]
if d.isInSeason(productIndex, self.business.model.calendar.state):
components = d.getComponents(productIndex)
tech = self.unit.getTech(productIndex)
growing = self.unit.growingPlants(productIndex)
DMClist = self.unit.getDMC()
isEnough = True
productDMC = 0
#subtract already growing
if amount > growing:
amount = amount - growing
isAllPlanted = False
else:
amount = 0
isAllPlanted = True
#plant
if not isAllPlanted:
#reduce to components
for component in components:
materialIndex = component[0]
inStock = self.unit.getStock(materialIndex)
ratio = component[1]
enoughFor = inStock / ratio
if amount > (enoughFor):
amount = enoughFor
isEnough = False
#DMC
componentDMC = DMClist[materialIndex]
productDMC += componentDMC * ratio
#reduce to employees
capability = (len(self.idlers) * tech)
if amount > capability:
amount = capability
#take employees from idlers (so they can't do anything else today)
working = math.ceil(amount / tech)
workers = self.takeIdlers(working)
#take components
for component in components:
materialIndex = component[0]
ratio = component[1]
used = amount * ratio
self.unit.addStock(materialIndex, -used)
#add product- goes to stock for assembly lines. Crafted is for natural price calculation.
self.unit.plantSeeds(productIndex, amount)
self.unit.addPlanted(productIndex, amount)
#set product DMC
self.unit.setDMC(productIndex, productDMC)
for farmer in workers:
if not isEnough:
farmer.think("We ran out of materials for " + product + " at work today.")
farmer.think("We planted " + str(amount) + " " + product + " today.")
else:
for farmer in self.getEmployees():
farmer.think("We've already planted enough " + product + " for the season.")
else:
for farmer in self.getEmployees():
farmer.think("It's not the planting season for " + product + ".")
def harvest(self, productIndex):
tech = self.unit.getTech(productIndex)
product = d.getMaterials()[productIndex]
amount = (len(self.idlers) * tech)
ripe = self.unit.ripePlants(productIndex)
if amount > ripe:
amount = ripe
#take employees from idlers (so they can't do anything else today)
working = math.ceil(amount / tech)
workers = self.takeIdlers(working)
self.unit.harvest(productIndex, amount)
self.unit.addHarvested(productIndex, amount)
for farmer in workers:
farmer.think("We harvested " + str(amount) + " " + product + " today.")
class Baker(Job):
jobType = "Baker"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addCraftingJob(self)
class Brewer(Job):
jobType = "Brewer"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addCraftingJob(self)
class Carrier(Job):
jobType = "Porter"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
# takes from unit1 output[] and places in unit2 stock[]
def transportMats(self, unit1, unit2, materialIndex, amount):
business1 = unit1.getBusiness()
business2 = unit2.getBusiness()
amountInStock = unit1.getStock(materialIndex)
isTransport = False
#transport
if (business1 == self.business):
if (business2 == self.business):
if (amount > amountInStock):
unit1.addFailTransports(materialIndex, amount - amountInStock)
amount = amountInStock
if amount > 0:
#DMC is the FULL natural price of the material, not just its DMC- it's the DMC of products MADE FROM this material.
#we want natural price because we don't care about supply and demand within businesses.
DMC = unit1.priceCalc(materialIndex)[2]
unit2.setDMC(materialIndex, DMC)
unit1.addTransports(materialIndex, amount)
unit2.addPurchase(materialIndex, amount)
#transport
unit1.addStock(materialIndex, -amount)
unit2.addStock(materialIndex, amount)
isTransport = True
#thoughts
for employee in self.getEmployees():
if isTransport == True:
employee.think("I carried " + str(amount) + " things today.")
else:
employee.think("My boss sent me on a wild goose chase today.")
return isTransport
class Farmer(Job):
jobType = "Farmer"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addCraftingJob(self)
# self.business.addHarvestJob(self)
class Owner(Job):
jobType = "Job Creator"
def __init__(self, business, unit):
Job.__init__(self, 1, business, unit, salary=6)
class Manager(Job):
jobType = "Manager"
def __init__(self, business, unit, salary):
Job.__init__(self, 1, business, unit, salary)
# takes from theUnit stock[] and places in theUnit output[], filling outupt[] up to amount.
def transferMats(self, theUnit, materialIndex, amount):
ourBusiness = self.getUnit().getBusiness()
business = theUnit.getBusiness()
isTransfer = False
if len(self.employees) > 0:
manager = self.employees[0]
if (amount > theUnit.getStock(materialIndex)):
amount = theUnit.getStock(materialIndex)
if amount > theUnit.getOutput(materialIndex):
amount -= theUnit.getOutput(materialIndex)
else:
amount = 0
theUnit.addStock(materialIndex, -amount)
theUnit.addOutput(materialIndex, amount)
isTransfer = True
#thoughts
if isTransfer:
if amount != 0:
manager.think("I transfered " + str(amount) + " " + d.materialsList[materialIndex] + " to " + theUnit.name + "'s output.")
else:
manager.think("My employees didn't have the " + d.materialsList[materialIndex] + " ready when I needed it.")
else:
manager.think("I can't transfer goods at " + str(theUnit) + ". Strange...")
else:
amount = 0
return amount
def updatePrices(self, jobUnit):
if jobUnit.business == self.business:
jobUnit.priceGen()
class Miller(Job):
jobType = "Miller"
jobVerb = "Milling"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addCraftingJob(self)
class Lumberjack(Job):
jobType = "Lumberjack"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addHarvestJob(self)
class Carpenter(Job):
jobType = "Carpenter"
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addCraftingJob(self)
#religious jobs
class Priest(Job):
jobType = 'Priest'
def __init__(self, slots, business, unit, salary):
Job.__init__(self, slots, business, unit, salary)
self.business.addPriestJob(self)
def service(self):
attendance = self.unit.getAttendance()
approvedSongs = self.unit.getReligion().getSongs()
song = random.choice(approvedSongs)
#pray
for congregant in attendance:
congregant.think("I love " + song + "!")
congregant.think("The service at " + self.unit.name + " was beautiful.")
#talk
self.mingle()
#go home
self.unit.resetAttendance()
def mingle(self):
attendance = self.unit.getAttendance()
for congregant in attendance:
i = random.randrange(len(attendance))
conversee = attendance[i]
if conversee is not congregant:
Convo.beginConversation(congregant, conversee)