diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 9373f5ad5..44e7f101e 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -437,10 +437,10 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node) case ArtBearer::HERO: //TODO: allow arts having several possible bearers break; case ArtBearer::COMMANDER: - makeItCommanderArt(art->id); //TODO: when id is deduced? + makeItCommanderArt (art, false); //do not erase already existing slots break; case ArtBearer::CREATURE: - makeItCreatureArt(art->id); + makeItCreatureArt (art, false); break; } } @@ -475,6 +475,8 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node) } } + readComponents (node, art); + BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector()) { auto b = JsonUtils::parseBonus(bonus); @@ -660,10 +662,8 @@ void CArtHandler::giveArtBonus(TArtifactID aid, Bonus *bonus) artifacts[aid]->addNewBonus(bonus); } - -void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/) +void CArtHandler::makeItCreatureArt (CArtifact * a, bool onlyCreature /*=true*/) { - CArtifact *a = artifacts[aid]; if (onlyCreature) { a->possibleSlots[ArtBearer::HERO].clear(); @@ -672,9 +672,14 @@ void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT); } -void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ ) +void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/) { CArtifact *a = artifacts[aid]; + makeItCreatureArt (a, onlyCreature); +} + +void CArtHandler::makeItCommanderArt (CArtifact * a, bool onlyCommander /*= true*/ ) +{ if (onlyCommander) { a->possibleSlots[ArtBearer::HERO].clear(); @@ -684,6 +689,12 @@ void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommande a->possibleSlots[ArtBearer::COMMANDER].push_back(i); } +void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ ) +{ + CArtifact *a = artifacts[aid]; + makeItCommanderArt (a, onlyCommander); +} + void CArtHandler::addBonuses() { const JsonNode config(ResourceID("config/artifacts.json")); @@ -702,23 +713,29 @@ void CArtHandler::addBonuses() else if(artifact.second["type"].String() == "Commander") makeItCommanderArt(ga->id); - const JsonNode *value; - value = &artifact.second["components"]; - if (!value->isNull()) - { - ga->constituents = new std::vector(); - BOOST_FOREACH (auto component, value->Vector()) - { - VLC->modh->identifiers.requestIdentifier(std::string("artifact.") + component.String(), - boost::bind (&CArtifact::addConstituent, ga, _1) - ); - } - } + readComponents (artifact.second, ga); VLC->modh->identifiers.registerObject ("artifact." + artifact.first, ga->id); } } +void CArtHandler::readComponents (const JsonNode & node, CArtifact * art) +{ + const JsonNode *value; + value = &node["components"]; + if (!value->isNull()) + { + art->constituents = new std::vector(); + BOOST_FOREACH (auto component, value->Vector()) + { + VLC->modh->identifiers.requestIdentifier(std::string("artifact.") + component.String(), + boost::bind (&CArtifact::addConstituent, art, _1) + ); + } + } + +} + void CArtHandler::clear() { BOOST_FOREACH(CArtifact *art, artifacts) @@ -755,7 +772,15 @@ void CArtHandler::initAllowedArtifactsList(const std::vector &allowed) } for (int i = GameConstants::ARTIFACTS_QUANTITY; i < artifacts.size(); ++i) //allow all new artifacts by default { - allowedArtifacts.push_back(artifacts[i]); + if (artifacts[i]->possibleSlots[ArtBearer::HERO].size()) + allowedArtifacts.push_back(artifacts[i]); + else //check if active modules allow artifact to be every used + { + if (artifacts[i]->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS || + artifacts[i]->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT) + allowedArtifacts.push_back(artifacts[i]); + //keep im mind that artifact can be worn by more than one type of bearer + } } } diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 69859eb7c..15ee1e854 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -234,6 +234,8 @@ public: void load(const JsonNode & node); /// load one artifact from json config CArtifact * loadArtifact(const JsonNode & node); + ///read (optional) components of combined artifact + void readComponents (const JsonNode & node, CArtifact * art); void sortArts(); void addBonuses(); @@ -247,7 +249,9 @@ public: bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();} void initAllowedArtifactsList(const std::vector &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed static int convertMachineID(int id, bool creToArt); + void makeItCreatureArt (CArtifact * a, bool onlyCreature = true); void makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature = true); + void makeItCommanderArt (CArtifact * a, bool onlyCommander = true); void makeItCommanderArt (TArtifactInstanceID aid, bool onlyCommander = true); CArtHandler(); ~CArtHandler();