protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army  army  = aiBehaviorTree.Variables[this.TargetVarName] as Army;
        Kaiju kaiju = aiBehaviorTree.Variables[this.TargetVarName] as Kaiju;

        if (army == null && kaiju != null && kaiju.OnArmyMode())
        {
            army = kaiju.KaijuArmy;
        }
        if (army != null)
        {
            return(this.ArmyExecute(army, aiBehaviorTree, parameters));
        }
        Garrison garrison = aiBehaviorTree.Variables[this.TargetVarName] as Garrison;

        if (garrison == null && kaiju != null && kaiju.OnGarrisonMode())
        {
            garrison = kaiju.KaijuGarrison;
        }
        if (garrison != null)
        {
            return(this.GeneralExecute(garrison, aiBehaviorTree, parameters));
        }
        aiBehaviorTree.ErrorCode = 10;
        return(State.Failure);
    }
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.ticket != null)
     {
         if (!this.orderExecuted)
         {
             return(State.Running);
         }
         if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed)
         {
             this.orderExecuted       = false;
             this.ticket              = null;
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         this.orderExecuted = false;
         this.ticket        = null;
         return(State.Success);
     }
     else
     {
         Army army;
         if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None)
         {
             return(State.Failure);
         }
         if (!(army is KaijuArmy))
         {
             return(State.Failure);
         }
         Kaiju kaiju = (army as KaijuArmy).Kaiju;
         if (kaiju == null || !(army.Empire is MajorEmpire) || kaiju.OnGarrisonMode() || !KaijuCouncil.IsPositionValidForSettleKaiju(army.WorldPosition, kaiju))
         {
             return(State.Failure);
         }
         this.failuresFlags.Clear();
         if (!this.armyAction_SettleKaiju.CanExecute(army, ref this.failuresFlags, new object[0]))
         {
             return(State.Failure);
         }
         this.orderExecuted = false;
         this.armyAction_SettleKaiju.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised), new object[0]);
         return(State.Running);
     }
 }
Пример #3
0
    protected override void RefreshObjectives(StaticString context, StaticString pass)
    {
        base.RefreshObjectives(context, pass);
        AILayer_Military layer = base.AIEntity.GetLayer <AILayer_Military>();

        base.GlobalPriority.Reset();
        AILayer_Strategy layer2 = base.AIEntity.GetLayer <AILayer_Strategy>();

        base.GlobalPriority.Add(layer2.StrategicNetwork.GetAgentValue("InternalMilitary"), "Strategic network 'InternalMilitary'", new object[0]);
        base.GlobalPriority.Boost(-0.5f, "Avoid patrol to be high", new object[0]);
        base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Patrol.ToString(), ref this.patrolObjectives);
        base.ValidateMessages(ref this.patrolObjectives);
        if (base.AIEntity.Empire is MajorEmpire)
        {
            MajorEmpire majorEmpire = base.AIEntity.Empire as MajorEmpire;
            for (int i = 0; i < majorEmpire.ConvertedVillages.Count; i++)
            {
                Village village = majorEmpire.ConvertedVillages[i];
                if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, village.Region, 0.95f))
                {
                    GlobalObjectiveMessage globalObjectiveMessage = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index);
                    if (globalObjectiveMessage == null)
                    {
                        globalObjectiveMessage = base.GenerateObjective(village.Region.Index);
                        this.patrolObjectives.Add(globalObjectiveMessage);
                    }
                    globalObjectiveMessage.TimeOut        = 1;
                    globalObjectiveMessage.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue = new HeuristicValue(0f);
                    heuristicValue.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]);
                    globalObjectiveMessage.LocalPriority = heuristicValue;
                }
            }
            for (int j = 0; j < majorEmpire.TamedKaijus.Count; j++)
            {
                Kaiju kaiju = majorEmpire.TamedKaijus[j];
                if (kaiju.OnGarrisonMode())
                {
                    GlobalObjectiveMessage globalObjectiveMessage2 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index);
                    if (globalObjectiveMessage2 == null)
                    {
                        globalObjectiveMessage2 = base.GenerateObjective(kaiju.Region.Index);
                        this.patrolObjectives.Add(globalObjectiveMessage2);
                    }
                    globalObjectiveMessage2.TimeOut        = 1;
                    globalObjectiveMessage2.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue2 = new HeuristicValue(0.6f);
                    AIRegionData   regionData      = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index);
                    if (regionData != null)
                    {
                        float operand = Mathf.Min(1f, 0.1f * (float)regionData.BorderWithNeutral + 0.2f * (float)regionData.BorderWithEnnemy);
                        heuristicValue2.Boost(operand, "Border with enemy!", new object[0]);
                    }
                    globalObjectiveMessage2.LocalPriority = heuristicValue2;
                }
            }
        }
        for (int k = 0; k < this.departmentOfTheInterior.Cities.Count; k++)
        {
            City city = this.departmentOfTheInterior.Cities[k];
            if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, city.Region, 0.8f))
            {
                GlobalObjectiveMessage globalObjectiveMessage3 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index);
                if (globalObjectiveMessage3 == null)
                {
                    globalObjectiveMessage3 = base.GenerateObjective(city.Region.Index);
                    this.patrolObjectives.Add(globalObjectiveMessage3);
                }
                globalObjectiveMessage3.TimeOut        = 1;
                globalObjectiveMessage3.GlobalPriority = base.GlobalPriority;
                HeuristicValue heuristicValue3 = new HeuristicValue(0f);
                heuristicValue3.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]);
                globalObjectiveMessage3.LocalPriority = heuristicValue3;
            }
        }
        if (base.AIEntity.Empire is MajorEmpire)
        {
            using (List <int> .Enumerator enumerator = this.questSolverLayer.QuestRegions.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    int regionIndex = enumerator.Current;
                    GlobalObjectiveMessage globalObjectiveMessage4 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex);
                    if (globalObjectiveMessage4 == null)
                    {
                        globalObjectiveMessage4 = base.GenerateObjective(regionIndex);
                        this.patrolObjectives.Add(globalObjectiveMessage4);
                    }
                    if (globalObjectiveMessage4 != null)
                    {
                        globalObjectiveMessage4.GlobalPriority.Value = 0.85f;
                        globalObjectiveMessage4.LocalPriority.Value  = 0.85f;
                    }
                }
            }
        }
        if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
        {
            base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString(), ref this.warPatrolObjectives);
            base.ValidateMessages(ref this.warPatrolObjectives);
            if (base.AIEntity.Empire is MajorEmpire)
            {
                MajorEmpire majorEmpire2 = base.AIEntity.Empire as MajorEmpire;
                for (int l = 0; l < majorEmpire2.ConvertedVillages.Count; l++)
                {
                    Village village = majorEmpire2.ConvertedVillages[l];
                    GlobalObjectiveMessage globalObjectiveMessage5 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index);
                    if (globalObjectiveMessage5 == null)
                    {
                        globalObjectiveMessage5 = base.GenerateObjective(village.Region.Index);
                        globalObjectiveMessage5.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString();
                        this.warPatrolObjectives.Add(globalObjectiveMessage5);
                    }
                    globalObjectiveMessage5.TimeOut        = 1;
                    globalObjectiveMessage5.GlobalPriority = base.GlobalPriority;
                    HeuristicValue heuristicValue4 = new HeuristicValue(0f);
                    heuristicValue4.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]);
                    globalObjectiveMessage5.LocalPriority = heuristicValue4;
                }
                for (int m = 0; m < majorEmpire2.TamedKaijus.Count; m++)
                {
                    Kaiju kaiju = majorEmpire2.TamedKaijus[m];
                    if (kaiju.OnGarrisonMode())
                    {
                        GlobalObjectiveMessage globalObjectiveMessage6 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index);
                        if (globalObjectiveMessage6 == null)
                        {
                            globalObjectiveMessage6 = base.GenerateObjective(kaiju.Region.Index);
                            this.warPatrolObjectives.Add(globalObjectiveMessage6);
                        }
                        globalObjectiveMessage6.TimeOut        = 1;
                        globalObjectiveMessage6.GlobalPriority = base.GlobalPriority;
                        HeuristicValue heuristicValue5 = new HeuristicValue(0.8f);
                        AIRegionData   regionData2     = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index);
                        if (regionData2 != null)
                        {
                            float operand2 = Mathf.Min(1f, 0.2f * (float)regionData2.BorderWithNeutral + 0.3f * (float)regionData2.BorderWithEnnemy);
                            heuristicValue5.Boost(operand2, "Border with enemy!", new object[0]);
                        }
                        globalObjectiveMessage6.LocalPriority = heuristicValue5;
                    }
                }
            }
            for (int n = 0; n < this.departmentOfTheInterior.Cities.Count; n++)
            {
                City city = this.departmentOfTheInterior.Cities[n];
                GlobalObjectiveMessage globalObjectiveMessage7 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index);
                if (globalObjectiveMessage7 == null)
                {
                    globalObjectiveMessage7 = base.GenerateObjective(city.Region.Index);
                    globalObjectiveMessage7.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString();
                    this.warPatrolObjectives.Add(globalObjectiveMessage7);
                }
                globalObjectiveMessage7.TimeOut        = 1;
                globalObjectiveMessage7.GlobalPriority = base.GlobalPriority;
                HeuristicValue heuristicValue6 = new HeuristicValue(0f);
                heuristicValue6.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]);
                if (this.worldAtlasHelper.GetRegionData(city.Empire.Index, city.Region.Index).BorderWithEnnemy > 0)
                {
                    heuristicValue6.Boost(0.2f, "Border with enemy!", new object[0]);
                }
                globalObjectiveMessage7.LocalPriority = heuristicValue6;
            }
            bool flag = false;
            for (int num = 0; num < this.warPatrolObjectives.Count; num++)
            {
                GlobalObjectiveMessage warPatrolObjective = this.warPatrolObjectives[num];
                if (base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(warPatrolObjective.ID) == null)
                {
                    GlobalObjectiveMessage globalObjectiveMessage8 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == warPatrolObjective.RegionIndex);
                    if (globalObjectiveMessage8 != null)
                    {
                        AICommander commanderProcessingTheNeededGlobalObjective = base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(globalObjectiveMessage8.ID);
                        if (commanderProcessingTheNeededGlobalObjective != null)
                        {
                            commanderProcessingTheNeededGlobalObjective.Release();
                            flag = true;
                        }
                    }
                }
            }
            if (flag)
            {
                base.AIEntity.KillAllCommanders("AICommander_Exploration");
            }
        }
    }
Пример #4
0
    public void FillTargets(Army army, List <IGameEntity> targets, ref List <StaticString> failureFlags)
    {
        if (targets == null)
        {
            targets = new List <IGameEntity>();
        }
        IGameService service = Services.GetService <IGameService>();

        if (service == null)
        {
            return;
        }
        IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();

        Diagnostics.Assert(service2 != null);
        IPathfindingService service3 = service.Game.Services.GetService <IPathfindingService>();

        Diagnostics.Assert(service2 != null);
        base.ListNearbyVillages(army);
        if (base.PointsOfInterest.Count != 0)
        {
            for (int i = base.PointsOfInterest.Count - 1; i >= 0; i--)
            {
                PointOfInterest pointOfInterest = base.PointsOfInterest[i];
                if (pointOfInterest.PointOfInterestImprovement != null && (pointOfInterest.Empire == null || pointOfInterest.Empire.Index != army.Empire.Index))
                {
                    Region region = service2.GetRegion(pointOfInterest.WorldPosition);
                    if (region != null && region.MinorEmpire != null)
                    {
                        Village village = region.MinorEmpire.GetAgency <BarbarianCouncil>().Villages.FirstOrDefault((Village iterator) => iterator.WorldPosition == pointOfInterest.WorldPosition);
                        if (village != null)
                        {
                            targets.Add(village);
                        }
                    }
                }
            }
        }
        List <WorldPosition> list = new List <WorldPosition>();

        for (int j = 0; j < 6; j++)
        {
            WorldPosition neighbourTile = service2.GetNeighbourTile(army.WorldPosition, (WorldOrientation)j, 1);
            if (neighbourTile.IsValid && service3.IsTransitionPassable(army.WorldPosition, neighbourTile, army, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreOtherEmpireDistrict | PathfindingFlags.IgnoreDiplomacy | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreZoneOfControl | PathfindingFlags.IgnorePOI | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null))
            {
                list.Add(neighbourTile);
            }
        }
        List <int> list2 = new List <int>();

        for (int k = 0; k < list.Count; k++)
        {
            Region region2 = service2.GetRegion(list[k]);
            if (region2 != null && !list2.Contains(region2.Index))
            {
                list2.Add(region2.Index);
                KaijuEmpire kaijuEmpire = region2.KaijuEmpire;
                if (kaijuEmpire != null)
                {
                    KaijuCouncil agency = kaijuEmpire.GetAgency <KaijuCouncil>();
                    if (agency != null)
                    {
                        Kaiju kaiju = agency.Kaiju;
                        if (kaiju != null && kaiju.OnGarrisonMode())
                        {
                            KaijuGarrison kaijuGarrison = kaiju.KaijuGarrison;
                            if (kaijuGarrison != null && list.Contains(kaijuGarrison.WorldPosition))
                            {
                                targets.Add(kaijuGarrison);
                            }
                        }
                    }
                }
                if (region2.City != null && region2.City.Empire != null && region2.City.Empire.Index != army.Empire.Index)
                {
                    for (int l = 0; l < region2.City.Districts.Count; l++)
                    {
                        District district = region2.City.Districts[l];
                        if (list.Contains(district.WorldPosition) && district.Type != DistrictType.Exploitation)
                        {
                            targets.Add(district);
                        }
                    }
                    if (region2.City.Camp != null && list.Contains(region2.City.Camp.WorldPosition))
                    {
                        targets.Add(region2.City.Camp);
                    }
                }
            }
        }
        global::Game game = service.Game as global::Game;

        if (game == null)
        {
            return;
        }
        for (int m = 0; m < game.Empires.Length; m++)
        {
            if (m != army.Empire.Index)
            {
                DepartmentOfDefense agency2 = game.Empires[m].GetAgency <DepartmentOfDefense>();
                if (agency2 != null)
                {
                    for (int n = 0; n < agency2.Armies.Count; n++)
                    {
                        Army army2 = agency2.Armies[n];
                        if (list.Contains(army2.WorldPosition))
                        {
                            if (army2 is KaijuArmy)
                            {
                                KaijuArmy kaijuArmy = army2 as KaijuArmy;
                                if (kaijuArmy != null && !kaijuArmy.Kaiju.OnArmyMode())
                                {
                                    goto IL_389;
                                }
                            }
                            targets.Add(army2);
                        }
                        IL_389 :;
                    }
                }
                DepartmentOfTheInterior agency3 = game.Empires[m].GetAgency <DepartmentOfTheInterior>();
                if (agency3 != null)
                {
                    for (int num = 0; num < agency3.TamedKaijuGarrisons.Count; num++)
                    {
                        KaijuGarrison kaijuGarrison2 = agency3.TamedKaijuGarrisons[num];
                        if (kaijuGarrison2 != null)
                        {
                            Kaiju kaiju2 = kaijuGarrison2.Kaiju;
                            if (kaiju2 != null && kaiju2.OnGarrisonMode() && list.Contains(kaijuGarrison2.WorldPosition))
                            {
                                targets.Add(kaijuGarrison2);
                            }
                        }
                    }
                }
            }
        }
    }