fixing MSVC 2013 warning C4244: & C4305

conversion from 'const float' to 'int', possible loss of data
conversion from 'double' to 'int', possible loss of data
conversion from 'float' to 'int', possible loss of data
celladd
dteviot 10 years ago
parent e6cd8484a2
commit ca8c8c6aa4

@ -150,10 +150,10 @@ void Repair::onRepairItem(MyGUI::Widget *sender)
void Repair::onMouseWheel(MyGUI::Widget* _sender, int _rel) void Repair::onMouseWheel(MyGUI::Widget* _sender, int _rel)
{ {
if (mRepairView->getViewOffset().top + _rel*0.3 > 0) if (mRepairView->getViewOffset().top + _rel*0.3f > 0)
mRepairView->setViewOffset(MyGUI::IntPoint(0, 0)); mRepairView->setViewOffset(MyGUI::IntPoint(0, 0));
else else
mRepairView->setViewOffset(MyGUI::IntPoint(0, mRepairView->getViewOffset().top + _rel*0.3)); mRepairView->setViewOffset(MyGUI::IntPoint(0, static_cast<int>(mRepairView->getViewOffset().top + _rel*0.3f)));
} }
} }

@ -74,9 +74,9 @@ namespace MWMechanics
for (std::vector<ActiveEffect>::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt) for (std::vector<ActiveEffect>::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt)
{ {
int duration = effectIt->mDuration; double duration = effectIt->mDuration;
MWWorld::TimeStamp end = start; MWWorld::TimeStamp end = start;
end += static_cast<double> (duration)* end += duration *
MWBase::Environment::get().getWorld()->getTimeScaleFactor()/(60*60); MWBase::Environment::get().getWorld()->getTimeScaleFactor()/(60*60);
if (end>now) if (end>now)
@ -110,7 +110,7 @@ namespace MWMechanics
{ {
const std::vector<ActiveEffect>& effects = iterator->second.mEffects; const std::vector<ActiveEffect>& effects = iterator->second.mEffects;
int duration = 0; float duration = 0;
for (std::vector<ActiveEffect>::const_iterator iter (effects.begin()); for (std::vector<ActiveEffect>::const_iterator iter (effects.begin());
iter!=effects.end(); ++iter) iter!=effects.end(); ++iter)
@ -216,7 +216,7 @@ namespace MWMechanics
std::string name = it->second.mDisplayName; std::string name = it->second.mDisplayName;
float remainingTime = effectIt->mDuration + float remainingTime = effectIt->mDuration +
(it->second.mTimeStamp - MWBase::Environment::get().getWorld()->getTimeStamp())*3600/timeScale; static_cast<float>(it->second.mTimeStamp - MWBase::Environment::get().getWorld()->getTimeStamp())*3600/timeScale;
float magnitude = effectIt->mMagnitude; float magnitude = effectIt->mMagnitude;
if (magnitude) if (magnitude)
@ -229,7 +229,7 @@ namespace MWMechanics
{ {
for (TContainer::iterator it = mSpells.begin(); it != mSpells.end(); ) for (TContainer::iterator it = mSpells.begin(); it != mSpells.end(); )
{ {
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (roll < chance) if (roll < chance)
mSpells.erase(it++); mSpells.erase(it++);
else else

@ -84,8 +84,8 @@ bool disintegrateSlot (MWWorld::Ptr ptr, int slot, float disintegrate)
// FIXME: charge should be a float, not int so that damage < 1 per frame can be applied. // FIXME: charge should be a float, not int so that damage < 1 per frame can be applied.
// This was also a bug in the original engine. // This was also a bug in the original engine.
charge -= charge -=
std::min(disintegrate, std::min(static_cast<int>(disintegrate),
static_cast<float>(charge)); charge);
item->getCellRef().setCharge(charge); item->getCellRef().setCharge(charge);
if (charge == 0) if (charge == 0)
@ -163,7 +163,7 @@ void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0; bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified (); int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified ();
health = 0.1 * endurance; health = 0.1f * endurance;
magicka = 0; magicka = 0;
if (!stunted) if (!stunted)
@ -203,7 +203,7 @@ namespace MWMechanics
static const float fSoulgemMult = world->getStore().get<ESM::GameSetting>().find("fSoulgemMult")->getFloat(); static const float fSoulgemMult = world->getStore().get<ESM::GameSetting>().find("fSoulgemMult")->getFloat();
float creatureSoulValue = mCreature.get<ESM::Creature>()->mBase->mData.mSoul; int creatureSoulValue = mCreature.get<ESM::Creature>()->mBase->mData.mSoul;
if (creatureSoulValue == 0) if (creatureSoulValue == 0)
return; return;
@ -519,8 +519,8 @@ namespace MWMechanics
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 * 1.5); stat.damage(effects.get(EffectKey(ESM::MagicEffect::DamageAttribute, i)).getMagnitude() * duration * 1.5f);
stat.restore(effects.get(EffectKey(ESM::MagicEffect::RestoreAttribute, i)).getMagnitude() * duration * 1.5); stat.restore(effects.get(EffectKey(ESM::MagicEffect::RestoreAttribute, i)).getMagnitude() * duration * 1.5f);
creatureStats.setAttribute(i, stat); creatureStats.setAttribute(i, stat);
} }
@ -566,19 +566,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(creatureStats.getMagicEffects().get(ESM::MagicEffect::FrenzyHumanoid+creature).getMagnitude() stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::FrenzyHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid+creature).getMagnitude()); - creatureStats.getMagicEffects().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(creatureStats.getMagicEffects().get(ESM::MagicEffect::DemoralizeHumanoid+creature).getMagnitude() stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::DemoralizeHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::RallyHumanoid+creature).getMagnitude()); - creatureStats.getMagicEffects().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(creatureStats.getMagicEffects().get(ESM::MagicEffect::TurnUndead).getMagnitude()); stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::TurnUndead).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); creatureStats.setAiSetting(CreatureStats::AI_Flee, stat);
} }
@ -741,7 +741,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();
int magnitude = creatureStats.getMagicEffects().get(it->first).getMagnitude(); float magnitude = creatureStats.getMagicEffects().get(it->first).getMagnitude();
if (found != (magnitude > 0)) if (found != (magnitude > 0))
{ {
std::string itemGmst = it->second; std::string itemGmst = it->second;
@ -786,8 +786,8 @@ namespace MWMechanics
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 * 1.5); skill.damage(effects.get(EffectKey(ESM::MagicEffect::DamageSkill, i)).getMagnitude() * duration * 1.5f);
skill.restore(effects.get(EffectKey(ESM::MagicEffect::RestoreSkill, i)).getMagnitude() * duration * 1.5); skill.restore(effects.get(EffectKey(ESM::MagicEffect::RestoreSkill, i)).getMagnitude() * duration * 1.5f);
} }
} }
@ -1331,7 +1331,7 @@ namespace MWMechanics
? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour ? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour
: 1.0f; : 1.0f;
int autoHours = std::ceil(std::max(1.f, std::max(healthHours, magickaHours))); int autoHours = static_cast<int>(std::ceil(std::max(1.f, std::max(healthHours, magickaHours))));
return autoHours; return autoHours;
} }

@ -31,12 +31,12 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor, AiState& stat
float x = pos.pos[0] - mLastPos.pos[0]; float x = pos.pos[0] - mLastPos.pos[0];
float y = pos.pos[1] - mLastPos.pos[1]; float y = pos.pos[1] - mLastPos.pos[1];
float z = pos.pos[2] - mLastPos.pos[2]; float z = pos.pos[2] - mLastPos.pos[2];
int distance = x * x + y * y + z * z; float distance = x * x + y * y + z * z;
if(distance < 10 * 10) { //Got stuck, didn't move if(distance < 10 * 10) { //Got stuck, didn't move
if(mAdjAngle == 0) //Try going in various directions if(mAdjAngle == 0) //Try going in various directions
mAdjAngle = 1.57079632679f; //pi/2 mAdjAngle = 1.57079632679f; //pi/2
else if (mAdjAngle == 1.57079632679f) else if (mAdjAngle == 1.57079632679f)
mAdjAngle = -1.57079632679; mAdjAngle = -1.57079632679f;
else else
mAdjAngle = 0; mAdjAngle = 0;
mDuration = 1; //reset timer mDuration = 1; //reset timer

@ -404,7 +404,7 @@ namespace MWMechanics
{ {
const MWWorld::ESMStore &store = world->getStore(); const MWWorld::ESMStore &store = world->getStore();
int chance = store.get<ESM::GameSetting>().find("iVoiceAttackOdds")->getInt(); int chance = store.get<ESM::GameSetting>().find("iVoiceAttackOdds")->getInt();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (roll < chance) if (roll < chance)
{ {
MWBase::Environment::get().getDialogueManager()->say(actor, "attack"); MWBase::Environment::get().getDialogueManager()->say(actor, "attack");
@ -521,7 +521,7 @@ namespace MWMechanics
//apply sideway movement (kind of dodging) with some probability //apply sideway movement (kind of dodging) with some probability
if(static_cast<float>(rand())/RAND_MAX < 0.25) if(static_cast<float>(rand())/RAND_MAX < 0.25)
{ {
movement.mPosition[0] = static_cast<float>(rand())/RAND_MAX < 0.5? 1: -1; movement.mPosition[0] = static_cast<float>(rand())/RAND_MAX < 0.5? 1.0f : -1.0f;
timerCombatMove = 0.05f + 0.15f * static_cast<float>(rand())/RAND_MAX; timerCombatMove = 0.05f + 0.15f * static_cast<float>(rand())/RAND_MAX;
combatMove = true; combatMove = true;
} }
@ -588,7 +588,7 @@ namespace MWMechanics
// get point just before target // get point just before target
std::list<ESM::Pathgrid::Point>::const_iterator pntIter = --mPathFinder.getPath().end(); std::list<ESM::Pathgrid::Point>::const_iterator pntIter = --mPathFinder.getPath().end();
--pntIter; --pntIter;
Ogre::Vector3 vBeforeTarget = Ogre::Vector3(pntIter->mX, pntIter->mY, pntIter->mZ); Ogre::Vector3 vBeforeTarget(PathFinder::MakeOgreVector3(*pntIter));
// if current actor pos is closer to target then last point of path (excluding target itself) then go straight on target // if current actor pos is closer to target then last point of path (excluding target itself) then go straight on target
if(distToTarget <= (vTargetPos - vBeforeTarget).length()) if(distToTarget <= (vTargetPos - vBeforeTarget).length())
@ -685,27 +685,21 @@ namespace MWMechanics
if(!mPathFinder.getPath().empty()) if(!mPathFinder.getPath().empty())
{ {
ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back();
Ogre::Vector3 currPathTarget(lastPt.mX, lastPt.mY, lastPt.mZ); Ogre::Vector3 currPathTarget(PathFinder::MakeOgreVector3(lastPt));
dist = (newPathTarget - currPathTarget).length(); dist = (newPathTarget - currPathTarget).length();
} }
else dist = 1e+38F; // necessarily construct a new path else dist = 1e+38F; // necessarily construct a new path
float targetPosThreshold = (actor.getCell()->getCell()->isExterior())? 300 : 100; float targetPosThreshold = (actor.getCell()->getCell()->isExterior())? 300.0f : 100.0f;
//construct new path only if target has moved away more than on [targetPosThreshold] //construct new path only if target has moved away more than on [targetPosThreshold]
if(dist > targetPosThreshold) if(dist > targetPosThreshold)
{ {
ESM::Position pos = actor.getRefData().getPosition(); ESM::Position pos = actor.getRefData().getPosition();
ESM::Pathgrid::Point start; ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
start.mX = pos.pos[0];
start.mY = pos.pos[1];
start.mZ = pos.pos[2];
ESM::Pathgrid::Point dest; ESM::Pathgrid::Point dest(PathFinder::MakePathgridPoint(newPathTarget));
dest.mX = newPathTarget.x;
dest.mY = newPathTarget.y;
dest.mZ = newPathTarget.z;
if(!mPathFinder.isPathConstructed()) if(!mPathFinder.isPathConstructed())
mPathFinder.buildPath(start, dest, actor.getCell(), false); mPathFinder.buildPath(start, dest, actor.getCell(), false);
@ -770,7 +764,7 @@ ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics:
float roll = static_cast<float>(rand())/RAND_MAX; float roll = static_cast<float>(rand())/RAND_MAX;
if(roll <= 0.333f) //side punch if(roll <= 0.333f) //side punch
{ {
movement.mPosition[0] = (static_cast<float>(rand())/RAND_MAX < 0.5f)? 1: -1; movement.mPosition[0] = (static_cast<float>(rand())/RAND_MAX < 0.5f)? 1.0f : -1.0f;
movement.mPosition[1] = 0; movement.mPosition[1] = 0;
attackType = ESM::Weapon::AT_Slash; attackType = ESM::Weapon::AT_Slash;
} }
@ -792,16 +786,16 @@ ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics:
int chop = (weapon->mData.mChop[0] + weapon->mData.mChop[1])/2; int chop = (weapon->mData.mChop[0] + weapon->mData.mChop[1])/2;
int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2; int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2;
float total = slash + chop + thrust; float total = static_cast<float>(slash + chop + thrust);
float roll = static_cast<float>(rand())/RAND_MAX; float roll = static_cast<float>(rand())/RAND_MAX;
if(roll <= static_cast<float>(slash)/total) if(roll <= (slash/total))
{ {
movement.mPosition[0] = (static_cast<float>(rand())/RAND_MAX < 0.5f)? 1: -1; movement.mPosition[0] = (static_cast<float>(rand())/RAND_MAX < 0.5f)? 1.0f : -1.0f;
movement.mPosition[1] = 0; movement.mPosition[1] = 0;
attackType = ESM::Weapon::AT_Slash; attackType = ESM::Weapon::AT_Slash;
} }
else if(roll <= (static_cast<float>(slash) + static_cast<float>(thrust))/total) else if(roll <= (slash + (thrust/total)))
{ {
movement.mPosition[1] = 1; movement.mPosition[1] = 1;
attackType = ESM::Weapon::AT_Thrust; attackType = ESM::Weapon::AT_Thrust;

@ -323,14 +323,14 @@ namespace MWMechanics
if (effect.mAttribute >= 0 && effect.mAttribute < ESM::Attribute::Length) if (effect.mAttribute >= 0 && effect.mAttribute < ESM::Attribute::Length)
{ {
const float attributePriorities[ESM::Attribute::Length] = { const float attributePriorities[ESM::Attribute::Length] = {
1.f, // Strength 1.0f, // Strength
0.5, // Intelligence 0.5f, // Intelligence
0.6, // Willpower 0.6f, // Willpower
0.7, // Agility 0.7f, // Agility
0.5, // Speed 0.5f, // Speed
0.8, // Endurance 0.8f, // Endurance
0.7, // Personality 0.7f, // Personality
0.3 // Luck 0.3f // Luck
}; };
rating *= attributePriorities[effect.mAttribute]; rating *= attributePriorities[effect.mAttribute];
} }

@ -23,7 +23,7 @@
namespace MWMechanics namespace MWMechanics
{ {
AiEscort::AiEscort(const std::string &actorId, int duration, float x, float y, float z) AiEscort::AiEscort(const std::string &actorId, int duration, float x, float y, float z)
: mActorId(actorId), mX(x), mY(y), mZ(z), mRemainingDuration(duration) : mActorId(actorId), mX(x), mY(y), mZ(z), mRemainingDuration(static_cast<float>(duration))
, mCellX(std::numeric_limits<int>::max()) , mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max()) , mCellY(std::numeric_limits<int>::max())
{ {
@ -36,7 +36,7 @@ namespace MWMechanics
} }
AiEscort::AiEscort(const std::string &actorId, const std::string &cellId,int duration, float x, float y, float z) AiEscort::AiEscort(const std::string &actorId, const std::string &cellId,int duration, float x, float y, float z)
: mActorId(actorId), mCellId(cellId), mX(x), mY(y), mZ(z), mRemainingDuration(duration) : mActorId(actorId), mCellId(cellId), mX(x), mY(y), mZ(z), mRemainingDuration(static_cast<float>(duration))
, mCellX(std::numeric_limits<int>::max()) , mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max()) , mCellY(std::numeric_limits<int>::max())
{ {
@ -86,13 +86,13 @@ namespace MWMechanics
for (short counter = 0; counter < 3; counter++) for (short counter = 0; counter < 3; counter++)
differenceBetween[counter] = (leaderPos[counter] - followerPos[counter]); differenceBetween[counter] = (leaderPos[counter] - followerPos[counter]);
float distanceBetweenResult = double distanceBetweenResult =
(differenceBetween[0] * differenceBetween[0]) + (differenceBetween[1] * differenceBetween[1]) + (differenceBetween[2] * (differenceBetween[0] * differenceBetween[0]) + (differenceBetween[1] * differenceBetween[1]) + (differenceBetween[2] *
differenceBetween[2]); differenceBetween[2]);
if(distanceBetweenResult <= mMaxDist * mMaxDist) if(distanceBetweenResult <= mMaxDist * mMaxDist)
{ {
ESM::Pathgrid::Point point(mX,mY,mZ); ESM::Pathgrid::Point point(static_cast<int>(mX), static_cast<int>(mY), static_cast<int>(mZ));
point.mAutogenerated = 0; point.mAutogenerated = 0;
point.mConnectionNum = 0; point.mConnectionNum = 0;
point.mUnknown = 0; point.mUnknown = 0;

@ -16,7 +16,7 @@
MWMechanics::AiPackage::~AiPackage() {} MWMechanics::AiPackage::~AiPackage() {}
MWMechanics::AiPackage::AiPackage() : mTimer(.26), mStuckTimer(0) { //mTimer starts at .26 to force initial pathbuild MWMechanics::AiPackage::AiPackage() : mTimer(0.26f), mStuckTimer(0) { //mTimer starts at .26 to force initial pathbuild
} }

@ -93,15 +93,9 @@ namespace MWMechanics
mCellX = cell->mData.mX; mCellX = cell->mData.mX;
mCellY = cell->mData.mY; mCellY = cell->mData.mY;
ESM::Pathgrid::Point dest; ESM::Pathgrid::Point dest(static_cast<int>(mX), static_cast<int>(mY), static_cast<int>(mZ));
dest.mX = mX;
dest.mY = mY; ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
dest.mZ = mZ;
ESM::Pathgrid::Point start;
start.mX = pos.pos[0];
start.mY = pos.pos[1];
start.mZ = pos.pos[2];
mPathFinder.buildPath(start, dest, actor.getCell(), true); mPathFinder.buildPath(start, dest, actor.getCell(), true);
} }

@ -192,7 +192,7 @@ namespace MWMechanics
if(mDistance && // actor is not intended to be stationary if(mDistance && // actor is not intended to be stationary
idleNow && // but is in idle idleNow && // but is in idle
!walking && // FIXME: some actors are idle while walking !walking && // FIXME: some actors are idle while walking
proximityToDoor(actor, MIN_DIST_TO_DOOR_SQUARED*1.6*1.6)) // NOTE: checks interior cells only proximityToDoor(actor, MIN_DIST_TO_DOOR_SQUARED*1.6f*1.6f)) // NOTE: checks interior cells only
{ {
idleNow = false; idleNow = false;
moveNow = true; moveNow = true;
@ -315,13 +315,13 @@ namespace MWMechanics
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();
float roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 10000; float roll = std::rand()/ (static_cast<float> (RAND_MAX) + 1) * 10000;
// In vanilla MW the chance was FPS dependent, and did not allow proper changing of fVoiceIdleOdds // In vanilla MW the chance was FPS dependent, and did not allow proper changing of fVoiceIdleOdds
// due to the roll being an integer. // due to the roll being an integer.
// Our implementation does not have these issues, so needs to be recalibrated. We chose to // Our implementation does not have these issues, so needs to be recalibrated. We chose to
// use the chance MW would have when run at 60 FPS with the default value of the GMST for calibration. // use the chance MW would have when run at 60 FPS with the default value of the GMST for calibration.
float x = fVoiceIdleOdds * 0.6 * (MWBase::Environment::get().getFrameDuration() / 0.1); float x = fVoiceIdleOdds * 0.6f * (MWBase::Environment::get().getFrameDuration() / 0.1f);
// Only say Idle voices when player is in LOS // Only say Idle voices when player is in LOS
// A bit counterintuitive, likely vanilla did this to reduce the appearance of // A bit counterintuitive, likely vanilla did this to reduce the appearance of
@ -393,18 +393,10 @@ namespace MWMechanics
if (!storage.mPathFinder.isPathConstructed()) if (!storage.mPathFinder.isPathConstructed())
{ {
Ogre::Vector3 destNodePos = mReturnPosition; ESM::Pathgrid::Point dest(PathFinder::MakePathgridPoint(mReturnPosition));
ESM::Pathgrid::Point dest;
dest.mX = destNodePos[0];
dest.mY = destNodePos[1];
dest.mZ = destNodePos[2];
// actor position is already in world co-ordinates // actor position is already in world co-ordinates
ESM::Pathgrid::Point start; ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
start.mX = pos.pos[0];
start.mY = pos.pos[1];
start.mZ = pos.pos[2];
// don't take shortcuts for wandering // don't take shortcuts for wandering
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false); storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
@ -422,7 +414,7 @@ namespace MWMechanics
{ {
// Play a random voice greeting if the player gets too close // Play a random voice greeting if the player gets too close
int hello = cStats.getAiSetting(CreatureStats::AI_Hello).getModified(); int hello = cStats.getAiSetting(CreatureStats::AI_Hello).getModified();
float helloDistance = hello; float helloDistance = static_cast<float>(hello);
static int iGreetDistanceMultiplier =MWBase::Environment::get().getWorld()->getStore() static int iGreetDistanceMultiplier =MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt(); .get<ESM::GameSetting>().find("iGreetDistanceMultiplier")->getInt();
@ -500,15 +492,10 @@ namespace MWMechanics
assert(mAllowedNodes.size()); assert(mAllowedNodes.size());
unsigned int randNode = (int)(rand() / ((double)RAND_MAX + 1) * mAllowedNodes.size()); unsigned int randNode = (int)(rand() / ((double)RAND_MAX + 1) * mAllowedNodes.size());
// NOTE: initially constructed with local (i.e. cell) co-ordinates // NOTE: initially constructed with local (i.e. cell) co-ordinates
Ogre::Vector3 destNodePos(mAllowedNodes[randNode].mX, Ogre::Vector3 destNodePos(PathFinder::MakeOgreVector3(mAllowedNodes[randNode]));
mAllowedNodes[randNode].mY,
mAllowedNodes[randNode].mZ);
// convert dest to use world co-ordinates // convert dest to use world co-ordinates
ESM::Pathgrid::Point dest; ESM::Pathgrid::Point dest(PathFinder::MakePathgridPoint(destNodePos));
dest.mX = destNodePos[0];
dest.mY = destNodePos[1];
dest.mZ = destNodePos[2];
if (currentCell->getCell()->isExterior()) if (currentCell->getCell()->isExterior())
{ {
dest.mX += currentCell->getCell()->mData.mX * ESM::Land::REAL_SIZE; dest.mX += currentCell->getCell()->mData.mX * ESM::Land::REAL_SIZE;
@ -516,10 +503,7 @@ namespace MWMechanics
} }
// actor position is already in world co-ordinates // actor position is already in world co-ordinates
ESM::Pathgrid::Point start; ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
start.mX = pos.pos[0];
start.mY = pos.pos[1];
start.mZ = pos.pos[2];
// don't take shortcuts for wandering // don't take shortcuts for wandering
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false); storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
@ -652,7 +636,7 @@ namespace MWMechanics
static float fIdleChanceMultiplier = MWBase::Environment::get().getWorld()->getStore() static float fIdleChanceMultiplier = MWBase::Environment::get().getWorld()->getStore()
.get<ESM::GameSetting>().find("fIdleChanceMultiplier")->getFloat(); .get<ESM::GameSetting>().find("fIdleChanceMultiplier")->getFloat();
unsigned short idleChance = fIdleChanceMultiplier * mIdle[counter]; unsigned short idleChance = static_cast<unsigned short>(fIdleChanceMultiplier * mIdle[counter]);
unsigned short randSelect = (int)(rand() / ((double)RAND_MAX + 1) * int(100 / fIdleChanceMultiplier)); unsigned short randSelect = (int)(rand() / ((double)RAND_MAX + 1) * int(100 / fIdleChanceMultiplier));
if(randSelect < idleChance && randSelect > idleRoll) if(randSelect < idleChance && randSelect > idleRoll)
{ {
@ -675,12 +659,12 @@ namespace MWMechanics
state.moveIn(new AiWanderStorage()); state.moveIn(new AiWanderStorage());
int index = std::rand() / (static_cast<double> (RAND_MAX) + 1) * mAllowedNodes.size(); int index = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * mAllowedNodes.size());
ESM::Pathgrid::Point dest = mAllowedNodes[index]; ESM::Pathgrid::Point dest = mAllowedNodes[index];
// apply a slight offset to prevent overcrowding // apply a slight offset to prevent overcrowding
dest.mX += Ogre::Math::RangeRandom(-64, 64); dest.mX += static_cast<int>(Ogre::Math::RangeRandom(-64, 64));
dest.mY += Ogre::Math::RangeRandom(-64, 64); dest.mY += static_cast<int>(Ogre::Math::RangeRandom(-64, 64));
if (actor.getCell()->isExterior()) if (actor.getCell()->isExterior())
{ {
@ -688,7 +672,8 @@ namespace MWMechanics
dest.mY += actor.getCell()->getCell()->mData.mY * ESM::Land::REAL_SIZE; dest.mY += actor.getCell()->getCell()->mData.mY * ESM::Land::REAL_SIZE;
} }
MWBase::Environment::get().getWorld()->moveObject(actor, dest.mX, dest.mY, dest.mZ); MWBase::Environment::get().getWorld()->moveObject(actor, static_cast<float>(dest.mX),
static_cast<float>(dest.mY), static_cast<float>(dest.mZ));
actor.getClass().adjustPosition(actor, false); actor.getClass().adjustPosition(actor, false);
} }
@ -720,8 +705,8 @@ namespace MWMechanics
float cellYOffset = 0; float cellYOffset = 0;
if(cell->isExterior()) if(cell->isExterior())
{ {
cellXOffset = cell->mData.mX * ESM::Land::REAL_SIZE; cellXOffset = static_cast<float>(cell->mData.mX * ESM::Land::REAL_SIZE);
cellYOffset = cell->mData.mY * ESM::Land::REAL_SIZE; cellYOffset = static_cast<float>(cell->mData.mY * ESM::Land::REAL_SIZE);
} }
// convert npcPos to local (i.e. cell) co-ordinates // convert npcPos to local (i.e. cell) co-ordinates
@ -733,20 +718,18 @@ namespace MWMechanics
// NOTE: mPoints and mAllowedNodes are in local co-ordinates // NOTE: mPoints and mAllowedNodes are in local co-ordinates
for(unsigned int counter = 0; counter < pathgrid->mPoints.size(); counter++) for(unsigned int counter = 0; counter < pathgrid->mPoints.size(); counter++)
{ {
Ogre::Vector3 nodePos(pathgrid->mPoints[counter].mX, pathgrid->mPoints[counter].mY, Ogre::Vector3 nodePos(PathFinder::MakeOgreVector3(pathgrid->mPoints[counter]));
pathgrid->mPoints[counter].mZ);
if(npcPos.squaredDistance(nodePos) <= mDistance * mDistance) if(npcPos.squaredDistance(nodePos) <= mDistance * mDistance)
mAllowedNodes.push_back(pathgrid->mPoints[counter]); mAllowedNodes.push_back(pathgrid->mPoints[counter]);
} }
if(!mAllowedNodes.empty()) if(!mAllowedNodes.empty())
{ {
Ogre::Vector3 firstNodePos(mAllowedNodes[0].mX, mAllowedNodes[0].mY, mAllowedNodes[0].mZ); Ogre::Vector3 firstNodePos(PathFinder::MakeOgreVector3(mAllowedNodes[0]));
float closestNode = npcPos.squaredDistance(firstNodePos); float closestNode = npcPos.squaredDistance(firstNodePos);
unsigned int index = 0; unsigned int index = 0;
for(unsigned int counterThree = 1; counterThree < mAllowedNodes.size(); counterThree++) for(unsigned int counterThree = 1; counterThree < mAllowedNodes.size(); counterThree++)
{ {
Ogre::Vector3 nodePos(mAllowedNodes[counterThree].mX, mAllowedNodes[counterThree].mY, Ogre::Vector3 nodePos(PathFinder::MakeOgreVector3(mAllowedNodes[counterThree]));
mAllowedNodes[counterThree].mZ);
float tempDist = npcPos.squaredDistance(nodePos); float tempDist = npcPos.squaredDistance(nodePos);
if(tempDist < closestNode) if(tempDist < closestNode)
index = counterThree; index = counterThree;

@ -94,17 +94,17 @@ void MWMechanics::Alchemy::applyTools (int flags, float& value) const
quality = negative ? 2 * toolQuality + 3 * calcinatorQuality : quality = negative ? 2 * toolQuality + 3 * calcinatorQuality :
(magnitude && duration ? (magnitude && duration ?
2 * toolQuality + calcinatorQuality : 2/3.0 * (toolQuality + calcinatorQuality) + 0.5); 2 * toolQuality + calcinatorQuality : 2/3.0f * (toolQuality + calcinatorQuality) + 0.5f);
break; break;
case 2: case 2:
quality = negative ? 1+toolQuality : (magnitude && duration ? toolQuality : toolQuality + 0.5); quality = negative ? 1+toolQuality : (magnitude && duration ? toolQuality : toolQuality + 0.5f);
break; break;
case 3: case 3:
quality = magnitude && duration ? calcinatorQuality : calcinatorQuality + 0.5; quality = magnitude && duration ? calcinatorQuality : calcinatorQuality + 0.5f;
break; break;
} }
@ -178,8 +178,8 @@ void MWMechanics::Alchemy::updateEffects()
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration)) if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration))
applyTools (magicEffect->mData.mFlags, duration); applyTools (magicEffect->mData.mFlags, duration);
duration = static_cast<int> (duration+0.5); duration = roundf(duration);
magnitude = static_cast<int> (magnitude+0.5); magnitude = roundf(magnitude);
if (magnitude>0 && duration>0) if (magnitude>0 && duration>0)
{ {
@ -197,8 +197,8 @@ void MWMechanics::Alchemy::updateEffects()
effect.mRange = 0; effect.mRange = 0;
effect.mArea = 0; effect.mArea = 0;
effect.mDuration = duration; effect.mDuration = static_cast<int>(duration);
effect.mMagnMin = effect.mMagnMax = magnitude; effect.mMagnMin = effect.mMagnMax = static_cast<int>(magnitude);
mEffects.push_back (effect); mEffects.push_back (effect);
} }
@ -323,8 +323,8 @@ float MWMechanics::Alchemy::getAlchemyFactor() const
return return
(npcStats.getSkill (ESM::Skill::Alchemy).getModified() + (npcStats.getSkill (ESM::Skill::Alchemy).getModified() +
0.1 * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified() 0.1f * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified()
+ 0.1 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified()); + 0.1f * creatureStats.getAttribute (ESM::Attribute::Luck).getModified());
} }
int MWMechanics::Alchemy::countIngredients() const int MWMechanics::Alchemy::countIngredients() const

@ -187,7 +187,7 @@ namespace MWMechanics
for (std::vector<ESM::ENAMstruct>::const_iterator it = effects.mList.begin(); it != effects.mList.end(); ++it) for (std::vector<ESM::ENAMstruct>::const_iterator it = effects.mList.begin(); it != effects.mList.end(); ++it)
{ {
const ESM::ENAMstruct& effect = *it; const ESM::ENAMstruct& effect = *it;
float x = effect.mDuration; float x = static_cast<float>(effect.mDuration);
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectID); const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectID);
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) if (!(magicEffect->mData.mFlags & ESM::MagicEffect::UncappedDamage))

@ -112,7 +112,7 @@ float getFallDamage(const MWWorld::Ptr& ptr, float fallHeight)
if (fallHeight >= fallDistanceMin) if (fallHeight >= fallDistanceMin)
{ {
const float acrobaticsSkill = ptr.getClass().getSkill(ptr, ESM::Skill::Acrobatics); const float acrobaticsSkill = static_cast<float>(ptr.getClass().getSkill(ptr, ESM::Skill::Acrobatics));
const float jumpSpellBonus = ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Jump).getMagnitude(); const float jumpSpellBonus = ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Jump).getMagnitude();
const float fallAcroBase = store.find("fFallAcroBase")->getFloat(); const float fallAcroBase = store.find("fFallAcroBase")->getFloat();
const float fallAcroMult = store.find("fFallAcroMult")->getFloat(); const float fallAcroMult = store.find("fFallAcroMult")->getFloat();
@ -120,7 +120,7 @@ float getFallDamage(const MWWorld::Ptr& ptr, float fallHeight)
const float fallDistanceMult = store.find("fFallDistanceMult")->getFloat(); const float fallDistanceMult = store.find("fFallDistanceMult")->getFloat();
float x = fallHeight - fallDistanceMin; float x = fallHeight - fallDistanceMin;
x -= (1.5 * acrobaticsSkill) + jumpSpellBonus; x -= (1.5f * acrobaticsSkill) + jumpSpellBonus;
x = std::max(0.0f, x); x = std::max(0.0f, x);
float a = fallAcroBase + fallAcroMult * (100 - acrobaticsSkill); float a = fallAcroBase + fallAcroMult * (100 - acrobaticsSkill);
@ -220,7 +220,7 @@ std::string CharacterController::chooseRandomGroup (const std::string& prefix, i
while (mAnimation->hasAnimation(prefix + Ogre::StringConverter::toString(numAnims+1))) while (mAnimation->hasAnimation(prefix + Ogre::StringConverter::toString(numAnims+1)))
++numAnims; ++numAnims;
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * numAnims + 1; // [1, numAnims] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * numAnims) + 1; // [1, numAnims]
if (num) if (num)
*num = roll; *num = roll;
return prefix + Ogre::StringConverter::toString(roll); return prefix + Ogre::StringConverter::toString(roll);
@ -829,7 +829,7 @@ bool CharacterController::updateCreatureState()
} }
if (weapType != WeapType_Spell || !mAnimation->hasAnimation("spellcast")) // Not all creatures have a dedicated spellcast animation if (weapType != WeapType_Spell || !mAnimation->hasAnimation("spellcast")) // Not all creatures have a dedicated spellcast animation
{ {
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 3; // [0, 2] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 3); // [0, 2]
if (roll == 0) if (roll == 0)
mCurrentWeapon = "attack1"; mCurrentWeapon = "attack1";
else if (roll == 1) else if (roll == 1)
@ -1531,7 +1531,7 @@ void CharacterController::update(float duration)
float normalizedEncumbrance = mPtr.getClass().getNormalizedEncumbrance(mPtr); float normalizedEncumbrance = mPtr.getClass().getNormalizedEncumbrance(mPtr);
if (normalizedEncumbrance > 1) if (normalizedEncumbrance > 1)
normalizedEncumbrance = 1; normalizedEncumbrance = 1;
const int fatigueDecrease = fatigueJumpBase + (1 - normalizedEncumbrance) * fatigueJumpMult; const float fatigueDecrease = fatigueJumpBase + (1 - normalizedEncumbrance) * fatigueJumpMult;
DynamicStat<float> fatigue = cls.getCreatureStats(mPtr).getFatigue(); DynamicStat<float> fatigue = cls.getCreatureStats(mPtr).getFatigue();
fatigue.setCurrent(fatigue.getCurrent() - fatigueDecrease); fatigue.setCurrent(fatigue.getCurrent() - fatigueDecrease);
cls.getCreatureStats(mPtr).setFatigue(fatigue); cls.getCreatureStats(mPtr).setFatigue(fatigue);
@ -1551,12 +1551,12 @@ void CharacterController::update(float duration)
// inflict fall damages // inflict fall damages
DynamicStat<float> health = cls.getCreatureStats(mPtr).getHealth(); DynamicStat<float> health = cls.getCreatureStats(mPtr).getHealth();
int realHealthLost = healthLost * (1.0f - 0.25 * fatigueTerm); float realHealthLost = static_cast<float>(healthLost * (1.0f - 0.25f * fatigueTerm));
health.setCurrent(health.getCurrent() - realHealthLost); health.setCurrent(health.getCurrent() - realHealthLost);
cls.getCreatureStats(mPtr).setHealth(health); cls.getCreatureStats(mPtr).setHealth(health);
cls.onHit(mPtr, realHealthLost, true, MWWorld::Ptr(), MWWorld::Ptr(), true); cls.onHit(mPtr, realHealthLost, true, MWWorld::Ptr(), MWWorld::Ptr(), true);
const float acrobaticsSkill = cls.getSkill(mPtr, ESM::Skill::Acrobatics); const int acrobaticsSkill = cls.getSkill(mPtr, ESM::Skill::Acrobatics);
if (healthLost > (acrobaticsSkill * fatigueTerm)) if (healthLost > (acrobaticsSkill * fatigueTerm))
{ {
cls.getCreatureStats(mPtr).setKnockedDown(true); cls.getCreatureStats(mPtr).setKnockedDown(true);
@ -1612,7 +1612,7 @@ void CharacterController::update(float duration)
mTurnAnimationThreshold -= duration; mTurnAnimationThreshold -= duration;
if (movestate == CharState_TurnRight || movestate == CharState_TurnLeft) if (movestate == CharState_TurnRight || movestate == CharState_TurnLeft)
mTurnAnimationThreshold = 0.05; mTurnAnimationThreshold = 0.05f;
else if (movestate == CharState_None && (mMovementState == CharState_TurnRight || mMovementState == CharState_TurnLeft) else if (movestate == CharState_None && (mMovementState == CharState_TurnRight || mMovementState == CharState_TurnLeft)
&& mTurnAnimationThreshold > 0) && mTurnAnimationThreshold > 0)
{ {

@ -83,8 +83,8 @@ namespace MWMechanics
MWMechanics::CreatureStats& attackerStats = attacker.getClass().getCreatureStats(attacker); MWMechanics::CreatureStats& attackerStats = attacker.getClass().getCreatureStats(attacker);
float blockTerm = blocker.getClass().getSkill(blocker, ESM::Skill::Block) + 0.2 * blockerStats.getAttribute(ESM::Attribute::Agility).getModified() float blockTerm = blocker.getClass().getSkill(blocker, ESM::Skill::Block) + 0.2f * blockerStats.getAttribute(ESM::Attribute::Agility).getModified()
+ 0.1 * blockerStats.getAttribute(ESM::Attribute::Luck).getModified(); + 0.1f * blockerStats.getAttribute(ESM::Attribute::Luck).getModified();
float enemySwing = attackerStats.getAttackStrength(); float enemySwing = attackerStats.getAttackStrength();
float swingTerm = enemySwing * gmst.find("fSwingBlockMult")->getFloat() + gmst.find("fSwingBlockBase")->getFloat(); float swingTerm = enemySwing * gmst.find("fSwingBlockMult")->getFloat() + gmst.find("fSwingBlockBase")->getFloat();
@ -93,13 +93,13 @@ namespace MWMechanics
blockerTerm *= gmst.find("fBlockStillBonus")->getFloat(); blockerTerm *= gmst.find("fBlockStillBonus")->getFloat();
blockerTerm *= blockerStats.getFatigueTerm(); blockerTerm *= blockerStats.getFatigueTerm();
float attackerSkill = 0.f; int attackerSkill = 0;
if (weapon.isEmpty()) if (weapon.isEmpty())
attackerSkill = attacker.getClass().getSkill(attacker, ESM::Skill::HandToHand); attackerSkill = attacker.getClass().getSkill(attacker, ESM::Skill::HandToHand);
else else
attackerSkill = attacker.getClass().getSkill(attacker, weapon.getClass().getEquipmentSkill(weapon)); attackerSkill = attacker.getClass().getSkill(attacker, weapon.getClass().getEquipmentSkill(weapon));
float attackerTerm = attackerSkill + 0.2 * attackerStats.getAttribute(ESM::Attribute::Agility).getModified() float attackerTerm = attackerSkill + 0.2f * attackerStats.getAttribute(ESM::Attribute::Agility).getModified()
+ 0.1 * attackerStats.getAttribute(ESM::Attribute::Luck).getModified(); + 0.1f * attackerStats.getAttribute(ESM::Attribute::Luck).getModified();
attackerTerm *= attackerStats.getFatigueTerm(); attackerTerm *= attackerStats.getFatigueTerm();
int x = int(blockerTerm - attackerTerm); int x = int(blockerTerm - attackerTerm);
@ -107,7 +107,7 @@ namespace MWMechanics
int iBlockMinChance = gmst.find("iBlockMinChance")->getInt(); int iBlockMinChance = gmst.find("iBlockMinChance")->getInt();
x = std::min(iBlockMaxChance, std::max(iBlockMinChance, x)); x = std::min(iBlockMaxChance, std::max(iBlockMinChance, x));
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (roll < x) if (roll < x)
{ {
// Reduce shield durability by incoming damage // Reduce shield durability by incoming damage
@ -183,7 +183,7 @@ namespace MWMechanics
if(!weapon.isEmpty()) if(!weapon.isEmpty())
weapskill = weapon.getClass().getEquipmentSkill(weapon); weapskill = weapon.getClass().getEquipmentSkill(weapon);
float skillValue = attacker.getClass().getSkill(attacker, int skillValue = attacker.getClass().getSkill(attacker,
weapon.getClass().getEquipmentSkill(weapon)); weapon.getClass().getEquipmentSkill(weapon));
if((::rand()/(RAND_MAX+1.0)) > getHitChance(attacker, victim, skillValue)/100.0f) if((::rand()/(RAND_MAX+1.0)) > getHitChance(attacker, victim, skillValue)/100.0f)
@ -206,7 +206,7 @@ namespace MWMechanics
} }
damage *= fDamageStrengthBase + damage *= fDamageStrengthBase +
(attackerStats.getAttribute(ESM::Attribute::Strength).getModified() * fDamageStrengthMult * 0.1); (attackerStats.getAttribute(ESM::Attribute::Strength).getModified() * fDamageStrengthMult * 0.1f);
adjustWeaponDamage(damage, weapon); adjustWeaponDamage(damage, weapon);
reduceWeaponCondition(damage, true, weapon, attacker); reduceWeaponCondition(damage, true, weapon, attacker);
@ -265,14 +265,14 @@ namespace MWMechanics
+ 0.2f * attackerStats.getAttribute(ESM::Attribute::Willpower).getModified() + 0.2f * attackerStats.getAttribute(ESM::Attribute::Willpower).getModified()
+ 0.1f * attackerStats.getAttribute(ESM::Attribute::Luck).getModified(); + 0.1f * attackerStats.getAttribute(ESM::Attribute::Luck).getModified();
int fatigueMax = attackerStats.getFatigue().getModified(); float fatigueMax = attackerStats.getFatigue().getModified();
int fatigueCurrent = attackerStats.getFatigue().getCurrent(); float fatigueCurrent = attackerStats.getFatigue().getCurrent();
float normalisedFatigue = fatigueMax==0 ? 1 : std::max (0.0f, static_cast<float> (fatigueCurrent)/fatigueMax); float normalisedFatigue = floor(fatigueMax)==0 ? 1 : std::max (0.0f, (fatigueCurrent/fatigueMax));
saveTerm *= 1.25f * normalisedFatigue; saveTerm *= 1.25f * normalisedFatigue;
float roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] float roll = std::rand()/ (static_cast<float> (RAND_MAX) + 1) * 100; // [0, 99]
float x = std::max(0.f, saveTerm - roll); float x = std::max(0.f, saveTerm - roll);
int element = ESM::MagicEffect::FireDamage; int element = ESM::MagicEffect::FireDamage;
@ -344,7 +344,7 @@ namespace MWMechanics
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
float minstrike = store.get<ESM::GameSetting>().find("fMinHandToHandMult")->getFloat(); float minstrike = store.get<ESM::GameSetting>().find("fMinHandToHandMult")->getFloat();
float maxstrike = store.get<ESM::GameSetting>().find("fMaxHandToHandMult")->getFloat(); float maxstrike = store.get<ESM::GameSetting>().find("fMaxHandToHandMult")->getFloat();
damage = attacker.getClass().getSkill(attacker, ESM::Skill::HandToHand); damage = static_cast<float>(attacker.getClass().getSkill(attacker, ESM::Skill::HandToHand));
damage *= minstrike + ((maxstrike-minstrike)*attacker.getClass().getCreatureStats(attacker).getAttackStrength()); damage *= minstrike + ((maxstrike-minstrike)*attacker.getClass().getCreatureStats(attacker).getAttackStrength());
MWMechanics::CreatureStats& otherstats = victim.getClass().getCreatureStats(victim); MWMechanics::CreatureStats& otherstats = victim.getClass().getCreatureStats(victim);

@ -42,10 +42,10 @@ namespace MWMechanics
float CreatureStats::getFatigueTerm() const float CreatureStats::getFatigueTerm() const
{ {
int max = getFatigue().getModified(); float max = getFatigue().getModified();
int current = getFatigue().getCurrent(); float current = getFatigue().getCurrent();
float normalised = max==0 ? 1 : std::max (0.0f, static_cast<float> (current)/max); float normalised = floor(max) == 0 ? 1 : std::max (0.0f, current / max);
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();

@ -176,7 +176,7 @@ namespace MWMechanics
int magMax = (it->mMagnMax == 0) ? 1 : it->mMagnMax; int magMax = (it->mMagnMax == 0) ? 1 : it->mMagnMax;
int area = (it->mArea == 0) ? 1 : it->mArea; int area = (it->mArea == 0) ? 1 : it->mArea;
float magnitudeCost = (magMin + magMax) * baseCost * 0.05; float magnitudeCost = (magMin + magMax) * baseCost * 0.05f;
if (mCastStyle == ESM::Enchantment::ConstantEffect) if (mCastStyle == ESM::Enchantment::ConstantEffect)
{ {
magnitudeCost *= store.get<ESM::GameSetting>().find("fEnchantmentConstantDurationMult")->getFloat(); magnitudeCost *= store.get<ESM::GameSetting>().find("fEnchantmentConstantDurationMult")->getFloat();
@ -186,7 +186,7 @@ namespace MWMechanics
magnitudeCost *= it->mDuration; magnitudeCost *= it->mDuration;
} }
float areaCost = area * 0.05 * baseCost; float areaCost = area * 0.05f * baseCost;
const float fEffectCostMult = store.get<ESM::GameSetting>().find("fEffectCostMult")->getFloat(); const float fEffectCostMult = store.get<ESM::GameSetting>().find("fEffectCostMult")->getFloat();
@ -215,7 +215,7 @@ namespace MWMechanics
{ {
int baseCost = getBaseCastCost(); int baseCost = getBaseCastCost();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
return getEffectiveEnchantmentCastCost(baseCost, player); return getEffectiveEnchantmentCastCost(static_cast<float>(baseCost), player);
} }
@ -225,7 +225,7 @@ namespace MWMechanics
return 0; return 0;
float priceMultipler = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("fEnchantmentValueMult")->getFloat(); float priceMultipler = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("fEnchantmentValueMult")->getFloat();
int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mEnchanter, (getEnchantPoints() * priceMultipler), true); int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mEnchanter, static_cast<int>(getEnchantPoints() * priceMultipler), true);
return price; return price;
} }
@ -247,7 +247,7 @@ namespace MWMechanics
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
return mOldItemPtr.getClass().getEnchantmentPoints(mOldItemPtr) * store.get<ESM::GameSetting>().find("fEnchantmentMult")->getFloat(); return static_cast<int>(mOldItemPtr.getClass().getEnchantmentPoints(mOldItemPtr) * store.get<ESM::GameSetting>().find("fEnchantmentMult")->getFloat());
} }
bool Enchanting::soulEmpty() const bool Enchanting::soulEmpty() const
{ {
@ -274,13 +274,13 @@ namespace MWMechanics
const NpcStats& npcStats = mEnchanter.getClass().getNpcStats (mEnchanter); const NpcStats& npcStats = mEnchanter.getClass().getNpcStats (mEnchanter);
float chance1 = (npcStats.getSkill (ESM::Skill::Enchant).getModified() + float chance1 = (npcStats.getSkill (ESM::Skill::Enchant).getModified() +
(0.25 * npcStats.getAttribute (ESM::Attribute::Intelligence).getModified()) (0.25f * npcStats.getAttribute (ESM::Attribute::Intelligence).getModified())
+ (0.125 * npcStats.getAttribute (ESM::Attribute::Luck).getModified())); + (0.125f * npcStats.getAttribute (ESM::Attribute::Luck).getModified()));
const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
float chance2 = 7.5 / (gmst.find("fEnchantmentChanceMult")->getFloat() * ((mCastStyle == ESM::Enchantment::ConstantEffect) ? float chance2 = 7.5f / (gmst.find("fEnchantmentChanceMult")->getFloat() * ((mCastStyle == ESM::Enchantment::ConstantEffect) ?
gmst.find("fEnchantmentConstantChanceMult")->getFloat() : 1 )) gmst.find("fEnchantmentConstantChanceMult")->getFloat() : 1.0f ))
* getEnchantPoints(); * getEnchantPoints();
return (chance1-chance2); return (chance1-chance2);

@ -142,7 +142,7 @@ void MWMechanics::NpcStats::setFactionReputation (const std::string& faction, in
float MWMechanics::NpcStats::getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const float MWMechanics::NpcStats::getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const
{ {
float progressRequirement = 1 + getSkill (skillIndex).getBase(); float progressRequirement = static_cast<float>(1 + getSkill(skillIndex).getBase());
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
@ -303,7 +303,7 @@ void MWMechanics::NpcStats::updateHealth()
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase(); const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
const int strength = getAttribute(ESM::Attribute::Strength).getBase(); const int strength = getAttribute(ESM::Attribute::Strength).getBase();
setHealth(static_cast<int> (0.5 * (strength + endurance))); setHealth(floor(0.5f * (strength + endurance)));
} }
int MWMechanics::NpcStats::getLevelupAttributeMultiplier(int attribute) const int MWMechanics::NpcStats::getLevelupAttributeMultiplier(int attribute) const

@ -17,7 +17,7 @@ namespace
// //
float distanceSquared(ESM::Pathgrid::Point point, Ogre::Vector3 pos) float distanceSquared(ESM::Pathgrid::Point point, Ogre::Vector3 pos)
{ {
return Ogre::Vector3(point.mX, point.mY, point.mZ).squaredDistance(pos); return MWMechanics::PathFinder::MakeOgreVector3(point).squaredDistance(pos);
} }
// Return the closest pathgrid point index from the specified position co // Return the closest pathgrid point index from the specified position co
@ -95,7 +95,7 @@ namespace MWMechanics
x -= point.mX; x -= point.mX;
y -= point.mY; y -= point.mY;
z -= point.mZ; z -= point.mZ;
return (x * x + y * y + 0.1 * z * z); return (x * x + y * y + 0.1f * z * z);
} }
float distance(ESM::Pathgrid::Point point, float x, float y, float z) float distance(ESM::Pathgrid::Point point, float x, float y, float z)
@ -108,9 +108,9 @@ namespace MWMechanics
float distance(ESM::Pathgrid::Point a, ESM::Pathgrid::Point b) float distance(ESM::Pathgrid::Point a, ESM::Pathgrid::Point b)
{ {
float x = a.mX - b.mX; float x = static_cast<float>(a.mX - b.mX);
float y = a.mY - b.mY; float y = static_cast<float>(a.mY - b.mY);
float z = a.mZ - b.mZ; float z = static_cast<float>(a.mZ - b.mZ);
return sqrt(x * x + y * y + z * z); return sqrt(x * x + y * y + z * z);
} }
@ -176,8 +176,9 @@ namespace MWMechanics
if(allowShortcuts) if(allowShortcuts)
{ {
// if there's a ray cast hit, can't take a direct path // if there's a ray cast hit, can't take a direct path
if(!MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ, if (!MWBase::Environment::get().getWorld()->castRay(
endPoint.mX, endPoint.mY, endPoint.mZ)) static_cast<float>(startPoint.mX), static_cast<float>(startPoint.mY), static_cast<float>(startPoint.mZ),
static_cast<float>(endPoint.mX), static_cast<float>(endPoint.mY), static_cast<float>(endPoint.mZ)))
{ {
mPath.push_back(endPoint); mPath.push_back(endPoint);
mIsPathConstructed = true; mIsPathConstructed = true;
@ -206,8 +207,8 @@ namespace MWMechanics
float yCell = 0; float yCell = 0;
if (mCell->isExterior()) if (mCell->isExterior())
{ {
xCell = mCell->getCell()->mData.mX * ESM::Land::REAL_SIZE; xCell = static_cast<float>(mCell->getCell()->mData.mX * ESM::Land::REAL_SIZE);
yCell = mCell->getCell()->mData.mY * ESM::Land::REAL_SIZE; yCell = static_cast<float>(mCell->getCell()->mData.mY * ESM::Land::REAL_SIZE);
} }
// NOTE: It is possible that getClosestPoint returns a pathgrind point index // NOTE: It is possible that getClosestPoint returns a pathgrind point index
@ -216,12 +217,12 @@ namespace MWMechanics
// point right behind the wall that is closer than any pathgrid // point right behind the wall that is closer than any pathgrid
// point outside the wall // point outside the wall
int startNode = getClosestPoint(mPathgrid, int startNode = getClosestPoint(mPathgrid,
Ogre::Vector3(startPoint.mX - xCell, startPoint.mY - yCell, startPoint.mZ)); Ogre::Vector3(startPoint.mX - xCell, startPoint.mY - yCell, static_cast<float>(startPoint.mZ)));
// Some cells don't have any pathgrids at all // Some cells don't have any pathgrids at all
if(startNode != -1) if(startNode != -1)
{ {
std::pair<int, bool> endNode = getClosestReachablePoint(mPathgrid, cell, std::pair<int, bool> endNode = getClosestReachablePoint(mPathgrid, cell,
Ogre::Vector3(endPoint.mX - xCell, endPoint.mY - yCell, endPoint.mZ), Ogre::Vector3(endPoint.mX - xCell, endPoint.mY - yCell, static_cast<float>(endPoint.mZ)),
startNode); startNode);
// this shouldn't really happen, but just in case // this shouldn't really happen, but just in case

@ -1,10 +1,12 @@
#ifndef GAME_MWMECHANICS_PATHFINDING_H #ifndef GAME_MWMECHANICS_PATHFINDING_H
#define GAME_MWMECHANICS_PATHFINDING_H #define GAME_MWMECHANICS_PATHFINDING_H
#include <components/esm/defs.hpp>
#include <components/esm/loadpgrd.hpp> #include <components/esm/loadpgrd.hpp>
#include <list> #include <list>
#include <OgreMath.h> #include <OgreMath.h>
#include <OgreVector3.h>
namespace MWWorld namespace MWWorld
{ {
@ -27,11 +29,11 @@ namespace MWMechanics
return -1.0; return -1.0;
} }
static float sgn(float a) static int sgn(int a)
{ {
if(a > 0) if(a > 0)
return 1.0; return 1;
return -1.0; return -1;
} }
void clearPath(); void clearPath();
@ -74,6 +76,24 @@ namespace MWMechanics
mPath.push_back(point); mPath.push_back(point);
} }
/// utility function to convert a Ogre::Vector3 to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const Ogre::Vector3& v)
{
return ESM::Pathgrid::Point(static_cast<int>(v[0]), static_cast<int>(v[1]), static_cast<int>(v[2]));
}
/// utility function to convert an ESM::Position to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const ESM::Position& p)
{
return ESM::Pathgrid::Point(static_cast<int>(p.pos[0]), static_cast<int>(p.pos[1]), static_cast<int>(p.pos[2]));
}
/// utility function to convert a Pathgrid::Point to a Ogre::Vector3
static Ogre::Vector3 MakeOgreVector3(const ESM::Pathgrid::Point& p)
{
return Ogre::Vector3(static_cast<Ogre::Real>(p.mX), static_cast<Ogre::Real>(p.mY), static_cast<Ogre::Real>(p.mZ));
}
private: private:
bool mIsPathConstructed; bool mIsPathConstructed;

@ -27,7 +27,7 @@ namespace
// //
float manhattan(const ESM::Pathgrid::Point& a, const ESM::Pathgrid::Point& b) float manhattan(const ESM::Pathgrid::Point& a, const ESM::Pathgrid::Point& b)
{ {
return 300 * (abs(a.mX - b.mX) + abs(a.mY - b.mY) + abs(a.mZ - b.mZ)); return 300.0f * (abs(a.mX - b.mX) + abs(a.mY - b.mY) + abs(a.mZ - b.mZ));
} }
// Choose a heuristics - Note that these may not be the best for directed // Choose a heuristics - Note that these may not be the best for directed
@ -317,23 +317,23 @@ namespace MWMechanics
float yCell = 0; float yCell = 0;
if (mIsExterior) if (mIsExterior)
{ {
xCell = mPathgrid->mData.mX * ESM::Land::REAL_SIZE; xCell = static_cast<float>(mPathgrid->mData.mX * ESM::Land::REAL_SIZE);
yCell = mPathgrid->mData.mY * ESM::Land::REAL_SIZE; yCell = static_cast<float>(mPathgrid->mData.mY * ESM::Land::REAL_SIZE);
} }
while(graphParent[current] != -1) while(graphParent[current] != -1)
{ {
ESM::Pathgrid::Point pt = mPathgrid->mPoints[current]; ESM::Pathgrid::Point pt = mPathgrid->mPoints[current];
pt.mX += xCell; pt.mX += static_cast<int>(xCell);
pt.mY += yCell; pt.mY += static_cast<int>(yCell);
path.push_front(pt); path.push_front(pt);
current = graphParent[current]; current = graphParent[current];
} }
// add first node to path explicitly // add first node to path explicitly
ESM::Pathgrid::Point pt = mPathgrid->mPoints[start]; ESM::Pathgrid::Point pt = mPathgrid->mPoints[start];
pt.mX += xCell; pt.mX += static_cast<int>(xCell);
pt.mY += yCell; pt.mY += static_cast<int>(yCell);
path.push_front(pt); path.push_front(pt);
return path; return path;
} }

@ -20,10 +20,10 @@ namespace MWMechanics
float Pickpocket::getChanceModifier(const MWWorld::Ptr &ptr, float add) float Pickpocket::getChanceModifier(const MWWorld::Ptr &ptr, float add)
{ {
NpcStats& stats = ptr.getClass().getNpcStats(ptr); NpcStats& stats = ptr.getClass().getNpcStats(ptr);
float agility = stats.getAttribute(ESM::Attribute::Agility).getModified(); float agility = static_cast<float>(stats.getAttribute(ESM::Attribute::Agility).getModified());
float luck = stats.getAttribute(ESM::Attribute::Luck).getModified(); float luck = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified());
float sneak = ptr.getClass().getSkill(ptr, ESM::Skill::Sneak); float sneak = static_cast<float>(ptr.getClass().getSkill(ptr, ESM::Skill::Sneak));
return (add + 0.2 * agility + 0.1 * luck + sneak) * stats.getFatigueTerm(); return (add + 0.2f * agility + 0.1f * luck + sneak) * stats.getFatigueTerm();
} }
bool Pickpocket::getDetected(float valueTerm) bool Pickpocket::getDetected(float valueTerm)
@ -33,13 +33,13 @@ namespace MWMechanics
float t = 2*x - y; float t = 2*x - y;
float pcSneak = mThief.getClass().getSkill(mThief, ESM::Skill::Sneak); float pcSneak = static_cast<float>(mThief.getClass().getSkill(mThief, ESM::Skill::Sneak));
int iPickMinChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>() int iPickMinChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
.find("iPickMinChance")->getInt(); .find("iPickMinChance")->getInt();
int iPickMaxChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>() int iPickMaxChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
.find("iPickMaxChance")->getInt(); .find("iPickMaxChance")->getInt();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (t < pcSneak / iPickMinChance) if (t < pcSneak / iPickMinChance)
{ {
return (roll > int(pcSneak / iPickMinChance)); return (roll > int(pcSneak / iPickMinChance));
@ -53,7 +53,7 @@ namespace MWMechanics
bool Pickpocket::pick(MWWorld::Ptr item, int count) bool Pickpocket::pick(MWWorld::Ptr item, int count)
{ {
float stackValue = item.getClass().getValue(item) * count; float stackValue = static_cast<float>(item.getClass().getValue(item) * count);
float fPickPocketMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>() float fPickPocketMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
.find("fPickPocketMod")->getFloat(); .find("fPickPocketMod")->getFloat();
float valueTerm = 10 * fPickPocketMod * stackValue; float valueTerm = 10 * fPickPocketMod * stackValue;

@ -44,12 +44,12 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
float toolQuality = ref->mBase->mData.mQuality; float toolQuality = ref->mBase->mData.mQuality;
float x = (0.1 * pcStrength + 0.1 * pcLuck + armorerSkill) * fatigueTerm; float x = (0.1f * pcStrength + 0.1f * pcLuck + armorerSkill) * fatigueTerm;
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100; int roll = static_cast<int>(static_cast<float> (std::rand()) / RAND_MAX * 100);
if (roll <= x) if (roll <= x)
{ {
int y = fRepairAmountMult * toolQuality * roll; int y = static_cast<int>(fRepairAmountMult * toolQuality * roll);
y = std::max(1, y); y = std::max(1, y);
// repair by 'y' points // repair by 'y' points

@ -20,9 +20,9 @@ namespace MWMechanics
{ {
CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor); CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor);
NpcStats& npcStats = actor.getClass().getNpcStats(actor); NpcStats& npcStats = actor.getClass().getNpcStats(actor);
mAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified(); mAgility = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Agility).getModified());
mLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified(); mLuck = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Luck).getModified());
mSecuritySkill = npcStats.getSkill(ESM::Skill::Security).getModified(); mSecuritySkill = static_cast<float>(npcStats.getSkill(ESM::Skill::Security).getModified());
mFatigueTerm = creatureStats.getFatigueTerm(); mFatigueTerm = creatureStats.getFatigueTerm();
} }
@ -38,7 +38,7 @@ namespace MWMechanics
float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPickLockMult")->getFloat(); float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPickLockMult")->getFloat();
float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill; float x = 0.2f * mAgility + 0.1f * mLuck + mSecuritySkill;
x *= pickQuality * mFatigueTerm; x *= pickQuality * mFatigueTerm;
x += fPickLockMult * lockStrength; x += fPickLockMult * lockStrength;
@ -48,7 +48,7 @@ namespace MWMechanics
else else
{ {
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, lock); MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, lock);
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100; int roll = static_cast<int>(static_cast<float> (std::rand()) / RAND_MAX * 100);
if (roll <= x) if (roll <= x)
{ {
lock.getClass().unlock(lock); lock.getClass().unlock(lock);
@ -76,11 +76,11 @@ namespace MWMechanics
float probeQuality = probe.get<ESM::Probe>()->mBase->mData.mQuality; float probeQuality = probe.get<ESM::Probe>()->mBase->mData.mQuality;
const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(trap.getCellRef().getTrap()); const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(trap.getCellRef().getTrap());
float trapSpellPoints = trapSpell->mData.mCost; int trapSpellPoints = trapSpell->mData.mCost;
float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTrapCostMult")->getFloat(); float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTrapCostMult")->getFloat();
float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill; float x = 0.2f * mAgility + 0.1f * mLuck + mSecuritySkill;
x += fTrapCostMult * trapSpellPoints; x += fTrapCostMult * trapSpellPoints;
x *= probeQuality * mFatigueTerm; x *= probeQuality * mFatigueTerm;
@ -90,7 +90,7 @@ namespace MWMechanics
else else
{ {
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, trap); MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, trap);
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100; int roll = static_cast<int>(static_cast<float> (std::rand()) / RAND_MAX * 100);
if (roll <= x) if (roll <= x)
{ {
trap.getCellRef().setTrap(""); trap.getCellRef().setTrap("");

@ -144,21 +144,21 @@ namespace MWMechanics
for (std::vector<ESM::ENAMstruct>::const_iterator it = spell->mEffects.mList.begin(); it != spell->mEffects.mList.end(); ++it) for (std::vector<ESM::ENAMstruct>::const_iterator it = spell->mEffects.mList.begin(); it != spell->mEffects.mList.end(); ++it)
{ {
float x = it->mDuration; float x = static_cast<float>(it->mDuration);
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find( const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(
it->mEffectID); it->mEffectID);
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) if (!(magicEffect->mData.mFlags & ESM::MagicEffect::UncappedDamage))
x = std::max(1.f, x); x = std::max(1.f, x);
x *= 0.1 * magicEffect->mData.mBaseCost; x *= 0.1f * magicEffect->mData.mBaseCost;
x *= 0.5 * (it->mMagnMin + it->mMagnMax); x *= 0.5f * (it->mMagnMin + it->mMagnMax);
x *= it->mArea * 0.05 * magicEffect->mData.mBaseCost; x *= it->mArea * 0.05f * magicEffect->mData.mBaseCost;
if (it->mRange == ESM::RT_Target) if (it->mRange == ESM::RT_Target)
x *= 1.5; x *= 1.5f;
static const float fEffectCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find( static const float fEffectCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
"fEffectCostMult")->getFloat(); "fEffectCostMult")->getFloat();
x *= fEffectCostMult; x *= fEffectCostMult;
float s = 2 * actor.getClass().getSkill(actor, spellSchoolToSkill(magicEffect->mData.mSchool)); float s = 2.0f * actor.getClass().getSkill(actor, spellSchoolToSkill(magicEffect->mData.mSchool));
if (s - x < y) if (s - x < y)
{ {
y = s - x; y = s - x;
@ -174,12 +174,12 @@ namespace MWMechanics
if (spell->mData.mFlags & ESM::Spell::F_Always) if (spell->mData.mFlags & ESM::Spell::F_Always)
return 100; return 100;
int castBonus = -stats.getMagicEffects().get(ESM::MagicEffect::Sound).getMagnitude(); float castBonus = -stats.getMagicEffects().get(ESM::MagicEffect::Sound).getMagnitude();
int actorWillpower = stats.getAttribute(ESM::Attribute::Willpower).getModified(); int actorWillpower = stats.getAttribute(ESM::Attribute::Willpower).getModified();
int actorLuck = stats.getAttribute(ESM::Attribute::Luck).getModified(); int actorLuck = stats.getAttribute(ESM::Attribute::Luck).getModified();
float castChance = (lowestSkill - spell->mData.mCost + castBonus + 0.2 * actorWillpower + 0.1 * 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.getRefData().getHandle() == "player") if (MWBase::Environment::get().getWorld()->getGodModeState() && actor.getRefData().getHandle() == "player")
castChance = 100; castChance = 100;
@ -267,9 +267,9 @@ namespace MWMechanics
float resistance = getEffectResistanceAttribute(effectId, magicEffects); float resistance = getEffectResistanceAttribute(effectId, magicEffects);
float willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified(); int willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified();
float luck = stats.getAttribute(ESM::Attribute::Luck).getModified(); float luck = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified());
float x = (willpower + 0.1 * luck) * stats.getFatigueTerm(); float x = (willpower + 0.1f * luck) * stats.getFatigueTerm();
// This makes spells that are easy to cast harder to resist and vice versa // This makes spells that are easy to cast harder to resist and vice versa
float castChance = 100.f; float castChance = 100.f;
@ -383,7 +383,7 @@ namespace MWMechanics
target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistCommonDisease).getMagnitude() target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
: target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistBlightDisease).getMagnitude(); : target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistBlightDisease).getMagnitude();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100); // [0, 99]
if (roll <= x) if (roll <= x)
{ {
// Fully resisted, show message // Fully resisted, show message
@ -413,8 +413,8 @@ namespace MWMechanics
bool absorbed = false; bool absorbed = false;
if (spell && caster != target && target.getClass().isActor()) if (spell && caster != target && target.getClass().isActor())
{ {
int absorb = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude(); float absorb = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
absorbed = (roll < absorb); absorbed = (roll < absorb);
if (absorbed) if (absorbed)
{ {
@ -462,8 +462,8 @@ namespace MWMechanics
// Try reflecting // Try reflecting
if (!reflected && magnitudeMult > 0 && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable)) if (!reflected && magnitudeMult > 0 && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable))
{ {
int reflect = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::Reflect).getMagnitude(); float reflect = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::Reflect).getMagnitude();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
bool isReflected = (roll < reflect); bool isReflected = (roll < reflect);
if (isReflected) if (isReflected)
{ {
@ -502,7 +502,7 @@ namespace MWMechanics
ActiveSpells::ActiveEffect effect; ActiveSpells::ActiveEffect effect;
effect.mEffectId = effectIt->mEffectID; effect.mEffectId = effectIt->mEffectID;
effect.mArg = MWMechanics::EffectKey(*effectIt).mArg; effect.mArg = MWMechanics::EffectKey(*effectIt).mArg;
effect.mDuration = effectIt->mDuration; effect.mDuration = static_cast<float>(effectIt->mDuration);
effect.mMagnitude = magnitude; effect.mMagnitude = magnitude;
targetEffects.add(MWMechanics::EffectKey(*effectIt), MWMechanics::EffectParam(effect.mMagnitude)); targetEffects.add(MWMechanics::EffectKey(*effectIt), MWMechanics::EffectParam(effect.mMagnitude));
@ -613,7 +613,7 @@ namespace MWMechanics
{ {
if (caster.getRefData().getHandle() == "player") if (caster.getRefData().getHandle() == "player")
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}");
target.getCellRef().setLockLevel(magnitude); target.getCellRef().setLockLevel(static_cast<int>(magnitude));
} }
} }
else if (effectId == ESM::MagicEffect::Open) else if (effectId == ESM::MagicEffect::Open)
@ -721,10 +721,10 @@ namespace MWMechanics
// Check if there's enough charge left // Check if there's enough charge left
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed || enchantment->mData.mType == ESM::Enchantment::WhenStrikes) if (enchantment->mData.mType == ESM::Enchantment::WhenUsed || enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
{ {
const int castCost = getEffectiveEnchantmentCastCost(enchantment->mData.mCost, mCaster); const int castCost = getEffectiveEnchantmentCastCost(static_cast<float>(enchantment->mData.mCost), mCaster);
if (item.getCellRef().getEnchantmentCharge() == -1) if (item.getCellRef().getEnchantmentCharge() == -1)
item.getCellRef().setEnchantmentCharge(enchantment->mData.mCharge); item.getCellRef().setEnchantmentCharge(static_cast<float>(enchantment->mData.mCharge));
if (item.getCellRef().getEnchantmentCharge() < castCost) if (item.getCellRef().getEnchantmentCharge() < castCost)
{ {
@ -823,8 +823,8 @@ namespace MWMechanics
bool fail = false; bool fail = false;
// Check success // Check success
int successChance = getSpellSuccessChance(spell, mCaster); float successChance = getSpellSuccessChance(spell, mCaster);
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (!fail && roll >= successChance) if (!fail && roll >= successChance)
{ {
if (mCaster.getRefData().getHandle() == "player") if (mCaster.getRefData().getHandle() == "player")
@ -899,11 +899,11 @@ namespace MWMechanics
const MWMechanics::CreatureStats& creatureStats = mCaster.getClass().getCreatureStats(mCaster); const MWMechanics::CreatureStats& creatureStats = mCaster.getClass().getCreatureStats(mCaster);
float x = (npcStats.getSkill (ESM::Skill::Alchemy).getModified() + float x = (npcStats.getSkill (ESM::Skill::Alchemy).getModified() +
0.2 * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified() 0.2f * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified()
+ 0.1 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified()) + 0.1f * creatureStats.getAttribute (ESM::Attribute::Luck).getModified())
* creatureStats.getFatigueTerm(); * creatureStats.getFatigueTerm();
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = static_cast<int>(std::rand() / (static_cast<double> (RAND_MAX)+1) * 100); // [0, 99]
if (roll > x) if (roll > x)
{ {
// "X has no effect on you" // "X has no effect on you"
@ -915,24 +915,24 @@ namespace MWMechanics
float magnitude = 0; float magnitude = 0;
float y = roll / std::min(x, 100.f); float y = roll / std::min(x, 100.f);
y *= 0.25 * x; y *= 0.25f * x;
if (magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration) if (magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration)
effect.mDuration = int(y); effect.mDuration = static_cast<int>(y);
else else
effect.mDuration = 1; effect.mDuration = 1;
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude)) if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude))
{ {
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration)) if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration))
magnitude = int((0.05 * y) / (0.1 * magicEffect->mData.mBaseCost)); magnitude = floor((0.05f * y) / (0.1f * magicEffect->mData.mBaseCost));
else else
magnitude = int(y / (0.1 * magicEffect->mData.mBaseCost)); magnitude = floor(y / (0.1f * magicEffect->mData.mBaseCost));
magnitude = std::max(1.f, magnitude); magnitude = std::max(1.f, magnitude);
} }
else else
magnitude = 1; magnitude = 1;
effect.mMagnMax = magnitude; effect.mMagnMax = static_cast<int>(magnitude);
effect.mMagnMin = magnitude; effect.mMagnMin = static_cast<int>(magnitude);
ESM::EffectList effects; ESM::EffectList effects;
effects.mList.push_back(effect); effects.mList.push_back(effect);

@ -15,10 +15,10 @@ void MWMechanics::AttributeValue::readState (const ESM::StatState<int>& state)
mDamage = state.mDamage; mDamage = state.mDamage;
} }
void MWMechanics::AttributeValue::setModifiers(int fortify, int drain, int absorb) void MWMechanics::AttributeValue::setModifiers(float fortify, float drain, float absorb)
{ {
mFortified = fortify; mFortified = static_cast<int>(fortify);
mModifier = (fortify - drain) - absorb; mModifier = mFortified - static_cast<int>(drain + absorb);
} }
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const

@ -247,7 +247,7 @@ namespace MWMechanics
int getModifier() const { return mModifier; } int getModifier() const { return mModifier; }
void setBase(int base) { mBase = std::max(0, base); } void setBase(int base) { mBase = std::max(0, base); }
void setModifiers(int fortify, int drain, int absorb); void setModifiers(float fortify, float drain, float absorb);
void damage(float damage) { mDamage = std::min(mDamage + damage, (float)(mBase + mFortified)); } void damage(float damage) { mDamage = std::min(mDamage + damage, (float)(mBase + mFortified)); }
void restore(float amount) { mDamage -= std::min(mDamage, amount); } void restore(float amount) { mDamage -= std::min(mDamage, amount); }

@ -111,7 +111,7 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool
sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition()); sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition());
mStaticGeometrySmall[ptr.getCell()] = sg; mStaticGeometrySmall[ptr.getCell()] = sg;
sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance")); sg->setRenderingDistance(static_cast<Ogre::Real>(Settings::Manager::getInt("small object distance", "Viewing distance")));
} }
else else
sg = mStaticGeometrySmall[ptr.getCell()]; sg = mStaticGeometrySmall[ptr.getCell()];

@ -630,7 +630,7 @@ void MWWorld::InventoryStore::updateRechargingItems()
it->getClass().getEnchantment(*it)); it->getClass().getEnchantment(*it));
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed if (enchantment->mData.mType == ESM::Enchantment::WhenUsed
|| enchantment->mData.mType == ESM::Enchantment::WhenStrikes) || enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
mRechargingItems.push_back(std::make_pair(it, enchantment->mData.mCharge)); mRechargingItems.push_back(std::make_pair(it, static_cast<float>(enchantment->mData.mCharge)));
} }
} }
} }

Loading…
Cancel
Save