Codechange: Replace FOR_ALL_OBJECTS with range-based for loops

pull/128/head
glx 5 years ago committed by Niels Martin Hansen
parent 11f178a312
commit 514565fad6

@ -186,8 +186,7 @@ static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, Obj
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current) static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
{ {
uint32 best_dist = UINT32_MAX; uint32 best_dist = UINT32_MAX;
const Object *o; for (const Object *o : Object::Iterate()) {
FOR_ALL_OBJECTS(o) {
if (o->type != type || o == current) continue; if (o->type != type || o == current) continue;
best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile)); best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));

@ -78,9 +78,6 @@ protected:
static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
}; };
#define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
#define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
/** /**
* Keeps track of removed objects during execution/testruns of commands. * Keeps track of removed objects during execution/testruns of commands.
*/ */

@ -173,8 +173,7 @@ void UpdateCompanyHQ(TileIndex tile, uint score)
*/ */
void UpdateObjectColours(const Company *c) void UpdateObjectColours(const Company *c)
{ {
Object *obj; for (Object *obj : Object::Iterate()) {
FOR_ALL_OBJECTS(obj) {
Owner owner = GetTileOwner(obj->location.tile); Owner owner = GetTileOwner(obj->location.tile);
/* Not the current owner, so colour doesn't change. */ /* Not the current owner, so colour doesn't change. */
if (owner != c->index) continue; if (owner != c->index) continue;

@ -253,8 +253,7 @@ static void InitializeWindowsAndCaches()
} }
/* Count number of objects per type */ /* Count number of objects per type */
Object *o; for (Object *o : Object::Iterate()) {
FOR_ALL_OBJECTS(o) {
Object::IncTypeCount(o->type); Object::IncTypeCount(o->type);
} }
@ -2474,8 +2473,7 @@ bool AfterLoadGame()
/* Add (random) colour to all objects. */ /* Add (random) colour to all objects. */
if (IsSavegameVersionBefore(SLV_148)) { if (IsSavegameVersionBefore(SLV_148)) {
Object *o; for (Object *o : Object::Iterate()) {
FOR_ALL_OBJECTS(o) {
Owner owner = GetTileOwner(o->location.tile); Owner owner = GetTileOwner(o->location.tile);
o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1; o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
} }

@ -31,10 +31,8 @@ static const SaveLoad _object_desc[] = {
static void Save_OBJS() static void Save_OBJS()
{ {
Object *o;
/* Write the objects */ /* Write the objects */
FOR_ALL_OBJECTS(o) { for (Object *o : Object::Iterate()) {
SlSetArrayIndex(o->index); SlSetArrayIndex(o->index);
SlObject(o, _object_desc); SlObject(o, _object_desc);
} }
@ -51,8 +49,7 @@ static void Load_OBJS()
static void Ptrs_OBJS() static void Ptrs_OBJS()
{ {
Object *o; for (Object *o : Object::Iterate()) {
FOR_ALL_OBJECTS(o) {
SlObject(o, _object_desc); SlObject(o, _object_desc);
if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) { if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
/* Due to a small bug stale objects could remain. */ /* Due to a small bug stale objects could remain. */

@ -115,8 +115,7 @@ Town::~Town()
for (const Industry *i : Industry::Iterate()) assert(i->town != this); for (const Industry *i : Industry::Iterate()) assert(i->town != this);
/* ... and no object is related to us. */ /* ... and no object is related to us. */
const Object *o; for (const Object *o : Object::Iterate()) assert(o->town != this);
FOR_ALL_OBJECTS(o) assert(o->town != this);
/* Check no tile is related to us. */ /* Check no tile is related to us. */
for (TileIndex tile = 0; tile < MapSize(); ++tile) { for (TileIndex tile = 0; tile < MapSize(); ++tile) {
@ -159,8 +158,7 @@ void Town::PostDestructor(size_t index)
UpdateNearestTownForRoadTiles(false); UpdateNearestTownForRoadTiles(false);
/* Give objects a new home! */ /* Give objects a new home! */
Object *o; for (Object *o : Object::Iterate()) {
FOR_ALL_OBJECTS(o) {
if (o->town == nullptr) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX); if (o->town == nullptr) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX);
} }
} }

Loading…
Cancel
Save