SpaceStationType::SpaceStationType(const std::string &id_, const std::string &path_) : id(id_) , model(0) , modelName("") , angVel(0.f) , dockMethod(SURFACE) , numDockingPorts(0) , numDockingStages(0) , numUndockStages(0) , shipLaunchStage(3) , parkingDistance(0) , parkingGapSize(0) { Json::Reader reader; Json::Value data; auto fd = FileSystem::gameDataFiles.ReadFile(path_); if (!fd) { Output("couldn't open station def '%s'\n", path_.c_str()); return; } if (!reader.parse(fd->GetData(), fd->GetData()+fd->GetSize(), data)) { Output("couldn't read station def '%s': %s\n", path_.c_str(), reader.getFormattedErrorMessages().c_str()); return; } modelName = data.get("model", "").asString(); const std::string type(data.get("type", "").asString()); if (type == "surface") dockMethod = SURFACE; else if (type == "orbital") dockMethod = ORBITAL; else { Output("couldn't parse station def '%s': unknown type '%s'\n", path_.c_str(), type.c_str()); return; } angVel = data.get("angular_velocity", 0.0f).asFloat(); parkingDistance = data.get("parking_distance", 0.0f).asFloat(); parkingGapSize = data.get("parking_gap_size", 0.0f).asFloat(); padOffset = data.get("pad_offset", 150.f).asFloat(); model = Pi::FindModel(modelName); assert(model); OnSetupComplete(); }
SpaceStationType::SpaceStationType(const std::string &id_, const std::string &path_) : id(id_), model(0), modelName(""), angVel(0.f), dockMethod(SURFACE), numDockingPorts(0), numDockingStages(0), numUndockStages(0), shipLaunchStage(3), parkingDistance(0), parkingGapSize(0) { Json data = JsonUtils::LoadJsonDataFile(path_); if (data.is_null()) { Output("couldn't read station def '%s'\n", path_.c_str()); throw StationTypeLoadError(); } modelName = data.value("model", ""); const std::string type = data.value("type", ""); if (type == "surface") dockMethod = SURFACE; else if (type == "orbital") dockMethod = ORBITAL; else { Output("couldn't parse station def '%s': unknown type '%s'\n", path_.c_str(), type.c_str()); throw StationTypeLoadError(); } angVel = data.value("angular_velocity", 0.0f); parkingDistance = data.value("parking_distance", 0.0f); parkingGapSize = data.value("parking_gap_size", 0.0f); padOffset = data.value("pad_offset", 150.f); model = Pi::FindModel(modelName, /* allowPlaceholder = */ false); if (!model) { Output("couldn't initialize station type '%s' because the corresponding model ('%s') could not be found.\n", path_.c_str(), modelName.c_str()); throw StationTypeLoadError(); } OnSetupComplete(); }