rail_cmd.c
changeset 3253 015524c19f16
parent 3242 1cefa03f0d5e
child 3254 b894326fcea0
equal deleted inserted replaced
3252:fb8df0423442 3253:015524c19f16
   313 		case MP_RAILWAY:
   313 		case MP_RAILWAY:
   314 			if (!CheckTrackCombination(tile, trackbit, flags) ||
   314 			if (!CheckTrackCombination(tile, trackbit, flags) ||
   315 					!EnsureNoVehicle(tile)) {
   315 					!EnsureNoVehicle(tile)) {
   316 				return CMD_ERROR;
   316 				return CMD_ERROR;
   317 			}
   317 			}
   318 			if (m5 & RAIL_TYPE_SPECIAL ||
   318 			if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT ||
   319 					!IsTileOwner(tile, _current_player) ||
   319 					!IsTileOwner(tile, _current_player) ||
   320 					GetRailType(tile) != p1) {
   320 					GetRailType(tile) != p1) {
   321 				// Get detailed error message
   321 				// Get detailed error message
   322 				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   322 				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   323 			}
   323 			}
  1036 	byte m5;
  1036 	byte m5;
  1037 
  1037 
  1038 	m5 = _m[tile].m5;
  1038 	m5 = _m[tile].m5;
  1039 
  1039 
  1040 	if (flags & DC_AUTO) {
  1040 	if (flags & DC_AUTO) {
  1041 		if (m5 & RAIL_TYPE_SPECIAL)
  1041 		if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
  1042 			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
  1042 			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
       
  1043 		}
  1043 
  1044 
  1044 		if (!IsTileOwner(tile, _current_player))
  1045 		if (!IsTileOwner(tile, _current_player))
  1045 			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
  1046 			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
  1046 
  1047 
  1047 		return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
  1048 		return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
  1347 	PalSpriteID image;
  1348 	PalSpriteID image;
  1348 
  1349 
  1349 	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
  1350 	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
  1350 
  1351 
  1351 	m5 = (byte)ti->map5;
  1352 	m5 = (byte)ti->map5;
  1352 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  1353 	if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
  1353 		bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
  1354 		bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
  1354 		bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
  1355 		bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
  1355 
  1356 
  1356 		DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
  1357 		DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
  1357 
  1358 
  1358 		if (_display_opt & DO_FULL_DETAIL) {
  1359 		if (_display_opt & DO_FULL_DETAIL) {
  1359 			_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
  1360 			_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
  1360 		}
  1361 		}
  1361 
  1362 
  1362 		/* draw signals also? */
  1363 		/* draw signals also? */
  1363 		if (!(ti->map5 & RAIL_TYPE_SIGNALS))
  1364 		if (GetRailTileType(ti->tile) != RAIL_TYPE_SIGNALS) return;
  1364 			return;
       
  1365 
  1365 
  1366 		{
  1366 		{
  1367 			byte m23;
  1367 			byte m23;
  1368 
  1368 
  1369 			m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0);
  1369 			m23 = (_m[ti->tile].m3 >> 4) | (_m[ti->tile].m2 & 0xF0);
  1402 	} else {
  1402 	} else {
  1403 		/* draw depots / waypoints */
  1403 		/* draw depots / waypoints */
  1404 		const DrawTrackSeqStruct *drss;
  1404 		const DrawTrackSeqStruct *drss;
  1405 		byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints
  1405 		byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints
  1406 
  1406 
  1407 		if (!(m5 & (RAIL_TILE_TYPE_MASK&~RAIL_TYPE_SPECIAL)))
       
  1408 			/* XXX: There used to be "return;" here, but since I could not find out
       
  1409 			 * why this would ever occur, I put assert(0) here. Let's see if someone
       
  1410 			 * complains about it. If not, we'll remove this check. (Matthijs). */
       
  1411 			 assert(0);
       
  1412 
       
  1413 		if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
  1407 		if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
  1414 
  1408 
  1415 		if (IsRailWaypoint(ti->tile) && HASBIT(_m[ti->tile].m3, 4)) {
  1409 		if (IsRailWaypoint(ti->tile) && HASBIT(_m[ti->tile].m3, 4)) {
  1416 			// look for customization
  1410 			// look for customization
  1417 			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
  1411 			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
  1853 static void TileLoop_Track(TileIndex tile)
  1847 static void TileLoop_Track(TileIndex tile)
  1854 {
  1848 {
  1855 	byte old_ground;
  1849 	byte old_ground;
  1856 	byte new_ground;
  1850 	byte new_ground;
  1857 
  1851 
  1858 	old_ground = _m[tile].m5 & RAIL_TYPE_SPECIAL ? GB(_m[tile].m4, 0, 4) : GB(_m[tile].m2, 0, 4);
  1852 	if (GetRailType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
       
  1853 		old_ground = GB(_m[tile].m4, 0, 4);
       
  1854 	} else {
       
  1855 		old_ground = GB(_m[tile].m2, 0, 4);
       
  1856 	}
  1859 
  1857 
  1860 	switch (_opt.landscape) {
  1858 	switch (_opt.landscape) {
  1861 		case LT_HILLY:
  1859 		case LT_HILLY:
  1862 			if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
  1860 			if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
  1863 				new_ground = RAIL_GROUND_ICE_DESERT;
  1861 				new_ground = RAIL_GROUND_ICE_DESERT;
  1872 			}
  1870 			}
  1873 			break;
  1871 			break;
  1874 	}
  1872 	}
  1875 
  1873 
  1876 	// Don't continue tile loop for depots
  1874 	// Don't continue tile loop for depots
  1877 	if (_m[tile].m5 & RAIL_TYPE_SPECIAL) return;
  1875 	if (GetRailType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) return;
  1878 
  1876 
  1879 	new_ground = RAIL_GROUND_GREEN;
  1877 	new_ground = RAIL_GROUND_GREEN;
  1880 
  1878 
  1881 	if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
  1879 	if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
  1882 		/* determine direction of fence */
  1880 		/* determine direction of fence */
  1954 	}
  1952 	}
  1955 
  1953 
  1956 modify_me:;
  1954 modify_me:;
  1957 	/* tile changed? */
  1955 	/* tile changed? */
  1958 	if (old_ground != new_ground) {
  1956 	if (old_ground != new_ground) {
  1959 		if (_m[tile].m5 & RAIL_TYPE_SPECIAL) {
  1957 		if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
  1960 			SB(_m[tile].m4, 0, 4, new_ground);
  1958 			SB(_m[tile].m4, 0, 4, new_ground);
  1961 		} else {
  1959 		} else {
  1962 			SB(_m[tile].m2, 0, 4, new_ground);
  1960 			SB(_m[tile].m2, 0, 4, new_ground);
  1963 		}
  1961 		}
  1964 		MarkTileDirtyByTile(tile);
  1962 		MarkTileDirtyByTile(tile);
  1974 
  1972 
  1975 	if (mode != TRANSPORT_RAIL) return 0;
  1973 	if (mode != TRANSPORT_RAIL) return 0;
  1976 
  1974 
  1977 	m5 = _m[tile].m5;
  1975 	m5 = _m[tile].m5;
  1978 
  1976 
  1979 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  1977 	if (GetRailType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
  1980 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  1978 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  1981 		if (!(m5 & RAIL_TYPE_SIGNALS)) {
  1979 		if (GetRailType(tile) != RAIL_TYPE_SIGNALS) {
  1982 			if ( (ret & 0xFF) == 3)
  1980 			if ( (ret & 0xFF) == 3)
  1983 			/* Diagonal crossing? */
  1981 			/* Diagonal crossing? */
  1984 				ret |= 0x40;
  1982 				ret |= 0x40;
  1985 		} else {
  1983 		} else {
  1986 			/* has_signals */
  1984 			/* has_signals */