static public bool isDecoupler(Part p) { if (p == null) { ASPConsoleStuff.AAprint("isDecoupler passed a null!"); return(false); } if (p.name.ToLower().Contains("decoupler")) { return(true); } foreach (PartModule pm in p.Modules) { if (pm.moduleName == "ModuleDecouple") { return(true); } if (pm.moduleName == "ModuleAnchoredDecoupler") { return(true); } if (pm.moduleName == "SSTUCustomRadialDecoupler") { return(true); } } return(false); }
// Called after the scene is loaded. public void Awake() { ASPConsoleStuff.AAprint("Awake()"); #if DEBUG // don't load configs because KramaxReload screws up PluginConfiguration #else PluginConfiguration config = PluginConfiguration.CreateForType <AutoAsparagus> (); config.load(); vizualize = config.GetValue <bool> ("vizualize"); stageParachutes = config.GetValue <bool> ("stageParachutes"); stageLaunchClamps = config.GetValue <bool> ("stageLaunchClamps"); launchClampsStage = config.GetValue <int> ("launchClampsStage"); stagesepratrons = config.GetValue <bool> ("stagesepratrons"); useSmartStage = config.GetValue <bool> ("useSmartStage"); windowRect.x = (float)config.GetValue <int> ("windowRectX"); windowRect.y = (float)config.GetValue <int> ("windowRectY"); if ((windowRect.x == 0) && (windowRect.y == 0)) { windowRect.x = Screen.width * 0.35f; windowRect.y = Screen.height * 0.1f; } #endif ASPConsoleStuff.AAprint("Add onEditorShipModified hook"); GameEvents.onEditorShipModified.Add(onCraftChange); ASPConsoleStuff.AAprint("End of Awake()"); }
// Called after Awake() public void Start() { ASPConsoleStuff.AAprint("Start()"); aspTexture = loadTexture("AutoAsparagus/asparagus"); onionTexture = loadTexture("AutoAsparagus/onion"); nofuelTexture = loadTexture("AutoAsparagus/nofuel"); launchclampTexture = loadTexture("AutoAsparagus/launchclamp"); parachuteTexture = loadTexture("AutoAsparagus/parachute"); sepratronTexture = loadTexture("AutoAsparagus/sepratron"); rainbowTexture = loadTexture("AutoAsparagus/rainbow"); AssemblyLoader.LoadedAssembly SmartStage = AssemblyLoader.loadedAssemblies.SingleOrDefault(a => a.dllName == "SmartStage"); if (SmartStage != null) { ASPConsoleStuff.AAprint("found SmartStage"); try { computeStagesMethod = SmartStage.assembly.GetTypes().SingleOrDefault(t => t.Name == "SmartStage").GetMethod("computeStages"); } catch (Exception e) { UnityEngine.Debug.LogError("Error finding the method definition\n" + e.StackTrace); } smartstageTexture = loadTexture("SmartStage/SmartStage38"); SmartStageAvailable = true; } else { ASPConsoleStuff.AAprint("no SmartStage found"); useSmartStage = false; } versionString = Assembly.GetCallingAssembly().GetName().Version.ToString(); line = lineObj.AddComponent <LineRenderer>(); line.material = Resources.Load <Material>("Telemetry/TelemetryMaterial"); line.useWorldSpace = false; line.startColor = Color.red; line.endColor = Color.red; line.startWidth = 0.2f; line.endWidth = 0.2f; line.positionCount = 2; line.SetPosition(0, Vector3.zero); line.enabled = false; ASPConsoleStuff.AAprint("setting up toolbar"); toolbarControl = gameObject.AddComponent <ToolbarControl>(); toolbarControl.AddToAllToolbars(appOnTrue, appOnFalse, ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH, MODID, "AutoAsparagusButton", "AutoAsparagus/asparagus-app", "AutoAsparagus/asparagus", MODNAME ); ASPConsoleStuff.AAprint("End of Start()"); }
private static bool researchedFuelLines() { AvailablePart ap = PartLoader.getPartInfoByName("fuelLine"); if (ap == null) { ASPConsoleStuff.AAprint("no fuelLine AvailablePart()"); return(false); } ASPConsoleStuff.AAprint("checking PartTechAvailable"); return(partResearched(ap)); }
private void newReloadShip() { ASPConsoleStuff.AAprint("newReloadShip() starting..."); EditorLogic editor = EditorLogic.fetch; ConfigNode shipCfg = editor.ship.SaveShip(); string filename = "saves/" + HighLogic.SaveFolder + "/Ships/VAB/AutoAsparagus.craft.hidden"; shipCfg.Save(filename); EditorLogic.LoadShipFromFile(filename); EditorLogic.fetch.SetBackup(); ASPConsoleStuff.AAprint("newReloadShip() done!"); }
static public void stageChain(List <Part> chain) { ASPConsoleStuff.printPartList("== Staging chain", "chain part", chain); int lowestStage = StageManager.StageCount - 1; foreach (Part p in chain) { if (p.parent.inverseStage < lowestStage) { lowestStage = p.parent.inverseStage; } } ASPConsoleStuff.AAprint("..lowest stage is " + lowestStage.ToString() + " out of " + StageManager.StageCount.ToString() + " total stages"); ASPConsoleStuff.AAprint("..adding " + (chain.Count - 1).ToString() + " stages"); int stage = lowestStage + chain.Count - 1; int partNumber = 0; int safetyfactor = 10000; while (partNumber < (chain.Count)) { safetyfactor = safetyfactor - 1; if (safetyfactor == 0) { AutoAsparagus.osd("Infinite loop in stageChain, aborting :("); AutoAsparagus.mystate = AutoAsparagus.ASPState.IDLE; return; } // Parent should be a decoupler Part parent = chain [partNumber].parent; ASPConsoleStuff.printPart("..parent is ", parent); if (isDecoupler(parent)) { ASPConsoleStuff.printPart("..setting part " + partNumber.ToString() + " to stage " + stage.ToString(), chain [partNumber]); setPartStage(chain [partNumber].parent, stage); setPartStage(chain [partNumber], stage); stageChildren(chain [partNumber], stage); } else { ASPConsoleStuff.AAprint("..parent is not a decoupler, ignoring!"); } stage = stage - 1; partNumber = partNumber + 1; } }
static public List <Part> findFuelTanks(List <Part> parts) { List <Part> tanks = new List <Part> (); ASPConsoleStuff.AAprint("=== Looking for fuel tanks"); foreach (Part p in parts) { //if ((isFuelTank(p)) && (p.symmetryCounterparts.Count>0) && (!isFuelTank(p.parent))){ if (isConnectableFuelTank(p)) { ASPConsoleStuff.printPart("Adding fuel tank", p); tanks.Add(p); } } return(tanks); }
static private void stageChildren(Part p, int stage) { // Sepratrons should be children foreach (Part child in p.children) { if ((AutoAsparagus.stagesepratrons) && (child.name.ToLower().Contains("sepmotor"))) { ASPConsoleStuff.printPart("..setting child Sepratron to stage " + stage.ToString(), child); setPartStage(child, stage); } if ((AutoAsparagus.stageParachutes) && (child.name.ToLower().Contains("parachute"))) { ASPConsoleStuff.printPart("..setting child Parachute to stage " + stage.ToString(), child); setPartStage(child, stage); } } }
private static bool partResearched(AvailablePart ap) { if (ResearchAndDevelopment.Instance == null) { ASPConsoleStuff.AAprint("no ResearchAndDevelopment.Instance, must be sandbox mode"); return(true); } if (!ResearchAndDevelopment.PartTechAvailable(ap)) { ASPConsoleStuff.AAprint(ap.name + ".PartTechAvailable()==false"); return(false); } if (!ResearchAndDevelopment.PartModelPurchased(ap)) { ASPConsoleStuff.AAprint(ap.name + ".PartModelPurchased()==false"); return(false); } return(true); }
static public bool isFuelTank(Part p) { if (p == null) { ASPConsoleStuff.AAprint("isFuelTank.p is null!"); return(false); } PartResourceList rl = p.Resources; if (rl == null) { ASPConsoleStuff.printPart("isFuelTank: Part is NOT a fuel tank, no resources", p); return(false); } if (rl.Count == 0) { ASPConsoleStuff.printPart("isFuelTank: Part is NOT a fuel tank, no resources", p); return(false); } // Check if this part has any resource that would actually flow through a fuel line PartResourceDefinition resource; foreach (PartResource pr in rl.dict.Values) { ASPConsoleStuff.printPart("isFuelTank: part has resource named: " + pr.resourceName, p); resource = PartResourceLibrary.Instance.GetDefinition(pr.resourceName); if (resource.resourceFlowMode == ResourceFlowMode.STACK_PRIORITY_SEARCH) { ASPConsoleStuff.printPart("isFuelTank: Part IS a fuel tank, has flowable resource: " + pr.resourceName, p); return(true); } else { ASPConsoleStuff.printPart("isFuelTank: resource is not flowable: " + resource.resourceFlowMode.ToString(), p); } } return(false); }
static public void StageLaunchClamps(int launchClampsStage) { var editor = EditorLogic.fetch; // Get all the parts of the ship var parts = editor.ship.parts; int stage = StageManager.StageCount - 1; if (launchClampsStage == 1) { stage = stage - 1; } foreach (Part p in parts) { if (p.name.ToLower().Contains("launchclamp")) { ASPConsoleStuff.printPart("Putting launch clamp into stage " + stage.ToString() + ", launchClampsStage =" + launchClampsStage.ToString(), p); setPartStage(p, stage); } } }
/*public static class PartIconGenerator * { * private const string IconHiddenTag = "Icon_Hidden"; * private const string KerbalEvaSubstring = "kerbal"; * * private static readonly int GameObjectLayer = LayerMask.NameToLayer ("PartsList_Icons"); * // note to future: if creating icons inside editor, you might want to choose a different layer or translate the camera and object out of frame * * private static Camera CreateCamera (int pixelWidth, int pixelHeight, Color backgroundColor) * { * //var camGo = new GameObject ("PartIconGenerator.Camera", typeof(Camera)); * //var cam = camGo.camera; * Camera cam = new Camera(); * * cam.enabled = false; * cam.cullingMask = (1 << GameObjectLayer); * cam.clearFlags = ~CameraClearFlags.Nothing; * cam.nearClipPlane = 0.1f; * cam.farClipPlane = 10f; * cam.orthographic = true; * cam.backgroundColor = backgroundColor; * cam.aspect = pixelWidth / (float)pixelHeight; * * // Camera Size = x / ((( x / y ) * 2 ) * s ) * cam.orthographicSize = pixelWidth / (((pixelWidth / (float)pixelHeight) * 2f) * pixelHeight); * cam.pixelRect = new Rect (0f, 0f, pixelWidth, pixelHeight); * * return cam; * } * * private static Light CreateLight () * { * var light = new GameObject ("PartIconGenerator.Light").AddComponent<Light> (); * * light.type = LightType.Directional; * light.color = XKCDColors.OffWhite; * light.cullingMask = 1 << GameObjectLayer; * light.intensity = 0.1f; * * return light; * } * * private static GameObject CreateIcon (AvailablePart part) * { * // kerbalEVA doesn't seem to init at origin if we aren't explicit * var go = UnityEngine.Object.Instantiate (part.iconPrefab, Vector3.zero, Quaternion.identity) as GameObject; * * // The kerbals are initially facing along positive Z so we'll be looking at their backs if we don't * // rotate them around * if (part.name.StartsWith (KerbalEvaSubstring)) * go.transform.rotation = Quaternion.AngleAxis (180f, Vector3.up); * * go.SetLayerRecursive (GameObjectLayer); * go.SetActive (true); * return go; * } * * private static void AdjustScaleAndCameraPosition (GameObject icon, Camera camera) * { * // get size of prefab * var bounds = CalculateBounds (icon); * float sphereDiameter = Mathf.Max (bounds.size.x, bounds.size.y, bounds.size.z); * * // rescale to size 1 unit so that object will take up as much viewspace as possible in ortho cam (with ortho size = 0.5) * var currentScale = icon.transform.localScale; * float scaleFactor = 1f / sphereDiameter; * icon.transform.localScale = currentScale * scaleFactor; * * icon.transform.position = -bounds.center * scaleFactor; * * camera.transform.position = Vector3.zero; * * // back out, else we'll be inside the model (which is scaled at 1 unit so this should be plenty) * camera.transform.Translate (new Vector3 (0f, 0f, -5f), Space.Self); * camera.transform.LookAt (Vector3.zero, Vector3.up); * } * * * public static Texture2D Create2D (AvailablePart part, int width, int height, Quaternion orientation, Color backgroundColor) * { * var cam = CreateCamera (width, height, backgroundColor); * var icon = CreateIcon (part); * var light = CreateLight (); * * var texture = new Texture2D (width, height, TextureFormat.ARGB32, false); * var rt = RenderTexture.GetTemporary (width, height, 24); * var prevRt = RenderTexture.active; * * RenderTexture.active = rt; * * icon.transform.rotation = orientation * icon.transform.rotation; * * AdjustScaleAndCameraPosition (icon, cam); * * cam.targetTexture = rt; * cam.pixelRect = new Rect (0f, 0f, width, height); // doc says this should be ignored but doesn't seem to be (?) -- rendered area very small once targetTexture is set * cam.Render (); * * texture.ReadPixels (new Rect (0f, 0f, width, height), 0, 0, false); * texture.Apply (); * * RenderTexture.active = prevRt; * RenderTexture.ReleaseTemporary (rt); * UnityEngine.Object.DestroyImmediate (light); * UnityEngine.Object.DestroyImmediate (cam); * UnityEngine.Object.DestroyImmediate (icon); * * return texture; * } * * private static Bounds CalculateBounds (GameObject go) * { * var renderers = go.GetComponentsInChildren<Renderer> (true).ToList (); * * if (renderers.Count == 0) * return default(Bounds); * * var boundsList = new List<Bounds> (); * * renderers.ForEach (r => { * if (r.tag == IconHiddenTag) * return; * * if (r is SkinnedMeshRenderer) { * var smr = r as SkinnedMeshRenderer; * * // the localBounds of the SkinnedMeshRenderer are initially large enough * // to accomodate all animation frames; they're likely to be far off for * // parts that do a lot of animation-related movement (like solar panels expanding) * // * // We can get correct mesh bounds by baking the current animation into a mesh * // note: vertex positions in baked mesh are relative to smr.transform; any scaling * // is already baked in * var mesh = new Mesh (); * smr.BakeMesh (mesh); * * // while the mesh bounds will now be correct, they don't consider orientation at all. * // If a long part is oriented along the wrong axis in world space, the bounds we'd get * // here could be very wrong. We need to come up with essentially the renderer bounds: * // a bounding box in world space that encompasses the mesh * var m = Matrix4x4.TRS (smr.transform.position, smr.transform.rotation, Vector3.one * // remember scale already factored in! * ); * var vertices = mesh.vertices; * * var smrBounds = new Bounds (m.MultiplyPoint3x4 (vertices [0]), Vector3.zero); * * for (int i = 1; i < vertices.Length; ++i) * smrBounds.Encapsulate (m.MultiplyPoint3x4 (vertices [i])); * * UnityEngine.Object.Destroy (mesh); * * boundsList.Add (smrBounds); * } else if (r is MeshRenderer) { // note: there are ParticleRenderers, LineRenderers, and TrailRenderers * r.gameObject.GetComponent<MeshFilter> ().sharedMesh.RecalculateBounds (); * boundsList.Add (r.bounds); * } * }); * * Bounds bounds = boundsList [0]; * * boundsList.Skip (1).ToList ().ForEach (b => bounds.Encapsulate (b)); * * return bounds; * } * }*/ private void OnGUI() { if (tooltipstyle == null) { setStyles(); } if (osdtime > Time.time) { float osdheight = osdstyle.CalcSize(new GUIContent(osdmessage)).y; GUILayout.BeginArea(new Rect(0, Screen.height * 0.1f, Screen.width, osdheight), osdstyle); GUILayout.Label(osdmessage, osdstyle); GUILayout.EndArea(); } if (visible) { if (refreshwait > 0) { refreshwait = refreshwait - 1; } else { switch (mystate) { case ASPState.IDLE: EditorLogic editor = EditorLogic.fetch; ShipConstruct ship = editor.ship; if (ship != null) { List <Part> parts = ship.parts; if ((parts != null) && (parts.Count > 0) && (parts [0] != null)) { parts [0].SetHighlight(false, true); if (tanks == null) { tanks = ASPStaging.findFuelTanks(parts); } else { if (vizualize) { if ((badDestTank != null) && (badStartTank != null)) { drawLineBetweenBadParts(); } foreach (Part p in parts) { if (p != null) { if ((badStartTank != null) && (p == badStartTank)) { Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position); GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "Start tank"); badStartTank.SetHighlightColor(Color.blue); badStartTank.SetHighlight(true, false); badStartTank.highlightType = Part.HighlightType.AlwaysOn; } else if ((badDestTank != null) && (p == badDestTank)) { Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position); GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "Destination tank"); badDestTank.SetHighlightColor(Color.blue); badDestTank.SetHighlight(true, false); badDestTank.highlightType = Part.HighlightType.AlwaysOn; } else if (blockingTanks.Contains(p)) { Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position); GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "X"); p.SetHighlightColor(Color.red); p.SetHighlight(true, false); p.highlightType = Part.HighlightType.AlwaysOn; } else if (tanks.Contains(p)) { // draw labels on the tanks Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position); string label = "L" + ASPFuelLine.countDecouplersToRoot(p).ToString(); #if DEBUG //label = label+": "+ASPConsoleStuff.getFriendlyName (p.craftID.ToString ()); #endif GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), label); if ((p != badStartTank) && (p != badDestTank) && (!blockingTanks.Contains(p))) { p.SetHighlightColor(Color.green); p.SetHighlight(true, false); p.highlightType = Part.HighlightType.AlwaysOn; } } else if (ASPStaging.isDecoupler(p)) { p.SetHighlightColor(Color.magenta); p.SetHighlight(true, false); p.highlightType = Part.HighlightType.AlwaysOn; } else { p.SetHighlight(false, false); } } } } } } windowRect = ClickThruBlocker.GUILayoutWindow(windowID, clampToScreen(windowRect), OnWindow, "AutoAsparagus " + versionString); mousepos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if ((tooltip != null) && (tooltip.Length > 0)) { GUI.depth = 0; Vector2 size = tooltipstyle.CalcSize(new GUIContent(tooltip)); Rect rect = new Rect(Input.mousePosition.x + 20, (Screen.height - Input.mousePosition.y) + 20, size.x, size.y); rect = clampToScreen(rect); GUILayout.BeginArea(rect); GUILayout.Label(tooltip, tooltipstyle); GUILayout.EndArea(); } } break; case ASPState.ERROR: vizualize = true; mystate = ASPState.IDLE; break; case ASPState.ADDASP: ASPConsoleStuff.ListTheShip(); mystate = ASPState.CONNECT; ASPFuelLine.AddAsparagusFuelLines(partsWeCanUse [partToUseIndex], textureIndex, partTexturePaths [partToUseIndex], partTextureNames [partToUseIndex], rainbow); if (mystate == ASPState.CONNECT) { osd("Connecting parts..."); } refreshwait = 100; break; case ASPState.ADDONION: ASPConsoleStuff.ListTheShip(); mystate = ASPState.CONNECT; ASPFuelLine.AddOnionFuelLines(partsWeCanUse [partToUseIndex], textureIndex, partTexturePaths [partToUseIndex], partTextureNames [partToUseIndex], rainbow); if (mystate == ASPState.CONNECT) { osd("Connecting parts..."); } refreshwait = 100; break; case ASPState.CONNECT: ASPFuelLine.connectFuelLines(); refreshwait = 100; osd("Refreshing ship..."); mystate = ASPState.AFTERCONNECT; break; case ASPState.AFTERCONNECT: newReloadShip(); refreshwait = 100; if (useSmartStage) { mystate = ASPState.SMARTSTAGE; osd("Calling SmartStage..."); ASPConsoleStuff.AAprint("Calling SmartStage"); } else { mystate = ASPState.ADDSTAGES; osd("Adding empty stages..."); } break; case ASPState.ADDSTAGES: ASPStaging.AddEmptyStages(); mystate = ASPState.STAGE; osd("Staging decouplers..."); refreshwait = 10; break; case ASPState.STAGE: ASPStaging.AsaparagusTheShip(partsWeCanUse [partToUseIndex].name); mystate = ASPState.AFTERSTAGE; osd("Decoupler staging done, refreshing..."); refreshwait = 10; break; case ASPState.CLAMPS: if (stageLaunchClamps) { ASPStaging.StageLaunchClamps(launchClampsStage); } mystate = ASPState.FINALREFRESH; osd("Done!"); refreshwait = 10; break; case ASPState.DELETEFUEL: ASPConsoleStuff.ListTheShip(); int count = ASPFuelLine.DeleteAllFuelLines(partsWeCanUse [partToUseIndex].name); newReloadShip(); osd(count.ToString() + " parts deleted."); mystate = ASPState.IDLE; break; case ASPState.FINALREFRESH: newReloadShip(); mystate = ASPState.IDLE; osd("Done!"); #if DEBUG tanks = ASPStaging.findFuelTanks(EditorLogic.fetch.ship.Parts); #endif break; case ASPState.AFTERSTAGE: newReloadShip(); if (stageLaunchClamps) { osd("Staging launch clamps..."); mystate = ASPState.CLAMPS; refreshwait = 10; } else { osd("Done!"); mystate = ASPState.IDLE; } break; case ASPState.SMARTSTAGE: mystate = ASPState.FINALREFRESH; try { computeStagesMethod.Invoke(null, new object[] { }); } catch (Exception e) { UnityEngine.Debug.LogError("Error invoking method\n" + e.StackTrace); } osd("Done!"); break; } } } }
public void appOnTrue() { if (researchedFuelLines()) { visible = true; // find available fuel line parts partsWeCanUse = new List <AvailablePart> (); foreach (AvailablePart ap in PartLoader.LoadedPartsList) { Part p = ap.partPrefab; if (p is CompoundPart) { if (partResearched(ap)) { partsWeCanUse.Add(ap); } } } partGrid = new GUIContent[partsWeCanUse.Count()]; partTexturePaths = new string[partsWeCanUse.Count()][]; partTextureNames = new string[partsWeCanUse.Count()][]; partTextures = new Texture2D[partsWeCanUse.Count()][]; int x = 0; foreach (AvailablePart ap in partsWeCanUse) { // Thanks to xEvilReeperx for the icon code! // http://forum.kerbalspaceprogram.com/index.php?/topic/7542-the-official-unoffical-quothelp-a-fellow-plugin-developerquot-thread/&do=findComment&comment=2355711 //Texture2D xEvilReeperxRules = PartIconGenerator.Create2D (ap, 32, 32, // Quaternion.AngleAxis (-15f, Vector3.right) * Quaternion.AngleAxis (-30f, Vector3.up), Color.clear); //partGrid [x] = new GUIContent (" " + ap.title, xEvilReeperxRules, ap.title + " (" + ap.name + ")"); partGrid [x] = new GUIContent(" " + ap.title, ap.title + " (" + ap.name + ")"); ASPConsoleStuff.AAprint("partGrid[" + x.ToString() + "]: " + ap.title); Part p = ap.partPrefab; partTexturePaths [x] = null; foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FStextureSwitch2") { ASPConsoleStuff.AAprint("FStextureSwitch2 detected!"); char[] sep = new char[1]; sep [0] = ';'; string textures = pm.GetType().GetField("textureNames").GetValue(pm).ToString(); ASPConsoleStuff.AAprint("Textures (path): " + textures); partTexturePaths [x] = textures.Split(sep, StringSplitOptions.RemoveEmptyEntries); int numTextures = partTexturePaths [x].Count(); partTextures [x] = new Texture2D[numTextures]; for (int i = 0; i < numTextures; i++) { ASPConsoleStuff.AAprint("Texture path: [" + partTexturePaths [x] [i] + "]"); partTextures [x] [i] = loadTexture(partTexturePaths [x] [i]); if ((partTextures [x] [i].height > 20) || (partTextures [x] [i].width > 20)) { int newWidth = partTextures [x] [i].width; int newHeight = partTextures [x] [i].height; if (partTextures [x] [i].height > partTextures [x] [i].width) { newHeight = 20; newWidth = partTextures [x] [i].width * (partTextures [x] [i].height / 20); } else { newHeight = partTextures [x] [i].height * (partTextures [x] [i].width / 20); newWidth = 20; } } } string textureDisplayNames = pm.GetType().GetField("textureDisplayNames").GetValue(pm).ToString(); ASPConsoleStuff.AAprint("Textures (display name): " + textureDisplayNames); partTextureNames [x] = textureDisplayNames.Split(sep, StringSplitOptions.RemoveEmptyEntries); } } x = x + 1; } } else { osd("Fuel lines have not been researched yet!"); visible = false; } tanks = null; }
static public void AsaparagusTheShip(string partName) { var editor = EditorLogic.fetch; // Get all the parts of the ship var parts = editor.ship.parts; ASPConsoleStuff.printPartList("All parts of ship", "Part", parts); // Find the symmetrical fuel tanks List <Part> tanks = findFuelTanks(parts); ASPConsoleStuff.AAprint("=== Tanks ==="); // print out a list of tanks, partners, and children foreach (Part p in tanks) { ASPConsoleStuff.printPart("Tank", p); foreach (Part partner in p.symmetryCounterparts) { ASPConsoleStuff.printPart("partner", partner); } foreach (Part child in p.children) { ASPConsoleStuff.printPart("child", child); } } // Make chains by following fuel lines List <Part> tanksToStage = new List <Part>(); foreach (Part p in tanks) { if (ASPFuelLine.countDecouplersToRoot(p) > 0) { tanksToStage.Add(p); } } int safetyfactor = 10000; while (tanksToStage.Count > 0) { safetyfactor = safetyfactor - 1; if (safetyfactor == 0) { AutoAsparagus.osd("Infinite loop in AsaparagusTheShip:tanksToStage.Count, aborting :("); AutoAsparagus.mystate = AutoAsparagus.ASPState.IDLE; return; } // start a new chain with the first tank Part p = tanksToStage [0]; List <Part> chain = new List <Part> (); ASPConsoleStuff.printPart("*** Starting new chain with", p); // First, follow the fuel lines while (p != null) { safetyfactor = safetyfactor - 1; if (safetyfactor == 0) { AutoAsparagus.osd("Infinite loop in AsaparagusTheShip:tanksToStage.Count:p!=null, aborting :("); AutoAsparagus.mystate = AutoAsparagus.ASPState.IDLE; return; } ASPConsoleStuff.printPart("Adding to chain at position " + chain.Count, p); chain.Add(p); // don't try to put that tank in another chain tanksToStage.Remove(p); ASPConsoleStuff.printPart("Following fuel line from", p); Part r = p; p = null; foreach (Part target in ASPFuelLine.getFuelLineTargets(r, partName)) { if (tanks.Contains(target)) // we're only following fuel lines in the asparagus { ASPConsoleStuff.printPart("..followed fuel line to", target); p = target; } } } // Next, look for fuel lines that lead to the start of our chain int x = tanksToStage.Count; while (x > 0) { p = tanksToStage [x - 1]; // get last tank ASPConsoleStuff.printPart("Checking tank " + x.ToString() + " of " + tanksToStage.Count + " to insert in chain", p); x = x - 1; foreach (Part target in ASPFuelLine.getFuelLineTargets(p, partName)) { if (chain [0] == target) { ASPConsoleStuff.printPart("..prepending to chain", target); chain.Insert(0, p); tanksToStage.Remove(p); x = tanksToStage.Count; // reset the countdown } } } ASPConsoleStuff.printPartList("*** Completed chain", "chain part", chain); stageChain(chain); } // Update staging display //StageManager.Instance.DeleteEmptyStages (); //StageManager.GenerateStagingSequence (parts [0]); //StageManager.Instance.SortIcons (true); //StageManager.Instance.UpdateStageGroups (false); //foreach (KSP.UI.Screens.StageGroup s in StageManager.Instance.Stages) { //} }
static public void AddEmptyStages() { ASPConsoleStuff.print("AddEmptyStages()"); var editor = EditorLogic.fetch; // Get all the parts of the ship var parts = editor.ship.parts; List <Part> decouplers = new List <Part> (); foreach (Part p in parts) { if (isDecoupler(p)) { if (p.symmetryCounterparts.Count > 0) { decouplers.Add(p); } } } ASPConsoleStuff.printPartList("AddEmptyStages decouplers", "decoupler", decouplers); List <Part> decouplers2 = decouplers; List <int> usedstages = new List <int> (); int safetyfactor = 10000; while (decouplers.Count > 0) { safetyfactor = safetyfactor - 1; if (safetyfactor == 0) { AutoAsparagus.osd("Infinite loop in AddEmptyStages, aborting :("); AutoAsparagus.mystate = AutoAsparagus.ASPState.IDLE; return; } Part p = decouplers [0]; ASPConsoleStuff.printPart("Checking for empty stage", p); if (usedstages.Contains(p.inverseStage)) { ASPConsoleStuff.printPart("Adding stage at " + (p.inverseStage + 1).ToString() + " for decoupler", p); StageManager.Instance.AddStageAt(p.inverseStage + 1); setPartStage(p, p.inverseStage + 1); } int x = p.symmetryCounterparts.Count / 2; while (x > 0) { ASPConsoleStuff.print("AddEmptyStages: x=" + x.ToString()); x = x - 1; usedstages.Add(p.inverseStage); } decouplers.Remove(p); foreach (Part brother in p.symmetryCounterparts) { setPartStage(brother, p.inverseStage); decouplers.Remove(brother); } } foreach (Part p in decouplers2) { ASPConsoleStuff.printPart("Adding stage at " + (p.inverseStage + 1).ToString() + " for decoupler2", p); StageManager.Instance.AddStageAt(p.inverseStage + 1); } }
static private void setPartStage(Part p, int stage) { ASPConsoleStuff.printPart("Setting to stage " + stage.ToString(), p); p.inverseStage = stage; }
// called every screen refresh private void OnWindow(int windowID) { GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Asparagus", aspTexture, "Create fuel lines and stage the ship, asparagus-style"), picbutton)) { mystate = ASPState.ADDASP; osd("Adding parts in asparagus style..."); } if (GUILayout.Button(new GUIContent("Onion", onionTexture, "Create fuel lines and stage the ship, onion-style"), picbutton)) { mystate = ASPState.ADDONION; osd("Adding parts in onion style..."); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Delete all " + partsWeCanUse [partToUseIndex].title, nofuelTexture, "Delete all " + partsWeCanUse [partToUseIndex].title + " parts on the ship"), picbutton)) { osd("Deleting parts..."); mystate = ASPState.DELETEFUEL; } GUILayout.EndHorizontal(); if (partsWeCanUse.Count() > 1) { // choose part to use for fuel lines GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Part to use:", labelstyle); GUILayout.EndVertical(); GUILayout.BeginVertical(); int oldPartToUseIndex = partToUseIndex; partToUseIndex = GUILayout.SelectionGrid(partToUseIndex, partGrid, 1, togglestyle); if (oldPartToUseIndex != partToUseIndex) { // shrink window windowRect.height = 0; windowRect.width = 0; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (partTextureNames [partToUseIndex] != null) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Texture:", labelstyle); GUILayout.EndVertical(); GUILayout.BeginVertical(); int numTextures = partTextureNames [partToUseIndex].Count(); GUIContent[] texSelect = new GUIContent[numTextures]; for (int i = 0; i < numTextures; i++) { texSelect [i] = new GUIContent(partTextureNames [partToUseIndex] [i], partTextures [partToUseIndex] [i]); } textureIndex = GUILayout.SelectionGrid(textureIndex, texSelect, 2, gridstyle); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Rainbow:", labelstyle); GUILayout.EndVertical(); GUILayout.BeginVertical(); rainbow = GUILayout.Toggle(rainbow, new GUIContent("Rainbow", rainbowTexture, "Oh, rainBOWs. Yeah I like those!")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Label("Options:"); GUILayout.EndHorizontal(); if (SmartStageAvailable) { GUILayout.BeginHorizontal(); useSmartStage = GUILayout.Toggle(useSmartStage, new GUIContent(" Use SmartStage", smartstageTexture, "Stage the ship using SmartStage instead of AutoAsparagus"), togglestyle); GUILayout.EndHorizontal(); } if (!useSmartStage) { GUILayout.BeginHorizontal(); stageParachutes = GUILayout.Toggle(stageParachutes, new GUIContent(" Stage parachutes", parachuteTexture, "Stage parachutes to fire with decouplers"), togglestyle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); stagesepratrons = GUILayout.Toggle(stagesepratrons, new GUIContent(" Stage sepratrons", sepratronTexture, "Stage sepratrons to fire with decouplers"), togglestyle); GUILayout.EndHorizontal(); if (!stageLaunchClamps) { minheight = windowRect.height; minwidth = windowRect.width; } bool oldclamps = stageLaunchClamps; GUILayout.BeginHorizontal(); stageLaunchClamps = GUILayout.Toggle(stageLaunchClamps, new GUIContent(" Stage launch clamps", launchclampTexture, "Move launch clamps to the bottom or next-to-bottom stage"), togglestyle); GUILayout.EndHorizontal(); if (stageLaunchClamps != oldclamps) { if (!stageLaunchClamps) { // shrink window to old dimesions windowRect.height = minheight; windowRect.width = minwidth; } } if (stageLaunchClamps) { GUILayout.BeginHorizontal(); //GUILayout.Label ("Launch clamps:"); launchClampsStage = GUILayout.SelectionGrid(launchClampsStage, launchClampsText, 1, togglestyle); GUILayout.EndHorizontal(); } } GUILayout.BeginHorizontal(); vizualize = GUILayout.Toggle(vizualize, new GUIContent(" Show visualizations", "Show visualizations such as highlights and levels"), togglestyle); GUILayout.EndHorizontal(); #if DEBUG GUILayout.BeginHorizontal(); if (GUILayout.Button("DEV - Reload ship", buttonStyle)) { newReloadShip(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("DEV - Dump the ship", buttonStyle)) { ASPConsoleStuff.ListTheShip(); tanks = ASPStaging.findFuelTanks(EditorLogic.fetch.ship.Parts); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("DEV - flush output buffer", buttonStyle)) { // flush output buffer for (int i = 1; i <= 20; i++) { print(""); } } GUILayout.EndHorizontal(); #endif GUI.DragWindow(); if (Event.current.type == EventType.Repaint) // why, Unity, why? { tooltip = GUI.tooltip; } }
private static Texture2D loadTexture(string path) { ASPConsoleStuff.AAprint("loading texture: " + path); return(GameDatabase.Instance.GetTexture(path, false)); }