src/road_gui.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9912 1ac8aac92385
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
     2 
     2 
     3 /** @file road_gui.cpp */
     3 /** @file road_gui.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "road_cmd.h"
       
     8 #include "road_map.h"
       
     9 #include "table/sprites.h"
     7 #include "table/sprites.h"
    10 #include "table/strings.h"
     8 #include "table/strings.h"
    11 #include "functions.h"
     9 #include "functions.h"
    12 #include "map.h"
    10 #include "map.h"
    13 #include "tile.h"
    11 #include "tile.h"
    16 #include "viewport.h"
    14 #include "viewport.h"
    17 #include "gfx.h"
    15 #include "gfx.h"
    18 #include "sound.h"
    16 #include "sound.h"
    19 #include "command.h"
    17 #include "command.h"
    20 #include "variables.h"
    18 #include "variables.h"
       
    19 #include "road.h"
       
    20 #include "road_cmd.h"
       
    21 #include "road_map.h"
    21 #include "station_map.h"
    22 #include "station_map.h"
    22 //needed for catchments
    23 //needed for catchments
    23 #include "station.h"
    24 #include "station.h"
    24 
    25 
    25 
    26 
    29 
    30 
    30 static bool _remove_button_clicked;
    31 static bool _remove_button_clicked;
    31 
    32 
    32 static byte _place_road_flag;
    33 static byte _place_road_flag;
    33 
    34 
       
    35 static RoadType _cur_roadtype;
       
    36 
    34 static DiagDirection _road_depot_orientation;
    37 static DiagDirection _road_depot_orientation;
    35 static DiagDirection _road_station_picker_orientation;
    38 static DiagDirection _road_station_picker_orientation;
    36 
    39 
    37 void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2)
    40 void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2)
    38 {
    41 {
    40 }
    43 }
    41 
    44 
    42 static void PlaceRoad_NE(TileIndex tile)
    45 static void PlaceRoad_NE(TileIndex tile)
    43 {
    46 {
    44 	_place_road_flag = (_tile_fract_coords.y >= 8) + 4;
    47 	_place_road_flag = (_tile_fract_coords.y >= 8) + 4;
    45 	VpStartPlaceSizing(tile, VPM_FIX_X);
    48 	VpStartPlaceSizing(tile, VPM_FIX_X, GUI_PlaceProc_None);
    46 }
    49 }
    47 
    50 
    48 static void PlaceRoad_NW(TileIndex tile)
    51 static void PlaceRoad_NW(TileIndex tile)
    49 {
    52 {
    50 	_place_road_flag = (_tile_fract_coords.x >= 8) + 0;
    53 	_place_road_flag = (_tile_fract_coords.x >= 8) + 0;
    51 	VpStartPlaceSizing(tile, VPM_FIX_Y);
    54 	VpStartPlaceSizing(tile, VPM_FIX_Y, GUI_PlaceProc_None);
    52 }
    55 }
    53 
    56 
    54 static void PlaceRoad_Bridge(TileIndex tile)
    57 static void PlaceRoad_Bridge(TileIndex tile)
    55 {
    58 {
    56 	VpStartPlaceSizing(tile, VPM_X_OR_Y);
    59 	VpStartPlaceSizing(tile, VPM_X_OR_Y, GUI_PlaceProc_None);
    57 }
    60 }
    58 
    61 
    59 
    62 
    60 void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
    63 void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
    61 {
    64 {
    67 	}
    70 	}
    68 }
    71 }
    69 
    72 
    70 static void PlaceRoad_Tunnel(TileIndex tile)
    73 static void PlaceRoad_Tunnel(TileIndex tile)
    71 {
    74 {
    72 	DoCommandP(tile, 0x200, 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
    75 	DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
    73 }
    76 }
    74 
    77 
    75 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
    78 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
    76 {
    79 {
    77 	tile += TileOffsByDiagDir(direction);
    80 	tile += TileOffsByDiagDir(direction);
    78 	// if there is a roadpiece just outside of the station entrance, build a connecting route
    81 	// if there is a roadpiece just outside of the station entrance, build a connecting route
    79 	if (IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
    82 	if (IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
    80 		DoCommandP(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
    83 		if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
       
    84 			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
       
    85 		}
    81 	}
    86 	}
    82 }
    87 }
    83 
    88 
    84 void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
    89 void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
    85 {
    90 {
    86 	if (success) {
    91 	if (success) {
       
    92 		DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
    87 		SndPlayTileFx(SND_1F_SPLAT, tile);
    93 		SndPlayTileFx(SND_1F_SPLAT, tile);
    88 		ResetObjectToPlace();
    94 		ResetObjectToPlace();
    89 		BuildRoadOutsideStation(tile, (DiagDirection)p1);
    95 		BuildRoadOutsideStation(tile, dir);
    90 		/* For a drive-through road stop build connecting road for other entrance */
    96 		/* For a drive-through road stop build connecting road for other entrance */
    91 		if (HASBIT(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir((DiagDirection)p1));
    97 		if (HASBIT(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
    92 	}
    98 	}
    93 }
    99 }
    94 
   100 
    95 static void PlaceRoad_Depot(TileIndex tile)
   101 static void PlaceRoad_Depot(TileIndex tile)
    96 {
   102 {
    97 	DoCommandP(tile, _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1807_CAN_T_BUILD_ROAD_VEHICLE));
   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));
    98 }
   104 }
    99 
   105 
   100 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
   106 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
   101 {
   107 {
   102 	uint32 p1 = _road_station_picker_orientation;
   108 	uint32 p1 = _road_station_picker_orientation;
   111 static void PlaceRoad_BusStation(TileIndex tile)
   117 static void PlaceRoad_BusStation(TileIndex tile)
   112 {
   118 {
   113 	if (_remove_button_clicked) {
   119 	if (_remove_button_clicked) {
   114 		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_BUS_STATION));
   120 		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_BUS_STATION));
   115 	} else {
   121 	} else {
   116 		PlaceRoadStop(tile, RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
   122 		PlaceRoadStop(tile, ROADTYPES_ROAD << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
   117 	}
   123 	}
   118 }
   124 }
   119 
   125 
   120 static void PlaceRoad_TruckStation(TileIndex tile)
   126 static void PlaceRoad_TruckStation(TileIndex tile)
   121 {
   127 {
   122 	if (_remove_button_clicked) {
   128 	if (_remove_button_clicked) {
   123 		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_TRUCK_STATION));
   129 		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(STR_CAN_T_REMOVE_TRUCK_STATION));
   124 	} else {
   130 	} else {
   125 		PlaceRoadStop(tile, RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
   131 		PlaceRoadStop(tile, ROADTYPES_ROAD << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
   126 	}
   132 	}
   127 }
   133 }
   128 
   134 
   129 static void PlaceRoad_DemolishArea(TileIndex tile)
   135 static void PlaceRoad_DemolishArea(TileIndex tile)
   130 {
   136 {
   131 	VpStartPlaceSizing(tile, 4);
   137 	VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_None);
   132 }
   138 }
   133 
   139 
   134 
   140 
   135 enum {
   141 enum {
   136 	RTW_ROAD_X        =  3,
   142 	RTW_ROAD_X        =  3,
   262 		if (w != NULL) WP(w, def_d).close = true;
   268 		if (w != NULL) WP(w, def_d).close = true;
   263 		w = FindWindowById(WC_BUILD_DEPOT, 0);
   269 		w = FindWindowById(WC_BUILD_DEPOT, 0);
   264 		if (w != NULL) WP(w, def_d).close = true;
   270 		if (w != NULL) WP(w, def_d).close = true;
   265 		break;
   271 		break;
   266 
   272 
   267 	case WE_PLACE_DRAG: {
   273 	case WE_PLACE_DRAG:
   268 		int sel_method;
   274 		switch (e->we.place.select_method) {
   269 		switch (e->we.place.userdata) {
   275 			case VPM_FIX_X:
   270 			case 1:
       
   271 				sel_method = VPM_FIX_X;
       
   272 				_place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.y & 8) >> 2);
   276 				_place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.y & 8) >> 2);
   273 				break;
   277 				break;
   274 
   278 
   275 			case 2:
   279 			case VPM_FIX_Y:
   276 				sel_method = VPM_FIX_Y;
       
   277 				_place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.x & 8) >> 2);
   280 				_place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.x & 8) >> 2);
   278 				break;
   281 				break;
   279 
   282 		}
   280 			case 4:
   283 
   281 				sel_method = VPM_X_AND_Y;
   284 		VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
   282 				break;
       
   283 
       
   284 			default:
       
   285 				sel_method = VPM_X_OR_Y;
       
   286 				break;
       
   287 		}
       
   288 
       
   289 		VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, sel_method);
       
   290 		return;
   285 		return;
   291 	}
       
   292 
   286 
   293 	case WE_PLACE_MOUSEUP:
   287 	case WE_PLACE_MOUSEUP:
   294 		if (e->we.place.pt.x != -1) {
   288 		if (e->we.place.pt.x != -1) {
   295 			TileIndex start_tile = e->we.place.starttile;
   289 			TileIndex start_tile = e->we.place.starttile;
   296 			TileIndex end_tile = e->we.place.tile;
   290 			TileIndex end_tile = e->we.place.tile;
   297 
   291 
   298 			if (e->we.place.userdata == 0) {
   292 			switch (e->we.place.select_method) {
   299 				ResetObjectToPlace();
   293 				case VPM_X_OR_Y:
   300 				ShowBuildBridgeWindow(start_tile, end_tile, 0x80);
   294 					ResetObjectToPlace();
   301 			} else if (e->we.place.userdata != 4) {
   295 					ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | RoadTypeToRoadTypes(_cur_roadtype));
   302 				DoCommandP(end_tile, start_tile, _place_road_flag, CcPlaySound1D,
   296 					break;
   303 					_remove_button_clicked ?
   297 
   304 					CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) :
   298 				case VPM_X_AND_Y:
   305 					CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE));
   299 					DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
   306 			} else {
   300 					break;
   307 				DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
   301 
       
   302 				default:
       
   303 					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D,
       
   304 						_remove_button_clicked ?
       
   305 						CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) :
       
   306 						CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE));
       
   307 					break;
   308 			}
   308 			}
   309 		}
   309 		}
   310 		break;
   310 		break;
   311 
   311 
   312 	case WE_PLACE_PRESIZE: {
   312 	case WE_PLACE_PRESIZE: {
   313 		TileIndex tile = e->we.place.tile;
   313 		TileIndex tile = e->we.place.tile;
   314 
   314 
   315 		DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
   315 		DoCommand(tile, 0x200 | _cur_roadtype, 0, DC_AUTO, CMD_BUILD_TUNNEL);
   316 		VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
   316 		VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
   317 		break;
   317 		break;
   318 	}
   318 	}
   319 
   319 
   320 	case WE_DESTROY:
   320 	case WE_DESTROY:
   346 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   346 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   347 	_build_road_widgets,
   347 	_build_road_widgets,
   348 	BuildRoadToolbWndProc
   348 	BuildRoadToolbWndProc
   349 };
   349 };
   350 
   350 
   351 void ShowBuildRoadToolbar()
   351 void ShowBuildRoadToolbar(RoadType roadtype)
   352 {
   352 {
   353 	if (!IsValidPlayer(_current_player)) return;
   353 	if (!IsValidPlayer(_current_player)) return;
       
   354 	_cur_roadtype = roadtype;
   354 
   355 
   355 	DeleteWindowById(WC_BUILD_TOOLBAR, 0);
   356 	DeleteWindowById(WC_BUILD_TOOLBAR, 0);
   356 	Window *w = AllocateWindowDesc(&_build_road_desc);
   357 	Window *w = AllocateWindowDesc(&_build_road_desc);
   357 	if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
   358 	if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
   358 }
   359 }
   393 	case WE_CREATE: LowerWindowWidget(w, _road_depot_orientation + 3); break;
   394 	case WE_CREATE: LowerWindowWidget(w, _road_depot_orientation + 3); break;
   394 
   395 
   395 	case WE_PAINT:
   396 	case WE_PAINT:
   396 		DrawWindowWidgets(w);
   397 		DrawWindowWidgets(w);
   397 
   398 
   398 		DrawRoadDepotSprite(70, 17, DIAGDIR_NE);
   399 		DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
   399 		DrawRoadDepotSprite(70, 69, DIAGDIR_SE);
   400 		DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
   400 		DrawRoadDepotSprite( 2, 69, DIAGDIR_SW);
   401 		DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
   401 		DrawRoadDepotSprite( 2, 17, DIAGDIR_NW);
   402 		DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
   402 		break;
   403 		break;
   403 
   404 
   404 	case WE_CLICK: {
   405 	case WE_CLICK: {
   405 		switch (e->we.click.widget) {
   406 		switch (e->we.click.widget) {
   406 		case 3: case 4: case 5: case 6:
   407 		case 3: case 4: case 5: case 6: