internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            MyEntity    enemy = bot.GetEnemy();
            MyDrillBase drill = bot.Weapons.GetMountedDrill();

            if (enemy != null && drill != null)
            {
                Vector3 botToEnemy = enemy.GetPosition() - bot.GetPosition();
                float   distance   = botToEnemy.Length();
                if (distance <= (bot.DrillDistance + bot.WorldVolume.Radius + enemy.WorldVolume.Radius))
                {
                    if (drill.CurrentState == MyDrillStateEnum.InsideShip)
                    {
                        drill.Eject();
                    }
                    else
                    {
                        drill.Shot(null);
                    }
                }
                else
                {
                    // pull drill back
                    if (drill.CurrentState == MyDrillStateEnum.Activated)
                    {
                        drill.Eject();
                    }
                }

                bot.Move(enemy.GetPosition(), enemy.GetPosition(), enemy.WorldMatrix.Up, distance < 100);
            }
        }
        void AllowBotManeuvers()
        {
            MyEntity transporterShip = MyScriptWrapper.TryGetEntity((uint)EntityID.TransporterShip);

            if (transporterShip != null)
            {
                for (int i = m_attackerWaitingForPass.Count - 1; i >= 0; i--)
                {
                    var bot = m_attackerWaitingForPass[i];

                    var direction = transporterDestination - transporterShip.GetPosition();
                    if (direction.LengthSquared() > 0)
                    {
                        direction.Normalize();
                        var d = Vector3.Dot(transporterShip.GetPosition() - m_towers[0].GetPosition(), direction);
                        var transporterToBot = bot.GetPosition() - transporterShip.GetPosition();

                        if (Vector3.Dot(direction, transporterToBot) < 180)
                        {
                            bot.SpeedModifier = 1;
                            m_attackerWaitingForPass.RemoveAt(i);
                        }
                    }
                }
            }
        }
示例#3
0
        public void Render()
        {
            switch (m_mode)
            {
            case Mode.BackCamera:
                ViewMatrix = MySession.PlayerShip.GetViewMatrix() * Matrix.CreateRotationY(MathHelper.Pi);
                break;

            case Mode.PlayerShip:
                ViewMatrix = MySession.PlayerShip.GetViewMatrix();
                break;

            case Mode.Entity:
                ViewMatrix = Matrix.CreateLookAt(
                    m_cameraSource.GetPosition(),
                    m_cameraSource.GetPosition() +
                    m_cameraSource.WorldMatrix.Forward,
                    m_cameraSource.WorldMatrix.Up);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SecondaryCameraRenderer.ViewMatrix = ViewMatrix;
            this.IsCurrentlyRendering          = true;
            SecondaryCameraRenderer.Render();
            this.IsCurrentlyRendering = false;
            ProjectionMatrix          = SecondaryCameraRenderer.ProjectionMatrix;

            BoundingFrustum.Matrix = ViewMatrix * ProjectionMatrix;
        }
示例#4
0
        bool MoveMotherShipForwardDest(MyEntity entity, Vector3 velocity, Vector3 destination)
        {
            if (Vector3.DistanceSquared(destination, entity.GetPosition()) > 10 * 10)
            {
                MyScriptWrapper.Move(entity, entity.GetPosition() + velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS);

                return(false);
            }
            return(true);
        }
        MyEntity ChooseClosestPlayer(MyEntity bot)
        {
            if (MyMultiplayerGameplay.IsHosting)
            {
                var closestEntity = MySession.PlayerShip;
                var distSquared   = Vector3.DistanceSquared(bot.GetPosition(), MySession.PlayerShip.GetPosition());

                foreach (var player in MyMultiplayerGameplay.Peers.Players)
                {
                    if (player.Ship != null && !player.Ship.IsDead() && !player.Ship.IsPilotDead())
                    {
                        var newDistSquared = Vector3.DistanceSquared(player.Ship.GetPosition(), closestEntity.GetPosition());
                        if (newDistSquared < distSquared)
                        {
                            distSquared   = newDistSquared;
                            closestEntity = player.Ship;
                        }
                    }
                }

                return(closestEntity);
            }
            else
            {
                return(MySession.PlayerShip);
            }
        }
示例#6
0
        /// <summary>
        /// If the missile is near the target and not getting closer, detonate.
        /// </summary>
        private void ProximityDetonate()
        {
            if (!MyAPIGateway.Multiplayer.IsServer || myDescr.DetonateRange == 0f)
            {
                return;
            }

            Target cached = CurrentTarget;

            if (!cached.FiringDirection.HasValue)
            {
                return;
            }

            Vector3D myPosition     = MyEntity.GetPosition();
            Vector3D targetPosition = cached.GetPosition();

            double distSq; Vector3D.DistanceSquared(ref myPosition, ref targetPosition, out distSq);

            if (distSq < myDescr.DetonateRange * myDescr.DetonateRange && Vector3.Normalize(MyEntity.GetLinearVelocity()).Dot(cached.FiringDirection.Value) < Static.Cos_Angle_Detonate)
            {
                Log.DebugLog("proximity detonation, target: " + cached.Entity + ", target position: " + cached.GetPosition() + ", real position: " + cached.Entity.GetPosition() + ", type: " + cached.GetType().Name, Logger.severity.INFO);
                Explode();
                m_stage = Stage.Terminated;
            }
        }
示例#7
0
        /// <summary>
        /// Destroys missiles in blast radius.
        /// </summary>
        private void DestroyAllNearbyMissiles()
        {
            if (myCluster != null || m_destroyedNearbyMissiles)
            {
                return;
            }
            m_destroyedNearbyMissiles = true;

            BoundingSphereD explosion = new BoundingSphereD(MyEntity.GetPosition(), myAmmo.MissileDefinition.MissileExplosionRadius);

            Log.DebugLog("Explosion: " + explosion);
            List <MyEntity> entitiesInExplosion = new List <MyEntity>();

            MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref explosion, entitiesInExplosion, MyEntityQueryType.Dynamic);

            foreach (MyEntity entity in entitiesInExplosion)
            {
                if (!entity.Closed && entity.IsMissile() && entity != MyEntity)
                {
                    Log.DebugLog("Explode: " + entity + ", position: " + entity.PositionComp.GetPosition());
                    ((MyAmmoBase)entity).Explode();
                }
            }

            explosion.Radius *= 10f;
            entitiesInExplosion.Clear();
            MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref explosion, entitiesInExplosion, MyEntityQueryType.Dynamic);
            foreach (MyEntity entity in entitiesInExplosion)
            {
                if (!entity.Closed && entity.IsMissile() && entity != MyEntity)
                {
                    Log.DebugLog("nearby: " + entity + ", position: " + entity.PositionComp.GetPosition());
                }
            }
        }
示例#8
0
        private static bool IsTargetVisible(MySmallShip smallShip, MyEntity otherEntity)
        {
            MyLine line = new MyLine(smallShip.WorldVolume.Center, otherEntity.GetPosition(), true);
            MyIntersectionResultLineTriangleEx?result = MyEntities.GetIntersectionWithLine(ref line, smallShip, null, ignoreChilds: true);

            return(result != null && result.Value.Entity.GetBaseEntity() == otherEntity);
        }
示例#9
0
        private void StartGravity()
        {
            Vector3D position = MyEntity.GetPosition();

            foreach (MyPlanet planet in Globals.AllPlanets())
            {
                if (planet.IsPositionInGravityWell(position))
                {
                    Vector3D targetPosition = CurrentTarget.GetPosition();
                    if (!planet.IsPositionInGravityWell(targetPosition))
                    {
                        Log.DebugLog("Target is not in gravity well, target position: " + targetPosition + ", planet: " + planet.getBestName(), Logger.severity.WARNING);
                        return;
                    }
                    Vector3 gravAtTarget = planet.GetWorldGravityNormalized(ref targetPosition);
                    m_gravData = new GravityData(planet, gravAtTarget);
                    break;
                }
            }

            if (m_gravData != null)
            {
                UpdateGravity();
            }
        }
示例#10
0
 private void CallOnEntityPositionChange(MyEntity entity)
 {
     if (OnEntityPositionChange != null)
     {
         OnEntityPositionChange(this, entity, entity.GetPosition());
     }
 }
示例#11
0
        /// <summary>
        /// Check if the missile does not collide too close to ship
        /// after shooting and correct its starting position if it does.
        /// </summary>
        private Vector3 CorrectPosition(Vector3 position, Vector3 direction, MyEntity viewerEntity)
        {
            //var predictedTrajectory = new MyLine(
            //    position - (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    position + (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    true);
            //var intersection = MyEntities.GetIntersectionWithLine(ref predictedTrajectory, this, viewerEntity);


            // This is fix for missles hitting voxels when you are near them (missles do not use per triangle collision as optimalization)
            float radius = MyModels.GetModel(MyModelsEnum.Missile).BoundingSphere.Radius;

            BoundingSphere boundingSphere = viewerEntity.WorldVolume;

            boundingSphere.Center += viewerEntity.WorldMatrix.Up * 1;

            var intersection = MyEntities.GetIntersectionWithSphere(ref boundingSphere, this, viewerEntity);

            if (intersection != null && !(intersection is MyMissile))
            {
                position = viewerEntity.GetPosition() + 2 * Vector3.One;
            }

            return(position);
        }
示例#12
0
        private void mineDetector_OnEntityPositionChange(MyEntityDetector sender, MyEntity entity, Vector3 newposition)
        {
            if (sender.Closed)
            {
                return;
            }

            if (entity == MySession.PlayerShip)
            {
                if (m_beepCue == null || !m_beepCue.Value.IsPlaying)
                {
                    m_beepCue = MyAudio.AddCue2D(MySoundCuesEnum.SfxHudAlarmDamageA);
                }

                float distance = (entity.GetPosition() - sender.GetPosition()).Length();

                if (distance < m_mineStartRadius)
                {
                    uint mineId = 0;
                    for (int i = 0; i < m_mines.GetLength(0); i++)
                    {
                        if (m_mines[i, 1] == sender.Parent.EntityId.Value.NumericValue)
                        {
                            mineId = m_mines[i, 0];
                        }
                    }
                    ExplodeMine(mineId);
                    sender.Off();
                    sender.Parent.MarkForClose();
                }
            }
        }
示例#13
0
 public void Update()
 {
     if (m_madelynEntity != null)
     {
         SectorPosition   = MyGuiScreenGamePlay.Static.GetSectorIdentifier().Position;
         PositionInSector = m_madelynEntity.GetPosition();
     }
 }
示例#14
0
        /// <summary>
        /// Chceck if ship can see target
        /// </summary>
        /// <param name="position">Target position</param>
        /// <param name="target">Target entity.</param>
        /// <returns>True, if bot can see position.</returns>
        public static MyEntity CanSee(MyEntity source, Vector3 position, MyEntity ignoreEntity)
        {
            MyIntersectionResultLineTriangleEx?result = null;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MySmallShip CanSee");
            //There is 100 multiplier because Epsilon can get lost during transformation inside GetAllIntersectionWithLine
            //and normalization assert then appears
            if ((source.GetPosition() - position).Length() > MyMwcMathConstants.EPSILON * 100.0f)
            {
                var line = new MyLine(source.GetPosition(), position, true);
                result = MyEntities.GetIntersectionWithLine(ref line, source, ignoreEntity, ignoreChilds: true);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return(result.HasValue ? result.Value.Entity : null);
        }
        private void DefendMadelyn2_Update(MyMissionBase sender)
        {
            if (m_madelynMoving2)
            {
                var speed = Math.Min(100, 15 + (100 - 15) * (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_madelynMovingStarted2) / 20000.0f); // it takes 20s for Madelyn to reach max speed after Marcus crashes

                Vector3 velocity = speed * m_madelyn.WorldMatrix.Forward;                                                                        // Speed in direction
                MyScriptWrapper.Move(m_madelyn, m_madelyn.GetPosition() + velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS);
            }
            else if (m_madelynMoving)
            {
                var speed = Math.Min(15, 15 * (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_madelynMovingStarted) / 10000.0f); // it takes 10s for Madelyn to reach max speed of 15 (jammed)

                Vector3 velocity = speed * m_madelyn.WorldMatrix.Forward;                                                         // Speed in direction
                MyScriptWrapper.Move(m_madelyn, m_madelyn.GetPosition() + velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS);
            }
        }
示例#16
0
        private bool IsInMyHemisphere(MyEntity targetEntity)
        {
            var direction = targetEntity.GetPosition() - GetPosition();

            direction.Normalize();
            var dot = Vector3.Dot(direction, WorldMatrix.Forward);

            return(dot > 0.5f);
        }
        public override void Update()
        {
            base.Update();

            if ((MySession.PlayerShip.GetPosition() - m_target.GetPosition()).Length() < WarningDistance)
            {
                m_notification.Appear();
                MyScriptWrapper.AddNotification(m_notification);
            }
            else
            {
                m_notification.Disappear();
            }

            if ((MySession.PlayerShip.GetPosition() - m_target.GetPosition()).Length() < FailDistance)
            {
                Fail(MyTextsWrapperEnum.Fail_LostTarget);
            }
        }
        /// <summary>
        /// Returns if bot can see target. If bot's fov is enabled and target is smallship which has radar jammer, then bot can see only targets in front of him
        /// </summary>
        /// <param name="target">Target</param>
        private bool CanSeeTarget(MySmallShipBot me, MyEntity target)
        {
            bool canSeeTarget = true;

            if (MyFakes.ENABLE_BOTS_FOV_WHEN_RADAR_JAMMER)
            {
                MySmallShip smallShipTarget = target as MySmallShip;
                if (smallShipTarget != null && !smallShipTarget.IsHologram && smallShipTarget.HasRadarJammerActive())
                {
                    float distanceSqr    = (me.GetPosition() - target.GetPosition()).LengthSquared();
                    float rangeOfViewSqr = smallShipTarget.IsHiddenFromBots() ? MyAIConstants.BOT_FOV_RANGE_HIDDEN : MyAIConstants.BOT_FOV_RANGE;
                    float targetRange    = Vector3.Dot(m_botWorldMatrix.Forward, target.GetPosition() - me.GetPosition());

                    canSeeTarget =
                        targetRange <= rangeOfViewSqr &&
                        Vector3.Dot(m_botWorldMatrix.Forward, Vector3.Normalize(target.GetPosition() - m_position)) >= MyAIConstants.BOT_FOV_COS;
                }
            }
            return(canSeeTarget);
        }
示例#19
0
        public override void Load(MyMissionBase sender)
        {
            base.Load(sender);
            m_ship       = m_shipId.HasValue ? MyScriptWrapper.GetEntity(m_shipId.Value) : MyScriptWrapper.GetEntity(m_shipName);
            m_trajectory = new MyLine(m_ship.GetPosition(), MyScriptWrapper.GetEntity(m_targetId).GetPosition());

            if (m_isShip)
            {
                MyScriptWrapper.PrepareMotherShipForMove(m_ship);
            }
            m_shipMoving = true;
        }
示例#20
0
        /// <summary>
        /// Updates stored gravity values.
        /// </summary>
        private void UpdateGravity()
        {
            Vector3D position = MyEntity.GetPosition();

            m_gravData.Normal = m_gravData.Planet.GetWorldGravityNormalized(ref position);
            if (m_stage == Stage.Boost)
            {
                float grav = m_gravData.Planet.GetGravityMultiplier(position) * 9.81f;
                m_gravData.AccelPerUpdate = m_gravData.Normal * grav * Globals.UpdateDuration;
            }

            //Log.DebugLog("updated gravity, norm: " + m_gravData.Normal, "UpdateGravity()");
        }
        private void SpeakCaptainOnOnMissionSuccess(MyMissionBase sender)
        {
            MyScriptWrapper.AddNotification(MyScriptWrapper.CreateNotification(MyTextsWrapperEnum.NewMissionRecieved, MyHudConstants.FRIEND_FONT, 10000));
            var position = m_madelynDummy.GetPosition();
            var rotation = m_madelynDummy.GetOrientation();

            m_madelyn.MoveAndRotate(position, rotation);

            //m_madelyn.SetWorldMatrix(m_madelynDummy.GetWorldMatrixForDraw());
            MyScriptWrapper.UnhideEntity(MyScriptWrapper.GetEntity((uint)EntityID.PrefabContainer));
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.Scanner1), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.Scanner2), false);
        }
示例#22
0
        public static void ApplyProjectileForce(MyEntity physObject, Vector3 intersectionPosition, Vector3 normalizedDirection, bool isPlayerShip)
        {
            float impulseMultiplier = isPlayerShip ? MyMinerShipConstants.MINER_SHIP_PLAYER_PROJECTILE_HIT_MULTIPLIER : (MyMinerShipConstants.MINER_SHIP_PROJECTILE_HIT_MULTIPLIER);

            // To make it look good, bots gets impulse which rotates them
            if (physObject is MySmallShipBot)
            {
                // These are constants to make proper bot behaviour to physics
                const float torqueMult  = 4;
                const float impulseMult = 20;

                impulseMultiplier *= impulseMult;
                var centerToIntersection = intersectionPosition - physObject.GetPosition();
                intersectionPosition = physObject.GetPosition() + centerToIntersection * torqueMult;
            }

            //  If we hit model that belongs to physic object, apply some force to it (so it's thrown in the direction of shoting)
            physObject.Physics.AddForce(
                MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE,
                normalizedDirection * MyProjectilesConstants.HIT_STRENGTH_IMPULSE * impulseMultiplier,
                intersectionPosition, Vector3.Zero);
        }
        private void UpdateVisibility(MySmallShipBot bot)
        {
            if (m_visibilityCheckTimer <= 0)
            {
                if (bot.GetPosition() == m_target.GetPosition())
                {
                    m_targetVisible = true;
                }
                else
                {
                    MyLine line   = new MyLine(bot.GetPosition(), m_target.GetPosition(), true);
                    var    result = MyEntities.GetIntersectionWithLine(ref line, bot, m_target, true, ignoreChilds: true);
                    m_targetVisible = !result.HasValue;
                }

                m_visibilityCheckTimer = 0.5f;
            }
            else
            {
                m_visibilityCheckTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            }
        }
示例#24
0
        /// <summary>
        /// Check if the missile does not collide too close to ship
        /// after shooting and correct its starting position if it does.
        /// </summary>
        private Vector3 CorrectPosition(Vector3 position, Vector3 direction, MyEntity viewerEntity)
        {
            var predictedTrajectory = new MyLine(
                position - MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION * direction,
                position + MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION * direction,
                false);
            var intersection = MyEntities.GetIntersectionWithLine(ref predictedTrajectory, this, viewerEntity);

            if (intersection != null)
            {
                position = viewerEntity.GetPosition();
            }
            return(position);
        }
        bool MoveEntityForward(MyEntity entity, float speed, Vector3 destination, bool updateVelocity)
        {
            float SlowDownRadius = 200;
            float StopRadius     = 10;

            // speed *= 10;

            Vector3 velocity = speed * entity.WorldMatrix.Forward; // Speed in direction

            if (Vector3.DistanceSquared(destination, entity.GetPosition()) < SlowDownRadius * SlowDownRadius)
            {
                velocity = entity.Physics.LinearVelocity * 0.995f;
            }

            entity.Physics.Clear();

            if (Vector3.DistanceSquared(destination, entity.GetPosition()) > StopRadius * StopRadius)
            {
                Vector3 newPos = entity.GetPosition() + velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                //entity.SetPosition(newPos); // recalculate position
                if (updateVelocity)
                {
                    MyScriptWrapper.MoveWithVelocity(entity, newPos, velocity);
                    // When at target set velocity to zero
                    if (Vector3.DistanceSquared(destination, entity.GetPosition()) > StopRadius * StopRadius)
                    {
                        MyScriptWrapper.MoveWithVelocity(entity, entity.GetPosition(), Vector3.Zero);
                    }
                }
                else
                {
                    MyScriptWrapper.Move(entity, newPos);
                }
                return(false);
            }
            return(true);
        }
示例#26
0
        protected void AddEditPositionControls()
        {
            if (HasEntity())
            {
                Controls.Add(new MyGuiControlLabel(this, GetControlsOriginLeftFromScreenSize() + 0 * CONTROLS_DELTA, null, MyTextsWrapperEnum.Position, MyGuiConstants.LABEL_TEXT_COLOR,
                                                   MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));

                //TODO add support for textbox with numbers with floating point
                Controls.Add(new MyGuiControlLabel(this, GetControlsOriginLeftFromScreenSize() + 1 * CONTROLS_DELTA, null, MyTextsWrapperEnum.X, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
                m_positionXTextBox = new MyGuiControlTextbox(this, (new Vector2(0.05f, 0) + GetControlsOriginLeftFromScreenSize()) + 1 * CONTROLS_DELTA + new Vector2(MyGuiConstants.TEXTBOX_MEDIUM_SIZE.X / 2.0f, 0), MyGuiControlPreDefinedSize.MEDIUM, "0", MyMwcValidationConstants.POSITION_X_MAX, MyGuiConstants.TEXTBOX_BACKGROUND_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.DIGITS_ONLY);
                Controls.Add(m_positionXTextBox);
                m_positionXTextBox.Text = Convert.ToInt32(m_entity.GetPosition().X).ToString();

                Controls.Add(new MyGuiControlLabel(this, GetControlsOriginLeftFromScreenSize() + 2 * CONTROLS_DELTA, null, MyTextsWrapperEnum.Y, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
                m_positionYTextBox = new MyGuiControlTextbox(this, (new Vector2(0.05f, 0) + GetControlsOriginLeftFromScreenSize()) + 2 * CONTROLS_DELTA + new Vector2(MyGuiConstants.TEXTBOX_MEDIUM_SIZE.X / 2.0f, 0), MyGuiControlPreDefinedSize.MEDIUM, "0", MyMwcValidationConstants.POSITION_X_MAX, MyGuiConstants.TEXTBOX_BACKGROUND_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.DIGITS_ONLY);
                Controls.Add(m_positionYTextBox);
                m_positionYTextBox.Text = Convert.ToInt32(m_entity.GetPosition().Y).ToString();

                Controls.Add(new MyGuiControlLabel(this, GetControlsOriginLeftFromScreenSize() + 3 * CONTROLS_DELTA, null, MyTextsWrapperEnum.Z, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
                m_positionZTextBox = new MyGuiControlTextbox(this, (new Vector2(0.05f, 0) + GetControlsOriginLeftFromScreenSize()) + 3 * CONTROLS_DELTA + new Vector2(MyGuiConstants.TEXTBOX_MEDIUM_SIZE.X / 2.0f, 0), MyGuiControlPreDefinedSize.MEDIUM, "0", MyMwcValidationConstants.POSITION_X_MAX, MyGuiConstants.TEXTBOX_BACKGROUND_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.DIGITS_ONLY);
                Controls.Add(m_positionZTextBox);
                m_positionZTextBox.Text = Convert.ToInt32(m_entity.GetPosition().Z).ToString();
            }
        }
示例#27
0
        public void Notify(MyLine line, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            lineResults.Clear();
            m_dangerZoneStructure.OverlapAllLineSegment<MyDangerZoneElement>(ref line, lineResults);

            foreach (var resultItem in lineResults)
            {
                if (source == null || (resultItem.Element.Bot != source && MyFactions.GetFactionsRelation(resultItem.Element.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    resultItem.Element.Bot.AddCuriousLocation(source != null ? source.GetPosition() : line.From, source);
                }
            }
        }
示例#28
0
        public void Notify(BoundingBox bbox, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            results.Clear();
            m_dangerZoneStructure.OverlapAllBoundingBox <MyDangerZoneElement>(ref bbox, results);

            foreach (var dangerZone in results)
            {
                if (source == null || (dangerZone.Bot != source && MyFactions.GetFactionsRelation(dangerZone.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    dangerZone.Bot.AddCuriousLocation(source != null ? source.GetPosition() : bbox.GetCenter(), source);
                }
            }
        }
示例#29
0
        public void Notify(MyLine line, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            lineResults.Clear();
            m_dangerZoneStructure.OverlapAllLineSegment <MyDangerZoneElement>(ref line, lineResults);

            foreach (var resultItem in lineResults)
            {
                if (source == null || (resultItem.Element.Bot != source && MyFactions.GetFactionsRelation(resultItem.Element.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    resultItem.Element.Bot.AddCuriousLocation(source != null ? source.GetPosition() : line.From, source);
                }
            }
        }
示例#30
0
        public bool IntersectsWithControlledEntity()
        {
            Matrix   worldMatrix      = WorldMatrix;
            MyEntity controlledEntity = MyGuiScreenGamePlay.Static.ControlledEntity;

            if (Vector3.DistanceSquared(worldMatrix.Translation, controlledEntity.GetPosition()) > m_bbForSoundDetection.Size().LengthSquared())
            {
                return(false);
            }
            Matrix         invMatrix           = Matrix.Invert(WorldMatrix);
            Vector3        localPlayerBSCenter = Vector3.Transform(MyGuiScreenGamePlay.Static.ControlledEntity.WorldVolume.Center, invMatrix);
            BoundingSphere localPlayerBS       = new BoundingSphere(localPlayerBSCenter, MyGuiScreenGamePlay.Static.ControlledEntity.WorldVolume.Radius);

            return(m_bbForSoundDetection.Intersects(localPlayerBS));
        }
示例#31
0
        // Calculates squared distance from entity to closest player or player friend
        public float DistanceToPlayersSquared(MyEntity entity)
        {
            float dist = Vector3.DistanceSquared(MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.ControlledEntity.GetPosition(), entity.GetPosition());

            for (int i = 0; i < PlayerFriends.Count; i++)
            {
                var   friend  = PlayerFriends[i];
                float newdist = Vector3.DistanceSquared(friend.GetPosition(), entity.GetPosition());
                if (newdist < dist)
                {
                    dist = newdist;
                }
            }

            return(dist);
        }
示例#32
0
        /// <summary>
        /// Returns if bot can see target. If bot's fov is enabled and target is smallship which has radar jammer, then bot can see only targets in front of him
        /// </summary>
        /// <param name="target">Target</param>
        private bool CanSeeTarget(MySmallShipBot me, MyEntity target) 
        {
            bool canSeeTarget = true;
            if (MyFakes.ENABLE_BOTS_FOV_WHEN_RADAR_JAMMER)
            {
                MySmallShip smallShipTarget = target as MySmallShip;
                if (smallShipTarget != null && !smallShipTarget.IsHologram && smallShipTarget.HasRadarJammerActive()) 
                {
                    float distanceSqr = (me.GetPosition() - target.GetPosition()).LengthSquared();
                    float rangeOfViewSqr = smallShipTarget.IsHiddenFromBots() ? MyAIConstants.BOT_FOV_RANGE_HIDDEN : MyAIConstants.BOT_FOV_RANGE;
                    float targetRange = Vector3.Dot(m_botWorldMatrix.Forward, target.GetPosition() - me.GetPosition());

                    canSeeTarget =
                        targetRange <= rangeOfViewSqr &&
                        Vector3.Dot(m_botWorldMatrix.Forward, Vector3.Normalize(target.GetPosition() - m_position)) >= MyAIConstants.BOT_FOV_COS;
                }                
            }
            return canSeeTarget;
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);
            
            m_isInvalid = false;
            m_target = SourceDesire.GetEnemy();
            if (m_target != null)
            {
                Debug.Assert(m_target != bot);
            }
            findSmallship = new MyFindSmallshipHelper();

            m_visibilityCheckTimer = 0;       // force visibility test
            m_closingTimer = 0;
            m_forcedClosingTimer = 0;
            m_hologramTargetTimer = 0;

            SwitchToClosing();
            
            PlanNextMissile();

            m_timeToAlarmCheck = 2;
            
            m_playerAttackDecisionTimer = 0;

            MyScriptWrapper.OnEntityAttackedByBot(bot, m_target);

            m_canShootWithAutocanon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Primary);
            m_canShootWithShotGun = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Secondary);
            m_canShootWithSniper = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Third);
            m_canShootMissile = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fourth);
            m_canShootCannon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fifth);

            m_canShootFlash = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront) && MyFakes.BOT_USE_FLASH_BOMBS;
            m_canShootSmoke = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront) && MyFakes.BOT_USE_SMOKE_BOMBS;
            m_canShootHologram = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.HologramFront) && MyFakes.BOT_USE_HOLOGRAMS;

            m_weaponChangeTimer = 0;
            m_currentWeapon = SelectWeapon((bot.GetPosition() - m_target.GetPosition()).Length());

            m_smokeBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_flashBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
            m_hologramTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f);
        }
示例#34
0
        public void Notify(BoundingBox bbox, MyEntity source)
        {
            System.Diagnostics.Debug.Assert(source == null || !source.Closed);

            results.Clear();
            m_dangerZoneStructure.OverlapAllBoundingBox<MyDangerZoneElement>(ref bbox, results);

            foreach (var dangerZone in results)
            {
                if (source == null || (dangerZone.Bot != source && MyFactions.GetFactionsRelation(dangerZone.Bot, source) == MyFactionRelationEnum.Enemy))
                {
                    dangerZone.Bot.AddCuriousLocation(source != null ? source.GetPosition() : bbox.GetCenter(), source);
                }
            }
        }
示例#35
0
 /// <summary>
 /// Check if the missile does not collide too close to ship
 /// after shooting and correct its starting position if it does.
 /// </summary>
 private Vector3 CorrectPosition(Vector3 position, Vector3 direction, MyEntity viewerEntity)
 {
     var predictedTrajectory = new MyLine(
         position - MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION * direction,
         position + MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION * direction,
         false);
     var intersection = MyEntities.GetIntersectionWithLine(ref predictedTrajectory, this, viewerEntity);
     if (intersection != null)
     {
         position = viewerEntity.GetPosition();
     }
     return position;
 }
示例#36
0
 float GetActiveDistanceToTarget(MyEntity e)
 {
     return (e.GetPosition() - GetPosition()).Length();
 }
示例#37
0
 private void CallOnEntityPositionChange(MyEntity entity)
 {
     if(OnEntityPositionChange != null)
     {
         OnEntityPositionChange(this, entity, entity.GetPosition());
     }
 }
示例#38
0
 private float GetEntityDistance(MyEntity entity)
 {
     return Vector3.Distance(GetPosition(), entity.GetPosition());
 }
        /// <summary>
        /// Check if the missile does not collide too close to ship
        /// after shooting and correct its starting position if it does.
        /// </summary>
        private Vector3 CorrectPosition(Vector3 position, Vector3 direction, MyEntity viewerEntity)
        {
            //var predictedTrajectory = new MyLine(
            //    position - (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    position + (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    true);
            //var intersection = MyEntities.GetIntersectionWithLine(ref predictedTrajectory, this, viewerEntity);


            // This is fix for missles hitting voxels when you are near them (missles do not use per triangle collision as optimalization)
            float radius = MyModels.GetModel(MyModelsEnum.Missile).BoundingSphere.Radius;

            BoundingSphere boundingSphere = viewerEntity.WorldVolume;
            boundingSphere.Center += viewerEntity.WorldMatrix.Up * 1;

            var intersection = MyEntities.GetIntersectionWithSphere(ref boundingSphere, this, viewerEntity);

            if (intersection != null && !(intersection is MyMissile))
            {
                position = viewerEntity.GetPosition() + 2 * Vector3.One;
            }

            return position;
        }
示例#40
0
 private bool IsInMyHemisphere(MyEntity targetEntity)
 {
     var direction = targetEntity.GetPosition() - GetPosition();
     direction.Normalize();
     var dot = Vector3.Dot(direction, WorldMatrix.Forward);
     return dot > 0.5f;
 }
示例#41
0
        public static void ApplyProjectileForce(MyEntity physObject, Vector3 intersectionPosition, Vector3 normalizedDirection, bool isPlayerShip)
        {
            float impulseMultiplier = isPlayerShip ? MyMinerShipConstants.MINER_SHIP_PLAYER_PROJECTILE_HIT_MULTIPLIER : (MyMinerShipConstants.MINER_SHIP_PROJECTILE_HIT_MULTIPLIER);

            // To make it look good, bots gets impulse which rotates them
            if (physObject is MySmallShipBot)
            {
                // These are constants to make proper bot behaviour to physics
                const float torqueMult = 4;
                const float impulseMult = 20;

                impulseMultiplier *= impulseMult;
                var centerToIntersection = intersectionPosition - physObject.GetPosition();
                intersectionPosition = physObject.GetPosition() + centerToIntersection * torqueMult;
            }

            //  If we hit model that belongs to physic object, apply some force to it (so it's thrown in the direction of shoting)
            physObject.Physics.AddForce(
                    MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE,
                    normalizedDirection * MyProjectilesConstants.HIT_STRENGTH_IMPULSE * impulseMultiplier,
                    intersectionPosition, Vector3.Zero);
        }