public CostReport getBuildCost(ConfigNode craft, string craftText = null) { lockedParts = false; ShipConstruct ship = new ShipConstruct(); if (!ship.LoadShip(craft)) { lockedParts = true; return(null); } if (ship.vesselDeltaV != null) { // The delta-v module is not needed. It has its own gameObject // for ShipConstruct. UnityEngine.Object.Destroy(ship.vesselDeltaV.gameObject); ship.vesselDeltaV = null; } if (!ship.shipPartsUnlocked) { lockedParts = true; } GameObject ro = ship.parts[0].localRoot.gameObject; Vessel craftVessel = ro.AddComponent <Vessel>(); craftVessel.vesselName = "EL craftVessel - " + craft.GetValue("ship"); craftVessel.Initialize(true); SetCraftOrbit(craftVessel, OrbitDriver.UpdateMode.IDLE); foreach (Part part in craftVessel.parts) { SanitizePart(part); part.ModulesOnStart(); } if (ELSettings.B9Wings_Present) { if (!InitializeB9Wings(craftVessel) && ELSettings.FAR_Present) { InitializeFARSurfaces(craftVessel); } } else if (ELSettings.FAR_Present) { InitializeFARSurfaces(craftVessel); } BuildCost resources = new BuildCost(); foreach (Part p in craftVessel.parts) { resources.addPart(p); } if (craftText != null && ELSettings.ShowCraftHull) { Quickhull.dump_points = ELSettings.DebugCraftHull; Quickhull.points_path = savesPath; DestroyCraftHull(); craftHull = new CraftHull(craftText); // GetVesselBox will rotate and minimize any launchclamps, // which is probably a good thing. var rootPart = ship.parts[0].localRoot; var rootPos = rootPart.transform.position; craftHull.SetBox(GetVesselBox(ship), rootPos); builder.SetShipTransform(rootPart.transform, rootPart); craftHull.SetTransform(rootPart.transform); if (ELSettings.DebugCraftHull || !craftHull.LoadHull(savesPath)) { craftHull.BuildConvexHull(craftVessel); craftHull.SaveHull(savesPath); } } craftVessel.Die(); return(resources.cost); }
public void Load(ConfigNode node) { if (node.HasValue("filename")) { filename = node.GetValue("filename"); } if (node.HasValue("flagname")) { flagname = node.GetValue("flagname"); } if (node.HasNode("CraftConfig")) { craftConfig = node.GetNode("CraftConfig"); } if (node.HasNode("CraftHull")) { craftHull = new CraftHull(); craftHull.Load(node.GetNode("CraftHull")); } if (node.HasNode("BuildCost")) { var bc = node.GetNode("BuildCost"); buildCost = new CostReport(); buildCost.Load(bc); } if (node.HasNode("BuiltStuff")) { var bs = node.GetNode("BuiltStuff"); builtStuff = new CostReport(); builtStuff.Load(bs); } if (node.HasValue("state")) { var s = node.GetValue("state"); state = (State)Enum.Parse(typeof(State), s); if (state == State.Dewarping) { // The game got saved while the Dewarping state was still // active. Rather than restarting the dewarp coroutine, // Just jump straight to the Complete state. state = State.Complete; } } if (node.HasValue("paused")) { var s = node.GetValue("paused"); bool p = false; bool.TryParse(s, out p); paused = p; } if (node.HasValue("KACalarmID")) { KACalarmID = node.GetValue("KACalarmID"); } if (node.HasNode("DockedVesselInfo")) { ConfigNode vi = node.GetNode("DockedVesselInfo"); vesselInfo = new DockedVesselInfo(); vesselInfo.Load(vi); } }