src/newgrf.cpp
changeset 10298 0a4a98c78137
parent 10266 435142fa43dc
child 10382 d1d4452acbfc
equal deleted inserted replaced
10296:a1b48fc82022 10298:0a4a98c78137
   113 
   113 
   114 enum {
   114 enum {
   115 	MAX_STATIONS = 256,
   115 	MAX_STATIONS = 256,
   116 };
   116 };
   117 
   117 
   118 static uint16 cargo_allowed[TOTAL_NUM_ENGINES];
   118 /* Temporary data used when loading only */
   119 static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
   119 struct GRFTempEngineData {
       
   120 	uint16 cargo_allowed;
       
   121 	uint16 cargo_disallowed;
       
   122 };
       
   123 
       
   124 static GRFTempEngineData *_gted;
   120 
   125 
   121 /* Contains the GRF ID of the owner of a vehicle if it has been reserved */
   126 /* Contains the GRF ID of the owner of a vehicle if it has been reserved */
   122 static uint32 _grm_engines[TOTAL_NUM_ENGINES];
   127 static uint32 _grm_engines[TOTAL_NUM_ENGINES];
   123 
   128 
   124 /* Contains the GRF ID of the owner of a cargo if it has been reserved */
   129 /* Contains the GRF ID of the owner of a cargo if it has been reserved */
   571 				ei->misc_flags = grf_load_byte(&buf);
   576 				ei->misc_flags = grf_load_byte(&buf);
   572 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   577 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   573 				break;
   578 				break;
   574 
   579 
   575 			case 0x28: // Cargo classes allowed
   580 			case 0x28: // Cargo classes allowed
   576 				cargo_allowed[engine + i] = grf_load_word(&buf);
   581 				_gted[engine + i].cargo_allowed = grf_load_word(&buf);
   577 				break;
   582 				break;
   578 
   583 
   579 			case 0x29: // Cargo classes disallowed
   584 			case 0x29: // Cargo classes disallowed
   580 				cargo_disallowed[engine + i] = grf_load_word(&buf);
   585 				_gted[engine + i].cargo_disallowed = grf_load_word(&buf);
   581 				break;
   586 				break;
   582 
   587 
   583 			case 0x2A: // Long format introduction date (days since year 0)
   588 			case 0x2A: // Long format introduction date (days since year 0)
   584 				ei->base_intro = grf_load_dword(&buf);
   589 				ei->base_intro = grf_load_dword(&buf);
   585 				break;
   590 				break;
   701 				ei->misc_flags = grf_load_byte(&buf);
   706 				ei->misc_flags = grf_load_byte(&buf);
   702 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   707 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   703 				break;
   708 				break;
   704 
   709 
   705 			case 0x1D: // Cargo classes allowed
   710 			case 0x1D: // Cargo classes allowed
   706 				cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   711 				_gted[ROAD_ENGINES_INDEX + engine + i].cargo_allowed = grf_load_word(&buf);
   707 				break;
   712 				break;
   708 
   713 
   709 			case 0x1E: // Cargo classes disallowed
   714 			case 0x1E: // Cargo classes disallowed
   710 				cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   715 				_gted[ROAD_ENGINES_INDEX + engine + i].cargo_disallowed = grf_load_word(&buf);
   711 				break;
   716 				break;
   712 
   717 
   713 			case 0x1F: // Long format introduction date (days since year 0)
   718 			case 0x1F: // Long format introduction date (days since year 0)
   714 				ei->base_intro = grf_load_dword(&buf);
   719 				ei->base_intro = grf_load_dword(&buf);
   715 				break;
   720 				break;
   807 				ei->misc_flags = grf_load_byte(&buf);
   812 				ei->misc_flags = grf_load_byte(&buf);
   808 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   813 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   809 				break;
   814 				break;
   810 
   815 
   811 			case 0x18: // Cargo classes allowed
   816 			case 0x18: // Cargo classes allowed
   812 				cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   817 				_gted[SHIP_ENGINES_INDEX + engine + i].cargo_allowed = grf_load_word(&buf);
   813 				break;
   818 				break;
   814 
   819 
   815 			case 0x19: // Cargo classes disallowed
   820 			case 0x19: // Cargo classes disallowed
   816 				cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   821 				_gted[SHIP_ENGINES_INDEX + engine + i].cargo_disallowed = grf_load_word(&buf);
   817 				break;
   822 				break;
   818 
   823 
   819 			case 0x1A: // Long format introduction date (days since year 0)
   824 			case 0x1A: // Long format introduction date (days since year 0)
   820 				ei->base_intro = grf_load_dword(&buf);
   825 				ei->base_intro = grf_load_dword(&buf);
   821 				break;
   826 				break;
   911 				ei->misc_flags = grf_load_byte(&buf);
   916 				ei->misc_flags = grf_load_byte(&buf);
   912 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   917 				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
   913 				break;
   918 				break;
   914 
   919 
   915 			case 0x18: // Cargo classes allowed
   920 			case 0x18: // Cargo classes allowed
   916 				cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   921 				_gted[AIRCRAFT_ENGINES_INDEX + engine + i].cargo_allowed = grf_load_word(&buf);
   917 				break;
   922 				break;
   918 
   923 
   919 			case 0x19: // Cargo classes disallowed
   924 			case 0x19: // Cargo classes disallowed
   920 				cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
   925 				_gted[AIRCRAFT_ENGINES_INDEX + engine + i].cargo_disallowed = grf_load_word(&buf);
   921 				break;
   926 				break;
   922 
   927 
   923 			case 0x1A: // Long format introduction date (days since year 0)
   928 			case 0x1A: // Long format introduction date (days since year 0)
   924 				ei->base_intro = grf_load_dword(&buf);
   929 				ei->base_intro = grf_load_dword(&buf);
   925 				break;
   930 				break;
  5216 	SetupEngines();
  5221 	SetupEngines();
  5217 
  5222 
  5218 	/* Copy/reset original bridge info data */
  5223 	/* Copy/reset original bridge info data */
  5219 	ResetBridges();
  5224 	ResetBridges();
  5220 
  5225 
  5221 	/* Reset refit/cargo class data */
  5226 	/* Allocate temporary refit/cargo class data */
  5222 	memset(&cargo_allowed, 0, sizeof(cargo_allowed));
  5227 	_gted = CallocT<GRFTempEngineData>(TOTAL_NUM_ENGINES);
  5223 	memset(&cargo_disallowed, 0, sizeof(cargo_disallowed));
       
  5224 
  5228 
  5225 	/* Reset GRM reservations */
  5229 	/* Reset GRM reservations */
  5226 	memset(&_grm_engines, 0, sizeof(_grm_engines));
  5230 	memset(&_grm_engines, 0, sizeof(_grm_engines));
  5227 	memset(&_grm_cargos, 0, sizeof(_grm_cargos));
  5231 	memset(&_grm_cargos, 0, sizeof(_grm_cargos));
  5228 
  5232 
  5421 					if (HasBit(ei->refit_mask, cs->bitnum)) SetBit(xor_mask, c);
  5425 					if (HasBit(ei->refit_mask, cs->bitnum)) SetBit(xor_mask, c);
  5422 				}
  5426 				}
  5423 			}
  5427 			}
  5424 		}
  5428 		}
  5425 
  5429 
  5426 		if (cargo_allowed[engine] != 0) {
  5430 		if (_gted[engine].cargo_allowed != 0) {
  5427 			/* Build up the list of cargo types from the set cargo classes. */
  5431 			/* Build up the list of cargo types from the set cargo classes. */
  5428 			for (CargoID i = 0; i < NUM_CARGO; i++) {
  5432 			for (CargoID i = 0; i < NUM_CARGO; i++) {
  5429 				const CargoSpec *cs = GetCargo(i);
  5433 				const CargoSpec *cs = GetCargo(i);
  5430 				if (cargo_allowed[engine]    & cs->classes) SetBit(mask,     i);
  5434 				if (_gted[engine].cargo_allowed    & cs->classes) SetBit(mask,     i);
  5431 				if (cargo_disallowed[engine] & cs->classes) SetBit(not_mask, i);
  5435 				if (_gted[engine].cargo_disallowed & cs->classes) SetBit(not_mask, i);
  5432 			}
  5436 			}
  5433 		} else {
  5437 		} else {
  5434 			/* Don't apply default refit mask to wagons or engines with no capacity */
  5438 			/* Don't apply default refit mask to wagons or engines with no capacity */
  5435 			if (xor_mask == 0 && (
  5439 			if (xor_mask == 0 && (
  5436 						GetEngine(engine)->type != VEH_TRAIN || (
  5440 						GetEngine(engine)->type != VEH_TRAIN || (
  5847 	/* Update the townname generators list */
  5851 	/* Update the townname generators list */
  5848 	InitGRFTownGeneratorNames();
  5852 	InitGRFTownGeneratorNames();
  5849 
  5853 
  5850 	/* Load old shore sprites in new position, if they were replaced by ActionA */
  5854 	/* Load old shore sprites in new position, if they were replaced by ActionA */
  5851 	ActivateOldShore();
  5855 	ActivateOldShore();
       
  5856 
       
  5857 	/* Deallocate temporary loading data */
       
  5858 	free(_gted);
  5852 }
  5859 }
  5853 
  5860 
  5854 void LoadNewGRF(uint load_index, uint file_index)
  5861 void LoadNewGRF(uint load_index, uint file_index)
  5855 {
  5862 {
  5856 	InitializeGRFSpecial();
  5863 	InitializeGRFSpecial();