|
@@ -91,49 +91,48 @@ const StringID _station_sort_listing[] =
|
|
|
STR_SORT_BY_WAITING,
|
|
|
STR_SORT_BY_RATING_MAX,
|
|
|
INVALID_STRING_ID
|
|
|
};
|
|
|
|
|
|
static char _bufcache[64];
|
|
|
static const Station* _last_station;
|
|
|
static const Station *_last_station;
|
|
|
static int _internal_sort_order;
|
|
|
|
|
|
static int CDECL StationNameSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
const Station* st2 = *(const Station**)b;
|
|
|
const Station *st1 = *(const Station**)a;
|
|
|
const Station *st2 = *(const Station**)b;
|
|
|
char buf1[64];
|
|
|
int r;
|
|
|
|
|
|
SetDParam(0, st1->index);
|
|
|
GetString(buf1, STR_STATION, lastof(buf1));
|
|
|
|
|
|
if (st2 != _last_station) {
|
|
|
_last_station = st2;
|
|
|
SetDParam(0, st2->index);
|
|
|
GetString(_bufcache, STR_STATION, lastof(_bufcache));
|
|
|
}
|
|
|
|
|
|
r = strcmp(buf1, _bufcache); // sort by name
|
|
|
int r = strcmp(buf1, _bufcache); // sort by name
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
}
|
|
|
|
|
|
static int CDECL StationTypeSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
const Station* st2 = *(const Station**)b;
|
|
|
const Station *st1 = *(const Station**)a;
|
|
|
const Station *st2 = *(const Station**)b;
|
|
|
return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
|
|
|
}
|
|
|
|
|
|
static const uint32 _cargo_filter_max = ~0;
|
|
|
static const uint32 _cargo_filter_max = UINT32_MAX;
|
|
|
static uint32 _cargo_filter = _cargo_filter_max;
|
|
|
|
|
|
static int CDECL StationWaitingSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
const Station* st2 = *(const Station**)b;
|
|
|
const Station *st1 = *(const Station**)a;
|
|
|
const Station *st2 = *(const Station**)b;
|
|
|
Money sum1 = 0, sum2 = 0;
|
|
|
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
|
|
if (!HasBit(_cargo_filter, j)) continue;
|
|
|
if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
|
|
|
if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
|
|
@@ -149,14 +148,14 @@ static int CDECL StationWaitingSorter(co
|
|
|
* @return The sort order
|
|
|
* @retval >0 a should come before b in the list
|
|
|
* @retval <0 b should come before a in the list
|
|
|
*/
|
|
|
static int CDECL StationRatingMaxSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
const Station* st2 = *(const Station**)b;
|
|
|
const Station *st1 = *(const Station**)a;
|
|
|
const Station *st2 = *(const Station**)b;
|
|
|
byte maxr1 = 0;
|
|
|
byte maxr2 = 0;
|
|
|
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
|
|
if (HasBit(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating);
|
|
|
if (HasBit(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating);
|
|
@@ -173,26 +172,26 @@ enum StationListFlags {
|
|
|
};
|
|
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(StationListFlags);
|
|
|
|
|
|
/** Information about station list */
|
|
|
struct plstations_d {
|
|
|
const Station** sort_list; ///< Pointer to list of stations
|
|
|
const Station **sort_list; ///< Pointer to list of stations
|
|
|
uint16 list_length; ///< Number of stations in list
|
|
|
uint16 resort_timer; ///< Tick counter to resort the list
|
|
|
byte sort_type; ///< Sort type - name, waiting, ...
|
|
|
byte flags; ///< Flags - SL_ORDER, SL_RESORT, SL_REBUILD
|
|
|
};
|
|
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
|
|
|
|
|
|
/**
|
|
|
* Set the 'SL_REBUILD' flag for all station lists
|
|
|
*/
|
|
|
void RebuildStationLists()
|
|
|
{
|
|
|
Window* const *wz;
|
|
|
Window *const *wz;
|
|
|
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
Window *w = *wz;
|
|
|
if (w->window_class == WC_STATION_LIST) {
|
|
|
WP(w, plstations_d).flags |= SL_REBUILD;
|
|
|
SetWindowDirty(w);
|
|
@@ -202,13 +201,13 @@ void RebuildStationLists()
|
|
|
|
|
|
/**
|
|
|
* Set the 'SL_RESORT' flag for all station lists
|
|
|
*/
|
|
|
void ResortStationLists()
|
|
|
{
|
|
|
Window* const *wz;
|
|
|
Window *const *wz;
|
|
|
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
Window *w = *wz;
|
|
|
if (w->window_class == WC_STATION_LIST) {
|
|
|
WP(w, plstations_d).flags |= SL_RESORT;
|
|
|
SetWindowDirty(w);
|
|
@@ -222,21 +221,21 @@ void ResortStationLists()
|
|
|
* @param sl pointer to plstations_d (station list and flags)
|
|
|
* @param owner player whose stations are to be in list
|
|
|
* @param facilities types of stations of interest
|
|
|
* @param cargo_filter bitmap of cargo types to include
|
|
|
* @param include_empty whether we should include stations without waiting cargo
|
|
|
*/
|
|
|
static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
|
|
|
static void BuildStationsList(plstations_d *sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
|
|
|
{
|
|
|
uint n = 0;
|
|
|
const Station *st;
|
|
|
|
|
|
if (!(sl->flags & SL_REBUILD)) return;
|
|
|
|
|
|
/* Create array for sorting */
|
|
|
const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
|
|
|
const Station **station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
|
|
|
|
|
|
DEBUG(misc, 3, "Building station list for player %d", owner);
|
|
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
|
|
|
if (facilities & st->facilities) { //only stations with selected facilities
|
|
@@ -274,13 +273,13 @@ static void BuildStationsList(plstations
|
|
|
* Sort station list if the SL_RESORT flag is set
|
|
|
*
|
|
|
* @param sl pointer to plstations_d (station list and flags)
|
|
|
*/
|
|
|
static void SortStationsList(plstations_d *sl)
|
|
|
{
|
|
|
static StationSortListingTypeFunction* const _station_sorter[] = {
|
|
|
static StationSortListingTypeFunction *const _station_sorter[] = {
|
|
|
&StationNameSorter,
|
|
|
&StationTypeSorter,
|
|
|
&StationWaitingSorter,
|
|
|
&StationRatingMaxSorter
|
|
|
};
|
|
|
|
|
@@ -746,16 +745,13 @@ typedef std::list<CargoData> CargoDataLi
|
|
|
*
|
|
|
* @param w pointer to window
|
|
|
*/
|
|
|
static void DrawStationViewWindow(Window *w)
|
|
|
{
|
|
|
StationID station_id = w->window_number;
|
|
|
const Station* st = GetStation(station_id);
|
|
|
int x, y; ///< coordinates used for printing waiting/accepted/rating of cargo
|
|
|
int pos; ///< = w->vscroll.pos
|
|
|
StringID str;
|
|
|
const Station *st = GetStation(station_id);
|
|
|
CargoDataList cargolist;
|
|
|
uint32 transfers = 0;
|
|
|
|
|
|
/* count types of cargos waiting in station */
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
|
|
if (st->goods[i].cargo.Empty()) {
|
|
@@ -805,19 +801,21 @@ static void DrawStationViewWindow(Window
|
|
|
w->SetWidgetDisabledState(SVW_SHIPS, !(st->facilities & FACIL_DOCK));
|
|
|
|
|
|
SetDParam(0, st->index);
|
|
|
SetDParam(1, st->facilities);
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
x = 2;
|
|
|
y = 15;
|
|
|
pos = w->vscroll.pos;
|
|
|
int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
|
|
|
int y = 15;
|
|
|
int pos = w->vscroll.pos; ///< = w->vscroll.pos
|
|
|
|
|
|
uint width = w->widget[SVW_WAITING].right - w->widget[SVW_WAITING].left - 4;
|
|
|
int maxrows = w->vscroll.cap;
|
|
|
|
|
|
StringID str;
|
|
|
|
|
|
if (--pos < 0) {
|
|
|
str = STR_00D0_NOTHING;
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
|
|
if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
|
|
|
}
|
|
|
SetDParam(0, str);
|