private float DangerIndex(Ingame.MyDetectedEntityInfo enemy) { AiSessionCore.DebugLog?.WriteToLog("DangerIndex", $"EnemyHuman:\t{enemy.Type == Ingame.MyDetectedEntityType.CharacterHuman}"); AiSessionCore.DebugLog?.WriteToLog("DangerIndex", $"EnemyGrid:\t{enemy.IsGrid()}\t{enemy.GetGrid()?.CustomName}"); 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); }
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); } }
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); }
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 != null && 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); }
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); } }