2014-03-17 22:51:07 +03:00
|
|
|
/*
|
|
|
|
* CArtHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
|
2023-05-17 15:52:16 +02:00
|
|
|
#include "ArtifactUtils.h"
|
2008-11-30 02:15:38 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "GameSettings.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "mapObjects/MapObjects.h"
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "constants/StringConstants.h"
|
2010-12-26 16:34:11 +02:00
|
|
|
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "mapObjectConstructors/AObjectTypeHandler.h"
|
|
|
|
#include "mapObjectConstructors/CObjectClassesHandler.h"
|
2016-11-13 12:38:42 +02:00
|
|
|
#include "serializer/JsonSerializeFormat.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
// Note: list must match entries in ArtTraits.txt
|
|
|
|
#define ART_POS_LIST \
|
|
|
|
ART_POS(SPELLBOOK) \
|
|
|
|
ART_POS(MACH4) \
|
|
|
|
ART_POS(MACH3) \
|
|
|
|
ART_POS(MACH2) \
|
|
|
|
ART_POS(MACH1) \
|
|
|
|
ART_POS(MISC5) \
|
|
|
|
ART_POS(MISC4) \
|
|
|
|
ART_POS(MISC3) \
|
|
|
|
ART_POS(MISC2) \
|
|
|
|
ART_POS(MISC1) \
|
|
|
|
ART_POS(FEET) \
|
|
|
|
ART_POS(LEFT_RING) \
|
|
|
|
ART_POS(RIGHT_RING) \
|
|
|
|
ART_POS(TORSO) \
|
|
|
|
ART_POS(LEFT_HAND) \
|
|
|
|
ART_POS(RIGHT_HAND) \
|
|
|
|
ART_POS(NECK) \
|
|
|
|
ART_POS(SHOULDERS) \
|
2014-10-02 18:43:46 +03:00
|
|
|
ART_POS(HEAD)
|
2012-12-10 16:55:54 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-06-29 17:34:07 +02:00
|
|
|
bool CCombinedArtifact::isCombined() const
|
|
|
|
{
|
2023-07-03 18:15:40 +02:00
|
|
|
return !(constituents.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<CArtifact*> & CCombinedArtifact::getConstituents() const
|
|
|
|
{
|
|
|
|
return constituents;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<CArtifact*> & CCombinedArtifact::getPartOf() const
|
|
|
|
{
|
|
|
|
return partOf;
|
2023-06-29 17:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CScrollArtifact::isScroll() const
|
|
|
|
{
|
|
|
|
return static_cast<const CArtifact*>(this)->getId() == ArtifactID::SPELL_SCROLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGrowingArtifact::isGrowing() const
|
|
|
|
{
|
|
|
|
return !bonusesPerLevel.empty() || !thresholdBonuses.empty();
|
|
|
|
}
|
|
|
|
|
2023-07-03 18:15:40 +02:00
|
|
|
std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getBonusesPerLevel()
|
|
|
|
{
|
|
|
|
return bonusesPerLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getBonusesPerLevel() const
|
|
|
|
{
|
|
|
|
return bonusesPerLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getThresholdBonuses()
|
|
|
|
{
|
|
|
|
return thresholdBonuses;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector <std::pair<ui16, Bonus>> & CGrowingArtifact::getThresholdBonuses() const
|
|
|
|
{
|
|
|
|
return thresholdBonuses;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t CArtifact::getIndex() const
|
|
|
|
{
|
|
|
|
return id.toEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t CArtifact::getIconIndex() const
|
|
|
|
{
|
|
|
|
return iconIndex;
|
|
|
|
}
|
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
std::string CArtifact::getJsonKey() const
|
2009-04-04 01:34:31 +03:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return modScope + ':' + identifier;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifact::registerIcons(const IconRegistar & cb) const
|
|
|
|
{
|
2022-11-29 14:47:51 +02:00
|
|
|
cb(getIconIndex(), 0, "ARTIFACT", image);
|
|
|
|
cb(getIconIndex(), 0, "ARTIFACTLARGE", large);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ArtifactID CArtifact::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
const IBonusBearer * CArtifact::getBonusBearer() const
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-01-02 15:58:56 +02:00
|
|
|
std::string CArtifact::getDescriptionTranslated() const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->translate(getDescriptionTextID());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CArtifact::getEventTranslated() const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->translate(getEventTextID());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CArtifact::getNameTranslated() const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->translate(getNameTextID());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CArtifact::getDescriptionTextID() const
|
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return TextIdentifier("artifact", modScope, identifier, "description").get();
|
2023-01-02 15:58:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CArtifact::getEventTextID() const
|
2009-04-04 01:34:31 +03:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return TextIdentifier("artifact", modScope, identifier, "event").get();
|
2012-12-06 22:03:47 +03:00
|
|
|
}
|
2023-01-02 15:58:56 +02:00
|
|
|
|
|
|
|
std::string CArtifact::getNameTextID() const
|
2012-12-06 22:03:47 +03:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return TextIdentifier("artifact", modScope, identifier, "name").get();
|
2009-04-04 01:34:31 +03:00
|
|
|
}
|
2009-12-30 17:33:28 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
uint32_t CArtifact::getPrice() const
|
|
|
|
{
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreatureID CArtifact::getWarMachine() const
|
|
|
|
{
|
|
|
|
return warMachine;
|
|
|
|
}
|
|
|
|
|
2017-05-26 18:51:45 +02:00
|
|
|
bool CArtifact::isBig() const
|
2009-12-30 17:33:28 +02:00
|
|
|
{
|
2017-05-26 18:51:45 +02:00
|
|
|
return warMachine != CreatureID::NONE;
|
2009-12-30 17:33:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-26 18:51:45 +02:00
|
|
|
bool CArtifact::isTradable() const
|
2014-12-24 19:43:35 +02:00
|
|
|
{
|
2017-05-26 18:51:45 +02:00
|
|
|
switch(id)
|
|
|
|
{
|
|
|
|
case ArtifactID::SPELLBOOK:
|
|
|
|
case ArtifactID::GRAIL:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return !isBig();
|
|
|
|
}
|
2014-12-24 19:43:35 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 12:28:33 +02:00
|
|
|
bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) const
|
|
|
|
{
|
|
|
|
auto simpleArtCanBePutAt = [this](const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) -> bool
|
|
|
|
{
|
|
|
|
if(ArtifactUtils::isSlotBackpack(slot))
|
|
|
|
{
|
2023-03-18 12:44:01 +02:00
|
|
|
if(isBig() || !ArtifactUtils::isBackpackFreeSlots(artSet))
|
2023-03-13 12:28:33 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-21 12:13:53 +02:00
|
|
|
if(!vstd::contains(possibleSlots.at(artSet->bearerType()), slot))
|
2023-03-13 12:28:33 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return artSet->isPositionFree(slot, assumeDestRemoved);
|
|
|
|
};
|
|
|
|
|
2023-03-21 12:13:53 +02:00
|
|
|
auto artCanBePutAt = [this, simpleArtCanBePutAt](const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) -> bool
|
2023-03-13 12:28:33 +02:00
|
|
|
{
|
2023-06-29 17:34:07 +02:00
|
|
|
if(isCombined())
|
2023-03-13 12:28:33 +02:00
|
|
|
{
|
2023-03-21 12:13:53 +02:00
|
|
|
if(!simpleArtCanBePutAt(artSet, slot, assumeDestRemoved))
|
2023-03-13 12:28:33 +02:00
|
|
|
return false;
|
2023-03-21 12:13:53 +02:00
|
|
|
if(ArtifactUtils::isSlotBackpack(slot))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
CArtifactFittingSet fittingSet(artSet->bearerType());
|
|
|
|
fittingSet.artifactsWorn = artSet->artifactsWorn;
|
|
|
|
if(assumeDestRemoved)
|
|
|
|
fittingSet.removeArtifact(slot);
|
2023-07-11 14:20:32 +02:00
|
|
|
|
2023-07-03 18:15:40 +02:00
|
|
|
for(const auto art : constituents)
|
2023-03-21 12:13:53 +02:00
|
|
|
{
|
|
|
|
auto possibleSlot = ArtifactUtils::getArtAnyPosition(&fittingSet, art->getId());
|
|
|
|
if(ArtifactUtils::isSlotEquipment(possibleSlot))
|
|
|
|
{
|
|
|
|
fittingSet.setNewArtSlot(possibleSlot, nullptr, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-13 12:28:33 +02:00
|
|
|
}
|
2023-03-21 12:13:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return simpleArtCanBePutAt(artSet, slot, assumeDestRemoved);
|
2023-03-13 12:28:33 +02:00
|
|
|
}
|
2023-03-21 12:13:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(slot == ArtifactPosition::TRANSITION_POS)
|
2023-03-13 12:28:33 +02:00
|
|
|
return true;
|
2023-03-21 12:13:53 +02:00
|
|
|
|
|
|
|
if(slot == ArtifactPosition::FIRST_AVAILABLE)
|
|
|
|
{
|
|
|
|
for(const auto & slot : possibleSlots.at(artSet->bearerType()))
|
|
|
|
{
|
|
|
|
if(artCanBePutAt(artSet, slot, assumeDestRemoved))
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-19 23:22:31 +02:00
|
|
|
return artCanBePutAt(artSet, ArtifactPosition::BACKPACK_START, assumeDestRemoved);
|
2023-03-21 12:13:53 +02:00
|
|
|
}
|
|
|
|
else if(ArtifactUtils::isSlotBackpack(slot))
|
|
|
|
{
|
2023-08-19 23:22:31 +02:00
|
|
|
return artCanBePutAt(artSet, ArtifactPosition::BACKPACK_START, assumeDestRemoved);
|
2023-03-13 12:28:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-21 12:13:53 +02:00
|
|
|
return artCanBePutAt(artSet, slot, assumeDestRemoved);
|
2023-03-13 12:28:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:34:32 +03:00
|
|
|
CArtifact::CArtifact()
|
2023-07-03 22:11:56 +02:00
|
|
|
: iconIndex(ArtifactID::NONE),
|
|
|
|
price(0)
|
2010-05-09 22:10:59 +03:00
|
|
|
{
|
2011-07-13 21:39:02 +03:00
|
|
|
setNodeType(ARTIFACT);
|
2012-12-14 11:37:46 +03:00
|
|
|
possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
|
|
|
|
possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
|
|
|
|
possibleSlots[ArtBearer::COMMANDER];
|
2010-05-09 22:10:59 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
//This destructor should be placed here to avoid side effects
|
|
|
|
CArtifact::~CArtifact() = default;
|
2010-05-09 22:10:59 +03:00
|
|
|
|
2010-07-23 15:02:15 +03:00
|
|
|
int CArtifact::getArtClassSerial() const
|
|
|
|
{
|
2014-12-24 17:49:12 +02:00
|
|
|
if(id == ArtifactID::SPELL_SCROLL)
|
2010-07-23 15:02:15 +03:00
|
|
|
return 4;
|
|
|
|
switch(aClass)
|
|
|
|
{
|
|
|
|
case ART_TREASURE:
|
|
|
|
return 0;
|
|
|
|
case ART_MINOR:
|
|
|
|
return 1;
|
|
|
|
case ART_MAJOR:
|
|
|
|
return 2;
|
|
|
|
case ART_RELIC:
|
|
|
|
return 3;
|
|
|
|
case ART_SPECIAL:
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
std::string CArtifact::nodeName() const
|
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return "Artifact: " + getNameTranslated();
|
2010-12-17 20:47:07 +02:00
|
|
|
}
|
2010-11-10 02:06:25 +02:00
|
|
|
|
2016-09-19 23:36:35 +02:00
|
|
|
void CArtifact::addNewBonus(const std::shared_ptr<Bonus>& b)
|
2012-12-13 17:27:33 +03:00
|
|
|
{
|
2023-05-01 00:20:01 +02:00
|
|
|
b->source = BonusSource::ARTIFACT;
|
|
|
|
b->duration = BonusDuration::PERMANENT;
|
2023-01-02 15:58:56 +02:00
|
|
|
b->description = getNameTranslated();
|
2012-12-13 17:27:33 +03:00
|
|
|
CBonusSystemNode::addNewBonus(b);
|
|
|
|
}
|
|
|
|
|
2023-07-03 22:11:56 +02:00
|
|
|
const std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition>> & CArtifact::getPossibleSlots() const
|
|
|
|
{
|
|
|
|
return possibleSlots;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void CArtifact::updateFrom(const JsonNode& data)
|
|
|
|
{
|
|
|
|
//TODO:CArtifact::updateFrom
|
|
|
|
}
|
|
|
|
|
2023-07-03 22:11:56 +02:00
|
|
|
void CArtifact::setImage(int32_t iconIndex, std::string image, std::string large)
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
2023-07-03 22:11:56 +02:00
|
|
|
this->iconIndex = iconIndex;
|
|
|
|
this->image = image;
|
|
|
|
this->large = large;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CArtHandler::~CArtHandler() = default;
|
2010-02-16 16:39:56 +02:00
|
|
|
|
2023-03-15 21:34:29 +02:00
|
|
|
std::vector<JsonNode> CArtHandler::loadLegacyData()
|
2007-06-07 23:16:19 +03:00
|
|
|
{
|
2023-03-15 21:34:29 +02:00
|
|
|
size_t dataSize = VLC->settings()->getInteger(EGameSettings::TEXTS_ARTIFACT);
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
objects.resize(dataSize);
|
2013-04-21 15:49:26 +03:00
|
|
|
std::vector<JsonNode> h3Data;
|
|
|
|
h3Data.reserve(dataSize);
|
2013-03-02 19:55:51 +03:00
|
|
|
|
2014-10-02 18:43:46 +03:00
|
|
|
#define ART_POS(x) #x ,
|
|
|
|
const std::vector<std::string> artSlots = { ART_POS_LIST };
|
2013-03-12 17:56:23 +03:00
|
|
|
#undef ART_POS
|
2013-03-02 19:55:51 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
static std::map<char, std::string> classes =
|
2014-10-02 18:43:46 +03:00
|
|
|
{{'S',"SPECIAL"}, {'T',"TREASURE"},{'N',"MINOR"},{'J',"MAJOR"},{'R',"RELIC"},};
|
2012-08-01 15:02:54 +03:00
|
|
|
|
2023-09-01 23:26:14 +02:00
|
|
|
CLegacyConfigParser parser(TextPath::builtin("DATA/ARTRAITS.TXT"));
|
|
|
|
CLegacyConfigParser events(TextPath::builtin("DATA/ARTEVENT.TXT"));
|
2012-08-25 11:44:51 +03:00
|
|
|
|
|
|
|
parser.endLine(); // header
|
|
|
|
parser.endLine();
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
for (size_t i = 0; i < dataSize; i++)
|
2007-06-07 23:16:19 +03:00
|
|
|
{
|
2013-03-12 17:56:23 +03:00
|
|
|
JsonNode artData;
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
artData["text"]["name"].String() = parser.readString();
|
|
|
|
artData["text"]["event"].String() = events.readString();
|
|
|
|
artData["value"].Float() = parser.readNumber();
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & artSlot : artSlots)
|
2007-06-07 23:16:19 +03:00
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
if(parser.readString() == "x")
|
2012-07-16 19:18:02 +03:00
|
|
|
{
|
2013-03-12 17:56:23 +03:00
|
|
|
artData["slot"].Vector().push_back(JsonNode());
|
2013-06-29 16:05:48 +03:00
|
|
|
artData["slot"].Vector().back().String() = artSlot;
|
2012-07-16 19:18:02 +03:00
|
|
|
}
|
|
|
|
}
|
2013-03-12 17:56:23 +03:00
|
|
|
artData["class"].String() = classes[parser.readString()[0]];
|
|
|
|
artData["text"]["description"].String() = parser.readString();
|
|
|
|
|
|
|
|
parser.endLine();
|
|
|
|
events.endLine();
|
|
|
|
h3Data.push_back(artData);
|
2012-07-16 19:18:02 +03:00
|
|
|
}
|
2013-04-21 15:49:26 +03:00
|
|
|
return h3Data;
|
|
|
|
}
|
2012-07-16 19:18:02 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * object = loadFromJson(scope, data, name, objects.size());
|
2013-03-12 17:56:23 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
object->iconIndex = object->getIndex() + 5;
|
2015-11-14 15:50:29 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
objects.emplace_back(object);
|
2015-11-14 15:50:29 +02:00
|
|
|
|
2016-02-21 19:58:09 +02:00
|
|
|
registerObject(scope, "artifact", name, object->id);
|
2007-06-08 17:58:04 +03:00
|
|
|
}
|
2008-08-30 00:41:32 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
2012-12-10 16:55:54 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * object = loadFromJson(scope, data, name, index);
|
2015-11-14 15:50:29 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
object->iconIndex = object->getIndex();
|
2015-11-14 15:50:29 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
assert(objects[index] == nullptr); // ensure that this id was not loaded before
|
|
|
|
objects[index] = object;
|
2015-11-14 15:50:29 +02:00
|
|
|
|
2016-02-21 19:58:09 +02:00
|
|
|
registerObject(scope, "artifact", name, object->id);
|
2012-12-10 16:55:54 +03:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const std::vector<std::string> & CArtHandler::getTypeNames() const
|
|
|
|
{
|
|
|
|
static const std::vector<std::string> typeNames = { "artifact" };
|
|
|
|
return typeNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index)
|
2012-12-10 16:55:54 +03:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
assert(identifier.find(':') == std::string::npos);
|
|
|
|
assert(!scope.empty());
|
|
|
|
|
2023-06-29 17:34:07 +02:00
|
|
|
CArtifact * art = new CArtifact();
|
|
|
|
if(!node["growing"].isNull())
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
2023-06-29 17:34:07 +02:00
|
|
|
for(auto bonus : node["growing"]["bonusesPerLevel"].Vector())
|
|
|
|
{
|
|
|
|
art->bonusesPerLevel.emplace_back(static_cast<ui16>(bonus["level"].Float()), Bonus());
|
|
|
|
JsonUtils::parseBonus(bonus["bonus"], &art->bonusesPerLevel.back().second);
|
|
|
|
}
|
|
|
|
for(auto bonus : node["growing"]["thresholdBonuses"].Vector())
|
|
|
|
{
|
|
|
|
art->thresholdBonuses.emplace_back(static_cast<ui16>(bonus["level"].Float()), Bonus());
|
|
|
|
JsonUtils::parseBonus(bonus["bonus"], &art->thresholdBonuses.back().second);
|
|
|
|
}
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
art->id = ArtifactID(index);
|
2015-08-24 10:55:45 +02:00
|
|
|
art->identifier = identifier;
|
2023-01-02 15:58:56 +02:00
|
|
|
art->modScope = scope;
|
|
|
|
|
2012-12-10 16:55:54 +03:00
|
|
|
const JsonNode & text = node["text"];
|
2023-01-02 15:58:56 +02:00
|
|
|
|
2023-02-09 15:03:49 +02:00
|
|
|
VLC->generaltexth->registerString(scope, art->getNameTextID(), text["name"].String());
|
|
|
|
VLC->generaltexth->registerString(scope, art->getDescriptionTextID(), text["description"].String());
|
|
|
|
VLC->generaltexth->registerString(scope, art->getEventTextID(), text["event"].String());
|
2012-12-10 16:55:54 +03:00
|
|
|
|
2012-12-13 18:38:04 +03:00
|
|
|
const JsonNode & graphics = node["graphics"];
|
2012-12-13 17:27:33 +03:00
|
|
|
art->image = graphics["image"].String();
|
2013-03-02 19:55:51 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(!graphics["large"].isNull())
|
2013-04-02 20:06:43 +03:00
|
|
|
art->large = graphics["large"].String();
|
|
|
|
else
|
2013-03-02 19:55:51 +03:00
|
|
|
art->large = art->image;
|
|
|
|
|
2012-12-16 14:35:14 +03:00
|
|
|
art->advMapDef = graphics["map"].String();
|
2012-12-10 16:55:54 +03:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
art->price = static_cast<ui32>(node["value"].Float());
|
2023-07-17 17:21:28 +02:00
|
|
|
art->onlyOnWaterMap = node["onlyOnWaterMap"].Bool();
|
2013-03-12 17:56:23 +03:00
|
|
|
|
|
|
|
loadSlots(art, node);
|
|
|
|
loadClass(art, node);
|
|
|
|
loadType(art, node);
|
|
|
|
loadComponents(art, node);
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & b : node["bonuses"].Vector())
|
2013-03-12 17:56:23 +03:00
|
|
|
{
|
2016-09-19 23:36:35 +02:00
|
|
|
auto bonus = JsonUtils::parseBonus(b);
|
2013-07-21 17:19:29 +03:00
|
|
|
art->addNewBonus(bonus);
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
2017-05-26 18:51:45 +02:00
|
|
|
|
|
|
|
const JsonNode & warMachine = node["warMachine"];
|
2022-11-15 02:20:55 +02:00
|
|
|
if(warMachine.getType() == JsonNode::JsonType::DATA_STRING && !warMachine.String().empty())
|
2017-05-26 18:51:45 +02:00
|
|
|
{
|
2023-07-30 19:12:25 +02:00
|
|
|
VLC->identifiers()->requestIdentifier("creature", warMachine, [=](si32 id)
|
2017-05-26 18:51:45 +02:00
|
|
|
{
|
|
|
|
art->warMachine = CreatureID(id);
|
|
|
|
|
|
|
|
//this assumes that creature object is stored before registration
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
VLC->creh->objects.at(id)->warMachine = art->id;
|
2017-05-26 18:51:45 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
VLC->identifiers()->requestIdentifier(scope, "object", "artifact", [=](si32 index)
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
|
|
|
JsonNode conf;
|
|
|
|
conf.setMeta(scope);
|
|
|
|
|
2023-01-19 01:43:12 +02:00
|
|
|
VLC->objtypeh->loadSubObject(art->identifier, conf, Obj::ARTIFACT, art->getIndex());
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
|
|
|
if(!art->advMapDef.empty())
|
|
|
|
{
|
|
|
|
JsonNode templ;
|
|
|
|
templ["animation"].String() = art->advMapDef;
|
2022-11-29 22:34:32 +02:00
|
|
|
templ.setMeta(scope);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
|
|
|
// add new template.
|
|
|
|
// Necessary for objects added via mods that don't have any templates in H3
|
|
|
|
VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, art->getIndex())->addTemplate(templ);
|
|
|
|
}
|
|
|
|
// object does not have any templates - this is not usable object (e.g. pseudo-art like lock)
|
|
|
|
if(VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, art->getIndex())->getTemplates().empty())
|
|
|
|
VLC->objtypeh->removeSubObject(Obj::ARTIFACT, art->getIndex());
|
|
|
|
});
|
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
return art;
|
|
|
|
}
|
|
|
|
|
2023-08-19 23:22:31 +02:00
|
|
|
int32_t ArtifactPositionBase::decode(const std::string & slotName)
|
2013-03-12 17:56:23 +03:00
|
|
|
{
|
2014-10-02 18:43:46 +03:00
|
|
|
#define ART_POS(x) { #x, ArtifactPosition::x },
|
|
|
|
static const std::map<std::string, ArtifactPosition> artifactPositionMap = { ART_POS_LIST };
|
2013-03-12 17:56:23 +03:00
|
|
|
#undef ART_POS
|
2014-06-22 13:39:40 +03:00
|
|
|
auto it = artifactPositionMap.find (slotName);
|
|
|
|
if (it != artifactPositionMap.end())
|
2023-08-19 23:22:31 +02:00
|
|
|
return it->second;
|
2023-02-15 12:10:39 +02:00
|
|
|
else
|
2023-08-19 23:22:31 +02:00
|
|
|
return PRE_FIRST;
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
2013-03-12 17:56:23 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CArtHandler::addSlot(CArtifact * art, const std::string & slotID) const
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2015-11-14 15:50:29 +02:00
|
|
|
static const std::vector<ArtifactPosition> miscSlots =
|
2014-10-03 23:34:13 +03:00
|
|
|
{
|
|
|
|
ArtifactPosition::MISC1, ArtifactPosition::MISC2, ArtifactPosition::MISC3, ArtifactPosition::MISC4, ArtifactPosition::MISC5
|
|
|
|
};
|
2015-11-14 15:50:29 +02:00
|
|
|
|
2014-10-03 23:34:13 +03:00
|
|
|
static const std::vector<ArtifactPosition> ringSlots =
|
|
|
|
{
|
2023-03-07 13:13:30 +02:00
|
|
|
ArtifactPosition::RIGHT_RING, ArtifactPosition::LEFT_RING
|
2014-10-03 23:34:13 +03:00
|
|
|
};
|
2015-11-14 15:50:29 +02:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
if (slotID == "MISC")
|
2012-12-14 11:37:46 +03:00
|
|
|
{
|
2014-10-03 23:34:13 +03:00
|
|
|
vstd::concatenate(art->possibleSlots[ArtBearer::HERO], miscSlots);
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
|
|
|
else if (slotID == "RING")
|
|
|
|
{
|
2014-10-03 23:34:13 +03:00
|
|
|
vstd::concatenate(art->possibleSlots[ArtBearer::HERO], ringSlots);
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-19 23:22:31 +02:00
|
|
|
auto slot = ArtifactPosition::decode(slotID);
|
2014-06-22 13:39:40 +03:00
|
|
|
if (slot != ArtifactPosition::PRE_FIRST)
|
2023-03-07 13:13:30 +02:00
|
|
|
art->possibleSlots[ArtBearer::HERO].push_back(slot);
|
2012-12-14 11:37:46 +03:00
|
|
|
}
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
2013-02-05 00:58:42 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node) const
|
2013-03-12 17:56:23 +03:00
|
|
|
{
|
2013-03-02 19:55:51 +03:00
|
|
|
if (!node["slot"].isNull()) //we assume non-hero slots are irrelevant?
|
2012-12-10 17:28:27 +03:00
|
|
|
{
|
2017-11-26 23:18:18 +02:00
|
|
|
if (node["slot"].getType() == JsonNode::JsonType::DATA_STRING)
|
2013-03-12 17:56:23 +03:00
|
|
|
addSlot(art, node["slot"].String());
|
2012-12-10 16:55:54 +03:00
|
|
|
else
|
2012-12-14 11:37:46 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (const JsonNode & slot : node["slot"].Vector())
|
2013-03-12 17:56:23 +03:00
|
|
|
addSlot(art, slot.String());
|
2012-12-14 11:37:46 +03:00
|
|
|
}
|
2023-03-07 13:13:30 +02:00
|
|
|
std::sort(art->possibleSlots.at(ArtBearer::HERO).begin(), art->possibleSlots.at(ArtBearer::HERO).end());
|
2012-12-10 16:55:54 +03:00
|
|
|
}
|
2013-03-02 19:55:51 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CArtifact::EartClass CArtHandler::stringToClass(const std::string & className)
|
2013-03-02 19:55:51 +03:00
|
|
|
{
|
2014-10-02 18:43:46 +03:00
|
|
|
static const std::map<std::string, CArtifact::EartClass> artifactClassMap =
|
2015-11-14 15:50:29 +02:00
|
|
|
{
|
2014-10-02 18:43:46 +03:00
|
|
|
{"TREASURE", CArtifact::ART_TREASURE},
|
|
|
|
{"MINOR", CArtifact::ART_MINOR},
|
|
|
|
{"MAJOR", CArtifact::ART_MAJOR},
|
|
|
|
{"RELIC", CArtifact::ART_RELIC},
|
|
|
|
{"SPECIAL", CArtifact::ART_SPECIAL}
|
|
|
|
};
|
2013-03-12 17:56:23 +03:00
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
auto it = artifactClassMap.find (className);
|
2013-03-12 17:56:23 +03:00
|
|
|
if (it != artifactClassMap.end())
|
2014-06-22 13:39:40 +03:00
|
|
|
return it->second;
|
|
|
|
|
2017-08-30 23:23:19 +02:00
|
|
|
logMod->warn("Warning! Artifact rarity %s not recognized!", className);
|
2014-06-22 13:39:40 +03:00
|
|
|
return CArtifact::ART_SPECIAL;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CArtHandler::loadClass(CArtifact * art, const JsonNode & node) const
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
|
|
|
art->aClass = stringToClass(node["class"].String());
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CArtHandler::loadType(CArtifact * art, const JsonNode & node) const
|
2013-03-12 17:56:23 +03:00
|
|
|
{
|
2014-10-02 18:43:46 +03:00
|
|
|
#define ART_BEARER(x) { #x, ArtBearer::x },
|
|
|
|
static const std::map<std::string, int> artifactBearerMap = { ART_BEARER_LIST };
|
2013-03-12 17:56:23 +03:00
|
|
|
#undef ART_BEARER
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for (const JsonNode & b : node["type"].Vector())
|
2012-12-10 16:55:54 +03:00
|
|
|
{
|
2013-03-02 19:55:51 +03:00
|
|
|
auto it = artifactBearerMap.find (b.String());
|
|
|
|
if (it != artifactBearerMap.end())
|
|
|
|
{
|
|
|
|
int bearerType = it->second;
|
|
|
|
switch (bearerType)
|
|
|
|
{
|
|
|
|
case ArtBearer::HERO://TODO: allow arts having several possible bearers
|
|
|
|
break;
|
|
|
|
case ArtBearer::COMMANDER:
|
|
|
|
makeItCommanderArt (art); //original artifacts should have only one bearer type
|
|
|
|
break;
|
|
|
|
case ArtBearer::CREATURE:
|
|
|
|
makeItCreatureArt (art);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-08-30 23:23:19 +02:00
|
|
|
logMod->warn("Warning! Artifact type %s not recognized!", b.String());
|
2012-12-10 16:55:54 +03:00
|
|
|
}
|
2013-03-12 17:56:23 +03:00
|
|
|
}
|
2012-12-10 16:55:54 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
void CArtHandler::loadComponents(CArtifact * art, const JsonNode & node)
|
|
|
|
{
|
|
|
|
if (!node["components"].isNull())
|
2013-03-02 19:55:51 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & component : node["components"].Vector())
|
2013-03-02 19:55:51 +03:00
|
|
|
{
|
2023-07-30 19:12:25 +02:00
|
|
|
VLC->identifiers()->requestIdentifier("artifact", component, [=](si32 id)
|
2013-03-02 19:55:51 +03:00
|
|
|
{
|
|
|
|
// when this code is called both combinational art as well as component are loaded
|
|
|
|
// so it is safe to access any of them
|
2023-07-03 18:15:40 +02:00
|
|
|
art->constituents.push_back(objects[id]);
|
2023-06-29 17:34:07 +02:00
|
|
|
objects[id]->partOf.push_back(art);
|
2013-03-02 19:55:51 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2012-12-10 16:55:54 +03:00
|
|
|
}
|
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags, std::function<bool(ArtifactID)> accepts)
|
2010-06-28 08:07:21 +03:00
|
|
|
{
|
2023-09-29 14:55:31 +02:00
|
|
|
std::set<ArtifactID> potentialPicks;
|
|
|
|
|
|
|
|
// Select artifacts that satisfy provided criterias
|
|
|
|
for (auto const * artifact : allowedArtifacts)
|
2010-06-28 08:07:21 +03:00
|
|
|
{
|
2023-09-29 14:55:31 +02:00
|
|
|
assert(artifact->aClass != CArtifact::ART_SPECIAL); // should be filtered out when allowedArtifacts is initialized
|
2008-11-30 02:15:38 +02:00
|
|
|
|
2023-09-29 14:55:31 +02:00
|
|
|
if ((flags & CArtifact::ART_TREASURE) == 0 && artifact->aClass == CArtifact::ART_TREASURE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((flags & CArtifact::ART_MINOR) == 0 && artifact->aClass == CArtifact::ART_MINOR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((flags & CArtifact::ART_MAJOR) == 0 && artifact->aClass == CArtifact::ART_MAJOR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((flags & CArtifact::ART_RELIC) == 0 && artifact->aClass == CArtifact::ART_RELIC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!accepts(artifact->id))
|
|
|
|
continue;
|
2013-02-13 01:24:48 +03:00
|
|
|
|
2023-09-29 14:55:31 +02:00
|
|
|
potentialPicks.insert(artifact->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pickRandomArtifact(rand, potentialPicks);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, std::set<ArtifactID> potentialPicks)
|
|
|
|
{
|
|
|
|
// No allowed artifacts at all - give Grail - this can't be banned (hopefully)
|
|
|
|
// FIXME: investigate how such cases are handled by H3 - some heavily customized user-made maps likely rely on H3 behavior
|
|
|
|
if (potentialPicks.empty())
|
2010-06-28 08:07:21 +03:00
|
|
|
{
|
2023-09-29 14:55:31 +02:00
|
|
|
logGlobal->warn("Failed to find artifact that matches requested parameters!");
|
|
|
|
return ArtifactID::GRAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find how many times least used artifacts were picked by randomizer
|
|
|
|
int leastUsedTimes = std::numeric_limits<int>::max();
|
|
|
|
for (auto const & artifact : potentialPicks)
|
|
|
|
if (allocatedArtifacts[artifact] < leastUsedTimes)
|
|
|
|
leastUsedTimes = allocatedArtifacts[artifact];
|
|
|
|
|
|
|
|
// Pick all artifacts that were used least number of times
|
|
|
|
std::set<ArtifactID> preferredPicks;
|
|
|
|
for (auto const & artifact : potentialPicks)
|
|
|
|
if (allocatedArtifacts[artifact] == leastUsedTimes)
|
|
|
|
preferredPicks.insert(artifact);
|
2013-02-13 01:24:48 +03:00
|
|
|
|
2023-09-29 14:55:31 +02:00
|
|
|
assert(!preferredPicks.empty());
|
|
|
|
|
|
|
|
ArtifactID artID = *RandomGeneratorUtil::nextItem(preferredPicks, rand);
|
|
|
|
allocatedArtifacts[artID] += 1; // record +1 more usage
|
2013-02-13 01:24:48 +03:00
|
|
|
return artID;
|
2010-06-28 08:07:21 +03:00
|
|
|
}
|
2012-08-26 12:07:48 +03:00
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return pickRandomArtifact(rand, 0xff, std::move(accepts));
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return pickRandomArtifact(rand, flags, [](const ArtifactID &) { return true; });
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
void CArtHandler::makeItCreatureArt(CArtifact * a, bool onlyCreature)
|
2012-04-18 16:24:18 +03:00
|
|
|
{
|
|
|
|
if (onlyCreature)
|
|
|
|
{
|
|
|
|
a->possibleSlots[ArtBearer::HERO].clear();
|
2012-05-20 11:39:19 +03:00
|
|
|
a->possibleSlots[ArtBearer::COMMANDER].clear();
|
2012-04-18 16:24:18 +03:00
|
|
|
}
|
|
|
|
a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
|
2012-09-15 22:16:16 +03:00
|
|
|
}
|
2008-11-30 02:15:38 +02:00
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
void CArtHandler::makeItCommanderArt(CArtifact * a, bool onlyCommander)
|
2012-12-27 14:00:28 +03:00
|
|
|
{
|
2012-05-20 11:39:19 +03:00
|
|
|
if (onlyCommander)
|
|
|
|
{
|
|
|
|
a->possibleSlots[ArtBearer::HERO].clear();
|
|
|
|
a->possibleSlots[ArtBearer::CREATURE].clear();
|
|
|
|
}
|
|
|
|
for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
|
2013-02-12 22:49:40 +03:00
|
|
|
a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(i));
|
2012-09-15 22:16:16 +03:00
|
|
|
}
|
2012-05-19 21:27:23 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CArtHandler::legalArtifact(const ArtifactID & id)
|
2013-01-21 18:11:37 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
auto art = objects[id];
|
2013-03-02 12:11:52 +03:00
|
|
|
//assert ( (!art->constituents) || art->constituents->size() ); //artifacts is not combined or has some components
|
2023-03-15 21:34:29 +02:00
|
|
|
|
2023-07-03 18:15:40 +02:00
|
|
|
if(art->isCombined())
|
2023-03-15 21:34:29 +02:00
|
|
|
return false; //no combo artifacts spawning
|
|
|
|
|
|
|
|
if(art->aClass < CArtifact::ART_TREASURE || art->aClass > CArtifact::ART_RELIC)
|
|
|
|
return false; // invalid class
|
|
|
|
|
|
|
|
if(!art->possibleSlots[ArtBearer::HERO].empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(!art->possibleSlots[ArtBearer::CREATURE].empty() && VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_ARTIFACT))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(!art->possibleSlots[ArtBearer::COMMANDER].empty() && VLC->settings()->getBoolean(EGameSettings::MODULE_COMMANDERS))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2013-01-21 18:11:37 +03:00
|
|
|
}
|
|
|
|
|
2013-02-05 00:58:42 +03:00
|
|
|
void CArtHandler::initAllowedArtifactsList(const std::vector<bool> &allowed)
|
2010-08-18 12:50:25 +03:00
|
|
|
{
|
|
|
|
allowedArtifacts.clear();
|
2023-09-29 14:55:31 +02:00
|
|
|
allocatedArtifacts.clear();
|
2013-03-29 22:15:52 +03:00
|
|
|
|
2023-06-16 18:10:48 +02:00
|
|
|
for (ArtifactID i=ArtifactID::SPELLBOOK; i < ArtifactID(static_cast<si32>(objects.size())); i.advance(1))
|
2010-08-18 12:50:25 +03:00
|
|
|
{
|
2023-06-16 18:10:48 +02:00
|
|
|
if (allowed[i] && legalArtifact(ArtifactID(i)))
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
allowedArtifacts.push_back(objects[i]);
|
2023-09-29 14:55:31 +02:00
|
|
|
//keep im mind that artifact can be worn by more than one type of bearer
|
2012-12-14 11:37:46 +03:00
|
|
|
}
|
2010-08-21 03:39:37 +03:00
|
|
|
}
|
2010-12-17 20:47:07 +02:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
std::vector<bool> CArtHandler::getDefaultAllowed() const
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-02-05 00:58:42 +03:00
|
|
|
std::vector<bool> allowedArtifacts;
|
|
|
|
allowedArtifacts.resize(127, true);
|
|
|
|
allowedArtifacts.resize(141, false);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
allowedArtifacts.resize(size(), true);
|
2013-01-06 22:30:12 +03:00
|
|
|
return allowedArtifacts;
|
|
|
|
}
|
|
|
|
|
2013-07-21 17:19:29 +03:00
|
|
|
void CArtHandler::afterLoadFinalization()
|
|
|
|
{
|
|
|
|
//All artifacts have their id, so we can properly update their bonuses' source ids.
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
for(auto &art : objects)
|
2013-07-21 17:19:29 +03:00
|
|
|
{
|
|
|
|
for(auto &bonus : art->getExportedBonusList())
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
assert(art == objects[art->id]);
|
2023-05-01 00:20:01 +02:00
|
|
|
assert(bonus->source == BonusSource::ARTIFACT);
|
2023-10-21 13:50:42 +02:00
|
|
|
bonus->sid = BonusSourceID(art->id);
|
2013-07-21 17:19:29 +03:00
|
|
|
}
|
|
|
|
}
|
2015-12-11 15:13:18 +02:00
|
|
|
CBonusSystemNode::treeHasChanged();
|
2013-07-21 17:19:29 +03:00
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
CArtifactSet::~CArtifactSet() = default;
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CArtifactInstance * CArtifactSet::getArt(const ArtifactPosition & pos, bool excludeLocked) const
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2023-06-22 16:08:16 +02:00
|
|
|
if(const ArtSlotInfo * si = getSlot(pos))
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
|
|
|
if(si->artifact && (!excludeLocked || !si->locked))
|
|
|
|
return si->artifact;
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CArtifactInstance * CArtifactSet::getArt(const ArtifactPosition & pos, bool excludeLocked)
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2012-04-14 05:20:22 +03:00
|
|
|
return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
ArtifactPosition CArtifactSet::getArtPos(const ArtifactID & aid, bool onlyWorn, bool allowLocked) const
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2022-10-01 08:28:32 +02:00
|
|
|
const auto result = getAllArtPositions(aid, onlyWorn, allowLocked, false);
|
|
|
|
return result.empty() ? ArtifactPosition{ArtifactPosition::PRE_FIRST} : result[0];
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(const ArtifactID & aid, bool onlyWorn, bool allowLocked, bool getAll) const
|
2022-10-01 08:28:32 +02:00
|
|
|
{
|
|
|
|
std::vector<ArtifactPosition> result;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & slotInfo : artifactsWorn)
|
2023-03-21 12:13:53 +02:00
|
|
|
if(slotInfo.second.artifact->getTypeId() == aid && (allowLocked || !slotInfo.second.locked))
|
2022-11-17 19:43:54 +02:00
|
|
|
result.push_back(slotInfo.first);
|
2011-06-24 20:43:02 +03:00
|
|
|
|
|
|
|
if(onlyWorn)
|
2022-10-01 08:28:32 +02:00
|
|
|
return result;
|
|
|
|
if(!getAll && !result.empty())
|
|
|
|
return result;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
2022-11-17 19:43:54 +02:00
|
|
|
auto backpackPositions = getBackpackArtPositions(aid);
|
|
|
|
result.insert(result.end(), backpackPositions.begin(), backpackPositions.end());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::vector<ArtifactPosition> CArtifactSet::getBackpackArtPositions(const ArtifactID & aid) const
|
2022-11-17 19:43:54 +02:00
|
|
|
{
|
|
|
|
std::vector<ArtifactPosition> result;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
2023-08-19 23:22:31 +02:00
|
|
|
si32 backpackPosition = ArtifactPosition::BACKPACK_START;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & artInfo : artifactsInBackpack)
|
2022-11-17 19:43:54 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * art = artInfo.getArt();
|
2023-01-02 15:58:56 +02:00
|
|
|
if(art && art->artType->getId() == aid)
|
2022-11-18 22:15:03 +02:00
|
|
|
result.emplace_back(backpackPosition);
|
2022-11-17 19:43:54 +02:00
|
|
|
backpackPosition++;
|
|
|
|
}
|
2022-10-01 08:28:32 +02:00
|
|
|
return result;
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2013-02-12 22:49:40 +03:00
|
|
|
ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto i : artifactsWorn)
|
2013-02-07 02:24:43 +03:00
|
|
|
if(i.second.artifact == art)
|
|
|
|
return i.first;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
|
|
|
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
|
|
|
if(artifactsInBackpack[i].artifact == art)
|
2023-08-19 23:22:31 +02:00
|
|
|
return ArtifactPosition::BACKPACK_START + i;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
2013-02-07 02:24:43 +03:00
|
|
|
return ArtifactPosition::PRE_FIRST;
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CArtifactInstance * CArtifactSet::getArtByInstanceId(const ArtifactInstanceID & artInstId) const
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto i : artifactsWorn)
|
2023-07-03 22:11:56 +02:00
|
|
|
if(i.second.artifact->getId() == artInstId)
|
2013-02-07 02:24:43 +03:00
|
|
|
return i.second.artifact;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto i : artifactsInBackpack)
|
2023-07-03 22:11:56 +02:00
|
|
|
if(i.artifact->getId() == artInstId)
|
2013-02-07 02:24:43 +03:00
|
|
|
return i.artifact;
|
2011-06-24 20:43:02 +03:00
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2023-04-23 13:48:04 +02:00
|
|
|
const ArtifactPosition CArtifactSet::getSlotByInstance(const CArtifactInstance * artInst) const
|
|
|
|
{
|
|
|
|
if(artInst)
|
|
|
|
{
|
2023-07-03 22:11:56 +02:00
|
|
|
for(const auto & slot : artInst->artType->getPossibleSlots().at(bearerType()))
|
2023-04-23 13:48:04 +02:00
|
|
|
if(getArt(slot) == artInst)
|
|
|
|
return slot;
|
|
|
|
|
2023-08-19 23:22:31 +02:00
|
|
|
ArtifactPosition backpackSlot = ArtifactPosition::BACKPACK_START;
|
2023-04-23 13:48:04 +02:00
|
|
|
for(auto & slotInfo : artifactsInBackpack)
|
|
|
|
{
|
|
|
|
if(slotInfo.getArt() == artInst)
|
|
|
|
return backpackSlot;
|
|
|
|
backpackSlot = ArtifactPosition(backpackSlot + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ArtifactPosition::PRE_FIRST;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CArtifactSet::hasArt(const ArtifactID & aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
2012-04-14 05:20:22 +03:00
|
|
|
{
|
2022-10-01 08:28:32 +02:00
|
|
|
return getArtPosCount(aid, onlyWorn, searchBackpackAssemblies, allowLocked) > 0;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CArtifactSet::hasArtBackpack(const ArtifactID & aid) const
|
2022-11-17 19:43:54 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return !getBackpackArtPositions(aid).empty();
|
2022-11-17 19:43:54 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
unsigned CArtifactSet::getArtPosCount(const ArtifactID & aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
2022-10-01 08:28:32 +02:00
|
|
|
{
|
|
|
|
const auto allPositions = getAllArtPositions(aid, onlyWorn, allowLocked, true);
|
|
|
|
if(!allPositions.empty())
|
|
|
|
return allPositions.size();
|
|
|
|
|
|
|
|
if(searchBackpackAssemblies && getHiddenArt(aid))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
2016-01-22 11:53:01 +02:00
|
|
|
}
|
|
|
|
|
2023-07-24 18:09:17 +02:00
|
|
|
CArtifactSet::ArtPlacementMap CArtifactSet::putArtifact(ArtifactPosition slot, CArtifactInstance * art)
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
2023-07-24 18:09:17 +02:00
|
|
|
ArtPlacementMap resArtPlacement;
|
|
|
|
|
2023-05-17 16:01:22 +02:00
|
|
|
setNewArtSlot(slot, art, false);
|
2023-06-29 17:34:07 +02:00
|
|
|
if(art->artType->isCombined() && ArtifactUtils::isSlotEquipment(slot))
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
|
|
|
const CArtifactInstance * mainPart = nullptr;
|
2023-07-03 18:15:40 +02:00
|
|
|
for(const auto & part : art->getPartsInfo())
|
2023-07-03 22:11:56 +02:00
|
|
|
if(vstd::contains(part.art->artType->getPossibleSlots().at(bearerType()), slot)
|
2023-06-06 13:37:48 +02:00
|
|
|
&& (part.slot == ArtifactPosition::PRE_FIRST))
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
|
|
|
mainPart = part.art;
|
|
|
|
break;
|
|
|
|
}
|
2023-07-24 18:09:17 +02:00
|
|
|
|
|
|
|
for(const auto & part : art->getPartsInfo())
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
|
|
|
if(part.art != mainPart)
|
|
|
|
{
|
2023-07-24 18:09:17 +02:00
|
|
|
auto partSlot = part.slot;
|
|
|
|
if(!part.art->artType->canBePutAt(this, partSlot))
|
|
|
|
partSlot = ArtifactUtils::getArtAnyPosition(this, part.art->getTypeId());
|
2023-05-17 16:01:22 +02:00
|
|
|
|
2023-07-24 18:09:17 +02:00
|
|
|
assert(ArtifactUtils::isSlotEquipment(partSlot));
|
|
|
|
setNewArtSlot(partSlot, part.art, true);
|
|
|
|
resArtPlacement.emplace(std::make_pair(part.art, partSlot));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resArtPlacement.emplace(std::make_pair(part.art, part.slot));
|
2023-05-17 16:01:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-24 18:09:17 +02:00
|
|
|
return resArtPlacement;
|
2023-05-17 16:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactSet::removeArtifact(ArtifactPosition slot)
|
|
|
|
{
|
|
|
|
auto art = getArt(slot, false);
|
|
|
|
if(art)
|
|
|
|
{
|
2023-06-29 17:34:07 +02:00
|
|
|
if(art->isCombined())
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
2023-07-03 18:15:40 +02:00
|
|
|
for(auto & part : art->getPartsInfo())
|
2023-05-17 16:01:22 +02:00
|
|
|
{
|
|
|
|
if(getArt(part.slot, false))
|
|
|
|
eraseArtSlot(part.slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eraseArtSlot(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-18 14:21:35 +02:00
|
|
|
std::pair<const CArtifactInstance *, const CArtifactInstance *> CArtifactSet::searchForConstituent(const ArtifactID & aid) const
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & slot : artifactsInBackpack)
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
|
|
|
auto art = slot.artifact;
|
2023-06-29 17:34:07 +02:00
|
|
|
if(art->isCombined())
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
2023-07-03 18:15:40 +02:00
|
|
|
for(auto & ci : art->getPartsInfo())
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
2023-03-21 12:13:53 +02:00
|
|
|
if(ci.art->getTypeId() == aid)
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
2023-06-18 14:21:35 +02:00
|
|
|
return {art, ci.art};
|
2016-01-22 11:53:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {nullptr, nullptr};
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CArtifactInstance * CArtifactSet::getHiddenArt(const ArtifactID & aid) const
|
2016-01-22 11:53:01 +02:00
|
|
|
{
|
|
|
|
return searchForConstituent(aid).second;
|
|
|
|
}
|
|
|
|
|
2023-06-18 14:21:35 +02:00
|
|
|
const CArtifactInstance * CArtifactSet::getAssemblyByConstituent(const ArtifactID & aid) const
|
2012-04-14 05:20:22 +03:00
|
|
|
{
|
2016-01-22 11:53:01 +02:00
|
|
|
return searchForConstituent(aid).first;
|
2012-04-14 05:20:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const ArtSlotInfo * CArtifactSet::getSlot(const ArtifactPosition & pos) const
|
2014-01-03 02:48:38 +03:00
|
|
|
{
|
2022-12-28 21:58:32 +02:00
|
|
|
if(pos == ArtifactPosition::TRANSITION_POS)
|
2022-12-29 20:39:01 +02:00
|
|
|
{
|
|
|
|
// Always add to the end. Always take from the beginning.
|
2023-02-10 13:46:34 +02:00
|
|
|
if(artifactsTransitionPos.empty())
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return &(*artifactsTransitionPos.begin());
|
2022-12-29 20:39:01 +02:00
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
if(vstd::contains(artifactsWorn, pos))
|
|
|
|
return &artifactsWorn.at(pos);
|
|
|
|
if(pos >= ArtifactPosition::AFTER_LAST )
|
|
|
|
{
|
2023-08-19 23:22:31 +02:00
|
|
|
int backpackPos = (int)pos - ArtifactPosition::BACKPACK_START;
|
2011-06-24 20:43:02 +03:00
|
|
|
if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2011-06-24 20:43:02 +03:00
|
|
|
else
|
|
|
|
return &artifactsInBackpack[backpackPos];
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CArtifactSet::isPositionFree(const ArtifactPosition & pos, bool onlyLockCheck) const
|
2012-04-14 05:20:22 +03:00
|
|
|
{
|
|
|
|
if(const ArtSlotInfo *s = getSlot(pos))
|
|
|
|
return (onlyLockCheck || !s->artifact) && !s->locked;
|
|
|
|
|
|
|
|
return true; //no slot means not used
|
|
|
|
}
|
|
|
|
|
2023-07-24 18:09:17 +02:00
|
|
|
void CArtifactSet::setNewArtSlot(const ArtifactPosition & slot, ConstTransitivePtr<CArtifactInstance> art, bool locked)
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
|
|
|
assert(!vstd::contains(artifactsWorn, slot));
|
|
|
|
|
2023-05-17 16:02:58 +02:00
|
|
|
ArtSlotInfo * slotInfo;
|
2022-12-28 21:58:32 +02:00
|
|
|
if(slot == ArtifactPosition::TRANSITION_POS)
|
2022-12-29 20:39:01 +02:00
|
|
|
{
|
|
|
|
// Always add to the end. Always take from the beginning.
|
2023-03-13 23:26:44 +02:00
|
|
|
artifactsTransitionPos.emplace_back();
|
2023-05-17 16:02:58 +02:00
|
|
|
slotInfo = &artifactsTransitionPos.back();
|
2022-12-29 20:39:01 +02:00
|
|
|
}
|
2023-05-17 16:02:58 +02:00
|
|
|
else if(ArtifactUtils::isSlotEquipment(slot))
|
|
|
|
{
|
|
|
|
slotInfo = &artifactsWorn[slot];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-19 23:22:31 +02:00
|
|
|
auto position = artifactsInBackpack.begin() + slot - ArtifactPosition::BACKPACK_START;
|
2023-05-17 16:02:58 +02:00
|
|
|
slotInfo = &(*artifactsInBackpack.emplace(position, ArtSlotInfo()));
|
|
|
|
}
|
|
|
|
slotInfo->artifact = art;
|
|
|
|
slotInfo->locked = locked;
|
2012-04-14 05:20:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CArtifactSet::eraseArtSlot(const ArtifactPosition & slot)
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2022-12-29 20:39:01 +02:00
|
|
|
if(slot == ArtifactPosition::TRANSITION_POS)
|
|
|
|
{
|
|
|
|
assert(!artifactsTransitionPos.empty());
|
|
|
|
artifactsTransitionPos.erase(artifactsTransitionPos.begin());
|
|
|
|
}
|
|
|
|
else if(ArtifactUtils::isSlotBackpack(slot))
|
2011-06-24 20:43:02 +03:00
|
|
|
{
|
2023-08-19 23:22:31 +02:00
|
|
|
auto backpackSlot = ArtifactPosition(slot - ArtifactPosition::BACKPACK_START);
|
2022-12-18 14:33:59 +02:00
|
|
|
|
|
|
|
assert(artifactsInBackpack.begin() + backpackSlot < artifactsInBackpack.end());
|
|
|
|
artifactsInBackpack.erase(artifactsInBackpack.begin() + backpackSlot);
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-29 01:20:31 +02:00
|
|
|
artifactsWorn.erase(slot);
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
2011-08-13 13:54:23 +03:00
|
|
|
}
|
|
|
|
|
2012-04-14 05:20:22 +03:00
|
|
|
void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
|
2011-08-13 13:54:23 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : artifactsWorn)
|
|
|
|
if(elem.second.artifact && !elem.second.locked)
|
2022-11-06 01:26:13 +02:00
|
|
|
node->attachTo(*elem.second.artifact);
|
2012-04-14 19:28:36 +03:00
|
|
|
}
|
2016-01-24 01:27:14 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map)
|
|
|
|
{
|
|
|
|
//todo: creature and commander artifacts
|
|
|
|
if(handler.saving && artifactsInBackpack.empty() && artifactsWorn.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!handler.saving)
|
|
|
|
{
|
|
|
|
assert(map);
|
|
|
|
artifactsInBackpack.clear();
|
|
|
|
artifactsWorn.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto s = handler.enterStruct(fieldName);
|
|
|
|
|
|
|
|
switch(bearerType())
|
|
|
|
{
|
|
|
|
case ArtBearer::HERO:
|
|
|
|
serializeJsonHero(handler, map);
|
|
|
|
break;
|
|
|
|
case ArtBearer::CREATURE:
|
|
|
|
serializeJsonCreature(handler, map);
|
|
|
|
break;
|
|
|
|
case ArtBearer::COMMANDER:
|
|
|
|
serializeJsonCommander(handler, map);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
|
|
|
|
{
|
|
|
|
for(ArtifactPosition ap = ArtifactPosition::HEAD; ap < ArtifactPosition::AFTER_LAST; ap.advance(1))
|
|
|
|
{
|
|
|
|
serializeJsonSlot(handler, ap, map);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ArtifactID> backpackTemp;
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
backpackTemp.reserve(artifactsInBackpack.size());
|
|
|
|
for(const ArtSlotInfo & info : artifactsInBackpack)
|
2023-03-21 12:13:53 +02:00
|
|
|
backpackTemp.push_back(info.artifact->getTypeId());
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeIdArray(NArtifactPosition::backpack, backpackTemp);
|
2016-11-13 12:38:42 +02:00
|
|
|
if(!handler.saving)
|
|
|
|
{
|
2023-01-02 15:58:56 +02:00
|
|
|
for(const ArtifactID & artifactID : backpackTemp)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-10-05 12:37:02 +02:00
|
|
|
auto * artifact = ArtifactUtils::createArtifact(map, artifactID);
|
|
|
|
auto slot = ArtifactPosition::BACKPACK_START + artifactsInBackpack.size();
|
2023-03-13 12:28:33 +02:00
|
|
|
if(artifact->artType->canBePutAt(this, slot))
|
2023-10-05 12:37:02 +02:00
|
|
|
{
|
|
|
|
auto artsMap = putArtifact(slot, artifact);
|
|
|
|
artifact->addPlacementMap(artsMap);
|
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactSet::serializeJsonCreature(JsonSerializeFormat & handler, CMap * map)
|
2016-01-24 01:27:14 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
logGlobal->error("CArtifactSet::serializeJsonCreature not implemented");
|
|
|
|
}
|
2016-01-24 01:27:14 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CArtifactSet::serializeJsonCommander(JsonSerializeFormat & handler, CMap * map)
|
|
|
|
{
|
|
|
|
logGlobal->error("CArtifactSet::serializeJsonCommander not implemented");
|
2016-01-24 01:27:14 +02:00
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const ArtifactPosition & slot, CMap * map)
|
2016-01-24 01:27:14 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
ArtifactID artifactID;
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
const ArtSlotInfo * info = getSlot(slot);
|
|
|
|
|
|
|
|
if(info != nullptr && !info->locked)
|
|
|
|
{
|
2023-03-21 12:13:53 +02:00
|
|
|
artifactID = info->artifact->getTypeId();
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeId(NArtifactPosition::namesHero[slot.num], artifactID, ArtifactID::NONE);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeId(NArtifactPosition::namesHero[slot.num], artifactID, ArtifactID::NONE);
|
2016-01-24 01:27:14 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
if(artifactID != ArtifactID::NONE)
|
|
|
|
{
|
2023-05-17 15:52:16 +02:00
|
|
|
auto * artifact = ArtifactUtils::createArtifact(map, artifactID.toEnum());
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-03-13 12:28:33 +02:00
|
|
|
if(artifact->artType->canBePutAt(this, slot))
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-10-05 12:37:02 +02:00
|
|
|
auto artsMap = putArtifact(slot, artifact);
|
|
|
|
artifact->addPlacementMap(artsMap);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->debug("Artifact can't be put at the specified location."); //TODO add more debugging information
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-24 01:27:14 +02:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CArtifactFittingSet::CArtifactFittingSet(ArtBearer::ArtBearer Bearer):
|
|
|
|
Bearer(Bearer)
|
2022-11-06 23:29:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtBearer::ArtBearer CArtifactFittingSet::bearerType() const
|
|
|
|
{
|
|
|
|
return this->Bearer;
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|