/*
   /std/act/chat.c

   Chatting: Standard action module for mobiles

   add_chat(string)	       Set a random chatstring 

   add_cchat(string)           Set a random combat chatstring 

   clear_chat()		       Clear random chatstring

   clear_cchat()	       Clear random combat chatstring

   set_chat_time(int)	       Set the mean value for chat intervall

   set_cchat_time(int)	       Set the mean value for combat chat intervall

*/
#pragma save_binary
#pragma strict_types
inherit "/std/act/seqaction";
#include <macros.h>
string room_do_event();
static	int	room_event_time;     /* Intervall between chat */

static  string  *room_event,	     
    		*room_event_left;


#define SEQ_CHAT  "_room_event"

/*
 * Function name: add_event
 * Description:   Adds a chat string that the monster will randomly say.
 * Arguments:	  str: Text
 */
void
add_event(mixed str)
{
    if(!str)
	return;

    if (!sizeof(room_event))
	room_event = ({});

    room_event += ({ str });
    room_event_left = room_event;
}

string *query_event() { return room_event; }

/*
 * Function name: add_cchat
 * Description:   Sets a combat chat string that the monster will randomly say
 * Arguments:	  str: Text
 */
/*
 * Function name: clear_chat
 * Description:   Clear random chatstring
 */
void
clear_event()
{
    room_event = room_event_left = 0;
}

/* Function name: set_chat_time
 * Description:   Set the mean value for chat intervall
 * Arguments:	  tim: Intervall
 */
void
set_event_time(int tim)
{
    room_event_time = tim;
}




/*
 * Sequence functions
 */

/*
 *  Description: The actual function chatting, called by VBFC in seq_heartbeat
 */
void
room_do_event()
{
    int il;
    string chatstr;

	if (!sizeof(room_event_left))
	    room_event_left = room_event;

	if (!(il=sizeof(room_event_left)))
	    return 0;

	il = random(il);
	chatstr = room_event_left[il];
	room_event_left = exclude_array(room_event_left,il,il);
	il = room_event_time;
	
    write(chatstr+"\n");
    room_do_event();
}

public string
query_seq_event_name()
{
    return SEQ_CHAT;
}
