mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-04 00:15:53 +02:00
CMap removed from CArtifactSet level
This commit is contained in:
parent
1e0f131d7f
commit
b06426ac43
@ -14,7 +14,6 @@
|
|||||||
#include "GameSettings.h"
|
#include "GameSettings.h"
|
||||||
#include "spells/CSpellHandler.h"
|
#include "spells/CSpellHandler.h"
|
||||||
|
|
||||||
#include "mapping/CMap.h"
|
|
||||||
#include "mapObjects/CGHeroInstance.h"
|
#include "mapObjects/CGHeroInstance.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
@ -256,33 +255,23 @@ DLL_LINKAGE CArtifactInstance * ArtifactUtils::createNewArtifactInstance(const A
|
|||||||
return ArtifactUtils::createNewArtifactInstance(aid.toArtifact());
|
return ArtifactUtils::createNewArtifactInstance(aid.toArtifact());
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_LINKAGE CArtifactInstance * ArtifactUtils::createArtifact(CMap * map, const ArtifactID & aid, SpellID spellID)
|
DLL_LINKAGE CArtifactInstance * ArtifactUtils::createArtifact(const ArtifactID & aid, SpellID spellID)
|
||||||
{
|
{
|
||||||
CArtifactInstance * art = nullptr;
|
|
||||||
if(aid.getNum() >= 0)
|
if(aid.getNum() >= 0)
|
||||||
{
|
{
|
||||||
if(spellID == SpellID::NONE)
|
if(spellID == SpellID::NONE)
|
||||||
{
|
{
|
||||||
art = ArtifactUtils::createNewArtifactInstance(aid);
|
return ArtifactUtils::createNewArtifactInstance(aid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
art = ArtifactUtils::createScroll(spellID);
|
return ArtifactUtils::createScroll(spellID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
art = new CArtifactInstance(); // random, empty
|
return new CArtifactInstance(); // random, empty
|
||||||
}
|
}
|
||||||
map->addNewArtifactInstance(art);
|
|
||||||
if(art->artType && art->isCombined())
|
|
||||||
{
|
|
||||||
for(auto & part : art->getPartsInfo())
|
|
||||||
{
|
|
||||||
map->addNewArtifactInstance(part.art);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return art;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_LINKAGE void ArtifactUtils::insertScrrollSpellName(std::string & description, const SpellID & sid)
|
DLL_LINKAGE void ArtifactUtils::insertScrrollSpellName(std::string & description, const SpellID & sid)
|
||||||
|
@ -21,7 +21,6 @@ class CGHeroInstance;
|
|||||||
class CArtifactSet;
|
class CArtifactSet;
|
||||||
class CArtifactInstance;
|
class CArtifactInstance;
|
||||||
struct ArtSlotInfo;
|
struct ArtSlotInfo;
|
||||||
class CMap;
|
|
||||||
|
|
||||||
namespace ArtifactUtils
|
namespace ArtifactUtils
|
||||||
{
|
{
|
||||||
@ -43,7 +42,7 @@ namespace ArtifactUtils
|
|||||||
DLL_LINKAGE CArtifactInstance * createScroll(const SpellID & sid);
|
DLL_LINKAGE CArtifactInstance * createScroll(const SpellID & sid);
|
||||||
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(const CArtifact * art);
|
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(const CArtifact * art);
|
||||||
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(const ArtifactID & aid);
|
DLL_LINKAGE CArtifactInstance * createNewArtifactInstance(const ArtifactID & aid);
|
||||||
DLL_LINKAGE CArtifactInstance * createArtifact(CMap * map, const ArtifactID & aid, SpellID spellID = SpellID::NONE);
|
DLL_LINKAGE CArtifactInstance * createArtifact(const ArtifactID & aid, SpellID spellID = SpellID::NONE);
|
||||||
DLL_LINKAGE void insertScrrollSpellName(std::string & description, const SpellID & sid);
|
DLL_LINKAGE void insertScrrollSpellName(std::string & description, const SpellID & sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -964,7 +964,7 @@ void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
|
|||||||
node->attachTo(*elem.second.artifact);
|
node->attachTo(*elem.second.artifact);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map)
|
void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName)
|
||||||
{
|
{
|
||||||
//todo: creature and commander artifacts
|
//todo: creature and commander artifacts
|
||||||
if(handler.saving && artifactsInBackpack.empty() && artifactsWorn.empty())
|
if(handler.saving && artifactsInBackpack.empty() && artifactsWorn.empty())
|
||||||
@ -972,7 +972,6 @@ void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const s
|
|||||||
|
|
||||||
if(!handler.saving)
|
if(!handler.saving)
|
||||||
{
|
{
|
||||||
assert(map);
|
|
||||||
artifactsInBackpack.clear();
|
artifactsInBackpack.clear();
|
||||||
artifactsWorn.clear();
|
artifactsWorn.clear();
|
||||||
}
|
}
|
||||||
@ -982,13 +981,13 @@ void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const s
|
|||||||
switch(bearerType())
|
switch(bearerType())
|
||||||
{
|
{
|
||||||
case ArtBearer::HERO:
|
case ArtBearer::HERO:
|
||||||
serializeJsonHero(handler, map);
|
serializeJsonHero(handler);
|
||||||
break;
|
break;
|
||||||
case ArtBearer::CREATURE:
|
case ArtBearer::CREATURE:
|
||||||
serializeJsonCreature(handler, map);
|
serializeJsonCreature(handler);
|
||||||
break;
|
break;
|
||||||
case ArtBearer::COMMANDER:
|
case ArtBearer::COMMANDER:
|
||||||
serializeJsonCommander(handler, map);
|
serializeJsonCommander(handler);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -996,11 +995,11 @@ void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
|
void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
for(const auto & slot : ArtifactUtils::allWornSlots())
|
for(const auto & slot : ArtifactUtils::allWornSlots())
|
||||||
{
|
{
|
||||||
serializeJsonSlot(handler, slot, map);
|
serializeJsonSlot(handler, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ArtifactID> backpackTemp;
|
std::vector<ArtifactID> backpackTemp;
|
||||||
@ -1016,7 +1015,7 @@ void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
|
|||||||
{
|
{
|
||||||
for(const ArtifactID & artifactID : backpackTemp)
|
for(const ArtifactID & artifactID : backpackTemp)
|
||||||
{
|
{
|
||||||
auto * artifact = ArtifactUtils::createArtifact(map, artifactID);
|
auto * artifact = ArtifactUtils::createArtifact(artifactID);
|
||||||
auto slot = ArtifactPosition::BACKPACK_START + artifactsInBackpack.size();
|
auto slot = ArtifactPosition::BACKPACK_START + artifactsInBackpack.size();
|
||||||
if(artifact->artType->canBePutAt(this, slot))
|
if(artifact->artType->canBePutAt(this, slot))
|
||||||
{
|
{
|
||||||
@ -1027,17 +1026,17 @@ void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactSet::serializeJsonCreature(JsonSerializeFormat & handler, CMap * map)
|
void CArtifactSet::serializeJsonCreature(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
logGlobal->error("CArtifactSet::serializeJsonCreature not implemented");
|
logGlobal->error("CArtifactSet::serializeJsonCreature not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactSet::serializeJsonCommander(JsonSerializeFormat & handler, CMap * map)
|
void CArtifactSet::serializeJsonCommander(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
logGlobal->error("CArtifactSet::serializeJsonCommander not implemented");
|
logGlobal->error("CArtifactSet::serializeJsonCommander not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const ArtifactPosition & slot, CMap * map)
|
void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const ArtifactPosition & slot)
|
||||||
{
|
{
|
||||||
ArtifactID artifactID;
|
ArtifactID artifactID;
|
||||||
|
|
||||||
@ -1057,7 +1056,7 @@ void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const Artifa
|
|||||||
|
|
||||||
if(artifactID != ArtifactID::NONE)
|
if(artifactID != ArtifactID::NONE)
|
||||||
{
|
{
|
||||||
auto * artifact = ArtifactUtils::createArtifact(map, artifactID.toEnum());
|
auto * artifact = ArtifactUtils::createArtifact(artifactID.toEnum());
|
||||||
|
|
||||||
if(artifact->artType->canBePutAt(this, slot))
|
if(artifact->artType->canBePutAt(this, slot))
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,6 @@ class CArtHandler;
|
|||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
class CArtifactSet;
|
class CArtifactSet;
|
||||||
class CArtifactInstance;
|
class CArtifactInstance;
|
||||||
class CMap;
|
|
||||||
class JsonSerializeFormat;
|
class JsonSerializeFormat;
|
||||||
|
|
||||||
#define ART_BEARER_LIST \
|
#define ART_BEARER_LIST \
|
||||||
@ -233,16 +232,16 @@ public:
|
|||||||
|
|
||||||
void artDeserializationFix(CBonusSystemNode *node);
|
void artDeserializationFix(CBonusSystemNode *node);
|
||||||
|
|
||||||
void serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map);
|
void serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName);
|
||||||
protected:
|
protected:
|
||||||
std::pair<const CArtifactInstance *, const CArtifactInstance *> searchForConstituent(const ArtifactID & aid) const;
|
std::pair<const CArtifactInstance *, const CArtifactInstance *> searchForConstituent(const ArtifactID & aid) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void serializeJsonHero(JsonSerializeFormat & handler, CMap * map);
|
void serializeJsonHero(JsonSerializeFormat & handler);
|
||||||
void serializeJsonCreature(JsonSerializeFormat & handler, CMap * map);
|
void serializeJsonCreature(JsonSerializeFormat & handler);
|
||||||
void serializeJsonCommander(JsonSerializeFormat & handler, CMap * map);
|
void serializeJsonCommander(JsonSerializeFormat & handler);
|
||||||
|
|
||||||
void serializeJsonSlot(JsonSerializeFormat & handler, const ArtifactPosition & slot, CMap * map);//normal slots
|
void serializeJsonSlot(JsonSerializeFormat & handler, const ArtifactPosition & slot);//normal slots
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to try on artifacts before the claimed changes have been applied
|
// Used to try on artifacts before the claimed changes have been applied
|
||||||
|
@ -407,7 +407,8 @@ CGHeroInstance * CampaignState::crossoverDeserialize(const JsonNode & node, CMap
|
|||||||
hero->ID = Obj::HERO;
|
hero->ID = Obj::HERO;
|
||||||
hero->serializeJsonOptions(handler);
|
hero->serializeJsonOptions(handler);
|
||||||
if (map)
|
if (map)
|
||||||
hero->serializeJsonArtifacts(handler, "artifacts", map);
|
hero->serializeJsonArtifacts(handler, "artifacts");
|
||||||
|
map->addNewArtifactInstance(*hero);
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1686,7 +1686,7 @@ void CGHeroInstance::serializeCommonOptions(JsonSerializeFormat & handler)
|
|||||||
handler.serializeIdArray("spellBook", spells);
|
handler.serializeIdArray("spellBook", spells);
|
||||||
|
|
||||||
if(handler.saving)
|
if(handler.saving)
|
||||||
CArtifactSet::serializeJsonArtifacts(handler, "artifacts", nullptr);
|
CArtifactSet::serializeJsonArtifacts(handler, "artifacts");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGHeroInstance::serializeJsonOptions(JsonSerializeFormat & handler)
|
void CGHeroInstance::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||||
|
@ -519,10 +519,26 @@ void CMap::checkForObjectives()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMap::addNewArtifactInstance(CArtifactSet & artSet)
|
||||||
|
{
|
||||||
|
for(const auto & [slot, slotInfo] : artSet.artifactsWorn)
|
||||||
|
{
|
||||||
|
if(!slotInfo.locked && slotInfo.getArt())
|
||||||
|
addNewArtifactInstance(slotInfo.artifact);
|
||||||
|
}
|
||||||
|
for(const auto & slotInfo : artSet.artifactsInBackpack)
|
||||||
|
addNewArtifactInstance(slotInfo.artifact);
|
||||||
|
}
|
||||||
|
|
||||||
void CMap::addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art)
|
void CMap::addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art)
|
||||||
{
|
{
|
||||||
|
assert(art);
|
||||||
|
assert(art->getId() == -1);
|
||||||
art->setId(static_cast<ArtifactInstanceID>(artInstances.size()));
|
art->setId(static_cast<ArtifactInstanceID>(artInstances.size()));
|
||||||
artInstances.emplace_back(art);
|
artInstances.emplace_back(art);
|
||||||
|
|
||||||
|
for(const auto & partInfo : art->getPartsInfo())
|
||||||
|
addNewArtifactInstance(partInfo.art);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMap::eraseArtifactInstance(CArtifactInstance * art)
|
void CMap::eraseArtifactInstance(CArtifactInstance * art)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class CArtifactInstance;
|
class CArtifactInstance;
|
||||||
|
class CArtifactSet;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
class CCommanderInstance;
|
class CCommanderInstance;
|
||||||
@ -102,6 +103,7 @@ public:
|
|||||||
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
|
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
|
||||||
void calculateGuardingGreaturePositions();
|
void calculateGuardingGreaturePositions();
|
||||||
|
|
||||||
|
void addNewArtifactInstance(CArtifactSet & artSet);
|
||||||
void addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art);
|
void addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art);
|
||||||
void eraseArtifactInstance(CArtifactInstance * art);
|
void eraseArtifactInstance(CArtifactInstance * art);
|
||||||
|
|
||||||
|
@ -954,10 +954,11 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
|
|||||||
// H3 bug workaround - Enemy hero on 3rd scenario of Good1.h3c campaign ("Long Live The Queen")
|
// H3 bug workaround - Enemy hero on 3rd scenario of Good1.h3c campaign ("Long Live The Queen")
|
||||||
// He has Shackles of War (normally - MISC slot artifact) in LEFT_HAND slot set in editor
|
// He has Shackles of War (normally - MISC slot artifact) in LEFT_HAND slot set in editor
|
||||||
// Artifact seems to be missing in game, so skip artifacts that don't fit target slot
|
// Artifact seems to be missing in game, so skip artifacts that don't fit target slot
|
||||||
auto * artifact = ArtifactUtils::createArtifact(map, artifactID);
|
auto * artifact = ArtifactUtils::createArtifact(artifactID);
|
||||||
if(artifact->canBePutAt(hero, ArtifactPosition(slot)))
|
if(artifact->canBePutAt(hero, ArtifactPosition(slot)))
|
||||||
{
|
{
|
||||||
artifact->putAt(*hero, ArtifactPosition(slot));
|
artifact->putAt(*hero, ArtifactPosition(slot));
|
||||||
|
map->addNewArtifactInstance(artifact);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1305,7 +1306,8 @@ CGObjectInstance * CMapLoaderH3M::readArtifact(const int3 & mapPosition, std::sh
|
|||||||
artID = ArtifactID(objectTemplate->subid);
|
artID = ArtifactID(objectTemplate->subid);
|
||||||
}
|
}
|
||||||
|
|
||||||
object->storedArtifact = ArtifactUtils::createArtifact(map, artID, spellID.getNum());
|
object->storedArtifact = ArtifactUtils::createArtifact(artID, spellID.getNum());
|
||||||
|
map->addNewArtifactInstance(object->storedArtifact);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1107,13 +1107,15 @@ void CMapLoaderJson::MapObjectLoader::configure()
|
|||||||
artID = art->getArtifact();
|
artID = art->getArtifact();
|
||||||
}
|
}
|
||||||
|
|
||||||
art->storedArtifact = ArtifactUtils::createArtifact(owner->map, artID, spellID.getNum());
|
art->storedArtifact = ArtifactUtils::createArtifact(artID, spellID.getNum());
|
||||||
|
owner->map->addNewArtifactInstance(art->storedArtifact);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(auto * hero = dynamic_cast<CGHeroInstance *>(instance))
|
if(auto * hero = dynamic_cast<CGHeroInstance *>(instance))
|
||||||
{
|
{
|
||||||
auto o = handler.enterStruct("options");
|
auto o = handler.enterStruct("options");
|
||||||
hero->serializeJsonArtifacts(handler, "artifacts", owner->map);
|
hero->serializeJsonArtifacts(handler, "artifacts");
|
||||||
|
owner->map->addNewArtifactInstance(*hero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user