Example #1
0
    def create_inventory(self):
        """Some buildings don't have an own inventory (e.g. storage building). Those can just
		overwrite this function to do nothing. see also: save_inventory() and load_inventory()"""
        db_data = horizons.main.db.cached_query("SELECT resource, size FROM balance.storage WHERE object_id = ?", \
                                   self.id)

        if len(db_data) == 0:
            # no db data about inventory. Create default inventory.
            self.inventory = PositiveSizedSlotStorage(
                STORAGE.DEFAULT_STORAGE_SIZE)
        else:
            # specialised storage; each res and limit is stored in db.
            self.inventory = PositiveSizedSpecializedStorage()
            for res, size in db_data:
                self.inventory.add_resource_slot(res, size)