当前位置: 首页>>代码示例>>C#>>正文


C# IMyEntity.GetPosition方法代码示例

本文整理汇总了C#中IMyEntity.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IMyEntity.GetPosition方法的具体用法?C# IMyEntity.GetPosition怎么用?C# IMyEntity.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMyEntity的用法示例。


在下文中一共展示了IMyEntity.GetPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindPlayer

        private IMyPlayer FindPlayer(IMyEntity entity)
        {
            List<IMyPlayer> players = new List<IMyPlayer>();
            MyAPIGateway.Players.GetPlayers(players);

            double nearestDistance = 5; // usually the distance between player and handtool is about 2 to 3, 5 is plenty 
            IMyPlayer nearestPlayer = null;

            foreach (IMyPlayer player in players)
            {
                var character = player.GetCharacter();
                if (character != null)
                {
                    var distance = (((IMyEntity)character).GetPosition() - entity.GetPosition()).LengthSquared();

                    if (distance < nearestDistance)
                    {
                        nearestDistance = distance;
                        nearestPlayer = player;
                    }
                }
            }

            return nearestPlayer;
        }
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:25,代码来源:HandtoolCache.cs

示例2: Waypoint

        public Waypoint(Mover mover, AllNavigationSettings navSet, AllNavigationSettings.SettingsLevelName level, IMyEntity targetEntity, Vector3D worldOffset)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_level = level;
            this.m_targetEntity = targetEntity;
            this.m_targetOffset = worldOffset;

            m_logger.debugLog(targetEntity != targetEntity.GetTopMostParent(), "targetEntity is not top-most", Logger.severity.FATAL);

            IMyCubeGrid asGrid = targetEntity as IMyCubeGrid;
            if (asGrid != null && Attached.AttachedGrid.IsGridAttached(asGrid, m_controlBlock.CubeGrid, Attached.AttachedGrid.AttachmentKind.Physics))
            {
                m_logger.debugLog("Cannot fly to entity, attached: " + targetEntity.getBestName() + ", creating GOLIS", Logger.severity.WARNING);
                new GOLIS(mover, navSet, TargetPosition, level);
                return;
            }
            if (targetEntity.Physics == null)
            {
                m_logger.debugLog("Target has no physics: " + targetEntity.getBestName() + ", creating GOLIS", Logger.severity.WARNING);
                new GOLIS(mover, navSet, TargetPosition, level);
                return;
            }

            var setLevel = navSet.GetSettingsLevel(level);
            setLevel.NavigatorMover = this;
            //setLevel.DestinationEntity = mover.Block.CubeBlock; // to force avoidance

            m_logger.debugLog("created, level: " + level + ", target: " + targetEntity.getBestName() + ", target position: " + targetEntity.GetPosition() + ", offset: " + worldOffset + ", position: " + TargetPosition, Logger.severity.DEBUG);
        }
开发者ID:Souper07,项目名称:Autopilot,代码行数:30,代码来源:Waypoint.cs

示例3: ConcealedEntity

 // Creation from ingame entity before it's removed
 public ConcealedEntity(IMyEntity entity)
     : this()
 {
     EntityId = entity.EntityId;
     DisplayName = entity.DisplayName;
     Position = entity.GetPosition();
     BoundingBox = entity.WorldAABB;
     WorldTranslation = entity.WorldMatrix.Translation;
     //TODO: stop entity if moving, we never update the below
     // and really we should never conceal a grid that's moving
     LinearVelocity = entity.Physics.LinearVelocity;
     Log = new Logger("GP.Concealment.World.Entities.ConcealedEntity",
         EntityId.ToString());
 }
开发者ID:zrisher,项目名称:GardenPerformance,代码行数:15,代码来源:ConcealedEntity.cs

示例4: CalculateRotation

        public static Vector2 CalculateRotation(Vector3D direction, IMyEntity _shipControls)
        {
            var _dir = direction - _shipControls.GetPosition();
            var dirNorm = Vector3D.Normalize(_dir);
            var x = -(_shipControls as IMyEntity).WorldMatrix.Up.Dot(dirNorm);
            var y = -(_shipControls as IMyEntity).WorldMatrix.Left.Dot(dirNorm);
            var forw = (_shipControls as IMyEntity).WorldMatrix.Forward.Dot(dirNorm);

            if (forw < 0)
                y = 0;
            if (Math.Abs(x) < 0.07f)
                x = 0;
            if (Math.Abs(y) < 0.07f)
                y = 0;

            return new Vector2((float)x, (float)y);
        }
开发者ID:ESearcy,项目名称:PVE-AI-Drones-Drone-Conquest,代码行数:17,代码来源:NavInfo.cs

示例5: SendVoxelData

        private static void SendVoxelData( ulong steamId, IMyEntity voxel )
        {
            try
            {
                IMyVoxelMap voxelMap = (IMyVoxelMap)voxel;

                byte[ ] voxelData;
                voxelMap.Storage.Save( out voxelData );

                VoxelHeaderData header = new VoxelHeaderData( );
                header.EntityId = voxel.EntityId;
                header.HalfExtent = voxelMap.Storage.Size / 2;
                header.Position = voxel.GetPosition( );
                header.Name = voxelMap.StorageName;
                header.DataLength = voxelData.Length;

                string headerString = MyAPIGateway.Utilities.SerializeToXML<VoxelHeaderData>( header );
                ushort length = (ushort)headerString.Length;

                byte[ ] headerData = new byte[ 2 + headerString.Length ];

                headerData[ 0 ] = (byte)length;
                headerData[ 1 ] = (byte)( length >> 8 );

                for ( int r = 0; r < headerString.Length; r++ )
                {
                    headerData[ r + 2 ] = (byte)headerString[ r ];
                }
                Essentials.Log.Debug( "Sending Voxel Header Data: {0} / {1} - {2} ({3})", voxelData.Length, headerData.Length, steamId, voxel.GetPosition( ) );
                Communication.SendDataMessage( steamId, 5001, headerData );

                int blockSize = 4096;
                for ( ushort r = 0; r < ( voxelData.Length / blockSize ) + 1; r++ )
                {
                    int partLength = voxelData.Length - ( r * blockSize );

                    if ( partLength > blockSize )
                        partLength = blockSize;

                    byte[ ] outData = new byte[ partLength + 12 ];

                    for ( int s = 0; s < 8; s++ )
                        outData[ s ] = (byte)( header.EntityId >> ( s * 8 ) );

                    for ( int s = 0; s < 2; s++ )
                        outData[ s + 8 ] = (byte)( partLength >> ( s * 8 ) );

                    for ( int s = 0; s < 2; s++ )
                        outData[ s + 10 ] = (byte)( r >> ( s * 8 ) );

                    Buffer.BlockCopy( voxelData, r * blockSize, outData, 12, partLength );
                    Communication.SendDataMessage( steamId, 5002, outData );
                }
            }
            catch ( Exception ex )
            {
                Essentials.Log.Error( "{0}", ex );
            }
        }
开发者ID:88tom,项目名称:EssentialsPlugin,代码行数:59,代码来源:VoxelManagement.cs

示例6: SetCameraController

        public void SetCameraController(MyCameraControllerEnum cameraControllerEnum, IMyEntity cameraEntity = null, Vector3D? position = null)
        {
            //bool wasUserControlled = MySession.Static.CameraController != null ? MySession.Static.CameraController.AllowObjectControl() : false;

            // When spectator is not initialized, initialize it
            if (cameraEntity != null && Spectator.Position == Vector3.Zero)
            {
                var cam = (IMyCameraController)cameraEntity;
                Spectator.Position = cameraEntity.GetPosition() + cameraEntity.WorldMatrix.Forward * 4 + cameraEntity.WorldMatrix.Up * 2;
                Spectator.Target = cameraEntity.GetPosition();
            }

            switch (cameraControllerEnum)
            {
                case MyCameraControllerEnum.Entity:
                    Debug.Assert(cameraEntity != null);
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: Entity");
                    Static.CameraController = (IMyCameraController)cameraEntity;
                    Static.CameraController.IsInFirstPersonView = true;
                    break;
                case MyCameraControllerEnum.Spectator:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: Spectator");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.UserControlled;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.SpectatorFixed:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: SpectatorFixed");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.None;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.SpectatorDelta:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: SpectatorDelta");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.ConstantDelta;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.ThirdPersonSpectator:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: ThirdPersonSpectator");

                    if (cameraEntity != null)
                        Static.CameraController = (IMyCameraController)cameraEntity;

                    Static.CameraController.IsInFirstPersonView = false;
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }

            //if (wasUserControlled && !MySession.Static.CameraController.AllowObjectControl())
            //{
            //    if (ControlledObject != null)
            //        ControlledObject.MoveAndRotateStopped();
            //}
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:69,代码来源:MySession.cs

示例7: FindEntityFreePosition

        private static bool FindEntityFreePosition(ref Vector3D position, IMyEntity entity, BoundingSphereD worldVolume)
        {
            // Find empty location.

            // TODO: dynamically adjust the stepSize depending on the size of the entity been teleported.
            // it is currently too slow to find an empty spot for LargeRed sized ships in a busy location.
            var freePos = MyAPIGateway.Entities.FindFreePlace(position, (float)worldVolume.Radius, 500, 20, 1f);
            if (!freePos.HasValue)
                return false;

            // Offset will center the player character in the middle of the location.
            var offset = entity.WorldAABB.Center - entity.GetPosition();
            position = freePos.Value - offset;

            return true;
        }
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:16,代码来源:Support.cs

示例8: MoveShipByOffset

        private static bool MoveShipByOffset(IMyEntity cubeGrid, Vector3D worldOffset, bool safely, Action<Vector3D> updatedPosition, Action noSafeLocationMessage)
        {
            var grids = cubeGrid.GetAttachedGrids();
            var currentPosition = cubeGrid.GetPosition();
            Vector3D position = cubeGrid.GetPosition() + worldOffset;

            if (safely)
            {
                var worldVolume = grids[0].WorldVolume;
                foreach (var grid in grids)
                {
                    worldVolume.Include(grid.WorldVolume);
                }

                // TODO: determine good location for moving one ship to another, checking for OrientedBoundingBox.Intersects() for a tighter fit.
                if (!FindEntityFreePosition(ref position, cubeGrid, worldVolume))
                {
                    if (noSafeLocationMessage != null)
                        noSafeLocationMessage.Invoke();
                    return false;
                }
            }

            foreach (var grid in grids)
                MessageSyncEntity.Process(grid, SyncEntityType.Position, position);

            if (updatedPosition != null)
                updatedPosition.Invoke(currentPosition);

            return true;
        }
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:31,代码来源:Support.cs

示例9: MissileBelongsTo

		private bool MissileBelongsTo(IMyEntity missile)
		{
			if (m_weaponTarget.myTurret == null && !(CubeBlock as Ingame.IMyUserControllableGun).IsShooting)
			{
				myLogger.debugLog("Not mine, not shooting", "MissileBelongsTo()");
				return false;
			}
			Vector3D local = Vector3D.Transform(missile.GetPosition(), CubeBlock.WorldMatrixNormalizedInv);
			if (MissileSpawnBox.Contains(local) != ContainmentType.Contains)
			{
				myLogger.debugLog("Not in my box: " + missile + ", position: " + local, "MissileBelongsTo()");
				return false;
			}
			if (m_weaponTarget.myTurret == null)
			{
				if (Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward) > 0.01)
				{
					myLogger.debugLog("Facing the wrong way: " + missile + ", missile direction: " + missile.WorldMatrix.Forward + ", block direction: " + CubeBlock.WorldMatrix.Forward 
						+ ", RectangularDistance: " + Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward), "MissileBelongsTo()");
					return false;
				}
			}
			else
			{
				Vector3 turretDirection;
				Vector3.CreateFromAzimuthAndElevation(m_weaponTarget.myTurret.Azimuth, m_weaponTarget.myTurret.Elevation, out turretDirection);
				turretDirection = Vector3.Transform(turretDirection, CubeBlock.WorldMatrix.GetOrientation());
				if (Vector3D.RectangularDistance(turretDirection, missile.WorldMatrix.Forward) > 0.01)
				{
					myLogger.debugLog("Facing the wrong way: " + missile + ", missile direction: " + missile.WorldMatrix.Forward + ", turret direction: " + turretDirection
						+ ", RectangularDistance: " + Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward), "MissileBelongsTo()");
					return false;
				}
			}

			if (loadedAmmo == null)
			{
				myLogger.debugLog("Mine but no loaded ammo!", "MissileBelongsTo()", Logger.severity.INFO);
				return true;
			}

			if (loadedAmmo.Description == null || loadedAmmo.Description.GuidanceSeconds < 1f)
			{
				myLogger.debugLog("Mine but not a guided missile!", "MissileBelongsTo()", Logger.severity.INFO);
				return true;
			}

			//myLogger.debugLog("Opts: " + m_weaponTarget.Options, "MissileBelongsTo()");
			try
			{
				//if (clusterMain != null)
				//{
				//	if (loadedAmmo.IsCluster)
				//	{
				//		if (clusterMain.AddToCluster(missile))
				//		{
				//			myLogger.debugLog("reached max cluster, on cooldown", "MissileBelongsTo()", Logger.severity.DEBUG);
				//			StartCooldown();
				//		}
				//	}
				//	else
				//	{
				//		myLogger.alwaysLog("deleting extraneous missile: " + missile, "MissileBelongsTo()", Logger.severity.WARNING);
				//		missile.Delete();
				//	}
				//	return true;
				//}

				if (loadedAmmo.IsCluster)
				{
					if (m_cluster.Count == 0)
						FuncBlock.ApplyAction("Shoot_On");

					m_cluster.Add(missile);
					if (m_cluster.Count >= loadedAmmo.MagazineDefinition.Capacity)
					{
						myLogger.debugLog("Final missile in cluster: " + missile, "MissileBelongsTo()", Logger.severity.DEBUG);
					}
					else
					{
						myLogger.debugLog("Added to cluster: " + missile, "MissileBelongsTo()", Logger.severity.DEBUG);
						return true;
					}
				}

				LastSeen initialTarget = null;
				if (findAntenna())
				{
					if (m_weaponTarget.Options.TargetEntityId.HasValue)
						myAntenna.tryGetLastSeen(m_weaponTarget.Options.TargetEntityId.Value, out initialTarget);
					else
					{
						myLogger.debugLog("Searching for target", "MissileBelongsTo()", Logger.severity.DEBUG);
						float closestDistanceSquared = float.MaxValue;
						myAntenna.ForEachLastSeen(seen => {
							if (!seen.isRecent())
								return false;
							IMyCubeGrid grid = seen.Entity as IMyCubeGrid;
							if (grid != null && CubeBlock.canConsiderHostile(grid) && m_weaponTarget.Options.CanTargetType(grid))
							{
//.........这里部分代码省略.........
开发者ID:Sutima,项目名称:Autopilot,代码行数:101,代码来源:GuidedMissileLauncher.cs

示例10: LoadFromEntity

        public void LoadFromEntity(IMyEntity entity)
        {
            EntityId = entity.EntityId;
            Position = entity.GetPosition();
            Transparent = entity.Transparent;

            // DO the timer-taker updates later when we have time:
            //RefreshRevealability();
            //RefreshConcealability();
        }
开发者ID:HaoTNN,项目名称:GardenPerformance,代码行数:10,代码来源:ConcealableEntity.cs

示例11: ProjectileIsThreat

		private bool ProjectileIsThreat(IMyEntity projectile, TargetType tType)
		{
			if (projectile.Closed)
				return false;

			Vector3D projectilePosition = projectile.GetPosition();
			BoundingSphereD ignoreArea = new BoundingSphereD(ProjectilePosition(), Options.TargetingRange / 10f);
			if (ignoreArea.Contains(projectilePosition) == ContainmentType.Contains)
				return false;

			Vector3D weaponPosition = ProjectilePosition();
			Vector3D nextPosition = projectilePosition + projectile.GetLinearVelocity() / 60f;
			if (Vector3D.DistanceSquared(weaponPosition, nextPosition) < Vector3D.DistanceSquared(weaponPosition, projectilePosition))
			{
				myLogger.debugLog("projectile: " + projectile.getBestName() + ", is moving towards weapon. D0 = " + Vector3D.DistanceSquared(weaponPosition, nextPosition) + ", D1 = " + Vector3D.DistanceSquared(weaponPosition, projectilePosition), "ProjectileIsThreat()");
				return true;
			}
			else
			{
				myLogger.debugLog("projectile: " + projectile.getBestName() + ", is moving away from weapon. D0 = " + Vector3D.DistanceSquared(weaponPosition, nextPosition) + ", D1 = " + Vector3D.DistanceSquared(weaponPosition, projectilePosition), "ProjectileIsThreat()");
				return false;
			}
		}
开发者ID:helppass,项目名称:Autopilot,代码行数:23,代码来源:TargetingBase.cs

示例12: PlayerDrone

 public PlayerDrone(IMyEntity entity, BroadcastingTypes broadcasting)
     : base(entity, broadcasting)
 {
     SentryLocation = entity.GetPosition();
     Type = typeof(PlayerDrone);
 }
开发者ID:sanzone13,项目名称:DroneConquest,代码行数:6,代码来源:PlayerDrone.cs

示例13: MissileBelongsTo

        private bool MissileBelongsTo(IMyEntity missile)
        {
            if (!(CubeBlock as Ingame.IMyUserControllableGun).IsShooting)
            {
                myLogger.debugLog("Not mine, not shooting", "MissileBelongsTo()");
                return false;
            }
            Vector3D local = Vector3D.Transform(missile.GetPosition(), CubeBlock.WorldMatrixNormalizedInv);
            if (MissileSpawnBox.Contains(local) != ContainmentType.Contains)
            {
                myLogger.debugLog("Not in my box: " + missile + ", position: " + local, "MissileBelongsTo()");
                return false;
            }
            if (Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward) > 0.01)
            {
                myLogger.debugLog("Facing the wrong way: " + missile + ", RectangularDistance: " + Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward), "MissileBelongsTo()");
                return false;
            }

            if (loadedAmmo == null)
            {
                myLogger.debugLog("Mine but no loaded ammo!", "MissileBelongsTo()", Logger.severity.INFO);
                return true;
            }

            if (loadedAmmo.Description == null || loadedAmmo.Description.GuidanceSeconds < 1f)
            {
                myLogger.debugLog("Mine but not a guided missile!", "MissileBelongsTo()", Logger.severity.INFO);
                return true;
            }

            myLogger.debugLog("Opts: " + myFixed.Options, "MissileBelongsTo()");
            try
            {
                if (clusterMain != null)
                {
                    if (loadedAmmo.IsCluster)
                    {
                        if (clusterMain.AddToCluster(missile))
                        {
                            myLogger.debugLog("reached max cluster, on cooldown", "MissileBelongsTo()", Logger.severity.DEBUG);
                            StartCooldown();
                        }
                    }
                    else
                    {
                        myLogger.alwaysLog("deleting extraneous missile: " + missile, "MissileBelongsTo()", Logger.severity.WARNING);
                        missile.Delete();
                    }
                    return true;
                }

                LastSeen initialTarget = null;
                if (findAntenna())
                {
                    if (myFixed.Options.TargetEntityId.HasValue)
                        myAntenna.tryGetLastSeen(myFixed.Options.TargetEntityId.Value, out initialTarget);
                    else
                    {
                        myLogger.debugLog("Searching for target", "MissileBelongsTo()", Logger.severity.DEBUG);
                        float closestDistanceSquared = float.MaxValue;
                        myAntenna.ForEachLastSeen(seen => {
                            if (!seen.isRecent())
                                return false;
                            IMyCubeGrid grid = seen.Entity as IMyCubeGrid;
                            if (grid != null && CubeBlock.canConsiderHostile(grid) && myFixed.Options.CanTargetType(grid))
                            {
                                float distSquared = Vector3.DistanceSquared(CubeBlock.GetPosition(), grid.GetCentre());
                                if (distSquared < closestDistanceSquared)
                                {
                                    closestDistanceSquared = distSquared;
                                    initialTarget = seen;
                                }
                            }
                            return false;
                        });
                    }
                }

                myLogger.debugLog("creating new guided missile", "MissileBelongsTo()");
                GuidedMissile gm = new GuidedMissile(missile as MyAmmoBase, CubeBlock, myFixed.Options.Clone(), loadedAmmo, initialTarget);
                if (loadedAmmo.IsCluster)
                {
                    myLogger.debugLog("missile is a cluster missile", "MissileBelongsTo()");
                    clusterMain = gm;
                    missile.OnClose += ClusterMain_OnClose;
                    var builder = CubeBlock.GetObjectBuilder_Safe() as MyObjectBuilder_UserControllableGun ;
                    restoreShootingToggle = builder.IsShootingFromTerminal;
                    FuncBlock.ApplyAction("Shoot_On");
                }
            }
            catch (Exception ex)
            {
                myLogger.alwaysLog("failed to create GuidedMissile", "MissileBelongsTo()", Logger.severity.ERROR);
                myLogger.alwaysLog("Exception: " + ex, "MissileBelongsTo()",  Logger.severity.ERROR);
            }

            return true;
        }
开发者ID:deimosx6,项目名称:Autopilot,代码行数:99,代码来源:GuidedMissileLauncher.cs

示例14: Update

 public void Update(IMyEntity missile)
 {
     LineSegment line = new LineSegment(entity.GetPosition(), entity.GetPosition() + entity.WorldMatrix.Forward * 1e6f);
     position = line.ClosestPoint(missile.GetPosition()) + missile.Physics.LinearVelocity;
     linearVelocity = entity.WorldMatrix.Forward * missile.Physics.LinearVelocity.Length();
 }
开发者ID:Souper07,项目名称:Autopilot,代码行数:6,代码来源:Target.cs

示例15: MissileBelongsTo

        private bool MissileBelongsTo(IMyEntity missile)
        {
            if (m_weaponTarget.myTurret == null && !(CubeBlock as Ingame.IMyUserControllableGun).IsShooting)
            {
                //myLogger.debugLog("Not mine, not shooting", "MissileBelongsTo()");
                return false;
            }
            Vector3D local = Vector3D.Transform(missile.GetPosition(), CubeBlock.WorldMatrixNormalizedInv);
            if (MissileSpawnBox.Contains(local) != ContainmentType.Contains)
            {
                //myLogger.debugLog("Not in my box: " + missile + ", position: " + local, "MissileBelongsTo()");
                return false;
            }
            if (m_weaponTarget.myTurret == null)
            {
                if (Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward) > 0.01)
                {
                    //myLogger.debugLog("Facing the wrong way: " + missile + ", missile direction: " + missile.WorldMatrix.Forward + ", block direction: " + CubeBlock.WorldMatrix.Forward
                    //	+ ", RectangularDistance: " + Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward), "MissileBelongsTo()");
                    return false;
                }
            }
            else
            {
                Vector3 turretDirection;
                Vector3.CreateFromAzimuthAndElevation(m_weaponTarget.myTurret.Azimuth, m_weaponTarget.myTurret.Elevation, out turretDirection);
                turretDirection = Vector3.Transform(turretDirection, CubeBlock.WorldMatrix.GetOrientation());
                if (Vector3D.RectangularDistance(turretDirection, missile.WorldMatrix.Forward) > 0.01)
                {
                    //myLogger.debugLog("Facing the wrong way: " + missile + ", missile direction: " + missile.WorldMatrix.Forward + ", turret direction: " + turretDirection
                    //	+ ", RectangularDistance: " + Vector3D.RectangularDistance(CubeBlock.WorldMatrix.Forward, missile.WorldMatrix.Forward), "MissileBelongsTo()");
                    return false;
                }
            }

            if (loadedAmmo == null)
            {
                //myLogger.debugLog("Mine but no loaded ammo!", "MissileBelongsTo()", Logger.severity.INFO);
                return true;
            }

            if (loadedAmmo.Description == null || loadedAmmo.Description.GuidanceSeconds < 1f)
            {
                //myLogger.debugLog("Mine but not a guided missile!", "MissileBelongsTo()", Logger.severity.INFO);
                return true;
            }

            //myLogger.debugLog("Opts: " + m_weaponTarget.Options, "MissileBelongsTo()");
            try
            {
                if (loadedAmmo.IsCluster)
                {
                    if (m_cluster.Count == 0)
                        FuncBlock.ApplyAction("Shoot_On");

                    m_cluster.Add(missile);
                    if (m_cluster.Count >= loadedAmmo.MagazineDefinition.Capacity)
                    {
                        //myLogger.debugLog("Final missile in cluster: " + missile, "MissileBelongsTo()", Logger.severity.DEBUG);
                    }
                    else
                    {
                        //myLogger.debugLog("Added to cluster: " + missile, "MissileBelongsTo()", Logger.severity.DEBUG);
                        return true;
                    }
                }

                //myLogger.debugLog("creating new guided missile", "MissileBelongsTo()");
                Target initialTarget;
                if (m_cluster.Count != 0)
                {
                    new GuidedMissile(new Cluster(m_cluster, CubeBlock), this, out initialTarget);
                    StartCooldown();
                    m_cluster.Clear();
                }
                else
                    new GuidedMissile(missile, this, out initialTarget);

                // display target in custom info
                if (m_weaponTarget.CurrentControl == WeaponTargeting.Control.Off)
                    m_weaponTarget.CurrentTarget = initialTarget;
            }
            catch (Exception ex)
            {
                myLogger.alwaysLog("failed to create GuidedMissile", Logger.severity.ERROR);
                myLogger.alwaysLog("Exception: " + ex, Logger.severity.ERROR);
            }

            return true;
        }
开发者ID:Souper07,项目名称:Autopilot,代码行数:90,代码来源:GuidedMissileLauncher.cs


注:本文中的IMyEntity.GetPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。