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):
21 def __init__(self, *args, **kwargs):
22 super().__init__(*args, **kwargs)
29 return self.__class__.get_type()
33 return cls.__name__[len('Thing_'):]
37 class Thing_Stone(Thing):
41 class ThingAnimate(Thing):
43 def __init__(self, *args, **kwargs):
44 super().__init__(*args, **kwargs)
49 def set_task(self, task_name, args=()):
50 task_class = self.game.tasks[task_name]
51 self.task = task_class(self, args)
52 self.task.check() # will throw GameError if necessary
54 def set_next_task(self, task_name, args=()):
55 task_class = self.game.tasks[task_name]
56 self.next_tasks += [task_class(self, args)]
58 def get_next_task(self):
59 if len(self.next_tasks) > 0:
60 task = self.next_tasks.pop(0)
69 self.task = self.get_next_task()
74 except GameError as e:
79 if self.task.todo <= 0:
80 self._last_task_result = self.task.do()
81 self.game.changed = True
82 self.task = self.get_next_task()
85 def fov_stencil(self):
88 fov_map_class = self.game.map_geometry.fov_map_class
89 self._fov = fov_map_class(self.game.map, self.position)
92 def fov_stencil_map(self, map):
94 for i in range(self.fov_stencil.size_i):
95 if self.fov_stencil.terrain[i] == '.':
96 visible_terrain += map.terrain[i]
98 visible_terrain += ' '
99 return visible_terrain
103 class Thing_Player(ThingAnimate):
106 def __init__(self, *args, **kwargs):
107 super().__init__(*args, **kwargs)
108 self.nickname = 'undefined'