mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 18:06:43 +00:00
Merge pull request #2109 from Capostrophic/loops
Simplify some world loops
This commit is contained in:
commit
9c795195d0
2 changed files with 96 additions and 147 deletions
|
@ -860,8 +860,13 @@ namespace MWMechanics
|
||||||
|
|
||||||
bool hasSummonEffect = false;
|
bool hasSummonEffect = false;
|
||||||
for (MagicEffects::Collection::const_iterator it = effects.begin(); it != effects.end(); ++it)
|
for (MagicEffects::Collection::const_iterator it = effects.begin(); it != effects.end(); ++it)
|
||||||
|
{
|
||||||
if (isSummoningEffect(it->first.mId))
|
if (isSummoningEffect(it->first.mId))
|
||||||
|
{
|
||||||
hasSummonEffect = true;
|
hasSummonEffect = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!creatureStats.getSummonedCreatureMap().empty() || !creatureStats.getSummonedCreatureGraveyard().empty() || hasSummonEffect)
|
if (!creatureStats.getSummonedCreatureMap().empty() || !creatureStats.getSummonedCreatureGraveyard().empty() || hasSummonEffect)
|
||||||
{
|
{
|
||||||
|
|
|
@ -387,10 +387,8 @@ namespace MWWorld
|
||||||
void World::write (ESM::ESMWriter& writer, Loading::Listener& progress) const
|
void World::write (ESM::ESMWriter& writer, Loading::Listener& progress) const
|
||||||
{
|
{
|
||||||
// Active cells could have a dirty fog of war, sync it to the CellStore first
|
// Active cells could have a dirty fog of war, sync it to the CellStore first
|
||||||
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
|
||||||
{
|
{
|
||||||
CellStore* cellstore = *iter;
|
|
||||||
MWBase::Environment::get().getWindowManager()->writeFog(cellstore);
|
MWBase::Environment::get().getWindowManager()->writeFog(cellstore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,22 +577,19 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
// first try named cells
|
// first try named cells
|
||||||
const ESM::Cell *cell = mStore.get<ESM::Cell>().searchExtByName (cellName);
|
const ESM::Cell *cell = mStore.get<ESM::Cell>().searchExtByName (cellName);
|
||||||
if (cell != 0) {
|
if (cell)
|
||||||
return cell;
|
return cell;
|
||||||
}
|
|
||||||
|
|
||||||
// didn't work -> now check for regions
|
// didn't work -> now check for regions
|
||||||
const MWWorld::Store<ESM::Region> ®ions = mStore.get<ESM::Region>();
|
for (const ESM::Region ®ion : mStore.get<ESM::Region>())
|
||||||
MWWorld::Store<ESM::Region>::iterator it = regions.begin();
|
|
||||||
for (; it != regions.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (Misc::StringUtils::ciEqual(cellName, it->mName))
|
if (Misc::StringUtils::ciEqual(cellName, region.mName))
|
||||||
{
|
{
|
||||||
return mStore.get<ESM::Cell>().searchExtByRegion(it->mId);
|
return mStore.get<ESM::Cell>().searchExtByRegion(region.mId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Fallback::Map *World::getFallback() const
|
const Fallback::Map *World::getFallback() const
|
||||||
|
@ -703,10 +698,10 @@ namespace MWWorld
|
||||||
if (!cell->getCell()->isExterior() || !cell->getCell()->mName.empty())
|
if (!cell->getCell()->isExterior() || !cell->getCell()->mName.empty())
|
||||||
return cell->getCell()->mName;
|
return cell->getCell()->mName;
|
||||||
|
|
||||||
if (const ESM::Region* region = getStore().get<ESM::Region>().search (cell->getCell()->mRegion))
|
if (const ESM::Region* region = mStore.get<ESM::Region>().search (cell->getCell()->mRegion))
|
||||||
return region->mName;
|
return region->mName;
|
||||||
|
|
||||||
return getStore().get<ESM::GameSetting>().find ("sDefaultCellname")->mValue.getString();
|
return mStore.get<ESM::GameSetting>().find ("sDefaultCellname")->mValue.getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::removeRefScript (MWWorld::RefData *ref)
|
void World::removeRefScript (MWWorld::RefData *ref)
|
||||||
|
@ -725,11 +720,9 @@ namespace MWWorld
|
||||||
|
|
||||||
std::string lowerCaseName = Misc::StringUtils::lowerCase(name);
|
std::string lowerCaseName = Misc::StringUtils::lowerCase(name);
|
||||||
|
|
||||||
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
|
||||||
{
|
{
|
||||||
// TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is in)
|
// TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is in)
|
||||||
CellStore* cellstore = *iter;
|
|
||||||
Ptr ptr = mCells.getPtr (lowerCaseName, *cellstore, false);
|
Ptr ptr = mCells.getPtr (lowerCaseName, *cellstore, false);
|
||||||
|
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
|
@ -743,10 +736,8 @@ namespace MWWorld
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
|
||||||
{
|
{
|
||||||
CellStore* cellstore = *iter;
|
|
||||||
Ptr ptr = cellstore->searchInContainer(lowerCaseName);
|
Ptr ptr = cellstore->searchInContainer(lowerCaseName);
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -803,15 +794,14 @@ namespace MWWorld
|
||||||
if (ptr.getContainerStore() == &player.getClass().getContainerStore(player))
|
if (ptr.getContainerStore() == &player.getClass().getContainerStore(player))
|
||||||
return player;
|
return player;
|
||||||
|
|
||||||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
|
||||||
{
|
{
|
||||||
FindContainerVisitor visitor(ptr);
|
FindContainerVisitor visitor(ptr);
|
||||||
(*cellIt)->forEachType<ESM::Container>(visitor);
|
cellstore->forEachType<ESM::Container>(visitor);
|
||||||
if (visitor.mResult.isEmpty())
|
if (visitor.mResult.isEmpty())
|
||||||
(*cellIt)->forEachType<ESM::Creature>(visitor);
|
cellstore->forEachType<ESM::Creature>(visitor);
|
||||||
if (visitor.mResult.isEmpty())
|
if (visitor.mResult.isEmpty())
|
||||||
(*cellIt)->forEachType<ESM::NPC>(visitor);
|
cellstore->forEachType<ESM::NPC>(visitor);
|
||||||
|
|
||||||
if (!visitor.mResult.isEmpty())
|
if (!visitor.mResult.isEmpty())
|
||||||
return visitor.mResult;
|
return visitor.mResult;
|
||||||
|
@ -1015,7 +1005,7 @@ namespace MWWorld
|
||||||
"sMonthHeartfire", "sMonthFrostfall", "sMonthSunsdusk", "sMonthEveningstar"
|
"sMonthHeartfire", "sMonthFrostfall", "sMonthSunsdusk", "sMonthEveningstar"
|
||||||
};
|
};
|
||||||
|
|
||||||
return getStore().get<ESM::GameSetting>().find (monthNames[month])->mValue.getString();
|
return mStore.get<ESM::GameSetting>().find (monthNames[month])->mValue.getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeStamp World::getTimeStamp() const
|
TimeStamp World::getTimeStamp() const
|
||||||
|
@ -1104,7 +1094,7 @@ namespace MWWorld
|
||||||
if (mActivationDistanceOverride >= 0)
|
if (mActivationDistanceOverride >= 0)
|
||||||
return static_cast<float>(mActivationDistanceOverride);
|
return static_cast<float>(mActivationDistanceOverride);
|
||||||
|
|
||||||
static const int iMaxActivateDist = getStore().get<ESM::GameSetting>().find("iMaxActivateDist")->mValue.getInteger();
|
static const int iMaxActivateDist = mStore.get<ESM::GameSetting>().find("iMaxActivateDist")->mValue.getInteger();
|
||||||
return static_cast<float>(iMaxActivateDist);
|
return static_cast<float>(iMaxActivateDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1876,7 +1866,7 @@ namespace MWWorld
|
||||||
bool swimming = isSwimming(player);
|
bool swimming = isSwimming(player);
|
||||||
bool flying = isFlying(player);
|
bool flying = isFlying(player);
|
||||||
|
|
||||||
static const float i1stPersonSneakDelta = getStore().get<ESM::GameSetting>().find("i1stPersonSneakDelta")->mValue.getFloat();
|
static const float i1stPersonSneakDelta = mStore.get<ESM::GameSetting>().find("i1stPersonSneakDelta")->mValue.getFloat();
|
||||||
if (sneaking && !swimming && !flying)
|
if (sneaking && !swimming && !flying)
|
||||||
mRendering->getCamera()->setSneakOffset(i1stPersonSneakDelta);
|
mRendering->getCamera()->setSneakOffset(i1stPersonSneakDelta);
|
||||||
else
|
else
|
||||||
|
@ -2574,17 +2564,16 @@ namespace MWWorld
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> actors;
|
std::vector<MWWorld::Ptr> actors;
|
||||||
mPhysics->getActorsStandingOn(object, actors);
|
mPhysics->getActorsStandingOn(object, actors);
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); ++it)
|
for (const Ptr &actor : actors)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr actor = *it;
|
|
||||||
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
||||||
if (stats.isDead())
|
if (stats.isDead())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mPhysics->markAsNonSolid (object);
|
mPhysics->markAsNonSolid (object);
|
||||||
|
|
||||||
if (actor == getPlayerPtr() && MWBase::Environment::get().getWorld()->getGodModeState())
|
if (actor == getPlayerPtr() && mGodMode)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
MWMechanics::DynamicStat<float> health = stats.getHealth();
|
MWMechanics::DynamicStat<float> health = stats.getHealth();
|
||||||
health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration());
|
health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration());
|
||||||
|
@ -2606,19 +2595,18 @@ namespace MWWorld
|
||||||
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> actors;
|
std::vector<Ptr> actors;
|
||||||
mPhysics->getActorsCollidingWith(object, actors);
|
mPhysics->getActorsCollidingWith(object, actors);
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); ++it)
|
for (const Ptr &actor : actors)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr actor = *it;
|
|
||||||
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
||||||
if (stats.isDead())
|
if (stats.isDead())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mPhysics->markAsNonSolid (object);
|
mPhysics->markAsNonSolid (object);
|
||||||
|
|
||||||
if (actor == getPlayerPtr() && MWBase::Environment::get().getWorld()->getGodModeState())
|
if (actor == getPlayerPtr() && mGodMode)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
MWMechanics::DynamicStat<float> health = stats.getHealth();
|
MWMechanics::DynamicStat<float> health = stats.getHealth();
|
||||||
health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration());
|
health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration());
|
||||||
|
@ -2688,11 +2676,10 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::getContainersOwnedBy (const MWWorld::ConstPtr& owner, std::vector<MWWorld::Ptr>& out)
|
void World::getContainersOwnedBy (const MWWorld::ConstPtr& owner, std::vector<MWWorld::Ptr>& out)
|
||||||
{
|
{
|
||||||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
|
||||||
{
|
{
|
||||||
GetContainersOwnedByVisitor visitor (owner, out);
|
GetContainersOwnedByVisitor visitor (owner, out);
|
||||||
(*cellIt)->forEachType<ESM::Container>(visitor);
|
cellstore->forEachType<ESM::Container>(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2710,15 +2697,14 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::getItemsOwnedBy (const MWWorld::ConstPtr& npc, std::vector<MWWorld::Ptr>& out)
|
void World::getItemsOwnedBy (const MWWorld::ConstPtr& npc, std::vector<MWWorld::Ptr>& out)
|
||||||
{
|
{
|
||||||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
|
||||||
{
|
{
|
||||||
ListObjectsVisitor visitor;
|
ListObjectsVisitor visitor;
|
||||||
(*cellIt)->forEach(visitor);
|
cellstore->forEach(visitor);
|
||||||
|
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it = visitor.mObjects.begin(); it != visitor.mObjects.end(); ++it)
|
for (const Ptr &object : visitor.mObjects)
|
||||||
if (Misc::StringUtils::ciEqual(it->getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
if (Misc::StringUtils::ciEqual(object.getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
||||||
out.push_back(*it);
|
out.push_back(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2759,28 +2745,21 @@ namespace MWWorld
|
||||||
|
|
||||||
bool World::findInteriorPosition(const std::string &name, ESM::Position &pos)
|
bool World::findInteriorPosition(const std::string &name, ESM::Position &pos)
|
||||||
{
|
{
|
||||||
typedef MWWorld::CellRefList<ESM::Door>::List DoorList;
|
|
||||||
typedef MWWorld::CellRefList<ESM::Static>::List StaticList;
|
|
||||||
|
|
||||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||||
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
|
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
|
||||||
|
|
||||||
MWWorld::CellStore *cellStore = getInterior(name);
|
MWWorld::CellStore *cellStore = getInterior(name);
|
||||||
|
|
||||||
if (0 == cellStore) {
|
if (!cellStore)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const MWWorld::CellRef *> sortedDoors;
|
std::vector<const MWWorld::CellRef *> sortedDoors;
|
||||||
const DoorList &doors = cellStore->getReadOnlyDoors().mList;
|
for (const MWWorld::LiveCellRef<ESM::Door>& door : cellStore->getReadOnlyDoors().mList)
|
||||||
for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (!it->mRef.getTeleport())
|
if (!door.mRef.getTeleport())
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
sortedDoors.push_back(&it->mRef);
|
sortedDoors.push_back(&door.mRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort teleporting doors alphabetically, first by ID, then by destination cell to make search consistent
|
// Sort teleporting doors alphabetically, first by ID, then by destination cell to make search consistent
|
||||||
|
@ -2792,44 +2771,43 @@ namespace MWWorld
|
||||||
return lhs->getDestCell() < rhs->getDestCell();
|
return lhs->getDestCell() < rhs->getDestCell();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (std::vector<const MWWorld::CellRef *>::const_iterator it = sortedDoors.begin(); it != sortedDoors.end(); ++it)
|
for (const MWWorld::CellRef* door : sortedDoors)
|
||||||
{
|
{
|
||||||
MWWorld::CellStore *source = 0;
|
MWWorld::CellStore *source = nullptr;
|
||||||
|
|
||||||
// door to exterior
|
// door to exterior
|
||||||
if ((*it)->getDestCell().empty())
|
if (door->getDestCell().empty())
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
ESM::Position doorDest = (*it)->getDoorDest();
|
ESM::Position doorDest = door->getDoorDest();
|
||||||
positionToIndex(doorDest.pos[0], doorDest.pos[1], x, y);
|
positionToIndex(doorDest.pos[0], doorDest.pos[1], x, y);
|
||||||
source = getExterior(x, y);
|
source = getExterior(x, y);
|
||||||
}
|
}
|
||||||
// door to interior
|
// door to interior
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
source = getInterior((*it)->getDestCell());
|
source = getInterior(door->getDestCell());
|
||||||
}
|
}
|
||||||
if (0 != source)
|
if (source)
|
||||||
{
|
{
|
||||||
// Find door leading to our current teleport door
|
// Find door leading to our current teleport door
|
||||||
// and use its destination to position inside cell.
|
// and use its destination to position inside cell.
|
||||||
const DoorList &destinationDoors = source->getReadOnlyDoors().mList;
|
for (const MWWorld::LiveCellRef<ESM::Door>& destDoor : source->getReadOnlyDoors().mList)
|
||||||
for (DoorList::const_iterator jt = destinationDoors.begin(); jt != destinationDoors.end(); ++jt)
|
|
||||||
{
|
{
|
||||||
if ((*it)->getTeleport() &&
|
if (Misc::StringUtils::ciEqual(name, destDoor.mRef.getDestCell()))
|
||||||
Misc::StringUtils::ciEqual(name, jt->mRef.getDestCell()))
|
|
||||||
{
|
{
|
||||||
/// \note Using _any_ door pointed to the interior,
|
/// \note Using _any_ door pointed to the interior,
|
||||||
/// not the one pointed to current door.
|
/// not the one pointed to current door.
|
||||||
pos = jt->mRef.getDoorDest();
|
pos = destDoor.mRef.getDoorDest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fall back to the first static location.
|
// Fall back to the first static location.
|
||||||
const StaticList &statics = cellStore->getReadOnlyStatics().mList;
|
const MWWorld::CellRefList<ESM::Static>::List &statics = cellStore->getReadOnlyStatics().mList;
|
||||||
if ( statics.begin() != statics.end() ) {
|
if (!statics.empty())
|
||||||
|
{
|
||||||
pos = statics.begin()->mRef.getPosition();
|
pos = statics.begin()->mRef.getPosition();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2924,22 +2902,21 @@ namespace MWWorld
|
||||||
void World::loadContentFiles(const Files::Collections& fileCollections,
|
void World::loadContentFiles(const Files::Collections& fileCollections,
|
||||||
const std::vector<std::string>& content, ContentLoader& contentLoader)
|
const std::vector<std::string>& content, ContentLoader& contentLoader)
|
||||||
{
|
{
|
||||||
std::vector<std::string>::const_iterator it(content.begin());
|
int idx = 0;
|
||||||
std::vector<std::string>::const_iterator end(content.end());
|
for (const std::string &file : content)
|
||||||
for (int idx = 0; it != end; ++it, ++idx)
|
|
||||||
{
|
{
|
||||||
boost::filesystem::path filename(*it);
|
boost::filesystem::path filename(file);
|
||||||
const Files::MultiDirCollection& col = fileCollections.getCollection(filename.extension().string());
|
const Files::MultiDirCollection& col = fileCollections.getCollection(filename.extension().string());
|
||||||
if (col.doesExist(*it))
|
if (col.doesExist(file))
|
||||||
{
|
{
|
||||||
contentLoader.load(col.getPath(*it), idx);
|
contentLoader.load(col.getPath(file), idx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::stringstream msg;
|
std::string message = "Failed loading " + file + ": the content file does not exist";
|
||||||
msg << "Failed loading " << *it << ": the content file does not exist";
|
throw std::runtime_error(message);
|
||||||
throw std::runtime_error(msg.str());
|
|
||||||
}
|
}
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2955,10 +2932,10 @@ namespace MWWorld
|
||||||
|
|
||||||
if (!selectedSpell.empty())
|
if (!selectedSpell.empty())
|
||||||
{
|
{
|
||||||
const ESM::Spell* spell = getStore().get<ESM::Spell>().find(selectedSpell);
|
const ESM::Spell* spell = mStore.get<ESM::Spell>().find(selectedSpell);
|
||||||
|
|
||||||
// Check mana
|
// Check mana
|
||||||
bool godmode = (isPlayer && getGodModeState());
|
bool godmode = (isPlayer && mGodMode);
|
||||||
MWMechanics::DynamicStat<float> magicka = stats.getMagicka();
|
MWMechanics::DynamicStat<float> magicka = stats.getMagicka();
|
||||||
if (magicka.getCurrent() < spell->mData.mCost && !godmode)
|
if (magicka.getCurrent() < spell->mData.mCost && !godmode)
|
||||||
{
|
{
|
||||||
|
@ -2996,7 +2973,7 @@ namespace MWWorld
|
||||||
if (!actor.isEmpty() && actor != MWMechanics::getPlayer() && !manualSpell)
|
if (!actor.isEmpty() && actor != MWMechanics::getPlayer() && !manualSpell)
|
||||||
stats.getAiSequence().getCombatTargets(targetActors);
|
stats.getAiSequence().getCombatTargets(targetActors);
|
||||||
|
|
||||||
const float fCombatDistance = getStore().get<ESM::GameSetting>().find("fCombatDistance")->mValue.getFloat();
|
const float fCombatDistance = mStore.get<ESM::GameSetting>().find("fCombatDistance")->mValue.getFloat();
|
||||||
|
|
||||||
osg::Vec3f hitPosition = actor.getRefData().getPosition().asVec3();
|
osg::Vec3f hitPosition = actor.getRefData().getPosition().asVec3();
|
||||||
|
|
||||||
|
@ -3014,14 +2991,13 @@ namespace MWWorld
|
||||||
// For scripted spells we should not use hit contact
|
// For scripted spells we should not use hit contact
|
||||||
if (manualSpell)
|
if (manualSpell)
|
||||||
{
|
{
|
||||||
// Actors that are targeted by this actor's Follow or Escort packages also side with them
|
|
||||||
if (actor != MWMechanics::getPlayer())
|
if (actor != MWMechanics::getPlayer())
|
||||||
{
|
{
|
||||||
for (std::list<MWMechanics::AiPackage*>::const_iterator it = stats.getAiSequence().begin(); it != stats.getAiSequence().end(); ++it)
|
for (const MWMechanics::AiPackage* package : stats.getAiSequence())
|
||||||
{
|
{
|
||||||
if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdCast)
|
if (package->getTypeId() == MWMechanics::AiPackage::TypeIdCast)
|
||||||
{
|
{
|
||||||
target = (*it)->getTarget();
|
target = package->getTarget();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3079,7 +3055,7 @@ namespace MWWorld
|
||||||
|
|
||||||
if (!selectedSpell.empty())
|
if (!selectedSpell.empty())
|
||||||
{
|
{
|
||||||
const ESM::Spell* spell = getStore().get<ESM::Spell>().find(selectedSpell);
|
const ESM::Spell* spell = mStore.get<ESM::Spell>().find(selectedSpell);
|
||||||
cast.cast(spell);
|
cast.cast(spell);
|
||||||
}
|
}
|
||||||
else if (actor.getClass().hasInventoryStore(actor))
|
else if (actor.getClass().hasInventoryStore(actor))
|
||||||
|
@ -3190,17 +3166,14 @@ namespace MWWorld
|
||||||
while ( !nextCells.empty() ) {
|
while ( !nextCells.empty() ) {
|
||||||
currentCells = nextCells;
|
currentCells = nextCells;
|
||||||
nextCells.clear();
|
nextCells.clear();
|
||||||
for( std::set< std::string >::const_iterator i = currentCells.begin(); i != currentCells.end(); ++i ) {
|
for (const std::string ¤tCell : currentCells)
|
||||||
MWWorld::CellStore *next = getInterior( *i );
|
{
|
||||||
|
MWWorld::CellStore *next = getInterior(currentCell);
|
||||||
if ( !next ) continue;
|
if ( !next ) continue;
|
||||||
|
|
||||||
const MWWorld::CellRefList<ESM::Door>& doors = next->getReadOnlyDoors();
|
|
||||||
const CellRefList<ESM::Door>::List& refList = doors.mList;
|
|
||||||
|
|
||||||
// Check if any door in the cell leads to an exterior directly
|
// Check if any door in the cell leads to an exterior directly
|
||||||
for (CellRefList<ESM::Door>::List::const_iterator it = refList.begin(); it != refList.end(); ++it)
|
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next->getReadOnlyDoors().mList)
|
||||||
{
|
{
|
||||||
const MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
|
||||||
if (!ref.mRef.getTeleport()) continue;
|
if (!ref.mRef.getTeleport()) continue;
|
||||||
|
|
||||||
if (ref.mRef.getDestCell().empty())
|
if (ref.mRef.getDestCell().empty())
|
||||||
|
@ -3217,7 +3190,7 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkedCells.insert( *i );
|
checkedCells.insert(currentCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3243,9 +3216,9 @@ namespace MWWorld
|
||||||
while ( !nextCells.empty() ) {
|
while ( !nextCells.empty() ) {
|
||||||
currentCells = nextCells;
|
currentCells = nextCells;
|
||||||
nextCells.clear();
|
nextCells.clear();
|
||||||
for( std::set< std::string >::const_iterator i = currentCells.begin(); i != currentCells.end(); ++i ) {
|
for (const std::string &cell : currentCells) {
|
||||||
MWWorld::CellStore *next = getInterior( *i );
|
MWWorld::CellStore *next = getInterior(cell);
|
||||||
checkedCells.insert( *i );
|
checkedCells.insert(cell);
|
||||||
if ( !next ) continue;
|
if ( !next ) continue;
|
||||||
|
|
||||||
closestMarker = next->searchConst( id );
|
closestMarker = next->searchConst( id );
|
||||||
|
@ -3254,14 +3227,9 @@ namespace MWWorld
|
||||||
return closestMarker;
|
return closestMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MWWorld::CellRefList<ESM::Door>& doors = next->getReadOnlyDoors();
|
|
||||||
const CellRefList<ESM::Door>::List& doorList = doors.mList;
|
|
||||||
|
|
||||||
// Check if any door in the cell leads to an exterior directly
|
// Check if any door in the cell leads to an exterior directly
|
||||||
for (CellRefList<ESM::Door>::List::const_iterator it = doorList.begin(); it != doorList.end(); ++it)
|
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next->getReadOnlyDoors().mList)
|
||||||
{
|
{
|
||||||
const MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
|
||||||
|
|
||||||
if (!ref.mRef.getTeleport()) continue;
|
if (!ref.mRef.getTeleport()) continue;
|
||||||
|
|
||||||
if (ref.mRef.getDestCell().empty())
|
if (ref.mRef.getDestCell().empty())
|
||||||
|
@ -3287,15 +3255,14 @@ namespace MWWorld
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> markers;
|
std::vector<MWWorld::Ptr> markers;
|
||||||
mCells.getExteriorPtrs(id, markers);
|
mCells.getExteriorPtrs(id, markers);
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it2 = markers.begin(); it2 != markers.end(); ++it2)
|
for (const Ptr& marker : markers)
|
||||||
{
|
{
|
||||||
ESM::Position pos = it2->getRefData().getPosition();
|
osg::Vec3f markerPos = marker.getRefData().getPosition().asVec3();
|
||||||
osg::Vec3f markerPos = pos.asVec3();
|
|
||||||
float distance = (worldPos - markerPos).length2();
|
float distance = (worldPos - markerPos).length2();
|
||||||
if (distance < closestDistance)
|
if (distance < closestDistance)
|
||||||
{
|
{
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
closestMarker = *it2;
|
closestMarker = marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3426,10 +3393,8 @@ namespace MWWorld
|
||||||
|
|
||||||
AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist);
|
AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist);
|
||||||
|
|
||||||
const Scene::CellStoreCollection& active = mWorldScene->getActiveCells();
|
for (CellStore* cellStore : mWorldScene->getActiveCells())
|
||||||
for (Scene::CellStoreCollection::const_iterator it = active.begin(); it != active.end(); ++it)
|
|
||||||
{
|
{
|
||||||
MWWorld::CellStore* cellStore = *it;
|
|
||||||
cellStore->forEach(visitor);
|
cellStore->forEach(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3464,8 +3429,8 @@ namespace MWWorld
|
||||||
int bounty = player.getClass().getNpcStats(player).getBounty();
|
int bounty = player.getClass().getNpcStats(player).getBounty();
|
||||||
int playerGold = player.getClass().getContainerStore(player).count(ContainerStore::sGoldId);
|
int playerGold = player.getClass().getContainerStore(player).count(ContainerStore::sGoldId);
|
||||||
|
|
||||||
float fCrimeGoldDiscountMult = getStore().get<ESM::GameSetting>().find("fCrimeGoldDiscountMult")->mValue.getFloat();
|
static float fCrimeGoldDiscountMult = mStore.get<ESM::GameSetting>().find("fCrimeGoldDiscountMult")->mValue.getFloat();
|
||||||
float fCrimeGoldTurnInMult = getStore().get<ESM::GameSetting>().find("fCrimeGoldTurnInMult")->mValue.getFloat();
|
static float fCrimeGoldTurnInMult = mStore.get<ESM::GameSetting>().find("fCrimeGoldTurnInMult")->mValue.getFloat();
|
||||||
|
|
||||||
int discount = static_cast<int>(bounty * fCrimeGoldDiscountMult);
|
int discount = static_cast<int>(bounty * fCrimeGoldDiscountMult);
|
||||||
int turnIn = static_cast<int>(bounty * fCrimeGoldTurnInMult);
|
int turnIn = static_cast<int>(bounty * fCrimeGoldTurnInMult);
|
||||||
|
@ -3530,7 +3495,7 @@ namespace MWWorld
|
||||||
mPlayer->recordCrimeId();
|
mPlayer->recordCrimeId();
|
||||||
confiscateStolenItems(player);
|
confiscateStolenItems(player);
|
||||||
|
|
||||||
int iDaysinPrisonMod = getStore().get<ESM::GameSetting>().find("iDaysinPrisonMod")->mValue.getInteger();
|
static int iDaysinPrisonMod = mStore.get<ESM::GameSetting>().find("iDaysinPrisonMod")->mValue.getInteger();
|
||||||
mDaysInPrison = std::max(1, bounty / iDaysinPrisonMod);
|
mDaysInPrison = std::max(1, bounty / iDaysinPrisonMod);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -3586,18 +3551,18 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::spawnRandomCreature(const std::string &creatureList)
|
void World::spawnRandomCreature(const std::string &creatureList)
|
||||||
{
|
{
|
||||||
const ESM::CreatureLevList* list = getStore().get<ESM::CreatureLevList>().find(creatureList);
|
const ESM::CreatureLevList* list = mStore.get<ESM::CreatureLevList>().find(creatureList);
|
||||||
|
|
||||||
int iNumberCreatures = getStore().get<ESM::GameSetting>().find("iNumberCreatures")->mValue.getInteger();
|
static int iNumberCreatures = mStore.get<ESM::GameSetting>().find("iNumberCreatures")->mValue.getInteger();
|
||||||
int numCreatures = 1 + Misc::Rng::rollDice(iNumberCreatures); // [1, iNumberCreatures]
|
int numCreatures = 1 + Misc::Rng::rollDice(iNumberCreatures); // [1, iNumberCreatures]
|
||||||
|
|
||||||
for (int i=0; i<numCreatures; ++i)
|
for (int i=0; i<numCreatures; ++i)
|
||||||
{
|
{
|
||||||
std::string selectedCreature = MWMechanics::getLevelledItem(list, true);
|
std::string selectedCreature = MWMechanics::getLevelledItem(list, true);
|
||||||
if (selectedCreature.empty())
|
if (selectedCreature.empty())
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
MWWorld::ManualRef ref(getStore(), selectedCreature, 1);
|
MWWorld::ManualRef ref(mStore, selectedCreature, 1);
|
||||||
|
|
||||||
safePlaceObject(ref.getPtr(), getPlayerPtr(), getPlayerPtr().getCell(), 0, 220.f);
|
safePlaceObject(ref.getPtr(), getPlayerPtr(), getPlayerPtr().getCell(), 0, 220.f);
|
||||||
}
|
}
|
||||||
|
@ -3608,27 +3573,8 @@ namespace MWWorld
|
||||||
if (ptr == getPlayerPtr() && Settings::Manager::getBool("hit fader", "GUI"))
|
if (ptr == getPlayerPtr() && Settings::Manager::getBool("hit fader", "GUI"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int type = ptr.getClass().getBloodTexture(ptr);
|
std::string texture = getFallback()->getFallbackString("Blood_Texture_" + std::to_string(ptr.getClass().getBloodTexture(ptr)));
|
||||||
std::string texture;
|
std::string model = "meshes\\" + getFallback()->getFallbackString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3))); // [0, 2]
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case 2:
|
|
||||||
texture = getFallback()->getFallbackString("Blood_Texture_2");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
texture = getFallback()->getFallbackString("Blood_Texture_1");
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
texture = getFallback()->getFallbackString("Blood_Texture_0");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::stringstream modelName;
|
|
||||||
modelName << "Blood_Model_";
|
|
||||||
int roll = Misc::Rng::rollDice(3); // [0, 2]
|
|
||||||
modelName << roll;
|
|
||||||
std::string model = "meshes\\" + getFallback()->getFallbackString(modelName.str());
|
|
||||||
|
|
||||||
mRendering->spawnEffect(model, texture, worldPosition, 1.0f, false);
|
mRendering->spawnEffect(model, texture, worldPosition, 1.0f, false);
|
||||||
}
|
}
|
||||||
|
@ -3645,7 +3591,7 @@ namespace MWWorld
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = effects.mList.begin();
|
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = effects.mList.begin();
|
||||||
effectIt != effects.mList.end(); ++effectIt)
|
effectIt != effects.mList.end(); ++effectIt)
|
||||||
{
|
{
|
||||||
const ESM::MagicEffect* effect = getStore().get<ESM::MagicEffect>().find(effectIt->mEffectID);
|
const ESM::MagicEffect* effect = mStore.get<ESM::MagicEffect>().find(effectIt->mEffectID);
|
||||||
|
|
||||||
if (effectIt->mRange != rangeType || (effectIt->mArea <= 0 && !ignore.isEmpty() && ignore.getClass().isActor()))
|
if (effectIt->mRange != rangeType || (effectIt->mArea <= 0 && !ignore.isEmpty() && ignore.getClass().isActor()))
|
||||||
continue; // Not right range type, or not area effect and hit an actor
|
continue; // Not right range type, or not area effect and hit an actor
|
||||||
|
@ -3659,9 +3605,9 @@ namespace MWWorld
|
||||||
// Spawn the explosion orb effect
|
// Spawn the explosion orb effect
|
||||||
const ESM::Static* areaStatic;
|
const ESM::Static* areaStatic;
|
||||||
if (!effect->mArea.empty())
|
if (!effect->mArea.empty())
|
||||||
areaStatic = getStore().get<ESM::Static>().find (effect->mArea);
|
areaStatic = mStore.get<ESM::Static>().find (effect->mArea);
|
||||||
else
|
else
|
||||||
areaStatic = getStore().get<ESM::Static>().find ("VFX_DefaultArea");
|
areaStatic = mStore.get<ESM::Static>().find ("VFX_DefaultArea");
|
||||||
|
|
||||||
std::string texture = effect->mParticle;
|
std::string texture = effect->mParticle;
|
||||||
|
|
||||||
|
@ -3689,13 +3635,13 @@ namespace MWWorld
|
||||||
std::vector<MWWorld::Ptr> objects;
|
std::vector<MWWorld::Ptr> objects;
|
||||||
MWBase::Environment::get().getMechanicsManager()->getObjectsInRange(
|
MWBase::Environment::get().getMechanicsManager()->getObjectsInRange(
|
||||||
origin, feetToGameUnits(static_cast<float>(effectIt->mArea)), objects);
|
origin, feetToGameUnits(static_cast<float>(effectIt->mArea)), objects);
|
||||||
for (std::vector<MWWorld::Ptr>::iterator affected = objects.begin(); affected != objects.end(); ++affected)
|
for (const Ptr& affected : objects)
|
||||||
{
|
{
|
||||||
// Ignore actors without collisions here, otherwise it will be possible to hit actors outside processing range.
|
// Ignore actors without collisions here, otherwise it will be possible to hit actors outside processing range.
|
||||||
if (affected->getClass().isActor() && !isActorCollisionEnabled(*affected))
|
if (affected.getClass().isActor() && !isActorCollisionEnabled(affected))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
toApply[*affected].push_back(*effectIt);
|
toApply[affected].push_back(*effectIt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3755,10 +3701,8 @@ namespace MWWorld
|
||||||
};
|
};
|
||||||
void World::resetActors()
|
void World::resetActors()
|
||||||
{
|
{
|
||||||
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
|
||||||
{
|
{
|
||||||
CellStore* cellstore = *iter;
|
|
||||||
ResetActorsVisitor visitor;
|
ResetActorsVisitor visitor;
|
||||||
cellstore->forEach(visitor);
|
cellstore->forEach(visitor);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue