diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 2158d9c50..77d1ba0f4 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -1,3 +1,16 @@ +/*========================================================================= + + npc.cpp + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + #include "enemy\npc.h" #ifndef __LEVEL_LEVEL_H__ @@ -190,7 +203,7 @@ void CNpc::processEvent( GAME_EVENT evt, CThing *sourceThing ) if ( m_data[this->m_type].canTalk ) { DVECTOR sourcePos; - int xDiffSqr, yDiffSqr; + s32 xDiffSqr, yDiffSqr; // check talk distance diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 0eef84b62..e57080085 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -1,3 +1,15 @@ +/*========================================================================= + + npc.h + + Author: CRB + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ #ifndef __NPC_H__ #define __NPC_H__ diff --git a/source/enemy/npcpath.cpp b/source/enemy/npcpath.cpp index b93903da1..68d64890f 100644 --- a/source/enemy/npcpath.cpp +++ b/source/enemy/npcpath.cpp @@ -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 \ No newline at end of file +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(); + } +} \ No newline at end of file diff --git a/source/enemy/npcpath.h b/source/enemy/npcpath.h index 08ac5ccf2..ce1390368 100644 --- a/source/enemy/npcpath.h +++ b/source/enemy/npcpath.h @@ -11,6 +11,9 @@ ===========================================================================*/ +#ifndef __ENEMY_NCPPATH_H__ +#define __ENEMY_NCPPATH_H__ + class CNpcWaypoint { public: @@ -38,9 +41,14 @@ private: NPC_PATH_TYPE pathType; u8 currentWaypoint; u8 waypointCount; + bool reversePath; public: + void initPath(); void addWaypoint( DVECTOR newPos ); void setPathType( NPC_PATH_TYPE newPathType ); bool incPath(); -}; \ No newline at end of file + void think( DVECTOR currentPos ); +}; + +#endif \ No newline at end of file diff --git a/users/paul/spongebob project/spongebob project.dsp b/users/paul/spongebob project/spongebob project.dsp index 8aa2c2cb0..ee2d0b3a2 100644 --- a/users/paul/spongebob project/spongebob project.dsp +++ b/users/paul/spongebob project/spongebob project.dsp @@ -131,6 +131,14 @@ SOURCE=..\..\..\source\enemy\npc.cpp SOURCE=..\..\..\source\enemy\npc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\source\enemy\npcpath.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\source\enemy\npcpath.h +# End Source File # End Group # Begin Group "fileio"