MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ConsoleCommandLoadObject

Function ConsoleCommandLoadObject

src/openrct2/interface/InteractiveConsole.cpp:1049–1137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1047}
1048
1049static 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 {

Callers

nothing calls this directly

Calls 15

GetContextFunction · 0.85
GetRideEntryByIndexFunction · 0.85
ResearchInsertRideEntryFunction · 0.85
ResearchResetCurrentItemFunction · 0.85
ContextBroadcastIntentFunction · 0.85
GfxInvalidateScreenFunction · 0.85
WriteLineErrorMethod · 0.80
FindObjectMethod · 0.80
FindObjectLegacyMethod · 0.80

Tested by

no test coverage detected