Changeset 323 for trunk/game


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]

Location:
trunk/game/scripts
Files:
5 edited

Legend:

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

    r317 r323  
    1515 
    1616import re  
     17import os 
    1718 
    1819class Console: 
     
    126127                l_args = command.lower()[end_load + 1:].strip() 
    127128                l_path, l_filename = l_args.split(' ') 
    128                 self.app_listener.model.load(l_path, l_filename) 
    129                 result = "Loaded file: " + l_path + l_filename 
     129                self.app_listener.model.load_save = True 
     130                self.app_listener.model.savegame = os.path.join(l_path, l_filename) 
     131                result = "Load triggered" 
    130132 
    131133            except Exception, l_error: 
  • 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): 
  • trunk/game/scripts/map.py

    r314 r323  
    3939        self.view = engine.getView() 
    4040        self.transitions = [] 
    41         self.obj_hash = {} 
    4241        self.cur_cam2_x = 0 
    4342        self.initial_cam2_x = 0 
     
    5554            self.model.deleteMap(self.map) 
    5655        self.transitions = [] 
    57         self.obj_hash = {} 
    5856        self.map = None 
    5957        self.agent_layer = None 
     
    118116            self.cameras['main'].attach(agent) 
    119117 
    120     def addObject(self, name, obj): 
    121         """Add an object to this map0 
    122             Inputs: 
    123                 name - ID of object 
    124                 obj - FIFE instance of object 
    125             Return: 
    126                 Nothing 
    127         """ 
    128         # save it for later use 
    129         self.obj_hash[name]=obj 
    130118         
    131119    def toggle_renderer(self, r_name): 
  • trunk/game/scripts/objects/actors.py

    r320 r323  
    115115         
    116116        self.state = _AGENT_STATE_NONE 
    117         self.behaviour = PCBehaviour(self, agent_layer) 
     117        self.layer_id = agent_layer.getId() 
     118        self.createBehaviour(agent_layer) 
     119     
     120    def createBehaviour(self, layer): 
     121        """ Creates the behaviour for this actor. 
     122            @return None """ 
     123        self.behaviour = PCBehaviour(self, layer) 
    118124     
    119125    def setup(self): 
     
    240246        self.is_NPC = True 
    241247        self.inventory = None 
    242          
    243         self.behaviour = NPCBehaviour(self, agent_layer) 
     248        self.layer_id = agent_layer.getId() 
     249        self.createBehaviour(agent_layer)         
    244250        self.dialogue = kwargs.get('dialogue') 
     251 
     252    def createBehaviour(self, layer): 
     253        """ Creates the behaviour for this actor. 
     254            @return None """ 
     255        self.behaviour = NPCBehaviour(self, layer) 
    245256 
    246257    def getLocation(self): 
  • trunk/game/scripts/world.py

    r315 r323  
    5757        self.data = None 
    5858        self.mouseCallback = None 
    59         self.obj_hash={} 
    6059 
    6160        # self.map is a Map object, set to none here 
     
    9695        """Loads the game state 
    9796           @return: None""" 
     97        print self.data 
    9898        self.data.load(*args, **kwargs) 
    99  
     99         
    100100    def loadMap(self, map_name, filename): 
    101101        """Loads a map and stores it under the given name in the maps list. 
Note: See TracChangeset for help on using the changeset viewer.