From dcb2f87af03acd8f1e17f7014ddc1ebc20cc6a8e Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 26 Jan 2001 15:16:07 +0000 Subject: [PATCH] --- source/enemy/npc.cpp | 11 ++-- source/enemy/npcpath.cpp | 105 +++++++++++++++++++++++++++++++-------- source/enemy/npcpath.h | 14 +++--- source/enemy/nsstomp.cpp | 93 ++++++++++++++++------------------ 4 files changed, 140 insertions(+), 83 deletions(-) diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index c657a47c5..c7b0e8266 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -435,7 +435,7 @@ CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] = void CNpc::init() { - m_type = NPC_IRON_DOGFISH; + m_type = NPC_SKULL_STOMPER; m_heading = m_fireHeading = 0; m_movementTimer = 0; @@ -471,7 +471,7 @@ void CNpc::init() m_npcPath.addWaypoint( newPos ); - /*newPos.vx = 500; + newPos.vx = 500; newPos.vy = 100; m_npcPath.addWaypoint( newPos ); @@ -479,9 +479,9 @@ void CNpc::init() newPos.vx = 100; newPos.vy = 100; - m_npcPath.addWaypoint( newPos );*/ + m_npcPath.addWaypoint( newPos ); - m_npcPath.setPathType( REPEATING_PATH ); + m_npcPath.setPathType( PONG_PATH ); break; } @@ -554,6 +554,7 @@ void CNpc::init() void CNpc::shutdown() { + m_npcPath.removeAllWaypoints(); } @@ -832,7 +833,7 @@ bool CNpc::processSensor() if ( xDistSqr + yDistSqr < 40000 ) { m_controlFunc = NPC_CONTROL_CLOSE; - m_npcPath.currentWaypoint = 0; + m_extendDir = EXTEND_DOWN; return( true ); } diff --git a/source/enemy/npcpath.cpp b/source/enemy/npcpath.cpp index c744b4cd6..342bb7d2f 100644 --- a/source/enemy/npcpath.cpp +++ b/source/enemy/npcpath.cpp @@ -37,27 +37,72 @@ bool CNpcWaypoint::isPointNear( DVECTOR testPos, s32 *xDist, s32 *yDist ) void CNpcPath::initPath() { - int loop; - - for ( loop = 0 ; loop < NPC_MAX_WAYPOINTS ; loop++ ) - { - waypoint[loop].pos.vx = 0; - waypoint[loop].pos.vy = 0; - } - + waypoint = NULL; pathType = SINGLE_USE_PATH; - currentWaypoint = lastWaypoint = 0; + currentWaypoint = NULL; waypointCount = 0; reversePath = false; } +void CNpcPath::resetPath() +{ + currentWaypoint = NULL; +} + void CNpcPath::addWaypoint( DVECTOR newPos ) { - if ( waypointCount < NPC_MAX_WAYPOINTS ) + CNpcWaypoint *testWaypoint; + CNpcWaypoint *newWaypoint; + + testWaypoint = this->waypoint; + + if ( testWaypoint ) { - waypoint[waypointCount].pos = newPos; + // find end of path + + while ( testWaypoint->nextWaypoint ) + { + testWaypoint = testWaypoint->nextWaypoint; + } + + newWaypoint = new( "waypoint" ) CNpcWaypoint; + newWaypoint->pos = newPos; + newWaypoint->nextWaypoint = NULL; + newWaypoint->prevWaypoint = testWaypoint; + + testWaypoint->nextWaypoint = newWaypoint; waypointCount++; } + else + { + // no waypoints exist in this path, create + + newWaypoint = new( "waypoint" ) CNpcWaypoint; + newWaypoint->pos = newPos; + newWaypoint->nextWaypoint = NULL; + newWaypoint->prevWaypoint = NULL; + + this->waypoint = newWaypoint; + waypointCount++; + } +} + +void CNpcPath::removeAllWaypoints() +{ + CNpcWaypoint *testWaypoint; + CNpcWaypoint *lastWaypoint; + + testWaypoint = this->waypoint; + + while ( testWaypoint ) + { + lastWaypoint = testWaypoint; + testWaypoint = testWaypoint->nextWaypoint; + + delete lastWaypoint; + } + + this->waypoint = NULL; } void CNpcPath::setPathType( NPC_PATH_TYPE newPathType ) @@ -69,9 +114,9 @@ bool CNpcPath::incPath() { if ( !reversePath ) { - if ( currentWaypoint < waypointCount - 1 ) + if ( currentWaypoint->nextWaypoint ) { - currentWaypoint++; + currentWaypoint = currentWaypoint->nextWaypoint; } else { @@ -85,7 +130,7 @@ bool CNpcPath::incPath() case REPEATING_PATH: // go back to start - currentWaypoint = 0; + currentWaypoint = this->waypoint; break; @@ -93,7 +138,11 @@ bool CNpcPath::incPath() // reverse path reversePath = !reversePath; - currentWaypoint--; + + if ( currentWaypoint->prevWaypoint ) + { + currentWaypoint = currentWaypoint->prevWaypoint; + } break; } @@ -103,14 +152,18 @@ bool CNpcPath::incPath() { // must be pong path if reversed - if ( currentWaypoint > 0 ) + if ( currentWaypoint->prevWaypoint ) { - currentWaypoint--; + currentWaypoint = currentWaypoint->prevWaypoint; } else { reversePath = !reversePath; - currentWaypoint++; + + if ( currentWaypoint->nextWaypoint ) + { + currentWaypoint = currentWaypoint->nextWaypoint; + } } } @@ -119,17 +172,29 @@ bool CNpcPath::incPath() bool CNpcPath::getDistToNextWaypoint( DVECTOR currentPos, s32 *distX, s32 *distY ) { - return( waypoint[currentWaypoint].isPointNear( currentPos, distX, distY ) ); + return( currentWaypoint->isPointNear( currentPos, distX, distY ) ); } s32 CNpcPath::think( DVECTOR currentPos, bool *pathComplete, bool *waypointChange ) { + if ( !this->waypoint ) + { + return( 0 ); + } + + if ( !currentWaypoint ) + { + // if no currentWaypoint set, start it off + + currentWaypoint = this->waypoint; + } + s32 xDist, yDist; *pathComplete = false; *waypointChange = false; - if ( waypoint[currentWaypoint].isPointNear( currentPos, &xDist, &yDist ) ) + if ( currentWaypoint->isPointNear( currentPos, &xDist, &yDist ) ) { *pathComplete = incPath(); *waypointChange = true; diff --git a/source/enemy/npcpath.h b/source/enemy/npcpath.h index eba433b60..4c8ff9c55 100644 --- a/source/enemy/npcpath.h +++ b/source/enemy/npcpath.h @@ -20,6 +20,8 @@ class CNpcWaypoint { public: DVECTOR pos; + CNpcWaypoint *nextWaypoint; + CNpcWaypoint *prevWaypoint; bool isPointNear( DVECTOR testPos, s32 *xDist, s32 *yDist ); }; @@ -33,25 +35,21 @@ enum NPC_PATH_TYPE class CNpcPath { - enum - { - NPC_MAX_WAYPOINTS = 4, - }; - private: - CNpcWaypoint waypoint[NPC_MAX_WAYPOINTS]; + CNpcWaypoint *waypoint; NPC_PATH_TYPE pathType; u8 waypointCount; - u8 lastWaypoint; bool reversePath; public: - u8 currentWaypoint; + CNpcWaypoint *currentWaypoint; void initPath(); void addWaypoint( DVECTOR newPos ); + void removeAllWaypoints(); void setPathType( NPC_PATH_TYPE newPathType ); bool incPath(); + void resetPath(); s32 think( DVECTOR currentPos, bool *pathComplete, bool *waypointChange ); bool getDistToNextWaypoint( DVECTOR currentPos, s32 *distX, s32 *distY ); }; diff --git a/source/enemy/nsstomp.cpp b/source/enemy/nsstomp.cpp index bb56e7fdd..c93aae9b5 100644 --- a/source/enemy/nsstomp.cpp +++ b/source/enemy/nsstomp.cpp @@ -38,66 +38,59 @@ void CNpc::processCloseSkullStomperAttack( int _frames ) s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange ); s32 moveX, moveY; - if ( waypointChange && !pathComplete ) + if ( waypointChange ) { + if ( !pathComplete ) + { + // pause and change direction + + m_timerTimer = GameState::getOneSecondInFrames(); + m_extendDir = EXTEND_UP; + + return; + } + } + + if ( pathComplete ) + { + m_controlFunc = NPC_CONTROL_MOVEMENT; + m_timerFunc = NPC_TIMER_ATTACK_DONE; m_timerTimer = GameState::getOneSecondInFrames(); + m_sensorFunc = NPC_SENSOR_NONE; + m_npcPath.resetPath(); } else { - if ( pathComplete ) + s32 preShiftX; + s32 preShiftY; + + m_heading = headingToTarget; + + if ( m_extendDir == EXTEND_DOWN ) { - m_controlFunc = NPC_CONTROL_MOVEMENT; - m_timerFunc = NPC_TIMER_ATTACK_DONE; - m_timerTimer = GameState::getOneSecondInFrames(); - m_sensorFunc = NPC_SENSOR_NONE; + preShiftX = _frames * 8 * rcos( m_heading ); + preShiftY = _frames * 8 * rsin( m_heading ); } else { - if ( m_npcPath.currentWaypoint == 0 ) - { - m_heading = headingToTarget; - - s32 preShiftX = _frames * 8 * rcos( m_heading ); - s32 preShiftY = _frames * 8 * rsin( m_heading ); - - moveX = preShiftX >> 12; - if ( !moveX && preShiftX ) - { - moveX = preShiftX / abs( preShiftX ); - } - - moveY = preShiftY >> 12; - if ( !moveY && preShiftY ) - { - moveY = preShiftY / abs( preShiftY ); - } - - Pos.vx += moveX; - Pos.vy += moveY; - } - else - { - m_heading = headingToTarget; - - s32 preShiftX = _frames * 2 * rcos( m_heading ); - s32 preShiftY = _frames * 2 * rsin( m_heading ); - - moveX = preShiftX >> 12; - if ( !moveX && preShiftX ) - { - moveX = preShiftX / abs( preShiftX ); - } - - moveY = preShiftY >> 12; - if ( !moveY && preShiftY ) - { - moveY = preShiftY / abs( preShiftY ); - } - - Pos.vx += moveX; - Pos.vy += moveY; - } + preShiftX = _frames * 2 * rcos( m_heading ); + preShiftY = _frames * 2 * rsin( m_heading ); } + + moveX = preShiftX >> 12; + if ( !moveX && preShiftX ) + { + moveX = preShiftX / abs( preShiftX ); + } + + moveY = preShiftY >> 12; + if ( !moveY && preShiftY ) + { + moveY = preShiftY / abs( preShiftY ); + } + + Pos.vx += moveX; + Pos.vy += moveY; } } } \ No newline at end of file