Exemplo n.º 1
0
    private void OrderAssignPopulation_TicketRaised(object sender, TicketRaisedEventArgs e)
    {
        for (int i = 0; i < AILayer_Population.PopulationResource.Length; i++)
        {
            this.resourceScore[i] = this.aiEntityCity.City.GetPropertyValue(AILayer_Population.PopulationResource[i]);
        }
        float propertyValue = this.aiEntityCity.City.GetPropertyValue(SimulationProperties.NetCityGrowth);

        if (propertyValue < 0f)
        {
            float propertyValue2 = this.aiEntityCity.City.GetPropertyValue(SimulationProperties.Population);
            float num            = DepartmentOfTheInterior.ComputeGrowthLimit(this.Empire.SimulationObject, propertyValue2);
            if (this.aiEntityCity.City.GetPropertyValue(SimulationProperties.CityGrowthStock) + propertyValue < num)
            {
                foreach (int num2 in AILayer_Population.NonFoodPopPriority)
                {
                    if (this.resourceScore[num2] >= 1f)
                    {
                        this.resourceScore[num2]       -= 1f;
                        this.resourceScore[0]          += 1f;
                        this.assignedPopulationThisTurn = false;
                        AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>().RegisterSynchronousJob(new SynchronousJob(this.SynchronousJob_AssignPopulation));
                        return;
                    }
                }
            }
        }
        this.assignedPopulationThisTurn = true;
    }
Exemplo n.º 2
0
 private void RemoveSettlerResponse(object sender, TicketRaisedEventArgs args)
 {
     if (args.Result == PostOrderResponse.Processed)
     {
         City  city           = this.departmentOfTheInterior.Cities[this.cityWithRemovedSettlerIndex];
         float propertyValue  = city.GetPropertyValue(SimulationProperties.Population);
         float propertyValue2 = city.GetPropertyValue(SimulationProperties.CityGrowthStock);
         float num            = DepartmentOfTheInterior.ComputeGrowthLimit(city.Empire.SimulationObject, propertyValue);
         float num2           = DepartmentOfTheInterior.ComputeGrowthLimit(city.Empire.SimulationObject, propertyValue + 1f);
         float num3           = propertyValue2 / num;
         num3  = num2 * num3;
         num3 -= propertyValue2;
         if (num3 > 0f)
         {
             Diagnostics.Log("ELCP {0} Disbanded Settler in {1}, tranfering {2} food ({3} -> {4})", new object[]
             {
                 city.Empire,
                 city.LocalizedName,
                 num3,
                 propertyValue2,
                 propertyValue2 + num3
             });
             OrderTransferResources order = new OrderTransferResources(base.AIEntity.Empire.Index, DepartmentOfTheTreasury.Resources.CityGrowth, num3, city.GUID);
             base.AIEntity.Empire.PlayerControllers.AI.PostOrder(order);
         }
     }
     this.cityWithRemovedSettlerIndex = -1;
 }
Exemplo n.º 3
0
    private void ComputeCostalBoost()
    {
        DepartmentOfTheInterior agency = base.Empire.GetAgency <DepartmentOfTheInterior>();

        this.costalCityCount = 0;
        for (int i = 0; i < agency.Cities.Count; i++)
        {
            if (agency.Cities[i].Districts.Any((District match) => this.worldPositionningService.IsWaterTile(match.WorldPosition)))
            {
                this.costalCityCount++;
            }
        }
        this.costalColonizationBoost.Reset();
        if (this.costalCityCount < 3)
        {
            int            num            = 3;
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)agency.Cities.Count, "City count", new object[0]);
            heuristicValue.Subtract((float)(this.costalCityCount * num), "Costal city * {0}", new object[]
            {
                num
            });
            heuristicValue.Divide((float)num, "Costal gap", new object[0]);
            heuristicValue.Clamp(0.1f, 1f);
            heuristicValue.Multiply(this.costalCityRatioMaxBoost, "Factor from xml", new object[0]);
            this.costalColonizationBoost.Boost(heuristicValue, "Costal city ratio boost", new object[0]);
        }
        if (base.Empire.SimulationObject.Tags.Contains(DownloadableContent16.AffinitySeaDemons))
        {
            this.costalColonizationBoost.Boost(0.1f, "Sea demons", new object[0]);
        }
    }
Exemplo n.º 4
0
	public void UnconvertAndPacifyAllConvertedVillages()
	{
		for (int i = this.ConvertedVillages.Count - 1; i >= 0; i--)
		{
			Village village = this.ConvertedVillages[i];
			if (village != null && village.Region != null)
			{
				BarbarianCouncil agency = village.Region.MinorEmpire.GetAgency<BarbarianCouncil>();
				if (agency != null)
				{
					agency.PacifyVillage(village, null);
				}
				DepartmentOfTheInterior agency2 = base.GetAgency<DepartmentOfTheInterior>();
				Diagnostics.Assert(agency2 != null);
				if (village.Region.City != null && agency2 != null && agency2.MainCity != village.Region.City)
				{
					DepartmentOfTheInterior agency3 = village.Region.City.Empire.GetAgency<DepartmentOfTheInterior>();
					Diagnostics.Assert(agency3 != null);
					agency3.BindMinorFactionToCity(village.Region.City, village.Region.MinorEmpire);
					agency3.VerifyOverallPopulation(village.Region.City);
				}
				else
				{
					agency2.UnbindConvertedVillage(village);
				}
			}
		}
	}
Exemplo n.º 5
0
    public void AddConvertVillageOnLoad(Village village, MajorEmpire converter)
    {
        if (converter == null)
        {
            throw new ArgumentNullException("converter");
        }
        SimulationDescriptor value = this.SimulationDescriptorDatabase.GetValue(BarbarianCouncil.VillageStatusConverted);

        village.SwapDescriptor(value);
        if (!village.HasBeenConverted)
        {
            if (village.HasBeenPacified)
            {
                village.HasBeenPacified = false;
            }
            SimulationDescriptor value2 = this.SimulationDescriptorDatabase.GetValue(Village.ConvertedVillage);
            if (value2 != null)
            {
                Diagnostics.Assert(village.PointOfInterest != null);
                village.PointOfInterest.SwapDescriptor(value2);
                village.SwapDescriptor(value2);
            }
            village.Converter = converter;
            if (village.Converter.ConvertedVillages != null && village.Converter.ConvertedVillages.Contains(village))
            {
                village.Converter.AddChild(village);
            }
            DepartmentOfTheInterior.GenerateFIMSEForConvertedVillage(village.Converter, village.PointOfInterest);
        }
    }
 private bool AskForArmy(int numberOfUnits)
 {
     if (!base.AIDataArmyGUID.IsValid && numberOfUnits > 0 && this.armySpawnTicket == null)
     {
         PathfindingContext pathfindingContext = new PathfindingContext(this.Camp.City.GUID, this.Camp.City.Empire, this.Camp.City.StandardUnits);
         WorldPosition      armyPosition;
         if (!DepartmentOfTheInterior.TryGetWorldPositionForNewArmyFromCity(this.Camp.City, this.pathfindingService, pathfindingContext, out armyPosition))
         {
             return(false);
         }
         if (this.Camp.City.StandardUnits.Count == 0)
         {
             return(false);
         }
         numberOfUnits = Mathf.Min(this.Camp.City.StandardUnits.Count, numberOfUnits);
         if (numberOfUnits > 0)
         {
             GameEntityGUID[] array = new GameEntityGUID[numberOfUnits];
             for (int i = 0; i < numberOfUnits; i++)
             {
                 array[i] = this.Camp.City.StandardUnits[i].GUID;
             }
             OrderTransferGarrisonToNewArmy order = new OrderTransferGarrisonToNewArmy(base.Commander.Empire.Index, this.Camp.City.GUID, array, armyPosition, null, false, true, true);
             base.Commander.Empire.PlayerControllers.AI.PostOrder(order, out this.armySpawnTicket, null);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
    private void RefreshPopulationGrowth()
    {
        float propertyValue            = this.City.GetPropertyValue(SimulationProperties.Population);
        float propertyValue2           = this.City.GetPropertyValue(SimulationProperties.CityGrowthStock);
        float propertyValue3           = this.City.GetPropertyValue(SimulationProperties.NetCityGrowth);
        DepartmentOfTheInterior agency = this.City.Empire.GetAgency <DepartmentOfTheInterior>();
        float num;
        float num2;

        agency.GetGrowthLimits(propertyValue, out num, out num2);
        this.GaugePopulation.PercentRight = Mathf.Clamp((propertyValue2 - num) / (num2 - num) * 100f, 0f, 100f);
        float num3 = Mathf.Round(100f * propertyValue3 / (num2 - num));

        if (num3 > 0f)
        {
            this.GaugeProgress.Visible = true;
            this.GaugeProgress.GetComponent <AgePrimitiveImage>().TintColor = this.GrowingPopulationColor;
            this.GaugeProgress.PercentLeft  = this.GaugePopulation.PercentRight;
            this.GaugeProgress.PercentRight = Mathf.Min(100f, this.GaugeProgress.PercentLeft + num3);
            this.NextPopulationTurns.Text   = GuiFormater.FormatGui((float)Mathf.Max(1, Mathf.CeilToInt((num2 - propertyValue2) / propertyValue3)), false, true, false, 1);
        }
        else if (num3 < 0f)
        {
            this.GaugeProgress.Visible = true;
            this.GaugeProgress.GetComponent <AgePrimitiveImage>().TintColor = this.LosingPopulationColor;
            this.GaugeProgress.PercentRight = this.GaugePopulation.PercentRight;
            this.GaugeProgress.PercentLeft  = Mathf.Max(0f, this.GaugeProgress.PercentRight + num3);
            this.NextPopulationTurns.Text   = GuiFormater.FormatGui((float)Mathf.Max(1, Mathf.CeilToInt((propertyValue2 - num) / -propertyValue3)), false, true, false, 1);
        }
        else
        {
            this.GaugeProgress.Visible    = false;
            this.NextPopulationTurns.Text = "-";
        }
    }
    protected override int GetNeededAvailabilityTime()
    {
        float num           = -DepartmentOfTheInterior.GetBesiegingPower(this.RegionWithCityToFree.City, true);
        float propertyValue = this.RegionWithCityToFree.City.GetPropertyValue(SimulationProperties.CityDefensePoint);

        return((int)Math.Floor((double)(propertyValue / num)));
    }
Exemplo n.º 9
0
    internal virtual void OnEmpireEliminated(global::Empire empire, bool authorized)
    {
        DepartmentOfDefense agency = base.GetAgency <DepartmentOfDefense>();

        if (agency != null)
        {
            agency.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfEducation agency2 = base.GetAgency <DepartmentOfEducation>();

        if (agency2 != null)
        {
            agency2.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheInterior agency3 = base.GetAgency <DepartmentOfTheInterior>();

        if (agency3 != null)
        {
            agency3.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfCreepingNodes agency4 = base.GetAgency <DepartmentOfCreepingNodes>();

        if (agency4 != null)
        {
            agency4.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheTreasury agency5 = base.GetAgency <DepartmentOfTheTreasury>();

        if (agency5 != null)
        {
            agency5.OnEmpireEliminated(empire, authorized);
        }
    }
Exemplo n.º 10
0
    public override void GatherAuctionItems(Empire empire)
    {
        base.GatherAuctionItems(empire);
        DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.Armies.Count; i++)
        {
            for (int j = 0; j < agency.Armies[i].StandardUnits.Count; j++)
            {
                if (this.CanSellUnit(agency.Armies[i].StandardUnits[j]))
                {
                    float score = this.ComputeUnitScore(agency.Armies[i].StandardUnits[j]);
                    base.AuctionItems.Add(new AuctionItem_GameEntity(agency.Armies[i].StandardUnits[j], score));
                }
            }
        }
        DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();

        for (int k = 0; k < agency2.Cities.Count; k++)
        {
            for (int l = 0; l < agency2.Cities[k].StandardUnits.Count; l++)
            {
                if (this.CanSellUnit(agency2.Cities[k].StandardUnits[l]))
                {
                    float score2 = this.ComputeUnitScore(agency2.Cities[k].StandardUnits[l]);
                    base.AuctionItems.Add(new AuctionItem_GameEntity(agency2.Cities[k].StandardUnits[l], score2));
                }
            }
        }
    }
Exemplo n.º 11
0
 protected override bool TryComputeArmyMissionParameter()
 {
     this.besiegers = null;
     if (this.City.BesiegingEmpire != null)
     {
         this.besiegers = DepartmentOfTheInterior.GetBesiegers(this.City);
         if (this.besiegers.Length == 0)
         {
             return(false);
         }
         float    num      = 0f;
         float    num2     = 0f;
         Garrison defender = this.besiegers[0];
         this.intelligenceAiHelper.EstimateMPInBattleground(this.City, defender, ref num, ref num2);
         if (num > num2)
         {
             return(this.AskForArmy(true));
         }
         float propertyValue  = this.City.GetPropertyValue(SimulationProperties.CityDefensePoint);
         float besiegingPower = DepartmentOfTheInterior.GetBesiegingPower(this.City, true);
         if (propertyValue <= besiegingPower)
         {
             return(this.AskForArmy(true));
         }
     }
     else
     {
         if (base.AIDataArmyGUID.IsValid)
         {
             return(this.DisbandArmy());
         }
         base.Completion = AICommanderMission.AICommanderMissionCompletion.Success;
     }
     return(false);
 }
Exemplo n.º 12
0
    private void ExecutePopulationBuyout()
    {
        if (!DepartmentOfTheInterior.CanBuyoutPopulation(this.aiEntityCity.City))
        {
            return;
        }
        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));

        if (list.Count == 0)
        {
            return;
        }
        if (list.Count > 1)
        {
            AILayer.LogWarning("There should not be several PopulationBuyout EvaluableMessages for the same city ({0})", new object[]
            {
                this.aiEntityCity.City
            });
        }
        EvaluableMessage_PopulationBuyout evaluableMessage_PopulationBuyout = list[0];

        Diagnostics.Log("ELCP {0}/{1} ExecutePopulationBuyout {2}", new object[]
        {
            this.Empire,
            this.aiEntityCity.City,
            evaluableMessage_PopulationBuyout.EvaluationState
        });
        if (evaluableMessage_PopulationBuyout.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate)
        {
            AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>().RegisterSynchronousJob(new SynchronousJob(this.SynchronousJob_BuyoutPopulation));
        }
    }
Exemplo n.º 13
0
 public void Configure(string mode)
 {
     if (mode == EmpireBannerPanel.Full)
     {
         base.AgeTransform.Height              = this.maxHeight;
         this.EmpireTreasuryPanel.Visible      = true;
         this.EmpireResearchPanel.Visible      = true;
         this.EmpirePointsPanel.Visible        = true;
         this.EmpireLavapoolStockPanel.Visible = DepartmentOfTheInterior.CanPerformLavaformation(base.Empire);
         this.ResourceEnumerator.Show(new object[0]);
     }
     else if (mode == EmpireBannerPanel.TreasuryResearch)
     {
         base.AgeTransform.Height              = this.maxHeight * 0.5f;
         this.EmpireTreasuryPanel.Visible      = true;
         this.EmpireResearchPanel.Visible      = true;
         this.EmpirePointsPanel.Visible        = true;
         this.EmpireLavapoolStockPanel.Visible = DepartmentOfTheInterior.CanPerformLavaformation(base.Empire);
         this.ResourceEnumerator.Hide(false);
     }
     else if (mode == EmpireBannerPanel.Strategic)
     {
         base.AgeTransform.Height              = this.maxHeight * 0.5f;
         this.EmpireTreasuryPanel.Visible      = false;
         this.EmpireResearchPanel.Visible      = false;
         this.EmpirePointsPanel.Visible        = false;
         this.EmpireLavapoolStockPanel.Visible = false;
         this.ResourceEnumerator.Show(new object[0]);
     }
 }
Exemplo n.º 14
0
    private float GetWonderProgress(MajorEmpire empire)
    {
        DepartmentOfTheInterior agency  = empire.GetAgency <DepartmentOfTheInterior>();
        DepartmentOfIndustry    agency2 = empire.GetAgency <DepartmentOfIndustry>();
        float num = 0f;

        for (int i = 0; i < agency.Cities.Count; i++)
        {
            Construction construction = agency2.GetConstructionQueue(agency.Cities[i]).Get((Construction x) => x.ConstructibleElement.SubCategory == "SubCategoryVictory");
            if (construction != null)
            {
                for (int j = 0; j < construction.CurrentConstructionStock.Length; j++)
                {
                    if (construction.CurrentConstructionStock[j].PropertyName == "Production")
                    {
                        float stock = construction.CurrentConstructionStock[j].Stock;
                        if (stock > 0f)
                        {
                            float num2 = stock / DepartmentOfTheTreasury.GetProductionCostWithBonus(agency.Cities[i], construction.ConstructibleElement, "Production");
                            if (num2 > num)
                            {
                                num = num2;
                            }
                        }
                    }
                }
            }
        }
        return(num);
    }
Exemplo n.º 15
0
    private City[] GetKnownCities(bool includeOwnCities = true)
    {
        List <City>  list = new List <City>();
        global::Game game = this.gameService.Game as global::Game;

        if (game != null)
        {
            for (int i = 0; i < game.Empires.Length; i++)
            {
                if (game.Empires[i] is MajorEmpire)
                {
                    if (includeOwnCities || game.Empires[i].Index != base.AIEntity.Empire.Index)
                    {
                        DepartmentOfTheInterior agency = game.Empires[i].GetAgency <DepartmentOfTheInterior>();
                        if (agency != null && agency.Cities != null)
                        {
                            for (int j = 0; j < agency.Cities.Count; j++)
                            {
                                if (this.visibilityService.IsWorldPositionExploredFor(agency.Cities[j].WorldPosition, base.AIEntity.Empire))
                                {
                                    list.Add(agency.Cities[j]);
                                }
                            }
                        }
                    }
                }
            }
        }
        return(list.ToArray());
    }
Exemplo n.º 16
0
    public void RefreshTerrainDescriptors()
    {
        if (base.SimulationObject == null)
        {
            return;
        }
        IWorldPositionningService service = ((global::Game)Services.GetService <IGameService>().Game).GetService <IWorldPositionningService>();

        DepartmentOfTheInterior.RemoveAnyTerrainTypeDescriptor(base.SimulationObject);
        DepartmentOfTheInterior.RemoveAnyBiomeTypeDescriptor(base.SimulationObject);
        DepartmentOfTheInterior.RemoveAnyAnomalyDescriptor(base.SimulationObject);
        DepartmentOfTheInterior.RemoveAnyRiverTypeDescriptor(base.SimulationObject);
        byte         terrainType            = service.GetTerrainType(this.WorldPosition);
        StaticString terrainTypeMappingName = service.GetTerrainTypeMappingName(terrainType);

        DepartmentOfTheInterior.ApplyTerrainTypeDescriptor(base.SimulationObject, terrainTypeMappingName);
        byte         biomeType            = service.GetBiomeType(this.WorldPosition);
        StaticString biomeTypeMappingName = service.GetBiomeTypeMappingName(biomeType);

        DepartmentOfTheInterior.ApplyBiomeTypeDescriptor(base.SimulationObject, biomeTypeMappingName);
        byte         anomalyType            = service.GetAnomalyType(this.WorldPosition);
        StaticString anomalyTypeMappingName = service.GetAnomalyTypeMappingName(anomalyType);

        DepartmentOfTheInterior.ApplyAnomalyDescriptor(base.SimulationObject, anomalyTypeMappingName);
        short        riverId = service.GetRiverId(this.WorldPosition);
        StaticString riverTypeMappingName = service.GetRiverTypeMappingName(riverId);

        DepartmentOfTheInterior.ApplyRiverTypeDescriptor(base.SimulationObject, riverTypeMappingName);
        this.Refresh(false);
    }
Exemplo n.º 17
0
    private static float UtilityFunc_EmpirePillageDefense(SeasonEffect aiEvaluableElement, InterpreterContext context, float aiParameterValue, AIHeuristicAnalyser.Context debugContext)
    {
        global::Empire empire = context.Get("Empire") as global::Empire;

        Diagnostics.Assert(empire != null);
        DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>();

        Diagnostics.Assert(agency != null);
        int   num   = 0;
        float num2  = 0f;
        int   count = agency.Cities.Count;

        for (int i = 0; i < count; i++)
        {
            for (int j = 0; j < agency.Cities[i].Region.PointOfInterests.Length; j++)
            {
                float propertyValue = agency.Cities[i].Region.PointOfInterests[j].GetPropertyValue(SimulationProperties.MaximumPillageDefense);
                num2 += propertyValue;
                num++;
            }
        }
        float b = num2 / (float)num;

        return(aiParameterValue / Mathf.Max(1f, b));
    }
Exemplo n.º 18
0
    private static float UtilityFunc_EmpireLuxury(SeasonEffect aiEvaluableElement, InterpreterContext context, float aiParameterValue, AIHeuristicAnalyser.Context debugContext)
    {
        global::Empire empire = context.Get("Empire") as global::Empire;

        Diagnostics.Assert(empire != null);
        DepartmentOfScience     agency  = empire.GetAgency <DepartmentOfScience>();
        DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();
        float num;
        float num2;

        AILayer_Altar.GetResourceUnitMarketPrice(empire, out num, out num2);
        float b = 0f;

        if (agency.GetTechnologyState(TechnologyDefinition.Names.MarketplaceResources) == DepartmentOfScience.ConstructibleElement.State.Researched)
        {
            float propertyValue = empire.GetPropertyValue(SimulationProperties.NetEmpireMoney);
            b = num2 / Mathf.Max(propertyValue, 1f);
        }
        float technologyUnlockedCount = agency.GetTechnologyUnlockedCount();
        float a    = (float)agency2.Cities.Count;
        float a2   = technologyUnlockedCount / (15f * Mathf.Max(a, 1f));
        float num3 = Mathf.Max(a2, b);

        return(aiParameterValue * num3);
    }
Exemplo n.º 19
0
    private void FillDecisionMakerVariables()
    {
        if (this.decisionMaker.Context == null)
        {
            return;
        }
        this.decisionMaker.Context.Register("GlobalWarNeed", this.aiLayerDiplomacy.GetGlobalWarNeed());
        this.decisionMaker.Context.Register("IndustryReferenceTurnCount", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.IndustryReferenceTurnCount));
        this.decisionMaker.Context.Register("TechnologyReferenceTurnCount", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.TechnologyReferenceTurnCount));
        this.decisionMaker.Context.Register("MoneyReferenceRatio", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.MoneyReferenceRatio));
        int num  = this.departmentOfScience.CurrentTechnologyEraNumber - 1;
        int num2 = 0;
        int num3 = 0;

        foreach (DepartmentOfScience.ConstructibleElement constructibleElement in this.departmentOfScience.TechnologyDatabase)
        {
            TechnologyDefinition technologyDefinition = constructibleElement as TechnologyDefinition;
            if (technologyDefinition != null)
            {
                int technologyEraNumber = DepartmentOfScience.GetTechnologyEraNumber(technologyDefinition);
                DepartmentOfScience.ConstructibleElement.State technologyState = this.departmentOfScience.GetTechnologyState(constructibleElement);
                if (technologyState == DepartmentOfScience.ConstructibleElement.State.Available)
                {
                    num3++;
                    if (technologyEraNumber < num)
                    {
                        num2++;
                    }
                }
            }
        }
        float num4 = 0f;

        if (num3 > 0)
        {
            num4 = (float)num2 / (float)num3;
        }
        this.decisionMaker.Context.Register("OldTechnologyRatio", num4);
        AILayer_Strategy layer      = base.AIEntity.GetLayer <AILayer_Strategy>();
        float            agentValue = layer.StrategicNetwork.GetAgentValue("Expansion");

        this.decisionMaker.Context.Register("ColonizationPriority", agentValue);
        DepartmentOfTheInterior agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();
        float num5 = 0f;

        if (agency.Cities.Count > 0)
        {
            for (int i = 0; i < agency.Cities.Count; i++)
            {
                AgentGroup cityAgentGroup = this.aiLayerResourceAmas.GetCityAgentGroup(agency.Cities[i]);
                if (cityAgentGroup != null)
                {
                    num5 += cityAgentGroup.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.PopulationReferenceTurnCount);
                }
            }
            num5 /= (float)agency.Cities.Count;
        }
        this.decisionMaker.Context.Register("PopulationReferenceTurnCount", num5);
    }
Exemplo n.º 20
0
 protected override void EvaluateNeeds(StaticString context, StaticString pass)
 {
     base.EvaluateNeeds(context, pass);
     foreach (EvaluableMessage_Assimilation evaluableMessage_Assimilation in base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_Assimilation>(BlackboardLayerID.Empire, (EvaluableMessage_Assimilation match) => match.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending || match.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate))
     {
         evaluableMessage_Assimilation.UpdateBuyEvaluation("Assimilation", 0UL, DepartmentOfTheInterior.GetAssimilationCost(this.Empire, 0), 2, 0f, 0UL);
     }
 }
Exemplo n.º 21
0
    public override void Deactivate()
    {
        base.Deactivate();
        WorldCircle  worldCircle = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range);
        List <short> list        = new List <short>();

        WorldPosition[] worldPositions = worldCircle.GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters);
        for (int i = 0; i < worldPositions.Length; i++)
        {
            short regionIndex = base.WorldEffectManager.WorldPositionningService.GetRegionIndex(worldPositions[i]);
            if (!list.Contains(regionIndex))
            {
                Region region = base.WorldEffectManager.WorldPositionningService.GetRegion(worldPositions[i]);
                if (region.City != null)
                {
                    for (int j = 0; j < region.City.Districts.Count; j++)
                    {
                        District district = region.City.Districts[j];
                        if (this.descriptorsAppliedOnDistrict.ContainsKey(district.WorldPosition))
                        {
                            List <string> list2 = this.descriptorsAppliedOnDistrict[district.WorldPosition];
                            for (int k = 0; k < list2.Count; k++)
                            {
                                StaticString descriptorNames = list2[k];
                                district.RemoveDescriptorByName(descriptorNames);
                            }
                        }
                        district.Refresh(false);
                    }
                }
                list.Add(regionIndex);
            }
        }
        worldPositions = new WorldCircle(base.WorldPosition, base.WorldEffectDefinition.Range + 1).GetWorldPositions(base.WorldEffectManager.WorldPositionningService.World.WorldParameters);
        for (int l = 0; l < worldPositions.Length; l++)
        {
            PointOfInterest pointOfInterest = base.WorldEffectManager.WorldPositionningService.GetPointOfInterest(worldPositions[l]);
            if (pointOfInterest != null)
            {
                if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero)
                {
                    IGameEntity gameEntity = null;
                    if (base.WorldEffectManager.GameEntityRepositoryService.TryGetValue(pointOfInterest.CreepingNodeGUID, out gameEntity))
                    {
                        CreepingNode creepingNode = gameEntity as CreepingNode;
                        if (!creepingNode.IsUnderConstruction)
                        {
                            creepingNode.ReApplyFIMSEOnCreepingNode();
                        }
                    }
                }
                else if (pointOfInterest.SimulationObject.Tags.Contains(Village.ConvertedVillage))
                {
                    DepartmentOfTheInterior.ReApplyFIMSEOnConvertedVillage(pointOfInterest.Empire, pointOfInterest);
                }
            }
        }
    }
Exemplo n.º 22
0
    private int GetMaximumConvertedUnitSlot()
    {
        Diagnostics.Assert(this.Converter != null);
        DepartmentOfTheInterior agency = this.Converter.GetAgency <DepartmentOfTheInterior>();

        Diagnostics.Assert(agency != null);
        Diagnostics.Assert(agency.Empire != null);
        return(Mathf.FloorToInt(agency.Empire.GetPropertyValue(SimulationProperties.CityUnitSlot)));
    }
Exemplo n.º 23
0
 private void BindMinorFactionToCity()
 {
     if (this.MinorEmpire.Region.City != null)
     {
         DepartmentOfTheInterior agency = this.MinorEmpire.Region.City.Empire.GetAgency <DepartmentOfTheInterior>();
         agency.BindMinorFactionToCity(this.MinorEmpire.Region.City, this.MinorEmpire);
         agency.VerifyOverallPopulation(this.MinorEmpire.Region.City);
     }
 }
Exemplo n.º 24
0
    private HeuristicValue GetUnitPriority(UnitDesign unitDesign)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        heuristicValue.Add(this.currentProductionPriority, "Current unit priority", new object[0]);
        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
        int            num             = this.availableMilitaryBody.IndexOf(unitDesign.UnitBodyDefinition.Name);

        if (num >= 0)
        {
            float num2 = this.bodyCount[num] / this.overralUnitCount;
            float num3 = this.wantedBodyRatio[num];
            if (num2 > num3)
            {
                heuristicValue2.Log("Too much of this body already", new object[0]);
                heuristicValue2.Add(num2, "Current ratio", new object[0]);
                heuristicValue2.Divide(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
                heuristicValue2.Multiply(-1f, "invert", new object[0]);
            }
            else
            {
                heuristicValue2.Log("Not enough of this body for now.", new object[0]);
                heuristicValue2.Add(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Divide(num2, "Current ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
            }
        }
        heuristicValue2.Multiply(0.05f, "constant", new object[0]);
        heuristicValue.Boost(heuristicValue2, "Body ratio boost", new object[0]);
        DepartmentOfTheInterior agency = this.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();

        if (unitDesign.Name.ToString().Contains("Preacher") && this.VillageLayer.ConversionArmiesCount > 0 && (this.VictoryLayer == null || this.VictoryLayer.CurrentVictoryDesign != AILayer_Victory.VictoryDesign.Preacher))
        {
            heuristicValue.Boost(-0.4f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("EyelessOnesCaecator"))
        {
            heuristicValue.Boost(-0.3f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("CeratanDrider"))
        {
            heuristicValue.Boost(-0.15f, "Bad Unit Malus", new object[0]);
        }
        if (unitDesign.Name.ToString().Contains("Mastermind") && agency.AssimilatedFactions.Count > 0)
        {
            foreach (Faction faction in agency.AssimilatedFactions)
            {
                if (faction.Name != "Ceratan" && faction.Name != "EyelessOnes")
                {
                    heuristicValue.Boost(-0.2f, "Bad Unit Malus", new object[0]);
                    break;
                }
            }
        }
        return(heuristicValue);
    }
Exemplo n.º 25
0
 private void GenerateDistrictProxy(int empireIndex, WorldPosition worldPosition, SimulationObject districtProxy)
 {
     districtProxy.RemoveAllDescriptors_ModifierForwardType_ChildrenOnly();
     if (this.WorldPositionningService != null)
     {
         DepartmentOfTheInterior.ApplyDistrictProxyDescriptors(base.Game.Empires[empireIndex], districtProxy, worldPosition, DistrictType.Exploitation, true, false);
         districtProxy.Refresh();
     }
 }
Exemplo n.º 26
0
    private void UpdateResourceStatus(PointOfInterest pointOfInterest, global::Empire empire, Region region, AIRegionData regionData, DepartmentOfTheTreasury departmentOfTheTreasury)
    {
        regionData.ResourcePointOfInterestCount++;
        if (pointOfInterest.PointOfInterestImprovement != null)
        {
            regionData.BuiltExtractor++;
        }
        if (!DepartmentOfTheInterior.IsPointOfInterestVisible(empire, pointOfInterest))
        {
            return;
        }
        string empty     = string.Empty;
        bool   condition = pointOfInterest.PointOfInterestDefinition.TryGetValue("ResourceName", out empty);

        Diagnostics.Assert(condition);
        ResourceDefinition.Type resourceType = departmentOfTheTreasury.GetResourceType(empty);
        float num        = 0f;
        bool  condition2 = departmentOfTheTreasury.TryGetNetResourceValue(empire, empty, out num, true);

        Diagnostics.Assert(condition2);
        if (num > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.ProducedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.ProducedStrategicRessourcesCount++;
            }
            return;
        }
        float num2       = 0f;
        bool  condition3 = departmentOfTheTreasury.TryGetResourceStockValue(empire, empty, out num2, true);

        Diagnostics.Assert(condition3);
        if (num2 > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.OwnedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.OwnedStrategicRessourcesCount++;
            }
            return;
        }
        if (resourceType == ResourceDefinition.Type.Luxury)
        {
            regionData.NewLuxuryRessourcesCount++;
        }
        else if (resourceType == ResourceDefinition.Type.Strategic)
        {
            regionData.NewStrategicRessourcesCount++;
        }
    }
Exemplo n.º 27
0
 private float GetVillageCost()
 {
     ConstructionCost[] dissentionCost = DepartmentOfTheInterior.GetDissentionCost(base.Owner, this.villagePOI[0].Village);
     if (dissentionCost.Length >= 1)
     {
         return(dissentionCost[0].GetValue(base.Owner));
     }
     return(0f);
 }
Exemplo n.º 28
0
    public static bool IsRegionValidForExploration(global::Empire empire, int regionIndex)
    {
        Diagnostics.Assert(AIScheduler.Services != null);
        IWorldAtlasAIHelper service = AIScheduler.Services.GetService <IWorldAtlasAIHelper>();

        Diagnostics.Assert(service != null);
        if (empire != null)
        {
            DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>();
            if (agency != null && !agency.CanMoveOn(regionIndex, false))
            {
                return(false);
            }
        }
        DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();

        if (agency2 != null)
        {
            bool flag = false;
            for (int i = 0; i < agency2.Cities.Count; i++)
            {
                if (agency2.Cities[i].Region.ContinentID == service.Regions[regionIndex].ContinentID)
                {
                    flag = true;
                    break;
                }
            }
            if (agency2.Cities.Count == 0)
            {
                flag = true;
            }
            if (!flag)
            {
                DepartmentOfCreepingNodes agency3 = empire.GetAgency <DepartmentOfCreepingNodes>();
                if (agency3 != null)
                {
                    using (List <CreepingNode> .Enumerator enumerator = agency3.Nodes.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            if (!enumerator.Current.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(empire, enumerator.Current) && enumerator.Current.Region.ContinentID == service.Regions[regionIndex].ContinentID)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
        }
        return(!service.IsRegionExplored(empire.Index, regionIndex, 0.95f));
    }
Exemplo n.º 29
0
    private void CreateEmpireFilters(List <global::Empire> empiresToSelect = null)
    {
        if (empiresToSelect != null && empiresToSelect.Count == 1 && empiresToSelect[0] == base.Empire)
        {
            empiresToSelect.Clear();
        }
        this.empireToFilter.Clear();
        DepartmentOfIntelligence agency = base.Empire.GetAgency <DepartmentOfIntelligence>();
        bool         flag = DepartmentOfTheInterior.CanSeeAllExchangeTransactions(base.Empire);
        global::Game game = base.Game as global::Game;

        for (int i = 0; i < game.Empires.Length; i++)
        {
            MajorEmpire majorEmpire = game.Empires[i] as MajorEmpire;
            if (majorEmpire != null)
            {
                if (base.Empire.Index == majorEmpire.Index)
                {
                    this.empireToFilter.Add(majorEmpire);
                }
                else if (!majorEmpire.IsEliminated)
                {
                    DepartmentOfScience agency2 = majorEmpire.GetAgency <DepartmentOfScience>();
                    if (agency2.CanTradeHeroes(true) || agency2.CanTradeUnits(true) || agency2.CanTradeResourcesAndBoosters(true))
                    {
                        if (flag)
                        {
                            this.empireToFilter.Add(majorEmpire);
                        }
                        else if (agency != null && agency.IsEmpireInfiltrated(majorEmpire))
                        {
                            this.empireToFilter.Add(majorEmpire);
                        }
                    }
                }
            }
        }
        this.empireFilterWidth = Mathf.Floor((this.EmpireFiltersContainer.Width - this.EmpireFiltersContainer.HorizontalSpacing * (float)(this.empireToFilter.Count - 1)) / (float)this.empireToFilter.Count);
        this.EmpireFiltersContainer.ReserveChildren(this.empireToFilter.Count, this.EmpireFilterPrefab, "EmpireFilterToggle");
        this.EmpireFiltersContainer.RefreshChildrenIList <global::Empire>(this.empireToFilter, new AgeTransform.RefreshTableItem <global::Empire>(this.SetupEmpireFilterToggle), true, false);
        this.EmpireFiltersContainer.ArrangeChildren();
        if (empiresToSelect != null && empiresToSelect.Count > 0)
        {
            this.SetEmpiresToShow(empiresToSelect);
        }
        else
        {
            this.SetEmpiresToShow(this.empireToFilter);
        }
        AgeTooltip ageTooltip = this.EmpireFilterPrefab.GetComponent <AgeTransform>().AgeTooltip;

        if (ageTooltip != null)
        {
            ageTooltip.Content = "%MarketplaceEmpireFilterDescription";
        }
    }
Exemplo n.º 30
0
    private void ManageGeomancy()
    {
        if (ELCPUtilities.GeomancyDuration < 1 || ELCPUtilities.GeomancyRadius < 0)
        {
            return;
        }
        Stopwatch stopwatch = new Stopwatch();

        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            stopwatch.Start();
        }
        foreach (global::Empire empire in base.Game.Empires)
        {
            List <IGarrison>        list   = new List <IGarrison>();
            DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>();
            if (agency != null)
            {
                list.AddRange(agency.Cities.Cast <IGarrison>());
                list.AddRange(agency.Camps.Cast <IGarrison>());
            }
            DepartmentOfDefense agency2 = empire.GetAgency <DepartmentOfDefense>();
            if (agency2 != null)
            {
                list.AddRange(agency2.Armies.Cast <IGarrison>());
            }
            foreach (IGarrison garrison in list)
            {
                using (IEnumerator <Unit> enumerator2 = garrison.Units.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        if (enumerator2.Current.CheckUnitAbility(UnitAbility.UnitAbilityGeomancy, -1))
                        {
                            WorldCircle     worldCircle = new WorldCircle((garrison as IWorldPositionable).WorldPosition, ELCPUtilities.GeomancyRadius);
                            WorldPosition[] array       = base.Game.World.PerformReversibleTerraformation(worldCircle.GetWorldPositions(base.Game.World.WorldParameters), false, ELCPUtilities.GeomancyDuration + 1);
                            if (array.Length != 0)
                            {
                                base.Game.World.UpdateTerraformStateMap(true);
                                this.eventService.Notify(new EventEmpireWorldTerraformed(empire, array, true));
                            }
                        }
                    }
                }
            }
        }
        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            stopwatch.Stop();
            Diagnostics.Log("ELCP ManageGeomancy time elapsed: {0}", new object[]
            {
                stopwatch.Elapsed
            });
        }
    }