-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Brain instance to the character class/objects. to-do: make use of the new Brain class/instance.
- Loading branch information
Florian R. A. Angermeier
committed
Jun 26, 2011
1 parent
5df350e
commit 375cd38
Showing
2 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
|
||
class Brain: | ||
# The brain class provides attributes and methodes for the ai of an character. | ||
|
||
def __init__( self, character ): | ||
self.character = character | ||
self.activitiesHigh = { 'sleep': 'rest', | ||
'food': 'eatSnack', | ||
'water': 'drink', | ||
'urination': 'use', | ||
'hygiene': 'shower' | ||
'fun': 'watch', | ||
'social': 'talk' } | ||
self.activitiesMedium = { 'sleep': 'rest', | ||
'food': 'cook', | ||
'water': 'drink', | ||
'urination': 'use', | ||
'hygiene': 'shower' | ||
'fun': 'watch', | ||
'social': 'talk' } | ||
self.activitiesLow = { 'sleep': 'sleep', | ||
'food': 'cook', | ||
'water': 'drink', | ||
'urination': 'use', | ||
'hygiene': 'shower' | ||
'fun': 'watch', | ||
'social': 'talk' } | ||
|
||
def getLowestNeed( self ): | ||
# Returns the lowest need including its value as a tuple. | ||
lowestNeed = (None, 1000) | ||
for need in self.character.needs.keys(): | ||
try: | ||
if( self.character.needs[need] < lowestNeed(1) ): | ||
lowestNeed(0) = need | ||
lowestNeed(1) = self.character.needs[need] | ||
except: | ||
print '\033[31mError\033[0m Character: %i\tNeed %s does not exist.' % ( self.character.id, need ) | ||
return lowestNeed | ||
|
||
def getHighestNeed( self ): | ||
# Returns the highest need including its value as a tuple. | ||
highestNeed = (None, 0) | ||
for need in self.character.needs.keys(): | ||
try: | ||
if( self.character.needs[need] > highestNeed(1) ): | ||
highestNeed(0) = need | ||
highestNeed(1) = self.character.needs[need] | ||
except: | ||
print '\033[31mError\033[0m Character: %i\tNeed %s does not exist.' % ( self.character.id, need ) | ||
return highestNeed | ||
|
||
def getNextActivity( self ): | ||
# Get the next activity to satisfy the lowest need. | ||
if( self.getLowestNeed()(1) <= 750 ): # 3/4, High | ||
return self.activitiesHigh[ self.getLowestNeed()(0) ] | ||
elif( self.getLowestNeed()(1) <= 500 ): # 1/2, Medium | ||
return self.activitiesMedium[ self.getLowestNeed()(0) ] | ||
elif( self.getLowestNeed()(1) <= 250 ): # 1/4, Low | ||
return self.activitiesLow[ self.getLowestNeed()(0) ] | ||
else: | ||
return None | ||
|
||
def getObjectById( self, id ): | ||
# Searches for an object in the world by id and returns it. | ||
for object in self.character.world.objects: | ||
if( object.id == id ): | ||
return object | ||
|
||
def getObjectByType( self, type ): | ||
# Searches for an object in the world by type and returns it. | ||
for object in self.character.world.objects: | ||
if( object.type == type ): | ||
return object | ||
|
||
def isInRange( self, characterOrObject, radiusType ): | ||
# Checks if a character or object is in range by utilization of a bounding box and returns True if the object is in range. | ||
# X axis | ||
if( self.character.pos[ 0 ] >= characterOrObject.pos[ 0 ] - characterOrObject.radii[ radiusType ] | ||
self.character.pos[ 0 ] <= characterOrObject.pos[ 0 ] + characterOrObject.radii[ radiusType ] ): | ||
# Y axis | ||
if( self.character.pos[ 1 ] >= characterOrObject.pos[ 1 ] - characterOrObject.radii[ radiusType ] | ||
self.character.pos[ 1 ] <= characterOrObject.pos[ 1 ] + characterOrObject.radii[ radiusType ] ): | ||
# Z axis | ||
if( self.character.pos[ 2 ] >= characterOrObject.pos[ 2 ] - characterOrObject.radii[ radiusType ] | ||
self.character.pos[ 2 ] <= characterOrObject.pos[ 2 ] + characterOrObject.radii[ radiusType ] ): | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters