cyphesis/data/rulesets/basic/scripts/mind/Memory.py

47 lines
1.4 KiB
Python
Raw Permalink Normal View History

2018-10-11 22:48:46 +02:00
# This file is distributed under the terms of the GNU General Public license.
# Copyright (C) 1999 Aloril (See the file COPYING for details).
2020-01-04 20:20:30 +01:00
from common import const
2018-10-11 22:48:46 +02:00
class Memory:
2020-01-04 20:20:30 +01:00
def __init__(self, a_map):
2018-10-11 22:48:46 +02:00
self.events = []
2020-01-04 20:20:30 +01:00
self.map = a_map
2018-10-11 22:48:46 +02:00
def destroy(self):
2018-10-11 22:48:46 +02:00
self.events = None
self.map = None
2020-01-04 20:20:30 +01:00
def recall_place(self, location, radius, a_filter):
try:
2020-01-05 11:11:44 +01:00
if isinstance(a_filter, list):
2020-01-04 20:20:30 +01:00
for i in a_filter:
result = self.map.find_by_location_query(location, radius, i)
2018-10-11 22:48:46 +02:00
if len(result) != 0:
return result
else:
2020-01-04 20:20:30 +01:00
return self.map.find_by_location_query(location, radius, a_filter)
except RuntimeError:
2018-10-11 22:48:46 +02:00
# Expect the location to be incomplete and handle it
return None
2018-10-11 22:48:46 +02:00
def remember_event(self, event):
2020-01-04 20:20:30 +01:00
"""add new memory with age"""
2018-10-11 22:48:46 +02:00
self.events.append([event, 1.0])
def recall_event(self, event, cmp):
2020-01-04 20:20:30 +01:00
"""return list of memories with same command"""
2018-10-11 22:48:46 +02:00
found = []
for (e, age) in self.events:
2020-01-04 20:20:30 +01:00
if cmp(*(event, e)):
found.append(e)
return found
2018-10-11 22:48:46 +02:00
def forget(self):
2020-01-04 20:20:30 +01:00
"""age memories and forgot too old ones"""
for m in self.events:
2018-10-11 22:48:46 +02:00
m[1] = m[1] - 0.1
# remove forgotten things
self.events = [m for m in self.events if m[1] > const.fzero]