136 } |
136 } |
137 |
137 |
138 return (_internal_sort_order & 1) ? sum2 - sum1 : sum1 - sum2; |
138 return (_internal_sort_order & 1) ? sum2 - sum1 : sum1 - sum2; |
139 } |
139 } |
140 |
140 |
|
141 /** |
|
142 * qsort-compatible version of sorting two stations by maximum rating |
|
143 * @param a First object to be sorted, must be of type (const Station *) |
|
144 * @param b Second object to be sorted, must be of type (const Station *) |
|
145 * @return The sort order |
|
146 * @retval >0 a should come before b in the list |
|
147 * @retval <0 b should come before a in the list |
|
148 */ |
141 static int CDECL StationRatingMaxSorter(const void *a, const void *b) |
149 static int CDECL StationRatingMaxSorter(const void *a, const void *b) |
142 { |
150 { |
143 const Station* st1 = *(const Station**)a; |
151 const Station* st1 = *(const Station**)a; |
144 const Station* st2 = *(const Station**)b; |
152 const Station* st2 = *(const Station**)b; |
145 byte maxr1 = 0; |
153 byte maxr1 = 0; |
146 byte maxr2 = 0; |
154 byte maxr2 = 0; |
147 |
155 |
148 for (CargoID j = 0; j < NUM_CARGO; j++) { |
156 for (CargoID j = 0; j < NUM_CARGO; j++) { |
149 if (st1->goods[j].waiting_acceptance & 0xfff) maxr1 = max(maxr1, st1->goods[j].rating); |
157 if (st1->goods[j].enroute_from != INVALID_STATION) maxr1 = max(maxr1, st1->goods[j].rating); |
150 if (st2->goods[j].waiting_acceptance & 0xfff) maxr2 = max(maxr2, st2->goods[j].rating); |
158 if (st2->goods[j].enroute_from != INVALID_STATION) maxr2 = max(maxr2, st2->goods[j].rating); |
151 } |
159 } |
152 |
160 |
153 return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; |
161 return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; |
154 } |
162 } |
155 |
163 |