Changeset 67:9171d9b9ab35


Ignore:
Timestamp:
Aug 31, 2009, 9:22:10 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@68
Message:

Sanity check and fix up buildings on map after loading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r66 r67  
    9696        self.add_cash(constants.STARTING_CASH)
    9797
     98        self.fix_buildings()
     99
    98100    def create_disp(self):
    99101        width, height = pygame.display.get_surface().get_size()
     
    233235        self.cash += amount
    234236        self.toolbar.update_cash_counter(self.cash)
     237
     238    def fix_buildings(self):
     239        """Go through the level map looking for buildings that haven't
     240           been added to self.buildings and adding them.
     241
     242           Where partial buildings exist (i.e. places where the building
     243           cannot fit on the available tiles) the building is added anyway
     244           to the top left corner.
     245
     246           Could be a lot faster.
     247           """
     248        tile_to_building = dict((b.TILE_NO, b) for b in buildings.BUILDINGS)
     249        print tile_to_building
     250
     251        w, h = self.tv.size
     252        for x in xrange(w):
     253            for y in xrange(h):
     254                tile_pos = (x, y)
     255                tile_no = self.tv.get(tile_pos)
     256                if tile_no not in tile_to_building:
     257                    continue
     258
     259                covered = False
     260                for building in self.buildings:
     261                    if building.covers(tile_pos):
     262                        covered = True
     263                        break
     264
     265                if covered:
     266                    continue
     267
     268                building_cls = tile_to_building[tile_no]
     269                building = building_cls(tile_pos)
     270                building.remove(self.tv)
     271                building.place(self.tv)
     272                self.add_building(building)
Note: See TracChangeset for help on using the changeset viewer.