1
0
Fork 0

(svn r16947) -Codechange: use TileArea instead of train_tile, trainst_w and trainst_h.

release/1.0
rubidium 2009-07-25 08:54:19 +00:00
parent 59c48fee8b
commit 7440ec7a73
13 changed files with 109 additions and 126 deletions

View File

@ -179,9 +179,9 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
case OT_GOTO_STATION: { case OT_GOTO_STATION: {
const Station *st = ::Station::Get(order->GetDestination()); const Station *st = ::Station::Get(order->GetDestination());
if (st->train_tile != INVALID_TILE) { if (st->train_station.tile != INVALID_TILE) {
for (uint i = 0; i < st->trainst_w; i++) { for (uint i = 0; i < st->train_station.w; i++) {
TileIndex t = st->train_tile + TileDiffXY(i, 0); TileIndex t = st->train_station.tile + TileDiffXY(i, 0);
if (st->TileBelongsToRailStation(t)) return t; if (st->TileBelongsToRailStation(t)) return t;
} }
} else if (st->dock_tile != INVALID_TILE) { } else if (st->dock_tile != INVALID_TILE) {

View File

@ -25,6 +25,11 @@ struct StationSpecList {
/** Represents the covered area */ /** Represents the covered area */
struct TileArea { struct TileArea {
/** Just construct this tile area */
TileArea() {}
/** Construct this tile area with some set values */
TileArea(TileIndex tile, uint8 w, uint8 h) : tile(tile), w(w), h(h) {}
TileIndex tile; ///< The base tile of the area TileIndex tile; ///< The base tile of the area
uint8 w; ///< The width of the area uint8 w; ///< The width of the area
uint8 h; ///< The height of the area uint8 h; ///< The height of the area

View File

@ -628,7 +628,7 @@ static const SpriteGroup *StationResolveReal(const ResolverObject *object, const
break; break;
} }
if (HasBit(statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->trainst_w + st->trainst_h); if (HasBit(statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h);
cargo = min(0xfff, cargo); cargo = min(0xfff, cargo);
if (cargo > statspec->cargo_threshold) { if (cargo > statspec->cargo_threshold) {

View File

@ -1404,7 +1404,7 @@ static TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
switch (v->type) { switch (v->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: return st->train_tile; case VEH_TRAIN: return st->train_station.tile;
case VEH_AIRCRAFT: return st->airport_tile; case VEH_AIRCRAFT: return st->airport_tile;
case VEH_SHIP: return st->dock_tile; case VEH_SHIP: return st->dock_tile;
case VEH_ROAD: return st->GetPrimaryRoadStop(RoadVehicle::From(v))->xy; case VEH_ROAD: return st->GetPrimaryRoadStop(RoadVehicle::From(v))->xy;

View File

@ -83,7 +83,7 @@ void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagD
/** /**
* Calculates the tile of given station that is closest to a given tile * Calculates the tile of given station that is closest to a given tile
* for this we assume the station is a rectangle, * for this we assume the station is a rectangle,
* as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h) * as defined by its tile are (st->train_station)
* @param station The station to calculate the distance to * @param station The station to calculate the distance to
* @param tile The tile from where to calculate the distance * @param tile The tile from where to calculate the distance
* @return The closest station tile to the given tile. * @return The closest station tile to the given tile.
@ -96,12 +96,12 @@ static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile
const Station *st = Station::From(bst); const Station *st = Station::From(bst);
/* If the rail station is (temporarily) not present, use the station sign to drive near the station */ /* If the rail station is (temporarily) not present, use the station sign to drive near the station */
if (st->train_tile == INVALID_TILE) return st->xy; if (st->train_station.tile == INVALID_TILE) return st->xy;
uint minx = TileX(st->train_tile); // topmost corner of station uint minx = TileX(st->train_station.tile); // topmost corner of station
uint miny = TileY(st->train_tile); uint miny = TileY(st->train_station.tile);
uint maxx = minx + st->trainst_w - 1; // lowermost corner of station uint maxx = minx + st->train_station.w - 1; // lowermost corner of station
uint maxy = miny + st->trainst_h - 1; uint maxy = miny + st->train_station.h - 1;
/* we are going the aim for the x coordinate of the closest corner /* we are going the aim for the x coordinate of the closest corner
* but if we are between those coordinates, we will aim for our own x coordinate */ * but if we are between those coordinates, we will aim for our own x coordinate */

View File

@ -387,17 +387,17 @@ bool AfterLoadGame()
if (CheckSavegameVersion(2)) { if (CheckSavegameVersion(2)) {
Station *st; Station *st;
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (st->train_tile != 0 && st->trainst_h == 0) { if (st->train_station.tile != 0 && st->train_station.h == 0) {
uint n = _savegame_type == SGT_OTTD ? 4 : 3; // OTTD uses 4 bits per dimensions, TTD 3 bits uint n = _savegame_type == SGT_OTTD ? 4 : 3; // OTTD uses 4 bits per dimensions, TTD 3 bits
uint w = GB(st->trainst_w, n, n); uint w = GB(st->train_station.w, n, n);
uint h = GB(st->trainst_w, 0, n); uint h = GB(st->train_station.w, 0, n);
if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h); if (GetRailStationAxis(st->train_station.tile) != AXIS_X) Swap(w, h);
st->trainst_w = w; st->train_station.w = w;
st->trainst_h = h; st->train_station.h = h;
assert(GetStationIndex(st->train_tile + TileDiffXY(w - 1, h - 1)) == st->index); assert(GetStationIndex(st->train_station.tile + TileDiffXY(w - 1, h - 1)) == st->index);
} }
} }
} }
@ -452,9 +452,9 @@ bool AfterLoadGame()
/* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */ /* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
Station *st; Station *st;
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (st->airport_tile == 0) st->airport_tile = INVALID_TILE; if (st->airport_tile == 0) st->airport_tile = INVALID_TILE;
if (st->dock_tile == 0) st->dock_tile = INVALID_TILE; if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
if (st->train_tile == 0) st->train_tile = INVALID_TILE; if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
} }
/* the same applies to Company::location_of_HQ */ /* the same applies to Company::location_of_HQ */

View File

@ -772,10 +772,10 @@ static const OldChunks station_chunk[] = {
OCL_VAR ( OC_UINT32, 1, &_old_town_index ), OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
OCL_NULL( 4 ), ///< bus/lorry tile OCL_NULL( 4 ), ///< bus/lorry tile
OCL_SVAR( OC_TILE, Station, train_tile ), OCL_SVAR( OC_TILE, Station, train_station.tile ),
OCL_SVAR( OC_TILE, Station, airport_tile ), OCL_SVAR( OC_TILE, Station, airport_tile ),
OCL_SVAR( OC_TILE, Station, dock_tile ), OCL_SVAR( OC_TILE, Station, dock_tile ),
OCL_SVAR( OC_UINT8, Station, trainst_w ), OCL_SVAR( OC_UINT8, Station, train_station.w ),
OCL_NULL( 1 ), ///< sort-index, no longer in use OCL_NULL( 1 ), ///< sort-index, no longer in use
OCL_NULL( 2 ), ///< sign-width, no longer in use OCL_NULL( 2 ), ///< sign-width, no longer in use

View File

@ -123,15 +123,15 @@ static const SaveLoad _old_station_desc[] = {
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDNULL(4, 0, 5), ///< bus/lorry tile SLE_CONDNULL(4, 0, 5), ///< bus/lorry tile
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Station, train_station.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION), SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_REF(Station, town, REF_TOWN), SLE_REF(Station, town, REF_TOWN),
SLE_VAR(Station, trainst_w, SLE_UINT8), SLE_VAR(Station, train_station.w, SLE_UINT8),
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), SLE_CONDVAR(Station, train_station.h, SLE_UINT8, 2, SL_MAX_VERSION),
SLE_CONDNULL(1, 0, 3), ///< alpha_order SLE_CONDNULL(1, 0, 3), ///< alpha_order
@ -299,9 +299,9 @@ static const SaveLoad _station_desc[] = {
SLE_WRITEBYTE(Station, facilities, FACIL_NONE), SLE_WRITEBYTE(Station, facilities, FACIL_NONE),
SLE_ST_INCLUDE(), SLE_ST_INCLUDE(),
SLE_VAR(Station, train_tile, SLE_UINT32), SLE_VAR(Station, train_station.tile, SLE_UINT32),
SLE_VAR(Station, trainst_w, SLE_UINT8), SLE_VAR(Station, train_station.w, SLE_UINT8),
SLE_VAR(Station, trainst_h, SLE_UINT8), SLE_VAR(Station, train_station.h, SLE_UINT8),
SLE_REF(Station, bus_stops, REF_ROADSTOPS), SLE_REF(Station, bus_stops, REF_ROADSTOPS),
SLE_REF(Station, truck_stops, REF_ROADSTOPS), SLE_REF(Station, truck_stops, REF_ROADSTOPS),

View File

@ -39,7 +39,7 @@ BaseStation::~BaseStation()
Station::Station(TileIndex tile) : Station::Station(TileIndex tile) :
SpecializedStation<Station, false>(tile), SpecializedStation<Station, false>(tile),
train_tile(INVALID_TILE), train_station(INVALID_TILE, 0, 0),
airport_tile(INVALID_TILE), airport_tile(INVALID_TILE),
dock_tile(INVALID_TILE), dock_tile(INVALID_TILE),
indtype(IT_INVALID), indtype(IT_INVALID),
@ -156,7 +156,7 @@ void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
void Station::MarkTilesDirty(bool cargo_change) const void Station::MarkTilesDirty(bool cargo_change) const
{ {
TileIndex tile = this->train_tile; TileIndex tile = this->train_station.tile;
int w, h; int w, h;
if (tile == INVALID_TILE) return; if (tile == INVALID_TILE) return;
@ -170,8 +170,8 @@ void Station::MarkTilesDirty(bool cargo_change) const
if (this->num_specs == 0) return; if (this->num_specs == 0) return;
} }
for (h = 0; h < trainst_h; h++) { for (h = 0; h < train_station.h; h++) {
for (w = 0; w < trainst_w; w++) { for (w = 0; w < train_station.w; w++) {
if (this->TileBelongsToRailStation(tile)) { if (this->TileBelongsToRailStation(tile)) {
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -226,13 +226,13 @@ uint Station::GetCatchmentRadius() const
uint ret = CA_NONE; uint ret = CA_NONE;
if (_settings_game.station.modified_catchment) { if (_settings_game.station.modified_catchment) {
if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS); if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK); if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
if (this->train_tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN); if (this->train_station.tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK); if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
if (this->airport_tile != INVALID_TILE) ret = max<uint>(ret, this->Airport()->catchment); if (this->airport_tile != INVALID_TILE) ret = max<uint>(ret, this->Airport()->catchment);
} else { } else {
if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_tile != INVALID_TILE || this->dock_tile != INVALID_TILE || this->airport_tile != INVALID_TILE) { if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_station.tile != INVALID_TILE || this->dock_tile != INVALID_TILE || this->airport_tile != INVALID_TILE) {
ret = CA_UNMODIFIED; ret = CA_UNMODIFIED;
} }
} }

View File

@ -83,11 +83,11 @@ public:
return GetAirport(airport_type); return GetAirport(airport_type);
} }
RoadStop *bus_stops; RoadStop *bus_stops; ///< All the road stops
RoadStop *truck_stops; RoadStop *truck_stops; ///< All the truck stops
TileIndex train_tile; TileArea train_station; ///< Tile area the train station part covers
TileIndex airport_tile; TileIndex airport_tile; ///< The location of the airport
TileIndex dock_tile; TileIndex dock_tile; ///< The location of the dock
IndustryType indtype; ///< Industry type to get the name from IndustryType indtype; ///< Industry type to get the name from
@ -97,9 +97,6 @@ public:
byte time_since_unload; byte time_since_unload;
byte airport_type; byte airport_type;
/* trainstation width/height */
byte trainst_w, trainst_h;
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
byte last_vehicle_type; byte last_vehicle_type;

View File

@ -370,9 +370,7 @@ void Station::GetTileArea(TileArea *ta, StationType type) const
{ {
switch (type) { switch (type) {
case STATION_RAIL: case STATION_RAIL:
ta->tile = this->train_tile; *ta = this->train_station;
ta->w = this->trainst_w;
ta->h = this->trainst_h;
return; return;
case STATION_AIRPORT: case STATION_AIRPORT:
@ -733,39 +731,39 @@ static bool CanExpandRailStation(const Station *st, TileArea &cur_ta, Axis axis)
if (_settings_game.station.nonuniform_stations) { if (_settings_game.station.nonuniform_stations) {
/* determine new size of train station region.. */ /* determine new size of train station region.. */
int x = min(TileX(st->train_tile), TileX(cur_ta.tile)); int x = min(TileX(st->train_station.tile), TileX(cur_ta.tile));
int y = min(TileY(st->train_tile), TileY(cur_ta.tile)); int y = min(TileY(st->train_station.tile), TileY(cur_ta.tile));
new_ta.w = max(TileX(st->train_tile) + new_ta.w, TileX(cur_ta.tile) + cur_ta.w) - x; new_ta.w = max(TileX(st->train_station.tile) + new_ta.w, TileX(cur_ta.tile) + cur_ta.w) - x;
new_ta.h = max(TileY(st->train_tile) + new_ta.h, TileY(cur_ta.tile) + cur_ta.h) - y; new_ta.h = max(TileY(st->train_station.tile) + new_ta.h, TileY(cur_ta.tile) + cur_ta.h) - y;
new_ta.tile = TileXY(x, y); new_ta.tile = TileXY(x, y);
} else { } else {
/* do not allow modifying non-uniform stations, /* do not allow modifying non-uniform stations,
* the uniform-stations code wouldn't handle it well */ * the uniform-stations code wouldn't handle it well */
BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) BEGIN_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED; _error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
return false; return false;
} }
END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) END_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
/* check so the orientation is the same */ /* check so the orientation is the same */
if (GetRailStationAxis(st->train_tile) != axis) { if (GetRailStationAxis(st->train_station.tile) != axis) {
_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED; _error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
return false; return false;
} }
/* check if the new station adjoins the old station in either direction */ /* check if the new station adjoins the old station in either direction */
if (new_ta.w == cur_ta.w && st->train_tile == cur_ta.tile + TileDiffXY(0, cur_ta.h)) { if (new_ta.w == cur_ta.w && st->train_station.tile == cur_ta.tile + TileDiffXY(0, cur_ta.h)) {
/* above */ /* above */
new_ta.h += cur_ta.h; new_ta.h += cur_ta.h;
} else if (new_ta.w == cur_ta.w && st->train_tile == cur_ta.tile - TileDiffXY(0, new_ta.h)) { } else if (new_ta.w == cur_ta.w && st->train_station.tile == cur_ta.tile - TileDiffXY(0, new_ta.h)) {
/* below */ /* below */
new_ta.tile -= TileDiffXY(0, new_ta.h); new_ta.tile -= TileDiffXY(0, new_ta.h);
new_ta.h += cur_ta.h; new_ta.h += cur_ta.h;
} else if (new_ta.h == cur_ta.h && st->train_tile == cur_ta.tile + TileDiffXY(cur_ta.w, 0)) { } else if (new_ta.h == cur_ta.h && st->train_station.tile == cur_ta.tile + TileDiffXY(cur_ta.w, 0)) {
/* to the left */ /* to the left */
new_ta.w += cur_ta.w; new_ta.w += cur_ta.w;
} else if (new_ta.h == cur_ta.h && st->train_tile == cur_ta.tile - TileDiffXY(new_ta.w, 0)) { } else if (new_ta.h == cur_ta.h && st->train_station.tile == cur_ta.tile - TileDiffXY(new_ta.w, 0)) {
/* to the right */ /* to the right */
new_ta.tile -= TileDiffXY(new_ta.w, 0); new_ta.tile -= TileDiffXY(new_ta.w, 0);
new_ta.w += cur_ta.w; new_ta.w += cur_ta.w;
@ -872,7 +870,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR; if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
/* these values are those that will be stored in train_tile and station_platforms */ /* these values are those that will be stored in train_tile and station_platforms */
TileArea new_location = { tile_org, w_org, h_org }; TileArea new_location(tile_org, w_org, h_org);
/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
StationID est = INVALID_STATION; StationID est = INVALID_STATION;
@ -922,7 +920,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
if (st->owner != _current_company) if (st->owner != _current_company)
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION); return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION);
if (st->train_tile != INVALID_TILE) { if (st->train_station.tile != INVALID_TILE) {
/* check if we want to expanding an already existing station? */ /* check if we want to expanding an already existing station? */
if (!_settings_game.station.join_stations) if (!_settings_game.station.join_stations)
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD); return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD);
@ -982,12 +980,9 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL); ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL);
if (CmdFailed(ret)) return ret; if (CmdFailed(ret)) return ret;
st->train_tile = new_location.tile; st->train_station = new_location;
st->AddFacility(FACIL_TRAIN, new_location.tile); st->AddFacility(FACIL_TRAIN, new_location.tile);
st->trainst_w = new_location.w;
st->trainst_h = new_location.h;
st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY); st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
if (statspec != NULL) { if (statspec != NULL) {
@ -1075,58 +1070,54 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
static void MakeRailStationAreaSmaller(Station *st) static void MakeRailStationAreaSmaller(Station *st)
{ {
uint w = st->trainst_w; TileArea ta = st->train_station;
uint h = st->trainst_h;
TileIndex tile = st->train_tile;
restart: restart:
/* too small? */ /* too small? */
if (w != 0 && h != 0) { if (ta.w != 0 && ta.h != 0) {
/* check the left side, x = constant, y changes */ /* check the left side, x = constant, y changes */
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) { for (uint i = 0; !st->TileBelongsToRailStation(ta.tile + TileDiffXY(0, i));) {
/* the left side is unused? */ /* the left side is unused? */
if (++i == h) { if (++i == ta.h) {
tile += TileDiffXY(1, 0); ta.tile += TileDiffXY(1, 0);
w--; ta.w--;
goto restart; goto restart;
} }
} }
/* check the right side, x = constant, y changes */ /* check the right side, x = constant, y changes */
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) { for (uint i = 0; !st->TileBelongsToRailStation(ta.tile + TileDiffXY(ta.w - 1, i));) {
/* the right side is unused? */ /* the right side is unused? */
if (++i == h) { if (++i == ta.h) {
w--; ta.w--;
goto restart; goto restart;
} }
} }
/* check the upper side, y = constant, x changes */ /* check the upper side, y = constant, x changes */
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) { for (uint i = 0; !st->TileBelongsToRailStation(ta.tile + TileDiffXY(i, 0));) {
/* the left side is unused? */ /* the left side is unused? */
if (++i == w) { if (++i == ta.w) {
tile += TileDiffXY(0, 1); ta.tile += TileDiffXY(0, 1);
h--; ta.h--;
goto restart; goto restart;
} }
} }
/* check the lower side, y = constant, x changes */ /* check the lower side, y = constant, x changes */
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) { for (uint i = 0; !st->TileBelongsToRailStation(ta.tile + TileDiffXY(i, ta.h - 1));) {
/* the left side is unused? */ /* the left side is unused? */
if (++i == w) { if (++i == ta.w) {
h--; ta.h--;
goto restart; goto restart;
} }
} }
} else { } else {
tile = INVALID_TILE; ta.tile = INVALID_TILE;
} }
st->trainst_w = w; st->train_station = ta;
st->trainst_h = h;
st->train_tile = tile;
} }
/** Remove a single tile from a railroad station. /** Remove a single tile from a railroad station.
@ -1234,7 +1225,7 @@ CommandCost CmdRemoveFromRailroadStation(TileIndex tile, DoCommandFlag flags, ui
UpdateStationSignCoord(st); UpdateStationSignCoord(st);
/* if we deleted the whole station, delete the train facility. */ /* if we deleted the whole station, delete the train facility. */
if (st->train_tile == INVALID_TILE) { if (st->train_station.tile == INVALID_TILE) {
st->facilities &= ~FACIL_TRAIN; st->facilities &= ~FACIL_TRAIN;
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
st->UpdateVirtCoord(); st->UpdateVirtCoord();
@ -1270,49 +1261,49 @@ static CommandCost RemoveRailroadStation(TileIndex tile, DoCommandFlag flags)
if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR; if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
/* determine width and height of platforms */ /* determine width and height of platforms */
tile = st->train_tile; TileArea ta = st->train_station;
int w = st->trainst_w;
int h = st->trainst_h;
assert(w != 0 && h != 0); assert(ta.w != 0 && ta.h != 0);
CommandCost cost(EXPENSES_CONSTRUCTION); CommandCost cost(EXPENSES_CONSTRUCTION);
/* clear all areas of the station */ /* clear all areas of the station */
do { do {
int w_bak = w; int w_bak = ta.w;
do { do {
/* for nonuniform stations, only remove tiles that are actually train station tiles */ /* for nonuniform stations, only remove tiles that are actually train station tiles */
if (st->TileBelongsToRailStation(tile)) { if (st->TileBelongsToRailStation(ta.tile)) {
if (!EnsureNoVehicleOnGround(tile)) { if (!EnsureNoVehicleOnGround(ta.tile)) {
return CMD_ERROR; return CMD_ERROR;
} }
cost.AddCost(_price.remove_rail_station); cost.AddCost(_price.remove_rail_station);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
/* read variables before the station tile is removed */ /* read variables before the station tile is removed */
Track track = GetRailStationTrack(tile); Track track = GetRailStationTrack(ta.tile);
Owner owner = GetTileOwner(tile); // _current_company can be OWNER_WATER Owner owner = GetTileOwner(ta.tile); // _current_company can be OWNER_WATER
Train *v = NULL; Train *v = NULL;
if (HasStationReservation(tile)) { if (HasStationReservation(ta.tile)) {
v = GetTrainForReservation(tile, track); v = GetTrainForReservation(ta.tile, track);
if (v != NULL) FreeTrainTrackReservation(v); if (v != NULL) FreeTrainTrackReservation(v);
} }
DoClearSquare(tile); DoClearSquare(ta.tile);
AddTrackToSignalBuffer(tile, track, owner); AddTrackToSignalBuffer(ta.tile, track, owner);
YapfNotifyTrackLayoutChange(tile, track); YapfNotifyTrackLayoutChange(ta.tile, track);
if (v != NULL) TryPathReserve(v, true); if (v != NULL) TryPathReserve(v, true);
} }
} }
tile += TileDiffXY(1, 0); ta.tile += TileDiffXY(1, 0);
} while (--w); } while (--ta.w);
w = w_bak; ta.w = w_bak;
tile += TileDiffXY(-w, 1); ta.tile += TileDiffXY(-ta.w, 1);
} while (--h); } while (--ta.h);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h); 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_tile = INVALID_TILE;
st->trainst_w = st->trainst_h = 0;
st->facilities &= ~FACIL_TRAIN; st->facilities &= ~FACIL_TRAIN;
free(st->speclist); free(st->speclist);
@ -2923,19 +2914,9 @@ void BuildOilRig(TileIndex tile)
MakeOilrig(tile, st->index, GetWaterClass(tile)); MakeOilrig(tile, st->index, GetWaterClass(tile));
st->owner = OWNER_NONE; st->owner = OWNER_NONE;
st->airport_flags = 0;
st->airport_type = AT_OILRIG; st->airport_type = AT_OILRIG;
st->xy = tile;
st->bus_stops = NULL;
st->truck_stops = NULL;
st->airport_tile = tile; st->airport_tile = tile;
st->dock_tile = tile; st->dock_tile = tile;
st->train_tile = INVALID_TILE;
st->had_vehicle_of_type = 0;
st->time_since_load = 255;
st->time_since_unload = 255;
st->delete_ctr = 0;
st->last_vehicle_type = VEH_INVALID;
st->facilities = FACIL_AIRPORT | FACIL_DOCK; st->facilities = FACIL_AIRPORT | FACIL_DOCK;
st->build_date = _date; st->build_date = _date;

View File

@ -4564,7 +4564,7 @@ void Train::OnNewDay()
/* update destination */ /* update destination */
if (this->current_order.IsType(OT_GOTO_STATION)) { if (this->current_order.IsType(OT_GOTO_STATION)) {
TileIndex tile = Station::Get(this->current_order.GetDestination())->train_tile; TileIndex tile = Station::Get(this->current_order.GetDestination())->train_station.tile;
if (tile != INVALID_TILE) this->dest_tile = tile; if (tile != INVALID_TILE) this->dest_tile = tile;
} }

View File

@ -749,11 +749,11 @@ static void FloodVehicles(TileIndex tile)
if (!_settings_game.station.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) { if (!_settings_game.station.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
const Station *st = Station::GetByTile(tile); const Station *st = Station::GetByTile(tile);
BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) BEGIN_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
if (st->TileBelongsToRailStation(t)) { if (st->TileBelongsToRailStation(t)) {
FindVehicleOnPos(tile, &z, &FloodVehicleProc); FindVehicleOnPos(tile, &z, &FloodVehicleProc);
} }
END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile) END_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
return; return;
} }