summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-13 06:05:01 +0000
committerrubidium <rubidium@openttd.org>2008-08-13 06:05:01 +0000
commitc816cc37fd01eb9b0842fd22cf5e79473d338c9f (patch)
treedd64aeafae6994a4ed4e2d23a71d62db7de1668f /src
parent688267ad524c955567924294d0e066379994773b (diff)
downloadopenttd-c816cc37fd01eb9b0842fd22cf5e79473d338c9f.tar.xz
(svn r14063) -Codechange: replace some "magic" constants with enumified constants.
Diffstat (limited to 'src')
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/engine_type.h4
-rw-r--r--src/group_gui.cpp2
-rw-r--r--src/group_type.h3
-rw-r--r--src/main_gui.cpp2
-rw-r--r--src/misc_cmd.cpp4
-rw-r--r--src/network/core/config.h2
-rw-r--r--src/network/network.cpp2
-rw-r--r--src/player_gui.cpp6
-rw-r--r--src/player_type.h6
-rw-r--r--src/signs_gui.cpp4
-rw-r--r--src/signs_type.h3
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/station_type.h5
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/town_type.h5
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/vehicle_type.h5
-rw-r--r--src/waypoint_type.h5
19 files changed, 48 insertions, 18 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index b1ec03e2c..eab5e15c2 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1091,7 +1091,7 @@ struct BuildVehicleWindow : Window {
case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE; break;
}
SetDParam(0, sel_eng);
- ShowQueryString(STR_ENGINE_NAME, str, 31, 160, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_ENGINE_NAME, str, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL);
}
break;
}
diff --git a/src/engine_type.h b/src/engine_type.h
index e6ed58377..38392d313 100644
--- a/src/engine_type.h
+++ b/src/engine_type.h
@@ -140,7 +140,9 @@ enum {
};
enum {
- NUM_VEHICLE_TYPES = 6
+ NUM_VEHICLE_TYPES = 6,
+ MAX_LENGTH_ENGINE_NAME_BYTES = 31, ///< The maximum length of an engine name in bytes including '\0'
+ MAX_LENGTH_ENGINE_NAME_PIXELS = 160, ///< The maximum length of an engine name in pixels
};
static const EngineID INVALID_ENGINE = 0xFFFF;
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 909ce8034..f806781c6 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -554,7 +554,7 @@ public:
const Group *g = GetGroup(this->group_sel);
SetDParam(0, g->index);
- ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, 31, 150, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL);
} break;
diff --git a/src/group_type.h b/src/group_type.h
index 9d4f269ed..94b25ab27 100644
--- a/src/group_type.h
+++ b/src/group_type.h
@@ -11,6 +11,9 @@ enum {
ALL_GROUP = 0xFFFD,
DEFAULT_GROUP = 0xFFFE, ///< ungrouped vehicles are in this group.
INVALID_GROUP = 0xFFFF,
+
+ MAX_LENGTH_GROUP_NAME_BYTES = 31, ///< The maximum length of a group name in bytes including '\0'
+ MAX_LENGTH_GROUP_NAME_PIXELS = 150, ///< The maximum length of a group name in pixels
};
struct Group;
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index fa89c91d3..218705527 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -145,7 +145,7 @@ void ShowRenameWaypointWindow(const Waypoint *wp)
_rename_id = id;
_rename_what = 1;
SetDParam(0, id);
- ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, 30, 180, NULL, CS_ALPHANUMERAL);
+ ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, NULL, CS_ALPHANUMERAL);
}
diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp
index 847200c49..00169e034 100644
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -224,7 +224,7 @@ static bool IsUniqueCompanyName(const char *name)
*/
CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_COMPANY_NAME) return CMD_ERROR;
+ if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
@@ -260,7 +260,7 @@ static bool IsUniquePresidentName(const char *name)
*/
CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_PRESIDENT_NAME) return CMD_ERROR;
+ if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
diff --git a/src/network/core/config.h b/src/network/core/config.h
index 72e4ca78a..7d9672036 100644
--- a/src/network/core/config.h
+++ b/src/network/core/config.h
@@ -24,7 +24,7 @@ enum {
NETWORK_MASTER_SERVER_VERSION = 1, ///< What version of master-server-protocol do we use?
NETWORK_NAME_LENGTH = 80, ///< The maximum length of the server name and map name, in bytes including '\0'
- NETWORK_COMPANY_NAME_LENGTH = 32, ///< The maximum length of the company name, in bytes including '\0'
+ NETWORK_COMPANY_NAME_LENGTH = 31, ///< The maximum length of the company name, in bytes including '\0'
NETWORK_HOSTNAME_LENGTH = 80, ///< The maximum length of the host name, in bytes including '\0'
NETWORK_UNIQUE_ID_LENGTH = 33, ///< The maximum length of the unique id of the clients, in bytes including '\0'
NETWORK_REVISION_LENGTH = 15, ///< The maximum length of the revision, in bytes including '\0'
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 54f6dd1b4..dff8c220d 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -72,7 +72,7 @@ uint8 _network_advertise_retries;
/* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
-assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME + 1);
+assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_BYTES);
// global variables (declared in network_data.h)
CommandPacket *_local_command_queue;
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index d4a101176..006e7244d 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -1222,7 +1222,7 @@ struct PlayerCompanyWindow : Window
/* "xxx (Manager)" */
SetDParam(0, p->index);
- DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
+ DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, MAX_LENGTH_PRESIDENT_NAME_PIXELS);
/* "Inaugurated:" */
SetDParam(0, p->inaugurated_year);
@@ -1257,13 +1257,13 @@ struct PlayerCompanyWindow : Window
case PCW_WIDGET_PRESIDENT_NAME:
this->query_widget = PCW_WIDGET_PRESIDENT_NAME;
SetDParam(0, this->window_number);
- ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME, 94, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL);
break;
case PCW_WIDGET_COMPANY_NAME:
this->query_widget = PCW_WIDGET_COMPANY_NAME;
SetDParam(0, this->window_number);
- ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME, 150, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL);
break;
case PCW_WIDGET_BUILD_VIEW_HQ: {
diff --git a/src/player_type.h b/src/player_type.h
index 0dbd4e687..aa7aea868 100644
--- a/src/player_type.h
+++ b/src/player_type.h
@@ -31,8 +31,10 @@ enum Owner {
DECLARE_POSTFIX_INCREMENT(Owner);
enum {
- MAX_LENGTH_PRESIDENT_NAME = 31, ///< The maximum length for a president's name
- MAX_LENGTH_COMPANY_NAME = 31, ///< The maximum length for a company's name
+ MAX_LENGTH_PRESIDENT_NAME_BYTES = 31, ///< The maximum length of a president name in bytes including '\0'
+ MAX_LENGTH_PRESIDENT_NAME_PIXELS = 94, ///< The maximum length of a president name in pixels
+ MAX_LENGTH_COMPANY_NAME_BYTES = 31, ///< The maximum length of a company name in bytes including '\0'
+ MAX_LENGTH_COMPANY_NAME_PIXELS = 150, ///< The maximum length of a company name in pixels
};
/** Define basic enum properties */
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 50b436ee6..ec0da0679 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -188,7 +188,7 @@ enum QueryEditSignWidgets {
struct SignWindow : QueryStringBaseWindow, SignList {
SignID cur_sign;
- SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(31, desc)
+ SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES, desc)
{
SetBit(_no_scroll, SCROLL_EDIT);
this->caption = STR_280B_EDIT_SIGN_TEXT;
@@ -218,7 +218,7 @@ struct SignWindow : QueryStringBaseWindow, SignList {
*last_of = '\0';
this->cur_sign = si->index;
- InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 255);
+ InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, MAX_LENGTH_SIGN_NAME_PIXELS);
this->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
}
diff --git a/src/signs_type.h b/src/signs_type.h
index 7f1dc5f4f..1757a96ef 100644
--- a/src/signs_type.h
+++ b/src/signs_type.h
@@ -10,6 +10,9 @@ struct Sign;
enum {
INVALID_SIGN = 0xFFFF,
+
+ MAX_LENGTH_SIGN_NAME_BYTES = 31, ///< The maximum length of a sign name in bytes including '\0'
+ MAX_LENGTH_SIGN_NAME_PIXELS = 255, ///< The maximum length of a sign name in pixels
};
#endif /* SIGNS_TYPE_H */
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index d1bcf3623..c382c783a 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -911,7 +911,7 @@ struct StationViewWindow : public Window {
case SVW_RENAME:
SetDParam(0, this->window_number);
- ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL);
break;
case SVW_TRAINS: { // Show a list of scheduled trains to this station
diff --git a/src/station_type.h b/src/station_type.h
index 092f1cf91..85457d544 100644
--- a/src/station_type.h
+++ b/src/station_type.h
@@ -62,4 +62,9 @@ enum CatchmentArea {
MAX_CATCHMENT = 10, ///< Airports have a catchment up to this number.
};
+enum {
+ MAX_LENGTH_STATION_NAME_BYTES = 31, ///< The maximum length of a station name in bytes including '\0'
+ MAX_LENGTH_STATION_NAME_PIXELS = 180, ///< The maximum length of a station name in pixels
+};
+
#endif /* STATION_TYPE_H */
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 78416c3ba..7c8b97376 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -370,7 +370,7 @@ public:
case TVW_CHANGENAME: /* rename */
SetDParam(0, this->window_number);
- ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL);
break;
case TVW_EXPAND: /* expand town - only available on Scenario editor */
diff --git a/src/town_type.h b/src/town_type.h
index 0127d92ed..3cb4151be 100644
--- a/src/town_type.h
+++ b/src/town_type.h
@@ -81,4 +81,9 @@ enum TownLayout {
template <> struct EnumPropsT<TownLayout> : MakeEnumPropsT<TownLayout, byte, TL_NO_ROADS, NUM_TLS, NUM_TLS> {};
typedef TinyEnumT<TownLayout> TownLayoutByte; //typedefing-enumification of TownLayout
+enum {
+ MAX_LENGTH_TOWN_NAME_BYTES = 31, ///< The maximum length of a town name in bytes including '\0'
+ MAX_LENGTH_TOWN_NAME_PIXELS = 130, ///< The maximum length of a town name in pixels
+};
+
#endif /* TOWN_TYPE_H */
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index cf2ea725b..24f0f5d1e 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1475,7 +1475,7 @@ struct VehicleDetailsWindow : Window {
case VLD_WIDGET_RENAME_VEHICLE: {// rename
const Vehicle *v = GetVehicle(this->window_number);
SetDParam(0, v->index);
- ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], 31, 150, this, CS_ALPHANUMERAL);
+ ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], MAX_LENGTH_VEHICLE_NAME_BYTES, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL);
} break;
case VLD_WIDGET_INCREASE_SERVICING_INTERVAL: // increase int
diff --git a/src/vehicle_type.h b/src/vehicle_type.h
index 79495cd1c..6a9d7c060 100644
--- a/src/vehicle_type.h
+++ b/src/vehicle_type.h
@@ -56,4 +56,9 @@ enum DepotCommand {
DEPOT_COMMAND_MASK = 0xF,
};
+enum {
+ MAX_LENGTH_VEHICLE_NAME_BYTES = 31, ///< The maximum length of a vehicle name in bytes including '\0'
+ MAX_LENGTH_VEHICLE_NAME_PIXELS = 150, ///< The maximum length of a vehicle name in pixels
+};
+
#endif /* VEHICLE_TYPE_H */
diff --git a/src/waypoint_type.h b/src/waypoint_type.h
index c74e8cf92..404ba7c68 100644
--- a/src/waypoint_type.h
+++ b/src/waypoint_type.h
@@ -8,4 +8,9 @@
typedef uint16 WaypointID;
struct Waypoint;
+enum {
+ MAX_LENGTH_WAYPOINT_NAME_BYTES = 31, ///< The maximum length of a waypoint name in bytes including '\0'
+ MAX_LENGTH_WAYPOINT_NAME_PIXELS = 180, ///< The maximum length of a waypoint name in pixels
+};
+
#endif /* WAYPOINT_TYPE_H */