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):
24 def __init__(self, *args, **kwargs):
25 super().__init__(*args, **kwargs)
32 return self.__class__.get_type()
36 return cls.__name__[len('Thing_'):]
40 class Thing_Item(Thing):
46 class ThingSpawner(Thing):
50 for t in [t for t in self.game.things
51 if t != self and t.position == self.position]:
53 t = self.game.thing_types[self.child_type](self.game,
54 position=self.position)
55 self.game.things += [t]
56 self.game.changed = True
60 class Thing_ItemSpawner(ThingSpawner):
65 class Thing_SpawnPointSpawner(ThingSpawner):
66 child_type = 'SpawnPoint'
70 class Thing_SpawnPoint(Thing):
77 class Thing_DoorSpawner(ThingSpawner):
82 class Thing_Door(Thing):
99 class ThingAnimate(Thing):
102 def __init__(self, *args, **kwargs):
103 super().__init__(*args, **kwargs)
105 self.set_task('WAIT')
108 def set_task(self, task_name, args=()):
109 task_class = self.game.tasks[task_name]
110 self.task = task_class(self, args)
111 self.task.check() # will throw GameError if necessary
113 def set_next_task(self, task_name, args=()):
114 task_class = self.game.tasks[task_name]
115 self.next_tasks += [task_class(self, args)]
117 def get_next_task(self):
118 if len(self.next_tasks) > 0:
119 task = self.next_tasks.pop(0)
127 if self.task is None:
128 self.task = self.get_next_task()
133 except GameError as e:
137 if self.task.todo <= 0:
138 self._last_task_result = self.task.do()
139 self.game.changed = True
140 self.task = self.get_next_task()
143 def fov_stencil(self):
146 fov_map_class = self.game.map_geometry.fov_map_class
147 self._fov = fov_map_class(self.game.things, self.game.maps, self.position,
148 12, self.game.get_map)
151 def fov_test(self, big_yx, little_yx):
152 test_position = self.fov_stencil.target_yx(big_yx, little_yx)
153 if self.fov_stencil.inside(test_position):
154 if self.fov_stencil[test_position] == '.':
158 def fov_stencil_map(self, map_type='normal'):
160 for yx in self.fov_stencil:
161 if self.fov_stencil[yx] == '.':
162 big_yx, little_yx = self.fov_stencil.source_yxyx(yx)
163 map_ = self.game.get_map(big_yx, map_type)
164 visible_terrain += map_[little_yx]
166 visible_terrain += ' '
167 return visible_terrain
171 class Thing_Player(ThingAnimate):
174 def __init__(self, *args, **kwargs):
175 super().__init__(*args, **kwargs)