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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.