コード例 #1
0
    private void RefreshMessagePriority(GlobalObjectiveMessage objectiveMessage)
    {
        objectiveMessage.GlobalPriority = base.GlobalPriority;
        objectiveMessage.LocalPriority  = new HeuristicValue(0.35f);
        List <int> list = new List <int>();

        if (!DepartmentOfTheInterior.CanNeverDeclareWar(base.AIEntity.Empire) || this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            foreach (AICommander aicommander in this.aILayer_ArmyManagement.AICommanders)
            {
                AICommander_WarWithObjective aicommander_WarWithObjective = aicommander as AICommander_WarWithObjective;
                if (aicommander_WarWithObjective != null)
                {
                    Region region = this.worldPositionningService.GetRegion(aicommander_WarWithObjective.RegionIndex);
                    if (region.Owner != null && region.Owner.Index != base.AIEntity.Empire.Index)
                    {
                        list.Add(region.Owner.Index);
                    }
                }
            }
        }
        if (list.Count == 0)
        {
            objectiveMessage.LocalPriority.Boost(0.4f, "NoWarBoost", new object[0]);
        }
        Region region2 = this.worldPositionningService.GetRegion(objectiveMessage.RegionIndex);

        if (region2.Kaiju != null && region2.Kaiju.IsTamed() && list.Contains(region2.Kaiju.OwnerEmpireIndex) && this.departmentOfForeignAffairs.IsAtWarWith(region2.Kaiju.MajorEmpire))
        {
            objectiveMessage.LocalPriority.Boost(0.2f, "At war boost", new object[0]);
        }
        if (region2 != null && region2.Kaiju != null && this.departmentOfTheInterior.Cities.Count > 0)
        {
            int num = int.MaxValue;
            foreach (City city in this.departmentOfTheInterior.Cities)
            {
                int distance = this.worldPositionningService.GetDistance(city.WorldPosition, region2.Kaiju.WorldPosition);
                if (distance < num)
                {
                    num = distance;
                }
            }
            if (this.departmentOfCreepingNodes != null)
            {
                foreach (CreepingNode creepingNode in this.departmentOfCreepingNodes.Nodes)
                {
                    if (creepingNode.Region.Index == region2.Index && !creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(base.AIEntity.Empire, creepingNode))
                    {
                        int distance2 = this.worldPositionningService.GetDistance(creepingNode.WorldPosition, region2.Kaiju.WorldPosition);
                        if (distance2 < num)
                        {
                            num = distance2;
                        }
                    }
                }
            }
            num = Mathf.Max(30 - num, 0);
            objectiveMessage.LocalPriority.Boost((float)num / 60f, "Close distance boost", new object[0]);
        }
        if (list.Count > 0 && !this.departmentOfForeignAffairs.IsInWarWithSomeone() && this.aiLayerStrategy.WantWarWithSomeone() && region2.Kaiju != null && region2.Kaiju.IsTamed() && (region2.Owner == null || region2.Owner.Index != base.AIEntity.Empire.Index) && !list.Contains(region2.Kaiju.OwnerEmpireIndex))
        {
            objectiveMessage.LocalPriority.Boost(-0.6f, "Not our target!", new object[0]);
        }
        objectiveMessage.TimeOut = 1;
    }
コード例 #2
0
    private bool CanAttackGameEntity(Army army, IGameEntity gameEntity, ref bool displayButtonAnyway, ref List <StaticString> failureFlags)
    {
        Village village = gameEntity as Village;

        if (village != null)
        {
            displayButtonAnyway = true;
            if (!TutorialManager.IsActivated)
            {
                if (village.PointOfInterest.Interaction.IsLocked(army.Empire.Index, this.Name))
                {
                    if (!failureFlags.Contains(ArmyAction_Attack.OneVillageOrManyLocked))
                    {
                        failureFlags.Add(ArmyAction_Attack.OneVillageOrManyLocked);
                    }
                    return(false);
                }
            }
            else
            {
                failureFlags.Add(ArmyAction.NoCanDoWhileTutorial);
            }
            if (village.HasBeenConverted)
            {
                if (village.Converter == army.Empire)
                {
                    failureFlags.Add(ArmyAction_Attack.OwnVillage);
                    return(false);
                }
                return(true);
            }
            else
            {
                if (village.HasBeenPacified)
                {
                    failureFlags.Add(ArmyAction_BaseVillage.NoCanDoWhileVillageIsPacified);
                    return(false);
                }
                return(true);
            }
        }
        else
        {
            Camp camp = gameEntity as Camp;
            if (camp != null)
            {
                if (camp.Empire == army.Empire)
                {
                    return(false);
                }
                DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                if (!agency.CanAttack(gameEntity) && !army.IsPrivateers && DepartmentOfTheInterior.CanNeverDeclareWar(army.Empire))
                {
                    failureFlags.Add(ArmyAction_Attack.CanNeverDeclareWar);
                    return(false);
                }
                return(true);
            }
            else
            {
                District district = gameEntity as District;
                if (district != null)
                {
                    if (district.City.Empire == army.Empire)
                    {
                        return(false);
                    }
                    displayButtonAnyway = true;
                    if (district.City.BesiegingEmpire != null && district.City.BesiegingEmpire != army.Empire)
                    {
                        return(false);
                    }
                    if (district.Type == DistrictType.Exploitation)
                    {
                        return(false);
                    }
                    DepartmentOfForeignAffairs agency2 = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                    Diagnostics.Assert(agency2 != null);
                    if (!agency2.CanAttack(gameEntity) && !army.IsPrivateers && DepartmentOfTheInterior.CanNeverDeclareWar(army.Empire))
                    {
                        failureFlags.Add(ArmyAction_Attack.CanNeverDeclareWar);
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    Army army2 = gameEntity as Army;
                    if (army2 == null)
                    {
                        KaijuGarrison kaijuGarrison = gameEntity as KaijuGarrison;
                        return(kaijuGarrison != null && (kaijuGarrison.Owner == null || kaijuGarrison.Owner.Index != army.Empire.Index) && !kaijuGarrison.Kaiju.IsStunned());
                    }
                    if (army2.Empire == army.Empire)
                    {
                        return(false);
                    }
                    if (army2.Sails)
                    {
                        return(false);
                    }
                    if (army2 is KaijuArmy)
                    {
                        KaijuArmy kaijuArmy = army2 as KaijuArmy;
                        if (kaijuArmy != null && kaijuArmy.Kaiju.IsStunned())
                        {
                            return(false);
                        }
                    }
                    DepartmentOfForeignAffairs agency3 = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                    Diagnostics.Assert(agency3 != null);
                    if (!agency3.CanAttack(gameEntity) && !army.IsPrivateers && DepartmentOfTheInterior.CanNeverDeclareWar(army.Empire))
                    {
                        failureFlags.Add(ArmyAction_Attack.CanNeverDeclareWar);
                        return(false);
                    }
                    displayButtonAnyway = true;
                    return(true);
                }
            }
        }
    }