summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-02 16:20:44 +0000
committerrubidium <rubidium@openttd.org>2009-12-02 16:20:44 +0000
commit81062163a25497e9d83fd354b53234d1796f675d (patch)
tree207947eb4a906654b373c62ba6b6fca2fbe96727
parent1c65150d6d30e460d1615c907e9c403d45a518ed (diff)
downloadopenttd-81062163a25497e9d83fd354b53234d1796f675d.tar.xz
(svn r18377) -Codechange: add 'cache' of the tile area of truck and bus stops.
-rw-r--r--src/saveload/station_sl.cpp6
-rw-r--r--src/station.cpp29
-rw-r--r--src/station_base.h3
-rw-r--r--src/station_cmd.cpp29
-rw-r--r--src/station_type.h16
5 files changed, 75 insertions, 8 deletions
diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
index 1e0f6d887..6c52e7cf6 100644
--- a/src/saveload/station_sl.cpp
+++ b/src/saveload/station_sl.cpp
@@ -98,6 +98,12 @@ void AfterLoadStations()
st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
}
+ if (Station::IsExpected(st)) {
+ Station *sta = Station::From(st);
+ for (const RoadStop *rs = sta->bus_stops; rs != NULL; rs = rs->next) sta->bus_station.Add(rs->xy);
+ for (const RoadStop *rs = sta->truck_stops; rs != NULL; rs = rs->next) sta->truck_station.Add(rs->xy);
+ }
+
StationUpdateAnimTriggers(st);
}
}
diff --git a/src/station.cpp b/src/station.cpp
index f1bf4b2bd..09204ec0a 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -38,6 +38,8 @@ BaseStation::~BaseStation()
Station::Station(TileIndex tile) :
SpecializedStation<Station, false>(tile),
+ bus_station(INVALID_TILE, 0, 0),
+ truck_station(INVALID_TILE, 0, 0),
airport_tile(INVALID_TILE),
dock_tile(INVALID_TILE),
indtype(IT_INVALID),
@@ -511,6 +513,33 @@ TileArea::TileArea(TileIndex start, TileIndex end)
this->h = ey - sy + 1;
}
+void TileArea::Add(TileIndex to_add)
+{
+ if (this->tile == INVALID_TILE) {
+ this->tile = to_add;
+ this->w = 1;
+ this->h = 1;
+ return;
+ }
+
+ uint sx = TileX(this->tile);
+ uint sy = TileY(this->tile);
+ uint ex = sx + this->w - 1;
+ uint ey = sy + this->h - 1;
+
+ uint ax = TileX(to_add);
+ uint ay = TileY(to_add);
+
+ sx = min(ax, sx);
+ sy = min(ay, sy);
+ ex = max(ax, ex);
+ ey = max(ay, ey);
+
+ this->tile = TileXY(sx, sy);
+ this->w = ex - sx + 1;
+ this->h = ey - sy + 1;
+}
+
void InitializeStations()
{
diff --git a/src/station_base.h b/src/station_base.h
index b912a4357..cdf06c0d7 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -67,7 +67,10 @@ public:
}
RoadStop *bus_stops; ///< All the road stops
+ TileArea bus_station; ///< Tile area the bus 'station' part covers
RoadStop *truck_stops; ///< All the truck stops
+ TileArea truck_station; ///< Tile area the truck 'station' part covers
+
TileIndex airport_tile; ///< The location of the airport
TileIndex dock_tile; ///< The location of the dock
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 45a534733..347c57dec 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -397,12 +397,12 @@ void Station::GetTileArea(TileArea *ta, StationType type) const
return;
case STATION_TRUCK:
- ta->tile = this->truck_stops != NULL ? this->truck_stops->xy : INVALID_TILE;
- break;
+ *ta = this->truck_station;
+ return;
case STATION_BUS:
- ta->tile = this->bus_stops != NULL ? this->bus_stops->xy : INVALID_TILE;
- break;
+ *ta = this->bus_station;
+ return;
case STATION_DOCK:
case STATION_OILRIG:
@@ -1212,7 +1212,7 @@ restart:
}
}
} else {
- ta.tile = INVALID_TILE;
+ ta.Clear();
}
st->train_station = ta;
@@ -1427,9 +1427,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
if (flags & DC_EXEC) {
st->rect.AfterRemoveRect(st, st->train_station.tile, st->train_station.w, st->train_station.h);
- st->train_station.tile = INVALID_TILE;
- st->train_station.w = 0;
- st->train_station.h = 0;
+ st->train_station.Clear();
st->facilities &= ~FACIL_TRAIN;
@@ -1626,6 +1624,12 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
RoadStop **currstop = FindRoadStopSpot(type, st);
*currstop = road_stop;
+ if (type) {
+ st->truck_station.Add(tile);
+ } else {
+ st->bus_station.Add(tile);
+ }
+
/* initialize an empty station */
st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
@@ -1735,6 +1739,15 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
st->UpdateVirtCoord();
st->RecomputeIndustriesNear();
DeleteStationIfEmpty(st);
+
+ /* Update the tile area of the truck/bus stop */
+ if (is_truck) {
+ st->truck_station.Clear();
+ for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) st->truck_station.Add(rs->xy);
+ } else {
+ st->bus_station.Clear();
+ for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) st->bus_station.Add(rs->xy);
+ }
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);
diff --git a/src/station_type.h b/src/station_type.h
index 2784f123b..769455d20 100644
--- a/src/station_type.h
+++ b/src/station_type.h
@@ -114,6 +114,22 @@ struct TileArea {
TileIndex tile; ///< The base tile of the area
uint8 w; ///< The width of the area
uint8 h; ///< The height of the area
+
+ /**
+ * Add a single tile to a tile area; enlarge if needed.
+ * @param to_add The tile to add
+ */
+ void Add(TileIndex to_add);
+
+ /**
+ * Clears the 'tile area', i.e. make the tile invalid.
+ */
+ void Clear()
+ {
+ this->tile = INVALID_TILE;
+ this->w = 0;
+ this->h = 0;
+ }
};
/** List of stations */