mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Some code cleanup.
This commit is contained in:
parent
eec43d3c58
commit
38004fc45c
@ -3661,8 +3661,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.
|
||||||
CGHeroInstance *destHero = const_cast<CGHeroInstance *>(ourOwner->curHero);
|
CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
|
||||||
CGI->arth->unequipArtifact(destHero->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)) {
|
||||||
@ -3753,19 +3752,18 @@ void CArtPlace::select ()
|
|||||||
ourOwner->commonInfo->srcAOH = ourOwner;
|
ourOwner->commonInfo->srcAOH = ourOwner;
|
||||||
|
|
||||||
// Temporarily remove artifact from hero.
|
// Temporarily remove artifact from hero.
|
||||||
CGHeroInstance* hero = const_cast<CGHeroInstance*>(ourOwner->curHero);
|
|
||||||
if (slotID < 19)
|
if (slotID < 19)
|
||||||
CGI->arth->unequipArtifact(hero->artifWorn, slotID);
|
CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
|
||||||
else
|
else
|
||||||
hero->artifacts.erase(hero->artifacts.begin() + (slotID - 19));
|
ourOwner->curHero->artifacts.erase(ourOwner->curHero->artifacts.begin() + (slotID - 19));
|
||||||
ourOwner->markPossibleSlots(ourArt);
|
ourOwner->markPossibleSlots(ourArt);
|
||||||
hero->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());
|
||||||
if (chw != NULL) {
|
if (chw != NULL) {
|
||||||
chw->deactivate();
|
chw->deactivate();
|
||||||
chw->setHero(hero);
|
chw->setHero(ourOwner->curHero);
|
||||||
chw->activate();
|
chw->activate();
|
||||||
} else {
|
} else {
|
||||||
CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt());
|
CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt());
|
||||||
@ -3773,9 +3771,9 @@ void CArtPlace::select ()
|
|||||||
cew->deactivate();
|
cew->deactivate();
|
||||||
for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
|
for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
|
||||||
{
|
{
|
||||||
if(cew->heroInst[g] == hero)
|
if(cew->heroInst[g] == ourOwner->curHero)
|
||||||
{
|
{
|
||||||
cew->artifs[g]->setHero(hero);
|
cew->artifs[g]->setHero(ourOwner->curHero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cew->prepareBackground();
|
cew->prepareBackground();
|
||||||
@ -4043,6 +4041,8 @@ 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);
|
||||||
|
|
||||||
// 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
|
||||||
&& commonInfo->destSlotID - 19 < backpackPos)
|
&& commonInfo->destSlotID - 19 < backpackPos)
|
||||||
@ -4051,16 +4051,14 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updateState && commonInfo->srcAOH == this) {
|
if (updateState && commonInfo->srcAOH == this) {
|
||||||
curHero = 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.
|
||||||
CGHeroInstance * nonconstCurHero = const_cast<CGHeroInstance *>(curHero);
|
|
||||||
if (commonInfo->srcSlotID < 19)
|
if (commonInfo->srcSlotID < 19)
|
||||||
CGI->arth->unequipArtifact(nonconstCurHero->artifWorn, commonInfo->srcSlotID);
|
CGI->arth->unequipArtifact(curHero->artifWorn, commonInfo->srcSlotID);
|
||||||
else
|
else
|
||||||
nonconstCurHero->artifacts.erase(nonconstCurHero->artifacts.begin() + (commonInfo->srcSlotID - 19));
|
curHero->artifacts.erase(curHero->artifacts.begin() + (commonInfo->srcSlotID - 19));
|
||||||
nonconstCurHero->recreateArtBonuses();
|
curHero->recreateArtBonuses();
|
||||||
|
|
||||||
// Source <- Dest
|
// Source <- Dest
|
||||||
commonInfo->srcArtifact = commonInfo->destArtifact;
|
commonInfo->srcArtifact = commonInfo->destArtifact;
|
||||||
@ -4090,7 +4088,7 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
|
|||||||
rollback();
|
rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
curHero = hero;
|
curHero = const_cast<CGHeroInstance *>(hero);
|
||||||
|
|
||||||
if (curHero->artifacts.size() > 0)
|
if (curHero->artifacts.size() > 0)
|
||||||
backpackPos %= curHero->artifacts.size();
|
backpackPos %= curHero->artifacts.size();
|
||||||
@ -4115,32 +4113,28 @@ void CArtifactsOfHero::rollback()
|
|||||||
if (curHero != NULL) {
|
if (curHero != NULL) {
|
||||||
// Restore any held artifact to it's original position.
|
// Restore any held artifact to it's original position.
|
||||||
if (commonInfo->srcArtifact && commonInfo->srcAOH == this) {
|
if (commonInfo->srcArtifact && commonInfo->srcAOH == this) {
|
||||||
CGHeroInstance * hero = const_cast<CGHeroInstance *>(curHero);
|
|
||||||
|
|
||||||
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(hero->artifWorn, commonInfo->srcSlotID, commonInfo->srcArtifact->id);
|
CGI->arth->equipArtifact(curHero->artifWorn, commonInfo->srcSlotID, commonInfo->srcArtifact->id);
|
||||||
else
|
else
|
||||||
hero->artifacts.insert(hero->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)
|
if (artWorn[i]->fitsHere(commonInfo->srcArtifact) && !vstd::contains(curHero->artifWorn, i)) {
|
||||||
&& curHero->artifWorn.find(i) == curHero->artifWorn.end())
|
CGI->arth->equipArtifact(curHero->artifWorn, i, commonInfo->srcArtifact->id);
|
||||||
{
|
|
||||||
CGI->arth->equipArtifact(hero->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)
|
||||||
hero->artifacts.push_back(commonInfo->srcArtifact->id);
|
curHero->artifacts.push_back(commonInfo->srcArtifact->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
hero->recreateArtBonuses();
|
curHero->recreateArtBonuses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ inline bool CArtPlace::locked () const
|
|||||||
|
|
||||||
class CArtifactsOfHero : public CIntObject
|
class CArtifactsOfHero : public CIntObject
|
||||||
{
|
{
|
||||||
const CGHeroInstance * curHero;
|
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!)
|
||||||
|
@ -615,7 +615,7 @@ void CArtHandler::equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, u
|
|||||||
destConsumed = true;
|
destConsumed = true;
|
||||||
} else {
|
} else {
|
||||||
BOOST_FOREACH(ui16 slot, constituent.possibleSlots) {
|
BOOST_FOREACH(ui16 slot, constituent.possibleSlots) {
|
||||||
if (artifWorn.find(slot) == artifWorn.end()) {
|
if (!vstd::contains(artifWorn, slot)) {
|
||||||
artifWorn[slot] = 145;
|
artifWorn[slot] = 145;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -632,7 +632,7 @@ void CArtHandler::equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, u
|
|||||||
*/
|
*/
|
||||||
void CArtHandler::unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID)
|
void CArtHandler::unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID)
|
||||||
{
|
{
|
||||||
if (artifWorn.find(slotID) == artifWorn.end())
|
if (!vstd::contains(artifWorn, slotID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CArtifact &artifact = artifacts[artifWorn[slotID]];
|
const CArtifact &artifact = artifacts[artifWorn[slotID]];
|
||||||
@ -651,7 +651,7 @@ void CArtHandler::unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID)
|
|||||||
destConsumed = true;
|
destConsumed = true;
|
||||||
} else {
|
} else {
|
||||||
BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots) {
|
BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots) {
|
||||||
if (artifWorn.find(slot) != artifWorn.end() && artifWorn[slot] == 145) {
|
if (vstd::contains(artifWorn, slot) && artifWorn[slot] == 145) {
|
||||||
artifWorn.erase(slot);
|
artifWorn.erase(slot);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1178,7 @@ void CGHeroInstance::giveArtifact (ui32 aid)
|
|||||||
|
|
||||||
if (artifact.isBig()) {
|
if (artifact.isBig()) {
|
||||||
for (std::vector<ui16>::const_iterator it = artifact.possibleSlots.begin(); it != artifact.possibleSlots.end(); ++it) {
|
for (std::vector<ui16>::const_iterator it = artifact.possibleSlots.begin(); it != artifact.possibleSlots.end(); ++it) {
|
||||||
if (artifWorn.find(*it) == artifWorn.end()) {
|
if (!vstd::contains(artifWorn, *it)) {
|
||||||
VLC->arth->equipArtifact(artifWorn, *it, aid);
|
VLC->arth->equipArtifact(artifWorn, *it, aid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2650,7 +2650,7 @@ bool CGameHandler::swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot,
|
|||||||
// Combinational artifacts needs to be removed first so they don't get denied movement because of their own locks.
|
// Combinational artifacts needs to be removed first so they don't get denied movement because of their own locks.
|
||||||
if (srcHeroID == destHeroID && srcSlot < 19 && destSlot < 19) {
|
if (srcHeroID == destHeroID && srcSlot < 19 && destSlot < 19) {
|
||||||
sha.setArtAtPos(srcSlot, -1);
|
sha.setArtAtPos(srcSlot, -1);
|
||||||
if (sha.artifWorn.find(destSlot) == sha.artifWorn.end())
|
if (!vstd::contains(sha.artifWorn, destSlot))
|
||||||
destArtifact = NULL;
|
destArtifact = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2681,7 +2681,7 @@ bool CGameHandler::swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot,
|
|||||||
// If dest does not fit in src, put it in dest's backpack instead.
|
// If dest does not fit in src, put it in dest's backpack instead.
|
||||||
if (srcHeroID == destHeroID) // To avoid stumbling on own locks, remove artifact first.
|
if (srcHeroID == destHeroID) // To avoid stumbling on own locks, remove artifact first.
|
||||||
sha.setArtAtPos(destSlot, -1);
|
sha.setArtAtPos(destSlot, -1);
|
||||||
bool destFits = !destArtifact || srcSlot >= 19 || destSlot >= 19 || destArtifact->fitsAt(sha.artifWorn, srcSlot);
|
const bool destFits = !destArtifact || srcSlot >= 19 || destSlot >= 19 || destArtifact->fitsAt(sha.artifWorn, srcSlot);
|
||||||
if (srcHeroID == destHeroID && destArtifact)
|
if (srcHeroID == destHeroID && destArtifact)
|
||||||
sha.setArtAtPos(destSlot, destArtifact->id);
|
sha.setArtAtPos(destSlot, destArtifact->id);
|
||||||
|
|
||||||
@ -2802,7 +2802,7 @@ bool CGameHandler::assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assem
|
|||||||
const CArtifact &constituent = VLC->arth->artifacts[constituentID];
|
const CArtifact &constituent = VLC->arth->artifacts[constituentID];
|
||||||
|
|
||||||
BOOST_REVERSE_FOREACH(ui16 slotID, constituent.possibleSlots) {
|
BOOST_REVERSE_FOREACH(ui16 slotID, constituent.possibleSlots) {
|
||||||
if (sha.artifWorn.find(slotID) != sha.artifWorn.end()) {
|
if (vstd::contains(sha.artifWorn, slotID)) {
|
||||||
if (sha.artifWorn[slotID] == 145 || (!destConsumed && slotID == artifactSlot)) {
|
if (sha.artifWorn[slotID] == 145 || (!destConsumed && slotID == artifactSlot)) {
|
||||||
if (slotID == artifactSlot)
|
if (slotID == artifactSlot)
|
||||||
destConsumed = true;
|
destConsumed = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user