Mercurial > parpg-core
changeset 190:a22e92090018
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 12 Nov 2011 20:54:25 +0100 |
parents | 61d158ce6bc3 |
children | c97e48257f51 |
files | src/parpg/behaviours/moving.py src/parpg/behaviours/npc.py src/parpg/entities/action.py src/parpg/gamescenecontroller.py |
diffstat | 4 files changed, 66 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parpg/behaviours/moving.py Sat Nov 12 16:27:39 2011 +0100 +++ b/src/parpg/behaviours/moving.py Sat Nov 12 20:54:25 2011 +0100 @@ -30,26 +30,34 @@ self.idle_counter = 1 - def approach(self, location, action=None): - """Approaches a location and then perform an action (if set). - @type loc: fife.Location - @param loc: the location to approach - @type action: Action - @param action: The action to schedule for execution after the approach. - @return: None""" + def approach(self, location_or_agent, action=None): + """Approaches a location or another agent and then perform an action + (if set). + @type loc: fife.Location + @param loc: the location or agent to approach + @type action: Action + @param action: The action to schedule for execution after the + approach. + @return: None""" + self.state = base._AGENT_STATE_APPROACH self.nextAction = action - boxLocation = tuple([int(float(i)) for i in location]) - l = fife.Location(self.agent.getLocation()) - l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) - self.agent.move('run', l, self.speed + 1) + if isinstance(location_or_agent, fife.Instance): + agent = location_or_agent + self.agent.follow('run', agent, self.speed + 1) + else: + location = location_or_agent + boxLocation = tuple([int(float(i)) for i in location]) + l = fife.Location(self.getLocation()) + l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) + self.agent.move('run', l, self.speed + 1) def onInstanceActionFinished(self, instance, action): """@type instance: ??? - @param instance: ??? - @type action: ??? - @param action: ??? - @return: None""" + @param instance: ??? + @type action: ??? + @param action: ??? + @return: None""" BaseBehaviour.onInstanceActionFinished(self, instance, action) if(action.getId() != 'stand'): @@ -64,9 +72,9 @@ def run(self, location): """Makes the PC run to a certain location - @type location: fife.ScreenPoint - @param location: Screen position to run to. - @return: None""" + @type location: fife.ScreenPoint + @param location: Screen position to run to. + @return: None""" self.state = base._AGENT_STATE_RUN self.clear_animations() self.nextAction = None @@ -74,9 +82,9 @@ def walk(self, location): """Makes the PC walk to a certain location. - @type location: fife.ScreenPoint - @param location: Screen position to walk to. - @return: None""" + @type location: fife.ScreenPoint + @param location: Screen position to walk to. + @return: None""" self.state = base._AGENT_STATE_RUN self.clear_animations() self.nextAction = None
--- a/src/parpg/behaviours/npc.py Sat Nov 12 16:27:39 2011 +0100 +++ b/src/parpg/behaviours/npc.py Sat Nov 12 20:54:25 2011 +0100 @@ -40,7 +40,7 @@ # I increased the wander rate to 900 since the idle method # gets called way more often now. self.wanderCounter = 0 - self.wanderRate = 900 + self.wanderRate = 9 def getTargetLocation(self): """@rtype: fife.Location
--- a/src/parpg/entities/action.py Sat Nov 12 16:27:39 2011 +0100 +++ b/src/parpg/entities/action.py Sat Nov 12 20:54:25 2011 +0100 @@ -324,50 +324,30 @@ @return: None""" player_char = self.model.game_state.\ getObjectById("PlayerCharacter").fifeagent - npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\ - getLayerCoordinates() - pc_coordinates = player_char.behaviour.agent.\ - getLocation().getLayerCoordinates() - - distance_squared = (npc_coordinates.x - pc_coordinates.x) *\ - (npc_coordinates.x - pc_coordinates.x) +\ - (npc_coordinates.y - pc_coordinates.y) *\ - (npc_coordinates.y - pc_coordinates.y) - - # If we are too far away, we approach the NPC again - if distance_squared > 2: - player_char.behaviour.approach( - [npc_coordinates.x, npc_coordinates.y], - TalkAction(self.controller, - self.npc, - self.commands - ) - ) + player_char.behaviour.animate( + 'stand', + self.npc.fifeagent.behaviour.getLocation() + ) + + if self.npc.dialogue.dialogue is not None: + dialogue_controller = DialogueController( + self.controller.engine, + self.view, + self.model, + self.controller.application + ) + self.controller.application.manager.push_mode( + dialogue_controller + ) + dialogue_controller.startTalk(self.npc) else: - player_char.behaviour.agent.act( - 'stand', - self.npc.fifeagent.behaviour.getLocation() - ) - - if self.npc.dialogue.dialogue is not None: - dialogue_controller = DialogueController( - self.controller.engine, - self.view, - self.model, - self.controller.application - ) - self.controller.application.manager.push_mode( - dialogue_controller - ) - dialogue_controller.startTalk(self.npc) - else: - self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000) - - self.model.game_state.getObjectById("PlayerCharacter").\ - fifeagent.behaviour.idle() - self.model.game_state.getObjectById("PlayerCharacter").\ - fifeagent.behaviour.nextAction = None - super(TalkAction, self).execute() + self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000) + + self.model.game_state.getObjectById("PlayerCharacter").\ + fifeagent.behaviour.idle() + self.model.game_state.getObjectById("PlayerCharacter").\ + fifeagent.behaviour.nextAction = None + super(TalkAction, self).execute() class UseAction(Action): """Action for carryable items. It executes special commands that can be only
--- a/src/parpg/gamescenecontroller.py Sat Nov 12 16:27:39 2011 +0100 +++ b/src/parpg/gamescenecontroller.py Sat Nov 12 20:54:25 2011 +0100 @@ -426,10 +426,10 @@ npc_info.general.identifier, self.model.game_state.current_map_name ) - npc_pos = npc.fifeagent.behaviour.getLocation().getLayerCoordinates() + npc_behaviour = npc.fifeagent.behaviour + npc_pos = npc_behaviour.getLocation().getLayerCoordinates() self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\ - behaviour.approach([npc_pos.x, - npc_pos.y], + behaviour.approach(npc_behaviour.agent, TalkAction(self, npc)) def getItemActions(self, obj_id): @@ -442,7 +442,8 @@ obj = self.model.game_state.\ getObjectById(obj_id, self.model.game_state.current_map_name) - obj_pos = obj.fifeagent.behaviour.getLocation().getLayerCoordinates() + #obj_pos = obj.fifeagent.behaviour.getLocation().getLayerCoordinates() + agent = obj.fifeagent.behaviour.agent player = self.model.game_state.getObjectById("PlayerCharacter") is_player = obj.general.identifier == player.general.identifier @@ -456,7 +457,7 @@ if obj.description and obj.description.desc: actions.append(["Examine", "Examine", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, ExamineAction(self, obj_id, obj.description.view_name, obj.description.desc)]) @@ -464,7 +465,7 @@ if obj.change_map: actions.append(["Change Map", "Change Map", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, ChangeMapAction(self, obj.change_map.target_map, obj.change_map.target_position)]) @@ -473,23 +474,23 @@ if not obj.lockable.locked: actions.append(["Open", "Open", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, OpenAction(self, obj)]) else: actions.append(["Close", "Close", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, CloseAction(self, obj)]) if obj.lockable.locked: actions.append(["Unlock", "Unlock", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, UnlockAction(self, obj)]) else: if obj.lockable.closed: actions.append(["Lock", "Lock", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, LockAction(self, obj)]) if obj.container: if obj.characterstats: @@ -498,12 +499,12 @@ elif not obj.lockable or not obj.lockable.closed: actions.append(["Examine contents", "Examine Contents", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, ExamineContentsAction(self, obj)]) if obj.containable: actions.append(["Pick Up", "Pick Up", player.fifeagent.behaviour.approach, - [obj_pos.x, obj_pos.y], + agent, PickUpAction(self, obj)]) return actions