From 019e8625360880c7fa62088c5a37efb3867db0fe Mon Sep 17 00:00:00 2001 From: patch-import Date: Fri, 11 Sep 2015 03:31:21 +0100 Subject: [PATCH 1/2] Import minimap patch. Fix various compilation issues and update to current trunk. http://www.tt-forums.net/viewtopic.php?p=848661#p848661 --- src/console_cmds.cpp | 8 +++++ src/screenshot.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 8d9e04113d..cc8321ed0e 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -49,6 +49,7 @@ static bool _script_running; ///< Script is running (used to abort execution whe #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[]) #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo) +void SaveMinimap(); /**************** * command hooks @@ -1390,6 +1391,12 @@ DEF_CONSOLE_CMD(ConScreenShot) return true; } +DEF_CONSOLE_CMD(ConMinimap) +{ + SaveMinimap(); + return true; +} + DEF_CONSOLE_CMD(ConInfoCmd) { if (argc == 0) { @@ -1920,6 +1927,7 @@ void IConsoleStdLibRegister() IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork); IConsoleCmdRegister("return", ConReturn); IConsoleCmdRegister("screenshot", ConScreenShot); + IConsoleCmdRegister("minimap", ConMinimap); IConsoleCmdRegister("script", ConScript); IConsoleCmdRegister("scrollto", ConScrollToTile); IConsoleCmdRegister("alias", ConAlias); diff --git a/src/screenshot.cpp b/src/screenshot.cpp index a24cc6b211..3def9b679a 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -68,6 +68,8 @@ struct ScreenshotFormat { ScreenshotHandlerProc *proc; ///< Function for writing the screenshot. }; +#define MKCOLOUR(x) TO_LE32X(x) + /************************************************* **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) *************************************************/ @@ -865,3 +867,80 @@ bool MakeScreenshot(ScreenshotType t, const char *name) return ret; } + +static byte _owner_colours[OWNER_END + 1]; + +/** + * Return the colour a tile would be displayed with in the small map in mode "Owner". + * + * @param tile The tile of which we would like to get the colour. + * @return The colour of tile in the small map in mode "Owner" + */ +static inline byte GetMinimapOwnerPixels(TileIndex tile) +{ + Owner o; + + switch (GetTileType(tile)) { + case MP_INDUSTRY: o = OWNER_END; break; + case MP_HOUSE: o = OWNER_TOWN; break; + default: o = GetTileOwner(tile); break; + /* FIXME: For MP_ROAD there are multiple owners. + * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road), + * even if there are no ROADTYPE_ROAD bits on the tile. + */ + } + + return _owner_colours[o]; +} + +static void MinimapOwnerCallback(void *userdata, void *buf, uint y, uint pitch, uint n) +{ + uint8 *ubuf = (uint8 *)buf; + + uint num = (pitch * n); + uint row, col; + byte val; + + for (uint i=0; i < num; i++) { + row = y + (int) (i / pitch); + col = (MapSizeX()-1) - (i % pitch); + + TileIndex tile = TileXY(col, row); + + if (IsTileType(tile, MP_VOID)) { + val = 0x00; + } else { + val = GetMinimapOwnerPixels(tile); + } + + *ubuf = (uint8) _cur_palette.palette[val].b; + ubuf += sizeof(uint8); *ubuf = (uint8) _cur_palette.palette[val].g; + ubuf += sizeof(uint8); *ubuf = (uint8) _cur_palette.palette[val].r; + ubuf += sizeof(uint8); + ubuf += sizeof(uint8); + } +} + +/** + * Saves the complete savemap in a PNG-file. + */ +void SaveMinimap() +{ + /* setup owner table */ + const Company *c; + + /* fill with some special colours */ + _owner_colours[OWNER_TOWN] = MKCOLOUR(0xB4); + _owner_colours[OWNER_NONE] = MKCOLOUR(0x54); + _owner_colours[OWNER_WATER] = MKCOLOUR(0xCA); + _owner_colours[OWNER_END] = MKCOLOUR(0x20); // industry + + /* now fill with the company colours */ + FOR_ALL_COMPANIES(c) { + _owner_colours[c->index] = + _colour_gradient[c->colour][5] * 0x01010101; + } + + const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; + sf->proc(MakeScreenshotName("minimap", sf->extension), MinimapOwnerCallback, NULL, MapSizeX(), MapSizeY(), 32, _cur_palette.palette); +} From dde1c1610579c8b11d64a803da50aa498161fea6 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 11 Sep 2015 03:44:25 +0100 Subject: [PATCH 2/2] Minimap screenshot: add console params and help to mostly match screenshot. --- src/console_cmds.cpp | 21 ++++++++++++++++++--- src/screenshot.cpp | 5 ++++- src/screenshot.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index cc8321ed0e..7f38455504 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -49,8 +49,6 @@ static bool _script_running; ///< Script is running (used to abort execution whe #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[]) #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo) -void SaveMinimap(); - /**************** * command hooks ****************/ @@ -1393,7 +1391,24 @@ DEF_CONSOLE_CMD(ConScreenShot) DEF_CONSOLE_CMD(ConMinimap) { - SaveMinimap(); + if (argc == 0) { + IConsoleHelp("Create a flat image of the game minimap. Usage: 'minimap [owner] [file name]'"); + IConsoleHelp("'owner' uses the tile owner to colour the minimap image, this is the only mode at present"); + return true; + } + + const char *name = NULL; + if (argc > 1) { + if (strcmp(argv[1], "owner") != 0) { + /* invalid mode */ + return false; + } + } + if (argc > 2) { + name = argv[2]; + } + + SaveMinimap(name); return true; } diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 3def9b679a..62705bd23e 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -924,7 +924,7 @@ static void MinimapOwnerCallback(void *userdata, void *buf, uint y, uint pitch, /** * Saves the complete savemap in a PNG-file. */ -void SaveMinimap() +void SaveMinimap(const char *name) { /* setup owner table */ const Company *c; @@ -941,6 +941,9 @@ void SaveMinimap() _colour_gradient[c->colour][5] * 0x01010101; } + _screenshot_name[0] = '\0'; + if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name)); + const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; sf->proc(MakeScreenshotName("minimap", sf->extension), MinimapOwnerCallback, NULL, MapSizeX(), MapSizeY(), 32, _cur_palette.palette); } diff --git a/src/screenshot.h b/src/screenshot.h index ee03d8aff7..a17c5cac8c 100644 --- a/src/screenshot.h +++ b/src/screenshot.h @@ -29,6 +29,7 @@ enum ScreenshotType { void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp); bool MakeHeightmapScreenshot(const char *filename); bool MakeScreenshot(ScreenshotType t, const char *name); +void SaveMinimap(const char *name); extern char _screenshot_format_name[8]; extern uint _num_screenshot_formats;