src/newgrf.cpp
branchNewGRF_ports
changeset 6870 ca3fd1fbe311
parent 6868 7eb395287b3d
child 6871 5a9dc001e1ad
--- a/src/newgrf.cpp	Thu Sep 06 19:42:48 2007 +0000
+++ b/src/newgrf.cpp	Sat Oct 06 21:16:00 2007 +0000
@@ -247,7 +247,7 @@
  * @param str StringID that we want to have the equivalent in OoenTTD
  * @return the properly adjusted StringID
  */
-static StringID MapGRFStringID(uint32 grfid, StringID str)
+StringID MapGRFStringID(uint32 grfid, StringID str)
 {
 	/* 0xD0 and 0xDC stand for all the TextIDs in the range
 	 * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
@@ -256,17 +256,26 @@
 	if (GB(str, 8, 8) == 0xD0 || GB(str, 8, 8) == 0xDC) {
 		return GetGRFStringID(grfid, str);
 	}
-
+#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. */
-	if (str >= 0x006E && str <= 0x008D) return str - 0x20;
-	if (str >= 0x008E && str <= 0x00AD) return str - 0x20;
+	TEXID_TO_STRINGID(0x000E, 0x002D, STR_000E);
+	TEXID_TO_STRINGID(0x002E, 0x004D, STR_002E);
+	TEXID_TO_STRINGID(0x004E, 0x006D, STR_QUANTITY_NOTHING);
+	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
 	 * 0x200F = Tall Office Block, first house name in the original data, the one that TTDPatch stil uses
 	 * 0x201F = Old houses is the last house name.
 	 * OpenTTD does not have exactly the same order aymore, so, the code below allows
 	 * to compensate for the difference */
-	if (str >= 0x200F && str <= 0x201F) return str + (STR_200F_TALL_OFFICE_BLOCK - 0x200F);
+	TEXID_TO_STRINGID(0x200F, 0x201F, STR_200F_TALL_OFFICE_BLOCK);
+
+	/* 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;
 }
@@ -1205,9 +1214,6 @@
 	/* Allocate house specs if they haven't been allocated already. */
 	if (_cur_grffile->housespec == NULL) {
 		_cur_grffile->housespec = CallocT<HouseSpec*>(HOUSE_MAX);
-
-		/* Reset any overrides that have been set. */
-		_house_mngr.ResetOverride();
 	}
 
 	for (int i = 0; i < numinfo; i++) {
@@ -1701,8 +1707,6 @@
 
 static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **bufp, int len)
 {
-	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return true;
-
 	byte *buf = *bufp;
 	bool ret = false;
 
@@ -1714,9 +1718,6 @@
 	/* Allocate industry tile specs if they haven't been allocated already. */
 	if (_cur_grffile->indtspec == NULL) {
 		_cur_grffile->indtspec = CallocT<IndustryTileSpec*>(NUM_INDUSTRYTILES);
-
-		/* Reset any overrides that have been set. */
-		_industile_mngr.ResetOverride();
 	}
 
 	for (int i = 0; i < numinfo; i++) {
@@ -1771,7 +1772,7 @@
 			case 0x0C: {
 				uint16 acctp = grf_load_word(&buf);
 				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
-				tsp->acceptance[prop - 0x0A] = GetCargoTranslation(GB(acctp, 8, 8), _cur_grffile);
+				tsp->acceptance[prop - 0x0A] = GB(acctp, 8, 8);
 			} break;
 
 			case 0x0D: // Land shape flags
@@ -1810,8 +1811,6 @@
 
 static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
 {
-	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return true;
-
 	byte *buf = *bufp;
 	bool ret = false;
 
@@ -1825,9 +1824,6 @@
 	/* Allocate industry specs if they haven't been allocated already. */
 	if (_cur_grffile->industryspec == NULL) {
 		_cur_grffile->industryspec = CallocT<IndustrySpec*>(NUM_INDUSTRYTYPES);
-
-		/* Reset any overrides that have been set. */
-		_industry_mngr.ResetOverride();
 	}
 
 	for (int i = 0; i < numinfo; i++) {
@@ -1937,6 +1933,9 @@
 								size = k + 1;
 								copy_from = itt;
 							}
+						} else if (itt[k].gfx == 0xFF) {
+							itt[k].ti.x = (int8)GB(itt[k].ti.x, 0, 8);
+							itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
 						}
 					}
 					tile_table[j] = CallocT<IndustryTileTable>(size);
@@ -2004,11 +2003,11 @@
 				break;
 
 			case 0x17: // Probability in random game
-				indsp->appear_ingame[_opt.landscape] = grf_load_byte(&buf);
+				indsp->appear_creation[_opt.landscape] = grf_load_byte(&buf);
 				break;
 
 			case 0x18: // Probability during gameplay
-				indsp->appear_creation[_opt.landscape] = grf_load_byte(&buf);
+				indsp->appear_ingame[_opt.landscape] = grf_load_byte(&buf);
 				break;
 
 			case 0x19: // Map color
@@ -3279,8 +3278,6 @@
 
 static void IndustryMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
 {
-	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return;
-
 	byte *bp = &buf[4 + idcount + cidcount * 3];
 	uint16 groupid = grf_load_word(&bp);
 
@@ -3305,8 +3302,6 @@
 
 static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
 {
-	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return;
-
 	byte *bp = &buf[4 + idcount + cidcount * 3];
 	uint16 groupid = grf_load_word(&bp);
 
@@ -3439,8 +3434,8 @@
 	grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d",
 			feature, idcount, cidcount, wagover);
 
-	if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) {
-		grfmsg(1, "FeatureMapSpriteGroup: No sprite set to work on! Skipping");
+	if (_cur_grffile->spritegroups == 0) {
+		grfmsg(1, "FeatureMapSpriteGroup: No sprite groups to work on! Skipping");
 		return;
 	}
 
@@ -3806,8 +3801,8 @@
 		case 0x8B: { // TTDPatch version
 			uint major    = 2;
 			uint minor    = 6;
-			uint revision = 0; // special case: 2.0.1 is 2.0.10
-			uint build    = 1210;
+			uint revision = 1; // special case: 2.0.1 is 2.0.10
+			uint build    = 1382;
 			return (major << 24) | (minor << 20) | (revision << 16) | build;
 		}
 
@@ -4928,9 +4923,9 @@
 				break;
 
 			case 'atad': // 'data'
-				se->file_size    = size;
-				se->file_offset  = FioGetPos() - (len - (buf - buf_start)) + 1;
-				se->file_offset |= _file_index << 24;
+				se->file_size   = size;
+				se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
+				se->file_slot   = _file_index;
 
 				/* Set default volume and priority */
 				se->volume = 0x80;
@@ -5143,7 +5138,7 @@
 	                   |                                        (0 << 0x04)  // aichoosechance
 	                   |                                        (1 << 0x05)  // resolutionwidth
 	                   |                                        (1 << 0x06)  // resolutionheight
-	                   |                                        (0 << 0x07)  // newindustries
+	                   |                                        (1 << 0x07)  // newindustries
 	                   |         ((_patches.improved_load ? 1 : 0) << 0x08)  // fifoloading
 	                   |                                        (0 << 0x09)  // townroadbranchprob
 	                   |                                        (0 << 0x0A)  // tempsnowline
@@ -5387,7 +5382,7 @@
 
 	_loaded_newgrf_features.has_2CC           = false;
 	_loaded_newgrf_features.has_newhouses     = false;
-	_loaded_newgrf_features.has_newindustries = false,
+	_loaded_newgrf_features.has_newindustries = false;
 
 	_signal_base = 0;
 	_coast_base = 0;
@@ -5912,7 +5907,7 @@
 	/* Load newgrf sprites
 	 * in each loading stage, (try to) open each file specified in the config
 	 * and load information from it. */
-	for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
+	for (GrfLoadingStage stage = GLS_LABELSCAN; stage < GLS_ACTIVATION; stage++) {
 		uint slot = file_index;
 
 		_cur_stage = stage;
@@ -5925,13 +5920,17 @@
 			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
 
 			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
-			LoadNewGRFFile(c, slot++, stage);
+			LoadNewGRFFile(c, slot, stage);
 			if (stage == GLS_RESERVE) {
 				if (c->status == GCS_ACTIVATED) c->status = GCS_INITIALISED;
-			} else if (stage == GLS_ACTIVATION) {
+				_cur_stage = GLS_ACTIVATION;
+				LoadNewGRFFile(c, slot++, GLS_ACTIVATION);
+				_cur_stage = stage;
 				ClearTemporaryNewGRFData();
 				BuildCargoTranslationMap();
 				DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
+			} else {
+				slot++;
 			}
 		}
 	}