diff --git a/lib/ArtifactUtils.cpp b/lib/ArtifactUtils.cpp index eb624cada..fcc5fe95f 100644 --- a/lib/ArtifactUtils.cpp +++ b/lib/ArtifactUtils.cpp @@ -204,7 +204,7 @@ DLL_LINKAGE CArtifactInstance * ArtifactUtils::createArtifact(CMap * map, const art = ArtifactUtils::createScroll(SpellID(spellID)); } } - else //TODO: create combined artifact instance for random artifacts, just in case + else { art = new CArtifactInstance(); // random, empty } diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index f8993b1f5..524169629 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -819,9 +819,6 @@ void CArtifactInstance::init() std::string CArtifactInstance::getDescription() const { std::string text = artType->getDescriptionTranslated(); - if (!vstd::contains(text, '{')) - text = '{' + artType->getNameTranslated() + "}\n\n" + text; //workaround for new artifacts with single name, turns it to H3-style - if(artType->getId() == ArtifactID::SPELL_SCROLL) { // we expect scroll description to be like this: This scroll contains the [spell name] spell which is added into your spell book for as long as you carry the scroll. @@ -849,12 +846,12 @@ bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestR return artType->canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved); } -void CArtifactInstance::putAt(ArtifactLocation al) +void CArtifactInstance::putAt(const ArtifactLocation & al) { al.getHolderArtSet()->putArtifact(al.slot, this); } -void CArtifactInstance::removeFrom(ArtifactLocation al) +void CArtifactInstance::removeFrom(const ArtifactLocation & al) { al.getHolderArtSet()->removeArtifact(al.slot); } @@ -917,7 +914,7 @@ void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance * art, const attachTo(*art); } -void CCombinedArtifactInstance::removeFrom(ArtifactLocation al) +void CCombinedArtifactInstance::removeFrom(const ArtifactLocation & al) { CArtifactInstance::removeFrom(al); for(auto & part : constituentsInfo) @@ -1110,7 +1107,7 @@ void CArtifactSet::putArtifact(ArtifactPosition slot, CArtifactInstance * art) part.slot = ArtifactUtils::getArtAnyPosition(this, part.art->getTypeId()); assert(ArtifactUtils::isSlotEquipment(part.slot)); - setNewArtSlot(part.slot, art, true); + setNewArtSlot(part.slot, part.art, true); } } } diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index f07b3d1ec..76f10930a 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -162,8 +162,8 @@ public: /// of itself, additionally truth is returned for constituents of combined arts virtual bool isPart(const CArtifactInstance *supposedPart) const; - virtual void putAt(ArtifactLocation al); - virtual void removeFrom(ArtifactLocation al); + virtual void putAt(const ArtifactLocation & al); + virtual void removeFrom(const ArtifactLocation & al); virtual void move(const ArtifactLocation & src, const ArtifactLocation & dst); template void serialize(Handler &h, const int version) @@ -198,7 +198,7 @@ public: bool isPart(const CArtifactInstance *supposedPart) const override; void createConstituents(); void addAsConstituent(CArtifactInstance * art, const ArtifactPosition & slot); - void removeFrom(ArtifactLocation al) override; + void removeFrom(const ArtifactLocation & al) override; CCombinedArtifactInstance() = default; diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index e69834738..93370fa85 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -882,9 +882,8 @@ void CStackInstance::removeArtifact(ArtifactPosition pos) { assert(getArt(pos)); + detachFrom(*getArt(pos)); CArtifactSet::removeArtifact(pos); - if(ArtifactUtils::isSlotEquipment(pos)) - detachFrom(*getArt(pos)); } void CStackInstance::serializeJson(JsonSerializeFormat & handler) diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 831db49dc..182f1ed48 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -782,20 +782,6 @@ struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient } }; -struct DLL_LINKAGE NewArtifact : public CPackForClient -{ - void applyGs(CGameState * gs); - - ConstTransitivePtr art; - - virtual void visitTyped(ICPackVisitor & visitor) override; - - template void serialize(Handler & h, const int version) - { - h & art; - } -}; - struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient { }; @@ -985,6 +971,19 @@ struct DLL_LINKAGE PutArtifact : CArtifactOperationPack } }; +struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack +{ + ConstTransitivePtr art; + + void applyGs(CGameState * gs); + virtual void visitTyped(ICPackVisitor & visitor) override; + + template void serialize(Handler & h, const int version) + { + h & art; + } +}; + struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack { ArtifactLocation al; diff --git a/lib/NetPacksBase.h b/lib/NetPacksBase.h index cbc793f5b..e7e7cb635 100644 --- a/lib/NetPacksBase.h +++ b/lib/NetPacksBase.h @@ -192,7 +192,7 @@ struct ArtifactLocation DLL_LINKAGE PlayerColor owningPlayer() const; DLL_LINKAGE CArtifactSet *getHolderArtSet(); DLL_LINKAGE CBonusSystemNode *getHolderNode(); - DLL_LINKAGE const CArtifactSet *getHolderArtSet() const; + DLL_LINKAGE CArtifactSet *getHolderArtSet() const; DLL_LINKAGE const CBonusSystemNode *getHolderNode() const; DLL_LINKAGE const CArtifactInstance *getArt() const; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index d3477d247..a19c94327 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1618,7 +1618,7 @@ const CArtifactInstance *ArtifactLocation::getArt() const return nullptr; } -const CArtifactSet * ArtifactLocation::getHolderArtSet() const +CArtifactSet * ArtifactLocation::getHolderArtSet() const { auto * t = const_cast(this); return t->getHolderArtSet();