This is a modified version of the NearestPoint command. The command search t the area specified by the Minimum and Maximum distance for a valid ScriptPoint, but chooses only a scriptpoint that starts with the word specified in an additional parameter.
Example:
Code: Select all
if(NearestPoint(0, 500, "PWAY"))
{
ideal_yaw=GetYawToPoint();
ChangeYaw();
}
Code: Select all
case 183: // NearestPoint(float MinDistance, float MaxDistance)
// NearestPoint(float MinDistance, float MaxDistance, char *PointName)
{
PARMCHECK(2);
returnValue = false;
//if(!TargetActor)
// return true;
geEntity_EntitySet *pSet;
geEntity *pEntity;
// Ok, check to see if there are ScriptPoints in this world
pSet = geWorld_GetEntitySet(CCD->World(), "ScriptPoint");
if(!pSet)
return true;
geVec3d Pos, Dist;//TargetPos,
float minDist2, MinDistance2, MaxDistance2;//minTargetDist2,
float newDist2;//, newTargetDist2;
MinDistance2 = arguments[0].floatValue()*arguments[0].floatValue();
MaxDistance2 = arguments[1].floatValue()*arguments[1].floatValue();
minDist2 = MaxDistance2;
//minTargetDist2 = minDist2*10000.f;
CCD->ActorManager()->GetPosition(Actor, &Pos);
//CCD->ActorManager()->GetPosition(TargetActor, &TargetPos);
// Ok, we have ScriptPoints somewhere. Dig through 'em all.
for(pEntity=geEntity_EntitySetGetNextEntity(pSet, NULL); pEntity;
pEntity=geEntity_EntitySetGetNextEntity(pSet, pEntity))
{
ScriptPoint *pSource = (ScriptPoint*)geEntity_GetUserData(pEntity);
if(arguments.entries() < 3)
{
//calc new dist
geVec3d_Subtract(&pSource->origin, &Pos, &Dist);
newDist2 = geVec3d_LengthSquared(&Dist);
//geVec3d_Subtract(&pSource->origin, &TargetPos, &Dist);
//newTargetDist2 = geVec3d_LengthSquared(&Dist);
// point is too close
if(newDist2<MinDistance2 || newDist2>MaxDistance2)
continue;
if(newDist2<minDist2)// && newTargetDist2<=minTargetDist2)
{
// probably slowest test...
if(CCD->Pawns()->CanSeePoint(FOV, Actor, &(pSource->origin), FOVBone))
{
minDist2 = newDist2;
//minTargetDist2 = newTargetDist2;
strcpy(Point, pSource->szEntityName);
CurrentPoint= pSource->origin;
ValidPoint = true;
returnValue = true;
}
}
}
else
{
strcpy(param0, arguments[2].str());
int StrLength = (int)strlen(param0);
char str2[64];
strncpy (str2,pSource->szEntityName,StrLength);
str2[StrLength]='\0';
if(!stricmp(param0, str2))
{
//calc new dist
geVec3d_Subtract(&pSource->origin, &Pos, &Dist);
newDist2 = geVec3d_LengthSquared(&Dist);
//geVec3d_Subtract(&pSource->origin, &TargetPos, &Dist);
//newTargetDist2 = geVec3d_LengthSquared(&Dist);
// point is too close
if(newDist2<MinDistance2 || newDist2>MaxDistance2)
continue;
if(newDist2<minDist2)// && newTargetDist2<=minTargetDist2)
{
// probably slowest test...
//if(CCD->Pawns()->CanSeePoint(FOV, Actor, &(pSource->origin), FOVBone))
//{
minDist2 = newDist2;
//minTargetDist2 = newTargetDist2;
strcpy(Point, pSource->szEntityName);
CurrentPoint= pSource->origin;
ValidPoint = true;
returnValue = true;
//}
}
}
else
{
continue;
}
}
}
return true;
}
1.diversify the pawn's actions and paths. When the character is angry or he's attacking or is taking cover he can choose a different path.
2.This command can provide a basic pathfinding method. I have different rooms with a door in each one. My pawn is free searching the rooms for the player. When he reachs the bottom wall (where the door is) of every room, I trigger him to search for a script point (I use an hint brush flagged as 'Lava'). I placed a Point named "PWAY...." in every door passage. So the pawn heads to the door and goes in the other room. The same scriptpoint can be used also in the other direction (to return back from the other room) and I can find the door passage just when I need it, also if the pawn is nearer ro other useless scriptpoints.
I hope this could help.