diff --git a/Graphics/levels/Chapter04/Level01/Level01.MEX b/Graphics/levels/Chapter04/Level01/Level01.MEX index 0a99b2f45..192120926 100644 Binary files a/Graphics/levels/Chapter04/Level01/Level01.MEX and b/Graphics/levels/Chapter04/Level01/Level01.MEX differ diff --git a/Graphics/levels/Chapter04/Level01/level01.Mep b/Graphics/levels/Chapter04/Level01/level01.Mep index f7e4cf87f..c92e28322 100644 Binary files a/Graphics/levels/Chapter04/Level01/level01.Mep and b/Graphics/levels/Chapter04/Level01/level01.Mep differ diff --git a/source/enemy/nanemone.cpp b/source/enemy/nanemone.cpp index 019b30cc2..507b36667 100644 --- a/source/enemy/nanemone.cpp +++ b/source/enemy/nanemone.cpp @@ -62,9 +62,9 @@ void CNpcAnemoneEnemy::postInit() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void CNpcAnemoneEnemy::setHeading( s32 xPos, s32 yPos ) +void CNpcAnemoneEnemy::setHeading( s32 xPos, s32 yPos, s32 xOrig, s32 yOrig ) { - m_heading = ( ratan2( ( ( yPos << 4 ) + 16 ) - Pos.vy, ( ( xPos << 4 ) + 8 ) - Pos.vx ) ) & 4095; + m_heading = ( ratan2( yPos - yOrig, xPos - xOrig ) ) & 4095; int newHeading = ( m_heading - 1024 ) & 4095; @@ -121,7 +121,7 @@ void CNpcAnemone1Enemy::processClose( int _frames ) s16 maxTurnRate = m_data[m_type].turnSpeed; bool withinRange = false; - s16 headingToPlayer = ratan2( playerYDist, playerXDist ); + s16 headingToPlayer = ratan2( playerYDist, playerXDist ) & 4095; decDir = m_fireHeading - headingToPlayer; diff --git a/source/enemy/nanemone.h b/source/enemy/nanemone.h index cba01897a..6cf04532e 100644 --- a/source/enemy/nanemone.h +++ b/source/enemy/nanemone.h @@ -22,7 +22,7 @@ class CNpcAnemoneEnemy : public CNpcEnemy { public: virtual void postInit(); - void setHeading( s32 xPos, s32 yPos ); + void setHeading( s32 xPos, s32 yPos, s32 xOrig, s32 yOrig ); protected: void processEnemyCollision( CThing *thisThing ); bool processSensor(); diff --git a/source/enemy/nclam.cpp b/source/enemy/nclam.cpp index ec05de4f7..ae05f67be 100644 --- a/source/enemy/nclam.cpp +++ b/source/enemy/nclam.cpp @@ -130,7 +130,7 @@ void CNpcJumpingClamEnemy::setupWaypoints( sThingActor *ThisActor ) endXPos = newXPos; endYPos = newYPos; - setHeading( newXPos, newYPos ); + setHeading( newXPos, newYPos, startXPos, startYPos ); s32 xDist = ( endXPos - startXPos ) << 4; s32 yDist = ( endYPos - startYPos ) << 4; diff --git a/source/enemy/ndustdev.cpp b/source/enemy/ndustdev.cpp index 747881f89..b712c1ad2 100644 --- a/source/enemy/ndustdev.cpp +++ b/source/enemy/ndustdev.cpp @@ -196,7 +196,7 @@ void CNpcDustDevilEnemy::processMovementModifier( int _frames, s32 distX, s32 di s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; - s16 heading = ratan2( yDist, xDist ); + s16 heading = ratan2( yDist, xDist ) & 4095; m_drawRotation = heading; } diff --git a/source/enemy/ngeneric.cpp b/source/enemy/ngeneric.cpp index daa9039f0..d578e1d09 100644 --- a/source/enemy/ngeneric.cpp +++ b/source/enemy/ngeneric.cpp @@ -28,7 +28,7 @@ void CNpcEnemy::processGenericGotoTarget( int _frames, s32 xDist, s32 yDist, s32 { s16 decDir, incDir, moveDist; s32 moveX, moveY; - s16 headingToTarget = ratan2( yDist, xDist ); + s16 headingToTarget = ratan2( yDist, xDist ) & 4095; s16 maxTurnRate = m_data[m_type].turnSpeed; decDir = m_heading - headingToTarget; @@ -166,7 +166,7 @@ bool CNpcEnemy::processGroundCollisionReverse( s32 *moveX, s32 *moveY ) *moveX = -(*moveX); - m_heading = ratan2( *moveY, *moveX ); + m_heading = ratan2( *moveY, *moveX ) & 4095; } else if ( !xBlocked && yBlocked ) { @@ -174,7 +174,7 @@ bool CNpcEnemy::processGroundCollisionReverse( s32 *moveX, s32 *moveY ) *moveY = -(*moveY); - m_heading = ratan2( *moveY, *moveX ); + m_heading = ratan2( *moveY, *moveX ) & 4095; } else { diff --git a/source/enemy/nhcrab.cpp b/source/enemy/nhcrab.cpp index dcf451e83..be23a3c5f 100644 --- a/source/enemy/nhcrab.cpp +++ b/source/enemy/nhcrab.cpp @@ -234,7 +234,7 @@ void CNpcHermitCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 d s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; - s16 heading = ratan2( yDist, xDist ); + s16 heading = ratan2( yDist, xDist ) & 4095; m_drawRotation = heading; diff --git a/source/enemy/nmjfish.cpp b/source/enemy/nmjfish.cpp index ee3c66886..fb6dcb217 100644 --- a/source/enemy/nmjfish.cpp +++ b/source/enemy/nmjfish.cpp @@ -104,15 +104,16 @@ void CNpcMotherJellyfishEnemy::setupWaypoints( sThingActor *ThisActor ) u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor)); u16 newXPos, newYPos; + u16 origXPos, origYPos; s32 startX = 0; m_npcPath.setWaypointCount( ThisActor->PointCount - 1 ); - newXPos = (u16) *PntList; + origXPos = newXPos = (u16) *PntList; setWaypointPtr( PntList ); PntList++; - newYPos = (u16) *PntList; + origYPos = newYPos = (u16) *PntList; PntList++; setStartPos( newXPos, newYPos ); @@ -130,7 +131,7 @@ void CNpcMotherJellyfishEnemy::setupWaypoints( sThingActor *ThisActor ) if ( pointNum == 1 ) { - setHeading( newXPos, newYPos ); + setHeading( newXPos, newYPos, origXPos, origYPos ); } if ( pointNum == ThisActor->PointCount - 2 ) diff --git a/source/enemy/npbug.cpp b/source/enemy/npbug.cpp index 3ccfb1f2e..6613cfbb4 100644 --- a/source/enemy/npbug.cpp +++ b/source/enemy/npbug.cpp @@ -47,7 +47,7 @@ void CNpcPricklyBugEnemy::processMovementModifier( int _frames, s32 distX, s32 d s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; - s16 heading = ratan2( yDist, xDist ); + s16 heading = ratan2( yDist, xDist ) & 4095; m_drawRotation = heading; } diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index dc69666fe..66b3409be 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -487,13 +487,14 @@ void CNpcEnemy::setupWaypoints( sThingActor *ThisActor ) u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor)); u16 newXPos, newYPos; + u16 origXPos, origYPos; m_npcPath.setWaypointCount( ThisActor->PointCount - 1 ); - newXPos = (u16) *PntList; + origXPos = newXPos = (u16) *PntList; setWaypointPtr( PntList ); PntList++; - newYPos = (u16) *PntList; + origYPos = newYPos = (u16) *PntList; PntList++; setStartPos( newXPos, newYPos ); @@ -505,7 +506,7 @@ void CNpcEnemy::setupWaypoints( sThingActor *ThisActor ) newYPos = (u16) *PntList; PntList++; - setHeading( newXPos, newYPos ); + setHeading( newXPos, newYPos, origXPos, origYPos ); } setThinkArea(); @@ -548,9 +549,9 @@ void CNpcEnemy::setStartPosHighRes( s32 xPos, s32 yPos ) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void CNpcEnemy::setHeading( s32 xPos, s32 yPos ) +void CNpcEnemy::setHeading( s32 xPos, s32 yPos, s32 xOrig, s32 yOrig ) { - m_heading = ( ratan2( ( ( yPos << 4 ) + 16 ) - Pos.vy, ( ( xPos << 4 ) + 8 ) - Pos.vx ) ) & 4095; + m_heading = ( ratan2( yPos - yOrig, xPos - xOrig ) ) & 4095; } @@ -1016,11 +1017,11 @@ bool CNpcEnemy::processSensor() if ( abs( playerXDist ) < abs( xDistWaypoint ) ) { - s16 headingToPlayer = ratan2( playerYDist, playerXDist ); + s16 headingToPlayer = ratan2( playerYDist, playerXDist ) & 4095; s16 decDir, incDir, moveDist; - s32 headingToWaypoint = ratan2( yDistWaypoint, xDistWaypoint ); + s32 headingToWaypoint = ratan2( yDistWaypoint, xDistWaypoint ) & 4095; // check waypoint is in the same direction as the user @@ -1511,7 +1512,7 @@ void CNpcEnemy::processEnemyCollision( CThing *thisThing ) s32 xDist = Pos.vx - otherPos.vx; s32 yDist = Pos.vy - otherPos.vy; - s16 headingFromTarget = ratan2( yDist, xDist ); + s16 headingFromTarget = ratan2( yDist, xDist ) & 4095; if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) ) { @@ -1576,7 +1577,7 @@ void CNpcEnemy::processUserCollision( CThing *thisThing ) s32 xDist = Pos.vx - otherPos.vx; s32 yDist = Pos.vy - otherPos.vy; - s16 headingFromTarget = ratan2( yDist, xDist ); + s16 headingFromTarget = ratan2( yDist, xDist ) & 4095; /*if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) ) { @@ -1623,7 +1624,7 @@ bool CNpcEnemy::processCoralBlowerMovement( int _frames, s32 xDist, s32 yDist, u s32 moveX, moveY; s16 headingToTarget; - headingToTarget = ratan2( yDist, xDist ); + headingToTarget = ratan2( yDist, xDist ) & 4095; s32 preShiftX = _frames * 5 * rcos( headingToTarget ); s32 preShiftY = _frames * 5 * rsin( headingToTarget ); diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 05f57cb53..c4b567e09 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -97,7 +97,7 @@ public: NPC_UNIT_TYPE getType() {return( m_type );} static NPC_UNIT_TYPE getTypeFromMapEdit( u16 newType ); void setHeading( s32 newHeading ) {m_heading = newHeading;} - virtual void setHeading( s32 xPos, s32 yPos ); + virtual void setHeading( s32 xPos, s32 yPos, s32 xOrig, s32 yOrig ); void setWaypointPtr( u16 *newPtr ) {m_npcPath.setWaypointPtr( newPtr );} void setWaypointCount( u8 newCount ) {m_npcPath.setWaypointCount( newCount );} void setPathType( u8 newType ) {m_npcPath.setPathType( newType );} diff --git a/source/enemy/npcpath.cpp b/source/enemy/npcpath.cpp index 445b58b1e..8d47f5833 100644 --- a/source/enemy/npcpath.cpp +++ b/source/enemy/npcpath.cpp @@ -298,7 +298,7 @@ s32 CNpcPath::think( DVECTOR const ¤tPos, bool *pathComplete, bool *waypoi *distY = ( ( *waypoint << 4 ) + 16 ) - currentPos.vy; } - s32 headingToTarget = ratan2( *distY, *distX ); + s32 headingToTarget = ratan2( *distY, *distX ) & 4095; return( headingToTarget ); } diff --git a/source/enemy/nscrab.cpp b/source/enemy/nscrab.cpp index 60be251a6..0a41b69f2 100644 --- a/source/enemy/nscrab.cpp +++ b/source/enemy/nscrab.cpp @@ -341,7 +341,7 @@ void CNpcSpiderCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 d s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; - s16 heading = ratan2( yDist, xDist ); + s16 heading = ratan2( yDist, xDist ) & 4095; m_drawRotation = heading; } diff --git a/source/enemy/nsjback.cpp b/source/enemy/nsjback.cpp index 6bd728a4c..052dae89c 100644 --- a/source/enemy/nsjback.cpp +++ b/source/enemy/nsjback.cpp @@ -92,6 +92,8 @@ void CNpcSmallJellyfishBackgroundEnemy::processMovement( int _frames ) { m_targetHeading += -1024 + ( getRnd() % 2049 ); } + + m_targetHeading &= 4095; } } } @@ -181,7 +183,7 @@ void CNpcSmallJellyfishBackgroundEnemy::processUserCollision( CThing *thisThing s32 xDist = Pos.vx - otherPos.vx; s32 yDist = Pos.vy - otherPos.vy; - s16 headingFromTarget = ratan2( yDist, xDist ); + s16 headingFromTarget = ratan2( yDist, xDist ) & 4095; if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) ) { diff --git a/source/enemy/nsjfish.cpp b/source/enemy/nsjfish.cpp index 6a0d68150..ce6b71c14 100644 --- a/source/enemy/nsjfish.cpp +++ b/source/enemy/nsjfish.cpp @@ -137,7 +137,7 @@ void CNpcSmallJellyfishEnemy::processClose( int _frames ) m_frame = 0; } - s16 headingToPlayer = ratan2( playerYDist, playerXDist ); + s16 headingToPlayer = ratan2( playerYDist, playerXDist ) & 4095; if ( m_evadeClockwise ) { diff --git a/source/enemy/nsklfish.cpp b/source/enemy/nsklfish.cpp index cfd0d435e..849e05a89 100644 --- a/source/enemy/nsklfish.cpp +++ b/source/enemy/nsklfish.cpp @@ -92,7 +92,7 @@ void CNpcSkeletalFishEnemy::processClose( int _frames ) m_chargeTime += _frames; } - s16 headingToPlayer = ratan2( playerYDist, playerXDist ); + s16 headingToPlayer = ratan2( playerYDist, playerXDist ) & 4095; if ( !m_animPlaying ) { diff --git a/source/enemy/nsshark.cpp b/source/enemy/nsshark.cpp index 8aa105215..ee81de2ac 100644 --- a/source/enemy/nsshark.cpp +++ b/source/enemy/nsshark.cpp @@ -876,13 +876,14 @@ void CNpcSubSharkEnemy::setupWaypoints( sThingActor *ThisActor ) u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor)); u16 newXPos, newYPos; + u16 startXPos, startYPos; m_npcPath.setWaypointCount( ThisActor->PointCount - 1 ); - newXPos = (u16) *PntList; + startXPos = newXPos = (u16) *PntList; setWaypointPtr( PntList ); PntList++; - newYPos = (u16) *PntList; + startYPos = newYPos = (u16) *PntList; PntList++; setStartPos( newXPos, newYPos ); @@ -894,7 +895,7 @@ void CNpcSubSharkEnemy::setupWaypoints( sThingActor *ThisActor ) newYPos = (u16) *PntList; PntList++; - setHeading( newXPos, newYPos ); + setHeading( newXPos, newYPos, startXPos, startYPos ); } s32 minX, maxX, minY, maxY; diff --git a/source/enemy/nssnake.cpp b/source/enemy/nssnake.cpp index 3d2ce164d..edae6b8a3 100644 --- a/source/enemy/nssnake.cpp +++ b/source/enemy/nssnake.cpp @@ -626,7 +626,7 @@ void CNpcSeaSnakeEnemy::updateTail( DVECTOR &oldPos, int _frames ) s32 xDist = oldPos.vx - newPos->pos.vx; s32 yDist = oldPos.vy - newPos->pos.vy; - s16 headingToTarget = ratan2( yDist, xDist ); + s16 headingToTarget = ratan2( yDist, xDist ) & 4095; DVECTOR sinPos; @@ -684,7 +684,7 @@ void CNpcSeaSnakeEnemy::updateTail( DVECTOR &oldPos, int _frames ) s32 xDist = oldPos.vx - currentPos.vx; s32 yDist = oldPos.vy - currentPos.vy; - s16 headingToPrev = ratan2( yDist, xDist ); + s16 headingToPrev = ratan2( yDist, xDist ) & 4095; s16 headingFromNext; s16 heading = headingToPrev; @@ -695,7 +695,7 @@ void CNpcSeaSnakeEnemy::updateTail( DVECTOR &oldPos, int _frames ) DVECTOR const &nextPos = m_segmentArray[segmentCount + 1].getPos(); xDist = currentPos.vx - nextPos.vx; yDist = currentPos.vy - nextPos.vy; - headingFromNext = ratan2( yDist, xDist ); + headingFromNext = ratan2( yDist, xDist ) & 4095; s16 decDir, incDir, moveDist; diff --git a/source/enemy/nworm.cpp b/source/enemy/nworm.cpp index 7391352e6..4540209d7 100644 --- a/source/enemy/nworm.cpp +++ b/source/enemy/nworm.cpp @@ -247,7 +247,7 @@ void CNpcParasiticWormEnemy::processMovement( int _frames ) s32 xDist = oldPos.vx - newPos->pos.vx; s32 yDist = oldPos.vy - newPos->pos.vy; - s16 headingToTarget = ratan2( yDist, xDist ); + s16 headingToTarget = ratan2( yDist, xDist ) & 4095; DVECTOR sinPos; @@ -282,7 +282,7 @@ void CNpcParasiticWormEnemy::processMovement( int _frames ) s32 xDist = oldPos.vx - currentPos.vx; s32 yDist = oldPos.vy - currentPos.vy; - s16 headingToPrev = ratan2( yDist, xDist ); + s16 headingToPrev = ratan2( yDist, xDist ) & 4095; s16 headingFromNext; s16 heading = headingToPrev; @@ -293,7 +293,7 @@ void CNpcParasiticWormEnemy::processMovement( int _frames ) DVECTOR const &nextPos = m_segmentArray[segmentCount + 1].getPos(); xDist = currentPos.vx - nextPos.vx; yDist = currentPos.vy - nextPos.vy; - headingFromNext = ratan2( yDist, xDist ); + headingFromNext = ratan2( yDist, xDist ) & 4095; s16 decDir, incDir, moveDist;