diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index f2e01e8a5..2b3269554 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -511,7 +511,7 @@ void CNpcEnemy::postInit() m_npcPath.setPathType( CNpcPath::PONG_PATH ); - // create head of list + // create start of list CNpcPositionHistory *newPosition; newPosition = new ("position history") CNpcPositionHistory; newPosition->pos = Pos; @@ -521,17 +521,23 @@ void CNpcEnemy::postInit() // create rest of list - for ( int histLength = 1 ; histLength < ( 10 * NPC_PARASITIC_WORM_SPACING ) ; histLength++ ) + for ( int histLength = 1 ; histLength < ( NPC_PARASITIC_WORM_LENGTH * NPC_PARASITIC_WORM_SPACING ) ; histLength++ ) { newPosition = new ("position history") CNpcPositionHistory; newPosition->pos = Pos; newPosition->next = NULL; + newPosition->prev = currentPosition; currentPosition->next = newPosition; currentPosition = newPosition; } - for ( int segCount = 0 ; segCount < 10 ; segCount++ ) + // link ends together for circular list + + currentPosition->next = m_positionHistory; + m_positionHistory->prev = currentPosition; + + for ( int segCount = 0 ; segCount < NPC_PARASITIC_WORM_LENGTH ; segCount++ ) { CNpcEnemy *segment; segment = new ("segment") CNpcEnemy; diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 684fb1971..20c849902 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -391,6 +391,7 @@ protected: NPC_BOOGER_MONSTER_MAX_EXTENSION = 20, NPC_SUB_SHARK_HIGH_SPEED = 6, NPC_PARASITIC_WORM_SPACING = 6, + NPC_PARASITIC_WORM_LENGTH = 10, EXTEND_UP = true, EXTEND_DOWN = false, EXTEND_RIGHT = true, @@ -611,6 +612,7 @@ protected: public: DVECTOR pos; CNpcPositionHistory *next; + CNpcPositionHistory *prev; }; CNpcPositionHistory *m_positionHistory; diff --git a/source/enemy/nworm.cpp b/source/enemy/nworm.cpp index 10be16906..a125bf5ab 100644 --- a/source/enemy/nworm.cpp +++ b/source/enemy/nworm.cpp @@ -39,7 +39,64 @@ void CNpcEnemy::processParasiticWormMovement( int _frames ) m_extension += 256; m_extension &= 4095; - // add new (old) position onto list head + m_positionHistory = m_positionHistory->prev; + m_positionHistory->pos = oldPos; + + CNpcPositionHistory *newPos; + newPos = m_positionHistory; + for ( skipCounter = 1 ; skipCounter < NPC_PARASITIC_WORM_SPACING ; skipCounter++ ) + { + newPos = newPos->next; + } + + CThing *List=Next; + + oldPos = Pos; + + s32 extension = m_extension; + u8 downShift = 2; + + while( List ) + { + CNpcEnemy *segment = (CNpcEnemy *) List; + + s32 xDist = oldPos.vx - newPos->pos.vx; + s32 yDist = oldPos.vy - newPos->pos.vy; + + s16 headingToTarget = ratan2( yDist, xDist ); + + segment->setHeading( headingToTarget ); + + DVECTOR sinPos; + + sinPos = newPos->pos; + s32 diff = ( ( 10 >> downShift ) * rsin( extension ) ) >> 12; + sinPos.vx += ( diff * rcos( headingToTarget + 1024 ) ) >> 12; + sinPos.vy += ( diff * rsin( headingToTarget + 1024 ) ) >> 12; + + List->setPos( sinPos ); + oldPos = newPos->pos; + + List = List->getNext(); + + if ( List ) + { + for ( skipCounter = 0 ; skipCounter < NPC_PARASITIC_WORM_SPACING ; skipCounter++ ) + { + newPos = newPos->next; + } + } + + extension += 1024; + extension &= 4095; + + if ( downShift > 0 ) + { + downShift--; + } + } + + /*// add new (old) position onto list head CNpcPositionHistory *newPos; newPos = new ("position history") CNpcPositionHistory; newPos->pos = oldPos; @@ -111,5 +168,5 @@ void CNpcEnemy::processParasiticWormMovement( int _frames ) { downShift--; } - } + }*/ } \ No newline at end of file