/*

  [BC] b_bot.cpp
  Last updated: 10/4/2000

  This section of code contains the console commands
  related to the bots, such as "addbot" and "removebot".
  It also contains a console command that displays all
  of the bot path nodes on the level, which can be particularly
  helpful for developers, and for people who need to pay
  close attention to their movement.

*/

#include <string.h>

#include "c_cvars.h"
#include "c_dispatch.h"
#include "b_bot.h"
#include "m_argv.h"
#include "doomstat.h"
#include "p_local.h"
#include "cmdlib.h"
#include "p_lnspec.h"

// Add a secret bot to the skirmish menu
BEGIN_COMMAND (reveal)
{
	if (argc < 2)
	{
		Printf (PRINT_HIGH, "reveal [botname]: reveals a secret bot");
		return;
	}

	for (int i=0; i<NUMTOTALBOTS; i++)
		if (!stricmp (argv[1], botinfo[i].name))
			botinfo[i].revealed = true;

	for (i=0; i<(int)numskins; i++)
		if (!stricmp (argv[1], skins[i].name))
			skins[i].hidden = false;
}
END_COMMAND (reveal)

BEGIN_COMMAND (addbot)
{
	if (oldschool.value)
		return;

	if (lockspvars && !sv_cheats.value)
	{
		Printf (PRINT_HIGH, "Bots cannot currently be added.\n");
		return;
	}
	if (netstate == NS_CLIENT)
	{
		Printf (PRINT_HIGH, "Only the host can add bots\n");
		return;
	}

	if (argc > 3)
	{
		Printf (PRINT_HIGH, "addbot [botname] [red/blue]: add a bot to the game\n");
		return;
	}

	if (argc > 2)
		B_Spawn(argv[1], argv[2]);
	else if (argc > 1)
		B_Spawn(argv[1], NULL);
	else
		B_Spawn(NULL, NULL);
}
END_COMMAND (addbot)

void ClearPlayer (int i)
{
	if (players[i].mo)
	{
		players[i].mo->Destroy ();
		players[i].mo = NULL;
	}
	if (players[i].skullb)
	{
		delete players[i].skullb;
		players[i].skullb = NULL;
	}
	memset (&players[i], 0, sizeof(player_t));
	playeringame[i] = false;
}

BEGIN_COMMAND (removebot)
{
	if (lockspvars && !sv_cheats.value)
	{
		Printf (PRINT_HIGH, "Bots cannot currently be removed.\n");
		return;
	}
	if (argc < 2)
	{
		Printf (PRINT_HIGH, "removebot [botname]: remove a bot from the game\n");
		return;
	}
	if (argc)
		B_Remove (argv[1]);
}
END_COMMAND (removebot)

BEGIN_COMMAND (removebots)
{
	if (lockspvars && !sv_cheats.value)
	{
		Printf (PRINT_HIGH, "Bots cannot currently be removed.\n");
		return;
	}

	Net_Command (DEM_KILLBOTS, 0, NULL, consoleplayer);
}
END_COMMAND (removebots)

BEGIN_COMMAND (listbots)
{
	int count = 0;

	Printf (PRINT_HIGH, "Active bots:\n\n");

	for (int i=0; i<MAXPLAYERS; i++)
	{
		if (playeringame[i] && players[i].skullb)
		{
			Printf (PRINT_HIGH, "%s\n", players[i].userinfo.netname);
			count++;
		}
	}
	Printf (PRINT_HIGH, "\n%d bot(s).\n", count);
}
END_COMMAND (listbots)

// Make all bot nodes visible (for all you developers)
BEGIN_COMMAND (shownodes)
{
	AActor *actor;
	TThinkerIterator<AActor> iterator;

	while (actor = iterator.Next ())
		if (actor->flags3 & MF3_NODE)
			P_SetMobjState (actor, S_PLASBALL);
}
END_COMMAND (shownodes)