From 0842f5afee3f7e47d7e448fab20adea7af7e7f4e Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 5 Nov 2023 15:24:26 +0200 Subject: [PATCH] Removed remaining usages of std::vector --- client/lobby/OptionsTab.cpp | 5 +- lib/BattleFieldHandler.cpp | 5 -- lib/BattleFieldHandler.h | 1 - lib/CArtHandler.cpp | 19 +++--- lib/CArtHandler.h | 4 +- lib/CCreatureHandler.cpp | 12 ---- lib/CCreatureHandler.h | 1 - lib/CGameInfoCallback.cpp | 24 ++++---- lib/CGameInfoCallback.h | 8 ++- lib/CHeroHandler.cpp | 18 ++---- lib/CHeroHandler.h | 4 +- lib/CSkillHandler.cpp | 10 +++- lib/CSkillHandler.h | 2 +- lib/CTownHandler.cpp | 29 ++++----- lib/CTownHandler.h | 2 +- lib/IGameCallback.cpp | 2 +- lib/IHandlerBase.h | 7 --- lib/JsonRandom.cpp | 8 +-- lib/ObstacleHandler.cpp | 5 -- lib/ObstacleHandler.h | 1 - lib/RiverHandler.cpp | 5 -- lib/RiverHandler.h | 1 - lib/RoadHandler.cpp | 5 -- lib/RoadHandler.h | 1 - lib/ScriptHandler.cpp | 5 -- lib/ScriptHandler.h | 1 - lib/TerrainHandler.cpp | 5 -- lib/TerrainHandler.h | 1 - lib/constants/EntityIdentifiers.h | 4 ++ lib/gameState/CGameState.cpp | 5 +- .../CObjectClassesHandler.cpp | 5 -- .../CObjectClassesHandler.h | 2 - lib/mapObjects/CGHeroInstance.cpp | 6 +- lib/mapObjects/CGMarket.cpp | 14 ----- lib/mapObjects/CGMarket.h | 1 - lib/mapObjects/CGTownInstance.cpp | 3 +- lib/mapping/CMap.cpp | 59 ++++++------------- lib/mapping/CMap.h | 6 +- lib/mapping/CMapHeader.h | 4 +- lib/mapping/MapFormatH3M.cpp | 16 ++--- lib/mapping/MapFormatJson.cpp | 17 ++---- lib/mapping/MapReaderH3M.cpp | 37 +++--------- lib/mapping/MapReaderH3M.h | 13 ++-- lib/pathfinder/TurnInfo.cpp | 5 +- lib/pathfinder/TurnInfo.h | 2 +- lib/rmg/CMapGenerator.cpp | 21 +++---- lib/rmg/CRmgTemplate.cpp | 8 +-- lib/rmg/CRmgTemplateStorage.cpp | 6 -- lib/rmg/CRmgTemplateStorage.h | 1 - lib/rmg/RmgMap.cpp | 2 +- lib/serializer/BinaryDeserializer.h | 9 --- lib/serializer/BinarySerializer.h | 8 --- lib/spells/CSpellHandler.cpp | 10 ++-- lib/spells/CSpellHandler.h | 2 +- 54 files changed, 140 insertions(+), 317 deletions(-) diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index 0584a1999..f9a211c25 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -407,10 +407,7 @@ OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color, SelType _type) selectedHero = initialHero; selectedBonus = initialBonus; allowedFactions = SEL->getPlayerInfo(color).allowedFactions; - std::vector allowedHeroesFlag = SEL->getMapInfo()->mapHeader->allowedHeroes; - for(int i = 0; i < allowedHeroesFlag.size(); i++) - if(allowedHeroesFlag[i]) - allowedHeroes.insert(HeroTypeID(i)); + allowedHeroes = SEL->getMapInfo()->mapHeader->allowedHeroes; for(auto & player : SEL->getStartInfo()->playerInfos) { diff --git a/lib/BattleFieldHandler.cpp b/lib/BattleFieldHandler.cpp index b5bcedb90..9b64a5336 100644 --- a/lib/BattleFieldHandler.cpp +++ b/lib/BattleFieldHandler.cpp @@ -54,11 +54,6 @@ const std::vector & BattleFieldHandler::getTypeNames() const return types; } -std::vector BattleFieldHandler::getDefaultAllowed() const -{ - return std::vector(); -} - int32_t BattleFieldInfo::getIndex() const { return battlefield.getNum(); diff --git a/lib/BattleFieldHandler.h b/lib/BattleFieldHandler.h index d51aeac57..ec5535bc0 100644 --- a/lib/BattleFieldHandler.h +++ b/lib/BattleFieldHandler.h @@ -71,7 +71,6 @@ public: virtual const std::vector & getTypeNames() const override; virtual std::vector loadLegacyData() override; - virtual std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 7b31c813e..97351d3b6 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -651,24 +651,27 @@ bool CArtHandler::legalArtifact(const ArtifactID & id) return false; } -void CArtHandler::initAllowedArtifactsList(const std::vector &allowed) +void CArtHandler::initAllowedArtifactsList(const std::set & allowed) { allowedArtifacts.clear(); - for (ArtifactID i=ArtifactID::SPELLBOOK; i < ArtifactID(static_cast(objects.size())); i.advance(1)) + for (ArtifactID i : allowed) { - if (allowed[i] && legalArtifact(ArtifactID(i))) + if (legalArtifact(ArtifactID(i))) allowedArtifacts.push_back(objects[i]); //keep im mind that artifact can be worn by more than one type of bearer } } -std::vector CArtHandler::getDefaultAllowed() const +std::set CArtHandler::getDefaultAllowed() const { - std::vector allowedArtifacts; - allowedArtifacts.resize(127, true); - allowedArtifacts.resize(141, false); - allowedArtifacts.resize(size(), true); + std::set allowedArtifacts; + + for (auto artifact : objects) + { + if (!artifact->isCombined()) + allowedArtifacts.insert(artifact->getId()); + } return allowedArtifacts; } diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index d8417d558..f9673a450 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -149,7 +149,7 @@ public: static CArtifact::EartClass stringToClass(const std::string & className); //TODO: rework EartClass to make this a constructor bool legalArtifact(const ArtifactID & id); - void initAllowedArtifactsList(const std::vector &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed + void initAllowedArtifactsList(const std::set & allowed); static void makeItCreatureArt(CArtifact * a, bool onlyCreature = true); static void makeItCommanderArt(CArtifact * a, bool onlyCommander = true); @@ -161,7 +161,7 @@ public: void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; void afterLoadFinalization() override; - std::vector getDefaultAllowed() const override; + std::set getDefaultAllowed() const; protected: const std::vector & getTypeNames() const override; diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 54c3083da..630992b51 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -666,18 +666,6 @@ const std::vector & CCreatureHandler::getTypeNames() const return typeNames; } -std::vector CCreatureHandler::getDefaultAllowed() const -{ - std::vector ret; - - ret.reserve(objects.size()); - for(const CCreature * crea : objects) - { - ret.push_back(crea ? !crea->special : false); - } - return ret; -} - void CCreatureHandler::loadCrExpMod() { if (VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE)) //reading default stack experience values diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index e7f6ccf6a..6d821e0c7 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -238,7 +238,6 @@ public: std::vector loadLegacyData() override; - std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 44de7bee3..a62a69c43 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -53,19 +53,19 @@ const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) c return &gs->scenarioOps->getIthPlayersSettings(color); } -bool CGameInfoCallback::isAllowed(int32_t type, int32_t id) const +bool CGameInfoCallback::isAllowed(SpellID id) const { - switch(type) - { - case 0: - return gs->map->allowedSpells[id]; - case 1: - return gs->map->allowedArtifact[id]; - case 2: - return gs->map->allowedAbilities[id]; - default: - ERROR_RET_VAL_IF(1, "Wrong type!", false); - } + return gs->map->allowedSpells.count(id) != 0; +} + +bool CGameInfoCallback::isAllowed(ArtifactID id) const +{ + return gs->map->allowedArtifact.count(id) != 0; +} + +bool CGameInfoCallback::isAllowed(SecondarySkill id) const +{ + return gs->map->allowedAbilities.count(id) != 0; } std::optional CGameInfoCallback::getPlayerID() const diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index 794719187..aeec312d3 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -57,7 +57,9 @@ public: // //various virtual int getDate(Date mode=Date::DAY) const = 0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month // const StartInfo * getStartInfo(bool beforeRandomization = false)const; - virtual bool isAllowed(int32_t type, int32_t id) const = 0; //type: 0 - spell; 1- artifact; 2 - secondary skill + virtual bool isAllowed(SpellID id) const = 0; + virtual bool isAllowed(ArtifactID id) const = 0; + virtual bool isAllowed(SecondarySkill id) const = 0; //player virtual std::optional getPlayerID() const = 0; @@ -143,7 +145,9 @@ public: //various int getDate(Date mode=Date::DAY)const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month virtual const StartInfo * getStartInfo(bool beforeRandomization = false)const; - bool isAllowed(int32_t type, int32_t id) const override; //type: 0 - spell; 1- artifact; 2 - secondary skill + bool isAllowed(SpellID id) const override; + bool isAllowed(ArtifactID id) const override; + bool isAllowed(SecondarySkill id) const override; //player std::optional getPlayerID() const override; diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 904880616..f71549e62 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -393,11 +393,6 @@ void CHeroClassHandler::afterLoadFinalization() } } -std::vector CHeroClassHandler::getDefaultAllowed() const -{ - return std::vector(size(), true); -} - CHeroClassHandler::~CHeroClassHandler() = default; CHeroHandler::~CHeroHandler() = default; @@ -763,18 +758,15 @@ ui64 CHeroHandler::reqExp (ui32 level) const } } -std::vector CHeroHandler::getDefaultAllowed() const +std::set CHeroHandler::getDefaultAllowed() const { - // Look Data/HOTRAITS.txt for reference - std::vector allowedHeroes; - allowedHeroes.reserve(size()); + std::set result; for(const CHero * hero : objects) - { - allowedHeroes.push_back(hero && !hero->special); - } + if (hero && !hero->special) + result.insert(hero->getId()); - return allowedHeroes; + return result; } VCMI_LIB_NAMESPACE_END diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 83b2e878f..3103594bc 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -165,8 +165,6 @@ public: void afterLoadFinalization() override; - std::vector getDefaultAllowed() const override; - ~CHeroClassHandler(); protected: @@ -206,7 +204,7 @@ public: CHeroHandler(); ~CHeroHandler(); - std::vector getDefaultAllowed() const override; + std::set getDefaultAllowed() const; protected: const std::vector & getTypeNames() const override; diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index 1d467b846..cea99072d 100644 --- a/lib/CSkillHandler.cpp +++ b/lib/CSkillHandler.cpp @@ -256,10 +256,14 @@ void CSkillHandler::beforeValidate(JsonNode & object) inheritNode("expert"); } -std::vector CSkillHandler::getDefaultAllowed() const +std::set CSkillHandler::getDefaultAllowed() const { - std::vector allowedSkills(objects.size(), true); - return allowedSkills; + std::set result; + + for (auto const & skill : objects) + result.insert(skill->getId()); + + return result; } VCMI_LIB_NAMESPACE_END diff --git a/lib/CSkillHandler.h b/lib/CSkillHandler.h index 920689e9e..fe699edcb 100644 --- a/lib/CSkillHandler.h +++ b/lib/CSkillHandler.h @@ -90,7 +90,7 @@ public: void afterLoadFinalization() override; void beforeValidate(JsonNode & object) override; - std::vector getDefaultAllowed() const override; + std::set getDefaultAllowed() const; protected: const std::vector & getTypeNames() const override; diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index d9541d545..b20f8f872 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -1259,31 +1259,28 @@ void CTownHandler::initializeWarMachines() warMachinesToLoad.clear(); } -std::vector CTownHandler::getDefaultAllowed() const +std::set CTownHandler::getDefaultAllowed() const { - std::vector allowedFactions; - allowedFactions.reserve(objects.size()); + std::set allowedFactions; + for(auto town : objects) - { - allowedFactions.push_back(town->town != nullptr); - } + if (town->town != nullptr) + allowedFactions.insert(town->getId()); + return allowedFactions; } std::set CTownHandler::getAllowedFactions(bool withTown) const { - std::set allowedFactions; - std::vector allowed; - if (withTown) - allowed = getDefaultAllowed(); - else - allowed.resize( objects.size(), true); + if (!withTown) + return getDefaultAllowed(); - for (size_t i=0; i(i)); + std::set result; + for(auto town : objects) + result.insert(town->getId()); + + return result; - return allowedFactions; } const std::vector & CTownHandler::getTypeNames() const diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 170cc2f1f..5a8421b35 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -350,7 +350,7 @@ public: void loadCustom() override; void afterLoadFinalization() override; - std::vector getDefaultAllowed() const override; + std::set getDefaultAllowed() const; std::set getAllowedFactions(bool withTown = true) const; static void loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building); diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index e14a5ac1c..f40aebcd8 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -160,7 +160,7 @@ void CPrivilegedInfoCallback::getAllowedSpells(std::vector & out, std:: { const spells::Spell * spell = SpellID(i).toSpell(); - if (!isAllowed(0, spell->getIndex())) + if (!isAllowed(spell->getId())) continue; if (level.has_value() && spell->getLevel() != level) diff --git a/lib/IHandlerBase.h b/lib/IHandlerBase.h index f513f3593..615e23f54 100644 --- a/lib/IHandlerBase.h +++ b/lib/IHandlerBase.h @@ -44,13 +44,6 @@ public: /// allows handler to do post-loading step for validation or integration of loaded data virtual void afterLoadFinalization(){}; - /** - * Gets a list of objects that are allowed by default on maps - * - * @return a list of allowed objects, the index is the object id - */ - virtual std::vector getDefaultAllowed() const = 0; - virtual ~IHandlerBase(){} }; diff --git a/lib/JsonRandom.cpp b/lib/JsonRandom.cpp index f960f0137..e87f9d6d2 100644 --- a/lib/JsonRandom.cpp +++ b/lib/JsonRandom.cpp @@ -164,7 +164,7 @@ namespace JsonRandom if(!allowedClasses.empty() && !allowedClasses.count(art->aClass)) continue; - if(!IObjectInterface::cb->isAllowed(1, art->getIndex())) + if(!IObjectInterface::cb->isAllowed(art->getId())) continue; if(!allowedPositions.empty()) @@ -344,7 +344,7 @@ namespace JsonRandom { std::set defaultSkills; for(const auto & skill : VLC->skillh->objects) - if (IObjectInterface::cb->isAllowed(2, skill->getIndex())) + if (IObjectInterface::cb->isAllowed(skill->getId())) defaultSkills.insert(skill->getId()); std::set potentialPicks = filterKeys(value, defaultSkills, variables); @@ -366,7 +366,7 @@ namespace JsonRandom { std::set defaultSkills; for(const auto & skill : VLC->skillh->objects) - if (IObjectInterface::cb->isAllowed(2, skill->getIndex())) + if (IObjectInterface::cb->isAllowed(skill->getId())) defaultSkills.insert(skill->getId()); for(const auto & element : value.Vector()) @@ -406,7 +406,7 @@ namespace JsonRandom { std::set defaultSpells; for(const auto & spell : VLC->spellh->objects) - if (IObjectInterface::cb->isAllowed(0, spell->getIndex())) + if (IObjectInterface::cb->isAllowed(spell->getId())) defaultSpells.insert(spell->getId()); std::set potentialPicks = filterKeys(value, defaultSpells, variables); diff --git a/lib/ObstacleHandler.cpp b/lib/ObstacleHandler.cpp index fbfc7efe2..f9ef0f0b2 100644 --- a/lib/ObstacleHandler.cpp +++ b/lib/ObstacleHandler.cpp @@ -116,11 +116,6 @@ std::vector ObstacleHandler::loadLegacyData() return {}; } -std::vector ObstacleHandler::getDefaultAllowed() const -{ - return {}; -} - const std::vector & ObstacleHandler::getTypeNames() const { static const std::vector types = { "obstacle" }; diff --git a/lib/ObstacleHandler.h b/lib/ObstacleHandler.h index 36268426a..e47d1c0ea 100644 --- a/lib/ObstacleHandler.h +++ b/lib/ObstacleHandler.h @@ -71,7 +71,6 @@ public: const std::vector & getTypeNames() const override; std::vector loadLegacyData() override; - std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/RiverHandler.cpp b/lib/RiverHandler.cpp index 3cc04eb37..5154505b4 100644 --- a/lib/RiverHandler.cpp +++ b/lib/RiverHandler.cpp @@ -68,11 +68,6 @@ std::vector RiverTypeHandler::loadLegacyData() return {}; } -std::vector RiverTypeHandler::getDefaultAllowed() const -{ - return {}; -} - std::string RiverType::getJsonKey() const { return modScope + ":" + identifier; diff --git a/lib/RiverHandler.h b/lib/RiverHandler.h index 5c028ddbd..c070a53a8 100644 --- a/lib/RiverHandler.h +++ b/lib/RiverHandler.h @@ -71,7 +71,6 @@ public: virtual const std::vector & getTypeNames() const override; virtual std::vector loadLegacyData() override; - virtual std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/RoadHandler.cpp b/lib/RoadHandler.cpp index 458d1588d..85380d460 100644 --- a/lib/RoadHandler.cpp +++ b/lib/RoadHandler.cpp @@ -59,11 +59,6 @@ std::vector RoadTypeHandler::loadLegacyData() return {}; } -std::vector RoadTypeHandler::getDefaultAllowed() const -{ - return {}; -} - std::string RoadType::getJsonKey() const { return modScope + ":" + identifier; diff --git a/lib/RoadHandler.h b/lib/RoadHandler.h index dbb9476b5..f58d5b9bb 100644 --- a/lib/RoadHandler.h +++ b/lib/RoadHandler.h @@ -61,7 +61,6 @@ public: virtual const std::vector & getTypeNames() const override; virtual std::vector loadLegacyData() override; - virtual std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/ScriptHandler.cpp b/lib/ScriptHandler.cpp index d672c74dd..5fe39407c 100644 --- a/lib/ScriptHandler.cpp +++ b/lib/ScriptHandler.cpp @@ -217,11 +217,6 @@ const Script * ScriptHandler::resolveScript(const std::string & name) const } } -std::vector ScriptHandler::getDefaultAllowed() const -{ - return std::vector(); -} - std::vector ScriptHandler::loadLegacyData() { return std::vector(); diff --git a/lib/ScriptHandler.h b/lib/ScriptHandler.h index e2ff3a7e4..a0177fc65 100644 --- a/lib/ScriptHandler.h +++ b/lib/ScriptHandler.h @@ -97,7 +97,6 @@ public: const Script * resolveScript(const std::string & name) const; - std::vector getDefaultAllowed() const override; std::vector loadLegacyData() override; ScriptPtr loadFromJson(vstd::CLoggerBase * logger, const std::string & scope, const JsonNode & json, const std::string & identifier) const; diff --git a/lib/TerrainHandler.cpp b/lib/TerrainHandler.cpp index f7a3eb96f..805f41362 100644 --- a/lib/TerrainHandler.cpp +++ b/lib/TerrainHandler.cpp @@ -140,11 +140,6 @@ std::vector TerrainTypeHandler::loadLegacyData() return result; } -std::vector TerrainTypeHandler::getDefaultAllowed() const -{ - return {}; -} - bool TerrainType::isLand() const { return !isWater(); diff --git a/lib/TerrainHandler.h b/lib/TerrainHandler.h index 447e1efc3..68103abd1 100644 --- a/lib/TerrainHandler.h +++ b/lib/TerrainHandler.h @@ -109,7 +109,6 @@ public: virtual const std::vector & getTypeNames() const override; virtual std::vector loadLegacyData() override; - virtual std::vector getDefaultAllowed() const override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h index a4dcc9d0e..a789b2e85 100644 --- a/lib/constants/EntityIdentifiers.h +++ b/lib/constants/EntityIdentifiers.h @@ -23,6 +23,7 @@ class HeroType; class CHero; class HeroTypeService; class Faction; +class Skill; class RoadType; class RiverType; class TerrainType; @@ -308,6 +309,9 @@ public: static std::string entityType(); static si32 decode(const std::string& identifier); static std::string encode(const si32 index); + + const CSkill * toSkill() const; + const Skill * toEntity(const Services * services) const; }; class DLL_LINKAGE PrimarySkill : public Identifier diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index beb8eeda4..d40f541b4 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -1877,10 +1877,7 @@ bool CGameState::giveHeroArtifact(CGHeroInstance * h, const ArtifactID & aid) std::set CGameState::getUnusedAllowedHeroes(bool alsoIncludeNotAllowed) const { - std::set ret; - for(int i = 0; i < map->allowedHeroes.size(); i++) - if(map->allowedHeroes[i] || alsoIncludeNotAllowed) - ret.insert(HeroTypeID(i)); + std::set ret = map->allowedHeroes; for(const auto & playerSettingPair : scenarioOps->playerInfos) //remove uninitialized yet heroes picked for start by other players { diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.cpp b/lib/mapObjectConstructors/CObjectClassesHandler.cpp index 1ef76010c..712b8c910 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.cpp +++ b/lib/mapObjectConstructors/CObjectClassesHandler.cpp @@ -304,11 +304,6 @@ void CObjectClassesHandler::removeSubObject(MapObjectID ID, MapObjectSubID subID objects[ID]->objects[subID] = nullptr; } -std::vector CObjectClassesHandler::getDefaultAllowed() const -{ - return std::vector(); //TODO? -} - TObjectTypeHandler CObjectClassesHandler::getHandlerFor(MapObjectID type, MapObjectSubID subtype) const { try diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.h b/lib/mapObjectConstructors/CObjectClassesHandler.h index ef42a32a1..835301916 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.h +++ b/lib/mapObjectConstructors/CObjectClassesHandler.h @@ -101,8 +101,6 @@ public: void beforeValidate(JsonNode & object) override; void afterLoadFinalization() override; - std::vector getDefaultAllowed() const override; - /// Queries to detect loaded objects std::set knownObjects() const; std::set knownSubObjects(MapObjectID primaryID) const; diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 6fa16d8ce..00b4e5dbc 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -212,7 +212,7 @@ bool CGHeroInstance::canLearnSkill(const SecondarySkill & which) const if ( !canLearnSkill()) return false; - if (!cb->isAllowed(2, which)) + if (!cb->isAllowed(which)) return false; if (getSecSkillLevel(which) > 0) @@ -777,7 +777,7 @@ void CGHeroInstance::spendMana(ServerCallback * server, const int spellCost) con bool CGHeroInstance::canCastThisSpell(const spells::Spell * spell) const { - const bool isAllowed = IObjectInterface::cb->isAllowed(0, spell->getIndex()); + const bool isAllowed = IObjectInterface::cb->isAllowed(spell->getId()); const bool inSpellBook = vstd::contains(spells, spell->getId()) && hasSpellbook(); const bool specificBonus = hasBonusOfType(BonusType::SPELL, BonusSubtypeID(spell->getId())); @@ -841,7 +841,7 @@ bool CGHeroInstance::canLearnSpell(const spells::Spell * spell, bool allowBanned return false;//creature abilities can not be learned } - if(!allowBanned && !IObjectInterface::cb->isAllowed(0, spell->getIndex())) + if(!allowBanned && !IObjectInterface::cb->isAllowed(spell->getId())) { logGlobal->warn("Hero %s try to learn banned spell %s", nodeName(), spell->getNameTranslated()); return false;//banned spells should not be learned diff --git a/lib/mapObjects/CGMarket.cpp b/lib/mapObjects/CGMarket.cpp index b429a84fe..f6ac45633 100644 --- a/lib/mapObjects/CGMarket.cpp +++ b/lib/mapObjects/CGMarket.cpp @@ -96,20 +96,6 @@ void CGBlackMarket::newTurn(CRandomGenerator & rand) const cb->sendAndApply(&saa); } -void CGUniversity::initObj(CRandomGenerator & rand) -{ - CGMarket::initObj(rand); - - std::vector toChoose; - for(int i = 0; i < VLC->skillh->size(); ++i) - { - if(!vstd::contains(skills, i) && cb->isAllowed(2, i)) - { - toChoose.push_back(i); - } - } -} - std::vector CGUniversity::availableItemsIds(EMarketMode mode) const { switch (mode) diff --git a/lib/mapObjects/CGMarket.h b/lib/mapObjects/CGMarket.h index aff11ce56..386988dfc 100644 --- a/lib/mapObjects/CGMarket.h +++ b/lib/mapObjects/CGMarket.h @@ -67,7 +67,6 @@ public: std::vector skills; //available skills std::vector availableItemsIds(EMarketMode mode) const override; - void initObj(CRandomGenerator & rand) override;//set skills for trade void onHeroVisit(const CGHeroInstance * h) const override; //open window template void serialize(Handler &h, const int version) diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index f2c331f50..49fa6800b 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -1201,8 +1201,7 @@ void CGTownInstance::serializeJsonOptions(JsonSerializeFormat & handler) } { - std::vector standard = VLC->spellh->getDefaultAllowed(); - JsonSerializeFormat::LIC spellsLIC(standard, SpellID::decode, SpellID::encode); + JsonSerializeFormat::LIC spellsLIC(VLC->spellh->getDefaultAllowed(), SpellID::decode, SpellID::encode); if(handler.saving) { diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index e116bf4e6..98d629adb 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -621,67 +621,44 @@ void CMap::banWaterContent() void CMap::banWaterSpells() { - for (int j = 0; j < allowedSpells.size(); j++) + vstd::erase_if(allowedSpells, [&](SpellID spell) { - if (allowedSpells[j]) - { - auto* spell = dynamic_cast(VLC->spells()->getByIndex(j)); - if (spell->onlyOnWaterMap && !isWaterMap()) - { - allowedSpells[j] = false; - } - } - } + return spell.toSpell()->onlyOnWaterMap && !isWaterMap(); + }); } void CMap::banWaterArtifacts() { - for (int j = 0; j < allowedArtifact.size(); j++) + vstd::erase_if(allowedArtifact, [&](ArtifactID artifact) { - if (allowedArtifact[j]) - { - auto* art = dynamic_cast(VLC->artifacts()->getByIndex(j)); - if (art->onlyOnWaterMap && !isWaterMap()) - { - allowedArtifact[j] = false; - } - } - } + return artifact.toArtifact()->onlyOnWaterMap && !isWaterMap(); + }); } void CMap::banWaterSkills() { - for (int j = 0; j < allowedAbilities.size(); j++) + vstd::erase_if(allowedAbilities, [&](SecondarySkill skill) { - if (allowedAbilities[j]) - { - auto* skill = dynamic_cast(VLC->skills()->getByIndex(j)); - if (skill->onlyOnWaterMap && !isWaterMap()) - { - allowedAbilities[j] = false; - } - } - } + return skill.toSkill()->onlyOnWaterMap && !isWaterMap(); + }); } void CMap::banWaterHeroes() { - for (int j = 0; j < allowedHeroes.size(); j++) + vstd::erase_if(allowedHeroes, [&](HeroTypeID hero) { - if (allowedHeroes[j]) - { - auto* h = dynamic_cast(VLC->heroTypes()->getByIndex(j)); - if ((h->onlyOnWaterMap && !isWaterMap()) || (h->onlyOnMapWithoutWater && isWaterMap())) - { - banHero(HeroTypeID(j)); - } - } - } + return hero.toHeroType()->onlyOnWaterMap && !isWaterMap(); + }); + + vstd::erase_if(allowedHeroes, [&](HeroTypeID hero) + { + return hero.toHeroType()->onlyOnMapWithoutWater && isWaterMap(); + }); } void CMap::banHero(const HeroTypeID & id) { - allowedHeroes.at(id) = false; + allowedHeroes.erase(id); } void CMap::initTerrain() diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 518b1fb6a..d1fbbc14d 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -129,9 +129,9 @@ public: std::vector rumors; std::vector disposedHeroes; std::vector > predefinedHeroes; - std::vector allowedSpells; - std::vector allowedArtifact; - std::vector allowedAbilities; + std::set allowedSpells; + std::set allowedArtifact; + std::set allowedAbilities; std::list events; int3 grailPos; int grailRadius; diff --git a/lib/mapping/CMapHeader.h b/lib/mapping/CMapHeader.h index b492237dc..2a83e7d0e 100644 --- a/lib/mapping/CMapHeader.h +++ b/lib/mapping/CMapHeader.h @@ -238,8 +238,8 @@ public: std::vector players; /// The default size of the vector is PlayerColor::PLAYER_LIMIT. ui8 howManyTeams; - std::vector allowedHeroes; - std::vector reservedCampaignHeroes; /// Heroes that have placeholders in this map and are reserverd for campaign + std::set allowedHeroes; + std::set reservedCampaignHeroes; /// Heroes that have placeholders in this map and are reserverd for campaign bool areAnyPlayers; /// Unused. True if there are any playable players on the map. diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 5bd59ca3b..02624ccdf 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -692,7 +692,7 @@ void CMapLoaderH3M::readAllowedHeroes() for (uint32_t i = 0; i < placeholdersQty; ++i) { auto heroID = reader->readHero(); - mapHeader->reservedCampaignHeroes.push_back(heroID); + mapHeader->reservedCampaignHeroes.insert(heroID); } } } @@ -764,13 +764,13 @@ void CMapLoaderH3M::readAllowedArtifacts() { for(CArtifact * artifact : VLC->arth->objects) if(artifact->isCombined()) - map->allowedArtifact[artifact->getId()] = false; + map->allowedArtifact.erase(artifact->getId()); } if(!features.levelAB) { - map->allowedArtifact[ArtifactID::VIAL_OF_DRAGON_BLOOD] = false; - map->allowedArtifact[ArtifactID::ARMAGEDDONS_BLADE] = false; + map->allowedArtifact.erase(ArtifactID::VIAL_OF_DRAGON_BLOOD); + map->allowedArtifact.erase(ArtifactID::ARMAGEDDONS_BLADE); } // Messy, but needed @@ -780,7 +780,7 @@ void CMapLoaderH3M::readAllowedArtifacts() { if(cond.condition == EventCondition::HAVE_ARTIFACT || cond.condition == EventCondition::TRANSPORT) { - map->allowedArtifact[cond.objectType] = false; + map->allowedArtifact.erase(cond.objectType); } return cond; }; @@ -1160,7 +1160,7 @@ CGObjectInstance * CMapLoaderH3M::readWitchHut(const int3 & position, std::share auto defaultAllowed = VLC->skillh->getDefaultAllowed(); for(int skillID = features.skillsCount; skillID < defaultAllowed.size(); ++skillID) - if(defaultAllowed[skillID]) + if(defaultAllowed.count(skillID)) allowedAbilities.insert(SecondarySkill(skillID)); } @@ -2085,7 +2085,7 @@ int CMapLoaderH3M::readQuest(IQuestObject * guard, const int3 & position) { auto artid = reader->readArtifact(); guard->quest->mission.artifacts.push_back(artid); - map->allowedArtifact[artid] = false; //these are unavailable for random generation + map->allowedArtifact.erase(artid); //these are unavailable for random generation } break; } @@ -2212,7 +2212,7 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt //add all spells from mods for(int i = features.spellsCount; i < defaultAllowed.size(); ++i) - if(defaultAllowed[i]) + if(defaultAllowed.count(i)) object->possibleSpells.emplace_back(i); } diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index 62ad052f4..fda1e4329 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -389,28 +389,19 @@ RoadType * CMapFormatJson::getRoadByCode(const std::string & code) void CMapFormatJson::serializeAllowedFactions(JsonSerializeFormat & handler, std::set & value) const { - //TODO: unify allowed factions with others - make them std::vector - - std::vector temp; - temp.resize(VLC->townh->size(), false); - auto standard = VLC->townh->getDefaultAllowed(); + std::set temp; if(handler.saving) { for(auto faction : VLC->townh->objects) if(faction->town && vstd::contains(value, faction->getId())) - temp[static_cast(faction->getIndex())] = true; + temp.insert(faction->getId()); } - handler.serializeLIC("allowedFactions", &FactionID::decode, &FactionID::encode, standard, temp); + handler.serializeLIC("allowedFactions", &FactionID::decode, &FactionID::encode, VLC->townh->getDefaultAllowed(), temp); if(!handler.saving) - { - value.clear(); - for (std::size_t i=0; i(i)); - } + value = temp; } void CMapFormatJson::serializeHeader(JsonSerializeFormat & handler) diff --git a/lib/mapping/MapReaderH3M.cpp b/lib/mapping/MapReaderH3M.cpp index 772c251de..00334d443 100644 --- a/lib/mapping/MapReaderH3M.cpp +++ b/lib/mapping/MapReaderH3M.cpp @@ -266,12 +266,12 @@ void MapReaderH3M::readBitmaskHeroClassesSized(std::set & dest, boo readBitmask(dest, classesBytes, classesCount, invert); } -void MapReaderH3M::readBitmaskHeroes(std::vector & dest, bool invert) +void MapReaderH3M::readBitmaskHeroes(std::set & dest, bool invert) { readBitmask(dest, features.heroesBytes, features.heroesCount, invert); } -void MapReaderH3M::readBitmaskHeroesSized(std::vector & dest, bool invert) +void MapReaderH3M::readBitmaskHeroesSized(std::set & dest, bool invert) { uint32_t heroesCount = readUInt32(); uint32_t heroesBytes = (heroesCount + 7) / 8; @@ -280,12 +280,12 @@ void MapReaderH3M::readBitmaskHeroesSized(std::vector & dest, bool invert) readBitmask(dest, heroesBytes, heroesCount, invert); } -void MapReaderH3M::readBitmaskArtifacts(std::vector &dest, bool invert) +void MapReaderH3M::readBitmaskArtifacts(std::set &dest, bool invert) { readBitmask(dest, features.artifactsBytes, features.artifactsCount, invert); } -void MapReaderH3M::readBitmaskArtifactsSized(std::vector &dest, bool invert) +void MapReaderH3M::readBitmaskArtifactsSized(std::set &dest, bool invert) { uint32_t artifactsCount = reader->readUInt32(); uint32_t artifactsBytes = (artifactsCount + 7) / 8; @@ -294,28 +294,18 @@ void MapReaderH3M::readBitmaskArtifactsSized(std::vector &dest, bool inver readBitmask(dest, artifactsBytes, artifactsCount, invert); } -void MapReaderH3M::readBitmaskSpells(std::vector & dest, bool invert) -{ - readBitmask(dest, features.spellsBytes, features.spellsCount, invert); -} - void MapReaderH3M::readBitmaskSpells(std::set & dest, bool invert) { readBitmask(dest, features.spellsBytes, features.spellsCount, invert); } -void MapReaderH3M::readBitmaskSkills(std::vector & dest, bool invert) -{ - readBitmask(dest, features.skillsBytes, features.skillsCount, invert); -} - void MapReaderH3M::readBitmaskSkills(std::set & dest, bool invert) { readBitmask(dest, features.skillsBytes, features.skillsCount, invert); } template -void MapReaderH3M::readBitmask(std::vector & dest, const int bytesToRead, const int objectsToRead, bool invert) +void MapReaderH3M::readBitmask(std::set & dest, int bytesToRead, int objectsToRead, bool invert) { for(int byte = 0; byte < bytesToRead; ++byte) { @@ -331,26 +321,13 @@ void MapReaderH3M::readBitmask(std::vector & dest, const int bytesToRead, Identifier h3mID(index); Identifier vcmiID = remapIdentifier(h3mID); - if (vcmiID.getNum() >= dest.size()) - dest.resize(vcmiID.getNum() + 1); - dest[vcmiID.getNum()] = result; + if (result) + dest.insert(vcmiID); } } } } -template -void MapReaderH3M::readBitmask(std::set & dest, int bytesToRead, int objectsToRead, bool invert) -{ - std::vector bitmap; - bitmap.resize(objectsToRead, false); - readBitmask(bitmap, bytesToRead, objectsToRead, invert); - - for(int i = 0; i < bitmap.size(); i++) - if(bitmap[i]) - dest.insert(static_cast(i)); -} - int3 MapReaderH3M::readInt3() { int3 p; diff --git a/lib/mapping/MapReaderH3M.h b/lib/mapping/MapReaderH3M.h index 9c34aba3d..92da10ab0 100644 --- a/lib/mapping/MapReaderH3M.h +++ b/lib/mapping/MapReaderH3M.h @@ -50,13 +50,11 @@ public: void readBitmaskPlayers(std::set & dest, bool invert); void readBitmaskResources(std::set & dest, bool invert); void readBitmaskHeroClassesSized(std::set & dest, bool invert); - void readBitmaskHeroes(std::vector & dest, bool invert); - void readBitmaskHeroesSized(std::vector & dest, bool invert); - void readBitmaskArtifacts(std::vector & dest, bool invert); - void readBitmaskArtifactsSized(std::vector & dest, bool invert); - void readBitmaskSpells(std::vector & dest, bool invert); + void readBitmaskHeroes(std::set & dest, bool invert); + void readBitmaskHeroesSized(std::set & dest, bool invert); + void readBitmaskArtifacts(std::set & dest, bool invert); + void readBitmaskArtifactsSized(std::set & dest, bool invert); void readBitmaskSpells(std::set & dest, bool invert); - void readBitmaskSkills(std::vector & dest, bool invert); void readBitmaskSkills(std::set & dest, bool invert); int3 readInt3(); @@ -88,9 +86,6 @@ private: template void readBitmask(std::set & dest, int bytesToRead, int objectsToRead, bool invert); - template - void readBitmask(std::vector & dest, int bytesToRead, int objectsToRead, bool invert); - MapFormatFeaturesH3M features; MapIdentifiersH3M remapper; diff --git a/lib/pathfinder/TurnInfo.cpp b/lib/pathfinder/TurnInfo.cpp index 8b8763cdb..1f32139a6 100644 --- a/lib/pathfinder/TurnInfo.cpp +++ b/lib/pathfinder/TurnInfo.cpp @@ -23,7 +23,8 @@ TurnInfo::BonusCache::BonusCache(const TConstBonusListPtr & bl) for(const auto & terrain : VLC->terrainTypeHandler->objects) { auto selector = Selector::typeSubtype(BonusType::NO_TERRAIN_PENALTY, BonusSubtypeID(terrain->getId())); - noTerrainPenalty.push_back(static_cast(bl->getFirst(selector))); + if (bl->getFirst(selector)) + noTerrainPenalty.insert(terrain->getId()); } freeShipBoarding = static_cast(bl->getFirst(Selector::type()(BonusType::FREE_SHIP_BOARDING))); @@ -87,7 +88,7 @@ bool TurnInfo::hasBonusOfType(BonusType type, BonusSubtypeID subtype) const case BonusType::WATER_WALKING: return bonusCache->waterWalking; case BonusType::NO_TERRAIN_PENALTY: - return bonusCache->noTerrainPenalty[subtype.getNum()]; + return bonusCache->noTerrainPenalty.count(subtype.as()); } return static_cast( diff --git a/lib/pathfinder/TurnInfo.h b/lib/pathfinder/TurnInfo.h index 4390e13c6..6fff27e6f 100644 --- a/lib/pathfinder/TurnInfo.h +++ b/lib/pathfinder/TurnInfo.h @@ -21,7 +21,7 @@ struct DLL_LINKAGE TurnInfo /// This is certainly not the best design ever and certainly can be improved /// Unfortunately for pathfinder that do hundreds of thousands calls onus system add too big overhead struct BonusCache { - std::vector noTerrainPenalty; + std::set noTerrainPenalty; bool freeShipBoarding; bool flyingMovement; int flyingMovementVal; diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index be317d717..3c66b3c39 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -493,19 +493,16 @@ const std::vector CMapGenerator::getAllPossibleHeroes() const auto isWaterMap = map->getMap(this).isWaterMap(); //Skip heroes that were banned, including the ones placed in prisons std::vector ret; - for (int j = 0; j < map->getMap(this).allowedHeroes.size(); j++) + for (HeroTypeID hero : map->getMap(this).allowedHeroes) { - if (map->getMap(this).allowedHeroes[j]) + auto * h = dynamic_cast(VLC->heroTypes()->getById(hero)); + if ((h->onlyOnWaterMap && !isWaterMap) || (h->onlyOnMapWithoutWater && isWaterMap)) { - auto * h = dynamic_cast(VLC->heroTypes()->getByIndex(j)); - if ((h->onlyOnWaterMap && !isWaterMap) || (h->onlyOnMapWithoutWater && isWaterMap)) - { - continue; - } - else - { - ret.push_back(HeroTypeID(j)); - } + continue; + } + else + { + ret.push_back(hero); } } return ret; @@ -514,7 +511,7 @@ const std::vector CMapGenerator::getAllPossibleHeroes() const void CMapGenerator::banQuestArt(const ArtifactID & id) { //TODO: Protect with mutex - map->getMap(this).allowedArtifact[id] = false; + map->getMap(this).allowedArtifact.erase(id); } void CMapGenerator::banHero(const HeroTypeID & id) diff --git a/lib/rmg/CRmgTemplate.cpp b/lib/rmg/CRmgTemplate.cpp index 5a688da6a..384d186a0 100644 --- a/lib/rmg/CRmgTemplate.cpp +++ b/lib/rmg/CRmgTemplate.cpp @@ -188,13 +188,7 @@ std::set ZoneOptions::getDefaultTerrainTypes() const std::set ZoneOptions::getDefaultTownTypes() const { - std::set defaultTowns; - auto towns = VLC->townh->getDefaultAllowed(); - for(int i = 0; i < towns.size(); ++i) - { - if(towns[i]) defaultTowns.insert(FactionID(i)); - } - return defaultTowns; + return VLC->townh->getDefaultAllowed(); } const std::set ZoneOptions::getTownTypes() const diff --git a/lib/rmg/CRmgTemplateStorage.cpp b/lib/rmg/CRmgTemplateStorage.cpp index 738d65c1a..c340219fd 100644 --- a/lib/rmg/CRmgTemplateStorage.cpp +++ b/lib/rmg/CRmgTemplateStorage.cpp @@ -51,12 +51,6 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const } } -std::vector CRmgTemplateStorage::getDefaultAllowed() const -{ - //all templates are allowed - return std::vector(); -} - std::vector CRmgTemplateStorage::loadLegacyData() { return std::vector(); diff --git a/lib/rmg/CRmgTemplateStorage.h b/lib/rmg/CRmgTemplateStorage.h index 6ce5c1411..4470c51d8 100644 --- a/lib/rmg/CRmgTemplateStorage.h +++ b/lib/rmg/CRmgTemplateStorage.h @@ -24,7 +24,6 @@ class DLL_LINKAGE CRmgTemplateStorage : public IHandlerBase public: CRmgTemplateStorage() = default; - std::vector getDefaultAllowed() const override; std::vector loadLegacyData() override; /// loads single object into game. Scope is namespace of this object, same as name of source mod diff --git a/lib/rmg/RmgMap.cpp b/lib/rmg/RmgMap.cpp index 85c0c8590..cdf8e0bb0 100644 --- a/lib/rmg/RmgMap.cpp +++ b/lib/rmg/RmgMap.cpp @@ -345,7 +345,7 @@ bool RmgMap::isAllowedSpell(const SpellID & sid) const assert(sid.getNum() >= 0); if (sid.getNum() < mapInstance->allowedSpells.size()) { - return mapInstance->allowedSpells[sid]; + return mapInstance->allowedSpells.count(sid); } else return false; diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index 1c4858469..4c6c9b39b 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -197,15 +197,6 @@ public: data = static_cast(read); } - template < typename T, typename std::enable_if < std::is_same >::value, int >::type = 0 > - void load(T & data) - { - std::vector convData; - load(convData); - convData.resize(data.size()); - range::copy(convData, data.begin()); - } - template ::value, int >::type = 0> void load(std::vector &data) { diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index 37a054d2d..ef2ddf416 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -137,14 +137,6 @@ public: save(writ); } - template < typename T, typename std::enable_if < std::is_same >::value, int >::type = 0 > - void save(const T &data) - { - std::vector convData; - std::copy(data.begin(), data.end(), std::back_inserter(convData)); - save(convData); - } - template < class T, typename std::enable_if < std::is_fundamental::value && !std::is_same::value, int >::type = 0 > void save(const T &data) { diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index ff235b245..3af7be51e 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -986,15 +986,13 @@ void CSpellHandler::beforeValidate(JsonNode & object) inheritNode("expert"); } -std::vector CSpellHandler::getDefaultAllowed() const +std::set CSpellHandler::getDefaultAllowed() const { - std::vector allowedSpells; - allowedSpells.reserve(objects.size()); + std::set allowedSpells; for(const CSpell * s : objects) - { - allowedSpells.push_back( !(s->isSpecial() || s->isCreatureAbility())); - } + if (!s->isSpecial() && !s->isCreatureAbility()) + allowedSpells.insert(s->getId()); return allowedSpells; } diff --git a/lib/spells/CSpellHandler.h b/lib/spells/CSpellHandler.h index e9de9440a..efe807831 100644 --- a/lib/spells/CSpellHandler.h +++ b/lib/spells/CSpellHandler.h @@ -349,7 +349,7 @@ public: * Gets a list of default allowed spells. OH3 spells are all allowed by default. * */ - std::vector getDefaultAllowed() const override; + std::set getDefaultAllowed() const; protected: const std::vector & getTypeNames() const override;