public void FilterRDNode(RDTech tech) { foreach (var filter in filters) { PruneRDNode(tech, filter.Value); } }
public void SendTechnologyMessage(RDTech tech) { var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <ShareProgressTechnologyMsgData>(); msgData.TechNode.Id = tech.techID; var configNode = ConvertTechNodeToConfigNode(tech); if (configNode == null) { return; } var data = configNode.Serialize(); var numBytes = data.Length; msgData.TechNode.NumBytes = numBytes; if (msgData.TechNode.Data.Length < numBytes) { msgData.TechNode.Data = new byte[numBytes]; } Array.Copy(data, msgData.TechNode.Data, numBytes); SendMessage(msgData); }
public void Update() { // Hides unwanted parts from the RnD techtree RDTech tech = GetComponent <RDTech>(); RDTechFilters.Instance.FilterRDNode(tech); Destroy(this); }
private void wip(Func <string, EventVoid> doWithApart) { foreach (AvailablePart aPart in PartLoader.Instance.parts) { if (aPart.partPrefab != null && aPart.partPrefab.Modules != null) { foreach (PartModule pm in aPart.partPrefab.Modules) { if (pm.moduleName.Equals("MerillMissionStub")) { if (((MerillMissionStub)pm).missionName.Equals(this.GetType().Name)) { if (ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired) == RDTech.State.Available) { MerillData.log(" RD purchased, is experimental? " + ResearchAndDevelopment.IsExperimentalPart( PartLoader.getPartInfoByName(((MerillMissionStub)pm).partUnlock))); //check if already experimental if (ResearchAndDevelopment.IsExperimentalPart(PartLoader.getPartInfoByName(((MerillMissionStub)pm).partUnlock))) { doWithApart(((MerillMissionStub)pm).partUnlock); } } else if (aPart.TechRequired != "specializedControl") { try { //try to remove the stub to a research node MerillData.log(" RD find a part with r&d node " + pm.name); RDTech tech = AssetBase.RnDTechTree.FindTech( ((MerillMissionStub)pm).techRequired); if (tech != null) { MerillData.log(" RD find good tech " + tech.name); aPart.TechRequired = "specializedControl"; tech.partsAssigned.Remove(aPart); MerillData.log(" RD find tech assigned "); if (ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired) == RDTech.State.Available) { doWithApart(((MerillMissionStub)pm).partUnlock); } } } catch (Exception e) { MerillData.log(" RD Exeption: " + e); } } } } } } } }
public TechItem(RDTech techNode) { ScienceCost = techNode.scienceCost; TechName = techNode.title; TechID = techNode.techID; Progress = 0; ProtoNode = ResearchAndDevelopment.Instance.GetTechState(TechID); KCTDebug.Log("techID = " + TechID); KCTDebug.Log("TimeLeft = " + TimeLeft); }
public void AddCoursesForTechNode(RDTech tech) { for (int i = 0; i < tech.partsAssigned.Count; i++) { AvailablePart ap = tech.partsAssigned[i]; if (ap.partPrefab.CrewCapacity > 0) { AddPartCourses(ap); } } }
public KCT_TechItem(RDTech techNode) { scienceCost = techNode.scienceCost; techName = techNode.title; techID = techNode.techID; progress = 0; protoNode = ResearchAndDevelopment.Instance.GetTechState(techID); KCTDebug.Log("techID = " + techID); KCTDebug.Log("BuildRate = " + BuildRate); KCTDebug.Log("TimeLeft = " + TimeLeft); }
public void AddCoursesForQueuedTechNode(RDTech tech) { for (int i = 0; i < tech.partsAssigned.Count; i++) { AvailablePart ap = tech.partsAssigned[i]; if (!ap.TechHidden && ap.partPrefab.CrewCapacity > 0) { // KSP thinks that the node is actually unlocked at this point. Use a flag to indicate that KCT will override it later on. AddPartCourses(ap, isKCTExperimentalNode: true); } } }
private static void PruneRDNode(RDTech tech, Func <AvailablePart, bool> filter) { int count = tech.partsAssigned.Count; while (count-- > 0) { if (!filter(tech.partsAssigned[count])) { tech.partsAssigned.RemoveAt(count); } } }
public KCT_TechItem(RDTech techNode) { scienceCost = techNode.scienceCost; techName = techNode.title; techID = techNode.techID; progress = 0; protoNode = ResearchAndDevelopment.Instance.GetTechState(techID); Debug.Log("[KCT] techID = " + techID); Debug.Log("[KCT] BuildRate = " + BuildRate); Debug.Log("[KCT] TimeLeft = " + TimeLeft); }
public KCT_TechItem(RDTech techNode) { scienceCost = techNode.scienceCost; techName = techNode.title; techID = techNode.techID; progress = 0; protoNode = ResearchAndDevelopment.Instance.GetTechState(techID); UnlockedParts = new List<string>(); foreach (AvailablePart p in techNode.partsPurchased) UnlockedParts.Add(p.name); KCTDebug.Log("techID = " + techID); //KCTDebug.Log("BuildRate = " + BuildRate); KCTDebug.Log("TimeLeft = " + TimeLeft); }
public KCT_TechItem(RDTech techNode) { scienceCost = techNode.scienceCost; techName = techNode.title; techID = techNode.techID; progress = 0; protoNode = ResearchAndDevelopment.Instance.GetTechState(techID); UnlockedParts = new List <string>(); foreach (AvailablePart p in techNode.partsPurchased) { UnlockedParts.Add(p.name); } Log.Trace("techID = " + techID); //Log.Trace("BuildRate = " + BuildRate); Log.Trace("TimeLeft = " + TimeLeft); }
public TechItem(RDTech techNode) { ScienceCost = techNode.scienceCost; TechName = techNode.title; TechID = techNode.techID; Progress = 0; ProtoNode = ResearchAndDevelopment.Instance.GetTechState(TechID); if (KerbalConstructionTime.TechNodePeriods.TryGetValue(TechID, out KCTTechNodePeriod period)) { StartYear = period.startYear; EndYear = period.endYear; } KCTDebug.Log("techID = " + TechID); KCTDebug.Log("TimeLeft = " + TimeLeft); }
internal static void Find(bool clean = false) { List <RDNode> _nodes = RDController.Instance.nodes; for (int _i = _nodes.Count - 1; _i >= 0; --_i) { RDNode _node = _nodes[_i]; RDTech _rdTech = _node.tech; if (_node.graphics != null) { UIStateButton _button = _node.graphics.button; if (!clean && _rdTech.partsAssigned.Find(aPart => QSearch.FindPart(aPart)) != null) { _button.Image.color = new Color(1f, 0f, 0f); continue; } _button.Image.color = new Color(1f, 1f, 1f); } } //QDebug.Log ("Find: " + QSearch.Text, "QRnD"); }
private static ConfigNode ConvertTechNodeToConfigNode(RDTech techNode) { var configNode = new ConfigNode(); try { configNode.AddValue("id", techNode.techID); configNode.AddValue("state", techNode.state); configNode.AddValue("cost", techNode.scienceCost); foreach (var part in techNode.partsPurchased) { configNode.AddValue("part", part.name); } } catch (Exception e) { LunaLog.LogError($"[LMP]: Error while saving tech node: {e}"); return(null); } return(configNode); }
private void OnKctTechQueued(RDTech data) { CrewHandler.Instance.AddCoursesForTechNode(data); }
private void OnKctTechQueued(RDTech data) { Debug.Log($"[LRTR] OnKctTechQueued"); CrewHandler.Instance.AddCoursesForTechNode(data); }
protected void removeExperimentalParts() { try { //remove mandatory parts removeExperimentalPart("MerillnlineCockpitLander"); foreach (AvailablePart aPart in PartLoader.Instance.parts) { if (aPart.partPrefab != null && aPart.partPrefab.Modules != null) { foreach (PartModule pm in aPart.partPrefab.Modules) { if (pm.moduleName.Equals("MerillMissionStub")) { if (((MerillMissionStub)pm).missionName.Equals(this.GetType().Name)) { MerillData.log(" RD find a part " + pm.name); MerillData.log(" RD purchased? " + ResearchAndDevelopment.PartModelPurchased(aPart)); MerillData.log(" RD available? " + ResearchAndDevelopment.PartTechAvailable(aPart)); MerillData.log(" RD mi '" + aPart.moduleInfo + "'"); MerillData.log(" RD tech required: " + aPart.TechRequired); MerillData.log(" RD tech Really required: " + ((MerillMissionStub)pm).techRequired); //research and set if (ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired) == RDTech.State.Available && aPart.TechRequired == ((MerillMissionStub)pm).techRequired) { MerillData.log(" RD purchased, is experimental? " + ResearchAndDevelopment.IsExperimentalPart( PartLoader.getPartInfoByName(((MerillMissionStub)pm).partUnlock))); //check if experimental if (ResearchAndDevelopment.IsExperimentalPart( PartLoader.getPartInfoByName(((MerillMissionStub)pm).partUnlock))) { removeExperimentalPart(((MerillMissionStub)pm).partUnlock); } //remove from tech RDTech tech = AssetBase.RnDTechTree.FindTech(aPart.TechRequired); if (tech != null) { MerillData.log(" RD find good tech " + tech.name); aPart.TechRequired = "specializedControl"; tech.partsAssigned.Remove(aPart); } } //set? ==((MerillMissionStub)pm).techRequired else if (aPart.TechRequired != "specializedControl") { try { //try to remove the stub to a research node MerillData.log(" RD find a part with r&d node " + pm.name); RDTech tech = AssetBase.RnDTechTree.FindTech(aPart.TechRequired); if (tech != null) { MerillData.log(" RD find good tech " + tech.name); aPart.TechRequired = "specializedControl"; tech.partsAssigned.Remove(aPart); MerillData.log(" RD find tech assigned "); if (ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired) == RDTech.State.Available) { removeExperimentalPart(((MerillMissionStub)pm).partUnlock); } } } catch (Exception e) { MerillData.log(" RD Exeption: " + e); } } } } } } } } catch (Exception e) { MerillData.log(" exception at contract OnAccepted:" + e); } }
// Add stub part into research node // Add exp part if in a researched node (from stub part) private void addExperimentalParts() { if (base.dateAccepted == 0) { MerillData.log("mun mission: can't add exp part: date accepted=" + dateAccepted); } try { //add mandatory parts addExperimentalPart("MerillnlineCockpitLander"); //add part from stubs foreach (AvailablePart aPart in PartLoader.Instance.parts) { if (aPart.partPrefab != null && aPart.partPrefab.Modules != null) { //MerillData.log("part " + aPart.name); foreach (PartModule pm in aPart.partPrefab.Modules) { if (pm.moduleName.Equals("MerillMissionStub")) { if (((MerillMissionStub)pm).missionName.Equals(this.GetType().Name)) { MerillData.log(" RD find a part " + pm.name); MerillData.log(" RD purchased? " + ResearchAndDevelopment.PartModelPurchased(aPart)); MerillData.log(" RD available? " + ResearchAndDevelopment.PartTechAvailable(aPart)); MerillData.log(" RD mi " + aPart.moduleInfo); MerillData.log(" RD tech required: " + aPart.TechRequired); MerillData.log(" RD tech Really required: " + ((MerillMissionStub)pm).techRequired); MerillData.log(" RD tech Really required purchased? : " + ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired)); //already set, and already researched? if (ResearchAndDevelopment.GetTechnologyState( ((MerillMissionStub)pm).techRequired) == RDTech.State.Available && aPart.TechRequired == ((MerillMissionStub)pm).techRequired) { MerillData.log(" RD find a part with r&d node " + pm.name); //check if already experimental if (!ResearchAndDevelopment.IsExperimentalPart( PartLoader.getPartInfoByName(((MerillMissionStub)pm).partUnlock))) { addExperimentalPart(((MerillMissionStub)pm).partUnlock); } } // not set else if (aPart.TechRequired == "specializedControl") { try { //try to attach the stub to a research node MerillData.log(" RD find a part without r&d node " + pm.name); RDTech tech = AssetBase.RnDTechTree.FindTech( ((MerillMissionStub)pm).techRequired); if (tech != null) { //Set it MerillData.log(" RD find good tech " + tech.name); aPart.TechRequired = ((MerillMissionStub)pm).techRequired; tech.partsAssigned.Add(aPart); MerillData.log(" RD find tech assigned "); MerillData.log(" RD good tech purchased? " + tech.state + " , " + tech.enabled + ", "); //already researched? if (ResearchAndDevelopment.GetTechnologyState(((MerillMissionStub)pm).techRequired) == RDTech.State.Available) { addExperimentalPart(((MerillMissionStub)pm).partUnlock); } } } catch (Exception e) { MerillData.log(" RD Exeption: " + e); } } } } } } } //TODO: made this auto + add stub in tree //if (ResearchAndDevelopment.PartModelPurchased(PartLoader.getPartInfoByName("MerillCheapFuelTank1-2Stub"))) // addExperimentalPart("MerillCheapFuelTank1-2"); //if (ResearchAndDevelopment.PartModelPurchased(PartLoader.getPartInfoByName("MerillCheapFuelTank3-2Stub"))) // addExperimentalPart("MerillCheapFuelTank3-2"); //if (ResearchAndDevelopment.PartModelPurchased(PartLoader.getPartInfoByName("MerillLinearRcsExperimental"))) // addExperimentalPart("MerillLinearRcsExperimental"); } catch (Exception e) { MerillData.log(" exception at contract OnAccepted:" + e); } }