File: to_cellar.py

package info (click to toggle)
adonthell-data 0.3.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,776 kB
  • ctags: 389
  • sloc: python: 4,667; sh: 3,327; makefile: 362; sed: 16
file content (94 lines) | stat: -rw-r--r-- 3,433 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
#  (C) Copyright 2001/2002/2003 Kai Sterker <kaisterker@linuxgames.com>
#  Part of the Adonthell Project http://adonthell.linuxgames.com
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License.
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY.
#
#  See the COPYING file for more details
#

# -- Movement schedule for all characters to get to Bjarn's room

import adonthell
import random

class to_cellar:

    def __init__ (self, mapcharacterinstance):
        self.myself = mapcharacterinstance

        # -- gives the proper exit for each submap to reach Bjarn's room
        # (yard, common room, parlour, kitchen, cellar, bath, Alek's room,
        # Bjarn's room, store room, 1st floor Fellnir's room, Frostbloom's
        # room, Player's room, Silverhair's room)
        self.exits = \
            [(18, 13, adonthell.STAND_NORTH), \
            (9, 1, adonthell.STAND_NORTH), \
            (0, 4, adonthell.STAND_WEST), \
            (6, 6, adonthell.STAND_SOUTH), \
            (10, 7, adonthell.STAND_EAST), \
            (4, 7, adonthell.STAND_SOUTH), \
            (6, 6, adonthell.STAND_EAST), \
            (-1, -1, -1), \
            (7, 3, adonthell.STAND_EAST), \
            (8, 1, adonthell.STAND_NORTH), \
            (0, 3, adonthell.STAND_WEST), \
            (5, 3, adonthell.STAND_EAST), \
            (5, 1, adonthell.STAND_NORTH), \
            (5, 1, adonthell.STAND_NORTH), \
            (4, 1, adonthell.STAND_SOUTH)]

        self.myself.set_callback (self.walk)


    def walk (self):        
        x, y, dir = self.exits[self.myself.submap ()]

        # -- in Bjarn's room
        if x == -1:
            self.myself.set_callback (self.goal_reached)
            
            submap = self.myself.mymap ().get_submap (self.myself.submap ())
            x = random.randint (2, 5)
            y = random.randint (5, 9)

            while not submap.get_square (x, y).is_free () or (y == 5 and x > 2):
                x = random.randint (2, 5)
                y = random.randint (5, 9)

            # -- calculate direction
            # -- north-western area
            if x + y < 10:
                if x + 3 > y: dir = adonthell.STAND_SOUTH
                else: dir = adonthell.STAND_EAST
            # -- south-east corner
            else:
                if y - (x + 3) > 0: dir = adonthell.STAND_NORTH
                else: dir = adonthell.STAND_WEST

        if not self.myself.set_goal (x, y, dir):
            self.myself.time_callback ("1t", self.walk)

    # -- teleport to the next exit
    def warp (self):
        x, y, dir = self.exits[self.myself.submap ()]
        self.myself.jump_to (self.myself.submap (), x, y, dir)
        self.myself.time_callback ("1t", self.walk)

    # -- reached Bjarn's room
    def goal_reached (self):
        if self.myself.get_name () == adonthell.gamedata_player ().get_name ():
            self.myself.set_schedule ("keyboard_control")
            bjarn = adonthell.gamedata_get_character ("Bjarn Fingolson")
            bjarn.set_dialogue ("dialogues.extro")
            bjarn.pause ()
            bjarn.launch_action (self.myself)
                        
        else:
            if self.myself.posx () == 1 and self.myself.posy () == 7:
                self.walk ()
            else:
                self.myself.pause ()