Changeset 565


Ignore:
Timestamp:
06/26/10 15:34:34 (9 years ago)
Author:
beliar
Message:

Ticket #260 Patch by Beliar

  • When creating inventory objects there will now e a consecutively numbered number added to the ID. The new ID will have the form <ID>_<number>

fixes[s:trac, t:260

Location:
trunk/game
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/maps/all_agents.yaml

    r563 r565  
    2323    Rotation: 0 
    2424    Inventory: 
    25         - {ID: "456", object_type: "Dagger", slot: "right_hand"} 
    26         - {ID: "555", object_type: "Beer"} 
    27         - {ID: "616", object_type: "Pamphlet"} 
     25        - {ID: "Dagger", object_type: "Dagger", slot: "right_hand"} 
     26        - {ID: "Beer", object_type: "Beer"} 
     27        - {ID: "Pamphlet", object_type: "Pamphlet"} 
    2828---             
    2929Janie: 
  • trunk/game/maps/map_agents.yaml

    r563 r565  
    2222    Rotation: 0 
    2323    Items: 
    24     - {ID: "456", object_type: "Dagger"} 
     24    - {ID: "Dagger", object_type: "Dagger"} 
    2525--- 
    2626ShantyDoor: 
     
    4040    Rotation: 255 
    4141    Items: 
    42     - {ID: "456", object_type: "Dagger"} 
     42    - {ID: "Dagger", object_type: "Dagger"} 
  • trunk/game/scripts/gamemodel.py

    r563 r565  
    4242       function heavy controller.""" 
    4343    ALL_AGENTS_KEY = "All" 
    44         
     44    MAX_ID_NUMBER = 1000 
     45     
    4546    def __init__(self, engine, settings): 
    4647        """Initialize the instance. 
     
    111112        info.update(extra) 
    112113        ID = info.pop("id") if info.has_key("id") else info.pop("ID") 
    113                  
    114         return CarryableItem(ID = ID, **info)   
     114        id_number = 0 
     115        while self.game_state.hasObject(ID + "_" + str(id_number)): 
     116            id_number += 1 
     117            if id_number > self.MAX_ID_NUMBER: 
     118                raise ValueError("Number exceeds MAX_ID_NUMBER:" +  
     119                                 str(self.MAX_ID_NUMBER)) 
     120        ID = ID + "_" + str(id_number) 
     121        new_item = CarryableItem(ID = ID, **info)  
     122        self.game_state.addObject(None, new_item) 
     123        return new_item 
    115124       
    116125    def createInventoryObject(self, container, attributes): 
     
    561570        if ref is None: 
    562571            # no, add it to the game state 
    563             self.game_state.objects[self.game_state.current_map_name][obj.ID] \ 
    564                                                                           = obj 
     572            self.game_state.addObject(self.game_state.current_map_name, obj) 
    565573        else: 
    566574            # yes, use the current game state data 
  • trunk/game/scripts/gamestate.py

    r563 r565  
    2424        self.quest_engine = quest_engine.QuestEngine() 
    2525        self.objects = {} 
     26        self.object_ids = {} 
    2627        self.current_map_name = None 
     28         
     29         
     30    def addObject(self, map_id, game_object): 
     31        """Adds an object to the objects and object_ids 
     32        dictionaries. 
     33        @param map_id: ID of the map the object is on.  
     34        If the object is in a container this has to be None 
     35        @param object: object to be added 
     36        @type object: GameObject 
     37        @type map_id: str or None 
     38        """ 
     39        object_id = game_object.ID 
     40        if not self.object_ids.has_key(object_id): 
     41            if map_id: 
     42                self.objects[map_id][object_id] = game_object 
     43            self.object_ids[object_id] = map_id 
    2744         
    2845    def getObjectsFromMap(self, map_id): 
     
    3653         
    3754        return {} 
     55     
     56    def hasObject(self, object_id): 
     57        """Check if an object with the given id is present  
     58        @param object_id: ID of the object 
     59        @type object_id: str 
     60        @return: True if there is an object False if not 
     61        """ 
     62        return self.object_ids.has_key(object_id) 
     63     
     64    def getMapOfObject(self, object_id): 
     65        """Returns the map the object is on. 
     66        @param object_id: ID of the object 
     67        @type object_id: str 
     68        @return: Name of the map the object is on.  
     69        If there is no such object or the object is in a container None is returned 
     70        """ 
     71        if self.object_ids.has_key(object_id): 
     72            return self.object_ids[object_id] 
     73        return None 
    3874     
    3975    def getObjectById(self, obj_id, map_id): 
     
    5389        """ 
    5490        self.objects = {} 
     91        self.object_ids = {} 
    5592         
    5693    def getStateForSaving(self): 
Note: See TracChangeset for help on using the changeset viewer.