Monday, 30 May 2011

Update

So I got the NPC code up to the point where it can follow you pretty successfully and then kill you. Additionally I wrote a piece of code that reads a ZHAO II formatted notecard out of the template avatar's inventory and uses the UUIDs it finds there for such animations as MeleeAttack, ProjectileAttack, Die etc etc. That way it makes it much easier for someone inworld to customize the appearance and animation behavior of NPCs without the need to get access to the code-base. It just makes things easier, really.

Anyways, then...Revolution Smythe who is a complete and total genius, extended Christy's Astar pathfinding code so that the follow code is better, the NPCs can follow you up stairs, round walls, over walls, fly after you etc etc.

Outstanding are getting the avatars to die (right now they won't die and mercilessly kill you over and over lol) and also some client side weapons/gun scripts.

The piece I'm working on currently is trying to get the avatars to play a "dying" animation once their health points go to zero or below. It's not working yet and it's been especially entertaining trying to get a chance to run a "kill" script while being relentlessly pursued by NPCs intent on your gory death. Fun times were had by all LOL.

Also: I borked my branch on github somehow when I tried to merge the code from the main branch over the weekend. Not being a github expert I don't know how to clean it up and it's just a big hassle really so I took the easy way out and just created a new repository with just the NPC project (i.e. aurora/botmanager). Since my code should just be a drag and drop replacement for the aurora/botmanager in the main branch that should make things much easier. Especially for those who have been unable to get my branch to compile (nod of the head to Enrico).

Saturday, 28 May 2011

How to add 32 bit launcher into the project

If you get a fresh virgin copy of aurora from the github master branch it will compile just fine in VS2008 but depending on the machine you have it might not run. This is the case on my machine so I spoke to Rev and he said I need to add the 32 bit launcher to be able to debug it in vs2008.
So on the right hand side in the solution explorer panel, right click on "solution 'Aurora'" right at the top and choose "add reference" then go looking for OpenSim/Tools/32bitlauncher and find the project.

You might also have problems with SmarthThreadPool, which is found in openSim/tools/smartthreadpool.

Tuesday, 10 May 2011

k so proof of concept of killer NPC attack bot

After struggling with the animation code and non-active damage code I eventually code a proof of concept attack bot to work.

It's hard-coded at the minute and basically what it does is it follows the prey avatar and when it gets close enough if it's in attack mode (which it is) it proceeds to play the hardcoded attack animation. It also reduces the prey avatar's health points by 10 each time until the prey avatar's health points reach zero. It will continue to dog the avatar even if the avatar moves away until it kills them. At the point at which it kills them the predator NPC goes out of attack mode and just sits there.

Obviously some more complicated AI would be good. For example, it would be good if an idle bot also attacked. So maybe what needs to happen is that the sensor prim makes all not attacking bots attack the nearest avatar. Anyways, the proof of concept works so now I need to think about how to improve on it and especially remove the hardcoded animations to make it easier for others. Probably the next step is to get it to be able to use ZHAO cards or a modified version for attacking animations et cetera.

Anyways the code is here:
https://github.com/x8ball/Aurora-Sim/commit/4d9ef599515a770be20602c934854ad51d9309ed#diff-1

Wednesday, 4 May 2011

Server side AO on the bot

Additionally on the to-do list is a server side AO for the bot using a standard ZHAO notecard.
The plan is to create a fixed directory called aurora/bin/ao whereby each bot's AO animation list will be inside a notecard formatted in standard ZHAO format and called the name of the seeding avie used to seed the bot. i.e. a bot called "test bot" seeded from avie John Doe would have a notecard called JohnDoe.txt (for example) inside aurora/bin/ao.

This code is lower down the priority list in the to-do's but it's in there. Before I do this I'm going to finish the detect-spawn-follow-attack code which will also involve digging into the LSL collision or sensor stuff. The scripting engine seems to be a little flaky in that scripts sometimes don't work (I tried the collision code last night and it didn't work very well so as a backup I could write something into the botmanager code but I digress).

So returning to the Server side AO, we will need code to pick up directories and code to read files etc. Clues to that code should be in the following code snippet:

private void FindDefaultLSLScript()
{
if (!Directory.Exists(ScriptEnginesPath))
{
try
{
Directory.CreateDirectory(ScriptEnginesPath);
}
catch (Exception)
{
}
}
string Dir = Path.Combine(Path.Combine(Environment.CurrentDirectory, ScriptEnginesPath), "default.lsl");
if (File.Exists(Dir))
{
string defaultScript = File.ReadAllText(Dir);
foreach (Scene scene in m_Scenes)
{
ILLClientInventory inventoryModule = scene.RequestModuleInterface();
if (inventoryModule != null)
inventoryModule.DefaultLSLScript = defaultScript;
}
}
}

Working on the detect-spawn-follow-attack code

So what I'm working on (loosely) at the moment is basically a detect-spawn-and-attack method a la left 4 dead or else call of duty. So basically an avie walks close to a spawning point, the spawning region detects the avie's presence, spawns a bot, sets the bot to follow the avie and sets the bots belligerence level to "hostile".

Then the bot will follow the avie till it gets close enough and then it will attack which means run the appropriate attack anim and then call the code to do damage to the avie.

Rather than do all of this code myself I can piggyback on the existing follow code and at the same time change the belligerence state to hostile. Then I can mod the code that stops the avie from walking when it's close enough (in the follow code) to instead check to see the attack state and take appropriate action instead.

So here's the follow code in rexbot.cs with the appropriate places to mod commented:

//this is the follow code
CurrentFollowTimeBeforeUpdate++;
if (CurrentFollowTimeBeforeUpdate == FollowTimeBeforeUpdate)
{
Vector3 diffAbsPos = FollowSP.AbsolutePosition - m_scenePresence.AbsolutePosition;
if (Math.Abs (diffAbsPos.X) > m_closeToPoint || Math.Abs (diffAbsPos.Y) > m_closeToPoint)
{
NavMesh mesh = new NavMesh ();

bool fly = FollowSP.PhysicsActor == null ? ShouldFly : FollowSP.PhysicsActor.Flying;
mesh.AddEdge (0, 1, fly ? TravelMode.Fly : TravelMode.Walk);
mesh.AddNode (m_scenePresence.AbsolutePosition); //Give it the current pos so that it will know where to start

mesh.AddEdge (1, 2, fly ? TravelMode.Fly : TravelMode.Walk);
mesh.AddNode (FollowSP.AbsolutePosition); //Give it the new point so that it will head toward it
SetPath (mesh, 0, false, 10000, false); //Set and go
}
else //distance is less than the follow range.
//in here (the else block) we need to check if we are to attack

//(if the bot is hostile we attack
//otherwise we just stop the bot
{
//if the bot is hostile we attack
//attack code goes here
//else
//Stop the bot then
State = RexBotState.Idle;
m_walkTime.Stop ();
m_startTime.Stop ();
}
//Reset the time
CurrentFollowTimeBeforeUpdate = -1;
}