From c30b9e4bb91fa3e6fa98f072b79b000fecd13f49 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 22:21:44 +0200 Subject: [PATCH] add/remove gold from the player at the end of the transaction. --- apps/openmw/mwgui/tradewindow.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 06e91d787..641ffa833 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -5,6 +5,7 @@ #include "../mwbase/environment.hpp" #include "../mwworld/world.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/manualref.hpp" #include "window_manager.hpp" #include "inventorywindow.hpp" @@ -206,6 +207,31 @@ namespace MWGui transferBoughtItems(); mWindowManager.getInventoryWindow()->transferBoughtItems(); + // add or remove gold from the player. + bool goldFound = false; + MWWorld::Ptr gold; + MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore(); + for (MWWorld::ContainerStoreIterator it = playerStore.begin(); + it != playerStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + goldFound = true; + gold = *it; + } + } + if (goldFound) + { + gold.getRefData().setCount(gold.getRefData().getCount() + mCurrentBalance); + } + else + { + assert(mCurrentBalance > 0); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); + ref.getPtr().getRefData().setCount(mCurrentBalance); + playerStore.add(ref.getPtr()); + } + mWindowManager.setGuiMode(GM_Game); }