Changeset - r28018:13053db3b627
[Not reviewed]
master
0 2 0
Peter Nelson - 14 months ago 2023-10-20 17:38:54
peter1138@openttd.org
Codechange: Simplify usage of GRFFile cargo_map. (#11349)
2 files changed with 7 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -8850,7 +8850,7 @@ void ResetPersistentNewGRFData()
 
 */
 
static void BuildCargoTranslationMap()
 
{
 
	memset(_cur.grffile->cargo_map, 0xFF, sizeof(_cur.grffile->cargo_map));
 
	_cur.grffile->cargo_map.fill(UINT8_MAX);
 

	
 
	for (const CargoSpec *cs : CargoSpec::Iterate()) {
 
		if (!cs->IsValid()) continue;
 
@@ -9067,20 +9067,13 @@ static void CalculateRefitMasks()
 
		 * cargo type. Finally disable the vehicle, if there is still no cargo. */
 
		if (!IsValidCargoID(ei->cargo_type) && ei->refit_mask != 0) {
 
			/* Figure out which CTT to use for the default cargo, if it is 'first refittable'. */
 
			const uint8_t *cargo_map_for_first_refittable = nullptr;
 
			{
 
				const GRFFile *file = _gted[engine].defaultcargo_grf;
 
				if (file == nullptr) file = e->GetGRF();
 
				if (file != nullptr && file->grf_version >= 8 && file->cargo_list.size() != 0) {
 
					cargo_map_for_first_refittable = file->cargo_map;
 
				}
 
			}
 

	
 
			if (cargo_map_for_first_refittable != nullptr) {
 
			const GRFFile *file = _gted[engine].defaultcargo_grf;
 
			if (file == nullptr) file = e->GetGRF();
 
			if (file != nullptr && file->grf_version >= 8 && file->cargo_list.size() != 0) {
 
				/* Use first refittable cargo from cargo translation table */
 
				byte best_local_slot = 0xFF;
 
				byte best_local_slot = UINT8_MAX;
 
				for (CargoID cargo_type : SetCargoBitIterator(ei->refit_mask)) {
 
					byte local_slot = cargo_map_for_first_refittable[cargo_type];
 
					byte local_slot = file->cargo_map[cargo_type];
 
					if (local_slot < best_local_slot) {
 
						best_local_slot = local_slot;
 
						ei->cargo_type = cargo_type;
src/newgrf.h
Show inline comments
 
@@ -127,7 +127,7 @@ struct GRFFile : ZeroedMemoryAllocator {
 
	std::vector<GRFLabel> labels;                   ///< List of labels
 

	
 
	std::vector<CargoLabel> cargo_list;             ///< Cargo translation table (local ID -> label)
 
	uint8_t cargo_map[NUM_CARGO];                     ///< Inverse cargo translation table (CargoID -> local ID)
 
	std::array<uint8_t, NUM_CARGO> cargo_map{}; ///< Inverse cargo translation table (CargoID -> local ID)
 

	
 
	std::vector<RailTypeLabel> railtype_list;       ///< Railtype translation table
 
	RailType railtype_map[RAILTYPE_END];
0 comments (0 inline, 0 general)