diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 43a4efc7a..3063b3268 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -74,27 +74,14 @@ namespace MWGui price = static_cast(d / gmst.find("fTravelMult")->getFloat()); } - // Add price for the followers in range - std::set followers; - MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(player, followers); - - int travellingFollowers = 0; - for(std::set::iterator it = followers.begin();it != followers.end();++it) - { - MWWorld::Ptr follower = *it; - - std::string script = follower.getClass().getScript(follower); - if (!script.empty() && follower.getRefData().getLocals().getIntVar(script, "stayoutside") == 1) - continue; + price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true); - if ((follower.getRefData().getPosition().asVec3() - player.getRefData().getPosition().asVec3()).length2() <= 800*800) - ++travellingFollowers; - } + // Add price for the travelling followers + std::set followers; + MWWorld::ActionTeleport::getFollowersToTeleport(player, followers); // Apply followers cost, in vanilla one follower travels for free - price *= std::max(1, travellingFollowers); - - price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true); + price *= std::max(1, static_cast(followers.size())); MyGUI::Button* toAdd = mDestinationsView->createWidget("SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); toAdd->setEnabled(price <= playerGold); diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index ab1c0afc6..5162cac66 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -20,22 +20,12 @@ namespace MWWorld { if (mTeleportFollowers) { - //find any NPC that is following the actor and teleport him too + // Find any NPCs that are following the actor and teleport them with him std::set followers; - MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor, followers); + getFollowersToTeleport(actor, followers); - for(std::set::iterator it = followers.begin();it != followers.end();++it) - { - MWWorld::Ptr follower = *it; - - std::string script = follower.getClass().getScript(follower); - if (!script.empty() && follower.getRefData().getLocals().getIntVar(script, "stayoutside") == 1) - continue; - - if ((follower.getRefData().getPosition().asVec3() - actor.getRefData().getPosition().asVec3()).length2() - <= 800*800) - teleport(*it); - } + for (std::set::iterator it = followers.begin(); it != followers.end(); ++it) + teleport(*it); } teleport(actor); @@ -66,4 +56,21 @@ namespace MWWorld world->moveObject(actor,world->getInterior(mCellName),mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]); } } + + void ActionTeleport::getFollowersToTeleport(const MWWorld::Ptr& actor, std::set& out) { + std::set followers; + MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor, followers); + + for(std::set::iterator it = followers.begin();it != followers.end();++it) + { + MWWorld::Ptr follower = *it; + + std::string script = follower.getClass().getScript(follower); + if (!script.empty() && follower.getRefData().getLocals().getIntVar(script, "stayoutside") == 1) + continue; + + if ((follower.getRefData().getPosition().asVec3() - actor.getRefData().getPosition().asVec3()).length2() <= 800*800) + out.insert(follower); + } + } } diff --git a/apps/openmw/mwworld/actionteleport.hpp b/apps/openmw/mwworld/actionteleport.hpp index 6191ee9f6..ab28d2c96 100644 --- a/apps/openmw/mwworld/actionteleport.hpp +++ b/apps/openmw/mwworld/actionteleport.hpp @@ -1,6 +1,7 @@ #ifndef GAME_MWWORLD_ACTIONTELEPORT_H #define GAME_MWWORLD_ACTIONTELEPORT_H +#include #include #include @@ -23,9 +24,12 @@ namespace MWWorld public: - ActionTeleport (const std::string& cellName, const ESM::Position& position, bool teleportFollowers); ///< If cellName is empty, an exterior cell is assumed. /// @param teleportFollowers Whether to teleport any following actors of the target actor as well. + ActionTeleport (const std::string& cellName, const ESM::Position& position, bool teleportFollowers); + + /// Outputs every actor follower who is in teleport range and wasn't ordered to not enter interiors + static void getFollowersToTeleport(const MWWorld::Ptr& actor, std::set& out); }; }