From 395a740e591e9dcfc4cf0f6e584ad08cdb29fae4 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 24 Apr 2001 19:03:06 +0000 Subject: [PATCH] --- source/enemy/nanemone.cpp | 5 +++ source/enemy/nanemone.h | 1 + source/enemy/nclam.cpp | 5 +++ source/enemy/nclam.h | 1 + source/enemy/neyeball.cpp | 5 +++ source/enemy/neyeball.h | 1 + source/enemy/nfskull.cpp | 5 +++ source/enemy/nfskull.h | 1 + source/enemy/ngen.cpp | 7 +++++ source/enemy/ngen.h | 1 + source/enemy/npc.cpp | 66 +++++++++++++++++++++++++++++++++++++++ source/enemy/npc.h | 4 +++ source/enemy/nsstomp.cpp | 5 +++ source/enemy/nsstomp.h | 1 + source/thing/thing.cpp | 25 +++++++++++++++ 15 files changed, 133 insertions(+) diff --git a/source/enemy/nanemone.cpp b/source/enemy/nanemone.cpp index 3a2e1c0fc..b0021f134 100644 --- a/source/enemy/nanemone.cpp +++ b/source/enemy/nanemone.cpp @@ -44,6 +44,11 @@ #endif +void CNpcAnemoneEnemy::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + bool CNpcAnemoneEnemy::processSensor() { switch( m_sensorFunc ) diff --git a/source/enemy/nanemone.h b/source/enemy/nanemone.h index ab5e5dcb0..5c5f876db 100644 --- a/source/enemy/nanemone.h +++ b/source/enemy/nanemone.h @@ -21,6 +21,7 @@ class CNpcAnemoneEnemy : public CNpcEnemy { protected: + virtual void processEnemyCollision( CThing *thisThing ); virtual bool processSensor(); }; diff --git a/source/enemy/nclam.cpp b/source/enemy/nclam.cpp index 83c76a009..a566a0f75 100644 --- a/source/enemy/nclam.cpp +++ b/source/enemy/nclam.cpp @@ -36,6 +36,11 @@ #endif +void CNpcClamEnemy::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + bool CNpcClamEnemy::processSensor() { switch( m_sensorFunc ) diff --git a/source/enemy/nclam.h b/source/enemy/nclam.h index 273b5f751..1c526fabf 100644 --- a/source/enemy/nclam.h +++ b/source/enemy/nclam.h @@ -17,6 +17,7 @@ class CNpcClamEnemy : public CNpcEnemy { protected: + virtual void processEnemyCollision( CThing *thisThing ); virtual bool processSensor(); }; diff --git a/source/enemy/neyeball.cpp b/source/enemy/neyeball.cpp index daf418d5a..671e96155 100644 --- a/source/enemy/neyeball.cpp +++ b/source/enemy/neyeball.cpp @@ -32,6 +32,11 @@ #endif +void CNpcEyeballEnemy::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + void CNpcEyeballEnemy::postInit() { CProjectile *projectile; diff --git a/source/enemy/neyeball.h b/source/enemy/neyeball.h index f0b99c945..8fd9d9794 100644 --- a/source/enemy/neyeball.h +++ b/source/enemy/neyeball.h @@ -18,6 +18,7 @@ class CNpcEyeballEnemy : public CNpcEnemy { virtual void postInit(); protected: + virtual void processEnemyCollision( CThing *thisThing ); virtual bool processSensor(); virtual void processClose( int _frames ); }; diff --git a/source/enemy/nfskull.cpp b/source/enemy/nfskull.cpp index f20f59393..d04f57d73 100644 --- a/source/enemy/nfskull.cpp +++ b/source/enemy/nfskull.cpp @@ -28,6 +28,11 @@ #endif +void CNpcFlamingSkullEnemy::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + void CNpcFlamingSkullEnemy::postInit() { m_state = FLAMING_SKULL_ATTACK; diff --git a/source/enemy/nfskull.h b/source/enemy/nfskull.h index 28443db9b..5b79891ef 100644 --- a/source/enemy/nfskull.h +++ b/source/enemy/nfskull.h @@ -18,6 +18,7 @@ class CNpcFlamingSkullEnemy : public CNpcEnemy { virtual void postInit(); protected: + virtual void processEnemyCollision( CThing *thisThing ); virtual bool processSensor(); virtual void processClose( int _frames ); diff --git a/source/enemy/ngen.cpp b/source/enemy/ngen.cpp index 4ff013dd1..238434177 100644 --- a/source/enemy/ngen.cpp +++ b/source/enemy/ngen.cpp @@ -80,3 +80,10 @@ void CNpcEnemyGenerator::render() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcEnemyGenerator::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + diff --git a/source/enemy/ngen.h b/source/enemy/ngen.h index c323c16ac..025e263c6 100644 --- a/source/enemy/ngen.h +++ b/source/enemy/ngen.h @@ -21,6 +21,7 @@ class CNpcEnemyGenerator : public CNpcEnemy { public: + virtual void processEnemyCollision( CThing *thisThing ); void render(); void think(int _frames); }; diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 55a7804f9..0a0d9538c 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -704,6 +704,7 @@ void CNpcEnemy::init() m_heading = m_fireHeading = 0; m_movementTimer = 0; m_timerTimer = 0; + m_collisionTimer = 0; m_velocity = 0; m_extension = 0; m_rotation = 0; @@ -751,6 +752,7 @@ void CNpcEnemy::reinit() m_heading = m_fireHeading = 0; m_movementTimer = 0; m_timerTimer = 0; + m_collisionTimer = 0; m_velocity = 0; m_extension = 0; m_rotation = 0; @@ -963,6 +965,13 @@ void CNpcEnemy::collidedWith( CThing *_thisThing ) break; } + case TYPE_ENEMY: + { + processEnemyCollision( _thisThing ); + + break; + } + default: ASSERT(0); break; @@ -1310,6 +1319,11 @@ void CNpcEnemy::processCollision() void CNpcEnemy::processTimer(int _frames) { + if ( m_collisionTimer > 0 ) + { + m_collisionTimer -= _frames; + } + if ( m_timerTimer > 0 ) { m_timerTimer -= _frames; @@ -1458,3 +1472,55 @@ void CNpcEnemy::caughtWithNet() shutdown(); } } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int CNpcEnemy::canCollide() +{ + return( m_isActive ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcEnemy::processEnemyCollision( 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 ) + { + Pos.vx += 6; + } + else + { + Pos.vx -= 6; + } + + if ( yDist > 0 ) + { + Pos.vy += 6; + } + else + { + Pos.vy -= 6; + } + + Pos.vx += otherDelta.vx; + Pos.vy += otherDelta.vy; + + if ( m_collisionTimer <= 0 ) + { + m_collisionTimer = GameState::getOneSecondInFrames(); + + m_heading = headingFromTarget; + + // try next waypoint to get around other enemy + + m_npcPath.incPath(); + } +} diff --git a/source/enemy/npc.h b/source/enemy/npc.h index a0e910c5c..8eaff4028 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -180,6 +180,8 @@ public: static CNpcEnemy *Create(sThingActor *ThisActor); void setupWaypoints( sThingActor *ThisActor ); + virtual int canCollide(); + protected: class CLayerCollision *m_layerCollision; @@ -302,6 +304,7 @@ protected: void processGenericFixedPathMove( int _frames, s32 *moveX, s32 *moveY, s32 *moveVel, s32 *moveDist ); void processGenericFixedPathWalk( int _frames, s32 *moveX, s32 *moveY ); bool processGroundCollisionReverse( s32 *moveX, s32 *moveY ); + virtual void processEnemyCollision( CThing *thisThing ); void reinit(); @@ -329,6 +332,7 @@ protected: s32 m_velocity; bool m_evadeClockwise; s32 m_movementTimer; + s32 m_collisionTimer; s32 m_timerTimer; s32 m_extension; bool m_extendDir; diff --git a/source/enemy/nsstomp.cpp b/source/enemy/nsstomp.cpp index acf957d45..f609e6a85 100644 --- a/source/enemy/nsstomp.cpp +++ b/source/enemy/nsstomp.cpp @@ -32,6 +32,11 @@ #endif +void CNpcSkullStomperEnemy::processEnemyCollision( CThing *thisThing ) +{ + // do nothing +} + void CNpcSkullStomperEnemy::postInit() { m_extendDir = EXTEND_DOWN; diff --git a/source/enemy/nsstomp.h b/source/enemy/nsstomp.h index 91b6f4ee9..57176e740 100644 --- a/source/enemy/nsstomp.h +++ b/source/enemy/nsstomp.h @@ -19,6 +19,7 @@ class CNpcSkullStomperEnemy : public CNpcEnemy public: virtual void postInit(); protected: + virtual void processEnemyCollision( CThing *thisThing ); virtual bool processSensor(); virtual void processClose( int _frames ); }; diff --git a/source/thing/thing.cpp b/source/thing/thing.cpp index bee759aed..16b4762a6 100644 --- a/source/thing/thing.cpp +++ b/source/thing/thing.cpp @@ -229,6 +229,31 @@ void CThingManager::thinkAllThings(int _frames) thing1=thing1->m_nextThing; } + // Enemy -> Enemy collision + thing1=s_thingLists[CThing::TYPE_ENEMY]; + while(thing1) + { + thing2=s_thingLists[CThing::TYPE_ENEMY]; + + while(thing2) + { + if ( thing1 != thing2 ) + { + if ( thing1->canCollide() && + thing2->canCollide() && + thing1->checkCollisionAgainst( thing2, _frames ) ) + { + thing1->collidedWith( thing2 ); + //thing2->collidedWith( thing1 ); + } + } + + thing2 = thing2->m_nextThing; + } + + thing1 = thing1->m_nextThing; + } + } /*----------------------------------------------------------------------