Fix crash in distributing residual cargo in MoveGoodsToStation
This commit is contained in:
@@ -4349,9 +4349,12 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
|
|||||||
return b.first->goods[type].rating < a.first->goods[type].rating;
|
return b.first->goods[type].rating < a.first->goods[type].rating;
|
||||||
});
|
});
|
||||||
|
|
||||||
assert(amount - moving <= used_stations.size());
|
uint to_deliver = amount - moving;
|
||||||
for (uint i = 0; i < amount - moving; i++) {
|
uint step_size = CeilDivT<uint>(to_deliver, used_stations.size());
|
||||||
used_stations[i].second++;
|
for (uint i = 0; i < used_stations.size() && to_deliver > 0; i++) {
|
||||||
|
uint delivery = min<uint>(to_deliver, step_size);
|
||||||
|
used_stations[i].second += delivery;
|
||||||
|
to_deliver -= delivery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user