Пример #1
0
    protected bool CanAffordFoodCost(AILayer_CreepingNode.EvaluableCreepingNode node)
    {
        List <CreepingNodeConstructionMessage> list = new List <CreepingNodeConstructionMessage>(base.AIEntity.AIPlayer.Blackboard.GetMessages <CreepingNodeConstructionMessage>(BlackboardLayerID.Empire, (CreepingNodeConstructionMessage match) => match.State != BlackboardMessage.StateValue.Message_Canceled));
        SimulationObject     simulationObject       = new SimulationObject("PendingNodesUpkeep");
        SimulationDescriptor descriptor             = null;
        SimulationDescriptor descriptor2            = null;

        if (this.simulationDescriptorDatabase.TryGetValue("ClassCreepingNode", out descriptor2))
        {
            simulationObject.AddDescriptor(descriptor2);
            for (int i = 0; i < list.Count; i++)
            {
                CreepingNodeImprovementDefinition value = this.creepingNodeDefinitionDatabase.GetValue(list[i].NodeDefinitionName);
                if (value != null && this.simulationDescriptorDatabase.TryGetValue(node.nodeDefinition.ConstructionCostDescriptor, out descriptor))
                {
                    simulationObject.AddDescriptor(descriptor);
                }
            }
            if (this.simulationDescriptorDatabase.TryGetValue(node.nodeDefinition.ConstructionCostDescriptor, out descriptor))
            {
                simulationObject.AddDescriptor(descriptor);
            }
            this.aiEntityCity.City.SimulationObject.AddChild(simulationObject);
            this.aiEntityCity.City.SimulationObject.Refresh();
            float propertyValue = this.aiEntityCity.City.GetPropertyValue("NetCityGrowth");
            this.aiEntityCity.City.SimulationObject.RemoveChild(simulationObject);
            this.aiEntityCity.City.SimulationObject.Refresh();
            return(propertyValue > 0f);
        }
        Diagnostics.LogError("Could not find the class creeping node descriptor");
        return(false);
    }
Пример #2
0
    protected bool CanAffordUpkeepCost(AILayer_CreepingNode.EvaluableCreepingNode node)
    {
        List <CreepingNodeConstructionMessage> list = new List <CreepingNodeConstructionMessage>(base.AIEntity.AIPlayer.Blackboard.GetMessages <CreepingNodeConstructionMessage>(BlackboardLayerID.Empire, (CreepingNodeConstructionMessage match) => match.State != BlackboardMessage.StateValue.Message_Canceled));
        SimulationObject     simulationObject       = new SimulationObject("PendingNodesUpkeep");
        SimulationDescriptor upkeepDescriptor;

        for (int i = 0; i < list.Count; i++)
        {
            CreepingNodeImprovementDefinition value = this.creepingNodeDefinitionDatabase.GetValue(list[i].NodeDefinitionName);
            if (value != null)
            {
                upkeepDescriptor = value.GetUpkeepDescriptor();
                if (upkeepDescriptor != null)
                {
                    simulationObject.AddDescriptor(upkeepDescriptor);
                }
            }
        }
        upkeepDescriptor = node.nodeDefinition.GetUpkeepDescriptor();
        if (upkeepDescriptor != null)
        {
            simulationObject.AddDescriptor(upkeepDescriptor);
        }
        this.aiEntityCity.City.SimulationObject.AddChild(simulationObject);
        this.aiEntityCity.City.SimulationObject.Refresh();
        float propertyValue = this.aiEntityCity.City.GetPropertyValue("CreepingNodesUpkeep");
        float upkeepLimit   = this.GetUpkeepLimit();

        this.aiEntityCity.City.SimulationObject.RemoveChild(simulationObject);
        this.aiEntityCity.City.SimulationObject.Refresh();
        return(propertyValue <= upkeepLimit);
    }
Пример #3
0
    protected List <AILayer_CreepingNode.EvaluableCreepingNode> GetAvailableNodes()
    {
        List <AILayer_CreepingNode.EvaluableCreepingNode> list = new List <AILayer_CreepingNode.EvaluableCreepingNode>();
        List <StaticString> list2 = new List <StaticString>();

        CreepingNodeImprovementDefinition[] values = this.creepingNodeDefinitionDatabase.GetValues();
        for (int i = 0; i < this.worldPositionningService.World.Regions.Length; i++)
        {
            Region region = this.worldPositionningService.World.Regions[i];
            int    num    = region.IsRegionColonized() ? 1 : 0;
            bool   flag   = region.Kaiju != null;
            bool   flag2  = region.BelongToEmpire(base.AIEntity.Empire);
            bool   flag3  = false;
            if (ELCPUtilities.UseELCPPeacefulCreepingNodes && !flag2 && region.Owner != null && region.Owner is MajorEmpire)
            {
                flag3 = (this.departmentOfForeignAffairs.IsFriend(region.Owner) && this.departmentOfForeignAffairs.CanMoveOn(region.Index, false));
            }
            bool flag4 = false;
            if (flag)
            {
                flag4 = (region.Kaiju.IsWild() || region.Kaiju.OwnerEmpireIndex == base.AIEntity.Empire.Index);
            }
            if (num == 0 || flag2 || flag3 || (flag && flag4))
            {
                foreach (PointOfInterest pointOfInterest in region.PointOfInterests)
                {
                    bool flag5 = this.departmentOfCreepingNodes.POIIsOnCooldown(pointOfInterest.GUID);
                    if ((!flag3 || pointOfInterest.Type == "QuestLocation") && !flag5)
                    {
                        bool flag6 = this.IsPoiUnlocked(pointOfInterest);
                        if (pointOfInterest.CreepingNodeImprovement == null && (!(pointOfInterest.Type != "Village") || pointOfInterest.PointOfInterestImprovement == null) && ((this.worldPositionningService.GetExplorationBits(pointOfInterest.WorldPosition) & base.AIEntity.Empire.Bits) > 0 && flag6))
                        {
                            foreach (CreepingNodeImprovementDefinition creepingNodeImprovementDefinition in values)
                            {
                                if (creepingNodeImprovementDefinition.PointOfInterestTemplateName == pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplateName && (!(pointOfInterest.Type == "Village") || (pointOfInterest.SimulationObject.Tags.Contains(Village.PacifiedVillage) && !pointOfInterest.SimulationObject.Tags.Contains(Village.ConvertedVillage))))
                                {
                                    list2.Clear();
                                    DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.aiEntityCity.City, creepingNodeImprovementDefinition, ref list2, new string[]
                                    {
                                        ConstructionFlags.Prerequisite
                                    });
                                    if (!list2.Contains(ConstructionFlags.Discard) && this.departmentOfTheTreasury.CheckConstructibleInstantCosts(this.aiEntityCity.City, creepingNodeImprovementDefinition))
                                    {
                                        CreepingNodeImprovementDefinition          bestCreepingNodeDefinition = this.departmentOfCreepingNodes.GetBestCreepingNodeDefinition(this.aiEntityCity.City, pointOfInterest, creepingNodeImprovementDefinition, list2);
                                        AILayer_CreepingNode.EvaluableCreepingNode item = new AILayer_CreepingNode.EvaluableCreepingNode(pointOfInterest, bestCreepingNodeDefinition);
                                        if (!list.Contains(item))
                                        {
                                            list.Add(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return(list);
    }
Пример #4
0
    private void ScoreRuinsNodes()
    {
        List <int> list = new List <int>();

        for (int i = 0; i < this.availableNodes.Count; i++)
        {
            AILayer_CreepingNode.EvaluableCreepingNode evaluableCreepingNode = this.availableNodes[i];
            if (evaluableCreepingNode.pointOfInterest.Type.Equals(ELCPUtilities.QuestLocation))
            {
                Region            region           = this.worldPositionningService.GetRegion(evaluableCreepingNode.pointOfInterest.WorldPosition);
                PointOfInterest[] pointOfInterests = region.PointOfInterests;
                bool flag = false;
                if (list.Contains(region.Index))
                {
                    flag = true;
                }
                else
                {
                    list.Add(region.Index);
                }
                if (!flag)
                {
                    for (int j = 0; j < this.departmentOfCreepingNodes.Nodes.Count; j++)
                    {
                        if (region.Index == this.departmentOfCreepingNodes.Nodes[j].Region.Index)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    evaluableCreepingNode.score = AILayer.Boost(evaluableCreepingNode.score, -0.9f);
                }
                else
                {
                    evaluableCreepingNode.score = AILayer.Boost(evaluableCreepingNode.score, this.RuinsWeight);
                }
            }
        }
    }
Пример #5
0
    private void ScoreWatchtowerNodes()
    {
        City[]       knownCities = this.GetKnownCities(false);
        List <float> list        = new List <float>();

        for (int i = 0; i < this.availableNodes.Count; i++)
        {
            AILayer_CreepingNode.EvaluableCreepingNode evaluableCreepingNode = this.availableNodes[i];
            if (evaluableCreepingNode.pointOfInterest.Type != "WatchTower")
            {
                list.Add(0f);
            }
            else
            {
                float num  = float.MaxValue;
                int   num2 = 0;
                for (int j = 0; j < knownCities.Length; j++)
                {
                    City  city = knownCities[j];
                    float num3 = (float)this.worldPositionningService.GetDistance(evaluableCreepingNode.pointOfInterest.WorldPosition, city.WorldPosition);
                    if (num3 < num)
                    {
                        num  = num3;
                        num2 = j;
                    }
                }
                float num4 = 0f;
                if (knownCities.Length != 0)
                {
                    num4 = 1f / num;
                    DiplomaticRelation diplomaticRelation = knownCities[num2].Empire.GetAgency <DepartmentOfForeignAffairs>().GetDiplomaticRelation(base.AIEntity.Empire);
                    if (diplomaticRelation != null)
                    {
                        string a = diplomaticRelation.State.Name;
                        if (!(a == "DiplomaticRelationStateWar"))
                        {
                            if (!(a == "DiplomaticRelationStateTruce"))
                            {
                                if (!(a == "DiplomaticRelationStateColdWar"))
                                {
                                    if (!(a == "DiplomaticRelationStatePeace"))
                                    {
                                        if (!(a == "DiplomaticRelationStateAlliance"))
                                        {
                                            num4 *= 0f;
                                        }
                                        else
                                        {
                                            num4 *= this.TowerMultiplierForAlliance;
                                        }
                                    }
                                    else
                                    {
                                        num4 *= this.TowerMultiplierForPeace;
                                    }
                                }
                                else
                                {
                                    num4 *= this.TowerMultiplierForColdWar;
                                }
                            }
                            else
                            {
                                num4 *= this.TowerMultiplierForTruce;
                            }
                        }
                        else
                        {
                            num4 *= this.TowerMultiplierForWar;
                        }
                    }
                }
                list.Add(num4);
            }
        }
        if (list.Count > 0)
        {
            float num5 = list.Min();
            float num6 = list.Max();
            for (int k = 0; k < list.Count; k++)
            {
                if (!(this.availableNodes[k].pointOfInterest.Type != "WatchTower"))
                {
                    float num7        = (num5 == num6) ? this.NormalizationFailSafeValue : Mathf.InverseLerp(num5, num6, list[k]);
                    float score       = this.availableNodes[k].score;
                    float boostFactor = num7 * this.TowersWeight;
                    this.availableNodes[k].score = AILayer.Boost(score, boostFactor);
                }
            }
        }
    }
Пример #6
0
    private void ComputeScoresByDistance()
    {
        City[] knownCities = this.GetKnownCities(true);
        Dictionary <AILayer_CreepingNode.EvaluableCreepingNode, float> dictionary = new Dictionary <AILayer_CreepingNode.EvaluableCreepingNode, float>();
        double num  = Math.Pow((double)this.worldPositionningService.World.WorldParameters.Columns, 2.0);
        double num2 = Math.Pow((double)this.worldPositionningService.World.WorldParameters.Rows, 2.0);
        float  num3 = (float)Math.Sqrt(num + num2);
        float  num4 = 1f;
        float  num5 = 0f;

        for (int i = 0; i < this.availableNodes.Count; i++)
        {
            AILayer_CreepingNode.EvaluableCreepingNode evaluableCreepingNode = this.availableNodes[i];
            float num6 = num3;
            float num7 = num3;
            foreach (City city in knownCities)
            {
                float num8 = (float)this.worldPositionningService.GetDistance(evaluableCreepingNode.pointOfInterest.WorldPosition, city.WorldPosition);
                if (city.Empire.Index == base.AIEntity.Empire.Index)
                {
                    if (num8 < num6)
                    {
                        num6 = num8;
                    }
                }
                else if (num8 < num7)
                {
                    num7 = num8;
                }
            }
            if (num6 <= 0f || num7 <= 0f)
            {
                dictionary.Add(evaluableCreepingNode, 0f);
            }
            else
            {
                float num9  = num6 + num7;
                float num10 = num7 / num9;
                if (num10 < num4)
                {
                    num4 = num10;
                }
                if (num10 > num5)
                {
                    num5 = num10;
                }
                float value = num10 * num7 * evaluableCreepingNode.nodeDefinition.AIPreferences.ScoringByDistanceMultiplier;
                dictionary.Add(evaluableCreepingNode, value);
            }
        }
        float num11 = float.MaxValue;
        float num12 = float.MinValue;

        foreach (float num13 in dictionary.Values)
        {
            float num14 = num13;
            if (num14 < num11)
            {
                num11 = num14;
            }
            if (num14 > num12)
            {
                num12 = num14;
            }
        }
        float num15 = num5 - num4;

        for (int k = 0; k < this.availableNodes.Count; k++)
        {
            AILayer_CreepingNode.EvaluableCreepingNode evaluableCreepingNode2 = this.availableNodes[k];
            float value2 = dictionary[evaluableCreepingNode2];
            float num16  = (num11 == num12) ? this.NormalizationFailSafeValue : Mathf.InverseLerp(num11, num12, value2);
            evaluableCreepingNode2.score = AILayer.Boost(evaluableCreepingNode2.score, num16 * num15 * this.DistanceWeight);
        }
    }
Пример #7
0
    private void ComputeScoresByResource()
    {
        Dictionary <StaticString, int> dictionary            = new Dictionary <StaticString, int>();
        IEnumerable <EvaluableMessage_ResourceNeed> messages = base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_ResourceNeed>(BlackboardLayerID.Empire, (EvaluableMessage_ResourceNeed match) => match.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending || match.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate);

        if (messages.Any <EvaluableMessage_ResourceNeed>())
        {
            foreach (EvaluableMessage_ResourceNeed evaluableMessage_ResourceNeed in messages)
            {
                if (evaluableMessage_ResourceNeed.MissingResources != null)
                {
                    foreach (MissingResource missingResource in evaluableMessage_ResourceNeed.MissingResources)
                    {
                        if (dictionary.ContainsKey(missingResource.ResourceName))
                        {
                            Dictionary <StaticString, int> dictionary2 = dictionary;
                            StaticString resourceName;
                            int          num = dictionary2[resourceName = missingResource.ResourceName];
                            dictionary2[resourceName] = num + 1;
                        }
                        else
                        {
                            dictionary.Add(missingResource.ResourceName, 1);
                        }
                    }
                }
            }
        }
        List <float> list = new List <float>();
        int          i    = 0;

        while (i < this.availableNodes.Count)
        {
            AILayer_CreepingNode.EvaluableCreepingNode evaluableCreepingNode = this.availableNodes[i];
            PointOfInterest pointOfInterest = evaluableCreepingNode.pointOfInterest;
            CreepingNodeImprovementDefinition nodeDefinition = evaluableCreepingNode.nodeDefinition;
            float num2 = 0f;
            if (!(pointOfInterest.Type == "ResourceDeposit"))
            {
                goto IL_184;
            }
            string x;
            if (pointOfInterest.PointOfInterestDefinition.TryGetValue("ResourceName", out x))
            {
                num2 = 0.5f;
                if (dictionary.ContainsKey(x))
                {
                    num2 = Mathf.Max(num2, (float)dictionary[x]);
                    goto IL_184;
                }
                goto IL_184;
            }
IL_17E:
            i++;
            continue;
IL_184:
            list.Add(num2);
            goto IL_17E;
        }
        if (list.Count > 0)
        {
            float num3 = list.Min();
            float num4 = list.Max();
            for (int j = 0; j < list.Count; j++)
            {
                if (!(this.availableNodes[j].pointOfInterest.Type != "ResourceDeposit"))
                {
                    float num5        = (num3 == num4) ? this.NormalizationFailSafeValue : Mathf.InverseLerp(num3, num4, list[j]);
                    float score       = this.availableNodes[j].score;
                    float boostFactor = num5 * this.ResourceWeight;
                    this.availableNodes[j].score = AILayer.Boost(score, boostFactor);
                }
            }
        }
    }