Changeset - r28000:c7edb1acb426
[Not reviewed]
master
0 1 0
Peter Nelson - 14 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
 
@@ -284,7 +284,7 @@ void CheckConsistencyOfArticulatedVehicl
 

	
 
	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);
 
@@ -292,15 +292,15 @@ void CheckConsistencyOfArticulatedVehicl
 
		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;
 
		}
0 comments (0 inline, 0 general)