36#include "table/strings.h"
64#define MK(a, b) {b, a, IT_INVALID, 0, CompanyID::Invalid(), true, false, false}
67#define MC(col_break) {STR_TINY_BLACK_HEIGHT, {}, IT_INVALID, 0, CompanyID::Invalid(), true, false, col_break}
70#define MO(a, b) {b, a, IT_INVALID, 0, CompanyID::Invalid(), true, false, false}
73#define MOEND() {STR_NULL, {}, IT_INVALID, 0, OWNER_NONE, true, true, false}
76#define MKEND() {STR_NULL, {}, IT_INVALID, 0, CompanyID::Invalid(), true, true, false}
82#define MS(a, b) {b, a, IT_INVALID, 0, CompanyID::Invalid(), true, false, true}
87 MK(
PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
111 MK(
PC_RED, STR_SMALLMAP_LEGENDA_TRAINS),
116 MS(
PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
123 MK(
PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
127 MK(
PC_ORANGE, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY),
129 MK(
PC_RED, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT),
146 MK(
PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
153 MO({}, STR_SMALLMAP_LEGENDA_NO_OWNER),
273#define MKCOLOUR(x) TO_LE32(x)
275#define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x.p))
276#define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x.p))
277#define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x.p))
279#define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y))
281#define MKCOLOUR_0000 MKCOLOUR_XXXX(PixelColour{0x00})
282#define MKCOLOUR_F00F MKCOLOUR_X00X(PixelColour{0xFF})
283#define MKCOLOUR_FFFF MKCOLOUR_XXXX(PixelColour{0xFF})
329 uint deltas[][2] = { { 24, 2 }, { 48, 4 }, { 72, 6 }, { 120, 10 }, { 180, 15 }, { 240, 20 }, {
MAX_TILE_HEIGHT + 1, 25 }};
331 for (;
_settings_game.construction.map_height_limit >= deltas[i][0]; i++) {
334 uint delta = deltas[i][1];
336 int total_entries = (
_settings_game.construction.map_height_limit / delta) + 1;
337 int rows =
CeilDiv(total_entries, 2);
362 _legend_land_owners[i].company = c->index;
363 _legend_land_owners[i].show_on_map =
true;
364 _legend_land_owners[i].col_break =
false;
365 _legend_land_owners[i].end =
false;
371 _legend_land_owners[i].end =
true;
390 return (colour & mask.mand) | mask.mor;
396 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
400 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
403 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
405 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
411 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
415 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
418 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
420 AndOr(MKCOLOUR_0000, MKCOLOUR_FFFF),
516 default:
return MKCOLOUR_FFFF;
536 if (rti !=
nullptr) {
685 std::unique_ptr<LinkGraphOverlay> overlay{};
693 static inline Point SmallmapRemapCoords(
int x,
int y)
741 return width / this->column_width;
785 size_t heights =
_settings_game.construction.map_height_limit + 1;
786 heightmap_scheme.height_colours.resize(heights);
788 for (
size_t z = 0; z < heights; z++) {
789 size_t access_index = (heightmap_scheme.height_colours_base.size() * z) / heights;
792 heightmap_scheme.height_colours[z] = heightmap_scheme.height_colours_base[access_index];
813 return std::max({this->min_number_of_fixed_rows, num_rows_linkstats, num_rows_others});
831 bool changes =
false;
832 for (
int i = begin_legend_item; i != end_legend_item; i++) {
833 bool new_state = (i == click_pos);
834 if (legend[i].show_on_map != new_state) {
841 for (
int i = begin_legend_item; i != end_legend_item; i++) {
902 this->subscroll = sub;
918 upper_left.
x -= this->subscroll;
921 lower_right.
x -= this->subscroll;
945 void *dst_ptr_abs_end = blitter->
MoveTo(_screen.dst_ptr, 0, _screen.height);
953 if (dst < _screen.dst_ptr)
continue;
954 if (dst >= dst_ptr_abs_end)
continue;
958 if (min_xy == 1 && (xc == 0 || yc == 0)) {
959 if (this->zoom == 1)
continue;
961 ta =
TileArea(
TileXY(std::max(min_xy, xc), std::max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
968 uint8_t *val8 = (uint8_t *)&val;
969 int idx = std::max(0, -start_pos);
970 for (
int pos = std::max(0, start_pos); pos < end_pos; pos++) {
975 }
while (xc += this->zoom, yc += this->zoom, dst = blitter->
MoveTo(dst, pitch, 0), --reps != 0);
987 if (v->vehstatus.Any({VehState::Hidden, VehState::Unclickable}))
continue;
992 int y = pt.
y - dpi->top;
996 int x = pt.
x - this->subscroll - 3 - dpi->left;
1000 if (++x != 0)
continue;
1002 }
else if (x >= dpi->width - 1) {
1004 if (x != dpi->width - 1)
continue;
1012 blitter->
SetPixel(dpi->dst_ptr, x, y, colour);
1013 if (!skip) blitter->
SetPixel(dpi->dst_ptr, x + 1, y, colour);
1027 int x = pt.
x - this->subscroll - (t->cache.sign.width_small >> 1);
1028 int y = pt.
y + vertical_padding;
1031 if (x + t->cache.sign.width_small > dpi->left &&
1032 x < dpi->
left + dpi->width &&
1034 y < dpi->
top + dpi->height) {
1056 if (is_blinking)
continue;
1064 const TileIndex &tile = i->location.GetCenterTile();
1066 const int x = pt.
x - this->subscroll - (legend_text_width / 2);
1067 const int y = pt.
y + vertical_padding;
1070 if (x + legend_text_width > dpi->left &&
1071 x < dpi->
left + dpi->width &&
1073 y < dpi->
top + dpi->height) {
1099 GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, map_clear_color);
1104 int tile_x = this->scroll_x / (int)
TILE_SIZE + tile.
x;
1105 int tile_y = this->scroll_y / (int)
TILE_SIZE + tile.
y;
1107 void *ptr = blitter->
MoveTo(dpi->dst_ptr, -dx - 4, 0);
1114 if (x >= dpi->width)
break;
1116 int end_pos = std::min(dpi->width, x + 4);
1117 int reps = (dpi->height - y + 1) / 2;
1119 this->
DrawSmallMapColumn(ptr, tile_x, tile_y, dpi->pitch * 2, reps, x, end_pos, blitter);
1124 tile_y += this->zoom;
1126 ptr = blitter->
MoveTo(ptr, 0, 1);
1128 tile_x -= this->zoom;
1130 ptr = blitter->
MoveTo(ptr, 0, -1);
1132 ptr = blitter->
MoveTo(ptr, 2, 0);
1142 const int map_labels_vertical_padding =
ScaleGUITrad(2);
1145 if (this->show_towns) this->
DrawTowns(dpi, map_labels_vertical_padding);
1148 if (this->show_ind_names) this->
DrawIndustryNames(dpi, map_labels_vertical_padding);
1162 int x_offset = tile_x - this->scroll_x / (int)
TILE_SIZE;
1163 int y_offset = tile_y - this->scroll_y / (int)
TILE_SIZE;
1165 if (this->zoom == 1)
return SmallmapRemapCoords(x_offset, y_offset);
1168 if (x_offset < 0) x_offset -= this->zoom - 1;
1169 if (y_offset < 0) y_offset -= this->zoom - 1;
1171 return SmallmapRemapCoords(x_offset / this->zoom, y_offset / this->zoom);
1186 if (add_sub) px += this->subscroll;
1190 Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
1218 assert(x >= 0 && y >= 0);
1232 scroll.
x = (tx + 2 * this->zoom) *
TILE_SIZE;
1233 scroll.
y = (ty - 2 * this->zoom) *
TILE_SIZE;
1246 static const int zoomlevels[] = {1, 2, 4, 6, 8};
1247 static const int MIN_ZOOM_INDEX = 0;
1248 static const int MAX_ZOOM_INDEX =
lengthof(zoomlevels) - 1;
1250 int new_index, cur_index, sub;
1255 new_index = MIN_ZOOM_INDEX;
1256 tile.
x = tile.
y = 0;
1261 for (cur_index = MIN_ZOOM_INDEX; cur_index <= MAX_ZOOM_INDEX; cur_index++) {
1262 if (this->zoom == zoomlevels[cur_index])
break;
1264 assert(cur_index <= MAX_ZOOM_INDEX);
1270 default: NOT_REACHED();
1273 if (new_index != cur_index) {
1274 this->zoom = zoomlevels[new_index];
1275 if (cur_index >= 0) {
1278 this->scroll_y + (tile.
y - new_tile.
y) *
TILE_SIZE, sub);
1280 this->overlay->SetDirty();
1297 this->overlay->SetCargoMask(cargo_mask);
1308 int industry_names_select_plane;
1309 int select_buttons_plane;
1310 switch (this->map_type) {
1312 legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
1313 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES;
1314 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES;
1315 industry_names_select_plane = 0;
1316 select_buttons_plane = 0;
1320 legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
1321 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
1322 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
1323 industry_names_select_plane =
SZSP_NONE;
1324 select_buttons_plane = 0;
1328 legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
1329 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
1330 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
1331 industry_names_select_plane =
SZSP_NONE;
1332 select_buttons_plane = 0;
1336 legend_tooltip = STR_NULL;
1337 enable_all_tooltip = STR_NULL;
1338 disable_all_tooltip = STR_NULL;
1339 industry_names_select_plane =
SZSP_NONE;
1340 select_buttons_plane = 1;
1406 switch (this->map_type) {
1428 default: NOT_REACHED();
1443 if (line >= number_of_rows)
return -1;
1446 int x = pt.
x - wi->
pos_x;
1450 return (column * number_of_rows) + line;
1458 if (this->overlay->GetCompanyMask() != company_mask) {
1459 this->overlay->SetCompanyMask(company_mask);
1461 this->overlay->SetDirty();
1480 if (_smallmap_industry_highlight != IT_INVALID)
return;
1541 ret.
x -= 3 + this->subscroll;
1545 void Close([[maybe_unused]]
int data)
override
1569 uint num_columns = 1;
1576 str =
GetString(STR_SMALLMAP_LINKSTATS, tbl.legend);
1578 if (tbl.company != CompanyID::Invalid()) {
1586 str =
GetString(STR_SMALLMAP_COMPANY, tbl.company);
1591 if (tbl.col_break) {
1592 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows,
height);
1605 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows,
height);
1606 this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns);
1683 int x = rtl ? -(int)this->column_width : this->column_width;
1684 int y = origin.top - text.top;
1692 switch (this->map_type) {
1703 this->
DrawLegend(text, icon, tbl.show_on_map,
GetString(STR_SMALLMAP_LINKSTATS, tbl.legend));
1707 if (tbl.company != CompanyID::Invalid()) {
1708 this->
DrawLegend(text, icon, tbl.show_on_map,
GetString(STR_SMALLMAP_COMPANY, tbl.company));
1774 this->show_towns = !this->show_towns;
1782 this->show_ind_names = !this->show_ind_names;
1792 if (click_pos < 0)
break;
1817 switch (this->map_type) {
1831 for (;!tbl->
end && tbl->
legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
1857 if (!gui_scope)
return;
1879 default: NOT_REACHED();
1897 int cursor_x = _cursor.pos.x - this->
left - wid->
pos_x;
1898 int cursor_y = _cursor.pos.y - this->
top - wid->
pos_y;
1899 Point pt = {cursor_x, cursor_y};
1918 IndustryType new_highlight = IT_INVALID;
1945 static constexpr std::tuple<WidgetID, WidgetType, SpriteID, StringID>
buttons[] = {
1970 for (
const auto &[widget, tp, sprite,
string] :
buttons) {
1973 this->
Add(std::move(leaf));
1976 leaf->SetToolbarMinimalSize(1);
1977 this->
Add(std::move(leaf));
1984 this->button.width = 0;
1985 this->button.height = 0;
1987 this->num_buttons = 0;
1988 for (
const auto &child_wid : this->
children) {
1989 child_wid->SetupSmallestSize(w);
1990 this->button.width = std::max(this->button.width, child_wid->smallest_y + child_wid->padding.Vertical());
1991 this->button.height = std::max(this->button.height, child_wid->smallest_x + child_wid->padding.Horizontal());
2006 if (given_height >= this->num_buttons * this->button.height)
return {this->button.width, given_height};
2007 return {given_width, given_height};
2012 assert(given_width >= this->button.width && given_height >= this->smallest_y);
2023 for (
auto &child : this->
children) {
2026 uint height = given_height - child_y - (remaining * this->button.height);
2027 child->AssignSizePosition(sizing, x, y + child_y, given_width, height, rtl);
2029 }
else if (given_width == this->button.width && child->GetIndex() ==
WID_SM_BLANK) {
2031 child->AssignSizePosition(sizing, x + child_x, y + child_y, 0, 0, rtl);
2033 child->AssignSizePosition(sizing, x + child_x, y + child_y, child->smallest_x, child->smallest_y, rtl);
2034 child_x += child->current_x;
2035 if (child_x >= given_width) {
2037 child_y += child->current_y;
2048 static std::unique_ptr<NWidgetBase>
Make()
2050 return std::make_unique<NWidgetSmallmapButtons>();
2062class NWidgetSmallmapDisplay :
public NWidgetContainer {
2065 NWidgetSmallmapDisplay() : NWidgetContainer(
NWID_CUSTOM) {}
2069 assert(this->
children.size() == 2);
2070 NWidgetBase *display = this->
children.front().get();
2071 NWidgetBase *bar = this->
children.back().get();
2077 assert(this->smallmap_window !=
nullptr);
2084 this->ApplyAspectRatio();
2094 assert(this->
children.size() == 2);
2095 NWidgetBase *display = this->
children.front().get();
2096 NWidgetBase *bar = this->
children.back().get();
2106 uint bar_height = std::max(bar->
smallest_y, this->smallmap_window->GetLegendHeight(this->smallmap_window->GetNumberColumnsLegend(given_width - bar->
smallest_x)));
2107 uint display_height = given_height - bar_height;
2117 NWidget(
WWT_INSET,
Colours::Brown,
WID_SM_MAP),
SetFill(1, 1),
SetResize(1, 1),
SetPadding(2, 2, 2, 2),
EndContainer(),
2129static std::unique_ptr<NWidgetBase> SmallMapDisplay()
2131 std::unique_ptr<NWidgetBase> map_display = std::make_unique<NWidgetSmallmapDisplay>();
2138static constexpr std::initializer_list<NWidgetPart> _nested_smallmap_widgets = {
2173 WindowClass::SmallMap, WindowClass::None,
2175 _nested_smallmap_widgets
2202 if (res)
return res;
2218 return static_cast<const SmallMapWindow *
>(w)->GetStationMiddle(st);
Class for backupping variables and making sure they are restored later.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
CargoType
Cargo slots to indicate a cargo type within a game.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
constexpr Timpl & Set()
Set all bits.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
virtual void SetPixel(void *video, int x, int y, PixelColour colour)=0
Draw a pixel with a given colour on the video-buffer.
Iterate a range of enum values.
An interval timer will fire every interval, and will continue to fire until it is deleted.
static const PixelColour LINK_COLOURS[][12]
Colours for the various "load" states of links.
PixelColour map_colour
Colour on mini-map.
Class managing the smallmap window.
void SmallMapCenterOnCurrentPos()
Center the small map on the current center of the viewport.
void SetOverlayCargoMask()
Set the link graph overlay cargo mask from the legend.
void Close(int data) override
Hide the window and all its child windows, and mark them for a later deletion.
static SmallMapType map_type
Currently displayed legends.
void DrawLegend(const Rect &text, const Rect &icon, bool highlight, std::string_view string) const
Draw a string legend.
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
uint column_width
Width of a column in the WID_SM_LEGEND widget.
uint min_number_of_fixed_rows
Minimal number of rows in the legends for the fixed layouts only (all except SmallMapType::Industries...
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item=0)
Select and toggle a legend item.
void SwitchMapType(SmallMapType map_type)
Select a new map type.
const IntervalTimer< TimerWindow > blink_interval
Blink the industries (if selected) on a regular interval.
void DrawSmallMap(DrawPixelInfo *dpi) const
Draws the small map.
Point ComputeScroll(int tx, int ty, int x, int y, int *sub) const
Compute base parameters of the smallmap such that tile (tx, ty) starts at pixel (x,...
Point GetStationMiddle(const Station *st) const
Get the center of the given station as point on the screen in the smallmap window.
void ForceRefresh()
Force a full refresh of the map.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
static bool show_towns
Display town names in the smallmap.
Point PixelToTile(int px, int py, int *sub, bool add_sub=true) const
Determine the tile relative to the base tile of the smallmap, and the pixel position at that tile for...
void Blink()
Blink the industries (if hover over an industry).
int32_t scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
int32_t scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
void DrawIndustryNames(const DrawPixelInfo *dpi, const int vertical_padding) const
Adds industry names to the smallmap.
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
uint min_number_of_columns
Minimal number of columns in legends.
int32_t subscroll
Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner o...
CompanyMask GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
uint32_t GetTileColours(const TileArea &ta) const
Decide which colours to show to the user for a group of tiles.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void DrawTowns(const DrawPixelInfo *dpi, const int vertical_padding) const
Adds town names to the smallmap.
void OnPaint() override
The window must be repainted.
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
Initialize or change the zoom level.
int GetPositionOnLegend(Point pt)
Determines the mouse position on the legend.
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
ZoomLevelChange
Available kinds of zoomlevel changes.
@ Init
Initialize zoom level.
void SetupWidgetData()
Function to set up widgets depending on the information being shown on the smallmap.
static bool show_ind_names
Display industry names in the smallmap.
void RebuildColourIndexIfNecessary()
Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightl...
void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
Draws one column of tiles of the small map in a certain mode onto the screen buffer,...
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static int map_height_limit
Currently used/cached map height limit.
Point RemapTile(int tile_x, int tile_y) const
Remap tile to location on this smallmap.
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateLinks()
Update all the links on the map.
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS
Minimal number of columns in the WID_SM_LEGEND widget for the SmallMapType::Industries legend.
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
uint legend_width
Width of legend 'blob'.
int zoom
Zoom level. Bigger number means more zoom-out (further away).
void DrawMapIndicators() const
Adds map indicators to the smallmap.
bool OnRightClick(Point, WidgetID widget) override
A click with the right mouse button has been made on the window.
void SetNewScroll(int sx, int sy, int sub)
Set new scroll_x, scroll_y, and subscroll values after limiting them such that the center of the smal...
uint GetNumberRowsLegend(uint columns) const
Get the number of rows in the legend from the number of columns.
const IntervalTimer< TimerWindow > refresh_interval
Update the whole map on a regular interval.
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
Adds vehicles to the smallmap.
static void BreakIndustryChainLink()
Notify the industry chain window to stop sending newly selected industries.
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
Map accessors for 'clear' tiles.
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
@ Grass
Plain grass with dirt transition (0-3).
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Function to handling different endian machines.
Type (helpers) for enums.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Factory to 'query' all available blitters.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
@ Start
Align to the start, LTR/RTL aware.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
bool _ctrl_pressed
Is Ctrl pressed?
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ Small
Index of the small font in the font tables.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
The colour tables for heightmaps.
static const uint32_t _violet_map_heights[]
Height map colours for the violet colour scheme, ordered by height.
static const uint32_t _dark_green_map_heights[]
Height map colours for the dark green colour scheme, ordered by height.
static const uint32_t _green_map_heights[]
Height map colours for the green colour scheme, ordered by height.
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Functions related to OTTD's landscape.
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
@ Arctic
Landscape with snow levels.
Declaration of linkgraph overlay GUI.
#define Point
Macro that prevents name conflicts between included headers.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
static constexpr PixelColour PC_TREES
Green palette colour for trees.
@ Light
Light colour shade.
static constexpr PixelColour PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
static constexpr PixelColour PC_ROUGH_LAND
Dark green palette colour for rough land.
static constexpr PixelColour PC_YELLOW
Yellow palette colour.
static constexpr PixelColour PC_GREEN
Green palette colour.
static constexpr PixelColour PC_FIELDS
Light brown palette colour for fields.
static constexpr PixelColour PC_DARK_RED
Dark red palette colour.
static constexpr PixelColour PC_WATER
Dark blue palette colour for water.
static constexpr PixelColour PC_ORANGE
Orange palette colour.
static constexpr PixelColour PC_GRASS_LAND
Dark green palette colour for grass land.
static constexpr PixelColour PC_BARE_LAND
Brown palette colour for bare land.
static constexpr PixelColour PC_GREY
Grey palette colour.
static constexpr PixelColour PC_RED
Red palette colour.
static constexpr PixelColour PC_DARK_GREY
Dark grey palette colour.
static constexpr PixelColour PC_BLACK
Black palette colour.
static constexpr PixelColour PC_RAINFOREST
Pale green palette colour for rainforest.
static constexpr PixelColour PC_WHITE
White palette colour.
static constexpr PixelColour PC_VERY_DARK_BROWN
Almost-black brown palette colour.
static constexpr PixelColour PC_LIGHT_BLUE
Light blue palette colour.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType GetRoadTypeRoad(Tile t)
Get the road type for RoadTramType being RoadTramType::Road.
RoadType GetRoadTypeTram(Tile t)
Get the road type for RoadTramType being RoadTramType::Tram.
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
bool HasRoadTypeRoad(Tile t)
Check if a tile has a road type when RoadTramType is RoadTramType::Road.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
@ MapRMBFixed
Map moves with mouse movement on holding right mouse button, cursor position is fixed.
@ ViewportRMBFixed
Viewport moves with mouse movement on holding right mouse button, cursor position is fixed.
@ Off
Scroll wheel has no effect.
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
#define MK(a, b)
Macro for ordinary entry of LegendAndColour.
void ShowSmallMap()
Show the smallmap window.
static const EnumIndexArray< AndOr, TileType, TileType::MaxSize > _smallmap_contours_andor
Colour masks for "Contour" and "Routes" modes.
static uint32_t GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "link stats".
static uint32_t GetSmallMapContoursPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Contour".
void BuildLandLegend()
(Re)build the colour tables for the legends.
static uint32_t GetSmallMapVehiclesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Vehicles".
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1]
Allow room for all industries, plus a terminator entry This is required in order to have the industry...
#define MS(a, b)
Macro for break marker in arrays of LegendAndColour.
#define MC(col_break)
Macro for a height legend entry with configurable colour.
static const EnumIndexArray< std::span< const LegendAndColour >, SmallMapType, SmallMapType::End > _legend_table
Legend to use for each SmallMapType.
static constexpr VehicleTypeIndexArray< PixelColour, VehicleType::End > _vehicle_type_colours
Vehicle colours in SmallMapType::Vehicles mode.
static const uint8_t _linkstat_colours_in_legenda[]
Link stat colours shown in legenda.
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES]
For connecting industry type to position in industries list(small map legend).
static const EnumIndexArray< AndOr, TileType, TileType::MaxSize > _smallmap_vehicles_andor
Colour masks for "Vehicles", "Industry", and "Vegetation" modes.
static IndustryType _smallmap_industry_highlight
Highlight a specific industry type.
void BuildOwnerLegend()
Completes the array for the owned property legend.
static const int NUM_NO_COMPANY_ENTRIES
Number of entries in the owner legend that are not companies.
static int _smallmap_cargo_count
Number of cargos in the link stats legend.
uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
Return the colour a tile would be displayed with in the small map in mode "Owner".
static bool IsDryCoast(TileIndex tile)
Test if a water tile is a dry coast tile, i.e.
static int _smallmap_company_count
Number of entries in the owner legend.
static SmallMapColourScheme _heightmap_schemes[]
Available colour schemes for height maps.
static constexpr std::initializer_list< NWidgetPart > _nested_smallmap_display
Widget parts of the smallmap display and image buttons.
static uint32_t GetSmallMapVegetationPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the smallmap in mode "Vegetation".
static constexpr std::initializer_list< NWidgetPart > _nested_smallmap_bar
Widget parts of the smallmap legend bar.
static uint32_t GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Industries".
static LegendAndColour _legend_land_contours[]
Legend text giving the colours to look for on the minimap.
static bool _smallmap_show_heightmap
Show heightmap in industry and owner mode of smallmap window.
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
@ Vegetation
Vegetation legend.
@ LinkStats
LinkStats legend.
@ Vehicles
Vehicles legend.
@ Industries
Industries legend.
static int _smallmap_industry_count
Number of used industries.
static bool _smallmap_industry_highlight_state
State of highlight blinking.
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
static uint32_t GetSmallMapRoutesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Routes".
static const AndOr & GetMaskPixelsForTileType(TileIndex tile, TileType t, const EnumIndexArray< AndOr, TileType, TileType::MaxSize > &table)
Get the mask pixel group for a tile from the given lookup table, taking account of coast tiles.
static uint16_t _industry_to_name_string_width[NUM_INDUSTRYTYPES]
The string bounding box width for each industry type in the smallmap.
#define MKEND()
Macro for end of list marker in arrays of LegendAndColour.
static constexpr EnumIndexArray< uint32_t, ClearGround, ClearGround::MaxSize > _vegetation_clear_bits
Lookup table of minimap colours to use for each ClearGround type.
static const EnumIndexArray< uint8_t, TileType, TileType::MaxSize > _tiletype_importance
Mapping of tile type to importance of the tile (higher number means more interesting to show).
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
static TypedIndexContainer< std::array< uint32_t, MAX_COMPANIES >, CompanyID > _company_to_list_pos
For connecting company ID to position in owner list (small map legend).
void BuildIndustriesLegend()
Fills an array for the industries legends.
static WindowDesc _smallmap_desc(WindowPosition::Automatic, "smallmap", 0, 0, WindowClass::SmallMap, WindowClass::None, {}, _nested_smallmap_widgets)
Window definition for the smallmap window.
#define MOEND()
Macro used for forcing a rebuild of the owner legend the first time it is used.
static LegendAndColour _legend_linkstats[NUM_CARGO+lengthof(_linkstat_colours_in_legenda)+1]
Legend entries for the link stats view.
static uint32_t ApplyMask(uint32_t colour, const AndOr &mask)
Mix colours for a smallmap pixel group.
#define MO(a, b)
Macro for non-company owned property entry of LegendAndColour.
Point GetSmallMapStationMiddle(const Window *w, const Station *st)
Determine the middle of a station in the smallmap window.
IncludeHeightmap
Enum for how to include the heightmap pixels/colours in small map related functions.
@ Always
Always include the heightmap.
@ IfEnabled
Only include the heightmap if its enabled in the gui by the player.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
static const SpriteID SPR_IMG_PLANTTREES
static const SpriteID SPR_IMG_COMPANY_GENERAL
static const SpriteID SPR_IMG_INDUSTRY
static const SpriteID SPR_IMG_SHOW_ROUTES
static const SpriteID SPR_IMG_SHOW_VEHICLES
static const SpriteID SPR_IMG_ZOOMIN
static const SpriteID SPR_IMG_SHOW_COUNTOURS
static const SpriteID SPR_IMG_ZOOMOUT
static const SpriteID SPR_IMG_TOWN
static const SpriteID SPR_EMPTY
Empty (transparent blue) sprite.
static const SpriteID SPR_IMG_SMALLMAP
Maps accessors for stations.
StationType GetStationType(Tile t)
Get the station type of this tile.
@ Rail
Railways/train station.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ Airport
Airports and heliports, excluding the ones on oil rigs.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Specification of a cargo type.
CargoType Index() const
Determines index of this cargospec.
StringID name
Name of this type of cargo.
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Defines the data structure for constructing industry.
StringID name
Displayed name of the industry.
bool enabled
entity still available (by default true).newgrf can disable it, though
PixelColour map_colour
colour used for the small map
Defines the internal data of a functional industry.
IndustryType type
type of industry.
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Structure for holding relevant data for legends in small map.
PixelColour colour
Colour of the item on the map.
uint8_t height
Height in tiles. Only valid for height legend entries.
StringID legend
String corresponding to the coloured item.
bool show_on_map
For filtering industries, if true, industry is shown on the map in colour.
CompanyID company
Company to display. Only valid for company entries of the owner legend.
bool end
This is the end of the list.
bool col_break
Perform a column break and go further at the next column.
IndustryType type
Type of industry. Only valid for industry entries.
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
void ClampToMap()
Clamp the tile area to map borders.
Colour for pixel/line drawing.
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static bool IsValidID(auto index)
static constexpr size_t MAX_SIZE
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Colour scheme of the smallmap.
std::vector< uint32_t > height_colours
Cached colours for each level in a map.
uint32_t default_colour
Default colour of the land.
std::span< const uint32_t > height_colours_base
Base table for determining the colours.
Data structure for viewport, display of a part of the world.
int virtual_top
Virtual top coordinate.
int virtual_left
Virtual left coordinate.
int virtual_width
width << zoom
int virtual_height
height << zoom
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). INVALID_WIDGET if no widget has mouse ca...
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
int left
x position of left edge of the window
int top
y position of top edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
static uint TileHeight(Tile tile)
Returns the height of a tile.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static constexpr uint MAX_TILE_HEIGHT
Maximum allowed tile height.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
@ Rainforest
Rainforest tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static constexpr uint TILE_SIZE
Tile size in world coordinates.
TileType
The different types of tiles.
@ TunnelBridge
Tunnel entry/exit and bridge heads.
@ Station
A tile of a station or airport.
@ Industry
Part of an industry.
@ Railway
A tile with railway.
@ Void
Invisible tiles at the SW and SE border.
@ Trees
Tile with one or more trees.
@ House
A house by a town.
@ Road
A tile with road and/or tram tracks.
@ Clear
A tile without any structures, i.e. grass, rocks, farm fields etc.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition of Interval and OneShot timers.
Definition of the Window system.
static constexpr std::chrono::milliseconds TIMER_BLINK_INTERVAL
Interval used by blinking interface elements.
TransportType
Available types of transport.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
Map accessors for tree tiles.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
@ SnowOrDesert
Snow or desert, depending on landscape.
@ RoughSnow
A snow tile that is rough underneath.
Functions that have tunnels and bridges in common.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Base class for all vehicles.
@ Effect
Effect vehicle type (smoke, explosions, sparks, bubbles).
EnumIndexArray< T, VehicleType, Tend > VehicleTypeIndexArray
Array with VehicleType as index.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Functions related to (drawing on) viewports.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
bool IsCoastTile(Tile t)
Is it a coast tile.
Window * GetMainWindow()
Get the main window, i.e.
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Window functions not directly related to making/drawing windows.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Functions related to zooming.