mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19654) -Codechange: Use Extract<> in more places.
This commit is contained in:
parent
184fa43df2
commit
75d4bc947d
|
@ -20,7 +20,8 @@ template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
|
||||||
assert_tcompile(N == EnumPropsT<T>::num_bits);
|
assert_tcompile(N == EnumPropsT<T>::num_bits);
|
||||||
assert_tcompile(S + N <= sizeof(U) * 8);
|
assert_tcompile(S + N <= sizeof(U) * 8);
|
||||||
assert_tcompile(EnumPropsT<T>::end <= (1 << N));
|
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
|
#endif
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "company_gui.h"
|
#include "company_gui.h"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "news_func.h"
|
#include "news_func.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "network/network.h"
|
#include "network/network.h"
|
||||||
#include "network/network_func.h"
|
#include "network/network_func.h"
|
||||||
|
@ -898,14 +899,11 @@ CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
*/
|
*/
|
||||||
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
if (p2 >= 16) return CMD_ERROR; // max 16 colours
|
Colours colour = Extract<Colours, 0, 4>(p2);
|
||||||
|
LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
|
||||||
Colours colour = (Colours)p2;
|
|
||||||
|
|
||||||
LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
|
|
||||||
byte state = GB(p1, 8, 2);
|
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);
|
Company *c = Company::Get(_current_company);
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ enum Colours {
|
||||||
COLOUR_END,
|
COLOUR_END,
|
||||||
INVALID_COLOUR = 0xFF,
|
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 */
|
/** Colour of the strings, see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png */
|
||||||
enum TextColour {
|
enum TextColour {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
/** @file group_cmd.cpp Handling of the engine groups */
|
/** @file group_cmd.cpp Handling of the engine groups */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "train.h"
|
#include "train.h"
|
||||||
|
@ -82,7 +83,7 @@ void InitializeGroup()
|
||||||
*/
|
*/
|
||||||
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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 (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
|
||||||
|
|
||||||
if (!Group::CanAllocateItem()) return CMD_ERROR;
|
if (!Group::CanAllocateItem()) return CMD_ERROR;
|
||||||
|
@ -258,13 +259,12 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
*/
|
*/
|
||||||
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
VehicleType type = (VehicleType)p2;
|
VehicleType type = Extract<VehicleType, 0, 3>(p2);
|
||||||
if (!Group::IsValidID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
GroupID id_g = p1;
|
||||||
|
if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
VehicleType type = (VehicleType)p2;
|
|
||||||
GroupID id_g = p1;
|
|
||||||
|
|
||||||
/* Find the first front engine which belong to the group id_g
|
/* 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 */
|
* then add all shared vehicles of this front engine to the group id_g */
|
||||||
|
@ -298,13 +298,13 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
*/
|
*/
|
||||||
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Group *g = Group::GetIfValid(p1);
|
GroupID old_g = p1;
|
||||||
VehicleType type = (VehicleType)p2;
|
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 (g == NULL || g->owner != _current_company || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
GroupID old_g = p1;
|
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
|
|
||||||
/* Find each Vehicle that belongs to the group old_g and add it to the default group */
|
/* Find each Vehicle that belongs to the group old_g and add it to the default group */
|
||||||
|
|
|
@ -55,6 +55,7 @@ enum LiveryScheme {
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_POSTFIX_INCREMENT(LiveryScheme)
|
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. */
|
/* List of different livery classes, used only by the livery GUI. */
|
||||||
enum LiveryClass {
|
enum LiveryClass {
|
||||||
|
|
|
@ -27,6 +27,7 @@ enum StationClassID {
|
||||||
STAT_CLASS_MAX = 32, ///< Maximum number of classes.
|
STAT_CLASS_MAX = 32, ///< Maximum number of classes.
|
||||||
};
|
};
|
||||||
typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
|
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 */
|
/** Allow incrementing of StationClassID variables */
|
||||||
DECLARE_POSTFIX_INCREMENT(StationClassID)
|
DECLARE_POSTFIX_INCREMENT(StationClassID)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
#include "news_func.h"
|
#include "news_func.h"
|
||||||
|
@ -933,7 +934,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
{
|
{
|
||||||
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
|
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
|
||||||
VehicleID veh = GB(p1, 0, 16);
|
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);
|
uint16 data = GB(p2, 4, 11);
|
||||||
|
|
||||||
if (mof >= MOF_END) return CMD_ERROR;
|
if (mof >= MOF_END) return CMD_ERROR;
|
||||||
|
|
|
@ -149,6 +149,7 @@ enum ModifyOrderFlags {
|
||||||
MOF_COND_DESTINATION,///< Change the destination of a conditional order.
|
MOF_COND_DESTINATION,///< Change the destination of a conditional order.
|
||||||
MOF_END
|
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.
|
* Depot action to switch to when doing a MOF_DEPOT_ACTION.
|
||||||
|
|
|
@ -181,7 +181,7 @@ bool HasRailtypeAvail(const CompanyID company, const RailType railtype)
|
||||||
|
|
||||||
bool ValParamRailtype(const RailType rail)
|
bool ValParamRailtype(const RailType rail)
|
||||||
{
|
{
|
||||||
return HasRailtypeAvail(_current_company, rail);
|
return rail < RAILTYPE_END && HasRailtypeAvail(_current_company, rail);
|
||||||
}
|
}
|
||||||
|
|
||||||
RailType GetBestRailtype(const CompanyID company)
|
RailType GetBestRailtype(const CompanyID company)
|
||||||
|
|
|
@ -358,8 +358,8 @@ static inline bool ValParamTrackOrientation(Track track)
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
RailType railtype = (RailType)p1;
|
RailType railtype = Extract<RailType, 0, 4>(p1);
|
||||||
Track track = (Track)p2;
|
Track track = Extract<Track, 0, 3>(p2);
|
||||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||||
|
|
||||||
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||||
|
@ -499,11 +499,11 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
*/
|
*/
|
||||||
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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);
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||||
bool crossing = false;
|
bool crossing = false;
|
||||||
|
|
||||||
if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
|
if (!ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||||
TrackBits trackbit = TrackToTrackBits(track);
|
TrackBits trackbit = TrackToTrackBits(track);
|
||||||
|
|
||||||
/* Need to read tile owner now because it may change when the rail is removed
|
/* Need to read tile owner now because it may change when the rail is removed
|
||||||
|
@ -741,9 +741,9 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd
|
||||||
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||||
Track track = (Track)GB(p2, 4, 3);
|
Track track = Extract<Track, 4, 3>(p2);
|
||||||
bool remove = HasBit(p2, 7);
|
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 (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
@ -833,7 +833,8 @@ CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p
|
||||||
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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 */
|
/* 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);
|
Slope tileh = GetTileSlope(tile, NULL);
|
||||||
|
|
||||||
|
@ -865,7 +866,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
Depot *d = new Depot(tile);
|
Depot *d = new Depot(tile);
|
||||||
d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
|
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);
|
MarkTileDirtyByTile(tile);
|
||||||
|
|
||||||
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
|
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
|
||||||
|
@ -898,16 +899,17 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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
|
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
|
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
|
bool convert_signal = HasBit(p1, 8); // convert button pressed
|
||||||
SignalType cycle_start = (SignalType)GB(p1, 9, 3);
|
SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
|
||||||
SignalType cycle_stop = (SignalType)GB(p1, 12, 3);
|
SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
|
||||||
uint num_dir_cycle = GB(p1, 15, 2);
|
uint num_dir_cycle = GB(p1, 15, 2);
|
||||||
|
|
||||||
if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
|
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 */
|
/* You can only build signals on plain rail tiles, and the selected track must exist */
|
||||||
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
|
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
|
||||||
|
@ -1127,15 +1129,14 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
||||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||||
TileIndex start_tile = tile;
|
TileIndex start_tile = tile;
|
||||||
|
|
||||||
Track track = (Track)GB(p2, 0, 3);
|
Track track = Extract<Track, 0, 3>(p2);
|
||||||
bool mode = HasBit(p2, 3);
|
bool mode = HasBit(p2, 3);
|
||||||
bool semaphores = HasBit(p2, 4);
|
bool semaphores = HasBit(p2, 4);
|
||||||
bool remove = HasBit(p2, 5);
|
bool remove = HasBit(p2, 5);
|
||||||
bool autofill = HasBit(p2, 6);
|
bool autofill = HasBit(p2, 6);
|
||||||
Trackdir trackdir = TrackToTrackdir(track);
|
|
||||||
byte signal_density = GB(p2, 24, 8);
|
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;
|
TileIndex end_tile = p1;
|
||||||
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
|
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -1145,6 +1146,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
||||||
* since the original amount will be too dense (shorter tracks) */
|
* since the original amount will be too dense (shorter tracks) */
|
||||||
signal_density *= 2;
|
signal_density *= 2;
|
||||||
|
|
||||||
|
Trackdir trackdir = TrackToTrackdir(track);
|
||||||
CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
|
CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
|
@ -1271,7 +1273,7 @@ CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||||
*/
|
*/
|
||||||
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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) ||
|
if (!ValParamTrackOrientation(track) ||
|
||||||
!IsPlainRailTile(tile) ||
|
!IsPlainRailTile(tile) ||
|
||||||
|
@ -1374,7 +1376,7 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
|
||||||
*/
|
*/
|
||||||
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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 (!ValParamRailtype(totype)) return CMD_ERROR;
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
|
|
@ -43,7 +43,7 @@ enum RailType {
|
||||||
/** Allow incrementing of Track variables */
|
/** Allow incrementing of Track variables */
|
||||||
DECLARE_POSTFIX_INCREMENT(RailType)
|
DECLARE_POSTFIX_INCREMENT(RailType)
|
||||||
/** Define basic enum properties */
|
/** 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;
|
typedef TinyEnumT<RailType> RailTypeByte;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -469,10 +469,10 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
/* do not allow building 'zero' road bits, code wouldn't handle it */
|
/* do not allow building 'zero' road bits, code wouldn't handle it */
|
||||||
if (pieces == ROAD_NONE) return CMD_ERROR;
|
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;
|
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);
|
Slope tileh = GetTileSlope(tile, NULL);
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
|
||||||
TileIndex end_tile = p1;
|
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;
|
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
||||||
|
|
||||||
Axis axis = Extract<Axis, 2, 1>(p2);
|
Axis axis = Extract<Axis, 2, 1>(p2);
|
||||||
|
@ -818,7 +818,7 @@ CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
|
||||||
TileIndex end_tile = p1;
|
TileIndex end_tile = p1;
|
||||||
RoadType rt = (RoadType)GB(p2, 3, 2);
|
RoadType rt = Extract<RoadType, 3, 2>(p2);
|
||||||
if (!IsValidRoadType(rt)) return CMD_ERROR;
|
if (!IsValidRoadType(rt)) return CMD_ERROR;
|
||||||
|
|
||||||
Axis axis = Extract<Axis, 2, 1>(p2);
|
Axis axis = Extract<Axis, 2, 1>(p2);
|
||||||
|
@ -887,7 +887,7 @@ CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32
|
||||||
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
DiagDirection dir = Extract<DiagDirection, 0, 2>(p1);
|
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;
|
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ enum DisallowedRoadDirections {
|
||||||
DRD_END
|
DRD_END
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections)
|
DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections)
|
||||||
|
template <> struct EnumPropsT<DisallowedRoadDirections> : MakeEnumPropsT<DisallowedRoadDirections, byte, DRD_NONE, DRD_END, DRD_END, 2> {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the disallowed directions
|
* Gets the disallowed directions
|
||||||
|
|
|
@ -27,7 +27,7 @@ enum RoadType {
|
||||||
INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
|
INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
|
||||||
};
|
};
|
||||||
DECLARE_POSTFIX_INCREMENT(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
|
* The different roadtypes we support, but then a bitmask of them
|
||||||
|
@ -42,6 +42,7 @@ enum RoadTypes {
|
||||||
INVALID_ROADTYPES = 0xFF ///< Invalid roadtypes
|
INVALID_ROADTYPES = 0xFF ///< Invalid roadtypes
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(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;
|
typedef SimpleTinyEnumT<RoadTypes, byte> RoadTypesByte;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,12 @@ enum SignalType {
|
||||||
SIGTYPE_COMBO = 3, ///< presignal inter-block
|
SIGTYPE_COMBO = 3, ///< presignal inter-block
|
||||||
SIGTYPE_PBS = 4, ///< normal pbs signal
|
SIGTYPE_PBS = 4, ///< normal pbs signal
|
||||||
SIGTYPE_PBS_ONEWAY = 5, ///< no-entry signal
|
SIGTYPE_PBS_ONEWAY = 5, ///< no-entry signal
|
||||||
|
|
||||||
|
SIGTYPE_END,
|
||||||
SIGTYPE_LAST = SIGTYPE_PBS_ONEWAY,
|
SIGTYPE_LAST = SIGTYPE_PBS_ONEWAY,
|
||||||
SIGTYPE_LAST_NOPBS = SIGTYPE_COMBO
|
SIGTYPE_LAST_NOPBS = SIGTYPE_COMBO
|
||||||
};
|
};
|
||||||
|
template <> struct EnumPropsT<SignalType> : MakeEnumPropsT<SignalType, byte, SIGTYPE_NORMAL, SIGTYPE_END, SIGTYPE_END, 3> {};
|
||||||
|
|
||||||
|
|
||||||
#endif /* SIGNAL_TYPE_H */
|
#endif /* SIGNAL_TYPE_H */
|
||||||
|
|
|
@ -1095,13 +1095,13 @@ CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_
|
||||||
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
/* Unpack parameters */
|
/* Unpack parameters */
|
||||||
RailType rt = (RailType)GB(p1, 0, 4);
|
RailType rt = Extract<RailType, 0, 4>(p1);
|
||||||
Axis axis = Extract<Axis, 4, 1>(p1);
|
Axis axis = Extract<Axis, 4, 1>(p1);
|
||||||
byte numtracks = GB(p1, 8, 8);
|
byte numtracks = GB(p1, 8, 8);
|
||||||
byte plat_len = GB(p1, 16, 8);
|
byte plat_len = GB(p1, 16, 8);
|
||||||
bool adjacent = HasBit(p1, 24);
|
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);
|
byte spec_index = GB(p2, 8, 8);
|
||||||
StationID station_to_join = GB(p2, 16, 16);
|
StationID station_to_join = GB(p2, 16, 16);
|
||||||
|
|
||||||
|
@ -1112,7 +1112,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
|
||||||
if (!ValParamRailtype(rt)) return CMD_ERROR;
|
if (!ValParamRailtype(rt)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Check if the given station class is valid */
|
/* 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 (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
|
||||||
if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
|
if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -1675,7 +1675,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||||
{
|
{
|
||||||
bool type = HasBit(p2, 0);
|
bool type = HasBit(p2, 0);
|
||||||
bool is_drive_through = HasBit(p2, 1);
|
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);
|
StationID station_to_join = GB(p2, 16, 16);
|
||||||
bool reuse = (station_to_join != NEW_STATION);
|
bool reuse = (station_to_join != NEW_STATION);
|
||||||
if (!reuse) station_to_join = INVALID_STATION;
|
if (!reuse) station_to_join = INVALID_STATION;
|
||||||
|
@ -1702,7 +1702,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||||
/* Trams only have drive through stops */
|
/* Trams only have drive through stops */
|
||||||
if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
|
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. */
|
/* Safeguard the parameters. */
|
||||||
if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
|
if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "road_cmd.h"
|
#include "road_cmd.h"
|
||||||
#include "landscape.h"
|
#include "landscape.h"
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "industry.h"
|
#include "industry.h"
|
||||||
#include "station_base.h"
|
#include "station_base.h"
|
||||||
|
@ -1518,9 +1519,9 @@ static bool IsUniqueTownName(const char *name)
|
||||||
*/
|
*/
|
||||||
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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);
|
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);
|
TownNameParams par(_settings_game.game_creation.town_name);
|
||||||
bool random = HasBit(p1, 6);
|
bool random = HasBit(p1, 6);
|
||||||
uint32 townnameparts = p2;
|
uint32 townnameparts = p2;
|
||||||
|
|
|
@ -26,6 +26,7 @@ enum TownSize {
|
||||||
|
|
||||||
TSZ_END, ///< Number of available town sizes.
|
TSZ_END, ///< Number of available town sizes.
|
||||||
};
|
};
|
||||||
|
template <> struct EnumPropsT<TownSize> : MakeEnumPropsT<TownSize, byte, TSZ_SMALL, TSZ_END, TSZ_END, 2> {};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/* These refer to the maximums, so Appalling is -1000 to -400
|
/* These refer to the maximums, so Appalling is -1000 to -400
|
||||||
|
@ -89,6 +90,7 @@ enum TownLayout {
|
||||||
|
|
||||||
NUM_TLS, ///< Number of town layouts
|
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 */
|
/** It needs to be 8bits, because we save and load it as such */
|
||||||
typedef SimpleTinyEnumT<TownLayout, byte> TownLayoutByte; // typedefing-enumification of TownLayout
|
typedef SimpleTinyEnumT<TownLayout, byte> TownLayoutByte; // typedefing-enumification of TownLayout
|
||||||
|
|
||||||
|
|
|
@ -30,5 +30,6 @@ enum TransportType {
|
||||||
TRANSPORT_END,
|
TRANSPORT_END,
|
||||||
INVALID_TRANSPORT = 0xff,
|
INVALID_TRANSPORT = 0xff,
|
||||||
};
|
};
|
||||||
|
template <> struct EnumPropsT<TransportType> : MakeEnumPropsT<TransportType, byte, TRANSPORT_BEGIN, TRANSPORT_END, INVALID_TRANSPORT, 2> {};
|
||||||
|
|
||||||
#endif /* TRANSPORT_TYPE_H */
|
#endif /* TRANSPORT_TYPE_H */
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "landscape.h"
|
#include "landscape.h"
|
||||||
#include "unmovable_map.h"
|
#include "unmovable_map.h"
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
@ -194,7 +195,7 @@ CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoC
|
||||||
* @param p1 packed start tile coords (~ dx)
|
* @param p1 packed start tile coords (~ dx)
|
||||||
* @param p2 various bitstuffed elements
|
* @param p2 various bitstuffed elements
|
||||||
* - p2 = (bit 0- 7) - bridge type (hi bh)
|
* - 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.
|
* - p2 = (bit 15-16) - transport type.
|
||||||
* @param text unused
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
|
@ -209,17 +210,17 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
|
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
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 */
|
/* type of bridge */
|
||||||
switch (transport_type) {
|
switch (transport_type) {
|
||||||
case TRANSPORT_ROAD:
|
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;
|
if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(_current_company, roadtypes)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRANSPORT_RAIL:
|
case TRANSPORT_RAIL:
|
||||||
railtype = (RailType)GB(p2, 8, 7);
|
railtype = Extract<RailType, 8, 4>(p2);
|
||||||
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -490,19 +491,19 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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;
|
RailType railtype = INVALID_RAILTYPE;
|
||||||
RoadTypes rts = ROADTYPES_NONE;
|
RoadTypes rts = ROADTYPES_NONE;
|
||||||
_build_tunnel_endtile = 0;
|
_build_tunnel_endtile = 0;
|
||||||
switch (transport_type) {
|
switch (transport_type) {
|
||||||
case TRANSPORT_RAIL:
|
case TRANSPORT_RAIL:
|
||||||
railtype = (RailType)GB(p1, 0, 4);
|
railtype = Extract<RailType, 0, 4>(p1);
|
||||||
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRANSPORT_ROAD:
|
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;
|
if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "roadveh.h"
|
#include "roadveh.h"
|
||||||
#include "news_func.h"
|
#include "news_func.h"
|
||||||
#include "airport.h"
|
#include "airport.h"
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
#include "vehicle_gui.h"
|
#include "vehicle_gui.h"
|
||||||
|
@ -126,17 +127,19 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||||
* - bit 0-4 Vehicle type
|
* - bit 0-4 Vehicle type
|
||||||
* - bit 5 false = start vehicles, true = stop vehicles
|
* - 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 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
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
*/
|
*/
|
||||||
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
VehicleList list;
|
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 start_stop = HasBit(p2, 5);
|
||||||
bool vehicle_list_window = HasBit(p2, 6);
|
bool vehicle_list_window = HasBit(p2, 6);
|
||||||
|
|
||||||
|
if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
|
||||||
|
|
||||||
if (vehicle_list_window) {
|
if (vehicle_list_window) {
|
||||||
uint32 id = p1;
|
uint32 id = p1;
|
||||||
uint16 window_type = p2 & VLW_MASK;
|
uint16 window_type = p2 & VLW_MASK;
|
||||||
|
@ -180,9 +183,11 @@ CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
VehicleList list;
|
VehicleList list;
|
||||||
|
|
||||||
CommandCost cost(EXPENSES_NEW_VEHICLES);
|
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);
|
uint sell_command = GetCmdSellVeh(vehicle_type);
|
||||||
|
|
||||||
|
if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Get the list of vehicles in the depot */
|
/* Get the list of vehicles in the depot */
|
||||||
BuildDepotVehicleList(vehicle_type, tile, &list, &list);
|
BuildDepotVehicleList(vehicle_type, tile, &list, &list);
|
||||||
|
|
||||||
|
@ -214,8 +219,9 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
{
|
{
|
||||||
VehicleList list;
|
VehicleList list;
|
||||||
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
|
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;
|
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Get the list of vehicles in the depot */
|
/* Get the list of vehicles in the depot */
|
||||||
|
|
|
@ -28,6 +28,7 @@ enum VehicleType {
|
||||||
VEH_INVALID = 0xFF, ///< Non-existing type of vehicle.
|
VEH_INVALID = 0xFF, ///< Non-existing type of vehicle.
|
||||||
};
|
};
|
||||||
DECLARE_POSTFIX_INCREMENT(VehicleType)
|
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 */
|
/** It needs to be 8bits, because we save and load it as such */
|
||||||
typedef SimpleTinyEnumT<VehicleType, byte> VehicleTypeByte;
|
typedef SimpleTinyEnumT<VehicleType, byte> VehicleTypeByte;
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
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 */
|
/* Outside of the editor you can only build canals, not oceans */
|
||||||
if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;
|
if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include "cmd_helper.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
#include "landscape.h"
|
#include "landscape.h"
|
||||||
#include "bridge_map.h"
|
#include "bridge_map.h"
|
||||||
|
@ -215,12 +216,12 @@ extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta,
|
||||||
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
/* Unpack parameters */
|
/* Unpack parameters */
|
||||||
Axis axis = (Axis)GB(p1, 4, 1);
|
Axis axis = Extract<Axis, 4, 1>(p1);
|
||||||
byte width = GB(p1, 8, 8);
|
byte width = GB(p1, 8, 8);
|
||||||
byte height = GB(p1, 16, 8);
|
byte height = GB(p1, 16, 8);
|
||||||
bool adjacent = HasBit(p1, 24);
|
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);
|
byte spec_index = GB(p2, 8, 8);
|
||||||
StationID station_to_join = GB(p2, 16, 16);
|
StationID station_to_join = GB(p2, 16, 16);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue