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

Method GetCapacityString

src/vehicle_gui.cpp:1006–1037  ·  view source on GitHub ↗

* Gets the #StringID to use for displaying capacity. * @param option Cargo and cargo subtype to check for capacity. * @return INVALID_STRING_ID if there is no capacity. StringID to use in any other case. * @post String parameters have been set. */

Source from the content-addressed store, hash-verified

1004 * @post String parameters have been set.
1005 */
1006 std::string GetCapacityString(const RefitOption &option) const
1007 {
1008 assert(_current_company == _local_company);
1009 auto [cost, refit_capacity, mail_capacity, cargo_capacities] = Command<CMD_REFIT_VEHICLE>::Do(DoCommandFlag::QueryCost, this->selected_vehicle, option.cargo, option.subtype, this->auto_refit, false, this->num_vehicles);
1010
1011 if (cost.Failed()) return {};
1012
1013 Money money = cost.GetCost();
1014 if (mail_capacity > 0) {
1015 if (this->order != INVALID_VEH_ORDER_ID) {
1016 /* No predictable cost */
1017 return GetString(STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, option.cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
1018 }
1019
1020 if (money <= 0) {
1021 return GetString(STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT, option.cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity, -money);
1022 }
1023
1024 return GetString(STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT, option.cargo, refit_capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity, money);
1025 }
1026
1027 if (this->order != INVALID_VEH_ORDER_ID) {
1028 /* No predictable cost */
1029 return GetString(STR_PURCHASE_INFO_CAPACITY, option.cargo, refit_capacity, STR_EMPTY);
1030 }
1031
1032 if (money <= 0) {
1033 return GetString(STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT, option.cargo, refit_capacity, -money);
1034 }
1035
1036 return GetString(STR_REFIT_NEW_CAPACITY_COST_OF_REFIT, option.cargo, refit_capacity, money);
1037 }
1038
1039 void DrawWidget(const Rect &r, WidgetID widget) const override
1040 {

Callers 2

DrawWidgetMethod · 0.95
OnInvalidateDataMethod · 0.95

Calls 4

GetCargoTypeByLabelFunction · 0.85
FailedMethod · 0.80
GetStringFunction · 0.70
GetCostMethod · 0.45

Tested by

no test coverage detected