[Package Index | Mudlib Index | Effect Index]

File /std/living/response_mon.c

This file contains the methods to make the npcs in game respond to soul and says. Allows for a level of npc interation.

Code originaly by nimmox@igor. Modified for discworld by Pinkfish.

See also:
/obj/monster.c

Written by Pinkfish

Includes

This class includes the following files /include/language.h, /include/soul.h and /include/gossip.h

Class Index

Method index

Public Functions

These are functions that everyone can access.

add_only_respond_to
void add_only_respond_to(object person)

This adds an object into the list of objects that we will only respond to. If this array is empty then we will respond to anyone, if it has something in it then we will only respond to them.

Parameters:
person - the person to add to the response array


add_respond_to_with
void add_respond_to_with(mixed * trigger,
mixed response)

This method adds a respond message to respond to into the current array of responses.

If response_mon_regexp is not set, the trigger consists of an array of words to be matched (in order) in the string. If there is an array instead of a single word at one point then any of the words in the array will be matched. If response_mon_regexp is set, the trigger is a single string, representing the regular expression to be matched in the string.

The response is either an array of things to execute (in which case a random one will be chosen each time) or a function pointer or a string. If it is a string then the command of that name will be executed, if the string starts with a '#' then the function named after that will be called on the npc. That was exciting wasn't it?

If the string is a function call (starts with a #) the associated function will be called with two arguments, the speaking object and the message string that triggered the response.

If the string is not a function call then the special string $hname$ will be replaced with the file name of the triggering object. $hcname$ or $short$ will likewise be replaced by the short of the triggering object.

NOTE: The NPC must explicitly know the language being spoken, even if it's "common". I don't know why. That's just the way it is. See add_language().

Parameters:
trigger - the trigger to trigger the action on
response - the response to the action

See also:
query_respond_to_with(), query_response_allowed(), set_response_mon_regexp(), query_response_mon_regexp(), regexp() and add_language()

Example:
// Simple response
add_respond_to_with(({ "@say", "bing" }), "'Yes!  Bing bing bing!");

// respond to someone saying 'frog' or 'toad'
add_respond_to_with(({ "@say", ({ "frog", "toad" }) }),
                    "'Frogs and toads are nice.");

// Randomly say something or bing back at them
add_respond_to_with(({ "@say", "bing" }),
                    ({ "'Yes!  Bing bing bing!", "bing $hname$" }));

// Call the function 'rabbit' on the npc.
add_respond_to_with(({ "@say", "bing" }), "#rabbit");
....
void rabbit( object speaker, string mess ) {}

// Do something cute with a function pointer
add_respond_to_with(({ "@bing" }),
                 (: do_command("'something wild for " + $1->a_short()) :));

// Triggers can also match entire categories of souls.  See the "soulinfo"
// command for which categories are available and which souls they contain:
add_respond_to_with( ({ "%violent", "you" }), "cry" );

check_locality
int check_locality(object respondee)
clear_respond_to_withs
void clear_respond_to_withs()

This method removes all add respond to withs.
disable_gossip
void disable_gossip()
do_gossip_say
varargs void do_gossip_say(string str)
enable_gossip
void enable_gossip()
event_person_sayto
void event_person_sayto(object per,
string mess,
string lang,
object * targets,
string accent)

This method is called on the npcs to help in recognising saytos. Beware... A @say message will also be added, so you need to make sure you respond to the correct message and not to both.
gossip_enabled
int gossip_enabled()
query_gossip_says
mixed * query_gossip_says()
query_only_respond_to
object * query_only_respond_to()

This method returns the current list of people we are only responding to.

Returns:
the array of people we are responding to


query_respond_to_with
mixed * query_respond_to_with()

This method returns the current responding to with array. The array is of the formant:
  ({
     trigger1,
     response1,
     trigger2,
     response2,
     ...
   })


See also:
add_respond_to_with()


query_response_allowed
int query_response_allowed(object ob,
string * response)

This method checks to see if the response is allowed for this object. NB: objects to which this_object is not visible are disallowed.

Parameters:
ob - the object to check
response - the response that is matched

Returns:
1 if the object is allowed, 0 if it is not


query_response_mon_debug_mode
int query_response_mon_debug_mode()

This method checks to see if the response monster code is in debug mode.

Returns:
1 if in debug mode, 0 if not

See also:
set_response_mon_debug_mode()


query_response_mon_ignore_linked_rooms
int query_response_mon_ignore_linked_rooms()

This method returns the flag determining if the NPC will ignore (not respond to) messages in rooms linked to its environment.

Returns:
1 to ignore such messages, 0 (the default) to handle to them.

See also:
set_response_mon_ignore_linked_rooms().


query_response_mon_regexp
int query_response_mon_regexp()

This method returns the current state of the flag that indicates whether to use regular expressions instead of the traditional array of words.

Returns:
1 if using regular expressions, 0 if not


query_say_log
string query_say_log()
query_stop_responding
int query_stop_responding()

This method returns the flag determining the toggling of the responses of the npc. If this is set to 1, then the npc will stop responding to messages.

Returns:
1 to the npc will not respond, 0 it is responding

See also:
set_stop_responding()


remove_only_respond_to
void remove_only_respond_to(object person)

This method removes an object from the list of people to respond to.

Parameters:
person - the person to remove


set_gossip_chance
void set_gossip_chance(int i)
set_respond_to_with
void set_respond_to_with(mixed map)

This method sets the current responses for the npc. This will overwrite the current responses in the npc. Please use add_respond_to_with in your NPC's instead of this function call, as it requires prior knowledge as to the internal structure of the respond_to_with code that add_respond_to_with handles nicely. The array is of the formant:
  ({
     trigger1,
     response1,
     trigger2,
     response2,
     ...
   })


See also:
add_respond_to_with() and query_respond_to_with()


set_response_mon_debug_mode
void set_response_mon_debug_mode(int flag)

This method sets the current debug flag for the response monster code.

Parameters:
flag - the new value of the flag, 1 on, 0 off

See also:
query_response_mon_debug_mode()


set_response_mon_ignore_linked_rooms
void set_response_mon_ignore_linked_rooms(int i)

This method sets the flag determining if the NPC will ignore (not respond to) messages in rooms linked to its environment.

Parameters:
i - 1 to ignore such messages, 0 (the default) to handle to them.

See also:
query_response_mon_ignore_linked_rooms().


set_response_mon_regexp
void set_response_mon_regexp(int flag)

This method sets or clears the flag to use regular expressions instead of the traditional arrays of words. In addition, this flag inhibits the usual stripping of non-alphanumerics from the input strings.

Parameters:
flag - the new value of the flag: 1 says to use regular expressions, 2 to use pcre, 0 to not use them


set_response_mon_understand_anything
void set_response_mon_understand_anything(int flag)

This method sets or clears the flag that allows the npc to understand any language at all. This is useful for those times when you need an npc that speaks/understands any language.

Parameters:
flag - the new value of the flag


set_say_log
void set_say_log(string str)
set_stop_responding
void set_stop_responding(int i)

This method allows the toggling of the responses of the npc. If this is set to 1, then the npc will stop responding to messages.

Parameters:
i - 1 to make the npc not respond, 0 to make it respond again

See also:
query_stop_responding()


Protected Functions

These are functions that only objects inheriting the class can access.

check_sub_sequence
mixed * check_sub_sequence(mixed * words)
exec_response
void exec_response(mixed rep,
object per,
string mess)
remove_read_marks
string remove_read_marks(string str)

This method removes annoying read marks to make the string easier to parse. Basically it strips puncutation.

Parameters:
str - the string to remove the punctuation from

Returns:
the string without any punctuation


senddstr
void senddstr(string str,
object per)

This method runs the command passed in, doing some substitution.

Parameters:
str - the string to execute
per - the person who triggered the command


Classes

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