mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
Moved duplicated code to common ActionTeleport static method and reordered travel price calculations
This commit is contained in:
parent
15cd3c178b
commit
ff4aba2a6e
@ -74,27 +74,14 @@ namespace MWGui
|
||||
price = static_cast<int>(d / gmst.find("fTravelMult")->getFloat());
|
||||
}
|
||||
|
||||
// Add price for the followers in range
|
||||
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true);
|
||||
|
||||
// Add price for the travelling followers
|
||||
std::set<MWWorld::Ptr> followers;
|
||||
MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(player, followers);
|
||||
|
||||
int travellingFollowers = 0;
|
||||
for(std::set<MWWorld::Ptr>::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() - player.getRefData().getPosition().asVec3()).length2() <= 800*800)
|
||||
++travellingFollowers;
|
||||
}
|
||||
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<int>(followers.size()));
|
||||
|
||||
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>("SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
||||
toAdd->setEnabled(price <= playerGold);
|
||||
|
@ -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<MWWorld::Ptr> followers;
|
||||
MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor, followers);
|
||||
getFollowersToTeleport(actor, followers);
|
||||
|
||||
for(std::set<MWWorld::Ptr>::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<MWWorld::Ptr>::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<MWWorld::Ptr>& out) {
|
||||
std::set<MWWorld::Ptr> followers;
|
||||
MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor, followers);
|
||||
|
||||
for(std::set<MWWorld::Ptr>::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef GAME_MWWORLD_ACTIONTELEPORT_H
|
||||
#define GAME_MWWORLD_ACTIONTELEPORT_H
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
@ -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<MWWorld::Ptr>& out);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user