Browse Source

Fixed Commander artifacts management, including #968.

DjWarmonger 13 năm trước cách đây
mục cha
commit
e0135ab6a6
3 tập tin đã thay đổi với 21 bổ sung10 xóa
  1. 7 1
      client/CCreatureWindow.cpp
  2. 13 8
      client/CHeroWindow.cpp
  3. 1 1
      lib/CArtHandler.h

+ 7 - 1
client/CCreatureWindow.cpp

@@ -533,7 +533,13 @@ void CCreatureWindow::passArtifactToHero()
 
 void CCreatureWindow::artifactRemoved (const ArtifactLocation &artLoc)
 {
-	//TODO: align artifacts to remove holes
+	//align artifacts to remove holes
+	BOOST_FOREACH (auto al, stack->artifactsWorn)
+	{
+		int freeSlot = al.second.artifact->firstAvailableSlot(stack); 
+		if (freeSlot < al.first)
+			LOCPLINT->cb->swapArtifacts (ArtifactLocation(stack, al.first), ArtifactLocation(stack, freeSlot));
+	}
 	int size = stack->artifactsWorn.size();
 	displayedArtifact  =  size ? (displayedArtifact % size) : ArtifactPosition::CREATURE_SLOT; //0
 	setArt (stack->getArt(displayedArtifact));

+ 13 - 8
client/CHeroWindow.cpp

@@ -312,15 +312,20 @@ void CHeroWindow::commanderWindow()
 	{
 		const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();
 		artSelected = true;
-		ArtifactLocation src (srcHero, commonInfo->src.slotID);
-		ArtifactLocation dst (curHero->commander.get(), art->firstAvailableSlot (curHero->commander));
-		if (art->canBePutAt(dst, true))
-		{	//equip clicked stack
-			if(dst.getArt())
-			{
-				LOCPLINT->cb->swapArtifacts (dst, ArtifactLocation(srcHero, dst.getArt()->firstBackpackSlot(srcHero)));
+		int freeSlot = art->firstAvailableSlot (curHero->commander);
+		if (freeSlot < ArtifactPosition::COMMANDER_AFTER_LAST) //we don't want to put it in commander's backpack!
+		{
+			ArtifactLocation src (srcHero, commonInfo->src.slotID);
+			ArtifactLocation dst (curHero->commander.get(), freeSlot);
+
+			if (art->canBePutAt(dst, true))
+			{	//equip clicked stack
+				if(dst.getArt())
+				{
+					LOCPLINT->cb->swapArtifacts (dst, ArtifactLocation(srcHero, dst.getArt()->firstBackpackSlot(srcHero)));
+				}
+				LOCPLINT->cb->swapArtifacts(src, dst);
 			}
-			LOCPLINT->cb->swapArtifacts(src, dst);
 		}
 	}
 	else

+ 1 - 1
lib/CArtHandler.h

@@ -29,7 +29,7 @@ namespace ArtifactPosition
 		AFTER_LAST,
 		//cres
 		CREATURE_SLOT = 0,
-		COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6
+		COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6, COMMANDER_AFTER_LAST
 	};
 }