示例#1
0
        /// <param name="damage">Not used for now but could be used as a multiplier instead of random decal size</param>
        public static void HandleAddDecal(IMyEntity entity, MyHitInfo hitInfo, MyStringHash source = default(MyStringHash), float damage = -1)
        {
            IMyDecalProxy proxy = entity as IMyDecalProxy;

            if (proxy != null)
            {
                AddDecal(proxy, ref hitInfo, damage, source);
                return;
            }

            MyCubeGrid grid = entity.GetTopMostParent() as MyCubeGrid;

            if (grid != null)
            {
                var block = grid.GetTargetedBlock(hitInfo.Position);
                if (block != null)
                {
                    var compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                    if (compoundBlock == null)
                    {
                        proxy = block;
                    }
                    else
                    {
                        proxy = compoundBlock;
                    }
                }
            }

            if (proxy != null)
            {
                AddDecal(proxy, ref hitInfo, damage, source);
            }
        }
示例#2
0
        /// <param name="damage">Not used for now but could be used as a multiplier instead of random decal size</param>
        public static void HandleAddDecal(IMyEntity entity, MyHitInfo hitInfo, MyStringHash material = default(MyStringHash), MyStringHash source = default(MyStringHash), object customdata = null, float damage = -1)
        {
            IMyDecalProxy proxy = entity as IMyDecalProxy;

            if (proxy != null)
            {
                AddDecal(proxy, ref hitInfo, damage, source, customdata, material);
                return;
            }

            MyCubeGrid grid = entity as MyCubeGrid;

            if (grid != null)
            {
                MyCubeGridHitInfo info = customdata as MyCubeGridHitInfo;
                MySlimBlock       block;
                if (info == null)
                {
                    block = grid.GetTargetedBlock(hitInfo.Position);
                    if (block == null)
                    {
                        return;
                    }

                    // If info is not provided, provide info with just block position
                    m_gridHitInfo.Position = block.Position;
                    customdata             = m_gridHitInfo;
                }
                else
                {
                    // If info is provided, lookup for the cube using provided position
                    MyCube cube;
                    bool   found = grid.TryGetCube(info.Position, out cube);
                    if (!found)
                    {
                        return;
                    }

                    block = cube.CubeBlock;
                }

                var compoundBlock = block != null ? block.FatBlock as MyCompoundCubeBlock : null;
                if (compoundBlock == null)
                {
                    proxy = block;
                }
                else
                {
                    proxy = compoundBlock;
                }
            }

            if (proxy == null)
            {
                return;
            }

            AddDecal(proxy, ref hitInfo, damage, source, customdata, material);
        }
示例#3
0
        private static void AddDecal(IMyDecalProxy proxy, ref MyHitInfo hitInfo, float damage, MyStringHash source, object customdata)
        {
            bool skip = DefaultFilterProxy(proxy);
            if (skip)
                return;

            m_handler.Source = source;
            m_handler.Enabled = true;
            proxy.AddDecals(hitInfo, source, customdata, m_handler);
            m_handler.Enabled = false;
            m_handler.Source = MyStringHash.NullOrEmpty;
        }
示例#4
0
        /// <returns>True to skip the decal</returns>
        private static bool DefaultFilterProxy(IMyDecalProxy proxy)
        {
            // TODO: Evaluate it better and add the ability to customize the filter on the game.
            // For example support filtering basing genericallt on the entity, hithinfo, damage...

            // Cannon ball in ME
            string tostring = proxy.ToString();
            if (tostring != null && tostring.StartsWith("MyRopeHookBlock"))
                return true;

            return false;
        }
示例#5
0
        /// <returns>True to skip the decal</returns>
        private static bool DefaultFilterProxy(IMyDecalProxy proxy)
        {
            // TODO: Evaluate it better and add the ability to customize the filter on the game.
            // For example support filtering basing genericallt on the entity, hithinfo, damage...

            // Cannon ball in ME
            if (proxy.GetType().Name.Contains("MyRopeHookBlock"))
            {
                return(true);
            }

            return(false);
        }
示例#6
0
        private static void AddDecal(IMyDecalProxy proxy, ref MyHitInfo hitInfo, float damage, MyStringHash source)
        {
            bool skip = DefaultFilterProxy(proxy);
            if (skip)
                return;

            MyDecalRenderData data;
            proxy.GetDecalRenderData(hitInfo, out data);
            if (data.Skip)
                return;

            MyDecalMaterial material;
            bool found = MyDecalMaterials.TryGetDecalMaterial(data.Material.String, source.String, out material);
            if (!found)
            {
                if (MyFakes.ENABLE_USE_DEFAULT_DAMAGE_DECAL)
                    found = MyDecalMaterials.TryGetDecalMaterial(DEFAULT, DEFAULT, out material);

                if (!found)
                    return;
            }

            var perp = Vector3.CalculatePerpendicularVector(data.Normal);

            float rotation = material.Rotation;
            if (material.Rotation == float.PositiveInfinity)
                rotation = MyRandom.Instance.NextFloat() * MathHelper.TwoPi;

            if (rotation != 0)
            {
                // Rotate around normal
                Quaternion q = Quaternion.CreateFromAxisAngle(data.Normal, rotation);
                perp = new Vector3((new Quaternion(perp, 0) * q).ToVector4());
            }

            var pos = MatrixD.CreateWorld(data.Position, data.Normal, perp);

            var size = material.MinSize;
            if (material.MaxSize > material.MinSize)
                size += MyRandom.Instance.NextFloat() * (material.MaxSize - material.MinSize);

            pos = Matrix.CreateScale(new Vector3(size, size, material.Depth)) * pos;

            var decalId = MyRenderProxy.CreateDecal(data.RenderObjectId, pos, material.GetStringId());
            proxy.OnAddDecal(decalId, ref data);
        }
示例#7
0
        private static void AddDecal(IMyDecalProxy proxy, ref MyHitInfo hitInfo, float damage, MyStringHash source)
        {
            bool skip = DefaultFilterProxy(proxy);

            if (skip)
            {
                return;
            }

            MyDecalRenderData data;

            proxy.GetDecalRenderData(hitInfo, out data);
            if (data.Skip)
            {
                return;
            }

            MyDecalMaterial material;
            bool            found = MyDecalMaterials.TryGetDecalMaterial(data.Material.String, source.String, out material);

            if (!found)
            {
                if (MyFakes.ENABLE_USE_DEFAULT_DAMAGE_DECAL)
                {
                    found = MyDecalMaterials.TryGetDecalMaterial(DEFAULT, DEFAULT, out material);
                }

                if (!found)
                {
                    return;
                }
            }

            var perp = Vector3.CalculatePerpendicularVector(data.Normal);

            float rotation = material.Rotation;

            if (material.Rotation == float.PositiveInfinity)
            {
                rotation = MyRandom.Instance.NextFloat() * MathHelper.TwoPi;
            }

            if (rotation != 0)
            {
                // Rotate around normal
                Quaternion q = Quaternion.CreateFromAxisAngle(data.Normal, rotation);
                perp = new Vector3((new Quaternion(perp, 0) * q).ToVector4());
            }

            var pos = MatrixD.CreateWorld(data.Position, data.Normal, perp);

            var size = material.MinSize;

            if (material.MaxSize > material.MinSize)
            {
                size += MyRandom.Instance.NextFloat() * (material.MaxSize - material.MinSize);
            }

            pos = Matrix.CreateScale(new Vector3(size, size, material.Depth)) * pos;

            var decalId = MyRenderProxy.CreateDecal(data.RenderObjectId, pos, material.GetStringId());

            proxy.OnAddDecal(decalId, ref data);
        }
示例#8
0
        /// <returns>True to skip the decal</returns>
        private static bool DefaultFilterProxy(IMyDecalProxy proxy)
        {
            // TODO: Evaluate it better and add the ability to customize the filter on the game.
            // For example support filtering basing genericallt on the entity, hithinfo, damage...

            // Cannon ball in ME
            string tostring = proxy.ToString();
            if (tostring != null && tostring.StartsWith("MyRopeHookBlock"))
                return true;

            return false;
        }