Changeset - r28000:c7edb1acb426
[Not reviewed]
master
0 1 0
Peter Nelson - 12 months ago 2023-10-18 19:49:00
peter1138@openttd.org
Codechange: Use bitmask instead of array for cargo consistency check.

We only need to know if a cargo type is accepted, not how much.
1 file changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/articulated_vehicles.cpp
Show inline comments
 
@@ -281,29 +281,29 @@ void CheckConsistencyOfArticulatedVehicl
 
	CargoTypes purchase_refit_union, purchase_refit_intersection;
 
	GetArticulatedRefitMasks(v->engine_type, true, &purchase_refit_union, &purchase_refit_intersection);
 
	CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type);
 

	
 
	CargoTypes real_refit_union = 0;
 
	CargoTypes real_refit_intersection = ALL_CARGOTYPES;
 
	CargoArray real_default_capacity{};
 
	CargoTypes real_default_cargoes = 0;
 

	
 
	do {
 
		CargoTypes refit_mask = GetAvailableVehicleCargoTypes(v->engine_type, true);
 
		real_refit_union |= refit_mask;
 
		if (refit_mask != 0) real_refit_intersection &= refit_mask;
 

	
 
		assert(v->cargo_type < NUM_CARGO);
 
		real_default_capacity[v->cargo_type] += v->cargo_cap;
 
		if (v->cargo_cap > 0) SetBit(real_default_cargoes, v->cargo_type);
 

	
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
 
	} while (v != nullptr);
 

	
 
	/* Check whether the vehicle carries more cargoes than expected */
 
	bool carries_more = false;
 
	for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 
		if (real_default_capacity[cid] != 0 && purchase_default_capacity[cid] == 0) {
 
	for (CargoID cid : SetCargoBitIterator(real_default_cargoes)) {
 
		if (purchase_default_capacity[cid] == 0) {
 
			carries_more = true;
 
			break;
 
		}
 
	}
 

	
 
	/* show a warning once for each GRF after each game load */
0 comments (0 inline, 0 general)