1 from plomrogue.errors import GameError
2 from plomrogue.mapping import YX
9 def __init__(self, game, id_=None, position=(YX(0,0))):
12 self.id_ = self.game.new_thing_id()
15 self.position = position
19 class Thing(ThingBase):
21 def __init__(self, *args, **kwargs):
22 super().__init__(*args, **kwargs)
29 class ThingAnimate(Thing):
31 def __init__(self, *args, **kwargs):
32 super().__init__(*args, **kwargs)
37 def set_task(self, task_name, args=()):
38 task_class = self.game.tasks[task_name]
39 self.task = task_class(self, args)
40 self.task.check() # will throw GameError if necessary
42 def set_next_task(self, task_name, args=()):
43 task_class = self.game.tasks[task_name]
44 self.next_tasks += [task_class(self, args)]
46 def get_next_task(self):
47 if len(self.next_tasks) > 0:
48 task = self.next_tasks.pop(0)
57 self.task = self.get_next_task()
62 except GameError as e:
67 if self.task.todo <= 0:
68 self._last_task_result = self.task.do()
69 self.game.changed = True
70 self.task = self.get_next_task()
73 def fov_stencil(self):
76 fov_map_class = self.game.map_geometry.fov_map_class
77 self._fov = fov_map_class(self.game.map, self.position)
80 def fov_stencil_map(self, map):
82 for i in range(self.fov_stencil.size_i):
83 if self.fov_stencil.terrain[i] == '.':
84 visible_terrain += map.terrain[i]
86 visible_terrain += ' '
87 return visible_terrain
91 class ThingPlayer(ThingAnimate):
94 def __init__(self, *args, **kwargs):
95 super().__init__(*args, **kwargs)
96 self.nickname = 'undefined'