1 from plomrogue.errors import GameError
2 from plomrogue.mapping import YX
9 def __init__(self, game, id_=0, position=(YX(0,0))):
12 self.id_ = self.game.new_thing_id()
15 self.position = position
19 class Thing(ThingBase):
22 def __init__(self, *args, **kwargs):
23 super().__init__(*args, **kwargs)
30 return self.__class__.get_type()
34 return cls.__name__[len('Thing_'):]
38 class Thing_Stone(Thing):
42 class ThingAnimate(Thing):
45 def __init__(self, *args, **kwargs):
46 super().__init__(*args, **kwargs)
51 def set_task(self, task_name, args=()):
52 task_class = self.game.tasks[task_name]
53 self.task = task_class(self, args)
54 self.task.check() # will throw GameError if necessary
56 def set_next_task(self, task_name, args=()):
57 task_class = self.game.tasks[task_name]
58 self.next_tasks += [task_class(self, args)]
60 def get_next_task(self):
61 if len(self.next_tasks) > 0:
62 task = self.next_tasks.pop(0)
71 self.task = self.get_next_task()
76 except GameError as e:
81 if self.task.todo <= 0:
82 self._last_task_result = self.task.do()
83 self.game.changed = True
84 self.task = self.get_next_task()
87 def fov_stencil(self):
90 fov_map_class = self.game.map_geometry.fov_map_class
91 self._fov = fov_map_class(self.game.map, self.position)
94 def fov_stencil_map(self, map):
96 for i in range(self.fov_stencil.size_i):
97 if self.fov_stencil.terrain[i] == '.':
98 visible_terrain += map.terrain[i]
100 visible_terrain += ' '
101 return visible_terrain
105 class Thing_Player(ThingAnimate):
108 def __init__(self, *args, **kwargs):
109 super().__init__(*args, **kwargs)