Ignore:
Timestamp:
10/13/09 18:42:00 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #73: Patch by eliedebrauwer, removed obj_hashes from world, and from the maps, added logic to restore PC and NPC behaviour based on the layer ID, added logic to trigger the map load using within the pump(). Load still not functional. comment[s:trac, t:73]

File:
1 edited

Legend:

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

    r319 r323  
    3939        self.view = view 
    4040        self.map_change = False 
     41        self.load_saver = False 
     42        self.savegame = None 
    4143        self.game_state = GameState() 
    4244        self.pc_run = 1 
     
    4446        self.target_map_name = None 
    4547        self.target_map_file = None 
     48         
    4649    def reset(self): 
    4750        """Clears the data on a map reload so we don't have objects/npcs from 
     
    6871        # Backup the behaviours  
    6972        for map_id in self.game_state.objects: 
    70             behaviours[map_id]={} 
     73            behaviours[map_id] = {} 
    7174            for (object_id, npc) in self.game_state.objects[map_id].items(): 
    72                 print object_id 
    7375                if npc.trueAttr("NPC"): 
    74                     behaviours[map_id][object_id]=npc.behaviour 
     76                    behaviours[map_id][object_id] = npc.behaviour 
    7577                    npc.behaviour = None; 
    76         print behaviours  
     78         
    7779        # Pickle it  
    7880        pickle.dump(self.game_state, f) 
     
    8789        self.game_state.PC.behaviour = behaviour_player 
    8890 
    89     def load(self, path, filename): 
     91    def load(self, filename): 
    9092        """Loads a saver from a file. 
    91            @type path: string  
    92            @param path: the path where the save file is located 
    9393           @type filename: string 
    94            @param filename: the name of the file to load from 
    95            @return: None""" 
    96         fname = '/'.join([path, filename]) 
     94           @param filename: the name of the file (including path) to load from 
     95           @return: None""" 
     96         
     97        # TODO 
     98        # Remove what we are currently working with  
     99        print "TODO: load" 
     100        self.view.active_map.view.clearCameras() 
     101        self.view.active_map.model.deleteMaps() 
     102         
    97103        try: 
    98             f = open(fname, 'r') 
     104            f = open(filename, 'r') 
    99105        except(IOError): 
    100106            sys.stderr.write("Error: Can't find save game file\n") 
     
    102108        self.game_state = pickle.load(f) 
    103109        f.close() 
     110         
     111        # Make sure we're on the right map 
    104112        if self.game_state.current_map_file: 
    105113            self.loadMap(self.game_state.current_map_name, \ 
     
    140148           @return: None 
    141149        """ 
    142         # If this map has already a PC 
    143         self.view.active_map.addObject(pc.ID, instance)           
    144          
    145150        # For now we copy the PC, in the future we will need to copy 
    146151        # PC specifics between the different PC's 
    147152        self.game_state.PC = pc 
    148              
    149153        self.game_state.PC.setup() 
    150154 
     
    170174            obj.Y = ref.Y 
    171175            obj.gfx = ref.gfx   
    172              
    173         # add it to the view 
    174         self.view.active_map.addObject(obj.ID, instance)           
    175  
     176              
    176177        if obj.trueAttr("NPC"): 
    177178            # create the agent 
     
    261262        self.view.setActiveMap(map_name) 
    262263        self.reset() 
     264         
     265        # If the map has been loaded, we might need to add some 
     266        # agents to the PC and NPS 
     267        for map_id in self.game_state.objects: 
     268            for (object_id, npc) in self.game_state.objects[map_id].items(): 
     269                if npc.trueAttr("NPC") and npc.behaviour == None: 
     270                    npc.createBehaviour(self.view.active_map.agent_layer) 
     271 
     272        # Fix the player behaviour 
     273        if self.game_state.PC.behaviour == None: 
     274            self.game_state.PC.createBehaviour(self.view.active_map.agent_layer) 
    263275 
    264276        # create the PC agent 
     
    301313            self.view.teleport(self.target_position) 
    302314            self.map_change = False 
     315         
     316        if self.load_saver: 
     317            self.load(self.savegame) 
     318            self.load_saver = False 
    303319 
    304320    def pump(self): 
Note: See TracChangeset for help on using the changeset viewer.