2
0
SoundSSGood 2 жил өмнө
parent
commit
fd9c7352a0

+ 3 - 3
client/widgets/CArtifactHolder.cpp

@@ -236,11 +236,11 @@ void CHeroArtPlace::addCombinedArtInfo(std::map<const CArtifact*, int> & arts)
 		text += "{" + combinedArt.first->getNameTranslated() + "}";
 		if(arts.size() == 1)
 		{
-			for(const auto part : *combinedArt.first->constituents)
+			for(const auto part : combinedArt.first->getConstituents())
 				artList += "\n" + part->getNameTranslated();
 		}
 		text += " (" + boost::str(boost::format("%d") % combinedArt.second) + " / " +
-			boost::str(boost::format("%d") % combinedArt.first->constituents->size()) + ")" + artList;
+			boost::str(boost::format("%d") % combinedArt.first->getConstituents().size()) + ")" + artList;
 	}
 }
 
@@ -292,7 +292,7 @@ bool ArtifactUtilsClient::askToDisassemble(const CGHeroInstance * hero, const Ar
 
 	if(art->isCombined())
 	{
-		if(ArtifactUtils::isSlotBackpack(slot) && !ArtifactUtils::isBackpackFreeSlots(hero, art->artType->constituents->size() - 1))
+		if(ArtifactUtils::isSlotBackpack(slot) && !ArtifactUtils::isBackpackFreeSlots(hero, art->artType->getConstituents().size() - 1))
 			return false;
 
 		LOCPLINT->showArtifactAssemblyDialog(

+ 1 - 1
client/widgets/CArtifactsOfHeroAltar.cpp

@@ -98,7 +98,7 @@ void CArtifactsOfHeroAltar::deleteFromVisible(const CArtifactInstance * artInst)
 	}
 	else
 	{
-		for(const auto & part : artInst->partsInfo)
+		for(const auto & part : artInst->getPartsInfo())
 		{
 			if(part.slot != ArtifactPosition::PRE_FIRST)
 				getArtPlace(part.slot)->setArtifact(nullptr);

+ 2 - 2
client/widgets/CArtifactsOfHeroBase.cpp

@@ -261,10 +261,10 @@ void CArtifactsOfHeroBase::setSlotData(ArtPlacePtr artPlace, const ArtifactPosit
 		{
 			// If the artifact is part of at least one combined artifact, add additional information
 			std::map<const CArtifact*, int> arts;
-			for(const auto combinedArt : slotInfo->artifact->artType->partOf)
+			for(const auto combinedArt : slotInfo->artifact->artType->getPartOf())
 			{
 				arts.insert(std::pair(combinedArt, 0));
-				for(const auto part : *combinedArt->constituents)
+				for(const auto part : combinedArt->getConstituents())
 					if(artSet.hasArt(part->getId(), true))
 						arts.at(combinedArt)++;
 			}

+ 5 - 5
lib/ArtifactUtils.cpp

@@ -123,12 +123,12 @@ DLL_LINKAGE std::vector<const CArtifact*> ArtifactUtils::assemblyPossibilities(
 	if(art->isCombined())
 		return arts;
 
-	for(const auto artifact : art->partOf)
+	for(const auto artifact : art->getPartOf())
 	{
 		assert(artifact->constituents);
 		bool possible = true;
 
-		for(const auto constituent : *artifact->constituents) //check if all constituents are available
+		for(const auto constituent : artifact->getConstituents()) //check if all constituents are available
 		{
 			if(equipped)
 			{
@@ -172,8 +172,8 @@ DLL_LINKAGE CArtifactInstance * ArtifactUtils::createNewArtifactInstance(CArtifa
 	if(art->isCombined())
 	{
 		assert(art->constituents);
-		for(const auto & part : *art->constituents)
-			artInst->addArtInstAsPart(ArtifactUtils::createNewArtifactInstance(part), ArtifactPosition::PRE_FIRST);
+		for(const auto & part : art->getConstituents())
+			artInst->addPart(ArtifactUtils::createNewArtifactInstance(part), ArtifactPosition::PRE_FIRST);
 	}
 	if(art->isGrowing())
 	{
@@ -211,7 +211,7 @@ DLL_LINKAGE CArtifactInstance * ArtifactUtils::createArtifact(CMap * map, const
 	map->addNewArtifactInstance(art);
 	if(art->artType && art->isCombined())
 	{
-		for(auto & part : art->partsInfo)
+		for(auto & part : art->getPartsInfo())
 		{
 			map->addNewArtifactInstance(part.art);
 		}

+ 48 - 9
lib/CArtHandler.cpp

@@ -48,7 +48,27 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 bool CCombinedArtifact::isCombined() const
 {
-	return !(constituents == nullptr);
+	return !(constituents.empty());
+}
+
+std::vector<CArtifact*> & CCombinedArtifact::getConstituents()
+{
+	return constituents;
+}
+
+const std::vector<CArtifact*> & CCombinedArtifact::getConstituents() const
+{
+	return constituents;
+}
+
+std::vector<CArtifact*> & CCombinedArtifact::getPartOf()
+{
+	return partOf;
+}
+
+const std::vector<CArtifact*> & CCombinedArtifact::getPartOf() const
+{
+	return partOf;
 }
 
 bool CScrollArtifact::isScroll() const
@@ -61,6 +81,26 @@ bool CGrowingArtifact::isGrowing() const
 	return !bonusesPerLevel.empty() || !thresholdBonuses.empty();
 }
 
+std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getBonusesPerLevel()
+{
+	return bonusesPerLevel;
+}
+
+const std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getBonusesPerLevel() const
+{
+	return bonusesPerLevel;
+}
+
+std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getThresholdBonuses()
+{
+	return thresholdBonuses;
+}
+
+const std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getThresholdBonuses() const
+{
+	return thresholdBonuses;
+}
+
 int32_t CArtifact::getIndex() const
 {
 	return id.toEnum();
@@ -180,7 +220,7 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b
 			if(assumeDestRemoved)
 				fittingSet.removeArtifact(slot);
 			assert(constituents);
-			for(const auto art : *constituents)
+			for(const auto art : constituents)
 			{
 				auto possibleSlot = ArtifactUtils::getArtAnyPosition(&fittingSet, art->getId());
 				if(ArtifactUtils::isSlotEquipment(possibleSlot))
@@ -557,14 +597,13 @@ void CArtHandler::loadComponents(CArtifact * art, const JsonNode & node)
 {
 	if (!node["components"].isNull())
 	{
-		art->constituents = std::make_unique<std::vector<CArtifact *>>();
 		for(const auto & component : node["components"].Vector())
 		{
 			VLC->modh->identifiers.requestIdentifier("artifact", component, [=](si32 id)
 			{
 				// when this code is called both combinational art as well as component are loaded
 				// so it is safe to access any of them
-				art->constituents->push_back(objects[id]);
+				art->constituents.push_back(objects[id]);
 				objects[id]->partOf.push_back(art);
 			});
 		}
@@ -655,7 +694,7 @@ bool CArtHandler::legalArtifact(const ArtifactID & id)
 	auto art = objects[id];
 	//assert ( (!art->constituents) || art->constituents->size() ); //artifacts is not combined or has some components
 
-	if(art->constituents)
+	if(art->isCombined())
 		return false; //no combo artifacts spawning
 
 	if(art->aClass < CArtifact::ART_TREASURE || art->aClass > CArtifact::ART_RELIC)
@@ -894,7 +933,7 @@ void CArtifactSet::putArtifact(ArtifactPosition slot, CArtifactInstance * art)
 	if(art->artType->isCombined() && ArtifactUtils::isSlotEquipment(slot))
 	{
 		const CArtifactInstance * mainPart = nullptr;
-		for(const auto & part : art->partsInfo)
+		for(const auto & part : art->getPartsInfo())
 			if(vstd::contains(part.art->artType->possibleSlots.at(bearerType()), slot)
 				&& (part.slot == ArtifactPosition::PRE_FIRST))
 			{
@@ -902,7 +941,7 @@ void CArtifactSet::putArtifact(ArtifactPosition slot, CArtifactInstance * art)
 				break;
 			}
 
-		for(auto & part : art->partsInfo)
+		for(auto & part : art->getPartsInfo())
 		{
 			if(part.art != mainPart)
 			{
@@ -923,7 +962,7 @@ void CArtifactSet::removeArtifact(ArtifactPosition slot)
 	{
 		if(art->isCombined())
 		{
-			for(auto & part : art->partsInfo)
+			for(auto & part : art->getPartsInfo())
 			{
 				if(getArt(part.slot, false))
 					eraseArtSlot(part.slot);
@@ -940,7 +979,7 @@ std::pair<const CArtifactInstance *, const CArtifactInstance *> CArtifactSet::se
 		auto art = slot.artifact;
 		if(art->isCombined())
 		{
-			for(auto& ci : art->partsInfo)
+			for(auto & ci : art->getPartsInfo())
 			{
 				if(ci.art->getTypeId() == aid)
 				{

+ 14 - 5
lib/CArtHandler.h

@@ -46,11 +46,15 @@ class DLL_LINKAGE CCombinedArtifact
 {
 protected:
 	CCombinedArtifact() = default;
-public:
-	std::unique_ptr<std::vector<CArtifact*>> constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
-	std::vector<CArtifact*> partOf; // Reverse map of constituents - combined arts that include this art
 
+	std::vector<CArtifact*> constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
+	std::vector<CArtifact*> partOf; // Reverse map of constituents - combined arts that include this art
+public:
 	bool isCombined() const;
+	std::vector<CArtifact*> & getConstituents();
+	const std::vector<CArtifact*> & getConstituents() const;
+	std::vector<CArtifact*> & getPartOf();
+	const std::vector<CArtifact*> & getPartOf() const;
 
 	template <typename Handler> void serialize(Handler & h, const int version)
 	{
@@ -71,12 +75,17 @@ class DLL_LINKAGE CGrowingArtifact
 {
 protected:
 	CGrowingArtifact() = default;
-public:
+
 	std::vector <std::pair<ui16, Bonus>> bonusesPerLevel; // Bonus given each n levels
 	std::vector <std::pair<ui16, Bonus>> thresholdBonuses; // After certain level they will be added once
-
+public:
 	bool isGrowing() const;
 
+	std::vector <std::pair<ui16, Bonus>> & getBonusesPerLevel();
+	const std::vector <std::pair<ui16, Bonus>> & getBonusesPerLevel() const;
+	std::vector <std::pair<ui16, Bonus>> & getThresholdBonuses();
+	const std::vector <std::pair<ui16, Bonus>> & getThresholdBonuses() const;
+
 	template <typename Handler> void serialize(Handler & h, const int version)
 	{
 		h & bonusesPerLevel;

+ 13 - 3
lib/CArtifactInstance.cpp

@@ -17,7 +17,7 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-void CCombinedArtifactInstance::addArtInstAsPart(CArtifactInstance * art, const ArtifactPosition & slot)
+void CCombinedArtifactInstance::addPart(CArtifactInstance * art, const ArtifactPosition & slot)
 {
 	auto artInst = static_cast<CArtifactInstance*>(this);
 	assert(vstd::contains_if(*artInst->artType->constituents,
@@ -44,6 +44,16 @@ bool CCombinedArtifactInstance::isPart(const CArtifactInstance * supposedPart) c
 	return false;
 }
 
+std::vector<CCombinedArtifactInstance::PartInfo> & CCombinedArtifactInstance::getPartsInfo()
+{
+	return partsInfo;
+}
+
+const std::vector<CCombinedArtifactInstance::PartInfo> & CCombinedArtifactInstance::getPartsInfo() const
+{
+	return partsInfo;
+}
+
 SpellID CScrollArtifactInstance::getScrollSpellID() const
 {
 	auto artInst = static_cast<const CArtifactInstance*>(this);
@@ -69,7 +79,7 @@ void CGrowingArtifactInstance::growingUp()
 		bonus->duration = BonusDuration::COMMANDER_KILLED;
 		artInst->accumulateBonus(bonus);
 
-		for(const auto & bonus : artInst->artType->bonusesPerLevel)
+		for(const auto & bonus : artInst->artType->getBonusesPerLevel())
 		{
 			// Every n levels
 			if(artInst->valOfBonuses(BonusType::LEVEL_COUNTER) % bonus.first == 0)
@@ -77,7 +87,7 @@ void CGrowingArtifactInstance::growingUp()
 				artInst->accumulateBonus(std::make_shared<Bonus>(bonus.second));
 			}
 		}
-		for(const auto & bonus : artInst->artType->thresholdBonuses)
+		for(const auto & bonus : artInst->artType->getThresholdBonuses())
 		{
 			// At n level
 			if(artInst->valOfBonuses(BonusType::LEVEL_COUNTER) == bonus.first)

+ 5 - 2
lib/CArtifactInstance.h

@@ -33,15 +33,18 @@ public:
 		PartInfo(CArtifactInstance * art = nullptr, const ArtifactPosition & slot = ArtifactPosition::PRE_FIRST)
 			: art(art), slot(slot) {};
 	};
-	std::vector<PartInfo> partsInfo;
-	void addArtInstAsPart(CArtifactInstance * art, const ArtifactPosition & slot);
+	void addPart(CArtifactInstance * art, const ArtifactPosition & slot);
 	// Checks if supposed part inst is part of this combined art inst
 	bool isPart(const CArtifactInstance * supposedPart) const;
+	std::vector<PartInfo> & getPartsInfo();
+	const std::vector<PartInfo> & getPartsInfo() const;
 
 	template <typename Handler> void serialize(Handler & h, const int version)
 	{
 		h & partsInfo;
 	}
+protected:
+	std::vector<PartInfo> partsInfo;
 };
 
 class DLL_LINKAGE CScrollArtifactInstance

+ 6 - 6
lib/NetPacksLib.cpp

@@ -1530,9 +1530,9 @@ void NewArtifact::applyGs(CGameState *gs)
 	art->setType(art->artType);
 	if(art->isCombined())
 	{
-		assert(art->artType->constituents);
-		for(const auto & part : *art->artType->constituents)
-			art->addArtInstAsPart(ArtifactUtils::createNewArtifactInstance(part), ArtifactPosition::PRE_FIRST);
+		assert(art->artType->getConstituents());
+		for(const auto & part : art->artType->getConstituents())
+			art->addPart(ArtifactUtils::createNewArtifactInstance(part), ArtifactPosition::PRE_FIRST);
 	}
 	gs->map->addNewArtifactInstance(art);
 }
@@ -1938,7 +1938,7 @@ void AssembledArtifact::applyGs(CGameState *gs)
 	auto * combinedArt = new CArtifactInstance(builtArt);
 	gs->map->addNewArtifactInstance(combinedArt);
 	// Retrieve all constituents
-	for(const CArtifact * constituent : *builtArt->constituents)
+	for(const CArtifact * constituent : builtArt->getConstituents())
 	{
 		ArtifactPosition pos = combineEquipped ? artSet->getArtPos(constituent->getId(), true, false) :
 			artSet->getArtBackpackPos(constituent->getId());
@@ -1960,7 +1960,7 @@ void AssembledArtifact::applyGs(CGameState *gs)
 			al.slot = std::min(al.slot, pos);
 			pos = ArtifactPosition::PRE_FIRST;
 		}
-		combinedArt->addArtInstAsPart(constituentInstance, pos);
+		combinedArt->addPart(constituentInstance, pos);
 	}
 
 	//put new combined artifacts
@@ -1972,7 +1972,7 @@ void DisassembledArtifact::applyGs(CGameState *gs)
 	auto * disassembled = al.getArt();
 	assert(disassembled);
 
-	auto parts = disassembled->partsInfo;
+	auto parts = disassembled->getPartsInfo();
 	disassembled->removeFrom(al);
 	for(auto & part : parts)
 	{

+ 2 - 2
lib/mapObjects/CQuest.cpp

@@ -153,7 +153,7 @@ bool CQuest::checkQuest(const CGHeroInstance * h) const
 				if(h->getArtPosCount(elem.first, false, true, true) < elem.second)
 					return false;
 				if(!h->hasArt(elem.first))
-					reqSlots += h->getAssemblyByConstituent(elem.first)->partsInfo.size() - 2;
+					reqSlots += h->getAssemblyByConstituent(elem.first)->getPartsInfo().size() - 2;
 			}
 			if(ArtifactUtils::isBackpackFreeSlots(h, reqSlots))
 				return true;
@@ -804,7 +804,7 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const
 					{
 						const auto * assembly = h->getAssemblyByConstituent(elem);
 						assert(assembly);
-						auto parts = assembly->partsInfo;
+						auto parts = assembly->getPartsInfo();
 
 						// Remove the assembly
 						cb->removeArtifact(ArtifactLocation(h, h->getArtPos(assembly)));

+ 1 - 1
lib/mapping/MapFormatH3M.cpp

@@ -746,7 +746,7 @@ void CMapLoaderH3M::readAllowedArtifacts()
 	if(!features.levelSOD)
 	{
 		for(CArtifact * artifact : VLC->arth->objects)
-			if(artifact->constituents)
+			if(artifact->isCombined())
 				map->allowedArtifact[artifact->getId()] = false;
 	}
 

+ 1 - 1
lib/rmg/CMapGenerator.cpp

@@ -118,7 +118,7 @@ void CMapGenerator::initQuestArtsRemaining()
 	for (auto art : VLC->arth->objects)
 	{
 		//Don't use parts of combined artifacts
-		if (art->aClass == CArtifact::ART_TREASURE && VLC->arth->legalArtifact(art->getId()) && art->partOf.empty())
+		if (art->aClass == CArtifact::ART_TREASURE && VLC->arth->legalArtifact(art->getId()) && art->getPartOf().empty())
 			questArtifacts.push_back(art->getId());
 	}
 }

+ 2 - 2
server/CGameHandler.cpp

@@ -4084,7 +4084,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
 	if(assemble)
 	{
 		CArtifact * combinedArt = VLC->arth->objects[assembleTo];
-		if(!combinedArt->constituents)
+		if(!combinedArt->isCombined())
 			COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
 		if (!vstd::contains(ArtifactUtils::assemblyPossibilities(hero, destArtifact->getTypeId(),
 			ArtifactUtils::isSlotEquipment(artifactSlot)), combinedArt))
@@ -4107,7 +4107,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
 			COMPLAIN_RET("assembleArtifacts: Artifact being attempted to disassemble is not a combined artifact!");
 
 		if(ArtifactUtils::isSlotBackpack(artifactSlot)
-			&& !ArtifactUtils::isBackpackFreeSlots(hero, destArtifact->artType->constituents->size() - 1))
+			&& !ArtifactUtils::isBackpackFreeSlots(hero, destArtifact->artType->getConstituents().size() - 1))
 			COMPLAIN_RET("assembleArtifacts: Artifact being attempted to disassemble but backpack is full!");
 
 		DisassembledArtifact da;