1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

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

This commit is contained in:
NeveHanter 2016-12-20 12:38:51 +01:00
parent 2b2a51d3b2
commit 8902bb5b13
7 changed files with 64 additions and 35 deletions

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <list> #include <list>
#include <set>
#include <stdint.h> #include <stdint.h>
namespace osg namespace osg
@ -200,6 +201,10 @@ namespace MWBase
virtual std::list<MWWorld::Ptr> getEnemiesNearby(const MWWorld::Ptr& actor) = 0; 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 void playerLoaded() = 0;
virtual int countSavedGameRecords() const = 0; virtual int countSavedGameRecords() const = 0;

View file

@ -55,7 +55,7 @@ namespace MWGui
void TravelWindow::addDestination(const std::string& name,ESM::Position pos,bool interior) void TravelWindow::addDestination(const std::string& name,ESM::Position pos,bool interior)
{ {
int price = 0; int price;
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
@ -70,14 +70,34 @@ namespace MWGui
else else
{ {
ESM::Position PlayerPos = player.getRefData().getPosition(); 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 = 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); 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; mCurrentY += sLineHeight;
if(interior) if(interior)
toAdd->setUserString("interior","y"); toAdd->setUserString("interior","y");

View file

@ -1482,6 +1482,20 @@ namespace MWMechanics
return list; 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> Actors::getActorsFollowingIndices(const MWWorld::Ptr &actor)
{ {
std::list<int> list; std::list<int> list;

View file

@ -123,6 +123,11 @@ namespace MWMechanics
std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor); std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor);
std::list<MWWorld::Ptr> getActorsFollowing(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 /// Get the list of AiFollow::mFollowIndex for all actors following this target
std::list<int> getActorsFollowingIndices(const MWWorld::Ptr& actor); std::list<int> getActorsFollowingIndices(const MWWorld::Ptr& actor);

View file

@ -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) bool MechanicsManager::commitCrime(const MWWorld::Ptr &player, const MWWorld::Ptr &victim, OffenseType type, int arg, bool victimAware)
{ {
// NOTE: victim may be empty // NOTE: victim may be empty
@ -1013,7 +1001,7 @@ namespace MWMechanics
// get the player's followers / allies (works recursively) that will not report crimes // get the player's followers / allies (works recursively) that will not report crimes
std::set<MWWorld::Ptr> playerFollowers; std::set<MWWorld::Ptr> playerFollowers;
getFollowers(player, playerFollowers); getActorsSidingWith(player, playerFollowers);
// Did anyone see it? // Did anyone see it?
bool crimeSeen = false; bool crimeSeen = false;
@ -1437,6 +1425,14 @@ namespace MWMechanics
return mActors.getEnemiesNearby(actor); 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 int MechanicsManager::countSavedGameRecords() const
{ {
return 1 // Death counter return 1 // Death counter

View file

@ -165,6 +165,11 @@ namespace MWMechanics
virtual std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor); virtual std::list<MWWorld::Ptr> getActorsFighting(const MWWorld::Ptr& actor);
virtual std::list<MWWorld::Ptr> getEnemiesNearby(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 toggleAI();
virtual bool isAIActive(); virtual bool isAIActive();

View file

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