rail_cmd.c
changeset 2639 eeaefdabfdfd
parent 2631 2ed0eb408229
child 2642 1d79b44ccbc9
equal deleted inserted replaced
2638:0811adaec525 2639:eeaefdabfdfd
   222 		return i + 15;
   222 		return i + 15;
   223 
   223 
   224 	return 0;
   224 	return 0;
   225 }
   225 }
   226 
   226 
   227 //
   227 
   228 static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
   228 static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
   229 {
   229 {
   230 	// never allow building on top of steep tiles
   230 	// never allow building on top of steep tiles
   231 	if (!IsSteepTileh(tileh)) {
   231 	if (!IsSteepTileh(tileh)) {
   232 		rail_bits |= existing;
   232 		rail_bits |= existing;
   687 	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   687 	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   688 	if (CmdFailed(ret)) return CMD_ERROR;
   688 	if (CmdFailed(ret)) return CMD_ERROR;
   689 	cost = ret;
   689 	cost = ret;
   690 
   690 
   691 	d = AllocateDepot();
   691 	d = AllocateDepot();
   692 	if (d == NULL)
   692 	if (d == NULL) return CMD_ERROR;
   693 		return CMD_ERROR;
       
   694 
   693 
   695 	if (flags & DC_EXEC) {
   694 	if (flags & DC_EXEC) {
   696 		if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
   695 		if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
   697 
   696 
   698 		ModifyTile(tile,
   697 		ModifyTile(tile,
   818 			/* If CmdBuildManySignals is called with copying signals, just copy the
   817 			/* If CmdBuildManySignals is called with copying signals, just copy the
   819 			 * direction of the first signal given as parameter by CmdBuildManySignals */
   818 			 * direction of the first signal given as parameter by CmdBuildManySignals */
   820 			_m[tile].m3 &= ~SignalOnTrack(track);
   819 			_m[tile].m3 &= ~SignalOnTrack(track);
   821 			_m[tile].m3 |= p2 & SignalOnTrack(track);
   820 			_m[tile].m3 |= p2 & SignalOnTrack(track);
   822 			// convert between signal<->semaphores when dragging
   821 			// convert between signal<->semaphores when dragging
   823 			if (semaphore)
   822 			if (semaphore) {
   824 				SETBIT(_m[tile].m4, 3);
   823 				SETBIT(_m[tile].m4, 3);
   825 			else
   824 			} else {
   826 				CLRBIT(_m[tile].m4, 3);
   825 				CLRBIT(_m[tile].m4, 3);
       
   826 			}
   827 		}
   827 		}
   828 
   828 
   829 		MarkTileDirtyByTile(tile);
   829 		MarkTileDirtyByTile(tile);
   830 		SetSignalsOnBothDir(tile, track);
   830 		SetSignalsOnBothDir(tile, track);
   831 	}
   831 	}
   857 	byte signal_density = (p2 >> 24);
   857 	byte signal_density = (p2 >> 24);
   858 
   858 
   859 	if (p1 > MapSize()) return CMD_ERROR;
   859 	if (p1 > MapSize()) return CMD_ERROR;
   860 	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
   860 	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
   861 
   861 
   862 	if (!IsTileType(tile, MP_RAILWAY))
   862 	if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
   863 		return CMD_ERROR;
       
   864 
   863 
   865 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   864 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   866 
   865 
   867 	/* for vertical/horizontal tracks, double the given signals density
   866 	/* for vertical/horizontal tracks, double the given signals density
   868 	* since the original amount will be too dense (shorter tracks) */
   867 	* since the original amount will be too dense (shorter tracks) */
  1288 }
  1287 }
  1289 
  1288 
  1290 static void DrawTrackFence_NS_1(const TileInfo *ti)
  1289 static void DrawTrackFence_NS_1(const TileInfo *ti)
  1291 {
  1290 {
  1292 	int z = ti->z;
  1291 	int z = ti->z;
  1293 	if (ti->tileh & 1)
  1292 	if (ti->tileh & 1) z += 8;
  1294 		z += 8;
       
  1295 	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
  1293 	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
  1296 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1294 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1297 }
  1295 }
  1298 
  1296 
  1299 static void DrawTrackFence_NS_2(const TileInfo *ti)
  1297 static void DrawTrackFence_NS_2(const TileInfo *ti)
  1300 {
  1298 {
  1301 	int z = ti->z;
  1299 	int z = ti->z;
  1302 	if (ti->tileh & 4)
  1300 	if (ti->tileh & 4) z += 8;
  1303 		z += 8;
       
  1304 	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
  1301 	AddSortableSpriteToDraw(0x517 | _drawtile_track_palette,
  1305 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1302 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1306 }
  1303 }
  1307 
  1304 
  1308 static void DrawTrackFence_WE_1(const TileInfo *ti)
  1305 static void DrawTrackFence_WE_1(const TileInfo *ti)
  1309 {
  1306 {
  1310 	int z = ti->z;
  1307 	int z = ti->z;
  1311 	if (ti->tileh & 8)
  1308 	if (ti->tileh & 8) z += 8;
  1312 		z += 8;
       
  1313 	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
  1309 	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
  1314 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1310 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1315 }
  1311 }
  1316 
  1312 
  1317 static void DrawTrackFence_WE_2(const TileInfo *ti)
  1313 static void DrawTrackFence_WE_2(const TileInfo *ti)
  1318 {
  1314 {
  1319 	int z = ti->z;
  1315 	int z = ti->z;
  1320 	if (ti->tileh & 2)
  1316 	if (ti->tileh & 2) z += 8;
  1321 		z += 8;
       
  1322 	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
  1317 	AddSortableSpriteToDraw(0x518 | _drawtile_track_palette,
  1323 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1318 		ti->x + 8, ti->y + 8, 1, 1, 4, z);
  1324 }
  1319 }
  1325 
  1320 
  1326 static void DetTrackDrawProc_Null(const TileInfo *ti)
  1321 static void DetTrackDrawProc_Null(const TileInfo *ti)
  1793 	ssd->stop = false;
  1788 	ssd->stop = false;
  1794 
  1789 
  1795 	/* Go through all the PF tiles */
  1790 	/* Go through all the PF tiles */
  1796 	for (i = 0; i < lengthof(tpf->hash_head); i++) {
  1791 	for (i = 0; i < lengthof(tpf->hash_head); i++) {
  1797 		/* Empty hash item */
  1792 		/* Empty hash item */
  1798 		if (tpf->hash_head[i] == 0)
  1793 		if (tpf->hash_head[i] == 0) continue;
  1799 			continue;
       
  1800 
  1794 
  1801 		/* If 0x8000 is not set, there is only 1 item */
  1795 		/* If 0x8000 is not set, there is only 1 item */
  1802 		if (!(tpf->hash_head[i] & 0x8000)) {
  1796 		if (!(tpf->hash_head[i] & 0x8000)) {
  1803 			/* Check if there is a vehicle on this tile */
  1797 			/* Check if there is a vehicle on this tile */
  1804 			if (SignalVehicleCheck(tpf->hash_tile[i], tpf->hash_head[i])) {
  1798 			if (SignalVehicleCheck(tpf->hash_tile[i], tpf->hash_head[i])) {
  1915 
  1909 
  1916 		// remember the result only for the first iteration.
  1910 		// remember the result only for the first iteration.
  1917 		if (result < 0) result = ssd.stop;
  1911 		if (result < 0) result = ssd.stop;
  1918 
  1912 
  1919 		// if any exit signals were changed, we need to keep going to modify the stuff behind those.
  1913 		// if any exit signals were changed, we need to keep going to modify the stuff behind those.
  1920 		if(!ssd.cur_stack)
  1914 		if (ssd.cur_stack == 0) break;
  1921 			break;
       
  1922 
  1915 
  1923 		// one or more exit signals were changed, so we need to update another segment too.
  1916 		// one or more exit signals were changed, so we need to update another segment too.
  1924 		tile = ssd.next_tile[--ssd.cur_stack];
  1917 		tile = ssd.next_tile[--ssd.cur_stack];
  1925 		direction = ssd.next_dir[ssd.cur_stack];
  1918 		direction = ssd.next_dir[ssd.cur_stack];
  1926 	}
  1919 	}
  2018 			}
  2011 			}
  2019 			break;
  2012 			break;
  2020 	}
  2013 	}
  2021 
  2014 
  2022 	// Don't continue tile loop for depots
  2015 	// Don't continue tile loop for depots
  2023 	if (_m[tile].m5 & RAIL_TYPE_SPECIAL)
  2016 	if (_m[tile].m5 & RAIL_TYPE_SPECIAL) return;
  2024 		return;
       
  2025 
  2017 
  2026 	a2 = RAIL_GROUND_GREEN;
  2018 	a2 = RAIL_GROUND_GREEN;
  2027 
  2019 
  2028 	if (m2 != RAIL_GROUND_BROWN) { /* wait until bottom is green */
  2020 	if (m2 != RAIL_GROUND_BROWN) { /* wait until bottom is green */
  2029 		/* determine direction of fence */
  2021 		/* determine direction of fence */
  2083 {
  2075 {
  2084 	byte m5, a;
  2076 	byte m5, a;
  2085 	uint16 b;
  2077 	uint16 b;
  2086 	uint32 ret;
  2078 	uint32 ret;
  2087 
  2079 
  2088 	if (mode != TRANSPORT_RAIL)
  2080 	if (mode != TRANSPORT_RAIL) return 0;
  2089 		return 0;
       
  2090 
  2081 
  2091 	m5 = _m[tile].m5;
  2082 	m5 = _m[tile].m5;
  2092 
  2083 
  2093 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  2084 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  2094 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  2085 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  2109 			 * signals are only one way, the other way will
  2100 			 * signals are only one way, the other way will
  2110 			 * implicitely become `red' */
  2101 			 * implicitely become `red' */
  2111 			if ((a & 0xC0) == 0) b |= 0xC0;
  2102 			if ((a & 0xC0) == 0) b |= 0xC0;
  2112 			if ((a & 0x30) == 0) b |= 0x30;
  2103 			if ((a & 0x30) == 0) b |= 0x30;
  2113 
  2104 
  2114 			if ( (b & 0x80) == 0)	ret |= 0x10070000;
  2105 			if ((b & 0x80) == 0) ret |= 0x10070000;
  2115 			if ( (b & 0x40) == 0)	ret |= 0x7100000;
  2106 			if ((b & 0x40) == 0) ret |= 0x07100000;
  2116 			if ( (b & 0x20) == 0)	ret |= 0x20080000;
  2107 			if ((b & 0x20) == 0) ret |= 0x20080000;
  2117 			if ( (b & 0x10) == 0)	ret |= 0x8200000;
  2108 			if ((b & 0x10) == 0) ret |= 0x08200000;
  2118 		}
  2109 		}
  2119 	} else if (m5 & 0x40) {
  2110 	} else if (m5 & 0x40) {
  2120 		static const byte _train_spec_tracks[6] = {1,2,1,2,1,2};
  2111 		static const byte _train_spec_tracks[6] = {1,2,1,2,1,2};
  2121 		m5 = _train_spec_tracks[m5 & 0x3F];
  2112 		m5 = _train_spec_tracks[m5 & 0x3F];
  2122 		ret = (m5 << 8) + m5;
  2113 		ret = (m5 << 8) + m5;
  2191 	byte fract_coord_leave;
  2182 	byte fract_coord_leave;
  2192 	int dir;
  2183 	int dir;
  2193 	int length;
  2184 	int length;
  2194 
  2185 
  2195 	// this routine applies only to trains in depot tiles
  2186 	// this routine applies only to trains in depot tiles
  2196 	if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL))
  2187 	if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0;
  2197 		return 0;
       
  2198 
  2188 
  2199 	/* depot direction */
  2189 	/* depot direction */
  2200 	dir = GetDepotDirection(tile, TRANSPORT_RAIL);
  2190 	dir = GetDepotDirection(tile, TRANSPORT_RAIL);
  2201 
  2191 
  2202 	/* calculate the point where the following wagon should be activated */
  2192 	/* calculate the point where the following wagon should be activated */