def __init__(self, db, island_id, session, preview=False): """ @param db: db instance with island table @param island_id: id of island in that table @param session: reference to Session instance @param preview: flag, map preview mode """ super(Island, self).__init__(worldid=island_id) self.session = session self.terrain_cache = None self.available_land_cache = None self.__init(db, island_id, preview) if not preview: # Create building indexers. from horizons.world.units.animal import WildAnimal self.building_indexers = {} self.building_indexers[BUILDINGS.TREE] = BuildingIndexer( WildAnimal.walking_range, self, self.session.random) # Load settlements. for (settlement_id, ) in db( "SELECT rowid FROM settlement WHERE island = ?", island_id): settlement = Settlement.load(db, settlement_id, self.session, self) self.settlements.append(settlement) if preview: # Caches and buildings are not required for map preview. return self.terrain_cache = TerrainBuildabilityCache(self) flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)] self.available_flat_land = len(flat_land_set) available_coords_set = set(self.terrain_cache.land_or_coast) for settlement in self.settlements: settlement.init_buildability_cache(self.terrain_cache) for coords in settlement.ground_map: available_coords_set.discard(coords) if coords in flat_land_set: self.available_flat_land -= 1 self.available_land_cache = FreeIslandBuildabilityCache(self) # Load buildings. from horizons.world import load_building buildings = db("SELECT rowid, type FROM building WHERE location = ?", island_id) for (building_worldid, building_typeid) in buildings: load_building(self.session, db, building_typeid, building_worldid)
def __init__(self, db, island_id, session, preview=False): """ @param db: db instance with island table @param island_id: id of island in that table @param session: reference to Session instance @param preview: flag, map preview mode """ super(Island, self).__init__(worldid=island_id) if False: from horizons.session import Session assert isinstance(session, Session) self.session = session self.__init(db, island_id, preview) if not preview: # create building indexers from horizons.world.units.animal import WildAnimal self.building_indexers = {} self.building_indexers[BUILDINGS.TREE] = BuildingIndexer( WildAnimal.walking_range, self, self.session.random) # load settlements for (settlement_id, ) in db( "SELECT rowid FROM settlement WHERE island = ?", island_id): settlement = Settlement.load(db, settlement_id, self.session, self) self.settlements.append(settlement) if not preview: # load buildings from horizons.world import load_building for (building_worldid, building_typeid) in \ db("SELECT rowid, type FROM building WHERE location = ?", island_id): load_building(self.session, db, building_typeid, building_worldid)
def init_fish_indexer(self): radius = Entities.buildings[BUILDINGS.FISHER].radius buildings = self.provider_buildings.provider_by_resources[RES.FISH] self.fish_indexer = BuildingIndexer(radius, self.full_map, buildings=buildings)