Game Development Community

Merging RTS Kit + immersive AI mod + World Dom mod -- works except peons wont collect (fixed)

by Jeff Yaskus · in RTS Starter Kit · 02/17/2010 (1:03 am) · 2 replies

Having trouble merging the RTS Kit + iAI + World Dom mod code into one ... the player.cs to be specific.

This is the function from World Dom mod ...
function Player::onReachDestination(%this, %dest)
{
   if(%this.status $= "Collecting" && %this.curGoal $= "")
   {

    //%this.setActionThread("gather", true);
echo("Player::onReachDestination--(" @ %this @ ") is currently collecting.");    
     %this.collectResource(%this.collecting, 2000);
   }
   if(%this.status $= "Full" && %this.curGoal $= "")
   {
    //Gold.count +=  %this.currentAmt;
    echo("Player::onReachDestination-- (" @ %this @ ") is dropping off (" @ %this.resourceType @ ")");
    resourceStore::requestAddSupplies(%this.client, "LOCAL", "", %this.resourceType SPC %this.currentAmt, false);
    //resourceStore::SetSupply(%this.client, );
    %this.currentAmt = "";
    if (!(%this.resourcePos $= "" ) )
    {
      %this.setMoveDestination(%this.resourcePos);
      %this.curGoal = %this.resourcePos;
      %this.status = "Collecting";
      echo("Player::onReachDestination-- (" @ %this @ ") now moving to (" @ %this.resourcePos @ ")");

      return;
    }
    else
    {
      echo("Player::onReachDestination--peon caught trying to harvest at a spot that doesn't exist!");
      %this.setMoveGoal("");
      %this.status = "Idle";
      return;
    }
   }

   if(%this.curGoal $= "")
   {
      echo(%this @ " - Arrived!");
      return;
   }

   %nextWP = PathManager::getNextWaypoint(%this.getPosition(), %this.curGoal);
   
   %this.setMoveDestination(%nextWP);
   
   if(VectorDist(%nextWP, %this.curGoal) > 0.01)
   {
      echo(%this @ " - waypoint = " @ %nextWP);
   }
   else
   {
      %this.curGoal = "";
   }   
}

With this code from iAI mod
function Player::onReachDestination(%this, %dest)
{
   if(%this.curGoal $= "")
   {
      echo(%this @ " - Arrived!");
      return;
   }

   %nextWP = PathManager::getNextWaypoint(%this); //%this.getPosition(), %this.curGoal);
   
   if (%nextWP != -1)
	{
		%this.setMoveDestination(%nextWP);
		echo(%this @ " - waypoint = " @ %nextWP);
	}
   
//   if(VectorDist(%nextWP, %this.curGoal) > 0.01)
//   {
//      echo(%this @ " - waypoint = " @ %nextWP);
//   }
//   else
//   {
//      %this.curGoal = "";
//   }
}


Peon goes to resource site and just stands there - never starts collecting.

Anyone out there understand better how this should work ?

#1
02/17/2010 (6:01 pm)
It looks like the setMoveGoal changes are causing this behavior ... I've been comparing the before/after scripts for differences.

For some odd reason with the iAI code --- it generates the Path and units starts moving, but it never completes the rest of the function. So the echo statement I added doesn't even get called ...
function Player::setMoveGoal(%this, %dest)
{
	if (%this.generatePath(%dest))
	{
		%this.curGoal = %dest;
		// Kick off the movement.
		%this.onReachDestination(%this.getPosition());
      echo("Player::setMoveGoal--object (" @ %this @ ") now moving to (" @ %this.curGoal @ ")");      
	}
	else
		echo("Player::setMoveGoal - Path to" SPC %dest SPC "cannot be found.");
}
#2
02/17/2010 (7:04 pm)
Fixed it!! The iAI code acts a bit differently, so the old method of checking for curGoal="" isnt working.

Added this to the top of the function and now its working great!
%distance = VectorDist(%this.getPosition(), %this.curGoal);

   if ((%distance < 4.0) && (%distance > -4.0) && (!(%this.curGoal $= "")))
   {
      %this.curGoal = "";
      echo("Player::onReachDestination distance is less than 4.0 to current goal");
   }