From fc307e64b03d47e38f91cdcb4ac181f7fdfb0d6d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 5 Feb 2013 19:05:07 -0800 Subject: [PATCH] Add swimming states --- apps/openmw/mwmechanics/character.cpp | 18 +++++++++++++----- apps/openmw/mwmechanics/character.hpp | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index f1f6280e5b..f119ceb69f 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -46,12 +46,18 @@ static const struct { { CharState_Idle7, "idle7" }, { CharState_Idle8, "idle8" }, { CharState_Idle9, "idle9" }, + { CharState_IdleSwim, "idleswim" }, { CharState_WalkForward, "walkforward" }, { CharState_WalkBack, "walkback" }, { CharState_WalkLeft, "walkleft" }, { CharState_WalkRight, "walkright" }, + { CharState_SwimWalkForward, "swimwalkforward" }, + { CharState_SwimWalkBack, "swimwalkback" }, + { CharState_SwimWalkLeft, "swimwalkleft" }, + { CharState_SwimWalkRight, "swimwalkright" }, + { CharState_Death1, "death1" }, { CharState_Death2, "death2" }, { CharState_Death3, "death3" }, @@ -157,21 +163,23 @@ Ogre::Vector3 CharacterController::update(float duration) const MWWorld::Class &cls = MWWorld::Class::get(mPtr); const Ogre::Vector3 &vec = cls.getMovementVector(mPtr); + bool inwater = MWBase::Environment::get().getWorld()->isSwimming(mPtr); + if(std::abs(vec.x/2.0f) > std::abs(vec.y)) { if(vec.x > 0.0f) - setState(CharState_WalkRight, true); + setState((inwater ? CharState_SwimWalkRight : CharState_WalkRight), true); else if(vec.x < 0.0f) - setState(CharState_WalkLeft, true); + setState((inwater ? CharState_SwimWalkLeft : CharState_WalkLeft), true); } else if(vec.y > 0.0f) - setState(CharState_WalkForward, true); + setState((inwater ? CharState_SwimWalkForward : CharState_WalkForward), true); else if(vec.y < 0.0f) - setState(CharState_WalkBack, true); + setState((inwater ? CharState_SwimWalkBack : CharState_WalkBack), true); else { if(!(getState() >= CharState_Death1)) - setState(CharState_Idle, true); + setState((inwater ? CharState_IdleSwim : CharState_Idle), true); } Ogre::Vector3 movement = Ogre::Vector3::ZERO; diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index adb6364a0c..535680fa15 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -23,12 +23,18 @@ enum CharacterState { CharState_Idle7, CharState_Idle8, CharState_Idle9, + CharState_IdleSwim, CharState_WalkForward, CharState_WalkBack, CharState_WalkLeft, CharState_WalkRight, + CharState_SwimWalkForward, + CharState_SwimWalkBack, + CharState_SwimWalkLeft, + CharState_SwimWalkRight, + /* Must be last! */ CharState_Death1, CharState_Death2,