Changeset - r15027:bb71fdfcc554
[Not reviewed]
master
0 24 0
frosch - 14 years ago 2010-04-17 13:31:41
frosch@openttd.org
(svn r19654) -Codechange: Use Extract<> in more places.
24 files changed with 86 insertions and 62 deletions:
0 comments (0 inline, 0 general)
src/cmd_helper.h
Show inline comments
 
@@ -17,10 +17,11 @@
 
template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
 
{
 
	/* Check if there are enough bits in v */
 
	assert_tcompile(N == EnumPropsT<T>::num_bits);
 
	assert_tcompile(S + N <= sizeof(U) * 8);
 
	assert_tcompile(EnumPropsT<T>::end <= (1 << N));
 
	return (T)GB(v, S, N);
 
	U masked = GB(v, S, N);
 
	return IsInsideMM(masked, EnumPropsT<T>::begin, EnumPropsT<T>::end) ? (T)masked : EnumPropsT<T>::invalid;
 
}
 

	
 
#endif
src/company_cmd.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#include "stdafx.h"
 
#include "engine_base.h"
 
#include "company_func.h"
 
#include "company_gui.h"
 
#include "town.h"
 
#include "news_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "network/network_base.h"
 
#include "ai/ai.hpp"
 
#include "company_manager_face.h"
 
@@ -895,20 +896,17 @@ CommandCost CmdSetCompanyManagerFace(Til
 
 * @param p2 new colour for vehicles, property, etc.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 >= 16) return CMD_ERROR; // max 16 colours
 

	
 
	Colours colour = (Colours)p2;
 

	
 
	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
 
	Colours colour = Extract<Colours, 0, 4>(p2);
 
	LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
 
	byte state = GB(p1, 8, 2);
 

	
 
	if (scheme >= LS_END || state >= 3) return CMD_ERROR;
 
	if (scheme >= LS_END || state >= 3 || colour == INVALID_COLOUR) return CMD_ERROR;
 

	
 
	Company *c = Company::Get(_current_company);
 

	
 
	/* Ensure no two companies have the same primary colour */
 
	if (scheme == LS_DEFAULT && state == 0) {
 
		const Company *cc;
src/gfx_type.h
Show inline comments
 
@@ -193,12 +193,13 @@ enum Colours {
 
	COLOUR_BROWN,
 
	COLOUR_GREY,
 
	COLOUR_WHITE,
 
	COLOUR_END,
 
	INVALID_COLOUR = 0xFF,
 
};
 
template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_DARK_BLUE, COLOUR_END, INVALID_COLOUR, 4> {};
 

	
 
/** Colour of the strings, see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png */
 
enum TextColour {
 
	TC_FROMSTRING  = 0x00,
 
	TC_BLUE        = 0x00,
 
	TC_SILVER      = 0x01,
src/group_cmd.cpp
Show inline comments
 
@@ -7,12 +7,13 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file group_cmd.cpp Handling of the engine groups */
 

	
 
#include "stdafx.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "group.h"
 
#include "train.h"
 
#include "engine_base.h"
 
#include "vehicle_gui.h"
 
#include "window_func.h"
 
@@ -79,13 +80,13 @@ void InitializeGroup()
 
 * @param p2   unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType vt = (VehicleType)p1;
 
	VehicleType vt = Extract<VehicleType, 0, 3>(p1);
 
	if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
 

	
 
	if (!Group::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Group *g = new Group(_current_company);
 
@@ -255,19 +256,18 @@ CommandCost CmdAddVehicleGroup(TileIndex
 
 * @param p2   type of vehicles
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!Group::IsValidID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 
	VehicleType type = Extract<VehicleType, 0, 3>(p2);
 
	GroupID id_g = p1;
 
	if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *v;
 
		VehicleType type = (VehicleType)p2;
 
		GroupID id_g = p1;
 

	
 
		/* Find the first front engine which belong to the group id_g
 
		 * then add all shared vehicles of this front engine to the group id_g */
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != id_g) continue;
 
@@ -295,19 +295,19 @@ CommandCost CmdAddSharedVehicleGroup(Til
 
 * @param p2   type of vehicles
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Group *g = Group::GetIfValid(p1);
 
	VehicleType type = (VehicleType)p2;
 
	GroupID old_g = p1;
 
	Group *g = Group::GetIfValid(old_g);
 
	VehicleType type = Extract<VehicleType, 0, 3>(p2);
 

	
 
	if (g == NULL || g->owner != _current_company || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		GroupID old_g = p1;
 
		Vehicle *v;
 

	
 
		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != old_g) continue;
src/livery.h
Show inline comments
 
@@ -52,12 +52,13 @@ enum LiveryScheme {
 
	LS_FREIGHT_TRAM,
 

	
 
	LS_END
 
};
 

	
 
DECLARE_POSTFIX_INCREMENT(LiveryScheme)
 
template <> struct EnumPropsT<LiveryScheme> : MakeEnumPropsT<LiveryScheme, byte, LS_BEGIN, LS_END, LS_END, 8> {};
 

	
 
/* List of different livery classes, used only by the livery GUI. */
 
enum LiveryClass {
 
	LC_OTHER,
 
	LC_RAIL,
 
	LC_ROAD,
src/newgrf_station.h
Show inline comments
 
@@ -24,12 +24,13 @@ enum StationClassID {
 
	STAT_CLASS_BEGIN = 0,    ///< the lowest valid value
 
	STAT_CLASS_DFLT = 0,     ///< Default station class.
 
	STAT_CLASS_WAYP,         ///< Waypoint class.
 
	STAT_CLASS_MAX = 32,     ///< Maximum number of classes.
 
};
 
typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
 
template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
 

	
 
/** Allow incrementing of StationClassID variables */
 
DECLARE_POSTFIX_INCREMENT(StationClassID)
 

	
 
enum StationSpecFlags {
 
	SSF_SEPARATE_GROUND,      ///< Use different sprite set for ground sprites.
src/order_cmd.cpp
Show inline comments
 
@@ -8,12 +8,13 @@
 
 */
 

	
 
/** @file order_cmd.cpp Handling of orders. */
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_func.h"
 
#include "news_func.h"
 
#include "vehicle_gui.h"
 
#include "strings_func.h"
 
#include "functions.h"
 
@@ -930,13 +931,13 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
 
	VehicleID veh          = GB(p1,  0, 16);
 
	ModifyOrderFlags mof   = (ModifyOrderFlags)GB(p2,  0,  4);
 
	ModifyOrderFlags mof   = Extract<ModifyOrderFlags, 0, 4>(p2);
 
	uint16 data             = GB(p2, 4, 11);
 

	
 
	if (mof >= MOF_END) return CMD_ERROR;
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL) return CMD_ERROR;
src/order_type.h
Show inline comments
 
@@ -146,12 +146,13 @@ enum ModifyOrderFlags {
 
	MOF_COND_VARIABLE,   ///< A conditional variable changes.
 
	MOF_COND_COMPARATOR, ///< A comparator changes.
 
	MOF_COND_VALUE,      ///< The value to set the condition to.
 
	MOF_COND_DESTINATION,///< Change the destination of a conditional order.
 
	MOF_END
 
};
 
template <> struct EnumPropsT<ModifyOrderFlags> : MakeEnumPropsT<ModifyOrderFlags, byte, MOF_NON_STOP, MOF_END, MOF_END, 4> {};
 

	
 
/**
 
 * Depot action to switch to when doing a MOF_DEPOT_ACTION.
 
 */
 
enum OrderDepotAction {
 
	DA_ALWAYS_GO, ///< Always go to the depot
src/rail.cpp
Show inline comments
 
@@ -178,13 +178,13 @@ bool HasRailtypeAvail(const CompanyID co
 
{
 
	return HasBit(Company::Get(company)->avail_railtypes, railtype);
 
}
 

	
 
bool ValParamRailtype(const RailType rail)
 
{
 
	return HasRailtypeAvail(_current_company, rail);
 
	return rail < RAILTYPE_END && HasRailtypeAvail(_current_company, rail);
 
}
 

	
 
RailType GetBestRailtype(const CompanyID company)
 
{
 
	if (HasRailtypeAvail(company, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
 
	if (HasRailtypeAvail(company, RAILTYPE_MONO)) return RAILTYPE_MONO;
src/rail_cmd.cpp
Show inline comments
 
@@ -355,14 +355,14 @@ static inline bool ValParamTrackOrientat
 
 * @param p2 rail track to build
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RailType railtype = (RailType)p1;
 
	Track track = (Track)p2;
 
	RailType railtype = Extract<RailType, 0, 4>(p1);
 
	Track track = Extract<Track, 0, 3>(p2);
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 
	TrackBits trackbit = TrackToTrackBits(track);
 
@@ -496,17 +496,17 @@ CommandCost CmdBuildSingleRail(TileIndex
 
 * @param p2 rail orientation
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)p2;
 
	Track track = Extract<Track, 0, 3>(p2);
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool crossing = false;
 

	
 
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
 
	if (!ValParamTrackOrientation(track)) return CMD_ERROR;
 
	TrackBits trackbit = TrackToTrackBits(track);
 

	
 
	/* Need to read tile owner now because it may change when the rail is removed
 
	 * Also, in case of floods, _current_company != owner
 
	 * There may be invalid tiletype even in exec run (when removing long track),
 
	 * so do not call GetTileOwner(tile) in any case here */
 
@@ -738,15 +738,15 @@ static CommandCost ValidateAutoDrag(Trac
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	Track track = (Track)GB(p2, 4, 3);
 
	Track track = Extract<Track, 4, 3>(p2);
 
	bool remove = HasBit(p2, 7);
 
	RailType railtype = (RailType)GB(p2, 0, 4);
 
	RailType railtype = Extract<RailType, 0, 4>(p2);
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 
	Trackdir trackdir = TrackToTrackdir(track);
 

	
 
@@ -830,13 +830,14 @@ CommandCost CmdRemoveRailroadTrack(TileI
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
 
	RailType railtype = Extract<RailType, 0, 4>(p1);
 
	if (!ValParamRailtype(railtype)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 

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

	
 
	/* Prohibit construction if
 
@@ -862,13 +863,13 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *d = new Depot(tile);
 
		d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		MakeRailDepot(tile, _current_company, d->index, dir, (RailType)p1);
 
		MakeRailDepot(tile, _current_company, d->index, dir, railtype);
 
		MarkTileDirtyByTile(tile);
 

	
 
		AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
	}
 

	
 
@@ -895,22 +896,23 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @todo p2 should be replaced by two bits for "along" and "against" the track.
 
 */
 
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 
	Track track = Extract<Track, 0, 3>(p1);
 
	bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed
 
	SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal
 
	SignalType sigtype = (SignalType)GB(p1, 5, 3); // the signal type of the new signal
 
	SignalType sigtype = Extract<SignalType, 5, 3>(p1); // the signal type of the new signal
 
	bool convert_signal = HasBit(p1, 8); // convert button pressed
 
	SignalType cycle_start = (SignalType)GB(p1, 9, 3);
 
	SignalType cycle_stop = (SignalType)GB(p1, 12, 3);
 
	SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
 
	SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
 
	uint num_dir_cycle = GB(p1, 15, 2);
 

	
 
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
 
	if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST) return CMD_ERROR;
 

	
 
	/* You can only build signals on plain rail tiles, and the selected track must exist */
 
	if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 
@@ -1124,30 +1126,30 @@ static bool CheckSignalAutoFill(TileInde
 
 */
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	TileIndex start_tile = tile;
 

	
 
	Track track = (Track)GB(p2, 0, 3);
 
	Track track = Extract<Track, 0, 3>(p2);
 
	bool mode = HasBit(p2, 3);
 
	bool semaphores = HasBit(p2, 4);
 
	bool remove = HasBit(p2, 5);
 
	bool autofill = HasBit(p2, 6);
 
	Trackdir trackdir = TrackToTrackdir(track);
 
	byte signal_density = GB(p2, 24, 8);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize() || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 
	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
 

	
 
	if (!IsPlainRailTile(tile)) return CMD_ERROR;
 

	
 
	/* for vertical/horizontal tracks, double the given signals density
 
	 * since the original amount will be too dense (shorter tracks) */
 
	signal_density *= 2;
 

	
 
	Trackdir trackdir = TrackToTrackdir(track);
 
	CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
 
	if (ret.Failed()) return ret;
 

	
 
	track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
 
	Trackdir start_trackdir = trackdir;
 

	
 
@@ -1268,13 +1270,13 @@ CommandCost CmdBuildSignalTrack(TileInde
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 
	Track track = Extract<Track, 0, 3>(p1);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track) ||
 
			!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 
@@ -1371,13 +1373,13 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
 * @param p2 new railtype to convert to
 
 * @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 = (RailType)p2;
 
	RailType totype = Extract<RailType, 0, 4>(p2);
 

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

	
 
	uint ex = TileX(tile);
 
	uint ey = TileY(tile);
src/rail_type.h
Show inline comments
 
@@ -40,13 +40,13 @@ enum RailType {
 
	DEF_RAILTYPE_MOST_USED,            ///< Default railtype: most used
 
};
 

	
 
/** Allow incrementing of Track variables */
 
DECLARE_POSTFIX_INCREMENT(RailType)
 
/** Define basic enum properties */
 
template <> struct EnumPropsT<RailType> : MakeEnumPropsT<RailType, byte, RAILTYPE_BEGIN, RAILTYPE_END, INVALID_RAILTYPE> {};
 
template <> struct EnumPropsT<RailType> : MakeEnumPropsT<RailType, byte, RAILTYPE_BEGIN, RAILTYPE_END, INVALID_RAILTYPE, 4> {};
 
typedef TinyEnumT<RailType> RailTypeByte;
 

	
 
/**
 
 * The different roadtypes we support, but then a bitmask of them
 
 */
 
enum RailTypes {
src/road_cmd.cpp
Show inline comments
 
@@ -466,16 +466,16 @@ CommandCost CmdBuildRoad(TileIndex tile,
 

	
 
	RoadBits pieces = Extract<RoadBits, 0, 4>(p1);
 

	
 
	/* do not allow building 'zero' road bits, code wouldn't handle it */
 
	if (pieces == ROAD_NONE) return CMD_ERROR;
 

	
 
	RoadType rt = (RoadType)GB(p1, 4, 2);
 
	RoadType rt = Extract<RoadType, 4, 2>(p1);
 
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
 
	DisallowedRoadDirections toggle_drd = Extract<DisallowedRoadDirections, 6, 2>(p1);
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 

	
 
	bool tile_cleared = false; // Used to remember that the tile was cleared during test run
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD:
 
@@ -723,13 +723,13 @@ CommandCost CmdBuildLongRoad(TileIndex s
 
{
 
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TileIndex end_tile = p1;
 
	RoadType rt = (RoadType)GB(p2, 3, 2);
 
	RoadType rt = Extract<RoadType, 3, 2>(p2);
 
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Axis axis = Extract<Axis, 2, 1>(p2);
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
	if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
 
@@ -815,13 +815,13 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TileIndex end_tile = p1;
 
	RoadType rt = (RoadType)GB(p2, 3, 2);
 
	RoadType rt = Extract<RoadType, 3, 2>(p2);
 
	if (!IsValidRoadType(rt)) return CMD_ERROR;
 

	
 
	Axis axis = Extract<Axis, 2, 1>(p2);
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
	if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
 
@@ -884,13 +884,13 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection dir = Extract<DiagDirection, 0, 2>(p1);
 
	RoadType rt = (RoadType)GB(p1, 2, 2);
 
	RoadType rt = Extract<RoadType, 2, 2>(p1);
 

	
 
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 
	if (tileh != SLOPE_FLAT && (
 
				!_settings_game.construction.build_on_slopes ||
src/road_map.h
Show inline comments
 
@@ -165,12 +165,13 @@ enum DisallowedRoadDirections {
 
	DRD_SOUTHBOUND, ///< All southbound traffic is disallowed
 
	DRD_NORTHBOUND, ///< All northbound traffic is disallowed
 
	DRD_BOTH,       ///< All directions are disallowed
 
	DRD_END
 
};
 
DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections)
 
template <> struct EnumPropsT<DisallowedRoadDirections> : MakeEnumPropsT<DisallowedRoadDirections, byte, DRD_NONE, DRD_END, DRD_END, 2> {};
 

	
 
/**
 
 * Gets the disallowed directions
 
 * @param t the tile to get the directions from
 
 * @return the disallowed directions
 
 */
src/road_type.h
Show inline comments
 
@@ -24,13 +24,13 @@ enum RoadType {
 
	ROADTYPE_ROAD = 0,      ///< Basic road type
 
	ROADTYPE_TRAM = 1,      ///< Trams
 
	ROADTYPE_END,           ///< Used for iterations
 
	INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
 
};
 
DECLARE_POSTFIX_INCREMENT(RoadType)
 
template <> struct EnumPropsT<RoadType> : MakeEnumPropsT<RoadType, byte, ROADTYPE_BEGIN, ROADTYPE_END, INVALID_ROADTYPE> {};
 
template <> struct EnumPropsT<RoadType> : MakeEnumPropsT<RoadType, byte, ROADTYPE_BEGIN, ROADTYPE_END, INVALID_ROADTYPE, 2> {};
 

	
 
/**
 
 * The different roadtypes we support, but then a bitmask of them
 
 * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
 
 */
 
enum RoadTypes {
 
@@ -39,12 +39,13 @@ enum RoadTypes {
 
	ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,               ///< Trams
 
	ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM,  ///< Road + trams
 
	ROADTYPES_END,                                         ///< Used for iterations?
 
	INVALID_ROADTYPES  = 0xFF                              ///< Invalid roadtypes
 
};
 
DECLARE_ENUM_AS_BIT_SET(RoadTypes)
 
template <> struct EnumPropsT<RoadTypes> : MakeEnumPropsT<RoadTypes, byte, ROADTYPES_NONE, ROADTYPES_END, INVALID_ROADTYPES, 2> {};
 
typedef SimpleTinyEnumT<RoadTypes, byte> RoadTypesByte;
 

	
 

	
 
/**
 
 * Enumeration for the road parts on a tile.
 
 *
src/signal_type.h
Show inline comments
 
@@ -24,12 +24,15 @@ enum SignalType {
 
	SIGTYPE_NORMAL     = 0, ///< normal signal
 
	SIGTYPE_ENTRY      = 1, ///< presignal block entry
 
	SIGTYPE_EXIT       = 2, ///< presignal block exit
 
	SIGTYPE_COMBO      = 3, ///< presignal inter-block
 
	SIGTYPE_PBS        = 4, ///< normal pbs signal
 
	SIGTYPE_PBS_ONEWAY = 5, ///< no-entry signal
 

	
 
	SIGTYPE_END,
 
	SIGTYPE_LAST       = SIGTYPE_PBS_ONEWAY,
 
	SIGTYPE_LAST_NOPBS = SIGTYPE_COMBO
 
};
 
template <> struct EnumPropsT<SignalType> : MakeEnumPropsT<SignalType, byte, SIGTYPE_NORMAL, SIGTYPE_END, SIGTYPE_END, 3> {};
 

	
 

	
 
#endif /* SIGNAL_TYPE_H */
src/station_cmd.cpp
Show inline comments
 
@@ -1092,30 +1092,30 @@ CommandCost FindJoiningWaypoint(StationI
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Unpack parameters */
 
	RailType rt    = (RailType)GB(p1, 0, 4);
 
	RailType rt    = Extract<RailType, 0, 4>(p1);
 
	Axis axis      = Extract<Axis, 4, 1>(p1);
 
	byte numtracks = GB(p1,  8, 8);
 
	byte plat_len  = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = (StationClassID)GB(p2, 0, 8);
 
	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;
 

	
 
	/* Check if the given station class is valid */
 
	if ((uint)spec_class >= GetNumStationClasses()) return CMD_ERROR;
 
	if ((uint)spec_class >= GetNumStationClasses() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
 
	if (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
 
	if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
 

	
 
	int w_org, h_org;
 
	if (axis == AXIS_X) {
 
		w_org = plat_len;
 
@@ -1672,13 +1672,13 @@ static CommandCost FindJoiningRoadStop(S
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 2);
 
	RoadTypes rts = Extract<RoadTypes, 2, 2>(p2);
 
	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);
 
	Owner tram_owner = _current_company;
 
	Owner road_owner = _current_company;
 
@@ -1699,13 +1699,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
 

	
 
	if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 

	
 
	/* Trams only have drive through stops */
 
	if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
 

	
 
	DiagDirection ddir = (DiagDirection)GB(p2, 6, 2);
 
	DiagDirection ddir = Extract<DiagDirection, 6, 2>(p2);
 

	
 
	/* Safeguard the parameters. */
 
	if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
 
	/* If it is a drive-through stop, check for valid axis. */
 
	if (is_drive_through && !IsValidAxis((Axis)ddir)) return CMD_ERROR;
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -11,12 +11,13 @@
 

	
 
#include "stdafx.h"
 
#include "road_internal.h" /* Cleaning up road bits */
 
#include "road_cmd.h"
 
#include "landscape.h"
 
#include "viewport_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "industry.h"
 
#include "station_base.h"
 
#include "company_base.h"
 
#include "news_func.h"
 
#include "gui.h"
 
@@ -1515,15 +1516,15 @@ static bool IsUniqueTownName(const char 
 
 * @param p2 town name parts
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TownSize size = (TownSize)GB(p1, 0, 2);
 
	TownSize size = Extract<TownSize, 0, 2>(p1);
 
	bool city = HasBit(p1, 2);
 
	TownLayout layout = (TownLayout)GB(p1, 3, 3);
 
	TownLayout layout = Extract<TownLayout, 3, 3>(p1);
 
	TownNameParams par(_settings_game.game_creation.town_name);
 
	bool random = HasBit(p1, 6);
 
	uint32 townnameparts = p2;
 

	
 
	if (size >= TSZ_END) return CMD_ERROR;
 
	if (layout >= NUM_TLS) return CMD_ERROR;
src/town_type.h
Show inline comments
 
@@ -23,12 +23,13 @@ enum TownSize {
 
	TSZ_MEDIUM, ///< Medium town.
 
	TSZ_LARGE,  ///< Large town.
 
	TSZ_RANDOM, ///< Random size, bigger than small, smaller than large.
 

	
 
	TSZ_END,    ///< Number of available town sizes.
 
};
 
template <> struct EnumPropsT<TownSize> : MakeEnumPropsT<TownSize, byte, TSZ_SMALL, TSZ_END, TSZ_END, 2> {};
 

	
 
enum {
 
	/* These refer to the maximums, so Appalling is -1000 to -400
 
	 * MAXIMUM RATINGS BOUNDARIES */
 
	RATING_MINIMUM     = -1000,
 
	RATING_APPALLING   =  -400,
 
@@ -86,12 +87,13 @@ enum TownLayout {
 
	TL_3X3_GRID,         ///< Geometric 3x3 grid algorithm
 

	
 
	TL_RANDOM,           ///< Random town layout
 

	
 
	NUM_TLS,             ///< Number of town layouts
 
};
 
template <> struct EnumPropsT<TownLayout> : MakeEnumPropsT<TownLayout, byte, TL_BEGIN, NUM_TLS, NUM_TLS, 3> {};
 
/** It needs to be 8bits, because we save and load it as such */
 
typedef SimpleTinyEnumT<TownLayout, byte> TownLayoutByte; // typedefing-enumification of TownLayout
 

	
 
/** Town founding setting values */
 
enum TownFounding {
 
	TF_BEGIN = 0,     ///< Used for iterations and limit testing
src/transport_type.h
Show inline comments
 
@@ -27,8 +27,9 @@ enum TransportType {
 
	TRANSPORT_ROAD,  ///< Transport by road vehicle
 
	TRANSPORT_WATER, ///< Transport over water
 
	TRANSPORT_AIR,   ///< Transport through air
 
	TRANSPORT_END,
 
	INVALID_TRANSPORT = 0xff,
 
};
 
template <> struct EnumPropsT<TransportType> : MakeEnumPropsT<TransportType, byte, TRANSPORT_BEGIN, TRANSPORT_END, INVALID_TRANSPORT, 2> {};
 

	
 
#endif /* TRANSPORT_TYPE_H */
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -14,12 +14,13 @@
 

	
 
#include "stdafx.h"
 
#include "rail_map.h"
 
#include "landscape.h"
 
#include "unmovable_map.h"
 
#include "viewport_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "town.h"
 
#include "variables.h"
 
#include "train.h"
 
#include "ship.h"
 
#include "roadveh.h"
 
@@ -191,13 +192,13 @@ CommandCost CheckBridgeAvailability(Brid
 
/** Build a Bridge
 
 * @param end_tile end tile
 
 * @param flags type of operation
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - bridge type (hi bh)
 
 * - p2 = (bit  8-14) - rail type or road types.
 
 * - p2 = (bit  8-11) - rail type or road types.
 
 * - p2 = (bit 15-16) - transport type.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
@@ -206,23 +207,23 @@ CommandCost CmdBuildBridge(TileIndex end
 

	
 
	/* unpack parameters */
 
	BridgeType bridge_type = GB(p2, 0, 8);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TransportType transport_type = (TransportType)GB(p2, 15, 2);
 
	TransportType transport_type = Extract<TransportType, 15, 2>(p2);
 

	
 
	/* type of bridge */
 
	switch (transport_type) {
 
		case TRANSPORT_ROAD:
 
			roadtypes = (RoadTypes)GB(p2, 8, 2);
 
			roadtypes = Extract<RoadTypes, 8, 2>(p2);
 
			if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(_current_company, roadtypes)) return CMD_ERROR;
 
			break;
 

	
 
		case TRANSPORT_RAIL:
 
			railtype = (RailType)GB(p2, 8, 7);
 
			railtype = Extract<RailType, 8, 4>(p2);
 
			if (!ValParamRailtype(railtype)) return CMD_ERROR;
 
			break;
 

	
 
		case TRANSPORT_WATER:
 
			break;
 

	
 
@@ -487,25 +488,25 @@ CommandCost CmdBuildBridge(TileIndex end
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TransportType transport_type = (TransportType)GB(p1, 8, 2);
 
	TransportType transport_type = Extract<TransportType, 8, 2>(p1);
 

	
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadTypes rts = ROADTYPES_NONE;
 
	_build_tunnel_endtile = 0;
 
	switch (transport_type) {
 
		case TRANSPORT_RAIL:
 
			railtype = (RailType)GB(p1, 0, 4);
 
			railtype = Extract<RailType, 0, 4>(p1);
 
			if (!ValParamRailtype(railtype)) return CMD_ERROR;
 
			break;
 

	
 
		case TRANSPORT_ROAD:
 
			rts = (RoadTypes)GB(p1, 0, 2);
 
			rts = Extract<RoadTypes, 0, 2>(p1);
 
			if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 
			break;
 

	
 
		default: return CMD_ERROR;
 
	}
 

	
src/vehicle_cmd.cpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file vehicle_cmd.cpp Commands for vehicles. */
 

	
 
#include "stdafx.h"
 
#include "roadveh.h"
 
#include "news_func.h"
 
#include "airport.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_func.h"
 
#include "vehicle_gui.h"
 
#include "train.h"
 
#include "aircraft.h"
 
#include "newgrf_engine.h"
 
@@ -123,23 +124,25 @@ CommandCost CmdStartStopVehicle(TileInde
 
 * @param flags type of operation
 
 * @param p1 Station/Order/Depot ID (only used for vehicle list windows)
 
 * @param p2 bitmask
 
 *   - bit 0-4 Vehicle type
 
 *   - bit 5 false = start vehicles, true = stop vehicles
 
 *   - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
 
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)
 
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 6 is set)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
 
	VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p2);
 
	bool start_stop = HasBit(p2, 5);
 
	bool vehicle_list_window = HasBit(p2, 6);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 

	
 
	if (vehicle_list_window) {
 
		uint32 id = p1;
 
		uint16 window_type = p2 & VLW_MASK;
 

	
 
		GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type);
 
	} else {
 
@@ -177,15 +180,17 @@ CommandCost CmdMassStartStopVehicle(Tile
 
 */
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
 
	uint sell_command = GetCmdSellVeh(vehicle_type);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 

	
 
	CommandCost last_error = CMD_ERROR;
 
	bool had_success = false;
 
	for (uint i = 0; i < list.Length(); i++) {
 
@@ -211,14 +216,15 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 
	if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
 

	
 
	for (uint i = 0; i < list.Length(); i++) {
src/vehicle_type.h
Show inline comments
 
@@ -25,12 +25,13 @@ enum VehicleType {
 
	VEH_EFFECT,         ///< Effect vehicle type (smoke, explosions, sparks, bubbles)
 
	VEH_DISASTER,       ///< Disaster vehicle type.
 
	VEH_END,
 
	VEH_INVALID = 0xFF, ///< Non-existing type of vehicle.
 
};
 
DECLARE_POSTFIX_INCREMENT(VehicleType)
 
template <> struct EnumPropsT<VehicleType> : MakeEnumPropsT<VehicleType, byte, VEH_TRAIN, VEH_END, VEH_INVALID, 3> {};
 
/** It needs to be 8bits, because we save and load it as such */
 
typedef SimpleTinyEnumT<VehicleType, byte> VehicleTypeByte;
 

	
 
struct Vehicle;
 
struct Train;
 
struct RoadVehicle;
src/water_cmd.cpp
Show inline comments
 
@@ -288,13 +288,13 @@ CommandCost CmdBuildLock(TileIndex tile,
 
 * @param p2 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize() || p2 > 2) return CMD_ERROR;
 

	
 
	/* Outside of the editor you can only build canals, not oceans */
 
	if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;
 

	
 
	TileArea ta(tile, p1);
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -8,12 +8,13 @@
 
 */
 

	
 
/** @file waypoint_cmd.cpp Command Handling for waypoints. */
 

	
 
#include "stdafx.h"
 

	
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "landscape.h"
 
#include "bridge_map.h"
 
#include "town.h"
 
#include "waypoint_base.h"
 
#include "pathfinder/yapf/yapf_cache.h"
 
@@ -212,18 +213,18 @@ extern CommandCost CanExpandRailStation(
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Unpack parameters */
 
	Axis axis      = (Axis)GB(p1,  4, 1);
 
	Axis axis      = Extract<Axis, 4, 1>(p1);
 
	byte width     = GB(p1,  8, 8);
 
	byte height    = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

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

	
 
	/* Check if the given station class is valid */
 
	if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
 
	if (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
0 comments (0 inline, 0 general)