summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--depot.c18
-rw-r--r--depot.h21
-rw-r--r--openttd.h1
-rw-r--r--rail_cmd.c2
-rw-r--r--road_cmd.c2
-rw-r--r--water_cmd.c2
6 files changed, 23 insertions, 23 deletions
diff --git a/depot.c b/depot.c
index e092940b8..6e30eb31a 100644
--- a/depot.c
+++ b/depot.c
@@ -59,7 +59,7 @@ Depot *AllocateDepot(void)
* 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;
+ DepotID index = d->index;
memset(d, 0, sizeof(Depot));
d->index = index;
@@ -75,26 +75,18 @@ Depot *AllocateDepot(void)
}
/**
- * Delete a depot
+ * Clean up a depot
*/
-void DoDeleteDepot(TileIndex tile)
+void DestroyDepot(Depot *depot)
{
- Depot *depot;
-
- /* Get the depot */
- depot = GetDepotByTile(tile);
-
/* Clear the tile */
- DoClearSquare(tile);
-
- /* Clear the depot */
- depot->xy = 0;
+ DoClearSquare(depot->xy);
/* Clear the depot from all order-lists */
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, depot->index);
/* Delete the depot-window */
- DeleteWindowById(WC_VEHICLE_DEPOT, tile);
+ DeleteWindowById(WC_VEHICLE_DEPOT, depot->xy);
}
void InitializeDepots(void)
diff --git a/depot.h b/depot.h
index 864237cf0..45b97f503 100644
--- a/depot.h
+++ b/depot.h
@@ -14,7 +14,7 @@
struct Depot {
TileIndex xy;
TownID town_index;
- StationID index;
+ DepotID index;
};
extern MemoryPool _depot_pool;
@@ -22,7 +22,7 @@ extern MemoryPool _depot_pool;
/**
* Get the pointer to the depot with index 'index'
*/
-static inline Depot *GetDepot(uint index)
+static inline Depot *GetDepot(DepotID index)
{
return (Depot*)GetItemFromPool(&_depot_pool, index);
}
@@ -38,9 +38,9 @@ static inline uint16 GetDepotPoolSize(void)
/**
* Check if a depot really exists.
*/
-static inline bool IsValidDepot(const Depot* depot)
+static inline bool IsValidDepot(const Depot *depot)
{
- return depot->xy != 0;
+ return depot != NULL && depot->xy != 0;
}
static inline bool IsValidDepotID(uint index)
@@ -48,6 +48,14 @@ static inline bool IsValidDepotID(uint index)
return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
}
+void DestroyDepot(Depot *depot);
+
+static inline void DeleteDepot(Depot *depot)
+{
+ DestroyDepot(depot);
+ depot->xy = 0;
+}
+
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
@@ -56,7 +64,8 @@ static inline bool IsValidDepotID(uint index)
#define MIN_SERVINT_DAYS 30
#define MAX_SERVINT_DAYS 800
-/** Get the service interval domain.
+/**
+ * Get the service interval domain.
* Get the new proposed service interval for the vehicle is indeed, clamped
* within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
* @param index proposed service interval
@@ -108,10 +117,8 @@ static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh)
return ((0x4C >> direction) & tileh) != 0;
}
-
Depot *GetDepotByTile(TileIndex tile);
void InitializeDepots(void);
Depot *AllocateDepot(void);
-void DoDeleteDepot(TileIndex tile);
#endif /* DEPOT_H */
diff --git a/openttd.h b/openttd.h
index 950844eb8..938b2dcad 100644
--- a/openttd.h
+++ b/openttd.h
@@ -39,6 +39,7 @@ typedef uint16 VehicleID;
typedef uint16 StationID;
typedef uint16 TownID;
typedef uint16 IndustryID;
+typedef uint16 DepotID;
typedef byte PlayerID;
typedef byte OrderID;
typedef byte CargoID;
diff --git a/rail_cmd.c b/rail_cmd.c
index 4e623703f..e5de12b62 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -975,7 +975,7 @@ static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
if (flags & DC_EXEC) {
DiagDirection dir = GetRailDepotDirection(tile);
- DoDeleteDepot(tile);
+ DeleteDepot(GetDepotByTile(tile));
UpdateSignalsOnSegment(tile, dir);
YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
}
diff --git a/road_cmd.c b/road_cmd.c
index 6b4956a31..3f9c2a3c7 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -603,7 +603,7 @@ static int32 RemoveRoadDepot(TileIndex tile, uint32 flags)
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
- if (flags & DC_EXEC) DoDeleteDepot(tile);
+ if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile));
return _price.remove_road_depot;
}
diff --git a/water_cmd.c b/water_cmd.c
index 5d50f01ac..009bdcd34 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -103,7 +103,7 @@ static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
if (flags & DC_EXEC) {
/* Kill the depot, which is registered at the northernmost tile. Use that one */
- DoDeleteDepot(tile2 < tile ? tile2 : tile);
+ DeleteDepot(GetDepotByTile(tile2 < tile ? tile2 : tile));
MakeWater(tile);
MakeWater(tile2);