diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 60a7eb6e1a..51a46ec3c3 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -121,4 +121,111 @@ namespace MWWorld } } } + + /// \todo this whole code needs major clean up + void CellStore::insertObject(const Ptr &ptr) + { + std::string type = ptr.getTypeName(); + + MWWorld::Ptr newPtr; + + // insert into the correct CellRefList + if (type == typeid(ESM::Potion).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&potions.insert(*ref), cell); + } + else if (type == typeid(ESM::Apparatus).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&appas.insert(*ref), cell); + } + else if (type == typeid(ESM::Armor).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&armors.insert(*ref), cell); + } + else if (type == typeid(ESM::Book).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&books.insert(*ref), cell); + } + else if (type == typeid(ESM::Clothing).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&clothes.insert(*ref), cell); + } + else if (type == typeid(ESM::Ingredient).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&ingreds.insert(*ref), cell); + } + else if (type == typeid(ESM::Light).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&lights.insert(*ref), cell); + } + else if (type == typeid(ESM::Tool).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&lockpicks.insert(*ref), cell); + } + else if (type == typeid(ESM::Repair).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&repairs.insert(*ref), cell); + } + else if (type == typeid(ESM::Probe).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&probes.insert(*ref), cell); + } + else if (type == typeid(ESM::Weapon).name()) + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&weapons.insert(*ref), cell); + } + else if (type == typeid(ESM::Miscellaneous).name()) + { + + // if this is gold, we need to fetch the correct mesh depending on the amount of gold. + if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + int goldAmount = ptr.getRefData().getCount(); + + std::string base = "Gold_001"; + if (goldAmount >= 100) + base = "Gold_100"; + else if (goldAmount >= 25) + base = "Gold_025"; + else if (goldAmount >= 10) + base = "Gold_010"; + else if (goldAmount >= 5) + base = "Gold_005"; + + MWWorld::ManualRef newRef (MWBase::Environment::get().getWorld()->getStore(), base); + + MWWorld::LiveCellRef* ref = + newRef.getPtr().get(); + + newPtr = MWWorld::Ptr(&miscItems.insert(*ref), cell); + + ESM::Position& p = newPtr.getRefData().getPosition(); + p.pos[0] = ptr.getRefData().getPosition().pos[0]; + p.pos[1] = ptr.getRefData().getPosition().pos[1]; + p.pos[2] = ptr.getRefData().getPosition().pos[2]; + } + else + { + MWWorld::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(&miscItems.insert(*ref), cell); + } + } + else + throw std::runtime_error("Trying to insert object of unhandled type"); + + newPtr.getRefData().setCount(ptr.getRefData().getCount()); + ptr.getRefData().setCount(0); + newPtr.getRefData().enable(); + } } diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index de3ac12ae5..89724bca42 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -7,6 +7,7 @@ #include #include "refdata.hpp" +#include "ptr.hpp" namespace ESMS { @@ -63,6 +64,11 @@ namespace MWWorld list.push_back(LiveRef(ref, obj)); } + const LiveRef &insert(LiveRef &item) { + list.push_back(item); + return list.back(); + } + LiveRef *find (const std::string& name) { for (typename std::list::iterator iter (list.begin()); iter!=list.end(); ++iter) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 33c67aad81..d2725b00e9 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -335,132 +335,6 @@ namespace MWWorld } - /// \todo this whole code needs major clean up, and doesn't belong in this class. - void Scene::insertObject (const Ptr& ptr, CellStore* cell) - { - std::string type = ptr.getTypeName(); - - MWWorld::Ptr newPtr; - - // insert into the correct CellRefList - if (type == typeid(ESM::Potion).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->potions.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->potions.list.back(), cell); - } - else if (type == typeid(ESM::Apparatus).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->appas.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->appas.list.back(), cell); - } - else if (type == typeid(ESM::Armor).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->armors.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->armors.list.back(), cell); - } - else if (type == typeid(ESM::Book).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->books.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->books.list.back(), cell); - } - else if (type == typeid(ESM::Clothing).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->clothes.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->clothes.list.back(), cell); - } - else if (type == typeid(ESM::Ingredient).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->ingreds.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->ingreds.list.back(), cell); - } - else if (type == typeid(ESM::Light).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->lights.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->lights.list.back(), cell); - } - else if (type == typeid(ESM::Tool).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->lockpicks.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->lockpicks.list.back(), cell); - } - else if (type == typeid(ESM::Repair).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->repairs.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->repairs.list.back(), cell); - } - else if (type == typeid(ESM::Probe).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->probes.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->probes.list.back(), cell); - } - else if (type == typeid(ESM::Weapon).name()) - { - MWWorld::LiveCellRef* ref = ptr.get(); - cell->weapons.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->weapons.list.back(), cell); - } - else if (type == typeid(ESM::Miscellaneous).name()) - { - - // if this is gold, we need to fetch the correct mesh depending on the amount of gold. - if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) - { - int goldAmount = ptr.getRefData().getCount(); - - std::string base = "Gold_001"; - if (goldAmount >= 100) - base = "Gold_100"; - else if (goldAmount >= 25) - base = "Gold_025"; - else if (goldAmount >= 10) - base = "Gold_010"; - else if (goldAmount >= 5) - base = "Gold_005"; - - MWWorld::ManualRef newRef (MWBase::Environment::get().getWorld()->getStore(), base); - - MWWorld::LiveCellRef* ref = newRef.getPtr().get(); - - cell->miscItems.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); - - ESM::Position& p = newPtr.getRefData().getPosition(); - p.pos[0] = ptr.getRefData().getPosition().pos[0]; - p.pos[1] = ptr.getRefData().getPosition().pos[1]; - p.pos[2] = ptr.getRefData().getPosition().pos[2]; - } - else - { - MWWorld::LiveCellRef* ref = ptr.get(); - - cell->miscItems.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); - } - } - else - throw std::runtime_error("Trying to insert object of unhandled type"); - - - - newPtr.getRefData().setCount(ptr.getRefData().getCount()); - ptr.getRefData().setCount(0); - newPtr.getRefData().enable(); - - mRendering.addObject(newPtr); - MWWorld::Class::get(newPtr).insertObject(newPtr, *mPhysics); - - } - void Scene::addObjectToScene (const Ptr& ptr) { mRendering.addObject (ptr);