home · contact · privacy
Make some things block movement, and others not.
[plomrogue2] / plomrogue / tasks.py
1 from plomrogue.errors import PlayError, GameError
2 from plomrogue.mapping import YX
3
4
5
6 class Task:
7     argtypes = ''
8     todo = 3
9
10     def __init__(self, thing, args=()):
11         self.thing = thing
12         self.args = args
13
14     def check(self):
15         pass
16
17
18
19 class Task_WAIT(Task):
20     todo = 1
21
22     def do(self):
23         return 'success'
24
25
26
27 class Task_MOVE(Task):
28     todo = 1
29     argtypes = 'string:direction'
30
31     def get_move_target(self):
32         return self.thing.game.map_geometry.move(self.thing.position,
33                                                  self.args[0])
34
35     def check(self):
36         test_pos = self.get_move_target()
37         if test_pos is None:
38             raise PlayError('would move out of map')
39         elif test_pos in [t.position for t in self.thing.game.things
40                           if t.blocking]:
41             raise PlayError('blocked by other thing')
42         elif self.thing.game.map[test_pos] != '.':
43             raise PlayError('would move into illegal territory')
44
45     def do(self):
46         self.thing.position = self.get_move_target()
47
48
49
50 class Task_WRITE(Task):
51     todo = 1
52     argtypes = 'string:char string'
53
54     def check(self):
55         if not self.thing.game.can_do_tile_with_pw(self.thing.position,
56                                                    self.args[1]):
57             raise GameError('wrong password for tile')
58
59     def do(self):
60         self.thing.game.map[self.thing.position] = self.args[0]
61
62
63
64 class Task_FLATTEN_SURROUNDINGS(Task):
65     todo = 10
66     argtypes = 'string'
67
68     def check(self):
69         pass
70
71     def do(self):
72         for yx in[self.thing.position] + \
73             list(self.thing.game.map_geometry.get_neighbors(self.thing.position).values()):
74             if yx is not None:
75                 if not self.thing.game.can_do_tile_with_pw(yx, self.args[0]):
76                     continue
77                 self.thing.game.map[yx] = '.'