aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/Bot.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-09-03 18:51:55 +0100
committerJustin Clark-Casey (justincc)2013-09-03 18:51:55 +0100
commit9bd62715704685738c55c6de8127b16cc6695bdb (patch)
tree2e05a893e763f9d02484f341d50f023d738a43f5 /OpenSim/Tools/pCampBot/Bot.cs
parentAnd fix break in "show bot" from commit 9c65207 (diff)
downloadopensim-SC-9bd62715704685738c55c6de8127b16cc6695bdb.zip
opensim-SC-9bd62715704685738c55c6de8127b16cc6695bdb.tar.gz
opensim-SC-9bd62715704685738c55c6de8127b16cc6695bdb.tar.bz2
opensim-SC-9bd62715704685738c55c6de8127b16cc6695bdb.tar.xz
Add ability to adjust pCampbot bot behaviours whilst running with "add behaviour <behaviour-name> <bot-number>" console commad
Diffstat (limited to '')
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs51
1 files changed, 37 insertions, 14 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index d418288..6037516 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -72,9 +72,10 @@ namespace pCampBot
72 /// Behaviours implemented by this bot. 72 /// Behaviours implemented by this bot.
73 /// </summary> 73 /// </summary>
74 /// <remarks> 74 /// <remarks>
75 /// Lock this list before manipulating it. 75 /// Indexed by abbreviated name. There can only be one instance of a particular behaviour.
76 /// Lock this structure before manipulating it.
76 /// </remarks> 77 /// </remarks>
77 public List<IBehaviour> Behaviours { get; private set; } 78 public Dictionary<string, IBehaviour> Behaviours { get; private set; }
78 79
79 /// <summary> 80 /// <summary>
80 /// Objects that the bot has discovered. 81 /// Objects that the bot has discovered.
@@ -165,8 +166,6 @@ namespace pCampBot
165 { 166 {
166 ConnectionState = ConnectionState.Disconnected; 167 ConnectionState = ConnectionState.Disconnected;
167 168
168 behaviours.ForEach(b => b.Initialize(this));
169
170 Random = new Random(Environment.TickCount);// We do stuff randomly here 169 Random = new Random(Environment.TickCount);// We do stuff randomly here
171 FirstName = firstName; 170 FirstName = firstName;
172 LastName = lastName; 171 LastName = lastName;
@@ -176,12 +175,31 @@ namespace pCampBot
176 StartLocation = startLocation; 175 StartLocation = startLocation;
177 176
178 Manager = bm; 177 Manager = bm;
179 Behaviours = behaviours; 178
179 Behaviours = new Dictionary<string, IBehaviour>();
180 foreach (IBehaviour behaviour in behaviours)
181 AddBehaviour(behaviour);
180 182
181 // Only calling for use as a template. 183 // Only calling for use as a template.
182 CreateLibOmvClient(); 184 CreateLibOmvClient();
183 } 185 }
184 186
187 public bool AddBehaviour(IBehaviour behaviour)
188 {
189 lock (Behaviours)
190 {
191 if (!Behaviours.ContainsKey(behaviour.AbbreviatedName))
192 {
193 behaviour.Initialize(this);
194 Behaviours.Add(behaviour.AbbreviatedName, behaviour);
195
196 return true;
197 }
198 }
199
200 return false;
201 }
202
185 private void CreateLibOmvClient() 203 private void CreateLibOmvClient()
186 { 204 {
187 GridClient newClient = new GridClient(); 205 GridClient newClient = new GridClient();
@@ -237,16 +255,21 @@ namespace pCampBot
237 private void Action() 255 private void Action()
238 { 256 {
239 while (ConnectionState != ConnectionState.Disconnecting) 257 while (ConnectionState != ConnectionState.Disconnecting)
258 {
240 lock (Behaviours) 259 lock (Behaviours)
241 Behaviours.ForEach( 260 {
242 b => 261 foreach (IBehaviour behaviour in Behaviours.Values)
243 { 262 {
244 Thread.Sleep(Random.Next(3000, 10000)); 263 Thread.Sleep(Random.Next(3000, 10000));
245 264
246 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); 265 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
247 b.Action(); 266 behaviour.Action();
248 } 267 }
249 ); 268 }
269
270 // XXX: This is a really shitty way of yielding so that behaviours can be added/removed
271 Thread.Sleep(100);
272 }
250 } 273 }
251 274
252 /// <summary> 275 /// <summary>