diff --git a/source/enemy/npcpath.cpp b/source/enemy/npcpath.cpp index 8d47f5833..3bdd3091c 100644 --- a/source/enemy/npcpath.cpp +++ b/source/enemy/npcpath.cpp @@ -69,7 +69,7 @@ void CNpcPath::initPath() reversePath = false; minX = maxX = minY = maxY = 0; waypointPtr = NULL; - + decLockout = false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -77,6 +77,7 @@ void CNpcPath::initPath() void CNpcPath::resetPath() { lastWaypoint = currentWaypoint = 0; + decLockout = false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -168,6 +169,8 @@ void CNpcPath::setPathExtents() bool CNpcPath::incPath() { + decLockout = false; + if ( !reversePath ) { if ( currentWaypoint < waypointCount ) @@ -233,18 +236,27 @@ bool CNpcPath::incPath() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void CNpcPath::decPath() +bool CNpcPath::decPath() { - if ( currentWaypoint > 0 ) + if ( !decLockout ) { - lastWaypoint = currentWaypoint; - currentWaypoint--; - } - else - { - lastWaypoint = currentWaypoint; - currentWaypoint = waypointCount; + if ( currentWaypoint > 0 ) + { + lastWaypoint = currentWaypoint; + currentWaypoint--; + } + else + { + lastWaypoint = currentWaypoint; + currentWaypoint = waypointCount; + } + + decLockout = true; + + return( true ); } + + return( false ); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/enemy/npcpath.h b/source/enemy/npcpath.h index caee80c67..45f746308 100644 --- a/source/enemy/npcpath.h +++ b/source/enemy/npcpath.h @@ -30,7 +30,7 @@ public: void setPathType( u8 newPathType ); u8 getPathType(); bool incPath(); - void decPath(); + bool decPath(); void resetPath(); void reversePathDir(); s32 think( DVECTOR const ¤tPos, bool *pathComplete, bool *waypointChange, s32 *distX, s32 *distY ); @@ -55,6 +55,7 @@ private: u8 lastWaypoint; s32 minX, maxX; s32 minY, maxY; + bool decLockout; u16 *waypointPtr; }; diff --git a/source/enemy/nssnake.cpp b/source/enemy/nssnake.cpp index 85a58c960..a84c59b69 100644 --- a/source/enemy/nssnake.cpp +++ b/source/enemy/nssnake.cpp @@ -164,6 +164,8 @@ void CNpcSeaSnakeEnemy::postInit() m_collTimer = 0; m_turnDir = 0; m_waitTimer = 0; + m_collCount = 0; + m_sign = 1; CNpcBossEnemy::postInit(); } @@ -555,20 +557,34 @@ void CNpcSeaSnakeEnemy::processMovement( int _frames ) case COLLISION_TYPE_FLAG_SOLID: { Pos = oldPos; - m_heading += 2048; + + if ( m_collCount > 4 ) + { + m_collCount = 0; + m_sign = -m_sign; + } + else + { + m_collCount++; + } + + m_heading += m_sign * 1024; m_heading &= 4095; - m_npcPath.decPath(); + bool dec = m_npcPath.decPath(); - DVECTOR waypointPos; - m_npcPath.getCurrentWaypointPos( &waypointPos ); - waypointPos.vy -= 8; - - if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 ) + if ( dec ) { - // one of the special 'teleport' waypoints + DVECTOR waypointPos; + m_npcPath.getCurrentWaypointPos( &waypointPos ); + waypointPos.vy -= 8; - m_npcPath.incPath(); + if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 ) + { + // one of the special 'teleport' waypoints + + m_npcPath.incPath(); + } } break; @@ -892,20 +908,34 @@ void CNpcSeaSnakeEnemy::processClose( int _frames ) m_sensorFunc = NPC_SENSOR_NONE; Pos = oldPos; - m_heading += 2048; + + if ( m_collCount > 4 ) + { + m_collCount = 0; + m_sign = -m_sign; + } + else + { + m_collCount++; + } + + m_heading += m_sign * 1024; m_heading &= 4095; - m_npcPath.decPath(); + bool dec = m_npcPath.decPath(); - DVECTOR waypointPos; - m_npcPath.getCurrentWaypointPos( &waypointPos ); - waypointPos.vy -= 8; - - if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 ) + if ( dec ) { - // one of the special 'teleport' waypoints + DVECTOR waypointPos; + m_npcPath.getCurrentWaypointPos( &waypointPos ); + waypointPos.vy -= 8; - m_npcPath.incPath(); + if ( CGameScene::getCollision()->getHeightFromGround( waypointPos.vx, waypointPos.vy ) < 0 ) + { + // one of the special 'teleport' waypoints + + m_npcPath.incPath(); + } } break; diff --git a/source/enemy/nssnake.h b/source/enemy/nssnake.h index 10153fc2c..bc1cfe13d 100644 --- a/source/enemy/nssnake.h +++ b/source/enemy/nssnake.h @@ -112,6 +112,8 @@ protected: s16 m_circleHeading; s16 m_origHeading; s32 m_waitTimer; + u8 m_collCount; + s8 m_sign; }; #endif \ No newline at end of file