Changeset 314 for trunk/game/scripts


Ignore:
Timestamp:
10/11/09 10:34:47 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #66: Patch by saritor, eliedebrauwer & kaydeth cross map teleporting is now possible, we extended the objects within gamestate to make use of double hashing (f(obj_id,map_id)->object). Going back to a previously loaded map is still broken (camera issue). Also extended map.xml and map2.xml in order to make it possible to go back and forth between these two maps. comment[s:trac, t:66]

Location:
trunk/game/scripts
Files:
3 edited

Legend:

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

    r313 r314  
    3232     
    3333    def __init__(self, view): 
    34         """Initialise the instance. 
     34        """Initialize the instance. 
    3535           @type view: world 
    3636           @param view: A world instance 
     
    4242        self.pc_run = 1 
    4343        self.target_position = None 
     44        self.target_map_name = None 
     45        self.target_map_file = None 
    4446    def reset(self): 
    4547        """Clears the data on a map reload so we don't have objects/npcs from 
     
    9597        if self.game_state.current_map: 
    9698            self.loadMap(self.game_state.current_map_name, \ 
    97                          self.game_state.current_map)  
     99                         self.game_state.current_map_file)  
    98100 
    99101    def createObject (self, layer, attributes, instance): 
     
    131133           @return: None 
    132134        """ 
    133         # add to view data  
     135        # If this map has already a PC 
    134136        self.view.active_map.addObject(pc.ID, instance)           
    135137         
    136         # sync with game data 
    137         if self.game_state.PC is None: 
    138             self.game_state.PC = pc 
     138        # For now we copy the PC, in the future we will need to copy 
     139        # PC specifics between the different PC's 
     140        self.game_state.PC = pc 
    139141             
    140142        self.game_state.PC.setup() 
    141  
    142143 
    143144    def addObject(self, layer, obj, instance): 
     
    149150           @type instance: fife.Instance 
    150151           @param instance: FIFE instance of object 
    151            @return: Nothing 
     152           @return: None 
    152153        """ 
    153          
    154         ref = self.game_state.getObjectById(obj.ID)  
     154 
     155        ref = self.game_state.getObjectById(obj.ID, \ 
     156                                            self.game_state.current_map_name)  
    155157        if ref is None: 
    156158            # no, add it to the game state 
    157             obj.map_id = self.game_state.current_map 
    158             self.game_state.objects[obj.ID] = obj 
     159            self.game_state.objects[self.game_state.current_map_name][obj.ID] = obj 
    159160        else: 
    160161            # yes, use the current game state data 
     
    180181           @rtype: boolean 
    181182           @return: Status of result (True/False)""" 
    182         for i in self.game_state.getObjectsFromMap(self.game_state.current_map): 
     183        for i in self.game_state.getObjectsFromMap(self.game_state.current_map_name): 
    183184            if (i.ID == ident): 
    184185                # we found a match 
     
    195196        actions=[] 
    196197        # note: ALWAYS check NPC's first! 
    197         obj = self.game_state.getObjectById(obj_id) 
     198        obj = self.game_state.getObjectById(obj_id, \ 
     199                                            self.game_state.current_map_name) 
    198200         
    199201        if obj is not None: 
     
    232234        # TODO: work more on this when we get NPCData and HeroData straightened 
    233235        # out 
    234         npc = self.game_state.getObjectById(npcInfo.ID) 
     236        npc = self.game_state.getObjectById(npcInfo.ID, \ 
     237                                            self.game_state.current_map_name) 
    235238        self.game_state.PC.approach([npc.getLocation().\ 
    236239                                     getLayerCoordinates().x, \ 
     
    240243 
    241244    def loadMap(self, map_name, map_file): 
    242         """THIS FUNCTION IS BROKEN. DO NOT USE IT YET 
    243            Load a new map. 
     245        """Load a new map. 
    244246           @type map_name: string 
    245247           @param map_name: Name of the map to load 
     
    247249           @param map_file: Filename of map file to load 
    248250           @return: None""" 
    249         self.game_state.current_map = map_file 
    250         self.game_state.current_map_name= map_name 
     251        self.game_state.current_map_file = map_file 
     252        self.game_state.current_map_name = map_name 
    251253        self.view.loadMap(map_name, str(map_file)) 
    252254        self.view.setActiveMap(map_name) 
    253  
    254255        self.reset() 
    255256 
     
    257258        self.view.active_map.addPC(self.game_state.PC.behaviour.agent) 
    258259        self.game_state.PC.start() 
    259  
    260260 
    261261    def handleMouseClick(self,position): 
     
    269269            self.game_state.PC.walk(position) 
    270270 
    271     def changeMap(self, map_name, mapFile, target_position): 
     271    def changeMap(self, map_name, map_file, target_position): 
    272272        """Registers for a map change on the next pump(). 
    273            @type nameName: String 
     273           @type name_name: String 
    274274           @param map_name: Id of the map to teleport to 
    275            @type mapFile: String 
    276            @param mapFile: Filename of the map to teleport to 
     275           @type map_file: String 
     276           @param map_file: Filename of the map to teleport to 
    277277           @type target_position: Tuple 
    278278           @param target_position: Position of PC on target map. 
    279279           @return None""" 
    280280        # set the parameters for the map change if moving to a new map 
    281         print self.game_state.current_map_name 
    282281        if map_name != self.game_state.current_map_name: 
    283             self.game_state.current_map_name = map_name 
    284             self.game_state.current_map = mapFile 
     282            self.target_map_name = map_name 
     283            self.target_map_file = map_file 
    285284            self.target_position = target_position 
    286285            # issue the map change 
     
    292291    def handleCommands(self): 
    293292        if self.map_change: 
    294             self.loadMap(self.game_state.current_map_name, \ 
    295                          self.game_state.current_map) 
     293            self.loadMap(self.target_map_name, self.target_map_file) 
    296294            self.view.teleport(self.target_position) 
    297295            self.map_change = False 
  • trunk/game/scripts/gamestate.py

    r313 r314  
    2424        self.PC = None 
    2525        self.objects = {} 
    26         self.current_map = None 
     26        self.current_map_file = None 
    2727        self.current_map_name = None 
    2828         
     
    3232           @param map: The map name. 
    3333           @returns: The list of objects on this map.""" 
    34         return [i for i in self.objects.values() if i.map_id == map_id] 
     34        return [i for i in self.objects[map_id].values() if map_id in self.objects] 
    3535     
    36     def getObjectById(self, id): 
    37         """Gets an object by it's id 
    38            @type id: String 
    39            @param id: The id of the object. 
     36    def getObjectById(self, obj_id, map_id): 
     37        """Gets an object by its object id and map id 
     38           @type obj_id: String 
     39           @param obj_id: The id of the object. 
     40           @type map_id: String 
     41           @param map_id: It id of the map containing the object. 
    4042           @returns: The object or None.""" 
    41         if id in self.objects: 
    42             return self.objects[id] 
     43        if not map_id in self.objects: 
     44            self.objects[map_id] = {} 
     45        if obj_id in self.objects[map_id]: 
     46            return self.objects[map_id][obj_id] 
    4347 
  • trunk/game/scripts/map.py

    r313 r314  
    113113           @return: None""" 
    114114        # actually this is real easy, we just have to 
    115         # attach the main camera to the PC 
    116         self.cameras['main'].attach(agent) 
     115        # attach the main camera to the PC, if a camera 
     116        # was already used, we simply recycle it.  
     117        if self.cameras['main'].getAttached() == None: 
     118            self.cameras['main'].attach(agent) 
    117119 
    118120    def addObject(self, name, obj): 
     
    132134        renderer = self.cameras['main'].getRenderer(str(r_name)) 
    133135        renderer.setEnabled(not renderer.isEnabled()) 
     136 
Note: See TracChangeset for help on using the changeset viewer.