diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index 85acbe46c..bdb25982d 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -1097,7 +1097,7 @@ void AIGateway::battleEnd(const BattleResult * br, QueryID queryID) logAi->debug("Player %d (%s): I %s the %s!", playerID, playerID.getStr(), (won ? "won" : "lost"), battlename); battlename.clear(); - if (queryID != -1) + if (queryID != QueryID::NONE) { status.addQuery(queryID, "Combat result dialog"); const int confirmAction = 0; diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index 54ce129ab..ae506f4af 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -24,7 +24,7 @@ void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo) for(auto &pair : townInfo->buildings) { - if(pair.second->upgrade != -1) + if(pair.second->upgrade != BuildingID::NONE) { parentMap[pair.second->upgrade] = pair.first; } diff --git a/AI/Nullkiller/Goals/AbstractGoal.cpp b/AI/Nullkiller/Goals/AbstractGoal.cpp index 1cc45a12a..98f6a4c49 100644 --- a/AI/Nullkiller/Goals/AbstractGoal.cpp +++ b/AI/Nullkiller/Goals/AbstractGoal.cpp @@ -10,7 +10,7 @@ #include "StdInc.h" #include "AbstractGoal.h" #include "../AIGateway.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" namespace NKAI { diff --git a/AI/Nullkiller/Goals/BuildThis.cpp b/AI/Nullkiller/Goals/BuildThis.cpp index 2f371346e..c73cb57e3 100644 --- a/AI/Nullkiller/Goals/BuildThis.cpp +++ b/AI/Nullkiller/Goals/BuildThis.cpp @@ -11,7 +11,7 @@ #include "BuildThis.h" #include "../AIGateway.h" #include "../AIUtility.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" namespace NKAI diff --git a/AI/Nullkiller/Goals/Composition.cpp b/AI/Nullkiller/Goals/Composition.cpp index ca77dc5e8..aff59aa7b 100644 --- a/AI/Nullkiller/Goals/Composition.cpp +++ b/AI/Nullkiller/Goals/Composition.cpp @@ -11,7 +11,7 @@ #include "Composition.h" #include "../AIGateway.h" #include "../AIUtility.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" namespace NKAI diff --git a/AI/Nullkiller/Goals/RecruitHero.cpp b/AI/Nullkiller/Goals/RecruitHero.cpp index fe4aaeb6f..c6a6c4d4e 100644 --- a/AI/Nullkiller/Goals/RecruitHero.cpp +++ b/AI/Nullkiller/Goals/RecruitHero.cpp @@ -11,7 +11,7 @@ #include "Goals.h" #include "../AIGateway.h" #include "../AIUtility.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" namespace NKAI diff --git a/AI/VCAI/BuildingManager.cpp b/AI/VCAI/BuildingManager.cpp index 5aeba8c6b..f5529777f 100644 --- a/AI/VCAI/BuildingManager.cpp +++ b/AI/VCAI/BuildingManager.cpp @@ -222,7 +222,7 @@ bool BuildingManager::getBuildingOptions(const CGTownInstance * t) std::vector extraBuildings; for (auto buildingInfo : t->town->buildings) { - if (buildingInfo.first > 43) + if (buildingInfo.first > BuildingID::DWELL_UP2_FIRST) extraBuildings.push_back(buildingInfo.first); } return tryBuildAnyStructure(t, extraBuildings); diff --git a/AI/VCAI/Goals/AbstractGoal.cpp b/AI/VCAI/Goals/AbstractGoal.cpp index 45b055d25..3ed71f08d 100644 --- a/AI/VCAI/Goals/AbstractGoal.cpp +++ b/AI/VCAI/Goals/AbstractGoal.cpp @@ -14,7 +14,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/Build.cpp b/AI/VCAI/Goals/Build.cpp index 182c8a4f4..4a57d0a5c 100644 --- a/AI/VCAI/Goals/Build.cpp +++ b/AI/VCAI/Goals/Build.cpp @@ -17,7 +17,7 @@ #include "../ResourceManager.h" #include "../BuildingManager.h" #include "../../../lib/mapObjects/CGTownInstance.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/BuildThis.cpp b/AI/VCAI/Goals/BuildThis.cpp index 703f66784..065db0b01 100644 --- a/AI/VCAI/Goals/BuildThis.cpp +++ b/AI/VCAI/Goals/BuildThis.cpp @@ -16,7 +16,7 @@ #include "../ResourceManager.h" #include "../BuildingManager.h" #include "../../../lib/mapObjects/CGTownInstance.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/CollectRes.cpp b/AI/VCAI/Goals/CollectRes.cpp index d0832c3e3..f5ec1d873 100644 --- a/AI/VCAI/Goals/CollectRes.cpp +++ b/AI/VCAI/Goals/CollectRes.cpp @@ -16,7 +16,7 @@ #include "../ResourceManager.h" #include "../BuildingManager.h" #include "../../../lib/mapObjects/CGMarket.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/Conquer.cpp b/AI/VCAI/Goals/Conquer.cpp index f18b629ed..bf0d368f1 100644 --- a/AI/VCAI/Goals/Conquer.cpp +++ b/AI/VCAI/Goals/Conquer.cpp @@ -15,7 +15,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/Explore.cpp b/AI/VCAI/Goals/Explore.cpp index 13571423f..4c25c74c0 100644 --- a/AI/VCAI/Goals/Explore.cpp +++ b/AI/VCAI/Goals/Explore.cpp @@ -15,7 +15,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" #include "../../../lib/CPlayerState.h" using namespace Goals; diff --git a/AI/VCAI/Goals/GatherArmy.cpp b/AI/VCAI/Goals/GatherArmy.cpp index 2e7ef718f..e6e0557f0 100644 --- a/AI/VCAI/Goals/GatherArmy.cpp +++ b/AI/VCAI/Goals/GatherArmy.cpp @@ -16,7 +16,7 @@ #include "../ResourceManager.h" #include "../BuildingManager.h" #include "../../../lib/mapObjects/CGTownInstance.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/GatherTroops.cpp b/AI/VCAI/Goals/GatherTroops.cpp index 471a997be..4af9e7434 100644 --- a/AI/VCAI/Goals/GatherTroops.cpp +++ b/AI/VCAI/Goals/GatherTroops.cpp @@ -16,7 +16,7 @@ #include "../ResourceManager.h" #include "../BuildingManager.h" #include "../../../lib/mapObjects/CGTownInstance.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/RecruitHero.cpp b/AI/VCAI/Goals/RecruitHero.cpp index 99c5dd0f2..971260202 100644 --- a/AI/VCAI/Goals/RecruitHero.cpp +++ b/AI/VCAI/Goals/RecruitHero.cpp @@ -15,7 +15,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/VisitObj.cpp b/AI/VCAI/Goals/VisitObj.cpp index be52de94d..a31b37af0 100644 --- a/AI/VCAI/Goals/VisitObj.cpp +++ b/AI/VCAI/Goals/VisitObj.cpp @@ -15,7 +15,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/VisitTile.cpp b/AI/VCAI/Goals/VisitTile.cpp index 369ba7380..4e036fbd4 100644 --- a/AI/VCAI/Goals/VisitTile.cpp +++ b/AI/VCAI/Goals/VisitTile.cpp @@ -15,7 +15,7 @@ #include "../FuzzyHelper.h" #include "../ResourceManager.h" #include "../BuildingManager.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/Goals/Win.cpp b/AI/VCAI/Goals/Win.cpp index f2a3b3dce..2ad9abdf8 100644 --- a/AI/VCAI/Goals/Win.cpp +++ b/AI/VCAI/Goals/Win.cpp @@ -17,7 +17,7 @@ #include "../BuildingManager.h" #include "../../../lib/mapping/CMapHeader.h" //for victory conditions #include "../../../lib/mapObjects/CGTownInstance.h" -#include "../../../lib/StringConstants.h" +#include "../../../lib/constants/StringConstants.h" using namespace Goals; diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 68a121f41..e59341a6f 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1594,7 +1594,7 @@ void VCAI::battleEnd(const BattleResult * br, QueryID queryID) logAi->debug("Player %d (%s): I %s the %s!", playerID, playerID.getStr(), (won ? "won" : "lost"), battlename); battlename.clear(); - if (queryID != -1) + if (queryID != QueryID::NONE) { status.addQuery(queryID, "Combat result dialog"); const int confirmAction = 0; diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index 681a02c36..1ffd16eb9 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -19,7 +19,7 @@ #include "../lib/JsonNode.h" #include "../lib/GameConstants.h" #include "../lib/filesystem/Filesystem.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "../lib/CRandomGenerator.h" #include "../lib/VCMIDirs.h" #include "../lib/TerrainHandler.h" diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 5d62dbdf0..a49ae7013 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -854,7 +854,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br, QueryID queryID) if(!battleInt) { - bool allowManualReplay = queryID != -1; + bool allowManualReplay = queryID != QueryID::NONE; auto wnd = std::make_shared(*br, *this, allowManualReplay); diff --git a/client/ClientCommandManager.cpp b/client/ClientCommandManager.cpp index c9cce134e..19ac8dcc9 100644 --- a/client/ClientCommandManager.cpp +++ b/client/ClientCommandManager.cpp @@ -22,7 +22,7 @@ #include "../lib/CConfigHandler.h" #include "../lib/gameState/CGameState.h" #include "../lib/CPlayerState.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "../lib/campaign/CampaignHandler.h" #include "../lib/mapping/CMapService.h" #include "../lib/mapping/CMap.h" diff --git a/client/adventureMap/AdventureMapWidget.cpp b/client/adventureMap/AdventureMapWidget.cpp index 65e1230be..7ee69da42 100644 --- a/client/adventureMap/AdventureMapWidget.cpp +++ b/client/adventureMap/AdventureMapWidget.cpp @@ -29,7 +29,7 @@ #include "../CPlayerInterface.h" #include "../PlayerLocalState.h" -#include "../../lib/StringConstants.h" +#include "../../lib/constants/StringConstants.h" #include "../../lib/filesystem/ResourceID.h" AdventureMapWidget::AdventureMapWidget( std::shared_ptr shortcuts ) diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index 1cb24adcb..bbbd25ca5 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -117,9 +117,9 @@ size_t OptionsTab::CPlayerSettingsHelper::getImageIndex(bool big) return HERO_RANDOM; default: { - if(settings.heroPortrait >= 0) + if(settings.heroPortrait != HeroTypeID::NONE) return settings.heroPortrait; - auto index = settings.hero >= CGI->heroh->size() ? 0 : settings.hero; + auto index = settings.hero.getNum() >= CGI->heroh->size() ? 0 : settings.hero.getNum(); return (*CGI->heroh)[index]->imageIndex; } } @@ -208,7 +208,7 @@ std::string OptionsTab::CPlayerSettingsHelper::getName() { if(!settings.heroName.empty()) return settings.heroName; - auto index = settings.hero >= CGI->heroh->size() ? 0 : settings.hero; + auto index = settings.hero.getNum() >= CGI->heroh->size() ? 0 : settings.hero.getNum(); return (*CGI->heroh)[index]->getNameTranslated(); } } @@ -235,7 +235,7 @@ std::string OptionsTab::CPlayerSettingsHelper::getTitle() case OptionsTab::TOWN: return (settings.castle.getNum() < 0) ? CGI->generaltexth->allTexts[103] : CGI->generaltexth->allTexts[80]; case OptionsTab::HERO: - return (settings.hero < 0) ? CGI->generaltexth->allTexts[101] : CGI->generaltexth->allTexts[77]; + return (settings.hero.getNum() < 0) ? CGI->generaltexth->allTexts[101] : CGI->generaltexth->allTexts[77]; case OptionsTab::BONUS: { switch(settings.bonus) @@ -256,7 +256,7 @@ std::string OptionsTab::CPlayerSettingsHelper::getTitle() std::string OptionsTab::CPlayerSettingsHelper::getSubtitle() { auto factionIndex = settings.castle.getNum() >= CGI->townh->size() ? 0 : settings.castle.getNum(); - auto heroIndex = settings.hero >= CGI->heroh->size() ? 0 : settings.hero; + auto heroIndex = settings.hero.getNum() >= CGI->heroh->size() ? 0 : settings.hero.getNum(); switch(type) { @@ -264,7 +264,7 @@ std::string OptionsTab::CPlayerSettingsHelper::getSubtitle() return getName(); case HERO: { - if(settings.hero >= 0) + if(settings.hero.getNum() >= 0) return getName() + " - " + (*CGI->heroh)[heroIndex]->heroClass->getNameTranslated(); return getName(); } @@ -403,7 +403,7 @@ void OptionsTab::CPlayerOptionTooltipBox::genHeroWindow() pos = Rect(0, 0, 292, 226); genHeader(); labelHeroSpeciality = std::make_shared(pos.w / 2 + 4, 117, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[78]); - auto heroIndex = settings.hero >= CGI->heroh->size() ? 0 : settings.hero; + auto heroIndex = settings.hero.getNum() >= CGI->heroh->size() ? 0 : settings.hero.getNum(); imageSpeciality = std::make_shared("UN44", (*CGI->heroh)[heroIndex]->imageIndex, 0, pos.w / 2 - 22, 134); labelSpecialityName = std::make_shared(pos.w / 2, 188, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, (*CGI->heroh)[heroIndex]->getSpecialtyNameTranslated()); @@ -438,7 +438,7 @@ OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color, SelType _type) allowedHeroes.insert(HeroTypeID(i)); allowedBonus.push_back(-1); // random - if(initialHero >= -1) + if(initialHero.getNum() >= -1) allowedBonus.push_back(0); // artifact allowedBonus.push_back(1); // gold if(initialFaction.getNum() >= 0) @@ -600,8 +600,8 @@ void OptionsTab::SelectionWindow::genContentHeroes() set.hero = PlayerSettings::RANDOM; CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO); components.push_back(std::make_shared(helper.getImageName(), helper.getImageIndex(), 0, 6, (ICON_SMALL_HEIGHT/2))); - drawOutlinedText(TEXT_POS_X, TEXT_POS_Y, (selectedHero == PlayerSettings::RANDOM) ? Colors::YELLOW : Colors::WHITE, helper.getName()); - if(selectedHero == PlayerSettings::RANDOM) + drawOutlinedText(TEXT_POS_X, TEXT_POS_Y, (selectedHero.getNum() == PlayerSettings::RANDOM) ? Colors::YELLOW : Colors::WHITE, helper.getName()); + if(selectedHero.getNum() == PlayerSettings::RANDOM) components.push_back(std::make_shared("lobby/townBorderSmallActivated", 6, (ICON_SMALL_HEIGHT/2))); for(auto & elem : allowedHeroes) @@ -701,7 +701,7 @@ void OptionsTab::SelectionWindow::setElement(int elem, bool doApply) { set.hero = PlayerSettings::RANDOM; } - if(set.hero != PlayerSettings::NONE) + if(set.hero.getNum() != PlayerSettings::NONE) { if(!doApply) { @@ -786,7 +786,7 @@ void OptionsTab::SelectedBox::showPopupWindow(const Point & cursorPosition) // cases when we do not need to display a message if(settings.castle.getNum() == PlayerSettings::NONE && CPlayerSettingsHelper::type == TOWN) return; - if(settings.hero == PlayerSettings::NONE && !SEL->getPlayerInfo(settings.color.getNum()).hasCustomMainHero() && CPlayerSettingsHelper::type == HERO) + if(settings.hero.getNum() == PlayerSettings::NONE && !SEL->getPlayerInfo(settings.color.getNum()).hasCustomMainHero() && CPlayerSettingsHelper::type == HERO) return; GH.windows().createAndPushWindow(*this); diff --git a/client/widgets/CArtifactsOfHeroBackpack.cpp b/client/widgets/CArtifactsOfHeroBackpack.cpp index 18a704a19..feb3c974a 100644 --- a/client/widgets/CArtifactsOfHeroBackpack.cpp +++ b/client/widgets/CArtifactsOfHeroBackpack.cpp @@ -77,7 +77,7 @@ void CArtifactsOfHeroBackpack::scrollBackpack(int offset) if(backpackListBox) backpackListBox->resize(getActiveSlotLinesNum()); backpackPos += offset; - auto slot = ArtifactPosition(GameConstants::BACKPACK_START + backpackPos); + auto slot = ArtifactPosition::BACKPACK_START + backpackPos; for(auto artPlace : backpack) { setSlotData(artPlace, slot, *curHero); diff --git a/client/widgets/CArtifactsOfHeroBase.cpp b/client/widgets/CArtifactsOfHeroBase.cpp index 799135837..f24d836ae 100644 --- a/client/widgets/CArtifactsOfHeroBase.cpp +++ b/client/widgets/CArtifactsOfHeroBase.cpp @@ -63,7 +63,7 @@ void CArtifactsOfHeroBase::init( // CArtifactsOfHeroBase::init may be transform to CArtifactsOfHeroBase::CArtifactsOfHeroBase if OBJECT_CONSTRUCTION_CAPTURING is removed OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE); pos += position; - for(int g = 0; g < GameConstants::BACKPACK_START; g++) + for(int g = 0; g < ArtifactPosition::BACKPACK_START; g++) { artWorn[ArtifactPosition(g)] = std::make_shared(slotPos[g]); } @@ -143,7 +143,7 @@ void CArtifactsOfHeroBase::scrollBackpackForArtSet(int offset, const CArtifactSe }; slotInc inc_ring = [artsInBackpack](ArtifactPosition & slot) -> ArtifactPosition { - return ArtifactPosition(GameConstants::BACKPACK_START + (slot - GameConstants::BACKPACK_START + 1) % artsInBackpack); + return ArtifactPosition::BACKPACK_START + (slot - ArtifactPosition::BACKPACK_START + 1) % artsInBackpack; }; slotInc inc; if(scrollingPossible) @@ -158,7 +158,7 @@ void CArtifactsOfHeroBase::scrollBackpackForArtSet(int offset, const CArtifactSe if(artsInBackpack) backpackPos %= artsInBackpack; - auto slot = ArtifactPosition(GameConstants::BACKPACK_START + backpackPos); + auto slot = ArtifactPosition(ArtifactPosition::BACKPACK_START + backpackPos); for(auto artPlace : backpack) { setSlotData(artPlace, slot, artSet); diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index d7bd05405..9364ad703 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -651,7 +651,7 @@ const CGHeroInstance * CCastleBuildings::getHero() return town->garrisonHero; } -void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades) +void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID, BuildingID upgrades) { logGlobal->trace("You've clicked on %d", (int)building.toEnum()); const CBuilding *b = town->town->buildings.find(building)->second; @@ -876,7 +876,7 @@ void CCastleBuildings::enterToTheQuickRecruitmentWindow() CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.townHall.noCreaturesToRecruit"), {}); } -void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades) +void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID upgrades) { std::vector> comps(1, std::make_shared(CComponent::building,town->subID,building)); std::string descr = town->town->buildings.find(building)->second->getDescriptionTranslated(); @@ -1613,7 +1613,9 @@ CFortScreen::CFortScreen(const CGTownInstance * town): BuildingID buildingID; if(fortSize == GameConstants::CREATURES_PER_TOWN) { - if(vstd::contains(town->builtBuildings, BuildingID::DWELL_UP_FIRST+i)) + BuildingID dwelling = BuildingID::DWELL_UP_FIRST+i; + + if(vstd::contains(town->builtBuildings, dwelling)) buildingID = BuildingID(BuildingID::DWELL_UP_FIRST+i); else buildingID = BuildingID(BuildingID::DWELL_FIRST+i); @@ -1718,7 +1720,7 @@ const CCreature * CFortScreen::RecruitArea::getMyCreature() const CBuilding * CFortScreen::RecruitArea::getMyBuilding() { - BuildingID myID = BuildingID(BuildingID::DWELL_FIRST).advance(level); + BuildingID myID = BuildingID(BuildingID::DWELL_FIRST + level); if (level == GameConstants::CREATURES_PER_TOWN) return town->town->getSpecialBuilding(BuildingSubID::PORTAL_OF_SUMMONING); diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 8aa56bbf1..3e05f3079 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -152,7 +152,7 @@ class CCastleBuildings : public CIntObject void enterBlacksmith(ArtifactID artifactID);//support for blacksmith + ballista yard void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages void enterCastleGate(); - void enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades);//Rampart's fountains + void enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID upgrades);//Rampart's fountains void enterMagesGuild(); void enterTownHall(); @@ -169,7 +169,7 @@ public: void enterDwelling(int level); void enterToTheQuickRecruitmentWindow(); - void buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID = BuildingSubID::NONE, BuildingID::EBuildingID upgrades = BuildingID::NONE); + void buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID = BuildingSubID::NONE, BuildingID upgrades = BuildingID::NONE); void addBuilding(BuildingID building); void removeBuilding(BuildingID building);//FIXME: not tested!!! }; diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index 0a2a40f39..04c94015b 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -369,6 +369,11 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/campaign/CampaignScenarioPrologEpilog.h ${MAIN_LIB_DIR}/campaign/CampaignState.h + ${MAIN_LIB_DIR}/constants/EntityIdentifiers.h + ${MAIN_LIB_DIR}/constants/Enumerations.h + ${MAIN_LIB_DIR}/constants/NumericConstants.h + ${MAIN_LIB_DIR}/constants/StringConstants.h + ${MAIN_LIB_DIR}/events/ApplyDamage.h ${MAIN_LIB_DIR}/events/GameResumed.h ${MAIN_LIB_DIR}/events/ObjectVisitEnded.h @@ -621,7 +626,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/ScriptHandler.h ${MAIN_LIB_DIR}/ScopeGuard.h ${MAIN_LIB_DIR}/StartInfo.h - ${MAIN_LIB_DIR}/StringConstants.h ${MAIN_LIB_DIR}/TerrainHandler.h ${MAIN_LIB_DIR}/TextOperations.h ${MAIN_LIB_DIR}/TurnTimerInfo.h diff --git a/include/vcmi/Faction.h b/include/vcmi/Faction.h index 2bc959567..6a1afe58f 100644 --- a/include/vcmi/Faction.h +++ b/include/vcmi/Faction.h @@ -15,7 +15,7 @@ VCMI_LIB_NAMESPACE_BEGIN class FactionID; -enum class EAlignment : uint8_t; +enum class EAlignment : int8_t; class BoatId; class DLL_LINKAGE Faction : public EntityT, public INativeTerrainProvider diff --git a/lib/ArtifactUtils.cpp b/lib/ArtifactUtils.cpp index a3532bee3..eeb94c2c6 100644 --- a/lib/ArtifactUtils.cpp +++ b/lib/ArtifactUtils.cpp @@ -33,16 +33,16 @@ DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtAnyPosition(const CArtifactSet DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtBackpackPosition(const CArtifactSet * target, const ArtifactID & aid) { const auto * art = aid.toArtifact(); - if(art->canBePutAt(target, GameConstants::BACKPACK_START)) + if(art->canBePutAt(target, ArtifactPosition::BACKPACK_START)) { - return GameConstants::BACKPACK_START; + return ArtifactPosition::BACKPACK_START; } return ArtifactPosition::PRE_FIRST; } -DLL_LINKAGE const std::vector & ArtifactUtils::unmovableSlots() +DLL_LINKAGE const std::vector & ArtifactUtils::unmovableSlots() { - static const std::vector positions = + static const std::vector positions = { ArtifactPosition::SPELLBOOK, ArtifactPosition::MACH4 @@ -51,9 +51,9 @@ DLL_LINKAGE const std::vector & ArtifactUti return positions; } -DLL_LINKAGE const std::vector & ArtifactUtils::constituentWornSlots() +DLL_LINKAGE const std::vector & ArtifactUtils::constituentWornSlots() { - static const std::vector positions = + static const std::vector positions = { ArtifactPosition::HEAD, ArtifactPosition::SHOULDERS, @@ -98,12 +98,12 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(const ArtifactPosition & slot) { - return slot >= GameConstants::BACKPACK_START; + return slot >= ArtifactPosition::BACKPACK_START; } DLL_LINKAGE bool ArtifactUtils::isSlotEquipment(const ArtifactPosition & slot) { - return slot < GameConstants::BACKPACK_START && slot >= 0; + return slot < ArtifactPosition::BACKPACK_START && slot >= ArtifactPosition(0); } DLL_LINKAGE bool ArtifactUtils::isBackpackFreeSlots(const CArtifactSet * target, const size_t reqSlots) diff --git a/lib/ArtifactUtils.h b/lib/ArtifactUtils.h index 39532f38e..2e70999b6 100644 --- a/lib/ArtifactUtils.h +++ b/lib/ArtifactUtils.h @@ -29,8 +29,8 @@ namespace ArtifactUtils DLL_LINKAGE ArtifactPosition getArtAnyPosition(const CArtifactSet * target, const ArtifactID & aid); DLL_LINKAGE ArtifactPosition getArtBackpackPosition(const CArtifactSet * target, const ArtifactID & aid); // TODO: Make this constexpr when the toolset is upgraded - DLL_LINKAGE const std::vector & unmovableSlots(); - DLL_LINKAGE const std::vector & constituentWornSlots(); + DLL_LINKAGE const std::vector & unmovableSlots(); + DLL_LINKAGE const std::vector & constituentWornSlots(); DLL_LINKAGE bool isArtRemovable(const std::pair & slot); DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, const ArtifactID & artID, const ArtifactPosition & slot); DLL_LINKAGE bool isSlotBackpack(const ArtifactPosition & slot); diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index abbaf32eb..9b8664301 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -15,7 +15,7 @@ #include "CGeneralTextHandler.h" #include "GameSettings.h" #include "mapObjects/MapObjects.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "mapObjectConstructors/AObjectTypeHandler.h" #include "mapObjectConstructors/CObjectClassesHandler.h" @@ -239,11 +239,11 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b if(artCanBePutAt(artSet, slot, assumeDestRemoved)) return true; } - return artCanBePutAt(artSet, GameConstants::BACKPACK_START, assumeDestRemoved); + return artCanBePutAt(artSet, ArtifactPosition::BACKPACK_START, assumeDestRemoved); } else if(ArtifactUtils::isSlotBackpack(slot)) { - return artCanBePutAt(artSet, GameConstants::BACKPACK_START, assumeDestRemoved); + return artCanBePutAt(artSet, ArtifactPosition::BACKPACK_START, assumeDestRemoved); } else { @@ -483,17 +483,16 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode return art; } -ArtifactPosition::ArtifactPosition(std::string slotName): - num(ArtifactPosition::PRE_FIRST) +int32_t ArtifactPositionBase::decode(const std::string & slotName) { #define ART_POS(x) { #x, ArtifactPosition::x }, static const std::map artifactPositionMap = { ART_POS_LIST }; #undef ART_POS auto it = artifactPositionMap.find (slotName); if (it != artifactPositionMap.end()) - num = it->second; + return it->second; else - logMod->warn("Warning! Artifact slot %s not recognized!", slotName); + return PRE_FIRST; } void CArtHandler::addSlot(CArtifact * art, const std::string & slotID) const @@ -518,7 +517,7 @@ void CArtHandler::addSlot(CArtifact * art, const std::string & slotID) const } else { - auto slot = ArtifactPosition(slotID); + auto slot = ArtifactPosition::decode(slotID); if (slot != ArtifactPosition::PRE_FIRST) art->possibleSlots[ArtBearer::HERO].push_back(slot); } @@ -848,7 +847,7 @@ std::vector CArtifactSet::getBackpackArtPositions(const Artifa { std::vector result; - si32 backpackPosition = GameConstants::BACKPACK_START; + si32 backpackPosition = ArtifactPosition::BACKPACK_START; for(const auto & artInfo : artifactsInBackpack) { const auto * art = artInfo.getArt(); @@ -867,7 +866,7 @@ ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const for(int i = 0; i < artifactsInBackpack.size(); i++) if(artifactsInBackpack[i].artifact == art) - return ArtifactPosition(GameConstants::BACKPACK_START + i); + return ArtifactPosition::BACKPACK_START + i; return ArtifactPosition::PRE_FIRST; } @@ -893,7 +892,7 @@ const ArtifactPosition CArtifactSet::getSlotByInstance(const CArtifactInstance * if(getArt(slot) == artInst) return slot; - auto backpackSlot = GameConstants::BACKPACK_START; + ArtifactPosition backpackSlot = ArtifactPosition::BACKPACK_START; for(auto & slotInfo : artifactsInBackpack) { if(slotInfo.getArt() == artInst) @@ -1014,7 +1013,7 @@ const ArtSlotInfo * CArtifactSet::getSlot(const ArtifactPosition & pos) const return &artifactsWorn.at(pos); if(pos >= ArtifactPosition::AFTER_LAST ) { - int backpackPos = (int)pos - GameConstants::BACKPACK_START; + int backpackPos = (int)pos - ArtifactPosition::BACKPACK_START; if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size()) return nullptr; else @@ -1049,7 +1048,7 @@ void CArtifactSet::setNewArtSlot(const ArtifactPosition & slot, CArtifactInstanc } else { - auto position = artifactsInBackpack.begin() + slot - GameConstants::BACKPACK_START; + auto position = artifactsInBackpack.begin() + slot - ArtifactPosition::BACKPACK_START; slotInfo = &(*artifactsInBackpack.emplace(position, ArtSlotInfo())); } slotInfo->artifact = art; @@ -1065,7 +1064,7 @@ void CArtifactSet::eraseArtSlot(const ArtifactPosition & slot) } else if(ArtifactUtils::isSlotBackpack(slot)) { - auto backpackSlot = ArtifactPosition(slot - GameConstants::BACKPACK_START); + auto backpackSlot = ArtifactPosition(slot - ArtifactPosition::BACKPACK_START); assert(artifactsInBackpack.begin() + backpackSlot < artifactsInBackpack.end()); artifactsInBackpack.erase(artifactsInBackpack.begin() + backpackSlot); @@ -1136,7 +1135,7 @@ void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map) for(const ArtifactID & artifactID : backpackTemp) { auto * artifact = ArtifactUtils::createArtifact(map, artifactID.toEnum()); - auto slot = ArtifactPosition(GameConstants::BACKPACK_START + (si32)artifactsInBackpack.size()); + auto slot = ArtifactPosition::BACKPACK_START + (si32)artifactsInBackpack.size(); if(artifact->artType->canBePutAt(this, slot)) putArtifact(slot, artifact); } diff --git a/lib/CArtifactInstance.h b/lib/CArtifactInstance.h index 079db214f..66e405328 100644 --- a/lib/CArtifactInstance.h +++ b/lib/CArtifactInstance.h @@ -11,6 +11,7 @@ #include "bonuses/CBonusSystemNode.h" #include "GameConstants.h" +#include "ConstTransitivePtr.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CBuildingHandler.cpp b/lib/CBuildingHandler.cpp index d5539ebac..a4673e5ae 100644 --- a/lib/CBuildingHandler.cpp +++ b/lib/CBuildingHandler.cpp @@ -53,7 +53,9 @@ BuildingID CBuildingHandler::campToERMU(int camp, int townType, const std::set 1) { - if(vstd::contains(builtBuildings, 37 + hordeLvlsPerTType[townType][1])) //if upgraded dwelling is built + BuildingID dwellingID(BuildingID::DWELL_UP_FIRST + hordeLvlsPerTType[townType][1]); + + if(vstd::contains(builtBuildings, dwellingID)) //if upgraded dwelling is built return BuildingID::HORDE_2_UPGR; else //upgraded dwelling not presents return BuildingID::HORDE_2; diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 205aa1ccf..8a49bb8b6 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -16,7 +16,7 @@ #include "VCMI_Lib.h" #include "CTownHandler.h" #include "GameSettings.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "bonuses/Limiters.h" #include "bonuses/Updaters.h" #include "serializer/JsonDeserializer.h" diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index c60023ad4..4b9923b36 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -14,7 +14,7 @@ #include "filesystem/Filesystem.h" #include "VCMI_Lib.h" #include "JsonNode.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "battle/BattleHex.h" #include "CCreatureHandler.h" #include "GameSettings.h" diff --git a/lib/CPlayerState.h b/lib/CPlayerState.h index 1b304eebc..ac8c1d4c6 100644 --- a/lib/CPlayerState.h +++ b/lib/CPlayerState.h @@ -16,6 +16,7 @@ #include "bonuses/CBonusSystemNode.h" #include "ResourceSet.h" #include "TurnTimerInfo.h" +#include "ConstTransitivePtr.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index 96a017208..dcd5d6725 100644 --- a/lib/CSkillHandler.cpp +++ b/lib/CSkillHandler.cpp @@ -22,7 +22,7 @@ #include "JsonNode.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 04a928ffb..ac01e787a 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -13,7 +13,7 @@ #include "VCMI_Lib.h" #include "CGeneralTextHandler.h" #include "JsonNode.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "CCreatureHandler.h" #include "CHeroHandler.h" #include "CArtHandler.h" @@ -82,7 +82,7 @@ std::string CBuilding::getDescriptionTextID() const BuildingID CBuilding::getBase() const { const CBuilding * build = this; - while (build->upgrade >= 0) + while (build->upgrade != BuildingID::NONE) { build = build->town->buildings.at(build->upgrade); } @@ -94,7 +94,7 @@ si32 CBuilding::getDistance(const BuildingID & buildID) const { const CBuilding * build = town->buildings.at(buildID); int distance = 0; - while (build->upgrade >= 0 && build != this) + while (build->upgrade != BuildingID::NONE && build != this) { build = build->town->buildings.at(build->upgrade); distance++; @@ -265,7 +265,7 @@ const CBuilding * CTown::getSpecialBuilding(BuildingSubID::EBuildingSubID subID) return nullptr; } -BuildingID::EBuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const +BuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const { const auto * building = getSpecialBuilding(subID); return building == nullptr ? BuildingID::NONE : building->bid.num; diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 0b4b40a08..0c15ef396 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -266,7 +266,7 @@ public: const CBuilding * getSpecialBuilding(BuildingSubID::EBuildingSubID subID) const; 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; + BuildingID getBuildingType(BuildingSubID::EBuildingSubID subID) const; std::string getRandomNameTranslated(size_t index) const; std::string getRandomNameTextID(size_t index) const; diff --git a/lib/GameConstants.cpp b/lib/GameConstants.cpp index f9095bc46..1b528ec7e 100644 --- a/lib/GameConstants.cpp +++ b/lib/GameConstants.cpp @@ -32,7 +32,7 @@ #include "CCreatureHandler.h"//todo: remove #include "spells/CSpellHandler.h" //todo: remove #include "CSkillHandler.h"//todo: remove -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "CGeneralTextHandler.h" #include "TerrainHandler.h" //TODO: remove #include "BattleFieldHandler.h" @@ -40,6 +40,7 @@ VCMI_LIB_NAMESPACE_BEGIN +const QueryID QueryID::NONE = QueryID(-1); const HeroTypeID HeroTypeID::NONE = HeroTypeID(-1); const ObjectInstanceID ObjectInstanceID::NONE = ObjectInstanceID(-1); @@ -257,7 +258,7 @@ std::ostream & operator<<(std::ostream & os, const EActionType actionType) std::ostream & operator<<(std::ostream & os, const EPathfindingLayer & pathfindingLayer) { - static const std::map pathfinderLayerToString + static const std::map pathfinderLayerToString { #define DEFINE_ELEMENT(element) {EPathfindingLayer::element, #element} DEFINE_ELEMENT(WRONG), diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 5c8fc936f..cb88895ac 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -9,1387 +9,14 @@ */ #pragma once -#include "ConstTransitivePtr.h" +#include "constants/NumericConstants.h" +#include "constants/Enumerations.h" +#include "constants/EntityIdentifiers.h" VCMI_LIB_NAMESPACE_BEGIN -class Artifact; -class ArtifactService; -class Creature; -class CreatureService; - -namespace spells -{ - class Spell; - class Service; -} - -class CArtifact; -class CArtifactInstance; -class CCreature; -class CHero; -class CSpell; -class CSkill; -class CGameInfoCallback; -class CNonConstInfoCallback; - - -struct IdTag -{}; - -namespace GameConstants -{ - DLL_LINKAGE extern const std::string VCMI_VERSION; - - constexpr int PUZZLE_MAP_PIECES = 48; - - constexpr int MAX_HEROES_PER_PLAYER = 8; - constexpr int AVAILABLE_HEROES_PER_PLAYER = 2; - - constexpr int ALL_PLAYERS = 255; //bitfield - - constexpr int CREATURES_PER_TOWN = 7; //without upgrades - constexpr int SPELL_LEVELS = 5; - constexpr int SPELL_SCHOOL_LEVELS = 4; - constexpr int DEFAULT_SCHOOLS = 4; - constexpr int CRE_LEVELS = 10; // number of creature experience levels - - constexpr int HERO_GOLD_COST = 2500; - constexpr int SPELLBOOK_GOLD_COST = 500; - constexpr int SKILL_GOLD_COST = 2000; - constexpr int BATTLE_SHOOTING_PENALTY_DISTANCE = 10; //if the distance is > than this, then shooting stack has distance penalty - constexpr int BATTLE_SHOOTING_RANGE_DISTANCE = std::numeric_limits::max(); // used when shooting stack has no shooting range limit - constexpr int ARMY_SIZE = 7; - constexpr int SKILL_PER_HERO = 8; - constexpr ui32 HERO_HIGH_LEVEL = 10; // affects primary skill upgrade order - - constexpr int SKILL_QUANTITY=28; - constexpr int PRIMARY_SKILLS=4; - constexpr int RESOURCE_QUANTITY=8; - constexpr int HEROES_PER_TYPE=8; //amount of heroes of each type - - // amounts of OH3 objects. Can be changed by mods, should be used only during H3 loading phase - constexpr int F_NUMBER = 9; - constexpr int ARTIFACTS_QUANTITY=171; - constexpr int HEROES_QUANTITY=156; - constexpr int SPELLS_QUANTITY=70; - constexpr int CREATURES_COUNT = 197; - - constexpr ui32 BASE_MOVEMENT_COST = 100; //default cost for non-diagonal movement - - constexpr int HERO_PORTRAIT_SHIFT = 9;// 2 special frames + 7 extra portraits - - constexpr std::array POSSIBLE_TURNTIME = {1, 2, 4, 6, 8, 10, 15, 20, 25, 30, 0}; -} - -#define ID_LIKE_CLASS_COMMON(CLASS_NAME, ENUM_NAME) \ -constexpr CLASS_NAME(const CLASS_NAME & other) = default; \ -constexpr CLASS_NAME & operator=(const CLASS_NAME & other) = default; \ -explicit constexpr CLASS_NAME(si32 id) \ - : num(static_cast(id)) \ -{} \ -constexpr operator ENUM_NAME() const \ -{ \ - return num; \ -} \ -constexpr si32 getNum() const \ -{ \ - return static_cast(num); \ -} \ -constexpr ENUM_NAME toEnum() const \ -{ \ - return num; \ -} \ -template void serialize(Handler &h, const int version) \ -{ \ - h & num; \ -} \ -constexpr CLASS_NAME & advance(int i) \ -{ \ - num = static_cast(static_cast(num) + i); \ - return *this; \ -} - - -// Operators are performance-critical and to be inlined they must be in header -#define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \ -STRONG_INLINE constexpr bool operator==(const A & a, const B & b) \ -{ \ - return AN == BN ; \ -} \ -STRONG_INLINE constexpr bool operator!=(const A & a, const B & b) \ -{ \ - return AN != BN ; \ -} \ -STRONG_INLINE constexpr bool operator<(const A & a, const B & b) \ -{ \ - return AN < BN ; \ -} \ -STRONG_INLINE constexpr bool operator<=(const A & a, const B & b) \ -{ \ - return AN <= BN ; \ -} \ -STRONG_INLINE constexpr bool operator>(const A & a, const B & b) \ -{ \ - return AN > BN ; \ -} \ -STRONG_INLINE constexpr bool operator>=(const A & a, const B & b) \ -{ \ - return AN >= BN ; \ -} - -#define ID_LIKE_OPERATORS(CLASS_NAME, ENUM_NAME) \ - ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, CLASS_NAME, a.num, b.num) \ - ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, ENUM_NAME, a.num, b) \ - ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num) - - -#define INSTID_LIKE_CLASS_COMMON(CLASS_NAME, NUMERIC_NAME) \ -public: \ -constexpr CLASS_NAME(const CLASS_NAME & other): \ - BaseForID(other) \ -{ \ -} \ -constexpr CLASS_NAME & operator=(const CLASS_NAME & other) = default; \ -constexpr CLASS_NAME & operator=(NUMERIC_NAME other) { num = other; return *this; }; \ -explicit constexpr CLASS_NAME(si32 id = -1) \ - : BaseForID(id) \ -{} - -template < typename Derived, typename NumericType> -class BaseForID : public IdTag -{ -protected: - NumericType num; - -public: - constexpr NumericType getNum() const - { - return num; - } - - //to make it more similar to IDLIKE - constexpr NumericType toEnum() const - { - return num; - } - - template void serialize(Handler &h, const int version) - { - h & num; - } - - constexpr explicit BaseForID(NumericType _num = -1) : - num(_num) - { - } - - constexpr void advance(int change) - { - num += change; - } - - constexpr bool operator == (const BaseForID & b) const { return num == b.num; } - constexpr bool operator <= (const BaseForID & b) const { return num <= b.num; } - constexpr bool operator >= (const BaseForID & b) const { return num >= b.num; } - constexpr bool operator != (const BaseForID & b) const { return num != b.num; } - constexpr bool operator < (const BaseForID & b) const { return num < b.num; } - constexpr bool operator > (const BaseForID & b) const { return num > b.num; } - - constexpr BaseForID & operator++() { ++num; return *this; } - - constexpr operator NumericType() const - { - return num; - } -}; - -template -std::ostream & operator << (std::ostream & os, BaseForID id); - -template -std::ostream & operator << (std::ostream & os, BaseForID id) -{ - //We use common type with short to force char and unsigned char to be promoted and formatted as numbers. - typedef typename std::common_type::type Number; - return os << static_cast(id.getNum()); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -class EntityBase -{ -public: - int32_t num; - - struct hash - { - size_t operator()(const EntityBase & id) const - { - return std::hash()(id.num); - } - }; -}; - -template -class EntityIdentifier : public T -{ - using EnumType = typename T::Type; - - static_assert(std::is_same_v, int32_t>, "Entity Identifier must use int32_t"); -public: - constexpr int32_t getNum() const - { - return T::num; - } - - constexpr EnumType toEnum() const - { - return static_cast(T::num); - } - - template void serialize(Handler &h, const int version) - { - h & T::num; - } - - constexpr EntityIdentifier(const EnumType & enumValue) - { - T::num = static_cast(enumValue); - } - - constexpr EntityIdentifier(int32_t _num = -1) - { - T::num = _num; - } - - constexpr void advance(int change) - { - T::num += change; - } - - constexpr bool operator == (const EnumType & b) const { return T::num == static_cast(b); } - constexpr bool operator <= (const EnumType & b) const { return T::num <= static_cast(b); } - constexpr bool operator >= (const EnumType & b) const { return T::num >= static_cast(b); } - constexpr bool operator != (const EnumType & b) const { return T::num != static_cast(b); } - constexpr bool operator < (const EnumType & b) const { return T::num < static_cast(b); } - constexpr bool operator > (const EnumType & b) const { return T::num > static_cast(b); } - - constexpr bool operator == (const EntityIdentifier & b) const { return T::num == b.num; } - constexpr bool operator <= (const EntityIdentifier & b) const { return T::num <= b.num; } - constexpr bool operator >= (const EntityIdentifier & b) const { return T::num >= b.num; } - constexpr bool operator != (const EntityIdentifier & b) const { return T::num != b.num; } - constexpr bool operator < (const EntityIdentifier & b) const { return T::num < b.num; } - constexpr bool operator > (const EntityIdentifier & b) const { return T::num > b.num; } - - constexpr EntityIdentifier & operator++() - { - ++T::num; - return *this; - } - - constexpr EntityIdentifier operator++(int) - { - EntityIdentifier ret(*this); - ++T::num; - return ret; - } - - constexpr operator int32_t () const - { - return T::num; - } -}; - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -class ArtifactInstanceID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(ArtifactInstanceID, si32) - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; -}; - -class QueryID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(QueryID, si32) - - QueryID & operator++() - { - ++num; - return *this; - } -}; - -class ObjectInstanceID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(ObjectInstanceID, si32) - - DLL_LINKAGE static const ObjectInstanceID NONE; - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; -}; - -class HeroClassID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(HeroClassID, si32) -}; - -class HeroTypeID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(HeroTypeID, si32) - - ///json serialization helpers - static si32 decode(const std::string & identifier); - static std::string encode(const si32 index); - - DLL_LINKAGE static const HeroTypeID NONE; -}; - -class SlotID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(SlotID, si32) - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; - - DLL_LINKAGE static const SlotID COMMANDER_SLOT_PLACEHOLDER; - DLL_LINKAGE static const SlotID SUMMONED_SLOT_PLACEHOLDER; ///= 0 && getNum() < GameConstants::ARMY_SIZE; - } -}; - -class PlayerColor : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(PlayerColor, ui8) - - enum EPlayerColor - { - PLAYER_LIMIT_I = 8, - }; - - using Mask = uint8_t; - - DLL_LINKAGE static const PlayerColor SPECTATOR; //252 - DLL_LINKAGE static const PlayerColor CANNOT_DETERMINE; //253 - DLL_LINKAGE static const PlayerColor UNFLAGGABLE; //254 - neutral objects (pandora, banks) - DLL_LINKAGE static const PlayerColor NEUTRAL; //255 - DLL_LINKAGE static const PlayerColor PLAYER_LIMIT; //player limit per map - - DLL_LINKAGE bool isValidPlayer() const; //valid means < PLAYER_LIMIT (especially non-neutral) - DLL_LINKAGE bool isSpectator() const; - - DLL_LINKAGE std::string getStr(bool L10n = false) const; - DLL_LINKAGE std::string getStrCap(bool L10n = false) const; - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; -}; - -class TeamID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(TeamID, ui8) - - DLL_LINKAGE static const TeamID NO_TEAM; - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; -}; - -class TeleportChannelID : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(TeleportChannelID, si32) - - friend class CGameInfoCallback; - friend class CNonConstInfoCallback; -}; - -// Enum declarations -enum class PrimarySkill : int8_t -{ - NONE = -1, - ATTACK, - DEFENSE, - SPELL_POWER, - KNOWLEDGE, - EXPERIENCE = 4 //for some reason changePrimSkill uses it -}; - -class SecondarySkillBase : public EntityBase -{ -public: - enum Type : int32_t - { - WRONG = -2, - DEFAULT = -1, - PATHFINDING = 0, ARCHERY, LOGISTICS, SCOUTING, DIPLOMACY, NAVIGATION, LEADERSHIP, WISDOM, MYSTICISM, - LUCK, BALLISTICS, EAGLE_EYE, NECROMANCY, ESTATES, FIRE_MAGIC, AIR_MAGIC, WATER_MAGIC, EARTH_MAGIC, - SCHOLAR, TACTICS, ARTILLERY, LEARNING, OFFENCE, ARMORER, INTELLIGENCE, SORCERY, RESISTANCE, - FIRST_AID, SKILL_SIZE - }; - static_assert(GameConstants::SKILL_QUANTITY == SKILL_SIZE, "Incorrect number of skills"); -}; - -class SecondarySkill : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -enum class EAlignment : uint8_t { GOOD, EVIL, NEUTRAL }; - -class FactionIDBase : public EntityBase -{ -public: - enum Type : int32_t - { - NONE = -2, - DEFAULT = -1, - RANDOM = -1, - ANY = -1, - CASTLE, - RAMPART, - TOWER, - INFERNO, - NECROPOLIS, - DUNGEON, - STRONGHOLD, - FORTRESS, - CONFLUX, - NEUTRAL - }; - - static si32 decode(const std::string& identifier); - static std::string encode(const si32 index); - static std::string entityType(); -}; - -class FactionID : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -using ETownType = FactionID; - -class BuildingID -{ -public: - //Quite useful as long as most of building mechanics hardcoded - // NOTE: all building with completely configurable mechanics will be removed from list - enum EBuildingID - { - DEFAULT = -50, - HORDE_PLACEHOLDER7 = -36, - HORDE_PLACEHOLDER6 = -35, - HORDE_PLACEHOLDER5 = -34, - HORDE_PLACEHOLDER4 = -33, - HORDE_PLACEHOLDER3 = -32, - HORDE_PLACEHOLDER2 = -31, - HORDE_PLACEHOLDER1 = -30, - NONE = -1, - FIRST_REGULAR_ID = 0, - MAGES_GUILD_1 = 0, MAGES_GUILD_2, MAGES_GUILD_3, MAGES_GUILD_4, MAGES_GUILD_5, - TAVERN, SHIPYARD, FORT, CITADEL, CASTLE, - VILLAGE_HALL, TOWN_HALL, CITY_HALL, CAPITOL, MARKETPLACE, - RESOURCE_SILO, BLACKSMITH, SPECIAL_1, HORDE_1, HORDE_1_UPGR, - SHIP, SPECIAL_2, SPECIAL_3, SPECIAL_4, HORDE_2, - HORDE_2_UPGR, GRAIL, EXTRA_TOWN_HALL, EXTRA_CITY_HALL, EXTRA_CAPITOL, - DWELL_FIRST=30, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LAST=36, - DWELL_UP_FIRST=37, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, - DWELL_LVL_6_UP, DWELL_UP_LAST=43, - - DWELL_LVL_1 = DWELL_FIRST, - DWELL_LVL_7 = DWELL_LAST, - DWELL_LVL_1_UP = DWELL_UP_FIRST, - DWELL_LVL_7_UP = DWELL_UP_LAST, - - //Special buildings for towns. - LIGHTHOUSE = SPECIAL_1, - STABLES = SPECIAL_2, //Castle - BROTHERHOOD = SPECIAL_3, - - MYSTIC_POND = SPECIAL_1, - FOUNTAIN_OF_FORTUNE = SPECIAL_2, //Rampart - TREASURY = SPECIAL_3, - - ARTIFACT_MERCHANT = SPECIAL_1, - LOOKOUT_TOWER = SPECIAL_2, //Tower - LIBRARY = SPECIAL_3, - WALL_OF_KNOWLEDGE = SPECIAL_4, - - STORMCLOUDS = SPECIAL_2, - CASTLE_GATE = SPECIAL_3, //Inferno - ORDER_OF_FIRE = SPECIAL_4, - - COVER_OF_DARKNESS = SPECIAL_1, - NECROMANCY_AMPLIFIER = SPECIAL_2, //Necropolis - SKELETON_TRANSFORMER = SPECIAL_3, - - //ARTIFACT_MERCHANT - same ID as in tower - MANA_VORTEX = SPECIAL_2, - PORTAL_OF_SUMMON = SPECIAL_3, //Dungeon - BATTLE_ACADEMY = SPECIAL_4, - - ESCAPE_TUNNEL = SPECIAL_1, - FREELANCERS_GUILD = SPECIAL_2, //Stronghold - BALLISTA_YARD = SPECIAL_3, - HALL_OF_VALHALLA = SPECIAL_4, - - CAGE_OF_WARLORDS = SPECIAL_1, - GLYPHS_OF_FEAR = SPECIAL_2, // Fortress - BLOOD_OBELISK = SPECIAL_3, - - //ARTIFACT_MERCHANT - same ID as in tower - MAGIC_UNIVERSITY = SPECIAL_2, // Conflux - }; - - BuildingID(EBuildingID _num = NONE) : num(_num) - {} - - STRONG_INLINE - bool IsSpecialOrGrail() const - { - return num == SPECIAL_1 || num == SPECIAL_2 || num == SPECIAL_3 || num == SPECIAL_4 || num == GRAIL; - } - - ID_LIKE_CLASS_COMMON(BuildingID, EBuildingID) - - EBuildingID num; -}; - -ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID) - -namespace BuildingSubID -{ - enum EBuildingSubID - { - DEFAULT = -50, - NONE = -1, - STABLES, - BROTHERHOOD_OF_SWORD, - CASTLE_GATE, - CREATURE_TRANSFORMER, - MYSTIC_POND, - FOUNTAIN_OF_FORTUNE, - ARTIFACT_MERCHANT, - LOOKOUT_TOWER, - LIBRARY, - MANA_VORTEX, - PORTAL_OF_SUMMONING, - ESCAPE_TUNNEL, - FREELANCERS_GUILD, - BALLISTA_YARD, - ATTACK_VISITING_BONUS, - MAGIC_UNIVERSITY, - SPELL_POWER_GARRISON_BONUS, - ATTACK_GARRISON_BONUS, - DEFENSE_GARRISON_BONUS, - DEFENSE_VISITING_BONUS, - SPELL_POWER_VISITING_BONUS, - KNOWLEDGE_VISITING_BONUS, - EXPERIENCE_VISITING_BONUS, - LIGHTHOUSE, - TREASURY, - CUSTOM_VISITING_BONUS, - CUSTOM_VISITING_REWARD - }; -} - -enum class EMarketMode : int8_t -{ - RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT, - ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, RESOURCE_SKILL, - MARTKET_AFTER_LAST_PLACEHOLDER -}; - -namespace MappedKeys -{ - - static const std::map BUILDING_NAMES_TO_TYPES = - { - { "special1", BuildingID::SPECIAL_1 }, - { "special2", BuildingID::SPECIAL_2 }, - { "special3", BuildingID::SPECIAL_3 }, - { "special4", BuildingID::SPECIAL_4 }, - { "grail", BuildingID::GRAIL }, - { "mageGuild1", BuildingID::MAGES_GUILD_1 }, - { "mageGuild2", BuildingID::MAGES_GUILD_2 }, - { "mageGuild3", BuildingID::MAGES_GUILD_3 }, - { "mageGuild4", BuildingID::MAGES_GUILD_4 }, - { "mageGuild5", BuildingID::MAGES_GUILD_5 }, - { "tavern", BuildingID::TAVERN }, - { "shipyard", BuildingID::SHIPYARD }, - { "fort", BuildingID::FORT }, - { "citadel", BuildingID::CITADEL }, - { "castle", BuildingID::CASTLE }, - { "villageHall", BuildingID::VILLAGE_HALL }, - { "townHall", BuildingID::TOWN_HALL }, - { "cityHall", BuildingID::CITY_HALL }, - { "capitol", BuildingID::CAPITOL }, - { "marketplace", BuildingID::MARKETPLACE }, - { "resourceSilo", BuildingID::RESOURCE_SILO }, - { "blacksmith", BuildingID::BLACKSMITH }, - { "horde1", BuildingID::HORDE_1 }, - { "horde1Upgr", BuildingID::HORDE_1_UPGR }, - { "horde2", BuildingID::HORDE_2 }, - { "horde2Upgr", BuildingID::HORDE_2_UPGR }, - { "ship", BuildingID::SHIP }, - { "dwellingLvl1", BuildingID::DWELL_LVL_1 }, - { "dwellingLvl2", BuildingID::DWELL_LVL_2 }, - { "dwellingLvl3", BuildingID::DWELL_LVL_3 }, - { "dwellingLvl4", BuildingID::DWELL_LVL_4 }, - { "dwellingLvl5", BuildingID::DWELL_LVL_5 }, - { "dwellingLvl6", BuildingID::DWELL_LVL_6 }, - { "dwellingLvl7", BuildingID::DWELL_LVL_7 }, - { "dwellingUpLvl1", BuildingID::DWELL_LVL_1_UP }, - { "dwellingUpLvl2", BuildingID::DWELL_LVL_2_UP }, - { "dwellingUpLvl3", BuildingID::DWELL_LVL_3_UP }, - { "dwellingUpLvl4", BuildingID::DWELL_LVL_4_UP }, - { "dwellingUpLvl5", BuildingID::DWELL_LVL_5_UP }, - { "dwellingUpLvl6", BuildingID::DWELL_LVL_6_UP }, - { "dwellingUpLvl7", BuildingID::DWELL_LVL_7_UP }, - }; - - static const std::map SPECIAL_BUILDINGS = - { - { "mysticPond", BuildingSubID::MYSTIC_POND }, - { "artifactMerchant", BuildingSubID::ARTIFACT_MERCHANT }, - { "freelancersGuild", BuildingSubID::FREELANCERS_GUILD }, - { "magicUniversity", BuildingSubID::MAGIC_UNIVERSITY }, - { "castleGate", BuildingSubID::CASTLE_GATE }, - { "creatureTransformer", BuildingSubID::CREATURE_TRANSFORMER },//only skeleton transformer yet - { "portalOfSummoning", BuildingSubID::PORTAL_OF_SUMMONING }, - { "ballistaYard", BuildingSubID::BALLISTA_YARD }, - { "stables", BuildingSubID::STABLES }, - { "manaVortex", BuildingSubID::MANA_VORTEX }, - { "lookoutTower", BuildingSubID::LOOKOUT_TOWER }, - { "library", BuildingSubID::LIBRARY }, - { "brotherhoodOfSword", BuildingSubID::BROTHERHOOD_OF_SWORD },//morale garrison bonus - { "fountainOfFortune", BuildingSubID::FOUNTAIN_OF_FORTUNE },//luck garrison bonus - { "spellPowerGarrisonBonus", BuildingSubID::SPELL_POWER_GARRISON_BONUS },//such as 'stormclouds', but this name is not ok for good towns - { "attackGarrisonBonus", BuildingSubID::ATTACK_GARRISON_BONUS }, - { "defenseGarrisonBonus", BuildingSubID::DEFENSE_GARRISON_BONUS }, - { "escapeTunnel", BuildingSubID::ESCAPE_TUNNEL }, - { "attackVisitingBonus", BuildingSubID::ATTACK_VISITING_BONUS }, - { "defenceVisitingBonus", BuildingSubID::DEFENSE_VISITING_BONUS }, - { "spellPowerVisitingBonus", BuildingSubID::SPELL_POWER_VISITING_BONUS }, - { "knowledgeVisitingBonus", BuildingSubID::KNOWLEDGE_VISITING_BONUS }, - { "experienceVisitingBonus", BuildingSubID::EXPERIENCE_VISITING_BONUS }, - { "lighthouse", BuildingSubID::LIGHTHOUSE }, - { "treasury", BuildingSubID::TREASURY } - }; - - static const std::map MARKET_NAMES_TO_TYPES = - { - { "resource-resource", EMarketMode::RESOURCE_RESOURCE }, - { "resource-player", EMarketMode::RESOURCE_PLAYER }, - { "creature-resource", EMarketMode::CREATURE_RESOURCE }, - { "resource-artifact", EMarketMode::RESOURCE_ARTIFACT }, - { "artifact-resource", EMarketMode::ARTIFACT_RESOURCE }, - { "artifact-experience", EMarketMode::ARTIFACT_EXP }, - { "creature-experience", EMarketMode::CREATURE_EXP }, - { "creature-undead", EMarketMode::CREATURE_UNDEAD }, - { "resource-skill", EMarketMode::RESOURCE_SKILL }, - }; -} - -enum class EAiTactic : int8_t -{ - NONE = -1, - RANDOM, - WARRIOR, - BUILDER, - EXPLORER -}; - -enum class EBuildingState : int8_t -{ - HAVE_CAPITAL, NO_WATER, FORBIDDEN, ADD_MAGES_GUILD, ALREADY_PRESENT, CANT_BUILD_TODAY, - NO_RESOURCES, ALLOWED, PREREQUIRES, MISSING_BASE, BUILDING_ERROR, TOWN_NOT_OWNED -}; - -enum class ESpellCastProblem : int8_t -{ - OK, NO_HERO_TO_CAST_SPELL, CASTS_PER_TURN_LIMIT, NO_SPELLBOOK, - HERO_DOESNT_KNOW_SPELL, NOT_ENOUGH_MANA, ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL, - SPELL_LEVEL_LIMIT_EXCEEDED, NO_SPELLS_TO_DISPEL, - NO_APPROPRIATE_TARGET, STACK_IMMUNE_TO_SPELL, WRONG_SPELL_TARGET, ONGOING_TACTIC_PHASE, - MAGIC_IS_BLOCKED, //For Orb of Inhibition and similar - no casting at all - INVALID -}; - -namespace ECommander -{ - enum SecondarySkills {ATTACK, DEFENSE, HEALTH, DAMAGE, SPEED, SPELL_POWER, CASTS, RESISTANCE}; - const int MAX_SKILL_LEVEL = 5; -} - -enum class EWallPart : int8_t -{ - INDESTRUCTIBLE_PART_OF_GATE = -3, INDESTRUCTIBLE_PART = -2, INVALID = -1, - KEEP = 0, BOTTOM_TOWER, BOTTOM_WALL, BELOW_GATE, OVER_GATE, UPPER_WALL, UPPER_TOWER, GATE, - PARTS_COUNT /* This constant SHOULD always stay as the last item in the enum. */ -}; - -enum class EWallState : int8_t -{ - NONE = -1, //no wall - DESTROYED, - DAMAGED, - INTACT, - REINFORCED, // walls in towns with castle -}; - -enum class EGateState : int8_t -{ - NONE, - CLOSED, - BLOCKED, // gate is blocked in closed state, e.g. by creature - OPENED, - DESTROYED -}; - - -enum class ETileType : int8_t -{ - FREE, - POSSIBLE, - BLOCKED, - USED -}; - -enum class ETeleportChannelType : int8_t -{ - IMPASSABLE, - BIDIRECTIONAL, - UNIDIRECTIONAL, - MIXED -}; - -class ObjBase : public EntityBase -{ -public: - enum Type - { - NO_OBJ = -1, - ALTAR_OF_SACRIFICE [[deprecated]] = 2, - ANCHOR_POINT = 3, - ARENA = 4, - ARTIFACT = 5, - PANDORAS_BOX = 6, - BLACK_MARKET [[deprecated]] = 7, - BOAT = 8, - BORDERGUARD = 9, - KEYMASTER = 10, - BUOY = 11, - CAMPFIRE = 12, - CARTOGRAPHER = 13, - SWAN_POND = 14, - COVER_OF_DARKNESS = 15, - CREATURE_BANK = 16, - CREATURE_GENERATOR1 = 17, - CREATURE_GENERATOR2 = 18, - CREATURE_GENERATOR3 = 19, - CREATURE_GENERATOR4 = 20, - CURSED_GROUND1 = 21, - CORPSE = 22, - MARLETTO_TOWER = 23, - DERELICT_SHIP = 24, - DRAGON_UTOPIA = 25, - EVENT = 26, - EYE_OF_MAGI = 27, - FAERIE_RING = 28, - FLOTSAM = 29, - FOUNTAIN_OF_FORTUNE = 30, - FOUNTAIN_OF_YOUTH = 31, - GARDEN_OF_REVELATION = 32, - GARRISON = 33, - HERO = 34, - HILL_FORT = 35, - GRAIL = 36, - HUT_OF_MAGI = 37, - IDOL_OF_FORTUNE = 38, - LEAN_TO = 39, - LIBRARY_OF_ENLIGHTENMENT = 41, - LIGHTHOUSE = 42, - MONOLITH_ONE_WAY_ENTRANCE = 43, - MONOLITH_ONE_WAY_EXIT = 44, - MONOLITH_TWO_WAY = 45, - MAGIC_PLAINS1 = 46, - SCHOOL_OF_MAGIC = 47, - MAGIC_SPRING = 48, - MAGIC_WELL = 49, - MARKET_OF_TIME = 50, - MERCENARY_CAMP = 51, - MERMAID = 52, - MINE = 53, - MONSTER = 54, - MYSTICAL_GARDEN = 55, - OASIS = 56, - OBELISK = 57, - REDWOOD_OBSERVATORY = 58, - OCEAN_BOTTLE = 59, - PILLAR_OF_FIRE = 60, - STAR_AXIS = 61, - PRISON = 62, - PYRAMID = 63,//subtype 0 - WOG_OBJECT = 63,//subtype > 0 - RALLY_FLAG = 64, - RANDOM_ART = 65, - RANDOM_TREASURE_ART = 66, - RANDOM_MINOR_ART = 67, - RANDOM_MAJOR_ART = 68, - RANDOM_RELIC_ART = 69, - RANDOM_HERO = 70, - RANDOM_MONSTER = 71, - RANDOM_MONSTER_L1 = 72, - RANDOM_MONSTER_L2 = 73, - RANDOM_MONSTER_L3 = 74, - RANDOM_MONSTER_L4 = 75, - RANDOM_RESOURCE = 76, - RANDOM_TOWN = 77, - REFUGEE_CAMP = 78, - RESOURCE = 79, - SANCTUARY = 80, - SCHOLAR = 81, - SEA_CHEST = 82, - SEER_HUT = 83, - CRYPT = 84, - SHIPWRECK = 85, - SHIPWRECK_SURVIVOR = 86, - SHIPYARD = 87, - SHRINE_OF_MAGIC_INCANTATION = 88, - SHRINE_OF_MAGIC_GESTURE = 89, - SHRINE_OF_MAGIC_THOUGHT = 90, - SIGN = 91, - SIRENS = 92, - SPELL_SCROLL = 93, - STABLES = 94, - TAVERN = 95, - TEMPLE = 96, - DEN_OF_THIEVES = 97, - TOWN = 98, - TRADING_POST [[deprecated]] = 99, - LEARNING_STONE = 100, - TREASURE_CHEST = 101, - TREE_OF_KNOWLEDGE = 102, - SUBTERRANEAN_GATE = 103, - UNIVERSITY [[deprecated]] = 104, - WAGON = 105, - WAR_MACHINE_FACTORY = 106, - SCHOOL_OF_WAR = 107, - WARRIORS_TOMB = 108, - WATER_WHEEL = 109, - WATERING_HOLE = 110, - WHIRLPOOL = 111, - WINDMILL = 112, - WITCH_HUT = 113, - HOLE = 124, - RANDOM_MONSTER_L5 = 162, - RANDOM_MONSTER_L6 = 163, - RANDOM_MONSTER_L7 = 164, - BORDER_GATE = 212, - FREELANCERS_GUILD [[deprecated]] = 213, - HERO_PLACEHOLDER = 214, - QUEST_GUARD = 215, - RANDOM_DWELLING = 216, - RANDOM_DWELLING_LVL = 217, //subtype = creature level - RANDOM_DWELLING_FACTION = 218, //subtype = faction - GARRISON2 = 219, - ABANDONED_MINE = 220, - TRADING_POST_SNOW [[deprecated]] = 221, - CLOVER_FIELD = 222, - CURSED_GROUND2 = 223, - EVIL_FOG = 224, - FAVORABLE_WINDS = 225, - FIERY_FIELDS = 226, - HOLY_GROUNDS = 227, - LUCID_POOLS = 228, - MAGIC_CLOUDS = 229, - MAGIC_PLAINS2 = 230, - ROCKLANDS = 231, - }; -}; - -class Obj : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class RoadIdBase : public EntityBase -{ -public: - enum Type : int32_t - { - NO_ROAD = 0, - FIRST_REGULAR_ROAD = 1, - DIRT_ROAD = 1, - GRAVEL_ROAD = 2, - COBBLESTONE_ROAD = 3, - ORIGINAL_ROAD_COUNT //+1 - }; -}; - -class RoadId : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class RiverIdBase : public EntityBase -{ -public: - enum Type : int32_t - { - NO_RIVER = 0, - FIRST_REGULAR_RIVER = 1, - WATER_RIVER = 1, - ICY_RIVER = 2, - MUD_RIVER = 3, - LAVA_RIVER = 4, - ORIGINAL_RIVER_COUNT //+1 - }; -}; - -class RiverId : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -using River = RiverId; -using Road = RoadId; - -namespace SecSkillLevel -{ - enum SecSkillLevel - { - NONE, - BASIC, - ADVANCED, - EXPERT, - LEVELS_SIZE - }; -} - -enum class Date : int8_t -{ - DAY = 0, - DAY_OF_WEEK = 1, - WEEK = 2, - MONTH = 3, - DAY_OF_MONTH -}; - -enum class EActionType : int8_t -{ - NO_ACTION, - - END_TACTIC_PHASE, - RETREAT, - SURRENDER, - - HERO_SPELL, - - WALK, - WAIT, - DEFEND, - WALK_AND_ATTACK, - SHOOT, - CATAPULT, - MONSTER_SPELL, - BAD_MORALE, - STACK_HEAL, -}; - -DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EActionType actionType); - -enum class EDiggingStatus : int8_t -{ - UNKNOWN = -1, - CAN_DIG = 0, - LACK_OF_MOVEMENT, - WRONG_TERRAIN, - TILE_OCCUPIED, - BACKPACK_IS_FULL -}; - -class DLL_LINKAGE EPathfindingLayer -{ -public: - enum EEPathfindingLayer : ui8 - { - LAND = 0, SAIL = 1, WATER, AIR, NUM_LAYERS, WRONG, AUTO - }; - - EPathfindingLayer(EEPathfindingLayer _num = WRONG) : num(_num) - {} - - ID_LIKE_CLASS_COMMON(EPathfindingLayer, EEPathfindingLayer) - - EEPathfindingLayer num; -}; - -DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EPathfindingLayer & pathfindingLayer); - -ID_LIKE_OPERATORS(EPathfindingLayer, EPathfindingLayer::EEPathfindingLayer) - -enum class EPlayerStatus -{ - WRONG = -1, - INGAME, - LOSER, - WINNER -}; - -enum class PlayerRelations -{ - ENEMIES, - ALLIES, - SAME_PLAYER -}; - -class ArtifactPosition -{ -public: - enum EArtifactPosition - { - TRANSITION_POS = -3, - FIRST_AVAILABLE = -2, - PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack - HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5 - RIGHT_RING, LEFT_RING, FEET, //8 - MISC1, MISC2, MISC3, MISC4, //12 - MACH1, MACH2, MACH3, MACH4, //16 - SPELLBOOK, MISC5, //18 - AFTER_LAST, - //cres - CREATURE_SLOT = 0, - COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6, COMMANDER_AFTER_LAST - }; - - static_assert (AFTER_LAST == 19, "incorrect number of artifact slots"); - - ArtifactPosition(EArtifactPosition _num = PRE_FIRST) : num(_num) - {} - - ArtifactPosition(std::string slotName); - - ID_LIKE_CLASS_COMMON(ArtifactPosition, EArtifactPosition) - - EArtifactPosition num; - - STRONG_INLINE EArtifactPosition operator+(const int arg) - { - return EArtifactPosition(static_cast(num) + arg); - } - STRONG_INLINE EArtifactPosition operator+(const EArtifactPosition & arg) - { - return EArtifactPosition(static_cast(num) + static_cast(arg)); - } -}; - -ID_LIKE_OPERATORS(ArtifactPosition, ArtifactPosition::EArtifactPosition) - -namespace GameConstants -{ - const auto BACKPACK_START = ArtifactPosition::AFTER_LAST; -} - -class ArtifactIDBase : public EntityBase -{ -public: - enum Type - { - NONE = -1, - SPELLBOOK = 0, - SPELL_SCROLL = 1, - GRAIL = 2, - CATAPULT = 3, - BALLISTA = 4, - AMMO_CART = 5, - FIRST_AID_TENT = 6, - VIAL_OF_DRAGON_BLOOD = 127, - ARMAGEDDONS_BLADE = 128, - TITANS_THUNDER = 135, - ART_SELECTION = 144, - ART_LOCK = 145, // FIXME: We must get rid of this one since it's conflict with artifact from mods. See issue 2455 - }; - - DLL_LINKAGE const CArtifact * toArtifact() const; - DLL_LINKAGE const Artifact * toArtifact(const ArtifactService * service) const; - - ///json serialization helpers - static si32 decode(const std::string & identifier); - static std::string encode(const si32 index); -}; - -class ArtifactID : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class CreatureIDBase : public EntityBase -{ -public: - enum Type - { - NONE = -1, - ARCHER = 2, // for debug / fallback - IMP = 42, // for Deity of Fire - SKELETON = 56, // for Skeleton Transformer - BONE_DRAGON = 68, // for Skeleton Transformer - TROGLODYTES = 70, // for Abandoned Mine - MEDUSA = 76, // for Siege UI workaround - HYDRA = 110, // for Skeleton Transformer - CHAOS_HYDRA = 111, // for Skeleton Transformer - AIR_ELEMENTAL = 112, // for tests - FIRE_ELEMENTAL = 114, // for tests - PSYCHIC_ELEMENTAL = 120, // for hardcoded ability - MAGIC_ELEMENTAL = 121, // for hardcoded ability - CATAPULT = 145, - BALLISTA = 146, - FIRST_AID_TENT = 147, - AMMO_CART = 148, - ARROW_TOWERS = 149 - }; - - DLL_LINKAGE const CCreature * toCreature() const; - DLL_LINKAGE const Creature * toCreature(const CreatureService * creatures) const; - - ///json serialization helpers - static si32 decode(const std::string & identifier); - static std::string encode(const si32 index); -}; - -class CreatureID : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class SpellIDBase : public EntityBase -{ -public: - enum Type - { - SPELLBOOK_PRESET = -3, - PRESET = -2, - NONE = -1, - SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5, - FLY=6, WATER_WALK=7, DIMENSION_DOOR=8, TOWN_PORTAL=9, - - QUICKSAND=10, LAND_MINE=11, FORCE_FIELD=12, FIRE_WALL=13, EARTHQUAKE=14, - MAGIC_ARROW=15, ICE_BOLT=16, LIGHTNING_BOLT=17, IMPLOSION=18, - CHAIN_LIGHTNING=19, FROST_RING=20, FIREBALL=21, INFERNO=22, - METEOR_SHOWER=23, DEATH_RIPPLE=24, DESTROY_UNDEAD=25, ARMAGEDDON=26, - SHIELD=27, AIR_SHIELD=28, FIRE_SHIELD=29, PROTECTION_FROM_AIR=30, - PROTECTION_FROM_FIRE=31, PROTECTION_FROM_WATER=32, - PROTECTION_FROM_EARTH=33, ANTI_MAGIC=34, DISPEL=35, MAGIC_MIRROR=36, - CURE=37, RESURRECTION=38, ANIMATE_DEAD=39, SACRIFICE=40, BLESS=41, - CURSE=42, BLOODLUST=43, PRECISION=44, WEAKNESS=45, STONE_SKIN=46, - DISRUPTING_RAY=47, PRAYER=48, MIRTH=49, SORROW=50, FORTUNE=51, - MISFORTUNE=52, HASTE=53, SLOW=54, SLAYER=55, FRENZY=56, - TITANS_LIGHTNING_BOLT=57, COUNTERSTRIKE=58, BERSERK=59, HYPNOTIZE=60, - FORGETFULNESS=61, BLIND=62, TELEPORT=63, REMOVE_OBSTACLE=64, CLONE=65, - SUMMON_FIRE_ELEMENTAL=66, SUMMON_EARTH_ELEMENTAL=67, SUMMON_WATER_ELEMENTAL=68, SUMMON_AIR_ELEMENTAL=69, - - STONE_GAZE=70, POISON=71, BIND=72, DISEASE=73, PARALYZE=74, AGE=75, DEATH_CLOUD=76, THUNDERBOLT=77, - DISPEL_HELPFUL_SPELLS=78, DEATH_STARE=79, ACID_BREATH_DEFENSE=80, ACID_BREATH_DAMAGE=81, - - FIRST_NON_SPELL = 70, AFTER_LAST = 82 - }; - - DLL_LINKAGE const CSpell * toSpell() const; //deprecated - DLL_LINKAGE const spells::Spell * toSpell(const spells::Service * service) const; - - ///json serialization helpers - static si32 decode(const std::string & identifier); - static std::string encode(const si32 index); -}; - -class SpellID : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class BattleFieldInfo; -class BattleField : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(BattleField, si32) - - DLL_LINKAGE static const BattleField NONE; - - DLL_LINKAGE friend bool operator==(const BattleField & l, const BattleField & r); - DLL_LINKAGE friend bool operator!=(const BattleField & l, const BattleField & r); - DLL_LINKAGE friend bool operator<(const BattleField & l, const BattleField & r); - - DLL_LINKAGE const BattleFieldInfo * getInfo() const; -}; - -class BoatIdBase : public EntityBase -{ -public: - enum Type : int32_t - { - NONE = -1, - NECROPOLIS = 0, - CASTLE, - FORTRESS - }; -}; - -class BoatId : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -class TerrainIdBase : public EntityBase -{ -public: - enum Type : int32_t - { - NATIVE_TERRAIN = -4, - ANY_TERRAIN = -3, - NONE = -1, - FIRST_REGULAR_TERRAIN = 0, - DIRT = 0, - SAND, - GRASS, - SNOW, - SWAMP, - ROUGH, - SUBTERRANEAN, - LAVA, - WATER, - ROCK, - ORIGINAL_REGULAR_TERRAIN_COUNT = ROCK - }; - - static si32 decode(const std::string & identifier); - static std::string encode(const si32 index); - static std::string entityType(); -}; - -class TerrainId : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -using ETerrainId = TerrainId; - -class ObstacleInfo; -class Obstacle : public BaseForID -{ - INSTID_LIKE_CLASS_COMMON(Obstacle, si32) - - DLL_LINKAGE const ObstacleInfo * getInfo() const; -}; - -class SpellSchoolBase : public EntityBase -{ -public: - enum Type : int32_t - { - ANY = -1, - AIR = 0, - FIRE = 1, - WATER = 2, - EARTH = 3, - }; -}; - -class SpellSchool : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -using ESpellSchool = SpellSchool; - -enum class EMetaclass: int8_t -{ - INVALID = 0, - ARTIFACT, - CREATURE, - FACTION, - EXPERIENCE, - HERO, - HEROCLASS, - LUCK, - MANA, - MORALE, - MOVEMENT, - OBJECT, - PRIMARY_SKILL, - SECONDARY_SKILL, - SPELL, - RESOURCE -}; - -enum class EHealLevel: ui8 -{ - HEAL, - RESURRECT, - OVERHEAL -}; - -enum class EHealPower : ui8 -{ - ONE_BATTLE, - PERMANENT -}; - -enum class EBattleResult : int8_t -{ - NORMAL = 0, - ESCAPE = 1, - SURRENDER = 2 -}; - -class GameResIDBase : public EntityBase -{ -public: - enum Type : int32_t - { - WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL, - COUNT, - - WOOD_AND_ORE = 127, // special case for town bonus resource - INVALID = -1 - }; -}; - -class GameResID : public EntityIdentifier -{ -public: - using EntityIdentifier::EntityIdentifier; -}; - -using EGameResID = GameResID; - -// Typedef declarations using TExpType = si64; using TQuantity = si32; - using TRmgTemplateZoneId = int; -#undef ID_LIKE_CLASS_COMMON -#undef ID_LIKE_OPERATORS -#undef ID_LIKE_OPERATORS_INTERNAL -#undef INSTID_LIKE_CLASS_COMMON - VCMI_LIB_NAMESPACE_END diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index f6d4a80df..842b3fdf2 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -23,7 +23,7 @@ #include "VCMI_Lib.h" //for identifier resolution #include "CGeneralTextHandler.h" #include "JsonDetail.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "battle/BattleHex.h" namespace diff --git a/lib/JsonRandom.cpp b/lib/JsonRandom.cpp index e5f14a03d..270c47b80 100644 --- a/lib/JsonRandom.cpp +++ b/lib/JsonRandom.cpp @@ -15,7 +15,7 @@ #include "JsonNode.h" #include "CRandomGenerator.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "VCMI_Lib.h" #include "CArtHandler.h" #include "CCreatureHandler.h" @@ -195,10 +195,10 @@ namespace JsonRandom allowedClasses.insert(CArtHandler::stringToClass(entry.String())); if (value["slot"].getType() == JsonNode::JsonType::DATA_STRING) - allowedPositions.insert(ArtifactPosition(value["class"].String())); + allowedPositions.insert(ArtifactPosition::decode(value["class"].String())); else for(const auto & entry : value["slot"].Vector()) - allowedPositions.insert(ArtifactPosition(entry.String())); + allowedPositions.insert(ArtifactPosition::decode(entry.String())); if (!value["minValue"].isNull()) minValue = static_cast(value["minValue"].Float()); if (!value["maxValue"].isNull()) maxValue = static_cast(value["maxValue"].Float()); diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 7a1a90463..33706619d 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1382,7 +1382,7 @@ void HeroRecruited::applyGs(CGameState * gs) const CGTownInstance *t = gs->getTown(tid); PlayerState *p = gs->getPlayerState(player); - if (boatId >= 0) + if (boatId != ObjectInstanceID::NONE) { CGObjectInstance *obj = gs->getObjInstance(boatId); auto * boat = dynamic_cast(obj); @@ -1418,7 +1418,7 @@ void GiveHero::applyGs(CGameState * gs) const { CGHeroInstance *h = gs->getHero(id); - if (boatId >= 0) + if (boatId != ObjectInstanceID::NONE) { CGObjectInstance *obj = gs->getObjInstance(boatId); auto * boat = dynamic_cast(obj); @@ -1880,7 +1880,7 @@ void BulkMoveArtifacts::applyGs(CGameState * gs) break; } - if(srcPos >= GameConstants::BACKPACK_START) + if(srcPos >= ArtifactPosition::BACKPACK_START) { numBackpackArtifactsMoved++; } @@ -1925,7 +1925,7 @@ void AssembledArtifact::applyGs(CGameState *gs) { ArtifactPosition pos = combineEquipped ? artSet->getArtPos(constituent->getId(), true, false) : artSet->getArtBackpackPos(constituent->getId()); - assert(pos >= 0); + assert(pos != ArtifactPosition::PRE_FIRST); CArtifactInstance * constituentInstance = artSet->getArt(pos); //move constituent from hero to be part of new, combined artifact diff --git a/lib/ResourceSet.cpp b/lib/ResourceSet.cpp index 56fc50442..e89855dcf 100644 --- a/lib/ResourceSet.cpp +++ b/lib/ResourceSet.cpp @@ -11,7 +11,7 @@ #include "StdInc.h" #include "GameConstants.h" #include "ResourceSet.h" -#include "StringConstants.h" +#include "constants/StringConstants.h" #include "JsonNode.h" #include "serializer/JsonSerializeFormat.h" #include "mapObjects/CObjectHandler.h" diff --git a/lib/StringConstants.h b/lib/StringConstants.h deleted file mode 100644 index e6190f756..000000000 --- a/lib/StringConstants.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * StringConstants.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ -#pragma once - -#include "GameConstants.h" - -VCMI_LIB_NAMESPACE_BEGIN - -/// -/// String ID which are pointless to move to config file - these types are mostly hardcoded -/// -namespace GameConstants -{ - const std::string RESOURCE_NAMES [RESOURCE_QUANTITY] = { - "wood", "mercury", "ore", "sulfur", "crystal", "gems", "gold", "mithril" - }; - - const std::string PLAYER_COLOR_NAMES [PlayerColor::PLAYER_LIMIT_I] = { - "red", "blue", "tan", "green", "orange", "purple", "teal", "pink" - }; - - const std::string ALIGNMENT_NAMES [3] = {"good", "evil", "neutral"}; -} - -namespace NPrimarySkill -{ - const std::string names [GameConstants::PRIMARY_SKILLS] = { "attack", "defence", "spellpower", "knowledge" }; -} - -namespace NSecondarySkill -{ - const std::string names [GameConstants::SKILL_QUANTITY] = - { - "pathfinding", "archery", "logistics", "scouting", "diplomacy", // 5 - "navigation", "leadership", "wisdom", "mysticism", "luck", // 10 - "ballistics", "eagleEye", "necromancy", "estates", "fireMagic", // 15 - "airMagic", "waterMagic", "earthMagic", "scholar", "tactics", // 20 - "artillery", "learning", "offence", "armorer", "intelligence", // 25 - "sorcery", "resistance", "firstAid" - }; - - const std::vector levels = - { - "none", "basic", "advanced", "expert" - }; -} - -namespace EBuildingType -{ - const std::string names [44] = - { - "mageGuild1", "mageGuild2", "mageGuild3", "mageGuild4", "mageGuild5", // 5 - "tavern", "shipyard", "fort", "citadel", "castle", // 10 - "villageHall", "townHall", "cityHall", "capitol", "marketplace", // 15 - "resourceSilo", "blacksmith", "special1", "horde1", "horde1Upgr", // 20 - "ship", "special2", "special3", "special4", "horde2", // 25 - "horde2Upgr", "grail", "extraTownHall", "extraCityHall", "extraCapitol", // 30 - "dwellingLvl1", "dwellingLvl2", "dwellingLvl3", "dwellingLvl4", "dwellingLvl5", // 35 - "dwellingLvl6", "dwellingLvl7", "dwellingUpLvl1", "dwellingUpLvl2", "dwellingUpLvl3", // 40 - "dwellingUpLvl4", "dwellingUpLvl5", "dwellingUpLvl6", "dwellingUpLvl7" - }; -} - -namespace NFaction -{ - const std::string names [GameConstants::F_NUMBER] = - { - "castle", "rampart", "tower", - "inferno", "necropolis", "dungeon", - "stronghold", "fortress", "conflux" - }; -} - -namespace NArtifactPosition -{ - const std::string namesHero [19] = - { - "head", "shoulders", "neck", "rightHand", "leftHand", "torso", //5 - "rightRing", "leftRing", "feet", //8 - "misc1", "misc2", "misc3", "misc4", //12 - "mach1", "mach2", "mach3", "mach4", //16 - "spellbook", "misc5" //18 - }; - - const std::string namesCreature[1] = - { - "creature1" - }; - - const std::string namesCommander[6] = - { - "commander1", "commander2", "commander3", "commander4", "commander5", "commander6", - }; - - - const std::string backpack = "backpack"; -} - -namespace NMetaclass -{ - const std::string names [16] = - { - "", - "artifact", "creature", "faction", "experience", "hero", - "heroClass", "luck", "mana", "morale", "movement", - "object", "primarySkill", "secondarySkill", "spell", "resource" - }; -} - -namespace NPathfindingLayer -{ - const std::string names[EPathfindingLayer::NUM_LAYERS] = - { - "land", "sail", "water", "air" - }; -} - -VCMI_LIB_NAMESPACE_END diff --git a/lib/battle/BattleAction.cpp b/lib/battle/BattleAction.cpp index 488cdf3ac..0e82ca884 100644 --- a/lib/battle/BattleAction.cpp +++ b/lib/battle/BattleAction.cpp @@ -122,9 +122,6 @@ BattleAction BattleAction::makeRetreat(ui8 side) std::string BattleAction::toString() const { - std::stringstream actionTypeStream; - actionTypeStream << actionType; - std::stringstream targetStream; for(const DestinationInfo & info : target) @@ -143,7 +140,7 @@ std::string BattleAction::toString() const } boost::format fmt("{BattleAction: side '%d', stackNumber '%d', actionType '%s', actionSubtype '%d', target {%s}}"); - fmt % static_cast(side) % stackNumber % actionTypeStream.str() % spell.getNum() % targetStream.str(); + fmt % static_cast(side) % stackNumber % static_cast(actionType) % spell.getNum() % targetStream.str(); return fmt.str(); } diff --git a/lib/bonuses/Bonus.cpp b/lib/bonuses/Bonus.cpp index cd493b17b..ff81c18eb 100644 --- a/lib/bonuses/Bonus.cpp +++ b/lib/bonuses/Bonus.cpp @@ -25,7 +25,7 @@ #include "../CSkillHandler.h" #include "../CArtHandler.h" #include "../TerrainHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../battle/BattleInfo.h" #include "../modding/ModUtility.h" diff --git a/lib/bonuses/Limiters.cpp b/lib/bonuses/Limiters.cpp index 64186b908..7916edb42 100644 --- a/lib/bonuses/Limiters.cpp +++ b/lib/bonuses/Limiters.cpp @@ -22,7 +22,7 @@ #include "../CStack.h" #include "../CArtHandler.h" #include "../TerrainHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../battle/BattleInfo.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index e239dec12..63630b6e2 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -21,7 +21,7 @@ #include "../CGeneralTextHandler.h" #include "../TextOperations.h" #include "../Languages.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../mapping/CMapHeader.h" #include "../mapping/CMapService.h" #include "../modding/CModHandler.h" diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h new file mode 100644 index 000000000..759934307 --- /dev/null +++ b/lib/constants/EntityIdentifiers.h @@ -0,0 +1,896 @@ +/* + * GameConstants.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "NumericConstants.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class Artifact; +class ArtifactService; +class Creature; +class CreatureService; + +namespace spells +{ + class Spell; + class Service; +} + +class CArtifact; +class CArtifactInstance; +class CCreature; +class CHero; +class CSpell; +class CSkill; +class CGameInfoCallback; +class CNonConstInfoCallback; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class IdentifierBase +{ +protected: + constexpr IdentifierBase(int32_t value = -1 ): + num(value) + {} +public: + int32_t num; + + constexpr int32_t getNum() const + { + return num; + } + + struct hash + { + size_t operator()(const IdentifierBase & id) const + { + return std::hash()(id.num); + } + }; + + friend std::ostream& operator<<(std::ostream& os, const IdentifierBase& dt) + { + return os << dt.num; + } +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// Note: use template to force different type, blocking any Identifier <=> Identifier comparisons +template +class Identifier : public IdentifierBase +{ + using T = IdentifierBase; +public: + constexpr Identifier(int32_t _num = -1) + :IdentifierBase(_num) + {} + + template void serialize(Handler &h, const int version) + { + h & T::num; + } + + constexpr bool operator == (const Identifier & b) const { return T::num == b.num; } + constexpr bool operator <= (const Identifier & b) const { return T::num <= b.num; } + constexpr bool operator >= (const Identifier & b) const { return T::num >= b.num; } + constexpr bool operator != (const Identifier & b) const { return T::num != b.num; } + constexpr bool operator < (const Identifier & b) const { return T::num < b.num; } + constexpr bool operator > (const Identifier & b) const { return T::num > b.num; } + + constexpr FinalClass & operator++() + { + ++T::num; + return static_cast(*this); + } + + constexpr FinalClass operator++(int) + { + FinalClass ret(num); + ++T::num; + return ret; + } + + constexpr operator int32_t () const + { + return T::num; + } + + constexpr void advance(int change) + { + T::num += change; + } +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template +class IdentifierWithEnum : public T +{ + using EnumType = typename T::Type; + + static_assert(std::is_same_v, int32_t>, "Entity Identifier must use int32_t"); +public: + constexpr int32_t getNum() const + { + return T::num; + } + + constexpr EnumType toEnum() const + { + return static_cast(T::num); + } + + template void serialize(Handler &h, const int version) + { + h & T::num; + } + + constexpr IdentifierWithEnum(const EnumType & enumValue) + { + T::num = static_cast(enumValue); + } + + constexpr IdentifierWithEnum(int32_t _num = -1) + { + T::num = _num; + } + + constexpr void advance(int change) + { + T::num += change; + } + + constexpr bool operator == (const EnumType & b) const { return T::num == static_cast(b); } + constexpr bool operator <= (const EnumType & b) const { return T::num <= static_cast(b); } + constexpr bool operator >= (const EnumType & b) const { return T::num >= static_cast(b); } + constexpr bool operator != (const EnumType & b) const { return T::num != static_cast(b); } + constexpr bool operator < (const EnumType & b) const { return T::num < static_cast(b); } + constexpr bool operator > (const EnumType & b) const { return T::num > static_cast(b); } + + constexpr bool operator == (const IdentifierWithEnum & b) const { return T::num == b.num; } + constexpr bool operator <= (const IdentifierWithEnum & b) const { return T::num <= b.num; } + constexpr bool operator >= (const IdentifierWithEnum & b) const { return T::num >= b.num; } + constexpr bool operator != (const IdentifierWithEnum & b) const { return T::num != b.num; } + constexpr bool operator < (const IdentifierWithEnum & b) const { return T::num < b.num; } + constexpr bool operator > (const IdentifierWithEnum & b) const { return T::num > b.num; } + + constexpr IdentifierWithEnum & operator++() + { + ++T::num; + return *this; + } + + constexpr IdentifierWithEnum operator++(int) + { + IdentifierWithEnum ret(*this); + ++T::num; + return ret; + } + + constexpr operator int32_t () const + { + return T::num; + } +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class ArtifactInstanceID : public Identifier +{ +public: + using Identifier::Identifier; +}; + +class QueryID : public Identifier +{ +public: + using Identifier::Identifier; + DLL_LINKAGE static const QueryID NONE; +}; + +class ObjectInstanceID : public Identifier +{ +public: + using Identifier::Identifier; + DLL_LINKAGE static const ObjectInstanceID NONE; +}; + +class HeroClassID : public Identifier +{ +public: + using Identifier::Identifier; +}; + +class HeroTypeID : public Identifier +{ +public: + using Identifier::Identifier; + ///json serialization helpers + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); + + DLL_LINKAGE static const HeroTypeID NONE; +}; + +class SlotID : public Identifier +{ +public: + using Identifier::Identifier; + + DLL_LINKAGE static const SlotID COMMANDER_SLOT_PLACEHOLDER; + DLL_LINKAGE static const SlotID SUMMONED_SLOT_PLACEHOLDER; ///= 0 && getNum() < GameConstants::ARMY_SIZE; + } +}; + +class PlayerColor : public Identifier +{ +public: + using Identifier::Identifier; + + enum EPlayerColor + { + PLAYER_LIMIT_I = 8, + }; + + using Mask = uint8_t; + + DLL_LINKAGE static const PlayerColor SPECTATOR; //252 + DLL_LINKAGE static const PlayerColor CANNOT_DETERMINE; //253 + DLL_LINKAGE static const PlayerColor UNFLAGGABLE; //254 - neutral objects (pandora, banks) + DLL_LINKAGE static const PlayerColor NEUTRAL; //255 + DLL_LINKAGE static const PlayerColor PLAYER_LIMIT; //player limit per map + + DLL_LINKAGE bool isValidPlayer() const; //valid means < PLAYER_LIMIT (especially non-neutral) + DLL_LINKAGE bool isSpectator() const; + + DLL_LINKAGE std::string getStr(bool L10n = false) const; + DLL_LINKAGE std::string getStrCap(bool L10n = false) const; +}; + +class TeamID : public Identifier +{ +public: + using Identifier::Identifier; + + DLL_LINKAGE static const TeamID NO_TEAM; +}; + +class TeleportChannelID : public Identifier +{ +public: + using Identifier::Identifier; +}; + +class SecondarySkillBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + WRONG = -2, + DEFAULT = -1, + PATHFINDING = 0, ARCHERY, LOGISTICS, SCOUTING, DIPLOMACY, NAVIGATION, LEADERSHIP, WISDOM, MYSTICISM, + LUCK, BALLISTICS, EAGLE_EYE, NECROMANCY, ESTATES, FIRE_MAGIC, AIR_MAGIC, WATER_MAGIC, EARTH_MAGIC, + SCHOLAR, TACTICS, ARTILLERY, LEARNING, OFFENCE, ARMORER, INTELLIGENCE, SORCERY, RESISTANCE, + FIRST_AID, SKILL_SIZE + }; + static_assert(GameConstants::SKILL_QUANTITY == SKILL_SIZE, "Incorrect number of skills"); +}; + +class SecondarySkill : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class FactionIDBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + NONE = -2, + DEFAULT = -1, + RANDOM = -1, + ANY = -1, + CASTLE, + RAMPART, + TOWER, + INFERNO, + NECROPOLIS, + DUNGEON, + STRONGHOLD, + FORTRESS, + CONFLUX, + NEUTRAL + }; + + static si32 decode(const std::string& identifier); + static std::string encode(const si32 index); + static std::string entityType(); +}; + +class FactionID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +using ETownType = FactionID; + +class BuildingIDBase : public IdentifierBase +{ +public: + //Quite useful as long as most of building mechanics hardcoded + // NOTE: all building with completely configurable mechanics will be removed from list + enum Type + { + DEFAULT = -50, + HORDE_PLACEHOLDER7 = -36, + HORDE_PLACEHOLDER6 = -35, + HORDE_PLACEHOLDER5 = -34, + HORDE_PLACEHOLDER4 = -33, + HORDE_PLACEHOLDER3 = -32, + HORDE_PLACEHOLDER2 = -31, + HORDE_PLACEHOLDER1 = -30, + NONE = -1, + FIRST_REGULAR_ID = 0, + MAGES_GUILD_1 = 0, MAGES_GUILD_2, MAGES_GUILD_3, MAGES_GUILD_4, MAGES_GUILD_5, + TAVERN, SHIPYARD, FORT, CITADEL, CASTLE, + VILLAGE_HALL, TOWN_HALL, CITY_HALL, CAPITOL, MARKETPLACE, + RESOURCE_SILO, BLACKSMITH, SPECIAL_1, HORDE_1, HORDE_1_UPGR, + SHIP, SPECIAL_2, SPECIAL_3, SPECIAL_4, HORDE_2, + HORDE_2_UPGR, GRAIL, EXTRA_TOWN_HALL, EXTRA_CITY_HALL, EXTRA_CAPITOL, + DWELL_FIRST=30, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LAST=36, + DWELL_UP_FIRST=37, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, + DWELL_LVL_6_UP, DWELL_UP_LAST=43, + + DWELL_LVL_1 = DWELL_FIRST, + DWELL_LVL_7 = DWELL_LAST, + DWELL_LVL_1_UP = DWELL_UP_FIRST, + DWELL_LVL_7_UP = DWELL_UP_LAST, + + DWELL_UP2_FIRST = DWELL_LVL_7_UP + 1, + + //Special buildings for towns. + LIGHTHOUSE = SPECIAL_1, + STABLES = SPECIAL_2, //Castle + BROTHERHOOD = SPECIAL_3, + + MYSTIC_POND = SPECIAL_1, + FOUNTAIN_OF_FORTUNE = SPECIAL_2, //Rampart + TREASURY = SPECIAL_3, + + ARTIFACT_MERCHANT = SPECIAL_1, + LOOKOUT_TOWER = SPECIAL_2, //Tower + LIBRARY = SPECIAL_3, + WALL_OF_KNOWLEDGE = SPECIAL_4, + + STORMCLOUDS = SPECIAL_2, + CASTLE_GATE = SPECIAL_3, //Inferno + ORDER_OF_FIRE = SPECIAL_4, + + COVER_OF_DARKNESS = SPECIAL_1, + NECROMANCY_AMPLIFIER = SPECIAL_2, //Necropolis + SKELETON_TRANSFORMER = SPECIAL_3, + + //ARTIFACT_MERCHANT - same ID as in tower + MANA_VORTEX = SPECIAL_2, + PORTAL_OF_SUMMON = SPECIAL_3, //Dungeon + BATTLE_ACADEMY = SPECIAL_4, + + ESCAPE_TUNNEL = SPECIAL_1, + FREELANCERS_GUILD = SPECIAL_2, //Stronghold + BALLISTA_YARD = SPECIAL_3, + HALL_OF_VALHALLA = SPECIAL_4, + + CAGE_OF_WARLORDS = SPECIAL_1, + GLYPHS_OF_FEAR = SPECIAL_2, // Fortress + BLOOD_OBELISK = SPECIAL_3, + + //ARTIFACT_MERCHANT - same ID as in tower + MAGIC_UNIVERSITY = SPECIAL_2, // Conflux + }; + + bool IsSpecialOrGrail() const + { + return num == SPECIAL_1 || num == SPECIAL_2 || num == SPECIAL_3 || num == SPECIAL_4 || num == GRAIL; + } +}; + +class BuildingID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class ObjBase : public IdentifierBase +{ +public: + enum Type + { + NO_OBJ = -1, + ALTAR_OF_SACRIFICE [[deprecated]] = 2, + ANCHOR_POINT = 3, + ARENA = 4, + ARTIFACT = 5, + PANDORAS_BOX = 6, + BLACK_MARKET [[deprecated]] = 7, + BOAT = 8, + BORDERGUARD = 9, + KEYMASTER = 10, + BUOY = 11, + CAMPFIRE = 12, + CARTOGRAPHER = 13, + SWAN_POND = 14, + COVER_OF_DARKNESS = 15, + CREATURE_BANK = 16, + CREATURE_GENERATOR1 = 17, + CREATURE_GENERATOR2 = 18, + CREATURE_GENERATOR3 = 19, + CREATURE_GENERATOR4 = 20, + CURSED_GROUND1 = 21, + CORPSE = 22, + MARLETTO_TOWER = 23, + DERELICT_SHIP = 24, + DRAGON_UTOPIA = 25, + EVENT = 26, + EYE_OF_MAGI = 27, + FAERIE_RING = 28, + FLOTSAM = 29, + FOUNTAIN_OF_FORTUNE = 30, + FOUNTAIN_OF_YOUTH = 31, + GARDEN_OF_REVELATION = 32, + GARRISON = 33, + HERO = 34, + HILL_FORT = 35, + GRAIL = 36, + HUT_OF_MAGI = 37, + IDOL_OF_FORTUNE = 38, + LEAN_TO = 39, + LIBRARY_OF_ENLIGHTENMENT = 41, + LIGHTHOUSE = 42, + MONOLITH_ONE_WAY_ENTRANCE = 43, + MONOLITH_ONE_WAY_EXIT = 44, + MONOLITH_TWO_WAY = 45, + MAGIC_PLAINS1 = 46, + SCHOOL_OF_MAGIC = 47, + MAGIC_SPRING = 48, + MAGIC_WELL = 49, + MARKET_OF_TIME = 50, + MERCENARY_CAMP = 51, + MERMAID = 52, + MINE = 53, + MONSTER = 54, + MYSTICAL_GARDEN = 55, + OASIS = 56, + OBELISK = 57, + REDWOOD_OBSERVATORY = 58, + OCEAN_BOTTLE = 59, + PILLAR_OF_FIRE = 60, + STAR_AXIS = 61, + PRISON = 62, + PYRAMID = 63,//subtype 0 + WOG_OBJECT = 63,//subtype > 0 + RALLY_FLAG = 64, + RANDOM_ART = 65, + RANDOM_TREASURE_ART = 66, + RANDOM_MINOR_ART = 67, + RANDOM_MAJOR_ART = 68, + RANDOM_RELIC_ART = 69, + RANDOM_HERO = 70, + RANDOM_MONSTER = 71, + RANDOM_MONSTER_L1 = 72, + RANDOM_MONSTER_L2 = 73, + RANDOM_MONSTER_L3 = 74, + RANDOM_MONSTER_L4 = 75, + RANDOM_RESOURCE = 76, + RANDOM_TOWN = 77, + REFUGEE_CAMP = 78, + RESOURCE = 79, + SANCTUARY = 80, + SCHOLAR = 81, + SEA_CHEST = 82, + SEER_HUT = 83, + CRYPT = 84, + SHIPWRECK = 85, + SHIPWRECK_SURVIVOR = 86, + SHIPYARD = 87, + SHRINE_OF_MAGIC_INCANTATION = 88, + SHRINE_OF_MAGIC_GESTURE = 89, + SHRINE_OF_MAGIC_THOUGHT = 90, + SIGN = 91, + SIRENS = 92, + SPELL_SCROLL = 93, + STABLES = 94, + TAVERN = 95, + TEMPLE = 96, + DEN_OF_THIEVES = 97, + TOWN = 98, + TRADING_POST [[deprecated]] = 99, + LEARNING_STONE = 100, + TREASURE_CHEST = 101, + TREE_OF_KNOWLEDGE = 102, + SUBTERRANEAN_GATE = 103, + UNIVERSITY [[deprecated]] = 104, + WAGON = 105, + WAR_MACHINE_FACTORY = 106, + SCHOOL_OF_WAR = 107, + WARRIORS_TOMB = 108, + WATER_WHEEL = 109, + WATERING_HOLE = 110, + WHIRLPOOL = 111, + WINDMILL = 112, + WITCH_HUT = 113, + HOLE = 124, + RANDOM_MONSTER_L5 = 162, + RANDOM_MONSTER_L6 = 163, + RANDOM_MONSTER_L7 = 164, + BORDER_GATE = 212, + FREELANCERS_GUILD [[deprecated]] = 213, + HERO_PLACEHOLDER = 214, + QUEST_GUARD = 215, + RANDOM_DWELLING = 216, + RANDOM_DWELLING_LVL = 217, //subtype = creature level + RANDOM_DWELLING_FACTION = 218, //subtype = faction + GARRISON2 = 219, + ABANDONED_MINE = 220, + TRADING_POST_SNOW [[deprecated]] = 221, + CLOVER_FIELD = 222, + CURSED_GROUND2 = 223, + EVIL_FOG = 224, + FAVORABLE_WINDS = 225, + FIERY_FIELDS = 226, + HOLY_GROUNDS = 227, + LUCID_POOLS = 228, + MAGIC_CLOUDS = 229, + MAGIC_PLAINS2 = 230, + ROCKLANDS = 231, + }; +}; + +class Obj : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class RoadIdBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + NO_ROAD = 0, + FIRST_REGULAR_ROAD = 1, + DIRT_ROAD = 1, + GRAVEL_ROAD = 2, + COBBLESTONE_ROAD = 3, + ORIGINAL_ROAD_COUNT //+1 + }; +}; + +class RoadId : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class RiverIdBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + NO_RIVER = 0, + FIRST_REGULAR_RIVER = 1, + WATER_RIVER = 1, + ICY_RIVER = 2, + MUD_RIVER = 3, + LAVA_RIVER = 4, + ORIGINAL_RIVER_COUNT //+1 + }; +}; + +class RiverId : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +using River = RiverId; +using Road = RoadId; + +class DLL_LINKAGE EPathfindingLayerBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + LAND = 0, SAIL = 1, WATER, AIR, NUM_LAYERS, WRONG, AUTO + }; +}; + +class EPathfindingLayer : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class ArtifactPositionBase : public IdentifierBase +{ +public: + enum Type + { + TRANSITION_POS = -3, + FIRST_AVAILABLE = -2, + PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack + HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5 + RIGHT_RING, LEFT_RING, FEET, //8 + MISC1, MISC2, MISC3, MISC4, //12 + MACH1, MACH2, MACH3, MACH4, //16 + SPELLBOOK, MISC5, //18 + AFTER_LAST, + //cres + CREATURE_SLOT = 0, + COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6, COMMANDER_AFTER_LAST, + + BACKPACK_START = 19 + }; + + static_assert (AFTER_LAST == BACKPACK_START, "incorrect number of artifact slots"); + + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); +}; + +class ArtifactPosition : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class ArtifactIDBase : public IdentifierBase +{ +public: + enum Type + { + NONE = -1, + SPELLBOOK = 0, + SPELL_SCROLL = 1, + GRAIL = 2, + CATAPULT = 3, + BALLISTA = 4, + AMMO_CART = 5, + FIRST_AID_TENT = 6, + VIAL_OF_DRAGON_BLOOD = 127, + ARMAGEDDONS_BLADE = 128, + TITANS_THUNDER = 135, + ART_SELECTION = 144, + ART_LOCK = 145, // FIXME: We must get rid of this one since it's conflict with artifact from mods. See issue 2455 + }; + + DLL_LINKAGE const CArtifact * toArtifact() const; + DLL_LINKAGE const Artifact * toArtifact(const ArtifactService * service) const; + + ///json serialization helpers + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); +}; + +class ArtifactID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class CreatureIDBase : public IdentifierBase +{ +public: + enum Type + { + NONE = -1, + ARCHER = 2, // for debug / fallback + IMP = 42, // for Deity of Fire + SKELETON = 56, // for Skeleton Transformer + BONE_DRAGON = 68, // for Skeleton Transformer + TROGLODYTES = 70, // for Abandoned Mine + MEDUSA = 76, // for Siege UI workaround + HYDRA = 110, // for Skeleton Transformer + CHAOS_HYDRA = 111, // for Skeleton Transformer + AIR_ELEMENTAL = 112, // for tests + FIRE_ELEMENTAL = 114, // for tests + PSYCHIC_ELEMENTAL = 120, // for hardcoded ability + MAGIC_ELEMENTAL = 121, // for hardcoded ability + CATAPULT = 145, + BALLISTA = 146, + FIRST_AID_TENT = 147, + AMMO_CART = 148, + ARROW_TOWERS = 149 + }; + + DLL_LINKAGE const CCreature * toCreature() const; + DLL_LINKAGE const Creature * toCreature(const CreatureService * creatures) const; + + ///json serialization helpers + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); +}; + +class CreatureID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class SpellIDBase : public IdentifierBase +{ +public: + enum Type + { + SPELLBOOK_PRESET = -3, + PRESET = -2, + NONE = -1, + SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5, + FLY=6, WATER_WALK=7, DIMENSION_DOOR=8, TOWN_PORTAL=9, + + QUICKSAND=10, LAND_MINE=11, FORCE_FIELD=12, FIRE_WALL=13, EARTHQUAKE=14, + MAGIC_ARROW=15, ICE_BOLT=16, LIGHTNING_BOLT=17, IMPLOSION=18, + CHAIN_LIGHTNING=19, FROST_RING=20, FIREBALL=21, INFERNO=22, + METEOR_SHOWER=23, DEATH_RIPPLE=24, DESTROY_UNDEAD=25, ARMAGEDDON=26, + SHIELD=27, AIR_SHIELD=28, FIRE_SHIELD=29, PROTECTION_FROM_AIR=30, + PROTECTION_FROM_FIRE=31, PROTECTION_FROM_WATER=32, + PROTECTION_FROM_EARTH=33, ANTI_MAGIC=34, DISPEL=35, MAGIC_MIRROR=36, + CURE=37, RESURRECTION=38, ANIMATE_DEAD=39, SACRIFICE=40, BLESS=41, + CURSE=42, BLOODLUST=43, PRECISION=44, WEAKNESS=45, STONE_SKIN=46, + DISRUPTING_RAY=47, PRAYER=48, MIRTH=49, SORROW=50, FORTUNE=51, + MISFORTUNE=52, HASTE=53, SLOW=54, SLAYER=55, FRENZY=56, + TITANS_LIGHTNING_BOLT=57, COUNTERSTRIKE=58, BERSERK=59, HYPNOTIZE=60, + FORGETFULNESS=61, BLIND=62, TELEPORT=63, REMOVE_OBSTACLE=64, CLONE=65, + SUMMON_FIRE_ELEMENTAL=66, SUMMON_EARTH_ELEMENTAL=67, SUMMON_WATER_ELEMENTAL=68, SUMMON_AIR_ELEMENTAL=69, + + STONE_GAZE=70, POISON=71, BIND=72, DISEASE=73, PARALYZE=74, AGE=75, DEATH_CLOUD=76, THUNDERBOLT=77, + DISPEL_HELPFUL_SPELLS=78, DEATH_STARE=79, ACID_BREATH_DEFENSE=80, ACID_BREATH_DAMAGE=81, + + FIRST_NON_SPELL = 70, AFTER_LAST = 82 + }; + + DLL_LINKAGE const CSpell * toSpell() const; //deprecated + DLL_LINKAGE const spells::Spell * toSpell(const spells::Service * service) const; + + ///json serialization helpers + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); +}; + +class SpellID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class BattleFieldInfo; +class BattleField : public Identifier +{ +public: + using Identifier::Identifier; + + DLL_LINKAGE static const BattleField NONE; + DLL_LINKAGE const BattleFieldInfo * getInfo() const; +}; + +class BoatIdBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + NONE = -1, + NECROPOLIS = 0, + CASTLE, + FORTRESS + }; +}; + +class BoatId : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +class TerrainIdBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + NATIVE_TERRAIN = -4, + ANY_TERRAIN = -3, + NONE = -1, + FIRST_REGULAR_TERRAIN = 0, + DIRT = 0, + SAND, + GRASS, + SNOW, + SWAMP, + ROUGH, + SUBTERRANEAN, + LAVA, + WATER, + ROCK, + ORIGINAL_REGULAR_TERRAIN_COUNT = ROCK + }; + + static si32 decode(const std::string & identifier); + static std::string encode(const si32 index); + static std::string entityType(); +}; + +class TerrainId : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +using ETerrainId = TerrainId; + +class ObstacleInfo; +class Obstacle : public Identifier +{ +public: + using Identifier::Identifier; + DLL_LINKAGE const ObstacleInfo * getInfo() const; +}; + +class SpellSchoolBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + ANY = -1, + AIR = 0, + FIRE = 1, + WATER = 2, + EARTH = 3, + }; +}; + +class SpellSchool : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +using ESpellSchool = SpellSchool; + +class GameResIDBase : public IdentifierBase +{ +public: + enum Type : int32_t + { + WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL, + COUNT, + + WOOD_AND_ORE = 127, // special case for town bonus resource + INVALID = -1 + }; +}; + +class GameResID : public IdentifierWithEnum +{ +public: + using IdentifierWithEnum::IdentifierWithEnum; +}; + +using EGameResID = GameResID; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/constants/Enumerations.h b/lib/constants/Enumerations.h new file mode 100644 index 000000000..778bd14ef --- /dev/null +++ b/lib/constants/Enumerations.h @@ -0,0 +1,251 @@ +/* + * GameConstants.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +enum class PrimarySkill : int8_t +{ + NONE = -1, + ATTACK, + DEFENSE, + SPELL_POWER, + KNOWLEDGE, + EXPERIENCE = 4 //for some reason changePrimSkill uses it +}; + +enum class EAlignment : int8_t +{ + GOOD, + EVIL, + NEUTRAL +}; + +namespace BuildingSubID +{ + enum EBuildingSubID + { + DEFAULT = -50, + NONE = -1, + STABLES, + BROTHERHOOD_OF_SWORD, + CASTLE_GATE, + CREATURE_TRANSFORMER, + MYSTIC_POND, + FOUNTAIN_OF_FORTUNE, + ARTIFACT_MERCHANT, + LOOKOUT_TOWER, + LIBRARY, + MANA_VORTEX, + PORTAL_OF_SUMMONING, + ESCAPE_TUNNEL, + FREELANCERS_GUILD, + BALLISTA_YARD, + ATTACK_VISITING_BONUS, + MAGIC_UNIVERSITY, + SPELL_POWER_GARRISON_BONUS, + ATTACK_GARRISON_BONUS, + DEFENSE_GARRISON_BONUS, + DEFENSE_VISITING_BONUS, + SPELL_POWER_VISITING_BONUS, + KNOWLEDGE_VISITING_BONUS, + EXPERIENCE_VISITING_BONUS, + LIGHTHOUSE, + TREASURY, + CUSTOM_VISITING_BONUS, + CUSTOM_VISITING_REWARD + }; +} + +enum class EMarketMode : int8_t +{ + RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT, + ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, RESOURCE_SKILL, + MARTKET_AFTER_LAST_PLACEHOLDER +}; + +enum class EAiTactic : int8_t +{ + NONE = -1, + RANDOM, + WARRIOR, + BUILDER, + EXPLORER +}; + +enum class EBuildingState : int8_t +{ + HAVE_CAPITAL, NO_WATER, FORBIDDEN, ADD_MAGES_GUILD, ALREADY_PRESENT, CANT_BUILD_TODAY, + NO_RESOURCES, ALLOWED, PREREQUIRES, MISSING_BASE, BUILDING_ERROR, TOWN_NOT_OWNED +}; + +enum class ESpellCastProblem : int8_t +{ + OK, NO_HERO_TO_CAST_SPELL, CASTS_PER_TURN_LIMIT, NO_SPELLBOOK, + HERO_DOESNT_KNOW_SPELL, NOT_ENOUGH_MANA, ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL, + SPELL_LEVEL_LIMIT_EXCEEDED, NO_SPELLS_TO_DISPEL, + NO_APPROPRIATE_TARGET, STACK_IMMUNE_TO_SPELL, WRONG_SPELL_TARGET, ONGOING_TACTIC_PHASE, + MAGIC_IS_BLOCKED, //For Orb of Inhibition and similar - no casting at all + INVALID +}; + +namespace ECommander +{ + enum SecondarySkills {ATTACK, DEFENSE, HEALTH, DAMAGE, SPEED, SPELL_POWER, CASTS, RESISTANCE}; + const int MAX_SKILL_LEVEL = 5; +} + +enum class EWallPart : int8_t +{ + INDESTRUCTIBLE_PART_OF_GATE = -3, INDESTRUCTIBLE_PART = -2, INVALID = -1, + KEEP = 0, BOTTOM_TOWER, BOTTOM_WALL, BELOW_GATE, OVER_GATE, UPPER_WALL, UPPER_TOWER, GATE, + PARTS_COUNT /* This constant SHOULD always stay as the last item in the enum. */ +}; + +enum class EWallState : int8_t +{ + NONE = -1, //no wall + DESTROYED, + DAMAGED, + INTACT, + REINFORCED, // walls in towns with castle +}; + +enum class EGateState : int8_t +{ + NONE, + CLOSED, + BLOCKED, // gate is blocked in closed state, e.g. by creature + OPENED, + DESTROYED +}; + +enum class ETileType : int8_t +{ + FREE, + POSSIBLE, + BLOCKED, + USED +}; + +enum class ETeleportChannelType : int8_t +{ + IMPASSABLE, + BIDIRECTIONAL, + UNIDIRECTIONAL, + MIXED +}; + +namespace SecSkillLevel +{ + enum SecSkillLevel + { + NONE, + BASIC, + ADVANCED, + EXPERT, + LEVELS_SIZE + }; +} + +enum class Date : int8_t +{ + DAY = 0, + DAY_OF_WEEK = 1, + WEEK = 2, + MONTH = 3, + DAY_OF_MONTH +}; + +enum class EActionType : int8_t +{ + NO_ACTION, + + END_TACTIC_PHASE, + RETREAT, + SURRENDER, + + HERO_SPELL, + + WALK, + WAIT, + DEFEND, + WALK_AND_ATTACK, + SHOOT, + CATAPULT, + MONSTER_SPELL, + BAD_MORALE, + STACK_HEAL, +}; + +enum class EDiggingStatus : int8_t +{ + UNKNOWN = -1, + CAN_DIG = 0, + LACK_OF_MOVEMENT, + WRONG_TERRAIN, + TILE_OCCUPIED, + BACKPACK_IS_FULL +}; + +enum class EPlayerStatus : int8_t +{ + WRONG = -1, + INGAME, + LOSER, + WINNER +}; + +enum class PlayerRelations : int8_t +{ + ENEMIES, + ALLIES, + SAME_PLAYER +}; + +enum class EMetaclass : int8_t +{ + INVALID = 0, + ARTIFACT, + CREATURE, + FACTION, + EXPERIENCE, + HERO, + HEROCLASS, + LUCK, + MANA, + MORALE, + MOVEMENT, + OBJECT, + PRIMARY_SKILL, + SECONDARY_SKILL, + SPELL, + RESOURCE +}; + +enum class EHealLevel: int8_t +{ + HEAL, + RESURRECT, + OVERHEAL +}; + +enum class EHealPower : int8_t +{ + ONE_BATTLE, + PERMANENT +}; + +enum class EBattleResult : int8_t +{ + NORMAL = 0, + ESCAPE = 1, + SURRENDER = 2, +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/constants/NumericConstants.h b/lib/constants/NumericConstants.h new file mode 100644 index 000000000..7973ac21d --- /dev/null +++ b/lib/constants/NumericConstants.h @@ -0,0 +1,59 @@ +/* + * GameConstants.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +namespace GameConstants +{ + DLL_LINKAGE extern const std::string VCMI_VERSION; + + constexpr int PUZZLE_MAP_PIECES = 48; + + constexpr int MAX_HEROES_PER_PLAYER = 8; + constexpr int AVAILABLE_HEROES_PER_PLAYER = 2; + + constexpr int ALL_PLAYERS = 255; //bitfield + + constexpr int CREATURES_PER_TOWN = 7; //without upgrades + constexpr int SPELL_LEVELS = 5; + constexpr int SPELL_SCHOOL_LEVELS = 4; + constexpr int DEFAULT_SCHOOLS = 4; + constexpr int CRE_LEVELS = 10; // number of creature experience levels + + constexpr int HERO_GOLD_COST = 2500; + constexpr int SPELLBOOK_GOLD_COST = 500; + constexpr int SKILL_GOLD_COST = 2000; + constexpr int BATTLE_SHOOTING_PENALTY_DISTANCE = 10; //if the distance is > than this, then shooting stack has distance penalty + constexpr int BATTLE_SHOOTING_RANGE_DISTANCE = std::numeric_limits::max(); // used when shooting stack has no shooting range limit + constexpr int ARMY_SIZE = 7; + constexpr int SKILL_PER_HERO = 8; + constexpr ui32 HERO_HIGH_LEVEL = 10; // affects primary skill upgrade order + + constexpr int SKILL_QUANTITY=28; + constexpr int PRIMARY_SKILLS=4; + constexpr int RESOURCE_QUANTITY=8; + constexpr int HEROES_PER_TYPE=8; //amount of heroes of each type + + // amounts of OH3 objects. Can be changed by mods, should be used only during H3 loading phase + constexpr int F_NUMBER = 9; + constexpr int ARTIFACTS_QUANTITY=171; + constexpr int HEROES_QUANTITY=156; + constexpr int SPELLS_QUANTITY=70; + constexpr int CREATURES_COUNT = 197; + + constexpr ui32 BASE_MOVEMENT_COST = 100; //default cost for non-diagonal movement + + constexpr int HERO_PORTRAIT_SHIFT = 9;// 2 special frames + 7 extra portraits + + constexpr std::array POSSIBLE_TURNTIME = {1, 2, 4, 6, 8, 10, 15, 20, 25, 30, 0}; +} + +VCMI_LIB_NAMESPACE_END diff --git a/lib/constants/StringConstants.h b/lib/constants/StringConstants.h new file mode 100644 index 000000000..f2edac8cf --- /dev/null +++ b/lib/constants/StringConstants.h @@ -0,0 +1,217 @@ +/* + * constants/StringConstants.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include "GameConstants.h" + +VCMI_LIB_NAMESPACE_BEGIN + +/// +/// String ID which are pointless to move to config file - these types are mostly hardcoded +/// +namespace GameConstants +{ + const std::string RESOURCE_NAMES [RESOURCE_QUANTITY] = { + "wood", "mercury", "ore", "sulfur", "crystal", "gems", "gold", "mithril" + }; + + const std::string PLAYER_COLOR_NAMES [PlayerColor::PLAYER_LIMIT_I] = { + "red", "blue", "tan", "green", "orange", "purple", "teal", "pink" + }; + + const std::string ALIGNMENT_NAMES [3] = {"good", "evil", "neutral"}; +} + +namespace NPrimarySkill +{ + const std::string names [GameConstants::PRIMARY_SKILLS] = { "attack", "defence", "spellpower", "knowledge" }; +} + +namespace NSecondarySkill +{ + const std::string names [GameConstants::SKILL_QUANTITY] = + { + "pathfinding", "archery", "logistics", "scouting", "diplomacy", // 5 + "navigation", "leadership", "wisdom", "mysticism", "luck", // 10 + "ballistics", "eagleEye", "necromancy", "estates", "fireMagic", // 15 + "airMagic", "waterMagic", "earthMagic", "scholar", "tactics", // 20 + "artillery", "learning", "offence", "armorer", "intelligence", // 25 + "sorcery", "resistance", "firstAid" + }; + + const std::vector levels = + { + "none", "basic", "advanced", "expert" + }; +} + +namespace EBuildingType +{ + const std::string names [44] = + { + "mageGuild1", "mageGuild2", "mageGuild3", "mageGuild4", "mageGuild5", // 5 + "tavern", "shipyard", "fort", "citadel", "castle", // 10 + "villageHall", "townHall", "cityHall", "capitol", "marketplace", // 15 + "resourceSilo", "blacksmith", "special1", "horde1", "horde1Upgr", // 20 + "ship", "special2", "special3", "special4", "horde2", // 25 + "horde2Upgr", "grail", "extraTownHall", "extraCityHall", "extraCapitol", // 30 + "dwellingLvl1", "dwellingLvl2", "dwellingLvl3", "dwellingLvl4", "dwellingLvl5", // 35 + "dwellingLvl6", "dwellingLvl7", "dwellingUpLvl1", "dwellingUpLvl2", "dwellingUpLvl3", // 40 + "dwellingUpLvl4", "dwellingUpLvl5", "dwellingUpLvl6", "dwellingUpLvl7" + }; +} + +namespace NFaction +{ + const std::string names [GameConstants::F_NUMBER] = + { + "castle", "rampart", "tower", + "inferno", "necropolis", "dungeon", + "stronghold", "fortress", "conflux" + }; +} + +namespace NArtifactPosition +{ + const std::string namesHero [19] = + { + "head", "shoulders", "neck", "rightHand", "leftHand", "torso", //5 + "rightRing", "leftRing", "feet", //8 + "misc1", "misc2", "misc3", "misc4", //12 + "mach1", "mach2", "mach3", "mach4", //16 + "spellbook", "misc5" //18 + }; + + const std::string namesCreature[1] = + { + "creature1" + }; + + const std::string namesCommander[6] = + { + "commander1", "commander2", "commander3", "commander4", "commander5", "commander6", + }; + + + const std::string backpack = "backpack"; +} + +namespace NMetaclass +{ + const std::string names [16] = + { + "", + "artifact", "creature", "faction", "experience", "hero", + "heroClass", "luck", "mana", "morale", "movement", + "object", "primarySkill", "secondarySkill", "spell", "resource" + }; +} + +namespace NPathfindingLayer +{ + const std::string names[EPathfindingLayer::NUM_LAYERS] = + { + "land", "sail", "water", "air" + }; +} + +namespace MappedKeys +{ + + static const std::map BUILDING_NAMES_TO_TYPES = + { + { "special1", BuildingID::SPECIAL_1 }, + { "special2", BuildingID::SPECIAL_2 }, + { "special3", BuildingID::SPECIAL_3 }, + { "special4", BuildingID::SPECIAL_4 }, + { "grail", BuildingID::GRAIL }, + { "mageGuild1", BuildingID::MAGES_GUILD_1 }, + { "mageGuild2", BuildingID::MAGES_GUILD_2 }, + { "mageGuild3", BuildingID::MAGES_GUILD_3 }, + { "mageGuild4", BuildingID::MAGES_GUILD_4 }, + { "mageGuild5", BuildingID::MAGES_GUILD_5 }, + { "tavern", BuildingID::TAVERN }, + { "shipyard", BuildingID::SHIPYARD }, + { "fort", BuildingID::FORT }, + { "citadel", BuildingID::CITADEL }, + { "castle", BuildingID::CASTLE }, + { "villageHall", BuildingID::VILLAGE_HALL }, + { "townHall", BuildingID::TOWN_HALL }, + { "cityHall", BuildingID::CITY_HALL }, + { "capitol", BuildingID::CAPITOL }, + { "marketplace", BuildingID::MARKETPLACE }, + { "resourceSilo", BuildingID::RESOURCE_SILO }, + { "blacksmith", BuildingID::BLACKSMITH }, + { "horde1", BuildingID::HORDE_1 }, + { "horde1Upgr", BuildingID::HORDE_1_UPGR }, + { "horde2", BuildingID::HORDE_2 }, + { "horde2Upgr", BuildingID::HORDE_2_UPGR }, + { "ship", BuildingID::SHIP }, + { "dwellingLvl1", BuildingID::DWELL_LVL_1 }, + { "dwellingLvl2", BuildingID::DWELL_LVL_2 }, + { "dwellingLvl3", BuildingID::DWELL_LVL_3 }, + { "dwellingLvl4", BuildingID::DWELL_LVL_4 }, + { "dwellingLvl5", BuildingID::DWELL_LVL_5 }, + { "dwellingLvl6", BuildingID::DWELL_LVL_6 }, + { "dwellingLvl7", BuildingID::DWELL_LVL_7 }, + { "dwellingUpLvl1", BuildingID::DWELL_LVL_1_UP }, + { "dwellingUpLvl2", BuildingID::DWELL_LVL_2_UP }, + { "dwellingUpLvl3", BuildingID::DWELL_LVL_3_UP }, + { "dwellingUpLvl4", BuildingID::DWELL_LVL_4_UP }, + { "dwellingUpLvl5", BuildingID::DWELL_LVL_5_UP }, + { "dwellingUpLvl6", BuildingID::DWELL_LVL_6_UP }, + { "dwellingUpLvl7", BuildingID::DWELL_LVL_7_UP }, + }; + + static const std::map SPECIAL_BUILDINGS = + { + { "mysticPond", BuildingSubID::MYSTIC_POND }, + { "artifactMerchant", BuildingSubID::ARTIFACT_MERCHANT }, + { "freelancersGuild", BuildingSubID::FREELANCERS_GUILD }, + { "magicUniversity", BuildingSubID::MAGIC_UNIVERSITY }, + { "castleGate", BuildingSubID::CASTLE_GATE }, + { "creatureTransformer", BuildingSubID::CREATURE_TRANSFORMER },//only skeleton transformer yet + { "portalOfSummoning", BuildingSubID::PORTAL_OF_SUMMONING }, + { "ballistaYard", BuildingSubID::BALLISTA_YARD }, + { "stables", BuildingSubID::STABLES }, + { "manaVortex", BuildingSubID::MANA_VORTEX }, + { "lookoutTower", BuildingSubID::LOOKOUT_TOWER }, + { "library", BuildingSubID::LIBRARY }, + { "brotherhoodOfSword", BuildingSubID::BROTHERHOOD_OF_SWORD },//morale garrison bonus + { "fountainOfFortune", BuildingSubID::FOUNTAIN_OF_FORTUNE },//luck garrison bonus + { "spellPowerGarrisonBonus", BuildingSubID::SPELL_POWER_GARRISON_BONUS },//such as 'stormclouds', but this name is not ok for good towns + { "attackGarrisonBonus", BuildingSubID::ATTACK_GARRISON_BONUS }, + { "defenseGarrisonBonus", BuildingSubID::DEFENSE_GARRISON_BONUS }, + { "escapeTunnel", BuildingSubID::ESCAPE_TUNNEL }, + { "attackVisitingBonus", BuildingSubID::ATTACK_VISITING_BONUS }, + { "defenceVisitingBonus", BuildingSubID::DEFENSE_VISITING_BONUS }, + { "spellPowerVisitingBonus", BuildingSubID::SPELL_POWER_VISITING_BONUS }, + { "knowledgeVisitingBonus", BuildingSubID::KNOWLEDGE_VISITING_BONUS }, + { "experienceVisitingBonus", BuildingSubID::EXPERIENCE_VISITING_BONUS }, + { "lighthouse", BuildingSubID::LIGHTHOUSE }, + { "treasury", BuildingSubID::TREASURY } + }; + + static const std::map MARKET_NAMES_TO_TYPES = + { + { "resource-resource", EMarketMode::RESOURCE_RESOURCE }, + { "resource-player", EMarketMode::RESOURCE_PLAYER }, + { "creature-resource", EMarketMode::CREATURE_RESOURCE }, + { "resource-artifact", EMarketMode::RESOURCE_ARTIFACT }, + { "artifact-resource", EMarketMode::ARTIFACT_RESOURCE }, + { "artifact-experience", EMarketMode::ARTIFACT_EXP }, + { "creature-experience", EMarketMode::CREATURE_EXP }, + { "creature-undead", EMarketMode::CREATURE_UNDEAD }, + { "resource-skill", EMarketMode::RESOURCE_SKILL }, + }; +} + + +VCMI_LIB_NAMESPACE_END diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 05d9a6bb0..df831c513 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -107,7 +107,7 @@ static CGObjectInstance * createObject(const Obj & id, int subid, const int3 & p HeroTypeID 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 + if(ps.hero >= HeroTypeID(0) && !isUsedHero(HeroTypeID(ps.hero))) //we haven't used selected hero { return HeroTypeID(ps.hero); } @@ -777,7 +777,7 @@ void CGameState::placeStartingHeroes() continue; int heroTypeId = pickNextHeroType(playerColor); - if(playerSettingPair.second.hero == -1) + if(playerSettingPair.second.hero == HeroTypeID::NONE) playerSettingPair.second.hero = heroTypeId; placeStartingHero(playerColor, HeroTypeID(heroTypeId), playerInfo.posOfMainTown); @@ -2063,7 +2063,7 @@ std::set CGameState::getUnusedAllowedHeroes(bool alsoIncludeNotAllow for(const auto & playerSettingPair : scenarioOps->playerInfos) //remove uninitialized yet heroes picked for start by other players { - if(playerSettingPair.second.hero != PlayerSettings::RANDOM) + if(playerSettingPair.second.hero.getNum() != PlayerSettings::RANDOM) ret -= HeroTypeID(playerSettingPair.second.hero); } diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index 40c3af61e..dbb56c45d 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -12,6 +12,7 @@ #include "bonuses/CBonusSystemNode.h" #include "IGameCallback.h" #include "LoadProgress.h" +#include "ConstTransitivePtr.h" namespace boost { diff --git a/lib/gameState/CGameStateCampaign.cpp b/lib/gameState/CGameStateCampaign.cpp index c45beb135..fbcd70011 100644 --- a/lib/gameState/CGameStateCampaign.cpp +++ b/lib/gameState/CGameStateCampaign.cpp @@ -146,7 +146,7 @@ void CGameStateCampaign::trimCrossoverHeroesParameters(std::vectorartifactsInBackpack.size() - 1; slotNumber >= 0; slotNumber--) - checkAndRemoveArtifact(ArtifactPosition(GameConstants::BACKPACK_START + slotNumber)); + checkAndRemoveArtifact(ArtifactPosition::BACKPACK_START + slotNumber); } } diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.cpp b/lib/mapObjectConstructors/CObjectClassesHandler.cpp index fd2e33b9b..ffa63e29b 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.cpp +++ b/lib/mapObjectConstructors/CObjectClassesHandler.cpp @@ -14,7 +14,7 @@ #include "../filesystem/CBinaryReader.h" #include "../VCMI_Lib.h" #include "../GameConstants.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../CGeneralTextHandler.h" #include "../GameSettings.h" #include "../JsonNode.h" diff --git a/lib/mapObjectConstructors/CommonConstructors.cpp b/lib/mapObjectConstructors/CommonConstructors.cpp index 390e1f5d9..14aec1665 100644 --- a/lib/mapObjectConstructors/CommonConstructors.cpp +++ b/lib/mapObjectConstructors/CommonConstructors.cpp @@ -15,7 +15,7 @@ #include "../CTownHandler.h" #include "../IGameCallback.h" #include "../JsonRandom.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../TerrainHandler.h" #include "../VCMI_Lib.h" diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index a52d5940e..d7dd0a855 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -35,7 +35,7 @@ #include "../mapObjectConstructors/AObjectTypeHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../modding/ModScope.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../battle/Unit.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGObjectInstance.cpp b/lib/mapObjects/CGObjectInstance.cpp index 5fbae6725..4b081c4e5 100644 --- a/lib/mapObjects/CGObjectInstance.cpp +++ b/lib/mapObjects/CGObjectInstance.cpp @@ -18,7 +18,7 @@ #include "../CGeneralTextHandler.h" #include "../IGameCallback.h" #include "../NetPacks.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../TerrainHandler.h" #include "../mapObjectConstructors/AObjectTypeHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h" diff --git a/lib/mapObjects/CGPandoraBox.cpp b/lib/mapObjects/CGPandoraBox.cpp index f7bc248f2..2e64f438b 100644 --- a/lib/mapObjects/CGPandoraBox.cpp +++ b/lib/mapObjects/CGPandoraBox.cpp @@ -20,7 +20,7 @@ #include "../CSkillHandler.h" #include "../StartInfo.h" #include "../IGameCallback.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../serializer/JsonSerializeFormat.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 3ad5f2948..cf2373dfb 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -364,7 +364,7 @@ void CGTownInstance::initOverriddenBids() } } -bool CGTownInstance::isBonusingBuildingAdded(BuildingID::EBuildingID bid) const +bool CGTownInstance::isBonusingBuildingAdded(BuildingID bid) const { auto present = std::find_if(bonusingBuildings.begin(), bonusingBuildings.end(), [&](CGTownBuilding* building) { @@ -428,7 +428,7 @@ DamageRange CGTownInstance::getKeepDamageRange() const }; } -void CGTownInstance::deleteTownBonus(BuildingID::EBuildingID bid) +void CGTownInstance::deleteTownBonus(BuildingID bid) { size_t i = 0; CGTownBuilding * freeIt = nullptr; @@ -467,7 +467,7 @@ void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structu for (int level = 0; level < GameConstants::CREATURES_PER_TOWN; level++) { - BuildingID buildID = BuildingID(BuildingID::DWELL_FIRST).advance(level); + BuildingID buildID = BuildingID(BuildingID::DWELL_FIRST + level); int upgradeNum = 0; for (; town->buildings.count(buildID); upgradeNum++, buildID.advance(GameConstants::CREATURES_PER_TOWN)) diff --git a/lib/mapObjects/CGTownInstance.h b/lib/mapObjects/CGTownInstance.h index 6f8298143..6f47cf525 100644 --- a/lib/mapObjects/CGTownInstance.h +++ b/lib/mapObjects/CGTownInstance.h @@ -175,7 +175,7 @@ public: void removeCapitols(const PlayerColor & owner) const; void clearArmy() const; void addHeroToStructureVisitors(const CGHeroInstance *h, si64 structureInstanceID) const; //hero must be visiting or garrisoned in town - void deleteTownBonus(BuildingID::EBuildingID bid); + void deleteTownBonus(BuildingID bid); /// Returns damage range for secondary towers of this town DamageRange getTowerDamageRange() const; @@ -220,7 +220,7 @@ private: void onTownCaptured(const PlayerColor & winner) const; int getDwellingBonus(const std::vector& creatureIds, const std::vector >& dwellings) const; bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const; - bool isBonusingBuildingAdded(BuildingID::EBuildingID bid) const; + bool isBonusingBuildingAdded(BuildingID bid) const; void initOverriddenBids(); void addTownBonuses(CRandomGenerator & rand); }; diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index 90eb106b2..9e73793ca 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -23,7 +23,7 @@ #include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../serializer/JsonSerializeFormat.h" #include "../GameConstants.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../CSkillHandler.h" #include "../mapping/CMap.h" #include "../modding/ModScope.h" @@ -814,7 +814,7 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const for(const auto & ci : parts) { if(ci.art->getTypeId() != elem) - cb->giveHeroNewArtifact(h, ci.art->artType, GameConstants::BACKPACK_START); + cb->giveHeroNewArtifact(h, ci.art->artType, ArtifactPosition::BACKPACK_START); } } } diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 0cc036acd..2779765d9 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -11,7 +11,7 @@ #include "StdInc.h" #include "MiscObjects.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../NetPacks.h" #include "../CGeneralTextHandler.h" #include "../CSoundBase.h" @@ -1291,7 +1291,7 @@ CGBoat::CGBoat() { hero = nullptr; direction = 4; - layer = EPathfindingLayer::EEPathfindingLayer::SAIL; + layer = EPathfindingLayer::SAIL; } bool CGBoat::isCoastVisitable() const diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index d681fe605..f159f418d 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -351,7 +351,7 @@ public: const CGHeroInstance *hero; //hero on board bool onboardAssaultAllowed; //if true, hero can attack units from transport bool onboardVisitAllowed; //if true, hero can visit objects from transport - EPathfindingLayer::EEPathfindingLayer layer; + EPathfindingLayer layer; //animation filenames. If empty - animations won't be used std::string actualAnimation; //for OH3 boats those have actual animations diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index ca1059d9c..675f98486 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -14,7 +14,7 @@ #include "../filesystem/CBinaryReader.h" #include "../VCMI_Lib.h" #include "../GameConstants.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../CGeneralTextHandler.h" #include "../JsonNode.h" #include "../TerrainHandler.h" diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 57fb49a9e..cd8d341a6 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -898,7 +898,7 @@ void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero) int amount = reader->readUInt16(); for(int i = 0; i < amount; ++i) { - loadArtifactToSlot(hero, GameConstants::BACKPACK_START + static_cast(hero->artifactsInBackpack.size())); + loadArtifactToSlot(hero, ArtifactPosition::BACKPACK_START + static_cast(hero->artifactsInBackpack.size())); } } @@ -917,7 +917,7 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot) return false; } - if(art->isBig() && slot >= GameConstants::BACKPACK_START) + if(art->isBig() && slot >= ArtifactPosition::BACKPACK_START) { logGlobal->warn("Map '%s': A big artifact (war machine) in hero's backpack, ignoring...", mapName); return false; @@ -1652,7 +1652,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(const int3 & mapPosition, const Objec for(auto & elem : map->disposedHeroes) { - if(elem.heroId == object->subID) + if(elem.heroId.getNum() == object->subID) { object->nameCustom = elem.name; object->portrait = elem.portrait; diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index 6908a7511..e8bd5fbe1 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -32,7 +32,7 @@ #include "../modding/ModUtility.h" #include "../spells/CSpellHandler.h" #include "../CSkillHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../serializer/JsonDeserializer.h" #include "../serializer/JsonSerializer.h" diff --git a/lib/modding/CModHandler.cpp b/lib/modding/CModHandler.cpp index bed4f0805..a26ab4248 100644 --- a/lib/modding/CModHandler.cpp +++ b/lib/modding/CModHandler.cpp @@ -22,7 +22,7 @@ #include "../GameSettings.h" #include "../Languages.h" #include "../ScriptHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../filesystem/Filesystem.h" #include "../spells/CSpellHandler.h" diff --git a/lib/modding/ContentTypeHandler.cpp b/lib/modding/ContentTypeHandler.cpp index ed2667e7e..afcfd0ff9 100644 --- a/lib/modding/ContentTypeHandler.cpp +++ b/lib/modding/ContentTypeHandler.cpp @@ -29,7 +29,7 @@ #include "../RiverHandler.h" #include "../RoadHandler.h" #include "../ScriptHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../TerrainHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../rmg/CRmgTemplateStorage.h" diff --git a/lib/pathfinder/PathfinderUtil.h b/lib/pathfinder/PathfinderUtil.h index 0121c8448..49efd7833 100644 --- a/lib/pathfinder/PathfinderUtil.h +++ b/lib/pathfinder/PathfinderUtil.h @@ -22,7 +22,7 @@ namespace PathfinderUtil using FoW = std::shared_ptr>; using ELayer = EPathfindingLayer; - template + template EPathAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, FoW fow, const PlayerColor player, const CGameState * gs) { if(!(*fow)[pos.z][pos.x][pos.y]) diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index 69527411f..d526d17c5 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -19,7 +19,7 @@ #include "../mapping/CMapEditManager.h" #include "../CTownHandler.h" #include "../CHeroHandler.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../filesystem/Filesystem.h" #include "CZonePlacer.h" #include "TileInfo.h" diff --git a/lib/rmg/CRmgTemplate.cpp b/lib/rmg/CRmgTemplate.cpp index b8032bc01..71e00fec7 100644 --- a/lib/rmg/CRmgTemplate.cpp +++ b/lib/rmg/CRmgTemplate.cpp @@ -19,7 +19,7 @@ #include "../TerrainHandler.h" #include "../serializer/JsonSerializeFormat.h" #include "../modding/ModScope.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index 086eb0d04..f09baeffb 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -60,7 +60,7 @@ class DLL_LINKAGE CSerializer } template - static NT idToNumber(const BaseForID &t) + static NT idToNumber(const IdentifierBase &t) { return t.getNum(); } diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index acfc219b3..f048d36c5 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -20,7 +20,7 @@ #include "../CGeneralTextHandler.h" #include "../filesystem/Filesystem.h" -#include "../StringConstants.h" +#include "../constants/StringConstants.h" #include "../battle/BattleInfo.h" #include "../battle/CBattleInfoCallback.h" diff --git a/mapeditor/inspector/questwidget.cpp b/mapeditor/inspector/questwidget.cpp index f9e2ddcb1..a21392983 100644 --- a/mapeditor/inspector/questwidget.cpp +++ b/mapeditor/inspector/questwidget.cpp @@ -15,7 +15,7 @@ #include "../lib/CArtHandler.h" #include "../lib/CCreatureHandler.h" #include "../lib/CHeroHandler.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "../lib/mapping/CMap.h" QuestWidget::QuestWidget(const CMap & _map, CGSeerHut & _sh, QWidget *parent) : diff --git a/mapeditor/inspector/rewardswidget.cpp b/mapeditor/inspector/rewardswidget.cpp index f131ae6a9..bcc974112 100644 --- a/mapeditor/inspector/rewardswidget.cpp +++ b/mapeditor/inspector/rewardswidget.cpp @@ -15,7 +15,7 @@ #include "../lib/spells/CSpellHandler.h" #include "../lib/CArtHandler.h" #include "../lib/CCreatureHandler.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "../lib/mapping/CMap.h" RewardsWidget::RewardsWidget(const CMap & m, CGPandoraBox & p, QWidget *parent) : diff --git a/mapeditor/inspector/townbulidingswidget.cpp b/mapeditor/inspector/townbulidingswidget.cpp index 23c75beb9..29ee4e500 100644 --- a/mapeditor/inspector/townbulidingswidget.cpp +++ b/mapeditor/inspector/townbulidingswidget.cpp @@ -130,7 +130,7 @@ QStandardItem * TownBulidingsWidget::addBuilding(const CTown & ctown, int bId, s for(int i = 0; i < model.rowCount(pindex); ++i) { QModelIndex index = model.index(i, 0, pindex); - if(building->upgrade == model.itemFromIndex(index)->data(Qt::UserRole).toInt()) + if(building->upgrade.getNum() == model.itemFromIndex(index)->data(Qt::UserRole).toInt()) { parent = model.itemFromIndex(index); break; diff --git a/mapeditor/mapsettings.cpp b/mapeditor/mapsettings.cpp index ca42a447e..66239ff3c 100644 --- a/mapeditor/mapsettings.cpp +++ b/mapeditor/mapsettings.cpp @@ -22,7 +22,7 @@ #include "../lib/mapping/CMapService.h" #include "../lib/modding/CModHandler.h" #include "../lib/modding/CModInfo.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "inspector/townbulidingswidget.h" //to convert BuildingID to string //parses date for lose condition (1m 1w 1d) diff --git a/mapeditor/playerparams.cpp b/mapeditor/playerparams.cpp index ebf29c9b2..9734f8f68 100644 --- a/mapeditor/playerparams.cpp +++ b/mapeditor/playerparams.cpp @@ -12,7 +12,7 @@ #include "playerparams.h" #include "ui_playerparams.h" #include "../lib/CTownHandler.h" -#include "../lib/StringConstants.h" +#include "../lib/constants/StringConstants.h" #include "../lib/mapping/CMap.h" diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 7ed103c5e..74f426a4d 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2676,7 +2676,7 @@ bool CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocat { if(!ArtifactUtils::isBackpackFreeSlots(dst.getHolderArtSet())) COMPLAIN_RET("Backpack is full!"); - vstd::amin(dst.slot, GameConstants::BACKPACK_START + dst.getHolderArtSet()->artifactsInBackpack.size()); + vstd::amin(dst.slot, ArtifactPosition::BACKPACK_START + dst.getHolderArtSet()->artifactsInBackpack.size()); } if(!(src.slot == ArtifactPosition::TRANSITION_POS && dst.slot == ArtifactPosition::TRANSITION_POS)) diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index ad2738c0b..5b3eecdef 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -727,7 +727,7 @@ void CVCMIServer::updateStartInfoOnMapChange(std::shared_ptr mapInfo, pset.castle = pinfo.defaultCastle(); pset.hero = pinfo.defaultHero(); - if(pset.hero != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) + if(pset.hero.getNum() != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) { pset.hero = pinfo.mainCustomHeroId; pset.heroName = pinfo.mainCustomHeroName; @@ -876,7 +876,7 @@ void CVCMIServer::optionNextCastle(PlayerColor player, int dir) } } - if(s.hero >= 0 && !getPlayerInfo(player.getNum()).hasCustomMainHero()) // remove hero unless it set to fixed one in map editor + if(s.hero.getNum() >= 0 && !getPlayerInfo(player.getNum()).hasCustomMainHero()) // remove hero unless it set to fixed one in map editor { s.hero = PlayerSettings::RANDOM; } @@ -935,10 +935,10 @@ void CVCMIServer::setCampaignBonus(int bonusId) void CVCMIServer::optionNextHero(PlayerColor player, int dir) { PlayerSettings & s = si->playerInfos[player]; - if(s.castle.getNum() < 0 || s.hero == PlayerSettings::NONE) + if(s.castle.getNum() < 0 || s.hero.getNum() == PlayerSettings::NONE) return; - if(s.hero == PlayerSettings::RANDOM) // first/last available + if(s.hero.getNum() == PlayerSettings::RANDOM) // first/last available { int max = static_cast(VLC->heroh->size()), min = 0; @@ -956,7 +956,7 @@ void CVCMIServer::optionNextHero(PlayerColor player, int dir) void CVCMIServer::optionSetHero(PlayerColor player, int id) { PlayerSettings & s = si->playerInfos[player]; - if(s.castle.getNum() < 0 || s.hero == PlayerSettings::NONE) + if(s.castle.getNum() < 0 || s.hero.getNum() == PlayerSettings::NONE) return; if(id == PlayerSettings::RANDOM) @@ -967,19 +967,19 @@ void CVCMIServer::optionSetHero(PlayerColor player, int id) s.hero = static_cast(id); } -int CVCMIServer::nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir) +HeroTypeID CVCMIServer::nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir) { if(dir > 0) { for(int i = min + incl; i <= max - incl; i++) if(canUseThisHero(player, i)) - return i; + return HeroTypeID(i); } else { for(int i = max - incl; i >= min + incl; i--) if(canUseThisHero(player, i)) - return i; + return HeroTypeID(i); } return -1; } @@ -989,7 +989,7 @@ void CVCMIServer::optionNextBonus(PlayerColor player, int dir) PlayerSettings & s = si->playerInfos[player]; PlayerSettings::Ebonus & ret = s.bonus = static_cast(static_cast(s.bonus) + dir); - if(s.hero == PlayerSettings::NONE && + if(s.hero.getNum() == PlayerSettings::NONE && !getPlayerInfo(player.getNum()).heroesNames.size() && ret == PlayerSettings::ARTIFACT) //no hero - can't be artifact { @@ -1017,7 +1017,7 @@ void CVCMIServer::optionSetBonus(PlayerColor player, int id) { PlayerSettings & s = si->playerInfos[player]; - if(s.hero == PlayerSettings::NONE && + if(s.hero.getNum() == PlayerSettings::NONE && !getPlayerInfo(player.getNum()).heroesNames.size() && id == PlayerSettings::ARTIFACT) //no hero - can't be artifact return; @@ -1051,7 +1051,7 @@ std::vector CVCMIServer::getUsedHeroes() if(hero.heroId >= 0) //in VCMI map format heroId = -1 means random hero heroIds.push_back(hero.heroId); - if(p.second.hero != PlayerSettings::RANDOM) + if(p.second.hero.getNum() != PlayerSettings::RANDOM) heroIds.push_back(p.second.hero); } return heroIds; diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index beb3be62b..450fe3732 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -108,7 +108,7 @@ public: void setPlayer(PlayerColor clickedColor); void optionNextHero(PlayerColor player, int dir); //dir == -1 or +1 void optionSetHero(PlayerColor player, int id); - int nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir); + HeroTypeID nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir); bool canUseThisHero(PlayerColor player, int ID); std::vector getUsedHeroes(); void optionNextBonus(PlayerColor player, int dir); //dir == -1 or +1 diff --git a/server/battles/BattleResultProcessor.cpp b/server/battles/BattleResultProcessor.cpp index 59860edf5..6bf6e6fcb 100644 --- a/server/battles/BattleResultProcessor.cpp +++ b/server/battles/BattleResultProcessor.cpp @@ -265,7 +265,7 @@ void BattleResultProcessor::endBattle(int3 tile, const CGHeroInstance * heroAtta gameHandler->sendAndApply(battleResult.get()); //after this point casualties objects are destroyed - if (battleResult->queryID == -1) + if (battleResult->queryID == QueryID::NONE) endBattleConfirm(gameHandler->gameState()->curB); } @@ -334,7 +334,7 @@ void BattleResultProcessor::endBattleConfirm(const BattleInfo * battleInfo) //we assume that no big artifacts can be found MoveArtifact ma; ma.src = ArtifactLocation(finishingBattle->loserHero, - ArtifactPosition(GameConstants::BACKPACK_START + slotNumber)); //backpack automatically shifts arts to beginning + ArtifactPosition(ArtifactPosition::BACKPACK_START + slotNumber)); //backpack automatically shifts arts to beginning const CArtifactInstance * art = ma.src.getArt(); if (art->artType->getId() != ArtifactID::GRAIL) //grail may not be won { diff --git a/server/queries/CQuery.h b/server/queries/CQuery.h index 0d105ca37..9eddbccdc 100644 --- a/server/queries/CQuery.h +++ b/server/queries/CQuery.h @@ -21,6 +21,7 @@ VCMI_LIB_NAMESPACE_END class CObjectVisitQuery; class QueriesProcessor; class CQuery; +class CGameHandler; using QueryPtr = std::shared_ptr; diff --git a/test/game/CGameStateTest.cpp b/test/game/CGameStateTest.cpp index 32f0cd176..4b41d2e3e 100644 --- a/test/game/CGameStateTest.cpp +++ b/test/game/CGameStateTest.cpp @@ -167,7 +167,7 @@ public: pset.castle = pinfo.defaultCastle(); pset.hero = pinfo.defaultHero(); - if(pset.hero != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) + if(pset.hero.getNum() != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) { pset.hero = pinfo.mainCustomHeroId; pset.heroName = pinfo.mainCustomHeroName;