Преглед на файлове

ArtifactUtils::isSlotBackpack() func + refactoring

SoundSSGood преди 2 години
родител
ревизия
e6e669d024
променени са 5 файла, в които са добавени 15 реда и са изтрити 17 реда
  1. 3 7
      client/widgets/CArtifactHolder.cpp
  2. 6 1
      lib/CArtHandler.cpp
  3. 1 0
      lib/CArtHandler.h
  4. 4 6
      lib/NetPacksLib.cpp
  5. 1 3
      server/CGameHandler.cpp

+ 3 - 7
client/widgets/CArtifactHolder.cpp

@@ -208,11 +208,7 @@ bool CHeroArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition
 {
 	assert(art);
 	assert(hero);
-	bool assembleEqipped = true;
-	if(slot >= GameConstants::BACKPACK_START)
-	{
-		assembleEqipped = false;
-	}
+	bool assembleEqipped = !ArtifactUtils::isSlotBackpack(slot);
 	auto assemblyPossibilities = art->assemblyPossibilities(hero, assembleEqipped);
 
 	// If the artifact can be assembled, display dialog.
@@ -823,7 +819,7 @@ void CArtifactsOfHero::artifactUpdateSlots(const ArtifactLocation & al)
 {
 	if(al.isHolder(curHero))
 	{
-		if(al.slot >= GameConstants::BACKPACK_START)
+		if(ArtifactUtils::isSlotBackpack(al.slot))
 			updateBackpackSlots();
 		else
 			updateWornSlots();
@@ -841,7 +837,7 @@ void CArtifactsOfHero::updateWornSlots(bool redrawParent)
 
 void CArtifactsOfHero::updateBackpackSlots(bool redrawParent)
 {
-	for(auto * artPlace : backpack)
+	for(auto artPlace : backpack)
 		updateSlot(artPlace->slotID);
 	scrollBackpack(0);
 

+ 6 - 1
lib/CArtHandler.cpp

@@ -883,7 +883,7 @@ std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CA
 
 		for(const auto * constituent : *artifact->constituents) //check if all constituents are available
 		{
-			if (equipped)
+			if(equipped)
 			{
 				// Search for equipped arts
 				if (!h->hasArt(constituent->id, true, false, false))
@@ -1564,4 +1564,9 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he
 	return false;
 }
 
+DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(ArtifactPosition slot)
+{
+	return slot >= GameConstants::BACKPACK_START;
+}
+
 VCMI_LIB_NAMESPACE_END

+ 1 - 0
lib/CArtHandler.h

@@ -388,6 +388,7 @@ namespace ArtifactUtils
 	DLL_LINKAGE std::vector<ArtifactPosition> unmovablePositions(); // TODO: Make this constexpr when the toolset is upgraded
 	DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot);
 	DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot);
+	DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot);
 }
 
 VCMI_LIB_NAMESPACE_END

+ 4 - 6
lib/NetPacksLib.cpp

@@ -1089,7 +1089,7 @@ DLL_LINKAGE void EraseArtifact::applyGs(CGameState *gs)
 DLL_LINKAGE void MoveArtifact::applyGs(CGameState * gs)
 {
 	CArtifactInstance * art = src.getArt();
-	if(dst.slot < GameConstants::BACKPACK_START)
+	if(!ArtifactUtils::isSlotBackpack(dst.slot))
 		assert(!dst.getArt());
 
 	art->move(src, dst);
@@ -1114,7 +1114,7 @@ DLL_LINKAGE void BulkMoveArtifacts::applyGs(CGameState * gs)
 			// so all the following indices will be affected. Thus, we need to update
 			// the subsequent artifact slots to account for that
 			auto srcPos = slot.srcPos;
-			if((srcPos >= GameConstants::BACKPACK_START) && (operation != EBulkArtsOp::BULK_PUT))
+			if(ArtifactUtils::isSlotBackpack(srcPos) && (operation != EBulkArtsOp::BULK_PUT))
 			{
 				srcPos = ArtifactPosition(srcPos.num - numBackpackArtifactsMoved);
 			}
@@ -1170,9 +1170,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
 	CArtifactSet * artSet = al.getHolderArtSet();
 	const CArtifactInstance *transformedArt = al.getArt();
 	assert(transformedArt);
-	bool combineEquipped = true;
-	if(al.slot >= GameConstants::BACKPACK_START)
-		combineEquipped = false;
+	bool combineEquipped = !ArtifactUtils::isSlotBackpack(al.slot);
 	assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, combineEquipped), builtArt));
 	UNUSED(transformedArt);
 
@@ -1196,7 +1194,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
 		}
 		else
 		{
-			al.slot = std::min(al.slot, pos)
+			al.slot = std::min(al.slot, pos);
 		}
 	}
 

+ 1 - 3
server/CGameHandler.cpp

@@ -4036,9 +4036,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
 		CArtifact *combinedArt = VLC->arth->objects[assembleTo];
 		if(!combinedArt->constituents)
 			COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
-		bool combineEquipped = true;
-		if(artifactSlot >= GameConstants::BACKPACK_START)
-			combineEquipped = false;
+		bool combineEquipped = !ArtifactUtils::isSlotBackpack(artifactSlot);
 		if(!vstd::contains(destArtifact->assemblyPossibilities(hero, combineEquipped), combinedArt))
 			COMPLAIN_RET("assembleArtifacts: It's impossible to assemble requested artifact!");