This commit is contained in:
Charles 2001-07-27 13:31:52 +00:00
parent 3a05eb9884
commit 035d72263d
20 changed files with 44 additions and 39 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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
{

View File

@ -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;

View File

@ -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 )

View File

@ -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;
}

View File

@ -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 );

View File

@ -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 );}

View File

@ -298,7 +298,7 @@ s32 CNpcPath::think( DVECTOR const &currentPos, bool *pathComplete, bool *waypoi
*distY = ( ( *waypoint << 4 ) + 16 ) - currentPos.vy;
}
s32 headingToTarget = ratan2( *distY, *distX );
s32 headingToTarget = ratan2( *distY, *distX ) & 4095;
return( headingToTarget );
}

View File

@ -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;
}

View File

@ -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 ) )
{

View File

@ -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 )
{

View File

@ -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 )
{

View File

@ -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;

View File

@ -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;

View File

@ -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;