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 ...
With this code from iAI mod
Peon goes to resource site and just stands there - never starts collecting.
Anyone out there understand better how this should work ?
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 ?
About the author
Long time gamer, hacker and programmer. With dreams of making video games -
#2
Added this to the top of the function and now its working great!
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");
}
Torque Owner Jeff Yaskus
jy games
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."); }