diff --git a/source/hazard/hazard.cpp b/source/hazard/hazard.cpp index d6cb84109..755c3b0c2 100644 --- a/source/hazard/hazard.cpp +++ b/source/hazard/hazard.cpp @@ -282,6 +282,8 @@ void CNpcHazard::init() m_extension = 0; m_extendDir = 0; m_heading = 0; + + clearPlatform(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -335,6 +337,8 @@ void CNpcHazard::think(int _frames) { processTimer( _frames ); } + + clearPlatform(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/hazard/hazard.h b/source/hazard/hazard.h index aa8552152..34d72ea84 100644 --- a/source/hazard/hazard.h +++ b/source/hazard/hazard.h @@ -65,6 +65,10 @@ public: static NPC_HAZARD_UNIT_TYPE getTypeFromMapEdit( u16 newType ); static CNpcHazard *Create(sThingHazard *ThisHazard); + void setPlatform(CThing *_newPlatform) {m_platform = _newPlatform;} + void clearPlatform() {m_platform = NULL;} + CThing *isOnPlatform() {return m_platform;} + protected: enum { @@ -93,6 +97,8 @@ protected: s32 m_heading; CModelGfx *m_modelGfx; + CThing *m_platform; + static NPC_HAZARD_UNIT_TYPE mapEditConvertTable[NPC_HAZARD_TYPE_MAX]; }; diff --git a/source/hazard/hdbarrel.cpp b/source/hazard/hdbarrel.cpp index 7f33d347d..26be57bc1 100644 --- a/source/hazard/hdbarrel.cpp +++ b/source/hazard/hdbarrel.cpp @@ -19,6 +19,10 @@ #include "level\layercollision.h" #endif +#ifndef __PLATFORM_PLATFORM_H__ +#include "platform\platform.h" +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void CNpcDualPlatformBarrelHazard::init() @@ -45,42 +49,25 @@ void CNpcDualPlatformBarrelHazard::processMovement( int _frames ) bool pathComplete; - if ( m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading ) ) + m_npcPath.thinkFlat( Pos, &pathComplete, &distX, &distY, &m_heading ); + + if ( pathComplete ) { - if ( pathComplete ) - { - // reset + // reset - Pos = m_base; - m_npcPath.resetPath(); + Pos = m_base; + m_npcPath.resetPath(); - return; - } - else - { - // check for vertical movement - - groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 ); - - if ( groundHeight <= yMovement ) - { - // groundHeight <= yMovement indicates either just above ground or on or below ground - - moveY = groundHeight; - } - else - { - // fall - - moveY = yMovement; - } - } + return; } else { // check for collision - distX = distX / abs( distX ); + if ( distX ) + { + distX = distX / abs( distX ); + } if ( m_layerCollision->getHeightFromGround( Pos.vx + ( distX * 3 * _frames ), Pos.vy ) < -maxHeight ) { @@ -103,9 +90,27 @@ void CNpcDualPlatformBarrelHazard::processMovement( int _frames ) } else { - // fall + CNpcPlatform *platform = (CNpcPlatform *) isOnPlatform(); - moveY = yMovement; + if ( platform ) + { + // stick to platform top + + moveY = platform->getHeightFromPlatformAtPosition( Pos.vx, Pos.vy + yMovement ); + + if ( !platform->canDrop() ) + { + // if platform cannot drop any further, move in X + + moveX = distX * 3 * _frames; + } + } + else + { + // fall + + moveY = yMovement; + } } } } diff --git a/source/platform/pdual.cpp b/source/platform/pdual.cpp index db8d6f659..26f8d55f6 100644 --- a/source/platform/pdual.cpp +++ b/source/platform/pdual.cpp @@ -83,6 +83,29 @@ void CNpcDualPlatform::setWaypoints( sThingPlatform *ThisPlatform ) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +u8 CNpcDualPlatform::canDrop() +{ + if ( m_isMaster ) + { + s32 extensionLeft = m_maxExtension - m_extension; + + if ( extensionLeft == 0 ) + { + return( false ); + } + else + { + return( true ); + } + } + else + { + return( false ); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CNpcDualPlatform::processMovement( int _frames ) { if ( m_isMaster ) diff --git a/source/platform/pdual.h b/source/platform/pdual.h index 1e90c8d51..90c2989d9 100644 --- a/source/platform/pdual.h +++ b/source/platform/pdual.h @@ -24,6 +24,7 @@ public: void setMaster( u8 isMaster ); void setOtherPlatform( CNpcDualPlatform *other ); void setMovement( DVECTOR move ); + virtual u8 canDrop(); protected: virtual void setWaypoints( sThingPlatform *ThisPlatform ); virtual void processMovement( int _frames ); diff --git a/source/platform/platform.cpp b/source/platform/platform.cpp index c407d4632..cc7a05f2c 100644 --- a/source/platform/platform.cpp +++ b/source/platform/platform.cpp @@ -29,6 +29,10 @@ #include "player\player.h" #endif +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + #ifndef __ENEMY_NPCPATH_H__ #include "enemy\npcpath.h" #endif @@ -826,6 +830,20 @@ void CNpcPlatform::collidedWith( CThing *_thisThing ) { m_contact = true; + CNpcHazard *hazard; + + hazard = (CNpcHazard *)_thisThing; + + hazard->setPlatform( this ); + + /*DVECTOR newPos = _thisThing->getPos(); + + s32 yDiff = getHeightFromPlatformAtPosition( newPos.vx, newPos.vy ); + + newPos.vy += yDiff; + + _thisThing->setPos( newPos );*/ + break; } diff --git a/source/platform/platform.h b/source/platform/platform.h index b83329dba..a64605f32 100644 --- a/source/platform/platform.h +++ b/source/platform/platform.h @@ -91,6 +91,7 @@ public: void shutdown(); virtual void think(int _frames); virtual void render(); + virtual u8 canDrop() {return true;} void setType( NPC_PLATFORM_UNIT_TYPE newType ) {m_type = newType;} void setTypeFromMapEdit( u16 newType ); void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;}