2014-07-11 07:31:18 +02:00
|
|
|
#include "autocalcspell.hpp"
|
|
|
|
|
2015-08-21 22:41:31 +12:00
|
|
|
#include <limits>
|
2014-07-11 07:31:18 +02:00
|
|
|
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm/attr.hpp>
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
#include <components/esm/refid.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
|
|
|
#include <components/esm3/loadrace.hpp>
|
|
|
|
#include <components/esm3/loadspel.hpp>
|
|
|
|
|
2014-07-11 07:31:18 +02:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2020-04-26 20:46:51 +03:00
|
|
|
#include "spellutil.hpp"
|
2014-07-11 07:31:18 +02:00
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
|
|
|
struct SchoolCaps
|
|
|
|
{
|
|
|
|
int mCount;
|
|
|
|
int mLimit;
|
|
|
|
bool mReachedLimit;
|
|
|
|
int mMinCost;
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
ESM::RefId mWeakestSpell;
|
2014-07-11 07:31:18 +02:00
|
|
|
};
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
std::vector<ESM::RefId> autoCalcNpcSpells(const int* actorSkills, const int* actorAttributes, const ESM::Race* race)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
2018-08-29 18:38:12 +03:00
|
|
|
static const float fNPCbaseMagickaMult = gmst.find("fNPCbaseMagickaMult")->mValue.getFloat();
|
2014-07-11 07:31:18 +02:00
|
|
|
float baseMagicka = fNPCbaseMagickaMult * actorAttributes[ESM::Attribute::Intelligence];
|
|
|
|
|
|
|
|
static const std::string schools[]
|
|
|
|
= { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" };
|
|
|
|
static int iAutoSpellSchoolMax[6];
|
|
|
|
static bool init = false;
|
|
|
|
if (!init)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
{
|
|
|
|
const std::string& gmstName = "iAutoSpell" + schools[i] + "Max";
|
2018-08-29 18:38:12 +03:00
|
|
|
iAutoSpellSchoolMax[i] = gmst.find(gmstName)->mValue.getInteger();
|
2014-07-11 07:31:18 +02:00
|
|
|
}
|
|
|
|
init = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<int, SchoolCaps> schoolCaps;
|
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
{
|
|
|
|
SchoolCaps caps;
|
|
|
|
caps.mCount = 0;
|
|
|
|
caps.mLimit = iAutoSpellSchoolMax[i];
|
|
|
|
caps.mReachedLimit = iAutoSpellSchoolMax[i] <= 0;
|
2018-09-20 16:02:26 +04:00
|
|
|
caps.mMinCost = std::numeric_limits<int>::max();
|
2023-02-17 19:20:29 +01:00
|
|
|
caps.mWeakestSpell = ESM::RefId();
|
2014-07-11 07:31:18 +02:00
|
|
|
schoolCaps[i] = caps;
|
|
|
|
}
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
std::vector<ESM::RefId> selectedSpells;
|
2014-07-11 07:31:18 +02:00
|
|
|
|
|
|
|
const MWWorld::Store<ESM::Spell>& spells = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>();
|
2014-07-12 08:05:10 +02:00
|
|
|
|
|
|
|
// Note: the algorithm heavily depends on the traversal order of the spells. For vanilla-compatible results the
|
|
|
|
// Store must preserve the record ordering as it was in the content files.
|
2020-07-25 15:54:49 +04:00
|
|
|
for (const ESM::Spell& spell : spells)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
if (spell.mData.mType != ESM::Spell::ST_Spell)
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
2020-07-25 15:54:49 +04:00
|
|
|
if (!(spell.mData.mFlags & ESM::Spell::F_Autocalc))
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
2018-08-29 18:38:12 +03:00
|
|
|
static const int iAutoSpellTimesCanCast = gmst.find("iAutoSpellTimesCanCast")->mValue.getInteger();
|
2021-04-02 19:47:21 +02:00
|
|
|
int spellCost = MWMechanics::calcSpellCost(spell);
|
|
|
|
if (baseMagicka < iAutoSpellTimesCanCast * spellCost)
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
if (race && race->mPowers.exists(spell.mId))
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
if (!attrSkillCheck(&spell, actorSkills, actorAttributes))
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int school;
|
|
|
|
float skillTerm;
|
2020-07-25 15:54:49 +04:00
|
|
|
calcWeakestSchool(&spell, actorSkills, school, skillTerm);
|
2014-07-11 07:31:18 +02:00
|
|
|
assert(school >= 0 && school < 6);
|
|
|
|
SchoolCaps& cap = schoolCaps[school];
|
|
|
|
|
2021-04-02 19:47:21 +02:00
|
|
|
if (cap.mReachedLimit && spellCost <= cap.mMinCost)
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
|
|
|
|
2018-08-29 18:38:12 +03:00
|
|
|
static const float fAutoSpellChance = gmst.find("fAutoSpellChance")->mValue.getFloat();
|
2020-07-25 15:54:49 +04:00
|
|
|
if (calcAutoCastChance(&spell, actorSkills, actorAttributes, school) < fAutoSpellChance)
|
2014-07-11 07:31:18 +02:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
selectedSpells.push_back(spell.mId);
|
2014-07-11 07:31:18 +02:00
|
|
|
|
|
|
|
if (cap.mReachedLimit)
|
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
auto found = std::find(selectedSpells.begin(), selectedSpells.end(), cap.mWeakestSpell);
|
2014-07-12 08:05:10 +02:00
|
|
|
if (found != selectedSpells.end())
|
|
|
|
selectedSpells.erase(found);
|
2014-07-11 07:31:18 +02:00
|
|
|
|
2018-09-20 16:02:26 +04:00
|
|
|
cap.mMinCost = std::numeric_limits<int>::max();
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
for (const ESM::RefId& testSpellName : selectedSpells)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
const ESM::Spell* testSpell = spells.find(testSpellName);
|
2021-04-02 19:47:21 +02:00
|
|
|
int testSpellCost = MWMechanics::calcSpellCost(*testSpell);
|
2014-07-12 08:05:10 +02:00
|
|
|
|
|
|
|
// int testSchool;
|
|
|
|
// float dummySkillTerm;
|
|
|
|
// calcWeakestSchool(testSpell, actorSkills, testSchool, dummySkillTerm);
|
|
|
|
|
|
|
|
// Note: if there are multiple spells with the same cost, we pick the first one we found.
|
|
|
|
// So the algorithm depends on the iteration order of the outer loop.
|
|
|
|
if (
|
|
|
|
// There is a huge bug here. It is not checked that weakestSpell is of the correct school.
|
|
|
|
// As result multiple SchoolCaps could have the same mWeakestSpell. Erasing the weakest spell
|
|
|
|
// would then fail if another school already erased it, and so the number of spells would often
|
|
|
|
// exceed the sum of limits. This bug cannot be fixed without significantly changing the results
|
|
|
|
// of the spell autocalc, which will not have been playtested.
|
|
|
|
// testSchool == school &&
|
2021-04-02 19:47:21 +02:00
|
|
|
testSpellCost < cap.mMinCost)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
2021-04-02 19:47:21 +02:00
|
|
|
cap.mMinCost = testSpellCost;
|
2014-07-11 07:31:18 +02:00
|
|
|
cap.mWeakestSpell = testSpell->mId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cap.mCount += 1;
|
|
|
|
if (cap.mCount == cap.mLimit)
|
|
|
|
cap.mReachedLimit = true;
|
|
|
|
|
2021-04-02 19:47:21 +02:00
|
|
|
if (spellCost < cap.mMinCost)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
cap.mWeakestSpell = spell.mId;
|
2021-04-02 19:47:21 +02:00
|
|
|
cap.mMinCost = spellCost;
|
2014-07-11 07:31:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-12 08:05:10 +02:00
|
|
|
|
2014-07-11 07:31:18 +02:00
|
|
|
return selectedSpells;
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:26:55 +02:00
|
|
|
std::vector<ESM::RefId> autoCalcPlayerSpells(
|
|
|
|
const int* actorSkills, const int* actorAttributes, const ESM::Race* race)
|
2016-11-18 17:59:05 +01:00
|
|
|
{
|
|
|
|
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2018-08-29 18:38:12 +03:00
|
|
|
static const float fPCbaseMagickaMult
|
|
|
|
= esmStore.get<ESM::GameSetting>().find("fPCbaseMagickaMult")->mValue.getFloat();
|
2016-11-18 17:59:05 +01:00
|
|
|
|
|
|
|
float baseMagicka = fPCbaseMagickaMult * actorAttributes[ESM::Attribute::Intelligence];
|
|
|
|
bool reachedLimit = false;
|
2018-10-09 10:21:12 +04:00
|
|
|
const ESM::Spell* weakestSpell = nullptr;
|
2018-09-20 16:02:26 +04:00
|
|
|
int minCost = std::numeric_limits<int>::max();
|
2016-11-18 17:59:05 +01:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
std::vector<ESM::RefId> selectedSpells;
|
2016-11-18 17:59:05 +01:00
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
const MWWorld::Store<ESM::Spell>& spells = esmStore.get<ESM::Spell>();
|
|
|
|
for (const ESM::Spell& spell : spells)
|
2016-11-18 17:59:05 +01:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
if (spell.mData.mType != ESM::Spell::ST_Spell)
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
2020-07-25 15:54:49 +04:00
|
|
|
if (!(spell.mData.mFlags & ESM::Spell::F_PCStart))
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
2021-04-02 19:47:21 +02:00
|
|
|
|
|
|
|
int spellCost = MWMechanics::calcSpellCost(spell);
|
|
|
|
if (reachedLimit && spellCost <= minCost)
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
2020-07-25 15:54:49 +04:00
|
|
|
if (race
|
|
|
|
&& std::find(race->mPowers.mList.begin(), race->mPowers.mList.end(), spell.mId)
|
|
|
|
!= race->mPowers.mList.end())
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
2021-04-02 19:47:21 +02:00
|
|
|
if (baseMagicka < spellCost)
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
|
|
|
|
2018-08-29 18:38:12 +03:00
|
|
|
static const float fAutoPCSpellChance
|
|
|
|
= esmStore.get<ESM::GameSetting>().find("fAutoPCSpellChance")->mValue.getFloat();
|
2020-07-25 15:54:49 +04:00
|
|
|
if (calcAutoCastChance(&spell, actorSkills, actorAttributes, -1) < fAutoPCSpellChance)
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
if (!attrSkillCheck(&spell, actorSkills, actorAttributes))
|
2016-11-18 17:59:05 +01:00
|
|
|
continue;
|
|
|
|
|
2020-07-25 15:54:49 +04:00
|
|
|
selectedSpells.push_back(spell.mId);
|
2016-11-18 17:59:05 +01:00
|
|
|
|
|
|
|
if (reachedLimit)
|
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
std::vector<ESM::RefId>::iterator it
|
2016-11-18 17:59:05 +01:00
|
|
|
= std::find(selectedSpells.begin(), selectedSpells.end(), weakestSpell->mId);
|
|
|
|
if (it != selectedSpells.end())
|
|
|
|
selectedSpells.erase(it);
|
|
|
|
|
2018-09-20 16:02:26 +04:00
|
|
|
minCost = std::numeric_limits<int>::max();
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
for (const ESM::RefId& testSpellName : selectedSpells)
|
2016-11-18 17:59:05 +01:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
const ESM::Spell* testSpell = esmStore.get<ESM::Spell>().find(testSpellName);
|
2021-04-02 19:47:21 +02:00
|
|
|
int testSpellCost = MWMechanics::calcSpellCost(*testSpell);
|
|
|
|
if (testSpellCost < minCost)
|
2016-11-18 17:59:05 +01:00
|
|
|
{
|
2021-04-02 19:47:21 +02:00
|
|
|
minCost = testSpellCost;
|
2016-11-18 17:59:05 +01:00
|
|
|
weakestSpell = testSpell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-02 19:47:21 +02:00
|
|
|
if (spellCost < minCost)
|
2016-11-18 17:59:05 +01:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
weakestSpell = &spell;
|
2021-04-02 19:47:21 +02:00
|
|
|
minCost = MWMechanics::calcSpellCost(*weakestSpell);
|
2016-11-18 17:59:05 +01:00
|
|
|
}
|
2018-08-29 18:38:12 +03:00
|
|
|
static const unsigned int iAutoPCSpellMax
|
|
|
|
= esmStore.get<ESM::GameSetting>().find("iAutoPCSpellMax")->mValue.getInteger();
|
2016-11-18 17:59:05 +01:00
|
|
|
if (selectedSpells.size() == iAutoPCSpellMax)
|
|
|
|
reachedLimit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedSpells;
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:31:18 +02:00
|
|
|
bool attrSkillCheck(const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes)
|
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
for (const auto& spellEffect : spell->mEffects.mList)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
const ESM::MagicEffect* magicEffect
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(spellEffect.mEffectID);
|
2018-08-29 18:38:12 +03:00
|
|
|
static const int iAutoSpellAttSkillMin = MWBase::Environment::get()
|
|
|
|
.getWorld()
|
|
|
|
->getStore()
|
|
|
|
.get<ESM::GameSetting>()
|
|
|
|
.find("iAutoSpellAttSkillMin")
|
|
|
|
->mValue.getInteger();
|
2014-07-11 07:31:18 +02:00
|
|
|
|
|
|
|
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill))
|
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
assert(spellEffect.mSkill >= 0 && spellEffect.mSkill < ESM::Skill::Length);
|
|
|
|
if (actorSkills[spellEffect.mSkill] < iAutoSpellAttSkillMin)
|
2014-07-11 07:31:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute))
|
|
|
|
{
|
2020-07-25 15:54:49 +04:00
|
|
|
assert(spellEffect.mAttribute >= 0 && spellEffect.mAttribute < ESM::Attribute::Length);
|
|
|
|
if (actorAttributes[spellEffect.mAttribute] < iAutoSpellAttSkillMin)
|
2014-07-11 07:31:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void calcWeakestSchool(const ESM::Spell* spell, const int* actorSkills, int& effectiveSchool, float& skillTerm)
|
|
|
|
{
|
2017-06-30 16:27:18 +04:00
|
|
|
// Morrowind for some reason uses a formula slightly different from magicka cost calculation
|
2015-08-21 19:34:28 +12:00
|
|
|
float minChance = std::numeric_limits<float>::max();
|
2020-07-25 15:54:49 +04:00
|
|
|
for (const ESM::ENAMstruct& effect : spell->mEffects.mList)
|
2014-07-11 07:31:18 +02:00
|
|
|
{
|
|
|
|
const ESM::MagicEffect* magicEffect
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectID);
|
|
|
|
|
2017-06-30 16:27:18 +04:00
|
|
|
int minMagn = 1;
|
|
|
|
int maxMagn = 1;
|
|
|
|
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude))
|
|
|
|
{
|
|
|
|
minMagn = effect.mMagnMin;
|
|
|
|
maxMagn = effect.mMagnMax;
|
|
|
|
}
|
2014-07-11 07:31:18 +02:00
|
|
|
|
2017-06-30 16:27:18 +04:00
|
|
|
int duration = 0;
|
|
|
|
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration))
|
|
|
|
duration = effect.mDuration;
|
2020-05-23 23:12:56 +03:00
|
|
|
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::AppliedOnce))
|
|
|
|
duration = std::max(1, duration);
|
2017-06-30 16:27:18 +04:00
|
|
|
|
|
|
|
static const float fEffectCostMult = MWBase::Environment::get()
|
|
|
|
.getWorld()
|
|
|
|
->getStore()
|
2018-08-29 18:38:12 +03:00
|
|
|
.get<ESM::GameSetting>()
|
|
|
|
.find("fEffectCostMult")
|
|
|
|
->mValue.getFloat();
|
2017-06-30 16:27:18 +04:00
|
|
|
|
|
|
|
float x = 0.5 * (std::max(1, minMagn) + std::max(1, maxMagn));
|
|
|
|
x *= 0.1 * magicEffect->mData.mBaseCost;
|
|
|
|
x *= 1 + duration;
|
|
|
|
x += 0.05 * std::max(1, effect.mArea) * magicEffect->mData.mBaseCost;
|
2014-07-11 07:31:18 +02:00
|
|
|
x *= fEffectCostMult;
|
|
|
|
|
2017-06-30 16:27:18 +04:00
|
|
|
if (effect.mRange == ESM::RT_Target)
|
|
|
|
x *= 1.5f;
|
|
|
|
|
2019-01-03 00:31:59 +03:00
|
|
|
float s = 2.f * actorSkills[spellSchoolToSkill(magicEffect->mData.mSchool)];
|
2014-07-11 07:31:18 +02:00
|
|
|
if (s - x < minChance)
|
|
|
|
{
|
|
|
|
minChance = s - x;
|
|
|
|
effectiveSchool = magicEffect->mData.mSchool;
|
|
|
|
skillTerm = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float calcAutoCastChance(
|
|
|
|
const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes, int effectiveSchool)
|
|
|
|
{
|
|
|
|
if (spell->mData.mType != ESM::Spell::ST_Spell)
|
|
|
|
return 100.f;
|
|
|
|
|
|
|
|
if (spell->mData.mFlags & ESM::Spell::F_Always)
|
|
|
|
return 100.f;
|
|
|
|
|
2014-09-28 12:44:47 +02:00
|
|
|
float skillTerm = 0;
|
2014-07-11 07:31:18 +02:00
|
|
|
if (effectiveSchool != -1)
|
2019-01-03 00:31:59 +03:00
|
|
|
skillTerm = 2.f * actorSkills[spellSchoolToSkill(effectiveSchool)];
|
2014-07-11 07:31:18 +02:00
|
|
|
else
|
|
|
|
calcWeakestSchool(
|
|
|
|
spell, actorSkills, effectiveSchool, skillTerm); // Note effectiveSchool is unused after this
|
|
|
|
|
2021-04-02 19:47:21 +02:00
|
|
|
float castChance = skillTerm - MWMechanics::calcSpellCost(*spell)
|
|
|
|
+ 0.2f * actorAttributes[ESM::Attribute::Willpower] + 0.1f * actorAttributes[ESM::Attribute::Luck];
|
2014-07-11 07:31:18 +02:00
|
|
|
return castChance;
|
|
|
|
}
|
|
|
|
}
|