Debian Codegraph @

scripts/schedules/mapcharacters/to_cellar.py

raw symbols SCIP
1 #
2 # (C) Copyright 2001/2002/2003 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 all characters to get to Bjarn's room
14
15 import adonthell
16 import random
17
18 class to_cellar(object):
19
20 def __init__ (self, mapcharacterinstance):
21 self.myself = mapcharacterinstance
22
23 # -- gives the proper exit for each submap to reach Bjarn's room
24 # (yard, common room, parlour, kitchen, cellar, bath, Alek's room,
25 # Bjarn's room, store room, 1st floor Fellnir's room, Frostbloom's
26 # room, Player's room, Silverhair's room)
27 self.exits = \
28 [(18, 13, adonthell.STAND_NORTH), \
29 (9, 1, adonthell.STAND_NORTH), \
30 (0, 4, adonthell.STAND_WEST), \
31 (6, 6, adonthell.STAND_SOUTH), \
32 (10, 7, adonthell.STAND_EAST), \
33 (4, 7, adonthell.STAND_SOUTH), \
34 (6, 6, adonthell.STAND_EAST), \
35 (-1, -1, -1), \
36 (7, 3, adonthell.STAND_EAST), \
37 (8, 1, adonthell.STAND_NORTH), \
38 (0, 3, adonthell.STAND_WEST), \
39 (5, 3, adonthell.STAND_EAST), \
40 (5, 1, adonthell.STAND_NORTH), \
41 (5, 1, adonthell.STAND_NORTH), \
42 (4, 1, adonthell.STAND_SOUTH)]
43
44 self.myself.set_callback (self.walk)
45
46
47 def walk (self):
48 x, y, dir = self.exits[self.myself.submap ()]
49
50 # -- in Bjarn's room
51 if x == -1:
52 self.myself.set_callback (self.goal_reached)
53
54 submap = self.myself.mymap ().get_submap (self.myself.submap ())
55 x = random.randint (2, 5)
56 y = random.randint (5, 9)
57
58 while not submap.get_square (x, y).is_free () or (y == 5 and x > 2):
59 x = random.randint (2, 5)
60 y = random.randint (5, 9)
61
62 # -- calculate direction
63 # -- north-western area
64 if x + y < 10:
65 if x + 3 > y: dir = adonthell.STAND_SOUTH
66 else: dir = adonthell.STAND_EAST
67 # -- south-east corner
68 else:
69 if y - (x + 3) > 0: dir = adonthell.STAND_NORTH
70 else: dir = adonthell.STAND_WEST
71
72 if not self.myself.set_goal (x, y, dir):
73 self.myself.time_callback ("1t", self.walk)
74
75 # -- teleport to the next exit
76 def warp (self):
77 x, y, dir = self.exits[self.myself.submap ()]
78 self.myself.jump_to (self.myself.submap (), x, y, dir)
79 self.myself.time_callback ("1t", self.walk)
80
81 # -- reached Bjarn's room
82 def goal_reached (self):
83 if self.myself.get_name () == adonthell.gamedata_player ().get_name ():
84 self.myself.set_schedule ("keyboard_control")
85 bjarn = adonthell.gamedata_get_character ("Bjarn Fingolson")
86 bjarn.set_dialogue ("dialogues.extro")
87 bjarn.pause ()
88 bjarn.stop_moving ()
89 bjarn.set_offset (0, 0)
90 bjarn.launch_action (self.myself)
91
92 else:
93 if self.myself.posx () == 1 and self.myself.posy () == 7:
94 self.walk ()
95 else:
96 self.myself.pause ()