Mercurial > rinkhals
comparison gamelib/gameboard.py @ 197:d74693555b86
Put chickens into first empty space in buildings to make it easier to add lots of chickens.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 19:32:30 +0000 |
parents | 5ec222ca07cd |
children | 67d10f7e0159 |
comparison
equal
deleted
inserted
replaced
196:edcb5edfa0ff | 197:d74693555b86 |
---|---|
336 self.animal_to_place = chicken | 336 self.animal_to_place = chicken |
337 pygame.mouse.set_cursor(*cursors.cursors['chicken']) | 337 pygame.mouse.set_cursor(*cursors.cursors['chicken']) |
338 return | 338 return |
339 building = self.get_building(tile_pos) | 339 building = self.get_building(tile_pos) |
340 if building: | 340 if building: |
341 self.open_building_dialog(building) | 341 if self.animal_to_place: |
342 try: | |
343 place = building.first_empty_place() | |
344 self.relocate_animal(self.animal_to_place, place=place) | |
345 self.animal_to_place = None | |
346 pygame.mouse.set_cursor(*cursors.cursors['select']) | |
347 except buildings.BuildingFullError: | |
348 pass | |
349 else: | |
350 self.open_building_dialog(building) | |
342 return | 351 return |
343 if self.tv.get(tile_pos) == self.GRASSLAND: | 352 if self.tv.get(tile_pos) == self.GRASSLAND: |
344 if self.animal_to_place is not None: | 353 if self.animal_to_place is not None: |
345 occupant = self.animal_to_place | 354 self.relocate_animal(self.animal_to_place, tile_pos=tile_pos) |
346 if occupant.abode is not None: | 355 |
347 occupant.abode.clear_occupant() | 356 def relocate_animal(self, chicken, tile_pos=None, place=None): |
348 occupant.set_pos(tile_pos) | 357 assert((tile_pos, place) != (None, None)) |
349 self.set_visibility(occupant) | 358 if chicken.abode is not None: |
359 chicken.abode.clear_occupant() | |
360 if tile_pos: | |
361 chicken.set_pos(tile_pos) | |
362 else: | |
363 place.set_occupant(chicken) | |
364 chicken.set_pos(place.get_pos()) | |
365 self.set_visibility(chicken) | |
350 | 366 |
351 def set_visibility(self, chicken): | 367 def set_visibility(self, chicken): |
352 if chicken.outside(): | 368 if chicken.outside(): |
353 if chicken not in self.tv.sprites: | 369 if chicken not in self.tv.sprites: |
354 self.tv.sprites.append(chicken) | 370 self.tv.sprites.append(chicken) |
403 button.disconnect(gui.CLICK, set_occupant) | 419 button.disconnect(gui.CLICK, set_occupant) |
404 button.connect(gui.CLICK, select_occupant, place, button, | 420 button.connect(gui.CLICK, select_occupant, place, button, |
405 sell_callback) | 421 sell_callback) |
406 | 422 |
407 old_abode = self.animal_to_place.abode | 423 old_abode = self.animal_to_place.abode |
408 if old_abode is not None: | |
409 old_abode.clear_occupant() | |
410 if id(old_abode) in place_button_map: | 424 if id(old_abode) in place_button_map: |
411 old_button = place_button_map[id(old_abode)] | 425 old_button = place_button_map[id(old_abode)] |
412 old_button.value = icons.EMPTY_NEST_ICON | 426 old_button.value = icons.EMPTY_NEST_ICON |
413 old_button.disconnect(gui.CLICK, select_occupant) | 427 old_button.disconnect(gui.CLICK, select_occupant) |
414 old_button.connect(gui.CLICK, set_occupant, place, button, | 428 old_button.connect(gui.CLICK, set_occupant, place, button, |
415 sell_callback) | 429 sell_callback) |
416 | 430 |
417 chicken = self.animal_to_place | 431 self.relocate_animal(self.animal_to_place, place=place) |
418 place.set_occupant(chicken) | |
419 chicken.set_pos(place.get_pos()) | |
420 self.set_visibility(self.animal_to_place) | |
421 | 432 |
422 place_button_map = {} | 433 place_button_map = {} |
423 | 434 |
424 tbl = gui.Table() | 435 tbl = gui.Table() |
425 columns = building.max_floor_width() | 436 columns = building.max_floor_width() |