# HG changeset patch # User KarstenBock@gmx.net # Date 1315399688 -7200 # Node ID dd9bd93ec81c7841b74aff9c579a91389ba31712 # Parent bf506f7393224db75f040978d24cffc24e4b4e18 Fixed NPC behaviour. NPCs are wandering around again. diff -r bf506f739322 -r dd9bd93ec81c behaviours/npc.py --- a/behaviours/npc.py Wed Sep 07 13:54:02 2011 +0200 +++ b/behaviours/npc.py Wed Sep 07 14:48:08 2011 +0200 @@ -15,6 +15,8 @@ from random import randrange +from fife import fife + import base from base import BaseBehaviour @@ -43,7 +45,7 @@ @return: NPC's position""" x = self.getX() y = self.getY() - if self.state == _AGENT_STATE_WANDER: + if self.state == base._AGENT_STATE_WANDER: """ Random Target Location """ l = [0, 0] for i in range(len(l)): @@ -69,7 +71,7 @@ @type action: ??? @param action: ??? @return: None""" - if self.state == _AGENT_STATE_WANDER: + if self.state == base._AGENT_STATE_WANDER: self.target_loc = self.getTargetLocation() self.idle() @@ -78,21 +80,28 @@ """Controls the NPC when it is idling. Different actions based on the NPC's state. @return: None""" - if self.state == _AGENT_STATE_NONE: - self.state = _AGENT_STATE_IDLE + if self.state == base._AGENT_STATE_NONE: + self.state = base._AGENT_STATE_IDLE self.agent.act('stand', self.agent.getFacingLocation()) - elif self.state == _AGENT_STATE_IDLE: + elif self.state == base._AGENT_STATE_IDLE: if self.wanderCounter > self.wanderRate: self.wanderCounter = 0 - self.state = _AGENT_STATE_WANDER + self.state = base._AGENT_STATE_WANDER else: self.wanderCounter += 1 - self.state = _AGENT_STATE_NONE + self.state = base._AGENT_STATE_NONE self.target_loc = self.getTargetLocation() self.agent.act('stand', self.agent.getFacingLocation()) - elif self.state == _AGENT_STATE_WANDER: - self.parent.wander(self.target_loc) - self.state = _AGENT_STATE_NONE - elif self.state == _AGENT_STATE_TALK: - self.agent.act('stand', self.pc.getLocation()) \ No newline at end of file + elif self.state == base._AGENT_STATE_WANDER: + self.wander(self.target_loc) + self.state = base._AGENT_STATE_NONE + elif self.state == base._AGENT_STATE_TALK: + self.agent.act('stand', self.pc.getLocation()) + + def wander(self, location): + """Nice slow movement for random walking. + @type location: fife.Location + @param location: Where the NPC will walk to. + @return: None""" + self.agent.move('walk', location, self.speed - 1) \ No newline at end of file