Loading

Revision differences

Old revision #p2pn4kewwNew revision #pempnuqzd
2{  2{  
3    /* Return if nothing to do. Also the rounding below fails for 0. */  3    /* Return if nothing to do. Also the rounding below fails for 0. */  
4    if (amount == 0) return 0;  4    if (amount == 0) return 0;  
5    
6    Station *st1 = NULL;   // Station with best rating  5    Station *st1 = NULL;   // Station with best rating  
7    Station *st2 = NULL;   // Second best station  6    Station *st2 = NULL;   // Second best station  
8    Station *st3 = NULL;   // Third best station  7    Station *st3 = NULL;   // Third best station  
  
86         * this calculation. In reality that will mean the bonus will be pretty low.  85         * this calculation. In reality that will mean the bonus will be pretty low.  
87         * Nevertheless, the best station should always get the most cargo regardless  86         * Nevertheless, the best station should always get the most cargo regardless  
88         * of rounding issues. */  87         * of rounding issues. */  
89        uint worst_cargo = amount * best_rating2 / (best_rating1 + best_rating2);  88        uint cargo_st2 = amount * best_rating2 / (best_rating1 + best_rating2);
90        assert(worst_cargo <= (amount - worst_cargo));  89        assert(cargo_st2 <= (amount - cargo_st2));
91  90       
92        /* And then send the cargo to the stations! */  91        uint cargo_st1 = amount - cargo_st2;
93        uint moved = UpdateStationWaiting(st1, type, amount - worst_cargo, source_type, source_id);  92        assert(amount = cargo_st1 + cargo_st2);
   93
   94        /* And then send the cargo to the stations! */
   95        uint moved = UpdateStationWaiting(st1, type, cargo_st1, source_type, source_id);
94        /* These two UpdateStationWaiting's can't be in the statement as then the order  96        /* These two UpdateStationWaiting's can't be in the statement as then the order  
95         * of execution would be undefined and that could cause desyncs with callbacks. */  97         * of execution would be undefined and that could cause desyncs with callbacks. */  
96        return moved + UpdateStationWaiting(st2, type, worst_cargo, source_type, source_id);  96        return moved + UpdateStationWaiting(st2, type, cargo_st2, source_type, source_id);
97    }  99    }  
98  100  
99    if (st4 == NULL) {  101    if (st4 == NULL) {  
  
159    }  161    }  
160  162  
161    if (st6 == NULL) {  163    if (st6 == NULL) {  
162        /* Five stations around, the best five (highest rating) are in st1, st2, st3, st4 and st5*/  162        /* Five stations around, the best five (highest rating) are in st1, st2, st3, st4 and st5 */
163        assert(st1 != NULL);  165        assert(st1 != NULL);  
164        assert(st2 != NULL);  166        assert(st2 != NULL);  
165        assert(st3 != NULL);  167        assert(st3 != NULL);