Ignore:
Timestamp:
06/26/10 18:30:19 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Fixed inventory/container contents not saved/restored correctly
  • Changed numbering of inventory-item id's to only add a number if the original id is in use. (Id's are being saved and we don't want to add another number to one already present)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/gamemodel.py

    r565 r566  
    112112        info.update(extra) 
    113113        ID = info.pop("id") if info.has_key("id") else info.pop("ID") 
    114         id_number = 0 
    115         while self.game_state.hasObject(ID + "_" + str(id_number)): 
    116             id_number += 1 
    117             if id_number > self.MAX_ID_NUMBER: 
    118                 raise ValueError("Number exceeds MAX_ID_NUMBER:" +  
    119                                  str(self.MAX_ID_NUMBER)) 
    120         ID = ID + "_" + str(id_number) 
     114        if self.game_state.hasObject(ID): 
     115            id_number = 1 
     116            while self.game_state.hasObject(ID + "_" + str(id_number)): 
     117                id_number += 1 
     118                if id_number > self.MAX_ID_NUMBER: 
     119                    raise ValueError("Number exceeds MAX_ID_NUMBER:" +  
     120                                     str(self.MAX_ID_NUMBER)) 
     121            ID = ID + "_" + str(id_number) 
    121122        new_item = CarryableItem(ID = ID, **info)  
    122123        self.game_state.addObject(None, new_item) 
     
    208209                self.addAgent(map_name, agent) 
    209210                 
    210         load_file.close() 
    211          
    212211        # Load the current map 
    213212        if self.game_state.current_map_name: 
    214213            self.loadMap(self.game_state.current_map_name)          
     214        load_file.close() 
     215         
    215216 
    216217        # Recreate all the behaviours. These can't be saved because FIFE 
     
    301302        if not self.agents.has_key(namespace): 
    302303            self.agents[namespace] = {} 
    303  
     304             
    304305        self.agents[namespace].update(agent) 
    305306        object_model = "" 
     
    312313        loadImportFile(import_file, self.engine) 
    313314         
     315    def readAgentsOfMap(self, map_name): 
     316        """Read the agents of the map 
     317        @param map_name: Name of the map 
     318        @type map_name: str 
     319        """ 
     320        #Get the agents of the map         
     321        map_agents_file = self.map_files[map_name].\ 
     322                            replace(".xml", "_agents.yaml")    
     323        agents_data = file(map_agents_file) 
     324        agents = yaml.load_all(agents_data) 
     325        for agent in agents: 
     326            if not agent == None: 
     327                self.addAgent(map_name, agent)   
     328     
    314329    def readAllAgents(self): 
    315330        """Read the agents of the all_agents_file and store them""" 
     
    350365           @param map_name: Name of the map to load 
    351366           @return: None""" 
    352         self.game_state.current_map_name = map_name 
    353  
    354367        if not map_name in self.maps:   
    355368            map_file = self.map_files[map_name] 
    356             map_agents_file = map_file.replace(".xml", "_agents.yaml")    
    357369            new_map = GameMap(self.engine, self) 
    358370            self.maps[map_name] = new_map 
    359             #Get the agents of the map 
    360             agents_data = file(map_agents_file) 
    361             agents = yaml.load_all(agents_data) 
    362             for agent in agents: 
    363                 if not agent == None: 
    364                     self.addAgent(map_name, agent)   
    365             new_map.load(self.map_files[map_name]) 
    366         else: 
    367             self.setActiveMap(map_name) 
    368  
     371            new_map.load(map_file) 
     372     
    369373    def createAgent(self, agent, inst_id): 
    370374        object_type = agent["ObjectType"] 
     
    480484        self.game_state.PlayerCharacter.start() 
    481485                       
    482     def changeMap(self, map_name, target_position): 
     486    def changeMap(self, map_name, target_position = None): 
    483487        """Registers for a map change on the next pump(). 
    484488           @type map_name: String 
     
    519523        self.active_map = self.maps[map_name] 
    520524        self.active_map.makeActive() 
     525        self.game_state.current_map_name = map_name 
    521526 
    522527    def createMapObject (self, layer, attributes, instance): 
Note: See TracChangeset for help on using the changeset viewer.