[an error occurred while processing this directive]
[<a href="index.shtml">Package Index</a></code> | <a href="index_std.shtml">Mudlib Index</a></code> | <a href="index_eff.shtml">Effect Index</a></code>]<br><h2>File /std/room/basic/situation_changer.c</h2>
situation changer object associated with a room object.
<h2>Includes</h2>
This class includes the following files <a href="include.situations.h.shtml">/include/situations.h</a> and <a href="include.am_time.h.shtml">/include/am_time.h</a><h2>Class Index</h2>
<ul><li><a href="#class_situation_timing">situation_timing</a>
</ul><h2>Method index</h2>
<dl><ul>
<li><a href="#add_situation">add_situation</a>(mixed, class situation)<br/>
Adds a situation to the room.
<li><a href="#automate_situation">automate_situation</a>(mixed, mixed, mixed, mixed, mixed)<br/>
Automate starting and ending of a situations.
<li><a href="#change_situation">change_situation</a>(mixed, mixed, mixed, mixed)<br/>
Starts one or more situations that will end after a
specified duration.
<li><a href="#check_situations">check_situations</a>()<br/>
Tests for enabling situation managing.
<li><a href="#choose_words">choose_words</a>(mixed, mixed)<br/>
This function selects word replacements for #n in the text.
<li><a href="#end_situation">end_situation</a>(mixed)<br/>
Ends a situation previously added and started on the room
that is managed by this object.
<li><a href="#extra_look">extra_look</a>()<li><a href="#insert_words_chats">insert_words_chats</a>(class situation, string *)<br/>
Replaces #1 in text with the one of the first array of words in wordlist
and #2 with one of the second array of words and so on.
<li><a href="#insert_words_items">insert_words_items</a>(class situation, string *)<br/>
Replaces #1 in text with the one of the first array of words in wordlist
and #2 with one of the second array of words and so on.
<li><a href="#make_seed">make_seed</a>(int, int)<br/>
Makes a seed value for the random part of when 
situations turn on and off.
<li><a href="#manage_situations">manage_situations</a>()<br/>
Starts and ends situations according to the information
in the sittiming array.
<li><a href="#query_current_situations">query_current_situations</a>()<br/>
returns situations currently turned on.
<li><a href="#query_possible">query_possible</a>(class situation_timing, int, int, int)<li><a href="#query_room">query_room</a>()<li><a href="#query_sittiming">query_sittiming</a>()<br/>
returns sittiming class with info about automated situations 
<li><a href="#query_situations">query_situations</a>()<br/>
returns mapping of situations.
<li><a href="#query_status">query_status</a>()<br/>
returns status of situation manager.
<li><a href="#set_room">set_room</a>(object)<li><a href="#shutdown_all_situations">shutdown_all_situations</a>()<br/>
Shuts down all current and pending situations.
<li><a href="#shutdown_situation">shutdown_situation</a>(int, mixed)<br/>
Shuts down a change_situation based on the call_out handle
returned by the call to change_situation.
<li><a href="#start_situation">start_situation</a>(mixed, int)<br/>
Starts a situation previously added to the room
that is managed by this object.
</ul><h2>Public Functions</h2>
These are functions that everyone can access.<p>
.<ul><a name="add_situation">
add_situation</a><pre>
void add_situation(mixed label,
                   class situation sit)
</pre></br>
Adds a situation to the room.  These situations can be
invoked manually with start_situation or automatically via
automate_situation.
<br/><ul>
<li><b>Parameters:</b>
<br/>label - string or number labelling the situation
<br/>sit - a structure (class) containing all the bits
of the situation you want to add.
eg. 
start_func function to be called at start of situation 
            that might be used to load NPC's or anything
            beyond a message.

            The start function is passed the label, 
            a do_start_mess flag and the room object.  
            If the flag is 1 the situation is starting 
            rather than being reloaded.  Thus if 
            do_start_mess is 0 then you should avoid
            any obvious start messages and make it look
            like the situation is already underway.

end_func function to be called an the end of a situation.  
            The end function is only
            passed the label and the room object.

start_mess message told to the room at start of situation

end_mess message told to the room at end of situation

extra_look extra look string appended to rooms long 
            during the situation

chats an array of chat strings to be active 
            during the situation 

add_items a mixed array of ({ item, item description }) 
            pairs to be active during the situation

random_words sets of words of the form ({ ({ "option1","option2" }),
            ({ "adjective1","adjective2" }), ... }).  One of the
            the first set replaces #1 in any text above and one of
            the second set replaces #2 in any text above and so on.
            The random choice is fixed for the duration of any one
            situation.

<li><b>See also:</b>
<br/>start_situation.c, automate_situation.c, add_item.c, room_chat.c and add_extra_look.c<li><b>Example:</b>
<br/><pre>#include <situations.h>

class situation frogs;
frogs = new(class situation, 
    start_mess: "Water seeps out of the ground to form puddles.",
    extra_look: "There are large puddles on the ground here.",
    chats: ({"A hidden frog croaks quietly.",
             "There is a blooping sound." }),
    add_items:({ ({"puddle", "The puddles are dark and murky.  " 
                   "They will probably dry up given time." }) }) );
add_situation( "frogs", frogs );</pre><br/><pre>
add_situation( "frogs", new(class situation, 
     start_mess: "Water seeps out of the ground to form puddles.",
     extra_look: "There are large puddles on the ground here.",
     chats: ({"A hidden frog croaks quietly.",
              "There is a blooping sound." }),
     add_items: ({ ({"puddle", "The puddles are dark and murky.  " 
                     "They will probably dry up given time." }) }) ));
</pre></dl>

<ul><a name="automate_situation">
automate_situation</a><pre>
void automate_situation(mixed label,
                        mixed duration,
                        mixed when,
                        mixed chance,
                        mixed category)
</pre></br>
Automate starting and ending of a situations.
These situations can be invoked manually with start_situation.
The automated starting and ending is unaffected by the room 
unloading.  When the room reloads the situation will be 
restarted unless its duration is up.
You must include the file situations.h for the definitions
of the when masks.
<br/><ul>
<li><b>Parameters:</b>
<br/>label - (mixed) label of the situation to start 
 up.  If you pass an array such as ({ "frog1", "frog2" }) for the 
label then that set of situations are started one at
a time and the total duration is split evenly between them.
Label is usually an integer or a string or an array of
integers and/or strings.
If the string is a list of labels
separated by , then multiple situations
are started using those labels.
<br/>duration - (int) total time (seconds) the overall situation 
should last.  If an array is specified for duration each
situation gets it's own little one.  If -1 is specified as
a duration for one part that situation is background complimentary
situation to the rest that is on when the rest are off.
<br/>when - (int) a time of the day mask.  This limits when
the situation is allowed to occur.  The mask is composed of
the allowed hours in AM time ( 24 hours clock, (1<<hour) and 
combined with | (OR) ).   You can just use these
predefined masks and ingore how it works:
 WHEN_WEE_HOURS, WHEN_EARLY_MORNING, WHEN_LATE_MORNING, WHEN_AFTERNOON
 WHEN_EVENING, WHEN_LATENIGHT, WHEN_MIDDAY, WHEN_MORNING, 
 WHEN_EARLY_MORNING, WHEN_LATE_MORNING, WHEN_NIGHT, WHEN_DAY
 WHEN_ANY_TIME    
The masks are defined in /include/situations.h.
<br/>chance -  (int) chance in 1000 of starting the situation
 This is tested every duration seconds.
<li><b>See also:</b>
<br/>add_situation.c, start_situation.c, end_situation.c and evolvingroom.h<li><b>Example:</b>
<br/><pre>#include <situations.h>

 automate_situation( "frog", 300, WHEN_ANY_TIME, 200 );

This will automatically start the situation labelled "frog" 
at a random time that is any time of the day with a 200/1000
chance of it starting per 300 seconds.  It will last for
300 seconds (5 minutes).  </pre><br/><pre>
 automate_situation( ({"frog1","frog2"}), 240, WHEN_EVENING|WHEN_NIGHT,
, 300 );

This will automatically start a situation that is a combination 
of "frog1" followed by "frog2" at a random time but only in the
evening or at night.  There will be a 300/1000 chance of it 
starting per 240 seconds.  Both the "frog1" and "frog2" 
situations will get half the total time (as there are two),  
120 seconds each, for a total duration of 240 seconds (4 minutes).
</pre></dl>

<ul><a name="change_situation">
change_situation</a><pre>
varargs mixed change_situation(mixed label,
                               mixed duration,
                               mixed words,
                               mixed handle)
</pre></br>
Starts one or more situations that will end after a
specified duration.  You can use an array and make
further situations commence when others end.
<br/><ul>
<li><b>Parameters:</b>
<br/>label - (mixed) label of the situation to start 
 up.  If you pass an array such as ({ "frog1", "frog2" }) for the 
label then that set of situations are started one at
a time and the total duration is split evenly between them.
Label is usually an integer or a string or an array of
integers and/or strings.
If the string is a list of labels
separated by , then multiple situations
are started using those labels.
<br/>duration - (int) total time (seconds) the overall situation 
should last.  You can put an array of durations -- one for each
situation if the label lists more than one situation and then
the overall time is the sum of the numbers.
-1 means indefinite so having any situations after
something with -1 duration is pointless.
<br/>handle - is an internal thing that should only be called with 0
unless you really know what you are doing.
<br/>words - is a list of replacements for #n in the text OR
       a random number seed, it is
       passed to choose_words.
       eg. ({ "#1", "frog", "#2", "honey" }) or 22
<li><b>Returns:</b>
<br/>call_out that is propogating the changes
This is useful if you want to be able to kill the whole
set without disturbing other situations.
<li><b>See also:</b>
<br/>start_situation.c, end_situation.c, add_situation.c and choose_words
.c</dl>

<ul><a name="check_situations">
check_situations</a><pre>
void check_situations()
</pre></br>
Tests for enabling situation managing.
If situation managing is already active or turned off
it does nothing.
<br/><ul>
<li><b>See also:</b>
<br/>automate_situation
.c</dl>

<ul><a name="choose_words">
choose_words</a><pre>
void choose_words(mixed label,
                  mixed choice)
</pre></br>
This function selects word replacements for #n in the text.
<br/><ul>
<li><b>Parameters:</b>
<br/>label - Situation label to choose for
<br/>choice - A random seed (integer) or
              a set of pairs exactly the same as the second
              argument to replace.
<li><b>See also:</b>
<br/>replace.c<li><b>Example:</b>
<br/><pre>     choose_words( "frog", ({ "#1", "tadpole", "#2", "pond" }));
</pre></dl>

<ul><a name="end_situation">
end_situation</a><pre>
void end_situation(mixed label)
</pre></br>
Ends a situation previously added and started on the room
that is managed by this object.
These situations can be invoked manually with start_situation 
or automatically via automate_situation. 
<br/><ul>
<li><b>Parameters:</b>
<br/>label - string or number labelling the situation
<li><b>See also:</b>
<br/>add_situation.c, start_situation.c and automate_situation
.c</dl>

<ul><a name="extra_look">
extra_look</a><pre>
string extra_look()
</pre>
<ul><a name="insert_words_chats">
insert_words_chats</a><pre>
string * insert_words_chats(class situation sit,
                            string * words)
</pre></br>
Replaces #1 in text with the one of the first array of words in wordlist
and #2 with one of the second array of words and so on...
Each string in the string array is changed.


<ul><a name="insert_words_items">
insert_words_items</a><pre>
mixed * insert_words_items(class situation sit,
                           string * words)
</pre></br>
Replaces #1 in text with the one of the first array of words in wordlist
and #2 with one of the second array of words and so on...
For items only the item text is changed, not the key words.


<ul><a name="make_seed">
make_seed</a><pre>
void make_seed(int xval,
               int yval)
</pre></br>
Makes a seed value for the random part of when 
situations turn on and off.  The two ints must be 
constant for a given room -- like the coordinates.
<br/><ul>
<li><b>Parameters:</b>
<br/>xval - integer to use to make a seed (eg. x coordinate)
<br/>yval - integer to use to make a seed (eg. y coordinate)

</dl>

<ul><a name="manage_situations">
manage_situations</a><pre>
void manage_situations()
</pre></br>
Starts and ends situations according to the information
in the sittiming array.  It is called continuously 
automatically while there are interactives in the room.


<ul><a name="query_current_situations">
query_current_situations</a><pre>
int * query_current_situations()
</pre></br>
returns situations currently turned on.
<br/><ul>
<li><b>Returns:</b>
<br/>int array of situation labels

</dl>

<ul><a name="query_possible">
query_possible</a><pre>
int query_possible(class situation_timing sit,
                   int it,
                   int tod,
                   int cnt)
</pre>
<ul><a name="query_room">
query_room</a><pre>
object query_room()
</pre>
<ul><a name="query_sittiming">
query_sittiming</a><pre>
mixed * query_sittiming()
</pre></br>
returns sittiming class with info about automated situations 
<br/><ul>
<li><b>Returns:</b>
<br/>class sittiming

</dl>

<ul><a name="query_situations">
query_situations</a><pre>
mapping query_situations()
</pre></br>
returns mapping of situations. 
<br/><ul>
<li><b>Returns:</b>
<br/>mapping of situations

</dl>

<ul><a name="query_status">
query_status</a><pre>
int query_status()
</pre></br>
returns status of situation manager.  
If it is sleeping it will turn on again if a
player enters the room.
<br/><ul>
<li><b>Returns:</b>
<br/>status 0 off 1 on 2 sleeping

</dl>

<ul><a name="set_room">
set_room</a><pre>
object set_room(object room_o)
</pre>
<ul><a name="shutdown_all_situations">
shutdown_all_situations</a><pre>
void shutdown_all_situations()
</pre></br>
Shuts down all current and pending situations.  It also turns off the
automated situation manager so no more are added.  It does not
destruct this object so all the add_situations are still loaded
and may be recommenced with automate_situation or change_situation.  
dest_me is the appropriate call to permanently remove all situations.
<br/><ul>
<li><b>See also:</b>
<br/>automate_situation.c and change_situation
.c</dl>

<ul><a name="shutdown_situation">
shutdown_situation</a><pre>
void shutdown_situation(int handle,
                        mixed label)
</pre></br>
Shuts down a change_situation based on the call_out handle
returned by the call to change_situation.
<br/><ul>
<li><b>Parameters:</b>
<br/>handle - call_out handle.  If 0 then the last
known handle is used.
<br/>label - label or array of labels of situations to clean 
up with end_situation
<br/>the_room - the room
<li><b>See also:</b>
<br/>automate_situation.c and change_situation
.c</dl>

<ul><a name="start_situation">
start_situation</a><pre>
void start_situation(mixed label,
                     int do_start_mess)
</pre></br>
Starts a situation previously added to the room
that is managed by this object.
These situations can be invoked manually with 
start_situation or automatically via
automate_situation. 
<br/><ul>
<li><b>Parameters:</b>
<br/>label - string or number labelling the situation
<br/>do_start_mess - 0 to supress the start_mess string
       This is to fake it that a situation has been 
       going for a while when really you just loaded it.
<li><b>See also:</b>
<br/>add_situation.c, end_situation.c and automate_situation
.c</dl>


<h2>Classes</h2>
These are nice data types for dealing with...  Data!<p>
<ul>
<li><a name="class_situation_timing">
situation_timing</a><pre>
class situation_timing {
                         mixed label;
                         mixed duration;
                         mixed when;
                         int chance;
                         int * endat;
                         mixed background;
                         mixed category;
                         int it;
                         mapping it_data;
}

</pre>
</ul>
[an error occurred while processing this directive]

