private float ComputeDestroyInterest(CreepingNode target, AIEntity_Empire entityEmpire, Army army)
    {
        float             normalizedScore = 0.1f;
        AILayer_Diplomacy layer           = entityEmpire.GetLayer <AILayer_Diplomacy>();

        if (layer != null)
        {
            float num  = layer.GetWantWarScore(target.Empire);
            float num2 = layer.GetAllyScore(target.Empire);
            if (num2 > 0.5f || num < 0.25f || layer.GetPeaceWish(target.Empire.Index))
            {
                return(-1f);
            }
            num  = (num - 0.25f) / 0.75f;
            num2 = (num2 - 0.5f) / 0.5f;
            float boostFactor = 0.2f * (num - num2);
            normalizedScore = AILayer.Boost(normalizedScore, boostFactor);
        }
        float propertyValue = army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower);
        float num3          = target.Empire.GetPropertyValue(SimulationProperties.MilitaryPower);

        if (num3 == 0f)
        {
            num3 = 1f;
        }
        float num4 = propertyValue / num3;

        if (num4 < 1f)
        {
            return(-1f);
        }
        float boostFactor2 = Mathf.Clamp01(num4 / 2f) * 0.2f;

        return(AILayer.Boost(normalizedScore, boostFactor2));
    }
Beispiel #2
0
    public override void Load()
    {
        base.Load();
        if (!this.TargetGUID.IsValid)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return;
        }
        IGameEntity gameEntity;

        if (this.gameEntityRepositoryService.TryGetValue(this.TargetGUID, out gameEntity) && gameEntity is PointOfInterest)
        {
            this.POI = (gameEntity as PointOfInterest);
        }
        AIEntity_Empire entity = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>();

        this.QuestBTlayer = entity.GetLayer <AILayer_QuestBTController>();
        if (this.POI != null)
        {
            this.village = this.POI.Region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(this.POI.WorldPosition);
            return;
        }
        if (gameEntity is TerraformDevice)
        {
            this.device = (gameEntity as TerraformDevice);
        }
    }
    public override void Reset()
    {
        base.Reset();
        if (!base.Enable)
        {
            return;
        }
        if (this.departmentOfTheInterior == null)
        {
            Diagnostics.LogError("The agent {0} can't get the department of interior.", new object[]
            {
                base.Name
            });
            base.Enable = false;
            return;
        }
        Agent[] validatedAgents = new AgentGroupPath("ResourceEvaluationAmas/CityAgentGroup").GetValidatedAgents(base.ParentGroup, "NetCityMoney");
        SimulationNormalizedAgent[] array;
        if (validatedAgents != null)
        {
            array = Array.ConvertAll <Agent, SimulationNormalizedAgent>(validatedAgents, (Agent agent) => agent as SimulationNormalizedAgent);
        }
        else
        {
            array = new SimulationNormalizedAgent[0];
        }
        this.netCityMoneyAgents = array;
        Diagnostics.Assert(this.netCityMoneyAgents != null);
        AIEntity_Empire entity = (base.ContextObject as AIPlayer_MajorEmpire).GetEntity <AIEntity_Empire>();

        this.aILayer_Victory = entity.GetLayer <AILayer_Victory>();
    }
Beispiel #4
0
    protected override bool Initialize(AIBehaviorTree aiBehaviorTree)
    {
        this.isDlcActive = true;
        IDownloadableContentService service = Services.GetService <IDownloadableContentService>();

        if (!service.IsShared(DownloadableContent13.ReadOnlyName))
        {
            this.isDlcActive = false;
        }
        if (!(aiBehaviorTree.AICommander.Empire is MajorEmpire))
        {
            this.isDlcActive = false;
        }
        if (this.isDlcActive)
        {
            IGameService service2 = Services.GetService <IGameService>();
            Diagnostics.Assert(service2 != null);
            this.gameEntityRepositoryService = service2.Game.Services.GetService <IGameEntityRepositoryService>();
            this.aiDataRepositoryHelper      = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>();
            this.orbAIHelper          = AIScheduler.Services.GetService <IOrbAIHelper>();
            this.intelligenceAiHelper = AIScheduler.Services.GetService <IIntelligenceAIHelper>();
            AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
            this.accountManager = entity.GetLayer <AILayer_AccountManager>();
        }
        return(base.Initialize(aiBehaviorTree));
    }
Beispiel #5
0
 protected override bool Initialize(AIBehaviorTree aiBehaviorTree)
 {
     if (aiBehaviorTree.AICommander.Empire is MajorEmpire)
     {
         AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
         this.aILayer_Trade = entity.GetLayer <AILayer_Trade>();
     }
     return(base.Initialize(aiBehaviorTree));
 }
    private float ComputePillageInterest(PointOfInterest target, AIEntity_Empire entityEmpire, Army army)
    {
        float             normalizedScore = 0.1f;
        AILayer_Diplomacy layer           = entityEmpire.GetLayer <AILayer_Diplomacy>();

        if (layer != null)
        {
            if (layer.GetPeaceWish(target.Region.City.Empire.Index))
            {
                return(-1f);
            }
            float num  = layer.GetWantWarScore(target.Region.City.Empire);
            float num2 = layer.GetAllyScore(target.Region.City.Empire);
            if (num2 > 0.5f || num < 0.25f)
            {
                return(-1f);
            }
            num  = (num - 0.25f) / 0.75f;
            num2 = (num2 - 0.5f) / 0.5f;
            float boostFactor = 0.2f * (num - num2);
            normalizedScore = AILayer.Boost(normalizedScore, boostFactor);
        }
        float propertyValue = army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower);
        float num3          = target.Region.City.Empire.GetPropertyValue(SimulationProperties.MilitaryPower);

        if (num3 == 0f)
        {
            num3 = 1f;
        }
        float num4 = propertyValue / num3;

        if (num4 < 1f)
        {
            return(-1f);
        }
        float boostFactor2 = Mathf.Clamp01(num4 / 2f) * 0.2f;

        normalizedScore = AILayer.Boost(normalizedScore, boostFactor2);
        string a = target.Type;
        float  boostFactor3;

        if (a == "ResourceDeposit")
        {
            boostFactor3 = 0.2f;
        }
        else if (a == "WatchTower")
        {
            boostFactor3 = 0.2f;
        }
        else
        {
            boostFactor3 = 0.2f;
        }
        normalizedScore = AILayer.Boost(normalizedScore, boostFactor3);
        return(AILayer.Boost(normalizedScore, this.ComputeInfluence(army, target) * 0.5f));
    }
Beispiel #7
0
    public override void Load()
    {
        base.Load();
        IGameService service = Services.GetService <IGameService>();

        this.gameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>();
        this.departmentOfScience         = base.Empire.GetAgency <DepartmentOfScience>();
        this.departmentOfInternalAffairs = base.Empire.GetAgency <DepartmentOfInternalAffairs>();
        AIEntity_Empire entity = base.AIPlayer.GetEntity <AIEntity_Empire>();

        this.villageLayer = entity.GetLayer <AILayer_Village>();
    }
Beispiel #8
0
 private float ComputeOrbCollectingScore(OrbSpawnInfo orbSpawn, AIEntity_Empire entityEmpire, Army army)
 {
     if (this.DiplomacyLayer != null)
     {
         Region region = this.worldPositionningService.GetRegion(orbSpawn.WorldPosition);
         if (region.Owner != null && region.Owner is MajorEmpire && this.DiplomacyLayer.GetPeaceWish(region.Owner.Index))
         {
             return(-1f);
         }
     }
     return(orbSpawn.EmpireNeedModifier[entityEmpire.Empire.Index]);
 }
    public override bool Initialize(BehaviourTree behaviourTree)
    {
        IGameService service = Services.GetService <IGameService>();

        this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>();
        if ((behaviourTree as AIBehaviorTree).AICommander.Empire is MajorEmpire)
        {
            AIEntity_Empire entity = (behaviourTree as AIBehaviorTree).AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
            this.aILayer_Terraformation = entity.GetLayer <AILayer_Terraformation>();
        }
        return(base.Initialize(behaviourTree));
    }
Beispiel #10
0
    protected override bool Initialize(AIBehaviorTree aiBehaviorTree)
    {
        if (aiBehaviorTree.AICommander.Empire is MajorEmpire)
        {
            AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
            this.aILayer_Trade = entity.GetLayer <AILayer_Trade>();
        }
        ArmyAction armyAction;

        Databases.GetDatabase <ArmyAction>(false).TryGetValue("ArmyActionTameUnstunnedKaiju", out armyAction);
        this.armyAction_TameUnstunnedKaiju = (armyAction as ArmyAction_TameUnstunnedKaiju);
        return(base.Initialize(aiBehaviorTree));
    }
Beispiel #11
0
    public override void Load()
    {
        base.Load();
        if (this.RegionTarget == null || this.RegionTarget.MinorEmpire == null)
        {
            base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return;
        }
        this.departmentOfInternalAffairs = base.Commander.Empire.GetAgency <DepartmentOfInternalAffairs>();
        this.barbarianCouncil            = this.RegionTarget.MinorEmpire.GetAgency <BarbarianCouncil>();
        AIEntity_Empire entity = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>();

        this.villageLayer = entity.GetLayer <AILayer_Village>();
        this.Village      = this.SelectVillage();
    }
    public override void Initialize(AICommander commander)
    {
        base.Initialize(commander);
        Diagnostics.Assert(AIScheduler.Services != null);
        this.intelligenceAiHelper = AIScheduler.Services.GetService <IIntelligenceAIHelper>();
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>();
        Diagnostics.Assert(this.worldPositionningService != null);
        this.pathfindingService    = service.Game.Services.GetService <IPathfindingService>();
        this.personalityAIHelper   = AIScheduler.Services.GetService <IPersonalityAIHelper>();
        this.unitInGarrisonPercent = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitInGarrisonPercent"), this.unitInGarrisonPercent);
        this.unitInGarrisonPriorityMultiplierPerSlot = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitInGarrisonPriorityMultiplierPerSlot"), this.unitInGarrisonPriorityMultiplierPerSlot);
        this.unitRatioBoost = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitRatioBoost"), this.unitRatioBoost);
        AIEntity_Empire entity = commander.AIPlayer.GetEntity <AIEntity_Empire>();

        this.militaryLayer = entity.GetLayer <AILayer_Military>();
    }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        DepartmentOfScience agency = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>();

        if (agency != null && !agency.CanPillage())
        {
            return(State.Failure);
        }
        if (!this.downloadableContentService.IsShared(DownloadableContent11.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName))
        {
            return(State.Failure);
        }
        if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName))
        {
            this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName];
        }
        List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>;

        if (list == null)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        if (list.Count == 0)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        AIEntity_Empire entity          = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
        float           num             = 0.1f;
        float           propertyValue   = army.GetPropertyValue(SimulationProperties.MaximumMovement);
        PointOfInterest pointOfInterest = null;

        for (int i = 0; i < list.Count; i++)
        {
            PointOfInterest pointOfInterest2 = list[i] as PointOfInterest;
            if (pointOfInterest2 != null && pointOfInterest2.Region.City != null && pointOfInterest2.PointOfInterestImprovement != null && DepartmentOfDefense.CanStartPillage(army, pointOfInterest2, false))
            {
                float num2 = 0.5f;
                if (entity != null)
                {
                    num2 = this.ComputePillageInterest(pointOfInterest2, entity, army) * 0.5f;
                }
                if (num2 >= 0f)
                {
                    float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest2.WorldPosition) / propertyValue;
                    if (num3 <= this.MaximumTurnDistance)
                    {
                        float num4 = 0.5f - num3 / this.MaximumTurnDistance;
                        num2 = AILayer.Boost(num2, num4 * 0.5f);
                        float propertyValue2 = pointOfInterest2.GetPropertyValue(SimulationProperties.PillageDefense);
                        float propertyValue3 = pointOfInterest2.GetPropertyValue(SimulationProperties.MaximumPillageDefense);
                        num2 = AILayer.Boost(num2, (1f - propertyValue2 / propertyValue3) * 0.2f);
                        if (num2 > num)
                        {
                            num             = num2;
                            pointOfInterest = pointOfInterest2;
                        }
                    }
                }
            }
        }
        if (pointOfInterest != null)
        {
            if (this.OpportunityMaximumTurn > 0f)
            {
                int num5 = 0;
                int num6 = 0;
                if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition))
                {
                    WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition];
                    if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, pointOfInterest.WorldPosition, mainTargetPosition, out num6, out num5))
                    {
                        return(State.Failure);
                    }
                }
                int remainingTurnToPillage        = DepartmentOfDefense.GetRemainingTurnToPillage(army, pointOfInterest);
                IAIDataRepositoryAIHelper service = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>();
                Diagnostics.Assert(service != null);
                float       num7 = 1f;
                AIData_Army aidata_Army;
                if (service.TryGetAIData <AIData_Army>(army.GUID, out aidata_Army))
                {
                    num7 = aiBehaviorTree.AICommander.GetPillageModifier(aidata_Army.CommanderMission);
                }
                if ((float)(num5 - num6 + remainingTurnToPillage) > this.OpportunityMaximumTurn * num7)
                {
                    return(State.Failure);
                }
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = pointOfInterest;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, pointOfInterest);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (!this.downloadableContentService.IsShared(DownloadableContent20.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
        if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName))
        {
            return(State.Failure);
        }
        if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName))
        {
            this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName];
        }
        List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>;

        if (list == null)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        if (list.Count == 0)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        AIEntity_Empire entity          = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
        float           num             = 0.1f;
        float           propertyValue   = army.GetPropertyValue(SimulationProperties.MaximumMovement);
        PointOfInterest pointOfInterest = null;

        for (int i = 0; i < list.Count; i++)
        {
            PointOfInterest pointOfInterest2 = list[i] as PointOfInterest;
            if (pointOfInterest2 != null)
            {
                if (pointOfInterest2.CreepingNodeImprovement != null)
                {
                    CreepingNode creepingNode = null;
                    IGameEntity  gameEntity   = null;
                    if (this.gameEntityRepositoryService.TryGetValue(pointOfInterest2.CreepingNodeGUID, out gameEntity))
                    {
                        creepingNode = (gameEntity as CreepingNode);
                    }
                    if (creepingNode != null)
                    {
                        if (DepartmentOfDefense.CanDismantleCreepingNode(army, creepingNode, false))
                        {
                            float num2 = 0.5f;
                            if (entity != null)
                            {
                                num2 = this.ComputeDestroyInterest(creepingNode, entity, army) * 0.5f;
                            }
                            if (num2 >= 0f)
                            {
                                float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest2.WorldPosition);
                                float num4 = num3 / propertyValue;
                                if (num4 <= this.MaximumTurnDistance)
                                {
                                    float num5 = 0.5f - num4 / this.MaximumTurnDistance;
                                    num2 = AILayer.Boost(num2, num5 * 0.5f);
                                    float life    = creepingNode.Life;
                                    float maxLife = creepingNode.MaxLife;
                                    num2 = AILayer.Boost(num2, (1f - life / maxLife) * 0.2f);
                                    if (num2 > num)
                                    {
                                        num             = num2;
                                        pointOfInterest = pointOfInterest2;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (pointOfInterest != null)
        {
            if (this.OpportunityMaximumTurn > 0f)
            {
                int num6 = 0;
                int num7 = 0;
                if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition))
                {
                    WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition];
                    if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, pointOfInterest.WorldPosition, mainTargetPosition, out num7, out num6))
                    {
                        return(State.Failure);
                    }
                }
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = pointOfInterest;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, pointOfInterest);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
    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);
    }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (this.TypeOfDiplomaticRelation == "VillageQuest" && (!(aiBehaviorTree.AICommander.Empire is MajorEmpire) || !aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley()))
        {
            return(State.Failure);
        }
        if (this.DiplomacyLayer == null && aiBehaviorTree.AICommander.Empire is MajorEmpire)
        {
            AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
            this.DiplomacyLayer = entity.GetLayer <AILayer_Diplomacy>();
        }
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName))
        {
            return(State.Failure);
        }
        List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>;

        if (list == null || list.Count == 0)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        List <IWorldPositionable> list2 = null;

        if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Army)
        {
            list2 = list.FindAll((IWorldPositionable match) => match is Army);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin)
        {
            list2 = this.Execute_GetRuins(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village)
        {
            list2 = this.Execute_GetVillages(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget > AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village && this.TypeOfTarget < AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice)
        {
            list2 = this.Execute_GetKaijus(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice)
        {
            list2 = this.Execute_GetVolcanoformers(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress)
        {
            list2 = this.Execute_GetFortresses(aiBehaviorTree, army, service, list);
        }
        else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Any)
        {
            list2 = new List <IWorldPositionable>(list);
        }
        if (army.Empire is MinorEmpire || army.Empire is NavalEmpire)
        {
            for (int i = list2.Count - 1; i >= 0; i--)
            {
                Garrison garrison = list2[i] as Garrison;
                if (garrison != null && garrison.Hero != null && garrison.Hero.IsSkillUnlocked("HeroSkillLeaderMap07"))
                {
                    list2.RemoveAt(i);
                }
            }
        }
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
        IWorldPositionningService    service3 = service.Game.Services.GetService <IWorldPositionningService>();
        bool flag = false;

        if (this.TypeOfDiplomaticRelation == "VillageQuest")
        {
            flag = true;
        }
        if (!string.IsNullOrEmpty(this.TypeOfDiplomaticRelationVariableName) && aiBehaviorTree.Variables.ContainsKey(this.TypeOfDiplomaticRelationVariableName))
        {
            this.TypeOfDiplomaticRelation = (aiBehaviorTree.Variables[this.TypeOfDiplomaticRelationVariableName] as string);
        }
        DepartmentOfForeignAffairs departmentOfForeignAffairs = null;
        bool canAttack = false;

        if (this.TypeOfDiplomaticRelation == "Enemy")
        {
            departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
            canAttack = true;
        }
        else if (this.TypeOfDiplomaticRelation == "DangerForMe")
        {
            departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
            canAttack = false;
        }
        for (int j = list2.Count - 1; j >= 0; j--)
        {
            if (!AIBehaviorTreeNode_Decorator_SelectTarget.ValidateTarget(army, list2[j] as IGameEntity, departmentOfForeignAffairs, canAttack, service2, service3))
            {
                list2.RemoveAt(j);
            }
            else if (list2[j] is IGarrison && departmentOfForeignAffairs != null && this.DiplomacyLayer != null && (list2[j] as IGarrison).Empire is MajorEmpire && this.DiplomacyLayer.GetPeaceWish((list2[j] as IGarrison).Empire.Index))
            {
                if (!(list2[j] is Army) || !(list2[j] as Army).IsPrivateers)
                {
                    list2.RemoveAt(j);
                }
            }
            else if (flag && list2[j] is Village && !this.ValidQuestVillage(list2[j] as Village, army))
            {
                list2.RemoveAt(j);
            }
        }
        IWorldPositionningService worldPositionService = service.Game.Services.GetService <IWorldPositionningService>();

        if (list2 != null && list2.Count != 0)
        {
            bool flag2;
            if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin || this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress)
            {
                flag2 = army.SimulationObject.Tags.Contains("MovementCapacitySail");
            }
            else
            {
                flag2 = army.HasSeafaringUnits();
            }
            Diagnostics.Assert(worldPositionService != null);
            if (!flag2)
            {
                list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsWaterTile(element.WorldPosition));
            }
            if (army.IsSeafaring)
            {
                list2.RemoveAll((IWorldPositionable element) => !worldPositionService.IsWaterTile(element.WorldPosition));
                list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsFrozenWaterTile(element.WorldPosition));
            }
        }
        if (list2 != null && list2.Count != 0)
        {
            if (list2.Count > 1)
            {
                list2.Sort((IWorldPositionable left, IWorldPositionable right) => worldPositionService.GetDistance(left.WorldPosition, army.WorldPosition).CompareTo(worldPositionService.GetDistance(right.WorldPosition, army.WorldPosition)));
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = list2[0];
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, list2[0]);
            }
        }
        else if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
        {
            aiBehaviorTree.Variables.Remove(this.Output_TargetVarName);
        }
        State result;

        if (this.Inverted)
        {
            if (list2 != null && list2.Count != 0)
            {
                result = State.Failure;
            }
            else
            {
                result = State.Success;
            }
        }
        else if (list2 != null && list2.Count != 0)
        {
            result = State.Success;
        }
        else
        {
            aiBehaviorTree.ErrorCode = 10;
            result = State.Failure;
        }
        return(result);
    }
Beispiel #17
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (!this.downloadableContentService.IsShared(DownloadableContent13.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!(army.Empire is MajorEmpire))
        {
            return(State.Failure);
        }
        if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName))
        {
            this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName];
        }
        AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();

        if (this.DiplomacyLayer == null && aiBehaviorTree.AICommander.Empire is MajorEmpire)
        {
            this.DiplomacyLayer = entity.GetLayer <AILayer_Diplomacy>();
        }
        Region      region = this.worldPositionningService.GetRegion(army.WorldPosition);
        bool        flag   = false;
        AIData_Army aidata_Army;

        if (this.aiDataRepositoryHelper.TryGetAIData <AIData_Army>(army.GUID, out aidata_Army))
        {
            flag = aidata_Army.IsManta;
        }
        float        num           = flag ? -1000f : 0.1f;
        float        propertyValue = army.GetPropertyValue(SimulationProperties.MaximumMovement);
        OrbSpawnInfo orbSpawnInfo  = null;

        for (int i = 0; i < this.orbAIHelper.OrbSpawns.Count; i++)
        {
            OrbSpawnInfo orbSpawnInfo2 = this.orbAIHelper.OrbSpawns[i];
            if (orbSpawnInfo2 != null && orbSpawnInfo2.CurrentOrbCount != 0f)
            {
                bool flag2 = this.worldPositionningService.IsWaterTile(orbSpawnInfo2.WorldPosition);
                if (flag || flag2 != !army.IsSeafaring)
                {
                    float num2 = 0.5f;
                    if (entity != null)
                    {
                        num2 = this.ComputeOrbCollectingScore(orbSpawnInfo2, entity, army);
                    }
                    if (num2 > 0f)
                    {
                        Region region2 = this.worldPositionningService.GetRegion(orbSpawnInfo2.WorldPosition);
                        if (flag || region2.ContinentID == region.ContinentID)
                        {
                            float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, orbSpawnInfo2.WorldPosition) / propertyValue;
                            if (num3 <= this.MaximumTurnDistance)
                            {
                                if (flag)
                                {
                                    num2 = -num3 + num2 * 1E-09f;
                                }
                                else
                                {
                                    float orbDistanceExponent = this.orbAIHelper.GetOrbDistanceExponent(entity.Empire);
                                    float num4 = 1f + Mathf.Pow(num3, orbDistanceExponent);
                                    num2 /= num4;
                                }
                                if (num2 > num)
                                {
                                    num          = num2;
                                    orbSpawnInfo = orbSpawnInfo2;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (orbSpawnInfo == null)
        {
            return(State.Failure);
        }
        if (num < this.orbAIHelper.EmpireOrbNeedThreshold[army.Empire.Index] && !flag)
        {
            return(State.Failure);
        }
        if (this.OpportunityMaximumTurn >= 0f)
        {
            int num5 = 0;
            int num6 = 0;
            if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition))
            {
                WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition];
                if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, orbSpawnInfo.WorldPosition, mainTargetPosition, out num6, out num5))
                {
                    return(State.Failure);
                }
            }
            if ((float)(num5 - num6) > this.OpportunityMaximumTurn)
            {
                return(State.Failure);
            }
        }
        if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
        {
            aiBehaviorTree.Variables[this.Output_TargetVarName] = orbSpawnInfo;
        }
        else
        {
            aiBehaviorTree.Variables.Add(this.Output_TargetVarName, orbSpawnInfo);
        }
        return(State.Success);
    }