mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
Removed vstd::advance. Added vstd::next to handle similar cases.
This commit is contained in:
parent
832e56e005
commit
a654cc2391
@ -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;
|
||||
|
12
Global.h
12
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<typename T>
|
||||
T advance_r(const T &obj, int change)
|
||||
T next(const T &obj, int change)
|
||||
{
|
||||
return static_cast<T>(static_cast<int>(obj) + change);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void advance(T &obj, int change)
|
||||
{
|
||||
obj = advance_r(obj, change);
|
||||
return static_cast<T>(static_cast<ptrdiff_t>(obj) + change);
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
|
@ -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));
|
||||
|
||||
|
@ -494,7 +494,7 @@ CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>>
|
||||
{
|
||||
comp->onSelect = std::bind(&CComponentBox::selectionChanged, this, comp);
|
||||
comp->assignedKey = key;
|
||||
vstd::advance(key, 1);
|
||||
key = vstd::next(key, 1);
|
||||
}
|
||||
selectionChanged(_components.front());
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
@ -1103,7 +1103,7 @@ CShipyardWindow::CShipyardWindow(const TResources & cost, int state, BoatId boat
|
||||
build = std::make_shared<CButton>(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<CButton>(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<CButton>(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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<int>(m7resources[i]))
|
||||
return false;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user