Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* From now we'll calculate with fractional cargo amounts.
- * First determine how much cargo we really have. */
- amount *= best_rating + 1;
- uint moving = 0;
- for (auto &p : used_stations) {
- uint owner = p.first->owner;
- /* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
- * and by (station rating / sum of ratings in a company) to get the result for a single station. */
- uint a = amount * company_best[owner] * p.first->goods[type].rating;
- uint b = best_sum * company_sum[owner];
- p.second = a / b;
- moving += p.second;
- p.second |= (65535 * (a % b) / b) << 16;
- }
- /* If there is some cargo left due to rounding issues distribute it according to the highest remainder. */
- if (amount > moving) {
- std::sort(used_stations.begin(), used_stations.end(), [](const StationInfo &a, const StationInfo &b) {
- return b.second >> 16 < a.second >> 16;
- });
- assert(amount - moving <= used_stations.size());
- for (uint i = 0; i < amount - moving; i++) {
- used_stations[i].second++;
- }
- }
- uint moved = 0;
- for (auto &p : used_stations) {
- moved += UpdateStationWaiting(p.first, type, GB(p.second, 0, 16), source_type, source_id);
- }
- return moved;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement