2010-07-02 07:38:22 +00:00
|
|
|
#include "world.hpp"
|
|
|
|
|
2010-07-18 16:29:16 +00:00
|
|
|
#include <cmath>
|
2010-07-03 13:04:00 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
2010-07-02 07:38:22 +00:00
|
|
|
|
2010-08-14 07:29:38 +00:00
|
|
|
#include "../mwsound/soundmanager.hpp"
|
|
|
|
|
2010-07-09 14:07:03 +00:00
|
|
|
#include "ptr.hpp"
|
2010-07-27 12:05:05 +00:00
|
|
|
#include "environment.hpp"
|
2010-08-14 09:27:13 +00:00
|
|
|
#include "class.hpp"
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "player.hpp"
|
2010-11-06 17:11:09 +00:00
|
|
|
|
|
|
|
#include "refdata.hpp"
|
|
|
|
#include "globals.hpp"
|
2011-01-29 13:33:44 +00:00
|
|
|
#include "cellfunctors.hpp"
|
2010-11-06 17:11:09 +00:00
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template<typename T>
|
2010-07-02 15:21:27 +00:00
|
|
|
void listCellScripts (const ESMS::ESMStore& store,
|
2011-10-06 10:29:59 +00:00
|
|
|
ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, MWWorld::LocalScripts& localScripts,
|
2010-07-10 11:19:04 +00:00
|
|
|
MWWorld::Ptr::CellStore *cell)
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2010-07-03 13:41:20 +00:00
|
|
|
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
2010-07-02 14:18:25 +00:00
|
|
|
cellRefList.list.begin());
|
|
|
|
iter!=cellRefList.list.end(); ++iter)
|
|
|
|
{
|
2010-08-04 12:04:22 +00:00
|
|
|
if (!iter->base->script.empty() && iter->mData.getCount())
|
2010-07-02 15:21:27 +00:00
|
|
|
{
|
|
|
|
if (const ESM::Script *script = store.scripts.find (iter->base->script))
|
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
|
|
|
|
2011-10-06 10:29:59 +00:00
|
|
|
localScripts.add (iter->base->script, MWWorld::Ptr (&*iter, cell));
|
2010-07-02 15:21:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
ESMS::LiveCellRef<T, MWWorld::RefData> *searchViaHandle (const std::string& handle,
|
|
|
|
ESMS::CellRefList<T, MWWorld::RefData>& refList)
|
|
|
|
{
|
2010-08-03 20:06:48 +00:00
|
|
|
typedef typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iterator;
|
|
|
|
|
|
|
|
for (iterator iter (refList.list.begin()); iter!=refList.list.end(); ++iter)
|
|
|
|
{
|
2011-11-19 22:45:05 +00:00
|
|
|
if(iter->mData.getBaseNode()){
|
2010-08-03 20:06:48 +00:00
|
|
|
if (iter->mData.getHandle()==handle)
|
|
|
|
{
|
|
|
|
return &*iter;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref =
|
|
|
|
searchViaHandle (handle, cell.activators))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = searchViaHandle (handle, cell.potions))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = searchViaHandle (handle, cell.appas))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = searchViaHandle (handle, cell.armors))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = searchViaHandle (handle, cell.books))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = searchViaHandle (handle, cell.clothes))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref =
|
|
|
|
searchViaHandle (handle, cell.containers))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref =
|
|
|
|
searchViaHandle (handle, cell.creatures))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = searchViaHandle (handle, cell.doors))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref =
|
|
|
|
searchViaHandle (handle, cell.ingreds))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = searchViaHandle (handle, cell.lights))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = searchViaHandle (handle, cell.lockpicks))
|
|
|
|
return Ptr (ref, &cell);
|
2011-06-19 16:14:03 +00:00
|
|
|
if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = searchViaHandle (handle, cell.miscItems))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = searchViaHandle (handle, cell.npcs))
|
|
|
|
return Ptr (ref, &cell);
|
2010-08-03 19:43:05 +00:00
|
|
|
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = searchViaHandle (handle, cell.probes))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
2010-08-03 19:43:05 +00:00
|
|
|
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = searchViaHandle (handle, cell.repairs))
|
2010-08-03 18:01:52 +00:00
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = searchViaHandle (handle, cell.statics))
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = searchViaHandle (handle, cell.weapons))
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (mSky)
|
|
|
|
{
|
|
|
|
toggleSky();
|
|
|
|
// TODO set weather
|
|
|
|
toggleSky();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 17:32:42 +00:00
|
|
|
World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng,
|
|
|
|
const Files::Collections& fileCollections,
|
2011-02-10 09:38:45 +00:00
|
|
|
const std::string& master, const boost::filesystem::path& resDir,
|
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
|
|
|
bool newGame, Environment& environment, const std::string& encoding)
|
2011-12-09 05:08:30 +00:00
|
|
|
: mRendering (renderer,resDir, physEng, environment),mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
2011-09-27 08:08:07 +00:00
|
|
|
mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this)
|
2010-08-03 18:01:52 +00:00
|
|
|
{
|
2011-04-01 21:35:56 +00:00
|
|
|
mPhysEngine = physEng;
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2011-08-01 13:55:36 +00:00
|
|
|
mPhysics = new PhysicsSystem(renderer, physEng);
|
2011-05-05 17:32:42 +00:00
|
|
|
|
|
|
|
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master));
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-02 07:38:22 +00:00
|
|
|
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
|
|
|
|
|
|
|
// This parses the ESM file and loads a sample cell
|
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
|
|
|
mEsm.setEncoding(encoding);
|
2011-03-28 15:36:05 +00:00
|
|
|
mEsm.open (masterPath.string());
|
2010-07-02 07:38:22 +00:00
|
|
|
mStore.load (mEsm);
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-11-21 11:52:28 +00:00
|
|
|
MWRender::Player* play = &(mRendering.getPlayer());
|
2011-11-01 17:47:36 +00:00
|
|
|
mPlayer = new MWWorld::Player (play, mStore.npcs.find ("player"), *this);
|
2011-08-01 13:55:36 +00:00
|
|
|
mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0));
|
2010-07-05 10:09:04 +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
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
mPhysEngine = physEng;
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2011-11-16 04:31:18 +00:00
|
|
|
mWorldScene = new Scene(environment, this, mRendering, mPhysics);
|
2011-10-29 07:55:22 +00:00
|
|
|
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-02 07:38:22 +00:00
|
|
|
World::~World()
|
|
|
|
{
|
2011-08-09 07:56:09 +00:00
|
|
|
delete mWorldScene;
|
2010-07-18 14:48:01 +00:00
|
|
|
delete mGlobalVariables;
|
2011-10-29 07:55:22 +00:00
|
|
|
|
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
|
|
|
|
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
|
|
|
|
return cell;
|
|
|
|
|
|
|
|
// didn't work -> now check for regions
|
|
|
|
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
|
|
|
|
|
|
|
|
for (ESMS::RecListT<ESM::Region>::MapType::const_iterator iter (mStore.regions.list.begin());
|
|
|
|
iter!=mStore.regions.list.end(); ++iter)
|
|
|
|
{
|
|
|
|
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
|
|
|
|
{
|
|
|
|
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
|
|
|
|
return cell;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-04-21 08:49:45 +00:00
|
|
|
const ESMS::ESMStore& World::getStore() const
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
|
|
|
return mStore;
|
|
|
|
}
|
2011-08-09 07:56:09 +00:00
|
|
|
|
2011-07-31 15:07:11 +00:00
|
|
|
ESM::ESMReader& World::getEsmReader()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown Ogre handle: " + handle);
|
|
|
|
}
|
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
void World::enable (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();
|
2010-08-03 18:01:52 +00:00
|
|
|
|
|
|
|
|
2011-11-14 04:14:18 +00:00
|
|
|
//render->enable (reference.getRefData().getHandle());
|
2011-11-16 04:31:18 +00:00
|
|
|
if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end())
|
|
|
|
Class::get (reference).enable (reference, mEnvironment);
|
2011-11-21 11:52:28 +00:00
|
|
|
|
|
|
|
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
void World::disable (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();
|
2010-08-03 18:01:52 +00:00
|
|
|
|
|
|
|
|
2011-11-14 04:14:18 +00:00
|
|
|
//render->disable (reference.getRefData().getHandle());
|
2011-11-16 04:31:18 +00:00
|
|
|
if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()){
|
|
|
|
Class::get (reference).disable (reference, mEnvironment);
|
|
|
|
mEnvironment.mSoundManager->stopSound3D (reference);
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
2011-11-21 11:52:28 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
hours += mGlobalVariables->getFloat ("gamehour");
|
2011-12-27 00:23:46 +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"));
|
2011-12-27 00:23:46 +00:00
|
|
|
mWorldScene->advanceTime();
|
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
|
|
|
|
2011-10-24 17:42:36 +00:00
|
|
|
mRendering.skySetHour (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)
|
|
|
|
{
|
|
|
|
if (day<0)
|
|
|
|
day = 0;
|
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);
|
2010-07-22 09:48:27 +00:00
|
|
|
if (day<days)
|
|
|
|
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);
|
|
|
|
|
2011-10-24 17:42:36 +00:00
|
|
|
mRendering.skySetDate (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
|
|
|
|
2010-07-22 09:48:27 +00:00
|
|
|
if (mGlobalVariables->getInt ("day")>=days)
|
|
|
|
mGlobalVariables->setInt ("day", days-1);
|
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"));
|
|
|
|
|
2011-10-24 17:42:36 +00:00
|
|
|
mRendering.skySetDate (mGlobalVariables->getInt ("day"), month);
|
2010-07-22 09:48:27 +00:00
|
|
|
}
|
2010-08-03 18:01:52 +00:00
|
|
|
|
2011-04-26 19:38:21 +00:00
|
|
|
bool World::toggleSky()
|
2010-07-18 17:48:02 +00:00
|
|
|
{
|
|
|
|
if (mSky)
|
|
|
|
{
|
|
|
|
mSky = false;
|
2011-10-24 17:42:36 +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;
|
|
|
|
// TODO check for extorior or interior with sky.
|
2011-10-24 17:42:36 +00:00
|
|
|
mRendering.skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
|
|
|
mRendering.skySetDate (mGlobalVariables->getInt ("day"),
|
2010-07-22 09:48:27 +00:00
|
|
|
mGlobalVariables->getInt ("month"));
|
2011-10-24 17:42:36 +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
|
|
|
|
{
|
2011-10-24 17:42:36 +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
|
|
|
|
{
|
2011-10-24 17:42:36 +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)
|
|
|
|
{
|
2011-10-24 17:42:36 +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
|
|
|
|
{
|
|
|
|
return mGlobalVariables->getInt ("timescale");
|
|
|
|
}
|
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
|
|
|
|
|
|
|
std::string World::getFacedHandle()
|
|
|
|
{
|
2011-10-24 17:42:36 +00:00
|
|
|
std::pair<std::string, float> result = mPhysics->getFacedHandle (*this);
|
2010-08-05 11:29:49 +00:00
|
|
|
|
|
|
|
if (result.first.empty() ||
|
|
|
|
result.second>getStore().gameSettings.find ("iMaxActivateDist")->i)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return result.first;
|
|
|
|
}
|
2010-08-07 18:25:17 +00:00
|
|
|
|
|
|
|
void World::deleteObject (Ptr ptr)
|
|
|
|
{
|
|
|
|
if (ptr.getRefData().getCount()>0)
|
|
|
|
{
|
|
|
|
ptr.getRefData().setCount (0);
|
|
|
|
|
2011-01-27 08:46:54 +00:00
|
|
|
|
2011-11-16 04:31:18 +00:00
|
|
|
if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end()){
|
2011-11-21 11:52:28 +00:00
|
|
|
// Class::get (ptr).disable (ptr, mEnvironment); /// \todo this line needs to be removed
|
2011-11-14 04:14:18 +00:00
|
|
|
mEnvironment.mSoundManager->stopSound3D (ptr);
|
2011-09-29 07:02:06 +00:00
|
|
|
|
2011-11-14 04:14:18 +00:00
|
|
|
mPhysics->removeObject (ptr.getRefData().getHandle());
|
2011-11-16 04:31:18 +00:00
|
|
|
mRendering.removeObject(ptr);
|
2011-01-27 08:46:54 +00:00
|
|
|
|
2011-11-14 04:14:18 +00:00
|
|
|
mLocalScripts.remove (ptr);
|
2010-08-14 09:39:32 +00:00
|
|
|
}
|
2010-08-07 18:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-21 10:31:04 +00:00
|
|
|
|
2011-08-02 16:50:31 +00:00
|
|
|
void World::moveObjectImp (Ptr ptr, float x, float y, float z)
|
2010-08-21 10:31:04 +00:00
|
|
|
{
|
2011-11-08 00:08:00 +00:00
|
|
|
ptr.getRefData().getPosition().pos[0] = x;
|
|
|
|
ptr.getRefData().getPosition().pos[1] = y;
|
|
|
|
ptr.getRefData().getPosition().pos[2] = z;
|
2010-08-21 10:31:04 +00:00
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
if (ptr==mPlayer->getPlayer())
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
|
|
|
if (currentCell)
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
2011-08-01 02:06:38 +00:00
|
|
|
if (!(currentCell->cell->data.flags & ESM::Cell::Interior))
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
|
|
|
// exterior -> adjust loaded cells
|
2010-08-22 19:30:48 +00:00
|
|
|
int cellX = 0;
|
|
|
|
int cellY = 0;
|
2010-08-21 10:41:59 +00:00
|
|
|
|
2010-08-22 19:30:48 +00:00
|
|
|
positionToIndex (x, y, cellX, cellY);
|
2010-08-21 10:41:59 +00:00
|
|
|
|
2011-08-01 02:06:38 +00:00
|
|
|
if (currentCell->cell->data.gridX!=cellX || currentCell->cell->data.gridY!=cellY)
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
2011-11-08 00:08:00 +00:00
|
|
|
mWorldScene->changeCell (cellX, cellY, mPlayer->getPlayer().getRefData().getPosition(), false);
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|
2011-01-29 13:33:44 +00:00
|
|
|
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-27 08:30:38 +00:00
|
|
|
|
2011-11-21 11:52:28 +00:00
|
|
|
/// \todo cell change for non-player ref
|
2011-08-27 08:30:38 +00:00
|
|
|
|
2011-11-21 11:52:28 +00:00
|
|
|
mRendering.moveObject (ptr, Ogre::Vector3 (x, y, z));
|
2011-08-02 16:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void World::moveObject (Ptr ptr, float x, float y, float z)
|
|
|
|
{
|
|
|
|
moveObjectImp(ptr, x, y, z);
|
2010-08-21 10:41:59 +00:00
|
|
|
|
2011-09-04 07:48:50 +00:00
|
|
|
mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z));
|
2010-08-21 10:31:04 +00:00
|
|
|
}
|
2010-08-22 19:30:48 +00:00
|
|
|
|
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
|
|
|
{
|
2011-08-02 16:44:10 +00:00
|
|
|
std::vector< std::pair<std::string, Ogre::Vector3> > vectors = mPhysics->doPhysics (duration, actors);
|
2011-09-03 08:26:31 +00:00
|
|
|
|
2011-08-27 08:30:38 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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-02 16:16:39 +00:00
|
|
|
}
|
2011-08-27 08:30:38 +00:00
|
|
|
|
|
|
|
// Make sure player is moved last (otherwise the cell might change in the middle of an update
|
|
|
|
// loop)
|
|
|
|
if (player!=vectors.end())
|
|
|
|
moveObjectImp (getPtrViaHandle (player->first),
|
|
|
|
player->second.x, player->second.y, player->second.z);
|
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
|
|
|
{
|
2011-09-04 07:48:50 +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
|
|
|
{
|
2011-10-30 04:25:29 +00:00
|
|
|
return mRendering.toggleRenderMode (mode);
|
2011-03-16 08:09:45 +00:00
|
|
|
}
|
2011-07-22 13:56:54 +00:00
|
|
|
|
|
|
|
std::pair<std::string, const ESM::Potion *> World::createRecord (const ESM::Potion& record)
|
|
|
|
{
|
|
|
|
/// \todo Rewrite the ESMStore so that a dynamic 2nd ESMStore can be attached to it.
|
|
|
|
/// This function should then insert the record into the 2nd store (the code for this
|
|
|
|
/// should also be moved to the ESMStore class). It might be a good idea to review
|
|
|
|
/// the STL-container usage of the ESMStore before the rewrite.
|
|
|
|
|
|
|
|
std::ostringstream stream;
|
2011-07-23 09:56:01 +00:00
|
|
|
stream << "$dynamic" << mNextDynamicRecord++;
|
2011-07-22 13:56:54 +00:00
|
|
|
|
|
|
|
const ESM::Potion *created =
|
|
|
|
&mStore.potions.list.insert (std::make_pair (stream.str(), record)).first->second;
|
|
|
|
|
|
|
|
mStore.all.insert (std::make_pair (stream.str(), ESM::REC_ALCH));
|
|
|
|
|
|
|
|
return std::make_pair (stream.str(), created);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<std::string, const ESM::Class *> World::createRecord (const ESM::Class& record)
|
|
|
|
{
|
|
|
|
/// \todo See function above.
|
|
|
|
std::ostringstream stream;
|
2011-07-23 09:56:01 +00:00
|
|
|
stream << "$dynamic" << mNextDynamicRecord++;
|
2011-07-22 13:56:54 +00:00
|
|
|
|
|
|
|
const ESM::Class *created =
|
|
|
|
&mStore.classes.list.insert (std::make_pair (stream.str(), record)).first->second;
|
|
|
|
|
|
|
|
mStore.all.insert (std::make_pair (stream.str(), ESM::REC_CLAS));
|
|
|
|
|
|
|
|
return std::make_pair (stream.str(), created);
|
|
|
|
}
|
2011-09-26 09:11:30 +00:00
|
|
|
|
|
|
|
const ESM::Cell *World::createRecord (const ESM::Cell& record)
|
|
|
|
{
|
|
|
|
if (record.data.flags & ESM::Cell::Interior)
|
|
|
|
{
|
|
|
|
if (mStore.cells.searchInt (record.name))
|
|
|
|
throw std::runtime_error ("failed creating interior cell");
|
|
|
|
|
|
|
|
ESM::Cell *cell = new ESM::Cell (record);
|
|
|
|
mStore.cells.intCells.insert (std::make_pair (record.name, cell));
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mStore.cells.searchExt (record.data.gridX, record.data.gridY))
|
|
|
|
throw std::runtime_error ("failed creating exterior cell");
|
|
|
|
|
|
|
|
ESM::Cell *cell = new ESM::Cell (record);
|
|
|
|
mStore.cells.extCells.insert (
|
|
|
|
std::make_pair (std::make_pair (record.data.gridX, record.data.gridY), cell));
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 13:08:44 +00:00
|
|
|
|
|
|
|
void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode,
|
|
|
|
int number)
|
|
|
|
{
|
|
|
|
mRendering.playAnimationGroup (ptr, groupName, mode, number);
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::skipAnimation (const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
mRendering.skipAnimation (ptr);
|
|
|
|
}
|
2012-01-05 00:47:06 +00:00
|
|
|
void World::setObjectPhysicsRotation(const std::string& handle, Ogre::Quaternion quat){
|
|
|
|
mPhysics->rotateObject(handle, quat);
|
|
|
|
}
|
|
|
|
void World::setObjectPhysicsPosition(const std::string& handle, Ogre::Vector3 vec){
|
|
|
|
mPhysics->moveObject(handle, vec);
|
|
|
|
}
|
2010-07-02 07:38:22 +00:00
|
|
|
}
|