Changeset 212


Ignore:
Timestamp:
07/22/09 18:54:38 (10 years ago)
Author:
tZee_parpg
Message:

#70 Merged the approach functions and added a tiny action queue for the PC.

Location:
trunk/PARPG/scripts
Files:
1 added
2 edited

Legend:

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

    r199 r212  
    2121from objects import * 
    2222from objectLoader import ObjectXMLParser 
     23from objects.action import * 
    2324 
    2425# design note: 
     
    225226                actions.append(["Attack", "Attack", self.nullFunc, obj])  
    226227            elif obj.trueAttr("Door"): 
    227                 #actions.append(["Change Map", "Change Map", \ 
    228                 #       self.gameState.PC.approachDoor, [obj.X, obj.Y], \ 
    229                 #        self.doors[str(i.ID)].map, [i.destx, i.desty]]) 
     228                actions.append(["Change Map", "Change Map", \ 
     229                       self.gameState.PC.approach, [obj.X, obj.Y], \ 
     230                        ChangeMapAction(self, self.doors[str(i.ID)].map, [i.destx, i.desty])]) 
    230231                pass 
    231232            else: 
    232                 actions.append(["Examine", "Examine", self.gameState.PC.approachAndExamine,  
    233                                 [obj.X, obj.Y], obj.name, obj.desc]) 
     233                actions.append(["Examine", "Examine", self.gameState.PC.approach,  
     234                                [obj.X, obj.Y], ExamineBoxAction(self, obj.name, obj.desc)]) 
    234235                # is it a container? 
    235236                if obj.trueAttr("container"): 
    236                     actions.append(["Open", "Open", self.gameState.PC.approachBox, [obj.X, obj.Y]]) 
     237                    actions.append(["Open", "Open", self.gameState.PC.approach, [obj.X, obj.Y], OpenBoxAction(self, "Box")]) 
    237238                # can you pick it up? 
    238239                if obj.trueAttr("carryable"): 
     
    252253        if npc: 
    253254            npc.talk() 
    254         self.gameState.PC.approachNPC(npc.getLocation()) 
     255        self.gameState.PC.approach([npc.getLocation().getLayerCoordinates().x, npc.getLocation().getLayerCoordinates().y]) 
    255256 
    256257    def loadMap(self, map_file): 
  • trunk/PARPG/scripts/objects/actors.py

    r211 r212  
    2424 
    2525TDS = Setting() 
    26 _AGENT_STATE_NONE, _AGENT_STATE_IDLE, _AGENT_STATE_RUN, _AGENT_STATE_WANDER, _AGENT_STATE_TALK = xrange(5) 
     26_AGENT_STATE_NONE, _AGENT_STATE_IDLE, _AGENT_STATE_APPROACH, _AGENT_STATE_RUN, _AGENT_STATE_WANDER, _AGENT_STATE_TALK = xrange(6) 
    2727 
    2828class ActorBehaviour (fife.InstanceActionListener): 
     
    5757     
    5858class PCBehaviour (ActorBehaviour): 
    59     def __init__(self, Parent = None, Layer = None, Engine = None): 
     59    def __init__(self, Parent = None, Layer = None): 
    6060        super(PCBehaviour, self).__init__(Layer) 
    6161         
    6262        self.parent = Parent 
    63         self.engine = Engine 
    6463        self.idlecounter = 1 
    6564        self.speed = float(TDS.readSetting("PCSpeed")) # TODO: rework/improve 
    6665        self.nextAction = None 
    67         self.boxTitle = None 
    68         self.examineName = None 
    69         self.examineDesc = None 
    7066         
    7167    def onInstanceActionFinished(self, instance, action): 
     
    7571           @param action: ??? 
    7672           @return: None""" 
    77         if action.getId() == 'approachDoor': 
    78             # issue map change 
    79             self.engine.changeMap(self.targetMap, self.targetLocation) 
    80         if self.state == _AGENT_STATE_TALK: 
    81             # TODO: do something 
    82             pass 
    83         if self.nextAction == "open_box": 
    84             self.engine.view.createBoxGUI(self.boxTitle) 
     73        if self.nextAction: 
     74            self.nextAction.execute() 
    8575            self.nextAction = None 
    86         elif self.nextAction == "examine_obj": 
    87             self.engine.view.createExamineBox(self.examineName, self.examineDesc) 
    88             self.nextAction = None 
    89  
    90         self.idle() 
     76        else: 
     77            self.idle() 
     78             
    9179        if(action.getId() != 'stand'): 
    9280            self.idlecounter = 1 
     
    11199    PC class 
    112100    """ 
    113     def __init__ (self, ID, agent_layer = None, engine = None, **kwargs): 
     101    def __init__ (self, ID, agent_layer = None, **kwargs): 
    114102        super(PlayerCharacter, self).__init__(ID, **kwargs) 
    115103        self.is_PC = True 
     
    119107         
    120108        self.state = _AGENT_STATE_NONE 
    121         self.behaviour = PCBehaviour(self, agent_layer, engine) 
     109        self.behaviour = PCBehaviour(self, agent_layer) 
    122110     
    123111    def setup(self): 
     
    136124        self.behaviour.agent.move('run', location, self.behaviour.speed) 
    137125         
    138     def approachNPC(self, npcLoc): 
     126    def approach(self, location, action = None): 
    139127        """Approaches an npc and then ???. 
    140            @type npcLoc: fife.Location 
    141            @param npcLoc: the location of the NPC to approach 
    142            @return: None""" 
    143         self.state = _AGENT_STATE_TALK 
    144         self.behaviour.agent.move('run', npcLoc, self.behaviour.speed) 
    145  
    146     def approachDoor(self, doorLocation, map, targetLocation): 
    147         """Approach a door and then teleport to the new map. 
    148            @type doorLocation: list 
    149            @param doorLocation: list that is converted to a fife.Location 
    150             that tells the PC where the door is 
    151            @type map: ??? 
    152            @param map: ??? 
    153            @type targetLocation: list 
    154            @param targetLocation: list that is converted to a tuple 
    155             that tels the PC where it should appear on the target map 
    156            @return: None""" 
    157         # The casting here is HORRIBLE, but I think it is preferable to having 
    158         # doors behave differently than other objects, hence the change. 
    159         self.state = _AGENT_STATE_RUN 
    160         targetLocation = tuple([int(float(i)) for i in targetLocation]) 
    161         doorLocation = tuple([int(float(i)) for i in doorLocation]) 
    162         self.targetMap = map 
    163         self.targetLocation = targetLocation 
    164         l = fife.Location(self.agent.getLocation()) 
    165         l.setLayerCoordinates(fife.ModelCoordinate(*doorLocation)) 
    166         self.behaviour.agent.move('approachDoor', l, self.behaviour.speed) 
    167          
    168     def approachBox(self, location, title): 
    169         """ 
    170         Approach a box and then open it 
    171         @type location: list 
    172         @param locatation: list that is converted to a fife.Location 
    173         @type title: string 
    174         @param title: The title for the window 
    175         @return: None 
    176         """ 
    177         self.state = _AGENT_STATE_RUN 
     128           @type loc: fife.Location 
     129           @param loc: the location to approach 
     130           @type action: Action 
     131           @param action: The action to schedule for execution after the approach. 
     132           @return: None""" 
     133        self.state = _AGENT_STATE_APPROACH 
     134        self.behaviour.nextAction = action 
    178135        boxLocation = tuple([int(float(i)) for i in location]) 
    179136        l = fife.Location(self.behaviour.agent.getLocation()) 
    180137        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) 
    181         self.behaviour.agent.move('run', l, self.behaviour.speed) 
    182         self.behaviour.nextAction = "open_box" 
    183         self.behaviour.boxTitle = title 
    184  
    185     def approachAndExamine(self, location, name, description): 
    186         """ 
    187         Approach something and then examine it 
    188         @type location: list 
    189         @param location: list that is converted to fife.Location 
    190         @type name: string 
    191         @param name: The name of the object 
    192         @type description: string 
    193         @param description: a detailed description of the object 
    194         @return: None 
    195         """ 
    196         self.state = _AGENT_STATE_RUN 
    197         objLocation = tuple([int(float(i)) for i in location]) 
    198         l = fife.Location(self.behaviour.agent.getLocation()) 
    199         l.setLayerCoordinates(fife.ModelCoordinate(*objLocation)) 
    200         self.behaviour.nextAction = "examine_obj" 
    201         self.behaviour.examineName = name 
    202         self.behaviour.examineDesc = description 
    203138        self.behaviour.agent.move('run', l, self.behaviour.speed) 
    204139 
Note: See TracChangeset for help on using the changeset viewer.