예제 #1
0
        protected override bool CanActivate(ref string reason)
        {
            lastActivationRequest = this;

            // Force the active strategies text to be updated next tick
            AdminResizer.Instance.ticks = 0;

            // If we are at max strategies, only allow activation if it would be an upgrade
            IEnumerable <Strategy> activeStrategies = StrategySystem.Instance.Strategies.Where(s => s.IsActive);
            int limit = GameVariables.Instance.GetActiveStrategyLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Administration)) - 1;

            if (activeStrategies.Count() >= limit)
            {
                UpgradeableStrategy upgradeable = this as UpgradeableStrategy;
                if (upgradeable != null && activeStrategies.OfType <UpgradeableStrategy>().Any(s => s.Name == upgradeable.Name))
                {
                    return(true);
                }
                else
                {
                    reason = "The Administration Building cannot support more than " + limit + " active strategies at this level.";
                    return(false);
                }
            }

            // Special requirements
            foreach (StrategyEffect effect in Effects)
            {
                IRequirementEffect requirement = effect as IRequirementEffect;
                if (requirement != null)
                {
                    string unmetReason;
                    if (!requirement.RequirementMet(out unmetReason))
                    {
                        reason = requirement.RequirementText();
                        if (!string.IsNullOrEmpty(unmetReason))
                        {
                            reason += " (" + unmetReason + ")";
                        }

                        return(false);
                    }
                }
            }

            return(base.CanActivate(ref reason));
        }
예제 #2
0
        protected virtual string GenerateRequirementText()
        {
            string result = "";

            // Write out stock-based requirements
            result += "\n<b><color=#feb200>Requirements:</color></b>\n\n";
            if (InitialCostFunds > 0)
            {
                double currentFunds = Funding.Instance.Funds;
                bool   fundsMet     = Math.Round(currentFunds) >= Math.Round(InitialCostFunds);
                string text         = "At least " + InitialCostFunds.ToString("N0") + " funds";
                if (!fundsMet)
                {
                    text += " (Current funds: " + Math.Round(currentFunds) + ")";
                }
                result += RequirementText(text, fundsMet);
            }
            if (InitialCostScience > 0)
            {
                double currentScience = ResearchAndDevelopment.Instance.Science;
                bool   scienceMet     = Math.Round(currentScience) >= Math.Round(InitialCostScience);
                string text           = "At least " + InitialCostScience.ToString("N0") + " science";
                if (!scienceMet)
                {
                    text += " (Current science: " + Math.Round(currentScience) + ")";
                }
                result += RequirementText(text, scienceMet);
            }
            if (RequiredReputation > -1000 || InitialCostReputation > 0)
            {
                float  reputationNeeded  = Math.Max(RequiredReputation, InitialCostReputation > 0 ? InitialCostReputation : -1000);
                float  currentReputation = Reputation.Instance.reputation;
                bool   repMet            = Math.Round(currentReputation) >= Math.Round(reputationNeeded);
                string text = "At least " + reputationNeeded.ToString("N0") + " reputation";
                if (!repMet)
                {
                    text += " (Current reputation: " + Math.Round(currentReputation) + ")";
                }
                result += RequirementText(text, repMet);
            }
            int minFacilityLevel = MinimumFacilityLevel();

            if (minFacilityLevel > 1)
            {
                int currentLevel = (int)Math.Round(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Administration) *
                                                   ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.Administration)) + 1;
                result += RequirementText("Administration Facility Level " + minFacilityLevel,
                                          currentLevel >= minFacilityLevel);
            }

            // Requirements from strategies
            foreach (StrategyEffect effect in Effects)
            {
                IRequirementEffect requirementEffect = effect as IRequirementEffect;
                if (requirementEffect != null)
                {
                    string unmetReason;
                    bool   requirementMet = requirementEffect.RequirementMet(out unmetReason);
                    string text           = requirementEffect.RequirementText();
                    if (!requirementMet && !string.IsNullOrEmpty(unmetReason))
                    {
                        text += " (" + unmetReason + ")";
                    }
                    result += RequirementText(text, requirementMet);
                }
            }

            return(result);
        }
예제 #3
0
        IEnumerator <YieldInstruction> CheckStrategyState()
        {
            float timeStep  = 0.01f;
            float pauseTime = 0.05f;

            // Pause until the strategy system and facility systems are ready
            while (StrategySystem.Instance == null || ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.Administration) == -1)
            {
                yield return(new WaitForSeconds(5));
            }

            while (true)
            {
                float startTime = Time.realtimeSinceStartup;

                string unmetReason = "unknown";

                foreach (StrategiaStrategy strategy in StrategySystem.Instance.Strategies.OfType <StrategiaStrategy>())
                {
                    bool met = true;

                    // Check Reputation
                    if (strategy.RequiredReputation > -1000 || strategy.InitialCostReputation > 0)
                    {
                        float currentReputation = Reputation.Instance.reputation;
                        float reputationNeeded  = Math.Max(strategy.RequiredReputation,
                                                           strategy.InitialCostReputation > 0 ? strategy.InitialCostReputation : -1000);
                        met &= Math.Round(currentReputation) >= Math.Round(reputationNeeded);

                        unmetReason = "Insufficient reputation (needs " + reputationNeeded + ", has " + currentReputation + ")";
                    }

                    // Check effects
                    foreach (StrategyEffect effect in strategy.Effects)
                    {
                        if (!met)
                        {
                            break;
                        }

                        // Check if a requirement is met
                        IRequirementEffect requirement = effect as IRequirementEffect;
                        if (requirement != null)
                        {
                            met = requirement.RequirementMet(out unmetReason);
                        }

                        // Check if we need to take a break
                        if (Time.realtimeSinceStartup >= startTime + timeStep)
                        {
                            yield return(null);

                            startTime = Time.realtimeSinceStartup;
                        }
                    }

                    if (!strategyActive.ContainsKey(strategy.Config.Name))
                    {
                        strategyActive[strategy.Config.Name] = met;
                    }
                    else if (strategyActive[strategy.Config.Name] != met)
                    {
                        Notify(strategy, met);
                        strategyActive[strategy.Config.Name] = met;

                        if (!met)
                        {
                            Debug.Log("Strategia: Strategy no longer available due to reason: " + unmetReason);
                        }
                    }

                    yield return(new WaitForSeconds(pauseTime));
                }

                // Pause at least 5 seconds between full checks
                yield return(new WaitForSeconds(5));
            }
        }