Exemple #1
0
        protected bool GeneratedBlockExists(Vector3I pos, MyBlockOrientation orientation, MyCubeBlockDefinition definition)
        {
            MySlimBlock block = m_grid.GetCubeBlock(pos);

            if (block == null)
            {
                return(false);
            }

            var cmpBlock = block.FatBlock as MyCompoundCubeBlock;

            if (MyFakes.ENABLE_COMPOUND_BLOCKS && cmpBlock != null)
            {
                foreach (var blockInCompound in cmpBlock.GetBlocks())
                {
                    // The same block with the same orientation
                    if (blockInCompound.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId && blockInCompound.Orientation == orientation)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                return(block.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId && block.Orientation == orientation);
            }
        }
        /// <summary>
        /// Transforms given compound block with matrix for static grid. Rotation of block is not changed.
        /// </summary>
        private static void ConvertRotatedGridCompoundBlockToStatic(ref MatrixI transform, MyObjectBuilder_CompoundCubeBlock origBlock)
        {
            MyDefinitionId        defId = new MyDefinitionId(origBlock.TypeId, origBlock.SubtypeName);
            MyCubeBlockDefinition blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out blockDefinition);
            if (blockDefinition == null)
            {
                return;
            }

            // Orientation quaternion is not setup in origblock
            MyBlockOrientation origOrientation = origBlock.BlockOrientation;
            Vector3I           origMin         = origBlock.Min;
            Vector3I           origMax;

            MySlimBlock.ComputeMax(blockDefinition, origOrientation, ref origMin, out origMax);

            Vector3I tMin;
            Vector3I tMax;

            Vector3I.Transform(ref origMin, ref transform, out tMin);
            Vector3I.Transform(ref origMax, ref transform, out tMax);

            // Write data
            origBlock.Min = Vector3I.Min(tMin, tMax);
        }
        public static BoundingBox CalculateBoundingBox(this MyObjectBuilder_CubeGrid grid)
        {
            float gridSize = MyDefinitionManager.Static.GetCubeSize(grid.GridSizeEnum);

            BoundingBox localBb = new BoundingBox(Vector3.MaxValue, Vector3.MinValue);

            try
            {
                foreach (var block in grid.CubeBlocks)
                {
                    MyCubeBlockDefinition definition;
                    if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out definition))
                    {
                        MyBlockOrientation ori       = block.BlockOrientation;
                        Vector3            blockSize = Vector3.TransformNormal(new Vector3(definition.Size) * gridSize, ori);
                        blockSize = Vector3.Abs(blockSize);

                        Vector3 minCorner = new Vector3(block.Min) * gridSize - new Vector3(gridSize / 2);
                        Vector3 maxCorner = minCorner + blockSize;

                        localBb.Include(minCorner);
                        localBb.Include(maxCorner);
                    }
                }
            }
            catch (KeyNotFoundException e)
            {
                MySandboxGame.Log.WriteLine(e);
                return(new BoundingBox());
            }

            return(localBb);
        }
Exemple #4
0
        public Vector3I TransformThrustData(Vector3I originalData)
        {
            Vector3I newThrustData = new Vector3I();

            _referenceOrientation = Behavior.Settings.BlockOrientation;

            if (originalData.X != 0)
            {
                var axisDir = originalData.X == 1 ? _referenceOrientation.TransformDirection(Base6Directions.Direction.Right) : _referenceOrientation.TransformDirection(Base6Directions.Direction.Left);
                DirectionToVector(axisDir, ref newThrustData);
            }

            if (originalData.Y != 0)
            {
                var axisDir = originalData.Y == 1 ? _referenceOrientation.TransformDirection(Base6Directions.Direction.Up) : _referenceOrientation.TransformDirection(Base6Directions.Direction.Down);
                DirectionToVector(axisDir, ref newThrustData);
            }

            if (originalData.Z != 0)
            {
                var axisDir = originalData.Z == 1 ? _referenceOrientation.TransformDirection(Base6Directions.Direction.Forward) : _referenceOrientation.TransformDirection(Base6Directions.Direction.Backward);
                DirectionToVector(axisDir, ref newThrustData);
            }

            return(newThrustData);
        }
Exemple #5
0
        public Vector3D GetThrustDataFromDirection(Direction direction, MyBlockOrientation orientation)
        {
            if (direction == Direction.None)
            {
                return(Vector3D.Zero);
            }

            var baseDir = GetTransformedBaseDirection(direction, orientation);

            if (baseDir == Base6Directions.Direction.Right || baseDir == Base6Directions.Direction.Left)
            {
                return(new Vector3D(ControlX ? 1 : 0, !InvertX ? 1 : -1, StrengthX));
            }

            if (baseDir == Base6Directions.Direction.Up || baseDir == Base6Directions.Direction.Down)
            {
                return(new Vector3D(ControlY ? 1 : 0, !InvertY ? 1 : -1, StrengthY));
            }

            if (baseDir == Base6Directions.Direction.Forward || baseDir == Base6Directions.Direction.Backward)
            {
                return(new Vector3D(ControlZ ? 1 : 0, !InvertZ ? 1 : -1, StrengthZ));
            }

            return(Vector3D.Zero);
        }
        private static MyObjectBuilder_CubeBlock ConvertDynamicGridBlockToStatic(ref MatrixD worldMatrix, MyObjectBuilder_CubeBlock origBlock)
        {
            MyDefinitionId        defId = new MyDefinitionId(origBlock.TypeId, origBlock.SubtypeName);
            MyCubeBlockDefinition blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out blockDefinition);
            if (blockDefinition == null)
            {
                return(null);
            }

            var blockBuilder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock;

            blockBuilder.EntityId = origBlock.EntityId;
            // Orientation quaternion is not setup in origblock
            MyBlockOrientation orientation = origBlock.BlockOrientation;
            Quaternion         rotationQuat;

            orientation.GetQuaternion(out rotationQuat);
            Matrix origRotationMatrix = Matrix.CreateFromQuaternion(rotationQuat);
            Matrix rotationMatrix     = origRotationMatrix * worldMatrix;

            blockBuilder.Orientation = Quaternion.CreateFromRotationMatrix(rotationMatrix);

            Vector3I origSizeRotated = Vector3I.Abs(Vector3I.Round(Vector3.TransformNormal((Vector3)blockDefinition.Size, origRotationMatrix)));
            Vector3I origMin         = origBlock.Min;
            Vector3I origMax         = origBlock.Min + origSizeRotated - Vector3I.One;

            Vector3I minXForm = Vector3I.Round(Vector3.TransformNormal((Vector3)origMin, worldMatrix));
            Vector3I maxXForm = Vector3I.Round(Vector3.TransformNormal((Vector3)origMax, worldMatrix));

            blockBuilder.Min = Vector3I.Min(minXForm, maxXForm);
            return(blockBuilder);
        }
Exemple #7
0
 //Parallel
 public void SetBaseDirections(MyBlockOrientation orientation)
 {
     foreach (var thrust in ThrustProfiles)
     {
         thrust.SetBaseDirection(orientation);
     }
 }
Exemple #8
0
        public static bool CanAddBlocks(MyCubeBlockDefinition definition, MyBlockOrientation orientation, MyCubeBlockDefinition otherDefinition, MyBlockOrientation otherOrientation)
        {
            Debug.Assert(MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES);

            if (!IsCompoundEnabled(definition) || !IsCompoundEnabled(otherDefinition))
            {
                return(false);
            }

            if (MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES)
            {
                Matrix thisRotation;
                orientation.GetMatrix(out thisRotation);

                m_tmpDummies.Clear();
                GetCompoundCollisionDummies(definition, m_tmpDummies);

                Matrix otherRotation;
                otherOrientation.GetMatrix(out otherRotation);

                m_tmpOtherDummies.Clear();
                GetCompoundCollisionDummies(otherDefinition, m_tmpOtherDummies);

                bool intersect = CompoundDummiesIntersect(ref thisRotation, ref otherRotation, m_tmpDummies, m_tmpOtherDummies);
                m_tmpDummies.Clear();
                m_tmpOtherDummies.Clear();
                return(!intersect);
            }

            // Note that this part (compound templates) is not implemented, because it will not be used in future (only dummies).
            return(true);
        }
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation, HashSet <string> names, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder)
        {
            var name = shape.Name;

            if (names.Contains(name))
            {
                MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
                if (shapeOrientation == blockOrientation)
                {
                    MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
                    builderShape.Name  = name;
                    builderShape.Fixed = MyDestructionHelper.IsFixed(shape);

                    fractureComponentBuilder.Shapes.Add(builderShape);
                }
            }

            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> children = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                {
                    var childShapeRotation = child.GetTransform();
                    ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, names, fractureComponentBuilder);
                }
            }
        }
Exemple #10
0
        public static bool getDirFromOri(MyBlockOrientation orientation, Base6Directions.Direction direction, out Base6Directions.Direction?result)
        {
            switch (direction)
            {
            case Base6Directions.Direction.Left:
                result = orientation.Left;
                break;

            case Base6Directions.Direction.Up:
                result = orientation.Up;
                break;

            case Base6Directions.Direction.Forward:
                result = orientation.Forward;
                break;

            case Base6Directions.Direction.Right:
                result = Base6Directions.GetFlippedDirection(orientation.Left);
                break;

            case Base6Directions.Direction.Down:
                result = Base6Directions.GetFlippedDirection(orientation.Up);
                break;

            case Base6Directions.Direction.Backward:
                result = Base6Directions.GetFlippedDirection(orientation.Forward);
                break;

            default:
                result = null;
                return(false);
            }
            return(true);
        }
Exemple #11
0
        private BoundingBox CalculateBoundingBox(MyObjectBuilder_CubeGrid grid)
        {
            float       cubeSize    = MyDefinitionManager.Static.GetCubeSize(grid.GridSizeEnum);
            BoundingBox boundingBox = new BoundingBox(Vector3.MaxValue, Vector3.MinValue);

            try
            {
                foreach (MyObjectBuilder_CubeBlock cubeBlock in grid.CubeBlocks)
                {
                    MyCubeBlockDefinition blockDefinition;
                    if (!MyDefinitionManager.Static.TryGetCubeBlockDefinition(cubeBlock.GetId(), out blockDefinition))
                    {
                        continue;
                    }
                    MyBlockOrientation blockOrientation = (MyBlockOrientation)cubeBlock.BlockOrientation;
                    Vector3            vector3          = Vector3.Abs(Vector3.TransformNormal(new Vector3(blockDefinition.Size) * cubeSize, blockOrientation));
                    Vector3            point1           = new Vector3((Vector3I)cubeBlock.Min) * cubeSize - new Vector3(cubeSize / 2f);
                    Vector3            point2           = point1 + vector3;
                    boundingBox.Include(point1);
                    boundingBox.Include(point2);
                }
            }
            catch (Exception e)
            {
                Core.GeneralLog.WriteToLog("CalculateBoundingBox", $"Exception:\t{e}");
                return(new BoundingBox());
            }
            return(boundingBox);
        }
Exemple #12
0
        private bool IsRotationValid(MyBlockOrientation refOrientation, MyBlockOrientation orientation, MyBlockOrientation[] validRotations)
        {
            Debug.Assert(validRotations != null);

            // Ref matrix
            MatrixI localMatrix = new MatrixI(Vector3I.Zero, refOrientation.Forward, refOrientation.Up);
            MatrixI inverseMatrix;

            MatrixI.Invert(ref localMatrix, out inverseMatrix);
            Matrix inverseMatrixF = inverseMatrix.GetFloatMatrix();

            // Transform orientation to ref
            Base6Directions.Direction forward = Base6Directions.GetClosestDirection(Vector3.TransformNormal((Vector3)Base6Directions.GetIntVector(orientation.Forward), inverseMatrixF));
            Base6Directions.Direction up      = Base6Directions.GetClosestDirection(Vector3.TransformNormal((Vector3)Base6Directions.GetIntVector(orientation.Up), inverseMatrixF));

            foreach (var validRotation in validRotations)
            {
                if (validRotation.Forward == forward && validRotation.Up == up)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #13
0
        protected bool GeneratedBlockExists(Vector3I pos, MyBlockOrientation orientation, MyCubeBlockDefinition definition)
        {
            MySlimBlock cubeBlock = this.m_grid.GetCubeBlock(pos);

            if (cubeBlock != null)
            {
                MyCompoundCubeBlock fatBlock = cubeBlock.FatBlock as MyCompoundCubeBlock;
                if (!MyFakes.ENABLE_COMPOUND_BLOCKS || (fatBlock == null))
                {
                    return((cubeBlock.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId) && (cubeBlock.Orientation == orientation));
                }
                using (List <MySlimBlock> .Enumerator enumerator = fatBlock.GetBlocks().GetEnumerator())
                {
                    while (true)
                    {
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                        MySlimBlock current = enumerator.Current;
                        if ((current.BlockDefinition.Id.SubtypeId == definition.Id.SubtypeId) && (current.Orientation == orientation))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemple #14
0
        public override bool ConnectionAllowed(ref Vector3I otherBlockPos, ref Vector3I faceNormal, MyCubeBlockDefinition def)
        {
            if (this.MountPoints == null)
            {
                return(true);
            }
            Vector3I           pos         = (Vector3I)(base.Position + faceNormal);
            MySlimBlock        cubeBlock   = base.CubeGrid.GetCubeBlock(pos);
            MyBlockOrientation orientation = (cubeBlock == null) ? MyBlockOrientation.Identity : cubeBlock.Orientation;
            Vector3I           position    = base.Position;

            this.m_mpCache.Clear();
            if ((cubeBlock != null) && (cubeBlock.FatBlock is MyFracturedBlock))
            {
                this.m_mpCache.AddRange((cubeBlock.FatBlock as MyFracturedBlock).MountPoints);
            }
            else if ((cubeBlock != null) && (cubeBlock.FatBlock is MyCompoundCubeBlock))
            {
                List <MyCubeBlockDefinition.MountPoint> outMountPoints = new List <MyCubeBlockDefinition.MountPoint>();
                foreach (MySlimBlock block2 in (cubeBlock.FatBlock as MyCompoundCubeBlock).GetBlocks())
                {
                    MyCubeBlockDefinition.MountPoint[] buildProgressModelMountPoints = block2.BlockDefinition.GetBuildProgressModelMountPoints(block2.BuildLevelRatio);
                    MyCubeGrid.TransformMountPoints(outMountPoints, block2.BlockDefinition, buildProgressModelMountPoints, ref block2.Orientation);
                    this.m_mpCache.AddRange(outMountPoints);
                }
            }
            else if (cubeBlock != null)
            {
                MyCubeBlockDefinition.MountPoint[] buildProgressModelMountPoints = def.GetBuildProgressModelMountPoints(cubeBlock.BuildLevelRatio);
                MyCubeGrid.TransformMountPoints(this.m_mpCache, def, buildProgressModelMountPoints, ref orientation);
            }
            return(MyCubeGrid.CheckMountPointsForSide(this.MountPoints, ref base.SlimBlock.Orientation, ref position, base.BlockDefinition.Id, ref faceNormal, this.m_mpCache, ref orientation, ref pos, def.Id));
        }
Exemple #15
0
        public static unsafe void Serialize(this BitStream stream, ref MyBlockOrientation orientation)
        {
            var copy = orientation;

            stream.SerializeMemory(&copy, sizeof(MyBlockOrientation) * 8);
            orientation = copy;
        }
        public static ListReader <Vector3> GetBlockVertices(MyCubeTopology topology, MyBlockOrientation orientation)
        {
            var list = Cache[(int)topology][(int)orientation.Forward * 6 + (int)orientation.Up];

            Debug.Assert(list != null, "Unknown topology");
            return(new ListReader <Vector3>(list));
        }
        static void GenerateConvexVertices()
        {
            List <Vector3> tmpHelperVerts = new List <Vector3>(27);
            var            topologyValues = Enum.GetValues(typeof(MyCubeTopology));

            Cache = new List <Vector3> [topologyValues.Length][];
            foreach (var topologyObj in topologyValues)
            {
                var topology = (MyCubeTopology)topologyObj;
                GetTopologySwitch(topology, tmpHelperVerts);

                Cache[(int)topology] = new List <Vector3> [6 * 6];
                foreach (var forward in Base6Directions.EnumDirections)
                {
                    foreach (var up in Base6Directions.EnumDirections)
                    {
                        if (forward == up || Base6Directions.GetIntVector(forward) == -Base6Directions.GetIntVector(up))
                        {
                            continue;
                        }
                        var list = new List <Vector3>(tmpHelperVerts.Count);
                        Cache[(int)topology][(int)forward * 6 + (int)up] = list;

                        var orientation = new MyBlockOrientation(forward, up);
                        foreach (var vert in tmpHelperVerts)
                        {
                            list.Add(Vector3.TransformNormal(vert, orientation));
                        }
                    }
                }

                tmpHelperVerts.Clear();
            }
        }
 public StructureEntry()
 {
     type           = typeof(CubeBlockEntity);
     color          = new Color(0, 0, 0);
     useOrientation = false;
     orientation    = MyBlockOrientation.Identity;
 }
        /// <summary>
        /// Converts the given block with the given matrix for static grid.
        /// </summary>
        private static void ConvertRotatedGridBlockToStatic(ref MatrixI transform, MyObjectBuilder_CubeBlock origBlock)
        {
            MyDefinitionId        defId = new MyDefinitionId(origBlock.TypeId, origBlock.SubtypeName);
            MyCubeBlockDefinition blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out blockDefinition);
            if (blockDefinition == null)
            {
                return;
            }

            // Orientation quaternion is not setup in origblock
            MyBlockOrientation origOrientation = origBlock.BlockOrientation;
            Vector3I           origMin         = origBlock.Min;
            Vector3I           origMax;

            MySlimBlock.ComputeMax(blockDefinition, origOrientation, ref origMin, out origMax);

            Vector3I tMin;
            Vector3I tMax;

            Vector3I.Transform(ref origMin, ref transform, out tMin);
            Vector3I.Transform(ref origMax, ref transform, out tMax);
            Base6Directions.Direction forward = transform.GetDirection(origOrientation.Forward);
            Base6Directions.Direction up      = transform.GetDirection(origOrientation.Up);

            // Write data
            MyBlockOrientation newBlockOrientation = new MyBlockOrientation(forward, up);
            Quaternion         rotationQuat;

            newBlockOrientation.GetQuaternion(out rotationQuat);
            origBlock.Orientation = rotationQuat;
            origBlock.Min         = Vector3I.Min(tMin, tMax);
        }
Exemple #20
0
        protected bool CanPlaceBlock(Vector3I position, MyCubeBlockDefinition definition, Vector3I forward, Vector3I up)
        {
            MyBlockOrientation orientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));
            int?ignoreMultiblockId         = null;

            return(this.m_grid.CanPlaceBlock(position, position, orientation, definition, ignoreMultiblockId, false));
        }
Exemple #21
0
        public bool IsThrustEnabledInDirection(Direction direction, MyBlockOrientation orientation)
        {
            if (direction == Direction.None)
            {
                return(false);
            }

            var baseDir = GetTransformedBaseDirection(direction, orientation);

            if (baseDir == Base6Directions.Direction.Right || baseDir == Base6Directions.Direction.Left)
            {
                return(ControlX);
            }

            if (baseDir == Base6Directions.Direction.Up || baseDir == Base6Directions.Direction.Down)
            {
                return(ControlY);
            }

            if (baseDir == Base6Directions.Direction.Forward || baseDir == Base6Directions.Direction.Backward)
            {
                return(ControlZ);
            }

            return(false);
        }
        protected bool CanPlaceBlock(Vector3I position, MyCubeBlockDefinition definition, Vector3I forward, Vector3I up)
        {
            Debug.Assert(forward != up);
            Debug.Assert(forward != Vector3I.Zero);
            Debug.Assert(up != Vector3I.Zero);
            MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));

            return(m_grid.CanPlaceBlock(position, position, blockOrientation, definition));
        }
        private void ComputeMax(MyCubeBlockDefinition definition, MyBlockOrientation orientation, ref Vector3I min, out Vector3I max)
        {
            Vector3I size        = definition.Size - 1;
            MatrixI  localMatrix = new MatrixI(orientation);

            Vector3I.TransformNormal(ref size, ref localMatrix, out size);
            Vector3I.Abs(ref size, out size);
            max = min + size;
        }
Exemple #24
0
 public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, Vector3I forward, Vector3I up, ushort?blockIdInCompound = new ushort?(), MyAdditionalModelGeneratorBase.MyGridInfo gridInfo = null)
 {
     this.RefBlock           = refBlock;
     this.BlockDefinition    = blockDefinition;
     this.Position           = position;
     this.Orientation        = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up));
     this.BlockIdInCompound  = blockIdInCompound;
     this.GridInfo           = gridInfo;
     this.GeneratedBlockType = MyStringId.NullOrEmpty;
 }
 public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, Vector3I forward, Vector3I up, ushort?blockIdInCompound = null, MyGridInfo gridInfo = null)
 {
     RefBlock           = refBlock;
     BlockDefinition    = blockDefinition;
     Position           = position;
     Orientation        = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up));
     BlockIdInCompound  = blockIdInCompound;
     GridInfo           = gridInfo;
     GeneratedBlockType = MyStringId.NullOrEmpty;
 }
 public MyGeneratedBlockLocation(MySlimBlock refBlock, MyCubeBlockDefinition blockDefinition, Vector3I position, MyBlockOrientation orientation, ushort?blockIdInCompound = null, MyGridInfo gridInfo = null)
 {
     RefBlock           = refBlock;
     BlockDefinition    = blockDefinition;
     Position           = position;
     Orientation        = orientation;
     BlockIdInCompound  = blockIdInCompound;
     GridInfo           = gridInfo;
     GeneratedBlockType = MyStringId.NullOrEmpty;
 }
Exemple #27
0
        protected void AddGeneratedBlock(MySlimBlock refBlock, MyCubeBlockDefinition generatedBlockDefinition, Vector3I position, Vector3I forward, Vector3I up)
        {
            MyBlockOrientation orientation = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up));

            if (generatedBlockDefinition.Size == Vector3I.One)
            {
                ushort?blockIdInCompound = null;
                this.m_addLocations.Add(new MyGeneratedBlockLocation(refBlock, generatedBlockDefinition, position, orientation, blockIdInCompound, null));
            }
        }
Exemple #28
0
        /// <summary>
        /// Move blocks in m_projectedBlocks to m_damagedBlocks if they are touching any real blocks
        /// </summary>
        private void ProjectedToDamaged()
        {
            foreach (IMySlimBlock block in m_projectedBlocks)
            {
                MyCubeGrid projected     = (MyCubeGrid)block.CubeGrid;
                MyCubeGrid projectorGrid = projected.Projector.CubeGrid;

                if (projected.Closed || projected.Projector.Closed || !projected.Projector.IsWorking || projectorGrid.Closed)
                {
                    Log.DebugLog("projection closed");
                    continue;
                }

                Vector3I min = projectorGrid.WorldToGridInteger(projected.GridIntegerToWorld(block.Min()));

                if (projectorGrid.GetCubeBlock(min) != null)
                {
                    Log.DebugLog("space is occupied: " + min);
                    m_projectedBlocks.Remove(block);
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;
                if (cubeBlock != null)
                {
                    Vector3I max = projectorGrid.WorldToGridInteger(projected.GridIntegerToWorld(block.Max()));

                    MatrixD invOrient = projectorGrid.PositionComp.WorldMatrixNormalizedInv.GetOrientation();
                    Vector3 forward   = Vector3D.Transform(cubeBlock.WorldMatrix.Forward, ref invOrient);
                    Vector3 up        = Vector3D.Transform(cubeBlock.WorldMatrix.Up, ref invOrient);

                    MyBlockOrientation orient = new MyBlockOrientation(Base6Directions.GetClosestDirection(ref forward), Base6Directions.GetClosestDirection(ref up));

                    if (projectorGrid.CanPlaceBlock(min, max, orient, ((MyCubeBlock)cubeBlock).BlockDefinition))
                    {
                        Log.DebugLog("can place fatblock: " + cubeBlock.DisplayNameText + ", position: " + min + ", world: " + projectorGrid.GridIntegerToWorld(min));
                        m_damagedBlocks.Add(block);
                        m_projectedBlocks.Remove(block);
                    }

                    continue;
                }

                // no fatblock, cannot get definition
                if (projectorGrid.IsTouchingAnyNeighbor(min, min))
                {
                    Log.DebugLog("can place slimblock: " + block.ToString() + ", position: " + min + ", world: " + projectorGrid.GridIntegerToWorld(min));
                    m_damagedBlocks.Add(block);
                    m_projectedBlocks.Remove(block);
                }
            }

            m_projectedBlocks.ApplyRemovals();
        }
Exemple #29
0
        /// <summary>
        /// Adds generated block to add block locations.
        /// </summary>
        protected void AddGeneratedBlock(MySlimBlock refBlock, MyCubeBlockDefinition generatedBlockDefinition, Vector3I position, Vector3I forward, Vector3I up)
        {
            Debug.Assert(refBlock != null && !refBlock.BlockDefinition.IsGeneratedBlock);

            var orientation = new MyBlockOrientation(Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up));

            Debug.Assert(generatedBlockDefinition.Size == Vector3I.One);
            if (generatedBlockDefinition.Size == Vector3I.One)
            {
                m_addLocations.Add(new MyGeneratedBlockLocation(refBlock, generatedBlockDefinition, position, orientation));
            }
        }
Exemple #30
0
        public ThrustSystem(IMyRemoteControl remoteControl)
        {
            AngleAllowedForForwardThrust    = 35;
            MaxVelocityAngleForSpeedControl = 5;
            AllowStrafing        = false;
            StrafeMinDurationMs  = 750;
            StrafeMaxDurationMs  = 1500;
            StrafeMinCooldownMs  = 1000;
            StrafeMaxCooldownMs  = 3000;
            StrafeSpeedCutOff    = 100;
            StrafeDistanceCutOff = 100;

            StrafeMinimumTargetDistance      = 250;
            StrafeMinimumSafeAngleFromTarget = 25;

            AllowedStrafingDirectionsSpace  = new Vector3I(1, 1, 1);
            AllowedStrafingDirectionsPlanet = new Vector3I(1, 1, 1);

            RemoteControl  = null;
            Mode           = ThrustMode.None;
            ThrustProfiles = new List <ThrustProfile>();
            Rnd            = new Random();

            CurrentAllowedThrust  = Vector3I.Zero;
            CurrentRequiredThrust = Vector3I.Zero;

            if (StrafeMinDurationMs >= StrafeMaxDurationMs)
            {
                StrafeMaxDurationMs = StrafeMinDurationMs + 1;
            }

            if (StrafeMinCooldownMs >= StrafeMaxCooldownMs)
            {
                StrafeMaxCooldownMs = StrafeMinCooldownMs + 1;
            }

            _referenceOrientation = new MyBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up);

            Strafing = false;
            CurrentStrafeDirections        = Vector3I.Zero;
            CurrentAllowedStrafeDirections = Vector3I.Zero;
            ThisStrafeDuration             = Rnd.Next(StrafeMinDurationMs, StrafeMaxDurationMs);
            ThisStrafeCooldown             = Rnd.Next(StrafeMinCooldownMs, StrafeMaxCooldownMs);
            LastStrafeStartTime            = MyAPIGateway.Session.GameDateTime;
            LastStrafeEndTime = MyAPIGateway.Session.GameDateTime;

            _collisionStrafeAdjusted        = false;
            _minAngleDistanceStrafeAdjusted = false;
            _collisionStrafeDirection       = Vector3D.Zero;

            Setup(remoteControl);
        }
    public void Init(IEnumerable<IMyTerminalBlock> blocks,
                     Func<IMyThrust, bool> collect = null,
                     Base6Directions.Direction shipUp = Base6Directions.Direction.Up,
                     Base6Directions.Direction shipForward = Base6Directions.Direction.Forward)
    {
        MyBlockOrientation shipOrientation = new MyBlockOrientation(shipForward, shipUp);

        thrusters.Clear();
        for (var e = blocks.GetEnumerator(); e.MoveNext();)
        {
            var thruster = e.Current as IMyThrust;
            if (thruster != null && thruster.IsFunctional &&
                (collect == null || collect(thruster)))
            {
                var facing = thruster.Orientation.TransformDirection(Base6Directions.Direction.Forward); // Exhaust goes this way
                var thrustDirection = Base6Directions.GetFlippedDirection(facing);
                var shipDirection = shipOrientation.TransformDirectionInverse(thrustDirection);
                AddThruster(shipDirection, thruster);
            }
        }
    }