public static IMyEntity GetMissileTargetForGrid(IMyEntity grid)
        {
            try
            {
                MyEntityComponentContainer  componentContainer = grid.Components;
                GuidedMissileTargetGridHook targetGridHook     = null;

                foreach (MyComponentBase comp in componentContainer)
                {
                    var hook = comp as GuidedMissileTargetGridHook;
                    if (hook != null)
                    {
                        targetGridHook = hook;
                    }
                    if (comp is MyCompositeGameLogicComponent)
                    {
                        //  Log.Info("we got a composite component!");
                        targetGridHook = comp.GetAs <GuidedMissileTargetGridHook>();
                    }
                }
                if (targetGridHook != null)
                {
                    return(targetGridHook.GetMissileTarget());
                }
            }
            catch (Exception e)
            {
                Log.Info("Error during GetMissileTargetForGrid: " + e);
                return(null);
            }
            return(null);
        }
Exemplo n.º 2
0
        protected virtual IMyEntity GetTarget(IMyEntity missile)
        {
            IMyEntity targetGrid = GuidedMissileTargetGridHook.GetMissileTargetForGrid(Entity.GetTopMostParent());
            IMyEntity target     = GuidedMissileTargetGridHook.GetRandomBlockInGrid(targetGrid);

            if (target == null)
            {
                target = targetGrid;
            }
            return(target);
        }
Exemplo n.º 3
0
        public bool AssignTarget(IMyEntity target)
        {
            if (target == null)
            {
                return(false);
            }
            // if(target.OwnerId == Entity.OwnerId) return false; //faction check?
            bool success = GuidedMissileTargetGridHook.SetMissileTargetForGrid(Entity.GetTopMostParent(), target);

            return(success);
        }
Exemplo n.º 4
0
        public bool AssignTarget(IMyEntity target)
        {
            ModDebugger.Launch();
            Log.Info("called assignTarget with entity " + target);
            if (target == null)
            {
                return(false);
            }
            // if(target.OwnerId == Entity.OwnerId) return false; //faction check?
            bool success = GuidedMissileTargetGridHook.SetMissileTargetForGrid(Entity.GetTopMostParent(), target);

            return(success);
        }
        public static bool SetMissileTargetForGrid(IMyEntity grid, IMyEntity target)
        {
            if (grid == null)
            {
                Log.Info("The grid seems to be null, no target could be assigned.");
                return(false);
            }
            if (target == null)
            {
                Log.Info("The target seems to be null, no target could be assigned.");
                return(false);
            }

            MyEntityComponentContainer componentContainer = grid.Components;

            if (componentContainer == null)
            {
                //     Log.Info("The grid.Components are null. Could not assign a target!");
                return(false);
            }

            GuidedMissileTargetGridHook targetGridHook = null;

            foreach (MyComponentBase comp in componentContainer)
            {
                var hook = comp as GuidedMissileTargetGridHook;
                if (hook != null)
                {
                    targetGridHook = hook;
                }
                if (comp is MyCompositeGameLogicComponent)
                {
                    //       Log.Info("we got a composite component!");
                    targetGridHook = comp.GetAs <GuidedMissileTargetGridHook>();
                }
            }
            if (targetGridHook == null)
            {
                //  Log.Info("We did not found our TargetGridHook. A target could not be assigned!");
                //  Log.Info("This is what we had: ");
                foreach (MyComponentBase comp in componentContainer)
                {
                    Log.Info(comp.ToString());
                }
                return(false);
            }
            return(targetGridHook.SetMissileTarget(target));
        }
Exemplo n.º 6
0
 public bool IsExpired()
 {
     if (Missile == null)
     {
         return(true);
     }
     if (Target == null)
     {
         return(true);
     }
     if (Missile.MarkedForClose)
     {
         _onExplode(Missile);
         return(true);
     }
     if (TrackedFrames > _deathTimer)
     {
         Missile.Close();
         return(true);
     }
     if (Target.MarkedForClose)
     {
         // Log.Info("Target is marked for close, searching new one");
         if (Target.GetTopMostParent().MarkedForClose)
         {
             return(true);
         }
         IMyEntity newTarget = GuidedMissileTargetGridHook.GetRandomBlockInGrid(Target);
         if (newTarget == null)
         {
             return(true);
         }
         Target                = newTarget;
         _isOvershooting       = false;
         _overshootDistance    = 0f;
         _finishedOvershooting = false;
         return(false);
         //  return true;
     }
     return(false);
 }
        protected override IMyEntity GetTarget(IMyEntity missile)
        {
            //IMyEntity targetGrid = GuidedMissileTargetGridHook.GetMissileTargetForGrid(Entity.GetTopMostParent());


            Ray       ray        = new Ray(missile.GetPosition(), Vector3.Normalize(missile.WorldMatrix.Forward));
            IMyEntity targetGrid = GuidedMissileCore.GetClosestTargetAlongRay(ray, 3000, 7, Entity.GetTopMostParent());
            IMyEntity target     = GuidedMissileTargetGridHook.GetRandomBlockInGrid(targetGrid);

            if (target == null)
            {
                //  Log.Info("target was null...");
                //   if (targetGrid == null) Log.Info("targetgrid was null as well!");
                target = targetGrid;
                Log.Info("target was null, now set to grid");
                //  IMyEntity grid = target;
            }

            //  Log.Info("got a target: " + target.ToString());

            if (target != null)
            {
                IMyPlayerCollection allPlayers = MyAPIGateway.Players;

                List <IMyPlayer> playerList = new List <IMyPlayer>();

                HashSet <IMyEntity> componentSet = new HashSet <IMyEntity>();

                Entity.GetTopMostParent().Hierarchy.GetChildrenRecursive(componentSet);
                List <IMyEntity> componentList = new List <IMyEntity>();
                componentList.AddRange(componentSet);

                allPlayers.GetPlayers(playerList);
                componentSet.Clear();


                foreach (IMyEntity component in componentList)
                {
                    if (component is IMyCockpit)
                    {
                        componentSet.Add(component);
                    }
                }

                foreach (IMyPlayer player in playerList)
                {
                    if (MyAPIGateway.Session.Player == player)
                    {
                        if ((player != null) && (player.Controller != null) && (player.Controller.ControlledEntity != null) && (player.Controller.ControlledEntity.Entity != null))
                        {
                            foreach (IMyEntity entity in componentSet)
                            {
                                if (player.Controller.ControlledEntity.Entity.EntityId == entity.EntityId)
                                {
                                    MyAPIGateway.Utilities.ShowNotification("" + target.GetTopMostParent().DisplayName + " was set as missile target!", 2000, MyFontEnum.Red);
                                }
                            }
                        }
                    }
                }
            }
            return(target);
        }