summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-08-24 13:48:29 +0000
committerrubidium <rubidium@openttd.org>2011-08-24 13:48:29 +0000
commit8e5f433b22a36b2210c4e7386b476382afad7dd6 (patch)
tree48e4c91ab9da85aa4defd8aceab7a639b6d6bcb4 /src
parent2a12c9df2ff36a5ad7f6e5c84438ac5571f6ba8c (diff)
downloadopenttd-8e5f433b22a36b2210c4e7386b476382afad7dd6.tar.xz
(svn r22826) -Codechange: pass sub directory to NewGRF loading functions
Diffstat (limited to 'src')
-rw-r--r--src/gfxinit.cpp2
-rw-r--r--src/newgrf.cpp21
-rw-r--r--src/newgrf.h3
-rw-r--r--src/newgrf_config.cpp16
-rw-r--r--src/newgrf_config.h3
5 files changed, 31 insertions, 14 deletions
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index eeaac8d9f..652462f49 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -180,7 +180,7 @@ static void LoadSpriteTables()
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;
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index d4594356a..b19030033 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -8076,7 +8076,14 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
}
-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 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
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 @@ static void AfterLoadGRFs()
_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 @@ void LoadNewGRF(uint load_index, uint file_index)
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) {
diff --git a/src/newgrf.h b/src/newgrf.h
index b139f4846..faf489b74 100644
--- 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 @@ struct GRFLoadedFeatures {
/* 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();
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index edd64745c..6683f7b4f 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -282,9 +282,10 @@ bool UpdateNewGRFConfigPalette(int32 p1)
/**
* 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 @@ static bool CalcGRFMD5Sum(GRFConfig *config)
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 @@ static bool CalcGRFMD5Sum(GRFConfig *config)
* 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 @@ bool FillGRFDetails(GRFConfig *config, bool is_static)
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);
}
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 9061f5044..253b267a5 100644
--- 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 AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
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 */