Browse Source

* fixed calling heroBonusChanged when artifact is unequipped; please fix hero screen without const_casts on hero (no mechanically important variable should be changed locally)

mateuszb 15 years ago
parent
commit
0ebad5bed6
2 changed files with 21 additions and 21 deletions
  1. 20 20
      client/GUIClasses.cpp
  2. 1 1
      client/GUIClasses.h

+ 20 - 20
client/GUIClasses.cpp

@@ -3664,7 +3664,7 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
 				ourOwner->commonInfo->destArtifact = ourArt;
 
 				// Special case when the dest artifact can't be fit into the src slot.
-				CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
+				//CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
 				const CArtifactsOfHero* srcAOH = ourOwner->commonInfo->srcAOH;
 				ui16 srcSlotID = ourOwner->commonInfo->srcSlotID;
 				if (ourArt && srcSlotID < 19 && !ourArt->fitsAt(srcAOH->curHero->artifWorn, srcSlotID)) {
@@ -3755,12 +3755,12 @@ void CArtPlace::select ()
 	ourOwner->commonInfo->srcAOH = ourOwner;
 
 	// Temporarily remove artifact from hero.
-	if (slotID < 19)
-		CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
-	else
-		ourOwner->curHero->artifacts.erase(ourOwner->curHero->artifacts.begin() + (slotID - 19));
-	ourOwner->markPossibleSlots(ourArt);
-	ourOwner->curHero->recreateArtBonuses();
+	//if (slotID < 19)
+	//	CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
+	//else
+	//	ourOwner->curHero->artifacts.erase(ourOwner->curHero->artifacts.begin() + (slotID - 19));
+	//ourOwner->markPossibleSlots(ourArt);
+	//ourOwner->curHero->recreateArtBonuses();
 
 	// Update the hero bonuses.
 	CHeroWindow* chw = dynamic_cast<CHeroWindow*>(GH.topInt());
@@ -4044,7 +4044,7 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
 {
 	// An update is made, rather than initialization.
 	if (curHero == hero) {
-		curHero = const_cast<CGHeroInstance *>(hero);
+		curHero = hero;
 
 		// Compensate backpack pos if an artifact was insertad before it.
 		if (commonInfo->destSlotID >= 19 && commonInfo->destAOH == this
@@ -4057,11 +4057,11 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
 			// A swap was made, make the replaced artifact the current selected.
 			if (commonInfo->destSlotID < 19 && commonInfo->destArtifact) {
 				// Temporarily remove artifact from hero.
-				if (commonInfo->srcSlotID < 19)
-					CGI->arth->unequipArtifact(curHero->artifWorn, commonInfo->srcSlotID);
-				else
-					curHero->artifacts.erase(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19));
-				curHero->recreateArtBonuses();
+				//if (commonInfo->srcSlotID < 19)
+				//	CGI->arth->unequipArtifact(curHero->artifWorn, commonInfo->srcSlotID);
+				//else
+				//	curHero->artifacts.erase(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19));
+				//curHero->recreateArtBonuses();
 
 				// Source <- Dest
 				commonInfo->srcArtifact = commonInfo->destArtifact;
@@ -4118,26 +4118,26 @@ void CArtifactsOfHero::rollback()
 		if (commonInfo->srcArtifact && commonInfo->srcAOH == this) {
 			if (commonInfo->srcSlotID != -1) {
 				// Put a held artifact back to it's spot.
-				if (commonInfo->srcSlotID < 19)
-					CGI->arth->equipArtifact(curHero->artifWorn, commonInfo->srcSlotID, commonInfo->srcArtifact->id);
-				else
-					curHero->artifacts.insert(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19), commonInfo->srcArtifact->id);
+				//if (commonInfo->srcSlotID < 19)
+				//	CGI->arth->equipArtifact(curHero->artifWorn, commonInfo->srcSlotID, commonInfo->srcArtifact->id);
+				//else
+				//	curHero->artifacts.insert(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19), commonInfo->srcArtifact->id);
 			} else { // Held swapped artifact.
 				// Wear the artifact in a suitable spot.
 				ui16 i = 0;
 				for (; i < 19; i++) {
 					if (artWorn[i]->fitsHere(commonInfo->srcArtifact) && !vstd::contains(curHero->artifWorn, i)) {
-						CGI->arth->equipArtifact(curHero->artifWorn, i, commonInfo->srcArtifact->id);
+						//CGI->arth->equipArtifact(curHero->artifWorn, i, commonInfo->srcArtifact->id);
 						break;
 					}
 				}
 
 				// If it can't be worn, put it in the backpack.
 				if (i == 19)
-					curHero->artifacts.push_back(commonInfo->srcArtifact->id);
+					;//curHero->artifacts.push_back(commonInfo->srcArtifact->id);
 			}
 
-			curHero->recreateArtBonuses();
+			//curHero->recreateArtBonuses();
 		}
 	}
 

+ 1 - 1
client/GUIClasses.h

@@ -790,7 +790,7 @@ inline bool CArtPlace::locked () const
 
 class CArtifactsOfHero : public CIntObject
 {
-	CGHeroInstance * curHero;
+	const CGHeroInstance * curHero;
 
 	std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
 	std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)