protected override void RefreshObjectives(StaticString context, StaticString pass)
 {
     base.RefreshObjectives(context, pass);
     for (int i = 0; i < this.MajorEmpire.TamedKaijus.Count; i++)
     {
         Kaiju kaiju = this.MajorEmpire.TamedKaijus[i];
         if (kaiju.OnArmyMode())
         {
             AICommander aicommander = this.aiCommanders.Find((AICommander match) => match.ForceArmyGUID == kaiju.KaijuArmy.GUID);
             if (aicommander == null)
             {
                 this.AddCommander(new AICommander_KaijuSupport
                 {
                     ForceArmyGUID = kaiju.KaijuArmy.GUID,
                     Empire        = base.AIEntity.Empire,
                     AIPlayer      = base.AIEntity.AIPlayer
                 });
             }
             else
             {
                 aicommander.Initialize();
                 aicommander.Load();
                 aicommander.CreateMission();
             }
         }
     }
 }
    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);
    }
Exemplo n.º 3
0
    public void FillTargets(Army army, List <IGameEntity> gameEntities, ref List <StaticString> failureFlags)
    {
        if (army == null)
        {
            throw new ArgumentNullException("army");
        }
        IGameService service = Services.GetService <IGameService>();

        if (service == null)
        {
            return;
        }
        global::Game x = service.Game as global::Game;

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

        Diagnostics.Assert(service2 != null);
        for (int i = 0; i < 6; i++)
        {
            WorldPosition neighbourTile = service2.GetNeighbourTile(army.WorldPosition, (WorldOrientation)i, 1);
            Region        region        = service2.GetRegion(neighbourTile);
            if (region != null && region.Kaiju != null)
            {
                Kaiju kaiju = region.Kaiju;
                if (this.IsKaijuValidForTame(army, kaiju, ref failureFlags, true) && !gameEntities.Contains(kaiju))
                {
                    gameEntities.Add(kaiju);
                }
            }
            Army armyAtPosition = service2.GetArmyAtPosition(neighbourTile);
            if (armyAtPosition != null && armyAtPosition is KaijuArmy)
            {
                KaijuArmy kaijuArmy = armyAtPosition as KaijuArmy;
                if (kaijuArmy != null)
                {
                    Kaiju kaiju2 = kaijuArmy.Kaiju;
                    if (kaiju2 != null && kaiju2.OnArmyMode() && !kaiju2.IsStunned() && !gameEntities.Contains(kaiju2))
                    {
                        gameEntities.Add(kaijuArmy.Kaiju);
                    }
                }
            }
        }
    }
    private void CreateRelocationNeeds()
    {
        float num = 0f;

        foreach (Kaiju kaiju in this.MajorEmpire.TamedKaijus)
        {
            if (kaiju.OnArmyMode())
            {
                num += kaiju.KaijuArmy.GetPropertyValue(SimulationProperties.LandMilitaryPower);
            }
            else
            {
                num += kaiju.KaijuGarrison.GetPropertyValue(SimulationProperties.LandMilitaryPower);
            }
        }
        this.KaijusToRise.Clear();
        this.KaijuSupport = (this.DiplomacyLayer.GetMilitaryPowerDif(false) - num <= (base.AIEntity.Empire.GetPropertyValue(SimulationProperties.LandMilitaryPower) - num) * 0.4f);
        List <Region>       list  = new List <Region>();
        List <StaticString> list2 = new List <StaticString>();

        for (int i = 0; i < this.MajorEmpire.TamedKaijus.Count; i++)
        {
            Kaiju kaiju2 = this.MajorEmpire.TamedKaijus[i];
            list2.Clear();
            if (!kaiju2.OnArmyMode() && this.garrisonAction_MigrateKaiju.CanExecute(kaiju2.KaijuGarrison, ref list2, new object[0]) && this.garrisonAction_MigrateKaiju.ComputeRemainingCooldownDuration(kaiju2.KaijuGarrison) < 1f)
            {
                if (!this.KaijuSupport || !this.IsKaijuValidForSupport(kaiju2))
                {
                    Region mostProfitableRegionForKaiju = this.GetMostProfitableRegionForKaiju(kaiju2, list);
                    if (mostProfitableRegionForKaiju != null && kaiju2.Region != mostProfitableRegionForKaiju)
                    {
                        WorldPosition bestDefensiveKaijuPosition = this.GetBestDefensiveKaijuPosition(mostProfitableRegionForKaiju);
                        if (bestDefensiveKaijuPosition.IsValid)
                        {
                            list.Add(mostProfitableRegionForKaiju);
                            KaijuRelocationMessage message = new KaijuRelocationMessage(kaiju2.GUID, bestDefensiveKaijuPosition);
                            base.AIEntity.AIPlayer.Blackboard.AddMessage(message);
                        }
                    }
                }
                else
                {
                    this.KaijusToRise.Add(kaiju2.GUID);
                }
            }
        }
    }
    private bool IsRelocationMessageValid(KaijuRelocationMessage message)
    {
        Kaiju kaiju = null;

        if (!this.gameEntityRepositoryService.TryGetValue <Kaiju>(message.KaijuGUID, out kaiju) || !this.MajorEmpire.TamedKaijus.Contains(kaiju))
        {
            return(false);
        }
        if (kaiju.OnArmyMode())
        {
            return(false);
        }
        WorldPosition targetPosition = message.TargetPosition;

        if (!targetPosition.IsValid || !KaijuCouncil.IsPositionValidForSettleKaiju(targetPosition, null))
        {
            return(false);
        }
        Region region = this.worldPositionningService.GetRegion(message.TargetPosition);

        if (region == null || !KaijuCouncil.IsRegionValidForSettleKaiju(region))
        {
            return(false);
        }
        for (int i = 0; i < this.validatedRelocationMessages.Count; i++)
        {
            KaijuRelocationMessage kaijuRelocationMessage = this.validatedRelocationMessages[i];
            GameEntityGUID         kaijuGUID  = message.KaijuGUID;
            GameEntityGUID         kaijuGUID2 = kaijuRelocationMessage.KaijuGUID;
            if (kaijuGUID == kaijuGUID2)
            {
                return(false);
            }
            int regionIndex  = (int)this.worldPositionningService.GetRegionIndex(message.TargetPosition);
            int regionIndex2 = (int)this.worldPositionningService.GetRegionIndex(kaijuRelocationMessage.TargetPosition);
            if (regionIndex == regionIndex2)
            {
                return(false);
            }
        }
        return(true);
    }
 private void AILayer_KaijuManagement_TamedKaijusCollectionChanged(object sender, CollectionChangeEventArgs e)
 {
     if (e.Action == CollectionChangeAction.Add && this.IsActive())
     {
         Kaiju kaiju = e.Element as Kaiju;
         if (kaiju != null && this.MajorEmpire.TamedKaijus.Contains(kaiju) && kaiju.OnArmyMode())
         {
             AICommander aicommander = this.aiCommanders.Find((AICommander match) => match.ForceArmyGUID == kaiju.KaijuArmy.GUID);
             if (aicommander == null)
             {
                 this.AddCommander(new AICommander_KaijuSupport
                 {
                     ForceArmyGUID = kaiju.KaijuArmy.GUID,
                     Empire        = base.AIEntity.Empire,
                     AIPlayer      = base.AIEntity.AIPlayer
                 });
                 return;
             }
             aicommander.Initialize();
             aicommander.Load();
             aicommander.CreateMission();
         }
     }
 }
Exemplo n.º 7
0
    private bool IsKaijuValidForObjective(Kaiju kaiju)
    {
        bool flag = false;

        if (kaiju == null)
        {
            return(flag);
        }
        int regionIndex = (int)this.worldPositionningService.GetRegionIndex(kaiju.WorldPosition);

        if (!this.departmentOfForeignAffairs.CanMoveOn(regionIndex, false))
        {
            return(false);
        }
        if (kaiju.MajorEmpire != null)
        {
            if (!this.departmentOfForeignAffairs.CanAttack(kaiju.GetActiveTroops()))
            {
                return(false);
            }
            if (kaiju.OnArmyMode())
            {
                District district = this.worldPositionningService.GetDistrict(kaiju.WorldPosition);
                if (district != null && District.IsACityTile(district))
                {
                    return(false);
                }
            }
            if (this.departmentOfForeignAffairs.IsInWarWithSomeone())
            {
                flag = !this.departmentOfForeignAffairs.IsAtWarWith(kaiju.MajorEmpire);
            }
            else
            {
                flag = this.departmentOfForeignAffairs.IsFriend(kaiju.MajorEmpire);
            }
        }
        if (!flag && kaiju.Empire.Index != base.AIEntity.Empire.Index && this.departmentOfTheInterior.Cities.Count > 0)
        {
            if (this.departmentOfCreepingNodes != null)
            {
                Region region = this.worldPositionningService.GetRegion(kaiju.WorldPosition);
                foreach (CreepingNode creepingNode in this.departmentOfCreepingNodes.Nodes)
                {
                    if (!creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(base.AIEntity.Empire, creepingNode) && creepingNode.Region.Index == region.Index)
                    {
                        return(true);
                    }
                }
            }
            foreach (Army army in this.departmentOfDefense.Armies)
            {
                if (!army.IsSeafaring)
                {
                    if (this.pathfindingService.FindPath(army, this.departmentOfTheInterior.Cities[0].WorldPosition, kaiju.WorldPosition, PathfindingManager.RequestMode.Default, null, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null) == null)
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
        return(false);
    }