Index: src/lang/english.txt =================================================================== --- src/lang/english.txt (revision 26578) +++ src/lang/english.txt (working copy) @@ -289,6 +289,7 @@ STR_SORT_BY_WAITING_AVAILABLE :Available waiting cargo STR_SORT_BY_RATING_MAX :Highest cargo rating STR_SORT_BY_RATING_MIN :Lowest cargo rating +STR_SORT_BY_VEHICLE_USAGE :Vehicle usage rating STR_SORT_BY_ENGINE_ID :EngineID (classic sort) STR_SORT_BY_COST :Cost STR_SORT_BY_POWER :Power Index: src/lang/polish.txt =================================================================== --- src/lang/polish.txt (revision 26578) +++ src/lang/polish.txt (working copy) @@ -668,6 +668,7 @@ STR_SORT_BY_WAITING_AVAILABLE :Dostępny czekający ładunek STR_SORT_BY_RATING_MAX :Towar najwyżej oceniany STR_SORT_BY_RATING_MIN :Towar najniżej oceniany +STR_SORT_BY_VEHICLE_USAGE :Użycie stacji przez pojazdy STR_SORT_BY_ENGINE_ID :ID pojazdu (klasyczne sortowanie) STR_SORT_BY_COST :Cena STR_SORT_BY_POWER :Moc Index: src/station_gui.cpp =================================================================== --- src/station_gui.cpp (revision 26578) +++ src/station_gui.cpp (working copy) @@ -142,6 +142,57 @@ if (rating != 0) GfxFillRect(left + 1, y, left + rating, y, PC_GREEN); } +/** + * Get the number of occurences of the station @c stationIdx in the schedules + * of the vehicles of type @c vtype. + * + * @param stationIdx The @c StationID of the station for which to compute the + * occurences. + * @param vtype Type of the vehicles whose schedules should be taken into + * account. + */ +static uint GetNumScheduledVehiclesForStation(StationID stationIdx, VehicleType vtype) +{ + // the CompanyID is not used when computing a station list, so we can just + // pass an invalid value in there. + VehicleListIdentifier vli(VL_STATION_LIST, vtype, INVALID_COMPANY, stationIdx); + VehicleList vl; + GenerateVehicleSortList(&vl, vli); + return vl.Length(); +} + +/** + * Get the number of occurrences of a given station in the schedules of all the + * vehicles that can be scheduled to go to this station, according to its + * facilities. + * + * @param st The station for which to compute the occurences. + */ +static uint GetAllScheduledVehiclesForStation(const Station &st) +{ + StationID stationIdx = GetStationIndex(st.xy); + uint retval = 0; + + if(st.facilities & FACIL_TRAIN) + { + retval += GetNumScheduledVehiclesForStation(stationIdx, VEH_TRAIN); + } + if(st.facilities & (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) + { + retval += GetNumScheduledVehiclesForStation(stationIdx, VEH_ROAD); + } + if(st.facilities & FACIL_AIRPORT) + { + retval += GetNumScheduledVehiclesForStation(stationIdx, VEH_AIRCRAFT); + } + if(st.facilities & FACIL_DOCK) + { + retval += GetNumScheduledVehiclesForStation(stationIdx, VEH_SHIP); + } + + return retval; +} + typedef GUIList GUIStationList; /** @@ -286,6 +337,14 @@ return -(minr1 - minr2); } + /** Sort stations by the number of their occurences in vehicles' schedules. */ + static int CDECL StationVehicleUseSorter(const Station * const *a, const Station * const *b) + { + int veha = GetAllScheduledVehiclesForStation(**a); + int vehb = GetAllScheduledVehiclesForStation(**b); + return veha - vehb; + } + /** Sort the stations list */ void SortStationsList() { @@ -661,7 +720,8 @@ &StationWaitingTotalSorter, &StationWaitingAvailableSorter, &StationRatingMaxSorter, - &StationRatingMinSorter + &StationRatingMinSorter, + &StationVehicleUseSorter }; /* Names of the sorting functions */ @@ -672,6 +732,7 @@ STR_SORT_BY_WAITING_AVAILABLE, STR_SORT_BY_RATING_MAX, STR_SORT_BY_RATING_MIN, + STR_SORT_BY_VEHICLE_USAGE, INVALID_STRING_ID };