aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-09-03 19:57:34 +0100
committerJustin Clark-Casey (justincc)2013-09-03 19:57:34 +0100
commit9c3c9b7f5f62a7ed892f691180b765a9190cbbcc (patch)
tree695058c25c15faceb8b1c0c265f10ea0739ed1e7 /OpenSim/Tools/pCampBot
parentConsistently give responsibility for thread sleeping to behaviours rather tha... (diff)
downloadopensim-SC-9c3c9b7f5f62a7ed892f691180b765a9190cbbcc.zip
opensim-SC-9c3c9b7f5f62a7ed892f691180b765a9190cbbcc.tar.gz
opensim-SC-9c3c9b7f5f62a7ed892f691180b765a9190cbbcc.tar.bz2
opensim-SC-9c3c9b7f5f62a7ed892f691180b765a9190cbbcc.tar.xz
Make pCampbot "add behaviour" and "remove behaviour" console commands work for all bots if no bot number is given
Diffstat (limited to 'OpenSim/Tools/pCampBot')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs123
1 files changed, 78 insertions, 45 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 6433c2e..3c1b11e 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -195,15 +195,17 @@ namespace pCampBot
195 HandleDisconnect); 195 HandleDisconnect);
196 196
197 m_console.Commands.AddCommand( 197 m_console.Commands.AddCommand(
198 "bot", false, "add behaviour", "add behaviour <abbreviated-name> <bot-number>", 198 "bot", false, "add behaviour", "add behaviour <abbreviated-name> [<bot-number>]",
199 "Add a behaviour to a bot", 199 "Add a behaviour to a bot",
200 "Can be performed on connected or disconnected bots.", 200 "If no bot number is specified then behaviour is added to all bots.\n"
201 + "Can be performed on connected or disconnected bots.",
201 HandleAddBehaviour); 202 HandleAddBehaviour);
202 203
203 m_console.Commands.AddCommand( 204 m_console.Commands.AddCommand(
204 "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> <bot-number>", 205 "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> [<bot-number>]",
205 "Remove a behaviour from a bot", 206 "Remove a behaviour from a bot",
206 "Can be performed on connected or disconnected bots.", 207 "If no bot number is specified then behaviour is added to all bots.\n"
208 + "Can be performed on connected or disconnected bots.",
207 HandleRemoveBehaviour); 209 HandleRemoveBehaviour);
208 210
209 m_console.Commands.AddCommand( 211 m_console.Commands.AddCommand(
@@ -224,7 +226,7 @@ namespace pCampBot
224 "bot", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus); 226 "bot", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus);
225 227
226 m_console.Commands.AddCommand( 228 m_console.Commands.AddCommand(
227 "bot", false, "show bot", "show bot <n>", 229 "bot", false, "show bot", "show bot <bot-number>",
228 "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus); 230 "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);
229 231
230 m_bots = new List<Bot>(); 232 m_bots = new List<Bot>();
@@ -489,83 +491,114 @@ namespace pCampBot
489 491
490 private void HandleAddBehaviour(string module, string[] cmd) 492 private void HandleAddBehaviour(string module, string[] cmd)
491 { 493 {
492 if (cmd.Length != 4) 494 if (cmd.Length < 3 || cmd.Length > 4)
493 { 495 {
494 MainConsole.Instance.OutputFormat("Usage: add behaviour <abbreviated-behaviour> <bot-number>"); 496 MainConsole.Instance.OutputFormat("Usage: add behaviour <abbreviated-behaviour> [<bot-number>]");
495 return; 497 return;
496 } 498 }
497 499
498 string rawBehaviours = cmd[2]; 500 string rawBehaviours = cmd[2];
499 int botNumber;
500
501 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
502 return;
503 501
504 Bot bot = GetBotFromNumber(botNumber); 502 List<Bot> botsToEffect = new List<Bot>();
505 503
506 if (bot == null) 504 if (cmd.Length == 3)
507 { 505 {
508 MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber); 506 lock (m_bots)
509 return; 507 botsToEffect.AddRange(m_bots);
510 } 508 }
509 else
510 {
511 int botNumber;
512 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
513 return;
514
515 Bot bot = GetBotFromNumber(botNumber);
516
517 if (bot == null)
518 {
519 MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber);
520 return;
521 }
522
523 botsToEffect.Add(bot);
524 }
525
511 526
512 HashSet<string> rawAbbreviatedSwitchesToAdd = new HashSet<string>(); 527 HashSet<string> rawAbbreviatedSwitchesToAdd = new HashSet<string>();
513 Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => rawAbbreviatedSwitchesToAdd.Add(b)); 528 Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => rawAbbreviatedSwitchesToAdd.Add(b));
514 529
515 List<IBehaviour> behavioursAdded = new List<IBehaviour>(); 530 foreach (Bot bot in botsToEffect)
516
517 foreach (IBehaviour behaviour in CreateBehavioursFromAbbreviatedNames(rawAbbreviatedSwitchesToAdd))
518 { 531 {
519 if (bot.AddBehaviour(behaviour)) 532 List<IBehaviour> behavioursAdded = new List<IBehaviour>();
520 behavioursAdded.Add(behaviour);
521 }
522 533
523 MainConsole.Instance.OutputFormat( 534 foreach (IBehaviour behaviour in CreateBehavioursFromAbbreviatedNames(rawAbbreviatedSwitchesToAdd))
524 "Added behaviours {0} to bot {1}", 535 {
525 string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name); 536 if (bot.AddBehaviour(behaviour))
537 behavioursAdded.Add(behaviour);
538 }
539
540 MainConsole.Instance.OutputFormat(
541 "Added behaviours {0} to bot {1}",
542 string.Join(", ", behavioursAdded.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
543 }
526 } 544 }
527 545
528 private void HandleRemoveBehaviour(string module, string[] cmd) 546 private void HandleRemoveBehaviour(string module, string[] cmd)
529 { 547 {
530 if (cmd.Length != 4) 548 if (cmd.Length < 3 || cmd.Length > 4)
531 { 549 {
532 MainConsole.Instance.OutputFormat("Usage: remove behaviour <abbreviated-behaviour> <bot-number>"); 550 MainConsole.Instance.OutputFormat("Usage: remove behaviour <abbreviated-behaviour> [<bot-number>]");
533 return; 551 return;
534 } 552 }
535 553
536 string rawBehaviours = cmd[2]; 554 string rawBehaviours = cmd[2];
537 int botNumber;
538
539 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
540 return;
541 555
542 Bot bot = GetBotFromNumber(botNumber); 556 List<Bot> botsToEffect = new List<Bot>();
543 557
544 if (bot == null) 558 if (cmd.Length == 3)
545 { 559 {
546 MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber); 560 lock (m_bots)
547 return; 561 botsToEffect.AddRange(m_bots);
548 } 562 }
563 else
564 {
565 int botNumber;
566 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[3], out botNumber))
567 return;
549 568
550 HashSet<string> abbreviatedBehavioursToRemove = new HashSet<string>(); 569 Bot bot = GetBotFromNumber(botNumber);
551 List<IBehaviour> behavioursRemoved = new List<IBehaviour>(); 570
571 if (bot == null)
572 {
573 MainConsole.Instance.OutputFormat("Error: No bot found with number {0}", botNumber);
574 return;
575 }
552 576
577 botsToEffect.Add(bot);
578 }
579
580 HashSet<string> abbreviatedBehavioursToRemove = new HashSet<string>();
553 Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => abbreviatedBehavioursToRemove.Add(b)); 581 Array.ForEach<string>(rawBehaviours.Split(new char[] { ',' }), b => abbreviatedBehavioursToRemove.Add(b));
554 582
555 foreach (string b in abbreviatedBehavioursToRemove) 583 foreach (Bot bot in botsToEffect)
556 { 584 {
557 IBehaviour behaviour; 585 List<IBehaviour> behavioursRemoved = new List<IBehaviour>();
558 586
559 if (bot.TryGetBehaviour(b, out behaviour)) 587 foreach (string b in abbreviatedBehavioursToRemove)
560 { 588 {
561 bot.RemoveBehaviour(b); 589 IBehaviour behaviour;
562 behavioursRemoved.Add(behaviour); 590
591 if (bot.TryGetBehaviour(b, out behaviour))
592 {
593 bot.RemoveBehaviour(b);
594 behavioursRemoved.Add(behaviour);
595 }
563 } 596 }
564 }
565 597
566 MainConsole.Instance.OutputFormat( 598 MainConsole.Instance.OutputFormat(
567 "Removed behaviours {0} to bot {1}", 599 "Removed behaviours {0} to bot {1}",
568 string.Join(", ", behavioursRemoved.ConvertAll<string>(b => b.Name).ToArray()), bot.Name); 600 string.Join(", ", behavioursRemoved.ConvertAll<string>(b => b.Name).ToArray()), bot.Name);
601 }
569 } 602 }
570 603
571 private void HandleDisconnect(string module, string[] cmd) 604 private void HandleDisconnect(string module, string[] cmd)