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

Method getCargoOffsets

src/OpenLoco/src/Objects/RoadStationObject.cpp:151–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 }
150
151 sfl::static_vector<RoadStationObject::CargoOffset, Limits::kMaxStationCargoDensity> RoadStationObject::getCargoOffsets(const uint8_t rotation, const uint8_t nibble) const
152 {
153 assert(rotation < 4 && nibble < 4);
154
155 const auto* bytes = reinterpret_cast<const std::byte*>(this) + cargoOffsetBytes[rotation][nibble];
156 uint8_t z = *reinterpret_cast<const uint8_t*>(bytes);
157 bytes++;
158 sfl::static_vector<CargoOffset, Limits::kMaxStationCargoDensity> result;
159 while (*bytes != static_cast<std::byte>(0xFF))
160 {
161 result.push_back({
162 World::Pos3{
163 *reinterpret_cast<const int8_t*>(bytes),
164 *reinterpret_cast<const int8_t*>(bytes + 1),
165 z,
166 },
167 World::Pos3{
168 *reinterpret_cast<const int8_t*>(bytes + 2),
169 *reinterpret_cast<const int8_t*>(bytes + 3),
170 z,
171 },
172 });
173 bytes += 4;
174
175 // The game can't handle anything larger than 16 so we've made the static vector 16 max
176 if (result.size() == result.max_size())
177 {
178 break;
179 }
180 }
181 return result;
182 }
183}

Calls 2

push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected