1 from plomrogue.errors import GameError
2 from plomrogue.mapping import YX
9 def __init__(self, game, id_=0, position=(YX(0, 0), 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_Item(Thing):
43 class Thing_Furniture(Thing):
48 class ThingAnimate(Thing):
51 def __init__(self, *args, **kwargs):
52 super().__init__(*args, **kwargs)
57 def set_task(self, task_name, args=()):
58 task_class = self.game.tasks[task_name]
59 self.task = task_class(self, args)
60 self.task.check() # will throw GameError if necessary
62 def set_next_task(self, task_name, args=()):
63 task_class = self.game.tasks[task_name]
64 self.next_tasks += [task_class(self, args)]
66 def get_next_task(self):
67 if len(self.next_tasks) > 0:
68 task = self.next_tasks.pop(0)
77 self.task = self.get_next_task()
82 except GameError as e:
86 if self.task.todo <= 0:
87 self._last_task_result = self.task.do()
88 self.game.changed = True
89 self.task = self.get_next_task()
92 def fov_stencil(self):
95 fov_map_class = self.game.map_geometry.fov_map_class
96 self._fov = fov_map_class(self.game.maps, self.position, 12,
100 def fov_test(self, big_yx, little_yx):
101 test_position = self.fov_stencil.target_yx(big_yx, little_yx)
102 if self.fov_stencil.inside(test_position):
103 if self.fov_stencil[test_position] == '.':
107 def fov_stencil_map(self, map_type='normal'):
109 for yx in self.fov_stencil:
110 if self.fov_stencil[yx] == '.':
111 big_yx, little_yx = self.fov_stencil.source_yxyx(yx)
112 map_ = self.game.get_map(big_yx, map_type)
113 visible_terrain += map_[little_yx]
115 visible_terrain += ' '
116 return visible_terrain
120 class Thing_Player(ThingAnimate):
123 def __init__(self, *args, **kwargs):
124 super().__init__(*args, **kwargs)