mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: replace for loops with endof with range-based for loops
This commit is contained in:
parent
095bdf32fe
commit
4e6d4fcf32
|
@ -2678,23 +2678,23 @@ static const SaveLoadFormat *GetSavegameFormat(const std::string &full_name, uin
|
||||||
bool has_comp_level = separator != std::string::npos;
|
bool has_comp_level = separator != std::string::npos;
|
||||||
const std::string name(full_name, 0, has_comp_level ? separator : full_name.size());
|
const std::string name(full_name, 0, has_comp_level ? separator : full_name.size());
|
||||||
|
|
||||||
for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
|
for (const auto &slf : _saveload_formats) {
|
||||||
if (slf->init_write != nullptr && name.compare(slf->name) == 0) {
|
if (slf.init_write != nullptr && name.compare(slf.name) == 0) {
|
||||||
*compression_level = slf->default_compression;
|
*compression_level = slf.default_compression;
|
||||||
if (has_comp_level) {
|
if (has_comp_level) {
|
||||||
const std::string complevel(full_name, separator + 1);
|
const std::string complevel(full_name, separator + 1);
|
||||||
|
|
||||||
/* Get the level and determine whether all went fine. */
|
/* Get the level and determine whether all went fine. */
|
||||||
size_t processed;
|
size_t processed;
|
||||||
long level = std::stol(complevel, &processed, 10);
|
long level = std::stol(complevel, &processed, 10);
|
||||||
if (processed == 0 || level != Clamp(level, slf->min_compression, slf->max_compression)) {
|
if (processed == 0 || level != Clamp(level, slf.min_compression, slf.max_compression)) {
|
||||||
SetDParamStr(0, complevel);
|
SetDParamStr(0, complevel);
|
||||||
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL);
|
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL);
|
||||||
} else {
|
} else {
|
||||||
*compression_level = level;
|
*compression_level = level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return slf;
|
return &slf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,10 @@ static DWORD WINAPI SoundThread(LPVOID)
|
||||||
SetCurrentThreadName("ottd:win-sound");
|
SetCurrentThreadName("ottd:win-sound");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (WAVEHDR *hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) {
|
for (auto &hdr : _wave_hdr) {
|
||||||
if ((hdr->dwFlags & WHDR_INQUEUE) != 0) continue;
|
if ((hdr.dwFlags & WHDR_INQUEUE) != 0) continue;
|
||||||
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4);
|
MxMixSamples(hdr.lpData, hdr.dwBufferLength / 4);
|
||||||
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
|
if (waveOutWrite(_waveout, &hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
|
||||||
MessageBox(nullptr, L"Sounds are disabled until restart.", L"waveOutWrite failed", MB_ICONINFORMATION);
|
MessageBox(nullptr, L"Sounds are disabled until restart.", L"waveOutWrite failed", MB_ICONINFORMATION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,25 +337,25 @@ int CDECL main(int argc, char *argv[])
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 'C':
|
case 'C':
|
||||||
fmt::print("args\tflags\tcommand\treplacement\n");
|
fmt::print("args\tflags\tcommand\treplacement\n");
|
||||||
for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
|
for (const auto &cs : _cmd_structs) {
|
||||||
char flags;
|
char flags;
|
||||||
if (cs->proc == EmitGender) {
|
if (cs.proc == EmitGender) {
|
||||||
flags = 'g'; // Command needs number of parameters defined by number of genders
|
flags = 'g'; // Command needs number of parameters defined by number of genders
|
||||||
} else if (cs->proc == EmitPlural) {
|
} else if (cs.proc == EmitPlural) {
|
||||||
flags = 'p'; // Command needs number of parameters defined by plural value
|
flags = 'p'; // Command needs number of parameters defined by plural value
|
||||||
} else if (cs->flags & C_DONTCOUNT) {
|
} else if (cs.flags & C_DONTCOUNT) {
|
||||||
flags = 'i'; // Command may be in the translation when it is not in base
|
flags = 'i'; // Command may be in the translation when it is not in base
|
||||||
} else {
|
} else {
|
||||||
flags = '0'; // Command needs no parameters
|
flags = '0'; // Command needs no parameters
|
||||||
}
|
}
|
||||||
fmt::print("{}\t{:c}\t\"{}\"\t\"{}\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
|
fmt::print("{}\t{:c}\t\"{}\"\t\"{}\"\n", cs.consumes, flags, cs.cmd, strstr(cs.cmd, "STRING") ? "STRING" : cs.cmd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
fmt::print("count\tdescription\tnames\n");
|
fmt::print("count\tdescription\tnames\n");
|
||||||
for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
|
for (const auto &pf : _plural_forms) {
|
||||||
fmt::print("{}\t\"{}\"\t{}\n", pf->plural_count, pf->description, pf->names);
|
fmt::print("{}\t\"{}\"\t{}\n", pf.plural_count, pf.description, pf.names);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -420,8 +420,8 @@ void EmitGender(Buffer *buffer, char *buf, int)
|
||||||
|
|
||||||
static const CmdStruct *FindCmd(const char *s, int len)
|
static const CmdStruct *FindCmd(const char *s, int len)
|
||||||
{
|
{
|
||||||
for (const CmdStruct *cs = _cmd_structs; cs != endof(_cmd_structs); cs++) {
|
for (const auto &cs : _cmd_structs) {
|
||||||
if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs;
|
if (strncmp(cs.cmd, s, len) == 0 && cs.cmd[len] == '\0') return &cs;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,8 +136,6 @@ static std::tuple<CommandCost, TileIndex> TerraformTileHeight(TerraformerState *
|
||||||
|
|
||||||
/* Recurse to neighboured corners if height difference is larger than 1 */
|
/* Recurse to neighboured corners if height difference is larger than 1 */
|
||||||
{
|
{
|
||||||
const TileIndexDiffC *ttm;
|
|
||||||
|
|
||||||
TileIndex orig_tile = tile;
|
TileIndex orig_tile = tile;
|
||||||
static const TileIndexDiffC _terraform_tilepos[] = {
|
static const TileIndexDiffC _terraform_tilepos[] = {
|
||||||
{ 1, 0}, // move to tile in SE
|
{ 1, 0}, // move to tile in SE
|
||||||
|
@ -146,8 +144,8 @@ static std::tuple<CommandCost, TileIndex> TerraformTileHeight(TerraformerState *
|
||||||
{ 0, -2} // undo last move, and move to tile in NE
|
{ 0, -2} // undo last move, and move to tile in NE
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
|
for (const auto &ttm : _terraform_tilepos) {
|
||||||
tile += ToTileIndexDiff(*ttm);
|
tile += ToTileIndexDiff(ttm);
|
||||||
|
|
||||||
if (tile >= Map::Size()) continue;
|
if (tile >= Map::Size()) continue;
|
||||||
/* Make sure we don't wrap around the map */
|
/* Make sure we don't wrap around the map */
|
||||||
|
|
|
@ -1398,8 +1398,8 @@ static inline bool RoadTypesAllowHouseHere(TileIndex t)
|
||||||
static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
|
static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
|
||||||
bool allow = false;
|
bool allow = false;
|
||||||
|
|
||||||
for (const TileIndexDiffC *ptr = tiles; ptr != endof(tiles); ++ptr) {
|
for (const auto &ptr : tiles) {
|
||||||
TileIndex cur_tile = t + ToTileIndexDiff(*ptr);
|
TileIndex cur_tile = t + ToTileIndexDiff(ptr);
|
||||||
if (!IsValidTile(cur_tile)) continue;
|
if (!IsValidTile(cur_tile)) continue;
|
||||||
|
|
||||||
if (!(IsTileType(cur_tile, MP_ROAD) || IsRoadStopTile(cur_tile))) continue;
|
if (!(IsTileType(cur_tile, MP_ROAD) || IsRoadStopTile(cur_tile))) continue;
|
||||||
|
@ -1826,21 +1826,20 @@ static bool GrowTown(Town *t)
|
||||||
TileIndex tile = t->xy; // The tile we are working with ATM
|
TileIndex tile = t->xy; // The tile we are working with ATM
|
||||||
|
|
||||||
/* Find a road that we can base the construction on. */
|
/* Find a road that we can base the construction on. */
|
||||||
const TileIndexDiffC *ptr;
|
for (const auto &ptr : _town_coord_mod) {
|
||||||
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
|
|
||||||
if (GetTownRoadBits(tile) != ROAD_NONE) {
|
if (GetTownRoadBits(tile) != ROAD_NONE) {
|
||||||
bool success = GrowTownAtRoad(t, tile);
|
bool success = GrowTownAtRoad(t, tile);
|
||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
tile = TileAdd(tile, ToTileIndexDiff(*ptr));
|
tile = TileAdd(tile, ToTileIndexDiff(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No road available, try to build a random road block by
|
/* No road available, try to build a random road block by
|
||||||
* clearing some land and then building a road there. */
|
* clearing some land and then building a road there. */
|
||||||
if (TownAllowedToBuildRoads()) {
|
if (TownAllowedToBuildRoads()) {
|
||||||
tile = t->xy;
|
tile = t->xy;
|
||||||
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
|
for (const auto &ptr : _town_coord_mod) {
|
||||||
/* Only work with plain land that not already has a house */
|
/* Only work with plain land that not already has a house */
|
||||||
if (!IsTileType(tile, MP_HOUSE) && IsTileFlat(tile)) {
|
if (!IsTileType(tile, MP_HOUSE) && IsTileFlat(tile)) {
|
||||||
if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile).Succeeded()) {
|
if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile).Succeeded()) {
|
||||||
|
@ -1850,7 +1849,7 @@ static bool GrowTown(Town *t)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tile = TileAdd(tile, ToTileIndexDiff(*ptr));
|
tile = TileAdd(tile, ToTileIndexDiff(ptr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue