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 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); } }
/// <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 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; } }
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; } }