1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-30 22:34:32 +00:00

Address more conversion warnings in the engine

This commit is contained in:
Evil Eye 2025-09-22 18:10:34 +02:00
parent e77ce5a507
commit 5308e22f6d
28 changed files with 115 additions and 110 deletions

View file

@ -339,7 +339,7 @@ namespace MWClass
->mValue.getInteger();
if (ref->mBase->mData.mWeight == 0)
return ref->mBase->mData.mArmor;
return static_cast<float>(ref->mBase->mData.mArmor);
else
return ref->mBase->mData.mArmor * armorSkill / static_cast<float>(iBaseArmorSkill);
}

View file

@ -190,7 +190,7 @@ namespace MWClass
ESM::Clothing newItem = *ref->mBase;
newItem.mId = ESM::RefId();
newItem.mName = newName;
newItem.mData.mEnchant = enchCharge;
newItem.mData.mEnchant = static_cast<uint16_t>(enchCharge);
newItem.mEnchant = enchId;
const ESM::Clothing* record = MWBase::Environment::get().getESMStore()->insert(newItem);
return record->mId;

View file

@ -132,7 +132,8 @@ namespace MWClass
// creature stats
for (size_t i = 0; i < ref->mBase->mData.mAttributes.size(); ++i)
data->mCreatureStats.setAttribute(ESM::Attribute::indexToRefId(i), ref->mBase->mData.mAttributes[i]);
data->mCreatureStats.setAttribute(ESM::Attribute::indexToRefId(static_cast<int>(i)),
static_cast<float>(ref->mBase->mData.mAttributes[i]));
data->mCreatureStats.setHealth(static_cast<float>(ref->mBase->mData.mHealth));
data->mCreatureStats.setMagicka(static_cast<float>(ref->mBase->mData.mMana));
data->mCreatureStats.setFatigue(static_cast<float>(ref->mBase->mData.mFatigue));
@ -757,11 +758,11 @@ namespace MWClass
switch (skillRecord->mData.mSpecialization)
{
case ESM::Class::Combat:
return ref->mBase->mData.mCombat;
return static_cast<float>(ref->mBase->mData.mCombat);
case ESM::Class::Magic:
return ref->mBase->mData.mMagic;
return static_cast<float>(ref->mBase->mData.mMagic);
case ESM::Class::Stealth:
return ref->mBase->mData.mStealth;
return static_cast<float>(ref->mBase->mData.mStealth);
default:
throw std::runtime_error("invalid specialisation");
}
@ -887,7 +888,7 @@ namespace MWClass
void Creature::setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const
{
MWMechanics::setBaseAISetting<ESM::Creature>(id, setting, value);
MWMechanics::setBaseAISetting<ESM::Creature>(id, setting, static_cast<unsigned char>(value));
}
void Creature::modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const

View file

@ -215,14 +215,14 @@ namespace MWClass
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr, closeSound, 0.5f);
// Doors rotate at 90 degrees per second, so start the sound at
// where it would be at the current rotation.
float offset = doorRot / (osg::PI * 0.5f);
float offset = doorRot / (osg::PIf * 0.5f);
action->setSoundOffset(offset);
action->setSound(openSound);
}
else
{
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr, openSound, 0.5f);
float offset = 1.0f - doorRot / (osg::PI * 0.5f);
float offset = 1.0f - doorRot / (osg::PIf * 0.5f);
action->setSoundOffset(std::max(offset, 0.0f));
action->setSound(closeSound);
}

View file

@ -134,7 +134,7 @@ namespace MWClass
if (ref->mBase->mData.mEffectID[i] < 0)
continue;
MWGui::Widgets::SpellEffectParams params;
params.mEffectID = ref->mBase->mData.mEffectID[i];
params.mEffectID = static_cast<short>(ref->mBase->mData.mEffectID[i]);
params.mAttribute = ESM::Attribute::indexToRefId(ref->mBase->mData.mAttributes[i]);
params.mSkill = ESM::Skill::indexToRefId(ref->mBase->mData.mSkills[i]);
params.mKnown = alchemySkill >= fWortChanceValue * (i + 1);

View file

@ -90,13 +90,13 @@ namespace MWClass
if (Settings::game().mRebalanceSoulGemValues)
{
// use the 'soul gem value rebalance' formula from the Morrowind Code Patch
float soulValue = 0.0001 * pow(soul, 3) + 2 * soul;
double soulValue = 0.0001 * std::pow(soul, 3) + 2 * soul;
// for Azura's star add the unfilled value
if (ptr.getCellRef().getRefId() == "Misc_SoulGem_Azura")
value += soulValue;
value += static_cast<int>(soulValue);
else
value = soulValue;
value = static_cast<int>(soulValue);
}
else
value *= soul;

View file

@ -85,24 +85,24 @@ namespace
const NpcParts npcParts;
int is_even(double d)
bool isEven(double d)
{
double intPart;
modf(d / 2.0, &intPart);
std::modf(d / 2.0, &intPart);
return 2.0 * intPart == d;
}
int round_ieee_754(double d)
float round_ieee_754(double d)
{
double i = floor(d);
double i = std::floor(d);
d -= i;
if (d < 0.5)
return static_cast<int>(i);
return float(static_cast<int>(i));
if (d > 0.5)
return static_cast<int>(i) + 1;
if (is_even(i))
return static_cast<int>(i);
return static_cast<int>(i) + 1;
return static_cast<int>(i) + 1.f;
if (isEven(i))
return float(static_cast<int>(i));
return static_cast<int>(i) + 1.f;
}
void autoCalculateAttributes(const ESM::NPC* npc, MWMechanics::CreatureStats& creatureStats)
@ -115,7 +115,8 @@ namespace
const auto& attributes = MWBase::Environment::get().getESMStore()->get<ESM::Attribute>();
int level = creatureStats.getLevel();
for (const ESM::Attribute& attribute : attributes)
creatureStats.setAttribute(attribute.mId, race->mData.getAttribute(attribute.mId, male));
creatureStats.setAttribute(
attribute.mId, static_cast<float>(race->mData.getAttribute(attribute.mId, male)));
// class bonus
const ESM::Class* npcClass = MWBase::Environment::get().getESMStore()->get<ESM::Class>().find(npc->mClass);
@ -155,7 +156,7 @@ namespace
creatureStats.setAttribute(attribute.mId,
std::min(
round_ieee_754(creatureStats.getAttribute(attribute.mId).getBase() + (level - 1) * modifierSum),
100));
100.f));
}
// initial health
@ -248,7 +249,7 @@ namespace
npcStats.getSkill(skill.mId).setBase(
std::min(round_ieee_754(npcStats.getSkill(skill.mId).getBase() + 5 + raceBonus + specBonus
+ (int(level) - 1) * (majorMultiplier + specMultiplier)),
100)); // Must gracefully handle level 0
100.f)); // Must gracefully handle level 0
}
if (!spellsInitialised)
@ -334,10 +335,12 @@ namespace MWClass
gold = ref->mBase->mNpdt.mGold;
for (size_t i = 0; i < ref->mBase->mNpdt.mSkills.size(); ++i)
data->mNpcStats.getSkill(ESM::Skill::indexToRefId(i)).setBase(ref->mBase->mNpdt.mSkills[i]);
data->mNpcStats.getSkill(ESM::Skill::indexToRefId(static_cast<int>(i)))
.setBase(ref->mBase->mNpdt.mSkills[i]);
for (size_t i = 0; i < ref->mBase->mNpdt.mAttributes.size(); ++i)
data->mNpcStats.setAttribute(ESM::Attribute::indexToRefId(i), ref->mBase->mNpdt.mAttributes[i]);
data->mNpcStats.setAttribute(
ESM::Attribute::indexToRefId(static_cast<int>(i)), ref->mBase->mNpdt.mAttributes[i]);
data->mNpcStats.setHealth(ref->mBase->mNpdt.mHealth);
data->mNpcStats.setMagicka(ref->mBase->mNpdt.mMana);
@ -589,7 +592,7 @@ namespace MWClass
if (!weapon.isEmpty())
weapskill = weapon.getClass().getEquipmentSkill(weapon);
float hitchance = MWMechanics::getHitChance(ptr, victim, getSkill(ptr, weapskill));
float hitchance = MWMechanics::getHitChance(ptr, victim, static_cast<int>(getSkill(ptr, weapskill)));
return Misc::Rng::roll0to99(world->getPrng()) < hitchance;
}
@ -1405,7 +1408,7 @@ namespace MWClass
void Npc::setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const
{
MWMechanics::setBaseAISetting<ESM::NPC>(id, setting, value);
MWMechanics::setBaseAISetting<ESM::NPC>(id, setting, static_cast<unsigned char>(value));
}
void Npc::modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const

View file

@ -261,7 +261,7 @@ namespace MWClass
ESM::Weapon newItem = *ref->mBase;
newItem.mId = ESM::RefId();
newItem.mName = newName;
newItem.mData.mEnchant = enchCharge;
newItem.mData.mEnchant = static_cast<uint16_t>(enchCharge);
newItem.mEnchant = enchId;
newItem.mData.mFlags |= ESM::Weapon::Magical;
const ESM::Weapon* record = MWBase::Environment::get().getESMStore()->insert(newItem);

View file

@ -127,7 +127,7 @@ namespace MWGui
getWidget(mFavoriteAttribute[0], "FavoriteAttribute0");
getWidget(mFavoriteAttribute[1], "FavoriteAttribute1");
for (int i = 0; i < 5; i++)
for (char i = 0; i < 5; i++)
{
char theIndex = '0' + i;
getWidget(mMajorSkill[i], std::string("MajorSkill").append(1, theIndex));
@ -483,7 +483,7 @@ namespace MWGui
return true;
setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
setControllerFocus(mButtons, mControllerFocus, true);
}
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -494,7 +494,7 @@ namespace MWGui
return true;
setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
setControllerFocus(mButtons, mControllerFocus, true);
}
@ -546,7 +546,7 @@ namespace MWGui
"MajorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMajor", {}));
setText(
"MinorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMinor", {}));
for (int i = 0; i < 5; i++)
for (char i = 0; i < 5; i++)
{
char theIndex = '0' + i;
getWidget(mMajorSkill[i], std::string("MajorSkill").append(1, theIndex));
@ -713,13 +713,13 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
{
setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
setControllerFocus(mButtons, mControllerFocus, true);
}
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{
setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
setControllerFocus(mButtons, mControllerFocus, true);
}
return true;
@ -1001,13 +1001,13 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
{
mAttributeButtons[mControllerFocus]->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus - 1, mAttributeButtons.size());
mControllerFocus = wrap(mControllerFocus, mAttributeButtons.size(), -1);
mAttributeButtons[mControllerFocus]->setStateSelected(true);
}
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{
mAttributeButtons[mControllerFocus]->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus + 1, mAttributeButtons.size());
mControllerFocus = wrap(mControllerFocus, mAttributeButtons.size(), 1);
mAttributeButtons[mControllerFocus]->setStateSelected(true);
}
@ -1103,13 +1103,13 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
{
mSkillButtons[mControllerFocus]->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus - 1, mSkillButtons.size());
mControllerFocus = wrap(mControllerFocus, mSkillButtons.size(), -1);
mSkillButtons[mControllerFocus]->setStateSelected(true);
}
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{
mSkillButtons[mControllerFocus]->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus + 1, mSkillButtons.size());
mControllerFocus = wrap(mControllerFocus, mSkillButtons.size(), 1);
mSkillButtons[mControllerFocus]->setStateSelected(true);
}
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)

View file

@ -84,7 +84,7 @@ namespace MWGui
}
MWWorld::Ptr object = item.mBase;
int count = item.mCount;
size_t count = item.mCount;
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
if (MyGUI::InputManager::getInstance().isControlPressed())
count = 1;
@ -96,7 +96,7 @@ namespace MWGui
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string name{ object.getClass().getName(object) };
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count);
dialog->openCountDialog(name, "#{sTake}", static_cast<int>(count));
dialog->eventOkClicked.clear();
if (Settings::gui().mControllerMenus || MyGUI::InputManager::getInstance().isAltPressed())
dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::transferItem);
@ -116,7 +116,7 @@ namespace MWGui
const ItemStack item = mModel->getItem(mSelectedItem);
if (!mModel->onTakeItem(item.mBase, count))
if (!mModel->onTakeItem(item.mBase, static_cast<int>(count)))
return;
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
@ -129,7 +129,7 @@ namespace MWGui
const ItemStack item = mModel->getItem(mSelectedItem);
if (!mModel->onTakeItem(item.mBase, count))
if (!mModel->onTakeItem(item.mBase, static_cast<int>(count)))
return;
mItemTransfer->apply(item, count, *mItemView);
@ -140,7 +140,7 @@ namespace MWGui
if (mModel == nullptr)
return;
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, mDragAndDrop->mDraggedCount);
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, static_cast<int>(mDragAndDrop->mDraggedCount));
if (success)
mDragAndDrop->drop(mModel, mItemView);
@ -248,7 +248,7 @@ namespace MWGui
MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr);
for (size_t i = 0; i < mModel->getItemCount(); ++i)
{
const ItemStack& item = mModel->getItem(i);
const ItemStack& item = mModel->getItem(static_cast<ItemModel::ModelIndex>(i));
if (invStore.isEquipped(item.mBase) == false)
continue;
@ -263,14 +263,14 @@ namespace MWGui
if (i == 0)
{
// play the sound of the first object
MWWorld::Ptr item = mModel->getItem(i).mBase;
MWWorld::Ptr item = mModel->getItem(static_cast<ItemModel::ModelIndex>(i)).mBase;
const ESM::RefId& sound = item.getClass().getUpSoundId(item);
MWBase::Environment::get().getWindowManager()->playSound(sound);
}
const ItemStack item = mModel->getItem(i);
const ItemStack item = mModel->getItem(static_cast<ItemModel::ModelIndex>(i));
if (!mModel->onTakeItem(item.mBase, item.mCount))
if (!mModel->onTakeItem(item.mBase, static_cast<int>(item.mCount)))
break;
mModel->moveItem(item, item.mCount, playerModel);

View file

@ -166,8 +166,8 @@ namespace MWLua
return completion;
return sol::nullopt;
};
api["getLoopCount"] = [](const LObject& object, std::string groupname) -> sol::optional<size_t> {
size_t loops = 0;
api["getLoopCount"] = [](const LObject& object, std::string groupname) -> sol::optional<uint32_t> {
uint32_t loops = 0;
if (getConstAnimationOrThrow(object)->getInfo(groupname, nullptr, nullptr, &loops))
return loops;
return sol::nullopt;

View file

@ -268,7 +268,7 @@ namespace MWLua
auto setOwnerFactionRank = [](const OwnerT& o, sol::optional<int64_t> factionRank) {
if (std::is_same_v<ObjectT, LObject> && !dynamic_cast<const SelfObject*>(&o.mObj))
throw std::runtime_error("Local scripts can set an owner faction rank only on self");
int64_t rank = std::max(0, LuaUtil::fromLuaIndex(factionRank.value_or(0)));
int64_t rank = std::max<int64_t>(0, LuaUtil::fromLuaIndex(factionRank.value_or(0)));
o.mObj.ptr().getCellRef().setFactionRank(static_cast<int>(rank));
};
ownerT["factionRank"] = sol::property(getOwnerFactionRank, setOwnerFactionRank);

View file

@ -61,7 +61,7 @@ namespace
if (rec["baseArmor"] != sol::nil)
armor.mData.mArmor = rec["baseArmor"];
if (rec["enchantCapacity"] != sol::nil)
armor.mData.mEnchant = std::round(rec["enchantCapacity"].get<float>() * 10);
armor.mData.mEnchant = static_cast<int32_t>(std::round(rec["enchantCapacity"].get<float>() * 10));
return armor;
}

View file

@ -49,7 +49,7 @@ namespace
}
if (rec["enchantCapacity"] != sol::nil)
book.mData.mEnchant = std::round(rec["enchantCapacity"].get<float>() * 10);
book.mData.mEnchant = static_cast<int32_t>(std::round(rec["enchantCapacity"].get<float>() * 10));
if (rec["mwscript"] != sol::nil)
{
std::string_view scriptId = rec["mwscript"].get<std::string_view>();

View file

@ -46,7 +46,7 @@ namespace
clothing.mEnchant = ESM::RefId::deserializeText(enchantId);
}
if (rec["enchantCapacity"] != sol::nil)
clothing.mData.mEnchant = std::round(rec["enchantCapacity"].get<float>() * 10);
clothing.mData.mEnchant = static_cast<int16_t>(std::round(rec["enchantCapacity"].get<float>() * 10));
if (rec["weight"] != sol::nil)
clothing.mData.mWeight = rec["weight"];
if (rec["value"] != sol::nil)

View file

@ -45,14 +45,14 @@ namespace MWLua
record["value"] = sol::readonly_property([](const ESM::Ingredient& rec) -> int { return rec.mData.mValue; });
record["effects"] = sol::readonly_property([lua = lua.lua_state()](const ESM::Ingredient& rec) -> sol::table {
sol::table res(lua, sol::create);
for (size_t i = 0; i < 4; ++i)
for (uint32_t i = 0; i < 4; ++i)
{
if (rec.mData.mEffectID[i] < 0)
continue;
ESM::IndexedENAMstruct effect;
effect.mData.mEffectID = rec.mData.mEffectID[i];
effect.mData.mSkill = rec.mData.mSkills[i];
effect.mData.mAttribute = rec.mData.mAttributes[i];
effect.mData.mEffectID = static_cast<int16_t>(rec.mData.mEffectID[i]);
effect.mData.mSkill = static_cast<signed char>(rec.mData.mSkills[i]);
effect.mData.mAttribute = static_cast<signed char>(rec.mData.mAttributes[i]);
effect.mData.mRange = ESM::RT_Self;
effect.mData.mArea = 0;
effect.mData.mDuration = 0;

View file

@ -120,7 +120,7 @@ namespace
}
if (rec["baseDisposition"] != sol::nil)
npc.mNpdt.mDisposition = rec["baseDisposition"].get<int>();
npc.mNpdt.mDisposition = rec["baseDisposition"].get<unsigned char>();
if (rec["baseGold"] != sol::nil)
npc.mNpdt.mGold = rec["baseGold"].get<int>();
@ -136,7 +136,7 @@ namespace
= MWBase::Environment::get().getESMStore()->get<ESM::Faction>().find(npc.mFaction);
int luaValue = rec["primaryFactionRank"];
int rank = LuaUtil::fromLuaIndex(luaValue);
int64_t rank = LuaUtil::fromLuaIndex(luaValue);
int maxRank = static_cast<int>(getValidRanksCount(faction));
@ -144,7 +144,7 @@ namespace
throw std::runtime_error("primaryFactionRank: Requested rank " + std::to_string(rank)
+ " is out of bounds for faction " + npc.mFaction.toDebugString());
npc.mNpdt.mRank = rank;
npc.mNpdt.mRank = static_cast<unsigned char>(rank);
}
}
@ -218,7 +218,7 @@ namespace MWLua
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead.serializeText(); });
record["primaryFaction"] = sol::readonly_property(
[](const ESM::NPC& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mFaction); });
record["primaryFactionRank"] = sol::readonly_property([](const ESM::NPC& rec, sol::this_state s) -> int {
record["primaryFactionRank"] = sol::readonly_property([](const ESM::NPC& rec, sol::this_state s) -> int64_t {
if (rec.mFaction.empty())
return 0;
return LuaUtil::toLuaIndex(rec.mNpdt.mRank);
@ -332,7 +332,7 @@ namespace MWLua
if (!npcStats.isInFaction(factionId))
throw std::runtime_error("Target actor is not a member of faction " + factionId.toDebugString());
npcStats.setFactionRank(factionId, targetRank);
npcStats.setFactionRank(factionId, static_cast<int>(targetRank));
};
npc["modifyFactionRank"] = [](Object& actor, std::string_view faction, int value) {

View file

@ -64,7 +64,7 @@ namespace
{
int weaponType = rec["type"].get<int>();
if (weaponType >= 0 && weaponType <= ESM::Weapon::Last)
weapon.mData.mType = weaponType;
weapon.mData.mType = static_cast<int16_t>(weaponType);
else
throw std::runtime_error("Invalid Weapon Type provided: " + std::to_string(weaponType));
}
@ -79,7 +79,7 @@ namespace
if (rec["reach"] != sol::nil)
weapon.mData.mReach = rec["reach"];
if (rec["enchantCapacity"] != sol::nil)
weapon.mData.mEnchant = std::round(rec["enchantCapacity"].get<float>() * 10);
weapon.mData.mEnchant = static_cast<uint16_t>(std::round(rec["enchantCapacity"].get<float>() * 10));
if (rec["chopMinDamage"] != sol::nil)
weapon.mData.mChop[0] = rec["chopMinDamage"];
if (rec["chopMaxDamage"] != sol::nil)

View file

@ -514,7 +514,7 @@ MWMechanics::Alchemy::TEffectsIterator MWMechanics::Alchemy::endEffects() const
return mEffects.end();
}
bool MWMechanics::Alchemy::knownEffect(unsigned int potionEffectIndex, const MWWorld::Ptr& npc)
bool MWMechanics::Alchemy::knownEffect(size_t potionEffectIndex, const MWWorld::Ptr& npc)
{
float alchemySkill = npc.getClass().getSkill(npc, ESM::Skill::Alchemy);
static const float fWortChanceValue

View file

@ -86,7 +86,7 @@ namespace MWMechanics
int countPotionsToBrew() const;
///< calculates maximum amount of potions, which you can make from selected ingredients
static bool knownEffect(unsigned int potionEffectIndex, const MWWorld::Ptr& npc);
static bool knownEffect(size_t potionEffectIndex, const MWWorld::Ptr& npc);
///< Does npc have sufficient alchemy skill to know about this potion effect?
void setAlchemist(const MWWorld::Ptr& npc);

View file

@ -828,8 +828,8 @@ namespace MWMechanics
clearStateAnimation(mCurrentIdle);
mCurrentIdle = std::move(idleGroup);
playBlendedAnimation(
mCurrentIdle, priority, MWRender::BlendMask_All, false, 1.0f, "start", "stop", startPoint, numLoops, true);
playBlendedAnimation(mCurrentIdle, priority, MWRender::BlendMask_All, false, 1.0f, "start", "stop", startPoint,
static_cast<uint32_t>(numLoops), true);
}
void CharacterController::refreshCurrentAnims(
@ -851,7 +851,8 @@ namespace MWMechanics
{
mDeathState = death;
mCurrentDeath = deathStateToAnimGroup(mDeathState);
mPtr.getClass().getCreatureStats(mPtr).setDeathAnimation(mDeathState - CharState_Death1);
mPtr.getClass().getCreatureStats(mPtr).setDeathAnimation(
static_cast<signed char>(mDeathState - CharState_Death1));
// For dead actors, refreshCurrentAnims is no longer called, so we need to disable the movement state manually.
// Note that these animations wouldn't actually be visible (due to the Death animation's priority being higher).
@ -1924,7 +1925,7 @@ namespace MWMechanics
else
{
float complete;
size_t loopcount;
uint32_t loopcount;
mAnimation->getInfo(mAnimQueue.front().mGroup, &complete, nullptr, &loopcount);
mAnimQueue.front().mLoopCount = loopcount;
mAnimQueue.front().mTime = complete;
@ -2010,10 +2011,10 @@ namespace MWMechanics
{
// Force Jump
if (stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceJump))
movementSettings.mPosition[2] = onground ? 1 : 0;
movementSettings.mPosition[2] = onground ? 1.f : 0.f;
// Force Move Jump, only jump if they're otherwise moving
if (stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceMoveJump) && isMoving)
movementSettings.mPosition[2] = onground ? 1 : 0;
movementSettings.mPosition[2] = onground ? 1.f : 0.f;
}
osg::Vec3f rot = cls.getRotationVector(mPtr);
@ -2036,7 +2037,7 @@ namespace MWMechanics
maxDelta = 1;
else if (std::abs(speedDelta) < deltaLen / 2)
// Turning is smooth for player and less smooth for NPCs (otherwise NPC can miss a path point).
maxDelta = duration * (isPlayer ? 1.0 / Settings::game().mSmoothMovementPlayerTurningDelay : 6.f);
maxDelta = duration * (isPlayer ? 1.0f / Settings::game().mSmoothMovementPlayerTurningDelay : 6.f);
else if (isPlayer && speedDelta < -deltaLen / 2)
// As soon as controls are released, mwinput switches player from running to walking.
// So stopping should be instant for player, otherwise it causes a small twitch.
@ -2094,7 +2095,7 @@ namespace MWMechanics
if (std::abs(delta) < osg::DegreesToRadians(20.0f))
mIsMovingBackward = vec.y() < 0;
float maxDelta = osg::PI * duration * (2.5f - cosDelta);
float maxDelta = osg::PIf * duration * (2.5f - cosDelta);
delta = std::clamp(delta, -maxDelta, maxDelta);
stats.setSideMovementAngle(stats.getSideMovementAngle() + delta);
effectiveRotation += delta;
@ -2520,7 +2521,7 @@ namespace MWMechanics
if (iter == mAnimQueue.begin() && mAnimation)
{
float complete;
size_t loopcount;
uint32_t loopcount;
mAnimation->getInfo(anim.mGroup, &complete, nullptr, &loopcount);
anim.mTime = complete;
anim.mLoopCount = loopcount;
@ -2542,24 +2543,23 @@ namespace MWMechanics
if (!state.mScriptedAnims.empty())
{
clearAnimQueue();
for (ESM::AnimationState::ScriptedAnimations::const_iterator iter = state.mScriptedAnims.begin();
iter != state.mScriptedAnims.end(); ++iter)
for (const ESM::AnimationState::ScriptedAnimation& animation : state.mScriptedAnims)
{
AnimationQueueEntry entry;
entry.mGroup = iter->mGroup;
entry.mLoopCount
= static_cast<uint32_t>(std::min<uint64_t>(iter->mLoopCount, std::numeric_limits<uint32_t>::max()));
entry.mGroup = animation.mGroup;
entry.mLoopCount = static_cast<uint32_t>(
std::min<uint64_t>(animation.mLoopCount, std::numeric_limits<uint32_t>::max()));
entry.mLooping = mAnimation->isLoopingAnimation(entry.mGroup);
entry.mScripted = true;
entry.mStartKey = "start";
entry.mStopKey = "stop";
entry.mSpeed = 1.f;
entry.mTime = iter->mTime;
if (iter->mAbsolute)
entry.mTime = animation.mTime;
if (animation.mAbsolute)
{
float start = mAnimation->getTextKeyTime(iter->mGroup + ": start");
float stop = mAnimation->getTextKeyTime(iter->mGroup + ": stop");
float time = std::clamp(iter->mTime, start, stop);
float start = mAnimation->getTextKeyTime(animation.mGroup + ": start");
float stop = mAnimation->getTextKeyTime(animation.mGroup + ": stop");
float time = std::clamp(animation.mTime, start, stop);
entry.mTime = (time - start) / (stop - start);
}
@ -3087,8 +3087,8 @@ namespace MWMechanics
if (!head)
return;
double zAngleRadians = 0.f;
double xAngleRadians = 0.f;
float zAngleRadians = 0.f;
float xAngleRadians = 0.f;
if (!mHeadTrackTarget.isEmpty())
{
@ -3122,14 +3122,15 @@ namespace MWMechanics
zAngleRadians
= std::atan2(actorDirection.x(), actorDirection.y()) - std::atan2(direction.x(), direction.y());
zAngleRadians = Misc::normalizeAngle(zAngleRadians - mAnimation->getHeadYaw()) + mAnimation->getHeadYaw();
zAngleRadians = static_cast<float>(
Misc::normalizeAngle(zAngleRadians - mAnimation->getHeadYaw()) + mAnimation->getHeadYaw());
zAngleRadians *= (1 - direction.z() * direction.z());
xAngleRadians = std::asin(direction.z());
}
const double xLimit = osg::DegreesToRadians(40.0);
const double zLimit = osg::DegreesToRadians(30.0);
double zLimitOffset = mAnimation->getUpperBodyYawRadians();
const float xLimit = osg::DegreesToRadians(40.f);
const float zLimit = osg::DegreesToRadians(30.f);
float zLimitOffset = mAnimation->getUpperBodyYawRadians();
xAngleRadians = std::clamp(xAngleRadians, -xLimit, xLimit);
zAngleRadians = std::clamp(zAngleRadians, -zLimit + zLimitOffset, zLimit + zLimitOffset);

View file

@ -12,7 +12,7 @@
namespace MWMechanics
{
template <class T>
void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value)
void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, unsigned char value)
{
T copy = *MWBase::Environment::get().getESMStore()->get<T>().find(id);
switch (setting)

View file

@ -50,9 +50,9 @@ namespace MWPhysics
btVector3 max;
shape->mCollisionShape->getAabb(transform, min, max);
mOriginalHalfExtents.x() = (max[0] - min[0]) / 2.f;
mOriginalHalfExtents.y() = (max[1] - min[1]) / 2.f;
mOriginalHalfExtents.z() = (max[2] - min[2]) / 2.f;
mOriginalHalfExtents.x() = static_cast<float>((max[0] - min[0]) / 2.f);
mOriginalHalfExtents.y() = static_cast<float>((max[1] - min[1]) / 2.f);
mOriginalHalfExtents.z() = static_cast<float>((max[2] - min[2]) / 2.f);
mMeshTranslation = osg::Vec3f(0.f, 0.f, mOriginalHalfExtents.z());
}

View file

@ -1223,7 +1223,7 @@ namespace MWRender
return false;
}
bool Animation::getInfo(std::string_view groupname, float* complete, float* speedmult, size_t* loopcount) const
bool Animation::getInfo(std::string_view groupname, float* complete, float* speedmult, uint32_t* loopcount) const
{
AnimStateMap::const_iterator iter = mStates.find(groupname);
if (iter == mStates.end())

View file

@ -411,7 +411,7 @@ namespace MWRender
* \return True if the animation is active, false otherwise.
*/
bool getInfo(std::string_view groupname, float* complete = nullptr, float* speedmult = nullptr,
size_t* loopcount = nullptr) const;
uint32_t* loopcount = nullptr) const;
/// Returns the group name of the animation currently active on that bone group.
std::string_view getActiveGroup(BoneGroup boneGroup) const;

View file

@ -93,8 +93,8 @@ namespace MWWorld
else
{
effect.mMagnitude = 0.f;
effect.mMinMagnitude = enam.mData.mMagnMin;
effect.mMaxMagnitude = enam.mData.mMagnMax;
effect.mMinMagnitude = static_cast<float>(enam.mData.mMagnMin);
effect.mMaxMagnitude = static_cast<float>(enam.mData.mMagnMax);
effect.mFlags = ESM::ActiveEffect::Flag_None;
}
params.mEffects.emplace_back(effect);
@ -106,7 +106,7 @@ namespace MWWorld
for (std::size_t i = 0; i < inventory.mItems.size(); ++i)
{
ESM::ObjectState& item = inventory.mItems[i];
auto slot = inventory.mEquipmentSlots.find(i);
auto slot = inventory.mEquipmentSlots.find(static_cast<uint32_t>(i));
if (slot != inventory.mEquipmentSlots.end())
{
MWBase::Environment::get().getWorldModel()->assignSaveFileRefNum(item.mRef);
@ -216,7 +216,7 @@ namespace MWWorld
dynamic.mMod = 0.f;
}
for (auto& setting : creatureStats.mAiSettings)
setting.mMod = 0.f;
setting.mMod = 0;
if (npcStats)
{
for (auto& skill : npcStats->mSkills)
@ -231,7 +231,7 @@ namespace MWWorld
for (auto& dynamic : creatureStats.mDynamic)
dynamic.mMod = 0.f;
for (auto& setting : creatureStats.mAiSettings)
setting.mMod = 0.f;
setting.mMod = 0;
}
// Versions 17-27 wrote an equipment slot index to mItem

View file

@ -68,9 +68,9 @@ namespace MWWorld
MWMechanics::NpcStats& stats = getPlayer().getClass().getNpcStats(getPlayer());
for (size_t i = 0; i < mSaveSkills.size(); ++i)
mSaveSkills[i] = stats.getSkill(ESM::Skill::indexToRefId(i)).getModified();
mSaveSkills[i] = stats.getSkill(ESM::Skill::indexToRefId(static_cast<int>(i))).getModified();
for (size_t i = 0; i < mSaveAttributes.size(); ++i)
mSaveAttributes[i] = stats.getAttribute(ESM::Attribute::indexToRefId(i)).getModified();
mSaveAttributes[i] = stats.getAttribute(ESM::Attribute::indexToRefId(static_cast<int>(i))).getModified();
}
void Player::restoreStats()
@ -83,13 +83,13 @@ namespace MWWorld
creatureStats.setHealth(health.getBase() / gmst.find("fWereWolfHealth")->mValue.getFloat());
for (size_t i = 0; i < mSaveSkills.size(); ++i)
{
auto& skill = npcStats.getSkill(ESM::Skill::indexToRefId(i));
auto& skill = npcStats.getSkill(ESM::Skill::indexToRefId(static_cast<int>(i)));
skill.restore(skill.getDamage());
skill.setModifier(mSaveSkills[i] - skill.getBase());
}
for (size_t i = 0; i < mSaveAttributes.size(); ++i)
{
auto id = ESM::Attribute::indexToRefId(i);
auto id = ESM::Attribute::indexToRefId(static_cast<int>(i));
auto attribute = npcStats.getAttribute(id);
attribute.restore(attribute.getDamage());
attribute.setModifier(mSaveAttributes[i] - attribute.getBase());

View file

@ -591,7 +591,7 @@ namespace Gui
// Underscore, use for NotDefined marker (used for glyphs not existing in the font)
additional.emplace(95, MyGUI::FontCodeType::NotDefined);
for (unsigned char i = 0; i < 256; i++)
for (unsigned i = 0; i < 256; i++)
{
float x1 = data[i].top_left.x * width;
float y1 = data[i].top_left.y * height;
@ -599,7 +599,7 @@ namespace Gui
float h = data[i].bottom_left.y * height - y1;
ToUTF8::Utf8Encoder encoder(mEncoding);
unsigned long unicodeVal = getUnicode(i, encoder, mEncoding);
unsigned long unicodeVal = getUnicode(static_cast<unsigned char>(i), encoder, mEncoding);
const std::string coord = MyGUI::utility::toString(x1) + " " + MyGUI::utility::toString(y1) + " "
+ MyGUI::utility::toString(w) + " " + MyGUI::utility::toString(h);
float advance = data[i].width + data[i].kerningRight;