This commit is contained in:
parent
dc9561dc93
commit
c33e2a4acd
5 changed files with 131 additions and 5 deletions
|
@ -11,6 +11,10 @@
|
|||
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef __ENEMY_NCPPATH_H__
|
||||
#include "enemy\ncppath.h"
|
||||
#endif
|
||||
|
||||
bool CNpcWaypoint::isPointNear( DVECTOR testPos )
|
||||
{
|
||||
s32 xDistSqr, yDistSqr;
|
||||
|
@ -31,6 +35,22 @@ bool CNpcWaypoint::isPointNear( DVECTOR testPos )
|
|||
}
|
||||
}
|
||||
|
||||
void CNpcPath::initPath()
|
||||
{
|
||||
int loop;
|
||||
|
||||
for ( loop = 0 ; loop < NPC_MAX_WAYPOINTS ; loop++ )
|
||||
{
|
||||
waypoint[loop].pos.vx = 0;
|
||||
waypoint[loop].pox.vy = 0;
|
||||
}
|
||||
|
||||
pathType = SINGLE_USE_PATH;
|
||||
currentWaypoint = 0;
|
||||
waypointCount = 0;
|
||||
reversePath = false;
|
||||
}
|
||||
|
||||
void CNpcPath::addWaypoint( DVECTOR newPos )
|
||||
{
|
||||
if ( waypointCount < NPC_MAX_WAYPOINTS )
|
||||
|
@ -40,6 +60,71 @@ void CNpcPath::addWaypoint( DVECTOR newPos )
|
|||
}
|
||||
}
|
||||
|
||||
void setPathType( NPC_PATH_TYPE newPathType );
|
||||
bool incPath();
|
||||
bool CNpcPath::incPath
|
||||
void CNpcPath::setPathType( NPC_PATH_TYPE newPathType )
|
||||
{
|
||||
pathType = newPathType;
|
||||
}
|
||||
|
||||
bool CNpcPath::incPath()
|
||||
{
|
||||
if ( !reversePath )
|
||||
{
|
||||
if ( currentWaypoint < waypointCount )
|
||||
{
|
||||
currentWaypoint++;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( pathType )
|
||||
{
|
||||
case SINGLE_USE_PATH:
|
||||
// path is completed
|
||||
|
||||
return( true );
|
||||
|
||||
case REPEATING_PATH:
|
||||
// go back to start
|
||||
|
||||
currentWaypoint = 0;
|
||||
|
||||
break;
|
||||
|
||||
case PONG_PATH:
|
||||
// reverse path
|
||||
|
||||
reversePath = !reversePath;
|
||||
currentWaypoint--;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// must be pong path if reversed
|
||||
|
||||
if ( currentWaypoint > 0 )
|
||||
{
|
||||
currentWaypoint--;
|
||||
}
|
||||
else
|
||||
{
|
||||
reversePath = !reversePath;
|
||||
currentWaypoint++;
|
||||
}
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
void CNpcPath::think( DVECTOR currentPos )
|
||||
{
|
||||
CNpcWaypoint *currentWaypoint;
|
||||
|
||||
currentWaypoint = &waypoint[currentWaypoint]
|
||||
|
||||
if ( currentWaypoint->isPointNear( currentPos ) )
|
||||
{
|
||||
incPath();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue