Player now pays for the following actors when travelling, with the exception of the first follower who travels for free, refactored getFollowers to getActorsFollowing/getActorsSidingWith

pull/118/head^2
NeveHanter 8 years ago
parent 2b2a51d3b2
commit 8902bb5b13

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <list>
#include <set>
#include <stdint.h>
namespace osg
@ -200,6 +201,10 @@ namespace MWBase
virtual std::list<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor) = 0;
/// Recursive versions of above methods
virtual void getActorsFollowing(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) = 0;
virtual void getActorsSidingWith(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) = 0;
virtual void playerLoaded() = 0;
virtual int countSavedGameRecords() const = 0;

@ -55,7 +55,7 @@ namespace MWGui
void TravelWindow::addDestination(const std::string& name,ESM::Position pos,bool interior)
{
int price = 0;
int price;
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
@ -70,14 +70,34 @@ namespace MWGui
else
{
ESM::Position PlayerPos = player.getRefData().getPosition();
float d = sqrt( pow(pos.pos[0] - PlayerPos.pos[0],2) + pow(pos.pos[1] - PlayerPos.pos[1],2) + pow(pos.pos[2] - PlayerPos.pos[2],2) );
float d = sqrt(pow(pos.pos[0] - PlayerPos.pos[0], 2) + pow(pos.pos[1] - PlayerPos.pos[1], 2) + pow(pos.pos[2] - PlayerPos.pos[2], 2));
price = static_cast<int>(d / gmst.find("fTravelMult")->getFloat());
}
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr,price,true);
// Add price for the followers in range
std::set<MWWorld::Ptr> followers;
MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(player, followers);
unsigned 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
price *= travellingFollowers;
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true);
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>("SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
toAdd->setEnabled(price<=playerGold);
toAdd->setEnabled(price <= playerGold);
mCurrentY += sLineHeight;
if(interior)
toAdd->setUserString("interior","y");

@ -1482,6 +1482,20 @@ namespace MWMechanics
return list;
}
void Actors::getActorsFollowing(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out) {
std::list<MWWorld::Ptr> followers = getActorsFollowing(actor);
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
if (out.insert(*it).second)
getActorsFollowing(*it, out);
}
void Actors::getActorsSidingWith(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out) {
std::list<MWWorld::Ptr> followers = getActorsSidingWith(actor);
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
if (out.insert(*it).second)
getActorsSidingWith(*it, out);
}
std::list<int> Actors::getActorsFollowingIndices(const MWWorld::Ptr &actor)
{
std::list<int> list;

@ -123,6 +123,11 @@ namespace MWMechanics
std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor);
std::list<MWWorld::Ptr> getActorsFollowing(const MWWorld::Ptr& actor);
/// Recursive version of getActorsFollowing
void getActorsFollowing(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out);
/// Recursive version of getActorsSidingWith
void getActorsSidingWith(const MWWorld::Ptr &actor, std::set<MWWorld::Ptr>& out);
/// Get the list of AiFollow::mFollowIndex for all actors following this target
std::list<int> getActorsFollowingIndices(const MWWorld::Ptr& actor);

@ -978,18 +978,6 @@ namespace MWMechanics
}
void getFollowers (const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out)
{
std::list<MWWorld::Ptr> followers = MWBase::Environment::get().getMechanicsManager()->getActorsSidingWith(actor);
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
{
if (out.insert(*it).second)
{
getFollowers(*it, out);
}
}
}
bool MechanicsManager::commitCrime(const MWWorld::Ptr &player, const MWWorld::Ptr &victim, OffenseType type, int arg, bool victimAware)
{
// NOTE: victim may be empty
@ -1013,7 +1001,7 @@ namespace MWMechanics
// get the player's followers / allies (works recursively) that will not report crimes
std::set<MWWorld::Ptr> playerFollowers;
getFollowers(player, playerFollowers);
getActorsSidingWith(player, playerFollowers);
// Did anyone see it?
bool crimeSeen = false;
@ -1437,6 +1425,14 @@ namespace MWMechanics
return mActors.getEnemiesNearby(actor);
}
void MechanicsManager::getActorsFollowing(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) {
mActors.getActorsFollowing(actor, out);
}
void MechanicsManager::getActorsSidingWith(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out) {
mActors.getActorsSidingWith(actor, out);
}
int MechanicsManager::countSavedGameRecords() const
{
return 1 // Death counter

@ -165,6 +165,11 @@ namespace MWMechanics
virtual std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor);
virtual std::list<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor);
/// Recursive version of getActorsFollowing
virtual void getActorsFollowing(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out);
/// Recursive version of getActorsSidingWith
virtual void getActorsSidingWith(const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out);
virtual bool toggleAI();
virtual bool isAIActive();

@ -8,23 +8,6 @@
#include "player.hpp"
namespace
{
void getFollowers (const MWWorld::Ptr& actor, std::set<MWWorld::Ptr>& out)
{
std::list<MWWorld::Ptr> followers = MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor);
for(std::list<MWWorld::Ptr>::iterator it = followers.begin();it != followers.end();++it)
{
if (out.insert(*it).second)
{
getFollowers(*it, out);
}
}
}
}
namespace MWWorld
{
ActionTeleport::ActionTeleport (const std::string& cellName,
@ -39,7 +22,8 @@ namespace MWWorld
{
//find any NPC that is following the actor and teleport him too
std::set<MWWorld::Ptr> followers;
getFollowers(actor, 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;

Loading…
Cancel
Save