Exemplo n.º 1
0
        public TryScanResults CameraTryScan(IIntelProvider intelProvider, IMyCameraBlock camera, Vector3D targetPosition, TimeSpan localTime, EnemyShipIntel enemy)
        {
            var cameraToTarget = targetPosition - camera.WorldMatrix.Translation;
            var cameraDist     = cameraToTarget.Length();

            if (!camera.CanScan(cameraDist + this.ScanExtent))
            {
                return(TryScanResults.Retry);
            }

            if (!camera.CanScan(targetPosition))
            {
                return(TryScanResults.Retry);
            }

            cameraToTarget.Normalize();
            var cameraFinalPosition = cameraToTarget * (cameraDist + this.ScanExtent) + camera.WorldMatrix.Translation;
            var info = camera.Raycast(cameraFinalPosition);

            if (info.IsEmpty())
            {
                return(TryScanResults.Retry);
            }

            // if ((ProgramReference.CubeGrid.GetPosition() - info.HitPosition.Value).Length() < ProgramReference.CubeGrid.WorldAABB.Size.Length())
            //     return TryScanResults.Retry;

            if (info.Relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership)
            {
                return(TryScanResults.DoNotRetry);
            }

            if (enemy.ID != 0 && info.EntityId != enemy.ID)
            {
                return(TryScanResults.Retry);
            }

            if (info.BoundingBox.Size.Length() * 0.5f < 4)
            {
                return(TryScanResults.Retry);
                //debugBuilder.AppendLine($"SUSP: {info.BoundingBox.Size.Length() * 0.5f}");
                //debugBuilder.AppendLine($"{info.Name}");
                //debugBuilder.AppendLine($"{info.EntityId}");
                //debugBuilder.AppendLine($"{(int)info.Position.X}, {(int)info.Position.Y}, {(int)info.Position.Z}");
                //debugBuilder.AppendLine($"{(int)info.Velocity.X}, {(int)info.Velocity.Y}, {(int)info.Velocity.Z}");
                //debugBuilder.AppendLine($"========");
                //debugBuilder.AppendLine($"{enemy.ID}");
                //var enemyPos = enemy.GetPositionFromCanonicalTime(localTime + IntelProvider.CanonicalTimeDiff);
                //debugBuilder.AppendLine($"{(int)enemyPos.X}, {(int)enemyPos.Y}, {(int)enemyPos.Z}");
                //debugBuilder.AppendLine($"{(int)enemy.CurrentVelocity.X}, {(int)enemy.CurrentVelocity.Y}, {(int)enemy.CurrentVelocity.Z}");
                //debugBuilder.AppendLine($"{enemy.Radius}");
            }

            enemy.FromDetectedInfo(info, localTime + intelProvider.CanonicalTimeDiff);
            intelProvider.ReportFleetIntelligence(enemy, localTime);

            return(TryScanResults.Scanned);
        }
Exemplo n.º 2
0
        public void TryAddEnemyShipIntel(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> intelDict, TimeSpan localTime, TimeSpan canonicalTime, MyDetectedEntityInfo target, bool validated = false, bool targetNeutral = false)
        {
            if (target.IsEmpty())
            {
                return;
            }
            if (target.Type != MyDetectedEntityType.SmallGrid && target.Type != MyDetectedEntityType.LargeGrid && target.Type != MyDetectedEntityType.Unknown)
            {
                return;
            }
            if (target.Relationship != MyRelationsBetweenPlayerAndBlock.Enemies && target.Relationship != MyRelationsBetweenPlayerAndBlock.Neutral)
            {
                return;
            }
            if (target.Relationship != MyRelationsBetweenPlayerAndBlock.Enemies && !targetNeutral)
            {
                return;
            }

            var  key         = MyTuple.Create(IntelItemType.Enemy, target.EntityId);
            bool gotNewIntel = false;
            IFleetIntelligence TargetIntel;

            if (!intelDict.TryGetValue(key, out TargetIntel))
            {
                gotNewIntel = true;
                TargetIntel = new EnemyShipIntel();
            }
            EnemyShipIntel enemyIntel = (EnemyShipIntel)TargetIntel;

            enemyIntel.ID = target.EntityId;

            if (validated && (target.Type != MyDetectedEntityType.Unknown || !gotNewIntel))
            {
                enemyIntel.DisplayName = target.Name;

                enemyIntel.FromDetectedInfo(target, canonicalTime);
                IntelProvider.ReportFleetIntelligence(enemyIntel, localTime);
            }
            else if (enemyIntel.LastValidatedCanonicalTime + TimeSpan.FromSeconds(0.5) < canonicalTime)
            {
                TryScanTarget(target.Position, localTime, enemyIntel);
            }
        }
        public HoneybeeMiningTask(MyGridProgram program, HoneybeeMiningSystem miningSystem, IAutopilot autopilot, IAgentSubsystem agentSubsystem, Waypoint target, AsteroidIntel host, IIntelProvider intelProvider, IMonitorSubsystem monitorSubsystem, IDockingSubsystem dockingSubsystem, DockTaskGenerator dockTaskGenerator, UndockFirstTaskGenerator undockTaskGenerator)
        {
            Program               = program;
            MiningSystem          = miningSystem;
            Autopilot             = autopilot;
            AgentSubsystem        = agentSubsystem;
            MonitorSubsystem      = monitorSubsystem;
            Host                  = host;
            MiningDepth           = MiningSystem.MineDepth;
            LowestExpectedOreDist = (float)MiningDepth;
            DockingSubsystem      = dockingSubsystem;

            Status = TaskStatus.Incomplete;

            double lDoc, det;

            GetSphereLineIntersects(host.Position, host.Radius, target.Position, target.Direction, out lDoc, out det);
            Perpendicular = GetPerpendicular(target.Direction);
            CoPerp        = Perpendicular.Cross(target.Direction);

            if (det < 0)
            {
                Status = TaskStatus.Aborted;
                state  = -1;
                return;
            }

            SurfaceDist = -lDoc + Math.Sqrt(det);

            ApproachPoint = target.Position + target.Direction * SurfaceDist * 0.3;
            ExitPoint     = ApproachPoint;

            EntryPoint = target.Position + target.Direction * miningSystem.CloseDist;
            MiningEnd  = target.Position - target.Direction * MiningDepth;

            SurfacePoint = target.Position;

            LeadTask = new WaypointTask(Program, Autopilot, new Waypoint(), WaypointTask.AvoidObstacleMode.SmartEnter);
            MineTask = new WaypointTask(Program, Autopilot, new Waypoint(), WaypointTask.AvoidObstacleMode.DoNotAvoid);

            LeadTask.Destination.Position    = ApproachPoint;
            LeadTask.Destination.Direction   = target.Direction * -1;
            LeadTask.Destination.DirectionUp = Perpendicular + CoPerp;
            intelProvider.ReportFleetIntelligence(LeadTask.Destination, TimeSpan.FromSeconds(1));
            MineTask.Destination.Direction   = target.Direction * -1;
            MineTask.Destination.DirectionUp = Perpendicular + CoPerp;
            MineTask.Destination.Position    = EntryPoint;

            DockTaskGenerator   = dockTaskGenerator;
            UndockTaskGenerator = undockTaskGenerator;
        }
        void Attack(TimeSpan localTime)
        {
            FriendlyShipScratchpad.Clear();

            var intelItems = IntelProvider.GetFleetIntelligences(localTime);

            foreach (var kvp in intelItems)
            {
                if (kvp.Key.Item1 == IntelItemType.Friendly)
                {
                    var friendly = (FriendlyShipIntel)kvp.Value;
                    if (friendly.AgentClass == AgentClass.Fighter && (friendly.AgentStatus & AgentStatus.Docked) != 0 && (friendly.GetPositionFromCanonicalTime(localTime + IntelProvider.CanonicalTimeDiff) - Controller.GetPosition()).Length() < 100)
                    {
                        FriendlyShipScratchpad.Add(friendly);
                    }
                }
            }

            if (FriendlyShipScratchpad.Count == 0)
            {
                return;
            }

            for (int i = 0; i < FriendlyShipScratchpad.Count; i++)
            {
                var targetWaypoint = new Waypoint();

                var gravDir = Controller.GetNaturalGravity();
                targetWaypoint.Position = Controller.GetPosition();
                var angle = 2 * i * Math.PI / FriendlyShipScratchpad.Count;

                if (gravDir != Vector3D.Zero)
                {
                    gravDir.Normalize();
                    var flatForward = Controller.WorldMatrix.Forward - VectorHelpers.VectorProjection(Controller.WorldMatrix.Forward, gravDir);
                    flatForward.Normalize();
                    var flatLeftDir = Vector3D.Cross(flatForward, gravDir);
                    targetWaypoint.Position += (flatForward * TrigHelpers.FastCos(angle) + flatLeftDir * TrigHelpers.FastSin(angle)) * 500;
                    targetWaypoint.Position -= gravDir * 200;
                }
                else
                {
                    targetWaypoint.Position += (Controller.WorldMatrix.Forward * TrigHelpers.FastCos(angle) + Controller.WorldMatrix.Left * TrigHelpers.FastSin(angle)) * 500;
                }

                targetWaypoint.Position += Controller.GetShipVelocities().LinearVelocity * 3;
                IntelProvider.ReportFleetIntelligence(targetWaypoint, localTime);
                IntelProvider.ReportCommand(FriendlyShipScratchpad[i], TaskType.Attack, MyTuple.Create(IntelItemType.Waypoint, targetWaypoint.ID), localTime);
            }
        }
        void ReportAndUpdateHangars(TimeSpan timestamp)
        {
            var intelItems = IntelProvider.GetFleetIntelligences(timestamp);

            foreach (var hangar in Hangars)
            {
                if (IsHangarOk(hangar))
                {
                    IntelProvider.ReportFleetIntelligence(GetHangarIntel(hangar, timestamp), timestamp);
                    hangar.Update(timestamp, intelItems);

                    if (requestingRefresh == false && lastConnectorStatuses.ContainsKey(hangar) &&
                        ((lastConnectorStatuses[hangar] == MyShipConnectorStatus.Connected && hangar.Connector.Status != MyShipConnectorStatus.Connected) ||
                         (lastConnectorStatuses[hangar] != MyShipConnectorStatus.Connected && hangar.Connector.Status == MyShipConnectorStatus.Connected)))
                    {
                        requestingRefresh = true;
                    }
                    lastConnectorStatuses[hangar] = hangar.Connector.Status;
                }
            }
        }