summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2013-01-22 03:54:40 +0000
committerpeter1138 <peter1138@openttd.org>2013-01-22 03:54:40 +0000
commitc18446951d57c1061405b11f048dca97f730a707 (patch)
tree95a7b97fccb90ace7cffc5daa299d8b4dc17679a /src
parent7e8efa04fe4fffa5237349c3c30b8489ae491274 (diff)
downloadopenttd-c18446951d57c1061405b11f048dca97f730a707.tar.xz
(svn r24932) -Fix [FS#5158]: Prevent more NewGRFs being selected than is possible to load.
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/newgrf_gui.cpp11
2 files changed, 12 insertions, 0 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index a69b6b0c1..42c5c07b2 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2763,6 +2763,7 @@ STR_NEWGRF_CONFIRMATION_TEXT :{YELLOW}You are
STR_NEWGRF_DUPLICATE_GRFID :{WHITE}Can't add file: duplicate GRF ID
STR_NEWGRF_COMPATIBLE_LOADED :{ORANGE}Matching file not found (compatible GRF loaded)
+STR_NEWGRF_TOO_MANY_NEWGRFS :{WHITE}Can't add file: NewGRF file limit reached
STR_NEWGRF_COMPATIBLE_LOAD_WARNING :{WHITE}Compatible GRF(s) loaded for missing files
STR_NEWGRF_DISABLED_WARNING :{WHITE}Missing GRF file(s) have been disabled
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 4495a05d8..84e48da45 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -29,12 +29,17 @@
#include "newgrf_text.h"
#include "textfile_gui.h"
#include "tilehighlight_func.h"
+#include "fios.h"
#include "widgets/newgrf_widget.h"
#include "widgets/misc_widget.h"
#include "table/sprites.h"
+/* Maximum number of NewGRFs that may be loaded. Six reserved slots are:
+ * 0 - config, 1 - sound, 2 - base, 3 - logos, 4 - climate, 5 - extra */
+static const int MAX_NEWGRFS = MAX_FILE_SLOTS - 6;
+
/**
* Show the first NewGRF error we can find.
*/
@@ -1432,6 +1437,7 @@ private:
{
if (this->avail_sel == NULL || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
+ int count = 0;
GRFConfig **entry = NULL;
GRFConfig **list;
/* Find last entry in the list, checking for duplicate grfid on the way */
@@ -1441,8 +1447,13 @@ private:
ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
return false;
}
+ count++;
}
if (entry == NULL) entry = list;
+ if (count >= MAX_NEWGRFS) {
+ ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
+ return false;
+ }
GRFConfig *c = new GRFConfig(*this->avail_sel); // Copy GRF details from scanned list.
c->SetParameterDefaults();