src/rail_cmd.cpp
branchcpp_gui
changeset 6303 84c215fc8eb8
parent 6298 c30fe89622df
child 6307 f40e88cff863
equal deleted inserted replaced
6302:bd80897189ba 6303:84c215fc8eb8
    10 #include "rail_map.h"
    10 #include "rail_map.h"
    11 #include "road_map.h"
    11 #include "road_map.h"
    12 #include "table/sprites.h"
    12 #include "table/sprites.h"
    13 #include "table/strings.h"
    13 #include "table/strings.h"
    14 #include "map.h"
    14 #include "map.h"
       
    15 #include "landscape.h"
    15 #include "tile.h"
    16 #include "tile.h"
    16 #include "town_map.h"
    17 #include "town_map.h"
    17 #include "tunnel_map.h"
    18 #include "tunnel_map.h"
    18 #include "vehicle.h"
    19 #include "vehicle.h"
    19 #include "viewport.h"
    20 #include "viewport.h"
   846 	return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit
   847 	return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit
   847 }
   848 }
   848 
   849 
   849 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
   850 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
   850 
   851 
       
   852 /**
       
   853  * Switches the rail type.
       
   854  * Railtypes are stored on a per-tile basis, not on a per-track basis, so
       
   855  * all the tracks in the given tile will be converted.
       
   856  * @param tile        The tile on which the railtype is to be convert.
       
   857  * @param totype      The railtype we want to convert to
       
   858  * @param exec        Switches between test and execute mode
       
   859  * @return            The cost and state of the operation
       
   860  * @retval CMD_ERROR  An error occured during the operation.
       
   861  */
   851 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
   862 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
   852 {
   863 {
   853 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   864 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   854 
   865 
       
   866 	if (GetRailType(tile) == totype) return CMD_ERROR;
       
   867 
   855 	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
   868 	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
   856 
       
   857 	// tile is already of requested type?
       
   858 	if (GetRailType(tile) == totype) return CMD_ERROR;
       
   859 
   869 
   860 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
   870 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
   861 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
   871 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
   862 
   872 
   863 	// change type.
   873 	// change type.
  1291 			image = dts->ground_sprite;
  1301 			image = dts->ground_sprite;
  1292 			if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
  1302 			if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
  1293 
  1303 
  1294 			// adjust ground tile for desert
  1304 			// adjust ground tile for desert
  1295 			// don't adjust for snow, because snow in depots looks weird
  1305 			// don't adjust for snow, because snow in depots looks weird
  1296 			if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_DESERT) {
  1306 			if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_TROPIC) {
  1297 				if (image != SPR_FLAT_GRASS_TILE) {
  1307 				if (image != SPR_FLAT_GRASS_TILE) {
  1298 					image += rti->snow_offset; // tile with tracks
  1308 					image += rti->snow_offset; // tile with tracks
  1299 				} else {
  1309 				} else {
  1300 					image = SPR_FLAT_SNOWY_TILE; // flat ground
  1310 					image = SPR_FLAT_SNOWY_TILE; // flat ground
  1301 				}
  1311 				}
  1735 {
  1745 {
  1736 	RailGroundType old_ground = GetRailGroundType(tile);
  1746 	RailGroundType old_ground = GetRailGroundType(tile);
  1737 	RailGroundType new_ground;
  1747 	RailGroundType new_ground;
  1738 
  1748 
  1739 	switch (_opt.landscape) {
  1749 	switch (_opt.landscape) {
  1740 		case LT_HILLY:
  1750 		case LT_ARCTIC:
  1741 			if (GetTileZ(tile) > _opt.snow_line) {
  1751 			if (GetTileZ(tile) > GetSnowLine()) {
  1742 				new_ground = RAIL_GROUND_ICE_DESERT;
  1752 				new_ground = RAIL_GROUND_ICE_DESERT;
  1743 				goto set_ground;
  1753 				goto set_ground;
  1744 			}
  1754 			}
  1745 			break;
  1755 			break;
  1746 
  1756 
  1747 		case LT_DESERT:
  1757 		case LT_TROPIC:
  1748 			if (GetTropicZone(tile) == TROPICZONE_DESERT) {
  1758 			if (GetTropicZone(tile) == TROPICZONE_DESERT) {
  1749 				new_ground = RAIL_GROUND_ICE_DESERT;
  1759 				new_ground = RAIL_GROUND_ICE_DESERT;
  1750 				goto set_ground;
  1760 				goto set_ground;
  1751 			}
  1761 			}
  1752 			break;
  1762 			break;