Browse Source

Sound patch from Ubuntux #3
(vcmi_sounds_sets.diff)

Michał W. Urbańczyk 16 years ago
parent
commit
ff131a3b2f
3 changed files with 18 additions and 1 deletions
  1. 3 0
      CPlayerInterface.cpp
  2. 11 1
      hch/CMusicHandler.cpp
  3. 4 0
      hch/CMusicHandler.h

+ 3 - 0
CPlayerInterface.cpp

@@ -2403,6 +2403,9 @@ void CPlayerInterface::battleAttack(BattleAttack *ba)
 void CPlayerInterface::showComp(SComponent comp)
 {
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
+
+	CGI->mush->playSoundFromSet(CGI->mush->pickup_sounds);
+
 	adventureInt->infoBar.showComp(&comp,4000);
 }
 

+ 11 - 1
hch/CMusicHandler.cpp

@@ -37,6 +37,10 @@ void CMusicHandler::initMusics()
 #undef VCMI_SOUND_NAME
 #undef VCMI_SOUND_FILE
 
+	// Vectors for helper(s)
+	pickup_sounds += soundBase::pickup01, soundBase::pickup02, soundBase::pickup03,
+		soundBase::pickup04, soundBase::pickup05, soundBase::pickup06, soundBase::pickup07;
+
 	//AITheme0 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITheme0.mp3");
 	//AITheme1 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITHEME1.mp3");
 	//AITheme2 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITHEME2.mp3");
@@ -80,7 +84,7 @@ void CMusicHandler::initMusics()
 	//winBattle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Win Battle.mp3");
 	//winScenario = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Win Scenario.mp3");
 
-	// Map sounds
+	// Load sounds
 	sndh = new CSndHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "Heroes3.snd"));
 }
 
@@ -137,3 +141,9 @@ int CMusicHandler::playSound(soundBase::soundNames soundID)
 
 	return channel;
 }
+
+// Helper. Randomly select a sound from an array and play it
+int CMusicHandler::playSoundFromSet(std::vector<soundBase::soundNames> &sound_vec)
+{
+	return playSound(sound_vec[rand() % sound_vec.size()]);
+}

+ 4 - 0
hch/CMusicHandler.h

@@ -42,6 +42,10 @@ public:
 
 	// Sounds
 	int playSound(soundBase::soundNames soundID); // plays sound wavs from Heroes3.snd
+	int playSoundFromSet(std::vector<soundBase::soundNames> &sound_vec);
+
+	// Sets
+	std::vector<soundBase::soundNames> pickup_sounds;
 };
 
 #endif // __CMUSICHANDLER_H__