1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 06:53:52 +00:00

Don't copy NpcStats/CreatureStats unnecessarily. Fixes a bug: taunt actions would not correctly increase the target's fight rating.

This commit is contained in:
scrawl 2014-01-08 02:35:36 +01:00
parent c85c2cff4e
commit 2bb21f2f76
4 changed files with 11 additions and 11 deletions

View file

@ -221,7 +221,7 @@ namespace MWGui
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::CreatureStats stats = MWWorld::Class::get(player).getCreatureStats(player); const MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
mReviewDialog->setHealth ( stats.getHealth() ); mReviewDialog->setHealth ( stats.getHealth() );
mReviewDialog->setMagicka( stats.getMagicka() ); mReviewDialog->setMagicka( stats.getMagicka() );

View file

@ -149,7 +149,7 @@ namespace MWGui
// I'm making the assumption here that the # of hours rested is calculated when rest is started // I'm making the assumption here that the # of hours rested is calculated when rest is started
// TODO: the rougher logic here (calculating the hourly deltas) should really go into helper funcs elsewhere // TODO: the rougher logic here (calculating the hourly deltas) should really go into helper funcs elsewhere
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::CreatureStats stats = MWWorld::Class::get(player).getCreatureStats(player); const MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
float hourlyHealthDelta = stats.getAttribute(ESM::Attribute::Endurance).getModified() * 0.1; float hourlyHealthDelta = stats.getAttribute(ESM::Attribute::Endurance).getModified() * 0.1;

View file

@ -46,7 +46,6 @@ namespace MWMechanics
bool mRecalcDynamicStats; bool mRecalcDynamicStats;
std::map<std::string, MWWorld::TimeStamp> mUsedPowers; std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
protected: protected:
bool mIsWerewolf; bool mIsWerewolf;
AttributeValue mWerewolfAttributes[8]; AttributeValue mWerewolfAttributes[8];
@ -124,10 +123,10 @@ namespace MWMechanics
enum AiSetting enum AiSetting
{ {
AI_Hello, AI_Hello = 0,
AI_Fight, AI_Fight = 1,
AI_Flee, AI_Flee = 2,
AI_Alarm AI_Alarm = 3
}; };
void setAiSetting (AiSetting index, Stat<int> value); void setAiSetting (AiSetting index, Stat<int> value);
void setAiSetting (AiSetting index, int base); void setAiSetting (AiSetting index, int base);

View file

@ -424,7 +424,7 @@ namespace MWMechanics
int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr) int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr)
{ {
MWMechanics::NpcStats npcSkill = MWWorld::Class::get(ptr).getNpcStats(ptr); const MWMechanics::NpcStats& npcSkill = MWWorld::Class::get(ptr).getNpcStats(ptr);
float x = npcSkill.getBaseDisposition(); float x = npcSkill.getBaseDisposition();
MWWorld::LiveCellRef<ESM::NPC>* npc = ptr.get<ESM::NPC>(); MWWorld::LiveCellRef<ESM::NPC>* npc = ptr.get<ESM::NPC>();
@ -539,7 +539,7 @@ namespace MWMechanics
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>();
MWMechanics::NpcStats npcStats = MWWorld::Class::get(npc).getNpcStats(npc); MWMechanics::NpcStats& npcStats = MWWorld::Class::get(npc).getNpcStats(npc);
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
const MWMechanics::NpcStats &playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr); const MWMechanics::NpcStats &playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr);
@ -613,6 +613,8 @@ namespace MWMechanics
int fight = npcStats.getAiSetting(MWMechanics::CreatureStats::AI_Fight).getBase(); int fight = npcStats.getAiSetting(MWMechanics::CreatureStats::AI_Fight).getBase();
npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee, npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee,
std::max(0, std::min(100, flee + int(std::max(iPerMinChange, s))))); std::max(0, std::min(100, flee + int(std::max(iPerMinChange, s)))));
// TODO: initiate combat and quit dialogue if fight rating is too high
// or should setAiSetting handle this?
npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight, npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight,
std::max(0, std::min(100, fight + int(std::min(-iPerMinChange, -s))))); std::max(0, std::min(100, fight + int(std::min(-iPerMinChange, -s)))));
} }
@ -644,10 +646,9 @@ namespace MWMechanics
float c = std::abs(int(target1 - roll)); float c = std::abs(int(target1 - roll));
if (roll <= target1) if (success)
{ {
float s = c * fPerDieRollMult * fPerTempMult; float s = c * fPerDieRollMult * fPerTempMult;
int flee = npcStats.getAiSetting (CreatureStats::AI_Flee).getBase(); int flee = npcStats.getAiSetting (CreatureStats::AI_Flee).getBase();
int fight = npcStats.getAiSetting (CreatureStats::AI_Fight).getBase(); int fight = npcStats.getAiSetting (CreatureStats::AI_Fight).getBase();
npcStats.setAiSetting (CreatureStats::AI_Flee, npcStats.setAiSetting (CreatureStats::AI_Flee,