MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / getCargoString

Method getCargoString

src/OpenLoco/src/Objects/VehicleObject.cpp:78–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 }
77
78 void VehicleObject::getCargoString(char* buffer) const
79 {
80 if (numSimultaneousCargoTypes != 0)
81 {
82 {
83 auto cargoType = Numerics::bitScanForward(compatibleCargoCategories[0]);
84 if (cargoType != -1)
85 {
86 auto primaryCargoTypes = compatibleCargoCategories[0] & ~(1 << cargoType);
87 {
88 auto cargoObj = ObjectManager::get<CargoObject>(cargoType);
89 FormatArguments args{};
90 auto cargoUnitName = cargoObj->unitNamePlural;
91 if (maxCargo[0] == 1)
92 {
93 cargoUnitName = cargoObj->unitNameSingular;
94 }
95 args.push(cargoUnitName);
96 args.push<uint32_t>(maxCargo[0]);
97 buffer = StringManager::formatString(buffer, StringIds::stats_capacity, args);
98 }
99 cargoType = Numerics::bitScanForward(primaryCargoTypes);
100 if (cargoType != -1)
101 {
102 strcpy(buffer, " (");
103 buffer += 2;
104 for (; cargoType != -1; cargoType = Numerics::bitScanForward(primaryCargoTypes))
105 {
106 primaryCargoTypes &= ~(1 << cargoType);
107 if (buffer[-1] != '(')
108 {
109 strcpy(buffer, " ");
110 buffer++;
111 }
112
113 auto cargoObj = ObjectManager::get<CargoObject>(cargoType);
114 FormatArguments args{};
115 args.push(cargoObj->name);
116 buffer = StringManager::formatString(buffer, StringIds::stats_or_string, args);
117 strcpy(buffer, " ");
118 buffer++;
119 }
120 buffer[-1] = ')';
121 }
122 }
123 }
124
125 if (hasFlags(VehicleObjectFlags::refittable))
126 {
127 buffer = StringManager::formatString(buffer, StringIds::stats_refittable);
128 }
129
130 if (numSimultaneousCargoTypes > 1)
131 {
132 auto cargoType = Numerics::bitScanForward(compatibleCargoCategories[1]);
133 if (cargoType != -1)
134 {
135 auto secondaryCargoTypes = compatibleCargoCategories[1] & ~(1 << cargoType);

Callers 1

drawFunction · 0.80

Calls 4

bitScanForwardFunction · 0.85
formatStringFunction · 0.85
hasFlagsFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected