mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
* Fixed bug 101, placing artifacts in specific slots in the backpack. Cleaned up swapArtifacts() to use more descriptive names as well.
This commit is contained in:
parent
db4ee5844f
commit
64a72c39cb
@ -3523,8 +3523,8 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
}
|
}
|
||||||
else //perform artifact substitution
|
else //perform artifact substitution
|
||||||
{
|
{
|
||||||
if(slotID >= 19) //we are an backpack slot - remove active artifact and put it to the last free pos in backpack
|
if (slotID >= 19) // Backpack slot - Remove active artifact and insert it into the designated position in backpack.
|
||||||
{ //TODO: putting artifacts in the middle of backpack (pushing following arts)
|
{
|
||||||
const CArtifact *cur = ourOwner->commonInfo->activeArtPlace->ourArt;
|
const CArtifact *cur = ourOwner->commonInfo->activeArtPlace->ourArt;
|
||||||
assert(cur); //there is highlighted slot, it must contain an art
|
assert(cur); //there is highlighted slot, it must contain an art
|
||||||
switch(cur->id)
|
switch(cur->id)
|
||||||
@ -3544,21 +3544,21 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
ourOwner->commonInfo->activeArtPlace->ourOwner->curHero,
|
ourOwner->commonInfo->activeArtPlace->ourOwner->curHero,
|
||||||
ourOwner->commonInfo->activeArtPlace->slotID,
|
ourOwner->commonInfo->activeArtPlace->slotID,
|
||||||
ourOwner->curHero,
|
ourOwner->curHero,
|
||||||
ourOwner->curHero->artifacts.size() + 19);
|
slotID);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if swap is possible
|
//check if swap is possible
|
||||||
else if(this->fitsHere(ourOwner->commonInfo->activeArtPlace->ourArt) && ourOwner->commonInfo->activeArtPlace->fitsHere(this->ourArt))
|
else if(this->fitsHere(ourOwner->commonInfo->activeArtPlace->ourArt) && ourOwner->commonInfo->activeArtPlace->fitsHere(this->ourArt))
|
||||||
{
|
{
|
||||||
int destSlot = slotID,
|
int srcSlot = ourOwner->commonInfo->activeArtPlace->slotID;
|
||||||
srcSlot = ourOwner->commonInfo->activeArtPlace->slotID;
|
int destSlot = slotID;
|
||||||
|
|
||||||
LOCPLINT->cb->swapArtifacts(
|
LOCPLINT->cb->swapArtifacts(
|
||||||
ourOwner->curHero,
|
|
||||||
destSlot,
|
|
||||||
ourOwner->commonInfo->activeArtPlace->ourOwner->curHero,
|
ourOwner->commonInfo->activeArtPlace->ourOwner->curHero,
|
||||||
srcSlot);
|
srcSlot,
|
||||||
|
ourOwner->curHero,
|
||||||
|
destSlot);
|
||||||
|
|
||||||
ourOwner->commonInfo->activeArtPlace->clicked = false;
|
ourOwner->commonInfo->activeArtPlace->clicked = false;
|
||||||
ourOwner->commonInfo->activeArtPlace = NULL;
|
ourOwner->commonInfo->activeArtPlace = NULL;
|
||||||
|
@ -451,17 +451,18 @@ DLL_EXPORT void SetHeroArtifacts::setArtAtPos(ui16 pos, int art)
|
|||||||
if(pos<19)
|
if(pos<19)
|
||||||
artifWorn.erase(pos);
|
artifWorn.erase(pos);
|
||||||
else
|
else
|
||||||
artifacts -= artifacts[pos-19];
|
artifacts.erase(artifacts.begin() + (pos - 19));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(pos<19)
|
if (pos < 19) {
|
||||||
artifWorn[pos] = art;
|
artifWorn[pos] = art;
|
||||||
else
|
} else { // Goes into the backpack.
|
||||||
if(pos-19 < artifacts.size())
|
if(pos - 19 < artifacts.size())
|
||||||
artifacts[pos-19] = art;
|
artifacts.insert(artifacts.begin() + (pos - 19), art);
|
||||||
else
|
else
|
||||||
artifacts.push_back(art);
|
artifacts.push_back(art);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2298,38 +2298,58 @@ bool CGameHandler::garrisonSwap( si32 tid )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameHandler::swapArtifacts( si32 hid1, si32 hid2, ui16 slot1, ui16 slot2 )
|
bool CGameHandler::swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, ui16 destSlot)
|
||||||
{
|
{
|
||||||
CGHeroInstance *h1 = gs->getHero(hid1), *h2 = gs->getHero(hid2);
|
CGHeroInstance *srcHero = gs->getHero(srcHeroID);
|
||||||
if((distance(h1->pos,h2->pos) > 1.5) || (h1->tempOwner != h2->tempOwner))
|
CGHeroInstance *destHero = gs->getHero(destHeroID);
|
||||||
|
|
||||||
|
// Make sure exchange is even possible between the two heroes.
|
||||||
|
if ((distance(srcHero->pos,destHero->pos) > 1.5 )|| (srcHero->tempOwner != destHero->tempOwner))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const CArtifact *a1 = h1->getArt(slot1),
|
const CArtifact *srcArtifact = srcHero->getArt(srcSlot);
|
||||||
*a2=h2->getArt(slot2);
|
const CArtifact *destArtifact = destHero->getArt(destSlot);
|
||||||
|
|
||||||
//check if
|
// Check if src/dest slots are appropriate for the artifacts exchanged.
|
||||||
// 1) slots are appropriate for that artifacts
|
// Moving to the backpack is always allowed.
|
||||||
// 2) they are not war machine
|
if ((!srcArtifact || destSlot < 19)
|
||||||
if((a1 && slot2<19 && !vstd::contains(a1->possibleSlots,slot2) || (a2 && slot1<19 && !vstd::contains(a2->possibleSlots,slot1))) && complain("Cannot swap artifacts!")
|
&& (((srcArtifact && !vstd::contains(srcArtifact->possibleSlots, destSlot))
|
||||||
|| (slot1>=13 && slot1<=16 || slot2>=13 && slot2<=16) && complain("Cannot move war machine!")
|
|| (destArtifact && srcSlot < 19 && !vstd::contains(destArtifact->possibleSlots, srcSlot)))))
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
complain("Cannot swap artifacts!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the artifacts are not war machines.
|
||||||
|
if ((srcSlot>=13 && srcSlot<=16) || (destSlot>=13 && destSlot<=16)) {
|
||||||
|
complain("Cannot move war machine!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the exchange.
|
||||||
SetHeroArtifacts sha;
|
SetHeroArtifacts sha;
|
||||||
sha.hid = hid1;
|
sha.hid = srcHeroID;
|
||||||
sha.artifacts = h1->artifacts;
|
sha.artifacts = srcHero->artifacts;
|
||||||
sha.artifWorn = h1->artifWorn;
|
sha.artifWorn = srcHero->artifWorn;
|
||||||
sha.setArtAtPos(slot1,h2->getArtAtPos(slot2));
|
|
||||||
if(h1 == h2) sha.setArtAtPos(slot2,h1->getArtAtPos(slot1));
|
sha.setArtAtPos(srcSlot, -1);
|
||||||
|
if (destSlot < 19 && (destArtifact || srcSlot < 19))
|
||||||
|
sha.setArtAtPos(srcSlot, destHero->getArtAtPos(destSlot));
|
||||||
|
|
||||||
|
// Correction for destination from removing source artifact in backpack.
|
||||||
|
if (srcSlot >= 19 && destSlot >= 19 && srcSlot < destSlot)
|
||||||
|
destSlot--;
|
||||||
|
|
||||||
|
// Internal hero artifact arrangement.
|
||||||
|
if(srcHero == destHero)
|
||||||
|
sha.setArtAtPos(destSlot, srcHero->getArtAtPos(srcSlot));
|
||||||
sendAndApply(&sha);
|
sendAndApply(&sha);
|
||||||
if(hid1 != hid2)
|
if (srcHeroID != destHeroID) {
|
||||||
{
|
// Exchange between two different heroes.
|
||||||
sha.hid = hid2;
|
sha.hid = destHeroID;
|
||||||
sha.artifacts = h2->artifacts;
|
sha.artifacts = destHero->artifacts;
|
||||||
sha.artifWorn = h2->artifWorn;
|
sha.artifWorn = destHero->artifWorn;
|
||||||
sha.setArtAtPos(slot2, a1 ? a1->id : -1);
|
sha.setArtAtPos(destSlot, srcArtifact ? srcArtifact->id : -1);
|
||||||
sendAndApply(&sha);
|
sendAndApply(&sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ public:
|
|||||||
bool setFormation( si32 hid, ui8 formation );
|
bool setFormation( si32 hid, ui8 formation );
|
||||||
bool tradeResources( ui32 val, ui8 player, ui32 id1, ui32 id2 );
|
bool tradeResources( ui32 val, ui8 player, ui32 id1, ui32 id2 );
|
||||||
bool buyArtifact( ui32 hid, si32 aid );
|
bool buyArtifact( ui32 hid, si32 aid );
|
||||||
bool swapArtifacts( si32 hid1, si32 hid2, ui16 slot1, ui16 slot2 );
|
bool swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, ui16 destSlot);
|
||||||
bool garrisonSwap(si32 tid);
|
bool garrisonSwap(si32 tid);
|
||||||
bool upgradeCreature( ui32 objid, ui8 pos, ui32 upgID );
|
bool upgradeCreature( ui32 objid, ui8 pos, ui32 upgID );
|
||||||
bool recruitCreatures(si32 objid, ui32 crid, ui32 cram);
|
bool recruitCreatures(si32 objid, ui32 crid, ui32 cram);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user