mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-10 08:17:05 +00:00
Codechange: Replace FOR_ALL_OBJECTS with range-based for loops
This commit is contained in:
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)
|
||||
{
|
||||
uint32 best_dist = UINT32_MAX;
|
||||
const Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (const Object *o : Object::Iterate()) {
|
||||
if (o->type != type || o == current) continue;
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
#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.
|
||||
*/
|
||||
|
@ -173,8 +173,7 @@ void UpdateCompanyHQ(TileIndex tile, uint score)
|
||||
*/
|
||||
void UpdateObjectColours(const Company *c)
|
||||
{
|
||||
Object *obj;
|
||||
FOR_ALL_OBJECTS(obj) {
|
||||
for (Object *obj : Object::Iterate()) {
|
||||
Owner owner = GetTileOwner(obj->location.tile);
|
||||
/* Not the current owner, so colour doesn't change. */
|
||||
if (owner != c->index) continue;
|
||||
|
@ -253,8 +253,7 @@ static void InitializeWindowsAndCaches()
|
||||
}
|
||||
|
||||
/* Count number of objects per type */
|
||||
Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (Object *o : Object::Iterate()) {
|
||||
Object::IncTypeCount(o->type);
|
||||
}
|
||||
|
||||
@ -2474,8 +2473,7 @@ bool AfterLoadGame()
|
||||
|
||||
/* Add (random) colour to all objects. */
|
||||
if (IsSavegameVersionBefore(SLV_148)) {
|
||||
Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (Object *o : Object::Iterate()) {
|
||||
Owner owner = GetTileOwner(o->location.tile);
|
||||
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()
|
||||
{
|
||||
Object *o;
|
||||
|
||||
/* Write the objects */
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (Object *o : Object::Iterate()) {
|
||||
SlSetArrayIndex(o->index);
|
||||
SlObject(o, _object_desc);
|
||||
}
|
||||
@ -51,8 +49,7 @@ static void Load_OBJS()
|
||||
|
||||
static void Ptrs_OBJS()
|
||||
{
|
||||
Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (Object *o : Object::Iterate()) {
|
||||
SlObject(o, _object_desc);
|
||||
if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
|
||||
/* 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);
|
||||
|
||||
/* ... and no object is related to us. */
|
||||
const Object *o;
|
||||
FOR_ALL_OBJECTS(o) assert(o->town != this);
|
||||
for (const Object *o : Object::Iterate()) assert(o->town != this);
|
||||
|
||||
/* Check no tile is related to us. */
|
||||
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
|
||||
@ -159,8 +158,7 @@ void Town::PostDestructor(size_t index)
|
||||
UpdateNearestTownForRoadTiles(false);
|
||||
|
||||
/* Give objects a new home! */
|
||||
Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
for (Object *o : Object::Iterate()) {
|
||||
if (o->town == nullptr) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user