From 91e95e1404ea33a83b311eddb54ebfb2ce10e195 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 16 Jul 2013 23:32:41 +0200 Subject: [PATCH] Use the correct slash, chop or thrust animation --- apps/openmw/mwgui/settingswindow.cpp | 5 +++ apps/openmw/mwgui/settingswindow.hpp | 1 + apps/openmw/mwinput/inputmanagerimp.cpp | 14 ++++++++ apps/openmw/mwmechanics/character.cpp | 41 +++++++++++++++++++---- apps/openmw/mwmechanics/character.hpp | 2 ++ apps/openmw/mwmechanics/creaturestats.hpp | 11 ++++++ apps/openmw/mwrender/animation.cpp | 2 +- files/mygui/openmw_settings_window.layout | 6 ++++ files/settings-default.cfg | 4 +++ 9 files changed, 79 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 97bccd01f..8443aaf30 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -91,6 +91,7 @@ namespace MWGui WindowBase("openmw_settings_window.layout") { getWidget(mOkButton, "OkButton"); + getWidget(mBestAttackButton, "BestAttackButton"); getWidget(mSubtitlesButton, "SubtitlesButton"); getWidget(mCrosshairButton, "CrosshairButton"); getWidget(mResolutionList, "ResolutionList"); @@ -131,6 +132,7 @@ namespace MWGui mSubtitlesButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mCrosshairButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mBestAttackButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mInvertYButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); mShadersButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onShadersToggled); @@ -200,6 +202,7 @@ namespace MWGui mSubtitlesButton->setCaptionWithReplacing(Settings::Manager::getBool("subtitles", "GUI") ? "#{sOn}" : "#{sOff}"); mCrosshairButton->setCaptionWithReplacing(Settings::Manager::getBool("crosshair", "HUD") ? "#{sOn}" : "#{sOff}"); + mBestAttackButton->setCaptionWithReplacing(Settings::Manager::getBool("best attack", "Game") ? "#{sOn}" : "#{sOff}"); float fovVal = (Settings::Manager::getFloat("field of view", "General")-sFovMin)/(sFovMax-sFovMin); mFOVSlider->setScrollPosition(fovVal * (mFOVSlider->getScrollRange()-1)); @@ -407,6 +410,8 @@ namespace MWGui Settings::Manager::setBool("crosshair", "HUD", newState); else if (_sender == mSubtitlesButton) Settings::Manager::setBool("subtitles", "GUI", newState); + else if (_sender == mBestAttackButton) + Settings::Manager::setBool("best attack", "Game", newState); apply(); } diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 20e9907d9..42ed5bf6d 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -32,6 +32,7 @@ namespace MWGui MyGUI::ScrollBar* mToolTipDelaySlider; MyGUI::Button* mSubtitlesButton; MyGUI::Button* mCrosshairButton; + MyGUI::Button* mBestAttackButton; // graphics MyGUI::ListBox* mResolutionList; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index fd2359f5c..90acbae6a 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -165,6 +165,20 @@ namespace MWInput if (action == A_Use) { MWWorld::Class::get(mPlayer.getPlayer()).getCreatureStats(mPlayer.getPlayer()).setAttackingOrSpell(currentValue); + if (currentValue == 1) + { + int type = MWMechanics::CreatureStats::AT_Chop; + bool forward = (mInputBinder->getChannel(A_MoveForward)->getValue() > 0 + || mInputBinder->getChannel(A_MoveBackward)->getValue() > 0); + bool side = (mInputBinder->getChannel(A_MoveLeft)->getValue() > 0 + || mInputBinder->getChannel(A_MoveRight)->getValue() > 0); + if (side && !forward) + type = MWMechanics::CreatureStats::AT_Slash; + if (forward && !side) + type = MWMechanics::CreatureStats::AT_Thrust; + + MWWorld::Class::get(mPlayer.getPlayer()).getCreatureStats(mPlayer.getPlayer()).setAttackType(type); + } } if (currentValue == 1) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index f4c975c41..04b379757 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -35,6 +35,23 @@ #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +namespace +{ + +int getBestAttack (const ESM::Weapon* weapon) +{ + int slash = (weapon->mData.mSlash[0] + weapon->mData.mSlash[1])/2; + int chop = (weapon->mData.mChop[0] + weapon->mData.mChop[1])/2; + int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2; + if (slash >= chop && slash >= thrust) + return MWMechanics::CreatureStats::AT_Slash; + else if (chop >= slash && chop >= thrust) + return MWMechanics::CreatureStats::AT_Chop; + else + return MWMechanics::CreatureStats::AT_Thrust; +} + +} namespace MWMechanics { @@ -540,13 +557,25 @@ void CharacterController::update(float duration, Movement &movement) float complete; float speedMult; bool animPlaying = mAnimation->getInfo(weapgroup,&complete,&speedMult,&start,&stop); + if(cls.getCreatureStats(mPtr).getAttackingOrSpell()) { if(mUpperBodyState == UpperCharState_WeapEquiped) { + int attackType = cls.getCreatureStats(mPtr).getAttackType(); + if (Settings::Manager::getBool("best attack", "Game") && weapon != inv.end()) + attackType = getBestAttack(weapon->get()->mBase); + + if (attackType == MWMechanics::CreatureStats::AT_Chop) + mAttackType = "chop"; + else if (attackType == MWMechanics::CreatureStats::AT_Slash) + mAttackType = "slash"; + else + mAttackType = "thrust"; + mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop start", "chop min attack", 0.0f, 0); + weapSpeed, mAttackType+" start", mAttackType+" min attack", 0.0f, 0); mUpperBodyState = UpperCharState_ChopStartToMinAttack; } } @@ -557,13 +586,13 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable(weapgroup); mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop max attack", "chop min hit", 1-complete, 0); + weapSpeed, mAttackType+" max attack", mAttackType+" min hit", 1-complete, 0); } else { mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop max attack", "chop min hit", 0, 0); + weapSpeed, mAttackType+" max attack", mAttackType+" min hit", 0, 0); } mUpperBodyState = UpperCharState_ChopMaxAttackToMinHit; } @@ -577,7 +606,7 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable(weapgroup); mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop min attack", "chop max attack",0, 0); + weapSpeed, mAttackType+" min attack", mAttackType+" max attack",0, 0); mUpperBodyState = UpperCharState_ChopMinAttackToMaxAttack; } else if(mUpperBodyState == UpperCharState_ChopMaxAttackToMinHit && complete == 1) @@ -585,7 +614,7 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable(weapgroup); mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop min hit", "chop hit",0, 0); + weapSpeed, mAttackType+" min hit", mAttackType+" hit",0, 0); mUpperBodyState = UpperCharState_ChopMinHitToHit; } else if(mUpperBodyState == UpperCharState_ChopMinHitToHit && complete == 1) @@ -593,7 +622,7 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable(weapgroup); mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, false, - weapSpeed,"chop large follow start", "chop large follow stop",0, 0); + weapSpeed, mAttackType+" large follow start", mAttackType+" large follow stop",0, 0); mUpperBodyState = UpperCharState_ChopLargeFollowStartToLargeFollowStop; } else if(mUpperBodyState == UpperCharState_ChopLargeFollowStartToLargeFollowStop && complete == 1) diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 08dc67f7b..d760f8957 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -146,6 +146,8 @@ class CharacterController float mSecondsOfSwimming; float mSecondsOfRunning; + std::string mAttackType; // slash, chop or thrust + void refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force=false); static void getWeaponGroup(WeaponType weaptype, std::string &group); diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 7423e76b2..2d979b9b2 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -36,6 +36,8 @@ namespace MWMechanics bool mHostile; bool mAttackingOrSpell;//for the player, this is true if the left mouse button is pressed, false if not. + int mAttackType; + public: CreatureStats(); @@ -88,6 +90,15 @@ namespace MWMechanics void setAttackingOrSpell(const bool &attackingOrSpell); + enum AttackType + { + AT_Slash, + AT_Thrust, + AT_Chop + }; + void setAttackType(int attackType) { mAttackType = attackType; } + int getAttackType() { return mAttackType; } + void setLevel(int level); void setAiSetting (int index, int value); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 147e7c90e..3ced108b3 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -654,7 +654,7 @@ void Animation::resetActiveGroups() return; const Ogre::SharedPtr &animsrc = state->second.mSource; - const NifOgre::TextKeyMap &keys = animsrc->mTextKeys; + //const NifOgre::TextKeyMap &keys = animsrc->mTextKeys; const std::vector >&ctrls = animsrc->mControllers[0]; for(size_t i = 0;i < ctrls.size();i++) { diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index ab91aed78..a54f3086e 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -44,6 +44,12 @@ + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 613f12432..ac56604d1 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -163,3 +163,7 @@ ui sensitivity = 1.0 camera y multiplier = 1.0 ui y multiplier = 1.0 + +[Game] +# Always use the most powerful attack when striking with a weapon (chop, slash or thrust) +best attack = false