1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Fixed Artifact parser. Check http://forum.vcmi.eu/viewtopic.php?p=7889#7889 for example mod.

This commit is contained in:
DjWarmonger 2012-12-14 08:37:46 +00:00
parent a8175c13bd
commit afe3f77a59
2 changed files with 59 additions and 28 deletions

View File

@ -24,7 +24,7 @@ using namespace boost::assign;
extern boost::rand48 ran;
const std::map<std::string, int> artRarityMap = boost::assign::map_list_of
const std::map<std::string, CArtifact::EartClass> artifactClassMap = boost::assign::map_list_of
("TREASURE", CArtifact::ART_TREASURE)
("MINOR", CArtifact::ART_MINOR)
("MAJOR", CArtifact::ART_MAJOR)
@ -168,6 +168,9 @@ bool CArtifact::isBig () const
CArtifact::CArtifact()
{
setNodeType(ARTIFACT);
possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
possibleSlots[ArtBearer::COMMANDER];
}
CArtifact::~CArtifact()
@ -313,10 +316,6 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
nart.price= parser.readNumber();
nart.possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
nart.possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
nart.possibleSlots[ArtBearer::COMMANDER];
for(int j=0;j<slots.size();j++)
{
if(parser.readString() == "x")
@ -468,7 +467,7 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
const JsonNode & text = node["text"];
art->setName (text["name"].String());
art->setDescription (text["description"].String());
art->setName (text["event"].String());
art->setEventText (text["event"].String());
const JsonNode & graphics = node["graphics"];
art->iconIndex = graphics["iconIndex"].Float();
@ -478,40 +477,68 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
art->large = value->String();
art->price = node["value"].Float();
{
auto it = artifactClassMap.find (node["class"].String());
if (it != artifactClassMap.end())
{
art->aClass = it->second;
}
else
{
tlog2 << "Warning! Artifact rarity " << value->String() << " not recognized!";
art->aClass = CArtifact::ART_SPECIAL;
}
}
int bearerType = -1;
// FIXME FIXME FIXME: value is unitialized = crash!
auto it = artifactBearerMap.find (value->String());
if (it != artifactPositionMap.end())
{
bearerType = it->second;
switch (bearerType)
auto it = artifactBearerMap.find (node["type"].String());
if (it != artifactBearerMap.end())
{
case ArtBearer::HERO: //TODO: allow arts having several possible bearers
break;
case ArtBearer::COMMANDER:
makeItCommanderArt(art->id); //TODO: when id is deduced?
break;
case ArtBearer::CREATURE:
makeItCreatureArt(art->id);
break;
bearerType = it->second;
switch (bearerType)
{
case ArtBearer::HERO: //TODO: allow arts having several possible bearers
break;
case ArtBearer::COMMANDER:
makeItCommanderArt(art->id); //TODO: when id is deduced?
break;
case ArtBearer::CREATURE:
makeItCreatureArt(art->id);
break;
}
}
else
tlog2 << "Warning! Artifact type " << value->String() << " not recognized!";
}
else
tlog2 << "Warning! Artifact type " << value->String() << " not recognized!";
value = &node["slot"];
if (!value->isNull() && bearerType == ArtBearer::HERO) //we assume non-hero slots are irrelevant?
{
auto it = artifactPositionMap.find (value->String());
if (it != artifactPositionMap.end())
std::string slotName = value->String();
if (slotName == "MISC")
{
auto slot = it->second;
art->possibleSlots[ArtBearer::HERO].push_back (slot);
//unfortunatelly slot ids aare not continuous
art->possibleSlots[ArtBearer::HERO] += ArtifactPosition::MISC1, ArtifactPosition::MISC2, ArtifactPosition::MISC3, ArtifactPosition::MISC4, ArtifactPosition::MISC5;
}
else if (slotName == "RING")
{
art->possibleSlots[ArtBearer::HERO] += ArtifactPosition::LEFT_RING, ArtifactPosition::RIGHT_RING;
}
else
tlog2 << "Warning! Artifact slot " << value->String() << " not recognized!";
{
auto it = artifactPositionMap.find (slotName);
if (it != artifactPositionMap.end())
{
auto slot = it->second;
art->possibleSlots[ArtBearer::HERO].push_back (slot);
}
else
tlog2 << "Warning! Artifact slot " << value->String() << " not recognized!";
}
}
BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector())
@ -771,6 +798,10 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
allowedArtifacts.push_back(artifacts[i]);
}
}
for (int i = GameConstants::ARTIFACTS_QUANTITY; i < artifacts.size(); ++i) //allow all new artifacts by default
{
allowedArtifacts.push_back(artifacts[i]);
}
}
CArtifactInstance::CArtifactInstance()

View File

@ -531,8 +531,8 @@ void CMapLoaderH3M::readDisposedHeroes()
void CMapLoaderH3M::readAllowedArtifacts()
{
map->allowedArtifact.resize(GameConstants::ARTIFACTS_QUANTITY);
for(ui32 x = 0; x < map->allowedArtifact.size(); x++)
map->allowedArtifact.resize (VLC->arth->artifacts.size()); //handle new artifacts, make them allowed by default
for (ui32 x = 0; x < map->allowedArtifact.size(); ++x)
{
map->allowedArtifact[x] = true;
}