Mercurial > rinkhals
annotate gamelib/buildings.py @ 223:527a5d4e3fa3
Disable tools at night.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 22:39:19 +0000 |
parents | 636c3fafa32d |
children | c279ad59b8e2 |
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 | |
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 |
124 def loop(self, tv, _sprite): | |
125 ppos = tv.tile_to_view(self.pos) | |
126 self.rect.x = ppos[0] | |
127 self.rect.y = ppos[1] | |
128 | |
129 def move(self, state): | |
130 """Given the game state, return a new position for the object""" | |
131 # Default is not to move | |
132 return self.pos | |
133 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
134 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
135 """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
|
136 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
137 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
138 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
139 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
140 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
141 return False |
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 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
144 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
145 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
146 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
147 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
148 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
149 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
150 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
151 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
152 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
153 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
154 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
155 |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
156 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
157 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
158 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
159 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
160 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
161 |
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
|
162 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
|
163 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
|
164 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
165 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
166 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
167 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
168 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
169 if selected: |
204 | 170 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
|
171 else: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
172 self.sun(self._sun_on) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
173 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
174 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
|
175 self._sun_on = sun_on |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
176 if sun_on: |
204 | 177 self._replace_main(self.day_image) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
178 else: |
204 | 179 self._replace_main(self.night_image) |
180 | |
181 def update_occupant_count(self): | |
182 count = len(list(self.occupants())) | |
183 if count == 0: | |
184 if "count" in self.draw_stack: | |
185 del self.draw_stack["count"] | |
186 else: | |
187 image = self._font_image.copy() | |
188 text = self._font.render(str(count), True, constants.FG_COLOR) | |
189 w, h = image.get_size() | |
190 x, y = text.get_size() | |
191 image.blit(text, (w - x, h - y)) | |
192 self.draw_stack["count"] = (1, image) | |
193 self._redraw() | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
194 |
125 | 195 def floors(self): |
196 return self._floors | |
197 | |
198 def places(self): | |
199 for floor in self._floors: | |
200 for row in floor.rows(): | |
201 for place in row: | |
202 yield place | |
203 | |
204 def max_floor_width(self): | |
205 return max(floor.width() for floor in self._floors) | |
206 | |
207 def first_empty_place(self): | |
208 for place in self.places(): | |
209 if place.occupant is None: | |
210 return place | |
211 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
212 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
213 def add_occupant(self, occupant): |
125 | 214 place = self.first_empty_place() |
215 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
216 |
125 | 217 def occupants(self): |
218 for place in self.places(): | |
219 if place.occupant is not None: | |
220 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
|
221 |
43 | 222 class HenHouse(Building): |
223 """A HenHouse.""" | |
224 | |
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
|
225 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
|
226 BUY_PRICE = 100 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
227 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
|
228 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
|
229 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
230 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
231 NAME = 'Henhouse' |
125 | 232 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
233 |
125 | 234 class DoubleStoryHenHouse(HenHouse): |
235 """A double story hen house.""" | |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
236 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
237 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
125 | 238 BUY_PRICE = 300 |
239 SELL_PRICE = 150 | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
240 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
241 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
242 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 243 NAME = 'Hendominium' |
244 FLOORS = 2 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
245 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
246 class GuardTower(Building): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
247 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
248 |
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
|
249 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
|
250 BUY_PRICE = 200 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
251 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
|
252 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
|
253 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
254 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
255 NAME = 'Watchtower' |
125 | 256 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
257 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 MODIFY_VISION_BONUS = lambda s, x: x+10 |
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
262 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
|
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 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
|
265 """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
|
266 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
|
267 |
144
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
268 # Building hens can lay eggs in |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
269 HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
270 |
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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 pass |