48#include "table/strings.h"
53static std::array<VehicleTypeIndexArray<BaseVehicleListWindow::GroupBy>, VLT_END> _grouping{};
54static std::array<Sorting, BaseVehicleListWindow::GB_END> _sorting{};
56static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNumberSorter;
57static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNameSorter;
58static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleAgeSorter;
59static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitThisYearSorter;
60static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleProfitLastYearSorter;
61static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleCargoSorter;
62static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleReliabilitySorter;
63static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleMaxSpeedSorter;
64static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleModelSorter;
65static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleValueSorter;
66static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleLengthSorter;
67static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimeToLiveSorter;
68static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleTimetableDelaySorter;
69static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupLengthSorter;
70static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitThisYearSorter;
71static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupTotalProfitLastYearSorter;
72static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitThisYearSorter;
73static BaseVehicleListWindow::VehicleGroupSortFunction VehicleGroupAverageProfitLastYearSorter;
76template <BaseVehicleListWindow::VehicleIndiv
idualSortFunction func>
82const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * const> BaseVehicleListWindow::vehicle_group_none_sorter_funcs = {
98const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar = {
102 STR_SORT_BY_PROFIT_THIS_YEAR,
103 STR_SORT_BY_PROFIT_LAST_YEAR,
104 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
105 STR_SORT_BY_RELIABILITY,
106 STR_SORT_BY_MAX_SPEED,
110 STR_SORT_BY_LIFE_TIME,
111 STR_SORT_BY_TIMETABLE_DELAY,
114const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock = {
118 STR_SORT_BY_PROFIT_THIS_PERIOD,
119 STR_SORT_BY_PROFIT_LAST_PERIOD,
120 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
121 STR_SORT_BY_RELIABILITY,
122 STR_SORT_BY_MAX_SPEED,
126 STR_SORT_BY_LIFE_TIME,
127 STR_SORT_BY_TIMETABLE_DELAY,
130const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * const> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs = {
131 &VehicleGroupLengthSorter,
132 &VehicleGroupTotalProfitThisYearSorter,
133 &VehicleGroupTotalProfitLastYearSorter,
134 &VehicleGroupAverageProfitThisYearSorter,
135 &VehicleGroupAverageProfitLastYearSorter,
138const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar = {
139 STR_SORT_BY_NUM_VEHICLES,
140 STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
141 STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
142 STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR,
143 STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR,
146const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock = {
147 STR_SORT_BY_NUM_VEHICLES,
148 STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD,
149 STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD,
150 STR_SORT_BY_AVERAGE_PROFIT_THIS_PERIOD,
151 STR_SORT_BY_AVERAGE_PROFIT_LAST_PERIOD,
154const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_by_names = {
156 STR_GROUP_BY_SHARED_ORDERS,
161 STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
162 STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
163 STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
164 STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
169 this->vehicle_sel = VehicleID::Invalid();
170 this->grouping = _grouping[vli.
type][vli.
vtype];
171 this->UpdateSortingFromGrouping();
174std::span<const StringID> BaseVehicleListWindow::GetVehicleSorterNames()
const
179 case GB_SHARED_ORDERS:
193 if (number >= 10000)
return 5;
194 if (number >= 1000)
return 4;
195 if (number >= 100)
return 3;
213 for (
const Vehicle *v : vehicles) {
214 unitnumber = std::max<uint>(unitnumber, v->unitnumber);
220void BaseVehicleListWindow::BuildVehicleList()
222 if (!this->
vehgroups.NeedRebuild())
return;
224 Debug(misc, 3,
"Building vehicle list type {} for company {} given index {}", this->
vli.type, this->vli.company, this->vli.index);
232 for (
const Vehicle *u = v; u !=
nullptr; u = u->Next()) {
233 if (u->cargo_cap > 0) used.
Set(u->cargo_type);
236 this->used_cargoes = used;
239 uint max_unitnumber = 0;
240 for (
auto it = this->
vehicles.begin(); it != this->vehicles.end(); ++it) {
241 this->
vehgroups.emplace_back(it, it + 1);
243 max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
248 std::stable_sort(this->
vehicles.begin(), this->vehicles.end(), [](
const Vehicle *
const &u,
const Vehicle *
const &v) {
249 return u->FirstShared() < v->FirstShared();
252 uint max_num_vehicles = 0;
254 VehicleList::const_iterator begin = this->
vehicles.begin();
255 while (begin != this->
vehicles.end()) {
256 VehicleList::const_iterator end = std::find_if_not(begin, this->
vehicles.cend(), [first_shared = (*begin)->FirstShared()](
const Vehicle *
const &v) {
257 return v->FirstShared() == first_shared;
260 this->
vehgroups.emplace_back(begin, end);
262 max_num_vehicles = std::max<uint>(max_num_vehicles,
static_cast<uint
>(end - begin));
272 this->vscroll->SetCount(this->
vehgroups.size());
287 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
288 if (w->cargo_cap > 0) {
294 bool have_capacity =
false;
295 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
296 if (w->cargo_cap > 0) {
300 have_capacity =
true;
304 return have_capacity;
306 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
307 if (w->cargo_cap > 0 && w->cargo_type == cargo_type) {
355 overlays.emplace_back(rtl ? x - width : x, rtl ? x : x + width, v->
cargo_type, v->
cargo_cap);
359 overlays.back().left -= width;
361 overlays.back().right += width;
363 overlays.back().cargo_cap += v->
cargo_cap;
381 if (spr == 0)
return;
394 DrawSprite(spr, PAL_NONE, x - d.width, y - d.height);
404 for (
const auto &cio : overlays) {
405 if (cio.cargo_cap == 0)
continue;
435 this->
vehgroups.SetFilterFuncs(_vehicle_group_filter_funcs);
445 if (this->vehicles.empty()) {
471 }
else if (show_create) {
486 switch (cargo_type) {
513 if (!full && !this->used_cargoes.Test(cs->Index()))
continue;
514 list.push_back(
MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false, !this->used_cargoes.Test(cs->Index())));
532 if (show_autoreplace) {
542 }
else if (show_create) {
557void BaseVehicleListWindow::SortVehicleList()
567 if (list->size() < 2)
return;
568 std::sort(list->begin(), list->end(), &VehicleNumberSorter);
586 }
else if (display_profit_last_year < 0) {
587 spr = SPR_PROFIT_NEGATIVE;
589 spr = SPR_PROFIT_SOME;
591 spr = SPR_PROFIT_LOT;
614 static std::vector<StringID> subtypes;
622 uint8_t ret_refit_cyc = 0;
623 bool success =
false;
624 if (!subtypes.empty()) {
627 const Engine *e = v->GetEngine();
629 if (!e->info.refit_mask.
Test(dest_cargo_type) && v->cargo_type != dest_cargo_type)
continue;
631 CargoType old_cargo_type = v->cargo_type;
632 uint8_t old_cargo_subtype = v->cargo_subtype;
635 v->cargo_type = dest_cargo_type;
639 v->cargo_subtype = refit_cyc;
642 v->First()->InvalidateNewGRFCache();
643 v->InvalidateNewGRFCache();
646 if (subtype == STR_EMPTY)
break;
648 if (std::ranges::find(subtypes, subtype) == subtypes.end())
continue;
651 ret_refit_cyc = refit_cyc;
657 v->cargo_type = old_cargo_type;
658 v->cargo_subtype = old_cargo_subtype;
661 v->First()->InvalidateNewGRFCache();
662 v->InvalidateNewGRFCache();
668 return ret_refit_cyc;
684 return other.
cargo == this->cargo && other.
string == this->string;
709 int iconleft = rtl ? ir.right - iconwidth : ir.left;
710 int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2;
711 int iconinner = rtl ? ir.right - iconwidth : ir.left + iconwidth;
716 for (
const auto &pair : refits) {
717 bool has_subtypes = pair.second.size() > 1;
719 if (current >= pos + rows)
break;
722 if ((sel ==
nullptr || sel->
cargo != refit.
cargo) && refit.
subtype != UINT8_MAX)
continue;
731 if (refit.
subtype != UINT8_MAX) {
735 GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
775 std::optional<RefitOption> current_refit_option;
776 if (this->selected_refit !=
nullptr) current_refit_option = *(this->selected_refit);
777 this->selected_refit =
nullptr;
779 this->refit_list.clear();
783 VehicleSet vehicles_to_refit;
787 if (v->
type ==
VehicleType::Train && std::ranges::find(vehicles_to_refit, v->index) == vehicles_to_refit.end())
continue;
789 CargoTypes cmask = e->info.refit_mask;
801 if (!cmask.
Test(cargo_type))
continue;
803 auto &list = this->refit_list[cargo_type];
804 bool first_vehicle = list.empty();
807 list.emplace_back(cargo_type, UINT8_MAX, STR_EMPTY);
833 if (subtype == STR_EMPTY)
break;
835 RefitOption option{cargo_type,
static_cast<uint8_t
>(refit_cyc), subtype};
839 if (subtype == STR_EMPTY) {
842 for (uint i = 1; i < list.size(); i++) {
843 if (list[i].subtype >= refit_cyc) {
844 list.erase(list.begin() + i, list.end());
852 while (pos < list.size() && list[pos].subtype != refit_cyc) pos++;
853 if (pos < list.size() && list[pos].string != subtype) {
855 list.erase(list.begin() + pos);
873 if (current_refit_option.has_value()) {
874 for (
const auto &pair : this->refit_list) {
875 for (
const auto &refit : pair.second) {
876 if (refit.cargo == current_refit_option->cargo && refit.subtype == current_refit_option->subtype) {
877 this->selected_refit = &refit;
881 if (this->selected_refit !=
nullptr)
break;
893 size_t scroll_row = 0;
895 CargoType cargo = this->selected_refit ==
nullptr ? INVALID_CARGO : this->selected_refit->
cargo;
897 for (
const auto &pair : this->refit_list) {
898 if (pair.first == cargo) {
900 scroll_row = rows + (this->selected_refit - pair.second.data());
901 rows += pair.second.size();
921 if (row == click_row) {
922 this->selected_refit = &refit;
927 if (this->selected_refit ==
nullptr || this->selected_refit->
cargo != refit.
cargo)
break;
932 this->selected_refit =
nullptr;
965 if (this->hscroll !=
nullptr) this->hscroll->
SetCount(this->vehicle_width);
969 int sprite_width = std::max(0, ((
int)vehicle_panel_display->
current_x - this->vehicle_width) / 2);
970 this->sprite_left = vehicle_panel_display->
pos_x;
971 this->sprite_right = vehicle_panel_display->
pos_x + vehicle_panel_display->
current_x - 1;
973 this->sprite_right -= sprite_width;
976 this->sprite_left += sprite_width;
988 size.height =
resize.height * 8;
996 size.width = this->information_width + padding.height;
1017 auto [cost, refit_capacity, mail_capacity, cargo_capacities] = Command<Commands::RefitVehicle>::Do(
DoCommandFlag::QueryCost, this->selected_vehicle, option.
cargo, option.
subtype, this->auto_refit,
false, this->num_vehicles);
1019 if (cost.Failed())
return {};
1021 Money money = cost.GetCost();
1022 if (mail_capacity > 0) {
1025 return GetString(STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, option.
cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
1029 return GetString(STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT, option.
cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity, -money);
1032 return GetString(STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT, option.
cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity, money);
1037 return GetString(STR_PURCHASE_INFO_CAPACITY, option.
cargo, refit_capacity, STR_EMPTY);
1041 return GetString(STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT, option.
cargo, refit_capacity, -money);
1044 return GetString(STR_REFIT_NEW_CAPACITY_COST_OF_REFIT, option.
cargo, refit_capacity, money);
1053 VehicleID::Invalid(),
EIT_IN_DETAILS, this->hscroll !=
nullptr ? this->hscroll->GetPosition() : 0);
1060 VehicleSet vehicles_to_refit;
1063 int left = INT32_MIN;
1069 const int highlight_bottom = highlight_top +
height - 1;
1073 const bool contained = std::ranges::find(vehicles_to_refit, u->index) != vehicles_to_refit.end();
1074 if (contained &&
left == INT32_MIN) {
1075 left = x - this->hscroll->
GetPosition() + r.left + this->vehicle_margin;
1080 if ((!contained || u->Next() ==
nullptr) &&
left != INT32_MIN) {
1081 if (u->Next() ==
nullptr && contained) {
1082 int current_width = u->GetDisplayImageWidth();
1083 width += current_width;
1095 if (
left != right) {
1096 Rect hr = {
left, highlight_top, right, highlight_bottom};
1103 int current_width = u->GetDisplayImageWidth();
1104 width += current_width;
1120 if (this->selected_refit !=
nullptr) {
1122 if (!
string.empty()) {
1135 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1142 this->selected_vehicle = v->index;
1143 this->num_vehicles = UINT8_MAX;
1148 if (!gui_scope)
break;
1156 for (
const auto &list : this->refit_list) {
1159 if (!
string.empty()) {
1161 max_width = std::max(dim.width, max_width);
1166 if (this->information_width < max_width) {
1167 this->information_width = max_width;
1174 if (!gui_scope)
break;
1180 int GetClickPosition(
int click_x)
1184 click_x -= this->vehicle_margin;
1190 void SetSelectedVehicles(
int drag_x)
1192 drag_x = GetClickPosition(drag_x);
1194 int left_x = std::min(this->
click_x, drag_x);
1195 int right_x = std::max(this->
click_x, drag_x);
1205 bool start_counting =
false;
1206 for (; u !=
nullptr; u = u->
Next()) {
1208 left_x -= current_width;
1209 right_x -= current_width;
1211 if (left_x < 0 && !start_counting) {
1213 start_counting =
true;
1222 if (right_x < 0)
break;
1248 this->click_x = GetClickPosition(pt.x - nwi->
pos_x);
1249 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1265 if (click_count == 1)
break;
1270 if (this->selected_refit !=
nullptr) {
1274 bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
1275 if (Command<Commands::RefitVehicle>::Post(GetCmdRefitVehMsg(v), v->
tile, this->selected_vehicle, this->selected_refit->cargo, this->selected_refit->subtype,
false,
false, this->num_vehicles) && delete_window) this->
Close();
1277 if (Command<Commands::OrderRefit>::Post(v->
tile, v->index, this->order, this->selected_refit->cargo)) this->
Close();
1290 this->SetSelectedVehicles(pt.
x - nwi->
pos_x);
1303 this->SetSelectedVehicles(pt.
x - nwi->
pos_x);
1318static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_refit_widgets = {
1334 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_VR_MATRIX),
SetMinimalSize(228, 112),
SetResize(1, 14),
SetFill(1, 1),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_VR_SCROLLBAR),
1349 _nested_vehicle_refit_widgets
1385 str =
GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_PURCHASE_INFO_ALL_TYPES, std::monostate{});
1389 CargoTypes excluded = CargoTypes{present}.Flip(
_cargo_mask);
1390 uint num_excluded = excluded.
Count();
1391 if (num_excluded < present.
Count() && num_excluded <= 7) {
1392 str =
GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_PURCHASE_INFO_ALL_BUT, excluded);
1394 str =
GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_JUST_CARGO_LIST, present);
1409 std::array<int32_t, 1> regs100;
1411 if (v->
GetGRF()->grf_version < 8 && cb == 0xFF)
return STR_EMPTY;
1426 return a.NumVehicles() < b.NumVehicles();
1432 return a.GetDisplayProfitThisYear() < b.GetDisplayProfitThisYear();
1438 return a.GetDisplayProfitLastYear() < b.GetDisplayProfitLastYear();
1444 return a.GetDisplayProfitThisYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitThisYear() *
static_cast<uint
>(a.NumVehicles());
1450 return a.GetDisplayProfitLastYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitLastYear() *
static_cast<uint
>(a.NumVehicles());
1462 static std::string last_name[2] = { {}, {} };
1466 last_name[0] =
GetString(STR_VEHICLE_NAME, a->index);
1471 last_name[1] =
GetString(STR_VEHICLE_NAME, b->index);
1475 return (r != 0) ? r < 0: VehicleNumberSorter(a, b);
1481 auto r = a->
age - b->
age;
1482 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1486static bool VehicleProfitThisYearSorter(
const Vehicle *
const &a,
const Vehicle *
const &b)
1489 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1493static bool VehicleProfitLastYearSorter(
const Vehicle *
const &a,
const Vehicle *
const &b)
1496 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1510 for (uint d : diff) {
1515 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1519static bool VehicleReliabilitySorter(
const Vehicle *
const &a,
const Vehicle *
const &b)
1522 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1529 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1536 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1545 for (u = a; u !=
nullptr; u = u->
Next()) diff += u->
value;
1546 for (u = b; u !=
nullptr; u = u->
Next()) diff -= u->
value;
1549 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1556 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1560static bool VehicleTimeToLiveSorter(
const Vehicle *
const &a,
const Vehicle *
const &b)
1563 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1567static bool VehicleTimetableDelaySorter(
const Vehicle *
const &a,
const Vehicle *
const &b)
1570 return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
1594 if (_thd.window_class == window_class && _thd.window_number == from_index) {
1595 _thd.window_number = to_index;
1617static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_list = {
1653 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_VL_LIST),
SetMinimalSize(248, 0),
SetFill(1, 0),
SetResize(1, 1),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_VL_SCROLLBAR),
1661 SetToolTip(STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
1664 SetStringTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
1666 SetSpriteTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
1668 SetSpriteTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
1677static void DrawSmallOrderList(
const Vehicle *v,
int left,
int right,
int y, uint order_arrow_width,
VehicleOrderID start)
1679 auto orders = v->Orders();
1680 if (orders.empty())
return;
1683 int l_offset = rtl ? 0 : order_arrow_width;
1684 int r_offset = rtl ? order_arrow_width : 0;
1691 if (orders[oid].IsType(OT_GOTO_STATION)) {
1695 if (++i == 4)
break;
1699 }
while (oid != start);
1710static void DrawSmallOrderList(
const OrderList *orderlist,
int left,
int right,
int y, uint order_arrow_width)
1712 if (orderlist ==
nullptr)
return;
1715 int l_offset = rtl ? 0 : order_arrow_width;
1716 int r_offset = rtl ? order_arrow_width : 0;
1719 for (
const Order &order : orderlist->GetOrders()) {
1720 if (order.IsType(OT_GOTO_STATION)) {
1724 if (++i == 4)
break;
1744 default: NOT_REACHED();
1761 if (divisor == 1)
return base;
1764 uint rem = base % divisor;
1765 return base + (rem == 0 ? 0 : divisor - rem);
1796 int image_left = (rtl && show_orderlist) ? olr.right : tr.left;
1797 int image_right = (!rtl && show_orderlist) ? olr.left : tr.right;
1799 int vehicle_button_x = rtl ? ir.right - profit.width : ir.left;
1802 for (
auto it = first; it != last; ++it) {
1807 vehgroup.GetDisplayProfitThisYear(),
1808 vehgroup.GetDisplayProfitLastYear()));
1814 const Vehicle *v = vehgroup.GetSingleVehicle();
1824 CargoTypes vehicle_cargoes{};
1826 for (
auto u = v; u !=
nullptr; u = u->
Next()) {
1832 if (!v->
name.empty()) {
1835 GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_VEHICLE_NAME, v->index, STR_VEHICLE_LIST_CARGO, vehicle_cargoes),
1840 GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_GROUP_NAME, v->
group_id, STR_VEHICLE_LIST_CARGO, vehicle_cargoes),
1846 }
else if (!v->
name.empty()) {
1867 case GB_SHARED_ORDERS:
1868 assert(vehgroup.NumVehicles() > 0);
1870 for (
int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
1888void BaseVehicleListWindow::UpdateSortingFromGrouping()
1898 default: NOT_REACHED();
1900 this->
vehgroups.SetSortFuncs(this->GetVehicleSorterFuncs());
1906void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
1914 _grouping[this->
vli.type][this->
vli.vtype] = group_by;
1915 this->UpdateSortingFromGrouping();
1923struct VehicleListWindow :
public BaseVehicleListWindow {
1965 this->BuildVehicleList();
1966 this->SortVehicleList();
1981 switch (this->vli.
vtype) {
1984 size.height = 6 *
resize.height;
1988 size.height = 4 *
resize.height;
1990 default: NOT_REACHED();
1997 d.height += padding.height;
2008 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
2009 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
2010 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
2011 size.width += padding.width;
2020 d.height += padding.height;
2021 d.width += padding.width;
2045 switch (this->vli.
type) {
2047 return GetString(stringid, this->vehicles.size());
2050 return GetString(stringid, STR_COMPANY_NAME, this->vli.ToCompanyID(), std::monostate{}, this->vehicles.size());
2056 return GetString(stringid, STR_DEPOT_CAPTION, this->vli.
vtype, this->vli.ToDestinationID(), this->vehicles.size());
2058 default: NOT_REACHED();
2083 this->BuildVehicleList();
2084 this->SortVehicleList();
2109 bool last_overlay_state =
false;
2123 assert(!this->vehicles.empty());
2124 ShowOrdersWindow(this->vehicles[0]);
2142 static std::string cargo_filter;
2149 if (it == this->
vehgroups.end())
return;
2154 const Vehicle *v = vehgroup.GetSingleVehicle();
2165 case GB_SHARED_ORDERS: {
2166 assert(vehgroup.NumVehicles() > 0);
2170 ShowOrdersWindow(v);
2172 if (vehgroup.NumVehicles() == 1) {
2175 ShowVehicleListWindow(v);
2182 default: NOT_REACHED();
2208 this->UpdateVehicleGroupBy(
static_cast<GroupBy
>(index));
2220 assert(!this->vehicles.empty());
2231 case ADI_CREATE_GROUP:
2235 default: NOT_REACHED();
2239 default: NOT_REACHED();
2247 StationID station = (this->vli.
type ==
VL_STATION_LIST) ? this->vli.ToStationID() : StationID::Invalid();
2249 Debug(misc, 3,
"Periodic resort {} list company {} at station {}", this->vli.
vtype, this->owner, station);
2264 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2268 this->vli.SetIndex(
GB(data, 0, 20));
2289 _nested_vehicle_list
2295 _nested_vehicle_list
2301 _nested_vehicle_list
2307 _nested_vehicle_list
2311static void ShowVehicleListWindowLocal(CompanyID company,
VehicleListType vlt,
VehicleType vehicle_type, uint32_t unique_number)
2320void ShowVehicleListWindow(CompanyID company,
VehicleType vehicle_type)
2330 ShowVehicleListWindowLocal(company,
VL_STANDARD, vehicle_type, company.base());
2334void ShowVehicleListWindow(
const Vehicle *v)
2339void ShowVehicleListWindow(CompanyID company,
VehicleType vehicle_type, StationID station)
2341 ShowVehicleListWindowLocal(company,
VL_STATION_LIST, vehicle_type, station.base());
2374 SetStringTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2391 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_VD_MATRIX),
SetResize(1, 1),
SetMinimalSize(393, 45),
SetMatrixDataTip(1, 0),
SetFill(1, 0),
SetScrollbar(
WID_VD_SCROLLBAR),
2400 SetStringTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2423static const StringID _service_interval_dropdown_calendar[] = {
2424 STR_VEHICLE_DETAILS_DEFAULT,
2425 STR_VEHICLE_DETAILS_DAYS,
2426 STR_VEHICLE_DETAILS_PERCENT,
2429static const StringID _service_interval_dropdown_wallclock[] = {
2430 STR_VEHICLE_DETAILS_DEFAULT,
2431 STR_VEHICLE_DETAILS_MINUTES,
2432 STR_VEHICLE_DETAILS_PERCENT,
2461 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2468 if (!gui_scope)
return;
2474 if (aimed_height != nwid_info->
current_y) {
2487 uint desired_height;
2492 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
2498 return desired_height;
2516 size.width = dim.width + padding.width;
2543 size.height = 4 *
resize.height;
2548 d.width += padding.width;
2549 d.height += padding.height;
2564 size.width += padding.width;
2581 switch (vehicle_type) {
2582 default: NOT_REACHED();
2606 default: NOT_REACHED();
2709 GetString(v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_MINUTES,
2710 v->GetServiceInterval(), STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO, minutes_since_serviced));
2716 GetString(v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS,
2739 !v->ServiceIntervalIsCustom() ? STR_VEHICLE_DETAILS_DEFAULT :
2740 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT :
2763 if (mod == v->GetServiceInterval())
return;
2765 Command<Commands::ChangeServiceInterval>::Post(STR_ERROR_CAN_T_CHANGE_SERVICING, v->index, mod,
true, v->ServiceIntervalIsPercent());
2773 v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
2798 if (v->ServiceIntervalIsPercent()) {
2799 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT;
2801 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES;
2803 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_DAYS : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_DAYS;
2817 bool iscustom = index != 0;
2818 bool ispercent = iscustom ? (index == 2) :
Company::Get(v->
owner)->settings.vehicle.servint_ispercent;
2820 Command<Commands::ChangeServiceInterval>::Post(STR_ERROR_CAN_T_CHANGE_SERVICING, v->index, interval, iscustom, ispercent);
2829 if (nwi !=
nullptr) {
2891 SetSpriteTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
2896 SetSpriteTip(SPR_FORCE_VEHICLE_TURN, STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP),
2934 VCT_CMD_START_STOP = 0,
2936 VCT_CMD_TURN_AROUND,
2942 STR_ERROR_CAN_T_STOP_START_TRAIN,
2943 STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
2944 STR_ERROR_CAN_T_STOP_START_SHIP,
2945 STR_ERROR_CAN_T_STOP_START_AIRCRAFT
2948 STR_ERROR_CAN_T_BUY_TRAIN,
2949 STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
2950 STR_ERROR_CAN_T_BUY_SHIP,
2951 STR_ERROR_CAN_T_BUY_AIRCRAFT
2954 STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN,
2955 STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN,
2968 if (result.
Failed())
return;
3020 bool mouse_over_start_stop =
false;
3052 SPR_SEND_TRAIN_TODEPOT,
3053 SPR_SEND_ROADVEH_TODEPOT,
3054 SPR_SEND_SHIP_TODEPOT,
3055 SPR_SEND_AIRCRAFT_TODEPOT,
3085 default: NOT_REACHED();
3104 void Close([[maybe_unused]]
int data = 0)
override
3168 if (mainwindow->
viewport->follow_vehicle == v->index) {
3180 return GetString(STR_VEHICLE_VIEW_CAPTION, v->index);
3183 std::string GetVehicleStatusString(
const Vehicle *v,
TextColour &text_colour)
const
3185 text_colour = TC_BLACK;
3194 if (
Train::From(v)->gcache.cached_power == 0)
return GetString(STR_VEHICLE_STATUS_TRAIN_NO_POWER);
3195 return GetString(STR_VEHICLE_STATUS_STOPPED);
3205 if (mouse_over_start_stop) {
3214 case OT_GOTO_STATION:
3218 case OT_GOTO_DEPOT: {
3240 return GetString(STR_VEHICLE_STATUS_LOADING_UNLOADING);
3242 case OT_GOTO_WAYPOINT:
3247 case OT_LEAVESTATION:
3249 return GetString(STR_VEHICLE_STATUS_LEAVING);
3273 DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl),
SA_CENTER);
3278 std::string str = GetVehicleStatusString(v, text_colour);
3315 if (click_count > 1) {
3317 mainwindow->
viewport->follow_vehicle = v->index;
3319 if (mainwindow->
viewport->follow_vehicle == v->index) mainwindow->
viewport->follow_vehicle = VehicleID::Invalid();
3336 ShowOrdersWindow(v);
3365 Command<Commands::ForceTrainProceed>::Post(STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL, v->
tile, v->index);
3377 if (mainwindow->
viewport->follow_vehicle == v->index) {
3386 if (!str.has_value())
return;
3388 Command<Commands::RenameVehicle>::Post(STR_ERROR_CAN_T_RENAME_TRAIN +
to_underlying(
Vehicle::Get(this->window_number)->type),
static_cast<VehicleID>(this->window_number), *str);
3394 if (start_stop != mouse_over_start_stop) {
3395 mouse_over_start_stop = start_stop;
3445 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
3468 static inline HotkeyList hotkeys{
"vehicleview", {
3479 &VehicleViewWindow::hotkeys
3491 &VehicleViewWindow::hotkeys
3510 assert(v !=
nullptr);
3511 if (!(_thd.place_mode &
HT_VEHICLE))
return false;
3516 return _thd.GetCallbackWnd()->OnVehicleSelect(v);
3525bool VehicleClicked(VehicleList::const_iterator begin, VehicleList::const_iterator end)
3527 assert(begin != end);
3528 if (!(_thd.place_mode &
HT_VEHICLE))
return false;
3531 if (begin + 1 == end)
return _thd.GetCallbackWnd()->OnVehicleSelect(*begin);
3533 return _thd.GetCallbackWnd()->OnVehicleSelect(begin, end);
3546void StopGlobalFollowVehicle(
const Vehicle *v)
3549 if (w->
viewport->follow_vehicle == v->index) {
3564 if (result.
Failed())
return;
3604 int vehicle_width = 0;
3605 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
3608 return vehicle_width;
3623 _cursor.sprites.clear();
3624 int total_width = 0;
3626 bool rotor_seq =
false;
3629 while (v !=
nullptr) {
3630 if (total_width >=
ScaleSpriteTrad(2 * (
int)VEHICLEINFO_FULL_VEHICLE_WIDTH))
break;
3637 if (!seq.
IsValid()) seq.
Set(SPR_ROTOR_STOPPED);
3646 for (uint i = 0; i < seq.count; ++i) {
3648 _cursor.sprites.emplace_back(seq.seq[i].sprite, pal2, rtl ? (-total_width + x_offs) : (total_width + x_offs), y_offset);
3660 if (is_ground_vehicle) {
3662 int offs = (
ScaleSpriteTrad(VEHICLEINFO_FULL_VEHICLE_WIDTH) - total_width) / 2;
3663 if (rtl) offs = -offs;
3664 for (
auto &cs : _cursor.sprites) {
@ DestinationTooFar
Next destination is too far away.
@ AIR_HELICOPTER
an helicopter
void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Functions related to articulated vehicles.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Functions related to the autoreplace GUIs.
@ PathfinderLost
Vehicle's pathfinder is lost.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
CargoType
Cargo slots to indicate a cargo type within a game.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
CargoTypes _cargo_mask
Bitmask of cargo types available.
bool IsCargoInClass(CargoType cargo, CargoClasses cc)
Does cargo c have cargo class cc?
uint Count() const
Count the number of set bits.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Set()
Set all bits.
Common return value for all commands.
bool Failed() const
Did this command fail?
static constexpr int DAYS_IN_ECONOMY_MONTH
Days in an economy month, when in wallclock timekeeping mode.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
uint16_t reliability
Current reliability of the engine.
bool CanCarryCargo() const
Determines whether an engine can carry something.
bool(const GUIVehicleGroup *item, CargoType filter) FilterFunction
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGame< struct Economy >::Date MAX_DATE
static constexpr int DAYS_IN_YEAR
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
static constexpr int DAYS_IN_LEAP_YEAR
static Date date
Current date in days (day counter).
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static constexpr Year DateToYear(Date date)
static constexpr Date DateAtStartOfYear(Year year)
StrongType::Typedef< int32_t, DateTag< struct Economy >, StrongType::Compare, StrongType::Integer > Date
Functions related to commands.
@ QueryCost
query cost only, don't build.
Commands
List of commands.
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.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
Some simple functions to help with accessing containers.
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Command definitions related to depots.
void CcCloneVehicle(Commands, const CommandCost &result, VehicleID veh_id)
This is the Callback method after the cloning attempt of a vehicle.
Map related accessors for depots.
DestinationID GetDepotDestinationIndex(Tile t)
Get the destination index of a 'depot'.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
Creates new DropDownListIconItem.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Functions related to the drop down widget.
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.
@ Filterable
Set if the dropdown is filterable.
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Functions related to engines.
@ AutoRefit
Automatic refitting is allowed.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
@ Maglev
Maglev acceleration model.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
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.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
void UpdateCursorSize()
Update cursor dimension.
bool _shift_pressed
Is Shift pressed?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
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 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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ Small
Index of the small font in the font tables.
@ Normal
Index of the normal font in the font tables.
@ SA_LEFT
Left align the text.
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_CENTER
Center both horizontally and vertically.
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...
@ TC_FORCED
Ignore colour changes from strings.
Command definitions related to engine groups.
void CcAddVehicleNewGroup(Commands, const CommandCost &result, GroupID new_group, GroupID, VehicleID, bool, const VehicleListIdentifier &)
Open rename window after adding a vehicle to a new group via drag and drop.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group)
Show the group window for the given company and vehicle type.
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
Functions/definitions that have something to do with groups.
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
static constexpr GroupID ALL_GROUP
All vehicles are in this group.
static constexpr GroupID NEW_GROUP
Sentinel for a to-be-created group.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Hotkey related functions.
static bool CargoFilter(const Industry *const *industry, const std::pair< CargoType, CargoType > &cargoes)
Cargo filter functions.
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
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.
static constexpr CargoType CF_FREIGHT
Show only vehicles which carry any freight (non-passenger) cargo.
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines).
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering).
GrfSpecFeature GetGrfSpecFeature(VehicleType type)
Get the GrfSpecFeature associated with a VehicleType.
@ CargoSuffix
Show suffix after cargo name.
@ CBID_VEHICLE_CARGO_SUFFIX
Determine the cargo "suffixes" for each refit possibility of a cargo.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Functions/types related to NewGRF debugging.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
Header of Action 04 "universal holder" structure and functions.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
@ Vehicle
Vehicle news item. (new engine available).
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
Command definitions related to orders.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related).
@ Halt
Service the vehicle and then halt it.
@ Unbunch
Service the vehicle and then unbunch it.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel).
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
@ Normal
Normal colour shade.
Command definitions related to road vehicles.
void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a road vehicle chain.
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.
@ Off
Scroll wheel has no effect.
void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
Draws an image of a ship.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
static const PaletteID PALETTE_ALL_BLACK
Exchange any colour by black, needed for painting fictive tiles outside map.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
static const SpriteID SPR_CLONE_TRAIN
Clone vehicles stuff.
Base classes/functions for stations.
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
@ 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.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
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.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
static void PrepareArgsForNextRun(std::span< StringParameter > args)
Prepare the string parameters for the next formatting run, resetting the type information.
auto MakeParameters(Args &&... args)
Helper to create the StringParameters with its own buffer with the given parameter values.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
@ TD_RTL
Text is written right-to-left by default.
Aircraft, helicopters, rotors and their shadows belong to this class.
VehicleAirFlags flags
Aircraft flags.
std::string name
Name of vehicle.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
void SetCargoFilter(CargoType cargo_type)
Set cargo filter for the vehicle group list.
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
static const VehicleTypeIndexArray< const StringID > vehicle_depot_name
List of depot name strings for each VehicleType.
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
VehicleID vehicle_sel
Selected vehicle.
Listing * sorting
Pointer to the vehicle type related sorting.
GroupBy grouping
How we want to group the list.
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create)
Compute the size for the Action dropdown.
uint order_arrow_width
Width of the arrow in the small order list.
uint8_t unitnumber_digits
The number of digits of the highest unit number.
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create)
Display the Action dropdown window.
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
DropDownList BuildCargoDropDownList(bool full) const
Build drop down list for cargo filter selection.
void OnInit() override
Notification that the nested widget tree gets initialized.
CargoType cargo_filter_criteria
Selected cargo filter index.
void FilterVehicleList()
Filter the engine list against the currently selected cargo filter.
VehicleType type
Type of vehicle.
Class for storing amounts of cargo.
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
StringID name
Name of this type of cargo.
Comparator to sort CargoType by according to desired order.
Dimensions (a width and height) of a rectangle in 2D.
EngineMiscFlags misc_flags
Miscellaneous flags.
VehicleCallbackMasks callback_mask
Bitmask of vehicle callbacks that have to be called.
VehicleList::const_iterator vehicles_end
Pointer to past-the-end element of this vehicle group.
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Cached, frequently calculated values.
uint32_t cached_weight
Total weight of the consist (valid only for the first engine).
uint32_t cached_power
Total power of the consist (valid only for the first engine).
uint16_t cached_total_length
Length of the whole vehicle (valid only for the first engine).
uint32_t cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
List of hotkeys for a window.
All data for a single hotkey.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
VehicleOrderID GetNext(VehicleOrderID cur) const
Get the order after the given one or the first one, if the given one is the last one.
If you change this, keep in mind that it is also saved in 2 other places:
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
OrderType GetType() const
Get the type of order of this order.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Colour for pixel/line drawing.
static Vehicle * Get(auto index)
static bool IsValidID(auto index)
static Vehicle * GetIfValid(auto index)
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 WithX(int new_left, int new_right) const
Create a new Rect, replacing the left and right coordinates.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Option to refit a vehicle chain.
StringID string
GRF-local String to display for the cargo.
CargoType cargo
Cargo to refit to.
uint8_t subtype
Subcargo to use.
bool operator==(const RefitOption &other) const
Equality operator for RefitOption.
void OnInit() override
Notification that the nested widget tree gets initialized.
uint information_width
Width required for correctly displaying all cargoes in the information panel.
void SetSelection(uint click_row)
Select a row.
void BuildRefitList()
Collects all (cargo, subcargo) refit options of a vehicle chain.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
int sprite_left
Left position of the vehicle sprite.
void RefreshScrollbar()
Refresh scrollbar after selection changed.
RefitOptions refit_list
List of refit subtypes available for each sorted cargo.
void OnMouseDrag(Point pt, WidgetID widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
void OnResize() override
Called after the window got resized.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
const RefitOption * selected_refit
Selected refit option.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint vehicle_margin
Margin to use while selecting vehicles when the vehicle image is centered.
uint8_t num_vehicles
Number of selected vehicles.
bool auto_refit
Select cargo for auto-refitting.
int sprite_right
Right position of the vehicle sprite.
VehicleOrderID order
If not INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
VehicleID selected_vehicle
First vehicle in the current selection.
void OnPaint() override
The window must be repainted.
void OnDragDrop(Point pt, WidgetID widget) override
A dragged 'object' has been released.
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.
Scrollbar * hscroll
Only used for long vehicles.
int vehicle_width
Width of the vehicle being drawn.
Scrollbar * vscroll
The main scrollbar.
int click_x
Position of the first click while dragging.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
std::string GetCapacityString(const RefitOption &option) const
Gets the StringID to use for displaying capacity.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
static bool IsExpected(const BaseStation *st)
T * Next() const
Get next vehicle in the chain.
static Train * From(Vehicle *v)
'Train' is either a loco or a wagon.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
VehicleRailFlags flags
Which flags has this train currently set.
int GetCursorImageOffset() const
Get the offset for train image when it is used as cursor.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Default settings for vehicles.
uint16_t servint_aircraft
service interval for aircraft
uint16_t servint_roadveh
service interval for road vehicles
uint16_t servint_ships
service interval for ships
uint16_t servint_trains
service interval for trains
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
uint GetRoadVehDetailsHeight(const Vehicle *v)
Gets the desired height for the road vehicle details panel.
static void DrawVehicleDetails(const Vehicle *v, const Rect &r, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the position of the Details windows.
void OnPaint() override
Repaint vehicle details window.
static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
Checks whether service interval is enabled for the vehicle.
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 DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnResize() override
Called after the window got resized.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
VehicleDetailsWindow(WindowDesc &desc, WindowNumber window_number)
Initialize a newly created vehicle details window.
TrainDetailsWindowTabs tab
For train vehicles: which tab is displayed.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
The information about a vehicle list.
VehicleListType type
The type of vehicle list.
WindowNumber ToWindowNumber() const
Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber.
VehicleType vtype
The vehicle type associated with this list.
Window for the (old) vehicle listing.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
void OnResize() override
Called after the window got resized.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnPaint() override
The window must be repainted.
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 OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
CaptionPlanes
Enumeration of planes of the title row at the top.
@ BP_SHARED_ORDERS
Show the normal caption.
@ BP_NORMAL
Show shared orders caption and buttons.
void OnGameTick() override
Called once per (game) tick.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
~VehicleListWindow() override
Save the last sorting state.
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 data=0, bool gui_scope=true) override
Some data on this window has become invalid.
ButtonPlanes
Enumeration of planes of the button row at the bottom.
@ BP_HIDE_BUTTONS
Show the empty panel.
@ BP_SHOW_BUTTONS
Show the buttons.
Sprite sequence for a vehicle part.
bool IsValid() const
Check whether the sequence contains any sprites.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Window manager class for viewing a vehicle.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnResize() override
Called after the window got resized.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void SelectPlane(PlaneSelections plane)
Display a plane in the window.
PlaneSelections
Display planes available in the vehicle view window.
@ SEL_RT_BASEPLANE
First plane of the WID_VV_SELECT_REFIT_TURN stacked widget.
@ SEL_RT_TURN_AROUND
Display 'turn around' button in WID_VV_SELECT_REFIT_TURN stacked widget.
@ SEL_DC_BASEPLANE
First plane of the WID_VV_SELECT_DEPOT_CLONE stacked widget.
@ SEL_RT_REFIT
Display 'refit' button in WID_VV_SELECT_REFIT_TURN stacked widget.
@ SEL_DC_GOTO_DEPOT
Display 'goto depot' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
@ SEL_DC_CLONE
Display 'clone vehicle' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
void UpdatePlanes()
Selects appropriate plane for current state of the shown vehicle.
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.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnPaint() override
The window must be repainted.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void UpdateButtons()
Update buttons state to match shown vehicle.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
EngineID engine_type
The type of engine used for this vehicle.
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into string parameters for string processing.
int32_t z_pos
z coordinate.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
uint16_t cargo_cap
total capacity
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
bool HasArticulatedPart() const
Check if an engine has an articulated part.
uint8_t breakdown_ctr
Counter for managing breakdown events.
GroupID group_id
Index of group Pool array.
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
VehStates vehstatus
Status.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
CargoType cargo_type
type of cargo this vehicle is carrying
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Order current_order
The current order (+ status, like: loading).
Vehicle * Next() const
Get the next vehicle of this vehicle.
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
OrderList * orders
Pointer to the order list for this vehicle.
uint32_t GetDisplayMinPowerToWeight() const
Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle.
Vehicle * GetMovingFront() const
Get the moving front of the vehicle chain.
Money value
Value of the vehicle.
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
VehicleCache vcache
Cache of often used vehicle values.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
uint16_t cur_speed
current speed
uint8_t cargo_subtype
Used for livery refits (NewGRF variations).
TimerGameCalendar::Date age
Age in calendar days.
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into string parameters for string processing.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
TimerGameCalendar::Date max_age
Maximum age.
uint16_t reliability
Reliability.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
virtual void PlayLeaveStationSound(bool force=false) const
Play the sound associated with leaving the station.
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
TileIndex tile
Current tile index.
Owner owner
Which company owns the vehicle?
UnitID unitnumber
unit number, for display purposes only
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
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.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
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 SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
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.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
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.
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
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
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.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
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.
@ TE_RISING
Make the text effect slowly go upwards.
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Functions related to tile highlights.
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_DRAG
dragging items in the depot windows
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
Base for the train class.
@ Stuck
Train can't get a path reservation.
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
Command definitions related to trains.
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
Calculates the set of vehicles that will be affected by a given selection.
@ Crashed
Vehicle is crashed.
@ Stopped
Vehicle is stopped by the player.
Command definitions for vehicles.
void CcStartStopVehicle(Commands, const CommandCost &result, VehicleID veh_id, bool)
This is the Callback method after attempting to start/stop a vehicle.
Functions related to vehicles.
static const TimerGameEconomy::Date VEHICLE_PROFIT_MIN_AGE
Only vehicles older than this have a meaningful profit.
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
void DrawAircraftDetails(const Aircraft *v, const Rect &r)
Draw the details for the given vehicle at the given position.
static bool CargoFilter(const GUIVehicleGroup *vehgroup, const CargoType cargo_type)
Check whether a vehicle can carry a specific cargo.
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (part) in pixels.
void DrawShipDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
static const Vehicle * _last_vehicle[2]
Cached values for VehicleNameSorter to spare many GetString() calls.
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (including all parts of the consist) in pixels.
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
static WindowDesc _vehicle_view_desc(WindowPosition::Automatic, "view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, {}, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for all vehicles but trains.
static void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
Assign a vehicle window a new vehicle.
static VehicleTypeIndexArray< WindowDesc > _vehicle_list_desc
Window definitions for the vehicle list windows.
static bool IsVehicleRefittable(const Vehicle *v)
Checks whether the vehicle may be refitted at the moment.
static constexpr std::initializer_list< NWidgetPart > _nested_train_vehicle_details_widgets
Train details widgets.
static constexpr VehicleTypeIndexArray< const ZoomLevel > _vehicle_view_zoom_levels
Zoom levels for vehicle views indexed by vehicle type.
void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
static const int VV_INITIAL_VIEWPORT_HEIGHT
static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
static constexpr VehicleTypeIndexArray< const StringID > _vehicle_msg_translation_table[]
Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
static WindowDesc _train_vehicle_details_desc(WindowPosition::Automatic, "view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, {}, _nested_train_vehicle_details_widgets)
Vehicle details window descriptor.
uint CountDigitsForAllocatingSpace(uint number)
Get the number of digits of space required for the given number.
static const uint MAX_REFIT_CYCLE
Maximum number of refit cycles we try, to prevent infinite loops.
static WindowDesc _nontrain_vehicle_details_desc(WindowPosition::Automatic, "view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, {}, _nested_nontrain_vehicle_details_widgets)
Vehicle details window descriptor for other vehicles than a train.
VehicleCommandTranslation
Command indices for the _vehicle_command_translation_table.
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
static void DrawVehicleProfitButton(TimerGameEconomy::Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
Draw the vehicle profit button in the vehicle list window.
static int GetUnitNumberWidth(int digits)
Get width required for the formatted unit number display.
static constexpr std::initializer_list< NWidgetPart > _nested_vehicle_view_widgets
Vehicle view widgets.
static WindowDesc _vehicle_refit_desc(WindowPosition::Automatic, "view_vehicle_refit", 240, 174, WC_VEHICLE_REFIT, WC_VEHICLE_VIEW, WindowDefaultFlag::Construction, _nested_vehicle_refit_widgets)
Window definition for the vehicle refit window.
static bool CargoFilterSingle(const Vehicle *v, const CargoType cargo_type)
Check whether a single vehicle should pass the filter.
uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
static const int VV_INITIAL_VIEWPORT_WIDTH
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes Commands::StartStopVehicle for given vehicle.
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
void DrawCargoIconOverlays(std::span< const CargoIconOverlay > overlays, int y)
Draw a list of cargo icon overlays.
void AddCargoIconOverlay(std::vector< CargoIconOverlay > &overlays, int x, int width, const Vehicle *v)
Add a cargo icon to the list of overlays.
static constexpr std::initializer_list< NWidgetPart > _nested_nontrain_vehicle_details_widgets
Vehicle details widgets (other than train).
static bool VehicleIndividualToGroupSorterWrapper(GUIVehicleGroup const &a, GUIVehicleGroup const &b)
Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
void DrawCargoIconOverlay(int x, int y, CargoType cargo_type)
Draw a cargo icon overlaying an existing sprite, with a black contrast outline.
bool ShowCargoIconOverlay()
Test if cargo icon overlays should be drawn.
static void DrawVehicleRefitWindow(const RefitOptions &refits, const RefitOption *sel, uint pos, uint rows, uint delta, const Rect &r)
Draw the list of available refit options for a consist and highlight the selected refit option (if an...
static void ShowVehicleDetailsWindow(const Vehicle *v)
Shows the vehicle details window of the given vehicle.
void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
std::map< CargoType, std::vector< RefitOption >, CargoTypeComparator > RefitOptions
Available refit options (subtype and string) associated with each cargo type.
void CcStartStopVehicle(Commands, const CommandCost &result, VehicleID veh_id, bool)
This is the Callback method after attempting to start/stop a vehicle.
static WindowDesc _train_view_desc(WindowPosition::Automatic, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, {}, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for trains.
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
uint GetVehicleHeight(VehicleType type)
Get the height of a single vehicle in the GUIs.
TrainDetailsWindowTabs
The tabs in the train details window.
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Functions/classes shared between the different vehicle list GUIs.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
VehicleType
Available vehicle types.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag).
@ Service
The vehicle will leave the depot right after arrival (service only).
EnumIndexArray< T, VehicleType, Tend > VehicleTypeIndexArray
Array with VehicleType as index.
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli)
Generate a list of vehicles based on window type.
std::vector< const Vehicle * > VehicleList
A list of vehicles.
VehicleListType
Vehicle List type flags.
@ VL_STANDARD
Index is the company.
@ VL_STATION_LIST
Index is the station.
@ VL_DEPOT_LIST
Index is the destination (station for hangar of aircraft, depot for others).
@ VL_SHARED_ORDERS
Index is the first vehicle of the shared orders.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * GetMainWindow()
Get the main window, i.e.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
@ Construction
This window is used for construction; close it whenever changing company.
@ BorderOnly
Draw border only, no background.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ DisableVpScroll
Window does not do autoscroll,.
@ SBS_DOWN
Sort ascending.
@ Automatic
Find a place automatically.
EventState
State of handling an event.
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_VEHICLE_REFIT
Vehicle refit; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
@ Ship
Default zoom level for the ship view.
@ RoadVehicle
Default zoom level for the road vehicle view.
@ Aircraft
Default zoom level for the aircraft view.
@ Train
Default zoom level for the train view.