diff options
author | Michael Lutz <michi@icosahedron.de> | 2020-05-17 23:31:59 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2020-05-21 20:02:34 +0200 |
commit | 63ccb36ef3ecd53a503c0e9fea87f0784802af0f (patch) | |
tree | d3e1134029fd437d1ad2d948f83592b930e9456f /src/company_cmd.cpp | |
parent | 9b6f5e3bb850b6cff02cc761767fcdf49c681645 (diff) | |
download | openttd-63ccb36ef3ecd53a503c0e9fea87f0784802af0f.tar.xz |
Codechange: Use std::string for most of the user-settable custom names.
Diffstat (limited to 'src/company_cmd.cpp')
-rw-r--r-- | src/company_cmd.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 835a7c4a8..25b3fe6fb 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -353,7 +353,7 @@ static void GenerateCompanyName(Company *c) StringID str; uint32 strp; - if (t->name == nullptr && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { + if (t->name.empty() && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START; strp = t->townnameparts; @@ -1043,7 +1043,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, static bool IsUniqueCompanyName(const char *name) { for (const Company *c : Company::Iterate()) { - if (c->name != nullptr && strcmp(c->name, name) == 0) return false; + if (!c->name.empty() && c->name == name) return false; } return true; @@ -1069,8 +1069,11 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (flags & DC_EXEC) { Company *c = Company::Get(_current_company); - free(c->name); - c->name = reset ? nullptr : stredup(text); + if (reset) { + c->name.clear(); + } else { + c->name = text; + } MarkWholeScreenDirty(); CompanyAdminUpdate(c); } @@ -1086,7 +1089,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin static bool IsUniquePresidentName(const char *name) { for (const Company *c : Company::Iterate()) { - if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false; + if (!c->president_name.empty() && c->president_name == name) return false; } return true; @@ -1112,14 +1115,13 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u if (flags & DC_EXEC) { Company *c = Company::Get(_current_company); - free(c->president_name); if (reset) { - c->president_name = nullptr; + c->president_name.clear(); } else { - c->president_name = stredup(text); + c->president_name = text; - if (c->name_1 == STR_SV_UNNAMED && c->name == nullptr) { + if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) { char buf[80]; seprintf(buf, lastof(buf), "%s Transport", text); |