public UnitModelProductionNeeds(UnitDesign unitDesign, RequestUnitListMessage requestArmy, int count, StaticString seekedUnitPatternCategory)
 {
     this.Count       = count;
     this.RequestArmy = requestArmy;
     this.UnitDesign  = unitDesign;
     this.WantedUnitPatternCategory = seekedUnitPatternCategory;
 }
Пример #2
0
    public void RefreshContent(City city, CityOptionsPanel.ProductionConstruction constructibleElementDefinition, int index, GameObject client)
    {
        IGuiPanelHelper guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper;

        Diagnostics.Assert(guiPanelHelper != null, "Unable to access GuiPanelHelper");
        UnitDesign unitDesign = constructibleElementDefinition.ConstructibleElement as UnitDesign;
        GuiElement guiElement2;

        if (unitDesign != null)
        {
            this.ConstructibleName.Text   = GuiUnitDesign.GetTruncatedTitle(unitDesign, this.ConstructibleName);
            this.ConstructibleImage.Image = null;
            GuiElement guiElement;
            Texture2D  image;
            if (guiPanelHelper.TryGetGuiElement(unitDesign.UnitBodyDefinitionReference, out guiElement) && guiPanelHelper.TryGetTextureFromIcon(guiElement, global::GuiPanel.IconSize.Small, out image))
            {
                this.ConstructibleImage.Image = image;
            }
        }
        else if (guiPanelHelper.TryGetGuiElement(constructibleElementDefinition.ConstructibleElement.Name, out guiElement2))
        {
            AgeUtils.TruncateString(AgeLocalizer.Instance.LocalizeString(guiElement2.Title), this.ConstructibleName, out this.temp, '.');
            this.ConstructibleName.Text = this.temp;
            Texture2D image2;
            if (guiPanelHelper.TryGetTextureFromIcon(guiElement2, global::GuiPanel.IconSize.Small, out image2))
            {
                this.ConstructibleImage.Image = image2;
            }
            else
            {
                this.ConstructibleImage.Image = null;
            }
        }
        else
        {
            this.ConstructibleName.Text   = string.Empty;
            this.ConstructibleImage.Image = null;
        }
        if (this.AgeTransform.AgeTooltip != null)
        {
            this.AgeTransform.AgeTooltip.Class   = constructibleElementDefinition.ConstructibleElement.TooltipClass;
            this.AgeTransform.AgeTooltip.Content = constructibleElementDefinition.ConstructibleElement.Name;
            if (constructibleElementDefinition.ConstructibleElement is BoosterGeneratorDefinition)
            {
                this.AgeTransform.AgeTooltip.ClientData = new BoosterGeneratorTooltipData(city.Empire, city, constructibleElementDefinition.ConstructibleElement);
            }
            else
            {
                this.AgeTransform.AgeTooltip.ClientData = new ConstructibleTooltipData(city.Empire, city, constructibleElementDefinition.ConstructibleElement);
            }
        }
        this.ConstructibleButton.OnActivateMethod     = "OnOptionSelect";
        this.ConstructibleButton.OnActivateObject     = client;
        this.ConstructibleButton.OnActivateDataObject = constructibleElementDefinition.ConstructibleElement;
        this.ConstructibleButton.OnMiddleClickMethod  = "OnRightClick";
        this.ConstructibleButton.OnMiddleClickObject  = client;
        this.ConstructibleButton.OnRightClickMethod   = "OnRightClick";
        this.ConstructibleButton.OnRightClickObject   = client;
        this.AgeTransform.Enable = (constructibleElementDefinition.Flags.Length == 0);
    }
Пример #3
0
    private void SpawnMinorArmy()
    {
        IGameService service = Services.GetService <IGameService>();

        if (service.Game == null)
        {
            return;
        }
        if (WorldCursor.HighlightedWorldPosition.IsValid && WorldCursor.HighlightedRegion.MinorEmpire != null)
        {
            IPlayerControllerRepositoryService service2 = service.Game.Services.GetService <IPlayerControllerRepositoryService>();
            UnitDesign          unitDesign = WorldCursor.HighlightedRegion.MinorEmpire.GetAgency <DepartmentOfDefense>().UnitDesignDatabase.UserDefinedUnitDesigns[0];
            List <StaticString> list       = new List <StaticString>();
            for (int i = 0; i < 3; i++)
            {
                list.Add(unitDesign.Name);
            }
            OrderSpawnArmy orderSpawnArmy = new OrderSpawnArmy(WorldCursor.HighlightedRegion.MinorEmpire.Index, WorldCursor.HighlightedWorldPosition, list.ToArray());
            service2.ActivePlayerController.PostOrder(orderSpawnArmy);
            Diagnostics.Log("Posting order: {0}.", new object[]
            {
                orderSpawnArmy.ToString()
            });
        }
    }
Пример #4
0
    private void DoProduce()
    {
        this.ComputeMilitaryBodyRatio();
        List <EvaluableMessage_UnitProduction> list = new List <EvaluableMessage_UnitProduction>();

        this.FillUnitProduction(ref list);
        HeuristicValue globalMotivation = new HeuristicValue(0.9f);

        for (int i = 0; i < list.Count; i++)
        {
            if (!this.CheckUnitProduction(list[i]))
            {
                list[i].Cancel();
            }
            else
            {
                HeuristicValue unitPriority = this.GetUnitPriority(list[i].UnitDesign);
                list[i].Refresh(globalMotivation, unitPriority);
                this.ProcessUnitProduction(list[i].UnitDesign);
            }
        }
        while (this.needMilitaryPower > 0f)
        {
            UnitDesign unitDesign = this.ChooseMilitaryUnitToBuild();
            if (unitDesign == null)
            {
                break;
            }
            HeuristicValue unitPriority2            = this.GetUnitPriority(unitDesign);
            EvaluableMessage_UnitProduction message = new EvaluableMessage_UnitProduction(globalMotivation, unitPriority2, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
            this.AIEntity.AIPlayer.Blackboard.AddMessage(message);
            this.ProcessUnitProduction(unitDesign);
        }
    }
Пример #5
0
 private float GetBodyWeight(UnitDesign unitDesign)
 {
     if (unitDesign.CheckAgainstTag("UnitClassInfantry"))
     {
         return(20f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassArcher"))
     {
         return(10f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassSupport"))
     {
         return(5f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassFrigate"))
     {
         return(20f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassInterceptor"))
     {
         return(10f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassJuggernaut"))
     {
         return(5f);
     }
     if (unitDesign.CheckAgainstTag("UnitClassSubmersible"))
     {
         return(5f);
     }
     return(10f);
 }
Пример #6
0
    private void ProcessUnitProduction(UnitDesign unitDesign)
    {
        int num = this.availableMilitaryBody.IndexOf(unitDesign.UnitBodyDefinition.Name);

        if (num >= 0)
        {
            this.overralUnitCount += 1f;
            List <float> list2;
            List <float> list = list2 = this.bodyCount;
            int          index2;
            int          index = index2 = num;
            float        num2  = list2[index2];
            list[index] = num2 + 1f;
        }
        if (unitDesign.Context != null && unitDesign.Context.SimulationObject != null)
        {
            this.needMilitaryPower -= unitDesign.Context.GetPropertyValue(SimulationProperties.MilitaryPower);
        }
        else
        {
            this.needMilitaryPower -= this.averageMilitaryPower;
        }
        this.maxNewUnits -= 1f;
        this.currentProductionPriority = AILayer.Boost(this.currentProductionPriority, -0.1f);
    }
Пример #7
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);
    }
Пример #8
0
    private void ComputeMilitaryBodyRatio()
    {
        this.overralBodyRatio = 1f;
        this.overralUnitCount = 1f;
        this.bodyCount.Clear();
        this.availableMilitaryDesign.Clear();
        this.wantedBodyRatio.Clear();
        this.availableMilitaryBody.Clear();
        this.averageMilitaryPower = 0f;
        IAIUnitDesignDataRepository service = AIScheduler.Services.GetService <IAIUnitDesignDataRepository>();
        DepartmentOfDefense         agency  = this.AIEntity.Empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.UnitDesignDatabase.UserDefinedUnitDesigns.Count; i++)
        {
            UnitDesign unitDesign = agency.UnitDesignDatabase.UserDefinedUnitDesigns[i];
            if (this.UnitDesignFilter(unitDesign))
            {
                AIUnitDesignData aiunitDesignData;
                if (service.TryGetUnitDesignData(this.AIEntity.Empire.Index, unitDesign.Model, out aiunitDesignData))
                {
                    this.availableMilitaryDesign.Add(unitDesign);
                    if (unitDesign.Context != null)
                    {
                        this.averageMilitaryPower += unitDesign.Context.GetPropertyValue(SimulationProperties.MilitaryPower);
                    }
                    int num = this.availableMilitaryBody.IndexOf(aiunitDesignData.BodyName);
                    if (num < 0)
                    {
                        num = this.availableMilitaryBody.Count;
                        this.availableMilitaryBody.Add(aiunitDesignData.BodyName);
                        this.bodyCount.Add(aiunitDesignData.EmpireBodyCount);
                        this.overralUnitCount += aiunitDesignData.EmpireBodyCount;
                        float bodyWeight = this.GetBodyWeight(unitDesign);
                        this.wantedBodyRatio.Add(bodyWeight);
                        this.overralBodyRatio += bodyWeight;
                    }
                }
            }
        }
        if (this.availableMilitaryDesign.Count > 0)
        {
            this.averageMilitaryPower /= (float)this.availableMilitaryDesign.Count;
        }
        for (int j = 0; j < this.wantedBodyRatio.Count; j++)
        {
            List <float> list2;
            List <float> list = list2 = this.wantedBodyRatio;
            int          index2;
            int          index = index2 = j;
            float        num2  = list2[index2];
            list[index] = num2 / this.overralBodyRatio;
        }
    }
Пример #9
0
    public void RefreshContent(global::Empire empire, UnitDesign design, GameObject client, AgeTransform anchor, bool allowDoubleClick)
    {
        this.Reset();
        IGuiPanelHelper guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper;

        Diagnostics.Assert(guiPanelHelper != null, "Unable to access GuiPanelHelper");
        this.UnitDesign = design;
        if (this.tooltip != null)
        {
            this.tooltip.Anchor     = anchor;
            this.tooltip.Class      = this.UnitDesign.TooltipClass;
            this.tooltip.ClientData = new ConstructibleTooltipData(empire, null, this.UnitDesign);
            this.tooltip.Content    = this.UnitDesign.Name;
        }
        this.UnitName.Text = GuiUnitDesign.GetTruncatedTitle(this.UnitDesign, this.UnitName);
        if (this.PrivateerGroup != null)
        {
            this.PrivateerGroup.Visible = this.IsMercenary(empire, this.UnitDesign);
        }
        GuiElement guiElement;

        if (guiPanelHelper.TryGetGuiElement(this.UnitDesign.UnitBodyDefinition.Name, out guiElement))
        {
            Texture2D image;
            if (guiPanelHelper.TryGetTextureFromIcon(guiElement, global::GuiPanel.IconSize.Small, out image))
            {
                this.UnitPortrait.Image = image;
            }
        }
        else
        {
            this.UnitPortrait.Image = null;
        }
        this.UnitToggle.State          = false;
        this.UnitToggle.OnSwitchMethod = "OnUnitDesignToggle";
        this.UnitToggle.OnSwitchObject = client;
        if (this.DoubleClickButton != null)
        {
            if (allowDoubleClick)
            {
                this.DoubleClickButton.AgeTransform.Visible = true;
                this.DoubleClickButton.OnDoubleClickMethod  = "OnDoubleClickDesignCB";
                this.DoubleClickButton.OnDoubleClickObject  = client;
            }
            else
            {
                this.DoubleClickButton.AgeTransform.Visible = false;
            }
        }
        this.LifeGauge.AgeTransform.Alpha = 0f;
    }
Пример #10
0
    protected virtual void OnDestroy()
    {
        this.Reset();
        this.GuiUnit    = null;
        this.UnitDesign = null;
        this.UnitBody   = null;
        this.empire     = null;
        AgeTooltip component = base.GetComponent <AgeTooltip>();

        if (component != null)
        {
            component.ClientData = null;
        }
    }
    private void SettlerProduction()
    {
        UnitDesign unitDesign = this.FindSettlerDesign();

        if (unitDesign == null)
        {
            return;
        }
        List <EvaluableMessage_SettlerProduction> list = new List <EvaluableMessage_SettlerProduction>();

        base.AIEntity.AIPlayer.Blackboard.FillMessages <EvaluableMessage_SettlerProduction>(BlackboardLayerID.Empire, (EvaluableMessage_SettlerProduction match) => match.EvaluationState != EvaluableMessage.EvaluableMessageState.Cancel && match.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtained, ref list);
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        heuristicValue.Add(1f, "(constant)", new object[0]);
        if (this.ColonizationLayer == null || this.ColonizationLayer.CurrentSettlerCount < 2)
        {
            for (int i = 0; i < this.requestArmyMessages.Count; i++)
            {
                if (this.requestArmyMessages[i].CommanderCategory == AICommanderMissionDefinition.AICommanderCategory.Colonization && this.requestArmyMessages[i].ExecutionState == RequestUnitListMessage.RequestUnitListState.Pending)
                {
                    if (list.Count == 0)
                    {
                        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                        heuristicValue2.Add(this.requestArmyMessages[i].Priority, "Army request priority", new object[0]);
                        EvaluableMessage_SettlerProduction message = new EvaluableMessage_SettlerProduction(heuristicValue, heuristicValue2, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
                        base.AIEntity.AIPlayer.Blackboard.AddMessage(message);
                    }
                    else
                    {
                        list[0].Refresh(1f, this.requestArmyMessages[i].Priority);
                    }
                }
            }
        }
        if (this.VictoryLayer != null && this.VictoryLayer.CurrentVictoryDesign == AILayer_Victory.VictoryDesign.Settler && (this.ColonizationLayer == null || this.ColonizationLayer.CurrentSettlerCount < 10))
        {
            if (list.Count < 1)
            {
                HeuristicValue localOpportunity             = new HeuristicValue(1f);
                EvaluableMessage_SettlerProduction message2 = new EvaluableMessage_SettlerProduction(heuristicValue, localOpportunity, unitDesign, -1, 1, AILayer_AccountManager.MilitaryAccountName);
                base.AIEntity.AIPlayer.Blackboard.AddMessage(message2);
                return;
            }
            list[0].Refresh(1f, 1f);
        }
    }
Пример #12
0
    private void RetrofitComputeCandidates()
    {
        this.retrofitableUnits.Clear();
        int i;

        for (i = 0; i < this.selectedUnits.Count; i++)
        {
            if (!(this.selectedUnits[i].Garrison is Army) || !(this.selectedUnits[i].Garrison as Army).HasCatspaw)
            {
                UnitDesign unitDesign = this.departmentOfDefense.UnitDesignDatabase.UserDefinedUnitDesigns.FirstOrDefault((UnitDesign design) => design.Model == this.selectedUnits[i].UnitDesign.Model);
                if (unitDesign != null && this.selectedUnits[i].UnitDesign != unitDesign)
                {
                    this.retrofitableUnits.Add(this.selectedUnits[i]);
                }
            }
        }
    }
Пример #13
0
    private void Client_TurnBegin_UpdateUnitDesigns()
    {
        Garrison   activeTroops  = this.GetActiveTroops();
        UnitDesign unitDesign    = this.KaijuEmpire.FindMonsterDesign(true);
        UnitDesign newUnitDesign = this.KaijuEmpire.FindLiceDesign(true);

        foreach (Unit unit in activeTroops.Units)
        {
            if (unit.UnitDesign.Tags.Contains(Kaiju.MonsterUnitTag) && unit.UnitDesign.Model != unitDesign.Model)
            {
                unit.RetrofitTo(unitDesign);
            }
            else if (unit.UnitDesign.Tags.Contains(Kaiju.LiceUnitTag) && unit.UnitDesign.Model != unitDesign.Model)
            {
                unit.RetrofitTo(newUnitDesign);
            }
        }
    }
Пример #14
0
    private void ConstructionQueue_CollectionChanged(object sender, CollectionChangeEventArgs e)
    {
        ConstructionQueue constructionQueue = this.departmentOfIndustry.GetConstructionQueue(this.aiEntityCity.City);

        if (constructionQueue != null && constructionQueue.Length > 0)
        {
            UnitDesign unitDesign = constructionQueue.Peek().ConstructibleElement as UnitDesign;
            if (unitDesign != null && this.IsActive() && unitDesign.UnitBodyDefinition != null && unitDesign.UnitBodyDefinition.Tags.Contains(AILayer_Population.Settler) && this.resourceScore[0] > 0f)
            {
                this.resourceScore[1] += this.resourceScore[0];
                this.resourceScore[0]  = 0f;
                if (this.assignedPopulationThisTurn)
                {
                    this.assignedPopulationThisTurn = false;
                    AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>().RegisterSynchronousJob(new SynchronousJob(this.SynchronousJob_AssignPopulation));
                }
            }
        }
    }
Пример #15
0
    protected override void ComputeInitValue()
    {
        base.ComputeInitValue();
        Diagnostics.Assert(this.contextSimulationObject != null);
        float propertyValue = this.contextSimulationObject.GetPropertyValue(SimulationProperties.NetCityProduction);

        Diagnostics.Assert(this.constructionQueue != null);
        Construction         construction         = this.constructionQueue.Peek();
        ConstructibleElement constructibleElement = (construction == null) ? null : construction.ConstructibleElement;

        this.currentCostWithReduction = ((constructibleElement == null) ? 0f : DepartmentOfTheTreasury.GetProductionCostWithBonus(this.contextSimulationObject, constructibleElement, DepartmentOfTheTreasury.Resources.Production));
        this.currentProductionStress  = 1f;
        UnitDesign unitDesign = constructibleElement as UnitDesign;

        if (unitDesign != null)
        {
            this.currentProductionStress = 0f;
            bool flag = false;
            IEnumerable <EvaluableMessageWithUnitDesign> messages = this.aiPlayer.Blackboard.GetMessages <EvaluableMessageWithUnitDesign>(BlackboardLayerID.Empire, (EvaluableMessageWithUnitDesign match) => match.UnitDesign != null && match.UnitDesign.Model == unitDesign.Model);
            foreach (EvaluableMessageWithUnitDesign evaluableMessageWithUnitDesign in messages)
            {
                if (float.IsNaN(evaluableMessageWithUnitDesign.Interest))
                {
                    Diagnostics.LogWarning("Unit request interest is at value NaN, it will be skipped.");
                }
                else
                {
                    this.currentProductionStress = Mathf.Max(this.currentProductionStress, evaluableMessageWithUnitDesign.Interest);
                    flag = true;
                }
            }
            if (!flag)
            {
                this.currentProductionStress = 1f;
            }
        }
        this.currentProductionStress = Mathf.Clamp01(this.currentProductionStress);
        float num  = this.currentCostWithReduction * this.currentProductionStress;
        float num2 = (propertyValue <= 0f) ? this.maximumTurnCount : (num / propertyValue);

        base.ValueInit = ((this.maximumTurnCount <= 0f) ? base.ValueMax : Mathf.Clamp(Mathf.Max(num2 - 1f, 0f) / Mathf.Max(1f, this.maximumTurnCount - 1f), base.ValueMin, base.ValueMax));
    }
 private void LaunchProductionNeeds(DepartmentOfDefense departmentOfDefense, RequestUnitListMessage requestUnitListMessage)
 {
     Predicate <AILayer_ArmyRecruitment.UnitModelProductionNeeds> < > 9__1;
     for (int i = 0; i < requestUnitListMessage.ArmyPattern.UnitPatternCategoryList.Count; i++)
     {
         ArmyPattern.UnitPatternCategory unitPatternCategory = requestUnitListMessage.ArmyPattern.UnitPatternCategoryList[i];
         UnitDesign bestUnitDesign = this.intelligenceAIHelper.GetBestUnitDesignForNeededCategory(departmentOfDefense, unitPatternCategory);
         if (bestUnitDesign != null)
         {
             int num = this.countByUnitModel.FindIndex((AILayer_ArmyRecruitment.UnitModelProductionNeeds match) => match.UnitDesign != null && match.UnitDesign.Model == bestUnitDesign.Model && match.RequestArmy.ID == requestUnitListMessage.ID);
             if (num < 0)
             {
                 num = ~num;
                 this.countByUnitModel.Insert(num, new AILayer_ArmyRecruitment.UnitModelProductionNeeds(bestUnitDesign, requestUnitListMessage, 1, unitPatternCategory.Category));
             }
             else
             {
                 this.countByUnitModel[num].Count++;
             }
         }
         else
         {
             List <AILayer_ArmyRecruitment.UnitModelProductionNeeds>      list = this.countByUnitModel;
             Predicate <AILayer_ArmyRecruitment.UnitModelProductionNeeds> match2;
             if ((match2 = < > 9__1) == null)
             {
                 match2 = (< > 9__1 = ((AILayer_ArmyRecruitment.UnitModelProductionNeeds match) => match.UnitDesign == null && match.RequestArmy.ID == requestUnitListMessage.ID));
             }
             int num2 = list.FindIndex(match2);
             if (num2 < 0)
             {
                 num2 = ~num2;
                 this.countByUnitModel.Insert(num2, new AILayer_ArmyRecruitment.UnitModelProductionNeeds(null, requestUnitListMessage, 1, unitPatternCategory.Category));
             }
             else
             {
                 this.countByUnitModel[num2].Count++;
             }
         }
     }
 }
Пример #17
0
    private float ComputeColossusScore(AIUnitDesignData unitDesignData, UnitDesign unitDesign)
    {
        float num  = 0f;
        float num2 = 0f;

        for (int i = 0; i < unitDesign.Costs.Length; i++)
        {
            if (unitDesign.Costs[i].Instant)
            {
                num2 += 1f;
                float num3;
                if (this.departmentOfTheTreasury.TryGetNetResourceValue(base.AIEntity.Empire, unitDesign.Costs[i].ResourceName, out num3, false))
                {
                    num += 1f;
                }
            }
        }
        float num4 = num / num2;

        return(num4 / (unitDesignData.EmpireUnitCount + 1f));
    }
Пример #18
0
    private void GenerateUnit(global::Empire empire)
    {
        if (this.temporaryUnit != null)
        {
            this.Reset();
        }
        this.empire = empire;
        UnitDesign unitDesign = new UnitDesign();

        unitDesign.UnitBodyDefinitionReference = new XmlNamedReference(this.UnitBody.Name);
        DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();

        if (!UnitGuiItem.temporaryUnitGuid.IsValid)
        {
            IGameService service = Services.GetService <IGameService>();
            IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
            UnitGuiItem.temporaryUnitGuid = service2.GenerateGUID();
        }
        this.temporaryUnit = agency.CreateTemporaryUnit(UnitGuiItem.temporaryUnitGuid, unitDesign);
        this.temporaryUnit.Rename(this.temporaryUnit.Name + "#" + this.UnitBody.Name);
        this.temporaryUnit.SimulationObject.ModifierForward = ModifierForwardType.ChildrenOnly;
        this.empire.AddChild(this.temporaryUnit);
    }
 public OrderEditHeroUnitDesign(int empireIndex, UnitDesign unitDesign) : base(empireIndex, unitDesign)
 {
 }
Пример #20
0
 private bool MayBuildIt(UnitDesign unitDesign)
 {
     return(true);
 }
 private bool UnitDesignFilter_NavyMilitaryUnit(UnitDesign unitDesign)
 {
     return(unitDesign.CheckAgainstTag(DownloadableContent16.SeafaringUnit));
 }
 private bool UnitDesignFilter_LandMilitaryUnit(UnitDesign unitDesign)
 {
     return(!unitDesign.CheckAgainstTag(DownloadableContent13.UnitTypeManta) && !unitDesign.CheckAgainstTag(DownloadableContent9.TagColossus) && !unitDesign.CheckAgainstTag(TradableUnit.ReadOnlyMercenary) && !unitDesign.CheckUnitAbility(UnitAbility.ReadonlyColonize, -1) && !unitDesign.CheckUnitAbility(UnitAbility.ReadonlyResettle, -1) && !unitDesign.CheckAgainstTag(DownloadableContent16.SeafaringUnit));
 }
Пример #23
0
 private bool IsMercenary(global::Empire designEmpire, UnitDesign unitDesign)
 {
     return(designEmpire != null && this.playerControllerRepositoryService != null && this.playerControllerRepositoryService.ActivePlayerController != null && this.playerControllerRepositoryService.ActivePlayerController.Empire.Index == designEmpire.Index && unitDesign.Tags.Contains(TradableUnit.ReadOnlyMercenary));
 }
Пример #24
0
    protected override IEnumerator OnShow(params object[] parameters)
    {
        if (this.Background != null)
        {
            this.Background.TintColor = this.NonEmbarkedBackgroundColor;
        }
        this.abilityReferences.Clear();
        if (this.context is IUnitAbilityController)
        {
            UnitAbilityReference[] abilities = (this.context as IUnitAbilityController).GetAbilities();
            if (abilities != null)
            {
                UnitAbilityReference[] array = abilities;
                for (int i = 0; i < array.Length; i++)
                {
                    UnitAbilityReference ability = array[i];
                    if (this.abilityReferences.Any((UnitAbilityReference match) => match.Name == ability.Name))
                    {
                        int index = this.abilityReferences.FindIndex((UnitAbilityReference match) => match.Name == ability.Name);
                        if (ability.Level > this.abilityReferences[index].Level)
                        {
                            this.abilityReferences[index] = ability;
                        }
                    }
                    else
                    {
                        this.abilityReferences.Add(ability);
                    }
                }
            }
        }
        this.abilityReferences.RemoveAll((UnitAbilityReference match) => !this.unitAbilityDatatable.ContainsKey(match.Name) || this.unitAbilityDatatable.GetValue(match.Name).Hidden);
        if (this.abilityReferences.Count > this.smallPrefabThreshold && this.abilityReferences.Count <= this.minimalPrefabThreshold && this.ResizeSelf)
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Small)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Small;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacitySmallPrefab, "Item");
        }
        else if (this.abilityReferences.Count > this.minimalPrefabThreshold && this.ResizeSelf)
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Minimal)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Minimal;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityMinimalPrefab, "Item");
        }
        else
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Normal)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Normal;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityPrefab, "Item");
        }
        GuiUnit guiUnit = this.context as GuiUnit;
        Unit    unit    = this.context as Unit;
        List <UnitAbilityReference> listToCheck   = new List <UnitAbilityReference>();
        List <UnitAbilityReference> HeroAbilities = new List <UnitAbilityReference>();
        List <UnitAbilityReference> ItemAbilities = new List <UnitAbilityReference>();
        UnitDesign unitDesign = null;

        if (unit != null)
        {
            unitDesign = unit.UnitDesign;
        }
        if (guiUnit != null)
        {
            unitDesign = guiUnit.UnitDesign;
        }
        if (unitDesign != null)
        {
            if (unitDesign.UnitBodyDefinition.UnitAbilities != null && unitDesign.UnitBodyDefinition.UnitAbilities.Length != 0)
            {
                listToCheck = unitDesign.UnitBodyDefinition.UnitAbilities.ToList <UnitAbilityReference>();
            }
            UnitProfile unitProfile = unitDesign as UnitProfile;
            if (unitProfile != null && unitProfile.ProfileAbilityReferences != null && unitProfile.ProfileAbilityReferences.Length != 0)
            {
                HeroAbilities = unitProfile.ProfileAbilityReferences.ToList <UnitAbilityReference>();
            }
            if (unitDesign.UnitEquipmentSet != null)
            {
                List <StaticString>        list     = new List <StaticString>(unitDesign.UnitEquipmentSet.Slots.Length);
                IDatabase <ItemDefinition> database = Databases.GetDatabase <ItemDefinition>(false);
                Diagnostics.Assert(database != null);
                for (int j = 0; j < unitDesign.UnitEquipmentSet.Slots.Length; j++)
                {
                    UnitEquipmentSet.Slot slot = unitDesign.UnitEquipmentSet.Slots[j];
                    if (!list.Contains(slot.ItemName))
                    {
                        StaticString   key = slot.ItemName.ToString().Split(DepartmentOfDefense.ItemSeparators)[0];
                        ItemDefinition itemDefinition;
                        if (database.TryGetValue(key, out itemDefinition))
                        {
                            Diagnostics.Assert(itemDefinition != null);
                            if (itemDefinition.AbilityReferences != null)
                            {
                                ItemAbilities.AddRange(itemDefinition.AbilityReferences);
                                list.Add(slot.ItemName);
                            }
                        }
                    }
                }
            }
        }
        this.abilityReferences.Sort(delegate(UnitAbilityReference left, UnitAbilityReference right)
        {
            bool flag   = !this.ContainsAbilityReference(HeroAbilities, left) && !this.ContainsAbilityReference(ItemAbilities, left);
            bool flag2  = this.ContainsAbilityReference(HeroAbilities, left);
            bool flag3  = this.ContainsAbilityReference(ItemAbilities, left);
            bool flag4  = !this.ContainsAbilityReference(HeroAbilities, right) && !this.ContainsAbilityReference(ItemAbilities, right);
            bool flag5  = this.ContainsAbilityReference(HeroAbilities, right);
            bool flag6  = this.ContainsAbilityReference(ItemAbilities, right);
            string x    = left.Name + Mathf.Max((float)left.Level, 0f);
            string text = "";
            GuiElement guiElement;
            if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement))
            {
                text = AgeLocalizer.Instance.LocalizeString(guiElement.Title);
            }
            x           = right.Name + Mathf.Max((float)right.Level, 0f);
            string strB = "";
            if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement))
            {
                strB = AgeLocalizer.Instance.LocalizeString(guiElement.Title);
            }
            if (flag && flag5)
            {
                return(-1);
            }
            if (flag && flag6)
            {
                return(-1);
            }
            if (flag2 && flag4)
            {
                return(1);
            }
            if (flag3 && flag4)
            {
                return(1);
            }
            if (flag2 && flag6)
            {
                return(-1);
            }
            if (flag3 && flag2)
            {
                return(1);
            }
            if ((flag && flag4) || (flag2 && flag5) || (flag3 && flag6))
            {
                return(text.CompareTo(strB));
            }
            return(0);
        });
        this.CapacitiesTable.RefreshChildrenIList <UnitAbilityReference>(this.abilityReferences, this.refreshAbilityReferenceDelegate, true, false);
        this.CapacitiesTable.ArrangeChildren();
        int num = this.CapacitiesTable.ComputeVisibleChildren();

        if (num > 0)
        {
            this.CapacitiesTable.Visible = true;
            AgeTransform ageTransform = this.CapacitiesTable.GetChildren()[num - 1];
            this.CapacitiesTable.Height = ageTransform.Y + ageTransform.Height + this.CapacitiesTable.VerticalMargin;
            this.Title.Text             = AgeLocalizer.Instance.LocalizeString("%FeatureCapacitiesTitle");
            if (this.ResizeSelf)
            {
                base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop + this.CapacitiesTable.Height + this.CapacitiesTable.PixelMarginBottom;
            }
            if (guiUnit != null && (guiUnit.Unit != null || guiUnit.UnitSnapshot != null) && this.Background != null && ((guiUnit.Unit != null && guiUnit.Unit.Embarked) || (guiUnit.UnitSnapshot != null && guiUnit.UnitSnapshot.Embarked)))
            {
                this.Title.Text           = "%FeatureCapacitiesEmbarkedTitle";
                this.Background.TintColor = this.EmbarkedBackgroundColor;
            }
            Color tintColor  = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor1"), 0)];
            Color tintColor2 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor2"), 2)];
            Color tintColor3 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor3"), 8)];
            for (int k = 0; k < this.abilityReferences.Count; k++)
            {
                FeatureItemCapacity component = this.CapacitiesTable.GetChildren()[k].GetComponent <FeatureItemCapacity>();
                if (component != null && !this.ContainsAbilityReference(listToCheck, this.abilityReferences[k]))
                {
                    component.Icon.TintColor = tintColor;
                    if (this.ContainsAbilityReference(HeroAbilities, this.abilityReferences[k]))
                    {
                        component.Icon.TintColor = tintColor2;
                    }
                    else if (this.ContainsAbilityReference(ItemAbilities, this.abilityReferences[k]))
                    {
                        component.Icon.TintColor = tintColor3;
                    }
                    else
                    {
                        component.Icon.TintColor = tintColor;
                    }
                }
                else if (component != null && this.ContainsAbilityReference(listToCheck, this.abilityReferences[k]))
                {
                    component.Icon.TintColor = tintColor;
                }
            }
        }
        else
        {
            this.CapacitiesTable.Visible = false;
            this.Title.Text = AgeLocalizer.Instance.LocalizeString("%FeatureNoCapacitiesTitle");
            if (this.ResizeSelf)
            {
                base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop;
            }
        }
        yield return(base.OnShow(parameters));

        yield break;
    }
Пример #25
0
    protected override void RefreshObjectives(StaticString context, StaticString pass)
    {
        base.RefreshObjectives(context, pass);
        this.averageMaximumMovementPoint = 4f;
        AIEmpireData aiempireData;

        if (this.empireDataAIHelper.TryGet(base.AIEntity.Empire.Index, out aiempireData) && aiempireData.AverageUnitDesignMaximumMovement > 0f)
        {
            this.averageMaximumMovementPoint = aiempireData.AverageUnitDesignMaximumMovement;
            this.hasShips = aiempireData.HasShips;
        }
        this.numberOfLivingMajorEmpire = 0;
        global::Game game = this.gameService.Game as global::Game;

        for (int i = 0; i < game.Empires.Length; i++)
        {
            if (game.Empires[i] is MajorEmpire)
            {
                MajorEmpire majorEmpire = game.Empires[i] as MajorEmpire;
                if (!majorEmpire.IsEliminated)
                {
                    this.numberOfLivingMajorEmpire++;
                }
                if (i != base.AIEntity.Empire.Index)
                {
                    this.UpdateHarassingScore(majorEmpire);
                }
            }
        }
        this.UpdateCitiesDefenseScore();
        this.UpdateArmiesSupportScore();
        this.canCreateAnotherColossus = false;
        this.buildableColossusUnitDesignData.Clear();
        this.colossusUnitDesignData.Clear();
        this.unitDesignDataRepository.FillUnitDesignByTags(base.AIEntity.Empire.Index, ref this.colossusUnitDesignData, this.colossusTags);
        for (int j = 0; j < this.colossusUnitDesignData.Count; j++)
        {
            UnitDesign unitDesign;
            if (this.departmentOfDefense.UnitDesignDatabase.TryGetValue(this.colossusUnitDesignData[j].UnitDesignModel, out unitDesign, false) && DepartmentOfTheTreasury.CheckConstructiblePrerequisites(base.AIEntity.Empire, unitDesign, new string[]
            {
                ConstructionFlags.AIColossusPrerequisite
            }))
            {
                this.canCreateAnotherColossus = true;
                break;
            }
        }
        if (!this.canCreateAnotherColossus)
        {
            return;
        }
        for (int k = this.colossusUnitDesignData.Count - 1; k >= 0; k--)
        {
            UnitDesign unitDesign;
            if (this.departmentOfDefense.UnitDesignDatabase.TryGetValue(this.colossusUnitDesignData[k].UnitDesignModel, out unitDesign, false))
            {
                this.missingResources = this.departmentOfTheTreasury.GetConstructibleMissingRessources(base.AIEntity.Empire, unitDesign);
                if (this.missingResources != null && this.missingResources.Count > 0)
                {
                    float num = 0f;
                    for (int l = 0; l < this.missingResources.Count; l++)
                    {
                        num += this.missingResources[l].MissingResourceValue / this.missingResources[l].AskedResourceValue;
                    }
                    float num2 = 0f;
                    for (int m = 0; m < unitDesign.Costs.Length; m++)
                    {
                        if (unitDesign.Costs[m].Instant)
                        {
                            num2 += 1f;
                        }
                    }
                    num /= num2;
                    if (num >= 0.4f)
                    {
                        goto IL_30E;
                    }
                }
                this.buildableColossusUnitDesignData.Add(this.colossusUnitDesignData[k]);
            }
            IL_30E :;
        }
        if (this.buildableColossusUnitDesignData.Count == 0)
        {
            return;
        }
        float      num3        = 0f;
        UnitDesign unitDesign2 = null;

        for (int n = 0; n < this.buildableColossusUnitDesignData.Count; n++)
        {
            UnitDesign unitDesign;
            if (this.departmentOfDefense.UnitDesignDatabase.TryGetValue(this.buildableColossusUnitDesignData[n].UnitDesignModel, out unitDesign, false))
            {
                float num4 = this.ComputeColossusScore(this.buildableColossusUnitDesignData[n], unitDesign);
                if (num4 > num3)
                {
                    num3        = num4;
                    unitDesign2 = unitDesign;
                }
            }
        }
        if (unitDesign2 == null)
        {
            return;
        }
        EvaluableMessage_Colossus evaluableMessage_Colossus = base.AIEntity.AIPlayer.Blackboard.FindFirst <EvaluableMessage_Colossus>(BlackboardLayerID.Empire, (EvaluableMessage_Colossus match) => match.State != BlackboardMessage.StateValue.Message_Canceled || match.State != BlackboardMessage.StateValue.Message_Failed);

        if (evaluableMessage_Colossus != null)
        {
            if (evaluableMessage_Colossus.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending || evaluableMessage_Colossus.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending_MissingResource || evaluableMessage_Colossus.EvaluationState == EvaluableMessage.EvaluableMessageState.Validate)
            {
                evaluableMessage_Colossus.ResetState();
                evaluableMessage_Colossus.ResetUnitDesign(unitDesign2);
            }
            else if (evaluableMessage_Colossus.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtaining)
            {
                evaluableMessage_Colossus = null;
            }
        }
        if (evaluableMessage_Colossus == null)
        {
            evaluableMessage_Colossus = new EvaluableMessage_Colossus(new HeuristicValue(0f), new HeuristicValue(0f), unitDesign2, -1, 1, AILayer_AccountManager.MilitaryAccountName);
            base.AIEntity.AIPlayer.Blackboard.AddMessage(evaluableMessage_Colossus);
        }
        float globalMotivation = this.ComputeGlobalPriority();
        float localOpportunity = this.ComputeLocalPriority();

        evaluableMessage_Colossus.Refresh(globalMotivation, localOpportunity);
        evaluableMessage_Colossus.TimeOut = 1;
    }