X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=new%2Fplomrogue%2Fthings.py;h=20ce4867c2211882b506de309d8881eb16842379;hb=729e72408fa1c3180275ad3c0e6689143a0f2f38;hp=a80e9e40913e9eac6e06221577cfe5815477a1a5;hpb=7d8ed36999f496383de39a76aee8dfb8e1bfbef7;p=plomrogue2-experiments diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index a80e9e4..20ce486 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -3,16 +3,38 @@ from plomrogue.errors import GameError class ThingBase: + type_ = '?' - def __init__(self, world, id_, type_='?', position=[0,0]): + def __init__(self, world, id_=None, position=(0,0)): self.world = world - self.id_ = id_ - self.type_ = type_ self.position = position + if id_ is None: + self.id_ = self.world.new_thing_id() + else: + self.id_ = id_ class Thing(ThingBase): + blocking = False + in_inventory = False + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.inventory = [] + + def proceed(self): + pass + + + +class ThingItem(Thing): + type_ = 'item' + + + +class ThingAnimate(Thing): + blocking = True def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -41,7 +63,7 @@ class Thing(ThingBase): neighbors = dijkstra_map.get_neighbors(tuple(self.position)) n = n_max target_direction = None - for direction in neighbors: + for direction in sorted(neighbors.keys()): yx = neighbors[direction] if yx is not None: n_new = dijkstra_map[yx] @@ -123,6 +145,26 @@ class Thing(ThingBase): stencil = self.get_stencil() visible_things = [] for thing in self.world.things: - if stencil[thing.position] == '.': + if (not thing.in_inventory) and stencil[thing.position] == '.': visible_things += [thing] return visible_things + + def get_pickable_items(self): + pickable_ids = [] + for t in [t for t in self.get_visible_things() if + isinstance(t, ThingItem) and + (t.position == self.position or + t.position in + self.world.map_.get_neighbors(self.position).values())]: + pickable_ids += [t.id_] + return pickable_ids + + + +class ThingHuman(ThingAnimate): + type_ = 'human' + + + +class ThingMonster(ThingAnimate): + type_ = 'monster'