MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildVehicle

Method BuildVehicle

src/build_vehicle_gui.cpp:1622–1649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1620 }
1621
1622 void BuildVehicle()
1623 {
1624 EngineID sel_eng = this->sel_engine;
1625 if (sel_eng == EngineID::Invalid()) return;
1626
1627 CargoType cargo = this->cargo_filter_criteria;
1628 if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1629 if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
1630 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
1631 } else {
1632 Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
1633 }
1634
1635 /* Update last used variant in hierarchy and refresh if necessary. */
1636 bool refresh = false;
1637 EngineID parent = sel_eng;
1638 while (parent != EngineID::Invalid()) {
1639 Engine *e = Engine::Get(parent);
1640 refresh |= (e->display_last_variant != sel_eng);
1641 e->display_last_variant = sel_eng;
1642 parent = e->info.variant_id;
1643 }
1644
1645 if (refresh) {
1646 InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
1647 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
1648 }
1649 }
1650
1651 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1652 {

Callers 1

OnClickMethod · 0.95

Calls 5

InvalidFunction · 0.85
RailVehInfoFunction · 0.85
GetCmdBuildVehMsgFunction · 0.85
InvalidateWindowDataFunction · 0.70

Tested by

no test coverage detected