summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base_station_base.h37
-rw-r--r--src/saveload/afterload.cpp11
-rw-r--r--src/station.cpp5
-rw-r--r--src/station_base.h26
-rw-r--r--src/waypoint_cmd.cpp6
5 files changed, 51 insertions, 34 deletions
diff --git a/src/base_station_base.h b/src/base_station_base.h
index 70146aa82..5f99adab8 100644
--- a/src/base_station_base.h
+++ b/src/base_station_base.h
@@ -35,6 +35,30 @@ struct TileArea {
uint8 h; ///< The height of the area
};
+
+/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
+struct StationRect : public Rect {
+ enum StationRectMode
+ {
+ ADD_TEST = 0,
+ ADD_TRY,
+ ADD_FORCE
+ };
+
+ StationRect();
+ void MakeEmpty();
+ bool PtInExtendedRect(int x, int y, int distance = 0) const;
+ bool IsEmpty() const;
+ bool BeforeAddTile(TileIndex tile, StationRectMode mode);
+ bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
+ bool AfterRemoveTile(BaseStation *st, TileIndex tile);
+ bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);
+
+ static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
+
+ StationRect& operator = (Rect src);
+};
+
/** Base class for all station-ish types */
struct BaseStation : StationPool::PoolItem<&_station_pool> {
TileIndex xy; ///< Base tile of the station
@@ -57,7 +81,18 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
byte waiting_triggers; ///< Waiting triggers (NewGRF) for this station
uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
- BaseStation(TileIndex tile) : xy(tile) { }
+ TileArea train_station; ///< Tile area the train 'station' part covers
+ StationRect rect; ///< NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions
+
+ /**
+ * Initialize the base station.
+ * @param tile The location of the station sign
+ */
+ BaseStation(TileIndex tile) :
+ xy(tile),
+ train_station(INVALID_TILE, 0, 0)
+ {
+ }
virtual ~BaseStation();
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index fd0c016b2..68009a727 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -605,11 +605,14 @@ bool AfterLoadGame()
for (TileIndex t = 0; t < map_size; t++) {
switch (GetTileType(t)) {
case MP_STATION: {
- Station *st = Station::GetByTile(t);
- if (st == NULL) break;
+ BaseStation *bst = BaseStation::GetByTile(t);
- /* Set up station spread; waypoints do not have one */
- st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
+ /* Set up station spread */
+ bst->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
+
+ /* Waypoints don't have road stops/oil rigs in the old format */
+ if (!Station::IsExpected(bst)) break;
+ Station *st = Station::From(bst);
switch (GetStationType(t)) {
case STATION_TRUCK:
diff --git a/src/station.cpp b/src/station.cpp
index 96a49663b..f4138af04 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -39,7 +39,6 @@ BaseStation::~BaseStation()
Station::Station(TileIndex tile) :
SpecializedStation<Station, false>(tile),
- train_station(INVALID_TILE, 0, 0),
airport_tile(INVALID_TILE),
dock_tile(INVALID_TILE),
indtype(IT_INVALID),
@@ -423,7 +422,7 @@ bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mo
return false;
}
-bool StationRect::AfterRemoveTile(Station *st, TileIndex tile)
+bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
{
int x = TileX(tile);
int y = TileY(tile);
@@ -473,7 +472,7 @@ bool StationRect::AfterRemoveTile(Station *st, TileIndex tile)
return false; // non-empty remaining rect
}
-bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h)
+bool StationRect::AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h)
{
assert(PtInExtendedRect(TileX(tile), TileY(tile)));
assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1));
diff --git a/src/station_base.h b/src/station_base.h
index 82c13223d..7ddb92b39 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -41,29 +41,6 @@ struct GoodsEntry {
CargoList cargo; ///< The cargo packets of cargo waiting in this station
};
-/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
-struct StationRect : public Rect {
- enum StationRectMode
- {
- ADD_TEST = 0,
- ADD_TRY,
- ADD_FORCE
- };
-
- StationRect();
- void MakeEmpty();
- bool PtInExtendedRect(int x, int y, int distance = 0) const;
- bool IsEmpty() const;
- bool BeforeAddTile(TileIndex tile, StationRectMode mode);
- bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
- bool AfterRemoveTile(Station *st, TileIndex tile);
- bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
-
- static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
-
- StationRect& operator = (Rect src);
-};
-
typedef SmallVector<Industry *, 2> IndustryVector;
@@ -85,7 +62,6 @@ public:
RoadStop *bus_stops; ///< All the road stops
RoadStop *truck_stops; ///< All the truck stops
- TileArea train_station; ///< Tile area the train station part covers
TileIndex airport_tile; ///< The location of the airport
TileIndex dock_tile; ///< The location of the dock
@@ -105,8 +81,6 @@ public:
IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
- StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
-
Station(TileIndex tile = INVALID_TILE);
~Station();
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index 29880a761..30f23ac9e 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -184,6 +184,8 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1
}
wp->owner = owner;
+ wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
+
bool reserved = HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis));
MakeRailWaypoint(tile, owner, wp->index, axis, 0, GetRailType(tile));
SetRailStationReservation(tile, reserved);
@@ -249,6 +251,7 @@ CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justre
if (v != NULL) TryPathReserve(v, true);
DeallocateSpecFromStation(wp, specindex);
+ wp->rect.AfterRemoveTile(wp, tile);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
@@ -296,6 +299,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
wp->xy = tile;
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
}
+ wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
wp->string_id = STR_SV_STNAME_BUOY;
@@ -344,6 +348,8 @@ CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
MakeWaterKeepingClass(tile, GetTileOwner(tile));
MarkTileDirtyByTile(tile);
+ wp->rect.AfterRemoveTile(wp, tile);
+
wp->UpdateVirtCoord();
wp->delete_ctr = 0;
}