forked from mirror/openmw-tes3mp
Moved duplicated code to common ActionTeleport static method and reordered travel price calculations
This commit is contained in:
parent
15cd3c178b
commit
ff4aba2a6e
3 changed files with 31 additions and 33 deletions
|
@ -74,27 +74,14 @@ namespace MWGui
|
||||||
price = static_cast<int>(d / gmst.find("fTravelMult")->getFloat());
|
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;
|
std::set<MWWorld::Ptr> followers;
|
||||||
MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(player, followers);
|
MWWorld::ActionTeleport::getFollowersToTeleport(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply followers cost, in vanilla one follower travels for free
|
// Apply followers cost, in vanilla one follower travels for free
|
||||||
price *= std::max(1, travellingFollowers);
|
price *= std::max(1, static_cast<int>(followers.size()));
|
||||||
|
|
||||||
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true);
|
|
||||||
|
|
||||||
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>("SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>("SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
||||||
toAdd->setEnabled(price <= playerGold);
|
toAdd->setEnabled(price <= playerGold);
|
||||||
|
|
|
@ -20,23 +20,13 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
if (mTeleportFollowers)
|
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;
|
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)
|
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);
|
teleport(*it);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
teleport(actor);
|
teleport(actor);
|
||||||
}
|
}
|
||||||
|
@ -66,4 +56,21 @@ namespace MWWorld
|
||||||
world->moveObject(actor,world->getInterior(mCellName),mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]);
|
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
|
#ifndef GAME_MWWORLD_ACTIONTELEPORT_H
|
||||||
#define GAME_MWWORLD_ACTIONTELEPORT_H
|
#define GAME_MWWORLD_ACTIONTELEPORT_H
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <components/esm/defs.hpp>
|
#include <components/esm/defs.hpp>
|
||||||
|
@ -23,9 +24,12 @@ namespace MWWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ActionTeleport (const std::string& cellName, const ESM::Position& position, bool teleportFollowers);
|
|
||||||
///< If cellName is empty, an exterior cell is assumed.
|
///< If cellName is empty, an exterior cell is assumed.
|
||||||
/// @param teleportFollowers Whether to teleport any following actors of the target actor as well.
|
/// @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 a new issue