summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoost Hopmans <joost@jhopmans.nl>2018-06-20 12:17:05 +0200
committerfrosch <github@elsenhans.name>2018-10-31 19:24:21 +0100
commit5029cd6f28e576558d4e9304093db6e9e1216f15 (patch)
tree7dbaabd742e5a503cd7f40d29b145e9c756c6718
parent18ca3e8660f90737d672b6780301ff4b998df56f (diff)
downloadopenttd-5029cd6f28e576558d4e9304093db6e9e1216f15.tar.xz
Fix: Only possible to build station next to competitors by using CTRL+click
Fix by checking only for stations owned by the current company when inspecting if there are multiple adjoining stations to the one being built. When building next to 2 or more owned stations we don't know which station should be extended. For other companies' stations that's not a problem since our station won't merge with theirs anyway. Calling to BuildStationPart should never have another company's station as a parameter to attach to unless the client is malicious, so just returning a generic error in that case.
-rw-r--r--src/station_cmd.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index ca5cbac8b..16f135df2 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -89,25 +89,25 @@ bool IsHangar(TileIndex t)
}
/**
- * Look for a station around the given tile area.
+ * Look for a station owned by the given company around the given tile area.
* @param ta the area to search over
- * @param closest_station the closest station found so far
+ * @param closest_station the closest owned station found so far
+ * @param company the company whose stations to look for
* @param st to 'return' the found station
* @return Succeeded command (if zero or one station found) or failed command (for two or more stations found).
*/
template <class T>
-CommandCost GetStationAround(TileArea ta, StationID closest_station, T **st)
+CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
{
ta.tile -= TileDiffXY(1, 1);
ta.w += 2;
ta.h += 2;
- /* check around to see if there's any stations there */
+ /* check around to see if there are any stations there owned by the company */
TILE_AREA_LOOP(tile_cur, ta) {
if (IsTileType(tile_cur, MP_STATION)) {
StationID t = GetStationIndex(tile_cur);
- if (!T::IsValidID(t)) continue;
-
+ if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
if (closest_station == INVALID_STATION) {
closest_station = t;
} else if (closest_station != t) {
@@ -676,7 +676,7 @@ static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reus
if (*st != NULL) {
if ((*st)->owner != _current_company) {
- return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION);
+ return_cmd_error(CMD_ERROR);
}
CommandCost ret = (*st)->rect.BeforeAddRect(area.tile, area.w, area.h, StationRect::ADD_TEST);
@@ -1105,8 +1105,8 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station
}
if (check_surrounding) {
- /* Make sure there are no similar stations around us. */
- CommandCost ret = GetStationAround(ta, existing_station, st);
+ /* Make sure there is no more than one other station around us that is owned by us. */
+ CommandCost ret = GetStationAround(ta, existing_station, _current_company, st);
if (ret.Failed()) return ret;
}