Changeset - r27423:4d40205ba623
[Not reviewed]
master
0 2 0
Peter Nelson - 16 months ago 2023-05-23 11:23:50
peter1138@openttd.org
Codechange: Use CargoArray::GetCount()
2 files changed with 2 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/subsidy.cpp
Show inline comments
 
@@ -325,28 +325,25 @@ bool FindSubsidyTownCargoRoute()
 
	/* Calculate the produced cargo of houses around town center. */
 
	CargoArray town_cargo_produced;
 
	TileArea ta = TileArea(src_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
 
	for (TileIndex tile : ta) {
 
		if (IsTileType(tile, MP_HOUSE)) {
 
			AddProducedCargo(tile, town_cargo_produced);
 
		}
 
	}
 

	
 
	/* Passenger subsidies are not handled here. */
 
	town_cargo_produced[CT_PASSENGERS] = 0;
 

	
 
	uint8 cargo_count = 0;
 
	for (CargoID i = 0; i < NUM_CARGO; i++) {
 
		if (town_cargo_produced[i] > 0) cargo_count++;
 
	}
 
	uint8 cargo_count = town_cargo_produced.GetCount();
 

	
 
	/* No cargo produced at all? */
 
	if (cargo_count == 0) return false;
 

	
 
	/* Choose a random cargo that is produced in the town. */
 
	uint8 cargo_number = RandomRange(cargo_count);
 
	CargoID cid;
 
	for (cid = 0; cid < NUM_CARGO; cid++) {
 
		if (town_cargo_produced[cid] > 0) {
 
			if (cargo_number == 0) break;
 
			cargo_number--;
 
		}
src/train_gui.cpp
Show inline comments
 
@@ -320,30 +320,25 @@ static uint GetLengthOfArticulatedVehicl
 
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
 
{
 
	int num = 0;
 

	
 
	if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
 
		CargoArray act_cargo;
 
		CargoArray max_cargo;
 
		for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
 
			act_cargo[v->cargo_type] += v->cargo.StoredCount();
 
			max_cargo[v->cargo_type] += v->cargo_cap;
 
		}
 

	
 
		/* Set scroll-amount separately from counting, as to not compute num double
 
		 * for more carriages of the same type
 
		 */
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			if (max_cargo[i] > 0) num++; // only count carriages that the train has
 
		}
 
		num = max_cargo.GetCount();
 
		num++; // needs one more because first line is description string
 
	} else {
 
		for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
 
			GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
 
			num += std::max(1u, (unsigned)_cargo_summary.size());
 

	
 
			uint length = GetLengthOfArticulatedVehicle(v);
 
			if (length > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT)) num++;
 
		}
 
	}
 

	
 
	return num;
0 comments (0 inline, 0 general)