# HG changeset patch # User KarstenBock@gmx.net # Date 1315484431 -7200 # Node ID 1bdadb768bcf8147664b2041f065d2350eec006c # Parent dd9bd93ec81c7841b74aff9c579a91389ba31712 Added approach functionality to the BaseBehaviour diff -r dd9bd93ec81c -r 1bdadb768bcf behaviours/base.py --- a/behaviours/base.py Wed Sep 07 14:48:08 2011 +0200 +++ b/behaviours/base.py Thu Sep 08 14:20:31 2011 +0200 @@ -64,5 +64,35 @@ self.state = _AGENT_STATE_IDLE self.agent.act('stand', self.agent.getFacingLocation()) + 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""" + self.state = _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) + def onInstanceActionFinished(self, instance, action): - pass \ No newline at end of file + """@type instance: ??? + @param instance: ??? + @type action: ??? + @param action: ??? + @return: None""" + # First we reset the next behavior + act = self.nextAction + self.nextAction = None + self.idle() + + if act: + act.execute() + + if(action.getId() != 'stand'): + self.idle_counter = 1 + else: + self.idle_counter += 1 \ No newline at end of file diff -r dd9bd93ec81c -r 1bdadb768bcf behaviours/npc.py --- a/behaviours/npc.py Wed Sep 07 14:48:08 2011 +0200 +++ b/behaviours/npc.py Thu Sep 08 14:20:31 2011 +0200 @@ -66,14 +66,13 @@ """What the NPC does when it has finished an action. Called by the engine and required for InstanceActionListeners. @type instance: fife.Instance - @param instance: self.agent (the NPC listener is listening for this - instance) + @param instance: self.agent @type action: ??? @param action: ??? @return: None""" if self.state == base._AGENT_STATE_WANDER: self.target_loc = self.getTargetLocation() - self.idle() + BaseBehaviour.onInstanceActionFinished(self, instance, action) def idle(self): diff -r dd9bd93ec81c -r 1bdadb768bcf behaviours/player.py --- a/behaviours/player.py Wed Sep 07 14:48:08 2011 +0200 +++ b/behaviours/player.py Thu Sep 08 14:20:31 2011 +0200 @@ -23,23 +23,4 @@ self.idle_counter = 1 self.speed = 0 self.nextAction = None - self.agent = None - - def onInstanceActionFinished(self, instance, action): - """@type instance: ??? - @param instance: ??? - @type action: ??? - @param action: ??? - @return: None""" - # First we reset the next behavior - act = self.nextAction - self.nextAction = None - self.idle() - - if act: - act.execute() - - if(action.getId() != 'stand'): - self.idle_counter = 1 - else: - self.idle_counter += 1 \ No newline at end of file + self.agent = None \ No newline at end of file