(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
authorcelestar
Thu, 01 Jun 2006 09:41:35 +0000
changeset 3928 791f04fb29ad
parent 3927 b6e0f409d92d
child 3929 e0db51e174bc
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
station.h
station_cmd.c
train_cmd.c
--- a/station.h	Wed May 31 20:08:55 2006 +0000
+++ b/station.h	Thu Jun 01 09:41:35 2006 +0000
@@ -200,6 +200,7 @@
 void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
 void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
 uint GetStationPlatforms(const Station *st, TileIndex tile);
+uint GetPlatformLength(TileIndex tile, DiagDirection dir);
 
 
 const DrawTileSprites *GetStationTileLayout(byte gfx);
--- a/station_cmd.c	Wed May 31 20:08:55 2006 +0000
+++ b/station_cmd.c	Thu Jun 01 09:41:35 2006 +0000
@@ -1255,6 +1255,28 @@
 	return len - 1;
 }
 
+/** Determines the REMAINING length of a platform, starting at (and including)
+  * the given tile.
+  * @param tile the tile from which to start searching. Must be a railway station tile
+  * @param dir The direction in which to search.
+  * @return The platform length
+  */
+uint GetPlatformLength(TileIndex tile, DiagDirection dir)
+{
+	TileIndex start_tile = tile;
+	uint length = 0;
+	assert(IsRailwayStationTile(tile));
+	assert(dir < DIAGDIR_END);
+
+	do {
+		length ++;
+		tile += TileOffsByDir(dir);
+	} while (IsCompatibleTrainStationTile(tile, start_tile));
+
+	return length;
+}
+
+
 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 {
 	int w,h;
--- a/train_cmd.c	Wed May 31 20:08:55 2006 +0000
+++ b/train_cmd.c	Thu Jun 01 09:41:35 2006 +0000
@@ -332,15 +332,11 @@
 
 	if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
 		if (TrainShouldStop(v, v->tile)) {
-			int station_length = 0;
-			TileIndex tile = v->tile;
+			uint station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction));
 			int delta_v;
+			DEBUG(misc, 0) ("Length: %d", station_length);
 
 			max_speed = 120;
-			do {
-				station_length++;
-				tile = TILE_ADD(tile, TileOffsByDir(v->direction / 2));
-			} while (IsCompatibleTrainStationTile(tile, v->tile));
 
 			delta_v = v->cur_speed / (station_length + 1);
 			if (v->max_speed > (v->cur_speed - delta_v))