Add pCampbot "remove behaviour" console command for removing bot behaviours during operation.
Doesn't currently work very well as stopping physics, for instance, can leave bot travelling in old direction0.7.6-extended
parent
7284cb76b6
commit
2a7b4c9db9
|
@ -184,6 +184,12 @@ namespace pCampBot
|
||||||
CreateLibOmvClient();
|
CreateLibOmvClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TryGetBehaviour(string abbreviatedName, out IBehaviour behaviour)
|
||||||
|
{
|
||||||
|
lock (Behaviours)
|
||||||
|
return Behaviours.TryGetValue(abbreviatedName, out behaviour);
|
||||||
|
}
|
||||||
|
|
||||||
public bool AddBehaviour(IBehaviour behaviour)
|
public bool AddBehaviour(IBehaviour behaviour)
|
||||||
{
|
{
|
||||||
lock (Behaviours)
|
lock (Behaviours)
|
||||||
|
@ -200,6 +206,12 @@ namespace pCampBot
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RemoveBehaviour(string abbreviatedName)
|
||||||
|
{
|
||||||
|
lock (Behaviours)
|
||||||
|
return Behaviours.Remove(abbreviatedName);
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateLibOmvClient()
|
private void CreateLibOmvClient()
|
||||||
{
|
{
|
||||||
GridClient newClient = new GridClient();
|
GridClient newClient = new GridClient();
|
||||||
|
|
|
@ -200,11 +200,11 @@ namespace pCampBot
|
||||||
"Can be performed on connected or disconnected bots.",
|
"Can be performed on connected or disconnected bots.",
|
||||||
HandleAddBehaviour);
|
HandleAddBehaviour);
|
||||||
|
|
||||||
// m_console.Commands.AddCommand(
|
m_console.Commands.AddCommand(
|
||||||
// "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> <bot-number>",
|
"bot", false, "remove behaviour", "remove behaviour <abbreviated-name> <bot-number>",
|
||||||
// "Remove a behaviour from a bot",
|
"Remove a behaviour from a bot",
|
||||||
// "Can be performed on connected or disconnected bots.",
|
"Can be performed on connected or disconnected bots.",
|
||||||
// HandleRemoveBehaviour);
|
HandleRemoveBehaviour);
|
||||||
|
|
||||||
m_console.Commands.AddCommand(
|
m_console.Commands.AddCommand(
|
||||||
"bot", false, "sit", "sit", "Sit all bots on the ground.",
|
"bot", false, "sit", "sit", "Sit all bots on the ground.",
|
||||||
|
@ -525,6 +525,49 @@ namespace pCampBot
|
||||||
string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
|
string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleRemoveBehaviour(string module, string[] cmd)
|
||||||
|
{
|
||||||
|
if (cmd.Length != 4)
|
||||||
|
{
|
||||||
|
MainConsole.Instance.OutputFormat("Usage: remove behaviour <abbreviated-behaviour> <bot-number>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string rawBehaviours = cmd[2];
|
||||||
|
int botNumber;
|
||||||
|
|
||||||
|
if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bot bot = GetBotFromNumber(botNumber);
|
||||||
|
|
||||||
|
if (bot == null)
|
||||||
|
{
|
||||||
|
MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<string> abbreviatedBehavioursToRemove = new HashSet<string>();
|
||||||
|
List<IBehaviour> behavioursRemoved = new List<IBehaviour>();
|
||||||
|
|
||||||
|
Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => abbreviatedBehavioursToRemove.Add(b));
|
||||||
|
|
||||||
|
foreach (string b in abbreviatedBehavioursToRemove)
|
||||||
|
{
|
||||||
|
IBehaviour behaviour;
|
||||||
|
|
||||||
|
if (bot.TryGetBehaviour(b, out behaviour))
|
||||||
|
{
|
||||||
|
bot.RemoveBehaviour(b);
|
||||||
|
behavioursRemoved.Add(behaviour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MainConsole.Instance.OutputFormat(
|
||||||
|
"Removed behaviours {0} to bot {1}",
|
||||||
|
string.Join(", ", behavioursRemoved.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleDisconnect(string module, string[] cmd)
|
private void HandleDisconnect(string module, string[] cmd)
|
||||||
{
|
{
|
||||||
lock (m_bots)
|
lock (m_bots)
|
||||||
|
|
Loading…
Reference in New Issue