Changeset - r27868:50ab1fbf7b72
[Not reviewed]
master
0 1 0
Jonathan G Rennison - 12 months ago 2023-09-06 19:36:26
j.g.rennison@gmail.com
Fix: Inaccurate waiting cargo total in station window when using cargodist (#11213)

For stations with many flows and/or small cargo packets,
due to accumulated inaccuracies in DivideApprox.

The displayed total should match GoodsEntry::TotalCount().
1 file changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/station_gui.cpp
Show inline comments
 
@@ -1603,9 +1603,23 @@ struct StationViewWindow : public Window
 
				continue;
 
			}
 

	
 
			for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
 
			uint remaining = cp->Count();
 
			for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End();) {
 
				CargoDataEntry *dest_entry = *dest_it;
 
				uint val = DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount());
 

	
 
				/* Advance iterator here instead of in the for statement to test whether this is the last entry */
 
				++dest_it;
 

	
 
				uint val;
 
				if (dest_it == via_entry->End()) {
 
					/* Allocate all remaining waiting cargo to the last destination to avoid
 
					 * waiting cargo being "lost", and the displayed total waiting cargo
 
					 * not matching GoodsEntry::TotalCount() */
 
					val = remaining;
 
				} else {
 
					val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
 
					remaining -= val;
 
				}
 
				this->ShowCargo(cargo, i, cp->SourceStation(), next, dest_entry->GetStation(), val);
 
			}
 
		}
0 comments (0 inline, 0 general)