mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
* rulesets/basic/mind/Knowledge.py, rulesets/basic/mind/NPCMind.py: Add new methods to remove knowledge from mind.
30 lines
909 B
Python
30 lines
909 B
Python
#This file is distributed under the terms of the GNU General Public license.
|
|
#Copyright (C) 1999 Aloril (See the file COPYING for details).
|
|
|
|
class Knowledge:
|
|
def __init__(self):
|
|
self.place={}
|
|
self.location={}
|
|
self.goal={}
|
|
self.importance={}
|
|
def add(self, what, key, value):
|
|
if not hasattr(self, what):
|
|
setattr(self, what, {})
|
|
d=getattr(self,what)
|
|
d[key]=value
|
|
def remove(self, what, key):
|
|
if not hasattr(self, what):
|
|
return
|
|
d=getattr(self,what)
|
|
if d.has_key(key):
|
|
del d[key]
|
|
if len(d)==0:
|
|
delattr(self,what)
|
|
def __str__(self):
|
|
s="<know: "
|
|
s=s+"place: "+str(self.place)+"\n"
|
|
s=s+"location: "+str(self.location)+"\n"
|
|
s=s+"goal: "+str(self.goal)+"\n"
|
|
s=s+"importance: "+str(self.importance)+"\n"
|
|
return s+">\n"
|
|
|