private void init() { if (initialized) { return; } initialized = true; rcsIndices = SSTUUtils.parseIntArray(rcsModuleIndex); engineIndices = SSTUUtils.parseIntArray(engineModuleIndex); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] fuelTypeNodes = node.GetNodes("FUELTYPE"); int len = fuelTypeNodes.Length; fuelTypes = FuelTypeISP.parse(fuelTypeNodes); fuelType = Array.Find(fuelTypes, m => m.fuelPreset.name == currentFuelType); if (fuelType == null && (fuelTypes != null && fuelTypes.Length > 0)) { SSTULog.error("ERROR: SSTUModularRCS - currentFuelType was null for value: " + currentFuelType); fuelType = fuelTypes[0]; currentFuelType = fuelType.fuelPreset.name; SSTULog.error("Assigned default fuel type of: " + currentFuelType + ". This is likely a config error that needs to be corrected."); } else if (fuelTypes == null || fuelTypes.Length < 1) { SSTULog.error("ERROR: SSTURCSFuelSelection - No fuel type definitions found."); } }
public static void updateResourceVolume(Part part) { SSTULog.debug("Part volume changed..."); SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>(); if (vc != null) { vc.recalcVolume(); SSTUResourceBoiloff rb = part.GetComponent <SSTUResourceBoiloff>(); if (rb != null) { rb.onPartResourcesChanged(); } } else { IContainerVolumeContributor[] contributors = part.FindModulesImplementing <IContainerVolumeContributor>().ToArray(); ContainerContribution[] cts; int len = contributors.Length; float totalVolume = 0; for (int i = 0; i < len; i++) { cts = contributors[i].getContainerContributions(); int len2 = cts.Length; for (int k = 0; k < len2; k++) { totalVolume += cts[k].containerVolume; } } realFuelsVolumeUpdate(part, totalVolume); } }
public static void updateEngineFuelType(FuelTypeISP fuelType, Part part, int engineModuleIndex) { if (engineModuleIndex < 0) { return; } ModuleEngines[] engines = part.GetComponents <ModuleEngines>(); int len = engines.Length; if (engineModuleIndex < len) { ModuleEngines engine = engines[engineModuleIndex]; engine.propellants.Clear(); ConfigNode pNode = fuelType.fuelPreset.getPropellantNode(ResourceFlowMode.ALL_VESSEL_BALANCE); if (fuelType.atmosphereCurve != null) { pNode.AddNode("atmosphereCurve", fuelType.atmosphereCurve.getNode("atmosphereCurve")); } engine.OnLoad(pNode); } else { SSTULog.error("Could not update fuel type - ModuleEngines could not be found for index: " + engineModuleIndex + " There are not enough modules present in the part: " + len); } }
public void thrustCurveGuiClosed(string preset, FloatCurve curve) { //update the persistent curve data from currentCurve = curve; presetCurveName = preset; usePresetCurve = !string.IsNullOrEmpty(presetCurveName); if (!usePresetCurve) { customCurveData = currentCurve.ToStringSingleLine(); } SSTULog.debug("Updating engine thrust cuve data. Use preset: " + usePresetCurve); updateEngineCurve(); }
/// <summary> /// Recalculates volume for all containers by finding all IContainerVolumeContributor implementors, and summing the volume for each container from the returned values. /// Removes the need to manually calculate new % values for each container. /// </summary> public void recalcVolume() { if (!initializedResources || containers == null) { //not yet initialized -- recalc will be called during Start, so ignore for now return; } float[] volumes = new float[numberOfContainers]; IContainerVolumeContributor[] contributors = part.FindModulesImplementing <IContainerVolumeContributor>().ToArray(); ContainerContribution[] cts; int len = contributors.Length; for (int i = 0; i < len; i++) { if (contributors[i] == null) { SSTULog.error("NULL Container Contributor"); } cts = contributors[i].getContainerContributions(); if (cts == null) { SSTULog.error("NULL Container Contributor Contributions"); } int len2 = cts.Length; for (int k = 0; k < len2; k++) { int idx = cts[k].containerIndex; if (idx < volumes.Length && idx >= 0) { volumes[cts[k].containerIndex] += cts[k].containerVolume; } } } len = containers.Length; for (int i = 0; i < len; i++) { if (containers[i] == null) { SSTULog.error("NULL Container definition for index: " + i); } containers[i].setContainerVolume(volumes[i]); } updateMassAndCost(); //update cached part mass and cost values updatePersistentData(); //update persistent data in case tank was just initialized updateFuelSelections(); //update the selections for the 'FuelType' UI slider, this adds or removes the 'custom' option as needed updatePartStats(); //update part stats for crash tolerance and heat, as determined by the container modifiers updateGUIControls(); updateTankResources(); SSTUStockInterop.fireEditorUpdate(); }
public static void openGUI(SSTUEngineThrustCurveGUI srbModule, string preset, FloatCurve inputCurve) { module = srbModule; id = module.GetInstanceID(); MonoBehaviour.print("ThrustCurveEditor-input curve: " + curve + "\n" + SSTUUtils.printFloatCurve(curve)); presetName = preset; setupCurveData(inputCurve); texture = new Texture2D(graphWidth, graphHeight); updateGraphTexture(); loadPresets(); if (activeGUI == null) { activeGUI = srbModule.gameObject.AddComponent <ThrustCurveEditorGUI>(); SSTULog.debug("Created new gui object: " + activeGUI); } }
public FuelTypeISP(ConfigNode node) { fuelPreset = VolumeContainerLoader.getPreset(node.GetStringValue("name")); if (fuelPreset == null) { SSTULog.error("Could not locate fuel preset for name: " + node.GetStringValue("name")); } if (node.HasNode("atmosphereCurve")) { atmosphereCurve = node.GetFloatCurve("atmosphereCurve"); } else { atmosphereCurve = null; } }
/// <summary> /// Applies the 'currentCurve' to the engine module as its active thrust curve. /// </summary> private void updateEngineCurve() { ModuleEngines[] engines = part.GetComponents <ModuleEngines>(); if (engineModuleIndex < 0) { return; } //config error if (engineModuleIndex >= engines.Length) { return; } //config error if (currentCurve == null) { return; } //code error SSTULog.debug("Updating ModuleEngine's thrust-curve"); engines[engineModuleIndex].thrustCurve = currentCurve; }
public static void updateContainerFuelType(FuelTypeISP fuelType, Part part, int containerIndex) { if (containerIndex < 0) { return; } SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>(); if (vc == null) { SSTULog.error("Could not update fuel type - no SSTUVolumeContainer found in part"); return; } if (containerIndex < vc.numberOfContainers) { vc.setFuelPreset(containerIndex, fuelType.fuelPreset, false); vc.recalcVolume(); } else { SSTULog.error("Could not update fuel type - not enough containers in SSTUVolumeContainer for index: " + containerIndex + " only found: " + vc.numberOfContainers); } }
private void updateGimbalOffset() { int len = gimbalModule.gimbalTransforms.Count(); Transform tr; Quaternion rot; for (int i = 0; i < len; i++) { tr = gimbalModule.gimbalTransforms[i]; if (tr == null) { SSTULog.error("NULL gimbal transform detected in ModuleGimbal's transform list!"); continue; } //use the parts 'right' and 'fwd' vectors for part-local axis rotations Vector3 vesselRight = part.transform.right; Vector3 vesselFwd = part.transform.forward; vesselRight = tr.InverseTransformDirection(vesselRight); vesselFwd = tr.InverseTransformDirection(vesselFwd); rot = defaultOrientations[i] * Quaternion.AngleAxis(gimbalOffsetX * gimbalXRange, vesselRight); tr.localRotation = rot * Quaternion.AngleAxis(gimbalOffsetZ * gimbalZRange, vesselFwd); gimbalModule.initRots[i] = tr.localRotation; } }
/// <summary> /// Called by SSTUModInterop whenever resources are changed for a part and VolumeContainer is present. /// </summary> public void onPartResourcesChanged() { SSTULog.debug("Part resources changed..."); initialize(); updateStatsFromContainer(); }