src/newgrf.cpp
changeset 8403 44f101c68312
parent 8393 a0ab817a8b73
child 8431 3efd3b25763d
equal deleted inserted replaced
8402:bd167712432a 8403:44f101c68312
  3301 	}
  3301 	}
  3302 
  3302 
  3303 	return 0;
  3303 	return 0;
  3304 }
  3304 }
  3305 
  3305 
  3306 /** Allows to reposition the loaded sprite to its correct placment.
       
  3307  * @param load_index SpriteID of the sprite to be relocated */
       
  3308 static inline void TranslateShoreSprites(SpriteID load_index)
       
  3309 {
       
  3310 	/** Contains the displacement required for the corresponding initial sprite*/
       
  3311 	static const SpriteID shore_dup[8] = {
       
  3312 		SPR_SHORE_BASE +  4,  ///< 4062
       
  3313 		SPR_SHORE_BASE +  1,  ///< 4063
       
  3314 		SPR_SHORE_BASE +  2,  ///< 4064
       
  3315 		SPR_SHORE_BASE +  8,  ///< 4065
       
  3316 		SPR_SHORE_BASE +  6,  ///< 4066
       
  3317 		SPR_SHORE_BASE + 12,  ///< 4067
       
  3318 		SPR_SHORE_BASE +  3,  ///< 4068
       
  3319 		SPR_SHORE_BASE +  9,  ///< 4069
       
  3320 	};
       
  3321 
       
  3322 	DupSprite(load_index, shore_dup[load_index - SPR_ORIGINALSHORE_START]);
       
  3323 }
       
  3324 
       
  3325 /* Action 0x05 */
  3306 /* Action 0x05 */
  3326 static void GraphicsNew(byte *buf, int len)
  3307 static void GraphicsNew(byte *buf, int len)
  3327 {
  3308 {
  3328 	/* <05> <graphics-type> <num-sprites> <other data...>
  3309 	/* <05> <graphics-type> <num-sprites> <other data...>
  3329 	 *
  3310 	 *
  3381 	if ((type == 0x0D) && (num == 10) && _cur_grffile->is_ottdfile) {
  3362 	if ((type == 0x0D) && (num == 10) && _cur_grffile->is_ottdfile) {
  3382 		/* Special not-TTDP-compatible case used in openttd(d/w).grf
  3363 		/* Special not-TTDP-compatible case used in openttd(d/w).grf
  3383 		 * Missing shore sprites and initialisation of SPR_SHORE_BASE */
  3364 		 * Missing shore sprites and initialisation of SPR_SHORE_BASE */
  3384 		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf.");
  3365 		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf.");
  3385 		LoadNextSprite(       SPR_SHORE_BASE          +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
  3366 		LoadNextSprite(       SPR_SHORE_BASE          +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
  3386 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  1);                           // SLOPE_W
       
  3387 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  2);                           // SLOPE_S
       
  3388 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  6);                           // SLOPE_SW
       
  3389 		TranslateShoreSprites(SPR_ORIGINALSHORE_START     );                           // SLOPE_E
       
  3390 		LoadNextSprite(       SPR_SHORE_BASE          +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
  3367 		LoadNextSprite(       SPR_SHORE_BASE          +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
  3391 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  4);                           // SLOPE_SE
       
  3392 		LoadNextSprite(       SPR_SHORE_BASE          +  7, _file_index, _nfo_line++); // SLOPE_WSE
  3368 		LoadNextSprite(       SPR_SHORE_BASE          +  7, _file_index, _nfo_line++); // SLOPE_WSE
  3393 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  3);                           // SLOPE_N
       
  3394 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  7);                           // SLOPE_NW
       
  3395 		LoadNextSprite(       SPR_SHORE_BASE          + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
  3369 		LoadNextSprite(       SPR_SHORE_BASE          + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
  3396 		LoadNextSprite(       SPR_SHORE_BASE          + 11, _file_index, _nfo_line++); // SLOPE_NWS
  3370 		LoadNextSprite(       SPR_SHORE_BASE          + 11, _file_index, _nfo_line++); // SLOPE_NWS
  3397 		TranslateShoreSprites(SPR_ORIGINALSHORE_START +  5);                           // SLOPE_NE
       
  3398 		LoadNextSprite(       SPR_SHORE_BASE          + 13, _file_index, _nfo_line++); // SLOPE_ENW
  3371 		LoadNextSprite(       SPR_SHORE_BASE          + 13, _file_index, _nfo_line++); // SLOPE_ENW
  3399 		LoadNextSprite(       SPR_SHORE_BASE          + 14, _file_index, _nfo_line++); // SLOPE_SEN
  3372 		LoadNextSprite(       SPR_SHORE_BASE          + 14, _file_index, _nfo_line++); // SLOPE_SEN
  3400 		LoadNextSprite(       SPR_SHORE_BASE          + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
  3373 		LoadNextSprite(       SPR_SHORE_BASE          + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
  3401 		LoadNextSprite(       SPR_SHORE_BASE          + 16, _file_index, _nfo_line++); // SLOPE_EW
  3374 		LoadNextSprite(       SPR_SHORE_BASE          + 16, _file_index, _nfo_line++); // SLOPE_EW
  3402 		LoadNextSprite(       SPR_SHORE_BASE          + 17, _file_index, _nfo_line++); // SLOPE_NS
  3375 		LoadNextSprite(       SPR_SHORE_BASE          + 17, _file_index, _nfo_line++); // SLOPE_NS
       
  3376 		if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ONLY_NEW;
  3403 		return;
  3377 		return;
  3404 	}
  3378 	}
  3405 
  3379 
  3406 	/* Supported type? */
  3380 	/* Supported type? */
  3407 	if ((type >= lengthof(action5_types)) || (action5_types[type].block_type == A5BLOCK_INVALID)) {
  3381 	if ((type >= lengthof(action5_types)) || (action5_types[type].block_type == A5BLOCK_INVALID)) {
  3435 
  3409 
  3436 	for (; num > 0; num--) {
  3410 	for (; num > 0; num--) {
  3437 		_nfo_line++;
  3411 		_nfo_line++;
  3438 		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
  3412 		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
  3439 	}
  3413 	}
       
  3414 
       
  3415 	if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5;
  3440 
  3416 
  3441 	_skip_sprites = skip_num;
  3417 	_skip_sprites = skip_num;
  3442 }
  3418 }
  3443 
  3419 
  3444 /* Action 0x05 (SKIP) */
  3420 /* Action 0x05 (SKIP) */
  3850 		for (uint j = 0; j < num_sprites; j++) {
  3826 		for (uint j = 0; j < num_sprites; j++) {
  3851 			int load_index = first_sprite + j;
  3827 			int load_index = first_sprite + j;
  3852 			_nfo_line++;
  3828 			_nfo_line++;
  3853 			LoadNextSprite(load_index, _file_index, _nfo_line); // XXX
  3829 			LoadNextSprite(load_index, _file_index, _nfo_line); // XXX
  3854 
  3830 
  3855 			/*  Shore sprites now located at different addresses.
  3831 			/* Shore sprites now located at different addresses.
  3856 			 * So apply the required displacements */
  3832 			 * So detect when the old ones get replaced. */
  3857 			if (IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) TranslateShoreSprites(load_index);
  3833 			if (IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
       
  3834 				if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
       
  3835 			}
  3858 		}
  3836 		}
  3859 	}
  3837 	}
  3860 }
  3838 }
  3861 
  3839 
  3862 /* Action 0x0A (SKIP) */
  3840 /* Action 0x0A (SKIP) */
  5125 	memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier));
  5103 	memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier));
  5126 
  5104 
  5127 	_loaded_newgrf_features.has_2CC           = false;
  5105 	_loaded_newgrf_features.has_2CC           = false;
  5128 	_loaded_newgrf_features.has_newhouses     = false;
  5106 	_loaded_newgrf_features.has_newhouses     = false;
  5129 	_loaded_newgrf_features.has_newindustries = false;
  5107 	_loaded_newgrf_features.has_newindustries = false;
       
  5108 	_loaded_newgrf_features.shore             = SHORE_REPLACE_NONE;
  5130 
  5109 
  5131 	InitializeSoundPool();
  5110 	InitializeSoundPool();
  5132 	InitializeSpriteGroupPool();
  5111 	InitializeSpriteGroupPool();
  5133 }
  5112 }
  5134 
  5113 
  5615 
  5594 
  5616 		if (_skip_sprites > 0) _skip_sprites--;
  5595 		if (_skip_sprites > 0) _skip_sprites--;
  5617 	}
  5596 	}
  5618 }
  5597 }
  5619 
  5598 
       
  5599 /**
       
  5600  * Relocates the old shore sprites at new positions.
       
  5601  *
       
  5602  * 1. If shore sprites are neither loaded by Action5 nor ActionA, the extra sprites from openttd(w/d).grf are used. (SHORE_REPLACE_ONLY_NEW)
       
  5603  * 2. If a newgrf replaces some shore sprites by ActionA. The (maybe also replaced) grass tiles are used for corner shores. (SHORE_REPLACE_ACTION_A)
       
  5604  * 3. If a newgrf replaces shore sprites by Action5 any shore replacement by ActionA has no effect. (SHORE_REPLACE_ACTION_5)
       
  5605  */
       
  5606 static void ActivateOldShore()
       
  5607 {
       
  5608 	/* Use default graphics, if no shore sprites were loaded.
       
  5609 	 * Should not happen, as openttd(w/d).grf includes some. */
       
  5610 	if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
       
  5611 
       
  5612 	if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) {
       
  5613 		DupSprite(SPR_ORIGINALSHORE_START +  1, SPR_SHORE_BASE +  1); // SLOPE_W
       
  5614 		DupSprite(SPR_ORIGINALSHORE_START +  2, SPR_SHORE_BASE +  2); // SLOPE_S
       
  5615 		DupSprite(SPR_ORIGINALSHORE_START +  6, SPR_SHORE_BASE +  3); // SLOPE_SW
       
  5616 		DupSprite(SPR_ORIGINALSHORE_START     , SPR_SHORE_BASE +  4); // SLOPE_E
       
  5617 		DupSprite(SPR_ORIGINALSHORE_START +  4, SPR_SHORE_BASE +  6); // SLOPE_SE
       
  5618 		DupSprite(SPR_ORIGINALSHORE_START +  3, SPR_SHORE_BASE +  8); // SLOPE_N
       
  5619 		DupSprite(SPR_ORIGINALSHORE_START +  7, SPR_SHORE_BASE +  9); // SLOPE_NW
       
  5620 		DupSprite(SPR_ORIGINALSHORE_START +  5, SPR_SHORE_BASE + 12); // SLOPE_NE
       
  5621 	}
       
  5622 
       
  5623 	if (_loaded_newgrf_features.shore == SHORE_REPLACE_ACTION_A) {
       
  5624 		DupSprite(SPR_FLAT_GRASS_TILE + 16, SPR_SHORE_BASE +  0); // SLOPE_STEEP_S
       
  5625 		DupSprite(SPR_FLAT_GRASS_TILE + 17, SPR_SHORE_BASE +  5); // SLOPE_STEEP_W
       
  5626 		DupSprite(SPR_FLAT_GRASS_TILE +  7, SPR_SHORE_BASE +  7); // SLOPE_WSE
       
  5627 		DupSprite(SPR_FLAT_GRASS_TILE + 15, SPR_SHORE_BASE + 10); // SLOPE_STEEP_N
       
  5628 		DupSprite(SPR_FLAT_GRASS_TILE + 11, SPR_SHORE_BASE + 11); // SLOPE_NWS
       
  5629 		DupSprite(SPR_FLAT_GRASS_TILE + 13, SPR_SHORE_BASE + 13); // SLOPE_ENW
       
  5630 		DupSprite(SPR_FLAT_GRASS_TILE + 14, SPR_SHORE_BASE + 14); // SLOPE_SEN
       
  5631 		DupSprite(SPR_FLAT_GRASS_TILE + 18, SPR_SHORE_BASE + 15); // SLOPE_STEEP_E
       
  5632 
       
  5633 		/* XXX - SLOPE_EW, SLOPE_NS are currently not used.
       
  5634 		 *       If they would be used somewhen, then these grass tiles will most like not look as needed */
       
  5635 		DupSprite(SPR_FLAT_GRASS_TILE +  5, SPR_SHORE_BASE + 16); // SLOPE_EW
       
  5636 		DupSprite(SPR_FLAT_GRASS_TILE + 10, SPR_SHORE_BASE + 17); // SLOPE_NS
       
  5637 	}
       
  5638 }
       
  5639 
  5620 void InitDepotWindowBlockSizes();
  5640 void InitDepotWindowBlockSizes();
  5621 
  5641 
  5622 extern void InitGRFTownGeneratorNames();
  5642 extern void InitGRFTownGeneratorNames();
  5623 
  5643 
  5624 static void AfterLoadGRFs()
  5644 static void AfterLoadGRFs()
  5649 	 * loaded before strings... */
  5669 	 * loaded before strings... */
  5650 	MapNewCargoStrings();
  5670 	MapNewCargoStrings();
  5651 
  5671 
  5652 	/* Update the townname generators list */
  5672 	/* Update the townname generators list */
  5653 	InitGRFTownGeneratorNames();
  5673 	InitGRFTownGeneratorNames();
       
  5674 
       
  5675 	/* Load old shore sprites in new position, if they were replaced by ActionA */
       
  5676 	ActivateOldShore();
  5654 }
  5677 }
  5655 
  5678 
  5656 void LoadNewGRF(uint load_index, uint file_index)
  5679 void LoadNewGRF(uint load_index, uint file_index)
  5657 {
  5680 {
  5658 	InitializeGRFSpecial();
  5681 	InitializeGRFSpecial();