diff options
author | truelight <truelight@openttd.org> | 2006-08-22 15:33:35 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2006-08-22 15:33:35 +0000 |
commit | 0461d896123b918b492a3d16439bb46b041528cd (patch) | |
tree | 618708068f10739a382af83313db9c96b4744ef5 /depot.c | |
parent | 4c2abf1de53e28a5c3c6c6920efabc4653693c4c (diff) | |
download | openttd-0461d896123b918b492a3d16439bb46b041528cd.tar.xz |
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
-Codechange: use IsValidXXX where ever possible
Note: both changes to prepare for new pool system, which needs those changes.
For every pool there are 2 ugly lines, which will be removed when done
implementing new pool system.
Based on FS#13 by blathijs, partly implemented.
Diffstat (limited to 'depot.c')
-rw-r--r-- | depot.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -21,10 +21,11 @@ enum { */ static void DepotPoolNewBlock(uint start_item) { - Depot *depot; + Depot *d; - FOR_ALL_DEPOTS_FROM(depot, start_item) - depot->index = start_item++; + /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. + * TODO - This is just a temporary stage, this will be removed. */ + for (d = GetDepot(start_item); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) d->index = start_item++; } /* Initialize the town-pool */ @@ -52,16 +53,18 @@ Depot *GetDepotByTile(TileIndex tile) */ Depot *AllocateDepot(void) { - Depot *depot; + Depot *d; - FOR_ALL_DEPOTS(depot) { - if (!IsValidDepot(depot)) { - uint index = depot->index; + /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. + * TODO - This is just a temporary stage, this will be removed. */ + for (d = GetDepot(0); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) { + if (!IsValidDepot(d)) { + uint index = d->index; - memset(depot, 0, sizeof(Depot)); - depot->index = index; + memset(d, 0, sizeof(Depot)); + d->index = index; - return depot; + return d; } } @@ -116,10 +119,8 @@ static void Save_DEPT(void) Depot *depot; FOR_ALL_DEPOTS(depot) { - if (IsValidDepot(depot)) { - SlSetArrayIndex(depot->index); - SlObject(depot, _depot_desc); - } + SlSetArrayIndex(depot->index); + SlObject(depot, _depot_desc); } } |