protected override bool TryComputeArmyMissionParameter()
    {
        if (!base.AIDataArmyGUID.IsValid)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return(false);
        }
        AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID);

        if (aidata == null || aidata.Army == null)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return(false);
        }
        if (aidata.Army.IsLocked || aidata.Army.IsInEncounter)
        {
            return(false);
        }
        if (this.AICommanderRegroupArmies.MissionHasAllUnits(this))
        {
            RequestGarrisonMessage requestGarrisonMessage = null;
            if (this.AICommanderRegroupArmies != null && this.AICommanderRegroupArmies.RequestUnitListMessageID != 0UL)
            {
                requestGarrisonMessage = (base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonMessage);
            }
            if (requestGarrisonMessage == null)
            {
                RequestGarrisonCampMessage requestGarrisonCampMessage = null;
                if (this.AICommanderRegroupArmies != null && this.AICommanderRegroupArmies.RequestUnitListMessageID != 0UL)
                {
                    requestGarrisonCampMessage = (base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonCampMessage);
                }
                if (requestGarrisonCampMessage == null)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Success;
                    return(false);
                }
                IGameEntity gameEntity;
                if (!this.gameEntityRepositoryService.TryGetValue(requestGarrisonCampMessage.CampGuid, out gameEntity))
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    return(false);
                }
                Camp camp = gameEntity as Camp;
                if (camp == null)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    return(false);
                }
                if (!this.AICommanderRegroupArmies.FinalPosition.IsValid)
                {
                    this.AICommanderRegroupArmies.FinalPosition = camp.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonCampMessage.FinalPosition    = this.AICommanderRegroupArmies.FinalPosition;
                }
                Army armyAtPosition = this.worldPositionningService.GetArmyAtPosition(this.AICommanderRegroupArmies.FinalPosition);
                if (armyAtPosition != null && armyAtPosition.GUID != base.AIDataArmyGUID)
                {
                    this.AICommanderRegroupArmies.FinalPosition = camp.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonCampMessage.FinalPosition    = this.AICommanderRegroupArmies.FinalPosition;
                }
                bool flag = false;
                for (int i = 0; i < camp.Districts.Count; i++)
                {
                    if (camp.Districts[i].Type != DistrictType.Exploitation && camp.Districts[i].Type != DistrictType.Improvement && this.worldPositionningService.GetDistance(this.AICommanderRegroupArmies.FinalPosition, camp.Districts[i].WorldPosition) <= 1)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    this.AICommanderRegroupArmies.FinalPosition = camp.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonCampMessage.FinalPosition    = this.AICommanderRegroupArmies.FinalPosition;
                }
                if (aidata.Army.WorldPosition == this.AICommanderRegroupArmies.FinalPosition)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Success;
                    return(false);
                }
            }
            else
            {
                IGameEntity gameEntity2;
                if (!this.gameEntityRepositoryService.TryGetValue(requestGarrisonMessage.CityGuid, out gameEntity2))
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    return(false);
                }
                City city = gameEntity2 as City;
                if (city == null)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    return(false);
                }
                if (city.IsInEncounter)
                {
                    return(false);
                }
                if (city.BesiegingEmpire != null)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
                    return(false);
                }
                if (!this.AICommanderRegroupArmies.FinalPosition.IsValid)
                {
                    this.AICommanderRegroupArmies.FinalPosition = city.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonMessage.FinalPosition        = this.AICommanderRegroupArmies.FinalPosition;
                }
                Army armyAtPosition2 = this.worldPositionningService.GetArmyAtPosition(this.AICommanderRegroupArmies.FinalPosition);
                if (armyAtPosition2 != null && armyAtPosition2.GUID != base.AIDataArmyGUID)
                {
                    this.AICommanderRegroupArmies.FinalPosition = city.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonMessage.FinalPosition        = this.AICommanderRegroupArmies.FinalPosition;
                }
                bool flag2 = false;
                for (int j = 0; j < city.Districts.Count; j++)
                {
                    if (city.Districts[j].Type != DistrictType.Exploitation && city.Districts[j].Type != DistrictType.Improvement && this.worldPositionningService.GetDistance(this.AICommanderRegroupArmies.FinalPosition, city.Districts[j].WorldPosition) <= 1)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    this.AICommanderRegroupArmies.FinalPosition = city.GetValidDistrictToTarget(aidata.Army).WorldPosition;
                    requestGarrisonMessage.FinalPosition        = this.AICommanderRegroupArmies.FinalPosition;
                }
                if (aidata.Army.WorldPosition == this.AICommanderRegroupArmies.FinalPosition)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Success;
                    return(false);
                }
            }
        }
        if (this.targetTransferArmy != null)
        {
            if (this.targetTransferArmy.Army == null)
            {
                this.targetTransferArmy = null;
            }
            else
            {
                if (!this.targetTransferArmy.Army.IsInEncounter && !this.targetTransferArmy.Army.IsLocked)
                {
                    return(false);
                }
                this.targetTransferArmy = null;
            }
        }
        foreach (AICommanderMission aicommanderMission in this.AICommanderRegroupArmies.Missions)
        {
            AICommanderMission_RegroupArmyAt aicommanderMission_RegroupArmyAt = (AICommanderMission_RegroupArmyAt)aicommanderMission;
            if (aicommanderMission_RegroupArmyAt != this && aicommanderMission_RegroupArmyAt.targetTransferArmy == aidata)
            {
                if (!aidata.Army.IsLocked && !aidata.Army.IsInEncounter)
                {
                    return(false);
                }
                aicommanderMission_RegroupArmyAt.targetTransferArmy = null;
            }
        }
        if (this.AICommanderRegroupArmies != null && this.AICommanderRegroupArmies.AIPlayer != null && this.AICommanderRegroupArmies.AIPlayer.AIEntities != null)
        {
            AIEntity_Empire aientity_Empire = this.AICommanderRegroupArmies.AIPlayer.AIEntities.Find((AIEntity match) => match is AIEntity_Empire) as AIEntity_Empire;
            if (aientity_Empire != null)
            {
                AICommanderMission_PrivateersHarass aicommanderMission_PrivateersHarass = aientity_Empire.GetCommanderMissionBasedOnItsArmyRequestArmy(this.AICommanderRegroupArmies.RequestUnitListMessageID) as AICommanderMission_PrivateersHarass;
                if (aicommanderMission_PrivateersHarass != null && aicommanderMission_PrivateersHarass.TargetCity != null && !aidata.Army.IsPrivateers && base.TryCreateArmyMission("ConvertToPrivateers", new List <object>
                {
                    aicommanderMission_PrivateersHarass.TargetCity
                }))
                {
                    base.State = TickableState.NeedTick;
                    RequestUnitListMessage requestUnitListMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestUnitListMessage;
                    if (requestUnitListMessage != null)
                    {
                        requestUnitListMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.Regrouping;
                    }
                    return(true);
                }
            }
        }
        WorldPosition worldPosition;

        if (this.IsMaster)
        {
            if (this.IsArmyBesiegingACity(base.AIDataArmyGUID) && !aidata.Army.IsPrivateers)
            {
                return(false);
            }
            if (this.CanTransferToNearMission())
            {
                return(false);
            }
            AICommanderMission_RegroupArmyAt aicommanderMission_RegroupArmyAt2 = null;
            int num = int.MaxValue;
            foreach (AICommanderMission aicommanderMission2 in this.AICommanderRegroupArmies.Missions)
            {
                AICommanderMission_RegroupArmyAt aicommanderMission_RegroupArmyAt3 = (AICommanderMission_RegroupArmyAt)aicommanderMission2;
                if (aicommanderMission_RegroupArmyAt3 != this)
                {
                    WorldPosition unitsToRegroupPosition = aicommanderMission_RegroupArmyAt3.GetUnitsToRegroupPosition();
                    if (unitsToRegroupPosition.IsValid)
                    {
                        int distance = this.worldPositionningService.GetDistance(aidata.Army.WorldPosition, unitsToRegroupPosition);
                        if (distance < num)
                        {
                            num = distance;
                            aicommanderMission_RegroupArmyAt2 = aicommanderMission_RegroupArmyAt3;
                        }
                    }
                }
            }
            if (aicommanderMission_RegroupArmyAt2 == null)
            {
                if (!this.AICommanderRegroupArmies.FinalPosition.IsValid)
                {
                    base.Completion = AICommanderMission.AICommanderMissionCompletion.Success;
                    return(false);
                }
                worldPosition = this.AICommanderRegroupArmies.FinalPosition;
            }
            else
            {
                worldPosition = aicommanderMission_RegroupArmyAt2.GetUnitsToRegroupPosition();
            }
        }
        else
        {
            if (this.CanTransferToNearMission())
            {
                return(false);
            }
            AICommanderMission_RegroupArmyAt masterMission = this.AICommanderRegroupArmies.MasterMission;
            if (masterMission == null)
            {
                return(false);
            }
            worldPosition = masterMission.GetUnitsToRegroupPosition();
        }
        base.State = TickableState.NoTick;
        if (aidata.Army.GetPropertyValue(SimulationProperties.Movement) > 0f)
        {
            int num2 = Math.Min(4, Math.Max(1, (this.worldPositionningService.GetDistance(worldPosition, aidata.Army.WorldPosition) - 1) / 2));
            PathfindingContext pathfindingContext = aidata.Army.GenerateContext();
            pathfindingContext.Greedy = true;
            PathfindingResult pathfindingResult = this.pathfindingService.FindPath(pathfindingContext, aidata.Army.WorldPosition, worldPosition, PathfindingManager.RequestMode.Default, null, PathfindingFlags.IgnoreFogOfWar, null);
            if (pathfindingResult != null)
            {
                int           num3           = 0;
                WorldPosition worldPosition2 = WorldPosition.Invalid;
                foreach (WorldPosition worldPosition3 in pathfindingResult.GetCompletePath())
                {
                    if (worldPosition3 != pathfindingResult.Start)
                    {
                        num3++;
                        if ((num3 <= num2 || !worldPosition2.IsValid) && worldPosition3 != worldPosition && this.pathfindingService.IsTileStopable(worldPosition3, aidata.Army, (PathfindingFlags)0, null))
                        {
                            worldPosition2 = worldPosition3;
                        }
                        if (num3 >= num2 && worldPosition2.IsValid && base.TryCreateArmyMission("ReachPosition", new List <object>
                        {
                            worldPosition2
                        }))
                        {
                            base.State = TickableState.NeedTick;
                            this.SetRequestMessageExecutionState(RequestUnitListMessage.RequestUnitListState.Regrouping);
                            return(true);
                        }
                    }
                }
            }
            if (base.Commander.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitMimics1))
            {
                DepartmentOfTheInterior agency = base.Commander.Empire.GetAgency <DepartmentOfTheInterior>();
                if (agency.NonInfectedCities.Count > 0 && base.TryCreateArmyMission("ReachPositionMykara", new List <object>
                {
                    agency.NonInfectedCities[0].WorldPosition
                }))
                {
                    base.State = TickableState.NeedTick;
                    this.SetRequestMessageExecutionState(RequestUnitListMessage.RequestUnitListState.Regrouping);
                    return(true);
                }
            }
        }
        return(false);
    }