Man populace
From LSWiki
Current revision
Description
We will detail here how to use the generic populace control daemon, /mod/daemon/populace, to set up a daemon which will manage an area's populace independently of monsters loaded in individual rooms. This daemon is designed to work well in conjunction with the generic guardian control daemon (see /txt/doc/build/guardian), and has special functionality to achieve this.
The daemon creates and maintains a population for the area, distributing it randomly amidst specified files. Each reset() it creates new populace to replace any killed during the intervening time. Because it carries out this population relatively slowly, to reduce processor load, it is probably a good idea to have your populace daemon preloaded from your domain's preload list.
To set up the daemon requires only the use of a few configuration functions.
Configuration
void set_guardian(string daemon); Sets the filename of the area's guardian daemon. If not specified, the populace daemon assumes that it is also the guardian daemon. This is only relevant if you will be defining elements of the populace as guardians.
void set_pathfinder(string daemon); Sets the filename of the area's pathfinder daemon. If not specified, the populace daemon assumes that it is also the pathfinder daemon. This is only relevant if you will be defining homes for NPCs.
void set_weather(string daemon); Sets the filename of the weather daemon to use. If not specified, the central MUD weather daemon is assumed. This is only relevant if you will be defining NPC homes which vary between day and night.
void add_file_selector(string sel); Defines a pattern for retrieving files which the area's populace will be randomly distributed within. The easiest way to do this is to simply use the area's room macro with wildcards. For instance, if you wanted to have the populace defined spread among all rooms in the area whose filenames began with the word "street", you could do:
add_file_selector(Area_Room("street*"));
If multiple file selectors are used, any rooms consistent with more than one will behave as if "weighted"; i.e. a room which is returned by two file selectors will be twice as likely to show up as a room which is returned by only one.
void set_file_selectors(string *sels); Sets the array of all file selectors used by the daemon.
void add_file_target(string targ); Sets an explicit filename to be used in addition to any files retrieved by file selectors. As with selectors, weighting behavior results if a file ends up being specified more than once.
void set_file_targets(string *targ); Sets the array of all file targets used by the daemon.
varargs void add_population(string file, int number, status guard); Defines a population of monsters to distribute within the area. The first argument is the filename from which to clone the monsters. The second argument is the number which should exist within the area. The third, optional, argument is a flag which should be set to true if the monsters being specified should function as area guardians.
void set_populations(mapping map); Sets the mapping of all populations used by the daemon. This is a two-value mapping containing the settings delineated by add_population(). It is recommended that you use add_population() rather than this function for ease of configuration.
varargs void add_person(string file, mixed home, status guard); Adds an individual (a non-cloned NPC) to the area's population. The first argument is the NPC's filename. The second, optional, argument designates the filename of the NPC's home; if this is specified the NPC will be placed at this location when created and will attempt to return to it periodically if it has moved. You may also specify a two-element string array; the first element is the NPC's home during the day and the second is its home at night. If the home value or either element of a home array are closures, they will be resolved, being passed an argument of the NPC in question. If nothing is specified the NPC will be distributed randomly amidst the locations defined by the daemon's file selectors just like the rest of the population. The third argument, also optional, should be set to true if the NPC should function as an area guardian.
void set_people(mapping map); Sets the mapping of all people managed by the daemon. This is a two- value mapping containing the settings delineated by add_person(). It is recommended that you use add_person() rather than this function for ease of configuration.
status set_populate_func(mixed func); Modifies the behavior associated with creating a new element of the populace. The functions specified are passed the character in question and the room to which the character is to be moved upon creation. If any of them return true, or the character is destructed, the character will not be moved to that location.
status set_travel_func(mixed func); Modifies the behavior associated with a person about to return to its home. The functions specified are passed the person in question, the person's current environment, and the room the person wishes to return to. If any of them return true, the person does not return.
status remove_travel_func(mixed func); Removes a previously set travel_func.
status set_traveling_func(mixed func); Modifies the behavior associated with a person about to move one step on the way back to its home. The functions specified are passed arguments of the person, its environment, the room it is returning to, and an array containing the string directions which it currently needs to move through to reach its home. If any of them return true, the person does not take this step in its traveling.
status remove_traveling_func(mixed func); Removes a previously set traveling_func.
status set_traveled_func(mixed func); Called when a person has just finished traveling to its home. The functions specified are passed arguments of the person, its home, and the direction it just moved. Their return values are ignored.
status remove_traveled_func(mixed func); Removes a previously set traveled_func.
Operational Use
mapping query_populace_active(); You may use this function to retrieve the data which the daemon uses to track existing monsters in its population base. This mapping's indices are the filenames of population elements; its values are arrays of monsters. These arrays may contain zero-value elements when monsters have been killed. Note that this mapping only tracks "populace", not "people".
status query_populace_managed(object obj); This function returns true if the object sent is managed by the populace daemon, whether as a 'populace' or 'people' object. Cloned objects will be examined for whether they are part of 'populace', non-clones will be examined for whether they are part of 'people'.