# HG changeset patch # User rubidium # Date 1182542819 0 # Node ID fee376b814473f7854b4adf6a9b65b1e69f8a097 # Parent d4b8e7933d5e955ba40bb7966aeec86c800b4c8e (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) diff -r d4b8e7933d5e -r fee376b81447 console_cmds.c --- a/console_cmds.c Fri Jun 22 20:04:18 2007 +0000 +++ b/console_cmds.c Fri Jun 22 20:06:59 2007 +0000 @@ -928,6 +928,20 @@ 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 @@ IConsoleCmdRegister("newgame", ConNewGame); IConsoleCmdRegister("restart", ConRestart); IConsoleCmdRegister("getseed", ConGetSeed); + IConsoleCmdRegister("getdate", ConGetDate); IConsoleCmdRegister("quit", ConExit); IConsoleCmdRegister("resetengines", ConResetEngines); IConsoleCmdRegister("return", ConReturn); diff -r d4b8e7933d5e -r fee376b81447 fileio.c --- a/fileio.c Fri Jun 22 20:04:18 2007 +0000 +++ b/fileio.c Fri Jun 22 20:06:59 2007 +0000 @@ -149,3 +149,20 @@ _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 -r d4b8e7933d5e -r fee376b81447 fileio.h --- a/fileio.h Fri Jun 22 20:04:18 2007 +0000 +++ b/fileio.h Fri Jun 22 20:06:59 2007 +0000 @@ -15,5 +15,6 @@ void FioReadBlock(void *ptr, uint size); void FioSkipBytes(int n); bool FioCheckFileExists(const char *filename); +void SanitizeFilename(char *filename); #endif /* FILEIO_H */ diff -r d4b8e7933d5e -r fee376b81447 misc_gui.c --- a/misc_gui.c Fri Jun 22 20:04:18 2007 +0000 +++ b/misc_gui.c Fri Jun 22 20:06:59 2007 +0000 @@ -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 @@ 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 -r d4b8e7933d5e -r fee376b81447 newgrf.c --- a/newgrf.c Fri Jun 22 20:04:18 2007 +0000 +++ b/newgrf.c Fri Jun 22 20:06:59 2007 +0000 @@ -1626,6 +1626,7 @@ 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 -r d4b8e7933d5e -r fee376b81447 newgrf_text.c --- a/newgrf_text.c Fri Jun 22 20:04:18 2007 +0000 +++ b/newgrf_text.c Fri Jun 22 20:06:59 2007 +0000 @@ -404,7 +404,7 @@ 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 -r d4b8e7933d5e -r fee376b81447 screenshot.c --- a/screenshot.c Fri Jun 22 20:04:18 2007 +0000 +++ b/screenshot.c Fri Jun 22 20:06:59 2007 +0000 @@ -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 @@ GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); } + SanitizeFilename(_screenshot_name); base = strchr(_screenshot_name, 0); base[0] = '.'; strcpy(base + 1, ext); diff -r d4b8e7933d5e -r fee376b81447 ship_cmd.c --- a/ship_cmd.c Fri Jun 22 20:04:18 2007 +0000 +++ b/ship_cmd.c Fri Jun 22 20:06:59 2007 +0000 @@ -239,7 +239,8 @@ 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 @@ 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 -r d4b8e7933d5e -r fee376b81447 sound.c --- a/sound.c Fri Jun 22 20:04:18 2007 +0000 +++ b/sound.c Fri Jun 22 20:06:59 2007 +0000 @@ -208,7 +208,7 @@ 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;