2012-07-03 10:30:50 +00:00
|
|
|
#include "worldimp.hpp"
|
2010-07-02 07:38:22 +00:00
|
|
|
|
2010-07-27 12:05:05 +00:00
|
|
|
#include <components/bsa/bsa_archive.hpp>
|
2011-05-05 17:32:42 +00:00
|
|
|
#include <components/files/collections.hpp>
|
2010-07-02 07:38:22 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-08-11 15:30:55 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-07-27 12:05:05 +00:00
|
|
|
#include "../mwrender/sky.hpp"
|
2011-11-01 17:47:36 +00:00
|
|
|
#include "../mwrender/player.hpp"
|
2010-07-27 12:05:05 +00:00
|
|
|
|
2012-12-23 19:23:24 +00:00
|
|
|
#include "../mwclass/door.hpp"
|
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "player.hpp"
|
2012-05-16 19:27:02 +00:00
|
|
|
#include "manualref.hpp"
|
2011-01-29 13:33:44 +00:00
|
|
|
#include "cellfunctors.hpp"
|
2010-11-06 17:11:09 +00:00
|
|
|
|
2012-02-24 15:12:43 +00:00
|
|
|
using namespace Ogre;
|
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
namespace
|
|
|
|
{
|
2012-11-06 10:03:36 +00:00
|
|
|
/* // NOTE this code is never instantiated (proper copy in localscripts.cpp),
|
|
|
|
// so this commented out to not produce syntactic errors
|
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
template<typename T>
|
2012-10-01 15:17:04 +00:00
|
|
|
void listCellScripts (const MWWorld::ESMStore& store,
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::CellRefList<T>& cellRefList, MWWorld::LocalScripts& localScripts,
|
2010-07-10 11:19:04 +00:00
|
|
|
MWWorld::Ptr::CellStore *cell)
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
for (typename MWWorld::CellRefList<T>::List::iterator iter (
|
2012-11-05 12:07:59 +00:00
|
|
|
cellRefList.mList.begin());
|
|
|
|
iter!=cellRefList.mList.end(); ++iter)
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2012-11-25 13:12:44 +00:00
|
|
|
if (!iter->second.mBase->mScript.empty() && iter->second.mData.getCount())
|
2010-07-02 15:21:27 +00:00
|
|
|
{
|
2012-11-25 13:12:44 +00:00
|
|
|
if (const ESM::Script *script = store.get<ESM::Script>().find (iter->second.mBase->mScript))
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2010-07-02 15:21:27 +00:00
|
|
|
iter->mData.setLocals (*script);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-11-25 13:12:44 +00:00
|
|
|
localScripts.add (iter->second.mBase->mScript, MWWorld::Ptr (&iter->second, cell));
|
2010-07-02 15:21:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-06 10:03:36 +00:00
|
|
|
*/
|
2010-08-03 18:01:52 +00:00
|
|
|
template<typename T>
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<T> *searchViaHandle (const std::string& handle,
|
|
|
|
MWWorld::CellRefList<T>& refList)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
typedef typename MWWorld::CellRefList<T>::List::iterator iterator;
|
2010-08-03 20:06:48 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
for (iterator iter (refList.mList.begin()); iter!=refList.mList.end(); ++iter)
|
2010-08-03 20:06:48 +00:00
|
|
|
{
|
2012-11-17 20:50:25 +00:00
|
|
|
if (iter->second.mData.getCount() > 0 && iter->second.mData.getBaseNode()){
|
|
|
|
if (iter->second.mData.getHandle()==handle)
|
2010-08-03 20:06:48 +00:00
|
|
|
{
|
2012-11-17 20:50:25 +00:00
|
|
|
return &iter->second;
|
2010-08-03 20:06:48 +00:00
|
|
|
}
|
2011-11-19 22:45:05 +00:00
|
|
|
}
|
2010-08-03 20:06:48 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 13:41:20 +00:00
|
|
|
namespace MWWorld
|
2010-07-02 07:38:22 +00:00
|
|
|
{
|
2010-08-03 18:01:52 +00:00
|
|
|
Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell)
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Activator> *ref =
|
2012-11-05 12:07:59 +00:00
|
|
|
searchViaHandle (handle, cell.mActivators))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Potion> *ref = searchViaHandle (handle, cell.mPotions))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Apparatus> *ref = searchViaHandle (handle, cell.mAppas))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Armor> *ref = searchViaHandle (handle, cell.mArmors))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Book> *ref = searchViaHandle (handle, cell.mBooks))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Clothing> *ref = searchViaHandle (handle, cell.mClothes))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-06-29 16:54:23 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Container> *ref =
|
2012-11-05 12:07:59 +00:00
|
|
|
searchViaHandle (handle, cell.mContainers))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-06-29 16:54:23 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2012-11-05 12:07:59 +00:00
|
|
|
searchViaHandle (handle, cell.mCreatures))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Door> *ref = searchViaHandle (handle, cell.mDoors))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-06-29 16:54:23 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Ingredient> *ref =
|
2012-11-05 12:07:59 +00:00
|
|
|
searchViaHandle (handle, cell.mIngreds))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Light> *ref = searchViaHandle (handle, cell.mLights))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Tool> *ref = searchViaHandle (handle, cell.mLockpicks))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = searchViaHandle (handle, cell.mMiscItems))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::NPC> *ref = searchViaHandle (handle, cell.mNpcs))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Probe> *ref = searchViaHandle (handle, cell.mProbes))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Repair> *ref = searchViaHandle (handle, cell.mRepairs))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Static> *ref = searchViaHandle (handle, cell.mStatics))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2012-11-05 12:07:59 +00:00
|
|
|
if (MWWorld::LiveCellRef<ESM::Weapon> *ref = searchViaHandle (handle, cell.mWeapons))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
|
|
|
return Ptr();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
int World::getDaysPerMonth (int month) const
|
|
|
|
{
|
|
|
|
switch (month)
|
|
|
|
{
|
|
|
|
case 0: return 31;
|
|
|
|
case 1: return 28;
|
|
|
|
case 2: return 31;
|
|
|
|
case 3: return 30;
|
|
|
|
case 4: return 31;
|
|
|
|
case 5: return 30;
|
|
|
|
case 6: return 31;
|
|
|
|
case 7: return 31;
|
|
|
|
case 8: return 30;
|
|
|
|
case 9: return 31;
|
|
|
|
case 10: return 30;
|
|
|
|
case 11: return 31;
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
throw std::runtime_error ("month out of range");
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-08-22 18:55:22 +00:00
|
|
|
void World::adjustSky()
|
|
|
|
{
|
2012-02-26 17:21:11 +00:00
|
|
|
if (mSky && (isCellExterior() || isCellQuasiExterior()))
|
2010-08-22 18:55:22 +00:00
|
|
|
{
|
2012-02-24 17:30:16 +00:00
|
|
|
mRendering->skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
|
|
|
mRendering->skySetDate (mGlobalVariables->getInt ("day"),
|
|
|
|
mGlobalVariables->getInt ("month"));
|
2012-02-26 17:21:11 +00:00
|
|
|
|
2012-04-01 13:07:41 +00:00
|
|
|
mRendering->skyEnable();
|
2010-08-22 18:55:22 +00:00
|
|
|
}
|
2012-02-26 17:21:11 +00:00
|
|
|
else
|
2012-04-01 13:07:41 +00:00
|
|
|
mRendering->skyDisable();
|
2010-08-22 18:55:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
void World::setFallbackValues (const std::map<std::string,std::string>& fallbackMap)
|
2012-04-02 18:47:09 +00:00
|
|
|
{
|
2012-04-03 00:14:39 +00:00
|
|
|
mFallback = fallbackMap;
|
2012-04-02 18:47:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
std::string World::getFallback (const std::string& key) const
|
2012-04-04 14:15:15 +00:00
|
|
|
{
|
|
|
|
return getFallback(key, "");
|
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
std::string World::getFallback (const std::string& key, const std::string& def) const
|
2012-04-02 18:47:09 +00:00
|
|
|
{
|
2012-07-02 23:06:38 +00:00
|
|
|
std::map<std::string,std::string>::const_iterator it;
|
2012-04-02 18:47:09 +00:00
|
|
|
if((it = mFallback.find(key)) == mFallback.end())
|
|
|
|
{
|
2012-04-04 14:15:15 +00:00
|
|
|
return def;
|
2012-04-02 18:47:09 +00:00
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2012-01-29 18:51:20 +00:00
|
|
|
World::World (OEngine::Render::OgreRenderer& renderer,
|
2011-05-05 17:32:42 +00:00
|
|
|
const Files::Collections& fileCollections,
|
2012-10-07 18:00:55 +00:00
|
|
|
const std::vector<std::string>& master, const std::vector<std::string>& plugins,
|
|
|
|
const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
2013-01-09 03:52:18 +00:00
|
|
|
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap, int mActivationDistanceOverride)
|
2012-01-29 18:51:20 +00:00
|
|
|
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
2012-11-06 13:51:38 +00:00
|
|
|
mSky (true), mCells (mStore, mEsm),
|
2013-01-09 03:52:18 +00:00
|
|
|
mNumFacing(0), mActivationDistanceOverride (mActivationDistanceOverride)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2012-01-29 15:31:18 +00:00
|
|
|
mPhysics = new PhysicsSystem(renderer);
|
2012-01-29 18:51:20 +00:00
|
|
|
mPhysEngine = mPhysics->getEngine();
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-09-02 17:40:26 +00:00
|
|
|
mRendering = new MWRender::RenderingManager(renderer, resDir, cacheDir, mPhysEngine);
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
mWeatherManager = new MWWorld::WeatherManager(mRendering);
|
2011-05-05 17:32:42 +00:00
|
|
|
|
2012-10-07 18:00:55 +00:00
|
|
|
int idx = 0;
|
2012-11-10 20:43:41 +00:00
|
|
|
// NOTE: We might need to reserve one more for the running game / save.
|
|
|
|
mEsm.resize(master.size() + plugins.size());
|
2012-10-07 18:00:55 +00:00
|
|
|
for (std::vector<std::string>::size_type i = 0; i < master.size(); i++, idx++)
|
|
|
|
{
|
|
|
|
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master[i]));
|
|
|
|
|
|
|
|
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
|
|
|
|
|
|
|
// This parses the ESM file
|
2012-11-10 20:43:41 +00:00
|
|
|
ESM::ESMReader lEsm;
|
2013-01-25 17:22:01 +00:00
|
|
|
lEsm.setEncoder(encoder);
|
2012-11-10 20:43:41 +00:00
|
|
|
lEsm.setIndex(idx);
|
2012-11-16 23:21:51 +00:00
|
|
|
lEsm.setGlobalReaderList(&mEsm);
|
|
|
|
lEsm.open (masterPath.string());
|
2012-11-10 20:43:41 +00:00
|
|
|
mEsm[idx] = lEsm;
|
|
|
|
mStore.load (mEsm[idx]);
|
2012-10-07 18:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (std::vector<std::string>::size_type i = 0; i < plugins.size(); i++, idx++)
|
|
|
|
{
|
|
|
|
boost::filesystem::path pluginPath (fileCollections.getCollection (".esp").getPath (plugins[i]));
|
|
|
|
|
|
|
|
std::cout << "Loading ESP " << pluginPath.string() << "\n";
|
|
|
|
|
|
|
|
// This parses the ESP file
|
2012-11-10 20:43:41 +00:00
|
|
|
ESM::ESMReader lEsm;
|
2013-01-25 17:22:01 +00:00
|
|
|
lEsm.setEncoder(encoder);
|
2012-11-10 20:43:41 +00:00
|
|
|
lEsm.setIndex(idx);
|
2012-11-16 23:21:51 +00:00
|
|
|
lEsm.setGlobalReaderList(&mEsm);
|
|
|
|
lEsm.open (pluginPath.string());
|
2012-11-10 20:43:41 +00:00
|
|
|
mEsm[idx] = lEsm;
|
|
|
|
mStore.load (mEsm[idx]);
|
2012-10-07 18:00:55 +00:00
|
|
|
}
|
2012-11-25 18:07:16 +00:00
|
|
|
|
|
|
|
mStore.setUp();
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-11-06 08:36:21 +00:00
|
|
|
mPlayer = new MWWorld::Player (mStore.get<ESM::NPC>().find ("player"), *this);
|
2012-08-08 20:15:52 +00:00
|
|
|
mRendering->attachCameraTo(mPlayer->getPlayer());
|
|
|
|
|
2012-11-05 18:40:02 +00:00
|
|
|
mPhysics->addActor(mPlayer->getPlayer());
|
2012-12-04 09:58:43 +00:00
|
|
|
|
2010-07-04 11:33:33 +00:00
|
|
|
// global variables
|
2010-07-18 14:48:01 +00:00
|
|
|
mGlobalVariables = new Globals (mStore);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
if (newGame)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2010-07-04 14:00:32 +00:00
|
|
|
// set new game mark
|
2010-07-18 14:48:01 +00:00
|
|
|
mGlobalVariables->setInt ("chargenstate", 1);
|
2010-07-04 14:00:32 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-12-04 09:58:43 +00:00
|
|
|
mGlobalVariables->setInt ("pcrace", 3);
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
mWorldScene = new Scene(*mRendering, mPhysics);
|
2012-04-04 14:08:46 +00:00
|
|
|
|
2012-04-03 00:14:39 +00:00
|
|
|
setFallbackValues(fallbackMap);
|
2011-10-29 07:55:22 +00:00
|
|
|
|
2012-04-30 21:55:22 +00:00
|
|
|
lastTick = mTimer.getMilliseconds();
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-01-29 22:50:51 +00:00
|
|
|
|
2010-07-02 07:38:22 +00:00
|
|
|
World::~World()
|
|
|
|
{
|
2012-02-21 19:22:46 +00:00
|
|
|
delete mWeatherManager;
|
2011-08-09 07:56:09 +00:00
|
|
|
delete mWorldScene;
|
2010-07-18 14:48:01 +00:00
|
|
|
delete mGlobalVariables;
|
2012-01-29 18:51:20 +00:00
|
|
|
delete mRendering;
|
2011-08-01 13:55:36 +00:00
|
|
|
delete mPhysics;
|
2011-10-29 07:55:22 +00:00
|
|
|
|
|
|
|
delete mPlayer;
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|
2011-08-01 12:41:15 +00:00
|
|
|
|
|
|
|
const ESM::Cell *World::getExterior (const std::string& cellName) const
|
|
|
|
{
|
|
|
|
// first try named cells
|
2012-11-06 08:36:21 +00:00
|
|
|
const ESM::Cell *cell = mStore.get<ESM::Cell>().searchExtByName (cellName);
|
|
|
|
if (cell != 0) {
|
2011-08-01 12:41:15 +00:00
|
|
|
return cell;
|
2012-11-06 08:36:21 +00:00
|
|
|
}
|
2011-08-01 12:41:15 +00:00
|
|
|
|
|
|
|
// didn't work -> now check for regions
|
2012-11-06 08:36:21 +00:00
|
|
|
const MWWorld::Store<ESM::Region> ®ions = mStore.get<ESM::Region>();
|
|
|
|
MWWorld::Store<ESM::Region>::iterator it = regions.begin();
|
|
|
|
for (; it != regions.end(); ++it)
|
2011-08-01 12:41:15 +00:00
|
|
|
{
|
2012-12-23 19:23:24 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(cellName, it->mName))
|
2011-08-01 12:41:15 +00:00
|
|
|
{
|
2012-11-06 08:36:21 +00:00
|
|
|
return mStore.get<ESM::Cell>().searchExtByRegion(it->mId);
|
2011-08-01 12:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2011-08-01 12:34:50 +00:00
|
|
|
Ptr::CellStore *World::getExterior (int x, int y)
|
|
|
|
{
|
2011-09-08 09:02:55 +00:00
|
|
|
return mCells.getExterior (x, y);
|
2011-08-01 12:34:50 +00:00
|
|
|
}
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2011-09-08 09:02:55 +00:00
|
|
|
Ptr::CellStore *World::getInterior (const std::string& name)
|
2011-08-01 12:34:50 +00:00
|
|
|
{
|
2011-09-08 09:02:55 +00:00
|
|
|
return mCells.getInterior (name);
|
2011-08-01 12:34:50 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
MWWorld::Player& World::getPlayer()
|
2010-07-02 07:38:22 +00:00
|
|
|
{
|
2011-01-04 14:58:22 +00:00
|
|
|
return *mPlayer;
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
const MWWorld::ESMStore& World::getStore() const
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
|
|
|
return mStore;
|
|
|
|
}
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2012-11-10 20:43:41 +00:00
|
|
|
std::vector<ESM::ESMReader>& World::getEsmReader()
|
2011-07-31 15:07:11 +00:00
|
|
|
{
|
|
|
|
return mEsm;
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-10-06 10:29:59 +00:00
|
|
|
LocalScripts& World::getLocalScripts()
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
|
|
|
return mLocalScripts;
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-03 10:12:13 +00:00
|
|
|
bool World::hasCellChanged() const
|
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
return mWorldScene->hasCellChanged();
|
2010-07-03 10:12:13 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 14:48:01 +00:00
|
|
|
Globals::Data& World::getGlobalVariable (const std::string& name)
|
2010-07-04 11:33:33 +00:00
|
|
|
{
|
2010-07-18 14:48:01 +00:00
|
|
|
return (*mGlobalVariables)[name];
|
2010-07-04 11:33:33 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-04-21 09:00:00 +00:00
|
|
|
Globals::Data World::getGlobalVariable (const std::string& name) const
|
|
|
|
{
|
|
|
|
return (*mGlobalVariables)[name];
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:01:35 +00:00
|
|
|
char World::getGlobalVariableType (const std::string& name) const
|
|
|
|
{
|
|
|
|
return mGlobalVariables->getType (name);
|
2010-08-03 18:01:52 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 23:16:34 +00:00
|
|
|
std::vector<std::string> World::getGlobals () const
|
|
|
|
{
|
|
|
|
return mGlobalVariables->getGlobals();
|
|
|
|
}
|
2012-12-21 18:09:31 +00:00
|
|
|
|
|
|
|
std::string World::getCurrentCellName () const
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
Ptr::CellStore *cell = mWorldScene->getCurrentCell();
|
|
|
|
if (cell->mCell->isExterior())
|
|
|
|
{
|
|
|
|
if (cell->mCell->mName != "")
|
|
|
|
{
|
|
|
|
name = cell->mCell->mName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ESM::Region* region =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(cell->mCell->mRegion);
|
|
|
|
if (region)
|
|
|
|
name = region->mName;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ESM::GameSetting *setting =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
|
|
|
|
|
|
|
|
if (setting && setting->mType == ESM::VT_String)
|
|
|
|
name = setting->getString();
|
|
|
|
else
|
|
|
|
name = "Wilderness";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = cell->mCell->mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2012-12-20 23:16:34 +00:00
|
|
|
|
2013-01-13 17:05:12 +00:00
|
|
|
void World::removeRefScript (MWWorld::RefData *ref)
|
|
|
|
{
|
|
|
|
mLocalScripts.remove (ref);
|
|
|
|
}
|
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
Ptr World::getPtr (const std::string& name, bool activeOnly)
|
2010-07-05 10:09:04 +00:00
|
|
|
{
|
|
|
|
// the player is always in an active cell.
|
|
|
|
if (name=="player")
|
|
|
|
{
|
2011-01-04 14:58:22 +00:00
|
|
|
return mPlayer->getPlayer();
|
2010-07-05 10:09:04 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
// active cells
|
2011-11-16 04:31:18 +00:00
|
|
|
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
2011-08-01 02:06:38 +00:00
|
|
|
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
2010-07-05 10:09:04 +00:00
|
|
|
{
|
2011-11-14 04:14:18 +00:00
|
|
|
Ptr::CellStore* cellstore = *iter;
|
|
|
|
Ptr ptr = mCells.getPtr (name, *cellstore);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
if (!ptr.isEmpty())
|
2010-07-10 11:19:04 +00:00
|
|
|
return ptr;
|
2010-07-05 10:09:04 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
if (!activeOnly)
|
|
|
|
{
|
2011-09-22 10:44:17 +00:00
|
|
|
Ptr ptr = mCells.getPtr (name);
|
|
|
|
|
|
|
|
if (!ptr.isEmpty())
|
|
|
|
return ptr;
|
2010-07-05 10:09:04 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
throw std::runtime_error ("unknown ID: " + name);
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
|
|
|
Ptr World::getPtrViaHandle (const std::string& handle)
|
2012-10-19 17:48:02 +00:00
|
|
|
{
|
|
|
|
Ptr res = searchPtrViaHandle (handle);
|
|
|
|
if (res.isEmpty ())
|
|
|
|
throw std::runtime_error ("unknown Ogre handle: " + handle);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ptr World::searchPtrViaHandle (const std::string& handle)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2011-02-10 12:32:34 +00:00
|
|
|
if (mPlayer->getPlayer().getRefData().getHandle()==handle)
|
|
|
|
return mPlayer->getPlayer();
|
2011-11-16 04:31:18 +00:00
|
|
|
for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
2011-08-01 02:06:38 +00:00
|
|
|
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2011-11-14 04:14:18 +00:00
|
|
|
Ptr::CellStore* cellstore = *iter;
|
|
|
|
Ptr ptr = getPtrViaHandle (handle, *cellstore);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
|
|
|
if (!ptr.isEmpty())
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2012-10-18 20:21:39 +00:00
|
|
|
return MWWorld::Ptr();
|
2010-08-03 18:01:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 16:38:56 +00:00
|
|
|
void World::addContainerScripts(const Ptr& reference, Ptr::CellStore * cell)
|
|
|
|
{
|
|
|
|
if( reference.getTypeName()==typeid (ESM::Container).name() ||
|
|
|
|
reference.getTypeName()==typeid (ESM::NPC).name() ||
|
|
|
|
reference.getTypeName()==typeid (ESM::Creature).name())
|
|
|
|
{
|
|
|
|
MWWorld::ContainerStore& container = MWWorld::Class::get(reference).getContainerStore(reference);
|
|
|
|
for(MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it)
|
|
|
|
{
|
|
|
|
std::string script = MWWorld::Class::get(*it).getScript(*it);
|
|
|
|
if(script != "")
|
|
|
|
{
|
|
|
|
MWWorld::Ptr item = *it;
|
|
|
|
item.mCell = cell;
|
|
|
|
mLocalScripts.add (script, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
void World::enable (const Ptr& reference)
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2010-07-10 11:19:04 +00:00
|
|
|
if (!reference.getRefData().isEnabled())
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2010-07-10 11:19:04 +00:00
|
|
|
reference.getRefData().enable();
|
2013-01-20 15:43:52 +00:00
|
|
|
|
2012-05-25 15:28:27 +00:00
|
|
|
if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
|
|
|
|
mWorldScene->addObjectToScene (reference);
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-20 16:38:56 +00:00
|
|
|
|
|
|
|
void World::removeContainerScripts(const Ptr& reference)
|
|
|
|
{
|
|
|
|
if( reference.getTypeName()==typeid (ESM::Container).name() ||
|
|
|
|
reference.getTypeName()==typeid (ESM::NPC).name() ||
|
|
|
|
reference.getTypeName()==typeid (ESM::Creature).name())
|
|
|
|
{
|
|
|
|
MWWorld::ContainerStore& container = MWWorld::Class::get(reference).getContainerStore(reference);
|
|
|
|
for(MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it)
|
2013-01-20 15:43:52 +00:00
|
|
|
{
|
2013-01-20 16:38:56 +00:00
|
|
|
std::string script = MWWorld::Class::get(*it).getScript(*it);
|
|
|
|
if(script != "")
|
2013-01-20 15:43:52 +00:00
|
|
|
{
|
2013-01-20 16:38:56 +00:00
|
|
|
MWWorld::Ptr item = *it;
|
|
|
|
mLocalScripts.remove (item);
|
2013-01-20 15:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
void World::disable (const Ptr& reference)
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2010-08-07 18:29:10 +00:00
|
|
|
if (reference.getRefData().isEnabled())
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2010-08-07 18:29:10 +00:00
|
|
|
reference.getRefData().disable();
|
2013-01-20 15:43:52 +00:00
|
|
|
|
2012-05-25 15:28:27 +00:00
|
|
|
if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
|
|
|
|
mWorldScene->removeObjectFromScene (reference);
|
2010-08-03 18:01:52 +00:00
|
|
|
}
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
void World::advanceTime (double hours)
|
|
|
|
{
|
2012-09-25 19:28:25 +00:00
|
|
|
mWeatherManager->advanceTime (hours);
|
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
hours += mGlobalVariables->getFloat ("gamehour");
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
setHour (hours);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
int days = hours / 24;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
if (days>0)
|
|
|
|
mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed"));
|
2010-07-18 16:29:16 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
void World::setHour (double hour)
|
|
|
|
{
|
|
|
|
if (hour<0)
|
|
|
|
hour = 0;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
int days = hour / 24;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
hour = std::fmod (hour, 24);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
mGlobalVariables->setFloat ("gamehour", hour);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skySetHour (hour);
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-22 19:12:08 +00:00
|
|
|
mWeatherManager->setHour (hour);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
if (days>0)
|
2010-07-22 09:48:27 +00:00
|
|
|
setDay (days + mGlobalVariables->getInt ("day"));
|
2010-07-18 16:29:16 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
void World::setDay (int day)
|
|
|
|
{
|
2012-11-05 17:01:50 +00:00
|
|
|
if (day<1)
|
|
|
|
day = 1;
|
2010-07-22 09:48:27 +00:00
|
|
|
|
|
|
|
int month = mGlobalVariables->getInt ("month");
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
while (true)
|
2010-07-18 16:29:16 +00:00
|
|
|
{
|
2010-08-03 18:01:52 +00:00
|
|
|
int days = getDaysPerMonth (month);
|
2012-11-05 17:01:50 +00:00
|
|
|
if (day<=days)
|
2010-07-22 09:48:27 +00:00
|
|
|
break;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
if (month<11)
|
|
|
|
{
|
|
|
|
++month;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
month = 0;
|
|
|
|
mGlobalVariables->setInt ("year", mGlobalVariables->getInt ("year")+1);
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
day -= days;
|
2010-08-03 18:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mGlobalVariables->setInt ("day", day);
|
2010-07-22 09:48:27 +00:00
|
|
|
mGlobalVariables->setInt ("month", month);
|
|
|
|
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skySetDate (day, month);
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-22 19:12:08 +00:00
|
|
|
mWeatherManager->setDate (day, month);
|
2010-08-03 18:01:52 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
void World::setMonth (int month)
|
|
|
|
{
|
|
|
|
if (month<0)
|
|
|
|
month = 0;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
int years = month / 12;
|
|
|
|
month = month % 12;
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
int days = getDaysPerMonth (month);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-11-05 17:01:50 +00:00
|
|
|
if (mGlobalVariables->getInt ("day")>days)
|
|
|
|
mGlobalVariables->setInt ("day", days);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
mGlobalVariables->setInt ("month", month);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
if (years>0)
|
|
|
|
mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year"));
|
|
|
|
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skySetDate (mGlobalVariables->getInt ("day"), month);
|
2010-07-22 09:48:27 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2012-09-18 18:53:32 +00:00
|
|
|
int World::getDay()
|
|
|
|
{
|
|
|
|
return mGlobalVariables->getInt("day");
|
|
|
|
}
|
|
|
|
|
|
|
|
int World::getMonth()
|
|
|
|
{
|
|
|
|
return mGlobalVariables->getInt("month");
|
|
|
|
}
|
|
|
|
|
2012-05-19 07:31:45 +00:00
|
|
|
TimeStamp World::getTimeStamp() const
|
|
|
|
{
|
|
|
|
return TimeStamp (mGlobalVariables->getFloat ("gamehour"),
|
|
|
|
mGlobalVariables->getInt ("dayspassed"));
|
|
|
|
}
|
|
|
|
|
2011-04-26 19:38:21 +00:00
|
|
|
bool World::toggleSky()
|
2010-07-18 17:48:02 +00:00
|
|
|
{
|
|
|
|
if (mSky)
|
|
|
|
{
|
|
|
|
mSky = false;
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skyDisable();
|
2011-04-26 19:38:21 +00:00
|
|
|
return false;
|
2010-07-18 17:48:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSky = true;
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skyEnable();
|
2011-04-26 19:38:21 +00:00
|
|
|
return true;
|
2010-07-18 17:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 17:48:02 +00:00
|
|
|
int World::getMasserPhase() const
|
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
return mRendering->skyGetMasserPhase();
|
2010-07-18 17:48:02 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 17:48:02 +00:00
|
|
|
int World::getSecundaPhase() const
|
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
return mRendering->skyGetSecundaPhase();
|
2010-07-18 17:48:02 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-18 17:48:02 +00:00
|
|
|
void World::setMoonColour (bool red)
|
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skySetMoonColour (red);
|
2010-07-18 17:48:02 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-21 12:10:52 +00:00
|
|
|
float World::getTimeScaleFactor() const
|
|
|
|
{
|
2012-03-16 18:02:33 +00:00
|
|
|
return mGlobalVariables->getFloat ("timescale");
|
2010-07-21 12:10:52 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-02-10 09:38:45 +00:00
|
|
|
void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position)
|
2010-07-22 10:29:23 +00:00
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
return mWorldScene->changeToInteriorCell(cellName, position);
|
2010-07-22 10:29:23 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-02-10 09:38:45 +00:00
|
|
|
void World::changeToExteriorCell (const ESM::Position& position)
|
2010-08-20 11:33:03 +00:00
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
return mWorldScene->changeToExteriorCell(position);
|
2010-08-20 11:33:03 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 10:29:23 +00:00
|
|
|
void World::markCellAsUnchanged()
|
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
return mWorldScene->markCellAsUnchanged();
|
2010-07-22 10:29:23 +00:00
|
|
|
}
|
2010-08-05 11:29:49 +00:00
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
float World::getMaxActivationDistance ()
|
2010-08-05 11:29:49 +00:00
|
|
|
{
|
2013-01-09 03:52:18 +00:00
|
|
|
if (mActivationDistanceOverride >= 0)
|
|
|
|
return mActivationDistanceOverride;
|
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
return (std::max) (getNpcActivationDistance (), getObjectActivationDistance ());
|
|
|
|
}
|
|
|
|
|
|
|
|
float World::getNpcActivationDistance ()
|
|
|
|
{
|
2013-01-09 03:52:18 +00:00
|
|
|
if (mActivationDistanceOverride >= 0)
|
|
|
|
return mActivationDistanceOverride;
|
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
return getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt()*5/4;
|
|
|
|
}
|
|
|
|
|
|
|
|
float World::getObjectActivationDistance ()
|
2010-08-05 11:29:49 +00:00
|
|
|
{
|
2013-01-09 03:52:18 +00:00
|
|
|
if (mActivationDistanceOverride >= 0)
|
|
|
|
return mActivationDistanceOverride;
|
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
return getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt();
|
|
|
|
}
|
|
|
|
|
2013-01-08 07:27:37 +00:00
|
|
|
MWWorld::Ptr World::getFacedObject()
|
2010-08-05 11:29:49 +00:00
|
|
|
{
|
2013-01-08 07:27:37 +00:00
|
|
|
std::pair<float, std::string> result;
|
|
|
|
|
2012-03-25 18:52:56 +00:00
|
|
|
if (!mRendering->occlusionQuerySupported())
|
2013-01-08 07:40:17 +00:00
|
|
|
result = mPhysics->getFacedHandle (*this, getMaxActivationDistance ());
|
2013-01-08 07:27:37 +00:00
|
|
|
else
|
|
|
|
result = std::make_pair (mFacedDistance, mFacedHandle);
|
2010-08-05 11:29:49 +00:00
|
|
|
|
2013-01-08 07:27:37 +00:00
|
|
|
if (result.second.empty())
|
|
|
|
return MWWorld::Ptr ();
|
2010-08-05 11:29:49 +00:00
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
MWWorld::Ptr object = searchPtrViaHandle (result.second);
|
|
|
|
|
|
|
|
float ActivationDistance;
|
|
|
|
|
|
|
|
if (object.getTypeName ().find("NPC") != std::string::npos)
|
|
|
|
ActivationDistance = getNpcActivationDistance ();
|
2012-03-25 18:52:56 +00:00
|
|
|
else
|
2013-01-08 07:40:17 +00:00
|
|
|
ActivationDistance = getObjectActivationDistance ();
|
2013-01-08 07:11:15 +00:00
|
|
|
|
2013-01-08 07:27:37 +00:00
|
|
|
if (result.first > ActivationDistance)
|
|
|
|
return MWWorld::Ptr ();
|
|
|
|
|
2013-01-08 07:40:17 +00:00
|
|
|
return object;
|
2010-08-05 11:29:49 +00:00
|
|
|
}
|
2010-08-07 18:25:17 +00:00
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
void World::deleteObject (const Ptr& ptr)
|
2010-08-07 18:25:17 +00:00
|
|
|
{
|
|
|
|
if (ptr.getRefData().getCount()>0)
|
|
|
|
{
|
|
|
|
ptr.getRefData().setCount (0);
|
|
|
|
|
2012-05-25 15:28:27 +00:00
|
|
|
if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end() &&
|
|
|
|
ptr.getRefData().isEnabled())
|
2012-05-24 11:26:07 +00:00
|
|
|
{
|
2012-05-25 15:28:27 +00:00
|
|
|
mWorldScene->removeObjectFromScene (ptr);
|
2012-05-24 11:26:07 +00:00
|
|
|
mLocalScripts.remove (ptr);
|
2013-01-20 17:01:30 +00:00
|
|
|
removeContainerScripts (ptr);
|
2012-05-24 11:26:07 +00:00
|
|
|
}
|
2010-08-07 18:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-21 10:31:04 +00:00
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z)
|
2010-08-21 10:31:04 +00:00
|
|
|
{
|
2012-07-30 19:28:14 +00:00
|
|
|
ESM::Position &pos = ptr.getRefData().getPosition();
|
|
|
|
pos.pos[0] = x, pos.pos[1] = y, pos.pos[2] = z;
|
|
|
|
Ogre::Vector3 vec(x, y, z);
|
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
CellStore *currCell = ptr.getCell();
|
|
|
|
bool isPlayer = ptr == mPlayer->getPlayer();
|
|
|
|
bool haveToMove = mWorldScene->isCellActive(*currCell) || isPlayer;
|
2013-01-20 17:01:30 +00:00
|
|
|
|
|
|
|
removeContainerScripts(ptr);
|
2012-11-07 18:34:28 +00:00
|
|
|
|
2012-11-05 18:40:02 +00:00
|
|
|
if (*currCell != newCell)
|
|
|
|
{
|
|
|
|
if (isPlayer)
|
|
|
|
if (!newCell.isExterior())
|
2012-12-31 07:22:40 +00:00
|
|
|
changeToInteriorCell(Misc::StringUtils::lowerCase(newCell.mCell->mName), pos);
|
2012-11-05 18:40:02 +00:00
|
|
|
else
|
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
int cellX = newCell.mCell->getGridX();
|
|
|
|
int cellY = newCell.mCell->getGridY();
|
2012-08-11 13:01:55 +00:00
|
|
|
mWorldScene->changeCell(cellX, cellY, pos, false);
|
2012-08-08 10:51:33 +00:00
|
|
|
}
|
2012-11-05 18:40:02 +00:00
|
|
|
else {
|
|
|
|
if (!mWorldScene->isCellActive(*currCell))
|
2012-08-08 10:51:33 +00:00
|
|
|
copyObjectToCell(ptr, newCell, pos);
|
2012-11-05 18:40:02 +00:00
|
|
|
else if (!mWorldScene->isCellActive(newCell))
|
|
|
|
{
|
2012-08-08 10:51:33 +00:00
|
|
|
MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
|
|
|
|
mWorldScene->removeObjectFromScene(ptr);
|
|
|
|
mLocalScripts.remove(ptr);
|
|
|
|
haveToMove = false;
|
2012-11-05 18:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-08 10:51:33 +00:00
|
|
|
MWWorld::Ptr copy =
|
|
|
|
MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
|
|
|
|
|
2013-01-20 17:01:30 +00:00
|
|
|
addContainerScripts(copy, &newCell);
|
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
mRendering->moveObjectToCell(copy, vec, currCell);
|
|
|
|
|
2012-11-05 18:40:02 +00:00
|
|
|
if (MWWorld::Class::get(ptr).isActor())
|
|
|
|
{
|
2012-08-11 15:30:55 +00:00
|
|
|
MWBase::MechanicsManager *mechMgr =
|
2012-08-08 10:51:33 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager();
|
|
|
|
|
|
|
|
mechMgr->removeActor(ptr);
|
|
|
|
mechMgr->addActor(copy);
|
2012-11-05 18:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-08 10:51:33 +00:00
|
|
|
std::string script =
|
|
|
|
MWWorld::Class::get(ptr).getScript(ptr);
|
2012-11-05 18:40:02 +00:00
|
|
|
if (!script.empty())
|
|
|
|
{
|
2012-07-30 19:28:14 +00:00
|
|
|
mLocalScripts.remove(ptr);
|
2012-08-08 10:51:33 +00:00
|
|
|
mLocalScripts.add(script, copy);
|
2012-07-30 19:28:14 +00:00
|
|
|
}
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-08 10:51:33 +00:00
|
|
|
ptr.getRefData().setCount(0);
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-05 18:40:02 +00:00
|
|
|
if (haveToMove)
|
|
|
|
{
|
2012-07-30 19:28:14 +00:00
|
|
|
mRendering->moveObject(ptr, vec);
|
2012-11-05 18:40:02 +00:00
|
|
|
mPhysics->moveObject (ptr);
|
2012-07-30 19:28:14 +00:00
|
|
|
}
|
2012-08-08 10:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool World::moveObjectImp(const Ptr& ptr, float x, float y, float z)
|
|
|
|
{
|
|
|
|
CellStore *cell = ptr.getCell();
|
|
|
|
if (cell->isExterior()) {
|
|
|
|
int cellX, cellY;
|
|
|
|
positionToIndex(x, y, cellX, cellY);
|
2012-08-11 15:30:55 +00:00
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
cell = getExterior(cellX, cellY);
|
|
|
|
}
|
|
|
|
moveObject(ptr, *cell, x, y, z);
|
2012-08-11 15:30:55 +00:00
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
return cell != ptr.getCell();
|
2011-08-02 16:50:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
void World::moveObject (const Ptr& ptr, float x, float y, float z)
|
2011-08-02 16:50:31 +00:00
|
|
|
{
|
|
|
|
moveObjectImp(ptr, x, y, z);
|
2010-08-21 10:31:04 +00:00
|
|
|
}
|
2010-08-22 19:30:48 +00:00
|
|
|
|
2012-07-09 16:47:59 +00:00
|
|
|
void World::scaleObject (const Ptr& ptr, float scale)
|
2012-05-25 16:23:06 +00:00
|
|
|
{
|
|
|
|
MWWorld::Class::get(ptr).adjustScale(ptr,scale);
|
2012-09-17 07:37:50 +00:00
|
|
|
ptr.getCellRef().mScale = scale;
|
2012-12-04 09:58:43 +00:00
|
|
|
|
2012-11-05 19:48:07 +00:00
|
|
|
if(ptr.getRefData().getBaseNode() == 0)
|
|
|
|
return;
|
|
|
|
mRendering->scaleObject(ptr, Vector3(scale,scale,scale));
|
2012-11-05 18:40:02 +00:00
|
|
|
mPhysics->scaleObject(ptr);
|
2012-05-25 16:23:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
void World::rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust)
|
2012-05-29 08:15:29 +00:00
|
|
|
{
|
2012-08-11 09:23:54 +00:00
|
|
|
Ogre::Vector3 rot;
|
|
|
|
rot.x = Ogre::Degree(x).valueRadians();
|
|
|
|
rot.y = Ogre::Degree(y).valueRadians();
|
|
|
|
rot.z = Ogre::Degree(z).valueRadians();
|
2012-12-04 09:58:43 +00:00
|
|
|
|
2012-11-05 19:48:07 +00:00
|
|
|
float *objRot = ptr.getRefData().getPosition().rot;
|
|
|
|
if(ptr.getRefData().getBaseNode() == 0 || !mRendering->rotateObject(ptr, rot, adjust))
|
|
|
|
{
|
|
|
|
objRot[0] = (adjust ? objRot[0] + rot.x : rot.x), objRot[1] = (adjust ? objRot[1] + rot.y : rot.y), objRot[2] = (adjust ? objRot[2] + rot.z : rot.z);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-01 21:28:12 +00:00
|
|
|
|
2012-11-05 19:48:07 +00:00
|
|
|
// do this after rendering rotated the object so it gets changed by Class->adjustRotation
|
|
|
|
objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z;
|
|
|
|
mPhysics->rotateObject(ptr);
|
2012-05-29 08:15:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 11:36:48 +00:00
|
|
|
void World::safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos)
|
|
|
|
{
|
|
|
|
copyObjectToCell(ptr,Cell,pos);
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:21:55 +00:00
|
|
|
void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const
|
2010-08-22 19:30:48 +00:00
|
|
|
{
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
|
|
|
x = cellSize * cellX;
|
|
|
|
y = cellSize * cellY;
|
2010-09-11 10:21:55 +00:00
|
|
|
|
|
|
|
if (centre)
|
|
|
|
{
|
|
|
|
x += cellSize/2;
|
|
|
|
y += cellSize/2;
|
|
|
|
}
|
2010-08-22 19:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
|
|
|
{
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
|
|
|
cellX = static_cast<int> (x/cellSize);
|
|
|
|
|
|
|
|
if (x<0)
|
|
|
|
--cellX;
|
|
|
|
|
|
|
|
cellY = static_cast<int> (y/cellSize);
|
|
|
|
|
|
|
|
if (y<0)
|
|
|
|
--cellY;
|
|
|
|
}
|
2011-01-29 16:39:34 +00:00
|
|
|
|
2011-02-01 09:11:41 +00:00
|
|
|
void World::doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors,
|
|
|
|
float duration)
|
2011-01-29 16:39:34 +00:00
|
|
|
{
|
2012-04-30 21:55:22 +00:00
|
|
|
mPhysics->doPhysics(duration, actors);
|
2011-09-03 08:26:31 +00:00
|
|
|
|
2012-04-30 21:55:22 +00:00
|
|
|
const int tick = 16; // 16 ms ^= 60 Hz
|
2011-08-27 08:30:38 +00:00
|
|
|
|
2012-04-30 21:55:22 +00:00
|
|
|
// Game clock part of the loop, contains everything that has to be executed in a fixed timestep
|
|
|
|
long long dt = mTimer.getMilliseconds() - lastTick;
|
2012-05-01 18:51:32 +00:00
|
|
|
if (dt >= 100)
|
|
|
|
{
|
|
|
|
// throw away wall clock time if necessary to keep the framerate above the minimum of 10 fps
|
|
|
|
lastTick += (dt - 100);
|
|
|
|
dt = 100;
|
|
|
|
}
|
2012-04-30 21:55:22 +00:00
|
|
|
while (dt >= tick)
|
2011-08-27 08:30:38 +00:00
|
|
|
{
|
2012-04-30 21:55:22 +00:00
|
|
|
dt -= tick;
|
|
|
|
lastTick += tick;
|
|
|
|
|
|
|
|
std::vector< std::pair<std::string, Ogre::Vector3> > vectors = mPhysics->doPhysicsFixed (actors);
|
|
|
|
|
|
|
|
std::vector< std::pair<std::string, Ogre::Vector3> >::iterator player = vectors.end();
|
|
|
|
|
|
|
|
for (std::vector< std::pair<std::string, Ogre::Vector3> >::iterator it = vectors.begin();
|
|
|
|
it!= vectors.end(); ++it)
|
2011-08-27 08:30:38 +00:00
|
|
|
{
|
2012-04-30 21:55:22 +00:00
|
|
|
if (it->first=="player")
|
|
|
|
{
|
|
|
|
player = it;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPtrViaHandle (it->first);
|
|
|
|
moveObjectImp (ptr, it->second.x, it->second.y, it->second.z);
|
|
|
|
}
|
2011-08-27 08:30:38 +00:00
|
|
|
}
|
2012-04-30 21:55:22 +00:00
|
|
|
|
|
|
|
// Make sure player is moved last (otherwise the cell might change in the middle of an update
|
|
|
|
// loop)
|
|
|
|
if (player!=vectors.end())
|
2011-08-27 08:30:38 +00:00
|
|
|
{
|
2012-04-30 21:55:22 +00:00
|
|
|
if (moveObjectImp (getPtrViaHandle (player->first),
|
|
|
|
player->second.x, player->second.y, player->second.z) == true)
|
|
|
|
return; // abort the current loop if the cell has changed
|
2011-08-27 08:30:38 +00:00
|
|
|
}
|
2011-08-02 16:16:39 +00:00
|
|
|
}
|
2011-01-29 16:39:34 +00:00
|
|
|
}
|
2011-03-13 21:33:55 +00:00
|
|
|
|
2011-04-26 19:38:21 +00:00
|
|
|
bool World::toggleCollisionMode()
|
2011-03-13 21:33:55 +00:00
|
|
|
{
|
2012-02-20 13:07:16 +00:00
|
|
|
return mPhysics->toggleCollisionMode();;
|
2011-03-13 21:33:55 +00:00
|
|
|
}
|
2011-03-16 08:09:45 +00:00
|
|
|
|
2011-04-26 19:38:21 +00:00
|
|
|
bool World::toggleRenderMode (RenderMode mode)
|
2011-03-16 08:09:45 +00:00
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
return mRendering->toggleRenderMode (mode);
|
2011-03-16 08:09:45 +00:00
|
|
|
}
|
2011-07-22 13:56:54 +00:00
|
|
|
|
2012-11-07 21:52:34 +00:00
|
|
|
const ESM::Potion *World::createRecord (const ESM::Potion& record)
|
2011-07-22 13:56:54 +00:00
|
|
|
{
|
2012-12-04 09:58:43 +00:00
|
|
|
return mStore.insert(record);
|
2011-07-22 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 21:52:34 +00:00
|
|
|
const ESM::Class *World::createRecord (const ESM::Class& record)
|
2011-07-22 13:56:54 +00:00
|
|
|
{
|
2012-11-07 21:52:34 +00:00
|
|
|
return mStore.insert(record);
|
2011-07-22 13:56:54 +00:00
|
|
|
}
|
2011-09-26 09:11:30 +00:00
|
|
|
|
2012-11-07 21:52:34 +00:00
|
|
|
const ESM::Spell *World::createRecord (const ESM::Spell& record)
|
2012-10-15 19:54:19 +00:00
|
|
|
{
|
2012-11-07 21:52:34 +00:00
|
|
|
return mStore.insert(record);
|
2012-10-15 19:54:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:11:30 +00:00
|
|
|
const ESM::Cell *World::createRecord (const ESM::Cell& record)
|
|
|
|
{
|
2012-11-06 13:51:38 +00:00
|
|
|
return mStore.insert(record);
|
2011-09-26 09:11:30 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:37:57 +00:00
|
|
|
const ESM::NPC *World::createRecord(const ESM::NPC &record)
|
|
|
|
{
|
2012-11-10 07:51:48 +00:00
|
|
|
bool update = false;
|
2012-12-04 09:58:43 +00:00
|
|
|
|
2012-12-23 19:23:24 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(record.mId, "player"))
|
2012-12-04 09:58:43 +00:00
|
|
|
{
|
|
|
|
static const char *sRaces[] =
|
|
|
|
{
|
|
|
|
"Argonian", "Breton", "Dark Elf", "High Elf", "Imperial", "Khajiit", "Nord", "Orc", "Redguard",
|
|
|
|
"Woodelf", 0
|
|
|
|
};
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
for (; sRaces[i]; ++i)
|
2012-12-23 19:23:24 +00:00
|
|
|
if (Misc::StringUtils::ciEqual (sRaces[i], record.mRace))
|
2012-12-04 09:58:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
mGlobalVariables->setInt ("pcrace", sRaces[i] ? i+1 : 0);
|
|
|
|
|
2012-11-10 07:51:48 +00:00
|
|
|
const ESM::NPC *player =
|
|
|
|
mPlayer->getPlayer().get<ESM::NPC>()->mBase;
|
2011-09-26 09:11:30 +00:00
|
|
|
|
2012-11-10 07:51:48 +00:00
|
|
|
update = record.isMale() != player->isMale() ||
|
2012-12-23 19:23:24 +00:00
|
|
|
!Misc::StringUtils::ciEqual(record.mRace, player->mRace) ||
|
|
|
|
!Misc::StringUtils::ciEqual(record.mHead, player->mHead) ||
|
|
|
|
!Misc::StringUtils::ciEqual(record.mHair, player->mHair);
|
2012-11-10 07:51:48 +00:00
|
|
|
}
|
|
|
|
const ESM::NPC *ret = mStore.insert(record);
|
|
|
|
if (update) {
|
|
|
|
mRendering->renderPlayer(mPlayer->getPlayer());
|
2011-09-26 09:11:30 +00:00
|
|
|
}
|
2012-11-10 07:51:48 +00:00
|
|
|
return ret;
|
2011-09-26 09:11:30 +00:00
|
|
|
}
|
2011-11-21 13:08:44 +00:00
|
|
|
|
|
|
|
void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode,
|
|
|
|
int number)
|
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->playAnimationGroup (ptr, groupName, mode, number);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void World::skipAnimation (const MWWorld::Ptr& ptr)
|
|
|
|
{
|
2012-01-29 18:51:20 +00:00
|
|
|
mRendering->skipAnimation (ptr);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2012-11-03 19:29:55 +00:00
|
|
|
void World::update (float duration, bool paused)
|
2012-01-23 13:33:06 +00:00
|
|
|
{
|
2012-11-03 19:29:55 +00:00
|
|
|
mWorldScene->update (duration, paused);
|
2012-12-04 09:58:43 +00:00
|
|
|
|
2012-08-17 06:10:37 +00:00
|
|
|
float pitch, yaw;
|
|
|
|
Ogre::Vector3 eyepos;
|
|
|
|
mRendering->getPlayerData(eyepos, pitch, yaw);
|
|
|
|
mPhysics->updatePlayerData(eyepos, pitch, yaw);
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-22 18:17:37 +00:00
|
|
|
mWeatherManager->update (duration);
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
performUpdateSceneQueries ();
|
|
|
|
|
|
|
|
updateWindowManager ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::updateWindowManager ()
|
|
|
|
{
|
2012-04-15 15:10:08 +00:00
|
|
|
// inform the GUI about focused object
|
2013-01-08 07:27:37 +00:00
|
|
|
MWWorld::Ptr object = getFacedObject ();
|
2012-05-14 19:37:43 +00:00
|
|
|
|
2012-10-18 20:21:39 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setFocusObject(object);
|
2012-05-14 19:37:43 +00:00
|
|
|
|
2012-10-18 20:21:39 +00:00
|
|
|
// retrieve object dimensions so we know where to place the floating label
|
|
|
|
if (!object.isEmpty ())
|
|
|
|
{
|
2012-05-14 19:37:43 +00:00
|
|
|
Ogre::SceneNode* node = object.getRefData().getBaseNode();
|
|
|
|
Ogre::AxisAlignedBox bounds;
|
|
|
|
int i;
|
|
|
|
for (i=0; i<node->numAttachedObjects(); ++i)
|
|
|
|
{
|
|
|
|
Ogre::MovableObject* ob = node->getAttachedObject(i);
|
|
|
|
bounds.merge(ob->getWorldBoundingBox());
|
|
|
|
}
|
|
|
|
if (bounds.isFinite())
|
|
|
|
{
|
|
|
|
Vector4 screenCoords = mRendering->boundingBoxToScreen(bounds);
|
|
|
|
MWBase::Environment::get().getWindowManager()->setFocusObjectScreenCoords(
|
|
|
|
screenCoords[0], screenCoords[1], screenCoords[2], screenCoords[3]);
|
|
|
|
}
|
2012-04-15 15:10:08 +00:00
|
|
|
}
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
2012-04-15 15:10:08 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
void World::performUpdateSceneQueries ()
|
|
|
|
{
|
2012-03-24 16:59:26 +00:00
|
|
|
if (!mRendering->occlusionQuerySupported())
|
|
|
|
{
|
|
|
|
// cast a ray from player to sun to detect if the sun is visible
|
|
|
|
// this is temporary until we find a better place to put this code
|
|
|
|
// currently its here because we need to access the physics system
|
|
|
|
float* p = mPlayer->getPlayer().getRefData().getPosition().pos;
|
|
|
|
Vector3 sun = mRendering->getSkyManager()->getRealSunPos();
|
|
|
|
sun = Vector3(sun.x, -sun.z, sun.y);
|
|
|
|
mRendering->getSkyManager()->setGlare(!mPhysics->castRay(Ogre::Vector3(p[0], p[1], p[2]), sun));
|
|
|
|
}
|
2012-03-25 18:52:56 +00:00
|
|
|
|
|
|
|
// update faced handle (object the player is looking at)
|
|
|
|
// this uses a mixture of raycasts and occlusion queries.
|
|
|
|
else // if (mRendering->occlusionQuerySupported())
|
|
|
|
{
|
|
|
|
MWRender::OcclusionQuery* query = mRendering->getOcclusionQuery();
|
|
|
|
if (!query->occlusionTestPending())
|
|
|
|
{
|
2013-01-08 06:48:24 +00:00
|
|
|
processFacedQueryResults (query);
|
|
|
|
beginFacedQueryProcess (query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-25 18:52:56 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
void World::processFacedQueryResults (MWRender::OcclusionQuery* query)
|
|
|
|
{
|
|
|
|
// get result of last query
|
|
|
|
if (mNumFacing == 0)
|
|
|
|
{
|
|
|
|
mFacedHandle = "";
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = FLT_MAX;
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
|
|
|
else if (mNumFacing == 1)
|
|
|
|
{
|
|
|
|
bool result = query->getTestResult();
|
|
|
|
mFacedHandle = result ? mFaced1Name : "";
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = result ? mFaced1Distance : FLT_MAX;
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
|
|
|
else if (mNumFacing == 2)
|
|
|
|
{
|
|
|
|
bool result = query->getTestResult();
|
|
|
|
mFacedHandle = result ? mFaced2Name : mFaced1Name;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = result ? mFaced1Distance : mFaced1Distance;
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-25 18:52:56 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
void World::beginFacedQueryProcess (MWRender::OcclusionQuery* query)
|
|
|
|
{
|
|
|
|
// send new query
|
|
|
|
// figure out which object we want to test against
|
|
|
|
std::vector < std::pair < float, std::string > > results;
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
2013-01-08 07:40:17 +00:00
|
|
|
results = mPhysics->getFacedHandles(x, y, getMaxActivationDistance ());
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-08 07:40:17 +00:00
|
|
|
results = mPhysics->getFacedHandles(getMaxActivationDistance ());
|
2013-01-08 06:48:24 +00:00
|
|
|
}
|
2012-03-27 20:36:02 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
// ignore the player and other things we're not interested in
|
|
|
|
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
|
|
|
while (it != results.end())
|
|
|
|
{
|
|
|
|
if ( (*it).second.find("HeightField") != std::string::npos // not interested in terrain
|
|
|
|
|| getPtrViaHandle((*it).second) == mPlayer->getPlayer() ) // not interested in player (unless you want to talk to yourself)
|
|
|
|
{
|
|
|
|
it = results.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
2012-03-25 18:52:56 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
if (results.size() == 0)
|
|
|
|
{
|
|
|
|
mNumFacing = 0;
|
|
|
|
}
|
|
|
|
else if (results.size() == 1)
|
|
|
|
{
|
|
|
|
beginSingleFacedQueryProcess (query, results);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
beginDoubleFacedQueryProcess (query, results);
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 12:22:04 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
void World::beginSingleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
|
|
|
|
{
|
|
|
|
mFaced1 = getPtrViaHandle(results.front().second);
|
|
|
|
mFaced1Name = results.front().second;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFaced1Distance = results.front().first;
|
2013-01-08 06:48:24 +00:00
|
|
|
mNumFacing = 1;
|
2012-04-01 12:53:41 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
btVector3 p;
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
|
|
|
p = mPhysics->getRayPoint(results.front().first, x, y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = mPhysics->getRayPoint(results.front().first);
|
|
|
|
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
|
|
|
Ogre::SceneNode* node = mFaced1.getRefData().getBaseNode();
|
2012-04-01 12:22:04 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
//std::cout << "Num facing 1 : " << mFaced1Name << std::endl;
|
|
|
|
//std::cout << "Type 1 " << mFaced1.getTypeName() << std::endl;
|
2012-04-01 12:22:04 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
query->occlusionTest(pos, node);
|
|
|
|
}
|
2012-04-01 12:22:04 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
void World::beginDoubleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
|
|
|
|
{
|
|
|
|
mFaced1Name = results.at (0).second;
|
|
|
|
mFaced2Name = results.at (1).second;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFaced1Distance = results.at (0).first;
|
|
|
|
mFaced2Distance = results.at (1).first;
|
2013-01-08 06:48:24 +00:00
|
|
|
mFaced1 = getPtrViaHandle(results.at (0).second);
|
|
|
|
mFaced2 = getPtrViaHandle(results.at (1).second);
|
|
|
|
mNumFacing = 2;
|
2012-04-01 12:22:04 +00:00
|
|
|
|
2013-01-08 06:48:24 +00:00
|
|
|
btVector3 p;
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
|
|
|
p = mPhysics->getRayPoint(results.at (1).first, x, y);
|
2012-03-25 18:52:56 +00:00
|
|
|
}
|
2013-01-08 06:48:24 +00:00
|
|
|
else
|
|
|
|
p = mPhysics->getRayPoint(results.at (1).first);
|
|
|
|
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
|
|
|
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
|
|
|
|
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
|
|
|
|
|
|
|
|
// no need to test if the first node is not occluder
|
|
|
|
if (!query->isPotentialOccluder(node1) && (mFaced1.getTypeName().find("Static") == std::string::npos))
|
|
|
|
{
|
|
|
|
mFacedHandle = mFaced1Name;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = mFaced1Distance;
|
2013-01-08 06:48:24 +00:00
|
|
|
//std::cout << "node1 Not an occluder" << std::endl;
|
|
|
|
return;
|
2012-03-25 18:52:56 +00:00
|
|
|
}
|
2013-01-08 06:48:24 +00:00
|
|
|
|
|
|
|
// no need to test if the second object is static (thus cannot be activated)
|
|
|
|
if (mFaced2.getTypeName().find("Static") != std::string::npos)
|
|
|
|
{
|
|
|
|
mFacedHandle = mFaced1Name;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = mFaced1Distance;
|
2013-01-08 06:48:24 +00:00
|
|
|
return;
|
2012-03-25 18:52:56 +00:00
|
|
|
}
|
2013-01-08 06:48:24 +00:00
|
|
|
|
|
|
|
// work around door problems
|
|
|
|
if (mFaced1.getTypeName().find("Static") != std::string::npos
|
|
|
|
&& mFaced2.getTypeName().find("Door") != std::string::npos)
|
|
|
|
{
|
|
|
|
mFacedHandle = mFaced2Name;
|
2013-01-08 07:11:15 +00:00
|
|
|
mFacedDistance = mFaced2Distance;
|
2013-01-08 06:48:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
query->occlusionTest(pos, node2);
|
2012-01-23 13:33:06 +00:00
|
|
|
}
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-23 20:12:06 +00:00
|
|
|
bool World::isCellExterior() const
|
|
|
|
{
|
|
|
|
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
|
|
|
if (currentCell)
|
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
return currentCell->mCell->isExterior();
|
2012-02-23 20:12:06 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-23 20:12:06 +00:00
|
|
|
bool World::isCellQuasiExterior() const
|
|
|
|
{
|
|
|
|
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
|
|
|
if (currentCell)
|
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
if (!(currentCell->mCell->mData.mFlags & ESM::Cell::QuasiEx))
|
2012-02-23 20:12:06 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-25 20:34:38 +00:00
|
|
|
int World::getCurrentWeather() const
|
|
|
|
{
|
|
|
|
return mWeatherManager->getWeatherID();
|
|
|
|
}
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-26 10:51:02 +00:00
|
|
|
void World::changeWeather(const std::string& region, const unsigned int id)
|
|
|
|
{
|
|
|
|
mWeatherManager->changeWeather(region, id);
|
|
|
|
}
|
2012-03-15 15:01:41 +00:00
|
|
|
|
2012-02-18 17:25:28 +00:00
|
|
|
OEngine::Render::Fader* World::getFader()
|
|
|
|
{
|
|
|
|
return mRendering->getFader();
|
|
|
|
}
|
2012-03-29 13:49:24 +00:00
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
Ogre::Vector2 World::getNorthVector (CellStore* cell)
|
2012-03-28 01:15:10 +00:00
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
MWWorld::CellRefList<ESM::Static>& statics = cell->mStatics;
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Static>* ref = statics.find("northmarker");
|
2012-03-28 01:15:10 +00:00
|
|
|
if (!ref)
|
|
|
|
return Vector2(0, 1);
|
|
|
|
Ogre::SceneNode* node = ref->mData.getBaseNode();
|
2012-03-29 15:07:59 +00:00
|
|
|
Vector3 dir = node->_getDerivedOrientation().yAxis();
|
2012-03-28 01:15:10 +00:00
|
|
|
Vector2 d = Vector2(dir.x, dir.z);
|
|
|
|
return d;
|
|
|
|
}
|
2012-03-30 13:31:07 +00:00
|
|
|
|
2012-08-28 15:30:34 +00:00
|
|
|
std::vector<World::DoorMarker> World::getDoorMarkers (CellStore* cell)
|
|
|
|
{
|
|
|
|
std::vector<World::DoorMarker> result;
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
MWWorld::CellRefList<ESM::Door>& doors = cell->mDoors;
|
2012-11-25 16:19:29 +00:00
|
|
|
CellRefList<ESM::Door>::List& refList = doors.mList;
|
|
|
|
for (CellRefList<ESM::Door>::List::iterator it = refList.begin(); it != refList.end(); ++it)
|
2012-08-28 15:30:34 +00:00
|
|
|
{
|
2012-11-17 20:50:25 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door>& ref = it->second;
|
2012-08-28 15:30:34 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (ref.mRef.mTeleport)
|
2012-08-28 15:30:34 +00:00
|
|
|
{
|
|
|
|
World::DoorMarker newMarker;
|
2012-12-23 19:23:24 +00:00
|
|
|
newMarker.name = MWClass::Door::getDestination(ref);
|
2012-08-28 15:30:34 +00:00
|
|
|
|
|
|
|
ESM::Position pos = ref.mData.getPosition ();
|
|
|
|
|
|
|
|
newMarker.x = pos.pos[0];
|
|
|
|
newMarker.y = pos.pos[1];
|
|
|
|
result.push_back(newMarker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::getInteriorMapPosition (Ogre::Vector2 position, float& nX, float& nY, int &x, int& y)
|
|
|
|
{
|
|
|
|
mRendering->getInteriorMapPosition(position, nX, nY, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool World::isPositionExplored (float nX, float nY, int x, int y, bool interior)
|
|
|
|
{
|
|
|
|
return mRendering->isPositionExplored(nX, nY, x, y, interior);
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:49:24 +00:00
|
|
|
void World::setWaterHeight(const float height)
|
|
|
|
{
|
|
|
|
mRendering->setWaterHeight(height);
|
|
|
|
}
|
|
|
|
|
2012-03-29 16:33:08 +00:00
|
|
|
void World::toggleWater()
|
|
|
|
{
|
|
|
|
mRendering->toggleWater();
|
|
|
|
}
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
|
2012-05-14 15:41:17 +00:00
|
|
|
{
|
2012-05-15 14:47:23 +00:00
|
|
|
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
|
|
|
|
|
|
|
|
if (!result.first)
|
|
|
|
return false;
|
|
|
|
|
2012-07-02 23:06:38 +00:00
|
|
|
CellStore* cell;
|
2012-05-15 14:47:23 +00:00
|
|
|
if (isCellExterior())
|
|
|
|
{
|
|
|
|
int cellX, cellY;
|
|
|
|
positionToIndex(result.second[0], -result.second[2], cellX, cellY);
|
|
|
|
cell = mCells.getExterior(cellX, cellY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cell = getPlayer().getPlayer().getCell();
|
|
|
|
|
2012-07-24 08:30:59 +00:00
|
|
|
ESM::Position pos = getPlayer().getPlayer().getRefData().getPosition();
|
2012-05-15 14:47:23 +00:00
|
|
|
pos.pos[0] = result.second[0];
|
|
|
|
pos.pos[1] = -result.second[2];
|
|
|
|
pos.pos[2] = result.second[1];
|
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
copyObjectToCell(object, *cell, pos);
|
2012-07-26 12:14:11 +00:00
|
|
|
object.getRefData().setCount(0);
|
2012-05-15 14:47:23 +00:00
|
|
|
|
|
|
|
return true;
|
2012-05-14 15:41:17 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 14:47:23 +00:00
|
|
|
bool World::canPlaceObject(float cursorX, float cursorY)
|
|
|
|
{
|
|
|
|
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
|
|
|
|
|
|
|
|
/// \todo also check if the wanted position is on a flat surface, and not e.g. against a vertical wall!
|
|
|
|
|
|
|
|
if (!result.first)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-25 06:47:59 +00:00
|
|
|
void
|
2012-08-08 10:51:33 +00:00
|
|
|
World::copyObjectToCell(const Ptr &object, CellStore &cell, const ESM::Position &pos)
|
2012-07-25 06:47:59 +00:00
|
|
|
{
|
2012-07-26 12:14:11 +00:00
|
|
|
/// \todo add searching correct cell for position specified
|
2012-07-25 13:18:17 +00:00
|
|
|
MWWorld::Ptr dropped =
|
2012-07-26 12:14:11 +00:00
|
|
|
MWWorld::Class::get(object).copyToCell(object, cell, pos);
|
|
|
|
|
|
|
|
Ogre::Vector3 min, max;
|
|
|
|
if (mPhysics->getObjectAABB(object, min, max)) {
|
|
|
|
float *pos = dropped.getRefData().getPosition().pos;
|
|
|
|
pos[0] -= (min.x + max.x) / 2;
|
|
|
|
pos[1] -= (min.y + max.y) / 2;
|
|
|
|
pos[2] -= min.z;
|
|
|
|
}
|
2012-07-25 13:18:17 +00:00
|
|
|
|
2012-07-26 12:14:11 +00:00
|
|
|
if (mWorldScene->isCellActive(cell)) {
|
2012-07-26 15:06:48 +00:00
|
|
|
if (dropped.getRefData().isEnabled()) {
|
|
|
|
mWorldScene->addObjectToScene(dropped);
|
|
|
|
}
|
2012-07-26 12:14:11 +00:00
|
|
|
std::string script = MWWorld::Class::get(dropped).getScript(dropped);
|
|
|
|
if (!script.empty()) {
|
|
|
|
mLocalScripts.add(script, dropped);
|
|
|
|
}
|
2013-01-20 17:01:30 +00:00
|
|
|
addContainerScripts(dropped, &cell);
|
2012-07-25 06:47:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 18:53:14 +00:00
|
|
|
void World::dropObjectOnGround (const Ptr& actor, const Ptr& object)
|
2012-05-15 14:47:23 +00:00
|
|
|
{
|
2013-01-09 21:16:45 +00:00
|
|
|
MWWorld::Ptr::CellStore* cell = actor.getCell();
|
2012-05-15 14:47:23 +00:00
|
|
|
|
2012-07-25 16:25:53 +00:00
|
|
|
ESM::Position pos =
|
2013-01-09 21:16:45 +00:00
|
|
|
actor.getRefData().getPosition();
|
2012-05-15 14:47:23 +00:00
|
|
|
|
2012-07-25 16:25:53 +00:00
|
|
|
Ogre::Vector3 orig =
|
|
|
|
Ogre::Vector3(pos.pos[0], pos.pos[1], pos.pos[2]);
|
|
|
|
Ogre::Vector3 dir = Ogre::Vector3(0, 0, -1);
|
2012-08-04 07:34:49 +00:00
|
|
|
|
2012-07-25 16:25:53 +00:00
|
|
|
float len = (pos.pos[2] >= 0) ? pos.pos[2] : -pos.pos[2];
|
|
|
|
len += 100.0;
|
|
|
|
|
|
|
|
std::pair<bool, Ogre::Vector3> hit =
|
|
|
|
mPhysics->castRay(orig, dir, len);
|
|
|
|
pos.pos[2] = hit.second.z;
|
|
|
|
|
2012-08-08 10:51:33 +00:00
|
|
|
copyObjectToCell(object, *cell, pos);
|
2012-07-26 12:14:11 +00:00
|
|
|
object.getRefData().setCount(0);
|
2012-05-15 14:47:23 +00:00
|
|
|
}
|
2012-05-22 23:32:36 +00:00
|
|
|
|
|
|
|
void World::processChangedSettings(const Settings::CategorySettingVector& settings)
|
|
|
|
{
|
|
|
|
mRendering->processChangedSettings(settings);
|
|
|
|
}
|
2012-06-22 10:56:04 +00:00
|
|
|
|
|
|
|
void World::getTriangleBatchCount(unsigned int &triangles, unsigned int &batches)
|
|
|
|
{
|
|
|
|
mRendering->getTriangleBatchCount(triangles, batches);
|
|
|
|
}
|
2012-08-03 10:42:09 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
World::isSwimming(const MWWorld::Ptr &object)
|
|
|
|
{
|
|
|
|
/// \todo add check ifActor() - only actors can swim
|
|
|
|
float *fpos = object.getRefData().getPosition().pos;
|
|
|
|
Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]);
|
|
|
|
|
|
|
|
/// \fixme should rely on object height
|
|
|
|
pos.z += 30;
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return isUnderwater(*object.getCell()->mCell, pos);
|
2012-08-03 10:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
World::isUnderwater(const ESM::Cell &cell, const Ogre::Vector3 &pos)
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
if (!(cell.mData.mFlags & ESM::Cell::HasWater)) {
|
2012-08-03 10:42:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-17 07:37:50 +00:00
|
|
|
return pos.z < cell.mWater;
|
2012-08-03 10:42:09 +00:00
|
|
|
}
|
2012-08-14 16:33:29 +00:00
|
|
|
|
|
|
|
void World::renderPlayer()
|
|
|
|
{
|
|
|
|
mRendering->renderPlayer(mPlayer->getPlayer());
|
|
|
|
}
|
2012-09-12 22:54:32 +00:00
|
|
|
|
2012-09-14 19:12:16 +00:00
|
|
|
void World::setupExternalRendering (MWRender::ExternalRendering& rendering)
|
2012-09-12 22:54:32 +00:00
|
|
|
{
|
2012-09-14 19:12:16 +00:00
|
|
|
mRendering->setupExternalRendering (rendering);
|
2012-09-14 12:34:18 +00:00
|
|
|
}
|
2012-09-18 18:53:32 +00:00
|
|
|
|
2012-09-19 00:53:06 +00:00
|
|
|
int World::canRest ()
|
2012-09-18 18:53:32 +00:00
|
|
|
{
|
|
|
|
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
2012-09-19 00:53:06 +00:00
|
|
|
|
|
|
|
Ogre::Vector3 playerPos;
|
|
|
|
float* pos = mPlayer->getPlayer ().getRefData ().getPosition ().pos;
|
|
|
|
playerPos.x = pos[0];
|
|
|
|
playerPos.y = pos[1];
|
|
|
|
playerPos.z = pos[2];
|
|
|
|
|
|
|
|
std::pair<bool, Ogre::Vector3> hit =
|
|
|
|
mPhysics->castRay(playerPos, Ogre::Vector3(0,0,-1), 50);
|
|
|
|
bool isOnGround = (hit.first ? (hit.second.distance (playerPos) < 25) : false);
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (!isOnGround || isUnderwater (*currentCell->mCell, playerPos))
|
2012-09-19 00:53:06 +00:00
|
|
|
return 2;
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (currentCell->mCell->mData.mFlags & ESM::Cell::NoSleep)
|
2012-09-19 00:53:06 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-09-18 18:53:32 +00:00
|
|
|
}
|
2012-09-25 00:35:50 +00:00
|
|
|
|
2013-01-07 12:19:52 +00:00
|
|
|
void World::playVideo (const std::string &name, bool allowSkipping)
|
2012-09-25 00:35:50 +00:00
|
|
|
{
|
2013-01-07 12:19:52 +00:00
|
|
|
mRendering->playVideo(name, allowSkipping);
|
2012-09-25 00:35:50 +00:00
|
|
|
}
|
2012-12-12 00:13:53 +00:00
|
|
|
|
|
|
|
void World::stopVideo ()
|
|
|
|
{
|
|
|
|
mRendering->stopVideo();
|
|
|
|
}
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|