public KCT_BuildListVessel NewCopy(bool RecalcTime) { KCT_BuildListVessel ret = new KCT_BuildListVessel(this.shipName, this.launchSite, this.effectiveCost, this.buildPoints, this.integrationPoints, this.flag, this.cost, this.integrationCost, (int)GetEditorFacility()); ret.shipNode = this.shipNode.CreateCopy(); //refresh all inventory parts to new for (int i = ret.ExtractedPartNodes.Count - 1; i >= 0; i--) { ConfigNode part = ret.ExtractedPartNodes[i]; //foreach (ConfigNode part in ret.ExtractedPartNodes) //{ ScrapYardWrapper.RefreshPart(part); } ret.id = Guid.NewGuid(); ret.TotalMass = this.TotalMass; ret.emptyMass = this.emptyMass; ret.cost = this.cost; ret.integrationCost = this.integrationCost; ret.emptyCost = this.emptyCost; ret.numStageParts = this.numStageParts; ret.numStages = this.numStages; ret.stagePartCost = this.stagePartCost; if (RecalcTime) { ret.effectiveCost = KCT_Utilities.GetEffectiveCost(ret.ExtractedPartNodes); ret.buildPoints = KCT_Utilities.GetBuildTime(ret.effectiveCost); ret.integrationPoints = KCT_MathParsing.ParseIntegrationTimeFormula(ret); ret.integrationCost = (float)KCT_MathParsing.ParseIntegrationCostFormula(ret); } return(ret); }
public void vesselRecoverEvent(ProtoVessel v, bool unknownAsOfNow) { KCTDebug.Log("VesselRecoverEvent"); if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled) { return; } if (!v.vesselRef.isEVA) { // if (KCT_GameStates.settings.Debug && HighLogic.LoadedScene != GameScenes.TRACKSTATION && (v.wasControllable || v.protoPartSnapshots.Find(p => p.modules.Find(m => m.moduleName.ToLower() == "modulecommand") != null) != null)) if (KCT_GameStates.recoveredVessel != null && v.vesselName == KCT_GameStates.recoveredVessel.shipName) { //KCT_GameStates.recoveredVessel = new KCT_BuildListVessel(v); //rebuy the ship if ScrapYard isn't overriding funds if (!ScrapYardWrapper.OverrideFunds) { KCT_Utilities.SpendFunds(KCT_GameStates.recoveredVessel.cost, TransactionReasons.VesselRollout); //pay for the ship again } //pull all of the parts out of the inventory //This is a bit funky since we grab the part id from our part, grab the inventory part out, then try to reapply that ontop of our part if (ScrapYardWrapper.Available) { foreach (ConfigNode partNode in KCT_GameStates.recoveredVessel.ExtractedPartNodes) { string id = ScrapYardWrapper.GetPartID(partNode); ConfigNode inventoryVersion = ScrapYardWrapper.FindInventoryPart(id); if (inventoryVersion != null) { //apply it to our copy of the part ConfigNode ourTracker = partNode.GetNodes("MODULE").FirstOrDefault(n => string.Equals(n.GetValue("name"), "ModuleSYPartTracker", StringComparison.Ordinal)); if (ourTracker != null) { ourTracker.SetValue("TimesRecovered", inventoryVersion.GetValue("_timesRecovered")); ourTracker.SetValue("Inventoried", inventoryVersion.GetValue("_inventoried")); } } } //process the vessel in ScrapYard ScrapYardWrapper.ProcessVessel(KCT_GameStates.recoveredVessel.ExtractedPartNodes); //reset the BP KCT_GameStates.recoveredVessel.buildPoints = KCT_Utilities.GetBuildTime(KCT_GameStates.recoveredVessel.ExtractedPartNodes); KCT_GameStates.recoveredVessel.integrationPoints = KCT_MathParsing.ParseIntegrationTimeFormula(KCT_GameStates.recoveredVessel); } if (KCT_GameStates.recoveredVessel.type == KCT_BuildListVessel.ListType.VAB) { KCT_GameStates.ActiveKSC.VABWarehouse.Add(KCT_GameStates.recoveredVessel); } else { KCT_GameStates.ActiveKSC.SPHWarehouse.Add(KCT_GameStates.recoveredVessel); } KCT_GameStates.ActiveKSC.Recon_Rollout.Add(new KCT_Recon_Rollout(KCT_GameStates.recoveredVessel, KCT_Recon_Rollout.RolloutReconType.Recovery, KCT_GameStates.recoveredVessel.id.ToString())); KCT_GameStates.recoveredVessel = null; } } }
public KCT_BuildListVessel(Vessel vessel, KCT_BuildListVessel.ListType listType = ListType.None) //For recovered vessels { id = Guid.NewGuid(); shipName = vessel.vesselName; shipNode = FromInFlightVessel(vessel, listType); if (listType != ListType.None) { this.type = listType; } cost = KCT_Utilities.GetTotalVesselCost(shipNode); emptyCost = KCT_Utilities.GetTotalVesselCost(shipNode, false); TotalMass = 0; emptyMass = 0; HashSet <int> stages = new HashSet <int>(); //for (int i = vessel.protoVessel.protoPartSnapshots.Count - 1; i >= 0; i--) //{ // ProtoPartSnapshot p = vessel.protoVessel.protoPartSnapshots[i]; foreach (ProtoPartSnapshot p in vessel.protoVessel.protoPartSnapshots) { stages.Add(p.inverseStageIndex); if (p.partPrefab != null && p.partPrefab.Modules.Contains <LaunchClamp>()) { continue; } TotalMass += p.mass; emptyMass += p.mass; //for (int i1 = p.resources.Count - 1; i1 >= 0; i1--) //{ // ProtoPartResourceSnapshot rsc = p.resources[i1]; foreach (ProtoPartResourceSnapshot rsc in p.resources) { PartResourceDefinition def = PartResourceLibrary.Instance.GetDefinition(rsc.resourceName); if (def != null) { TotalMass += def.density * (float)rsc.amount; } } } cannotEarnScience = true; numStages = stages.Count; // FIXME ignore stageable part count and cost - it'll be fixed when we put this back in the editor. effectiveCost = KCT_Utilities.GetEffectiveCost(shipNode.GetNodes("PART").ToList()); buildPoints = KCT_Utilities.GetBuildTime(effectiveCost); flag = HighLogic.CurrentGame.flagURL; DistanceFromKSC = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude)); rushBuildClicks = 0; integrationPoints = KCT_MathParsing.ParseIntegrationTimeFormula(this); integrationCost = (float)KCT_MathParsing.ParseIntegrationCostFormula(this); progress = buildPoints + integrationPoints; }
public KCT_BuildListVessel(ShipConstruct s, String ls, double effCost, double bP, String flagURL) { ship = s; shipNode = s.SaveShip(); shipName = s.shipName; //Get total ship cost float fuel; cost = s.GetShipCosts(out emptyCost, out fuel); TotalMass = s.GetShipMass(true, out emptyMass, out fuel); HashSet <int> stages = new HashSet <int>(); numStageParts = 0; stagePartCost = 0d; //for (int i = s.Parts.Count - 1; i >= 0; i--) //{ // Part p = s.Parts[i]; foreach (Part p in s.Parts) { if (p.stagingOn) { stages.Add(p.inverseStage); ++numStageParts; stagePartCost += p.GetModuleCosts(p.partInfo.cost, ModifierStagingSituation.CURRENT) + p.partInfo.cost; } } numStages = stages.Count; launchSite = ls; effectiveCost = effCost; buildPoints = bP; progress = 0; flag = flagURL; if (s.shipFacility == EditorFacility.VAB) { type = ListType.VAB; } else if (s.shipFacility == EditorFacility.SPH) { type = ListType.SPH; } else { type = ListType.None; } id = Guid.NewGuid(); cannotEarnScience = false; //get the crew from the editorlogic DesiredManifest = new List <string>(); if (CrewAssignmentDialog.Instance?.GetManifest()?.CrewCount > 0) { //var pcm = CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List<ProtoCrewMember>(); //for (int i = pcm.Count - 1; i >= 0; i--) //{ // ProtoCrewMember crew = pcm[i]; foreach (ProtoCrewMember crew in CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List <ProtoCrewMember>()) { DesiredManifest.Add(crew?.name ?? string.Empty); } } if (effectiveCost == default(double)) { // Can only happen in older saves that didn't have Effective cost persisted as a separate field // This code should be safe to remove after a while. effectiveCost = KCT_Utilities.GetEffectiveCost(shipNode.GetNodes("PART").ToList()); } integrationPoints = KCT_MathParsing.ParseIntegrationTimeFormula(this); integrationCost = (float)KCT_MathParsing.ParseIntegrationCostFormula(this); }