summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-08-12 18:34:09 +0000
committerrubidium <rubidium@openttd.org>2011-08-12 18:34:09 +0000
commitc8f19a608da349bdb22e286054daa08d049baf84 (patch)
tree2259134cb16a4d15445580ad6315db8d5a0aba72 /src/saveload
parent14fae95134d036262a3e070913fa8ebf5af16254 (diff)
downloadopenttd-c8f19a608da349bdb22e286054daa08d049baf84.tar.xz
(svn r22736) -Codechange: constify some numbers
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/strings_sl.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/saveload/strings_sl.cpp b/src/saveload/strings_sl.cpp
index 07a8ddd9f..6869a1af6 100644
--- a/src/saveload/strings_sl.cpp
+++ b/src/saveload/strings_sl.cpp
@@ -15,6 +15,10 @@
#include "table/strings.h"
+static const int NUM_OLD_STRINGS = 512; ///< The number of custom strings stored in old savegames.
+static const int LEN_OLD_STRINGS = 32; ///< The number of characters per string.
+static const int LEN_OLD_STRINGS_TTO = 24; ///< The number of characters per string in TTO savegames.
+
/**
* Remap a string ID from the old format to the new format
* @param s StringID that requires remapping
@@ -57,10 +61,9 @@ char *CopyFromOldName(StringID id)
if (GB(id, 11, 5) != 15) return NULL;
if (IsSavegameVersionBefore(37)) {
- /* Old names were 24/32 characters long, so 128 characters should be
- * plenty to allow for expansion when converted to UTF-8. */
- char tmp[128];
- uint offs = _savegame_type == SGT_TTO ? 24 * GB(id, 0, 8) : 32 * GB(id, 0, 9);
+ /* Allow for expansion when converted to UTF-8. */
+ char tmp[LEN_OLD_STRINGS * MAX_CHAR_LENGTH];
+ uint offs = _savegame_type == SGT_TTO ? LEN_OLD_STRINGS_TTO * GB(id, 0, 8) : LEN_OLD_STRINGS * GB(id, 0, 9);
const char *strfrom = &_old_name_array[offs];
char *strto = tmp;
@@ -92,7 +95,7 @@ char *CopyFromOldName(StringID id)
return strdup(tmp);
} else {
/* Name will already be in UTF-8. */
- return strdup(&_old_name_array[32 * GB(id, 0, 9)]);
+ return strdup(&_old_name_array[LEN_OLD_STRINGS * GB(id, 0, 9)]);
}
}
@@ -112,7 +115,7 @@ void ResetOldNames()
void InitializeOldNames()
{
free(_old_name_array);
- _old_name_array = CallocT<char>(512 * 32); // 200 * 24 would be enough for TTO savegames
+ _old_name_array = CallocT<char>(NUM_OLD_STRINGS * LEN_OLD_STRINGS); // 200 * 24 would be enough for TTO savegames
}
/**
@@ -123,7 +126,7 @@ static void Load_NAME()
int index;
while ((index = SlIterateArray()) != -1) {
- SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8);
+ SlArray(&_old_name_array[LEN_OLD_STRINGS * index], SlGetFieldLength(), SLE_UINT8);
}
}