diff options
Diffstat (limited to 'src/screenshot.cpp')
-rw-r--r-- | src/screenshot.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 60196cdf0..4a80a0cbf 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -16,6 +16,7 @@ #include "zoom_func.h" #include "core/endian_func.hpp" #include "saveload/saveload.h" +#include "company_base.h" #include "company_func.h" #include "strings_func.h" #include "error.h" @@ -66,6 +67,8 @@ struct ScreenshotFormat { ScreenshotHandlerProc *proc; ///< Function for writing the screenshot. }; +#define MKCOLOUR(x) TO_LE32X(x) + /************************************************* **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) *************************************************/ @@ -842,6 +845,10 @@ bool MakeScreenshot(ScreenshotType t, const char *name) break; } + case SC_MINIMAP: + ret = MakeMinimapWorldScreenshot(); + break; + default: NOT_REACHED(); } @@ -855,3 +862,79 @@ bool MakeScreenshot(ScreenshotType t, const char *name) return ret; } + + +/** + * Return the owner of a tile to display it with in the small map in mode "Owner". + * + * @param tile The tile of which we would like to get the colour. + * @return The owner of tile in the small map in mode "Owner" + */ +static Owner GetMinimapOwner(TileIndex tile) +{ + Owner o; + + if (IsTileType(tile, MP_VOID)) { + return OWNER_END; + } else { + switch (GetTileType(tile)) { + case MP_INDUSTRY: o = OWNER_DEITY; 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 o; + } +} + +static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) +{ + uint32 *ubuf; + uint num, row, col; + byte val; + byte owner_colours[OWNER_END + 1]; + + /* Fill with the company colours */ + for (const Company *c : Company::Iterate()) { + owner_colours[c->index] = MKCOLOUR(_colour_gradient[c->colour][5]); + } + + /* Fill with some special colours */ + owner_colours[OWNER_TOWN] = PC_DARK_RED; + owner_colours[OWNER_NONE] = PC_GRASS_LAND; + owner_colours[OWNER_WATER] = PC_WATER; + owner_colours[OWNER_DEITY] = PC_DARK_GREY; // industry + owner_colours[OWNER_END] = PC_BLACK; + + ubuf = (uint32 *)buf; + num = (pitch * n); + for (uint i = 0; i < num; i++) { + row = y + (int)(i / pitch); + col = (MapSizeX() - 1) - (i % pitch); + + TileIndex tile = TileXY(col, row); + Owner o = GetMinimapOwner(tile); + val = owner_colours[o]; + + uint32 colour_buf = 0; + colour_buf = (_cur_palette.palette[val].b << 0); + colour_buf |= (_cur_palette.palette[val].g << 8); + colour_buf |= (_cur_palette.palette[val].r << 16); + + *ubuf = colour_buf; + *ubuf++; // Skip alpha + } +} + +/** + * Make a minimap screenshot. + */ +bool MakeMinimapWorldScreenshot() +{ + const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; + return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette); +} |