コード例 #1
0
    private void GeneratePopulationBuyoutMessage()
    {
        if (!DepartmentOfTheInterior.CanBuyoutPopulation(this.aiEntityCity.City))
        {
            return;
        }
        this.GeneratePopulationBuyoutMessage_ELCPGlobalPopulationInfo();
        List <EvaluableMessage_PopulationBuyout> list = new List <EvaluableMessage_PopulationBuyout>(this.aiEntityCity.Blackboard.GetMessages <EvaluableMessage_PopulationBuyout>(BlackboardLayerID.City, (EvaluableMessage_PopulationBuyout message) => message.CityGuid == this.aiEntityCity.City.GUID && message.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained && message.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel));
        EvaluableMessage_PopulationBuyout        evaluableMessage_PopulationBuyout;

        if (list.Count == 0)
        {
            evaluableMessage_PopulationBuyout = new EvaluableMessage_PopulationBuyout(this.aiEntityCity.City.GUID, 1, AILayer_AccountManager.EconomyAccountName);
            this.aiEntityCity.Blackboard.AddMessage(evaluableMessage_PopulationBuyout);
        }
        else
        {
            evaluableMessage_PopulationBuyout = list[0];
        }
        float num = 0f;

        for (int i = 0; i < AILayer_Population.GainPerPopulation.Length; i++)
        {
            num += this.aiEntityCity.City.GetPropertyValue(AILayer_Population.GainPerPopulation[i]);
        }
        float num2          = num / AILayer_Population.GlobalPopulationInfos[this.Empire.Index].bestGainPerPop * 0.5f;
        float propertyValue = this.aiEntityCity.City.GetPropertyValue(SimulationProperties.Population);

        if (propertyValue == AILayer_Population.GlobalPopulationInfos[this.Empire.Index].lowestPopulation)
        {
            num2 = AILayer.Boost(num2, 0.2f);
        }
        float populationBuyOutCost = DepartmentOfTheTreasury.GetPopulationBuyOutCost(this.aiEntityCity.City);
        float num3;

        if (!this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpireMoney, out num3, false))
        {
            num3 = 1f;
        }
        float num4 = (num3 - populationBuyOutCost) / num3 / 0.8f;

        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            num4 -= 0.05f;
        }
        num2 = AILayer.Boost(num2, num4);
        ConstructionQueue constructionQueue = this.departmentOfIndustry.GetConstructionQueue(this.aiEntityCity.City);

        if (propertyValue > 1f)
        {
            for (int j = constructionQueue.Length - 1; j >= 0; j--)
            {
                if (constructionQueue.PeekAt(j).ConstructibleElementName.ToString().Contains("Settler"))
                {
                    num2 = AILayer.Boost(num2, -1f);
                    break;
                }
            }
        }
        Diagnostics.Log("ELCP {0}/{1} GeneratePopulationBuyoutMessage score: {2}, cost: {3}", new object[]
        {
            this.Empire,
            this.aiEntityCity.City.LocalizedName,
            num2,
            populationBuyOutCost
        });
        evaluableMessage_PopulationBuyout.Refresh(1f, num2, populationBuyOutCost, int.MaxValue);
    }