Ejemplo n.º 1
0
        protected bool TrackTargetPickSubtarget(Ingame.MyDetectedEntityInfo Target)
        {
            if (TurretPosition.DistanceTo(Target.Position) > Turret.Range)
            {
                return(false);
            }
            if (!Target.IsGrid())
            {
                IMyEntity TargetEntity = MyAPIGateway.Entities.GetEntityById(Target.EntityId);
                if (TurretPosition.DistanceTo(TargetEntity.GetPosition()) > Turret.Range)
                {
                    return(false);
                }
                Turret.TrackTarget(TargetEntity);
                return(true);
            }
            IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid;

            if (Grid == null)
            {
                return(false);
            }
            List <IMyTerminalBlock> TermBlocks = new List <IMyTerminalBlock>();
            IMyGridTerminalSystem   Term       = Grid.GetTerminalSystem();

            if (Term == null)
            {
                return(false);
            }
            Term.GetBlocks(TermBlocks);
            TermBlocks.RemoveAll(x => !x.IsFunctional);
            if (!TermBlocks.Any())
            {
                Turret.TrackTarget(Grid);
                return(true);
            }

            var PrioritizedBlocks = TermBlocks.OrderByDescending(x => PriorityIndex(x)).ThenBy(x => DistanceSq(x.GetPosition()));

            Turret.TrackTarget(PrioritizedBlocks.First());
            return(true);
        }
Ejemplo n.º 2
0
        protected bool TrackTarget(Ingame.MyDetectedEntityInfo Target, long SubtargetID)
        {
            if (TurretPosition.DistanceTo(Target.Position) > Turret.Range)
            {
                return(false);
            }
            IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid;

            if (Grid == null)
            {
                return(false);
            }
            IMyTerminalBlock        Block  = null;
            List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>();

            Grid.GetTerminalSystem().GetBlocks(Blocks);
            Block = Blocks.FirstOrDefault(x => x.EntityId == SubtargetID);
            if (Block == null || TurretPosition.DistanceTo(Block.GetPosition()) > Turret.Range)
            {
                return(false);
            }
            Turret.TrackTarget(Block);
            return(true);
        }