aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-09-03 19:05:54 +0100
committerJustin Clark-Casey (justincc)2013-09-04 00:48:06 +0100
commit2a7b4c9db9c72c22ff90e3879e2cc9a5134d679a (patch)
tree91ffdd1722d0b276ef41fba934ea796d69d181a3 /OpenSim
parentAdd ability to adjust pCampbot bot behaviours whilst running with "add behavi... (diff)
downloadopensim-SC_OLD-2a7b4c9db9c72c22ff90e3879e2cc9a5134d679a.zip
opensim-SC_OLD-2a7b4c9db9c72c22ff90e3879e2cc9a5134d679a.tar.gz
opensim-SC_OLD-2a7b4c9db9c72c22ff90e3879e2cc9a5134d679a.tar.bz2
opensim-SC_OLD-2a7b4c9db9c72c22ff90e3879e2cc9a5134d679a.tar.xz
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 direction
Diffstat (limited to '')
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs12
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs53
2 files changed, 60 insertions, 5 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index 6037516..0bd8151 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -184,6 +184,12 @@ namespace pCampBot
184 CreateLibOmvClient(); 184 CreateLibOmvClient();
185 } 185 }
186 186
187 public bool TryGetBehaviour(string abbreviatedName, out IBehaviour behaviour)
188 {
189 lock (Behaviours)
190 return Behaviours.TryGetValue(abbreviatedName, out behaviour);
191 }
192
187 public bool AddBehaviour(IBehaviour behaviour) 193 public bool AddBehaviour(IBehaviour behaviour)
188 { 194 {
189 lock (Behaviours) 195 lock (Behaviours)
@@ -200,6 +206,12 @@ namespace pCampBot
200 return false; 206 return false;
201 } 207 }
202 208
209 public bool RemoveBehaviour(string abbreviatedName)
210 {
211 lock (Behaviours)
212 return Behaviours.Remove(abbreviatedName);
213 }
214
203 private void CreateLibOmvClient() 215 private void CreateLibOmvClient()
204 { 216 {
205 GridClient newClient = new GridClient(); 217 GridClient newClient = new GridClient();
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 51c5ff4..6433c2e 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -200,11 +200,11 @@ namespace pCampBot
200 "Can be performed on connected or disconnected bots.", 200 "Can be performed on connected or disconnected bots.",
201 HandleAddBehaviour); 201 HandleAddBehaviour);
202 202
203// m_console.Commands.AddCommand( 203 m_console.Commands.AddCommand(
204// "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> <bot-number>", 204 "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> <bot-number>",
205// "Remove a behaviour from a bot", 205 "Remove a behaviour from a bot",
206// "Can be performed on connected or disconnected bots.", 206 "Can be performed on connected or disconnected bots.",
207// HandleRemoveBehaviour); 207 HandleRemoveBehaviour);
208 208
209 m_console.Commands.AddCommand( 209 m_console.Commands.AddCommand(
210 "bot", false, "sit", "sit", "Sit all bots on the ground.", 210 "bot", false, "sit", "sit", "Sit all bots on the ground.",
@@ -525,6 +525,49 @@ namespace pCampBot
525 string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name); 525 string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
526 } 526 }
527 527
528 private void HandleRemoveBehaviour(string module, string[] cmd)
529 {
530 if (cmd.Length != 4)
531 {
532 MainConsole.Instance.OutputFormat("Usage: remove behaviour <abbreviated-behaviour> <bot-number>");
533 return;
534 }
535
536 string rawBehaviours = cmd[2];
537 int botNumber;
538
539 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
540 return;
541
542 Bot bot = GetBotFromNumber(botNumber);
543
544 if (bot == null)
545 {
546 MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber);
547 return;
548 }
549
550 HashSet<string> abbreviatedBehavioursToRemove = new HashSet<string>();
551 List<IBehaviour> behavioursRemoved = new List<IBehaviour>();
552
553 Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => abbreviatedBehavioursToRemove.Add(b));
554
555 foreach (string b in abbreviatedBehavioursToRemove)
556 {
557 IBehaviour behaviour;
558
559 if (bot.TryGetBehaviour(b, out behaviour))
560 {
561 bot.RemoveBehaviour(b);
562 behavioursRemoved.Add(behaviour);
563 }
564 }
565
566 MainConsole.Instance.OutputFormat(
567 "Removed behaviours {0} to bot {1}",
568 string.Join(", ", behavioursRemoved.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
569 }
570
528 private void HandleDisconnect(string module, string[] cmd) 571 private void HandleDisconnect(string module, string[] cmd)
529 { 572 {
530 lock (m_bots) 573 lock (m_bots)