src/rail_gui.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
    70 	GenericPlaceRail(tile, cmd);
    70 	GenericPlaceRail(tile, cmd);
    71 }
    71 }
    72 
    72 
    73 static void PlaceRail_NE(TileIndex tile)
    73 static void PlaceRail_NE(TileIndex tile)
    74 {
    74 {
    75 	VpStartPlaceSizing(tile, VPM_FIX_Y, GUI_PlaceProc_None);
    75 	VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_RAIL_NE);
    76 }
    76 }
    77 
    77 
    78 static void PlaceRail_E(TileIndex tile)
    78 static void PlaceRail_E(TileIndex tile)
    79 {
    79 {
    80 	int cmd = _tile_fract_coords.x + _tile_fract_coords.y <= 15 ? 2 : 3;
    80 	int cmd = _tile_fract_coords.x + _tile_fract_coords.y <= 15 ? 2 : 3;
    81 	GenericPlaceRail(tile, cmd);
    81 	GenericPlaceRail(tile, cmd);
    82 }
    82 }
    83 
    83 
    84 static void PlaceRail_NW(TileIndex tile)
    84 static void PlaceRail_NW(TileIndex tile)
    85 {
    85 {
    86 	VpStartPlaceSizing(tile, VPM_FIX_X, GUI_PlaceProc_None);
    86 	VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_RAIL_NW);
    87 }
    87 }
    88 
    88 
    89 static void PlaceRail_AutoRail(TileIndex tile)
    89 static void PlaceRail_AutoRail(TileIndex tile)
    90 {
    90 {
    91 	VpStartPlaceSizing(tile, VPM_RAILDIRS, GUI_PlaceProc_None);
    91 	VpStartPlaceSizing(tile, VPM_RAILDIRS, DDSP_PLACE_AUTORAIL);
    92 }
    92 }
    93 
    93 
    94 static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
    94 static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
    95 {
    95 {
    96 	if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
    96 	if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
   149 }
   149 }
   150 
   150 
   151 static void PlaceRail_Station(TileIndex tile)
   151 static void PlaceRail_Station(TileIndex tile)
   152 {
   152 {
   153 	if (_remove_button_clicked) {
   153 	if (_remove_button_clicked) {
   154 		VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_RemoveFromStation);
   154 		VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_STATION);
   155 	} else if (_railstation.dragdrop) {
   155 	} else if (_railstation.dragdrop) {
   156 		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, GUI_PlaceProc_None);
   156 		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION);
   157 		VpSetPlaceSizingLimit(_patches.station_spread);
   157 		VpSetPlaceSizingLimit(_patches.station_spread);
   158 	} else {
   158 	} else {
   159 		DoCommandP(tile,
   159 		DoCommandP(tile,
   160 				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16),
   160 				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16) | (_ctrl_pressed << 24),
   161 				_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
   161 				_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
   162 				CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
   162 				CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
   163 	}
   163 	}
   164 }
   164 }
   165 
   165 
   166 static void GenericPlaceSignals(TileIndex tile)
   166 static void GenericPlaceSignals(TileIndex tile)
   167 {
   167 {
   168 	byte trackstat;
   168 	TrackBits trackbits = (TrackBits)GB(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0), 0, 6);
   169 	uint i;
   169 
   170 
   170 	if (trackbits & TRACK_BIT_VERT) { // N-S direction
   171 	trackstat = (byte)GetTileTrackStatus(tile, TRANSPORT_RAIL);
   171 		trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT;
   172 
   172 	}
   173 	if (trackstat & TRACK_BIT_VERT) // N-S direction
   173 
   174 		trackstat = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT;
   174 	if (trackbits & TRACK_BIT_HORZ) { // E-W direction
   175 
   175 		trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
   176 	if (trackstat & TRACK_BIT_HORZ) // E-W direction
   176 	}
   177 		trackstat = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
   177 
   178 
   178 	Track track = TrackBitsToTrack(trackbits);
   179 	// Lookup the bit index
       
   180 	i = 0;
       
   181 	if (trackstat != 0) {
       
   182 		for (; !(trackstat & 1); trackstat >>= 1) i++;
       
   183 	}
       
   184 
   179 
   185 	if (!_remove_button_clicked) {
   180 	if (!_remove_button_clicked) {
   186 		uint32 p1 = GB(i, 0, 3);
   181 		uint32 p1 = track;
   187 		SB(p1, 3, 1, _ctrl_pressed);
   182 		SB(p1, 3, 1, _ctrl_pressed);
   188 		SB(p1, 4, 1, _cur_year < _patches.semaphore_build_before);
   183 		SB(p1, 4, 1, _cur_year < _patches.semaphore_build_before);
   189 
   184 
   190 		DoCommandP(tile, p1, 0, CcPlaySound1E,
   185 		DoCommandP(tile, p1, 0, CcPlaySound1E,
   191 			CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE));
   186 			CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE));
   192 	} else {
   187 	} else {
   193 		DoCommandP(tile, i, 0, CcPlaySound1E,
   188 		DoCommandP(tile, track, 0, CcPlaySound1E,
   194 			CMD_REMOVE_SIGNALS | CMD_AUTO | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM));
   189 			CMD_REMOVE_SIGNALS | CMD_AUTO | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM));
   195 	}
   190 	}
   196 }
   191 }
   197 
   192 
   198 static void PlaceRail_Bridge(TileIndex tile)
   193 static void PlaceRail_Bridge(TileIndex tile)
   199 {
   194 {
   200 	VpStartPlaceSizing(tile, VPM_X_OR_Y, GUI_PlaceProc_None);
   195 	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
   201 }
   196 }
   202 
   197 
   203 void CcBuildRailTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
   198 void CcBuildRailTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
   204 {
   199 {
   205 	if (success) {
   200 	if (success) {
   221 	DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND));
   216 	DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND));
   222 }
   217 }
   223 
   218 
   224 static void PlaceRail_ConvertRail(TileIndex tile)
   219 static void PlaceRail_ConvertRail(TileIndex tile)
   225 {
   220 {
   226 	VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_ConvertRailArea);
   221 	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CONVERT_RAIL);
   227 }
   222 }
   228 
   223 
   229 static void PlaceRail_AutoSignals(TileIndex tile)
   224 static void PlaceRail_AutoSignals(TileIndex tile)
   230 {
   225 {
   231 	VpStartPlaceSizing(tile, VPM_SIGNALDIRS, GUI_PlaceProc_None);
   226 	VpStartPlaceSizing(tile, VPM_SIGNALDIRS, DDSP_BUILD_SIGNALS);
   232 }
   227 }
   233 
   228 
   234 
   229 
   235 /** Enum referring to the widgets of the build rail toolbar */
   230 /** Enum referring to the widgets of the build rail toolbar */
   236 enum {
   231 enum {
   499 	case WE_PLACE_MOUSEUP:
   494 	case WE_PLACE_MOUSEUP:
   500 		if (e->we.place.pt.x != -1) {
   495 		if (e->we.place.pt.x != -1) {
   501 			TileIndex start_tile = e->we.place.starttile;
   496 			TileIndex start_tile = e->we.place.starttile;
   502 			TileIndex end_tile = e->we.place.tile;
   497 			TileIndex end_tile = e->we.place.tile;
   503 
   498 
   504 			switch (e->we.place.select_method) {
   499 			switch (e->we.place.select_proc) {
   505 				case VPM_X_OR_Y:
   500 				case DDSP_BUILD_BRIDGE:
   506 					ResetObjectToPlace();
   501 					ResetObjectToPlace();
   507 					ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype);
   502 					ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype);
   508 					break;
   503 					break;
   509 
   504 
   510 				case VPM_RAILDIRS: {
   505 				case DDSP_PLACE_AUTORAIL: {
   511 					bool old = _remove_button_clicked;
   506 					bool old = _remove_button_clicked;
   512 					if (_ctrl_pressed) _remove_button_clicked = true;
   507 					if (_ctrl_pressed) _remove_button_clicked = true;
   513 					HandleAutodirPlacement();
   508 					HandleAutodirPlacement();
   514 					_remove_button_clicked = old;
   509 					_remove_button_clicked = old;
   515 					break;
   510 					break;
   516 				}
   511 				}
   517 
   512 
   518 				case VPM_SIGNALDIRS:
   513 				case DDSP_BUILD_SIGNALS:
   519 					HandleAutoSignalPlacement();
   514 					HandleAutoSignalPlacement();
   520 					break;
   515 					break;
   521 
   516 
   522 				case VPM_X_AND_Y:
   517 				case DDSP_DEMOLISH_AREA:
   523 					if (GUIPlaceProcDragXY(e)) break;
   518 					GUIPlaceProcDragXY(e);
   524 
       
   525 					switch (e->we.place.select_proc) {
       
   526 						case GUI_PlaceProc_RemoveFromStation:
       
   527 							DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION));
       
   528 							break;
       
   529 
       
   530 						case GUI_PlaceProc_ConvertRailArea:
       
   531 							DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL));
       
   532 							break;
       
   533 					}
       
   534 					break;
   519 					break;
   535 
   520 
   536 				case VPM_X_AND_Y_LIMITED:
   521 				case DDSP_REMOVE_STATION:
       
   522 					DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION));
       
   523 					break;
       
   524 
       
   525 				case DDSP_CONVERT_RAIL:
       
   526 					DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL));
       
   527 					break;
       
   528 
       
   529 				case DDSP_BUILD_STATION:
   537 					HandleStationPlacement(start_tile, end_tile);
   530 					HandleStationPlacement(start_tile, end_tile);
   538 					break;
   531 					break;
   539 
   532 
   540 				default:
   533 				case DDSP_PLACE_RAIL_NE:
   541 					DoRailroadTrack(e->we.place.select_method == VPM_FIX_Y ? TRACK_X : TRACK_Y);
   534 				case DDSP_PLACE_RAIL_NW:
       
   535 					DoRailroadTrack(e->we.place.select_proc == DDSP_PLACE_RAIL_NE ? TRACK_X : TRACK_Y);
   542 					break;
   536 					break;
   543 			}
   537 			}
   544 		}
   538 		}
   545 		break;
   539 		break;
   546 
   540 
   664 	w = ex - sx + 1;
   658 	w = ex - sx + 1;
   665 	h = ey - sy + 1;
   659 	h = ey - sy + 1;
   666 	if (!_railstation.orientation) Swap(w, h);
   660 	if (!_railstation.orientation) Swap(w, h);
   667 
   661 
   668 	DoCommandP(TileXY(sx, sy),
   662 	DoCommandP(TileXY(sx, sy),
   669 			_railstation.orientation | (w << 8) | (h << 16),
   663 			_railstation.orientation | (w << 8) | (h << 16) | (_ctrl_pressed << 24),
   670 			_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
   664 			_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
   671 			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
   665 			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
   672 }
   666 }
   673 
   667 
   674 /* Check if the currently selected station size is allowed */
   668 /* Check if the currently selected station size is allowed */
   754 		/* Set up a clipping area for the '/' station preview */
   748 		/* Set up a clipping area for the '/' station preview */
   755 		if (FillDrawPixelInfo(&tmp_dpi, 7, 26 + y_offset, 66, 48)) {
   749 		if (FillDrawPixelInfo(&tmp_dpi, 7, 26 + y_offset, 66, 48)) {
   756 			old_dpi = _cur_dpi;
   750 			old_dpi = _cur_dpi;
   757 			_cur_dpi = &tmp_dpi;
   751 			_cur_dpi = &tmp_dpi;
   758 			if (!DrawStationTile(32, 16, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) {
   752 			if (!DrawStationTile(32, 16, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) {
   759 				StationPickerDrawSprite(32, 16, _cur_railtype, 2);
   753 				StationPickerDrawSprite(32, 16, _cur_railtype, INVALID_ROADTYPE, 2);
   760 			}
   754 			}
   761 			_cur_dpi = old_dpi;
   755 			_cur_dpi = old_dpi;
   762 		}
   756 		}
   763 
   757 
   764 		/* Set up a clipping area for the '\' station preview */
   758 		/* Set up a clipping area for the '\' station preview */
   765 		if (FillDrawPixelInfo(&tmp_dpi, 75, 26 + y_offset, 66, 48)) {
   759 		if (FillDrawPixelInfo(&tmp_dpi, 75, 26 + y_offset, 66, 48)) {
   766 			old_dpi = _cur_dpi;
   760 			old_dpi = _cur_dpi;
   767 			_cur_dpi = &tmp_dpi;
   761 			_cur_dpi = &tmp_dpi;
   768 			if (!DrawStationTile(32, 16, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) {
   762 			if (!DrawStationTile(32, 16, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) {
   769 				StationPickerDrawSprite(32, 16, _cur_railtype, 3);
   763 				StationPickerDrawSprite(32, 16, _cur_railtype, INVALID_ROADTYPE, 3);
   770 			}
   764 			}
   771 			_cur_dpi = old_dpi;
   765 			_cur_dpi = old_dpi;
   772 		}
   766 		}
   773 
   767 
   774 		DrawStringCentered(74, 15 + y_offset, STR_3002_ORIENTATION, 0);
   768 		DrawStringCentered(74, 15 + y_offset, STR_3002_ORIENTATION, 0);