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 }
static void GameLogicLoop() { // Can't find a better place. // FIXME: We need find better place! SaveGameLoading = false; #ifdef USE_OAML if (enableOAML && oaml) { // Time of day can change our main music loop, if the current playing track is set for this SetMusicCondition(OAML_CONDID_MAIN_LOOP, Map.TimeOfDay[CurrentMapLayer]); } #endif // // Game logic part // if (!GamePaused && NetworkInSync && !SkipGameCycle) { SinglePlayerReplayEachCycle(); ++GameCycle; MultiPlayerReplayEachCycle(); NetworkCommands(); // Get network commands TriggersEachCycle();// handle triggers UnitActions(); // handle units MissileActions(); // handle missiles PlayersEachCycle(); // handle players UpdateTimer(); // update game timer // // Work todo each second. // Split into different frames, to reduce cpu time. // Increment mana of magic units. // Update mini-map. // Update map fog of war. // Call AI. // Check game goals. // Check rescue of units. // switch (GameCycle % CYCLES_PER_SECOND) { case 0: // At cycle 0, start all ai players... if (GameCycle == 0) { for (int player = 0; player < NumPlayers; ++player) { PlayersEachSecond(player); } } break; case 1: break; case 2: break; case 3: // minimap update UI.Minimap.UpdateCache = true; break; case 4: break; case 5: // forest grow Map.RegenerateForest(); break; case 6: // overtaking units RescueUnits(); break; //Wyrmgus start /* default: { // FIXME: assume that NumPlayers < (CYCLES_PER_SECOND - 7) int player = (GameCycle % CYCLES_PER_SECOND) - 7; Assert(player >= 0); if (player < NumPlayers) { PlayersEachSecond(player); } } */ //Wyrmgus end } //Wyrmgus start int player = (GameCycle - 1) % CYCLES_PER_SECOND; Assert(player >= 0); if (player < NumPlayers) { PlayersEachSecond(player); if ((player + CYCLES_PER_SECOND) < NumPlayers) { PlayersEachSecond(player + CYCLES_PER_SECOND); } } player = (GameCycle - 1) % CYCLES_PER_MINUTE; Assert(player >= 0); if (player < NumPlayers) { PlayersEachMinute(player); } //Wyrmgus end //Wyrmgus start for (size_t z = 0; z < Map.Fields.size(); ++z) { if (GameSettings.Inside || GameSettings.NoTimeOfDay || !Map.TimeOfDaySeconds[z]) { // indoors it is always dark (maybe would be better to allow a special setting to have bright indoor places? Map.TimeOfDay[z] = NoTimeOfDay; // make indoors have no time of day setting until it is possible to make light sources change their surrounding "time of day" continue; } if (GameCycle > 0 && GameCycle % (CYCLES_PER_SECOND * Map.TimeOfDaySeconds[z]) == 0) { Map.TimeOfDay[z] += 1; if (Map.TimeOfDay[z] == MaxTimesOfDay) { Map.TimeOfDay[z] = 1; } #ifdef USE_OAML if (enableOAML && oaml && z == CurrentMapLayer) { // Time of day can change our main music loop, if the current playing track is set for this SetMusicCondition(OAML_CONDID_MAIN_LOOP, Map.TimeOfDay[z]); } #endif //update the sight of all units for (CUnitManager::Iterator it = UnitManager.begin(); it != UnitManager.end(); ++it) { CUnit *unit = *it; if ( unit && unit->IsAlive() && unit->MapLayer == z && ( ((Map.TimeOfDay[z] == MorningTimeOfDay || Map.TimeOfDay[z] == DuskTimeOfDay) && unit->Variable[DAYSIGHTRANGEBONUS_INDEX].Value != 0) // if has day sight bonus and is entering or exiting day || ((Map.TimeOfDay[z] == FirstWatchTimeOfDay || Map.TimeOfDay[z] == DawnTimeOfDay) && unit->Variable[NIGHTSIGHTRANGEBONUS_INDEX].Value != 0) // if has night sight bonus and is entering or exiting night ) ) { MapUnmarkUnitSight(*unit); UpdateUnitSightRange(*unit); MapMarkUnitSight(*unit); } } } } //Wyrmgus end //Wyrmgus start // if (Preference.AutosaveMinutes != 0 && !IsNetworkGame() && GameCycle > 0 && (GameCycle % (CYCLES_PER_SECOND * 60 * Preference.AutosaveMinutes)) == 0) { // autosave every X minutes, if the option is enabled if (Preference.AutosaveMinutes != 0 && !IsNetworkGame() && !GrandStrategy && GameCycle > 0 && (GameCycle % (CYCLES_PER_MINUTE * Preference.AutosaveMinutes)) == 0) { // autosave every X minutes, if the option is enabled //Wyrmgus end UI.StatusLine.Set(_("Autosave")); //Wyrmgus start // SaveGame("autosave.sav"); CclCommand("if (RunSaveGame ~= nil) then RunSaveGame(\"autosave.sav\") end;"); //Wyrmgus end } } UpdateMessages(); // update messages ParticleManager.update(); // handle particles CheckMusicFinished(); // Check for next song if (FastForwardCycle <= GameCycle || !(GameCycle & 0x3f)) { WaitEventsOneFrame(); } if (!NetworkInSync) { NetworkRecover(); // recover network } }