53#include "table/strings.h"
92 const std::initializer_list<ExpensesType> &
items;
98 uint GetHeight()
const
171 DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
195 y += list.GetHeight();
223 StringID str = STR_FINANCES_NEGATIVE_INCOME;
225 str = STR_FINANCES_ZERO_INCOME;
226 }
else if (amount < 0) {
228 str = STR_FINANCES_POSITIVE_INCOME;
243 Money cost = tbl[et];
245 if (cost != 0)
DrawPrice(cost, r.left, r.right, y, TC_BLACK);
252 if (sum != 0)
DrawPrice(sum, r.left, r.right, y, TC_WHITE);
286 DrawPrice(sum, r.left, r.right, y, TC_WHITE);
289static constexpr NWidgetPart _nested_company_finances_widgets[] = {
414 size.width += padding.width;
456 this->GetWidget<NWidgetStacked>(
WID_CF_SEL_PANEL)->SetDisplayedPlane(plane);
497 this->small = !this->
small;
522 void RefreshVisibleColumns()
524 for (uint period = 0; period < this->
first_visible; ++period) {
528 if (std::ranges::any_of(expenses, [](
const Money &value) {
return value != 0; })) {
529 this->first_visible = period;
537 this->RefreshVisibleColumns();
561 _nested_company_finances_widgets
580 LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL,
583 LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
591template <SpriteID TSprite = SPR_SQUARE>
607 uint line_height = 0;
611 void ShowColourDropDownMenu(uint32_t widget)
613 uint32_t used_colours = 0;
614 const Livery *livery, *default_livery =
nullptr;
616 uint8_t default_col = 0;
619 if (this->livery_class < LC_GROUP_RAIL &&
HasBit(this->sel, LS_DEFAULT) && primary) {
627 if (this->livery_class < LC_GROUP_RAIL) {
630 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
631 if (
HasBit(this->sel, scheme))
break;
633 if (scheme == LS_END) scheme = LS_DEFAULT;
634 livery = &c->livery[scheme];
635 if (scheme != LS_DEFAULT) default_livery = &c->livery[LS_DEFAULT];
639 if (g->
parent == GroupID::Invalid()) {
640 default_livery = &c->livery[LS_DEFAULT];
643 default_livery = &pg->
livery;
648 if (default_livery !=
nullptr) {
650 default_col = (primary ? default_livery->
colour1 : default_livery->
colour2) + COLOUR_END;
653 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
658 if (default_livery ==
nullptr ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
670 this->groups.clear();
672 if (this->livery_class >= LC_GROUP_RAIL) {
682 if (this->livery_class < LC_GROUP_RAIL) {
684 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
690 this->rows = (uint)this->groups.size();
693 this->vscroll->
SetCount(this->rows);
702 if (group == GroupID::Invalid()) {
703 this->livery_class = LC_OTHER;
706 this->BuildGroupList(company);
709 this->SetSelectedGroup(company, group);
713 this->owner = company;
722 case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL;
break;
723 case VEH_ROAD: this->livery_class = LC_GROUP_ROAD;
break;
724 case VEH_SHIP: this->livery_class = LC_GROUP_SHIP;
break;
725 case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT;
break;
726 default: NOT_REACHED();
728 this->sel = group.base();
732 this->BuildGroupList(company);
736 for (uint i = 0; i < this->rows; i++) {
737 if (this->groups[i].group->index == sel) {
750 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
754 size.width = std::max(size.width, 5 + d.width + padding.width);
763 size.height = 5 * this->line_height;
765 fill.height =
resize.height = this->line_height;
779 for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) {
793 bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel == GroupID::Invalid());
812 StringID colour = STR_COLOUR_DEFAULT;
814 if (this->livery_class < LC_GROUP_RAIL) {
815 if (this->sel != 0) {
817 for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
818 if (
HasBit(this->sel, scheme))
break;
820 if (scheme == LS_END) scheme = LS_DEFAULT;
821 const Livery *livery = &c->livery[scheme];
822 if (scheme == LS_DEFAULT ||
HasBit(livery->
in_use, primary ? 0 : 1)) {
823 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
827 if (this->sel != GroupID::Invalid()) {
831 colour = STR_COLOUR_DARK_BLUE + (primary ? livery->
colour1 : livery->
colour2);
866 int square_offs = (ir.
Height() - this->square.height) / 2;
872 auto draw_livery = [&](std::string_view str,
const Livery &livery,
bool is_selected,
bool is_default_scheme,
int indent) {
874 DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TC_WHITE : TC_BLACK);
878 DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme ||
HasBit(livery.in_use, 0)) ? STR_COLOUR_DARK_BLUE + livery.colour1 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
881 if (sec.right > sec.left) {
883 DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme ||
HasBit(livery.in_use, 1)) ? STR_COLOUR_DARK_BLUE + livery.colour2 : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
886 y += this->line_height;
891 if (livery_class < LC_GROUP_RAIL) {
893 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
895 if (pos-- > 0)
continue;
896 draw_livery(
GetString(STR_LIVERY_DEFAULT + scheme), c->livery[scheme],
HasBit(this->sel, scheme), scheme == LS_DEFAULT, 0);
901 for (
auto it = first; it != last; ++it) {
902 const Group *g = it->group;
906 if (this->vscroll->
GetCount() == 0) {
907 const StringID empty_labels[] = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
909 DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
932 if (this->livery_class < LC_GROUP_RAIL) {
934 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
936 this->sel = 1 << scheme;
941 this->sel = GroupID::Invalid().base();
945 if (!this->groups.empty()) {
946 this->sel = this->groups[0].group->index.base();
963 if (this->livery_class < LC_GROUP_RAIL) {
965 if (row >= this->rows)
return;
969 for (
LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
981 if (it == std::end(this->groups))
return;
983 this->sel = it->group->index.base();
1001 Colours colour =
static_cast<Colours
>(index);
1002 if (colour >= COLOUR_END) colour = INVALID_COLOUR;
1004 if (this->livery_class < LC_GROUP_RAIL) {
1006 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1023 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1025 if (!gui_scope)
return;
1029 if (this->livery_class == data + LC_GROUP_RAIL) {
1035 this->sel = GroupID::Invalid().base();
1036 if (!this->groups.empty()) this->sel = this->groups[0].group->index.base();
1046 bool current_class_valid = this->livery_class == LC_OTHER || this->livery_class >= LC_GROUP_RAIL;
1048 for (
LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1050 if (_livery_class[scheme] == this->livery_class) current_class_valid =
true;
1052 }
else if (this->livery_class < LC_GROUP_RAIL) {
1053 ClrBit(this->sel, scheme);
1058 if (!current_class_valid) {
1023 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
1065static constexpr NWidgetPart _nested_select_company_livery_widgets[] = {
1086 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SCL_MATRIX),
SetMinimalSize(275, 0),
SetResize(1, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_LIVERY_PANEL_TOOLTIP),
SetScrollbar(
WID_SCL_MATRIX_SCROLLBAR),
1097static WindowDesc _select_company_livery_desc(
1098 WDP_AUTO,
"company_color_scheme", 0, 0,
1101 _nested_select_company_livery_widgets
1109 }
else if (group != GroupID::Invalid()) {
1110 w->SetSelectedGroup(company, group);
1132 std::unordered_map<uint8_t, PaletteID> palettes;
1136 if (vars[var].type != FaceVarType::Palette)
continue;
1139 switch (vars[var].GetBits(cmf)) {
1140 default: NOT_REACHED();
1141 case 0: pal = PALETTE_TO_BROWN;
break;
1142 case 1: pal = PALETTE_TO_BLUE;
break;
1143 case 2: pal = PALETTE_TO_GREEN;
break;
1145 for (uint8_t affected_var :
SetBitIterator(std::get<uint64_t>(vars[var].data))) {
1146 palettes[affected_var] = pal;
1155 if (vars[var].type != FaceVarType::Sprite)
continue;
1157 auto it = palettes.find(var);
1158 PaletteID pal = (it == std::end(palettes)) ? PAL_NONE : it->second;
1159 DrawSprite(vars[var].GetSprite(cmf), pal, x, y);
1192 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_SCMF_PARTS),
SetResize(1, 1),
SetFill(1, 1),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_SCMF_PARTS_SCROLLBAR),
1229 if (vars[var].name == STR_NULL)
ClrBit(active_vars, var);
1233 this->face_vars.clear();
1235 this->face_vars.emplace_back(&vars[var]);
1272 wi->
SetStringTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1274 wi->
SetStringTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1283 static uint GetMaximumFacePartsWidth()
1285 StringID yes_no = GetLongestString(STR_FACE_YES, STR_FACE_NO);
1290 for (
const auto &info : vars) {
1291 if (info.name == STR_NULL)
continue;
1292 if (info.type == FaceVarType::Toggle) {
1319 size.width = GetMaximumFacePartsWidth();
1320 size.height =
resize.height * 5;
1339 DrawArrowButtons(br.left, br.top, COLOUR_YELLOW, this->selected_var == UINT_MAX - 1 ? this->click_state : 0,
true,
true);
1351 for (
auto it = first; it != last; ++it) {
1352 const uint8_t var =
static_cast<uint8_t
>(*it - vars.data());
1353 const FaceVar &facevar = **it;
1358 uint val = vars[var].GetBits(this->
face);
1359 if (facevar.type == FaceVarType::Toggle) {
1360 DrawBoolButton(br.left, br.top, COLOUR_YELLOW, COLOUR_GREY, val == 1,
true);
1361 DrawString(tr,
GetString(STR_FACE_SETTING_TOGGLE, facevar.name, val == 1 ? STR_FACE_YES : STR_FACE_NO), TC_WHITE);
1363 DrawArrowButtons(br.left, br.top, COLOUR_YELLOW, this->selected_var == var ? this->click_state : 0,
true,
true);
1367 ir = ir.
Translate(0, this->line_height);
1398 if (cmf.has_value()) this->
face = *cmf;
1429 this->selected_var = UINT_MAX - 1;
1432 this->click_state = 1;
1435 this->click_state = 2;
1449 this->selected_var = UINT_MAX;
1453 if (it == std::end(this->face_vars))
break;
1455 this->selected_var =
static_cast<uint8_t
>(*it - vars.data());
1456 const auto &facevar = **it;
1458 if (facevar.type == FaceVarType::Toggle) {
1460 facevar.ChangeBits(this->
face, 1);
1464 facevar.ChangeBits(this->
face, -1);
1465 this->click_state = 1;
1467 facevar.ChangeBits(this->
face, 1);
1468 this->click_state = 2;
1483 if (
auto *wid = this->GetWidget<NWidgetResizeBase>(
WID_SCMF_PARTS); wid !=
nullptr) {
1486 if (wid->UpdateVerticalSize((wid->current_y + wid->resize_y - 1) / wid->resize_y * wid->resize_y)) {
1497 this->click_state = 0;
1498 this->selected_var = UINT_MAX;
1504 if (!str.has_value())
return;
1507 if (cmf.has_value()) {
1539static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = {
1577 uint count_width = 0;
1578 uint cost_width = 0;
1580 mutable std::vector<InfrastructureItem> list;
1590 this->UpdateInfrastructureList();
1593 void UpdateInfrastructureList()
1598 if (c ==
nullptr)
return;
1600 Money total_monthly_cost = 0;
1609 total_monthly_cost += monthly_cost;
1615 total_monthly_cost += monthly_cost;
1626 if (!RoadTypeIsRoad(rt))
continue;
1629 total_monthly_cost += monthly_cost;
1640 if (!RoadTypeIsTram(rt))
continue;
1643 total_monthly_cost += monthly_cost;
1654 total_monthly_cost += monthly_cost;
1665 total_monthly_cost += monthly_cost;
1669 if (airport_cost > 0) {
1670 Money monthly_cost = airport_cost;
1671 total_monthly_cost += monthly_cost;
1699 if (def_height == 0) {
1702 int delta = std::min(20,
static_cast<int>(std::size(this->list))) - rows;
1713 uint max_count = 1000;
1714 Money max_cost = 1000000;
1717 static constexpr StringID header_strings[] = {
1718 STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT,
1719 STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT,
1720 STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT,
1721 STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT,
1722 STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT,
1725 static constexpr StringID label_strings[] = {
1726 STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS,
1727 STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS,
1728 STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS,
1729 STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS,
1740 max_count = std::max(max_count, entry.count);
1741 max_cost = std::max(max_cost, entry.cost * 12);
1750 this->cost_width = 0;
1772 for (
auto it = first; it != last; ++it) {
1797 labelr.top += line_height;
1798 countr.top += line_height;
1799 costr.top += line_height;
1804 this->UpdateInfrastructureList();
1818 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1820 if (!gui_scope)
return;
1818 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
1826static WindowDesc _company_infrastructure_desc(
1827 WDP_AUTO,
"company_infrastructure", 0, 0,
1830 _nested_company_infrastructure_widgets
1840 AllocateWindowDescFront<CompanyInfrastructureWindow>(_company_infrastructure_desc, company);
1843static constexpr NWidgetPart _nested_company_widgets[] = {
1921 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
1955 bool reinit =
false;
1996 d.width -= offset.x;
1997 d.height -= offset.y;
2023 size.width += padding.width;
2041 size.width += padding.width;
2046 void DrawVehicleCountsWidget(
const Rect &r,
const Company *c)
const
2052 uint amount = c->
group_all[type].num_vehicle;
2061 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2065 void DrawInfrastructureCountsWidget(
const Rect &r,
const Company *c)
const
2070 if (rail_pieces != 0) {
2071 DrawString(r.left, r.right, y,
GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL, rail_pieces));
2077 if (road_pieces != 0) {
2078 DrawString(r.left, r.right, y,
GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD, road_pieces));
2099 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2118 d.height -= offset.y;
2124 DrawVehicleCountsWidget(r, c);
2128 DrawInfrastructureCountsWidget(r, c);
2168 ShowCompanyLiveryWindow(this->
window_number, GroupID::Invalid());
2264 if (!str.has_value())
return;
2266 switch (this->query_widget) {
2267 default: NOT_REACHED();
2270 auto value = ParseInteger<uint64_t>(*str, 10,
true);
2271 if (!value.has_value())
return;
2287 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2289 if (gui_scope && data == 1) {
2287 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
2300 _nested_company_widgets
2311 AllocateWindowDescFront<CompanyWindow>(_company_desc, company);
2351 return GetString(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY,
Company::Get(this->window_number)->index);
2393 if (!this->hostile_takeover)
return;
2404 bool hostile_takeover =
false;
2408static constexpr NWidgetPart _nested_buy_company_widgets[] = {
2431 _nested_buy_company_widgets
2442 if (window ==
nullptr) {
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Drop down icon component.
Colour selection list item, with icon and string components.
bool masked
Masked and unselectable item.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
An interval timer will fire every interval, and will continue to fire until it is deleted.
StringID name
Name of this rail type.
StringID name
Name of this rail type.
Management class for customizing the face of the company manager.
void SelectDisplayPlanes(bool advanced)
Select planes to display to the user with the NWID_SELECTION widgets WID_SCMF_SEL_LOADSAVE,...
uint click_state
Click state on selected face variable.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::vector< const FaceVar * > face_vars
Visible face variables.
void OnResize() override
Called after the window got resized.
bool advanced
advanced company manager face selection window
uint selected_var
Currently selected face variable. UINT_MAX for none, UINT_MAX - 1 means style is clicked instead.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
CompanyManagerFace face
company manager face bits
int line_height
Height of each face variable row.
void UpdateData()
Make face bits valid and update visible face variables.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnInit() override
Notification that the nested widget tree gets initialized.
static Year year
Current year, starting at 0.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
Money CalculateHostileTakeoverValue(const Company *c)
Calculate what you have to pay to take over a company.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode(std::string_view str)
Parse a face code into a company manager face.
FaceVars GetCompanyManagerFaceVars(uint style)
Get the face variables for a face style.
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
std::string _company_manager_face
for company manager face storage in openttd.cfg
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
uint GetNumCompanyManagerFaceStyles()
Get the number of company manager face styles.
std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
Get a face code representation of a company manager face.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Command definitions related to companies.
Functions related to companies.
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &list, const Expenses &tbl)
Draw a category of expenses/revenues in the year column.
static uint GetMaxCategoriesWidth()
Get the required width of the "categories" column, equal to the widest element.
static WindowDesc _select_company_manager_face_desc(WDP_AUTO, {}, 0, 0, WC_COMPANY_MANAGER_FACE, WC_NONE, WindowDefaultFlag::Construction, _nested_select_company_manager_face_widgets)
Company manager face selection window description.
static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
Draw a column with prices.
static const std::initializer_list< ExpensesType > _expenses_list_capital_costs
List of capital expenses.
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
static const StringID _company_view_vehicle_count_strings[]
Strings for the company vehicle counts.
static const std::initializer_list< ExpensesList > _expenses_list_types
Types of expense lists.
static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
Draw an amount of money.
static void ShowCompanyInfrastructure(CompanyID company)
Open the infrastructure window of a company.
static void DrawCategories(const Rect &r)
Draw the expenses categories.
static void DoSelectCompanyManagerFace(Window *parent)
Company GUI constants.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
static constexpr NWidgetPart _nested_select_company_manager_face_widgets[]
Nested widget description for the company manager face selection dialog.
static const std::initializer_list< ExpensesType > _expenses_list_operating_costs
List of operating expenses.
static uint GetTotalCategoriesHeight()
Get the total height of the "categories" column.
static const std::initializer_list< ExpensesType > _expenses_list_revenue
List of revenues.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
Draw a category of expenses (revenue, operating expenses, capital expenses).
Functionality related to the company manager's face.
uint64_t GetActiveFaceVars(const CompanyManagerFace &cmf, FaceVars vars)
Get a bitmask of currently active face variables.
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars)
Scales all company manager's face bits to the correct scope.
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS
The maximum length of a president name in characters including '\0'.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Common drop down list components.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Command definitions related to the economy.
std::array< Money, EXPENSES_END > Expenses
Data type for storage of Money for each ExpensesType category.
ExpensesType
Types of expenses.
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
@ EXPENSES_TRAIN_RUN
Running costs trains.
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
@ EXPENSES_CONSTRUCTION
Construction costs.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
@ EXPENSES_PROPERTY
Property costs.
@ EXPENSES_OTHER
Other expenses.
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
@ EXPENSES_SHIP_RUN
Running costs ships.
@ EXPENSES_NEW_VEHICLES
New vehicles.
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Functions related to errors.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool _shift_pressed
Is Shift pressed?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
uint GetStringListWidth(std::span< const StringID > list, FontSize fontsize)
Get maximum width of a list of strings.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_TOP
Top align the text.
@ SA_LEFT
Left align the text.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ SA_CENTER
Center both horizontally and vertically.
@ SA_VERT_CENTER
Vertically center the text.
uint32_t PaletteID
The number of the palette.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Command definitions related to engine groups.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void BuildGuiGroupList(GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.
Functions/definitions that have something to do with groups.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
static const uint8_t LIT_ALL
Show the liveries of all companies.
LiveryScheme
List of different livery schemes.
static const uint8_t LIT_COMPANY
Show the liveries of your own company.
LiveryClass
List of different livery classes, used only by the livery GUI.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Miscellaneous command definitions.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Basic functions/variables used all over the place.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
Network functions used by other parts of OpenTTD.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
GUIs related to networking.
@ CLIENT_ID_SERVER
Servers always have this ID.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Base for the NewGRF implementation.
Command definitions related to objects.
Types related to object tiles.
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
static const uint8_t PC_WHITE
White palette colour.
static const uint8_t PC_BLACK
Black palette colour.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Money RailMaintenanceCost(RailType railtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of track bits.
Money SignalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of signals.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType
Enumeration for all possible railtypes.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Functions related to roads.
Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of road bits.
RoadType
The different roadtypes we support.
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.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Base types for having sorted lists in GUIs.
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Functions related to stations.
Money StationMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of station tiles.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
@ CS_NUMERAL
Only numeric ones.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Money company_value
The value of the company for which the user can buy it.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
bool hostile_takeover
Whether the window is showing a hostile takeover.
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the company value has changed.
GUISettings gui
settings related to the GUI
Window class displaying the company finances.
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the maximum amount of money has changed.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int, bool) override
Some data on this window has become invalid.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
bool small
Window is toggled to 'small'.
static Money max_money
The maximum amount of money a company has had this 'run'.
uint8_t first_visible
First visible expenses column. The last column (current) is always visible.
void SetupWidgets()
Setup the widgets in the nested tree, such that the finances window is displayed properly.
void OnPaint() override
The window must be repainted.
Window with detailed information about the company's infrastructure.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
@ Value
Label with values.
void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) override
Resize window towards the default size.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnResize() override
Called after the window got resized.
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
uint32_t GetRailTotal() const
Get total sum of all owned track bits.
uint32_t GetRoadTotal() const
Get total sum of all owned road bits.
uint32_t station
Count of company owned station tiles.
uint32_t signal
Count of company owned signals.
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
uint32_t GetTramTotal() const
Get total sum of all owned tram bits.
uint32_t airport
Count of company owned airports.
uint32_t water
Count of company owned track bits for canals.
uint32_t bits
Company manager face bits, meaning is dependent on style.
uint style
Company manager face style.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Money current_loan
Amount of money borrowed from the bank.
TimerGameCalendar::Year inaugurated_year_calendar
Calendar year of starting the company. Used to display proper Inauguration year while in wallclock mo...
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Colours colour
Company colour.
CompanyManagerFace face
Face description of the president.
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Money money
Money owned by the company.
Window with general information about a company.
void OnResize() override
Called after the window got resized.
const IntervalTimer< TimerWindow > redraw_interval
Redraw the window on a regular interval.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
CompanyWindowPlanes
Display planes in the company window.
@ CWP_RELOCATE_SHOW
Show the relocate HQ button.
@ CWP_RELOCATE_HIDE
Hide the relocate HQ button.
@ CWP_VB_BUILD
Display the build button.
@ CWP_VB_VIEW
Display the view button.
void OnPaint() override
The window must be repainted.
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
std::array< GroupStatistics, VEH_COMPANY_END > group_all
NOSAVE: Statistics for the ALL_GROUP group.
uint16_t rate
The conversion rate compared to the base currency.
uint8_t initial_interest
amount of interest (to pay over the loan)
Dimensions (a width and height) of a rectangle in 2D.
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
bool give_money
allow giving other companies money
uint GetListWidth() const
Compute width of the expenses categories in pixels.
const std::initializer_list< ExpensesType > & items
List of expenses types.
const StringID title
StringID of list title.
Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.
uint8_t position
Position in UI.
uint8_t valid_values
The number of valid values.
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
uint64_t used_liveries
Bitmask of LiveryScheme used by the defined engines.
uint8_t liveries
options for displaying company liveries, 0=none, 1=self, 2=all
EconomySettings economy
settings to change the economy
DifficultySettings difficulty
settings related to the difficulty
Livery livery
Custom colour scheme for vehicles in this group.
GroupID parent
Parent group.
VehicleType vehicle_type
Vehicle type of the group.
Information about a particular livery.
Colours colour2
Second colour, for vehicles with 2CC support.
Colours colour1
First colour, for all vehicles.
uint8_t in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect CentreTo(int width, int height) const
Centre a dimension within this Rect.
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.
int Height() const
Get height of Rect.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
uint step_height
Step-size of height resize changes.
Company livery colour scheme window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnResize() override
Called after the window got resized.
Iterable ensemble of each set bit in a value.
Templated helper to make a type-safe 'typedef' representing a single POD value.
High level window description.
Number to differentiate different windows of the same class.
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)
Window * parent
Parent window.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
bool IsShaded() const
Is window shaded currently?
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
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.
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
the length of the string is counted in characters
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the Window system.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
@ VEH_COMPANY_END
Last company-ownable type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Functions related to water (management)
Money CanalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of canal tiles.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_FINANCES
Finances of a company; Window numbers:
@ WC_COMPANY_MANAGER_FACE
Alter company face window; Window numbers:
@ WC_COMPANY
Company view; Window numbers:
Functions related to zooming.