summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-11 18:57:48 +0000
committerrubidium <rubidium@openttd.org>2010-08-11 18:57:48 +0000
commitd6004d17d4f7616cff4f905ada03fa7d1626aa0e (patch)
treea2c1e4382dc2455ca2f605829572657b156d40be
parente0a3a0fd54cff08f8d721dded1dc9651296de1d2 (diff)
downloadopenttd-d6004d17d4f7616cff4f905ada03fa7d1626aa0e.tar.xz
(svn r20449) -Codechange: unduplicate saving/loading of NewGRF ID + local id -> OpenTTD spec mappings
-rw-r--r--projects/openttd_vs100.vcxproj1
-rw-r--r--projects/openttd_vs100.vcxproj.filters3
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--projects/openttd_vs90.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/saveload/airport_sl.cpp33
-rw-r--r--src/saveload/industry_sl.cpp57
-rw-r--r--src/saveload/newgrf_sl.cpp33
-rw-r--r--src/saveload/newgrf_sl.h29
-rw-r--r--src/saveload/town_sl.cpp36
10 files changed, 90 insertions, 111 deletions
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj
index 53c8d4547..190823fc5 100644
--- a/projects/openttd_vs100.vcxproj
+++ b/projects/openttd_vs100.vcxproj
@@ -724,6 +724,7 @@
<ClCompile Include="..\src\saveload\map_sl.cpp" />
<ClCompile Include="..\src\saveload\misc_sl.cpp" />
<ClCompile Include="..\src\saveload\newgrf_sl.cpp" />
+ <ClInclude Include="..\src\saveload\newgrf_sl.h" />
<ClCompile Include="..\src\saveload\oldloader.cpp" />
<ClInclude Include="..\src\saveload\oldloader.h" />
<ClCompile Include="..\src\saveload\oldloader_sl.cpp" />
diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters
index 0d9c99690..da6bd7e99 100644
--- a/projects/openttd_vs100.vcxproj.filters
+++ b/projects/openttd_vs100.vcxproj.filters
@@ -1375,6 +1375,9 @@
<ClCompile Include="..\src\saveload\newgrf_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
+ <ClInclude Include="..\src\saveload\newgrf_sl.h">
+ <Filter>Save/Load handlers</Filter>
+ </ClInclude>
<ClCompile Include="..\src\saveload\oldloader.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index caad61a7c..9dff3f882 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -2184,6 +2184,10 @@
>
</File>
<File
+ RelativePath=".\..\src\saveload\newgrf_sl.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\saveload\oldloader.cpp"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 1d35bb7f9..482f9f788 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -2181,6 +2181,10 @@
>
</File>
<File
+ RelativePath=".\..\src\saveload\newgrf_sl.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\saveload\oldloader.cpp"
>
</File>
diff --git a/source.list b/source.list
index 3505807ae..592e32d5a 100644
--- a/source.list
+++ b/source.list
@@ -475,6 +475,7 @@ saveload/labelmaps_sl.cpp
saveload/map_sl.cpp
saveload/misc_sl.cpp
saveload/newgrf_sl.cpp
+saveload/newgrf_sl.h
saveload/oldloader.cpp
saveload/oldloader.h
saveload/oldloader_sl.cpp
diff --git a/src/saveload/airport_sl.cpp b/src/saveload/airport_sl.cpp
index c7f5c5769..e0637dbc0 100644
--- a/src/saveload/airport_sl.cpp
+++ b/src/saveload/airport_sl.cpp
@@ -10,45 +10,18 @@
/** @file airport_sl.cpp Code handling saving and loading airport ids */
#include "../stdafx.h"
-#include "../newgrf_commons.h"
#include "saveload.h"
-
-/**
- * Save and load the mapping between the airport id in the AirportSpec array
- * and the grf file it came from.
- */
-static const SaveLoad _airport_id_mapping_desc[] = {
- SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
- SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
- SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
- SLE_END()
-};
+#include "newgrf_sl.h"
static void Save_APID()
{
- uint i;
- uint j = _airport_mngr.GetMaxMapping();
-
- for (i = 0; i < j; i++) {
- SlSetArrayIndex(i);
- SlObject(&_airport_mngr.mapping_ID[i], _airport_id_mapping_desc);
- }
+ Save_NewGRFMapping(_airport_mngr);
}
static void Load_APID()
{
- /* clear the current mapping stored.
- * This will create the manager if ever it is not yet done */
- _airport_mngr.ResetMapping();
-
- uint max_id = _airport_mngr.GetMaxMapping();
-
- int index;
- while ((index = SlIterateArray()) != -1) {
- if ((uint)index >= max_id) break;
- SlObject(&_airport_mngr.mapping_ID[index], _airport_id_mapping_desc);
- }
+ Load_NewGRFMapping(_airport_mngr);
}
extern const ChunkHandler _airport_chunk_handlers[] = {
diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp
index c99bbc446..e3c9ff438 100644
--- a/src/saveload/industry_sl.cpp
+++ b/src/saveload/industry_sl.cpp
@@ -11,9 +11,9 @@
#include "../stdafx.h"
#include "../industry.h"
-#include "../newgrf_commons.h"
#include "saveload.h"
+#include "newgrf_sl.h"
static const SaveLoad _industry_desc[] = {
SLE_CONDVAR(Industry, location.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
@@ -71,35 +71,14 @@ static void Save_INDY()
}
}
-/* Save and load the mapping between the industry/tile id on the map, and the grf file
- * it came from. */
-static const SaveLoad _industries_id_mapping_desc[] = {
- SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
- SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
- SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
- SLE_END()
-};
-
static void Save_IIDS()
{
- uint i;
- uint j = _industry_mngr.GetMaxMapping();
-
- for (i = 0; i < j; i++) {
- SlSetArrayIndex(i);
- SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
- }
+ Save_NewGRFMapping(_industry_mngr);
}
static void Save_TIDS()
{
- uint i;
- uint j = _industile_mngr.GetMaxMapping();
-
- for (i = 0; i < j; i++) {
- SlSetArrayIndex(i);
- SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
- }
+ Save_NewGRFMapping(_industile_mngr);
}
static void Load_INDY()
@@ -117,38 +96,12 @@ static void Load_INDY()
static void Load_IIDS()
{
- int index;
- uint max_id;
-
- /* clear the current mapping stored.
- * This will create the manager if ever it is not yet done */
- _industry_mngr.ResetMapping();
-
- /* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
- max_id = _industry_mngr.GetMaxMapping();
-
- while ((index = SlIterateArray()) != -1) {
- if ((uint)index >= max_id) break;
- SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
- }
+ Load_NewGRFMapping(_industry_mngr);
}
static void Load_TIDS()
{
- int index;
- uint max_id;
-
- /* clear the current mapping stored.
- * This will create the manager if ever it is not yet done */
- _industile_mngr.ResetMapping();
-
- /* get boundary for the temporary map loader NUM_INDUSTILES? */
- max_id = _industile_mngr.GetMaxMapping();
-
- while ((index = SlIterateArray()) != -1) {
- if ((uint)index >= max_id) break;
- SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
- }
+ Load_NewGRFMapping(_industile_mngr);
}
static void Ptrs_INDY()
diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp
index c66d7739b..b4405b171 100644
--- a/src/saveload/newgrf_sl.cpp
+++ b/src/saveload/newgrf_sl.cpp
@@ -17,6 +17,39 @@
#include "../fios.h"
#include "saveload.h"
+#include "newgrf_sl.h"
+
+/** Save and load the mapping between a spec and the NewGRF it came from. */
+static const SaveLoad _newgrf_mapping_desc[] = {
+ SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
+ SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
+ SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
+ SLE_END()
+};
+
+void Save_NewGRFMapping(const OverrideManagerBase &mapping)
+{
+ for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
+ SlSetArrayIndex(i);
+ SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
+ }
+}
+
+void Load_NewGRFMapping(OverrideManagerBase &mapping)
+{
+ /* Clear the current mapping stored.
+ * This will create the manager if ever it is not yet done */
+ mapping.ResetMapping();
+
+ uint max_id = mapping.GetMaxMapping();
+
+ int index;
+ while ((index = SlIterateArray()) != -1) {
+ if ((uint)index >= max_id) break;
+ SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
+ }
+}
+
static const SaveLoad _grfconfig_desc[] = {
SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
diff --git a/src/saveload/newgrf_sl.h b/src/saveload/newgrf_sl.h
new file mode 100644
index 000000000..43c8552f7
--- /dev/null
+++ b/src/saveload/newgrf_sl.h
@@ -0,0 +1,29 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file newgrf_sl.h Code handling saving and loading of NewGRF mappings. */
+
+#ifndef SAVELOAD_NEWGRF_SL_H
+#define SAVELOAD_NEWGRF_SL_H
+
+#include "../newgrf_commons.h"
+
+/**
+ * Save a GRF ID + local id -> OpenTTD's id mapping.
+ * @param mapping The mapping to save.
+ */
+void Save_NewGRFMapping(const OverrideManagerBase &mapping);
+
+/**
+ * Load a GRF ID + local id -> OpenTTD's id mapping.
+ * @param mapping The mapping to load.
+ */
+void Load_NewGRFMapping(OverrideManagerBase &mapping);
+
+#endif /* SAVELOAD_NEWGRF_SL_H */
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index bc95ba8ab..af255ee91 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -11,10 +11,10 @@
#include "../stdafx.h"
#include "../newgrf_house.h"
-#include "../newgrf_commons.h"
#include "../town.h"
#include "saveload.h"
+#include "newgrf_sl.h"
/**
* Check and update town and house values.
@@ -139,36 +139,14 @@ static const SaveLoad _town_desc[] = {
SLE_END()
};
-/* Save and load the mapping between the house id on the map, and the grf file
- * it came from. */
-static const SaveLoad _house_id_mapping_desc[] = {
- SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
- SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
- SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
- SLE_END()
-};
-
-static void Save_HOUSEIDS()
+static void Save_HIDS()
{
- uint j = _house_mngr.GetMaxMapping();
-
- for (uint i = 0; i < j; i++) {
- SlSetArrayIndex(i);
- SlObject(&_house_mngr.mapping_ID[i], _house_id_mapping_desc);
- }
+ Save_NewGRFMapping(_house_mngr);
}
-static void Load_HOUSEIDS()
+static void Load_HIDS()
{
- int index;
-
- _house_mngr.ResetMapping();
- uint max_id = _house_mngr.GetMaxMapping();
-
- while ((index = SlIterateArray()) != -1) {
- if ((uint)index >= max_id) break;
- SlObject(&_house_mngr.mapping_ID[index], _house_id_mapping_desc);
- }
+ Load_NewGRFMapping(_house_mngr);
}
static void Save_TOWN()
@@ -192,6 +170,6 @@ static void Load_TOWN()
}
extern const ChunkHandler _town_chunk_handlers[] = {
- { 'HIDS', Save_HOUSEIDS, Load_HOUSEIDS, NULL, NULL, CH_ARRAY },
- { 'CITY', Save_TOWN, Load_TOWN, NULL, NULL, CH_ARRAY | CH_LAST},
+ { 'HIDS', Save_HIDS, Load_HIDS, NULL, NULL, CH_ARRAY },
+ { 'CITY', Save_TOWN, Load_TOWN, NULL, NULL, CH_ARRAY | CH_LAST},
};