Ignore:
Timestamp:
02/03/10 13:21:45 (10 years ago)
Author:
maximinus_parpg
Message:

More clean up of the code.
Finshed first pass.
So should be at least stands compliant.

Location:
trunk/game/scripts/objects
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/objects/__init__.py

    r342 r477  
    1515#   You should have received a copy of the GNU General Public License 
    1616#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
     17 
    1718import containers, doors 
    1819import actors 
     
    2324def getAllObjects (): 
    2425    """Returns a dictionary with the names of the concrete game object classes 
    25     mapped to the classes themselves""" 
     26       mapped to the classes themselves""" 
    2627    result = {} 
    2728    for module in object_modules: 
    2829        for class_name in module.__all__: 
    2930            result[class_name] = getattr (module,class_name) 
    30  
    3131    return result 
    3232 
    3333def createObject(info, extra = {}): 
    3434    """Called when we need to get an actual object. 
    35     @type info: dict 
    36     @param info: stores information about the object we want to create 
    37     @type extra: dict 
    38     @param extra: stores additionally required attributes, like agent layer, engine etc. 
    39     @return: the object""" 
     35       @type info: dict 
     36       @param info: stores information about the object we want to create 
     37       @type extra: dict 
     38       @param extra: stores additionally required attributes 
     39       @return: the object""" 
    4040    # First, we try to get the type and ID, which every game_obj needs. 
    4141    try: 
  • trunk/game/scripts/objects/action.py

    r451 r477  
    5151        """@type engine: Engine reference 
    5252           @param engine: A reference to the engine. 
    53            @param container: A reference to the container 
    54            """ 
     53           @param container: A reference to the container""" 
    5554        self.engine = engine 
    5655        self.container = container 
     
    6564        except ValueError: 
    6665            self.engine.view.hud.createExamineBox(self.container.name, \ 
    67                                               "The container is locked") 
     66                                                  "The container is locked") 
    6867         
    6968class UnlockBoxAction(Action): 
    7069    """Unlocks a box. Needs to be more generic, but will do for now.""" 
    7170    def __init__(self,  container): 
    72         """@param container: A reference to the container 
    73            """ 
     71        """@param container: A reference to the container""" 
    7472        self.container = container 
    7573     
     
    8179    """Locks a box. Needs to be more generic, but will do for now.""" 
    8280    def __init__(self, container): 
    83         """@param container: A reference to the container 
    84            """ 
     81        """@param container: A reference to the container""" 
    8582        self.container = container 
     83         
    8684    def execute(self): 
    8785        """Lock the box.""" 
     
    9795           @param examine_name: Name of the object to be examined. 
    9896           @type examine_name: String 
    99            @param examine_name: Description of the object to be examined. 
    100            """ 
     97           @param examine_name: Description of the object to be examined.""" 
    10198        self.engine = engine 
    10299        self.examine_name = examine_name 
     
    114111           @param engine: A reference to the engine. 
    115112           @type npc: NonPlayerCharacter 
    116            @param npc: NPC to interact with. 
    117            """ 
     113           @param npc: NPC to interact with.""" 
    118114        self.engine = engine 
    119115        self.npc = npc 
    120116         
    121117    def execute(self): 
    122         """Talk with the NPC when we are close enough, otherwise 
    123            we move close. 
     118        """Talk with the NPC when close enough, otherwise move closer. 
    124119           @return: None""" 
    125          
     120       
    126121        pc = self.engine.game_state.PC 
    127122        npc_coordinates = self.npc.getLocation().getLayerCoordinates() 
     
    129124         
    130125        distance_squared = (npc_coordinates.x - pc_coordinates.x) *\ 
    131                          (npc_coordinates.x - pc_coordinates.x) +\ 
    132                          (npc_coordinates.y - pc_coordinates.y) *\ 
    133                          (npc_coordinates.y - pc_coordinates.y) 
    134          
     126                           (npc_coordinates.x - pc_coordinates.x) +\ 
     127                           (npc_coordinates.y - pc_coordinates.y) *\ 
     128                           (npc_coordinates.y - pc_coordinates.y) 
    135129         
    136130        # If we are too far away, we approach the NPC again 
     
    152146                 
    153147            self.engine.game_state.PC.behaviour.idle() 
    154             self.engine.game_state.PC.nextAction = None  
     148            self.engine.game_state.PC.nextAction = None 
  • trunk/game/scripts/objects/actors.py

    r473 r477  
    3030 
    3131class ActorBehaviour (fife.InstanceActionListener): 
    32     """Fife agent listener 
    33     """ 
     32    """Fife agent listener""" 
    3433    def __init__(self, layer): 
    3534        fife.InstanceActionListener.__init__(self) 
     
    3736     
    3837    def attachToLayer(self, agent_ID): 
    39         """ Attaches to a certain layer 
    40             @type agent_ID: String 
    41             @param agent_ID: ID of the layer to attach to. 
    42             @return: None 
    43         """ 
     38        """Attaches to a certain layer 
     39           @type agent_ID: String 
     40           @param agent_ID: ID of the layer to attach to. 
     41           @return: None""" 
    4442        self.agent = self.layer.getInstance(agent_ID) 
    4543        self.agent.addActionListener(self) 
    4644        self.state = _AGENT_STATE_NONE 
    47         self.speed = float(TDS.readSetting("PCSpeed"))-1 # TODO: rework/improve 
     45        # TODO: rework/improve 
     46        self.speed = float(TDS.readSetting("PCSpeed"))-1 
    4847         
    4948    def getX(self): 
     
    6261        pass 
    6362 
    64      
    6563class PCBehaviour (ActorBehaviour): 
    6664    def __init__(self, parent = None, layer = None): 
    67         super(PCBehaviour, self).__init__(layer) 
    68          
     65        super(PCBehaviour, self).__init__(layer)         
    6966        self.parent = parent 
    7067        self.idle_counter = 1 
    71         self.speed = float(TDS.readSetting("PCSpeed")) # TODO: rework/improve 
     68        # TODO: rework/improve 
     69        self.speed = float(TDS.readSetting("PCSpeed")) 
    7270        self.nextAction = None 
    7371        self.agent = None 
     
    7977           @param action: ??? 
    8078           @return: None""" 
    81          
    8279        # First we reset the next behavior  
    8380        act = self.nextAction 
     
    9491             
    9592    def onNewMap(self, layer): 
    96         """Sets the agent onto the new layer. 
    97         """ 
     93        """Sets the agent onto the new layer.""" 
    9894        if self.agent is not None: 
    9995            self.agent.removeActionListener(self) 
     
    110106 
    111107class PlayerCharacter (GameObject, Living, CharStats): 
    112     """ 
    113     PC class 
    114     """ 
     108    """PC class""" 
    115109    def __init__ (self, ID, agent_layer = None, inventory = None, **kwargs): 
    116110        GameObject.__init__( self, ID, **kwargs ) 
     
    135129    def meet(self, npc): 
    136130        """Record that the PC has met a certain NPC 
    137         @type npc: str 
    138         @param npc: The NPC's name or id""" 
     131           @type npc: str 
     132           @param npc: The NPC's name or id""" 
    139133        if npc in self.peopleIknow: 
    140             """raise RuntimeError("I already know %s" % npc) 
    141                we could raise an error here, but should probably be a warn""" 
     134            # we could raise an error here, but should probably be a warn 
     135            # raise RuntimeError("I already know %s" % npc) 
    142136            return 
    143137        self.peopleIknow.add(npc) 
     
    145139    def met(self, npc): 
    146140        """Indicate whether the PC has met this npc before 
    147         @type npc: str 
    148         @param npc: The NPC's name or id 
    149         @return: None""" 
     141           @type npc: str 
     142           @param npc: The NPC's name or id 
     143           @return: None""" 
    150144        return npc in self.peopleIknow 
    151145 
    152146    def createBehaviour(self, layer): 
    153147        """Creates the behaviour for this actor. 
    154             @return None """ 
     148           @return: None""" 
    155149        self.behaviour = PCBehaviour(self, layer) 
    156150     
     
    242236           @type instance: fife.Instance 
    243237           @param instance: self.agent (the NPC listener is listening for this 
    244             instance) 
     238                                        instance) 
    245239           @type action: ??? 
    246240           @param action: ??? 
     
    269263 
    270264class NonPlayerCharacter(GameObject, Living, Scriptable, CharStats): 
    271     """ 
    272     NPC class 
    273     """ 
     265    """NPC class""" 
    274266    def __init__(self, ID, agent_layer=None, name='NPC', \ 
    275267                 text = 'A nonplayer character', inventory = None, **kwargs): 
     
    290282 
    291283    def createBehaviour(self, layer): 
    292         """ Creates the behaviour for this actor. 
    293             @return None """ 
     284        """Creates the behaviour for this actor. 
     285           @return None """ 
    294286        self.behaviour = NPCBehaviour(self, layer) 
    295287 
    296288    def getLocation(self): 
    297         """ Get the NPC's position as a fife.Location object. Basically a 
    298             wrapper. 
    299             @rtype: fife.Location 
    300             @return: the location of the NPC""" 
     289        """Get the NPC's position as a fife.Location object. Basically a 
     290           wrapper. 
     291           @rtype: fife.Location 
     292           @return: the location of the NPC""" 
    301293        return self.behaviour.agent.getLocation() 
    302294     
     
    315307 
    316308    def talk(self, pc): 
    317         """ Makes the NPC ready to talk to the PC 
    318             @return: None""" 
     309        """Makes the NPC ready to talk to the PC 
     310           @return: None""" 
    319311        self.behaviour.state = _AGENT_STATE_TALK 
    320312        self.behaviour.pc = pc.behaviour.agent 
  • trunk/game/scripts/objects/base.py

    r473 r477  
    5151           super(TinCan,self).__init__ (*args, **kwargs) 
    5252           self.name = 'Tin Can'""" 
     53            
    5354from fife import fife 
    5455from settings import Setting 
     
    6061    def __init__ (self, name="Dynamic object", **kwargs): 
    6162        """Initialise minimalistic set of data 
    62         @type name: String 
    63         @param name: Object display name 
    64         """ 
     63           @type name: String 
     64           @param name: Object display name""" 
    6565        self.name = name 
    6666 
     
    122122class Openable(object): 
    123123    """Adds open() and .close() capabilities to game objects 
    124     The current state is tracked by the .is_open variable""" 
     124       The current state is tracked by the .is_open variable""" 
    125125    def __init__(self, is_open = True, **kwargs): 
    126126        """Init operation for openable objects 
    127         @type is_open: Boolean 
    128         @param is_open: Keyword boolean argument sets the initial state.""" 
     127           @type is_open: Boolean 
     128           @param is_open: Keyword boolean argument sets the initial state.""" 
    129129        self.is_openable = True 
    130130        self.is_open = is_open 
     
    152152    def __init__ (self, locked = False, is_open = True, **kwargs): 
    153153        """Init operation for lockable objects 
    154         @type locked: Boolean 
    155         @param locked: Keyword boolen argument to set the initial locked state. 
    156         @type is_open: Boolean 
    157         @param is_open: Keyword boolean argument sets the initial open state. It is ignored if locked is True -- locked objects are always closed. 
    158         """ 
     154           @type locked: Boolean 
     155           @param locked: Keyword boolen argument sets the initial locked state. 
     156           @type is_open: Boolean 
     157           @param is_open: Keyword boolean argument sets the initial open state. 
     158                           It is ignored if locked is True -- locked objects 
     159                           are always closed.""" 
    159160        self.is_lockable = True 
    160         if locked == True: #HACK: For some reason locked appears to NOT be a bool. Needs investigation 
     161        # HACK: For some reason locked appears to NOT be a bool??? 
     162        # TODO: fix this, if only for our sanity! 
     163        if locked == True: 
    161164            locked = True 
    162165        else: locked = False 
     
    191194 
    192195    def getInventoryThumbnail(self): 
    193         #TODO: Implement properly after the objects database is in place 
     196        # TODO: Implement properly after the objects database is in place 
    194197        return "gui/inv_images/inv_litem.png" 
    195198     
     
    270273 
    271274    def findItem(self, **kwargs): 
    272         """Find an item in container by various attributes. All parameters are optional. 
     275        """Find an item in container by attributes. All params are optional. 
    273276           @type name: String 
    274            @param name: Unique or non-unique object name. If the name is non-unique, first matching object is returned 
     277           @param name: If the name is non-unique, return first matching object 
    275278           @type kind: String 
    276            @param kind: One of the possible object kinds like "openable" or "weapon" 
    277            @return: The item matching criteria or None if none was found 
    278         """ 
     279           @param kind: One of the possible object types 
     280           @return: The item matching criteria or None if none was found""" 
    279281        for i in self.items : 
    280282            if "name" in kwargs and self.items[i].name != kwargs["name"]: 
     
    288290    def __init__ (self, **kwargs): 
    289291        self.is_living = True 
     292 
    290293    def die(self): 
    291294        self.is_living = False 
  • trunk/game/scripts/objects/composed.py

    r451 r477  
    4343        return sum((item.weight for item in self.items.values()), self.own_weight) 
    4444 
    45  
    4645    def setWeight(self, weight): 
    4746        """Set container's own weight. For compatibility with inherited methods""" 
     
    6463                                    str(self.items[b])), self.items,""))+" ]" 
    6564 
    66  
    6765class SingleItemContainer (CarryableContainer) : 
    68     """Container that can only store a single item. This class can represent single-item inventory slots""" 
     66    """Container that can only store a single item. 
     67       This class can represent single-item inventory slots""" 
    6968    def __init__ (self, **kwargs): 
    7069        CarryableContainer.__init__(self, **kwargs) 
     
    7675 
    7776class CarryableItem (GameObject, Carryable): 
    78     """Composite class that will be used for all carryable items, weapons, etc. 
    79     """ 
     77    """Composite class that will be used for all carryable items""" 
    8078    def __init__(self, **kwargs): 
    8179        GameObject.__init__(self,**kwargs) 
     
    8482class Door(GameObject, Lockable, Scriptable, Trappable): 
    8583    """Composite class that can be used to create doors on a map.""" 
    86     def __init__ (self, target_map_name = 'my-map', target_map = 'map/map.xml', target_x = 0.0, \ 
    87                         target_y = 0.0, **kwargs): 
    88         GameObject   .__init__(self, **kwargs) 
    89         Lockable     .__init__(self, **kwargs) 
    90         Scriptable   .__init__(self, **kwargs) 
    91         Trappable    .__init__(self, **kwargs) 
     84    def __init__ (self, target_map_name = 'my-map', target_map = 'map/map.xml', 
     85                  target_x = 0.0, target_y = 0.0, **kwargs): 
     86        GameObject.__init__(self, **kwargs) 
     87        Lockable.__init__(self, **kwargs) 
     88        Scriptable.__init__(self, **kwargs) 
     89        Trappable.__init__(self, **kwargs) 
    9290        self.is_door = True 
    9391        self.target_map_name = target_map_name 
  • trunk/game/scripts/objects/containers.py

    r473 r477  
    1717 
    1818"""Containes classes defining concrete container game objects like crates, 
    19 barrels, chests, etc.""" 
     19   barrels, chests, etc.""" 
    2020 
    2121__all__ = ["WoodenCrate", "Footlocker"] 
    2222 
    23 _AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, _AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5) 
     23_AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, \ 
     24_AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5) 
    2425 
    2526from composed import ImmovableContainer 
     
    2829 
    2930class WoodenCrate (ImmovableContainer): 
    30     def __init__ (self, ID, name = 'Wooden Crate', \ 
    31             text = 'A battered crate', gfx = 'crate', **kwargs): 
     31    def __init__ (self, ID, name = 'Wooden Crate', 
     32                  text = 'A battered crate', gfx = 'crate', **kwargs): 
    3233        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    3334                text = text, **kwargs) 
     
    3536         
    3637class Footlocker(ImmovableContainer, fife.InstanceActionListener): 
    37     def __init__ (self, ID, agent_layer=None, name = 'Footlocker', \ 
    38                text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 
    39         ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    40                 text = text, **kwargs) 
     38    def __init__ (self, ID, agent_layer=None, name = 'Footlocker', 
     39                  text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 
     40        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, 
     41                                    text = text, **kwargs) 
    4142        self.placeItem(CarryableItem(ID=987,name="Dagger456")) 
    4243 
     
    7475        if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 
    7576            self.agent.act('close', self.agent.getLocation()) 
    76             self.state = _AGENT_STATE_CLOSING        
     77            self.state = _AGENT_STATE_CLOSING 
  • trunk/game/scripts/objects/doors.py

    r373 r477  
    2323 
    2424class ShantyDoor(Door): 
    25     def __init__ (self, ID, name = 'Shanty Door', \ 
    26             text = 'A door', gfx = 'shanty-door', target_map_name = 'my-map', \ 
    27             target_map = 'map.xml', target_x = 0.0, target_y = 0.0,\ 
    28             **kwargs): 
    29         Door.__init__(self, ID = ID, name = name, text = text, gfx = gfx, \ 
    30             target_map_name = target_map_name, target_map = target_map, \ 
    31             target_x = target_x, target_y = target_y, **kwargs) 
    32  
     25    def __init__ (self, ID, name = 'Shanty Door', text = 'A door', 
     26                   gfx = 'shanty-door', target_map_name = 'my-map', 
     27                   target_map = 'map.xml', target_x = 0.0, 
     28                   target_y = 0.0, **kwargs): 
     29        Door.__init__(self, ID = ID, name = name, text = text, gfx = gfx, 
     30                      target_map_name = target_map_name, 
     31                      target_map = target_map, target_x = target_x, 
     32                      target_y = target_y, **kwargs) 
Note: See TracChangeset for help on using the changeset viewer.