/
building_info.py
509 lines (418 loc) · 13.8 KB
/
building_info.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
from __future__ import division
import random
from random import randint as roll
import libtcodpy as libtcod
import config as g
BUILDING_INFO = {
'tomb':{'cons materials': 500},
'bowyer':{'cons materials': 100},
'barracks':{'cons materials': 200},
'stable':{'cons materials': 200},
'weaponsmith':{'cons materials': 200},
'armorer':{'cons materials': 200},
'hideout':{'cons materials': 30}
}
class Building:
'''A building'''
def __init__(self, zone, type_, template, site, construction_material, professions, inhabitants, tax_status, wx, wy, constructed=1):
self.zone = zone
self.template = template
self.type_ = type_
self.name = type_
self.site = site
self.construction_material = construction_material
self.wx = wx
self.wy = wy
self.cost_to_build = BUILDING_INFO[self.type_] if self.type_ in BUILDING_INFO else {}
self.linked_economy_agent = None
self.professions = []
self.inhabitants = []
self.tax_staus = tax_status
for profession in professions:
self.add_profession(profession)
for inhabitant in inhabitants:
self.add_inhabitant(inhabitant)
self.constructed = constructed
self.current_workers = []
self.physical_property = []
self.housed_objects = []
# Garrison consists of armies
self.garrison = []
self.captives = []
self.add_building_to_map_func = 'will be implemented at some point'
self.add_building_to_map_args = []
self.set_name()
def add_housed_object(self, obj):
self.housed_objects.append(obj)
def remove_housed_object(self, obj):
self.housed_objects.remove(obj)
def add_inhabitant(self, inhabitant):
inhabitant.creature.house = self
self.inhabitants.append(inhabitant)
def remove_inhabitant(self, figure):
figure.creature.house = None
self.inhabitants.remove(figure)
def add_housed_objects_to_map(self):
''' will be expanded later? '''
for obj in self.housed_objects:
self.place_within(obj)
def place_within(self, obj):
## Place an object within the building
if not self.physical_property:
print self.get_name(), 'has no physical property!'
return
# Choose a tile that is not blocked
while 1:
x, y = random.choice(self.physical_property)
if not g.M.tiles[x][y].blocks_mov:
break
g.M.add_object_to_map(x=x, y=y, obj=obj)
def set_name(self):
if self.type_ == 'Tavern':
num = roll(1, 5)
if num == 1:
front = 'The {0} {1}'.format(random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS))
ending = random.choice(['', '', '', ' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn'])
elif num == 2:
front = 'The {0}\'s {1}'.format(random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS))
ending = ''
elif num == 3:
front = '{0}\'s {1}'.format(random.choice(g.TAVERN_NOUNS), random.choice(g.TAVERN_OBJECTS))
ending = random.choice([' Inn', ' Tavern', ' Tavern', ' Lodge', ' Bar and Inn'])
elif num == 4:
front = '{0}\'s {1}'.format(self.site.name, random.choice(g.TAVERN_OBJECTS))
ending = ''
elif num == 5:
front = 'The {0} of the {1} {2}'.format(random.choice(('Inn', 'Tavern', 'Lodge')), random.choice(g.TAVERN_ADJECTIVES), random.choice(g.TAVERN_NOUNS))
ending = ''
self.name = front + ending
def get_name(self):
return self.name
def add_worker(self, worker):
self.current_workers.append(worker)
worker.creature.profession.current_work_building = self
def remove_worker(self, worker):
self.current_workers.remove(worker)
worker.creature.profession.current_work_building = None
def add_profession(self, profession):
profession.building = self
profession.current_work_building = self
self.professions.append(profession)
def fill_position(self, profession):
# Give temples and nobles and stuff an initial dynasty to begin with
potential_employees = [figure for figure in g.WORLD.tiles[self.site.x][self.site.y].entities if
figure.creature.profession is None and figure.creature.sex == 1 and figure.creature.get_age() > g.MIN_MARRIAGE_AGE]
# Mostly try to use existing folks to fill the position
if not profession.name in ('Assassin', ) and len(potential_employees) > 0:
human = random.choice(potential_employees)
# Otherwise, create a new person
else:
born = g.WORLD.time_cycle.years_ago(roll(18, 40))
human = self.site.create_inhabitant(sex=1, born=born, dynasty=None, important=0, house=None)
## Actually give profession to the person ##
profession.give_profession_to(human)
def fill_initial_positions(self):
for profession in self.professions:
self.fill_position(profession)
def add_building_to_map(self, *args):
# Find an ok center point
building_center = (roll(50, 100), roll(50, 100))
building_size = (roll(15, 20), roll(15, 20))
'''
## Make a nice rectangle, with walls at the corners
for q in xrange(building_center[0], building_center[0] + building_size[0] + 1):
for r in xrange(building_center[1], building_center[1] + building_size[1] + 1):
g.M.tiles[q][r].building = self
self.physical_property.append((q, r))
## Add wall or floor
if q in [building_center[0], building_center[0] + building_size[0]] or r in [building_center[1], building_center[1] + building_size[1]]:
g.M.tiles[q][r].make_wall(libtcod.darkest_grey)
else:
g.M.tiles[q][r].make_floor(floor_type='dirt')
door_coords = (int(building_center[0] + (building_size[0] / 2)), building_center[1] + building_size[1])
g.M.make_door(x=door_coords[0], y=door_coords[1], floor_type='dirt')
'''
bx, by = building_center[0], building_center[1]
for i, row in enumerate(BUILDINGS[self.template]):
for j, tile in enumerate(row):
x, y = bx+j, by+i
self.physical_property.append((x, y))
if tile == '#':
g.M.tiles[x][y].make_wall(libtcod.darkest_grey)
elif tile == ' ':
g.M.tiles[x][y].make_floor(floor_type='stone')
elif tile in ('d', '-'):
g.M.make_door(x=x, y=y, floor_type='stone')
def add_building_from_rect_lot(self, rect, building_color, floor, door_dir):
w, h = rect.x2-rect.x1, rect.y2-rect.y1
if (w, h) in BUILDINGS[self.type_]:
bx, by = rect.x1, rect.y1
template = random.choice(BUILDINGS['houses'][(w, h)])
for i, row in enumerate(template):
for j, tile in enumerate(row):
x, y = bx+j, by+i
self.physical_property.append((x, y))
if tile == '#':
g.M.tiles[x][y].make_wall(libtcod.darkest_sepia)
elif tile == ' ':
g.M.tiles[x][y].make_floor(floor_type='dirt')
elif tile in ('d', '-'):
g.M.make_door(x=x, y=y, floor_type='dirt')
else:
for x in xrange(rect.x1, rect.x2 + 1):
for y in xrange(rect.y1, rect.y2 + 1):
self.physical_property.append((x, y))
self.usemap.tiles[x][y].building = self
if x in (rect.x1, rect.x2) or y in (rect.y1, rect.y2):
self.usemap.tiles[x][y].make_wall(building_color)
else:
self.usemap.tiles[x][y].make_floor(floor_type=floor)
def add_physical_property_rect(self, physical_property_rect):
for x in xrange(physical_property_rect.x1, physical_property_rect.x2 + 1):
for y in xrange(physical_property_rect.y1, physical_property_rect.y2 + 1):
self.physical_property.append((x, y))
g.M.tiles[x][y].building = self
def create_door_and_outside_road(self, rect, door_dir):
pass
'''
b - bedroom
c - closet
d - den
D - dormitory
h - hallway
j - jail
k - kitchen
l - library
p - pantry
r = recreation
'''
BUILDINGS = {'house':{}, 'shop':{}}
BUILDINGS['TEST'] = [
'###############',
'# # #',
'# # #',
'# # #',
'# # #',
'# # #',
'# # #',
'###-######-##########',
'# # #',
'# # #',
'# # #',
'# - #',
'# # #',
'# # #',
'# # #',
'# # #',
'# # #',
'#################d###'
]
BUILDINGS['temple1'] = [
'##################################################',
'# # #',
'# # #',
'# # # # #',
'# # #',
'# # #',
'# # #',
'# # # # ####',
'# # #',
'# # #',
'# # #',
'# - # # #',
'# # #',
'# # #',
'# # #',
'# # ####',
'# # #',
'############### ###########',
'# # # #',
'# # # #',
'# # # #',
'# - ###### #',
'# # # ####',
'# # - #',
'###-#### # # #',
'# # ################-#-########-#####',
'# # # # # #',
'# ###-#### #',
'# - # # # #',
'# # #',
'# # # # # ####',
'# # #',
'# # # # # #',
'# - #',
'# # # # # #',
'# # #',
'###-######-#### # # # ####',
'# # #',
'# # # # # #',
'# # #',
'# - # # # #',
'# # #',
'# # # # # #',
'# # #',
'# ######### ###########',
'# # # # #',
'############### # # #',
'# # # # # #',
'# # ######### # #',
'# # # # #',
'# # # ###### #',
'# ####-### # ####',
'# # - #',
'###-#### # #',
'# ############ ##d## #',
'# # # # #',
'# # # # #',
'# - # # #',
'# # ########### #############',
'# # #',
'# # #',
'# # #',
'# # #',
'#################d###'
]
BUILDINGS['house'][(6, 6)] = [
[
'#####.',
'# ##',
'# #',
'##-###',
'# #',
'# #',
'##d###'
],
[
'.####.',
'## ##',
'# #',
'# #',
'# #',
'## ##',
'.#d##.'
],
[
'######',
'# #',
'# #',
'# ###',
'# #',
'## ##',
'.#d##.'
]
]
BUILDINGS['house'][(7, 7)] = [
[
'#######',
'# # #',
'# # #',
'##-##-#',
'# #',
'# #',
'# #',
'##d####'
],
[
'#######',
'# #',
'# #',
'##-####',
'# # #',
'# - #',
'# # #',
'##d####'
],
[
'...####',
'#### #',
'# #',
'##-####',
'# #',
'# #',
'# #',
'##d####'
]
]
BUILDINGS['house'][(8, 8)] = [
[
'########',
'# # #',
'# # #',
'##-## #',
'# # #',
'# ##-#',
'# #',
'# #',
'####d###'
],
[
'########',
'# # #',
'# # #',
'##-## #',
'# - #',
'# #####',
'# - #',
'# # #',
'########'
],
[
'#####...',
'# #...',
'# ####',
'##-## #',
'# - #',
'# ####',
'# #',
'# #',
'####d###'
]
]
BUILDINGS['house'][(12, 12)] = [
[
'############',
'# # #',
'# - #',
'# ######',
'# - #',
'# # #',
'# ########',
'##-## #',
'# # #',
'# ##-#####',
'# #',
'# ##',
'####d###'
],
[
'############',
'# # #',
'# # #',
'##-# #',
'# #',
'##-####-####',
'# # #',
'##### ####',
'.# - #',
'.# ####',
'.# #',
'.# #',
'.####d####'
],
[
'.##########.',
'.# # #.',
'.# # #.',
'.##-###-###.',
'.# #.',
'.# #####',
'.# # #',
'.#### #',
'.# #',
'.# #####',
'.# #',
'.# #',
'.####d####'
]
]