示例#1
0
void PlayMusicByGroupAndFactionRandom(const std::string &group, const std::string &civilization_name, const std::string &faction_name) {
	if (!IsMusicEnabled()) {
		return;
	}

#ifdef USE_OAML
	if (enableOAML == false || oaml == NULL)
		return;

	SDL_LockMutex(Audio.Lock);
	if (oaml->PlayTrackByGroupAndSubgroupRandom(group.c_str(), faction_name.c_str()) != OAML_OK) {
		int civilization = PlayerRaces.GetRaceIndexByName(civilization_name.c_str());
		int faction = PlayerRaces.GetFactionIndexByName(civilization, faction_name);
		int parent_faction = -1;
		bool found_music = false;
		if (faction != -1) {
			while (true) {
				parent_faction = PlayerRaces.Factions[civilization][faction]->ParentFaction;
				if (parent_faction == -1) {
					break;
				}
				faction = parent_faction;
				
				if (oaml->PlayTrackByGroupAndSubgroupRandom(group.c_str(), PlayerRaces.Factions[civilization][faction]->Ident.c_str()) == OAML_OK) {
					found_music = true;
					break;
				}
			}
		}
		if (!found_music && oaml->PlayTrackByGroupAndSubgroupRandom(group.c_str(), civilization_name.c_str()) != OAML_OK) {
			int parent_civilization = -1;
			if (civilization != -1) {
				while (true) {
					parent_civilization = PlayerRaces.Civilizations[civilization]->ParentCivilization;
					if (parent_civilization == -1) {
						break;
					}
					civilization = parent_civilization;
					
					if (oaml->PlayTrackByGroupAndSubgroupRandom(group.c_str(), PlayerRaces.Name[civilization].c_str()) == OAML_OK) {
						found_music = true;
						break;
					}
				}
			}
			if (!found_music) {
				oaml->PlayTrackByGroupRandom(group.c_str());
			}
		}
	}
	SDL_UnlockMutex(Audio.Lock);
	
	if (GrandStrategy && !GameRunning) { // play day music in grand strategy mode
		SetMusicCondition(OAML_CONDID_MAIN_LOOP, MiddayTimeOfDay);
	}
#endif
}
示例#2
0
void PlayMusicByGroupRandom(const std::string &group) {
	if (!IsMusicEnabled()) {
		return;
	}
	
#ifdef USE_OAML
	if (enableOAML == false || oaml == NULL)
		return;

	SDL_LockMutex(Audio.Lock);
	oaml->PlayTrackByGroupRandom(group.c_str());
	SDL_UnlockMutex(Audio.Lock);
#endif
}
示例#3
0
void PlayMusicName(const std::string &name) {
	if (!IsMusicEnabled()) {
		return;
	}
	
#ifdef USE_OAML
	if (enableOAML == false || oaml == NULL)
		return;

	SDL_LockMutex(Audio.Lock);
	oaml->PlayTrack(name.c_str());
	SDL_UnlockMutex(Audio.Lock);
#endif
}
示例#4
0
文件: music.cpp 项目: AMDmi3/Wyrmgus
/**
**  Check if music is finished and play the next song
*/
void CheckMusicFinished(bool force)
{
	bool proceed;

	SDL_LockMutex(MusicFinishedMutex);
	proceed = MusicFinished;
	MusicFinished = false;
	SDL_UnlockMutex(MusicFinishedMutex);

	if ((proceed || force) && SoundEnabled() && IsMusicEnabled() && CallbackMusic) {
		lua_getglobal(Lua, "MusicStopped");
		if (!lua_isfunction(Lua, -1)) {
			fprintf(stderr, "No MusicStopped function in Lua\n");
			StopMusic();
		} else {
			LuaCall(0, 1);
		}
	}
}
示例#5
0
/**
**  Play a music file.
**
**  @param file  Name of music file, format is automatically detected.
**
**  @return      0 if music is playing, -1 if not.
*/
int PlayMusic(const std::string &file)
{
	if (!SoundEnabled() || !IsMusicEnabled()) {
		return -1;
	}
	const std::string name = LibraryFileName(file.c_str());
	DebugPrint("play music %s\n" _C_ name.c_str());
	CSample *sample = LoadSample(name.c_str(), PlayAudioStream);

	if (sample) {
		StopMusic();
		MusicChannel.Sample = sample;
		MusicPlaying = true;
		return 0;
	} else {
		DebugPrint("Could not play %s\n" _C_ file.c_str());
		return -1;
	}
}