1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

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

This commit is contained in:
mateuszb
2010-05-16 12:34:48 +00:00
parent edd31ef41b
commit 0ebad5bed6
2 changed files with 21 additions and 21 deletions

View File

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

View File

@@ -790,7 +790,7 @@ inline bool CArtPlace::locked () const
class CArtifactsOfHero : public CIntObject 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 *> 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!) std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)