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

Function validateObjectSelection

src/OpenLoco/src/Objects/ObjectIndex.cpp:1240–1283  ·  view source on GitHub ↗

0x00474167

Source from the content-addressed store, hash-verified

1238
1239 // 0x00474167
1240 std::optional<ObjectType> validateObjectSelection(std::span<SelectedObjectsFlags> objectFlags)
1241 {
1242 const auto atLeastOneSelected = [](const ObjectIndexEntry&) { return true; };
1243 // Validate all the simple object types that
1244 // require at least one item selected of the type
1245 for (auto& [objectType, errorMessage] : kValidateTypeAndErrorMessage)
1246 {
1247 if (!validateObjectTypeSelection(objectFlags, objectType, atLeastOneSelected))
1248 {
1249 GameCommands::setErrorText(errorMessage);
1250 return objectType;
1251 }
1252 }
1253
1254 // Validate the more complex road object type that
1255 // has more complex logic
1256 if (!validateObjectTypeSelection(
1257 objectFlags, ObjectType::road, [](const ObjectIndexEntry& entry) {
1258 const auto tempObj = loadTemporaryObject(entry._header);
1259 if (!tempObj.has_value())
1260 {
1261 return false;
1262 }
1263 auto* roadObj = reinterpret_cast<RoadObject*>(getTemporaryObject());
1264 if (!roadObj->hasFlags(RoadObjectFlags::anyRoadTypeCompatible))
1265 {
1266 freeTemporaryObject();
1267 return false;
1268 }
1269 if (roadObj->hasFlags(RoadObjectFlags::isOneWay))
1270 {
1271 freeTemporaryObject();
1272 return false;
1273 }
1274 freeTemporaryObject();
1275 return true;
1276 }))
1277 {
1278 GameCommands::setErrorText(StringIds::at_least_one_generic_dual_direction_road_type_must_be_selected);
1279 return ObjectType::road;
1280 }
1281
1282 return std::nullopt;
1283 }
1284}

Callers 1

tryCloseWindowFunction · 0.85

Calls 6

setErrorTextFunction · 0.85
loadTemporaryObjectFunction · 0.85
getTemporaryObjectFunction · 0.85
freeTemporaryObjectFunction · 0.85
hasFlagsMethod · 0.45

Tested by

no test coverage detected