Mercurial > rinkhals
annotate gamelib/buildings.py @ 170:92d11e0544bc
Switch building to selected image when building is selected.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 22:59:30 +0000 |
parents | a9b800b4175e |
children | b400991ccce1 |
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'] |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
54 |
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
|
55 def __init__(self, pos): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
56 """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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 self._buy_price = self.BUY_PRICE |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
64 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
|
65 self._sun_on = True |
125 | 66 |
67 self._floors = [] | |
68 for f in range(self.FLOORS): | |
69 places = [] | |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
70 for j in range(self.size[1]): |
125 | 71 row = [] |
136
9acf8e3d9596
Fix orientation of places in buildings.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
72 for i in range(self.size[0]): |
125 | 73 row.append(Place(self, (i, j))) |
74 places.append(row) | |
75 floor = Floor("Floor %s" % (f+1,), places) | |
76 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
|
77 |
43 | 78 # 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
|
79 Sprite.__init__(self, self.day_image, (-1000, -1000)) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
80 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
81 def tile_positions(self): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
82 """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
|
83 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
|
84 """ |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
85 xpos, ypos = self.pos |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
86 xsize, ysize = self.size |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
87 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
88 for dx in xrange(xsize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
89 for dy in xrange(ysize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
90 yield (xpos + dx, ypos + dy) |
43 | 91 |
92 def loop(self, tv, _sprite): | |
93 ppos = tv.tile_to_view(self.pos) | |
94 self.rect.x = ppos[0] | |
95 self.rect.y = ppos[1] | |
96 | |
97 def move(self, state): | |
98 """Given the game state, return a new position for the object""" | |
99 # Default is not to move | |
100 return self.pos | |
101 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
102 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
103 """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
|
104 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
105 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
106 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
107 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
108 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
109 return False |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
110 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
111 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
112 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
113 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
114 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
115 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
116 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
117 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
118 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
119 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
120 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
121 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
122 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
123 |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
124 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
125 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
126 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
127 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
128 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
129 |
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
|
130 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
|
131 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
|
132 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
133 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
134 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
135 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
136 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
137 if selected: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
138 self.setimage(self.selected_image) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
139 else: |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
140 self.sun(self._sun_on) |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
141 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
142 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
|
143 self._sun_on = sun_on |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
144 if sun_on: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
145 self.setimage(self.day_image) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
146 else: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
147 self.setimage(self.night_image) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
148 |
125 | 149 def floors(self): |
150 return self._floors | |
151 | |
152 def places(self): | |
153 for floor in self._floors: | |
154 for row in floor.rows(): | |
155 for place in row: | |
156 yield place | |
157 | |
158 def max_floor_width(self): | |
159 return max(floor.width() for floor in self._floors) | |
160 | |
161 def first_empty_place(self): | |
162 for place in self.places(): | |
163 if place.occupant is None: | |
164 return place | |
165 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
166 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
167 def add_occupant(self, occupant): |
125 | 168 place = self.first_empty_place() |
169 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
170 |
125 | 171 def occupants(self): |
172 for place in self.places(): | |
173 if place.occupant is not None: | |
174 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
|
175 |
43 | 176 class HenHouse(Building): |
177 """A HenHouse.""" | |
178 | |
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
|
179 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
|
180 BUY_PRICE = 100 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
181 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
|
182 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
|
183 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
184 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
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
|
185 NAME = 'Hen House' |
125 | 186 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
187 |
125 | 188 class DoubleStoryHenHouse(HenHouse): |
189 """A double story hen house.""" | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
190 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
125 | 191 BUY_PRICE = 300 |
192 SELL_PRICE = 150 | |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
193 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
194 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
195 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 196 NAME = 'Hendominium' |
197 FLOORS = 2 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
198 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
199 class GuardTower(Building): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
200 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
201 |
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
|
202 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
|
203 BUY_PRICE = 200 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
204 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
|
205 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
|
206 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
207 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
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 NAME = 'Watch Tower' |
125 | 209 FLOORS = 1 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
210 |
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
|
211 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
|
212 """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
|
213 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
|
214 |
144
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
215 # Building hens can lay eggs in |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
diff
changeset
|
216 HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] |
a9b800b4175e
Add define for henhouses & egg laying.
Neil Muller <drnlmuller@gmail.com>
parents:
136
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 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 pass |