1 from plomrogue.errors import GameError
2 from plomrogue.misc import quote
9 def __init__(self, thing, args=()):
17 def get_args_string(self):
21 stringed_args += [quote(arg)]
23 raise GameError('stringifying arg type not implemented')
24 return ' '.join(stringed_args)
28 class Task_WAIT(Task):
35 class Task_MOVE(Task):
36 argtypes = 'string:direction'
39 test_pos = self.thing.world.map_.move(self.thing.position, self.args[0])
40 if self.thing.world.map_[test_pos] != '.':
41 raise GameError('%s would move into illegal terrain' % self.thing.id_)
42 for t in self.thing.world.things:
43 if t.blocking and t.position == test_pos:
44 raise GameError('%s would move into other thing' % self.thing.id_)
47 self.thing.position = self.thing.world.map_.move(self.thing.position,
49 for id_ in self.thing.inventory:
50 t = self.thing.world.get_thing(id_)
51 t.position[:] = self.thing.position
55 class Task_PICKUP(Task):
56 argtypes = 'int:nonneg'
59 to_pick_up = self.thing.world.get_thing(self.args[0],
61 if to_pick_up is None or \
62 to_pick_up.in_inventory or \
63 to_pick_up == self.thing or \
64 self.thing.position != to_pick_up.position:
65 raise GameError('thing of ID %s not in reach to pick up'
69 to_pick_up = self.thing.world.get_thing(self.args[0])
70 self.thing.inventory += [self.args[0]]
71 to_pick_up.in_inventory = True
75 class Task_DROP(Task):
76 argtypes = 'int:nonneg'
79 to_pick_up = self.thing.world.get_thing(self.args[0],
81 if to_pick_up is None:
82 raise GameError('no thing of ID %s to drop' % self.args[0])
83 if to_pick_up.id_ not in self.thing.inventory:
84 raise GameError('no thing of ID %s to drop in inventory'
88 to_drop = self.thing.world.get_thing(self.args[0])
89 del self.thing.inventory[self.thing.inventory.index(to_drop.id_)]
90 to_drop.in_inventory = False