diff --git a/fios.c b/fios.c index fb54c0ce9d..0ff535f717 100644 --- a/fios.c +++ b/fios.c @@ -32,6 +32,7 @@ static int _fios_count, _fios_alloc; /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */ extern bool FiosIsRoot(const char *path); extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); +extern bool FiosIsHiddenFile(const struct dirent *ent); extern void FiosGetDrives(void); extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot); @@ -218,7 +219,8 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_ /* found file must be directory, but not '.' or '..' */ if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) && - strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) { + (!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) && + strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) { fios = FiosAlloc(); fios->type = FIOS_TYPE_DIR; fios->mtime = 0; @@ -250,7 +252,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_ byte type; ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name)); - if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue; + if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue; /* File has no extension, skip it */ if ((t = strrchr(d_name, '.')) == NULL) continue; diff --git a/os2.c b/os2.c index 88ca2fddf6..7443e68963 100644 --- a/os2.c +++ b/os2.c @@ -114,11 +114,15 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb char filename[MAX_PATH]; snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); - if (stat(filename, sb) != 0) return false; - - return (ent->d_name[0] != '.'); // hidden file + return stat(filename, sb) == 0; } +bool FiosIsHiddenFile(const struct dirent *ent) +{ + return ent->d_name[0] == '.'; +} + + static void ChangeWorkingDirectory(char *exe) { char *s = strrchr(exe, PATHSEPCHAR); diff --git a/settings_gui.c b/settings_gui.c index f9efc264d5..969334c388 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -823,8 +823,8 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min; } - /* Set up scroller timeout */ - if (value != oldvalue) { + /* Set up scroller timeout for numeric values */ + if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) { WP(w,def_d).data_2 = btn * 2 + 1 + ((x >= 10) ? 1 : 0); w->flags4 |= 5 << WF_TIMEOUT_SHL; _left_button_clicked = false; diff --git a/station.h b/station.h index affd7abe40..36be0bc307 100644 --- a/station.h +++ b/station.h @@ -27,6 +27,7 @@ typedef enum RoadStopType { enum { INVALID_STATION = 0xFFFF, + INITIAL_STATION_RATING = 175, ROAD_STOP_LIMIT = 16, }; diff --git a/station_cmd.c b/station_cmd.c index 31248e123f..2201e61f96 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -467,7 +467,7 @@ static void StationInitialize(Station *st, TileIndex tile) ge->waiting_acceptance = 0; ge->days_since_pickup = 0; ge->enroute_from = INVALID_STATION; - ge->rating = 175; + ge->rating = INITIAL_STATION_RATING; ge->last_speed = 0; ge->last_age = 0xFF; ge->feeder_profit = 0; @@ -2473,6 +2473,12 @@ static void UpdateStationRating(Station *st) ge = st->goods; do { + /* Slowly increase the rating back to his original level in the case we + * didn't deliver cargo yet to this station. This happens when a bribe + * failed while you didn't moved that cargo yet to a station. */ + if (ge->enroute_from == INVALID_STATION && ge->rating < INITIAL_STATION_RATING) + ge->rating++; + /* Only change the rating if we are moving this cargo */ if (ge->enroute_from != INVALID_STATION) { byte_inc_sat(&ge->enroute_time); byte_inc_sat(&ge->days_since_pickup); @@ -2832,7 +2838,7 @@ void BuildOilRig(TileIndex tile) st->goods[j].waiting_acceptance = 0; st->goods[j].days_since_pickup = 0; st->goods[j].enroute_from = INVALID_STATION; - st->goods[j].rating = 175; + st->goods[j].rating = INITIAL_STATION_RATING; st->goods[j].last_speed = 0; st->goods[j].last_age = 255; } diff --git a/station_gui.c b/station_gui.c index 0139d73c11..4f8a861951 100644 --- a/station_gui.c +++ b/station_gui.c @@ -134,6 +134,14 @@ static int CDECL StationWaitingSorter(const void *a, const void *b) return (_internal_sort_order & 1) ? sum2 - sum1 : sum1 - sum2; } +/** + * qsort-compatible version of sorting two stations by maximum rating + * @param a First object to be sorted, must be of type (const Station *) + * @param b Second object to be sorted, must be of type (const Station *) + * @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; @@ -143,8 +151,8 @@ static int CDECL StationRatingMaxSorter(const void *a, const void *b) int j; for (j = 0; j < NUM_CARGO; j++) { - if (st1->goods[j].waiting_acceptance & 0xfff) maxr1 = max(maxr1, st1->goods[j].rating); - if (st2->goods[j].waiting_acceptance & 0xfff) maxr2 = max(maxr2, st2->goods[j].rating); + if (st1->goods[j].enroute_from != INVALID_STATION) maxr1 = max(maxr1, st1->goods[j].rating); + if (st2->goods[j].enroute_from != INVALID_STATION) maxr2 = max(maxr2, st2->goods[j].rating); } return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; diff --git a/unix.c b/unix.c index c4ba502432..acfbcbbcfa 100644 --- a/unix.c +++ b/unix.c @@ -92,9 +92,12 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb #endif snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); - if (stat(filename, sb) != 0) return false; + return stat(filename, sb) == 0; +} - return (ent->d_name[0] != '.'); // hidden file +bool FiosIsHiddenFile(const struct dirent *ent) +{ + return ent->d_name[0] == '.'; } #if defined(__BEOS__) || defined(__linux__) diff --git a/win32.c b/win32.c index a0160da033..bf4ec84577 100644 --- a/win32.c +++ b/win32.c @@ -743,7 +743,6 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb // hectonanoseconds between Windows and POSIX epoch static const int64 posix_epoch_hns = 0x019DB1DED53E8000LL; const WIN32_FIND_DATAW *fd = &ent->dir->fd; - if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false; sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow; /* UTC FILETIME to seconds-since-1970 UTC @@ -757,6 +756,11 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb return true; } +bool FiosIsHiddenFile(const struct dirent *ent) +{ + return (ent->dir->fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0; +} + bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) { UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box