Mercurial > rinkhals
annotate gamelib/buildings.py @ 198:355eaae40b1f
Buildings now affect weapon range and accuracy.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 19:34:01 +0000 |
parents | b400991ccce1 |
children | 696936621a93 |
rev | line source |
---|---|
43 | 1 """Classes for various buildings in the game.""" |
2 | |
3 from pgu.vid import Sprite | |
4 | |
5 import imagecache | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
6 import tiles |
43 | 7 |
125 | 8 class Place(object): |
9 """Space within a building that can be occupied.""" | |
10 | |
11 def __init__(self, building, offset): | |
12 self.occupant = None | |
13 self.building = building | |
14 self.offset = offset | |
15 | |
16 def set_occupant(self, occupant): | |
17 self.clear_occupant() | |
18 self.occupant = occupant | |
19 self.occupant.abode = self | |
20 | |
21 def clear_occupant(self): | |
22 if self.occupant is not None: | |
23 self.occupant.abode = None | |
24 self.occupant = None | |
25 | |
26 def get_pos(self): | |
27 bpos = self.building.pos | |
28 return (bpos[0] + self.offset[0], bpos[1] + self.offset[1]) | |
29 | |
30 class Floor(object): | |
31 """A set of places within a building. Places on a | |
32 floor are organised into rows and columns. | |
33 """ | |
34 | |
35 def __init__(self, title, places): | |
36 self.title = title # str | |
37 self.places = places # list of lists of places | |
38 | |
39 def rows(self): | |
40 for row in self.places: | |
41 yield row | |
42 | |
43 def width(self): | |
44 return max(len(row) for row in self.places) | |
45 | |
46 class BuildingFullError(Exception): | |
47 pass | |
48 | |
43 | 49 class Building(Sprite): |
50 """Base class for buildings""" | |
51 | |
109
48019afde338
Equipment purchasing and some toolbar tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
52 IS_BUILDING = True |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
53 GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
54 MODIFY_KNIFE_RANGE = lambda s, x: 0 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
55 MODIFY_GUN_RANGE = lambda s, x: -1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
56 |
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
|
57 def __init__(self, pos): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
58 """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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 self._buy_price = self.BUY_PRICE |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
66 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
|
67 self._sun_on = True |
125 | 68 |
69 self._floors = [] | |
70 for f in range(self.FLOORS): | |
71 places = [] | |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
72 for j in range(self.size[1]): |
125 | 73 row = [] |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
74 for i in range(self.size[0]): |
125 | 75 row.append(Place(self, (i, j))) |
76 places.append(row) | |
77 floor = Floor("Floor %s" % (f+1,), places) | |
78 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
|
79 |
43 | 80 # 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
|
81 Sprite.__init__(self, self.day_image, (-1000, -1000)) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
82 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
83 def tile_positions(self): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
84 """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
|
85 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
|
86 """ |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
87 xpos, ypos = self.pos |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
88 xsize, ysize = self.size |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
89 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
90 for dx in xrange(xsize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
91 for dy in xrange(ysize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
92 yield (xpos + dx, ypos + dy) |
43 | 93 |
94 def loop(self, tv, _sprite): | |
95 ppos = tv.tile_to_view(self.pos) | |
96 self.rect.x = ppos[0] | |
97 self.rect.y = ppos[1] | |
98 | |
99 def move(self, state): | |
100 """Given the game state, return a new position for the object""" | |
101 # Default is not to move | |
102 return self.pos | |
103 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
104 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
105 """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
|
106 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
107 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
108 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
109 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
110 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
111 return False |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
112 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
113 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
114 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
115 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
116 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
117 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
118 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
119 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
120 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
121 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
122 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
123 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
124 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
125 |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
126 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
127 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
128 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
129 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
130 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
131 |
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
|
132 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
|
133 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
|
134 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
135 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
136 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
137 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
138 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
139 if selected: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
140 self.setimage(self.selected_image) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
141 else: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
142 self.sun(self._sun_on) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
143 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
144 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
|
145 self._sun_on = sun_on |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
146 if sun_on: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
147 self.setimage(self.day_image) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
148 else: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
149 self.setimage(self.night_image) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
150 |
125 | 151 def floors(self): |
152 return self._floors | |
153 | |
154 def places(self): | |
155 for floor in self._floors: | |
156 for row in floor.rows(): | |
157 for place in row: | |
158 yield place | |
159 | |
160 def max_floor_width(self): | |
161 return max(floor.width() for floor in self._floors) | |
162 | |
163 def first_empty_place(self): | |
164 for place in self.places(): | |
165 if place.occupant is None: | |
166 return place | |
167 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
168 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
169 def add_occupant(self, occupant): |
125 | 170 place = self.first_empty_place() |
171 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
172 |
125 | 173 def occupants(self): |
174 for place in self.places(): | |
175 if place.occupant is not None: | |
176 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
|
177 |
43 | 178 class HenHouse(Building): |
179 """A HenHouse.""" | |
180 | |
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
|
181 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
|
182 BUY_PRICE = 100 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
183 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
|
184 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
|
185 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
186 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
187 NAME = 'Henhouse' |
125 | 188 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
189 |
125 | 190 class DoubleStoryHenHouse(HenHouse): |
191 """A double story hen house.""" | |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
192 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
193 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
125 | 194 BUY_PRICE = 300 |
195 SELL_PRICE = 150 | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
196 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
197 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
198 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 199 NAME = 'Hendominium' |
200 FLOORS = 2 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
201 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
202 class GuardTower(Building): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
203 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
204 |
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
|
205 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
|
206 BUY_PRICE = 200 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
207 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
|
208 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
|
209 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
210 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
211 NAME = 'Watchtower' |
125 | 212 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
213 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
214 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
|
215 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
|
216 MODIFY_GUN_RANGE_PENALTY = lambda s, x: x-1 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
217 |
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
|
218 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
|
219 """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
|
220 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
|
221 |
144
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
222 # Building hens can lay eggs in |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
223 HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
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 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 pass |