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

Artifacts can now have multiple types of bearers. Fixed problems with Commander arts impossible to wear.

This commit is contained in:
DjWarmonger 2013-01-16 07:37:51 +00:00
parent 0741639baf
commit a86b5c1e2e
2 changed files with 225 additions and 193 deletions

File diff suppressed because it is too large Load Diff

View File

@ -427,30 +427,36 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
} }
int bearerType = -1; int bearerType = -1;
bool heroArt = false;
{ {
auto it = artifactBearerMap.find (node["type"].String()); const JsonNode & bearer = node["type"];
if (it != artifactBearerMap.end()) BOOST_FOREACH (const JsonNode & b, bearer.Vector())
{ {
bearerType = it->second; auto it = artifactBearerMap.find (b.String());
switch (bearerType) if (it != artifactBearerMap.end())
{ {
case ArtBearer::HERO: //TODO: allow arts having several possible bearers bearerType = it->second;
break; switch (bearerType)
case ArtBearer::COMMANDER: {
makeItCommanderArt (art, false); //do not erase already existing slots case ArtBearer::HERO: //TODO: allow arts having several possible bearers
break; heroArt = true;
case ArtBearer::CREATURE: break;
makeItCreatureArt (art, false); case ArtBearer::COMMANDER:
break; makeItCommanderArt (art, false); //do not erase already existing slots
break;
case ArtBearer::CREATURE:
makeItCreatureArt (art, false);
break;
}
} }
else
tlog2 << "Warning! Artifact type " << b.String() << " not recognized!";
} }
else
tlog2 << "Warning! Artifact type " << value->String() << " not recognized!";
} }
value = &node["slot"]; value = &node["slot"];
if (!value->isNull() && bearerType == ArtBearer::HERO) //we assume non-hero slots are irrelevant? if (!value->isNull() && heroArt) //we assume non-hero slots are irrelevant?
{ {
std::string slotName = value->String(); std::string slotName = value->String();
if (slotName == "MISC") if (slotName == "MISC")
@ -709,11 +715,27 @@ void CArtHandler::addBonuses()
bonus->sid = ga->id; bonus->sid = ga->id;
ga->addNewBonus (bonus); ga->addNewBonus (bonus);
} }
if(artifact.second["type"].String() == "Creature") BOOST_FOREACH (const JsonNode & b, artifact.second["type"].Vector()) //TODO: remove duplicate code
makeItCreatureArt(ga->id); {
else if(artifact.second["type"].String() == "Commander") auto it = artifactBearerMap.find (b.String());
makeItCommanderArt(ga->id); if (it != artifactBearerMap.end())
{
int bearerType = it->second;
switch (bearerType)
{
case ArtBearer::HERO:
break;
case ArtBearer::COMMANDER:
makeItCommanderArt (ga); //original artifacts should have only one bearer type
break;
case ArtBearer::CREATURE:
makeItCreatureArt (ga);
break;
}
}
else
tlog2 << "Warning! Artifact type " << b.String() << " not recognized!";
}
readComponents (artifact.second, ga); readComponents (artifact.second, ga);
VLC->modh->identifiers.registerObject ("artifact." + artifact.first, ga->id); VLC->modh->identifiers.registerObject ("artifact." + artifact.first, ga->id);