summaryrefslogtreecommitdiff
path: root/src/newgrf.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-24 23:20:21 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-24 23:20:21 +0000
commit29c81427842d282127c0e12789a156a1f833dcae (patch)
tree953522568a4df36b0eb313ad9f8f22918ab8e79c /src/newgrf.cpp
parent5aaff3b5a1bb6dc7a4bc23e25f8d74086437435b (diff)
downloadopenttd-29c81427842d282127c0e12789a156a1f833dcae.tar.xz
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
Diffstat (limited to 'src/newgrf.cpp')
-rw-r--r--src/newgrf.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 41fa5f0bb..1263ea151 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3707,6 +3707,29 @@ static void ClearTemporaryNewGRFData(void)
_cur_grffile->spritegroups_count = 0;
}
+static void BuildCargoTranslationMap()
+{
+ memset(_cur_grffile->cargo_map, 0xFF, sizeof(_cur_grffile->cargo_map));
+
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ const CargoSpec *cs = GetCargo(c);
+ if (!cs->IsValid()) continue;
+
+ if (_cur_grffile->cargo_max == 0) {
+ /* Default translation table, so just a straight mapping to bitnum */
+ _cur_grffile->cargo_map[c] = cs->bitnum;
+ } else {
+ /* Check the translation table for this cargo's label */
+ for (uint i = 0; i < _cur_grffile->cargo_max; i++) {
+ if (cs->label == _cur_grffile->cargo_list[i]) {
+ _cur_grffile->cargo_map[c] = i;
+ break;
+ }
+ }
+ }
+ }
+}
+
static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
{
GRFFile *newfile;
@@ -4032,6 +4055,7 @@ void LoadNewGRF(uint load_index, uint file_index)
LoadNewGRFFile(c, slot++, stage);
if (stage == GLS_ACTIVATION) {
ClearTemporaryNewGRFData();
+ BuildCargoTranslationMap();
DEBUG(sprite, 2, "Currently %i sprites are loaded", _cur_spriteid);
}
}