Debian Codegraph @

scripts/schedules/mapcharacters/erek.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 Erek Stonebreaker
14 #
15 # Erek will either be in the parlour or the common room.
16 # He'll also help the player to get into Bjarn's room.
17
18 import adonthell
19 from schedules.mapcharacters import schedule
20 import random
21
22 def _(message): return message
23
24 class erek (schedule.speak):
25
26 def __init__ (self, mapcharacterinstance):
27 self.myself = mapcharacterinstance
28
29 # -- make random remarks
30 self.speech = [_("How could they do that to the Master?"), \
31 _("This place is so much different from home."), \
32 _("Who could have taken the gems?")]
33 self.speech_delay = (20, 40)
34 schedule.speak.__init__(self)
35
36 # -- the coordinates for normal schedule
37 self.coords = \
38 [(5, 5, adonthell.STAND_NORTH), \
39 (10, 6, adonthell.STAND_WEST), \
40 (5, 3, adonthell.STAND_NORTH), \
41 (4, 5, adonthell.STAND_SOUTH)]
42
43 # -- the coordinates for getting back to common room
44 self.to_common = \
45 [(0, 7, adonthell.STAND_WEST), \
46 (6, 1, adonthell.STAND_NORTH)]
47
48 # -- the coordinates for getting back to the 1st floor
49 self.to_1st = \
50 [(0, 7, adonthell.STAND_WEST), \
51 (6, 1, adonthell.STAND_NORTH), \
52 (12, 1, adonthell.STAND_NORTH), \
53 (2, 4, adonthell.STAND_SOUTH)]
54
55 self.walk_delay = "45t"
56
57 if self.myself.get_val ("goto") != 0:
58 self.myself.set_callback (self.leave_cellar)
59 else:
60 self.myself.set_callback (self.goal_reached)
61
62 def walk (self):
63 # -- in common room -> goto parlour
64 if self.myself.submap () == 1:
65 self.myself.set_goal (14, 4, adonthell.STAND_EAST)
66 self.walk_delay = "%it" % random.randrange (36, 108)
67
68 # -- in parlour -> goto common room
69 else:
70 self.myself.set_goal (0, 4, adonthell.STAND_WEST)
71 self.walk_delay = "%it" % random.randrange (20, 60)
72
73 def goal_reached (self):
74 # -- reached common room
75 if self.myself.submap () == 1 and self.myself.posx () == 13:
76 x, y, dir = self.coords[random.randrange (0, 2)]
77 self.myself.set_goal (x, y, dir)
78 # -- reached parlour
79 elif self.myself.submap () == 2 and self.myself.posx () == 1:
80 x, y, dir = self.coords[random.randrange (2, 4)]
81 self.myself.set_goal (x, y, dir)
82 # -- reached our final destination
83 else:
84 self.myself.time_callback (self.walk_delay, self.walk)
85
86 # -- leave Bjarn's room
87 def leave_bjarn (self):
88 # -- set alternative schedule
89 self.myself.set_callback (self.leave_cellar)
90
91 x, y, dir = self.to_common[0]
92 self.myself.set_goal (x, y, dir)
93 self.myself.set_val ("index", 0)
94
95 def leave_cellar (self):
96 index = self.myself.get_val ("index") + 1
97 goto = self.myself.get_val ("goto")
98
99 # -- goto first floor
100 if goto == 9: coords = self.to_1st
101 # -- goto common room
102 else: coords = self.to_common
103
104 if index < len (coords):
105 x, y, dir = coords[index]
106 self.myself.set_goal (x, y, dir)
107 self.myself.set_val ("index", index)
108
109 # -- arrived
110 else:
111 # -- restore normal schedule
112 self.myself.set_callback (self.goal_reached)
113 self.myself.set_val ("goto", 0)
114
115 if self.myself.submap () == 1:
116 x, y, dir = self.coords[random.randrange (0, 2)]
117 self.myself.set_goal (x, y, dir)
118 else:
119 self.myself.pause ()