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

- fixed crash on missing icons

- proper ID resolution for secondary skills to avoid #1258
This commit is contained in:
Ivan Savenko 2013-04-23 09:16:20 +00:00
parent c9bbf7dfd5
commit e71bace8e3
3 changed files with 33 additions and 18 deletions

View File

@ -934,6 +934,8 @@ bool CAnimation::loadFrame(CDefFile * file, size_t frame, size_t group)
//try to get image from def //try to get image from def
if (source[group][frame].getType() == JsonNode::DATA_NULL) if (source[group][frame].getType() == JsonNode::DATA_NULL)
{
if (file)
{ {
auto frameList = file->getEntries(); auto frameList = file->getEntries();
@ -943,14 +945,14 @@ bool CAnimation::loadFrame(CDefFile * file, size_t frame, size_t group)
images[group][frame] = new CompImage(file, frame, group); images[group][frame] = new CompImage(file, frame, group);
else else
images[group][frame] = new SDLImage(file, frame, group); images[group][frame] = new SDLImage(file, frame, group);
return true;
} }
else // missing image }
{ // still here? image is missing
printError(frame, group, "LoadFrame"); printError(frame, group, "LoadFrame");
images[group][frame] = new SDLImage("DEFAULT", compressed); images[group][frame] = new SDLImage("DEFAULT", compressed);
} }
}
else //load from separate file else //load from separate file
{ {
std::string filename = source[group][frame].Struct().find("file")->second.String(); std::string filename = source[group][frame].Struct().find("file")->second.String();

View File

@ -272,11 +272,21 @@ void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node)
{ {
BOOST_FOREACH(const JsonNode &set, node["skills"].Vector()) BOOST_FOREACH(const JsonNode &set, node["skills"].Vector())
{ {
SecondarySkill skillID = SecondarySkill(
boost::range::find(NSecondarySkill::names, set["skill"].String()) - boost::begin(NSecondarySkill::names));
int skillLevel = boost::range::find(NSecondarySkill::levels, set["level"].String()) - boost::begin(NSecondarySkill::levels); int skillLevel = boost::range::find(NSecondarySkill::levels, set["level"].String()) - boost::begin(NSecondarySkill::levels);
if (skillLevel < SecSkillLevel::LEVELS_SIZE)
{
size_t currentIndex = hero->secSkillsInit.size();
hero->secSkillsInit.push_back(std::make_pair(-1, skillLevel));
hero->secSkillsInit.push_back(std::make_pair(skillID, skillLevel)); VLC->modh->identifiers.requestIdentifier("skill." + set["skill"].String(), [=](si32 id)
{
hero->secSkillsInit[currentIndex].first = SecondarySkill(id);
});
}
else
{
logGlobal->errorStream() << "Unknown skill level: " <<set["level"].String();
}
} }
// spellbook is considered present if hero have "spellbook" entry even when this is an empty set (0 spells) // spellbook is considered present if hero have "spellbook" entry even when this is an empty set (0 spells)

View File

@ -257,9 +257,11 @@ public:
PATHFINDING = 0, ARCHERY, LOGISTICS, SCOUTING, DIPLOMACY, NAVIGATION, LEADERSHIP, WISDOM, MYSTICISM, PATHFINDING = 0, ARCHERY, LOGISTICS, SCOUTING, DIPLOMACY, NAVIGATION, LEADERSHIP, WISDOM, MYSTICISM,
LUCK, BALLISTICS, EAGLE_EYE, NECROMANCY, ESTATES, FIRE_MAGIC, AIR_MAGIC, WATER_MAGIC, EARTH_MAGIC, LUCK, BALLISTICS, EAGLE_EYE, NECROMANCY, ESTATES, FIRE_MAGIC, AIR_MAGIC, WATER_MAGIC, EARTH_MAGIC,
SCHOLAR, TACTICS, ARTILLERY, LEARNING, OFFENCE, ARMORER, INTELLIGENCE, SORCERY, RESISTANCE, SCHOLAR, TACTICS, ARTILLERY, LEARNING, OFFENCE, ARMORER, INTELLIGENCE, SORCERY, RESISTANCE,
FIRST_AID FIRST_AID, SKILL_SIZE
}; };
static_assert(GameConstants::SKILL_QUANTITY == SKILL_SIZE, "Incorrect number of skills");
SecondarySkill(ESecondarySkill _num = WRONG) : num(_num) SecondarySkill(ESecondarySkill _num = WRONG) : num(_num)
{} {}
@ -601,7 +603,8 @@ namespace SecSkillLevel
NONE, NONE,
BASIC, BASIC,
ADVANCED, ADVANCED,
EXPERT EXPERT,
LEVELS_SIZE
}; };
} }