Ejemplo n.º 1
0
    private void InitializeAIEvaluableElement(SeasonEffectDefinition seasonEffectDefinition)
    {
        if (seasonEffectDefinition == null)
        {
            throw new ArgumentNullException("seasonEffect");
        }
        Diagnostics.Assert(seasonEffectDefinition.Name != null);
        Diagnostics.Assert(this.aiParametersByElement != null);
        if (this.aiParametersByElement.ContainsKey(seasonEffectDefinition.Name))
        {
            return;
        }
        List <IAIParameter <InterpreterContext> > list = new List <IAIParameter <InterpreterContext> >();

        if (this.aiParameterDatabase != null && this.aiParameterDatabase.ContainsKey(seasonEffectDefinition.Name))
        {
            AIParameterDatatableElement value = this.aiParameterDatabase.GetValue(seasonEffectDefinition.Name);
            if (value == null)
            {
                Diagnostics.LogWarning("Cannot retrieve ai parameters for constructible element '{0}'", new object[]
                {
                    seasonEffectDefinition.Name
                });
                return;
            }
            if (value.AIParameters == null)
            {
                Diagnostics.LogWarning("There aren't any parameters in aiParameters '{0}'", new object[]
                {
                    seasonEffectDefinition.Name
                });
                return;
            }
            for (int i = 0; i < value.AIParameters.Length; i++)
            {
                AIParameterDatatableElement.AIParameter aiparameter = value.AIParameters[i];
                Diagnostics.Assert(aiparameter != null);
                list.Add(aiparameter.Instantiate());
            }
        }
        if (this.orbUnlockDefinitions == null)
        {
            this.aiParametersByElement.Add(seasonEffectDefinition.Name, list.ToArray());
            IEnumerable <DepartmentOfScience.ConstructibleElement> database = Databases.GetDatabase <DepartmentOfScience.ConstructibleElement>(false);
            List <TechnologyDefinition> list2 = new List <TechnologyDefinition>();
            foreach (DepartmentOfScience.ConstructibleElement constructibleElement in database)
            {
                TechnologyDefinition technologyDefinition = constructibleElement as TechnologyDefinition;
                if (technologyDefinition != null && technologyDefinition.Visibility == TechnologyDefinitionVisibility.Visible && (technologyDefinition.TechnologyFlags & DepartmentOfScience.ConstructibleElement.TechnologyFlag.OrbUnlock) == DepartmentOfScience.ConstructibleElement.TechnologyFlag.OrbUnlock)
                {
                    list2.Add(technologyDefinition);
                }
            }
            this.orbUnlockDefinitions = list2.ToArray();
        }
    }
Ejemplo n.º 2
0
    public IEnumerable <IAIParameter <InterpreterContext> > GetAIParameters(PillarDefinition pillarDefinition)
    {
        if (pillarDefinition == null)
        {
            throw new ArgumentNullException("pillarDefinition");
        }
        IEnumerable <WorldEffectDefinition> enumerator = this.pillarService.GetActiveWorldEffectDefinitions(pillarDefinition.Name, base.AIEntity.Empire);

        if (enumerator != null)
        {
            foreach (WorldEffectDefinition worldEffectDefinition in enumerator)
            {
                IAIParameter <InterpreterContext>[] worldEffectAiParameters;
                if (!this.pillarEffectsAiParameters.TryGetValue(worldEffectDefinition.Name, out worldEffectAiParameters))
                {
                    IDatabase <AIParameterDatatableElement> aiParameterDatabase = Databases.GetDatabase <AIParameterDatatableElement>(false);
                    Diagnostics.Assert(aiParameterDatabase != null);
                    AIParameterDatatableElement aiParameterDatatableElement;
                    if (aiParameterDatabase.TryGetValue(worldEffectDefinition.Name, out aiParameterDatatableElement))
                    {
                        if (aiParameterDatatableElement.AIParameters != null)
                        {
                            worldEffectAiParameters = new IAIParameter <InterpreterContext> [aiParameterDatatableElement.AIParameters.Length];
                            for (int index = 0; index < aiParameterDatatableElement.AIParameters.Length; index++)
                            {
                                AIParameterDatatableElement.AIParameter parameterDefinition = aiParameterDatatableElement.AIParameters[index];
                                Diagnostics.Assert(parameterDefinition != null);
                                worldEffectAiParameters[index] = parameterDefinition.Instantiate();
                            }
                        }
                    }
                    else
                    {
                        AILayer.LogError("No AIParameters for WorldEffectDefinition {0}", new object[]
                        {
                            worldEffectDefinition.Name
                        });
                    }
                }
                if (worldEffectAiParameters != null)
                {
                    for (int index2 = 0; index2 < worldEffectAiParameters.Length; index2++)
                    {
                        yield return(worldEffectAiParameters[index2]);
                    }
                }
            }
        }
        yield break;
    }
Ejemplo n.º 3
0
    public IEnumerable <IAIParameter <InterpreterContext> > GetAIParameters(Region regionElement)
    {
        IDatabase <AIParameterDatatableElement> aiParameterDatabase = Databases.GetDatabase <AIParameterDatatableElement>(false);

        Diagnostics.Assert(aiParameterDatabase != null);
        IWorldAtlasAIHelper worldAtlasHelper = AIScheduler.Services.GetService <IWorldAtlasAIHelper>();

        Diagnostics.Assert(worldAtlasHelper != null);
        StaticString biomeName = worldAtlasHelper.GetRegionBiome(regionElement);

        Diagnostics.Assert(!StaticString.IsNullOrEmpty(biomeName));
        IAIParameter <InterpreterContext>[] aiParameters;
        if (!this.aiParametersByBiomeName.TryGetValue(biomeName, out aiParameters))
        {
            AIParameterDatatableElement aiParameterDatatableElement;
            if (aiParameterDatabase.TryGetValue(biomeName, out aiParameterDatatableElement))
            {
                Diagnostics.Assert(aiParameterDatatableElement != null);
                if (aiParameterDatatableElement.AIParameters != null)
                {
                    aiParameters = new IAIParameter <InterpreterContext> [aiParameterDatatableElement.AIParameters.Length];
                    for (int index = 0; index < aiParameterDatatableElement.AIParameters.Length; index++)
                    {
                        AIParameterDatatableElement.AIParameter parameterDefinition = aiParameterDatatableElement.AIParameters[index];
                        Diagnostics.Assert(parameterDefinition != null);
                        aiParameters[index] = parameterDefinition.Instantiate();
                    }
                }
                else
                {
                    Diagnostics.LogWarning("Biome {0} has no AI Parameters.", new object[]
                    {
                        biomeName
                    });
                }
            }
            else
            {
                Diagnostics.LogWarning("Biome {0} has no AI Parameters.", new object[]
                {
                    biomeName
                });
            }
            this.aiParametersByBiomeName.Add(biomeName, aiParameters);
        }
        if (aiParameters != null)
        {
            for (int index2 = 0; index2 < aiParameters.Length; index2++)
            {
                yield return(aiParameters[index2]);
            }
        }
        if (this.regionEvaluationAiParameters == null)
        {
            AIParameterDatatableElement aiParameterDatatableElement2;
            if (aiParameterDatabase.TryGetValue("RegionEvaluation", out aiParameterDatatableElement2))
            {
                if (aiParameterDatatableElement2.AIParameters != null)
                {
                    this.regionEvaluationAiParameters = new IAIParameter <InterpreterContext> [aiParameterDatatableElement2.AIParameters.Length];
                    for (int index3 = 0; index3 < aiParameterDatatableElement2.AIParameters.Length; index3++)
                    {
                        AIParameterDatatableElement.AIParameter parameterDefinition2 = aiParameterDatatableElement2.AIParameters[index3];
                        Diagnostics.Assert(parameterDefinition2 != null);
                        this.regionEvaluationAiParameters[index3] = parameterDefinition2.Instantiate();
                    }
                }
                else
                {
                    Diagnostics.LogWarning("RegionEvaluation has no AI Parameters.");
                }
            }
            else
            {
                Diagnostics.LogWarning("RegionEvaluation has no AI Parameters.");
            }
        }
        for (int index4 = 0; index4 < this.regionEvaluationAiParameters.Length; index4++)
        {
            yield return(this.regionEvaluationAiParameters[index4]);
        }
        yield break;
    }