|
|
|
@ -28,9 +28,9 @@ namespace
|
|
|
|
|
if (!iter->base->script.empty())
|
|
|
|
|
{
|
|
|
|
|
if (const ESM::Script *script = store.scripts.find (iter->base->script))
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
iter->mData.setLocals (*script);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scriptList.push_back (
|
|
|
|
|
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell)));
|
|
|
|
|
}
|
|
|
|
@ -61,7 +61,7 @@ namespace MWWorld
|
|
|
|
|
listCellScripts (mStore, cell.repairs, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mStore, cell.weapons, mLocalScripts, &cell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell)
|
|
|
|
|
{
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
|
|
|
@ -69,68 +69,68 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Misc, RefData> *ref = cell.miscItems.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.probes.find (name))
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = cell.probes.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.repairs.find (name))
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = cell.repairs.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ptr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWRender::CellRender *World::searchRender (Ptr::CellStore *store)
|
|
|
|
|
{
|
|
|
|
|
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (iter!=mActiveCells.end())
|
|
|
|
|
{
|
|
|
|
|
return iter->second;
|
|
|
|
@ -141,10 +141,10 @@ namespace MWWorld
|
|
|
|
|
if (iter!=mBufferedCells.end())
|
|
|
|
|
return iter->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int World::getDaysPerMonth (int month) const
|
|
|
|
|
{
|
|
|
|
|
switch (month)
|
|
|
|
@ -162,84 +162,84 @@ namespace MWWorld
|
|
|
|
|
case 10: return 30;
|
|
|
|
|
case 11: return 31;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("month out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
|
|
|
|
const std::string& master, bool newGame, Environment& environment)
|
|
|
|
|
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
|
|
|
|
|
mSky (false), mCellChanged (false), mEnvironment (environment)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::filesystem::path masterPath (dataDir);
|
|
|
|
|
masterPath /= master;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
|
|
|
|
|
|
|
|
|
// This parses the ESM file and loads a sample cell
|
|
|
|
|
mEsm.open (masterPath.file_string());
|
|
|
|
|
mStore.load (mEsm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPlayerPos = new MWRender::PlayerPos (mScene.getCamera(), mStore.npcs.find ("player"));
|
|
|
|
|
|
|
|
|
|
// global variables
|
|
|
|
|
mGlobalVariables = new Globals (mStore);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newGame)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
// set new game mark
|
|
|
|
|
mGlobalVariables->setInt ("chargenstate", 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mSkyManager =
|
|
|
|
|
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera());
|
|
|
|
|
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
World::~World()
|
|
|
|
|
{
|
|
|
|
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
|
|
|
|
iter!=mActiveCells.end(); ++iter)
|
|
|
|
|
delete iter->second;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CellRenderCollection::iterator iter (mBufferedCells.begin());
|
|
|
|
|
iter!=mBufferedCells.end(); ++iter)
|
|
|
|
|
delete iter->second;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete mPlayerPos;
|
|
|
|
|
delete mSkyManager;
|
|
|
|
|
delete mGlobalVariables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWRender::PlayerPos& World::getPlayerPos()
|
|
|
|
|
{
|
|
|
|
|
return *mPlayerPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ESMS::ESMStore& World::getStore()
|
|
|
|
|
{
|
|
|
|
|
return mStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const World::ScriptList& World::getLocalScripts() const
|
|
|
|
|
{
|
|
|
|
|
return mLocalScripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool World::hasCellChanged() const
|
|
|
|
|
{
|
|
|
|
|
return mCellChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Globals::Data& World::getGlobalVariable (const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
return (*mGlobalVariables)[name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char World::getGlobalVariableType (const std::string& name) const
|
|
|
|
|
{
|
|
|
|
|
return mGlobalVariables->getType (name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr World::getPtr (const std::string& name, bool activeOnly)
|
|
|
|
|
{
|
|
|
|
|
// the player is always in an active cell.
|
|
|
|
@ -247,35 +247,35 @@ namespace MWWorld
|
|
|
|
|
{
|
|
|
|
|
return mPlayerPos->getPlayer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// active cells
|
|
|
|
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
|
|
|
|
iter!=mActiveCells.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
Ptr ptr = getPtr (name, *iter->first);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ptr.isEmpty())
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!activeOnly)
|
|
|
|
|
{
|
|
|
|
|
// TODO: inactive cells
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown ID: " + name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::enable (Ptr reference)
|
|
|
|
|
{
|
|
|
|
|
if (!reference.getRefData().isEnabled())
|
|
|
|
|
{
|
|
|
|
|
reference.getRefData().enable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
|
|
|
|
{
|
|
|
|
|
render->enable (reference.getRefData().getHandle());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
|
|
|
|
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
|
|
|
|
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
|
|
|
@ -285,69 +285,69 @@ namespace MWWorld
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::disable (Ptr reference)
|
|
|
|
|
{
|
|
|
|
|
if (!reference.getRefData().isEnabled())
|
|
|
|
|
{
|
|
|
|
|
reference.getRefData().enable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
|
|
|
|
{
|
|
|
|
|
render->disable (reference.getRefData().getHandle());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
|
|
|
|
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
|
|
|
|
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
|
|
|
|
{
|
|
|
|
|
mEnvironment.mMechanicsManager->removeActor (reference);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::advanceTime (double hours)
|
|
|
|
|
{
|
|
|
|
|
hours += mGlobalVariables->getFloat ("gamehour");
|
|
|
|
|
|
|
|
|
|
setHour (hours);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int days = hours / 24;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (days>0)
|
|
|
|
|
mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::setHour (double hour)
|
|
|
|
|
{
|
|
|
|
|
if (hour<0)
|
|
|
|
|
hour = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int days = hour / 24;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hour = std::fmod (hour, 24);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mGlobalVariables->setFloat ("gamehour", hour);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mSkyManager->setHour (hour);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (days>0)
|
|
|
|
|
setDay (days + mGlobalVariables->getInt ("day"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::setDay (int day)
|
|
|
|
|
{
|
|
|
|
|
if (day<0)
|
|
|
|
|
day = 0;
|
|
|
|
|
|
|
|
|
|
int month = mGlobalVariables->getInt ("month");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
int days = getDaysPerMonth (month);
|
|
|
|
|
int days = getDaysPerMonth (month);
|
|
|
|
|
if (day<days)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (month<11)
|
|
|
|
|
{
|
|
|
|
|
++month;
|
|
|
|
@ -357,37 +357,37 @@ namespace MWWorld
|
|
|
|
|
month = 0;
|
|
|
|
|
mGlobalVariables->setInt ("year", mGlobalVariables->getInt ("year")+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
day -= days;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mGlobalVariables->setInt ("day", day);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mGlobalVariables->setInt ("day", day);
|
|
|
|
|
mGlobalVariables->setInt ("month", month);
|
|
|
|
|
|
|
|
|
|
mSkyManager->setDate (day, month);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void World::setMonth (int month)
|
|
|
|
|
{
|
|
|
|
|
if (month<0)
|
|
|
|
|
month = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int years = month / 12;
|
|
|
|
|
month = month % 12;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int days = getDaysPerMonth (month);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mGlobalVariables->getInt ("day")>=days)
|
|
|
|
|
mGlobalVariables->setInt ("day", days-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mGlobalVariables->setInt ("month", month);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (years>0)
|
|
|
|
|
mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year"));
|
|
|
|
|
|
|
|
|
|
mSkyManager->setDate (mGlobalVariables->getInt ("day"), month);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::toggleSky()
|
|
|
|
|
{
|
|
|
|
|
if (mSky)
|
|
|
|
@ -405,36 +405,36 @@ namespace MWWorld
|
|
|
|
|
mSkyManager->enable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int World::getMasserPhase() const
|
|
|
|
|
{
|
|
|
|
|
return mSkyManager->getMasserPhase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int World::getSecundaPhase() const
|
|
|
|
|
{
|
|
|
|
|
return mSkyManager->getSecundaPhase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::setMoonColour (bool red)
|
|
|
|
|
{
|
|
|
|
|
mSkyManager->setMoonColour (red);
|
|
|
|
|
mSkyManager->setMoonColour (red);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float World::getTimeScaleFactor() const
|
|
|
|
|
{
|
|
|
|
|
return mGlobalVariables->getInt ("timescale");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::changeCell (const std::string& cellName, const ESM::Position& position)
|
|
|
|
|
{
|
|
|
|
|
// Load cell.
|
|
|
|
|
// Load cell.
|
|
|
|
|
mInteriors[cellName].loadInt (cellName, mStore, mEsm);
|
|
|
|
|
Ptr::CellStore *cell = &mInteriors[cellName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove active
|
|
|
|
|
CellRenderCollection::iterator active = mActiveCells.begin();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (active!=mActiveCells.end())
|
|
|
|
|
{
|
|
|
|
|
mEnvironment.mMechanicsManager->dropActors (active->first);
|
|
|
|
@ -444,7 +444,7 @@ namespace MWWorld
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// register local scripts
|
|
|
|
|
mLocalScripts.clear(); // FIXME won't work with exteriors
|
|
|
|
|
mLocalScripts.clear(); // FIXME won't work with exteriors
|
|
|
|
|
insertInteriorScripts (*cell);
|
|
|
|
|
|
|
|
|
|
// adjust player
|
|
|
|
@ -458,11 +458,11 @@ namespace MWWorld
|
|
|
|
|
new MWRender::InteriorCellRender (*cell, mScene)));
|
|
|
|
|
|
|
|
|
|
if (result.second)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
// Load the cell and insert it into the renderer
|
|
|
|
|
result.first->second->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actors
|
|
|
|
|
mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer());
|
|
|
|
|
mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer());
|
|
|
|
@ -496,12 +496,12 @@ namespace MWWorld
|
|
|
|
|
// TODO set weather
|
|
|
|
|
toggleSky();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCellChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void World::markCellAsUnchanged()
|
|
|
|
|
{
|
|
|
|
|
mCellChanged = false;
|
|
|
|
|
mCellChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|