| 1047 | } |
| 1048 | |
| 1049 | static void ConsoleCommandLoadObject(InteractiveConsole& console, const arguments_t& argv) |
| 1050 | { |
| 1051 | if (argv.empty()) |
| 1052 | { |
| 1053 | console.WriteLineError("Please specify an object name."); |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | auto& objectRepository = GetContext()->GetObjectRepository(); |
| 1058 | auto objectName = argv[0]; |
| 1059 | |
| 1060 | // First, try and find a JSON object by this name |
| 1061 | const ObjectRepositoryItem* ori = objectRepository.FindObject(objectName); |
| 1062 | |
| 1063 | // If this fails, try loading by DAT name |
| 1064 | if (ori == nullptr) |
| 1065 | { |
| 1066 | char name[9] = { 0 }; |
| 1067 | std::fill_n(name, 8, ' '); |
| 1068 | std::size_t i = 0; |
| 1069 | for (const char* ch = objectName.c_str(); *ch != '\0' && i < std::size(name) - 1; ch++) |
| 1070 | { |
| 1071 | name[i++] = *ch; |
| 1072 | } |
| 1073 | |
| 1074 | ori = objectRepository.FindObjectLegacy(name); |
| 1075 | } |
| 1076 | |
| 1077 | if (ori == nullptr) |
| 1078 | { |
| 1079 | console.WriteLineError("Could not find the object."); |
| 1080 | return; |
| 1081 | } |
| 1082 | |
| 1083 | const auto* loadedObject = ObjectManagerGetLoadedObject(ObjectEntryDescriptor(*ori)); |
| 1084 | if (loadedObject != nullptr) |
| 1085 | { |
| 1086 | console.WriteLineError("Object is already in scenario."); |
| 1087 | return; |
| 1088 | } |
| 1089 | |
| 1090 | auto& objectManager = GetContext()->GetObjectManager(); |
| 1091 | loadedObject = objectManager.LoadRepositoryItem(*ori); |
| 1092 | if (loadedObject == nullptr) |
| 1093 | { |
| 1094 | console.WriteLineError("Unable to load object."); |
| 1095 | return; |
| 1096 | } |
| 1097 | auto groupIndex = ObjectManagerGetLoadedObjectEntryIndex(loadedObject); |
| 1098 | |
| 1099 | ObjectType objectType = loadedObject->GetObjectType(); |
| 1100 | if (objectType == ObjectType::ride) |
| 1101 | { |
| 1102 | // Automatically research the ride so it's supported by the game. |
| 1103 | const auto* rideEntry = GetRideEntryByIndex(groupIndex); |
| 1104 | |
| 1105 | for (int32_t j = 0; j < RCT2::ObjectLimits::kMaxRideTypesPerRideEntry; j++) |
| 1106 | { |
nothing calls this directly
no test coverage detected