diff --git a/AI/VCAI/Goals/CollectRes.cpp b/AI/VCAI/Goals/CollectRes.cpp index 4599bed34..4a7feff61 100644 --- a/AI/VCAI/Goals/CollectRes.cpp +++ b/AI/VCAI/Goals/CollectRes.cpp @@ -170,7 +170,7 @@ TSubgoal CollectRes::whatToDoToTrade() const IMarket * m = markets.back(); //attempt trade at back (best prices) int howManyCanWeBuy = 0; - for (auto i = EGameResID::WOOD; i <= EGameResID::GOLD; vstd::advance(i, 1)) + for (GameResID i = EGameResID::WOOD; i <= EGameResID::GOLD; ++i) { if (GameResID(i) == resID) continue; diff --git a/Global.h b/Global.h index e32b0da72..a869ac611 100644 --- a/Global.h +++ b/Global.h @@ -543,16 +543,12 @@ namespace vstd }); } + /// Increments value by specific delta + /// similar to std::next but works with other types, e.g. enum class template - T advance_r(const T &obj, int change) + T next(const T &obj, int change) { - return static_cast(static_cast(obj) + change); - } - - template - void advance(T &obj, int change) - { - obj = advance_r(obj, change); + return static_cast(static_cast(obj) + change); } template diff --git a/client/adventureMap/CResDataBar.cpp b/client/adventureMap/CResDataBar.cpp index 33cb30f0a..6227b9f4b 100644 --- a/client/adventureMap/CResDataBar.cpp +++ b/client/adventureMap/CResDataBar.cpp @@ -80,7 +80,7 @@ std::string CResDataBar::buildDateString() void CResDataBar::draw(SDL_Surface * to) { //TODO: all this should be labels, but they require proper text update on change - for (auto i=GameResID(EGameResID::WOOD); i <= GameResID(EGameResID::GOLD); vstd::advance(i, 1)) + for (GameResID i=EGameResID::WOOD; i <= GameResID(EGameResID::GOLD); ++i) { std::string text = std::to_string(LOCPLINT->cb->getResourceAmount(i)); diff --git a/client/widgets/CComponent.cpp b/client/widgets/CComponent.cpp index a75334d7e..1aaec7be9 100644 --- a/client/widgets/CComponent.cpp +++ b/client/widgets/CComponent.cpp @@ -494,7 +494,7 @@ CComponentBox::CComponentBox(std::vector> { comp->onSelect = std::bind(&CComponentBox::selectionChanged, this, comp); comp->assignedKey = key; - vstd::advance(key, 1); + key = vstd::next(key, 1); } selectionChanged(_components.front()); } diff --git a/client/widgets/MiscWidgets.cpp b/client/widgets/MiscWidgets.cpp index 2e443d4d5..8d1179621 100644 --- a/client/widgets/MiscWidgets.cpp +++ b/client/widgets/MiscWidgets.cpp @@ -200,7 +200,7 @@ void CMinorResDataBar::showAll(SDL_Surface * to) { CIntObject::showAll(to); - for (EGameResID i=EGameResID::WOOD; i<=EGameResID::GOLD; vstd::advance(i, 1)) + for (GameResID i=EGameResID::WOOD; i<=EGameResID::GOLD; ++i) { std::string text = std::to_string(LOCPLINT->cb->getResourceAmount(i)); diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 629f1ce3d..bed47e646 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -1103,7 +1103,7 @@ CShipyardWindow::CShipyardWindow(const TResources & cost, int state, BoatId boat build = std::make_shared(Point(42, 312), "IBUY30", CButton::tooltip(CGI->generaltexth->allTexts[598]), std::bind(&CShipyardWindow::close, this), EShortcut::GLOBAL_CONFIRM); build->addCallback(onBuy); - for(auto i = EGameResID::WOOD; i <= EGameResID::GOLD; vstd::advance(i, 1)) + for(GameResID i = EGameResID::WOOD; i <= EGameResID::GOLD; ++i) { if(cost[i] > LOCPLINT->cb->getResourceAmount(i)) { @@ -1427,7 +1427,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance * visitor, const CGObjectI for(int i = 0; i < slotsCount; i++) { - upgrade[i] = std::make_shared(Point(107 + i * 76, 171), "", CButton::tooltip(getTextForSlot(SlotID(i))), [=](){ makeDeal(SlotID(i)); }, vstd::advance_r(EShortcut::SELECT_INDEX_1, i)); + upgrade[i] = std::make_shared(Point(107 + i * 76, 171), "", CButton::tooltip(getTextForSlot(SlotID(i))), [=](){ makeDeal(SlotID(i)); }, vstd::next(EShortcut::SELECT_INDEX_1, i)); for(auto image : { "APHLF1R.DEF", "APHLF1Y.DEF", "APHLF1G.DEF" }) upgrade[i]->addImage(image); diff --git a/client/windows/InfoWindows.cpp b/client/windows/InfoWindows.cpp index 50c11e623..2843aa38c 100644 --- a/client/windows/InfoWindows.cpp +++ b/client/windows/InfoWindows.cpp @@ -95,7 +95,7 @@ CSelWindow::CSelWindow(const std::string &Text, PlayerColor player, int charperl components.push_back(comps[i]); comps[i]->onSelect = std::bind(&CSelWindow::selectionChange,this,i); if(i<8) - comps[i]->assignedKey = vstd::advance_r(EShortcut::SELECT_INDEX_1,i); + comps[i]->assignedKey = vstd::next(EShortcut::SELECT_INDEX_1,i); } CMessage::drawIWindow(this, Text, player); } diff --git a/lib/ResourceSet.cpp b/lib/ResourceSet.cpp index 8603fbc84..d571d4ea8 100644 --- a/lib/ResourceSet.cpp +++ b/lib/ResourceSet.cpp @@ -149,7 +149,7 @@ void ResourceSet::nziterator::advance() { do { - vstd::advance(cur.resType, +1); + ++cur.resType; } while(cur.resType < GameConstants::RESOURCE_QUANTITY && !(cur.resVal=rs[cur.resType])); if(cur.resType >= GameConstants::RESOURCE_QUANTITY) diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index bd9163a24..a3672b4d5 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -163,7 +163,7 @@ bool CQuest::checkQuest(const CGHeroInstance * h) const case MISSION_ARMY: return checkMissionArmy(this, h); case MISSION_RESOURCES: - for(auto i = EGameResID::WOOD; i <= EGameResID::GOLD; vstd::advance(i, +1)) //including Mithril ? + for(GameResID i = EGameResID::WOOD; i <= EGameResID::GOLD; ++i) //including Mithril ? { //Quest has no direct access to callback if(CGHeroInstance::cb->getResource(h->tempOwner, i) < static_cast(m7resources[i])) return false; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f24e0e580..6af785620 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -7029,7 +7029,7 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons ///Give resources to player TResources resources; resources[EGameResID::GOLD] = 100000; - for (auto i = EGameResID::WOOD; i < EGameResID::GOLD; vstd::advance(i, 1)) + for (GameResID i = EGameResID::WOOD; i < EGameResID::GOLD; ++i) resources[i] = 100; giveResources(player, resources);