From f73d3ad33fa79fd99ce49ce549a98e313de48f4b Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 21:27:02 +0200 Subject: [PATCH] fix to the "drop object on ground" feature. still crashes for gold. --- apps/openmw/mwworld/scene.cpp | 91 ++++++++++++++++++++++++++++------- apps/openmw/mwworld/world.cpp | 24 ++++++++- 2 files changed, 96 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 1d4f078d5..311f8770b 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -328,41 +328,96 @@ namespace MWWorld void Scene::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) { - ptr.mCell = cell; - - mRendering.addObject(ptr); - MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics); - MWWorld::Class::get(ptr).enable(ptr); - std::string type = ptr.getTypeName(); + MWWorld::Ptr newPtr; + // insert into the correct CellRefList if (type == typeid(ESM::Potion).name()) - cell->potions.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->potions.list.push_back( *ref ); + } else if (type == typeid(ESM::Apparatus).name()) - cell->appas.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->appas.list.push_back( *ref ); + } else if (type == typeid(ESM::Armor).name()) - cell->armors.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->armors.list.push_back( *ref ); + } else if (type == typeid(ESM::Book).name()) - cell->books.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->books.list.push_back( *ref ); + } else if (type == typeid(ESM::Clothing).name()) - cell->clothes.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->clothes.list.push_back( *ref ); + } else if (type == typeid(ESM::Ingredient).name()) - cell->ingreds.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->ingreds.list.push_back( *ref ); + } else if (type == typeid(ESM::Light).name()) - cell->lights.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->lights.list.push_back( *ref ); + } else if (type == typeid(ESM::Tool).name()) - cell->lockpicks.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->lockpicks.list.push_back( *ref ); + } else if (type == typeid(ESM::Repair).name()) - cell->repairs.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->repairs.list.push_back( *ref ); + } else if (type == typeid(ESM::Probe).name()) - cell->probes.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->probes.list.push_back( *ref ); + } else if (type == typeid(ESM::Weapon).name()) - cell->weapons.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->weapons.list.push_back( *ref ); + } else if (type == typeid(ESM::Miscellaneous).name()) - cell->miscItems.list.push_back( *ptr.get() ); + { + ESMS::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); + MWWorld::Class::get(newPtr).enable(newPtr); + } } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 973407b0c..0672d5f3b 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -21,7 +21,7 @@ #include "class.hpp" #include "player.hpp" #include "weather.hpp" - +#include "manualref.hpp" #include "refdata.hpp" #include "globals.hpp" #include "cellfunctors.hpp" @@ -982,6 +982,28 @@ namespace MWWorld else cell = getPlayer().getPlayer().getCell(); + // if this is gold, we need to fetch the correct mesh depending on the amount of gold. + if (MWWorld::Class::get(object).getName(object) == getStore().gameSettings.search("sGold")->str) + { + int goldAmount = object.getRefData().getCount(); + + std::string base = "Gold_001"; + if (goldAmount >= 5) + base = "Gold_005"; + else if (goldAmount >= 10) + base = "Gold_010"; + else if (goldAmount >= 25) + base = "Gold_025"; + else if (goldAmount >= 100) + base = "Gold_100"; + + std::cout << "using " << base << std::endl; + MWWorld::ManualRef newRef (getStore(), base); + object = newRef.getPtr(); + object.getRefData().setCount(goldAmount); + object.mCell = cell; + } + ESM::Position& pos = object.getRefData().getPosition(); pos.pos[0] = result.second[0]; pos.pos[1] = -result.second[2];