diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 64bbe63d7..c6c4b0e6f 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -625,7 +625,7 @@ void CArtHandler::makeItCommanderArt(CArtifact * a, bool onlyCommander) a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(slot)); } -bool CArtHandler::legalArtifact(const ArtifactID & id) +bool CArtHandler::legalArtifact(const ArtifactID & id) const { auto art = id.toArtifact(); //assert ( (!art->constituents) || art->constituents->size() ); //artifacts is not combined or has some components @@ -648,18 +648,6 @@ bool CArtHandler::legalArtifact(const ArtifactID & id) return false; } -void CArtHandler::initAllowedArtifactsList(const std::set & allowed) -{ - allowedArtifacts.clear(); - - for (ArtifactID i : allowed) - { - if (legalArtifact(ArtifactID(i))) - allowedArtifacts.push_back(i.toArtifact()); - //keep im mind that artifact can be worn by more than one type of bearer - } -} - std::set CArtHandler::getDefaultAllowed() const { std::set allowedArtifacts; diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 957d2b1c5..065ebefd7 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -141,15 +141,11 @@ public: class DLL_LINKAGE CArtHandler : public CHandlerBase { public: - /// List of artifacts allowed on the map - std::vector allowedArtifacts; - void addBonuses(CArtifact *art, const JsonNode &bonusList); static CArtifact::EartClass stringToClass(const std::string & className); //TODO: rework EartClass to make this a constructor - bool legalArtifact(const ArtifactID & id); - void initAllowedArtifactsList(const std::set & allowed); + bool legalArtifact(const ArtifactID & id) const; static void makeItCreatureArt(CArtifact * a, bool onlyCreature = true); static void makeItCommanderArt(CArtifact * a, bool onlyCommander = true); diff --git a/lib/JsonRandom.cpp b/lib/JsonRandom.cpp index f99a678fb..ca068c973 100644 --- a/lib/JsonRandom.cpp +++ b/lib/JsonRandom.cpp @@ -384,8 +384,9 @@ namespace JsonRandom ArtifactID loadArtifact(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) { std::set allowedArts; - for (auto const * artifact : VLC->arth->allowedArtifacts) - allowedArts.insert(artifact->getId()); + for(const auto & artifact : VLC->arth->objects) + if (IObjectInterface::cb->isAllowed(artifact->getId()) && VLC->arth->legalArtifact(artifact->getId())) + allowedArts.insert(artifact->getId()); std::set potentialPicks = filterKeys(value, allowedArts, variables); diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 5d49b350e..089d4aced 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -195,7 +195,6 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog logGlobal->error("Wrong mode: %d", static_cast(scenarioOps->mode)); return; } - VLC->arth->initAllowedArtifactsList(map->allowedArtifact); logGlobal->info("Map loaded!"); checkMapChecksum(); @@ -1947,8 +1946,13 @@ ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, int flags, st std::set potentialPicks; // Select artifacts that satisfy provided criterias - for (auto const * artifact : VLC->arth->allowedArtifacts) + for (auto const & artifactID : map->allowedArtifact) { + if (!VLC->arth->legalArtifact(artifactID)) + continue; + + auto const * artifact = artifactID.toArtifact(); + assert(artifact->aClass != CArtifact::ART_SPECIAL); // should be filtered out when allowedArtifacts is initialized if ((flags & CArtifact::ART_TREASURE) == 0 && artifact->aClass == CArtifact::ART_TREASURE)