aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-11-24 22:36:45 +0000
committerJustin Clark-Casey (justincc)2011-11-24 22:36:45 +0000
commit2ae5b40ca6bb3d33310f0f66569bf150548a2de6 (patch)
tree9c485fa9e2e9d1b2d976d3b6d9777457b836df36 /OpenSim
parentminor: remove mono compiler warning (diff)
downloadopensim-SC-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.zip
opensim-SC-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.gz
opensim-SC-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.bz2
opensim-SC-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.xz
On pCampBot, add bot as a property on behaviours instead of passing it in every time
Diffstat (limited to '')
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs49
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs16
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs31
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs22
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs4
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs38
-rw-r--r--OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs11
7 files changed, 115 insertions, 56 deletions
diff --git a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs
new file mode 100644
index 0000000..9a9371d
--- /dev/null
+++ b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs
@@ -0,0 +1,49 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29using System;
30using System.Collections.Generic;
31using System.Linq;
32using pCampBot.Interfaces;
33
34namespace pCampBot
35{
36 public class AbstractBehaviour : IBehaviour
37 {
38 public string Name { get; protected set; }
39
40 public Bot Bot { get; protected set; }
41
42 public virtual void Action() {}
43
44 public virtual void Initialize(Bot bot)
45 {
46 Bot = bot;
47 }
48 }
49}
diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
index 0a6d5d2..6ad02b2 100644
--- a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
@@ -39,20 +39,20 @@ namespace pCampBot
39 /// <remarks> 39 /// <remarks>
40 /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable. 40 /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable.
41 /// </remarks> 41 /// </remarks>
42 public class GrabbingBehaviour : IBehaviour 42 public class GrabbingBehaviour : AbstractBehaviour
43 { 43 {
44 public string Name { get { return "Grabbing"; } } 44 public GrabbingBehaviour() { Name = "Grabbing"; }
45 45
46 public void Action(Bot bot) 46 public override void Action()
47 { 47 {
48 Dictionary<UUID, Primitive> objects = bot.Objects; 48 Dictionary<UUID, Primitive> objects = Bot.Objects;
49 49
50 Primitive prim = objects.ElementAt(bot.Random.Next(0, objects.Count)).Value; 50 Primitive prim = objects.ElementAt(Bot.Random.Next(0, objects.Count)).Value;
51 51
52 // This appears to be a typical message sent when a viewer user clicks a clickable object 52 // This appears to be a typical message sent when a viewer user clicks a clickable object
53 bot.Client.Self.Grab(prim.LocalID); 53 Bot.Client.Self.Grab(prim.LocalID);
54 bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero); 54 Bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero);
55 bot.Client.Self.DeGrab(prim.LocalID); 55 Bot.Client.Self.DeGrab(prim.LocalID);
56 } 56 }
57 } 57 }
58} \ No newline at end of file 58} \ No newline at end of file
diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
index 25529d0..daa7485 100644
--- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
@@ -40,42 +40,41 @@ namespace pCampBot
40 /// <remarks> 40 /// <remarks>
41 /// TODO: talkarray should be in a separate behaviour. 41 /// TODO: talkarray should be in a separate behaviour.
42 /// </remarks> 42 /// </remarks>
43 public class PhysicsBehaviour : IBehaviour 43 public class PhysicsBehaviour : AbstractBehaviour
44 { 44 {
45 public string Name { get { return "Physics"; } }
46
47 private string[] talkarray; 45 private string[] talkarray;
48 46
49 public PhysicsBehaviour() 47 public PhysicsBehaviour()
50 { 48 {
49 Name = "Physics";
51 talkarray = readexcuses(); 50 talkarray = readexcuses();
52 } 51 }
53 52
54 public void Action(Bot bot) 53 public override void Action()
55 { 54 {
56 int walkorrun = bot.Random.Next(4); // Randomize between walking and running. The greater this number, 55 int walkorrun = Bot.Random.Next(4); // Randomize between walking and running. The greater this number,
57 // the greater the bot's chances to walk instead of run. 56 // the greater the bot's chances to walk instead of run.
58 bot.Client.Self.Jump(false); 57 Bot.Client.Self.Jump(false);
59 if (walkorrun == 0) 58 if (walkorrun == 0)
60 { 59 {
61 bot.Client.Self.Movement.AlwaysRun = true; 60 Bot.Client.Self.Movement.AlwaysRun = true;
62 } 61 }
63 else 62 else
64 { 63 {
65 bot.Client.Self.Movement.AlwaysRun = false; 64 Bot.Client.Self.Movement.AlwaysRun = false;
66 } 65 }
67 66
68 // TODO: unused: Vector3 pos = client.Self.SimPosition; 67 // TODO: unused: Vector3 pos = client.Self.SimPosition;
69 Vector3 newpos = new Vector3(bot.Random.Next(1, 254), bot.Random.Next(1, 254), bot.Random.Next(1, 254)); 68 Vector3 newpos = new Vector3(Bot.Random.Next(1, 254), Bot.Random.Next(1, 254), Bot.Random.Next(1, 254));
70 bot.Client.Self.Movement.TurnToward(newpos); 69 Bot.Client.Self.Movement.TurnToward(newpos);
71 70
72 bot.Client.Self.Movement.AtPos = true; 71 Bot.Client.Self.Movement.AtPos = true;
73 Thread.Sleep(bot.Random.Next(3000, 13000)); 72 Thread.Sleep(Bot.Random.Next(3000, 13000));
74 bot.Client.Self.Movement.AtPos = false; 73 Bot.Client.Self.Movement.AtPos = false;
75 bot.Client.Self.Jump(true); 74 Bot.Client.Self.Jump(true);
76 string randomf = talkarray[bot.Random.Next(talkarray.Length)]; 75 string randomf = talkarray[Bot.Random.Next(talkarray.Length)];
77 if (talkarray.Length > 1 && randomf.Length > 1) 76 if (talkarray.Length > 1 && randomf.Length > 1)
78 bot.Client.Self.Chat(randomf, 0, ChatType.Normal); 77 Bot.Client.Self.Chat(randomf, 0, ChatType.Normal);
79 } 78 }
80 79
81 private string[] readexcuses() 80 private string[] readexcuses()
diff --git a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs
index fc2ed2c..fbb4e96 100644
--- a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs
@@ -38,38 +38,38 @@ namespace pCampBot
38 /// <summary> 38 /// <summary>
39 /// Teleport to a random region on the grid. 39 /// Teleport to a random region on the grid.
40 /// </summary> 40 /// </summary>
41 public class TeleportBehaviour : IBehaviour 41 public class TeleportBehaviour : AbstractBehaviour
42 { 42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
45 public string Name { get { return "Teleport"; } } 45 public TeleportBehaviour() { Name = "Teleport"; }
46 46
47 public void Action(Bot bot) 47 public override void Action()
48 { 48 {
49 Random rng = bot.Manager.Rng; 49 Random rng = Bot.Manager.Rng;
50 GridRegion[] knownRegions; 50 GridRegion[] knownRegions;
51 51
52 lock (bot.Manager.RegionsKnown) 52 lock (Bot.Manager.RegionsKnown)
53 { 53 {
54 if (bot.Manager.RegionsKnown.Count == 0) 54 if (Bot.Manager.RegionsKnown.Count == 0)
55 { 55 {
56 m_log.DebugFormat( 56 m_log.DebugFormat(
57 "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", bot.Name); 57 "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", Bot.Name);
58 return; 58 return;
59 } 59 }
60 60
61 knownRegions = bot.Manager.RegionsKnown.Values.ToArray(); 61 knownRegions = Bot.Manager.RegionsKnown.Values.ToArray();
62 } 62 }
63 63
64 Simulator sourceRegion = bot.Client.Network.CurrentSim; 64 Simulator sourceRegion = Bot.Client.Network.CurrentSim;
65 GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)]; 65 GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)];
66 Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50); 66 Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50);
67 67
68 m_log.DebugFormat( 68 m_log.DebugFormat(
69 "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}", 69 "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}",
70 bot.Name, sourceRegion.Name, bot.Client.Self.SimPosition, destRegion.Name, destPosition); 70 Bot.Name, sourceRegion.Name, Bot.Client.Self.SimPosition, destRegion.Name, destPosition);
71 71
72 bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition); 72 Bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition);
73 } 73 }
74 } 74 }
75} \ No newline at end of file 75} \ No newline at end of file
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index 409734e..0bd0bcc 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -130,6 +130,8 @@ namespace pCampBot
130 BotManager bm, List<IBehaviour> behaviours, 130 BotManager bm, List<IBehaviour> behaviours,
131 string firstName, string lastName, string password, string loginUri) 131 string firstName, string lastName, string password, string loginUri)
132 { 132 {
133 behaviours.ForEach(b => b.Initialize(this));
134
133 Client = new GridClient(); 135 Client = new GridClient();
134 136
135 Random = new Random(Environment.TickCount);// We do stuff randomly here 137 Random = new Random(Environment.TickCount);// We do stuff randomly here
@@ -156,7 +158,7 @@ namespace pCampBot
156 b => 158 b =>
157 { 159 {
158 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); 160 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
159 b.Action(this); 161 b.Action();
160 162
161 Thread.Sleep(Random.Next(1000, 10000)); 163 Thread.Sleep(Random.Next(1000, 10000));
162 } 164 }
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index d91990f..6481e97 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -151,29 +151,29 @@ namespace pCampBot
151 Array.ForEach<string>( 151 Array.ForEach<string>(
152 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); 152 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
153 153
154 List<IBehaviour> behaviours = new List<IBehaviour>();
155
156 // Hard-coded for now
157 if (behaviourSwitches.Contains("p"))
158 behaviours.Add(new PhysicsBehaviour());
159
160 if (behaviourSwitches.Contains("g"))
161 behaviours.Add(new GrabbingBehaviour());
162
163 if (behaviourSwitches.Contains("t"))
164 behaviours.Add(new TeleportBehaviour());
165
166// if (behaviourSwitches.Contains("c"))
167// behaviours.Add(new CrossBehaviour());
168
169 MainConsole.Instance.OutputFormat(
170 "[BOT MANAGER]: Bots configured for behaviours {0}",
171 string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
172
173 for (int i = 0; i < botcount; i++) 154 for (int i = 0; i < botcount; i++)
174 { 155 {
175 string lastName = string.Format("{0}_{1}", lastNameStem, i); 156 string lastName = string.Format("{0}_{1}", lastNameStem, i);
176 157
158 List<IBehaviour> behaviours = new List<IBehaviour>();
159
160 // Hard-coded for now
161 if (behaviourSwitches.Contains("p"))
162 behaviours.Add(new PhysicsBehaviour());
163
164 if (behaviourSwitches.Contains("g"))
165 behaviours.Add(new GrabbingBehaviour());
166
167 if (behaviourSwitches.Contains("t"))
168 behaviours.Add(new TeleportBehaviour());
169
170 if (behaviourSwitches.Contains("c"))
171 behaviours.Add(new CrossBehaviour());
172
173 MainConsole.Instance.OutputFormat(
174 "[BOT MANAGER]: Bot {0} {1} configured for behaviours {2}",
175 firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
176
177 StartBot(this, behaviours, firstName, lastName, password, loginUri); 177 StartBot(this, behaviours, firstName, lastName, password, loginUri);
178 } 178 }
179 } 179 }
diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs
index 912216f..9c984be 100644
--- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs
@@ -37,9 +37,18 @@ namespace pCampBot.Interfaces
37 string Name { get; } 37 string Name { get; }
38 38
39 /// <summary> 39 /// <summary>
40 /// Initialize the behaviour for this bot.
41 /// </summary>
42 /// <remarks>
43 /// This must be invoked before Action() is called.
44 /// </remarks>
45 /// <param name="bot"></param>
46 void Initialize(Bot bot);
47
48 /// <summary>
40 /// Action to take when this behaviour is invoked. 49 /// Action to take when this behaviour is invoked.
41 /// </summary> 50 /// </summary>
42 /// <param name="bot"></param> 51 /// <param name="bot"></param>
43 void Action(Bot bot); 52 void Action();
44 } 53 }
45} \ No newline at end of file 54} \ No newline at end of file