| 1 |
/* |
| 2 |
$Id$ |
| 3 |
|
| 4 |
Copyright (C) 2001 Alexandre Courbot |
| 5 |
Part of the Adonthell Project http://adonthell.linuxgames.com |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License. |
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY. |
| 11 |
|
| 12 |
See the COPYING file for more details. |
| 13 |
*/ |
| 14 |
|
| 15 |
/*! |
| 16 |
|
| 17 |
\page page8 Writing mapcharacter schedules |
| 18 |
|
| 19 |
\section mcharsched0 Generalities |
| 20 |
A mapcharacter schedule file should always be placed in the \e |
| 21 |
script/schedules/mapcharacters directory in the %game hierarchy. It |
| 22 |
should contain a single class, named like the module. A schedule is |
| 23 |
attached to a mapcharacter by the mapcharacter::set_schedule () |
| 24 |
method. See it's documentation for more details. You should be |
| 25 |
particularly careful that the argument list given to |
| 26 |
mapcharacter::set_schedule () \e has to be a Python tuple |
| 27 |
containing ONLY Python strings or integers. |
| 28 |
|
| 29 |
\section mcharsched1 Arguments passed to __init__ () |
| 30 |
When you call mapcharacter::set_schedule (), the first argument |
| 31 |
passed to the class constructor is a reference to the mapcharacter |
| 32 |
that called this method. This parameter should be saved as it will |
| 33 |
most likely be used during the run () method to control the |
| 34 |
mapcharacter. Then follow the arguments inside the tuple (optionally) |
| 35 |
passed to mapcharacter::set_schedule (). |
| 36 |
|
| 37 |
\section mcharsched2 Arguments passed to run () |
| 38 |
No arguments are passed to the run () method. |
| 39 |
|
| 40 |
\section mcharsched3 Structure of a mapcharacter schedule file |
| 41 |
Here is what a mapcharacter schedule file should ideally look like: |
| 42 |
\verbatim |
| 43 |
# |
| 44 |
# (C) Copyright <year> <your name> |
| 45 |
# Part of the Adonthell Project http://adonthell.linuxgames.com |
| 46 |
# |
| 47 |
# This program is free software; you can redistribute it and/or modify |
| 48 |
# it under the terms of the GNU General Public License. |
| 49 |
# This program is distributed in the hope that it will be useful, |
| 50 |
# but WITHOUT ANY WARRANTY. |
| 51 |
# |
| 52 |
# See the COPYING file for more details |
| 53 |
# |
| 54 |
|
| 55 |
# |
| 56 |
# <description of the schedule> |
| 57 |
# |
| 58 |
|
| 59 |
<do your imports here> |
| 60 |
|
| 61 |
class myschedule: |
| 62 |
|
| 63 |
# Parameters: |
| 64 |
# Description of myparameter1 |
| 65 |
# Description of myparameter2 |
| 66 |
def __init__ (self, mapcharacterinstance, myparameter1, myparameter2): |
| 67 |
self.myself = mapcharacterinstance |
| 68 |
<do your other initialisation here> |
| 69 |
|
| 70 |
def run (self): |
| 71 |
<mapcharacter control> |
| 72 |
|
| 73 |
def __del__ (self) |
| 74 |
<eventual cleanup> |
| 75 |
\endverbatim |
| 76 |
|
| 77 |
\section mcharsched4 Storing variables |
| 78 |
It is unsafe to store variables in the class instance others than |
| 79 |
those passed to the __init__ method. When a mapcharacter's |
| 80 |
schedule is state-saved, only the schedule filename and it's |
| 81 |
initialisation arguments (the Python tuple passed to |
| 82 |
mapcharacter::set_schedule ()) are saved. So, if you create variables |
| 83 |
in the \e self object, do not expect them to survive %game |
| 84 |
saving/loading. A safe approach is to make use of the storage class, |
| 85 |
from which mapcharacter inherits, to store your persistant variables. |
| 86 |
Then they are automatically saved together with the mapcharacter. |
| 87 |
|
| 88 |
*/ |