From 584c121f33ac2f879b366ec60591aa9f6af4d604 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 14 Jan 2014 17:20:41 +0400 Subject: [PATCH 01/82] fix windows unicode path handling --- components/files/windowspath.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index ea1ca56d3c..a8cbcb24b7 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,8 +10,12 @@ #pragma comment(lib, "Shlwapi.lib") +#include +namespace bconv = boost::locale::conv; + /** * FIXME: Someone with Windows system should check this and correct if necessary + * FIXME: MAX_PATH is irrelevant for extended-length paths, i.e. \\?\... */ /** @@ -29,16 +33,15 @@ boost::filesystem::path WindowsPath::getUserConfigPath() const { boost::filesystem::path userPath("."); - TCHAR path[MAX_PATH]; + WCHAR path[MAX_PATH + 1]; memset(path, 0, sizeof(path)); - if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path))) + if(SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path))) { - PathAppend(path, TEXT("My Games")); - userPath = boost::filesystem::path(path); + userPath = boost::filesystem::path(bconv::utf_to_utf(path)); } - return userPath / mName; + return userPath / "MyGames" / mName; } boost::filesystem::path WindowsPath::getUserDataPath() const @@ -51,12 +54,12 @@ boost::filesystem::path WindowsPath::getGlobalConfigPath() const { boost::filesystem::path globalPath("."); - TCHAR path[MAX_PATH]; + WCHAR path[MAX_PATH + 1]; memset(path, 0, sizeof(path)); - if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path))) + if(SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path))) { - globalPath = boost::filesystem::path(path); + globalPath = boost::filesystem::path(bconv::utf_to_utf(path)); } return globalPath / mName; From eafdefe9993b550e1cc5a1edbd3b92183473e9bb Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 14 Jan 2014 23:08:54 +0400 Subject: [PATCH 02/82] using WindowsPath implies utf-8 for boost fs::path --- components/files/windowspath.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index a8cbcb24b7..f27c1cc925 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -27,6 +27,7 @@ namespace Files WindowsPath::WindowsPath(const std::string& application_name) : mName(application_name) { + boost::filesystem::path::imbue(boost::locale::generator.generate("")); } boost::filesystem::path WindowsPath::getUserConfigPath() const @@ -41,7 +42,7 @@ boost::filesystem::path WindowsPath::getUserConfigPath() const userPath = boost::filesystem::path(bconv::utf_to_utf(path)); } - return userPath / "MyGames" / mName; + return userPath / "My Games" / mName; } boost::filesystem::path WindowsPath::getUserDataPath() const From cd990a665a5b59770174ceeece71c0b675865cb7 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 14 Jan 2014 23:29:24 +0400 Subject: [PATCH 03/82] create QString from utf-8 when expected --- apps/launcher/maindialog.cpp | 20 ++++++++++---------- apps/launcher/settings/gamesettings.cpp | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 5cf8f8a892..fb4c09b918 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -41,11 +41,11 @@ Launcher::MainDialog::MainDialog(QWidget *parent) // Check if the font is installed if (!fonts.contains("EB Garamond")) { - QString font = QString::fromStdString(mCfgMgr.getGlobalDataPath().string()) + QString("resources/mygui/EBGaramond-Regular.ttf"); + QString font = QString::fromUtf8(mCfgMgr.getGlobalDataPath().string().c_str()) + QString("resources/mygui/EBGaramond-Regular.ttf"); file.setFileName(font); if (!file.exists()) { - font = QString::fromStdString(mCfgMgr.getLocalPath().string()) + QString("resources/mygui/EBGaramond-Regular.ttf"); + font = QString::fromUtf8(mCfgMgr.getLocalPath().string().c_str()) + QString("resources/mygui/EBGaramond-Regular.ttf"); } fontDatabase.addApplicationFont(font); @@ -243,7 +243,7 @@ bool Launcher::MainDialog::showFirstRunDialog() } // Create the file if it doesn't already exist, else the importer will fail - QString path = QString::fromStdString(mCfgMgr.getUserConfigPath().string()) + QString("openmw.cfg"); + QString path = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()) + QString("openmw.cfg"); QFile file(path); if (!file.exists()) { @@ -358,7 +358,7 @@ bool Launcher::MainDialog::setupLauncherSettings() { mLauncherSettings.setMultiValueEnabled(true); - QString userPath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()); + QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()); QStringList paths; paths.append(QString("launcher.cfg")); @@ -464,8 +464,8 @@ bool Launcher::expansions(Launcher::UnshieldThread& cd) bool Launcher::MainDialog::setupGameSettings() { - QString userPath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()); - QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string()); + QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()); + QString globalPath = QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str()); // Load the user config file first, separately // So we can write it properly, uncontaminated @@ -594,7 +594,7 @@ bool Launcher::MainDialog::setupGameSettings() while(expansions(cd)); - selectedFile = QString::fromStdString(cd.GetMWEsmPath()); + selectedFile = QString::fromUtf8(cd.GetMWEsmPath().c_str()); } #endif // WIN32 @@ -615,8 +615,8 @@ bool Launcher::MainDialog::setupGraphicsSettings() { mGraphicsSettings.setMultiValueEnabled(false); - QString userPath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()); - QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string()); + QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()); + QString globalPath = QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str()); QFile localDefault(QString("settings-default.cfg")); QFile globalDefault(globalPath + QString("settings-default.cfg")); @@ -702,7 +702,7 @@ bool Launcher::MainDialog::writeSettings() mGraphicsPage->saveSettings(); mDataFilesPage->saveSettings(); - QString userPath = QString::fromStdString(mCfgMgr.getUserConfigPath().string()); + QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()); QDir dir(userPath); if (!dir.exists()) { diff --git a/apps/launcher/settings/gamesettings.cpp b/apps/launcher/settings/gamesettings.cpp index e7e5cf1ea7..0a09c5cc04 100644 --- a/apps/launcher/settings/gamesettings.cpp +++ b/apps/launcher/settings/gamesettings.cpp @@ -53,7 +53,7 @@ void Launcher::GameSettings::validatePaths() mDataDirs.clear(); for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { - QString path = QString::fromStdString(it->string()); + QString path = QString::fromUtf8(it->string().c_str()); path.remove(QChar('\"')); QDir dir(path); @@ -73,7 +73,7 @@ void Launcher::GameSettings::validatePaths() mCfgMgr.processPaths(dataDirs); if (!dataDirs.empty()) { - QString path = QString::fromStdString(dataDirs.front().string()); + QString path = QString::fromUtf8(dataDirs.front().string().c_str()); path.remove(QChar('\"')); QDir dir(path); From b4950509bc5e55016f79ad0aa50fb8d9164c35c5 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 14 Jan 2014 23:30:56 +0400 Subject: [PATCH 04/82] use converted widechars in ini importer --- apps/mwiniimporter/main.cpp | 32 ++++++++++++++++++++++++++++++++ components/files/windowspath.cpp | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 364a6b1a4a..58ae1d593a 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -4,11 +4,43 @@ #include #include #include +#include namespace bpo = boost::program_options; +#ifndef _WIN32 int main(int argc, char *argv[]) { +#else +class utf8argv +{ +public: + + utf8argv(int argc, wchar_t *wargv[]) + { + args.reserve(argc); + argv = new const char *[argc]; + + for (int i = 0; i < argc; ++i) { + args.push_back(boost::locale::conv::utf_to_utf(wargv[i])); + argv[i] = args.back().c_str(); + } + } + + ~utf8argv() { delete[] argv; } + const char * const *get() const { return argv; } + +private: + + const char **argv; + std::vector args; +}; + +int wmain(int argc, wchar_t *wargv[]) { + utf8argv converter(argc, wargv); + char **argv = converter.get(); + boost::filesystem::path::imbue(boost::locale::generator().generate("")); +#endif bpo::options_description desc("Syntax: mwiniimporter inifile configfile\nAllowed options"); bpo::positional_options_description p_desc; desc.add_options() diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f27c1cc925..41240ae488 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -27,7 +27,7 @@ namespace Files WindowsPath::WindowsPath(const std::string& application_name) : mName(application_name) { - boost::filesystem::path::imbue(boost::locale::generator.generate("")); + boost::filesystem::path::imbue(boost::locale::generator().generate("")); } boost::filesystem::path WindowsPath::getUserConfigPath() const From 18b3cfebdbb4bfe371333c6273480feeca002853 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 15 Jan 2014 01:43:55 +0400 Subject: [PATCH 05/82] fix importer crash on empty lines (thanks to Ace) --- apps/mwiniimporter/importer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 648ab3ebee..3226278fe9 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -674,6 +674,10 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::string& filenam line = line.substr(0, line.length()-1); } + if(line.empty()) { + continue; + } + if(line[0] == '[') { int pos = line.find(']'); if(pos < 2) { @@ -690,10 +694,6 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::string& filenam line = line.substr(0,comment_pos); } - if(line.empty()) { - continue; - } - int pos = line.find("="); if(pos < 1) { continue; From a22ec223d86246dc0640701b3637f40fdeaa89da Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 19 Jan 2014 11:34:54 +0400 Subject: [PATCH 06/82] open fstreams from boost::filesystem::path, vol.1 --- apps/launcher/unshieldthread.cpp | 6 +++--- apps/openmw/mwgui/console.cpp | 6 +++++- components/files/configurationmanager.cpp | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/launcher/unshieldthread.cpp b/apps/launcher/unshieldthread.cpp index 52f9357108..26010faf3f 100644 --- a/apps/launcher/unshieldthread.cpp +++ b/apps/launcher/unshieldthread.cpp @@ -1,6 +1,6 @@ #include "unshieldthread.hpp" -#include +#include #include namespace bfs = boost::filesystem; @@ -49,7 +49,7 @@ namespace std::string read_to_string(const bfs::path& path) { - std::ifstream strstream(path.c_str(), std::ios::in | std::ios::binary); + bfs::ifstream strstream(path, std::ios::in | std::ios::binary); std::string str; strstream.seekg(0, std::ios::end); @@ -201,7 +201,7 @@ namespace add_setting("Archives", "Archive 1", "Bloodmoon.bsa", ini); } - std::ofstream inistream(ini_path.c_str()); + bfs::ofstream inistream(ini_path) inistream << ini; inistream.close(); } diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index d51d4298f6..dd3a67e940 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -1,5 +1,8 @@ #include "console.hpp" +#include +#include + #include #include @@ -194,7 +197,8 @@ namespace MWGui void Console::executeFile (const std::string& path) { - std::ifstream stream (path.c_str()); + namespace bfs = boost::filesystem; + bfs::ifstream stream (bfs::path(path)); if (!stream.is_open()) printError ("failed to open file: " + path); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 761b7ca5ad..ffa911b44f 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -1,12 +1,12 @@ #include "configurationmanager.hpp" #include -#include #include #include #include #include +#include /** * \namespace Files @@ -125,7 +125,7 @@ void ConfigurationManager::loadConfig(const boost::filesystem::path& path, { std::cout << "Loading config file: " << cfgFile.string() << "... "; - std::ifstream configFileStream(cfgFile.string().c_str()); + boost::filesystem::ifstream configFileStream(cfgFile); if (configFileStream.is_open()) { boost::program_options::store(boost::program_options::parse_config_file( From 2236216344c489503cbd5945478b0ae196237a12 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 19 Jan 2014 14:55:12 +0400 Subject: [PATCH 07/82] minor simplification --- components/files/multidircollection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/files/multidircollection.cpp b/components/files/multidircollection.cpp index 347de96a6a..1abbae3ae8 100644 --- a/components/files/multidircollection.cpp +++ b/components/files/multidircollection.cpp @@ -60,10 +60,10 @@ namespace Files { boost::filesystem::path path = *dirIter; - if (!equal (extension, boost::filesystem::path (path.extension()).string())) + if (!equal (extension, path.extension().string())) continue; - std::string filename = boost::filesystem::path (path.filename()).string(); + std::string filename = path.filename().string(); TIter result = mFiles.find (filename); From 424d06a6f88906b4d10f76060c4cd0032440d150 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 19 Jan 2014 15:20:08 +0400 Subject: [PATCH 08/82] open fstreams from boost::filesystem::path, vol.2 --- components/settings/settings.cpp | 6 ++++-- components/translation/translation.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 13015e39c9..3a3a3dddda 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -1,7 +1,8 @@ #include "settings.hpp" -#include #include +#include +#include #include #include @@ -25,7 +26,8 @@ void Manager::loadDefault (const std::string& file) void Manager::saveUser(const std::string& file) { - std::fstream fout(file.c_str(), std::ios::out); + namespace bfs = boost::filesystem; + bfs::ofstream fout(bfs::path(file)); Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator(); diff --git a/components/translation/translation.cpp b/components/translation/translation.cpp index d0ea4b7fb6..423c3971a0 100644 --- a/components/translation/translation.cpp +++ b/components/translation/translation.cpp @@ -1,7 +1,8 @@ #include "translation.hpp" -#include -#include +#include + +#include namespace Translation { @@ -28,9 +29,8 @@ namespace Translation if (dataFileCollections.getCollection (extension).doesExist (fileName)) { - std::string path = dataFileCollections.getCollection (extension).getPath (fileName).string(); - - std::ifstream stream (path.c_str()); + boost::filesystem::ifstream stream ( + dataFileCollections.getCollection (extension).getPath (fileName)); if (!stream.is_open()) throw std::runtime_error ("failed to open translation file: " + fileName); From e02b04536f8e840cde337fd3cd622e7c765f3050 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 19 Jan 2014 18:13:35 +0400 Subject: [PATCH 09/82] fix most vexing parse issue --- apps/launcher/unshieldthread.cpp | 2 +- apps/openmw/mwgui/console.cpp | 2 +- components/settings/settings.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/launcher/unshieldthread.cpp b/apps/launcher/unshieldthread.cpp index 26010faf3f..3d0f2e5da6 100644 --- a/apps/launcher/unshieldthread.cpp +++ b/apps/launcher/unshieldthread.cpp @@ -201,7 +201,7 @@ namespace add_setting("Archives", "Archive 1", "Bloodmoon.bsa", ini); } - bfs::ofstream inistream(ini_path) + bfs::ofstream inistream((ini_path)); inistream << ini; inistream.close(); } diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index dd3a67e940..237d145a2e 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -198,7 +198,7 @@ namespace MWGui void Console::executeFile (const std::string& path) { namespace bfs = boost::filesystem; - bfs::ifstream stream (bfs::path(path)); + bfs::ifstream stream ((bfs::path(path))); if (!stream.is_open()) printError ("failed to open file: " + path); diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 3a3a3dddda..ac09db9d95 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -27,7 +27,7 @@ void Manager::loadDefault (const std::string& file) void Manager::saveUser(const std::string& file) { namespace bfs = boost::filesystem; - bfs::ofstream fout(bfs::path(file)); + bfs::ofstream fout((bfs::path(file))); Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator(); From 2c82da8e6e5d535e2032c8e21150d7a8d3a60f07 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 10:07:43 +0400 Subject: [PATCH 10/82] load Ogre::ConfigFile from DataStream --- components/settings/settings.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index ac09db9d95..56e937c8ef 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -6,9 +6,12 @@ #include #include +#include using namespace Settings; +namespace bfs = boost::filesystem; + Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); CategorySettingVector Manager::mChangedSettings = CategorySettingVector(); @@ -16,17 +19,20 @@ CategorySettingValueMap Manager::mNewSettings = CategorySettingValueMap(); void Manager::loadUser (const std::string& file) { - mFile.load(file); + bfs::ifstream fin((bfs::path(file))); + Ogre::DataStreamPtr stream((OGRE_NEW Ogre::FileStreamDataStream(file, &fin, false))); + mFile.load(stream); } void Manager::loadDefault (const std::string& file) { - mDefaultFile.load(file); + bfs::ifstream fin((bfs::path(file))); + Ogre::DataStreamPtr stream((OGRE_NEW Ogre::FileStreamDataStream(file, &fin, false))); + mDefaultFile.load(stream); } void Manager::saveUser(const std::string& file) { - namespace bfs = boost::filesystem; bfs::ofstream fout((bfs::path(file))); Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator(); From 6cb795ef7d86f14358f2b497c561de1c226465c4 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 10:47:02 +0400 Subject: [PATCH 11/82] attempt to fix LowLevelFile, minor code reuse --- components/files/lowlevelfile.cpp | 5 ++++- components/settings/settings.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/files/lowlevelfile.cpp b/components/files/lowlevelfile.cpp index 06ee9fb4e8..4466e354d1 100644 --- a/components/files/lowlevelfile.cpp +++ b/components/files/lowlevelfile.cpp @@ -206,6 +206,8 @@ size_t LowLevelFile::read (void * data, size_t size) } #elif FILE_API == FILE_API_WIN32 + +#include /* * * Implementation of LowLevelFile methods using Win32 API calls @@ -227,7 +229,8 @@ void LowLevelFile::open (char const * filename) { assert (mHandle == INVALID_HANDLE_VALUE); - HANDLE handle = CreateFileA (filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + std::wstring wname = boost::locale::conv::utf_to_utf(filename); + HANDLE handle = CreateFileW (wname.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (handle == NULL) { diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 56e937c8ef..0def0afdb7 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -8,6 +8,8 @@ #include #include +#include + using namespace Settings; namespace bfs = boost::filesystem; @@ -19,15 +21,13 @@ CategorySettingValueMap Manager::mNewSettings = CategorySettingValueMap(); void Manager::loadUser (const std::string& file) { - bfs::ifstream fin((bfs::path(file))); - Ogre::DataStreamPtr stream((OGRE_NEW Ogre::FileStreamDataStream(file, &fin, false))); + Ogre::DataStreamPtr stream = openConstrainedFileDataStream(file.c_str()); mFile.load(stream); } void Manager::loadDefault (const std::string& file) { - bfs::ifstream fin((bfs::path(file))); - Ogre::DataStreamPtr stream((OGRE_NEW Ogre::FileStreamDataStream(file, &fin, false))); + Ogre::DataStreamPtr stream = openConstrainedFileDataStream(file.c_str()); mDefaultFile.load(stream); } From 417e07fbcef11d94d903925bf9a6bd91f3e0bbb4 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 10:59:36 +0400 Subject: [PATCH 12/82] fix irrelevant error reporting --- components/files/lowlevelfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/lowlevelfile.cpp b/components/files/lowlevelfile.cpp index 4466e354d1..4cdeec043a 100644 --- a/components/files/lowlevelfile.cpp +++ b/components/files/lowlevelfile.cpp @@ -232,7 +232,7 @@ void LowLevelFile::open (char const * filename) std::wstring wname = boost::locale::conv::utf_to_utf(filename); HANDLE handle = CreateFileW (wname.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == NULL) + if (handle == INVALID_HANDLE_VALUE) { std::ostringstream os; os << "Failed to open '" << filename << "' for reading."; From 493f8c60504222e5fe51a34548c69907bdec2ae0 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 13:39:07 +0400 Subject: [PATCH 13/82] fix opening BSA on Unicode path --- components/bsa/bsa_file.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index 25b006fb3e..0958c8f0c2 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -25,6 +25,9 @@ #include +#include +#include + #include "../files/constrainedfiledatastream.hpp" using namespace std; @@ -72,7 +75,8 @@ void BSAFile::readHeader() */ assert(!isLoaded); - std::ifstream input(filename.c_str(), std::ios_base::binary); + namespace bfs = boost::filesystem; + bfs::ifstream input(bfs::path(filename), std::ios_base::binary); // Total archive size size_t fsize = 0; From 9c6224c74d0e19e680a9f22f037503ba28451b10 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 15:43:25 +0400 Subject: [PATCH 14/82] fix saving to Unicode path destination --- apps/openmw/mwstate/statemanagerimp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 304228010a..0cd23eb6ff 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -12,6 +12,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/journal.hpp" @@ -187,7 +189,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot else slot = mCharacterManager.getCurrentCharacter()->updateSlot (slot, profile); - std::ofstream stream (slot->mPath.string().c_str(), std::ios::binary); + boost::filesystem::ofstream stream (slot->mPath, std::ios::binary); ESM::ESMWriter writer; From db16bb89834954adc94a5bcab82d8f1a72d42502 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 15:52:19 +0400 Subject: [PATCH 15/82] fix OpenCS saving to Unicode path destination --- apps/opencs/model/doc/savingstages.cpp | 4 ++-- apps/opencs/model/doc/savingstate.cpp | 4 ++-- apps/opencs/model/doc/savingstate.hpp | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index eb93d90475..34d93c49a2 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -27,7 +27,7 @@ void CSMDoc::OpenSaveStage::perform (int stage, Messages& messages) { mState.start (mDocument, mProjectFile); - mState.getStream().open ((mProjectFile ? mState.getPath() : mState.getTmpPath()).string().c_str()); + mState.getStream().open (mProjectFile ? mState.getPath() : mState.getTmpPath()); if (!mState.getStream().is_open()) throw std::runtime_error ("failed to open stream for saving"); @@ -260,4 +260,4 @@ void CSMDoc::FinalSavingStage::perform (int stage, Messages& messages) mDocument.getUndoStack().setClean(); } -} \ No newline at end of file +} diff --git a/apps/opencs/model/doc/savingstate.cpp b/apps/opencs/model/doc/savingstate.cpp index 8742148226..07c42a490f 100644 --- a/apps/opencs/model/doc/savingstate.cpp +++ b/apps/opencs/model/doc/savingstate.cpp @@ -47,7 +47,7 @@ const boost::filesystem::path& CSMDoc::SavingState::getTmpPath() const return mTmpPath; } -std::ofstream& CSMDoc::SavingState::getStream() +boost::filesystem::ofstream& CSMDoc::SavingState::getStream() { return mStream; } @@ -60,4 +60,4 @@ ESM::ESMWriter& CSMDoc::SavingState::getWriter() bool CSMDoc::SavingState::isProjectFile() const { return mProjectFile; -} \ No newline at end of file +} diff --git a/apps/opencs/model/doc/savingstate.hpp b/apps/opencs/model/doc/savingstate.hpp index 6b45655846..7b0c373866 100644 --- a/apps/opencs/model/doc/savingstate.hpp +++ b/apps/opencs/model/doc/savingstate.hpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -20,7 +21,7 @@ namespace CSMDoc boost::filesystem::path mPath; boost::filesystem::path mTmpPath; ToUTF8::Utf8Encoder mEncoder; - std::ofstream mStream; + boost::filesystem::ofstream mStream; ESM::ESMWriter mWriter; boost::filesystem::path mProjectPath; bool mProjectFile; @@ -39,7 +40,7 @@ namespace CSMDoc const boost::filesystem::path& getTmpPath() const; - std::ofstream& getStream(); + boost::filesystem::ofstream& getStream(); ESM::ESMWriter& getWriter(); @@ -50,4 +51,4 @@ namespace CSMDoc } -#endif \ No newline at end of file +#endif From 20527e0bd4418b107634247e78b08d6ec9c608fa Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 16:56:41 +0400 Subject: [PATCH 16/82] use boost::filesystem instead of boost::iostreams --- apps/mwiniimporter/importer.cpp | 13 ++++++++----- apps/mwiniimporter/importer.hpp | 5 ++--- apps/mwiniimporter/main.cpp | 9 ++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 3226278fe9..3a52592ae8 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -1,6 +1,5 @@ #include "importer.hpp" -#include -#include + #include #include #include @@ -9,6 +8,10 @@ #include #include +#include +#include + +namespace bfs = boost::filesystem; MwIniImporter::MwIniImporter() : mVerbose(false) @@ -661,7 +664,7 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::string& filenam std::string section(""); MwIniImporter::multistrmap map; - boost::iostreams::streamfile(filename.c_str()); + bfs::ifstream file((bfs::path(filename))); ToUTF8::Utf8Encoder encoder(mEncoding); std::string line; @@ -720,7 +723,7 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::string& filenam std::cout << "load cfg file: " << filename << std::endl; MwIniImporter::multistrmap map; - boost::iostreams::streamfile(filename.c_str()); + bfs::ifstream file((bfs::path(filename))); std::string line; while (std::getline(file, line)) { @@ -858,7 +861,7 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, const multistrmap &ini) co } } -void MwIniImporter::writeToFile(boost::iostreams::stream &out, const multistrmap &cfg) { +void MwIniImporter::writeToFile(std::ostream &out, const multistrmap &cfg) { for(multistrmap::const_iterator it=cfg.begin(); it != cfg.end(); ++it) { for(std::vector::const_iterator entry=it->second.begin(); entry != it->second.end(); ++entry) { diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 784980e090..72b14ba75f 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -1,12 +1,11 @@ #ifndef MWINIIMPORTER_IMPORTER #define MWINIIMPORTER_IMPORTER 1 -#include -#include #include #include #include #include +#include #include @@ -24,7 +23,7 @@ class MwIniImporter { void mergeFallback(multistrmap &cfg, const multistrmap &ini) const; void importGameFiles(multistrmap &cfg, const multistrmap &ini) const; void importArchives(multistrmap &cfg, const multistrmap &ini) const; - static void writeToFile(boost::iostreams::stream &out, const multistrmap &cfg); + static void writeToFile(std::ostream &out, const multistrmap &cfg); private: static void insertMultistrmap(multistrmap &cfg, const std::string& key, const std::string& value); diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 58ae1d593a..d9c1454fc2 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -1,12 +1,15 @@ #include "importer.hpp" -#include #include + #include -#include #include +#include +#include +#include namespace bpo = boost::program_options; +namespace bfs = boost::filesystem; #ifndef _WIN32 int main(int argc, char *argv[]) { @@ -126,7 +129,7 @@ int wmain(int argc, wchar_t *wargv[]) { } std::cout << "write to: " << outputFile << std::endl; - boost::iostreams::stream file(outputFile); + bfs::ofstream file((bfs::path(outputFile))); importer.writeToFile(file, cfg); return 0; From 444a07c01b89b7eda8ae4346d821f65231d79d4d Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 18:12:13 +0400 Subject: [PATCH 17/82] workaround OgreLog Unicode path handling --- components/ogreinit/ogreinit.cpp | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/components/ogreinit/ogreinit.cpp b/components/ogreinit/ogreinit.cpp index 01b8764c2b..5827645f53 100644 --- a/components/ogreinit/ogreinit.cpp +++ b/components/ogreinit/ogreinit.cpp @@ -1,11 +1,15 @@ #include "ogreinit.hpp" #include +#include +#include +#include #include #include #include #include +#include #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE #include @@ -13,8 +17,47 @@ #include +#include +#include + #include "ogreplugin.hpp" +namespace bfs = boost::filesystem; + +namespace +{ + class LogListener : public Ogre::LogListener + { + bfs::ofstream file; + char buffer[16]; + + + public: + + LogListener(const std::string &path) + : file((bfs::path(path))) + { + memset(buffer, sizeof(buffer), 0); + } + + void timestamp() + { + int local = time(0) % 86400; + int sec = local % 60; + int min = (local / 60) % 60; + int hrs = local / 3600; + sprintf(buffer, "%02d:%02d:%02d: ", hrs, min, sec); + } + + virtual void messageLogged(const std::string &msg, Ogre::LogMessageLevel lvl, bool mask, const std::string &logName, bool &skip) + { + timestamp(); + file << buffer << msg << std::endl; + skip = true; + } + }; +} + namespace OgreInit { @@ -43,6 +86,10 @@ namespace OgreInit new Ogre::LogManager; Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath); + #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + log->addListener(new LogListener(logPath)); + #endif + // Disable logging to cout/cerr log->setDebugOutputEnabled(false); From 86a89663066f20b65a40293eddf85fdb97c24717 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 19 May 2014 22:56:40 +0400 Subject: [PATCH 18/82] manual screenshot creation and uploading (scrawl) --- libs/openengine/ogre/renderer.cpp | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index caf62546e5..ae0d477d29 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -15,6 +15,9 @@ #include +#include +#include + #include #include @@ -48,7 +51,37 @@ void OgreRenderer::update(float dt) void OgreRenderer::screenshot(const std::string &file) { - mWindow->writeContentsToFile(file); + namespace bfs = boost::filesystem; + bfs::ofstream out((bfs::path(file))); + + Ogre::Image image; + + Ogre::PixelFormat pf = mWindow->suggestPixelFormat(); + int w = mWindow->getWidth(); + int h = mWindow->getHeight(); + + image.loadDynamicImage( + OGRE_ALLOC_T(Ogre::uchar, w * h * Ogre::PixelUtil::getNumElemBytes(pf), Ogre::MEMCATEGORY_GENERAL), + w, h, 1, pf, true + ); + mWindow->copyContentsToMemory(image.getPixelBox()); + + Ogre::DataStreamPtr stream = image.encode("png"); + Ogre::MemoryDataStream *mem = dynamic_cast(stream.get()); + if (mem != 0) { // likely + const char *ptr = reinterpret_cast(mem->getCurrentPtr()); + out.write(ptr, mem->size()); + } + else { + char buf[4096]; + size_t size = stream->size(); + while (size > 0) { + size_t chunk = (size > sizeof(buf)) ? sizeof(buf) : size; + stream->read(buf, chunk); + out.write(buf, chunk); + size -= chunk; + } + } } float OgreRenderer::getFPS() From 130349e0cd044b3972920380f81655cb6d6ed93f Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 08:14:29 +0400 Subject: [PATCH 19/82] open files in binary mode when necessary --- apps/opencs/model/doc/savingstages.cpp | 4 +++- libs/openengine/ogre/renderer.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index 34d93c49a2..066c76734e 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -27,7 +27,9 @@ void CSMDoc::OpenSaveStage::perform (int stage, Messages& messages) { mState.start (mDocument, mProjectFile); - mState.getStream().open (mProjectFile ? mState.getPath() : mState.getTmpPath()); + mState.getStream().open ( + mProjectFile ? mState.getPath() : mState.getTmpPath(), + std::ios::binary); if (!mState.getStream().is_open()) throw std::runtime_error ("failed to open stream for saving"); diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index ae0d477d29..64d65ea0da 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -52,7 +52,7 @@ void OgreRenderer::update(float dt) void OgreRenderer::screenshot(const std::string &file) { namespace bfs = boost::filesystem; - bfs::ofstream out((bfs::path(file))); + bfs::ofstream out(bfs::path(file), std::ios::binary); Ogre::Image image; From a46662043ad1f0eab2c0fb9b8c877a067b96815e Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 09:17:32 +0400 Subject: [PATCH 20/82] tinyxml convert path to UTF-16 on Windows --- extern/oics/tinyxml.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/extern/oics/tinyxml.cpp b/extern/oics/tinyxml.cpp index 29a4768aa0..2cd42eb307 100644 --- a/extern/oics/tinyxml.cpp +++ b/extern/oics/tinyxml.cpp @@ -31,18 +31,33 @@ distribution. #include "tinyxml.h" +#ifdef _WIN32 +#include +#endif + bool TiXmlBase::condenseWhiteSpace = true; // Microsoft compiler security FILE* TiXmlFOpen( const char* filename, const char* mode ) { - #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + #if defined(_WIN32) FILE* fp = 0; - errno_t err = fopen_s( &fp, filename, mode ); - if ( !err && fp ) - return fp; - return 0; + size_t len = strlen(filename); + wchar_t *wname = new wchar_t[len] + wchar_t wmode[32] = { 0 }; + + MultiByteToWideChar(CP_UTF8, 0, filename, len, wname, len); + MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, sizeof(wmode) / sizeof(*wmode)); + + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + errno_t err = _wfopen_s( &fp, wname, wmode ); + #else + fp = _wfopen(wname, wmode) + #endif + delete[] wname; + + return fp; #else return fopen( filename, mode ); #endif From 46c32f6c4753fe7c04ab3e598784d52625de314e Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 10:37:04 +0400 Subject: [PATCH 21/82] OpenEngine MyGUI logging facility --- CMakeLists.txt | 1 + libs/openengine/gui/loglistener.cpp | 39 +++++++++++++++++++++++++++++ libs/openengine/gui/loglistener.hpp | 35 ++++++++++++++++++++++++++ libs/openengine/gui/manager.cpp | 39 +++++++++++++++++++++++++---- libs/openengine/gui/manager.hpp | 2 ++ 5 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 libs/openengine/gui/loglistener.cpp create mode 100644 libs/openengine/gui/loglistener.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8179021a4c..9abd6ac3f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ set(OENGINE_OGRE ) set(OENGINE_GUI + ${LIBDIR}/openengine/gui/loglistener.cpp ${LIBDIR}/openengine/gui/manager.cpp ${LIBDIR}/openengine/gui/layout.hpp ) diff --git a/libs/openengine/gui/loglistener.cpp b/libs/openengine/gui/loglistener.cpp new file mode 100644 index 0000000000..da36b90a2f --- /dev/null +++ b/libs/openengine/gui/loglistener.cpp @@ -0,0 +1,39 @@ +#include "loglistener.hpp" + +#include +#include + +#include + +namespace MyGUI +{ + void CustomLogListener::open() + { + mStream.open(boost::filesystem::path(mFileName), std::ios_base::out); + } + + void CustomLogListener::close() + { + if (mStream.is_open()) + mStream.close(); + } + + void CustomLogListener::flush() + { + if (mStream.is_open()) + mStream.flush(); + } + + void CustomLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line) + { + if (mStream.is_open()) + { + const char* separator = " | "; + mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":" + << std::setw(2) << std::setfill('0') << _time->tm_min << ":" + << std::setw(2) << std::setfill('0') << _time->tm_sec << separator + << _section << separator << _level.print() << separator + << _message << separator << _file << separator << _line << std::endl; + } + } +} diff --git a/libs/openengine/gui/loglistener.hpp b/libs/openengine/gui/loglistener.hpp new file mode 100644 index 0000000000..20f23cf0ce --- /dev/null +++ b/libs/openengine/gui/loglistener.hpp @@ -0,0 +1,35 @@ +#ifndef OPENENGINE_MYGUI_LOGLISTENER_H +#define OPENENGINE_MYGUI_LOGLISTENER_H + +#include +#include + +#include + +namespace MyGUI +{ + class CustomLogListener : public ILogListener + { + public: + CustomLogListener(const std::string &name) + : mFileName(name) + {} + + ~CustomLogListener() {} + + virtual void open(); + virtual void close(); + virtual void flush(); + + virtual void log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line); + + const std::string& getFileName() const { return mFileName; } + + private: + boost::filesystem::ofstream mStream; + std::string mFileName; + }; + +} + +#endif diff --git a/libs/openengine/gui/manager.cpp b/libs/openengine/gui/manager.cpp index 91937d24bc..fa7419b32d 100644 --- a/libs/openengine/gui/manager.cpp +++ b/libs/openengine/gui/manager.cpp @@ -1,9 +1,14 @@ #include "manager.hpp" +#include "loglistener.hpp" #include #include #include +#include +#include +#include + #include #include @@ -554,8 +559,32 @@ public: } }; -} +class LogFacility +{ + ConsoleLogListener mConsole; + CustomLogListener mFile; + LevelLogFilter mFilter; + LogSource mSource; +public: + + LogFacility(const std::string &output, bool console) + : mFile(output) + { + mConsole.setEnabled(console); + mFilter.setLoggingLevel(LogLevel::Info); + + mSource.addLogListener(&mFile); + mSource.addLogListener(&mConsole); + mSource.setLogFilter(&mFilter); + + mSource.open(); + } + + LogSource *getSource() { return &mSource; } +}; + +} void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging, const std::string& logDir) { @@ -586,10 +615,8 @@ void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool mRenderManager = new MyGUI::OgreRenderManager(); mDataManager = new MyGUI::FixedOgreDataManager(); - LogManager::getInstance().setSTDOutputEnabled(logging); - - if (!theLogFile.empty()) - LogManager::getInstance().createDefaultSource(theLogFile); + mLogFacility = new MyGUI::LogFacility(theLogFile, logging); + LogManager::getInstance().addLogSource(mLogFacility->getSource()); if (mShaderRenderManager) mShaderRenderManager->initialise(wnd, mgr); @@ -648,5 +675,7 @@ void MyGUIManager::shutdown() delete mLogManager; mLogManager = NULL; } + delete mLogFacility; + mGui = NULL; } diff --git a/libs/openengine/gui/manager.hpp b/libs/openengine/gui/manager.hpp index cca70dfcfe..8923a5cc8e 100644 --- a/libs/openengine/gui/manager.hpp +++ b/libs/openengine/gui/manager.hpp @@ -10,6 +10,7 @@ namespace MyGUI class OgreDataManager; class OgreRenderManager; class ShaderBasedRenderManager; + class LogFacility; } namespace Ogre @@ -25,6 +26,7 @@ namespace GUI { MyGUI::Gui *mGui; MyGUI::LogManager* mLogManager; + MyGUI::LogFacility* mLogFacility; MyGUI::OgreDataManager* mDataManager; MyGUI::OgreRenderManager* mRenderManager; MyGUI::ShaderBasedRenderManager* mShaderRenderManager; From 9dbe3f21d987ba307498351fb8437058d43776dd Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 10:42:21 +0400 Subject: [PATCH 22/82] keep non-const signature for argv after conversion --- apps/mwiniimporter/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index d9c1454fc2..a4e5cad4df 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -31,7 +31,7 @@ public: } ~utf8argv() { delete[] argv; } - const char * const *get() const { return argv; } + char **get() const { return const_cast(argv); } private: From 1b7ed98325e6e3b4f43d0b08a6956963d8af3820 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 12:41:45 +0400 Subject: [PATCH 23/82] fix typos, reset memory before using --- extern/oics/tinyxml.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extern/oics/tinyxml.cpp b/extern/oics/tinyxml.cpp index 2cd42eb307..5be99f166a 100644 --- a/extern/oics/tinyxml.cpp +++ b/extern/oics/tinyxml.cpp @@ -44,7 +44,8 @@ FILE* TiXmlFOpen( const char* filename, const char* mode ) #if defined(_WIN32) FILE* fp = 0; size_t len = strlen(filename); - wchar_t *wname = new wchar_t[len] + wchar_t *wname = new wchar_t[len + 1]; + memset(wname, 0, sizeof(*wname) * (len + 1)); wchar_t wmode[32] = { 0 }; MultiByteToWideChar(CP_UTF8, 0, filename, len, wname, len); @@ -53,7 +54,7 @@ FILE* TiXmlFOpen( const char* filename, const char* mode ) #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) errno_t err = _wfopen_s( &fp, wname, wmode ); #else - fp = _wfopen(wname, wmode) + fp = _wfopen(wname, wmode); #endif delete[] wname; From b728a919a2089272a853bf8f31d84e71f3c05915 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 12:59:58 +0400 Subject: [PATCH 24/82] write dependency on boost::locale to CMake files --- CMakeLists.txt | 2 +- apps/opencs/CMakeLists.txt | 2 +- apps/openmw/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9abd6ac3f8..e4d8d1b9fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,7 +234,7 @@ if (HAVE_UNORDERED_MAP) endif () -set(BOOST_COMPONENTS system filesystem program_options) +set(BOOST_COMPONENTS system filesystem program_options locale) IF(BOOST_STATIC) set(Boost_USE_STATIC_LIBS ON) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 35551f97b8..6141790a8c 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -144,7 +144,7 @@ if(WIN32) set(QT_USE_QTMAIN TRUE) endif(WIN32) -set(BOOST_COMPONENTS system filesystem program_options thread wave) +set(BOOST_COMPONENTS system filesystem program_options thread wave locale) find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index e791ab8910..cf72cc7325 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -82,7 +82,7 @@ add_openmw_dir (mwbase ) # Main executable -set(BOOST_COMPONENTS system filesystem program_options thread wave) +set(BOOST_COMPONENTS system filesystem program_options thread wave locale) find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) IF(OGRE_STATIC) From 4346e3b4d09e84aa7f15b2df06b68ed8a08d1541 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 20 May 2014 21:42:51 +0400 Subject: [PATCH 25/82] try to load plugins from relative paths --- components/ogreinit/ogreinit.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/ogreinit/ogreinit.cpp b/components/ogreinit/ogreinit.cpp index 5827645f53..44d5fe3d53 100644 --- a/components/ogreinit/ogreinit.cpp +++ b/components/ogreinit/ogreinit.cpp @@ -188,11 +188,6 @@ namespace OgreInit pluginDir = OGRE_PLUGIN_DIR_REL; #endif } - - boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir)); - - pluginDir = absPluginPath.string(); - Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mRoot); Files::loadOgrePlugin(pluginDir, "RenderSystem_GLES2", *mRoot); Files::loadOgrePlugin(pluginDir, "RenderSystem_GL3Plus", *mRoot); From 8b94e310623a2b54fd2ae8488d0dac5f0ff55f25 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 21 May 2014 15:39:58 +0400 Subject: [PATCH 26/82] try to set relative path to resources --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 66c09b6ff7..27739fd26c 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -236,7 +236,7 @@ void OMW::Engine::addArchive (const std::string& archive) { // Set resource dir void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir) { - mResDir = boost::filesystem::system_complete(parResDir); + mResDir = parResDir; } // Set start cell name (only interiors for now) From 3a7e2f8bb579e79c72d12d4e84711f4bf8a3f04f Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 21 May 2014 14:18:14 +0200 Subject: [PATCH 27/82] Allow invoking Journal instruction with non-existing index This is used by the MG_EscortScholar1 quest. --- apps/openmw/mwscript/dialogueextensions.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index a882ae05e7..6958084f4a 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -34,7 +34,15 @@ namespace MWScript Interpreter::Type_Integer index = runtime[0].mInteger; runtime.pop(); - MWBase::Environment::get().getJournal()->addEntry (quest, index); + // Invoking Journal with a non-existing index is allowed, and triggers no errors. Seriously? :( + try + { + MWBase::Environment::get().getJournal()->addEntry (quest, index); + } + catch (...) + { + MWBase::Environment::get().getJournal()->setJournalIndex(quest, index); + } } }; From f812746010a835b0b8dba4a4d333fafa9c363170 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 21 May 2014 16:36:55 +0200 Subject: [PATCH 28/82] Auto-select first save in load dialog --- apps/openmw/mwgui/savegamedialog.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 16e939eb24..6048e49b41 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -256,7 +256,16 @@ namespace MWGui { mSaveList->addItem(it->mProfile.mDescription); } - onSlotSelected(mSaveList, MyGUI::ITEM_NONE); + // When loading, Auto-select the first save, if there is one + if (mSaveList->getItemCount() && !mSaving) + { + mSaveList->setIndexSelected(0); + onSlotSelected(mSaveList, 0); + // Give key focus to save list so we can confirm the selection with Enter + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mSaveList); + } + else + onSlotSelected(mSaveList, MyGUI::ITEM_NONE); } void SaveGameDialog::onSlotSelected(MyGUI::ListBox *sender, size_t pos) From cf07d2ab93fcb05e6e7c5e92552c6da083026e29 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 21 May 2014 16:38:50 +0200 Subject: [PATCH 29/82] Fix swapped position of Save and Load menu buttons --- apps/openmw/mwgui/mainmenu.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index 8b44af2ef3..bafd04311b 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -165,15 +165,15 @@ namespace MWGui buttons.push_back("newgame"); - if (MWBase::Environment::get().getStateManager()->characterBegin()!= - MWBase::Environment::get().getStateManager()->characterEnd()) - buttons.push_back("loadgame"); - if (state==MWBase::StateManager::State_Running && MWBase::Environment::get().getWorld()->getGlobalInt ("chargenstate")==-1 && MWBase::Environment::get().getWindowManager()->isSavingAllowed()) buttons.push_back("savegame"); + if (MWBase::Environment::get().getStateManager()->characterBegin()!= + MWBase::Environment::get().getStateManager()->characterEnd()) + buttons.push_back("loadgame"); + buttons.push_back("options"); if (state==MWBase::StateManager::State_NoGame) From 3721174ae433d530bb872fc4b2c70df37c1ac239 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 21 May 2014 23:50:58 +0400 Subject: [PATCH 30/82] proof-of-concept boost::wave iteration policy --- extern/shiny/Main/Preprocessor.cpp | 46 +++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/extern/shiny/Main/Preprocessor.cpp b/extern/shiny/Main/Preprocessor.cpp index 1a97668bcc..bc2957da1b 100644 --- a/extern/shiny/Main/Preprocessor.cpp +++ b/extern/shiny/Main/Preprocessor.cpp @@ -4,6 +4,50 @@ #include #include +#include + +namespace boost { +namespace wave { +namespace iteration_context_policies { + + struct load_utf8_path_to_string + { + template + class inner + { + public: + template + static void init_iterators(IterContextT &iter_ctx, + PositionT const &act_pos, language_support language) + { + typedef typename IterContextT::iterator_type iterator_type; + namespace bfs = boost::filesystem; + + // read in the file + bfs::ifstream instream(bfs::path(iter_ctx.filename.c_str())); + if (!instream.is_open()) { + BOOST_WAVE_THROW_CTX(iter_ctx.ctx, preprocess_exception, + bad_include_file, iter_ctx.filename.c_str(), act_pos); + return; + } + instream.unsetf(std::ios::skipws); + + iter_ctx.instring.assign( + std::istreambuf_iterator(instream.rdbuf()), + std::istreambuf_iterator()); + + iter_ctx.first = iterator_type( + iter_ctx.instring.begin(), iter_ctx.instring.end(), + PositionT(iter_ctx.filename), language); + iter_ctx.last = iterator_type(); + } + + private: + std::string instring; + }; + }; +} } } + namespace sh { std::string Preprocessor::preprocess (std::string source, const std::string& includePath, std::vector definitions, const std::string& name) @@ -29,7 +73,7 @@ namespace sh // match the iterator type used during construction of the context // instance (see below). It is the type of the underlying input stream. typedef boost::wave::context context_type; From 28b59f40084368d85b4659908069e01f08583876 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 22 May 2014 01:08:03 +0400 Subject: [PATCH 31/82] process paths as UTF-8 in launcher --- apps/launcher/settings/gamesettings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/launcher/settings/gamesettings.cpp b/apps/launcher/settings/gamesettings.cpp index 0a09c5cc04..4ebdb715a7 100644 --- a/apps/launcher/settings/gamesettings.cpp +++ b/apps/launcher/settings/gamesettings.cpp @@ -45,7 +45,8 @@ void Launcher::GameSettings::validatePaths() Files::PathContainer dataDirs; foreach (const QString &path, paths) { - dataDirs.push_back(Files::PathContainer::value_type(path.toStdString())); + QByteArray bytes = path.toUtf8(); + dataDirs.push_back(Files::PathContainer::value_type(std::string(bytes.constData(), bytes.length()))); } // Parse the data dirs to convert the tokenized paths From cb598f0455b15962fe9f818290acb7b8b31e3d22 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 22 May 2014 01:13:27 +0400 Subject: [PATCH 32/82] the same for data-local entry --- apps/launcher/settings/gamesettings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/launcher/settings/gamesettings.cpp b/apps/launcher/settings/gamesettings.cpp index 4ebdb715a7..2f3dd9a458 100644 --- a/apps/launcher/settings/gamesettings.cpp +++ b/apps/launcher/settings/gamesettings.cpp @@ -69,7 +69,8 @@ void Launcher::GameSettings::validatePaths() return; dataDirs.clear(); - dataDirs.push_back(Files::PathContainer::value_type(local.toStdString())); + QByteArray bytes = local.toUtf8(); + dataDirs.push_back(Files::PathContainer::value_type(std::string(bytes.constData(), bytes.length()))); mCfgMgr.processPaths(dataDirs); From 18bba6bcece30f3b0aaa8224b810fbc882237dbf Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 11:03:45 +0200 Subject: [PATCH 33/82] Fix layout glitch when autosaving --- apps/openmw/mwgui/waitdialog.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ed1b9e0a90..d5b52ebae8 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -118,11 +118,12 @@ namespace MWGui void WaitDialog::startWaiting(int hoursToWait) { + if(Settings::Manager::getBool("autosave","Saves") && mSleeping) //autosaves when enabled and sleeping + MWBase::Environment::get().getStateManager()->quickSave("Autosave"); + MWBase::World* world = MWBase::Environment::get().getWorld(); world->getFader ()->fadeOut(0.2); setVisible(false); - if(Settings::Manager::getBool("autosave","Saves") && mSleeping) //autosaves when enabled and sleeping (Not resting, apparently) - MWBase::Environment::get().getStateManager()->quickSave("Autosave"); mProgressBar.setVisible (true); mWaiting = true; From c6c254d279259a105fe4acee9f86a794af700750 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 11:08:36 +0200 Subject: [PATCH 34/82] Do not trigger levelup if rest was interrupted --- apps/openmw/mwgui/waitdialog.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index d5b52ebae8..7eaba93613 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -219,8 +219,20 @@ namespace MWGui } if (mCurHour > mHours) + { stopWaiting(); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + const MWMechanics::NpcStats &pcstats = MWWorld::Class::get(player).getNpcStats(player); + + // trigger levelup if possible + const MWWorld::Store &gmst = + MWBase::Environment::get().getWorld()->getStore().get(); + if (mSleeping && pcstats.getLevelProgress () >= gmst.find("iLevelUpTotal")->getInt()) + { + MWBase::Environment::get().getWindowManager()->pushGuiMode (GM_Levelup); + } + } } void WaitDialog::stopWaiting () @@ -230,17 +242,6 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Rest); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_RestBed); mWaiting = false; - - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &pcstats = MWWorld::Class::get(player).getNpcStats(player); - - // trigger levelup if possible - const MWWorld::Store &gmst = - MWBase::Environment::get().getWorld()->getStore().get(); - if (mSleeping && pcstats.getLevelProgress () >= gmst.find("iLevelUpTotal")->getInt()) - { - MWBase::Environment::get().getWindowManager()->pushGuiMode (GM_Levelup); - } } From 3380e1e1c563850d9b63a23f4b2c15c098232191 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 12:14:33 +0200 Subject: [PATCH 35/82] Fix ShouldAttack filter This makes NPCs exit dialogue properly when they should attack as a result of taunting actions. --- apps/openmw/mwdialogue/filter.cpp | 2 +- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 8b9ee9184f..5bdf80593b 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -539,7 +539,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_ShouldAttack: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).isHostile(); + return mActor.getClass().getCreatureStats(mActor).getAiSetting(MWMechanics::CreatureStats::AI_Fight).getModified() >= 80; case SelectWrapper::Function_CreatureTargetted: diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index bf9a11d6e5..f5f2443303 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -666,8 +666,6 @@ namespace MWMechanics int fight = npcStats.getAiSetting(MWMechanics::CreatureStats::AI_Fight).getBase(); npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee, std::max(0, std::min(100, flee + int(std::max(iPerMinChange, s))))); - // TODO: initiate combat and quit dialogue if fight rating is too high - // or should setAiSetting handle this? npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight, std::max(0, std::min(100, fight + int(std::min(-iPerMinChange, -s))))); } From 8f9091550e6097ebd456911889472446860c0033 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 22 May 2014 15:42:47 +0400 Subject: [PATCH 36/82] require boost::locale only on Windows --- CMakeLists.txt | 5 ++++- apps/mwiniimporter/main.cpp | 4 +++- apps/opencs/CMakeLists.txt | 6 +++++- apps/openmw/CMakeLists.txt | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d8d1b9fa..b323d4759f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,7 +234,10 @@ if (HAVE_UNORDERED_MAP) endif () -set(BOOST_COMPONENTS system filesystem program_options locale) +set(BOOST_COMPONENTS system filesystem program_options) +if(WIN32) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale) +endif(WIN32) IF(BOOST_STATIC) set(Boost_USE_STATIC_LIBS ON) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index a4e5cad4df..e9e4302758 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -15,6 +14,9 @@ namespace bfs = boost::filesystem; int main(int argc, char *argv[]) { #else +// Include on Windows only +#include + class utf8argv { public: diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 6141790a8c..4576432e1c 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -144,7 +144,11 @@ if(WIN32) set(QT_USE_QTMAIN TRUE) endif(WIN32) -set(BOOST_COMPONENTS system filesystem program_options thread wave locale) +set(BOOST_COMPONENTS system filesystem program_options thread wave) +if(WIN32) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale) +endif(WIN32) + find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index cf72cc7325..9e959a986d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -82,7 +82,11 @@ add_openmw_dir (mwbase ) # Main executable -set(BOOST_COMPONENTS system filesystem program_options thread wave locale) +set(BOOST_COMPONENTS system filesystem program_options thread wave) +if(WIN32) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale) +endif(WIN32) + find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) IF(OGRE_STATIC) From 663d5c314e38df474899744cdabdce56d063f792 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 22 May 2014 16:35:57 +0400 Subject: [PATCH 37/82] be more verbose on change reasons --- apps/mwiniimporter/main.cpp | 7 +++++++ components/files/windowspath.cpp | 7 +++++++ components/ogreinit/ogreinit.cpp | 8 ++++++++ extern/oics/tinyxml.cpp | 2 +- extern/shiny/Main/Preprocessor.cpp | 9 +++++++++ libs/openengine/gui/loglistener.hpp | 2 ++ libs/openengine/gui/manager.cpp | 4 ++++ libs/openengine/ogre/renderer.cpp | 4 ++++ 8 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index e9e4302758..c2408a5541 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -41,6 +41,13 @@ private: std::vector args; }; +/* The only way to pass Unicode on Winodws with CLI is to use wide + characters interface which presents UTF-16 encoding. The rest of + OpenMW application stack assumes UTF-8 encoding, therefore this + conversion. + + For boost::filesystem::path::imbue see components/files/windowspath.cpp +*/ int wmain(int argc, wchar_t *wargv[]) { utf8argv converter(argc, wargv); char **argv = converter.get(); diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 41240ae488..6b58304a0f 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -27,6 +27,13 @@ namespace Files WindowsPath::WindowsPath(const std::string& application_name) : mName(application_name) { + /* Since on Windows boost::path.string() returns string of narrow + characters in local encoding, it is required to path::imbue() + with UTF-8 encoding (generated for empty name from boost::locale) + to handle Unicode in platform-agnostic way using std::string. + + See boost::filesystem and boost::locale reference for details. + */ boost::filesystem::path::imbue(boost::locale::generator().generate("")); } diff --git a/components/ogreinit/ogreinit.cpp b/components/ogreinit/ogreinit.cpp index 44d5fe3d53..77dbcb1ee1 100644 --- a/components/ogreinit/ogreinit.cpp +++ b/components/ogreinit/ogreinit.cpp @@ -26,6 +26,13 @@ namespace bfs = boost::filesystem; namespace { + /** \brief Custom Ogre::LogListener interface implementation being + able to portably handle UTF-8 encoded path. + + Effectively this is used in conjunction with default listener, + but since on every message messageLogged() set 'skip' flag to + true, there should be no troubles sharing same file. + */ class LogListener : public Ogre::LogListener { bfs::ofstream file; @@ -87,6 +94,7 @@ namespace OgreInit Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath); #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + // Use custom listener only on Windows log->addListener(new LogListener(logPath)); #endif diff --git a/extern/oics/tinyxml.cpp b/extern/oics/tinyxml.cpp index 5be99f166a..21b2d9c9a3 100644 --- a/extern/oics/tinyxml.cpp +++ b/extern/oics/tinyxml.cpp @@ -32,7 +32,7 @@ distribution. #include "tinyxml.h" #ifdef _WIN32 -#include +#include // import MultiByteToWideChar #endif diff --git a/extern/shiny/Main/Preprocessor.cpp b/extern/shiny/Main/Preprocessor.cpp index bc2957da1b..c03879d460 100644 --- a/extern/shiny/Main/Preprocessor.cpp +++ b/extern/shiny/Main/Preprocessor.cpp @@ -6,6 +6,15 @@ #include +/* + Almost exact copy of load_file_to_string policy found in + boost::wave headers with the only change that it uses + boost::filesystem facility to handle UTF-8 paths used + throughout OpenMW (bfs::fstream, bfs::path). + + Original namespace is used due to required bost::wave + internal symbols. +*/ namespace boost { namespace wave { namespace iteration_context_policies { diff --git a/libs/openengine/gui/loglistener.hpp b/libs/openengine/gui/loglistener.hpp index 20f23cf0ce..47978ba447 100644 --- a/libs/openengine/gui/loglistener.hpp +++ b/libs/openengine/gui/loglistener.hpp @@ -8,6 +8,8 @@ namespace MyGUI { + /// \brief Custom MyGUI::ILogListener interface implementation + /// being able to portably handle UTF-8 encoded path. class CustomLogListener : public ILogListener { public: diff --git a/libs/openengine/gui/manager.cpp b/libs/openengine/gui/manager.cpp index fa7419b32d..383d37640b 100644 --- a/libs/openengine/gui/manager.cpp +++ b/libs/openengine/gui/manager.cpp @@ -559,6 +559,8 @@ public: } }; +/// \brief Helper class holding data that required during +/// MyGUI log creation class LogFacility { ConsoleLogListener mConsole; @@ -615,6 +617,8 @@ void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool mRenderManager = new MyGUI::OgreRenderManager(); mDataManager = new MyGUI::FixedOgreDataManager(); + // Do not use default log since it don't support Unicode path on Windows. + // Instead, manually create log source using LogFacility and pass it. mLogFacility = new MyGUI::LogFacility(theLogFile, logging); LogManager::getInstance().addLogSource(mLogFacility->getSource()); diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 64d65ea0da..8fcf615ba4 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -51,6 +51,10 @@ void OgreRenderer::update(float dt) void OgreRenderer::screenshot(const std::string &file) { + /* Since Ogre uses narrow character interfaces, it does not support + Unicode paths on Windows. Therefore we had to implement screenshot + saving manually. + */ namespace bfs = boost::filesystem; bfs::ofstream out(bfs::path(file), std::ios::binary); From 4b5f02f6447a6596640c155c5eaaab7318d43d20 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 15:29:36 +0200 Subject: [PATCH 38/82] Remove useless throwing of exception --- apps/openmw/mwmechanics/levelledlist.hpp | 38 +++++++++++------------- apps/openmw/mwworld/esmstore.hpp | 3 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwmechanics/levelledlist.hpp b/apps/openmw/mwmechanics/levelledlist.hpp index 6888d88a68..5d9e291181 100644 --- a/apps/openmw/mwmechanics/levelledlist.hpp +++ b/apps/openmw/mwmechanics/levelledlist.hpp @@ -53,29 +53,27 @@ namespace MWMechanics return std::string(); std::string item = candidates[std::rand()%candidates.size()]; - // Is this another levelled item or a real item? - try + // Vanilla doesn't fail on nonexistent items in levelled lists + if (!MWBase::Environment::get().getWorld()->getStore().find(Misc::StringUtils::lowerCase(item))) { - MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), item, 1); - if (ref.getPtr().getTypeName() != typeid(ESM::ItemLevList).name() - && ref.getPtr().getTypeName() != typeid(ESM::CreatureLevList).name()) - { - return item; - } - else - { - if (ref.getPtr().getTypeName() == typeid(ESM::ItemLevList).name()) - return getLevelledItem(ref.getPtr().get()->mBase, failChance); - else - return getLevelledItem(ref.getPtr().get()->mBase, failChance); - } - } - catch (std::logic_error&) - { - // Vanilla doesn't fail on nonexistent items in levelled lists - std::cerr << "Warning: ignoring nonexistent item '" << item << "'" << std::endl; + std::cerr << "Warning: ignoring nonexistent item '" << item << "' in levelled list '" << levItem->mId << "'" << std::endl; return std::string(); } + + // Is this another levelled item or a real item? + MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), item, 1); + if (ref.getPtr().getTypeName() != typeid(ESM::ItemLevList).name() + && ref.getPtr().getTypeName() != typeid(ESM::CreatureLevList).name()) + { + return item; + } + else + { + if (ref.getPtr().getTypeName() == typeid(ESM::ItemLevList).name()) + return getLevelledItem(ref.getPtr().get()->mBase, failChance); + else + return getLevelledItem(ref.getPtr().get()->mBase, failChance); + } } } diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index c6c9c1ffe2..90786acd42 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -85,7 +85,8 @@ namespace MWWorld return mStores.end(); } - // Look up the given ID in 'all'. Returns 0 if not found. + /// Look up the given ID in 'all'. Returns 0 if not found. + /// \note id must be in lower case. int find(const std::string &id) const { std::map::const_iterator it = mIds.find(id); From cba50c733839390736fa648f777dcddfcc99a90c Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 15:46:35 +0200 Subject: [PATCH 39/82] Optimize ManualRef: look up correct Store instead of searching --- apps/openmw/mwworld/manualref.hpp | 75 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index 0e21c55acd..99accbb979 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -19,54 +19,57 @@ namespace MWWorld ManualRef& operator= (const ManualRef&); template - bool create (const MWWorld::Store& list, const std::string& name) + void create (const MWWorld::Store& list, const std::string& name) { - if (const T *instance = list.search (name)) - { - LiveCellRef ref; - ref.mBase = instance; - ref.mRef.mRefNum.mIndex = 0; - ref.mRef.mRefNum.mContentFile = -1; + const T* base = list.find(name); - mRef = ref; - mPtr = Ptr (&boost::any_cast&> (mRef), 0); + LiveCellRef ref; + ref.mBase = base; + ref.mRef.mRefNum.mIndex = 0; + ref.mRef.mRefNum.mContentFile = -1; - return true; - } - - return false; + mRef = ref; + mPtr = Ptr (&boost::any_cast&> (mRef), 0); } public: ManualRef (const MWWorld::ESMStore& store, const std::string& name, const int count=1) { - // create - if (!create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name) && - !create (store.get(), name)) - throw std::logic_error ("failed to create manual cell ref for " + name); + std::string lowerName = Misc::StringUtils::lowerCase (name); + switch (store.find (lowerName)) + { + case ESM::REC_ACTI: create (store.get(), lowerName); break; + case ESM::REC_ALCH: create (store.get(), lowerName); break; + case ESM::REC_APPA: create (store.get(), lowerName); break; + case ESM::REC_ARMO: create (store.get(), lowerName); break; + case ESM::REC_BOOK: create (store.get(), lowerName); break; + case ESM::REC_CLOT: create (store.get(), lowerName); break; + case ESM::REC_CONT: create (store.get(), lowerName); break; + case ESM::REC_CREA: create (store.get(), lowerName); break; + case ESM::REC_DOOR: create (store.get(), lowerName); break; + case ESM::REC_INGR: create (store.get(), lowerName); break; + case ESM::REC_LEVC: create (store.get(), lowerName); break; + case ESM::REC_LEVI: create (store.get(), lowerName); break; + case ESM::REC_LIGH: create (store.get(), lowerName); break; + case ESM::REC_LOCK: create (store.get(), lowerName); break; + case ESM::REC_MISC: create (store.get(), lowerName); break; + case ESM::REC_NPC_: create (store.get(), lowerName); break; + case ESM::REC_PROB: create (store.get(), lowerName); break; + case ESM::REC_REPA: create (store.get(), lowerName); break; + case ESM::REC_STAT: create (store.get(), lowerName); break; + case ESM::REC_WEAP: create (store.get(), lowerName); break; + + case 0: + throw std::logic_error ("failed to create manual cell ref for " + lowerName + " (unknown ID)"); + + default: + throw std::logic_error ("failed to create manual cell ref for " + lowerName + " (unknown type)"); + } // initialise ESM::CellRef& cellRef = mPtr.getCellRef(); - cellRef.mRefID = Misc::StringUtils::lowerCase (name); + cellRef.mRefID = lowerName; cellRef.mRefNum.mIndex = 0; cellRef.mRefNum.mContentFile = -1; cellRef.mScale = 1; From 20cfdd4b433fb90a64a08a540e50deaae0181b58 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Thu, 8 May 2014 13:47:54 +0200 Subject: [PATCH 40/82] Move LiveCellRefBase ctor where it belongs to --- apps/openmw/mwworld/livecellref.cpp | 5 +++++ apps/openmw/mwworld/ptr.cpp | 11 ++--------- apps/openmw/mwworld/ptr.hpp | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 4a610b45ca..1b13e38038 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -10,6 +10,11 @@ #include "class.hpp" #include "esmstore.hpp" +MWWorld::LiveCellRefBase::LiveCellRefBase(std::string type, const ESM::CellRef &cref) + : mClass(&Class::get(type)), mRef(cref), mData(mRef) +{ +} + void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state) { mRef = state.mRef; diff --git a/apps/openmw/mwworld/ptr.cpp b/apps/openmw/mwworld/ptr.cpp index 3920a3e794..b047ba47ca 100644 --- a/apps/openmw/mwworld/ptr.cpp +++ b/apps/openmw/mwworld/ptr.cpp @@ -5,14 +5,7 @@ #include "containerstore.hpp" #include "class.hpp" - - -/* This shouldn't really be here. */ -MWWorld::LiveCellRefBase::LiveCellRefBase(std::string type, const ESM::CellRef &cref) - : mClass(&Class::get(type)), mRef(cref), mData(mRef) -{ -} - +#include "livecellref.hpp" const std::string& MWWorld::Ptr::getTypeName() const { @@ -59,4 +52,4 @@ MWWorld::ContainerStore *MWWorld::Ptr::getContainerStore() const MWWorld::Ptr::operator const void *() { return mRef; -} \ No newline at end of file +} diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index b830692831..f4696d3b3b 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -7,12 +7,12 @@ #include #include "cellreflist.hpp" -#include "livecellref.hpp" namespace MWWorld { class ContainerStore; class CellStore; + class LiveCellRefBase; /// \brief Pointer to a LiveCellRef From 1e4a854433115efa142001479489a23aa79dd0c4 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Thu, 22 May 2014 20:37:22 +0200 Subject: [PATCH 41/82] Remove static method MWWorld::Class::get(&Ptr) It was just adding a level of indirection to Ptr.getClass(). All the call were replaced by that instead. The number of lines changed is important, but the change itself is trivial, so everything should be fine. :) --- apps/openmw/engine.cpp | 4 +- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 2 +- apps/openmw/mwclass/book.cpp | 2 +- apps/openmw/mwclass/clothing.cpp | 2 +- apps/openmw/mwclass/container.cpp | 6 +- apps/openmw/mwclass/creature.cpp | 6 +- apps/openmw/mwclass/door.cpp | 4 +- apps/openmw/mwclass/ingredient.cpp | 2 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 26 ++-- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/weapon.cpp | 2 +- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 8 +- apps/openmw/mwdialogue/filter.cpp | 94 ++++++------ apps/openmw/mwgui/alchemywindow.cpp | 4 +- apps/openmw/mwgui/charactercreation.cpp | 4 +- apps/openmw/mwgui/companionwindow.cpp | 16 +- apps/openmw/mwgui/container.cpp | 18 +-- apps/openmw/mwgui/containeritemmodel.cpp | 4 +- apps/openmw/mwgui/dialogue.cpp | 4 +- apps/openmw/mwgui/enchantingdialog.cpp | 6 +- apps/openmw/mwgui/hud.cpp | 18 +-- apps/openmw/mwgui/inventoryitemmodel.cpp | 4 +- apps/openmw/mwgui/inventorywindow.cpp | 24 +-- apps/openmw/mwgui/itemmodel.cpp | 2 +- apps/openmw/mwgui/itemview.cpp | 2 +- apps/openmw/mwgui/levelupdialog.cpp | 10 +- apps/openmw/mwgui/merchantrepair.cpp | 12 +- apps/openmw/mwgui/quickkeysmenu.cpp | 18 +-- apps/openmw/mwgui/recharge.cpp | 8 +- apps/openmw/mwgui/repair.cpp | 12 +- apps/openmw/mwgui/sortfilteritemmodel.cpp | 4 +- apps/openmw/mwgui/spellbuyingwindow.cpp | 6 +- apps/openmw/mwgui/spellcreationdialog.cpp | 4 +- apps/openmw/mwgui/spellicons.cpp | 4 +- apps/openmw/mwgui/spellwindow.cpp | 18 +-- apps/openmw/mwgui/statswindow.cpp | 4 +- apps/openmw/mwgui/tooltips.cpp | 4 +- apps/openmw/mwgui/tradeitemmodel.cpp | 6 +- apps/openmw/mwgui/tradewindow.cpp | 14 +- apps/openmw/mwgui/trainingwindow.cpp | 8 +- apps/openmw/mwgui/travelwindow.cpp | 2 +- apps/openmw/mwgui/waitdialog.cpp | 6 +- apps/openmw/mwgui/windowmanagerimp.cpp | 8 +- apps/openmw/mwinput/inputmanagerimp.cpp | 6 +- apps/openmw/mwmechanics/actors.cpp | 28 ++-- apps/openmw/mwmechanics/aiactivate.cpp | 2 +- apps/openmw/mwmechanics/aiavoiddoor.cpp | 2 +- apps/openmw/mwmechanics/aiescort.cpp | 2 +- apps/openmw/mwmechanics/aiwander.cpp | 2 +- apps/openmw/mwmechanics/alchemy.cpp | 8 +- apps/openmw/mwmechanics/character.cpp | 10 +- apps/openmw/mwmechanics/enchanting.cpp | 12 +- .../mwmechanics/mechanicsmanagerimp.cpp | 28 ++-- apps/openmw/mwmechanics/repair.cpp | 14 +- apps/openmw/mwmechanics/security.cpp | 10 +- apps/openmw/mwrender/characterpreview.cpp | 2 +- apps/openmw/mwrender/npcanimation.cpp | 10 +- apps/openmw/mwrender/renderingmanager.cpp | 12 +- apps/openmw/mwscript/aiextensions.cpp | 28 ++-- apps/openmw/mwscript/compilercontext.cpp | 2 +- apps/openmw/mwscript/containerextensions.cpp | 12 +- apps/openmw/mwscript/dialogueextensions.cpp | 8 +- apps/openmw/mwscript/interpretercontext.cpp | 16 +- apps/openmw/mwscript/miscextensions.cpp | 20 +-- apps/openmw/mwscript/statsextensions.cpp | 140 +++++++++--------- .../mwscript/transformationextensions.cpp | 4 +- apps/openmw/mwworld/actionapply.cpp | 6 +- apps/openmw/mwworld/actioneat.cpp | 6 +- apps/openmw/mwworld/actionequip.cpp | 2 +- apps/openmw/mwworld/actionread.cpp | 2 +- apps/openmw/mwworld/cellstore.cpp | 2 +- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 6 - apps/openmw/mwworld/containerstore.cpp | 8 +- apps/openmw/mwworld/inventorystore.cpp | 12 +- apps/openmw/mwworld/localscripts.cpp | 4 +- apps/openmw/mwworld/physicssystem.cpp | 6 +- apps/openmw/mwworld/player.cpp | 18 +-- apps/openmw/mwworld/scene.cpp | 6 +- apps/openmw/mwworld/worldimp.cpp | 36 ++--- 82 files changed, 453 insertions(+), 459 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 26ff7e96ed..41977ad7ed 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -492,11 +492,11 @@ void OMW::Engine::activate() MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); boost::shared_ptr action = - MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayerPtr()); + ptr.getClass().activate (ptr, MWBase::Environment::get().getWorld()->getPlayerPtr()); interpreterContext.activate (ptr, action); - std::string script = MWWorld::Class::get (ptr).getScript (ptr); + std::string script = ptr.getClass().getScript (ptr); MWBase::Environment::get().getWorld()->breakInvisibility(MWBase::Environment::get().getWorld()->getPlayerPtr()); diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 16ab6321d5..fe9368b446 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -108,7 +108,7 @@ namespace MWClass boost::shared_ptr Activator::activate(const MWWorld::Ptr &ptr, const MWWorld::Ptr &actor) const { - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfActivator"); diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 550151e43b..26d1cab6d2 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -295,7 +295,7 @@ namespace MWClass return std::make_pair(0, "#{sInventoryMessage1}"); // slots that this item can be equipped in - std::pair, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); + std::pair, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr); if (slots_.first.empty()) return std::make_pair(0, ""); diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index ebc3b18e6f..183d91ca1f 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -61,7 +61,7 @@ namespace MWClass boost::shared_ptr Book::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfItem"); diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 18a40d5d30..a174f69a77 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -233,7 +233,7 @@ namespace MWClass std::pair Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const { // slots that this item can be equipped in - std::pair, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); + std::pair, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr); if (slots_.first.empty()) return std::make_pair(0, ""); diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 2d9695c6b9..62734c03de 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -112,7 +112,7 @@ namespace MWClass if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) return boost::shared_ptr (new MWWorld::NullAction ()); - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfContainer"); @@ -127,7 +127,7 @@ namespace MWClass const std::string trapActivationSound = "Disarm Trap Fail"; MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); + MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); bool needKey = ptr.getCellRef().mLockLevel > 0; bool hasKey = false; @@ -143,7 +143,7 @@ namespace MWClass if (refId == keyId) { hasKey = true; - keyName = MWWorld::Class::get(*it).getName(*it); + keyName = it->getClass().getName(*it); } } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 924021faae..7e484f9d48 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -277,7 +277,7 @@ namespace MWClass if (!weapon.isEmpty()) { - const bool weaphashealth = get(weapon).hasItemHealth(weapon); + const bool weaphashealth = weapon.getClass().hasItemHealth(weapon); const unsigned char *attack = NULL; if(type == ESM::Weapon::AT_Chop) attack = weapon.get()->mBase->mData.mChop; @@ -354,7 +354,7 @@ namespace MWClass } if(!object.isEmpty()) - getCreatureStats(ptr).setLastHitObject(MWWorld::Class::get(object).getId(object)); + getCreatureStats(ptr).setLastHitObject(object.getClass().getId(object)); if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player") { @@ -444,7 +444,7 @@ namespace MWClass boost::shared_ptr Creature::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfCreature"); diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 06f0619cec..27903c4103 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -99,7 +99,7 @@ namespace MWClass const std::string lockedSound = "LockedDoor"; const std::string trapActivationSound = "Disarm Trap Fail"; - MWWorld::ContainerStore &invStore = get(actor).getContainerStore(actor); + MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); bool needKey = ptr.getCellRef().mLockLevel > 0; bool hasKey = false; @@ -115,7 +115,7 @@ namespace MWClass if (refId == keyId) { hasKey = true; - keyName = get(*it).getName(*it); + keyName = it->getClass().getName(*it); } } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index e15424c388..ebe41bb537 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -153,7 +153,7 @@ namespace MWClass } MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats (player); int alchemySkill = npcStats.getSkill (ESM::Skill::Alchemy).getBase(); static const float fWortChanceValue = diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index bd25b66b2c..1b28a84625 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -250,7 +250,7 @@ namespace MWClass std::pair Light::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const { - MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc); + MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc); MWWorld::ContainerStoreIterator weapon = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if(weapon == invStore.end()) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 72505fa081..bca7708eab 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -484,10 +484,10 @@ namespace MWClass if(victim.isEmpty()) // Didn't hit anything return; - const MWWorld::Class &othercls = MWWorld::Class::get(victim); + const MWWorld::Class &othercls = victim.getClass(); if(!othercls.isActor()) // Can't hit non-actors return; - MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); + MWMechanics::CreatureStats &otherstats = othercls.getCreatureStats(victim); if(otherstats.isDead()) // Can't hit dead actors return; @@ -496,7 +496,7 @@ namespace MWClass int weapskill = ESM::Skill::HandToHand; if(!weapon.isEmpty()) - weapskill = get(weapon).getEquipmentSkill(weapon); + weapskill = weapon.getClass().getEquipmentSkill(weapon); float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.getClass().getSkill(ptr, weapskill)); @@ -511,7 +511,7 @@ namespace MWClass MWMechanics::NpcStats &stats = getNpcStats(ptr); if(!weapon.isEmpty()) { - const bool weaphashealth = get(weapon).hasItemHealth(weapon); + const bool weaphashealth = weapon.getClass().hasItemHealth(weapon); const unsigned char *attack = NULL; if(type == ESM::Weapon::AT_Chop) attack = weapon.get()->mBase->mData.mChop; @@ -637,7 +637,7 @@ namespace MWClass } if(!object.isEmpty()) - getCreatureStats(ptr).setLastHitObject(get(object).getId(object)); + getCreatureStats(ptr).setLastHitObject(object.getClass().getId(object)); if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player") { @@ -716,9 +716,9 @@ namespace MWClass inv.unequipItem(armor, ptr); if (ptr.getRefData().getHandle() == "player") - skillUsageSucceeded(ptr, get(armor).getEquipmentSkill(armor), 0); + skillUsageSucceeded(ptr, armor.getClass().getEquipmentSkill(armor), 0); - switch(get(armor).getEquipmentSkill(armor)) + switch(armor.getClass().getEquipmentSkill(armor)) { case ESM::Skill::LightArmor: sndMgr->playSound3D(ptr, "Light Armor Hit", 1.0f, 1.0f); @@ -802,7 +802,7 @@ namespace MWClass if(ptr.getRefData().getHandle() == "player") return boost::shared_ptr(new MWWorld::ActionTalk(actor)); - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfNPC"); @@ -814,7 +814,7 @@ namespace MWClass } if(getCreatureStats(ptr).isDead()) return boost::shared_ptr(new MWWorld::ActionOpen(ptr, true)); - if(get(ptr).getCreatureStats(ptr).isHostile()) + if(ptr.getClass().getCreatureStats(ptr).isHostile()) return boost::shared_ptr(new MWWorld::FailedAction("#{sActorInCombat}")); if(getCreatureStats(actor).getStance(MWMechanics::CreatureStats::Stance_Sneak)) return boost::shared_ptr(new MWWorld::ActionOpen(ptr)); // stealing @@ -943,7 +943,7 @@ namespace MWClass if (fallHeight >= fallDistanceMin) { - const float acrobaticsSkill = MWWorld::Class::get(ptr).getNpcStats (ptr).getSkill(ESM::Skill::Acrobatics).getModified(); + const float acrobaticsSkill = ptr.getClass().getNpcStats (ptr).getSkill(ESM::Skill::Acrobatics).getModified(); const NpcCustomData *npcdata = static_cast(ptr.getRefData().getCustomData()); const float jumpSpellBonus = npcdata->mNpcStats.getMagicEffects().get(ESM::MagicEffect::Jump).mMagnitude; const float fallAcroBase = gmst.find("fFallAcroBase")->getFloat(); @@ -1107,7 +1107,7 @@ namespace MWClass { MWWorld::LiveCellRef *ref = it->get(); - int armorSkillType = MWWorld::Class::get(*it).getEquipmentSkill(*it); + int armorSkillType = it->getClass().getEquipmentSkill(*it); int armorSkill = stats.getSkill(armorSkillType).getModified(); if(ref->mBase->mData.mWeight == 0) @@ -1177,7 +1177,7 @@ namespace MWClass if(boots == inv.end() || boots->getTypeName() != typeid(ESM::Armor).name()) return "FootBareLeft"; - switch(Class::get(*boots).getEquipmentSkill(*boots)) + switch(boots->getClass().getEquipmentSkill(*boots)) { case ESM::Skill::LightArmor: return "FootLightLeft"; @@ -1204,7 +1204,7 @@ namespace MWClass if(boots == inv.end() || boots->getTypeName() != typeid(ESM::Armor).name()) return "FootBareRight"; - switch(Class::get(*boots).getEquipmentSkill(*boots)) + switch(boots->getClass().getEquipmentSkill(*boots)) { case ESM::Skill::LightArmor: return "FootLightRight"; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 216f815cd6..f9d7947a66 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -133,7 +133,7 @@ namespace MWClass // hide effects the player doesnt know about MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats (player); int alchemySkill = npcStats.getSkill (ESM::Skill::Alchemy).getBase(); int i=0; static const float fWortChanceValue = diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index e9b0c8f3cb..146251ca29 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -392,7 +392,7 @@ namespace MWClass if (ptr.getCellRef().mCharge == 0) return std::make_pair(0, "#{sInventoryMessage1}"); - std::pair, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); + std::pair, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr); if (slots_.first.empty()) return std::make_pair (0, ""); diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index fe37f37ff7..c7e832e4ab 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -134,13 +134,13 @@ namespace MWDialogue mActor = actor; - MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor); + MWMechanics::CreatureStats& creatureStats = actor.getClass().getCreatureStats (actor); mTalkedTo = creatureStats.hasTalkedToPlayer(); mActorKnownTopics.clear(); MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow(); - win->startDialogue(actor, MWWorld::Class::get (actor).getName (actor)); + win->startDialogue(actor, actor.getClass().getName (actor)); //setup the list of topics known by the actor. Topics who are also on the knownTopics list will be added to the GUI updateTopics(); @@ -194,7 +194,7 @@ namespace MWDialogue Compiler::Locals locals; - std::string actorScript = MWWorld::Class::get (mActor).getScript (mActor); + std::string actorScript = mActor.getClass().getScript (mActor); if (!actorScript.empty()) { @@ -435,7 +435,7 @@ namespace MWDialogue // Apply disposition change to NPC's base disposition if (mActor.getClass().isNpc()) { - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(mActor).getNpcStats(mActor); + MWMechanics::NpcStats& npcStats = mActor.getClass().getNpcStats(mActor); npcStats.setBaseDisposition(npcStats.getBaseDisposition() + mPermanentDispositionChange); } mPermanentDispositionChange = 0; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 8b9ee9184f..0678623455 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -25,7 +25,7 @@ bool MWDialogue::Filter::testActor (const ESM::DialInfo& info) const // actor id if (!info.mActor.empty()) { - if ( !Misc::StringUtils::ciEqual(info.mActor, MWWorld::Class::get (mActor).getId (mActor))) + if ( !Misc::StringUtils::ciEqual(info.mActor, mActor.getClass().getId (mActor))) return false; } else if (isCreature) @@ -64,7 +64,7 @@ bool MWDialogue::Filter::testActor (const ESM::DialInfo& info) const if (isCreature) return false; - MWMechanics::NpcStats& stats = MWWorld::Class::get (mActor).getNpcStats (mActor); + MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats (mActor); std::map::iterator iter = stats.getFactionRanks().find ( Misc::StringUtils::lowerCase (info.mFaction)); if (iter==stats.getFactionRanks().end()) @@ -98,7 +98,7 @@ bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const // check player faction if (!info.mPcFaction.empty()) { - MWMechanics::NpcStats& stats = MWWorld::Class::get (player).getNpcStats (player); + MWMechanics::NpcStats& stats = player.getClass().getNpcStats (player); std::map::iterator iter = stats.getFactionRanks().find (Misc::StringUtils::lowerCase (info.mPcFaction)); if(iter==stats.getFactionRanks().end()) @@ -182,7 +182,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c case SelectWrapper::Function_Local: { - std::string scriptName = MWWorld::Class::get (mActor).getScript (mActor); + std::string scriptName = mActor.getClass().getScript (mActor); if (scriptName.empty()) return false; // no script @@ -220,8 +220,8 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - float ratio = MWWorld::Class::get (player).getCreatureStats (player).getHealth().getCurrent() / - MWWorld::Class::get (player).getCreatureStats (player).getHealth().getModified(); + float ratio = player.getClass().getCreatureStats (player).getHealth().getCurrent() / + player.getClass().getCreatureStats (player).getHealth().getModified(); return select.selectCompare (static_cast(ratio*100)); } @@ -230,7 +230,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - float value = MWWorld::Class::get (player).getCreatureStats (player). + float value = player.getClass().getCreatureStats (player). getDynamic (select.getArgument()).getCurrent(); return select.selectCompare (value); @@ -238,8 +238,8 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c case SelectWrapper::Function_HealthPercent: { - float ratio = MWWorld::Class::get (mActor).getCreatureStats (mActor).getHealth().getCurrent() / - MWWorld::Class::get (mActor).getCreatureStats (mActor).getHealth().getModified(); + float ratio = mActor.getClass().getCreatureStats (mActor).getHealth().getCurrent() / + mActor.getClass().getCreatureStats (mActor).getHealth().getModified(); return select.selectCompare (ratio); } @@ -262,7 +262,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_Item: { - MWWorld::ContainerStore& store = MWWorld::Class::get (player).getContainerStore (player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore (player); int sum = 0; @@ -285,29 +285,29 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_AiSetting: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).getAiSetting ( + return mActor.getClass().getCreatureStats (mActor).getAiSetting ( (MWMechanics::CreatureStats::AiSetting)select.getArgument()).getModified(); case SelectWrapper::Function_PcAttribute: - return MWWorld::Class::get (player).getCreatureStats (player). + return player.getClass().getCreatureStats (player). getAttribute (select.getArgument()).getModified(); case SelectWrapper::Function_PcSkill: - return static_cast (MWWorld::Class::get (player). + return static_cast (player.getClass(). getNpcStats (player).getSkill (select.getArgument()).getModified()); case SelectWrapper::Function_FriendlyHit: { - int hits = MWWorld::Class::get (mActor).getCreatureStats (mActor).getFriendlyHits(); + int hits = mActor.getClass().getCreatureStats (mActor).getFriendlyHits(); return hits>4 ? 4 : hits; } case SelectWrapper::Function_PcLevel: - return MWWorld::Class::get (player).getCreatureStats (player).getLevel(); + return player.getClass().getCreatureStats (player).getLevel(); case SelectWrapper::Function_PcGender: @@ -315,7 +315,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_PcClothingModifier: { - MWWorld::InventoryStore& store = MWWorld::Class::get (player).getInventoryStore (player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore (player); int value = 0; @@ -324,7 +324,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con MWWorld::ContainerStoreIterator slot = store.getSlot (i); if (slot!=store.end()) - value += MWWorld::Class::get (*slot).getValue (*slot); + value += slot->getClass().getValue (*slot); } return value; @@ -332,15 +332,15 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_PcCrimeLevel: - return MWWorld::Class::get (player).getNpcStats (player).getBounty(); + return player.getClass().getNpcStats (player).getBounty(); case SelectWrapper::Function_RankRequirement: { - if (MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().empty()) + if (mActor.getClass().getNpcStats (mActor).getFactionRanks().empty()) return 0; std::string faction = - MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().begin()->first; + mActor.getClass().getNpcStats (mActor).getFactionRanks().begin()->first; int rank = getFactionRank (player, faction); @@ -360,11 +360,11 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_Level: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).getLevel(); + return mActor.getClass().getCreatureStats (mActor).getLevel(); case SelectWrapper::Function_PCReputation: - return MWWorld::Class::get (player).getNpcStats (player).getReputation(); + return player.getClass().getNpcStats (player).getReputation(); case SelectWrapper::Function_Weather: @@ -372,15 +372,15 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_Reputation: - return MWWorld::Class::get (mActor).getNpcStats (mActor).getReputation(); + return mActor.getClass().getNpcStats (mActor).getReputation(); case SelectWrapper::Function_FactionRankDiff: { - if (MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().empty()) + if (mActor.getClass().getNpcStats (mActor).getFactionRanks().empty()) return 0; std::pair faction = - *MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().begin(); + *mActor.getClass().getNpcStats (mActor).getFactionRanks().begin(); int rank = getFactionRank (player, faction.first); @@ -389,25 +389,25 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_WerewolfKills: - return MWWorld::Class::get (player).getNpcStats (player).getWerewolfKills(); + return player.getClass().getNpcStats (player).getWerewolfKills(); case SelectWrapper::Function_RankLow: case SelectWrapper::Function_RankHigh: { bool low = select.getFunction()==SelectWrapper::Function_RankLow; - if (MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().empty()) + if (mActor.getClass().getNpcStats (mActor).getFactionRanks().empty()) return 0; std::string factionId = - MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().begin()->first; + mActor.getClass().getNpcStats (mActor).getFactionRanks().begin()->first; int value = 0; const ESM::Faction& faction = *MWBase::Environment::get().getWorld()->getStore().get().find (factionId); - MWMechanics::NpcStats& playerStats = MWWorld::Class::get (player).getNpcStats (player); + MWMechanics::NpcStats& playerStats = player.getClass().getNpcStats (player); for (std::vector::const_iterator iter (faction.mReactions.begin()); iter!=faction.mReactions.end(); ++iter) @@ -436,7 +436,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_NotId: - return !Misc::StringUtils::ciEqual(MWWorld::Class::get (mActor).getId (mActor), select.getName()); + return !Misc::StringUtils::ciEqual(mActor.getClass().getId (mActor), select.getName()); case SelectWrapper::Function_NotFaction: @@ -456,7 +456,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_NotLocal: { - std::string scriptName = MWWorld::Class::get (mActor).getScript (mActor); + std::string scriptName = mActor.getClass().getScript (mActor); if (scriptName.empty()) // This actor has no attached script, so there is no local variable @@ -489,36 +489,36 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_SameFaction: - return MWWorld::Class::get (mActor).getNpcStats (mActor).isSameFaction ( - MWWorld::Class::get (player).getNpcStats (player)); + return mActor.getClass().getNpcStats (mActor).isSameFaction ( + player.getClass().getNpcStats (player)); case SelectWrapper::Function_PcCommonDisease: - return MWWorld::Class::get (player).getCreatureStats (player).hasCommonDisease(); + return player.getClass().getCreatureStats (player).hasCommonDisease(); case SelectWrapper::Function_PcBlightDisease: - return MWWorld::Class::get (player).getCreatureStats (player).hasBlightDisease(); + return player.getClass().getCreatureStats (player).hasBlightDisease(); case SelectWrapper::Function_PcCorprus: - return MWWorld::Class::get (player).getCreatureStats (player). + return player.getClass().getCreatureStats (player). getMagicEffects().get (ESM::MagicEffect::Corprus).mMagnitude!=0; case SelectWrapper::Function_PcExpelled: { - if (MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().empty()) + if (mActor.getClass().getNpcStats (mActor).getFactionRanks().empty()) return false; std::string faction = - MWWorld::Class::get (mActor).getNpcStats (mActor).getFactionRanks().begin()->first; + mActor.getClass().getNpcStats (mActor).getFactionRanks().begin()->first; return player.getClass().getNpcStats(player).getExpelled(faction); } case SelectWrapper::Function_PcVampire: - return MWWorld::Class::get (player).getCreatureStats(player).getMagicEffects(). + return player.getClass().getCreatureStats(player).getMagicEffects(). get(ESM::MagicEffect::Vampirism).mMagnitude > 0; case SelectWrapper::Function_TalkedToPc: @@ -527,7 +527,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_Alarmed: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).isAlarmed(); + return mActor.getClass().getCreatureStats (mActor).isAlarmed(); case SelectWrapper::Function_Detected: @@ -535,11 +535,11 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_Attacked: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).getAttacked(); + return mActor.getClass().getCreatureStats (mActor).getAttacked(); case SelectWrapper::Function_ShouldAttack: - return MWWorld::Class::get (mActor).getCreatureStats (mActor).isHostile(); + return mActor.getClass().getCreatureStats (mActor).isHostile(); case SelectWrapper::Function_CreatureTargetted: @@ -547,7 +547,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_Werewolf: - return MWWorld::Class::get (mActor).getNpcStats (mActor).isWerewolf(); + return mActor.getClass().getNpcStats (mActor).isWerewolf(); default: @@ -557,7 +557,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co int MWDialogue::Filter::getFactionRank (const MWWorld::Ptr& actor, const std::string& factionId) const { - MWMechanics::NpcStats& stats = MWWorld::Class::get (actor).getNpcStats (actor); + MWMechanics::NpcStats& stats = actor.getClass().getNpcStats (actor); std::map::const_iterator iter = stats.getFactionRanks().find (factionId); @@ -573,13 +573,13 @@ bool MWDialogue::Filter::hasFactionRankSkillRequirements (const MWWorld::Ptr& ac if (rank<0 || rank>=10) throw std::runtime_error ("rank index out of range"); - if (!MWWorld::Class::get (actor).getNpcStats (actor).hasSkillsForRank (factionId, rank)) + if (!actor.getClass().getNpcStats (actor).hasSkillsForRank (factionId, rank)) return false; const ESM::Faction& faction = *MWBase::Environment::get().getWorld()->getStore().get().find (factionId); - MWMechanics::CreatureStats& stats = MWWorld::Class::get (actor).getCreatureStats (actor); + MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats (actor); return stats.getAttribute (faction.mData.mAttribute[0]).getBase()>=faction.mData.mRankData[rank].mAttribute1 && stats.getAttribute (faction.mData.mAttribute[1]).getBase()>=faction.mData.mRankData[rank].mAttribute2; @@ -591,7 +591,7 @@ bool MWDialogue::Filter::hasFactionRankReputationRequirements (const MWWorld::Pt if (rank<0 || rank>=10) throw std::runtime_error ("rank index out of range"); - MWMechanics::NpcStats& stats = MWWorld::Class::get (actor).getNpcStats (actor); + MWMechanics::NpcStats& stats = actor.getClass().getNpcStats (actor); const ESM::Faction& faction = *MWBase::Environment::get().getWorld()->getStore().get().find (factionId); diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index a6880ffcb5..6524c168e1 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -19,7 +19,7 @@ namespace std::string getIconPath(MWWorld::Ptr ptr) { std::string path = std::string("icons\\"); - path += MWWorld::Class::get(ptr).getInventoryIcon(ptr); + path += ptr.getClass().getInventoryIcon(ptr); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -174,7 +174,7 @@ namespace MWGui { update(); - std::string sound = MWWorld::Class::get(item).getUpSoundId(item); + std::string sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); } } diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index fa1bd28be2..85f57a1a8c 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -47,7 +47,7 @@ namespace void updatePlayerHealth() { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player); + MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); npcStats.updateHealth(); } } @@ -220,7 +220,7 @@ namespace MWGui { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); mReviewDialog->setHealth ( stats.getHealth() ); mReviewDialog->setMagicka( stats.getMagicka() ); diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp index a0a34108eb..70093049da 100644 --- a/apps/openmw/mwgui/companionwindow.cpp +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -61,7 +61,7 @@ void CompanionWindow::onItemSelected(int index) if (count > 1 && !shift) { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), "#{sTake}", count); + dialog->open(object.getClass().getName(object), "#{sTake}", count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem); } @@ -92,7 +92,7 @@ void CompanionWindow::open(const MWWorld::Ptr& npc) mSortModel = new SortFilterItemModel(mModel); mItemView->setModel(mSortModel); - setTitle(MWWorld::Class::get(npc).getName(npc)); + setTitle(npc.getClass().getName(npc)); } void CompanionWindow::onFrame() @@ -104,22 +104,22 @@ void CompanionWindow::updateEncumbranceBar() { if (mPtr.isEmpty()) return; - float capacity = MWWorld::Class::get(mPtr).getCapacity(mPtr); - float encumbrance = MWWorld::Class::get(mPtr).getEncumbrance(mPtr); + float capacity = mPtr.getClass().getCapacity(mPtr); + float encumbrance = mPtr.getClass().getEncumbrance(mPtr); mEncumbranceBar->setValue(encumbrance, capacity); if (mPtr.getTypeName() != typeid(ESM::NPC).name()) mProfitLabel->setCaption(""); else { - MWMechanics::NpcStats& stats = MWWorld::Class::get(mPtr).getNpcStats(mPtr); + MWMechanics::NpcStats& stats = mPtr.getClass().getNpcStats(mPtr); mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + boost::lexical_cast(stats.getProfit())); } } void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { - if (mPtr.getTypeName() == typeid(ESM::NPC).name() && MWWorld::Class::get(mPtr).getNpcStats(mPtr).getProfit() < 0) + if (mPtr.getTypeName() == typeid(ESM::NPC).name() && mPtr.getClass().getNpcStats(mPtr).getProfit() < 0) { std::vector buttons; buttons.push_back("#{sCompanionWarningButtonOne}"); @@ -135,8 +135,8 @@ void CompanionWindow::onMessageBoxButtonClicked(int button) { if (button == 0) { - mPtr.getRefData().getLocals().setVarByInt(MWWorld::Class::get(mPtr).getScript(mPtr), - "minimumProfit", MWWorld::Class::get(mPtr).getNpcStats(mPtr).getProfit()); + mPtr.getRefData().getLocals().setVarByInt(mPtr.getClass().getScript(mPtr), + "minimumProfit", mPtr.getClass().getNpcStats(mPtr).getProfit()); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion); MWBase::Environment::get().getDialogueManager()->startDialogue (mPtr); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 02c4b93560..a207dec0c5 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -37,7 +37,7 @@ namespace MWGui mIsOnDragAndDrop = true; mDragAndDropWidget->setVisible(true); - std::string sound = MWWorld::Class::get(mItem.mBase).getUpSoundId(mItem.mBase); + std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); if (mSourceSortModel) @@ -47,7 +47,7 @@ namespace MWGui } std::string path = std::string("icons\\"); - path += MWWorld::Class::get(mItem.mBase).getInventoryIcon(mItem.mBase); + path += mItem.mBase.getClass().getInventoryIcon(mItem.mBase); MyGUI::ImageBox* baseWidget = mDragAndDropWidget->createWidget ("ImageBox", MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default); mDraggedWidget = baseWidget; @@ -76,7 +76,7 @@ namespace MWGui void DragAndDrop::drop(ItemModel *targetModel, ItemView *targetView) { - std::string sound = MWWorld::Class::get(mItem.mBase).getDownSoundId(mItem.mBase); + std::string sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); mDragAndDropWidget->setVisible(false); @@ -155,7 +155,7 @@ namespace MWGui if (count > 1 && !shift) { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), "#{sTake}", count); + dialog->open(object.getClass().getName(object), "#{sTake}", count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem); } @@ -177,8 +177,8 @@ namespace MWGui { // check that we don't exceed container capacity MWWorld::Ptr item = mDragAndDrop->mItem.mBase; - float weight = MWWorld::Class::get(item).getWeight(item) * mDragAndDrop->mDraggedCount; - if (MWWorld::Class::get(mPtr).getCapacity(mPtr) < MWWorld::Class::get(mPtr).getEncumbrance(mPtr) + weight) + float weight = item.getClass().getWeight(item) * mDragAndDrop->mDraggedCount; + if (mPtr.getClass().getCapacity(mPtr) < mPtr.getClass().getEncumbrance(mPtr) + weight) { MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage3}"); return; @@ -227,7 +227,7 @@ namespace MWGui // Careful here. setTitle may cause size updates, causing itemview redraw, so make sure to do it last // or we end up using a possibly invalid model. - setTitle(MWWorld::Class::get(container).getName(container)); + setTitle(container.getClass().getName(container)); } void ContainerWindow::onKeyPressed(MyGUI::Widget *_sender, MyGUI::KeyCode _key, MyGUI::Char _char) @@ -284,7 +284,7 @@ namespace MWGui { // play the sound of the first object MWWorld::Ptr item = mModel->getItem(i).mBase; - std::string sound = MWWorld::Class::get(item).getUpSoundId(item); + std::string sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); } @@ -306,7 +306,7 @@ namespace MWGui { onTakeAllButtonClicked(mTakeButton); - if (MWWorld::Class::get(mPtr).isPersistent(mPtr)) + if (mPtr.getClass().isPersistent(mPtr)) MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}"); else MWBase::Environment::get().getWorld()->deleteObject(mPtr); diff --git a/apps/openmw/mwgui/containeritemmodel.cpp b/apps/openmw/mwgui/containeritemmodel.cpp index b5b498e5e6..b2befc3ba8 100644 --- a/apps/openmw/mwgui/containeritemmodel.cpp +++ b/apps/openmw/mwgui/containeritemmodel.cpp @@ -85,7 +85,7 @@ void ContainerItemModel::removeItem (const ItemStack& item, size_t count) for (std::vector::iterator source = mItemSources.begin(); source != mItemSources.end(); ++source) { - MWWorld::ContainerStore& store = MWWorld::Class::get(*source).getContainerStore(*source); + MWWorld::ContainerStore& store = source->getClass().getContainerStore(*source); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { @@ -120,7 +120,7 @@ void ContainerItemModel::update() mItems.clear(); for (std::vector::iterator source = mItemSources.begin(); source != mItemSources.end(); ++source) { - MWWorld::ContainerStore& store = MWWorld::Class::get(*source).getContainerStore(*source); + MWWorld::ContainerStore& store = source->getClass().getContainerStore(*source); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index dcd26d4698..0002757947 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -386,8 +386,8 @@ namespace MWGui mTopicLinks.clear(); mKeywordSearch.clear(); - bool isCompanion = !MWWorld::Class::get(mPtr).getScript(mPtr).empty() - && mPtr.getRefData().getLocals().getIntVar(MWWorld::Class::get(mPtr).getScript(mPtr), "companion"); + bool isCompanion = !mPtr.getClass().getScript(mPtr).empty() + && mPtr.getRefData().getLocals().getIntVar(mPtr.getClass().getScript(mPtr), "companion"); bool anyService = mServices > 0 || isCompanion || mPtr.getTypeName() == typeid(ESM::NPC).name(); diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index ada004612a..b303848df5 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -119,7 +119,7 @@ namespace MWGui MyGUI::ImageBox* image = mSoulBox->createWidget("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(soulgem).getInventoryIcon(soulgem); + path += soulgem.getClass().getInventoryIcon(soulgem); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -164,7 +164,7 @@ namespace MWGui MyGUI::ImageBox* image = mItemBox->createWidget("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -207,7 +207,7 @@ namespace MWGui MyGUI::ImageBox* image = mSoulBox->createWidget("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 079793ee19..103c48ca14 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -348,7 +348,7 @@ namespace MWGui void HUD::onWeaponClicked(MyGUI::Widget* _sender) { const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - if (MWWorld::Class::get(player).getNpcStats(player).isWerewolf()) + if (player.getClass().getNpcStats(player).isWerewolf()) { MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}"); return; @@ -360,7 +360,7 @@ namespace MWGui void HUD::onMagicClicked(MyGUI::Widget* _sender) { const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - if (MWWorld::Class::get(player).getNpcStats(player).isWerewolf()) + if (player.getClass().getNpcStats(player).isWerewolf()) { MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}"); return; @@ -443,7 +443,7 @@ namespace MWGui void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) { - std::string itemName = MWWorld::Class::get(item).getName(item); + std::string itemName = item.getClass().getName(item); if (itemName != mSpellName && mSpellVisible) { mWeaponSpellTimer = 5.0f; @@ -466,7 +466,7 @@ namespace MWGui , MyGUI::Align::Stretch); std::string path = std::string("icons\\"); - path+=MWWorld::Class::get(item).getInventoryIcon(item); + path+=item.getClass().getInventoryIcon(item); Widgets::fixTexturePath(path); itemBox->setImageTexture(path); itemBox->setNeedMouseFocus(false); @@ -474,7 +474,7 @@ namespace MWGui void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent) { - std::string itemName = MWWorld::Class::get(item).getName(item); + std::string itemName = item.getClass().getName(item); if (itemName != mWeaponName && mWeaponVisible) { mWeaponSpellTimer = 5.0f; @@ -493,10 +493,10 @@ namespace MWGui MyGUI::Gui::getInstance().destroyWidget(mWeapImage->getChildAt(0)); std::string path = std::string("icons\\"); - path+=MWWorld::Class::get(item).getInventoryIcon(item); + path+=item.getClass().getInventoryIcon(item); Widgets::fixTexturePath(path); - if (MWWorld::Class::get(item).getEnchantment(item) != "") + if (item.getClass().getEnchantment(item) != "") { mWeapImage->setImageTexture("textures\\menu_icon_magic_mini.dds"); MyGUI::ImageBox* itemBox = mWeapImage->createWidgetReal("ImageBox", MyGUI::FloatCoord(0,0,1,1) @@ -545,7 +545,7 @@ namespace MWGui MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - if (MWWorld::Class::get(player).getNpcStats(player).isWerewolf()) + if (player.getClass().getNpcStats(player).isWerewolf()) mWeapImage->setImageTexture("icons\\k\\tx_werewolf_hand.dds"); else mWeapImage->setImageTexture("icons\\k\\stealth_handtohand.dds"); @@ -636,7 +636,7 @@ namespace MWGui void HUD::updateEnemyHealthBar() { - MWMechanics::CreatureStats& stats = MWWorld::Class::get(mEnemy).getCreatureStats(mEnemy); + MWMechanics::CreatureStats& stats = mEnemy.getClass().getCreatureStats(mEnemy); mEnemyHealth->setProgressRange(100); // Health is usually cast to int before displaying. Actors die whenever they are < 1 health. // Therefore any value < 1 should show as an empty health bar. We do the same in statswindow :) diff --git a/apps/openmw/mwgui/inventoryitemmodel.cpp b/apps/openmw/mwgui/inventoryitemmodel.cpp index 718c6d991f..e1bc9d4daa 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.cpp +++ b/apps/openmw/mwgui/inventoryitemmodel.cpp @@ -50,7 +50,7 @@ MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count, void InventoryItemModel::removeItem (const ItemStack& item, size_t count) { - MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor); + MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); int removed = store.remove(item.mBase, count, mActor); if (removed == 0) @@ -77,7 +77,7 @@ MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack &item, size_t count, I void InventoryItemModel::update() { - MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor); + MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); mItems.clear(); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e9a4a18e5a..788f90f504 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -162,7 +162,7 @@ namespace MWGui } const ItemStack& item = mTradeModel->getItem(index); - std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase); + std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); MWWorld::Ptr object = item.mBase; int count = item.mCount; @@ -184,7 +184,7 @@ namespace MWGui { // check if merchant accepts item int services = MWBase::Environment::get().getWindowManager()->getTradeWindow()->getMerchantServices(); - if (!MWWorld::Class::get(object).canSell(object, services)) + if (!object.getClass().canSell(object, services)) { MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); MWBase::Environment::get().getWindowManager()-> @@ -197,7 +197,7 @@ namespace MWGui { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); std::string message = mTrading ? "#{sQuanityMenuMessage01}" : "#{sTake}"; - dialog->open(MWWorld::Class::get(object).getName(object), message, count); + dialog->open(object.getClass().getName(object), message, count); dialog->eventOkClicked.clear(); if (mTrading) dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::sellItem); @@ -223,7 +223,7 @@ namespace MWGui const ItemStack& item = mTradeModel->getItem(mSelectedItem); if (item.mType == ItemStack::Type_Equipped) { - MWWorld::InventoryStore& invStore = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); + MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr); MWWorld::Ptr newStack = *invStore.unequipItem(item.mBase, mPtr); // The unequipped item was re-stacked. We have to update the index @@ -259,7 +259,7 @@ namespace MWGui { ensureSelectedItemUnequipped(); const ItemStack& item = mTradeModel->getItem(mSelectedItem); - std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase); + std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); if (item.mType == ItemStack::Type_Barter) @@ -382,7 +382,7 @@ namespace MWGui if (script.empty() || ptr.getRefData().getLocals().getIntVar(script, "pcskipequip") == 0) { - boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); + boost::shared_ptr action = ptr.getClass().use(ptr); action->execute (MWBase::Environment::get().getWorld()->getPlayerPtr()); @@ -447,7 +447,7 @@ namespace MWGui if (slot == -1) return MWWorld::Ptr(); - MWWorld::InventoryStore& invStore = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); + MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr); if(invStore.getSlot(slot) != invStore.end()) { MWWorld::Ptr item = *invStore.getSlot(slot); @@ -466,8 +466,8 @@ namespace MWGui { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - float capacity = MWWorld::Class::get(player).getCapacity(player); - float encumbrance = MWWorld::Class::get(player).getEncumbrance(player); + float capacity = player.getClass().getCapacity(player); + float encumbrance = player.getClass().getEncumbrance(player); mEncumbranceBar->setValue(encumbrance, capacity); } @@ -498,9 +498,9 @@ namespace MWGui mAvatarImage->setImageTile(MyGUI::IntSize(std::min(512, size.width), std::min(1024, size.height))); mArmorRating->setCaptionWithReplacing ("#{sArmor}: " - + boost::lexical_cast(static_cast(MWWorld::Class::get(mPtr).getArmorRating(mPtr)))); + + boost::lexical_cast(static_cast(mPtr.getClass().getArmorRating(mPtr)))); if (mArmorRating->getTextSize().width > mArmorRating->getSize().width) - mArmorRating->setCaptionWithReplacing (boost::lexical_cast(static_cast(MWWorld::Class::get(mPtr).getArmorRating(mPtr)))); + mArmorRating->setCaptionWithReplacing (boost::lexical_cast(static_cast(mPtr.getClass().getArmorRating(mPtr)))); } } @@ -534,7 +534,7 @@ namespace MWGui && (type != typeid(ESM::Potion).name())) return; - if (MWWorld::Class::get(object).getName(object) == "") // objects without name presented to user can never be picked up + if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; int count = object.getRefData().getCount(); diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 2cdd8a2e66..55317724e3 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -13,7 +13,7 @@ namespace MWGui , mType(Type_Normal) , mBase(base) { - if (MWWorld::Class::get(base).getEnchantment(base) != "") + if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; } diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp index 027c3201fc..24bc3fd630 100644 --- a/apps/openmw/mwgui/itemview.cpp +++ b/apps/openmw/mwgui/itemview.cpp @@ -81,7 +81,7 @@ void ItemView::update() /// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item.mBase).getInventoryIcon(item.mBase); + path += item.mBase.getClass().getInventoryIcon(item.mBase); // background widget (for the "equipped" frame and magic item background image) bool isMagic = (item.mFlags & ItemStack::Flag_Enchanted); diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 5a3fc2855d..38995ac326 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -61,8 +61,8 @@ namespace MWGui void LevelupDialog::setAttributeValues() { MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player); - MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::CreatureStats& creatureStats = player.getClass().getCreatureStats (player); + MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); for (int i=0; i<8; ++i) { @@ -117,8 +117,8 @@ namespace MWGui { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player); - MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::CreatureStats& creatureStats = player.getClass().getCreatureStats (player); + MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); mSpentAttributes.clear(); resetCoins(); @@ -172,7 +172,7 @@ namespace MWGui void LevelupDialog::onOkButtonClicked (MyGUI::Widget* sender) { MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); if (mSpentAttributes.size() < 3) MWBase::Environment::get().getWindowManager ()->messageBox("#{sNotifyMessage36}"); diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 2a48e62a94..83527a8845 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -39,19 +39,19 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor) MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); iter!=store.end(); ++iter) { - if (MWWorld::Class::get(*iter).hasItemHealth(*iter)) + if (iter->getClass().hasItemHealth(*iter)) { - int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter); + int maxDurability = iter->getClass().getItemMaxHealth(*iter); int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge; if (maxDurability == durability) continue; - int basePrice = MWWorld::Class::get(*iter).getValue(*iter); + int basePrice = iter->getClass().getValue(*iter); float fRepairMult = MWBase::Environment::get().getWorld()->getStore().get() .find("fRepairMult")->getFloat(); @@ -64,7 +64,7 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor) int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mActor, x, true); - std::string name = MWWorld::Class::get(*iter).getName(*iter) + std::string name = iter->getClass().getName(*iter) + " - " + boost::lexical_cast(price) + MWBase::Environment::get().getWorld()->getStore().get() .find("sgp")->getString();; @@ -114,7 +114,7 @@ void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender) { // repair MWWorld::Ptr item = *sender->getUserData(); - item.getCellRef().mCharge = MWWorld::Class::get(item).getItemMaxHealth(item); + item.getCellRef().mCharge = item.getClass().getItemMaxHealth(item); MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1); diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 51e24e29c8..5df2b12b8d 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -166,7 +166,7 @@ namespace MWGui frame->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked); MyGUI::ImageBox* image = frame->createWidget("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -200,7 +200,7 @@ namespace MWGui MyGUI::ImageBox* image = frame->createWidget("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -265,7 +265,7 @@ namespace MWGui QuickKeyType type = *button->getUserData(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); if (type == Type_Item || type == Type_MagicItem) { @@ -290,7 +290,7 @@ namespace MWGui { // No replacement was found MWBase::Environment::get().getWindowManager ()->messageBox ( - "#{sQuickMenu5} " + MWWorld::Class::get(item).getName(item)); + "#{sQuickMenu5} " + item.getClass().getName(item)); return; } } @@ -330,7 +330,7 @@ namespace MWGui assert(it != store.end()); // equip, if it can be equipped - if (!MWWorld::Class::get(item).getEquipmentSlots(item).first.empty()) + if (!item.getClass().getEquipmentSlots(item).first.empty()) { MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item); } @@ -522,8 +522,8 @@ namespace MWGui const int spellHeight = 18; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); /// \todo lots of copy&pasted code from SpellWindow @@ -566,7 +566,7 @@ namespace MWGui std::vector items; for (MWWorld::ContainerStoreIterator it(store.begin()); it != store.end(); ++it) { - std::string enchantId = MWWorld::Class::get(*it).getEnchantment(*it); + std::string enchantId = it->getClass().getEnchantment(*it); if (enchantId != "") { // only add items with "Cast once" or "Cast on use" @@ -645,7 +645,7 @@ namespace MWGui MyGUI::Button* t = mMagicList->createWidget(equipped ? "SpellText" : "SpellTextUnequipped", MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top); - t->setCaption(MWWorld::Class::get(item).getName(item)); + t->setCaption(item.getClass().getName(item)); t->setTextAlign(MyGUI::Align::Left); t->setUserData(item); t->setUserString("ToolTipType", "ItemPtr"); diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index 683406d9eb..313650bb64 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -41,7 +41,7 @@ void Recharge::open() void Recharge::start (const MWWorld::Ptr &item) { std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -85,7 +85,7 @@ void Recharge::updateView() int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { @@ -99,14 +99,14 @@ void Recharge::updateView() MyGUI::TextBox* text = mView->createWidget ( "SandText", MyGUI::IntCoord(8, currentY, mView->getWidth()-8, 18), MyGUI::Align::Default); - text->setCaption(MWWorld::Class::get(*iter).getName(*iter)); + text->setCaption(iter->getClass().getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; MyGUI::ImageBox* icon = mView->createWidget ( "ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(*iter).getInventoryIcon(*iter); + path += iter->getClass().getInventoryIcon(*iter); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index de96bcacd1..a3df2dfbea 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -40,7 +40,7 @@ void Repair::startRepairItem(const MWWorld::Ptr &item) mRepair.setTool(item); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(item).getInventoryIcon(item); + path += item.getClass().getInventoryIcon(item); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); @@ -90,28 +90,28 @@ void Repair::updateRepairView() int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); iter!=store.end(); ++iter) { - if (MWWorld::Class::get(*iter).hasItemHealth(*iter)) + if (iter->getClass().hasItemHealth(*iter)) { - int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter); + int maxDurability = iter->getClass().getItemMaxHealth(*iter); int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge; if (maxDurability == durability) continue; MyGUI::TextBox* text = mRepairView->createWidget ( "SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default); - text->setCaption(MWWorld::Class::get(*iter).getName(*iter)); + text->setCaption(iter->getClass().getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; MyGUI::ImageBox* icon = mRepairView->createWidget ( "ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); - path += MWWorld::Class::get(*iter).getInventoryIcon(*iter); + path += iter->getClass().getInventoryIcon(*iter); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 74a4f88e79..475f73a072 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -47,8 +47,8 @@ namespace if (left.mBase.getTypeName() == right.mBase.getTypeName()) { - int cmp = MWWorld::Class::get(left.mBase).getName(left.mBase).compare( - MWWorld::Class::get(right.mBase).getName(right.mBase)); + int cmp = left.mBase.getClass().getName(left.mBase).compare( + right.mBase.getClass().getName(right.mBase)); return cmp < 0; } else diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 77df465146..99b85c13cc 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -83,7 +83,7 @@ namespace MWGui mPtr = actor; clearSpells(); - MWMechanics::Spells& merchantSpells = MWWorld::Class::get (actor).getCreatureStats (actor).getSpells(); + MWMechanics::Spells& merchantSpells = actor.getClass().getCreatureStats (actor).getSpells(); for (MWMechanics::Spells::TIterator iter = merchantSpells.begin(); iter!=merchantSpells.end(); ++iter) { @@ -107,7 +107,7 @@ namespace MWGui bool SpellBuyingWindow::playerHasSpell(const std::string &id) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::Spells& playerSpells = MWWorld::Class::get (player).getCreatureStats (player).getSpells(); + MWMechanics::Spells& playerSpells = player.getClass().getCreatureStats (player).getSpells(); for (MWMechanics::Spells::TIterator it = playerSpells.begin(); it != playerSpells.end(); ++it) { if (Misc::StringUtils::ciEqual(id, it->first)) @@ -121,7 +121,7 @@ namespace MWGui int price = *_sender->getUserData(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); spells.add (mSpellsWidgetMap.find(_sender)->second); player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price, player); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 469d7188ec..1ec4bd6da4 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -353,7 +353,7 @@ namespace MWGui const ESM::Spell* spell = MWBase::Environment::get().getWorld()->createRecord(mSpell); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); spells.add (spell->mId); @@ -445,7 +445,7 @@ namespace MWGui // get the list of magic effects that are known to the player MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); std::vector knownEffects; diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index d5ece298b0..1a9e418de6 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -40,14 +40,14 @@ namespace MWGui // TODO: Tracking add/remove/expire would be better than force updating every frame MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); EffectSourceVisitor visitor; // permanent item enchantments & permanent spells visitor.mIsPermanent = true; - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); store.visitEffectSources(visitor); stats.getSpells().visitEffectSources(visitor); diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index a00c2480e2..16e4741432 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -84,8 +84,8 @@ namespace MWGui // retrieve all player spells, divide them into Powers and Spells and sort them std::vector spellList; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); for (MWMechanics::Spells::TIterator it = spells.begin(); it != spells.end(); ++it) @@ -122,7 +122,7 @@ namespace MWGui std::vector items; for (MWWorld::ContainerStoreIterator it(store.begin()); it != store.end(); ++it) { - std::string enchantId = MWWorld::Class::get(*it).getEnchantment(*it); + std::string enchantId = it->getClass().getEnchantment(*it); if (enchantId != "") { // only add items with "Cast once" or "Cast on use" @@ -203,7 +203,7 @@ namespace MWGui MWWorld::Ptr item = *it; const ESM::Enchantment* enchant = - esmStore.get().find(MWWorld::Class::get(item).getEnchantment(item)); + esmStore.get().find(item.getClass().getEnchantment(item)); // check if the item is currently equipped (will display in a different color) bool equipped = false; @@ -218,7 +218,7 @@ namespace MWGui MyGUI::Button* t = mSpellView->createWidget(equipped ? "SpellText" : "SpellTextUnequipped", MyGUI::IntCoord(4, mHeight, mWidth-8, spellHeight), MyGUI::Align::Left | MyGUI::Align::Top); - t->setCaption(MWWorld::Class::get(item).getName(item)); + t->setCaption(item.getClass().getName(item)); t->setTextAlign(MyGUI::Align::Left); t->setUserData(item); t->setUserString("ToolTipType", "ItemPtr"); @@ -300,7 +300,7 @@ namespace MWGui void SpellWindow::onEnchantedItemSelected(MyGUI::Widget* _sender) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::Ptr item = *_sender->getUserData(); // retrieve ContainerStoreIterator to the item @@ -316,7 +316,7 @@ namespace MWGui // equip, if it can be equipped and is not already equipped if (_sender->getUserString("Equipped") == "false" - && !MWWorld::Class::get(item).getEquipmentSlots(item).first.empty()) + && !item.getClass().getEquipmentSlots(item).first.empty()) { MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item); } @@ -330,7 +330,7 @@ namespace MWGui { std::string spellId = _sender->getUserString("Spell"); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::InventoryStore& store = MWWorld::Class::get(player).getInventoryStore(player); + MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); if (MyGUI::InputManager::getInstance().isShiftPressed()) { @@ -384,7 +384,7 @@ namespace MWGui void SpellWindow::onDeleteSpellAccept() { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); if (MWBase::Environment::get().getWindowManager()->getSelectedSpell() == mSpellToDelete) diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index 31a3b6fdd0..6ae44e3146 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -228,7 +228,7 @@ namespace MWGui NoDrop::onFrame(dt); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &PCstats = MWWorld::Class::get(player).getNpcStats(player); + const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player); // level progress MyGUI::Widget* levelWidget; @@ -459,7 +459,7 @@ namespace MWGui addSeparator(coord1, coord2); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &PCstats = MWWorld::Class::get(player).getNpcStats(player); + const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player); const std::set &expelled = PCstats.getExpelled(); addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString("sFaction", "Faction"), coord1, coord2); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index b931966f07..dd29f40ce4 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -89,7 +89,7 @@ namespace MWGui if (mFocusObject.isEmpty ()) return; - const MWWorld::Class& objectclass = MWWorld::Class::get (mFocusObject); + const MWWorld::Class& objectclass = mFocusObject.getClass(); MyGUI::IntSize tooltipSize; if ((!objectclass.hasToolTip(mFocusObject))&&(MWBase::Environment::get().getWindowManager()->getMode() == GM_Console)) @@ -305,7 +305,7 @@ namespace MWGui MyGUI::IntSize tooltipSize; - const MWWorld::Class& object = MWWorld::Class::get (mFocusObject); + const MWWorld::Class& object = mFocusObject.getClass(); if (!object.hasToolTip(mFocusObject)) { mDynamicToolTipBox->setVisible(false); diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index ad18a13e81..18b0d5ae3f 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -138,7 +138,7 @@ namespace MWGui int services = 0; if (!mMerchant.isEmpty()) - services = MWWorld::Class::get(mMerchant).getServices(mMerchant); + services = mMerchant.getClass().getServices(mMerchant); mItems.clear(); // add regular items @@ -150,7 +150,7 @@ namespace MWGui MWWorld::Ptr base = item.mBase; if(Misc::StringUtils::ciEqual(base.getCellRef().mRefID, MWWorld::ContainerStore::sGoldId)) continue; - if(!MWWorld::Class::get(base).canSell(base, services)) + if(!base.getClass().canSell(base, services)) continue; // Bound items may not be bought @@ -164,7 +164,7 @@ namespace MWGui if(mMerchant.getClass().hasInventoryStore(mMerchant)) { bool isEquipped = false; - MWWorld::InventoryStore& store = MWWorld::Class::get(mMerchant).getInventoryStore(mMerchant); + MWWorld::InventoryStore& store = mMerchant.getClass().getInventoryStore(mMerchant); for (int slot=0; slotgetCountDialog(); std::string message = "#{sQuanityMenuMessage02}"; - dialog->open(MWWorld::Class::get(object).getName(object), message, count); + dialog->open(object.getClass().getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem); mItemToSell = mSortModel->mapToSource(index); @@ -165,7 +165,7 @@ namespace MWGui void TradeWindow::sellItem(MyGUI::Widget* sender, int count) { const ItemStack& item = mTradeModel->getItem(mItemToSell); - std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase); + std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); TradeItemModel* playerTradeModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); @@ -208,7 +208,7 @@ namespace MWGui void TradeWindow::addOrRemoveGold(int amount, const MWWorld::Ptr& actor) { - MWWorld::ContainerStore& store = MWWorld::Class::get(actor).getContainerStore(actor); + MWWorld::ContainerStore& store = actor.getClass().getContainerStore(actor); if (amount > 0) { @@ -442,7 +442,7 @@ namespace MWGui void TradeWindow::sellToNpc(const MWWorld::Ptr& item, int count, bool boughtItem) { - int diff = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, MWWorld::Class::get(item).getValue(item) * count, boughtItem); + int diff = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, item.getClass().getValue(item) * count, boughtItem); mCurrentBalance += diff; mCurrentMerchantOffer += diff; @@ -452,7 +452,7 @@ namespace MWGui void TradeWindow::buyFromNpc(const MWWorld::Ptr& item, int count, bool soldItem) { - int diff = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, MWWorld::Class::get(item).getValue(item) * count, !soldItem); + int diff = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, item.getClass().getValue(item) * count, !soldItem); mCurrentBalance -= diff; mCurrentMerchantOffer -= diff; diff --git a/apps/openmw/mwgui/trainingwindow.cpp b/apps/openmw/mwgui/trainingwindow.cpp index bee76992af..34873b9bc7 100644 --- a/apps/openmw/mwgui/trainingwindow.cpp +++ b/apps/openmw/mwgui/trainingwindow.cpp @@ -44,7 +44,7 @@ namespace MWGui mPlayerGold->setCaptionWithReplacing("#{sGold}: " + boost::lexical_cast(playerGold)); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats (actor); + MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats (actor); // NPC can train you in his best 3 skills std::vector< std::pair > bestSkills; @@ -73,7 +73,7 @@ namespace MWGui MyGUI::EnumeratorWidgetPtr widgets = mTrainingOptions->getEnumerator (); MyGUI::Gui::getInstance ().destroyWidgets (widgets); - MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); @@ -115,7 +115,7 @@ namespace MWGui int skillId = *sender->getUserData(); MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); @@ -123,7 +123,7 @@ namespace MWGui int price = pcStats.getSkill (skillId).getBase() * store.get().find("iTrainingMod")->getInt (); price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr,price,true); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(mPtr).getNpcStats (mPtr); + MWMechanics::NpcStats& npcStats = mPtr.getClass().getNpcStats (mPtr); if (npcStats.getSkill (skillId).getBase () <= pcStats.getSkill (skillId).getBase ()) { MWBase::Environment::get().getWindowManager()->messageBox ("#{sServiceTrainingWords}"); diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 89d73215d0..642e1a6449 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -161,7 +161,7 @@ namespace MWGui MWBase::Environment::get().getWorld()->changeToExteriorCell(pos); } - MWWorld::Class::get(player).adjustPosition(player); + player.getClass().adjustPosition(player); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Travel); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue); MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0); diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ed1b9e0a90..6c07e14d36 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -171,11 +171,11 @@ namespace MWGui void WaitDialog::setCanRest (bool canRest) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); bool full = (stats.getFatigue().getCurrent() >= stats.getFatigue().getModified()) && (stats.getHealth().getCurrent() >= stats.getHealth().getModified()) && (stats.getMagicka().getCurrent() >= stats.getMagicka().getModified()); - MWMechanics::NpcStats& npcstats = MWWorld::Class::get(player).getNpcStats(player); + MWMechanics::NpcStats& npcstats = player.getClass().getNpcStats(player); bool werewolf = npcstats.isWerewolf(); mUntilHealedButton->setVisible(canRest && !full); @@ -231,7 +231,7 @@ namespace MWGui mWaiting = false; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &pcstats = MWWorld::Class::get(player).getNpcStats(player); + const MWMechanics::NpcStats &pcstats = player.getClass().getNpcStats(player); // trigger levelup if possible const MWWorld::Store &gmst = diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 81b28aa66f..40fcc35300 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1027,20 +1027,20 @@ namespace MWGui { mSelectedSpell = ""; const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get() - .find(MWWorld::Class::get(item).getEnchantment(item)); + .find(item.getClass().getEnchantment(item)); int chargePercent = (item.getCellRef().mEnchantmentCharge == -1) ? 100 : (item.getCellRef().mEnchantmentCharge / static_cast(ench->mData.mCharge) * 100); mHud->setSelectedEnchantItem(item, chargePercent); - mSpellWindow->setTitle(MWWorld::Class::get(item).getName(item)); + mSpellWindow->setTitle(item.getClass().getName(item)); } void WindowManager::setSelectedWeapon(const MWWorld::Ptr& item) { int durabilityPercent = (item.getCellRef().mCharge == -1) ? 100 - : (item.getCellRef().mCharge / static_cast(MWWorld::Class::get(item).getItemMaxHealth(item)) * 100); + : (item.getCellRef().mCharge / static_cast(item.getClass().getItemMaxHealth(item)) * 100); mHud->setSelectedWeapon(item, durabilityPercent); - mInventoryWindow->setTitle(MWWorld::Class::get(item).getName(item)); + mInventoryWindow->setTitle(item.getClass().getName(item)); } void WindowManager::unsetSelectedSpell() diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 8095b0d05d..cf71cc1aa4 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -172,7 +172,7 @@ namespace MWInput if (action == A_Use) { - MWWorld::Class::get(mPlayer->getPlayer()).getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue); + mPlayer->getPlayer().getClass().getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue); } if (currentValue == 1) @@ -359,7 +359,7 @@ namespace MWInput { MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); mOverencumberedMessageDelay -= dt; - if (MWWorld::Class::get(player).getEncumbrance(player) >= MWWorld::Class::get(player).getCapacity(player)) + if (player.getClass().getEncumbrance(player) >= player.getClass().getCapacity(player)) { mPlayer->setAutoMove (false); if (mOverencumberedMessageDelay <= 0) @@ -664,7 +664,7 @@ namespace MWInput return; // Not allowed if no spell selected - MWWorld::InventoryStore& inventory = MWWorld::Class::get(mPlayer->getPlayer()).getInventoryStore(mPlayer->getPlayer()); + MWWorld::InventoryStore& inventory = mPlayer->getPlayer().getClass().getInventoryStore(mPlayer->getPlayer()); if (MWBase::Environment::get().getWindowManager()->getSelectedSpell().empty() && inventory.getSelectedEnchantItem() == inventory.end()) return; diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 363647467a..35667a23c4 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -187,7 +187,7 @@ namespace MWMechanics void Actors::engageCombat (const MWWorld::Ptr& actor1, const MWWorld::Ptr& actor2, bool againstPlayer) { - CreatureStats& creatureStats = MWWorld::Class::get(actor1).getCreatureStats(actor1); + CreatureStats& creatureStats = actor1.getClass().getCreatureStats(actor1); if (againstPlayer && creatureStats.isHostile()) return; // already fighting against player @@ -244,13 +244,13 @@ namespace MWMechanics void Actors::adjustMagicEffects (const MWWorld::Ptr& creature) { - CreatureStats& creatureStats = MWWorld::Class::get (creature).getCreatureStats (creature); + CreatureStats& creatureStats = creature.getClass().getCreatureStats (creature); MagicEffects now = creatureStats.getSpells().getMagicEffects(); if (creature.getTypeName()==typeid (ESM::NPC).name()) { - MWWorld::InventoryStore& store = MWWorld::Class::get (creature).getInventoryStore (creature); + MWWorld::InventoryStore& store = creature.getClass().getInventoryStore (creature); now += store.getMagicEffects(); } @@ -265,7 +265,7 @@ namespace MWMechanics void Actors::calculateDynamicStats (const MWWorld::Ptr& ptr) { - CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr); int strength = creatureStats.getAttribute(ESM::Attribute::Strength).getBase(); int intelligence = creatureStats.getAttribute(ESM::Attribute::Intelligence).getBase(); @@ -333,7 +333,7 @@ namespace MWMechanics void Actors::calculateCreatureStatModifiers (const MWWorld::Ptr& ptr, float duration) { - CreatureStats &creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr); + CreatureStats &creatureStats = ptr.getClass().getCreatureStats(ptr); const MagicEffects &effects = creatureStats.getMagicEffects(); // attributes @@ -600,7 +600,7 @@ namespace MWMechanics void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr) { - NpcStats &npcStats = MWWorld::Class::get(ptr).getNpcStats(ptr); + NpcStats &npcStats = ptr.getClass().getNpcStats(ptr); const MagicEffects &effects = npcStats.getMagicEffects(); // skills @@ -656,7 +656,7 @@ namespace MWMechanics { bool isPlayer = ptr.getRefData().getHandle()=="player"; - MWWorld::InventoryStore &inventoryStore = MWWorld::Class::get(ptr).getInventoryStore(ptr); + MWWorld::InventoryStore &inventoryStore = ptr.getClass().getInventoryStore(ptr); MWWorld::ContainerStoreIterator heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); /** @@ -678,7 +678,7 @@ namespace MWMechanics { if (torch != inventoryStore.end()) { - if (!MWWorld::Class::get (ptr).getCreatureStats (ptr).isHostile()) + if (!ptr.getClass().getCreatureStats (ptr).isHostile()) { // For non-hostile NPCs, unequip whatever is in the left slot in favor of a light. if (heldIter != inventoryStore.end() && heldIter->getTypeName() != typeid(ESM::Light).name()) @@ -755,8 +755,8 @@ namespace MWMechanics if (ptr != player && ptr.getClass().isNpc()) { // get stats of witness - CreatureStats& creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr); - NpcStats& npcStats = MWWorld::Class::get(ptr).getNpcStats(ptr); + CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); + NpcStats& npcStats = ptr.getClass().getNpcStats(ptr); if (ptr.getClass().isClass(ptr, "Guard") && creatureStats.getAiSequence().getTypeId() != AiPackage::TypeIdPursue && !creatureStats.isHostile()) { @@ -824,7 +824,7 @@ namespace MWMechanics void Actors::addActor (const MWWorld::Ptr& ptr, bool updateImmediately) { // erase previous death events since we are currently only tracking them while in an active cell - MWWorld::Class::get(ptr).getCreatureStats(ptr).clearHasDied(); + ptr.getClass().getCreatureStats(ptr).clearHasDied(); removeActor(ptr); @@ -964,7 +964,7 @@ namespace MWMechanics // Kill dead actors, update some variables for(PtrControllerMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) { - const MWWorld::Class &cls = MWWorld::Class::get(iter->first); + const MWWorld::Class &cls = iter->first.getClass(); CreatureStats &stats = cls.getCreatureStats(iter->first); //KnockedOutOneFrameLogic @@ -1137,7 +1137,7 @@ namespace MWMechanics std::list list; for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();iter++) { - const MWWorld::Class &cls = MWWorld::Class::get(iter->first); + const MWWorld::Class &cls = iter->first.getClass(); CreatureStats &stats = cls.getCreatureStats(iter->first); if(!stats.isDead() && stats.getAiSequence().getTypeId() == AiPackage::TypeIdFollow) { @@ -1158,7 +1158,7 @@ namespace MWMechanics neighbors); //only care about those within the alarm disance for(std::vector::iterator iter(neighbors.begin());iter != neighbors.end();iter++) { - const MWWorld::Class &cls = MWWorld::Class::get(*iter); + const MWWorld::Class &cls = iter->getClass(); CreatureStats &stats = cls.getCreatureStats(*iter); if(!stats.isDead() && stats.getAiSequence().getTypeId() == AiPackage::TypeIdCombat) { diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index 4b4b36ed65..3dfacb853d 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -32,7 +32,7 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 200) { //Stop when you get close actor.getClass().getMovementSettings(actor).mPosition[1] = 0; MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false); - MWWorld::Class::get(target).activate(target,actor).get()->execute(actor); //Arrest player + target.getClass().activate(target,actor).get()->execute(actor); //Arrest player return true; } else { diff --git a/apps/openmw/mwmechanics/aiavoiddoor.cpp b/apps/openmw/mwmechanics/aiavoiddoor.cpp index 44eacb0d1e..5045225828 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.cpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.cpp @@ -63,7 +63,7 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor,float duration MWBase::Environment::get().getMechanicsManager()->getActorsInRange(Ogre::Vector3(pos.pos[0],pos.pos[1],pos.pos[2]),100,actors); for(std::vector::iterator it = actors.begin(); it != actors.end(); it++) { if(*it != MWBase::Environment::get().getWorld()->getPlayerPtr()) { //Not the player - MWMechanics::AiSequence& seq = MWWorld::Class::get(*it).getCreatureStats(*it).getAiSequence(); + MWMechanics::AiSequence& seq = it->getClass().getCreatureStats(*it).getAiSequence(); if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) { //Only add it once seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr),*it); } diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 0430adf06a..07bb9726ef 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -97,7 +97,7 @@ namespace MWMechanics { // Stop moving if the player is to far away MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle3", 0, 1); - MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; + actor.getClass().getMovementSettings(actor).mPosition[1] = 0; mMaxDist = 330; } diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 7120ff5afc..1c870bda47 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -572,7 +572,7 @@ namespace MWMechanics void AiWander::stopWalking(const MWWorld::Ptr& actor) { mPathFinder.clearPath(); - MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; + actor.getClass().getMovementSettings(actor).mPosition[1] = 0; } void AiWander::playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect) diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index af58e9ee0b..64b358b96c 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -292,13 +292,13 @@ void MWMechanics::Alchemy::addPotion (const std::string& name) void MWMechanics::Alchemy::increaseSkill() { - MWWorld::Class::get (mAlchemist).skillUsageSucceeded (mAlchemist, ESM::Skill::Alchemy, 0); + mAlchemist.getClass().skillUsageSucceeded (mAlchemist, ESM::Skill::Alchemy, 0); } float MWMechanics::Alchemy::getChance() const { - const CreatureStats& creatureStats = MWWorld::Class::get (mAlchemist).getCreatureStats (mAlchemist); - const NpcStats& npcStats = MWWorld::Class::get (mAlchemist).getNpcStats (mAlchemist); + const CreatureStats& creatureStats = mAlchemist.getClass().getCreatureStats (mAlchemist); + const NpcStats& npcStats = mAlchemist.getClass().getNpcStats (mAlchemist); return (npcStats.getSkill (ESM::Skill::Alchemy).getModified() + @@ -331,7 +331,7 @@ void MWMechanics::Alchemy::setAlchemist (const MWWorld::Ptr& npc) mEffects.clear(); - MWWorld::ContainerStore& store = MWWorld::Class::get (npc).getContainerStore (npc); + MWWorld::ContainerStore& store = npc.getClass().getContainerStore (npc); for (MWWorld::ContainerStoreIterator iter (store.begin (MWWorld::ContainerStore::Type_Apparatus)); iter!=store.end(); ++iter) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index b6d91db583..60bccb3f7e 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -459,7 +459,7 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim if(!mAnimation) return; - const MWWorld::Class &cls = MWWorld::Class::get(mPtr); + const MWWorld::Class &cls = mPtr.getClass(); if(cls.isActor()) { /* Accumulate along X/Y only for now, until we can figure out how we should @@ -549,7 +549,7 @@ bool CharacterController::updateCreatureState() bool CharacterController::updateWeaponState() { - const MWWorld::Class &cls = MWWorld::Class::get(mPtr); + const MWWorld::Class &cls = mPtr.getClass(); CreatureStats &stats = cls.getCreatureStats(mPtr); WeaponType weaptype = WeapType_None; MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr); @@ -601,8 +601,8 @@ bool CharacterController::updateWeaponState() if(weapon != inv.end() && !(weaptype == WeapType_None && mWeaponType == WeapType_Spell)) { std::string soundid = (weaptype == WeapType_None) ? - MWWorld::Class::get(*weapon).getDownSoundId(*weapon) : - MWWorld::Class::get(*weapon).getUpSoundId(*weapon); + weapon->getClass().getDownSoundId(*weapon) : + weapon->getClass().getUpSoundId(*weapon); if(!soundid.empty()) { MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); @@ -983,7 +983,7 @@ bool CharacterController::updateWeaponState() void CharacterController::update(float duration) { MWBase::World *world = MWBase::Environment::get().getWorld(); - const MWWorld::Class &cls = MWWorld::Class::get(mPtr); + const MWWorld::Class &cls = mPtr.getClass(); Ogre::Vector3 movement(0.0f); updateVisibility(); diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 87337cdd70..23246c2945 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -52,7 +52,7 @@ namespace MWMechanics bool Enchanting::create() { const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); ESM::Enchantment enchantment; enchantment.mData.mCharge = getGemCharge(); @@ -67,7 +67,7 @@ namespace MWMechanics if(getEnchantChance() (RAND_MAX)*100) return false; - MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 2); + mEnchanter.getClass().skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 2); } if(mCastStyle==ESM::Enchantment::ConstantEffect) @@ -84,7 +84,7 @@ namespace MWMechanics // Apply the enchantment const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment); - MWWorld::Class::get(newItemPtr).applyEnchantment(newItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); + newItemPtr.getClass().applyEnchantment(newItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); // Add the new item to player inventory and remove the old one store.remove(mOldItemPtr, 1, player); @@ -212,7 +212,7 @@ namespace MWMechanics const float enchantCost = getEnchantPoints(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); + MWMechanics::NpcStats &stats = player.getClass().getNpcStats(player); int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); /* @@ -277,7 +277,7 @@ namespace MWMechanics float Enchanting::getEnchantChance() const { - const NpcStats& npcStats = MWWorld::Class::get (mEnchanter).getNpcStats (mEnchanter); + const NpcStats& npcStats = mEnchanter.getClass().getNpcStats (mEnchanter); float chance1 = (npcStats.getSkill (ESM::Skill::Enchant).getModified() + (0.25 * npcStats.getAttribute (ESM::Attribute::Intelligence).getModified()) @@ -295,7 +295,7 @@ namespace MWMechanics void Enchanting::payForEnchantment() const { const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); store.remove(MWWorld::ContainerStore::sGoldId, getEnchantPrice(), player); } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index bf9a11d6e5..5a72c88837 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -49,8 +49,8 @@ namespace MWMechanics { MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get (ptr).getNpcStats (ptr); + MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr); + MWMechanics::NpcStats& npcStats = ptr.getClass().getNpcStats (ptr); const ESM::NPC *player = ptr.get()->mBase; @@ -215,7 +215,7 @@ namespace MWMechanics void MechanicsManager::add(const MWWorld::Ptr& ptr) { - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) mActors.addActor(ptr); else mObjects.addObject(ptr); @@ -234,7 +234,7 @@ namespace MWMechanics if(old == mWatched) mWatched = ptr; - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) mActors.updateActor(old, ptr); else mObjects.updateObject(old, ptr); @@ -475,13 +475,13 @@ namespace MWMechanics int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr) { - const MWMechanics::NpcStats& npcSkill = MWWorld::Class::get(ptr).getNpcStats(ptr); + const MWMechanics::NpcStats& npcSkill = ptr.getClass().getNpcStats(ptr); float x = npcSkill.getBaseDisposition(); MWWorld::LiveCellRef* npc = ptr.get(); MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::LiveCellRef* player = playerPtr.get(); - const MWMechanics::NpcStats &playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr); + const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); if (Misc::StringUtils::ciEqual(npc->mBase->mRace, player->mBase->mRace)) x += MWBase::Environment::get().getWorld()->getStore().get().find("fDispRaceMod")->getFloat(); @@ -547,10 +547,10 @@ namespace MWMechanics if (ptr.getTypeName() == typeid(ESM::Creature).name()) return basePrice; - const MWMechanics::NpcStats &sellerStats = MWWorld::Class::get(ptr).getNpcStats(ptr); + const MWMechanics::NpcStats &sellerStats = ptr.getClass().getNpcStats(ptr); MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr); + const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); // I suppose the temporary disposition change _has_ to be considered here, // otherwise one would get different prices when exiting and re-entering the dialogue window... @@ -592,10 +592,10 @@ namespace MWMechanics const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(npc).getNpcStats(npc); + MWMechanics::NpcStats& npcStats = npc.getClass().getNpcStats(npc); MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const MWMechanics::NpcStats &playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr); + const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); float persTerm = playerStats.getAttribute(ESM::Attribute::Personality).getModified() / gmst.find("fPersonalityMod")->getFloat(); @@ -741,27 +741,27 @@ namespace MWMechanics void MechanicsManager::forceStateUpdate(const MWWorld::Ptr &ptr) { - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) mActors.forceStateUpdate(ptr); } void MechanicsManager::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number) { - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) mActors.playAnimationGroup(ptr, groupName, mode, number); else mObjects.playAnimationGroup(ptr, groupName, mode, number); } void MechanicsManager::skipAnimation(const MWWorld::Ptr& ptr) { - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) mActors.skipAnimation(ptr); else mObjects.skipAnimation(ptr); } bool MechanicsManager::checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName) { - if(MWWorld::Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) return mActors.checkAnimationPlaying(ptr, groupName); else return false; diff --git a/apps/openmw/mwmechanics/repair.cpp b/apps/openmw/mwmechanics/repair.cpp index 48179d3442..dc8b567a9b 100644 --- a/apps/openmw/mwmechanics/repair.cpp +++ b/apps/openmw/mwmechanics/repair.cpp @@ -31,8 +31,8 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) int uses = (mTool.getCellRef().mCharge != -1) ? mTool.getCellRef().mCharge : ref->mBase->mData.mUses; mTool.getCellRef().mCharge = uses-1; - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player); + MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); + MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); float fatigueTerm = stats.getFatigueTerm(); int pcStrength = stats.getAttribute(ESM::Attribute::Strength).getModified(); @@ -55,15 +55,15 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) // repair by 'y' points itemToRepair.getCellRef().mCharge += y; itemToRepair.getCellRef().mCharge = std::min(itemToRepair.getCellRef().mCharge, - MWWorld::Class::get(itemToRepair).getItemMaxHealth(itemToRepair)); + itemToRepair.getClass().getItemMaxHealth(itemToRepair)); // set the OnPCRepair variable on the item's script - std::string script = MWWorld::Class::get(itemToRepair).getScript(itemToRepair); + std::string script = itemToRepair.getClass().getScript(itemToRepair); if(script != "") itemToRepair.getRefData().getLocals().setVarByInt(script, "onpcrepair", 1); // increase skill - MWWorld::Class::get(player).skillUsageSucceeded(player, ESM::Skill::Armorer, 0); + player.getClass().skillUsageSucceeded(player, ESM::Skill::Armorer, 0); MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1); MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairSuccess}"); @@ -78,14 +78,14 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) if (mTool.getCellRef().mCharge == 0) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); + MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); store.remove(mTool, 1, player); std::string message = MWBase::Environment::get().getWorld()->getStore().get() .find("sNotifyMessage51")->getString(); - MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % MWWorld::Class::get(mTool).getName(mTool)).str()); + MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % mTool.getClass().getName(mTool)).str()); // try to find a new tool of the same ID for (MWWorld::ContainerStoreIterator iter (store.begin()); diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 3751e58285..bb2e942238 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -18,8 +18,8 @@ namespace MWMechanics Security::Security(const MWWorld::Ptr &actor) : mActor(actor) { - CreatureStats& creatureStats = MWWorld::Class::get(actor).getCreatureStats(actor); - NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats(actor); + CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor); + NpcStats& npcStats = actor.getClass().getNpcStats(actor); mAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified(); mLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified(); mSecuritySkill = npcStats.getSkill(ESM::Skill::Security).getModified(); @@ -51,10 +51,10 @@ namespace MWMechanics int roll = static_cast (std::rand()) / RAND_MAX * 100; if (roll <= x) { - MWWorld::Class::get(lock).unlock(lock); + lock.getClass().unlock(lock); resultMessage = "#{sLockSuccess}"; resultSound = "Open Lock"; - MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 1); + mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, 1); } else resultMessage = "#{sLockFail}"; @@ -97,7 +97,7 @@ namespace MWMechanics resultSound = "Disarm Trap"; resultMessage = "#{sTrapSuccess}"; - MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 0); + mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, 0); } else resultMessage = "#{sTrapFail}"; diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 013e3daf4f..5e88b22505 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -118,7 +118,7 @@ namespace MWRender 0, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal)); float scale=1.f; - MWWorld::Class::get(mCharacter).adjustScale(mCharacter, scale); + mCharacter.getClass().adjustScale(mCharacter, scale); mNode->setScale(Ogre::Vector3(scale)); mCamera->setPosition(mPosition * mNode->getScale()); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 14f5cc4e7f..03ccde388b 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -237,7 +237,7 @@ void NpcAnimation::updateNpcBase() void NpcAnimation::updateParts() { mAlpha = 1.f; - const MWWorld::Class &cls = MWWorld::Class::get(mPtr); + const MWWorld::Class &cls = mPtr.getClass(); MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr); NpcType curType = Type_Normal; @@ -668,12 +668,12 @@ void NpcAnimation::showWeapons(bool showWeapon) mShowWeapons = showWeapon; if(showWeapon) { - MWWorld::InventoryStore &inv = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); + MWWorld::InventoryStore &inv = mPtr.getClass().getInventoryStore(mPtr); MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if(weapon != inv.end()) { Ogre::Vector3 glowColor = getEnchantmentColor(*weapon); - std::string mesh = MWWorld::Class::get(*weapon).getModel(*weapon); + std::string mesh = weapon->getClass().getModel(*weapon); addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1, mesh, !weapon->getClass().getEnchantment(*weapon).empty(), &glowColor); @@ -701,13 +701,13 @@ void NpcAnimation::showWeapons(bool showWeapon) void NpcAnimation::showCarriedLeft(bool show) { mShowCarriedLeft = show; - MWWorld::InventoryStore &inv = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); + MWWorld::InventoryStore &inv = mPtr.getClass().getInventoryStore(mPtr); MWWorld::ContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); if(show && iter != inv.end()) { Ogre::Vector3 glowColor = getEnchantmentColor(*iter); - std::string mesh = MWWorld::Class::get(*iter).getModel(*iter); + std::string mesh = iter->getClass().getModel(*iter); if (addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1, mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor)) { diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 991ca690ee..882a3d09bf 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -249,7 +249,7 @@ void RenderingManager::cellAdded (MWWorld::CellStore *store) void RenderingManager::addObject (const MWWorld::Ptr& ptr){ const MWWorld::Class& class_ = - MWWorld::Class::get (ptr); + ptr.getClass(); class_.insertObjectRendering(ptr, *this); } @@ -279,7 +279,7 @@ void RenderingManager::rotateObject(const MWWorld::Ptr &ptr) mCamera->rotateCamera(-rot, false); Ogre::Quaternion newo = Ogre::Quaternion(Ogre::Radian(rot.z), Ogre::Vector3::NEGATIVE_UNIT_Z); - if(!MWWorld::Class::get(ptr).isActor()) + if(!ptr.getClass().isActor()) newo = Ogre::Quaternion(Ogre::Radian(rot.x), Ogre::Vector3::NEGATIVE_UNIT_X) * Ogre::Quaternion(Ogre::Radian(rot.y), Ogre::Vector3::NEGATIVE_UNIT_Y) * newo; ptr.getRefData().getBaseNode()->setOrientation(newo); @@ -294,7 +294,7 @@ RenderingManager::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr & Ogre::SceneNode *parent = child->getParentSceneNode(); parent->removeChild(child); - if (MWWorld::Class::get(old).isActor()) { + if (old.getClass().isActor()) { mActors->updateObjectCell(old, cur); } else { mObjects->updateObjectCell(old, cur); @@ -314,7 +314,7 @@ void RenderingManager::rebuildPtr(const MWWorld::Ptr &ptr) NpcAnimation *anim = NULL; if(ptr.getRefData().getHandle() == "player") anim = mPlayerAnimation; - else if(MWWorld::Class::get(ptr).isActor()) + else if(ptr.getClass().isActor()) anim = dynamic_cast(mActors->getAnimation(ptr)); if(anim) { @@ -337,7 +337,7 @@ void RenderingManager::update (float duration, bool paused) MWWorld::Ptr player = world->getPlayerPtr(); - int blind = MWWorld::Class::get(player).getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Blind).mMagnitude; + int blind = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Blind).mMagnitude; mRendering.getFader()->setFactor(std::max(0.f, 1.f-(blind / 100.f))); setAmbientMode(); @@ -599,7 +599,7 @@ void RenderingManager::setAmbientColour(const Ogre::ColourValue& colour) mAmbientColor = colour; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - int nightEye = MWWorld::Class::get(player).getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::NightEye).mMagnitude; + int nightEye = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::NightEye).mMagnitude; Ogre::ColourValue final = colour; final += Ogre::ColourValue(0.7,0.7,0.7,0) * std::min(1.f, (nightEye/100.f)); diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index ded25479c4..cc17905df6 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -47,7 +47,7 @@ namespace MWScript for (unsigned int i=0; i @@ -298,7 +298,7 @@ namespace MWScript for (unsigned int i=0; igetPtr (id, false); - script = MWWorld::Class::get (ptr).getScript (ptr); + script = ptr.getClass().getScript (ptr); reference = true; } diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 66c8d44687..6737d6a945 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -117,7 +117,7 @@ namespace MWScript if (count == 0) return; - MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr); + MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); std::string itemName; for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) @@ -231,7 +231,7 @@ namespace MWScript throw std::runtime_error ("armor index out of range"); } - MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); + MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); MWWorld::ContainerStoreIterator it = invStore.getSlot (slot); if (it == invStore.end() || it->getTypeName () != typeid(ESM::Armor).name()) @@ -240,7 +240,7 @@ namespace MWScript return; } - int skill = MWWorld::Class::get(*it).getEquipmentSkill (*it) ; + int skill = it->getClass().getEquipmentSkill (*it) ; if (skill == ESM::Skill::HeavyArmor) runtime.push(2); else if (skill == ESM::Skill::MediumArmor) @@ -264,7 +264,7 @@ namespace MWScript std::string item = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); + MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ContainerStoreIterator it = invStore.getSlot (slot); @@ -290,7 +290,7 @@ namespace MWScript const std::string &name = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); + MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); for (MWWorld::ContainerStoreIterator it = invStore.begin(MWWorld::ContainerStore::Type_Miscellaneous); it != invStore.end(); ++it) { @@ -314,7 +314,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); + MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); MWWorld::ContainerStoreIterator it = invStore.getSlot (MWWorld::InventoryStore::Slot_CarriedRight); if (it == invStore.end() || it->getTypeName () != typeid(ESM::Weapon).name()) { diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index a882ae05e7..993e99c2e6 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -141,7 +141,7 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWWorld::Class::get(ptr).getNpcStats (ptr).setReputation (MWWorld::Class::get(ptr).getNpcStats (ptr).getReputation () + value); + ptr.getClass().getNpcStats (ptr).setReputation (ptr.getClass().getNpcStats (ptr).getReputation () + value); } }; @@ -156,7 +156,7 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWWorld::Class::get(ptr).getNpcStats (ptr).setReputation (value); + ptr.getClass().getNpcStats (ptr).setReputation (value); } }; @@ -169,7 +169,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - runtime.push (MWWorld::Class::get(ptr).getNpcStats (ptr).getReputation ()); + runtime.push (ptr.getClass().getNpcStats (ptr).getReputation ()); } }; @@ -184,7 +184,7 @@ namespace MWScript MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - runtime.push (MWWorld::Class::get(ptr).getNpcStats (ptr).isSameFaction (MWWorld::Class::get(player).getNpcStats (player))); + runtime.push (ptr.getClass().getNpcStats (ptr).isSameFaction (player.getClass().getNpcStats (player))); } }; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 1f5ad5b071..6f7968fac8 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -66,7 +66,7 @@ namespace MWScript { const MWWorld::Ptr ptr = getReference (id, false); - id = MWWorld::Class::get (ptr).getScript (ptr); + id = ptr.getClass().getScript (ptr); ptr.getRefData().setLocals ( *MWBase::Environment::get().getWorld()->getStore().get().find (id)); @@ -86,7 +86,7 @@ namespace MWScript { const MWWorld::Ptr ptr = getReference (id, false); - id = MWWorld::Class::get (ptr).getScript (ptr); + id = ptr.getClass().getScript (ptr); ptr.getRefData().setLocals ( *MWBase::Environment::get().getWorld()->getStore().get().find (id)); @@ -263,7 +263,7 @@ namespace MWScript std::string InterpreterContext::getNPCRank() const { - std::map ranks = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks(); + std::map ranks = mReference.getClass().getNpcStats (mReference).getFactionRanks(); std::map::const_iterator it = ranks.begin(); MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -299,9 +299,9 @@ namespace MWScript MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - std::string factionId = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks().begin()->first; + std::string factionId = mReference.getClass().getNpcStats (mReference).getFactionRanks().begin()->first; - std::map ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks(); + std::map ranks = player.getClass().getNpcStats (player).getFactionRanks(); std::map::const_iterator it = ranks.find(factionId); int rank = -1; if (it != ranks.end()) @@ -326,9 +326,9 @@ namespace MWScript MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - std::string factionId = MWWorld::Class::get (mReference).getNpcStats (mReference).getFactionRanks().begin()->first; + std::string factionId = mReference.getClass().getNpcStats (mReference).getFactionRanks().begin()->first; - std::map ranks = MWWorld::Class::get (player).getNpcStats (player).getFactionRanks(); + std::map ranks = player.getClass().getNpcStats (player).getFactionRanks(); std::map::const_iterator it = ranks.find(factionId); int rank = -1; if (it != ranks.end()) @@ -353,7 +353,7 @@ namespace MWScript { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - return MWWorld::Class::get (player).getNpcStats (player).getBounty(); + return player.getClass().getNpcStats (player).getBounty(); } std::string InterpreterContext::getCurrentCellName() const diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 620a0d0c94..b0d73253ff 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -142,7 +142,7 @@ namespace MWScript runtime.pop(); } - MWWorld::Class::get (ptr).lock (ptr, lockLevel); + ptr.getClass().lock (ptr, lockLevel); } }; @@ -155,7 +155,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - MWWorld::Class::get (ptr).unlock (ptr); + ptr.getClass().unlock (ptr); } }; @@ -345,7 +345,7 @@ namespace MWScript if(key < 0 || key > 32767 || *end != '\0') key = ESM::MagicEffect::effectStringToId(effect); - runtime.push(MWWorld::Class::get(ptr).getCreatureStats(ptr).getMagicEffects().get( + runtime.push(ptr.getClass().getCreatureStats(ptr).getMagicEffects().get( MWMechanics::EffectKey(key)).mMagnitude > 0); } }; @@ -389,7 +389,7 @@ namespace MWScript for (unsigned int i=0; igetCellRef().mSoul, soul)) @@ -424,7 +424,7 @@ namespace MWScript if (amount == 0) return; - MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr); + MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); int toRemove = amount; @@ -457,7 +457,7 @@ namespace MWScript std::string soul = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr); + MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) @@ -481,7 +481,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - runtime.push(MWWorld::Class::get(ptr).getCreatureStats (ptr).getAttacked ()); + runtime.push(ptr.getClass().getCreatureStats (ptr).getAttacked ()); } }; @@ -522,7 +522,7 @@ namespace MWScript std::string id = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - runtime.push(MWWorld::Class::get(ptr).getCreatureStats(ptr).getActiveSpells().isSpellActive(id)); + runtime.push(ptr.getClass().getCreatureStats(ptr).getActiveSpells().isSpellActive(id)); } }; @@ -621,7 +621,7 @@ namespace MWScript std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWMechanics::CreatureStats &stats = MWWorld::Class::get(ptr).getCreatureStats(ptr); + MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); runtime.push(::Misc::StringUtils::ciEqual(objectID, stats.getLastHitObject())); } }; @@ -657,7 +657,7 @@ namespace MWScript { std::stringstream str; - const std::string script = MWWorld::Class::get(ptr).getScript(ptr); + const std::string script = ptr.getClass().getScript(ptr); if(script.empty()) str<< ptr.getCellRef().mRefID<<" ("< stat (MWWorld::Class::get (ptr).getCreatureStats (ptr) + MWMechanics::DynamicStat stat (ptr.getClass().getCreatureStats (ptr) .getDynamic (mIndex)); stat.setModified (value, 0); stat.setCurrent(value); - MWWorld::Class::get (ptr).getCreatureStats (ptr).setDynamic (mIndex, stat); + ptr.getClass().getCreatureStats (ptr).setDynamic (mIndex, stat); } }; @@ -222,18 +222,18 @@ namespace MWScript Interpreter::Type_Float diff = runtime[0].mFloat; runtime.pop(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); Interpreter::Type_Float current = stats.getDynamic(mIndex).getCurrent(); - MWMechanics::DynamicStat stat (MWWorld::Class::get (ptr).getCreatureStats (ptr) + MWMechanics::DynamicStat stat (ptr.getClass().getCreatureStats (ptr) .getDynamic (mIndex)); stat.setModified (diff + stat.getModified(), 0); stat.setCurrent (diff + current); - MWWorld::Class::get (ptr).getCreatureStats (ptr).setDynamic (mIndex, stat); + ptr.getClass().getCreatureStats (ptr).setDynamic (mIndex, stat); } }; @@ -253,16 +253,16 @@ namespace MWScript Interpreter::Type_Float diff = runtime[0].mFloat; runtime.pop(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); Interpreter::Type_Float current = stats.getDynamic(mIndex).getCurrent(); - MWMechanics::DynamicStat stat (MWWorld::Class::get (ptr).getCreatureStats (ptr) + MWMechanics::DynamicStat stat (ptr.getClass().getCreatureStats (ptr) .getDynamic (mIndex)); stat.setCurrent (diff + current); - MWWorld::Class::get (ptr).getCreatureStats (ptr).setDynamic (mIndex, stat); + ptr.getClass().getCreatureStats (ptr).setDynamic (mIndex, stat); } }; @@ -279,7 +279,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); Interpreter::Type_Float value = 0; @@ -327,7 +327,7 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWMechanics::NpcStats& stats = MWWorld::Class::get (ptr).getNpcStats (ptr); + MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats (ptr); MWWorld::LiveCellRef *ref = ptr.get(); @@ -386,7 +386,7 @@ namespace MWScript { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - runtime.push (static_cast (MWWorld::Class::get (player).getNpcStats (player).getBounty())); + runtime.push (static_cast (player.getClass().getNpcStats (player).getBounty())); } }; @@ -399,7 +399,7 @@ namespace MWScript MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - MWWorld::Class::get (player).getNpcStats (player).setBounty(runtime[0].mFloat); + player.getClass().getNpcStats (player).setBounty(runtime[0].mFloat); runtime.pop(); } }; @@ -413,7 +413,7 @@ namespace MWScript MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - MWWorld::Class::get (player).getNpcStats (player).setBounty(runtime[0].mFloat + MWWorld::Class::get (player).getNpcStats (player).getBounty()); + player.getClass().getNpcStats (player).setBounty(runtime[0].mFloat + player.getClass().getNpcStats (player).getBounty()); runtime.pop(); } }; @@ -433,7 +433,7 @@ namespace MWScript // make sure a spell with this ID actually exists. MWBase::Environment::get().getWorld()->getStore().get().find (id); - MWWorld::Class::get (ptr).getCreatureStats (ptr).getSpells().add (id); + ptr.getClass().getCreatureStats (ptr).getSpells().add (id); } }; @@ -449,7 +449,7 @@ namespace MWScript std::string id = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::Class::get (ptr).getCreatureStats (ptr).getSpells().remove (id); + ptr.getClass().getCreatureStats (ptr).getSpells().remove (id); MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager(); @@ -473,7 +473,7 @@ namespace MWScript std::string spellid = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::Class::get (ptr).getCreatureStats (ptr).getActiveSpells().removeEffects(spellid); + ptr.getClass().getCreatureStats (ptr).getActiveSpells().removeEffects(spellid); } }; @@ -489,7 +489,7 @@ namespace MWScript Interpreter::Type_Integer effectId = runtime[0].mInteger; runtime.pop(); - MWWorld::Class::get (ptr).getCreatureStats (ptr).getActiveSpells().purgeEffect(effectId); + ptr.getClass().getCreatureStats (ptr).getActiveSpells().purgeEffect(effectId); } }; @@ -509,8 +509,8 @@ namespace MWScript Interpreter::Type_Integer value = 0; for (MWMechanics::Spells::TIterator iter ( - MWWorld::Class::get (ptr).getCreatureStats (ptr).getSpells().begin()); - iter!=MWWorld::Class::get (ptr).getCreatureStats (ptr).getSpells().end(); ++iter) + ptr.getClass().getCreatureStats (ptr).getSpells().begin()); + iter!=ptr.getClass().getCreatureStats (ptr).getSpells().end(); ++iter) if (iter->first==id) { value = 1; @@ -544,9 +544,9 @@ namespace MWScript if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - if(MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().find(factionID) == MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().end()) + if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end()) { - MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] = 0; + player.getClass().getNpcStats(player).getFactionRanks()[factionID] = 0; } } } @@ -575,13 +575,13 @@ namespace MWScript if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - if(MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().find(factionID) == MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().end()) + if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end()) { - MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] = 0; + player.getClass().getNpcStats(player).getFactionRanks()[factionID] = 0; } else { - MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] = MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] +1; + player.getClass().getNpcStats(player).getFactionRanks()[factionID] = player.getClass().getNpcStats(player).getFactionRanks()[factionID] +1; } } } @@ -610,9 +610,9 @@ namespace MWScript if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - if(MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().find(factionID) != MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().end()) + if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end()) { - MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] = MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID] -1; + player.getClass().getNpcStats(player).getFactionRanks()[factionID] = player.getClass().getNpcStats(player).getFactionRanks()[factionID] -1; } } } @@ -635,22 +635,22 @@ namespace MWScript } else { - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) { factionID = ""; } else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } } ::Misc::StringUtils::toLower(factionID); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); if(factionID!="") { - if(MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().find(factionID) != MWWorld::Class::get(player).getNpcStats(player).getFactionRanks().end()) + if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end()) { - runtime.push(MWWorld::Class::get(player).getNpcStats(player).getFactionRanks()[factionID]); + runtime.push(player.getClass().getNpcStats(player).getFactionRanks()[factionID]); } else { @@ -676,8 +676,8 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWWorld::Class::get (ptr).getNpcStats (ptr).setBaseDisposition - (MWWorld::Class::get (ptr).getNpcStats (ptr).getBaseDisposition() + value); + ptr.getClass().getNpcStats (ptr).setBaseDisposition + (ptr.getClass().getNpcStats (ptr).getBaseDisposition() + value); } }; @@ -693,7 +693,7 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWWorld::Class::get (ptr).getNpcStats (ptr).setBaseDisposition (value); + ptr.getClass().getNpcStats (ptr).setBaseDisposition (value); } }; @@ -739,8 +739,8 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty()) - factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first; + if (!ptr.getClass().getNpcStats (ptr).getFactionRanks().empty()) + factionId = ptr.getClass().getNpcStats (ptr).getFactionRanks().begin()->first; } if (factionId.empty()) @@ -750,7 +750,7 @@ namespace MWScript MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); runtime.push ( - MWWorld::Class::get (player).getNpcStats (player).getFactionReputation (factionId)); + player.getClass().getNpcStats (player).getFactionReputation (factionId)); } }; @@ -775,8 +775,8 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty()) - factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first; + if (!ptr.getClass().getNpcStats (ptr).getFactionRanks().empty()) + factionId = ptr.getClass().getNpcStats (ptr).getFactionRanks().begin()->first; } if (factionId.empty()) @@ -785,7 +785,7 @@ namespace MWScript ::Misc::StringUtils::toLower (factionId); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::Class::get (player).getNpcStats (player).setFactionReputation (factionId, value); + player.getClass().getNpcStats (player).setFactionReputation (factionId, value); } }; @@ -810,8 +810,8 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty()) - factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first; + if (!ptr.getClass().getNpcStats (ptr).getFactionRanks().empty()) + factionId = ptr.getClass().getNpcStats (ptr).getFactionRanks().begin()->first; } if (factionId.empty()) @@ -820,8 +820,8 @@ namespace MWScript ::Misc::StringUtils::toLower (factionId); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::Class::get (player).getNpcStats (player).setFactionReputation (factionId, - MWWorld::Class::get (player).getNpcStats (player).getFactionReputation (factionId)+ + player.getClass().getNpcStats (player).setFactionReputation (factionId, + player.getClass().getNpcStats (player).getFactionReputation (factionId)+ value); } }; @@ -835,7 +835,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - runtime.push (MWWorld::Class::get (ptr).getCreatureStats (ptr).hasCommonDisease()); + runtime.push (ptr.getClass().getCreatureStats (ptr).hasCommonDisease()); } }; @@ -848,7 +848,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - runtime.push (MWWorld::Class::get (ptr).getCreatureStats (ptr).hasBlightDisease()); + runtime.push (ptr.getClass().getCreatureStats (ptr).hasBlightDisease()); } }; @@ -880,7 +880,7 @@ namespace MWScript { MWWorld::Ptr ptr = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - runtime.push (MWWorld::Class::get(ptr).getNpcStats (ptr).getWerewolfKills ()); + runtime.push (ptr.getClass().getNpcStats (ptr).getWerewolfKills ()); } }; @@ -901,13 +901,13 @@ namespace MWScript } else { - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) { factionID = ""; } else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } } ::Misc::StringUtils::toLower(factionID); @@ -939,13 +939,13 @@ namespace MWScript else { MWWorld::Ptr ptr = R()(runtime); - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) { factionID = ""; } else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } } MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -972,13 +972,13 @@ namespace MWScript else { MWWorld::Ptr ptr = R()(runtime); - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) { factionID = ""; } else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } } MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -997,11 +997,11 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); std::string factionID = ""; - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) return; else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -1009,7 +1009,7 @@ namespace MWScript if (ptr == player) return; - std::map& ranks = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks (); + std::map& ranks = ptr.getClass().getNpcStats(ptr).getFactionRanks (); ranks[factionID] = ranks[factionID]+1; } }; @@ -1024,11 +1024,11 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); std::string factionID = ""; - if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty()) + if(ptr.getClass().getNpcStats(ptr).getFactionRanks().empty()) return; else { - factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().begin()->first; + factionID = ptr.getClass().getNpcStats(ptr).getFactionRanks().begin()->first; } MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -1036,7 +1036,7 @@ namespace MWScript if (ptr == player) return; - std::map& ranks = MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks (); + std::map& ranks = ptr.getClass().getNpcStats(ptr).getFactionRanks (); ranks[factionID] = ranks[factionID]-1; } }; @@ -1051,10 +1051,10 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); Interpreter::Type_Integer value = - MWWorld::Class::get (ptr).getCreatureStats (ptr).hasDied(); + ptr.getClass().getCreatureStats (ptr).hasDied(); if (value) - MWWorld::Class::get (ptr).getCreatureStats (ptr).clearHasDied(); + ptr.getClass().getCreatureStats (ptr).clearHasDied(); runtime.push (value); } @@ -1070,7 +1070,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); Interpreter::Type_Integer value = - MWWorld::Class::get (ptr).getCreatureStats (ptr).getKnockedDownOneFrame(); + ptr.getClass().getCreatureStats (ptr).getKnockedDownOneFrame(); runtime.push (value); } @@ -1084,7 +1084,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { MWWorld::Ptr ptr = R()(runtime); - runtime.push(MWWorld::Class::get(ptr).getNpcStats(ptr).isWerewolf()); + runtime.push(ptr.getClass().getNpcStats(ptr).isWerewolf()); } }; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index e4c1a26772..fb27e73f44 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -319,7 +319,7 @@ namespace MWScript } MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot); - MWWorld::Class::get(ptr).adjustPosition(ptr); + ptr.getClass().adjustPosition(ptr); } else { @@ -366,7 +366,7 @@ namespace MWScript zRot = zRot/60.; } MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot); - MWWorld::Class::get(ptr).adjustPosition(ptr); + ptr.getClass().adjustPosition(ptr); } }; diff --git a/apps/openmw/mwworld/actionapply.cpp b/apps/openmw/mwworld/actionapply.cpp index bd3e875484..6b12cc3e65 100644 --- a/apps/openmw/mwworld/actionapply.cpp +++ b/apps/openmw/mwworld/actionapply.cpp @@ -16,7 +16,7 @@ namespace MWWorld { MWBase::Environment::get().getWorld()->breakInvisibility(actor); - MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor); + getTarget().getClass().apply (getTarget(), mId, actor); } @@ -29,7 +29,7 @@ namespace MWWorld { MWBase::Environment::get().getWorld()->breakInvisibility(actor); - if (MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor) && mUsageType!=-1) - MWWorld::Class::get (getTarget()).skillUsageSucceeded (actor, mSkillIndex, mUsageType); + if (getTarget().getClass().apply (getTarget(), mId, actor) && mUsageType!=-1) + getTarget().getClass().skillUsageSucceeded (actor, mSkillIndex, mUsageType); } } diff --git a/apps/openmw/mwworld/actioneat.cpp b/apps/openmw/mwworld/actioneat.cpp index 020bdb0ff7..6609155236 100644 --- a/apps/openmw/mwworld/actioneat.cpp +++ b/apps/openmw/mwworld/actioneat.cpp @@ -20,10 +20,10 @@ namespace MWWorld getTarget().getContainerStore()->remove(getTarget(), 1, actor); // apply to actor - std::string id = Class::get (getTarget()).getId (getTarget()); + std::string id = getTarget().getClass().getId (getTarget()); - if (Class::get (actor).apply (actor, id, actor)) - Class::get (actor).skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1); + if (actor.getClass().apply (actor, id, actor)) + actor.getClass().skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1); } ActionEat::ActionEat (const MWWorld::Ptr& object) : Action (false, object) {} diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 2a1b7a3aa4..05677cdc7f 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -40,7 +40,7 @@ namespace MWWorld } // slots that this item can be equipped in - std::pair, bool> slots_ = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget()); + std::pair, bool> slots_ = getTarget().getClass().getEquipmentSlots(getTarget()); // retrieve ContainerStoreIterator to the item MWWorld::ContainerStoreIterator it = invStore.begin(); diff --git a/apps/openmw/mwworld/actionread.cpp b/apps/openmw/mwworld/actionread.cpp index 60af3d9b9e..0a4e2d6c9c 100644 --- a/apps/openmw/mwworld/actionread.cpp +++ b/apps/openmw/mwworld/actionread.cpp @@ -47,7 +47,7 @@ namespace MWWorld } MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player); + MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats (player); // Skill gain from books if (ref->mBase->mData.mSkillID >= 0 && ref->mBase->mData.mSkillID < ESM::Skill::Length diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index aa247f0b90..04d733e2c4 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -36,7 +36,7 @@ namespace MWWorld::Ptr container (&*iter, 0); MWWorld::Ptr ptr = - MWWorld::Class::get (container).getContainerStore (container).search (id); + container.getClass().getContainerStore (container).search (id); if (!ptr.isEmpty()) return ptr; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 951ba7865e..6629f84f91 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -323,7 +323,7 @@ namespace MWWorld if(!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) return boost::shared_ptr(new NullAction()); - if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf()) + if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) { const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Sound *sound = store.get().searchRandom("WolfItem"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 0b1eb857c8..b47028e01f 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -325,12 +325,6 @@ namespace MWWorld static const Class& get (const std::string& key); ///< If there is no class for this \a key, an exception is thrown. - static const Class& get (const Ptr& ptr) - { - return ptr.getClass(); - } - ///< If there is no class for this pointer, an exception is thrown. - static void registerClass (const std::string& key, boost::shared_ptr instance); virtual int getBaseGold(const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 8f2a566461..d816f993bd 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -142,8 +142,8 @@ void MWWorld::ContainerStore::unstack(const Ptr &ptr, const Ptr& container) bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) { - const MWWorld::Class& cls1 = MWWorld::Class::get(ptr1); - const MWWorld::Class& cls2 = MWWorld::Class::get(ptr2); + const MWWorld::Class& cls1 = ptr1.getClass(); + const MWWorld::Class& cls2 = ptr2.getClass(); if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().mRefID, ptr2.getCellRef().mRefID)) return false; @@ -226,14 +226,14 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr item.getCellRef().mPos.pos[1] = 0; item.getCellRef().mPos.pos[2] = 0; - std::string script = MWWorld::Class::get(item).getScript(item); + std::string script = item.getClass().getScript(item); if(script != "") { CellStore *cell; MWBase::Environment::get().getWorld()->getLocalScripts().add(script, item); - if(&(MWWorld::Class::get (player).getContainerStore (player)) == this) + if(&(player.getClass().getContainerStore (player)) == this) { cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 7127c92f3f..78a2950304 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -129,7 +129,7 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite std::pair, bool> slots_; - slots_ = Class::get (*iterator).getEquipmentSlots (*iterator); + slots_ = iterator->getClass().getEquipmentSlots (*iterator); if (std::find (slots_.first.begin(), slots_.first.end(), slot)==slots_.first.end()) throw std::runtime_error ("invalid slot"); @@ -258,7 +258,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) } } - switch(MWWorld::Class::get (test).canBeEquipped (test, actor).first) + switch(test.getClass().canBeEquipped (test, actor).first) { case 0: continue; @@ -325,7 +325,7 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor) if (*iter==end()) continue; - std::string enchantmentId = MWWorld::Class::get (**iter).getEnchantment (**iter); + std::string enchantmentId = (*iter)->getClass().getEnchantment (**iter); if (!enchantmentId.empty()) { @@ -441,7 +441,7 @@ bool MWWorld::InventoryStore::stacks(const Ptr& ptr1, const Ptr& ptr2) { if (*iter != end() && (ptr1 == **iter || ptr2 == **iter)) { - bool stackWhenEquipped = MWWorld::Class::get(**iter).getEquipmentSlots(**iter).second; + bool stackWhenEquipped = (*iter)->getClass().getEquipmentSlots(**iter).second; if (!stackWhenEquipped) return false; } @@ -527,7 +527,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c if (actor.getRefData().getHandle() == "player") { // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared - const std::string& script = Class::get(*it).getScript(*it); + const std::string& script = it->getClass().getScript(*it); if (script != "") (*it).getRefData().getLocals().setVarByInt(script, "onpcequip", 0); @@ -579,7 +579,7 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito if (*iter==end()) continue; - std::string enchantmentId = MWWorld::Class::get (**iter).getEnchantment (**iter); + std::string enchantmentId = (*iter)->getClass().getEnchantment (**iter); if (enchantmentId.empty()) continue; diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 844e2b18ba..8a671cea8c 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -36,10 +36,10 @@ namespace MWWorld::Ptr containerPtr (&*iter, cell); - MWWorld::ContainerStore& container = MWWorld::Class::get(containerPtr).getContainerStore(containerPtr); + MWWorld::ContainerStore& container = containerPtr.getClass().getContainerStore(containerPtr); for(MWWorld::ContainerStoreIterator it3 = container.begin(); it3 != container.end(); ++it3) { - std::string script = MWWorld::Class::get(*it3).getScript(*it3); + std::string script = it3->getClass().getScript(*it3); if(script != "") { MWWorld::Ptr item = *it3; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index ced952861e..039fce0caa 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -538,7 +538,7 @@ namespace MWWorld void PhysicsSystem::addObject (const Ptr& ptr, bool placeable) { - std::string mesh = MWWorld::Class::get(ptr).getModel(ptr); + std::string mesh = ptr.getClass().getModel(ptr); Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); handleToMesh[node->getName()] = mesh; OEngine::Physic::RigidBody* body = mEngine->createAndAdjustRigidBody( @@ -550,7 +550,7 @@ namespace MWWorld void PhysicsSystem::addActor (const Ptr& ptr) { - std::string mesh = MWWorld::Class::get(ptr).getModel(ptr); + std::string mesh = ptr.getClass().getModel(ptr); Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); //TODO:optimize this. Searching the std::map isn't very efficient i think. mEngine->addCharacter(node->getName(), mesh, node->getPosition(), node->getScale().x, node->getOrientation()); @@ -651,7 +651,7 @@ namespace MWWorld bool PhysicsSystem::getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max) { - std::string model = MWWorld::Class::get(ptr).getModel(ptr); + std::string model = ptr.getClass().getModel(ptr); if (model.empty()) { return false; } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 1f994d013d..5ca8f29525 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -75,7 +75,7 @@ namespace MWWorld void Player::setDrawState (MWMechanics::DrawState_ state) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get(ptr).getNpcStats(ptr).setDrawState (state); + ptr.getClass().getNpcStats(ptr).setDrawState (state); } bool Player::getAutoMove() const @@ -94,13 +94,13 @@ namespace MWWorld if (mAutoMove) value = 1; - MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[1] = value; + ptr.getClass().getMovementSettings (ptr).mPosition[1] = value; } void Player::setLeftRight (int value) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[0] = value; + ptr.getClass().getMovementSettings (ptr).mPosition[0] = value; } void Player::setForwardBackward (int value) @@ -112,13 +112,13 @@ namespace MWWorld if (mAutoMove) value = 1; - MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[1] = value; + ptr.getClass().getMovementSettings (ptr).mPosition[1] = value; } void Player::setUpDown(int value) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[2] = value; + ptr.getClass().getMovementSettings (ptr).mPosition[2] = value; } void Player::setRunState(bool run) @@ -136,23 +136,23 @@ namespace MWWorld void Player::yaw(float yaw) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[2] += yaw; + ptr.getClass().getMovementSettings(ptr).mRotation[2] += yaw; } void Player::pitch(float pitch) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[0] += pitch; + ptr.getClass().getMovementSettings(ptr).mRotation[0] += pitch; } void Player::roll(float roll) { MWWorld::Ptr ptr = getPlayer(); - MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[1] += roll; + ptr.getClass().getMovementSettings(ptr).mRotation[1] += roll; } MWMechanics::DrawState_ Player::getDrawState() { MWWorld::Ptr ptr = getPlayer(); - return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState(); + return ptr.getClass().getNpcStats(ptr).getDrawState(); } bool Player::wasTeleported() const diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 25ee0c2e83..122a6f9bf5 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -198,7 +198,7 @@ namespace MWWorld float z = Ogre::Radian(pos.rot[2]).valueDegrees(); world->rotateObject(player, x, y, z); - MWWorld::Class::get(player).adjustPosition(player); + player.getClass().adjustPosition(player); } MWBase::MechanicsManager *mechMgr = @@ -399,7 +399,7 @@ namespace MWWorld float z = Ogre::Radian(position.rot[2]).valueDegrees(); world->rotateObject(world->getPlayerPtr(), x, y, z); - MWWorld::Class::get(world->getPlayerPtr()).adjustPosition(world->getPlayerPtr()); + world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr()); world->getFader()->fadeIn(0.5f); return; } @@ -482,7 +482,7 @@ namespace MWWorld void Scene::addObjectToScene (const Ptr& ptr) { mRendering.addObject(ptr); - MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics); + ptr.getClass().insertObject(ptr, *mPhysics); MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale); } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 9b5f9d9d3d..5a83a5bc74 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -537,8 +537,8 @@ namespace MWWorld return ptr; } - Ptr ptr = Class::get (mPlayer->getPlayer()). - getContainerStore (mPlayer->getPlayer()).search (lowerCaseName); + Ptr ptr = mPlayer->getPlayer().getClass() + .getContainerStore(mPlayer->getPlayer()).search(lowerCaseName); if (!ptr.isEmpty()) return ptr; @@ -589,10 +589,10 @@ namespace MWWorld reference.getTypeName()==typeid (ESM::NPC).name() || reference.getTypeName()==typeid (ESM::Creature).name()) { - MWWorld::ContainerStore& container = MWWorld::Class::get(reference).getContainerStore(reference); + MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference); for(MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it) { - std::string script = MWWorld::Class::get(*it).getScript(*it); + std::string script = it->getClass().getScript(*it); if(script != "") { MWWorld::Ptr item = *it; @@ -624,10 +624,10 @@ namespace MWWorld reference.getTypeName()==typeid (ESM::NPC).name() || reference.getTypeName()==typeid (ESM::Creature).name()) { - MWWorld::ContainerStore& container = MWWorld::Class::get(reference).getContainerStore(reference); + MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference); for(MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it) { - std::string script = MWWorld::Class::get(*it).getScript(*it); + std::string script = it->getClass().getScript(*it); if(script != "") { MWWorld::Ptr item = *it; @@ -976,14 +976,14 @@ namespace MWWorld removeContainerScripts (ptr); haveToMove = false; - MWWorld::Ptr newPtr = MWWorld::Class::get(ptr) + MWWorld::Ptr newPtr = ptr.getClass() .copyToCell(ptr, *newCell); newPtr.getRefData().setBaseNode(0); } else { MWWorld::Ptr copy = - MWWorld::Class::get(ptr).copyToCell(ptr, *newCell, pos); + ptr.getClass().copyToCell(ptr, *newCell, pos); mRendering->updateObjectCell(ptr, copy); MWBase::Environment::get().getSoundManager()->updatePtr (ptr, copy); @@ -992,7 +992,7 @@ namespace MWWorld mechMgr->updateCell(ptr, copy); std::string script = - MWWorld::Class::get(ptr).getScript(ptr); + ptr.getClass().getScript(ptr); if (!script.empty()) { mLocalScripts.remove(ptr); @@ -1035,7 +1035,7 @@ namespace MWWorld void World::scaleObject (const Ptr& ptr, float scale) { ptr.getCellRef().mScale = scale; - MWWorld::Class::get(ptr).adjustScale(ptr,scale); + ptr.getClass().adjustScale(ptr,scale); if(ptr.getRefData().getBaseNode() == 0) return; @@ -1062,7 +1062,7 @@ namespace MWWorld objRot[2] = rot.z; } - if(Class::get(ptr).isActor()) + if(ptr.getClass().isActor()) { /* HACK? Actors shouldn't really be rotating around X (or Y), but * currently it's done so for rotating the camera, which needs @@ -1580,7 +1580,7 @@ namespace MWWorld void World::PCDropped (const Ptr& item) { - std::string script = MWWorld::Class::get(item).getScript(item); + std::string script = item.getClass().getScript(item); // Set OnPCDrop Variable on item's script, if it has a script with that variable declared if(script != "") @@ -1648,13 +1648,13 @@ namespace MWWorld } MWWorld::Ptr dropped = - MWWorld::Class::get(object).copyToCell(object, *cell, pos); + object.getClass().copyToCell(object, *cell, pos); if (mWorldScene->isCellActive(*cell)) { if (dropped.getRefData().isEnabled()) { mWorldScene->addObjectToScene(dropped); } - std::string script = MWWorld::Class::get(dropped).getScript(dropped); + std::string script = dropped.getClass().getScript(dropped); if (!script.empty()) { mLocalScripts.add(script, dropped); } @@ -1863,7 +1863,7 @@ namespace MWWorld if((!physactor->getOnGround()&&physactor->getCollisionMode()) || isUnderwater(currentCell, playerPos)) return 2; if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) || - Class::get(player).getNpcStats(player).isWerewolf()) + player.getClass().getNpcStats(player).isWerewolf()) return 1; return 0; @@ -2107,7 +2107,7 @@ namespace MWWorld void World::setWerewolf(const MWWorld::Ptr& actor, bool werewolf) { - MWMechanics::NpcStats& npcStats = Class::get(actor).getNpcStats(actor); + MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats(actor); // The actor does not have to change state if (npcStats.isWerewolf() == werewolf) @@ -2119,7 +2119,7 @@ namespace MWWorld // bones that do not even exist with the werewolf object root. // Therefore, make sure to unequip everything at once, and only fire the change event // (which will rebuild the animation parts) afterwards. unequipAll will do this for us. - MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor); + MWWorld::InventoryStore& invStore = actor.getClass().getInventoryStore(actor); invStore.unequipAll(actor); if(werewolf) @@ -2158,7 +2158,7 @@ namespace MWWorld void World::applyWerewolfAcrobatics(const Ptr &actor) { const Store &gmst = getStore().get(); - MWMechanics::NpcStats &stats = Class::get(actor).getNpcStats(actor); + MWMechanics::NpcStats &stats = actor.getClass().getNpcStats(actor); stats.getSkill(ESM::Skill::Acrobatics).setBase(gmst.find("fWerewolfAcrobatics")->getFloat()); } From e51300989cbb8ff0bb341da67bd7147c0cd5e3f9 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 22:15:20 +0200 Subject: [PATCH 42/82] Handle NiBSPArrayController as alias for NiParticleSystemController The differences (if any) are unknown. NiBSPArrayController is used by the Atronach_Fire.nif model. Its particles are now visible, but they don't look right yet. Need to handle NiAutoNormalParticlesData? --- components/nifogre/ogrenifloader.cpp | 3 ++- components/nifogre/skeleton.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/nifogre/ogrenifloader.cpp b/components/nifogre/ogrenifloader.cpp index ce82446194..36d7508214 100644 --- a/components/nifogre/ogrenifloader.cpp +++ b/components/nifogre/ogrenifloader.cpp @@ -863,7 +863,8 @@ class NIFObjectLoader Nif::ControllerPtr ctrl = partnode->controller; while(!ctrl.empty()) { - if(ctrl->recType == Nif::RC_NiParticleSystemController && ctrl->flags & Nif::NiNode::ControllerFlag_Active) + if((ctrl->recType == Nif::RC_NiParticleSystemController || ctrl->recType == Nif::RC_NiBSPArrayController) + && ctrl->flags & Nif::NiNode::ControllerFlag_Active) { const Nif::NiParticleSystemController *partctrl = static_cast(ctrl.getPtr()); diff --git a/components/nifogre/skeleton.cpp b/components/nifogre/skeleton.cpp index c0482cf5e3..26647e595d 100644 --- a/components/nifogre/skeleton.cpp +++ b/components/nifogre/skeleton.cpp @@ -42,6 +42,7 @@ void NIFSkeletonLoader::buildBones(Ogre::Skeleton *skel, const Nif::Node *node, while(!ctrl.empty()) { if(!(ctrl->recType == Nif::RC_NiParticleSystemController || + ctrl->recType == Nif::RC_NiBSPArrayController || ctrl->recType == Nif::RC_NiVisController || ctrl->recType == Nif::RC_NiUVController || ctrl->recType == Nif::RC_NiKeyframeController || From df8e095c83ac2655cee0082d3f06c8419fc29e24 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 23:27:54 +0200 Subject: [PATCH 43/82] Small cleanup --- apps/openmw/mwdialogue/filter.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 5bdf80593b..863a0f2ffc 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -264,15 +264,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con { MWWorld::ContainerStore& store = MWWorld::Class::get (player).getContainerStore (player); - int sum = 0; - - std::string name = select.getName(); - - for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) - if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, name)) - sum += iter->getRefData().getCount(); - - return sum; + return store.count(select.getName()); } case SelectWrapper::Function_Dead: From a2f156be8e506503628c424e695ede9834f234b3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 22 May 2014 23:33:34 +0200 Subject: [PATCH 44/82] Prevent magic bolts from colliding with their caster --- apps/openmw/mwworld/projectilemanager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 266b566f70..bf0fb75795 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -152,6 +152,10 @@ namespace MWWorld MWWorld::Ptr obstacle = MWBase::Environment::get().getWorld()->searchPtrViaHandle(cIt->second); MWWorld::Ptr caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->mActorId); + + if (!obstacle.isEmpty() && obstacle == caster) + continue; + if (caster.isEmpty()) caster = obstacle; From 3718847ffc0c77db9d979d1a4aed7f351c92a96e Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 23 May 2014 21:07:01 +1000 Subject: [PATCH 45/82] Disable video for Windows until the crash issues are fixed. --- apps/openmw/mwrender/videoplayer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index 82400aac43..b1519b9d2c 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -1080,6 +1080,11 @@ VideoPlayer::~VideoPlayer() void VideoPlayer::playVideo(const std::string &resourceName) { +#ifdef WIN32 + // FIXME: Need FFmpeg FLTP audio support for BIK video format + std::cout<<"Temporarily disabled, did not play \""+resourceName+"\""< Date: Fri, 23 May 2014 21:55:47 +1000 Subject: [PATCH 46/82] Enable video but without sound. --- apps/openmw/mwrender/videoplayer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index b1519b9d2c..9fd1cee961 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -970,8 +970,13 @@ void VideoState::init(const std::string& resourceName) MWBase::Environment::get().getSoundManager()->pauseSounds(); this->external_clock_base = av_gettime(); +#ifdef WIN32 + // FIXME: Need FFmpeg FLTP audio support for BIK video format + std::cout<<"Sound temporarily disabled for \""+resourceName+"\""<= 0) this->stream_open(audio_index, this->format_ctx); +#endif if(video_index >= 0) { this->stream_open(video_index, this->format_ctx); @@ -1080,11 +1085,6 @@ VideoPlayer::~VideoPlayer() void VideoPlayer::playVideo(const std::string &resourceName) { -#ifdef WIN32 - // FIXME: Need FFmpeg FLTP audio support for BIK video format - std::cout<<"Temporarily disabled, did not play \""+resourceName+"\""< Date: Fri, 23 May 2014 08:41:49 -0400 Subject: [PATCH 47/82] missing #include in mwiniimporter missing #include in mwiniimporter/main.cpp --- apps/mwiniimporter/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index c2408a5541..c10103cd62 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -1,6 +1,7 @@ #include "importer.hpp" #include +#include #include #include From a7d525245ce81c583a8db943dd0df77fbea8b277 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 23 May 2014 16:07:02 +0200 Subject: [PATCH 48/82] Fix missing include --- apps/openmw/mwworld/projectilemanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index bf0fb75795..12cca27545 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -1,6 +1,7 @@ #include "projectilemanager.hpp" #include +#include #include From f09c8ddc9e3ba3258b3af1faafdb0800bd8ebfc2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 23 May 2014 16:39:42 +0200 Subject: [PATCH 49/82] Remove a pointless assert --- apps/openmw/mwmechanics/creaturestats.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 3648877fdd..3ef6ff4df9 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -102,7 +102,6 @@ namespace MWMechanics Stat CreatureStats::getAiSetting (AiSetting index) const { - assert (index>=0 && index<4); return mAiSettings[index]; } @@ -220,7 +219,6 @@ namespace MWMechanics void CreatureStats::setAiSetting (AiSetting index, Stat value) { - assert (index>=0 && index<4); mAiSettings[index] = value; } From 1d8da957564b4dd6823935961e7c58ecdfdef0fc Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 24 May 2014 14:47:51 +0200 Subject: [PATCH 50/82] Warning fix --- apps/openmw/mwrender/localmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 0d32dd0ef0..2b0323675e 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -353,7 +353,7 @@ void LocalMap::loadFogOfWar (const std::string& texturePrefix, ESM::FogTexture& Ogre::Image image; image.load(stream, "tga"); - if (image.getWidth() != sFogOfWarResolution || image.getHeight() != sFogOfWarResolution) + if (int(image.getWidth()) != sFogOfWarResolution || int(image.getHeight()) != sFogOfWarResolution) throw std::runtime_error("fog texture size mismatch"); std::string texName = texturePrefix + "_fog"; From a05c8fd3ceefa0d0f0ff287023eb332217552315 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 24 May 2014 14:48:37 +0200 Subject: [PATCH 51/82] Make applyEnchantment return the record ID instead of modifying Ptr --- apps/openmw/mwclass/armor.cpp | 5 ++--- apps/openmw/mwclass/armor.hpp | 3 ++- apps/openmw/mwclass/book.cpp | 5 ++--- apps/openmw/mwclass/book.hpp | 3 ++- apps/openmw/mwclass/clothing.cpp | 5 ++--- apps/openmw/mwclass/clothing.hpp | 3 ++- apps/openmw/mwclass/weapon.cpp | 5 ++--- apps/openmw/mwclass/weapon.hpp | 3 ++- apps/openmw/mwmechanics/enchanting.cpp | 10 ++-------- apps/openmw/mwmechanics/enchanting.hpp | 1 - apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 3 ++- 12 files changed, 21 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 26d1cab6d2..d7dae97a5b 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -272,7 +272,7 @@ namespace MWClass return ref->mBase->mEnchant; } - void Armor::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + std::string Armor::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { MWWorld::LiveCellRef *ref = ptr.get(); @@ -283,8 +283,7 @@ namespace MWClass newItem.mData.mEnchant=enchCharge; newItem.mEnchant=enchId; const ESM::Armor *record = MWBase::Environment::get().getWorld()->createRecord (newItem); - ref->mBase = record; - ref->mRef.mRefID = record->mId; + return record->mId; } std::pair Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 17cfca4534..e9164f920b 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -67,7 +67,8 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. \n diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 183d91ca1f..338a7ba0d7 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -159,7 +159,7 @@ namespace MWClass return ref->mBase->mEnchant; } - void Book::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + std::string Book::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { MWWorld::LiveCellRef *ref = ptr.get(); @@ -171,8 +171,7 @@ namespace MWClass newItem.mData.mEnchant=enchCharge; newItem.mEnchant=enchId; const ESM::Book *record = MWBase::Environment::get().getWorld()->createRecord (newItem); - ref->mBase = record; - ref->mRef.mRefID = record->mId; + return record->mId; } boost::shared_ptr Book::use (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 79b823fa9f..b60ef41d64 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -51,7 +51,8 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) const; ///< Generate action for using via inventory menu diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index a174f69a77..f596f60deb 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -215,7 +215,7 @@ namespace MWClass return ref->mBase->mEnchant; } - void Clothing::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + std::string Clothing::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { MWWorld::LiveCellRef *ref = ptr.get(); @@ -226,8 +226,7 @@ namespace MWClass newItem.mData.mEnchant=enchCharge; newItem.mEnchant=enchId; const ESM::Clothing *record = MWBase::Environment::get().getWorld()->createRecord (newItem); - ref->mBase = record; - ref->mRef.mRefID = record->mId; + return record->mId; } std::pair Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index a73b2c1907..052928238e 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -59,7 +59,8 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 146251ca29..5edf22b008 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -372,7 +372,7 @@ namespace MWClass return ref->mBase->mEnchant; } - void Weapon::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + std::string Weapon::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { MWWorld::LiveCellRef *ref = ptr.get(); @@ -383,8 +383,7 @@ namespace MWClass newItem.mData.mEnchant=enchCharge; newItem.mEnchant=enchId; const ESM::Weapon *record = MWBase::Environment::get().getWorld()->createRecord (newItem); - ref->mBase = record; - ref->mRef.mRefID = record->mId; + return record->mId; } std::pair Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index db44cd2b71..97ee102911 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -68,7 +68,8 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 23246c2945..9c5c9dbb9d 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -20,12 +20,10 @@ namespace MWMechanics if(!itemEmpty()) { mObjectType = mOldItemPtr.getTypeName(); - mOldItemId = mOldItemPtr.getCellRef().mRefID; } else { mObjectType=""; - mOldItemId=""; } } @@ -78,17 +76,13 @@ namespace MWMechanics enchantment.mData.mCost = getEnchantPoints(); enchantment.mEffects = mEffectList; - // Create a new item - MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId, 1); - const MWWorld::Ptr& newItemPtr = ref.getPtr(); - // Apply the enchantment const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment); - newItemPtr.getClass().applyEnchantment(newItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); + std::string newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); // Add the new item to player inventory and remove the old one store.remove(mOldItemPtr, 1, player); - store.add(newItemPtr, 1, player); + store.add(newItemId, 1, player); if(!mSelfEnchanting) payForEnchantment(); diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index ae0b25a4a2..01ca1e0e1d 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -21,7 +21,6 @@ namespace MWMechanics std::string mNewItemName; std::string mObjectType; - std::string mOldItemId; public: Enchanting(); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 6629f84f91..100e758f24 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -304,7 +304,7 @@ namespace MWWorld return ""; } - void Class::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + std::string Class::applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { throw std::runtime_error ("class can't be enchanted"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index b47028e01f..54cea9ab01 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -278,7 +278,8 @@ namespace MWWorld virtual std::string getModel(const MWWorld::Ptr &ptr) const; - virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual std::string applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. From 56881cb7c91e956831a42340528530f58f8e4456 Mon Sep 17 00:00:00 2001 From: mrcheko Date: Sat, 24 May 2014 23:05:30 +0400 Subject: [PATCH 52/82] fix bugs in aisequence::execute --- apps/openmw/mwmechanics/aisequence.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 980a23a3ed..6d2c15549f 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -137,7 +137,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration) float nearestDist = std::numeric_limits::max(); Ogre::Vector3 vActorPos = Ogre::Vector3(actor.getRefData().getPosition().pos); - for(std::list::iterator it = mPackages.begin(); it != mPackages.end(); ++it) + for(std::list::iterator it = mPackages.begin(); it != mPackages.end();) { if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break; @@ -147,7 +147,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration) if (target.isEmpty()) { delete *it; - mPackages.erase(it++); + it = mPackages.erase(it); } else { @@ -159,20 +159,26 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration) nearestDist = distTo; itActualCombat = it; } + ++it; } } - // all targets disappeared - if (nearestDist == std::numeric_limits::max()) + if (!mPackages.empty()) + { + if (nearestDist < std::numeric_limits::max() && mPackages.begin() != itActualCombat) + { + // move combat package with nearest target to the front + mPackages.splice(mPackages.begin(), mPackages, itActualCombat); + } + + package = mPackages.front(); + mLastAiPackage = package->getTypeId(); + } + else { mDone = true; return; } - else if (mPackages.begin() != itActualCombat) - { - // move combat package with nearest target to the front - mPackages.splice(mPackages.begin(), mPackages, itActualCombat); - } } if (package->execute (actor,duration)) From 4f94a31b5422545a8ed7b76920c132192a9c5a9d Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 25 May 2014 07:50:19 +1000 Subject: [PATCH 53/82] Fix crash starting a new game. --- apps/openmw/mwscript/cellextensions.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 825d62efb5..ac175634bd 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -88,6 +88,12 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { + if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) + { + runtime.push (0); + return; + } + bool interior = !MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->isExterior(); From d2794165bac7e4993510d1b9bf95f90fe7312508 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 25 May 2014 18:56:50 +1000 Subject: [PATCH 54/82] Disable binkaudio sound for FFmpeg libavocdec versions below 54.55.xxx (Windows x64) and 54.10.xxx (Windows 32bit). Later versions are all allowed, but due to sample formats there will be no sound and this message will be shown on the console "Sound Error: Unsupported sample format: fltp" --- apps/openmw/mwrender/videoplayer.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index 82400aac43..fe97d77d4c 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -50,6 +50,29 @@ extern "C" #endif } +#ifdef _WIN32 + // Decide whether to play binkaudio. + #include + // libavcodec versions 54.10.100 (or maybe earlier) to 54.54.100 potentially crashes Windows 64bit. + // From version 54.56 or higher, there's no sound due to the encoding format changing from S16 to FLTP + // (see https://gitorious.org/ffmpeg/ffmpeg/commit/7bfd1766d1c18f07b0a2dd042418a874d49ea60d and + // http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=3049d5b9b32845c86aa5588bb3352bdeb2edfdb2;hp=43c6b45a53a186a187f7266e4d6bd3c2620519f1), + // but does not crash (or at least no known crash). + #if (LIBAVCODEC_VERSION_MAJOR > 54) + #define FFMPEG_PLAY_BINKAUDIO + #else + #ifdef _WIN64 + #if ((LIBAVCODEC_VERSION_MAJOR == 54) && (LIBAVCODEC_VERSION_MINOR >= 55)) + #define FFMPEG_PLAY_BINKAUDIO + #endif + #else + #if ((LIBAVCODEC_VERSION_MAJOR == 54) && (LIBAVCODEC_VERSION_MINOR >= 10)) + #define FFMPEG_PLAY_BINKAUDIO + #endif + #endif + #endif +#endif + #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) #define MAX_VIDEOQ_SIZE (5 * 256 * 1024) #define AV_SYNC_THRESHOLD 0.01 @@ -970,8 +993,12 @@ void VideoState::init(const std::string& resourceName) MWBase::Environment::get().getSoundManager()->pauseSounds(); this->external_clock_base = av_gettime(); +#if !defined(_WIN32) || defined(FFMPEG_PLAY_BINKAUDIO) if(audio_index >= 0) this->stream_open(audio_index, this->format_ctx); +#else + std::cout<<"FFmpeg sound disabled for \""+resourceName+"\""<= 0) { this->stream_open(video_index, this->format_ctx); From c62187bd555e3bcdef232c5c3e1c949809b2e5ca Mon Sep 17 00:00:00 2001 From: mrcheko Date: Sun, 25 May 2014 13:31:46 +0400 Subject: [PATCH 55/82] fix bug at http://bugs.openmw.org/issues/1155 Though it still can happen sometimes but not in such stupid manner. --- apps/openmw/mwmechanics/aicombat.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 1027cc48a7..9fe92f8070 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -330,7 +330,7 @@ namespace MWMechanics bool isStuck = false; float speed = 0.0f; - if(mMovement.mPosition[1] && (Ogre::Vector3(mLastPos.pos) - vActorPos).length() < (speed = actorCls.getSpeed(actor)) / 10.0f) + if(mMovement.mPosition[1] && (Ogre::Vector3(mLastPos.pos) - vActorPos).length() < (speed = actorCls.getSpeed(actor)) * tReaction / 2) isStuck = true; mLastPos = pos; @@ -397,14 +397,10 @@ namespace MWMechanics { bool preferShortcut = false; bool inLOS = MWBase::Environment::get().getWorld()->getLOS(actor, target); - - if(mReadyToAttack) isStuck = false; // check if shortcut is available - if(!isStuck - && (!mForceNoShortcut - || (Ogre::Vector3(mShortcutFailPos.pos) - vActorPos).length() >= PATHFIND_SHORTCUT_RETRY_DIST) - && inLOS) + if(inLOS && (!isStuck || mReadyToAttack) + && (!mForceNoShortcut || (Ogre::Vector3(mShortcutFailPos.pos) - vActorPos).length() >= PATHFIND_SHORTCUT_RETRY_DIST)) { if(speed == 0.0f) speed = actorCls.getSpeed(actor); // maximum dist before pit/obstacle for actor to avoid them depending on his speed @@ -467,7 +463,7 @@ namespace MWMechanics mReadyToAttack = false; } - if(distToTarget > rangeAttack && !distantCombat) + if(!isStuck && distToTarget > rangeAttack && !distantCombat) { //special run attack; it shouldn't affect melee combat tactics if(actorCls.getMovementSettings(actor).mPosition[1] == 1) From 039398c8aeecc54b627d6294b6c8e11c9abda133 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 25 May 2014 14:13:07 +0200 Subject: [PATCH 56/82] Basic RefData and CellRef change tracking Wrapped item charge handling in getItemHealth function --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwclass/activator.cpp | 4 +- apps/openmw/mwclass/apparatus.cpp | 4 +- apps/openmw/mwclass/armor.cpp | 15 +- apps/openmw/mwclass/book.cpp | 4 +- apps/openmw/mwclass/clothing.cpp | 6 +- apps/openmw/mwclass/container.cpp | 34 ++-- apps/openmw/mwclass/creature.cpp | 34 ++-- apps/openmw/mwclass/creaturelevlist.cpp | 4 +- apps/openmw/mwclass/door.cpp | 42 ++-- apps/openmw/mwclass/ingredient.cpp | 4 +- apps/openmw/mwclass/light.cpp | 4 +- apps/openmw/mwclass/lockpick.cpp | 11 +- apps/openmw/mwclass/misc.cpp | 37 ++-- apps/openmw/mwclass/npc.cpp | 47 ++--- apps/openmw/mwclass/potion.cpp | 4 +- apps/openmw/mwclass/probe.cpp | 11 +- apps/openmw/mwclass/repair.cpp | 11 +- apps/openmw/mwclass/weapon.cpp | 15 +- apps/openmw/mwgui/console.cpp | 2 +- apps/openmw/mwgui/enchantingdialog.cpp | 2 +- apps/openmw/mwgui/hud.cpp | 2 +- apps/openmw/mwgui/inventoryitemmodel.cpp | 4 +- apps/openmw/mwgui/inventorywindow.cpp | 6 +- apps/openmw/mwgui/merchantrepair.cpp | 4 +- apps/openmw/mwgui/pickpocketitemmodel.cpp | 4 +- apps/openmw/mwgui/quickkeysmenu.cpp | 11 +- apps/openmw/mwgui/recharge.cpp | 14 +- apps/openmw/mwgui/repair.cpp | 4 +- apps/openmw/mwgui/sortfilteritemmodel.cpp | 2 +- apps/openmw/mwgui/spellwindow.cpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 2 +- apps/openmw/mwgui/tradeitemmodel.cpp | 6 +- apps/openmw/mwgui/tradewindow.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 8 +- apps/openmw/mwmechanics/actors.cpp | 22 +-- apps/openmw/mwmechanics/aiavoiddoor.cpp | 5 - apps/openmw/mwmechanics/aiavoiddoor.hpp | 3 - apps/openmw/mwmechanics/aicombat.cpp | 4 +- apps/openmw/mwmechanics/aipackage.cpp | 2 +- apps/openmw/mwmechanics/combat.cpp | 9 +- apps/openmw/mwmechanics/enchanting.cpp | 4 +- .../mwmechanics/mechanicsmanagerimp.cpp | 8 +- apps/openmw/mwmechanics/obstacle.cpp | 2 +- apps/openmw/mwmechanics/repair.cpp | 14 +- apps/openmw/mwmechanics/security.cpp | 26 +-- apps/openmw/mwmechanics/spellcasting.cpp | 22 +-- apps/openmw/mwrender/actors.cpp | 4 +- apps/openmw/mwrender/animation.cpp | 6 +- apps/openmw/mwrender/objects.cpp | 4 +- apps/openmw/mwscript/cellextensions.cpp | 5 + apps/openmw/mwscript/containerextensions.cpp | 8 +- apps/openmw/mwscript/miscextensions.cpp | 16 +- .../mwscript/transformationextensions.cpp | 26 +-- apps/openmw/mwworld/actiontrap.cpp | 2 +- apps/openmw/mwworld/cellref.cpp | 185 ++++++++++++++++++ apps/openmw/mwworld/cellref.hpp | 99 ++++++++++ apps/openmw/mwworld/cellreflist.hpp | 2 +- apps/openmw/mwworld/cellstore.cpp | 14 +- apps/openmw/mwworld/class.cpp | 8 + apps/openmw/mwworld/class.hpp | 5 +- apps/openmw/mwworld/containerstore.cpp | 60 +++--- apps/openmw/mwworld/inventorystore.cpp | 22 +-- apps/openmw/mwworld/livecellref.cpp | 4 +- apps/openmw/mwworld/livecellref.hpp | 8 +- apps/openmw/mwworld/manualref.hpp | 31 ++- apps/openmw/mwworld/physicssystem.cpp | 2 +- apps/openmw/mwworld/player.cpp | 6 +- apps/openmw/mwworld/projectilemanager.cpp | 8 +- apps/openmw/mwworld/ptr.cpp | 2 +- apps/openmw/mwworld/ptr.hpp | 2 +- apps/openmw/mwworld/refdata.cpp | 24 ++- apps/openmw/mwworld/refdata.hpp | 5 + apps/openmw/mwworld/scene.cpp | 12 +- apps/openmw/mwworld/worldimp.cpp | 32 +-- components/esm/cellref.cpp | 2 +- components/esm/cellref.hpp | 22 ++- components/esm/loadcell.cpp | 6 +- components/esm/loadcell.hpp | 6 +- 79 files changed, 720 insertions(+), 407 deletions(-) create mode 100644 apps/openmw/mwworld/cellref.cpp create mode 100644 apps/openmw/mwworld/cellref.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 9e959a986d..8496b47a4a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -57,7 +57,7 @@ add_openmw_dir (mwworld cells localscripts customdata weather inventorystore ptr actionopen actionread actionequip timestamp actionalchemy cellstore actionapply actioneat esmstore store recordcmp fallback actionrepair actionsoulgem livecellref actiondoor - contentloader esmloader omwloader actiontrap cellreflist projectilemanager + contentloader esmloader omwloader actiontrap cellreflist projectilemanager cellref ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index fe9368b446..043aadd359 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -97,8 +97,8 @@ namespace MWClass std::string text; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 8580d61ce0..947a9cb948 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -127,8 +127,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index d7dae97a5b..825b14978f 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -168,10 +168,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ptr.getCellRef().mCharge == -1) - return ref->mBase->mData.mValue; - else - return ref->mBase->mData.mValue * (static_cast(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); + return ref->mBase->mData.mValue * (static_cast(getItemHealth(ptr)) / getItemMaxHealth(ptr)); } void Armor::registerSelf() @@ -242,7 +239,7 @@ namespace MWClass text += "\n#{sArmorRating}: " + MWGui::ToolTips::toString(ref->mBase->mData.mArmor); - int remainingHealth = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mHealth; + int remainingHealth = getItemHealth(ptr); text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/" + MWGui::ToolTips::toString(ref->mBase->mData.mHealth); @@ -250,14 +247,14 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.enchant = ref->mBase->mEnchant; if (!info.enchant.empty()) - info.remainingEnchantCharge = ptr.getCellRef().mEnchantmentCharge; + info.remainingEnchantCharge = ptr.getCellRef().getEnchantmentCharge(); info.text = text; @@ -290,7 +287,7 @@ namespace MWClass { MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc); - if (ptr.getCellRef().mCharge == 0) + if (ptr.getCellRef().getCharge() == 0) return std::make_pair(0, "#{sInventoryMessage1}"); // slots that this item can be equipped in diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 338a7ba0d7..0cc2e60207 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -139,8 +139,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index f596f60deb..c0362188b8 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -193,14 +193,14 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } info.enchant = ref->mBase->mEnchant; if (!info.enchant.empty()) - info.remainingEnchantCharge = ptr.getCellRef().mEnchantmentCharge; + info.remainingEnchantCharge = ptr.getCellRef().getEnchantmentCharge(); info.text = text; diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 62734c03de..9498ea52df 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -53,7 +53,7 @@ namespace MWClass ptr.get(); data->mContainerStore.fill( - ref->mBase->mInventory, ptr.getCellRef().mOwner, ptr.getCellRef().mFaction, MWBase::Environment::get().getWorld()->getStore()); + ref->mBase->mInventory, ptr.getCellRef().getOwner(), ptr.getCellRef().getFaction(), MWBase::Environment::get().getWorld()->getStore()); // store ptr.getRefData().setCustomData (data.release()); @@ -75,7 +75,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); const ESM::InventoryList& list = ref->mBase->mInventory; MWWorld::ContainerStore& store = getContainerStore(ptr); - store.restock(list, ptr, ptr.getCellRef().mOwner, ptr.getCellRef().mFaction); + store.restock(list, ptr, ptr.getCellRef().getOwner(), ptr.getCellRef().getFaction()); } void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const @@ -129,16 +129,16 @@ namespace MWClass MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); - bool needKey = ptr.getCellRef().mLockLevel > 0; + bool needKey = ptr.getCellRef().getLockLevel() > 0; bool hasKey = false; std::string keyName; // make key id lowercase - std::string keyId = ptr.getCellRef().mKey; + std::string keyId = ptr.getCellRef().getKey(); Misc::StringUtils::toLower(keyId); for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { - std::string refId = it->getCellRef().mRefID; + std::string refId = it->getCellRef().getRefId(); Misc::StringUtils::toLower(refId); if (refId == keyId) { @@ -152,13 +152,13 @@ namespace MWClass MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}"); unlock(ptr); // using a key disarms the trap - ptr.getCellRef().mTrap = ""; + ptr.getCellRef().setTrap(""); } if (!needKey || hasKey) { - if(ptr.getCellRef().mTrap.empty()) + if(ptr.getCellRef().getTrap().empty()) { boost::shared_ptr action (new MWWorld::ActionOpen(ptr)); return action; @@ -166,7 +166,7 @@ namespace MWClass else { // Activate trap - boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().mTrap, ptr)); + boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); action->setSound(trapActivationSound); return action; } @@ -227,16 +227,16 @@ namespace MWClass info.caption = ref->mBase->mName; std::string text; - if (ref->mRef.mLockLevel > 0) - text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ref->mRef.mLockLevel); - else if (ref->mRef.mLockLevel < 0) + if (ptr.getCellRef().getLockLevel() > 0) + text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); + else if (ptr.getCellRef().getLockLevel() < 0) text += "\n#{sUnlocked}"; - if (ref->mRef.mTrap != "") + if (ptr.getCellRef().getTrap() != "") text += "\n#{sTrapped}"; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } @@ -261,14 +261,14 @@ namespace MWClass void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if(lockLevel!=0) - ptr.getCellRef().mLockLevel = abs(lockLevel); //Changes lock to locklevel, in positive + ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, in positive else - ptr.getCellRef().mLockLevel = abs(ptr.getCellRef().mLockLevel); //No locklevel given, just flip the oriional one + ptr.getCellRef().setLockLevel(abs(ptr.getCellRef().getLockLevel())); //No locklevel given, just flip the original one } void Container::unlock (const MWWorld::Ptr& ptr) const { - ptr.getCellRef().mLockLevel = -abs(ptr.getCellRef().mLockLevel); //Makes lockLevel negative + ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 7e484f9d48..1a6e4e321d 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -291,20 +291,24 @@ namespace MWClass weaponDamage *= 0.5f + (stats.getAttribute(ESM::Attribute::Luck).getModified() / 100.0f); if(weaphashealth) { - int weapmaxhealth = weapon.get()->mBase->mData.mHealth; - if(weapon.getCellRef().mCharge == -1) - weapon.getCellRef().mCharge = weapmaxhealth; - weaponDamage *= float(weapon.getCellRef().mCharge) / weapmaxhealth; + int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon); + int weaphealth = weapon.getClass().getItemHealth(weapon); + weaponDamage *= float(weaphealth) / weapmaxhealth; + + if (!MWBase::Environment::get().getWorld()->getGodModeState()) + { + // Reduce weapon charge by at least one, but cap at 0 + weaphealth -= std::min(std::max(1, + (int)(damage * gmst.find("fWeaponDamageMult")->getFloat())), weaphealth); + + weapon.getCellRef().setCharge(weaphealth); + } + + // Weapon broken? unequip it + if (weapon.getCellRef().getCharge() == 0) + weapon = *getInventoryStore(ptr).unequipItem(weapon, ptr); } - if (!MWBase::Environment::get().getWorld()->getGodModeState()) - weapon.getCellRef().mCharge -= std::min(std::max(1, - (int)(damage * gmst.find("fWeaponDamageMult")->getFloat())), weapon.getCellRef().mCharge); - - // Weapon broken? unequip it - if (weapon.getCellRef().mCharge == 0) - weapon = *getInventoryStore(ptr).unequipItem(weapon, ptr); - damage += weaponDamage; } @@ -825,14 +829,14 @@ namespace MWClass { // Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell. // This also means we cannot respawn dynamically placed references with no content file connection. - if (ptr.getCellRef().mRefNum.mContentFile != -1) + if (ptr.getCellRef().getRefNum().mContentFile != -1) { if (ptr.getRefData().getCount() == 0) ptr.getRefData().setCount(1); // Reset to original position ESM::Position& pos = ptr.getRefData().getPosition(); - pos = ptr.getCellRef().mPos; + pos = ptr.getCellRef().getPosition(); ptr.getRefData().setCustomData(NULL); } @@ -844,7 +848,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); const ESM::InventoryList& list = ref->mBase->mInventory; MWWorld::ContainerStore& store = getContainerStore(ptr); - store.restock(list, ptr, ptr.getCellRef().mRefID, ptr.getCellRef().mFaction); + store.restock(list, ptr, ptr.getCellRef().getRefId(), ptr.getCellRef().getFaction()); } const ESM::GameSetting* Creature::fMinWalkSpeedCreature; diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index fea30735c6..7843048044 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -73,8 +73,8 @@ namespace MWClass const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); MWWorld::ManualRef ref(store, id); - ref.getPtr().getCellRef().mPos = ptr.getCellRef().mPos; - MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(), ptr.getCell() , ptr.getCellRef().mPos); + ref.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition()); + MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(), ptr.getCell() , ptr.getCellRef().getPosition()); customData.mSpawnActorId = placed.getClass().getCreatureStats(placed).getActorId(); customData.mSpawn = false; } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 27903c4103..12645c9f39 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -83,8 +83,8 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ref->mRef.mTeleport && !ref->mRef.mDestCell.empty()) // TODO doors that lead to exteriors - return ref->mRef.mDestCell; + if (ptr.getCellRef().getTeleport() && !ptr.getCellRef().getDestCell().empty()) // TODO doors that lead to exteriors + return ptr.getCellRef().getDestCell(); return ref->mBase->mName; } @@ -101,16 +101,16 @@ namespace MWClass MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); - bool needKey = ptr.getCellRef().mLockLevel > 0; + bool needKey = ptr.getCellRef().getLockLevel() > 0; bool hasKey = false; std::string keyName; // make key id lowercase - std::string keyId = ptr.getCellRef().mKey; + std::string keyId = ptr.getCellRef().getKey(); Misc::StringUtils::toLower(keyId); for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { - std::string refId = it->getCellRef().mRefID; + std::string refId = it->getCellRef().getRefId(); Misc::StringUtils::toLower(refId); if (refId == keyId) { @@ -125,22 +125,22 @@ namespace MWClass MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}"); unlock(ptr); //Call the function here. because that makes sense. // using a key disarms the trap - ptr.getCellRef().mTrap = ""; + ptr.getCellRef().getTrap() = ""; } if (!needKey || hasKey) { - if(!ptr.getCellRef().mTrap.empty()) + if(!ptr.getCellRef().getTrap().empty()) { // Trap activation - boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().mTrap, ptr)); + boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); action->setSound(trapActivationSound); return action; } - if (ref->mRef.mTeleport) + if (ptr.getCellRef().getTeleport()) { - boost::shared_ptr action(new MWWorld::ActionTeleport (ref->mRef.mDestCell, ref->mRef.mDoorDest)); + boost::shared_ptr action(new MWWorld::ActionTeleport (ptr.getCellRef().getDestCell(), ptr.getCellRef().getDoorDest())); action->setSound(openSound); @@ -191,14 +191,14 @@ namespace MWClass void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const { if(lockLevel!=0) - ptr.getCellRef().mLockLevel = abs(lockLevel); //Changes lock to locklevel, in positive + ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, in positive else - ptr.getCellRef().mLockLevel = abs(ptr.getCellRef().mLockLevel); //No locklevel given, just flip the origional one + ptr.getCellRef().setLockLevel(abs(ptr.getCellRef().getLockLevel())); //No locklevel given, just flip the origional one } void Door::unlock (const MWWorld::Ptr& ptr) const { - ptr.getCellRef().mLockLevel = -abs(ptr.getCellRef().mLockLevel); //Makes lockLevel negative + ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative } std::string Door::getScript (const MWWorld::Ptr& ptr) const @@ -234,17 +234,17 @@ namespace MWClass std::string text; - if (ref->mRef.mTeleport) + if (ptr.getCellRef().getTeleport()) { text += "\n#{sTo}"; text += "\n" + getDestination(*ref); } - if (ref->mRef.mLockLevel > 0) - text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ref->mRef.mLockLevel); - else if (ref->mRef.mLockLevel < 0) + if (ptr.getCellRef().getLockLevel() > 0) + text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); + else if (ptr.getCellRef().getLockLevel() < 0) text += "\n#{sUnlocked}"; - if (ref->mRef.mTrap != "") + if (ptr.getCellRef().getTrap() != "") text += "\n#{sTrapped}"; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) @@ -260,16 +260,16 @@ namespace MWClass const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); std::string dest; - if (door.mRef.mDestCell != "") + if (door.mRef.getDestCell() != "") { // door leads to an interior, use interior name as tooltip - dest = door.mRef.mDestCell; + dest = door.mRef.getDestCell(); } else { // door leads to exterior, use cell name (if any), otherwise translated region name int x,y; - MWBase::Environment::get().getWorld()->positionToIndex (door.mRef.mDoorDest.pos[0], door.mRef.mDoorDest.pos[1], x, y); + MWBase::Environment::get().getWorld()->positionToIndex (door.mRef.getDoorDest().pos[0], door.mRef.getDoorDest().pos[1], x, y); const ESM::Cell* cell = store.get().find(x,y); if (cell->mName != "") dest = cell->mName; diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index ebe41bb537..60c0efeb86 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -147,8 +147,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 1b28a84625..fd45ec8592 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -187,8 +187,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 60ffec7b9b..19381a3fd5 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -86,10 +86,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ptr.getCellRef().mCharge == -1) - return ref->mBase->mData.mValue; - else - return ref->mBase->mData.mValue * (static_cast(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); + return ref->mBase->mData.mValue * (static_cast(getItemHealth(ptr)) / getItemMaxHealth(ptr)); } void Lockpick::registerSelf() @@ -136,7 +133,7 @@ namespace MWClass std::string text; - int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses; + int remainingUses = getItemHealth(ptr); text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses); text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality); @@ -144,8 +141,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index e568bf8697..1044fb01d4 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -28,11 +28,11 @@ namespace { bool isGold (const MWWorld::Ptr& ptr) { - return Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_001") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_005") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_010") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_025") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_100"); + return Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_001") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_005") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_010") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_025") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_100"); } } @@ -94,12 +94,12 @@ namespace MWClass ptr.get(); int value = ref->mBase->mData.mValue; - if (ptr.getCellRef().mGoldValue > 1 && ptr.getRefData().getCount() == 1) - value = ptr.getCellRef().mGoldValue; + if (ptr.getCellRef().getGoldValue() > 1 && ptr.getRefData().getCount() == 1) + value = ptr.getCellRef().getGoldValue(); - if (ptr.getCellRef().mSoul != "") + if (ptr.getCellRef().getSoul() != "") { - const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(ref->mRef.mSoul); + const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(ref->mRef.getSoul()); value *= creature->mData.mSoul; } @@ -167,9 +167,9 @@ namespace MWClass info.caption = ref->mBase->mName + countString; info.icon = ref->mBase->mIcon; - if (ref->mRef.mSoul != "") + if (ref->mRef.getSoul() != "") { - const ESM::Creature *creature = store.get().find(ref->mRef.mSoul); + const ESM::Creature *creature = store.get().find(ref->mRef.getSoul()); info.caption += " (" + creature->mName + ")"; } @@ -182,8 +182,8 @@ namespace MWClass } if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } @@ -219,7 +219,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = newRef.getPtr().get(); newPtr = MWWorld::Ptr(&cell.get().insert(*ref), &cell); - newPtr.getCellRef().mGoldValue = goldAmount; + newPtr.getCellRef().setGoldValue(goldAmount); newPtr.getRefData().setCount(1); } else { MWWorld::LiveCellRef *ref = @@ -231,7 +231,7 @@ namespace MWClass boost::shared_ptr Miscellaneous::use (const MWWorld::Ptr& ptr) const { - if (ptr.getCellRef().mSoul == "") + if (ptr.getCellRef().getSoul().empty()) return boost::shared_ptr(new MWWorld::NullAction()); else return boost::shared_ptr(new MWWorld::ActionSoulgem(ptr)); @@ -242,12 +242,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = item.get(); - return !ref->mBase->mData.mIsKey && (npcServices & ESM::NPC::Misc) - && !Misc::StringUtils::ciEqual(item.getCellRef().mRefID, "gold_001") - && !Misc::StringUtils::ciEqual(item.getCellRef().mRefID, "gold_005") - && !Misc::StringUtils::ciEqual(item.getCellRef().mRefID, "gold_010") - && !Misc::StringUtils::ciEqual(item.getCellRef().mRefID, "gold_025") - && !Misc::StringUtils::ciEqual(item.getCellRef().mRefID, "gold_100"); + return !ref->mBase->mData.mIsKey && (npcServices & ESM::NPC::Misc) && !isGold(item); } float Miscellaneous::getWeight(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index bca7708eab..7405292b4b 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -526,20 +526,24 @@ namespace MWClass (stats.getAttribute(ESM::Attribute::Strength).getModified() * fDamageStrengthMult->getFloat() * 0.1); if(weaphashealth) { - int weapmaxhealth = weapon.get()->mBase->mData.mHealth; - if(weapon.getCellRef().mCharge == -1) - weapon.getCellRef().mCharge = weapmaxhealth; - damage *= float(weapon.getCellRef().mCharge) / weapmaxhealth; + int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon); + int weaphealth = weapon.getClass().getItemHealth(weapon); + + damage *= float(weaphealth) / weapmaxhealth; + + if (!MWBase::Environment::get().getWorld()->getGodModeState()) + { + // Reduce weapon charge by at least one, but cap at 0 + weaphealth -= std::min(std::max(1, + (int)(damage * gmst.find("fWeaponDamageMult")->getFloat())), weaphealth); + + weapon.getCellRef().setCharge(weaphealth); + } + + // Weapon broken? unequip it + if (weaphealth == 0) + weapon = *inv.unequipItem(weapon, ptr); } - - if (!MWBase::Environment::get().getWorld()->getGodModeState()) - weapon.getCellRef().mCharge -= std::min(std::max(1, - (int)(damage * gmst.find("fWeaponDamageMult")->getFloat())), weapon.getCellRef().mCharge); - - // Weapon broken? unequip it - if (weapon.getCellRef().mCharge == 0) - weapon = *inv.unequipItem(weapon, ptr); - } healthdmg = true; } @@ -705,14 +709,13 @@ namespace MWClass MWWorld::Ptr armor = ((armorslot != inv.end()) ? *armorslot : MWWorld::Ptr()); if(!armor.isEmpty() && armor.getTypeName() == typeid(ESM::Armor).name()) { - ESM::CellRef &armorref = armor.getCellRef(); - if(armorref.mCharge == -1) - armorref.mCharge = armor.get()->mBase->mData.mHealth; - armorref.mCharge -= std::min(std::max(1, (int)damagediff), - armorref.mCharge); + int armorhealth = armor.getClass().getItemHealth(armor); + armorhealth -= std::min(std::max(1, (int)damagediff), + armorhealth); + armor.getCellRef().setCharge(armorhealth); // Armor broken? unequip it - if (armorref.mCharge == 0) + if (armorhealth == 0) inv.unequipItem(armor, ptr); if (ptr.getRefData().getHandle() == "player") @@ -1316,14 +1319,14 @@ namespace MWClass { // Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell. // This also means we cannot respawn dynamically placed references with no content file connection. - if (ptr.getCellRef().mRefNum.mContentFile != -1) + if (ptr.getCellRef().getRefNum().mContentFile != -1) { if (ptr.getRefData().getCount() == 0) ptr.getRefData().setCount(1); // Reset to original position ESM::Position& pos = ptr.getRefData().getPosition(); - pos = ptr.getCellRef().mPos; + pos = ptr.getCellRef().getPosition(); ptr.getRefData().setCustomData(NULL); } @@ -1335,7 +1338,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); const ESM::InventoryList& list = ref->mBase->mInventory; MWWorld::ContainerStore& store = getContainerStore(ptr); - store.restock(list, ptr, ptr.getCellRef().mRefID, ptr.getCellRef().mFaction); + store.restock(list, ptr, ptr.getCellRef().getRefId(), ptr.getCellRef().getFaction()); } const ESM::GameSetting *Npc::fMinWalkSpeed; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index f9d7947a66..7440617c25 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -151,8 +151,8 @@ namespace MWClass info.isPotion = true; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index d376270cb3..5d076a3c5e 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -85,10 +85,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ptr.getCellRef().mCharge == -1) - return ref->mBase->mData.mValue; - else - return ref->mBase->mData.mValue * (static_cast(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); + return ref->mBase->mData.mValue * (static_cast(getItemHealth(ptr)) / getItemMaxHealth(ptr)); } void Probe::registerSelf() @@ -135,7 +132,7 @@ namespace MWClass std::string text; - int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses; + int remainingUses = getItemHealth(ptr); text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses); text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality); @@ -143,8 +140,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index af79a96915..9b528a4fce 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -76,10 +76,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ptr.getCellRef().mCharge == -1) - return ref->mBase->mData.mValue; - else - return ref->mBase->mData.mValue * (static_cast(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); + return ref->mBase->mData.mValue * (static_cast(getItemHealth(ptr)) / getItemMaxHealth(ptr)); } void Repair::registerSelf() @@ -139,7 +136,7 @@ namespace MWClass std::string text; - int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses; + int remainingUses = getItemHealth(ptr); text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses); text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality); @@ -147,8 +144,8 @@ namespace MWClass text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}"); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 5edf22b008..26618c021c 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -154,10 +154,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - if (ptr.getCellRef().mCharge == -1) - return ref->mBase->mData.mValue; - else - return ref->mBase->mData.mValue * (static_cast(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr)); + return ref->mBase->mData.mValue * (static_cast(getItemHealth(ptr)) / getItemMaxHealth(ptr)); } void Weapon::registerSelf() @@ -340,7 +337,7 @@ namespace MWClass if (ref->mBase->mData.mType < 11) // thrown weapons and arrows/bolts don't have health, only quantity { - int remainingHealth = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mHealth; + int remainingHealth = getItemHealth(ptr); text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/" + MWGui::ToolTips::toString(ref->mBase->mData.mHealth); } @@ -351,11 +348,11 @@ namespace MWClass info.enchant = ref->mBase->mEnchant; if (!info.enchant.empty()) - info.remainingEnchantCharge = ptr.getCellRef().mEnchantmentCharge; + info.remainingEnchantCharge = ptr.getCellRef().getEnchantmentCharge(); if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { - text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner"); - text += MWGui::ToolTips::getMiscString(ref->mRef.mFaction, "Faction"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getOwner(), "Owner"); + text += MWGui::ToolTips::getMiscString(ptr.getCellRef().getFaction(), "Faction"); text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); } @@ -388,7 +385,7 @@ namespace MWClass std::pair Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const { - if (ptr.getCellRef().mCharge == 0) + if (ptr.getCellRef().getCharge() == 0) return std::make_pair(0, "#{sInventoryMessage1}"); std::pair, bool> slots_ = ptr.getClass().getEquipmentSlots(ptr); diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 237d145a2e..811f93b486 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -413,7 +413,7 @@ namespace MWGui } else { - setTitle("#{sConsoleTitle} (" + object.getCellRef().mRefID + ")"); + setTitle("#{sConsoleTitle} (" + object.getCellRef().getRefId() + ")"); mPtr = object; } // User clicked on an object. Restore focus to the console command line. diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index b303848df5..29fe6f82d5 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -306,7 +306,7 @@ namespace MWGui for (int i=0; i<2; ++i) { MWWorld::Ptr item = (i == 0) ? mEnchanting.getOldItem() : mEnchanting.getGem(); - if (Misc::StringUtils::ciEqual(item.getCellRef().mOwner, mPtr.getCellRef().mRefID)) + if (Misc::StringUtils::ciEqual(item.getCellRef().getOwner(), mPtr.getCellRef().getRefId())) { std::string msg = MWBase::Environment::get().getWorld()->getStore().get().find("sNotifyMessage49")->getString(); if (msg.find("%s") != std::string::npos) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 103c48ca14..ede5750a56 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -40,7 +40,7 @@ namespace MWGui else dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count); if (setNewOwner) - dropped.getCellRef().mOwner = ""; + dropped.getCellRef().setOwner(""); return dropped; } diff --git a/apps/openmw/mwgui/inventoryitemmodel.cpp b/apps/openmw/mwgui/inventoryitemmodel.cpp index e1bc9d4daa..ad1a4e9537 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.cpp +++ b/apps/openmw/mwgui/inventoryitemmodel.cpp @@ -67,7 +67,7 @@ MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack &item, size_t count, I if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead() // Make sure that the item is actually owned by the dead actor // Prevents a potential exploit for resetting the owner of any item, by placing the item in a corpse - && Misc::StringUtils::ciEqual(item.mBase.getCellRef().mOwner, mActor.getCellRef().mRefID)) + && Misc::StringUtils::ciEqual(item.mBase.getCellRef().getOwner(), mActor.getCellRef().getRefId())) setNewOwner = true; MWWorld::Ptr ret = otherModel->copyItem(item, count, setNewOwner); @@ -87,7 +87,7 @@ void InventoryItemModel::update() // NOTE: Don't show WerewolfRobe objects in the inventory, or allow them to be taken. // Vanilla likely uses a hack like this since there's no other way to prevent it from // being shown or taken. - if(item.getCellRef().mRefID == "werewolfrobe") + if(item.getCellRef().getRefId() == "werewolfrobe") continue; ItemStack newItem (item, this, item.getRefData().getCount()); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 788f90f504..b1e8052d8c 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -168,8 +168,8 @@ namespace MWGui int count = item.mCount; // Bound items may not be moved - if (item.mBase.getCellRef().mRefID.size() > 6 - && item.mBase.getCellRef().mRefID.substr(0,6) == "bound_") + if (item.mBase.getCellRef().getRefId().size() > 6 + && item.mBase.getCellRef().getRefId().substr(0,6) == "bound_") { MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog12}"); @@ -454,7 +454,7 @@ namespace MWGui // NOTE: Don't allow users to select WerewolfRobe objects in the inventory. Vanilla // likely uses a hack like this since there's no other way to prevent it from being // taken. - if(item.getCellRef().mRefID == "werewolfrobe") + if(item.getCellRef().getRefId() == "werewolfrobe") return MWWorld::Ptr(); return item; } diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 83527a8845..50e7644fb9 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -47,7 +47,7 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor) if (iter->getClass().hasItemHealth(*iter)) { int maxDurability = iter->getClass().getItemMaxHealth(*iter); - int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge; + int durability = iter->getClass().getItemHealth(*iter); if (maxDurability == durability) continue; @@ -114,7 +114,7 @@ void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender) { // repair MWWorld::Ptr item = *sender->getUserData(); - item.getCellRef().mCharge = item.getClass().getItemMaxHealth(item); + item.getCellRef().setCharge(item.getClass().getItemMaxHealth(item)); MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1); diff --git a/apps/openmw/mwgui/pickpocketitemmodel.cpp b/apps/openmw/mwgui/pickpocketitemmodel.cpp index 0196bf02d3..230282f152 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.cpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.cpp @@ -42,8 +42,8 @@ namespace MWGui const ItemStack& item = mSourceModel->getItem(i); // Bound items may not be stolen - if (item.mBase.getCellRef().mRefID.size() > 6 - && item.mBase.getCellRef().mRefID.substr(0,6) == "bound_") + if (item.mBase.getCellRef().getRefId().size() > 6 + && item.mBase.getCellRef().getRefId().substr(0,6) == "bound_") { continue; } diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 5df2b12b8d..90abbb1450 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -274,11 +274,11 @@ namespace MWGui if (item.getRefData ().getCount() < 1) { // Try searching for a compatible replacement - std::string id = item.getCellRef().mRefID; + std::string id = item.getCellRef().getRefId(); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { - if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, id)) + if (Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), id)) { item = *it; button->getChildAt(0)->setUserData(item); @@ -408,7 +408,7 @@ namespace MWGui case Type_MagicItem: { MWWorld::Ptr item = *button->getChildAt(0)->getUserData(); - key.mId = item.getCellRef().mRefID; + key.mId = item.getCellRef().getRefId(); break; } case Type_Magic: @@ -458,11 +458,12 @@ namespace MWGui MWWorld::Ptr item; for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { - if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, id)) + if (Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), id)) { if (item.isEmpty() || // Prefer the stack with the lowest remaining uses - (it->getCellRef().mCharge != -1 && (item.getCellRef().mCharge == -1 || it->getCellRef().mCharge < item.getCellRef().mCharge) )) + !item.getClass().hasItemHealth(*it) || + it->getClass().getItemHealth(*it) < item.getClass().getItemHealth(item)) { item = *it; } diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index 313650bb64..5c4f3eb5a5 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -56,7 +56,7 @@ void Recharge::updateView() { MWWorld::Ptr gem = *mGemIcon->getUserData(); - std::string soul = gem.getCellRef().mSoul; + std::string soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); mChargeLabel->setCaptionWithReplacing("#{sCharges} " + boost::lexical_cast(creature->mData.mSoul)); @@ -93,8 +93,8 @@ void Recharge::updateView() if (enchantmentName.empty()) continue; const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find(enchantmentName); - if (iter->getCellRef().mEnchantmentCharge >= enchantment->mData.mCharge - || iter->getCellRef().mEnchantmentCharge == -1) + if (iter->getCellRef().getEnchantmentCharge() >= enchantment->mData.mCharge + || iter->getCellRef().getEnchantmentCharge() == -1) continue; MyGUI::TextBox* text = mView->createWidget ( @@ -118,7 +118,7 @@ void Recharge::updateView() Widgets::MWDynamicStatPtr chargeWidget = mView->createWidget ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default); - chargeWidget->setValue(iter->getCellRef().mEnchantmentCharge, enchantment->mData.mCharge); + chargeWidget->setValue(iter->getCellRef().getEnchantmentCharge(), enchantment->mData.mCharge); chargeWidget->setNeedMouseFocus(false); currentY += 32 + 4; @@ -159,15 +159,15 @@ void Recharge::onItemClicked(MyGUI::Widget *sender) int roll = std::rand()/ (static_cast (RAND_MAX) + 1) * 100; // [0, 99] if (roll < x) { - std::string soul = gem.getCellRef().mSoul; + std::string soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); float restored = creature->mData.mSoul * (roll / x); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find( item.getClass().getEnchantment(item)); - item.getCellRef().mEnchantmentCharge = - std::min(item.getCellRef().mEnchantmentCharge + restored, static_cast(enchantment->mData.mCharge)); + item.getCellRef().setEnchantmentCharge( + std::min(item.getCellRef().getEnchantmentCharge() + restored, static_cast(enchantment->mData.mCharge))); player.getClass().skillUsageSucceeded (player, ESM::Skill::Enchant, 0); } diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index a3df2dfbea..1ae02599ee 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -56,7 +56,7 @@ void Repair::updateRepairView() MWWorld::LiveCellRef *ref = mRepair.getTool().get(); - int uses = (mRepair.getTool().getCellRef().mCharge != -1) ? mRepair.getTool().getCellRef().mCharge : ref->mBase->mData.mUses; + int uses = mRepair.getTool().getClass().getItemHealth(mRepair.getTool()); float quality = ref->mBase->mData.mQuality; @@ -98,7 +98,7 @@ void Repair::updateRepairView() if (iter->getClass().hasItemHealth(*iter)) { int maxDurability = iter->getClass().getItemMaxHealth(*iter); - int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge; + int durability = iter->getClass().getItemHealth(*iter); if (maxDurability == durability) continue; diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 475f73a072..b8dcbcbbb1 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -114,7 +114,7 @@ namespace MWGui if ((mFilter & Filter_OnlyEnchanted) && !(item.mFlags & ItemStack::Flag_Enchanted)) return false; if ((mFilter & Filter_OnlyChargedSoulstones) && (base.getTypeName() != typeid(ESM::Miscellaneous).name() - || base.getCellRef().mSoul == "")) + || base.getCellRef().getSoul() == "")) return false; if ((mFilter & Filter_OnlyEnchantable) && (item.mFlags & ItemStack::Flag_Enchanted || (base.getTypeName() != typeid(ESM::Armor).name() diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 16e4741432..fb5a80cc7d 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -238,7 +238,7 @@ namespace MWGui int castCost = std::max(1.f, enchantCost - (enchantCost / 100) * (eSkill - 10)); std::string cost = boost::lexical_cast(castCost); - int currentCharge = int(item.getCellRef().mEnchantmentCharge); + int currentCharge = int(item.getCellRef().getEnchantmentCharge()); if (currentCharge == -1) currentCharge = enchant->mData.mCharge; std::string charge = boost::lexical_cast(currentCharge); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index dd29f40ce4..aeb79a9381 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -97,7 +97,7 @@ namespace MWGui setCoord(0, 0, 300, 300); mDynamicToolTipBox->setVisible(true); ToolTipInfo info; - info.caption=mFocusObject.getCellRef().mRefID; + info.caption=mFocusObject.getCellRef().getRefId(); info.icon=""; tooltipSize = createToolTip(info); } diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index 18b0d5ae3f..fe43eb5483 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -148,14 +148,14 @@ namespace MWGui if(!mMerchant.isEmpty()) { MWWorld::Ptr base = item.mBase; - if(Misc::StringUtils::ciEqual(base.getCellRef().mRefID, MWWorld::ContainerStore::sGoldId)) + if(Misc::StringUtils::ciEqual(base.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) continue; if(!base.getClass().canSell(base, services)) continue; // Bound items may not be bought - if (item.mBase.getCellRef().mRefID.size() > 6 - && item.mBase.getCellRef().mRefID.substr(0,6) == "bound_") + if (item.mBase.getCellRef().getRefId().size() > 6 + && item.mBase.getCellRef().getRefId().substr(0,6) == "bound_") { continue; } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 4baa48e7cf..558e955f0d 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -277,7 +277,7 @@ namespace MWGui // check if the player is attempting to sell back an item stolen from this actor for (std::vector::iterator it = merchantBought.begin(); it != merchantBought.end(); ++it) { - if (Misc::StringUtils::ciEqual(it->mBase.getCellRef().mOwner, mPtr.getCellRef().mRefID)) + if (Misc::StringUtils::ciEqual(it->mBase.getCellRef().getOwner(), mPtr.getCellRef().getRefId())) { std::string msg = gmst.find("sNotifyMessage49")->getString(); if (msg.find("%s") != std::string::npos) diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 40fcc35300..a42dca79e5 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1029,16 +1029,16 @@ namespace MWGui const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get() .find(item.getClass().getEnchantment(item)); - int chargePercent = (item.getCellRef().mEnchantmentCharge == -1) ? 100 - : (item.getCellRef().mEnchantmentCharge / static_cast(ench->mData.mCharge) * 100); + int chargePercent = (item.getCellRef().getEnchantmentCharge() == -1) ? 100 + : (item.getCellRef().getEnchantmentCharge() / static_cast(ench->mData.mCharge) * 100); mHud->setSelectedEnchantItem(item, chargePercent); mSpellWindow->setTitle(item.getClass().getName(item)); } void WindowManager::setSelectedWeapon(const MWWorld::Ptr& item) { - int durabilityPercent = (item.getCellRef().mCharge == -1) ? 100 - : (item.getCellRef().mCharge / static_cast(item.getClass().getItemMaxHealth(item)) * 100); + int durabilityPercent = + (item.getClass().getItemHealth(item) / static_cast(item.getClass().getItemMaxHealth(item)) * 100); mHud->setSelectedWeapon(item, durabilityPercent); mInventoryWindow->setTitle(item.getClass().getName(item)); } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 35667a23c4..9f141a951b 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -62,17 +62,17 @@ bool disintegrateSlot (MWWorld::Ptr ptr, int slot, float disintegrate) { if (!item->getClass().hasItemHealth(*item)) return false; - if (item->getCellRef().mCharge == -1) - item->getCellRef().mCharge = item->getClass().getItemMaxHealth(*item); + int charge = item->getClass().getItemHealth(*item); - if (item->getCellRef().mCharge == 0) + if (charge == 0) return false; - item->getCellRef().mCharge -= + charge -= std::min(disintegrate, - static_cast(item->getCellRef().mCharge)); + static_cast(charge)); + item->getCellRef().setCharge(charge); - if (item->getCellRef().mCharge == 0) + if (charge == 0) { // Will unequip the broken item and try to find a replacement if (ptr.getRefData().getHandle() != "player") @@ -147,13 +147,13 @@ namespace MWMechanics for (MWWorld::ContainerStoreIterator it = container.begin(MWWorld::ContainerStore::Type_Miscellaneous); it != container.end(); ++it) { - const std::string& id = it->getCellRef().mRefID; + const std::string& id = it->getCellRef().getRefId(); if (id.size() >= soulgemFilter.size() && id.substr(0,soulgemFilter.size()) == soulgemFilter) { float thisGemCapacity = it->get()->mBase->mData.mValue * fSoulgemMult; if (thisGemCapacity >= creatureSoulValue && thisGemCapacity < gemCapacity - && it->getCellRef().mSoul.empty()) + && it->getCellRef().getSoul().empty()) { gem = it; gemCapacity = thisGemCapacity; @@ -166,7 +166,7 @@ namespace MWMechanics // Set the soul on just one of the gems, not the whole stack gem->getContainerStore()->unstack(*gem, caster); - gem->getCellRef().mSoul = mCreature.getCellRef().mRefID; + gem->getCellRef().setSoul(mCreature.getCellRef().getRefId()); if (caster.getRefData().getHandle() == "player") MWBase::Environment::get().getWindowManager()->messageBox("#{sSoultrapSuccess}"); @@ -546,7 +546,7 @@ namespace MWMechanics { MWWorld::CellStore* store = ptr.getCell(); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), creatureID, 1); - ref.getPtr().getCellRef().mPos = ipos; + ref.getPtr().getCellRef().setPosition(ipos); MWMechanics::CreatureStats& summonedCreatureStats = ref.getPtr().getClass().getCreatureStats(ref.getPtr()); @@ -1142,7 +1142,7 @@ namespace MWMechanics if(!stats.isDead() && stats.getAiSequence().getTypeId() == AiPackage::TypeIdFollow) { MWMechanics::AiFollow* package = static_cast(stats.getAiSequence().getActivePackage()); - if(package->getFollowedActor() == actor.getCellRef().mRefID) + if(package->getFollowedActor() == actor.getCellRef().getRefId()) list.push_front(iter->first); } } diff --git a/apps/openmw/mwmechanics/aiavoiddoor.cpp b/apps/openmw/mwmechanics/aiavoiddoor.cpp index 5045225828..ea6f296cc8 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.cpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.cpp @@ -73,11 +73,6 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor,float duration return false; } -std::string MWMechanics::AiAvoidDoor::getAvoidedDoor() -{ - return mDoorPtr.getCellRef().mRefID; -} - MWMechanics::AiAvoidDoor *MWMechanics::AiAvoidDoor::clone() const { return new AiAvoidDoor(*this); diff --git a/apps/openmw/mwmechanics/aiavoiddoor.hpp b/apps/openmw/mwmechanics/aiavoiddoor.hpp index c1b3261981..d2a2e33a1f 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.hpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.hpp @@ -24,9 +24,6 @@ namespace MWMechanics virtual int getTypeId() const; - /// Returns the door being avoided - std::string getAvoidedDoor(); - private: float mDuration; MWWorld::Ptr mDoorPtr; diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 1027cc48a7..8ea9be3399 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -517,7 +517,7 @@ namespace MWMechanics { MWWorld::LiveCellRef& ref = *mDoorIter; float minSqr = 1.3*1.3*MIN_DIST_TO_DOOR_SQUARED; // for legibility - if(vActorPos.squaredDistance(Ogre::Vector3(ref.mRef.mPos.pos)) < minSqr && + if(vActorPos.squaredDistance(Ogre::Vector3(ref.mRef.getPosition().pos)) < minSqr && ref.mData.getLocalRotation().rot[2] < 0.4f) // even small opening { //std::cout<<"closed door id \""<execute(actor); mLastDoorChecked = door; } diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 5ffa7a547f..69c3c08f76 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -102,10 +102,11 @@ namespace MWMechanics if (roll < x) { // Reduce shield durability by incoming damage - if (shield->getCellRef().mCharge == -1) - shield->getCellRef().mCharge = shield->getClass().getItemMaxHealth(*shield); - shield->getCellRef().mCharge -= std::min(shield->getCellRef().mCharge, int(damage)); - if (!shield->getCellRef().mCharge) + int shieldhealth = shield->getClass().getItemHealth(*shield); + + shieldhealth -= std::min(shieldhealth, int(damage)); + shield->getCellRef().setCharge(shieldhealth); + if (shieldhealth == 0) inv.unequipItem(*shield, blocker); // Reduce blocker fatigue diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 9c5c9dbb9d..f3f6795db8 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -234,9 +234,9 @@ namespace MWMechanics const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); if(soulEmpty()) return 0; - if(mSoulGemPtr.getCellRef().mSoul=="") + if(mSoulGemPtr.getCellRef().getSoul()=="") return 0; - const ESM::Creature* soul = store.get().find(mSoulGemPtr.getCellRef().mSoul); + const ESM::Creature* soul = store.get().find(mSoulGemPtr.getCellRef().getSoul()); return soul->mData.mSoul; } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index d25be1e13f..0d5bae42bd 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -24,10 +24,10 @@ namespace /// @return is \a ptr allowed to take/use \a item or is it a crime? bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, MWWorld::Ptr& victim) { - const std::string& owner = item.getCellRef().mOwner; + const std::string& owner = item.getCellRef().getOwner(); bool isOwned = !owner.empty() && owner != "player"; - const std::string& faction = item.getCellRef().mFaction; + const std::string& faction = item.getCellRef().getFaction(); bool isFactionOwned = false; if (!faction.empty() && ptr.getClass().isNpc()) { @@ -36,8 +36,8 @@ namespace isFactionOwned = true; } - if (!item.getCellRef().mOwner.empty()) - victim = MWBase::Environment::get().getWorld()->searchPtr(item.getCellRef().mOwner, true); + if (!item.getCellRef().getOwner().empty()) + victim = MWBase::Environment::get().getWorld()->searchPtr(item.getCellRef().getOwner(), true); return (!isOwned && !isFactionOwned); } diff --git a/apps/openmw/mwmechanics/obstacle.cpp b/apps/openmw/mwmechanics/obstacle.cpp index fc781e6377..55ebfeab54 100644 --- a/apps/openmw/mwmechanics/obstacle.cpp +++ b/apps/openmw/mwmechanics/obstacle.cpp @@ -50,7 +50,7 @@ namespace MWMechanics for (; it != refList.end(); ++it) { MWWorld::LiveCellRef& ref = *it; - if(pos.squaredDistance(Ogre::Vector3(ref.mRef.mPos.pos)) < minSqr) + if(pos.squaredDistance(Ogre::Vector3(ref.mData.getPosition().pos)) < minSqr) if((closed && ref.mData.getLocalRotation().rot[2] == 0) || (!closed && ref.mData.getLocalRotation().rot[2] >= 1)) { diff --git a/apps/openmw/mwmechanics/repair.cpp b/apps/openmw/mwmechanics/repair.cpp index dc8b567a9b..9f2c851cf8 100644 --- a/apps/openmw/mwmechanics/repair.cpp +++ b/apps/openmw/mwmechanics/repair.cpp @@ -28,8 +28,8 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) player.getClass().getContainerStore(player).unstack(mTool, player); // reduce number of uses left - int uses = (mTool.getCellRef().mCharge != -1) ? mTool.getCellRef().mCharge : ref->mBase->mData.mUses; - mTool.getCellRef().mCharge = uses-1; + int uses = mTool.getClass().getItemHealth(mTool); + mTool.getCellRef().setCharge(uses-1); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); @@ -53,9 +53,9 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) y = std::max(1, y); // repair by 'y' points - itemToRepair.getCellRef().mCharge += y; - itemToRepair.getCellRef().mCharge = std::min(itemToRepair.getCellRef().mCharge, - itemToRepair.getClass().getItemMaxHealth(itemToRepair)); + int charge = itemToRepair.getClass().getItemHealth(itemToRepair); + charge = std::min(charge + y, itemToRepair.getClass().getItemMaxHealth(itemToRepair)); + itemToRepair.getCellRef().setCharge(charge); // set the OnPCRepair variable on the item's script std::string script = itemToRepair.getClass().getScript(itemToRepair); @@ -75,7 +75,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) } // tool used up? - if (mTool.getCellRef().mCharge == 0) + if (mTool.getCellRef().getCharge() == 0) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); @@ -91,7 +91,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair) for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { - if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, mTool.getCellRef().mRefID)) + if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), mTool.getCellRef().getRefId())) { mTool = *iter; break; diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index bb2e942238..4a049d60f8 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -29,10 +29,10 @@ namespace MWMechanics void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick, std::string& resultMessage, std::string& resultSound) { - if (!(lock.getCellRef().mLockLevel > 0)) //If it's unlocked back out immediately + if (!(lock.getCellRef().getLockLevel() > 0)) //If it's unlocked back out immediately return; - int lockStrength = lock.getCellRef().mLockLevel; + int lockStrength = lock.getCellRef().getLockLevel(); float pickQuality = lockpick.get()->mBase->mData.mQuality; @@ -60,22 +60,22 @@ namespace MWMechanics resultMessage = "#{sLockFail}"; } - if (lockpick.getCellRef().mCharge == -1) - lockpick.getCellRef().mCharge = lockpick.get()->mBase->mData.mUses; - --lockpick.getCellRef().mCharge; - if (!lockpick.getCellRef().mCharge) + int uses = lockpick.getClass().getItemHealth(lockpick); + --uses; + lockpick.getCellRef().setCharge(uses); + if (!uses) lockpick.getContainerStore()->remove(lockpick, 1, mActor); } void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe, std::string& resultMessage, std::string& resultSound) { - if (trap.getCellRef().mTrap == "") + if (trap.getCellRef().getTrap() == "") return; float probeQuality = probe.get()->mBase->mData.mQuality; - const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get().find(trap.getCellRef().mTrap); + const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get().find(trap.getCellRef().getTrap()); float trapSpellPoints = trapSpell->mData.mCost; float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get().find("fTrapCostMult")->getFloat(); @@ -93,7 +93,7 @@ namespace MWMechanics int roll = static_cast (std::rand()) / RAND_MAX * 100; if (roll <= x) { - trap.getCellRef().mTrap = ""; + trap.getCellRef().setTrap(""); resultSound = "Disarm Trap"; resultMessage = "#{sTrapSuccess}"; @@ -103,10 +103,10 @@ namespace MWMechanics resultMessage = "#{sTrapFail}"; } - if (probe.getCellRef().mCharge == -1) - probe.getCellRef().mCharge = probe.get()->mBase->mData.mUses; - --probe.getCellRef().mCharge; - if (!probe.getCellRef().mCharge) + int uses = probe.getClass().getItemHealth(probe); + --uses; + probe.getCellRef().setCharge(uses); + if (!uses) probe.getContainerStore()->remove(probe, 1, mActor); } diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 91a81c74be..c996e90d6f 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -470,21 +470,21 @@ namespace MWMechanics { if (effectId == ESM::MagicEffect::Lock) { - if (target.getCellRef().mLockLevel < magnitude) //If the door is not already locked to a higher value, lock it to spell magnitude - target.getCellRef().mLockLevel = magnitude; + if (target.getCellRef().getLockLevel() < magnitude) //If the door is not already locked to a higher value, lock it to spell magnitude + target.getCellRef().setLockLevel(magnitude); } else if (effectId == ESM::MagicEffect::Open) { - if (target.getCellRef().mLockLevel <= magnitude) + if (target.getCellRef().getLockLevel() <= magnitude) { - //Door not already unlocked - if (target.getCellRef().mLockLevel > 0) + if (target.getCellRef().getLockLevel() > 0) { + //Door not already unlocked MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock", 1.f, 1.f); if (!caster.isEmpty() && caster.getClass().isActor()) MWBase::Environment::get().getMechanicsManager()->objectOpened(caster, target); } - target.getCellRef().mLockLevel = -abs(target.getCellRef().mLockLevel); //unlocks the door + target.getCellRef().setLockLevel(-abs(target.getCellRef().getLockLevel())); //unlocks the door } else MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock Fail", 1.f, 1.f); @@ -588,7 +588,7 @@ namespace MWMechanics throw std::runtime_error("can't cast an item without an enchantment"); mSourceName = item.getClass().getName(item); - mId = item.getCellRef().mRefID; + mId = item.getCellRef().getRefId(); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find(enchantmentName); @@ -601,10 +601,10 @@ namespace MWMechanics int eSkill = mCaster.getClass().getSkill(mCaster, ESM::Skill::Enchant); const int castCost = std::max(1.f, enchantCost - (enchantCost / 100) * (eSkill - 10)); - if (item.getCellRef().mEnchantmentCharge == -1) - item.getCellRef().mEnchantmentCharge = enchantment->mData.mCharge; + if (item.getCellRef().getEnchantmentCharge() == -1) + item.getCellRef().setEnchantmentCharge(enchantment->mData.mCharge); - if (item.getCellRef().mEnchantmentCharge < castCost) + if (item.getCellRef().getEnchantmentCharge() < castCost) { // TODO: Should there be a sound here? if (mCaster.getRefData().getHandle() == "player") @@ -612,7 +612,7 @@ namespace MWMechanics return false; } // Reduce charge - item.getCellRef().mEnchantmentCharge -= castCost; + item.getCellRef().setEnchantmentCharge(item.getCellRef().getEnchantmentCharge() - castCost); } if (enchantment->mData.mType == ESM::Enchantment::WhenUsed) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 820ba8acca..a9c9884d58 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -49,10 +49,10 @@ void Actors::insertBegin(const MWWorld::Ptr &ptr) Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getRefData().getPosition().pos; insert->setPosition(f[0], f[1], f[2]); - insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale); + insert->setScale(ptr.getCellRef().getScale(), ptr.getCellRef().getScale(), ptr.getCellRef().getScale()); // Convert MW rotation to a quaternion: - f = ptr.getCellRef().mPos.rot; + f = ptr.getCellRef().getPosition().rot; // Rotate around X axis Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3b8b91b0e4..9124e89b88 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -290,7 +290,7 @@ void Animation::addAnimSource(const std::string &model) mAccumRoot = mNonAccumRoot->getParent(); if(!mAccumRoot) { - std::cerr<< "Non-Accum root for "<getParent(); if(!mAccumRoot) { - std::cerr<< "Non-Accum root for "<setPosition(f[0], f[1], f[2]); - insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale); + insert->setScale(ptr.getCellRef().getScale(), ptr.getCellRef().getScale(), ptr.getCellRef().getScale()); // Convert MW rotation to a quaternion: - f = ptr.getCellRef().mPos.rot; + f = ptr.getCellRef().getPosition().rot; // Rotate around X axis Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X); diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 825d62efb5..a5bd121526 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -88,6 +88,11 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { + if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) + { + runtime.push (0); + return; + } bool interior = !MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->isExterior(); diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 6737d6a945..93711d036e 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -121,7 +121,7 @@ namespace MWScript std::string itemName; for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) - if (::Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item)) + if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) itemName = iter->getClass().getName(*iter); int numRemoved = store.remove(item, count, ptr); @@ -165,7 +165,7 @@ namespace MWScript MWWorld::ContainerStoreIterator it = invStore.begin(); for (; it != invStore.end(); ++it) { - if (::Misc::StringUtils::ciEqual(it->getCellRef().mRefID, item)) + if (::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) break; } if (it == invStore.end()) @@ -268,7 +268,7 @@ namespace MWScript for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ContainerStoreIterator it = invStore.getSlot (slot); - if (it != invStore.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().mRefID, item)) + if (it != invStore.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) { runtime.push(1); return; @@ -295,7 +295,7 @@ namespace MWScript it != invStore.end(); ++it) { - if (::Misc::StringUtils::ciEqual(it->getCellRef().mSoul, name)) + if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), name)) { runtime.push(1); return; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index b0d73253ff..fa17d96af3 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -131,7 +131,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - Interpreter::Type_Integer lockLevel = ptr.getCellRef().mLockLevel; + Interpreter::Type_Integer lockLevel = ptr.getCellRef().getLockLevel(); if(lockLevel==0) { //no lock level was ever set, set to 100 as default lockLevel = 100; } @@ -324,7 +324,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - runtime.push (ptr.getCellRef().mLockLevel > 0); + runtime.push (ptr.getCellRef().getLockLevel() > 0); } }; @@ -369,7 +369,7 @@ namespace MWScript store.get().find(creature); // This line throws an exception if it can't find the creature MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add(gem, 1, ptr); - item.getCellRef().mSoul = creature; + item.getCellRef().setSoul(creature); } }; @@ -392,7 +392,7 @@ namespace MWScript MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { - if (::Misc::StringUtils::ciEqual(it->getCellRef().mSoul, soul)) + if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), soul)) { store.remove(*it, 1, ptr); return; @@ -430,7 +430,7 @@ namespace MWScript int toRemove = amount; for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { - if (::Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item)) + if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) { int removed = store.remove(*iter, toRemove, ptr); MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, removed); @@ -462,7 +462,7 @@ namespace MWScript for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { - if (::Misc::StringUtils::ciEqual(iter->getCellRef().mSoul, soul)) + if (::Misc::StringUtils::ciEqual(iter->getCellRef().getSoul(), soul)) { MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, 1); store.remove(*iter, 1, ptr); @@ -659,10 +659,10 @@ namespace MWScript const std::string script = ptr.getClass().getScript(ptr); if(script.empty()) - str<< ptr.getCellRef().mRefID<<" ("<getLocals(script); diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index fb27e73f44..a944a31b8d 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -47,7 +47,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { MWWorld::Ptr ptr = R()(runtime); - runtime.push(ptr.getCellRef().mScale); + runtime.push(ptr.getCellRef().getScale()); } }; @@ -64,7 +64,7 @@ namespace MWScript runtime.pop(); // add the parameter to the object's scale. - MWBase::Environment::get().getWorld()->scaleObject(ptr,ptr.getCellRef().mScale + scale); + MWBase::Environment::get().getWorld()->scaleObject(ptr,ptr.getCellRef().getScale() + scale); } }; @@ -117,15 +117,15 @@ namespace MWScript if (axis == "x") { - runtime.push(Ogre::Radian(ptr.getCellRef().mPos.rot[0]).valueDegrees()); + runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[0]).valueDegrees()); } else if (axis == "y") { - runtime.push(Ogre::Radian(ptr.getCellRef().mPos.rot[1]).valueDegrees()); + runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[1]).valueDegrees()); } else if (axis == "z") { - runtime.push(Ogre::Radian(ptr.getCellRef().mPos.rot[2]).valueDegrees()); + runtime.push(Ogre::Radian(ptr.getCellRef().getPosition().rot[2]).valueDegrees()); } else throw std::runtime_error ("invalid rotation axis: " + axis); @@ -247,15 +247,15 @@ namespace MWScript if(axis == "x") { - runtime.push(ptr.getCellRef().mPos.pos[0]); + runtime.push(ptr.getCellRef().getPosition().pos[0]); } else if(axis == "y") { - runtime.push(ptr.getCellRef().mPos.pos[1]); + runtime.push(ptr.getCellRef().getPosition().pos[1]); } else if(axis == "z") { - runtime.push(ptr.getCellRef().mPos.pos[2]); + runtime.push(ptr.getCellRef().getPosition().pos[2]); } else throw std::runtime_error ("invalid axis: " + axis); @@ -415,7 +415,7 @@ namespace MWScript pos.rot[0] = pos.rot[1] = 0; pos.rot[2] = zRot; MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(),itemID); - ref.getPtr().getCellRef().mPos = pos; + ref.getPtr().getCellRef().setPosition(pos); MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,pos); } else @@ -456,7 +456,7 @@ namespace MWScript pos.rot[0] = pos.rot[1] = 0; pos.rot[2] = zRot; MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(),itemID); - ref.getPtr().getCellRef().mPos = pos; + ref.getPtr().getCellRef().setPosition(pos); MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,pos); } else @@ -523,7 +523,7 @@ namespace MWScript // create item MWWorld::CellStore* store = actor.getCell(); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), itemID, count); - ref.getPtr().getCellRef().mPos = ipos; + ref.getPtr().getCellRef().setPosition(ipos); MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,ipos); } @@ -617,8 +617,8 @@ namespace MWScript ptr.getRefData().getLocalRotation().rot[1] = 0; ptr.getRefData().getLocalRotation().rot[2] = 0; MWBase::Environment::get().getWorld()->rotateObject(ptr, 0,0,0,true); - MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().mPos.pos[0], - ptr.getCellRef().mPos.pos[1], ptr.getCellRef().mPos.pos[2]); + MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().pos[0], + ptr.getCellRef().getPosition().pos[1], ptr.getCellRef().getPosition().pos[2]); } }; diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index bcefb0181b..1472afc087 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -11,7 +11,7 @@ namespace MWWorld cast.mHitPosition = Ogre::Vector3(actor.getRefData().getPosition().pos); cast.cast(mSpellId); - mTrapSource.getCellRef().mTrap = ""; + mTrapSource.getCellRef().setTrap(""); } } diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp new file mode 100644 index 0000000000..f16d8e3d17 --- /dev/null +++ b/apps/openmw/mwworld/cellref.cpp @@ -0,0 +1,185 @@ +#include "cellref.hpp" + +#include + +namespace MWWorld +{ + + ESM::RefNum CellRef::getRefNum() const + { + return mCellRef.mRefNum; + } + + std::string CellRef::getRefId() const + { + return mCellRef.mRefID; + } + + bool CellRef::getTeleport() const + { + return mCellRef.mTeleport; + } + + ESM::Position CellRef::getDoorDest() const + { + return mCellRef.mDoorDest; + } + + std::string CellRef::getDestCell() const + { + return mCellRef.mDestCell; + } + + float CellRef::getScale() const + { + return mCellRef.mScale; + } + + void CellRef::setScale(float scale) + { + if (scale != mCellRef.mScale) + { + mChanged = true; + mCellRef.mScale = scale; + } + } + + ESM::Position CellRef::getPosition() const + { + return mCellRef.mPos; + } + + void CellRef::setPosition(const ESM::Position &position) + { + mChanged = true; + mCellRef.mPos = position; + } + + float CellRef::getEnchantmentCharge() const + { + return mCellRef.mEnchantmentCharge; + } + + void CellRef::setEnchantmentCharge(float charge) + { + if (charge != mCellRef.mEnchantmentCharge) + { + mChanged = true; + mCellRef.mEnchantmentCharge = charge; + } + } + + int CellRef::getCharge() const + { + return mCellRef.mCharge; + } + + void CellRef::setCharge(int charge) + { + if (charge != mCellRef.mCharge) + { + mChanged = true; + mCellRef.mCharge = charge; + } + } + + std::string CellRef::getOwner() const + { + return mCellRef.mOwner; + } + + void CellRef::setOwner(const std::string &owner) + { + if (owner != mCellRef.mOwner) + { + mChanged = true; + mCellRef.mOwner = owner; + } + } + + std::string CellRef::getSoul() const + { + return mCellRef.mSoul; + } + + void CellRef::setSoul(const std::string &soul) + { + if (soul != mCellRef.mSoul) + { + mChanged = true; + mCellRef.mSoul = soul; + } + } + + std::string CellRef::getFaction() const + { + return mCellRef.mFaction; + } + + void CellRef::setFaction(const std::string &faction) + { + if (faction != mCellRef.mFaction) + { + mChanged = true; + mCellRef.mFaction = faction; + } + } + + int CellRef::getLockLevel() const + { + return mCellRef.mLockLevel; + } + + void CellRef::setLockLevel(int lockLevel) + { + if (lockLevel != mCellRef.mLockLevel) + { + mChanged = true; + mCellRef.mLockLevel = lockLevel; + } + } + + std::string CellRef::getKey() const + { + return mCellRef.mKey; + } + + std::string CellRef::getTrap() const + { + return mCellRef.mTrap; + } + + void CellRef::setTrap(const std::string& trap) + { + if (trap != mCellRef.mTrap) + { + mChanged = true; + mCellRef.mTrap = trap; + } + } + + int CellRef::getGoldValue() const + { + return mCellRef.mGoldValue; + } + + void CellRef::setGoldValue(int value) + { + if (value != mCellRef.mGoldValue) + { + mChanged = true; + mCellRef.mGoldValue = value; + } + } + + void CellRef::writeState(ESM::ObjectState &state) const + { + state.mRef = mCellRef; + } + + bool CellRef::hasChanged() const + { + return mChanged; + } + +} diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp new file mode 100644 index 0000000000..3b0c2251be --- /dev/null +++ b/apps/openmw/mwworld/cellref.hpp @@ -0,0 +1,99 @@ +#ifndef OPENMW_MWWORLD_CELLREF_H +#define OPENMW_MWWORLD_CELLREF_H + +#include + +namespace ESM +{ + class ObjectState; +} + +namespace MWWorld +{ + + /// \brief Encapsulated variant of ESM::CellRef with change tracking + class CellRef + { + public: + + CellRef (const ESM::CellRef& ref) + : mCellRef(ref) + { + mChanged = false; + } + + // Note: Currently unused for items in containers + ESM::RefNum getRefNum() const; + + // Id of object being referenced + std::string getRefId() const; + + // For doors - true if this door teleports to somewhere else, false + // if it should open through animation. + bool getTeleport() const; + + // Teleport location for the door, if this is a teleporting door. + ESM::Position getDoorDest() const; + + // Destination cell for doors (optional) + std::string getDestCell() const; + + // Scale applied to mesh + float getScale() const; + void setScale(float scale); + + // Position and rotation of this object within the cell + ESM::Position getPosition() const; + void setPosition (const ESM::Position& position); + + // Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full). + float getEnchantmentCharge() const; + + void setEnchantmentCharge(float charge); + + // For weapon or armor, this is the remaining item health. + // For tools (lockpicks, probes, repair hammer) it is the remaining uses. + int getCharge() const; + void setCharge(int charge); + + // The NPC that owns this object (and will get angry if you steal it) + std::string getOwner() const; + void setOwner(const std::string& owner); + + // ID of creature trapped in this soul gem + std::string getSoul() const; + void setSoul(const std::string& soul); + + // The faction that owns this object (and will get angry if + // you take it and are not a faction member) + std::string getFaction() const; + void setFaction (const std::string& faction); + + // Lock level for doors and containers + // Positive for a locked door. 0 for a door that was never locked. + // For an unlocked door, it is set to -(previous locklevel) + int getLockLevel() const; + void setLockLevel(int lockLevel); + // Key and trap ID names, if any + std::string getKey() const; + std::string getTrap() const; + void setTrap(const std::string& trap); + + // This is 5 for Gold_005 references, 100 for Gold_100 and so on. + int getGoldValue() const; + void setGoldValue(int value); + + // Write the content of this CellRef into the given ObjectState + void writeState (ESM::ObjectState& state) const; + + // Has this CellRef changed since it was originally loaded? + bool hasChanged() const; + + private: + bool mChanged; + ESM::CellRef mCellRef; + }; + +} + +#endif diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp index 264929bfb5..9c3370f08a 100644 --- a/apps/openmw/mwworld/cellreflist.hpp +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -27,7 +27,7 @@ namespace MWWorld LiveRef *find (const std::string& name) { for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter) - if (iter->mData.getCount() > 0 && iter->mRef.mRefID == name) + if (iter->mData.getCount() > 0 && iter->mRef.getRefId() == name) return &*iter; return 0; diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 04d733e2c4..63cdbfb1a3 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -72,8 +72,16 @@ namespace iter (collection.mList.begin()); iter!=collection.mList.end(); ++iter) { - if (iter->mData.getCount()==0 && iter->mRef.mRefNum.mContentFile==-1) - continue; // deleted reference that did not come from a content file -> ignore + if (!iter->mData.hasChanged() && !iter->mRef.hasChanged() && iter->mRef.getRefNum().mContentFile != -1) + { + // Reference that came from a content file and has not been changed -> ignore + continue; + } + if (iter->mData.getCount()==0 && iter->mRef.getRefNum().mContentFile==-1) + { + // Deleted reference that did not come from a content file -> ignore + continue; + } RecordType state; iter->save (state); @@ -117,7 +125,7 @@ namespace { for (typename MWWorld::CellRefList::List::iterator iter (collection.mList.begin()); iter!=collection.mList.end(); ++iter) - if (iter->mRef.mRefNum==state.mRef.mRefNum) + if (iter->mRef.getRefNum()==state.mRef.mRefNum) { // overwrite existing reference iter->load (state); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 100e758f24..c13ecfab5a 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -82,6 +82,14 @@ namespace MWWorld return false; } + int Class::getItemHealth(const Ptr &ptr) const + { + if (ptr.getCellRef().getCharge() == -1) + return getItemMaxHealth(ptr); + else + return ptr.getCellRef().getCharge(); + } + int Class::getItemMaxHealth (const Ptr& ptr) const { throw std::runtime_error ("class does not have item health"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 54cea9ab01..c3f94d7f10 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -116,9 +116,12 @@ namespace MWWorld virtual bool hasItemHealth (const Ptr& ptr) const; ///< \return Item health data available? (default implementation: false) + virtual int getItemHealth (const Ptr& ptr) const; + ///< Return current item health or throw an exception if class does not have item health + virtual int getItemMaxHealth (const Ptr& ptr) const; ///< Return item max health or throw an exception, if class does not have item health - /// (default implementation: throw an exceoption) + /// (default implementation: throw an exception) virtual void hit(const Ptr& ptr, int type=-1) const; ///< Execute a melee hit, using the current weapon. This will check the relevant skills diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index d816f993bd..2496a6eff4 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -74,7 +74,6 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::getState (CellRefList ref (record); ref.load (state); - ref.mRef.mRefNum.mContentFile = -1; collection.mList.push_back (ref); return ContainerStoreIterator (this, --collection.mList.end()); @@ -127,7 +126,7 @@ int MWWorld::ContainerStore::count(const std::string &id) { int total=0; for (MWWorld::ContainerStoreIterator iter (begin()); iter!=end(); ++iter) - if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, id)) + if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), id)) total += iter->getRefData().getCount(); return total; } @@ -145,7 +144,7 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) const MWWorld::Class& cls1 = ptr1.getClass(); const MWWorld::Class& cls2 = ptr2.getClass(); - if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().mRefID, ptr2.getCellRef().mRefID)) + if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().getRefId(), ptr2.getCellRef().getRefId())) return false; // If it has an enchantment, don't stack when some of the charge is already used @@ -154,25 +153,24 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find( ptr1.getClass().getEnchantment(ptr1)); float maxCharge = enchantment->mData.mCharge; - float enchantCharge1 = ptr1.getCellRef().mEnchantmentCharge == -1 ? maxCharge : ptr1.getCellRef().mEnchantmentCharge; - float enchantCharge2 = ptr2.getCellRef().mEnchantmentCharge == -1 ? maxCharge : ptr2.getCellRef().mEnchantmentCharge; + float enchantCharge1 = ptr1.getCellRef().getEnchantmentCharge() == -1 ? maxCharge : ptr1.getCellRef().getEnchantmentCharge(); + float enchantCharge2 = ptr2.getCellRef().getEnchantmentCharge() == -1 ? maxCharge : ptr2.getCellRef().getEnchantmentCharge(); if (enchantCharge1 != maxCharge || enchantCharge2 != maxCharge) return false; } return ptr1 != ptr2 // an item never stacks onto itself - && ptr1.getCellRef().mOwner == ptr2.getCellRef().mOwner - && ptr1.getCellRef().mSoul == ptr2.getCellRef().mSoul + && ptr1.getCellRef().getOwner() == ptr2.getCellRef().getOwner() + && ptr1.getCellRef().getSoul() == ptr2.getCellRef().getSoul() && ptr1.getClass().getRemainingUsageTime(ptr1) == ptr2.getClass().getRemainingUsageTime(ptr2) && cls1.getScript(ptr1) == cls2.getScript(ptr2) // item that is already partly used up never stacks - && (!cls1.hasItemHealth(ptr1) || ptr1.getCellRef().mCharge == -1 - || cls1.getItemMaxHealth(ptr1) == ptr1.getCellRef().mCharge) - && (!cls2.hasItemHealth(ptr2) || ptr2.getCellRef().mCharge == -1 - || cls2.getItemMaxHealth(ptr2) == ptr2.getCellRef().mCharge); + && (!cls1.hasItemHealth(ptr1) || ( + cls1.getItemHealth(ptr1) == cls1.getItemMaxHealth(ptr1) + && cls2.getItemHealth(ptr2) == cls2.getItemMaxHealth(ptr2))); } MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &id, int count, const Ptr &actorPtr) @@ -195,19 +193,19 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr { // HACK: Set owner on the original item, then reset it after we have copied it // If we set the owner on the copied item, it would not stack correctly... - std::string oldOwner = itemPtr.getCellRef().mOwner; + std::string oldOwner = itemPtr.getCellRef().getOwner(); if (actorPtr == player) { // No point in setting owner to the player - NPCs will not respect this anyway // Additionally, setting it to "player" would make those items not stack with items that don't have an owner - itemPtr.getCellRef().mOwner = ""; + itemPtr.getCellRef().setOwner(""); } else - itemPtr.getCellRef().mOwner = actorPtr.getCellRef().mRefID; + itemPtr.getCellRef().setOwner(actorPtr.getCellRef().getRefId()); it = addImp(itemPtr, count); - itemPtr.getCellRef().mOwner = oldOwner; + itemPtr.getCellRef().setOwner(oldOwner); } else { @@ -219,12 +217,14 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr // we may have copied an item from the world, so reset a few things first item.getRefData().setBaseNode(NULL); // Especially important, otherwise scripts on the item could think that it's actually in a cell - item.getCellRef().mPos.rot[0] = 0; - item.getCellRef().mPos.rot[1] = 0; - item.getCellRef().mPos.rot[2] = 0; - item.getCellRef().mPos.pos[0] = 0; - item.getCellRef().mPos.pos[1] = 0; - item.getCellRef().mPos.pos[2] = 0; + ESM::Position pos; + pos.rot[0] = 0; + pos.rot[1] = 0; + pos.rot[2] = 0; + pos.pos[0] = 0; + pos.pos[1] = 0; + pos.pos[2] = 0; + item.getCellRef().setPosition(pos); std::string script = item.getClass().getScript(item); if(script != "") @@ -259,17 +259,17 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr, // gold needs special handling: when it is inserted into a container, the base object automatically becomes Gold_001 // this ensures that gold piles of different sizes stack with each other (also, several scripts rely on Gold_001 for detecting player gold) - if (Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_001") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_005") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_010") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_025") - || Misc::StringUtils::ciEqual(ptr.getCellRef().mRefID, "gold_100")) + if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_001") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_005") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_010") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_025") + || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_100")) { int realCount = count * ptr.getClass().getValue(ptr); for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { - if (Misc::StringUtils::ciEqual((*iter).getCellRef().mRefID, MWWorld::ContainerStore::sGoldId)) + if (Misc::StringUtils::ciEqual((*iter).getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) { iter->getRefData().setCount(iter->getRefData().getCount() + realCount); flagAsModified(); @@ -328,7 +328,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const int toRemove = count; for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter) - if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, itemId)) + if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId)) toRemove -= remove(*iter, toRemove, actor); flagAsModified(); @@ -408,8 +408,8 @@ void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std:: } count = std::abs(count); - ref.getPtr().getCellRef().mOwner = owner; - ref.getPtr().getCellRef().mFaction = faction; + ref.getPtr().getCellRef().setOwner(owner); + ref.getPtr().getCellRef().setFaction(faction); addImp (ref.getPtr(), count); } } diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 78a2950304..2eb8aeb465 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -206,7 +206,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) // Only autoEquip if we are the original owner of the item. // This stops merchants from auto equipping anything you sell to them. // ...unless this is a companion, he should always equip items given to him. - if (!Misc::StringUtils::ciEqual(test.getCellRef().mOwner, actor.getCellRef().mRefID) && + if (!Misc::StringUtils::ciEqual(test.getCellRef().getOwner(), actor.getCellRef().getRefId()) && (actor.getClass().getScript(actor).empty() || !actor.getRefData().getLocals().getIntVar(actor.getClass().getScript(actor), "companion"))) continue; @@ -337,7 +337,7 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor) std::vector params; - bool existed = (mPermanentMagicEffectMagnitudes.find((**iter).getCellRef().mRefID) != mPermanentMagicEffectMagnitudes.end()); + bool existed = (mPermanentMagicEffectMagnitudes.find((**iter).getCellRef().getRefId()) != mPermanentMagicEffectMagnitudes.end()); if (!existed) { // Roll some dice, one for each effect @@ -358,10 +358,10 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor) // Consider equipping the same item twice (e.g. a ring) // However, permanent enchantments with a random magnitude are kind of an exploit anyway, // so it doesn't really matter if both items will get the same magnitude. *Extreme* edge case. - mPermanentMagicEffectMagnitudes[(**iter).getCellRef().mRefID] = params; + mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()] = params; } else - params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().mRefID]; + params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()]; int i=0; for (std::vector::const_iterator effectIt (enchantment.mEffects.mList.begin()); @@ -407,7 +407,7 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor) { if (*iter == end()) continue; - if ((**iter).getCellRef().mRefID == it->first) + if ((**iter).getCellRef().getRefId() == it->first) { found = true; } @@ -589,14 +589,14 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito if (enchantment.mData.mType != ESM::Enchantment::ConstantEffect) continue; - if (mPermanentMagicEffectMagnitudes.find((**iter).getCellRef().mRefID) == mPermanentMagicEffectMagnitudes.end()) + if (mPermanentMagicEffectMagnitudes.find((**iter).getCellRef().getRefId()) == mPermanentMagicEffectMagnitudes.end()) continue; int i=0; for (std::vector::const_iterator effectIt (enchantment.mEffects.mList.begin()); effectIt!=enchantment.mEffects.mList.end(); ++effectIt) { - const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().mRefID][i]; + const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()][i]; float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params.mRandom; magnitude *= params.mMultiplier; visitor.visit(MWMechanics::EffectKey(*effectIt), (**iter).getClass().getName(**iter), -1, magnitude); @@ -626,15 +626,15 @@ void MWWorld::InventoryStore::rechargeItems(float duration) { for (TRechargingItems::iterator it = mRechargingItems.begin(); it != mRechargingItems.end(); ++it) { - if (it->first->getCellRef().mEnchantmentCharge == -1 - || it->first->getCellRef().mEnchantmentCharge == it->second) + if (it->first->getCellRef().getEnchantmentCharge() == -1 + || it->first->getCellRef().getEnchantmentCharge() == it->second) continue; static float fMagicItemRechargePerSecond = MWBase::Environment::get().getWorld()->getStore().get().find( "fMagicItemRechargePerSecond")->getFloat(); - it->first->getCellRef().mEnchantmentCharge = std::min (it->first->getCellRef().mEnchantmentCharge + fMagicItemRechargePerSecond * duration, - it->second); + it->first->getCellRef().setEnchantmentCharge(std::min (it->first->getCellRef().getEnchantmentCharge() + fMagicItemRechargePerSecond * duration, + it->second)); } } diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 1b13e38038..0921d3a1b5 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -11,7 +11,7 @@ #include "esmstore.hpp" MWWorld::LiveCellRefBase::LiveCellRefBase(std::string type, const ESM::CellRef &cref) - : mClass(&Class::get(type)), mRef(cref), mData(mRef) + : mClass(&Class::get(type)), mRef(cref), mData(cref) { } @@ -41,7 +41,7 @@ void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state) void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const { - state.mRef = mRef; + mRef.writeState(state); /// \todo get rid of this cast once const-correct Ptr are available Ptr ptr (const_cast (this)); diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index b2e4d6d567..3994d8a249 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -3,7 +3,7 @@ #include -#include +#include "cellref.hpp" #include "refdata.hpp" @@ -26,7 +26,7 @@ namespace MWWorld /** Information about this instance, such as 3D location and rotation * and individual type-dependent data. */ - ESM::CellRef mRef; + MWWorld::CellRef mRef; /** runtime-data */ RefData mData; @@ -62,9 +62,9 @@ namespace MWWorld /// \note Does not check if the RefId exists. }; - inline bool operator== (const LiveCellRefBase& cellRef, const ESM::CellRef::RefNum refNum) + inline bool operator== (const LiveCellRefBase& cellRef, const ESM::RefNum refNum) { - return cellRef.mRef.mRefNum==refNum; + return cellRef.mRef.getRefNum()==refNum; } /// A reference to one object (of any type) in a cell. diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index 99accbb979..3842e7ff1b 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -23,10 +23,20 @@ namespace MWWorld { const T* base = list.find(name); - LiveCellRef ref; - ref.mBase = base; - ref.mRef.mRefNum.mIndex = 0; - ref.mRef.mRefNum.mContentFile = -1; + ESM::CellRef cellRef; + cellRef.mRefNum.mIndex = 0; + cellRef.mRefNum.mContentFile = -1; + cellRef.mRefID = name; + cellRef.mScale = 1; + cellRef.mFactIndex = 0; + cellRef.mCharge = -1; + cellRef.mGoldValue = 1; + cellRef.mEnchantmentCharge = -1; + cellRef.mTeleport = false; + cellRef.mLockLevel = 0; + cellRef.mReferenceBlocked = 0; + + LiveCellRef ref(cellRef, base); mRef = ref; mPtr = Ptr (&boost::any_cast&> (mRef), 0); @@ -67,19 +77,6 @@ namespace MWWorld throw std::logic_error ("failed to create manual cell ref for " + lowerName + " (unknown type)"); } - // initialise - ESM::CellRef& cellRef = mPtr.getCellRef(); - cellRef.mRefID = lowerName; - cellRef.mRefNum.mIndex = 0; - cellRef.mRefNum.mContentFile = -1; - cellRef.mScale = 1; - cellRef.mFactIndex = 0; - cellRef.mCharge = -1; - cellRef.mGoldValue = 1; - cellRef.mEnchantmentCharge = -1; - cellRef.mTeleport = false; - cellRef.mLockLevel = 0; - cellRef.mReferenceBlocked = 0; mPtr.getRefData().setCount(count); } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 039fce0caa..b8f0f8699b 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -656,7 +656,7 @@ namespace MWWorld return false; } btVector3 btMin, btMax; - float scale = ptr.getCellRef().mScale; + float scale = ptr.getCellRef().getScale(); mEngine->getObjectAABB(model, scale, btMin, btMax); min.x = btMin.x(); diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 5ca8f29525..9913b888b2 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -39,8 +39,10 @@ namespace MWWorld mCurrentCrimeId(-1), mPaidCrimeId(-1) { - mPlayer.mBase = player; - mPlayer.mRef.mRefID = "player"; + ESM::CellRef cellRef; + cellRef.blank(); + cellRef.mRefID = "player"; + mPlayer = LiveCellRef(cellRef, player); float* playerPos = mPlayer.mData.getPosition().pos; playerPos[0] = playerPos[1] = playerPos[2] = 0; diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 12cca27545..4e4f0b271a 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -102,11 +102,11 @@ namespace MWWorld { ProjectileState state; state.mActorId = actor.getClass().getCreatureStats(actor).getActorId(); - state.mBowId = bow.getCellRef().mRefID; + state.mBowId = bow.getCellRef().getRefId(); state.mVelocity = orient.yAxis() * speed; - state.mId = projectile.getCellRef().mRefID; + state.mId = projectile.getCellRef().getRefId(); - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().mRefID); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId()); MWWorld::Ptr ptr = ref.getPtr(); state.mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(pos, orient); @@ -241,7 +241,7 @@ namespace MWWorld { MWWorld::InventoryStore& inv = caster.getClass().getInventoryStore(caster); MWWorld::ContainerStoreIterator invIt = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - if (invIt != inv.end() && Misc::StringUtils::ciEqual(invIt->getCellRef().mRefID, it->mBowId)) + if (invIt != inv.end() && Misc::StringUtils::ciEqual(invIt->getCellRef().getRefId(), it->mBowId)) bow = *invIt; } diff --git a/apps/openmw/mwworld/ptr.cpp b/apps/openmw/mwworld/ptr.cpp index b047ba47ca..1cf22744a8 100644 --- a/apps/openmw/mwworld/ptr.cpp +++ b/apps/openmw/mwworld/ptr.cpp @@ -22,7 +22,7 @@ MWWorld::LiveCellRefBase *MWWorld::Ptr::getBase() const return mRef; } -ESM::CellRef& MWWorld::Ptr::getCellRef() const +MWWorld::CellRef& MWWorld::Ptr::getCellRef() const { assert(mRef); diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index f4696d3b3b..2f37a1cfd8 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -60,7 +60,7 @@ namespace MWWorld MWWorld::LiveCellRefBase *getBase() const; - ESM::CellRef& getCellRef() const; + MWWorld::CellRef& getCellRef() const; RefData& getRefData() const; diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 008782130b..2e267b37ce 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -22,6 +22,7 @@ namespace MWWorld mCount = refData.mCount; mPosition = refData.mPosition; mLocalRotation = refData.mLocalRotation; + mChanged = refData.mChanged; mCustomData = refData.mCustomData ? refData.mCustomData->clone() : 0; } @@ -35,7 +36,7 @@ namespace MWWorld } RefData::RefData() - : mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mCustomData (0) + : mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mCustomData (0), mChanged(false) { for (int i=0; i<3; ++i) { @@ -47,7 +48,8 @@ namespace MWWorld RefData::RefData (const ESM::CellRef& cellRef) : mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mPosition (cellRef.mPos), - mCustomData (0) + mCustomData (0), + mChanged(false) // Loading from ESM/ESP files -> assume unchanged { mLocalRotation.rot[0]=0; mLocalRotation.rot[1]=0; @@ -56,8 +58,9 @@ namespace MWWorld RefData::RefData (const ESM::ObjectState& objectState) : mBaseNode (0), mHasLocals (false), mEnabled (objectState.mEnabled), - mCount (objectState.mCount), mPosition (objectState.mPosition), mCustomData (0) - { + mCount (objectState.mCount), mPosition (objectState.mPosition), mCustomData (0), + mChanged(true) // Loading from a savegame -> assume changed + { for (int i=0; i<3; ++i) mLocalRotation.rot[i] = objectState.mLocalRotation[i]; } @@ -149,6 +152,7 @@ namespace MWWorld { mLocals.configure (script); mHasLocals = true; + mChanged = true; } } @@ -157,6 +161,8 @@ namespace MWWorld if(count == 0) MWBase::Environment::get().getWorld()->removeRefScript(this); + mChanged = true; + mCount = count; } @@ -172,26 +178,31 @@ namespace MWWorld void RefData::enable() { + mChanged = !mEnabled; mEnabled = true; } void RefData::disable() { + mChanged = mEnabled; mEnabled = false; } ESM::Position& RefData::getPosition() { + mChanged = true; return mPosition; } LocalRotation& RefData::getLocalRotation() { + mChanged = true; return mLocalRotation; } void RefData::setCustomData (CustomData *data) { + mChanged = true; // We do not currently track CustomData, so assume anything with a CustomData is changed delete mCustomData; mCustomData = data; } @@ -200,4 +211,9 @@ namespace MWWorld { return mCustomData; } + + bool RefData::hasChanged() const + { + return mChanged; + } } diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 82371b056a..a8ffad6843 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -47,6 +47,8 @@ namespace MWWorld void cleanup(); + bool mChanged; + public: RefData(); @@ -108,6 +110,9 @@ namespace MWWorld CustomData *getCustomData(); ///< May return a 0-pointer. The ownership of the return data object is not transferred. + + bool hasChanged() const; + ///< Has this RefData changed since it was originally loaded? }; } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 122a6f9bf5..32bf773bd5 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -47,10 +47,10 @@ namespace { if (mRescale) { - if (ptr.getCellRef().mScale<0.5) - ptr.getCellRef().mScale = 0.5; - else if (ptr.getCellRef().mScale>2) - ptr.getCellRef().mScale = 2; + if (ptr.getCellRef().getScale()<0.5) + ptr.getCellRef().setScale(0.5); + else if (ptr.getCellRef().getScale()>2) + ptr.getCellRef().setScale(2); } if (ptr.getRefData().getCount() && ptr.getRefData().isEnabled()) @@ -65,7 +65,7 @@ namespace float az = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[2]).valueDegrees(); MWBase::Environment::get().getWorld()->localRotateObject (ptr, ax, ay, az); - MWBase::Environment::get().getWorld()->scaleObject (ptr, ptr.getCellRef().mScale); + MWBase::Environment::get().getWorld()->scaleObject (ptr, ptr.getCellRef().getScale()); ptr.getClass().adjustPosition (ptr); } catch (const std::exception& e) @@ -484,7 +484,7 @@ namespace MWWorld mRendering.addObject(ptr); ptr.getClass().insertObject(ptr, *mPhysics); MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); - MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale); + MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale()); } void Scene::removeObjectFromScene (const Ptr& ptr) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5a83a5bc74..727b200f57 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1034,7 +1034,7 @@ namespace MWWorld void World::scaleObject (const Ptr& ptr, float scale) { - ptr.getCellRef().mScale = scale; + ptr.getCellRef().setScale(scale); ptr.getClass().adjustScale(ptr,scale); if(ptr.getRefData().getBaseNode() == 0) @@ -1544,7 +1544,7 @@ namespace MWWorld if (!ref.mData.isEnabled()) continue; - if (ref.mRef.mTeleport) + if (ref.mRef.getTeleport()) { World::DoorMarker newMarker; newMarker.name = MWClass::Door::getDestination(ref); @@ -1948,7 +1948,7 @@ namespace MWWorld for (CellRefList::List::iterator container = refList.begin(); container != refList.end(); ++container) { MWWorld::Ptr ptr (&*container, *cellIt); - if (Misc::StringUtils::ciEqual(ptr.getCellRef().mOwner, npc.getCellRef().mRefID)) + if (Misc::StringUtils::ciEqual(ptr.getCellRef().getOwner(), npc.getCellRef().getRefId())) out.push_back(ptr); } } @@ -1976,7 +1976,7 @@ namespace MWWorld (*cellIt)->forEach(functor); for (std::vector::iterator it = functor.mHandles.begin(); it != functor.mHandles.end(); ++it) - if (Misc::StringUtils::ciEqual(searchPtrViaHandle(*it).getCellRef().mOwner, npc.getCellRef().mRefID)) + if (Misc::StringUtils::ciEqual(searchPtrViaHandle(*it).getCellRef().getOwner(), npc.getCellRef().getRefId())) out.push_back(searchPtrViaHandle(*it)); } } @@ -2032,34 +2032,34 @@ namespace MWWorld } const DoorList &doors = cellStore->get().mList; for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it) { - if (!it->mRef.mTeleport) { + if (!it->mRef.getTeleport()) { continue; } MWWorld::CellStore *source = 0; // door to exterior - if (it->mRef.mDestCell.empty()) { + if (it->mRef.getDestCell().empty()) { int x, y; - const float *pos = it->mRef.mDoorDest.pos; + const float *pos = it->mRef.getDoorDest().pos; positionToIndex(pos[0], pos[1], x, y); source = getExterior(x, y); } // door to interior else { - source = getInterior(it->mRef.mDestCell); + source = getInterior(it->mRef.getDestCell()); } if (0 != source) { // Find door leading to our current teleport door // and use it destination to position inside cell. const DoorList &doors = source->get().mList; for (DoorList::const_iterator jt = doors.begin(); jt != doors.end(); ++jt) { - if (it->mRef.mTeleport && - Misc::StringUtils::ciEqual(name, jt->mRef.mDestCell)) + if (it->mRef.getTeleport() && + Misc::StringUtils::ciEqual(name, jt->mRef.getDestCell())) { /// \note Using _any_ door pointed to the interior, /// not the one pointed to current door. - pos = jt->mRef.mDoorDest; + pos = jt->mRef.getDoorDest(); return true; } } @@ -2322,9 +2322,9 @@ namespace MWWorld for (CellRefList::List::iterator it = refList.begin(); it != refList.end(); ++it) { MWWorld::LiveCellRef& ref = *it; - if (ref.mRef.mTeleport && ref.mRef.mDestCell.empty()) + if (ref.mRef.getTeleport() && ref.mRef.getDestCell().empty()) { - ESM::Position pos = ref.mRef.mDoorDest; + ESM::Position pos = ref.mRef.getDoorDest(); result = Ogre::Vector3(pos.pos); return true; } @@ -2520,13 +2520,13 @@ namespace MWWorld ContainerStore& store = ptr.getClass().getContainerStore(ptr); for (ContainerStoreIterator it = store.begin(); it != store.end(); ++it) //Move all stolen stuff into chest { - if (!it->getCellRef().mOwner.empty() && it->getCellRef().mOwner != "player") //Not owned by no one/player? + if (!it->getCellRef().getOwner().empty() && it->getCellRef().getOwner() != "player") //Not owned by no one/player? { closestChest.getClass().getContainerStore(closestChest).add(*it, it->getRefData().getCount(), closestChest); store.remove(*it, it->getRefData().getCount(), ptr); } } - closestChest.getCellRef().mLockLevel = abs(closestChest.getCellRef().mLockLevel); + closestChest.getClass().unlock(closestChest); } } @@ -2630,7 +2630,7 @@ namespace MWWorld MWWorld::CellStore* cell = mPlayer->getPlayer().getCell(); MWWorld::ManualRef ref(getStore(), selectedCreature, 1); - ref.getPtr().getCellRef().mPos = ipos; + ref.getPtr().getCellRef().setPosition(ipos); safePlaceObject(ref.getPtr(), cell, ipos); } diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index f04e819c88..84518bed90 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -168,7 +168,7 @@ void ESM::CellRef::blank() } } -bool ESM::operator== (const CellRef::RefNum& left, const CellRef::RefNum& right) +bool ESM::operator== (const RefNum& left, const RefNum& right) { return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile; } diff --git a/components/esm/cellref.hpp b/components/esm/cellref.hpp index 16f6603a28..5f53eadbe3 100644 --- a/components/esm/cellref.hpp +++ b/components/esm/cellref.hpp @@ -10,6 +10,13 @@ namespace ESM class ESMWriter; class ESMReader; + + struct RefNum + { + int mIndex; + int mContentFile; // -1 no content file + }; + /* Cell reference. This represents ONE object (of many) inside the cell. The cell references are not loaded as part of the normal loading process, but are rather loaded later on demand when we are @@ -20,13 +27,10 @@ namespace ESM { public: - struct RefNum - { - int mIndex; - int mContentFile; // -1 no content file - }; + // Reference number + // Note: Currently unused for items in containers + RefNum mRefNum; - RefNum mRefNum; // Reference number std::string mRefID; // ID of object being referenced float mScale; // Scale applied to mesh @@ -38,7 +42,7 @@ namespace ESM // I have no idea, looks like a link to a global variable? std::string mGlob; - // ID of creature trapped in this soul gem (?) + // ID of creature trapped in this soul gem std::string mSoul; // The faction that owns this object (and will get angry if @@ -53,7 +57,7 @@ namespace ESM // For tools (lockpicks, probes, repair hammer) it is the remaining uses. int mCharge; - // Remaining enchantment charge + // Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full). float mEnchantmentCharge; // This is 5 for Gold_005 references, 100 for Gold_100 and so on. @@ -94,7 +98,7 @@ namespace ESM void blank(); }; - bool operator== (const CellRef::RefNum& left, const CellRef::RefNum& right); + bool operator== (const RefNum& left, const RefNum& right); } #endif diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 55d043c8a4..0830c5de69 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -16,7 +16,7 @@ namespace { ///< Translate 8bit/24bit code (stored in refNum.mIndex) into a proper refNum - void adjustRefNum (ESM::CellRef::RefNum& refNum, ESM::ESMReader& reader) + void adjustRefNum (ESM::RefNum& refNum, ESM::ESMReader& reader) { int local = (refNum.mIndex & 0xff000000) >> 24; @@ -40,12 +40,12 @@ namespace ESM unsigned int Cell::sRecordId = REC_CELL; // Some overloaded compare operators. - bool operator== (const MovedCellRef& ref, const CellRef::RefNum& refNum) + bool operator== (const MovedCellRef& ref, const RefNum& refNum) { return ref.mRefNum == refNum; } - bool operator== (const CellRef& ref, const CellRef::RefNum& refNum) + bool operator== (const CellRef& ref, const RefNum& refNum) { return ref.mRefNum == refNum; } diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index f01c88c65d..28204c9ee1 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -28,7 +28,7 @@ class ESMWriter; class MovedCellRef { public: - CellRef::RefNum mRefNum; + RefNum mRefNum; // Target cell (if exterior) int mTarget[2]; @@ -39,8 +39,8 @@ public: }; /// Overloaded compare operator used to search inside a list of cell refs. -bool operator==(const MovedCellRef& ref, const CellRef::RefNum& refNum); -bool operator==(const CellRef& ref, const CellRef::RefNum& refNum); +bool operator==(const MovedCellRef& ref, const RefNum& refNum); +bool operator==(const CellRef& ref, const RefNum& refNum); typedef std::list MovedCellRefTracker; typedef std::list CellRefTracker; From 10d835a55c2d1bbd4fac3950d6253245e10a0feb Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 25 May 2014 15:06:53 +0200 Subject: [PATCH 57/82] Some more missing isInCell checks --- apps/openmw/mwscript/cellextensions.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index ac175634bd..2e2e9b6985 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -142,6 +142,11 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { + if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) + { + runtime.push(0.f); + return; + } MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); if (cell->getCell()->hasWater()) runtime.push (cell->getWaterLevel()); @@ -158,6 +163,11 @@ namespace MWScript { Interpreter::Type_Float level = runtime[0].mFloat; + if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) + { + return; + } + MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); if (cell->getCell()->isExterior()) @@ -176,6 +186,11 @@ namespace MWScript { Interpreter::Type_Float level = runtime[0].mFloat; + if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) + { + return; + } + MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); if (cell->getCell()->isExterior()) From 8fa7fcdbee3d63d61120526b24ef3b104c01e718 Mon Sep 17 00:00:00 2001 From: mrcheko Date: Sun, 25 May 2014 21:03:37 +0400 Subject: [PATCH 58/82] fix bug http://bugs.openmw.org/issues/1335 (1304 as well) though fish detects if actor is swimming, but in MW it attacks even if the player is knee-deep in water --- apps/openmw/mwmechanics/actors.cpp | 8 +++++ apps/openmw/mwmechanics/aicombat.cpp | 29 +++++++++++++------ .../mwmechanics/mechanicsmanagerimp.cpp | 4 ++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 35667a23c4..fe89fda11b 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -191,6 +191,14 @@ namespace MWMechanics if (againstPlayer && creatureStats.isHostile()) return; // already fighting against player + // pure water creatures won't try to fight with the target on the ground + // except that creature is already hostile + if ((againstPlayer || !creatureStats.isHostile()) + && ((actor1.getClass().canSwim(actor1) && !actor1.getClass().canWalk(actor1) // pure water creature + && !MWBase::Environment::get().getWorld()->isSwimming(actor2)) + || (!actor1.getClass().canSwim(actor1) && MWBase::Environment::get().getWorld()->isSwimming(actor2)))) // creature can't swim to target + return; + float fight; if (againstPlayer) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 9fe92f8070..8f81885597 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -53,7 +53,7 @@ namespace // cast up-down ray with some offset from actor position to check for pits/obstacles on the way to target; // magnitude of pits/obstacles is defined by PATHFIND_Z_REACH - bool checkWayIsClear(const Ogre::Vector3& from, const Ogre::Vector3& to, float offset) + bool checkWayIsClear(const Ogre::Vector3& from, const Ogre::Vector3& to, float offsetXY) { if((to - from).length() >= PATHFIND_CAUTION_DIST || abs(from.z - to.z) <= PATHFIND_Z_REACH) { @@ -61,7 +61,7 @@ namespace dir.z = 0; dir.normalise(); float verticalOffset = 200; // instead of '200' here we want the height of the actor - Ogre::Vector3 _from = from + dir*offset + Ogre::Vector3::UNIT_Z * verticalOffset; + Ogre::Vector3 _from = from + dir*offsetXY + Ogre::Vector3::UNIT_Z * verticalOffset; // cast up-down ray and find height in world space of hit float h = _from.z - MWBase::Environment::get().getWorld()->getDistToNearestRayHit(_from, -Ogre::Vector3::UNIT_Z, verticalOffset + PATHFIND_Z_REACH + 1); @@ -149,13 +149,24 @@ namespace MWMechanics bool AiCombat::execute (const MWWorld::Ptr& actor,float duration) { //General description - if(actor.getClass().getCreatureStats(actor).isDead()) return true; + if(actor.getClass().getCreatureStats(actor).isDead()) + return true; MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId); if(target.getClass().getCreatureStats(target).isDead()) return true; + if (!actor.getClass().isNpc() && target == MWBase::Environment::get().getWorld()->getPlayerPtr() && + (actor.getClass().canSwim(actor) && !actor.getClass().canWalk(actor) // pure water creature + && !MWBase::Environment::get().getWorld()->isSwimming(target)) // Player moved out of water + || (!actor.getClass().canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(target))) // creature can't swim to Player + { + actor.getClass().getCreatureStats(actor).setHostile(false); + actor.getClass().getCreatureStats(actor).setAttackingOrSpell(false); + return true; + } + //Update every frame if(mCombatMove) { @@ -327,6 +338,7 @@ namespace MWMechanics Ogre::Vector3 vActorPos(pos.pos); Ogre::Vector3 vTargetPos(target.getRefData().getPosition().pos); Ogre::Vector3 vDirToTarget = vTargetPos - vActorPos; + float distToTarget = vDirToTarget.length(); bool isStuck = false; float speed = 0.0f; @@ -342,16 +354,15 @@ namespace MWMechanics // determine vertical angle to target // if actor can move along z-axis it will control movement dir // if can't - it will control correct aiming - mMovement.mRotation[0] = getXAngleToDir(vDirToTarget); - - vDirToTarget.z = 0; - float distToTarget = vDirToTarget.length(); + mMovement.mRotation[0] = getXAngleToDir(vDirToTarget, distToTarget); // (within strike dist) || (not quite strike dist while following) if(distToTarget < rangeAttack || (distToTarget <= rangeFollow && mFollowTarget && !isStuck) ) { //Melee and Close-up combat - mMovement.mRotation[2] = getZAngleToDir(vDirToTarget, distToTarget); + + // if we preserve dir.z then horizontal angle can be inaccurate + mMovement.mRotation[2] = getZAngleToDir(Ogre::Vector3(vDirToTarget.x, vDirToTarget.y, 0)); // (not quite strike dist while following) if (mFollowTarget && distToTarget > rangeAttack) @@ -405,7 +416,7 @@ namespace MWMechanics if(speed == 0.0f) speed = actorCls.getSpeed(actor); // maximum dist before pit/obstacle for actor to avoid them depending on his speed float maxAvoidDist = tReaction * speed + speed / MAX_VEL_ANGULAR.valueRadians() * 2; // *2 - for reliability - preferShortcut = checkWayIsClear(vActorPos, vTargetPos, distToTarget > maxAvoidDist*1.5? maxAvoidDist : maxAvoidDist/2); + preferShortcut = checkWayIsClear(vActorPos, vTargetPos, Ogre::Vector3(vDirToTarget.x, vDirToTarget.y, 0).length() > maxAvoidDist*1.5? maxAvoidDist : maxAvoidDist/2); } // don't use pathgrid when actor can move in 3 dimensions diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 5a72c88837..c9a1814618 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1024,7 +1024,9 @@ namespace MWMechanics void MechanicsManager::startCombat(const MWWorld::Ptr &ptr, const MWWorld::Ptr &target) { - MWBase::Environment::get().getDialogueManager()->say(ptr, "attack"); + if (ptr.getClass().isNpc()) + MWBase::Environment::get().getDialogueManager()->say(ptr, "attack"); + ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(MWMechanics::AiCombat(target), ptr); if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) ptr.getClass().getCreatureStats(ptr).setHostile(true); From 4aab4bae6528af0caa5f0f98b5037383d3b6fa5a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 26 May 2014 10:14:24 +0200 Subject: [PATCH 59/82] minor cleanup and silenced a warning --- apps/openmw/mwmechanics/aicombat.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index d14251886e..9ec770c9d1 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -149,7 +149,7 @@ namespace MWMechanics bool AiCombat::execute (const MWWorld::Ptr& actor,float duration) { //General description - if(actor.getClass().getCreatureStats(actor).isDead()) + if(actor.getClass().getCreatureStats(actor).isDead()) return true; MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId); @@ -157,13 +157,16 @@ namespace MWMechanics if(target.getClass().getCreatureStats(target).isDead()) return true; - if (!actor.getClass().isNpc() && target == MWBase::Environment::get().getWorld()->getPlayerPtr() && - (actor.getClass().canSwim(actor) && !actor.getClass().canWalk(actor) // pure water creature - && !MWBase::Environment::get().getWorld()->isSwimming(target)) // Player moved out of water - || (!actor.getClass().canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(target))) // creature can't swim to Player + const MWWorld::Class& actorClass = actor.getClass(); + MWBase::World& world = *MWBase::Environment::get().getWorld(); + + if ((!actorClass.isNpc() && target == world.getPlayerPtr() && + actorClass.canSwim(actor) && !actorClass.canWalk(actor) // pure water creature + && !world.isSwimming(target)) // Player moved out of water + || (!actorClass.canSwim(actor) && world.isSwimming(target))) // creature can't swim to Player { - actor.getClass().getCreatureStats(actor).setHostile(false); - actor.getClass().getCreatureStats(actor).setAttackingOrSpell(false); + actorClass.getCreatureStats(actor).setHostile(false); + actorClass.getCreatureStats(actor).setAttackingOrSpell(false); return true; } @@ -360,9 +363,9 @@ namespace MWMechanics if(distToTarget < rangeAttack || (distToTarget <= rangeFollow && mFollowTarget && !isStuck) ) { //Melee and Close-up combat - + // if we preserve dir.z then horizontal angle can be inaccurate - mMovement.mRotation[2] = getZAngleToDir(Ogre::Vector3(vDirToTarget.x, vDirToTarget.y, 0)); + mMovement.mRotation[2] = getZAngleToDir(Ogre::Vector3(vDirToTarget.x, vDirToTarget.y, 0)); // (not quite strike dist while following) if (mFollowTarget && distToTarget > rangeAttack) @@ -408,7 +411,7 @@ namespace MWMechanics { bool preferShortcut = false; bool inLOS = MWBase::Environment::get().getWorld()->getLOS(actor, target); - + // check if shortcut is available if(inLOS && (!isStuck || mReadyToAttack) && (!mForceNoShortcut || (Ogre::Vector3(mShortcutFailPos.pos) - vActorPos).length() >= PATHFIND_SHORTCUT_RETRY_DIST)) From bfd91c0681ee766256a0295a2c3f8b0502397167 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 12:31:08 +0200 Subject: [PATCH 60/82] Fix potential NpcStats overwriting issue --- apps/openmw/mwmechanics/npcstats.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 24e758e32e..d50f2c5ae4 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -496,10 +496,10 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state) mExpelled.insert (iter->first); if (iter->second.mRank >= 0) - mFactionRank.insert (std::make_pair (iter->first, iter->second.mRank)); + mFactionRank[iter->first] = iter->second.mRank; if (iter->second.mReputation) - mFactionReputation.insert (std::make_pair (iter->first, iter->second.mReputation)); + mFactionReputation[iter->first] = iter->second.mReputation; } mDisposition = state.mDisposition; From f629307f6050e69cfa295cee59ffbb00b9656591 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 16:43:19 +0200 Subject: [PATCH 61/82] Fix frame delay for sound listener position (Fixes #1180) --- apps/openmw/mwworld/worldimp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 727b200f57..43153612d7 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1375,11 +1375,11 @@ namespace MWWorld updateWeather(duration); - mWorldScene->update (duration, paused); - if (!paused) doPhysics (duration); + mWorldScene->update (duration, paused); + performUpdateSceneQueries (); updateWindowManager (); From 3cd835e61a4a2e1b8e9d28fee5fa1a570459a96d Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 17:34:36 +0200 Subject: [PATCH 62/82] Fix bsa file loading not being case insensitive (Fixes #1178) --- apps/openmw/mwworld/esmstore.cpp | 2 +- components/files/collections.cpp | 35 ++++++++++++++++++----- files/mygui/openmw_settings_window.layout | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 1fdf3c5a50..fc2bd4d773 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -42,7 +42,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) for (int i = 0; i < esm.getIndex(); i++) { const std::string &candidate = allPlugins->at(i).getContext().filename; std::string fnamecandidate = boost::filesystem::path(candidate).filename().string(); - if (fname == fnamecandidate) { + if (Misc::StringUtils::ciEqual(fname, fnamecandidate)) { index = i; break; } diff --git a/components/files/collections.cpp b/components/files/collections.cpp index c6195d88cf..a933eb682c 100644 --- a/components/files/collections.cpp +++ b/components/files/collections.cpp @@ -1,6 +1,7 @@ - #include "collections.hpp" +#include + namespace Files { Collections::Collections() @@ -36,9 +37,19 @@ namespace Files for (Files::PathContainer::const_iterator iter = mDirectories.begin(); iter != mDirectories.end(); ++iter) { - const boost::filesystem::path path = *iter / file; - if (boost::filesystem::exists(path)) - return path.string(); + for (boost::filesystem::directory_iterator iter2 (*iter); + iter2!=boost::filesystem::directory_iterator(); ++iter2) + { + boost::filesystem::path path = *iter2; + + if (mFoldCase) + { + if (Misc::StringUtils::ciEqual(file, path.filename().string())) + return path.string(); + } + else if (path.filename().string() == file) + return path.string(); + } } throw std::runtime_error ("file " + file + " not found"); @@ -49,9 +60,19 @@ namespace Files for (Files::PathContainer::const_iterator iter = mDirectories.begin(); iter != mDirectories.end(); ++iter) { - const boost::filesystem::path path = *iter / file; - if (boost::filesystem::exists(path)) - return true; + for (boost::filesystem::directory_iterator iter2 (*iter); + iter2!=boost::filesystem::directory_iterator(); ++iter2) + { + boost::filesystem::path path = *iter2; + + if (mFoldCase) + { + if (Misc::StringUtils::ciEqual(file, path.filename().string())) + return true; + } + else if (path.filename().string() == file) + return true; + } } return false; diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index 6119ab7b4d..9ecae465c6 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -417,7 +417,7 @@ - + From 0966755a0c8393c6276f3217f6a215f7182f72f5 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 19:56:32 +0200 Subject: [PATCH 63/82] Store death animation index in CreatureStats --- apps/openmw/mwmechanics/character.cpp | 56 +++++++++++++++-------- apps/openmw/mwmechanics/character.hpp | 1 + apps/openmw/mwmechanics/creaturestats.cpp | 15 +++++- apps/openmw/mwmechanics/creaturestats.hpp | 6 +++ components/esm/creaturestats.cpp | 6 +++ components/esm/creaturestats.hpp | 1 + 6 files changed, 66 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 60bccb3f7e..c9da912dd2 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -407,29 +407,25 @@ MWWorld::ContainerStoreIterator getActiveWeapon(CreatureStats &stats, MWWorld::I return inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); } -void CharacterController::playRandomDeath(float startpoint) +void CharacterController::playDeath(float startpoint, CharacterState death) { - if(MWBase::Environment::get().getWorld()->isSwimming(mPtr) && mAnimation->hasAnimation("swimdeath")) + switch (death) { - mDeathState = CharState_SwimDeath; + case CharState_SwimDeath: mCurrentDeath = "swimdeath"; - } - else if (mHitState == CharState_KnockDown) - { - mDeathState = CharState_DeathKnockDown; + break; + case CharState_DeathKnockDown: mCurrentDeath = "deathknockdown"; - } - else if (mHitState == CharState_KnockOut) - { - mDeathState = CharState_DeathKnockOut; + break; + case CharState_DeathKnockOut: mCurrentDeath = "deathknockout"; + break; + default: + mCurrentDeath = "death" + Ogre::StringConverter::toString(death - CharState_Death1 + 1); } - else - { - int selected=0; - mCurrentDeath = chooseRandomGroup("death", &selected); - mDeathState = static_cast(CharState_Death1 + (selected-1)); - } + mDeathState = death; + + mPtr.getClass().getCreatureStats(mPtr).setDeathAnimation(mDeathState - CharState_Death1); // For dead actors, refreshCurrentAnims is no longer called, so we need to disable the movement state manually. mMovementState = CharState_None; @@ -440,6 +436,29 @@ void CharacterController::playRandomDeath(float startpoint) false, 1.0f, "start", "stop", startpoint, 0); } +void CharacterController::playRandomDeath(float startpoint) +{ + if(MWBase::Environment::get().getWorld()->isSwimming(mPtr) && mAnimation->hasAnimation("swimdeath")) + { + mDeathState = CharState_SwimDeath; + } + else if (mHitState == CharState_KnockDown) + { + mDeathState = CharState_DeathKnockDown; + } + else if (mHitState == CharState_KnockOut) + { + mDeathState = CharState_DeathKnockOut; + } + else + { + int selected=0; + chooseRandomGroup("death", &selected); + mDeathState = static_cast(CharState_Death1 + (selected-1)); + } + playDeath(startpoint, mDeathState); +} + CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim) : mPtr(ptr) , mAnimation(anim) @@ -497,7 +516,8 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim if(mDeathState != CharState_None) { - playRandomDeath(1.0f); + int deathindex = mPtr.getClass().getCreatureStats(mPtr).getDeathAnimation(); + playDeath(1.0f, CharacterState(CharState_Death1 + deathindex)); } else refreshCurrentAnims(mIdleState, mMovementState, true); diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 1b7caf34d7..5cefe13bc8 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -181,6 +181,7 @@ class CharacterController void updateVisibility(); + void playDeath(float startpoint, CharacterState death); void playRandomDeath(float startpoint = 0.0f); /// choose a random animation group with \a prefix and numeric suffix diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 3ef6ff4df9..7fd26c25c9 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -22,7 +22,8 @@ namespace MWMechanics mFallHeight(0), mRecalcDynamicStats(false), mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false), mHitRecovery(false), mBlock(false), mMovementFlags(0), mDrawState (DrawState_Nothing), mAttackStrength(0.f), - mLastRestock(0,0), mGoldPool(0), mActorId(-1) + mLastRestock(0,0), mGoldPool(0), mActorId(-1), + mDeathAnimation(0) { for (int i=0; i<4; ++i) mAiSettings[i] = 0; @@ -498,6 +499,7 @@ namespace MWMechanics state.mDrawState = mDrawState; state.mLevel = mLevel; state.mActorId = mActorId; + state.mDeathAnimation = mDeathAnimation; mSpells.writeState(state.mSpells); mActiveSpells.writeState(state.mActiveSpells); @@ -537,6 +539,7 @@ namespace MWMechanics mDrawState = DrawState_(state.mDrawState); mLevel = state.mLevel; mActorId = state.mActorId; + mDeathAnimation = state.mDeathAnimation; mSpells.readState(state.mSpells); mActiveSpells.readState(state.mActiveSpells); @@ -590,4 +593,14 @@ namespace MWMechanics { esm.getHNT(sActorId, "COUN"); } + + unsigned char CreatureStats::getDeathAnimation() const + { + return mDeathAnimation; + } + + void CreatureStats::setDeathAnimation(unsigned char index) + { + mDeathAnimation = index; + } } diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 70a86536a0..8b2398dfbd 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -64,6 +64,9 @@ namespace MWMechanics int mActorId; + // The index of the death animation that was played + unsigned char mDeathAnimation; + protected: // These two are only set by NpcStats, but they are declared in CreatureStats to prevent using virtual methods. bool mIsWerewolf; @@ -250,6 +253,9 @@ namespace MWMechanics void setGoldPool(int pool); int getGoldPool() const; + unsigned char getDeathAnimation() const; + void setDeathAnimation(unsigned char index); + int getActorId(); ///< Will generate an actor ID, if the actor does not have one yet. diff --git a/components/esm/creaturestats.cpp b/components/esm/creaturestats.cpp index 66d8481240..3860e9351f 100644 --- a/components/esm/creaturestats.cpp +++ b/components/esm/creaturestats.cpp @@ -74,6 +74,9 @@ void ESM::CreatureStats::load (ESMReader &esm) mActorId = -1; esm.getHNOT (mActorId, "ACID"); + mDeathAnimation = 0; + esm.getHNOT (mDeathAnimation, "DANM"); + mSpells.load(esm); mActiveSpells.load(esm); } @@ -152,6 +155,9 @@ void ESM::CreatureStats::save (ESMWriter &esm) const if (mActorId != -1) esm.writeHNT ("ACID", mActorId); + if (mDeathAnimation) + esm.writeHNT ("DANM", mDeathAnimation); + mSpells.save(esm); mActiveSpells.save(esm); } diff --git a/components/esm/creaturestats.hpp b/components/esm/creaturestats.hpp index 7814d937ae..5ca3d071fe 100644 --- a/components/esm/creaturestats.hpp +++ b/components/esm/creaturestats.hpp @@ -46,6 +46,7 @@ namespace ESM std::string mLastHitObject; bool mRecalcDynamicStats; int mDrawState; + unsigned char mDeathAnimation; int mLevel; From 5660f283dde88ce71ed9475c3b12a42c45075320 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 20:33:01 +0200 Subject: [PATCH 64/82] Fix actor models incorrectly being rotated on X/Y axes --- apps/openmw/mwrender/actors.cpp | 13 ++++--------- apps/openmw/mwworld/worldimp.cpp | 14 ++++++++------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index a9c9884d58..b7e9f5730c 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -54,17 +54,12 @@ void Actors::insertBegin(const MWWorld::Ptr &ptr) // Convert MW rotation to a quaternion: f = ptr.getCellRef().getPosition().rot; - // Rotate around X axis - Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X); - - // Rotate around Y axis - Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y); - - // Rotate around Z axis + // For rendering purposes, actors should only rotate around the Z axis. + // X rotation is used for camera rotation (for the player) and for + // ranged magic / ranged weapon aiming. Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z); - // Rotates first around z, then y, then x - insert->setOrientation(xr*yr*zr); + insert->setOrientation(zr); ptr.getRefData().setBaseNode(insert); } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 43153612d7..435ca8b367 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1116,13 +1116,15 @@ namespace MWWorld while(ptr.getRefData().getLocalRotation().rot[2]<=-fullRotateRad) ptr.getRefData().getLocalRotation().rot[2]+=fullRotateRad; - Ogre::Quaternion worldRotQuat(Ogre::Quaternion(Ogre::Radian(ptr.getRefData().getPosition().rot[0]), Ogre::Vector3::NEGATIVE_UNIT_X)* - Ogre::Quaternion(Ogre::Radian(ptr.getRefData().getPosition().rot[1]), Ogre::Vector3::NEGATIVE_UNIT_Y)* - Ogre::Quaternion(Ogre::Radian(ptr.getRefData().getPosition().rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z)); + Ogre::Quaternion worldRotQuat(Ogre::Radian(ptr.getRefData().getPosition().rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z); + if (!ptr.getClass().isActor()) + worldRotQuat = Ogre::Quaternion(Ogre::Radian(ptr.getRefData().getPosition().rot[0]), Ogre::Vector3::NEGATIVE_UNIT_X)* + Ogre::Quaternion(Ogre::Radian(ptr.getRefData().getPosition().rot[1]), Ogre::Vector3::NEGATIVE_UNIT_Y)* worldRotQuat; - Ogre::Quaternion rot(Ogre::Quaternion(Ogre::Degree(x), Ogre::Vector3::NEGATIVE_UNIT_X)* - Ogre::Quaternion(Ogre::Degree(y), Ogre::Vector3::NEGATIVE_UNIT_Y)* - Ogre::Quaternion(Ogre::Degree(z), Ogre::Vector3::NEGATIVE_UNIT_Z)); + Ogre::Quaternion rot(Ogre::Degree(z), Ogre::Vector3::NEGATIVE_UNIT_Z); + if (!ptr.getClass().isActor()) + rot = Ogre::Quaternion(Ogre::Degree(x), Ogre::Vector3::NEGATIVE_UNIT_X)* + Ogre::Quaternion(Ogre::Degree(y), Ogre::Vector3::NEGATIVE_UNIT_Y)*rot; ptr.getRefData().getBaseNode()->setOrientation(worldRotQuat*rot); mPhysics->rotateObject(ptr); From 4caa8c5ccaa31324c08b40a045f372e6fc2a5745 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 26 May 2014 20:37:12 +0200 Subject: [PATCH 65/82] Fix offset to accumulation root not being cleared when adding an animation state with startpoint=1.f (observed with death animations) --- apps/openmw/mwrender/animation.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 9124e89b88..a2f901b26a 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -775,11 +775,11 @@ void Animation::play(const std::string &groupname, int priority, int groups, boo } /* Look in reverse; last-inserted source has priority. */ + AnimState state; AnimSourceList::reverse_iterator iter(mAnimSources.rbegin()); for(;iter != mAnimSources.rend();++iter) { const NifOgre::TextKeyMap &textkeys = (*iter)->mTextKeys; - AnimState state; if(reset(state, textkeys, groupname, start, stop, startpoint)) { state.mSource = *iter; @@ -821,6 +821,13 @@ void Animation::play(const std::string &groupname, int priority, int groups, boo std::cerr<< "Failed to find animation "<setPosition(-mNonAccumCtrl->getTranslation(state.mTime)*mAccumulate); + } } bool Animation::isPlaying(const std::string &groupname) const From cf68f6da96ad4d3be5137f39e6888f25d253019e Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 00:06:34 +0200 Subject: [PATCH 66/82] Fix ESX dependencies not being checked except for the first one --- apps/openmw/mwworld/esmstore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index fc2bd4d773..03d928d2a5 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -33,12 +33,12 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) // Cache parent esX files by tracking their indices in the global list of // all files/readers used by the engine. This will greaty accelerate // refnumber mangling, as required for handling moved references. - int index = ~0; const std::vector &masters = esm.getGameFiles(); std::vector *allPlugins = esm.getGlobalReaderList(); for (size_t j = 0; j < masters.size(); j++) { ESM::Header::MasterData &mast = const_cast(masters[j]); std::string fname = mast.name; + int index = ~0; for (int i = 0; i < esm.getIndex(); i++) { const std::string &candidate = allPlugins->at(i).getContext().filename; std::string fnamecandidate = boost::filesystem::path(candidate).filename().string(); From beba58268ce2374e10a0935f540686c814563cad Mon Sep 17 00:00:00 2001 From: Kevin Poitra Date: Tue, 27 May 2014 01:47:57 -0500 Subject: [PATCH 67/82] Fix a typo within the launcher. Fixes bug #1058. --- apps/launcher/maindialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index fb4c09b918..41d662d30b 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -806,7 +806,7 @@ void Launcher::MainDialog::play() msgBox.setWindowTitle(tr("No game file selected")); msgBox.setIcon(QMessageBox::Warning); msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
You do not have no game file selected.

\ + msgBox.setText(tr("
You do not have a game file selected.

\ OpenMW will not start without a game file selected.
")); msgBox.exec(); return; From d3357cc279d1ab96096648454cbb3aa8f12beaee Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Tue, 27 May 2014 13:27:18 +0200 Subject: [PATCH 68/82] The MSVC linker is really pedantic with this. Functions compiled as taking a class can't be linked with functions giving a struct, because of the name mangling I'm guessing... unresolved external symbol "protected: void __thiscall MWWorld::LiveCellRefBase::loadImp(class ESM::ObjectState const &)" (?loadImp@LiveCellRefBase@MWWorld@@IAEXABVObjectState@ESM@@@Z) --- apps/openmw/mwworld/cellref.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index 3b0c2251be..4db362b1e0 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -5,7 +5,7 @@ namespace ESM { - class ObjectState; + struct ObjectState; } namespace MWWorld From 578adb4ef6700d4dc812190b9b285739468fe4d5 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 13:54:25 +0200 Subject: [PATCH 69/82] PcJoinFaction and friends: make sure the given faction exists --- apps/openmw/mwscript/statsextensions.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index d9c9e5e0b3..8b61237a1d 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -541,6 +541,9 @@ namespace MWScript runtime.pop(); } ::Misc::StringUtils::toLower(factionID); + // Make sure this faction exists + MWBase::Environment::get().getWorld()->getStore().get().find(factionID); + if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -572,6 +575,9 @@ namespace MWScript runtime.pop(); } ::Misc::StringUtils::toLower(factionID); + // Make sure this faction exists + MWBase::Environment::get().getWorld()->getStore().get().find(factionID); + if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -607,6 +613,9 @@ namespace MWScript runtime.pop(); } ::Misc::StringUtils::toLower(factionID); + // Make sure this faction exists + MWBase::Environment::get().getWorld()->getStore().get().find(factionID); + if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); @@ -645,6 +654,9 @@ namespace MWScript } } ::Misc::StringUtils::toLower(factionID); + // Make sure this faction exists + MWBase::Environment::get().getWorld()->getStore().get().find(factionID); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); if(factionID!="") { From ad911d4d033926965ed593ede3db3ec6ad6d5782 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Tue, 27 May 2014 22:09:08 +1000 Subject: [PATCH 70/82] MSVC generates different symbols for class vs struct, confusing the linker. --- apps/openmw/mwworld/cellref.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index 3b0c2251be..4db362b1e0 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -5,7 +5,7 @@ namespace ESM { - class ObjectState; + struct ObjectState; } namespace MWWorld From e266c39c5d831a45be5fa9e6df7eef2e11ea925d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 14:54:29 +0200 Subject: [PATCH 71/82] Implement modFactionReaction instruction (Closes #1347) --- apps/openmw/mwbase/dialoguemanager.hpp | 6 +++ apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 37 +++++++++++++++++++ apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 11 ++++++ apps/openmw/mwdialogue/filter.cpp | 15 ++++---- .../mwmechanics/mechanicsmanagerimp.cpp | 27 ++++++-------- apps/openmw/mwscript/dialogueextensions.cpp | 19 ++++++++++ apps/openmw/mwscript/docs/vmformat.txt | 3 +- components/compiler/extensions0.cpp | 1 + components/compiler/opcodes.hpp | 1 + components/esm/dialoguestate.cpp | 30 ++++++++++++++- components/esm/dialoguestate.hpp | 5 ++- components/esm/loadfact.cpp | 14 +++---- components/esm/loadfact.hpp | 11 ++---- 13 files changed, 138 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index f51fba07b7..cab6809aa0 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -68,6 +68,12 @@ namespace MWBase virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const = 0; virtual void readRecord (ESM::ESMReader& reader, int32_t type) = 0; + + /// Changes faction1's opinion of faction2 by \a diff. + virtual void modFactionReaction (const std::string& faction1, const std::string& faction2, int diff) = 0; + + /// @return faction1's opinion of faction2 + virtual int getFactionReaction (const std::string& faction1, const std::string& faction2) const = 0; }; } diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index c7e832e4ab..3ca2b8345f 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -642,6 +642,8 @@ namespace MWDialogue if (iter->second) state.mKnownTopics.push_back (iter->first); + state.mModFactionReaction = mModFactionReaction; + writer.startRecord (ESM::REC_DIAS); state.save (writer); writer.endRecord (ESM::REC_DIAS); @@ -661,9 +663,44 @@ namespace MWDialogue iter!=state.mKnownTopics.end(); ++iter) if (store.get().search (*iter)) mKnownTopics.insert (std::make_pair (*iter, true)); + + mModFactionReaction = state.mModFactionReaction; } } + void DialogueManager::modFactionReaction(const std::string &faction1, const std::string &faction2, int diff) + { + std::string fact1 = Misc::StringUtils::lowerCase(faction1); + std::string fact2 = Misc::StringUtils::lowerCase(faction2); + + // Make sure the factions exist + MWBase::Environment::get().getWorld()->getStore().get().find(fact1); + MWBase::Environment::get().getWorld()->getStore().get().find(fact2); + + std::map& map = mModFactionReaction[fact1]; + if (map.find(fact2) == map.end()) + map[fact2] = 0; + map[fact2] += diff; + } + + int DialogueManager::getFactionReaction(const std::string &faction1, const std::string &faction2) const + { + std::string fact1 = Misc::StringUtils::lowerCase(faction1); + std::string fact2 = Misc::StringUtils::lowerCase(faction2); + + ModFactionReactionMap::const_iterator map = mModFactionReaction.find(fact1); + int diff = 0; + if (map != mModFactionReaction.end() && map->second.find(fact2) != map->second.end()) + diff = map->second.at(fact2); + + const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(fact1); + + std::map::const_iterator it = faction->mReactions.find(fact2); + if (it == faction->mReactions.end()) + return diff; + else + return it->second + diff; + } std::vector ParseHyperText(const std::string& text) { diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 6cd2c75afb..db0b78d594 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -24,6 +24,11 @@ namespace MWDialogue { std::map mDialogueMap; std::map mKnownTopics;// Those are the topics the player knows. + + // Modified faction reactions. > + typedef std::map > ModFactionReactionMap; + ModFactionReactionMap mModFactionReaction; + std::list mActorKnownTopics; Translation::Storage& mTranslationDataStorage; @@ -86,6 +91,12 @@ namespace MWDialogue virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const; virtual void readRecord (ESM::ESMReader& reader, int32_t type); + + /// Changes faction1's opinion of faction2 by \a diff. + virtual void modFactionReaction (const std::string& faction1, const std::string& faction2, int diff); + + /// @return faction1's opinion of faction2 + virtual int getFactionReaction (const std::string& faction1, const std::string& faction2) const; }; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 3d67f3bce0..d301e88aac 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -396,16 +396,15 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con int value = 0; - const ESM::Faction& faction = - *MWBase::Environment::get().getWorld()->getStore().get().find (factionId); - MWMechanics::NpcStats& playerStats = player.getClass().getNpcStats (player); - for (std::vector::const_iterator iter (faction.mReactions.begin()); - iter!=faction.mReactions.end(); ++iter) - if (playerStats.getFactionRanks().find (iter->mFaction)!=playerStats.getFactionRanks().end()) - if (low ? iter->mReactionmReaction>value) - value = iter->mReaction; + std::map::const_iterator playerFactionIt = playerStats.getFactionRanks().begin(); + for (; playerFactionIt != playerStats.getFactionRanks().end(); ++playerFactionIt) + { + int reaction = MWBase::Environment::get().getDialogueManager()->getFactionReaction(factionId, playerFactionIt->first); + if (low ? reaction < value : reaction > value) + value = reaction; + } return value; } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 1ea4be8432..1f9846aa71 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -498,27 +498,24 @@ namespace MWMechanics if (playerStats.getFactionRanks().find(npcFaction) != playerStats.getFactionRanks().end()) { - for(std::vector::const_iterator it = MWBase::Environment::get().getWorld()->getStore().get().find(npcFaction)->mReactions.begin(); - it != MWBase::Environment::get().getWorld()->getStore().get().find(npcFaction)->mReactions.end(); ++it) + if (!playerStats.getExpelled(npcFaction)) { - if(Misc::StringUtils::ciEqual(it->mFaction, npcFaction) - && !playerStats.getExpelled(it->mFaction)) - reaction = it->mReaction; + reaction = playerStats.getFactionReputation(npcFaction); + + rank = playerStats.getFactionRanks().find(npcFaction)->second; } - rank = playerStats.getFactionRanks().find(npcFaction)->second; } - else if (npcFaction != "") + else if (!npcFaction.empty()) { - for(std::vector::const_iterator it = MWBase::Environment::get().getWorld()->getStore().get().find(npcFaction)->mReactions.begin(); - it != MWBase::Environment::get().getWorld()->getStore().get().find(npcFaction)->mReactions.end();++it) + std::map::const_iterator playerFactionIt = playerStats.getFactionRanks().begin(); + for (; playerFactionIt != playerStats.getFactionRanks().end(); ++playerFactionIt) { - if(playerStats.getFactionRanks().find(Misc::StringUtils::lowerCase(it->mFaction)) != playerStats.getFactionRanks().end() ) - { - if(it->mReaction < reaction) - reaction = it->mReaction; - } + std::string itFaction = playerFactionIt->first; + + int itReaction = MWBase::Environment::get().getDialogueManager()->getFactionReaction(npcFaction, itFaction); + if (playerFactionIt == playerStats.getFactionRanks().begin() || itReaction < reaction) + reaction = itReaction; } - rank = 0; } else { diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index 047c4d92fa..19f6ca2df4 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -196,6 +196,24 @@ namespace MWScript } }; + class OpModFactionReaction : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + std::string faction1 = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + int modReaction = runtime[0].mInteger; + runtime.pop(); + + MWBase::Environment::get().getDialogueManager()->modFactionReaction(faction1, faction2, modReaction); + } + }; void installOpcodes (Interpreter::Interpreter& interpreter) { @@ -215,6 +233,7 @@ namespace MWScript interpreter.installSegment5 (Compiler::Dialogue::opcodeGetReputationExplicit, new OpGetReputation); interpreter.installSegment5 (Compiler::Dialogue::opcodeSameFaction, new OpSameFaction); interpreter.installSegment5 (Compiler::Dialogue::opcodeSameFactionExplicit, new OpSameFaction); + interpreter.installSegment5 (Compiler::Dialogue::opcodeModFactionReaction, new OpModFactionReaction); } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index bf2273b17e..f81cfb460c 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -390,5 +390,6 @@ op 0x200023e: GetPcInJail op 0x200023f: GetPcTraveling op 0x2000240: onKnockout op 0x2000241: onKnockoutExplicit +op 0x2000242: ModFactionReaction -opcodes 0x2000242-0x3ffffff unused +opcodes 0x2000243-0x3ffffff unused diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index db1ac16095..24e875173a 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -179,6 +179,7 @@ namespace Compiler opcodeGetReputationExplicit); extensions.registerFunction("samefaction", 'l', "", opcodeSameFaction, opcodeSameFactionExplicit); + extensions.registerInstruction("modfactionreaction", "ccl", opcodeModFactionReaction); } } diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index 9e36cb68d7..381a052ac2 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -152,6 +152,7 @@ namespace Compiler const int opcodeGetReputationExplicit = 0x20001b2; const int opcodeSameFaction = 0x20001b5; const int opcodeSameFactionExplicit = 0x20001b6; + const int opcodeModFactionReaction = 0x2000242; } namespace Gui diff --git a/components/esm/dialoguestate.cpp b/components/esm/dialoguestate.cpp index b3544c85ce..14301ac198 100644 --- a/components/esm/dialoguestate.cpp +++ b/components/esm/dialoguestate.cpp @@ -8,6 +8,20 @@ void ESM::DialogueState::load (ESMReader &esm) { while (esm.isNextSub ("TOPI")) mKnownTopics.push_back (esm.getHString()); + + while (esm.isNextSub ("FACT")) + { + std::string faction = esm.getHString(); + + while (esm.isNextSub ("REAC")) + { + std::string faction2 = esm.getHString(); + int reaction; + esm.getHNT(reaction, "INTV"); + + mModFactionReaction[faction][faction2] = reaction; + } + } } void ESM::DialogueState::save (ESMWriter &esm) const @@ -16,6 +30,18 @@ void ESM::DialogueState::save (ESMWriter &esm) const iter!=mKnownTopics.end(); ++iter) { esm.writeHNString ("TOPI", *iter); - } -} \ No newline at end of file + + for (std::map >::const_iterator iter = mModFactionReaction.begin(); + iter != mModFactionReaction.end(); ++iter) + { + esm.writeHNString ("FACT", iter->first); + + for (std::map::const_iterator reactIter = iter->second.begin(); + reactIter != iter->second.end(); ++reactIter) + { + esm.writeHNString ("REAC", reactIter->first); + esm.writeHNT ("INTV", reactIter->second); + } + } +} diff --git a/components/esm/dialoguestate.hpp b/components/esm/dialoguestate.hpp index 9aa9eaefd3..5e5f602a30 100644 --- a/components/esm/dialoguestate.hpp +++ b/components/esm/dialoguestate.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -15,9 +16,11 @@ namespace ESM { std::vector mKnownTopics; + std::map > mModFactionReaction; + void load (ESMReader &esm); void save (ESMWriter &esm) const; }; } -#endif \ No newline at end of file +#endif diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 84be21938b..0924efb174 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -44,10 +44,10 @@ void Faction::load(ESMReader &esm) // Read faction response values while (esm.hasMoreSubs()) { - Reaction r; - r.mFaction = esm.getHNString("ANAM"); - esm.getHNT(r.mReaction, "INTV"); - mReactions.push_back(r); + std::string faction = esm.getHNString("ANAM"); + int reaction; + esm.getHNT(reaction, "INTV"); + mReactions[faction] = reaction; } } void Faction::save(ESMWriter &esm) const @@ -64,10 +64,10 @@ void Faction::save(ESMWriter &esm) const esm.writeHNT("FADT", mData, 240); - for (std::vector::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it) + for (std::map::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it) { - esm.writeHNString("ANAM", it->mFaction); - esm.writeHNT("INTV", it->mReaction); + esm.writeHNString("ANAM", it->first); + esm.writeHNT("INTV", it->second); } } diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 9c257e068e..75e30a5bf1 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -2,7 +2,7 @@ #define OPENMW_ESM_FACT_H #include -#include +#include namespace ESM { @@ -53,13 +53,8 @@ struct Faction FADTstruct mData; - struct Reaction - { - std::string mFaction; - int mReaction; - }; - - std::vector mReactions; + // + std::map mReactions; // Name of faction ranks (may be empty for NPC factions) std::string mRanks[10]; From 3e2eed92695405eae7372cf64fea18acd0af7abe Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 15:23:22 +0200 Subject: [PATCH 72/82] Implement getFactionReaction function Strange bug when using value != 0 for the garbage argument? --- apps/openmw/mwscript/dialogueextensions.cpp | 22 +++++++++++++++++++++ apps/openmw/mwscript/docs/vmformat.txt | 3 ++- components/compiler/extensions0.cpp | 1 + components/compiler/opcodes.hpp | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index 19f6ca2df4..9dde65ab2c 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -215,6 +215,27 @@ namespace MWScript } }; + class OpGetFactionReaction : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + std::string faction1 = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + // ignore extra garbage argument + runtime.pop(); + + runtime.push(MWBase::Environment::get().getDialogueManager() + ->getFactionReaction(faction1, faction2)); + } + }; + + void installOpcodes (Interpreter::Interpreter& interpreter) { interpreter.installSegment5 (Compiler::Dialogue::opcodeJournal, new OpJournal); @@ -234,6 +255,7 @@ namespace MWScript interpreter.installSegment5 (Compiler::Dialogue::opcodeSameFaction, new OpSameFaction); interpreter.installSegment5 (Compiler::Dialogue::opcodeSameFactionExplicit, new OpSameFaction); interpreter.installSegment5 (Compiler::Dialogue::opcodeModFactionReaction, new OpModFactionReaction); + interpreter.installSegment5 (Compiler::Dialogue::opcodeGetFactionReaction, new OpGetFactionReaction); } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index f81cfb460c..53c80a943b 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -391,5 +391,6 @@ op 0x200023f: GetPcTraveling op 0x2000240: onKnockout op 0x2000241: onKnockoutExplicit op 0x2000242: ModFactionReaction +op 0x2000243: GetFactionReaction -opcodes 0x2000243-0x3ffffff unused +opcodes 0x2000244-0x3ffffff unused diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index 24e875173a..4ef638ef83 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -180,6 +180,7 @@ namespace Compiler extensions.registerFunction("samefaction", 'l', "", opcodeSameFaction, opcodeSameFactionExplicit); extensions.registerInstruction("modfactionreaction", "ccl", opcodeModFactionReaction); + extensions.registerFunction("getfactionreaction", 'l', "ccl", opcodeGetFactionReaction); } } diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index 381a052ac2..1dff046652 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -153,6 +153,7 @@ namespace Compiler const int opcodeSameFaction = 0x20001b5; const int opcodeSameFactionExplicit = 0x20001b6; const int opcodeModFactionReaction = 0x2000242; + const int opcodeGetFactionReaction = 0x2000243; } namespace Gui From 49a6579d3a9bce5d36530769af654ef792d7bf6e Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 15:37:04 +0200 Subject: [PATCH 73/82] Fixed esmtool --- apps/esmtool/record.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index fd4b97acb9..bcf16091f4 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -707,9 +707,9 @@ void Record::print() std::cout << " Faction Reaction: " << mData.mData.mRankData[i].mFactReaction << std::endl; } - std::vector::iterator rit; + std::map::iterator rit; for (rit = mData.mReactions.begin(); rit != mData.mReactions.end(); rit++) - std::cout << " Reaction: " << rit->mReaction << " = " << rit->mFaction << std::endl; + std::cout << " Reaction: " << rit->second << " = " << rit->first << std::endl; } template<> From f476aa4ade40a21e39d8a555580bebf66b3b4e84 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 17:07:14 +0200 Subject: [PATCH 74/82] Remove MyGUI color codes when copying to system clipboard --- apps/openmw/mwinput/inputmanagerimp.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index cf71cc1aa4..8cfe2c2b31 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -492,7 +492,8 @@ namespace MWInput } if (arg.keysym.sym == SDLK_x && (arg.keysym.mod & SDL_Keymod(KMOD_CTRL))) { - std::string text = edit->getTextSelection(); + // Discard color codes and other escape characters + std::string text = MyGUI::TextIterator::getOnlyText(edit->getTextSelection()); if (text.length()) { SDL_SetClipboardText(text.c_str()); @@ -504,7 +505,8 @@ namespace MWInput { if (arg.keysym.sym == SDLK_c && (arg.keysym.mod & SDL_Keymod(KMOD_CTRL))) { - std::string text = edit->getTextSelection(); + // Discard color codes and other escape characters + std::string text = MyGUI::TextIterator::getOnlyText(edit->getTextSelection()); if (text.length()) SDL_SetClipboardText(text.c_str()); } From 2fe86f2b85aa9a29f8a0d80b8982c97afc643b57 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 17:39:04 +0200 Subject: [PATCH 75/82] Consider hit normal for item drop test (Fixes #995) --- apps/openmw/mwworld/physicssystem.cpp | 4 ++-- apps/openmw/mwworld/physicssystem.hpp | 5 +++-- apps/openmw/mwworld/worldimp.cpp | 13 ++++++++----- libs/openengine/bullet/physic.cpp | 8 ++++++-- libs/openengine/bullet/physic.hpp | 4 +++- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index b8f0f8699b..e93d9e640f 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -492,7 +492,7 @@ namespace MWWorld return std::make_pair(true, ray.getPoint(len * test.second)); } - std::pair PhysicsSystem::castRay(float mouseX, float mouseY) + std::pair PhysicsSystem::castRay(float mouseX, float mouseY, Ogre::Vector3* normal) { Ogre::Ray ray = mRender.getCamera()->getCameraToViewportRay( mouseX, @@ -504,7 +504,7 @@ namespace MWWorld _from = btVector3(from.x, from.y, from.z); _to = btVector3(to.x, to.y, to.z); - std::pair result = mEngine->rayTest(_from, _to); + std::pair result = mEngine->rayTest(_from, _to, true, false, normal); if (result.first == "") return std::make_pair(false, Ogre::Vector3()); diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 3dcd088f54..899d7144d9 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -70,8 +70,9 @@ namespace MWWorld std::pair castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len); - std::pair castRay(float mouseX, float mouseY); - ///< cast ray from the mouse, return true if it hit something and the first result (in OGRE coordinates) + std::pair castRay(float mouseX, float mouseY, Ogre::Vector3* normal = NULL); + ///< cast ray from the mouse, return true if it hit something and the first result + /// @param normal if non-NULL, the hit normal will be written there (if there is a hit) OEngine::Physic::PhysicEngine* getEngine(); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 435ca8b367..fdc2031823 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1620,13 +1620,16 @@ namespace MWWorld bool World::canPlaceObject(float cursorX, float cursorY) { - std::pair result = mPhysics->castRay(cursorX, cursorY); + Ogre::Vector3 normal(0,0,0); + std::pair result = mPhysics->castRay(cursorX, cursorY, &normal); - /// \todo also check if the wanted position is on a flat surface, and not e.g. against a vertical wall! - - if (!result.first) + if (result.first) + { + // check if the wanted position is on a flat surface, and not e.g. against a vertical wall + return (normal.angleBetween(Ogre::Vector3(0.f,0.f,1.f)).valueDegrees() < 30); + } + else return false; - return true; } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 6646ce2738..235300b438 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -677,7 +677,7 @@ namespace Physic { } - std::pair PhysicEngine::rayTest(btVector3& from,btVector3& to,bool raycastingObjectOnly,bool ignoreHeightMap) + std::pair PhysicEngine::rayTest(btVector3& from,btVector3& to,bool raycastingObjectOnly,bool ignoreHeightMap, Ogre::Vector3* normal) { std::string name = ""; float d = -1; @@ -694,7 +694,11 @@ namespace Physic if (resultCallback1.hasHit()) { name = static_cast(*resultCallback1.m_collisionObject).mName; - d = resultCallback1.m_closestHitFraction;; + d = resultCallback1.m_closestHitFraction; + if (normal) + *normal = Ogre::Vector3(resultCallback1.m_hitNormalWorld.x(), + resultCallback1.m_hitNormalWorld.y(), + resultCallback1.m_hitNormalWorld.z()); } return std::pair(name,d); diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 16eb453068..803986d5b7 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -308,8 +308,10 @@ namespace Physic /** * Return the closest object hit by a ray. If there are no objects, it will return ("",-1). + * If \a normal is non-NULL, the hit normal will be written there (if there is a hit) */ - std::pair rayTest(btVector3& from,btVector3& to,bool raycastingObjectOnly = true,bool ignoreHeightMap = false); + std::pair rayTest(btVector3& from,btVector3& to,bool raycastingObjectOnly = true, + bool ignoreHeightMap = false, Ogre::Vector3* normal = NULL); /** * Return all objects hit by a ray. From 2b15b85af1472a5565310b6eae2000242198e584 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 17:58:18 +0200 Subject: [PATCH 76/82] Fix position adjustment not working properly for rotated objects --- apps/openmw/mwworld/worldimp.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index fdc2031823..38edd8b8d6 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1635,13 +1635,24 @@ namespace MWWorld Ptr World::copyObjectToCell(const Ptr &object, CellStore* cell, ESM::Position pos, bool adjustPos) { - if (object.getClass().isActor() || adjustPos) + if (!object.getClass().isActor() && adjustPos) { + // Adjust position so the location we wanted ends up in the middle of the object bounding box Ogre::Vector3 min, max; if (mPhysics->getObjectAABB(object, min, max)) { - pos.pos[0] -= (min.x + max.x) / 2; - pos.pos[1] -= (min.y + max.y) / 2; - pos.pos[2] -= min.z; + Ogre::Quaternion xr(Ogre::Radian(-pos.rot[0]), Ogre::Vector3::UNIT_X); + Ogre::Quaternion yr(Ogre::Radian(-pos.rot[1]), Ogre::Vector3::UNIT_Y); + Ogre::Quaternion zr(Ogre::Radian(-pos.rot[2]), Ogre::Vector3::UNIT_Z); + + Ogre::Vector3 adjust ( + (min.x + max.x) / 2, + (min.y + max.y) / 2, + min.z + ); + adjust = (xr*yr*zr) * adjust; + pos.pos[0] -= adjust.x; + pos.pos[1] -= adjust.y; + pos.pos[2] -= adjust.z; } } From 0b45a9e6b25865143f686d5738ea45faab269e0f Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 27 May 2014 19:02:48 +0200 Subject: [PATCH 77/82] Fix case folding for faction reaction from ESX records --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 3ca2b8345f..b6cef2fe7f 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -695,11 +695,13 @@ namespace MWDialogue const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(fact1); - std::map::const_iterator it = faction->mReactions.find(fact2); - if (it == faction->mReactions.end()) - return diff; - else - return it->second + diff; + std::map::const_iterator it = faction->mReactions.begin(); + for (; it != faction->mReactions.end(); ++it) + { + if (Misc::StringUtils::ciEqual(it->first, fact2)) + return it->second + diff; + } + return diff; } std::vector ParseHyperText(const std::string& text) From 12fc0aaecb856e4dd7966801bbdc6ebb36558e7a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 27 May 2014 21:08:29 +0200 Subject: [PATCH 78/82] removed an unused parser settings (implicitly fixing a case were this setting was not applied correctly) --- components/compiler/exprparser.cpp | 18 +++++------------- components/compiler/exprparser.hpp | 2 +- components/compiler/lineparser.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 0c013b18f1..90a294c0c6 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -730,7 +730,7 @@ namespace Compiler } int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner, - std::vector& code, bool invert) + std::vector& code) { bool optional = false; int optionalCount = 0; @@ -762,15 +762,10 @@ namespace Compiler if (*iter!='x') { - if (invert) - { - std::vector tmp; - stringParser.append (tmp); + std::vector tmp; + stringParser.append (tmp); - stack.push (tmp); - } - else - stringParser.append (code); + stack.push (tmp); if (optional) ++optionalCount; @@ -795,10 +790,7 @@ namespace Compiler if (type!=*iter) Generator::convert (tmp, type, *iter); - if (invert) - stack.push (tmp); - else - std::copy (tmp.begin(), tmp.end(), std::back_inserter (code)); + stack.push (tmp); if (optional) ++optionalCount; diff --git a/components/compiler/exprparser.hpp b/components/compiler/exprparser.hpp index 93e0d1c366..e4e385ff0f 100644 --- a/components/compiler/exprparser.hpp +++ b/components/compiler/exprparser.hpp @@ -96,7 +96,7 @@ namespace Compiler /// \return Type ('l': integer, 'f': float) int parseArguments (const std::string& arguments, Scanner& scanner, - std::vector& code, bool invert = false); + std::vector& code); ///< Parse sequence of arguments specified by \a arguments. /// \param arguments Uses ScriptArgs typedef /// \see Compiler::ScriptArgs diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 98bd63ba1e..f7d2726e35 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -166,7 +166,7 @@ namespace Compiler if (!arguments.empty()) { mExprParser.reset(); - mExprParser.parseArguments (arguments, scanner, mCode, true); + mExprParser.parseArguments (arguments, scanner, mCode); } mName = name; @@ -278,7 +278,7 @@ namespace Compiler mExplicit.clear(); } - int optionals = mExprParser.parseArguments (argumentType, scanner, mCode, true); + int optionals = mExprParser.parseArguments (argumentType, scanner, mCode); extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit, optionals); mState = EndState; @@ -363,14 +363,14 @@ namespace Compiler case Scanner::K_startscript: - mExprParser.parseArguments ("c", scanner, mCode, true); + mExprParser.parseArguments ("c", scanner, mCode); Generator::startScript (mCode); mState = EndState; return true; case Scanner::K_stopscript: - mExprParser.parseArguments ("c", scanner, mCode, true); + mExprParser.parseArguments ("c", scanner, mCode); Generator::stopScript (mCode); mState = EndState; return true; From 9be219beba07bdd274fb9a80029827e147d36051 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Tue, 27 May 2014 22:09:37 -0400 Subject: [PATCH 79/82] Fixes Bug #1348 "Evidence Chest unlocking when arrested." --- apps/openmw/mwworld/worldimp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 38edd8b8d6..c95a137ecc 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2542,7 +2542,7 @@ namespace MWWorld store.remove(*it, it->getRefData().getCount(), ptr); } } - closestChest.getClass().unlock(closestChest); + closestChest.getClass().lock(closestChest,50); } } From 50a4d175da4fad6aa428a59839db157614c8fa3b Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Wed, 28 May 2014 03:42:26 -0400 Subject: [PATCH 80/82] Read NIF interpolation type 4 (XYZ_ROTATION_KEY) Don't actually do anything with it yet, but without this the "MW Containers Animated" mod made containers inaccessible. Partly implements Feature #1067 --- components/nif/niffile.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/components/nif/niffile.hpp b/components/nif/niffile.hpp index d4b042726f..77e0acb9e5 100644 --- a/components/nif/niffile.hpp +++ b/components/nif/niffile.hpp @@ -155,6 +155,7 @@ struct KeyListT { static const int sLinearInterpolation = 1; static const int sQuadraticInterpolation = 2; static const int sTBCInterpolation = 3; + static const int sXYZInterpolation = 4; int mInterpolationType; VecType mKeys; @@ -199,6 +200,38 @@ struct KeyListT { key.mContinuity = nif->getFloat(); } } + //\FIXME This now reads the correct amount of data in the file, but doesn't actually do anything with it. + else if(mInterpolationType == sXYZInterpolation) + { + if (count != 1) + { + nif->file->fail("count should always be '1' for XYZ_ROTATION_KEY. Retrieved Value: "+Ogre::StringConverter::toString(count)); + return; + } + //KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html) + //Chomp unknown and possibly unused float + nif->getFloat(); + for(size_t i=0;i<3;++i) + { + unsigned int numKeys = nif->getInt(); + if(numKeys != 0) + { + int interpolationTypeAgain = nif->getInt(); + if( interpolationTypeAgain != sLinearInterpolation) + { + nif->file->fail("XYZ_ROTATION_KEY's KeyGroup keyType must be '1' (Linear Interpolation). Retrieved Value: "+Ogre::StringConverter::toString(interpolationTypeAgain)); + return; + } + for(size_t j = 0;j < numKeys;j++) + { + //For now just chomp these + nif->getFloat(); + nif->getFloat(); + } + } + nif->file->warn("XYZ_ROTATION_KEY read, but not used!"); + } + } else if (mInterpolationType == 0) { if (count != 0) From 3244f2197a03c51fdddc6cc4f3523bedad4fb5d0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 28 May 2014 11:13:23 +0200 Subject: [PATCH 81/82] updated credits file --- credits.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/credits.txt b/credits.txt index 6f0561490b..da54170345 100644 --- a/credits.txt +++ b/credits.txt @@ -17,6 +17,7 @@ Alex McKibben (WeirdSexy) Alexander Nadeau (wareya) Alexander Olofsson (Ace) Artem Kotsynyak (greye) +Arthur Moore (EmperorArthur) athile Britt Mathis (galdor557) BrotherBrick From bbe77d656a99031b2fbcc31391701c1aabbf53f8 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 28 May 2014 21:15:50 +1000 Subject: [PATCH 82/82] Minor fixes from static analysis. --- apps/esmtool/labels.cpp | 6 +++--- components/compiler/exprparser.cpp | 2 +- extern/shiny/Main/Factory.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/esmtool/labels.cpp b/apps/esmtool/labels.cpp index 7a42e6900f..ef45989efe 100644 --- a/apps/esmtool/labels.cpp +++ b/apps/esmtool/labels.cpp @@ -387,7 +387,7 @@ std::string magicEffectLabel(int idx) "sEffectSummonCreature04", "sEffectSummonCreature05" }; - if (idx >= 0 && idx <= 143) + if (idx >= 0 && idx <= 142) return magicEffectLabels[idx]; else return "Invalid"; @@ -471,7 +471,7 @@ std::string skillLabel(int idx) "Speechcraft", "Hand-to-hand" }; - if (idx >= 0 && idx <= 27) + if (idx >= 0 && idx <= 26) return skillLabels[idx]; else return "Invalid"; @@ -498,7 +498,7 @@ std::string rangeTypeLabel(int idx) "Touch", "Target" }; - if (idx >= 0 && idx <= 3) + if (idx >= 0 && idx <= 2) return rangeTypeLabels[idx]; else return "Invalid"; diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 90a294c0c6..ed628278b5 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -98,7 +98,7 @@ namespace Compiler else if (t1=='f' || t2=='f') mOperands.push_back ('f'); else - std::logic_error ("failed to determine result operand type"); + throw std::logic_error ("failed to determine result operand type"); } void ExprParser::pop() diff --git a/extern/shiny/Main/Factory.hpp b/extern/shiny/Main/Factory.hpp index 15c8599583..e8562011cb 100644 --- a/extern/shiny/Main/Factory.hpp +++ b/extern/shiny/Main/Factory.hpp @@ -206,7 +206,7 @@ namespace sh std::string getCacheFolder () { return mPlatform->getCacheFolder (); } bool getReadSourceCache() { return mReadSourceCache; } - bool getWriteSourceCache() { return mReadSourceCache; } + bool getWriteSourceCache() { return mWriteSourceCache; } public: bool getWriteMicrocodeCache() { return mWriteMicrocodeCache; } // Fixme