Esempio n. 1
0
        void SetLocalTarget(IMySlimBlock block)
        {
            if (block == TargetBlock)
            {
                return;
            }

            TargetBlock = block;

            if (block != null)
            {
                block.ComputeWorldCenter(out BlockLocalCenter);
                BlockLocalCenter = Vector3D.Transform(BlockLocalCenter, block.CubeGrid.WorldMatrixInvScaled);

                Packet.GridId   = block.CubeGrid.EntityId;
                Packet.BlockPos = block.Min;
            }
            else
            {
                Packet.GridId   = 0;
                Packet.BlockPos = default(Vector3I);
            }

            Main.Networking.SendToServer(Packet);

            //Main.Notifications.Print(Channel.Other, $"Precision Grind: set={(block?.BlockDefinition?.DisplayNameText ?? "null")}", MyFontEnum.Debug, 3 * 1000);
        }
Esempio n. 2
0
        public bool Init(MaterialPropertyDatabase db, IMySlimBlock block)
        {
            if (block.FatBlock != null)
            {
                return(Init(db, block.FatBlock));
            }
            Vector3D center;

            block.ComputeWorldCenter(out center);
            Init(db.PropertiesOf(block.BlockDefinition.Id), block.Mass, PhysicalConstants.TemperatureAtPoint(center));
            return(true);
        }
Esempio n. 3
0
        public static MyOrientedBoundingBoxD GetOBB(this IMySlimBlock block)
        {
            Quaternion quaternion = Quaternion.CreateFromForwardUp(
                block.CubeGrid.WorldMatrix.Forward,
                block.CubeGrid.WorldMatrix.Up);
            float blocksize   = block.CubeGrid.GridSize;
            var   def         = block.BlockDefinition as MyCubeBlockDefinition;
            var   halfExtents = new Vector3D(
                (def.Size.X + 1) * blocksize / 2,
                (def.Size.Y + 1) * blocksize / 2,
                (def.Size.Z + 1) * blocksize / 2);
            Vector3D center;

            MyTexts.Clear();
            block.ComputeWorldCenter(out center);
            return(new MyOrientedBoundingBoxD(center, halfExtents, quaternion));
        }
        public DetachEffectsPacket(IMySlimBlock block)
        {
            Matrix localMatrix;

            block.Orientation.GetMatrix(out localMatrix);
            block.ComputeWorldCenter(out Position);

            MatrixD wm = localMatrix * block.CubeGrid.WorldMatrix;

            Orientation = QuaternionD.CreateFromRotationMatrix(wm);

            Velocity = block.CubeGrid.Physics.LinearVelocity;

            ModelBB = block.FatBlock?.LocalAABB;

            BlockDefId = block.BlockDefinition.Id;
        }
Esempio n. 5
0
        public WeldBlock(Pathfinder pathfinder, AllNavigationSettings navSet, PseudoBlock welder, IMySlimBlock block)
            : base(pathfinder)
        {
            this.m_offset        = welder.Block.LocalAABB.GetLongestDim() * 0.5f;      // this works for default welders, may not work if mod has an exotic design
            this.m_welder        = welder;
            this.m_targetSlim    = block;
            this.m_timeout_start = Globals.UpdateCount + TimeoutStart;

            IMyCubeBlock Projector = ((MyCubeGrid)block.CubeGrid).Projector;

            if (Projector != null)
            {
                this.m_weldProjection     = true;
                this.m_otherGrid          = Projector.CubeGrid;
                this.m_slimTarget_initDmg = 1f;
                this.m_targetCell         = Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(block.Position));
            }
            else
            {
                this.m_weldProjection     = false;
                this.m_slimTarget_initDmg = block.Damage();
                this.m_targetCell         = block.Position;
            }

            m_navSet.Settings_Task_NavEngage.NavigatorMover    = this;
            m_navSet.Settings_Task_NavEngage.NavigatorRotator  = this;
            m_navSet.Settings_Task_NavEngage.DestinationEntity = m_realGrid;

            IEnumerator <Vector3I> neighbours = this.m_targetSlim.ForEachNeighbourCell();

            while (neighbours.MoveNext())
            {
                Vector3I cell = m_weldProjection ? Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(neighbours.Current)) : neighbours.Current;
                m_neighbours.Add(cell);
                if (this.m_realGrid.GetCubeBlock(cell) == null)
                {
                    m_emptyNeighbours.Add(cell);
                }
            }

            m_targetSlim.ComputeWorldCenter(out m_targetWorld);
            m_lineUp.To = m_targetWorld;
        }
Esempio n. 6
0
        internal void AddShieldHit(long attackerId, float amount, MyStringHash damageType, IMySlimBlock block, bool reset, Vector3D?hitPos = null)
        {
            lock (ShieldHit)
            {
                ShieldHit.Amount    += amount;
                ShieldHit.DamageType = damageType.String;

                if (block != null && !hitPos.HasValue && ShieldHit.HitPos == Vector3D.Zero)
                {
                    if (block.FatBlock != null)
                    {
                        ShieldHit.HitPos = block.FatBlock.PositionComp.WorldAABB.Center;
                    }
                    else
                    {
                        block.ComputeWorldCenter(out ShieldHit.HitPos);
                    }
                }
                else if (hitPos.HasValue)
                {
                    ShieldHit.HitPos = hitPos.Value;
                }

                if (attackerId != 0)
                {
                    ShieldHit.AttackerId = attackerId;
                }
                if (amount > 0)
                {
                    _lastSendDamageTick = _tick;
                }
                if (reset)
                {
                    ShieldHitReset(true);
                }
            }
        }
Esempio n. 7
0
        public WeldBlock(Mover mover, AllNavigationSettings navSet, PseudoBlock welder, IMySlimBlock block)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, () => mover.Block.CubeGrid.DisplayName, () => block.getBestName(), () => m_stage.ToString());
            this.m_offset = welder.Block.LocalAABB.GetLongestDim() * 0.5f; // this works for default welders, may not work if mod has an exotic design
            this.m_welder = welder;
            this.m_targetSlim = block;
            this.m_timeout_start = Globals.UpdateCount + TimeoutStart;

            IMyCubeBlock Projector = ((MyCubeGrid)block.CubeGrid).Projector;
            if (Projector != null)
            {
                this.m_weldProjection = true;
                this.m_otherGrid = Projector.CubeGrid;
                this.m_slimTarget_initDmg = 1f;
                this.m_targetCell = Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(block.Position));
            }
            else
            {
                this.m_weldProjection = false;
                this.m_slimTarget_initDmg = block.Damage();
                this.m_targetCell = block.Position;
            }

            m_navSet.Settings_Task_NavEngage.NavigatorMover = this;
            m_navSet.Settings_Task_NavEngage.NavigatorRotator = this;
            m_navSet.Settings_Task_NavEngage.DestinationEntity = m_realGrid;

            IEnumerator<Vector3I> neighbours = this.m_targetSlim.ForEachNeighbourCell();
            while (neighbours.MoveNext())
            {
                Vector3I cell = m_weldProjection ? Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(neighbours.Current)) : neighbours.Current;
                m_neighbours.Add(cell);
                if (this.m_realGrid.GetCubeBlock(cell) == null)
                    m_emptyNeighbours.Add(cell);
            }

            m_targetSlim.ComputeWorldCenter(out m_targetWorld);
            m_lineUp.To = m_targetWorld;
        }
Esempio n. 8
0
        public void TargetIntersectionCheck()
        {
            _entityScanList.Clear();
            _voxelScanList.Clear();
            _entityScanList = new List <MyLineSegmentOverlapResult <MyEntity> >();
            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref Line, _entityScanList);

            IMyCubeGrid closestGrid         = null;
            double      closestGridDistance = -1;

            MySafeZone closestZone         = null;
            double     closestZoneDistance = -1;

            IMyCharacter closestCharacter         = null;
            double       closestCharacterDistance = -1;

            foreach (var item in _entityScanList)
            {
                var targetGrid   = item.Element as IMyCubeGrid;
                var targetZone   = item.Element as MySafeZone;
                var targetVoxel  = item.Element as MyVoxelBase;
                var targetPlayer = item.Element as IMyCharacter;

                if (targetGrid != null)
                {
                    if (targetGrid == _collisionSystem.RemoteControl.SlimBlock.CubeGrid || _collisionSystem.RemoteControl.SlimBlock.CubeGrid.IsSameConstructAs(targetGrid))
                    {
                        continue;
                    }

                    if (closestGrid == null || (closestGrid != null && item.Distance < closestGridDistance))
                    {
                        closestGrid         = targetGrid;
                        closestGridDistance = item.Distance;
                    }
                }

                if (targetZone != null)
                {
                    if (closestZone == null || (closestZone != null && item.Distance < closestZoneDistance))
                    {
                        closestZone         = targetZone;
                        closestZoneDistance = item.Distance;
                    }
                }

                if (targetVoxel != null)
                {
                    _voxelScanList.Add(targetVoxel);
                }

                if (targetPlayer != null)
                {
                    if (closestCharacter == null || (closestCharacter != null && item.Distance < closestCharacterDistance))
                    {
                        closestCharacter         = targetPlayer;
                        closestCharacterDistance = item.Distance;
                    }
                }
            }

            if (closestGrid != null)
            {
                double minDist        = 0;
                double maxDist        = 0;
                bool   boxCheckResult = closestGrid.PositionComp.WorldAABB.Intersect(ref Ray, out minDist, out maxDist);

                Vector3D startBox = boxCheckResult ? (minDist - 5) * DirectionVector + StartPosition : StartPosition;
                Vector3D endBox   = boxCheckResult ? (maxDist + 5) * DirectionVector + StartPosition : EndPosition;

                var blockPos = closestGrid.RayCastBlocks(startBox, endBox);

                if (!blockPos.HasValue)
                {
                    return;
                }

                IMySlimBlock slimBlock = closestGrid.GetCubeBlock(blockPos.Value);

                if (slimBlock == null)
                {
                    return;
                }

                Vector3D blockPosition = Vector3D.Zero;
                slimBlock.ComputeWorldCenter(out blockPosition);


                GridCoords   = blockPosition;
                GridDistance = Vector3D.Distance(blockPosition, StartPosition);
                GridEntity   = closestGrid;
                GridOwner    = OwnershipHelper.GetOwnershipTypes(closestGrid, false);
                GridRelation = OwnershipHelper.GetTargetReputation(_collisionSystem.Owner, closestGrid, false);
            }

            if (closestZone != null)
            {
                SafezoneEntity   = closestZone;
                SafezoneCoords   = closestZoneDistance * DirectionVector + StartPosition;
                SafezoneDistance = closestZoneDistance;
            }

            if (closestCharacter != null)
            {
                PlayerEntity   = closestCharacter;
                PlayerCoords   = PlayerEntity.PositionComp.WorldAABB.Center;
                PlayerDistance = closestCharacterDistance;
            }
        }
Esempio n. 9
0
        public override void Move()
        {
            if (m_targetSlim.Closed())
            {
                Log.DebugLog("target block closed: " + m_targetSlim.getBestName(), Logger.severity.INFO);
                m_navSet.OnTaskComplete_NavEngage();
                EnableWelders(false);
                return;
            }

            m_targetSlim.ComputeWorldCenter(out m_targetWorld);

            if (m_stage == Stage.Retreat)
            {
                Retreat();
                return;
            }

            float offsetSquared = m_offset + OffsetAdd + OffsetAdd; offsetSquared *= offsetSquared;

            if (Vector3.DistanceSquared(m_welder.WorldPosition, m_targetWorld) > offsetSquared)
            {
                EnableWelders(false);

                if (m_closestEmptyNeighbour.HasValue && Globals.UpdateCount > m_timeout_start)
                {
                    Log.DebugLog("failed to start, dropping neighbour: " + m_closestEmptyNeighbour, Logger.severity.DEBUG);

                    if (m_emptyNeighbours.Count > 1)
                    {
                        m_emptyNeighbours.Remove(m_closestEmptyNeighbour.Value);
                        m_closestEmptyNeighbour = null;
                    }
                    else
                    {
                        Log.DebugLog("tried every empty neighbour, giving up", Logger.severity.INFO);

                        EnableWelders(false);
                        m_stage = Stage.Retreat;
                        return;
                    }
                }

                if (!m_closestEmptyNeighbour.HasValue)
                {
                    GetClosestEmptyNeighbour();

                    if (!m_closestEmptyNeighbour.HasValue)
                    {
                        Log.DebugLog("tried every empty neighbour, giving up", Logger.severity.INFO);

                        EnableWelders(false);
                        m_stage = Stage.Retreat;
                        return;
                    }

                    m_timeout_start = Globals.UpdateCount + TimeoutStart;
                    Vector3D from = m_realGrid.GridIntegerToWorld(m_closestEmptyNeighbour.Value);
                    m_lineUp.From = m_lineUp.To + (from - m_lineUp.To) * 100d;
                }

                Vector3 closestPoint = m_lineUp.ClosestPoint(m_welder.WorldPosition);
                if (Vector3.DistanceSquared(m_welder.WorldPosition, closestPoint) > 1f || m_navSet.Settings_Current.DistanceAngle > 0.1f)
                {
                    m_stage = Stage.Lineup;
                    Destination dest = Destination.FromWorld(m_realGrid, m_lineUp.ClosestPoint(m_welder.WorldPosition));
                    m_pathfinder.MoveTo(destinations: dest);
                    return;
                }
                else                 // linedup up
                {
                    m_stage = Stage.Approach;
                }
            }
            else             // near target
            {
                m_stage = Stage.Weld;
                EnableWelders(true);
            }

            MoveToTarget();
        }