Ignore:
Timestamp:
10/31/09 15:11:33 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket #73. Patch by Kaydeth. Most of the changes were made to the map loading logic in the Engine, World, and Map classes to make sure it could handle loading maps after the game state has been restored by a load game. Also added a floating door back to both maps so map changing can still be tested in game. fixes[s:trac, t:73]

File:
1 edited

Legend:

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

    r341 r356  
    5454        fname = '/'.join([path, filename]) 
    5555        try: 
    56             f = open(fname, 'w') 
     56            f = open(fname, 'wb') 
    5757        except(IOError): 
    5858            sys.stderr.write("Error: Can't find save game: " + fname + "\n") 
    5959            return 
     60         
     61        # save the PC coordinates before we destroy the behaviour 
     62        coords = self.game_state.PC.behaviour.agent.getLocation().\ 
     63                    getMapCoordinates() 
     64        self.game_state.saved_pc_coordinates = (coords.x, coords.y) 
    6065         
    6166        # can't pickle SwigPyObjects 
     
    8489        self.game_state.PC.behaviour = behaviour_player 
    8590 
    86     def load(self, filename): 
     91    def load(self, path, filename): 
    8792        """Loads a saver from a file. 
    8893           @type filename: string 
    8994           @param filename: the name of the file (including path) to load from 
    9095           @return: None""" 
    91          
    92         # TODO 
    93         # Remove what we are currently working with  
    94         print "TODO: load" 
    95         self.view.active_map.view.clearCameras() 
    96         self.view.active_map.model.deleteMaps() 
    97          
     96             
     97        fname = '/'.join([path, filename]) 
     98 
    9899        try: 
    99             f = open(filename, 'r') 
     100            f = open(fname, 'rb') 
    100101        except(IOError): 
    101102            sys.stderr.write("Error: Can't find save game file\n") 
    102103            return 
     104         
     105        #Remove all currently loaded maps so we can start fresh 
     106        self.view.deleteMaps(); 
     107         
    103108        self.game_state = pickle.load(f) 
    104109        f.close() 
    105110         
    106         # Make sure we're on the right map 
     111        # Recreate all the behaviours. These can't be saved because FIFE 
     112        # objects cannot be pickled 
     113        for map_id in self.game_state.objects: 
     114            for (object_id, npc) in self.game_state.objects[map_id].items(): 
     115                if npc.trueAttr("NPC"): 
     116                    npc.createBehaviour(self.view.active_map.agent_layer) 
     117 
     118        # Fix the player behaviour 
     119        self.game_state.PC.createBehaviour(self.view.active_map.agent_layer) 
     120         
     121        #In most maps we'll create the PC Instance internally. In these 
     122        #cases we need a target position 
     123        self.target_position = self.game_state.saved_pc_coordinates 
     124         
     125        #Load the current map 
    107126        if self.game_state.current_map_file: 
    108127            self.loadMap(self.game_state.current_map_name, \ 
    109128                         self.game_state.current_map_file)  
    110  
     129             
    111130    def createObject (self, layer, attributes, instance): 
    112131        """Create an object and add it to the current map. 
     
    258277        self.view.loadMap(map_name, str(map_file)) 
    259278 
    260         # If the map has been loaded, we might need to add some 
    261         # agents to the PC and NPS 
    262         for map_id in self.game_state.objects: 
    263             for (object_id, npc) in self.game_state.objects[map_id].items(): 
    264                 if npc.trueAttr("NPC") and npc.behaviour == None: 
    265                     npc.createBehaviour(self.view.active_map.agent_layer) 
    266  
    267         # Fix the player behaviour 
    268         if self.game_state.PC.behaviour == None: 
    269             self.game_state.PC.createBehaviour(self.view.active_map.agent_layer) 
    270  
    271279        # create the PC agent 
    272280        self.view.active_map.addPC() 
Note: See TracChangeset for help on using the changeset viewer.