private bool TrySelectRegionToExplore(global::Empire empire, ref List <Region> regionList)
    {
        Diagnostics.Assert(AIScheduler.Services != null);
        IIntelligenceAIHelper service = AIScheduler.Services.GetService <IIntelligenceAIHelper>();

        Diagnostics.Assert(service != null);
        return(service.TryGetListOfRegionToExplore(base.AIEntity.Empire, 0.95f, ref regionList));
    }
Beispiel #2
0
    protected override bool TryComputeArmyMissionParameter()
    {
        if (this.ticket != null)
        {
            if (this.ticket.Raised)
            {
                this.ticket = null;
            }
            return(false);
        }
        if (base.AIDataArmyGUID.IsValid && this.TargetCity != null && this.TargetCity.Empire == base.Commander.Empire && this.aiDataRepository.GetAIData <AIData_City>(this.TargetCity.GUID) != null)
        {
            AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID);
            if (aidata != null)
            {
                List <object> list = new List <object>();
                list.Add(this.TargetCity);
                if (this.TargetCity.MaximumUnitSlot > this.TargetCity.CurrentUnitSlot + aidata.Army.CurrentUnitSlot)
                {
                    return(base.TryCreateArmyMission("DefendCity_Bail", list));
                }
                if (aidata.Army.CurrentUnitSlot > 1)
                {
                    GameEntityGUID[] array = new GameEntityGUID[1];
                    for (int i = 0; i < aidata.Army.StandardUnits.Count; i++)
                    {
                        if (aidata.Army.StandardUnits[i].IsSettler && aidata.Army.StandardUnits[i].GetPropertyValue(SimulationProperties.Movement) > 0f)
                        {
                            array[0] = aidata.Army.StandardUnits[i].GUID;
                            break;
                        }
                    }
                    WorldPosition neighbourFirstAvailablePositionForArmyCreation = DepartmentOfDefense.GetNeighbourFirstAvailablePositionForArmyCreation(aidata.Army);
                    if (neighbourFirstAvailablePositionForArmyCreation.IsValid && array[0].IsValid)
                    {
                        OrderTransferGarrisonToNewArmy order = new OrderTransferGarrisonToNewArmy(base.Commander.Empire.Index, base.AIDataArmyGUID, array, neighbourFirstAvailablePositionForArmyCreation, null, false, true, true);
                        base.Commander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, null);
                    }
                    return(false);
                }
                return(base.TryCreateArmyMission("ReachTarget", list));
            }
        }
        Diagnostics.Assert(AIScheduler.Services != null);
        IIntelligenceAIHelper service = AIScheduler.Services.GetService <IIntelligenceAIHelper>();

        Diagnostics.Assert(service != null);
        List <Region> list2 = new List <Region>();

        if (service.TryGetListOfRegionToExplore(base.Commander.Empire, 0.95f, ref list2))
        {
            foreach (Region region in list2)
            {
                if (AILayer_Exploration.IsRegionValidForExploration(base.Commander.Empire, region))
                {
                    return(base.TryCreateArmyMission("ExploreAt", new List <object>
                    {
                        region.Index
                    }));
                }
            }
            return(false);
        }
        return(false);
    }
Beispiel #3
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army  army;
        State result;

        if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
        {
            result = State.Failure;
        }
        else if (this.StrongestAttacker)
        {
            result = this.StrongestAttackerExecute(army);
        }
        else if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
        {
            result = State.Failure;
        }
        else
        {
            Garrison garrison;
            if (aiBehaviorTree.Variables[this.TargetVarName] is Kaiju)
            {
                garrison = (aiBehaviorTree.Variables[this.TargetVarName] as Kaiju).GetActiveTroops();
                if (garrison == null)
                {
                    aiBehaviorTree.ErrorCode = 10;
                    return(State.Failure);
                }
            }
            else
            {
                garrison = (aiBehaviorTree.Variables[this.TargetVarName] as Garrison);
                if (garrison == null)
                {
                    aiBehaviorTree.ErrorCode = 10;
                    return(State.Failure);
                }
            }
            if (garrison == army)
            {
                result = State.Failure;
            }
            else if (garrison is Fortress && garrison.UnitsCount > 0)
            {
                if (this.Inverted)
                {
                    return(State.Success);
                }
                return(State.Failure);
            }
            else
            {
                float        num     = (garrison is City) ? 1.5f : ((garrison is KaijuGarrison || garrison is KaijuArmy) ? 1f : 1.1f);
                IGameService service = Services.GetService <IGameService>();
                Diagnostics.Assert(service != null);
                Diagnostics.Assert(service.Game.Services.GetService <IWorldPositionningService>() != null);
                IIntelligenceAIHelper service2 = AIScheduler.Services.GetService <IIntelligenceAIHelper>();
                float num2 = 0f;
                float num3 = 0f;
                service2.EstimateMPInBattleground(army, garrison, ref num3, ref num2);
                if (!this.EvaluateArmyGroup)
                {
                    bool flag = true;
                    if (num2 * num > num3)
                    {
                        flag = false;
                    }
                    if (this.Inverted)
                    {
                        if (!flag)
                        {
                            result = State.Success;
                        }
                        else
                        {
                            aiBehaviorTree.ErrorCode = 14;
                            result = State.Failure;
                        }
                    }
                    else if (flag)
                    {
                        result = State.Success;
                    }
                    else
                    {
                        aiBehaviorTree.ErrorCode = 13;
                        result = State.Failure;
                    }
                }
                else
                {
                    float num4 = army.GetPropertyValue(SimulationProperties.MilitaryPower);
                    foreach (AICommanderMission aicommanderMission in aiBehaviorTree.AICommander.Missions)
                    {
                        IGameEntity gameEntity = null;
                        if (aicommanderMission.AIDataArmyGUID.IsValid && aicommanderMission.AIDataArmyGUID != army.GUID && this.gameEntityRepositoryService.TryGetValue(aicommanderMission.AIDataArmyGUID, out gameEntity) && gameEntity is Army)
                        {
                            Army army2 = gameEntity as Army;
                            if (army2.GUID.IsValid)
                            {
                                num4 += army2.GetPropertyValue(SimulationProperties.MilitaryPower);
                            }
                        }
                    }
                    bool flag2 = true;
                    if (num2 * num > num4)
                    {
                        flag2 = false;
                    }
                    if (this.Inverted)
                    {
                        if (!flag2)
                        {
                            result = State.Success;
                        }
                        else
                        {
                            aiBehaviorTree.ErrorCode = 14;
                            result = State.Failure;
                        }
                    }
                    else if (flag2)
                    {
                        result = State.Success;
                    }
                    else
                    {
                        aiBehaviorTree.ErrorCode = 13;
                        result = State.Failure;
                    }
                }
            }
        }
        return(result);
    }
Beispiel #4
0
    public static bool HasSaveAttackableTargetsNearby(Garrison Attacker, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, out List <IGarrison> Targets, bool NavalOnly = false)
    {
        IIntelligenceAIHelper service  = AIScheduler.Services.GetService <IIntelligenceAIHelper>();
        IVisibilityService    service2 = Services.GetService <IGameService>().Game.Services.GetService <IVisibilityService>();

        Targets = new List <IGarrison>();
        if (size < 1 || Attacker == null || !(Attacker is IWorldPositionable))
        {
            return(false);
        }
        List <global::Empire> list = new List <global::Empire>(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match)));

        if (list.Count < 1)
        {
            return(false);
        }
        bool result = true;
        IWorldPositionningService service3 = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>();

        foreach (global::Empire empire in list)
        {
            List <Garrison>         list2   = new List <Garrison>();
            DepartmentOfDefense     agency  = empire.GetAgency <DepartmentOfDefense>();
            DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();
            if (!NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <Garrison>());
                list2.AddRange(agency2.Cities.Cast <Garrison>());
                list2.AddRange(agency2.Camps.Cast <Garrison>());
                list2.AddRange(agency2.ConvertedVillages.Cast <Garrison>());
            }
            if (NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <Garrison>());
                list2.AddRange(agency2.OccupiedFortresses.Cast <Garrison>());
            }
            foreach (Garrison garrison in list2)
            {
                if (garrison.UnitsCount > 0 && garrison is IWorldPositionable && (float)service3.GetDistance((garrison as IWorldPositionable).WorldPosition, (Attacker as IWorldPositionable).WorldPosition) <= (float)size && departmentOfForeignAffairs.CanAttack(garrison) && (!garrison.SimulationObject.Tags.Contains(Army.TagCamouflaged) || service2.IsWorldPositionDetectedFor((garrison as IWorldPositionable).WorldPosition, Attacker.Empire)) && service2.IsWorldPositionVisibleFor((garrison as IWorldPositionable).WorldPosition, Attacker.Empire))
                {
                    float num  = 0f;
                    float num2 = 0f;
                    if (!NavalOnly)
                    {
                        service.EstimateMPInBattleground(Attacker, garrison, ref num, ref num2);
                    }
                    else
                    {
                        num  += Attacker.GetPropertyValue(SimulationProperties.MilitaryPower);
                        num2 += garrison.GetPropertyValue(SimulationProperties.MilitaryPower);
                        if (Attacker is Army && (Attacker as Army).IsSeafaring && garrison is Army && !(garrison as Army).IsSeafaring)
                        {
                            num2 *= 0.2f;
                        }
                    }
                    if (num > num2 * 1.5f)
                    {
                        Targets.Add(garrison);
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
        }
        if (Targets.Count == 0)
        {
            result = false;
        }
        return(result);
    }