forked from teamnwah/openmw-tes3coop
Regional Sounds
This commit is contained in:
parent
a038c67e5a
commit
be1582a88f
2 changed files with 49 additions and 9 deletions
|
@ -40,6 +40,7 @@
|
|||
#include <MyGUI_WidgetManager.h>
|
||||
#include "mwgui/class.hpp"
|
||||
|
||||
|
||||
void OMW::Engine::executeLocalScripts()
|
||||
{
|
||||
for (MWWorld::World::ScriptList::const_iterator iter (
|
||||
|
@ -107,27 +108,61 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
|||
// Play some good 'ol tunes
|
||||
startRandomTitle();
|
||||
}
|
||||
|
||||
std::string effect;
|
||||
|
||||
|
||||
//If the region has changed
|
||||
|
||||
MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayerPos().getPlayer().getCell();
|
||||
if(!(current->cell->data.flags & current->cell->Interior) && (test.name != current->cell->region)){
|
||||
test = *(mEnvironment.mWorld->getStore().regions.find(current->cell->region));
|
||||
//If the region has changed
|
||||
if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){
|
||||
timer.restart();
|
||||
if (test.name != current->cell->region)
|
||||
{
|
||||
total = 0;
|
||||
test = *(mEnvironment.mWorld->getStore().regions.find(current->cell->region));
|
||||
}
|
||||
|
||||
if(test.soundList.size() > 0)
|
||||
{
|
||||
std::vector<ESM::Region::SoundRef>::iterator soundIter = test.soundList.begin();
|
||||
mEnvironment.mWorld->getPlayerPos().getPlayer().getCell();
|
||||
//mEnvironment.mSoundManager
|
||||
if(total == 0){
|
||||
while (!(soundIter == test.soundList.end()))
|
||||
{
|
||||
ESM::NAME32 go = soundIter->sound;
|
||||
int chance = (int) soundIter->chance;
|
||||
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
||||
soundIter++;
|
||||
total += chance;
|
||||
}
|
||||
}
|
||||
|
||||
srand ( time(NULL) );
|
||||
int r = rand() % total; //old random code
|
||||
int pos = 0;
|
||||
soundIter = test.soundList.begin();
|
||||
while (!(soundIter == test.soundList.end()))
|
||||
{
|
||||
ESM::NAME32 go = soundIter->sound;
|
||||
char chance = soundIter->chance;
|
||||
std::cout << "Sound: " << go.name <<" Chance:" << (int) chance << "\n";
|
||||
const ESM::NAME32 go = soundIter->sound;
|
||||
int chance = (int) soundIter->chance;
|
||||
//std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
||||
soundIter++;
|
||||
if( r - pos < chance)
|
||||
{
|
||||
effect = go.name;
|
||||
//play sound
|
||||
std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n";
|
||||
mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
pos += chance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//mEnvironment.mSoundManager->playSound(effect, 1.0, 1.0);
|
||||
//printf("REGION: %s\n", test.name);
|
||||
|
||||
}
|
||||
|
@ -296,6 +331,7 @@ void OMW::Engine::go()
|
|||
|
||||
MP3Lookup();
|
||||
test.name = "";
|
||||
total = 0;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include "mwworld/environment.hpp"
|
||||
#include "mwworld/ptr.hpp"
|
||||
#include <boost/timer.hpp>
|
||||
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
|
@ -62,6 +64,7 @@ namespace OMW
|
|||
bool mVerboseScripts;
|
||||
bool mNewGame;
|
||||
bool mUseSound;
|
||||
int total;
|
||||
|
||||
MWWorld::Environment mEnvironment;
|
||||
MWScript::ScriptManager *mScriptManager;
|
||||
|
@ -69,6 +72,7 @@ namespace OMW
|
|||
Compiler::Context *mScriptContext;
|
||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||
ESM::Region test;
|
||||
boost::timer timer;
|
||||
|
||||
int focusFrameCounter;
|
||||
static const int focusUpdateFrame = 10;
|
||||
|
|
Loading…
Reference in a new issue