Changeset - r26112:8e77e1979a31
[Not reviewed]
src/airport_gui.cpp
Show inline comments
 
@@ -58,20 +58,16 @@ void CcBuildAirport(Commands cmd, const 
 
static void PlaceAirport(TileIndex tile)
 
{
 
	if (_selected_airport_index == -1) return;
 
	uint32 p2 = _ctrl_pressed;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
 
	p1 |= _selected_airport_layout << 8;
 
	byte airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
 
	byte layout = _selected_airport_layout;
 
	bool adjacent = _ctrl_pressed;
 

	
 
	auto proc = [=](bool test, StationID to_join) -> bool {
 
		if (test) {
 
			return Command<CMD_BUILD_AIRPORT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_AIRPORT>()), tile, p1, p2, {}).Succeeded();
 
			return Command<CMD_BUILD_AIRPORT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_AIRPORT>()), tile, airport_type, layout, INVALID_STATION, adjacent).Succeeded();
 
		} else {
 
			uint32 p2_final = p2;
 
			if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
			return Command<CMD_BUILD_AIRPORT>::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, p1, p2_final, {});
 
			return Command<CMD_BUILD_AIRPORT>::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, airport_type, layout, to_join, adjacent);
 
		}
 
	};
 

	
src/cmd_helper.h
Show inline comments
 
@@ -31,4 +31,15 @@ template<typename T, uint S, uint N, typ
 
	return IsInsideMM(masked, EnumPropsT<T>::begin, EnumPropsT<T>::end) ? (T)masked : EnumPropsT<T>::invalid;
 
}
 

	
 
/**
 
 * Check if an enum value is inside it's valid values.
 
 * @tparam T Type of enum.
 
 * @param v The value to validate
 
 * @return True if enum is valid.
 
 */
 
template <typename T> static constexpr inline bool IsEnumValid(T v) noexcept
 
{
 
	return IsInsideMM(v, EnumPropsT<T>::begin, EnumPropsT<T>::end);
 
}
 

	
 
#endif /* CMD_HELPER_H */
src/core/math_func.hpp
Show inline comments
 
@@ -201,7 +201,7 @@ static inline bool IsInsideBS(const T x,
 
 * @see IsInsideBS()
 
 */
 
template <typename T>
 
static inline bool IsInsideMM(const T x, const size_t min, const size_t max)
 
static constexpr inline bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
 
{
 
	return (size_t)(x - min) < (max - min);
 
}
src/depot_cmd.cpp
Show inline comments
 
@@ -39,15 +39,13 @@ static bool IsUniqueDepotName(const std:
 
/**
 
 * Rename a depot.
 
 * @param flags type of operation
 
 * @param tile unused
 
 * @param p1 id of depot
 
 * @param p2 unused
 
 * @param depot_id id of depot
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::string &text)
 
{
 
	Depot *d = Depot::GetIfValid(p1);
 
	Depot *d = Depot::GetIfValid(depot_id);
 
	if (d == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckTileOwnership(d->xy);
src/depot_cmd.h
Show inline comments
 
@@ -11,8 +11,9 @@
 
#define DEPOT_CMD_H
 

	
 
#include "command_type.h"
 
#include "depot_type.h"
 

	
 
CommandProc CmdRenameDepot;
 
CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::string &text);
 

	
 
DEF_CMD_TRAIT(CMD_RENAME_DEPOT, CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT)
 

	
src/depot_gui.cpp
Show inline comments
 
@@ -837,7 +837,7 @@ struct DepotWindow : Window {
 
		if (str == nullptr) return;
 

	
 
		/* Do depot renaming */
 
		Command<CMD_RENAME_DEPOT>::Post(STR_ERROR_CAN_T_RENAME_DEPOT, 0, this->GetDepotIndex(), 0, str);
 
		Command<CMD_RENAME_DEPOT>::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), str);
 
	}
 

	
 
	bool OnRightClick(Point pt, int widget) override
src/dock_gui.cpp
Show inline comments
 
@@ -204,7 +204,7 @@ struct BuildDocksToolbarWindow : Window 
 
				break;
 

	
 
			case WID_DT_DEPOT: // Build depot button
 
				Command<CMD_BUILD_SHIP_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT, CcBuildDocks, tile, _ship_depot_direction, 0, {});
 
				Command<CMD_BUILD_SHIP_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT, CcBuildDocks, tile, _ship_depot_direction);
 
				break;
 

	
 
			case WID_DT_STATION: { // Build station button
 
@@ -212,17 +212,12 @@ struct BuildDocksToolbarWindow : Window 
 
				DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
 
				TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
 

	
 
				uint32 p1 = _ctrl_pressed;
 
				uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
 

	
 
				bool adjacent = _ctrl_pressed;
 
				auto proc = [=](bool test, StationID to_join) -> bool {
 
					if (test) {
 
						return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, p1, p2, {}).Succeeded();
 
						return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, INVALID_STATION, adjacent).Succeeded();
 
					} else {
 
						uint32 p2_final = p2;
 
						if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
						return Command<CMD_BUILD_DOCK>::Post(STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, p1, p2_final, {});
 
						return Command<CMD_BUILD_DOCK>::Post(STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, to_join, adjacent);
 
					}
 
				};
 

	
 
@@ -231,7 +226,7 @@ struct BuildDocksToolbarWindow : Window 
 
			}
 

	
 
			case WID_DT_BUOY: // Build buoy button
 
				Command<CMD_BUILD_BUOY>::Post(STR_ERROR_CAN_T_POSITION_BUOY_HERE, CcBuildDocks, tile, 0, 0, {});
 
				Command<CMD_BUILD_BUOY>::Post(STR_ERROR_CAN_T_POSITION_BUOY_HERE, CcBuildDocks, tile);
 
				break;
 

	
 
			case WID_DT_RIVER: // Build river button (in scenario editor)
src/rail_cmd.cpp
Show inline comments
 
@@ -976,24 +976,21 @@ CommandCost CmdRemoveRailroadTrack(DoCom
 
 * Build a train depot
 
 * @param flags operation to perform
 
 * @param tile position of the train depot
 
 * @param p1 rail type
 
 * @param p2 bit 0..1 entrance direction (DiagDirection)
 
 * @param railtype rail type
 
 * @param dir entrance direction
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 *
 
 * @todo When checking for the tile slope,
 
 * distinguish between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType railtype, DiagDirection dir)
 
{
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	RailType railtype = Extract<RailType, 0, 6>(p1);
 
	if (!ValParamRailtype(railtype)) return CMD_ERROR;
 
	if (!ValParamRailtype(railtype) || !IsEnumValid(dir)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile);
 

	
 
	DiagDirection dir = Extract<DiagDirection, 0, 2>(p2);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	/* Prohibit construction if
src/rail_cmd.h
Show inline comments
 
@@ -16,7 +16,7 @@ CommandProc CmdBuildRailroadTrack;
 
CommandProc CmdRemoveRailroadTrack;
 
CommandProc CmdBuildSingleRail;
 
CommandProc CmdRemoveSingleRail;
 
CommandProc CmdBuildTrainDepot;
 
CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType railtype, DiagDirection dir);
 
CommandProc CmdBuildSingleSignal;
 
CommandProc CmdRemoveSingleSignal;
 
CommandProc CmdConvertRail;
src/rail_gui.cpp
Show inline comments
 
@@ -139,8 +139,7 @@ void CcRailDepot(Commands cmd, const Com
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_TRAIN_DEPOT>::Args>(data);
 
	DiagDirection dir = (DiagDirection)p2;
 
	auto [tile_, rt, dir] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_TRAIN_DEPOT>::Args>(data);
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
@@ -173,7 +172,7 @@ static void PlaceRail_Waypoint(TileIndex
 
	} else {
 
		/* Tile where we can't build rail waypoints. This is always going to fail,
 
		 * but provides the user with a proper error message. */
 
		Command<CMD_BUILD_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, tile, 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, {});
 
		Command<CMD_BUILD_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, tile, AXIS_X, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false);
 
	}
 
}
 

	
 
@@ -199,21 +198,21 @@ static void PlaceRail_Station(TileIndex 
 
		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION);
 
		VpSetPlaceSizingLimit(_settings_game.station.station_spread);
 
	} else {
 
		uint32 p1 = _cur_railtype | _railstation.orientation << 6 | _settings_client.gui.station_numtracks << 8 | _settings_client.gui.station_platlength << 16 | _ctrl_pressed << 24;
 
		uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
 

	
 
		int w = _settings_client.gui.station_numtracks;
 
		int h = _settings_client.gui.station_platlength;
 
		if (!_railstation.orientation) Swap(w, h);
 

	
 
		RailStationGUISettings params = _railstation;
 
		RailType rt = _cur_railtype;
 
		byte numtracks = _settings_client.gui.station_numtracks;
 
		byte platlength = _settings_client.gui.station_platlength;
 
		bool adjacent = _ctrl_pressed;
 

	
 
		auto proc = [=](bool test, StationID to_join) -> bool {
 
			if (test) {
 
				return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), tile, p1, p2, {}).Succeeded();
 
				return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), tile, rt, params.orientation, numtracks, platlength, params.station_class, params.station_type, INVALID_STATION, adjacent).Succeeded();
 
			} else {
 
				uint32 p2_final = p2;
 
				if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
				return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, tile, p1, p2_final, {});
 
				return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, tile, rt, params.orientation, numtracks, platlength, params.station_class, params.station_type, to_join, adjacent);
 
			}
 
		};
 

	
 
@@ -664,7 +663,7 @@ struct BuildRailToolbarWindow : Window {
 
				break;
 

	
 
			case WID_RAT_BUILD_DEPOT:
 
				Command<CMD_BUILD_TRAIN_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT, CcRailDepot, tile, _cur_railtype, _build_depot_direction, {});
 
				Command<CMD_BUILD_TRAIN_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT, CcRailDepot, tile, _cur_railtype, _build_depot_direction);
 
				break;
 

	
 
			case WID_RAT_BUILD_WAYPOINT:
 
@@ -734,27 +733,25 @@ struct BuildRailToolbarWindow : Window {
 
					if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) {
 
						/* Station */
 
						if (_remove_button_clicked) {
 
							Command<CMD_REMOVE_FROM_RAIL_STATION>::Post(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, _ctrl_pressed ? 0 : 1, {});
 
							Command<CMD_REMOVE_FROM_RAIL_STATION>::Post(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, _ctrl_pressed);
 
						} else {
 
							HandleStationPlacement(start_tile, end_tile);
 
						}
 
					} else {
 
						/* Waypoint */
 
						if (_remove_button_clicked) {
 
							Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_REMOVE_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, _ctrl_pressed ? 0 : 1, {});
 
							Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_REMOVE_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, _ctrl_pressed);
 
						} else {
 
							TileArea ta(start_tile, end_tile);
 
							uint32 p1 = _cur_railtype | (select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y) << 6 | ta.w << 8 | ta.h << 16 | _ctrl_pressed << 24;
 
							uint32 p2 = STAT_CLASS_WAYP | _cur_waypoint_type << 8 | INVALID_STATION << 16;
 
							Axis axis = select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y;
 
							bool adjacent = _ctrl_pressed;
 
							byte waypoint_type = _cur_waypoint_type;
 

	
 
							auto proc = [=](bool test, StationID to_join) -> bool {
 
								if (test) {
 
									return Command<CMD_BUILD_RAIL_WAYPOINT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_WAYPOINT>()), ta.tile, p1, p2, {}).Succeeded();
 
									return Command<CMD_BUILD_RAIL_WAYPOINT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_WAYPOINT>()), ta.tile, axis, ta.w, ta.h, STAT_CLASS_WAYP, waypoint_type, INVALID_STATION, adjacent).Succeeded();
 
								} else {
 
									uint32 p2_final = p2;
 
									if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
									return Command<CMD_BUILD_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, ta.tile, p1, p2_final, {});
 
									return Command<CMD_BUILD_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, ta.tile, axis, ta.w, ta.h, STAT_CLASS_WAYP, waypoint_type, to_join, adjacent);
 
								}
 
							};
 

	
 
@@ -913,17 +910,15 @@ static void HandleStationPlacement(TileI
 

	
 
	if (_railstation.orientation == AXIS_X) Swap(numtracks, platlength);
 

	
 
	uint32 p1 = _cur_railtype | _railstation.orientation << 6 | numtracks << 8 | platlength << 16 | _ctrl_pressed << 24;
 
	uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
 
	RailStationGUISettings params = _railstation;
 
	RailType rt = _cur_railtype;
 
	bool adjacent = _ctrl_pressed;
 

	
 
	auto proc = [=](bool test, StationID to_join) -> bool {
 
		if (test) {
 
			return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), ta.tile, p1, p2, {}).Succeeded();
 
			return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), ta.tile, rt, params.orientation, numtracks, platlength, params.station_class, params.station_type, INVALID_STATION, adjacent).Succeeded();
 
		} else {
 
			uint32 p2_final = p2;
 
			if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
			return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, ta.tile, p1, p2_final, {});
 
			return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, ta.tile, rt, params.orientation, numtracks, platlength, params.station_class, params.station_type, to_join, adjacent);
 
		}
 
	};
 

	
src/road_cmd.cpp
Show inline comments
 
@@ -1157,21 +1157,16 @@ CommandCost CmdRemoveLongRoad(DoCommandF
 
 * Build a road depot.
 
 * @param tile tile where to build the depot
 
 * @param flags operation to perform
 
 * @param p1 bit 0..1 entrance direction (DiagDirection)
 
 *           bit 2..7 road type
 
 * @param p2 unused
 
 * @param text unused
 
 * @param rt road type
 
 * @param dir entrance direction
 
 * @return the cost of this operation or an error
 
 *
 
 * @todo When checking for the tile slope,
 
 * distinguish between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
 
{
 
	DiagDirection dir = Extract<DiagDirection, 0, 2>(p1);
 

	
 
	RoadType rt = Extract<RoadType, 2, 6>(p1);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 
	if (!ValParamRoadType(rt) || !IsEnumValid(dir)) return CMD_ERROR;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
src/road_cmd.h
Show inline comments
 
@@ -20,7 +20,7 @@ void UpdateNearestTownForRoadTiles(bool 
 
CommandProc CmdBuildLongRoad;
 
CommandProc CmdRemoveLongRoad;
 
CommandProc CmdBuildRoad;
 
CommandProc CmdBuildRoadDepot;
 
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir);
 
CommandProc CmdConvertRoad;
 

	
 
DEF_CMD_TRAIT(CMD_BUILD_LONG_ROAD,  CmdBuildLongRoad,  CMD_AUTO | CMD_NO_WATER | CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION)
src/road_gui.cpp
Show inline comments
 
@@ -133,9 +133,8 @@ void CcRoadDepot(Commands cmd, const Com
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_DEPOT>::Args>(data);
 
	auto [tile_, rt, dir] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_DEPOT>::Args>(data);
 

	
 
	DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	ConnectRoadToStructure(tile, dir);
 
@@ -146,32 +145,22 @@ void CcRoadDepot(Commands cmd, const Com
 
 * @param result Result of the build road stop command.
 
 * @param cmd Unused.
 
 * @param tile Start tile.
 
 * @param p1 bit 0..7: Width of the road stop.
 
 *           bit 8..15: Length of the road stop.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2: Allow stations directly adjacent to other stations.
 
 *           bit 3..4: Entrance direction (#DiagDirection) for normal stops.
 
 *           bit 3: #Axis of the road for drive-through stops.
 
 *           bit 5..9: The roadtype.
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @param text Unused.
 
 * @param data Command data.
 
 * @see CmdBuildRoadStop
 
 */
 
void CcRoadStop(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_STOP>::Args>(data);
 
	auto [tile_, width, length, stop_type, is_drive_through, dir, rt, station_to_join, adjacent] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_STOP>::Args>(data);
 

	
 
	DiagDirection dir = (DiagDirection)GB(p2, 3, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	TileArea roadstop_area(tile, GB(p1, 0, 8), GB(p1, 8, 8));
 
	TileArea roadstop_area(tile, width, length);
 
	for (TileIndex cur_tile : roadstop_area) {
 
		ConnectRoadToStructure(cur_tile, dir);
 
		/* For a drive-through road stop build connecting road for other entrance. */
 
		if (HasBit(p2, 1)) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
 
		if (is_drive_through) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
 
	}
 
}
 

	
 
@@ -179,34 +168,24 @@ void CcRoadStop(Commands cmd, const Comm
 
 * Place a new road stop.
 
 * @param start_tile First tile of the area.
 
 * @param end_tile Last tile of the area.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 2: Allow stations directly adjacent to other stations.
 
 *           bit 5..10: The roadtypes.
 
 * @param stop_type Type of stop (bus/truck).
 
 * @param adjacent Allow stations directly adjacent to other stations.
 
 * @param rt The roadtypes.
 
 * @param err_msg Error message to show.
 
 * @see CcRoadStop()
 
 */
 
static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, StringID err_msg)
 
static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
 
{
 
	TileArea ta(start_tile, end_tile);
 
	uint32 p1 = (uint32)(ta.w | ta.h << 8);
 

	
 
	uint8 ddir = _road_station_picker_orientation;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	if (ddir >= DIAGDIR_END) {
 
		SetBit(p2, 1); // It's a drive-through stop.
 
		ddir -= DIAGDIR_END; // Adjust picker result to actual direction.
 
	}
 
	p2 |= ddir << 3; // Set the DiagDirecion into p2 bits 3 and 4.
 
	DiagDirection ddir = _road_station_picker_orientation;
 
	bool drive_through = ddir >= DIAGDIR_END;
 
	if (drive_through) ddir = static_cast<DiagDirection>(ddir - DIAGDIR_END); // Adjust picker result to actual direction.
 

	
 
	auto proc = [=](bool test, StationID to_join) -> bool {
 
		if (test) {
 
			return Command<CMD_BUILD_ROAD_STOP>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_ROAD_STOP>()), ta.tile, p1, p2, {}).Succeeded();
 
			return Command<CMD_BUILD_ROAD_STOP>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_ROAD_STOP>()), ta.tile, ta.w, ta.h, stop_type, drive_through, ddir, rt, INVALID_STATION, adjacent).Succeeded();
 
		} else {
 
			uint32 p2_final = p2;
 
			if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
 

	
 
			return Command<CMD_BUILD_ROAD_STOP>::Post(err_msg, CcRoadStop, ta.tile, p1, p2_final, {});
 
			return Command<CMD_BUILD_ROAD_STOP>::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through, ddir, rt, to_join, adjacent);
 
		}
 
	};
 

	
 
@@ -568,7 +547,7 @@ struct BuildRoadToolbarWindow : Window {
 

	
 
			case WID_ROT_DEPOT:
 
				Command<CMD_BUILD_ROAD_DEPOT>::Post(this->rti->strings.err_depot, CcRoadDepot,
 
						tile, _cur_roadtype << 2 | _road_depot_orientation, 0, {});
 
						tile, _cur_roadtype, _road_depot_orientation);
 
				break;
 

	
 
			case WID_ROT_BUS_STATION:
 
@@ -700,9 +679,9 @@ struct BuildRoadToolbarWindow : Window {
 
					if (this->IsWidgetLowered(WID_ROT_BUS_STATION)) {
 
						if (_remove_button_clicked) {
 
							TileArea ta(start_tile, end_tile);
 
							Command<CMD_REMOVE_ROAD_STOP>::Post(this->rti->strings.err_remove_station[ROADSTOP_BUS], CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w | ta.h << 8, (_ctrl_pressed << 1) | ROADSTOP_BUS, {});
 
							Command<CMD_REMOVE_ROAD_STOP>::Post(this->rti->strings.err_remove_station[ROADSTOP_BUS], CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, ROADSTOP_BUS, _ctrl_pressed);
 
						} else {
 
							PlaceRoadStop(start_tile, end_tile, _cur_roadtype << 5 | (_ctrl_pressed << 2) | ROADSTOP_BUS, this->rti->strings.err_build_station[ROADSTOP_BUS]);
 
							PlaceRoadStop(start_tile, end_tile, ROADSTOP_BUS, _ctrl_pressed, _cur_roadtype, this->rti->strings.err_build_station[ROADSTOP_BUS]);
 
						}
 
					}
 
					break;
 
@@ -712,9 +691,9 @@ struct BuildRoadToolbarWindow : Window {
 
					if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION)) {
 
						if (_remove_button_clicked) {
 
							TileArea ta(start_tile, end_tile);
 
							Command<CMD_REMOVE_ROAD_STOP>::Post(this->rti->strings.err_remove_station[ROADSTOP_TRUCK], CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w | ta.h << 8, (_ctrl_pressed << 1) | ROADSTOP_TRUCK, {});
 
							Command<CMD_REMOVE_ROAD_STOP>::Post(this->rti->strings.err_remove_station[ROADSTOP_TRUCK], CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, ROADSTOP_TRUCK, _ctrl_pressed);
 
						} else {
 
							PlaceRoadStop(start_tile, end_tile, _cur_roadtype << 5 | (_ctrl_pressed << 2) | ROADSTOP_TRUCK, this->rti->strings.err_build_station[ROADSTOP_TRUCK]);
 
							PlaceRoadStop(start_tile, end_tile, ROADSTOP_TRUCK, _ctrl_pressed, _cur_roadtype, this->rti->strings.err_build_station[ROADSTOP_TRUCK]);
 
						}
 
					}
 
					break;
src/script/api/script_airport.cpp
Show inline comments
 
@@ -77,9 +77,7 @@
 
	EnforcePrecondition(false, IsValidAirportType(type));
 
	EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
 

	
 
	uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
 
	p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
	return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, p2, {});
 
	return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION), station_id == ScriptStation::STATION_JOIN_ADJACENT);
 
}
 

	
 
/* static */ bool ScriptAirport::RemoveAirport(TileIndex tile)
src/script/api/script_basestation.cpp
Show inline comments
 
@@ -45,9 +45,9 @@
 
	EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
 

	
 
	if (::Station::IsValidID(station_id)) {
 
		return ScriptObject::Command<CMD_RENAME_STATION>::Do(0, station_id, 0, text);
 
		return ScriptObject::Command<CMD_RENAME_STATION>::Do(station_id, text);
 
	} else {
 
		return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(0, station_id, 0, text);
 
		return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(station_id, text);
 
	}
 
}
 

	
src/script/api/script_marine.cpp
Show inline comments
 
@@ -83,7 +83,7 @@
 
	EnforcePrecondition(false, ::IsValidTile(front));
 
	EnforcePrecondition(false, (::TileX(front) == ::TileX(tile)) != (::TileY(front) == ::TileY(tile)));
 

	
 
	return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile), 0, {});
 
	return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile) ? AXIS_Y : AXIS_X);
 
}
 

	
 
/* static */ bool ScriptMarine::BuildDock(TileIndex tile, StationID station_id)
 
@@ -92,9 +92,7 @@
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
 

	
 
	uint p1 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
 
	uint p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
	return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, p1, p2, {});
 
	return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, station_id != ScriptStation::STATION_JOIN_ADJACENT);
 
}
 

	
 
/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile)
 
@@ -102,7 +100,7 @@
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 

	
 
	return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile, 0, 0, {});
 
	return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile);
 
}
 

	
 
/* static */ bool ScriptMarine::BuildLock(TileIndex tile)
src/script/api/script_rail.cpp
Show inline comments
 
@@ -142,9 +142,9 @@
 
	EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
 
	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 

	
 
	uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
 
	DiagDirection entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? DIAGDIR_SE : DIAGDIR_NW) : (::TileX(tile) < ::TileX(front) ? DIAGDIR_SW : DIAGDIR_NE);
 

	
 
	return ScriptObject::Command<CMD_BUILD_TRAIN_DEPOT>::Do(tile, ScriptObject::GetRailType(), entrance_dir, {});
 
	return ScriptObject::Command<CMD_BUILD_TRAIN_DEPOT>::Do(tile, (::RailType)ScriptObject::GetRailType(), entrance_dir);
 
}
 

	
 
/* static */ bool ScriptRail::BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id)
 
@@ -157,10 +157,8 @@
 
	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 
	EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
 

	
 
	uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
 
	if (direction == RAILTRACK_NW_SE) p1 |= (1 << 6);
 
	if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
 
	return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, {});
 
	bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
 
	return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, adjacent);
 
}
 

	
 
/* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
 
@@ -176,10 +174,6 @@
 
	EnforcePrecondition(false, source_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(source_industry));
 
	EnforcePrecondition(false, goal_industry   == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry   == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry));
 

	
 
	uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
 
	if (direction == RAILTRACK_NW_SE) p1 |= 1 << 6;
 
	if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
 

	
 
	const GRFFile *file;
 
	uint16 res = GetAiPurchaseCallbackResult(
 
		GSF_STATIONS,
 
@@ -193,7 +187,10 @@
 
		std::min(15u, num_platforms) << 4 | std::min(15u, platform_length),
 
		&file
 
	);
 
	uint32 p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 

	
 
	Axis axis = direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X;
 
	bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
 
	StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
 
	if (res != CALLBACK_FAILED) {
 
		int index = 0;
 
		const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index);
 
@@ -201,11 +198,11 @@
 
			Debug(grf, 1, "{} returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
 
		} else {
 
			/* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */
 
			if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2 | spec->cls_id | index << 8, {})) return true;
 
			if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, spec->cls_id, index, to_join, adjacent)) return true;
 
		}
 
	}
 

	
 
	return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2, {});
 
	return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, STAT_CLASS_DFLT, 0, to_join, adjacent);
 
}
 

	
 
/* static */ bool ScriptRail::BuildRailWaypoint(TileIndex tile)
 
@@ -216,7 +213,7 @@
 
	EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE);
 
	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 

	
 
	return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 6 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, {});
 
	return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false);
 
}
 

	
 
/* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
 
@@ -225,7 +222,7 @@
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, ::IsValidTile(tile2));
 

	
 
	return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(tile, tile2, keep_rail ? 1 : 0, {});
 
	return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(tile, tile2, keep_rail);
 
}
 

	
 
/* static */ bool ScriptRail::RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
 
@@ -234,7 +231,7 @@
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, ::IsValidTile(tile2));
 

	
 
	return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(tile, tile2, keep_rail ? 1 : 0, {});
 
	return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(tile, tile2, keep_rail);
 
}
 

	
 
/* static */ uint ScriptRail::GetRailTracks(TileIndex tile)
src/script/api/script_road.cpp
Show inline comments
 
@@ -529,9 +529,9 @@ static bool NeighbourHasReachableRoad(::
 
	EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
 
	EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
 

	
 
	uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
 
	DiagDirection entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? DIAGDIR_SE : DIAGDIR_NW) : (::TileX(tile) < ::TileX(front) ? DIAGDIR_SW : DIAGDIR_NE);
 

	
 
	return ScriptObject::Command<CMD_BUILD_ROAD_DEPOT>::Do(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, {});
 
	return ScriptObject::Command<CMD_BUILD_ROAD_DEPOT>::Do(tile, ScriptObject::GetRoadType(), entrance_dir);
 
}
 

	
 
/* static */ bool ScriptRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id)
 
@@ -545,20 +545,10 @@ static bool NeighbourHasReachableRoad(::
 
	EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK);
 
	EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
 

	
 
	uint entrance_dir;
 
	if (drive_through) {
 
		entrance_dir = ::TileY(tile) != ::TileY(front);
 
	} else {
 
		entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
 
	}
 

	
 
	uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 4;
 
	p2 |= drive_through ? 2 : 0;
 
	p2 |= road_veh_type == ROADVEHTYPE_TRUCK ? 1 : 0;
 
	p2 |= ScriptObject::GetRoadType() << 5;
 
	p2 |= entrance_dir << 3;
 
	p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
	return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1 | 1 << 8, p2, {});
 
	DiagDirection entrance_dir = DiagdirBetweenTiles(tile, front);
 
	RoadStopType stop_type = road_veh_type == ROADVEHTYPE_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 
	StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
 
	return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1, 1, stop_type, drive_through, entrance_dir, ScriptObject::GetRoadType(), to_join, station_id != ScriptStation::STATION_JOIN_ADJACENT);
 
}
 

	
 
/* static */ bool ScriptRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id)
 
@@ -612,7 +602,7 @@ static bool NeighbourHasReachableRoad(::
 
	EnforcePrecondition(false, IsTileType(tile, MP_STATION));
 
	EnforcePrecondition(false, IsRoadStop(tile));
 

	
 
	return ScriptObject::Command<CMD_REMOVE_ROAD_STOP>::Do(tile, 1 | 1 << 8, GetRoadStopType(tile), {});
 
	return ScriptObject::Command<CMD_REMOVE_ROAD_STOP>::Do(tile, 1, 1, GetRoadStopType(tile), false);
 
}
 

	
 
/* static */ Money ScriptRoad::GetBuildCost(RoadType roadtype, BuildType build_type)
src/script/api/script_station.cpp
Show inline comments
 
@@ -240,5 +240,5 @@ template<bool Tfrom, bool Tvia>
 
	EnforcePrecondition(false, IsValidStation(station_id));
 
	EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
 

	
 
	return ScriptObject::Command<CMD_OPEN_CLOSE_AIRPORT>::Do(0, station_id, 0, {});
 
	return ScriptObject::Command<CMD_OPEN_CLOSE_AIRPORT>::Do(station_id);
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -1241,37 +1241,23 @@ static void RestoreTrainReservation(Trai
 
 * Build rail station
 
 * @param flags operation to perform
 
 * @param tile_org northern most position of station dragging/placement
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0- 5) - railtype
 
 * - p1 = (bit  6)    - orientation (Axis)
 
 * - p1 = (bit  8-15) - number of tracks
 
 * - p1 = (bit 16-23) - platform length
 
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - custom station class
 
 * - p2 = (bit  8-15) - custom station id
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @param rt railtype
 
 * @param axis orientation (Axis)
 
 * @param numtracks number of tracks
 
 * @param plat_len platform length
 
 * @param spec_class custom station class
 
 * @param spec_index custom station id
 
 * @param station_to_join station ID to join (NEW_STATION if build new one)
 
 * @param adjacent allow stations directly adjacent to other stations.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailType rt, Axis axis, byte numtracks, byte plat_len, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent)
 
{
 
	/* Unpack parameters */
 
	RailType rt    = Extract<RailType, 0, 6>(p1);
 
	Axis axis      = Extract<Axis, 6, 1>(p1);
 
	byte numtracks = GB(p1,  8, 8);
 
	byte plat_len  = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
	/* Does the authority allow this? */
 
	CommandCost ret = CheckIfAuthorityAllowsNewStation(tile_org, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	if (!ValParamRailtype(rt)) return CMD_ERROR;
 
	if (!ValParamRailtype(rt) || !IsEnumValid(axis)) return CMD_ERROR;
 

	
 
	/* Check if the given station class is valid */
 
	if ((uint)spec_class >= StationClass::GetClassCount() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
 
@@ -1657,21 +1643,19 @@ CommandCost RemoveFromRailBaseStation(Ti
 
 * This allows for custom-built station with holes and weird layouts
 
 * @param flags operation to perform
 
 * @param start tile of station piece to remove
 
 * @param p1 start_tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = bit 0 - if set keep the rail
 
 * @param text unused
 
 * @param end other edge of the rect to remove
 
 * @param keep_rail if set keep the rail
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveFromRailStation(DoCommandFlag flags, TileIndex start, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRemoveFromRailStation(DoCommandFlag flags, TileIndex start, TileIndex end, bool keep_rail)
 
{
 
	TileIndex end = p1 == 0 ? start : p1;
 
	if (end == 0) end = start;
 
	if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
 

	
 
	TileArea ta(start, end);
 
	std::vector<Station *> affected_stations;
 

	
 
	CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_STATION_RAIL], HasBit(p2, 0));
 
	CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_STATION_RAIL], keep_rail);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Do all station specific functions here. */
 
@@ -1691,21 +1675,19 @@ CommandCost CmdRemoveFromRailStation(DoC
 
 * This allows for custom-built waypoint with holes and weird layouts
 
 * @param flags operation to perform
 
 * @param start tile of waypoint piece to remove
 
 * @param p1 start_tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = bit 0 - if set keep the rail
 
 * @param text unused
 
 * @param end other edge of the rect to remove
 
 * @param keep_rail if set keep the rail
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveFromRailWaypoint(DoCommandFlag flags, TileIndex start, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRemoveFromRailWaypoint(DoCommandFlag flags, TileIndex start, TileIndex end, bool keep_rail)
 
{
 
	TileIndex end = p1 == 0 ? start : p1;
 
	if (end == 0) end = start;
 
	if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
 

	
 
	TileArea ta(start, end);
 
	std::vector<Waypoint *> affected_stations;
 

	
 
	return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_WAYPOINT_RAIL], HasBit(p2, 0));
 
	return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_WAYPOINT_RAIL], keep_rail);
 
}
 

	
 

	
 
@@ -1756,7 +1738,7 @@ static CommandCost RemoveRailStation(Til
 
{
 
	/* if there is flooding, remove platforms tile by tile */
 
	if (_current_company == OWNER_WATER) {
 
		return Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(DC_EXEC, tile, 0, 0, {});
 
		return Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(DC_EXEC, tile, 0, false);
 
	}
 

	
 
	Station *st = Station::GetByTile(tile);
 
@@ -1777,7 +1759,7 @@ static CommandCost RemoveRailWaypoint(Ti
 
{
 
	/* if there is flooding, remove waypoints tile by tile */
 
	if (_current_company == OWNER_WATER) {
 
		return Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(DC_EXEC, tile, 0, 0, {});
 
		return Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(DC_EXEC, tile, 0, false);
 
	}
 

	
 
	return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]);
 
@@ -1824,32 +1806,23 @@ static CommandCost FindJoiningRoadStop(S
 
 * Build a bus or truck stop.
 
 * @param flags Operation to perform.
 
 * @param tile Northernmost tile of the stop.
 
 * @param p1 bit 0..7: Width of the road stop.
 
 *           bit 8..15: Length of the road stop.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2: Allow stations directly adjacent to other stations.
 
 *           bit 3..4: Entrance direction (#DiagDirection) for normal stops.
 
 *           bit 3: #Axis of the road for drive-through stops.
 
 *           bit 5..10: The roadtype.
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @param text Unused.
 
 * @param width Width of the road stop.
 
 * @param length Length of the road stop.
 
 * @param stop_type Type of road stop (bus/truck).
 
 * @param is_drive_through False for normal stops, true for drive-through.
 
 * @param ddir Entrance direction (#DiagDirection) for normal stops. Converted to the axis for drive-through stops.
 
 * @param rt The roadtype.
 
 * @param station_to_join Station ID to join (NEW_STATION if build new one).
 
 * @param adjacent Allow stations directly adjacent to other stations.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8 width, uint8 length, RoadStopType stop_type, bool is_drive_through, DiagDirection ddir, RoadType rt, StationID station_to_join, bool adjacent)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	RoadType rt = Extract<RoadType, 5, 6>(p2);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	if (!ValParamRoadType(rt) || !IsEnumValid(ddir) || stop_type >= ROADSTOP_END) return CMD_ERROR;
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	uint8 width = (uint8)GB(p1, 0, 8);
 
	uint8 length = (uint8)GB(p1, 8, 8);
 

	
 
	/* Check if the requested road stop is too big */
 
	if (width > _settings_game.station.station_spread || length > _settings_game.station.station_spread) return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
 
	/* Check for incorrect width / length. */
 
@@ -1864,34 +1837,26 @@ CommandCost CmdBuildRoadStop(DoCommandFl
 
	/* Trams only have drive through stops */
 
	if (!is_drive_through && RoadTypeIsTram(rt)) return CMD_ERROR;
 

	
 
	DiagDirection ddir;
 
	Axis axis;
 
	if (is_drive_through) {
 
		/* By definition axis is valid, due to there being 2 axes and reading 1 bit. */
 
		axis = Extract<Axis, 3, 1>(p2);
 
		ddir = AxisToDiagDir(axis);
 
	} else {
 
		/* By definition ddir is valid, due to there being 4 diagonal directions and reading 2 bits. */
 
		ddir = Extract<DiagDirection, 3, 2>(p2);
 
		axis = DiagDirToAxis(ddir);
 
	}
 
	Axis axis = DiagDirToAxis(ddir);
 

	
 
	CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	bool is_truck_stop = stop_type != ROADSTOP_BUS;
 

	
 
	/* Total road stop cost. */
 
	CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
 
	CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[is_truck_stop ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
 
	StationID est = INVALID_STATION;
 
	ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << axis : 1 << ddir, is_drive_through, type, axis, &est, rt);
 
	ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << axis : 1 << ddir, is_drive_through, is_truck_stop, axis, &est, rt);
 
	if (ret.Failed()) return ret;
 
	cost.AddCost(ret);
 

	
 
	Station *st = nullptr;
 
	ret = FindJoiningRoadStop(est, station_to_join, HasBit(p2, 2), roadstop_area, &st);
 
	ret = FindJoiningRoadStop(est, station_to_join, adjacent, roadstop_area, &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Check if this number of road stops can be allocated. */
 
	if (!RoadStop::CanAllocateItem(roadstop_area.w * roadstop_area.h)) return_cmd_error(type ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
 
	if (!RoadStop::CanAllocateItem(roadstop_area.w * roadstop_area.h)) return_cmd_error(is_truck_stop ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
 

	
 
	ret = BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
 
	if (ret.Failed()) return ret;
 
@@ -1911,21 +1876,21 @@ CommandCost CmdBuildRoadStop(DoCommandFl
 

	
 
			RoadStop *road_stop = new RoadStop(cur_tile);
 
			/* Insert into linked list of RoadStops. */
 
			RoadStop **currstop = FindRoadStopSpot(type, st);
 
			RoadStop **currstop = FindRoadStopSpot(is_truck_stop, st);
 
			*currstop = road_stop;
 

	
 
			if (type) {
 
			if (is_truck_stop) {
 
				st->truck_station.Add(cur_tile);
 
			} else {
 
				st->bus_station.Add(cur_tile);
 
			}
 

	
 
			/* Initialize an empty station. */
 
			st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, cur_tile);
 
			st->AddFacility(is_truck_stop ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, cur_tile);
 

	
 
			st->rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
 

	
 
			RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 
			RoadStopType rs_type = is_truck_stop ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 
			if (is_drive_through) {
 
				/* Update company infrastructure counts. If the current tile is a normal road tile, remove the old
 
				 * bits first. */
 
@@ -1956,7 +1921,7 @@ CommandCost CmdBuildRoadStop(DoCommandFl
 
	}
 

	
 
	if (st != nullptr) {
 
		st->AfterStationTileSetChange(true, type ? STATION_TRUCK: STATION_BUS);
 
		st->AfterStationTileSetChange(true, is_truck_stop ? STATION_TRUCK: STATION_BUS);
 
	}
 
	return cost;
 
}
 
@@ -2079,25 +2044,21 @@ static CommandCost RemoveRoadStop(TileIn
 
 * Remove bus or truck stops.
 
 * @param flags Operation to perform.
 
 * @param tile Northernmost tile of the removal area.
 
 * @param p1 bit 0..7: Width of the removal area.
 
 *           bit 8..15: Height of the removal area.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 * @param p2 bit 1: 0 to keep roads of all drive-through stops, 1 to remove them.
 
 * @param text Unused.
 
 * @param width Width of the removal area.
 
 * @param height Height of the removal area.
 
 * @param stop_type Type of stop (bus/truck).
 
 * @param remove_road Remove roads of drive-through stops?
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdRemoveRoadStop(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRemoveRoadStop(DoCommandFlag flags, TileIndex tile, uint8 width, uint height, RoadStopType stop_type, bool remove_road)
 
{
 
	uint8 width = (uint8)GB(p1, 0, 8);
 
	uint8 height = (uint8)GB(p1, 8, 8);
 
	bool keep_drive_through_roads = !HasBit(p2, 1);
 

	
 
	if (stop_type >= ROADSTOP_END) return CMD_ERROR;
 
	/* Check for incorrect width / height. */
 
	if (width == 0 || height == 0) return CMD_ERROR;
 
	/* Check if the first tile and the last tile are valid */
 
	if (!IsValidTile(tile) || TileAddWrap(tile, width - 1, height - 1) == INVALID_TILE) return CMD_ERROR;
 
	/* Bankrupting company is not supposed to remove roads, there may be road vehicles. */
 
	if (!keep_drive_through_roads && (flags & DC_BANKRUPT)) return CMD_ERROR;
 
	if (remove_road && (flags & DC_BANKRUPT)) return CMD_ERROR;
 

	
 
	TileArea roadstop_area(tile, width, height);
 

	
 
@@ -2107,7 +2068,7 @@ CommandCost CmdRemoveRoadStop(DoCommandF
 

	
 
	for (TileIndex cur_tile : roadstop_area) {
 
		/* Make sure the specified tile is a road stop of the correct type */
 
		if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
 
		if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || GetRoadStopType(cur_tile) != stop_type) continue;
 

	
 
		/* Save information on to-be-restored roads before the stop is removed. */
 
		RoadBits road_bits = ROAD_NONE;
 
@@ -2119,7 +2080,7 @@ CommandCost CmdRemoveRoadStop(DoCommandF
 
				if (road_type[rtt] == INVALID_ROADTYPE) continue;
 
				road_owner[rtt] = GetRoadOwner(cur_tile, rtt);
 
				/* If we don't want to preserve our roads then restore only roads of others. */
 
				if (!keep_drive_through_roads && road_owner[rtt] == _current_company) road_type[rtt] = INVALID_ROADTYPE;
 
				if (remove_road && road_owner[rtt] == _current_company) road_type[rtt] = INVALID_ROADTYPE;
 
			}
 
			road_bits = AxisToRoadBits(DiagDirToAxis(GetRoadStopDir(cur_tile)));
 
		}
 
@@ -2236,23 +2197,17 @@ void UpdateAirportsNoise()
 
 * Place an Airport.
 
 * @param flags operation to perform
 
 * @param tile tile where airport will be built
 
 * @param p1
 
 * - p1 = (bit  0- 7) - airport type, @see airport.h
 
 * - p1 = (bit  8-15) - airport layout
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit     0) - allow airports directly adjacent to other airports.
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @param airport_type airport type, @see airport.h
 
 * @param layout airport layout
 
 * @param station_to_join station ID to join (NEW_STATION if build new one)
 
 * @param allow_adjacent allow airports directly adjacent to other airports.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, byte airport_type, byte layout, StationID station_to_join, bool allow_adjacent)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
	byte airport_type = GB(p1, 0, 8);
 
	byte layout = GB(p1, 8, 8);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
@@ -2313,7 +2268,7 @@ CommandCost CmdBuildAirport(DoCommandFla
 
	}
 

	
 
	Station *st = nullptr;
 
	ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), airport_area, &st);
 
	ret = FindJoiningStation(INVALID_STATION, station_to_join, allow_adjacent, airport_area, &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
 
@@ -2456,16 +2411,13 @@ static CommandCost RemoveAirport(TileInd
 
/**
 
 * Open/close an airport to incoming aircraft.
 
 * @param flags Operation to perform.
 
 * @param tile Unused.
 
 * @param p1 Station ID of the airport.
 
 * @param p2 Unused.
 
 * @param text unused
 
 * @param station_id Station ID of the airport.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdOpenCloseAirport(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id)
 
{
 
	if (!Station::IsValidID(p1)) return CMD_ERROR;
 
	Station *st = Station::Get(p1);
 
	if (!Station::IsValidID(station_id)) return CMD_ERROR;
 
	Station *st = Station::Get(station_id);
 

	
 
	if (!(st->facilities & FACIL_AIRPORT) || st->owner == OWNER_NONE) return CMD_ERROR;
 

	
 
@@ -2512,14 +2464,12 @@ static const byte _dock_h_chk[4] = { 1, 
 
 * Build a dock/haven.
 
 * @param flags operation to perform
 
 * @param tile tile where dock will be built
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 bit 16-31: station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @param station_to_join station ID to join (NEW_STATION if build new one)
 
 * @param adjacent allow docks directly adjacent to other docks.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_to_join, bool adjacent)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
@@ -2567,7 +2517,7 @@ CommandCost CmdBuildDock(DoCommandFlag f
 

	
 
	/* middle */
 
	Station *st = nullptr;
 
	ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0), dock_area, &st);
 
	ret = FindJoiningStation(INVALID_STATION, station_to_join, adjacent, dock_area, &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
 
@@ -3930,15 +3880,13 @@ static bool IsUniqueStationName(const st
 
/**
 
 * Rename a station
 
 * @param flags operation to perform
 
 * @param tile unused
 
 * @param p1 station ID that is to be renamed
 
 * @param p2 unused
 
 * @param station_id station ID that is to be renamed
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameStation(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRenameStation(DoCommandFlag flags, StationID station_id, const std::string &text)
 
{
 
	Station *st = Station::GetIfValid(p1);
 
	Station *st = Station::GetIfValid(station_id);
 
	if (st == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(st->owner);
 
@@ -4244,7 +4192,7 @@ static void ChangeTileOwner_Station(Tile
 
	} else {
 
		if (IsDriveThroughStopTile(tile)) {
 
			/* Remove the drive-through road stop */
 
			Command<CMD_REMOVE_ROAD_STOP>::Do(DC_EXEC | DC_BANKRUPT, tile, 1 | 1 << 8, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, {});
 
			Command<CMD_REMOVE_ROAD_STOP>::Do(DC_EXEC | DC_BANKRUPT, tile, 1, 1, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, false);
 
			assert(IsTileType(tile, MP_ROAD));
 
			/* Change owner of tile and all roadtypes */
 
			ChangeTileOwner(tile, old_owner, new_owner);
src/station_cmd.h
Show inline comments
 
@@ -11,15 +11,18 @@
 
#define STATION_CMD_H
 

	
 
#include "command_type.h"
 
#include "station_type.h"
 

	
 
CommandProc CmdBuildAirport;
 
CommandProc CmdBuildDock;
 
CommandProc CmdBuildRailStation;
 
CommandProc CmdRemoveFromRailStation;
 
CommandProc CmdBuildRoadStop;
 
CommandProc CmdRemoveRoadStop;
 
CommandProc CmdRenameStation;
 
CommandProc CmdOpenCloseAirport;
 
enum StationClassID : byte;
 

	
 
CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, byte airport_type, byte layout, StationID station_to_join, bool allow_adjacent);
 
CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_to_join, bool adjacent);
 
CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailType rt, Axis axis, byte numtracks, byte plat_len, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent);
 
CommandCost CmdRemoveFromRailStation(DoCommandFlag flags, TileIndex start, TileIndex end, bool keep_rail);
 
CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8 width, uint8 length, RoadStopType stop_type, bool is_drive_through, DiagDirection ddir, RoadType rt, StationID station_to_join, bool adjacent);
 
CommandCost CmdRemoveRoadStop(DoCommandFlag flags, TileIndex tile, uint8 width, uint height, RoadStopType stop_type, bool remove_road);
 
CommandCost CmdRenameStation(DoCommandFlag flags, StationID station_id, const std::string &text);
 
CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id);
 

	
 
DEF_CMD_TRAIT(CMD_BUILD_AIRPORT,            CmdBuildAirport,          CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION)
 
DEF_CMD_TRAIT(CMD_BUILD_DOCK,               CmdBuildDock,             CMD_AUTO,                CMDT_LANDSCAPE_CONSTRUCTION)
src/station_gui.cpp
Show inline comments
 
@@ -1948,7 +1948,7 @@ struct StationViewWindow : public Window
 
				break;
 

	
 
			case WID_SV_CLOSE_AIRPORT:
 
				Command<CMD_OPEN_CLOSE_AIRPORT>::Post(0, this->window_number, 0, {});
 
				Command<CMD_OPEN_CLOSE_AIRPORT>::Post(this->window_number);
 
				break;
 

	
 
			case WID_SV_TRAINS:   // Show list of scheduled trains to this station
 
@@ -2085,7 +2085,7 @@ struct StationViewWindow : public Window
 
	{
 
		if (str == nullptr) return;
 

	
 
		Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, 0, this->window_number, 0, str);
 
		Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str);
 
	}
 

	
 
	void OnResize() override
src/station_type.h
Show inline comments
 
@@ -41,9 +41,10 @@ enum StationType {
 
};
 

	
 
/** Types of RoadStops */
 
enum RoadStopType {
 
enum RoadStopType : byte {
 
	ROADSTOP_BUS,    ///< A standard stop for buses
 
	ROADSTOP_TRUCK,  ///< A standard stop for trucks
 
	ROADSTOP_END,    ///< End of valid types
 
};
 

	
 
/** The facilities a station might be having */
src/water_cmd.cpp
Show inline comments
 
@@ -95,15 +95,12 @@ static void MarkCanalsAndRiversAroundDir
 
 * Build a ship depot.
 
 * @param flags type of operation
 
 * @param tile tile where ship depot is built
 
 * @param p1 bit 0 depot orientation (Axis)
 
 * @param p2 unused
 
 * @param text unused
 
 * @param axis depot orientation (Axis)
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, Axis axis)
 
{
 
	Axis axis = Extract<Axis, 0, 1>(p1);
 

	
 
	if (!IsEnumValid(axis)) return CMD_ERROR;
 
	TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
src/water_cmd.h
Show inline comments
 
@@ -12,7 +12,7 @@
 

	
 
#include "command_type.h"
 

	
 
CommandProc CmdBuildShipDepot;
 
CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, Axis axis);
 
CommandProc CmdBuildCanal;
 
CommandProc CmdBuildLock;
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -164,30 +164,18 @@ extern CommandCost CanExpandRailStation(
 
 * piece of rail
 
 * @param flags type of operation
 
 * @param start_tile northern most tile where waypoint will be built
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0- 5) - railtype (not used)
 
 * - p1 = (bit  6)    - orientation (Axis)
 
 * - p1 = (bit  8-15) - width of waypoint
 
 * - p1 = (bit 16-23) - height of waypoint
 
 * - p1 = (bit 24)    - allow waypoints directly adjacent to other waypoints.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - custom station class
 
 * - p2 = (bit  8-15) - custom station id
 
 * @param text unused
 
 * @param axis orientation (Axis)
 
 * @param width width of waypoint
 
 * @param height height of waypoint
 
 * @param spec_class custom station class
 
 * @param spec_index custom station id
 
 * @param station_to_join station ID to join (NEW_STATION if build new one)
 
 * @param adjacent allow waypoints directly adjacent to other waypoints.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent)
 
{
 
	/* Unpack parameters */
 
	Axis axis      = Extract<Axis, 6, 1>(p1);
 
	byte width     = GB(p1,  8, 8);
 
	byte height    = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
	if (!IsEnumValid(axis)) return CMD_ERROR;
 
	/* Check if the given station class is valid */
 
	if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
 
	if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
 
@@ -299,12 +287,9 @@ CommandCost CmdBuildRailWaypoint(DoComma
 
 * Build a buoy.
 
 * @param flags operation to perform
 
 * @param tile tile where to place the buoy
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile)
 
{
 
	if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
@@ -409,15 +394,13 @@ static bool IsUniqueWaypointName(const s
 
/**
 
 * Rename a waypoint.
 
 * @param flags type of operation
 
 * @param tile unused
 
 * @param p1 id of waypoint
 
 * @param p2 unused
 
 * @param waypoint_id id of waypoint
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameWaypoint(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
 
{
 
	Waypoint *wp = Waypoint::GetIfValid(p1);
 
	Waypoint *wp = Waypoint::GetIfValid(waypoint_id);
 
	if (wp == nullptr) return CMD_ERROR;
 

	
 
	if (wp->owner != OWNER_NONE) {
src/waypoint_cmd.h
Show inline comments
 
@@ -11,11 +11,14 @@
 
#define WAYPOINT_CMD_H
 

	
 
#include "command_type.h"
 
#include "station_type.h"
 

	
 
CommandProc CmdBuildRailWaypoint;
 
CommandProc CmdRemoveFromRailWaypoint;
 
CommandProc CmdBuildBuoy;
 
CommandProc CmdRenameWaypoint;
 
enum StationClassID : byte;
 

	
 
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent);
 
CommandCost CmdRemoveFromRailWaypoint(DoCommandFlag flags, TileIndex start, TileIndex end, bool keep_rail);
 
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile);
 
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text);
 

	
 
DEF_CMD_TRAIT(CMD_BUILD_RAIL_WAYPOINT,       CmdBuildRailWaypoint,      0,        CMDT_LANDSCAPE_CONSTRUCTION)
 
DEF_CMD_TRAIT(CMD_REMOVE_FROM_RAIL_WAYPOINT, CmdRemoveFromRailWaypoint, 0,        CMDT_LANDSCAPE_CONSTRUCTION)
src/waypoint_gui.cpp
Show inline comments
 
@@ -139,7 +139,7 @@ public:
 
	{
 
		if (str == nullptr) return;
 

	
 
		Command<CMD_RENAME_WAYPOINT>::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, 0, this->window_number, 0, str);
 
		Command<CMD_RENAME_WAYPOINT>::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, str);
 
	}
 

	
 
};
0 comments (0 inline, 0 general)