/// <summary>
        /// Find the best reference orientation to use for jump drive coordinates.
        /// It will try one of several things:
        /// 1) Find a cockpit or RC block grouped to the FTL. If it find any, it will use the 'Main Cockpit', if set, otherwise random.
        /// 2) Search for a non-grouped cockpit or remote control block. If it finds only one, it uses that
        /// 3) If there are multiple, and one has 'FTL' in the name, it uses the first one found.
        /// 4) If there are multiple, and not named, it finds the first one with 'Main Cockpit' set
        /// 4) If there are multiple, and not named, it finds the first one with 'Control Thrusters' set
        /// 5) If there are no cockpits, it uses the original entity reference.
        /// </summary>
        /// <returns>Worldmatrix of entity to use for reference</returns>
        public static VRageMath.MatrixD GetShipReference(this IMyFunctionalBlock ftl)
        {
            VRageMath.MatrixD reference = ftl.GetTopMostParent().PositionComp.WorldMatrix;
            var controller = GetShipController(ftl);

            if (controller != null)
            {
                reference = controller.WorldMatrix;
            }

            return(reference);
        }
Esempio n. 2
0
        // Plot a course for jumping
        // This works around a game bug causing ships to be deleted if jumping to
        // a map cluster not connected to the source.
        public static HashSet <VRageMath.Vector3D> PlotJumpCourse(this IMyFunctionalBlock ftl)
        {
            var    ftld              = ftl.GetFTLData();
            var    tempList          = new HashSet <VRageMath.Vector3D>();
            var    destunit          = ftld.jumpDest - ftl.PositionComp.GetPosition();
            double remainingDistance = destunit.Length();

            destunit.Normalize();
            destunit = VRageMath.Vector3D.Negate(destunit);
            Logger.Instance.LogDebug(string.Format("Jump destination: {0:F0}, {1:F0}, {2:F0}", ftld.jumpDest.X, ftld.jumpDest.Y, ftld.jumpDest.Z));

            var clusterSize           = 10000; // VRageMath.Spatial.MyClusterTree.IdealClusterSize.Length() - 1000;
            var collisionOffsetAmount = 100;

            do
            {
                var offset = new VRageMath.Vector3D(destunit * remainingDistance);
                var pos    = ftld.jumpDest + offset;
                Logger.Instance.LogDebug(string.Format("Jump point: {0:F0}, {1:F0}, {2:F0}", pos.X, pos.Y, pos.Z));
                // Check make sure the position won't collide with anything
                var sphere = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                while (MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere).Count > 0)
                {
                    pos               += (destunit * collisionOffsetAmount);
                    sphere             = new VRageMath.BoundingSphereD(pos, ftl.GetTopMostParent().PositionComp.WorldVolume.Radius);
                    remainingDistance += collisionOffsetAmount;
                }
                tempList.Add(pos);
                remainingDistance -= clusterSize;
            } while (remainingDistance > clusterSize / 2);
            tempList.Add(ftld.jumpDest);

            //MyAPIGateway.Multiplayer.SendEntitiesCreated(obList.ToList());
            //return new HashSet<VRageMath.Vector3D>(tempList.Reverse());
            return(tempList);
        }
Esempio n. 3
0
        public static void ShowMessageToUsersInRange(IMyFunctionalBlock block, string message, int time = 2000, bool bIsError = false)
        {
            bool isMe = false;

            if (MyAPIGateway.Players == null || MyAPIGateway.Entities == null || MyAPIGateway.Session == null || MyAPIGateway.Utilities == null)
            {
                return;
            }

            if (MyAPIGateway.Multiplayer.IsServer || MyAPIGateway.Session.Player == null)
            {
                // DS, look for players
                VRageMath.BoundingBoxD box = block.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity>    entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);
                HashSet <IMyPlayer> players  = new HashSet <IMyPlayer>();

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    var player = MyAPIGateway.Players.GetPlayerControllingEntity(entity);

                    if (player != null && entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        players.Add(player);
                    }
                }

                foreach (var player in players)
                {
                    MessageUtils.SendMessageToPlayer(player.SteamUserId, new MessageText()
                    {
                        Message = message, Timeout = time, Error = bIsError
                    });
                }
            }
            else
            {
                if (MyAPIGateway.Players == null || MyAPIGateway.Entities == null || MyAPIGateway.Session == null || MyAPIGateway.Utilities == null ||
                    MyAPIGateway.Session.Player == null || MyAPIGateway.Session.Player.Controller == null ||
                    MyAPIGateway.Session.Player.Controller.ControlledEntity == null)
                {
                    return;
                }

                VRageMath.BoundingBoxD box = block.GetTopMostParent().PositionComp.WorldAABB;

                List <IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInAABB(ref box);

                foreach (var entity in entities)
                {
                    if (entity == null)
                    {
                        continue;
                    }

                    if (entity.EntityId == MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent().EntityId&&
                        entity.PositionComp.WorldAABB.Intersects(box))
                    {
                        isMe = true;
                        break;
                    }
                }

                if ((MyAPIGateway.Players.GetPlayerControllingEntity(block.GetTopMostParent()) != null &&
                     MyAPIGateway.Session.Player != null &&
                     MyAPIGateway.Session.Player.PlayerID == MyAPIGateway.Players.GetPlayerControllingEntity(block.GetTopMostParent()).PlayerID) ||
                    isMe)
                {
                    MyAPIGateway.Utilities.ShowNotification(message, time, (bIsError ? MyFontEnum.Red : MyFontEnum.White));
                }
            }
        }