From bec420c69b988b75254e848ab745080963ed32c7 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 26 Jul 2013 05:24:56 -0700 Subject: [PATCH] Add Class::onHit for creatures --- apps/openmw/mwclass/creature.cpp | 28 ++++++++++++++++++++-------- apps/openmw/mwclass/creature.hpp | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 003eb1d148..0f719b3320 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -11,6 +11,7 @@ #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" @@ -153,17 +154,28 @@ namespace MWClass { } + void Creature::onHit(const MWWorld::Ptr &ptr, float damage, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, bool successful) const + { + // NOTE: 'object' and/or 'attacker' may be empty. + + if(!successful) + { + // TODO: Handle HitAttemptOnMe script function + + // Missed + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f); + return; + } + + // TODO: Handle HitOnMe script function and OnPCHitMe script variable. + + float health = getCreatureStats(ptr).getHealth().getCurrent() - damage; + setActorHealth(ptr, health, attacker); + } + void Creature::setActorHealth(const MWWorld::Ptr& ptr, float health, const MWWorld::Ptr& attacker) const { MWMechanics::CreatureStats &crstats = getCreatureStats(ptr); - float diff = health - crstats.getHealth().getCurrent(); - - if(diff < 0.0f) - { - // actor is losing health. Alert the character controller, scripts, etc. - // NOTE: 'attacker' may be empty. - } - bool wasDead = crstats.isDead(); MWMechanics::DynamicStat stat(crstats.getHealth()); diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index a15128ac72..452a0054fe 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -44,6 +44,8 @@ namespace MWClass virtual void hit(const MWWorld::Ptr& ptr, int type) const; + virtual void onHit(const MWWorld::Ptr &ptr, float damage, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, bool successful) const; + virtual void setActorHealth(const MWWorld::Ptr& ptr, float health, const MWWorld::Ptr& attacker) const; virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr,