MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / userStringAllocate

Function userStringAllocate

src/OpenLoco/src/Localisation/StringManager.cpp:79–109  ·  view source on GitHub ↗

0x00496522

Source from the content-addressed store, hash-verified

77
78 // 0x00496522
79 StringId userStringAllocate(char* str, bool mustBeUnique)
80 {
81 auto bestSlot = -1;
82 for (auto i = 0u; i < Limits::kMaxUserStrings; ++i)
83 {
84 char* userStr = rawUserStrings()[i];
85 if (*userStr == '\0')
86 {
87 bestSlot = i;
88 }
89 else if (mustBeUnique)
90 {
91 if (strcmp(str, userStr) == 0)
92 {
93 GameCommands::setErrorText(StringIds::chosen_name_in_use);
94 return StringIds::empty;
95 }
96 }
97 }
98
99 if (bestSlot == -1)
100 {
101 GameCommands::setErrorText(StringIds::too_many_names_in_use);
102 return StringIds::empty;
103 }
104
105 char* userStr = rawUserStrings()[bestSlot];
106 strncpy(userStr, str, kUserStringSize);
107 userStr[kUserStringSize - 1] = '\0';
108 return bestSlot + kUserStringsStart;
109 }
110
111 const char* getUserString(StringId id)
112 {

Callers 10

generateTownNameFunction · 0.85
generateNewStationNameFunction · 0.85
createCompanyFunction · 0.85
allocateNewIndustryFunction · 0.85
renameStationFunction · 0.85
renameVehicleFunction · 0.85
renameIndustryFunction · 0.85
changeCompanyOwnerNameFunction · 0.85
changeCompanyNameFunction · 0.85
renameTownFunction · 0.85

Calls 1

setErrorTextFunction · 0.85

Tested by

no test coverage detected