Beispiel #1
0
        private bool CanWeldTo(MyEntity entity, ref Matrix otherBodySpacePivot)
        {
            if (BreakForce < MyObjectBuilder_LandingGear.MaxSolverImpulse)
            {
                return(false);
            }

            MyCubeGrid grid = entity as MyCubeGrid;

            if (grid == null)
            {
                var block = entity as MyCubeBlock;
                if (block != null)
                {
                    grid = block.CubeGrid;
                }
            }

            if (grid != null)
            {
                Vector3I cube;
                grid.FixTargetCube(out cube, otherBodySpacePivot.Translation * grid.GridSizeR);
                var hangar = grid.GetCubeBlock(cube);
                if (hangar != null && hangar.FatBlock is MyAirtightHangarDoor)
                {
                    return(false);
                }
            }
            else if (entity.Parent != null)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public void OnWorldPosChanged(ref MatrixD newTransform)
        {
            MatrixD worldPos = newTransform;

            m_caster.OnWorldPositionChanged(ref worldPos);

            var      entitiesInRange = this.m_caster.EntitiesInRange;
            float    closestDistance = float.MaxValue;
            MyEntity closestEntity   = null;
            int      itemId          = 0;

            if (!m_isPointOfRefSet)
            {
                m_pointOfReference = worldPos.Translation;
            }

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
                // int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    float distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_pointOfReference);

                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            closestEntity          = entity.Entity;
                            itemId                 = entity.ItemId;
                            this.m_distanceToHitSq = distanceSq;
                            this.m_hitPosition     = entity.DetectionPoint;

                            closestDistance = distanceSq;
                        }
                    }
                    //   ++i;
                }
            }

            this.m_hitCubeGrid          = closestEntity as MyCubeGrid;
            this.m_hitBlock             = null;
            this.m_hitDestroaybleObj    = closestEntity as IMyDestroyableObject;
            this.m_hitFloatingObject    = closestEntity as MyFloatingObject;
            this.m_hitCharacter         = closestEntity as MyCharacter;
            this.m_hitEnvironmentSector = closestEntity as MyEnvironmentSector;
            this.m_environmentItem      = itemId;

            if (m_hitCubeGrid != null)
            {
                var      invWorld     = m_hitCubeGrid.PositionComp.WorldMatrixNormalizedInv;
                var      gridLocalPos = Vector3D.Transform(this.m_hitPosition, invWorld);
                Vector3I blockPos;
                m_hitCubeGrid.FixTargetCube(out blockPos, gridLocalPos / m_hitCubeGrid.GridSize);
                m_hitBlock = m_hitCubeGrid.GetCubeBlock(blockPos);
            }
        }
Beispiel #3
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            //MyRenderProxy.DebugDrawSphere(m_gunBase.PositionMuzzleWorld, 0.2f, new Vector3(1, 0, 0), 1.0f, true);

            m_targetGrid           = null;
            m_targetDestroyable    = null;
            m_targetFloatingObject = null;
            m_targetCharacter      = null;

            if (Owner == null)
            {
                return;
            }

            var   entitiesInRange    = m_sensor.EntitiesInRange;
            int   closestEntityIndex = 0;
            float closestDistance    = float.MaxValue;

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
                int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    var targetGrid = entity.Entity as MyCubeGrid;
                    var distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_gunBase.GetMuzzleWorldPosition());
                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            m_targetGrid           = targetGrid;
                            m_targetDistanceSq     = (float)distanceSq;
                            m_targetDestroyable    = entity.Entity as IMyDestroyableObject;
                            m_targetFloatingObject = entity.Entity as MyFloatingObject;
                            m_targetCharacter      = entity.Entity as MyCharacter;
                            closestDistance        = m_targetDistanceSq;
                            closestEntityIndex     = i;
                        }
                    }
                    ++i;
                }
            }

            if (m_targetGrid != null)
            {
                m_targetPosition = entitiesInRange.Values.ElementAt(closestEntityIndex).DetectionPoint;
                var invWorld     = m_targetGrid.PositionComp.GetWorldMatrixNormalizedInv();
                var gridLocalPos = Vector3D.Transform(m_targetPosition, invWorld);
                var gridSpacePos = Vector3I.Round(gridLocalPos / m_targetGrid.GridSize);
                m_targetGrid.FixTargetCube(out m_targetCube, gridLocalPos / m_targetGrid.GridSize);

                var head        = PositionComp.WorldMatrix;
                var aimToMuzzle = Vector3D.Normalize(m_targetPosition - m_gunBase.GetMuzzleWorldPosition());
                if (Vector3.Dot(aimToMuzzle, head.Forward) > 0)
                {
                    m_targetDistanceSq = 0;
                }
                else
                {
                    m_targetDistanceSq = (float)Vector3D.DistanceSquared(m_targetPosition, m_gunBase.GetMuzzleWorldPosition());
                }
            }
            PowerReceiver.Update();

            if (IsShooting && !PowerReceiver.IsPowered)
            {
                EndShoot(MyShootActionEnum.PrimaryAction);
            }

            UpdateEffect();
            CheckEffectType();

            //MyTrace.Watch("MyEngineerToolBase.RequiredPowerInput", RequiredPowerInput);
        }
Beispiel #4
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            //MyRenderProxy.DebugDrawSphere(m_gunBase.PositionMuzzleWorld, 0.2f, new Vector3(1, 0, 0), 1.0f, true);

            m_targetGrid           = null;
            m_targetDestroyable    = null;
            m_targetFloatingObject = null;
            m_targetCharacter      = null;

            if (Owner == null)
            {
                return;
            }

            var   entitiesInRange    = m_sensor.EntitiesInRange;
            int   closestEntityIndex = 0;
            float closestDistance    = float.MaxValue;

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
                int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    var targetGrid = entity.Entity as MyCubeGrid;
                    var distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_gunBase.GetMuzzleWorldPosition());
                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            m_targetGrid           = targetGrid;
                            m_targetDistanceSq     = (float)distanceSq;
                            m_targetDestroyable    = entity.Entity as IMyDestroyableObject;
                            m_targetFloatingObject = entity.Entity as MyFloatingObject;
                            m_targetCharacter      = entity.Entity as MyCharacter;
                            closestDistance        = m_targetDistanceSq;
                            closestEntityIndex     = i;
                        }
                    }
                    ++i;
                }
            }

            if (m_targetGrid != null)
            {
                m_targetPosition = entitiesInRange.Values.ElementAt(closestEntityIndex).DetectionPoint;
                var invWorld     = m_targetGrid.PositionComp.GetWorldMatrixNormalizedInv();
                var gridLocalPos = Vector3D.Transform(m_targetPosition, invWorld);
                var gridSpacePos = Vector3I.Round(gridLocalPos / m_targetGrid.GridSize);
                m_targetGrid.FixTargetCube(out m_targetCube, gridLocalPos / m_targetGrid.GridSize);

                var head        = PositionComp.WorldMatrix;
                var aimToMuzzle = Vector3D.Normalize(m_targetPosition - m_gunBase.GetMuzzleWorldPosition());
                if (Vector3.Dot(aimToMuzzle, head.Forward) > 0)
                {
                    m_targetDistanceSq = 0;
                }
                else
                {
                    m_targetDistanceSq = (float)Vector3D.DistanceSquared(m_targetPosition, m_gunBase.GetMuzzleWorldPosition());
                }
            }
            SinkComp.Update();

            if (IsShooting && !SinkComp.IsPowered)
            {
                EndShoot(MyShootActionEnum.PrimaryAction);
            }

            UpdateEffect();
            CheckEffectType();

            if (Owner != null && Owner.ControllerInfo.IsLocallyHumanControlled())
            {
                if (MySession.Static.SurvivalMode && (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.Spectator || MyFinalBuildConstants.IS_OFFICIAL))
                {
                    var character = ((MyCharacter)this.CharacterInventory.Owner);
                    MyCubeBuilder.Static.MaxGridDistanceFrom = character.PositionComp.GetPosition() + character.WorldMatrix.Up * 1.8f;
                }
                else
                {
                    MyCubeBuilder.Static.MaxGridDistanceFrom = null;
                }
            }

            //MyTrace.Watch("MyEngineerToolBase.RequiredPowerInput", RequiredPowerInput);
        }