src/road_gui.cpp
changeset 7172 40781792e25f
parent 7170 bd34b6d0e4f1
child 7173 0a9b13debedf
equal deleted inserted replaced
7171:87515d9cb3e6 7172:40781792e25f
    68 	} else {
    68 	} else {
    69 		SetRedErrorSquare(_build_tunnel_endtile);
    69 		SetRedErrorSquare(_build_tunnel_endtile);
    70 	}
    70 	}
    71 }
    71 }
    72 
    72 
       
    73 /** Structure holding information per roadtype for several functions */
       
    74 struct RoadTypeInfo {
       
    75 	StringID err_build_road;        ///< Building a normal piece of road
       
    76 	StringID err_remove_road;       ///< Removing a normal piece of road
       
    77 	StringID err_depot;             ///< Building a depot
       
    78 	StringID err_build_station[2];  ///< Building a bus or truck station
       
    79 	StringID err_remove_station[2]; ///< Removing of a bus or truck station
       
    80 
       
    81 	SpriteID cursor_nesw;           ///< Cursor for building NE and SW bits
       
    82 	SpriteID cursor_nwse;           ///< Cursor for building NW and SE bits
       
    83 };
       
    84 
       
    85 /** What errors/cursors must be shown for several types of roads */
       
    86 static const RoadTypeInfo _road_type_infos[] = {
       
    87 	{
       
    88 		STR_1804_CAN_T_BUILD_ROAD_HERE,
       
    89 		STR_1805_CAN_T_REMOVE_ROAD_FROM,
       
    90 		STR_1807_CAN_T_BUILD_ROAD_VEHICLE,
       
    91 		{ STR_1808_CAN_T_BUILD_BUS_STATION, STR_1809_CAN_T_BUILD_TRUCK_STATION },
       
    92 		{ STR_CAN_T_REMOVE_BUS_STATION,     STR_CAN_T_REMOVE_TRUCK_STATION     },
       
    93 
       
    94 		SPR_CURSOR_ROAD_NESW,
       
    95 		SPR_CURSOR_ROAD_NWSE,
       
    96 	},
       
    97 };
       
    98 
    73 static void PlaceRoad_Tunnel(TileIndex tile)
    99 static void PlaceRoad_Tunnel(TileIndex tile)
    74 {
   100 {
    75 	DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
   101 	DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
    76 }
   102 }
    77 
   103 
    98 	}
   124 	}
    99 }
   125 }
   100 
   126 
   101 static void PlaceRoad_Depot(TileIndex tile)
   127 static void PlaceRoad_Depot(TileIndex tile)
   102 {
   128 {
   103 	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1807_CAN_T_BUILD_ROAD_VEHICLE));
   129 	DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot));
   104 }
   130 }
   105 
   131 
   106 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
   132 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
   107 {
   133 {
   108 	uint32 p1 = _road_station_picker_orientation;
   134 	uint32 p1 = _road_station_picker_orientation;
   115 }
   141 }
   116 
   142 
   117 static void PlaceRoad_BusStation(TileIndex tile)
   143 static void PlaceRoad_BusStation(TileIndex tile)
   118 {
   144 {
   119 	if (_remove_button_clicked) {
   145 	if (_remove_button_clicked) {
   120 		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_BUS_STATION));
   146 		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[RoadStop::BUS]));
   121 	} else {
   147 	} else {
   122 		PlaceRoadStop(tile, (_ctrl_pressed << 5) | ROADTYPES_ROAD << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
   148 		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::BUS]));
   123 	}
   149 	}
   124 }
   150 }
   125 
   151 
   126 static void PlaceRoad_TruckStation(TileIndex tile)
   152 static void PlaceRoad_TruckStation(TileIndex tile)
   127 {
   153 {
   128 	if (_remove_button_clicked) {
   154 	if (_remove_button_clicked) {
   129 		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_TRUCK_STATION));
   155 		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::TRUCK]));
   130 	} else {
   156 	} else {
   131 		PlaceRoadStop(tile, (_ctrl_pressed << 5) | ROADTYPES_ROAD << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
   157 		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::TRUCK]));
   132 	}
   158 	}
   133 }
   159 }
   134 
   160 
   135 static void PlaceRoad_DemolishArea(TileIndex tile)
   161 static void PlaceRoad_DemolishArea(TileIndex tile)
   136 {
   162 {
   153 
   179 
   154 typedef void OnButtonClick(Window *w);
   180 typedef void OnButtonClick(Window *w);
   155 
   181 
   156 static void BuildRoadClick_NE(Window *w)
   182 static void BuildRoadClick_NE(Window *w)
   157 {
   183 {
   158 	HandlePlacePushButton(w, RTW_ROAD_X, SPR_CURSOR_ROAD_NESW, 1, PlaceRoad_NE);
   184 	HandlePlacePushButton(w, RTW_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nesw, 1, PlaceRoad_NE);
   159 }
   185 }
   160 
   186 
   161 static void BuildRoadClick_NW(Window *w)
   187 static void BuildRoadClick_NW(Window *w)
   162 {
   188 {
   163 	HandlePlacePushButton(w, RTW_ROAD_Y, SPR_CURSOR_ROAD_NWSE, 1, PlaceRoad_NW);
   189 	HandlePlacePushButton(w, RTW_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nwse, 1, PlaceRoad_NW);
   164 }
   190 }
   165 
   191 
   166 
   192 
   167 static void BuildRoadClick_Demolish(Window *w)
   193 static void BuildRoadClick_Demolish(Window *w)
   168 {
   194 {
   301 
   327 
   302 				case DDSP_PLACE_ROAD_NE:
   328 				case DDSP_PLACE_ROAD_NE:
   303 				case DDSP_PLACE_ROAD_NW:
   329 				case DDSP_PLACE_ROAD_NW:
   304 					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D,
   330 					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D,
   305 						_remove_button_clicked ?
   331 						_remove_button_clicked ?
   306 						CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) :
   332 						CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
   307 						CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE));
   333 						CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
   308 					break;
   334 					break;
   309 			}
   335 			}
   310 		}
   336 		}
   311 		break;
   337 		break;
   312 
   338