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

Function ShowRefitOptionsList

src/vehicle_gui.cpp:1358–1384  ·  view source on GitHub ↗

Display list of cargo types of the engine, for the purchase information window */

Source from the content-addressed store, hash-verified

1356
1357/** Display list of cargo types of the engine, for the purchase information window */
1358uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
1359{
1360 /* List of cargo types of this engine */
1361 CargoTypes cmask = GetUnionOfArticulatedRefitMasks(engine, false);
1362 /* List of cargo types available in this climate */
1363 CargoTypes lmask = _cargo_mask;
1364
1365 /* Draw nothing if the engine is not refittable */
1366 if (HasAtMostOneBit(cmask)) return y;
1367
1368 std::string str;
1369 if (cmask == lmask) {
1370 /* Engine can be refitted to all types in this climate */
1371 str = GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_PURCHASE_INFO_ALL_TYPES, std::monostate{});
1372 } else {
1373 /* Check if we are able to refit to more cargo types and unable to. If
1374 * so, invert the cargo types to list those that we can't refit to. */
1375 if (CountBits(cmask ^ lmask) < CountBits(cmask) && CountBits(cmask ^ lmask) <= 7) {
1376 cmask ^= lmask;
1377 str = GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_PURCHASE_INFO_ALL_BUT, cmask);
1378 } else {
1379 str = GetString(STR_PURCHASE_INFO_REFITTABLE_TO, STR_JUST_CARGO_LIST, cmask);
1380 }
1381 }
1382
1383 return DrawStringMultiLine(left, right, y, INT32_MAX, str);
1384}
1385
1386/** Get the cargo subtype text from NewGRF for the vehicle details window. */
1387StringID GetCargoSubtypeText(const Vehicle *v)

Callers 1

DrawVehiclePurchaseInfoFunction · 0.85

Calls 5

HasAtMostOneBitFunction · 0.85
CountBitsFunction · 0.85
GetStringFunction · 0.70
DrawStringMultiLineFunction · 0.70

Tested by

no test coverage detected