From c50ee22772cb7cb4e8229fc5e0e73ff46df85ad2 Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Sun, 23 Sep 2018 01:52:56 +0300 Subject: [PATCH 1/6] Wrap up World::canRest() implementation by moving enemiesNearby() from InputManager::rest() to World::canRest(). --- apps/openmw/mwbase/world.hpp | 16 ++++++++++------ apps/openmw/mwgui/waitdialog.cpp | 11 ++++++++--- apps/openmw/mwinput/inputmanagerimp.cpp | 4 ---- apps/openmw/mwworld/worldimp.cpp | 11 +++++++---- apps/openmw/mwworld/worldimp.hpp | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 72c4c3a2a..4e9e3f4a9 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -438,12 +438,16 @@ namespace MWBase virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable) = 0; - virtual int canRest() = 0; - ///< check if the player is allowed to rest \n - /// 0 - yes \n - /// 1 - only waiting \n - /// 2 - player is underwater \n - /// 3 - enemies are nearby (not implemented) + enum RestPermitted + { + Rest_Allowed = 0, + Rest_OnlyWaiting = 1, + Rest_PlayerIsUnderwater = 2, + Rest_EnemiesAreNearby = 3 + }; + + virtual RestPermitted canRest() = 0; + ///< check if the player is allowed to rest /// \todo Probably shouldn't be here virtual MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr) = 0; diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index c5a06a12c..37cc9a59f 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -83,7 +83,7 @@ namespace MWGui void WaitDialog::setPtr(const MWWorld::Ptr &ptr) { - setCanRest(!ptr.isEmpty() || MWBase::Environment::get().getWorld ()->canRest () == 0); + setCanRest(!ptr.isEmpty() || MWBase::Environment::get().getWorld ()->canRest () == MWBase::World::Rest_Allowed); if (mUntilHealedButton->getVisible()) MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mUntilHealedButton); @@ -120,9 +120,14 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->popGuiMode (); } - int canRest = MWBase::Environment::get().getWorld ()->canRest (); + MWBase::World::RestPermitted canRest = MWBase::Environment::get().getWorld ()->canRest (); - if (canRest == 2) + if (canRest == MWBase::World::Rest_EnemiesAreNearby) + { + MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}"); + MWBase::Environment::get().getWindowManager()->popGuiMode (); + } + else if (canRest == MWBase::World::Rest_PlayerIsUnderwater) { // resting underwater or mid-air not allowed MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage1}"); diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index ba9370122..101b4f2f7 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -1029,10 +1029,6 @@ namespace MWInput if (!MWBase::Environment::get().getWindowManager()->getRestEnabled () || MWBase::Environment::get().getWindowManager()->isGuiMode ()) return; - if(mPlayer->enemiesNearby()) {//Check if in combat - MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}"); //Nope, - return; - } MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_Rest); //Open rest GUI } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 2afcdffc8..458ff3a01 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2297,7 +2297,7 @@ namespace MWWorld applyLoopingParticles(player); } - int World::canRest () + World::RestPermitted World::canRest () { CellStore *currentCell = mWorldScene->getCurrentCell(); @@ -2309,13 +2309,16 @@ namespace MWWorld if (!actor) throw std::runtime_error("can't find player"); + if(mPlayer->enemiesNearby()) + return Rest_EnemiesAreNearby; + if ((actor->getCollisionMode() && !mPhysics->isOnSolidGround(player)) || isUnderwater(currentCell, playerPos) || isWalkingOnWater(player)) - return 2; + return Rest_PlayerIsUnderwater; if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) || player.getClass().getNpcStats(player).isWerewolf()) - return 1; + return Rest_OnlyWaiting; - return 0; + return Rest_Allowed; } MWRender::Animation* World::getAnimation(const MWWorld::Ptr &ptr) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 536a40468..92fb091bf 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -551,7 +551,7 @@ namespace MWWorld void enableActorCollision(const MWWorld::Ptr& actor, bool enable) override; - int canRest() override; + World::RestPermitted canRest() override; ///< check if the player is allowed to rest \n /// 0 - yes \n /// 1 - only waiting \n From 44bcd9b25fa8c94da732de933e2465185d58673c Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Sun, 23 Sep 2018 02:46:29 +0300 Subject: [PATCH 2/6] Fix tab characters --- apps/openmw/mwgui/waitdialog.cpp | 8 ++++---- apps/openmw/mwworld/worldimp.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 37cc9a59f..db92b355c 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -120,14 +120,14 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->popGuiMode (); } - MWBase::World::RestPermitted canRest = MWBase::Environment::get().getWorld ()->canRest (); + MWBase::World::RestPermitted canRest = MWBase::Environment::get().getWorld ()->canRest (); - if (canRest == MWBase::World::Rest_EnemiesAreNearby) + if (canRest == MWBase::World::Rest_EnemiesAreNearby) { MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}"); MWBase::Environment::get().getWindowManager()->popGuiMode (); - } - else if (canRest == MWBase::World::Rest_PlayerIsUnderwater) + } + else if (canRest == MWBase::World::Rest_PlayerIsUnderwater) { // resting underwater or mid-air not allowed MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage1}"); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 458ff3a01..1b3e3c3ef 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2309,8 +2309,8 @@ namespace MWWorld if (!actor) throw std::runtime_error("can't find player"); - if(mPlayer->enemiesNearby()) - return Rest_EnemiesAreNearby; + if(mPlayer->enemiesNearby()) + return Rest_EnemiesAreNearby; if ((actor->getCollisionMode() && !mPhysics->isOnSolidGround(player)) || isUnderwater(currentCell, playerPos) || isWalkingOnWater(player)) return Rest_PlayerIsUnderwater; From f2e11e6def966680380267ab84169b3670e66237 Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Sun, 23 Sep 2018 04:06:29 +0300 Subject: [PATCH 3/6] Fix MSVC C4596 illegal qualified name --- apps/openmw/mwworld/worldimp.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 92fb091bf..5c3eb30b3 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -551,7 +551,7 @@ namespace MWWorld void enableActorCollision(const MWWorld::Ptr& actor, bool enable) override; - World::RestPermitted canRest() override; + RestPermitted canRest() override; ///< check if the player is allowed to rest \n /// 0 - yes \n /// 1 - only waiting \n From f00f35ba86f719e2fa7615a3aab9e402acaa27b9 Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Sun, 23 Sep 2018 06:25:20 +0300 Subject: [PATCH 4/6] Add const to canRest() --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 2 +- apps/openmw/mwworld/worldimp.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 4e9e3f4a9..330babf09 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -446,7 +446,7 @@ namespace MWBase Rest_EnemiesAreNearby = 3 }; - virtual RestPermitted canRest() = 0; + virtual RestPermitted canRest() const = 0; ///< check if the player is allowed to rest /// \todo Probably shouldn't be here diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1b3e3c3ef..9b701d17b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2297,7 +2297,7 @@ namespace MWWorld applyLoopingParticles(player); } - World::RestPermitted World::canRest () + World::RestPermitted World::canRest () const { CellStore *currentCell = mWorldScene->getCurrentCell(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 5c3eb30b3..e694d9d84 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -551,7 +551,7 @@ namespace MWWorld void enableActorCollision(const MWWorld::Ptr& actor, bool enable) override; - RestPermitted canRest() override; + RestPermitted canRest() const override; ///< check if the player is allowed to rest \n /// 0 - yes \n /// 1 - only waiting \n From b2a52a5b6c1ba97ee3d5bab99cfb66a675e3ad78 Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Mon, 24 Sep 2018 14:59:10 +0300 Subject: [PATCH 5/6] Change 'after function'-style doxygen comment to normal. --- apps/openmw/mwbase/world.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 330babf09..f44e6593b 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -446,8 +446,8 @@ namespace MWBase Rest_EnemiesAreNearby = 3 }; + /// check if the player is allowed to rest virtual RestPermitted canRest() const = 0; - ///< check if the player is allowed to rest /// \todo Probably shouldn't be here virtual MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr) = 0; From 657d95a0bedc63e252139a28c6275e3b8ed86c27 Mon Sep 17 00:00:00 2001 From: Sergey Fukanchik Date: Mon, 24 Sep 2018 15:30:30 +0300 Subject: [PATCH 6/6] Paperwork for the pull request #1935 --- AUTHORS.md | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 5320a2462..074081876 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -148,6 +148,7 @@ Programmers Scott Howard scrawl Sebastian Wick (swick) + Sergey Fukanchik Sergey Shambir ShadowRadiance Siimacore diff --git a/CHANGELOG.md b/CHANGELOG.md index b45727939..7083fcdb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,6 +164,7 @@ Task #4621: Optimize combat AI Task #4643: Revise editor record verifying functionality Task #4645: Use constants instead of widely used magic numbers + Task #4652: Move call to enemiesNearby() from InputManager::rest() to World::canRest() 0.44.0 ------