Changeset - r8655:74c23e2271a3
[Not reviewed]
master
0 1 0
peter1138 - 16 years ago 2008-02-29 08:40:49
peter1138@openttd.org
(svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
includes 0xD000 to 0xD3FF (yes, 0xD0xx makes a lot of sense, really...)
and handle 0xD400 to 0xD7FF strings which map to 0xD000 to 0xD3FF
(obviously).
1 file changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -199,103 +199,114 @@ static const char *grf_load_string(byte 
 
		/* Increase the string length to include the NUL byte. */
 
		string_length++;
 
	}
 
	*buf += string_length;
 

	
 
	return string;
 
}
 

	
 
static GRFFile *GetFileByGRFID(uint32 grfid)
 
{
 
	GRFFile *file;
 

	
 
	for (file = _first_grffile; file != NULL; file = file->next) {
 
		if (file->grfid == grfid) break;
 
	}
 
	return file;
 
}
 

	
 
static GRFFile *GetFileByFilename(const char *filename)
 
{
 
	GRFFile *file;
 

	
 
	for (file = _first_grffile; file != NULL; file = file->next) {
 
		if (strcmp(file->filename, filename) == 0) break;
 
	}
 
	return file;
 
}
 

	
 

	
 
/** 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
 
 * @param str StringID that we want to have the equivalent in OoenTTD
 
 * @return the properly adjusted StringID
 
 */
 
StringID MapGRFStringID(uint32 grfid, StringID str)
 
{
 
	/* StringID table for TextIDs 0x4E->0x6D */
 
	static StringID units_volume[] = {
 
		STR_NOTHING,    STR_PASSENGERS, STR_TONS,       STR_BAGS,
 
		STR_LITERS,     STR_ITEMS,      STR_CRATES,     STR_TONS,
 
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
 
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
 
		STR_TONS,       STR_TONS,       STR_BAGS,       STR_LITERS,
 
		STR_TONS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
 
		STR_BAGS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
 
		STR_TONS,       STR_NOTHING,    STR_LITERS,     STR_NOTHING
 
	};
 

	
 
	/* 0xD0 and 0xDC stand for all the TextIDs in the range
 
	 * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
 
	 * These strings are unique to each grf file, and thus require to be used with the
 
	 * grfid in which they are declared */
 
	if (GB(str, 8, 8) == 0xD0 || GB(str, 8, 8) == 0xDC) {
 
		return GetGRFStringID(grfid, str);
 
	switch (GB(str, 8, 8)) {
 
		case 0xD0: case 0xD1: case 0xD2: case 0xD3:
 
		case 0xDC:
 
			return GetGRFStringID(grfid, str);
 

	
 
		case 0xD4: case 0xD5: case 0xD6: case 0xD7:
 
			/* Strings embedded via 0x81 have 0x400 added to them (no real
 
			 * explanation why...) */
 
			return GetGRFStringID(grfid, str - 0x400);
 

	
 
		default: break;
 
	}
 

	
 
#define TEXID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
 
	/* We have some changes in our cargo strings, resulting in some missing. */
 
	TEXID_TO_STRINGID(0x000E, 0x002D, STR_000E);
 
	TEXID_TO_STRINGID(0x002E, 0x004D, STR_002E);
 
	if (str >= 0x004E && str <= 0x006D) str = units_volume[str - 0x004E];
 
	TEXID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
 
	TEXID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING);
 

	
 
	/* Map building names according to our lang file changes. There are several
 
	 * ranges of house ids, all of which need to be remapped to allow newgrfs
 
	 * to use original house names. */
 
	TEXID_TO_STRINGID(0x200F, 0x201F, STR_200F_TALL_OFFICE_BLOCK);
 
	TEXID_TO_STRINGID(0x2036, 0x2041, STR_2036_COTTAGES);
 
	TEXID_TO_STRINGID(0x2059, 0x205C, STR_2059_IGLOO);
 

	
 
	/* Same thing for industries, since the introduction of 4 new strings above STR_482A_PRODUCTION_LAST_MONTH */
 
	TEXID_TO_STRINGID(0x482A, 0x483B, STR_482A_PRODUCTION_LAST_MONTH);
 
#undef TEXTID_TO_STRINGID
 

	
 
	if (str == STR_NULL) return STR_EMPTY;
 

	
 
	return str;
 
}
 

	
 
static uint8 MapDOSColour(uint8 colour)
 
{
 
	if (_use_dos_palette) return colour;
 

	
 
	if (colour < 10) {
 
		static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 };
 
		return dos_to_win_colour_map[colour];
 
	}
 

	
 
	if (colour >= 245 && colour < 254) return colour - 28;
 

	
 
	return colour;
 
}
 

	
 
/** Map the colour modifiers of TTDPatch to those that Open is using.
 
 * @param grf_sprite pointer to the structure been modified
 
 */
 
static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
 
{
 
	if (HasBit(grf_sprite->pal, 14)) {
 
		ClrBit(grf_sprite->pal, 14);
 
		SetBit(grf_sprite->sprite, SPRITE_MODIFIER_OPAQUE);
 
	}
 

	
 
@@ -3197,96 +3208,99 @@ static void FeatureNewName(byte *buf, in
 
		switch (feature) {
 
			case GSF_TRAIN:
 
			case GSF_ROAD:
 
			case GSF_SHIP:
 
			case GSF_AIRCRAFT:
 
				if (id < TOTAL_NUM_ENGINES) {
 
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
 
					EngineInfo *ei = &_engine_info[id];
 
					ei->string_id = string;
 
				} else {
 
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
 
				}
 
				break;
 

	
 
			case GSF_INDUSTRIES: {
 
				AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
				break;
 
			}
 

	
 
			case GSF_TOWNHOUSE:
 
			default:
 
				switch (GB(id, 8, 8)) {
 
					case 0xC4: // Station class name
 
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
 
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
 
						}
 
						break;
 

	
 
					case 0xC5: // Station name
 
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
						}
 
						break;
 

	
 
					case 0xC9: // House name
 
						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);
 
						}
 
						break;
 

	
 
					case 0xD0:
 
					case 0xD1:
 
					case 0xD2:
 
					case 0xD3:
 
					case 0xDC:
 
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
						break;
 

	
 
					default:
 
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
 
						break;
 
				}
 
				break;
 

	
 
#if 0
 
				case GSF_CANAL :
 
				case GSF_BRIDGE :
 
					AddGRFString(_cur_spriteid, id, lang, name);
 
					switch (GB(id, 8, 8)) {
 
						case 0xC9: // House name
 
						default:
 
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
 
					}
 
					break;
 

	
 
				default :
 
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
 
					break;
 
#endif
 
		}
 
	}
 
}
 

	
 
/**
 
 * Sanitize incoming sprite offsets for Action 5 graphics replacements.
 
 * @param num         the number of sprites to load.
 
 * @param offset      offset from the base.
 
 * @param max_sprites the maximum number of sprites that can be loaded in this action 5.
 
 * @param name        used for error warnings.
 
 * @return the number of sprites that is going to be skipped
 
 */
 
static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name)
 
{
 

	
 
	if (offset >= max_sprites) {
 
		grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
 
		uint orig_num = num;
 
		num = 0;
 
		return orig_num;
 
	}
 

	
 
	if (offset + num > max_sprites) {
0 comments (0 inline, 0 general)