private bool CanAffordTechs()
    {
        ConstructionQueue          constructionQueueForEmpire = this.kaijuTechsService.GetConstructionQueueForEmpire(base.Empire);
        Dictionary <string, float> dictionary = new Dictionary <string, float>();

        for (int i = 0; i < constructionQueueForEmpire.Length; i++)
        {
            ConstructibleElement constructibleElement = constructionQueueForEmpire.PeekAt(i).ConstructibleElement;
            for (int j = 0; j < constructibleElement.Costs.Length; j++)
            {
                string key = constructibleElement.Costs[j].ResourceName;
                float  num = -constructibleElement.Costs[j].GetValue(base.Empire);
                if (!dictionary.ContainsKey(constructibleElement.Costs[j].ResourceName))
                {
                    dictionary.Add(constructibleElement.Costs[j].ResourceName, num);
                }
                else
                {
                    num            += dictionary[key];
                    dictionary[key] = num;
                }
            }
        }
        foreach (KeyValuePair <string, float> keyValuePair in dictionary)
        {
            float value = keyValuePair.Value;
            if (!this.departmentOfTheTreasury.IsTransferOfResourcePossible(base.Empire, keyValuePair.Key, ref value))
            {
                return(false);
            }
        }
        return(true);
    }
Ejemplo n.º 2
0
    private int GetSettlerCount()
    {
        int num = 0;

        for (int i = 0; i < this.departmentOfDefense.Armies.Count; i++)
        {
            num += this.GetSettlerCount(this.departmentOfDefense.Armies[i]);
        }
        for (int j = 0; j < this.departmentOfTheInterior.Cities.Count; j++)
        {
            num += this.GetSettlerCount(this.departmentOfTheInterior.Cities[j]);
            if (this.departmentOfTheInterior.Cities[j].Camp != null)
            {
                num += this.GetSettlerCount(this.departmentOfTheInterior.Cities[j].Camp);
            }
            ConstructionQueue constructionQueue = this.departmentOfIndustry.GetConstructionQueue(this.departmentOfTheInterior.Cities[j]);
            if (constructionQueue != null)
            {
                for (int k = constructionQueue.Length - 1; k >= 0; k--)
                {
                    if (constructionQueue.PeekAt(k).ConstructibleElementName.ToString().Contains("Settler"))
                    {
                        num++;
                    }
                }
            }
        }
        return(num);
    }
Ejemplo n.º 3
0
    public void EmptyConstructionQueueForEmpire(Empire empire)
    {
        IPlayerControllerRepositoryService service   = base.Game.Services.GetService <IPlayerControllerRepositoryService>();
        ConstructionQueue constructionQueueForEmpire = this.GetConstructionQueueForEmpire(empire);

        for (int i = constructionQueueForEmpire.Length - 1; i >= 0; i--)
        {
            Construction             construction = constructionQueueForEmpire.PeekAt(i);
            OrderCancelKaijuResearch order        = new OrderCancelKaijuResearch(empire.Index, construction.GUID);
            service.ActivePlayerController.PostOrder(order);
        }
    }
    private void OnApplyCB(GameObject obj)
    {
        ConstructionQueue constructionQueueForEmpire = this.kaijuTechsService.GetConstructionQueueForEmpire(base.Empire);

        if (constructionQueueForEmpire != null)
        {
            for (int i = constructionQueueForEmpire.Length - 1; i >= 0; i--)
            {
                this.buyoutButton.AgeTransform.Enable = false;
                Construction construction = constructionQueueForEmpire.PeekAt(i);
                if (construction == null)
                {
                    return;
                }
                OrderBuyOutKaijuTechnology order = new OrderBuyOutKaijuTechnology(base.Empire.Index, construction.ConstructibleElement.Name);
                base.PlayerController.PostOrder(order);
            }
        }
    }
    private void OnTechnologyBuyoutCB(GameObject obj)
    {
        ConstructionQueue constructionQueueForEmpire = this.KaijuTechsService.GetConstructionQueueForEmpire(base.Empire);

        if (constructionQueueForEmpire != null)
        {
            int length = constructionQueueForEmpire.Length;
            for (int i = length - 1; i >= 0; i--)
            {
                Construction construction = constructionQueueForEmpire.PeekAt(i);
                if (construction == null)
                {
                    return;
                }
                OrderBuyOutKaijuTechnology order = new OrderBuyOutKaijuTechnology(base.Empire.Index, construction.ConstructibleElement.Name);
                base.PlayerController.PostOrder(order);
            }
        }
    }
Ejemplo n.º 6
0
    public virtual void ReadXml(XmlReader reader)
    {
        int num = reader.ReadVersionAttribute();

        reader.ReadStartElement();
        this.researchQueues.Clear();
        int num2 = reader.ReadElementString <int>("QueuesCount");

        reader.ReadStartElement("ResearchQueues");
        for (int i = 0; i < num2; i++)
        {
            reader.ReadStartElement("Queue");
            int key = reader.ReadElementString <int>("EmpireIndex");
            ConstructionQueue constructionQueue = new ConstructionQueue();
            Amplitude.Xml.Serialization.IXmlSerializable xmlSerializable = constructionQueue;
            reader.ReadElementSerializable <Amplitude.Xml.Serialization.IXmlSerializable>("Researches", ref xmlSerializable);
            for (int j = constructionQueue.Length - 1; j >= 0; j--)
            {
                Construction construction = constructionQueue.PeekAt(j);
                if (construction.ConstructibleElement == null)
                {
                    Diagnostics.LogWarning("Compatibility issue, constructible element (name: '{0}') is null.", new object[]
                    {
                        construction.ConstructibleElementName
                    });
                    constructionQueue.Remove(construction);
                }
            }
            this.researchQueues.Add(key, constructionQueue);
            reader.ReadEndElement("Queue");
        }
        reader.ReadEndElement("ResearchQueues");
        int num3 = reader.ReadElementString <int>("ResearchedTechsCount");

        reader.ReadStartElement("ResearchedTechs");
        for (int k = 0; k < num3; k++)
        {
            this.researchedTechNames.Add(reader.ReadElementString("TechName"));
        }
        reader.ReadEndElement("ResearchedTechs");
    }
Ejemplo n.º 7
0
    public void Refresh(global::Empire empire, DepartmentOfScience.ConstructibleElement.State state)
    {
        if (this.Button != null)
        {
            this.Button.AgeTransform.Enable = true;
        }
        TechnologyDefinitionVisibility visibility = this.TechnologyDefinition.Visibility;

        if (visibility != TechnologyDefinitionVisibility.VisibleWhenUnlocked)
        {
            if (visibility == TechnologyDefinitionVisibility.BasedOnPrerequisites)
            {
                bool flag = DepartmentOfTheTreasury.CheckConstructiblePrerequisites(empire, this.TechnologyDefinition, new string[]
                {
                    "Visibility"
                });
                if (flag)
                {
                    this.AgeTransform.Visible = true;
                }
                else
                {
                    this.AgeTransform.Visible = false;
                }
            }
        }
        else
        {
            if (state != DepartmentOfScience.ConstructibleElement.State.Researched)
            {
                this.AgeTransform.Visible = false;
                return;
            }
            if (!this.AgeTransform.Visible)
            {
                this.AgeTransform.Visible = true;
                this.SetSimpleMode(false);
            }
        }
        this.UnlockDisabled.Visible = false;
        this.InProgressSector.AgeTransform.Visible = false;
        this.OrderCaption.AgeTransform.Visible     = false;
        DepartmentOfScience agency = empire.GetAgency <DepartmentOfScience>();
        bool flag2 = false;
        int  num   = 0;
        ConstructionQueue constructionQueueForTech = agency.GetConstructionQueueForTech(this.TechnologyDefinition);

        if ((state == DepartmentOfScience.ConstructibleElement.State.Queued || state == DepartmentOfScience.ConstructibleElement.State.InProgress) && constructionQueueForTech.Length > 1)
        {
            flag2 = true;
            if (state == DepartmentOfScience.ConstructibleElement.State.Queued)
            {
                for (int i = 0; i < constructionQueueForTech.Length; i++)
                {
                    DepartmentOfScience.ConstructibleElement constructibleElement = constructionQueueForTech.PeekAt(i).ConstructibleElement as DepartmentOfScience.ConstructibleElement;
                    if (constructibleElement.Name == this.TechnologyDefinition.Name)
                    {
                        num = i;
                        break;
                    }
                }
            }
        }
        bool  flag3 = this.TechnologyDefinition.HasTechnologyFlag(DepartmentOfScience.ConstructibleElement.TechnologyFlag.Affinity) || this.TechnologyDefinition.HasTechnologyFlag(DepartmentOfScience.ConstructibleElement.TechnologyFlag.Medal) || this.TechnologyDefinition.HasTechnologyFlag(DepartmentOfScience.ConstructibleElement.TechnologyFlag.Quest);
        bool  flag4 = this.TechnologyDefinition.HasTechnologyFlag(DepartmentOfScience.ConstructibleElement.TechnologyFlag.OrbUnlock);
        Color tintColor;
        Color tintColor2;
        Color tintColor3;
        Color tintColor4;

        switch (state)
        {
        case DepartmentOfScience.ConstructibleElement.State.Available:
            tintColor  = ((!flag4) ? this.AvailableColor : this.AvailableOrbUnlockColor);
            tintColor2 = ((!flag3) ? ((!flag4) ? this.AvailableBackdropColor : this.AvailableOrbUnlockBackdropColor) : this.AvailableBackdropColorAffinity);
            tintColor3 = this.AvailableSymbolColor;
            tintColor4 = this.GlowAvailableColor;
            break;

        case DepartmentOfScience.ConstructibleElement.State.Queued:
            tintColor  = this.QueuedColor;
            tintColor2 = ((!flag3) ? this.QueuedBackdropColor : this.QueuedBackdropColorAffinity);
            tintColor3 = this.QueuedSymbolColor;
            tintColor4 = this.GlowAvailableColor;
            this.OrderCaption.AgeTransform.Visible = true;
            this.OrderCaption.TintColor            = this.QueuedColor;
            this.OrderLabel.Text = (num + 1).ToString();
            break;

        case DepartmentOfScience.ConstructibleElement.State.InProgress:
            tintColor  = this.InProgressColor;
            tintColor2 = ((!flag3) ? this.InProgressBackdropColor : this.InProgressBackdropColorAffinity);
            tintColor3 = this.InProgressSymbolColor;
            tintColor4 = this.GlowAvailableColor;
            this.InProgressSector.AgeTransform.Visible = true;
            if (flag2)
            {
                this.OrderCaption.AgeTransform.Visible = true;
                this.OrderCaption.TintColor            = this.InProgressColor;
                this.OrderLabel.Text = (num + 1).ToString();
            }
            break;

        case DepartmentOfScience.ConstructibleElement.State.Researched:
            if (this.Button != null)
            {
                this.Button.AgeTransform.Enable = false;
            }
            tintColor  = ((!flag4) ? this.ResearchedColor : this.ResearchedOrbUnlockColor);
            tintColor2 = ((!flag3) ? this.ResearchedBackdropColor : this.ResearchedBackdropColorAffinity);
            tintColor3 = this.ResearchedSymbolColor;
            tintColor4 = this.GlowAvailableColor;
            break;

        case DepartmentOfScience.ConstructibleElement.State.ResearchedButUnavailable:
            if (this.Button != null)
            {
                this.Button.AgeTransform.Enable = false;
            }
            tintColor  = this.ResearchedButUnavailableColor;
            tintColor2 = ((!flag3) ? this.ResearchedBackdropColor : this.ResearchedBackdropColorAffinity);
            tintColor3 = this.ResearchedSymbolColor;
            tintColor4 = this.GlowNotAvailableColor;
            this.UnlockDisabled.Visible = true;
            break;

        default:
            tintColor  = this.NotAvailableColor;
            tintColor2 = ((!flag3) ? this.NotAvailableBackdropColor : this.NotAvailableBackdropColorAffinity);
            tintColor3 = this.NotAvailableSymbolColor;
            tintColor4 = this.GlowNotAvailableColor;
            if (this.Button != null)
            {
                this.Button.AgeTransform.Enable = false;
            }
            this.UnlockDisabled.Visible = true;
            break;
        }
        this.CircularFrame.TintColor           = tintColor;
        this.CaptionFullBackground.TintColor   = tintColor2;
        this.CaptionTopBackground.TintColor    = tintColor2;
        this.CaptionBottomBackground.TintColor = tintColor2;
        this.EraLabel.TintColor            = tintColor3;
        this.CategoryIcon.TintColor        = tintColor3;
        this.SubCategoryIcon.TintColor     = tintColor3;
        this.CategoryFullIcon.TintColor    = tintColor3;
        this.SubCategoryFullIcon.TintColor = tintColor3;
        this.GlowImage.TintColor           = tintColor4;
        this.RefreshCostGroup(state);
    }
 public override void RefreshContent()
 {
     base.RefreshContent();
     this.validPointsOfInterest.Clear();
     this.validImprovements.Clear();
     if (this.City != null && this.City.BesiegingEmpire == null && base.Empire == this.City.Empire && !this.City.IsInfected)
     {
         DepartmentOfIndustry    agency  = this.City.Empire.GetAgency <DepartmentOfIndustry>();
         DepartmentOfTheInterior agency2 = this.City.Empire.GetAgency <DepartmentOfTheInterior>();
         DepartmentOfTheTreasury agency3 = this.City.Empire.GetAgency <DepartmentOfTheTreasury>();
         ConstructibleElement[]  availableConstructibleElements = agency.ConstructibleElementDatabase.GetAvailableConstructibleElements(new StaticString[0]);
         ConstructibleElement[]  array = availableConstructibleElements;
         List <StaticString>     list  = new List <StaticString>();
         for (int i = 0; i < this.City.Region.PointOfInterests.Length; i++)
         {
             PointOfInterest pointOfInterest = this.City.Region.PointOfInterests[i];
             if (pointOfInterest.PointOfInterestImprovement == null && pointOfInterest.CreepingNodeImprovement == null && (base.WorldPositionningService.GetExplorationBits(pointOfInterest.WorldPosition) & this.City.Empire.Bits) > 0)
             {
                 List <PointOfInterestImprovementDefinition> list2 = new List <PointOfInterestImprovementDefinition>();
                 List <ConstructibleDistrictDefinition>      list3 = new List <ConstructibleDistrictDefinition>();
                 for (int j = 0; j < array.Length; j++)
                 {
                     if (array[j] is PointOfInterestImprovementDefinition)
                     {
                         PointOfInterestImprovementDefinition pointOfInterestImprovementDefinition = array[j] as PointOfInterestImprovementDefinition;
                         if (pointOfInterestImprovementDefinition.PointOfInterestTemplateName == pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplateName)
                         {
                             list.Clear();
                             DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.City, pointOfInterestImprovementDefinition, ref list, new string[]
                             {
                                 ConstructionFlags.Prerequisite
                             });
                             if (!list.Contains(ConstructionFlags.Discard) && agency3.CheckConstructibleInstantCosts(this.City, pointOfInterestImprovementDefinition))
                             {
                                 list2.Add(agency2.GetBestImprovementDefinition(this.City, pointOfInterest, pointOfInterestImprovementDefinition, list));
                             }
                         }
                     }
                     else if (array[j] is ConstructibleDistrictDefinition)
                     {
                         ConstructibleDistrictDefinition constructibleDistrictDefinition = array[j] as ConstructibleDistrictDefinition;
                         if (constructibleDistrictDefinition != null)
                         {
                             list3.Add(constructibleDistrictDefinition);
                         }
                     }
                 }
                 if (list2.Count > 0)
                 {
                     ConstructionQueue constructionQueue = agency.GetConstructionQueue(this.City);
                     bool flag = false;
                     for (int k = 0; k < list2.Count; k++)
                     {
                         for (int l = 0; l < constructionQueue.Length; l++)
                         {
                             Construction construction = constructionQueue.PeekAt(l);
                             if (construction.ConstructibleElement == list2[k] && construction.WorldPosition == pointOfInterest.WorldPosition)
                             {
                                 flag = true;
                                 break;
                             }
                         }
                     }
                     if (!flag)
                     {
                         for (int m = 0; m < list3.Count; m++)
                         {
                             for (int n = 0; n < constructionQueue.Length; n++)
                             {
                                 Construction construction2 = constructionQueue.PeekAt(n);
                                 if (construction2.ConstructibleElement == list3[m] && construction2.WorldPosition == pointOfInterest.WorldPosition)
                                 {
                                     flag = true;
                                     break;
                                 }
                             }
                         }
                     }
                     if (!flag)
                     {
                         for (int num = 0; num < list2.Count; num++)
                         {
                             this.validPointsOfInterest.Add(pointOfInterest);
                             this.validImprovements.Add(list2[num]);
                         }
                     }
                 }
             }
         }
     }
     this.LabelsTable.ReserveChildren(this.validPointsOfInterest.Count, this.LabelPrefab, "ConstructibleLabel");
     this.LabelsTable.RefreshChildrenIList <PointOfInterest>(this.validPointsOfInterest, new AgeTransform.RefreshTableItem <PointOfInterest>(this.RefreshPointOfInterest), true, false);
     this.LabelsTable.Enable = this.interactionsAllowed;
     this.UnbindAndHideLabels(this.validPointsOfInterest.Count);
 }
Ejemplo n.º 9
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);
    }