summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-05 22:24:50 +0000
committerrubidium <rubidium@openttd.org>2010-12-05 22:24:50 +0000
commitcf61c2f11fbffe20749382feb8fe03d238a2888d (patch)
treef6a5ff6ee367f3a62f59d1e7099aeafcfb665b5f
parent768da4b48f8c70177cb5dfc77a30a23a98a3ae05 (diff)
downloadopenttd-cf61c2f11fbffe20749382feb8fe03d238a2888d.tar.xz
(svn r21412) -Codechange: limit company name by amount of characters, not bytes
-rw-r--r--src/ai/api/ai_company.cpp2
-rw-r--r--src/company_cmd.cpp6
-rw-r--r--src/company_gui.cpp2
-rw-r--r--src/company_type.h2
-rw-r--r--src/network/core/config.h2
-rw-r--r--src/network/network.cpp2
-rw-r--r--src/subsidy.cpp12
-rw-r--r--src/town_cmd.cpp4
8 files changed, 17 insertions, 15 deletions
diff --git a/src/ai/api/ai_company.cpp b/src/ai/api/ai_company.cpp
index e11b2bb4b..03a642609 100644
--- a/src/ai/api/ai_company.cpp
+++ b/src/ai/api/ai_company.cpp
@@ -38,7 +38,7 @@
/* static */ bool AICompany::SetName(const char *name)
{
EnforcePrecondition(false, !::StrEmpty(name));
- EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_COMPANY_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
+ EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_COMPANY_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
return AIObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name);
}
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index d44f4c4ab..3e9cf9463 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -325,7 +325,7 @@ static void GenerateCompanyName(Company *c)
{
/* Reserve space for extra unicode character. We need to do this to be able
* to detect too long company name. */
- char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH];
+ char buffer[(MAX_LENGTH_COMPANY_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
if (c->name_1 != STR_SV_UNNAMED) return;
if (c->last_build_coordinate == 0) return;
@@ -346,7 +346,7 @@ verify_name:;
}
GetString(buffer, str, lastof(buffer));
- if (strlen(buffer) >= MAX_LENGTH_COMPANY_NAME_BYTES) goto bad_town_name;
+ if (Utf8StringLength(buffer) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
set_name:;
c->name_1 = str;
@@ -1049,7 +1049,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
bool reset = StrEmpty(text);
if (!reset) {
- if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
+ if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
diff --git a/src/company_gui.cpp b/src/company_gui.cpp
index d5176abf6..8471ccfe3 100644
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -1952,7 +1952,7 @@ struct CompanyWindow : Window
case CW_WIDGET_COMPANY_NAME:
this->query_widget = CW_WIDGET_COMPANY_NAME;
SetDParam(0, this->window_number);
- ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
+ ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
break;
case CW_WIDGET_VIEW_HQ: {
diff --git a/src/company_type.h b/src/company_type.h
index 7e308b6f7..1671f70df 100644
--- a/src/company_type.h
+++ b/src/company_type.h
@@ -39,7 +39,7 @@ DECLARE_POSTFIX_INCREMENT(Owner)
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS = 31; ///< The maximum length of a president name in characters including '\0'
static const uint MAX_LENGTH_PRESIDENT_NAME_PIXELS = 94; ///< The maximum length of a president name in pixels
-static const uint MAX_LENGTH_COMPANY_NAME_BYTES = 31; ///< The maximum length of a company name in bytes including '\0'
+static const uint MAX_LENGTH_COMPANY_NAME_CHARS = 32; ///< The maximum length of a company name in characters including '\0'
static const uint MAX_LENGTH_COMPANY_NAME_PIXELS = 150; ///< The maximum length of a company name in pixels
static const uint MAX_HISTORY_MONTHS = 24; ///< The maximum number of months kept as performance's history
diff --git a/src/network/core/config.h b/src/network/core/config.h
index 584e0382a..ff4d6e22e 100644
--- a/src/network/core/config.h
+++ b/src/network/core/config.h
@@ -40,7 +40,7 @@ static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of c
static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What version of master-server-protocol do we use?
static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0'
-static const uint NETWORK_COMPANY_NAME_LENGTH = 31; ///< The maximum length of the company name, in bytes including '\0'
+static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0'
static const uint NETWORK_HOSTNAME_LENGTH = 80; ///< The maximum length of the host name, in bytes including '\0'
static const uint NETWORK_SERVER_ID_LENGTH = 33; ///< The maximum length of the network id of the servers, in bytes including '\0'
static const uint 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 242f89acf..5631643d2 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -82,7 +82,7 @@ CompanyMask _network_company_passworded; ///< Bitmask of the password status of
/* 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_BYTES);
+assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
extern NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index e83da0ab2..341166480 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -40,20 +40,22 @@ void Subsidy::AwardTo(CompanyID company)
this->awarded = company;
this->remaining = SUBSIDY_CONTRACT_MONTHS;
- char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
- SetDParam(0, company);
- GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
+ char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
+ SetDParam(0, _current_company);
+ GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
+
+ char *cn = strdup(company_name);
/* Add a news item */
Pair reftype = SetupSubsidyDecodeParam(this, false);
InjectDParam(1);
- SetDParamStr(0, company_name);
+ SetDParamStr(0, cn);
AddNewsItem(
STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
NS_SUBSIDIES,
(NewsReferenceType)reftype.a, this->src, (NewsReferenceType)reftype.b, this->dst,
- company_name
+ cn
);
AI::BroadcastNewEvent(new AIEventSubsidyAwarded(this->index));
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index ddf3f186b..bf2ea082b 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1596,7 +1596,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (_game_mode != GM_EDITOR) {
/* 't' can't be NULL since 'random' is false outside scenedit */
assert(!random);
- char company_name[MAX_LENGTH_COMPANY_NAME_BYTES];
+ char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
SetDParam(0, _current_company);
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
@@ -2466,7 +2466,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
if (flags & DC_EXEC) {
t->road_build_months = 6;
- char company_name[MAX_LENGTH_COMPANY_NAME_BYTES];
+ char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
SetDParam(0, _current_company);
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));