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