1 /*************************************************************************** 2 sound.h - Sound and music manager 3 ------------------- 4 begin : Sat May 3 2003 5 copyright : (C) 2003 by Gabor Torok 6 email : cctorok@yahoo.com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef SOUND_H 19 #define SOUND_H 20 #pragma once 21 22 #include <string> 23 #include <map> 24 #include <vector> 25 #include "gui/window.h" 26 #include "userconfiguration.h" 27 #include "board.h" 28 29 /// This object manages random ambient sounds, and footstep sounds. 30 class AmbientSound { 31 std::string name; 32 #ifdef HAVE_SDL_MIXER 33 Mix_Chunk *footsteps; 34 std::vector<Mix_Chunk*> ambients; 35 #endif 36 std::string afterFirstLevel; 37 public: 38 AmbientSound( std::string& name, std::string& ambient, std::string& footsteps, std::string& afterFirstLevel ); 39 ~AmbientSound(); 40 int playRandomAmbientSample(); 41 int playFootsteps( int panning ); getAfterFirstLevel()42 inline std::string &getAfterFirstLevel() { 43 return afterFirstLevel; 44 } 45 }; 46 47 /// The game's main sound object. 48 class Sound { 49 private: 50 int missionMusicIndex; 51 int fightMusicIndex; 52 bool haveSound; 53 bool ambientPause; 54 std::map<std::string, AmbientSound*> ambients; 55 #ifdef HAVE_SDL_MIXER 56 Mix_Music *menuMusic; 57 Mix_Music *hqMusic; 58 Mix_Music *missionMusic; 59 Mix_Music *fightMusic, *currentFightMusic; 60 std::map<string, Mix_Music*> bossCombatMusics; 61 Mix_Music *currentMusic; 62 Mix_Music *currentLevelMusic; 63 Mix_Music *chapterMusic; 64 Mix_Music *outroMusic; 65 int lastChapter; 66 Uint32 musicStartTime; 67 double musicPosition; 68 std::map<std::string, Mix_Chunk*> soundMap; 69 std::map<std::string, std::string> soundNameMap; 70 std::map<std::string, Mix_Chunk*> ambient_objects; 71 std::map<std::string, std::map<int, std::vector<Mix_Chunk*>* >* > characterSounds; 72 #endif 73 74 public: 75 76 static char *TELEPORT; 77 static char *OPEN_DOOR; 78 static char *OPEN_BOX; 79 static char *FOOTSTEP_INDOORS; 80 static char *FOOTSTEP_OUTDOORS; 81 82 Sound( Preferences *preferences ); 83 virtual ~Sound(); 84 playMusicMenu()85 inline void playMusicMenu() { 86 #ifdef HAVE_SDL_MIXER 87 playMusic( menuMusic ); 88 #endif 89 } 90 playMusicHQ()91 inline void playMusicHQ() { 92 #ifdef HAVE_SDL_MIXER 93 playMusic( hqMusic ); 94 #endif 95 } 96 playMusicMission()97 inline void playMusicMission() { 98 #ifdef HAVE_SDL_MIXER 99 playMusic( missionMusic ); 100 #endif 101 } 102 playMusicChapter(bool gameCompleted)103 inline void playMusicChapter( bool gameCompleted ) { 104 #ifdef HAVE_SDL_MIXER 105 if( gameCompleted ) { 106 playMusic( outroMusic, 2000 ); 107 } else { 108 playMusic( chapterMusic, 2000, 1 ); 109 } 110 #endif 111 } 112 113 void stopMusic( int ms = 3000 ); 114 115 void loadSounds( Preferences *preferences ); 116 void loadUISounds( Preferences *preferences ); 117 void loadMonsterSounds( char const* monsterType, std::map<int, std::vector<std::string>*> *m, 118 Preferences *preferences ); 119 void unloadMonsterSounds( char const* monsterType, std::map<int, std::vector<std::string>*> *m ); 120 121 void loadCharacterSounds( char const* type ); 122 void unloadCharacterSounds( char const* type ); 123 void playCharacterSound( char const* type, int soundType, int panning ); 124 125 void storeSound( const std::string& name, const std::string& file ); 126 void storeSound( int type, const std::string& file ); 127 void unloadSound( int type, const std::string& file ); 128 int playSound( const std::string& file, int panning ); 129 130 void setMusicVolume( int volume ); 131 void setEffectsVolume( int volume ); 132 133 void selectMusic( Preferences *preferences, Mission *mission = NULL ); 134 135 void checkMusic( bool inCombat, const char *currentCombatMusic ); 136 137 void startFootsteps( std::string& name, int depth, int panning ); 138 void stopFootsteps(); 139 140 void addAmbientSound( std::string& name, std::string& ambient, std::string& footsteps, std::string& afterFirstLevel ); 141 void startAmbientSound( std::string& name, int depth ); 142 void stopAmbientSound(); 143 144 void pauseAmbientSounds(); 145 void unpauseAmbientSounds(); 146 147 void playObjectSound( std::string& name, int percent, int panning ); 148 void storeAmbientObjectSound( std::string const& sound ); 149 150 void startRain(); 151 void stopRain(); 152 153 protected: 154 AmbientSound *getAmbientSound( std::string& name, int depth ); 155 #ifdef HAVE_SDL_MIXER 156 void playMusic( Mix_Music *music, int ms = 2000, int loopCount = -1 ); 157 void storeCharacterSounds( std::map<int, std::vector<Mix_Chunk*>*> *charSoundMap, 158 char const* type, int soundType, char const* filePrefix ); 159 #endif 160 }; 161 162 #endif 163 164