From 16c576b8855798c7e414550568edc7c26de04064 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 18 Jun 2001 19:06:43 +0000 Subject: [PATCH] --- makefile.gfx | 2 +- source/enemy/nanemone.cpp | 30 ++++++++++++++++++++++----- source/enemy/nbblob.cpp | 5 ++++- source/enemy/nclam.cpp | 17 ++++++++++++--- source/enemy/ndogfish.cpp | 17 +++++++++------ source/enemy/neyeball.cpp | 10 +++++++-- source/enemy/nfdutch.cpp | 7 ++++++- source/enemy/nfskull.cpp | 5 ++++- source/enemy/nhcrab.cpp | 16 +++++++++++++-- source/enemy/npbug.cpp | 4 ---- source/enemy/npc.cpp | 40 +++++++++++++++++++++++++++++++++--- source/enemy/npc.h | 2 ++ source/enemy/npcdata.cpp | 3 ++- source/enemy/nscrab.cpp | 7 ++++++- source/enemy/nsdart.cpp | 7 ++++++- source/enemy/nsshark.cpp | 12 ++++++++++- source/enemy/nssnake.cpp | 5 ++++- source/enemy/nsstomp.cpp | 8 +++++++- source/enemy/nworm.cpp | 7 ++++++- source/hazard/hazard.cpp | 29 ++++++++++++++++++++++++++ source/hazard/hazard.h | 2 ++ source/hazard/hbwheel.cpp | 6 +++++- source/hazard/hcsaw.cpp | 5 ++++- source/hazard/hfalling.cpp | 5 ++++- source/hazard/hfirebal.cpp | 11 ++++++++-- source/hazard/hmower.cpp | 5 ++++- source/hazard/hrckshrd.cpp | 12 +++++++++-- source/hazard/hrrock.cpp | 5 ++++- source/hazard/hsaw.cpp | 5 ++++- source/platform/pfishhk.cpp | 5 ++++- source/platform/pgeyser.cpp | 6 +++++- source/platform/platform.cpp | 28 +++++++++++++++++++++++++ source/platform/platform.h | 3 +++ source/platform/pseesaw.cpp | 6 +++++- 34 files changed, 288 insertions(+), 49 deletions(-) diff --git a/makefile.gfx b/makefile.gfx index fe2fd7dba..7c2723715 100644 --- a/makefile.gfx +++ b/makefile.gfx @@ -193,7 +193,7 @@ PICKUP_GFX_IN := $(foreach FILE,$(PICKUP_GFX),$(PICKUP_GFX_DIR)/$(FILE).bmp) INGAMEFX_GFX_DIR := $(GRAF_DIR)/ingamefx INGAMEFX_GFX_TRANS := +watermeter +waterhilight +netblob \ - +spike + +spike +sharkmine INGAMEFX_GFX_TRANS_NONROT_NONCLIP := +bubble_1 +bubble_2 +bubble_3 \ +water +aim_arrow diff --git a/source/enemy/nanemone.cpp b/source/enemy/nanemone.cpp index 502f074b3..a3ad2da62 100644 --- a/source/enemy/nanemone.cpp +++ b/source/enemy/nanemone.cpp @@ -194,7 +194,10 @@ void CNpcAnemone1Enemy::processClose( int _frames ) m_drawRotation = ( m_heading + 1024 ) & 4095; - CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_MOVE ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_MOVE, true ); + } } if ( withinRange ) @@ -230,7 +233,12 @@ void CNpcAnemone1Enemy::processClose( int _frames ) { // if firing anim is complete and user is still in range, fire projectile - CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL1 ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL1, true ); DVECTOR projPos; projPos = Pos; @@ -331,7 +339,12 @@ void CNpcAnemone2Enemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } deleteAllChild(); @@ -402,7 +415,11 @@ void CNpcAnemone2Enemy::processClose( int _frames ) } else { - CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL2 ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL2, true ); + } + CProjectile *projectile; s16 heading; @@ -579,7 +596,10 @@ void CNpcAnemone3Enemy::processClose( int _frames ) } else if ( !m_animPlaying ) { - CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL3 ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_ANEMONE_ATTACK_LEVEL3, true ); + } CProjectile *projectile; u8 lifetime = 8; diff --git a/source/enemy/nbblob.cpp b/source/enemy/nbblob.cpp index 5c62f6976..ba737eef9 100644 --- a/source/enemy/nbblob.cpp +++ b/source/enemy/nbblob.cpp @@ -86,7 +86,10 @@ void CNpcBallBlobEnemy::processMovement( int _frames ) if ( m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].moveSfx ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].moveSfx, true ); + } } } diff --git a/source/enemy/nclam.cpp b/source/enemy/nclam.cpp index 9e3386ecd..5db5bf179 100644 --- a/source/enemy/nclam.cpp +++ b/source/enemy/nclam.cpp @@ -71,7 +71,10 @@ bool CNpcClamEnemy::processSensor() m_extendDir = EXTEND_UP; m_extension = 0; - CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_MOVE ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_MOVE, true ); + } return( true ); } @@ -254,7 +257,11 @@ void CNpcStaticClamEnemy::collidedWith( CThing *_thisThing ) if ( m_frame != 0 ) { m_frame = 0; - CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK, true ); + } } m_isStunned = 2 * GameState::getOneSecondInFrames(); @@ -321,7 +328,11 @@ void CNpcStaticClamEnemy::processAnimFrames( int _frames ) { m_frame = 0; m_animPlaying = false; - CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK, true ); + } } } } diff --git a/source/enemy/ndogfish.cpp b/source/enemy/ndogfish.cpp index a208c9e49..5681ad3f5 100644 --- a/source/enemy/ndogfish.cpp +++ b/source/enemy/ndogfish.cpp @@ -65,7 +65,7 @@ void CNpcIronDogfishEnemy::postInit() bool CNpcIronDogfishEnemy::processSensor() { - /*switch( m_sensorFunc ) + switch( m_sensorFunc ) { case NPC_SENSOR_NONE: return( false ); @@ -83,9 +83,7 @@ bool CNpcIronDogfishEnemy::processSensor() return( false ); } } - }*/ - - return( false ); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -347,7 +345,9 @@ void CNpcIronDogfishEnemy::hasBeenSteamed( DVECTOR &steamPos ) if ( m_steamTimer <= 0 ) { m_controlFunc = NPC_CONTROL_MOVEMENT; - m_vulnerableTimer = 2 * GameState::getOneSecondInFrames(); + + s16 second = GameState::getOneSecondInFrames(); + m_vulnerableTimer = ( 2 * second ) + ( 2 * second * ( ( m_data[m_type].initHealth - m_health ) / m_data[m_type].initHealth ) ); //hasBeenAttacked(); m_steamTimer = 4 * GameState::getOneSecondInFrames(); @@ -425,7 +425,12 @@ void CNpcIronDogfishEnemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } m_speed = -5; diff --git a/source/enemy/neyeball.cpp b/source/enemy/neyeball.cpp index 9e7fc6414..18c034dbc 100644 --- a/source/enemy/neyeball.cpp +++ b/source/enemy/neyeball.cpp @@ -119,7 +119,10 @@ CThing *Next=getNext(); // sound - CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK, true ); + } } } else @@ -139,7 +142,10 @@ CThing *Next=getNext(); // sound - CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_EYEBALL_SENTRY_ATTACK, true ); + } } } diff --git a/source/enemy/nfdutch.cpp b/source/enemy/nfdutch.cpp index 10cba5582..b4e3e222a 100644 --- a/source/enemy/nfdutch.cpp +++ b/source/enemy/nfdutch.cpp @@ -344,7 +344,12 @@ void CNpcFlyingDutchmanEnemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } m_speed = -5; diff --git a/source/enemy/nfskull.cpp b/source/enemy/nfskull.cpp index 13d348901..34912ad8e 100644 --- a/source/enemy/nfskull.cpp +++ b/source/enemy/nfskull.cpp @@ -67,7 +67,10 @@ void CNpcFlamingSkullEnemy::processClose( int _frames ) s32 distX, distY; s32 distXSqr, distYSqr; - CSoundMediator::playSfx( CSoundMediator::SFX_FLAMING_SKULL_ATTACK ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_FLAMING_SKULL_ATTACK, true ); + } if ( m_state == FLAMING_SKULL_ATTACK ) { diff --git a/source/enemy/nhcrab.cpp b/source/enemy/nhcrab.cpp index 427427094..e728d7dfe 100644 --- a/source/enemy/nhcrab.cpp +++ b/source/enemy/nhcrab.cpp @@ -60,6 +60,12 @@ bool CNpcHermitCrabEnemy::processSensor() { m_controlFunc = NPC_CONTROL_CLOSE; + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } + return( true ); } else @@ -235,7 +241,10 @@ void CNpcHermitCrabEnemy::processClose( int _frames ) // sound - CSoundMediator::playSfx( CSoundMediator::SFX_HERMIT_CRAB_ATTACK ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HERMIT_CRAB_ATTACK, true ); + } } } } @@ -272,5 +281,8 @@ void CNpcHermitCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 d // sound - CSoundMediator::playSfx( CSoundMediator::SFX_HERMIT_CRAB_MOVE ); + if( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HERMIT_CRAB_MOVE, true ); + } } diff --git a/source/enemy/npbug.cpp b/source/enemy/npbug.cpp index 467660b59..3ccfb1f2e 100644 --- a/source/enemy/npbug.cpp +++ b/source/enemy/npbug.cpp @@ -50,8 +50,4 @@ void CNpcPricklyBugEnemy::processMovementModifier( int _frames, s32 distX, s32 d s16 heading = ratan2( yDist, xDist ); m_drawRotation = heading; - - // sound - - //CSoundMediator::playSfx( CSoundMediator::SFX_PRICKLY_BUG_MOVE ); } diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index ae42eb1ec..8251ae9e8 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -599,6 +599,8 @@ void CNpcEnemy::init() m_heading = 0; m_RGB = 0; + m_soundId = (int) NOT_PLAYING; + updateCollisionArea(); } @@ -642,6 +644,11 @@ void CNpcEnemy::reinit() void CNpcEnemy::shutdown() { + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + //m_npcPath.removeAllWaypoints(); if (m_actorGfx) delete m_actorGfx; @@ -651,6 +658,17 @@ void CNpcEnemy::shutdown() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcEnemy::leftThinkZone(int _frames) +{ + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + int CNpcEnemy::getFrameCount() { return( m_actorGfx->getFrameCount( m_animNo ) ); @@ -720,6 +738,17 @@ void CNpcEnemy::think(int _frames) playerXDistSqr = playerXDist * playerXDist; playerYDistSqr = playerYDist * playerYDist; + if ( m_soundId != NOT_PLAYING ) + { + if( !CSoundMediator::isSfxStillPlaying( (xmPlayingId) m_soundId ) ) + { + // unlock sound if it has finished + + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } + } + if ( m_isCaught ) { processCoralBlower( moveFrames ); @@ -1060,9 +1089,9 @@ void CNpcEnemy::processMovement(int _frames) s32 moveVel = 0; s32 moveDist = 0; - if ( m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS ) + if ( m_soundId == NOT_PLAYING && m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].moveSfx ); + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].moveSfx, true ); } switch( m_movementFunc ) @@ -1201,7 +1230,12 @@ void CNpcEnemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } m_speed = -5; diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 535fcc822..f805afdc6 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -118,6 +118,7 @@ public: virtual int getFrame() {return( m_frame );} void setSpeed( s16 newSpeed ) {m_speed = newSpeed;} virtual u32 getRGB() {return( m_RGB );} + virtual void leftThinkZone(int _frames); static CNpcEnemy *Create(int enemyType); static CNpcEnemy *Create(sThingActor *ThisActor); @@ -311,6 +312,7 @@ protected: s16 m_speed; u8 m_isDying; u32 m_RGB; + int m_soundId; s32 m_frame; int m_animNo; diff --git a/source/enemy/npcdata.cpp b/source/enemy/npcdata.cpp index b4892148c..89aad13a3 100644 --- a/source/enemy/npcdata.cpp +++ b/source/enemy/npcdata.cpp @@ -1008,7 +1008,8 @@ CNpcEnemy::NPC_DATA CNpcEnemy::m_data[NPC_UNIT_TYPE_MAX] = false, 3, 2048, - DETECT_ALL_COLLISION, + //DETECT_ALL_COLLISION, + DETECT_ATTACK_COLLISION_GENERIC, DAMAGE__HIT_ENEMY, 50, ANIM_IRONDOGFISH_WALK, diff --git a/source/enemy/nscrab.cpp b/source/enemy/nscrab.cpp index 21ffafac7..60be251a6 100644 --- a/source/enemy/nscrab.cpp +++ b/source/enemy/nscrab.cpp @@ -99,7 +99,12 @@ bool CNpcSpiderCrabEnemy::processSensor() // sound - CSoundMediator::playSfx( CSoundMediator::SFX_SPIDERCRAB_ATTACK ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SPIDERCRAB_ATTACK, true ); return( true ); } diff --git a/source/enemy/nsdart.cpp b/source/enemy/nsdart.cpp index 4326faca3..78489ddee 100644 --- a/source/enemy/nsdart.cpp +++ b/source/enemy/nsdart.cpp @@ -138,7 +138,12 @@ bool CNpcSquidDartEnemy::processSensor() // sound - CSoundMediator::playSfx( CSoundMediator::SFX_SQUIDDART_ATTACK ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SQUIDDART_ATTACK, true ); return( true ); } diff --git a/source/enemy/nsshark.cpp b/source/enemy/nsshark.cpp index 5046fe728..e0ef923e5 100644 --- a/source/enemy/nsshark.cpp +++ b/source/enemy/nsshark.cpp @@ -39,6 +39,10 @@ #include "system\vid.h" #endif +#ifndef __SPR_SPRITES_H__ +#include +#endif + #include "fx\fx.h" #include "fx\fxnrgbar.h" @@ -89,6 +93,7 @@ void CNpcSubSharkEnemy::processMovement( int _frames ) CProjectile *projectile; projectile = CProjectile::Create(); projectile->init( Pos, 1024, CProjectile::PROJECTILE_MINE, CProjectile::PROJECTILE_FINITE_LIFE ); + projectile->setGraphic( FRM__SHARKMINE ); m_salvoCount--; @@ -358,7 +363,12 @@ void CNpcSubSharkEnemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } m_speed = -5; diff --git a/source/enemy/nssnake.cpp b/source/enemy/nssnake.cpp index 289a0ba37..28f450306 100644 --- a/source/enemy/nssnake.cpp +++ b/source/enemy/nssnake.cpp @@ -261,7 +261,10 @@ void CNpcSeaSnakeEnemy::processMovement( int _frames ) if ( m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].moveSfx ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].moveSfx, true ); + } } processGenericFixedPathMove( _frames, &moveX, &moveY, &moveVel, &moveDist ); diff --git a/source/enemy/nsstomp.cpp b/source/enemy/nsstomp.cpp index 253a6941b..c6519d093 100644 --- a/source/enemy/nsstomp.cpp +++ b/source/enemy/nsstomp.cpp @@ -67,7 +67,13 @@ bool CNpcSkullStomperEnemy::processSensor() { m_controlFunc = NPC_CONTROL_CLOSE; m_extendDir = EXTEND_DOWN; - CSoundMediator::playSfx( CSoundMediator::SFX_SKULL_ATTACK ); + + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SKULL_ATTACK, true ); return( true ); } diff --git a/source/enemy/nworm.cpp b/source/enemy/nworm.cpp index e766dcadb..f95625d44 100644 --- a/source/enemy/nworm.cpp +++ b/source/enemy/nworm.cpp @@ -638,7 +638,12 @@ void CNpcParasiticWormEnemy::processShot( int _frames ) if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS ) { - CSoundMediator::playSfx( m_data[m_type].deathSfx ); + if( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + + m_soundId = CSoundMediator::playSfx( m_data[m_type].deathSfx, true ); } m_isDying = true; diff --git a/source/hazard/hazard.cpp b/source/hazard/hazard.cpp index b44db8893..570c39ea1 100644 --- a/source/hazard/hazard.cpp +++ b/source/hazard/hazard.cpp @@ -400,6 +400,8 @@ void CNpcHazard::init() m_extendDir = 0; m_heading = 0; + m_soundId = (int) NOT_PLAYING; + clearPlatform(); } @@ -419,6 +421,11 @@ void CNpcHazard::setGraphic( sThingHazard *ThisHazard ) void CNpcHazard::shutdown() { + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + delete m_modelGfx; // remove waypoints @@ -431,8 +438,30 @@ void CNpcHazard::shutdown() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcHazard::leftThinkZone(int _frames) +{ + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CNpcHazard::think(int _frames) { + if ( m_soundId != NOT_PLAYING ) + { + if( !CSoundMediator::isSfxStillPlaying( (xmPlayingId) m_soundId ) ) + { + // unlock sound if it has finished + + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } + } + CHazardThing::think(_frames); if ( m_isActive ) diff --git a/source/hazard/hazard.h b/source/hazard/hazard.h index 2b322f1ff..0bb4917b2 100644 --- a/source/hazard/hazard.h +++ b/source/hazard/hazard.h @@ -82,6 +82,7 @@ public: void setWaypointCount( u8 newCount ) {m_npcPath.setWaypointCount( newCount );} virtual void setRespawnRate( s16 newRespawnRate ) {m_respawnRate=newRespawnRate;} virtual void trigger() {} + virtual void leftThinkZone(int _frames); static NPC_HAZARD_UNIT_TYPE getTypeFromMapEdit( u16 newType ); static CNpcHazard *Create(int Type); @@ -116,6 +117,7 @@ protected: s32 m_heading; CModelGfx *m_modelGfx; s16 m_respawnRate; + int m_soundId; CThing *m_platform; diff --git a/source/hazard/hbwheel.cpp b/source/hazard/hbwheel.cpp index 231c3977c..3158fdc9f 100644 --- a/source/hazard/hbwheel.cpp +++ b/source/hazard/hbwheel.cpp @@ -39,7 +39,11 @@ void CNpcBigWheelHazard::processMovement( int _frames ) { m_rotation += 5 * _frames; m_rotation &= 4095; - CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__BIG_WHEEL ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__BIG_WHEEL, true ); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/hazard/hcsaw.cpp b/source/hazard/hcsaw.cpp index 50b678734..257007024 100644 --- a/source/hazard/hcsaw.cpp +++ b/source/hazard/hcsaw.cpp @@ -40,7 +40,10 @@ void CNpcCircularSawHazard::processMovement( int _frames ) m_rotation += 256 * _frames; m_rotation &= 4095; - CSoundMediator::playSfx( CSoundMediator::SFX_SAW ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SAW, true ); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/hazard/hfalling.cpp b/source/hazard/hfalling.cpp index 20e3c3eed..149ec05e0 100644 --- a/source/hazard/hfalling.cpp +++ b/source/hazard/hfalling.cpp @@ -132,7 +132,10 @@ void CNpcFallingHazard::processMovement( int _frames ) if ( groundHeight < yMovement ) { - CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__ACORN_LAND, true ); + } // colliding with ground diff --git a/source/hazard/hfirebal.cpp b/source/hazard/hfirebal.cpp index 93359b5d7..8e60e31ea 100644 --- a/source/hazard/hfirebal.cpp +++ b/source/hazard/hfirebal.cpp @@ -106,7 +106,11 @@ void CNpcFireballHazard::processMovement( int _frames ) m_isActive = false; m_timerActive = true; m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames(); - CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAND ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAND, true ); + } return; } @@ -126,6 +130,9 @@ void CNpcFireballHazard::processTimer( int _frames ) m_timerActive = false; m_isActive = true; - CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAUNCH ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__FIREBALL_LAUNCH, true ); + } } } diff --git a/source/hazard/hmower.cpp b/source/hazard/hmower.cpp index de1701b88..74c8b4f74 100644 --- a/source/hazard/hmower.cpp +++ b/source/hazard/hmower.cpp @@ -40,7 +40,10 @@ void CNpcMowerHazard::processMovement( int _frames ) m_rotation += 256 * _frames; m_rotation &= 4095; - CSoundMediator::playSfx( CSoundMediator::SFX_SAW ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SAW, true ); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/hazard/hrckshrd.cpp b/source/hazard/hrckshrd.cpp index 0dd2e9551..1f2b3b4ba 100644 --- a/source/hazard/hrckshrd.cpp +++ b/source/hazard/hrckshrd.cpp @@ -58,7 +58,11 @@ void CNpcRockShardHazard::processMovement( int _frames ) { Pos.vx = m_base.vx + ( -3 + ( getRnd() % 7 ) ); Pos.vy = m_base.vy + ( -3 + ( getRnd() % 7 ) ); - CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_RATTLE ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_RATTLE, true ); + } } } else @@ -76,7 +80,11 @@ void CNpcRockShardHazard::processMovement( int _frames ) m_isActive = false; m_timerActive = true; m_timer = ( m_respawnRate - 1 ) * GameState::getOneSecondInFrames(); - CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_LAND ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_HAZARD__STALACTITE_LAND, true ); + } } else { diff --git a/source/hazard/hrrock.cpp b/source/hazard/hrrock.cpp index cd5c3bb27..71f692fa6 100644 --- a/source/hazard/hrrock.cpp +++ b/source/hazard/hrrock.cpp @@ -66,7 +66,10 @@ void CNpcRollingRockHazard::processMovement( int _frames ) { if ( !m_jump ) { - CSoundMediator::playSfx( CSoundMediator::SFX_ROLLING_ROCK ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_ROLLING_ROCK, true ); + } } if ( distX ) diff --git a/source/hazard/hsaw.cpp b/source/hazard/hsaw.cpp index d9d6dab06..1879b2c99 100644 --- a/source/hazard/hsaw.cpp +++ b/source/hazard/hsaw.cpp @@ -45,7 +45,10 @@ void CNpcSawbladeHazard::processMovement( int _frames ) s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange, &xDist, &yDist ); - CSoundMediator::playSfx( CSoundMediator::SFX_SAW ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_SAW, true ); + } if ( !pathComplete ) { diff --git a/source/platform/pfishhk.cpp b/source/platform/pfishhk.cpp index 56cad2cea..0ea084b55 100644 --- a/source/platform/pfishhk.cpp +++ b/source/platform/pfishhk.cpp @@ -64,7 +64,10 @@ void CNpcFishHookPlatform::processMovement( int _frames ) { if ( m_isMoving ) { - CSoundMediator::playSfx( CSoundMediator::SFX_FISH_HOOK_MOVE ); + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_FISH_HOOK_MOVE, true ); + } if ( m_isResetting ) { diff --git a/source/platform/pgeyser.cpp b/source/platform/pgeyser.cpp index fe1ec3f9f..a0175c93a 100644 --- a/source/platform/pgeyser.cpp +++ b/source/platform/pgeyser.cpp @@ -141,7 +141,11 @@ void CNpcGeyserPlatform::processTimer( int _frames ) m_isFiring = true; Pos = m_base; m_state = GEYSER_RISING; - CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__GEYSER ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__GEYSER, true ); + } } } } diff --git a/source/platform/platform.cpp b/source/platform/platform.cpp index 64a5594dd..6a813eaaa 100644 --- a/source/platform/platform.cpp +++ b/source/platform/platform.cpp @@ -607,6 +607,8 @@ void CNpcPlatform::init() m_npcPath.initPath(); m_speed = m_dataPtr->speed; + + m_soundId = (int) NOT_PLAYING; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -682,6 +684,11 @@ void CNpcPlatform::postInit() void CNpcPlatform::shutdown() { + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + } + delete m_modelGfx; //m_npcPath.removeAllWaypoints(); @@ -691,6 +698,17 @@ void CNpcPlatform::shutdown() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcPlatform::leftThinkZone(int _frames) +{ + if ( m_soundId != NOT_PLAYING ) + { + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CNpcPlatform::processLifetime( int _frames ) { switch( m_lifetimeType ) @@ -747,6 +765,16 @@ void CNpcPlatform::processLifetime( int _frames ) void CNpcPlatform::think(int _frames) { + if ( m_soundId != NOT_PLAYING ) + { + if( !CSoundMediator::isSfxStillPlaying( (xmPlayingId) m_soundId ) ) + { + // unlock sound if it has finished + + CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId ); + m_soundId = NOT_PLAYING; + } + } if ( m_isActive ) { diff --git a/source/platform/platform.h b/source/platform/platform.h index 457bb4085..9c3f554ca 100644 --- a/source/platform/platform.h +++ b/source/platform/platform.h @@ -123,6 +123,7 @@ public: virtual void trigger() {;} virtual u8 isCart() {return( false );} virtual void jump() {;} + virtual void leftThinkZone(int _frames); s16 getCollisionAngle() {return m_collisionAngle;} static NPC_PLATFORM_UNIT_TYPE getTypeFromMapEdit( u16 newType ); @@ -230,6 +231,8 @@ protected: sBBox m_nonRotatedCollisionArea; DVECTOR m_nonRotatedCollisionOffset; + int m_soundId; + virtual void collidedWith(CThing *_thisThing); static NPC_PLATFORM_UNIT_TYPE mapEditConvertTable[NPC_PLATFORM_TYPE_MAX]; diff --git a/source/platform/pseesaw.cpp b/source/platform/pseesaw.cpp index 51dd19b71..acf8178f4 100644 --- a/source/platform/pseesaw.cpp +++ b/source/platform/pseesaw.cpp @@ -107,7 +107,11 @@ void CNpcSeesawPlatform::processMovement( int _frames ) if ( m_currentAngle != newAngle ) { m_currentAngle = newAngle; - CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__SEESAW ); + + if ( m_soundId == NOT_PLAYING ) + { + m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_WORLD_OBJECT__SEESAW, true ); + } } setCollisionAngle( newAngle >> 8 );