Mercurial > rinkhals
annotate gamelib/buildings.py @ 413:bdc4757e0497
Add Sniper Rifle and give guns limited ammunition.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 12:07:01 +0000 |
parents | 532f1ea476ff |
children | 9096c237928c |
rev | line source |
---|---|
43 | 1 """Classes for various buildings in the game.""" |
2 | |
3 from pgu.vid import Sprite | |
204 | 4 from pygame.locals import SRCALPHA |
5 import pygame | |
43 | 6 |
7 import imagecache | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
8 import tiles |
204 | 9 import constants |
10 | |
231
857040b211d5
Note why we're disabling a warning.
Simon Cross <hodgestar@gmail.com>
parents:
224
diff
changeset
|
11 # ignore os.popen3 warning generated by pygame.font.SysFont |
204 | 12 import warnings |
13 warnings.filterwarnings("ignore", "os.popen3 is deprecated.") | |
43 | 14 |
125 | 15 class Place(object): |
16 """Space within a building that can be occupied.""" | |
17 | |
18 def __init__(self, building, offset): | |
19 self.occupant = None | |
20 self.building = building | |
21 self.offset = offset | |
22 | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
23 def set_occupant(self, occupant, _update=True, _predator=False): |
204 | 24 self.clear_occupant(_update=False) |
125 | 25 self.occupant = occupant |
26 self.occupant.abode = self | |
204 | 27 if _update: |
28 self.building.update_occupant_count() | |
125 | 29 |
204 | 30 def clear_occupant(self, _update=True): |
125 | 31 if self.occupant is not None: |
32 self.occupant.abode = None | |
33 self.occupant = None | |
204 | 34 if _update: |
35 self.building.update_occupant_count() | |
125 | 36 |
37 def get_pos(self): | |
38 bpos = self.building.pos | |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
39 return (bpos[0] + self.offset[0], bpos[1] + self.offset[1], |
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
40 self.offset[2]) |
125 | 41 |
42 class Floor(object): | |
43 """A set of places within a building. Places on a | |
44 floor are organised into rows and columns. | |
45 """ | |
46 | |
47 def __init__(self, title, places): | |
48 self.title = title # str | |
49 self.places = places # list of lists of places | |
50 | |
51 def rows(self): | |
52 for row in self.places: | |
53 yield row | |
54 | |
55 def width(self): | |
56 return max(len(row) for row in self.places) | |
57 | |
58 class BuildingFullError(Exception): | |
59 pass | |
60 | |
43 | 61 class Building(Sprite): |
62 """Base class for buildings""" | |
63 | |
109
48019afde338
Equipment purchasing and some toolbar tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
64 IS_BUILDING = True |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
65 GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
66 MODIFY_KNIFE_RANGE = lambda s, x: 0 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
67 MODIFY_GUN_RANGE = lambda s, x: -1 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
68 BREAKABLE = False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
69 ABODE = False |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
70 FLOORS = None |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
71 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
72 def __init__(self, pos): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
73 """Initial image, tile vid position, size and tile number for building.""" |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
74 self._set_images() |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
75 self.pos = pos |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
76 self.size = self.SIZE |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
77 self.tile_no = self.TILE_NO |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
78 self._buy_price = self.BUY_PRICE |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
79 self._sell_price = self.SELL_PRICE |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
80 self._repair_price = getattr(self, 'REPAIR_PRICE', None) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
81 self._sun_on = True |
204 | 82 self._font = pygame.font.SysFont('Vera', 30, bold=True) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
83 self._font_image = pygame.Surface(self.images['fixed']['day'].get_size(), flags=SRCALPHA) |
204 | 84 self._font_image.fill((0, 0, 0, 0)) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
85 self._broken = False |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
86 self._predators = [] |
125 | 87 |
88 self._floors = [] | |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
89 if self.FLOORS: |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
90 for f, z in enumerate(self.FLOORS): |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
91 places = [] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
92 for j in range(self.size[1]): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
93 row = [] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
94 for i in range(self.size[0]): |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
95 row.append(Place(self, (i, j, z))) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
96 places.append(row) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
97 floor = Floor("Floor %s" % (f+1,), places) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
98 self._floors.append(floor) |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
99 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
100 # 0: the main image |
204 | 101 # 1: above, -1: below |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
102 self.draw_stack = {"main": (0, self.images['fixed']['day'])} |
204 | 103 |
43 | 104 # Create the building somewhere far off screen |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
105 Sprite.__init__(self, self.images['fixed']['day'], (-1000, -1000)) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
106 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
107 def _set_images(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
108 self.images = {'fixed': { |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
109 'day': imagecache.load_image(self.IMAGE), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
110 'night': imagecache.load_image(self.IMAGE, ('night',)), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
111 'selected': imagecache.load_image(self.SELECTED_IMAGE), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
112 }} |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
113 if self.BREAKABLE: |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
114 self.images['broken'] = { |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
115 'day': imagecache.load_image(self.IMAGE_BROKEN), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
116 'night': imagecache.load_image(self.IMAGE_BROKEN, ('night',)), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
117 'selected': imagecache.load_image(self.SELECTED_IMAGE_BROKEN), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
118 } |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
119 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
120 def _set_main_image(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
121 image_set = self.images[{True: 'broken',False: 'fixed'}[self._broken]] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
122 self._replace_main(image_set[{True: 'day', False: 'night'}[self._sun_on]]) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
123 |
204 | 124 def _redraw(self): |
125 items = self.draw_stack.values() | |
126 items.sort(key=lambda x: x[0]) | |
127 image = items.pop(0)[1].copy() | |
128 for _lvl, overlay in items: | |
129 image.blit(overlay, (0, 0)) | |
130 self.setimage(image) | |
131 | |
132 def _replace_main(self, new_main): | |
133 self.draw_stack["main"] = (0, new_main) | |
134 self._redraw() | |
135 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
136 def tile_positions(self): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
137 """Return pairs of (x, y) tile positions for each of the tile positions |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
138 occupied by the building. |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
139 """ |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
140 xpos, ypos = self.pos |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
141 xsize, ysize = self.size |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
142 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
143 for dx in xrange(xsize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
144 for dy in xrange(ysize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
145 yield (xpos + dx, ypos + dy) |
43 | 146 |
224
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
147 def adjacent_tiles(self): |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
148 """Return pairs of (x, y) tile positions for each of the tiles |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
149 adjacent to the building. |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
150 """ |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
151 xpos, ypos = self.pos |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
152 xsize, ysize = self.size |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
153 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
154 for dx in xrange(xsize): # top and bottom |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
155 yield (xpos + dx, ypos - 1) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
156 yield (xpos + dx, ypos + ysize) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
157 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
158 for dy in xrange(ysize): # left and right |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
159 yield (xpos - 1, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
160 yield (xpos + xsize, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
161 |
43 | 162 def loop(self, tv, _sprite): |
163 ppos = tv.tile_to_view(self.pos) | |
164 self.rect.x = ppos[0] | |
165 self.rect.y = ppos[1] | |
166 | |
167 def move(self, state): | |
168 """Given the game state, return a new position for the object""" | |
169 # Default is not to move | |
170 return self.pos | |
171 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
172 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
173 """Check that the building can be placed at its current position |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
174 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
175 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
176 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
177 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
178 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
179 return False |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
180 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
181 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
182 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
183 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
184 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
185 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
186 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
187 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
188 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
189 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
190 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
191 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
192 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
193 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
194 def broken(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
195 return self._broken |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
196 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
197 def damage(self, tv): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
198 if not self.BREAKABLE: |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
199 return False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
200 self._broken = True |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
201 self._sell_price = self.SELL_PRICE_BROKEN |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
202 self.tile_no = self.TILE_NO_BROKEN |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
203 for tile_pos in self.tile_positions(): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
204 tv.set(tile_pos, self.tile_no) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
205 self._set_main_image() |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
206 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
207 def repair(self, tv): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
208 self._broken = False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
209 self._sell_price = self.SELL_PRICE |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
210 self.tile_no = self.TILE_NO |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
211 for tile_pos in self.tile_positions(): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
212 tv.set(tile_pos, self.tile_no) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
213 self._set_main_image() |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
214 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
215 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
216 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
217 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
218 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
219 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
220 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
221 def buy_price(self): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
222 return self._buy_price |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
223 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
224 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
225 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
226 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
227 def repair_price(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
228 return self._repair_price |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
229 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
230 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
231 if selected: |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
232 self._replace_main(self.images[{True: 'broken',False: 'fixed'}[self._broken]]['selected']) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
233 else: |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
234 self._set_main_image() |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
235 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
236 def sun(self, sun_on): |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
237 self._sun_on = sun_on |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
238 self._set_main_image() |
204 | 239 |
240 def update_occupant_count(self): | |
241 count = len(list(self.occupants())) | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
242 if count == 0 and not self._predators: |
204 | 243 if "count" in self.draw_stack: |
244 del self.draw_stack["count"] | |
245 else: | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
246 # Render chicken count |
204 | 247 image = self._font_image.copy() |
248 w, h = image.get_size() | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
249 if count: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
250 text = self._font.render(str(count), True, |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
251 constants.FG_COLOR) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
252 # Blit to the right |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
253 x, y = text.get_size() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
254 image.blit(text, (w - x, h - y)) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
255 # Render predator count |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
256 if self._predators: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
257 text = self._font.render(str(len(self._predators)), True, |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
258 constants.PREDATOR_COUNT_COLOR) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
259 # Blit to the left |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
260 x, y = text.get_size() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
261 image.blit(text, (0, h - y)) |
204 | 262 self.draw_stack["count"] = (1, image) |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
263 |
204 | 264 self._redraw() |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
265 |
125 | 266 def floors(self): |
267 return self._floors | |
268 | |
269 def places(self): | |
270 for floor in self._floors: | |
271 for row in floor.rows(): | |
272 for place in row: | |
273 yield place | |
274 | |
275 def max_floor_width(self): | |
276 return max(floor.width() for floor in self._floors) | |
277 | |
278 def first_empty_place(self): | |
279 for place in self.places(): | |
280 if place.occupant is None: | |
281 return place | |
282 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
283 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
284 def add_occupant(self, occupant): |
125 | 285 place = self.first_empty_place() |
286 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
287 |
125 | 288 def occupants(self): |
289 for place in self.places(): | |
290 if place.occupant is not None: | |
291 yield place.occupant | |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
292 |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
293 def add_predator(self, animal): |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
294 animal.building = self |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
295 self._predators.append(animal) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
296 self.update_occupant_count() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
297 |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
298 def remove_predator(self, animal): |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
299 if animal in self._predators: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
300 self._predators.remove(animal) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
301 animal.building = None |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
302 self.update_occupant_count() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
303 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
304 class Abode(Building): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
305 ABODE = True |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
306 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
307 class HenHouse(Abode): |
43 | 308 """A HenHouse.""" |
309 | |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
310 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse'] |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
311 BUY_PRICE = 100 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
312 SELL_PRICE = 90 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
313 SIZE = (3, 2) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
314 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
315 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
316 NAME = 'Henhouse' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
317 FLOORS = [0] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
318 |
125 | 319 class DoubleStoryHenHouse(HenHouse): |
320 """A double story hen house.""" | |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
321 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
322 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
125 | 323 BUY_PRICE = 300 |
324 SELL_PRICE = 150 | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
325 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
326 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
327 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 328 NAME = 'Hendominium' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
329 FLOORS = [0, 1] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
330 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
331 class GuardTower(Abode): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
332 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
333 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
334 TILE_NO = tiles.REVERSE_TILE_MAP['guardtower'] |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
335 BUY_PRICE = 200 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
336 SELL_PRICE = 150 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
337 SIZE = (2, 2) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
338 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
339 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
340 NAME = 'Watchtower' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
341 FLOORS = [2] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
342 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
343 MODIFY_GUN_RANGE = lambda s, x: (3*x)/2 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
344 MODIFY_GUN_BASE_HIT = lambda s, x: x-5 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
345 MODIFY_GUN_RANGE_PENALTY = lambda s, x: x-1 |
199
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
346 MODIFY_VISION_BONUS = lambda s, x: x+10 |
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
347 MODIFY_VISION_RANGE_PENALTY = lambda s, x: x-2 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
348 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
349 class Fence(Building): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
350 """A fence.""" |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
351 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
352 TILE_NO = tiles.REVERSE_TILE_MAP['fence'] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
353 TILE_NO_BROKEN = tiles.REVERSE_TILE_MAP['broken fence'] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
354 BREAKABLE = True |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
355 BUY_PRICE = 50 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
356 SELL_PRICE = 25 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
357 REPAIR_PRICE = 25 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
358 SELL_PRICE_BROKEN = 5 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
359 SIZE = (1, 1) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
360 IMAGE = 'tiles/fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
361 SELECTED_IMAGE = 'tiles/fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
362 IMAGE_BROKEN = 'tiles/broken_fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
363 SELECTED_IMAGE_BROKEN = 'tiles/broken_fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
364 NAME = 'Fence' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
365 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
366 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
367 def is_building(obj): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
368 """Return true if obj is a build class.""" |
109
48019afde338
Equipment purchasing and some toolbar tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
369 return getattr(obj, "IS_BUILDING", False) and hasattr(obj, "NAME") |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
370 |
144
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
371 # Building hens can lay eggs in |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
372 HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
373 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
374 BUILDINGS = [] |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
375 for name in dir(): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
376 obj = eval(name) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
377 try: |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
378 if is_building(obj): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
379 BUILDINGS.append(obj) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
380 except TypeError: |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
381 pass |