Merge remote-tracking branch 'dteviot/MagicEffectsRefactorDraft3'

This commit is contained in:
Marc Zinnschlag 2015-08-23 12:11:30 +02:00
commit a52b947efe
74 changed files with 376 additions and 259 deletions

View file

@ -78,7 +78,7 @@ add_openmw_dir (mwclass
) )
add_openmw_dir (mwmechanics add_openmw_dir (mwmechanics
mechanicsmanagerimp stat creaturestats magiceffects movement mechanicsmanagerimp stat creaturestats magiceffects movement actorutil
drawstate spells activespells npcstats aipackage aisequence aipursue alchemy aiwander aitravel aifollow aiavoiddoor drawstate spells activespells npcstats aipackage aisequence aipursue alchemy aiwander aitravel aifollow aiavoiddoor
aiescort aiactivate aicombat repair enchanting pathfinding pathgrid security spellsuccess spellcasting aiescort aiactivate aicombat repair enchanting pathfinding pathgrid security spellsuccess spellcasting
disease pickpocket levelledlist combat steering obstacle autocalcspell difficultyscaling aicombataction actor summoning disease pickpocket levelledlist combat steering obstacle autocalcspell difficultyscaling aicombataction actor summoning

View file

@ -704,8 +704,8 @@ void OMW::Engine::activate()
return; return;
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr(); MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
if (player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0 const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
|| player.getClass().getCreatureStats(player).getKnockedDown()) if (playerStats.isParalyzed() || playerStats.getKnockedDown())
return; return;
MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject(); MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject();

View file

@ -20,6 +20,7 @@
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
@ -244,7 +245,7 @@ namespace MWClass
typeText = "#{sHeavy}"; typeText = "#{sHeavy}";
text += "\n#{sArmorRating}: " + MWGui::ToolTips::toString(getEffectiveArmorRating(ptr, text += "\n#{sArmorRating}: " + MWGui::ToolTips::toString(getEffectiveArmorRating(ptr,
MWBase::Environment::get().getWorld()->getPlayerPtr())); MWMechanics::getPlayer()));
int remainingHealth = getItemHealth(ptr); int remainingHealth = getItemHealth(ptr);
text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/" text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/"

View file

@ -36,6 +36,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/combat.hpp" #include "../mwmechanics/combat.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace namespace
{ {
@ -344,7 +345,7 @@ namespace MWClass
if(!object.isEmpty()) if(!object.isEmpty())
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object)); getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
if(setOnPcHitMe && !attacker.isEmpty() && attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
{ {
const std::string &script = ptr.get<ESM::Creature>()->mBase->mScript; const std::string &script = ptr.get<ESM::Creature>()->mBase->mScript;
/* Set the OnPCHitMe script variable. The script is responsible for clearing it. */ /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */
@ -603,11 +604,9 @@ namespace MWClass
{ {
float weight = getContainerStore (ptr).getWeight(); float weight = getContainerStore (ptr).getWeight();
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); const MWMechanics::MagicEffects& effects = getCreatureStats(ptr).getMagicEffects();
weight -= effects.get(ESM::MagicEffect::Feather).getMagnitude();
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Feather)).getMagnitude(); weight += effects.get(ESM::MagicEffect::Burden).getMagnitude();
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Burden)).getMagnitude();
if (weight<0) if (weight<0)
weight = 0; weight = 0;

View file

@ -26,6 +26,8 @@
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace namespace
{ {
struct DoorCustomData : public MWWorld::CustomData struct DoorCustomData : public MWWorld::CustomData
@ -126,7 +128,7 @@ namespace MWClass
if (needKey && hasKey) if (needKey && hasKey)
{ {
if(actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(actor == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}"); MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}");
unlock(ptr); //Call the function here. because that makes sense. unlock(ptr); //Call the function here. because that makes sense.
// using a key disarms the trap // using a key disarms the trap

View file

@ -24,6 +24,7 @@
#include "../mwmechanics/autocalcspell.hpp" #include "../mwmechanics/autocalcspell.hpp"
#include "../mwmechanics/difficultyscaling.hpp" #include "../mwmechanics/difficultyscaling.hpp"
#include "../mwmechanics/character.hpp" #include "../mwmechanics/character.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp" #include "../mwworld/actiontalk.hpp"
@ -503,7 +504,7 @@ namespace MWClass
if(otherstats.isDead()) // Can't hit dead actors if(otherstats.isDead()) // Can't hit dead actors
return; return;
if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(ptr == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->setEnemy(victim); MWBase::Environment::get().getWindowManager()->setEnemy(victim);
int weapskill = ESM::Skill::HandToHand; int weapskill = ESM::Skill::HandToHand;
@ -542,7 +543,7 @@ namespace MWClass
{ {
MWMechanics::getHandToHandDamage(ptr, victim, damage, healthdmg, attackStrength); MWMechanics::getHandToHandDamage(ptr, victim, damage, healthdmg, attackStrength);
} }
if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(ptr == MWMechanics::getPlayer())
{ {
skillUsageSucceeded(ptr, weapskill, 0); skillUsageSucceeded(ptr, weapskill, 0);
@ -608,7 +609,7 @@ namespace MWClass
if(!object.isEmpty()) if(!object.isEmpty())
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object)); getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
if(setOnPcHitMe && !attacker.isEmpty() && attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
{ {
const std::string &script = ptr.getClass().getScript(ptr); const std::string &script = ptr.getClass().getScript(ptr);
/* Set the OnPCHitMe script variable. The script is responsible for clearing it. */ /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */
@ -700,7 +701,7 @@ namespace MWClass
if (armorhealth == 0) if (armorhealth == 0)
armor = *inv.unequipItem(armor, ptr); armor = *inv.unequipItem(armor, ptr);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
skillUsageSucceeded(ptr, armor.getClass().getEquipmentSkill(armor), 0); skillUsageSucceeded(ptr, armor.getClass().getEquipmentSkill(armor), 0);
switch(armor.getClass().getEquipmentSkill(armor)) switch(armor.getClass().getEquipmentSkill(armor))
@ -716,7 +717,7 @@ namespace MWClass
break; break;
} }
} }
else if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) else if(ptr == MWMechanics::getPlayer())
skillUsageSucceeded(ptr, ESM::Skill::Unarmored, 0); skillUsageSucceeded(ptr, ESM::Skill::Unarmored, 0);
} }
} }
@ -729,7 +730,7 @@ namespace MWClass
if(damage > 0.0f) if(damage > 0.0f)
{ {
sndMgr->playSound3D(ptr, "Health Damage", 1.0f, 1.0f); sndMgr->playSound3D(ptr, "Health Damage", 1.0f, 1.0f);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->activateHitOverlay(); MWBase::Environment::get().getWindowManager()->activateHitOverlay();
} }
MWMechanics::DynamicStat<float> health(getCreatureStats(ptr).getHealth()); MWMechanics::DynamicStat<float> health(getCreatureStats(ptr).getHealth());
@ -783,7 +784,7 @@ namespace MWClass
const MWWorld::Ptr& actor) const const MWWorld::Ptr& actor) const
{ {
// player got activated by another NPC // player got activated by another NPC
if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(ptr == MWMechanics::getPlayer())
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionTalk(actor)); return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionTalk(actor));
// Werewolfs can't activate NPCs // Werewolfs can't activate NPCs

View file

@ -41,6 +41,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "filter.hpp" #include "filter.hpp"
#include "hypertextparser.hpp" #include "hypertextparser.hpp"
@ -532,7 +533,7 @@ namespace MWDialogue
else if (curDisp + mTemporaryDispositionChange > 100) else if (curDisp + mTemporaryDispositionChange > 100)
mTemporaryDispositionChange = 100 - curDisp; mTemporaryDispositionChange = 100 - curDisp;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().skillUsageSucceeded(player, ESM::Skill::Speechcraft, success ? 0 : 1); player.getClass().skillUsageSucceeded(player, ESM::Skill::Speechcraft, success ? 0 : 1);
if (success) if (success)

View file

@ -17,6 +17,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/magiceffects.hpp" #include "../mwmechanics/magiceffects.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "selectwrapper.hpp" #include "selectwrapper.hpp"
@ -97,7 +98,7 @@ bool MWDialogue::Filter::testActor (const ESM::DialInfo& info) const
bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const
{ {
const MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr player = MWMechanics::getPlayer();
// check player faction // check player faction
if (!info.mPcFaction.empty()) if (!info.mPcFaction.empty())
@ -219,7 +220,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
case SelectWrapper::Function_PcHealthPercent: case SelectWrapper::Function_PcHealthPercent:
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
float ratio = player.getClass().getCreatureStats (player).getHealth().getCurrent() / float ratio = player.getClass().getCreatureStats (player).getHealth().getCurrent() /
player.getClass().getCreatureStats (player).getHealth().getModified(); player.getClass().getCreatureStats (player).getHealth().getModified();
@ -229,7 +230,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
case SelectWrapper::Function_PcDynamicStat: case SelectWrapper::Function_PcDynamicStat:
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
float value = player.getClass().getCreatureStats (player). float value = player.getClass().getCreatureStats (player).
getDynamic (select.getArgument()).getCurrent(); getDynamic (select.getArgument()).getCurrent();
@ -253,7 +254,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) const int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) const
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
switch (select.getFunction()) switch (select.getFunction())
{ {
@ -429,7 +430,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) const bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) const
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
switch (select.getFunction()) switch (select.getFunction())
{ {
@ -532,7 +533,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
case SelectWrapper::Function_ShouldAttack: case SelectWrapper::Function_ShouldAttack:
return MWBase::Environment::get().getMechanicsManager()->isAggressive(mActor, return MWBase::Environment::get().getMechanicsManager()->isAggressive(mActor,
MWBase::Environment::get().getWorld()->getPlayerPtr()); MWMechanics::getPlayer());
case SelectWrapper::Function_Werewolf: case SelectWrapper::Function_Werewolf:

View file

@ -11,6 +11,7 @@
#include "../mwmechanics/magiceffects.hpp" #include "../mwmechanics/magiceffects.hpp"
#include "../mwmechanics/alchemy.hpp" #include "../mwmechanics/alchemy.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
@ -124,9 +125,9 @@ namespace MWGui
void AlchemyWindow::open() void AlchemyWindow::open()
{ {
mAlchemy->setAlchemist (MWBase::Environment::get().getWorld()->getPlayerPtr()); mAlchemy->setAlchemist (MWMechanics::getPlayer());
InventoryItemModel* model = new InventoryItemModel(MWBase::Environment::get().getWorld()->getPlayerPtr()); InventoryItemModel* model = new InventoryItemModel(MWMechanics::getPlayer());
mSortModel = new SortFilterItemModel(model); mSortModel = new SortFilterItemModel(model);
mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients); mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients);
mItemView->setModel (mSortModel); mItemView->setModel (mSortModel);
@ -136,7 +137,7 @@ namespace MWGui
int index = 0; int index = 0;
mAlchemy->setAlchemist (MWBase::Environment::get().getWorld()->getPlayerPtr()); mAlchemy->setAlchemist (MWMechanics::getPlayer());
for (MWMechanics::Alchemy::TToolsIterator iter (mAlchemy->beginTools()); for (MWMechanics::Alchemy::TToolsIterator iter (mAlchemy->beginTools());
iter!=mAlchemy->endTools() && index<static_cast<int> (mApparatus.size()); ++iter, ++index) iter!=mAlchemy->endTools() && index<static_cast<int> (mApparatus.size()); ++iter, ++index)

View file

@ -9,6 +9,8 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/actiontake.hpp" #include "../mwworld/actiontake.hpp"
#include "formatting.hpp" #include "formatting.hpp"
@ -123,7 +125,7 @@ namespace MWGui
MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0); MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0);
MWWorld::ActionTake take(mBook); MWWorld::ActionTake take(mBook);
take.execute (MWBase::Environment::get().getWorld()->getPlayerPtr()); take.execute (MWMechanics::getPlayer());
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Book); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Book);
} }

View file

@ -7,6 +7,7 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/fallback.hpp" #include "../mwworld/fallback.hpp"
@ -51,7 +52,7 @@ namespace
void updatePlayerHealth() void updatePlayerHealth()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player);
npcStats.updateHealth(); npcStats.updateHealth();
} }
@ -228,7 +229,7 @@ namespace MWGui
mReviewDialog->setBirthSign(mPlayerBirthSignId); mReviewDialog->setBirthSign(mPlayerBirthSignId);
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
mReviewDialog->setHealth ( stats.getHealth() ); mReviewDialog->setHealth ( stats.getHealth() );

View file

@ -9,6 +9,7 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/dialoguemanager.hpp" #include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
@ -137,7 +138,7 @@ namespace MWGui
if (mPtr.getTypeName() == typeid(ESM::NPC).name() && !loot) if (mPtr.getTypeName() == typeid(ESM::NPC).name() && !loot)
{ {
// we are stealing stuff // we are stealing stuff
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
mModel = new PickpocketItemModel(player, new InventoryItemModel(container), mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown()); !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
} }
@ -183,7 +184,7 @@ namespace MWGui
&& !mPickpocketDetected && !mPickpocketDetected
) )
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mPtr); MWMechanics::Pickpocket pickpocket(player, mPtr);
if (pickpocket.finish()) if (pickpocket.finish())
{ {
@ -260,7 +261,7 @@ namespace MWGui
bool ContainerWindow::onTakeItem(const ItemStack &item, int count) bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
// TODO: move to ItemModels // TODO: move to ItemModels
if (dynamic_cast<PickpocketItemModel*>(mModel) if (dynamic_cast<PickpocketItemModel*>(mModel)
&& !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown()) && !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown())

View file

@ -21,6 +21,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "widgets.hpp" #include "widgets.hpp"
#include "bookpage.hpp" #include "bookpage.hpp"
@ -89,7 +90,7 @@ namespace MWGui
WindowModal::open(); WindowModal::open();
center(); center();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
mBribe10Button->setEnabled (playerGold >= 10); mBribe10Button->setEnabled (playerGold >= 10);

View file

@ -18,6 +18,8 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "itemselection.hpp" #include "itemselection.hpp"
#include "itemwidget.hpp" #include "itemwidget.hpp"
@ -160,7 +162,7 @@ namespace MWGui
void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem) void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
mEnchanting.setSelfEnchanting(true); mEnchanting.setSelfEnchanting(true);
mEnchanting.setEnchanter(player); mEnchanting.setEnchanter(player);
@ -208,7 +210,7 @@ namespace MWGui
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);
mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayerPtr()); mItemSelectionDialog->openContainer(MWMechanics::getPlayer());
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyEnchantable); mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyEnchantable);
} }
else else
@ -263,7 +265,7 @@ namespace MWGui
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected); mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel);
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);
mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayerPtr()); mItemSelectionDialog->openContainer(MWMechanics::getPlayer());
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyChargedSoulstones); mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyChargedSoulstones);
//MWBase::Environment::get().getWindowManager()->messageBox("#{sInventorySelectNoSoul}"); //MWBase::Environment::get().getWindowManager()->messageBox("#{sInventorySelectNoSoul}");
@ -324,7 +326,7 @@ namespace MWGui
mEnchanting.setNewItemName(mName->getCaption()); mEnchanting.setNewItemName(mName->getCaption());
mEnchanting.setEffect(mEffectList); mEnchanting.setEffect(mEffectList);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
if (mPtr != player && mEnchanting.getEnchantPrice() > playerGold) if (mPtr != player && mEnchanting.getEnchantPrice() > playerGold)
{ {

View file

@ -18,6 +18,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
#include "spellicons.hpp" #include "spellicons.hpp"
@ -259,7 +260,7 @@ namespace MWGui
{ {
// drop item into the gameworld // drop item into the gameworld
MWBase::Environment::get().getWorld()->breakInvisibility( MWBase::Environment::get().getWorld()->breakInvisibility(
MWBase::Environment::get().getWorld()->getPlayerPtr()); MWMechanics::getPlayer());
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition(); MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
@ -338,7 +339,7 @@ namespace MWGui
void HUD::onWeaponClicked(MyGUI::Widget* _sender) void HUD::onWeaponClicked(MyGUI::Widget* _sender)
{ {
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf()) if (player.getClass().getNpcStats(player).isWerewolf())
{ {
MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}");
@ -350,7 +351,7 @@ namespace MWGui
void HUD::onMagicClicked(MyGUI::Widget* _sender) void HUD::onMagicClicked(MyGUI::Widget* _sender)
{ {
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf()) if (player.getClass().getNpcStats(player).isWerewolf())
{ {
MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}");

View file

@ -29,6 +29,8 @@
#include "../mwscript/interpretercontext.hpp" #include "../mwscript/interpretercontext.hpp"
#include "../mwrender/characterpreview.hpp" #include "../mwrender/characterpreview.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "itemview.hpp" #include "itemview.hpp"
#include "inventoryitemmodel.hpp" #include "inventoryitemmodel.hpp"
#include "sortfilteritemmodel.hpp" #include "sortfilteritemmodel.hpp"
@ -63,7 +65,7 @@ namespace MWGui
, mGuiMode(GM_Inventory) , mGuiMode(GM_Inventory)
, mLastXSize(0) , mLastXSize(0)
, mLastYSize(0) , mLastYSize(0)
, mPreview(new MWRender::InventoryPreview(viewer, resourceSystem, MWBase::Environment::get().getWorld()->getPlayerPtr())) , mPreview(new MWRender::InventoryPreview(viewer, resourceSystem, MWMechanics::getPlayer()))
, mTrading(false) , mTrading(false)
{ {
mPreviewTexture.reset(new osgMyGUI::OSGTexture(mPreview->getTexture())); mPreviewTexture.reset(new osgMyGUI::OSGTexture(mPreview->getTexture()));
@ -333,7 +335,7 @@ namespace MWGui
void InventoryWindow::open() void InventoryWindow::open()
{ {
mPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); mPtr = MWMechanics::getPlayer();
updateEncumbranceBar(); updateEncumbranceBar();
@ -439,7 +441,7 @@ namespace MWGui
{ {
const std::string& script = ptr.getClass().getScript(ptr); const std::string& script = ptr.getClass().getScript(ptr);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
// early-out for items that need to be equipped, but can't be equipped: we don't want to set OnPcEquip in that case // early-out for items that need to be equipped, but can't be equipped: we don't want to set OnPcEquip in that case
if (!ptr.getClass().getEquipmentSlots(ptr).first.empty()) if (!ptr.getClass().getEquipmentSlots(ptr).first.empty())
@ -549,7 +551,7 @@ namespace MWGui
void InventoryWindow::updateEncumbranceBar() void InventoryWindow::updateEncumbranceBar()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
float capacity = player.getClass().getCapacity(player); float capacity = player.getClass().getCapacity(player);
float encumbrance = player.getClass().getEncumbrance(player); float encumbrance = player.getClass().getEncumbrance(player);
@ -583,7 +585,7 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->updateSpellWindow(); MWBase::Environment::get().getWindowManager()->updateSpellWindow();
MWBase::Environment::get().getMechanicsManager()->updateMagicEffects( MWBase::Environment::get().getMechanicsManager()->updateMagicEffects(
MWBase::Environment::get().getWorld()->getPlayerPtr()); MWMechanics::getPlayer());
dirtyPreview(); dirtyPreview();
} }
@ -614,7 +616,7 @@ namespace MWGui
int count = object.getRefData().getCount(); int count = object.getRefData().getCount();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getWorld()->breakInvisibility(player); MWBase::Environment::get().getWorld()->breakInvisibility(player);
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, object, MWWorld::Ptr(), count); MWBase::Environment::get().getMechanicsManager()->itemTaken(player, object, MWWorld::Ptr(), count);
@ -644,7 +646,7 @@ namespace MWGui
{ {
ItemModel::ModelIndex selected = -1; ItemModel::ModelIndex selected = -1;
// not using mSortFilterModel as we only need sorting, not filtering // not using mSortFilterModel as we only need sorting, not filtering
SortFilterItemModel model(new InventoryItemModel(MWBase::Environment::get().getWorld()->getPlayerPtr())); SortFilterItemModel model(new InventoryItemModel(MWMechanics::getPlayer()));
model.setSortByType(false); model.setSortByType(false);
model.update(); model.update();
if (model.getItemCount() == 0) if (model.getItemCount() == 0)

View file

@ -8,6 +8,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/store.hpp" #include "../mwworld/store.hpp"
@ -57,7 +58,7 @@ namespace MWGui
if (mFadeTimeRemaining <= 0) if (mFadeTimeRemaining <= 0)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker"); MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker");
setVisible(true); setVisible(true);
@ -76,7 +77,7 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Jail); MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Jail);
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5); MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getWorld()->advanceTime(mDays * 24); MWBase::Environment::get().getWorld()->advanceTime(mDays * 24);
for (int i=0; i<mDays*24; ++i) for (int i=0; i<mDays*24; ++i)

View file

@ -16,6 +16,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWGui namespace MWGui
{ {
@ -203,7 +204,7 @@ namespace MWGui
void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender) void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player); MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats (player);
if (mSpentAttributes.size() < mCoinCount) if (mSpentAttributes.size() < mCoinCount)

View file

@ -13,6 +13,7 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
@ -40,7 +41,7 @@ void MerchantRepair::startRepair(const MWWorld::Ptr &actor)
int currentY = 0; int currentY = 0;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
@ -125,7 +126,7 @@ void MerchantRepair::exit()
void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender) void MerchantRepair::onRepairButtonClick(MyGUI::Widget *sender)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int price = MyGUI::utility::parseInt(sender->getUserString("Price")); int price = MyGUI::utility::parseInt(sender->getUserString("Price"));
if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId)) if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId))

View file

@ -19,6 +19,7 @@
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwgui/inventorywindow.hpp" #include "../mwgui/inventorywindow.hpp"
@ -147,7 +148,7 @@ namespace MWGui
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel); mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel);
} }
mItemSelectionDialog->setVisible(true); mItemSelectionDialog->setVisible(true);
mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayerPtr()); mItemSelectionDialog->openContainer(MWMechanics::getPlayer());
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyUsableItems); mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyUsableItems);
mAssignDialog->setVisible (false); mAssignDialog->setVisible (false);
@ -262,7 +263,7 @@ namespace MWGui
QuickKeyType type = mAssigned[index-1]; QuickKeyType type = mAssigned[index-1];
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
if (type == Type_Item || type == Type_MagicItem) if (type == Type_Item || type == Type_MagicItem)
@ -474,7 +475,7 @@ namespace MWGui
case Type_MagicItem: case Type_MagicItem:
{ {
// Find the item by id // Find the item by id
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
MWWorld::Ptr item; MWWorld::Ptr item;
for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
@ -544,7 +545,7 @@ namespace MWGui
{ {
WindowModal::open(); WindowModal::open();
mMagicList->setModel(new SpellModel(MWBase::Environment::get().getWorld()->getPlayerPtr())); mMagicList->setModel(new SpellModel(MWMechanics::getPlayer()));
mMagicList->resetScrollbars(); mMagicList->resetScrollbars();
} }

View file

@ -17,6 +17,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "widgets.hpp" #include "widgets.hpp"
#include "itemwidget.hpp" #include "itemwidget.hpp"
@ -92,7 +93,7 @@ void Recharge::updateView()
int currentY = 0; int currentY = 0;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
for (MWWorld::ContainerStoreIterator iter (store.begin()); for (MWWorld::ContainerStoreIterator iter (store.begin());
iter!=store.end(); ++iter) iter!=store.end(); ++iter)
@ -147,7 +148,7 @@ void Recharge::onItemClicked(MyGUI::Widget *sender)
MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>(); MWWorld::Ptr item = *sender->getUserData<MWWorld::Ptr>();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player); MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats(player);

View file

@ -3,6 +3,8 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWGui namespace MWGui
{ {
ReferenceInterface::ReferenceInterface() ReferenceInterface::ReferenceInterface()
@ -16,7 +18,7 @@ namespace MWGui
void ReferenceInterface::checkReferenceAvailable() void ReferenceInterface::checkReferenceAvailable()
{ {
MWWorld::CellStore* playerCell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); MWWorld::CellStore* playerCell = MWMechanics::getPlayer().getCell();
// check if player has changed cell, or count of the reference has become 0 // check if player has changed cell, or count of the reference has become 0
if ((playerCell != mCurrentPlayerCell && mCurrentPlayerCell != NULL) if ((playerCell != mCurrentPlayerCell && mCurrentPlayerCell != NULL)

View file

@ -9,6 +9,8 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
@ -94,7 +96,7 @@ void Repair::updateRepairView()
int currentY = 0; int currentY = 0;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor;
for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); for (MWWorld::ContainerStoreIterator iter (store.begin(categories));

View file

@ -10,6 +10,8 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/actiontake.hpp" #include "../mwworld/actiontake.hpp"
#include "formatting.hpp" #include "formatting.hpp"
@ -103,7 +105,7 @@ namespace MWGui
MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0); MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0);
MWWorld::ActionTake take(mScroll); MWWorld::ActionTake take(mScroll);
take.execute (MWBase::Environment::get().getWorld()->getPlayerPtr()); take.execute (MWMechanics::getPlayer());
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
} }

View file

@ -15,6 +15,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWGui namespace MWGui
{ {
@ -48,7 +49,7 @@ namespace MWGui
int price = static_cast<int>(spell->mData.mCost*store.get<ESM::GameSetting>().find("fSpellValueMult")->getFloat()); int price = static_cast<int>(spell->mData.mCost*store.get<ESM::GameSetting>().find("fSpellValueMult")->getFloat());
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr,price,true); price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr,price,true);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
// TODO: refactor to use MyGUI::ListBox // TODO: refactor to use MyGUI::ListBox
@ -125,7 +126,7 @@ namespace MWGui
bool SpellBuyingWindow::playerHasSpell(const std::string &id) bool SpellBuyingWindow::playerHasSpell(const std::string &id)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
return player.getClass().getCreatureStats(player).getSpells().hasSpell(id); return player.getClass().getCreatureStats(player).getSpells().hasSpell(id);
} }
@ -133,7 +134,7 @@ namespace MWGui
{ {
int price = *_sender->getUserData<int>(); int price = *_sender->getUserData<int>();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId)) if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId))
return; return;
@ -158,7 +159,7 @@ namespace MWGui
void SpellBuyingWindow::updateLabels() void SpellBuyingWindow::updateLabels()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
mPlayerGold->setCaptionWithReplacing("#{sGold}: " + MyGUI::utility::toString(playerGold)); mPlayerGold->setCaptionWithReplacing("#{sGold}: " + MyGUI::utility::toString(playerGold));

View file

@ -19,6 +19,7 @@
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/spells.hpp" #include "../mwmechanics/spells.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "tooltips.hpp" #include "tooltips.hpp"
#include "class.hpp" #include "class.hpp"
@ -376,7 +377,7 @@ namespace MWGui
return; return;
} }
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
if (MyGUI::utility::parseInt(mPriceLabel->getCaption()) > playerGold) if (MyGUI::utility::parseInt(mPriceLabel->getCaption()) > playerGold)
@ -474,7 +475,7 @@ namespace MWGui
mPriceLabel->setCaption(MyGUI::utility::toString(int(price))); mPriceLabel->setCaption(MyGUI::utility::toString(int(price)));
float chance = MWMechanics::getSpellSuccessChance(&mSpell, MWBase::Environment::get().getWorld()->getPlayerPtr()); float chance = MWMechanics::getSpellSuccessChance(&mSpell, MWMechanics::getPlayer());
mSuccessChance->setCaption(MyGUI::utility::toString(int(chance))); mSuccessChance->setCaption(MyGUI::utility::toString(int(chance)));
} }
@ -507,7 +508,7 @@ namespace MWGui
{ {
// get the list of magic effects that are known to the player // get the list of magic effects that are known to the player
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells(); MWMechanics::Spells& spells = stats.getSpells();

View file

@ -16,6 +16,7 @@
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "tooltips.hpp" #include "tooltips.hpp"
@ -43,7 +44,7 @@ namespace MWGui
{ {
// TODO: Tracking add/remove/expire would be better than force updating every frame // TODO: Tracking add/remove/expire would be better than force updating every frame
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);

View file

@ -15,6 +15,7 @@
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/spells.hpp" #include "../mwmechanics/spells.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "spellicons.hpp" #include "spellicons.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
@ -79,12 +80,12 @@ namespace MWGui
{ {
mSpellIcons->updateWidgets(mEffectBox, false); mSpellIcons->updateWidgets(mEffectBox, false);
mSpellView->setModel(new SpellModel(MWBase::Environment::get().getWorld()->getPlayerPtr())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
} }
void SpellWindow::onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped) void SpellWindow::onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
// retrieve ContainerStoreIterator to the item // retrieve ContainerStoreIterator to the item
@ -159,7 +160,7 @@ namespace MWGui
void SpellWindow::onSpellSelected(const std::string& spellId) void SpellWindow::onSpellSelected(const std::string& spellId)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
store.setSelectedEnchantItem(store.end()); store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
@ -169,7 +170,7 @@ namespace MWGui
void SpellWindow::onDeleteSpellAccept() void SpellWindow::onDeleteSpellAccept()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells(); MWMechanics::Spells& spells = stats.getSpells();
@ -183,7 +184,7 @@ namespace MWGui
void SpellWindow::cycle(bool next) void SpellWindow::cycle(bool next)
{ {
mSpellView->setModel(new SpellModel(MWBase::Environment::get().getWorld()->getPlayerPtr())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
SpellModel::ModelIndex selected = 0; SpellModel::ModelIndex selected = 0;
for (SpellModel::ModelIndex i = 0; i<int(mSpellView->getModel()->getItemCount()); ++i) for (SpellModel::ModelIndex i = 0; i<int(mSpellView->getModel()->getItemCount()); ++i)

View file

@ -15,6 +15,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "tooltips.hpp" #include "tooltips.hpp"
@ -234,7 +235,7 @@ namespace MWGui
NoDrop::onFrame(dt); NoDrop::onFrame(dt);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player); const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player);
// level progress // level progress
@ -383,7 +384,7 @@ namespace MWGui
int base = stat.getBase(); int base = stat.getBase();
int modified = stat.getModified(); int modified = stat.getModified();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWWorld::ESMStore &esmStore = const MWWorld::ESMStore &esmStore =
MWBase::Environment::get().getWorld()->getStore(); MWBase::Environment::get().getWorld()->getStore();
@ -493,7 +494,7 @@ namespace MWGui
if (!mFactions.empty()) if (!mFactions.empty())
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player); const MWMechanics::NpcStats &PCstats = player.getClass().getNpcStats(player);
const std::set<std::string> &expelled = PCstats.getExpelled(); const std::set<std::string> &expelled = PCstats.getExpelled();

View file

@ -17,6 +17,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "mapwindow.hpp" #include "mapwindow.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
@ -234,7 +235,7 @@ namespace MWGui
} }
if (MWMechanics::spellIncreasesSkill(spell)) // display school of spells that contribute to skill progress if (MWMechanics::spellIncreasesSkill(spell)) // display school of spells that contribute to skill progress
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int school = MWMechanics::getSpellSchool(spell, player); int school = MWMechanics::getSpellSchool(spell, player);
info.text = "#{sSchool}: " + sSchoolNames[school]; info.text = "#{sSchool}: " + sSchoolNames[school];
} }
@ -355,7 +356,7 @@ namespace MWGui
if(!mFocusObject.isEmpty()) if(!mFocusObject.isEmpty())
{ {
const MWWorld::CellRef& cellref = mFocusObject.getCellRef(); const MWWorld::CellRef& cellref = mFocusObject.getCellRef();
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr ptr = MWMechanics::getPlayer();
MWWorld::Ptr victim; MWWorld::Ptr victim;
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager(); MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();

View file

@ -20,6 +20,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
#include "itemview.hpp" #include "itemview.hpp"
@ -282,7 +283,7 @@ namespace MWGui
return; return;
} }
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
// check if the player can afford this // check if the player can afford this
@ -490,7 +491,7 @@ namespace MWGui
void TradeWindow::updateLabels() void TradeWindow::updateLabels()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + MyGUI::utility::toString(playerGold)); mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + MyGUI::utility::toString(playerGold));

View file

@ -13,6 +13,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "tooltips.hpp" #include "tooltips.hpp"
@ -68,7 +69,7 @@ namespace MWGui
{ {
mPtr = actor; mPtr = actor;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
mPlayerGold->setCaptionWithReplacing("#{sGold}: " + MyGUI::utility::toString(playerGold)); mPlayerGold->setCaptionWithReplacing("#{sGold}: " + MyGUI::utility::toString(playerGold));

View file

@ -12,6 +12,7 @@
#include "../mwbase/dialoguemanager.hpp" #include "../mwbase/dialoguemanager.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
@ -144,7 +145,7 @@ namespace MWGui
int price; int price;
iss >> price; iss >> price;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId); int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
if (playerGold<price) if (playerGold<price)

View file

@ -19,6 +19,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwstate/charactermanager.hpp" #include "../mwstate/charactermanager.hpp"
@ -199,7 +200,7 @@ namespace MWGui
{ {
stopWaiting(); stopWaiting();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
const MWMechanics::NpcStats &pcstats = player.getClass().getNpcStats(player); const MWMechanics::NpcStats &pcstats = player.getClass().getNpcStats(player);
// trigger levelup if possible // trigger levelup if possible
@ -213,7 +214,7 @@ namespace MWGui
void WaitDialog::setCanRest (bool canRest) void WaitDialog::setCanRest (bool canRest)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
bool full = (stats.getHealth().getCurrent() >= stats.getHealth().getModified()) bool full = (stats.getHealth().getCurrent() >= stats.getHealth().getModified())
&& (stats.getMagicka().getCurrent() >= stats.getMagicka().getModified()); && (stats.getMagicka().getCurrent() >= stats.getMagicka().getModified());

View file

@ -56,6 +56,7 @@
#include "../mwmechanics/stat.hpp" #include "../mwmechanics/stat.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwrender/localmap.hpp" #include "../mwrender/localmap.hpp"
@ -903,7 +904,7 @@ namespace MWGui
if (!mLocalMapRender) if (!mLocalMapRender)
return; return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
osg::Vec3f playerPosition = player.getRefData().getPosition().asVec3(); osg::Vec3f playerPosition = player.getRefData().getPosition().asVec3();
osg::Quat playerOrientation (-player.getRefData().getPosition().rot[2], osg::Vec3(0,0,1)); osg::Quat playerOrientation (-player.getRefData().getPosition().rot[2], osg::Vec3(0,0,1));
@ -1547,7 +1548,7 @@ namespace MWGui
{ {
mInventoryWindow->updatePlayer(); mInventoryWindow->updatePlayer();
const MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf()) if (player.getClass().getNpcStats(player).isWerewolf())
{ {
setWerewolfOverlay(true); setWerewolfOverlay(true);

View file

@ -28,6 +28,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
using namespace ICS; using namespace ICS;
@ -1012,7 +1013,7 @@ namespace MWInput
{ {
if (!mControlSwitch["playercontrols"]) if (!mControlSwitch["playercontrols"])
return; return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf()) if (player.getClass().getNpcStats(player).isWerewolf())
{ {
// Cannot use items or spells while in werewolf form // Cannot use items or spells while in werewolf form
@ -1029,7 +1030,7 @@ namespace MWInput
if (!MWBase::Environment::get().getWindowManager()->isGuiMode () if (!MWBase::Environment::get().getWindowManager()->isGuiMode ()
&& MWBase::Environment::get().getWorld()->getGlobalFloat ("chargenstate")==-1) && MWBase::Environment::get().getWorld()->getGlobalFloat ("chargenstate")==-1)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if (player.getClass().getNpcStats(player).isWerewolf()) if (player.getClass().getNpcStats(player).isWerewolf())
{ {
// Cannot use items or spells while in werewolf form // Cannot use items or spells while in werewolf form

View file

@ -34,6 +34,7 @@
#include "actor.hpp" #include "actor.hpp"
#include "summoning.hpp" #include "summoning.hpp"
#include "combat.hpp" #include "combat.hpp"
#include "actorutil.hpp"
namespace namespace
{ {
@ -56,7 +57,7 @@ void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& a
action.execute(actor); action.execute(actor);
MWWorld::ContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); MWWorld::ContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
// change draw state only if the item is in player's right hand // change draw state only if the item is in player's right hand
if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() if (actor == MWMechanics::getPlayer()
&& rightHand != store.end() && newPtr == *rightHand) && rightHand != store.end() && newPtr == *rightHand)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
@ -82,7 +83,7 @@ public:
const std::string& sourceName, const std::string& sourceId, int casterActorId, const std::string& sourceName, const std::string& sourceId, int casterActorId,
float magnitude, float remainingTime = -1, float totalTime = -1) float magnitude, float remainingTime = -1, float totalTime = -1)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if ( ((key.mId == ESM::MagicEffect::CommandHumanoid && mActor.getClass().isNpc()) if ( ((key.mId == ESM::MagicEffect::CommandHumanoid && mActor.getClass().isNpc())
|| (key.mId == ESM::MagicEffect::CommandCreature && mActor.getTypeName() == typeid(ESM::Creature).name())) || (key.mId == ESM::MagicEffect::CommandCreature && mActor.getTypeName() == typeid(ESM::Creature).name()))
&& casterActorId == player.getClass().getCreatureStats(player).getActorId() && casterActorId == player.getClass().getCreatureStats(player).getActorId()
@ -203,7 +204,7 @@ namespace MWMechanics
gem->getContainerStore()->unstack(*gem, caster); gem->getContainerStore()->unstack(*gem, caster);
gem->getCellRef().setSoul(mCreature.getCellRef().getRefId()); gem->getCellRef().setSoul(mCreature.getCellRef().getRefId());
if (caster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (caster == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sSoultrapSuccess}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sSoultrapSuccess}");
const ESM::Static* fx = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>() const ESM::Static* fx = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>()
@ -401,7 +402,7 @@ namespace MWMechanics
int intelligence = creatureStats.getAttribute(ESM::Attribute::Intelligence).getModified(); int intelligence = creatureStats.getAttribute(ESM::Attribute::Intelligence).getModified();
float base = 1.f; float base = 1.f;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == getPlayer())
base = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPCbaseMagickaMult")->getFloat(); base = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPCbaseMagickaMult")->getFloat();
else else
base = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCbaseMagickaMult")->getFloat(); base = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCbaseMagickaMult")->getFloat();
@ -512,7 +513,7 @@ namespace MWMechanics
{ {
spells.worsenCorprus(it->first); spells.worsenCorprus(it->first);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicCorprusWorsens}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicCorprusWorsens}");
} }
} }
@ -539,19 +540,19 @@ namespace MWMechanics
if (!creature || ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Creatures) if (!creature || ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Creatures)
{ {
Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Fight); Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Fight);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::FrenzyHumanoid + creature).getMagnitude() stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::FrenzyHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid+creature).getMagnitude())); - effects.get(ESM::MagicEffect::CalmHumanoid+creature).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Fight, stat); creatureStats.setAiSetting(CreatureStats::AI_Fight, stat);
stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); stat = creatureStats.getAiSetting(CreatureStats::AI_Flee);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::DemoralizeHumanoid + creature).getMagnitude() stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::DemoralizeHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::RallyHumanoid+creature).getMagnitude())); - effects.get(ESM::MagicEffect::RallyHumanoid+creature).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); creatureStats.setAiSetting(CreatureStats::AI_Flee, stat);
} }
if (creature && ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Undead) if (creature && ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Undead)
{ {
Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Flee);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::TurnUndead).getMagnitude())); stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::TurnUndead).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); creatureStats.setAiSetting(CreatureStats::AI_Flee, stat);
} }
@ -560,7 +561,7 @@ namespace MWMechanics
// The actor was killed by a magic effect. Figure out if the player was responsible for it. // The actor was killed by a magic effect. Figure out if the player was responsible for it.
const ActiveSpells& spells = creatureStats.getActiveSpells(); const ActiveSpells& spells = creatureStats.getActiveSpells();
bool killedByPlayer = false; bool killedByPlayer = false;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
for (ActiveSpells::TIterator it = spells.begin(); it != spells.end(); ++it) for (ActiveSpells::TIterator it = spells.begin(); it != spells.end(); ++it)
{ {
const ActiveSpells::ActiveSpellParams& spell = it->second; const ActiveSpells::ActiveSpellParams& spell = it->second;
@ -597,8 +598,8 @@ namespace MWMechanics
// TODO: dirty flag for magic effects to avoid some unnecessary work below? // TODO: dirty flag for magic effects to avoid some unnecessary work below?
// any value of calm > 0 will stop the actor from fighting // any value of calm > 0 will stop the actor from fighting
if ((creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc()) if ((effects.get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc())
|| (creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc())) || (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc()))
{ {
for (std::list<AiPackage*>::const_iterator it = creatureStats.getAiSequence().begin(); it != creatureStats.getAiSequence().end(); ) for (std::list<AiPackage*>::const_iterator it = creatureStats.getAiSequence().begin(); it != creatureStats.getAiSequence().end(); )
{ {
@ -631,7 +632,7 @@ namespace MWMechanics
for (std::map<int, std::string>::iterator it = boundItemsMap.begin(); it != boundItemsMap.end(); ++it) for (std::map<int, std::string>::iterator it = boundItemsMap.begin(); it != boundItemsMap.end(); ++it)
{ {
bool found = creatureStats.mBoundItems.find(it->first) != creatureStats.mBoundItems.end(); bool found = creatureStats.mBoundItems.find(it->first) != creatureStats.mBoundItems.end();
float magnitude = creatureStats.getMagicEffects().get(it->first).getMagnitude(); float magnitude = effects.get(it->first).getMagnitude();
if (found != (magnitude > 0)) if (found != (magnitude > 0))
{ {
std::string itemGmst = it->second; std::string itemGmst = it->second;
@ -727,7 +728,7 @@ namespace MWMechanics
void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration) void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration)
{ {
bool isPlayer = (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()); bool isPlayer = (ptr == getPlayer());
MWWorld::InventoryStore &inventoryStore = ptr.getClass().getInventoryStore(ptr); MWWorld::InventoryStore &inventoryStore = ptr.getClass().getInventoryStore(ptr);
MWWorld::ContainerStoreIterator heldIter = MWWorld::ContainerStoreIterator heldIter =
@ -824,7 +825,7 @@ namespace MWMechanics
void Actors::updateCrimePersuit(const MWWorld::Ptr& ptr, float duration) void Actors::updateCrimePersuit(const MWWorld::Ptr& ptr, float duration)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
if (ptr != player && ptr.getClass().isNpc()) if (ptr != player && ptr.getClass().isNpc())
{ {
// get stats of witness // get stats of witness
@ -946,7 +947,7 @@ namespace MWMechanics
if (timerUpdateAITargets >= 1.0f) timerUpdateAITargets = 0; if (timerUpdateAITargets >= 1.0f) timerUpdateAITargets = 0;
if (timerUpdateHeadTrack >= 0.3f) timerUpdateHeadTrack = 0; if (timerUpdateHeadTrack >= 0.3f) timerUpdateHeadTrack = 0;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
int hostilesCount = 0; // need to know this to play Battle music int hostilesCount = 0; // need to know this to play Battle music
@ -1038,13 +1039,12 @@ namespace MWMechanics
> sqrProcessingDistance) > sqrProcessingDistance)
continue; continue;
if (iter->first.getClass().getCreatureStats(iter->first).getMagicEffects().get( if (iter->first.getClass().getCreatureStats(iter->first).isParalyzed())
ESM::MagicEffect::Paralyze).getMagnitude() > 0)
iter->second->getCharacterController()->skipAnim(); iter->second->getCharacterController()->skipAnim();
// Handle player last, in case a cell transition occurs by casting a teleportation spell // Handle player last, in case a cell transition occurs by casting a teleportation spell
// (would invalidate the iterator) // (would invalidate the iterator)
if (iter->first == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (iter->first == getPlayer())
{ {
playerCharacter = iter->second->getCharacterController(); playerCharacter = iter->second->getCharacterController();
continue; continue;
@ -1431,9 +1431,9 @@ namespace MWMechanics
for (PtrActorMap::iterator it = map.begin(); it != map.end(); ++it) for (PtrActorMap::iterator it = map.begin(); it != map.end(); ++it)
{ {
MWWorld::Ptr ptr = it->first; MWWorld::Ptr ptr = it->first;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr() if (ptr == getPlayer()
|| !isConscious(ptr) || !isConscious(ptr)
|| ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0) || ptr.getClass().getCreatureStats(ptr).isParalyzed())
continue; continue;
MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence(); MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
seq.fastForward(ptr, it->second->getAiState()); seq.fastForward(ptr, it->second->getAiState());

View file

@ -0,0 +1,12 @@
#include "actorutil.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
namespace MWMechanics
{
MWWorld::Ptr getPlayer()
{
return MWBase::Environment::get().getWorld()->getPlayerPtr();
}
}

View file

@ -0,0 +1,14 @@
#ifndef OPENMW_MWMECHANICS_ACTORUTIL_H
#define OPENMW_MWMECHANICS_ACTORUTIL_H
namespace MWWorld
{
class Ptr;
}
namespace MWMechanics
{
MWWorld::Ptr getPlayer();
}
#endif

View file

@ -6,6 +6,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "creaturestats.hpp" #include "creaturestats.hpp"
#include "movement.hpp" #include "movement.hpp"
#include "actorutil.hpp"
#include "steering.hpp" #include "steering.hpp"
@ -63,7 +64,7 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor, CharacterCont
std::vector<MWWorld::Ptr> actors; std::vector<MWWorld::Ptr> actors;
MWBase::Environment::get().getMechanicsManager()->getActorsInRange(pos.asVec3(),100,actors); MWBase::Environment::get().getMechanicsManager()->getActorsInRange(pos.asVec3(),100,actors);
for(std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); ++it) { for(std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); ++it) {
if(*it != MWBase::Environment::get().getWorld()->getPlayerPtr()) { //Not the player if(*it != getPlayer()) { //Not the player
MWMechanics::AiSequence& seq = it->getClass().getCreatureStats(*it).getAiSequence(); MWMechanics::AiSequence& seq = it->getClass().getCreatureStats(*it).getAiSequence();
if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) { //Only add it once if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) { //Only add it once
seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr),*it); seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr),*it);

View file

@ -15,6 +15,7 @@
#include "../mwworld/action.hpp" #include "../mwworld/action.hpp"
#include "steering.hpp" #include "steering.hpp"
#include "actorutil.hpp"
MWMechanics::AiPackage::~AiPackage() {} MWMechanics::AiPackage::~AiPackage() {}
@ -34,7 +35,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
/// Stops the actor when it gets too close to a unloaded cell /// Stops the actor when it gets too close to a unloaded cell
const ESM::Cell *cell = actor.getCell()->getCell(); const ESM::Cell *cell = actor.getCell()->getCell();
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
Movement &movement = actor.getClass().getMovementSettings(actor); Movement &movement = actor.getClass().getMovementSettings(actor);
//Ensure pursuer doesn't leave loaded cells //Ensure pursuer doesn't leave loaded cells

View file

@ -12,6 +12,7 @@
#include "aiactivate.hpp" #include "aiactivate.hpp"
#include "aicombat.hpp" #include "aicombat.hpp"
#include "aipursue.hpp" #include "aipursue.hpp"
#include "actorutil.hpp"
#include <components/esm/aisequence.hpp> #include <components/esm/aisequence.hpp>
@ -150,7 +151,7 @@ bool AiSequence::isPackageDone() const
void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration)
{ {
if(actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if(actor != getPlayer())
{ {
if (!mPackages.empty()) if (!mPackages.empty())
{ {
@ -242,7 +243,7 @@ void AiSequence::clear()
void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor) void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor)
{ {
if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor == getPlayer())
throw std::runtime_error("Can't add AI packages to player"); throw std::runtime_error("Can't add AI packages to player");
if (package.getTypeId() == AiPackage::TypeIdCombat || package.getTypeId() == AiPackage::TypeIdPursue) if (package.getTypeId() == AiPackage::TypeIdCombat || package.getTypeId() == AiPackage::TypeIdPursue)

View file

@ -21,6 +21,7 @@
#include "steering.hpp" #include "steering.hpp"
#include "movement.hpp" #include "movement.hpp"
#include "coordinateconverter.hpp" #include "coordinateconverter.hpp"
#include "actorutil.hpp"
@ -462,7 +463,7 @@ namespace MWMechanics
if (hello > 0 && !MWBase::Environment::get().getWorld()->isSwimming(actor) if (hello > 0 && !MWBase::Environment::get().getWorld()->isSwimming(actor)
&& MWBase::Environment::get().getSoundManager()->sayDone(actor)) && MWBase::Environment::get().getSoundManager()->sayDone(actor))
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
static float fVoiceIdleOdds = MWBase::Environment::get().getWorld()->getStore() static float fVoiceIdleOdds = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("fVoiceIdleOdds")->getFloat(); .get<ESM::GameSetting>().find("fVoiceIdleOdds")->getFloat();
@ -496,7 +497,7 @@ namespace MWMechanics
helloDistance *= iGreetDistanceMultiplier; helloDistance *= iGreetDistanceMultiplier;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
osg::Vec3f playerPos(player.getRefData().getPosition().asVec3()); osg::Vec3f playerPos(player.getRefData().getPosition().asVec3());
osg::Vec3f actorPos(actor.getRefData().getPosition().asVec3()); osg::Vec3f actorPos(actor.getRefData().getPosition().asVec3());
float playerDistSqr = (playerPos - actorPos).length2(); float playerDistSqr = (playerPos - actorPos).length2();

View file

@ -27,6 +27,7 @@
#include "npcstats.hpp" #include "npcstats.hpp"
#include "creaturestats.hpp" #include "creaturestats.hpp"
#include "security.hpp" #include "security.hpp"
#include "actorutil.hpp"
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
@ -619,7 +620,7 @@ void CharacterController::playDeath(float startpoint, CharacterState death)
void CharacterController::playRandomDeath(float startpoint) void CharacterController::playRandomDeath(float startpoint)
{ {
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
{ {
// The first-person animations do not include death, so we need to // The first-person animations do not include death, so we need to
// force-switch to third person before playing the death animation. // force-switch to third person before playing the death animation.
@ -1167,7 +1168,7 @@ bool CharacterController::updateWeaponState()
// Unset casting flag, otherwise pressing the mouse button down would // Unset casting flag, otherwise pressing the mouse button down would
// continue casting every frame if there is no animation // continue casting every frame if there is no animation
mAttackingOrSpell = false; mAttackingOrSpell = false;
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setAttackingOrSpell(false); MWBase::Environment::get().getWorld()->getPlayer().setAttackingOrSpell(false);
} }
@ -1177,7 +1178,7 @@ bool CharacterController::updateWeaponState()
// For the player, set the spell we want to cast // For the player, set the spell we want to cast
// This has to be done at the start of the casting animation, // This has to be done at the start of the casting animation,
// *not* when selecting a spell in the GUI (otherwise you could change the spell mid-animation) // *not* when selecting a spell in the GUI (otherwise you could change the spell mid-animation)
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
{ {
std::string selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); std::string selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
stats.getSpells().setSelectedSpell(selectedSpell); stats.getSpells().setSelectedSpell(selectedSpell);
@ -1257,7 +1258,7 @@ bool CharacterController::updateWeaponState()
mAttackType = "shoot"; mAttackType = "shoot";
else else
{ {
if(isWeapon && mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr() && if(isWeapon && mPtr == getPlayer() &&
Settings::Manager::getBool("best attack", "Game")) Settings::Manager::getBool("best attack", "Game"))
{ {
MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight); MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
@ -1563,7 +1564,7 @@ void CharacterController::update(float duration)
// advance athletics // advance athletics
if(mHasMovedInXY && mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(mHasMovedInXY && mPtr == getPlayer())
{ {
if(inwater) if(inwater)
{ {
@ -1664,7 +1665,7 @@ void CharacterController::update(float duration)
} }
// advance acrobatics // advance acrobatics
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
cls.skillUsageSucceeded(mPtr, ESM::Skill::Acrobatics, 0); cls.skillUsageSucceeded(mPtr, ESM::Skill::Acrobatics, 0);
// decrease fatigue // decrease fatigue
@ -1707,7 +1708,7 @@ void CharacterController::update(float duration)
else else
{ {
// report acrobatics progression // report acrobatics progression
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
cls.skillUsageSucceeded(mPtr, ESM::Skill::Acrobatics, 1); cls.skillUsageSucceeded(mPtr, ESM::Skill::Acrobatics, 1);
} }
} }
@ -1949,7 +1950,7 @@ bool CharacterController::kill()
{ {
if( isDead() ) if( isDead() )
{ {
if( mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr() && !isAnimPlaying(mCurrentDeath) ) if( mPtr == getPlayer() && !isAnimPlaying(mCurrentDeath) )
{ {
//player's death animation is over //player's death animation is over
MWBase::Environment::get().getStateManager()->askLoadRecent(); MWBase::Environment::get().getStateManager()->askLoadRecent();
@ -1965,7 +1966,7 @@ bool CharacterController::kill()
mCurrentIdle.clear(); mCurrentIdle.clear();
// Play Death Music if it was the player dying // Play Death Music if it was the player dying
if(mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(mPtr == getPlayer())
MWBase::Environment::get().getSoundManager()->streamMusic("Special/MW_Death.mp3"); MWBase::Environment::get().getSoundManager()->streamMusic("Special/MW_Death.mp3");
return true; return true;
@ -2006,7 +2007,7 @@ void CharacterController::updateMagicEffects()
float alpha = 1.f; float alpha = 1.f;
if (mPtr.getClass().getCreatureStats(mPtr).getMagicEffects().get(ESM::MagicEffect::Invisibility).getMagnitude()) if (mPtr.getClass().getCreatureStats(mPtr).getMagicEffects().get(ESM::MagicEffect::Invisibility).getMagnitude())
{ {
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == getPlayer())
alpha = 0.4f; alpha = 0.4f;
else else
alpha = 0.f; alpha = 0.f;

View file

@ -19,6 +19,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "actorutil.hpp"
namespace namespace
{ {
@ -60,7 +61,7 @@ namespace MWMechanics
if (blockerStats.getKnockedDown() // Used for both knockout or knockdown if (blockerStats.getKnockedDown() // Used for both knockout or knockdown
|| blockerStats.getHitRecovery() || blockerStats.getHitRecovery()
|| blockerStats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0) || blockerStats.isParalyzed())
return false; return false;
if (!MWBase::Environment::get().getMechanicsManager()->isReadyToBlock(blocker)) if (!MWBase::Environment::get().getMechanicsManager()->isReadyToBlock(blocker))
@ -137,7 +138,7 @@ namespace MWMechanics
blockerStats.setBlock(true); blockerStats.setBlock(true);
if (blocker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (blocker == getPlayer())
blocker.getClass().skillUsageSucceeded(blocker, ESM::Skill::Block, 0); blocker.getClass().skillUsageSucceeded(blocker, ESM::Skill::Block, 0);
return true; return true;
@ -147,9 +148,9 @@ namespace MWMechanics
void resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage) void resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage)
{ {
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor); const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects();
float resistance = std::min(100.f, stats.getMagicEffects().get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude() float resistance = std::min(100.f, effects.get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude()
- stats.getMagicEffects().get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude()); - effects.get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude());
float multiplier = 1.f - resistance / 100.f; float multiplier = 1.f - resistance / 100.f;
@ -161,7 +162,7 @@ namespace MWMechanics
&& actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) && actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
damage *= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWereWolfSilverWeaponDamageMult")->getFloat(); damage *= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWereWolfSilverWeaponDamageMult")->getFloat();
if (damage == 0 && attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (damage == 0 && attacker == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}");
} }
@ -178,7 +179,7 @@ namespace MWMechanics
return; return;
} }
if(attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(attacker == getPlayer())
MWBase::Environment::get().getWindowManager()->setEnemy(victim); MWBase::Environment::get().getWindowManager()->setEnemy(victim);
int weapskill = ESM::Skill::Marksman; int weapskill = ESM::Skill::Marksman;
@ -207,7 +208,7 @@ namespace MWMechanics
adjustWeaponDamage(damage, weapon, attacker); adjustWeaponDamage(damage, weapon, attacker);
reduceWeaponCondition(damage, true, weapon, attacker); reduceWeaponCondition(damage, true, weapon, attacker);
if(attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) if(attacker == getPlayer())
attacker.getClass().skillUsageSucceeded(attacker, weapskill, 0); attacker.getClass().skillUsageSucceeded(attacker, weapskill, 0);
if (victim.getClass().getCreatureStats(victim).getKnockedDown()) if (victim.getClass().getCreatureStats(victim).getKnockedDown())
@ -222,7 +223,7 @@ namespace MWMechanics
MWBase::Environment::get().getWorld()->spawnBloodEffect(victim, hitPosition); MWBase::Environment::get().getWorld()->spawnBloodEffect(victim, hitPosition);
// Non-enchanted arrows shot at enemies have a chance to turn up in their inventory // Non-enchanted arrows shot at enemies have a chance to turn up in their inventory
if (victim != MWBase::Environment::get().getWorld()->getPlayerPtr() if (victim != getPlayer()
&& !appliedEnchantment) && !appliedEnchantment)
{ {
float fProjectileThrownStoreChance = gmst.find("fProjectileThrownStoreChance")->getFloat(); float fProjectileThrownStoreChance = gmst.find("fProjectileThrownStoreChance")->getFloat();
@ -242,15 +243,15 @@ namespace MWMechanics
const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>(); const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();
float defenseTerm = 0; float defenseTerm = 0;
if (victim.getClass().getCreatureStats(victim).getFatigue().getCurrent() >= 0)
{
MWMechanics::CreatureStats& victimStats = victim.getClass().getCreatureStats(victim); MWMechanics::CreatureStats& victimStats = victim.getClass().getCreatureStats(victim);
if (victimStats.getFatigue().getCurrent() >= 0)
{
// Maybe we should keep an aware state for actors updated every so often instead of testing every time // Maybe we should keep an aware state for actors updated every so often instead of testing every time
bool unaware = (!victimStats.getAiSequence().isInCombat()) bool unaware = (!victimStats.getAiSequence().isInCombat())
&& (attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) && (attacker == getPlayer())
&& (!MWBase::Environment::get().getMechanicsManager()->awarenessCheck(attacker, victim)); && (!MWBase::Environment::get().getMechanicsManager()->awarenessCheck(attacker, victim));
if (!(victimStats.getKnockedDown() || if (!(victimStats.getKnockedDown() ||
victimStats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0 victimStats.isParalyzed()
|| unaware )) || unaware ))
{ {
defenseTerm = victimStats.getEvasion(); defenseTerm = victimStats.getEvasion();
@ -375,7 +376,7 @@ namespace MWMechanics
damage *= minstrike + ((maxstrike-minstrike)*attackStrength); damage *= minstrike + ((maxstrike-minstrike)*attackStrength);
MWMechanics::CreatureStats& otherstats = victim.getClass().getCreatureStats(victim); MWMechanics::CreatureStats& otherstats = victim.getClass().getCreatureStats(victim);
healthdmg = (otherstats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0) healthdmg = otherstats.isParalyzed()
|| otherstats.getKnockedDown(); || otherstats.getKnockedDown();
bool isWerewolf = (attacker.getClass().isNpc() && attacker.getClass().getNpcStats(attacker).isWerewolf()); bool isWerewolf = (attacker.getClass().isNpc() && attacker.getClass().getNpcStats(attacker).isWerewolf());
if(isWerewolf) if(isWerewolf)

View file

@ -221,6 +221,11 @@ namespace MWMechanics
setAiSetting(index, stat); setAiSetting(index, stat);
} }
bool CreatureStats::isParalyzed() const
{
return mMagicEffects.get(ESM::MagicEffect::Paralyze).getMagnitude() > 0;
}
bool CreatureStats::isDead() const bool CreatureStats::isDead() const
{ {
return mDead; return mDead;

View file

@ -155,6 +155,8 @@ namespace MWMechanics
float getFatigueTerm() const; float getFatigueTerm() const;
///< Return effective fatigue ///< Return effective fatigue
bool isParalyzed() const;
bool isDead() const; bool isDead() const;
void notifyDied(); void notifyDied();

View file

@ -6,9 +6,11 @@
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include "actorutil.hpp"
float scaleDamage(float damage, const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim) float scaleDamage(float damage, const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
{ {
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = MWMechanics::getPlayer();
// [-100, 100] // [-100, 100]
int difficultySetting = Settings::Manager::getInt("difficulty", "Game"); int difficultySetting = Settings::Manager::getInt("difficulty", "Game");

View file

@ -9,8 +9,10 @@
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/spells.hpp" #include "spells.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "creaturestats.hpp"
#include "actorutil.hpp"
namespace MWMechanics namespace MWMechanics
{ {
@ -20,7 +22,7 @@ namespace MWMechanics
/// @param carrier The disease carrier. /// @param carrier The disease carrier.
inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier) inline void diseaseContact (MWWorld::Ptr actor, MWWorld::Ptr carrier)
{ {
if (!carrier.getClass().isActor() || actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (!carrier.getClass().isActor() || actor != getPlayer())
return; return;
float fDiseaseXferChance = float fDiseaseXferChance =

View file

@ -11,6 +11,7 @@
#include "creaturestats.hpp" #include "creaturestats.hpp"
#include "npcstats.hpp" #include "npcstats.hpp"
#include "spellcasting.hpp" #include "spellcasting.hpp"
#include "actorutil.hpp"
namespace MWMechanics namespace MWMechanics
{ {
@ -54,7 +55,7 @@ namespace MWMechanics
bool Enchanting::create() bool Enchanting::create()
{ {
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = getPlayer();
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
ESM::Enchantment enchantment; ESM::Enchantment enchantment;
enchantment.mData.mCharge = getGemCharge(); enchantment.mData.mCharge = getGemCharge();
@ -217,7 +218,7 @@ namespace MWMechanics
int Enchanting::getEffectiveCastCost() const int Enchanting::getEffectiveCastCost() const
{ {
int baseCost = getBaseCastCost(); int baseCost = getBaseCastCost();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
return getEffectiveEnchantmentCastCost(static_cast<float>(baseCost), player); return getEffectiveEnchantmentCastCost(static_cast<float>(baseCost), player);
} }
@ -291,7 +292,7 @@ namespace MWMechanics
void Enchanting::payForEnchantment() const void Enchanting::payForEnchantment() const
{ {
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = getPlayer();
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
store.remove(MWWorld::ContainerStore::sGoldId, getEnchantPrice(), player); store.remove(MWWorld::ContainerStore::sGoldId, getEnchantPrice(), player);

View file

@ -11,7 +11,8 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "creaturestats.hpp"
#include "actorutil.hpp"
namespace MWMechanics namespace MWMechanics
{ {
@ -21,7 +22,7 @@ namespace MWMechanics
{ {
const std::vector<ESM::LevelledListBase::LevelItem>& items = levItem->mList; const std::vector<ESM::LevelledListBase::LevelItem>& items = levItem->mList;
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const MWWorld::Ptr& player = getPlayer();
int playerLevel = player.getClass().getCreatureStats(player).getLevel(); int playerLevel = player.getClass().getCreatureStats(player).getLevel();
failChance += levItem->mChanceNone; failChance += levItem->mChanceNone;

View file

@ -26,6 +26,7 @@
#include "spellcasting.hpp" #include "spellcasting.hpp"
#include "autocalcspell.hpp" #include "autocalcspell.hpp"
#include "npcstats.hpp" #include "npcstats.hpp"
#include "actorutil.hpp"
namespace namespace
{ {
@ -83,7 +84,7 @@ namespace MWMechanics
{ {
void MechanicsManager::buildPlayer() void MechanicsManager::buildPlayer()
{ {
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr ptr = getPlayer();
MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats (ptr);
MWMechanics::NpcStats& npcStats = ptr.getClass().getNpcStats (ptr); MWMechanics::NpcStats& npcStats = ptr.getClass().getNpcStats (ptr);
@ -361,7 +362,7 @@ namespace MWMechanics
{ {
// Uses ingame time, but scaled to real time // Uses ingame time, but scaled to real time
duration /= MWBase::Environment::get().getWorld()->getTimeScaleFactor(); duration /= MWBase::Environment::get().getWorld()->getTimeScaleFactor();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
player.getClass().getInventoryStore(player).rechargeItems(duration); player.getClass().getInventoryStore(player).rechargeItems(duration);
} }
@ -489,7 +490,7 @@ namespace MWMechanics
// HACK? The player has been changed, so a new Animation object may // HACK? The player has been changed, so a new Animation object may
// have been made for them. Make sure they're properly updated. // have been made for them. Make sure they're properly updated.
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr ptr = getPlayer();
mActors.removeActor(ptr); mActors.removeActor(ptr);
mActors.addActor(ptr, true); mActors.addActor(ptr, true);
} }
@ -586,7 +587,7 @@ namespace MWMechanics
float x = static_cast<float>(npcSkill.getBaseDisposition()); float x = static_cast<float>(npcSkill.getBaseDisposition());
MWWorld::LiveCellRef<ESM::NPC>* npc = ptr.get<ESM::NPC>(); MWWorld::LiveCellRef<ESM::NPC>* npc = ptr.get<ESM::NPC>();
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr playerPtr = getPlayer();
MWWorld::LiveCellRef<ESM::NPC>* player = playerPtr.get<ESM::NPC>(); MWWorld::LiveCellRef<ESM::NPC>* player = playerPtr.get<ESM::NPC>();
const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr);
@ -663,7 +664,7 @@ namespace MWMechanics
const MWMechanics::NpcStats &sellerStats = ptr.getClass().getNpcStats(ptr); const MWMechanics::NpcStats &sellerStats = ptr.getClass().getNpcStats(ptr);
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr playerPtr = getPlayer();
const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr);
// I suppose the temporary disposition change _has_ to be considered here, // I suppose the temporary disposition change _has_ to be considered here,
@ -707,7 +708,7 @@ namespace MWMechanics
MWMechanics::NpcStats& npcStats = npc.getClass().getNpcStats(npc); MWMechanics::NpcStats& npcStats = npc.getClass().getNpcStats(npc);
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr playerPtr = getPlayer();
const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr); const MWMechanics::NpcStats &playerStats = playerPtr.getClass().getNpcStats(playerPtr);
float npcRating1, npcRating2, npcRating3; float npcRating1, npcRating2, npcRating3;
@ -1010,7 +1011,7 @@ namespace MWMechanics
void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, const MWWorld::Ptr& container, void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, const MWWorld::Ptr& container,
int count) int count)
{ {
if (ptr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr != getPlayer())
return; return;
MWWorld::Ptr victim; MWWorld::Ptr victim;
@ -1067,7 +1068,7 @@ namespace MWMechanics
// NOTE: victim may be empty // NOTE: victim may be empty
// Only player can commit crime // Only player can commit crime
if (player != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (player != getPlayer())
return false; return false;
// Find all the actors within the alarm radius // Find all the actors within the alarm radius
@ -1306,15 +1307,16 @@ namespace MWMechanics
bool MechanicsManager::actorAttacked(const MWWorld::Ptr &ptr, const MWWorld::Ptr &attacker) bool MechanicsManager::actorAttacked(const MWWorld::Ptr &ptr, const MWWorld::Ptr &attacker)
{ {
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == getPlayer())
return false; return false;
std::list<MWWorld::Ptr> followers = getActorsFollowing(attacker); std::list<MWWorld::Ptr> followers = getActorsFollowing(attacker);
MWMechanics::CreatureStats& targetStats = ptr.getClass().getCreatureStats(ptr);
if (std::find(followers.begin(), followers.end(), ptr) != followers.end()) if (std::find(followers.begin(), followers.end(), ptr) != followers.end())
{ {
ptr.getClass().getCreatureStats(ptr).friendlyHit(); targetStats.friendlyHit();
if (ptr.getClass().getCreatureStats(ptr).getFriendlyHits() < 4) if (targetStats.getFriendlyHits() < 4)
{ {
MWBase::Environment::get().getDialogueManager()->say(ptr, "hit"); MWBase::Environment::get().getDialogueManager()->say(ptr, "hit");
return false; return false;
@ -1322,7 +1324,7 @@ namespace MWMechanics
} }
// Attacking an NPC that is already in combat with any other NPC is not a crime // Attacking an NPC that is already in combat with any other NPC is not a crime
AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence(); AiSequence& seq = targetStats.getAiSequence();
bool isFightingNpc = false; bool isFightingNpc = false;
for (std::list<AiPackage*>::const_iterator it = seq.begin(); it != seq.end(); ++it) for (std::list<AiPackage*>::const_iterator it = seq.begin(); it != seq.end(); ++it)
{ {
@ -1334,13 +1336,13 @@ namespace MWMechanics
} }
} }
if (ptr.getClass().isNpc() && !attacker.isEmpty() && !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(attacker) if (ptr.getClass().isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker)
&& !isAggressive(ptr, attacker) && !isFightingNpc) && !isAggressive(ptr, attacker) && !isFightingNpc)
commitCrime(attacker, ptr, MWBase::MechanicsManager::OT_Assault); commitCrime(attacker, ptr, MWBase::MechanicsManager::OT_Assault);
if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(ptr) if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(ptr)
|| attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) || attacker == getPlayer())
&& !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(attacker)) && !seq.isInCombat(attacker))
{ {
// Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back. // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
// Note: accidental or collateral damage attacks are ignored. // Note: accidental or collateral damage attacks are ignored.
@ -1352,7 +1354,7 @@ namespace MWMechanics
void MechanicsManager::actorKilled(const MWWorld::Ptr &victim, const MWWorld::Ptr &attacker) void MechanicsManager::actorKilled(const MWWorld::Ptr &victim, const MWWorld::Ptr &attacker)
{ {
if (attacker.isEmpty() || attacker != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (attacker.isEmpty() || attacker != getPlayer())
return; return;
if (victim == attacker) if (victim == attacker)
@ -1449,7 +1451,7 @@ namespace MWMechanics
if (ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(target)) if (ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(target))
return; return;
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(MWMechanics::AiCombat(target), ptr); ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(MWMechanics::AiCombat(target), ptr);
if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (target == getPlayer())
{ {
// if guard starts combat with player, guards pursuing player should do the same // if guard starts combat with player, guards pursuing player should do the same
if (ptr.getClass().isClass(ptr, "Guard")) if (ptr.getClass().isClass(ptr, "Guard"))
@ -1546,7 +1548,7 @@ namespace MWMechanics
if (ptr.getClass().isNpc() && target.getClass().isNpc()) if (ptr.getClass().isNpc() && target.getClass().isNpc())
{ {
if (target.getClass().getNpcStats(target).isWerewolf() || if (target.getClass().getNpcStats(target).isWerewolf() ||
(target == MWBase::Environment::get().getWorld()->getPlayerPtr() && (target == getPlayer() &&
MWBase::Environment::get().getWorld()->getGlobalInt("pcknownwerewolf"))) MWBase::Environment::get().getWorld()->getGlobalInt("pcknownwerewolf")))
{ {
const ESM::GameSetting * iWerewolfFightMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("iWerewolfFightMod"); const ESM::GameSetting * iWerewolfFightMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("iWerewolfFightMod");
@ -1559,7 +1561,7 @@ namespace MWMechanics
void MechanicsManager::keepPlayerAlive() void MechanicsManager::keepPlayerAlive()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
CreatureStats& stats = player.getClass().getCreatureStats(player); CreatureStats& stats = player.getClass().getCreatureStats(player);
if (stats.isDead()) if (stats.isDead())
{ {

View file

@ -14,15 +14,16 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "npcstats.hpp"
#include "actorutil.hpp"
namespace MWMechanics namespace MWMechanics
{ {
void Repair::repair(const MWWorld::Ptr &itemToRepair) void Repair::repair(const MWWorld::Ptr &itemToRepair)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
MWWorld::LiveCellRef<ESM::Repair> *ref = MWWorld::LiveCellRef<ESM::Repair> *ref =
mTool.get<ESM::Repair>(); mTool.get<ESM::Repair>();
@ -82,7 +83,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
// tool used up? // tool used up?
if (mTool.getCellRef().getCharge() == 0) if (mTool.getCellRef().getCharge() == 0)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = getPlayer();
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
store.remove(mTool, 1, player); store.remove(mTool, 1, player);

View file

@ -27,6 +27,7 @@
#include "magiceffects.hpp" #include "magiceffects.hpp"
#include "npcstats.hpp" #include "npcstats.hpp"
#include "summoning.hpp" #include "summoning.hpp"
#include "actorutil.hpp"
namespace namespace
{ {
@ -134,7 +135,7 @@ namespace MWMechanics
int actorLuck = stats.getAttribute(ESM::Attribute::Luck).getModified(); int actorLuck = stats.getAttribute(ESM::Attribute::Luck).getModified();
float castChance = (lowestSkill - spell->mData.mCost + castBonus + 0.2f * actorWillpower + 0.1f * actorLuck) * stats.getFatigueTerm(); float castChance = (lowestSkill - spell->mData.mCost + castBonus + 0.2f * actorWillpower + 0.1f * actorLuck) * stats.getFatigueTerm();
if (MWBase::Environment::get().getWorld()->getGodModeState() && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (MWBase::Environment::get().getWorld()->getGodModeState() && actor == getPlayer())
castChance = 100; castChance = 100;
if (!cap) if (!cap)
@ -333,14 +334,15 @@ namespace MWMechanics
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
if (spell && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight)) if (spell && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
{ {
float x = (spell->mData.mType == ESM::Spell::ST_Disease) ? int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistCommonDisease).getMagnitude() ESM::MagicEffect::ResistCommonDisease
: target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistBlightDisease).getMagnitude(); : ESM::MagicEffect::ResistBlightDisease;
float x = target.getClass().getCreatureStats(target).getMagicEffects().get(requiredResistance).getMagnitude();
if (Misc::Rng::roll0to99() <= x) if (Misc::Rng::roll0to99() <= x)
{ {
// Fully resisted, show message // Fully resisted, show message
if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (target == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}");
return; return;
} }
@ -358,7 +360,7 @@ namespace MWMechanics
if (target.getClass().isActor()) if (target.getClass().isActor())
targetEffects += target.getClass().getCreatureStats(target).getMagicEffects(); targetEffects += target.getClass().getCreatureStats(target).getMagicEffects();
bool castByPlayer = (!caster.isEmpty() && caster == MWBase::Environment::get().getWorld()->getPlayerPtr()); bool castByPlayer = (!caster.isEmpty() && caster == getPlayer());
// Try absorbing if it's a spell // Try absorbing if it's a spell
// NOTE: Vanilla does this once per effect source instead of adding the % from all sources together, not sure // NOTE: Vanilla does this once per effect source instead of adding the % from all sources together, not sure
@ -433,7 +435,7 @@ namespace MWMechanics
if (magnitudeMult == 0) if (magnitudeMult == 0)
{ {
// Fully resisted, show message // Fully resisted, show message
if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (target == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}");
else if (castByPlayer) else if (castByPlayer)
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}");
@ -569,7 +571,7 @@ namespace MWMechanics
{ {
if (target.getCellRef().getLockLevel() < magnitude) //If the door is not already locked to a higher value, lock it to spell magnitude if (target.getCellRef().getLockLevel() < magnitude) //If the door is not already locked to a higher value, lock it to spell magnitude
{ {
if (caster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (caster == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}");
target.getClass().lock(target, static_cast<int>(magnitude)); target.getClass().lock(target, static_cast<int>(magnitude));
} }
@ -585,7 +587,7 @@ namespace MWMechanics
if (!caster.isEmpty() && caster.getClass().isActor()) if (!caster.isEmpty() && caster.getClass().isActor())
MWBase::Environment::get().getMechanicsManager()->objectOpened(caster, target); MWBase::Environment::get().getMechanicsManager()->objectOpened(caster, target);
if (caster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (caster == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}");
} }
target.getClass().unlock(target); target.getClass().unlock(target);
@ -622,7 +624,7 @@ namespace MWMechanics
return true; return true;
} }
if (target != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (target != getPlayer())
return false; return false;
if (effectId == ESM::MagicEffect::DivineIntervention) if (effectId == ESM::MagicEffect::DivineIntervention)
@ -701,7 +703,7 @@ namespace MWMechanics
if (item.getCellRef().getEnchantmentCharge() < castCost) if (item.getCellRef().getEnchantmentCharge() < castCost)
{ {
if (mCaster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mCaster == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientCharge}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientCharge}");
// Failure sound // Failure sound
@ -725,14 +727,14 @@ namespace MWMechanics
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed) if (enchantment->mData.mType == ESM::Enchantment::WhenUsed)
{ {
if (mCaster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mCaster == getPlayer())
mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 1); mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 1);
} }
if (enchantment->mData.mType == ESM::Enchantment::CastOnce) if (enchantment->mData.mType == ESM::Enchantment::CastOnce)
item.getContainerStore()->remove(item, 1, mCaster); item.getContainerStore()->remove(item, 1, mCaster);
else if (enchantment->mData.mType != ESM::Enchantment::WhenStrikes) else if (enchantment->mData.mType != ESM::Enchantment::WhenStrikes)
{ {
if (mCaster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mCaster == getPlayer())
{ {
mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 3); mCaster.getClass().skillUsageSucceeded (mCaster, ESM::Skill::Enchant, 3);
} }
@ -799,7 +801,7 @@ namespace MWMechanics
float successChance = getSpellSuccessChance(spell, mCaster); float successChance = getSpellSuccessChance(spell, mCaster);
if (Misc::Rng::roll0to99() >= successChance) if (Misc::Rng::roll0to99() >= successChance)
{ {
if (mCaster == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mCaster == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}");
fail = true; fail = true;
} }
@ -817,7 +819,7 @@ namespace MWMechanics
} }
} }
if (mCaster == MWBase::Environment::get().getWorld()->getPlayerPtr() && spellIncreasesSkill(spell)) if (mCaster == getPlayer() && spellIncreasesSkill(spell))
mCaster.getClass().skillUsageSucceeded(mCaster, mCaster.getClass().skillUsageSucceeded(mCaster,
spellSchoolToSkill(school), 0); spellSchoolToSkill(school), 0);
@ -962,7 +964,7 @@ namespace MWMechanics
if (charge == 0) if (charge == 0)
{ {
// Will unequip the broken item and try to find a replacement // Will unequip the broken item and try to find a replacement
if (ptr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr != getPlayer())
inv.autoEquip(ptr); inv.autoEquip(ptr);
else else
inv.unequipItem(*item, ptr); inv.unequipItem(*item, ptr);
@ -1097,7 +1099,7 @@ namespace MWMechanics
} }
if (receivedMagicDamage && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (receivedMagicDamage && actor == getPlayer())
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
} }

View file

@ -30,6 +30,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/movement.hpp" #include "../mwmechanics/movement.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
@ -1091,7 +1092,7 @@ namespace MWPhysics
bool PhysicsSystem::toggleCollisionMode() bool PhysicsSystem::toggleCollisionMode()
{ {
ActorMap::iterator found = mActors.find(MWBase::Environment::get().getWorld()->getPlayerPtr()); ActorMap::iterator found = mActors.find(MWMechanics::getPlayer());
if (found != mActors.end()) if (found != mActors.end())
{ {
bool cmode = found->second->getCollisionMode(); bool cmode = found->second->getCollisionMode();

View file

@ -17,6 +17,8 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "npcanimation.hpp" #include "npcanimation.hpp"
#include "vismask.hpp" #include "vismask.hpp"
@ -295,7 +297,7 @@ namespace MWRender
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
RaceSelectionPreview::RaceSelectionPreview(osgViewer::Viewer* viewer, Resource::ResourceSystem* resourceSystem) RaceSelectionPreview::RaceSelectionPreview(osgViewer::Viewer* viewer, Resource::ResourceSystem* resourceSystem)
: CharacterPreview(viewer, resourceSystem, MWBase::Environment::get().getWorld()->getPlayerPtr(), : CharacterPreview(viewer, resourceSystem, MWMechanics::getPlayer(),
512, 512, osg::Vec3f(0, 125, 8), osg::Vec3f(0,0,8)) 512, 512, osg::Vec3f(0, 125, 8), osg::Vec3f(0,0,8))
, mBase (*mCharacter.get<ESM::NPC>()->mBase) , mBase (*mCharacter.get<ESM::NPC>()->mBase)
, mRef(&mBase) , mRef(&mBase)

View file

@ -21,6 +21,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -1039,7 +1040,7 @@ void NpcAnimation::setVampire(bool vampire)
return; return;
if ((mNpcType == Type_Vampire) != vampire) if ((mNpcType == Type_Vampire) != vampire)
{ {
if (mPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mPtr == MWMechanics::getPlayer())
MWBase::Environment::get().getWorld()->reattachPlayerCamera(); MWBase::Environment::get().getWorld()->reattachPlayerCamera();
else else
rebuild(); rebuild();

View file

@ -22,6 +22,8 @@
#include "../mwworld/fallback.hpp" #include "../mwworld/fallback.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace namespace
{ {
void createWaterRippleStateSet(Resource::ResourceSystem* resourceSystem, const MWWorld::Fallback* fallback, osg::Node* node) void createWaterRippleStateSet(Resource::ResourceSystem* resourceSystem, const MWWorld::Fallback* fallback, osg::Node* node)
@ -177,7 +179,7 @@ void RippleSimulation::removeCell(const MWWorld::CellStore *store)
{ {
for (std::vector<Emitter>::iterator it = mEmitters.begin(); it != mEmitters.end();) for (std::vector<Emitter>::iterator it = mEmitters.begin(); it != mEmitters.end();)
{ {
if (it->mPtr.getCell() == store && it->mPtr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (it->mPtr.getCell() == store && it->mPtr != MWMechanics::getPlayer())
{ {
it = mEmitters.erase(it); it = mEmitters.erase(it);
} }

View file

@ -16,6 +16,8 @@
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
namespace MWScript namespace MWScript
@ -91,14 +93,14 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) if (!MWMechanics::getPlayer().isInCell())
{ {
runtime.push (0); runtime.push (0);
return; return;
} }
bool interior = bool interior =
!MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->isExterior(); !MWMechanics::getPlayer().getCell()->getCell()->isExterior();
runtime.push (interior ? 1 : 0); runtime.push (interior ? 1 : 0);
} }
@ -113,12 +115,12 @@ namespace MWScript
std::string name = runtime.getStringLiteral (runtime[0].mInteger); std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) if (!MWMechanics::getPlayer().isInCell())
{ {
runtime.push(0); runtime.push(0);
return; return;
} }
const MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); const MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
std::string current = MWBase::Environment::get().getWorld()->getCellName(cell); std::string current = MWBase::Environment::get().getWorld()->getCellName(cell);
Misc::StringUtils::toLower(current); Misc::StringUtils::toLower(current);
@ -136,12 +138,12 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) if (!MWMechanics::getPlayer().isInCell())
{ {
runtime.push(0.f); runtime.push(0.f);
return; return;
} }
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
if (cell->getCell()->hasWater()) if (cell->getCell()->hasWater())
runtime.push (cell->getWaterLevel()); runtime.push (cell->getWaterLevel());
else else
@ -157,12 +159,12 @@ namespace MWScript
{ {
Interpreter::Type_Float level = runtime[0].mFloat; Interpreter::Type_Float level = runtime[0].mFloat;
if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) if (!MWMechanics::getPlayer().isInCell())
{ {
return; return;
} }
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
if (cell->getCell()->isExterior()) if (cell->getCell()->isExterior())
throw std::runtime_error("Can't set water level in exterior cell"); throw std::runtime_error("Can't set water level in exterior cell");
@ -180,12 +182,12 @@ namespace MWScript
{ {
Interpreter::Type_Float level = runtime[0].mFloat; Interpreter::Type_Float level = runtime[0].mFloat;
if (!MWBase::Environment::get().getWorld()->getPlayerPtr().isInCell()) if (!MWMechanics::getPlayer().isInCell())
{ {
return; return;
} }
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
if (cell->getCell()->isExterior()) if (cell->getCell()->isExterior())
throw std::runtime_error("Can't set water level in exterior cell"); throw std::runtime_error("Can't set water level in exterior cell");

View file

@ -26,6 +26,8 @@
#include "../mwworld/actionequip.hpp" #include "../mwworld/actionequip.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -147,7 +149,7 @@ namespace MWScript
// Spawn a messagebox (only for items removed from player's inventory) // Spawn a messagebox (only for items removed from player's inventory)
if ((numRemoved > 0) if ((numRemoved > 0)
&& (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())) && (ptr == MWMechanics::getPlayer()))
{ {
// The two GMST entries below expand to strings informing the player of what, and how many of it has been removed from their inventory // The two GMST entries below expand to strings informing the player of what, and how many of it has been removed from their inventory
std::string msgBox; std::string msgBox;
@ -192,7 +194,7 @@ namespace MWScript
MWWorld::ActionEquip action (*it); MWWorld::ActionEquip action (*it);
action.execute(ptr); action.execute(ptr);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr() && !ptr.getClass().getScript(ptr).empty()) if (ptr == MWMechanics::getPlayer() && !ptr.getClass().getScript(ptr).empty())
ptr.getRefData().getLocals().setVarByInt(ptr.getClass().getScript(ptr), "onpcequip", 1); ptr.getRefData().getLocals().setVarByInt(ptr.getClass().getScript(ptr), "onpcequip", 1);
} }
}; };

View file

@ -14,6 +14,8 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -53,7 +55,7 @@ namespace MWScript
{ {
MWWorld::Ptr bed = R()(runtime, false); MWWorld::Ptr bed = R()(runtime, false);
if (bed.isEmpty() || !MWBase::Environment::get().getMechanicsManager()->sleepInBed(MWBase::Environment::get().getWorld()->getPlayerPtr(), if (bed.isEmpty() || !MWBase::Environment::get().getMechanicsManager()->sleepInBed(MWMechanics::getPlayer(),
bed)) bed))
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_RestBed); MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_RestBed);
} }

View file

@ -27,6 +27,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -156,7 +157,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
context.executeActivation(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr()); context.executeActivation(ptr, MWMechanics::getPlayer());
} }
}; };
@ -976,7 +977,7 @@ namespace MWScript
public: public:
virtual void execute(Interpreter::Runtime &runtime) virtual void execute(Interpreter::Runtime &runtime)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).setBounty(0); player.getClass().getNpcStats(player).setBounty(0);
MWBase::Environment::get().getWorld()->confiscateStolenItems(player); MWBase::Environment::get().getWorld()->confiscateStolenItems(player);
MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId(); MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId();
@ -988,7 +989,7 @@ namespace MWScript
public: public:
virtual void execute(Interpreter::Runtime &runtime) virtual void execute(Interpreter::Runtime &runtime)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).setBounty(0); player.getClass().getNpcStats(player).setBounty(0);
MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId(); MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId();
} }

View file

@ -25,6 +25,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -460,7 +461,7 @@ namespace MWScript
MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr() && if (ptr == MWMechanics::getPlayer() &&
id == wm->getSelectedSpell()) id == wm->getSelectedSpell())
{ {
wm->unsetSelectedSpell(); wm->unsetSelectedSpell();
@ -548,7 +549,7 @@ namespace MWScript
if(factionID != "") if(factionID != "")
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).joinFaction(factionID); player.getClass().getNpcStats(player).joinFaction(factionID);
} }
} }
@ -580,7 +581,7 @@ namespace MWScript
if(factionID != "") if(factionID != "")
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end()) if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end())
{ {
player.getClass().getNpcStats(player).joinFaction(factionID); player.getClass().getNpcStats(player).joinFaction(factionID);
@ -619,7 +620,7 @@ namespace MWScript
if(factionID != "") if(factionID != "")
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).lowerRank(factionID); player.getClass().getNpcStats(player).lowerRank(factionID);
} }
} }
@ -648,7 +649,7 @@ namespace MWScript
// Make sure this faction exists // Make sure this faction exists
MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID); MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(factionID!="")
{ {
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end()) if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end())
@ -757,7 +758,7 @@ namespace MWScript
::Misc::StringUtils::toLower (factionId); ::Misc::StringUtils::toLower (factionId);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
runtime.push ( runtime.push (
player.getClass().getNpcStats (player).getFactionReputation (factionId)); player.getClass().getNpcStats (player).getFactionReputation (factionId));
} }
@ -792,7 +793,7 @@ namespace MWScript
::Misc::StringUtils::toLower (factionId); ::Misc::StringUtils::toLower (factionId);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats (player).setFactionReputation (factionId, value); player.getClass().getNpcStats (player).setFactionReputation (factionId, value);
} }
}; };
@ -826,7 +827,7 @@ namespace MWScript
::Misc::StringUtils::toLower (factionId); ::Misc::StringUtils::toLower (factionId);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats (player).setFactionReputation (factionId, player.getClass().getNpcStats (player).setFactionReputation (factionId,
player.getClass().getNpcStats (player).getFactionReputation (factionId)+ player.getClass().getNpcStats (player).getFactionReputation (factionId)+
value); value);
@ -911,7 +912,7 @@ namespace MWScript
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
::Misc::StringUtils::toLower(factionID); ::Misc::StringUtils::toLower(factionID);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(factionID!="")
{ {
runtime.push(player.getClass().getNpcStats(player).getExpelled(factionID)); runtime.push(player.getClass().getNpcStats(player).getExpelled(factionID));
@ -942,7 +943,7 @@ namespace MWScript
{ {
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(factionID!="")
{ {
player.getClass().getNpcStats(player).expell(factionID); player.getClass().getNpcStats(player).expell(factionID);
@ -969,7 +970,7 @@ namespace MWScript
{ {
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(factionID!="")
player.getClass().getNpcStats(player).clearExpelled(factionID); player.getClass().getNpcStats(player).clearExpelled(factionID);
} }
@ -988,7 +989,7 @@ namespace MWScript
if(factionID.empty()) if(factionID.empty())
return; return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
// no-op when executed on the player // no-op when executed on the player
if (ptr == player) if (ptr == player)
@ -1011,7 +1012,7 @@ namespace MWScript
if(factionID.empty()) if(factionID.empty())
return; return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
// no-op when executed on the player // no-op when executed on the player
if (ptr == player) if (ptr == player)
@ -1120,7 +1121,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
ptr.getClass().getCreatureStats(ptr).resurrect(); ptr.getClass().getCreatureStats(ptr).resurrect();
else if (ptr.getClass().getCreatureStats(ptr).isDead()) else if (ptr.getClass().getCreatureStats(ptr).isDead())
{ {
@ -1159,10 +1160,10 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); const MWMechanics::MagicEffects& effects = ptr.getClass().getCreatureStats(ptr).getMagicEffects();
float currentValue = stats.getMagicEffects().get(mPositiveEffect).getMagnitude(); float currentValue = effects.get(mPositiveEffect).getMagnitude();
if (mNegativeEffect != -1) if (mNegativeEffect != -1)
currentValue -= stats.getMagicEffects().get(mNegativeEffect).getMagnitude(); currentValue -= effects.get(mNegativeEffect).getMagnitude();
int ret = static_cast<int>(currentValue); int ret = static_cast<int>(currentValue);
runtime.push(ret); runtime.push(ret);
@ -1185,14 +1186,14 @@ namespace MWScript
virtual void execute(Interpreter::Runtime &runtime) virtual void execute(Interpreter::Runtime &runtime)
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); MWMechanics::MagicEffects& effects = ptr.getClass().getCreatureStats(ptr).getMagicEffects();
float currentValue = stats.getMagicEffects().get(mPositiveEffect).getMagnitude(); float currentValue = effects.get(mPositiveEffect).getMagnitude();
if (mNegativeEffect != -1) if (mNegativeEffect != -1)
currentValue -= stats.getMagicEffects().get(mNegativeEffect).getMagnitude(); currentValue -= effects.get(mNegativeEffect).getMagnitude();
int arg = runtime[0].mInteger; int arg = runtime[0].mInteger;
runtime.pop(); runtime.pop();
stats.getMagicEffects().modifyBase(mPositiveEffect, (arg - static_cast<int>(currentValue))); effects.modifyBase(mPositiveEffect, (arg - static_cast<int>(currentValue)));
} }
}; };

View file

@ -20,6 +20,8 @@
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -214,7 +216,7 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
} }
@ -289,7 +291,7 @@ namespace MWScript
if (ptr.getContainerStore()) if (ptr.getContainerStore())
return; return;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
} }
@ -333,7 +335,7 @@ namespace MWScript
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200) // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used. // except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. // See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
if(ptr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if(ptr != MWMechanics::getPlayer())
zRot = zRot/60.0f; zRot = zRot/60.0f;
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot); MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot);
@ -354,7 +356,7 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
} }
@ -372,7 +374,7 @@ namespace MWScript
// another morrowind oddity: player will be moved to the exterior cell at this location, // another morrowind oddity: player will be moved to the exterior cell at this location,
// non-player actors will move within the cell they are in. // non-player actors will move within the cell they are in.
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWMechanics::getPlayer())
{ {
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy); MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
MWBase::Environment::get().getWorld()->moveObject(ptr,cell,x,y,z); MWBase::Environment::get().getWorld()->moveObject(ptr,cell,x,y,z);
@ -389,7 +391,7 @@ namespace MWScript
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200) // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200)
// except for when you position the player, then degrees must be used. // except for when you position the player, then degrees must be used.
// See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. // See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
if(ptr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if(ptr != MWMechanics::getPlayer())
zRot = zRot/60.0f; zRot = zRot/60.0f;
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot); MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,zRot);
ptr.getClass().adjustPosition(ptr, false); ptr.getClass().adjustPosition(ptr, false);
@ -469,7 +471,7 @@ namespace MWScript
Interpreter::Type_Float zRot = runtime[0].mFloat; Interpreter::Type_Float zRot = runtime[0].mFloat;
runtime.pop(); runtime.pop();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::CellStore* store = NULL; MWWorld::CellStore* store = NULL;
if (player.getCell()->isExterior()) if (player.getCell()->isExterior())
{ {
@ -501,7 +503,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr actor = pc MWWorld::Ptr actor = pc
? MWBase::Environment::get().getWorld()->getPlayerPtr() ? MWMechanics::getPlayer()
: R()(runtime); : R()(runtime);
std::string itemID = runtime.getStringLiteral (runtime[0].mInteger); std::string itemID = runtime.getStringLiteral (runtime[0].mInteger);

View file

@ -15,6 +15,8 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "sound_output.hpp" #include "sound_output.hpp"
#include "sound_decoder.hpp" #include "sound_decoder.hpp"
#include "sound.hpp" #include "sound.hpp"
@ -490,7 +492,7 @@ namespace MWSound
while(snditer != mActiveSounds.end()) while(snditer != mActiveSounds.end())
{ {
if(snditer->second.first != MWWorld::Ptr() && if(snditer->second.first != MWWorld::Ptr() &&
snditer->second.first != MWBase::Environment::get().getWorld()->getPlayerPtr() && snditer->second.first != MWMechanics::getPlayer() &&
snditer->second.first.getCell() == cell) snditer->second.first.getCell() == cell)
{ {
snditer->first->stop(); snditer->first->stop();
@ -735,7 +737,7 @@ namespace MWSound
mListenerUp = up; mListenerUp = up;
MWWorld::Ptr player = MWWorld::Ptr player =
MWBase::Environment::get().getWorld()->getPlayerPtr(); MWMechanics::getPlayer();
const MWWorld::CellStore *cell = player.getCell(); const MWWorld::CellStore *cell = player.getCell();
mListenerUnderwater = ((cell->getCell()->mData.mFlags&ESM::Cell::HasWater) && mListenerPos.z() < cell->getWaterLevel()); mListenerUnderwater = ((cell->getCell()->mData.mFlags&ESM::Cell::HasWater) && mListenerPos.z() < cell->getWaterLevel());

View file

@ -36,6 +36,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwscript/globalscripts.hpp" #include "../mwscript/globalscripts.hpp"
@ -472,7 +473,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
if (firstPersonCam != MWBase::Environment::get().getWorld()->isFirstPerson()) if (firstPersonCam != MWBase::Environment::get().getWorld()->isFirstPerson())
MWBase::Environment::get().getWorld()->togglePOV(); MWBase::Environment::get().getWorld()->togglePOV();
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr ptr = MWMechanics::getPlayer();
ESM::CellId cellId = ptr.getCell()->getCell()->getCellId(); ESM::CellId cellId = ptr.getCell()->getCell()->getCellId();
@ -519,7 +520,7 @@ void MWState::StateManager::deleteGame(const MWState::Character *character, cons
MWState::Character *MWState::StateManager::getCurrentCharacter (bool create) MWState::Character *MWState::StateManager::getCurrentCharacter (bool create)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
std::string name = player.get<ESM::NPC>()->mBase->mName; std::string name = player.get<ESM::NPC>()->mBase->mName;
return mCharacterManager.getCurrentCharacter (create, name); return mCharacterManager.getCurrentCharacter (create, name);

View file

@ -5,6 +5,8 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
const MWWorld::Ptr& MWWorld::Action::getTarget() const const MWWorld::Ptr& MWWorld::Action::getTarget() const
{ {
return mTarget; return mTarget;
@ -19,7 +21,7 @@ void MWWorld::Action::execute (const Ptr& actor)
{ {
if (!mSoundId.empty()) if (!mSoundId.empty())
{ {
if (mKeepSound && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (mKeepSound && actor == MWMechanics::getPlayer())
MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0, MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0,
MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Normal,mSoundOffset); MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Normal,mSoundOffset);
else else

View file

@ -4,6 +4,8 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include <components/compiler/locals.hpp> #include <components/compiler/locals.hpp>
#include "inventorystore.hpp" #include "inventorystore.hpp"
@ -24,7 +26,7 @@ namespace MWWorld
std::pair <int, std::string> result = object.getClass().canBeEquipped (object, actor); std::pair <int, std::string> result = object.getClass().canBeEquipped (object, actor);
// display error message if the player tried to equip something // display error message if the player tried to equip something
if (!result.second.empty() && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (!result.second.empty() && actor == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(result.second); MWBase::Environment::get().getWindowManager()->messageBox(result.second);
switch(result.first) switch(result.first)

View file

@ -11,6 +11,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/levelledlist.hpp" #include "../mwmechanics/levelledlist.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "manualref.hpp" #include "manualref.hpp"
#include "refdata.hpp" #include "refdata.hpp"
@ -209,7 +210,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &
{ {
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count);
// a bit pointless to set owner for the player // a bit pointless to set owner for the player
if (actorPtr != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actorPtr != MWMechanics::getPlayer())
return add(ref.getPtr(), count, actorPtr, true); return add(ref.getPtr(), count, actorPtr, true);
else else
return add(ref.getPtr(), count, actorPtr, false); return add(ref.getPtr(), count, actorPtr, false);
@ -224,7 +225,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr
// HACK: Set owner on the original item, then reset it after we have copied it // HACK: Set owner on the original item, then reset it after we have copied it
// If we set the owner on the copied item, it would not stack correctly... // If we set the owner on the copied item, it would not stack correctly...
std::string oldOwner = itemPtr.getCellRef().getOwner(); std::string oldOwner = itemPtr.getCellRef().getOwner();
if (!setOwner || actorPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) // No point in setting owner to the player - NPCs will not respect this anyway if (!setOwner || actorPtr == MWMechanics::getPlayer()) // No point in setting owner to the player - NPCs will not respect this anyway
{ {
itemPtr.getCellRef().setOwner(""); itemPtr.getCellRef().setOwner("");
} }

View file

@ -4,6 +4,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWWorld namespace MWWorld
{ {
@ -13,7 +14,7 @@ namespace MWWorld
void FailedAction::executeImp(const Ptr &actor) void FailedAction::executeImp(const Ptr &actor)
{ {
if(actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && !mMessage.empty()) if(actor == MWMechanics::getPlayer() && !mMessage.empty())
MWBase::Environment::get().getWindowManager()->messageBox(mMessage); MWBase::Environment::get().getWindowManager()->messageBox(mMessage);
} }
} }

View file

@ -16,6 +16,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "esmstore.hpp" #include "esmstore.hpp"
@ -136,7 +137,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr, setOwner); const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr, setOwner);
// Auto-equip items if an armor/clothing or weapon item is added, but not for the player nor werewolves // Auto-equip items if an armor/clothing or weapon item is added, but not for the player nor werewolves
if (actorPtr != MWBase::Environment::get().getWorld()->getPlayerPtr() if (actorPtr != MWMechanics::getPlayer()
&& !(actorPtr.getClass().isNpc() && actorPtr.getClass().getNpcStats(actorPtr).isWerewolf())) && !(actorPtr.getClass().isNpc() && actorPtr.getClass().getNpcStats(actorPtr).isWerewolf()))
{ {
std::string type = itemPtr.getTypeName(); std::string type = itemPtr.getTypeName();
@ -508,7 +509,7 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
// If an armor/clothing item is removed, try to find a replacement, // If an armor/clothing item is removed, try to find a replacement,
// but not for the player nor werewolves. // but not for the player nor werewolves.
if (wasEquipped && (actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (wasEquipped && (actor != MWMechanics::getPlayer())
&& !(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())) && !(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()))
{ {
std::string type = item.getTypeName(); std::string type = item.getTypeName();
@ -540,7 +541,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c
{ {
retval = restack(*it); retval = restack(*it);
if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor == MWMechanics::getPlayer())
{ {
// Unset OnPCEquip Variable on item's script, if it has a script with that variable declared // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared
const std::string& script = it->getClass().getScript(*it); const std::string& script = it->getClass().getScript(*it);
@ -595,7 +596,7 @@ void MWWorld::InventoryStore::fireEquipmentChangedEvent(const Ptr& actor)
// if player, update inventory window // if player, update inventory window
/* /*
if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView(); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
} }

View file

@ -20,6 +20,7 @@
#include "../mwmechanics/combat.hpp" #include "../mwmechanics/combat.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwrender/effectmanager.hpp" #include "../mwrender/effectmanager.hpp"
#include "../mwrender/animation.hpp" #include "../mwrender/animation.hpp"
@ -187,7 +188,7 @@ namespace MWWorld
} }
// Explodes when hitting water // Explodes when hitting water
if (MWBase::Environment::get().getWorld()->isUnderwater(MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(), newPos)) if (MWBase::Environment::get().getWorld()->isUnderwater(MWMechanics::getPlayer().getCell(), newPos))
hit = true; hit = true;
if (hit) if (hit)

View file

@ -12,6 +12,8 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwsound/sound.hpp" #include "../mwsound/sound.hpp"
#include "../mwrender/renderingmanager.hpp" #include "../mwrender/renderingmanager.hpp"
@ -798,7 +800,7 @@ void WeatherManager::changeWeather(const std::string& region, const unsigned int
mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather; mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWMechanics::getPlayer();
if (player.isInCell()) if (player.isInCell())
{ {
std::string playerRegion = player.getCell()->getCell()->mRegion; std::string playerRegion = player.getCell()->getCell()->mRegion;

View file

@ -1924,16 +1924,15 @@ namespace MWWorld
bool World::isFlying(const MWWorld::Ptr &ptr) const bool World::isFlying(const MWWorld::Ptr &ptr) const
{ {
const MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); const MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
bool isParalyzed = (stats.getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0);
if(!ptr.getClass().isActor()) if(!ptr.getClass().isActor())
return false; return false;
if (ptr.getClass().getCreatureStats(ptr).isDead()) if (stats.isDead())
return false; return false;
if (ptr.getClass().canFly(ptr)) if (ptr.getClass().canFly(ptr))
return !isParalyzed; return !stats.isParalyzed();
if(stats.getMagicEffects().get(ESM::MagicEffect::Levitate).getMagnitude() > 0 if(stats.getMagicEffects().get(ESM::MagicEffect::Levitate).getMagnitude() > 0
&& isLevitationEnabled()) && isLevitationEnabled())