/// <summary> /// Creates a new instance of the MaterialsLibrary /// </summary> public MaterialsLibrary() { foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("MATERIAL")) { MaterialDefinition material = new MaterialDefinition(node); _materials.Add(material, material.name); } _count = materials.Count; }
/// <summary> /// Tries to get the material of the given name and stores it in the out value /// </summary> /// <param name="name">Name of the material to find</param> /// <param name="material">Value to store the result into</param> public bool TryGetMaterial(string name, ref MaterialDefinition material) { if (ContainsMaterial(name)) { material = this._materials[name]; return(true); } if (!string.IsNullOrEmpty(name) && this._materials.Count > 0) { Debug.LogError("[RealChute]: Could not find the MaterialDefinition \"" + name + "\" in the library"); } return(false); }
/// <summary> /// Returns true and stores the value in the ref if the library contains a definition for the material. /// </summary> /// <param name="name">Name of the material</param> /// <param name="material">Value to store the result in</param> public bool TryGetMaterial(string name, ref MaterialDefinition material) { if (MaterialExists(name)) { material = GetMaterial(name); return(true); } if (name != "empty" && name != string.Empty) { UnityEngine.Debug.LogWarning("[RealChute]: Could not find the " + name + " material within library"); } return(false); }
/// <summary> /// Returns true and stores the value in the ref if the library contains a definition for the material. /// </summary> /// <param name="name">Name of the material</param> /// <param name="material">Value to store the result in</param> public bool TryGetMaterial(string name, ref MaterialDefinition material) { if (MaterialExists(name)) { material = GetMaterial(name); return true; } if (name != "empty" && name != string.Empty) { UnityEngine.Debug.LogWarning("[RealChute]: Could not find the " + name + " material within library"); } return false; }
//Applies the preset on the chute internal void ApplyPreset(Preset preset) { Preset.ChuteParameters parameters = preset.parameters[id]; this.material = this.pChute.materials.GetMaterial(parameters.material); this.templateGUI.materialsID = this.pChute.materials.GetMaterialIndex(parameters.material); this.templateGUI.preDepDiam = parameters.preDeployedDiameter; this.templateGUI.depDiam = parameters.deployedDiameter; this.templateGUI.isPressure = parameters.minIsPressure; this.templateGUI.predepClause = this.templateGUI.isPressure ? parameters.minPressure : parameters.minDeployment; if (templateGUI.isPressure) { this.parachute.minDeployment = float.Parse(parameters.minDeployment); } else { this.parachute.minPressure = float.Parse(parameters.minPressure); } this.templateGUI.deploymentAlt = parameters.deploymentAlt; this.templateGUI.cutAlt = parameters.cutAlt; this.templateGUI.preDepSpeed = parameters.preDeploymentSpeed; this.templateGUI.depSpeed = parameters.deploymentSpeed; if (this.textures != null) { if (this.textures.ContainsCanopy(parameters.chuteTexture)) { this.templateGUI.chuteID = this.textures.GetCanopyIndex(parameters.chuteTexture); } if (this.textures.ContainsModel(parameters.modelName)) { this.templateGUI.modelID = this.textures.GetModelIndex(parameters.modelName); } } this.templateGUI.typeID = parameters.type; this.templateGUI.calcSelect = parameters.calcSelect; this.templateGUI.getMass = parameters.getMass; this.templateGUI.useDry = parameters.useDry; this.templateGUI.mass = parameters.mass; this.templateGUI.landingSpeed = parameters.landingSpeed; this.templateGUI.deceleration = parameters.deceleration; this.templateGUI.refDepAlt = parameters.refDepAlt; this.templateGUI.chuteCount = parameters.chuteCount; }
//Applies changes to the parachute internal void ApplyChanges(bool toSymmetryCounterparts) { this.parachute.material = this.material.name; this.parachute.mat = this.material; if (this.templateGUI.calcSelect) { double m = this.templateGUI.getMass ? this.pChute.GetCraftMass(this.templateGUI.useDry) : double.Parse(this.templateGUI.mass); double alt = 0, acc = 0; switch (this.templateGUI.type) { case ParachuteType.Main: { alt = double.Parse(this.pChute.landingAlt); acc = (this.body.GeeASL * RCUtils.geeToAcc); break; } case ParachuteType.Drogue: { alt = double.Parse(this.templateGUI.refDepAlt); acc = (this.body.GeeASL * RCUtils.geeToAcc); break; } case ParachuteType.Drag: { alt = double.Parse(this.pChute.landingAlt); acc = double.Parse(this.templateGUI.deceleration); break; } default: break; } double density = this.body.GetDensityAtAlt(alt, this.body.GetMaxTemperatureAtAlt(alt)); double speed = double.Parse(this.templateGUI.landingSpeed); speed *= speed; Debug.Log(String.Format("[RealChute]: {0} {1} - m: {2}t, alt: {3}m, ρ: {4}kg/m³, v²: {5}m²/s², a: {6}m/s²", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), m, alt, density, speed, acc)); this.parachute.deployedDiameter = RCUtils.Round(Math.Sqrt((8000 * m * acc) / (Math.PI * speed * material.dragCoefficient * density * double.Parse(this.templateGUI.chuteCount)))); float maxDiam = (this.textures != null || this.textures.models.Count > 0) ? this.model.maxDiam : 70; if (this.parachute.deployedDiameter > this.model.maxDiam) { this.parachute.deployedDiameter = maxDiam; this.editorGUI.warning = true; } else { this.editorGUI.warning = false; } this.parachute.preDeployedDiameter = RCUtils.Round(this.templateGUI.type == ParachuteType.Main ? (this.parachute.deployedDiameter / 20) : (this.parachute.deployedDiameter / 2)); Debug.Log(String.Format("[RealChute]: {0} {1} - depDiam: {2}m, preDepDiam: {3}m", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), this.parachute.deployedDiameter, this.parachute.preDeployedDiameter)); } else { this.parachute.preDeployedDiameter = RCUtils.Round(float.Parse(this.templateGUI.preDepDiam)); this.parachute.deployedDiameter = RCUtils.Round(float.Parse(this.templateGUI.depDiam)); Debug.Log(String.Format("[RealChute]: {0} {1} - depDiam: {2}m, preDepDiam: {3}m", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), this.parachute.deployedDiameter, this.parachute.preDeployedDiameter)); } this.parachute.minIsPressure = this.templateGUI.isPressure; if (this.templateGUI.isPressure) { this.parachute.minPressure = float.Parse(this.templateGUI.predepClause); } else { this.parachute.minDeployment = float.Parse(this.templateGUI.predepClause); } this.parachute.deploymentAlt = float.Parse(this.templateGUI.deploymentAlt); this.parachute.cutAlt = GUIUtils.ParseEmpty(this.templateGUI.cutAlt); this.parachute.preDeploymentSpeed = float.Parse(this.templateGUI.preDepSpeed); this.parachute.deploymentSpeed = float.Parse(this.templateGUI.depSpeed); if (toSymmetryCounterparts) { foreach (Part part in this.part.symmetryCounterparts) { Parachute sym = ((RealChuteModule)part.Modules["RealChuteModule"]).parachutes[id]; sym.material = this.material.name; sym.mat = this.material; sym.deployedDiameter = this.parachute.deployedDiameter; sym.preDeployedDiameter = this.parachute.preDeployedDiameter; sym.minIsPressure = this.templateGUI.isPressure; sym.minPressure = this.parachute.minPressure; sym.minDeployment = this.parachute.minDeployment; sym.deploymentAlt = this.parachute.deploymentAlt; sym.cutAlt = this.parachute.cutAlt; sym.preDeploymentSpeed = this.parachute.preDeploymentSpeed; sym.deploymentSpeed = this.parachute.deploymentSpeed; TemplateGUI template = ((ProceduralChute)part.Modules["ProceduralChute"]).chutes[id].templateGUI; template.chuteID = this.templateGUI.chuteID; template.typeID = this.templateGUI.typeID; template.modelID = this.templateGUI.modelID; template.materialsID = this.templateGUI.materialsID; template.isPressure = this.templateGUI.isPressure; template.calcSelect = this.templateGUI.calcSelect; template.getMass = this.templateGUI.getMass; template.useDry = this.templateGUI.useDry; template.preDepDiam = this.templateGUI.preDepDiam; template.depDiam = this.templateGUI.depDiam; template.predepClause = this.templateGUI.predepClause; template.mass = this.templateGUI.mass; template.landingSpeed = this.templateGUI.landingSpeed; template.deceleration = this.templateGUI.deceleration; template.refDepAlt = this.templateGUI.refDepAlt; template.chuteCount = this.templateGUI.chuteCount; template.deploymentAlt = this.templateGUI.deploymentAlt; template.cutAlt = this.templateGUI.cutAlt; template.preDepSpeed = this.templateGUI.preDepSpeed; template.depSpeed = this.templateGUI.depSpeed; } } }
//Materials window GUI code internal void MaterialsWindow(int id) { GUI.DragWindow(new Rect(0, 0, materialsWindow.width, 25)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); materialsScroll = GUILayout.BeginScrollView(materialsScroll, false, false, skins.horizontalScrollbar, skins.verticalScrollbar, skins.box, GUILayout.MaxHeight(200), GUILayout.Width(140)); materialsID = GUILayout.SelectionGrid(materialsID, this.pChute.materials.materials.Values.ToArray(), 1, skins.button); GUILayout.EndScrollView(); GUILayout.BeginVertical(); MaterialDefinition material = this.pChute.materials.materials.Keys.ToArray()[materialsID]; StringBuilder builder = new StringBuilder(); builder.Append("Description: ").AppendLine(material.description); builder.Append("\nDrag coefficient: ").AppendLine(material.dragCoefficient.ToString("0.00#")); builder.Append("\nArea density: ").Append(material.areaDensity * 1000).AppendLine("kg/m²\n"); builder.Append("Area cost: ").Append(material.areaCost.ToString()).Append("f/m²"); GUILayout.Label(builder.ToString(), skins.label); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Choose material", skins.button, GUILayout.Width(150))) { this.material = material; this.materialsVisible = false; } if (GUILayout.Button("Cancel", skins.button, GUILayout.Width(150))) { this.materialsVisible = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
//Applies the preset on the chute internal void ApplyPreset(Preset preset) { Preset.ChuteParameters parameters = preset.parameters[id]; this.material = pChute.materials.GetMaterial(parameters.material); this.materialsID = pChute.materials.GetMaterialIndex(parameters.material); this.preDepDiam = parameters.preDeployedDiameter; this.depDiam = parameters.deployedDiameter; this.isPressure = parameters.minIsPressure; this.predepClause = this.isPressure ? parameters.minPressure : parameters.minDeployment; if (isPressure) { this.parachute.minDeployment = float.Parse(parameters.minDeployment); } else { this.parachute.minPressure = float.Parse(parameters.minPressure); } this.deploymentAlt = parameters.deploymentAlt; this.cutAlt = parameters.cutAlt; this.preDepSpeed = parameters.preDeploymentSpeed; this.depSpeed = parameters.deploymentSpeed; if (pChute.textureLibrary == preset.textureLibrary || pChute.textureLibrary != "none") { if (textures.canopyNames.Contains(parameters.chuteTexture) && textures.canopies.Count > 0 && !string.IsNullOrEmpty(parameters.chuteTexture)) { this.chuteID = textures.GetCanopyIndex(textures.GetCanopy(parameters.chuteTexture)); } if (textures.modelNames.Contains(parameters.modelName) && textures.models.Count > 0 && !string.IsNullOrEmpty(parameters.modelName)) { this.modelID = textures.GetModelIndex(textures.GetModel(parameters.modelName)); } } this.typeID = RCUtils.types.ToList().IndexOf(parameters.type); this.calcSelect = parameters.calcSelect; this.getMass = parameters.getMass; this.useDry = parameters.useDry; this.mass = parameters.mass; this.landingSpeed = parameters.landingSpeed; this.deceleration = parameters.deceleration; this.refDepAlt = parameters.refDepAlt; this.chuteCount = parameters.chuteCount; }
//Copies all fields to the symmetry counterpart public void CopyFromOriginal(RealChuteModule module, ProceduralChute pChute) { Parachute sym = module.parachutes[id]; ChuteTemplate template = pChute.chutes[id]; parachute = pChute.rcModule.parachutes[id]; material = sym.mat; parachute.deployedDiameter = sym.deployedDiameter; parachute.preDeployedDiameter = sym.preDeployedDiameter; isPressure = sym.minIsPressure; if (isPressure) { parachute.minPressure = sym.minPressure; } else { parachute.minDeployment = sym.minDeployment; } parachute.deploymentAlt = sym.deploymentAlt; parachute.cutAlt = sym.cutAlt; parachute.preDeploymentSpeed = sym.preDeploymentSpeed; parachute.deploymentSpeed = sym.deploymentSpeed; this.chuteID = template.chuteID; this.typeID = template.typeID; this.modelID = template.modelID; this.materialsID = template.materialsID; this.isPressure = template.isPressure; this.calcSelect = template.calcSelect; this.getMass = template.getMass; this.useDry = template.useDry; this.preDepDiam = template.preDepDiam; this.depDiam = template.depDiam; this.predepClause = template.predepClause; this.mass = template.mass; this.landingSpeed = template.landingSpeed; this.deceleration = template.deceleration; this.refDepAlt = template.refDepAlt; this.chuteCount = template.chuteCount; this.deploymentAlt = template.deploymentAlt; this.cutAlt = template.cutAlt; this.preDepSpeed = template.preDepSpeed; this.depSpeed = template.depSpeed; }
//Materials window GUI code internal void MaterialsWindow(int id) { GUI.DragWindow(new Rect(0, 0, materialsWindow.width, 25)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); materialsScroll = GUILayout.BeginScrollView(materialsScroll, false, false, skins.horizontalScrollbar, skins.verticalScrollbar, skins.box, GUILayout.MaxHeight(200), GUILayout.Width(140)); materialsID = GUILayout.SelectionGrid(materialsID, this.pChute.materials.materials.Values.ToArray(), 1, skins.button); GUILayout.EndScrollView(); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Label("Description:", skins.label); GUILayout.Label(this.pChute.materials.materials.Keys.ToArray()[materialsID].description, skins.label); GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace(); GUILayout.Label("Drag coefficient:", skins.label); GUILayout.Label(this.pChute.materials.materials.Keys.ToArray()[materialsID].dragCoefficient.ToString("0.00#"), skins.label); GUILayout.FlexibleSpace(); GUILayout.Label("Area density:", skins.label); GUILayout.Label(this.pChute.materials.materials.Keys.ToArray()[materialsID].areaDensity * 1000 + "kg/m²", skins.label); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Choose material", skins.button)) { material = this.pChute.materials.materials.Keys.ToArray()[materialsID]; this.materialsVisible = false; } if (GUILayout.Button("Cancel", skins.button)) { this.materialsVisible = false; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
/// <summary> /// Tries to get the material of the given name and stores it in the out value /// </summary> /// <param name="name">Name of the material to find</param> /// <param name="material">Value to store the result into</param> public bool TryGetMaterial(string name, ref MaterialDefinition material) { if (ContainsMaterial(name)) { material = this._materials[name]; return true; } if (!string.IsNullOrEmpty(name) && this._materials.Count > 0) { Debug.LogError("[RealChute]: Could not find the MaterialDefinition \"" + name + "\" in the library"); } return false; }
//Materials window GUI code internal void MaterialsWindow(int id) { GUI.DragWindow(drag); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); this.materialsScroll = GUILayout.BeginScrollView(this.materialsScroll, false, false, this.skins.horizontalScrollbar, this.skins.verticalScrollbar, this.skins.box, GUILayout.MaxHeight(200), GUILayout.Width(140)); this.materialsID = GUILayout.SelectionGrid(this.materialsID, this.pChute.materials.materialNames, 1, this.skins.button); GUILayout.EndScrollView(); GUILayout.BeginVertical(); MaterialDefinition material = new MaterialDefinition(); if (this.pChute.materials.materialNames.IndexInRange(this.materialsID)) { string name = this.pChute.materials.materialNames[this.materialsID]; this.pChute.materials.TryGetMaterial(name, ref material); } StringBuilder builder = new StringBuilder(); builder.Append("Description: ").AppendLine(material.description); builder.Append("\nDrag coefficient: ").AppendLine(material.dragCoefficient.ToString("0.00#")); builder.Append("\nArea density: ").Append(material.areaDensity * 1000).AppendLine("kg/m²"); builder.Append("\nArea cost: ").Append(material.areaCost.ToString()).Append("F/m²"); builder.Append("\nMax temperature: ").Append((material.maxTemp + RCUtils.absoluteZero).ToString()).Append("°C"); builder.Append("\nSpecific heat: ").Append(material.specificHeat.ToString()).Append("J/kg∙K"); builder.Append("\nEmissivity constant: ").Append(material.emissivity.ToString()); GUILayout.Label(builder.ToString(), this.skins.label); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Choose material", this.skins.button, GUILayout.Width(150))) { this.material = material; this.materialsVisible = false; } if (GUILayout.Button("Cancel", this.skins.button, GUILayout.Width(150))) { this.materialsVisible = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
/// <summary> /// Loads the Parachute from a ConfigNode. /// </summary> /// <param name="node">Node to load the Parachute from</param> private void Load(ConfigNode node) { node.TryGetValue("material", ref material); node.TryGetValue("preDeployedDiameter", ref preDeployedDiameter); node.TryGetValue("deployedDiameter", ref deployedDiameter); node.TryGetValue("minIsPressure", ref minIsPressure); node.TryGetValue("minDeployment", ref minDeployment); node.TryGetValue("minPressure", ref minPressure); node.TryGetValue("deploymentAlt", ref deploymentAlt); node.TryGetValue("cutAlt", ref cutAlt); node.TryGetValue("preDeploymentSpeed", ref preDeploymentSpeed); node.TryGetValue("deploymentSpeed", ref deploymentSpeed); node.TryGetValue("parachuteName", ref parachuteName); node.TryGetValue("baseParachuteName", ref baseParachuteName); node.TryGetValue("capName", ref capName); node.TryGetValue("preDeploymentAnimation", ref preDeploymentAnimation); node.TryGetValue("deploymentAnimation", ref deploymentAnimation); node.TryGetValue("forcedOrientation", ref forcedOrientation); node.TryGetValue("depState", ref depState); if (!MaterialsLibrary.instance.TryGetMaterial(material, ref mat)) { material = "Nylon"; mat = MaterialsLibrary.instance.GetMaterial("Nylon"); } }
public override string GetInfo() { if (!CompatibilityChecker.IsCompatible()) { return string.Empty; } //Info in the editor part window MaterialDefinition mat = new MaterialDefinition(), secMat = new MaterialDefinition(); float chuteMass = 0, secChuteMass = 0; if (materials.MaterialExists(material)) { mat = materials.GetMaterial(material); chuteMass = mat.areaDensity * deployedDiameter; } if (secondaryChute && materials.MaterialExists(secMaterial)) { secMat = materials.GetMaterial(secMaterial); secChuteMass = secMat.areaDensity * secDeployedDiameter; } this.part.mass = caseMass + chuteMass + secChuteMass; string infoList = string.Empty; infoList = String.Format("Parachute material: {0}\n", material); if (secondaryChute && secMaterial != material && secMaterial != "empty") { infoList += String.Format("Secondary parachute material: {0}\n", secMaterial); } infoList += String.Format("Case mass: {0}\n", caseMass); if (material == secMaterial) { infoList += String.Format("Drag coefficient: {0:0.00}\n", mat.dragCoefficient); } else { infoList += String.Format("Drag coefficients: {0:0.00}, {1:0.00}\n", mat.dragCoefficient, secMat.dragCoefficient); } if (timer > 0) { infoList += String.Format("Deployment timer: {0}s\n", timer); } if (mustGoDown) { infoList += "Must go downwards to deploy: true\n"; } if (deployOnGround) { infoList += "Deploys on ground contact: true\n"; } if (spareChutes >= 0) { infoList += String.Format("Spare chutes: {0}\n", spareChutes); } if (!secondaryChute) { infoList += String.Format("Predeployed diameter: {0}m\n", preDeployedDiameter); infoList += String.Format("Deployed diameter: {0}m\n", deployedDiameter); if (!minIsPressure) { infoList += String.Format("Minimum deployment altitude: {0}m\n", minDeployment); } else { infoList += String.Format("Minimum deployment pressure: {0}atm\n", minPressure); } infoList += String.Format("Deployment altitude: {0}m\n", deploymentAlt); infoList += String.Format("Predeployment speed: {0}s\n", preDeploymentSpeed); infoList += String.Format("Deployment speed: {0}s\n", deploymentSpeed); infoList += String.Format("Autocut speed: {0}m/s\n", cutSpeed); if (cutAlt >= 0) { infoList += String.Format("Autocut altitude: {0}m\n", cutAlt); } } //In case of dual chutes else { infoList += String.Format("Predeployed diameters: {0}m, {1}m\n", preDeployedDiameter, secPreDeployedDiameter); infoList += String.Format("Deployed diameters: {0}m, {1}m\n", deployedDiameter, secDeployedDiameter); if (!minIsPressure && !secMinIsPressure) { infoList += String.Format("Minimum deployment altitudes: {0}m, {1}m\n", minDeployment, secMinDeployment); } else if (minIsPressure && !secMinIsPressure) { infoList += String.Format("Minimum deployment clauses: {0}atm, {1}m\n", minDeployment, secMinDeployment); } else if (!minIsPressure && secMinIsPressure) { infoList += String.Format("Minimum deployment clauses: {0}m, {1}atm\n", minDeployment, secMinDeployment); } else if (minIsPressure && secMinIsPressure) { infoList += String.Format("Minimum deployment pressures: {0}atmm, {1}atm\n", minDeployment, secMinDeployment); } infoList += String.Format("Deployment altitudes: {0}m, {1}m\n", deploymentAlt, secDeploymentAlt); infoList += String.Format("Predeployment speeds: {0}s, {1}s\n", preDeploymentSpeed, secPreDeploymentSpeed); infoList += String.Format("Deployment speeds: {0}s, {1}s\n", deploymentSpeed, secDeploymentSpeed); infoList += String.Format("Autocut speed: {0}m/s\n", cutSpeed); if (cutAlt >= 0 && secCutAlt >= 0) { infoList += String.Format("Autocut altitudes: {0}m, {1}m\n", cutAlt, secCutAlt); } else if (cutAlt >= 0 && secCutAlt < 0) { infoList += String.Format("Main chute autocut altutude: {0}m\n", cutAlt); } else if (cutAlt < 0 && secCutAlt >= 0) { infoList += String.Format("Secondary chute autocut altitude: {0}m\n", secCutAlt); } } return infoList; }