diff --git a/source/enemy/nhcrab.cpp b/source/enemy/nhcrab.cpp index cc12260d5..c65d1835d 100644 --- a/source/enemy/nhcrab.cpp +++ b/source/enemy/nhcrab.cpp @@ -47,7 +47,7 @@ bool CNpcHermitCrabEnemy::processSensor() default: { - if ( playerXDistSqr + playerYDistSqr < 400 ) + if ( playerXDistSqr + playerYDistSqr < 4000 ) { m_controlFunc = NPC_CONTROL_CLOSE; diff --git a/source/enemy/nmjfish.cpp b/source/enemy/nmjfish.cpp index b8c4581c5..a9e9b56a1 100644 --- a/source/enemy/nmjfish.cpp +++ b/source/enemy/nmjfish.cpp @@ -343,3 +343,9 @@ void CNpcMotherJellyfishEnemy::render() } } } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcMotherJellyfishEnemy::processUserCollision( CThing *thisThing ) +{ +} diff --git a/source/enemy/nmjfish.h b/source/enemy/nmjfish.h index 950256095..748cc8b13 100644 --- a/source/enemy/nmjfish.h +++ b/source/enemy/nmjfish.h @@ -24,6 +24,7 @@ protected: virtual void processClose( int _frames ); virtual void processMovement( int _frames ); void spawnJellyfish( int _frames ); + virtual void processUserCollision( CThing *thisThing ); enum NPC_MOTHER_JELLYFISH_STATE { diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 412ffd708..80d99fc89 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -874,12 +874,15 @@ void CNpcEnemy::collidedWith( CThing *_thisThing ) m_oldControlFunc = m_controlFunc; m_controlFunc = NPC_CONTROL_COLLISION; + processUserCollision( _thisThing ); + break; } case DETECT_ATTACK_COLLISION_GENERIC: { processAttackCollision(); + processUserCollision( _thisThing ); break; } @@ -1456,6 +1459,46 @@ void CNpcEnemy::processEnemyCollision( CThing *thisThing ) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcEnemy::processUserCollision( CThing *thisThing ) +{ + DVECTOR otherPos = thisThing->getPos(); + DVECTOR otherDelta = thisThing->getPosDelta(); + + s32 xDist = Pos.vx - otherPos.vx; + s32 yDist = Pos.vy - otherPos.vy; + + s16 headingFromTarget = ratan2( yDist, xDist ); + + if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) ) + { + otherDelta.vx = -otherDelta.vx; + } + + if ( ( yDist > 0 && otherDelta.vy < 0 ) || ( yDist < 0 && otherDelta.vy > 0 ) ) + { + otherDelta.vy = -otherDelta.vy; + } + + Pos.vx += otherDelta.vx; + Pos.vy += otherDelta.vy; + + m_heading = headingFromTarget; + + s32 waypointXDist; + s32 waypointYDist; + + m_npcPath.getDistToNextWaypoint( Pos, &waypointXDist, &waypointYDist ); + + if ( ( xDist > 0 && waypointXDist < 0 ) || ( xDist < 0 && waypointXDist > 0 ) ) + { + // try next waypoint to get around other enemy + + m_npcPath.incPath(); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool CNpcEnemy::processCoralBlowerMovement( int _frames, s32 xDist, s32 yDist, u8 destroyAtTarget ) { s32 moveX, moveY; diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 1538c3ef0..ea301a9db 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -249,6 +249,7 @@ protected: void processGenericFixedPathWalk( int _frames, s32 *moveX, s32 *moveY ); bool processGroundCollisionReverse( s32 *moveX, s32 *moveY ); virtual void processEnemyCollision( CThing *thisThing ); + virtual void processUserCollision( CThing *thisThing ); void reinit(); diff --git a/source/enemy/nscrab.cpp b/source/enemy/nscrab.cpp index d5d569e92..350963efd 100644 --- a/source/enemy/nscrab.cpp +++ b/source/enemy/nscrab.cpp @@ -59,7 +59,7 @@ bool CNpcSpiderCrabEnemy::processSensor() default: { - if ( playerXDistSqr + playerYDistSqr < 10000 ) + if ( abs( playerXDist ) < 64 ) { // only attack if within path extents @@ -70,7 +70,7 @@ bool CNpcSpiderCrabEnemy::processSensor() { m_extendDir = EXTEND_LEFT; - if ( ( Pos.vx + playerXDist - 128 ) < minX ) + if ( ( Pos.vx + playerXDist ) < minX ) { return( false ); } @@ -79,12 +79,14 @@ bool CNpcSpiderCrabEnemy::processSensor() { m_extendDir = EXTEND_RIGHT; - if ( ( Pos.vx + playerXDist + 128 ) > maxX ) + if ( ( Pos.vx + playerXDist ) > maxX ) { return( false ); } } + m_attackDist = abs( playerXDist ); + m_controlFunc = NPC_CONTROL_CLOSE; m_extension = 0; m_velocity = 5; @@ -129,19 +131,19 @@ void CNpcSpiderCrabEnemy::processClose( int _frames ) bool completed = false; - if ( m_extension > 128 ) + if ( m_extension > m_attackDist ) { - m_extension = 128; + m_extension = m_attackDist; completed = true; } - else if ( m_extension < -128 ) + else if ( m_extension < -m_attackDist ) { - m_extension = -128; + m_extension = -m_attackDist; completed = true; } newPos.vx = m_base.vx + m_extension; - newPos.vy = m_base.vy - ( ( 20 * rsin( abs( m_extension ) << 4 ) ) >> 12 ); + newPos.vy = m_base.vy - ( ( SPIDER_CRAB_HEIGHT * rsin( abs( ( m_extension << 11 ) / m_attackDist ) ) ) >> 12 ); s32 minX, maxX; diff --git a/source/enemy/nscrab.h b/source/enemy/nscrab.h index 21523bda2..cd8094445 100644 --- a/source/enemy/nscrab.h +++ b/source/enemy/nscrab.h @@ -32,11 +32,19 @@ protected: virtual void processMovement( int _frames ); void processSpiderCrabInitJumpMovement( int _frames ); + s32 m_attackDist; + enum NPC_SPIDER_CRAB_STATE { SPIDER_CRAB_DEFAULT = 0, SPIDER_CRAB_INIT_JUMP = 1, }; + + enum NPC_SPIDER_CRAB_CONSTANTS + { + SPIDER_CRAB_EXTENSION = 64, + SPIDER_CRAB_HEIGHT = 50, + }; }; #endif diff --git a/source/platform/pbranch.cpp b/source/platform/pbranch.cpp index 30366604a..d983ae56f 100644 --- a/source/platform/pbranch.cpp +++ b/source/platform/pbranch.cpp @@ -36,7 +36,17 @@ void CNpcBranchPlatform::postInit() { - CNpcPlatform::postInit(); + sBBox boundingBox = m_modelGfx->GetBBox(); + setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ) << 1, 50 + ( boundingBox.YMax - boundingBox.YMin ) ); + + if ( m_reversed ) + { + setCollisionCentreOffset( boundingBox.XMax, 18 + ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) ); + } + else + { + setCollisionCentreOffset( boundingBox.XMin, 18 + ( ( boundingBox.YMax + boundingBox.YMin ) >> 1 ) ); + } m_angularVelocity = 0; } @@ -300,3 +310,27 @@ void CNpcBranchPlatform::render() } } } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcBranchPlatform::calculateBoundingBoxSize() +{ + int angle; + DVECTOR centre; + int length; + int x1,y1,x2,y2; + + angle=getCollisionAngle(); + centre=getCollisionCentre(); + + //halfLength=m_platformWidth/2; + sBBox boundingBox = m_modelGfx->GetBBox(); + length = ( boundingBox.XMax - boundingBox.XMin ); + + x1=-length*mcos(angle&4095)>>12; + y1=-length*msin(angle&4095)>>12; + x2=+length*mcos(angle&4095)>>12; + y2=+length*msin(angle&4095)>>12; + + setCollisionSize(abs(x2-x1),50 + abs(y2-y1)+PLATFORMCOLLISIONHEIGHT); +} diff --git a/source/platform/pbranch.h b/source/platform/pbranch.h index 5f5d8e7c4..c9117f25f 100644 --- a/source/platform/pbranch.h +++ b/source/platform/pbranch.h @@ -28,6 +28,7 @@ protected: virtual void processMovement( int _frames ); virtual void collidedWith(CThing *_thisThing); + virtual void calculateBoundingBoxSize(); s32 m_angularVelocity; u8 m_reversed; diff --git a/source/platform/platform.h b/source/platform/platform.h index 18f2ce429..ab28cd6ea 100644 --- a/source/platform/platform.h +++ b/source/platform/platform.h @@ -218,7 +218,7 @@ protected: protected: virtual void setCollisionAngle(int newAngle); // Actually.. this probly doesn't need to be in the base calss anymore.. :/ - void calculateBoundingBoxSize(); + virtual void calculateBoundingBoxSize(); };