mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Removed ARRAY_COUNT in favor of std::size
This commit is contained in:
parent
506c3d29bc
commit
644f0f4b32
@ -90,10 +90,10 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
|
||||
}
|
||||
//build dwelling
|
||||
//TODO: plan building over multiple turns?
|
||||
//auto bid = ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK));
|
||||
//auto bid = ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + std::size(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK));
|
||||
|
||||
//Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm
|
||||
/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1);
|
||||
/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + std::size(unitsSource)), 1);
|
||||
if (bid.is_initialized())
|
||||
{
|
||||
auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority));
|
||||
|
16
Global.h
16
Global.h
@ -233,16 +233,12 @@ using TLockGuardRec = std::lock_guard<std::recursive_mutex>;
|
||||
#else
|
||||
# define DLL_LINKAGE DLL_IMPORT
|
||||
#endif
|
||||
|
||||
#define THROW_FORMAT(message, formatting_elems) throw std::runtime_error(boost::str(boost::format(message) % formatting_elems))
|
||||
|
||||
// can be used for counting arrays
|
||||
template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
|
||||
#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr)))
|
||||
|
||||
// old iOS SDKs compatibility
|
||||
#ifdef VCMI_IOS
|
||||
#include <AvailabilityVersions.h>
|
||||
|
||||
#define THROW_FORMAT(message, formatting_elems) throw std::runtime_error(boost::str(boost::format(message) % formatting_elems))
|
||||
|
||||
// old iOS SDKs compatibility
|
||||
#ifdef VCMI_IOS
|
||||
#include <AvailabilityVersions.h>
|
||||
|
||||
#ifndef __IPHONE_13_0
|
||||
#define __IPHONE_13_0 130000
|
||||
|
@ -260,7 +260,7 @@ void Graphics::loadErmuToPicture()
|
||||
ERMUtoPicture[idx][etp_idx] = n.String();
|
||||
idx ++;
|
||||
}
|
||||
assert (idx == ARRAY_COUNT(ERMUtoPicture));
|
||||
assert (idx == std::size(ERMUtoPicture));
|
||||
|
||||
etp_idx ++;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
||||
|
||||
assert(ret && ret->text);
|
||||
for(int i = 0;
|
||||
i < ARRAY_COUNT(sizes)
|
||||
i < std::size(sizes)
|
||||
&& sizes[i][0] < GH.screenDimensions().x - 150
|
||||
&& sizes[i][1] < GH.screenDimensions().y - 150
|
||||
&& ret->text->slider;
|
||||
|
@ -433,7 +433,7 @@ void CSpellWindow::keyPressed(const SDL_Keycode & key)
|
||||
int index = -1;
|
||||
while(schoolsOrder[++index] != selectedTab);
|
||||
index += (down ? 1 : -1);
|
||||
vstd::abetween<int>(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
||||
vstd::abetween<int>(index, 0, std::size(schoolsOrder) - 1);
|
||||
if(selectedTab != schoolsOrder[index])
|
||||
selectSchool(schoolsOrder[index]);
|
||||
break;
|
||||
@ -463,8 +463,8 @@ void CSpellWindow::keyPressed(const SDL_Keycode & key)
|
||||
static const SDL_Keycode spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};
|
||||
|
||||
int index = -1;
|
||||
while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey);
|
||||
if(index >= ARRAY_COUNT(spellSelectors))
|
||||
while(++index < std::size(spellSelectors) && spellSelectors[index] != hlpKey);
|
||||
if(index >= std::size(spellSelectors))
|
||||
return;
|
||||
|
||||
//try casting spell
|
||||
|
@ -1662,7 +1662,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
|
||||
itgflags->preload();
|
||||
|
||||
//printing flags
|
||||
for(int g = 0; g < ARRAY_COUNT(fields); ++g) //by lines
|
||||
for(int g = 0; g < std::size(fields); ++g) //by lines
|
||||
{
|
||||
for(int b=0; b<(tgi .* fields[g]).size(); ++b) //by places (1st, 2nd, ...)
|
||||
{
|
||||
|
@ -2053,7 +2053,7 @@ UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance &stack) const
|
||||
if(h && map->getTile(h->visitablePos()).visitableObjects.front()->ID == Obj::HILL_FORT)
|
||||
{
|
||||
static const int costModifiers[] = {0, 25, 50, 75, 100}; //we get cheaper upgrades depending on level
|
||||
const int costModifier = costModifiers[std::min<int>(std::max((int)base->getLevel() - 1, 0), ARRAY_COUNT(costModifiers) - 1)];
|
||||
const int costModifier = costModifiers[std::min<int>(std::max((int)base->getLevel() - 1, 0), std::size(costModifiers) - 1)];
|
||||
|
||||
for(const auto & nid : base->upgrades)
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
|
||||
EResType::ARCHIVE_VID,
|
||||
EResType::ARCHIVE_SND,
|
||||
EResType::ARCHIVE_ZIP };
|
||||
static const std::set<EResType::Type> initialTypes(initArray, initArray + ARRAY_COUNT(initArray));
|
||||
static const std::set<EResType::Type> initialTypes(initArray, initArray + std::size(initArray));
|
||||
|
||||
assert(bfs::is_directory(baseDirectory));
|
||||
std::unordered_map<ResourceID, bfs::path> fileList;
|
||||
|
@ -176,7 +176,7 @@ CTerrainViewPatternConfig::CTerrainViewPatternConfig()
|
||||
{
|
||||
const JsonNode config(ResourceID("config/terrainViewPatterns.json"));
|
||||
static const std::string patternTypes[] = { "terrainView", "terrainType" };
|
||||
for (int i = 0; i < ARRAY_COUNT(patternTypes); ++i)
|
||||
for (int i = 0; i < std::size(patternTypes); ++i)
|
||||
{
|
||||
const auto& patternsVec = config[patternTypes[i]].Vector();
|
||||
for (const auto& ptrnNode : patternsVec)
|
||||
|
@ -274,11 +274,11 @@ void TreasurePlacer::addAllPossibleObjects()
|
||||
}
|
||||
else if(creaturesAmount <= 50)
|
||||
{
|
||||
creaturesAmount = boost::math::round(creaturesAmount / 5) * 5;
|
||||
creaturesAmount = std::round(creaturesAmount / 5) * 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
creaturesAmount = boost::math::round(creaturesAmount / 10) * 10;
|
||||
creaturesAmount = std::round(creaturesAmount / 10) * 10;
|
||||
}
|
||||
return static_cast<int>(creaturesAmount);
|
||||
};
|
||||
|
@ -210,7 +210,7 @@ public:
|
||||
template < typename T, typename std::enable_if < std::is_array<T>::value, int >::type = 0 >
|
||||
void load(T &data)
|
||||
{
|
||||
ui32 size = ARRAY_COUNT(data);
|
||||
ui32 size = std::size(data);
|
||||
for(ui32 i = 0; i < size; i++)
|
||||
load(data[i]);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public:
|
||||
template < typename T, typename std::enable_if < std::is_array<T>::value, int >::type = 0 >
|
||||
void save(const T &data)
|
||||
{
|
||||
ui32 size = ARRAY_COUNT(data);
|
||||
ui32 size = std::size(data);
|
||||
for(ui32 i=0; i < size; i++)
|
||||
*this & data[i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user