cleaned up object movement and fixed a bug regarding local scripts

actorid
Marc Zinnschlag 12 years ago
parent cfceb45009
commit c409f1184e

@ -302,26 +302,26 @@ namespace MWWorld
{ {
return mGlobalVariables->getGlobals(); return mGlobalVariables->getGlobals();
} }
std::string World::getCurrentCellName () const std::string World::getCurrentCellName () const
{ {
std::string name; std::string name;
Ptr::CellStore *cell = mWorldScene->getCurrentCell(); Ptr::CellStore *cell = mWorldScene->getCurrentCell();
if (cell->mCell->isExterior()) if (cell->mCell->isExterior())
{ {
if (cell->mCell->mName != "") if (cell->mCell->mName != "")
{ {
name = cell->mCell->mName; name = cell->mCell->mName;
} }
else else
{ {
const ESM::Region* region = const ESM::Region* region =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(cell->mCell->mRegion); MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(cell->mCell->mRegion);
if (region) if (region)
name = region->mName; name = region->mName;
else else
{ {
const ESM::GameSetting *setting = const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname"); MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
@ -331,13 +331,13 @@ namespace MWWorld
name = "Wilderness"; name = "Wilderness";
} }
} }
} }
else else
{ {
name = cell->mCell->mName; name = cell->mCell->mName;
} }
return name; return name;
} }
@ -426,12 +426,12 @@ namespace MWWorld
if (!reference.getRefData().isEnabled()) if (!reference.getRefData().isEnabled())
{ {
reference.getRefData().enable(); reference.getRefData().enable();
if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end() && reference.getRefData().getCount()) if(mWorldScene->getActiveCells().find (reference.getCell()) != mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
mWorldScene->addObjectToScene (reference); mWorldScene->addObjectToScene (reference);
} }
} }
void World::removeContainerScripts(const Ptr& reference) void World::removeContainerScripts(const Ptr& reference)
{ {
if( reference.getTypeName()==typeid (ESM::Container).name() || if( reference.getTypeName()==typeid (ESM::Container).name() ||
@ -456,7 +456,7 @@ namespace MWWorld
if (reference.getRefData().isEnabled()) if (reference.getRefData().isEnabled())
{ {
reference.getRefData().disable(); reference.getRefData().disable();
if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end() && reference.getRefData().getCount()) if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
mWorldScene->removeObjectFromScene (reference); mWorldScene->removeObjectFromScene (reference);
} }
@ -687,14 +687,14 @@ namespace MWWorld
void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z) void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z)
{ {
ESM::Position &pos = ptr.getRefData().getPosition(); 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); Ogre::Vector3 vec(x, y, z);
CellStore *currCell = ptr.getCell(); CellStore *currCell = ptr.getCell();
bool isPlayer = ptr == mPlayer->getPlayer(); bool isPlayer = ptr == mPlayer->getPlayer();
bool haveToMove = mWorldScene->isCellActive(*currCell) || isPlayer; bool haveToMove = mWorldScene->isCellActive(*currCell) || isPlayer;
removeContainerScripts(ptr);
if (*currCell != newCell) if (*currCell != newCell)
{ {
@ -707,7 +707,8 @@ namespace MWWorld
int cellY = newCell.mCell->getGridY(); int cellY = newCell.mCell->getGridY();
mWorldScene->changeCell(cellX, cellY, pos, false); mWorldScene->changeCell(cellX, cellY, pos, false);
} }
else { else
{
if (!mWorldScene->isCellActive(*currCell)) if (!mWorldScene->isCellActive(*currCell))
copyObjectToCell(ptr, newCell, pos); copyObjectToCell(ptr, newCell, pos);
else if (!mWorldScene->isCellActive(newCell)) else if (!mWorldScene->isCellActive(newCell))
@ -715,6 +716,7 @@ namespace MWWorld
MWWorld::Class::get(ptr).copyToCell(ptr, newCell); MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
mWorldScene->removeObjectFromScene(ptr); mWorldScene->removeObjectFromScene(ptr);
mLocalScripts.remove(ptr); mLocalScripts.remove(ptr);
removeContainerScripts (ptr);
haveToMove = false; haveToMove = false;
} }
else else
@ -722,10 +724,18 @@ namespace MWWorld
MWWorld::Ptr copy = MWWorld::Ptr copy =
MWWorld::Class::get(ptr).copyToCell(ptr, newCell); MWWorld::Class::get(ptr).copyToCell(ptr, newCell);
addContainerScripts(copy, &newCell);
mRendering->moveObjectToCell(copy, vec, currCell); 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()) if (MWWorld::Class::get(ptr).isActor())
{ {
MWBase::MechanicsManager *mechMgr = MWBase::MechanicsManager *mechMgr =
@ -734,16 +744,6 @@ namespace MWWorld
mechMgr->removeActor(ptr); mechMgr->removeActor(ptr);
mechMgr->addActor(copy); 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); ptr.getRefData().setCount(0);
} }

Loading…
Cancel
Save