/*
   /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 (!IS_CLONE)
	return;

    if (!this_object()->seq_query(SEQ_CHAT))
    {
	this_object()->seq_new(SEQ_CHAT);
	this_object()->seq_clear(SEQ_CHAT);
	this_object()->seq_addfirst(SEQ_CHAT, ({ random(4), 
	    "@@room_do_event" }));
    }

    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
 */
string
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;
    this_object()->seq_clear(SEQ_CHAT);
    this_object()->seq_addfirst(SEQ_CHAT,
	({ il, "@@room_do_event" }) );
	
    return say(chatstr)
}

public string
query_seq_event_name()
{
    return SEQ_CHAT;
}
