Merge branch 'master' into dialogue

Conflicts:
	apps/openmw/mwdialogue/dialoguemanagerimp.hpp
	apps/openmw/mwmechanics/npcstats.cpp
	apps/openmw/mwmechanics/npcstats.hpp
actorid
Marc Zinnschlag 12 years ago
commit 75f64aa38b

@ -40,6 +40,10 @@ namespace MWBase
virtual void keywordSelected (const std::string& keyword) = 0;
virtual void goodbyeSelected() = 0;
virtual void questionAnswered (const std::string& answer) = 0;
virtual void persuade (int type) = 0;
virtual int getTemporaryDispositionChange () const = 0;
virtual void applyTemporaryDispositionChange (int delta) = 0;
};
}

@ -62,7 +62,7 @@ namespace MWBase
virtual void setPlayerName (const std::string& name) = 0;
///< Set player name.
virtual void setPlayerRace (const std::string& id, bool male) = 0;
virtual void setPlayerRace (const std::string& id, bool male, const std::string &head, const std::string &hair) = 0;
///< Set player race.
virtual void setPlayerBirthsign (const std::string& id) = 0;
@ -85,6 +85,19 @@ namespace MWBase
virtual int countDeaths (const std::string& id) const = 0;
///< Return the number of deaths for actors with the given ID.
enum PersuasionType
{
PT_Admire,
PT_Intimidate,
PT_Taunt,
PT_Bribe10,
PT_Bribe100,
PT_Bribe1000
};
virtual void getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type,
float currentTemporaryDispositionDelta, bool& success, float& tempChange, float& permChange) = 0;
///< Perform a persuasion action on NPC
};
}

@ -95,7 +95,8 @@ namespace MWClass
data->mCreatureStats.setFatigue (ref->mBase->mNpdt52.mFatigue);
data->mCreatureStats.setLevel(ref->mBase->mNpdt52.mLevel);
data->mNpcStats.setDisposition(ref->mBase->mNpdt52.mDisposition);
data->mNpcStats.setBaseDisposition(ref->mBase->mNpdt52.mDisposition);
data->mNpcStats.setReputation(ref->mBase->mNpdt52.mReputation);
}
else
{

@ -21,10 +21,12 @@
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/player.hpp"
#include "../mwgui/dialogue.hpp"
@ -33,6 +35,7 @@
#include "../mwscript/extensions.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "filter.hpp"
@ -75,6 +78,8 @@ namespace MWDialogue
DialogueManager::DialogueManager (const Compiler::Extensions& extensions) :
mCompilerContext (MWScript::CompilerContext::Type_Dialgoue),
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
, mTemporaryDispositionChange(0.f)
, mPermanentDispositionChange(0.f)
{
mChoice = -1;
mIsInChoice = false;
@ -350,6 +355,15 @@ namespace MWDialogue
void DialogueManager::goodbyeSelected()
{
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Dialogue);
// Apply disposition change to NPC's base disposition
if (mActor.getTypeName() == typeid(ESM::NPC).name())
{
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(mActor).getNpcStats(mActor);
npcStats.setBaseDisposition(npcStats.getBaseDisposition() + mPermanentDispositionChange);
}
mPermanentDispositionChange = 0;
mTemporaryDispositionChange = 0;
}
void DialogueManager::questionAnswered (const std::string& answer)
@ -408,4 +422,56 @@ namespace MWDialogue
win->goodbye();
}
void DialogueManager::persuade(int type)
{
bool success;
float temp, perm;
MWBase::Environment::get().getMechanicsManager()->getPersuasionDispositionChange(
mActor, MWBase::MechanicsManager::PersuasionType(type), mTemporaryDispositionChange,
success, temp, perm);
mTemporaryDispositionChange += temp;
mPermanentDispositionChange += perm;
// change temp disposition so that final disposition is between 0...100
int curDisp = MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mActor);
if (curDisp + mTemporaryDispositionChange < 0)
mTemporaryDispositionChange = -curDisp;
else if (curDisp + mTemporaryDispositionChange > 100)
mTemporaryDispositionChange = 100 - curDisp;
// practice skill
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Class::get(player).skillUsageSucceeded(player, ESM::Skill::Speechcraft, 0);
// add status message to dialogue window
std::string text;
if (type == MWBase::MechanicsManager::PT_Admire)
text = "sAdmire";
else if (type == MWBase::MechanicsManager::PT_Taunt)
text = "sTaunt";
else if (type == MWBase::MechanicsManager::PT_Intimidate)
text = "sIntimidate";
else
text = "sBribe";
text += (success ? "Success" : "Fail");
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
win->addTitle(MyGUI::LanguageManager::getInstance().replaceTags("#{"+text+"}"));
/// \todo text from INFO record, how to get the ID?
}
int DialogueManager::getTemporaryDispositionChange() const
{
return mTemporaryDispositionChange;
}
void DialogueManager::applyTemporaryDispositionChange(int delta)
{
mTemporaryDispositionChange += delta;
}
}

@ -33,6 +33,9 @@ namespace MWDialogue
ESM::DialInfo mLastDialogue;
bool mIsInChoice;
float mTemporaryDispositionChange;
float mPermanentDispositionChange;
void parseText (const std::string& text);
void updateTopics();
@ -62,6 +65,9 @@ namespace MWDialogue
virtual void goodbyeSelected();
virtual void questionAnswered (const std::string& answer);
virtual void persuade (int type);
virtual int getTemporaryDispositionChange () const;
virtual void applyTemporaryDispositionChange (int delta);
};
}

@ -7,6 +7,7 @@
#include "review.hpp"
#include "dialogue.hpp"
#include "mode.hpp"
#include "inventorywindow.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
@ -459,9 +460,16 @@ void CharacterCreation::onRaceDialogBack()
{
if (mRaceDialog)
{
mPlayerRaceId = mRaceDialog->getRaceId();
if (!mPlayerRaceId.empty())
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male);
const ESM::NPC &data = mRaceDialog->getResult();
mPlayerRaceId = data.mId;
if (!mPlayerRaceId.empty()) {
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
data.mId,
data.isMale(),
data.mHead,
data.mHair
);
}
mWM->removeDialog(mRaceDialog);
mRaceDialog = 0;
}
@ -474,10 +482,18 @@ void CharacterCreation::onRaceDialogDone(WindowBase* parWindow)
{
if (mRaceDialog)
{
mPlayerRaceId = mRaceDialog->getRaceId();
mWM->setValue("race", mPlayerRaceId);
if (!mPlayerRaceId.empty())
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male);
const ESM::NPC &data = mRaceDialog->getResult();
mPlayerRaceId = data.mRace;
if (!mPlayerRaceId.empty()) {
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
data.mRace,
data.isMale(),
data.mHead,
data.mHair
);
}
mWM->getInventoryWindow()->rebuildAvatar();
mWM->removeDialog(mRaceDialog);
mRaceDialog = 0;
}

@ -14,6 +14,8 @@
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "dialogue_history.hpp"
#include "widgets.hpp"
#include "list.hpp"
@ -49,14 +51,87 @@ std::string::size_type find_str_ci(const std::string& str, const std::string& su
}
PersuasionDialog::PersuasionDialog(MWBase::WindowManager &parWindowManager)
: WindowModal("openmw_persuasion_dialog.layout", parWindowManager)
{
getWidget(mCancelButton, "CancelButton");
getWidget(mAdmireButton, "AdmireButton");
getWidget(mIntimidateButton, "IntimidateButton");
getWidget(mTauntButton, "TauntButton");
getWidget(mBribe10Button, "Bribe10Button");
getWidget(mBribe100Button, "Bribe100Button");
getWidget(mBribe1000Button, "Bribe1000Button");
getWidget(mGoldLabel, "GoldLabel");
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onCancel);
mAdmireButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mIntimidateButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mTauntButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mBribe10Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mBribe100Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mBribe1000Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
}
void PersuasionDialog::onCancel(MyGUI::Widget *sender)
{
setVisible(false);
}
void PersuasionDialog::onPersuade(MyGUI::Widget *sender)
{
MWBase::MechanicsManager::PersuasionType type;
if (sender == mAdmireButton) type = MWBase::MechanicsManager::PT_Admire;
else if (sender == mIntimidateButton) type = MWBase::MechanicsManager::PT_Intimidate;
else if (sender == mTauntButton) type = MWBase::MechanicsManager::PT_Taunt;
else if (sender == mBribe10Button)
{
mWindowManager.getTradeWindow()->addOrRemoveGold(-10);
type = MWBase::MechanicsManager::PT_Bribe10;
}
else if (sender == mBribe100Button)
{
mWindowManager.getTradeWindow()->addOrRemoveGold(-100);
type = MWBase::MechanicsManager::PT_Bribe100;
}
else /*if (sender == mBribe1000Button)*/
{
mWindowManager.getTradeWindow()->addOrRemoveGold(-1000);
type = MWBase::MechanicsManager::PT_Bribe1000;
}
MWBase::Environment::get().getDialogueManager()->persuade(type);
setVisible(false);
}
void PersuasionDialog::open()
{
WindowModal::open();
center();
int playerGold = mWindowManager.getInventoryWindow()->getPlayerGold();
mBribe10Button->setEnabled (playerGold >= 10);
mBribe100Button->setEnabled (playerGold >= 100);
mBribe1000Button->setEnabled (playerGold >= 1000);
mGoldLabel->setCaptionWithReplacing("#{sGold}: " + boost::lexical_cast<std::string>(playerGold));
}
// --------------------------------------------------------------------------------------------------
DialogueWindow::DialogueWindow(MWBase::WindowManager& parWindowManager)
: WindowBase("openmw_dialogue_window.layout", parWindowManager)
, mPersuasionDialog(parWindowManager)
, mEnabled(false)
, mServices(0)
{
// Centre dialog
center();
mPersuasionDialog.setVisible(false);
//History view
getWidget(mHistory, "History");
mHistory->setOverflowToTheLeft(true);
@ -137,6 +212,10 @@ void DialogueWindow::onSelectTopic(std::string topic)
mWindowManager.pushGuiMode(GM_Barter);
mWindowManager.getTradeWindow()->startTrade(mPtr);
}
if (topic == gmst.find("sPersuasion")->getString())
{
mPersuasionDialog.setVisible(true);
}
else if (topic == gmst.find("sSpells")->getString())
{
mWindowManager.pushGuiMode(GM_SpellBuying);
@ -187,6 +266,9 @@ void DialogueWindow::setKeywords(std::list<std::string> keyWords)
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
if (mPtr.getTypeName() == typeid(ESM::NPC).name())
mTopicsList->addItem(gmst.find("sPersuasion")->getString());
if (mServices & Service_Trade)
mTopicsList->addItem(gmst.find("sBarter")->getString());
@ -325,9 +407,12 @@ void DialogueWindow::onFrame()
{
if(mEnabled && mPtr.getTypeName() == typeid(ESM::NPC).name())
{
int disp = std::max(0, std::min(100,
MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr)
+ MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange()));
mDispositionBar->setProgressRange(100);
mDispositionBar->setProgressPosition(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr));
mDispositionBar->setProgressPosition(disp);
mDispositionText->eraseText(0, mDispositionText->getTextLength());
mDispositionText->addText("#B29154"+boost::lexical_cast<std::string>(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr))+std::string("/100")+"#B29154");
mDispositionText->addText("#B29154"+boost::lexical_cast<std::string>(disp)+std::string("/100")+"#B29154");
}
}

@ -26,6 +26,27 @@ namespace MWGui
{
class DialogueHistory;
class PersuasionDialog : public WindowModal
{
public:
PersuasionDialog(MWBase::WindowManager& parWindowManager);
virtual void open();
private:
MyGUI::Button* mCancelButton;
MyGUI::Button* mAdmireButton;
MyGUI::Button* mIntimidateButton;
MyGUI::Button* mTauntButton;
MyGUI::Button* mBribe10Button;
MyGUI::Button* mBribe100Button;
MyGUI::Button* mBribe1000Button;
MyGUI::TextBox* mGoldLabel;
void onCancel (MyGUI::Widget* sender);
void onPersuade (MyGUI::Widget* sender);
};
class DialogueWindow: public WindowBase, public ReferenceInterface
{
public:
@ -86,6 +107,8 @@ namespace MWGui
Widgets::MWList* mTopicsList;
MyGUI::ProgressPtr mDispositionBar;
MyGUI::EditPtr mDispositionText;
PersuasionDialog mPersuasionDialog;
};
}
#endif

@ -28,6 +28,10 @@ namespace MWGui
MWWorld::Ptr getAvatarSelectedItem(int x, int y);
void rebuildAvatar() {
mPreview.rebuild();
}
protected:
MyGUI::Widget* mAvatar;
MyGUI::ImageBox* mAvatarImage;

@ -214,6 +214,29 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
return;
mCurrentRaceId = *raceId;
ESM::NPC record = mPreview->getPrototype();
record.mRace = mCurrentRaceId;
record.setIsMale(mGenderIndex == 0);
std::string prefix =
"b_n_" + mCurrentRaceId + ((record.isMale()) ? "_m_" : "_f_");
record.mHead = prefix + "head_01";
record.mHair = prefix + "hair_01";
const MWWorld::Store<ESM::BodyPart> &parts =
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
if (parts.search(record.mHair) == 0) {
record.mHair = prefix + "hair01";
}
mFaceIndex = 0;
mHairIndex = 0;
mPreview->setPrototype(record);
updateSkills();
updateSpellPowers();
}

@ -34,6 +34,7 @@ namespace MWGui
GM_Female
};
const ESM::NPC &getResult() const { return mPreview->getPrototype(); }
const std::string &getRaceId() const { return mCurrentRaceId; }
Gender getGender() const { return mGenderIndex == 0 ? GM_Male : GM_Female; }
// getFace()

@ -7,6 +7,7 @@
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/dialoguemanager.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/manualref.hpp"
@ -206,7 +207,8 @@ namespace MWGui
if (mCurrentMerchantOffer<0) d = int(100 * (a - b) / a);
else d = int(100 * (b - a) / a);
float clampedDisposition = std::max<int>(0,std::min<int>(int(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr)),100));
float clampedDisposition = std::max<int>(0,std::min<int>(int(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr)
+ MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange()),100));
MWMechanics::NpcStats sellerSkill = MWWorld::Class::get(mPtr).getNpcStats(mPtr);
MWMechanics::CreatureStats sellerStats = MWWorld::Class::get(mPtr).getCreatureStats(mPtr);
@ -232,13 +234,15 @@ namespace MWGui
{
MWBase::Environment::get().getWindowManager()->
messageBox("#{sNotifyMessage9}", std::vector<std::string>());
/// \todo adjust npc temporary disposition by iBarterSuccessDisposition or iBarterFailDisposition
return ;
int iBarterFailDisposition = gmst.find("iBarterFailDisposition")->getInt();
MWBase::Environment::get().getDialogueManager()->applyTemporaryDispositionChange(iBarterFailDisposition);
return;
}
}
/// \todo adjust npc temporary disposition by iBarterSuccessDisposition or iBarterFailDisposition
int iBarterSuccessDisposition = gmst.find("iBarterSuccessDisposition")->getInt();
MWBase::Environment::get().getDialogueManager()->applyTemporaryDispositionChange(iBarterSuccessDisposition);
// success! make the item transfer.
transferBoughtItems();

@ -6,6 +6,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/dialoguemanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/player.hpp"
@ -318,7 +319,7 @@ namespace MWMechanics
mUpdatePlayer = true;
}
void MechanicsManager::setPlayerRace (const std::string& race, bool male)
void MechanicsManager::setPlayerRace (const std::string& race, bool male, const std::string &head, const std::string &hair)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
@ -326,11 +327,9 @@ namespace MWMechanics
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mRace = race;
player.mFlags |= ESM::NPC::Female;
if (male) {
player.mFlags ^= ESM::NPC::Female;
}
player.mHead = head;
player.mHair = hair;
player.setIsMale(male);
world->createRecord(player);
@ -391,13 +390,13 @@ namespace MWMechanics
int MechanicsManager::getDerivedDisposition(const MWWorld::Ptr& ptr)
{
MWMechanics::NpcStats npcSkill = MWWorld::Class::get(ptr).getNpcStats(ptr);
float x = npcSkill.getDisposition();
float x = npcSkill.getBaseDisposition();
MWWorld::LiveCellRef<ESM::NPC>* npc = ptr.get<ESM::NPC>();
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::LiveCellRef<ESM::NPC>* player = playerPtr.get<ESM::NPC>();
MWMechanics::CreatureStats playerStats = MWWorld::Class::get(playerPtr).getCreatureStats(playerPtr);
MWMechanics::NpcStats playerSkill = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr);
MWMechanics::NpcStats playerNpcStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr);
if (toLower(npc->mBase->mRace) == toLower(player->mBase->mRace)) x += MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispRaceMod")->getFloat();
@ -409,21 +408,21 @@ namespace MWMechanics
std::string npcFaction = "";
if(!npcSkill.getFactionRanks().empty()) npcFaction = npcSkill.getFactionRanks().begin()->first;
if (playerSkill.getFactionRanks().find(toLower(npcFaction)) != playerSkill.getFactionRanks().end())
if (playerNpcStats.getFactionRanks().find(toLower(npcFaction)) != playerNpcStats.getFactionRanks().end())
{
for(std::vector<ESM::Faction::Reaction>::const_iterator it = MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(toLower(npcFaction))->mReactions.begin();
it != MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(toLower(npcFaction))->mReactions.end(); it++)
{
if(toLower(it->mFaction) == toLower(npcFaction)) reaction = it->mReaction;
}
rank = playerSkill.getFactionRanks().find(toLower(npcFaction))->second;
rank = playerNpcStats.getFactionRanks().find(toLower(npcFaction))->second;
}
else if (npcFaction != "")
{
for(std::vector<ESM::Faction::Reaction>::const_iterator it = MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(toLower(npcFaction))->mReactions.begin();
it != MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(toLower(npcFaction))->mReactions.end();it++)
{
if(playerSkill.getFactionRanks().find(toLower(it->mFaction)) != playerSkill.getFactionRanks().end() )
if(playerNpcStats.getFactionRanks().find(toLower(it->mFaction)) != playerNpcStats.getFactionRanks().end() )
{
if(it->mReaction<reaction) reaction = it->mReaction;
}
@ -439,10 +438,12 @@ namespace MWMechanics
+ MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispFactionRankBase")->getFloat())
* MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispFactionMod")->getFloat() * reaction;
/// \todo implement bounty and disease
//x -= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispCrimeMod") * pcBounty;
//if (pc has a disease) x += MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispDiseaseMod");
if (playerSkill.getDrawState() == MWMechanics::DrawState_::DrawState_Weapon) x += MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispWeaponDrawn")->getFloat();
x -= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispCrimeMod")->getFloat() * playerNpcStats.getBounty();
if (playerStats.hasCommonDisease() || playerStats.hasBlightDisease())
x += MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispDiseaseMod")->getFloat();
if (playerNpcStats.getDrawState() == MWMechanics::DrawState_::DrawState_Weapon)
x += MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fDispWeaponDrawn")->getFloat();
int effective_disposition = std::max(0,std::min(int(x),100));//, normally clamped to [0..100] when used
return effective_disposition;
@ -460,7 +461,10 @@ namespace MWMechanics
MWMechanics::NpcStats playerSkill = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr);
MWMechanics::CreatureStats playerStats = MWWorld::Class::get(playerPtr).getCreatureStats(playerPtr);
int clampedDisposition = std::min(getDerivedDisposition(ptr),100);
// I suppose the temporary disposition change _has_ to be considered here,
// otherwise one would get different prices when exiting and re-entering the dialogue window...
int clampedDisposition = std::max(0, std::min(getDerivedDisposition(ptr)
+ MWBase::Environment::get().getDialogueManager()->getTemporaryDispositionChange(),100));
float a = std::min(playerSkill.getSkill(ESM::Skill::Mercantile).getModified(), 100.f);
float b = std::min(0.1f * playerStats.getAttribute(ESM::Attribute::Luck).getModified(), 10.f);
float c = std::min(0.2f * playerStats.getAttribute(ESM::Attribute::Personality).getModified(), 10.f);
@ -487,4 +491,152 @@ namespace MWMechanics
{
return mActors.countDeaths (id);
}
void MechanicsManager::getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type,
float currentTemporaryDispositionDelta, bool& success, float& tempChange, float& permChange)
{
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::NpcStats playerSkill = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr);
MWMechanics::CreatureStats playerStats = MWWorld::Class::get(playerPtr).getCreatureStats(playerPtr);
MWMechanics::NpcStats npcSkill = MWWorld::Class::get(npc).getNpcStats(npc);
MWMechanics::CreatureStats npcStats = MWWorld::Class::get(npc).getCreatureStats(npc);
float persTerm = playerStats.getAttribute(ESM::Attribute::Personality).getModified()
/ gmst.find("fPersonalityMod")->getFloat();
float luckTerm = playerStats.getAttribute(ESM::Attribute::Luck).getModified()
/ gmst.find("fLuckMod")->getFloat();
float repTerm = playerSkill.getReputation() * gmst.find("fReputationMod")->getFloat();
float levelTerm = playerStats.getLevel() * gmst.find("fLevelMod")->getFloat();
float fatigueTerm = playerStats.getFatigueTerm();
float playerRating1 = (repTerm + luckTerm + persTerm + playerSkill.getSkill(ESM::Skill::Speechcraft).getModified()) * fatigueTerm;
float playerRating2 = playerRating1 + levelTerm;
float playerRating3 = (playerSkill.getSkill(ESM::Skill::Mercantile).getModified() + luckTerm + persTerm) * fatigueTerm;
float npcRating1 = (repTerm + luckTerm + persTerm + playerSkill.getSkill(ESM::Skill::Speechcraft).getModified()) * fatigueTerm;
float npcRating2 = (levelTerm + repTerm + luckTerm + persTerm + npcSkill.getSkill(ESM::Skill::Speechcraft).getModified()) * fatigueTerm;
float npcRating3 = (playerSkill.getSkill(ESM::Skill::Mercantile).getModified() + repTerm + luckTerm + persTerm) * fatigueTerm;
int currentDisposition = std::min(100, std::max(0, int(getDerivedDisposition(npc) + currentTemporaryDispositionDelta)));
float d = 1 - 0.02 * abs(currentDisposition - 50);
float target1 = d * (playerRating1 - npcRating1 + 50);
float target2 = d * (playerRating2 - npcRating2 + 50);
float bribeMod;
if (type == PT_Bribe10) bribeMod = gmst.find("fBribe10Mod")->getFloat();
if (type == PT_Bribe100) bribeMod = gmst.find("fBribe100Mod")->getFloat();
else bribeMod = gmst.find("fBribe1000Mod")->getFloat();
float target3 = d * (playerRating3 - npcRating3 + 50) + bribeMod;
float iPerMinChance = gmst.find("iPerMinChance")->getInt();
float iPerMinChange = gmst.find("iPerMinChange")->getInt();
float fPerDieRollMult = gmst.find("fPerDieRollMult")->getFloat();
float fPerTempMult = gmst.find("fPerTempMult")->getFloat();
float x,y;
float roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
if (type == PT_Admire)
{
target1 = std::max(iPerMinChance, target1);
success = (roll <= target1);
float c = int(fPerDieRollMult * (target1 - roll));
x = success ? std::max(iPerMinChange, c) : c;
}
else if (type == PT_Intimidate)
{
target2 = std::max(iPerMinChance, target2);
success = (roll <= target2);
float r;
if (roll != target2)
r = int(target2 - roll);
else
r = 1;
if (roll <= target2)
{
float s = int(r * fPerDieRollMult * fPerTempMult);
npcStats.setAiSetting (2, std::max(0, std::min(100, npcStats.getAiSetting (2) + int(std::max(iPerMinChange, s)))));
npcStats.setAiSetting (1, std::max(0, std::min(100, npcStats.getAiSetting (1) + int(std::min(-iPerMinChange, -s)))));
}
float c = -std::abs(int(r * fPerDieRollMult));
if (success)
{
if (std::abs(c) < iPerMinChange)
{
x = 0;
y = -iPerMinChange;
}
else
{
x = -int(c * fPerTempMult);
y = c;
}
}
else
{
x = int(c * fPerTempMult);
y = c;
}
}
else if (type == PT_Taunt)
{
target1 = std::max(iPerMinChance, target1);
success = (roll <= target1);
float c = std::abs(int(target1 - roll));
if (roll <= target1)
{
float s = c * fPerDieRollMult * fPerTempMult;
npcStats.setAiSetting (2, std::max(0, std::min(100, npcStats.getAiSetting (2) + std::min(-int(iPerMinChange), int(-s)))));
npcStats.setAiSetting (1, std::max(0, std::min(100, npcStats.getAiSetting (1) + std::max(int(iPerMinChange), int(s)))));
}
x = int(-c * fPerDieRollMult);
if (success && std::abs(x) < iPerMinChange)
x = -iPerMinChange;
}
else // Bribe
{
target3 = std::max(iPerMinChance, target3);
success = (roll <= target3);
float c = int((target3 - roll) * fPerDieRollMult);
x = success ? std::max(iPerMinChange, c) : c;
}
tempChange = type == PT_Intimidate ? x : int(x * fPerTempMult);
float cappedDispositionChange = tempChange;
if (currentDisposition + tempChange > 100.f)
cappedDispositionChange = 100 - currentDisposition;
if (currentDisposition + tempChange < 0.f)
cappedDispositionChange = -currentDisposition;
permChange = int(cappedDispositionChange / fPerTempMult);
if (type == PT_Intimidate)
{
permChange = success ? -int(cappedDispositionChange/ fPerTempMult) : y;
}
}
}

@ -64,7 +64,7 @@ namespace MWMechanics
virtual void setPlayerName (const std::string& name);
///< Set player name.
virtual void setPlayerRace (const std::string& id, bool male);
virtual void setPlayerRace (const std::string& id, bool male, const std::string &head, const std::string &hair);
///< Set player race.
virtual void setPlayerBirthsign (const std::string& id);
@ -88,6 +88,9 @@ namespace MWMechanics
virtual int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID.
virtual void getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type,
float currentTemporaryDispositionDelta, bool& success, float& tempChange, float& permChange);
///< Perform a persuasion action on NPC
};
}

@ -19,8 +19,7 @@
MWMechanics::NpcStats::NpcStats()
: mMovementFlags (0), mDrawState (DrawState_Nothing), mBounty (0)
, mLevelProgress(0), mDisposition(0), mVampire (0)
, mLevelProgress(0), mDisposition(0), mVampire (0), mReputation(0)
{
mSkillIncreases.resize (ESM::Attribute::Length);
for (int i=0; i<ESM::Attribute::Length; ++i)
@ -37,12 +36,12 @@ void MWMechanics::NpcStats::setDrawState (DrawState_ state)
mDrawState = state;
}
int MWMechanics::NpcStats::getDisposition() const
int MWMechanics::NpcStats::getBaseDisposition() const
{
return mDisposition;
}
void MWMechanics::NpcStats::setDisposition(int disposition)
void MWMechanics::NpcStats::setBaseDisposition(int disposition)
{
mDisposition = disposition;
}
@ -300,3 +299,13 @@ void MWMechanics::NpcStats::setVampire (bool set)
mVampire = set;
}
int MWMechanics::NpcStats::getReputation() const
{
return mReputation;
}
void MWMechanics::NpcStats::setReputation(int reputation)
{
mReputation = reputation;
}

@ -50,6 +50,7 @@ namespace MWMechanics
std::set<std::string> mExpelled;
std::map<std::string, int> mFactionReputation;
bool mVampire;
int mReputation;
int mLevelProgress; // 0-10
@ -65,9 +66,13 @@ namespace MWMechanics
void setDrawState (DrawState_ state);
int getDisposition() const;
int getBaseDisposition() const;
void setDisposition(int disposition);
void setBaseDisposition(int disposition);
int getReputation() const;
void setReputation(int reputation);
bool getMovementFlag (Flag flag) const;

@ -48,8 +48,9 @@ namespace MWRender
mNode->setVisible (false);
mCamera->setPosition(mPosition);
mCamera->lookAt(mLookAt);
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
mCamera->setNearClipDistance (0.01);
mCamera->setFarClipDistance (1000);
@ -80,6 +81,22 @@ namespace MWRender
delete mAnimation;
}
void CharacterPreview::rebuild()
{
assert(mAnimation);
delete mAnimation;
mAnimation = new NpcAnimation(mCharacter, mNode,
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
mNode->setVisible (false);
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
onSetup();
}
// --------------------------------------------------------------------------------------------------
@ -128,8 +145,10 @@ namespace MWRender
RaceSelectionPreview::RaceSelectionPreview()
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
, mRef(&mBase)
{
mBase = *mCharacter.get<ESM::NPC>()->mBase;
mCharacter = MWWorld::Ptr(&mRef, mCharacter.getCell());
}
void RaceSelectionPreview::update(float angle)
@ -141,4 +160,11 @@ namespace MWRender
mNode->setVisible (false);
}
void RaceSelectionPreview::setPrototype(const ESM::NPC &proto)
{
mBase = proto;
mBase.mId = "player";
rebuild();
update(0);
}
}

@ -4,6 +4,7 @@
#include <OgreRenderTarget.h>
#include <OgreMaterialManager.h>
#include <components/esm/loadnpc.hpp>
#include "externalrendering.hpp"
@ -32,6 +33,7 @@ namespace MWRender
virtual void setup (Ogre::SceneManager *sceneManager);
virtual void onSetup();
virtual void rebuild();
protected:
Ogre::TexturePtr mTexture;
@ -77,10 +79,19 @@ namespace MWRender
class RaceSelectionPreview : public CharacterPreview
{
ESM::NPC mBase;
MWWorld::LiveCellRef<ESM::NPC> mRef;
public:
RaceSelectionPreview();
void update(float angle);
const ESM::NPC &getPrototype() const {
return mBase;
}
void setPrototype(const ESM::NPC &proto);
};
}

@ -17,44 +17,54 @@ using namespace NifOgre;
namespace MWRender{
NpcAnimation::~NpcAnimation()
{
removeEntities(head);
removeEntities(hair);
removeEntities(neck);
removeEntities(chest);
removeEntities(groin);
removeEntities(skirt);
removeEntities(rHand);
removeEntities(lHand);
removeEntities(rWrist);
removeEntities(lWrist);
removeEntities(rForearm);
removeEntities(lForearm);
removeEntities(rupperArm);
removeEntities(lupperArm);
removeEntities(rfoot);
removeEntities(lfoot);
removeEntities(rAnkle);
removeEntities(lAnkle);
removeEntities(rKnee);
removeEntities(lKnee);
removeEntities(rUpperLeg);
removeEntities(lUpperLeg);
removeEntities(rclavicle);
removeEntities(lclavicle);
removeEntities(tail);
removeEntities(mHead);
removeEntities(mHair);
removeEntities(mNeck);
removeEntities(mChest);
removeEntities(mGroin);
removeEntities(mSkirt);
removeEntities(mHandL);
removeEntities(mHandR);
removeEntities(mWristL);
removeEntities(mWristR);
removeEntities(mForearmL);
removeEntities(mForearmR);
removeEntities(mUpperArmL);
removeEntities(mUpperArmR);
removeEntities(mFootL);
removeEntities(mFootR);
removeEntities(mAnkleL);
removeEntities(mAnkleR);
removeEntities(mKneeL);
removeEntities(mKneeR);
removeEntities(mUpperLegL);
removeEntities(mUpperLegR);
removeEntities(mClavicleL);
removeEntities(mClavicleR);
removeEntities(mTail);
}
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& _inv, int visibilityFlags)
: Animation(), mStateID(-1), mInv(_inv), timeToChange(0), mVisibilityFlags(visibilityFlags),
robe(mInv.end()), helmet(mInv.end()), shirt(mInv.end()),
cuirass(mInv.end()), greaves(mInv.end()),
leftpauldron(mInv.end()), rightpauldron(mInv.end()),
boots(mInv.end()),
leftglove(mInv.end()), rightglove(mInv.end()), skirtiter(mInv.end()),
pants(mInv.end())
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags)
: Animation(),
mStateID(-1),
mInv(inv),
mTimeToChange(0),
mVisibilityFlags(visibilityFlags),
mRobe(mInv.end()),
mHelmet(mInv.end()),
mShirt(mInv.end()),
mCuirass(mInv.end()),
mGreaves(mInv.end()),
mPauldronL(mInv.end()),
mPauldronR(mInv.end()),
mBoots(mInv.end()),
mPants(mInv.end()),
mGloveL(mInv.end()),
mGloveR(mInv.end()),
mSkirtIter(mInv.end())
{
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
mNpc = ptr.get<ESM::NPC>()->mBase;
for (int init = 0; init < 27; init++)
{
@ -64,24 +74,18 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWor
const MWWorld::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
const ESM::Race *race = store.get<ESM::Race>().find(ref->mBase->mRace);
const ESM::Race *race = store.get<ESM::Race>().find(mNpc->mRace);
std::string hairID = ref->mBase->mHair;
std::string headID = ref->mBase->mHead;
headModel = "meshes\\" + store.get<ESM::BodyPart>().find(headID)->mModel;
hairModel = "meshes\\" + store.get<ESM::BodyPart>().find(hairID)->mModel;
npcName = ref->mBase->mName;
isFemale = !!(ref->mBase->mFlags&ESM::NPC::Female);
isBeast = !!(race->mData.mFlags&ESM::Race::Beast);
bodyRaceID = "b_n_"+ref->mBase->mRace;
std::transform(bodyRaceID.begin(), bodyRaceID.end(), bodyRaceID.begin(), ::tolower);
mHeadModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHead)->mModel;
mHairModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHair)->mModel;
mBodyPrefix = "b_n_" + mNpc->mRace;
std::transform(mBodyPrefix.begin(), mBodyPrefix.end(), mBodyPrefix.begin(), ::tolower);
mInsert = node;
assert(mInsert);
bool isBeast = (race->mData.mFlags & ESM::Race::Beast) != 0;
std::string smodel = (!isBeast ? "meshes\\base_anim.nif" : "meshes\\base_animkna.nif");
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, &mTextKeys, smodel);
@ -125,7 +129,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWor
}
float scale = race->mData.mHeight.mMale;
if (isFemale) {
if (!mNpc->isMale()) {
scale = race->mData.mHeight.mFemale;
}
mInsert->scale(scale, scale, scale);
@ -141,18 +145,18 @@ void NpcAnimation::updateParts()
MWWorld::ContainerStoreIterator *iter;
int slot;
} slotlist[] = {
{ &robe, MWWorld::InventoryStore::Slot_Robe },
{ &skirtiter, MWWorld::InventoryStore::Slot_Skirt },
{ &helmet, MWWorld::InventoryStore::Slot_Helmet },
{ &cuirass, MWWorld::InventoryStore::Slot_Cuirass },
{ &greaves, MWWorld::InventoryStore::Slot_Greaves },
{ &leftpauldron, MWWorld::InventoryStore::Slot_LeftPauldron },
{ &rightpauldron, MWWorld::InventoryStore::Slot_RightPauldron },
{ &boots, MWWorld::InventoryStore::Slot_Boots },
{ &leftglove, MWWorld::InventoryStore::Slot_LeftGauntlet },
{ &rightglove, MWWorld::InventoryStore::Slot_RightGauntlet },
{ &shirt, MWWorld::InventoryStore::Slot_Shirt },
{ &pants, MWWorld::InventoryStore::Slot_Pants },
{ &mRobe, MWWorld::InventoryStore::Slot_Robe },
{ &mSkirtIter, MWWorld::InventoryStore::Slot_Skirt },
{ &mHelmet, MWWorld::InventoryStore::Slot_Helmet },
{ &mCuirass, MWWorld::InventoryStore::Slot_Cuirass },
{ &mGreaves, MWWorld::InventoryStore::Slot_Greaves },
{ &mPauldronL, MWWorld::InventoryStore::Slot_LeftPauldron },
{ &mPauldronR, MWWorld::InventoryStore::Slot_RightPauldron },
{ &mBoots, MWWorld::InventoryStore::Slot_Boots },
{ &mGloveL, MWWorld::InventoryStore::Slot_LeftGauntlet },
{ &mGloveR, MWWorld::InventoryStore::Slot_RightGauntlet },
{ &mShirt, MWWorld::InventoryStore::Slot_Shirt },
{ &mPants, MWWorld::InventoryStore::Slot_Pants },
};
for(size_t i = 0;i < sizeof(slotlist)/sizeof(slotlist[0]);i++)
{
@ -167,9 +171,9 @@ void NpcAnimation::updateParts()
if(apparelChanged)
{
if(robe != mInv.end())
if(mRobe != mInv.end())
{
MWWorld::Ptr ptr = *robe;
MWWorld::Ptr ptr = *mRobe;
const ESM::Clothing *clothes = (ptr.get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
@ -187,9 +191,9 @@ void NpcAnimation::updateParts()
reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
}
if(skirtiter != mInv.end())
if(mSkirtIter != mInv.end())
{
MWWorld::Ptr ptr = *skirtiter;
MWWorld::Ptr ptr = *mSkirtIter;
const ESM::Clothing *clothes = (ptr.get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
@ -199,103 +203,103 @@ void NpcAnimation::updateParts()
reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4);
}
if(helmet != mInv.end())
if(mHelmet != mInv.end())
{
removeIndividualPart(ESM::PRT_Hair);
const ESM::Armor *armor = (helmet->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mHelmet->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts);
}
if(cuirass != mInv.end())
if(mCuirass != mInv.end())
{
const ESM::Armor *armor = (cuirass->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mCuirass->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts);
}
if(greaves != mInv.end())
if(mGreaves != mInv.end())
{
const ESM::Armor *armor = (greaves->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mGreaves->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts);
}
if(leftpauldron != mInv.end())
if(mPauldronL != mInv.end())
{
const ESM::Armor *armor = (leftpauldron->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mPauldronL->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts);
}
if(rightpauldron != mInv.end())
if(mPauldronR != mInv.end())
{
const ESM::Armor *armor = (rightpauldron->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mPauldronR->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts);
}
if(boots != mInv.end())
if(mBoots != mInv.end())
{
if(boots->getTypeName() == typeid(ESM::Clothing).name())
if(mBoots->getTypeName() == typeid(ESM::Clothing).name())
{
const ESM::Clothing *clothes = (boots->get<ESM::Clothing>())->mBase;
const ESM::Clothing *clothes = (mBoots->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Boots, 2, parts);
}
else if(boots->getTypeName() == typeid(ESM::Armor).name())
else if(mBoots->getTypeName() == typeid(ESM::Armor).name())
{
const ESM::Armor *armor = (boots->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mBoots->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts);
}
}
if(leftglove != mInv.end())
if(mGloveL != mInv.end())
{
if(leftglove->getTypeName() == typeid(ESM::Clothing).name())
if(mGloveL->getTypeName() == typeid(ESM::Clothing).name())
{
const ESM::Clothing *clothes = (leftglove->get<ESM::Clothing>())->mBase;
const ESM::Clothing *clothes = (mGloveL->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 2, parts);
}
else
{
const ESM::Armor *armor = (leftglove->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mGloveL->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts);
}
}
if(rightglove != mInv.end())
if(mGloveR != mInv.end())
{
if(rightglove->getTypeName() == typeid(ESM::Clothing).name())
if(mGloveR->getTypeName() == typeid(ESM::Clothing).name())
{
const ESM::Clothing *clothes = (rightglove->get<ESM::Clothing>())->mBase;
const ESM::Clothing *clothes = (mGloveR->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 2, parts);
}
else
{
const ESM::Armor *armor = (rightglove->get<ESM::Armor>())->mBase;
const ESM::Armor *armor = (mGloveR->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 3, parts);
}
}
if(shirt != mInv.end())
if(mShirt != mInv.end())
{
const ESM::Clothing *clothes = (shirt->get<ESM::Clothing>())->mBase;
const ESM::Clothing *clothes = (mShirt->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts);
}
if(pants != mInv.end())
if(mPants != mInv.end())
{
const ESM::Clothing *clothes = (pants->get<ESM::Clothing>())->mBase;
const ESM::Clothing *clothes = (mPants->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Pants, 2, parts);
}
}
if(mPartPriorities[ESM::PRT_Head] < 1)
addOrReplaceIndividualPart(ESM::PRT_Head, -1,1, headModel);
addOrReplaceIndividualPart(ESM::PRT_Head, -1,1, mHeadModel);
if(mPartPriorities[ESM::PRT_Hair] < 1 && mPartPriorities[ESM::PRT_Head] <= 1)
addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1, hairModel);
addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1, mHairModel);
static const struct {
ESM::PartReferenceType type;
@ -329,20 +333,21 @@ void NpcAnimation::updateParts()
if(mPartPriorities[PartTypeList[i].type] < 1)
{
const ESM::BodyPart *part = NULL;
bool tryfemale = isFemale;
int ni = 0;
do {
part = store.get<ESM::BodyPart>().search(bodyRaceID+(tryfemale?"_f_":"_m_")+PartTypeList[i].name[ni]);
if(part) break;
ni ^= 1;
if(ni == 0)
{
if(!tryfemale)
break;
tryfemale = false;
const MWWorld::Store<ESM::BodyPart> &partStore =
store.get<ESM::BodyPart>();
if (!mNpc->isMale()) {
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[0]);
if (part == 0) {
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[1]);
}
} while(1);
}
if (part == 0) {
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[0]);
}
if (part == 0) {
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[1]);
}
if(part)
addOrReplaceIndividualPart(PartTypeList[i].type, -1,1, "meshes\\"+part->mModel);
@ -365,12 +370,12 @@ NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int
void NpcAnimation::runAnimation(float timepassed)
{
if(timeToChange > .2)
if(mTimeToChange > .2)
{
timeToChange = 0;
mTimeToChange = 0;
updateParts();
}
timeToChange += timepassed;
mTimeToChange += timepassed;
Animation::runAnimation(timepassed);
}
@ -395,61 +400,61 @@ void NpcAnimation::removeIndividualPart(int type)
mPartslots[type] = -1;
if(type == ESM::PRT_Head) //0
removeEntities(head);
removeEntities(mHead);
else if(type == ESM::PRT_Hair) //1
removeEntities(hair);
removeEntities(mHair);
else if(type == ESM::PRT_Neck) //2
removeEntities(neck);
removeEntities(mNeck);
else if(type == ESM::PRT_Cuirass)//3
removeEntities(chest);
removeEntities(mChest);
else if(type == ESM::PRT_Groin)//4
removeEntities(groin);
removeEntities(mGroin);
else if(type == ESM::PRT_Skirt)//5
removeEntities(skirt);
removeEntities(mSkirt);
else if(type == ESM::PRT_RHand)//6
removeEntities(rHand);
removeEntities(mHandR);
else if(type == ESM::PRT_LHand)//7
removeEntities(lHand);
removeEntities(mHandL);
else if(type == ESM::PRT_RWrist)//8
removeEntities(rWrist);
removeEntities(mWristR);
else if(type == ESM::PRT_LWrist) //9
removeEntities(lWrist);
removeEntities(mWristL);
else if(type == ESM::PRT_Shield) //10
{
}
else if(type == ESM::PRT_RForearm) //11
removeEntities(rForearm);
removeEntities(mForearmR);
else if(type == ESM::PRT_LForearm) //12
removeEntities(lForearm);
removeEntities(mForearmL);
else if(type == ESM::PRT_RUpperarm) //13
removeEntities(rupperArm);
removeEntities(mUpperArmR);
else if(type == ESM::PRT_LUpperarm) //14
removeEntities(lupperArm);
removeEntities(mUpperArmL);
else if(type == ESM::PRT_RFoot) //15
removeEntities(rfoot);
removeEntities(mFootR);
else if(type == ESM::PRT_LFoot) //16
removeEntities(lfoot);
removeEntities(mFootL);
else if(type == ESM::PRT_RAnkle) //17
removeEntities(rAnkle);
removeEntities(mAnkleR);
else if(type == ESM::PRT_LAnkle) //18
removeEntities(lAnkle);
removeEntities(mAnkleL);
else if(type == ESM::PRT_RKnee) //19
removeEntities(rKnee);
removeEntities(mKneeR);
else if(type == ESM::PRT_LKnee) //20
removeEntities(lKnee);
removeEntities(mKneeL);
else if(type == ESM::PRT_RLeg) //21
removeEntities(rUpperLeg);
removeEntities(mUpperLegR);
else if(type == ESM::PRT_LLeg) //22
removeEntities(lUpperLeg);
removeEntities(mUpperLegL);
else if(type == ESM::PRT_RPauldron) //23
removeEntities(rclavicle);
removeEntities(mClavicleR);
else if(type == ESM::PRT_LPauldron) //24
removeEntities(lclavicle);
removeEntities(mClavicleL);
else if(type == ESM::PRT_Weapon) //25
{
}
else if(type == ESM::PRT_Tail) //26
removeEntities(tail);
removeEntities(mTail);
}
void NpcAnimation::reserveIndividualPart(int type, int group, int priority)
@ -482,83 +487,83 @@ bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority,
switch(type)
{
case ESM::PRT_Head: //0
head = insertBoundedPart(mesh, group, "Head");
mHead = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Hair: //1
hair = insertBoundedPart(mesh, group, "Head");
mHair = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Neck: //2
neck = insertBoundedPart(mesh, group, "Neck");
mNeck = insertBoundedPart(mesh, group, "Neck");
break;
case ESM::PRT_Cuirass: //3
chest = insertBoundedPart(mesh, group, "Chest");
mChest = insertBoundedPart(mesh, group, "Chest");
break;
case ESM::PRT_Groin: //4
groin = insertBoundedPart(mesh, group, "Groin");
mGroin = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_Skirt: //5
skirt = insertBoundedPart(mesh, group, "Groin");
mSkirt = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_RHand: //6
rHand = insertBoundedPart(mesh, group, "Right Hand");
mHandR = insertBoundedPart(mesh, group, "Right Hand");
break;
case ESM::PRT_LHand: //7
lHand = insertBoundedPart(mesh, group, "Left Hand");
mHandL = insertBoundedPart(mesh, group, "Left Hand");
break;
case ESM::PRT_RWrist: //8
rWrist = insertBoundedPart(mesh, group, "Right Wrist");
mWristR = insertBoundedPart(mesh, group, "Right Wrist");
break;
case ESM::PRT_LWrist: //9
lWrist = insertBoundedPart(mesh, group, "Left Wrist");
mWristL = insertBoundedPart(mesh, group, "Left Wrist");
break;
case ESM::PRT_Shield: //10
break;
case ESM::PRT_RForearm: //11
rForearm = insertBoundedPart(mesh, group, "Right Forearm");
mForearmR = insertBoundedPart(mesh, group, "Right Forearm");
break;
case ESM::PRT_LForearm: //12
lForearm = insertBoundedPart(mesh, group, "Left Forearm");
mForearmL = insertBoundedPart(mesh, group, "Left Forearm");
break;
case ESM::PRT_RUpperarm: //13
rupperArm = insertBoundedPart(mesh, group, "Right Upper Arm");
mUpperArmR = insertBoundedPart(mesh, group, "Right Upper Arm");
break;
case ESM::PRT_LUpperarm: //14
lupperArm = insertBoundedPart(mesh, group, "Left Upper Arm");
mUpperArmL = insertBoundedPart(mesh, group, "Left Upper Arm");
break;
case ESM::PRT_RFoot: //15
rfoot = insertBoundedPart(mesh, group, "Right Foot");
mFootR = insertBoundedPart(mesh, group, "Right Foot");
break;
case ESM::PRT_LFoot: //16
lfoot = insertBoundedPart(mesh, group, "Left Foot");
mFootL = insertBoundedPart(mesh, group, "Left Foot");
break;
case ESM::PRT_RAnkle: //17
rAnkle = insertBoundedPart(mesh, group, "Right Ankle");
mAnkleR = insertBoundedPart(mesh, group, "Right Ankle");
break;
case ESM::PRT_LAnkle: //18
lAnkle = insertBoundedPart(mesh, group, "Left Ankle");
mAnkleL = insertBoundedPart(mesh, group, "Left Ankle");
break;
case ESM::PRT_RKnee: //19
rKnee = insertBoundedPart(mesh, group, "Right Knee");
mKneeR = insertBoundedPart(mesh, group, "Right Knee");
break;
case ESM::PRT_LKnee: //20
lKnee = insertBoundedPart(mesh, group, "Left Knee");
mKneeL = insertBoundedPart(mesh, group, "Left Knee");
break;
case ESM::PRT_RLeg: //21
rUpperLeg = insertBoundedPart(mesh, group, "Right Upper Leg");
mUpperLegR = insertBoundedPart(mesh, group, "Right Upper Leg");
break;
case ESM::PRT_LLeg: //22
lUpperLeg = insertBoundedPart(mesh, group, "Left Upper Leg");
mUpperLegL = insertBoundedPart(mesh, group, "Left Upper Leg");
break;
case ESM::PRT_RPauldron: //23
rclavicle = insertBoundedPart(mesh , group, "Right Clavicle");
mClavicleR = insertBoundedPart(mesh , group, "Right Clavicle");
break;
case ESM::PRT_LPauldron: //24
lclavicle = insertBoundedPart(mesh, group, "Left Clavicle");
mClavicleL = insertBoundedPart(mesh, group, "Left Clavicle");
break;
case ESM::PRT_Weapon: //25
break;
case ESM::PRT_Tail: //26
tail = insertBoundedPart(mesh, group, "Tail");
mTail = insertBoundedPart(mesh, group, "Tail");
break;
}
return true;
@ -570,14 +575,14 @@ void NpcAnimation::addPartGroup(int group, int priority, std::vector<ESM::PartRe
{
ESM::PartReference &part = parts[i];
const MWWorld::Store<ESM::BodyPart> &parts =
const MWWorld::Store<ESM::BodyPart> &partStore =
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
const ESM::BodyPart *bodypart = 0;
if(isFemale)
bodypart = parts.search(part.mFemale);
if(!mNpc->isMale())
bodypart = partStore.search(part.mFemale);
if(!bodypart)
bodypart = parts.search(part.mMale);
bodypart = partStore.search(part.mMale);
if(bodypart)
addOrReplaceIndividualPart(part.mPart, group, priority,"meshes\\" + bodypart->mModel);

@ -8,6 +8,11 @@
#include "../mwclass/npc.hpp"
#include "../mwworld/containerstore.hpp"
namespace ESM
{
struct NPC;
}
namespace MWRender{
class NpcAnimation: public Animation{
@ -19,57 +24,57 @@ private:
int mPartPriorities[27];
//Bounded Parts
NifOgre::EntityList lclavicle;
NifOgre::EntityList rclavicle;
NifOgre::EntityList rupperArm;
NifOgre::EntityList lupperArm;
NifOgre::EntityList rUpperLeg;
NifOgre::EntityList lUpperLeg;
NifOgre::EntityList lForearm;
NifOgre::EntityList rForearm;
NifOgre::EntityList lWrist;
NifOgre::EntityList rWrist;
NifOgre::EntityList rKnee;
NifOgre::EntityList lKnee;
NifOgre::EntityList neck;
NifOgre::EntityList rAnkle;
NifOgre::EntityList lAnkle;
NifOgre::EntityList groin;
NifOgre::EntityList skirt;
NifOgre::EntityList lfoot;
NifOgre::EntityList rfoot;
NifOgre::EntityList hair;
NifOgre::EntityList rHand;
NifOgre::EntityList lHand;
NifOgre::EntityList head;
NifOgre::EntityList chest;
NifOgre::EntityList tail;
NifOgre::EntityList mClavicleL;
NifOgre::EntityList mClavicleR;
NifOgre::EntityList mUpperArmL;
NifOgre::EntityList mUpperArmR;
NifOgre::EntityList mUpperLegL;
NifOgre::EntityList mUpperLegR;
NifOgre::EntityList mForearmL;
NifOgre::EntityList mForearmR;
NifOgre::EntityList mWristL;
NifOgre::EntityList mWristR;
NifOgre::EntityList mKneeR;
NifOgre::EntityList mKneeL;
NifOgre::EntityList mNeck;
NifOgre::EntityList mAnkleL;
NifOgre::EntityList mAnkleR;
NifOgre::EntityList mGroin;
NifOgre::EntityList mSkirt;
NifOgre::EntityList mFootL;
NifOgre::EntityList mFootR;
NifOgre::EntityList mHair;
NifOgre::EntityList mHandL;
NifOgre::EntityList mHandR;
NifOgre::EntityList mHead;
NifOgre::EntityList mChest;
NifOgre::EntityList mTail;
const ESM::NPC *mNpc;
std::string mHeadModel;
std::string mHairModel;
std::string mBodyPrefix;
bool isBeast;
bool isFemale;
std::string headModel;
std::string hairModel;
std::string npcName;
std::string bodyRaceID;
float timeToChange;
MWWorld::ContainerStoreIterator robe;
MWWorld::ContainerStoreIterator helmet;
MWWorld::ContainerStoreIterator shirt;
MWWorld::ContainerStoreIterator cuirass;
MWWorld::ContainerStoreIterator greaves;
MWWorld::ContainerStoreIterator leftpauldron;
MWWorld::ContainerStoreIterator rightpauldron;
MWWorld::ContainerStoreIterator boots;
MWWorld::ContainerStoreIterator pants;
MWWorld::ContainerStoreIterator leftglove;
MWWorld::ContainerStoreIterator rightglove;
MWWorld::ContainerStoreIterator skirtiter;
float mTimeToChange;
MWWorld::ContainerStoreIterator mRobe;
MWWorld::ContainerStoreIterator mHelmet;
MWWorld::ContainerStoreIterator mShirt;
MWWorld::ContainerStoreIterator mCuirass;
MWWorld::ContainerStoreIterator mGreaves;
MWWorld::ContainerStoreIterator mPauldronL;
MWWorld::ContainerStoreIterator mPauldronR;
MWWorld::ContainerStoreIterator mBoots;
MWWorld::ContainerStoreIterator mPants;
MWWorld::ContainerStoreIterator mGloveL;
MWWorld::ContainerStoreIterator mGloveR;
MWWorld::ContainerStoreIterator mSkirtIter;
int mVisibilityFlags;
public:
NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node,
MWWorld::InventoryStore& _inv, int visibilityFlags);
MWWorld::InventoryStore& inv, int visibilityFlags);
virtual ~NpcAnimation();
NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename);
virtual void runAnimation(float timepassed);

@ -18,6 +18,7 @@ namespace MWRender
: mCamera(camera),
mPlayerNode(node),
mCameraNode(mPlayerNode->createChildSceneNode()),
mAnimation(0),
mFirstPersonView(true),
mPreviewMode(false),
mFreeLook(true),
@ -309,6 +310,9 @@ namespace MWRender
void Player::setAnimation(NpcAnimation *anim)
{
if (mAnimation) {
delete mAnimation;
}
mAnimation = anim;
}

@ -801,7 +801,21 @@ namespace MWWorld
const ESM::NPC *World::createRecord(const ESM::NPC &record)
{
return mStore.insert(record);
bool update = false;
if (StringUtils::ciEqual(record.mId, "player")) {
const ESM::NPC *player =
mPlayer->getPlayer().get<ESM::NPC>()->mBase;
update = record.isMale() != player->isMale() ||
!StringUtils::ciEqual(record.mRace, player->mRace) ||
!StringUtils::ciEqual(record.mHead, player->mHead) ||
!StringUtils::ciEqual(record.mHair, player->mHair);
}
const ESM::NPC *ret = mStore.insert(record);
if (update) {
mRendering->renderPlayer(mPlayer->getPlayer());
}
return ret;
}
void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode,

@ -117,6 +117,17 @@ struct NPC
// Implementation moved to load_impl.cpp
void load(ESMReader &esm);
void save(ESMWriter &esm);
bool isMale() const {
return (mFlags & Female) == 0;
}
void setIsMale(bool value) {
mFlags |= Female;
if (value) {
mFlags ^= Female;
}
}
};
}
#endif

@ -80,6 +80,7 @@ set(MYGUI_FILES
openmw_enchanting_dialog.layout
openmw_trainingwindow.layout
openmw_travel_window.layout
openmw_persuasion_dialog.layout
smallbars.png
VeraMono.ttf
markers.png

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 220 194" name="_Main">
<Widget type="TextBox" skin="NormalText" position="0 6 220 24">
<Property key="Caption" value="#{sPersuasionMenuTitle}"/>
<Property key="TextAlign" value="Center"/>
</Widget>
<Widget type="TextBox" skin="SandText" position="8 156 208 24" name="GoldLabel">
<Property key="TextAlign" value="Left VCenter"/>
</Widget>
<Widget type="Widget" skin="MW_Box" position="8 32 196 115">
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 0 0 18" name="AdmireButton">
<Property key="Caption" value="#{sAdmire}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 18 0 18" name="IntimidateButton">
<Property key="Caption" value="#{sIntimidate}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 36 0 18" name="TauntButton">
<Property key="Caption" value="#{sTaunt}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 54 0 18" name="Bribe10Button">
<Property key="Caption" value="#{sBribe 10 Gold}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 72 0 18" name="Bribe100Button">
<Property key="Caption" value="#{sBribe 100 Gold}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="AutoSizedButton" skin="SandTextButton" position="4 90 0 18" name="Bribe1000Button">
<Property key="Caption" value="#{sBribe 1000 Gold}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
</Widget>
<Widget type="AutoSizedButton" skin="MW_Button" position="204 156 0 24" name="CancelButton">
<Property key="ExpandDirection" value="Left"/>
<Property key="Caption" value="#{sCancel}"/>
</Widget>
</Widget>
</MyGUI>
Loading…
Cancel
Save