Game Development Community

Plan for Mark Storer

by Mark Storer · 06/09/2005 (10:00 am) · 4 comments

As I mentioned in my last plan, I actually went through AIPlayer.cs to figure out what the heck was going wrong with my bots.

What I wanted: Spawn a bot at each node in the path, have them follow the path from that point.

What I had: Spawned the bots just fine, but then they all went to node 0 before following the path. Goofy.

It turns out that there's a small bug in followPath:

function AIPlayer::followPath(%this,%path,%node)
{
   // Start the player following a path
   %this.stopThread(0);
   if (!isObject(%path)) {
      %this.path = "";
      return;
   }
   if (%node > %path.getCount() - 1)
      %this.targetNode = %path.getCount() - 1;
   else
      %this.targetNode = %node;
   if (%this.path $= %path)
      %this.moveToNode(%this.currentNode);   //  <-- refered before being set
   else {
      %this.path = %path;
      %this.moveToNode(0);
   }
}

FollowPath uses %this.currentNode before it has a value... so everyone went to node zero. Further, if %this doesn't have a path yet, you're sent to node zero. So the first time you call followPath (no .path, no .currentNode), the %node parameter is useless. Bah humbug. So rather than fixing the problem at its origin (boo hiss):

A bit of hackery in AIManager::spawn set things straight:
function AIManager::spawn(%this, %num)
{
   %spawnName = "Kork" @ %num;
   echo( %spawnName );
   %pathName = "MissionGroup/Paths/Path1";
   %nodeNum = %num % 5;
   %player = AIPlayer::spawnOnPath(%spawnName, %pathName, %num % 5);
   %player.path = %pathName;
   %player.currentNode = %nodeNum;
   %player.targetNode = (%nodeNum < 4) ? %nodeNum + 1 : 0;
   %player.followPath(%pathName, -1);

   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   
   %this.player[%num] = %player;
}

So I too can write bad code that works anyway. Yay me. Ideally, this would all be taken care of in followPath, without all the hard-coded numbers (%nodeNum = %num % %path.getCount()).

I'll clean it up at some point in the future. (Yeah right)

#1
06/09/2005 (11:11 am)
glad you got it working
#2
06/09/2005 (1:03 pm)
Congrats on figuring it out Mark.
#3
06/09/2005 (1:04 pm)
I messed with it more this morning a bit before going to work, but never "compiled" it much less tested it. I'll post the new-n-improved version tonight... Much Later tonight. I've only just arrived here at work, so it looks like I'll be leaving around 8 or 9pm. Whee.

My goal is to have followPath( path, node ) order the AIPlayer to start following "path" starting at "node". The script I had last night does that, but that logic should be contained entirely within "followPath".

Am I missing something, or is the original followPath()'s %node parameter completely useless?
#4
06/09/2005 (6:08 pm)
Good Stuff!!