1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 07:23:52 +00:00

Merge remote-tracking branch 'potatoesmaster/importer' into next

Conflicts:
	apps/openmw/mwworld/worldimp.cpp
This commit is contained in:
Marc Zinnschlag 2013-02-06 10:12:40 +01:00
commit 43912f927a
4 changed files with 76 additions and 36 deletions

View file

@ -777,6 +777,39 @@ void MwIniImporter::insertMultistrmap(multistrmap &cfg, std::string key, std::st
cfg[key].push_back(value);
}
void MwIniImporter::importArchives(multistrmap &cfg, multistrmap &ini) {
std::vector<std::string> archives;
std::string baseArchive("Archives:Archive ");
std::string archive;
// Search archives listed in ini file
multistrmap::iterator it = ini.begin();
for(int i=0; it != ini.end(); i++) {
archive = baseArchive;
archive.append(this->numberToString(i));
it = ini.find(archive);
if(it == ini.end()) {
break;
}
for(std::vector<std::string>::iterator entry = it->second.begin(); entry!=it->second.end(); ++entry) {
archives.push_back(*entry);
}
}
cfg.erase("fallback-archive");
cfg.insert( std::make_pair<std::string, std::vector<std::string> > ("fallback-archive", std::vector<std::string>()));
// Add Morrowind.bsa by default, since Vanilla loads this archive even if it
// does not appears in the ini file
cfg["fallback-archive"].push_back("Morrowind.bsa");
for(std::vector<std::string>::iterator it=archives.begin(); it!=archives.end(); ++it) {
cfg["fallback-archive"].push_back(*it);
}
}
void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) {
std::vector<std::string> esmFiles;
std::vector<std::string> espFiles;
@ -794,7 +827,7 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) {
}
for(std::vector<std::string>::iterator entry = it->second.begin(); entry!=it->second.end(); ++entry) {
std::string filetype(entry->substr(entry->length()-4, 3));
std::string filetype(entry->substr(entry->length()-3));
Misc::StringUtils::toLower(filetype);
if(filetype.compare("esm") == 0) {

View file

@ -23,6 +23,7 @@ class MwIniImporter {
void merge(multistrmap &cfg, multistrmap &ini);
void mergeFallback(multistrmap &cfg, multistrmap &ini);
void importGameFiles(multistrmap &cfg, multistrmap &ini);
void importArchives(multistrmap &cfg, multistrmap &ini);
void writeToFile(boost::iostreams::stream<boost::iostreams::file_sink> &out, multistrmap &cfg);
private:

View file

@ -18,6 +18,7 @@ int main(int argc, char *argv[]) {
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
("game-files,g", "import esm and esp files")
("no-archives,A", "disable bsa archives import")
("encoding,e", bpo::value<std::string>()-> default_value("win1252"),
"Character encoding used in OpenMW game messages:\n"
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
@ -76,6 +77,10 @@ int main(int argc, char *argv[]) {
importer.importGameFiles(cfg, ini);
}
if(!vm.count("no-archives")) {
importer.importArchives(cfg, ini);
}
std::cout << "write to: " << outputFile << std::endl;
boost::iostreams::stream<boost::iostreams::file_sink> file(outputFile);
importer.writeToFile(file, cfg);

View file

@ -304,26 +304,26 @@ namespace MWWorld
{
return mGlobalVariables->getGlobals();
}
std::string World::getCurrentCellName () const
{
std::string name;
Ptr::CellStore *cell = mWorldScene->getCurrentCell();
if (cell->mCell->isExterior())
{
{
if (cell->mCell->mName != "")
{
{
name = cell->mCell->mName;
}
else
{
}
else
{
const ESM::Region* region =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(cell->mCell->mRegion);
if (region)
name = region->mName;
else
{
{
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
@ -333,13 +333,13 @@ namespace MWWorld
name = "Wilderness";
}
}
}
else
{
}
}
else
{
name = cell->mCell->mName;
}
}
return name;
}
@ -428,12 +428,12 @@ namespace MWWorld
if (!reference.getRefData().isEnabled())
{
reference.getRefData().enable();
if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
mWorldScene->addObjectToScene (reference);
}
}
void World::removeContainerScripts(const Ptr& reference)
{
if( reference.getTypeName()==typeid (ESM::Container).name() ||
@ -458,7 +458,7 @@ namespace MWWorld
if (reference.getRefData().isEnabled())
{
reference.getRefData().disable();
if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
mWorldScene->removeObjectFromScene (reference);
}
@ -689,13 +689,14 @@ namespace MWWorld
void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z)
{
ESM::Position &pos = ptr.getRefData().getPosition();
pos.pos[0] = x, pos.pos[1] = y, pos.pos[2] = z;
pos.pos[0] = x;
pos.pos[1] = y;
pos.pos[2] = z;
Ogre::Vector3 vec(x, y, z);
CellStore *currCell = ptr.getCell();
bool isPlayer = ptr == mPlayer->getPlayer();
bool haveToMove = mWorldScene->isCellActive(*currCell) || isPlayer;
if (*currCell != newCell)
{
@ -710,7 +711,8 @@ namespace MWWorld
int cellY = newCell.mCell->getGridY();
mWorldScene->changeCell(cellX, cellY, pos, false);
}
else {
else
{
if (!mWorldScene->isCellActive(*currCell))
copyObjectToCell(ptr, newCell, pos);
else if (!mWorldScene->isCellActive(newCell))
@ -718,6 +720,7 @@ namespace MWWorld
MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
mWorldScene->removeObjectFromScene(ptr);
mLocalScripts.remove(ptr);
removeContainerScripts (ptr);
haveToMove = false;
}
else
@ -725,10 +728,18 @@ namespace MWWorld
MWWorld::Ptr copy =
MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
addContainerScripts(copy, &newCell);
mRendering->moveObjectToCell(copy, vec, currCell);
std::string script =
MWWorld::Class::get(ptr).getScript(ptr);
if (!script.empty())
{
mLocalScripts.remove(ptr);
removeContainerScripts (ptr);
mLocalScripts.add(script, copy);
addContainerScripts (copy, &newCell);
}
if (MWWorld::Class::get(ptr).isActor())
{
MWBase::MechanicsManager *mechMgr =
@ -737,16 +748,6 @@ namespace MWWorld
mechMgr->removeActor(ptr);
mechMgr->addActor(copy);
}
else
{
std::string script =
MWWorld::Class::get(ptr).getScript(ptr);
if (!script.empty())
{
mLocalScripts.remove(ptr);
mLocalScripts.add(script, copy);
}
}
}
ptr.getRefData().setCount(0);
}
@ -1276,8 +1277,8 @@ namespace MWWorld
void World::PCDropped (const Ptr& item)
{
std::string script = MWWorld::Class::get(item).getScript(item);
// Set OnPCDrop Variable on item's script, if it has a script with that variable declared
// Set OnPCDrop Variable on item's script, if it has a script with that variable declared
if(script != "")
item.mRefData->getLocals().setVarByInt(script, "onpcdrop", 1);
}
@ -1307,7 +1308,7 @@ namespace MWWorld
Ptr dropped = copyObjectToCell(object, *cell, pos);
PCDropped(dropped);
object.getRefData().setCount(0);
return true;
}
@ -1322,7 +1323,7 @@ namespace MWWorld
return true;
}
Ptr World::copyObjectToCell(const Ptr &object, CellStore &cell, const ESM::Position &pos)
{
/// \todo add searching correct cell for position specified