1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-27 05:37:25 +00:00
This commit is contained in:
Capostrophic 2018-10-14 20:37:40 +03:00
parent 19fd404b7b
commit bf3f82b9d4
3 changed files with 27 additions and 40 deletions

View File

@ -138,19 +138,13 @@ namespace MWClass
std::string Activator::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const
{
std::string model = getModel(ptr);
if (model.empty())
return std::string();
const MWWorld::Store<ESM::Creature> &creaturestore = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>();
std::string model = getModel(ptr); // Assume it's not empty, since we wouldn't have gotten the soundgen otherwise
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
std::string creatureId;
for (const ESM::Creature &iter : creaturestore)
{
if (iter.mModel.empty())
continue;
if (Misc::StringUtils::ciEqual(model, "meshes\\" + iter.mModel))
for (const ESM::Creature &iter : store.get<ESM::Creature>())
{
if (!iter.mModel.empty() && Misc::StringUtils::ciEqual(model, "meshes\\" + iter.mModel))
{
creatureId = !iter.mOriginal.empty() ? iter.mOriginal : iter.mId;
break;
@ -160,19 +154,12 @@ namespace MWClass
if (creatureId.empty())
return std::string();
const MWWorld::Store<ESM::SoundGenerator> &store = MWBase::Environment::get().getWorld()->getStore().get<ESM::SoundGenerator>();
int type = getSndGenTypeFromName(name);
std::vector<const ESM::SoundGenerator*> sounds;
MWWorld::Store<ESM::SoundGenerator>::iterator sound = store.begin();
while (sound != store.end())
{
for (auto sound = store.get<ESM::SoundGenerator>().begin(); sound != store.get<ESM::SoundGenerator>().end(); ++sound)
if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature)))
sounds.push_back(&*sound);
++sound;
}
if (!sounds.empty())
return sounds[Misc::Rng::rollDice(sounds.size())]->mSound;
@ -183,24 +170,24 @@ namespace MWClass
return std::string();
}
int Activator::getSndGenTypeFromName(const std::string &name) const
int Activator::getSndGenTypeFromName(const std::string &name)
{
if (name == "left")
return 0;
return ESM::SoundGenerator::LeftFoot;
if (name == "right")
return 1;
return ESM::SoundGenerator::RightFoot;
if (name == "swimleft")
return 2;
return ESM::SoundGenerator::SwimLeft;
if (name == "swimright")
return 3;
return ESM::SoundGenerator::SwimRight;
if (name == "moan")
return 4;
return ESM::SoundGenerator::Moan;
if (name == "roar")
return 5;
return ESM::SoundGenerator::Roar;
if (name == "scream")
return 6;
return ESM::SoundGenerator::Scream;
if (name == "land")
return 7;
return ESM::SoundGenerator::Land;
throw std::runtime_error(std::string("Unexpected soundgen type: ")+name);
}

View File

@ -10,6 +10,8 @@ namespace MWClass
virtual MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const;
static int getSndGenTypeFromName(const std::string &name);
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const;
@ -46,8 +48,6 @@ namespace MWClass
virtual bool isActivator() const;
virtual std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const;
virtual int getSndGenTypeFromName(const std::string &name) const;
};
}

View File

@ -688,9 +688,9 @@ namespace MWClass
MWBase::World *world = MWBase::Environment::get().getWorld();
osg::Vec3f pos(ptr.getRefData().getPosition().asVec3());
if(world->isUnderwater(ptr.getCell(), pos) || world->isWalkingOnWater(ptr))
return 2;
return ESM::SoundGenerator::SwimLeft;
if(world->isOnGround(ptr))
return 0;
return ESM::SoundGenerator::LeftFoot;
return -1;
}
if(name == "right")
@ -698,23 +698,23 @@ namespace MWClass
MWBase::World *world = MWBase::Environment::get().getWorld();
osg::Vec3f pos(ptr.getRefData().getPosition().asVec3());
if(world->isUnderwater(ptr.getCell(), pos) || world->isWalkingOnWater(ptr))
return 3;
return ESM::SoundGenerator::SwimRight;
if(world->isOnGround(ptr))
return 1;
return ESM::SoundGenerator::RightFoot;
return -1;
}
if(name == "swimleft")
return 2;
return ESM::SoundGenerator::SwimLeft;
if(name == "swimright")
return 3;
return ESM::SoundGenerator::SwimRight;
if(name == "moan")
return 4;
return ESM::SoundGenerator::Moan;
if(name == "roar")
return 5;
return ESM::SoundGenerator::Roar;
if(name == "scream")
return 6;
return ESM::SoundGenerator::Scream;
if(name == "land")
return 7;
return ESM::SoundGenerator::Land;
throw std::runtime_error(std::string("Unexpected soundgen type: ")+name);
}