[Package Index | Mudlib Index | Effect Index]

File /obj/handlers/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.

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.

An npc is the definition of a specific type of NPC.

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".

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().

Change history

Inherits

This class inherits the following classes /std/room.c

Includes

This class includes the following files /include/data.h, /include/weather.h and /include/armoury.h

Class Index

Method index

Public Functions

These are functions that everyone can access.

do_report
int do_report()

Prints a report of all the npcs in the hospital currently.
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


pick_al
int pick_al(int average,
            int range)

This function produces a random alignment for an npc, based on a normal distribution around a supplied average, with a maximum and minimum limit provided by a requested range.

The alignment produced will be within the range[ average - range, average + range ]

Parameters:
average - The average alignment for this npc
range - The range request for alignment - the difference between average and maximum possible alignment




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_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()


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
void scan_for_new_data()

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


Classes

These are nice data types for dealing with... Data!