Mercurial > rinkhals
annotate gamelib/buildings.py @ 231:857040b211d5
Note why we're disabling a warning.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 23:59:28 +0000 |
parents | c279ad59b8e2 |
children | 47c411d20b00 |
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 | |
6 import pygame.font | |
43 | 7 |
8 import imagecache | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
9 import tiles |
204 | 10 import constants |
11 | |
231
857040b211d5
Note why we're disabling a warning.
Simon Cross <hodgestar@gmail.com>
parents:
224
diff
changeset
|
12 # ignore os.popen3 warning generated by pygame.font.SysFont |
204 | 13 import warnings |
14 warnings.filterwarnings("ignore", "os.popen3 is deprecated.") | |
43 | 15 |
125 | 16 class Place(object): |
17 """Space within a building that can be occupied.""" | |
18 | |
19 def __init__(self, building, offset): | |
20 self.occupant = None | |
21 self.building = building | |
22 self.offset = offset | |
23 | |
204 | 24 def set_occupant(self, occupant, _update=True): |
25 self.clear_occupant(_update=False) | |
125 | 26 self.occupant = occupant |
27 self.occupant.abode = self | |
204 | 28 if _update: |
29 self.building.update_occupant_count() | |
125 | 30 |
204 | 31 def clear_occupant(self, _update=True): |
125 | 32 if self.occupant is not None: |
33 self.occupant.abode = None | |
34 self.occupant = None | |
204 | 35 if _update: |
36 self.building.update_occupant_count() | |
125 | 37 |
38 def get_pos(self): | |
39 bpos = self.building.pos | |
40 return (bpos[0] + self.offset[0], bpos[1] + self.offset[1]) | |
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 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
68 |
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
|
69 def __init__(self, pos): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
70 """Initial image, tile vid position, size and tile number for building.""" |
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
|
71 self.day_image = imagecache.load_image(self.IMAGE) |
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 self.night_image = imagecache.load_image(self.IMAGE, ('night',)) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
73 self.selected_image = imagecache.load_image(self.SELECTED_IMAGE) |
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
|
74 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
|
75 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
|
76 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
|
77 self._buy_price = self.BUY_PRICE |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
78 self._sell_price = self.SELL_PRICE |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
79 self._sun_on = True |
204 | 80 self._font = pygame.font.SysFont('Vera', 30, bold=True) |
81 self._font_image = pygame.Surface(self.day_image.get_size(), flags=SRCALPHA) | |
82 self._font_image.fill((0, 0, 0, 0)) | |
125 | 83 |
84 self._floors = [] | |
85 for f in range(self.FLOORS): | |
86 places = [] | |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
87 for j in range(self.size[1]): |
125 | 88 row = [] |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
89 for i in range(self.size[0]): |
125 | 90 row.append(Place(self, (i, j))) |
91 places.append(row) | |
92 floor = Floor("Floor %s" % (f+1,), places) | |
93 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
|
94 |
204 | 95 # 0: the main iamge |
96 # 1: above, -1: below | |
97 self.draw_stack = {"main": (0, self.day_image)} | |
98 | |
43 | 99 # Create the building somewhere far off screen |
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
|
100 Sprite.__init__(self, self.day_image, (-1000, -1000)) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
101 |
204 | 102 def _redraw(self): |
103 items = self.draw_stack.values() | |
104 items.sort(key=lambda x: x[0]) | |
105 image = items.pop(0)[1].copy() | |
106 for _lvl, overlay in items: | |
107 image.blit(overlay, (0, 0)) | |
108 self.setimage(image) | |
109 | |
110 def _replace_main(self, new_main): | |
111 self.draw_stack["main"] = (0, new_main) | |
112 self._redraw() | |
113 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
114 def tile_positions(self): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
115 """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
|
116 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
|
117 """ |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
118 xpos, ypos = self.pos |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
119 xsize, ysize = self.size |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
120 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
121 for dx in xrange(xsize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
122 for dy in xrange(ysize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
123 yield (xpos + dx, ypos + dy) |
43 | 124 |
224
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
125 def adjacent_tiles(self): |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
126 """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
|
127 adjacent to the building. |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
128 """ |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
129 xpos, ypos = self.pos |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
130 xsize, ysize = self.size |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
131 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
132 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
|
133 yield (xpos + dx, ypos - 1) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
134 yield (xpos + dx, ypos + ysize) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
135 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
136 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
|
137 yield (xpos - 1, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
138 yield (xpos + xsize, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
139 |
43 | 140 def loop(self, tv, _sprite): |
141 ppos = tv.tile_to_view(self.pos) | |
142 self.rect.x = ppos[0] | |
143 self.rect.y = ppos[1] | |
144 | |
145 def move(self, state): | |
146 """Given the game state, return a new position for the object""" | |
147 # Default is not to move | |
148 return self.pos | |
149 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
150 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
151 """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
|
152 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
153 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
154 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
155 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
156 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
157 return False |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
158 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
159 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
160 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
161 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
162 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
163 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
164 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
165 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
166 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
167 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
168 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
169 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
170 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
171 |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
172 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
173 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
174 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
175 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
176 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
177 |
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
|
178 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
|
179 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
|
180 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
181 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
182 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
183 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
184 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
185 if selected: |
204 | 186 self._replace_main(self.selected_image) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
187 else: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
188 self.sun(self._sun_on) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
189 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
190 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
|
191 self._sun_on = sun_on |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
192 if sun_on: |
204 | 193 self._replace_main(self.day_image) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
194 else: |
204 | 195 self._replace_main(self.night_image) |
196 | |
197 def update_occupant_count(self): | |
198 count = len(list(self.occupants())) | |
199 if count == 0: | |
200 if "count" in self.draw_stack: | |
201 del self.draw_stack["count"] | |
202 else: | |
203 image = self._font_image.copy() | |
204 text = self._font.render(str(count), True, constants.FG_COLOR) | |
205 w, h = image.get_size() | |
206 x, y = text.get_size() | |
207 image.blit(text, (w - x, h - y)) | |
208 self.draw_stack["count"] = (1, image) | |
209 self._redraw() | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
210 |
125 | 211 def floors(self): |
212 return self._floors | |
213 | |
214 def places(self): | |
215 for floor in self._floors: | |
216 for row in floor.rows(): | |
217 for place in row: | |
218 yield place | |
219 | |
220 def max_floor_width(self): | |
221 return max(floor.width() for floor in self._floors) | |
222 | |
223 def first_empty_place(self): | |
224 for place in self.places(): | |
225 if place.occupant is None: | |
226 return place | |
227 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
228 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
229 def add_occupant(self, occupant): |
125 | 230 place = self.first_empty_place() |
231 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
232 |
125 | 233 def occupants(self): |
234 for place in self.places(): | |
235 if place.occupant is not None: | |
236 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
|
237 |
43 | 238 class HenHouse(Building): |
239 """A HenHouse.""" | |
240 | |
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
|
241 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
|
242 BUY_PRICE = 100 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
243 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
|
244 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
|
245 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
246 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
247 NAME = 'Henhouse' |
125 | 248 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
249 |
125 | 250 class DoubleStoryHenHouse(HenHouse): |
251 """A double story hen house.""" | |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
252 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
253 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
125 | 254 BUY_PRICE = 300 |
255 SELL_PRICE = 150 | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
256 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
257 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
258 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 259 NAME = 'Hendominium' |
260 FLOORS = 2 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
261 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
262 class GuardTower(Building): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
263 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
264 |
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
|
265 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
|
266 BUY_PRICE = 200 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
267 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
|
268 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
|
269 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
270 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
271 NAME = 'Watchtower' |
125 | 272 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
273 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 MODIFY_VISION_BONUS = lambda s, x: x+10 |
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
278 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
|
279 |
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
|
280 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
|
281 """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
|
282 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
|
283 |
144
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
284 # Building hens can lay eggs in |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
285 HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
286 |
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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 pass |