summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-17 11:47:22 +0000
committerrubidium <rubidium@openttd.org>2008-04-17 11:47:22 +0000
commit00f0bf98ee3612899bcd6e71c34694cc8f69838c (patch)
tree5acb4a3c8eefc56274a8869d71f45aa60fe942f5 /src
parent5796fb3b349d6f8f311d79b397faa0caf1865f98 (diff)
downloadopenttd-00f0bf98ee3612899bcd6e71c34694cc8f69838c.tar.xz
(svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
Diffstat (limited to 'src')
-rw-r--r--src/cargotype.h12
-rw-r--r--src/industry.h13
-rw-r--r--src/newgrf.cpp69
-rw-r--r--src/newgrf_string_type.h54
-rw-r--r--src/table/build_industry.h2
-rw-r--r--src/table/cargo_const.h2
-rw-r--r--src/table/town_land.h2
-rw-r--r--src/town.h4
8 files changed, 52 insertions, 106 deletions
diff --git a/src/cargotype.h b/src/cargotype.h
index 7d770b1b9..51bd2fd64 100644
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -7,7 +7,7 @@
#include "cargo_type.h"
#include "gfx_type.h"
-#include "newgrf_string_type.h"
+#include "strings_type.h"
typedef uint32 CargoLabel;
@@ -36,11 +36,11 @@ struct CargoSpec {
uint16 multipliertowngrowth;
uint8 callback_mask;
- GRFMappedStringID name;
- GRFMappedStringID name_single;
- GRFMappedStringID units_volume;
- GRFMappedStringID quantifier;
- GRFMappedStringID abbrev;
+ StringID name;
+ StringID name_single;
+ StringID units_volume;
+ StringID quantifier;
+ StringID abbrev;
SpriteID sprite;
diff --git a/src/industry.h b/src/industry.h
index c2fed658c..497cb5744 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -15,7 +15,6 @@
#include "date_type.h"
#include "town_type.h"
#include "industry_type.h"
-#include "newgrf_string_type.h"
enum {
INVALID_INDUSTRY = 0xFFFF,
@@ -174,12 +173,12 @@ struct IndustrySpec {
byte climate_availability; ///< Bitmask, giving landscape enums as bit position
IndustryBehaviour behaviour; ///< How this industry will behave, and how others entities can use it
byte map_colour; ///< colour used for the small map
- GRFMappedStringID name; ///< Displayed name of the industry
- GRFMappedStringID new_industry_text; ///< Message appearing when the industry is built
- GRFMappedStringID closure_text; ///< Message appearing when the industry closes
- GRFMappedStringID production_up_text; ///< Message appearing when the industry's production is increasing
- GRFMappedStringID production_down_text; ///< Message appearing when the industry's production is decreasing
- GRFMappedStringID station_name; ///< Default name for nearby station
+ StringID name; ///< Displayed name of the industry
+ StringID new_industry_text; ///< Message appearing when the industry is built
+ StringID closure_text; ///< Message appearing when the industry closes
+ StringID production_up_text; ///< Message appearing when the industry's production is increasing
+ StringID production_down_text; ///< Message appearing when the industry's production is decreasing
+ StringID station_name; ///< Default name for nearby station
byte appear_ingame[NUM_LANDSCAPE]; ///< Probability of appearance in game
byte appear_creation[NUM_LANDSCAPE]; ///< Probability of appearance during map creation
uint8 number_of_sounds; ///< Number of sounds available in the sounds array
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 9b93f714d..4614645d0 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -46,6 +46,8 @@
#include "settings_type.h"
#include "map_func.h"
+#include <map>
+
#include "table/strings.h"
#include "table/sprites.h"
#include "table/town_land.h"
@@ -225,6 +227,9 @@ static GRFFile *GetFileByFilename(const char *filename)
}
+typedef std::map<StringID *, uint32> StringIDToGRFIDMapping;
+StringIDToGRFIDMapping _string_to_grf_mapping;
+
/** Used when setting an object's property to map to the GRF's strings
* while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
* @param grfid Id of the grf file
@@ -1387,7 +1392,8 @@ static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, in
break;
case 0x12: // Building name ID
- housespec->building_name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ housespec->building_name = grf_load_word(&buf);
+ _string_to_grf_mapping[&housespec->building_name] = _cur_grffile->grfid;
break;
case 0x13: // Building availability mask
@@ -1630,25 +1636,30 @@ static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int le
break;
case 0x09: /* String ID for cargo type name */
- cs->name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->name = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->name] = _cur_grffile->grfid;
break;
case 0x0A: /* String for 1 unit of cargo */
- cs->name_single = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->name_single = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->name_single] = _cur_grffile->grfid;
break;
case 0x0B:
/* String for units of cargo. This is different in OpenTTD to TTDPatch
* (e.g. 10 tonnes of coal) */
- cs->units_volume = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->units_volume = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->units_volume] = _cur_grffile->grfid;
break;
case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
- cs->quantifier = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->quantifier = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->quantifier] = _cur_grffile->grfid;
break;
case 0x0D: /* String for two letter cargo abbreviation */
- cs->abbrev = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->abbrev = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->abbrev] = _cur_grffile->grfid;
break;
case 0x0E: /* Sprite ID for cargo icon */
@@ -2032,15 +2043,18 @@ static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp,
break;
case 0x0C: // Industry closure message
- indsp->closure_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->closure_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->closure_text] = _cur_grffile->grfid;
break;
case 0x0D: // Production increase message
- indsp->production_up_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->production_up_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->production_up_text] = _cur_grffile->grfid;
break;
case 0x0E: // Production decrease message
- indsp->production_down_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->production_down_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->production_down_text] = _cur_grffile->grfid;
break;
case 0x0F: // Fund cost multiplier
@@ -2099,7 +2113,8 @@ static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp,
break;
case 0x1B: // New industry text ID
- indsp->new_industry_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->new_industry_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->new_industry_text] = _cur_grffile->grfid;
break;
case 0x1C: // Input cargo multipliers for the three input cargo types
@@ -2111,7 +2126,8 @@ static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp,
} break;
case 0x1F: // Industry name
- indsp->name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->name = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->name] = _cur_grffile->grfid;
break;
case 0x20: // Prospecting success chance
@@ -2129,7 +2145,8 @@ static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp,
break;
case 0x24: // name for nearby station
- indsp->station_name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->station_name = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->station_name] = _cur_grffile->grfid;
break;
default:
@@ -3254,7 +3271,7 @@ static void FeatureNewName(byte *buf, int len)
if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
} else {
- _cur_grffile->housespec[GB(id, 0, 8)]->building_name = GRFMappedStringID(AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED), 0);
+ _cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
}
break;
@@ -5487,7 +5504,6 @@ static void FinaliseHouseArray()
for (int i = 0; i < HOUSE_MAX; i++) {
HouseSpec *hs = file->housespec[i];
if (hs != NULL) {
- hs->building_name.MapString();
_house_mngr.SetEntitySpec(hs);
if (hs->min_date < min_date) min_date = hs->min_date;
}
@@ -5518,27 +5534,21 @@ static void FinaliseIndustriesArray()
/* process the conversion of text at the end, so to be sure everything will be fine
* and available. Check if it does not return undefind marker, which is a very good sign of a
* substitute industry who has not changed the string been examined, thus using it as such */
- indsp->name.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
if (strid != STR_UNDEFINED) indsp->name = strid;
- indsp->closure_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
if (strid != STR_UNDEFINED) indsp->closure_text = strid;
- indsp->production_up_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
- indsp->production_down_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
- indsp->new_industry_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
- indsp->station_name.MapString();
if (indsp->station_name != STR_NULL) {
/* STR_NULL (0) can be set by grf. It has a meaning regarding assignation of the
* station's name. Don't wont to loose the value, therefor, do not process. */
@@ -5581,12 +5591,6 @@ static void MapNewCargoStrings()
CargoSpec *cs = &_cargo[c];
/* Don't map if the cargo is unavailable or not from NewGRF */
if (cs->grfid == 0) continue;
-
- cs->name.MapString();
- cs->name_single.MapString();
- cs->units_volume.MapString();
- cs->quantifier.MapString();
- cs->abbrev.MapString();
}
}
@@ -5811,6 +5815,11 @@ extern void InitGRFTownGeneratorNames();
static void AfterLoadGRFs()
{
+ for (StringIDToGRFIDMapping::iterator it = _string_to_grf_mapping.begin(); it != _string_to_grf_mapping.end(); it++) {
+ *((*it).first) = MapGRFStringID((*it).second, *((*it).first));
+ }
+ _string_to_grf_mapping.clear();
+
/* Update the bitmasks for the vehicle lists */
Player *p;
FOR_ALL_PLAYERS(p) {
@@ -5903,11 +5912,3 @@ bool HasGrfMiscBit(GrfMiscBit bit)
{
return HasBit(_misc_grf_features, bit);
}
-
-void GRFMappedStringID::MapString()
-{
- if (this->grfid == 0) return;
-
- this->string = MapGRFStringID(this->grfid, this->string);
- this->grfid = 0;
-}
diff --git a/src/newgrf_string_type.h b/src/newgrf_string_type.h
deleted file mode 100644
index 4a0bdd790..000000000
--- a/src/newgrf_string_type.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* $Id$ */
-
-/** @file newgrf_string_type.h */
-
-#ifndef NEWGRF_STRING_TYPE_H
-#define NEWGRF_STRING_TYPE_H
-
-#include "strings_type.h"
-
-/**
- * A string with the required information to perform a GRF string remapping.
- */
-struct GRFMappedStringID
-{
-private:
- /** The GRF ID associated to the to-be-remapped string */
- uint32 grfid;
- /** The string; when grfid != 0 it should be remapped */
- StringID string;
-
-public:
- /**
- * Create the struct.
- * @param str the string to store (or remap)
- * @param grf_id the GRF to remap it with
- */
- GRFMappedStringID(StringID str, uint32 grf_id) : grfid(grf_id), string(str) {}
-
- /**
- * An empty string.
- */
- GRFMappedStringID() {}
-
- /** Cast operator, returns the string */
- inline operator StringID() const
- {
- return string;
- }
-
- /** Assigns the string and resets the GRF ID. */
- GRFMappedStringID& operator = (StringID str)
- {
- string = str;
- grfid = 0;
- return *this;
- }
-
- /**
- * Map the string.
- */
- void MapString();
-};
-
-#endif /* NEWGRF_STRING_TYPE_H */
diff --git a/src/table/build_industry.h b/src/table/build_industry.h
index 58b2b78c9..64b01899f 100644
--- a/src/table/build_industry.h
+++ b/src/table/build_industry.h
@@ -1176,7 +1176,7 @@ enum {
#define MI(tbl, sndc, snd, d, pc, ai1, ai2, ai3, ai4, ag1, ag2, ag3, ag4, col, \
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
{tbl, lengthof(tbl), min(255, d), 0, d, pc, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m, \
- {a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, GRFMappedStringID(in, 0), GRFMappedStringID(intx, 0), GRFMappedStringID(s1, 0), GRFMappedStringID(s2, 0), GRFMappedStringID(s3, 0), GRFMappedStringID(STR_UNDEFINED, 0), {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
+ {a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
sndc, snd, 0, 0, true, {INVALID_INDUSTRYTYPE, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
/* Format:
tile table count and sounds table
diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h
index f87e0090c..6c24716f5 100644
--- a/src/table/cargo_const.h
+++ b/src/table/cargo_const.h
@@ -3,7 +3,7 @@
/* Table of all default cargo types */
#define MK(bt, label, c, e, f, g, h, fr, te, ks1, ks2, ks3, ks4, ks5, l, m) \
- {bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, GRFMappedStringID(ks1, 0), GRFMappedStringID(ks2, 0), GRFMappedStringID(ks3, 0), GRFMappedStringID(ks4, 0), GRFMappedStringID(ks5, 0), l, m, NULL}
+ {bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL}
static const CargoSpec _default_cargo[] = {
MK( 0, 'PASS', 152, 1, 3185, 0, 24, false, TE_PASSENGERS,
STR_000F_PASSENGERS, STR_002F_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS,
diff --git a/src/table/town_land.h b/src/table/town_land.h
index ea46f1157..89d7d30a1 100644
--- a/src/table/town_land.h
+++ b/src/table/town_land.h
@@ -1803,7 +1803,7 @@ assert_compile(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
* @see HouseSpec
*/
#define MS(mnd, mxd, p, rc, bn, rr, mg, ca1, ca2, ca3, bf, ba, cg1, cg2, cg3) \
- {mnd, mxd, p, rc, GRFMappedStringID(bn, 0), rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
+ {mnd, mxd, p, rc, bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
0, NULL, 0, 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, 0, 2, 0, 0, 0, NULL}
/** House specifications from original data */
static const HouseSpec _original_house_specs[] = {
diff --git a/src/town.h b/src/town.h
index e85307edd..068567842 100644
--- a/src/town.h
+++ b/src/town.h
@@ -13,8 +13,8 @@
#include "date_type.h"
#include "town_type.h"
#include "player_type.h"
-#include "newgrf_string_type.h"
#include "settings_type.h"
+#include "strings_type.h"
enum {
HOUSE_NO_CLASS = 0,
@@ -201,7 +201,7 @@ struct HouseSpec {
Year max_date; ///< last year it can be built
byte population; ///< population (Zero on other tiles in multi tile house.)
byte removal_cost; ///< cost multiplier for removing it
- GRFMappedStringID building_name; ///< building name
+ StringID building_name; ///< building name
uint16 remove_rating_decrease; ///< rating decrease if removed
byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
byte cargo_acceptance[3]; ///< acceptance level for the cargo slots