Ignore:
Timestamp:
02/03/10 14:54:21 (10 years ago)
Author:
maximinus_parpg
Message:

Added Beliars patch for loading / saving.

File:
1 edited

Legend:

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

    r476 r478  
    5959            return 
    6060         
    61         # save the PC coordinates before we destroy the behaviour 
     61        # save the PC coordinates 
    6262        coords = self.game_state.PC.behaviour.agent.getLocation().\ 
    6363                    getMapCoordinates() 
    6464        self.game_state.saved_pc_coordinates = (coords.x, coords.y) 
    6565         
    66         # can't pickle SwigPyObjects 
    67         behaviours = {} 
    68         behaviour_player = self.game_state.PC.behaviour 
    69         self.game_state.PC.behaviour = None 
    70          
    71         # Backup the behaviours  
    72         for map_id in self.game_state.objects: 
    73             behaviours[map_id] = {} 
    74             for (object_id, npc) in self.game_state.objects[map_id].items(): 
    75                 if npc.trueAttr("NPC"): 
    76                     behaviours[map_id][object_id] = npc.behaviour 
    77                     npc.behaviour = None 
    78          
    7966        # Pickle it  
    8067        pickle.dump(self.game_state, f) 
    81         f.close() 
    82          
    83         # Restore behaviours 
    84         for map_id in behaviours: 
    85             for (object_id, behaviour) in behaviours[map_id].items(): 
    86                 self.game_state.objects[map_id][object_id].behaviour = \ 
    87                     behaviours[map_id][object_id] 
    88                  
    89         self.game_state.PC.behaviour = behaviour_player 
     68        f.close()        
    9069 
    9170    def load(self, path, filename): 
     
    11291        # objects cannot be pickled 
    11392        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) 
     93            for (object_id, obj) in self.game_state.objects[map_id].items(): 
     94                if obj.trueAttr("NPC") or obj.trueAttr("AnimatedContainer"): 
     95                    obj.createBehaviour(self.view.active_map.agent_layer) 
    11796 
    11897        # Fix the player behaviour 
     
    194173            # create the PC agent 
    195174            obj.start() 
     175        if obj.trueAttr("AnimatedContainer"): 
     176            # create the agent 
     177            obj.setup() 
    196178 
    197179    def objectActive(self, ident): 
Note: See TracChangeset for help on using the changeset viewer.