[Package Index | Mudlib Index | Effect Index]
File /std/hospital.c
This is a generalised hospital inheritable for the creation of NPCs.
The NPCs within the hospital are defined in the configuration files which
are parsed by the hospital. The configuration files can define zones,
groups and npcs.
A zone is a region of the mud. It can have any name you choose and is then
used as the first parameter to load_random_npc(). A zone may be made up of
other zones, groups and npcs.
The following directives are available for zones:
- name (required) - the name of this zone
- group - the definition of an NPC group that can appear in this zone.
The group definition must include only a name and a chance. The chance of
a given NPC being created is chance / sum of chances for this zone. The
details of the group must be defined in a group definition.
- npc - the definition name of an NPC that can appear in this zone. The
definition is the same as for a group.
- zone - a zone may contain sub-zones. As with group and npc, this should
use a zone name and a chance only.
- busy - the level of business of this zone
A group is a group of NPCs. It may be made up of other groups and npcs. A
group has a name by which it is referenced by zones and other groups.
The following directives are available for groups:
- name (required) - the name of this group
- npc - definition of an NPC type within this group. This npc definition
must have two directives: name & quantity. Quantity is either a number or
a number and N rolls of M sided dice written as MdN+L, L+MdN is not
supported!
There may be multiple npc definitions within a group. The definition may
optionally have a command directive indicating init_command() actions to be
performed on creation.
- population - the maximum population allowed for this kind of group
- protect - indicates if group members should protect each other (leap in front of an attack)
- defend - indicaes if group members should defend each other (attempt to parry for someone else)
- join_fight - indicates if the NPC should join fights and the message to be displayed when this occurs.
- transient - indicates if this group is transient (can be recycled within
terrains)
An npc is the definition of a specific type of NPC.
The following directives are available for NPCs:
- name (required) - the name of the NPC
- path (required) - the path of the NPCs file
- command - commands to be executed by init_command() when the NPC
is created.
- move_zone - the move zone for this NPC
- unique - indicates if the NPC is unique
- delay - delay between regeneration of this NPC (usually used with
unique)
- population - maximum population allowed for this kind of NPC
- transient - indicates if this NPC is transient (can be recycled within
terrains)
- nocturnal - indicates if this NPC is nocturnal (only comes out at night)
- diurnal - indicates if this NPC is diurnal (only comes out during the
day)
- seasonal - indicates which season(s) this NPC comes out in (useful
for things like bears which hibernate)
Written by Taffyd
Started December 3, 1998.
Example 1
A typical hospital setup would look like this:
void setup() {
set_save_file(SAVE + "/hospital");
set_data_directory(DATA + "/hospital");
set_log_directory(LOG + "/hospital");
set_npc_path(CHARS + "/hospital");
set_not_replaceable(1);
set_short("Our hospital");
set_long("This is the hospital.\n");
}
Example 2
These are examples of zones, groups & npcs.
(zone
(name "desert")
(busy 5)
(group
(name "vultures")
(chance 1)
)
(npc
("name "lizard")
(chance 1)
)
)
(group
(name "vultures")
(transient "true")
(npc
(name "vulture")
(quantity 1 + 1d5)
)
)
(npc
(name "vulture")
(path "vulture")
(transient true)
)
(npc
(name "lizard")
(path "lizard")
(transient true)
(diurnal true)
)
The above configuration file defines a zone "desert". The zone has a
business factor of 5 which means rooms in the zone will typically get a
chance at cloning npcs 5% of the time (every 20 rooms).
The zone is made up of a group called "vultures" and an npc called
"lizard". When cloning NPCs there is equal chance of a group of vultures
or a lizard being cloned.
The vultures group is transient (ie. the NPCs will be removed from the
room when the player leaves the room, rather like wandering monsters) and
contains 1 + 1d5 "vulture" npcs.
The vulture NPC is transient and can be found in the filename "vulture.c" in
the path defined by set_npc_path(). The lizard NPC is also transient and
diurnal (it only comes out during the day) and can be found in the filename
"lizard.c" in the path defined by set_npc_path().
Most terrain NPCs should be transient. This means that when no players are
present the NPCs are recycled by the hospital hence avoiding the problem of
thousands of NPCs in out of the way terrain rooms. It is essential that all
wandering terrain NPCs be transient to prevent them loading thousands of
rooms and lagging or crashing the mud.
Change history
- Ceres November 14th 2002
Altered to work as a hospital for terrain NPCs especially the transient
ones. It now handles transient npcs as well as conditions for
diurnal, nocturnal and seasonal npcs.
- Pinkfish March 10th
Major rewrite of bits to make it use a lisp like data file format.
- Carmine April 9th
Added some alignment-generation code.
Inherits
This class inherits the following classes /std/hospital/alignment.c and /std/room.cIncludes
This class includes the following files /include/hospital.h, /include/data.h, /include/armoury.h and /include/weather.hMethod index
- create_terrain_npcs(string)
This method clones & moves terrain NPCs into a terrain room.
- do_report()
Prints a report of all the npcs in the hospital currently.
- event_enter(object, string, object)
- finish_compiling(string, mapping)
This is called by the data compiler when the system has
finished compiling the data file.
- get_item(object, string *)
This function provides an interface to the armoury, selecting
an item at random from the 'items' array and attempting to
clone it.
- hospital_log_file(string, string, mixed * args)
This method provides log_file() functionality but for /d/am/log
instead.
- is_group_under_max_population(string)
This method checks to see if the number of npcs of this
type is under the maximum population.
- is_npc_under_max_population(string)
THis method checks to see if the number of npcs of this
type is under the maximum population.
- load_group_npcs(string)
This method creates the npcs for the specificed group of npcs.
- load_npc_object(string)
This method loads the specific npc.
- load_random_npc(string, int, int)
This method randomly selects an NPC or a group of NPC's from
the list of defined NPC's for the room/region.
- make_unique(mixed)
This method returns whether or not it is time to regenerate a
unique NPC.
- npc_died(object)
This method is called when a specific npc dies so we can do some
tracking on it.
- npc_path(string)
This method expands the path for the given npc by combining the npc_path
set in set_npc_path with the relative path defined in the configuration
file.
- query_data_directory()
This method returns the directory to scan for new files.
- query_debug_npc_info()
This returns all the npcs in the debug data array.
- query_deities()
This function returns an array of the gods in Ankh-Morpork
- query_disable_npc_generation()
This method returns the flag that disables the npc generation.
- query_group_info(string)
This returns the group info class for the group in question.
- query_is_hospital()
This function tells NPCs etc.
- query_made_uniques()
This function returns an array of the defined names of all created
unique NPCs.
- query_npc_current_population(string, int)
This method returns the current population of this npc
- query_npc_info(string)
This returns the npc info class for the npc in question.
- query_npc_max_population(string)
This method returns the maximum population of this npc.
- query_registered_npcs()
This function returns the ids of all the NPCs which are registered with the
hospital, ie the ones that have to be specified with add_hospital_npc().
- query_save_file()
This returns the location where hospital data will be stored.
- query_zone_info(string)
This function returns the data associated with a given zone in form
of a zone_info class.
- query_zone_not_empty(string)
This function checks if there are any NPCs or other zones associated with
a given zone.
- regen_after_death(object)
This method is called by the npc.
- reset_unique(string)
This method resets the unique status of the npc so it can be tested for
loading over again.
- roll_dice(mixed)
This method rolls the dice, if a dice is specified.
- scan_for_new_data(int)
This method scans through all the files and sees if anything has
changed.
- set_data_directory(string)
This method sets the directory to scan for new files.
- set_disable_npc_generation(int)
This method sets the flag which enables or disables npc generation.
- set_domain(string)
This method sets the domain string used when requesting things
from the hospital.
- set_log_directory(string)
This method sets the directory in to which hospital_log_file will
log by default.
- set_max_cache(int)
This method sets the maximum number of transient npcs of a given type
that the hospital will cache.
- set_npc_path(string)
This method sets the directory for npcs.
- set_save_file(string)
This method is used to set the save file for the hospital.
Public Functions
These are functions that everyone can access.
-
create_terrain_npcs
int create_terrain_npcs(string zone)
This method clones & moves terrain NPCs into a terrain room. It does all
the right checks to make sure NPCs aren't created in the wrong places
or at the wrong times.
- Parameters:
zone - the zone to choose npcs from.
-
do_report
int do_report()
Prints a report of all the npcs in the hospital currently.
-
event_enter
void event_enter(object ob,
string mess,
object from)
-
get_item
int get_item(object destination,
string * items)
This function provides an interface to the armoury, selecting
an item at random from the 'items' array and attempting to
clone it.
Any items of jewellery, clothing, weapons, armour or scabbards
that are available in the armoury can be accessed using this
function.
- Parameters:
destination - where to place the item that is fetched
from the armoury.
items - an array of items, of which one will be selected,
cloned, and then moved to destination.
- Returns:
1 if the item was successfully created, 0 if it was not.
- See also:
/obj/handlers/armoury.c
-
hospital_log_file
void hospital_log_file(string file,
string format,
mixed * args ...)
This method provides log_file() functionality but for /d/am/log
instead. You should use this method to record errors and whatever
that are domain specific instead of using log_file().
- Parameters:
file - the file name to log to. This will have /d/am/log/
inserted before it.
format - the text to log, can contain sprintf() format specifiers.
args - the arguments for any sprintf format thingies
- Example:
hospital_log_file("BAD_HOSPITAL_NPC", "%s: Bad NPC hospital data, %O.\n",
ctime(time()), _regenerated_npcs);
// This would log to /d/am/log/BAD_HOSPITAL_NPC.
-
is_group_under_max_population
int is_group_under_max_population(string name)
This method checks to see if the number of npcs of this
type is under the maximum population.
- Parameters:
npc - the npc to check to see if it is under population max
- Returns:
1 if is under, 0 if is not
-
is_npc_under_max_population
int is_npc_under_max_population(string name)
THis method checks to see if the number of npcs of this
type is under the maximum population.
- Parameters:
npc - the npc to check to see if it is under population max
- Returns:
1 if is under, 0 if is not
-
load_group_npcs
object * load_group_npcs(string group_name)
This method creates the npcs for the specificed group of npcs.
- Parameters:
group_name - the name of the group
- Returns:
the npcs
-
load_npc_object
object load_npc_object(string npc_name)
This method loads the specific npc. It will do everything it needs
to create the npc. In the case of unique npcs they are not cloned.
- Parameters:
npc_name - the name of the npc to load
- Returns:
the npc object
-
load_random_npc
object * load_random_npc(string zone,
int wealth,
int busy)
This method randomly selects an NPC or a group of NPC's from
the list of defined NPC's for the room/region.
- Parameters:
zone - This is a zone (as defined in the configuration files).
wealth - How wealthy this particular part of this zone is.
busy - How busy this particular part of this zone is.
- Returns:
Returns a group of NPCs randomly selected.
-
make_unique
int make_unique(mixed who)
This method returns whether or not it is time to regenerate a
unique NPC. The regeneration time is controlled by the REGEN_TIME
#define.
- Parameters:
who - this is the name or object reference of the NPC
- Returns:
1 if it is time to make the unique NPC, or 0 if it is not.
-
npc_died
void npc_died(object ob)
This method is called when a specific npc dies so we can do some
tracking on it.
- Parameters:
npc_ob - the npc object
-
npc_path
string npc_path(string str)
This method expands the path for the given npc by combining the npc_path
set in set_npc_path with the relative path defined in the configuration
file.
- Parameters:
path - the path to expand
- Returns:
the expanded path
-
query_data_directory
string query_data_directory()
This method returns the directory to scan for new files.
- Returns:
the directory to scan new data
- See also:
set_data_directory()
-
query_debug_npc_info
mapping query_debug_npc_info()
This returns all the npcs in the debug data array.
- Returns:
this returns the debug information for the npcs
-
query_deities
string * query_deities()
This function returns an array of the gods in Ankh-Morpork
-
query_disable_npc_generation
int query_disable_npc_generation()
This method returns the flag that disables the npc generation.
- Returns:
the flag that disables the npc generation
- See also:
set_disable_npc_generation
.c
-
query_group_info
class group_info query_group_info(string group)
This returns the group info class for the group in question. THis should
only be used for debugging.
- Parameters:
group - the name of the group to get the info on
- Returns:
the class of the group
-
query_is_hospital
int query_is_hospital()
This function tells NPCs etc. that this is a hospital and so there should
be no fighting etc.
-
query_made_uniques
string * query_made_uniques()
This function returns an array of the defined names of all created
unique NPCs.
-
query_npc_current_population
int query_npc_current_population(string npc,
int clean)
This method returns the current population of this npc
- Parameters:
npc - the name of the npc
- Returns:
the npc population
-
query_npc_info
class npc_info query_npc_info(string npc)
This returns the npc info class for the npc in question. THis should
only be used for debugging.
- Parameters:
npc - the name of the npc to get the info on
- Returns:
the class of the npc
-
query_npc_max_population
int query_npc_max_population(string npc)
This method returns the maximum population of this npc.
- Parameters:
npc - the name of the npc
- Returns:
the npc population
-
query_registered_npcs
string * query_registered_npcs()
This function returns the ids of all the NPCs which are registered with the
hospital, ie the ones that have to be specified with add_hospital_npc().
- Returns:
All the ids.
-
query_save_file
string query_save_file()
This returns the location where hospital data will be stored.
- See also:
set_save_file()
-
query_zone_info
class zone_info query_zone_info(string zone)
This function returns the data associated with a given zone in form
of a zone_info class.
-
query_zone_not_empty
int query_zone_not_empty(string zone)
This function checks if there are any NPCs or other zones associated with
a given zone.
- Returns:
1 if the zone is not empty, 0 if it is, -1 if it doesn't exist
-
regen_after_death
void regen_after_death(object dead_npc)
This method is called by the npc.death effect after an NPC that is handled
by the hospital has died. It tells the room where it was generated to
make a new NPC and to all sorts of funky things.
This is not fully implemented yet.
-
reset_unique
void reset_unique(string who)
This method resets the unique status of the npc so it can be tested for
loading over again.
- Parameters:
npc - the name of the npc
-
roll_dice
int roll_dice(mixed die)
This method rolls the dice, if a dice is specified.
- Parameters:
dice - the dice or number
- Returns:
the actual number
-
scan_for_new_data
int scan_for_new_data(int force)
This method scans through all the files and sees if anything has
changed.
-
set_data_directory
void set_data_directory(string dir)
This method sets the directory to scan for new files. The data directory
stores the configuration files for the hospital that define the zones,
groups and npcs.
- Parameters:
dir - the directory to scan for new files
-
set_disable_npc_generation
void set_disable_npc_generation(int value)
This method sets the flag which enables or disables npc generation. This
is mostly used for debugging.
- Parameters:
value - the new value of the flag
-
set_domain
void set_domain(string domain)
This method sets the domain string used when requesting things
from the hospital.
- Parameters:
domain - the domain name
-
set_max_cache
void set_max_cache(int num)
This method sets the maximum number of transient npcs of a given type
that the hospital will cache.
- Parameters:
num - the maximum number
-
set_npc_path
void set_npc_path(string path)
This method sets the directory for npcs. The filename for npcs defined
in the configuration files is realtive to this path.
- Parameters:
dir - the director for npcs.
Protected Functions
These are functions that only objects inheriting the class can access.
-
finish_compiling
void finish_compiling(string fname,
mapping data)
This is called by the data compiler when the system has
finished compiling the data file.
- Parameters:
data - the data to deal with
-
set_log_directory
void set_log_directory(string new_dir)
This method sets the directory in to which hospital_log_file will
log by default. If the directory does not exist, then it is set to
DEFAULT_LOG_DIRECTORY.
- Parameters:
new_dir - the directory to log to.
- Example:
set_log_directory( "/d/cwc/Bes_Pelargic/log" );
// log directory is now /d/cwc/Bes_Pelargic/log
// (cre) MacChirton: ithinkmykeyboardisbroken
set_log_directory( "/d/cWc/BeS_pelarGic/lrg" );
// Displays: "/d/cwc/hospital/bes_pelargic: Invalid log
// directory, defaulting to /log"
-
set_save_file
void set_save_file(string new_save)
This method is used to set the save file for the hospital. This
file is where all of the hospitals NPC data is stored while it is
not active and in between reboots.
If this file does not exist when the hospital is loaded, then the
variables will be initialised to their defaults and
restore_default_npcs() called.
- Parameters:
new_save - the file name to save the hospital data in