mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
vcmi: modernize rest of lib
This commit is contained in:
@@ -36,6 +36,10 @@
|
||||
#include "serializer/BinaryDeserializer.h"
|
||||
#include <vcmi/events/EventBus.h>
|
||||
|
||||
#if SCRIPTING_ENABLED
|
||||
#include "../lib/ScriptHandler.h"
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#include "lib/CAndroidVMHelper.h"
|
||||
|
||||
|
@@ -18,12 +18,12 @@ BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, co
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
|
||||
BattleFieldInfo * info = new BattleFieldInfo(BattleField(index), identifier);
|
||||
auto * info = new BattleFieldInfo(BattleField(index), identifier);
|
||||
|
||||
info->graphics = json["graphics"].String();
|
||||
info->icon = json["icon"].String();
|
||||
info->name = json["name"].String();
|
||||
for(auto b : json["bonuses"].Vector())
|
||||
for(const auto & b : json["bonuses"].Vector())
|
||||
{
|
||||
auto bonus = JsonUtils::parseBonus(b);
|
||||
|
||||
@@ -36,7 +36,7 @@ BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, co
|
||||
|
||||
info->isSpecial = json["isSpecial"].Bool();
|
||||
for(auto node : json["impassableHexes"].Vector())
|
||||
info->impassableHexes.push_back(BattleHex(node.Integer()));
|
||||
info->impassableHexes.emplace_back(node.Integer());
|
||||
|
||||
return info;
|
||||
}
|
||||
|
@@ -144,14 +144,10 @@ CArtifact::CArtifact()
|
||||
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];
|
||||
iconIndex = ArtifactID::NONE;
|
||||
price = 0;
|
||||
aClass = ART_SPECIAL;
|
||||
}
|
||||
|
||||
CArtifact::~CArtifact()
|
||||
{
|
||||
}
|
||||
//This destructor should be placed here to avoid side effects
|
||||
CArtifact::~CArtifact() = default;
|
||||
|
||||
int CArtifact::getArtClassSerial() const
|
||||
{
|
||||
@@ -205,14 +201,14 @@ void CGrowingArtifact::levelUpArtifact (CArtifactInstance * art)
|
||||
b->duration = Bonus::COMMANDER_KILLED;
|
||||
art->accumulateBonus(b);
|
||||
|
||||
for (auto bonus : bonusesPerLevel)
|
||||
for(const auto & bonus : bonusesPerLevel)
|
||||
{
|
||||
if (art->valOfBonuses(Bonus::LEVEL_COUNTER) % bonus.first == 0) //every n levels
|
||||
{
|
||||
art->accumulateBonus(std::make_shared<Bonus>(bonus.second));
|
||||
}
|
||||
}
|
||||
for (auto bonus : thresholdBonuses)
|
||||
for(const auto & bonus : thresholdBonuses)
|
||||
{
|
||||
if (art->valOfBonuses(Bonus::LEVEL_COUNTER) == bonus.first) //every n levels
|
||||
{
|
||||
@@ -221,10 +217,6 @@ void CGrowingArtifact::levelUpArtifact (CArtifactInstance * art)
|
||||
}
|
||||
}
|
||||
|
||||
CArtHandler::CArtHandler()
|
||||
{
|
||||
}
|
||||
|
||||
CArtHandler::~CArtHandler() = default;
|
||||
|
||||
std::vector<JsonNode> CArtHandler::loadLegacyData(size_t dataSize)
|
||||
@@ -254,7 +246,7 @@ std::vector<JsonNode> CArtHandler::loadLegacyData(size_t dataSize)
|
||||
artData["text"]["event"].String() = events.readString();
|
||||
artData["value"].Float() = parser.readNumber();
|
||||
|
||||
for(auto & artSlot : artSlots)
|
||||
for(const auto & artSlot : artSlots)
|
||||
{
|
||||
if(parser.readString() == "x")
|
||||
{
|
||||
@@ -274,18 +266,18 @@ std::vector<JsonNode> CArtHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(scope, data, name, objects.size());
|
||||
auto * object = loadFromJson(scope, data, name, objects.size());
|
||||
|
||||
object->iconIndex = object->getIndex() + 5;
|
||||
|
||||
objects.push_back(object);
|
||||
objects.emplace_back(object);
|
||||
|
||||
registerObject(scope, "artifact", name, object->id);
|
||||
}
|
||||
|
||||
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(scope, data, name, index);
|
||||
auto * object = loadFromJson(scope, data, name, index);
|
||||
|
||||
object->iconIndex = object->getIndex();
|
||||
|
||||
@@ -306,7 +298,7 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
assert(!scope.empty());
|
||||
|
||||
CArtifact * art;
|
||||
CArtifact * art = nullptr;
|
||||
|
||||
if(!VLC->modh->modules.COMMANDERS || node["growing"].isNull())
|
||||
{
|
||||
@@ -314,7 +306,7 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode
|
||||
}
|
||||
else
|
||||
{
|
||||
auto growing = new CGrowingArtifact();
|
||||
auto * growing = new CGrowingArtifact();
|
||||
loadGrowingArt(growing, node);
|
||||
art = growing;
|
||||
}
|
||||
@@ -345,7 +337,7 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode
|
||||
loadType(art, node);
|
||||
loadComponents(art, node);
|
||||
|
||||
for(auto b : node["bonuses"].Vector())
|
||||
for(const auto & b : node["bonuses"].Vector())
|
||||
{
|
||||
auto bonus = JsonUtils::parseBonus(b);
|
||||
art->addNewBonus(bonus);
|
||||
@@ -401,7 +393,7 @@ ArtifactPosition::ArtifactPosition(std::string slotName):
|
||||
logMod->warn("Warning! Artifact slot %s not recognized!", slotName);
|
||||
}
|
||||
|
||||
void CArtHandler::addSlot(CArtifact * art, const std::string & slotID)
|
||||
void CArtHandler::addSlot(CArtifact * art, const std::string & slotID) const
|
||||
{
|
||||
static const std::vector<ArtifactPosition> miscSlots =
|
||||
{
|
||||
@@ -429,7 +421,7 @@ void CArtHandler::addSlot(CArtifact * art, const std::string & slotID)
|
||||
}
|
||||
}
|
||||
|
||||
void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node)
|
||||
void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node) const
|
||||
{
|
||||
if (!node["slot"].isNull()) //we assume non-hero slots are irrelevant?
|
||||
{
|
||||
@@ -444,7 +436,7 @@ void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node)
|
||||
}
|
||||
}
|
||||
|
||||
CArtifact::EartClass CArtHandler::stringToClass(std::string className)
|
||||
CArtifact::EartClass CArtHandler::stringToClass(const std::string & className)
|
||||
{
|
||||
static const std::map<std::string, CArtifact::EartClass> artifactClassMap =
|
||||
{
|
||||
@@ -463,12 +455,12 @@ CArtifact::EartClass CArtHandler::stringToClass(std::string className)
|
||||
return CArtifact::ART_SPECIAL;
|
||||
}
|
||||
|
||||
void CArtHandler::loadClass(CArtifact * art, const JsonNode & node)
|
||||
void CArtHandler::loadClass(CArtifact * art, const JsonNode & node) const
|
||||
{
|
||||
art->aClass = stringToClass(node["class"].String());
|
||||
}
|
||||
|
||||
void CArtHandler::loadType(CArtifact * art, const JsonNode & node)
|
||||
void CArtHandler::loadType(CArtifact * art, const JsonNode & node) const
|
||||
{
|
||||
#define ART_BEARER(x) { #x, ArtBearer::x },
|
||||
static const std::map<std::string, int> artifactBearerMap = { ART_BEARER_LIST };
|
||||
@@ -501,8 +493,8 @@ void CArtHandler::loadComponents(CArtifact * art, const JsonNode & node)
|
||||
{
|
||||
if (!node["components"].isNull())
|
||||
{
|
||||
art->constituents.reset(new std::vector<CArtifact *>());
|
||||
for (auto component : node["components"].Vector())
|
||||
art->constituents = std::make_unique<std::vector<CArtifact *>>();
|
||||
for(const auto & component : node["components"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("artifact", component, [=](si32 id)
|
||||
{
|
||||
@@ -515,16 +507,16 @@ void CArtHandler::loadComponents(CArtifact * art, const JsonNode & node)
|
||||
}
|
||||
}
|
||||
|
||||
void CArtHandler::loadGrowingArt(CGrowingArtifact * art, const JsonNode & node)
|
||||
void CArtHandler::loadGrowingArt(CGrowingArtifact * art, const JsonNode & node) const
|
||||
{
|
||||
for (auto b : node["growing"]["bonusesPerLevel"].Vector())
|
||||
{
|
||||
art->bonusesPerLevel.push_back(std::pair <ui16, Bonus>((ui16)b["level"].Float(), Bonus()));
|
||||
art->bonusesPerLevel.emplace_back(static_cast<ui16>(b["level"].Float()), Bonus());
|
||||
JsonUtils::parseBonus(b["bonus"], &art->bonusesPerLevel.back().second);
|
||||
}
|
||||
for (auto b : node["growing"]["thresholdBonuses"].Vector())
|
||||
{
|
||||
art->thresholdBonuses.push_back(std::pair <ui16, Bonus>((ui16)b["level"].Float(), Bonus()));
|
||||
art->thresholdBonuses.emplace_back(static_cast<ui16>(b["level"].Float()), Bonus());
|
||||
JsonUtils::parseBonus(b["bonus"], &art->thresholdBonuses.back().second);
|
||||
}
|
||||
}
|
||||
@@ -541,7 +533,7 @@ ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags, s
|
||||
if (accepts(arts_i->id))
|
||||
{
|
||||
CArtifact *art = arts_i;
|
||||
out.push_back(art);
|
||||
out.emplace_back(art);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -556,14 +548,14 @@ ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags, s
|
||||
getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
|
||||
if (flags & CArtifact::ART_RELIC)
|
||||
getAllowedArts (out, &relics, CArtifact::ART_RELIC);
|
||||
if (!out.size()) //no artifact of specified rarity, we need to take another one
|
||||
if(out.empty()) //no artifact of specified rarity, we need to take another one
|
||||
{
|
||||
getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
|
||||
getAllowedArts (out, &minors, CArtifact::ART_MINOR);
|
||||
getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
|
||||
getAllowedArts (out, &relics, CArtifact::ART_RELIC);
|
||||
}
|
||||
if (!out.size()) //no arts are available at all
|
||||
if(out.empty()) //no arts are available at all
|
||||
{
|
||||
out.resize (64);
|
||||
std::fill_n (out.begin(), 64, objects[2]); //Give Grail - this can't be banned (hopefully)
|
||||
@@ -579,12 +571,12 @@ ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags, s
|
||||
|
||||
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts)
|
||||
{
|
||||
return pickRandomArtifact(rand, 0xff, accepts);
|
||||
return pickRandomArtifact(rand, 0xff, std::move(accepts));
|
||||
}
|
||||
|
||||
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags)
|
||||
{
|
||||
return pickRandomArtifact(rand, flags, [](ArtifactID){ return true;});
|
||||
return pickRandomArtifact(rand, flags, [](const ArtifactID &) { return true; });
|
||||
}
|
||||
|
||||
void CArtHandler::makeItCreatureArt(CArtifact * a, bool onlyCreature)
|
||||
@@ -608,13 +600,13 @@ void CArtHandler::makeItCommanderArt(CArtifact * a, bool onlyCommander)
|
||||
a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(i));
|
||||
}
|
||||
|
||||
bool CArtHandler::legalArtifact(ArtifactID id)
|
||||
bool CArtHandler::legalArtifact(const ArtifactID & id)
|
||||
{
|
||||
auto art = objects[id];
|
||||
//assert ( (!art->constituents) || art->constituents->size() ); //artifacts is not combined or has some components
|
||||
return ((art->possibleSlots[ArtBearer::HERO].size() ||
|
||||
(art->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS) ||
|
||||
(art->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT)) &&
|
||||
return ((!art->possibleSlots[ArtBearer::HERO].empty() ||
|
||||
(!art->possibleSlots[ArtBearer::COMMANDER].empty() && VLC->modh->modules.COMMANDERS) ||
|
||||
(!art->possibleSlots[ArtBearer::CREATURE].empty() && VLC->modh->modules.STACK_ARTIFACT)) &&
|
||||
!(art->constituents) && //no combo artifacts spawning
|
||||
art->aClass >= CArtifact::ART_TREASURE &&
|
||||
art->aClass <= CArtifact::ART_RELIC);
|
||||
@@ -635,7 +627,7 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<bool> &allowed)
|
||||
if (allowed[i] && legalArtifact(i))
|
||||
allowedArtifacts.push_back(objects[i]);
|
||||
}
|
||||
for (ArtifactID i = ArtifactID::ART_SELECTION; i<ArtifactID((si32)objects.size()); i.advance(1)) //try to allow all artifacts added by mods
|
||||
for(ArtifactID i = ArtifactID::ART_SELECTION; i < ArtifactID(static_cast<si32>(objects.size())); i.advance(1)) //try to allow all artifacts added by mods
|
||||
{
|
||||
if (legalArtifact(ArtifactID(i)))
|
||||
allowedArtifacts.push_back(objects[i]);
|
||||
@@ -652,7 +644,7 @@ std::vector<bool> CArtHandler::getDefaultAllowed() const
|
||||
return allowedArtifacts;
|
||||
}
|
||||
|
||||
void CArtHandler::erasePickedArt(ArtifactID id)
|
||||
void CArtHandler::erasePickedArt(const ArtifactID & id)
|
||||
{
|
||||
CArtifact *art = objects[id];
|
||||
|
||||
@@ -738,9 +730,9 @@ std::string CArtifactInstance::nodeName() const
|
||||
return "Artifact instance of " + (artType ? artType->getJsonKey() : std::string("uninitialized")) + " type";
|
||||
}
|
||||
|
||||
CArtifactInstance *CArtifactInstance::createScroll(SpellID sid)
|
||||
CArtifactInstance * CArtifactInstance::createScroll(const SpellID & sid)
|
||||
{
|
||||
auto ret = new CArtifactInstance(VLC->arth->objects[ArtifactID::SPELL_SCROLL]);
|
||||
auto * ret = new CArtifactInstance(VLC->arth->objects[ArtifactID::SPELL_SCROLL]);
|
||||
auto b = std::make_shared<Bonus>(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, ArtifactID::SPELL_SCROLL, sid);
|
||||
ret->addNewBonus(b);
|
||||
return ret;
|
||||
@@ -773,14 +765,14 @@ std::string CArtifactInstance::getEffectiveDescription(const CGHeroInstance * he
|
||||
text = text.replace(nameStart, nameEnd - nameStart + 1, spellID.toSpell(VLC->spells())->getNameTranslated());
|
||||
}
|
||||
}
|
||||
else if(hero && artType->constituentOf.size()) //display info about set
|
||||
else if(hero && !artType->constituentOf.empty()) //display info about set
|
||||
{
|
||||
std::string artList;
|
||||
auto combinedArt = artType->constituentOf[0];
|
||||
auto * combinedArt = artType->constituentOf[0];
|
||||
text += "\n\n";
|
||||
text += "{" + combinedArt->getNameTranslated() + "}";
|
||||
int wornArtifacts = 0;
|
||||
for(auto a : *combinedArt->constituents) //TODO: can the artifact be a part of more than one set?
|
||||
for(auto * a : *combinedArt->constituents) //TODO: can the artifact be a part of more than one set?
|
||||
{
|
||||
artList += "\n" + a->getNameTranslated();
|
||||
if (hero->hasArt(a->getId(), true))
|
||||
@@ -796,7 +788,7 @@ std::string CArtifactInstance::getEffectiveDescription(const CGHeroInstance * he
|
||||
|
||||
ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
|
||||
{
|
||||
for(auto slot : artType->possibleSlots.at(h->bearerType()))
|
||||
for(const auto & slot : artType->possibleSlots.at(h->bearerType()))
|
||||
{
|
||||
if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
|
||||
{
|
||||
@@ -812,8 +804,7 @@ ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) co
|
||||
ArtifactPosition CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
|
||||
{
|
||||
if(!artType->isBig()) //discard big artifact
|
||||
return ArtifactPosition(
|
||||
GameConstants::BACKPACK_START + (si32)h->artifactsInBackpack.size());
|
||||
return ArtifactPosition(GameConstants::BACKPACK_START + static_cast<si32>(h->artifactsInBackpack.size()));
|
||||
|
||||
return ArtifactPosition::PRE_FIRST;
|
||||
}
|
||||
@@ -914,7 +905,7 @@ std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CA
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
|
||||
void CArtifactInstance::move(const ArtifactLocation & src, const ArtifactLocation & dst)
|
||||
{
|
||||
removeFrom(src);
|
||||
putAt(dst);
|
||||
@@ -924,7 +915,7 @@ CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
|
||||
{
|
||||
if(!Art->constituents)
|
||||
{
|
||||
auto ret = new CArtifactInstance(Art);
|
||||
auto * ret = new CArtifactInstance(Art);
|
||||
if (dynamic_cast<CGrowingArtifact *>(Art))
|
||||
{
|
||||
auto bonus = std::make_shared<Bonus>();
|
||||
@@ -936,18 +927,18 @@ CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ret = new CCombinedArtifactInstance(Art);
|
||||
auto * ret = new CCombinedArtifactInstance(Art);
|
||||
ret->createConstituents();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
CArtifactInstance * CArtifactInstance::createNewArtifactInstance(ArtifactID aid)
|
||||
CArtifactInstance * CArtifactInstance::createNewArtifactInstance(const ArtifactID & aid)
|
||||
{
|
||||
return createNewArtifactInstance(VLC->arth->objects[aid]);
|
||||
}
|
||||
|
||||
CArtifactInstance * CArtifactInstance::createArtifact(CMap * map, ArtifactID aid, int spellID)
|
||||
CArtifactInstance * CArtifactInstance::createArtifact(CMap * map, const ArtifactID & aid, int spellID)
|
||||
{
|
||||
CArtifactInstance * a = nullptr;
|
||||
if(aid >= 0)
|
||||
@@ -971,7 +962,7 @@ CArtifactInstance * CArtifactInstance::createArtifact(CMap * map, ArtifactID aid
|
||||
//TODO make it nicer
|
||||
if(a->artType && (!!a->artType->constituents))
|
||||
{
|
||||
CCombinedArtifactInstance * comb = dynamic_cast<CCombinedArtifactInstance *>(a);
|
||||
auto * comb = dynamic_cast<CCombinedArtifactInstance *>(a);
|
||||
for(CCombinedArtifactInstance::ConstituentInfo & ci : comb->constituentsInfo)
|
||||
{
|
||||
map->addNewArtifactInstance(ci.art);
|
||||
@@ -1054,10 +1045,6 @@ CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
|
||||
{
|
||||
}
|
||||
|
||||
CCombinedArtifactInstance::CCombinedArtifactInstance()
|
||||
{
|
||||
}
|
||||
|
||||
void CCombinedArtifactInstance::createConstituents()
|
||||
{
|
||||
assert(artType);
|
||||
@@ -1069,13 +1056,13 @@ void CCombinedArtifactInstance::createConstituents()
|
||||
}
|
||||
}
|
||||
|
||||
void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, ArtifactPosition slot)
|
||||
void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance * art, const ArtifactPosition & slot)
|
||||
{
|
||||
assert(vstd::contains_if(*artType->constituents, [=](const CArtifact * constituent){
|
||||
return constituent->getId() == art->artType->getId();
|
||||
}));
|
||||
assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
|
||||
constituentsInfo.push_back(ConstituentInfo(art, slot));
|
||||
constituentsInfo.emplace_back(art, slot);
|
||||
attachTo(*art);
|
||||
}
|
||||
|
||||
@@ -1145,7 +1132,7 @@ void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
|
||||
}
|
||||
}
|
||||
|
||||
CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
|
||||
CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation & al)
|
||||
{
|
||||
CArtifactInstance *mainConstituent = nullptr; //it'll be replaced with combined artifact, not a lock
|
||||
for(ConstituentInfo &ci : constituentsInfo)
|
||||
@@ -1186,10 +1173,10 @@ bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) co
|
||||
return false;
|
||||
}
|
||||
|
||||
CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art, ArtifactPosition Slot)
|
||||
CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance * Art, const ArtifactPosition & Slot):
|
||||
art(Art),
|
||||
slot(Slot)
|
||||
{
|
||||
art = Art;
|
||||
slot = Slot;
|
||||
}
|
||||
|
||||
bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
|
||||
@@ -1199,7 +1186,7 @@ bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInf
|
||||
|
||||
CArtifactSet::~CArtifactSet() = default;
|
||||
|
||||
const CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked) const
|
||||
const CArtifactInstance * CArtifactSet::getArt(const ArtifactPosition & pos, bool excludeLocked) const
|
||||
{
|
||||
if(const ArtSlotInfo *si = getSlot(pos))
|
||||
{
|
||||
@@ -1210,27 +1197,27 @@ const CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool exclude
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked)
|
||||
CArtifactInstance * CArtifactSet::getArt(const ArtifactPosition & pos, bool excludeLocked)
|
||||
{
|
||||
return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
|
||||
}
|
||||
|
||||
ArtifactPosition CArtifactSet::getArtPos(ArtifactID aid, bool onlyWorn, bool allowLocked) const
|
||||
ArtifactPosition CArtifactSet::getArtPos(const ArtifactID & aid, bool onlyWorn, bool allowLocked) const
|
||||
{
|
||||
const auto result = getAllArtPositions(aid, onlyWorn, allowLocked, false);
|
||||
return result.empty() ? ArtifactPosition{ArtifactPosition::PRE_FIRST} : result[0];
|
||||
}
|
||||
|
||||
ArtifactPosition CArtifactSet::getArtBackpackPos(ArtifactID aid) const
|
||||
ArtifactPosition CArtifactSet::getArtBackpackPos(const ArtifactID & aid) const
|
||||
{
|
||||
const auto result = getBackpackArtPositions(aid);
|
||||
return result.empty() ? ArtifactPosition{ArtifactPosition::PRE_FIRST} : result[0];
|
||||
}
|
||||
|
||||
std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(ArtifactID aid, bool onlyWorn, bool allowLocked, bool getAll) const
|
||||
std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(const ArtifactID & aid, bool onlyWorn, bool allowLocked, bool getAll) const
|
||||
{
|
||||
std::vector<ArtifactPosition> result;
|
||||
for(auto & slotInfo : artifactsWorn)
|
||||
for(const auto & slotInfo : artifactsWorn)
|
||||
if(slotInfo.second.artifact->artType->getId() == aid && (allowLocked || !slotInfo.second.locked))
|
||||
result.push_back(slotInfo.first);
|
||||
|
||||
@@ -1244,14 +1231,14 @@ std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(ArtifactID aid, b
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<ArtifactPosition> CArtifactSet::getBackpackArtPositions(ArtifactID aid) const
|
||||
std::vector<ArtifactPosition> CArtifactSet::getBackpackArtPositions(const ArtifactID & aid) const
|
||||
{
|
||||
std::vector<ArtifactPosition> result;
|
||||
|
||||
si32 backpackPosition = GameConstants::BACKPACK_START;
|
||||
for(auto & artInfo : artifactsInBackpack)
|
||||
for(const auto & artInfo : artifactsInBackpack)
|
||||
{
|
||||
auto * art = artInfo.getArt();
|
||||
const auto * art = artInfo.getArt();
|
||||
if(art && art->artType->getId() == aid)
|
||||
result.emplace_back(backpackPosition);
|
||||
backpackPosition++;
|
||||
@@ -1272,7 +1259,7 @@ ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const
|
||||
return ArtifactPosition::PRE_FIRST;
|
||||
}
|
||||
|
||||
const CArtifactInstance * CArtifactSet::getArtByInstanceId( ArtifactInstanceID artInstId ) const
|
||||
const CArtifactInstance * CArtifactSet::getArtByInstanceId(const ArtifactInstanceID & artInstId) const
|
||||
{
|
||||
for(auto i : artifactsWorn)
|
||||
if(i.second.artifact->id == artInstId)
|
||||
@@ -1285,21 +1272,17 @@ const CArtifactInstance * CArtifactSet::getArtByInstanceId( ArtifactInstanceID a
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CArtifactSet::hasArt(
|
||||
ArtifactID aid,
|
||||
bool onlyWorn,
|
||||
bool searchBackpackAssemblies,
|
||||
bool allowLocked) const
|
||||
bool CArtifactSet::hasArt(const ArtifactID & aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
||||
{
|
||||
return getArtPosCount(aid, onlyWorn, searchBackpackAssemblies, allowLocked) > 0;
|
||||
}
|
||||
|
||||
bool CArtifactSet::hasArtBackpack(ArtifactID aid) const
|
||||
bool CArtifactSet::hasArtBackpack(const ArtifactID & aid) const
|
||||
{
|
||||
return getBackpackArtPositions(aid).size() > 0;
|
||||
return !getBackpackArtPositions(aid).empty();
|
||||
}
|
||||
|
||||
unsigned CArtifactSet::getArtPosCount(ArtifactID aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
||||
unsigned CArtifactSet::getArtPosCount(const ArtifactID & aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
||||
{
|
||||
const auto allPositions = getAllArtPositions(aid, onlyWorn, allowLocked, true);
|
||||
if(!allPositions.empty())
|
||||
@@ -1311,15 +1294,14 @@ unsigned CArtifactSet::getArtPosCount(ArtifactID aid, bool onlyWorn, bool search
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::pair<const CCombinedArtifactInstance *, const CArtifactInstance *>
|
||||
CArtifactSet::searchForConstituent(ArtifactID aid) const
|
||||
std::pair<const CCombinedArtifactInstance *, const CArtifactInstance *> CArtifactSet::searchForConstituent(const ArtifactID & aid) const
|
||||
{
|
||||
for(auto & slot : artifactsInBackpack)
|
||||
for(const auto & slot : artifactsInBackpack)
|
||||
{
|
||||
auto art = slot.artifact;
|
||||
if(art->canBeDisassembled())
|
||||
{
|
||||
auto ass = static_cast<CCombinedArtifactInstance *>(art.get());
|
||||
auto * ass = dynamic_cast<CCombinedArtifactInstance *>(art.get());
|
||||
for(auto& ci : ass->constituentsInfo)
|
||||
{
|
||||
if(ci.art->artType->getId() == aid)
|
||||
@@ -1332,17 +1314,17 @@ CArtifactSet::searchForConstituent(ArtifactID aid) const
|
||||
return {nullptr, nullptr};
|
||||
}
|
||||
|
||||
const CArtifactInstance *CArtifactSet::getHiddenArt(ArtifactID aid) const
|
||||
const CArtifactInstance * CArtifactSet::getHiddenArt(const ArtifactID & aid) const
|
||||
{
|
||||
return searchForConstituent(aid).second;
|
||||
}
|
||||
|
||||
const CCombinedArtifactInstance *CArtifactSet::getAssemblyByConstituent(ArtifactID aid) const
|
||||
const CCombinedArtifactInstance * CArtifactSet::getAssemblyByConstituent(const ArtifactID & aid) const
|
||||
{
|
||||
return searchForConstituent(aid).first;
|
||||
}
|
||||
|
||||
const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
|
||||
const ArtSlotInfo * CArtifactSet::getSlot(const ArtifactPosition & pos) const
|
||||
{
|
||||
if(pos == ArtifactPosition::TRANSITION_POS)
|
||||
{
|
||||
@@ -1366,7 +1348,7 @@ const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck) const
|
||||
bool CArtifactSet::isPositionFree(const ArtifactPosition & pos, bool onlyLockCheck) const
|
||||
{
|
||||
if(const ArtSlotInfo *s = getSlot(pos))
|
||||
return (onlyLockCheck || !s->artifact) && !s->locked;
|
||||
@@ -1374,14 +1356,14 @@ bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck) cons
|
||||
return true; //no slot means not used
|
||||
}
|
||||
|
||||
ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
|
||||
ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(const ArtifactPosition & slot)
|
||||
{
|
||||
assert(!vstd::contains(artifactsWorn, slot));
|
||||
|
||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||
{
|
||||
// Always add to the end. Always take from the beginning.
|
||||
artifactsTransitionPos.push_back(ArtSlotInfo());
|
||||
artifactsTransitionPos.emplace_back();
|
||||
return artifactsTransitionPos.back();
|
||||
}
|
||||
if(!ArtifactUtils::isSlotBackpack(slot))
|
||||
@@ -1395,14 +1377,14 @@ ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
|
||||
return *inserted;
|
||||
}
|
||||
|
||||
void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked)
|
||||
void CArtifactSet::setNewArtSlot(const ArtifactPosition & slot, CArtifactInstance * art, bool locked)
|
||||
{
|
||||
ArtSlotInfo & asi = retrieveNewArtSlot(slot);
|
||||
asi.artifact = art;
|
||||
asi.locked = locked;
|
||||
}
|
||||
|
||||
void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
|
||||
void CArtifactSet::eraseArtSlot(const ArtifactPosition & slot)
|
||||
{
|
||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||
{
|
||||
@@ -1481,8 +1463,8 @@ void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
|
||||
{
|
||||
for(const ArtifactID & artifactID : backpackTemp)
|
||||
{
|
||||
auto artifact = CArtifactInstance::createArtifact(map, artifactID.toEnum());
|
||||
auto slot = ArtifactPosition(GameConstants::BACKPACK_START + (si32)artifactsInBackpack.size());
|
||||
auto * artifact = CArtifactInstance::createArtifact(map, artifactID.toEnum());
|
||||
auto slot = ArtifactPosition(GameConstants::BACKPACK_START + static_cast<si32>(artifactsInBackpack.size()));
|
||||
if(artifact->canBePutAt(this, slot))
|
||||
putArtifact(slot, artifact);
|
||||
}
|
||||
@@ -1519,7 +1501,7 @@ void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const Artifa
|
||||
|
||||
if(artifactID != ArtifactID::NONE)
|
||||
{
|
||||
auto artifact = CArtifactInstance::createArtifact(map, artifactID.toEnum());
|
||||
auto * artifact = CArtifactInstance::createArtifact(map, artifactID.toEnum());
|
||||
|
||||
if(artifact->canBePutAt(this, slot))
|
||||
{
|
||||
@@ -1533,16 +1515,9 @@ void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const Artifa
|
||||
}
|
||||
}
|
||||
|
||||
CArtifactFittingSet::CArtifactFittingSet(ArtBearer::ArtBearer Bearer)
|
||||
CArtifactFittingSet::CArtifactFittingSet(ArtBearer::ArtBearer Bearer):
|
||||
Bearer(Bearer)
|
||||
{
|
||||
this->Bearer = Bearer;
|
||||
}
|
||||
|
||||
void CArtifactFittingSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance * art, bool locked)
|
||||
{
|
||||
ArtSlotInfo & asi = retrieveNewArtSlot(slot);
|
||||
asi.artifact = art;
|
||||
asi.locked = locked;
|
||||
}
|
||||
|
||||
void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
||||
@@ -1569,9 +1544,9 @@ ArtBearer::ArtBearer CArtifactFittingSet::bearerType() const
|
||||
DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtifactDstPosition(const CArtifactInstance * artifact,
|
||||
const CArtifactSet * target)
|
||||
{
|
||||
for(auto slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
for(const auto & slot : artifact->artType->possibleSlots.at(target->bearerType()))
|
||||
{
|
||||
auto existingArtInfo = target->getSlot(slot);
|
||||
const auto * existingArtInfo = target->getSlot(slot);
|
||||
|
||||
if((!existingArtInfo || !existingArtInfo->locked)
|
||||
&& artifact->canBePutAt(target, slot))
|
||||
@@ -1623,7 +1598,7 @@ DLL_LINKAGE bool ArtifactUtils::isArtRemovable(const std::pair<ArtifactPosition,
|
||||
&& !vstd::contains(unmovableSlots(), slot.first);
|
||||
}
|
||||
|
||||
DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot)
|
||||
DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, const ArtifactID & artID, const ArtifactPosition & slot)
|
||||
{
|
||||
// TODO what'll happen if Titan's thunder is equipped by pickin git up or the start of game?
|
||||
// Titan's Thunder creates new spellbook on equip
|
||||
@@ -1638,12 +1613,12 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he
|
||||
return false;
|
||||
}
|
||||
|
||||
DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(ArtifactPosition slot)
|
||||
DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(const ArtifactPosition & slot)
|
||||
{
|
||||
return slot >= GameConstants::BACKPACK_START;
|
||||
}
|
||||
|
||||
DLL_LINKAGE bool ArtifactUtils::isSlotEquipment(ArtifactPosition slot)
|
||||
DLL_LINKAGE bool ArtifactUtils::isSlotEquipment(const ArtifactPosition & slot)
|
||||
{
|
||||
return slot < GameConstants::BACKPACK_START && slot >= 0;
|
||||
}
|
||||
|
@@ -56,12 +56,12 @@ public:
|
||||
std::string image;
|
||||
std::string large; // big image for custom artifacts, used in drag & drop
|
||||
std::string advMapDef; //used for adventure map object
|
||||
si32 iconIndex;
|
||||
ui32 price;
|
||||
si32 iconIndex = ArtifactID::NONE;
|
||||
ui32 price = 0;
|
||||
std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed
|
||||
std::unique_ptr<std::vector<CArtifact *> > constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
|
||||
std::vector<CArtifact *> constituentOf; // Reverse map of constituents - combined arts that include this art
|
||||
EartClass aClass;
|
||||
EartClass aClass = ART_SPECIAL;
|
||||
CreatureID warMachine;
|
||||
|
||||
int32_t getIndex() const override;
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
virtual bool isPart(const CArtifactInstance *supposedPart) const;
|
||||
|
||||
std::vector<const CArtifact *> assemblyPossibilities(const CArtifactSet * h, bool equipped) const;
|
||||
void move(ArtifactLocation src, ArtifactLocation dst);
|
||||
void move(const ArtifactLocation & src,const ArtifactLocation & dst);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@@ -175,9 +175,9 @@ public:
|
||||
BONUS_TREE_DESERIALIZATION_FIX
|
||||
}
|
||||
|
||||
static CArtifactInstance *createScroll(SpellID sid);
|
||||
static CArtifactInstance * createScroll(const SpellID & sid);
|
||||
static CArtifactInstance *createNewArtifactInstance(CArtifact *Art);
|
||||
static CArtifactInstance *createNewArtifactInstance(ArtifactID aid);
|
||||
static CArtifactInstance * createNewArtifactInstance(const ArtifactID & aid);
|
||||
|
||||
/**
|
||||
* Creates an artifact instance.
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
* @param spellID optional. the id of a spell if a spell scroll object should be created
|
||||
* @return the created artifact instance
|
||||
*/
|
||||
static CArtifactInstance * createArtifact(CMap * map, ArtifactID aid, int spellID = -1);
|
||||
static CArtifactInstance * createArtifact(CMap * map, const ArtifactID & aid, int spellID = -1);
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CCombinedArtifactInstance : public CArtifactInstance
|
||||
@@ -204,7 +204,7 @@ public:
|
||||
}
|
||||
|
||||
bool operator==(const ConstituentInfo &rhs) const;
|
||||
ConstituentInfo(CArtifactInstance *art = nullptr, ArtifactPosition slot = ArtifactPosition::PRE_FIRST);
|
||||
ConstituentInfo(CArtifactInstance * art = nullptr, const ArtifactPosition & slot = ArtifactPosition::PRE_FIRST);
|
||||
};
|
||||
|
||||
std::vector<ConstituentInfo> constituentsInfo;
|
||||
@@ -216,10 +216,10 @@ public:
|
||||
bool isPart(const CArtifactInstance *supposedPart) const override;
|
||||
|
||||
void createConstituents();
|
||||
void addAsConstituent(CArtifactInstance *art, ArtifactPosition slot);
|
||||
CArtifactInstance *figureMainConstituent(const ArtifactLocation al); //main constituent is replaced with us (combined art), not lock
|
||||
void addAsConstituent(CArtifactInstance * art, const ArtifactPosition & slot);
|
||||
CArtifactInstance * figureMainConstituent(const ArtifactLocation & al); //main constituent is replaced with us (combined art), not lock
|
||||
|
||||
CCombinedArtifactInstance();
|
||||
CCombinedArtifactInstance() = default;
|
||||
|
||||
void deserializationFix();
|
||||
|
||||
@@ -247,19 +247,18 @@ public:
|
||||
|
||||
boost::optional<std::vector<CArtifact*>&> listFromClass(CArtifact::EartClass artifactClass);
|
||||
|
||||
static CArtifact::EartClass stringToClass(std::string className); //TODO: rework EartClass to make this a constructor
|
||||
static CArtifact::EartClass stringToClass(const std::string & className); //TODO: rework EartClass to make this a constructor
|
||||
|
||||
/// Gets a artifact ID randomly and removes the selected artifact from this handler.
|
||||
ArtifactID pickRandomArtifact(CRandomGenerator & rand, int flags);
|
||||
ArtifactID pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts);
|
||||
ArtifactID pickRandomArtifact(CRandomGenerator & rand, int flags, std::function<bool(ArtifactID)> accepts);
|
||||
|
||||
bool legalArtifact(ArtifactID id);
|
||||
bool legalArtifact(const ArtifactID & id);
|
||||
void initAllowedArtifactsList(const std::vector<bool> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
|
||||
void makeItCreatureArt (CArtifact * a, bool onlyCreature = true);
|
||||
void makeItCommanderArt (CArtifact * a, bool onlyCommander = true);
|
||||
static void makeItCreatureArt(CArtifact * a, bool onlyCreature = true);
|
||||
static void makeItCommanderArt(CArtifact * a, bool onlyCommander = true);
|
||||
|
||||
CArtHandler();
|
||||
~CArtHandler();
|
||||
|
||||
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
|
||||
@@ -286,15 +285,14 @@ protected:
|
||||
CArtifact * loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) override;
|
||||
|
||||
private:
|
||||
|
||||
void addSlot(CArtifact * art, const std::string & slotID);
|
||||
void loadSlots(CArtifact * art, const JsonNode & node);
|
||||
void loadClass(CArtifact * art, const JsonNode & node);
|
||||
void loadType(CArtifact * art, const JsonNode & node);
|
||||
void addSlot(CArtifact * art, const std::string & slotID) const;
|
||||
void loadSlots(CArtifact * art, const JsonNode & node) const;
|
||||
void loadClass(CArtifact * art, const JsonNode & node) const;
|
||||
void loadType(CArtifact * art, const JsonNode & node) const;
|
||||
void loadComponents(CArtifact * art, const JsonNode & node);
|
||||
void loadGrowingArt(CGrowingArtifact * art, const JsonNode & node);
|
||||
void loadGrowingArt(CGrowingArtifact * art, const JsonNode & node) const;
|
||||
|
||||
void erasePickedArt(ArtifactID id);
|
||||
void erasePickedArt(const ArtifactID & id);
|
||||
};
|
||||
|
||||
struct DLL_LINKAGE ArtSlotInfo
|
||||
@@ -319,29 +317,29 @@ public:
|
||||
std::map<ArtifactPosition, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
|
||||
std::vector<ArtSlotInfo> artifactsTransitionPos; // Used as transition position for dragAndDrop artifact exchange
|
||||
|
||||
ArtSlotInfo & retrieveNewArtSlot(ArtifactPosition slot);
|
||||
void setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked);
|
||||
void eraseArtSlot(ArtifactPosition slot);
|
||||
ArtSlotInfo & retrieveNewArtSlot(const ArtifactPosition & slot);
|
||||
void setNewArtSlot(const ArtifactPosition & slot, CArtifactInstance * art, bool locked);
|
||||
void eraseArtSlot(const ArtifactPosition & slot);
|
||||
|
||||
const ArtSlotInfo *getSlot(ArtifactPosition pos) const;
|
||||
const CArtifactInstance* getArt(ArtifactPosition pos, bool excludeLocked = true) const; //nullptr - no artifact
|
||||
CArtifactInstance* getArt(ArtifactPosition pos, bool excludeLocked = true); //nullptr - no artifact
|
||||
const ArtSlotInfo * getSlot(const ArtifactPosition & pos) const;
|
||||
const CArtifactInstance * getArt(const ArtifactPosition & pos, bool excludeLocked = true) const; //nullptr - no artifact
|
||||
CArtifactInstance * getArt(const ArtifactPosition & pos, bool excludeLocked = true); //nullptr - no artifact
|
||||
/// Looks for equipped artifact with given ID and returns its slot ID or -1 if none
|
||||
/// (if more than one such artifact lower ID is returned)
|
||||
ArtifactPosition getArtPos(ArtifactID aid, bool onlyWorn = true, bool allowLocked = true) const;
|
||||
ArtifactPosition getArtPos(const ArtifactID & aid, bool onlyWorn = true, bool allowLocked = true) const;
|
||||
ArtifactPosition getArtPos(const CArtifactInstance *art) const;
|
||||
ArtifactPosition getArtBackpackPos(ArtifactID aid) const;
|
||||
std::vector<ArtifactPosition> getAllArtPositions(ArtifactID aid, bool onlyWorn, bool allowLocked, bool getAll) const;
|
||||
std::vector<ArtifactPosition> getBackpackArtPositions(ArtifactID aid) const;
|
||||
const CArtifactInstance *getArtByInstanceId(ArtifactInstanceID artInstId) const;
|
||||
ArtifactPosition getArtBackpackPos(const ArtifactID & aid) const;
|
||||
std::vector<ArtifactPosition> getAllArtPositions(const ArtifactID & aid, bool onlyWorn, bool allowLocked, bool getAll) const;
|
||||
std::vector<ArtifactPosition> getBackpackArtPositions(const ArtifactID & aid) const;
|
||||
const CArtifactInstance * getArtByInstanceId(const ArtifactInstanceID & artInstId) const;
|
||||
/// Search for constituents of assemblies in backpack which do not have an ArtifactPosition
|
||||
const CArtifactInstance *getHiddenArt(ArtifactID aid) const;
|
||||
const CCombinedArtifactInstance *getAssemblyByConstituent(ArtifactID aid) const;
|
||||
const CArtifactInstance * getHiddenArt(const ArtifactID & aid) const;
|
||||
const CCombinedArtifactInstance * getAssemblyByConstituent(const ArtifactID & aid) const;
|
||||
/// Checks if hero possess artifact of given id (either in backack or worn)
|
||||
bool hasArt(ArtifactID aid, bool onlyWorn = false, bool searchBackpackAssemblies = false, bool allowLocked = true) const;
|
||||
bool hasArtBackpack(ArtifactID aid) const;
|
||||
bool isPositionFree(ArtifactPosition pos, bool onlyLockCheck = false) const;
|
||||
unsigned getArtPosCount(ArtifactID aid, bool onlyWorn = true, bool searchBackpackAssemblies = true, bool allowLocked = true) const;
|
||||
bool hasArt(const ArtifactID & aid, bool onlyWorn = false, bool searchBackpackAssemblies = false, bool allowLocked = true) const;
|
||||
bool hasArtBackpack(const ArtifactID & aid) const;
|
||||
bool isPositionFree(const ArtifactPosition & pos, bool onlyLockCheck = false) const;
|
||||
unsigned getArtPosCount(const ArtifactID & aid, bool onlyWorn = true, bool searchBackpackAssemblies = true, bool allowLocked = true) const;
|
||||
|
||||
virtual ArtBearer::ArtBearer bearerType() const = 0;
|
||||
virtual void putArtifact(ArtifactPosition pos, CArtifactInstance * art) = 0;
|
||||
@@ -357,9 +355,8 @@ public:
|
||||
|
||||
void serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map);
|
||||
protected:
|
||||
std::pair<const CCombinedArtifactInstance *, const CArtifactInstance *> searchForConstituent(const ArtifactID & aid) const;
|
||||
|
||||
|
||||
std::pair<const CCombinedArtifactInstance *, const CArtifactInstance *> searchForConstituent(ArtifactID aid) const;
|
||||
private:
|
||||
void serializeJsonHero(JsonSerializeFormat & handler, CMap * map);
|
||||
void serializeJsonCreature(JsonSerializeFormat & handler, CMap * map);
|
||||
@@ -373,7 +370,6 @@ class DLL_LINKAGE CArtifactFittingSet : public CArtifactSet
|
||||
{
|
||||
public:
|
||||
CArtifactFittingSet(ArtBearer::ArtBearer Bearer);
|
||||
void setNewArtSlot(ArtifactPosition slot, CArtifactInstance * art, bool locked);
|
||||
void putArtifact(ArtifactPosition pos, CArtifactInstance * art) override;
|
||||
ArtBearer::ArtBearer bearerType() const override;
|
||||
|
||||
@@ -390,9 +386,9 @@ namespace ArtifactUtils
|
||||
DLL_LINKAGE const std::vector<ArtifactPosition::EArtifactPosition> & unmovableSlots();
|
||||
DLL_LINKAGE const std::vector<ArtifactPosition::EArtifactPosition> & constituentWornSlots();
|
||||
DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot);
|
||||
DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot);
|
||||
DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot);
|
||||
DLL_LINKAGE bool isSlotEquipment(ArtifactPosition slot);
|
||||
DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, const ArtifactID & artID, const ArtifactPosition & slot);
|
||||
DLL_LINKAGE bool isSlotBackpack(const ArtifactPosition & slot);
|
||||
DLL_LINKAGE bool isSlotEquipment(const ArtifactPosition & slot);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -209,7 +209,7 @@ void CBonusTypeHandler::load()
|
||||
|
||||
void CBonusTypeHandler::load(const JsonNode & config)
|
||||
{
|
||||
for(auto & node : config.Struct())
|
||||
for(const auto & node : config.Struct())
|
||||
{
|
||||
auto it = bonusNameMap.find(node.first);
|
||||
|
||||
@@ -235,7 +235,7 @@ void CBonusTypeHandler::load(const JsonNode & config)
|
||||
}
|
||||
}
|
||||
|
||||
void CBonusTypeHandler::loadItem(const JsonNode & source, CBonusType & dest, const std::string & name)
|
||||
void CBonusTypeHandler::loadItem(const JsonNode & source, CBonusType & dest, const std::string & name) const
|
||||
{
|
||||
dest.identifier = name;
|
||||
dest.hidden = source["hidden"].Bool(); //Null -> false
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
private:
|
||||
void load();
|
||||
void load(const JsonNode & config);
|
||||
void loadItem(const JsonNode & source, CBonusType & dest, const std::string & name);
|
||||
void loadItem(const JsonNode & source, CBonusType & dest, const std::string & name) const;
|
||||
|
||||
std::vector<CBonusType> bonusTypes; //index = BonusTypeID
|
||||
};
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
BuildingID CBuildingHandler::campToERMU( int camp, int townType, std::set<BuildingID> builtBuildings )
|
||||
BuildingID CBuildingHandler::campToERMU(int camp, int townType, const std::set<BuildingID> & builtBuildings)
|
||||
{
|
||||
static const std::vector<BuildingID> campToERMU =
|
||||
{
|
||||
|
@@ -16,7 +16,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
class DLL_LINKAGE CBuildingHandler
|
||||
{
|
||||
public:
|
||||
static BuildingID campToERMU(int camp, int townType, std::set<BuildingID> builtBuildings);
|
||||
static BuildingID campToERMU(int camp, int townType, const std::set<BuildingID> & builtBuildings);
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -25,12 +25,12 @@ CConfigHandler conf;
|
||||
template<typename Accessor>
|
||||
SettingsStorage::NodeAccessor<Accessor>::NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path):
|
||||
parent(_parent),
|
||||
path(_path)
|
||||
path(std::move(_path))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Accessor>
|
||||
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator [](std::string nextNode) const
|
||||
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator[](const std::string & nextNode) const
|
||||
{
|
||||
std::vector<std::string> newPath = path;
|
||||
newPath.push_back(nextNode);
|
||||
@@ -84,21 +84,21 @@ void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath
|
||||
file << savedConf.toJson();
|
||||
}
|
||||
|
||||
JsonNode & SettingsStorage::getNode(std::vector<std::string> path)
|
||||
JsonNode & SettingsStorage::getNode(const std::vector<std::string> & path)
|
||||
{
|
||||
JsonNode *node = &config;
|
||||
for(std::string& value : path)
|
||||
for(const std::string & value : path)
|
||||
node = &(*node)[value];
|
||||
|
||||
return *node;
|
||||
}
|
||||
|
||||
Settings SettingsStorage::get(std::vector<std::string> path)
|
||||
Settings SettingsStorage::get(const std::vector<std::string> & path)
|
||||
{
|
||||
return Settings(*this, path);
|
||||
}
|
||||
|
||||
const JsonNode & SettingsStorage::operator [](std::string value) const
|
||||
const JsonNode & SettingsStorage::operator[](const std::string & value) const
|
||||
{
|
||||
return config[value];
|
||||
}
|
||||
@@ -108,9 +108,9 @@ const JsonNode & SettingsStorage::toJsonNode() const
|
||||
return config;
|
||||
}
|
||||
|
||||
SettingsListener::SettingsListener(SettingsStorage &_parent, const std::vector<std::string> &_path):
|
||||
SettingsListener::SettingsListener(SettingsStorage & _parent, std::vector<std::string> _path):
|
||||
parent(_parent),
|
||||
path(_path)
|
||||
path(std::move(_path))
|
||||
{
|
||||
parent.listeners.insert(this);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ void SettingsListener::nodeInvalidated(const std::vector<std::string> &changedPa
|
||||
|
||||
void SettingsListener::operator() (std::function<void(const JsonNode&)> _callback)
|
||||
{
|
||||
callback = _callback;
|
||||
callback = std::move(_callback);
|
||||
}
|
||||
|
||||
Settings::Settings(SettingsStorage &_parent, const std::vector<std::string> &_path):
|
||||
@@ -169,12 +169,12 @@ const JsonNode* Settings::operator ->() const
|
||||
return &node;
|
||||
}
|
||||
|
||||
const JsonNode& Settings::operator [](std::string value) const
|
||||
const JsonNode & Settings::operator[](const std::string & value) const
|
||||
{
|
||||
return node[value];
|
||||
}
|
||||
|
||||
JsonNode& Settings::operator [](std::string value)
|
||||
JsonNode & Settings::operator[](const std::string & value)
|
||||
{
|
||||
return node[value];
|
||||
}
|
||||
@@ -210,10 +210,6 @@ CConfigHandler::CConfigHandler()
|
||||
{
|
||||
}
|
||||
|
||||
CConfigHandler::~CConfigHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void config::CConfigHandler::init()
|
||||
{
|
||||
/* Read resolutions. */
|
||||
@@ -222,7 +218,7 @@ void config::CConfigHandler::init()
|
||||
|
||||
for(const JsonNode &g : guisettings_vec)
|
||||
{
|
||||
std::pair<int,int> curRes((int)g["resolution"]["x"].Float(), (int)g["resolution"]["y"].Float());
|
||||
std::pair<int, int> curRes(static_cast<int>(g["resolution"]["x"].Float()), static_cast<int>(g["resolution"]["y"].Float()));
|
||||
GUIOptions *current = &conf.guiOptions[curRes];
|
||||
|
||||
current->ac.inputLineLength = static_cast<int>(g["InGameConsole"]["maxInputPerLine"].Float());
|
||||
@@ -297,7 +293,7 @@ void config::CConfigHandler::init()
|
||||
|
||||
const JsonNode& screenRes = settings["video"]["screenRes"];
|
||||
|
||||
SetResolution((int)screenRes["width"].Float(), (int)screenRes["height"].Float());
|
||||
SetResolution(static_cast<int>(screenRes["width"].Float()), static_cast<int>(screenRes["height"].Float()));
|
||||
}
|
||||
|
||||
// Force instantiation of the SettingsStorage::NodeAccessor class template.
|
||||
|
@@ -27,7 +27,7 @@ class DLL_LINKAGE SettingsStorage
|
||||
std::vector<std::string> path;
|
||||
|
||||
NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path);
|
||||
NodeAccessor<Accessor> operator [] (std::string nextNode) const;
|
||||
NodeAccessor<Accessor> operator[](const std::string & nextNode) const;
|
||||
NodeAccessor<Accessor> operator () (std::vector<std::string> _path) const;
|
||||
operator Accessor() const;
|
||||
};
|
||||
@@ -35,12 +35,13 @@ class DLL_LINKAGE SettingsStorage
|
||||
std::set<SettingsListener*> listeners;
|
||||
JsonNode config;
|
||||
|
||||
JsonNode & getNode(std::vector<std::string> path);
|
||||
JsonNode & getNode(const std::vector<std::string> & path);
|
||||
|
||||
// Calls all required listeners
|
||||
void invalidateNode(const std::vector<std::string> &changedPath);
|
||||
|
||||
Settings get(std::vector<std::string> path);
|
||||
Settings get(const std::vector<std::string> & path);
|
||||
|
||||
public:
|
||||
// Initialize config structure
|
||||
SettingsStorage();
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
const NodeAccessor<SettingsListener> listen;
|
||||
|
||||
//Read access, see JsonNode::operator[]
|
||||
const JsonNode & operator [](std::string value) const;
|
||||
const JsonNode & operator[](const std::string & value) const;
|
||||
const JsonNode & toJsonNode() const;
|
||||
|
||||
friend class SettingsListener;
|
||||
@@ -69,7 +70,7 @@ class DLL_LINKAGE SettingsListener
|
||||
// Callback
|
||||
std::function<void(const JsonNode&)> callback;
|
||||
|
||||
SettingsListener(SettingsStorage &_parent, const std::vector<std::string> &_path);
|
||||
SettingsListener(SettingsStorage & _parent, std::vector<std::string> _path);
|
||||
|
||||
// Executes callback if changedpath begins with path
|
||||
void nodeInvalidated(const std::vector<std::string> & changedPath);
|
||||
@@ -105,8 +106,8 @@ public:
|
||||
const JsonNode* operator ->() const;
|
||||
|
||||
//Helper, replaces JsonNode::operator[]
|
||||
JsonNode& operator [](std::string value);
|
||||
const JsonNode& operator [](std::string value) const;
|
||||
JsonNode & operator[](const std::string & value);
|
||||
const JsonNode & operator[](const std::string & value) const;
|
||||
|
||||
friend class SettingsStorage;
|
||||
};
|
||||
@@ -174,7 +175,6 @@ namespace config
|
||||
GuiOptionsMap guiOptions;
|
||||
void init();
|
||||
CConfigHandler();
|
||||
~CConfigHandler();
|
||||
|
||||
GUIOptions *go() { return current; };
|
||||
void SetResolution(int x, int y)
|
||||
|
@@ -22,7 +22,7 @@ DLL_LINKAGE CConsoleHandler * console = nullptr;
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
#ifndef VCMI_WINDOWS
|
||||
typedef std::string TColor;
|
||||
using TColor = std::string;
|
||||
#define CONSOLE_GREEN "\x1b[1;32m"
|
||||
#define CONSOLE_RED "\x1b[1;31m"
|
||||
#define CONSOLE_MAGENTA "\x1b[1;35m"
|
||||
@@ -212,7 +212,7 @@ void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color)
|
||||
#endif
|
||||
}
|
||||
|
||||
int CConsoleHandler::run()
|
||||
int CConsoleHandler::run() const
|
||||
{
|
||||
setThreadName("CConsoleHandler::run");
|
||||
//disabling sync to make in_avail() work (othervice always returns 0)
|
||||
@@ -244,7 +244,9 @@ int CConsoleHandler::run()
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
CConsoleHandler::CConsoleHandler() : thread(nullptr)
|
||||
CConsoleHandler::CConsoleHandler():
|
||||
cb(new std::function<void(const std::string &, bool)>),
|
||||
thread(nullptr)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
handleIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
@@ -263,7 +265,6 @@ CConsoleHandler::CConsoleHandler() : thread(nullptr)
|
||||
#else
|
||||
defColor = "\x1b[0m";
|
||||
#endif
|
||||
cb = new std::function<void(const std::string &, bool)>;
|
||||
}
|
||||
CConsoleHandler::~CConsoleHandler()
|
||||
{
|
||||
|
@@ -79,18 +79,18 @@ public:
|
||||
std::function<void(const std::string &, bool)> *cb;
|
||||
|
||||
private:
|
||||
int run();
|
||||
int run() const;
|
||||
|
||||
void end(); //kills listening thread
|
||||
void end(); //kills listening thread
|
||||
|
||||
void setColor(EConsoleTextColor::EConsoleTextColor color); //sets color of text appropriate for given logging level
|
||||
static void setColor(EConsoleTextColor::EConsoleTextColor color); //sets color of text appropriate for given logging level
|
||||
|
||||
/// FIXME: Implement CConsoleHandler as singleton, move some logic into CLogConsoleTarget, etc... needs to be disussed:)
|
||||
/// Without static, application will crash complaining about mutex deleted. In short: CConsoleHandler gets deleted before
|
||||
/// the logging system.
|
||||
static boost::mutex smx;
|
||||
/// FIXME: Implement CConsoleHandler as singleton, move some logic into CLogConsoleTarget, etc... needs to be disussed:)
|
||||
/// Without static, application will crash complaining about mutex deleted. In short: CConsoleHandler gets deleted before
|
||||
/// the logging system.
|
||||
static boost::mutex smx;
|
||||
|
||||
boost::thread * thread;
|
||||
boost::thread * thread;
|
||||
};
|
||||
|
||||
extern DLL_LINKAGE CConsoleHandler * console;
|
||||
|
@@ -272,19 +272,14 @@ si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatur
|
||||
int resAmnt = static_cast<int>(std::min(res.size(),cost.size()));
|
||||
for(int i=0;i<resAmnt;i++)
|
||||
if(cost[i])
|
||||
ret = std::min(ret,(int)(res[i]/cost[i]));
|
||||
ret = std::min(ret, (res[i] / cost[i]));
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCreature::CCreature()
|
||||
{
|
||||
setNodeType(CBonusSystemNode::CREATURE);
|
||||
faction = 0;
|
||||
level = 0;
|
||||
fightValue = AIValue = growth = hordeGrowth = ammMin = ammMax = 0;
|
||||
doubleWide = false;
|
||||
special = true;
|
||||
iconIndex = -1;
|
||||
}
|
||||
|
||||
void CCreature::addBonus(int val, Bonus::BonusType type, int subtype)
|
||||
@@ -449,10 +444,10 @@ void CCreatureHandler::loadCommanders()
|
||||
int i = 0;
|
||||
for (auto skill : config["skillLevels"].Vector())
|
||||
{
|
||||
skillLevels.push_back (std::vector<ui8>());
|
||||
skillLevels.emplace_back();
|
||||
for (auto skillLevel : skill["levels"].Vector())
|
||||
{
|
||||
skillLevels[i].push_back ((ui8)skillLevel.Float());
|
||||
skillLevels[i].push_back(static_cast<ui8>(skillLevel.Float()));
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -467,9 +462,9 @@ void CCreatureHandler::loadCommanders()
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadBonuses(JsonNode & creature, std::string bonuses)
|
||||
void CCreatureHandler::loadBonuses(JsonNode & creature, std::string bonuses) const
|
||||
{
|
||||
auto makeBonusNode = [&](std::string type, double val = 0) -> JsonNode
|
||||
auto makeBonusNode = [&](const std::string & type, double val = 0) -> JsonNode
|
||||
{
|
||||
JsonNode ret;
|
||||
ret["type"].String() = type;
|
||||
@@ -495,12 +490,12 @@ void CCreatureHandler::loadBonuses(JsonNode & creature, std::string bonuses)
|
||||
{"HAS_EXTENDED_ATTACK", makeBonusNode("TWO_HEX_ATTACK_BREATH")}
|
||||
};
|
||||
|
||||
auto hasAbility = [&](const std::string name) -> bool
|
||||
auto hasAbility = [&](const std::string & name) -> bool
|
||||
{
|
||||
return boost::algorithm::find_first(bonuses, name);
|
||||
};
|
||||
|
||||
for(auto a : abilityMap)
|
||||
for(const auto & a : abilityMap)
|
||||
{
|
||||
if(hasAbility(a.first))
|
||||
creature["abilities"][a.first] = a.second;
|
||||
@@ -532,15 +527,13 @@ std::vector<JsonNode> CCreatureHandler::loadLegacyData(size_t dataSize)
|
||||
//RUS: Singular Plural Plural2 Wood ...
|
||||
// Try to detect which version this is by header
|
||||
// TODO: use 3rd name? Stand for "whose", e.g. pikemans'
|
||||
size_t namesCount;
|
||||
size_t namesCount = 2;
|
||||
{
|
||||
if ( parser.readString() != "Singular" || parser.readString() != "Plural" )
|
||||
throw std::runtime_error("Incorrect format of CrTraits.txt");
|
||||
|
||||
if (parser.readString() == "Plural2")
|
||||
namesCount = 3;
|
||||
else
|
||||
namesCount = 2;
|
||||
|
||||
parser.endLine();
|
||||
}
|
||||
@@ -600,7 +593,7 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
assert(!scope.empty());
|
||||
|
||||
auto cre = new CCreature();
|
||||
auto * cre = new CCreature();
|
||||
|
||||
if(node["hasDoubleWeek"].Bool())
|
||||
{
|
||||
@@ -636,9 +629,9 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
|
||||
loadJsonAnimation(cre, node["graphics"]);
|
||||
loadCreatureJson(cre, node);
|
||||
|
||||
for(auto & extraName : node["extraNames"].Vector())
|
||||
for(const auto & extraName : node["extraNames"].Vector())
|
||||
{
|
||||
for(auto type_name : getTypeNames())
|
||||
for(const auto & type_name : getTypeNames())
|
||||
registerObject(scope, type_name, extraName.String(), cre->getIndex());
|
||||
}
|
||||
|
||||
@@ -674,6 +667,7 @@ std::vector<bool> CCreatureHandler::getDefaultAllowed() const
|
||||
{
|
||||
std::vector<bool> ret;
|
||||
|
||||
ret.reserve(objects.size());
|
||||
for(const CCreature * crea : objects)
|
||||
{
|
||||
ret.push_back(crea ? !crea->special : false);
|
||||
@@ -700,7 +694,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
|
||||
parser.readString(); //ignore index
|
||||
loadStackExp(b, bl, parser);
|
||||
for(auto b : bl)
|
||||
for(const auto & b : bl)
|
||||
addBonusForAllCreatures(b); //health bonus is common for all
|
||||
parser.endLine();
|
||||
|
||||
@@ -711,7 +705,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
parser.readString(); //ignore index
|
||||
bl.clear();
|
||||
loadStackExp(b, bl, parser);
|
||||
for(auto b : bl)
|
||||
for(const auto & b : bl)
|
||||
addBonusForTier(i, b);
|
||||
parser.endLine();
|
||||
}
|
||||
@@ -721,7 +715,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
parser.readString(); //ignore index
|
||||
bl.clear();
|
||||
loadStackExp(b, bl, parser);
|
||||
for(auto b : bl)
|
||||
for(const auto & b : bl)
|
||||
{
|
||||
addBonusForTier(7, b);
|
||||
creaturesOfLevel[0].addNewBonus(b); //bonuses from level 7 are given to high-level creatures
|
||||
@@ -735,7 +729,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
b.sid = sid;
|
||||
bl.clear();
|
||||
loadStackExp(b, bl, parser);
|
||||
for(auto b : bl)
|
||||
for(const auto & b : bl)
|
||||
{
|
||||
objects[sid]->addNewBonus(b); //add directly to CCreature Node
|
||||
}
|
||||
@@ -777,7 +771,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
expBonParser.readString(); //already calculated
|
||||
|
||||
maxExpPerBattle[i] = static_cast<ui32>(expBonParser.readNumber());
|
||||
expRanks[i].push_back(expRanks[i].back() + (ui32)expBonParser.readNumber());
|
||||
expRanks[i].push_back(expRanks[i].back() + static_cast<ui32>(expBonParser.readNumber()));
|
||||
|
||||
expBonParser.endLine();
|
||||
}
|
||||
@@ -792,7 +786,7 @@ void CCreatureHandler::loadCrExpBon()
|
||||
}//end of Stack Experience
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadAnimationInfo(std::vector<JsonNode> &h3Data)
|
||||
void CCreatureHandler::loadAnimationInfo(std::vector<JsonNode> &h3Data) const
|
||||
{
|
||||
CLegacyConfigParser parser("DATA/CRANIM.TXT");
|
||||
|
||||
@@ -809,7 +803,7 @@ void CCreatureHandler::loadAnimationInfo(std::vector<JsonNode> &h3Data)
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadUnitAnimInfo(JsonNode & graphics, CLegacyConfigParser & parser)
|
||||
void CCreatureHandler::loadUnitAnimInfo(JsonNode & graphics, CLegacyConfigParser & parser) const
|
||||
{
|
||||
graphics["timeBetweenFidgets"].Float() = parser.readNumber();
|
||||
|
||||
@@ -846,7 +840,7 @@ void CCreatureHandler::loadUnitAnimInfo(JsonNode & graphics, CLegacyConfigParser
|
||||
graphics.Struct().erase("missile");
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadJsonAnimation(CCreature * cre, const JsonNode & graphics)
|
||||
void CCreatureHandler::loadJsonAnimation(CCreature * cre, const JsonNode & graphics) const
|
||||
{
|
||||
cre->animation.timeBetweenFidgets = graphics["timeBetweenFidgets"].Float();
|
||||
cre->animation.troopCountLocationOffset = static_cast<int>(graphics["troopCountLocationOffset"].Float());
|
||||
@@ -873,14 +867,14 @@ void CCreatureHandler::loadJsonAnimation(CCreature * cre, const JsonNode & graph
|
||||
cre->largeIconName = graphics["iconLarge"].String();
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & config)
|
||||
void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & config) const
|
||||
{
|
||||
creature->animDefName = config["graphics"]["animation"].String();
|
||||
|
||||
//FIXME: MOD COMPATIBILITY
|
||||
if (config["abilities"].getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
for(auto &ability : config["abilities"].Struct())
|
||||
for(const auto & ability : config["abilities"].Struct())
|
||||
{
|
||||
if (!ability.second.isNull())
|
||||
{
|
||||
@@ -959,7 +953,7 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
|
||||
#undef GET_SOUND_VALUE
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode & input)
|
||||
void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode & input) const
|
||||
{
|
||||
for (const JsonNode &exp : input.Vector())
|
||||
{
|
||||
@@ -972,7 +966,7 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
|
||||
{
|
||||
for (const JsonNode &val : values)
|
||||
{
|
||||
if (val.Bool() == true)
|
||||
if(val.Bool())
|
||||
{
|
||||
bonus->limiter = std::make_shared<RankRangeLimiter>(RankRangeLimiter(lowerLimit));
|
||||
creature->addNewBonus (std::make_shared<Bonus>(*bonus)); //bonuses must be unique objects
|
||||
@@ -988,7 +982,7 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
|
||||
{
|
||||
if (val.Float() != lastVal)
|
||||
{
|
||||
bonus->val = (int)val.Float() - lastVal;
|
||||
bonus->val = static_cast<int>(val.Float()) - lastVal;
|
||||
bonus->limiter.reset (new RankRangeLimiter(lowerLimit));
|
||||
creature->addNewBonus (std::make_shared<Bonus>(*bonus));
|
||||
}
|
||||
@@ -999,7 +993,7 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigParser & parser) //help function for parsing CREXPBON.txt
|
||||
void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigParser & parser) const//help function for parsing CREXPBON.txt
|
||||
{
|
||||
bool enable = false; //some bonuses are activated with values 2 or 1
|
||||
std::string buf = parser.readString();
|
||||
@@ -1267,7 +1261,9 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigPars
|
||||
}
|
||||
|
||||
//limiters, range
|
||||
si32 lastVal, curVal, lastLev = 0;
|
||||
si32 lastVal;
|
||||
si32 curVal;
|
||||
si32 lastLev = 0;
|
||||
|
||||
if (enable) //0 and 2 means non-active, 1 - active
|
||||
{
|
||||
@@ -1313,7 +1309,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigPars
|
||||
}
|
||||
}
|
||||
|
||||
int CCreatureHandler::stringToNumber(std::string & s)
|
||||
int CCreatureHandler::stringToNumber(std::string & s) const
|
||||
{
|
||||
boost::algorithm::replace_first(s,"#",""); //drop hash character
|
||||
return std::atoi(s.c_str());
|
||||
@@ -1342,12 +1338,12 @@ CreatureID CCreatureHandler::pickRandomMonster(CRandomGenerator & rand, int tier
|
||||
for(const CBonusSystemNode *b : creaturesOfLevel[tier].getChildrenNodes())
|
||||
{
|
||||
assert(b->getNodeType() == CBonusSystemNode::CREATURE);
|
||||
const CCreature * crea = dynamic_cast<const CCreature*>(b);
|
||||
const auto * crea = dynamic_cast<const CCreature *>(b);
|
||||
if(crea && !crea->special)
|
||||
allowed.push_back(crea->idNumber);
|
||||
}
|
||||
|
||||
if(!allowed.size())
|
||||
if(allowed.empty())
|
||||
{
|
||||
logGlobal->warn("Cannot pick a random creature of tier %d!", tier);
|
||||
return CreatureID::NONE;
|
||||
|
@@ -40,22 +40,22 @@ class DLL_LINKAGE CCreature : public Creature, public CBonusSystemNode
|
||||
public:
|
||||
CreatureID idNumber;
|
||||
|
||||
TFaction faction;
|
||||
ui8 level; // 0 - unknown; 1-7 for "usual" creatures
|
||||
TFaction faction = 0;
|
||||
ui8 level = 0; // 0 - unknown; 1-7 for "usual" creatures
|
||||
|
||||
//stats that are not handled by bonus system
|
||||
ui32 fightValue, AIValue, growth, hordeGrowth;
|
||||
ui32 ammMin, ammMax; // initial size of stack of these creatures on adventure map (if not set in editor)
|
||||
|
||||
bool doubleWide;
|
||||
bool special; // Creature is not available normally (war machines, commanders, several unused creatures, etc
|
||||
bool doubleWide = false;
|
||||
bool special = true; // Creature is not available normally (war machines, commanders, several unused creatures, etc
|
||||
|
||||
TResources cost; //cost[res_id] - amount of that resource required to buy creature from dwelling
|
||||
std::set<CreatureID> upgrades; // IDs of creatures to which this creature can be upgraded
|
||||
|
||||
std::string animDefName; // creature animation used during battles
|
||||
std::string advMapDef; //for new creatures only, image for adventure map
|
||||
si32 iconIndex; // index of icon in files like twcrport
|
||||
si32 iconIndex = -1; // index of icon in files like twcrport
|
||||
|
||||
/// names of files with appropriate icons. Used only during loading
|
||||
std::string smallIconName;
|
||||
@@ -262,25 +262,25 @@ private:
|
||||
CBonusSystemNode allCreatures;
|
||||
CBonusSystemNode creaturesOfLevel[GameConstants::CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range
|
||||
|
||||
void loadJsonAnimation(CCreature * creature, const JsonNode & graphics);
|
||||
void loadStackExperience(CCreature * creature, const JsonNode &input);
|
||||
void loadCreatureJson(CCreature * creature, const JsonNode & config);
|
||||
void loadJsonAnimation(CCreature * creature, const JsonNode & graphics) const;
|
||||
void loadStackExperience(CCreature * creature, const JsonNode & input) const;
|
||||
void loadCreatureJson(CCreature * creature, const JsonNode & config) const;
|
||||
|
||||
/// adding abilities from ZCRTRAIT.TXT
|
||||
void loadBonuses(JsonNode & creature, std::string bonuses);
|
||||
void loadBonuses(JsonNode & creature, std::string bonuses) const;
|
||||
/// load all creatures from H3 files
|
||||
void load();
|
||||
void loadCommanders();
|
||||
/// load creature from json structure
|
||||
void load(std::string creatureID, const JsonNode & node);
|
||||
/// read cranim.txt file from H3
|
||||
void loadAnimationInfo(std::vector<JsonNode> & h3Data);
|
||||
void loadAnimationInfo(std::vector<JsonNode> & h3Data) const;
|
||||
/// read one line from cranim.txt
|
||||
void loadUnitAnimInfo(JsonNode & unit, CLegacyConfigParser &parser);
|
||||
void loadUnitAnimInfo(JsonNode & unit, CLegacyConfigParser & parser) const;
|
||||
/// parse crexpbon.txt file from H3
|
||||
void loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigParser &parser);
|
||||
void loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigParser & parser) const;
|
||||
/// help function for parsing CREXPBON.txt
|
||||
int stringToNumber(std::string & s);
|
||||
int stringToNumber(std::string & s) const;
|
||||
|
||||
protected:
|
||||
const std::vector<std::string> & getTypeNames() const override;
|
||||
|
@@ -32,7 +32,7 @@ bool CreatureSlotComparer::operator()(const TPairCreatureSlot & lhs, const TPair
|
||||
return lhs.first->getAIValue() < rhs.first->getAIValue(); // Descendant order sorting
|
||||
}
|
||||
|
||||
const CStackInstance &CCreatureSet::operator[](SlotID slot) const
|
||||
const CStackInstance & CCreatureSet::operator[](const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
@@ -41,7 +41,7 @@ const CStackInstance &CCreatureSet::operator[](SlotID slot) const
|
||||
throw std::runtime_error("That slot is empty!");
|
||||
}
|
||||
|
||||
const CCreature* CCreatureSet::getCreature(SlotID slot) const
|
||||
const CCreature * CCreatureSet::getCreature(const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
@@ -67,14 +67,14 @@ bool CCreatureSet::setCreature(SlotID slot, CreatureID type, TQuantity quantity)
|
||||
if(hasStackAtSlot(slot)) //remove old creature
|
||||
eraseStack(slot);
|
||||
|
||||
auto armyObj = castToArmyObj();
|
||||
auto * armyObj = castToArmyObj();
|
||||
bool isHypotheticArmy = armyObj ? armyObj->isHypothetic() : false;
|
||||
|
||||
putStack(slot, new CStackInstance(type, quantity, isHypotheticArmy));
|
||||
return true;
|
||||
}
|
||||
|
||||
SlotID CCreatureSet::getSlotFor(CreatureID creature, ui32 slotsAmount) const /*returns -1 if no slot available */
|
||||
SlotID CCreatureSet::getSlotFor(const CreatureID & creature, ui32 slotsAmount) const /*returns -1 if no slot available */
|
||||
{
|
||||
return getSlotFor(VLC->creh->objects[creature], slotsAmount);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ SlotID CCreatureSet::getSlotFor(CreatureID creature, ui32 slotsAmount) const /*r
|
||||
SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount) const
|
||||
{
|
||||
assert(c && c->valid());
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
assert(elem.second->type->valid());
|
||||
if(elem.second->type == c)
|
||||
@@ -93,10 +93,10 @@ SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount) const
|
||||
return getFreeSlot(slotsAmount);
|
||||
}
|
||||
|
||||
bool CCreatureSet::hasCreatureSlots(const CCreature * c, SlotID exclude) const
|
||||
bool CCreatureSet::hasCreatureSlots(const CCreature * c, const SlotID & exclude) const
|
||||
{
|
||||
assert(c && c->valid());
|
||||
for(auto & elem : stacks) // elem is const
|
||||
for(const auto & elem : stacks) // elem is const
|
||||
{
|
||||
if(elem.first == exclude) // Check slot
|
||||
continue;
|
||||
@@ -112,12 +112,12 @@ bool CCreatureSet::hasCreatureSlots(const CCreature * c, SlotID exclude) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<SlotID> CCreatureSet::getCreatureSlots(const CCreature * c, SlotID exclude, TQuantity ignoreAmount) const
|
||||
std::vector<SlotID> CCreatureSet::getCreatureSlots(const CCreature * c, const SlotID & exclude, TQuantity ignoreAmount) const
|
||||
{
|
||||
assert(c && c->valid());
|
||||
std::vector<SlotID> result;
|
||||
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(elem.first == exclude)
|
||||
continue;
|
||||
@@ -140,7 +140,7 @@ bool CCreatureSet::isCreatureBalanced(const CCreature * c, TQuantity ignoreAmoun
|
||||
TQuantity max = 0;
|
||||
TQuantity min = std::numeric_limits<TQuantity>::max();
|
||||
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(!elem.second || !elem.second->type || elem.second->type != c)
|
||||
continue;
|
||||
@@ -209,11 +209,11 @@ TMapCreatureSlot CCreatureSet::getCreatureMap() const
|
||||
|
||||
// https://stackoverflow.com/questions/97050/stdmap-insert-or-stdmap-find
|
||||
// https://www.cplusplus.com/reference/map/map/key_comp/
|
||||
for(auto pair : stacks)
|
||||
for(const auto & pair : stacks)
|
||||
{
|
||||
auto creature = pair.second->type;
|
||||
const auto * creature = pair.second->type;
|
||||
auto slot = pair.first;
|
||||
TMapCreatureSlot::iterator lb = creatureMap.lower_bound(creature);
|
||||
auto lb = creatureMap.lower_bound(creature);
|
||||
|
||||
if(lb != creatureMap.end() && !(keyComp(creature, lb->first)))
|
||||
continue;
|
||||
@@ -223,11 +223,11 @@ TMapCreatureSlot CCreatureSet::getCreatureMap() const
|
||||
return creatureMap;
|
||||
}
|
||||
|
||||
TCreatureQueue CCreatureSet::getCreatureQueue(SlotID exclude) const
|
||||
TCreatureQueue CCreatureSet::getCreatureQueue(const SlotID & exclude) const
|
||||
{
|
||||
TCreatureQueue creatureQueue;
|
||||
|
||||
for(auto pair : stacks)
|
||||
for(const auto & pair : stacks)
|
||||
{
|
||||
if(pair.first == exclude)
|
||||
continue;
|
||||
@@ -236,7 +236,7 @@ TCreatureQueue CCreatureSet::getCreatureQueue(SlotID exclude) const
|
||||
return creatureQueue;
|
||||
}
|
||||
|
||||
TQuantity CCreatureSet::getStackCount(SlotID slot) const
|
||||
TQuantity CCreatureSet::getStackCount(const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
@@ -245,7 +245,7 @@ TQuantity CCreatureSet::getStackCount(SlotID slot) const
|
||||
return 0; //TODO? consider issuing a warning
|
||||
}
|
||||
|
||||
TExpType CCreatureSet::getStackExperience(SlotID slot) const
|
||||
TExpType CCreatureSet::getStackExperience(const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
@@ -254,14 +254,13 @@ TExpType CCreatureSet::getStackExperience(SlotID slot) const
|
||||
return 0; //TODO? consider issuing a warning
|
||||
}
|
||||
|
||||
|
||||
bool CCreatureSet::mergableStacks(std::pair<SlotID, SlotID> &out, SlotID preferable) const /*looks for two same stacks, returns slot positions */
|
||||
bool CCreatureSet::mergableStacks(std::pair<SlotID, SlotID> & out, const SlotID & preferable) const /*looks for two same stacks, returns slot positions */
|
||||
{
|
||||
//try to match creature to our preferred stack
|
||||
if(preferable.validSlot() && vstd::contains(stacks, preferable))
|
||||
{
|
||||
const CCreature *cr = stacks.find(preferable)->second->type;
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(cr == elem.second->type && elem.first != preferable)
|
||||
{
|
||||
@@ -272,13 +271,13 @@ bool CCreatureSet::mergableStacks(std::pair<SlotID, SlotID> &out, SlotID prefera
|
||||
}
|
||||
}
|
||||
|
||||
for(auto i=stacks.begin(); i!=stacks.end(); ++i)
|
||||
for(const auto & stack : stacks)
|
||||
{
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(i->second->type == elem.second->type && i->first != elem.first)
|
||||
if(stack.second->type == elem.second->type && stack.first != elem.first)
|
||||
{
|
||||
out.first = i->first;
|
||||
out.first = stack.first;
|
||||
out.second = elem.first;
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +299,7 @@ void CCreatureSet::sweep()
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureSet::addToSlot(SlotID slot, CreatureID cre, TQuantity count, bool allowMerging)
|
||||
void CCreatureSet::addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging)
|
||||
{
|
||||
const CCreature *c = VLC->creh->objects[cre];
|
||||
|
||||
@@ -318,7 +317,7 @@ void CCreatureSet::addToSlot(SlotID slot, CreatureID cre, TQuantity count, bool
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureSet::addToSlot(SlotID slot, CStackInstance *stack, bool allowMerging)
|
||||
void CCreatureSet::addToSlot(const SlotID & slot, CStackInstance * stack, bool allowMerging)
|
||||
{
|
||||
assert(stack->valid(true));
|
||||
|
||||
@@ -338,7 +337,7 @@ void CCreatureSet::addToSlot(SlotID slot, CStackInstance *stack, bool allowMergi
|
||||
|
||||
bool CCreatureSet::validTypes(bool allowUnrandomized) const
|
||||
{
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(!elem.second->valid(allowUnrandomized))
|
||||
return false;
|
||||
@@ -346,7 +345,7 @@ bool CCreatureSet::validTypes(bool allowUnrandomized) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCreatureSet::slotEmpty(SlotID slot) const
|
||||
bool CCreatureSet::slotEmpty(const SlotID & slot) const
|
||||
{
|
||||
return !hasStackAtSlot(slot);
|
||||
}
|
||||
@@ -359,17 +358,17 @@ bool CCreatureSet::needsLastStack() const
|
||||
ui64 CCreatureSet::getArmyStrength() const
|
||||
{
|
||||
ui64 ret = 0;
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
ret += elem.second->getPower();
|
||||
return ret;
|
||||
}
|
||||
|
||||
ui64 CCreatureSet::getPower (SlotID slot) const
|
||||
ui64 CCreatureSet::getPower(const SlotID & slot) const
|
||||
{
|
||||
return getStack(slot).getPower();
|
||||
}
|
||||
|
||||
std::string CCreatureSet::getRoughAmount(SlotID slot, int mode) const
|
||||
std::string CCreatureSet::getRoughAmount(const SlotID & slot, int mode) const
|
||||
{
|
||||
/// Mode represent return string format
|
||||
/// "Pack" - 0, "A pack of" - 1, "a pack of" - 2
|
||||
@@ -389,12 +388,12 @@ std::string CCreatureSet::getArmyDescription() const
|
||||
{
|
||||
std::string text;
|
||||
std::vector<std::string> guards;
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
auto str = boost::str(boost::format("%s %s") % getRoughAmount(elem.first, 2) % getCreature(elem.first)->getNamePluralTranslated());
|
||||
guards.push_back(str);
|
||||
}
|
||||
if(guards.size())
|
||||
if(!guards.empty())
|
||||
{
|
||||
for(int i = 0; i < guards.size(); i++)
|
||||
{
|
||||
@@ -418,7 +417,7 @@ void CCreatureSet::setFormation(bool tight)
|
||||
formation = tight;
|
||||
}
|
||||
|
||||
void CCreatureSet::setStackCount(SlotID slot, TQuantity count)
|
||||
void CCreatureSet::setStackCount(const SlotID & slot, TQuantity count)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
assert(stacks[slot]->count + count > 0);
|
||||
@@ -433,7 +432,7 @@ void CCreatureSet::giveStackExp(TExpType exp)
|
||||
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
|
||||
i->second->giveStackExp(exp);
|
||||
}
|
||||
void CCreatureSet::setStackExp(SlotID slot, TExpType exp)
|
||||
void CCreatureSet::setStackExp(const SlotID & slot, TExpType exp)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
stacks[slot]->experience = exp;
|
||||
@@ -447,20 +446,20 @@ void CCreatureSet::clear()
|
||||
}
|
||||
}
|
||||
|
||||
const CStackInstance& CCreatureSet::getStack(SlotID slot) const
|
||||
const CStackInstance & CCreatureSet::getStack(const SlotID & slot) const
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
return *getStackPtr(slot);
|
||||
}
|
||||
|
||||
const CStackInstance* CCreatureSet::getStackPtr(SlotID slot) const
|
||||
const CStackInstance * CCreatureSet::getStackPtr(const SlotID & slot) const
|
||||
{
|
||||
if(hasStackAtSlot(slot))
|
||||
return stacks.find(slot)->second;
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
void CCreatureSet::eraseStack(SlotID slot)
|
||||
void CCreatureSet::eraseStack(const SlotID & slot)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
CStackInstance *toErase = detachStack(slot);
|
||||
@@ -472,7 +471,7 @@ bool CCreatureSet::contains(const CStackInstance *stack) const
|
||||
if(!stack)
|
||||
return false;
|
||||
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
if(elem.second == stack)
|
||||
return true;
|
||||
|
||||
@@ -481,14 +480,14 @@ bool CCreatureSet::contains(const CStackInstance *stack) const
|
||||
|
||||
SlotID CCreatureSet::findStack(const CStackInstance *stack) const
|
||||
{
|
||||
auto h = dynamic_cast<const CGHeroInstance *>(this);
|
||||
const auto * h = dynamic_cast<const CGHeroInstance *>(this);
|
||||
if (h && h->commander == stack)
|
||||
return SlotID::COMMANDER_SLOT_PLACEHOLDER;
|
||||
|
||||
if(!stack)
|
||||
return SlotID();
|
||||
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
if(elem.second == stack)
|
||||
return elem.first;
|
||||
|
||||
@@ -500,7 +499,7 @@ CArmedInstance * CCreatureSet::castToArmyObj()
|
||||
return dynamic_cast<CArmedInstance *>(this);
|
||||
}
|
||||
|
||||
void CCreatureSet::putStack(SlotID slot, CStackInstance *stack)
|
||||
void CCreatureSet::putStack(const SlotID & slot, CStackInstance * stack)
|
||||
{
|
||||
assert(slot.getNum() < GameConstants::ARMY_SIZE);
|
||||
assert(!hasStackAtSlot(slot));
|
||||
@@ -509,7 +508,7 @@ void CCreatureSet::putStack(SlotID slot, CStackInstance *stack)
|
||||
armyChanged();
|
||||
}
|
||||
|
||||
void CCreatureSet::joinStack(SlotID slot, CStackInstance * stack)
|
||||
void CCreatureSet::joinStack(const SlotID & slot, CStackInstance * stack)
|
||||
{
|
||||
const CCreature *c = getCreature(slot);
|
||||
assert(c == stack->type);
|
||||
@@ -521,21 +520,11 @@ void CCreatureSet::joinStack(SlotID slot, CStackInstance * stack)
|
||||
vstd::clear_pointer(stack);
|
||||
}
|
||||
|
||||
void CCreatureSet::changeStackCount(SlotID slot, TQuantity toAdd)
|
||||
void CCreatureSet::changeStackCount(const SlotID & slot, TQuantity toAdd)
|
||||
{
|
||||
setStackCount(slot, getStackCount(slot) + toAdd);
|
||||
}
|
||||
|
||||
CCreatureSet::CCreatureSet()
|
||||
{
|
||||
formation = false;
|
||||
}
|
||||
|
||||
CCreatureSet::CCreatureSet(const CCreatureSet&)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
CCreatureSet::~CCreatureSet()
|
||||
{
|
||||
clear();
|
||||
@@ -553,7 +542,7 @@ void CCreatureSet::setToArmy(CSimpleArmy &src)
|
||||
}
|
||||
}
|
||||
|
||||
CStackInstance * CCreatureSet::detachStack(SlotID slot)
|
||||
CStackInstance * CCreatureSet::detachStack(const SlotID & slot)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
CStackInstance *ret = stacks[slot];
|
||||
@@ -570,7 +559,7 @@ CStackInstance * CCreatureSet::detachStack(SlotID slot)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CCreatureSet::setStackType(SlotID slot, CreatureID type)
|
||||
void CCreatureSet::setStackType(const SlotID & slot, const CreatureID & type)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
CStackInstance *s = stacks[slot];
|
||||
@@ -584,7 +573,7 @@ bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStac
|
||||
{
|
||||
int freeSlots = stacksCount() - GameConstants::ARMY_SIZE;
|
||||
std::set<const CCreature*> cresToAdd;
|
||||
for(auto & elem : cs.stacks)
|
||||
for(const auto & elem : cs.stacks)
|
||||
{
|
||||
SlotID dest = getSlotFor(elem.second->type);
|
||||
if(!dest.validSlot() || hasStackAtSlot(dest))
|
||||
@@ -598,11 +587,11 @@ bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStac
|
||||
SlotID j;
|
||||
|
||||
//get types of creatures that need their own slot
|
||||
for(auto & elem : cs.stacks)
|
||||
for(const auto & elem : cs.stacks)
|
||||
if ((j = cres.getSlotFor(elem.second->type)).validSlot())
|
||||
cres.addToSlot(j, elem.second->type->idNumber, 1, true); //merge if possible
|
||||
//cres.addToSlot(elem.first, elem.second->type->idNumber, 1, true);
|
||||
for(auto & elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if ((j = cres.getSlotFor(elem.second->type)).validSlot())
|
||||
cres.addToSlot(j, elem.second->type->idNumber, 1, true); //merge if possible
|
||||
@@ -613,7 +602,7 @@ bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStac
|
||||
}
|
||||
}
|
||||
|
||||
bool CCreatureSet::hasStackAtSlot(SlotID slot) const
|
||||
bool CCreatureSet::hasStackAtSlot(const SlotID & slot) const
|
||||
{
|
||||
return vstd::contains(stacks, slot);
|
||||
}
|
||||
@@ -667,9 +656,9 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
|
||||
|
||||
if(amount > 0)
|
||||
{
|
||||
CStackInstance * new_stack = new CStackInstance();
|
||||
auto * new_stack = new CStackInstance();
|
||||
new_stack->serializeJson(handler);
|
||||
putStack(SlotID((si32)idx), new_stack);
|
||||
putStack(SlotID(static_cast<si32>(idx)), new_stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -681,8 +670,8 @@ CStackInstance::CStackInstance()
|
||||
init();
|
||||
}
|
||||
|
||||
CStackInstance::CStackInstance(CreatureID id, TQuantity Count, bool isHypothetic)
|
||||
: CBonusSystemNode(isHypothetic), armyObj(_armyObj)
|
||||
CStackInstance::CStackInstance(const CreatureID & id, TQuantity Count, bool isHypothetic):
|
||||
CBonusSystemNode(isHypothetic), armyObj(_armyObj)
|
||||
{
|
||||
init();
|
||||
setType(id);
|
||||
@@ -719,7 +708,7 @@ int CStackInstance::getExpRank() const
|
||||
int tier = type->level;
|
||||
if (vstd::iswithin(tier, 1, 7))
|
||||
{
|
||||
for (int i = (int)VLC->creh->expRanks[tier].size()-2; i >-1; --i)//sic!
|
||||
for(int i = static_cast<int>(VLC->creh->expRanks[tier].size()) - 2; i > -1; --i) //sic!
|
||||
{ //exp values vary from 1st level to max exp at 11th level
|
||||
if (experience >= VLC->creh->expRanks[tier][i])
|
||||
return ++i; //faster, but confusing - 0 index mean 1st level of experience
|
||||
@@ -728,7 +717,7 @@ int CStackInstance::getExpRank() const
|
||||
}
|
||||
else //higher tier
|
||||
{
|
||||
for (int i = (int)VLC->creh->expRanks[0].size()-2; i >-1; --i)
|
||||
for(int i = static_cast<int>(VLC->creh->expRanks[0].size()) - 2; i > -1; --i)
|
||||
{
|
||||
if (experience >= VLC->creh->expRanks[0][i])
|
||||
return ++i;
|
||||
@@ -739,7 +728,7 @@ int CStackInstance::getExpRank() const
|
||||
|
||||
int CStackInstance::getLevel() const
|
||||
{
|
||||
return std::max (1, (int)type->level);
|
||||
return std::max(1, static_cast<int>(type->level));
|
||||
}
|
||||
|
||||
si32 CStackInstance::magicResistance() const
|
||||
@@ -758,12 +747,12 @@ void CStackInstance::giveStackExp(TExpType exp)
|
||||
CCreatureHandler * creh = VLC->creh;
|
||||
ui32 maxExp = creh->expRanks[level].back();
|
||||
|
||||
vstd::amin(exp, (TExpType)maxExp); //prevent exp overflow due to different types
|
||||
vstd::amin(exp, static_cast<TExpType>(maxExp)); //prevent exp overflow due to different types
|
||||
vstd::amin(exp, (maxExp * creh->maxExpPerBattle[level])/100);
|
||||
vstd::amin(experience += exp, maxExp); //can't get more exp than this limit
|
||||
}
|
||||
|
||||
void CStackInstance::setType(CreatureID creID)
|
||||
void CStackInstance::setType(const CreatureID & creID)
|
||||
{
|
||||
if(creID >= 0 && creID < VLC->creh->objects.size())
|
||||
setType(VLC->creh->objects[creID]);
|
||||
@@ -790,7 +779,7 @@ std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus, b
|
||||
return VLC->getBth()->bonusToString(bonus, this, description);
|
||||
}
|
||||
|
||||
std::string CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus>& bonus) const
|
||||
std::string CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const
|
||||
{
|
||||
return VLC->getBth()->bonusToGraphics(bonus);
|
||||
}
|
||||
@@ -832,11 +821,6 @@ bool CStackInstance::valid(bool allowUnrandomized) const
|
||||
return allowUnrandomized;
|
||||
}
|
||||
|
||||
CStackInstance::~CStackInstance()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string CStackInstance::nodeName() const
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -903,7 +887,7 @@ void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
if(idRand > -1)
|
||||
{
|
||||
int level = (int)idRand / 2;
|
||||
int level = idRand / 2;
|
||||
|
||||
boost::logic::tribool upgraded = (idRand % 2) > 0;
|
||||
|
||||
@@ -922,7 +906,7 @@ void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
handler.serializeInt("level", level, 0);
|
||||
handler.serializeBool("upgraded", upgraded);
|
||||
|
||||
idRand = level * 2 + (int)(bool)upgraded;
|
||||
idRand = level * 2 + static_cast<int>(upgraded);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -930,14 +914,13 @@ void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
CCommanderInstance::CCommanderInstance()
|
||||
{
|
||||
init();
|
||||
name = "Unnamed";
|
||||
}
|
||||
|
||||
CCommanderInstance::CCommanderInstance (CreatureID id)
|
||||
CCommanderInstance::CCommanderInstance(const CreatureID & id): name("Commando")
|
||||
{
|
||||
init();
|
||||
setType(id);
|
||||
name = "Commando"; //TODO - parse them
|
||||
//TODO - parse them
|
||||
}
|
||||
|
||||
void CCommanderInstance::init()
|
||||
@@ -953,11 +936,6 @@ void CCommanderInstance::init()
|
||||
secondarySkills.resize (ECommander::SPELL_POWER + 1);
|
||||
}
|
||||
|
||||
CCommanderInstance::~CCommanderInstance()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCommanderInstance::setAlive (bool Alive)
|
||||
{
|
||||
//TODO: helm of immortality
|
||||
@@ -987,7 +965,7 @@ int CCommanderInstance::getLevel() const
|
||||
void CCommanderInstance::levelUp ()
|
||||
{
|
||||
level++;
|
||||
for (auto bonus : VLC->creh->commanderLevelPremy)
|
||||
for(const auto & bonus : VLC->creh->commanderLevelPremy)
|
||||
{ //grant all regular level-up bonuses
|
||||
accumulateBonus(bonus);
|
||||
}
|
||||
@@ -1000,17 +978,15 @@ ArtBearer::ArtBearer CCommanderInstance::bearerType() const
|
||||
|
||||
bool CCommanderInstance::gainsLevel() const
|
||||
{
|
||||
return experience >= (TExpType)VLC->heroh->reqExp(level+1);
|
||||
return experience >= static_cast<TExpType>(VLC->heroh->reqExp(level + 1));
|
||||
}
|
||||
|
||||
CStackBasicDescriptor::CStackBasicDescriptor()
|
||||
{
|
||||
type = nullptr;
|
||||
count = -1;
|
||||
}
|
||||
//This constructor should be placed here to avoid side effects
|
||||
CStackBasicDescriptor::CStackBasicDescriptor() = default;
|
||||
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(CreatureID id, TQuantity Count)
|
||||
: type (VLC->creh->objects[id]), count(Count)
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(const CreatureID & id, TQuantity Count):
|
||||
type(VLC->creh->objects[id]),
|
||||
count(Count)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1049,7 +1025,7 @@ void CStackBasicDescriptor::serializeJson(JsonSerializeFormat & handler)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string typeName("");
|
||||
std::string typeName;
|
||||
handler.serializeString("type", typeName);
|
||||
if(!typeName.empty())
|
||||
setType(VLC->creh->getCreature(CModHandler::scopeMap(), typeName));
|
||||
@@ -1063,7 +1039,7 @@ void CSimpleArmy::clear()
|
||||
|
||||
CSimpleArmy::operator bool() const
|
||||
{
|
||||
return army.size();
|
||||
return !army.empty();
|
||||
}
|
||||
|
||||
bool CSimpleArmy::setCreature(SlotID slot, CreatureID cre, TQuantity count)
|
||||
|
@@ -27,10 +27,10 @@ class DLL_LINKAGE CStackBasicDescriptor
|
||||
{
|
||||
public:
|
||||
const CCreature *type;
|
||||
TQuantity count; //exact quantity or quantity ID from CCreature::getQuantityID when getting info about enemy army
|
||||
TQuantity count = -1;; //exact quantity or quantity ID from CCreature::getQuantityID when getting info about enemy army
|
||||
|
||||
CStackBasicDescriptor();
|
||||
CStackBasicDescriptor(CreatureID id, TQuantity Count);
|
||||
CStackBasicDescriptor(const CreatureID & id, TQuantity Count);
|
||||
CStackBasicDescriptor(const CCreature *c, TQuantity Count);
|
||||
virtual ~CStackBasicDescriptor() = default;
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
|
||||
//overrides CBonusSystemNode
|
||||
std::string bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const override; // how would bonus description look for this particular type of node
|
||||
std::string bonusToGraphics(const std::shared_ptr<Bonus>& bonus) const; //file name of graphics from StackSkills , in future possibly others
|
||||
std::string bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const; //file name of graphics from StackSkills , in future possibly others
|
||||
|
||||
virtual ui64 getPower() const;
|
||||
CCreature::CreatureQuantityId getQuantityID() const;
|
||||
@@ -102,11 +102,11 @@ public:
|
||||
std::string getName() const; //plural or singular
|
||||
virtual void init();
|
||||
CStackInstance();
|
||||
CStackInstance(CreatureID id, TQuantity count, bool isHypothetic = false);
|
||||
CStackInstance(const CreatureID & id, TQuantity count, bool isHypothetic = false);
|
||||
CStackInstance(const CCreature *cre, TQuantity count, bool isHypothetic = false);
|
||||
virtual ~CStackInstance();
|
||||
virtual ~CStackInstance() = default;
|
||||
|
||||
void setType(CreatureID creID);
|
||||
void setType(const CreatureID & creID);
|
||||
void setType(const CCreature * c) override;
|
||||
void setArmyObj(const CArmedInstance *ArmyObj);
|
||||
virtual void giveStackExp(TExpType exp);
|
||||
@@ -132,8 +132,7 @@ public:
|
||||
//std::vector <CArtifactInstance *> arts;
|
||||
void init() override;
|
||||
CCommanderInstance();
|
||||
CCommanderInstance (CreatureID id);
|
||||
virtual ~CCommanderInstance();
|
||||
CCommanderInstance(const CreatureID & id);
|
||||
void setAlive (bool alive);
|
||||
void giveStackExp (TExpType exp) override;
|
||||
void levelUp ();
|
||||
@@ -196,51 +195,51 @@ public:
|
||||
|
||||
class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures
|
||||
{
|
||||
CCreatureSet(const CCreatureSet&);
|
||||
CCreatureSet(const CCreatureSet &) = delete;
|
||||
CCreatureSet &operator=(const CCreatureSet&);
|
||||
public:
|
||||
TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity)
|
||||
ui8 formation; //false - wide, true - tight
|
||||
ui8 formation; //0 - wide, 1 - tight
|
||||
|
||||
CCreatureSet();
|
||||
CCreatureSet() = default; //Should be here to avoid compile errors
|
||||
virtual ~CCreatureSet();
|
||||
virtual void armyChanged();
|
||||
|
||||
const CStackInstance &operator[](SlotID slot) const;
|
||||
const CStackInstance & operator[](const SlotID & slot) const;
|
||||
|
||||
const TSlots &Slots() const {return stacks;}
|
||||
|
||||
void addToSlot(SlotID slot, CreatureID cre, TQuantity count, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(SlotID slot, CStackInstance *stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(const SlotID & slot, CStackInstance * stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
void clear() override;
|
||||
void setFormation(bool tight);
|
||||
CArmedInstance *castToArmyObj();
|
||||
|
||||
//basic operations
|
||||
void putStack(SlotID slot, CStackInstance *stack); //adds new stack to the army, slot must be empty
|
||||
void setStackCount(SlotID slot, TQuantity count); //stack must exist!
|
||||
CStackInstance *detachStack(SlotID slot); //removes stack from army but doesn't destroy it (so it can be moved somewhere else or safely deleted)
|
||||
void setStackType(SlotID slot, CreatureID type);
|
||||
void putStack(const SlotID & slot, CStackInstance * stack); //adds new stack to the army, slot must be empty
|
||||
void setStackCount(const SlotID & slot, TQuantity count); //stack must exist!
|
||||
CStackInstance * detachStack(const SlotID & slot); //removes stack from army but doesn't destroy it (so it can be moved somewhere else or safely deleted)
|
||||
void setStackType(const SlotID & slot, const CreatureID & type);
|
||||
void giveStackExp(TExpType exp);
|
||||
void setStackExp(SlotID slot, TExpType exp);
|
||||
void setStackExp(const SlotID & slot, TExpType exp);
|
||||
|
||||
//derivative
|
||||
void eraseStack(SlotID slot); //slot must be occupied
|
||||
void joinStack(SlotID slot, CStackInstance * stack); //adds new stack to the existing stack of the same type
|
||||
void changeStackCount(SlotID slot, TQuantity toAdd); //stack must exist!
|
||||
void eraseStack(const SlotID & slot); //slot must be occupied
|
||||
void joinStack(const SlotID & slot, CStackInstance * stack); //adds new stack to the existing stack of the same type
|
||||
void changeStackCount(const SlotID & slot, TQuantity toAdd); //stack must exist!
|
||||
bool setCreature (SlotID slot, CreatureID type, TQuantity quantity) override; //replaces creature in stack; slots 0 to 6, if quantity=0 erases stack
|
||||
void setToArmy(CSimpleArmy &src); //erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all.
|
||||
|
||||
const CStackInstance& getStack(SlotID slot) const; //stack must exist
|
||||
const CStackInstance* getStackPtr(SlotID slot) const; //if stack doesn't exist, returns nullptr
|
||||
const CCreature* getCreature(SlotID slot) const; //workaround of map issue;
|
||||
int getStackCount (SlotID slot) const;
|
||||
TExpType getStackExperience(SlotID slot) const;
|
||||
const CStackInstance & getStack(const SlotID & slot) const; //stack must exist
|
||||
const CStackInstance * getStackPtr(const SlotID & slot) const; //if stack doesn't exist, returns nullptr
|
||||
const CCreature * getCreature(const SlotID & slot) const; //workaround of map issue;
|
||||
int getStackCount(const SlotID & slot) const;
|
||||
TExpType getStackExperience(const SlotID & slot) const;
|
||||
SlotID findStack(const CStackInstance *stack) const; //-1 if none
|
||||
SlotID getSlotFor(CreatureID creature, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
SlotID getSlotFor(const CreatureID & creature, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
SlotID getSlotFor(const CCreature *c, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
bool hasCreatureSlots(const CCreature * c, SlotID exclude) const;
|
||||
std::vector<SlotID> getCreatureSlots(const CCreature * c, SlotID exclude, TQuantity ignoreAmount = -1) const;
|
||||
bool hasCreatureSlots(const CCreature * c, const SlotID & exclude) const;
|
||||
std::vector<SlotID> getCreatureSlots(const CCreature * c, const SlotID & exclude, TQuantity ignoreAmount = -1) const;
|
||||
bool isCreatureBalanced(const CCreature* c, TQuantity ignoreAmount = 1) const; // Check if the creature is evenly distributed across slots
|
||||
|
||||
SlotID getFreeSlot(ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns first free slot
|
||||
@@ -248,18 +247,18 @@ public:
|
||||
std::queue<SlotID> getFreeSlotsQueue(ui32 slotsAmount = GameConstants::ARMY_SIZE) const;
|
||||
|
||||
TMapCreatureSlot getCreatureMap() const;
|
||||
TCreatureQueue getCreatureQueue(SlotID exclude) const;
|
||||
TCreatureQueue getCreatureQueue(const SlotID & exclude) const;
|
||||
|
||||
bool mergableStacks(std::pair<SlotID, SlotID> &out, SlotID preferable = SlotID()) const; //looks for two same stacks, returns slot positions;
|
||||
bool mergableStacks(std::pair<SlotID, SlotID> & out, const SlotID & preferable = SlotID()) const; //looks for two same stacks, returns slot positions;
|
||||
bool validTypes(bool allowUnrandomized = false) const; //checks if all types of creatures are set properly
|
||||
bool slotEmpty(SlotID slot) const;
|
||||
bool slotEmpty(const SlotID & slot) const;
|
||||
int stacksCount() const;
|
||||
virtual bool needsLastStack() const; //true if last stack cannot be taken
|
||||
ui64 getArmyStrength() const; //sum of AI values of creatures
|
||||
ui64 getPower (SlotID slot) const; //value of specific stack
|
||||
std::string getRoughAmount(SlotID slot, int mode = 0) const; //rough size of specific stack
|
||||
ui64 getPower(const SlotID & slot) const; //value of specific stack
|
||||
std::string getRoughAmount(const SlotID & slot, int mode = 0) const; //rough size of specific stack
|
||||
std::string getArmyDescription() const;
|
||||
bool hasStackAtSlot(SlotID slot) const;
|
||||
bool hasStackAtSlot(const SlotID & slot) const;
|
||||
|
||||
bool contains(const CStackInstance *stack) const;
|
||||
bool canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks = true) const;
|
||||
|
@@ -248,15 +248,15 @@ bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown
|
||||
{
|
||||
if(!detailed && nullptr != selectedObject)
|
||||
{
|
||||
const CGHeroInstance * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
||||
const auto * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
||||
if(nullptr != selectedHero)
|
||||
detailed = selectedHero->hasVisions(town, 1);
|
||||
}
|
||||
|
||||
dest.initFromTown(static_cast<const CGTownInstance *>(town), detailed);
|
||||
dest.initFromTown(dynamic_cast<const CGTownInstance *>(town), detailed);
|
||||
}
|
||||
else if(town->ID == Obj::GARRISON || town->ID == Obj::GARRISON2)
|
||||
dest.initFromArmy(static_cast<const CArmedInstance *>(town), detailed);
|
||||
dest.initFromArmy(dynamic_cast<const CArmedInstance *>(town), detailed);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
@@ -272,7 +272,7 @@ std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (in
|
||||
{
|
||||
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", std::vector<const CGObjectInstance*>());
|
||||
std::vector<const CGObjectInstance*> ret;
|
||||
for(auto cr : gs->guardingCreatures(pos))
|
||||
for(auto * cr : gs->guardingCreatures(pos))
|
||||
{
|
||||
ret.push_back(cr);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (in
|
||||
|
||||
bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject) const
|
||||
{
|
||||
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(hero);
|
||||
const auto * h = dynamic_cast<const CGHeroInstance *>(hero);
|
||||
|
||||
ERROR_RET_VAL_IF(!h, "That's not a hero!", false);
|
||||
|
||||
@@ -300,7 +300,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
||||
|
||||
if( (infoLevel == InfoAboutHero::EInfoLevel::BASIC) && nullptr != selectedObject)
|
||||
{
|
||||
const CGHeroInstance * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
||||
const auto * selectedHero = dynamic_cast<const CGHeroInstance *>(selectedObject);
|
||||
if(nullptr != selectedHero)
|
||||
if(selectedHero->hasVisions(hero, 1))
|
||||
infoLevel = InfoAboutHero::EInfoLevel::DETAILED;
|
||||
@@ -322,7 +322,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
||||
|
||||
for(auto & elem : info.army)
|
||||
{
|
||||
if((int)elem.second.type->AIValue > maxAIValue)
|
||||
if(static_cast<int>(elem.second.type->AIValue) > maxAIValue)
|
||||
{
|
||||
maxAIValue = elem.second.type->AIValue;
|
||||
mostStrong = elem.second.type;
|
||||
@@ -358,7 +358,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
||||
|
||||
for(auto creature : VLC->creh->objects)
|
||||
{
|
||||
if((si16)creature->faction == factionIndex && (int)creature->AIValue > maxAIValue)
|
||||
if(static_cast<si16>(creature->faction) == factionIndex && static_cast<int>(creature->AIValue) > maxAIValue)
|
||||
{
|
||||
maxAIValue = creature->AIValue;
|
||||
mostStrong = creature;
|
||||
@@ -400,7 +400,7 @@ int CGameInfoCallback::getDate(Date::EDateType mode) const
|
||||
return gs->getDate(mode);
|
||||
}
|
||||
|
||||
bool CGameInfoCallback::isVisible(int3 pos, boost::optional<PlayerColor> Player) const
|
||||
bool CGameInfoCallback::isVisible(int3 pos, const boost::optional<PlayerColor> & Player) const
|
||||
{
|
||||
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
return gs->isVisible(pos, Player);
|
||||
@@ -411,7 +411,7 @@ bool CGameInfoCallback::isVisible(int3 pos) const
|
||||
return isVisible(pos, player);
|
||||
}
|
||||
|
||||
bool CGameInfoCallback::isVisible( const CGObjectInstance *obj, boost::optional<PlayerColor> Player ) const
|
||||
bool CGameInfoCallback::isVisible( const CGObjectInstance *obj,const boost::optional<PlayerColor> & Player) const
|
||||
{
|
||||
return gs->isVisible(obj, Player);
|
||||
}
|
||||
@@ -521,13 +521,13 @@ EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) cons
|
||||
std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const
|
||||
{
|
||||
assert(player.is_initialized());
|
||||
auto team = getPlayerTeam(player.get());
|
||||
const auto * team = getPlayerTeam(player.get());
|
||||
|
||||
size_t width = gs->map->width;
|
||||
size_t height = gs->map->height;
|
||||
size_t levels = gs->map->levels();
|
||||
|
||||
auto ptr = new boost::multi_array<TerrainTile*, 3>(boost::extents[levels][width][height]);
|
||||
auto * ptr = new boost::multi_array<TerrainTile *, 3>(boost::extents[levels][width][height]);
|
||||
|
||||
int3 tile;
|
||||
for(tile.z = 0; tile.z < levels; tile.z++)
|
||||
@@ -560,12 +560,12 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
|
||||
if(vstd::contains(t->forbiddenBuildings, ID))
|
||||
return EBuildingState::FORBIDDEN; //forbidden
|
||||
|
||||
auto possiblyNotBuiltTest = [&](BuildingID id) -> bool
|
||||
auto possiblyNotBuiltTest = [&](const BuildingID & id) -> bool
|
||||
{
|
||||
return ((id == BuildingID::CAPITOL) ? true : !t->hasBuilt(id));
|
||||
};
|
||||
|
||||
std::function<bool(BuildingID id)> allowedTest = [&](BuildingID id) -> bool
|
||||
std::function<bool(BuildingID id)> allowedTest = [&](const BuildingID & id) -> bool
|
||||
{
|
||||
return !vstd::contains(t->forbiddenBuildings, id);
|
||||
};
|
||||
@@ -595,7 +595,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
|
||||
return EBuildingState::NO_WATER; //lack of water
|
||||
}
|
||||
|
||||
auto buildTest = [&](BuildingID id) -> bool
|
||||
auto buildTest = [&](const BuildingID & id) -> bool
|
||||
{
|
||||
return t->hasBuilt(id);
|
||||
};
|
||||
@@ -633,7 +633,8 @@ EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bo
|
||||
|
||||
std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTavern) const
|
||||
{
|
||||
std::string text = "", extraText = "";
|
||||
std::string text;
|
||||
std::string extraText;
|
||||
if(gs->rumor.type == RumorState::TYPE_NONE)
|
||||
return text;
|
||||
|
||||
@@ -680,7 +681,7 @@ int CGameInfoCallback::getHeroCount( PlayerColor player, bool includeGarrisoned
|
||||
if(includeGarrisoned)
|
||||
return static_cast<int>(p->heroes.size());
|
||||
else
|
||||
for(auto & elem : p->heroes)
|
||||
for(const auto & elem : p->heroes)
|
||||
if(!elem->inTownGarrison)
|
||||
ret++;
|
||||
return ret;
|
||||
@@ -701,14 +702,10 @@ PlayerColor CGameInfoCallback::getCurrentPlayer() const
|
||||
return gs->currentPlayer;
|
||||
}
|
||||
|
||||
CGameInfoCallback::CGameInfoCallback()
|
||||
CGameInfoCallback::CGameInfoCallback(CGameState * GS, boost::optional<PlayerColor> Player):
|
||||
gs(GS)
|
||||
{
|
||||
}
|
||||
|
||||
CGameInfoCallback::CGameInfoCallback(CGameState *GS, boost::optional<PlayerColor> Player)
|
||||
{
|
||||
gs = GS;
|
||||
player = Player;
|
||||
player = std::move(Player);
|
||||
}
|
||||
|
||||
std::shared_ptr<const boost::multi_array<ui8, 3>> CPlayerSpecificInfoCallback::getVisibilityMap() const
|
||||
@@ -823,7 +820,7 @@ std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings()
|
||||
std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
|
||||
{
|
||||
std::vector <QuestInfo> ret;
|
||||
for (auto quest : gs->getPlayerState(*player)->quests)
|
||||
for(const auto & quest : gs->getPlayerState(*player)->quests)
|
||||
{
|
||||
ret.push_back (quest);
|
||||
}
|
||||
@@ -845,7 +842,7 @@ const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId,
|
||||
|
||||
if (!includeGarrisoned)
|
||||
{
|
||||
for(ui32 i = 0; i < p->heroes.size() && (int)i<=serialId; i++)
|
||||
for(ui32 i = 0; i < p->heroes.size() && static_cast<int>(i) <= serialId; i++)
|
||||
if(p->heroes[i]->inTownGarrison)
|
||||
serialId++;
|
||||
}
|
||||
@@ -942,7 +939,7 @@ void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3, ShashInt
|
||||
gs->getTilesInRange(tiles, pos, radious, getLocalPlayer(), -1, distanceFormula);
|
||||
}
|
||||
|
||||
void CGameInfoCallback::calculatePaths(std::shared_ptr<PathfinderConfig> config)
|
||||
void CGameInfoCallback::calculatePaths(const std::shared_ptr<PathfinderConfig> & config)
|
||||
{
|
||||
gs->calculatePaths(config);
|
||||
}
|
||||
@@ -965,9 +962,9 @@ const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid
|
||||
|
||||
std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const
|
||||
{
|
||||
vstd::erase_if(ids, [&](ObjectInstanceID id) -> bool
|
||||
vstd::erase_if(ids, [&](const ObjectInstanceID & id) -> bool
|
||||
{
|
||||
auto obj = getObj(id, false);
|
||||
const auto * obj = getObj(id, false);
|
||||
return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisible(obj->pos, player));
|
||||
});
|
||||
return ids;
|
||||
@@ -987,8 +984,8 @@ ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID
|
||||
{
|
||||
std::vector<ObjectInstanceID> entrances = getTeleportChannelEntraces(id, player);
|
||||
std::vector<ObjectInstanceID> exits = getTeleportChannelExits(id, player);
|
||||
if((!entrances.size() || !exits.size()) // impassable if exits or entrances list are empty
|
||||
|| (entrances.size() == 1 && entrances == exits)) // impassable if only entrance and only exit is same object. e.g bidirectional monolith
|
||||
if((entrances.empty() || exits.empty()) // impassable if exits or entrances list are empty
|
||||
|| (entrances.size() == 1 && entrances == exits)) // impassable if only entrance and only exit is same object. e.g bidirectional monolith
|
||||
{
|
||||
return ETeleportChannelType::IMPASSABLE;
|
||||
}
|
||||
@@ -996,7 +993,7 @@ ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID
|
||||
auto intersection = vstd::intersection(entrances, exits);
|
||||
if(intersection.size() == entrances.size() && intersection.size() == exits.size())
|
||||
return ETeleportChannelType::BIDIRECTIONAL;
|
||||
else if(!intersection.size())
|
||||
else if(intersection.empty())
|
||||
return ETeleportChannelType::UNIDIRECTIONAL;
|
||||
else
|
||||
return ETeleportChannelType::MIXED;
|
||||
|
@@ -132,7 +132,7 @@ class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase, public IGame
|
||||
protected:
|
||||
CGameState * gs;//todo: replace with protected const getter, only actual Server and Client objects should hold game state
|
||||
|
||||
CGameInfoCallback();
|
||||
CGameInfoCallback() = default;
|
||||
CGameInfoCallback(CGameState *GS, boost::optional<PlayerColor> Player);
|
||||
bool hasAccess(boost::optional<PlayerColor> playerId) const;
|
||||
|
||||
@@ -157,8 +157,8 @@ public:
|
||||
virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
|
||||
|
||||
//map
|
||||
virtual bool isVisible(int3 pos, boost::optional<PlayerColor> Player) const;
|
||||
virtual bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> Player) const;
|
||||
virtual bool isVisible(int3 pos, const boost::optional<PlayerColor> & Player) const;
|
||||
virtual bool isVisible(const CGObjectInstance *obj, const boost::optional<PlayerColor> & Player) const;
|
||||
virtual bool isVisible(const CGObjectInstance *obj) const;
|
||||
virtual bool isVisible(int3 pos) const;
|
||||
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
virtual std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
|
||||
virtual bool isInTheMap(const int3 &pos) const;
|
||||
virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
|
||||
virtual void calculatePaths(std::shared_ptr<PathfinderConfig> config);
|
||||
virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config);
|
||||
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out);
|
||||
virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;
|
||||
|
||||
|
@@ -40,8 +40,8 @@ std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const s
|
||||
// is possible only via specializations of this template
|
||||
throw std::runtime_error("Could not resolve ai library " + libpath.generic_string());
|
||||
#else
|
||||
typedef void(* TGetAIFun)(std::shared_ptr<rett> &);
|
||||
typedef void(* TGetNameFun)(char *);
|
||||
using TGetAIFun = void (*)(std::shared_ptr<rett> &);
|
||||
using TGetNameFun = void (*)(char *);
|
||||
|
||||
char temp[150];
|
||||
|
||||
@@ -56,8 +56,8 @@ std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const s
|
||||
HMODULE dll = LoadLibraryW(libpath.c_str());
|
||||
if (dll)
|
||||
{
|
||||
getName = (TGetNameFun)GetProcAddress(dll, "GetAiName");
|
||||
getAI = (TGetAIFun)GetProcAddress(dll, methodName.c_str());
|
||||
getName = reinterpret_cast<TGetNameFun>(GetProcAddress(dll, "GetAiName"));
|
||||
getAI = reinterpret_cast<TGetAIFun>(GetProcAddress(dll, methodName.c_str()));
|
||||
}
|
||||
#ifdef __MINGW32__
|
||||
#pragma GCC diagnostic pop
|
||||
@@ -66,8 +66,8 @@ std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const s
|
||||
void *dll = dlopen(libpath.string().c_str(), RTLD_LOCAL | RTLD_LAZY);
|
||||
if (dll)
|
||||
{
|
||||
getName = (TGetNameFun)dlsym(dll, "GetAiName");
|
||||
getAI = (TGetAIFun)dlsym(dll, methodName.c_str());
|
||||
getName = reinterpret_cast<TGetNameFun>(dlsym(dll, "GetAiName"));
|
||||
getAI = reinterpret_cast<TGetAIFun>(dlsym(dll, methodName.c_str()));
|
||||
}
|
||||
#endif // VCMI_WINDOWS
|
||||
|
||||
@@ -125,22 +125,22 @@ std::shared_ptr<CBattleGameInterface> createAny(const boost::filesystem::path &
|
||||
#endif // STATIC_AI
|
||||
|
||||
template<typename rett>
|
||||
std::shared_ptr<rett> createAnyAI(std::string dllname, const std::string & methodName)
|
||||
std::shared_ptr<rett> createAnyAI(const std::string & dllname, const std::string & methodName)
|
||||
{
|
||||
logGlobal->info("Opening %s", dllname);
|
||||
|
||||
const boost::filesystem::path filePath = VCMIDirs::get().fullLibraryPath("AI", dllname);
|
||||
auto ret = createAny<rett>(filePath, methodName);
|
||||
ret->dllName = std::move(dllname);
|
||||
ret->dllName = dllname;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<CGlobalAI> CDynLibHandler::getNewAI(std::string dllname)
|
||||
std::shared_ptr<CGlobalAI> CDynLibHandler::getNewAI(const std::string & dllname)
|
||||
{
|
||||
return createAnyAI<CGlobalAI>(dllname, "GetNewAI");
|
||||
}
|
||||
|
||||
std::shared_ptr<CBattleGameInterface> CDynLibHandler::getNewBattleAI(std::string dllname)
|
||||
std::shared_ptr<CBattleGameInterface> CDynLibHandler::getNewBattleAI(const std::string & dllname)
|
||||
{
|
||||
return createAnyAI<CBattleGameInterface>(dllname, "GetNewBattleAI");
|
||||
}
|
||||
|
@@ -121,8 +121,8 @@ public:
|
||||
class DLL_LINKAGE CDynLibHandler
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<CGlobalAI> getNewAI(std::string dllname);
|
||||
static std::shared_ptr<CBattleGameInterface> getNewBattleAI(std::string dllname);
|
||||
static std::shared_ptr<CGlobalAI> getNewAI(const std::string & dllname);
|
||||
static std::shared_ptr<CBattleGameInterface> getNewBattleAI(const std::string & dllname);
|
||||
#if SCRIPTING_ENABLED
|
||||
static std::shared_ptr<scripting::Module> getNewScriptingModule(const boost::filesystem::path & dllname);
|
||||
#endif
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
class DLL_LINKAGE CAdventureAI : public CGlobalAI
|
||||
{
|
||||
public:
|
||||
CAdventureAI() {};
|
||||
CAdventureAI() = default;
|
||||
|
||||
std::shared_ptr<CBattleGameInterface> battleAI;
|
||||
std::shared_ptr<CBattleCallback> cbc;
|
||||
|
@@ -48,7 +48,7 @@ class CBaseForGSApply
|
||||
{
|
||||
public:
|
||||
virtual void applyOnGS(CGameState *gs, void *pack) const =0;
|
||||
virtual ~CBaseForGSApply(){};
|
||||
virtual ~CBaseForGSApply() = default;
|
||||
template<typename U> static CBaseForGSApply *getApplier(const U * t=nullptr)
|
||||
{
|
||||
return new CApplyOnGS<U>();
|
||||
@@ -67,13 +67,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst) const
|
||||
void MetaString::getLocalString(const std::pair<ui8, ui32> & txt, std::string & dst) const
|
||||
{
|
||||
int type = txt.first, ser = txt.second;
|
||||
int type = txt.first;
|
||||
int ser = txt.second;
|
||||
|
||||
if(type == ART_NAMES)
|
||||
{
|
||||
auto art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
if(art)
|
||||
dst = art->getNameTranslated();
|
||||
else
|
||||
@@ -81,7 +82,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
}
|
||||
else if(type == ART_DESCR)
|
||||
{
|
||||
auto art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
if(art)
|
||||
dst = art->getDescriptionTranslated();
|
||||
else
|
||||
@@ -89,7 +90,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
}
|
||||
else if (type == ART_EVNTS)
|
||||
{
|
||||
auto art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
const auto * art = ArtifactID(ser).toArtifact(VLC->artifacts());
|
||||
if(art)
|
||||
dst = art->getEventTranslated();
|
||||
else
|
||||
@@ -97,7 +98,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
}
|
||||
else if(type == CRE_PL_NAMES)
|
||||
{
|
||||
auto cre = CreatureID(ser).toCreature(VLC->creatures());
|
||||
const auto * cre = CreatureID(ser).toCreature(VLC->creatures());
|
||||
if(cre)
|
||||
dst = cre->getNamePluralTranslated();
|
||||
else
|
||||
@@ -105,7 +106,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
}
|
||||
else if(type == CRE_SING_NAMES)
|
||||
{
|
||||
auto cre = CreatureID(ser).toCreature(VLC->creatures());
|
||||
const auto * cre = CreatureID(ser).toCreature(VLC->creatures());
|
||||
if(cre)
|
||||
dst = cre->getNameSingularTranslated();
|
||||
else
|
||||
@@ -121,7 +122,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
}
|
||||
else if(type == SPELL_NAME)
|
||||
{
|
||||
auto spell = SpellID(ser).toSpell(VLC->spells());
|
||||
const auto * spell = SpellID(ser).toSpell(VLC->spells());
|
||||
if(spell)
|
||||
dst = spell->getNameTranslated();
|
||||
else
|
||||
@@ -173,10 +174,12 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
|
||||
|
||||
DLL_LINKAGE void MetaString::toString(std::string &dst) const
|
||||
{
|
||||
size_t exSt = 0, loSt = 0, nums = 0;
|
||||
size_t exSt = 0;
|
||||
size_t loSt = 0;
|
||||
size_t nums = 0;
|
||||
dst.clear();
|
||||
|
||||
for(auto & elem : message)
|
||||
for(const auto & elem : message)
|
||||
{//TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER
|
||||
switch(elem)
|
||||
{
|
||||
@@ -227,7 +230,9 @@ DLL_LINKAGE std::string MetaString::buildList () const
|
||||
///used to handle loot from creature bank
|
||||
{
|
||||
|
||||
size_t exSt = 0, loSt = 0, nums = 0;
|
||||
size_t exSt = 0;
|
||||
size_t loSt = 0;
|
||||
size_t nums = 0;
|
||||
std::string lista;
|
||||
for (int i = 0; i < message.size(); ++i)
|
||||
{
|
||||
@@ -290,7 +295,7 @@ void MetaString::addReplacement(const CStackBasicDescriptor & stack)
|
||||
addCreReplacement(stack.type->idNumber, stack.count);
|
||||
}
|
||||
|
||||
static CGObjectInstance * createObject(Obj id, int subid, int3 pos, PlayerColor owner)
|
||||
static CGObjectInstance * createObject(const Obj & id, int subid, const int3 & pos, const PlayerColor & owner)
|
||||
{
|
||||
CGObjectInstance * nobj;
|
||||
switch(id)
|
||||
@@ -318,8 +323,12 @@ static CGObjectInstance * createObject(Obj id, int subid, int3 pos, PlayerColor
|
||||
return nobj;
|
||||
}
|
||||
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor player, const CTown *town,
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > &available, CRandomGenerator & rand, const CHeroClass * bannedClass) const
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native,
|
||||
const PlayerColor & player,
|
||||
const CTown * town,
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance>> & available,
|
||||
CRandomGenerator & rand,
|
||||
const CHeroClass * bannedClass) const
|
||||
{
|
||||
CGHeroInstance *ret = nullptr;
|
||||
|
||||
@@ -341,7 +350,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor pl
|
||||
pool.push_back(elem.second); //get all available heroes
|
||||
}
|
||||
}
|
||||
if(!pool.size())
|
||||
if(pool.empty())
|
||||
{
|
||||
logGlobal->error("Cannot pick native hero for %s. Picking any...", player.getStr());
|
||||
return pickHeroFor(false, player, town, available, rand);
|
||||
@@ -353,7 +362,8 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor pl
|
||||
}
|
||||
else
|
||||
{
|
||||
int sum=0, r;
|
||||
int sum = 0;
|
||||
int r;
|
||||
|
||||
for(auto & elem : available)
|
||||
{
|
||||
@@ -364,7 +374,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor pl
|
||||
sum += elem.second->type->heroClass->selectionProbability[town->faction->getIndex()]; //total weight
|
||||
}
|
||||
}
|
||||
if(!pool.size() || sum == 0)
|
||||
if(pool.empty() || sum == 0)
|
||||
{
|
||||
logGlobal->error("There are no heroes available for player %s!", player.getStr());
|
||||
return nullptr;
|
||||
@@ -400,12 +410,14 @@ void CGameState::CrossoverHeroesList::removeHeroFromBothLists(CGHeroInstance * h
|
||||
heroesFromAnyPreviousScenarios -= hero;
|
||||
}
|
||||
|
||||
CGameState::CampaignHeroReplacement::CampaignHeroReplacement(CGHeroInstance * hero, ObjectInstanceID heroPlaceholderId) : hero(hero), heroPlaceholderId(heroPlaceholderId)
|
||||
CGameState::CampaignHeroReplacement::CampaignHeroReplacement(CGHeroInstance * hero, const ObjectInstanceID & heroPlaceholderId):
|
||||
hero(hero),
|
||||
heroPlaceholderId(heroPlaceholderId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CGameState::pickNextHeroType(PlayerColor owner)
|
||||
int CGameState::pickNextHeroType(const PlayerColor & owner)
|
||||
{
|
||||
const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(owner);
|
||||
if(ps.hero >= 0 && !isUsedHero(HeroTypeID(ps.hero))) //we haven't used selected hero
|
||||
@@ -416,13 +428,14 @@ int CGameState::pickNextHeroType(PlayerColor owner)
|
||||
return pickUnusedHeroTypeRandomly(owner);
|
||||
}
|
||||
|
||||
int CGameState::pickUnusedHeroTypeRandomly(PlayerColor owner)
|
||||
int CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
|
||||
{
|
||||
//list of available heroes for this faction and others
|
||||
std::vector<HeroTypeID> factionHeroes, otherHeroes;
|
||||
std::vector<HeroTypeID> factionHeroes;
|
||||
std::vector<HeroTypeID> otherHeroes;
|
||||
|
||||
const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(owner);
|
||||
for(HeroTypeID hid : getUnusedAllowedHeroes())
|
||||
for(const HeroTypeID & hid : getUnusedAllowedHeroes())
|
||||
{
|
||||
if(VLC->heroh->objects[hid.getNum()]->heroClass->faction == ps.castle)
|
||||
factionHeroes.push_back(hid);
|
||||
@@ -444,7 +457,7 @@ int CGameState::pickUnusedHeroTypeRandomly(PlayerColor owner)
|
||||
|
||||
logGlobal->error("No free allowed heroes!");
|
||||
auto notAllowedHeroesButStillBetterThanCrash = getUnusedAllowedHeroes(true);
|
||||
if(notAllowedHeroesButStillBetterThanCrash.size())
|
||||
if(!notAllowedHeroesButStillBetterThanCrash.empty())
|
||||
return notAllowedHeroesButStillBetterThanCrash.begin()->getNum();
|
||||
|
||||
logGlobal->error("No free heroes at all!");
|
||||
@@ -482,9 +495,9 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
return std::make_pair(Obj::RESOURCE,getRandomGenerator().nextInt(6)); //now it's OH3 style, use %8 for mithril
|
||||
case Obj::RANDOM_TOWN:
|
||||
{
|
||||
PlayerColor align = PlayerColor((static_cast<CGTownInstance*>(obj))->alignment);
|
||||
PlayerColor align = PlayerColor((dynamic_cast<CGTownInstance *>(obj))->alignment);
|
||||
si32 f; // can be negative (for random)
|
||||
if(align >= PlayerColor::PLAYER_LIMIT)//same as owner / random
|
||||
if(align >= PlayerColor::PLAYER_LIMIT) //same as owner / random
|
||||
{
|
||||
if(obj->tempOwner >= PlayerColor::PLAYER_LIMIT)
|
||||
f = -1; //random
|
||||
@@ -515,11 +528,11 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
case Obj::RANDOM_DWELLING_LVL:
|
||||
case Obj::RANDOM_DWELLING_FACTION:
|
||||
{
|
||||
CGDwelling * dwl = static_cast<CGDwelling*>(obj);
|
||||
auto * dwl = dynamic_cast<CGDwelling *>(obj);
|
||||
int faction;
|
||||
|
||||
//if castle alignment available
|
||||
if (auto info = dynamic_cast<CCreGenAsCastleInfo*>(dwl->info))
|
||||
if(auto * info = dynamic_cast<CCreGenAsCastleInfo *>(dwl->info))
|
||||
{
|
||||
faction = getRandomGenerator().nextInt((int)VLC->townh->size() - 1);
|
||||
if(info->asCastle && !info->instanceId.empty())
|
||||
@@ -585,7 +598,7 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
int level;
|
||||
|
||||
//if level set to range
|
||||
if (auto info = dynamic_cast<CCreGenLeveledInfo*>(dwl->info))
|
||||
if(auto * info = dynamic_cast<CCreGenLeveledInfo *>(dwl->info))
|
||||
{
|
||||
level = getRandomGenerator().nextInt(info->minLevel, info->maxLevel);
|
||||
}
|
||||
@@ -602,12 +615,12 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
|
||||
//NOTE: this will pick last dwelling with this creature (Mantis #900)
|
||||
//check for block map equality is better but more complex solution
|
||||
auto testID = [&](Obj primaryID) -> void
|
||||
auto testID = [&](const Obj & primaryID) -> void
|
||||
{
|
||||
auto dwellingIDs = VLC->objtypeh->knownSubObjects(primaryID);
|
||||
for (si32 entry : dwellingIDs)
|
||||
{
|
||||
auto handler = dynamic_cast<const CDwellingInstanceConstructor*>(VLC->objtypeh->getHandlerFor(primaryID, entry).get());
|
||||
const auto * handler = dynamic_cast<const CDwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(primaryID, entry).get());
|
||||
|
||||
if (handler->producesCreature(VLC->creh->objects[cid]))
|
||||
result = std::make_pair(primaryID, entry);
|
||||
@@ -640,15 +653,15 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
|
||||
}
|
||||
else if(ran.first==Obj::HERO)//special code for hero
|
||||
{
|
||||
CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
|
||||
auto * h = dynamic_cast<CGHeroInstance *>(cur);
|
||||
cur->setType(ran.first, ran.second);
|
||||
map->heroesOnMap.push_back(h);
|
||||
map->heroesOnMap.emplace_back(h);
|
||||
}
|
||||
else if(ran.first==Obj::TOWN)//special code for town
|
||||
{
|
||||
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
|
||||
auto * t = dynamic_cast<CGTownInstance *>(cur);
|
||||
cur->setType(ran.first, ran.second);
|
||||
map->towns.push_back(t);
|
||||
map->towns.emplace_back(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -692,8 +705,6 @@ CGameState::CGameState()
|
||||
//objCaller = new CObjectCallersHandler();
|
||||
globalEffects.setDescription("Global effects");
|
||||
globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS);
|
||||
day = 0;
|
||||
services = nullptr;
|
||||
}
|
||||
|
||||
CGameState::~CGameState()
|
||||
@@ -974,7 +985,7 @@ void CGameState::initGrailPosition()
|
||||
&& t.terType->isLand()
|
||||
&& t.terType->isPassable()
|
||||
&& (int)map->grailPos.dist2dSQ(int3(x, y, z)) <= (map->grailRadius * map->grailRadius))
|
||||
allowedPos.push_back(int3(x,y,z));
|
||||
allowedPos.emplace_back(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1091,7 +1102,7 @@ void CGameState::placeCampaignHeroes()
|
||||
|
||||
for(auto & campaignHeroReplacement : campaignHeroReplacements)
|
||||
{
|
||||
auto hero = getUsedHero(HeroTypeID(campaignHeroReplacement.hero->subID));
|
||||
auto * hero = getUsedHero(HeroTypeID(campaignHeroReplacement.hero->subID));
|
||||
if(hero)
|
||||
{
|
||||
removedHeroes.push_back(hero);
|
||||
@@ -1105,7 +1116,7 @@ void CGameState::placeCampaignHeroes()
|
||||
replaceHeroesPlaceholders(campaignHeroReplacements);
|
||||
|
||||
// now add removed heroes again with unused type ID
|
||||
for(auto hero : removedHeroes)
|
||||
for(auto * hero : removedHeroes)
|
||||
{
|
||||
si32 heroTypeId = 0;
|
||||
if(hero->ID == Obj::HERO)
|
||||
@@ -1151,7 +1162,7 @@ void CGameState::placeCampaignHeroes()
|
||||
}
|
||||
}
|
||||
|
||||
void CGameState::placeStartingHero(PlayerColor playerColor, HeroTypeID heroTypeId, int3 townPos)
|
||||
void CGameState::placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos)
|
||||
{
|
||||
for(auto town : map->towns)
|
||||
{
|
||||
@@ -1178,7 +1189,7 @@ CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenar
|
||||
std::vector<CGHeroInstance *> heroes;
|
||||
for(auto & node : campaignState->camp->scenarios[bonus->info2].crossoverHeroes)
|
||||
{
|
||||
auto h = CCampaignState::crossoverDeserialize(node);
|
||||
auto * h = CCampaignState::crossoverDeserialize(node);
|
||||
heroes.push_back(h);
|
||||
}
|
||||
crossoverHeroes.heroesFromAnyPreviousScenarios = crossoverHeroes.heroesFromPreviousScenario = heroes;
|
||||
@@ -1199,7 +1210,7 @@ CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenar
|
||||
auto lostCrossoverHeroes = scenario.getLostCrossoverHeroes();
|
||||
|
||||
// remove heroes which didn't reached the end of the scenario, but were available at the start
|
||||
for(auto hero : lostCrossoverHeroes)
|
||||
for(auto * hero : lostCrossoverHeroes)
|
||||
{
|
||||
// auto hero = CCampaignState::crossoverDeserialize(node);
|
||||
vstd::erase_if(crossoverHeroes.heroesFromAnyPreviousScenarios, [hero](CGHeroInstance * h)
|
||||
@@ -1211,7 +1222,7 @@ CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenar
|
||||
// now add heroes which completed the scenario
|
||||
for(auto node : scenario.crossoverHeroes)
|
||||
{
|
||||
auto hero = CCampaignState::crossoverDeserialize(node);
|
||||
auto * hero = CCampaignState::crossoverDeserialize(node);
|
||||
// add new heroes and replace old heroes with newer ones
|
||||
auto it = range::find_if(crossoverHeroes.heroesFromAnyPreviousScenarios, [hero](CGHeroInstance * h)
|
||||
{
|
||||
@@ -1245,6 +1256,7 @@ void CGameState::prepareCrossoverHeroes(std::vector<CGameState::CampaignHeroRepl
|
||||
{
|
||||
// create heroes list for convenience iterating
|
||||
std::vector<CGHeroInstance *> crossoverHeroes;
|
||||
crossoverHeroes.reserve(campaignHeroReplacements.size());
|
||||
for(auto & campaignHeroReplacement : campaignHeroReplacements)
|
||||
{
|
||||
crossoverHeroes.push_back(campaignHeroReplacement.hero);
|
||||
@@ -1405,11 +1417,10 @@ void CGameState::initStartingResources()
|
||||
auto getHumanPlayerInfo = [&]() -> std::vector<const PlayerSettings *>
|
||||
{
|
||||
std::vector<const PlayerSettings *> ret;
|
||||
for(auto it = scenarioOps->playerInfos.cbegin();
|
||||
it != scenarioOps->playerInfos.cend(); ++it)
|
||||
for(const auto & playerInfo : scenarioOps->playerInfos)
|
||||
{
|
||||
if(it->second.isControlledByHuman())
|
||||
ret.push_back(&it->second);
|
||||
if(playerInfo.second.isControlledByHuman())
|
||||
ret.push_back(&playerInfo.second);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1484,9 +1495,9 @@ void CGameState::initHeroes()
|
||||
map->allHeroes[ph->subID] = ph;
|
||||
}
|
||||
|
||||
for(HeroTypeID htype : heroesToCreate) //all not used allowed heroes go with default state into the pool
|
||||
for(const HeroTypeID & htype : heroesToCreate) //all not used allowed heroes go with default state into the pool
|
||||
{
|
||||
auto vhi = new CGHeroInstance();
|
||||
auto * vhi = new CGHeroInstance();
|
||||
vhi->initHero(getRandomGenerator(), htype);
|
||||
|
||||
int typeID = htype.getNum();
|
||||
@@ -1623,7 +1634,7 @@ void CGameState::initFogOfWar()
|
||||
|
||||
std::unordered_set<int3, ShashInt3> tiles;
|
||||
getTilesInRange(tiles, obj->getSightCenter(), obj->getSightRadius(), obj->tempOwner, 1);
|
||||
for(int3 tile : tiles)
|
||||
for(const int3 & tile : tiles)
|
||||
{
|
||||
(*elem.second.fogOfWarMap)[tile.z][tile.x][tile.y] = 1;
|
||||
}
|
||||
@@ -1666,7 +1677,7 @@ void CGameState::initStartingBonus()
|
||||
}
|
||||
case PlayerSettings::ARTIFACT:
|
||||
{
|
||||
if(!elem.second.heroes.size())
|
||||
if(elem.second.heroes.empty())
|
||||
{
|
||||
logGlobal->error("Cannot give starting artifact - no heroes!");
|
||||
break;
|
||||
@@ -1750,8 +1761,10 @@ void CGameState::initTowns()
|
||||
}
|
||||
|
||||
//#1444 - remove entries that don't have buildings defined (like some unused extra town hall buildings)
|
||||
vstd::erase_if(vti->builtBuildings, [vti](BuildingID bid){
|
||||
return !vti->town->buildings.count(bid) || !vti->town->buildings.at(bid); });
|
||||
vstd::erase_if(vti->builtBuildings, [vti](const BuildingID & bid)
|
||||
{
|
||||
return !vti->town->buildings.count(bid) || !vti->town->buildings.at(bid);
|
||||
});
|
||||
|
||||
if (vstd::contains(vti->builtBuildings, BuildingID::SHIPYARD) && vti->shipyardStatus()==IBoatGenerator::TILE_BLOCKED)
|
||||
vti->builtBuildings.erase(BuildingID::SHIPYARD);//if we have harbor without water - erase it (this is H3 behaviour)
|
||||
@@ -1776,7 +1789,7 @@ void CGameState::initTowns()
|
||||
}
|
||||
|
||||
//Early check for #1444-like problems
|
||||
for(auto building : vti->builtBuildings)
|
||||
for(const auto & building : vti->builtBuildings)
|
||||
{
|
||||
assert(vti->town->buildings.at(building) != nullptr);
|
||||
MAYBE_UNUSED(building);
|
||||
@@ -1800,11 +1813,11 @@ void CGameState::initTowns()
|
||||
|
||||
for(ui32 z=0; z<vti->obligatorySpells.size();z++)
|
||||
{
|
||||
auto s = vti->obligatorySpells[z].toSpell();
|
||||
const auto * s = vti->obligatorySpells[z].toSpell();
|
||||
vti->spells[s->level-1].push_back(s->id);
|
||||
vti->possibleSpells -= s->id;
|
||||
}
|
||||
while(vti->possibleSpells.size())
|
||||
while(!vti->possibleSpells.empty())
|
||||
{
|
||||
ui32 total=0;
|
||||
int sel = -1;
|
||||
@@ -1828,14 +1841,13 @@ void CGameState::initTowns()
|
||||
if(sel<0)
|
||||
sel=0;
|
||||
|
||||
auto s = vti->possibleSpells[sel].toSpell();
|
||||
const auto * s = vti->possibleSpells[sel].toSpell();
|
||||
vti->spells[s->level-1].push_back(s->id);
|
||||
vti->possibleSpells -= s->id;
|
||||
}
|
||||
vti->possibleSpells.clear();
|
||||
if(vti->getOwner() != PlayerColor::NEUTRAL)
|
||||
getPlayerState(vti->getOwner())->towns.push_back(vti);
|
||||
|
||||
getPlayerState(vti->getOwner())->towns.emplace_back(vti);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1863,7 +1875,7 @@ void CGameState::initMapObjects()
|
||||
case Obj::QUEST_GUARD:
|
||||
case Obj::SEER_HUT:
|
||||
{
|
||||
auto q = static_cast<CGSeerHut*>(obj);
|
||||
auto * q = dynamic_cast<CGSeerHut *>(obj);
|
||||
assert (q);
|
||||
q->setObjToKill();
|
||||
}
|
||||
@@ -1876,14 +1888,14 @@ void CGameState::initMapObjects()
|
||||
|
||||
void CGameState::placeHeroesInTowns()
|
||||
{
|
||||
for(auto k=players.begin(); k!=players.end(); ++k)
|
||||
for(auto & player : players)
|
||||
{
|
||||
if(k->first==PlayerColor::NEUTRAL)
|
||||
if(player.first == PlayerColor::NEUTRAL)
|
||||
continue;
|
||||
|
||||
for(CGHeroInstance *h : k->second.heroes)
|
||||
for(CGHeroInstance * h : player.second.heroes)
|
||||
{
|
||||
for(CGTownInstance *t : k->second.towns)
|
||||
for(CGTownInstance * t : player.second.towns)
|
||||
{
|
||||
if(h->visitablePos().z != t->visitablePos().z)
|
||||
continue;
|
||||
@@ -1909,15 +1921,15 @@ void CGameState::placeHeroesInTowns()
|
||||
|
||||
void CGameState::initVisitingAndGarrisonedHeroes()
|
||||
{
|
||||
for(auto k=players.begin(); k!=players.end(); ++k)
|
||||
for(auto & player : players)
|
||||
{
|
||||
if(k->first==PlayerColor::NEUTRAL)
|
||||
if(player.first == PlayerColor::NEUTRAL)
|
||||
continue;
|
||||
|
||||
//init visiting and garrisoned heroes
|
||||
for(CGHeroInstance *h : k->second.heroes)
|
||||
for(CGHeroInstance * h : player.second.heroes)
|
||||
{
|
||||
for(CGTownInstance *t : k->second.towns)
|
||||
for(CGTownInstance * t : player.second.towns)
|
||||
{
|
||||
if(h->visitablePos().z != t->visitablePos().z)
|
||||
continue;
|
||||
@@ -1948,7 +1960,7 @@ BattleField CGameState::battleGetBattlefieldType(int3 tile, CRandomGenerator & r
|
||||
|
||||
const TerrainTile &t = map->getTile(tile);
|
||||
|
||||
auto topObject = t.visitableObjects.front();
|
||||
auto * topObject = t.visitableObjects.front();
|
||||
if(topObject && topObject->getBattlefield() != BattleField::NONE)
|
||||
{
|
||||
return topObject->getBattlefield();
|
||||
@@ -1986,11 +1998,11 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance &stack) const
|
||||
UpgradeInfo ret;
|
||||
const CCreature *base = stack.type;
|
||||
|
||||
const CGHeroInstance *h = stack.armyObj->ID == Obj::HERO ? static_cast<const CGHeroInstance*>(stack.armyObj) : nullptr;
|
||||
const CGHeroInstance * h = stack.armyObj->ID == Obj::HERO ? dynamic_cast<const CGHeroInstance *>(stack.armyObj) : nullptr;
|
||||
const CGTownInstance *t = nullptr;
|
||||
|
||||
if(stack.armyObj->ID == Obj::TOWN)
|
||||
t = static_cast<const CGTownInstance *>(stack.armyObj);
|
||||
t = dynamic_cast<const CGTownInstance *>(stack.armyObj);
|
||||
else if(h)
|
||||
{ //hero specialty
|
||||
TConstBonusListPtr lista = h->getBonuses(Selector::typeSubtype(Bonus::SPECIAL_UPGRADE, base->idNumber));
|
||||
@@ -2011,7 +2023,7 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance &stack) const
|
||||
{
|
||||
if (vstd::contains(dwelling.second, base->idNumber)) //Dwelling with our creature
|
||||
{
|
||||
for(auto upgrID : dwelling.second)
|
||||
for(const auto & upgrID : dwelling.second)
|
||||
{
|
||||
if(vstd::contains(base->upgrades, upgrID)) //possible upgrade
|
||||
{
|
||||
@@ -2029,14 +2041,14 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance &stack) const
|
||||
static const int costModifiers[] = {0, 25, 50, 75, 100}; //we get cheaper upgrades depending on level
|
||||
const int costModifier = costModifiers[std::min<int>(std::max((int)base->level - 1, 0), ARRAY_COUNT(costModifiers) - 1)];
|
||||
|
||||
for(auto nid : base->upgrades)
|
||||
for(const auto & nid : base->upgrades)
|
||||
{
|
||||
ret.newID.push_back(nid);
|
||||
ret.cost.push_back((VLC->creh->objects[nid]->cost - base->cost) * costModifier / 100);
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.newID.size())
|
||||
if(!ret.newID.empty())
|
||||
ret.oldID = base->idNumber;
|
||||
|
||||
for (Res::ResourceSet &cost : ret.cost)
|
||||
@@ -2069,7 +2081,7 @@ void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out)
|
||||
calculatePaths(std::make_shared<SingleHeroPathfinderConfig>(out, this, hero));
|
||||
}
|
||||
|
||||
void CGameState::calculatePaths(std::shared_ptr<PathfinderConfig> config)
|
||||
void CGameState::calculatePaths(const std::shared_ptr<PathfinderConfig> & config)
|
||||
{
|
||||
//FIXME: creating pathfinder is costly, maybe reset / clear is enough?
|
||||
CPathfinder pathfinder(this, config);
|
||||
@@ -2144,7 +2156,8 @@ void CGameState::updateRumor()
|
||||
if(map->grailPos.valid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce
|
||||
sRumorTypes.push_back(RumorState::RUMOR_GRAIL);
|
||||
|
||||
int rumorId = -1, rumorExtra = -1;
|
||||
int rumorId = -1;
|
||||
int rumorExtra = -1;
|
||||
auto & rand = getRandomGenerator();
|
||||
rumor.type = *RandomGeneratorUtil::nextItem(rumorTypes, rand);
|
||||
|
||||
@@ -2188,7 +2201,7 @@ void CGameState::updateRumor()
|
||||
}
|
||||
case RumorState::TYPE_MAP:
|
||||
// Makes sure that map rumors only used if there enough rumors too choose from
|
||||
if(map->rumors.size() && (map->rumors.size() > 1 || !rumor.last.count(RumorState::TYPE_MAP)))
|
||||
if(!map->rumors.empty() && (map->rumors.size() > 1 || !rumor.last.count(RumorState::TYPE_MAP)))
|
||||
{
|
||||
rumorId = rand.nextInt((int)map->rumors.size() - 1);
|
||||
break;
|
||||
@@ -2207,7 +2220,7 @@ void CGameState::updateRumor()
|
||||
while(!rumor.update(rumorId, rumorExtra));
|
||||
}
|
||||
|
||||
bool CGameState::isVisible(int3 pos, boost::optional<PlayerColor> player) const
|
||||
bool CGameState::isVisible(int3 pos, const boost::optional<PlayerColor> & player) const
|
||||
{
|
||||
if (!map->isInTheMap(pos))
|
||||
return false;
|
||||
@@ -2221,7 +2234,7 @@ bool CGameState::isVisible(int3 pos, boost::optional<PlayerColor> player) const
|
||||
return (*getPlayerTeam(*player)->fogOfWarMap)[pos.z][pos.x][pos.y];
|
||||
}
|
||||
|
||||
bool CGameState::isVisible( const CGObjectInstance *obj, boost::optional<PlayerColor> player ) const
|
||||
bool CGameState::isVisible( const CGObjectInstance *obj, const boost::optional<PlayerColor> & player) const
|
||||
{
|
||||
if(!player)
|
||||
return true;
|
||||
@@ -2254,7 +2267,7 @@ bool CGameState::checkForVisitableDir(const int3 & src, const int3 & dst) const
|
||||
return map->checkForVisitableDir(src, pom, dst);
|
||||
}
|
||||
|
||||
EVictoryLossCheckResult CGameState::checkForVictoryAndLoss(PlayerColor player) const
|
||||
EVictoryLossCheckResult CGameState::checkForVictoryAndLoss(const PlayerColor & player) const
|
||||
{
|
||||
const std::string & messageWonSelf = VLC->generaltexth->allTexts[659];
|
||||
const std::string & messageWonOther = VLC->generaltexth->allTexts[5];
|
||||
@@ -2294,7 +2307,7 @@ EVictoryLossCheckResult CGameState::checkForVictoryAndLoss(PlayerColor player) c
|
||||
return EVictoryLossCheckResult();
|
||||
}
|
||||
|
||||
bool CGameState::checkForVictory(PlayerColor player, const EventCondition & condition) const
|
||||
bool CGameState::checkForVictory(const PlayerColor & player, const EventCondition & condition) const
|
||||
{
|
||||
const PlayerState *p = CGameInfoCallback::getPlayerState(player);
|
||||
switch (condition.condition)
|
||||
@@ -2305,7 +2318,7 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
}
|
||||
case EventCondition::HAVE_ARTIFACT: //check if any hero has winning artifact
|
||||
{
|
||||
for(auto & elem : p->heroes)
|
||||
for(const auto & elem : p->heroes)
|
||||
if(elem->hasArt(ArtifactID(condition.objectType)))
|
||||
return true;
|
||||
return false;
|
||||
@@ -2314,14 +2327,14 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
{
|
||||
//check if in players armies there is enough creatures
|
||||
int total = 0; //creature counter
|
||||
for(size_t i = 0; i < map->objects.size(); i++)
|
||||
for(auto object : map->objects)
|
||||
{
|
||||
const CArmedInstance *ai = nullptr;
|
||||
if(map->objects[i]
|
||||
&& map->objects[i]->tempOwner == player //object controlled by player
|
||||
&& (ai = dynamic_cast<const CArmedInstance*>(map->objects[i].get()))) //contains army
|
||||
if(object
|
||||
&& object->tempOwner == player //object controlled by player
|
||||
&& (ai = dynamic_cast<const CArmedInstance *>(object.get()))) //contains army
|
||||
{
|
||||
for(auto & elem : ai->Slots()) //iterate through army
|
||||
for(const auto & elem : ai->Slots()) //iterate through army
|
||||
if(elem.second->type->idNumber == condition.objectType) //it's searched creature
|
||||
total += elem.second->count;
|
||||
}
|
||||
@@ -2336,7 +2349,7 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
{
|
||||
if (condition.object) // specific town
|
||||
{
|
||||
const CGTownInstance *t = static_cast<const CGTownInstance *>(condition.object);
|
||||
const auto * t = dynamic_cast<const CGTownInstance *>(condition.object);
|
||||
return (t->tempOwner == player && t->hasBuilt(BuildingID(condition.objectType)));
|
||||
}
|
||||
else // any town
|
||||
@@ -2353,14 +2366,14 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
{
|
||||
if (condition.object) // mode A - destroy specific object of this type
|
||||
{
|
||||
if (auto hero = dynamic_cast<const CGHeroInstance*>(condition.object))
|
||||
if(const auto * hero = dynamic_cast<const CGHeroInstance *>(condition.object))
|
||||
return boost::range::find(gs->map->heroesOnMap, hero) == gs->map->heroesOnMap.end();
|
||||
else
|
||||
return getObj(condition.object->id) == nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto & elem : map->objects) // mode B - destroy all objects of this type
|
||||
for(const auto & elem : map->objects) // mode B - destroy all objects of this type
|
||||
{
|
||||
if(elem && elem->ID == condition.objectType)
|
||||
return false;
|
||||
@@ -2372,7 +2385,7 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
{
|
||||
// list of players that need to control object to fulfull condition
|
||||
// NOTE: cgameinfocallback specified explicitly in order to get const version
|
||||
auto & team = CGameInfoCallback::getPlayerTeam(player)->players;
|
||||
const auto & team = CGameInfoCallback::getPlayerTeam(player)->players;
|
||||
|
||||
if (condition.object) // mode A - flag one specific object, like town
|
||||
{
|
||||
@@ -2380,7 +2393,7 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto & elem : map->objects) // mode B - flag all objects of this type
|
||||
for(const auto & elem : map->objects) // mode B - flag all objects of this type
|
||||
{
|
||||
//check not flagged objs
|
||||
if ( elem && elem->ID == condition.objectType && team.count(elem->tempOwner) == 0 )
|
||||
@@ -2391,13 +2404,9 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
|
||||
}
|
||||
case EventCondition::TRANSPORT:
|
||||
{
|
||||
const CGTownInstance *t = static_cast<const CGTownInstance *>(condition.object);
|
||||
if((t->visitingHero && t->visitingHero->hasArt(ArtifactID(condition.objectType)))
|
||||
|| (t->garrisonHero && t->garrisonHero->hasArt(ArtifactID(condition.objectType))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
const auto * t = dynamic_cast<const CGTownInstance *>(condition.object);
|
||||
return (t->visitingHero && t->visitingHero->hasArt(ArtifactID(condition.objectType))) ||
|
||||
(t->garrisonHero && t->garrisonHero->hasArt(ArtifactID(condition.objectType)));
|
||||
}
|
||||
case EventCondition::DAYS_PASSED:
|
||||
{
|
||||
@@ -2448,7 +2457,7 @@ PlayerColor CGameState::checkForStandardWin() const
|
||||
//all enemies lost
|
||||
PlayerColor supposedWinner = PlayerColor::NEUTRAL;
|
||||
TeamID winnerTeam = TeamID::NO_TEAM;
|
||||
for(auto & elem : players)
|
||||
for(const auto & elem : players)
|
||||
{
|
||||
if(elem.second.status == EPlayerStatus::INGAME && elem.first < PlayerColor::PLAYER_LIMIT)
|
||||
{
|
||||
@@ -2469,7 +2478,7 @@ PlayerColor CGameState::checkForStandardWin() const
|
||||
return supposedWinner;
|
||||
}
|
||||
|
||||
bool CGameState::checkForStandardLoss( PlayerColor player ) const
|
||||
bool CGameState::checkForStandardLoss(const PlayerColor & player) const
|
||||
{
|
||||
//std loss condition is: player lost all towns and heroes
|
||||
const PlayerState & pState = *CGameInfoCallback::getPlayerState(player);
|
||||
@@ -2478,7 +2487,7 @@ bool CGameState::checkForStandardLoss( PlayerColor player ) const
|
||||
|
||||
struct statsHLP
|
||||
{
|
||||
typedef std::pair< PlayerColor, si64 > TStat;
|
||||
using TStat = std::pair<PlayerColor, si64>;
|
||||
//converts [<player's color, value>] to vec[place] -> platers
|
||||
static std::vector< std::vector< PlayerColor > > getRank( std::vector<TStat> stats )
|
||||
{
|
||||
@@ -2514,10 +2523,10 @@ struct statsHLP
|
||||
return a.second > b.second;
|
||||
}
|
||||
|
||||
static const CGHeroInstance * findBestHero(CGameState * gs, PlayerColor color)
|
||||
static const CGHeroInstance * findBestHero(CGameState * gs, const PlayerColor & color)
|
||||
{
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > &h = gs->players[color].heroes;
|
||||
if(!h.size())
|
||||
if(h.empty())
|
||||
return nullptr;
|
||||
//best hero will be that with highest exp
|
||||
int best = 0;
|
||||
@@ -2562,7 +2571,7 @@ struct statsHLP
|
||||
const CGObjectInstance * heroOrTown = nullptr;
|
||||
|
||||
//Heroes can produce gold as well - skill, specialty or arts
|
||||
for(auto & h : ps->heroes)
|
||||
for(const auto & h : ps->heroes)
|
||||
{
|
||||
totalIncome += h->valOfBonuses(Selector::typeSubtype(Bonus::GENERATE_RESOURCE, Res::GOLD));
|
||||
|
||||
@@ -2571,7 +2580,7 @@ struct statsHLP
|
||||
}
|
||||
|
||||
//Add town income of all towns
|
||||
for(auto & t : ps->towns)
|
||||
for(const auto & t : ps->towns)
|
||||
{
|
||||
totalIncome += t->dailyIncome()[Res::GOLD];
|
||||
|
||||
@@ -2590,12 +2599,12 @@ struct statsHLP
|
||||
/// This is code from CPlayerSpecificInfoCallback::getMyObjects
|
||||
/// I'm really need to find out about callback interface design...
|
||||
|
||||
for(auto object : ownedObjects)
|
||||
for(const auto * object : ownedObjects)
|
||||
{
|
||||
//Mines
|
||||
if ( object->ID == Obj::MINE )
|
||||
{
|
||||
const CGMine *mine = dynamic_cast<const CGMine*>(object);
|
||||
const auto * mine = dynamic_cast<const CGMine *>(object);
|
||||
assert(mine);
|
||||
|
||||
if (mine->producedResource == Res::GOLD)
|
||||
@@ -2609,9 +2618,9 @@ struct statsHLP
|
||||
|
||||
void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
{
|
||||
auto playerInactive = [&](PlayerColor color)
|
||||
auto playerInactive = [&](const PlayerColor & color)
|
||||
{
|
||||
return color == PlayerColor::NEUTRAL || players.at(color).status != EPlayerStatus::INGAME;
|
||||
return color == PlayerColor::NEUTRAL || players.at(color).status != EPlayerStatus::INGAME;
|
||||
};
|
||||
|
||||
#define FILL_FIELD(FIELD, VAL_GETTER) \
|
||||
@@ -2644,15 +2653,15 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
}
|
||||
if(level >= 1) //best hero's portrait
|
||||
{
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
for(const auto & player : players)
|
||||
{
|
||||
if(playerInactive(g->second.color))
|
||||
if(playerInactive(player.second.color))
|
||||
continue;
|
||||
const CGHeroInstance * best = statsHLP::findBestHero(this, g->second.color);
|
||||
const CGHeroInstance * best = statsHLP::findBestHero(this, player.second.color);
|
||||
InfoAboutHero iah;
|
||||
iah.initFromHero(best, (level >= 2) ? InfoAboutHero::EInfoLevel::DETAILED : InfoAboutHero::EInfoLevel::BASIC);
|
||||
iah.army.clear();
|
||||
tgi.colorToBestHero[g->second.color] = iah;
|
||||
tgi.colorToBestHero[player.second.color] = iah;
|
||||
}
|
||||
}
|
||||
if(level >= 2) //gold
|
||||
@@ -2669,7 +2678,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
}
|
||||
if(level >= 3) //obelisks found
|
||||
{
|
||||
auto getObeliskVisited = [](TeamID t)
|
||||
auto getObeliskVisited = [](const TeamID & t)
|
||||
{
|
||||
if(CGObelisk::visited.count(t))
|
||||
return CGObelisk::visited[t];
|
||||
@@ -2697,17 +2706,17 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
}
|
||||
if(level >= 3) //personality
|
||||
{
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
for(const auto & player : players)
|
||||
{
|
||||
if(playerInactive(g->second.color)) //do nothing for neutral player
|
||||
if(playerInactive(player.second.color)) //do nothing for neutral player
|
||||
continue;
|
||||
if(g->second.human)
|
||||
if(player.second.human)
|
||||
{
|
||||
tgi.personality[g->second.color] = EAiTactic::NONE;
|
||||
tgi.personality[player.second.color] = EAiTactic::NONE;
|
||||
}
|
||||
else //AI
|
||||
{
|
||||
tgi.personality[g->second.color] = map->players[g->second.color.getNum()].aiTactic;
|
||||
tgi.personality[player.second.color] = map->players[player.second.color.getNum()].aiTactic;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2715,23 +2724,23 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
if(level >= 4) //best creature
|
||||
{
|
||||
//best creatures belonging to player (highest AI value)
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
for(const auto & player : players)
|
||||
{
|
||||
if(playerInactive(g->second.color)) //do nothing for neutral player
|
||||
if(playerInactive(player.second.color)) //do nothing for neutral player
|
||||
continue;
|
||||
int bestCre = -1; //best creature's ID
|
||||
for(auto & elem : g->second.heroes)
|
||||
for(const auto & elem : player.second.heroes)
|
||||
{
|
||||
for(auto it = elem->Slots().begin(); it != elem->Slots().end(); ++it)
|
||||
for(const auto & it : elem->Slots())
|
||||
{
|
||||
int toCmp = it->second->type->idNumber; //ID of creature we should compare with the best one
|
||||
int toCmp = it.second->type->idNumber; //ID of creature we should compare with the best one
|
||||
if(bestCre == -1 || VLC->creh->objects[bestCre]->AIValue < VLC->creh->objects[toCmp]->AIValue)
|
||||
{
|
||||
bestCre = toCmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
tgi.bestCreature[g->second.color] = bestCre;
|
||||
tgi.bestCreature[player.second.color] = bestCre;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2741,10 +2750,10 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > CGameState::unusedHeroesFromPool()
|
||||
{
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > pool = hpool.heroesPool;
|
||||
for ( auto i = players.cbegin() ; i != players.cend();i++)
|
||||
for(auto j = i->second.availableHeroes.cbegin(); j != i->second.availableHeroes.cend(); j++)
|
||||
if(*j)
|
||||
pool.erase((**j).subID);
|
||||
for(const auto & player : players)
|
||||
for(auto availableHero : player.second.availableHeroes)
|
||||
if(availableHero)
|
||||
pool.erase((*availableHero).subID);
|
||||
|
||||
return pool;
|
||||
}
|
||||
@@ -2770,12 +2779,12 @@ void CGameState::deserializationFix()
|
||||
|
||||
void CGameState::buildGlobalTeamPlayerTree()
|
||||
{
|
||||
for(auto k=teams.begin(); k!=teams.end(); ++k)
|
||||
for(auto & team : teams)
|
||||
{
|
||||
TeamState *t = &k->second;
|
||||
TeamState * t = &team.second;
|
||||
t->attachTo(globalEffects);
|
||||
|
||||
for(PlayerColor teamMember : k->second.players)
|
||||
for(const PlayerColor & teamMember : team.second.players)
|
||||
{
|
||||
PlayerState *p = getPlayerState(teamMember);
|
||||
assert(p);
|
||||
@@ -2788,14 +2797,14 @@ void CGameState::attachArmedObjects()
|
||||
{
|
||||
for(CGObjectInstance *obj : map->objects)
|
||||
{
|
||||
if(CArmedInstance *armed = dynamic_cast<CArmedInstance*>(obj))
|
||||
if(auto * armed = dynamic_cast<CArmedInstance *>(obj))
|
||||
{
|
||||
armed->whatShouldBeAttached().attachTo(armed->whereShouldBeAttached(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGameState::giveHeroArtifact(CGHeroInstance *h, ArtifactID aid)
|
||||
void CGameState::giveHeroArtifact(CGHeroInstance * h, const ArtifactID & aid)
|
||||
{
|
||||
CArtifact * const artifact = VLC->arth->objects[aid]; //pointer to constant object
|
||||
CArtifactInstance *ai = CArtifactInstance::createNewArtifactInstance(artifact);
|
||||
@@ -2810,7 +2819,7 @@ std::set<HeroTypeID> CGameState::getUnusedAllowedHeroes(bool alsoIncludeNotAllow
|
||||
if(map->allowedHeroes[i] || alsoIncludeNotAllowed)
|
||||
ret.insert(HeroTypeID(i));
|
||||
|
||||
for(auto & playerSettingPair : scenarioOps->playerInfos) //remove uninitialized yet heroes picked for start by other players
|
||||
for(const auto & playerSettingPair : scenarioOps->playerInfos) //remove uninitialized yet heroes picked for start by other players
|
||||
{
|
||||
if(playerSettingPair.second.hero != PlayerSettings::RANDOM)
|
||||
ret -= HeroTypeID(playerSettingPair.second.hero);
|
||||
@@ -2840,7 +2849,7 @@ std::vector<CGameState::CampaignHeroReplacement> CGameState::generateCampaignHer
|
||||
{
|
||||
if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
|
||||
{
|
||||
auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
|
||||
auto * heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
|
||||
if(heroPlaceholder->subID != 0xFF) //select by type
|
||||
{
|
||||
auto it = range::find_if(crossoverHeroes.heroesFromAnyPreviousScenarios, [heroPlaceholder](CGHeroInstance * hero)
|
||||
@@ -2850,9 +2859,9 @@ std::vector<CGameState::CampaignHeroReplacement> CGameState::generateCampaignHer
|
||||
|
||||
if(it != crossoverHeroes.heroesFromAnyPreviousScenarios.end())
|
||||
{
|
||||
auto hero = *it;
|
||||
auto * hero = *it;
|
||||
crossoverHeroes.removeHeroFromBothLists(hero);
|
||||
campaignHeroReplacements.push_back(CampaignHeroReplacement(CMemorySerializer::deepCopy(*hero).release(), heroPlaceholder->id));
|
||||
campaignHeroReplacements.emplace_back(CMemorySerializer::deepCopy(*hero).release(), heroPlaceholder->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2870,7 +2879,7 @@ std::vector<CGameState::CampaignHeroReplacement> CGameState::generateCampaignHer
|
||||
{
|
||||
if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
|
||||
{
|
||||
auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
|
||||
auto * heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
|
||||
if(heroPlaceholder->subID == 0xFF) //select by power
|
||||
{
|
||||
heroPlaceholders.push_back(heroPlaceholder);
|
||||
@@ -2884,11 +2893,11 @@ std::vector<CGameState::CampaignHeroReplacement> CGameState::generateCampaignHer
|
||||
|
||||
for(int i = 0; i < heroPlaceholders.size(); ++i)
|
||||
{
|
||||
auto heroPlaceholder = heroPlaceholders[i];
|
||||
auto * heroPlaceholder = heroPlaceholders[i];
|
||||
if(crossoverHeroes.heroesFromPreviousScenario.size() > i)
|
||||
{
|
||||
auto hero = crossoverHeroes.heroesFromPreviousScenario[i];
|
||||
campaignHeroReplacements.push_back(CampaignHeroReplacement(CMemorySerializer::deepCopy(*hero).release(), heroPlaceholder->id));
|
||||
auto * hero = crossoverHeroes.heroesFromPreviousScenario[i];
|
||||
campaignHeroReplacements.emplace_back(CMemorySerializer::deepCopy(*hero).release(), heroPlaceholder->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2897,9 +2906,9 @@ std::vector<CGameState::CampaignHeroReplacement> CGameState::generateCampaignHer
|
||||
|
||||
void CGameState::replaceHeroesPlaceholders(const std::vector<CGameState::CampaignHeroReplacement> & campaignHeroReplacements)
|
||||
{
|
||||
for(auto campaignHeroReplacement : campaignHeroReplacements)
|
||||
for(const auto & campaignHeroReplacement : campaignHeroReplacements)
|
||||
{
|
||||
auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder*>(getObjInstance(campaignHeroReplacement.heroPlaceholderId));
|
||||
auto * heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(getObjInstance(campaignHeroReplacement.heroPlaceholderId));
|
||||
|
||||
CGHeroInstance *heroToPlace = campaignHeroReplacement.hero;
|
||||
heroToPlace->id = campaignHeroReplacement.heroPlaceholderId;
|
||||
@@ -2915,7 +2924,7 @@ void CGameState::replaceHeroesPlaceholders(const std::vector<CGameState::Campaig
|
||||
auto fixArtifact = [&](CArtifactInstance * art)
|
||||
{
|
||||
art->artType = VLC->arth->objects[art->artType->getId()];
|
||||
gs->map->artInstances.push_back(art);
|
||||
gs->map->artInstances.emplace_back(art);
|
||||
art->id = ArtifactInstanceID((si32)gs->map->artInstances.size() - 1);
|
||||
};
|
||||
|
||||
@@ -2928,7 +2937,7 @@ void CGameState::replaceHeroesPlaceholders(const std::vector<CGameState::Campaig
|
||||
map->objects[heroPlaceholder->id.getNum()] = nullptr;
|
||||
map->instanceNames.erase(heroPlaceholder->instanceName);
|
||||
|
||||
map->heroesOnMap.push_back(heroToPlace);
|
||||
map->heroesOnMap.emplace_back(heroToPlace);
|
||||
map->objects[heroToPlace->id.getNum()] = heroToPlace;
|
||||
map->addBlockVisTiles(heroToPlace);
|
||||
map->instanceNames[heroToPlace->instanceName] = heroToPlace;
|
||||
@@ -2939,12 +2948,12 @@ void CGameState::replaceHeroesPlaceholders(const std::vector<CGameState::Campaig
|
||||
}
|
||||
}
|
||||
|
||||
bool CGameState::isUsedHero(HeroTypeID hid) const
|
||||
bool CGameState::isUsedHero(const HeroTypeID & hid) const
|
||||
{
|
||||
return getUsedHero(hid);
|
||||
}
|
||||
|
||||
CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
|
||||
CGHeroInstance * CGameState::getUsedHero(const HeroTypeID & hid) const
|
||||
{
|
||||
for(auto hero : map->heroesOnMap) //heroes instances initialization
|
||||
{
|
||||
@@ -2958,7 +2967,7 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
|
||||
{
|
||||
if(obj && obj->ID == Obj::PRISON )
|
||||
{
|
||||
auto hero = dynamic_cast<CGHeroInstance *>(obj.get());
|
||||
auto * hero = dynamic_cast<CGHeroInstance *>(obj.get());
|
||||
assert(hero);
|
||||
if ( hero->type && hero->type->getId() == hid )
|
||||
return hero;
|
||||
@@ -3012,21 +3021,14 @@ void InfoAboutHero::assign(const InfoAboutHero & iah)
|
||||
portrait = iah.portrait;
|
||||
}
|
||||
|
||||
InfoAboutHero::InfoAboutHero():
|
||||
details(nullptr),
|
||||
hclass(nullptr),
|
||||
portrait(-1)
|
||||
{}
|
||||
InfoAboutHero::InfoAboutHero(): portrait(-1) {}
|
||||
|
||||
InfoAboutHero::InfoAboutHero(const InfoAboutHero & iah):
|
||||
InfoAboutArmy()
|
||||
InfoAboutHero::InfoAboutHero(const InfoAboutHero & iah): InfoAboutArmy(iah)
|
||||
{
|
||||
assign(iah);
|
||||
}
|
||||
|
||||
InfoAboutHero::InfoAboutHero(const CGHeroInstance *h, InfoAboutHero::EInfoLevel infoLevel)
|
||||
: details(nullptr),
|
||||
hclass(nullptr),
|
||||
InfoAboutHero::InfoAboutHero(const CGHeroInstance * h, InfoAboutHero::EInfoLevel infoLevel):
|
||||
portrait(-1)
|
||||
{
|
||||
initFromHero(h, infoLevel);
|
||||
@@ -3126,7 +3128,7 @@ void InfoAboutTown::initFromTown(const CGTownInstance *t, bool detailed)
|
||||
ArmyDescriptor::ArmyDescriptor(const CArmedInstance *army, bool detailed)
|
||||
: isDetailed(detailed)
|
||||
{
|
||||
for(auto & elem : army->Slots())
|
||||
for(const auto & elem : army->Slots())
|
||||
{
|
||||
if(detailed)
|
||||
(*this)[elem.first] = *elem.second;
|
||||
@@ -3146,12 +3148,12 @@ int ArmyDescriptor::getStrength() const
|
||||
ui64 ret = 0;
|
||||
if(isDetailed)
|
||||
{
|
||||
for(auto & elem : *this)
|
||||
for(const auto & elem : *this)
|
||||
ret += elem.second.type->AIValue * elem.second.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto & elem : *this)
|
||||
for(const auto & elem : *this)
|
||||
ret += elem.second.type->AIValue * CCreature::estimateCreatureCount(elem.second.count);
|
||||
}
|
||||
return static_cast<int>(ret);
|
||||
@@ -3163,7 +3165,7 @@ TeamState::TeamState()
|
||||
fogOfWarMap = std::make_shared<boost::multi_array<ui8, 3>>();
|
||||
}
|
||||
|
||||
TeamState::TeamState(TeamState && other):
|
||||
TeamState::TeamState(TeamState && other) noexcept:
|
||||
CBonusSystemNode(std::move(other)),
|
||||
id(other.id)
|
||||
{
|
||||
|
@@ -142,8 +142,12 @@ public:
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; nullptr if not available
|
||||
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
|
||||
|
||||
CGHeroInstance * pickHeroFor(bool native, PlayerColor player, const CTown *town,
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > &available, CRandomGenerator & rand, const CHeroClass *bannedClass = nullptr) const;
|
||||
CGHeroInstance * pickHeroFor(bool native,
|
||||
const PlayerColor & player,
|
||||
const CTown * town,
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance>> & available,
|
||||
CRandomGenerator & rand,
|
||||
const CHeroClass * bannedClass = nullptr) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@@ -174,7 +178,7 @@ public:
|
||||
|
||||
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
|
||||
|
||||
void giveHeroArtifact(CGHeroInstance *h, ArtifactID aid);
|
||||
void giveHeroArtifact(CGHeroInstance * h, const ArtifactID & aid);
|
||||
|
||||
void apply(CPack *pack);
|
||||
BattleField battleGetBattlefieldType(int3 tile, CRandomGenerator & rand);
|
||||
@@ -183,24 +187,24 @@ public:
|
||||
PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override;
|
||||
bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile
|
||||
void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out) override; //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists
|
||||
void calculatePaths(std::shared_ptr<PathfinderConfig> config) override;
|
||||
void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) override;
|
||||
int3 guardingCreaturePosition (int3 pos) const override;
|
||||
std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
|
||||
void updateRumor();
|
||||
|
||||
// ----- victory, loss condition checks -----
|
||||
|
||||
EVictoryLossCheckResult checkForVictoryAndLoss(PlayerColor player) const;
|
||||
bool checkForVictory(PlayerColor player, const EventCondition & condition) const; //checks if given player is winner
|
||||
EVictoryLossCheckResult checkForVictoryAndLoss(const PlayerColor & player) const;
|
||||
bool checkForVictory(const PlayerColor & player, const EventCondition & condition) const; //checks if given player is winner
|
||||
PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner
|
||||
bool checkForStandardLoss(PlayerColor player) const; //checks if given player lost the game
|
||||
bool checkForStandardLoss(const PlayerColor & player) const; //checks if given player lost the game
|
||||
|
||||
void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
|
||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
|
||||
|
||||
|
||||
bool isVisible(int3 pos, boost::optional<PlayerColor> player) const override;
|
||||
bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> player) const override;
|
||||
bool isVisible(int3 pos, const boost::optional<PlayerColor> & player) const override;
|
||||
bool isVisible(const CGObjectInstance *obj, const boost::optional<PlayerColor> & player) const override;
|
||||
|
||||
int getDate(Date::EDateType mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
|
||||
@@ -242,7 +246,7 @@ private:
|
||||
|
||||
struct CampaignHeroReplacement
|
||||
{
|
||||
CampaignHeroReplacement(CGHeroInstance * hero, ObjectInstanceID heroPlaceholderId);
|
||||
CampaignHeroReplacement(CGHeroInstance * hero, const ObjectInstanceID & heroPlaceholderId);
|
||||
CGHeroInstance * hero;
|
||||
ObjectInstanceID heroPlaceholderId;
|
||||
};
|
||||
@@ -269,7 +273,7 @@ private:
|
||||
|
||||
void replaceHeroesPlaceholders(const std::vector<CampaignHeroReplacement> & campaignHeroReplacements);
|
||||
void placeStartingHeroes();
|
||||
void placeStartingHero(PlayerColor playerColor, HeroTypeID heroTypeId, int3 townPos);
|
||||
void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos);
|
||||
void initStartingResources();
|
||||
void initHeroes();
|
||||
void placeHeroesInTowns();
|
||||
@@ -289,12 +293,12 @@ private:
|
||||
|
||||
// ---- misc helpers -----
|
||||
|
||||
CGHeroInstance * getUsedHero(HeroTypeID hid) const;
|
||||
bool isUsedHero(HeroTypeID hid) const; //looks in heroes and prisons
|
||||
CGHeroInstance * getUsedHero(const HeroTypeID & hid) const;
|
||||
bool isUsedHero(const HeroTypeID & hid) const; //looks in heroes and prisons
|
||||
std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
|
||||
std::pair<Obj,int> pickObject(CGObjectInstance *obj); //chooses type of object to be randomized, returns <type, subtype>
|
||||
int pickUnusedHeroTypeRandomly(PlayerColor owner); // picks a unused hero type randomly
|
||||
int pickNextHeroType(PlayerColor owner); // picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly
|
||||
int pickUnusedHeroTypeRandomly(const PlayerColor & owner); // picks a unused hero type randomly
|
||||
int pickNextHeroType(const PlayerColor & owner); // picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly
|
||||
UpgradeInfo fillUpgradeInfo(const CStackInstance &stack) const;
|
||||
|
||||
// ---- data -----
|
||||
|
@@ -233,7 +233,7 @@ bool CLegacyConfigParser::endLine()
|
||||
return curr < end;
|
||||
}
|
||||
|
||||
void CGeneralTextHandler::readToVector(std::string const & sourceID, std::string const & sourceName)
|
||||
void CGeneralTextHandler::readToVector(const std::string & sourceID, const std::string & sourceName)
|
||||
{
|
||||
CLegacyConfigParser parser(sourceName);
|
||||
size_t index = 0;
|
||||
@@ -357,7 +357,7 @@ bool CGeneralTextHandler::validateTranslation(const std::string & language, cons
|
||||
|
||||
void CGeneralTextHandler::loadTranslationOverrides(const std::string & language, const std::string & modContext, const JsonNode & config)
|
||||
{
|
||||
for ( auto const & node : config.Struct())
|
||||
for(const auto & node : config.Struct())
|
||||
registerStringOverride(modContext, language, node.first, node.second.String());
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ CGeneralTextHandler::CGeneralTextHandler():
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CGeneralTextHandler::pluralText(int32_t textIndex, int32_t count) const
|
||||
int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t count) const
|
||||
{
|
||||
if(textIndex == 0)
|
||||
return 0;
|
||||
@@ -577,7 +577,7 @@ int32_t CGeneralTextHandler::pluralText(int32_t textIndex, int32_t count) const
|
||||
void CGeneralTextHandler::dumpAllTexts()
|
||||
{
|
||||
logGlobal->info("BEGIN TEXT EXPORT");
|
||||
for ( auto const & entry : stringsLocalizations)
|
||||
for(const auto & entry : stringsLocalizations)
|
||||
{
|
||||
if (!entry.second.overrideValue.empty())
|
||||
logGlobal->info(R"("%s" : "%s",)", entry.first, TextOperations::escapeString(entry.second.overrideValue));
|
||||
@@ -622,11 +622,11 @@ std::string CGeneralTextHandler::getInstalledEncoding()
|
||||
return settings["session"]["encoding"].String();
|
||||
}
|
||||
|
||||
std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(std::string const & prefix)
|
||||
std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(const std::string & prefix)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
for (auto const & entry : stringsLocalizations)
|
||||
for(const auto & entry : stringsLocalizations)
|
||||
{
|
||||
if(boost::algorithm::starts_with(entry.first, prefix))
|
||||
result.push_back(entry.first);
|
||||
@@ -635,9 +635,9 @@ std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(std::string
|
||||
return result;
|
||||
}
|
||||
|
||||
LegacyTextContainer::LegacyTextContainer(CGeneralTextHandler & owner, std::string const & basePath):
|
||||
LegacyTextContainer::LegacyTextContainer(CGeneralTextHandler & owner, std::string basePath):
|
||||
owner(owner),
|
||||
basePath(basePath)
|
||||
basePath(std::move(basePath))
|
||||
{}
|
||||
|
||||
std::string LegacyTextContainer::operator[](size_t index) const
|
||||
@@ -645,9 +645,9 @@ std::string LegacyTextContainer::operator[](size_t index) const
|
||||
return owner.translate(basePath, index);
|
||||
}
|
||||
|
||||
LegacyHelpContainer::LegacyHelpContainer(CGeneralTextHandler & owner, std::string const & basePath):
|
||||
LegacyHelpContainer::LegacyHelpContainer(CGeneralTextHandler & owner, std::string basePath):
|
||||
owner(owner),
|
||||
basePath(basePath)
|
||||
basePath(std::move(basePath))
|
||||
{}
|
||||
|
||||
std::pair<std::string, std::string> LegacyHelpContainer::operator[](size_t index) const
|
||||
|
@@ -68,7 +68,7 @@ class DLL_LINKAGE LegacyTextContainer
|
||||
std::string basePath;
|
||||
|
||||
public:
|
||||
LegacyTextContainer(CGeneralTextHandler & owner, std::string const & basePath);
|
||||
LegacyTextContainer(CGeneralTextHandler & owner, std::string basePath);
|
||||
std::string operator [](size_t index) const;
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ class DLL_LINKAGE LegacyHelpContainer
|
||||
std::string basePath;
|
||||
|
||||
public:
|
||||
LegacyHelpContainer(CGeneralTextHandler & owner, std::string const & basePath);
|
||||
LegacyHelpContainer(CGeneralTextHandler & owner, std::string basePath);
|
||||
std::pair<std::string, std::string> operator[](size_t index) const;
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ class TextIdentifier
|
||||
{
|
||||
std::string identifier;
|
||||
public:
|
||||
std::string const & get() const
|
||||
const std::string & get() const
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
@@ -96,18 +96,18 @@ public:
|
||||
identifier(id)
|
||||
{}
|
||||
|
||||
TextIdentifier(std::string const & id):
|
||||
identifier(id)
|
||||
TextIdentifier(const std::string & id):
|
||||
identifier(id)
|
||||
{}
|
||||
|
||||
template<typename ... T>
|
||||
TextIdentifier(std::string const & id, size_t index, T ... rest):
|
||||
TextIdentifier(id + '.' + std::to_string(index), rest ... )
|
||||
template<typename... T>
|
||||
TextIdentifier(const std::string & id, size_t index, T... rest):
|
||||
TextIdentifier(id + '.' + std::to_string(index), rest...)
|
||||
{}
|
||||
|
||||
template<typename ... T>
|
||||
TextIdentifier(std::string const & id, std::string const & id2, T ... rest):
|
||||
TextIdentifier(id + '.' + id2, rest ... )
|
||||
template<typename... T>
|
||||
TextIdentifier(const std::string & id, const std::string & id2, T... rest):
|
||||
TextIdentifier(id + '.' + id2, rest...)
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
//commanders
|
||||
LegacyTextContainer znpc00; //more or less useful content of that file
|
||||
|
||||
std::vector<std::string> findStringsWithPrefix(std::string const & prefix);
|
||||
std::vector<std::string> findStringsWithPrefix(const std::string & prefix);
|
||||
|
||||
int32_t pluralText(int32_t textIndex, int32_t count) const;
|
||||
|
||||
|
@@ -21,8 +21,6 @@
|
||||
#include "CTownHandler.h"
|
||||
#include "mapObjects/CObjectHandler.h" //for hero specialty
|
||||
#include "CSkillHandler.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "mapObjects/CObjectClassesHandler.h"
|
||||
#include "BattleFieldHandler.h"
|
||||
|
||||
@@ -123,14 +121,14 @@ void CHero::serializeJson(JsonSerializeFormat & handler)
|
||||
SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const //picks secondary skill out from given possibilities
|
||||
{
|
||||
int totalProb = 0;
|
||||
for(auto & possible : possibles)
|
||||
for(const auto & possible : possibles)
|
||||
{
|
||||
totalProb += secSkillProbability[possible];
|
||||
}
|
||||
if (totalProb != 0) // may trigger if set contains only banned skills (0 probability)
|
||||
{
|
||||
auto ran = rand.nextInt(totalProb - 1);
|
||||
for(auto & possible : possibles)
|
||||
for(const auto & possible : possibles)
|
||||
{
|
||||
ran -= secSkillProbability[possible];
|
||||
if(ran < 0)
|
||||
@@ -150,7 +148,7 @@ bool CHeroClass::isMagicHero() const
|
||||
|
||||
EAlignment::EAlignment CHeroClass::getAlignment() const
|
||||
{
|
||||
return EAlignment::EAlignment((*VLC->townh)[faction]->alignment);
|
||||
return ((*VLC->townh)[faction]->alignment);
|
||||
}
|
||||
|
||||
int32_t CHeroClass::getIndex() const
|
||||
@@ -198,16 +196,18 @@ void CHeroClass::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
}
|
||||
|
||||
|
||||
CHeroClass::CHeroClass()
|
||||
: faction(0), id(), affinity(0), defaultTavernChance(0), commander(nullptr)
|
||||
CHeroClass::CHeroClass():
|
||||
faction(0),
|
||||
affinity(0),
|
||||
defaultTavernChance(0),
|
||||
commander(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill::PrimarySkill pSkill)
|
||||
void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill::PrimarySkill pSkill) const
|
||||
{
|
||||
const auto & skillName = PrimarySkill::names[pSkill];
|
||||
auto currentPrimarySkillValue = (int)node["primarySkills"][skillName].Integer();
|
||||
auto currentPrimarySkillValue = static_cast<int>(node["primarySkills"][skillName].Integer());
|
||||
//minimal value is 0 for attack and defense and 1 for spell power and knowledge
|
||||
auto primarySkillLegalMinimum = (pSkill == PrimarySkill::ATTACK || pSkill == PrimarySkill::DEFENSE) ? 0 : 1;
|
||||
|
||||
@@ -218,8 +218,8 @@ void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass *
|
||||
currentPrimarySkillValue = primarySkillLegalMinimum;
|
||||
}
|
||||
heroClass->primarySkillInitial.push_back(currentPrimarySkillValue);
|
||||
heroClass->primarySkillLowLevel.push_back((int)node["lowLevelChance"][skillName].Float());
|
||||
heroClass->primarySkillHighLevel.push_back((int)node["highLevelChance"][skillName].Float());
|
||||
heroClass->primarySkillLowLevel.push_back(static_cast<int>(node["lowLevelChance"][skillName].Float()));
|
||||
heroClass->primarySkillHighLevel.push_back(static_cast<int>(node["highLevelChance"][skillName].Float()));
|
||||
}
|
||||
|
||||
const std::vector<std::string> & CHeroClassHandler::getTypeNames() const
|
||||
@@ -235,7 +235,7 @@ CHeroClass * CHeroClassHandler::loadFromJson(const std::string & scope, const Js
|
||||
|
||||
std::string affinityStr[2] = { "might", "magic" };
|
||||
|
||||
auto heroClass = new CHeroClass();
|
||||
auto * heroClass = new CHeroClass();
|
||||
|
||||
heroClass->id = HeroClassID(index);
|
||||
heroClass->identifier = identifier;
|
||||
@@ -281,7 +281,7 @@ CHeroClass * CHeroClassHandler::loadFromJson(const std::string & scope, const Js
|
||||
});
|
||||
|
||||
heroClass->defaultTavernChance = static_cast<ui32>(node["defaultTavern"].Float());
|
||||
for(auto & tavern : node["tavern"].Struct())
|
||||
for(const auto & tavern : node["tavern"].Struct())
|
||||
{
|
||||
int value = static_cast<int>(tavern.second.Float());
|
||||
|
||||
@@ -328,19 +328,19 @@ std::vector<JsonNode> CHeroClassHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
parser.readNumber(); // unused aggression
|
||||
|
||||
for (auto & name : PrimarySkill::names)
|
||||
for(const auto & name : PrimarySkill::names)
|
||||
entry["primarySkills"][name].Float() = parser.readNumber();
|
||||
|
||||
for (auto & name : PrimarySkill::names)
|
||||
for(const auto & name : PrimarySkill::names)
|
||||
entry["lowLevelChance"][name].Float() = parser.readNumber();
|
||||
|
||||
for (auto & name : PrimarySkill::names)
|
||||
for(const auto & name : PrimarySkill::names)
|
||||
entry["highLevelChance"][name].Float() = parser.readNumber();
|
||||
|
||||
for (auto & name : NSecondarySkill::names)
|
||||
for(const auto & name : NSecondarySkill::names)
|
||||
entry["secondarySkills"][name].Float() = parser.readNumber();
|
||||
|
||||
for(auto & name : ETownType::names)
|
||||
for(const auto & name : ETownType::names)
|
||||
entry["tavern"][name].Float() = parser.readNumber();
|
||||
|
||||
parser.endLine();
|
||||
@@ -361,7 +361,7 @@ void CHeroClassHandler::afterLoadFinalization()
|
||||
if (heroClass->selectionProbability.count(faction->getIndex()))
|
||||
continue;
|
||||
|
||||
float chance = static_cast<float>(heroClass->defaultTavernChance * faction->town->defaultTavernChance);
|
||||
auto chance = static_cast<float>(heroClass->defaultTavernChance * faction->town->defaultTavernChance);
|
||||
heroClass->selectionProbability[faction->getIndex()] = static_cast<int>(sqrt(chance) + 0.5); //FIXME: replace with std::round once MVS supports it
|
||||
}
|
||||
// set default probabilities for gaining secondary skills where not loaded previously
|
||||
@@ -413,7 +413,7 @@ CHero * CHeroHandler::loadFromJson(const std::string & scope, const JsonNode & n
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
assert(!scope.empty());
|
||||
|
||||
auto hero = new CHero();
|
||||
auto * hero = new CHero();
|
||||
hero->ID = HeroTypeID(index);
|
||||
hero->identifier = identifier;
|
||||
hero->modScope = scope;
|
||||
@@ -445,7 +445,7 @@ CHero * CHeroHandler::loadFromJson(const std::string & scope, const JsonNode & n
|
||||
return hero;
|
||||
}
|
||||
|
||||
void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node)
|
||||
void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node) const
|
||||
{
|
||||
assert(node["army"].Vector().size() <= 3); // anything bigger is useless - army initialization uses up to 3 slots
|
||||
|
||||
@@ -467,7 +467,7 @@ void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node)
|
||||
}
|
||||
}
|
||||
|
||||
void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node)
|
||||
void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node) const
|
||||
{
|
||||
for(const JsonNode &set : node["skills"].Vector())
|
||||
{
|
||||
@@ -475,7 +475,7 @@ void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node)
|
||||
if (skillLevel < SecSkillLevel::LEVELS_SIZE)
|
||||
{
|
||||
size_t currentIndex = hero->secSkillsInit.size();
|
||||
hero->secSkillsInit.push_back(std::make_pair(SecondarySkill(-1), skillLevel));
|
||||
hero->secSkillsInit.emplace_back(SecondarySkill(-1), skillLevel);
|
||||
|
||||
VLC->modh->identifiers.requestIdentifier("skill", set["skill"], [=](si32 id)
|
||||
{
|
||||
@@ -639,7 +639,7 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo
|
||||
bonus->additionalInfo = spec.additionalinfo; //target id
|
||||
result.push_back(bonus);
|
||||
//propagate for regular upgrades of base creature
|
||||
for(auto cre_id : creatures[spec.subtype]->upgrades)
|
||||
for(const auto & cre_id : creatures[spec.subtype]->upgrades)
|
||||
{
|
||||
std::shared_ptr<Bonus> upgradeUpgradedVersion = std::make_shared<Bonus>(*bonus);
|
||||
upgradeUpgradedVersion->subtype = cre_id;
|
||||
@@ -705,7 +705,7 @@ void CHeroHandler::beforeValidate(JsonNode & object)
|
||||
}
|
||||
}
|
||||
|
||||
void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
||||
void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node) const
|
||||
{
|
||||
int sid = hero->ID.getNum();
|
||||
auto prepSpec = [=](std::shared_ptr<Bonus> bonus)
|
||||
@@ -725,7 +725,7 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("creature", specialtyNode["creature"], [hero](si32 creature) {
|
||||
// use legacy format for delayed conversion (must have all creature data loaded, also for upgrades)
|
||||
SSpecialtyInfo spec;
|
||||
SSpecialtyInfo spec{};
|
||||
spec.type = 1;
|
||||
spec.additionalinfo = creature;
|
||||
hero->specDeprecated.push_back(spec);
|
||||
@@ -734,7 +734,7 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
||||
if(!specialtyNode["bonuses"].isNull())
|
||||
{
|
||||
//proper new format
|
||||
for(auto keyValue : specialtyNode["bonuses"].Struct())
|
||||
for(const auto & keyValue : specialtyNode["bonuses"].Struct())
|
||||
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(keyValue.second)));
|
||||
}
|
||||
}
|
||||
@@ -824,17 +824,17 @@ std::vector<JsonNode> CHeroHandler::loadLegacyData(size_t dataSize)
|
||||
void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
size_t index = objects.size();
|
||||
auto object = loadFromJson(scope, data, name, index);
|
||||
object->imageIndex = (si32)index + GameConstants::HERO_PORTRAIT_SHIFT; // 2 special frames + some extra portraits
|
||||
auto * object = loadFromJson(scope, data, name, index);
|
||||
object->imageIndex = static_cast<si32>(index) + GameConstants::HERO_PORTRAIT_SHIFT; // 2 special frames + some extra portraits
|
||||
|
||||
objects.push_back(object);
|
||||
objects.emplace_back(object);
|
||||
|
||||
registerObject(scope, "hero", name, object->getIndex());
|
||||
}
|
||||
|
||||
void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(scope, data, name, index);
|
||||
auto * object = loadFromJson(scope, data, name, index);
|
||||
object->imageIndex = static_cast<si32>(index);
|
||||
|
||||
assert(objects[index] == nullptr); // ensure that this id was not loaded before
|
||||
@@ -847,25 +847,25 @@ void CHeroHandler::afterLoadFinalization()
|
||||
{
|
||||
for(auto & hero : objects)
|
||||
{
|
||||
for(auto bonus : hero->specialty)
|
||||
for(const auto & bonus : hero->specialty)
|
||||
{
|
||||
bonus->sid = hero->getIndex();
|
||||
}
|
||||
|
||||
if(hero->specDeprecated.size() > 0)
|
||||
if(!hero->specDeprecated.empty())
|
||||
{
|
||||
logMod->debug("Converting specialty format for hero %s(%s)", hero->getNameTranslated(), FactionID::encode(hero->heroClass->faction));
|
||||
std::vector<std::shared_ptr<Bonus>> convertedBonuses;
|
||||
for(const SSpecialtyInfo & spec : hero->specDeprecated)
|
||||
{
|
||||
for(std::shared_ptr<Bonus> b : SpecialtyInfoToBonuses(spec, hero->ID.getNum()))
|
||||
for(const std::shared_ptr<Bonus> & b : SpecialtyInfoToBonuses(spec, hero->ID.getNum()))
|
||||
convertedBonuses.push_back(b);
|
||||
}
|
||||
hero->specDeprecated.clear();
|
||||
// store and create json for logging
|
||||
std::vector<JsonNode> specVec;
|
||||
std::vector<std::string> specNames;
|
||||
for(std::shared_ptr<Bonus> bonus : convertedBonuses)
|
||||
for(const std::shared_ptr<Bonus> & bonus : convertedBonuses)
|
||||
{
|
||||
hero->specialty.push_back(bonus);
|
||||
specVec.push_back(bonus->toJsonNode());
|
||||
|
@@ -66,18 +66,18 @@ public:
|
||||
h & creature;
|
||||
}
|
||||
};
|
||||
si32 imageIndex;
|
||||
si32 imageIndex = 0;
|
||||
|
||||
std::vector<InitialArmyStack> initialArmy;
|
||||
|
||||
CHeroClass * heroClass;
|
||||
CHeroClass * heroClass{};
|
||||
std::vector<std::pair<SecondarySkill, ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
|
||||
std::vector<SSpecialtyInfo> specDeprecated;
|
||||
BonusList specialty;
|
||||
std::set<SpellID> spells;
|
||||
bool haveSpellBook;
|
||||
bool special; // hero is special and won't be placed in game (unless preset on map), e.g. campaign heroes
|
||||
ui8 sex; // default sex: 0=male, 1=female
|
||||
bool haveSpellBook = false;
|
||||
bool special = false; // hero is special and won't be placed in game (unless preset on map), e.g. campaign heroes
|
||||
ui8 sex = 0; // default sex: 0=male, 1=female
|
||||
|
||||
/// Graphics
|
||||
std::string iconSpecSmall;
|
||||
@@ -220,7 +220,8 @@ public:
|
||||
|
||||
class DLL_LINKAGE CHeroClassHandler : public CHandlerBase<HeroClassID, HeroClass, CHeroClass, HeroClassService>
|
||||
{
|
||||
void fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill::PrimarySkill pSkill);
|
||||
void fillPrimarySkillData(const JsonNode & node, CHeroClass * heroClass, PrimarySkill::PrimarySkill pSkill) const;
|
||||
|
||||
public:
|
||||
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
|
||||
|
||||
@@ -248,9 +249,9 @@ class DLL_LINKAGE CHeroHandler : public CHandlerBase<HeroTypeID, HeroType, CHero
|
||||
std::vector<ui64> expPerLevel;
|
||||
|
||||
/// helpers for loading to avoid huge load functions
|
||||
void loadHeroArmy(CHero * hero, const JsonNode & node);
|
||||
void loadHeroSkills(CHero * hero, const JsonNode & node);
|
||||
void loadHeroSpecialty(CHero * hero, const JsonNode & node);
|
||||
void loadHeroArmy(CHero * hero, const JsonNode & node) const;
|
||||
void loadHeroSkills(CHero * hero, const JsonNode & node) const;
|
||||
void loadHeroSpecialty(CHero * hero, const JsonNode & node) const;
|
||||
|
||||
void loadExperience();
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "CModHandler.h"
|
||||
#include "mapObjects/CObjectClassesHandler.h"
|
||||
#include "rmg/CRmgTemplateStorage.h"
|
||||
#include "filesystem/FileStream.h"
|
||||
#include "filesystem/AdapterLoaders.h"
|
||||
#include "filesystem/CFilesystemLoader.h"
|
||||
@@ -42,10 +43,6 @@ CIdentifierStorage::CIdentifierStorage():
|
||||
{
|
||||
}
|
||||
|
||||
CIdentifierStorage::~CIdentifierStorage()
|
||||
{
|
||||
}
|
||||
|
||||
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||
{
|
||||
if (boost::algorithm::ends_with(ID, "."))
|
||||
@@ -66,15 +63,17 @@ void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||
}
|
||||
}
|
||||
|
||||
CIdentifierStorage::ObjectCallback::ObjectCallback(
|
||||
std::string localScope, std::string remoteScope, std::string type,
|
||||
std::string name, const std::function<void(si32)> & callback,
|
||||
bool optional):
|
||||
localScope(localScope),
|
||||
remoteScope(remoteScope),
|
||||
type(type),
|
||||
name(name),
|
||||
callback(callback),
|
||||
CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope,
|
||||
std::string remoteScope,
|
||||
std::string type,
|
||||
std::string name,
|
||||
std::function<void(si32)> callback,
|
||||
bool optional):
|
||||
localScope(std::move(localScope)),
|
||||
remoteScope(std::move(remoteScope)),
|
||||
type(std::move(type)),
|
||||
name(std::move(name)),
|
||||
callback(std::move(callback)),
|
||||
optional(optional)
|
||||
{}
|
||||
|
||||
@@ -91,14 +90,14 @@ void CIdentifierStorage::requestIdentifier(ObjectCallback callback)
|
||||
resolveIdentifier(callback);
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)>& callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto scopeAndFullName = vstd::splitStringToPair(fullName, ':');
|
||||
auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.');
|
||||
@@ -106,7 +105,7 @@ void CIdentifierStorage::requestIdentifier(std::string scope, std::string fullNa
|
||||
requestIdentifier(ObjectCallback(scope, scopeAndFullName.first, typeAndName.first, typeAndName.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
|
||||
@@ -121,21 +120,21 @@ void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::fun
|
||||
requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::tryRequestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, true));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::tryRequestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, true));
|
||||
}
|
||||
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::string type, std::string name, bool silent)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback(scope, pair.first, type, pair.second, std::function<void(si32)>(), silent));
|
||||
@@ -148,7 +147,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::
|
||||
return boost::optional<si32>();
|
||||
}
|
||||
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string type, const JsonNode & name, bool silent)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, type, pair.second, std::function<void(si32)>(), silent));
|
||||
@@ -175,7 +174,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, b
|
||||
return boost::optional<si32>();
|
||||
}
|
||||
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::string fullName, bool silent)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(fullName, ':'); // remoteScope:<type.name>
|
||||
auto pair2 = vstd::splitStringToPair(pair.second, '.'); // type.name
|
||||
@@ -189,7 +188,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::
|
||||
return boost::optional<si32>();
|
||||
}
|
||||
|
||||
void CIdentifierStorage::registerObject(std::string scope, std::string type, std::string name, si32 identifier)
|
||||
void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier)
|
||||
{
|
||||
ObjectData data;
|
||||
data.scope = scope;
|
||||
@@ -300,14 +299,14 @@ bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request)
|
||||
}
|
||||
|
||||
// error found. Try to generate some debug info
|
||||
if (identifiers.size() == 0)
|
||||
if(identifiers.empty())
|
||||
logMod->error("Unknown identifier!");
|
||||
else
|
||||
logMod->error("Ambiguous identifier request!");
|
||||
|
||||
logMod->error("Request for %s.%s from mod %s", request.type, request.name, request.localScope);
|
||||
|
||||
for (auto id : identifiers)
|
||||
for(const auto & id : identifiers)
|
||||
{
|
||||
logMod->error("\tID is available in mod %s", id.scope);
|
||||
}
|
||||
@@ -331,7 +330,7 @@ void CIdentifierStorage::finalize()
|
||||
|
||||
if (errorsFound)
|
||||
{
|
||||
for(auto object : registeredObjects)
|
||||
for(const auto & object : registeredObjects)
|
||||
{
|
||||
logMod->trace("%s : %s -> %d", object.second.scope, object.first, object.second.id);
|
||||
}
|
||||
@@ -341,10 +340,10 @@ void CIdentifierStorage::finalize()
|
||||
state = FINISHED;
|
||||
}
|
||||
|
||||
ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objectName):
|
||||
ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, const std::string & objectName):
|
||||
handler(handler),
|
||||
objectName(objectName),
|
||||
originalData(handler->loadLegacyData((size_t)VLC->modh->settings.data["textData"][objectName].Float()))
|
||||
originalData(handler->loadLegacyData(static_cast<size_t>(VLC->modh->settings.data["textData"][objectName].Float())))
|
||||
{
|
||||
for(auto & node : originalData)
|
||||
{
|
||||
@@ -352,9 +351,9 @@ ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objec
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentTypeHandler::preloadModData(std::string modName, std::vector<std::string> fileList, bool validate)
|
||||
bool ContentTypeHandler::preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate)
|
||||
{
|
||||
bool result;
|
||||
bool result = false;
|
||||
JsonNode data = JsonUtils::assembleFromFiles(fileList, result);
|
||||
data.setMeta(modName);
|
||||
|
||||
@@ -387,7 +386,7 @@ bool ContentTypeHandler::preloadModData(std::string modName, std::vector<std::st
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ContentTypeHandler::loadMod(std::string modName, bool validate)
|
||||
bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
|
||||
{
|
||||
ModInfo & modInfo = modData[modName];
|
||||
bool result = true;
|
||||
@@ -440,7 +439,6 @@ bool ContentTypeHandler::loadMod(std::string modName, bool validate)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ContentTypeHandler::loadCustom()
|
||||
{
|
||||
handler->loadCustom();
|
||||
@@ -451,10 +449,6 @@ void ContentTypeHandler::afterLoadFinalization()
|
||||
handler->afterLoadFinalization();
|
||||
}
|
||||
|
||||
CContentHandler::CContentHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void CContentHandler::init()
|
||||
{
|
||||
handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(&VLC->heroh->classes, "heroClass")));
|
||||
@@ -465,7 +459,7 @@ void CContentHandler::init()
|
||||
handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero")));
|
||||
handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell")));
|
||||
handlers.insert(std::make_pair("skills", ContentTypeHandler(VLC->skillh, "skill")));
|
||||
handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template")));
|
||||
handlers.insert(std::make_pair("templates", ContentTypeHandler(VLC->tplh, "template")));
|
||||
#if SCRIPTING_ENABLED
|
||||
handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script")));
|
||||
#endif
|
||||
@@ -477,7 +471,7 @@ void CContentHandler::init()
|
||||
//TODO: any other types of moddables?
|
||||
}
|
||||
|
||||
bool CContentHandler::preloadModData(std::string modName, JsonNode modConfig, bool validate)
|
||||
bool CContentHandler::preloadModData(const std::string & modName, JsonNode modConfig, bool validate)
|
||||
{
|
||||
bool result = true;
|
||||
for(auto & handler : handlers)
|
||||
@@ -487,7 +481,7 @@ bool CContentHandler::preloadModData(std::string modName, JsonNode modConfig, bo
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CContentHandler::loadMod(std::string modName, bool validate)
|
||||
bool CContentHandler::loadMod(const std::string & modName, bool validate)
|
||||
{
|
||||
bool result = true;
|
||||
for(auto & handler : handlers)
|
||||
@@ -552,7 +546,7 @@ const ContentTypeHandler & CContentHandler::operator[](const std::string & name)
|
||||
return handlers.at(name);
|
||||
}
|
||||
|
||||
static JsonNode loadModSettings(std::string path)
|
||||
static JsonNode loadModSettings(const std::string & path)
|
||||
{
|
||||
if (CResourceHandler::get("local")->existsResource(ResourceID(path)))
|
||||
{
|
||||
@@ -563,7 +557,7 @@ static JsonNode loadModSettings(std::string path)
|
||||
return JsonNode();
|
||||
}
|
||||
|
||||
JsonNode addMeta(JsonNode config, std::string meta)
|
||||
JsonNode addMeta(JsonNode config, const std::string & meta)
|
||||
{
|
||||
config.setMeta(meta);
|
||||
return config;
|
||||
@@ -576,7 +570,9 @@ CModInfo::Version CModInfo::Version::GameVersion()
|
||||
|
||||
CModInfo::Version CModInfo::Version::fromString(std::string from)
|
||||
{
|
||||
int major = 0, minor = 0, patch = 0;
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
try
|
||||
{
|
||||
auto pointPos = from.find('.');
|
||||
@@ -623,12 +619,12 @@ CModInfo::CModInfo():
|
||||
|
||||
}
|
||||
|
||||
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):
|
||||
CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config):
|
||||
identifier(identifier),
|
||||
name(config["name"].String()),
|
||||
description(config["description"].String()),
|
||||
dependencies(config["depends"].convertTo<std::set<std::string> >()),
|
||||
conflicts(config["conflicts"].convertTo<std::set<std::string> >()),
|
||||
dependencies(config["depends"].convertTo<std::set<std::string>>()),
|
||||
conflicts(config["conflicts"].convertTo<std::set<std::string>>()),
|
||||
checksum(0),
|
||||
explicitlyEnabled(false),
|
||||
implicitlyEnabled(true),
|
||||
@@ -662,12 +658,12 @@ JsonNode CModInfo::saveLocalData() const
|
||||
return conf;
|
||||
}
|
||||
|
||||
std::string CModInfo::getModDir(std::string name)
|
||||
std::string CModInfo::getModDir(const std::string & name)
|
||||
{
|
||||
return "MODS/" + boost::algorithm::replace_all_copy(name, ".", "/MODS/");
|
||||
}
|
||||
|
||||
std::string CModInfo::getModFile(std::string name)
|
||||
std::string CModInfo::getModFile(const std::string & name)
|
||||
{
|
||||
return getModDir(name) + "/mod.json";
|
||||
}
|
||||
@@ -749,14 +745,10 @@ CModHandler::CModHandler() : content(std::make_shared<CContentHandler>())
|
||||
}
|
||||
}
|
||||
|
||||
CModHandler::~CModHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void CModHandler::loadConfigFromFile (std::string name)
|
||||
void CModHandler::loadConfigFromFile(const std::string & name)
|
||||
{
|
||||
std::string paths;
|
||||
for(auto& p : CResourceHandler::get()->getResourceNames(ResourceID("config/" + name)))
|
||||
for(const auto & p : CResourceHandler::get()->getResourceNames(ResourceID("config/" + name)))
|
||||
{
|
||||
paths += p.string() + ", ";
|
||||
}
|
||||
@@ -820,7 +812,7 @@ void CModHandler::loadConfigFromFile (std::string name)
|
||||
}
|
||||
|
||||
// currentList is passed by value to get current list of depending mods
|
||||
bool CModHandler::hasCircularDependency(TModID modID, std::set <TModID> currentList) const
|
||||
bool CModHandler::hasCircularDependency(const TModID & modID, std::set<TModID> currentList) const
|
||||
{
|
||||
const CModInfo & mod = allMods.at(modID);
|
||||
|
||||
@@ -885,7 +877,7 @@ std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModI
|
||||
}
|
||||
it++;
|
||||
}
|
||||
if(resolvedOnCurrentTreeLevel.size())
|
||||
if(!resolvedOnCurrentTreeLevel.empty())
|
||||
{
|
||||
resolvedModIDs.insert(resolvedOnCurrentTreeLevel.begin(), resolvedOnCurrentTreeLevel.end());
|
||||
continue;
|
||||
@@ -907,8 +899,7 @@ std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModI
|
||||
return sortedValidMods;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> CModHandler::getModList(std::string path)
|
||||
std::vector<std::string> CModHandler::getModList(const std::string & path) const
|
||||
{
|
||||
std::string modDir = boost::to_upper_copy(path + "MODS/");
|
||||
size_t depth = boost::range::count(modDir, '/');
|
||||
@@ -926,7 +917,7 @@ std::vector<std::string> CModHandler::getModList(std::string path)
|
||||
|
||||
//storage for found mods
|
||||
std::vector<std::string> foundMods;
|
||||
for (auto & entry : list)
|
||||
for(const auto & entry : list)
|
||||
{
|
||||
std::string name = entry.getName();
|
||||
name.erase(0, modDir.size()); //Remove path prefix
|
||||
@@ -967,13 +958,13 @@ const TModID & CModHandler::scopeMap()
|
||||
return scope;
|
||||
}
|
||||
|
||||
void CModHandler::loadMods(std::string path, std::string parent, const JsonNode & modSettings, bool enableMods)
|
||||
void CModHandler::loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods)
|
||||
{
|
||||
for(std::string modName : getModList(path))
|
||||
for(const std::string & modName : getModList(path))
|
||||
loadOneMod(modName, parent, modSettings, enableMods);
|
||||
}
|
||||
|
||||
void CModHandler::loadOneMod(std::string modName, std::string parent, const JsonNode & modSettings, bool enableMods)
|
||||
void CModHandler::loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods)
|
||||
{
|
||||
boost::to_lower(modName);
|
||||
std::string modFullName = parent.empty() ? modName : parent + '.' + modName;
|
||||
@@ -1019,6 +1010,7 @@ void CModHandler::loadMods(bool onlyEssential)
|
||||
std::vector<std::string> CModHandler::getAllMods()
|
||||
{
|
||||
std::vector<std::string> modlist;
|
||||
modlist.reserve(allMods.size());
|
||||
for (auto & entry : allMods)
|
||||
modlist.push_back(entry.first);
|
||||
return modlist;
|
||||
@@ -1051,7 +1043,7 @@ static ISimpleResourceLoader * genModFilesystem(const std::string & modName, con
|
||||
return CResourceHandler::createFileSystem(CModInfo::getModDir(modName), defaultFS);
|
||||
}
|
||||
|
||||
static ui32 calculateModChecksum(const std::string modName, ISimpleResourceLoader * filesystem)
|
||||
static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoader * filesystem)
|
||||
{
|
||||
boost::crc_32_type modChecksum;
|
||||
// first - add current VCMI version into checksum to force re-validation on VCMI updates
|
||||
@@ -1121,7 +1113,7 @@ std::string CModHandler::getModLanguage(const TModID& modId) const
|
||||
return allMods.at(modId).baseLanguage;
|
||||
}
|
||||
|
||||
std::set<TModID> CModHandler::getModDependencies(TModID modId, bool & isModFound) const
|
||||
std::set<TModID> CModHandler::getModDependencies(const TModID & modId, bool & isModFound) const
|
||||
{
|
||||
auto it = allMods.find(modId);
|
||||
isModFound = (it != allMods.end());
|
||||
@@ -1168,7 +1160,7 @@ bool CModHandler::validateTranslations(TModID modName) const
|
||||
return result;
|
||||
}
|
||||
|
||||
void CModHandler::loadTranslation(TModID modName)
|
||||
void CModHandler::loadTranslation(const TModID & modName)
|
||||
{
|
||||
const auto & mod = allMods[modName];
|
||||
|
||||
@@ -1277,7 +1269,7 @@ void CModHandler::parseIdentifier(const std::string & fullIdentifier, std::strin
|
||||
|
||||
auto p2 = vstd::splitStringToPair(p.second, '.');
|
||||
|
||||
if(p2.first != "")
|
||||
if(!p2.first.empty())
|
||||
{
|
||||
type = p2.first;
|
||||
identifier = p2.second;
|
||||
@@ -1300,7 +1292,7 @@ std::string CModHandler::makeFullIdentifier(const std::string & scope, const std
|
||||
//ignore scope if identifier is scoped
|
||||
auto scopeAndName = vstd::splitStringToPair(identifier, ':');
|
||||
|
||||
if(scopeAndName.first != "")
|
||||
if(!scopeAndName.first.empty())
|
||||
{
|
||||
actualScope = scopeAndName.first;
|
||||
actualName = scopeAndName.second;
|
||||
|
@@ -50,7 +50,7 @@ class DLL_LINKAGE CIdentifierStorage
|
||||
|
||||
ObjectCallback(std::string localScope, std::string remoteScope,
|
||||
std::string type, std::string name,
|
||||
const std::function<void(si32)> & callback,
|
||||
std::function<void(si32)> callback,
|
||||
bool optional);
|
||||
};
|
||||
|
||||
@@ -77,34 +77,34 @@ class DLL_LINKAGE CIdentifierStorage
|
||||
ELoadingState state;
|
||||
|
||||
/// Check if identifier can be valid (camelCase, point as separator)
|
||||
void checkIdentifier(std::string & ID);
|
||||
static void checkIdentifier(std::string & ID);
|
||||
|
||||
void requestIdentifier(ObjectCallback callback);
|
||||
bool resolveIdentifier(const ObjectCallback & callback);
|
||||
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback);
|
||||
public:
|
||||
CIdentifierStorage();
|
||||
virtual ~CIdentifierStorage();
|
||||
virtual ~CIdentifierStorage() = default;
|
||||
/// request identifier for specific object name.
|
||||
/// Function callback will be called during ID resolution phase of loading
|
||||
void requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback);
|
||||
///fullName = [remoteScope:]type.name
|
||||
void requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
|
||||
/// try to request ID. If ID with such name won't be loaded, callback function will not be called
|
||||
void tryRequestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback);
|
||||
void tryRequestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
void tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback);
|
||||
void tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
|
||||
/// get identifier immediately. If identifier is not know and not silent call will result in error message
|
||||
boost::optional<si32> getIdentifier(std::string scope, std::string type, std::string name, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(std::string type, const JsonNode & name, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(const std::string & type, const JsonNode & name, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(const JsonNode & name, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(std::string scope, std::string fullName, bool silent = false);
|
||||
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & fullName, bool silent = false);
|
||||
|
||||
/// registers new object
|
||||
void registerObject(std::string scope, std::string type, std::string name, si32 identifier);
|
||||
void registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier);
|
||||
|
||||
/// called at the very end of loading to check for any missing ID's
|
||||
void finalize();
|
||||
@@ -135,12 +135,12 @@ public:
|
||||
std::vector<JsonNode> originalData;
|
||||
std::map<std::string, ModInfo> modData;
|
||||
|
||||
ContentTypeHandler(IHandlerBase * handler, std::string objectName);
|
||||
ContentTypeHandler(IHandlerBase * handler, const std::string & objectName);
|
||||
|
||||
/// local version of methods in ContentHandler
|
||||
/// returns true if loading was successful
|
||||
bool preloadModData(std::string modName, std::vector<std::string> fileList, bool validate);
|
||||
bool loadMod(std::string modName, bool validate);
|
||||
bool preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate);
|
||||
bool loadMod(const std::string & modName, bool validate);
|
||||
void loadCustom();
|
||||
void afterLoadFinalization();
|
||||
};
|
||||
@@ -149,15 +149,14 @@ public:
|
||||
class DLL_LINKAGE CContentHandler
|
||||
{
|
||||
/// preloads all data from fileList as data from modName.
|
||||
bool preloadModData(std::string modName, JsonNode modConfig, bool validate);
|
||||
bool preloadModData(const std::string & modName, JsonNode modConfig, bool validate);
|
||||
|
||||
/// actually loads data in mod
|
||||
bool loadMod(std::string modName, bool validate);
|
||||
bool loadMod(const std::string & modName, bool validate);
|
||||
|
||||
std::map<std::string, ContentTypeHandler> handlers;
|
||||
public:
|
||||
CContentHandler();
|
||||
|
||||
public:
|
||||
void init();
|
||||
|
||||
/// preloads all data from fileList as data from modName.
|
||||
@@ -241,7 +240,7 @@ public:
|
||||
JsonNode config;
|
||||
|
||||
CModInfo();
|
||||
CModInfo(std::string identifier, const JsonNode & local, const JsonNode & config);
|
||||
CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config);
|
||||
|
||||
JsonNode saveLocalData() const;
|
||||
void updateChecksum(ui32 newChecksum);
|
||||
@@ -249,8 +248,8 @@ public:
|
||||
bool isEnabled() const;
|
||||
void setEnabled(bool on);
|
||||
|
||||
static std::string getModDir(std::string name);
|
||||
static std::string getModFile(std::string name);
|
||||
static std::string getModDir(const std::string & name);
|
||||
static std::string getModFile(const std::string & name);
|
||||
|
||||
private:
|
||||
/// true if mod is enabled by user, e.g. in Launcher UI
|
||||
@@ -268,9 +267,9 @@ class DLL_LINKAGE CModHandler
|
||||
std::vector <TModID> activeMods;//active mods, in order in which they were loaded
|
||||
CModInfo coreMod;
|
||||
|
||||
void loadConfigFromFile(std::string name);
|
||||
void loadConfigFromFile(const std::string & name);
|
||||
|
||||
bool hasCircularDependency(TModID mod, std::set <TModID> currentList = std::set <TModID>()) const;
|
||||
bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
|
||||
|
||||
/**
|
||||
* 1. Set apart mods with resolved dependencies from mods which have unresolved dependencies
|
||||
@@ -282,10 +281,10 @@ class DLL_LINKAGE CModHandler
|
||||
*/
|
||||
std::vector <TModID> validateAndSortDependencies(std::vector <TModID> modsToResolve) const;
|
||||
|
||||
std::vector<std::string> getModList(std::string path);
|
||||
void loadMods(std::string path, std::string parent, const JsonNode & modSettings, bool enableMods);
|
||||
void loadOneMod(std::string modName, std::string parent, const JsonNode & modSettings, bool enableMods);
|
||||
void loadTranslation(TModID modName);
|
||||
std::vector<std::string> getModList(const std::string & path) const;
|
||||
void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods);
|
||||
void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods);
|
||||
void loadTranslation(const TModID & modName);
|
||||
|
||||
bool validateTranslations(TModID modName) const;
|
||||
public:
|
||||
@@ -342,9 +341,9 @@ public:
|
||||
/// returns ID of mod that provides selected file resource
|
||||
TModID findResourceOrigin(const ResourceID & name);
|
||||
|
||||
std::string getModLanguage(const TModID& modId) const;
|
||||
std::string getModLanguage(const TModID & modId) const;
|
||||
|
||||
std::set<TModID> getModDependencies(TModID modId, bool & isModFound) const;
|
||||
std::set<TModID> getModDependencies(const TModID & modId, bool & isModFound) const;
|
||||
|
||||
/// returns list of all (active) mods
|
||||
std::vector<std::string> getAllMods();
|
||||
@@ -421,7 +420,7 @@ public:
|
||||
} modules;
|
||||
|
||||
CModHandler();
|
||||
virtual ~CModHandler();
|
||||
virtual ~CModHandler() = default;
|
||||
|
||||
static std::string normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier);
|
||||
|
||||
|
@@ -80,7 +80,7 @@ std::vector<CGPathNode *> NodeStorage::calculateNeighbours(
|
||||
{
|
||||
for(EPathfindingLayer i = EPathfindingLayer::LAND; i <= EPathfindingLayer::AIR; i.advance(1))
|
||||
{
|
||||
auto node = getNode(neighbour, i);
|
||||
auto * node = getNode(neighbour, i);
|
||||
|
||||
if(node->accessible == CGPathNode::NOT_SET)
|
||||
continue;
|
||||
@@ -106,7 +106,7 @@ std::vector<CGPathNode *> NodeStorage::calculateTeleportations(
|
||||
|
||||
for(auto & neighbour : accessibleExits)
|
||||
{
|
||||
auto node = getNode(neighbour, source.node->layer);
|
||||
auto * node = getNode(neighbour, source.node->layer);
|
||||
|
||||
neighbours.push_back(node);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ std::vector<int3> CPathfinderHelper::getNeighbourTiles(const PathNodeInfo & sour
|
||||
|
||||
if(source.isNodeObjectVisitable())
|
||||
{
|
||||
vstd::erase_if(neighbourTiles, [&](int3 tile) -> bool
|
||||
vstd::erase_if(neighbourTiles, [&](const int3 & tile) -> bool
|
||||
{
|
||||
return !canMoveBetween(tile, source.nodeObject->visitablePos());
|
||||
});
|
||||
@@ -144,17 +144,14 @@ NodeStorage::NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero)
|
||||
out.hpos = hero->visitablePos();
|
||||
}
|
||||
|
||||
void NodeStorage::resetTile(
|
||||
const int3 & tile,
|
||||
EPathfindingLayer layer,
|
||||
CGPathNode::EAccessibility accessibility)
|
||||
void NodeStorage::resetTile(const int3 & tile, const EPathfindingLayer & layer, CGPathNode::EAccessibility accessibility)
|
||||
{
|
||||
getNode(tile, layer)->update(tile, layer, accessibility);
|
||||
}
|
||||
|
||||
std::vector<CGPathNode *> NodeStorage::getInitialNodes()
|
||||
{
|
||||
auto initialNode = getNode(out.hpos, out.hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND);
|
||||
auto * initialNode = getNode(out.hpos, out.hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND);
|
||||
|
||||
initialNode->turns = 0;
|
||||
initialNode->moveRemains = out.hero->movement;
|
||||
@@ -247,10 +244,9 @@ void MovementCostRule::process(
|
||||
destination.blocked = true;
|
||||
}
|
||||
|
||||
PathfinderConfig::PathfinderConfig(
|
||||
std::shared_ptr<INodeStorage> nodeStorage,
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules)
|
||||
: nodeStorage(nodeStorage), rules(rules), options()
|
||||
PathfinderConfig::PathfinderConfig(std::shared_ptr<INodeStorage> nodeStorage, std::vector<std::shared_ptr<IPathfindingRule>> rules):
|
||||
nodeStorage(std::move(nodeStorage)),
|
||||
rules(std::move(rules))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -268,7 +264,7 @@ std::vector<std::shared_ptr<IPathfindingRule>> SingleHeroPathfinderConfig::build
|
||||
SingleHeroPathfinderConfig::SingleHeroPathfinderConfig(CPathsInfo & out, CGameState * gs, const CGHeroInstance * hero)
|
||||
: PathfinderConfig(std::make_shared<NodeStorage>(out, hero), buildRuleSet())
|
||||
{
|
||||
pathfinderHelper.reset(new CPathfinderHelper(gs, hero, options));
|
||||
pathfinderHelper = std::make_unique<CPathfinderHelper>(gs, hero, options);
|
||||
}
|
||||
|
||||
CPathfinderHelper * SingleHeroPathfinderConfig::getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs)
|
||||
@@ -276,13 +272,9 @@ CPathfinderHelper * SingleHeroPathfinderConfig::getOrCreatePathfinderHelper(cons
|
||||
return pathfinderHelper.get();
|
||||
}
|
||||
|
||||
CPathfinder::CPathfinder(
|
||||
CGameState * _gs,
|
||||
std::shared_ptr<PathfinderConfig> config)
|
||||
: gamestate(_gs)
|
||||
, config(config)
|
||||
, source()
|
||||
, destination()
|
||||
CPathfinder::CPathfinder(CGameState * _gs, std::shared_ptr<PathfinderConfig> config):
|
||||
gamestate(_gs),
|
||||
config(std::move(config))
|
||||
{
|
||||
initializeGraph();
|
||||
}
|
||||
@@ -301,7 +293,7 @@ void CPathfinder::push(CGPathNode * node)
|
||||
|
||||
CGPathNode * CPathfinder::topAndPop()
|
||||
{
|
||||
auto node = pq.top();
|
||||
auto * node = pq.top();
|
||||
|
||||
pq.pop();
|
||||
node->inPQ = false;
|
||||
@@ -317,7 +309,7 @@ void CPathfinder::calculatePaths()
|
||||
std::vector<CGPathNode *> initialNodes = config->nodeStorage->getInitialNodes();
|
||||
int counter = 0;
|
||||
|
||||
for(auto initialNode : initialNodes)
|
||||
for(auto * initialNode : initialNodes)
|
||||
{
|
||||
if(!gamestate->isInTheMap(initialNode->coord)/* || !gs->map->isInTheMap(dest)*/) //check input
|
||||
{
|
||||
@@ -326,7 +318,7 @@ void CPathfinder::calculatePaths()
|
||||
}
|
||||
|
||||
source.setNode(gamestate, initialNode);
|
||||
auto hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
||||
auto * hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
||||
|
||||
if(hlp->isHeroPatrolLocked())
|
||||
continue;
|
||||
@@ -337,7 +329,7 @@ void CPathfinder::calculatePaths()
|
||||
while(!pq.empty())
|
||||
{
|
||||
counter++;
|
||||
auto node = topAndPop();
|
||||
auto * node = topAndPop();
|
||||
|
||||
source.setNode(gamestate, node);
|
||||
source.node->locked = true;
|
||||
@@ -346,7 +338,7 @@ void CPathfinder::calculatePaths()
|
||||
uint8_t turn = source.node->turns;
|
||||
float cost = source.node->getCost();
|
||||
|
||||
auto hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
||||
auto * hlp = config->getOrCreatePathfinderHelper(source, gamestate);
|
||||
|
||||
hlp->updateTurnInfo(turn);
|
||||
if(!movement)
|
||||
@@ -386,7 +378,7 @@ void CPathfinder::calculatePaths()
|
||||
destination.updateInfo(hlp, gamestate);
|
||||
destination.isGuardianTile = destination.guarded && isDestinationGuardian();
|
||||
|
||||
for(auto rule : config->rules)
|
||||
for(const auto & rule : config->rules)
|
||||
{
|
||||
rule->process(source, destination, config.get(), hlp);
|
||||
|
||||
@@ -439,17 +431,17 @@ void CPathfinder::calculatePaths()
|
||||
logAi->trace("CPathfinder finished with %s iterations", std::to_string(counter));
|
||||
}
|
||||
|
||||
std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(TeleportChannelID channelID) const
|
||||
std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(const TeleportChannelID & channelID) const
|
||||
{
|
||||
std::vector<int3> allowedExits;
|
||||
|
||||
for(auto objId : getTeleportChannelExits(channelID, hero->tempOwner))
|
||||
for(const auto & objId : getTeleportChannelExits(channelID, hero->tempOwner))
|
||||
{
|
||||
auto obj = getObj(objId);
|
||||
const auto * obj = getObj(objId);
|
||||
if(dynamic_cast<const CGWhirlpool *>(obj))
|
||||
{
|
||||
auto pos = obj->getBlockedPos();
|
||||
for(auto p : pos)
|
||||
for(const auto & p : pos)
|
||||
{
|
||||
if(gs->map->getTile(p).topVisitableId() == obj->ID)
|
||||
allowedExits.push_back(p);
|
||||
@@ -483,10 +475,10 @@ std::vector<int3> CPathfinderHelper::getTeleportExits(const PathNodeInfo & sourc
|
||||
{
|
||||
std::vector<int3> teleportationExits;
|
||||
|
||||
const CGTeleport * objTeleport = dynamic_cast<const CGTeleport *>(source.nodeObject);
|
||||
const auto * objTeleport = dynamic_cast<const CGTeleport *>(source.nodeObject);
|
||||
if(isAllowedTeleportEntrance(objTeleport))
|
||||
{
|
||||
for(auto exit : getAllowedTeleportChannelExits(objTeleport->channel))
|
||||
for(const auto & exit : getAllowedTeleportChannelExits(objTeleport->channel))
|
||||
{
|
||||
teleportationExits.push_back(exit);
|
||||
}
|
||||
@@ -497,7 +489,7 @@ std::vector<int3> CPathfinderHelper::getTeleportExits(const PathNodeInfo & sourc
|
||||
{
|
||||
/// TODO: Find way to reuse CPlayerSpecificInfoCallback::getTownsInfo
|
||||
/// This may be handy if we allow to use teleportation to friendly towns
|
||||
for(auto exit : getCastleGates(source))
|
||||
for(const auto & exit : getCastleGates(source))
|
||||
{
|
||||
teleportationExits.push_back(exit);
|
||||
}
|
||||
@@ -734,7 +726,7 @@ PathfinderBlockingRule::BlockingReason MovementAfterDestinationRule::getBlocking
|
||||
{
|
||||
/// For now we only add visitable tile into queue when it's teleporter that allow transit
|
||||
/// Movement from visitable tile when hero is standing on it is possible into any layer
|
||||
const CGTeleport * objTeleport = dynamic_cast<const CGTeleport *>(destination.nodeObject);
|
||||
const auto * objTeleport = dynamic_cast<const CGTeleport *>(destination.nodeObject);
|
||||
if(pathfinderHelper->isAllowedTeleportEntrance(objTeleport))
|
||||
{
|
||||
/// For now we'll always allow transit over teleporters
|
||||
@@ -798,7 +790,7 @@ void DestinationActionRule::process(
|
||||
}
|
||||
|
||||
CGPathNode::ENodeAction action = CGPathNode::NORMAL;
|
||||
auto hero = pathfinderHelper->hero;
|
||||
const auto * hero = pathfinderHelper->hero;
|
||||
|
||||
switch(destination.node->layer)
|
||||
{
|
||||
@@ -930,7 +922,7 @@ bool CPathfinderHelper::isAllowedTeleportEntrance(const CGTeleport * obj) const
|
||||
if(!obj || !isTeleportEntrancePassable(obj, hero->tempOwner))
|
||||
return false;
|
||||
|
||||
auto whirlpool = dynamic_cast<const CGWhirlpool *>(obj);
|
||||
const auto * whirlpool = dynamic_cast<const CGWhirlpool *>(obj);
|
||||
if(whirlpool)
|
||||
{
|
||||
if(addTeleportWhirlpool(whirlpool))
|
||||
@@ -989,16 +981,13 @@ bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
|
||||
return false;
|
||||
if(source.node->layer == EPathfindingLayer::AIR)
|
||||
{
|
||||
if(options.originalMovementRules && source.node->accessible == CGPathNode::ACCESSIBLE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return options.originalMovementRules && source.node->accessible == CGPathNode::ACCESSIBLE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TurnInfo::BonusCache::BonusCache(TConstBonusListPtr bl)
|
||||
TurnInfo::BonusCache::BonusCache(const TConstBonusListPtr & bl)
|
||||
{
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
||||
{
|
||||
@@ -1025,7 +1014,7 @@ TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn):
|
||||
nativeTerrain = hero->getNativeTerrain();
|
||||
}
|
||||
|
||||
bool TurnInfo::isLayerAvailable(const EPathfindingLayer layer) const
|
||||
bool TurnInfo::isLayerAvailable(const EPathfindingLayer & layer) const
|
||||
{
|
||||
switch(layer)
|
||||
{
|
||||
@@ -1078,7 +1067,7 @@ int TurnInfo::valOfBonuses(Bonus::BonusType type, int subtype) const
|
||||
return bonuses->valOfBonuses(Selector::type()(type).And(Selector::subtype()(subtype)));
|
||||
}
|
||||
|
||||
int TurnInfo::getMaxMovePoints(const EPathfindingLayer layer) const
|
||||
int TurnInfo::getMaxMovePoints(const EPathfindingLayer & layer) const
|
||||
{
|
||||
if(maxMovePointsLand == -1)
|
||||
maxMovePointsLand = hero->maxMovePointsCached(true, this);
|
||||
@@ -1121,7 +1110,7 @@ CPathfinderHelper::CPathfinderHelper(CGameState * gs, const CGHeroInstance * Her
|
||||
|
||||
CPathfinderHelper::~CPathfinderHelper()
|
||||
{
|
||||
for(auto ti : turnsInfo)
|
||||
for(auto * ti : turnsInfo)
|
||||
delete ti;
|
||||
}
|
||||
|
||||
@@ -1132,13 +1121,13 @@ void CPathfinderHelper::updateTurnInfo(const int Turn)
|
||||
turn = Turn;
|
||||
if(turn >= turnsInfo.size())
|
||||
{
|
||||
auto ti = new TurnInfo(hero, turn);
|
||||
auto * ti = new TurnInfo(hero, turn);
|
||||
turnsInfo.push_back(ti);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CPathfinderHelper::isLayerAvailable(const EPathfindingLayer layer) const
|
||||
bool CPathfinderHelper::isLayerAvailable(const EPathfindingLayer & layer) const
|
||||
{
|
||||
switch(layer)
|
||||
{
|
||||
@@ -1168,7 +1157,7 @@ bool CPathfinderHelper::hasBonusOfType(const Bonus::BonusType type, const int su
|
||||
return turnsInfo[turn]->hasBonusOfType(type, subtype);
|
||||
}
|
||||
|
||||
int CPathfinderHelper::getMaxMovePoints(const EPathfindingLayer layer) const
|
||||
int CPathfinderHelper::getMaxMovePoints(const EPathfindingLayer & layer) const
|
||||
{
|
||||
return turnsInfo[turn]->getMaxMovePoints(layer);
|
||||
}
|
||||
@@ -1188,7 +1177,7 @@ void CPathfinderHelper::getNeighbours(
|
||||
int3(-1, -1, +0), int3(0, -1, +0), int3(+1, -1, +0)
|
||||
};
|
||||
|
||||
for(auto & dir : dirs)
|
||||
for(const auto & dir : dirs)
|
||||
{
|
||||
const int3 hlp = tile + dir;
|
||||
if(!map->isInTheMap(hlp))
|
||||
@@ -1207,8 +1196,8 @@ void CPathfinderHelper::getNeighbours(
|
||||
/// Following condition let us avoid diagonal movement over coast when sailing
|
||||
if(srct.terType->isWater() && limitCoastSailing && hlpt.terType->isWater() && dir.x && dir.y) //diagonal move through water
|
||||
{
|
||||
int3 hlp1 = tile,
|
||||
hlp2 = tile;
|
||||
int3 hlp1 = tile;
|
||||
int3 hlp2 = tile;
|
||||
hlp1.x += dir.x;
|
||||
hlp2.y += dir.y;
|
||||
|
||||
@@ -1234,7 +1223,7 @@ int CPathfinderHelper::getMovementCost(
|
||||
if(src == dst) //same tile
|
||||
return 0;
|
||||
|
||||
auto ti = getTurnInfo();
|
||||
const auto * ti = getTurnInfo();
|
||||
|
||||
if(ct == nullptr || dt == nullptr)
|
||||
{
|
||||
@@ -1342,7 +1331,7 @@ bool CPathsInfo::getPath(CGPath & out, const int3 & dst) const
|
||||
|
||||
const CGPathNode * CPathsInfo::getNode(const int3 & coord) const
|
||||
{
|
||||
auto landNode = &nodes[ELayer::LAND][coord.z][coord.x][coord.y];
|
||||
const auto * landNode = &nodes[ELayer::LAND][coord.z][coord.x][coord.y];
|
||||
if(landNode->reachable())
|
||||
return landNode;
|
||||
else
|
||||
@@ -1401,8 +1390,7 @@ void PathNodeInfo::updateInfo(CPathfinderHelper * hlp, CGameState * gs)
|
||||
}
|
||||
}
|
||||
|
||||
CDestinationNodeInfo::CDestinationNodeInfo()
|
||||
: PathNodeInfo(),
|
||||
CDestinationNodeInfo::CDestinationNodeInfo():
|
||||
blocked(false),
|
||||
action(CGPathNode::ENodeAction::UNKNOWN)
|
||||
{
|
||||
|
@@ -412,7 +412,7 @@ private:
|
||||
CPathsInfo & out;
|
||||
|
||||
STRONG_INLINE
|
||||
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
|
||||
void resetTile(const int3 & tile, const EPathfindingLayer & layer, CGPathNode::EAccessibility accessibility);
|
||||
|
||||
public:
|
||||
NodeStorage(CPathsInfo & pathsInfo, const CGHeroInstance * hero);
|
||||
@@ -520,7 +520,7 @@ struct DLL_LINKAGE TurnInfo
|
||||
int waterWalkingVal;
|
||||
int pathfindingVal;
|
||||
|
||||
BonusCache(TConstBonusListPtr bonusList);
|
||||
BonusCache(const TConstBonusListPtr & bonusList);
|
||||
};
|
||||
std::unique_ptr<BonusCache> bonusCache;
|
||||
|
||||
@@ -532,11 +532,11 @@ struct DLL_LINKAGE TurnInfo
|
||||
int turn;
|
||||
|
||||
TurnInfo(const CGHeroInstance * Hero, const int Turn = 0);
|
||||
bool isLayerAvailable(const EPathfindingLayer layer) const;
|
||||
bool isLayerAvailable(const EPathfindingLayer & layer) const;
|
||||
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const;
|
||||
int valOfBonuses(const Bonus::BonusType type, const int subtype = -1) const;
|
||||
void updateHeroBonuses(Bonus::BonusType type, const CSelector& sel) const;
|
||||
int getMaxMovePoints(const EPathfindingLayer layer) const;
|
||||
int getMaxMovePoints(const EPathfindingLayer & layer) const;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CPathfinderHelper : private CGameInfoCallback
|
||||
@@ -562,14 +562,14 @@ public:
|
||||
bool isHeroPatrolLocked() const;
|
||||
bool isPatrolMovementAllowed(const int3 & dst) const;
|
||||
void updateTurnInfo(const int turn = 0);
|
||||
bool isLayerAvailable(const EPathfindingLayer layer) const;
|
||||
bool isLayerAvailable(const EPathfindingLayer & layer) const;
|
||||
const TurnInfo * getTurnInfo() const;
|
||||
bool hasBonusOfType(const Bonus::BonusType type, const int subtype = -1) const;
|
||||
int getMaxMovePoints(const EPathfindingLayer layer) const;
|
||||
int getMaxMovePoints(const EPathfindingLayer & layer) const;
|
||||
|
||||
std::vector<int3> getCastleGates(const PathNodeInfo & source) const;
|
||||
bool isAllowedTeleportEntrance(const CGTeleport * obj) const;
|
||||
std::vector<int3> getAllowedTeleportChannelExits(TeleportChannelID channelID) const;
|
||||
std::vector<int3> getAllowedTeleportChannelExits(const TeleportChannelID & channelID) const;
|
||||
bool addTeleportTwoWay(const CGTeleport * obj) const;
|
||||
bool addTeleportOneWay(const CGTeleport * obj) const;
|
||||
bool addTeleportOneWayRandom(const CGTeleport * obj) const;
|
||||
|
@@ -21,7 +21,7 @@ PlayerState::PlayerState()
|
||||
setNodeType(PLAYER);
|
||||
}
|
||||
|
||||
PlayerState::PlayerState(PlayerState && other):
|
||||
PlayerState::PlayerState(PlayerState && other) noexcept:
|
||||
CBonusSystemNode(std::move(other)),
|
||||
color(other.color),
|
||||
human(other.human),
|
||||
|
@@ -41,7 +41,7 @@ public:
|
||||
boost::optional<ui8> daysWithoutCastle;
|
||||
|
||||
PlayerState();
|
||||
PlayerState(PlayerState && other);
|
||||
PlayerState(PlayerState && other) noexcept;
|
||||
|
||||
std::string nodeName() const override;
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
std::shared_ptr<boost::multi_array<ui8, 3>> fogOfWarMap; //[z][x][y] true - visible, false - hidden
|
||||
|
||||
TeamState();
|
||||
TeamState(TeamState && other);
|
||||
TeamState(TeamState && other) noexcept;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@@ -29,7 +29,7 @@ void CRandomGenerator::resetSeed()
|
||||
{
|
||||
boost::hash<std::string> stringHash;
|
||||
auto threadIdHash = stringHash(boost::lexical_cast<std::string>(boost::this_thread::get_id()));
|
||||
setSeed((int)(threadIdHash * std::time(nullptr)));
|
||||
setSeed(static_cast<int>(threadIdHash * std::time(nullptr)));
|
||||
}
|
||||
|
||||
TRandI CRandomGenerator::getIntRange(int lower, int upper)
|
||||
@@ -83,7 +83,7 @@ CRandomGenerator & CRandomGenerator::getDefault()
|
||||
{
|
||||
defaultRand.reset(new CRandomGenerator());
|
||||
}
|
||||
return *defaultRand.get();
|
||||
return *defaultRand;
|
||||
}
|
||||
|
||||
TGenerator & CRandomGenerator::getStdGenerator()
|
||||
|
@@ -17,21 +17,10 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
namespace scripting
|
||||
{
|
||||
|
||||
ContextBase::ContextBase(vstd::CLoggerBase * logger_)
|
||||
: logger(logger_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ContextBase::~ContextBase() = default;
|
||||
|
||||
|
||||
Module::Module()
|
||||
ContextBase::ContextBase(vstd::CLoggerBase * logger_):
|
||||
logger(logger_)
|
||||
{
|
||||
}
|
||||
|
||||
Module::~Module() = default;
|
||||
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -29,7 +29,8 @@ class DLL_LINKAGE ContextBase : public Context
|
||||
{
|
||||
public:
|
||||
ContextBase(vstd::CLoggerBase * logger_);
|
||||
virtual ~ContextBase();
|
||||
virtual ~ContextBase() = default;
|
||||
|
||||
protected:
|
||||
vstd::CLoggerBase * logger;
|
||||
};
|
||||
@@ -37,8 +38,8 @@ protected:
|
||||
class DLL_LINKAGE Module
|
||||
{
|
||||
public:
|
||||
Module();
|
||||
virtual ~Module();
|
||||
Module() = default;
|
||||
virtual ~Module() = default;
|
||||
|
||||
virtual std::string compile(const std::string & name, const std::string & source, vstd::CLoggerBase * logger) const = 0;
|
||||
|
||||
|
@@ -24,26 +24,16 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
///CSkill
|
||||
CSkill::LevelInfo::LevelInfo()
|
||||
{
|
||||
}
|
||||
|
||||
CSkill::LevelInfo::~LevelInfo()
|
||||
{
|
||||
}
|
||||
|
||||
CSkill::CSkill(SecondarySkill id, std::string identifier, bool obligatoryMajor, bool obligatoryMinor)
|
||||
: id(id), identifier(identifier), obligatoryMajor(obligatoryMajor), obligatoryMinor(obligatoryMinor)
|
||||
CSkill::CSkill(const SecondarySkill & id, std::string identifier, bool obligatoryMajor, bool obligatoryMinor):
|
||||
id(id),
|
||||
identifier(std::move(identifier)),
|
||||
obligatoryMajor(obligatoryMajor),
|
||||
obligatoryMinor(obligatoryMinor)
|
||||
{
|
||||
gainChance[0] = gainChance[1] = 0; //affects CHeroClassHandler::afterLoadFinalization()
|
||||
levels.resize(NSecondarySkill::levels.size() - 1);
|
||||
}
|
||||
|
||||
CSkill::~CSkill()
|
||||
{
|
||||
}
|
||||
|
||||
int32_t CSkill::getIndex() const
|
||||
{
|
||||
return id.num;
|
||||
@@ -151,12 +141,7 @@ void CSkill::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
}
|
||||
|
||||
|
||||
///CSkillHandler
|
||||
CSkillHandler::CSkillHandler()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
|
||||
{
|
||||
CLegacyConfigParser parser("DATA/SSTRAITS.TXT");
|
||||
@@ -170,7 +155,7 @@ std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
|
||||
do
|
||||
{
|
||||
skillNames.push_back(parser.readString());
|
||||
skillInfoTexts.push_back(std::vector<std::string>());
|
||||
skillInfoTexts.emplace_back();
|
||||
for(int i = 0; i < 3; i++)
|
||||
skillInfoTexts.back().push_back(parser.readString());
|
||||
}
|
||||
@@ -211,7 +196,7 @@ CSkill * CSkillHandler::loadFromJson(const std::string & scope, const JsonNode &
|
||||
|
||||
major = json["obligatoryMajor"].Bool();
|
||||
minor = json["obligatoryMinor"].Bool();
|
||||
CSkill * skill = new CSkill(SecondarySkill((si32)index), identifier, major, minor);
|
||||
auto * skill = new CSkill(SecondarySkill((si32)index), identifier, major, minor);
|
||||
skill->modScope = scope;
|
||||
|
||||
VLC->generaltexth->registerString(scope, skill->getNameTextID(), json["name"].String());
|
||||
@@ -233,7 +218,7 @@ CSkill * CSkillHandler::loadFromJson(const std::string & scope, const JsonNode &
|
||||
const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert
|
||||
const JsonNode & levelNode = json[levelName];
|
||||
// parse bonus effects
|
||||
for(auto b : levelNode["effects"].Struct())
|
||||
for(const auto & b : levelNode["effects"].Struct())
|
||||
{
|
||||
auto bonus = JsonUtils::parseBonus(b.second);
|
||||
skill->addNewBonus(bonus, level);
|
||||
@@ -267,10 +252,6 @@ void CSkillHandler::beforeValidate(JsonNode & object)
|
||||
inheritNode("expert");
|
||||
}
|
||||
|
||||
CSkillHandler::~CSkillHandler()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<bool> CSkillHandler::getDefaultAllowed() const
|
||||
{
|
||||
std::vector<bool> allowedSkills(objects.size(), true);
|
||||
|
@@ -30,9 +30,6 @@ public:
|
||||
std::string iconLarge;
|
||||
std::vector<std::shared_ptr<Bonus>> effects;
|
||||
|
||||
LevelInfo();
|
||||
~LevelInfo();
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
h & iconSmall;
|
||||
@@ -51,8 +48,8 @@ private:
|
||||
std::string identifier;
|
||||
|
||||
public:
|
||||
CSkill(SecondarySkill id = SecondarySkill::DEFAULT, std::string identifier = "default", bool obligatoryMajor = false, bool obligatoryMinor = false);
|
||||
~CSkill();
|
||||
CSkill(const SecondarySkill & id = SecondarySkill::DEFAULT, std::string identifier = "default", bool obligatoryMajor = false, bool obligatoryMinor = false);
|
||||
~CSkill() = default;
|
||||
|
||||
enum class Obligatory : ui8
|
||||
{
|
||||
@@ -104,9 +101,6 @@ private:
|
||||
class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, Skill, CSkill, SkillService>
|
||||
{
|
||||
public:
|
||||
CSkillHandler();
|
||||
virtual ~CSkillHandler();
|
||||
|
||||
///IHandler base
|
||||
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
|
||||
void afterLoadFinalization() override;
|
||||
|
@@ -23,48 +23,35 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
///CStack
|
||||
CStack::CStack(const CStackInstance * Base, PlayerColor O, int I, ui8 Side, SlotID S)
|
||||
: CBonusSystemNode(STACK_BATTLE),
|
||||
CUnitState(),
|
||||
CStack::CStack(const CStackInstance * Base, const PlayerColor & O, int I, ui8 Side, const SlotID & S):
|
||||
CBonusSystemNode(STACK_BATTLE),
|
||||
base(Base),
|
||||
ID(I),
|
||||
type(Base->type),
|
||||
baseAmount(base->count),
|
||||
owner(O),
|
||||
slot(S),
|
||||
side(Side),
|
||||
initialPosition(),
|
||||
nativeTerrain()
|
||||
side(Side)
|
||||
{
|
||||
health.init(); //???
|
||||
}
|
||||
|
||||
CStack::CStack()
|
||||
: CBonusSystemNode(STACK_BATTLE),
|
||||
CUnitState(),
|
||||
nativeTerrain()
|
||||
CStack::CStack():
|
||||
CBonusSystemNode(STACK_BATTLE),
|
||||
owner(PlayerColor::NEUTRAL),
|
||||
slot(SlotID(255)),
|
||||
initialPosition(BattleHex())
|
||||
{
|
||||
base = nullptr;
|
||||
type = nullptr;
|
||||
ID = -1;
|
||||
baseAmount = -1;
|
||||
owner = PlayerColor::NEUTRAL;
|
||||
slot = SlotID(255);
|
||||
side = 1;
|
||||
initialPosition = BattleHex();
|
||||
}
|
||||
|
||||
CStack::CStack(const CStackBasicDescriptor * stack, PlayerColor O, int I, ui8 Side, SlotID S)
|
||||
: CBonusSystemNode(STACK_BATTLE),
|
||||
CUnitState(),
|
||||
base(nullptr),
|
||||
CStack::CStack(const CStackBasicDescriptor * stack, const PlayerColor & O, int I, ui8 Side, const SlotID & S):
|
||||
CBonusSystemNode(STACK_BATTLE),
|
||||
ID(I),
|
||||
type(stack->type),
|
||||
baseAmount(stack->count),
|
||||
owner(O),
|
||||
slot(S),
|
||||
side(Side),
|
||||
initialPosition()
|
||||
side(Side)
|
||||
{
|
||||
health.init(); //???
|
||||
}
|
||||
@@ -101,7 +88,7 @@ ui32 CStack::level() const
|
||||
if(base)
|
||||
return base->getLevel(); //creature or commander
|
||||
else
|
||||
return std::max(1, (int)getCreature()->level); //war machine, clone etc
|
||||
return std::max(1, static_cast<int>(getCreature()->level)); //war machine, clone etc
|
||||
}
|
||||
|
||||
si32 CStack::magicResistance() const
|
||||
@@ -110,7 +97,7 @@ si32 CStack::magicResistance() const
|
||||
|
||||
si32 auraBonus = 0;
|
||||
|
||||
for(auto one : battle->battleAdjacentUnits(this))
|
||||
for(const auto * one : battle->battleAdjacentUnits(this))
|
||||
{
|
||||
if(one->unitOwner() == owner)
|
||||
vstd::amax(auraBonus, one->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value
|
||||
@@ -197,7 +184,7 @@ void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand) const
|
||||
prepareAttacked(bsa, rand, newState);
|
||||
}
|
||||
|
||||
void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, std::shared_ptr<battle::CUnitState> customState)
|
||||
void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, const std::shared_ptr<battle::CUnitState> & customState)
|
||||
{
|
||||
auto initialCount = customState->getCount();
|
||||
|
||||
@@ -224,9 +211,9 @@ void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, std::s
|
||||
|
||||
double resurrectedRaw = baseAmount * resurrectFactor;
|
||||
|
||||
int32_t resurrectedCount = static_cast<int32_t>(floor(resurrectedRaw));
|
||||
auto resurrectedCount = static_cast<int32_t>(floor(resurrectedRaw));
|
||||
|
||||
int32_t resurrectedAdd = static_cast<int32_t>(baseAmount - (resurrectedCount/resurrectFactor));
|
||||
auto resurrectedAdd = static_cast<int32_t>(baseAmount - (resurrectedCount / resurrectFactor));
|
||||
|
||||
auto rangeGen = rand.getInt64Range(0, 99);
|
||||
|
||||
@@ -325,9 +312,7 @@ std::string CStack::getName() const
|
||||
|
||||
bool CStack::canBeHealed() const
|
||||
{
|
||||
return getFirstHPleft() < (int32_t)MaxHealth()
|
||||
&& isValidTarget()
|
||||
&& !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
||||
return getFirstHPleft() < static_cast<int32_t>(MaxHealth()) && isValidTarget() && !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
||||
}
|
||||
|
||||
bool CStack::isOnNativeTerrain() const
|
||||
@@ -362,7 +347,7 @@ bool CStack::unitHasAmmoCart(const battle::Unit * unit) const
|
||||
}
|
||||
}
|
||||
//ammo cart works during creature bank battle while not on battlefield
|
||||
auto ownerHero = battle->battleGetOwnerHero(unit);
|
||||
const auto * ownerHero = battle->battleGetOwnerHero(unit);
|
||||
if(ownerHero && ownerHero->artifactsWorn.find(ArtifactPosition::MACH2) != ownerHero->artifactsWorn.end())
|
||||
{
|
||||
if(battle->battleGetOwnerHero(unit)->artifactsWorn.at(ArtifactPosition::MACH2).artifact->artType->getId() == ArtifactID::AMMO_CART)
|
||||
|
18
lib/CStack.h
18
lib/CStack.h
@@ -26,20 +26,20 @@ class BattleInfo;
|
||||
class DLL_LINKAGE CStack : public CBonusSystemNode, public battle::CUnitState, public battle::IUnitEnvironment
|
||||
{
|
||||
public:
|
||||
const CStackInstance * base; //garrison slot from which stack originates (nullptr for war machines, summoned cres, etc)
|
||||
const CStackInstance * base = nullptr; //garrison slot from which stack originates (nullptr for war machines, summoned cres, etc)
|
||||
|
||||
ui32 ID; //unique ID of stack
|
||||
const CCreature * type;
|
||||
ui32 ID = -1; //unique ID of stack
|
||||
const CCreature * type = nullptr;
|
||||
TerrainId nativeTerrain; //tmp variable to save native terrain value on battle init
|
||||
ui32 baseAmount;
|
||||
ui32 baseAmount = -1;
|
||||
|
||||
PlayerColor owner; //owner - player color (255 for neutrals)
|
||||
SlotID slot; //slot - position in garrison (may be 255 for neutrals/called creatures)
|
||||
ui8 side;
|
||||
ui8 side = 1;
|
||||
BattleHex initialPosition; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
|
||||
|
||||
CStack(const CStackInstance * base, PlayerColor O, int I, ui8 Side, SlotID S);
|
||||
CStack(const CStackBasicDescriptor * stack, PlayerColor O, int I, ui8 Side, SlotID S = SlotID(255));
|
||||
CStack(const CStackInstance * base, const PlayerColor & O, int I, ui8 Side, const SlotID & S);
|
||||
CStack(const CStackBasicDescriptor * stack, const PlayerColor & O, int I, ui8 Side, const SlotID & S = SlotID(255));
|
||||
CStack();
|
||||
~CStack();
|
||||
|
||||
@@ -65,7 +65,9 @@ public:
|
||||
BattleHex::EDir destShiftDir() const;
|
||||
|
||||
void prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand) const; //requires bsa.damageAmout filled
|
||||
static void prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, std::shared_ptr<battle::CUnitState> customState); //requires bsa.damageAmout filled
|
||||
static void prepareAttacked(BattleStackAttacked & bsa,
|
||||
vstd::RNG & rand,
|
||||
const std::shared_ptr<battle::CUnitState> & customState); //requires bsa.damageAmout filled
|
||||
|
||||
const CCreature * unitType() const override;
|
||||
int32_t unitBaseAmount() const override;
|
||||
|
@@ -18,11 +18,12 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CThreadHelper::CThreadHelper(std::vector<std::function<void()> > *Tasks, int Threads)
|
||||
CThreadHelper::CThreadHelper(std::vector<std::function<void()>> * Tasks, int Threads):
|
||||
currentTask(0),
|
||||
amount(static_cast<int>(Tasks->size())),
|
||||
tasks(Tasks),
|
||||
threads(Threads)
|
||||
{
|
||||
currentTask = 0; amount = (int)Tasks->size();
|
||||
tasks = Tasks;
|
||||
threads = Threads;
|
||||
}
|
||||
void CThreadHelper::run()
|
||||
{
|
||||
|
@@ -80,7 +80,7 @@ BuildingID CBuilding::getBase() const
|
||||
return build->bid;
|
||||
}
|
||||
|
||||
si32 CBuilding::getDistance(BuildingID buildID) const
|
||||
si32 CBuilding::getDistance(const BuildingID & buildID) const
|
||||
{
|
||||
const CBuilding * build = town->buildings.at(buildID);
|
||||
int distance = 0;
|
||||
@@ -94,19 +94,11 @@ si32 CBuilding::getDistance(BuildingID buildID) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CBuilding::addNewBonus(std::shared_ptr<Bonus> b, BonusList & bonusList)
|
||||
void CBuilding::addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const
|
||||
{
|
||||
bonusList.push_back(b);
|
||||
}
|
||||
|
||||
CFaction::CFaction()
|
||||
{
|
||||
town = nullptr;
|
||||
index = 0;
|
||||
alignment = EAlignment::NEUTRAL;
|
||||
preferUndergroundPlacement = false;
|
||||
}
|
||||
|
||||
CFaction::~CFaction()
|
||||
{
|
||||
delete town;
|
||||
@@ -241,24 +233,24 @@ const CBuilding * CTown::getSpecialBuilding(BuildingSubID::EBuildingSubID subID)
|
||||
|
||||
BuildingID::EBuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const
|
||||
{
|
||||
auto building = getSpecialBuilding(subID);
|
||||
const auto * building = getSpecialBuilding(subID);
|
||||
return building == nullptr ? BuildingID::NONE : building->bid.num;
|
||||
}
|
||||
|
||||
const std::string CTown::getGreeting(BuildingSubID::EBuildingSubID subID) const
|
||||
std::string CTown::getGreeting(BuildingSubID::EBuildingSubID subID) const
|
||||
{
|
||||
return VLC->townh->getMappedValue<const std::string, BuildingSubID::EBuildingSubID>(subID, std::string(), specialMessages, false);
|
||||
return CTownHandler::getMappedValue<const std::string, BuildingSubID::EBuildingSubID>(subID, std::string(), specialMessages, false);
|
||||
}
|
||||
|
||||
void CTown::setGreeting(BuildingSubID::EBuildingSubID subID, const std::string message) const
|
||||
void CTown::setGreeting(BuildingSubID::EBuildingSubID subID, const std::string & message) const
|
||||
{
|
||||
specialMessages.insert(std::pair<BuildingSubID::EBuildingSubID, const std::string>(subID, message));
|
||||
}
|
||||
|
||||
CTownHandler::CTownHandler()
|
||||
CTownHandler::CTownHandler():
|
||||
randomTown(new CTown()),
|
||||
randomFaction(new CFaction())
|
||||
{
|
||||
randomTown = new CTown();
|
||||
randomFaction = new CFaction();
|
||||
randomFaction->town = randomTown;
|
||||
randomTown->faction = randomFaction;
|
||||
randomFaction->identifier = "random";
|
||||
@@ -446,7 +438,7 @@ std::vector<JsonNode> CTownHandler::loadLegacyData(size_t dataSize)
|
||||
return dest;
|
||||
}
|
||||
|
||||
void CTownHandler::loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad)
|
||||
void CTownHandler::loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad) const
|
||||
{
|
||||
if (source.isNull())
|
||||
return;
|
||||
@@ -479,7 +471,7 @@ R CTownHandler::getMappedValue(const JsonNode & node, const R defval, const std:
|
||||
return defval;
|
||||
}
|
||||
|
||||
void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building)
|
||||
void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
|
||||
{
|
||||
std::shared_ptr<Bonus> b;
|
||||
static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
|
||||
@@ -529,19 +521,24 @@ void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building)
|
||||
building->addNewBonus(b, building->buildingBonuses);
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, Bonus::BonusType type, int val, int subtype)
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, Bonus::BonusType type, int val, int subtype) const
|
||||
{
|
||||
return createBonus(build, type, val, emptyPropagator(), subtype);
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype)
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype) const
|
||||
{
|
||||
std::ostringstream descr;
|
||||
descr << build->getNameTranslated();
|
||||
return createBonusImpl(build->bid, type, val, prop, descr.str(), subtype);
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonusImpl(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr & prop, const std::string & description, int subtype)
|
||||
std::shared_ptr<Bonus> CTownHandler::createBonusImpl(const BuildingID & building,
|
||||
Bonus::BonusType type,
|
||||
int val,
|
||||
TPropagatorPtr & prop,
|
||||
const std::string & description,
|
||||
int subtype) const
|
||||
{
|
||||
auto b = std::make_shared<Bonus>(Bonus::PERMANENT, type, Bonus::TOWN_STRUCTURE, val, building, description, subtype);
|
||||
|
||||
@@ -553,7 +550,7 @@ std::shared_ptr<Bonus> CTownHandler::createBonusImpl(BuildingID building, Bonus:
|
||||
|
||||
void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building)
|
||||
{
|
||||
for(auto b : source.Vector())
|
||||
for(const auto & b : source.Vector())
|
||||
{
|
||||
auto bonus = JsonUtils::parseBuildingBonus(b, building->bid, building->getNameTranslated());
|
||||
|
||||
@@ -562,10 +559,10 @@ void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList
|
||||
|
||||
if(bonus->limiter != nullptr)
|
||||
{
|
||||
auto limPtr = dynamic_cast<CreatureFactionLimiter*>(bonus->limiter.get());
|
||||
auto * limPtr = dynamic_cast<CreatureFactionLimiter *>(bonus->limiter.get());
|
||||
|
||||
if(limPtr != nullptr && limPtr->faction == (TFaction)-1)
|
||||
limPtr->faction = building->town->faction->getIndex();
|
||||
if(limPtr != nullptr && limPtr->faction == static_cast<TFaction>(-1))
|
||||
limPtr->faction = building->town->faction->getIndex();
|
||||
}
|
||||
//JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty.
|
||||
if(bonus->propagator != nullptr
|
||||
@@ -580,7 +577,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
|
||||
assert(stringID.find(':') == std::string::npos);
|
||||
assert(!source.meta.empty());
|
||||
|
||||
auto ret = new CBuilding();
|
||||
auto * ret = new CBuilding();
|
||||
ret->bid = getMappedValue<BuildingID, std::string>(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false);
|
||||
|
||||
if(ret->bid == BuildingID::NONE)
|
||||
@@ -686,7 +683,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
|
||||
|
||||
void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
|
||||
{
|
||||
for(auto & node : source.Struct())
|
||||
for(const auto & node : source.Struct())
|
||||
{
|
||||
if (!node.second.isNull())
|
||||
{
|
||||
@@ -695,9 +692,9 @@ void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
|
||||
}
|
||||
}
|
||||
|
||||
void CTownHandler::loadStructure(CTown &town, const std::string & stringID, const JsonNode & source)
|
||||
void CTownHandler::loadStructure(CTown &town, const std::string & stringID, const JsonNode & source) const
|
||||
{
|
||||
auto ret = new CStructure();
|
||||
auto * ret = new CStructure();
|
||||
|
||||
ret->building = nullptr;
|
||||
ret->buildable = nullptr;
|
||||
@@ -732,40 +729,40 @@ void CTownHandler::loadStructure(CTown &town, const std::string & stringID, cons
|
||||
ret->borderName = source["border"].String();
|
||||
ret->areaName = source["area"].String();
|
||||
|
||||
town.clientInfo.structures.push_back(ret);
|
||||
town.clientInfo.structures.emplace_back(ret);
|
||||
}
|
||||
|
||||
void CTownHandler::loadStructures(CTown &town, const JsonNode & source)
|
||||
void CTownHandler::loadStructures(CTown &town, const JsonNode & source) const
|
||||
{
|
||||
for(auto &node : source.Struct())
|
||||
for(const auto & node : source.Struct())
|
||||
{
|
||||
if (!node.second.isNull())
|
||||
loadStructure(town, node.first, node.second);
|
||||
}
|
||||
}
|
||||
|
||||
void CTownHandler::loadTownHall(CTown &town, const JsonNode & source)
|
||||
void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) const
|
||||
{
|
||||
auto & dstSlots = town.clientInfo.hallSlots;
|
||||
auto & srcSlots = source.Vector();
|
||||
const auto & srcSlots = source.Vector();
|
||||
dstSlots.resize(srcSlots.size());
|
||||
|
||||
for(size_t i=0; i<dstSlots.size(); i++)
|
||||
{
|
||||
auto & dstRow = dstSlots[i];
|
||||
auto & srcRow = srcSlots[i].Vector();
|
||||
const auto & srcRow = srcSlots[i].Vector();
|
||||
dstRow.resize(srcRow.size());
|
||||
|
||||
for(size_t j=0; j < dstRow.size(); j++)
|
||||
{
|
||||
auto & dstBox = dstRow[j];
|
||||
auto & srcBox = srcRow[j].Vector();
|
||||
const auto & srcBox = srcRow[j].Vector();
|
||||
dstBox.resize(srcBox.size());
|
||||
|
||||
for(size_t k=0; k<dstBox.size(); k++)
|
||||
{
|
||||
auto & dst = dstBox[k];
|
||||
auto & src = srcBox[k];
|
||||
const auto & src = srcBox[k];
|
||||
|
||||
VLC->modh->identifiers.requestIdentifier("building." + town.faction->getJsonKey(), src, [&](si32 identifier)
|
||||
{
|
||||
@@ -784,7 +781,7 @@ Point JsonToPoint(const JsonNode & node)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source)
|
||||
void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source) const
|
||||
{
|
||||
town.clientInfo.siegePrefix = source["imagePrefix"].String();
|
||||
town.clientInfo.towerIconSmall = source["towerIconSmall"].String();
|
||||
@@ -793,7 +790,7 @@ void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source)
|
||||
VLC->modh->identifiers.requestIdentifier("creature", source["shooter"], [&town](si32 creature)
|
||||
{
|
||||
auto crId = CreatureID(creature);
|
||||
if(!(*VLC->creh)[crId]->animation.missleFrameAngles.size())
|
||||
if((*VLC->creh)[crId]->animation.missleFrameAngles.empty())
|
||||
logMod->error("Mod '%s' error: Creature '%s' on the Archer's tower is not a shooter. Mod should be fixed. Siege will not work properly!"
|
||||
, town.faction->getNameTranslated()
|
||||
, (*VLC->creh)[crId]->getNameSingularTranslated());
|
||||
@@ -841,7 +838,7 @@ static void readIcon(JsonNode source, std::string & small, std::string & large)
|
||||
}
|
||||
}
|
||||
|
||||
void CTownHandler::loadClientData(CTown &town, const JsonNode & source)
|
||||
void CTownHandler::loadClientData(CTown &town, const JsonNode & source) const
|
||||
{
|
||||
CTown::ClientInfo & info = town.clientInfo;
|
||||
|
||||
@@ -874,7 +871,7 @@ void CTownHandler::loadClientData(CTown &town, const JsonNode & source)
|
||||
|
||||
void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
{
|
||||
auto resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String());
|
||||
const auto * resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String());
|
||||
if(resIter == std::end(GameConstants::RESOURCE_NAMES))
|
||||
town->primaryRes = Res::WOOD_AND_ORE; //Wood + Ore
|
||||
else
|
||||
@@ -888,7 +885,7 @@ void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
town->mageLevel = static_cast<ui32>(source["mageGuild"].Float());
|
||||
|
||||
town->namesCount = 0;
|
||||
for (auto const & name : source["names"].Vector())
|
||||
for(const auto & name : source["names"].Vector())
|
||||
{
|
||||
VLC->generaltexth->registerString(town->faction->modScope, town->getRandomNameTextID(town->namesCount), name.String());
|
||||
town->namesCount += 1;
|
||||
@@ -896,12 +893,12 @@ void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
|
||||
// Horde building creature level
|
||||
for(const JsonNode &node : source["horde"].Vector())
|
||||
town->hordeLvl[(int)town->hordeLvl.size()] = static_cast<int>(node.Float());
|
||||
town->hordeLvl[static_cast<int>(town->hordeLvl.size())] = static_cast<int>(node.Float());
|
||||
|
||||
// town needs to have exactly 2 horde entries. Validation will take care of 2+ entries
|
||||
// but anything below 2 must be handled here
|
||||
for (size_t i=source["horde"].Vector().size(); i<2; i++)
|
||||
town->hordeLvl[(int)i] = -1;
|
||||
town->hordeLvl[static_cast<int>(i)] = -1;
|
||||
|
||||
const JsonVector & creatures = source["creatures"].Vector();
|
||||
|
||||
@@ -924,7 +921,7 @@ void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
|
||||
town->defaultTavernChance = static_cast<ui32>(source["defaultTavern"].Float());
|
||||
/// set chance of specific hero class to appear in this town
|
||||
for(auto &node : source["tavern"].Struct())
|
||||
for(const auto & node : source["tavern"].Struct())
|
||||
{
|
||||
int chance = static_cast<int>(node.second.Float());
|
||||
|
||||
@@ -934,7 +931,7 @@ void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
});
|
||||
}
|
||||
|
||||
for(auto &node : source["guildSpells"].Struct())
|
||||
for(const auto & node : source["guildSpells"].Struct())
|
||||
{
|
||||
int chance = static_cast<int>(node.second.Float());
|
||||
|
||||
@@ -954,7 +951,7 @@ void CTownHandler::loadTown(CTown * town, const JsonNode & source)
|
||||
loadClientData(*town, source);
|
||||
}
|
||||
|
||||
void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source)
|
||||
void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source) const
|
||||
{
|
||||
faction.puzzleMap.reserve(GameConstants::PUZZLE_MAP_PIECES);
|
||||
|
||||
@@ -984,7 +981,7 @@ CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
|
||||
auto faction = new CFaction();
|
||||
auto * faction = new CFaction();
|
||||
|
||||
faction->index = static_cast<TFaction>(index);
|
||||
faction->modScope = scope;
|
||||
@@ -1033,9 +1030,9 @@ CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode
|
||||
|
||||
void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(scope, data, name, objects.size());
|
||||
auto * object = loadFromJson(scope, data, name, objects.size());
|
||||
|
||||
objects.push_back(object);
|
||||
objects.emplace_back(object);
|
||||
|
||||
if (object->town)
|
||||
{
|
||||
@@ -1056,7 +1053,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
|
||||
VLC->objtypeh->loadSubObject(object->identifier, config, index, object->index);
|
||||
|
||||
// MODS COMPATIBILITY FOR 0.96
|
||||
auto & advMap = data["town"]["adventureMap"];
|
||||
const auto & advMap = data["town"]["adventureMap"];
|
||||
if (!advMap.isNull())
|
||||
{
|
||||
logMod->warn("Outdated town mod. Will try to generate valid templates out of fort");
|
||||
@@ -1072,7 +1069,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
|
||||
|
||||
void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(scope, data, name, index);
|
||||
auto * object = loadFromJson(scope, data, name, index);
|
||||
|
||||
if (objects.size() > index)
|
||||
assert(objects[index] == nullptr); // ensure that this id was not loaded before
|
||||
@@ -1148,7 +1145,7 @@ void CTownHandler::initializeOverridden()
|
||||
auto jsonNode = bidHelper.json;
|
||||
auto scope = bidHelper.town->getBuildingScope();
|
||||
|
||||
for(auto b : jsonNode.Vector())
|
||||
for(const auto & b : jsonNode.Vector())
|
||||
{
|
||||
auto bid = BuildingID(VLC->modh->identifiers.getIdentifier(scope, b).get());
|
||||
bidHelper.building->overrideBids.insert(bid);
|
||||
@@ -1181,6 +1178,7 @@ void CTownHandler::initializeWarMachines()
|
||||
std::vector<bool> CTownHandler::getDefaultAllowed() const
|
||||
{
|
||||
std::vector<bool> allowedFactions;
|
||||
allowedFactions.reserve(objects.size());
|
||||
for(auto town : objects)
|
||||
{
|
||||
allowedFactions.push_back(town->town != nullptr);
|
||||
@@ -1199,7 +1197,7 @@ std::set<TFaction> CTownHandler::getAllowedFactions(bool withTown) const
|
||||
|
||||
for (size_t i=0; i<allowed.size(); i++)
|
||||
if (allowed[i])
|
||||
allowedFactions.insert((TFaction)i);
|
||||
allowedFactions.insert(static_cast<TFaction>(i));
|
||||
|
||||
return allowedFactions;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public:
|
||||
BuildingID getBase() const;
|
||||
|
||||
// returns how many times build has to be upgraded to become build
|
||||
si32 getDistance(BuildingID build) const;
|
||||
si32 getDistance(const BuildingID & build) const;
|
||||
|
||||
STRONG_INLINE
|
||||
bool IsTradeBuilding() const
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
subId == BuildingSubID::CUSTOM_VISITING_BONUS;
|
||||
}
|
||||
|
||||
void addNewBonus(std::shared_ptr<Bonus> b, BonusList & bonusList);
|
||||
void addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@@ -190,21 +190,21 @@ class DLL_LINKAGE CFaction : public Faction
|
||||
std::string modScope;
|
||||
std::string identifier;
|
||||
|
||||
TFaction index;
|
||||
TFaction index = 0;
|
||||
|
||||
public:
|
||||
TerrainId nativeTerrain;
|
||||
EAlignment::EAlignment alignment;
|
||||
bool preferUndergroundPlacement;
|
||||
EAlignment::EAlignment alignment = EAlignment::NEUTRAL;
|
||||
bool preferUndergroundPlacement = false;
|
||||
|
||||
CTown * town; //NOTE: can be null
|
||||
CTown * town = nullptr; //NOTE: can be null
|
||||
|
||||
std::string creatureBg120;
|
||||
std::string creatureBg130;
|
||||
|
||||
std::vector<SPuzzleInfo> puzzleMap;
|
||||
|
||||
CFaction();
|
||||
CFaction() = default;
|
||||
~CFaction();
|
||||
|
||||
int32_t getIndex() const override;
|
||||
@@ -238,7 +238,7 @@ public:
|
||||
class DLL_LINKAGE CTown
|
||||
{
|
||||
friend class CTownHandler;
|
||||
size_t namesCount;
|
||||
size_t namesCount = 0;
|
||||
|
||||
public:
|
||||
CTown();
|
||||
@@ -247,8 +247,8 @@ public:
|
||||
std::string getBuildingScope() const;
|
||||
std::set<si32> getAllBuildings() const;
|
||||
const CBuilding * getSpecialBuilding(BuildingSubID::EBuildingSubID subID) const;
|
||||
const std::string getGreeting(BuildingSubID::EBuildingSubID subID) const;
|
||||
void setGreeting(BuildingSubID::EBuildingSubID subID, const std::string message) const; //may affect only mutable field
|
||||
std::string getGreeting(BuildingSubID::EBuildingSubID subID) const;
|
||||
void setGreeting(BuildingSubID::EBuildingSubID subID, const std::string & message) const; //may affect only mutable field
|
||||
BuildingID::EBuildingID getBuildingType(BuildingSubID::EBuildingSubID subID) const;
|
||||
|
||||
std::string getRandomNameTranslated(size_t index) const;
|
||||
@@ -369,27 +369,32 @@ class DLL_LINKAGE CTownHandler : public CHandlerBase<FactionID, Faction, CFactio
|
||||
void initializeWarMachines();
|
||||
|
||||
/// loads CBuilding's into town
|
||||
void loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad);
|
||||
void loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad) const;
|
||||
void loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source);
|
||||
void loadBuildings(CTown * town, const JsonNode & source);
|
||||
|
||||
std::shared_ptr<Bonus> createBonus(CBuilding * build, Bonus::BonusType type, int val, int subtype = -1);
|
||||
std::shared_ptr<Bonus> createBonus(CBuilding * build, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype = -1);
|
||||
std::shared_ptr<Bonus> createBonusImpl(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr & prop, const std::string & description, int subtype = -1);
|
||||
std::shared_ptr<Bonus> createBonus(CBuilding * build, Bonus::BonusType type, int val, int subtype = -1) const;
|
||||
std::shared_ptr<Bonus> createBonus(CBuilding * build, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype = -1) const;
|
||||
std::shared_ptr<Bonus> createBonusImpl(const BuildingID & building,
|
||||
Bonus::BonusType type,
|
||||
int val,
|
||||
TPropagatorPtr & prop,
|
||||
const std::string & description,
|
||||
int subtype = -1) const;
|
||||
|
||||
/// loads CStructure's into town
|
||||
void loadStructure(CTown &town, const std::string & stringID, const JsonNode & source);
|
||||
void loadStructures(CTown &town, const JsonNode & source);
|
||||
void loadStructure(CTown & town, const std::string & stringID, const JsonNode & source) const;
|
||||
void loadStructures(CTown & town, const JsonNode & source) const;
|
||||
|
||||
/// loads town hall vector (hallSlots)
|
||||
void loadTownHall(CTown &town, const JsonNode & source);
|
||||
void loadSiegeScreen(CTown &town, const JsonNode & source);
|
||||
void loadTownHall(CTown & town, const JsonNode & source) const;
|
||||
void loadSiegeScreen(CTown & town, const JsonNode & source) const;
|
||||
|
||||
void loadClientData(CTown &town, const JsonNode & source);
|
||||
void loadClientData(CTown & town, const JsonNode & source) const;
|
||||
|
||||
void loadTown(CTown * town, const JsonNode & source);
|
||||
|
||||
void loadPuzzle(CFaction & faction, const JsonNode & source);
|
||||
void loadPuzzle(CFaction & faction, const JsonNode & source) const;
|
||||
|
||||
void loadRandomFaction();
|
||||
|
||||
@@ -410,7 +415,7 @@ public:
|
||||
|
||||
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
||||
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
||||
void addBonusesForVanilaBuilding(CBuilding * building);
|
||||
void addBonusesForVanilaBuilding(CBuilding * building) const;
|
||||
|
||||
void loadCustom() override;
|
||||
void afterLoadFinalization() override;
|
||||
|
@@ -126,7 +126,7 @@ const CSpell * SpellID::toSpell() const
|
||||
{
|
||||
if(num < 0 || num >= VLC->spellh->objects.size())
|
||||
{
|
||||
logGlobal->error("Unable to get spell of invalid ID %d", int(num));
|
||||
logGlobal->error("Unable to get spell of invalid ID %d", static_cast<int>(num));
|
||||
return nullptr;
|
||||
}
|
||||
return VLC->spellh->objects[*this];
|
||||
@@ -239,7 +239,7 @@ std::ostream & operator<<(std::ostream & os, const EActionType actionType)
|
||||
else return os << it->second;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer)
|
||||
std::ostream & operator<<(std::ostream & os, const EPathfindingLayer & pathfindingLayer)
|
||||
{
|
||||
static const std::map<EPathfindingLayer::EEPathfindingLayer, std::string> pathfinderLayerToString
|
||||
{
|
||||
@@ -286,7 +286,7 @@ const BattleFieldInfo * BattleField::getInfo() const
|
||||
return VLC->battlefields()->getById(*this);
|
||||
}
|
||||
|
||||
BattleField BattleField::fromString(std::string identifier)
|
||||
BattleField BattleField::fromString(const std::string & identifier)
|
||||
{
|
||||
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "battlefield", identifier);
|
||||
|
||||
@@ -306,7 +306,7 @@ Obstacle::operator std::string() const
|
||||
return getInfo()->identifier;
|
||||
}
|
||||
|
||||
Obstacle Obstacle::fromString(std::string identifier)
|
||||
Obstacle Obstacle::fromString(const std::string & identifier)
|
||||
{
|
||||
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "obstacle", identifier);
|
||||
|
||||
|
@@ -997,7 +997,7 @@ public:
|
||||
EEPathfindingLayer num;
|
||||
};
|
||||
|
||||
DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer);
|
||||
DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EPathfindingLayer & pathfindingLayer);
|
||||
|
||||
ID_LIKE_OPERATORS(EPathfindingLayer, EPathfindingLayer::EEPathfindingLayer)
|
||||
|
||||
@@ -1216,7 +1216,7 @@ class BattleField : public BaseForID<BattleField, si32>
|
||||
DLL_LINKAGE operator std::string() const;
|
||||
DLL_LINKAGE const BattleFieldInfo * getInfo() const;
|
||||
|
||||
DLL_LINKAGE static BattleField fromString(std::string identifier);
|
||||
DLL_LINKAGE static BattleField fromString(const std::string & identifier);
|
||||
};
|
||||
|
||||
enum class ETerrainId {
|
||||
@@ -1248,7 +1248,7 @@ class Obstacle : public BaseForID<Obstacle, si32>
|
||||
|
||||
DLL_LINKAGE const ObstacleInfo * getInfo() const;
|
||||
DLL_LINKAGE operator std::string() const;
|
||||
DLL_LINKAGE static Obstacle fromString(std::string identifier);
|
||||
DLL_LINKAGE static Obstacle fromString(const std::string & identifier);
|
||||
};
|
||||
|
||||
enum class ESpellSchool: ui8
|
||||
|
@@ -118,34 +118,28 @@ const std::set<std::string> deprecatedBonusSet = {
|
||||
};
|
||||
|
||||
///CBonusProxy
|
||||
CBonusProxy::CBonusProxy(const IBonusBearer * Target, CSelector Selector)
|
||||
: bonusListCachedLast(0),
|
||||
CBonusProxy::CBonusProxy(const IBonusBearer * Target, CSelector Selector):
|
||||
bonusListCachedLast(0),
|
||||
target(Target),
|
||||
selector(Selector),
|
||||
bonusList(),
|
||||
currentBonusListIndex(0),
|
||||
swapGuard()
|
||||
selector(std::move(Selector)),
|
||||
currentBonusListIndex(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CBonusProxy::CBonusProxy(const CBonusProxy & other)
|
||||
: bonusListCachedLast(other.bonusListCachedLast),
|
||||
CBonusProxy::CBonusProxy(const CBonusProxy & other):
|
||||
bonusListCachedLast(other.bonusListCachedLast),
|
||||
target(other.target),
|
||||
selector(other.selector),
|
||||
currentBonusListIndex(other.currentBonusListIndex),
|
||||
swapGuard()
|
||||
currentBonusListIndex(other.currentBonusListIndex)
|
||||
{
|
||||
bonusList[currentBonusListIndex] = other.bonusList[currentBonusListIndex];
|
||||
}
|
||||
|
||||
CBonusProxy::CBonusProxy(CBonusProxy && other)
|
||||
: bonusListCachedLast(0),
|
||||
CBonusProxy::CBonusProxy(CBonusProxy && other) noexcept:
|
||||
bonusListCachedLast(0),
|
||||
target(other.target),
|
||||
selector(),
|
||||
bonusList(),
|
||||
currentBonusListIndex(0),
|
||||
swapGuard()
|
||||
currentBonusListIndex(0)
|
||||
{
|
||||
std::swap(bonusListCachedLast, other.bonusListCachedLast);
|
||||
std::swap(selector, other.selector);
|
||||
@@ -164,7 +158,7 @@ CBonusProxy & CBonusProxy::operator=(const CBonusProxy & other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBonusProxy & CBonusProxy::operator=(CBonusProxy && other)
|
||||
CBonusProxy & CBonusProxy::operator=(CBonusProxy && other) noexcept
|
||||
{
|
||||
std::swap(bonusListCachedLast, other.bonusListCachedLast);
|
||||
std::swap(selector, other.selector);
|
||||
@@ -180,7 +174,7 @@ void CBonusProxy::swapBonusList(TConstBonusListPtr other) const
|
||||
// Because such use of shared ptr is not thread safe
|
||||
// So to avoid this we change the second offline instance and swap active index
|
||||
auto newCurrent = 1 - currentBonusListIndex;
|
||||
bonusList[newCurrent] = other;
|
||||
bonusList[newCurrent] = std::move(other);
|
||||
currentBonusListIndex = newCurrent;
|
||||
}
|
||||
|
||||
@@ -212,15 +206,13 @@ const BonusList * CBonusProxy::operator->() const
|
||||
return getBonusList().get();
|
||||
}
|
||||
|
||||
CTotalsProxy::CTotalsProxy(const IBonusBearer * Target, CSelector Selector, int InitialValue)
|
||||
: CBonusProxy(Target, Selector),
|
||||
CTotalsProxy::CTotalsProxy(const IBonusBearer * Target, CSelector Selector, int InitialValue):
|
||||
CBonusProxy(Target, std::move(Selector)),
|
||||
initialValue(InitialValue),
|
||||
meleeCachedLast(0),
|
||||
meleeValue(0),
|
||||
rangedCachedLast(0),
|
||||
rangedValue(0),
|
||||
value(0),
|
||||
valueCachedLast(0)
|
||||
rangedValue(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -234,20 +226,6 @@ CTotalsProxy::CTotalsProxy(const CTotalsProxy & other)
|
||||
{
|
||||
}
|
||||
|
||||
CTotalsProxy & CTotalsProxy::operator=(const CTotalsProxy & other)
|
||||
{
|
||||
CBonusProxy::operator=(other);
|
||||
initialValue = other.initialValue;
|
||||
meleeCachedLast = other.meleeCachedLast;
|
||||
meleeValue = other.meleeValue;
|
||||
rangedCachedLast = other.rangedCachedLast;
|
||||
rangedValue = other.rangedValue;
|
||||
value = other.value;
|
||||
valueCachedLast = other.valueCachedLast;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int CTotalsProxy::getValue() const
|
||||
{
|
||||
const auto treeVersion = target->getTreeVersion();
|
||||
@@ -308,21 +286,16 @@ int CTotalsProxy::getRangedValue() const
|
||||
}
|
||||
|
||||
///CCheckProxy
|
||||
CCheckProxy::CCheckProxy(const IBonusBearer * Target, CSelector Selector)
|
||||
: target(Target),
|
||||
selector(Selector),
|
||||
CCheckProxy::CCheckProxy(const IBonusBearer * Target, CSelector Selector):
|
||||
target(Target),
|
||||
selector(std::move(Selector)),
|
||||
cachedLast(0),
|
||||
hasBonus(false)
|
||||
{
|
||||
}
|
||||
|
||||
CCheckProxy::CCheckProxy(const CCheckProxy & other)
|
||||
: target(other.target),
|
||||
selector(other.selector),
|
||||
cachedLast(other.cachedLast),
|
||||
hasBonus(other.hasBonus)
|
||||
{
|
||||
}
|
||||
//This constructor should be placed here to avoid side effects
|
||||
CCheckProxy::CCheckProxy(const CCheckProxy & other) = default;
|
||||
|
||||
bool CCheckProxy::getHasBonus() const
|
||||
{
|
||||
@@ -337,9 +310,8 @@ bool CCheckProxy::getHasBonus() const
|
||||
return hasBonus;
|
||||
}
|
||||
|
||||
CAddInfo::CAddInfo()
|
||||
{
|
||||
}
|
||||
//This constructor should be placed here to avoid side effects
|
||||
CAddInfo::CAddInfo() = default;
|
||||
|
||||
CAddInfo::CAddInfo(si32 value)
|
||||
{
|
||||
@@ -405,15 +377,13 @@ BonusList::BonusList(bool BelongsToTree) : belongsToTree(BelongsToTree)
|
||||
|
||||
}
|
||||
|
||||
BonusList::BonusList(const BonusList &bonusList)
|
||||
BonusList::BonusList(const BonusList & bonusList): belongsToTree(false)
|
||||
{
|
||||
bonuses.resize(bonusList.size());
|
||||
std::copy(bonusList.begin(), bonusList.end(), bonuses.begin());
|
||||
belongsToTree = false;
|
||||
}
|
||||
|
||||
BonusList::BonusList(BonusList&& other):
|
||||
belongsToTree(false)
|
||||
BonusList::BonusList(BonusList && other) noexcept: belongsToTree(false)
|
||||
{
|
||||
std::swap(belongsToTree, other.belongsToTree);
|
||||
std::swap(bonuses, other.bonuses);
|
||||
@@ -427,7 +397,7 @@ BonusList& BonusList::operator=(const BonusList &bonusList)
|
||||
return *this;
|
||||
}
|
||||
|
||||
void BonusList::changed()
|
||||
void BonusList::changed() const
|
||||
{
|
||||
if(belongsToTree)
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
@@ -435,7 +405,7 @@ void BonusList::changed()
|
||||
|
||||
void BonusList::stackBonuses()
|
||||
{
|
||||
boost::sort(bonuses, [](std::shared_ptr<Bonus> b1, std::shared_ptr<Bonus> b2) -> bool
|
||||
boost::sort(bonuses, [](const std::shared_ptr<Bonus> & b1, const std::shared_ptr<Bonus> & b2) -> bool
|
||||
{
|
||||
if(b1 == b2)
|
||||
return false;
|
||||
@@ -451,7 +421,7 @@ void BonusList::stackBonuses()
|
||||
size_t next = 1;
|
||||
while(next < bonuses.size())
|
||||
{
|
||||
bool remove;
|
||||
bool remove = false;
|
||||
std::shared_ptr<Bonus> last = bonuses[next-1];
|
||||
std::shared_ptr<Bonus> current = bonuses[next];
|
||||
|
||||
@@ -491,7 +461,7 @@ int BonusList::totalValue() const
|
||||
bool hasIndepMax = false;
|
||||
bool hasIndepMin = false;
|
||||
|
||||
for(std::shared_ptr<Bonus> b : bonuses)
|
||||
for(const std::shared_ptr<Bonus> & b : bonuses)
|
||||
{
|
||||
switch(b->valType)
|
||||
{
|
||||
@@ -541,10 +511,10 @@ int BonusList::totalValue() const
|
||||
if(hasIndepMin && hasIndepMax)
|
||||
assert(any.indepMin < any.indepMax);
|
||||
|
||||
const int notIndepBonuses = (int)std::count_if(bonuses.cbegin(), bonuses.cend(), [](const std::shared_ptr<Bonus>& b)
|
||||
const int notIndepBonuses = static_cast<int>(std::count_if(bonuses.cbegin(), bonuses.cend(), [](const std::shared_ptr<Bonus>& b)
|
||||
{
|
||||
return b->valType != Bonus::INDEPENDENT_MAX && b->valType != Bonus::INDEPENDENT_MIN;
|
||||
});
|
||||
}));
|
||||
|
||||
if (hasIndepMax)
|
||||
{
|
||||
@@ -576,7 +546,7 @@ std::shared_ptr<Bonus> BonusList::getFirst(const CSelector &select)
|
||||
|
||||
std::shared_ptr<const Bonus> BonusList::getFirst(const CSelector &selector) const
|
||||
{
|
||||
for (auto & b : bonuses)
|
||||
for(const auto & b : bonuses)
|
||||
{
|
||||
if(selector(b.get()))
|
||||
return b;
|
||||
@@ -587,7 +557,7 @@ std::shared_ptr<const Bonus> BonusList::getFirst(const CSelector &selector) cons
|
||||
void BonusList::getBonuses(BonusList & out, const CSelector &selector, const CSelector &limit) const
|
||||
{
|
||||
out.reserve(bonuses.size());
|
||||
for (auto & b : bonuses)
|
||||
for(const auto & b : bonuses)
|
||||
{
|
||||
//add matching bonuses that matches limit predicate or have NO_LIMIT if no given predicate
|
||||
auto noFightLimit = b->effectRange == Bonus::NO_LIMIT;
|
||||
@@ -598,7 +568,7 @@ void BonusList::getBonuses(BonusList & out, const CSelector &selector, const CSe
|
||||
|
||||
void BonusList::getAllBonuses(BonusList &out) const
|
||||
{
|
||||
for(auto & b : bonuses)
|
||||
for(const auto & b : bonuses)
|
||||
out.push_back(b);
|
||||
}
|
||||
|
||||
@@ -613,12 +583,12 @@ int BonusList::valOfBonuses(const CSelector &select) const
|
||||
JsonNode BonusList::toJsonNode() const
|
||||
{
|
||||
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
|
||||
for(std::shared_ptr<Bonus> b : bonuses)
|
||||
for(const std::shared_ptr<Bonus> & b : bonuses)
|
||||
node.Vector().push_back(b->toJsonNode());
|
||||
return node;
|
||||
}
|
||||
|
||||
void BonusList::push_back(std::shared_ptr<Bonus> x)
|
||||
void BonusList::push_back(const std::shared_ptr<Bonus> & x)
|
||||
{
|
||||
bonuses.push_back(x);
|
||||
changed();
|
||||
@@ -636,7 +606,7 @@ void BonusList::clear()
|
||||
changed();
|
||||
}
|
||||
|
||||
std::vector<BonusList*>::size_type BonusList::operator-=(std::shared_ptr<Bonus> const &i)
|
||||
std::vector<BonusList *>::size_type BonusList::operator-=(const std::shared_ptr<Bonus> & i)
|
||||
{
|
||||
auto itr = std::find(bonuses.begin(), bonuses.end(), i);
|
||||
if(itr == bonuses.end())
|
||||
@@ -646,7 +616,7 @@ std::vector<BonusList*>::size_type BonusList::operator-=(std::shared_ptr<Bonus>
|
||||
return true;
|
||||
}
|
||||
|
||||
void BonusList::resize(BonusList::TInternalContainer::size_type sz, std::shared_ptr<Bonus> c )
|
||||
void BonusList::resize(BonusList::TInternalContainer::size_type sz, const std::shared_ptr<Bonus> & c)
|
||||
{
|
||||
bonuses.resize(sz, c);
|
||||
changed();
|
||||
@@ -657,7 +627,7 @@ void BonusList::reserve(TInternalContainer::size_type sz)
|
||||
bonuses.reserve(sz);
|
||||
}
|
||||
|
||||
void BonusList::insert(BonusList::TInternalContainer::iterator position, BonusList::TInternalContainer::size_type n, std::shared_ptr<Bonus> const &x)
|
||||
void BonusList::insert(BonusList::TInternalContainer::iterator position, BonusList::TInternalContainer::size_type n, const std::shared_ptr<Bonus> & x)
|
||||
{
|
||||
bonuses.insert(position, n, x);
|
||||
changed();
|
||||
@@ -687,7 +657,7 @@ int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector)
|
||||
int IBonusBearer::valOfBonuses(Bonus::BonusType type, int subtype) const
|
||||
{
|
||||
//This part is performance-critical
|
||||
std::string cachingStr = "type_" + std::to_string(int(type)) + "_" + std::to_string(subtype);
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + std::to_string(subtype);
|
||||
|
||||
CSelector s = Selector::type()(type);
|
||||
if(subtype != -1)
|
||||
@@ -716,7 +686,7 @@ bool IBonusBearer::hasBonus(const CSelector &selector, const CSelector &limit, c
|
||||
bool IBonusBearer::hasBonusOfType(Bonus::BonusType type, int subtype) const
|
||||
{
|
||||
//This part is performance-ciritcal
|
||||
std::string cachingStr = "type_" + std::to_string(int(type)) + "_" + std::to_string(subtype);
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + std::to_string(subtype);
|
||||
|
||||
CSelector s = Selector::type()(type);
|
||||
if(subtype != -1)
|
||||
@@ -738,7 +708,7 @@ TConstBonusListPtr IBonusBearer::getBonuses(const CSelector &selector, const CSe
|
||||
bool IBonusBearer::hasBonusFrom(Bonus::BonusSource source, ui32 sourceID) const
|
||||
{
|
||||
boost::format fmt("source_%did_%d");
|
||||
fmt % (int)source % sourceID;
|
||||
fmt % static_cast<int>(source) % sourceID;
|
||||
|
||||
return hasBonus(Selector::source(source,sourceID), fmt.str());
|
||||
}
|
||||
@@ -888,7 +858,7 @@ const CStack * retrieveStackBattle(const CBonusSystemNode * node)
|
||||
switch(node->getNodeType())
|
||||
{
|
||||
case CBonusSystemNode::STACK_BATTLE:
|
||||
return static_cast<const CStack*>(node);
|
||||
return dynamic_cast<const CStack *>(node);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
@@ -899,9 +869,9 @@ const CStackInstance * retrieveStackInstance(const CBonusSystemNode * node)
|
||||
switch(node->getNodeType())
|
||||
{
|
||||
case CBonusSystemNode::STACK_INSTANCE:
|
||||
return (static_cast<const CStackInstance *>(node));
|
||||
return (dynamic_cast<const CStackInstance *>(node));
|
||||
case CBonusSystemNode::STACK_BATTLE:
|
||||
return (static_cast<const CStack*>(node))->base;
|
||||
return (dynamic_cast<const CStack *>(node))->base;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
@@ -935,7 +905,7 @@ std::shared_ptr<const Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelecto
|
||||
|
||||
void CBonusSystemNode::getParents(TCNodes & out) const /*retrieves list of parent nodes (nodes to inherit bonuses from) */
|
||||
{
|
||||
for (auto & elem : parents)
|
||||
for(const auto & elem : parents)
|
||||
{
|
||||
const CBonusSystemNode *parent = elem;
|
||||
out.insert(parent);
|
||||
@@ -953,7 +923,7 @@ void CBonusSystemNode::getParents(TNodes &out)
|
||||
|
||||
void CBonusSystemNode::getAllParents(TCNodes & out) const //retrieves list of parent nodes (nodes to inherit bonuses from)
|
||||
{
|
||||
for(auto parent : parents)
|
||||
for(auto * parent : parents)
|
||||
{
|
||||
out.insert(parent);
|
||||
parent->getAllParents(out);
|
||||
@@ -968,7 +938,7 @@ void CBonusSystemNode::getAllBonusesRec(BonusList &out, const CSelector & select
|
||||
TCNodes lparents;
|
||||
getAllParents(lparents);
|
||||
|
||||
if (lparents.size())
|
||||
if(!lparents.empty())
|
||||
{
|
||||
//estimate on how many bonuses are missing yet - must be positive
|
||||
beforeUpdate.reserve(std::max(out.capacity() - out.size(), bonuses.size()));
|
||||
@@ -978,7 +948,7 @@ void CBonusSystemNode::getAllBonusesRec(BonusList &out, const CSelector & select
|
||||
beforeUpdate.reserve(bonuses.size()); //at most all local bonuses
|
||||
}
|
||||
|
||||
for (auto parent : lparents)
|
||||
for(const auto * parent : lparents)
|
||||
{
|
||||
parent->getAllBonusesRec(beforeUpdate, selector);
|
||||
}
|
||||
@@ -993,7 +963,7 @@ void CBonusSystemNode::getAllBonusesRec(BonusList &out, const CSelector & select
|
||||
|
||||
//do not add bonus with updater
|
||||
bool bonusExists = false;
|
||||
for (auto const & bonus : out )
|
||||
for(const auto & bonus : out)
|
||||
{
|
||||
if (bonus == updated)
|
||||
bonusExists = true;
|
||||
@@ -1065,7 +1035,8 @@ TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector
|
||||
auto ret = std::make_shared<BonusList>();
|
||||
|
||||
// Get bonus results without caching enabled.
|
||||
BonusList beforeLimiting, afterLimiting;
|
||||
BonusList beforeLimiting;
|
||||
BonusList afterLimiting;
|
||||
getAllBonusesRec(beforeLimiting, selector);
|
||||
|
||||
if(!root || root == this)
|
||||
@@ -1076,15 +1047,16 @@ TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector
|
||||
{
|
||||
//We want to limit our query against an external node. We get all its bonuses,
|
||||
// add the ones we're considering and see if they're cut out by limiters
|
||||
BonusList rootBonuses, limitedRootBonuses;
|
||||
BonusList rootBonuses;
|
||||
BonusList limitedRootBonuses;
|
||||
getAllBonusesRec(rootBonuses, selector);
|
||||
|
||||
for(auto b : beforeLimiting)
|
||||
for(const auto & b : beforeLimiting)
|
||||
rootBonuses.push_back(b);
|
||||
|
||||
root->limitBonuses(rootBonuses, limitedRootBonuses);
|
||||
|
||||
for(auto b : beforeLimiting)
|
||||
for(const auto & b : beforeLimiting)
|
||||
if(vstd::contains(limitedRootBonuses, b))
|
||||
afterLimiting.push_back(b);
|
||||
|
||||
@@ -1094,7 +1066,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> CBonusSystemNode::getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr updater) const
|
||||
std::shared_ptr<Bonus> CBonusSystemNode::getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr & updater) const
|
||||
{
|
||||
assert(updater);
|
||||
return updater->createUpdatedBonus(b, * this);
|
||||
@@ -1105,33 +1077,30 @@ CBonusSystemNode::CBonusSystemNode()
|
||||
{
|
||||
}
|
||||
|
||||
CBonusSystemNode::CBonusSystemNode(bool isHypotetic)
|
||||
: bonuses(true),
|
||||
CBonusSystemNode::CBonusSystemNode(bool isHypotetic):
|
||||
bonuses(true),
|
||||
exportedBonuses(true),
|
||||
nodeType(UNKNOWN),
|
||||
cachedLast(0),
|
||||
sync(),
|
||||
isHypotheticNode(isHypotetic)
|
||||
{
|
||||
}
|
||||
|
||||
CBonusSystemNode::CBonusSystemNode(ENodeTypes NodeType)
|
||||
: bonuses(true),
|
||||
CBonusSystemNode::CBonusSystemNode(ENodeTypes NodeType):
|
||||
bonuses(true),
|
||||
exportedBonuses(true),
|
||||
nodeType(NodeType),
|
||||
cachedLast(0),
|
||||
sync(),
|
||||
isHypotheticNode(false)
|
||||
{
|
||||
}
|
||||
|
||||
CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other):
|
||||
CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other) noexcept:
|
||||
bonuses(std::move(other.bonuses)),
|
||||
exportedBonuses(std::move(other.exportedBonuses)),
|
||||
nodeType(other.nodeType),
|
||||
description(other.description),
|
||||
cachedLast(0),
|
||||
sync(),
|
||||
isHypotheticNode(other.isHypotheticNode)
|
||||
{
|
||||
std::swap(parents, other.parents);
|
||||
@@ -1164,9 +1133,9 @@ CBonusSystemNode::~CBonusSystemNode()
|
||||
{
|
||||
detachFromAll();
|
||||
|
||||
if(children.size())
|
||||
if(!children.empty())
|
||||
{
|
||||
while(children.size())
|
||||
while(!children.empty())
|
||||
children.front()->detachFrom(*this);
|
||||
}
|
||||
}
|
||||
@@ -1229,7 +1198,7 @@ void CBonusSystemNode::reduceBonusDurations(const CSelector &s)
|
||||
{
|
||||
BonusList bl;
|
||||
exportedBonuses.getBonuses(bl, s, Selector::all);
|
||||
for(auto b : bl)
|
||||
for(const auto & b : bl)
|
||||
{
|
||||
b->turnsRemain--;
|
||||
if(b->turnsRemain <= 0)
|
||||
@@ -1277,7 +1246,7 @@ void CBonusSystemNode::removeBonuses(const CSelector & selector)
|
||||
{
|
||||
BonusList toRemove;
|
||||
exportedBonuses.getBonuses(toRemove, selector, Selector::all);
|
||||
for(auto bonus : toRemove)
|
||||
for(const auto & bonus : toRemove)
|
||||
removeBonus(bonus);
|
||||
}
|
||||
|
||||
@@ -1294,7 +1263,7 @@ bool CBonusSystemNode::actsAsBonusSourceOnly() const
|
||||
}
|
||||
}
|
||||
|
||||
void CBonusSystemNode::propagateBonus(std::shared_ptr<Bonus> b, const CBonusSystemNode & source)
|
||||
void CBonusSystemNode::propagateBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & source)
|
||||
{
|
||||
if(b->propagator->shouldBeAttached(this))
|
||||
{
|
||||
@@ -1309,7 +1278,7 @@ void CBonusSystemNode::propagateBonus(std::shared_ptr<Bonus> b, const CBonusSyst
|
||||
child->propagateBonus(b, source);
|
||||
}
|
||||
|
||||
void CBonusSystemNode::unpropagateBonus(std::shared_ptr<Bonus> b)
|
||||
void CBonusSystemNode::unpropagateBonus(const std::shared_ptr<Bonus> & b)
|
||||
{
|
||||
if(b->propagator->shouldBeAttached(this))
|
||||
{
|
||||
@@ -1340,7 +1309,7 @@ void CBonusSystemNode::childDetached(CBonusSystemNode & child)
|
||||
|
||||
void CBonusSystemNode::detachFromAll()
|
||||
{
|
||||
while(parents.size())
|
||||
while(!parents.empty())
|
||||
detachFrom(*parents.front());
|
||||
}
|
||||
|
||||
@@ -1351,7 +1320,7 @@ bool CBonusSystemNode::isIndependentNode() const
|
||||
|
||||
std::string CBonusSystemNode::nodeName() const
|
||||
{
|
||||
return description.size()
|
||||
return !description.empty()
|
||||
? description
|
||||
: std::string("Bonus system node of type ") + typeid(*this).name();
|
||||
}
|
||||
@@ -1412,7 +1381,7 @@ void CBonusSystemNode::getRedChildren(TNodes &out)
|
||||
|
||||
void CBonusSystemNode::newRedDescendant(CBonusSystemNode & descendant)
|
||||
{
|
||||
for(auto b : exportedBonuses)
|
||||
for(const auto & b : exportedBonuses)
|
||||
{
|
||||
if(b->propagator)
|
||||
descendant.propagateBonus(b, *this);
|
||||
@@ -1420,9 +1389,9 @@ void CBonusSystemNode::newRedDescendant(CBonusSystemNode & descendant)
|
||||
TNodes redParents;
|
||||
getRedAncestors(redParents); //get all red parents recursively
|
||||
|
||||
for(auto parent : redParents)
|
||||
for(auto * parent : redParents)
|
||||
{
|
||||
for(auto b : parent->exportedBonuses)
|
||||
for(const auto & b : parent->exportedBonuses)
|
||||
{
|
||||
if(b->propagator)
|
||||
descendant.propagateBonus(b, *this);
|
||||
@@ -1432,16 +1401,16 @@ void CBonusSystemNode::newRedDescendant(CBonusSystemNode & descendant)
|
||||
|
||||
void CBonusSystemNode::removedRedDescendant(CBonusSystemNode & descendant)
|
||||
{
|
||||
for(auto b : exportedBonuses)
|
||||
for(const auto & b : exportedBonuses)
|
||||
if(b->propagator)
|
||||
descendant.unpropagateBonus(b);
|
||||
|
||||
TNodes redParents;
|
||||
getRedAncestors(redParents); //get all red parents recursively
|
||||
|
||||
for(auto parent : redParents)
|
||||
for(auto * parent : redParents)
|
||||
{
|
||||
for(auto b : parent->exportedBonuses)
|
||||
for(const auto & b : parent->exportedBonuses)
|
||||
if(b->propagator)
|
||||
descendant.unpropagateBonus(b);
|
||||
}
|
||||
@@ -1465,7 +1434,7 @@ void CBonusSystemNode::getRedDescendants(TNodes &out)
|
||||
c->getRedChildren(out);
|
||||
}
|
||||
|
||||
void CBonusSystemNode::exportBonus(std::shared_ptr<Bonus> b)
|
||||
void CBonusSystemNode::exportBonus(const std::shared_ptr<Bonus> & b)
|
||||
{
|
||||
if(b->propagator)
|
||||
propagateBonus(b, *this);
|
||||
@@ -1477,7 +1446,7 @@ void CBonusSystemNode::exportBonus(std::shared_ptr<Bonus> b)
|
||||
|
||||
void CBonusSystemNode::exportBonuses()
|
||||
{
|
||||
for(auto b : exportedBonuses)
|
||||
for(const auto & b : exportedBonuses)
|
||||
exportBonus(b);
|
||||
}
|
||||
|
||||
@@ -1530,8 +1499,8 @@ void CBonusSystemNode::limitBonuses(const BonusList &allBonuses, BonusList &out)
|
||||
{
|
||||
assert(&allBonuses != &out); //todo should it work in-place?
|
||||
|
||||
BonusList undecided = allBonuses,
|
||||
&accepted = out;
|
||||
BonusList undecided = allBonuses;
|
||||
BonusList & accepted = out;
|
||||
|
||||
while(true)
|
||||
{
|
||||
@@ -1687,7 +1656,7 @@ JsonNode durationToJson(ui16 duration)
|
||||
else
|
||||
{
|
||||
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
|
||||
for(std::string dur : durationNames)
|
||||
for(const std::string & dur : durationNames)
|
||||
node.Vector().push_back(JsonUtils::stringNode(dur));
|
||||
return node;
|
||||
}
|
||||
@@ -1705,7 +1674,7 @@ JsonNode Bonus::toJsonNode() const
|
||||
if(duration != 0)
|
||||
{
|
||||
JsonNode durationVec(JsonNode::JsonType::DATA_VECTOR);
|
||||
for(auto & kv : bonusDurationMap)
|
||||
for(const auto & kv : bonusDurationMap)
|
||||
{
|
||||
if(duration & kv.second)
|
||||
durationVec.Vector().push_back(JsonUtils::stringNode(kv.first));
|
||||
@@ -1755,7 +1724,7 @@ std::string Bonus::nameForBonus() const
|
||||
case Bonus::SPECIAL_PECULIAR_ENCHANT:
|
||||
case Bonus::SPECIAL_ADD_VALUE_ENCHANT:
|
||||
case Bonus::SPECIAL_FIXED_VALUE_ENCHANT:
|
||||
return (*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier;
|
||||
return (*VLC->spellh)[static_cast<SpellID::ESpellID>(subtype)]->identifier;
|
||||
case Bonus::SPECIAL_UPGRADE:
|
||||
return CreatureID::encode(subtype) + "2" + CreatureID::encode(additionalInfo[0]);
|
||||
case Bonus::GENERATE_RESOURCE:
|
||||
@@ -2005,40 +1974,34 @@ CSelector BonusParams::toSelector()
|
||||
return ret;
|
||||
}
|
||||
|
||||
Bonus::Bonus(Bonus::BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype)
|
||||
: duration((ui16)Duration), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc)
|
||||
Bonus::Bonus(Bonus::BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype):
|
||||
duration(static_cast<ui16>(Duration)),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
source(Src),
|
||||
val(Val),
|
||||
sid(ID),
|
||||
description(std::move(Desc))
|
||||
{
|
||||
turnsRemain = 0;
|
||||
valType = ADDITIVE_VALUE;
|
||||
effectRange = NO_LIMIT;
|
||||
boost::algorithm::trim(description);
|
||||
targetSourceType = OTHER;
|
||||
}
|
||||
|
||||
Bonus::Bonus(Bonus::BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype, ValueType ValType)
|
||||
: duration((ui16)Duration), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), valType(ValType)
|
||||
Bonus::Bonus(Bonus::BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype, ValueType ValType):
|
||||
duration(static_cast<ui16>(Duration)),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
source(Src),
|
||||
val(Val),
|
||||
sid(ID),
|
||||
valType(ValType)
|
||||
{
|
||||
turnsRemain = 0;
|
||||
effectRange = NO_LIMIT;
|
||||
targetSourceType = OTHER;
|
||||
}
|
||||
|
||||
Bonus::Bonus()
|
||||
{
|
||||
duration = PERMANENT;
|
||||
turnsRemain = 0;
|
||||
type = NONE;
|
||||
subtype = -1;
|
||||
|
||||
valType = ADDITIVE_VALUE;
|
||||
effectRange = NO_LIMIT;
|
||||
val = 0;
|
||||
source = OTHER;
|
||||
sid = 0;
|
||||
targetSourceType = OTHER;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> Bonus::addPropagator(TPropagatorPtr Propagator)
|
||||
std::shared_ptr<Bonus> Bonus::addPropagator(const TPropagatorPtr & Propagator)
|
||||
{
|
||||
propagator = Propagator;
|
||||
return this->shared_from_this();
|
||||
@@ -2090,7 +2053,7 @@ namespace Selector
|
||||
return type()(Type).And(subtype()(Subtype));
|
||||
}
|
||||
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, CAddInfo info)
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, const CAddInfo & info)
|
||||
{
|
||||
return CSelectFieldEqual<Bonus::BonusType>(&Bonus::type)(type)
|
||||
.And(CSelectFieldEqual<TBonusSubtype>(&Bonus::subtype)(subtype))
|
||||
@@ -2137,9 +2100,9 @@ const CCreature * retrieveCreature(const CBonusSystemNode *node)
|
||||
switch(node->getNodeType())
|
||||
{
|
||||
case CBonusSystemNode::CREATURE:
|
||||
return (static_cast<const CCreature *>(node));
|
||||
return (dynamic_cast<const CCreature *>(node));
|
||||
case CBonusSystemNode::STACK_BATTLE:
|
||||
return (static_cast<const CStack*>(node))->type;
|
||||
return (dynamic_cast<const CStack *>(node))->type;
|
||||
default:
|
||||
const CStackInstance * csi = retrieveStackInstance(node);
|
||||
if(csi)
|
||||
@@ -2152,7 +2115,7 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const BonusList &bonusL
|
||||
{
|
||||
for (ui32 i = 0; i < bonusList.size(); i++)
|
||||
{
|
||||
auto b = bonusList[i];
|
||||
const auto & b = bonusList[i];
|
||||
out << "Bonus " << i << "\n" << *b << std::endl;
|
||||
}
|
||||
return out;
|
||||
@@ -2160,9 +2123,9 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const BonusList &bonusL
|
||||
|
||||
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
|
||||
{
|
||||
for(auto i = bonusNameMap.cbegin(); i != bonusNameMap.cend(); i++)
|
||||
if(i->second == bonus.type)
|
||||
out << "\tType: " << i->first << " \t";
|
||||
for(const auto & i : bonusNameMap)
|
||||
if(i.second == bonus.type)
|
||||
out << "\tType: " << i.first << " \t";
|
||||
|
||||
#define printField(field) out << "\t" #field ": " << (int)bonus.field << "\n"
|
||||
printField(val);
|
||||
@@ -2187,7 +2150,7 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> Bonus::addLimiter(TLimiterPtr Limiter)
|
||||
std::shared_ptr<Bonus> Bonus::addLimiter(const TLimiterPtr & Limiter)
|
||||
{
|
||||
if (limiter)
|
||||
{
|
||||
@@ -2210,10 +2173,6 @@ std::shared_ptr<Bonus> Bonus::addLimiter(TLimiterPtr Limiter)
|
||||
return this->shared_from_this();
|
||||
}
|
||||
|
||||
ILimiter::~ILimiter()
|
||||
{
|
||||
}
|
||||
|
||||
int ILimiter::limit(const BonusLimitationContext &context) const /*return true to drop the bonus */
|
||||
{
|
||||
return false;
|
||||
@@ -2245,13 +2204,7 @@ CCreatureTypeLimiter::CCreatureTypeLimiter(const CCreature & creature_, bool Inc
|
||||
{
|
||||
}
|
||||
|
||||
CCreatureTypeLimiter::CCreatureTypeLimiter()
|
||||
{
|
||||
creature = nullptr;
|
||||
includeUpgrades = false;
|
||||
}
|
||||
|
||||
void CCreatureTypeLimiter::setCreature (CreatureID id)
|
||||
void CCreatureTypeLimiter::setCreature(const CreatureID & id)
|
||||
{
|
||||
creature = VLC->creh->objects[id];
|
||||
}
|
||||
@@ -2351,11 +2304,6 @@ JsonNode HasAnotherBonusLimiter::toJsonNode() const
|
||||
return root;
|
||||
}
|
||||
|
||||
IPropagator::~IPropagator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool IPropagator::shouldBeAttached(CBonusSystemNode *dest)
|
||||
{
|
||||
return false;
|
||||
@@ -2439,8 +2387,8 @@ CreatureFactionLimiter::CreatureFactionLimiter(TFaction creatureFaction)
|
||||
{
|
||||
}
|
||||
|
||||
CreatureFactionLimiter::CreatureFactionLimiter()
|
||||
: faction((TFaction)-1)
|
||||
CreatureFactionLimiter::CreatureFactionLimiter():
|
||||
faction(static_cast<TFaction>(-1))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2552,18 +2500,18 @@ StackOwnerLimiter::StackOwnerLimiter()
|
||||
{
|
||||
}
|
||||
|
||||
StackOwnerLimiter::StackOwnerLimiter(PlayerColor Owner)
|
||||
: owner(Owner)
|
||||
StackOwnerLimiter::StackOwnerLimiter(const PlayerColor & Owner):
|
||||
owner(Owner)
|
||||
{
|
||||
}
|
||||
|
||||
OppositeSideLimiter::OppositeSideLimiter()
|
||||
: owner(PlayerColor::CANNOT_DETERMINE)
|
||||
OppositeSideLimiter::OppositeSideLimiter():
|
||||
owner(PlayerColor::CANNOT_DETERMINE)
|
||||
{
|
||||
}
|
||||
|
||||
OppositeSideLimiter::OppositeSideLimiter(PlayerColor Owner)
|
||||
: owner(Owner)
|
||||
OppositeSideLimiter::OppositeSideLimiter(const PlayerColor & Owner):
|
||||
owner(Owner)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2576,7 +2524,7 @@ int OppositeSideLimiter::limit(const BonusLimitationContext & context) const
|
||||
|
||||
// Aggregate/Boolean Limiters
|
||||
|
||||
void AggregateLimiter::add(TLimiterPtr limiter)
|
||||
void AggregateLimiter::add(const TLimiterPtr & limiter)
|
||||
{
|
||||
if(limiter)
|
||||
limiters.push_back(limiter);
|
||||
@@ -2586,7 +2534,7 @@ JsonNode AggregateLimiter::toJsonNode() const
|
||||
{
|
||||
JsonNode result(JsonNode::JsonType::DATA_VECTOR);
|
||||
result.Vector().push_back(JsonUtils::stringNode(getAggregator()));
|
||||
for(auto l : limiters)
|
||||
for(const auto & l : limiters)
|
||||
result.Vector().push_back(l->toJsonNode());
|
||||
return result;
|
||||
}
|
||||
@@ -2601,7 +2549,7 @@ int AllOfLimiter::limit(const BonusLimitationContext & context) const
|
||||
{
|
||||
bool wasntSure = false;
|
||||
|
||||
for(auto limiter : limiters)
|
||||
for(const auto & limiter : limiters)
|
||||
{
|
||||
auto result = limiter->limit(context);
|
||||
if(result == ILimiter::DISCARD)
|
||||
@@ -2623,7 +2571,7 @@ int AnyOfLimiter::limit(const BonusLimitationContext & context) const
|
||||
{
|
||||
bool wasntSure = false;
|
||||
|
||||
for(auto limiter : limiters)
|
||||
for(const auto & limiter : limiters)
|
||||
{
|
||||
auto result = limiter->limit(context);
|
||||
if(result == ILimiter::ACCEPT)
|
||||
@@ -2645,7 +2593,7 @@ int NoneOfLimiter::limit(const BonusLimitationContext & context) const
|
||||
{
|
||||
bool wasntSure = false;
|
||||
|
||||
for(auto limiter : limiters)
|
||||
for(const auto & limiter : limiters)
|
||||
{
|
||||
auto result = limiter->limit(context);
|
||||
if(result == ILimiter::ACCEPT)
|
||||
@@ -2659,16 +2607,12 @@ int NoneOfLimiter::limit(const BonusLimitationContext & context) const
|
||||
|
||||
// Updaters
|
||||
|
||||
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
|
||||
std::shared_ptr<Bonus> Bonus::addUpdater(const TUpdaterPtr & Updater)
|
||||
{
|
||||
updater = Updater;
|
||||
return this->shared_from_this();
|
||||
}
|
||||
|
||||
IUpdater::~IUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> IUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
||||
{
|
||||
return b;
|
||||
@@ -2684,10 +2628,6 @@ JsonNode IUpdater::toJsonNode() const
|
||||
return JsonNode(JsonNode::JsonType::DATA_NULL);
|
||||
}
|
||||
|
||||
GrowsWithLevelUpdater::GrowsWithLevelUpdater() : valPer20(0), stepSize(1)
|
||||
{
|
||||
}
|
||||
|
||||
GrowsWithLevelUpdater::GrowsWithLevelUpdater(int valPer20, int stepSize) : valPer20(valPer20), stepSize(stepSize)
|
||||
{
|
||||
}
|
||||
@@ -2696,7 +2636,7 @@ std::shared_ptr<Bonus> GrowsWithLevelUpdater::createUpdatedBonus(const std::shar
|
||||
{
|
||||
if(context.getNodeType() == CBonusSystemNode::HERO)
|
||||
{
|
||||
int level = static_cast<const CGHeroInstance &>(context).level;
|
||||
int level = dynamic_cast<const CGHeroInstance &>(context).level;
|
||||
int steps = stepSize ? level / stepSize : level;
|
||||
//rounding follows format for HMM3 creature specialty bonus
|
||||
int newVal = (valPer20 * steps + 19) / 20;
|
||||
@@ -2725,15 +2665,11 @@ JsonNode GrowsWithLevelUpdater::toJsonNode() const
|
||||
return root;
|
||||
}
|
||||
|
||||
TimesHeroLevelUpdater::TimesHeroLevelUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> TimesHeroLevelUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
||||
{
|
||||
if(context.getNodeType() == CBonusSystemNode::HERO)
|
||||
{
|
||||
int level = static_cast<const CGHeroInstance &>(context).level;
|
||||
int level = dynamic_cast<const CGHeroInstance &>(context).level;
|
||||
std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*b);
|
||||
newBonus->val *= level;
|
||||
return newBonus;
|
||||
@@ -2801,23 +2737,18 @@ JsonNode ArmyMovementUpdater::toJsonNode() const
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
TimesStackLevelUpdater::TimesStackLevelUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
||||
{
|
||||
if(context.getNodeType() == CBonusSystemNode::STACK_INSTANCE)
|
||||
{
|
||||
int level = static_cast<const CStackInstance &>(context).getLevel();
|
||||
int level = dynamic_cast<const CStackInstance &>(context).getLevel();
|
||||
std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*b);
|
||||
newBonus->val *= level;
|
||||
return newBonus;
|
||||
}
|
||||
else if(context.getNodeType() == CBonusSystemNode::STACK_BATTLE)
|
||||
{
|
||||
const CStack & stack = static_cast<const CStack &>(context);
|
||||
const auto & stack = dynamic_cast<const CStack &>(context);
|
||||
//only update if stack doesn't have an instance (summons, war machines)
|
||||
//otherwise we'd end up multiplying twice
|
||||
if(stack.base == nullptr)
|
||||
@@ -2841,10 +2772,6 @@ JsonNode TimesStackLevelUpdater::toJsonNode() const
|
||||
return JsonUtils::stringNode("TIMES_STACK_LEVEL");
|
||||
}
|
||||
|
||||
OwnerUpdater::OwnerUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
std::string OwnerUpdater::toString() const
|
||||
{
|
||||
return "OwnerUpdater";
|
||||
@@ -2862,8 +2789,8 @@ std::shared_ptr<Bonus> OwnerUpdater::createUpdatedBonus(const std::shared_ptr<Bo
|
||||
if(owner == PlayerColor::UNFLAGGABLE)
|
||||
owner = PlayerColor::NEUTRAL;
|
||||
|
||||
std::shared_ptr<Bonus> updated = std::make_shared<Bonus>(
|
||||
(Bonus::BonusDuration)b->duration, b->type, b->source, b->val, b->sid, b->subtype, b->valType);
|
||||
std::shared_ptr<Bonus> updated =
|
||||
std::make_shared<Bonus>(static_cast<Bonus::BonusDuration>(b->duration), b->type, b->source, b->val, b->sid, b->subtype, b->valType);
|
||||
updated->limiter = std::make_shared<OppositeSideLimiter>(owner);
|
||||
return updated;
|
||||
}
|
||||
|
@@ -81,9 +81,9 @@ class DLL_LINKAGE CBonusProxy
|
||||
public:
|
||||
CBonusProxy(const IBonusBearer * Target, CSelector Selector);
|
||||
CBonusProxy(const CBonusProxy & other);
|
||||
CBonusProxy(CBonusProxy && other);
|
||||
CBonusProxy(CBonusProxy && other) noexcept;
|
||||
|
||||
CBonusProxy & operator=(CBonusProxy && other);
|
||||
CBonusProxy & operator=(CBonusProxy && other) noexcept;
|
||||
CBonusProxy & operator=(const CBonusProxy & other);
|
||||
const BonusList * operator->() const;
|
||||
TConstBonusListPtr getBonusList() const;
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
CTotalsProxy(const CTotalsProxy & other);
|
||||
CTotalsProxy(CTotalsProxy && other) = delete;
|
||||
|
||||
CTotalsProxy & operator=(const CTotalsProxy & other);
|
||||
CTotalsProxy & operator=(const CTotalsProxy & other) = default;
|
||||
CTotalsProxy & operator=(CTotalsProxy && other) = delete;
|
||||
|
||||
int getMeleeValue() const;
|
||||
@@ -121,8 +121,8 @@ public:
|
||||
private:
|
||||
int initialValue;
|
||||
|
||||
mutable int64_t valueCachedLast;
|
||||
mutable int value;
|
||||
mutable int64_t valueCachedLast = 0;
|
||||
mutable int value = 0;
|
||||
|
||||
mutable int64_t meleeCachedLast;
|
||||
mutable int meleeValue;
|
||||
@@ -415,21 +415,21 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
#undef BONUS_VALUE
|
||||
};
|
||||
|
||||
ui16 duration; //uses BonusDuration values
|
||||
si16 turnsRemain; //used if duration is N_TURNS, N_DAYS or ONE_WEEK
|
||||
ui16 duration = PERMANENT; //uses BonusDuration values
|
||||
si16 turnsRemain = 0; //used if duration is N_TURNS, N_DAYS or ONE_WEEK
|
||||
|
||||
BonusType type; //uses BonusType values - says to what is this bonus - 1 byte
|
||||
TBonusSubtype subtype; //-1 if not applicable - 4 bytes
|
||||
BonusType type = NONE; //uses BonusType values - says to what is this bonus - 1 byte
|
||||
TBonusSubtype subtype = -1; //-1 if not applicable - 4 bytes
|
||||
|
||||
BonusSource source;//source type" uses BonusSource values - what gave that bonus
|
||||
BonusSource source = OTHER; //source type" uses BonusSource values - what gave that bonus
|
||||
BonusSource targetSourceType;//Bonuses of what origin this amplifies, uses BonusSource values. Needed for PERCENT_TO_TARGET_TYPE.
|
||||
si32 val;
|
||||
ui32 sid; //source id: id of object/artifact/spell
|
||||
ValueType valType;
|
||||
si32 val = 0;
|
||||
ui32 sid = 0; //source id: id of object/artifact/spell
|
||||
ValueType valType = ADDITIVE_VALUE;
|
||||
std::string stacking; // bonuses with the same stacking value don't stack (e.g. Angel/Archangel morale bonus)
|
||||
|
||||
CAddInfo additionalInfo;
|
||||
LimitEffect effectRange; //if not NO_LIMIT, bonus will be omitted by default
|
||||
LimitEffect effectRange = NO_LIMIT; //if not NO_LIMIT, bonus will be omitted by default
|
||||
|
||||
TLimiterPtr limiter;
|
||||
TPropagatorPtr propagator;
|
||||
@@ -440,7 +440,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
|
||||
Bonus(BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1);
|
||||
Bonus(BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype=-1, ValueType ValType = ADDITIVE_VALUE);
|
||||
Bonus();
|
||||
Bonus() = default;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@@ -525,9 +525,9 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
JsonNode toJsonNode() const;
|
||||
std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct
|
||||
|
||||
std::shared_ptr<Bonus> addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls
|
||||
std::shared_ptr<Bonus> addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls
|
||||
std::shared_ptr<Bonus> addUpdater(TUpdaterPtr Updater); //returns this for convenient chain-calls
|
||||
std::shared_ptr<Bonus> addLimiter(const TLimiterPtr & Limiter); //returns this for convenient chain-calls
|
||||
std::shared_ptr<Bonus> addPropagator(const TPropagatorPtr & Propagator); //returns this for convenient chain-calls
|
||||
std::shared_ptr<Bonus> addUpdater(const TUpdaterPtr & Updater); //returns this for convenient chain-calls
|
||||
};
|
||||
|
||||
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus);
|
||||
@@ -562,7 +562,7 @@ public:
|
||||
private:
|
||||
TInternalContainer bonuses;
|
||||
bool belongsToTree;
|
||||
void changed();
|
||||
void changed() const;
|
||||
|
||||
public:
|
||||
typedef TInternalContainer::const_reference const_reference;
|
||||
@@ -573,16 +573,16 @@ public:
|
||||
|
||||
BonusList(bool BelongsToTree = false);
|
||||
BonusList(const BonusList &bonusList);
|
||||
BonusList(BonusList && other);
|
||||
BonusList(BonusList && other) noexcept;
|
||||
BonusList& operator=(const BonusList &bonusList);
|
||||
|
||||
// wrapper functions of the STL vector container
|
||||
TInternalContainer::size_type size() const { return bonuses.size(); }
|
||||
void push_back(std::shared_ptr<Bonus> x);
|
||||
void push_back(const std::shared_ptr<Bonus> & x);
|
||||
TInternalContainer::iterator erase (const int position);
|
||||
void clear();
|
||||
bool empty() const { return bonuses.empty(); }
|
||||
void resize(TInternalContainer::size_type sz, std::shared_ptr<Bonus> c = nullptr );
|
||||
void resize(TInternalContainer::size_type sz, const std::shared_ptr<Bonus> & c = nullptr);
|
||||
void reserve(TInternalContainer::size_type sz);
|
||||
TInternalContainer::size_type capacity() const { return bonuses.capacity(); }
|
||||
STRONG_INLINE std::shared_ptr<Bonus> &operator[] (TInternalContainer::size_type n) { return bonuses[n]; }
|
||||
@@ -595,7 +595,7 @@ public:
|
||||
// There should be no non-const access to provide solid,robust bonus caching
|
||||
TInternalContainer::const_iterator begin() const { return bonuses.begin(); }
|
||||
TInternalContainer::const_iterator end() const { return bonuses.end(); }
|
||||
TInternalContainer::size_type operator-=(std::shared_ptr<Bonus> const &i);
|
||||
TInternalContainer::size_type operator-=(const std::shared_ptr<Bonus> & i);
|
||||
|
||||
// BonusList functions
|
||||
void stackBonuses();
|
||||
@@ -629,7 +629,7 @@ public:
|
||||
|
||||
template <class InputIterator>
|
||||
void insert(const int position, InputIterator first, InputIterator last);
|
||||
void insert(TInternalContainer::iterator position, TInternalContainer::size_type n, std::shared_ptr<Bonus> const &x);
|
||||
void insert(TInternalContainer::iterator position, TInternalContainer::size_type n, const std::shared_ptr<Bonus> & x);
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler &h, const int version)
|
||||
@@ -661,12 +661,12 @@ inline BonusList::iterator range_end(BonusList & x)
|
||||
return x.end();
|
||||
}
|
||||
|
||||
inline BonusList::const_iterator range_begin(BonusList const &x)
|
||||
inline BonusList::const_iterator range_begin(const BonusList & x)
|
||||
{
|
||||
return x.begin();
|
||||
}
|
||||
|
||||
inline BonusList::const_iterator range_end(BonusList const &x)
|
||||
inline BonusList::const_iterator range_end(const BonusList & x)
|
||||
{
|
||||
return x.end();
|
||||
}
|
||||
@@ -686,7 +686,7 @@ class DLL_LINKAGE ILimiter
|
||||
public:
|
||||
enum EDecision {ACCEPT, DISCARD, NOT_SURE};
|
||||
|
||||
virtual ~ILimiter();
|
||||
virtual ~ILimiter() = default;
|
||||
|
||||
virtual int limit(const BonusLimitationContext &context) const; //0 - accept bonus; 1 - drop bonus; 2 - delay (drops eventually)
|
||||
virtual std::string toString() const;
|
||||
@@ -791,13 +791,13 @@ private:
|
||||
|
||||
void getAllBonusesRec(BonusList &out, const CSelector & selector) const;
|
||||
TConstBonusListPtr getAllBonusesWithoutCaching(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr) const;
|
||||
std::shared_ptr<Bonus> getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr updater) const;
|
||||
std::shared_ptr<Bonus> getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr & updater) const;
|
||||
|
||||
public:
|
||||
explicit CBonusSystemNode();
|
||||
explicit CBonusSystemNode(bool isHypotetic);
|
||||
explicit CBonusSystemNode(ENodeTypes NodeType);
|
||||
CBonusSystemNode(CBonusSystemNode && other);
|
||||
CBonusSystemNode(CBonusSystemNode && other) noexcept;
|
||||
virtual ~CBonusSystemNode();
|
||||
|
||||
void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here
|
||||
@@ -825,8 +825,8 @@ public:
|
||||
|
||||
void newChildAttached(CBonusSystemNode & child);
|
||||
void childDetached(CBonusSystemNode & child);
|
||||
void propagateBonus(std::shared_ptr<Bonus> b, const CBonusSystemNode & source);
|
||||
void unpropagateBonus(std::shared_ptr<Bonus> b);
|
||||
void propagateBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & source);
|
||||
void unpropagateBonus(const std::shared_ptr<Bonus> & b);
|
||||
void removeBonus(const std::shared_ptr<Bonus>& b);
|
||||
void removeBonuses(const CSelector & selector);
|
||||
void removeBonusesRecursive(const CSelector & s);
|
||||
@@ -843,7 +843,7 @@ public:
|
||||
bool isHypothetic() const { return isHypotheticNode; }
|
||||
|
||||
void deserializationFix();
|
||||
void exportBonus(std::shared_ptr<Bonus> b);
|
||||
void exportBonus(const std::shared_ptr<Bonus> & b);
|
||||
void exportBonuses();
|
||||
|
||||
const BonusList &getBonusList() const;
|
||||
@@ -881,7 +881,7 @@ public:
|
||||
class DLL_LINKAGE IPropagator
|
||||
{
|
||||
public:
|
||||
virtual ~IPropagator();
|
||||
virtual ~IPropagator() = default;
|
||||
virtual bool shouldBeAttached(CBonusSystemNode *dest);
|
||||
virtual CBonusSystemNode::ENodeTypes getPropagatorType() const;
|
||||
|
||||
@@ -1003,7 +1003,7 @@ protected:
|
||||
std::vector<TLimiterPtr> limiters;
|
||||
virtual const std::string & getAggregator() const = 0;
|
||||
public:
|
||||
void add(TLimiterPtr limiter);
|
||||
void add(const TLimiterPtr & limiter);
|
||||
JsonNode toJsonNode() const override;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
@@ -1043,12 +1043,12 @@ public:
|
||||
class DLL_LINKAGE CCreatureTypeLimiter : public ILimiter //affect only stacks of given creature (and optionally it's upgrades)
|
||||
{
|
||||
public:
|
||||
const CCreature *creature;
|
||||
bool includeUpgrades;
|
||||
const CCreature * creature = nullptr;
|
||||
bool includeUpgrades = false;
|
||||
|
||||
CCreatureTypeLimiter();
|
||||
CCreatureTypeLimiter() = default;
|
||||
CCreatureTypeLimiter(const CCreature & creature_, bool IncludeUpgrades = true);
|
||||
void setCreature (CreatureID id);
|
||||
void setCreature(const CreatureID & id);
|
||||
|
||||
int limit(const BonusLimitationContext &context) const override;
|
||||
virtual std::string toString() const override;
|
||||
@@ -1154,7 +1154,7 @@ class DLL_LINKAGE StackOwnerLimiter : public ILimiter //applies only to creature
|
||||
public:
|
||||
PlayerColor owner;
|
||||
StackOwnerLimiter();
|
||||
StackOwnerLimiter(PlayerColor Owner);
|
||||
StackOwnerLimiter(const PlayerColor & Owner);
|
||||
|
||||
int limit(const BonusLimitationContext &context) const override;
|
||||
|
||||
@@ -1170,7 +1170,7 @@ class DLL_LINKAGE OppositeSideLimiter : public ILimiter //applies only to creatu
|
||||
public:
|
||||
PlayerColor owner;
|
||||
OppositeSideLimiter();
|
||||
OppositeSideLimiter(PlayerColor Owner);
|
||||
OppositeSideLimiter(const PlayerColor & Owner);
|
||||
|
||||
int limit(const BonusLimitationContext &context) const override;
|
||||
|
||||
@@ -1210,7 +1210,7 @@ namespace Selector
|
||||
extern DLL_LINKAGE CWillLastDays days;
|
||||
|
||||
CSelector DLL_LINKAGE typeSubtype(Bonus::BonusType Type, TBonusSubtype Subtype);
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, CAddInfo info);
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, const CAddInfo & info);
|
||||
CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID);
|
||||
CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source);
|
||||
CSelector DLL_LINKAGE valueType(Bonus::ValueType valType);
|
||||
@@ -1254,7 +1254,7 @@ void BonusList::insert(const int position, InputIterator first, InputIterator la
|
||||
class DLL_LINKAGE IUpdater
|
||||
{
|
||||
public:
|
||||
virtual ~IUpdater();
|
||||
virtual ~IUpdater() = default;
|
||||
|
||||
virtual std::shared_ptr<Bonus> createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const;
|
||||
virtual std::string toString() const;
|
||||
@@ -1268,10 +1268,10 @@ public:
|
||||
class DLL_LINKAGE GrowsWithLevelUpdater : public IUpdater
|
||||
{
|
||||
public:
|
||||
int valPer20;
|
||||
int stepSize;
|
||||
int valPer20 = 0;
|
||||
int stepSize = 1;
|
||||
|
||||
GrowsWithLevelUpdater();
|
||||
GrowsWithLevelUpdater() = default;
|
||||
GrowsWithLevelUpdater(int valPer20, int stepSize = 1);
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
@@ -1289,8 +1289,6 @@ public:
|
||||
class DLL_LINKAGE TimesHeroLevelUpdater : public IUpdater
|
||||
{
|
||||
public:
|
||||
TimesHeroLevelUpdater();
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
h & static_cast<IUpdater &>(*this);
|
||||
@@ -1304,8 +1302,6 @@ public:
|
||||
class DLL_LINKAGE TimesStackLevelUpdater : public IUpdater
|
||||
{
|
||||
public:
|
||||
TimesStackLevelUpdater();
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
h & static_cast<IUpdater &>(*this);
|
||||
@@ -1342,8 +1338,6 @@ public:
|
||||
class DLL_LINKAGE OwnerUpdater : public IUpdater
|
||||
{
|
||||
public:
|
||||
OwnerUpdater();
|
||||
|
||||
template <typename Handler> void serialize(Handler& h, const int version)
|
||||
{
|
||||
h & static_cast<IUpdater &>(*this);
|
||||
|
@@ -19,7 +19,7 @@ struct Bonus;
|
||||
class DLL_LINKAGE IBonusTypeHandler
|
||||
{
|
||||
public:
|
||||
virtual ~IBonusTypeHandler(){};
|
||||
virtual ~IBonusTypeHandler() = default;
|
||||
|
||||
virtual std::string bonusToString(const std::shared_ptr<Bonus> & bonus, const IBonusBearer * bearer, bool description) const = 0;
|
||||
virtual std::string bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const = 0;
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include "CGameState.h"
|
||||
#include "mapping/CMap.h"
|
||||
#include "CPlayerState.h"
|
||||
#include "CSkillHandler.h"
|
||||
#include "ScriptHandler.h"
|
||||
#include "RoadHandler.h"
|
||||
#include "RiverHandler.h"
|
||||
@@ -43,11 +42,12 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
|
||||
{
|
||||
std::vector<int> floors;
|
||||
floors.reserve(gs->map->levels());
|
||||
for(int b = 0; b < gs->map->levels(); ++b)
|
||||
{
|
||||
floors.push_back(b);
|
||||
}
|
||||
const TerrainTile *tinfo;
|
||||
const TerrainTile * tinfo = nullptr;
|
||||
for (auto zd : floors)
|
||||
{
|
||||
for (int xd = 0; xd < gs->map->width; xd++)
|
||||
@@ -56,13 +56,18 @@ void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
|
||||
{
|
||||
tinfo = getTile(int3 (xd,yd,zd));
|
||||
if (tinfo->terType->isLand() && tinfo->terType->isPassable() && !tinfo->blocked) //land and free
|
||||
tiles.push_back (int3 (xd,yd,zd));
|
||||
tiles.emplace_back(xd, yd, zd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles, int3 pos, int radious, boost::optional<PlayerColor> player, int mode, int3::EDistanceFormula distanceFormula) const
|
||||
void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
|
||||
const int3 & pos,
|
||||
int radious,
|
||||
boost::optional<PlayerColor> player,
|
||||
int mode,
|
||||
int3::EDistanceFormula distanceFormula) const
|
||||
{
|
||||
if(!!player && *player >= PlayerColor::PLAYER_LIMIT)
|
||||
{
|
||||
@@ -147,7 +152,7 @@ void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3, ShashInt3> &
|
||||
}
|
||||
}
|
||||
|
||||
void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand)
|
||||
void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand) const
|
||||
{
|
||||
for (int j = 0; j < 3 ; j++)
|
||||
out.push_back(VLC->arth->objects[VLC->arth->pickRandomArtifact(rand, CArtifact::ART_TREASURE)]);
|
||||
@@ -182,7 +187,7 @@ void CPrivilegedInfoCallback::loadCommonState(Loader & in)
|
||||
in.checkMagicBytes(SAVEGAME_MAGIC);
|
||||
|
||||
CMapHeader dum;
|
||||
StartInfo *si;
|
||||
StartInfo * si = nullptr;
|
||||
|
||||
logGlobal->info("\tReading header");
|
||||
in.serializer & dum;
|
||||
@@ -217,49 +222,49 @@ template DLL_LINKAGE void CPrivilegedInfoCallback::loadCommonState<CLoadIntegrit
|
||||
template DLL_LINKAGE void CPrivilegedInfoCallback::loadCommonState<CLoadFile>(CLoadFile &);
|
||||
template DLL_LINKAGE void CPrivilegedInfoCallback::saveCommonState<CSaveFile>(CSaveFile &) const;
|
||||
|
||||
TerrainTile * CNonConstInfoCallback::getTile( int3 pos )
|
||||
TerrainTile * CNonConstInfoCallback::getTile(const int3 & pos)
|
||||
{
|
||||
if(!gs->map->isInTheMap(pos))
|
||||
return nullptr;
|
||||
return &gs->map->getTile(pos);
|
||||
}
|
||||
|
||||
CGHeroInstance *CNonConstInfoCallback::getHero(ObjectInstanceID objid)
|
||||
CGHeroInstance * CNonConstInfoCallback::getHero(const ObjectInstanceID & objid)
|
||||
{
|
||||
return const_cast<CGHeroInstance*>(CGameInfoCallback::getHero(objid));
|
||||
}
|
||||
|
||||
CGTownInstance *CNonConstInfoCallback::getTown(ObjectInstanceID objid)
|
||||
CGTownInstance * CNonConstInfoCallback::getTown(const ObjectInstanceID & objid)
|
||||
{
|
||||
return const_cast<CGTownInstance*>(CGameInfoCallback::getTown(objid));
|
||||
}
|
||||
|
||||
TeamState *CNonConstInfoCallback::getTeam(TeamID teamID)
|
||||
TeamState * CNonConstInfoCallback::getTeam(const TeamID & teamID)
|
||||
{
|
||||
return const_cast<TeamState*>(CGameInfoCallback::getTeam(teamID));
|
||||
}
|
||||
|
||||
TeamState *CNonConstInfoCallback::getPlayerTeam(PlayerColor color)
|
||||
TeamState * CNonConstInfoCallback::getPlayerTeam(const PlayerColor & color)
|
||||
{
|
||||
return const_cast<TeamState*>(CGameInfoCallback::getPlayerTeam(color));
|
||||
}
|
||||
|
||||
PlayerState * CNonConstInfoCallback::getPlayerState( PlayerColor color, bool verbose )
|
||||
PlayerState * CNonConstInfoCallback::getPlayerState(const PlayerColor & color, bool verbose)
|
||||
{
|
||||
return const_cast<PlayerState*>(CGameInfoCallback::getPlayerState(color, verbose));
|
||||
}
|
||||
|
||||
CArtifactInstance * CNonConstInfoCallback::getArtInstance( ArtifactInstanceID aid )
|
||||
CArtifactInstance * CNonConstInfoCallback::getArtInstance(const ArtifactInstanceID & aid)
|
||||
{
|
||||
return gs->map->artInstances.at(aid.num);
|
||||
}
|
||||
|
||||
CGObjectInstance * CNonConstInfoCallback::getObjInstance( ObjectInstanceID oid )
|
||||
CGObjectInstance * CNonConstInfoCallback::getObjInstance(const ObjectInstanceID & oid)
|
||||
{
|
||||
return gs->map->objects.at(oid.num);
|
||||
}
|
||||
|
||||
CArmedInstance * CNonConstInfoCallback::getArmyInstance(ObjectInstanceID oid)
|
||||
CArmedInstance * CNonConstInfoCallback::getArmyInstance(const ObjectInstanceID & oid)
|
||||
{
|
||||
return dynamic_cast<CArmedInstance *>(getObjInstance(oid));
|
||||
}
|
||||
|
@@ -54,16 +54,19 @@ public:
|
||||
void getFreeTiles(std::vector<int3> &tiles) const;
|
||||
|
||||
//mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
|
||||
void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious,
|
||||
boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode = 0,
|
||||
void getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
|
||||
const int3 & pos,
|
||||
int radious,
|
||||
boost::optional<PlayerColor> player = boost::optional<PlayerColor>(),
|
||||
int mode = 0,
|
||||
int3::EDistanceFormula formula = int3::DIST_2D) const;
|
||||
|
||||
//returns all tiles on given level (-1 - both levels, otherwise number of level)
|
||||
void getAllTiles(std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(),
|
||||
int level = -1, MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode::NONE) const;
|
||||
|
||||
void pickAllowedArtsSet(std::vector<const CArtifact *> &out,
|
||||
CRandomGenerator &rand); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
|
||||
//gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
|
||||
void pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand) const;
|
||||
void getAllowedSpells(std::vector<SpellID> &out, ui16 level);
|
||||
|
||||
template<typename Saver>
|
||||
@@ -144,15 +147,15 @@ public:
|
||||
using CGameInfoCallback::getArtInstance;
|
||||
using CGameInfoCallback::getObjInstance;
|
||||
|
||||
PlayerState * getPlayerState(PlayerColor color, bool verbose = true);
|
||||
TeamState *getTeam(TeamID teamID);//get team by team ID
|
||||
TeamState *getPlayerTeam(PlayerColor color);// get team by player color
|
||||
CGHeroInstance *getHero(ObjectInstanceID objid);
|
||||
CGTownInstance *getTown(ObjectInstanceID objid);
|
||||
TerrainTile * getTile(int3 pos);
|
||||
CArtifactInstance * getArtInstance(ArtifactInstanceID aid);
|
||||
CGObjectInstance * getObjInstance(ObjectInstanceID oid);
|
||||
CArmedInstance * getArmyInstance(ObjectInstanceID oid);
|
||||
PlayerState * getPlayerState(const PlayerColor & color, bool verbose = true);
|
||||
TeamState * getTeam(const TeamID & teamID); //get team by team ID
|
||||
TeamState * getPlayerTeam(const PlayerColor & color); // get team by player color
|
||||
CGHeroInstance * getHero(const ObjectInstanceID & objid);
|
||||
CGTownInstance * getTown(const ObjectInstanceID & objid);
|
||||
TerrainTile * getTile(const int3 & pos);
|
||||
CArtifactInstance * getArtInstance(const ArtifactInstanceID & aid);
|
||||
CGObjectInstance * getObjInstance(const ObjectInstanceID & oid);
|
||||
CArmedInstance * getArmyInstance(const ObjectInstanceID & oid);
|
||||
|
||||
virtual void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) = 0;
|
||||
};
|
||||
|
@@ -14,12 +14,12 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
std::string IHandlerBase::getScopeBuiltin() const
|
||||
std::string IHandlerBase::getScopeBuiltin()
|
||||
{
|
||||
return CModHandler::scopeBuiltin();
|
||||
}
|
||||
|
||||
void IHandlerBase::registerObject(std::string scope, std::string type_name, std::string name, si32 index)
|
||||
void IHandlerBase::registerObject(const std::string & scope, const std::string & type_name, const std::string & name, si32 index)
|
||||
{
|
||||
return VLC->modh->identifiers.registerObject(scope, type_name, name, index);
|
||||
}
|
||||
|
@@ -21,10 +21,11 @@ class Entity;
|
||||
class DLL_LINKAGE IHandlerBase
|
||||
{
|
||||
protected:
|
||||
std::string getScopeBuiltin() const;
|
||||
static std::string getScopeBuiltin();
|
||||
|
||||
/// Calls modhandler. Mostly needed to avoid large number of includes in headers
|
||||
void registerObject(std::string scope, std::string type_name, std::string name, si32 index);
|
||||
static void registerObject(const std::string & scope, const std::string & type_name, const std::string & name, si32 index);
|
||||
|
||||
public:
|
||||
/// loads all original game data in vector of json nodes
|
||||
/// dataSize - is number of items that must be loaded (normally - constant from GameConstants)
|
||||
|
@@ -77,7 +77,8 @@ void JsonWriter::writeString(const std::string &string)
|
||||
static const std::array<char, 8> escaped_code = {'\"', '\\', 'b', 'f', 'n', 'r', 't', '/'};
|
||||
|
||||
out <<'\"';
|
||||
size_t pos=0, start=0;
|
||||
size_t pos = 0;
|
||||
size_t start = 0;
|
||||
for (; pos<string.size(); pos++)
|
||||
{
|
||||
//we need to check if special character was been already escaped
|
||||
@@ -159,7 +160,7 @@ JsonParser::JsonParser(const char * inputString, size_t stringSize):
|
||||
{
|
||||
}
|
||||
|
||||
JsonNode JsonParser::parse(std::string fileName)
|
||||
JsonNode JsonParser::parse(const std::string & fileName)
|
||||
{
|
||||
JsonNode root;
|
||||
|
||||
@@ -232,7 +233,7 @@ bool JsonParser::extractWhitespace(bool verbose)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
while (pos < input.size() && (ui8)input[pos] <= ' ')
|
||||
while(pos < input.size() && static_cast<ui8>(input[pos]) <= ' ')
|
||||
{
|
||||
if (input[pos] == '\n')
|
||||
{
|
||||
@@ -308,7 +309,7 @@ bool JsonParser::extractString(std::string &str)
|
||||
str.append( &input[first], pos-first);
|
||||
return error("Closing quote not found!", true);
|
||||
}
|
||||
if ((unsigned char)(input[pos]) < ' ') // control character
|
||||
if(static_cast<unsigned char>(input[pos]) < ' ') // control character
|
||||
{
|
||||
str.append( &input[first], pos-first);
|
||||
first = pos+1;
|
||||
@@ -616,24 +617,31 @@ namespace
|
||||
{
|
||||
namespace Common
|
||||
{
|
||||
std::string emptyCheck(Validation::ValidationData &, const JsonNode &, const JsonNode &, const JsonNode &)
|
||||
std::string emptyCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
// check is not needed - e.g. incorporated into another check
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string notImplementedCheck(Validation::ValidationData &, const JsonNode &, const JsonNode &, const JsonNode &)
|
||||
std::string notImplementedCheck(Validation::ValidationData & validator,
|
||||
const JsonNode & baseSchema,
|
||||
const JsonNode & schema,
|
||||
const JsonNode & data)
|
||||
{
|
||||
return "Not implemented entry in schema";
|
||||
}
|
||||
|
||||
std::string schemaListCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data,
|
||||
std::string errorMsg, std::function<bool(size_t)> isValid)
|
||||
std::string schemaListCheck(Validation::ValidationData & validator,
|
||||
const JsonNode & baseSchema,
|
||||
const JsonNode & schema,
|
||||
const JsonNode & data,
|
||||
const std::string & errorMsg,
|
||||
const std::function<bool(size_t)> & isValid)
|
||||
{
|
||||
std::string errors = "<tested schemas>\n";
|
||||
size_t result = 0;
|
||||
|
||||
for(auto & schemaEntry : schema.Vector())
|
||||
for(const auto & schemaEntry : schema.Vector())
|
||||
{
|
||||
std::string error = check(schemaEntry, data, validator);
|
||||
if (error.empty())
|
||||
@@ -685,7 +693,7 @@ namespace
|
||||
|
||||
std::string enumCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
for(auto & enumEntry : schema.Vector())
|
||||
for(const auto & enumEntry : schema.Vector())
|
||||
{
|
||||
if (data == enumEntry)
|
||||
return "";
|
||||
@@ -695,7 +703,7 @@ namespace
|
||||
|
||||
std::string typeCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
const auto typeName = schema.String();
|
||||
const auto & typeName = schema.String();
|
||||
auto it = stringToType.find(typeName);
|
||||
if(it == stringToType.end())
|
||||
{
|
||||
@@ -801,9 +809,9 @@ namespace
|
||||
|
||||
namespace Vector
|
||||
{
|
||||
std::string itemEntryCheck(Validation::ValidationData & validator, const JsonVector items, const JsonNode & schema, size_t index)
|
||||
std::string itemEntryCheck(Validation::ValidationData & validator, const JsonVector & items, const JsonNode & schema, size_t index)
|
||||
{
|
||||
validator.currentPath.push_back(JsonNode());
|
||||
validator.currentPath.emplace_back();
|
||||
validator.currentPath.back().Float() = static_cast<double>(index);
|
||||
auto onExit = vstd::makeScopeGuard([&]()
|
||||
{
|
||||
@@ -845,7 +853,7 @@ namespace
|
||||
{
|
||||
if (schema.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
errors += itemEntryCheck(validator, data.Vector(), schema, i);
|
||||
else if (!schema.isNull() && schema.Bool() == false)
|
||||
else if(!schema.isNull() && !schema.Bool())
|
||||
errors += validator.makeErrorMessage("Unknown entry found");
|
||||
}
|
||||
return errors;
|
||||
@@ -916,7 +924,7 @@ namespace
|
||||
std::string requiredCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
std::string errors;
|
||||
for(auto & required : schema.Vector())
|
||||
for(const auto & required : schema.Vector())
|
||||
{
|
||||
if (data[required.String()].isNull())
|
||||
errors += validator.makeErrorMessage("Required entry " + required.String() + " is missing");
|
||||
@@ -927,7 +935,7 @@ namespace
|
||||
std::string dependenciesCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
std::string errors;
|
||||
for(auto & deps : schema.Struct())
|
||||
for(const auto & deps : schema.Struct())
|
||||
{
|
||||
if (!data[deps.first].isNull())
|
||||
{
|
||||
@@ -950,9 +958,9 @@ namespace
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::string propertyEntryCheck(Validation::ValidationData & validator, const JsonNode &node, const JsonNode & schema, std::string nodeName)
|
||||
std::string propertyEntryCheck(Validation::ValidationData & validator, const JsonNode &node, const JsonNode & schema, const std::string & nodeName)
|
||||
{
|
||||
validator.currentPath.push_back(JsonNode());
|
||||
validator.currentPath.emplace_back();
|
||||
validator.currentPath.back().String() = nodeName;
|
||||
auto onExit = vstd::makeScopeGuard([&]()
|
||||
{
|
||||
@@ -969,7 +977,7 @@ namespace
|
||||
{
|
||||
std::string errors;
|
||||
|
||||
for(auto & entry : data.Struct())
|
||||
for(const auto & entry : data.Struct())
|
||||
errors += propertyEntryCheck(validator, entry.second, schema[entry.first], entry.first);
|
||||
return errors;
|
||||
}
|
||||
@@ -977,7 +985,7 @@ namespace
|
||||
std::string additionalPropertiesCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
std::string errors;
|
||||
for(auto & entry : data.Struct())
|
||||
for(const auto & entry : data.Struct())
|
||||
{
|
||||
if (baseSchema["properties"].Struct().count(entry.first) == 0)
|
||||
{
|
||||
@@ -986,7 +994,7 @@ namespace
|
||||
errors += propertyEntryCheck(validator, entry.second, schema, entry.first);
|
||||
|
||||
// or, additionalItems field can be bool which indicates if such items are allowed
|
||||
else if (!schema.isNull() && schema.Bool() == false) // present and set to false - error
|
||||
else if(!schema.isNull() && !schema.Bool()) // present and set to false - error
|
||||
errors += validator.makeErrorMessage("Unknown entry found: " + entry.first);
|
||||
}
|
||||
}
|
||||
@@ -996,7 +1004,7 @@ namespace
|
||||
|
||||
namespace Formats
|
||||
{
|
||||
bool testFilePresence(std::string scope, ResourceID resource)
|
||||
bool testFilePresence(const std::string & scope, const ResourceID & resource)
|
||||
{
|
||||
std::set<std::string> allowedScopes;
|
||||
if(scope != CModHandler::scopeBuiltin() && !scope.empty()) // all real mods may have dependencies
|
||||
@@ -1012,7 +1020,7 @@ namespace
|
||||
}
|
||||
allowedScopes.insert(scope); // mods can use their own files
|
||||
|
||||
for (auto & entry : allowedScopes)
|
||||
for(const auto & entry : allowedScopes)
|
||||
{
|
||||
if (CResourceHandler::get(entry)->existsResource(resource))
|
||||
return true;
|
||||
@@ -1024,7 +1032,7 @@ namespace
|
||||
if (testFilePresence(scope, ResourceID(prefix + file, type))) \
|
||||
return ""
|
||||
|
||||
std::string testAnimation(std::string path, std::string scope)
|
||||
std::string testAnimation(const std::string & path, const std::string & scope)
|
||||
{
|
||||
TEST_FILE(scope, "Sprites/", path, EResType::ANIMATION);
|
||||
TEST_FILE(scope, "Sprites/", path, EResType::TEXT);
|
||||
@@ -1186,13 +1194,13 @@ namespace Validation
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::string check(std::string schemaName, const JsonNode & data)
|
||||
std::string check(const std::string & schemaName, const JsonNode & data)
|
||||
{
|
||||
ValidationData validator;
|
||||
return check(schemaName, data, validator);
|
||||
}
|
||||
|
||||
std::string check(std::string schemaName, const JsonNode & data, ValidationData & validator)
|
||||
std::string check(const std::string & schemaName, const JsonNode & data, ValidationData & validator)
|
||||
{
|
||||
validator.usedSchemas.push_back(schemaName);
|
||||
auto onscopeExit = vstd::makeScopeGuard([&]()
|
||||
@@ -1206,7 +1214,7 @@ namespace Validation
|
||||
{
|
||||
const TValidatorMap & knownFields = getKnownFieldsFor(data.getType());
|
||||
std::string errors;
|
||||
for(auto & entry : schema.Struct())
|
||||
for(const auto & entry : schema.Struct())
|
||||
{
|
||||
auto checker = knownFields.find(entry.first);
|
||||
if (checker != knownFields.end())
|
||||
|
@@ -92,7 +92,7 @@ public:
|
||||
JsonParser(const char * inputString, size_t stringSize);
|
||||
|
||||
/// do actual parsing. filename is name of file that will printed to console if any errors were found
|
||||
JsonNode parse(std::string fileName);
|
||||
JsonNode parse(const std::string & fileName);
|
||||
|
||||
/// returns true if parsing was successful
|
||||
bool isValid();
|
||||
@@ -125,8 +125,8 @@ namespace Validation
|
||||
const TValidatorMap & getKnownFieldsFor(JsonNode::JsonType type);
|
||||
const TFormatMap & getKnownFormats();
|
||||
|
||||
std::string check(std::string schemaName, const JsonNode & data);
|
||||
std::string check(std::string schemaName, const JsonNode & data, ValidationData & validator);
|
||||
std::string check(const std::string & schemaName, const JsonNode & data);
|
||||
std::string check(const std::string & schemaName, const JsonNode & data, ValidationData & validator);
|
||||
std::string check(const JsonNode & schema, const JsonNode & data, ValidationData & validator);
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ Node & resolvePointer(Node & in, const std::string & pointer)
|
||||
if(entry.size() > 1 && entry[0] == '0') // leading zeros are not allowed
|
||||
throw std::runtime_error("Invalid Json pointer");
|
||||
|
||||
size_t index = boost::lexical_cast<size_t>(entry);
|
||||
auto index = boost::lexical_cast<size_t>(entry);
|
||||
|
||||
if (in.Vector().size() > index)
|
||||
return in.Vector()[index].resolvePointer(remainer);
|
||||
@@ -178,7 +178,7 @@ JsonNode::JsonType JsonNode::getType() const
|
||||
return type;
|
||||
}
|
||||
|
||||
void JsonNode::setMeta(std::string metadata, bool recursive)
|
||||
void JsonNode::setMeta(const std::string & metadata, bool recursive)
|
||||
{
|
||||
meta = metadata;
|
||||
if (recursive)
|
||||
@@ -218,7 +218,7 @@ void JsonNode::setType(JsonType Type)
|
||||
}
|
||||
else if(type == JsonType::DATA_INTEGER && Type == JsonType::DATA_FLOAT)
|
||||
{
|
||||
double converted = static_cast<double>(data.Integer);
|
||||
auto converted = static_cast<double>(data.Integer);
|
||||
type = Type;
|
||||
data.Float = converted;
|
||||
return;
|
||||
@@ -282,7 +282,7 @@ bool JsonNode::containsBaseData() const
|
||||
case JsonType::DATA_NULL:
|
||||
return false;
|
||||
case JsonType::DATA_STRUCT:
|
||||
for(auto elem : *data.Struct)
|
||||
for(const auto & elem : *data.Struct)
|
||||
{
|
||||
if(elem.second.containsBaseData())
|
||||
return true;
|
||||
@@ -442,12 +442,12 @@ const JsonMap & JsonNode::Struct() const
|
||||
return *data.Struct;
|
||||
}
|
||||
|
||||
JsonNode & JsonNode::operator[](std::string child)
|
||||
JsonNode & JsonNode::operator[](const std::string & child)
|
||||
{
|
||||
return Struct()[child];
|
||||
}
|
||||
|
||||
const JsonNode & JsonNode::operator[](std::string child) const
|
||||
const JsonNode & JsonNode::operator[](const std::string & child) const
|
||||
{
|
||||
auto it = Struct().find(child);
|
||||
if (it != Struct().end())
|
||||
@@ -475,7 +475,7 @@ std::string JsonNode::toJson(bool compact) const
|
||||
|
||||
///JsonUtils
|
||||
|
||||
void JsonUtils::parseTypedBonusShort(const JsonVector& source, std::shared_ptr<Bonus> dest)
|
||||
void JsonUtils::parseTypedBonusShort(const JsonVector & source, const std::shared_ptr<Bonus> & dest)
|
||||
{
|
||||
dest->val = static_cast<si32>(source[1].Float());
|
||||
resolveIdentifier(source[2],dest->subtype);
|
||||
@@ -501,12 +501,12 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonVector & ability_vec)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, std::string err)
|
||||
const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, const std::string & err)
|
||||
{
|
||||
static T defaultValue = T();
|
||||
if (!val->isNull())
|
||||
{
|
||||
std::string type = val->String();
|
||||
const std::string & type = val->String();
|
||||
auto it = map.find(type);
|
||||
if (it == map.end())
|
||||
{
|
||||
@@ -523,7 +523,7 @@ const T parseByMap(const std::map<std::string, T> & map, const JsonNode * val, s
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T parseByMapN(const std::map<std::string, T> & map, const JsonNode * val, std::string err)
|
||||
const T parseByMapN(const std::map<std::string, T> & map, const JsonNode * val, const std::string & err)
|
||||
{
|
||||
if(val->isNumber())
|
||||
return static_cast<T>(val->Integer());
|
||||
@@ -531,7 +531,7 @@ const T parseByMapN(const std::map<std::string, T> & map, const JsonNode * val,
|
||||
return parseByMap<T>(map, val, err);
|
||||
}
|
||||
|
||||
void JsonUtils::resolveIdentifier(si32 &var, const JsonNode &node, std::string name)
|
||||
void JsonUtils::resolveIdentifier(si32 & var, const JsonNode & node, const std::string & name)
|
||||
{
|
||||
const JsonNode &value = node[name];
|
||||
if (!value.isNull())
|
||||
@@ -635,7 +635,7 @@ std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
{
|
||||
const JsonVector & subLimiters = limiter.Vector();
|
||||
if(subLimiters.size() == 0)
|
||||
if(subLimiters.empty())
|
||||
{
|
||||
logMod->warn("Warning: empty limiter list");
|
||||
return std::make_shared<AllOfLimiter>();
|
||||
@@ -760,7 +760,7 @@ std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
|
||||
else if(limiterType == "CREATURE_TERRAIN_LIMITER")
|
||||
{
|
||||
std::shared_ptr<CreatureTerrainLimiter> terrainLimiter = std::make_shared<CreatureTerrainLimiter>();
|
||||
if(parameters.size())
|
||||
if(!parameters.empty())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("terrain", parameters[0], [=](si32 terrain)
|
||||
{
|
||||
@@ -792,7 +792,7 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonNode &ability)
|
||||
return b;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> JsonUtils::parseBuildingBonus(const JsonNode &ability, BuildingID building, std::string description)
|
||||
std::shared_ptr<Bonus> JsonUtils::parseBuildingBonus(const JsonNode & ability, const BuildingID & building, const std::string & description)
|
||||
{
|
||||
/* duration = Bonus::PERMANENT
|
||||
source = Bonus::TOWN_STRUCTURE
|
||||
@@ -891,7 +891,7 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||
|
||||
bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
||||
{
|
||||
const JsonNode *value;
|
||||
const JsonNode * value = nullptr;
|
||||
|
||||
std::string type = ability["type"].String();
|
||||
auto it = bonusNameMap.find(type);
|
||||
@@ -950,7 +950,7 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
||||
switch (value->getType())
|
||||
{
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
b->duration = (Bonus::BonusDuration)parseByMap(bonusDurationMap, value, "duration type ");
|
||||
b->duration = static_cast<Bonus::BonusDuration>(parseByMap(bonusDurationMap, value, "duration type "));
|
||||
break;
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
{
|
||||
@@ -959,7 +959,7 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
||||
{
|
||||
dur |= parseByMapN(bonusDurationMap, &d, "duration type ");
|
||||
}
|
||||
b->duration = (Bonus::BonusDuration)dur;
|
||||
b->duration = static_cast<Bonus::BonusDuration>(dur);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1126,9 +1126,9 @@ void minimizeNode(JsonNode & node, const JsonNode & schema)
|
||||
{
|
||||
std::set<std::string> foundEntries;
|
||||
|
||||
for(auto & entry : schema["required"].Vector())
|
||||
for(const auto & entry : schema["required"].Vector())
|
||||
{
|
||||
std::string name = entry.String();
|
||||
const std::string & name = entry.String();
|
||||
foundEntries.insert(name);
|
||||
|
||||
minimizeNode(node[name], schema["properties"][name]);
|
||||
@@ -1151,7 +1151,7 @@ void minimizeNode(JsonNode & node, const JsonNode & schema)
|
||||
}
|
||||
}
|
||||
|
||||
void JsonUtils::minimize(JsonNode & node, std::string schemaName)
|
||||
void JsonUtils::minimize(JsonNode & node, const std::string & schemaName)
|
||||
{
|
||||
minimizeNode(node, getSchema(schemaName));
|
||||
}
|
||||
@@ -1165,9 +1165,9 @@ void maximizeNode(JsonNode & node, const JsonNode & schema)
|
||||
std::set<std::string> foundEntries;
|
||||
|
||||
// check all required entries that have default version
|
||||
for(auto & entry : schema["required"].Vector())
|
||||
for(const auto & entry : schema["required"].Vector())
|
||||
{
|
||||
std::string name = entry.String();
|
||||
const std::string & name = entry.String();
|
||||
foundEntries.insert(name);
|
||||
|
||||
if (node[name].isNull() &&
|
||||
@@ -1189,12 +1189,12 @@ void maximizeNode(JsonNode & node, const JsonNode & schema)
|
||||
}
|
||||
}
|
||||
|
||||
void JsonUtils::maximize(JsonNode & node, std::string schemaName)
|
||||
void JsonUtils::maximize(JsonNode & node, const std::string & schemaName)
|
||||
{
|
||||
maximizeNode(node, getSchema(schemaName));
|
||||
}
|
||||
|
||||
bool JsonUtils::validate(const JsonNode &node, std::string schemaName, std::string dataName)
|
||||
bool JsonUtils::validate(const JsonNode & node, const std::string & schemaName, const std::string & dataName)
|
||||
{
|
||||
std::string log = Validation::check(schemaName, node);
|
||||
if (!log.empty())
|
||||
@@ -1206,7 +1206,7 @@ bool JsonUtils::validate(const JsonNode &node, std::string schemaName, std::stri
|
||||
return log.empty();
|
||||
}
|
||||
|
||||
const JsonNode & getSchemaByName(std::string name)
|
||||
const JsonNode & getSchemaByName(const std::string & name)
|
||||
{
|
||||
// cached schemas to avoid loading json data multiple times
|
||||
static std::map<std::string, JsonNode> loadedSchemas;
|
||||
@@ -1227,7 +1227,7 @@ const JsonNode & getSchemaByName(std::string name)
|
||||
return nullNode;
|
||||
}
|
||||
|
||||
const JsonNode & JsonUtils::getSchema(std::string URI)
|
||||
const JsonNode & JsonUtils::getSchema(const std::string & URI)
|
||||
{
|
||||
size_t posColon = URI.find(':');
|
||||
size_t posHash = URI.find('#');
|
||||
@@ -1312,7 +1312,7 @@ void JsonUtils::inherit(JsonNode & descendant, const JsonNode & base)
|
||||
|
||||
JsonNode JsonUtils::intersect(const std::vector<JsonNode> & nodes, bool pruneEmpty)
|
||||
{
|
||||
if(nodes.size() == 0)
|
||||
if(nodes.empty())
|
||||
return nullNode;
|
||||
|
||||
JsonNode result = nodes[0];
|
||||
@@ -1331,7 +1331,7 @@ JsonNode JsonUtils::intersect(const JsonNode & a, const JsonNode & b, bool prune
|
||||
{
|
||||
// intersect individual properties
|
||||
JsonNode result(JsonNode::JsonType::DATA_STRUCT);
|
||||
for(auto property : a.Struct())
|
||||
for(const auto & property : a.Struct())
|
||||
{
|
||||
if(vstd::contains(b.Struct(), property.first))
|
||||
{
|
||||
@@ -1361,7 +1361,7 @@ JsonNode JsonUtils::difference(const JsonNode & node, const JsonNode & base)
|
||||
case JsonNode::JsonType::DATA_NULL:
|
||||
return false;
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
return diff.Struct().size() > 0;
|
||||
return !diff.Struct().empty();
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@@ -1371,7 +1371,7 @@ JsonNode JsonUtils::difference(const JsonNode & node, const JsonNode & base)
|
||||
{
|
||||
// subtract individual properties
|
||||
JsonNode result(JsonNode::JsonType::DATA_STRUCT);
|
||||
for(auto property : node.Struct())
|
||||
for(const auto & property : node.Struct())
|
||||
{
|
||||
if(vstd::contains(base.Struct(), property.first))
|
||||
{
|
||||
@@ -1394,20 +1394,20 @@ JsonNode JsonUtils::difference(const JsonNode & node, const JsonNode & base)
|
||||
return node;
|
||||
}
|
||||
|
||||
JsonNode JsonUtils::assembleFromFiles(std::vector<std::string> files)
|
||||
JsonNode JsonUtils::assembleFromFiles(const std::vector<std::string> & files)
|
||||
{
|
||||
bool isValid;
|
||||
bool isValid = false;
|
||||
return assembleFromFiles(files, isValid);
|
||||
}
|
||||
|
||||
JsonNode JsonUtils::assembleFromFiles(std::vector<std::string> files, bool &isValid)
|
||||
JsonNode JsonUtils::assembleFromFiles(const std::vector<std::string> & files, bool & isValid)
|
||||
{
|
||||
isValid = true;
|
||||
JsonNode result;
|
||||
|
||||
for(std::string file : files)
|
||||
for(const std::string & file : files)
|
||||
{
|
||||
bool isValidFile;
|
||||
bool isValidFile = false;
|
||||
JsonNode section(ResourceID(file, EResType::TEXT), isValidFile);
|
||||
merge(result, section);
|
||||
isValid |= isValidFile;
|
||||
@@ -1415,7 +1415,7 @@ JsonNode JsonUtils::assembleFromFiles(std::vector<std::string> files, bool &isVa
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonNode JsonUtils::assembleFromFiles(std::string filename)
|
||||
JsonNode JsonUtils::assembleFromFiles(const std::string & filename)
|
||||
{
|
||||
JsonNode result;
|
||||
ResourceID resID(filename, EResType::TEXT);
|
||||
@@ -1427,7 +1427,7 @@ JsonNode JsonUtils::assembleFromFiles(std::string filename)
|
||||
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
|
||||
stream->read(textData.get(), stream->getSize());
|
||||
|
||||
JsonNode section((char*)textData.get(), stream->getSize());
|
||||
JsonNode section(reinterpret_cast<char *>(textData.get()), stream->getSize());
|
||||
merge(result, section);
|
||||
}
|
||||
return result;
|
||||
@@ -1447,7 +1447,7 @@ DLL_LINKAGE JsonNode JsonUtils::floatNode(double value)
|
||||
return node;
|
||||
}
|
||||
|
||||
DLL_LINKAGE JsonNode JsonUtils::stringNode(std::string value)
|
||||
DLL_LINKAGE JsonNode JsonUtils::stringNode(const std::string & value)
|
||||
{
|
||||
JsonNode node;
|
||||
node.String() = value;
|
||||
|
@@ -76,7 +76,7 @@ public:
|
||||
bool operator == (const JsonNode &other) const;
|
||||
bool operator != (const JsonNode &other) const;
|
||||
|
||||
void setMeta(std::string metadata, bool recursive = true);
|
||||
void setMeta(const std::string & metadata, bool recursive = true);
|
||||
|
||||
/// Convert node to another type. Converting to nullptr will clear all data
|
||||
void setType(JsonType Type);
|
||||
@@ -126,8 +126,8 @@ public:
|
||||
Type convertTo() const;
|
||||
|
||||
//operator [], for structs only - get child node by name
|
||||
JsonNode & operator[](std::string child);
|
||||
const JsonNode & operator[](std::string child) const;
|
||||
JsonNode & operator[](const std::string & child);
|
||||
const JsonNode & operator[](const std::string & child) const;
|
||||
|
||||
std::string toJson(bool compact = false) const;
|
||||
|
||||
@@ -168,17 +168,17 @@ namespace JsonUtils
|
||||
* @brief parse short bonus format, excluding type
|
||||
* @note sets duration to Permament
|
||||
*/
|
||||
DLL_LINKAGE void parseTypedBonusShort(const JsonVector &source, std::shared_ptr<Bonus> dest);
|
||||
DLL_LINKAGE void parseTypedBonusShort(const JsonVector & source, const std::shared_ptr<Bonus> & dest);
|
||||
|
||||
///
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonVector &ability_vec);
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonNode &ability);
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBuildingBonus(const JsonNode &ability, BuildingID building, std::string description);
|
||||
DLL_LINKAGE bool parseBonus(const JsonNode &ability, Bonus *placement);
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonVector & ability_vec);
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonNode & ability);
|
||||
DLL_LINKAGE std::shared_ptr<Bonus> parseBuildingBonus(const JsonNode & ability, const BuildingID & building, const std::string & description);
|
||||
DLL_LINKAGE bool parseBonus(const JsonNode & ability, Bonus * placement);
|
||||
DLL_LINKAGE std::shared_ptr<ILimiter> parseLimiter(const JsonNode & limiter);
|
||||
DLL_LINKAGE CSelector parseSelector(const JsonNode &ability);
|
||||
DLL_LINKAGE void resolveIdentifier(si32 &var, const JsonNode &node, std::string name);
|
||||
DLL_LINKAGE void resolveIdentifier(const JsonNode &node, si32 &var);
|
||||
DLL_LINKAGE void resolveIdentifier(si32 & var, const JsonNode & node, const std::string & name);
|
||||
DLL_LINKAGE void resolveIdentifier(const JsonNode & node, si32 & var);
|
||||
DLL_LINKAGE void resolveAddInfo(CAddInfo & var, const JsonNode & node);
|
||||
|
||||
/**
|
||||
@@ -201,11 +201,9 @@ namespace JsonUtils
|
||||
*/
|
||||
DLL_LINKAGE void mergeCopy(JsonNode & dest, JsonNode source, bool ignoreOverride = false, bool copyMeta = false);
|
||||
|
||||
/** @brief recursively merges descendant into copy of base node
|
||||
* Result emulates inheritance semantic
|
||||
*
|
||||
*
|
||||
*/
|
||||
/** @brief recursively merges descendant into copy of base node
|
||||
* Result emulates inheritance semantic
|
||||
*/
|
||||
DLL_LINKAGE void inherit(JsonNode & descendant, const JsonNode & base);
|
||||
|
||||
/**
|
||||
@@ -228,11 +226,11 @@ namespace JsonUtils
|
||||
* @brief generate one Json structure from multiple files
|
||||
* @param files - list of filenames with parts of json structure
|
||||
*/
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(std::vector<std::string> files);
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(std::vector<std::string> files, bool & isValid);
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(const std::vector<std::string> & files);
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(const std::vector<std::string> & files, bool & isValid);
|
||||
|
||||
/// This version loads all files with same name (overridden by mods)
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(std::string filename);
|
||||
DLL_LINKAGE JsonNode assembleFromFiles(const std::string & filename);
|
||||
|
||||
/**
|
||||
* @brief removes all nodes that are identical to default entry in schema
|
||||
@@ -240,9 +238,9 @@ namespace JsonUtils
|
||||
* @param schemaName - name of schema to use
|
||||
* @note for minimizing data must be valid against given schema
|
||||
*/
|
||||
DLL_LINKAGE void minimize(JsonNode & node, std::string schemaName);
|
||||
DLL_LINKAGE void minimize(JsonNode & node, const std::string & schemaName);
|
||||
/// opposed to minimize, adds all missing, required entries that have default value
|
||||
DLL_LINKAGE void maximize(JsonNode & node, std::string schemaName);
|
||||
DLL_LINKAGE void maximize(JsonNode & node, const std::string & schemaName);
|
||||
|
||||
/**
|
||||
* @brief validate node against specified schema
|
||||
@@ -251,16 +249,16 @@ namespace JsonUtils
|
||||
* @param dataName - some way to identify data (printed in console in case of errors)
|
||||
* @returns true if data in node fully compilant with schema
|
||||
*/
|
||||
DLL_LINKAGE bool validate(const JsonNode & node, std::string schemaName, std::string dataName);
|
||||
DLL_LINKAGE bool validate(const JsonNode & node, const std::string & schemaName, const std::string & dataName);
|
||||
|
||||
/// get schema by json URI: vcmi:<name of file in schemas directory>#<entry in file, optional>
|
||||
/// example: schema "vcmi:settings" is used to check user settings
|
||||
DLL_LINKAGE const JsonNode & getSchema(std::string URI);
|
||||
DLL_LINKAGE const JsonNode & getSchema(const std::string & URI);
|
||||
|
||||
/// for easy construction of JsonNodes; helps with inserting primitives into vector node
|
||||
DLL_LINKAGE JsonNode boolNode(bool value);
|
||||
DLL_LINKAGE JsonNode floatNode(double value);
|
||||
DLL_LINKAGE JsonNode stringNode(std::string value);
|
||||
DLL_LINKAGE JsonNode stringNode(const std::string & value);
|
||||
DLL_LINKAGE JsonNode intNode(si64 value);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
std::string LogicalExpressionDetail::getTextForOperator(std::string operation)
|
||||
std::string LogicalExpressionDetail::getTextForOperator(const std::string & operation)
|
||||
{
|
||||
//placed in cpp mostly to avoid unnecessary includes in header
|
||||
return VLC->generaltexth->translate("vcmi.logicalExpressions." + operation);
|
||||
|
@@ -439,7 +439,7 @@ namespace LogicalExpressionDetail
|
||||
}
|
||||
};
|
||||
|
||||
std::string DLL_LINKAGE getTextForOperator(std::string operation);
|
||||
std::string DLL_LINKAGE getTextForOperator(const std::string & operation);
|
||||
|
||||
/// Prints expression in human-readable format
|
||||
template <typename ContainedClass>
|
||||
|
@@ -75,8 +75,8 @@ std::vector<BattleHex> ObstacleInfo::getBlocked(BattleHex hex) const
|
||||
|
||||
bool ObstacleInfo::isAppropriate(const TerrainId terrainType, const BattleField & battlefield) const
|
||||
{
|
||||
auto bgInfo = battlefield.getInfo();
|
||||
|
||||
const auto * bgInfo = battlefield.getInfo();
|
||||
|
||||
if(bgInfo->isSpecial)
|
||||
return vstd::contains(allowedSpecialBfields, bgInfo->identifier);
|
||||
|
||||
@@ -92,20 +92,20 @@ ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const Js
|
||||
info->animation = json["animation"].String();
|
||||
info->width = json["width"].Integer();
|
||||
info->height = json["height"].Integer();
|
||||
for(auto & t : json["allowedTerrains"].Vector())
|
||||
for(const auto & t : json["allowedTerrains"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("terrain", t, [info](int32_t identifier){
|
||||
info->allowedTerrains.emplace_back(identifier);
|
||||
});
|
||||
}
|
||||
for(auto & t : json["specialBattlefields"].Vector())
|
||||
for(const auto & t : json["specialBattlefields"].Vector())
|
||||
|
||||
info->allowedSpecialBfields.emplace_back(t.String());
|
||||
info->blockedTiles = json["blockedTiles"].convertTo<std::vector<si16>>();
|
||||
info->isAbsoluteObstacle = json["absolute"].Bool();
|
||||
|
||||
objects.push_back(info);
|
||||
|
||||
|
||||
objects.emplace_back(info);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@@ -26,15 +26,15 @@ Res::ResourceSet::ResourceSet()
|
||||
Res::ResourceSet::ResourceSet(const JsonNode & node)
|
||||
{
|
||||
reserve(GameConstants::RESOURCE_QUANTITY);
|
||||
for(std::string name : GameConstants::RESOURCE_NAMES)
|
||||
push_back((int)node[name].Float());
|
||||
for(const std::string & name : GameConstants::RESOURCE_NAMES)
|
||||
push_back(static_cast<int>(node[name].Float()));
|
||||
}
|
||||
|
||||
Res::ResourceSet::ResourceSet(TResource wood, TResource mercury, TResource ore, TResource sulfur, TResource crystal,
|
||||
TResource gems, TResource gold, TResource mithril)
|
||||
{
|
||||
resize(GameConstants::RESOURCE_QUANTITY);
|
||||
auto d = data();
|
||||
auto * d = data();
|
||||
d[Res::WOOD] = wood;
|
||||
d[Res::MERCURY] = mercury;
|
||||
d[Res::ORE] = ore;
|
||||
@@ -60,7 +60,7 @@ void Res::ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::s
|
||||
|
||||
bool Res::ResourceSet::nonZero() const
|
||||
{
|
||||
for(auto & elem : *this)
|
||||
for(const auto & elem : *this)
|
||||
if(elem)
|
||||
return true;
|
||||
|
||||
@@ -126,7 +126,7 @@ std::string Res::ResourceSet::toString() const
|
||||
return out.str();
|
||||
}
|
||||
|
||||
bool Res::ResourceSet::nziterator::valid()
|
||||
bool Res::ResourceSet::nziterator::valid() const
|
||||
{
|
||||
return cur.resType < GameConstants::RESOURCE_QUANTITY && cur.resVal;
|
||||
}
|
||||
|
@@ -155,7 +155,7 @@ namespace Res
|
||||
|
||||
public:
|
||||
nziterator(const ResourceSet &RS);
|
||||
bool valid();
|
||||
bool valid() const;
|
||||
nziterator operator++();
|
||||
nziterator operator++(int);
|
||||
const ResEntry& operator*() const;
|
||||
|
@@ -30,7 +30,7 @@ RiverType * RiverTypeHandler::loadFromJson(
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
|
||||
RiverType * info = new RiverType;
|
||||
auto * info = new RiverType;
|
||||
|
||||
info->id = RiverId(index);
|
||||
info->identifier = identifier;
|
||||
|
@@ -30,7 +30,7 @@ RoadType * RoadTypeHandler::loadFromJson(
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
|
||||
RoadType * info = new RoadType;
|
||||
auto * info = new RoadType;
|
||||
|
||||
info->id = RoadId(index);
|
||||
info->identifier = identifier;
|
||||
|
@@ -35,12 +35,10 @@ static const std::vector<std::string> IMPLEMENTS_MAP =
|
||||
namespace scripting
|
||||
{
|
||||
|
||||
ScriptImpl::ScriptImpl(const ScriptHandler * owner_)
|
||||
:owner(owner_),
|
||||
host(),
|
||||
ScriptImpl::ScriptImpl(const ScriptHandler * owner_):
|
||||
owner(owner_),
|
||||
implements(Implements::ANYTHING)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScriptImpl::~ScriptImpl() = default;
|
||||
@@ -97,7 +95,7 @@ void ScriptImpl::serializeJson(vstd::CLoggerBase * logger, JsonSerializeFormat &
|
||||
|
||||
auto rawData = CResourceHandler::get()->load(sourcePathId)->readAll();
|
||||
|
||||
sourceText = std::string((char *)rawData.first.get(), rawData.second);
|
||||
sourceText = std::string(reinterpret_cast<char *>(rawData.first.get()), rawData.second);
|
||||
|
||||
compile(logger);
|
||||
}
|
||||
@@ -149,7 +147,7 @@ std::shared_ptr<Context> PoolImpl::getContext(const Script * script)
|
||||
auto context = script->createContext(env);
|
||||
cache[script] = context;
|
||||
|
||||
auto & key = script->getName();
|
||||
const auto & key = script->getName();
|
||||
const JsonNode & scriptState = state[key];
|
||||
|
||||
if(srv)
|
||||
@@ -171,7 +169,7 @@ void PoolImpl::serializeState(const bool saving, JsonNode & data)
|
||||
{
|
||||
for(auto & scriptAndContext : cache)
|
||||
{
|
||||
auto script = scriptAndContext.first;
|
||||
const auto * script = scriptAndContext.first;
|
||||
auto context = scriptAndContext.second;
|
||||
|
||||
state[script->getName()] = context->saveState();
|
||||
@@ -254,7 +252,7 @@ void ScriptHandler::loadObject(std::string scope, std::string name, const JsonNo
|
||||
|
||||
void ScriptHandler::performRegistration(Services * services) const
|
||||
{
|
||||
for(auto & keyValue : objects)
|
||||
for(const auto & keyValue : objects)
|
||||
{
|
||||
auto script = keyValue.second;
|
||||
script->performRegistration(services);
|
||||
@@ -263,7 +261,7 @@ void ScriptHandler::performRegistration(Services * services) const
|
||||
|
||||
void ScriptHandler::run(std::shared_ptr<Pool> pool) const
|
||||
{
|
||||
for(auto & keyValue : objects)
|
||||
for(const auto & keyValue : objects)
|
||||
{
|
||||
auto script = keyValue.second;
|
||||
|
||||
@@ -281,7 +279,7 @@ void ScriptHandler::loadState(const JsonNode & state)
|
||||
|
||||
const JsonNode & scriptsData = state["scripts"];
|
||||
|
||||
for(auto & keyValue : scriptsData.Struct())
|
||||
for(const auto & keyValue : scriptsData.Struct())
|
||||
{
|
||||
std::string name = keyValue.first;
|
||||
|
||||
@@ -308,7 +306,7 @@ void ScriptHandler::saveState(JsonNode & state)
|
||||
JsonSerializer handler(nullptr, scriptData);
|
||||
script->serializeJsonState(handler);
|
||||
|
||||
scriptsData[name] = std::move(scriptData);
|
||||
scriptsData[name] = scriptData;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,22 +26,22 @@ PlayerSettings::PlayerSettings()
|
||||
|
||||
bool PlayerSettings::isControlledByAI() const
|
||||
{
|
||||
return !connectedPlayerIDs.size();
|
||||
return connectedPlayerIDs.empty();
|
||||
}
|
||||
|
||||
bool PlayerSettings::isControlledByHuman() const
|
||||
{
|
||||
return connectedPlayerIDs.size();
|
||||
return !connectedPlayerIDs.empty();
|
||||
}
|
||||
|
||||
PlayerSettings & StartInfo::getIthPlayersSettings(PlayerColor no)
|
||||
PlayerSettings & StartInfo::getIthPlayersSettings(const PlayerColor & no)
|
||||
{
|
||||
if(playerInfos.find(no) != playerInfos.end())
|
||||
return playerInfos[no];
|
||||
logGlobal->error("Cannot find info about player %s. Throwing...", no.getStr());
|
||||
throw std::runtime_error("Cannot find info about player");
|
||||
}
|
||||
const PlayerSettings & StartInfo::getIthPlayersSettings(PlayerColor no) const
|
||||
const PlayerSettings & StartInfo::getIthPlayersSettings(const PlayerColor & no) const
|
||||
{
|
||||
return const_cast<StartInfo &>(*this).getIthPlayersSettings(no);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ std::vector<ui8> LobbyInfo::getConnectedPlayerIdsForClient(int clientId) const
|
||||
{
|
||||
std::vector<ui8> ids;
|
||||
|
||||
for(auto & pair : playerNames)
|
||||
for(const auto & pair : playerNames)
|
||||
{
|
||||
if(pair.second.connection == clientId)
|
||||
{
|
||||
@@ -158,7 +158,7 @@ PlayerColor LobbyInfo::clientFirstColor(int clientId) const
|
||||
return PlayerColor::CANNOT_DETERMINE;
|
||||
}
|
||||
|
||||
bool LobbyInfo::isClientColor(int clientId, PlayerColor color) const
|
||||
bool LobbyInfo::isClientColor(int clientId, const PlayerColor & color) const
|
||||
{
|
||||
if(si->playerInfos.find(color) != si->playerInfos.end())
|
||||
{
|
||||
@@ -176,7 +176,7 @@ bool LobbyInfo::isClientColor(int clientId, PlayerColor color) const
|
||||
|
||||
ui8 LobbyInfo::clientFirstId(int clientId) const
|
||||
{
|
||||
for(auto & pair : playerNames)
|
||||
for(const auto & pair : playerNames)
|
||||
{
|
||||
if(pair.second.connection == clientId)
|
||||
return pair.first;
|
||||
@@ -190,7 +190,7 @@ PlayerInfo & LobbyInfo::getPlayerInfo(int color)
|
||||
return mi->mapHeader->players[color];
|
||||
}
|
||||
|
||||
TeamID LobbyInfo::getPlayerTeamId(PlayerColor color)
|
||||
TeamID LobbyInfo::getPlayerTeamId(const PlayerColor & color)
|
||||
{
|
||||
if(color < PlayerColor::PLAYER_LIMIT)
|
||||
return getPlayerInfo(color.getNum()).team;
|
||||
|
@@ -89,8 +89,8 @@ struct DLL_LINKAGE StartInfo
|
||||
|
||||
std::shared_ptr<CCampaignState> campState;
|
||||
|
||||
PlayerSettings & getIthPlayersSettings(PlayerColor no);
|
||||
const PlayerSettings & getIthPlayersSettings(PlayerColor no) const;
|
||||
PlayerSettings & getIthPlayersSettings(const PlayerColor & no);
|
||||
const PlayerSettings & getIthPlayersSettings(const PlayerColor & no) const;
|
||||
PlayerSettings * getPlayersSettings(const ui8 connectedPlayerId);
|
||||
|
||||
// TODO: Must be client-side
|
||||
@@ -171,10 +171,10 @@ struct DLL_LINKAGE LobbyInfo : public LobbyState
|
||||
// Helpers for lobby state access
|
||||
std::set<PlayerColor> clientHumanColors(int clientId);
|
||||
PlayerColor clientFirstColor(int clientId) const;
|
||||
bool isClientColor(int clientId, PlayerColor color) const;
|
||||
bool isClientColor(int clientId, const PlayerColor & color) const;
|
||||
ui8 clientFirstId(int clientId) const; // Used by chat only!
|
||||
PlayerInfo & getPlayerInfo(int color);
|
||||
TeamID getPlayerTeamId(PlayerColor color);
|
||||
TeamID getPlayerTeamId(const PlayerColor & color);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -19,7 +19,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
|
||||
TerrainType * info = new TerrainType;
|
||||
auto * info = new TerrainType;
|
||||
|
||||
info->id = TerrainId(index);
|
||||
info->identifier = identifier;
|
||||
@@ -37,17 +37,17 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
|
||||
const JsonVector & unblockedVec = json["minimapUnblocked"].Vector();
|
||||
info->minimapUnblocked =
|
||||
{
|
||||
ui8(unblockedVec[0].Float()),
|
||||
ui8(unblockedVec[1].Float()),
|
||||
ui8(unblockedVec[2].Float())
|
||||
static_cast<ui8>(unblockedVec[0].Float()),
|
||||
static_cast<ui8>(unblockedVec[1].Float()),
|
||||
static_cast<ui8>(unblockedVec[2].Float())
|
||||
};
|
||||
|
||||
const JsonVector &blockedVec = json["minimapBlocked"].Vector();
|
||||
info->minimapBlocked =
|
||||
{
|
||||
ui8(blockedVec[0].Float()),
|
||||
ui8(blockedVec[1].Float()),
|
||||
ui8(blockedVec[2].Float())
|
||||
static_cast<ui8>(blockedVec[0].Float()),
|
||||
static_cast<ui8>(blockedVec[1].Float()),
|
||||
static_cast<ui8>(blockedVec[2].Float())
|
||||
};
|
||||
|
||||
info->passabilityType = 0;
|
||||
@@ -55,7 +55,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
|
||||
for(const auto& node : json["type"].Vector())
|
||||
{
|
||||
//Set bits
|
||||
auto s = node.String();
|
||||
const auto & s = node.String();
|
||||
if (s == "LAND") info->passabilityType |= TerrainType::PassabilityType::LAND;
|
||||
if (s == "WATER") info->passabilityType |= TerrainType::PassabilityType::WATER;
|
||||
if (s == "ROCK") info->passabilityType |= TerrainType::PassabilityType::ROCK;
|
||||
@@ -75,7 +75,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
|
||||
info->shortIdentifier = json["shortIdentifier"].String();
|
||||
assert(info->shortIdentifier.length() == 2);
|
||||
|
||||
for(auto & t : json["battleFields"].Vector())
|
||||
for(const auto & t : json["battleFields"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("battlefield", t, [info](int32_t identifier)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
|
||||
});
|
||||
}
|
||||
|
||||
for(auto & t : json["prohibitTransitions"].Vector())
|
||||
for(const auto & t : json["prohibitTransitions"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("terrain", t, [info](int32_t identifier)
|
||||
{
|
||||
@@ -188,7 +188,4 @@ std::string TerrainType::getNameTranslated() const
|
||||
return VLC->generaltexth->translate(getNameTextID());
|
||||
}
|
||||
|
||||
TerrainType::TerrainType()
|
||||
{}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -61,9 +61,9 @@ public:
|
||||
RiverId river;
|
||||
int moveCost;
|
||||
bool transitionRequired;
|
||||
|
||||
TerrainType();
|
||||
|
||||
|
||||
TerrainType() = default;
|
||||
|
||||
bool isLand() const;
|
||||
bool isWater() const;
|
||||
bool isPassable() const;
|
||||
|
@@ -618,13 +618,15 @@ bfs::path VCMIDirsXDG::userCachePath() const
|
||||
bfs::path VCMIDirsXDG::userConfigPath() const
|
||||
{
|
||||
// $XDG_CONFIG_HOME, default: $HOME/.config
|
||||
const char * tempResult;
|
||||
if ((tempResult = getenv("XDG_CONFIG_HOME")))
|
||||
const char * tempResult = getenv("XDG_CONFIG_HOME");
|
||||
if (tempResult)
|
||||
return bfs::path(tempResult) / "vcmi";
|
||||
else if ((tempResult = getenv("HOME")))
|
||||
|
||||
tempResult = getenv("HOME");
|
||||
if (tempResult)
|
||||
return bfs::path(tempResult) / ".config" / "vcmi";
|
||||
else
|
||||
return ".";
|
||||
|
||||
return ".";
|
||||
}
|
||||
|
||||
std::vector<bfs::path> VCMIDirsXDG::dataPaths() const
|
||||
@@ -639,11 +641,11 @@ std::vector<bfs::path> VCMIDirsXDG::dataPaths() const
|
||||
if(developmentMode())
|
||||
{
|
||||
//For now we'll disable usage of system directories when VCMI running from bin directory
|
||||
ret.push_back(".");
|
||||
ret.emplace_back(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.push_back(M_DATA_DIR);
|
||||
ret.emplace_back(M_DATA_DIR);
|
||||
const char * tempResult;
|
||||
if((tempResult = getenv("XDG_DATA_DIRS")) != nullptr)
|
||||
{
|
||||
|
@@ -198,7 +198,8 @@ template <class Handler> void createHandler(Handler *&handler, const std::string
|
||||
|
||||
void LibClasses::init(bool onlyEssential)
|
||||
{
|
||||
CStopWatch pomtime, totalTime;
|
||||
CStopWatch pomtime;
|
||||
CStopWatch totalTime;
|
||||
|
||||
modh->initializeConfig();
|
||||
|
||||
@@ -293,7 +294,6 @@ void LibClasses::makeNull()
|
||||
|
||||
LibClasses::LibClasses()
|
||||
{
|
||||
IS_AI_ENABLED = false;
|
||||
//init pointers to handlers
|
||||
makeNull();
|
||||
}
|
||||
@@ -327,7 +327,7 @@ std::shared_ptr<CContentHandler> LibClasses::getContent() const
|
||||
|
||||
void LibClasses::setContent(std::shared_ptr<CContentHandler> content)
|
||||
{
|
||||
modh->content = content;
|
||||
modh->content = std::move(content);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -56,7 +56,7 @@ class DLL_LINKAGE LibClasses : public Services
|
||||
void setContent(std::shared_ptr<CContentHandler> content);
|
||||
|
||||
public:
|
||||
bool IS_AI_ENABLED; //unused?
|
||||
bool IS_AI_ENABLED = false; //unused?
|
||||
|
||||
const ArtifactService * artifacts() const override;
|
||||
const CreatureService * creatures() const override;
|
||||
|
Reference in New Issue
Block a user