void ki_go_to(ENTITY* goto_ent,target_x,target_y,target_z)
{
var ValidPosition=IS_TRUE;
var FoundPath=IS_FALSE;
var MyOriginHeight;
var HitVerticalWall=IS_FALSE;
VECTOR temp;
VECTOR is_temp2;
//Kill previous Red lines
ixT_particle_DestroyLines(IS_NOCOLOUR);
//Find the origint point of the Agent
goto_ent = id_to_ptr(1);
MyOriginHeight = goto_ent.min_z*(-1);
TargetPosX = target_x;
TargetPosY = target_y;
TargetPosZ = target_z;
int i,j;
for (i=1;i<=entity_count;i++)
{
my=id_to_ptr(i);
if (my==you)
{
for (j=1;j<=entity_count;j++)
{
my=id_to_ptr(j);
}
vec_set(Debug_tp.x,vector(0,0,-1000));
return;
}
}
//Wait for the previous action to finish
wait(1);
//If Nothing is hit mark position as invalid
if (!trace_hit) {ValidPosition=IS_FALSE;}
//If position found is inside solid block, mark it as invalid
if (c_content(vector(target.x,target.y,target.z+20),0)==3) {ValidPosition=IS_FALSE; HitVerticalWall=IS_TRUE;}
//Figure out of position is in the air due to player clicking on a steep vertical surface
if (ValidPosition)
{
//Downwards trace to check if position is hovering on air
c_trace(vector(target.x,target.y,target.z+20),vector(target.x,target.y,target.z-MyOriginHeight),IGNORE_PASSABLE+IGNORE_PASSENTS);
//If Nothing is hit on the downwards trace, mark position as invalid
if (!trace_hit) {ValidPosition=IS_FALSE; HitVerticalWall=IS_TRUE;}
}
//If the position found is on a vertical wall, attempt to find a valid position nearby
if (HitVerticalWall)
{
//Find a new Offset Target Position, a little further away from the vertical wall
is_CalculateMidPoint(camera.x,vector(TargetPosX,TargetPosY,TargetPosZ+20),vec_dist(camera.x,vector(TargetPosX,TargetPosY,TargetPosZ+20))-is_ai_WallOffset,OffsetTargetPos);
//Save the result as the new Target Position
TargetPosX=OffsetTargetPos.x;
TargetPosY=OffsetTargetPos.y;
TargetPosZ=OffsetTargetPos.z;
//Make the Position Valid Again
ValidPosition=IS_TRUE;
HitVerticalWall=IS_FALSE;
}
if (ValidPosition)
{
//Clamp target position to the ground
ClampPosition(vector(TargetPosX,TargetPosY,TargetPosZ+20),MyOriginHeight,is_temp2);
//Save the result as the final Target Position
TargetPosX=is_temp2.x;
TargetPosY=is_temp2.y;
TargetPosZ=is_temp2.z;
for (i=1;i<=entity_count;i++)
{
goto_ent=id_to_ptr(i);
if (goto_ent)
{
my = goto_ent;
FoundPath=is_Action_Move_To(TargetPosX,TargetPosY,TargetPosZ,goto_ent);
}
}
}
//Color the X model green if Path was found, or red otherwise
/*if (FoundPath)
{
if (goto_ent)
Debug_tp.skin=IS_GREEN;
}
else
{
if (goto_ent)
Debug_tp.skin=IS_RED;
}*/
//Set the position of the X model to the Position the Npc is commanded to go to
//vec_set(Debug_tp.x,vector(TargetPosX,TargetPosY,TargetPosZ));
vec_set(Debug_tp.x,vector(TargetPosX,TargetPosY,TargetPosZ));
}