From 526b2ae81bddba5812738eec477f861fcbfb19f1 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 22 Jun 2007 20:06:59 +0000 Subject: [PATCH] (svn r10277) [0.5] -Backport from trunk (10116, r10128, r10130, r10131, r10137, r10138): - Feature: console command to get the current game date (r10137) - Fix: When you got a sufficiently small resolution, there is a possibility for a division by zero when a sound is played (r10138) - Fix: When removing a dock, a ship will always try to reach the old location of the dock even when it cannot anymore because it the old location of the dock is now land instead of water [FS#810] (r10131) - Fix: SetCurrentGrfLangID returned the wrong language ids for most languages (r10130) --- console_cmds.c | 15 +++++++++++++++ fileio.c | 17 +++++++++++++++++ fileio.h | 1 + misc_gui.c | 2 ++ newgrf.c | 1 + newgrf_text.c | 2 +- screenshot.c | 2 ++ ship_cmd.c | 5 ++++- sound.c | 2 +- 9 files changed, 44 insertions(+), 3 deletions(-) diff --git a/console_cmds.c b/console_cmds.c index ce5a203b1a..f6579f7f51 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -928,6 +928,20 @@ DEF_CONSOLE_CMD(ConGetSeed) return true; } +DEF_CONSOLE_CMD(ConGetDate) +{ + YearMonthDay ymd; + if (argc == 0) { + IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'"); + return true; + } + + ConvertDateToYMD(_date, &ymd); + IConsolePrintF(_icolour_def, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year); + return true; +} + + DEF_CONSOLE_CMD(ConAlias) { IConsoleAlias *alias; @@ -1484,6 +1498,7 @@ void IConsoleStdLibRegister(void) IConsoleCmdRegister("newgame", ConNewGame); IConsoleCmdRegister("restart", ConRestart); IConsoleCmdRegister("getseed", ConGetSeed); + IConsoleCmdRegister("getdate", ConGetDate); IConsoleCmdRegister("quit", ConExit); IConsoleCmdRegister("resetengines", ConResetEngines); IConsoleCmdRegister("return", ConReturn); diff --git a/fileio.c b/fileio.c index 2a09916ea3..202f3249b6 100644 --- a/fileio.c +++ b/fileio.c @@ -149,3 +149,20 @@ void FioOpenFile(int slot, const char *filename) _fio.handles[slot] = f; FioSeekToFile(slot << 24); } + +/** + * Sanitizes a filename, i.e. removes all illegal characters from it. + * @param filename the "\0" terminated filename + */ +void SanitizeFilename(char *filename) +{ + for (; *filename != '\0'; filename++) { + switch (*filename) { + /* The following characters are not allowed in filenames + * on at least one of the supported operating systems: */ + case ':': case '\\': case '*': case '?': case '/': case '<': case '>': case '|': case '"': + *filename = '_'; + break; + } + } +} diff --git a/fileio.h b/fileio.h index 6ee58b32c3..a925aa95fa 100644 --- a/fileio.h +++ b/fileio.h @@ -15,5 +15,6 @@ void FioOpenFile(int slot, const char *filename); void FioReadBlock(void *ptr, uint size); void FioSkipBytes(int n); bool FioCheckFileExists(const char *filename); +void SanitizeFilename(char *filename); #endif /* FILEIO_H */ diff --git a/misc_gui.c b/misc_gui.c index 5a93e1b63b..4df7333fcb 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -30,6 +30,7 @@ #include "tgp.h" #include "settings.h" #include "date.h" +#include "fileio.h" #include "fios.h" /* Variables to display file lists */ @@ -1337,6 +1338,7 @@ static void GenerateFileName(void) SetDParam(1, p->name_2); SetDParam(2, _date); GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf)); + SanitizeFilename(_edit_str_buf); } extern void StartupEngines(void); diff --git a/newgrf.c b/newgrf.c index d94a1a7345..5a6599efa8 100644 --- a/newgrf.c +++ b/newgrf.c @@ -1626,6 +1626,7 @@ static const SpriteGroup* CreateGroupFromGroupID(byte feature, byte setid, byte if (feature != _cur_grffile->spriteset_feature) { grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping.", + setid, type, _cur_grffile->spriteset_feature, feature); return NULL; } diff --git a/newgrf_text.c b/newgrf_text.c index e21a66bd72..caeed8116a 100644 --- a/newgrf_text.c +++ b/newgrf_text.c @@ -404,7 +404,7 @@ void SetCurrentGrfLangID(const char *iso_name) for (i=0; i < lengthof(iso_codes); i++) { if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code)) == 0) { /* We found a match, so let's use it. */ - ret = i; + ret = iso_codes[i].grfLangID; break; } } diff --git a/screenshot.c b/screenshot.c index 503c78a5c0..8428c7cac4 100644 --- a/screenshot.c +++ b/screenshot.c @@ -13,6 +13,7 @@ #include "screenshot.h" #include "variables.h" #include "date.h" +#include "fileio.h" char _screenshot_format_name[8]; uint _num_screenshot_formats; @@ -507,6 +508,7 @@ static char *MakeScreenshotName(const char *ext) GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); } + SanitizeFilename(_screenshot_name); base = strchr(_screenshot_name, 0); base[0] = '.'; strcpy(base + 1, ext); diff --git a/ship_cmd.c b/ship_cmd.c index 0f361b54d3..f05ca58dad 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -239,7 +239,8 @@ static void ProcessShipOrder(Vehicle *v) if (order->type == v->current_order.type && order->flags == v->current_order.flags && - order->dest == v->current_order.dest) + order->dest == v->current_order.dest && + (order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0)) return; v->current_order = *order; @@ -253,6 +254,8 @@ static void ProcessShipOrder(Vehicle *v) st = GetStation(order->dest); if (st->dock_tile != 0) { v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile))); + } else { + v->cur_order_index++; } } else if (order->type == OT_GOTO_DEPOT) { v->dest_tile = GetDepot(order->dest)->xy; diff --git a/sound.c b/sound.c index 7e78b07dd6..e4666a1f51 100644 --- a/sound.c +++ b/sound.c @@ -208,7 +208,7 @@ static void SndPlayScreenCoordFx(SoundFx sound, int x, int y) StartSound( sound, - left / (vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, + left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, (GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15 ); return;