@ -5,6 +5,8 @@
# include <OgreSceneNode.h>
# include <openengine/misc/rng.hpp>
# include <components/esm/loadmgef.hpp>
# include <components/esm/loadnpc.hpp>
# include <components/esm/npcstate.hpp>
@ -66,12 +68,12 @@ namespace
double i = floor ( d ) ;
d - = i ;
if ( d < 0.5 )
return i ;
return static_cast < int > ( i ) ;
if ( d > 0.5 )
return i + 1.0 ;
return static_cast < int > ( i ) + 1 ;
if ( is_even ( i ) )
return i ;
return i + 1.0 ;
return static_cast < int > ( i ) ;
return static_cast < int > ( i ) + 1 ;
}
void autoCalculateAttributes ( const ESM : : NPC * npc , MWMechanics : : CreatureStats & creatureStats )
@ -116,7 +118,7 @@ namespace
continue ;
// is this a minor or major skill?
float add = 0.2 ;
float add = 0.2 f ;
for ( int k = 0 ; k < 5 ; + + k )
{
if ( class_ - > mData . mSkills [ k ] [ 0 ] = = j )
@ -149,7 +151,7 @@ namespace
| | class_ - > mData . mAttribute [ 1 ] = = ESM : : Attribute : : Endurance )
multiplier + = 1 ;
creatureStats . setHealth ( static_cast < int > ( 0.5 * ( strength + endurance ) ) + multiplier * ( creatureStats . getLevel ( ) - 1 ) ) ;
creatureStats . setHealth ( floor ( 0.5f * ( strength + endurance ) ) + multiplier * ( creatureStats . getLevel ( ) - 1 ) ) ;
}
/**
@ -279,8 +281,6 @@ namespace MWClass
gmst . fKnockDownMult = store . find ( " fKnockDownMult " ) ;
gmst . iKnockDownOddsMult = store . find ( " iKnockDownOddsMult " ) ;
gmst . iKnockDownOddsBase = store . find ( " iKnockDownOddsBase " ) ;
gmst . fDamageStrengthBase = store . find ( " fDamageStrengthBase " ) ;
gmst . fDamageStrengthMult = store . find ( " fDamageStrengthMult " ) ;
gmst . fCombatArmorMinMult = store . find ( " fCombatArmorMinMult " ) ;
inited = true ;
@ -475,7 +475,6 @@ namespace MWClass
void Npc : : hit ( const MWWorld : : Ptr & ptr , int type ) const
{
MWBase : : World * world = MWBase : : Environment : : get ( ) . getWorld ( ) ;
const GMST & gmst = getGmst ( ) ;
const MWWorld : : Store < ESM : : GameSetting > & store = world - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
@ -507,7 +506,7 @@ namespace MWClass
if ( otherstats . isDead ( ) ) // Can't hit dead actors
return ;
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setEnemy ( victim ) ;
int weapskill = ESM : : Skill : : HandToHand ;
@ -516,7 +515,7 @@ namespace MWClass
float hitchance = MWMechanics : : getHitChance ( ptr , victim , ptr . getClass ( ) . getSkill ( ptr , weapskill ) ) ;
if ( ( : : rand ( ) / ( RAND_MAX + 1.0 ) ) > hitchance / 100.0f )
if ( OEngine : : Misc : : Rng : : rollProbability ( ) > = hitchance / 100.0f )
{
othercls . onHit ( victim , 0.0f , false , weapon , ptr , false ) ;
MWMechanics : : reduceWeaponCondition ( 0.f , false , weapon , ptr ) ;
@ -538,10 +537,8 @@ namespace MWClass
if ( attack )
{
damage = attack [ 0 ] + ( ( attack [ 1 ] - attack [ 0 ] ) * stats . getAttackStrength ( ) ) ;
damage * = gmst . fDamageStrengthBase - > getFloat ( ) +
( stats . getAttribute ( ESM : : Attribute : : Strength ) . getModified ( ) * gmst . fDamageStrengthMult - > getFloat ( ) * 0.1 ) ;
}
MWMechanics : : adjustWeaponDamage ( damage , weapon );
MWMechanics : : adjustWeaponDamage ( damage , weapon , ptr ) ;
MWMechanics : : reduceWeaponCondition ( damage , true , weapon , ptr ) ;
healthdmg = true ;
}
@ -549,7 +546,7 @@ namespace MWClass
{
MWMechanics : : getHandToHandDamage ( ptr , victim , damage , healthdmg ) ;
}
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
{
skillUsageSucceeded ( ptr , weapskill , 0 ) ;
@ -625,7 +622,7 @@ namespace MWClass
if ( ! object . isEmpty ( ) )
getCreatureStats ( ptr ) . setLastHitObject ( object . getClass ( ) . getId ( object ) ) ;
if ( setOnPcHitMe & & ! attacker . isEmpty ( ) & & attacker . getRefData ( ) . getHandle ( ) = = " player " )
if ( setOnPcHitMe & & ! attacker . isEmpty ( ) & & attacker = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
{
const std : : string & script = ptr . getClass ( ) . getScript ( ptr ) ;
/* Set the OnPCHitMe script variable. The script is responsible for clearing it. */
@ -648,8 +645,7 @@ namespace MWClass
const GMST & gmst = getGmst ( ) ;
int chance = store . get < ESM : : GameSetting > ( ) . find ( " iVoiceHitOdds " ) - > getInt ( ) ;
int roll = std : : rand ( ) / ( static_cast < double > ( RAND_MAX ) + 1 ) * 100 ; // [0, 99]
if ( roll < chance )
if ( OEngine : : Misc : : Rng : : roll0to99 ( ) < chance )
{
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > say ( ptr , " hit " ) ;
}
@ -657,9 +653,8 @@ namespace MWClass
// Check for knockdown
float agilityTerm = getCreatureStats ( ptr ) . getAttribute ( ESM : : Attribute : : Agility ) . getModified ( ) * gmst . fKnockDownMult - > getFloat ( ) ;
float knockdownTerm = getCreatureStats ( ptr ) . getAttribute ( ESM : : Attribute : : Agility ) . getModified ( )
* gmst . iKnockDownOddsMult - > getInt ( ) * 0.01 + gmst . iKnockDownOddsBase - > getInt ( ) ;
roll = std : : rand ( ) / ( static_cast < double > ( RAND_MAX ) + 1 ) * 100 ; // [0, 99]
if ( ishealth & & agilityTerm < = damage & & knockdownTerm < = roll )
* gmst . iKnockDownOddsMult - > getInt ( ) * 0.01f + gmst . iKnockDownOddsBase - > getInt ( ) ;
if ( ishealth & & agilityTerm < = damage & & knockdownTerm < = OEngine : : Misc : : Rng : : roll0to99 ( ) )
{
getCreatureStats ( ptr ) . setKnockedDown ( true ) ;
@ -685,12 +680,12 @@ namespace MWClass
MWWorld : : InventoryStore : : Slot_RightPauldron , MWWorld : : InventoryStore : : Slot_RightPauldron ,
MWWorld : : InventoryStore : : Slot_LeftGauntlet , MWWorld : : InventoryStore : : Slot_RightGauntlet
} ;
int hitslot = hitslots [ ( int ) ( : : rand ( ) / ( RAND_MAX + 1.0 ) * 20. 0) ] ;
int hitslot = hitslots [ OEngine : : Misc : : Rng : : rollDice ( 2 0) ] ;
float unmitigatedDamage = damage ;
float x = damage / ( damage + getArmorRating ( ptr ) ) ;
damage * = std : : max ( gmst . fCombatArmorMinMult - > getFloat ( ) , x ) ;
int damageDiff = unmitigatedDamage - damage ;
int damageDiff = static_cast < int > ( unmitigatedDamage - damage ) ;
if ( damage < 1 )
damage = 1 ;
@ -708,7 +703,7 @@ namespace MWClass
if ( armorhealth = = 0 )
armor = * inv . unequipItem ( armor , ptr ) ;
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
skillUsageSucceeded ( ptr , armor . getClass ( ) . getEquipmentSkill ( armor ) , 0 ) ;
switch ( armor . getClass ( ) . getEquipmentSkill ( armor ) )
@ -724,7 +719,7 @@ namespace MWClass
break ;
}
}
else if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
else if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
skillUsageSucceeded ( ptr , ESM : : Skill : : Unarmored , 0 ) ;
}
}
@ -737,7 +732,7 @@ namespace MWClass
if ( damage > 0.0f )
{
sndMgr - > playSound3D ( ptr , " Health Damage " , 1.0f , 1.0f ) ;
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > activateHitOverlay ( ) ;
}
float health = getCreatureStats ( ptr ) . getHealth ( ) . getCurrent ( ) - damage ;
@ -815,7 +810,7 @@ namespace MWClass
const MWWorld : : Ptr & actor ) const
{
// player got activated by another NPC
if ( ptr . getRefData ( ) . getHandle ( ) = = " player " )
if ( ptr = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) )
return boost : : shared_ptr < MWWorld : : Action > ( new MWWorld : : ActionTalk ( actor ) ) ;
// Werewolfs can't activate NPCs
@ -938,7 +933,7 @@ namespace MWClass
gmst . fJumpEncumbranceMultiplier - > getFloat ( ) *
( 1.0f - Npc : : getEncumbrance ( ptr ) / Npc : : getCapacity ( ptr ) ) ;
float a = npcdata - > mNpcStats . getSkill ( ESM : : Skill : : Acrobatics ) . getModified ( ) ;
float a = static_cast < float > ( npcdata - > mNpcStats . getSkill ( ESM : : Skill : : Acrobatics ) . getModified ( ) ) ;
float b = 0.0f ;
if ( a > 50.0f )
{
@ -993,7 +988,7 @@ namespace MWClass
MWWorld : : LiveCellRef < ESM : : NPC > * ref =
ptr . get < ESM : : NPC > ( ) ;
return ref - > mBase - > mFlags & ESM : : NPC : : Essential ;
return ( ref - > mBase - > mFlags & ESM : : NPC : : Essential ) ! = 0 ;
}
void Npc : : registerSelf ( )
@ -1086,7 +1081,6 @@ namespace MWClass
MWMechanics : : NpcStats & stats = getNpcStats ( ptr ) ;
MWWorld : : InventoryStore & invStore = getInventoryStore ( ptr ) ;
int iBaseArmorSkill = store . find ( " iBaseArmorSkill " ) - > getInt ( ) ;
float fUnarmoredBase1 = store . find ( " fUnarmoredBase1 " ) - > getFloat ( ) ;
float fUnarmoredBase2 = store . find ( " fUnarmoredBase2 " ) - > getFloat ( ) ;
int unarmoredSkill = stats . getSkill ( ESM : : Skill : : Unarmored ) . getModified ( ) ;
@ -1098,19 +1092,11 @@ namespace MWClass
if ( it = = invStore . end ( ) | | it - > getTypeName ( ) ! = typeid ( ESM : : Armor ) . name ( ) )
{
// unarmored
ratings [ i ] = ( fUnarmoredBase1 * unarmoredSkill ) * ( fUnarmoredBase2 * unarmoredSkill ) ;
ratings [ i ] = static_cast < int > ( ( fUnarmoredBase1 * unarmoredSkill ) * ( fUnarmoredBase2 * unarmoredSkill ) ) ;
}
else
{
MWWorld : : LiveCellRef < ESM : : Armor > * ref = it - > get < ESM : : Armor > ( ) ;
int armorSkillType = it - > getClass ( ) . getEquipmentSkill ( * it ) ;
int armorSkill = stats . getSkill ( armorSkillType ) . getModified ( ) ;
if ( ref - > mBase - > mData . mWeight = = 0 )
ratings [ i ] = ref - > mBase - > mData . mArmor ;
else
ratings [ i ] = ref - > mBase - > mData . mArmor * armorSkill / iBaseArmorSkill ;
ratings [ i ] = it - > getClass ( ) . getEffectiveArmorRating ( * it , ptr ) ;
}
}