Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1.     uint moving = 0;
  2.     for (auto &p : used_stations) {
  3.         uint owner = p.first->owner;
  4.         /* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
  5.          * and by (station rating / sum of ratings in a company) to get the result for a single station. */
  6.         p.second = amount * company_best[owner] * p.first->goods[type].rating / best_sum / company_sum[owner];
  7.         moving += p.second;
  8.         uint difference = amount * company_best[owner] * p.first->goods[type].rating % (best_sum * company_sum[owner]);
  9.         p.second |= (65535 * difference / best_sum / company_sum[owner]) << 16;
  10.     }
  11.  
  12.     /* If there is some cargo left due to rounding issues distribute it according to the highest decimal. */
  13.     if (amount > moving) {
  14.         std::sort(used_stations.begin(), used_stations.end(), [](const StationInfo &a, const StationInfo &b) {
  15.             return b.second >> 16 < a.second >> 16;
  16.         });
  17.  
  18.         assert(amount - moving <= used_stations.size());
  19.         for (uint i = 0; i < amount - moving; i++) {
  20.             used_stations[i].second++;
  21.         }
  22.     }
  23.  
  24.     uint moved = 0;
  25.     for (auto &p : used_stations) {
  26.         moved += UpdateStationWaiting(p.first, type, GB(p.second, 0, 16), source_type, source_id);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement