mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
- one more unitialized memory crash (#1163)
- minor tweaks for hero handler
This commit is contained in:
parent
f05b398e5c
commit
c764ce6ebe
@ -84,9 +84,13 @@ class CFileCache
|
|||||||
std::copy(data, data + size, ret);
|
std::copy(data, data + size, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
FileData():
|
||||||
|
size(0),
|
||||||
|
data(nullptr)
|
||||||
|
{}
|
||||||
~FileData()
|
~FileData()
|
||||||
{
|
{
|
||||||
delete data;
|
delete [] data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -253,10 +253,9 @@ void CHeroHandler::loadHeroes()
|
|||||||
|
|
||||||
// Load heroes information
|
// Load heroes information
|
||||||
const JsonNode config(ResourceID("config/heroes.json"));
|
const JsonNode config(ResourceID("config/heroes.json"));
|
||||||
BOOST_FOREACH(const JsonNode &hero, config["heroes"].Vector()) {
|
BOOST_FOREACH(const JsonNode &hero, config["heroes"].Vector())
|
||||||
|
{
|
||||||
CHero * currentHero = heroes[hero["id"].Float()];
|
CHero * currentHero = heroes[hero["id"].Float()];
|
||||||
const JsonNode *value;
|
|
||||||
|
|
||||||
// sex: 0=male, 1=female
|
// sex: 0=male, 1=female
|
||||||
currentHero->sex = !!hero["female"].Bool();
|
currentHero->sex = !!hero["female"].Bool();
|
||||||
@ -268,9 +267,8 @@ void CHeroHandler::loadHeroes()
|
|||||||
currentHero->secSkillsInit.push_back(std::make_pair(skillID, skillLevel));
|
currentHero->secSkillsInit.push_back(std::make_pair(skillID, skillLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
value = &hero["spell"];
|
if (!hero["spell"].isNull()) {
|
||||||
if (!value->isNull()) {
|
currentHero->startingSpell = hero["spell"].Float();
|
||||||
currentHero->startingSpell = value->Float();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector())
|
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector())
|
||||||
@ -322,19 +320,7 @@ void CHeroHandler::loadBallistics()
|
|||||||
|
|
||||||
ui32 CHeroHandler::level (ui64 experience) const
|
ui32 CHeroHandler::level (ui64 experience) const
|
||||||
{
|
{
|
||||||
int i;
|
return boost::range::upper_bound(expPerLevel, experience) - boost::begin(expPerLevel);
|
||||||
if (experience <= expPerLevel.back())
|
|
||||||
{
|
|
||||||
for (i = expPerLevel.size()-1; experience < expPerLevel[i]; i--);
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = expPerLevel.size() - 1;
|
|
||||||
while (experience > reqExp (i))
|
|
||||||
i++;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui64 CHeroHandler::reqExp (ui32 level) const
|
ui64 CHeroHandler::reqExp (ui32 level) const
|
||||||
|
@ -142,7 +142,9 @@ public:
|
|||||||
|
|
||||||
class DLL_LINKAGE CHeroHandler
|
class DLL_LINKAGE CHeroHandler
|
||||||
{
|
{
|
||||||
std::vector<ui64> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
|
/// expPerLEvel[i] is amount of exp needed to reach level i;
|
||||||
|
/// consists of 201 values. Any higher levels require experience larger that ui64 can hold
|
||||||
|
std::vector<ui64> expPerLevel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CHeroClassHandler classes;
|
CHeroClassHandler classes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user