// plugin_sank_AI.sma
// Author: Luke Sankey
// Date April 4, 2001
//
// Fuctions included in this plugin:
// Intercepts clients saying:
//  next && map
//  time && left
//  current && map
//  friendly fire || ff on || ff was on || ff is on
//  server && suck || hate || fuck
//  server && ip
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
//#include <sound> // get this from the sank_sounds plugin
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
 
public plugin_init() 
{
	plugin_registerinfo("Sank Artificial Intelligence Plugin", "Responds to certain chat messages.", STRING_VERSION);
 
	plugin_registercmd("say", "HandleSay", ACCESS_ALL);
	plugin_registerhelp("say", ACCESS_ALL, "say next map: Displays the next map.");
	plugin_registerhelp("say", ACCESS_ALL, "say current map: Displays the current map.");
	plugin_registerhelp("say", ACCESS_ALL, "say time left: Displays the time left.");
	plugin_registerhelp("say", ACCESS_ALL, "say server ip: Displays the server's IP address.");
 
	return PLUGIN_CONTINUE;
}
 
 
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
 
 
///////////////////////////////////////////////////////////////////////////////
// TODO: comments needed here
///////////////////////////////////////////////////////////////////////////////
public HandleSay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new Command[MAX_COMMAND_LENGTH];
	new Speech[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	convert_string(HLCommand, Command, MAX_COMMAND_LENGTH);
	convert_string(HLData, Speech, MAX_DATA_LENGTH);
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	strstripquotes(Speech);
 
 
	// When people ask how much time is left...
	if ( (strcasestr(Speech, "time") != -1) && (strcasestr(Speech, "left") != -1) )
	{
		new iRounds = 0;
		new iWins = 0;
		new iTime = timeleft(0);
		iTime /= 60;						// Convert from seconds to minutes
		iRounds = getvar("mp_maxrounds");	// Get the number of maxrounds
		iWins = getvar("mp_winlimit");
 
		say("<Server Auto-Response> Map changes when:");
		if (iTime != 0)
		{
			snprintf(Text, MAX_TEXT_LENGTH, "  The remaining %i minutes is up", iTime);
			say(Text);
		}
		if (iRounds != 0)
		{
			snprintf(Text, MAX_TEXT_LENGTH, "  Maximum rounds of %i is reached", iRounds);
			say(Text);
		}
		if (iWins != 0)
		{
			snprintf(Text, MAX_TEXT_LENGTH, "  A team wins the maximum of %i rounds", iWins);
			say(Text);
		}
	}
 
	// If they ask which map is next
	else if ( (strcasestr(Speech, "next") != -1) && (strcasestr(Speech, "map") != -1) )
	{
		new NextMap[MAX_NAME_LENGTH];
		nextmap(NextMap, MAX_NAME_LENGTH);
 
		snprintf(Text, MAX_TEXT_LENGTH, "<Server Auto-Response> The next map will be: %s", NextMap);
		say(Text);
	}
 
	// If they ask which map this is
	else if ( (strcasestr(Speech, "current") != -1) && (strcasestr(Speech, "map") != -1) )
	{
		new ThisMap[MAX_NAME_LENGTH];
		currentmap(ThisMap, MAX_NAME_LENGTH);
 
		snprintf(Text, MAX_TEXT_LENGTH, "<Server Auto-Response> The current map is: %s", ThisMap);
		say(Text);
	}
 
	// If we think user is asking about friendly fire, we should answer
	else if ( (strcasestr(Speech, "friendly fire") != -1) || (strcasestr(Speech, " ff on") != -1) || (strcasestr(Speech, " ff was on") != -1) || (strcasestr(Speech, "ff is on") != -1) )
	{
		if (getvar("mp_friendlyfire") == 1)
		{
			say("<Server Auto-Response> Friendly fire is ON");
		}
		else
		{
			say("<Server Auto-Response> Friendly fire is OFF");
		}
	}
 
	// If they say something about how they hate the server, they can leave.
	else if ( (strcasestr(Speech, "server") != -1) &&
			( (strcasestr(Speech, "suck") != -1) || (strcasestr(Speech, "hate") != -1) || (strcasestr(Speech, "fuck") != -1) ))
	{
		if(access(ACCESS_IMMUNITY, User) == 0)
		{
			//playsoundall("misc\comeagain.wav"); get this from the sank_sounds plugin
			selfmessage("The server has decided that you don't like it here.");
			snprintf(Text, MAX_TEXT_LENGTH, "<Server Auto-Response> Thanks for playing, %s", User);
			say(Text);
			kick(User);
		}
	}
 
	// Server IP address is...
	else if ( (strcasestr(Speech, "server") != -1) && (strcasestr(Speech, "ip") != -1) )
	{
		snprintf(Text, MAX_TEXT_LENGTH, "<Server Auto-Response> Server IP: I FORGOT TO PUT MY IP IN THE SCRIPT");
		say(Text);
	}
 
	return PLUGIN_CONTINUE;
}