1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- one more unitialized memory crash (#1163)

- minor tweaks for hero handler
This commit is contained in:
Ivan Savenko 2012-12-15 13:40:22 +00:00
parent f05b398e5c
commit c764ce6ebe
3 changed files with 13 additions and 21 deletions

View File

@ -84,9 +84,13 @@ class CFileCache
std::copy(data, data + size, ret);
return ret;
}
FileData():
size(0),
data(nullptr)
{}
~FileData()
{
delete data;
delete [] data;
}
};

View File

@ -253,10 +253,9 @@ void CHeroHandler::loadHeroes()
// Load heroes information
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()];
const JsonNode *value;
// sex: 0=male, 1=female
currentHero->sex = !!hero["female"].Bool();
@ -268,9 +267,8 @@ void CHeroHandler::loadHeroes()
currentHero->secSkillsInit.push_back(std::make_pair(skillID, skillLevel));
}
value = &hero["spell"];
if (!value->isNull()) {
currentHero->startingSpell = value->Float();
if (!hero["spell"].isNull()) {
currentHero->startingSpell = hero["spell"].Float();
}
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector())
@ -322,19 +320,7 @@ void CHeroHandler::loadBallistics()
ui32 CHeroHandler::level (ui64 experience) const
{
int i;
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;
}
return boost::range::upper_bound(expPerLevel, experience) - boost::begin(expPerLevel);
}
ui64 CHeroHandler::reqExp (ui32 level) const

View File

@ -142,7 +142,9 @@ public:
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:
CHeroClassHandler classes;