X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=plomrogue%2Fthings.py;h=895f5ce98938515e84670aa89b05694b01c6fbac;hb=51addf32b5a876c47325fb55756aacaea65ed0da;hp=15216efe5fdbaa8309a6f5b48bd5e4dc971dce2e;hpb=e5a83f8987647c3c239e48d5bc1ff939ce531544;p=plomrogue2 diff --git a/plomrogue/things.py b/plomrogue/things.py index 15216ef..895f5ce 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -1,4 +1,4 @@ -from plomrogue.errors import GameError +from plomrogue.errors import GameError, PlayError from plomrogue.mapping import YX @@ -141,14 +141,20 @@ class Thing_Door(Thing): -class Thing_Consumable(Thing): +class Thing_Bottle(Thing): symbol_hint = 'B' portable = True + full = True + thing_char = '~' + def empty(self): + self.thing_char = '_' + self.full = False -class Thing_ConsumableSpawner(ThingSpawner): - child_type = 'Consumable' + +class Thing_BottleSpawner(ThingSpawner): + child_type = 'Bottle' @@ -157,7 +163,6 @@ class Thing_MusicPlayer(Thing): symbol_hint = 'R' commandable = True portable = True - playlist = [] repeat = True next_song_start = datetime.datetime.now() playlist_index = 0 @@ -166,6 +171,7 @@ class Thing_MusicPlayer(Thing): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.next_song_start = datetime.datetime.now() + self.playlist = [] def proceed(self): if (not self.playing) or len(self.playlist) == 0: @@ -249,32 +255,50 @@ class Thing_MusicPlayer(Thing): +class Thing_BottleDeposit(Thing): + bottle_counter = 0 + symbol_hint = 'O' + + def proceed(self): + if self.bottle_counter >= 3: + self.bottle_counter = 0 + t = self.game.thing_types['MusicPlayer'](self.game, + position=self.position) + self.game.things += [t] + self.sound('BOTTLE DEPOSITOR', + 'here is a gift as a reward for ecological consciousness –' + 'use "command thing" on it to learn more!') + self.game.changed = True + + def accept(self): + self.bottle_counter += 1 + self.sound('BOTTLE DEPOSITOR', + 'thanks for this empty bottle – deposit %s more for a gift!' % + (3 - self.bottle_counter)) + + + + class ThingAnimate(Thing): blocking = True drunk = 0 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.next_tasks = [] - self.set_task('WAIT') + self.next_task = [None] + self.task = None self._fov = None - def set_task(self, task_name, args=()): - task_class = self.game.tasks[task_name] - self.task = task_class(self, args) - self.task.check() # will throw GameError if necessary - def set_next_task(self, task_name, args=()): task_class = self.game.tasks[task_name] - self.next_tasks += [task_class(self, args)] + self.next_task = [task_class(self, args)] def get_next_task(self): - if len(self.next_tasks) > 0: - task = self.next_tasks.pop(0) + if self.next_task[0]: + task = self.next_task[0] + self.next_task = [None] task.check() return task - else: - return None def proceed(self): self.drunk -= 1 @@ -283,6 +307,7 @@ class ThingAnimate(Thing): if self.game.sessions[c_id]['thing_id'] == self.id_: self.game.io.send('DEFAULT_COLORS', c_id) self.game.io.send('CHAT "You sober up."', c_id) + break self.game.changed = True self._fov = None if self.task is None: @@ -290,24 +315,37 @@ class ThingAnimate(Thing): return try: self.task.check() - except GameError as e: + except (PlayError, GameError) as e: self.task = None raise e self.task.todo -= 1 if self.task.todo <= 0: - self._last_task_result = self.task.do() + self.task.do() self.game.changed = True self.task = self.get_next_task() + def prepare_multiprocessible_fov_stencil(self): + fov_map_class = self.game.map_geometry.fov_map_class + fov_radius = 3 if self.drunk > 0 else 12 + self._fov = fov_map_class(self.game.things, self.game.maps, + self.position, fov_radius, self.game.get_map) + + def multiprocessible_fov_stencil(self): + self._fov.init_terrain() + @property def fov_stencil(self): if self._fov: return self._fov - fov_map_class = self.game.map_geometry.fov_map_class - self._fov = fov_map_class(self.game.things, self.game.maps, self.position, - 12, self.game.get_map) + # due to the pre-multiprocessing in game.send_gamestate, + # the following should actually never be called + self.prepare_multiprocessible_fov_stencil() + self.multiprocessible_fov_stencil() return self._fov + def fov_stencil_make(self): + self._fov.make() + def fov_test(self, big_yx, little_yx): test_position = self.fov_stencil.target_yx(big_yx, little_yx) if self.fov_stencil.inside(test_position):