File: schedule.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 (51 lines) | stat: -rw-r--r-- 1,912 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
#
#  (C) Copyright 2002 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
#

# -- various low level schedule base classes

import adonthell
import random
import types

# -- let NPC utter random remarks
#    requires the NPC schedule to have the members 
#
#    myself, a pointer to the mapcharacter
#    speech, an array of remarks for the NPC, and 
#    speech_delay, a tuple with the minimum and maximum delay 
#        between two remarks
#
#    The derived schedule needs to call speak.__init__ (self) after
#    setting the above values.
class speak:
    def __init__ (self):
        # -- sanity checks
        if not hasattr (self, "myself"):
            print "*** speak::__init__: character 'myself' not found!"
        if not hasattr (self, "speech") and \
            type (self.speech) != types.ListType:
            print "*** speak::__init__: 'speech' list not found!"
        if not hasattr (self, "speech_delay") and \
            type (self.speech_delay) != types.TupleType:
            print "*** speak::__init__: 'speech_delay' tuple not found!"
        elif len (self.speech_delay) != 2:
            print "*** speak::__init__: 'speech_delay' has wrong size!"
            
        # -- member initialization
        self.speech_length = len (self.speech)
               
    # -- make remark and set delay for the next one
    def speak (self):
        self.myself.speak (self.speech[random.randrange (0, self.speech_length)])

        delay = "%it" % random.randrange (self.speech_delay[0], self.speech_delay[1])
        self.myself.time_callback (delay, self.speak)