Debian Codegraph @

scripts/schedules/mapcharacters/sarin.py

raw symbols SCIP
1 #
2 # (C) Copyright 2001/2002 Kai Sterker <[email protected]>
3 # Part of the Adonthell Project http://adonthell.linuxgames.com
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY.
9 #
10 # See the COPYING file for more details
11 #
12
13 # -- Movement schedule for Sarin Trailfollower
14 #
15 # He walks from one end of the room to the other. From time to
16 # to time he'll stop and chose another direction
17
18 import adonthell
19 from schedules.mapcharacters import schedule
20 import random
21
22 def _(message): return message
23
24 class sarin (schedule.speak):
25
26 def __init__ (self, mapcharacterinstance):
27 self.myself = mapcharacterinstance
28
29 # -- Borders of the area he should stay in
30 self.min_x = 1
31 self.max_x = 6
32 self.min_y = 2
33 self.max_y = 6
34
35 self.direction = self.myself.get_val ("direction")
36
37 # -- make random remarks
38 self.speech = [_("Ruffians, the lot of them!"), \
39 _("How dare they imprison one better than they?"), \
40 _("This is an insult to all of the High Born."), \
41 _("I cannot believe such disrespect. Barbarians!")]
42 self.speech_delay = (20, 40)
43 schedule.speak.__init__(self)
44
45 self.myself.set_callback (self.goal_reached)
46
47 def switch_direction (self):
48 # -- ... and set the new one accordingly
49 if self.direction == adonthell.WALK_EAST or self.direction == adonthell.WALK_WEST:
50 self.direction = random.randrange (adonthell.WALK_NORTH, adonthell.WALK_SOUTH + 1)
51 else:
52 self.direction = random.randrange (adonthell.WALK_WEST, adonthell.WALK_EAST + 1)
53
54 delay = "%it" % random.randrange (30, 60)
55 self.myself.time_callback (delay, self.switch_direction)
56 self.walk ()
57
58 def walk (self):
59 # -- switch direction
60 if self.direction == adonthell.WALK_NORTH:
61 goal = (self.myself.posx (), self.min_y, adonthell.STAND_SOUTH, 0, 1)
62 elif self.direction == adonthell.WALK_SOUTH:
63 goal = (self.myself.posx (), self.max_y, adonthell.STAND_NORTH, 0, -1)
64 elif self.direction == adonthell.WALK_EAST:
65 goal = (self.max_x, self.myself.posy (), adonthell.STAND_WEST, -1, 0)
66 else:
67 goal = (self.min_x, self.myself.posy (), adonthell.STAND_EAST, 1, 0)
68
69 x, y, d = goal[:3]
70 self.direction = d + 4
71
72 while not self.myself.set_goal (x, y, d):
73 offx, offy = goal [-2:]
74 x = x + offx
75 y = y + offy
76
77 def goal_reached (self):
78 delay = "%it" % random.randrange (3, 6)
79 self.myself.time_callback (delay, self.walk)