Changeset - r26169:fdb7183fad74
[Not reviewed]
master
1 21 0
J0anJosep - 2 years ago 2022-01-08 11:01:37
juanjo.ng.83@gmail.com
Cleanup #9725: Replace cmd_helper related functions and remove cmd_helper.h.
22 files changed with 60 insertions and 74 deletions:
0 comments (0 inline, 0 general)
src/CMakeLists.txt
Show inline comments
 
@@ -87,7 +87,6 @@ add_files(
 
    clear_cmd.cpp
 
    clear_func.h
 
    clear_map.h
 
    cmd_helper.h
 
    command.cpp
 
    command_func.h
 
    command_type.h
src/bridge_gui.cpp
Show inline comments
 
@@ -20,7 +20,6 @@
 
#include "sortlist_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "core/geometry_func.hpp"
 
#include "cmd_helper.h"
 
#include "tunnelbridge_map.h"
 
#include "road_gui.h"
 
#include "tunnelbridge_cmd.h"
src/cmd_helper.h
Show inline comments
 
deleted file
src/company_cmd.cpp
Show inline comments
 
@@ -14,7 +14,6 @@
 
#include "core/backup_type.hpp"
 
#include "town.h"
 
#include "news_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
src/gfx_func.h
Show inline comments
 
@@ -174,6 +174,17 @@ int GetCharacterHeight(FontSize size);
 

	
 
extern DrawPixelInfo *_cur_dpi;
 

	
 
/**
 
 * Checks if a Colours value is valid.
 
 *
 
 * @param colours The value to check
 
 * @return true if the given value is a valid Colours.
 
 */
 
static inline bool IsValidColours(Colours colours)
 
{
 
	return colours < COLOUR_END;
 
}
 

	
 
TextColour GetContrastColour(uint8 background, uint8 threshold = 128);
 

	
 
/**
src/group_cmd.cpp
Show inline comments
 
@@ -8,7 +8,6 @@
 
/** @file group_cmd.cpp Handling of the engine groups */
 

	
 
#include "stdafx.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "train.h"
 
#include "vehiclelist.h"
src/industry_cmd.cpp
Show inline comments
 
@@ -40,7 +40,6 @@
 
#include "object_base.h"
 
#include "game/game.hpp"
 
#include "error.h"
 
#include "cmd_helper.h"
 
#include "string_func.h"
 
#include "industry_cmd.h"
 
#include "landscape_cmd.h"
src/misc_cmd.cpp
Show inline comments
 
@@ -10,7 +10,6 @@
 
#include "stdafx.h"
 
#include "command_func.h"
 
#include "economy_func.h"
 
#include "cmd_helper.h"
 
#include "window_func.h"
 
#include "textbuf_gui.h"
 
#include "network/network.h"
src/order_cmd.cpp
Show inline comments
 
@@ -9,7 +9,6 @@
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_func.h"
 
#include "news_func.h"
src/rail_cmd.cpp
Show inline comments
 
@@ -8,7 +8,6 @@
 
/** @file rail_cmd.cpp Handling of rail tiles. */
 

	
 
#include "stdafx.h"
 
#include "cmd_helper.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
#include "depot_base.h"
 
@@ -966,7 +965,7 @@ CommandCost CmdRemoveRailroadTrack(DoCom
 
CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType railtype, DiagDirection dir)
 
{
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	if (!ValParamRailtype(railtype) || !IsEnumValid(dir)) return CMD_ERROR;
 
	if (!ValParamRailtype(railtype) || !IsValidDiagDirection(dir)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile);
 

	
src/road_cmd.cpp
Show inline comments
 
@@ -8,7 +8,6 @@
 
/** @file road_cmd.cpp Commands related to road tiles. */
 

	
 
#include "stdafx.h"
 
#include "cmd_helper.h"
 
#include "road.h"
 
#include "road_internal.h"
 
#include "viewport_func.h"
 
@@ -638,7 +637,7 @@ CommandCost CmdBuildRoad(DoCommandFlag f
 
	}
 

	
 
	/* do not allow building 'zero' road bits, code wouldn't handle it */
 
	if (pieces == ROAD_NONE || !IsEnumValid(pieces) || !IsEnumValid(toggle_drd)) return CMD_ERROR;
 
	if (pieces == ROAD_NONE || !IsValidRoadBits(pieces) || !IsValidDisallowedRoadDirections(toggle_drd)) return CMD_ERROR;
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile);
 
@@ -979,7 +978,7 @@ CommandCost CmdBuildLongRoad(DoCommandFl
 
{
 
	if (end_tile >= MapSize()) return CMD_ERROR;
 

	
 
	if (!ValParamRoadType(rt) || !IsEnumValid(axis) || !IsEnumValid(drd)) return CMD_ERROR;
 
	if (!ValParamRoadType(rt) || !IsValidAxis(axis) || !IsValidDisallowedRoadDirections(drd)) return CMD_ERROR;
 

	
 
	/* 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
 
@@ -1075,7 +1074,7 @@ std::tuple<CommandCost, Money> CmdRemove
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (end_tile >= MapSize()) return { CMD_ERROR, 0 };
 
	if (!ValParamRoadType(rt) || !IsEnumValid(axis)) return { CMD_ERROR, 0 };
 
	if (!ValParamRoadType(rt) || !IsValidAxis(axis)) return { CMD_ERROR, 0 };
 

	
 
	/* 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, 0 }; // x-axis
 
@@ -1140,7 +1139,7 @@ std::tuple<CommandCost, Money> CmdRemove
 
 */
 
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
 
{
 
	if (!ValParamRoadType(rt) || !IsEnumValid(dir)) return CMD_ERROR;
 
	if (!ValParamRoadType(rt) || !IsValidDiagDirection(dir)) return CMD_ERROR;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
src/road_map.h
Show inline comments
 
@@ -283,6 +283,17 @@ static inline bool HasTownOwnedRoad(Tile
 
}
 

	
 
/**
 
 * Checks if a DisallowedRoadDirections is valid.
 
 *
 
 * @param wc The value to check
 
 * @return true if the given value is a valid DisallowedRoadDirections.
 
 */
 
static inline bool IsValidDisallowedRoadDirections(DisallowedRoadDirections drt)
 
{
 
	return drt < DRD_END;
 
}
 

	
 
/**
 
 * Gets the disallowed directions
 
 * @param t the tile to get the directions from
 
 * @return the disallowed directions
src/station_cmd.cpp
Show inline comments
 
@@ -10,7 +10,6 @@
 
#include "stdafx.h"
 
#include "aircraft.h"
 
#include "bridge_map.h"
 
#include "cmd_helper.h"
 
#include "viewport_func.h"
 
#include "viewport_kdtree.h"
 
#include "command_func.h"
 
@@ -1257,7 +1256,7 @@ CommandCost CmdBuildRailStation(DoComman
 
	CommandCost ret = CheckIfAuthorityAllowsNewStation(tile_org, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	if (!ValParamRailtype(rt) || !IsEnumValid(axis)) return CMD_ERROR;
 
	if (!ValParamRailtype(rt) || !IsValidAxis(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;
 
@@ -1818,7 +1817,7 @@ static CommandCost FindJoiningRoadStop(S
 
 */
 
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)
 
{
 
	if (!ValParamRoadType(rt) || !IsEnumValid(ddir) || stop_type >= ROADSTOP_END) return CMD_ERROR;
 
	if (!ValParamRoadType(rt) || !IsValidDiagDirection(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);
src/story.cpp
Show inline comments
 
@@ -10,7 +10,6 @@
 
#include "stdafx.h"
 
#include "story_base.h"
 
#include "core/pool_func.hpp"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_base.h"
 
#include "company_func.h"
 
@@ -144,7 +143,9 @@ void StoryPageButtonData::SetVehicleType
 
/** Get the button background colour. */
 
Colours StoryPageButtonData::GetColour() const
 
{
 
	return Extract<Colours, 0, 8>(this->referenced_id);
 
	Colours colour = (Colours)GB(this->referenced_id, 0, 8);
 
	if (!IsValidColours(colour)) return INVALID_COLOUR;
 
	return colour;
 
}
 

	
 
StoryPageButtonFlags StoryPageButtonData::GetFlags() const
 
@@ -155,7 +156,9 @@ StoryPageButtonFlags StoryPageButtonData
 
/** Get the mouse cursor used while waiting for input for the button. */
 
StoryPageButtonCursor StoryPageButtonData::GetCursor() const
 
{
 
	return Extract<StoryPageButtonCursor, 8, 8>(this->referenced_id);
 
	StoryPageButtonCursor cursor = (StoryPageButtonCursor)GB(this->referenced_id, 8, 8);
 
	if (!IsValidStoryPageButtonCursor(cursor)) return INVALID_SPBC;
 
	return cursor;
 
}
 

	
 
/** Get the type of vehicles that are accepted by the button */
src/story_base.h
Show inline comments
 
@@ -113,6 +113,17 @@ enum StoryPageButtonCursor : byte {
 
/** Define basic enum properties */
 
template <> struct EnumPropsT<StoryPageButtonCursor> : MakeEnumPropsT<StoryPageButtonCursor, byte, SPBC_MOUSE, SPBC_END, INVALID_SPBC, 8> {};
 

	
 
/**
 
 * Checks if a StoryPageButtonCursor value is valid.
 
 *
 
 * @param wc The value to check
 
 * @return true if the given value is a valid StoryPageButtonCursor.
 
 */
 
static inline bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
 
{
 
	return cursor < SPBC_END;
 
}
 

	
 
/** Helper to construct packed "id" values for button-type StoryPageElement */
 
struct StoryPageButtonData {
 
	uint32 referenced_id;
src/timetable_cmd.cpp
Show inline comments
 
@@ -13,7 +13,6 @@
 
#include "date_func.h"
 
#include "window_func.h"
 
#include "vehicle_base.h"
 
#include "cmd_helper.h"
 
#include "timetable_cmd.h"
 

	
 
#include "table/strings.h"
src/town_cmd.cpp
Show inline comments
 
@@ -14,7 +14,6 @@
 
#include "landscape.h"
 
#include "viewport_func.h"
 
#include "viewport_kdtree.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "industry.h"
 
#include "station_base.h"
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -14,7 +14,6 @@
 
#include "stdafx.h"
 
#include "newgrf_object.h"
 
#include "viewport_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "town.h"
 
#include "train.h"
src/vehicle_cmd.cpp
Show inline comments
 
@@ -11,7 +11,6 @@
 
#include "roadveh.h"
 
#include "news_func.h"
 
#include "airport.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_func.h"
 
#include "train.h"
src/water_cmd.cpp
Show inline comments
 
@@ -8,7 +8,6 @@
 
/** @file water_cmd.cpp Handling of water tiles. */
 

	
 
#include "stdafx.h"
 
#include "cmd_helper.h"
 
#include "landscape.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
@@ -100,7 +99,7 @@ static void MarkCanalsAndRiversAroundDir
 
 */
 
CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, Axis axis)
 
{
 
	if (!IsEnumValid(axis)) return CMD_ERROR;
 
	if (!IsValidAxis(axis)) return CMD_ERROR;
 
	TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
 
@@ -439,7 +438,7 @@ bool RiverModifyDesertZone(TileIndex til
 
 */
 
CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
 
{
 
	if (start_tile >= MapSize() || !IsEnumValid(wc)) return CMD_ERROR;
 
	if (start_tile >= MapSize() || !IsValidWaterClass(wc)) return CMD_ERROR;
 

	
 
	/* Outside of the editor you can only build canals, not oceans */
 
	if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
src/water_map.h
Show inline comments
 
@@ -53,6 +53,17 @@ enum WaterClass : byte {
 
/** Helper information for extract tool. */
 
template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
 

	
 
/**
 
 * Checks if a water class is valid.
 
 *
 
 * @param wc The value to check
 
 * @return true if the given value is a valid water class.
 
 */
 
static inline bool IsValidWaterClass(WaterClass wc)
 
{
 
	return wc < WATER_CLASS_INVALID;
 
}
 

	
 
/** Sections of the water depot. */
 
enum DepotPart {
 
	DEPOT_PART_NORTH = 0, ///< Northern part of a depot.
src/waypoint_cmd.cpp
Show inline comments
 
@@ -9,7 +9,6 @@
 

	
 
#include "stdafx.h"
 

	
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "landscape.h"
 
#include "bridge_map.h"
 
@@ -175,7 +174,7 @@ extern CommandCost CanExpandRailStation(
 
 */
 
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)
 
{
 
	if (!IsEnumValid(axis)) return CMD_ERROR;
 
	if (!IsValidAxis(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;
0 comments (0 inline, 0 general)