mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-30 02:56:44 +00:00 
			
		
		
		
	Issue #356: Implemented ingredient eating
This commit is contained in:
		
							parent
							
								
									2ccd7a480d
								
							
						
					
					
						commit
						fe68a252d5
					
				
					 5 changed files with 93 additions and 1 deletions
				
			
		|  | @ -51,7 +51,7 @@ add_openmw_dir (mwworld | |||
|     refdata worldimp physicssystem scene globals class action nullaction actionteleport | ||||
|     containerstore actiontalk actiontake manualref player cellfunctors | ||||
|     cells localscripts customdata weather inventorystore ptr actionopen actionread | ||||
|     actionequip timestamp actionalchemy cellstore actionapply | ||||
|     actionequip timestamp actionalchemy cellstore actionapply actioneat | ||||
|     ) | ||||
| 
 | ||||
| add_openmw_dir (mwclass | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ | |||
| #include "../mwworld/actiontake.hpp" | ||||
| #include "../mwworld/cellstore.hpp" | ||||
| #include "../mwworld/physicssystem.hpp" | ||||
| #include "../mwworld/actioneat.hpp" | ||||
| 
 | ||||
| #include "../mwgui/tooltips.hpp" | ||||
| 
 | ||||
|  | @ -19,6 +20,14 @@ | |||
| 
 | ||||
| namespace MWClass | ||||
| { | ||||
|     std::string Ingredient::getId (const MWWorld::Ptr& ptr) const | ||||
|     { | ||||
|         MWWorld::LiveCellRef<ESM::Ingredient> *ref = | ||||
|             ptr.get<ESM::Ingredient>(); | ||||
| 
 | ||||
|         return ref->base->mId; | ||||
|     } | ||||
|      | ||||
|     void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const | ||||
|     { | ||||
|         const std::string model = getModel(ptr); | ||||
|  | @ -84,6 +93,14 @@ namespace MWClass | |||
|         return ref->base->data.value; | ||||
|     } | ||||
| 
 | ||||
|     | ||||
|     boost::shared_ptr<MWWorld::Action> Ingredient::use (const MWWorld::Ptr& ptr) const | ||||
|     { | ||||
|         boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionEat (ptr)); | ||||
| 
 | ||||
|         return action;     | ||||
|     } | ||||
|      | ||||
|     void Ingredient::registerSelf() | ||||
|     { | ||||
|         boost::shared_ptr<Class> instance (new Ingredient); | ||||
|  |  | |||
|  | @ -12,6 +12,9 @@ namespace MWClass | |||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             virtual std::string getId (const MWWorld::Ptr& ptr) const; | ||||
|             ///< Return ID of \a ptr
 | ||||
| 
 | ||||
|             virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; | ||||
|             ///< Add reference into a cell for rendering
 | ||||
| 
 | ||||
|  | @ -37,6 +40,10 @@ namespace MWClass | |||
|             virtual int getValue (const MWWorld::Ptr& ptr) const; | ||||
|             ///< Return trade value of the object. Throws an exception, if the object can't be traded.
 | ||||
| 
 | ||||
|             virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) | ||||
|                 const; | ||||
|             ///< Generate action for using via inventory menu
 | ||||
|              | ||||
|             static void registerSelf(); | ||||
| 
 | ||||
|             virtual std::string getUpSoundId (const MWWorld::Ptr& ptr) const; | ||||
|  |  | |||
							
								
								
									
										49
									
								
								apps/openmw/mwworld/actioneat.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								apps/openmw/mwworld/actioneat.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,49 @@ | |||
| 
 | ||||
| #include "actioneat.hpp" | ||||
| 
 | ||||
| #include <cstdlib> | ||||
| 
 | ||||
| #include <components/esm/loadskil.hpp> | ||||
| 
 | ||||
| #include <components/esm_store/store.hpp> | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/world.hpp" | ||||
| 
 | ||||
| #include "../mwmechanics/creaturestats.hpp" | ||||
| #include "../mwmechanics/npcstats.hpp" | ||||
| 
 | ||||
| #include "class.hpp" | ||||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     void ActionEat::executeImp (const Ptr& actor) | ||||
|     { | ||||
|         // remove used item
 | ||||
|         getTarget().getRefData().setCount (getTarget().getRefData().getCount()-1); | ||||
| 
 | ||||
|         // check for success
 | ||||
|         const MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor); | ||||
|         MWMechanics::NpcStats& npcStats = MWWorld::Class::get (actor).getNpcStats (actor); | ||||
|      | ||||
|         float x = | ||||
|             (npcStats.getSkill (ESM::Skill::Alchemy).getModified() + | ||||
|             0.2 * creatureStats.getAttribute (1).getModified() | ||||
|             + 0.1 * creatureStats.getAttribute (7).getModified()) | ||||
|             * creatureStats.getFatigueTerm(); | ||||
| 
 | ||||
|         if (x>=100*static_cast<float> (std::rand()) / RAND_MAX) | ||||
|         { | ||||
|             // apply to actor
 | ||||
|             std::string id = Class::get (getTarget()).getId (getTarget()); | ||||
|              | ||||
|             Class::get (actor).apply (actor, id, actor); | ||||
|             // we ignore the result here. Skill increases no matter if the ingredient did something or not.      
 | ||||
|          | ||||
|             // increase skill
 | ||||
|             Class::get (actor).skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1); | ||||
|         } | ||||
|     }     | ||||
| 
 | ||||
|     ActionEat::ActionEat (const MWWorld::Ptr& object) : Action (false, object) {} | ||||
| } | ||||
							
								
								
									
										19
									
								
								apps/openmw/mwworld/actioneat.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								apps/openmw/mwworld/actioneat.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| #ifndef GAME_MWWORLD_ACTIONEAT_H | ||||
| #define GAME_MWWORLD_ACTIONEAT_H | ||||
| 
 | ||||
| #include "action.hpp" | ||||
| #include "ptr.hpp" | ||||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     class ActionEat : public Action | ||||
|     { | ||||
|             virtual void executeImp (const Ptr& actor); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             ActionEat (const MWWorld::Ptr& object); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
		Loading…
	
		Reference in a new issue