""" mgoal.py
Copyright (C) 1998 Aloril
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import whrandom
import const
from goal import goal
from house import house
from mind import *
#goals for minds
def false(me): return 0
def true(me): return 1
############################ FIND HOME ####################################
def is_suitable_place_for_home(me):
"place is suitable is there is no homes in 100m radius"
count=len(me.mem.recall_place(me.get_xyz(),100.0))
return count==0
def find_place(me):
"find place for home: wander randomly"
(x,y,z)=me.get_xyz()
r=lambda :whrandom.uniform(-50,50)
return [event("move",what=me,loc=(x+r(),y+r(),z+r()))]
find_place_for_home=goal("find place for home not too near or far from others",
is_suitable_place_for_home,
[find_place])
def make_home(me):
"Starts home building"
me.add_knowledge("xyz","home",me.get_xyz())
return [event("make",what="house", what_desc="home", loc=me.get_xyz())]
def have_home(me):
"Do I have home?"
return me.things.has_key('house')
find_home=goal("find place for home and make it",
have_home,
[find_place_for_home,make_home])
############################ BUILD HOME ####################################
def have_build_home(me):
"Do I have home that is fully build?"
t=me.things.get('house')
if t: return t[0].status>=1.0-const.fzero
def build_house(me):
"Build my home"
h=me.things['house'][0]
return [event("change",what=h,amount=0.1)]
build_home=goal("find place for home and build it",
have_build_home,
[find_home, build_house])
########################## MAKE LOTS OF SOMETHING #################################
class make_amount(goal):
def __init__(self, what, amount, what_desc="some thing", place=None):
goal.__init__(self,"make certain amount of things",
self.are_all_done,
[move_me(place),self.do_all])
self.what=what
self.amount=amount
self.what_desc=what_desc
self.vars=["what","amount"]
def are_all_done(self, me):
t_list=me.find_thing(self.what)
if len(t_list)