Replace some iterator usages by for-range or algorithm.
This commit is contained in:
parent
77e3f63bb8
commit
af0f4e38fb
30 changed files with 166 additions and 224 deletions
|
@ -542,17 +542,15 @@ void FreeAi()
|
|||
*/
|
||||
static int AiRemoveFromBuilt2(PlayerAi *pai, const CUnitType &type)
|
||||
{
|
||||
std::vector<AiBuildQueue>::iterator i;
|
||||
|
||||
for (i = pai->UnitTypeBuilt.begin(); i != pai->UnitTypeBuilt.end(); ++i) {
|
||||
Assert((*i).Want);
|
||||
if (&type == (*i).Type && (*i).Made) {
|
||||
--(*i).Made;
|
||||
if (!--(*i).Want) {
|
||||
pai->UnitTypeBuilt.erase(i);
|
||||
}
|
||||
return 1;
|
||||
auto it = ranges::find_if(pai->UnitTypeBuilt,
|
||||
[&](const AiBuildQueue &q) { return q.Made && q.Type == &type; });
|
||||
if (it != pai->UnitTypeBuilt.end())
|
||||
{
|
||||
--(*it).Made;
|
||||
if (!--(*it).Want) {
|
||||
pai->UnitTypeBuilt.erase(it);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -593,13 +591,13 @@ static void AiRemoveFromBuilt(PlayerAi *pai, const CUnitType &type)
|
|||
*/
|
||||
static bool AiReduceMadeInBuilt2(PlayerAi &pai, const CUnitType &type)
|
||||
{
|
||||
std::vector<AiBuildQueue>::iterator i;
|
||||
auto it = ranges::find_if(pai.UnitTypeBuilt,
|
||||
[&](const AiBuildQueue &q) { return q.Made && q.Type == &type; });
|
||||
|
||||
for (i = pai.UnitTypeBuilt.begin(); i != pai.UnitTypeBuilt.end(); ++i) {
|
||||
if (&type == (*i).Type && (*i).Made) {
|
||||
(*i).Made--;
|
||||
return true;
|
||||
}
|
||||
if (it != pai.UnitTypeBuilt.end())
|
||||
{
|
||||
(*it).Made--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -484,8 +484,8 @@ CUnit *AiGetSuitableDepot(const CUnit &worker, const CUnit &oldDepot, CUnit **re
|
|||
}
|
||||
std::sort(depots.begin(), depots.end(), CompareDepotsByDistance(worker));
|
||||
|
||||
for (std::vector<CUnit *>::iterator it = depots.begin(); it != depots.end(); ++it) {
|
||||
CUnit &unit = **it;
|
||||
for (CUnit* unitPtr : depots) {
|
||||
CUnit &unit = *unitPtr;
|
||||
|
||||
const unsigned int tooManyWorkers = 15;
|
||||
const int range = 15;
|
||||
|
|
|
@ -148,11 +148,9 @@ static std::vector<CUnitType *> getSupplyUnits()
|
|||
}
|
||||
}
|
||||
sorted_res.push_back(besttype);
|
||||
for (std::vector<CUnitType *>::iterator i = res.begin(); i != res.end(); ++i) {
|
||||
if (*i == besttype) {
|
||||
i = res.erase(i);
|
||||
break;
|
||||
}
|
||||
auto it = ranges::find(res, besttype);
|
||||
if (it != res.end()) {
|
||||
res.erase(it);
|
||||
}
|
||||
}
|
||||
return sorted_res;
|
||||
|
@ -197,11 +195,9 @@ static std::vector<CUnitType *> getRefineryUnits()
|
|||
}
|
||||
}
|
||||
sorted_res.push_back(besttype);
|
||||
for (std::vector<CUnitType *>::iterator i = res.begin(); i != res.end(); ++i) {
|
||||
if (*i == besttype) {
|
||||
i = res.erase(i);
|
||||
break;
|
||||
}
|
||||
auto it = ranges::find(res, besttype);
|
||||
if (it != res.end()) {
|
||||
res.erase(it);
|
||||
}
|
||||
}
|
||||
return sorted_res;
|
||||
|
|
|
@ -415,9 +415,7 @@ CAnimations *AnimationsByIdent(const std::string &ident)
|
|||
|
||||
void FreeAnimations()
|
||||
{
|
||||
std::map<std::string, CAnimations *>::iterator it;
|
||||
for (it = AnimationMap.begin(); it != AnimationMap.end(); ++it) {
|
||||
CAnimations *anims = (*it).second;
|
||||
for (auto &[key, anims] : AnimationMap) {
|
||||
delete anims;
|
||||
}
|
||||
AnimationMap.clear();
|
||||
|
|
|
@ -477,8 +477,8 @@ static int WriteMapSetup(const fs::path &mapSetup, CMap &map, int writeTerrain,
|
|||
}
|
||||
}
|
||||
f->printf("\n\n");
|
||||
for (std::vector<CUnit *>::iterator it = teleporters.begin(); it != teleporters.end(); ++it) {
|
||||
CUnit &unit = **it;
|
||||
for (const CUnit* unitPtr : teleporters) {
|
||||
const CUnit &unit = *unitPtr;
|
||||
f->printf("SetTeleportDestination(%d, %d)\n", UnitNumber(unit), UnitNumber(*unit.Goal));
|
||||
}
|
||||
f->printf("\n\n");
|
||||
|
|
|
@ -172,11 +172,10 @@ public:
|
|||
}
|
||||
}
|
||||
#else
|
||||
for (std::vector<CUnit *>::iterator i(Units.begin()), end(Units.end()); i != end; ++i) {
|
||||
if ((*i) == unit) {
|
||||
Units.erase(i);
|
||||
return true;
|
||||
}
|
||||
auto it = ranges::find(Units, unit);
|
||||
if (it != Units.end()) {
|
||||
Units.erase(it);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
@ -189,11 +188,9 @@ public:
|
|||
*/
|
||||
void RemoveS(CUnit *const unit)
|
||||
{
|
||||
for (std::vector<CUnit *>::iterator i(Units.begin()), end(Units.end()); i != end; ++i) {
|
||||
if ((*i) == unit) {
|
||||
Units.erase(i);
|
||||
return;
|
||||
}
|
||||
auto it = ranges::find(Units, unit);
|
||||
if (it != Units.end()) {
|
||||
Units.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -737,11 +737,9 @@ public:
|
|||
return buildin[i].key;
|
||||
}
|
||||
}
|
||||
for (std::map<std::string, int>::iterator
|
||||
it(user.begin()), end(user.end());
|
||||
it != end; ++it) {
|
||||
if ((*it).second == index) {
|
||||
return ((*it).first).c_str();
|
||||
for (const auto &[key, value] : user) {
|
||||
if (value == index) {
|
||||
return key.c_str();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -199,6 +199,13 @@ namespace ranges
|
|||
return std::find(begin(range), end(range), value);
|
||||
}
|
||||
|
||||
template <typename Range, typename Predicate>
|
||||
auto find_if(Range &range, Predicate &&predicate)
|
||||
{
|
||||
return std::find_if(begin(range), end(range), std::forward<Predicate>(predicate));
|
||||
}
|
||||
|
||||
|
||||
template<typename Range, typename Value>
|
||||
bool consist(Range& range, const Value& value)
|
||||
{
|
||||
|
|
|
@ -103,8 +103,8 @@ void MissileType::LoadMissileSprite()
|
|||
void LoadMissileSprites()
|
||||
{
|
||||
#ifndef DYNAMIC_LOAD
|
||||
for (MissileTypeMap::iterator it = MissileTypes.begin(); it != MissileTypes.end(); ++it) {
|
||||
(*it).second->LoadMissileSprite();
|
||||
for (auto &[key, missileType] : MissileTypes) {
|
||||
missileType->LoadMissileSprite();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -669,8 +669,8 @@ void MissileHandlePierce(Missile &missile, const Vec2i &pos)
|
|||
}
|
||||
std::vector<CUnit *> units;
|
||||
Select(pos, pos, units);
|
||||
for (std::vector<CUnit *>::iterator it = units.begin(); it != units.end(); ++it) {
|
||||
CUnit &unit = **it;
|
||||
for (CUnit *unitPtr : units) {
|
||||
CUnit &unit = *unitPtr;
|
||||
|
||||
if (unit.IsAliveOnMap()
|
||||
&& (missile.Type->FriendlyFire == false || unit.IsEnemy(*missile.SourceUnit->Player))) {
|
||||
|
@ -695,8 +695,8 @@ bool MissileHandleBlocking(Missile &missile, const PixelPos &position)
|
|||
std::vector<CUnit *> blockingUnits;
|
||||
const Vec2i missilePos = Map.MapPixelPosToTilePos(position);
|
||||
Select(missilePos, missilePos, blockingUnits);
|
||||
for (std::vector<CUnit *>::iterator it = blockingUnits.begin(); it != blockingUnits.end(); ++it) {
|
||||
CUnit &unit = **it;
|
||||
for (CUnit *unitPtr : blockingUnits) {
|
||||
CUnit &unit = *unitPtr;
|
||||
// If land unit shoots at land unit, missile can be blocked by Wall units
|
||||
if (!missile.Type->IgnoreWalls && missile.SourceUnit->Type->UnitType == UnitTypeLand) {
|
||||
if (!missile.TargetUnit || missile.TargetUnit->Type->UnitType == UnitTypeLand) {
|
||||
|
@ -1227,10 +1227,9 @@ int ViewPointDistanceToMissile(const Missile &missile)
|
|||
*/
|
||||
MissileType *MissileBurningBuilding(int percent)
|
||||
{
|
||||
for (std::vector<BurningBuildingFrame *>::iterator i = BurningBuildingFrames.begin();
|
||||
i != BurningBuildingFrames.end(); ++i) {
|
||||
if (percent > (*i)->Percent) {
|
||||
return (*i)->Missile;
|
||||
for (BurningBuildingFrame *frame : BurningBuildingFrames) {
|
||||
if (percent > frame->Percent) {
|
||||
return frame->Missile;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -1307,10 +1306,8 @@ void MissileType::Init()
|
|||
// Resolve impact missiles and sounds.
|
||||
this->FiredSound.MapSound();
|
||||
this->ImpactSound.MapSound();
|
||||
for (std::vector<MissileConfig *>::iterator it = this->Impact.begin(); it != this->Impact.end(); ++it) {
|
||||
MissileConfig &mc = **it;
|
||||
|
||||
mc.MapMissile();
|
||||
for (MissileConfig *mc : this->Impact) {
|
||||
mc->MapMissile();
|
||||
}
|
||||
this->Smoke.MapMissile();
|
||||
}
|
||||
|
@ -1320,8 +1317,8 @@ void MissileType::Init()
|
|||
*/
|
||||
void InitMissileTypes()
|
||||
{
|
||||
for (MissileTypeMap::iterator it = MissileTypes.begin(); it != MissileTypes.end(); ++it) {
|
||||
(*it).second->Init();
|
||||
for (auto &[key, value] : MissileTypes) {
|
||||
value->Init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1361,8 +1358,8 @@ MissileType::~MissileType()
|
|||
*/
|
||||
void CleanMissileTypes()
|
||||
{
|
||||
for (MissileTypeMap::iterator it = MissileTypes.begin(); it != MissileTypes.end(); ++it) {
|
||||
delete it->second;
|
||||
for (auto &[key, value] : MissileTypes) {
|
||||
delete value;
|
||||
}
|
||||
MissileTypes.clear();
|
||||
}
|
||||
|
@ -1401,9 +1398,8 @@ void CleanMissiles()
|
|||
|
||||
void FreeBurningBuildingFrames()
|
||||
{
|
||||
for (std::vector<BurningBuildingFrame *>::iterator i = BurningBuildingFrames.begin();
|
||||
i != BurningBuildingFrames.end(); ++i) {
|
||||
delete *i;
|
||||
for (BurningBuildingFrame *frame : BurningBuildingFrames) {
|
||||
delete frame;
|
||||
}
|
||||
BurningBuildingFrames.clear();
|
||||
}
|
||||
|
|
|
@ -344,9 +344,8 @@ static int CclMissile(lua_State *l)
|
|||
*/
|
||||
static int CclDefineBurningBuilding(lua_State *l)
|
||||
{
|
||||
for (std::vector<BurningBuildingFrame *>::iterator i = BurningBuildingFrames.begin();
|
||||
i != BurningBuildingFrames.end(); ++i) {
|
||||
delete *i;
|
||||
for (BurningBuildingFrame *frame : BurningBuildingFrames) {
|
||||
delete frame;
|
||||
}
|
||||
BurningBuildingFrames.clear();
|
||||
|
||||
|
|
|
@ -664,8 +664,8 @@ void SocketSet::DelSocket(Socket socket)
|
|||
}
|
||||
if (socket == MaxSockFD) {
|
||||
MaxSockFD = 0;
|
||||
for (i = Sockets.begin(); i != Sockets.end(); ++i) {
|
||||
MaxSockFD = std::max(this->MaxSockFD, *i);
|
||||
for (auto &socketFd : Sockets) {
|
||||
MaxSockFD = std::max(this->MaxSockFD, socketFd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,13 @@ void CParticleManager::exit()
|
|||
|
||||
void CParticleManager::clear()
|
||||
{
|
||||
std::vector<CParticle *>::iterator i;
|
||||
for (i = particles.begin(); i != particles.end(); ++i) {
|
||||
delete *i;
|
||||
for (auto *p : particles) {
|
||||
delete p;
|
||||
}
|
||||
particles.clear();
|
||||
|
||||
for (i = new_particles.begin(); i != new_particles.end(); ++i) {
|
||||
delete *i;
|
||||
for (auto *p : new_particles) {
|
||||
delete p;
|
||||
}
|
||||
new_particles.clear();
|
||||
}
|
||||
|
@ -81,8 +80,8 @@ void CParticleManager::prepareToDraw(const CViewport &vp, std::vector<CParticle
|
|||
{
|
||||
this->vp = &vp;
|
||||
|
||||
for (std::vector<CParticle *>::iterator it = particles.begin(); it != particles.end(); ++it) {
|
||||
CParticle &particle = **it;
|
||||
for (CParticle *p : particles) {
|
||||
CParticle &particle = *p;
|
||||
if (particle.isVisible(vp)) {
|
||||
table.push_back(&particle);
|
||||
}
|
||||
|
|
|
@ -235,29 +235,23 @@ inline void ProfilePrint()
|
|||
return;
|
||||
}
|
||||
std::vector<ProfileData *> prof;
|
||||
for (std::map<const char *const, ProfileData>::iterator i = functionProfiles.begin();
|
||||
i != functionProfiles.end(); ++i) {
|
||||
ProfileData *data = &i->second;
|
||||
prof.insert(std::upper_bound(prof.begin(), prof.end(), data, compProfileData), data);
|
||||
for (auto &[key, data] : functionProfiles) {
|
||||
prof.insert(std::upper_bound(prof.begin(), prof.end(), &data, compProfileData), &data);
|
||||
}
|
||||
|
||||
FILE *fd = fopen("profile.txt", "wb");
|
||||
fprintf(fd, " total\t calls\t per\tname\n");
|
||||
|
||||
for (std::vector<ProfileData *>::iterator i = prof.begin(); i != prof.end(); ++i) {
|
||||
ProfileData *data = (*i);
|
||||
for (ProfileData *data : prof) {
|
||||
fprintf(fd, "%9.3f\t%9lu\t%9.3f\t",
|
||||
(double)data->TotalTime / frequency.QuadPart * 1000.0,
|
||||
data->Calls,
|
||||
(double)data->TotalTime / frequency.QuadPart * 1000.0 / data->Calls);
|
||||
for (std::map<const char *const, ProfileData>::iterator j =
|
||||
functionProfiles.begin(); j != functionProfiles.end(); ++j) {
|
||||
ProfileData *data2 = &j->second;
|
||||
if (data == data2) {
|
||||
fprintf(fd, "%s\n", j->first);
|
||||
for (const auto &[key, data2] : functionProfiles) {
|
||||
if (data == &data2) {
|
||||
fprintf(fd, "%s\n", key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
|
|
@ -192,8 +192,8 @@ static void EvaluateMissileLocation(const SpellActionMissileLocation &location,
|
|||
std::vector<CUnit *> table;
|
||||
Select(goalPos - offset, goalPos + offset, table);
|
||||
int count = 0;
|
||||
for (std::vector<CUnit *>::iterator it = table.begin(); it != table.end(); ++it) {
|
||||
CUnit &unit = **it;
|
||||
for (CUnit *unitPtr : table) {
|
||||
CUnit &unit = *unitPtr;
|
||||
|
||||
if (unit.Type->BoolFlag[ORGANIC_INDEX].value && unit.IsEnemy(caster)) {
|
||||
table[count++] = &unit;
|
||||
|
|
|
@ -417,10 +417,9 @@ void InitSpells()
|
|||
*/
|
||||
SpellType *SpellTypeByIdent(const std::string &ident)
|
||||
{
|
||||
for (std::vector<SpellType *>::iterator i = SpellTypeTable.begin(); i < SpellTypeTable.end(); ++i) {
|
||||
if ((*i)->Ident == ident) {
|
||||
return *i;
|
||||
}
|
||||
auto it = ranges::find_if(SpellTypeTable, [&](SpellType* spell) { return spell->Ident == ident; });
|
||||
if (it != SpellTypeTable.end()) {
|
||||
return *it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -585,8 +584,8 @@ SpellType::SpellType(int slot, const std::string &ident) :
|
|||
*/
|
||||
SpellType::~SpellType()
|
||||
{
|
||||
for (std::vector<SpellActionType *>::iterator act = Action.begin(); act != Action.end(); ++act) {
|
||||
delete *act;
|
||||
for (auto *act : Action) {
|
||||
delete act;
|
||||
}
|
||||
Action.clear();
|
||||
|
||||
|
@ -605,8 +604,8 @@ SpellType::~SpellType()
|
|||
void CleanSpells()
|
||||
{
|
||||
DebugPrint("Cleaning spells.\n");
|
||||
for (std::vector<SpellType *>::iterator i = SpellTypeTable.begin(); i < SpellTypeTable.end(); ++i) {
|
||||
delete *i;
|
||||
for (SpellType *spell : SpellTypeTable) {
|
||||
delete spell;
|
||||
}
|
||||
SpellTypeTable.clear();
|
||||
}
|
||||
|
|
|
@ -133,10 +133,8 @@ void InitConstructions()
|
|||
*/
|
||||
void LoadConstructions()
|
||||
{
|
||||
for (std::vector<CConstruction *>::iterator it = Constructions.begin();
|
||||
it != Constructions.end();
|
||||
++it) {
|
||||
(*it)->Load();
|
||||
for (CConstruction *c :Constructions) {
|
||||
c->Load();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,10 +144,8 @@ void LoadConstructions()
|
|||
void CleanConstructions()
|
||||
{
|
||||
// Free the construction table.
|
||||
for (std::vector<CConstruction *>::iterator it = Constructions.begin();
|
||||
it != Constructions.end();
|
||||
++it) {
|
||||
delete *it;
|
||||
for (CConstruction *c : Constructions) {
|
||||
delete c;
|
||||
}
|
||||
Constructions.clear();
|
||||
}
|
||||
|
@ -190,7 +186,6 @@ static int CclDefineConstruction(lua_State *l)
|
|||
// Slot identifier
|
||||
const std::string str = LuaToString(l, 1);
|
||||
CConstruction *construction = ConstructionByIdent(str);
|
||||
std::vector<CConstruction *>::iterator i;
|
||||
|
||||
if (construction == nullptr) {
|
||||
construction = new CConstruction;
|
||||
|
|
|
@ -389,11 +389,9 @@ bool IconConfig::Load()
|
|||
*/
|
||||
void LoadIcons()
|
||||
{
|
||||
for (IconMap::iterator it = Icons.begin(); it != Icons.end(); ++it) {
|
||||
CIcon &icon = *(*it).second;
|
||||
|
||||
ShowLoadProgress(_("Icons %s"), icon.G->File.c_str());
|
||||
icon.Load();
|
||||
for (auto &[key, icon] : Icons) {
|
||||
ShowLoadProgress(_("Icons %s"), icon->G->File.c_str());
|
||||
icon->Load();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,8 +400,7 @@ void LoadIcons()
|
|||
*/
|
||||
void CleanIcons()
|
||||
{
|
||||
for (IconMap::iterator it = Icons.begin(); it != Icons.end(); ++it) {
|
||||
CIcon *icon = (*it).second;
|
||||
for (auto &[key, icon] : Icons) {
|
||||
delete icon;
|
||||
}
|
||||
Icons.clear();
|
||||
|
|
|
@ -618,9 +618,8 @@ CPopup::CPopup() :
|
|||
|
||||
CPopup::~CPopup()
|
||||
{
|
||||
for (std::vector<CPopupContentType *>::iterator content = Contents.begin();
|
||||
content != Contents.end(); ++content) {
|
||||
delete *content;
|
||||
for (CPopupContentType *content : Contents) {
|
||||
delete content;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -609,10 +609,9 @@ static int CclDefinePanelContents(lua_State *l)
|
|||
LuaError(l, "'%s' invalid for DefinePanelContents" _C_ key);
|
||||
}
|
||||
}
|
||||
for (std::vector<CContentType *>::iterator content = infopanel->Contents.begin();
|
||||
content != infopanel->Contents.end(); ++content) { // Default value for invalid value.
|
||||
(*content)->Pos.x += infopanel->PosX;
|
||||
(*content)->Pos.y += infopanel->PosY;
|
||||
for (CContentType *content : infopanel->Contents) { // Default value for invalid value.
|
||||
content->Pos.x += infopanel->PosX;
|
||||
content->Pos.y += infopanel->PosY;
|
||||
}
|
||||
size_t j;
|
||||
for (j = 0; j < UI.InfoPanelContents.size(); ++j) {
|
||||
|
|
|
@ -119,9 +119,8 @@ bool IsDemoMode()
|
|||
|
||||
CUnitInfoPanel::~CUnitInfoPanel()
|
||||
{
|
||||
for (std::vector<CContentType *>::iterator content = Contents.begin();
|
||||
content != Contents.end(); ++content) {
|
||||
delete *content;
|
||||
for (CContentType *content : Contents) {
|
||||
delete content;
|
||||
}
|
||||
delete Condition;
|
||||
}
|
||||
|
@ -189,10 +188,10 @@ CUserInterface::CUserInterface() :
|
|||
*/
|
||||
CPopup *PopupByIdent(const std::string &ident)
|
||||
{
|
||||
for (std::vector<CPopup *>::iterator i = UI.ButtonPopups.begin(); i < UI.ButtonPopups.end(); ++i) {
|
||||
if ((*i)->Ident == ident) {
|
||||
return *i;
|
||||
}
|
||||
const auto it =
|
||||
ranges::find_if(UI.ButtonPopups, [&](CPopup *popup) { return popup->Ident == ident; });
|
||||
if (it != UI.ButtonPopups.end()) {
|
||||
return *it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -206,8 +205,8 @@ void InitUserInterface()
|
|||
UI.Offset480Y = (Video.Height - 480) / 2;
|
||||
|
||||
UI.LifeBarColorsInt.clear();
|
||||
for(std::vector<std::string>::iterator it = UI.LifeBarColorNames.begin(); it != UI.LifeBarColorNames.end(); ++it) {
|
||||
UI.LifeBarColorsInt.push_back(IndexToColor(GetColorIndexByName((*it).c_str())));
|
||||
for(const std::string& name : UI.LifeBarColorNames) {
|
||||
UI.LifeBarColorsInt.push_back(IndexToColor(GetColorIndexByName(name.c_str())));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -371,9 +370,8 @@ void CleanUserInterface()
|
|||
|
||||
// Info Panel
|
||||
CGraphic::Free(UI.InfoPanel.G);
|
||||
for (std::vector<CUnitInfoPanel *>::iterator panel = UI.InfoPanelContents.begin();
|
||||
panel != UI.InfoPanelContents.end(); ++panel) {
|
||||
delete *panel;
|
||||
for (CUnitInfoPanel *panel : UI.InfoPanelContents) {
|
||||
delete panel;
|
||||
}
|
||||
UI.InfoPanelContents.clear();
|
||||
|
||||
|
@ -385,9 +383,8 @@ void CleanUserInterface()
|
|||
}
|
||||
|
||||
// Button Popups
|
||||
for (std::vector<CPopup *>::iterator popup = UI.ButtonPopups.begin();
|
||||
popup != UI.ButtonPopups.end(); ++popup) {
|
||||
delete *popup;
|
||||
for (CPopup *popup : UI.ButtonPopups) {
|
||||
delete popup;
|
||||
}
|
||||
UI.ButtonPopups.clear();
|
||||
|
||||
|
@ -424,9 +421,8 @@ void CleanUserInterface()
|
|||
|
||||
void FreeButtonStyles()
|
||||
{
|
||||
std::map<std::string, ButtonStyle *>::iterator i;
|
||||
for (i = ButtonStyleHash.begin(); i != ButtonStyleHash.end(); ++i) {
|
||||
delete(*i).second;
|
||||
for (auto &[key, value] : ButtonStyleHash) {
|
||||
delete value;
|
||||
}
|
||||
ButtonStyleHash.clear();
|
||||
}
|
||||
|
|
|
@ -276,10 +276,8 @@ void PathFinderOutput::Load(lua_State *l)
|
|||
*/
|
||||
static void CclParseOrders(lua_State *l, CUnit &unit)
|
||||
{
|
||||
for (std::vector<COrderPtr>::iterator order = unit.Orders.begin();
|
||||
order != unit.Orders.end();
|
||||
++order) {
|
||||
delete *order;
|
||||
for (COrderPtr order : unit.Orders) {
|
||||
delete order;
|
||||
}
|
||||
unit.Orders.clear();
|
||||
const int n = lua_rawlen(l, -1);
|
||||
|
|
|
@ -918,9 +918,8 @@ static int CclDefineUnitType(lua_State *l)
|
|||
}
|
||||
const int subargs = lua_rawlen(l, -1);
|
||||
// Free any old restrictions if they are redefined
|
||||
for (std::vector<CBuildRestriction *>::iterator b = type->BuildingRules.begin();
|
||||
b != type->BuildingRules.end(); ++b) {
|
||||
delete *b;
|
||||
for (CBuildRestriction *b : type->BuildingRules) {
|
||||
delete b;
|
||||
}
|
||||
type->BuildingRules.clear();
|
||||
for (int k = 0; k < subargs; ++k) {
|
||||
|
@ -937,9 +936,8 @@ static int CclDefineUnitType(lua_State *l)
|
|||
}
|
||||
const int subargs = lua_rawlen(l, -1);
|
||||
// Free any old restrictions if they are redefined
|
||||
for (std::vector<CBuildRestriction *>::iterator b = type->AiBuildingRules.begin();
|
||||
b != type->AiBuildingRules.end(); ++b) {
|
||||
delete *b;
|
||||
for (CBuildRestriction *b : type->AiBuildingRules) {
|
||||
delete b;
|
||||
}
|
||||
type->AiBuildingRules.clear();
|
||||
for (int k = 0; k < subargs; ++k) {
|
||||
|
|
|
@ -3521,9 +3521,7 @@ void CleanUnits()
|
|||
// Free memory for all units in unit table.
|
||||
std::vector<CUnit *> units(UnitManager->begin(), UnitManager->end());
|
||||
|
||||
for (std::vector<CUnit *>::iterator it = units.begin(); it != units.end(); ++it) {
|
||||
CUnit *unit = *it;
|
||||
|
||||
for (CUnit *unit : units) {
|
||||
if (unit == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -373,11 +373,10 @@ void DecorationCclRegister()
|
|||
*/
|
||||
void LoadDecorations()
|
||||
{
|
||||
std::vector<Decoration>::iterator i;
|
||||
for (i = DecoSprite.SpriteArray.begin(); i != DecoSprite.SpriteArray.end(); ++i) {
|
||||
ShowLoadProgress(_("Decorations '%s'"), (*i).File.c_str());
|
||||
(*i).Sprite = CGraphic::New((*i).File, (*i).Width, (*i).Height);
|
||||
(*i).Sprite->Load();
|
||||
for (Decoration& deco : DecoSprite.SpriteArray) {
|
||||
ShowLoadProgress(_("Decorations '%s'"), deco.File.c_str());
|
||||
deco.Sprite = CGraphic::New(deco.File, deco.Width, deco.Height);
|
||||
deco.Sprite->Load();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -563,14 +563,12 @@ CUnitType::~CUnitType()
|
|||
BoolFlag.clear();
|
||||
|
||||
// Free Building Restrictions if there are any
|
||||
for (std::vector<CBuildRestriction *>::iterator b = BuildingRules.begin();
|
||||
b != BuildingRules.end(); ++b) {
|
||||
delete *b;
|
||||
for (CBuildRestriction *b : BuildingRules) {
|
||||
delete b;
|
||||
}
|
||||
BuildingRules.clear();
|
||||
for (std::vector<CBuildRestriction *>::iterator b = AiBuildingRules.begin();
|
||||
b != AiBuildingRules.end(); ++b) {
|
||||
delete *b;
|
||||
for (CBuildRestriction *b : AiBuildingRules) {
|
||||
delete b;
|
||||
}
|
||||
AiBuildingRules.clear();
|
||||
|
||||
|
@ -964,15 +962,13 @@ void InitUnitTypes(int reset_player_stats)
|
|||
type.StillFrame = GetStillFrame(type);
|
||||
|
||||
// Lookup BuildingTypes
|
||||
for (std::vector<CBuildRestriction *>::iterator b = type.BuildingRules.begin();
|
||||
b < type.BuildingRules.end(); ++b) {
|
||||
(*b)->Init();
|
||||
for (CBuildRestriction *b : type.BuildingRules) {
|
||||
b->Init();
|
||||
}
|
||||
|
||||
// Lookup AiBuildingTypes
|
||||
for (std::vector<CBuildRestriction *>::iterator b = type.AiBuildingRules.begin();
|
||||
b < type.AiBuildingRules.end(); ++b) {
|
||||
(*b)->Init();
|
||||
for (CBuildRestriction *b : type.AiBuildingRules) {
|
||||
b->Init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1103,9 +1099,8 @@ void CUnitTypeVar::Clear()
|
|||
{
|
||||
Variable.clear();
|
||||
|
||||
for (std::vector<CDecoVar *>::iterator it = DecoVar.begin();
|
||||
it != DecoVar.end(); ++it) {
|
||||
delete(*it);
|
||||
for (CDecoVar *deco : DecoVar) {
|
||||
delete deco;
|
||||
}
|
||||
DecoVar.clear();
|
||||
}
|
||||
|
|
|
@ -163,8 +163,8 @@ void CCursor::Reset() {
|
|||
*/
|
||||
void LoadCursors(const std::string &race)
|
||||
{
|
||||
for (std::vector<CCursor *>::iterator i = AllCursors.begin(); i != AllCursors.end(); ++i) {
|
||||
CCursor &cursor = **i;
|
||||
for (CCursor *cursorPtr : AllCursors) {
|
||||
CCursor &cursor = *cursorPtr;
|
||||
|
||||
// Only load cursors of this race or universal cursors.
|
||||
if (!cursor.Race.empty() && cursor.Race != race) {
|
||||
|
@ -189,8 +189,8 @@ void LoadCursors(const std::string &race)
|
|||
*/
|
||||
CCursor *CursorByIdent(const std::string &ident)
|
||||
{
|
||||
for (std::vector<CCursor *>::iterator i = AllCursors.begin(); i != AllCursors.end(); ++i) {
|
||||
CCursor &cursor = **i;
|
||||
for (CCursor *cursorPtr : AllCursors) {
|
||||
CCursor &cursor = *cursorPtr;
|
||||
|
||||
if (cursor.Ident != ident || !cursor.G->IsLoaded()) {
|
||||
continue;
|
||||
|
@ -436,9 +436,9 @@ void InitVideoCursors()
|
|||
*/
|
||||
void CleanCursors()
|
||||
{
|
||||
for (std::vector<CCursor *>::iterator i = AllCursors.begin(); i != AllCursors.end(); ++i) {
|
||||
CGraphic::Free((**i).G);
|
||||
delete *i;
|
||||
for (CCursor *cursor : AllCursors) {
|
||||
CGraphic::Free(cursor->G);
|
||||
delete cursor;
|
||||
}
|
||||
AllCursors.clear();
|
||||
|
||||
|
|
|
@ -932,9 +932,8 @@ void CFont::DynamicLoad() const
|
|||
*/
|
||||
void LoadFonts()
|
||||
{
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
font.Load();
|
||||
for (auto &[key, font] : Fonts) {
|
||||
font->Load();
|
||||
}
|
||||
|
||||
// TODO: remove this
|
||||
|
@ -946,9 +945,7 @@ void CFont::Reload() const
|
|||
{
|
||||
if (this->G) {
|
||||
FontColorGraphicMap &fontColorGraphicMap = FontColorGraphics[this];
|
||||
for (FontColorGraphicMap::iterator it = fontColorGraphicMap.begin();
|
||||
it != fontColorGraphicMap.end(); ++it) {
|
||||
CGraphic *g = it->second;
|
||||
for (auto &[key, g] : fontColorGraphicMap) {
|
||||
delete g;
|
||||
}
|
||||
fontColorGraphicMap.clear();
|
||||
|
@ -961,10 +958,8 @@ void CFont::Reload() const
|
|||
*/
|
||||
void ReloadFonts()
|
||||
{
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
|
||||
font.Reload();
|
||||
for (auto &[key, font] : Fonts) {
|
||||
font->Reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1066,16 +1061,14 @@ void CFont::Clean()
|
|||
*/
|
||||
void CleanFonts()
|
||||
{
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont *font = it->second;
|
||||
|
||||
for (auto &[key, font] : Fonts) {
|
||||
font->Clean();
|
||||
delete font;
|
||||
}
|
||||
Fonts.clear();
|
||||
|
||||
for (FontColorMap::iterator it = FontColors.begin(); it != FontColors.end(); ++it) {
|
||||
delete it->second;
|
||||
for (auto &[key, fontColor] : FontColors) {
|
||||
delete fontColor;
|
||||
}
|
||||
FontColors.clear();
|
||||
|
||||
|
|
|
@ -908,16 +908,14 @@ int Str2SdlKey(const char *str)
|
|||
{
|
||||
InitKey2Str();
|
||||
|
||||
std::map<int, std::string>::iterator i;
|
||||
for (i = Key2Str.begin(); i != Key2Str.end(); ++i) {
|
||||
if (!strcasecmp(str, (*i).second.c_str())) {
|
||||
return (*i).first;
|
||||
for (auto &[sdlkey, s] : Key2Str) {
|
||||
if (!strcasecmp(str, s.c_str())) {
|
||||
return sdlkey;
|
||||
}
|
||||
}
|
||||
std::map<std::string, int>::iterator i2;
|
||||
for (i2 = Str2Key.begin(); i2 != Str2Key.end(); ++i2) {
|
||||
if (!strcasecmp(str, (*i2).first.c_str())) {
|
||||
return (*i2).second;
|
||||
for (auto &[s, sdlkey] : Str2Key) {
|
||||
if (!strcasecmp(str, s.c_str())) {
|
||||
return sdlkey;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -551,8 +551,7 @@ void ColorCycle()
|
|||
CColorCycling &colorCycling = CColorCycling::GetInstance();
|
||||
if (colorCycling.ColorCycleAll) {
|
||||
++colorCycling.cycleCount;
|
||||
for (std::vector<SDL_Surface *>::iterator it = colorCycling.PaletteList.begin(); it != colorCycling.PaletteList.end(); ++it) {
|
||||
SDL_Surface *surface = (*it);
|
||||
for (SDL_Surface *surface : colorCycling.PaletteList) {
|
||||
ColorCycleSurface(*surface);
|
||||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
|
@ -565,9 +564,7 @@ void RestoreColorCyclingSurface()
|
|||
{
|
||||
CColorCycling &colorCycling = CColorCycling::GetInstance();
|
||||
if (colorCycling.ColorCycleAll) {
|
||||
for (std::vector<SDL_Surface *>::iterator it = colorCycling.PaletteList.begin(); it != colorCycling.PaletteList.end(); ++it) {
|
||||
SDL_Surface *surface = (*it);
|
||||
|
||||
for (SDL_Surface *surface : colorCycling.PaletteList) {
|
||||
ColorCycleSurface_Reverse(*surface, colorCycling.cycleCount);
|
||||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
|
|
|
@ -249,19 +249,18 @@ public:
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
/** swaps color a and color b in both the palette and the image */
|
||||
void swap_colors (int a, int b)
|
||||
{
|
||||
std::swap (m_palette[a], m_palette[b]);
|
||||
/** swaps color a and color b in both the palette and the image */
|
||||
void swap_colors(int a, int b)
|
||||
{
|
||||
std::swap(m_palette[a], m_palette[b]);
|
||||
|
||||
for (std::vector<int>::iterator i = m_image.begin (); i != m_image.end (); ++i)
|
||||
{
|
||||
if (*i == a)
|
||||
*i = b;
|
||||
else if (*i == b)
|
||||
*i = a;
|
||||
}
|
||||
}
|
||||
for (int &e : m_image) {
|
||||
if (e == a)
|
||||
e = b;
|
||||
else if (e == b)
|
||||
e = a;
|
||||
}
|
||||
}
|
||||
|
||||
void set_color (int i, Color c) {
|
||||
m_palette[i] = c;
|
||||
|
|
Loading…
Reference in a new issue