mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-04 23:17:41 +02:00
Fixed artifact screens so only local changes are made. Some ugly const casting, for now.
This commit is contained in:
parent
5fe80d89ef
commit
137ab65a13
@ -433,16 +433,6 @@ bool CCallback::swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGH
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCallback::setArtifact(const CGHeroInstance * hero, ui16 pos, int artID)
|
|
||||||
{
|
|
||||||
if(player != hero->tempOwner)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetArtifact sa(hero->id, pos, artID);
|
|
||||||
sendRequest(&sa);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID)
|
bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID)
|
||||||
{
|
{
|
||||||
CGTownInstance * t = const_cast<CGTownInstance *>(town);
|
CGTownInstance * t = const_cast<CGTownInstance *>(town);
|
||||||
|
@ -3613,7 +3613,7 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
}
|
}
|
||||||
else //perform artifact substitution
|
else //perform artifact substitution
|
||||||
{
|
{
|
||||||
if (slotID >= 19) // Backpack slot - Remove active artifact and insert it into the designated position in backpack.
|
if (slotID >= 19) // Backpack destination.
|
||||||
{
|
{
|
||||||
const CArtifact * cur = ourOwner->commonInfo->srcArtifact;
|
const CArtifact * cur = ourOwner->commonInfo->srcArtifact;
|
||||||
|
|
||||||
@ -3635,10 +3635,17 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
ourOwner->commonInfo->destSlotID = slotID;
|
ourOwner->commonInfo->destSlotID = slotID;
|
||||||
ourOwner->commonInfo->destArtifact = NULL;
|
ourOwner->commonInfo->destArtifact = NULL;
|
||||||
|
|
||||||
LOCPLINT->cb->setArtifact(
|
// Correction for backpack position when src lies before dest.
|
||||||
|
ourOwner->commonInfo->destSlotID +=
|
||||||
|
(ourOwner->commonInfo->srcAOH == ourOwner
|
||||||
|
&& ourOwner->commonInfo->srcSlotID >= 19
|
||||||
|
&& ourOwner->commonInfo->srcSlotID <= slotID);
|
||||||
|
|
||||||
|
LOCPLINT->cb->swapArtifacts(
|
||||||
|
ourOwner->commonInfo->srcAOH->curHero,
|
||||||
|
ourOwner->commonInfo->srcSlotID,
|
||||||
ourOwner->curHero,
|
ourOwner->curHero,
|
||||||
slotID,
|
ourOwner->commonInfo->destSlotID);
|
||||||
ourOwner->commonInfo->srcArtifact->id);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3650,10 +3657,11 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
ourOwner->commonInfo->destSlotID = slotID;
|
ourOwner->commonInfo->destSlotID = slotID;
|
||||||
ourOwner->commonInfo->destArtifact = ourArt;
|
ourOwner->commonInfo->destArtifact = ourArt;
|
||||||
|
|
||||||
LOCPLINT->cb->setArtifact(
|
LOCPLINT->cb->swapArtifacts(
|
||||||
|
ourOwner->commonInfo->srcAOH->curHero,
|
||||||
|
ourOwner->commonInfo->srcSlotID,
|
||||||
ourOwner->curHero,
|
ourOwner->curHero,
|
||||||
slotID,
|
slotID);
|
||||||
ourOwner->commonInfo->srcArtifact->id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3684,13 +3692,41 @@ void CArtPlace::select ()
|
|||||||
ourOwner->commonInfo->srcSlotID = slotID;
|
ourOwner->commonInfo->srcSlotID = slotID;
|
||||||
ourOwner->commonInfo->srcAOH = ourOwner;
|
ourOwner->commonInfo->srcAOH = ourOwner;
|
||||||
|
|
||||||
|
// Temporarily remove artifact from hero.
|
||||||
|
CGHeroInstance* hero = const_cast<CGHeroInstance*>(ourOwner->curHero);
|
||||||
|
if (slotID < 19)
|
||||||
|
hero->artifWorn.erase(slotID);
|
||||||
|
else
|
||||||
|
hero->artifacts.erase(hero->artifacts.begin() + (slotID - 19));
|
||||||
|
hero->recreateArtBonuses();
|
||||||
|
|
||||||
|
// Update the hero bonuses.
|
||||||
|
CHeroWindow* chw = dynamic_cast<CHeroWindow*>(GH.topInt());
|
||||||
|
if (chw != NULL) {
|
||||||
|
chw->deactivate();
|
||||||
|
chw->setHero(hero);
|
||||||
|
chw->activate();
|
||||||
|
} else {
|
||||||
|
CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(GH.topInt());
|
||||||
|
assert(cew); // Either an exchange- or hero window should be active if an artifact slot is selected.
|
||||||
|
cew->deactivate();
|
||||||
|
for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
|
||||||
|
{
|
||||||
|
if(cew->heroInst[g] == hero)
|
||||||
|
{
|
||||||
|
cew->artifs[g]->setHero(hero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cew->prepareBackground();
|
||||||
|
cew->activate();
|
||||||
|
}
|
||||||
|
|
||||||
if (slotID >= 19) {
|
if (slotID >= 19) {
|
||||||
// Correcting position in backpack.
|
// Correcting position in backpack.
|
||||||
ourOwner->scrollBackpack(-(slotID - 19 < ourOwner->backpackPos));
|
ourOwner->scrollBackpack(-(slotID - 19 < ourOwner->backpackPos));
|
||||||
} else {
|
} else {
|
||||||
ourOwner->eraseSlotData(this, slotID);
|
ourOwner->eraseSlotData(this, slotID);
|
||||||
}
|
}
|
||||||
LOCPLINT->cb->setArtifact(ourOwner->curHero, slotID, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3952,12 +3988,21 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
|
|||||||
backpackPos++;
|
backpackPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A swap was made, make the replaced artifact into current selected.
|
if (commonInfo->srcAOH == this) {
|
||||||
|
// 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.
|
||||||
|
CGHeroInstance * hero = const_cast<CGHeroInstance *>(curHero);
|
||||||
|
if (commonInfo->srcSlotID < 19)
|
||||||
|
hero->artifWorn.erase(commonInfo->srcSlotID);
|
||||||
|
else
|
||||||
|
hero->artifacts.erase(hero->artifacts.begin() + (commonInfo->srcSlotID - 19));
|
||||||
|
hero->recreateArtBonuses();
|
||||||
|
|
||||||
// Source <- Dest
|
// Source <- Dest
|
||||||
commonInfo->srcAOH = commonInfo->destAOH;
|
//commonInfo->srcAOH = commonInfo->destAOH;
|
||||||
commonInfo->srcArtifact = commonInfo->destArtifact;
|
commonInfo->srcArtifact = commonInfo->destArtifact;
|
||||||
commonInfo->srcSlotID = -1; // The artifact's original place is taken now.
|
//commonInfo->srcSlotID = commonInfo->destSlotID;
|
||||||
|
|
||||||
// Reset destination parameters.
|
// Reset destination parameters.
|
||||||
commonInfo->destAOH = NULL;
|
commonInfo->destAOH = NULL;
|
||||||
@ -3979,6 +4024,7 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
|
|||||||
CGI->curh->dragAndDropCursor(NULL);
|
CGI->curh->dragAndDropCursor(NULL);
|
||||||
unmarkSlots();
|
unmarkSlots();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rollback();
|
rollback();
|
||||||
}
|
}
|
||||||
@ -4007,41 +4053,36 @@ 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->destArtifact && commonInfo->destAOH == this) {
|
if (commonInfo->srcArtifact && commonInfo->srcAOH == this) {
|
||||||
// For an unlikely race condition scenario, put swapped artifact into backpack.
|
CGHeroInstance * hero = const_cast<CGHeroInstance *>(curHero);
|
||||||
LOCPLINT->cb->setArtifact(
|
|
||||||
curHero,
|
if (commonInfo->srcSlotID != -1) {
|
||||||
19 + curHero->artifacts.size(),
|
// Put a held artifact back to it's spot.
|
||||||
commonInfo->destArtifact->id);
|
if (commonInfo->srcSlotID < 19)
|
||||||
}
|
hero->artifWorn[commonInfo->srcSlotID] = commonInfo->srcArtifact->id;
|
||||||
else if (commonInfo->srcArtifact && commonInfo->srcAOH == this) {
|
else
|
||||||
if (commonInfo->srcSlotID != -1) { // Held artifact, just put it back to it's spot.
|
hero->artifacts.insert(hero->artifacts.begin() + (commonInfo->srcSlotID - 19), commonInfo->srcArtifact->id);
|
||||||
LOCPLINT->cb->setArtifact(
|
} else { // Held swapped artifact.
|
||||||
curHero,
|
|
||||||
commonInfo->srcSlotID,
|
|
||||||
commonInfo->srcArtifact->id);
|
|
||||||
} else { // 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)
|
||||||
&& curHero->artifWorn.find(i) == curHero->artifWorn.end())
|
&& curHero->artifWorn.find(i) == curHero->artifWorn.end())
|
||||||
{
|
{
|
||||||
LOCPLINT->cb->setArtifact(
|
hero->artifWorn[i] = commonInfo->srcArtifact->id;
|
||||||
curHero, 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)
|
||||||
LOCPLINT->cb->setArtifact(
|
hero->artifacts.push_back(commonInfo->srcArtifact->id);
|
||||||
curHero,
|
}
|
||||||
19 + curHero->artifacts.size(),
|
|
||||||
commonInfo->srcArtifact->id);
|
hero->recreateArtBonuses();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unmarkSlots();
|
unmarkSlots();
|
||||||
backpackPos = 0;
|
backpackPos = 0;
|
||||||
|
|
||||||
|
@ -1225,7 +1225,7 @@ void CGHeroInstance::giveArtifact (ui32 aid)
|
|||||||
void CGHeroInstance::recreateArtBonuses()
|
void CGHeroInstance::recreateArtBonuses()
|
||||||
{
|
{
|
||||||
//clear all bonuses from artifacts (if present) and give them again
|
//clear all bonuses from artifacts (if present) and give them again
|
||||||
std::remove_if(bonuses.begin(), bonuses.end(), boost::bind(HeroBonus::IsFrom,_1,HeroBonus::ARTIFACT,0xffffff));
|
bonuses.remove_if(boost::bind(HeroBonus::IsFrom,_1,HeroBonus::ARTIFACT,0xffffff));
|
||||||
for (std::map<ui16,ui32>::iterator ari = artifWorn.begin(); ari != artifWorn.end(); ari++)
|
for (std::map<ui16,ui32>::iterator ari = artifWorn.begin(); ari != artifWorn.end(); ari++)
|
||||||
{
|
{
|
||||||
CArtifact &art = VLC->arth->artifacts[ari->second];
|
CArtifact &art = VLC->arth->artifacts[ari->second];
|
||||||
|
@ -1249,22 +1249,6 @@ struct ExchangeArtifacts : public CPackForServer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SetArtifact : public CPackForServer
|
|
||||||
{
|
|
||||||
SetArtifact () {};
|
|
||||||
SetArtifact (si32 hid, ui16 slot, int artID)
|
|
||||||
:hid(hid), slot(slot), artID(artID) {};
|
|
||||||
si32 hid;
|
|
||||||
ui16 slot;
|
|
||||||
int artID;
|
|
||||||
|
|
||||||
bool applyGh(CGameHandler *gh);
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
|
||||||
{
|
|
||||||
h & hid & slot & artID;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BuyArtifact : public CPackForServer
|
struct BuyArtifact : public CPackForServer
|
||||||
{
|
{
|
||||||
BuyArtifact(){};
|
BuyArtifact(){};
|
||||||
|
@ -139,7 +139,6 @@ void registerTypes3(Serializer &s)
|
|||||||
s.template registerType<UpgradeCreature>();
|
s.template registerType<UpgradeCreature>();
|
||||||
s.template registerType<GarrisonHeroSwap>();
|
s.template registerType<GarrisonHeroSwap>();
|
||||||
s.template registerType<ExchangeArtifacts>();
|
s.template registerType<ExchangeArtifacts>();
|
||||||
s.template registerType<SetArtifact>();
|
|
||||||
s.template registerType<BuyArtifact>();
|
s.template registerType<BuyArtifact>();
|
||||||
s.template registerType<TradeOnMarketplace>();
|
s.template registerType<TradeOnMarketplace>();
|
||||||
s.template registerType<SetFormation>();
|
s.template registerType<SetFormation>();
|
||||||
|
@ -2522,45 +2522,6 @@ bool CGameHandler::swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a hero artifact slot to contain a specific artifact.
|
|
||||||
*
|
|
||||||
* @param artID ID of an artifact or -1 for no artifact.
|
|
||||||
*/
|
|
||||||
bool CGameHandler::setArtifact(si32 heroID, ui16 slot, int artID)
|
|
||||||
{
|
|
||||||
const CGHeroInstance *hero = gs->getHero(heroID);
|
|
||||||
|
|
||||||
if (artID != -1) {
|
|
||||||
const CArtifact &artifact = VLC->arth->artifacts[artID];
|
|
||||||
|
|
||||||
if (slot < 19 && !vstd::contains(artifact.possibleSlots, slot)) {
|
|
||||||
complain("Artifact does not fit!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot >= 19 && artifact.isBig()) {
|
|
||||||
complain("Cannot put big artifacts in backpack!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot == 16) {
|
|
||||||
complain("Cannot alter catapult slot!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the exchange.
|
|
||||||
SetHeroArtifacts sha;
|
|
||||||
sha.hid = heroID;
|
|
||||||
sha.artifacts = hero->artifacts;
|
|
||||||
sha.artifWorn = hero->artifWorn;
|
|
||||||
sha.setArtAtPos(slot, artID);
|
|
||||||
sendAndApply(&sha);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CGameHandler::buyArtifact( ui32 hid, si32 aid )
|
bool CGameHandler::buyArtifact( ui32 hid, si32 aid )
|
||||||
{
|
{
|
||||||
CGHeroInstance *hero = gs->getHero(hid);
|
CGHeroInstance *hero = gs->getHero(hid);
|
||||||
|
@ -163,7 +163,6 @@ public:
|
|||||||
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 srcHeroID, si32 destHeroID, ui16 srcSlot, ui16 destSlot);
|
bool swapArtifacts(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, ui16 destSlot);
|
||||||
bool setArtifact(si32 heroID, ui16 slot, int artID);
|
|
||||||
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);
|
||||||
|
@ -98,12 +98,6 @@ bool ExchangeArtifacts::applyGh( CGameHandler *gh )
|
|||||||
return gh->swapArtifacts(hid1,hid2,slot1,slot2);
|
return gh->swapArtifacts(hid1,hid2,slot1,slot2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetArtifact::applyGh( CGameHandler *gh )
|
|
||||||
{
|
|
||||||
ERROR_IF_NOT_OWNS(hid);
|
|
||||||
return gh->setArtifact(hid, slot, artID);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BuyArtifact::applyGh( CGameHandler *gh )
|
bool BuyArtifact::applyGh( CGameHandler *gh )
|
||||||
{
|
{
|
||||||
ERROR_IF_NOT_OWNS(hid);
|
ERROR_IF_NOT_OWNS(hid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user