Changeset - r18484:e95011e0b692
[Not reviewed]
master
0 2 0
rubidium - 13 years ago 2011-11-26 18:11:22
rubidium@openttd.org
(svn r23338) -Feature [FS#4841]: diagonal dragging the rail conversion tool when pressing CTRL
2 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -1393,41 +1393,44 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
	TrainList *affected_trains = static_cast<TrainList*>(data);
 
	affected_trains->Include(Train::From(v)->First());
 

	
 
	return NULL;
 
}
 

	
 
/**
 
 * Convert one rail type to the other. You can convert normal rail to
 
 * monorail/maglev easily or vice-versa.
 
 * @param tile end tile of rail conversion drag
 
 * @param flags operation to perform
 
 * @param p1 start tile of drag
 
 * @param p2 new railtype to convert to
 
 * @param p2 various bitstuffed elements:
 
 * - p2 = (bit  0- 3) new railtype to convert to.
 
 * - p2 = (bit  4)    build diagonally or not.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RailType totype = Extract<RailType, 0, 4>(p2);
 

	
 
	if (!ValParamRailtype(totype)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TrainList affected_trains;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert.
 
	TileArea ta(tile, p1);
 
	TILE_AREA_LOOP(tile, ta) {
 
	TileIterator *iter = HasBit(p2, 4) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(ta);
 
	for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
 
		TileType tt = GetTileType(tile);
 

	
 
		/* Check if there is any track on tile */
 
		switch (tt) {
 
			case MP_RAILWAY:
 
				break;
 
			case MP_STATION:
 
				if (!HasStationRail(tile)) continue;
 
				break;
 
			case MP_ROAD:
 
				if (!IsLevelCrossing(tile)) continue;
 
				if (RailNoLevelCrossings(totype)) {
src/rail_gui.cpp
Show inline comments
 
@@ -595,25 +595,25 @@ struct BuildRailToolbarWindow : Window {
 
				break;
 

	
 
			case RTW_BUILD_TUNNEL:
 
				HandlePlacePushButton(this, RTW_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, HT_SPECIAL);
 
				this->last_user_action = widget;
 
				break;
 

	
 
			case RTW_REMOVE:
 
				BuildRailClick_Remove(this);
 
				break;
 

	
 
			case RTW_CONVERT_RAIL:
 
				HandlePlacePushButton(this, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, HT_RECT);
 
				HandlePlacePushButton(this, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, HT_RECT | HT_DIAGONAL);
 
				this->last_user_action = widget;
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 
		this->UpdateRemoveWidgetStatus(widget);
 
		if (_ctrl_pressed) RailToolbar_CtrlChanged(this);
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		int num = CheckHotkeyMatch(railtoolbar_hotkeys, keycode, this);
 
@@ -706,25 +706,25 @@ struct BuildRailToolbarWindow : Window {
 
					HandleAutodirPlacement();
 
					break;
 

	
 
				case DDSP_BUILD_SIGNALS:
 
					HandleAutoSignalPlacement();
 
					break;
 

	
 
				case DDSP_DEMOLISH_AREA:
 
					GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
 
					break;
 

	
 
				case DDSP_CONVERT_RAIL:
 
					DoCommandP(end_tile, start_tile, _cur_railtype, CMD_CONVERT_RAIL | CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL), CcPlaySound10);
 
					DoCommandP(end_tile, start_tile, _cur_railtype | (_ctrl_pressed ? 0x10 : 0), CMD_CONVERT_RAIL | CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL), CcPlaySound10);
 
					break;
 

	
 
				case DDSP_REMOVE_STATION:
 
				case DDSP_BUILD_STATION:
 
					if (this->IsWidgetLowered(RTW_BUILD_STATION)) {
 
						/* Station */
 
						if (_remove_button_clicked) {
 
							DoCommandP(end_tile, start_tile, _ctrl_pressed ? 0 : 1, CMD_REMOVE_FROM_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION), CcPlaySound1E);
 
						} else {
 
							HandleStationPlacement(start_tile, end_tile);
 
						}
 
					} else {
0 comments (0 inline, 0 general)