mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Mostly done combined artifacts.
[assembling, disassembling, moving, picking]
This commit is contained in:
parent
3fde9e45df
commit
e6d577c233
@ -2179,11 +2179,19 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact
|
|||||||
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
|
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
||||||
|
BOOST_FOREACH(IShowActivable *isa, GH.listInt)
|
||||||
|
if(isa->type & IShowActivable::WITH_ARTIFACTS)
|
||||||
|
BOOST_FOREACH(CArtifactsOfHero *aoh, (dynamic_cast<CWindowWithArtifacts*>(isa))->artSets)
|
||||||
|
aoh->artifactAssembled(al);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
|
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
||||||
|
BOOST_FOREACH(IShowActivable *isa, GH.listInt)
|
||||||
|
if(isa->type & IShowActivable::WITH_ARTIFACTS)
|
||||||
|
BOOST_FOREACH(CArtifactsOfHero *aoh, (dynamic_cast<CWindowWithArtifacts*>(isa))->artSets)
|
||||||
|
aoh->artifactDisassembled(al);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
|
CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
|
||||||
|
@ -803,6 +803,11 @@ SComponent::SComponent(const Component &c)
|
|||||||
subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
|
subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SComponent::SComponent()
|
||||||
|
{
|
||||||
|
img = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SComponent::~SComponent()
|
SComponent::~SComponent()
|
||||||
{
|
{
|
||||||
if (free && img)
|
if (free && img)
|
||||||
@ -4665,7 +4670,7 @@ void CArtPlace::clickRight(tribool down, bool previousState)
|
|||||||
boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb, ourOwner->curHero, slotID, true, combination->id),
|
boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb, ourOwner->curHero, slotID, true, combination->id),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if(assemblyPossibilities.size())
|
if(assemblyPossibilities.size() > 2)
|
||||||
{
|
{
|
||||||
tlog3 << "More than one possibility of assembling... taking only first\n";
|
tlog3 << "More than one possibility of assembling... taking only first\n";
|
||||||
break;
|
break;
|
||||||
@ -5239,12 +5244,12 @@ void CArtifactsOfHero::realizeCurrentTransaction()
|
|||||||
|
|
||||||
void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
|
void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
|
||||||
{
|
{
|
||||||
if(src.hero == curHero)
|
if(src.hero == curHero && src.slot >= Arts::BACKPACK_START)
|
||||||
setSlotData(getArtPlace(src.slot), src.slot);
|
setSlotData(getArtPlace(src.slot), src.slot);
|
||||||
if(dst.hero == curHero)
|
if(dst.hero == curHero && dst.slot >= Arts::BACKPACK_START)
|
||||||
setSlotData(getArtPlace(dst.slot), dst.slot);
|
setSlotData(getArtPlace(dst.slot), dst.slot);
|
||||||
|
if(src.hero == curHero || dst.hero == curHero) //we need to update all slots, artifact might be combined and affect more slots
|
||||||
updateParentWindow();
|
updateWornSlots();
|
||||||
|
|
||||||
if(commonInfo->src == src) //artifact was taken from us
|
if(commonInfo->src == src) //artifact was taken from us
|
||||||
{
|
{
|
||||||
@ -5313,6 +5318,26 @@ CArtPlace * CArtifactsOfHero::getArtPlace(int slot)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CArtifactsOfHero::artifactAssembled(const ArtifactLocation &al)
|
||||||
|
{
|
||||||
|
if(al.hero == curHero)
|
||||||
|
updateWornSlots();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CArtifactsOfHero::artifactDisassembled(const ArtifactLocation &al)
|
||||||
|
{
|
||||||
|
if(al.hero == curHero)
|
||||||
|
updateWornSlots();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CArtifactsOfHero::updateWornSlots()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < Arts::BACKPACK_START; i++)
|
||||||
|
setSlotData(getArtPlace(i), i);
|
||||||
|
|
||||||
|
updateParentWindow();
|
||||||
|
}
|
||||||
|
|
||||||
void CExchangeWindow::close()
|
void CExchangeWindow::close()
|
||||||
{
|
{
|
||||||
GH.popIntTotally(this);
|
GH.popIntTotally(this);
|
||||||
|
@ -170,7 +170,7 @@ public:
|
|||||||
void init(Etype Type, int Subtype, int Val);
|
void init(Etype Type, int Subtype, int Val);
|
||||||
SComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur=NULL, bool freeSur=false); //c-tor
|
SComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur=NULL, bool freeSur=false); //c-tor
|
||||||
SComponent(const Component &c); //c-tor
|
SComponent(const Component &c); //c-tor
|
||||||
SComponent(){}; //c-tor
|
SComponent();; //c-tor
|
||||||
virtual ~SComponent(); //d-tor
|
virtual ~SComponent(); //d-tor
|
||||||
|
|
||||||
void clickRight(tribool down, bool previousState); //call-in
|
void clickRight(tribool down, bool previousState); //call-in
|
||||||
@ -982,6 +982,8 @@ public:
|
|||||||
|
|
||||||
void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
|
void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
|
||||||
void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
|
void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
|
||||||
|
void artifactAssembled(const ArtifactLocation &al);
|
||||||
|
void artifactDisassembled(const ArtifactLocation &al);
|
||||||
CArtPlace *getArtPlace(int slot);
|
CArtPlace *getArtPlace(int slot);
|
||||||
|
|
||||||
void setHero(const CGHeroInstance * hero);
|
void setHero(const CGHeroInstance * hero);
|
||||||
@ -992,6 +994,7 @@ public:
|
|||||||
void markPossibleSlots(const CArtifactInstance* art);
|
void markPossibleSlots(const CArtifactInstance* art);
|
||||||
void unmarkSlots(bool withRedraw = true);
|
void unmarkSlots(bool withRedraw = true);
|
||||||
void setSlotData (CArtPlace* artPlace, int slotID);
|
void setSlotData (CArtPlace* artPlace, int slotID);
|
||||||
|
void updateWornSlots ();
|
||||||
void eraseSlotData (CArtPlace* artPlace, int slotID);
|
void eraseSlotData (CArtPlace* artPlace, int slotID);
|
||||||
|
|
||||||
CArtifactsOfHero(const Point& position, bool createCommonPart = false); //c-tor
|
CArtifactsOfHero(const Point& position, bool createCommonPart = false); //c-tor
|
||||||
|
@ -186,16 +186,12 @@ void MoveArtifact::applyCl( CClient *cl )
|
|||||||
|
|
||||||
void AssembledArtifact::applyCl( CClient *cl )
|
void AssembledArtifact::applyCl( CClient *cl )
|
||||||
{
|
{
|
||||||
// INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
|
INTERFACE_CALL_IF_PRESENT(al.hero->tempOwner, artifactAssembled, al);
|
||||||
// if(src.hero->tempOwner != dst.hero->tempOwner)
|
|
||||||
// INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassembledArtifact::applyCl( CClient *cl )
|
void DisassembledArtifact::applyCl( CClient *cl )
|
||||||
{
|
{
|
||||||
// INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
|
INTERFACE_CALL_IF_PRESENT(al.hero->tempOwner, artifactDisassembled, al);
|
||||||
// if(src.hero->tempOwner != dst.hero->tempOwner)
|
|
||||||
// INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GiveBonus::applyCl( CClient *cl )
|
void GiveBonus::applyCl( CClient *cl )
|
||||||
|
@ -942,9 +942,7 @@ bool CArtifactInstance::canBePutAt(const ArtifactLocation &al, bool assumeDestRe
|
|||||||
if(!vstd::contains(artType->possibleSlots, al.slot))
|
if(!vstd::contains(artType->possibleSlots, al.slot))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!assumeDestRemoved) //test if slot is free
|
return al.hero->isPositionFree(al.slot, assumeDestRemoved);
|
||||||
return al.hero->isPositionFree(al.slot);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactInstance::putAt(CGHeroInstance *h, ui16 slot)
|
void CArtifactInstance::putAt(CGHeroInstance *h, ui16 slot)
|
||||||
@ -968,7 +966,7 @@ void CArtifactInstance::removeFrom(CGHeroInstance *h, ui16 slot)
|
|||||||
|
|
||||||
bool CArtifactInstance::canBeDisassembled() const
|
bool CArtifactInstance::canBeDisassembled() const
|
||||||
{
|
{
|
||||||
return false;
|
return artType->constituents && artType->constituentOf->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CGHeroInstance *h) const
|
std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CGHeroInstance *h) const
|
||||||
@ -1074,6 +1072,7 @@ void CCombinedArtifactInstance::putAt(CGHeroInstance *h, ui16 slot)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CArtifactInstance *mainConstituent = figureMainConstituent(slot); //it'll be replaced with combined artifact, not a lock
|
CArtifactInstance *mainConstituent = figureMainConstituent(slot); //it'll be replaced with combined artifact, not a lock
|
||||||
|
CArtifactInstance::putAt(h, slot); //puts combined art (this)
|
||||||
|
|
||||||
BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
|
BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
|
||||||
{
|
{
|
||||||
@ -1091,7 +1090,6 @@ void CCombinedArtifactInstance::putAt(CGHeroInstance *h, ui16 slot)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ci.slot = -1;
|
ci.slot = -1;
|
||||||
CArtifactInstance::putAt(h, slot); //puts combined art (this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7005,10 +7005,10 @@ const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CArtifactSet::isPositionFree(ui16 pos) const
|
bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
|
||||||
{
|
{
|
||||||
if(const ArtSlotInfo *s = getSlot(pos))
|
if(const ArtSlotInfo *s = getSlot(pos))
|
||||||
return !s->artifact && !s->locked;
|
return (onlyLockCheck || !s->artifact) && !s->locked;
|
||||||
|
|
||||||
return true; //no slot means not used
|
return true; //no slot means not used
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ public:
|
|||||||
si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
|
si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
|
||||||
si32 getArtPos(const CArtifactInstance *art) const;
|
si32 getArtPos(const CArtifactInstance *art) const;
|
||||||
bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
|
bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
|
||||||
bool isPositionFree(ui16 pos) const;
|
bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const;
|
||||||
si32 getArtTypeId(ui16 pos) const;
|
si32 getArtTypeId(ui16 pos) const;
|
||||||
|
|
||||||
|
|
||||||
|
@ -747,6 +747,19 @@ DLL_EXPORT void AssembledArtifact::applyGs( CGameState *gs )
|
|||||||
|
|
||||||
DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs )
|
DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs )
|
||||||
{
|
{
|
||||||
|
CGHeroInstance *h = al.hero;
|
||||||
|
CCombinedArtifactInstance *disassembled = dynamic_cast<CCombinedArtifactInstance*>(al.getArt());
|
||||||
|
assert(disassembled);
|
||||||
|
|
||||||
|
std::vector<CCombinedArtifactInstance::ConstituentInfo> constituents = disassembled->constituentsInfo;
|
||||||
|
disassembled->removeFrom(h, al.slot);
|
||||||
|
BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo &ci, constituents)
|
||||||
|
{
|
||||||
|
ci.art->detachFrom(disassembled);
|
||||||
|
ci.art->putAt(h, ci.slot >= 0 ? ci.slot : al.slot); //-1 is slot of main constituent -> it'll replace combined artifact in its pos
|
||||||
|
}
|
||||||
|
|
||||||
|
delNull(disassembled);
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs )
|
DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs )
|
||||||
|
@ -2572,6 +2572,8 @@ bool CGameHandler::assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assem
|
|||||||
if(!destArtifact)
|
if(!destArtifact)
|
||||||
COMPLAIN_RET("assembleArtifacts: there is no such artifact instance!");
|
COMPLAIN_RET("assembleArtifacts: there is no such artifact instance!");
|
||||||
|
|
||||||
|
if(assemble)
|
||||||
|
{
|
||||||
CArtifact *combinedArt = VLC->arth->artifacts[assembleTo];
|
CArtifact *combinedArt = VLC->arth->artifacts[assembleTo];
|
||||||
if(!combinedArt->constituents)
|
if(!combinedArt->constituents)
|
||||||
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
|
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
|
||||||
@ -2581,8 +2583,17 @@ bool CGameHandler::assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assem
|
|||||||
AssembledArtifact aa;
|
AssembledArtifact aa;
|
||||||
aa.al = ArtifactLocation(hero, artifactSlot);
|
aa.al = ArtifactLocation(hero, artifactSlot);
|
||||||
aa.builtArt = combinedArt;
|
aa.builtArt = combinedArt;
|
||||||
|
sendAndApply(&aa);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!destArtifact->artType->constituents)
|
||||||
|
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to disassemble is not a combined artifact!");
|
||||||
|
|
||||||
CCombinedArtifactInstance *assembliedArt = new CCombinedArtifactInstance();
|
DisassembledArtifact da;
|
||||||
|
da.al = ArtifactLocation(hero, artifactSlot);
|
||||||
|
sendAndApply(&da);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
SetHeroArtifacts sha;
|
SetHeroArtifacts sha;
|
||||||
sha.hid = heroID;
|
sha.hid = heroID;
|
||||||
|
Loading…
Reference in New Issue
Block a user