From 4b5d6ce311f7c31461951ebb7675344931eb30f7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 17:22:25 +0200 Subject: [PATCH] allow stacking gold --- apps/openmw/mwclass/misc.cpp | 18 +++++++++++----- apps/openmw/mwworld/containerstore.cpp | 29 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 936dc4558d..d8e0553b9e 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -1,6 +1,8 @@ #include "misc.hpp" +#include + #include #include @@ -142,12 +144,18 @@ namespace MWClass const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); int count = ptr.getRefData().getCount(); - // gold has count both as reference count and as value, multiply them together to get real count - bool isGold = (ref->base->name == store.gameSettings.search("sGold")->str); - if (isGold) - count *= ref->base->data.value; - info.caption = ref->base->name + MWGui::ToolTips::getCountString(count); + bool isGold = (ref->base->name == store.gameSettings.search("sGold")->str); + if (isGold && count == 1) + count = ref->base->data.value; + + std::string countString; + if (!isGold) + countString = MWGui::ToolTips::getCountString(count); + else // gold displays its count also if it's 1. + countString = " (" + boost::lexical_cast(count) + ")"; + + info.caption = ref->base->name + countString; info.icon = ref->base->icon; if (ref->ref.soul != "") diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index eca7206030..9b5afea740 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -7,6 +7,9 @@ #include +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + #include "manualref.hpp" #include "refdata.hpp" #include "class.hpp" @@ -62,6 +65,32 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) { int type = getType(ptr); + // gold needs special treatment because it uses several different meshes + if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + ESMS::LiveCellRef *gold = + ptr.get(); + + int goldValue = (ptr.getRefData().getCount() == 1) ? gold->base->data.value : ptr.getRefData().getCount(); + + for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) + { + if (MWWorld::Class::get(*iter).getName(*iter) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + ESMS::LiveCellRef *ref = + iter->get(); + + if (iter->getRefData().getCount() == 1) + iter->getRefData().setCount(ref->base->data.value + goldValue); + else + iter->getRefData().setCount(iter->getRefData().getCount() + goldValue); + + flagAsModified(); + return iter; + } + } + } + // determine whether to stack or not for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) {