コード例 #1
0
        private void contractRewards()
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractReward, (float)root.FundsCompletion, root.ScienceCompletion, root.ReputationCompletion);

            fundsRew      = (float)root.FundsCompletion;
            fundsRewStrat = currencyQuery.GetEffectDelta(Currency.Funds);

            if (fundsRewStrat != 0)
            {
                fundsRewString = string.Format("+ {0:N0} ({1:N0})", fundsRew + fundsRewStrat, fundsRewStrat);
            }
            else if (fundsRew != 0)
            {
                fundsRewString = "+ " + fundsRew.ToString("N0");
            }
            else
            {
                fundsRewString = "";
            }

            repRew      = root.ReputationCompletion;
            repRewStrat = currencyQuery.GetEffectDelta(Currency.Reputation);

            if (repRewStrat != 0)
            {
                repRewString = string.Format("+ {0:N0} ({1:N0})", repRew + repRewStrat, repRewStrat);
            }
            else if (repRew != 0)
            {
                repRewString = "+ " + repRew.ToString("N0");
            }
            else
            {
                repRewString = "";
            }

            sciRew      = root.ScienceCompletion;
            sciRewStrat = currencyQuery.GetEffectDelta(Currency.Science);

            if (sciRewStrat != 0)
            {
                sciRewString = string.Format("+ {0:N0} ({1:N0})", sciRew + sciRewStrat, sciRewStrat);
            }
            else if (sciRew != 0)
            {
                sciRewString = "+ " + sciRew.ToString("N0");
            }
            else
            {
                sciRewString = "";
            }
        }
コード例 #2
0
 /// <summary>
 /// Updates the research on the team's current part
 /// </summary>
 /// <returns>The amount of du added to the part this update.</returns>
 public float UpdateResearch(float normalizedTime, float currentPartData)
 {
     if (PartInResearch != "" && ResearchActive)
     {
         float pointsForTick = Points * normalizedTime * PartRnDRate;
         pointsForTick = Mathf.Min(pointsForTick, MaxData - currentPartData);
         float costForTick = Cost * normalizedTime * PartRnDCost;
         Log("Points " + pointsForTick + ", Cost " + costForTick);
         if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
         {
             CurrencyModifierQuery query = CurrencyModifierQuery.RunQuery(TransactionReasons.RnDPartPurchase, -costForTick, 0f, 0f);
             float totalCost             = query.GetInput(Currency.Funds) + query.GetEffectDelta(Currency.Funds);
             Log("Total cost " + totalCost);
             if (totalCost < Funding.Instance.Funds)
             {
                 Log("Subtracting cost...");
                 Funding.Instance.AddFunds(totalCost, TransactionReasons.RnDPartPurchase);
                 return(pointsForTick);
             }
             else
             {
                 return(0f);
             }
         }
         else
         {
             return(pointsForTick);
         }
     }
     return(0f);
 }
コード例 #3
0
        internal void paramPenalties(ContractParameter cP)
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractPenalty, (float)cP.FundsFailure, 0f, cP.ReputationFailure);

            fundsPenalty  = cP.FundsFailure;
            fundsPen      = "- " + fundsPenalty.ToString("N0");
            fundsPenStrat = currencyQuery.GetEffectDelta(Currency.Funds);
            if (fundsPenStrat != 0f)
            {
                fundsPen = string.Format("- {0:N0} ({1:N0})", fundsPenalty + fundsPenStrat, fundsPenStrat);
            }
            repPenalty  = cP.ReputationFailure;
            repPen      = "- " + repPenalty.ToString("N0");
            repPenStrat = currencyQuery.GetEffectDelta(Currency.Reputation);
            if (repPenStrat != 0f)
            {
                repPen = string.Format("- {0:N0} ({1:N0})", repPenalty + repPenStrat, repPenStrat);
            }
        }
コード例 #4
0
        private static float NextKerbalHireCost()
        {
            if (GameVariables.Instance == null || HighLogic.CurrentGame == null)
            {
                return(1.0f);
            }

            CurrencyModifierQuery currencyModifierQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.CrewRecruited, -GameVariables.Instance.GetRecruitHireCost(HighLogic.CurrentGame.CrewRoster.GetActiveCrewCount()) *
                                                                                         HighLogic.CurrentGame.Parameters.Career.FundsLossMultiplier, 0.0f, 0.0f);

            return(-(currencyModifierQuery.GetInput(Currency.Funds) + currencyModifierQuery.GetEffectDelta(Currency.Funds)));
        }
コード例 #5
0
ファイル: BCEvents.cs プロジェクト: OverloadUT/OATBeanCounter
        /// <summary>
        /// Fires every time a currency transaction is modified by a CurrencyModifierQuery object
        /// </summary>
        /// <param name="query">The object with all of the modification info</param>
        public void currencyModifiedEvent(CurrencyModifierQuery query)
        {
            BeanCounter.LogFormatted_DebugOnly("--------- currencyModifiedEvent ------------");

            BeanCounter.LogFormatted_DebugOnly("Currency modified! Reason: {0}, Funds {1:f2}, Science {2:f2}, Rep {3:f3}",
                                               query.reason.ToString(),
                                               query.GetEffectDelta(Currency.Funds),
                                               query.GetEffectDelta(Currency.Reputation),
                                               query.GetEffectDelta(Currency.Science)
                                               );

            //BeanCounter.LogFormatted_DebugOnly("Stack Trace: {0}", System.Environment.StackTrace);

            if (currencyModTime != HighLogic.CurrentGame.UniversalTime)
            {
                currencyModTime  = HighLogic.CurrentGame.UniversalTime;
                lastCurrencyMods = new List <CurrencyModifierQuery>();
            }

            lastCurrencyMods.Add(query);

            BeanCounter.LogFormatted_DebugOnly("-------- /currencyModifiedEvent ------------");
        }
コード例 #6
0
        private void contractPenalties()
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractPenalty, (float)root.FundsFailure, 0f, root.ReputationFailure);

            fundsPen      = (float)root.FundsFailure;
            fundsPenStrat = currencyQuery.GetEffectDelta(Currency.Funds);

            if (fundsPenStrat != 0)
            {
                fundsPenString = string.Format("- {0:N0} ({1:N0})", fundsPen + fundsPenStrat, fundsPenStrat);
            }
            else if (fundsPen != 0)
            {
                fundsPenString = "- " + fundsPen.ToString("N0");
            }
            else
            {
                fundsPenString = "";
            }

            repPen      = root.ReputationFailure;
            repPenStrat = currencyQuery.GetEffectDelta(Currency.Reputation);

            if (repPenStrat != 0)
            {
                repPenString = string.Format("- {0:N0} ({1:N0})", repPen + repPenStrat, repPenStrat);
            }
            else if (repPen != 0)
            {
                repPenString = "- " + repPen.ToString("N0");
            }
            else
            {
                repPenString = "";
            }
        }
コード例 #7
0
        private void contractAdvance()
        {
            CurrencyModifierQuery currencyQuery = CurrencyModifierQuery.RunQuery(TransactionReasons.ContractAdvance, (float)root.FundsAdvance, 0, 0);

            fundsAdv      = (float)root.FundsAdvance;
            fundsAdvStrat = currencyQuery.GetEffectDelta(Currency.Funds);

            if (fundsAdvStrat != 0)
            {
                fundsAdvString = string.Format("- {0:N0} ({1:N0})", fundsAdv + fundsAdvStrat, fundsAdvStrat);
            }
            else if (fundsAdv != 0)
            {
                fundsAdvString = fundsAdv.ToString("N0");
            }
            else
            {
                fundsAdvString = "";
            }
        }
コード例 #8
0
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            if (qry.reason != TransactionReasons.StructureConstruction)
            {
                return;
            }

            fundsDelta      = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta    = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta      = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta    = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
コード例 #9
0
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            fundsDelta      = 0.0f;
            reputationDelta = 0.0f;
            scienceDelta    = 0.0f;

            // Check if it's non-zero
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 && Math.Abs(qry.GetInput(Currency.Science)) < 0.01 && Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            fundsDelta      = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta    = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta      = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta    = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
コード例 #10
0
        protected override void OnEffectQuery(CurrencyModifierQuery qry)
        {
            fundsDelta = 0.0f;
            reputationDelta = 0.0f;
            scienceDelta = 0.0f;

            // Check if it's non-zero
            if (Math.Abs(qry.GetInput(Currency.Funds)) < 0.01 && Math.Abs(qry.GetInput(Currency.Science)) < 0.01 && Math.Abs(qry.GetInput(Currency.Reputation)) < 0.01)
            {
                return;
            }

            fundsDelta = qry.GetEffectDelta(Currency.Funds);
            reputationDelta = qry.GetEffectDelta(Currency.Reputation);
            scienceDelta = qry.GetEffectDelta(Currency.Science);

            base.OnEffectQuery(qry);

            // Calculate any changes
            fundsDelta = qry.GetEffectDelta(Currency.Funds) - fundsDelta;
            reputationDelta = qry.GetEffectDelta(Currency.Reputation) - reputationDelta;
            scienceDelta = qry.GetEffectDelta(Currency.Science) - scienceDelta;
        }
コード例 #11
0
ファイル: BCEvents.cs プロジェクト: OverloadUT/OATBeanCounter
        /// <summary>
        /// Fires every time a currency transaction is modified by a CurrencyModifierQuery object
        /// </summary>
        /// <param name="query">The object with all of the modification info</param>
        public void currencyModifiedEvent(CurrencyModifierQuery query)
        {
            BeanCounter.LogFormatted_DebugOnly("--------- currencyModifiedEvent ------------");

            BeanCounter.LogFormatted_DebugOnly("Currency modified! Reason: {0}, Funds {1:f2}, Science {2:f2}, Rep {3:f3}",
                query.reason.ToString(),
                query.GetEffectDelta(Currency.Funds),
                query.GetEffectDelta(Currency.Reputation),
                query.GetEffectDelta(Currency.Science)
                );

            //BeanCounter.LogFormatted_DebugOnly("Stack Trace: {0}", System.Environment.StackTrace);

            if (currencyModTime != HighLogic.CurrentGame.UniversalTime)
            {
                currencyModTime = HighLogic.CurrentGame.UniversalTime;
                lastCurrencyMods = new List<CurrencyModifierQuery>();
            }

            lastCurrencyMods.Add(query);

            BeanCounter.LogFormatted_DebugOnly("-------- /currencyModifiedEvent ------------");
        }
コード例 #12
0
        /// <summary>
        /// Checks if the "basic" requirements that shouldn't change due to expressions are met.
        /// </summary>
        /// <param name="contract">The contract</param>
        /// <returns>Whether the contract can be offered.</returns>
        public bool MeetBasicRequirements(ConfiguredContract contract)
        {
            LoggingUtil.LogLevel origLogLevel = LoggingUtil.logLevel;
            try
            {
                // Turn tracing on
                if (trace)
                {
                    LoggingUtil.logLevel = LoggingUtil.LogLevel.VERBOSE;
                    LoggingUtil.LogWarning(this, "Tracing enabled for contract type " + name);
                }

                // Check funding
                if (advanceFunds < 0)
                {
                    CurrencyModifierQuery q = new CurrencyModifierQuery(TransactionReasons.ContractAdvance, -advanceFunds, 0.0f, 0.0f);
                    GameEvents.Modifiers.OnCurrencyModifierQuery.Fire(q);
                    float fundsRequired = advanceFunds + q.GetEffectDelta(Currency.Funds);

                    if (!Funding.CanAfford(fundsRequired))
                    {
                        throw new ContractRequirementException("Can't afford contract advance cost.");
                    }
                }

                // Check expiry
                if ((contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Withdrawn) &&
                    Planetarium.fetch != null && contract.DateExpire < Planetarium.fetch.time)
                {
                    throw new ContractRequirementException("Expired contract.");
                }

                // Checks for maxSimultaneous/maxCompletions
                if (maxSimultaneous != 0 || maxCompletions != 0)
                {
                    IEnumerable <ConfiguredContract> contractList = ConfiguredContract.CurrentContracts.
                                                                    Where(c => c.contractType != null && c.contractType.name == name && c != contract);

                    // Check if we're breaching the active limit
                    int activeContracts = contractList.Count();
                    if (maxSimultaneous != 0 && activeContracts >= maxSimultaneous)
                    {
                        throw new ContractRequirementException("Too many active contracts.");
                    }

                    // Check if we're breaching the completed limit
                    if (maxCompletions != 0)
                    {
                        if (ActualCompletions() + activeContracts >= maxCompletions)
                        {
                            throw new ContractRequirementException("Too many completed/active/offered contracts.");
                        }
                    }
                }

                // Check the group values
                if (group != null)
                {
                    CheckContractGroup(contract, group);
                }

                return(true);
            }
            catch (ContractRequirementException e)
            {
                LoggingUtil.LogLevel level = contract.ContractState == Contract.State.Active ? LoggingUtil.LogLevel.INFO : contract.contractType != null ? LoggingUtil.LogLevel.DEBUG : LoggingUtil.LogLevel.VERBOSE;
                string prefix = contract.contractType != null ? "Cancelling contract of type " + name + " (" + contract.Title + "): " :
                                "Didn't generate contract of type " + name + ": ";
                LoggingUtil.Log(level, this.GetType(), prefix + e.Message);
                return(false);
            }
            catch
            {
                LoggingUtil.LogError(this, "Exception while attempting to check requirements of contract type " + name);
                throw;
            }
            finally
            {
                LoggingUtil.logLevel = origLogLevel;
                loaded = true;
            }
        }
コード例 #13
0
        protected void MissionControlText(ContractType contractType)
        {
            string text = "<b><color=#DB8310>Briefing:</color></b>\n\n";

            // Special case for one-off contracts
            string description = contractType.genericDescription;
            if (contractType.maxCompletions == 1)
            {
                foreach (ConfiguredContract c in ConfiguredContract.CompletedContracts)
                {
                    if (c.contractType != null && c.contractType.name == contractType.name)
                    {
                        description = c.Description;
                        break;
                    }
                }
            }
            text += "<color=#CCCCCC>" + description + "</color>\n\n";

            text += "<b><color=#DB8310>Pre-Requisites:</color></b>\n\n";

            // Do text for funds
            if (contractType.advanceFunds < 0)
            {
                CurrencyModifierQuery q = new CurrencyModifierQuery(TransactionReasons.ContractAdvance, -contractType.advanceFunds, 0.0f, 0.0f);
                GameEvents.Modifiers.OnCurrencyModifierQuery.Fire(q);
                float fundsRequired = contractType.advanceFunds + q.GetEffectDelta(Currency.Funds);

                text += RequirementLine("Must have {0} funds for advance", Funding.CanAfford(fundsRequired));
            }

            // Do text for max completions
            if (contractType.maxCompletions != 0)
            {
                int completionCount = contractType.ActualCompletions();
                bool met = completionCount < contractType.maxCompletions;
                if (contractType.maxCompletions == 1)
                {
                    text += RequirementLine("Must not have been completed before", met);
                }
                else
                {
                    text += RequirementLine("May only be completed " + contractType.maxCompletions + " times", met,
                        "has been completed " + completionCount + " times");
                }
            }

            // Do check for group maxSimultaneous
            for (ContractGroup currentGroup = contractType.group; currentGroup != null; currentGroup = currentGroup.parent)
            {
                if (currentGroup.maxSimultaneous != 0)
                {
                    int count = currentGroup.CurrentContracts();
                    text += RequirementLine(string.Format("May only have {0} offered/active {1} contracts at a time",
                        currentGroup.maxSimultaneous, currentGroup.displayName, count), count < currentGroup.maxSimultaneous);
                }
            }

            // Do check of required values
            List<string> titles = new List<string>();
            Dictionary<string, bool> titlesMet = new Dictionary<string, bool>();
            foreach (KeyValuePair<string, ContractType.DataValueInfo> pair in contractType.dataValues)
            {
                string name = pair.Key;
                if (pair.Value.required && !contractType.dataNode.IsDeterministic(name) && !pair.Value.hidden && !pair.Value.IsIgnoredType())
                {
                    bool met = true;
                    try
                    {
                        contractType.CheckRequiredValue(name);
                    }
                    catch
                    {
                        met = false;
                    }

                    string title = string.IsNullOrEmpty(pair.Value.title) ? "Key " + name + " must have a value" : pair.Value.title;
                    if (titlesMet.ContainsKey(title))
                    {
                        titlesMet[title] &= met;
                    }
                    else
                    {
                        titlesMet[title] = met;
                        titles.Add(title);
                    }
                }
            }

            // Do the actual add
            foreach (string title in titles)
            {
                text += RequirementLine(title, titlesMet[title]);
            }

            // Force check requirements for this contract
            CheckRequirements(contractType.Requirements);

            // Do a Research Bodies check, if applicable
            if (Util.Version.VerifyResearchBodiesVersion() && contractType.targetBody != null)
            {
                text += ResearchBodyText(contractType);
            }

            text += ContractRequirementText(contractType.Requirements);

            MissionControl.Instance.contractText.text = text;
        }