station_cmd.c
changeset 4549 106ed18a7675
parent 4528 969ebcde6b81
child 4559 aa0c13e39840
equal deleted inserted replaced
4548:6165e12570bf 4549:106ed18a7675
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file station_cmd.c
     3 /** @file station_cmd.c */
     4   */
       
     5 
     4 
     6 #include "stdafx.h"
     5 #include "stdafx.h"
     7 #include "openttd.h"
     6 #include "openttd.h"
     8 #include "debug.h"
     7 #include "debug.h"
     9 #include "functions.h"
     8 #include "functions.h"
   167 
   166 
   168 	return NULL;
   167 	return NULL;
   169 }
   168 }
   170 
   169 
   171 /* Calculate the radius of the station. Basicly it is the biggest
   170 /* Calculate the radius of the station. Basicly it is the biggest
   172     radius that is available within the station */
   171  *  radius that is available within the station */
   173 static uint FindCatchmentRadius(const Station* st)
   172 static uint FindCatchmentRadius(const Station* st)
   174 {
   173 {
   175 	uint ret = 0;
   174 	uint ret = 0;
   176 
   175 
   177 	if (st->bus_stops != NULL)   ret = max(ret, CA_BUS);
   176 	if (st->bus_stops != NULL)   ret = max(ret, CA_BUS);
   781 		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
   780 		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
   782 
   781 
   783 		tileh = GetTileSlope(tile_cur, &z);
   782 		tileh = GetTileSlope(tile_cur, &z);
   784 
   783 
   785 		/* Prohibit building if
   784 		/* Prohibit building if
   786 			1) The tile is "steep" (i.e. stretches two height levels)
   785 		 *   1) The tile is "steep" (i.e. stretches two height levels)
   787 			-OR-
   786 		 * -OR-
   788 			2) The tile is non-flat if
   787 		 *   2) The tile is non-flat if
   789 				a) the player building is an "old-school" AI
   788 		 *     a) the player building is an "old-school" AI
   790 				-OR-
   789 		 *   -OR-
   791 				b) the build_on_slopes switch is disabled
   790 		 *     b) the build_on_slopes switch is disabled
   792 		*/
   791 		 */
   793 		if (IsSteepSlope(tileh) ||
   792 		if (IsSteepSlope(tileh) ||
   794 				((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) {
   793 				((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) {
   795 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   794 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   796 		}
   795 		}
   797 
   796 
  1250 
  1249 
  1251 	return len - 1;
  1250 	return len - 1;
  1252 }
  1251 }
  1253 
  1252 
  1254 /** Determines the REMAINING length of a platform, starting at (and including)
  1253 /** Determines the REMAINING length of a platform, starting at (and including)
  1255   * the given tile.
  1254  * the given tile.
  1256   * @param tile the tile from which to start searching. Must be a railway station tile
  1255  * @param tile the tile from which to start searching. Must be a railway station tile
  1257   * @param dir The direction in which to search.
  1256  * @param dir The direction in which to search.
  1258   * @return The platform length
  1257  * @return The platform length
  1259   */
  1258  */
  1260 uint GetPlatformLength(TileIndex tile, DiagDirection dir)
  1259 uint GetPlatformLength(TileIndex tile, DiagDirection dir)
  1261 {
  1260 {
  1262 	TileIndex start_tile = tile;
  1261 	TileIndex start_tile = tile;
  1263 	uint length = 0;
  1262 	uint length = 0;
  1264 	assert(IsRailwayStationTile(tile));
  1263 	assert(IsRailwayStationTile(tile));
  1351 
  1350 
  1352 	return _price.build_rail >> 1;
  1351 	return _price.build_rail >> 1;
  1353 }
  1352 }
  1354 
  1353 
  1355 /** Heavy wizardry used to add a roadstop to a station.
  1354 /** Heavy wizardry used to add a roadstop to a station.
  1356   * To understand the function, lets first look at what is passed around,
  1355  * To understand the function, lets first look at what is passed around,
  1357   * especially the last two parameters. CmdBuildRoadStop allocates a road
  1356  * especially the last two parameters. CmdBuildRoadStop allocates a road
  1358   * stop and needs to put that stop into the linked list of road stops.
  1357  * stop and needs to put that stop into the linked list of road stops.
  1359   * It (CmdBuildRoadStop) has a **currstop pointer which points to element
  1358  * It (CmdBuildRoadStop) has a **currstop pointer which points to element
  1360   * in the linked list of stops (each element in this list being a pointer
  1359  * in the linked list of stops (each element in this list being a pointer
  1361   * in itself, hence the double pointer). We (FindRoadStopSpot) need to
  1360  * in itself, hence the double pointer). We (FindRoadStopSpot) need to
  1362   * modify this pointer (**currstop) thus we need to pass by reference,
  1361  * modify this pointer (**currstop) thus we need to pass by reference,
  1363   * obtaining a triple pointer (***currstop). When finished, **currstop
  1362  * obtaining a triple pointer (***currstop). When finished, **currstop
  1364   * in CmdBuildRoadStop will contain the address of the pointer which will
  1363  * in CmdBuildRoadStop will contain the address of the pointer which will
  1365   * then point into the global roadstop array. *prev (in CmdBuildRoadStop)
  1364  * then point into the global roadstop array. *prev (in CmdBuildRoadStop)
  1366   * is the pointer tino the global roadstop array which has *currstop in
  1365  * is the pointer tino the global roadstop array which has *currstop in
  1367   * its ->next element.
  1366  * its ->next element.
  1368   * @param[in] truck_station Determines whether a stop is RS_BUS or RS_TRUCK
  1367  * @param[in] truck_station Determines whether a stop is RS_BUS or RS_TRUCK
  1369   * @param[in] station The station to do the whole procedure for
  1368  * @param[in] station The station to do the whole procedure for
  1370   * @param[out] currstop See the detailed function description
  1369  * @param[out] currstop See the detailed function description
  1371   * @param prev See the detailed function description
  1370  * @param prev See the detailed function description
  1372   */
  1371  */
  1373 static void FindRoadStopSpot(bool truck_station, Station* st, RoadStop*** currstop, RoadStop** prev)
  1372 static void FindRoadStopSpot(bool truck_station, Station* st, RoadStop*** currstop, RoadStop** prev)
  1374 {
  1373 {
  1375 	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
  1374 	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
  1376 	assert(*prev == NULL);
  1375 	assert(*prev == NULL);
  1377 
  1376 
  2365 	if (rs->prev != NULL) rs->prev->next = rs->next;
  2364 	if (rs->prev != NULL) rs->prev->next = rs->next;
  2366 	if (rs->next != NULL) rs->next->prev = rs->prev;
  2365 	if (rs->next != NULL) rs->next->prev = rs->prev;
  2367 }
  2366 }
  2368 
  2367 
  2369 /**
  2368 /**
  2370   * Clean up a station by clearing vehicle orders and invalidating windows.
  2369  * Clean up a station by clearing vehicle orders and invalidating windows.
  2371   * Aircraft-Hangar orders need special treatment here, as the hangars are
  2370  * Aircraft-Hangar orders need special treatment here, as the hangars are
  2372   * actually part of a station (tiletype is STATION), but the order type
  2371  * actually part of a station (tiletype is STATION), but the order type
  2373   * is OT_GOTO_DEPOT.
  2372  * is OT_GOTO_DEPOT.
  2374   * @param st Station to be deleted
  2373  * @param st Station to be deleted
  2375   */
  2374  */
  2376 void DestroyStation(Station *st)
  2375 void DestroyStation(Station *st)
  2377 {
  2376 {
  2378 	StationID index;
  2377 	StationID index;
  2379 
  2378 
  2380 	index = st->index;
  2379 	index = st->index;