From 0ebad5bed64072c6b44065135f2847655a80dc47 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 16 May 2010 12:34:48 +0000 Subject: [PATCH] * fixed calling heroBonusChanged when artifact is unequipped; please fix hero screen without const_casts on hero (no mechanically important variable should be changed locally) --- client/GUIClasses.cpp | 40 ++++++++++++++++++++-------------------- client/GUIClasses.h | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index bc7b2f03e..4e22233ff 100644 --- a/client/GUIClasses.cpp +++ b/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(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(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(); } } diff --git a/client/GUIClasses.h b/client/GUIClasses.h index daf5c064f..89668dce0 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -790,7 +790,7 @@ inline bool CArtPlace::locked () const class CArtifactsOfHero : public CIntObject { - CGHeroInstance * curHero; + const CGHeroInstance * curHero; std::vector 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 backpack; //hero's visible backpack (only 5 elements!)