forked from mirror/openmw-tes3mp
Don't allow raising faction rank if the next rank has no name (Fixes #1975)
This commit is contained in:
parent
fe4d74a6cb
commit
c4fa671381
6 changed files with 58 additions and 29 deletions
|
@ -302,11 +302,11 @@ namespace MWClass
|
|||
Misc::StringUtils::toLower(faction);
|
||||
if(ref->mBase->mNpdtType != ESM::NPC::NPC_WITH_AUTOCALCULATED_STATS)
|
||||
{
|
||||
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt52.mRank;
|
||||
data->mNpcStats.setFactionRank(faction, (int)ref->mBase->mNpdt52.mRank);
|
||||
}
|
||||
else
|
||||
{
|
||||
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt12.mRank;
|
||||
data->mNpcStats.setFactionRank(faction, (int)ref->mBase->mNpdt12.mRank);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ bool MWDialogue::Filter::testActor (const ESM::DialInfo& info) const
|
|||
return false;
|
||||
|
||||
MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats (mActor);
|
||||
std::map<std::string, int>::iterator iter = stats.getFactionRanks().find ( Misc::StringUtils::lowerCase (info.mFaction));
|
||||
std::map<std::string, int>::const_iterator iter = stats.getFactionRanks().find ( Misc::StringUtils::lowerCase (info.mFaction));
|
||||
|
||||
if (iter==stats.getFactionRanks().end())
|
||||
return false;
|
||||
|
@ -112,7 +112,7 @@ bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const
|
|||
if (!info.mPcFaction.empty())
|
||||
{
|
||||
MWMechanics::NpcStats& stats = player.getClass().getNpcStats (player);
|
||||
std::map<std::string,int>::iterator iter = stats.getFactionRanks().find (Misc::StringUtils::lowerCase (info.mPcFaction));
|
||||
std::map<std::string,int>::const_iterator iter = stats.getFactionRanks().find (Misc::StringUtils::lowerCase (info.mPcFaction));
|
||||
|
||||
if(iter==stats.getFactionRanks().end())
|
||||
return false;
|
||||
|
@ -379,7 +379,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
|
|||
if (mActor.getClass().getNpcStats (mActor).getFactionRanks().empty())
|
||||
return 0;
|
||||
|
||||
std::pair<std::string, int> faction =
|
||||
const std::pair<std::string, int> faction =
|
||||
*mActor.getClass().getNpcStats (mActor).getFactionRanks().begin();
|
||||
|
||||
int rank = getFactionRank (player, faction.first);
|
||||
|
|
|
@ -69,9 +69,41 @@ const std::map<std::string, int>& MWMechanics::NpcStats::getFactionRanks() const
|
|||
return mFactionRank;
|
||||
}
|
||||
|
||||
std::map<std::string, int>& MWMechanics::NpcStats::getFactionRanks()
|
||||
void MWMechanics::NpcStats::raiseRank(const std::string &faction)
|
||||
{
|
||||
return mFactionRank;
|
||||
const std::string lower = Misc::StringUtils::lowerCase(faction);
|
||||
std::map<std::string, int>::iterator it = mFactionRank.find(lower);
|
||||
if (it != mFactionRank.end())
|
||||
{
|
||||
// Does the next rank exist?
|
||||
const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(lower);
|
||||
if (it->second+1 < 10 && !faction->mRanks[it->second+1].empty())
|
||||
it->second += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::lowerRank(const std::string &faction)
|
||||
{
|
||||
const std::string lower = Misc::StringUtils::lowerCase(faction);
|
||||
std::map<std::string, int>::iterator it = mFactionRank.find(lower);
|
||||
if (it != mFactionRank.end())
|
||||
{
|
||||
it->second = std::max(0, it->second-1);
|
||||
}
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::setFactionRank(const std::string &faction, int rank)
|
||||
{
|
||||
const std::string lower = Misc::StringUtils::lowerCase(faction);
|
||||
mFactionRank[lower] = rank;
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::joinFaction(const std::string& faction)
|
||||
{
|
||||
const std::string lower = Misc::StringUtils::lowerCase(faction);
|
||||
std::map<std::string, int>::iterator it = mFactionRank.find(lower);
|
||||
if (it == mFactionRank.end())
|
||||
mFactionRank[lower] = 0;
|
||||
}
|
||||
|
||||
bool MWMechanics::NpcStats::getExpelled(const std::string& factionID) const
|
||||
|
|
|
@ -70,7 +70,15 @@ namespace MWMechanics
|
|||
SkillValue& getSkill (int index);
|
||||
|
||||
const std::map<std::string, int>& getFactionRanks() const;
|
||||
std::map<std::string, int>& getFactionRanks();
|
||||
/// Increase the rank in this faction by 1, if such a rank exists.
|
||||
void raiseRank(const std::string& faction);
|
||||
/// Lower the rank in this faction by 1, if such a rank exists.
|
||||
void lowerRank(const std::string& faction);
|
||||
/// Join this faction, setting the initial rank to 0.
|
||||
void joinFaction(const std::string& faction);
|
||||
/// Warning: this function performs no check whether the rank exists,
|
||||
/// and should be used in initial actor setup only.
|
||||
void setFactionRank(const std::string& faction, int rank);
|
||||
|
||||
const std::set<std::string>& getExpelled() const { return mExpelled; }
|
||||
bool getExpelled(const std::string& factionID) const;
|
||||
|
|
|
@ -310,7 +310,7 @@ namespace MWScript
|
|||
|
||||
std::string InterpreterContext::getNPCRank() const
|
||||
{
|
||||
std::map<std::string, int> ranks = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks();
|
||||
const std::map<std::string, int>& ranks = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks();
|
||||
std::map<std::string, int>::const_iterator it = ranks.begin();
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
@ -348,7 +348,7 @@ namespace MWScript
|
|||
|
||||
std::string factionId = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks().begin()->first;
|
||||
|
||||
std::map<std::string, int> ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
||||
const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
||||
std::map<std::string, int>::const_iterator it = ranks.find(factionId);
|
||||
int rank = -1;
|
||||
if (it != ranks.end())
|
||||
|
@ -375,7 +375,7 @@ namespace MWScript
|
|||
|
||||
std::string factionId = getReferenceImp().getClass().getNpcStats (getReferenceImp()).getFactionRanks().begin()->first;
|
||||
|
||||
std::map<std::string, int> ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
||||
const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
||||
std::map<std::string, int>::const_iterator it = ranks.find(factionId);
|
||||
int rank = -1;
|
||||
if (it != ranks.end())
|
||||
|
|
|
@ -548,10 +548,7 @@ namespace MWScript
|
|||
if(factionID != "")
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end())
|
||||
{
|
||||
player.getClass().getNpcStats(player).getFactionRanks()[factionID] = 0;
|
||||
}
|
||||
player.getClass().getNpcStats(player).joinFaction(factionID);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -585,13 +582,11 @@ namespace MWScript
|
|||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end())
|
||||
{
|
||||
player.getClass().getNpcStats(player).getFactionRanks()[factionID] = 0;
|
||||
player.getClass().getNpcStats(player).joinFaction(factionID);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getClass().getNpcStats(player).getFactionRanks()[factionID] =
|
||||
std::min(player.getClass().getNpcStats(player).getFactionRanks()[factionID] +1,
|
||||
9);
|
||||
player.getClass().getNpcStats(player).raiseRank(factionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -624,11 +619,7 @@ namespace MWScript
|
|||
if(factionID != "")
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end())
|
||||
{
|
||||
player.getClass().getNpcStats(player).getFactionRanks()[factionID] =
|
||||
std::max(0, player.getClass().getNpcStats(player).getFactionRanks()[factionID]-1);
|
||||
}
|
||||
player.getClass().getNpcStats(player).lowerRank(factionID);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -668,7 +659,7 @@ namespace MWScript
|
|||
{
|
||||
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end())
|
||||
{
|
||||
runtime.push(player.getClass().getNpcStats(player).getFactionRanks()[factionID]);
|
||||
runtime.push(player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1036,8 +1027,7 @@ namespace MWScript
|
|||
if (ptr == player)
|
||||
return;
|
||||
|
||||
std::map<std::string, int>& ranks = ptr.getClass().getNpcStats(ptr).getFactionRanks ();
|
||||
ranks[factionID] = std::min(9, ranks[factionID]+1);
|
||||
ptr.getClass().getNpcStats(ptr).raiseRank(factionID);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1063,8 +1053,7 @@ namespace MWScript
|
|||
if (ptr == player)
|
||||
return;
|
||||
|
||||
std::map<std::string, int>& ranks = ptr.getClass().getNpcStats(ptr).getFactionRanks ();
|
||||
ranks[factionID] = std::max(0, ranks[factionID]-1);
|
||||
ptr.getClass().getNpcStats(ptr).lowerRank(factionID);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue