summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-03 13:27:08 +0000
committerrubidium <rubidium@openttd.org>2009-01-03 13:27:08 +0000
commitfa2bf69a5384a8035a92a069f47f31a178bc3f3c (patch)
tree2e6f8dd908d22c3e124e12b75835554deac21b8d /src
parentd428da5a356a3d9036b21b502bc90488270cdca9 (diff)
downloadopenttd-fa2bf69a5384a8035a92a069f47f31a178bc3f3c.tar.xz
(svn r14802) -Fix [FS#2490]: "(undefined string)" in default savegame/screenshot names when there's no company in the game.
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/saveload.cpp22
2 files changed, 19 insertions, 4 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 5b1224f9f..5875c7bf1 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2017,6 +2017,7 @@ STR_4001_LOAD_GAME :{WHITE}Load Gam
STR_4002_SAVE :{BLACK}Save
STR_4003_DELETE :{BLACK}Delete
STR_4004 :{COMPANY}, {STRING1}
+STR_GAME_SAVELOAD_SPECTATOR_SAVEGAME :Spectator, {SKIP}{STRING1}
STR_4005_BYTES_FREE :{BLACK}{COMMA} megabyte{P "" s} free
STR_4006_UNABLE_TO_READ_DRIVE :{BLACK}Unable to read drive
STR_4007_GAME_SAVE_FAILED :{WHITE}Game Save Failed{}{STRING}
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 2fb119e17..a5de05b06 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -1826,9 +1826,21 @@ void DoExitSave()
*/
void GenerateDefaultSaveName(char *buf, const char *last)
{
- /* Check if we are not a spectator who wants to generate a name..
- * Let's use the name of company #0 for now. */
- SetDParam(0, IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
+ /* Check if we have a name for this map, which is the name of the first
+ * available company. When there's no company available we'll use
+ * 'Spectator' as "company" name. */
+ CompanyID cid = _local_company;
+ if (!IsValidCompanyID(cid)) {
+ const Company *c;
+ FOR_ALL_COMPANIES(c) {
+ cid = c->index;
+ break;
+ }
+ }
+
+ SetDParam(0, cid);
+
+ /* Insert current date */
switch (_settings_client.gui.date_format_in_default_names) {
case 0: SetDParam(1, STR_JUST_DATE_LONG); break;
case 1: SetDParam(1, STR_JUST_DATE_TINY); break;
@@ -1836,7 +1848,9 @@ void GenerateDefaultSaveName(char *buf, const char *last)
default: NOT_REACHED();
}
SetDParam(2, _date);
- GetString(buf, STR_4004, last);
+
+ /* Get the correct string (special string for when there's not company) */
+ GetString(buf, IsValidCompanyID(cid) ? STR_GAME_SAVELOAD_SPECTATOR_SAVEGAME : STR_4004, last);
SanitizeFilename(buf);
}