Debian Codegraph @

scripts/schedules/mapcharacters/schedule.py

raw symbols SCIP
1 #
2 # (C) Copyright 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 # -- various low level schedule base classes
14
15 import adonthell
16 import random
17 import types
18
19 # -- let NPC utter random remarks
20 # requires the NPC schedule to have the members
21 #
22 # myself, a pointer to the mapcharacter
23 # speech, an array of remarks for the NPC, and
24 # speech_delay, a tuple with the minimum and maximum delay
25 # between two remarks
26 #
27 # The derived schedule needs to call speak.__init__ (self) after
28 # setting the above values.
29 class speak(object):
30 def __init__ (self):
31 # -- sanity checks
32 if not hasattr (self, "myself"):
33 print ("*** speak::__init__: character 'myself' not found!")
34 if not hasattr (self, "speech") and \
35 not isinstance (self.speech, list):
36 print ("*** speak::__init__: 'speech' list not found!")
37 if not hasattr (self, "speech_delay") and \
38 not isinstance (self.speech_delay, tuple):
39 print ("*** speak::__init__: 'speech_delay' tuple not found!")
40 elif len (self.speech_delay) != 2:
41 print ("*** speak::__init__: 'speech_delay' has wrong size!")
42
43 # -- member initialization
44 self.speech_length = len (self.speech)
45
46 # -- make remark and set delay for the next one
47 def speak (self):
48 self.myself.speak (self.speech[random.randrange (0, self.speech_length)])
49
50 delay = "%it" % random.randrange (self.speech_delay[0], self.speech_delay[1])
51 self.myself.time_callback (delay, self.speak)