コード例 #1
0
    protected override void CreateLocalNeeds(StaticString context, StaticString pass)
    {
        AILayer_Military layer = base.AIEntity.GetLayer <AILayer_Military>();

        base.CreateLocalNeeds(context, pass);
        this.VerifyAndUpdateRecruitementLocks();
        Diagnostics.Assert(base.AIEntity != null && base.AIEntity.AIPlayer != null && base.AIEntity.AIPlayer.Blackboard != null);
        IEnumerable <RequestUnitListMessage> messages = base.AIEntity.AIPlayer.Blackboard.GetMessages <RequestUnitListMessage>(BlackboardLayerID.Empire);

        Diagnostics.Assert(messages != null);
        List <RequestUnitListMessage> list = new List <RequestUnitListMessage>(messages);

        Diagnostics.Assert(this.Empire != null);
        list.RemoveAll((RequestUnitListMessage match) => match.EmpireTarget != this.Empire.Index);
        this.ResetRequestArmyMessages();
        this.countByUnitModel.Clear();
        list.Sort((RequestUnitListMessage left, RequestUnitListMessage right) => - 1 * left.Priority.CompareTo(right.Priority));
        this.intelligenceAIHelper.FillAvailableUnitDesignList(this.Empire);
        Diagnostics.Assert(this.intelligenceAIHelper != null);
        for (int i = 0; i < list.Count; i++)
        {
            RequestUnitListMessage requestUnitListMessage = list[i];
            if (float.IsNaN(requestUnitListMessage.Priority) || float.IsInfinity(requestUnitListMessage.Priority))
            {
                AILayer.LogWarning("[SCORING] Skipping RequestUnitListMessage {0} with a priority of {1}", new object[]
                {
                    requestUnitListMessage.CommanderCategory,
                    requestUnitListMessage.Priority
                });
            }
            else if (AILayer_ArmyRecruitment.IsCommanderMissionNotInteresting(requestUnitListMessage.CommanderCategory))
            {
                requestUnitListMessage.State   = BlackboardMessage.StateValue.Message_Canceled;
                requestUnitListMessage.TimeOut = 0;
            }
            else
            {
                BlackboardMessage.StateValue state = requestUnitListMessage.State;
                if (state != BlackboardMessage.StateValue.Message_None)
                {
                    if (state == BlackboardMessage.StateValue.Message_Success || state == BlackboardMessage.StateValue.Message_Canceled)
                    {
                        goto IL_1F3;
                    }
                    if (state != BlackboardMessage.StateValue.Message_InProgress)
                    {
                        AILayer.LogError("[AILayer_ArmyRecruitment] Unknow state for RequestArmyMessage {0}", new object[]
                        {
                            requestUnitListMessage.State
                        });
                        goto IL_1F3;
                    }
                }
                if (requestUnitListMessage.ExecutionState == RequestUnitListMessage.RequestUnitListState.Pending)
                {
                    Intelligence.BestRecruitementCombination bestRecruitementCombination;
                    if (requestUnitListMessage is RequestGarrisonMessage)
                    {
                        bestRecruitementCombination = null;
                    }
                    else if (requestUnitListMessage is RequestGarrisonCampMessage)
                    {
                        bestRecruitementCombination = null;
                    }
                    else
                    {
                        bestRecruitementCombination = this.intelligenceAIHelper.FillArmyPattern(this.Empire.Index, requestUnitListMessage, layer);
                    }
                    if (bestRecruitementCombination != null)
                    {
                        this.RecruitArmiesUnits(requestUnitListMessage, bestRecruitementCombination);
                    }
                }
            }
            IL_1F3 :;
        }
        this.ResetRecruitementLocks();
        this.RegroupSmallFreeArmies();
        this.CleanupRequestUnitMessages();
    }
コード例 #2
0
    private void RegroupSmallFreeArmies()
    {
        List <Army> list = new List <Army>();
        IAIDataRepositoryAIHelper service = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>();

        this.smallEntitiesToRegroup.Clear();
        this.tempEntitiesToRegroup.Clear();
        int num = (int)this.Empire.GetPropertyValue(SimulationProperties.ArmyUnitSlot);
        DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.Armies.Count; i++)
        {
            Army        army   = agency.Armies[i];
            AIData_Army aidata = service.GetAIData <AIData_Army>(army.GUID);
            if (aidata != null && !aidata.IsSolitary && !aidata.Army.IsSeafaring && !aidata.Army.HasCatspaw && !(aidata.Army is KaijuArmy))
            {
                if (aidata.CommanderMission != null)
                {
                    if (aidata.CommanderMission.Commander == null)
                    {
                        AILayer.LogError("[AILayer_ArmyRecruitment] Commander Mission without a commander");
                        goto IL_131;
                    }
                    if (!AILayer_ArmyRecruitment.IsCommanderMissionNotInteresting(aidata.CommanderMission.Commander.Category))
                    {
                        goto IL_131;
                    }
                }
                else if (!aidata.IsTaggedFreeForExploration())
                {
                    goto IL_131;
                }
                if (army.StandardUnits.Count < num)
                {
                    if (!this.IsMercArmy(aidata.Army))
                    {
                        this.smallEntitiesToRegroup.Add(aidata);
                    }
                    else
                    {
                        list.Add(aidata.Army);
                    }
                }
            }
            IL_131 :;
        }
        if (this.Empire is MajorEmpire)
        {
            DepartmentOfTheInterior agency2 = this.Empire.GetAgency <DepartmentOfTheInterior>();
            if (agency2 != null)
            {
                for (int j = 0; j < agency2.Cities.Count; j++)
                {
                    City garrison = agency2.Cities[j];
                    this._Internal_RegroupSmallFreeArmies(garrison);
                }
            }
            List <Village> convertedVillages = ((MajorEmpire)this.Empire).ConvertedVillages;
            for (int k = 0; k < convertedVillages.Count; k++)
            {
                Village village = convertedVillages[k];
                if (village != null)
                {
                    this._Internal_RegroupSmallFreeArmies(village);
                }
            }
        }
        while (this.smallEntitiesToRegroup.Count > 1)
        {
            AIData_GameEntity aidata_GameEntity = this.smallEntitiesToRegroup[0];
            this.smallEntitiesToRegroup.RemoveAt(0);
            int num2;
            if (aidata_GameEntity is AIData_Army)
            {
                num2 = (aidata_GameEntity as AIData_Army).Army.StandardUnits.Count;
            }
            else
            {
                if (!(aidata_GameEntity is AIData_Unit))
                {
                    continue;
                }
                num2 = 1;
            }
            this.tempEntitiesToRegroup.Clear();
            this.tempEntitiesToRegroup.Add(aidata_GameEntity);
            int num3 = this.smallEntitiesToRegroup.Count - 1;
            while (num3 >= 0 && num2 < num)
            {
                AIData_GameEntity item = this.smallEntitiesToRegroup[num3];
                int num4;
                if (aidata_GameEntity is AIData_Army)
                {
                    num4 = (aidata_GameEntity as AIData_Army).Army.StandardUnits.Count;
                    goto IL_29E;
                }
                if (aidata_GameEntity is AIData_Unit)
                {
                    num4 = 1;
                    goto IL_29E;
                }
IL_296:
                num3--;
                continue;
IL_29E:
                if (num2 + num4 <= num)
                {
                    num2 += num4;
                    this.tempEntitiesToRegroup.Add(item);
                    this.smallEntitiesToRegroup.RemoveAt(num3);
                    goto IL_296;
                }
                goto IL_296;
            }
            if (this.tempEntitiesToRegroup.Count > 1)
            {
                this.unitsGUIDS.Clear();
                for (int l = 0; l < this.tempEntitiesToRegroup.Count; l++)
                {
                    AIData_GameEntity aidata_GameEntity2 = this.tempEntitiesToRegroup[l];
                    if (aidata_GameEntity2 is AIData_Army)
                    {
                        AIData_Army aidata_Army = aidata_GameEntity2 as AIData_Army;
                        if (aidata_Army.CommanderMission != null)
                        {
                            aidata_Army.CommanderMission.Interrupt();
                        }
                        for (int m = 0; m < aidata_Army.Army.StandardUnits.Count; m++)
                        {
                            AIData_Unit aidata_Unit;
                            if (service.TryGetAIData <AIData_Unit>(aidata_Army.Army.StandardUnits[m].GUID, out aidata_Unit))
                            {
                                aidata_Unit.ReservationExtraTag = AIData_Unit.AIDataReservationExtraTag.None;
                                this.unitsGUIDS.Add(aidata_Unit.Unit.GUID);
                            }
                        }
                    }
                    else if (aidata_GameEntity2 is AIData_Unit)
                    {
                        AIData_Unit aidata_Unit2 = aidata_GameEntity2 as AIData_Unit;
                        aidata_Unit2.ReservationExtraTag = AIData_Unit.AIDataReservationExtraTag.None;
                        this.unitsGUIDS.Add(aidata_Unit2.Unit.GUID);
                    }
                }
                if (this.unitsGUIDS.Count != 0)
                {
                    this.CreateNewCommanderRegroup(this.unitsGUIDS.ToArray(), null);
                }
            }
        }
        if (list.Count > 1)
        {
            int num5 = 0;
            List <GameEntityGUID> list2 = new List <GameEntityGUID>();
            for (int n = 0; n < list.Count; n++)
            {
                num5++;
                foreach (Unit unit in list[n].StandardUnits)
                {
                    AIData_Unit aidata_Unit3;
                    if (service.TryGetAIData <AIData_Unit>(unit.GUID, out aidata_Unit3))
                    {
                        aidata_Unit3.ReservationExtraTag = AIData_Unit.AIDataReservationExtraTag.None;
                        list2.Add(aidata_Unit3.Unit.GUID);
                        if (list2.Count >= num)
                        {
                            this.CreateNewCommanderRegroup(list2.ToArray(), null);
                            list2.Clear();
                            num5 = 0;
                            break;
                        }
                    }
                }
            }
            if (num5 > 1)
            {
                this.CreateNewCommanderRegroup(list2.ToArray(), null);
            }
        }
    }