changeset 18017:63bd30142ab5 draft

(svn r22826) -Codechange: pass sub directory to NewGRF loading functions
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 13:48:29 +0000
parents 09780d1c580a
children 873018a3a54e
files src/gfxinit.cpp src/newgrf.cpp src/newgrf.h src/newgrf_config.cpp src/newgrf_config.h
diffstat 5 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -180,7 +180,7 @@
 		case PAL_WINDOWS: master->palette |= GRFP_GRF_WINDOWS; break;
 		default: break;
 	}
-	FillGRFDetails(master, false);
+	FillGRFDetails(master, false, BASESET_DIR);
 
 	ClrBit(master->flags, GCF_INIT_ONLY);
 	master->next = top;
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -8076,7 +8076,14 @@
 }
 
 
-void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
+/**
+ * Load a particular NewGRF.
+ * @param config     The configuration of the to be loaded NewGRF.
+ * @param file_index The Fio index of the first NewGRF to load.
+ * @param stage      The loading stage of the NewGRF.
+ * @param subdir     The sub directory to find the NewGRF in.
+ */
+void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
 {
 	const char *filename = config->filename;
 	uint16 num;
@@ -8105,7 +8112,7 @@
 		return;
 	}
 
-	FioOpenFile(file_index, filename, NEWGRF_DIR);
+	FioOpenFile(file_index, filename, subdir);
 	_cur.file_index = file_index; // XXX
 	_palette_remap_grf[_cur.file_index] = (config->palette & GRFP_USE_MASK);
 
@@ -8404,6 +8411,11 @@
 	_grm_sprites.clear();
 }
 
+/**
+ * Load all the NewGRFs.
+ * @param load_index The offset for the first sprite to add.
+ * @param file_index The Fio index of the first NewGRF to load.
+ */
 void LoadNewGRF(uint load_index, uint file_index)
 {
 	/* In case of networking we need to "sync" the start values
@@ -8458,14 +8470,15 @@
 			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
 			if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
 
-			if (!FioCheckFileExists(c->filename)) {
+			Subdirectory subdir = slot == file_index ? BASESET_DIR : NEWGRF_DIR;
+			if (!FioCheckFileExists(c->filename, subdir)) {
 				DEBUG(grf, 0, "NewGRF file is missing '%s'; disabling", c->filename);
 				c->status = GCS_NOT_FOUND;
 				continue;
 			}
 
 			if (stage == GLS_LABELSCAN) InitNewGRFFile(c);
-			LoadNewGRFFile(c, slot++, stage);
+			LoadNewGRFFile(c, slot++, stage, subdir);
 			if (stage == GLS_RESERVE) {
 				SetBit(c->flags, GCF_RESERVED);
 			} else if (stage == GLS_ACTIVATION) {
--- a/src/newgrf.h
+++ b/src/newgrf.h
@@ -14,6 +14,7 @@
 
 #include "cargotype.h"
 #include "rail_type.h"
+#include "fileio_type.h"
 
 enum GrfLoadingStage {
 	GLS_FILESCAN,
@@ -139,7 +140,7 @@
 /* Indicates which are the newgrf features currently loaded ingame */
 extern GRFLoadedFeatures _loaded_newgrf_features;
 
-void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage);
+void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
 void LoadNewGRF(uint load_index, uint file_index);
 void ReloadNewGRFData(); // in saveload/afterload.cpp
 void ResetNewGRFData();
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -282,9 +282,10 @@
 /**
  * Calculate the MD5 sum for a GRF, and store it in the config.
  * @param config GRF to compute.
+ * @param subdir The subdirectory to look in.
  * @return MD5 sum was successfully computed
  */
-static bool CalcGRFMD5Sum(GRFConfig *config)
+static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
 {
 	FILE *f;
 	Md5 checksum;
@@ -292,7 +293,7 @@
 	size_t len, size;
 
 	/* open the file */
-	f = FioFOpenFile(config->filename, "rb", NEWGRF_DIR, &size);
+	f = FioFOpenFile(config->filename, "rb", subdir, &size);
 	if (f == NULL) return false;
 
 	/* calculate md5sum */
@@ -312,17 +313,18 @@
  * Find the GRFID of a given grf, and calculate its md5sum.
  * @param config    grf to fill.
  * @param is_static grf is static.
+ * @param subdir    the subdirectory to search in.
  * @return Operation was successfully completed.
  */
-bool FillGRFDetails(GRFConfig *config, bool is_static)
+bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
 {
-	if (!FioCheckFileExists(config->filename)) {
+	if (!FioCheckFileExists(config->filename, subdir)) {
 		config->status = GCS_NOT_FOUND;
 		return false;
 	}
 
 	/* Find and load the Action 8 information */
-	LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
+	LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN, subdir);
 	config->SetSuitablePalette();
 
 	/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
@@ -330,13 +332,13 @@
 
 	if (is_static) {
 		/* Perform a 'safety scan' for static GRFs */
-		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
+		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN, subdir);
 
 		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
 		if (HasBit(config->flags, GCF_UNSAFE)) return false;
 	}
 
-	return CalcGRFMD5Sum(config);
+	return CalcGRFMD5Sum(config, subdir);
 }
 
 
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -16,6 +16,7 @@
 #include "core/alloc_type.hpp"
 #include "core/smallmap_type.hpp"
 #include "misc/countedptr.hpp"
+#include "fileio_type.h"
 
 /** GRF config bit flags */
 enum GCF_Flags {
@@ -206,7 +207,7 @@
 void ClearGRFConfigList(GRFConfig **config);
 void ResetGRFConfig(bool defaults);
 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
-bool FillGRFDetails(GRFConfig *config, bool is_static);
+bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 
 /* In newgrf_gui.cpp */