53 Sorting _sorting[BaseVehicleListWindow::GB_END];
57 static BaseVehicleListWindow::VehicleIndividualSortFunction
VehicleAgeSorter;
75 template <BaseVehicleListWindow::VehicleIndiv
idualSortFunction func>
81 const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * const> BaseVehicleListWindow::vehicle_group_none_sorter_funcs = {
82 &VehicleIndividualToGroupSorterWrapper<VehicleNumberSorter>,
83 &VehicleIndividualToGroupSorterWrapper<VehicleNameSorter>,
84 &VehicleIndividualToGroupSorterWrapper<VehicleAgeSorter>,
85 &VehicleIndividualToGroupSorterWrapper<VehicleProfitThisYearSorter>,
86 &VehicleIndividualToGroupSorterWrapper<VehicleProfitLastYearSorter>,
87 &VehicleIndividualToGroupSorterWrapper<VehicleCargoSorter>,
88 &VehicleIndividualToGroupSorterWrapper<VehicleReliabilitySorter>,
89 &VehicleIndividualToGroupSorterWrapper<VehicleMaxSpeedSorter>,
90 &VehicleIndividualToGroupSorterWrapper<VehicleModelSorter>,
91 &VehicleIndividualToGroupSorterWrapper<VehicleValueSorter>,
92 &VehicleIndividualToGroupSorterWrapper<VehicleLengthSorter>,
93 &VehicleIndividualToGroupSorterWrapper<VehicleTimeToLiveSorter>,
94 &VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
97 const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar = {
101 STR_SORT_BY_PROFIT_THIS_YEAR,
102 STR_SORT_BY_PROFIT_LAST_YEAR,
103 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
104 STR_SORT_BY_RELIABILITY,
105 STR_SORT_BY_MAX_SPEED,
109 STR_SORT_BY_LIFE_TIME,
110 STR_SORT_BY_TIMETABLE_DELAY,
113 const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock = {
117 STR_SORT_BY_PROFIT_THIS_PERIOD,
118 STR_SORT_BY_PROFIT_LAST_PERIOD,
119 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
120 STR_SORT_BY_RELIABILITY,
121 STR_SORT_BY_MAX_SPEED,
125 STR_SORT_BY_LIFE_TIME,
126 STR_SORT_BY_TIMETABLE_DELAY,
129 const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * const> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs = {
137 const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar = {
138 STR_SORT_BY_NUM_VEHICLES,
139 STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
140 STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
141 STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR,
142 STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR,
145 const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock = {
146 STR_SORT_BY_NUM_VEHICLES,
147 STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD,
148 STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD,
149 STR_SORT_BY_AVERAGE_PROFIT_THIS_PERIOD,
150 STR_SORT_BY_AVERAGE_PROFIT_LAST_PERIOD,
153 const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_by_names = {
155 STR_GROUP_BY_SHARED_ORDERS,
158 const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
159 STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
160 STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
161 STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
162 STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
168 this->grouping = _grouping[vli.type][vli.vtype];
169 this->UpdateSortingFromGrouping();
172 std::span<const StringID> BaseVehicleListWindow::GetVehicleSorterNames()
177 case GB_SHARED_ORDERS:
191 if (number >= 10000)
return 5;
192 if (number >= 1000)
return 4;
193 if (number >= 100)
return 3;
211 for (
const Vehicle *v : vehicles) {
212 unitnumber = std::max<uint>(unitnumber, v->unitnumber);
218 void BaseVehicleListWindow::BuildVehicleList()
222 Debug(misc, 3,
"Building vehicle list type {} for company {} given index {}", this->
vli.
type, this->vli.company, this->vli.index);
230 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
231 if (u->cargo_cap > 0)
SetBit(used, u->cargo_type);
234 this->used_cargoes = used;
237 uint max_unitnumber = 0;
238 for (
auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
239 this->
vehgroups.emplace_back(it, it + 1);
241 max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
246 std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](
const Vehicle *
const &u,
const Vehicle *
const &v) {
247 return u->FirstShared() < v->FirstShared();
250 uint max_num_vehicles = 0;
252 VehicleList::const_iterator begin = this->vehicles.begin();
253 while (begin != this->vehicles.end()) {
254 VehicleList::const_iterator end = std::find_if_not(begin, this->vehicles.cend(), [first_shared = (*begin)->FirstShared()](
const Vehicle *
const &v) {
255 return v->FirstShared() == first_shared;
258 this->
vehgroups.emplace_back(begin, end);
260 max_num_vehicles = std::max<uint>(max_num_vehicles,
static_cast<uint
>(end - begin));
285 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
286 if (w->cargo_cap > 0) {
292 bool have_capacity =
false;
293 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
294 if (w->cargo_cap > 0) {
298 have_capacity =
true;
302 return have_capacity;
304 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
305 if (w->cargo_cap > 0 && w->cargo_type == cid) {
353 overlays.emplace_back(rtl ? x - width : x, rtl ? x : x + width, v->
cargo_type, v->
cargo_cap);
357 overlays.back().left -= width;
359 overlays.back().right += width;
361 overlays.back().cargo_cap += v->
cargo_cap;
379 if (spr == 0)
return;
392 DrawSprite(spr, PAL_NONE, x - d.width, y - d.height);
402 for (
const auto &cio : overlays) {
403 if (cio.cargo_cap == 0)
continue;
443 if (this->vehicles.empty()) {
469 }
else if (show_create) {
511 if (!full && !
HasBit(this->used_cargoes, cs->Index()))
continue;
512 list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false, !
HasBit(this->used_cargoes, cs->Index())));
530 if (show_autoreplace) {
531 list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE));
532 list.push_back(MakeDropDownListDividerItem());
537 list.push_back(MakeDropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED));
538 list.push_back(MakeDropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL));
539 list.push_back(MakeDropDownListDividerItem());
540 }
else if (show_create) {
541 list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_CREATE_GROUP, ADI_CREATE_GROUP));
542 list.push_back(MakeDropDownListDividerItem());
546 list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE));
547 list.push_back(MakeDropDownListStringItem(this->vehicle_depot_name[this->
vli.
vtype], ADI_DEPOT));
553 static const Vehicle *_last_vehicle[2] = {
nullptr,
nullptr };
555 void BaseVehicleListWindow::SortVehicleList()
560 _last_vehicle[0] = _last_vehicle[1] =
nullptr;
565 if (list->size() < 2)
return;
577 }
else if (display_profit_last_year < 0) {
578 spr = SPR_PROFIT_NEGATIVE;
580 spr = SPR_PROFIT_SOME;
582 spr = SPR_PROFIT_LOT;
605 static std::vector<StringID> subtypes;
613 uint8_t ret_refit_cyc = 0;
614 bool success =
false;
615 if (!subtypes.empty()) {
618 const Engine *e = v->GetEngine();
620 if (!
HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type)
continue;
622 CargoID old_cargo_type = v->cargo_type;
623 uint8_t old_cargo_subtype = v->cargo_subtype;
626 v->cargo_type = dest_cargo_type;
630 v->cargo_subtype = refit_cyc;
633 v->First()->InvalidateNewGRFCache();
634 v->InvalidateNewGRFCache();
637 if (subtype == STR_EMPTY)
break;
639 if (std::find(subtypes.begin(), subtypes.end(), subtype) == subtypes.end())
continue;
642 ret_refit_cyc = refit_cyc;
648 v->cargo_type = old_cargo_type;
649 v->cargo_subtype = old_cargo_subtype;
652 v->First()->InvalidateNewGRFCache();
653 v->InvalidateNewGRFCache();
659 return ret_refit_cyc;
710 int iconleft = rtl ? ir.right - iconwidth : ir.left;
711 int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2;
712 int iconinner = rtl ? ir.right - iconwidth : ir.left + iconwidth;
717 for (
const auto &pair : refits) {
718 bool has_subtypes = pair.second.size() > 1;
720 if (current >= pos + rows)
break;
723 if ((sel ==
nullptr || sel->
cargo != refit.
cargo) && refit.
subtype != UINT8_MAX)
continue;
732 if (refit.
subtype != UINT8_MAX) {
736 GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
747 DrawString(tr, STR_JUST_STRING_STRING, colour);
778 std::optional<RefitOption> current_refit_option;
779 if (this->selected_refit !=
nullptr) current_refit_option = *(this->
selected_refit);
780 this->selected_refit =
nullptr;
782 this->refit_list.clear();
786 VehicleSet vehicles_to_refit;
790 if (v->
type ==
VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->
index) == vehicles_to_refit.end())
continue;
792 CargoTypes cmask = e->info.refit_mask;
804 if (!
HasBit(cmask, cid))
continue;
806 auto &list = this->refit_list[cid];
807 bool first_vehicle = list.empty();
810 list.push_back({cid, UINT8_MAX, STR_EMPTY});
836 if (subtype == STR_EMPTY)
break;
845 if (subtype == STR_EMPTY) {
848 for (uint i = 1; i < list.size(); i++) {
849 if (list[i].subtype >= refit_cyc) {
858 while (pos < list.size() && list[pos].subtype != refit_cyc) pos++;
859 if (pos < list.size() && list[pos].string != subtype) {
861 list.erase(list.begin() + pos);
879 if (current_refit_option.has_value()) {
880 for (
const auto &pair : this->refit_list) {
881 for (
const auto &refit : pair.second) {
882 if (refit.cargo == current_refit_option->cargo && refit.subtype == current_refit_option->subtype) {
883 this->selected_refit = &refit;
887 if (this->selected_refit !=
nullptr)
break;
899 size_t scroll_row = 0;
901 CargoID cargo = this->selected_refit ==
nullptr ? INVALID_CARGO : this->selected_refit->
cargo;
903 for (
const auto &pair : this->refit_list) {
904 if (pair.first == cargo) {
906 scroll_row = rows + (this->selected_refit - pair.second.data());
907 rows += pair.second.size();
927 if (row == click_row) {
928 this->selected_refit = &refit;
933 if (this->selected_refit ==
nullptr || this->selected_refit->
cargo != refit.
cargo)
break;
938 this->selected_refit =
nullptr;
950 this->GetWidget<NWidgetCore>(
WID_VR_MATRIX)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->
type;
953 nwi->
tool_tip = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->
type;
972 if (this->hscroll !=
nullptr) this->hscroll->
SetCount(this->vehicle_width);
976 int sprite_width = std::max(0, ((
int)vehicle_panel_display->
current_x - this->vehicle_width) / 2);
977 this->sprite_left = vehicle_panel_display->
pos_x;
978 this->sprite_right = vehicle_panel_display->
pos_x + vehicle_panel_display->
current_x - 1;
980 this->sprite_right -= sprite_width;
983 this->sprite_left += sprite_width;
995 size.height =
resize.height * 8;
1003 size.width = this->information_width + padding.height;
1008 void SetStringParameters(
WidgetID widget)
const override
1029 Money money = cost.GetCost();
1030 if (mail_capacity > 0) {
1031 SetDParam(2, GetCargoIDByLabel(CT_MAIL));
1035 return STR_PURCHASE_INFO_AIRCRAFT_CAPACITY;
1036 }
else if (money <= 0) {
1038 return STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT;
1041 return STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT;
1047 return STR_PURCHASE_INFO_CAPACITY;
1048 }
else if (money <= 0) {
1050 return STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT;
1053 return STR_REFIT_NEW_CAPACITY_COST_OF_REFIT;
1058 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1071 VehicleSet vehicles_to_refit;
1074 int left = INT32_MIN;
1080 const int highlight_bottom = highlight_top +
height - 1;
1084 const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
1085 if (contained &&
left == INT32_MIN) {
1091 if ((!contained || u->Next() ==
nullptr) &&
left != INT32_MIN) {
1092 if (u->Next() ==
nullptr && contained) {
1093 int current_width = u->GetDisplayImageWidth();
1094 width += current_width;
1106 if (
left != right) {
1107 Rect hr = {
left, highlight_top, right, highlight_bottom};
1114 int current_width = u->GetDisplayImageWidth();
1115 width += current_width;
1131 if (this->selected_refit !=
nullptr) {
1146 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1153 this->selected_vehicle = v->
index;
1154 this->num_vehicles = UINT8_MAX;
1159 if (!gui_scope)
break;
1167 for (
const auto &list : this->refit_list) {
1172 max_width = std::max(dim.width, max_width);
1177 if (this->information_width < max_width) {
1178 this->information_width = max_width;
1185 if (!gui_scope)
break;
1191 int GetClickPosition(
int click_x)
1201 void SetSelectedVehicles(
int drag_x)
1203 drag_x = GetClickPosition(drag_x);
1205 int left_x = std::min(this->click_x, drag_x);
1206 int right_x = std::max(this->click_x, drag_x);
1207 this->num_vehicles = 0;
1216 bool start_counting =
false;
1217 for (; u !=
nullptr; u = u->
Next()) {
1219 left_x -= current_width;
1220 right_x -= current_width;
1222 if (left_x < 0 && !start_counting) {
1223 this->selected_vehicle = u->
index;
1224 start_counting =
true;
1227 this->num_vehicles++;
1230 this->num_vehicles++;
1233 if (right_x < 0)
break;
1238 if (this->num_vehicles != 0) {
1247 this->selected_vehicle = v->
index;
1248 this->num_vehicles = UINT8_MAX;
1253 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1259 this->click_x = GetClickPosition(pt.x - nwi->
pos_x);
1260 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1276 if (click_count == 1)
break;
1281 if (this->selected_refit !=
nullptr) {
1285 bool delete_window = this->selected_vehicle == v->
index && this->num_vehicles == UINT8_MAX;
1286 if (
Command<CMD_REFIT_VEHICLE>::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();
1301 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1314 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1329 static constexpr
NWidgetPart _nested_vehicle_refit_widgets[] = {
1345 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VR_MATRIX),
SetMinimalSize(228, 112),
SetResize(1, 14),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_VR_SCROLLBAR),
1356 WDP_AUTO,
"view_vehicle_refit", 240, 174,
1359 _nested_vehicle_refit_widgets
1387 if (cmask == lmask) {
1389 SetDParam(0, STR_PURCHASE_INFO_ALL_TYPES);
1395 SetDParam(0, STR_PURCHASE_INFO_ALL_BUT);
1424 return a.NumVehicles() < b.NumVehicles();
1430 return a.GetDisplayProfitThisYear() < b.GetDisplayProfitThisYear();
1436 return a.GetDisplayProfitLastYear() < b.GetDisplayProfitLastYear();
1442 return a.GetDisplayProfitThisYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitThisYear() *
static_cast<uint
>(a.NumVehicles());
1448 return a.GetDisplayProfitLastYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitLastYear() *
static_cast<uint
>(a.NumVehicles());
1460 static std::string last_name[2] = { {}, {} };
1462 if (a != _last_vehicle[0]) {
1463 _last_vehicle[0] = a;
1465 last_name[0] =
GetString(STR_VEHICLE_NAME);
1468 if (b != _last_vehicle[1]) {
1469 _last_vehicle[1] = b;
1471 last_name[1] =
GetString(STR_VEHICLE_NAME);
1481 auto r = a->
age - b->
age;
1510 for (uint d : diff) {
1545 for (u = a; u !=
nullptr; u = u->
Next()) diff += u->
value;
1546 for (u = b; u !=
nullptr; u = u->
Next()) diff -= u->
value;
1548 int r = ClampTo<int32_t>(diff);
1573 void InitializeGUI()
1617 static constexpr
NWidgetPart _nested_vehicle_list[] = {
1653 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VL_LIST),
SetMinimalSize(248, 0),
SetFill(1, 0),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_VL_SCROLLBAR),
1661 SetDataTip(STR_JUST_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
1664 SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
1666 SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
1668 SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
1680 if (order ==
nullptr)
return;
1683 int l_offset = rtl ? 0 : order_arrow_width;
1684 int r_offset = rtl ? order_arrow_width : 0;
1691 if (order->
IsType(OT_GOTO_STATION)) {
1696 if (++i == 4)
break;
1700 order = order->
next;
1701 if (order ==
nullptr) {
1705 }
while (oid != start);
1712 int l_offset = rtl ? 0 : order_arrow_width;
1713 int r_offset = rtl ? order_arrow_width : 0;
1715 while (order !=
nullptr) {
1716 if (order->
IsType(OT_GOTO_STATION)) {
1721 if (++i == 4)
break;
1723 order = order->
next;
1741 default: NOT_REACHED();
1758 if (divisor == 1)
return base;
1761 uint rem = base % divisor;
1762 return base + (rem == 0 ? 0 : divisor - rem);
1794 int image_left = (rtl && show_orderlist) ? olr.right : tr.left;
1795 int image_right = (!rtl && show_orderlist) ? olr.left : tr.right;
1797 int vehicle_button_x = rtl ? ir.right - profit.width : ir.left;
1800 for (
auto it = first; it != last; ++it) {
1803 SetDParam(0, vehgroup.GetDisplayProfitThisYear());
1804 SetDParam(1, vehgroup.GetDisplayProfitLastYear());
1812 const Vehicle *v = vehgroup.GetSingleVehicle();
1822 CargoTypes vehicle_cargoes = 0;
1824 for (
auto u = v; u !=
nullptr; u = u->
Next()) {
1830 if (!v->
name.empty()) {
1849 }
else if (!v->
name.empty()) {
1873 case GB_SHARED_ORDERS:
1874 assert(vehgroup.NumVehicles() > 0);
1876 for (
int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
1895 void BaseVehicleListWindow::UpdateSortingFromGrouping()
1905 default: NOT_REACHED();
1913 void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
1922 this->UpdateSortingFromGrouping();
1959 this->GetWidget<NWidgetCore>(
WID_VL_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->
vli.
vtype;
1962 if (this->
vli.
type == VL_SHARED_ORDERS) {
1970 this->GetWidget<NWidgetCore>(
WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->
vli.
vtype;
1977 this->BuildVehicleList();
1978 this->SortVehicleList();
1995 size.height = 6 *
resize.height;
1999 size.height = 4 *
resize.height;
2001 default: NOT_REACHED();
2008 d.height += padding.height;
2019 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
2020 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
2021 size.width = std::max(size.width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
2022 size.width += padding.width;
2031 d.height += padding.height;
2032 d.width += padding.width;
2039 void SetStringParameters(
WidgetID widget)
const override
2053 case VL_SHARED_ORDERS:
2063 case VL_STATION_LIST:
2075 default: NOT_REACHED();
2082 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2098 this->BuildVehicleList();
2099 this->SortVehicleList();
2132 bool last_overlay_state;
2141 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2145 assert(this->
vli.
type == VL_SHARED_ORDERS);
2146 assert(!this->vehicles.empty());
2147 ShowOrdersWindow(this->vehicles[0]);
2170 if (it == this->
vehgroups.end())
return;
2175 const Vehicle *v = vehgroup.GetSingleVehicle();
2186 case GB_SHARED_ORDERS: {
2187 assert(vehgroup.NumVehicles() > 0);
2191 ShowOrdersWindow(v);
2193 if (vehgroup.NumVehicles() == 1) {
2196 ShowVehicleListWindow(v);
2203 default: NOT_REACHED();
2225 void OnDropdownSelect(
WidgetID widget,
int index)
override
2229 this->UpdateVehicleGroupBy(
static_cast<GroupBy
>(index));
2241 assert(!this->vehicles.empty());
2252 case ADI_CREATE_GROUP:
2256 default: NOT_REACHED();
2260 default: NOT_REACHED();
2268 StationID station = (this->
vli.
type == VL_STATION_LIST) ? this->
vli.
index : INVALID_STATION;
2270 Debug(misc, 3,
"Periodic resort {} list company {} at station {}", this->
vli.
vtype, this->owner, station);
2285 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2287 if (!gui_scope &&
HasBit(data, 31) && this->
vli.
type == VL_SHARED_ORDERS) {
2290 this->window_number = this->
vli.
Pack();
2305 WDP_AUTO,
"list_vehicles", 260, 246,
2308 _nested_vehicle_list
2312 WDP_AUTO,
"list_vehicles_train", 325, 246,
2315 _nested_vehicle_list
2324 AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_train_desc, num);
2327 AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_other_desc, num);
2341 ShowVehicleListWindowLocal(company, VL_STANDARD, vehicle_type, company);
2345 void ShowVehicleListWindow(
const Vehicle *v)
2352 ShowVehicleListWindowLocal(company, VL_STATION_LIST, vehicle_type, station);
2357 uint16_t depot_airport_index;
2364 ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index);
2392 SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2409 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VD_MATRIX),
SetResize(1, 1),
SetMinimalSize(393, 45),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 0),
SetScrollbar(
WID_VD_SCROLLBAR),
2418 SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2425 SetDataTip(STR_VEHICLE_DETAIL_TAB_INFORMATION, STR_VEHICLE_DETAILS_TRAIN_INFORMATION_TOOLTIP),
SetFill(1, 0),
SetResize(1, 0),
2429 SetDataTip(STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP),
SetFill(1, 0),
SetResize(1, 0),
2441 static StringID _service_interval_dropdown_calendar[] = {
2442 STR_VEHICLE_DETAILS_DEFAULT,
2443 STR_VEHICLE_DETAILS_DAYS,
2444 STR_VEHICLE_DETAILS_PERCENT,
2447 static StringID _service_interval_dropdown_wallclock[] = {
2448 STR_VEHICLE_DETAILS_DEFAULT,
2449 STR_VEHICLE_DETAILS_MINUTES,
2450 STR_VEHICLE_DETAILS_PERCENT,
2476 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2483 if (!gui_scope)
return;
2489 if (aimed_height != nwid_info->
current_y) {
2502 uint desired_height;
2507 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
2513 return desired_height;
2524 static const StringID info_strings[] = {
2525 STR_VEHICLE_INFO_MAX_SPEED,
2526 STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
2527 STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
2528 STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_MIN_PERFORMANCE,
2529 STR_VEHICLE_INFO_PROFIT_THIS_PERIOD_LAST_PERIOD_MIN_PERFORMANCE,
2530 STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
2532 for (
const auto &info_string : info_strings) {
2537 size.width = dim.width + padding.width;
2564 size.height = 4 *
resize.height;
2569 d.width += padding.width;
2570 d.height += padding.height;
2580 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO);
2584 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_DATE);
2588 size.width = std::max(
2601 switch (vehicle_type) {
2602 default: NOT_REACHED();
2626 default: NOT_REACHED();
2630 void SetStringParameters(
WidgetID widget)
const override
2635 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2645 SetDParam(0, (v->
age + CalendarTime::DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
2662 string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
2664 string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
2672 string = STR_VEHICLE_INFO_MAX_SPEED_TYPE_RANGE;
2674 string = STR_VEHICLE_INFO_MAX_SPEED_TYPE;
2677 string = STR_VEHICLE_INFO_MAX_SPEED;
2697 DrawString(tr, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
2734 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO);
2737 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_MINUTES);
2742 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_DATE);
2745 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS);
2767 !v->ServiceIntervalIsCustom() ? STR_VEHICLE_DETAILS_DEFAULT :
2768 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT :
2775 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2790 if (mod == v->GetServiceInterval())
return;
2800 v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
2820 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
2825 if (v->ServiceIntervalIsPercent()) {
2826 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT;
2828 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES;
2830 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_DAYS : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_DAYS;
2839 void OnDropdownSelect(
WidgetID widget,
int index)
override
2844 bool iscustom = index != 0;
2845 bool ispercent = iscustom ? (index == 2) :
Company::Get(v->
owner)->settings.vehicle.servint_ispercent;
2856 if (nwi !=
nullptr) {
2864 WDP_AUTO,
"view_vehicle_details_train", 405, 178,
2872 WDP_AUTO,
"view_vehicle_details", 405, 113,
2914 SetDataTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
2918 SetDataTip(SPR_FORCE_VEHICLE_TURN, STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP),
2948 static const int VV_INITIAL_VIEWPORT_WIDTH = 226;
2949 static const int VV_INITIAL_VIEWPORT_HEIGHT = 84;
2950 static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
2954 VCT_CMD_START_STOP = 0,
2956 VCT_CMD_TURN_AROUND,
2962 STR_ERROR_CAN_T_STOP_START_TRAIN,
2963 STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
2964 STR_ERROR_CAN_T_STOP_START_SHIP,
2965 STR_ERROR_CAN_T_STOP_START_AIRCRAFT
2968 STR_ERROR_CAN_T_BUY_TRAIN,
2969 STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
2970 STR_ERROR_CAN_T_BUY_SHIP,
2971 STR_ERROR_CAN_T_BUY_AIRCRAFT
2974 STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN,
2975 STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN,
2988 if (result.
Failed())
return;
3035 bool mouse_over_start_stop =
false;
3066 static const SpriteID vehicle_view_goto_depot_sprites[] = {
3067 SPR_SEND_TRAIN_TODEPOT,
3068 SPR_SEND_ROADVEH_TODEPOT,
3069 SPR_SEND_SHIP_TODEPOT,
3070 SPR_SEND_AIRCRAFT_TODEPOT,
3073 this->GetWidget<NWidgetCore>(
WID_VV_GOTO_DEPOT)->widget_data = vehicle_view_goto_depot_sprites[v->
type];
3076 static const SpriteID vehicle_view_clone_sprites[] = {
3082 this->GetWidget<NWidgetCore>(
WID_VV_CLONE)->widget_data = vehicle_view_clone_sprites[v->
type];
3086 this->GetWidget<NWidgetCore>(
WID_VV_TURN_AROUND)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP;
3097 default: NOT_REACHED();
3103 this->GetWidget<NWidgetCore>(
WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->
type;
3104 this->GetWidget<NWidgetCore>(
WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->
type;
3105 this->GetWidget<NWidgetCore>(
WID_VV_LOCATION)->tool_tip = STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->
type;
3106 this->GetWidget<NWidgetCore>(
WID_VV_REFIT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->
type;
3107 this->GetWidget<NWidgetCore>(
WID_VV_GOTO_DEPOT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->
type;
3108 this->GetWidget<NWidgetCore>(
WID_VV_SHOW_ORDERS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->
type;
3109 this->GetWidget<NWidgetCore>(
WID_VV_SHOW_DETAILS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->
type;
3110 this->GetWidget<NWidgetCore>(
WID_VV_CLONE)->tool_tip = STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->
type;
3112 this->UpdateButtonStatus();
3115 void Close([[maybe_unused]]
int data = 0)
override
3140 size.width = VV_INITIAL_VIEWPORT_WIDTH;
3141 size.height = (v->
type ==
VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
3171 void SetStringParameters(
WidgetID widget)
const override
3179 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
3187 str = STR_VEHICLE_STATUS_CRASHED;
3189 str = STR_VEHICLE_STATUS_BROKEN_DOWN;
3194 str = STR_VEHICLE_STATUS_TRAIN_NO_POWER;
3196 str = STR_VEHICLE_STATUS_STOPPED;
3200 str = STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL;
3203 str = STR_VEHICLE_STATUS_STOPPED;
3206 str = STR_VEHICLE_STATUS_WAITING_UNBUNCHING;
3208 str = STR_VEHICLE_STATUS_TRAIN_STUCK;
3210 str = STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR;
3212 if (mouse_over_start_stop) {
3220 case OT_GOTO_STATION: {
3227 case OT_GOTO_DEPOT: {
3250 str = STR_VEHICLE_STATUS_LOADING_UNLOADING;
3253 case OT_GOTO_WAYPOINT: {
3261 case OT_LEAVESTATION:
3263 str = STR_VEHICLE_STATUS_LEAVING;
3269 str = STR_VEHICLE_STATUS_NO_ORDERS_VEL;
3283 DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl),
SA_CENTER);
3288 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
3322 if (click_count > 1) {
3341 ShowOrdersWindow(v);
3389 void OnQueryTextFinished(std::optional<std::string> str)
override
3391 if (!str.has_value())
return;
3396 void OnMouseOver([[maybe_unused]]
Point pt,
WidgetID widget)
override
3399 if (start_stop != mouse_over_start_stop) {
3400 mouse_over_start_stop = start_stop;
3405 void OnMouseWheel(
int wheel)
override
3420 void UpdateButtonStatus()
3450 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
3458 this->UpdateButtonStatus();
3471 static inline HotkeyList hotkeys{
"vehicleview", {
3478 WDP_AUTO,
"view_vehicle", 250, 116,
3482 &VehicleViewWindow::hotkeys
3490 WDP_AUTO,
"view_vehicle_train", 250, 134,
3494 &VehicleViewWindow::hotkeys
3510 assert(v !=
nullptr);
3525 bool VehicleClicked(VehicleList::const_iterator begin, VehicleList::const_iterator end)
3527 assert(begin != end);
3546 void StopGlobalFollowVehicle(
const Vehicle *v)
3563 if (result.
Failed())
return;
3601 int vehicle_width = 0;
3602 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
3605 return vehicle_width;
3621 int total_width = 0;
3623 bool rotor_seq =
false;
3626 while (v !=
nullptr) {
3627 if (total_width >=
ScaleSpriteTrad(2 * (
int)VEHICLEINFO_FULL_VEHICLE_WIDTH))
break;
3634 if (!seq.
IsValid()) seq.
Set(SPR_ROTOR_STOPPED);
3643 for (uint i = 0; i < seq.count; ++i) {
3645 _cursor.
sprites.emplace_back(seq.seq[i].
sprite, pal2, rtl ? (-total_width + x_offs) : (total_width + x_offs), y_offset);
3657 if (is_ground_vehicle) {
3659 int offs = (
ScaleSpriteTrad(VEHICLEINFO_FULL_VEHICLE_WIDTH) - total_width) / 2;
3660 if (rtl) offs = -offs;
3661 for (
auto &cs : _cursor.
sprites) {
@ VAF_DEST_TOO_FAR
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.
constexpr debug_inline 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 uint CountBits(T value)
Counts the number of set bits in a variable.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
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(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
@ CC_PASSENGERS
Passengers.
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.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetListing(Listing l)
Import sort conditions.
void SetFilterState(bool state)
Enable or disable the filter.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool(const GUIVehicleGroup *, CargoID) FilterFunction
Signature of filter function.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
bool NeedRebuild() const
Check if a rebuild is needed.
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
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 int MONTHS_IN_YEAR
months per year
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
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)
Calculate the year of a given date.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
Functions related to commands.
@ DC_QUERY_COST
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.
Owner
Enum for all companies/owners.
@ 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,...)
Ouptut a line of debugging information.
Command definitions related to depots.
void CcCloneVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id)
This is the Callback method after the cloning attempt of a vehicle.
Map related accessors for depots.
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
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.
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Functions related to engines.
uint16_t EngineID
Unique identification number of an engine.
@ EF_AUTO_REFIT
Automatic refitting is allowed.
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.
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.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ SA_LEFT
Left align the text.
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_CENTER
Center both horizontally and vertically.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
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 cmd, const CommandCost &result, GroupID new_group, GroupID, VehicleID veh_id, 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, bool need_existing_window)
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 const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
static const GroupID ALL_GROUP
All vehicles are in this group.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Hotkey related 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.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
static debug_inline 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.
void MemSetT(T *ptr, uint8_t value, size_t num=1)
Type-safe version of memset().
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
static constexpr CargoID CF_FREIGHT
Show only vehicles which carry any freight (non-passenger) cargo.
@ CBID_VEHICLE_CARGO_SUFFIX
Determine the cargo "suffixes" for each refit possibility of a cargo.
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
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.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Header of Action 04 "universal holder" structure and functions.
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
Command definitions related to orders.
@ ODATFB_UNBUNCH
Service the vehicle and then unbunch it.
@ ODATFB_HALT
Service the vehicle and then halt it.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
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.
@ SWS_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.
Functions to cache sprites in memory.
static const PaletteID PALETTE_ALL_BLACK
Exchange any color 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.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
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.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
@ TD_RTL
Text is written right-to-left by default.
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)
Aircraft, helicopters, rotors and their shadows belong to this class.
std::string name
Name of vehicle.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
CargoID cargo_filter_criteria
Selected cargo filter index.
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
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.
void SetCargoFilter(uint8_t index)
Set cargo filter for the vehicle group list.
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.
void FilterVehicleList()
Filter the engine list against the currently selected cargo filter.
VehicleType type
Type of vehicle.
Class for storing amounts of cargo.
Comparator to sort CargoID by according to desired order.
Specification of a cargo type.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
StringID name
Name of this type of cargo.
GUISettings gui
settings related to the GUI
std::vector< CursorSprite > sprites
Sprites comprising cursor.
Dimensions (a width and height) of a rectangle in 2D.
uint8_t misc_flags
Miscellaneous flags.
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
bool CanCarryCargo() const
Determines whether an engine can carry something.
bool show_cargo_in_vehicle_lists
Show the cargoes the vehicles can carry in the list windows.
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
uint8_t advanced_vehicle_list
use the "advanced" vehicle list
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.
VehicleSettings vehicle
options for vehicles
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.
Order * GetFirstOrder() const
Get the first order of the order chain.
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.
Order * next
Pointer to next order. If nullptr, end of list.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
SpriteID sprite
The 'real' sprite.
PaletteID pal
The palette (use PAL_NONE) if not needed)
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(size_t 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.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
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.
uint8_t subtype
Subcargo to use.
CargoID cargo
Cargo to refit to.
bool operator!=(const RefitOption &other) const
Inequality operator for RefitOption.
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.
int sprite_left
Left position of the vehicle sprite.
void RefreshScrollbar()
Refresh scrollbar after selection changed.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
RefitOptions refit_list
List of refit subtypes available for each sorted cargo.
void OnResize() override
Called after the window got resized.
const RefitOption * selected_refit
Selected refit option.
StringID GetCapacityString(const RefitOption &option) const
Gets the StringID to use for displaying capacity.
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.
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.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
T * Next() const
Get next vehicle in the chain.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
HighLightStyle place_mode
Method which is used to place the selection.
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
'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.
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
Class for managing the vehicle details window.
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([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void OnResize() override
Called after the window got resized.
VehicleDetailsWindow(WindowDesc &desc, WindowNumber window_number)
Initialize a newly created vehicle details window.
TrainDetailsWindowTabs tab
For train vehicles: which tab is displayed.
The information about a vehicle list.
VehicleListType type
The type of vehicle list.
CompanyID company
The company associated with this list.
uint32_t Pack() const
Pack a VehicleListIdentifier in a single uint32.
VehicleType vtype
The vehicle type associated with this list.
static VehicleListIdentifier UnPack(uint32_t data)
Decode a packed vehicle list identifier into a new one.
uint32_t index
A vehicle list type specific index.
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.
void OnPaint() override
The window must be repainted.
ButtonPlanes
Enumeration of planes of the button row at the bottom.
@ BP_HIDE_BUTTONS
Show the empty panel.
@ BP_SHOW_BUTTONS
Show the buttons.
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 OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
uint8_t train_acceleration_model
realistic acceleration for trains
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 OnResize() override
Called after the window got resized.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection 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.
void SelectPlane(PlaneSelections plane)
Display a plane in the window.
void OnPaint() override
The window must be repainted.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
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 SetDParam for string processing.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
int32_t z_pos
z coordinate.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
uint16_t cargo_cap
total capacity
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
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 SetDParam for string processing.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Vehicle * Next() const
Get the next vehicle of this vehicle.
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Order current_order
The current order (+ status, like: loading)
CargoID cargo_type
type of cargo this vehicle is carrying
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.
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 void PlayLeaveStationSound([[maybe_unused]] bool force=false) const
Play the sound associated with leaving the station.
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 SetDParam for string processing.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
TimerGameCalendar::Date max_age
Maximum age.
uint16_t reliability
Reliability.
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
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
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
High level window description.
WindowClass cls
Class of the window,.
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.
virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
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.
ViewportData * viewport
Pointer to viewport data, if present.
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
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.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
@ TE_RISING
Make the text effect slowly go upwards.
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.
@ VRF_TRAIN_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.
@ VF_PATHFINDER_LOST
Vehicle's pathfinder is lost.
@ VS_STOPPED
Vehicle is stopped by the player.
@ VS_CRASHED
Vehicle is crashed.
Command definitions for vehicles.
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.
void DrawAircraftDetails(const Aircraft *v, const Rect &r)
Draw the details for the given vehicle at the given position.
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (part) in pixels.
static bool CargoFilterSingle(const Vehicle *v, const CargoID cid)
Check whether a single vehicle should pass the filter.
void DrawShipDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
static bool VehicleTimetableDelaySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the timetable delay.
VehicleCommandTranslation
Command indices for the _vehicle_command_translation_table.
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 void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
Assign a vehicle window a new vehicle.
static bool VehicleAgeSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their age.
static bool VehicleGroupLengthSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the number of vehicles in the group.
std::map< CargoID, std::vector< RefitOption >, CargoIDComparator > RefitOptions
Available refit options (subtype and string) associated with each cargo type.
static bool VehicleCargoSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their cargo.
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.
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
static bool VehicleGroupTotalProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit this year.
static constexpr NWidgetPart _nested_vehicle_view_widgets[]
Vehicle view widgets.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
static const StringID _vehicle_msg_translation_table[][4]
Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.
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 bool VehicleProfitThisYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by this year profit.
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 const ZoomLevel _vehicle_view_zoom_levels[]
Zoom levels for vehicle views indexed by vehicle type.
uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
static bool CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid)
Check whether a vehicle can carry a specific cargo.
static constexpr NWidgetPart _nested_nontrain_vehicle_details_widgets[]
Vehicle details widgets (other than train).
static bool IsVehicleRefitable(const Vehicle *v)
Checks whether the vehicle may be refitted at the moment.
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 bool VehicleGroupAverageProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit last year.
static int GetUnitNumberWidth(int digits)
Get width required for the formatted unit number display.
static bool VehicleLengthSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their length.
void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
static bool VehicleGroupAverageProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit this year.
static bool VehicleNameSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their name.
static WindowDesc _train_view_desc(WDP_AUTO, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for trains.
static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
Draw small order list in the vehicle GUI, but without the little black arrow.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
static WindowDesc _vehicle_view_desc(WDP_AUTO, "view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for all vehicles but trains.
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 CMD_START_STOP_VEHICLE for given vehicle.
static constexpr NWidgetPart _nested_train_vehicle_details_widgets[]
Train details widgets.
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
static bool VehicleProfitLastYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by last year profit.
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
static WindowDesc _nontrain_vehicle_details_desc(WDP_AUTO, "view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_nontrain_vehicle_details_widgets)
Vehicle details window descriptor for other vehicles than a train.
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 bool VehicleIndividualToGroupSorterWrapper(GUIVehicleGroup const &a, GUIVehicleGroup const &b)
Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
static bool VehicleGroupTotalProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit last year.
static bool VehicleModelSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by model.
static bool VehicleValueSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their value.
static bool VehicleTimeToLiveSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the time they can still live.
static bool VehicleNumberSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their number.
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 bool VehicleMaxSpeedSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their max speed.
static void ShowVehicleDetailsWindow(const Vehicle *v)
Shows the vehicle details window of the given vehicle.
void DrawCargoIconOverlay(int x, int y, CargoID cid)
Draw a cargo icon overlaying an existing sprite, with a black contrast outline.
void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
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_vehicle_details_desc(WDP_AUTO, "view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_train_vehicle_details_widgets)
Vehicle details window descriptor.
static bool VehicleReliabilitySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their reliability.
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.
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
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, ...
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.
uint32_t VehicleID
The type all our vehicle IDs have.
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
@ 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)
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.
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 * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window * GetMainWindow()
Get the main window, i.e.
@ SBS_DOWN
Sort ascending.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
@ FR_BORDERONLY
Draw border only, no background.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
EventState
State of handling an event.
WindowClass
Window classes.
@ WC_INVALID
Invalid window.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ 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:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
ZoomLevel
All zoom levels we know.
@ ZOOM_LVL_ROADVEH
Default zoom level for the road vehicle view.
@ ZOOM_LVL_AIRCRAFT
Default zoom level for the aircraft view.
@ ZOOM_LVL_TRAIN
Default zoom level for the train view.
@ ZOOM_LVL_SHIP
Default zoom level for the ship view.