/// <summary>
        /// Get block.
        /// </summary>
        /// <returns> BLock3D </returns>
        private static Block3D GetBlock()
        {
            var height     = GetDoubleFromInterval();
            var baseHeight = GetDoubleFromInterval();
            var baseWidth  = GetDoubleFromInterval();
            var block      = new Block3D(height, baseHeight, baseWidth);

            return(block);
        }
Example #2
0
        public override void Add(Block3D item)
        {
            if (!_InitialRender)
            {
                Render();
            }

            base.Add(item);
        }
Example #3
0
        public override bool Remove(Block3D item)
        {
            if (!_InitialRender)
            {
                Render();
            }

            return(base.Remove(item));
        }
        /// <summary>
        /// Get block.
        /// </summary>
        /// <param name="line"> Line with info about block </param>
        /// <returns> Block3D </returns>
        private static Block3D GetBlock(string line)
        {
            var height     = double.Parse(line.Substring(14, 6));
            var baseHeight = double.Parse(line.Substring(30, 6));
            var baseWidth  = double.Parse(line.Substring(41, 6));
            var block      = new Block3D(height, baseHeight, baseWidth);

            return(block);
        }
        /// <summary>
        /// Get blocks.
        /// </summary>
        /// <param name="amount"> Amount of blocks </param>
        /// <returns> List of blocks </returns>
        private static List <Block3D> GetBlocks(int amount)
        {
            var blocks = new List <Block3D>(amount);

            for (var i = 0; i < amount; i++)
            {
                Block3D block = GetBlock();

                blocks.Add(block);
            }

            return(blocks);
        }
        private static void Main()
        {
            var sep    = Path.DirectorySeparatorChar;
            var path   = $@"..{sep}..{sep}..{sep}Blocks.txt";
            var blocks = new List <Block3D>();

            try
            {
                // Read from file.
                using (var sr = new StreamReader(new FileStream(path, FileMode.Open)))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        Block3D block = GetBlock(line);

                        blocks.Add(block);
                    }
                }

                // Print info.
                blocks.ForEach(el => PrintMessage(el + "\n"));
                blocks.Sort();
                PrintMessage("\nSorted by volume:\n\n", ConsoleColor.Yellow);
                blocks.ForEach(el => PrintMessage(el + "\n"));

                // Print to file.
                using (var sw = new StreamWriter(new FileStream(path, FileMode.Open)))
                {
                    blocks.ForEach(el => sw.WriteLine(el));
                }
            }
            catch (IOException)
            {
                PrintMessage("Problem with file!\n", ConsoleColor.Red);
            }
            catch (Exception)
            {
                PrintMessage("Unexpected error!\n", ConsoleColor.Red);
            }

            PrintMessage("\nPress ESC to exit...", ConsoleColor.Green);
            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                ;
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Random rand = new Random();

            Block3D[] bricks = new Block3D[10];
            for (int i = 0; i < 10; i++)
            {
                bricks[i] = new Block3D(rand.NextDouble() * 10, new Rectangle(rand.NextDouble() * 50 + 10, rand.NextDouble() * 10));
                Console.WriteLine(bricks[i]);
            }
            Console.WriteLine("Сортировка");
            Array.Sort(bricks);
            foreach (Block3D brick in bricks)
            {
                Console.WriteLine(brick);
            }
        }
Example #8
0
        protected override void OnInvoke(BaseAspect aspect)
        {
            if (aspect == null || aspect.Deleted)
            {
                return;
            }

            var list = ListPool <EffectQueue> .AcquireObject();

            var cw = Utility.RandomBool();

            for (int a = (cw ? 0 : 360), h = 0; (cw ? a <= 360 : a >= 0); a += (cw ? 1 : -1))
            {
                var x = (int)Math.Round(aspect.X + (aspect.RangePerception * Math.Sin(Geometry.DegreesToRadians(a))));
                var y = (int)Math.Round(aspect.Y + (aspect.RangePerception * Math.Cos(Geometry.DegreesToRadians(a))));

                if (((x * 397) ^ y) == h)
                {
                    // This location was just handled, ignore it to avoid small increments
                    continue;
                }

                h = ((x * 397) ^ y);

                var start = aspect.Clone3D(0, 0, 10);
                var end   = new Point3D(x, y, aspect.Z);

                end.Z = end.GetTopZ(aspect.Map);

                var l = start.GetLine3D(end, aspect.Map, false);

                var q = new EffectQueue
                {
                    Deferred = false,
                    Handler  = e => HandleDeathRay(aspect, e)
                };

                for (var i = 0; i < l.Length; i++)
                {
                    var p       = new Block3D(l[i], 5);
                    var blocked = i + 1 >= l.Length;

                    if (!blocked)
                    {
                        var land = aspect.Map.GetLandTile(p);

                        if (p.Intersects(land.Z, land.Height))
                        {
                            var o = TileData.LandTable[land.ID];

                            if (o.Flags.AnyFlags(_BlockingFlags))
                            {
                                blocked = true;
                            }
                        }
                    }

                    if (!blocked)
                    {
                        var tiles = aspect.Map.GetStaticTiles(p);

                        var data = tiles.Where(o => p.Intersects(o.Z, o.Height)).Select(t => TileData.ItemTable[t.ID]);

                        if (data.Any(o => o.Flags.AnyFlags(_BlockingFlags)))
                        {
                            blocked = true;
                        }
                    }

                    if (!blocked)
                    {
                        var items = p.FindItemsAt(aspect.Map);

                        var data = items.Where(p.Intersects).Select(o => TileData.ItemTable[o.ItemID]);

                        if (data.Any(o => o.Flags.AnyFlags(_BlockingFlags)))
                        {
                            blocked = true;
                        }
                    }

                    var effect = blocked ? 14120 : Utility.RandomMinMax(12320, 12324);
                    var hue    = blocked ? 0 : 2075;

                    if (blocked)
                    {
                        p = p.Clone3D(0, 0, -8);
                    }

                    q.Add(
                        new EffectInfo(p, aspect.Map, effect, hue, 10, 10, EffectRender.Darken)
                    {
                        QueueIndex = i
                    });

                    if (blocked)
                    {
                        break;
                    }
                }

                if (q.Queue.Count > 0)
                {
                    list.Add(q);
                }
            }

            if (list.Count == 0)
            {
                ObjectPool.Free(list);

                return;
            }

            for (var i = 0; i < list.Count; i++)
            {
                var cur = list[i];

                if (i + 1 < list.Count)
                {
                    var next = list[i + 1];

                    cur.Callback = () =>
                    {
                        if (aspect.Deleted || !aspect.Alive)
                        {
                            list.ForEach(q => q.Dispose());

                            ObjectPool.Free(list);

                            return;
                        }

                        if (next.Queue.Count > 0)
                        {
                            SpellHelper.Turn(aspect, next.Queue.Last().Source);
                        }

                        Timer.DelayCall(TimeSpan.FromSeconds(0.05), next.Process);
                    };
                }
                else
                {
                    cur.Callback = () =>
                    {
                        list.ForEach(q => q.Dispose());

                        ObjectPool.Free(list);

                        aspect.CantWalk      = false;
                        aspect.LockDirection = false;
                    };
                }
            }

            if (list.Count == 0)
            {
                ObjectPool.Free(list);

                return;
            }

            aspect.CantWalk      = true;
            aspect.LockDirection = true;

            if (list[0].Queue.Count > 0)
            {
                SpellHelper.Turn(aspect, list[0].Queue.Last().Source);
            }

            Timer.DelayCall(TimeSpan.FromSeconds(0.1), list[0].Process);
        }
Example #9
0
		public static Wireframe GetWireframe(this MultiComponentList mcl)
		{
			if (mcl == null)
			{
				return Wireframe.Empty;
			}

			var frame = new Block3D[mcl.List.Length];

			frame.SetAll(
				i =>
				new Block3D(
					mcl.List[i].m_OffsetX,
					mcl.List[i].m_OffsetY,
					mcl.List[i].m_OffsetZ,
					TileData.ItemTable[mcl.List[i].m_ItemID].CalcHeight + 5));

			return new Wireframe(frame);
		}
Example #10
0
		public override bool Remove(Block3D item)
		{
			if (!_InitialRender)
			{
				Render();
			}

			return base.Remove(item);
		}
Example #11
0
		public override void Add(Block3D item)
		{
			if (!_InitialRender)
			{
				Render();
			}

			base.Add(item);
		}