Mercurial > hg > openttd
comparison src/station_gui.cpp @ 12522:becf2d0cf3d2 draft
(svn r16959) -Codechange: make the station joiner a bit more aware of the difference between waypoints and stations.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 26 Jul 2009 09:25:00 +0000 |
parents | 32e2de3d509a |
children | a8b8bcd7f03d |
comparison
equal
deleted
inserted
replaced
12521:24160fbe9e96 | 12522:becf2d0cf3d2 |
---|---|
1074 }; | 1074 }; |
1075 | 1075 |
1076 static SmallVector<TileAndStation, 8> _deleted_stations_nearby; | 1076 static SmallVector<TileAndStation, 8> _deleted_stations_nearby; |
1077 static SmallVector<StationID, 8> _stations_nearby_list; | 1077 static SmallVector<StationID, 8> _stations_nearby_list; |
1078 | 1078 |
1079 /** Context for FindStationsNearby */ | |
1080 struct FindNearbyStationContext { | |
1081 TileIndex tile; ///< Base tile of station to be built | |
1082 uint w; ///< Width of station to be built | |
1083 uint h; ///< Height of station to be built | |
1084 }; | |
1085 | |
1086 /** | 1079 /** |
1087 * Add station on this tile to _stations_nearby_list if it's fully within the | 1080 * Add station on this tile to _stations_nearby_list if it's fully within the |
1088 * station spread. | 1081 * station spread. |
1089 * @param tile Tile just being checked | 1082 * @param tile Tile just being checked |
1090 * @param user_data Pointer to FindNearbyStationContext context | 1083 * @param user_data Pointer to TileArea context |
1091 */ | 1084 */ |
1092 static bool AddNearbyStation(TileIndex tile, void *user_data) | 1085 static bool AddNearbyStation(TileIndex tile, void *user_data) |
1093 { | 1086 { |
1094 FindNearbyStationContext *ctx = (FindNearbyStationContext *)user_data; | 1087 TileArea *ctx = (TileArea *)user_data; |
1095 | 1088 |
1096 /* First check if there were deleted stations here */ | 1089 /* First check if there were deleted stations here */ |
1097 for (uint i = 0; i < _deleted_stations_nearby.Length(); i++) { | 1090 for (uint i = 0; i < _deleted_stations_nearby.Length(); i++) { |
1098 TileAndStation *ts = _deleted_stations_nearby.Get(i); | 1091 TileAndStation *ts = _deleted_stations_nearby.Get(i); |
1099 if (ts->tile == tile) { | 1092 if (ts->tile == tile) { |
1105 | 1098 |
1106 /* Check if own station and if we stay within station spread */ | 1099 /* Check if own station and if we stay within station spread */ |
1107 if (!IsTileType(tile, MP_STATION)) return false; | 1100 if (!IsTileType(tile, MP_STATION)) return false; |
1108 | 1101 |
1109 StationID sid = GetStationIndex(tile); | 1102 StationID sid = GetStationIndex(tile); |
1103 | |
1104 /* This station is (likely) a waypoint */ | |
1105 if (!Station::IsValidID(sid)) return false; | |
1106 | |
1110 Station *st = Station::Get(sid); | 1107 Station *st = Station::Get(sid); |
1111 if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false; | 1108 if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false; |
1112 | 1109 |
1113 if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST)) { | 1110 if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST)) { |
1114 *_stations_nearby_list.Append() = sid; | 1111 *_stations_nearby_list.Append() = sid; |
1127 * @param distant_join Search for adjacent stations (false) or stations fully | 1124 * @param distant_join Search for adjacent stations (false) or stations fully |
1128 * within station spread | 1125 * within station spread |
1129 **/ | 1126 **/ |
1130 static const Station *FindStationsNearby(TileIndex tile, int w, int h, bool distant_join) | 1127 static const Station *FindStationsNearby(TileIndex tile, int w, int h, bool distant_join) |
1131 { | 1128 { |
1132 FindNearbyStationContext ctx; | 1129 TileArea ctx; |
1133 ctx.tile = tile; | 1130 ctx.tile = tile; |
1134 ctx.w = w; | 1131 ctx.w = w; |
1135 ctx.h = h; | 1132 ctx.h = h; |
1136 | 1133 |
1137 _stations_nearby_list.Clear(); | 1134 _stations_nearby_list.Clear(); |
1138 _deleted_stations_nearby.Clear(); | 1135 _deleted_stations_nearby.Clear(); |
1139 | 1136 |
1140 /* Check the inside, to return, if we sit on another station */ | 1137 /* Check the inside, to return, if we sit on another station */ |
1141 BEGIN_TILE_LOOP(t, w, h, tile) | 1138 BEGIN_TILE_LOOP(t, w, h, tile) |
1142 if (t < MapSize() && IsTileType(t, MP_STATION)) return Station::GetByTile(t); | 1139 if (t < MapSize() && IsTileType(t, MP_STATION) && Station::IsValidID(GetStationIndex(t))) return Station::GetByTile(t); |
1143 END_TILE_LOOP(t, w, h, tile) | 1140 END_TILE_LOOP(t, w, h, tile) |
1144 | 1141 |
1145 /* Look for deleted stations */ | 1142 /* Look for deleted stations */ |
1146 const Station *st; | 1143 const BaseStation *st; |
1147 FOR_ALL_STATIONS(st) { | 1144 FOR_ALL_BASE_STATIONS(st) { |
1148 if (st->facilities == 0 && st->owner == _local_company) { | 1145 if (Station::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) { |
1149 /* Include only within station spread (yes, it is strictly less than) */ | 1146 /* Include only within station spread (yes, it is strictly less than) */ |
1150 if (max(DistanceMax(tile, st->xy), DistanceMax(TILE_ADDXY(tile, w - 1, h - 1), st->xy)) < _settings_game.station.station_spread) { | 1147 if (max(DistanceMax(tile, st->xy), DistanceMax(TILE_ADDXY(tile, w - 1, h - 1), st->xy)) < _settings_game.station.station_spread) { |
1151 TileAndStation *ts = _deleted_stations_nearby.Append(); | 1148 TileAndStation *ts = _deleted_stations_nearby.Append(); |
1152 ts->tile = st->xy; | 1149 ts->tile = st->xy; |
1153 ts->station = st->index; | 1150 ts->station = st->index; |