Mercurial > rinkhals
comparison gamelib/buildings.py @ 557:50d6c68ce267
Add gameboard to buildings. Update save version as this breaks old save games
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 18:20:46 +0000 |
parents | 3ed6c011106d |
children | 7f037ee2a6c8 |
comparison
equal
deleted
inserted
replaced
556:46f6f1a98f3f | 557:50d6c68ce267 |
---|---|
91 '_sell_price', | 91 '_sell_price', |
92 '_repair_price', | 92 '_repair_price', |
93 '_sun_on', | 93 '_sun_on', |
94 '_broken', | 94 '_broken', |
95 '_floors', | 95 '_floors', |
96 'gameboard', | |
96 ] | 97 ] |
97 | 98 |
98 def __init__(self, pos): | 99 def __init__(self, pos, gameboard): |
99 """Initial image, tile vid position, size and tile number for building.""" | 100 """Initial image, tile vid position, size and tile number for building.""" |
100 self._set_images() | 101 self._set_images() |
101 self.pos = pos | 102 self.pos = pos |
103 self.gameboard = gameboard | |
102 self.size = self.SIZE | 104 self.size = self.SIZE |
103 self.tile_no = self.TILE_NO | 105 self.tile_no = self.TILE_NO |
104 self._buy_price = self.BUY_PRICE | 106 self._buy_price = self.BUY_PRICE |
105 self._sell_price = self.SELL_PRICE | 107 self._sell_price = self.SELL_PRICE |
106 self._repair_price = getattr(self, 'REPAIR_PRICE', None) | 108 self._repair_price = getattr(self, 'REPAIR_PRICE', None) |
131 Sprite.__init__(self, self.images['fixed']['day'], (-1000, -1000)) | 133 Sprite.__init__(self, self.images['fixed']['day'], (-1000, -1000)) |
132 | 134 |
133 @classmethod | 135 @classmethod |
134 def make(cls): | 136 def make(cls): |
135 """Override default Simplifiable object creation.""" | 137 """Override default Simplifiable object creation.""" |
136 return cls((0, 0)) | 138 return cls((0, 0), None) |
137 | 139 |
138 @classmethod | 140 @classmethod |
139 def unsimplify(cls, *args, **kwargs): | 141 def unsimplify(cls, *args, **kwargs): |
140 """Override default Simplifiable unsimplification.""" | 142 """Override default Simplifiable unsimplification.""" |
141 obj = super(Building, cls).unsimplify(*args, **kwargs) | 143 obj = super(Building, cls).unsimplify(*args, **kwargs) |
206 def move(self, state): | 208 def move(self, state): |
207 """Given the game state, return a new position for the object""" | 209 """Given the game state, return a new position for the object""" |
208 # Default is not to move | 210 # Default is not to move |
209 return self.pos | 211 return self.pos |
210 | 212 |
211 def place(self, tv): | 213 def place(self): |
212 """Check that the building can be placed at its current position | 214 """Check that the building can be placed at its current position |
213 and place it if possible. | 215 and place it if possible. |
214 """ | 216 """ |
215 # check that all spaces under the structure are grassland | 217 # check that all spaces under the structure are grassland |
216 for tile_pos in self.tile_positions(): | 218 for tile_pos in self.tile_positions(): |
217 if not tv.get(tile_pos) == self.GRASSLAND: | 219 if not self.gameboard.tv.get(tile_pos) == self.GRASSLAND: |
218 return False | 220 return False |
219 | 221 |
220 # place tile | 222 # place tile |
221 for tile_pos in self.tile_positions(): | 223 for tile_pos in self.tile_positions(): |
222 tv.set(tile_pos, self.tile_no) | 224 self.gameboard.tv.set(tile_pos, self.tile_no) |
223 | 225 |
224 return True | 226 return True |
225 | 227 |
226 def covers(self, tile_pos): | 228 def covers(self, tile_pos): |
227 """Return True if build covers tile_pos, False otherwise.""" | 229 """Return True if build covers tile_pos, False otherwise.""" |
231 (ypos <= tile_pos[1] < ypos + ysize) | 233 (ypos <= tile_pos[1] < ypos + ysize) |
232 | 234 |
233 def broken(self): | 235 def broken(self): |
234 return self._broken | 236 return self._broken |
235 | 237 |
236 def damage(self, tv): | 238 def damage(self): |
237 if not self.BREAKABLE: | 239 if not self.BREAKABLE: |
238 return False | 240 return False |
239 self._broken = True | 241 self._broken = True |
240 self._sell_price = self.SELL_PRICE_BROKEN | 242 self._sell_price = self.SELL_PRICE_BROKEN |
241 self.tile_no = self.TILE_NO_BROKEN | 243 self.tile_no = self.TILE_NO_BROKEN |
242 for tile_pos in self.tile_positions(): | 244 for tile_pos in self.tile_positions(): |
243 tv.set(tile_pos, self.tile_no) | 245 self.gameboard.tv.set(tile_pos, self.tile_no) |
244 self._set_main_image() | 246 self._set_main_image() |
245 | 247 |
246 def repair(self, tv): | 248 def repair(self): |
247 self._broken = False | 249 self._broken = False |
248 self._sell_price = self.SELL_PRICE | 250 self._sell_price = self.SELL_PRICE |
249 self.tile_no = self.TILE_NO | 251 self.tile_no = self.TILE_NO |
250 for tile_pos in self.tile_positions(): | 252 for tile_pos in self.tile_positions(): |
251 tv.set(tile_pos, self.tile_no) | 253 self.gameboard.tv.set(tile_pos, self.tile_no) |
252 self._set_main_image() | 254 self._set_main_image() |
253 | 255 |
254 def remove(self, tv): | 256 def remove(self): |
255 """Remove the building from its current position.""" | 257 """Remove the building from its current position.""" |
256 # remove tile | 258 # remove tile |
257 for tile_pos in self.tile_positions(): | 259 for tile_pos in self.tile_positions(): |
258 tv.set(tile_pos, self.GRASSLAND) | 260 self.gameboard.tv.set(tile_pos, self.GRASSLAND) |
259 | 261 |
260 def buy_price(self): | 262 def buy_price(self): |
261 return self._buy_price | 263 return self._buy_price |
262 | 264 |
263 def sell_price(self): | 265 def sell_price(self): |