/* $Id$ */ /** @file smallmap_gui.cpp GUI that shows a small map of the world with metadata like owner or height. */ #include "stdafx.h" #include "clear_map.h" #include "industry_map.h" #include "station_map.h" #include "landscape.h" #include "window_gui.h" #include "tree_map.h" #include "viewport_func.h" #include "gfx_func.h" #include "town.h" #include "blitter/factory.hpp" #include "tunnelbridge_map.h" #include "strings_func.h" #include "zoom_func.h" #include "core/endian_func.hpp" #include "vehicle_base.h" #include "sound_func.h" #include "window_func.h" #include "table/strings.h" #include "table/sprites.h" /** Widget numbers of the small map window. */ enum SmallMapWindowWidgets { SM_WIDGET_CLOSEBOX, SM_WIDGET_CAPTION, SM_WIDGET_STICKYBOX, SM_WIDGET_MAP_BORDER, SM_WIDGET_MAP, SM_WIDGET_LEGEND, SM_WIDGET_BUTTONSPANEL, SM_WIDGET_CONTOUR, SM_WIDGET_VEHICLES, SM_WIDGET_INDUSTRIES, SM_WIDGET_ROUTES, SM_WIDGET_VEGETATION, SM_WIDGET_OWNERS, SM_WIDGET_CENTERMAP, SM_WIDGET_TOGGLETOWNNAME, SM_WIDGET_BOTTOMPANEL, SM_WIDGET_ENABLEINDUSTRIES, SM_WIDGET_DISABLEINDUSTRIES, SM_WIDGET_RESIZEBOX, }; static const Widget _smallmap_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // SM_WIDGET_CLOSEBOX { WWT_CAPTION, RESIZE_RIGHT, COLOUR_BROWN, 11, 337, 0, 13, STR_SMALLMAP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // SM_WIDGET_CAPTION { WWT_STICKYBOX, RESIZE_LR, COLOUR_BROWN, 338, 349, 0, 13, 0x0, STR_TOOLTIP_STICKY}, // SM_WIDGET_STICKYBOX { WWT_PANEL, RESIZE_RB, COLOUR_BROWN, 0, 349, 14, 157, 0x0, STR_NULL}, // SM_WIDGET_MAP_BORDER { WWT_INSET, RESIZE_RB, COLOUR_BROWN, 2, 347, 16, 155, 0x0, STR_NULL}, // SM_WIDGET_MAP { WWT_PANEL, RESIZE_RTB, COLOUR_BROWN, 0, 261, 158, 201, 0x0, STR_NULL}, // SM_WIDGET_LEGEND { WWT_PANEL, RESIZE_LRTB, COLOUR_BROWN, 262, 349, 158, 158, 0x0, STR_NULL}, // SM_WIDGET_BUTTONSPANEL { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 284, 305, 158, 179, SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP}, // SM_WIDGET_CONTOUR { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 306, 327, 158, 179, SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP}, // SM_WIDGET_VEHICLES { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 328, 349, 158, 179, SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP}, // SM_WIDGET_INDUSTRIES { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 284, 305, 180, 201, SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON}, // SM_WIDGET_ROUTES { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 306, 327, 180, 201, SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP}, // SM_WIDGET_VEGETATION { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 328, 349, 180, 201, SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP}, // SM_WIDGET_OWNERS { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 262, 283, 158, 179, SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER}, // SM_WIDGET_CENTERMAP { WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 262, 283, 180, 201, SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF}, // SM_WIDGET_TOGGLETOWNNAME { WWT_PANEL, RESIZE_RTB, COLOUR_BROWN, 0, 337, 202, 213, 0x0, STR_NULL}, // SM_WIDGET_BOTTOMPANEL { WWT_TEXTBTN, RESIZE_TB, COLOUR_BROWN, 0, 99, 202, 213, STR_SMALLMAP_ENABLE_ALL, STR_NULL}, // SM_WIDGET_ENABLEINDUSTRIES { WWT_TEXTBTN, RESIZE_TB, COLOUR_BROWN, 100, 201, 202, 213, STR_SMALLMAP_DISABLE_ALL, STR_NULL}, // SM_WIDGET_DISABLEINDUSTRIES { WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_BROWN, 338, 349, 202, 213, 0x0, STR_TOOLTIP_RESIZE}, // SM_WIDGET_RESIZEBOX { WIDGETS_END}, }; /* Todo: Stacked panel (SM_WIDGET_BUTTONSPANEL) is used to allow vertical growth of SM_WIDGET_LEGEND. As such, its proper place is above both button * rows, have 0 height, and allow vertical resizing. * However, #ResizeWindowForWidget freaks out in that case. As it does not seem easy to fix, the problem is parked until later. */ static const NWidgetPart _nested_smallmap_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_BROWN, SM_WIDGET_CLOSEBOX), NWidget(WWT_CAPTION, COLOUR_BROWN, SM_WIDGET_CAPTION), SetDataTip(STR_SMALLMAP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), NWidget(WWT_STICKYBOX, COLOUR_BROWN, SM_WIDGET_STICKYBOX), EndContainer(), /* Small map display. */ NWidget(WWT_PANEL, COLOUR_BROWN, SM_WIDGET_MAP_BORDER), NWidget(WWT_INSET, COLOUR_BROWN, SM_WIDGET_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), EndContainer(), /* Panel. */ NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_BROWN, SM_WIDGET_LEGEND), SetMinimalSize(262, 44), SetResize(1, 0), EndContainer(), NWidget(NWID_LAYERED), NWidget(NWID_VERTICAL), /* Top button row. */ NWidget(NWID_HORIZONTAL), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_CENTERMAP), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_CONTOUR), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_VEHICLES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_INDUSTRIES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP), EndContainer(), /* Bottom button row. */ NWidget(NWID_HORIZONTAL), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_TOGGLETOWNNAME), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_ROUTES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_VEGETATION), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP), NWidget(WWT_IMGBTN, COLOUR_BROWN, SM_WIDGET_OWNERS), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP), EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), NWidget(WWT_PANEL, COLOUR_BROWN, SM_WIDGET_BUTTONSPANEL), SetMinimalSize(88, 1), SetFill(0, 0), EndContainer(), NWidget(NWID_SPACER), SetFill(0, 1), EndContainer(), EndContainer(), EndContainer(), /* Bottom button row and resize box. */ NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_BROWN, SM_WIDGET_BOTTOMPANEL), NWidget(NWID_HORIZONTAL), NWidget(WWT_TEXTBTN, COLOUR_BROWN, SM_WIDGET_ENABLEINDUSTRIES), SetMinimalSize(100, 12), SetDataTip(STR_SMALLMAP_ENABLE_ALL, STR_NULL), NWidget(WWT_TEXTBTN, COLOUR_BROWN, SM_WIDGET_DISABLEINDUSTRIES), SetMinimalSize(102, 12), SetDataTip(STR_SMALLMAP_DISABLE_ALL, STR_NULL), NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0), EndContainer(), EndContainer(), NWidget(WWT_RESIZEBOX, COLOUR_BROWN, SM_WIDGET_RESIZEBOX), EndContainer(), }; /* number of used industries */ static int _smallmap_industry_count; /** Macro for ordinary entry of LegendAndColour */ #define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, true, false, false} /** Macro for end of list marker in arrays of LegendAndColour */ #define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, true, true, false} /** Macro for break marker in arrays of LegendAndColour. * It will have valid data, though */ #define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, true, false, true} /** Structure for holding relevant data for legends in small map */ struct LegendAndColour { uint16 colour; ///< colour of the item on the map StringID legend; ///< string corresponding to the coloured item IndustryType type; ///< type of industry bool show_on_map; ///< for filtering industries, if true is shown on map in colour bool end; ///< this is the end of the list bool col_break; ///< perform a break and go one collumn further }; /** Legend text giving the colours to look for on the minimap */ static const LegendAndColour _legend_land_contours[] = { MK(0x5A, STR_SMALLMAP_LEGENDA_100M), MK(0x5C, STR_SMALLMAP_LEGENDA_200M), MK(0x5E, STR_SMALLMAP_LEGENDA_300M), MK(0x1F, STR_SMALLMAP_LEGENDA_400M), MK(0x27, STR_SMALLMAP_LEGENDA_500M), MS(0xD7, STR_SMALLMAP_LEGENDA_ROADS), MK(0x0A, STR_SMALLMAP_LEGENDA_RAILROADS), MK(0x98, STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS), MK(0xB5, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES), MK(0x0F, STR_SMALLMAP_LEGENDA_VEHICLES), MKEND() }; static const LegendAndColour _legend_vehicles[] = { MK(0xB8, STR_SMALLMAP_LEGENDA_TRAINS), MK(0xBF, STR_SMALLMAP_LEGENDA_ROAD_VEHICLES), MK(0x98, STR_SMALLMAP_LEGENDA_SHIPS), MK(0x0F, STR_SMALLMAP_LEGENDA_AIRCRAFT), MS(0xD7, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES), MK(0xB5, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES), MKEND() }; static const LegendAndColour _legend_routes[] = { MK(0xD7, STR_SMALLMAP_LEGENDA_ROADS), MK(0x0A, STR_SMALLMAP_LEGENDA_RAILROADS), MK(0xB5, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES), MS(0x56, STR_SMALLMAP_LEGENDA_RAILROAD_STATION), MK(0xC2, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY), MK(0xBF, STR_SMALLMAP_LEGENDA_BUS_STATION), MK(0xB8, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT), MK(0x98, STR_SMALLMAP_LEGENDA_DOCK), MKEND() }; static const LegendAndColour _legend_vegetation[] = { MK(0x52, STR_SMALLMAP_LEGENDA_ROUGH_LAND), MK(0x54, STR_SMALLMAP_LEGENDA_GRASS_LAND), MK(0x37, STR_SMALLMAP_LEGENDA_BARE_LAND), MK(0x25, STR_SMALLMAP_LEGENDA_FIELDS), MK(0x57, STR_SMALLMAP_LEGENDA_TREES), MK(0xD0, STR_SMALLMAP_LEGENDA_FOREST), MS(0x0A, STR_SMALLMAP_LEGENDA_ROCKS), MK(0xC2, STR_SMALLMAP_LEGENDA_DESERT), MK(0x98, STR_SMALLMAP_LEGENDA_SNOW), MK(0xD7, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES), MK(0xB5, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES), MKEND() }; static const LegendAndColour _legend_land_owners[] = { MK(0xCA, STR_SMALLMAP_LEGENDA_WATER), MK(0x54, STR_SMALLMAP_LEGENDA_NO_OWNER), MK(0xB4, STR_SMALLMAP_LEGENDA_TOWNS), MK(0x20, STR_SMALLMAP_LEGENDA_INDUSTRIES), MKEND() }; #undef MK #undef MS #undef MKEND /** Allow room for all industries, plus a terminator entry * This is required in order to have the indutry slots all filled up */ static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1]; /* For connecting industry type to position in industries list(small map legend) */ static uint _industry_to_list_pos[NUM_INDUSTRYTYPES]; /** * Fills an array for the industries legends. */ void BuildIndustriesLegend() { uint j = 0; /* Add each name */ for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { const IndustrySpec *indsp = GetIndustrySpec(i); if (indsp->enabled) { _legend_from_industries[j].legend = indsp->name; _legend_from_industries[j].colour = indsp->map_colour; _legend_from_industries[j].type = i; _legend_from_industries[j].show_on_map = true; _legend_from_industries[j].col_break = false; _legend_from_industries[j].end = false; /* Store widget number for this industry type */ _industry_to_list_pos[i] = j; j++; } } /* Terminate the list */ _legend_from_industries[j].end = true; /* Store number of enabled industries */ _smallmap_industry_count = j; } static const LegendAndColour * const _legend_table[] = { _legend_land_contours, _legend_vehicles, _legend_from_industries, _legend_routes, _legend_vegetation, _legend_land_owners, }; #define MKCOLOUR(x) TO_LE32X(x) /** * Height encodings; MAX_TILE_HEIGHT + 1 levels, from 0 to MAX_TILE_HEIGHT */ static const uint32 _map_height_bits[] = { MKCOLOUR(0x5A5A5A5A), MKCOLOUR(0x5A5B5A5B), MKCOLOUR(0x5B5B5B5B), MKCOLOUR(0x5B5C5B5C), MKCOLOUR(0x5C5C5C5C), MKCOLOUR(0x5C5D5C5D), MKCOLOUR(0x5D5D5D5D), MKCOLOUR(0x5D5E5D5E), MKCOLOUR(0x5E5E5E5E), MKCOLOUR(0x5E5F5E5F), MKCOLOUR(0x5F5F5F5F), MKCOLOUR(0x5F1F5F1F), MKCOLOUR(0x1F1F1F1F), MKCOLOUR(0x1F271F27), MKCOLOUR(0x27272727), MKCOLOUR(0x27272727), }; assert_compile(lengthof(_map_height_bits) == MAX_TILE_HEIGHT + 1); struct AndOr { uint32 mor; uint32 mand; }; static inline uint32 ApplyMask(uint32 colour, const AndOr *mask) { return (colour & mask->mand) | mask->mor; } static const AndOr _smallmap_contours_andor[] = { {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x000A0A00), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x98989898), MKCOLOUR(0x00000000)}, {MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x000A0A00), MKCOLOUR(0xFF0000FF)}, }; static const AndOr _smallmap_vehicles_andor[] = { {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, }; static const AndOr _smallmap_vegetation_andor[] = { {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00575700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)}, {MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)}, {MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)}, {MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)}, }; typedef uint32 GetSmallMapPixels(TileIndex tile); // typedef callthrough function static inline TileType GetEffectiveTileType(TileIndex tile) { TileType t = GetTileType(tile); if (t == MP_TUNNELBRIDGE) { TransportType tt = GetTunnelBridgeTransportType(tile); switch (tt) { case TRANSPORT_RAIL: t = MP_RAILWAY; break; case TRANSPORT_ROAD: t = MP_ROAD; break; default: t = MP_WATER; break; } } return t; } /** * Return the colour a tile would be displayed with in the small map in mode "Contour". * @param tile The tile of which we would like to get the colour. * @return The colour of tile in the small map in mode "Contour" */ static inline uint32 GetSmallMapContoursPixels(TileIndex tile) { TileType t = GetEffectiveTileType(tile); return ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]); } /** * Return the colour a tile would be displayed with in the small map in mode "Vehicles". * * @param tile The tile of which we would like to get the colour. * @return The colour of tile in the small map in mode "Vehicles" */ static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile) { TileType t = GetEffectiveTileType(tile); return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]); } /** * Return the colour a tile would be displayed with in the small map in mode "Industries". * * @param tile The tile of which we would like to get the colour. * @return The colour of tile in the small map in mode "Industries" */ static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile) { TileType t = GetEffectiveTileType(tile); if (t == MP_INDUSTRY) { /* If industry is allowed to be seen, use its colour on the map */ if (_legend_from_industries[_industry_to_list_pos[GetIndustryByTile(tile)->type]].show_on_map) { return GetIndustrySpec(GetIndustryByTile(tile)->type)->map_colour * 0x01010101; } else { /* otherwise, return the colour of the clear tiles, which will make it disappear */ return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[MP_CLEAR]); } } return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]); } /** * Return the colour a tile would be displayed with in the small map in mode "Routes". * * @param tile The tile of which we would like to get the colour. * @return The colour of tile in the small map in mode "Routes" */ static inline uint32 GetSmallMapRoutesPixels(TileIndex tile) { TileType t = GetEffectiveTileType(tile); if (t == MP_STATION) { switch (GetStationType(tile)) { case STATION_RAIL: return MKCOLOUR(0x56565656); case STATION_AIRPORT: return MKCOLOUR(0xB8B8B8B8); case STATION_TRUCK: return MKCOLOUR(0xC2C2C2C2); case STATION_BUS: return MKCOLOUR(0xBFBFBFBF); case STATION_DOCK: return MKCOLOUR(0x98989898); default: return MKCOLOUR(0xFFFFFFFF); } } /* ground colour */ return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_contours_andor[t]); } static const uint32 _vegetation_clear_bits[] = { MKCOLOUR(0x54545454), ///< full grass MKCOLOUR(0x52525252), ///< rough land MKCOLOUR(0x0A0A0A0A), ///< rocks MKCOLOUR(0x25252525), ///< fields MKCOLOUR(0x98989898), ///< snow MKCOLOUR(0xC2C2C2C2), ///< desert MKCOLOUR(0x54545454), ///< unused MKCOLOUR(0x54545454), ///< unused }; static inline uint32 GetSmallMapVegetationPixels(TileIndex tile) { TileType t = GetEffectiveTileType(tile); switch (t) { case MP_CLEAR: return (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) < 3) ? MKCOLOUR(0x37373737) : _vegetation_clear_bits[GetClearGround(tile)]; case MP_INDUSTRY: return GetIndustrySpec(GetIndustryByTile(tile)->type)->check_proc == CHECK_FOREST ? MKCOLOUR(0xD0D0D0D0) : MKCOLOUR(0xB5B5B5B5); case MP_TREES: if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT) { return (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOUR(0x98575798) : MKCOLOUR(0xC25757C2); } return MKCOLOUR(0x54575754); default: return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]); } } static uint32 _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 uint32 GetSmallMapOwnerPixels(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 const uint32 _smallmap_mask_left[3] = { MKCOLOUR(0xFF000000), MKCOLOUR(0xFFFF0000), MKCOLOUR(0xFFFFFF00), }; static const uint32 _smallmap_mask_right[] = { MKCOLOUR(0x000000FF), MKCOLOUR(0x0000FFFF), MKCOLOUR(0x00FFFFFF), }; /* each tile has 4 x pixels and 1 y pixel */ static GetSmallMapPixels *_smallmap_draw_procs[] = { GetSmallMapContoursPixels, GetSmallMapVehiclesPixels, GetSmallMapIndustriesPixels, GetSmallMapRoutesPixels, GetSmallMapVegetationPixels, GetSmallMapOwnerPixels, }; static const byte _vehicle_type_colours[6] = { 184, 191, 152, 15, 215, 184 }; static void DrawVertMapIndicator(int x, int y, int x2, int y2) { GfxFillRect(x, y, x2, y + 3, 69); GfxFillRect(x, y2 - 3, x2, y2, 69); } static void DrawHorizMapIndicator(int x, int y, int x2, int y2) { GfxFillRect(x, y, x + 3, y2, 69); GfxFillRect(x2 - 3, y, x2, y2, 69); } class SmallMapWindow : public Window { enum SmallMapType { SMT_CONTOUR, SMT_VEHICLES, SMT_INDUSTRY, SMT_ROUTES, SMT_VEGETATION, SMT_OWNER, }; static SmallMapType map_type; static bool show_towns; int32 scroll_x; int32 scroll_y; int32 subscroll; uint8 refresh; static const int COLUMN_WIDTH = 119; static const int MIN_LEGEND_HEIGHT = 6 * 7; /** * Remap a map's tile X coordinate (TileX(TileIndex)) to * a location on this smallmap. * @param tile_x the tile's X coordinate. * @return the X coordinate to draw on. */ inline int RemapX(int tile_x) { return tile_x - this->scroll_x / TILE_SIZE; } /** * Remap a map's tile Y coordinate (TileY(TileIndex)) to * a location on this smallmap. * @param tile_y the tile's Y coordinate. * @return the Y coordinate to draw on. */ inline int RemapY(int tile_y) { return tile_y - this->scroll_y / TILE_SIZE; } /** * Draws one column of the small map in a certain mode onto the screen buffer. This * function looks exactly the same for all types * * @param dst Pointer to a part of the screen buffer to write to. * @param xc The X coordinate of the first tile in the column. * @param yc The Y coordinate of the first tile in the column * @param pitch Number of pixels to advance in the screen buffer each time a pixel is written. * @param reps Number of lines to draw * @param mask ? * @param proc Pointer to the colour function * @see GetSmallMapPixels(TileIndex) */ inline void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height); void *dst_ptr_end = blitter->MoveTo(dst_ptr_abs_end, -4, 0); do { /* check if the tile (xc,yc) is within the map range */ uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0; if (IsInsideMM(xc, min_xy, MapMaxX()) && IsInsideMM(yc, min_xy, MapMaxY())) { /* check if the dst pointer points to a pixel inside the screen buffer */ if (dst < _screen.dst_ptr) continue; if (dst >= dst_ptr_abs_end) continue; uint32 val = proc(TileXY(xc, yc)) & mask; uint8 *val8 = (uint8 *)&val; if (dst <= dst_ptr_end) { blitter->SetPixelIfEmpty(dst, 0, 0, val8[0]); blitter->SetPixelIfEmpty(dst, 1, 0, val8[1]); blitter->SetPixelIfEmpty(dst, 2, 0, val8[2]); blitter->SetPixelIfEmpty(dst, 3, 0, val8[3]); } else { /* It happens that there are only 1, 2 or 3 pixels left to fill, so in that special case, write till the end of the video-buffer */ int i = 0; do { blitter->SetPixelIfEmpty(dst, 0, 0, val8[i]); } while (i++, dst = blitter->MoveTo(dst, 1, 0), dst < dst_ptr_abs_end); } } /* switch to next tile in the column */ } while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0); } public: /** * Draws the small map. * * Basically, the small map is draw column of pixels by column of pixels. The pixels * are drawn directly into the screen buffer. The final map is drawn in multiple passes. * The passes are: *