| 81 | /* three stations around, the best three (highest rating) are in st1, st2 and st3 */
| 154 | if (st4 == NULL) {
|
|---|
| | | 155 | /* three stations around, the best three (highest rating) are in st1, st2 and st3 */
|
|---|
| | | 156 | assert(st1 != NULL);
|
|---|
| | | 157 | assert(st2 != NULL);
|
|---|
| | | 158 | assert(st3 != NULL);
|
|---|
| | | 159 | assert(best_rating1 != 0 || best_rating2 != 0 || best_rating3 != 0);
|
|---|
| | | 160 |
|
|---|
| | | 161 | /* Then determine the amount the worst stations get. We do it this way as the
|
|---|
| | | 162 | * best should get a bonus, which in this case is the rounding difference from
|
|---|
| | | 163 | * this calculation. In reality that will mean the bonus will be pretty low.
|
|---|
| | | 164 | * Nevertheless, the best station should always get the most cargo regardless
|
|---|
| | | 165 | * of rounding issues. */
|
|---|
| | | 166 | uint cargo_st3 = amount * best_rating3 / (best_rating1 + best_rating2 + best_rating3);
|
|---|
| | | 167 | assert(cargo_st3 <= (amount - cargo_st3));
|
|---|
| | | 168 |
|
|---|
| | | 169 | uint remaining = amount - cargo_st3;
|
|---|
| | | 170 | uint cargo_st2 = remaining * best_rating2 / (best_rating1 + best_rating2);
|
|---|
| | | 171 | assert(cargo_st2 <= (remaining - cargo_st2));
|
|---|
| | | 172 |
|
|---|
| | | 173 | uint cargo_st1 = remaining - cargo_st2;
|
|---|
| | | 174 | assert(amount == cargo_st1 + cargo_st2 + cargo_st3);
|
|---|
| | | 175 |
|
|---|
| | | 176 | /* And then send the cargo to the stations! */
|
|---|
| | | 177 | uint moved = UpdateStationWaiting(st1, type, cargo_st1, source_type, source_id);
|
|---|
| | | 178 | moved += UpdateStationWaiting(st2, type, cargo_st2, source_type, source_id);
|
|---|
| | | 179 | return moved + UpdateStationWaiting(st3, type, cargo_st3, source_type, source_id);
|
|---|
| | | 180 | }
|
|---|
| | | 181 |
|
|---|
| | | 182 | if (st5 == NULL) {
|
|---|
| | | 183 | /* Four stations around, the best four (highest rating) are in st1, st2, st3 and st4 */
|
|---|
| | | 184 | assert(st1 != NULL);
|
|---|
| | | 185 | assert(st2 != NULL);
|
|---|
| | | 186 | assert(st3 != NULL);
|
|---|
| | | 187 | assert(st4 != NULL);
|
|---|
| | | 188 | assert(best_rating1 != 0 || best_rating2 != 0 || best_rating3 != 0 || best_rating4 != 0);
|
|---|
| | | 189 |
|
|---|
| | | 190 | /* Then determine the amount the worst stations get. We do it this way as the
|
|---|
| | | 191 | * best should get a bonus, which in this case is the rounding difference from
|
|---|
| | | 192 | * this calculation. In reality that will mean the bonus will be pretty low.
|
|---|
| | | 193 | * Nevertheless, the best station should always get the most cargo regardless
|
|---|
| | | 194 | * of rounding issues. */
|
|---|
| | | 195 | uint cargo_st4 = amount * best_rating4 / (best_rating1 + best_rating2 + best_rating3 + best_rating4);
|
|---|
| | | 196 | assert(cargo_st4 <= (amount - cargo_st4));
|
|---|
| | | 197 |
|
|---|
| | | 198 | uint remaining = amount - cargo_st4;
|
|---|
| | | 199 | uint cargo_st3 = remaining * best_rating3 / (best_rating1 + best_rating2 + best_rating3);
|
|---|
| | | 200 | assert(cargo_st3 <= (remaining - cargo_st3));
|
|---|
| | | 201 |
|
|---|
| | | 202 | remaining -= cargo_st3;
|
|---|
| | | 203 | uint cargo_st2 = remaining * best_rating2 / (best_rating1 + best_rating2);
|
|---|
| | | 204 | assert(cargo_st2 <= (remaining - cargo_st2));
|
|---|
| | | 205 |
|
|---|
| | | 206 | uint cargo_st1 = remaining - cargo_st2;
|
|---|
| | | 207 | assert(amount == cargo_st1 + cargo_st2 + cargo_st3 + cargo_st4);
|
|---|
| | | 208 |
|
|---|
| | | 209 | /* And then send the cargo to the stations! */
|
|---|
| | | 210 | uint moved = UpdateStationWaiting(st1, type, cargo_st1, source_type, source_id);
|
|---|
| | | 211 | moved += UpdateStationWaiting(st2, type, cargo_st2, source_type, source_id);
|
|---|
| | | 212 | moved += UpdateStationWaiting(st3, type, cargo_st3, source_type, source_id);
|
|---|
| | | 213 | return moved + UpdateStationWaiting(st4, type, cargo_st4, source_type, source_id);
|
|---|
| | | 214 | }
|
|---|
| | | 215 |
|
|---|
| | | 216 | if (st6 == NULL) {
|
|---|
| | | 217 | /* Five stations around, the best five (highest rating) are in st1, st2, st3, st4 and st5 */
|
|---|
| | | 218 | assert(st1 != NULL);
|
|---|
| | | 219 | assert(st2 != NULL);
|
|---|
| | | 220 | assert(st3 != NULL);
|
|---|
| | | 221 | assert(st4 != NULL);
|
|---|
| | | 222 | assert(st5 != NULL);
|
|---|
| | | 223 | assert(best_rating1 != 0 || best_rating2 != 0 || best_rating3 != 0 || best_rating4 != 0 || best_rating5 != 0);
|
|---|
| | | 224 |
|
|---|
| | | 225 | /* Then determine the amount the worst stations get. We do it this way as the
|
|---|
| | | 226 | * best should get a bonus, which in this case is the rounding difference from
|
|---|
| | | 227 | * this calculation. In reality that will mean the bonus will be pretty low.
|
|---|
| | | 228 | * Nevertheless, the best station should always get the most cargo regardless
|
|---|
| | | 229 | * of rounding issues. */
|
|---|
| | | 230 | uint cargo_st5 = amount * best_rating5 / (best_rating1 + best_rating2 + best_rating3 + best_rating4 + best_rating5);
|
|---|
| | | 231 | assert(cargo_st5 <= (amount - cargo_st5));
|
|---|
| | | 232 |
|
|---|
| | | 233 | uint remaining = amount - cargo_st5;
|
|---|
| | | 234 | uint cargo_st4 = remaining * best_rating4 / (best_rating1 + best_rating2 + best_rating3 + best_rating4);
|
|---|
| | | 235 | assert(cargo_st4 <= (remaining - cargo_st4));
|
|---|
| | | 236 |
|
|---|
| | | 237 | remaining -= cargo_st4;
|
|---|
| | | 238 | uint cargo_st3 = remaining * best_rating3 / (best_rating1 + best_rating2 + best_rating3);
|
|---|
| | | 239 | assert(cargo_st3 <= (remaining - cargo_st3));
|
|---|
| | | 240 |
|
|---|
| | | 241 | remaining -= cargo_st3;
|
|---|
| | | 242 | uint cargo_st2 = remaining * best_rating2 / (best_rating1 + best_rating2);
|
|---|
| | | 243 | assert(cargo_st2 <= (remaining - cargo_st2));
|
|---|
| | | 244 |
|
|---|
| | | 245 | uint cargo_st1 = remaining - cargo_st2;
|
|---|
| | | 246 | assert(amount == cargo_st1 + cargo_st2 + cargo_st3 + cargo_st4 + cargo_st5);
|
|---|
| | | 247 |
|
|---|
| | | 248 | /* And then send the cargo to the stations! */
|
|---|
| | | 249 | uint moved = UpdateStationWaiting(st1, type, cargo_st1, source_type, source_id);
|
|---|
| | | 250 | moved += UpdateStationWaiting(st2, type, cargo_st2, source_type, source_id);
|
|---|
| | | 251 | moved += UpdateStationWaiting(st3, type, cargo_st3, source_type, source_id);
|
|---|
| | | 252 | moved += UpdateStationWaiting(st4, type, cargo_st4, source_type, source_id);
|
|---|
| | | 253 | return moved + UpdateStationWaiting(st5, type, cargo_st5, source_type, source_id);
|
|---|
| | | 254 | }
|
|---|
| | | 255 |
|
|---|
| | | 256 | /* Six stations around, the best six (highest rating) are in st1, st2, st3, st4, st5 and st6 */
|
|---|
| 92 | uint worst_cargo_st3 = amount * best_rating3 / (best_rating1 + best_rating2 + best_rating3);
| 270 | uint cargo_st6 = amount * best_rating6 / (best_rating1 + best_rating2 + best_rating3 + best_rating4 + best_rating5 + best_rating6);
|
|---|
| 93 | assert(worst_cargo_st3 <= (amount - worst_cargo_st3));
| 271 | assert(cargo_st6 <= (amount - cargo_st6));
|
|---|
| 94 |
| 272 |
|
|---|
| 95 | uint remaining_amount = amount - worst_cargo_st3;
| 273 | uint remaining = amount - cargo_st6;
|
|---|
| 96 | uint worst_cargo_st2 = remaining_amount * best_rating2 / (best_rating1 + best_rating2);
| 274 | uint cargo_st5 = remaining * best_rating5 / (best_rating1 + best_rating2 + best_rating3 + best_rating4 + best_rating5);
|
|---|
| 97 | assert(worst_cargo_st2 <= (remaining_amount - worst_cargo_st2));
| 275 | assert(cargo_st5 <= (remaining - cargo_st5));
|
|---|
| | | 276 |
|
|---|
| | | 277 | remaining -= cargo_st5;
|
|---|
| | | 278 | uint cargo_st4 = remaining * best_rating4 / (best_rating1 + best_rating2 + best_rating3 + best_rating4);
|
|---|
| | | 279 | assert(cargo_st4 <= (remaining - cargo_st4));
|
|---|
| | | 280 |
|
|---|
| | | 281 | remaining -= cargo_st4;
|
|---|
| | | 282 | uint cargo_st3 = remaining * best_rating3 / (best_rating1 + best_rating2 + best_rating3);
|
|---|
| | | 283 | assert(cargo_st3 <= (remaining - cargo_st3));
|
|---|
| | | 284 |
|
|---|
| | | 285 | remaining -= cargo_st3;
|
|---|
| | | 286 | uint cargo_st2 = remaining * best_rating2 / (best_rating1 + best_rating2);
|
|---|
| | | 287 | assert(cargo_st2 <= (remaining - cargo_st2));
|
|---|
| | | 288 |
|
|---|
| | | 289 | uint cargo_st1 = remaining - cargo_st2;
|
|---|
| | | 290 | assert(amount == cargo_st1 + cargo_st2 + cargo_st3 + cargo_st4 + cargo_st5 + cargo_st6);
|
|---|
| 100 | uint moved = UpdateStationWaiting(st1, type, remaining_amount - worst_cargo_st2, source_type, source_id);
| 293 | uint moved = UpdateStationWaiting(st1, type, cargo_st1, source_type, source_id);
|
|---|
| 101 | /* HALP - I GOT 3 UpdateStationWaitings now! */
| 294 | moved += UpdateStationWaiting(st2, type, cargo_st2, source_type, source_id);
|
|---|
| 102 | moved += UpdateStationWaiting(st2, type, worst_cargo_st2, source_type, source_id);
| 295 | moved += UpdateStationWaiting(st3, type, cargo_st3, source_type, source_id);
|
|---|
| 103 | return moved + UpdateStationWaiting(st3, type, worst_cargo_st3, source_type, source_id);
| 296 | moved += UpdateStationWaiting(st4, type, cargo_st4, source_type, source_id);
|
|---|
| | | 297 | moved += UpdateStationWaiting(st5, type, cargo_st5, source_type, source_id);
|
|---|
| | | 298 | return moved + UpdateStationWaiting(st6, type, cargo_st6, source_type, source_id);
|
|---|