public static bool PartIsRadialDecoupler(Part part, bool techRequired = true)
        {
            if (part == null || !HighLogic.CurrentGame.Parameters.CustomParams <KLFCustomParams2>().allowRadialDecouplerFailures)
            {
                return(false);
            }


            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX && !techRequired)
            {
                if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX && part.partInfo.TechRequired != null)
                {
                    ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(part.partInfo.TechRequired);

                    if (techNode != null && techNode.state == RDTech.State.Available)
                    {
                        return(false);
                    }
                }
            }

            List <ModuleAnchoredDecoupler> anchoredDecouplers = part.Modules.OfType <ModuleAnchoredDecoupler>().ToList();

            if (anchoredDecouplers.Count > 0)
            {
                Log.Info("anchoredDecoupler: " + part.partInfo.title);
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Determines if the part has enough explosive fuel to guarantee an explosion.
        /// </summary>
        /// <param name="part">The part to check.</param>
        /// <returns>True if valid, false is not.</returns>
        public static bool PartIsExplosiveFuelTank(Part part, bool techRequired = true)
        {
            if (part == null)
            {
                return(false);
            }
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX && !techRequired)
            {
                ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(part.partInfo.TechRequired);
                if (techNode != null && techNode.state == RDTech.State.Available)
                {
                    return(false);
                }
            }
            // There's gotta be a better way to do this.
            foreach (PartResource resource in part.Resources)
            {
                if (resource.maxAmount > 0 && resource.amount / resource.maxAmount > ExplosiveTankThreshold)
                {
                    switch (resource.resourceName)
                    {
                    case "LiquidFuel":
                    case "Oxidizer":
                    case "MonoPropellant":
                    case "SolidFuel":
                        return(true);

                    default:
                        break;
                    }
                }
            }
            return(false);
        }
        protected void DoUnlock(AvailablePart part)
        {
            ProtoTechNode ptn = ResearchAndDevelopment.Instance.GetTechState(part.TechRequired);

            // The tech may be null - we need to create it
            if (ptn == null)
            {
                ptn             = new ProtoTechNode();
                ptn.state       = RDTech.State.Unavailable;
                ptn.techID      = part.TechRequired;
                ptn.scienceCost = 9999; // ignored
            }

            if (unlockTech)
            {
                ptn.state = RDTech.State.Available;
            }

            if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch && !ptn.partsPurchased.Contains(part))
            {
                ptn.partsPurchased.Add(part);
            }
            else
            {
                ptn.partsPurchased = new List <AvailablePart>();
            }

            ResearchAndDevelopment.Instance.SetTechState(part.TechRequired, ptn);
        }
Exemple #4
0
 public static bool CheckTechPresence(string techName)
 {
     if (ResearchAndDevelopment.Instance != null)
     {
         ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(techName);
         if (techNode != null)
         {
             bool available = techNode.state == RDTech.State.Available;
             if (available)
             {
                 Utils.Log("Tech is available");
                 return(available);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
        private void Research()
        {
            if (m_node.state == RDTech.State.Available)
            {
                throw new KOSException("Node is already purchased");
            }

            var host = ResearchAndDevelopment.Instance;

            if (host != null)
            {
                if (!CurrencyModifierQuery.RunQuery(TransactionReasons.RnDTechResearch, 0f, -m_node.scienceCost, 0f).CanAfford(delegate(Currency c)
                {
                    throw new KOSException("Not enough science to research this node");
                }))
                {
                    throw new KOSException("Not enough funds");
                }
                float scienceCostLimit = GameVariables.Instance.GetScienceCostLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment));
                if ((float)m_node.scienceCost > scienceCostLimit)
                {
                    throw new KOSException("Node exceeds science cost limit");
                }
                host.AddScience(-m_node.scienceCost, TransactionReasons.RnDTechResearch);
            }
            ResearchAndDevelopment.Instance.UnlockProtoTechNode(m_node);
            m_node = ResearchAndDevelopment.Instance.GetTechState(m_node.techID);
        }
        public static bool PartIsStrutOrFuelLine(CompoundPart part, bool techRequired = true)
        {
            if (part == null || !HighLogic.CurrentGame.Parameters.CustomParams <KLFCustomParams2>().allowStrutFuelFailures)
            {
                return(false);
            }
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX && !techRequired)
            {
                ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(part.partInfo.TechRequired);
                if (techNode != null && techNode.state == RDTech.State.Available)
                {
                    return(false);
                }
            }

            if (part.name != "fuelLine" && part.name != "strutConnector")
            {
                return(false);
            }
            if (part.attachState == CompoundPart.AttachState.Detached || part.attachState == CompoundPart.AttachState.Attaching)
            {
                return(false);
            }
            if (part.target == part.parent)
            {
                return(false);
            }
            return(true);
        }
        protected void DoUnlock(AvailablePart part)
        {
            ProtoTechNode ptn = ResearchAndDevelopment.Instance.GetTechState(part.TechRequired);

            // The tech may be null - we need to create it
            if (ptn == null)
            {
                ptn = new ProtoTechNode();
                ptn.state = RDTech.State.Unavailable;
                ptn.techID = part.TechRequired;
                ptn.scienceCost = 9999; // ignored
            }

            if (unlockTech)
            {
                ptn.state = RDTech.State.Available;
            }

            if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch && !ptn.partsPurchased.Contains(part))
            {
                ptn.partsPurchased.Add(part);
            }
            else
            {
                ptn.partsPurchased = new List<AvailablePart>();
            }

            ResearchAndDevelopment.Instance.SetTechState(part.TechRequired, ptn);
        }
Exemple #8
0
        public override bool RequirementMet(ConfiguredContract contract)
        {
            foreach (string tech in techs)
            {
                ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(tech);
                if (techNode == null || techNode.state != RDTech.State.Available)
                {
                    return(false);
                }
            }

            foreach (string partModule in partModules)
            {
                bool hasModule = false;
                foreach (AvailablePart part in PartLoader.LoadedPartsList)
                {
                    if (part.partPrefab == null || part.partPrefab.Modules == null)
                    {
                        continue;
                    }

                    if (ResearchAndDevelopment.PartTechAvailable(part))
                    {
                        hasModule = true;
                        break;
                    }
                }

                if (!hasModule)
                {
                    return(false);
                }
            }

            foreach (string partModuleType in partModuleTypes)
            {
                bool hasType = false;
                foreach (AvailablePart part in PartLoader.LoadedPartsList)
                {
                    if (part.partPrefab == null || part.partPrefab.Modules == null)
                    {
                        continue;
                    }

                    if (part.partPrefab.HasValidContractObjective(partModuleType) && ResearchAndDevelopment.PartTechAvailable(part))
                    {
                        hasType = true;
                        break;
                    }
                }

                if (!hasType)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #9
0
        private void OnKctTechCompleted(ProtoTechNode data)
        {
            if (CareerEventScope.ShouldIgnore)
            {
                return;
            }

            AddTechEvent(data.techID);
        }
Exemple #10
0
        public override bool RequirementMet(ConfiguredContract contract)
        {
            ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(tech);

            if (techNode == null)
            {
                return(false);
            }
            return(techNode.state == RDTech.State.Available);
        }
Exemple #11
0
        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);
        }
 protected void UnlockParts()
 {
     foreach (AvailablePart part in parts)
     {
         ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(part.TechRequired);
         if (techNode == null || techNode.state != RDTech.State.Available)
         {
             ResearchAndDevelopment.AddExperimentalPart(part);
         }
     }
 }
Exemple #13
0
        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);
        }
Exemple #14
0
        public string GetBlockingTech(KCT_GameStates.KCT_TechItemIlist <KCT_TechItem> techList)
        {
            string        blockingTech = null;
            string        anyToUnlock  = KerbalConstructionTimeData.techNameToAnyToUnlock[techID];
            List <string> parentList   = KerbalConstructionTimeData.techNameToParents[techID];

            if (parentList == null)
            {
                return(null);
            }

            // if node can unlock with any parent,
            // any researched parent means it's unblocked
            if (anyToUnlock == "True")
            {
                foreach (var p in parentList)
                {
                    ProtoTechNode pn = ResearchAndDevelopment.Instance.GetTechState(p);
                    if (pn != null && pn.state == RDTech.State.Available)
                    {
                        blockingTech = null;
                        break;
                    }
                    blockingTech = KerbalConstructionTimeData.techNameToTitle[p];
                }
            }
            // otherwise, can use old method. is it efficient, tho? seems like
            // rather than checking the entire list of techs being researched,
            // one could instead check the (usually smaller) list of parents
            // to see if any is unavailable ~ monstah
            else
            {
                //    foreach (var t in techList)
                //    {
                //        if (parentList.Contains(t.techID))
                //        {
                //            blockingTech = t.techName;
                //            break;
                //        }
                //    }
                foreach (var p in parentList)
                {
                    ProtoTechNode pn = ResearchAndDevelopment.Instance.GetTechState(p);
                    if (pn == null || pn.state == RDTech.State.Unavailable)
                    {
                        blockingTech = KerbalConstructionTimeData.techNameToTitle[p];
                        break;
                    }
                }
            }

            return(blockingTech);
        }
 public override bool RequirementMet(ConfiguredContract contract)
 {
     foreach (string tech in techs)
     {
         ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(tech);
         if (techNode == null || techNode.state != RDTech.State.Available)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #16
0
        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);
        }
Exemple #17
0
 public void TechDisableEvent()
 {
     Log("Giving back " + giveBack.ToString() + " sci");
     ResearchAndDevelopment.Instance.AddScience(giveBack, TransactionReasons.None);
     giveBack = 0;
     foreach (RDTech item in relock)
     {
         ProtoTechNode protoNode = ResearchAndDevelopment.Instance.GetTechState(item.techID);
         protoNode.state = RDTech.State.Unavailable;
         ResearchAndDevelopment.Instance.SetTechState(item.techID, protoNode);
     }
     relock.Clear();
     Save();
 }
Exemple #18
0
        public ProtoTechNode ToProtoTechNode()
        {
            ProtoTechNode ret = new ProtoTechNode();

            ret.techID = id;
            if (state == "Available")
            {
                ret.state = RDTech.State.Available;
            }
            else
            {
                ret.state = RDTech.State.Unavailable;
            }
            return(ret);
        }
        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);
        }
Exemple #20
0
        public bool IsUnlocked()
        {
            if (ResearchAndDevelopment.Instance == null)
            {
                return(false);
            }

            ProtoTechNode ptn = ResearchAndDevelopment.Instance.GetTechState(techID);

            if (ptn == null)
            {
                return(false);
            }

            return(ptn.state == RDTech.State.Available);
        }
Exemple #21
0
        public void TechUnlockEvent(GameEvents.HostTargetAction <RDTech, RDTech.OperationResult> ev)
        {
            if (skip)
            {
                skip = false;
                return;
            }
            bool canAfford = false;

            int cost = ev.host.scienceCost * 10000;

            if (Funding.Instance.Funds >= cost)
            {
                canAfford = true;
            }

            if (ev.target == RDTech.OperationResult.Successful)
            {
                //Always give the science back
                giveBack += ev.host.scienceCost;
            }

            if (canAfford)
            {
                //Take the funds
                Funding.Instance.AddFunds((double)-cost, TransactionReasons.RnDTechResearch);
                Log("Taking " + cost.ToString() + " funds");
                if (ev.target != RDTech.OperationResult.Successful)
                {
                    skip = true;
                    ev.host.UnlockTech(true);
                    ProtoTechNode protoNode = ResearchAndDevelopment.Instance.GetTechState(ev.host.techID);
                    protoNode.state = RDTech.State.Available;
                    ResearchAndDevelopment.Instance.SetTechState(ev.host.techID, protoNode);
                }
            }
            else
            {
                Log("Cannot afford " + cost.ToString() + " funds");
                ScreenMessages.PostScreenMessage("[KSPCasher]: You cannot afford this node, it costs " + cost.ToString("C"));
                if (ev.target == RDTech.OperationResult.Successful)
                {
                    relock.Add(ev.host);
                }
            }
        }
Exemple #22
0
        protected float CurrentMultiplier()
        {
            SetupTech();

            int count = 0;

            foreach (string techId in allTech)
            {
                ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(techId);
                if (techNode == null || techNode.state != RDTech.State.Available)
                {
                    count++;
                }
            }

            return(Parent.GetLeveledListItem(multipliers) * count);
        }
Exemple #23
0
        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);
        }
Exemple #24
0
        float CalcScienceReward(float vesselCost, Vessel v, Part startingPart)
        {
            Log.Info("CalcScienceReward");

            if (KLFSettings.Instance.ScienceAtFailure &&
                HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                if (startingPart != null)
                {
                    if (ResearchAndDevelopment.Instance != null)
                    {
                        ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(startingPart.partInfo.TechRequired);
                        if (techNode != null)
                        {
                            // Need to reverse the science adjustment here
                            float scienceAdjustmentAdj = 110 - KLFSettings.Instance.ScienceAdjustment;

                            return((float)(techNode.scienceCost * Math.Log(vesselCost, scienceAdjustmentAdj)));
                        }
                        else
                        {
                            Log.Info("techNode is null");
                        }
                    }
                    else
                    {
                        Log.Info("ResearchAndDevelopment.Instance is null");
                    }
                }
                else
                {
                    float r = (float)(Math.Log(vesselCost, 10) * UnityEngine.Random.Range(0.75f, 1.25f));
                    if (r < 1)
                    {
                        r *= 10f;
                    }
                    if (r < 1)
                    {
                        r = 1.5f;
                    }
                    return(r);
                }
            }

            return(0f);
        }
Exemple #25
0
        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);
        }
Exemple #26
0
        private void Start()
        {
            TechAvailable = false;
            RealChutes    = false;

            try
            {
                if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX)
                {
                    AvailablePart availablePart = PartLoader.getPartInfoByName("Kaboom");

                    if (availablePart != null)
                    {
                        // This looks weird, because we get the part, find the node that it is in, loop through the parts in that node,
                        // and look at PartModelPurchased() when we get to the part we started with.
                        // Why not just call PartModelPurchased() on the part that we first get? Because it doesn't work, it always returns true.
                        // So this code looks as if it was written by the Department of Redundancy Department, but it is necessary to do it this way.

                        ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(availablePart.TechRequired);

                        if (techNode != null)
                        {
                            List <AvailablePart> lap = techNode.partsPurchased;

                            foreach (AvailablePart p in lap)
                            {
                                if (p.name == "Kaboom")
                                {
                                    if (ResearchAndDevelopment.PartModelPurchased(p))
                                    {
                                        Initialize();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Initialize();
                }
            }
            catch (Exception ex) { print("Kaboom startup exception - " + ex.Message); }
        }
        protected void UnlockTechnology(string techID)
        {
            ProtoTechNode ptd = new ProtoTechNode();
            ptd.state = RDTech.State.Available;
            ptd.techID = techID;
            ptd.scienceCost = 9999;

            if (HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
            {
                ptd.partsPurchased = PartLoader.Instance.parts.Where(p => p.TechRequired == techID).ToList();
            }
            else
            {
                ptd.partsPurchased = new List<AvailablePart>();
            }
                
            ResearchAndDevelopment.Instance.SetTechState(techID, ptd);
        }
Exemple #28
0
        public static bool IsBuyable(Part part)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }

            bool result = false;

            ProtoTechNode techNode = ResearchAndDevelopment.Instance.GetTechState(part.partInfo.TechRequired);

            if (techNode != null)
            {
                result = !techNode.partsPurchased.Contains(part.partInfo);
            }

            return(result);
        }
 private void ForceLockTech(string techID)
 {
     Debug.Log("[Toppler] Force locking " + techID);
     try
     {
         ProtoTechNode protoNode = ResearchAndDevelopment.Instance.GetTechState(techID);
         if (protoNode != null && protoNode.scienceCost > 0) //can't force close the initial tech
         {
             protoNode.state = RDTech.State.Unavailable;
             protoNode.partsPurchased.Clear();
             ResearchAndDevelopment.Instance.SetTechState(techID, protoNode);
         }
     }
     catch (Exception e)
     {
         Debug.Log("Error while force locking node.");
         Debug.LogException(e);
     }
 }
        protected void UnlockTechnology(string techID)
        {
            ProtoTechNode ptd = new ProtoTechNode();

            ptd.state       = RDTech.State.Available;
            ptd.techID      = techID;
            ptd.scienceCost = 9999;

            if (HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
            {
                ptd.partsPurchased = PartLoader.Instance.loadedParts.Where(p => p.TechRequired == techID).ToList();
            }
            else
            {
                ptd.partsPurchased = new List <AvailablePart>();
            }

            ResearchAndDevelopment.Instance.SetTechState(techID, ptd);
        }
Exemple #31
0
        void LockTechnologies()
        {
            if (!RnDOpen)
            {
                return;
            }

            unlockTechnology = TechnologyUnlock.OFF;

            foreach (RDNode node in RDController.Instance.nodes)
            {
                if (node.tech.scienceCost > 0)
                {
                    ProtoTechNode protoNode = ResearchAndDevelopment.Instance.GetTechState(node.tech.techID);
                    protoNode.state = RDTech.State.Unavailable;
                    protoNode.partsPurchased.Clear();
                    ResearchAndDevelopment.Instance.SetTechState(node.tech.techID, protoNode);
                }
            }
        }
Exemple #32
0
 private void LockTechnologies()
 {
     //bool flag = !this.RnDOpen;
     //if (!flag)
     if (this.RnDOpen)
     {
         this.unlockTechnology = TechnologyUnlock.OFF;
         foreach (RDNode current in RDController.Instance.nodes)
         {
             //bool flag2 = current.tech.scienceCost > 0;
             //if (flag2)
             if (current != null && current.tech.scienceCost > 0)
             {
                 ProtoTechNode techState = ResearchAndDevelopment.Instance.GetTechState(current.tech.techID);
                 techState.state = RDTech.State.Unavailable;
                 techState.partsPurchased.Clear();
                 ResearchAndDevelopment.Instance.SetTechState(current.tech.techID, techState);
             }
         }
     }
 }
Exemple #33
0
 private bool checkTechs()
 {
     if (ResearchAndDevelopment.Instance != null)
     {
         bool allTechsResearched = true;
         foreach (string techId in STOCK_TECH_IDS)
         {
             ProtoTechNode node = ResearchAndDevelopment.Instance.GetTechState(techId);
             if ((node == null) || (node.state != RDTech.State.Available))
             {
                 allTechsResearched = false;
                 break;
             }
         }
         this.allTechsResearched = allTechsResearched;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #34
0
        }         // So many ifs.....

        public static bool hasTech(string techid)
        {
            if (String.IsNullOrEmpty(techid))
            {
                return(false);
            }

            if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            {
                return(true);
            }

            ProtoTechNode techstate = ResearchAndDevelopment.Instance.GetTechState(techid);

            if (techstate != null)
            {
                return(techstate.state == RDTech.State.Available);
            }
            else
            {
                return(false);
            }
        }
Exemple #35
0
 public FakeTechNode FromProtoTechNode(ProtoTechNode node)
 {
     this.id = node.techID;
     this.state = node.state.ToString();
     return this;
 }
Exemple #36
0
 public ProtoTechNode ToProtoTechNode()
 {
     ProtoTechNode ret = new ProtoTechNode();
     ret.techID = id;
     if (state == "Available")
         ret.state = RDTech.State.Available;
     else
         ret.state = RDTech.State.Unavailable;
     return ret;
 }