SHOW:
|
|
- or go back to the newest paste.
| 1 | /* From now we'll calculate with fractional cargo amounts. | |
| 2 | * First determine how much cargo we really have. */ | |
| 3 | amount *= best_rating + 1; | |
| 4 | ||
| 5 | uint moving = 0; | |
| 6 | - | p.second = amount * company_best[owner] * p.first->goods[type].rating / best_sum / company_sum[owner]; |
| 6 | + | |
| 7 | uint owner = p.first->owner; | |
| 8 | - | uint difference = amount * company_best[owner] * p.first->goods[type].rating % (best_sum * company_sum[owner]); |
| 8 | + | |
| 9 | - | p.second |= (65535 * difference / best_sum / company_sum[owner]) << 16; |
| 9 | + | |
| 10 | uint a = amount * company_best[owner] * p.first->goods[type].rating; | |
| 11 | uint b = best_sum * company_sum[owner]; | |
| 12 | - | /* If there is some cargo left due to rounding issues distribute it according to the highest decimal. */ |
| 12 | + | p.second = a / b; |
| 13 | moving += p.second; | |
| 14 | p.second |= (65535 * (a % b) / b) << 16; | |
| 15 | } | |
| 16 | ||
| 17 | /* If there is some cargo left due to rounding issues distribute it according to the highest remainder. */ | |
| 18 | if (amount > moving) {
| |
| 19 | std::sort(used_stations.begin(), used_stations.end(), [](const StationInfo &a, const StationInfo &b) {
| |
| 20 | return b.second >> 16 < a.second >> 16; | |
| 21 | }); | |
| 22 | ||
| 23 | assert(amount - moving <= used_stations.size()); | |
| 24 | for (uint i = 0; i < amount - moving; i++) {
| |
| 25 | used_stations[i].second++; | |
| 26 | } | |
| 27 | - | } |
| 27 | + | |
| 28 | ||
| 29 | uint moved = 0; | |
| 30 | for (auto &p : used_stations) {
| |
| 31 | moved += UpdateStationWaiting(p.first, type, GB(p.second, 0, 16), source_type, source_id); | |
| 32 | } | |
| 33 | ||
| 34 | return moved; |