@ -54,9 +54,17 @@ void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& a
{
{
if ( actor . getClass ( ) . getContainerStore ( actor ) . count ( item ) = = 0 )
if ( actor . getClass ( ) . getContainerStore ( actor ) . count ( item ) = = 0 )
{
{
MWWorld : : Ptr newPtr = * actor . getClass ( ) . getContainerStore ( actor ) . add ( item , 1 , actor ) ;
MWWorld : : InventoryStore & store = actor . getClass ( ) . getInventoryStore ( actor ) ;
MWWorld : : Ptr newPtr = * store . MWWorld : : ContainerStore : : add ( item , 1 , actor ) ;
MWWorld : : ActionEquip action ( newPtr ) ;
MWWorld : : ActionEquip action ( newPtr ) ;
action . execute ( actor ) ;
action . execute ( actor ) ;
MWWorld : : ContainerStoreIterator rightHand = store . getSlot ( MWWorld : : InventoryStore : : Slot_CarriedRight ) ;
// change draw state only if the item is in player's right hand
if ( actor = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( )
& & rightHand ! = store . end ( ) & & newPtr = = * rightHand )
{
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Weapon ) ;
}
}
}
}
}
else
else
@ -91,7 +99,7 @@ bool disintegrateSlot (MWWorld::Ptr ptr, int slot, float disintegrate)
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 . getRefData ( ) . getHandle ( ) ! = " player " )
if ( ptr ! = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
inv . autoEquip ( ptr ) ;
inv . autoEquip ( ptr ) ;
else
else
inv . unequipItem ( * item , ptr ) ;
inv . unequipItem ( * item , ptr ) ;
@ -146,6 +154,7 @@ void adjustCommandedActor (const MWWorld::Ptr& actor)
if ( check . mCommanded & & ! hasCommandPackage )
if ( check . mCommanded & & ! hasCommandPackage )
{
{
// FIXME: don't use refid string
MWMechanics : : AiFollow package ( " player " , true ) ;
MWMechanics : : AiFollow package ( " player " , true ) ;
stats . getAiSequence ( ) . stack ( package , actor ) ;
stats . getAiSequence ( ) . stack ( package , actor ) ;
}
}
@ -236,7 +245,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 . getRefData ( ) . getHandle ( ) = = " player " )
if ( caster = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
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 > ( )
@ -425,7 +434,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 . getCellRef ( ) . getRefId ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
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 ( ) ;
@ -515,8 +524,8 @@ namespace MWMechanics
for ( int i = 0 ; i < ESM : : Attribute : : Length ; + + i )
for ( int i = 0 ; i < ESM : : Attribute : : Length ; + + i )
{
{
AttributeValue stat = creatureStats . getAttribute ( i ) ;
AttributeValue stat = creatureStats . getAttribute ( i ) ;
stat . setModifier s ( effects . get ( EffectKey ( ESM : : MagicEffect : : FortifyAttribute , i ) ) . getMagnitude ( ) ,
stat . setModifier ( effects . get ( EffectKey ( ESM : : MagicEffect : : FortifyAttribute , i ) ) . getMagnitude ( ) -
effects . get ( EffectKey ( ESM : : MagicEffect : : DrainAttribute , i ) ) . getMagnitude ( ) ,
effects . get ( EffectKey ( ESM : : MagicEffect : : DrainAttribute , i ) ) . getMagnitude ( ) -
effects . get ( EffectKey ( ESM : : MagicEffect : : AbsorbAttribute , i ) ) . getMagnitude ( ) ) ;
effects . get ( EffectKey ( ESM : : MagicEffect : : AbsorbAttribute , i ) ) . getMagnitude ( ) ) ;
stat . damage ( effects . get ( EffectKey ( ESM : : MagicEffect : : DamageAttribute , i ) ) . getMagnitude ( ) * duration ) ;
stat . damage ( effects . get ( EffectKey ( ESM : : MagicEffect : : DamageAttribute , i ) ) . getMagnitude ( ) * duration ) ;
@ -535,7 +544,7 @@ namespace MWMechanics
{
{
spells . worsenCorprus ( it - > first ) ;
spells . worsenCorprus ( it - > first ) ;
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sMagicCorprusWorsens} " ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sMagicCorprusWorsens} " ) ;
}
}
}
}
@ -547,7 +556,9 @@ namespace MWMechanics
{
{
DynamicStat < float > stat = creatureStats . getDynamic ( i ) ;
DynamicStat < float > stat = creatureStats . getDynamic ( i ) ;
stat . setModifier ( effects . get ( ESM : : MagicEffect : : FortifyHealth + i ) . getMagnitude ( ) -
stat . setModifier ( effects . get ( ESM : : MagicEffect : : FortifyHealth + i ) . getMagnitude ( ) -
effects . get ( ESM : : MagicEffect : : DrainHealth + i ) . getMagnitude ( ) ) ;
effects . get ( ESM : : MagicEffect : : DrainHealth + i ) . getMagnitude ( ) ,
// Fatigue can be decreased below zero meaning the actor will be knocked out
i = = 2 ) ;
float currentDiff = creatureStats . getMagicEffects ( ) . get ( ESM : : MagicEffect : : RestoreHealth + i ) . getMagnitude ( )
float currentDiff = creatureStats . getMagicEffects ( ) . get ( ESM : : MagicEffect : : RestoreHealth + i ) . getMagnitude ( )
@ -655,7 +666,7 @@ namespace MWMechanics
}
}
}
}
if ( receivedMagicDamage & & ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( receivedMagicDamage & & ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > activateHitOverlay ( false ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > activateHitOverlay ( false ) ;
creatureStats . setHealth ( health ) ;
creatureStats . setHealth ( health ) ;
@ -782,8 +793,8 @@ namespace MWMechanics
for ( int i = 0 ; i < ESM : : Skill : : Length ; + + i )
for ( int i = 0 ; i < ESM : : Skill : : Length ; + + i )
{
{
SkillValue & skill = npcStats . getSkill ( i ) ;
SkillValue & skill = npcStats . getSkill ( i ) ;
skill . setModifier s ( effects . get ( EffectKey ( ESM : : MagicEffect : : FortifySkill , i ) ) . getMagnitude ( ) ,
skill . setModifier ( effects . get ( EffectKey ( ESM : : MagicEffect : : FortifySkill , i ) ) . getMagnitude ( ) -
effects . get ( EffectKey ( ESM : : MagicEffect : : DrainSkill , i ) ) . getMagnitude ( ) ,
effects . get ( EffectKey ( ESM : : MagicEffect : : DrainSkill , i ) ) . getMagnitude ( ) -
effects . get ( EffectKey ( ESM : : MagicEffect : : AbsorbSkill , i ) ) . getMagnitude ( ) ) ;
effects . get ( EffectKey ( ESM : : MagicEffect : : AbsorbSkill , i ) ) . getMagnitude ( ) ) ;
skill . damage ( effects . get ( EffectKey ( ESM : : MagicEffect : : DamageSkill , i ) ) . getMagnitude ( ) * duration ) ;
skill . damage ( effects . get ( EffectKey ( ESM : : MagicEffect : : DamageSkill , i ) ) . getMagnitude ( ) * duration ) ;
@ -838,7 +849,7 @@ namespace MWMechanics
void Actors : : updateEquippedLight ( const MWWorld : : Ptr & ptr , float duration )
void Actors : : updateEquippedLight ( const MWWorld : : Ptr & ptr , float duration )
{
{
bool isPlayer = ptr . getRefData ( ) . getHandle ( ) = = " player " ;
bool isPlayer = ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) ) ;
MWWorld : : InventoryStore & inventoryStore = ptr . getClass ( ) . getInventoryStore ( ptr ) ;
MWWorld : : InventoryStore & inventoryStore = ptr . getClass ( ) . getInventoryStore ( ptr ) ;
MWWorld : : ContainerStoreIterator heldIter =
MWWorld : : ContainerStoreIterator heldIter =
@ -1147,7 +1158,7 @@ namespace MWMechanics
// 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 . getCellRef ( ) . getRefId ( ) = = " player " )
if ( iter - > first = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
{
{
playerCharacter = iter - > second - > getCharacterController ( ) ;
playerCharacter = iter - > second - > getCharacterController ( ) ;
continue ;
continue ;