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

Method SelectEngine

src/build_vehicle_gui.cpp:1302–1330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1300 }
1301
1302 void SelectEngine(EngineID engine)
1303 {
1304 CargoType cargo = this->cargo_filter_criteria;
1305 if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
1306
1307 this->sel_engine = engine;
1308 this->SetBuyVehicleText();
1309
1310 if (this->sel_engine == EngineID::Invalid()) return;
1311
1312 const Engine *e = Engine::Get(this->sel_engine);
1313
1314 if (!this->listview_mode) {
1315 /* Query for cost and refitted capacity */
1316 auto [ret, veh_id, refit_capacity, refit_mail, cargo_capacities] = Command<CMD_BUILD_VEHICLE>::Do(DoCommandFlag::QueryCost, TileIndex(this->window_number), this->sel_engine, true, cargo, INVALID_CLIENT_ID);
1317 if (ret.Succeeded()) {
1318 this->te.cost = ret.GetCost() - e->GetCost();
1319 this->te.capacity = refit_capacity;
1320 this->te.mail_capacity = refit_mail;
1321 this->te.cargo = !IsValidCargoType(cargo) ? e->GetDefaultCargoType() : cargo;
1322 this->te.all_capacities = cargo_capacities;
1323 return;
1324 }
1325 }
1326
1327 /* Purchase test was not possible or failed, fill in the defaults instead. */
1328 this->te.cost = 0;
1329 this->te.FillDefaultCapacities(e);
1330 }
1331
1332 void OnInit() override
1333 {

Callers 8

BuildVehicleWindowMethod · 0.95
FilterEngineListMethod · 0.95
GenerateBuildShipListMethod · 0.95
OnClickMethod · 0.95
OnDropdownSelectMethod · 0.95

Calls 7

SetBuyVehicleTextMethod · 0.95
InvalidFunction · 0.85
IsValidCargoTypeFunction · 0.85
SucceededMethod · 0.80
GetDefaultCargoTypeMethod · 0.80
FillDefaultCapacitiesMethod · 0.80
GetCostMethod · 0.45

Tested by

no test coverage detected