1 #include "ingredient.hpp" 2 3 #include <components/esm/loadingr.hpp> 4 5 #include "../mwbase/environment.hpp" 6 #include "../mwbase/world.hpp" 7 #include "../mwbase/windowmanager.hpp" 8 9 #include "../mwworld/ptr.hpp" 10 #include "../mwworld/cellstore.hpp" 11 #include "../mwworld/esmstore.hpp" 12 #include "../mwphysics/physicssystem.hpp" 13 #include "../mwworld/actioneat.hpp" 14 #include "../mwworld/nullaction.hpp" 15 16 #include "../mwgui/tooltips.hpp" 17 18 #include "../mwrender/objects.hpp" 19 #include "../mwrender/renderinginterface.hpp" 20 21 namespace MWClass 22 { 23 insertObjectRendering(const MWWorld::Ptr & ptr,const std::string & model,MWRender::RenderingInterface & renderingInterface) const24 void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const 25 { 26 if (!model.empty()) { 27 renderingInterface.getObjects().insertModel(ptr, model); 28 } 29 } 30 insertObject(const MWWorld::Ptr & ptr,const std::string & model,MWPhysics::PhysicsSystem & physics) const31 void Ingredient::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const 32 { 33 // TODO: add option somewhere to enable collision for placeable objects 34 } 35 getModel(const MWWorld::ConstPtr & ptr) const36 std::string Ingredient::getModel(const MWWorld::ConstPtr &ptr) const 37 { 38 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 39 40 const std::string &model = ref->mBase->mModel; 41 if (!model.empty()) { 42 return "meshes\\" + model; 43 } 44 return ""; 45 } 46 getName(const MWWorld::ConstPtr & ptr) const47 std::string Ingredient::getName (const MWWorld::ConstPtr& ptr) const 48 { 49 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 50 const std::string& name = ref->mBase->mName; 51 52 return !name.empty() ? name : ref->mBase->mId; 53 } 54 activate(const MWWorld::Ptr & ptr,const MWWorld::Ptr & actor) const55 std::shared_ptr<MWWorld::Action> Ingredient::activate (const MWWorld::Ptr& ptr, 56 const MWWorld::Ptr& actor) const 57 { 58 return defaultItemActivate(ptr, actor); 59 } 60 getScript(const MWWorld::ConstPtr & ptr) const61 std::string Ingredient::getScript (const MWWorld::ConstPtr& ptr) const 62 { 63 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 64 65 return ref->mBase->mScript; 66 } 67 getValue(const MWWorld::ConstPtr & ptr) const68 int Ingredient::getValue (const MWWorld::ConstPtr& ptr) const 69 { 70 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 71 72 return ref->mBase->mData.mValue; 73 } 74 75 use(const MWWorld::Ptr & ptr,bool force) const76 std::shared_ptr<MWWorld::Action> Ingredient::use (const MWWorld::Ptr& ptr, bool force) const 77 { 78 std::shared_ptr<MWWorld::Action> action (new MWWorld::ActionEat (ptr)); 79 80 action->setSound ("Swallow"); 81 82 return action; 83 } 84 registerSelf()85 void Ingredient::registerSelf() 86 { 87 std::shared_ptr<Class> instance (new Ingredient); 88 89 registerClass (typeid (ESM::Ingredient).name(), instance); 90 } 91 getUpSoundId(const MWWorld::ConstPtr & ptr) const92 std::string Ingredient::getUpSoundId (const MWWorld::ConstPtr& ptr) const 93 { 94 return std::string("Item Ingredient Up"); 95 } 96 getDownSoundId(const MWWorld::ConstPtr & ptr) const97 std::string Ingredient::getDownSoundId (const MWWorld::ConstPtr& ptr) const 98 { 99 return std::string("Item Ingredient Down"); 100 } 101 getInventoryIcon(const MWWorld::ConstPtr & ptr) const102 std::string Ingredient::getInventoryIcon (const MWWorld::ConstPtr& ptr) const 103 { 104 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 105 106 return ref->mBase->mIcon; 107 } 108 getToolTipInfo(const MWWorld::ConstPtr & ptr,int count) const109 MWGui::ToolTipInfo Ingredient::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const 110 { 111 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 112 113 MWGui::ToolTipInfo info; 114 info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); 115 info.icon = ref->mBase->mIcon; 116 117 std::string text; 118 119 text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}"); 120 text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); 121 122 if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { 123 text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); 124 text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); 125 } 126 127 MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); 128 float alchemySkill = player.getClass().getSkill(player, ESM::Skill::Alchemy); 129 130 static const float fWortChanceValue = 131 MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWortChanceValue")->mValue.getFloat(); 132 133 MWGui::Widgets::SpellEffectList list; 134 for (int i=0; i<4; ++i) 135 { 136 if (ref->mBase->mData.mEffectID[i] < 0) 137 continue; 138 MWGui::Widgets::SpellEffectParams params; 139 params.mEffectID = ref->mBase->mData.mEffectID[i]; 140 params.mAttribute = ref->mBase->mData.mAttributes[i]; 141 params.mSkill = ref->mBase->mData.mSkills[i]; 142 143 params.mKnown = ( (i == 0 && alchemySkill >= fWortChanceValue) 144 || (i == 1 && alchemySkill >= fWortChanceValue*2) 145 || (i == 2 && alchemySkill >= fWortChanceValue*3) 146 || (i == 3 && alchemySkill >= fWortChanceValue*4)); 147 148 list.push_back(params); 149 } 150 info.effects = list; 151 152 info.text = text; 153 info.isIngredient = true; 154 155 return info; 156 } 157 copyToCellImpl(const MWWorld::ConstPtr & ptr,MWWorld::CellStore & cell) const158 MWWorld::Ptr Ingredient::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const 159 { 160 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 161 162 return MWWorld::Ptr(cell.insert(ref), &cell); 163 } 164 canSell(const MWWorld::ConstPtr & item,int npcServices) const165 bool Ingredient::canSell (const MWWorld::ConstPtr& item, int npcServices) const 166 { 167 return (npcServices & ESM::NPC::Ingredients) != 0; 168 } 169 170 getWeight(const MWWorld::ConstPtr & ptr) const171 float Ingredient::getWeight(const MWWorld::ConstPtr &ptr) const 172 { 173 const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>(); 174 return ref->mBase->mData.mWeight; 175 } 176 } 177