Update music state in the menu mode (bug #3664)

pull/351/head
Andrei Kortunov 7 years ago
parent 9920779a7b
commit b9d9660efd

@ -1148,6 +1148,46 @@ namespace MWMechanics
}
}
void Actors::updateCombatMusic ()
{
MWWorld::Ptr player = getPlayer();
int hostilesCount = 0; // need to know this to play Battle music
for(PtrActorMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter)
{
if (!iter->first.getClass().getCreatureStats(iter->first).isDead())
{
bool inProcessingRange = (player.getRefData().getPosition().asVec3() - iter->first.getRefData().getPosition().asVec3()).length2()
<= sqrAiProcessingDistance;
if (MWBase::Environment::get().getMechanicsManager()->isAIActive() && inProcessingRange)
{
if (iter->first != player)
{
MWMechanics::CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first);
if (stats.getAiSequence().isInCombat() && !stats.isDead()) hostilesCount++;
}
}
}
}
// check if we still have any player enemies to switch music
static int currentMusic = 0;
if (currentMusic != 1 && hostilesCount == 0 && !(player.getClass().getCreatureStats(player).isDead() &&
MWBase::Environment::get().getSoundManager()->isMusicPlaying()))
{
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
currentMusic = 1;
}
else if (currentMusic != 2 && hostilesCount > 0)
{
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Battle"));
currentMusic = 2;
}
}
void Actors::update (float duration, bool paused)
{
if(!paused)
@ -1165,8 +1205,6 @@ namespace MWMechanics
MWWorld::Ptr player = getPlayer();
int hostilesCount = 0; // need to know this to play Battle music
/// \todo move update logic to Actor class where appropriate
std::map<const MWWorld::Ptr, const std::set<MWWorld::Ptr> > cachedAllies; // will be filled as engageCombat iterates
@ -1257,8 +1295,6 @@ namespace MWMechanics
CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first);
if (isConscious(iter->first))
stats.getAiSequence().execute(iter->first, *iter->second->getCharacterController(), iter->second->getAiState(), duration);
if (stats.getAiSequence().isInCombat() && !stats.isDead()) hostilesCount++;
}
}
@ -1331,21 +1367,6 @@ namespace MWMechanics
killDeadActors();
// check if we still have any player enemies to switch music
static int currentMusic = 0;
if (currentMusic != 1 && hostilesCount == 0 && !(player.getClass().getCreatureStats(player).isDead() &&
MWBase::Environment::get().getSoundManager()->isMusicPlaying()))
{
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
currentMusic = 1;
}
else if (currentMusic != 2 && hostilesCount > 0)
{
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Battle"));
currentMusic = 2;
}
static float sneakTimer = 0.f; // times update of sneak icon
// if player is in sneak state see if anyone detects him
@ -1412,6 +1433,8 @@ namespace MWMechanics
MWBase::Environment::get().getWindowManager()->setSneakVisibility(false);
}
}
updateCombatMusic();
}
void Actors::killDeadActors()

@ -81,6 +81,9 @@ namespace MWMechanics
void dropActors (const MWWorld::CellStore *cellStore, const MWWorld::Ptr& ignore);
///< Deregister all actors (except for \a ignore) in the given cell.
void updateCombatMusic();
///< Update combat music state
void update (float duration, bool paused);
///< Update actor stats and store desired velocity vectors in \a movement

Loading…
Cancel
Save