Пример #1
0
        protected void AddEntity(IMyEntity RadarEntity, Vector3D?Hit)
        {
            Ingame.MyDetectedEntityInfo RadarInfo = MyDetectedEntityInfoHelper.Create(RadarEntity as MyEntity, RadarBlock.OwnerId, Hit);
            bool AddMarker = DetectedEntities.Add(RadarInfo) & MarkerModule.ShouldMarkerExist(RadarInfo);

            if (!AddMarker || MarkerModule.RadarMarkers.ContainsKey(RadarInfo.EntityId))
            {
                return;
            }

            IMyVoxelMap voxel;

            if (RadarEntity is IMyCubeGrid)
            {
                string GridName = (RadarEntity as IMyCubeGrid).CustomName;
                MarkerModule.AddGPSMarker(RadarInfo.Rename(GridName), GridName);
            }
            else if (RadarEntity.IsOfType(out voxel))
            {
                string VoxelName = (!voxel.StorageName.StartsWith("Asteroid_") ? voxel.StorageName : "Asteroid");
                MarkerModule.AddGPSMarker(RadarInfo, VoxelName);
            }
            else
            {
                MarkerModule.AddGPSMarker(RadarInfo, RadarEntity.DisplayName);
            }
        }
Пример #2
0
        private float DangerIndex(Ingame.MyDetectedEntityInfo enemy)
        {
            if (enemy.Type == Ingame.MyDetectedEntityType.CharacterHuman)
            {
                return(Distance(enemy) < 100 ? 100 : 10);
            }
            if (!enemy.IsGrid())
            {
                return(0);
            }

            float       dangerIndex = 0;
            IMyCubeGrid enemyGrid   = enemy.GetGrid();
            //if (MyTrashRemoval.IsTrash(EnemyGrid as MyEntity)) return 0;

            List <IMySlimBlock> enemySlimBlocks = new List <IMySlimBlock>();

            enemyGrid.GetBlocks(enemySlimBlocks, x => x.FatBlock is IMyTerminalBlock);
            List <IMyTerminalBlock> enemyBlocks = enemySlimBlocks.Select(x => x.FatBlock as IMyTerminalBlock).ToList();

            dangerIndex += enemyBlocks.Count(x => x is IMyLargeMissileTurret) * 300;
            dangerIndex += enemyBlocks.Count(x => x is IMyLargeGatlingTurret) * 100;
            dangerIndex += enemyBlocks.Count(x => x is IMySmallMissileLauncher) * 400;
            dangerIndex += enemyBlocks.Count(x => x is IMySmallGatlingGun) * 250;
            dangerIndex += enemyBlocks.Count(x => x is IMyLargeInteriorTurret) * 40;

            if (enemy.Type == Ingame.MyDetectedEntityType.LargeGrid)
            {
                dangerIndex *= 2.5f;
            }
            return(dangerIndex);
        }
Пример #3
0
            internal void Init(ref DetectInfo detectInfo, MyCubeGrid myGrid, GridAi myAi, GridAi targetAi)
            {
                EntInfo   = detectInfo.EntInfo;
                Target    = detectInfo.Parent;
                PartCount = detectInfo.PartCount;
                FatCount  = detectInfo.FatCount;
                IsStatic  = Target.Physics.IsStatic;
                IsGrid    = detectInfo.IsGrid;
                LargeGrid = detectInfo.LargeGrid;
                MyGrid    = myGrid;
                MyAi      = myAi;
                TargetAi  = targetAi;
                Velocity  = Target.Physics.LinearVelocity;
                VelLenSqr = Velocity.LengthSquared();
                var targetSphere = Target.PositionComp.WorldVolume;

                TargetPos    = targetSphere.Center;
                TargetRadius = targetSphere.Radius;
                var myCenter = myAi.GridVolume.Center;

                if (!MyUtils.IsZero(Velocity, 1E-02F))
                {
                    var targetMag = myCenter - TargetPos;
                    Approaching = MathFuncs.IsDotProductWithinTolerance(ref Velocity, ref targetMag, myAi.Session.ApproachDegrees);
                }
                else
                {
                    Approaching   = false;
                    TargetHeading = Vector3D.Zero;
                }

                if (targetAi != null)
                {
                    OffenseRating = targetAi.Construct.OptimalDps / myAi.Construct.OptimalDps;
                    if (OffenseRating <= 0 && detectInfo.Armed)
                    {
                        OffenseRating = 0.0001f;
                    }
                }
                else if (detectInfo.Armed)
                {
                    OffenseRating = 0.0001f;
                }
                else
                {
                    OffenseRating = 0;
                }
                var myRadius       = myAi.MyGrid.PositionComp.LocalVolume.Radius;
                var sphereDistance = MyUtils.GetSmallestDistanceToSphere(ref myCenter, ref targetSphere);

                if (sphereDistance <= myRadius)
                {
                    sphereDistance = 0;
                }
                else
                {
                    sphereDistance -= myRadius;
                }
                DistSqr = sphereDistance * sphereDistance;
            }
Пример #4
0
        protected List <Ingame.MyDetectedEntityInfo> LookAround(float Radius, Func <Ingame.MyDetectedEntityInfo, bool> Filter = null)
        {
            List <Ingame.MyDetectedEntityInfo> RadarData = new List <Ingame.MyDetectedEntityInfo>();
            BoundingSphereD LookaroundSphere             = new BoundingSphereD(GridPosition, Radius);

            List <IMyEntity> EntitiesAround = MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref LookaroundSphere);

            EntitiesAround.RemoveAll(x => x == Grid || GridPosition.DistanceTo(x.GetPosition()) < GridRadius * 1.5);

            long OwnerID;

            if (OwnerFaction != null)
            {
                OwnerID = OwnerFaction.FounderId;
                Grid.DebugWrite("LookAround", "Found owner via faction owner");
            }
            else
            {
                OwnerID = RC.OwnerId;
                Grid.DebugWrite("LookAround", "OWNER FACTION NOT FOUND, found owner via RC owner");
            }

            foreach (IMyEntity DetectedEntity in EntitiesAround)
            {
                Ingame.MyDetectedEntityInfo RadarDetectedEntity = MyDetectedEntityInfoHelper.Create(DetectedEntity as MyEntity, OwnerID);
                if (Filter == null ? true : (Filter(RadarDetectedEntity)))
                {
                    RadarData.Add(RadarDetectedEntity);
                }
            }

            //DebugWrite("LookAround", $"Radar entities detected: {String.Join(" | ", RadarData.Select(x => $"{x.Name}"))}");
            return(RadarData);
        }
Пример #5
0
        public void RemoveGPSMarkers(bool PurgeAll = false)
        {
            List <long> RemoveKeys = new List <long>();

            foreach (var MarkerPair in RadarMarkers)
            {
                try
                {
                    if (PurgeAll)
                    {
                        MarkerPair.Value.Remove();
                        RadarCore.DebugWrite($"{RadarBlock.CustomName}.RemoveGPSMarkers()", $"Removing marker [{MarkerPair.Value.Name}/{MarkerPair.Value.Description}] -> purging all", true);
                        RemoveKeys.Add(MarkerPair.Key);
                    }
                    else
                    {
                        Ingame.MyDetectedEntityInfo RadarInfo = Radar.DetectedEntities.FirstOrDefault(x => x.EntityId == MarkerPair.Key);
                        if (!Radar.DetectedEntities.Any(x => x.EntityId == RadarInfo.EntityId) || !ShouldMarkerExist(RadarInfo))
                        {
                            MarkerPair.Value.Remove();
                            RadarCore.DebugWrite($"{RadarBlock.CustomName}.RemoveGPSMarkers()", $"Removing marker [{MarkerPair.Value.Name}/{MarkerPair.Value.Description}] -> entity is no longer detected", true);
                            RemoveKeys.Add(MarkerPair.Key);
                        }
                    }
                }
                catch (Exception Scrap)
                {
                    RadarCore.LogError(RadarBlock.CustomName, Scrap);
                }
            }
            RadarMarkers.RemoveAll(RemoveKeys);
        }
Пример #6
0
        public bool CanScan(Ingame.MyDetectedEntityInfo Target)
        {
            try
            {
                if (RadarCore.AllowScanningTargets == false)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scanning disabled in settings");
                    return(false);
                }
                if (!Radar.IsWorking())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Radar is disabled");
                    return(false);
                }
                if (!IsScanReady)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Scan cooldown not expired");
                    return(false);
                }
                if (Target.IsEmpty())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target struct is empty");
                    return(false);
                }
                if (!Radar.DetectedEntities.Any(x => x.EntityId == Target.EntityId))
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target not found");
                    return(false);
                }

                if (!Target.IsGrid())
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Target is not a grid");
                    return(false);
                }
                IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid;
                if (Grid == null)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Cannot resolve EntityID");
                    return(false);
                }
                float Distance        = Radar.Position.DistanceTo(Target.Position);
                float MaxScanDistance = 3000 / (float)Math.Pow(RadarCore.DecoyScanDisruptionCoefficient, Grid.AsRadarable().DecoysCount);
                if (Distance > RadarCore.GuaranteedDetectionRange && Distance > MaxScanDistance)
                {
                    RadarCore.DebugWrite($"{RadarBlock.CustomName}.CanScan()", $"Out of range: dist={Distance}; scanrange={MaxScanDistance}");
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #7
0
        public bool ShouldMarkerExist(Ingame.MyDetectedEntityInfo RadarInfo)
        {
            if (!Radar.IsWorking())
            {
                return(false);
            }
            if (!Radar.ShowMarkers)
            {
                return(false);
            }
            if (!Radar.HasOwnerInRelay)
            {
                return(false);
            }
            IMyEntity     RadarEntity = MyAPIGateway.Entities.GetEntityById(RadarInfo.EntityId);
            RadarableGrid rgrid       = null;
            bool          HasMarker   = false;

            if (RadarEntity.TryGetComponent(out rgrid))
            {
                if (Radar.ShowWorkingGridsOnly && !rgrid.IsWorkingGrid)
                {
                    return(false);
                }
                HasMarker = rgrid.MarkerRange >= Radar.Position.DistanceTo(RadarInfo.Position);
            }
            if (HasMarker)
            {
                return(true);
            }
            if (RadarInfo.Relationship.IsFriendly() && Radar.ShowOnlyHostiles)
            {
                return(false);
            }
            if (RadarInfo.Type == Ingame.MyDetectedEntityType.Asteroid && !Radar.ShowRoids)
            {
                return(false);
            }
            if (RadarInfo.Type == Ingame.MyDetectedEntityType.FloatingObject && !Radar.ShowFloating)
            {
                return(false);
            }

            return(true);
        }
Пример #8
0
        public List <Dictionary <string, string> > ScanTarget(Ingame.MyDetectedEntityInfo Target)
        {
            if (CanScan(Target) == false)
            {
                return(null);
            }
            List <Dictionary <string, string> > Scan         = new List <Dictionary <string, string> >();
            List <IMyTerminalBlock>             TargetBlocks = new List <IMyTerminalBlock>();
            IMyCubeGrid Grid = MyAPIGateway.Entities.GetEntityById(Target.EntityId) as IMyCubeGrid;

            Grid.GetTerminalSystem().GetBlocks(TargetBlocks);
            foreach (IMyTerminalBlock Block in TargetBlocks)
            {
                Scan.Add(ReadBlock(Block));
            }
            LastScan = DateTime.Now;
            return(Scan);
        }
Пример #9
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);
        }
Пример #10
0
            public DetectInfo(Session session, MyEntity parent, MyDetectedEntityInfo entInfo, int partCount, int fatCount, bool suspectedDrone, bool loneWarhead)
            {
                Parent         = parent;
                EntInfo        = entInfo;
                PartCount      = partCount;
                FatCount       = fatCount;
                SuspectedDrone = suspectedDrone;
                var armed     = false;
                var isGrid    = false;
                var largeGrid = false;
                var grid      = parent as MyCubeGrid;

                if (grid != null)
                {
                    isGrid    = true;
                    largeGrid = grid.GridSizeEnum == MyCubeSize.Large;
                    ConcurrentDictionary <WeaponDefinition.TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > blockTypeMap;
                    if (session.GridToBlockTypeMap.TryGetValue((MyCubeGrid)Parent, out blockTypeMap))
                    {
                        ConcurrentCachingList <MyCubeBlock> weaponBlocks;
                        if (blockTypeMap.TryGetValue(WeaponDefinition.TargetingDef.BlockTypes.Offense, out weaponBlocks) && weaponBlocks.Count > 0)
                        {
                            armed = true;
                        }
                        else if (blockTypeMap.TryGetValue(WeaponDefinition.TargetingDef.BlockTypes.Utility, out weaponBlocks) && weaponBlocks.Count > 0)
                        {
                            armed = true;
                        }
                    }
                }
                else if (parent is MyMeteor || parent is IMyCharacter || loneWarhead)
                {
                    armed = true;
                }

                Armed     = armed;
                IsGrid    = isGrid;
                LargeGrid = largeGrid;
            }
Пример #11
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);
        }
Пример #12
0
 /// <summary>
 /// Returns distance from the grid to an object.
 /// </summary>
 protected float Distance(Ingame.MyDetectedEntityInfo Target)
 {
     return((float)Vector3D.Distance(GridPosition, Target.Position));
 }
Пример #13
0
 protected float RelSpeed(Ingame.MyDetectedEntityInfo Target)
 {
     return((float)(Target.Velocity - GridVelocity).Length());
 }
Пример #14
0
        public void AddGPSMarker(Ingame.MyDetectedEntityInfo RadarScan, string EntityName, bool DontAddIfDetectedByRadioMarker = true)
        {
            try
            {
                try
                {
                    //RadarCore.DebugWrite($"{Radar.CustomName}", $"Trying to add marker for entity {RadarScan.Type.ToString()} {RadarScan.Name}");
                    if (Radar.OwnerID == 0)
                    {
                        return;
                    }
                    if (!Radar.HasOwnerInRelay)
                    {
                        return;
                    }
                    if (Radar.OwnerGPSes.Any(x => x.Description == $"RadarEntity {RadarScan.EntityId}"))
                    {
                        return;
                    }
                    if (Radar.OwnerEntity?.GetTopMostParent()?.EntityId == RadarScan.EntityId)
                    {
                        return;
                    }
                    if (Radar.MyRadarGrid.RelayedGrids.Any(x => x.EntityId == RadarScan.EntityId))
                    {
                        return;
                    }
                    if (DontAddIfDetectedByRadioMarker && RadarScan.HitPosition == null)
                    {
                        return;
                    }
                }
                catch (Exception Scrap)
                {
                    RadarCore.LogError("Radar.AddGPSMarker.GetOwnerPlayer", Scrap);
                    return;
                }

                if (RadarMarkers.ContainsKey(RadarScan.EntityId))
                {
                    return;
                }
                IMyEntity AttachTo = MyAPIGateway.Entities.GetEntityById(RadarScan.EntityId);
                if (AttachTo == null)
                {
                    return;
                }
                StringBuilder MarkerName = new StringBuilder();
                if (RadarScan.Type == Ingame.MyDetectedEntityType.Asteroid && EntityName == "Asteroid")
                {
                    MarkerName.Append("[Asteroid]");
                }
                else if (RadarScan.IsGrid() && (EntityName.StartsWith("Large Grid") || EntityName.StartsWith("Small Grid")))
                {
                    if (RadarScan.Type == Ingame.MyDetectedEntityType.LargeGrid)
                    {
                        MarkerName.Append("[Large Grid]");
                    }
                    else
                    {
                        MarkerName.Append("[Small Grid]");
                    }
                }
                else
                {
                    MarkerName.Append($"[{RadarScan.Type.ToString()}{(RadarScan.IsAllied() ? $" | {RadarScan.Name.Truncate(50)}" : $"{(!string.IsNullOrWhiteSpace(EntityName) ? " | " + EntityName.Truncate(50) : "")}")}]");
                }
                GPSMarker Marker = GPSMarker.Create(AttachTo, MarkerName.ToString(), $"RadarEntity {RadarScan.EntityId}", RadarScan.GetRelationshipColor(), Radar.OwnerID);
                RadarMarkers.Add(RadarScan.EntityId, Marker);
            }
            catch (Exception Scrap)
            {
                RadarCore.LogError("Radar.AddGPSMarker", Scrap);
            }
        }
Пример #15
0
        private void Flee(List <Ingame.MyDetectedEntityInfo> radarData = null)
        {
            try
            {
                if (!IsFleeing)
                {
                    return;
                }

                try
                {
                    if (!FleeTimersTriggered)
                    {
                        TriggerFleeTimers();
                    }

                    try
                    {
                        if (radarData == null)
                        {
                            radarData = LookForEnemies(_freighterSetup.FleeTriggerDistance);
                        }
                        if (radarData.Count == 0)
                        {
                            return;
                        }

                        try
                        {
                            Ingame.MyDetectedEntityInfo closestEnemy = radarData.OrderBy(x => GridPosition.DistanceTo(x.Position)).FirstOrDefault();

                            if (closestEnemy.IsEmpty())
                            {
                                Grid.DebugWrite("Flee", "Cannot find closest hostile");
                                return;
                            }

                            try
                            {
                                IMyEntity enemyEntity = MyAPIGateway.Entities.GetEntityById(closestEnemy.EntityId);
                                if (enemyEntity == null)
                                {
                                    Grid.DebugWrite("Flee", "Cannot find enemy entity from closest hostile ID");
                                    return;
                                }

                                try
                                {
                                    //Grid.DebugWrite("Flee", $"Fleeing from '{EnemyEntity.DisplayName}'. Distance: {Math.Round(GridPosition.DistanceTo(ClosestEnemy.Position))}m; FleeTriggerDistance: {FreighterSetup.FleeTriggerDistance}");
                                    //ShowIngameMessage.ShowMessage($"Fleeing from '{enemyEntity.DisplayName}'. Distance: {Math.Round(GridPosition.DistanceTo(closestEnemy.Position))}m; FleeTriggerDistance: {_freighterSetup.FleeTriggerDistance}");
                                    Vector3D fleePoint = GridPosition.InverseVectorTo(closestEnemy.Position, 100 * 1000);
                                    //ShowIngameMessage.ShowMessage($"Flee point: {fleePoint} which is {GridPosition.DistanceTo(fleePoint)}m from me and enemy {enemyEntity.DisplayName}");
                                    //ShowIngameMessage.ShowMessage($"Fleeing at: {DetermineFleeSpeed()}m/s...");
                                    Rc.AddWaypoint(fleePoint, "Flee Point");
                                    (Rc as MyRemoteControl)?.ChangeFlightMode(Ingame.FlightMode.OneWay);
                                    (Rc as MyRemoteControl)?.SetAutoPilotSpeedLimit(DetermineFleeSpeed());
                                    Rc.SetAutoPilotEnabled(true);
                                }
                                catch (Exception scrap)
                                {
                                    Grid.LogError("Flee.AddWaypoint", scrap);
                                }
                            }
                            catch (Exception scrap)
                            {
                                Grid.LogError("Flee.LookForEnemies.GetEntity", scrap);
                            }
                        }
                        catch (Exception scrap)
                        {
                            Grid.LogError("Flee.LookForEnemies.Closest", scrap);
                        }
                    }
                    catch (Exception scrap)
                    {
                        Grid.LogError("Flee.LookForEnemies", scrap);
                    }
                }
                catch (Exception scrap)
                {
                    Grid.LogError("Flee.TriggerTimers", scrap);
                }
            }
            catch (Exception scrap)
            {
                Grid.LogError("Flee", scrap);
            }
        }
Пример #16
0
        private void Flee(List <Ingame.MyDetectedEntityInfo> RadarData = null)
        {
            try
            {
                if (!IsFleeing)
                {
                    return;
                }

                try
                {
                    if (!FleeTimersTriggered)
                    {
                        TriggerFleeTimers();
                    }

                    try
                    {
                        if (RadarData == null)
                        {
                            RadarData = LookForEnemies(FreighterSetup.FleeTriggerDistance);
                        }
                        if (RadarData.Count == 0)
                        {
                            return;
                        }

                        try
                        {
                            Ingame.MyDetectedEntityInfo ClosestEnemy = RadarData.OrderBy(x => GridPosition.DistanceTo(x.Position)).FirstOrDefault();

                            if (ClosestEnemy.IsEmpty())
                            {
                                Grid.DebugWrite("Flee", "Cannot find closest hostile");
                                return;
                            }

                            try
                            {
                                IMyEntity EnemyEntity = MyAPIGateway.Entities.GetEntityById(ClosestEnemy.EntityId);
                                if (EnemyEntity == null)
                                {
                                    Grid.DebugWrite("Flee", "Cannot find enemy entity from closest hostile ID");
                                    return;
                                }

                                try
                                {
                                    //Grid.DebugWrite("Flee", $"Fleeing from '{EnemyEntity.DisplayName}'. Distance: {Math.Round(GridPosition.DistanceTo(ClosestEnemy.Position))}m; FleeTriggerDistance: {FreighterSetup.FleeTriggerDistance}");

                                    Vector3D FleePoint = GridPosition.InverseVectorTo(ClosestEnemy.Position, 100 * 1000);
                                    RC.AddWaypoint(FleePoint, "Flee Point");
                                    (RC as MyRemoteControl).ChangeFlightMode(MyRemoteControl.FlightMode.OneWay);
                                    (RC as MyRemoteControl).SetAutoPilotSpeedLimit(DetermineFleeSpeed());
                                    RC.SetAutoPilotEnabled(true);
                                }
                                catch (Exception Scrap)
                                {
                                    Grid.LogError("Flee.AddWaypoint", Scrap);
                                }
                            }
                            catch (Exception Scrap)
                            {
                                Grid.LogError("Flee.LookForEnemies.GetEntity", Scrap);
                            }
                        }
                        catch (Exception Scrap)
                        {
                            Grid.LogError("Flee.LookForEnemies.Closest", Scrap);
                        }
                    }
                    catch (Exception Scrap)
                    {
                        Grid.LogError("Flee.LookForEnemies", Scrap);
                    }
                }
                catch (Exception Scrap)
                {
                    Grid.LogError("Flee.TriggerTimers", Scrap);
                }
            }
            catch (Exception Scrap)
            {
                Grid.LogError("Flee", Scrap);
            }
        }
Пример #17
0
        public static void InitTurretControls()
        {
            if (InitedTurretControls)
            {
                return;
            }
            if (!MyAPIGateway.Session.IsServer)
            {
                return;
            }
            var GetTarget = MyAPIGateway.TerminalControls.CreateProperty <Ingame.MyDetectedEntityInfo, IMyLargeTurretBase>("CurrentTarget");

            GetTarget.Enabled = Block =>
            {
                IMyLargeTurretBase Turret = Block as IMyLargeTurretBase;
                return(Turret.AIEnabled);
            };
            GetTarget.Getter = Block =>
            {
                IMyLargeTurretBase Turret = Block as IMyLargeTurretBase;
                if (!Turret.HasTarget)
                {
                    return(new Ingame.MyDetectedEntityInfo());
                }
                Ingame.MyDetectedEntityInfo Target = Sandbox.Game.Entities.MyDetectedEntityInfoHelper.Create(Turret.Target as VRage.Game.Entity.MyEntity, Block.OwnerId, null);
                return(Target);
            };
            GetTarget.Setter = (Block, trash) =>
            {
                throw new Exception("The CurrentTarget property is read-only. Invoke the TrackTarget property-function to set a target.");
            };
            MyAPIGateway.TerminalControls.AddControl <IMyLargeTurretBase>(GetTarget);

            var SetTarget = MyAPIGateway.TerminalControls.CreateProperty <Func <Ingame.MyDetectedEntityInfo, long, bool>, IMyLargeTurretBase>("TrackSubtarget");

            SetTarget.Enabled = Block =>
            {
                IMyLargeTurretBase Turret = Block as IMyLargeTurretBase;
                return(Turret.AIEnabled);
            };
            SetTarget.Getter = Block =>
            {
                try
                {
                    AdvTurretBase Turret;
                    if (Block.TryGetComponent(out Turret))
                    {
                        return(Turret.TrackTargetAction);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception Scrap)
                {
                    throw new Exception($"Exception is SetTarget.Getter: {Scrap.Message}");
                }
            };
            SetTarget.Setter = (Block, trash) =>
            {
                throw new Exception("The TrackSubtarget property is a function and cannot be set.");
            };
            MyAPIGateway.TerminalControls.AddControl <IMyLargeTurretBase>(SetTarget);

            var SetTargetPickSubtarget = MyAPIGateway.TerminalControls.CreateProperty <Func <Ingame.MyDetectedEntityInfo, bool>, IMyLargeTurretBase>("TrackTarget");

            SetTargetPickSubtarget.Enabled = Block =>
            {
                IMyLargeTurretBase Turret = Block as IMyLargeTurretBase;
                return(Turret.AIEnabled);
            };
            SetTargetPickSubtarget.Getter = Block =>
            {
                AdvTurretBase Turret;
                if (Block.TryGetComponent(out Turret))
                {
                    return(Turret.TrackTargetPickSubtargetAction);
                }
                else
                {
                    return(null);
                }
            };
            SetTargetPickSubtarget.Setter = (Block, trash) =>
            {
                throw new Exception("The TrackTarget property is a function and cannot be set.");
            };
            MyAPIGateway.TerminalControls.AddControl <IMyLargeTurretBase>(SetTargetPickSubtarget);

            var ResetTargetingProp = MyAPIGateway.TerminalControls.CreateProperty <Action, IMyLargeTurretBase>("ResetTargeting");

            ResetTargetingProp.Enabled = Block =>
            {
                IMyLargeTurretBase Turret = Block as IMyLargeTurretBase;
                return(Turret.AIEnabled);
            };
            ResetTargetingProp.Getter = Block =>
            {
                AdvTurretBase Turret;
                if (Block.TryGetComponent(out Turret))
                {
                    return(Turret.ResetTargeting);
                }
                else
                {
                    return(null);
                }
            };
            ResetTargetingProp.Setter = (Block, trash) =>
            {
                throw new Exception("The ResetTargeting property is a function and cannot be set.");
            };
            MyAPIGateway.TerminalControls.AddControl <IMyLargeTurretBase>(ResetTargetingProp);
            InitedTurretControls = true;
        }
Пример #18
0
 protected Vector3 RelVelocity(Ingame.MyDetectedEntityInfo Target)
 {
     return(Target.Velocity - GridVelocity);
 }