Ejemplo n.º 1
0
        public Cave(ref Random rnd, ref IMapHandler mh, Vector3i StartingPoint)
        {
            mMap = mh;
            rand = rnd;
            AddPoint(StartingPoint);
            // We need at least 4 points.
            int numPoints2Make = rand.Next(3, 10);
            for(int i=0;i<numPoints2Make;i++)
            {
                i++;
                AddPoint(new Vector3i(StartingPoint.X+rand.Next(-16, 16), StartingPoint.Y+rand.Next(-16, 16), StartingPoint.Z+rand.Next(-16, 16)));
            }
            Profiler profSphere = new Profiler("MakeSphere");
            Profiler profSpline = new Profiler("GetInterpolatedSplinePoint");
            int rad = rand.Next(1, 3);
            for(int p = 0;p<20;p++)
            {
                double t = (double)p/(double)(Points.Count*32);
                // Between 2/10 radius.
                profSpline.Start();
                Vector3i derp = this.GetInterpolatedSplinePoint(t);
                profSpline.Stop();

                mMap.SetBlockAt(derp.X, derp.Y, derp.Z, 0);

                profSphere.Start();
                MakeSphere(derp, rad);
                profSphere.Stop();
                //Console.WriteLine("MakeSphere r={0} @ t={1}", rad, t);
                //t += 0.05;
            }
            mMap.SaveAll();
            Console.WriteLine(profSpline.ToString());
            Console.WriteLine(profSphere.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialize and set up events for this MapChunk.
 /// </summary>
 /// <param name="mc">Parent mapcontrol</param>
 /// <param name="pos">Position of chunk</param>
 /// <param name="sz">Chunk size</param>
 public MapChunkControl(MapControl mc,Vector3i pos,Vector3i sz)
 {
     parent=mc;
     Map = parent.Map;
     AssignedChunk = pos;
     ChunkSize = sz;
     MyChunk = Map.GetChunk(AssignedChunk);
     //Console.WriteLine("{0}: Chunk ({1},{2}), origin ({3},{4}), size {5}", this, pos.X, pos.Y, pos.X * sz.X, pos.Y * sz.Y, sz);
     InitializeComponent();
     Paint += new PaintEventHandler(MapChunkControl_Paint);
 }
Ejemplo n.º 3
0
 public dlgChunk(IMapHandler m,Vector3i pos)
 {
     InitializeComponent();
     if (m == null)
     {
         MessageBox.Show("m==null");
         Environment.Exit(-1);
     }
     Map = m;
     //mcc.Map = m;
     //mcc.Render();
     //mcc.Refresh();
     ChunkPos = pos;
 }
Ejemplo n.º 4
0
 public static bool CheckForDungeonSpace(byte[,,] b, int x, int y, int z)
 {
     Vector3i pos=new Vector3i(x,y,z);
     Vector3i size = new Vector3i((DungeonSizeX+1)*2+1,(DungeonSizeY+1)*2+1,DungeonSizeZ+1);
     if (!ObjectIsInChunk(b, pos, size))
     {
         //Console.WriteLine("Object is not in chunk.");
         return false;
     }
     if (!ObjectIsCompletelyUnderground(b, pos, size))
     {
         //Console.WriteLine("Object is not underground.");
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
        private void MakeSphere(Vector3i pos, int rad)
        {
            Profiler profRead = new Profiler("Read");
            Profiler profWrite = new Profiler("Write");
            int radsq = rad ^ 2; // So we don't have to do sqrt, which is slow

            for (int x = (int)pos.X - rad; x < pos.X + rad; x++)
            {
                for (int y = (int)pos.Y - rad; y < pos.Y + rad; y++)
                {
                    for (int z = (int)pos.Z - rad; z < pos.Z + rad; z++)
                    {
                        if(y<0||y>=mMap.ChunkScale.Y-1) continue;

                        profRead.Start();
                        byte block = mMap.GetBlockAt(x,y,z);
                        profRead.Stop();
                        //byte blockabove = mMap.GetBlockAt(x,y+1,z);

                        // If water/sand/gravel, or the block above is, abort
                        if (block == 0 || block == 8 || block == 9 || block == 12 || block == 13 || block==KnownBlocks.Error)
                            continue;
                        //if (blockabove == 0 || blockabove == 8 || blockabove == 9 || blockabove == 12 || blockabove == 13)
                        //    continue;

                        int distsq = (x - (int)pos.X) ^ 2 + (y - (int)pos.Y) ^ 2 + (z - (int)pos.Z);
                        if (distsq <= radsq)
                        {
                            profWrite.Start();
                            mMap.SetBlockAt(x, y, z, 0);
                            profWrite.Stop();
                        }
                    }
                }
            }

            Console.WriteLine(profRead.ToString());
            Console.WriteLine(profWrite.ToString());
        }
Ejemplo n.º 6
0
 public static int Distance(Vector3i v1, Vector3i v2)
 {
     if (v1 == null || v2 == null) return int.MaxValue;
     int x = (int)(v1.X - v2.X);
     int y = (int)(v1.Y - v2.Y);
     int z = (int)(v1.Z - v2.Z);
     return Isqrt(x * x + y * y + z * z);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Copy the essential values of the other tree object into self.
 /// </summary>
 /// <param name="other"></param>
 public virtual void Copy(Tree other)
 {
     Pos=other.Pos;
     Height=other.Height;
 }
Ejemplo n.º 8
0
 public abstract Vector3i Local2Global(int CX, int CZ, Vector3i vector3i);
Ejemplo n.º 9
0
 public abstract void GetOverview(int CX, int CY, Vector3i pos, out int h, out byte block, out int waterdepth);
Ejemplo n.º 10
0
 void MapChunkControl_Paint(object sender, PaintEventArgs e)
 {
     Graphics g = e.Graphics;
     if (parent == null)
     {
         g.FillRectangle(Brushes.Blue, 0, 0, Width - 1, Height - 1);
         g.DrawString("[ NO PARENT! ]", new Font(FontFamily.GenericSansSerif, 7), Brushes.White, 2, 2);
         return;
     }
     if (MyChunk == null)
     {
         g.FillRectangle(new SolidBrush(Blocks.GetColor(9)), 0, 0, Width - 1, Height - 1);
         g.DrawString("[ Missing Chunk ]", new Font(FontFamily.GenericSansSerif, 7), Brushes.White, 2, 2);
         return;
     }
     if (bmp != null/* && LastPos==parent.CurrentPosition*/)
         g.DrawImage(bmp, 0, 0, Width, Height);
     else
     {
         g.FillRectangle(Brushes.Maroon, 0, 0, Width-1, Height-1);
         g.DrawString("[ Loading ]", new Font(FontFamily.GenericSansSerif, 7), Brushes.White, 2, 2);
         Render();
     }
     if(parent!=null)
         LastPos = parent.CurrentPosition;
 }
Ejemplo n.º 11
0
		public void GetOverview(int CX,int CY,Vector3i pos, out int h, out byte block, out int waterdepth)
		{
			h = 0;
			block = 0;
			waterdepth = 0;

			int x = (int)pos.X;
			int y = (int)pos.Y;
			//int z = (int)pos.Z;// % ChunkZ;
			string ci = string.Format("{0},{1}", CX, CY);

			for (int z = (int)pos.Z; z > 0; --z)
			{
				byte b = GetBlockIn(CX,CY,new Vector3i(x, y, z));
				if (b == 8 || b == 9 || b == 52)
				{
					waterdepth++;
					continue;
				}
				if (b != 0)
				{
					block=b;
					h = z;
					return;
				}
			}
		}
Ejemplo n.º 12
0
		public Chunk GetChunk(Vector3i chunkpos)
		{
			return GetChunk(chunkpos.X, chunkpos.Y);
		}
Ejemplo n.º 13
0
		public void SetBlockAt(Vector3i p, byte id)
		{
			//Console.WriteLine("{0}", p);
			int CX = (int)p.X >> 4;// / (long)ChunkX);
			int CZ = (int)p.Y >> 4;// / (long)ChunkY);

			int x = ((int)p.Y % ChunkX) & 0xf;
			int y = ((int)p.X % ChunkY) & 0xf;
			int z = (int)p.Z;// % ChunkZ;

			if (
				!Check(x, -1, ChunkX) ||
				!Check(y, -1, ChunkY) ||
				!Check(z, -1, ChunkZ))
			{
				//Console.WriteLine("<{0},{1},{2}> out of bounds", x, y, z);
				return;
			}
			string ci = string.Format("{0},{1}", CX, CZ);
			if (!mChunks.ContainsKey(ci))
				return;
			Chunk c = mChunks[ci];
			c.Blocks[x,y,z]=id;
			mChunks[ci] = c;
			if (!mChangedChunks.Contains(ci))
			{
				mChangedChunks.Add(ci);
				Console.WriteLine(ci+" has changed");
			}
		}
Ejemplo n.º 14
0
		public void SetBlockIn(long CX, long CY, Vector3i pos, byte type)
		{
			pos = new Vector3i(pos.Y, pos.X, pos.Z);
			// block saving to any negative chunk due to being unreadable.
			if (CX < 0 || CY < 0) return;

			string ci = string.Format("{0},{1}", CX, CY);
			//try
			//{
			if (mChunks.ContainsKey(ci))
			{
				mChunks[ci].Blocks[(int)pos.X,(int)pos.Y,(int)pos.Z] = type;
				return;
			}
			// Don't mess with unloaded blocks.
		}
Ejemplo n.º 15
0
 public void SetBlock(Vector3i bp, byte p)
 {
     Blocks[bp.X, bp.Y, bp.Z] = p;
 }
Ejemplo n.º 16
0
 public byte GetBlock(Vector3i bp)
 {
     return(Blocks[bp.X, bp.Y, bp.Z]);
 }
Ejemplo n.º 17
0
 public Tree(long x, long y, long z, int h)
 {
     Pos    = new Vector3i(x, y, z);
     Height = h;
 }
Ejemplo n.º 18
0
		public Vector3i GetMousePos(Vector3i mp, int scale, ViewAngle angle)
		{
			Vector3i p = new Vector3i(0,0,0);
			switch(angle)
			{
				case ViewAngle.FrontSlice:
					p.X = mp.X / scale;
					p.Y = ChunkY-(mp.Y / scale);
					p.Z = mp.Z;
					break;
				case ViewAngle.TopDown:
					p.X = mp.X/scale;
					p.Y = mp.Y/scale;
					p.Z = mp.Z; // wut 
					break;
				case ViewAngle.SideSlice:
					p.X=mp.Z;
					p.Y=mp.Y/scale;
					p.Z=mp.X/scale;
					break;
			}
			return p;
		}
Ejemplo n.º 19
0
 /// <summary>
 /// Try to find a block in this direction.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="direction"></param>
 /// <param name="matFilter"></param>
 /// <param name="invert"></param>
 /// <returns></returns>
 public byte CastRay(Vector3i from, Vector3i direction, List<byte> matFilter, bool invert, out int iterations)
 {
     invert =!invert;
     Vector3i curcord = from + .5;
     iterations = 0;
     byte mat = 0;
     while (
         curcord.X > 0 && curcord.Y > 0 && curcord.Z > 0 &&
         curcord.X < ChunkScale.X && curcord.Y < ChunkScale.Y && curcord.Z < ChunkScale.Z)
     {
         mat = GetBlockAt(curcord.X, curcord.Y, curcord.Z);
         if (matFilter.Contains(mat) && invert == false) break;
         else if (!matFilter.Contains(mat) && invert) break;
         else
         {
             curcord = curcord + direction;
             iterations++;
         }
     }
     return mat;
 }
Ejemplo n.º 20
0
        public void Render()
        {
            //Console.WriteLine("[MapChunkControl::Render()] Rendering chunk ({0},{1})...", AssignedChunk.X, AssignedChunk.Y);
            if (Drawing)
            {
                Console.WriteLine("Drawing, aborting render.");
                return;
            }
            if (Map == null)
            {
                Console.WriteLine("parent.Map = null");
                return;
            }
            if (MyChunk == null)
            {
                Console.WriteLine("MyChunk = null");
                return;
            }
            Drawing = true;
            int w = Width;
            int h = Height;
            //if (lh == h && lw == w && ly==parent.CurrentPosition.Z) return;
            if (w == 0 || h == 0)
                return;
            bmp = new Bitmap(w, h);
            bool DrawSquares=true;
            if(parent!=null)
                DrawSquares=(parent.ViewingAngle == ViewAngle.TopDown);
            Graphics g = Graphics.FromImage((Image)bmp);
            // No AA.  We WANT pixels :V
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            // Chunk        1,1
            // ChunkSZ      16,16
            // ChunkCoords  16,16
            int z = 128;
            int zoom = 8;
            Color wc = Blocks.GetColor(9);
            if (parent != null)
            {
                z = (int)parent.CurrentPosition.Z;
                if (z > MyChunk.Size.Z - 1)
                    z = (int)MyChunk.Size.Z - 1;
                if (z < 0)
                    z = 0;
                zoom = parent.ZoomLevel;
            }
            for (int x = 0; x < Map.ChunkScale.X; x++)
            {
                for (int y = 0; y < Map.ChunkScale.Y; y++)
                {
                    Vector3i blockpos = new Vector3i(x, y, z);

                    byte block = MyChunk.Blocks[x,y,z];

                    int waterdepth = 0;
                    int bh = 0;
                    Color c = Blocks.GetColor(block);
                    Color shadow = Color.Transparent;
                    if (block == 0)
                    {
                        Vector3i bp = blockpos;
                        //bp.X += Map.CurrentPosition.X + (x >> 4);
                        //bp.Y += Map.CurrentPosition.Y + (y >> 4);
                        // Console.WriteLine("hurr air");

                        // BROKEN for some reason (?!)
                        MyChunk.GetOverview(blockpos, out bh, out block, out waterdepth);

                        c = Blocks.GetColor(block);
                        // Water translucency
                        if (waterdepth > 0)
                        {
                            if (waterdepth > 15)
                                waterdepth = 15;
                            float pct = ((float)waterdepth / 15f) * 100f;
                            c = Color.FromArgb(
                                Utils.Lerp(c.R, wc.R, (int)pct),
                                Utils.Lerp(c.G, wc.G, (int)pct),
                                Utils.Lerp(c.B, wc.B, (int)pct));
                        }

                        // Height (TODO: Replace with lighting?)
                        // 128-50 =
                        bh = (int)parent.CurrentPosition.Z - bh;
                        if (bh > 0)
                        {
                            //if (bh > 5)
                            //    bh = 5;
                            float pct = ((float)bh / 128f) * 100f;
                            //shadow = Color.FromArgb((int)pct, Color.Black);
                            c = Color.FromArgb(
                                Utils.Lerp(c.R, 0, (int)pct),
                                Utils.Lerp(c.G, 0, (int)pct),
                                Utils.Lerp(c.B, 0, (int)pct));
                            //Console.WriteLine("{0}h = {1}% opacity shadow",bh,pct);
                        }
                    }
                    Vector3i bgpos = new Vector3i(
                        x + (AssignedChunk.X * Map.ChunkScale.X),
                        y + (AssignedChunk.Y * Map.ChunkScale.Y),
                        z
                    );
                    if (parent != null)
                    {
                        Color selcol = Color.Orange;
                        int points = 0;
                        if (bgpos.X == parent.SelectedVoxel.X) points++;
                        if (bgpos.Y == parent.SelectedVoxel.Y) points++;
                        if(points>0)
                        {
                            float pct = ((float)points / 3f) * 100f;
                            c = Color.FromArgb(
                                Utils.Lerp(c.R, selcol.R, (int)pct),
                                Utils.Lerp(c.G, selcol.G, (int)pct),
                                Utils.Lerp(c.B, selcol.B, (int)pct));
                        }
                    }
                    g.FillRectangle(new SolidBrush(c), x * zoom, y * zoom, zoom, zoom);
                    //g.FillRectangle(new SolidBrush(shadow), x * zoom, y * zoom, zoom, zoom);
                    //g.DrawString(bh.ToString(), new Font(FontFamily.GenericSansSerif, 5), Brushes.Blue, new PointF((float)(x * zoom), (float)(y * zoom)));
                    if (Settings.ShowWaterDepth && waterdepth > 0)
                        g.DrawString(waterdepth.ToString(), new Font(FontFamily.GenericSansSerif, 5), Brushes.Blue, new PointF((float)(x * zoom), (float)(y * zoom)));
                    if (Settings.ShowGridLines)
                    {
                        if (parent != null && bgpos == parent.SelectedVoxel)
                            g.DrawRectangle(new Pen(Color.Orange), x * zoom, y * zoom, zoom, zoom);
                        else
                            g.DrawRectangle(new Pen(Color.Black), x * zoom, y * zoom, zoom, zoom);
                    }
                }
            }
            Pen fp = new Pen(Color.Black);
            if (Settings.ShowChunks)
            {
                long ox = AssignedChunk.X * (int)zoom;
                long oz = AssignedChunk.Y * (int)zoom;
                int chunksz = (16 * zoom);
                Font f = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
                for (int x = 0; x < w / 2; x++)
                {
                    if (DrawSquares)
                    {
                        DrawCross(ref g, Pens.Black, 1, 1);
                        DrawCross(ref g, Pens.White, 0, 0);
                        g.DrawString(string.Format("Chunk {0},{1}", AssignedChunk.X, AssignedChunk.Y), f, Brushes.Black, 2, 2);
                        g.DrawString(string.Format("Chunk {0},{1}", AssignedChunk.X, AssignedChunk.Y), f, Brushes.White, 1, 1);
                    }
                    else
                    {
                        g.DrawRectangle(fp, 0, 0, Map.ChunkScale.X * zoom, Map.ChunkScale.Y * zoom);
                        g.DrawString(string.Format("Chunk {0},{1}", AssignedChunk.X, AssignedChunk.Y), f, Brushes.Black, 2, 2);
                        g.DrawString(string.Format("Chunk {0},{1}", AssignedChunk.X, AssignedChunk.Y), f, Brushes.White, 1, 1);
                    }
                }

                /// F*****G ENTITIES HURRRRRRRRRRRRR ////////////////////////////////
                foreach (KeyValuePair<Guid, PictureBox> p in EntityButtons)
                {
                    p.Value.MouseDown += new MouseEventHandler(EntityMouseDown);
                    Controls.Remove(p.Value);
                    p.Value.Dispose();
                }
                EntityButtons.Clear();
                foreach (KeyValuePair<Guid, Entity> k in MyChunk.Entities)
                {
                    if (
                        k.Value.Pos.X > (AssignedChunk.X * 16) &&
                        k.Value.Pos.X < (AssignedChunk.X * 16) + 16 &&
                        k.Value.Pos.Y > (AssignedChunk.Y * 16) &&
                        k.Value.Pos.Y < (AssignedChunk.Y * 16) + 16)
                    {
                        float x = (float)(k.Value.Pos.X - ((double)MyChunk.Position.X * (double)MyChunk.Size.X));
                        float y = (float)(k.Value.Pos.Y - ((double)MyChunk.Position.Y * (double)MyChunk.Size.Y));
                        x *= parent.ZoomLevel;
                        y *= parent.ZoomLevel;
                        if ((int)k.Value.Pos.Z != parent.CurrentPosition.Z)
                        {
                            g.DrawImage(Fade(k.Value.Image), new RectangleF(x, y, 16, 16));
                            if ((int)k.Value.Pos.Z > parent.CurrentPosition.Z)
                            {
                                g.DrawString("^", f, Brushes.Black, x + 1f, y + 1f);
                                g.DrawString("^", f, Brushes.White, x, y);
                            }
                            else
                            {
                                g.DrawString("v", f, Brushes.Black, x + 1f, y + 1f);
                                g.DrawString("v", f, Brushes.White, x, y);
                            }
                        }
                        else
                        {
                            Guid lol = k.Key;
                            EntityButtons.Add(lol, new PictureBox());
                            EntityButtons[lol].Tag = lol;
                            EntityButtons[lol].Image = k.Value.Image;
                            EntityButtons[lol].BackColor = Color.Transparent;
                            EntityButtons[lol].MouseDown += new MouseEventHandler(EntityMouseDown);
                            EntityButtons[lol].ContextMenu = new ContextMenu(new MenuItem[]{
                                new MenuItem("Entity Editor...",delegate(object s,EventArgs e){
                                    if (parent != null)
                                        parent.SelectEntity(lol);
                                }),
                                new MenuItem("Delete",delegate(object s,EventArgs e){
                                    if (parent != null)
                                        parent.Map.RemoveEntity(parent.Map.Entities[lol]);
                                })
                            });
                            EntityButtons[lol].MouseHover += new EventHandler(EntityHover);
                            EntityButtons[lol].SetBounds((int)x, (int)y, 16, 16);
                            Controls.Add(EntityButtons[lol]);
                        }
                    }
                }

                /// F*****G TILEENTITIES HURRRRRRRRRRRRR ////////////////////////////////
                foreach (KeyValuePair<Guid, PictureBox> p in TileEntityButtons)
                {
                    p.Value.MouseDown += new MouseEventHandler(TileEntityMouseDown);
                    Controls.Remove(p.Value);
                    p.Value.Dispose();
                }
                TileEntityButtons.Clear();
                foreach (KeyValuePair<Guid, TileEntity> k in MyChunk.TileEntities)
                {
                    if (
                        k.Value.Pos.X > (AssignedChunk.X * 16) &&
                        k.Value.Pos.X < (AssignedChunk.X * 16) + 16 &&
                        k.Value.Pos.Y > (AssignedChunk.Y * 16) &&
                        k.Value.Pos.Y < (AssignedChunk.Y * 16) + 16)
                    {
                        float x = (float)(k.Value.Pos.X - ((double)MyChunk.Position.X * (double)MyChunk.Size.X));
                        float y = (float)(k.Value.Pos.Y - ((double)MyChunk.Position.Y * (double)MyChunk.Size.Y));
                        x *= parent.ZoomLevel;
                        y *= parent.ZoomLevel;
                        if ((int)k.Value.Pos.Z != parent.CurrentPosition.Z)
                        {
                            g.DrawImage(Fade(k.Value.Image), new RectangleF(x, y, 16, 16));
                            if ((int)k.Value.Pos.Z > parent.CurrentPosition.Z)
                            {
                                g.DrawString("^", f, Brushes.Black, x + 1f, y + 1f);
                                g.DrawString("^", f, Brushes.White, x, y);
                            }
                            else
                            {
                                g.DrawString("v", f, Brushes.Black, x + 1f, y + 1f);
                                g.DrawString("v", f, Brushes.White, x, y);
                            }
                        }
                        else
                        {
                            Guid lol = k.Key;
                            TileEntityButtons.Add(lol, new PictureBox());
                            TileEntityButtons[lol].Tag = lol;
                            TileEntityButtons[lol].Image = k.Value.Image;
                            TileEntityButtons[lol].BackColor = Color.Transparent;
                            TileEntityButtons[lol].MouseDown += new MouseEventHandler(TileEntityMouseDown);
                            TileEntityButtons[lol].ContextMenu = new ContextMenu(new MenuItem[]{
                                new MenuItem("TileEntity Editor...",delegate(object s,EventArgs e){
                                    if (parent != null)
                                        parent.SelectTileEntity(lol);
                                }),
                                new MenuItem("Delete",delegate(object s,EventArgs e){
                                    if (parent != null)
                                        parent.Map.RemoveEntity(parent.Map.Entities[lol]);
                                })
                            });
                            TileEntityButtons[lol].MouseHover += new EventHandler(TileEntityHover);
                            TileEntityButtons[lol].SetBounds((int)x, (int)y, 16, 16);
                            Controls.Add(TileEntityButtons[lol]);
                        }
                    }
                }
            }
            Drawing = false;
        }
Ejemplo n.º 21
0
 public abstract Chunk GetChunk(Vector3i ChunkPos);
Ejemplo n.º 22
0
 void ChunkRightClicked(object sender, MouseEventArgs e)
 {
     MapChunkControl mcc = (MapChunkControl)sender;
     SelectedVoxel = new Vector3i(
         CurrentPosition.X + (e.X / _ZoomLevel) + (mcc.AssignedChunk.X * _Map.ChunkScale.X),
         CurrentPosition.Y + (e.Y / _ZoomLevel) + (mcc.AssignedChunk.Y * _Map.ChunkScale.Y),
         CurrentPosition.Z);
     if (e.Button == MouseButtons.Left)
     {
         Vector3i bp = new Vector3i(e.X/ZoomLevel,e.Y/ZoomLevel,CurrentPosition.Z);
         Chunk c = _Map.GetChunk(mcc.AssignedChunk.X,mcc.AssignedChunk.Y);
         if (c == null) return;
         c.Blocks[bp.X,bp.Y,bp.Z] =CurrentMaterial;
         c.Save();
     }
     if (e.Button == MouseButtons.Right)
     {
         Vector3i bp = new Vector3i(e.X/ZoomLevel,e.Y/ZoomLevel,CurrentPosition.Z);
         Chunk c = _Map.GetChunk(mcc.AssignedChunk);
         Block b = Blocks.Get(0);
         if (c != null)
         {
             byte bid = c.GetBlock(bp);
             b = Blocks.Get(bid);
         }
         ContextMenu cmnu = new System.Windows.Forms.ContextMenu();
         cmnu.MenuItems.AddRange(new MenuItem[]{
             new MenuItem("What's this?",new EventHandler(delegate(object s,EventArgs ea){
                 MessageBox.Show("That is a(n) " + b.ToString() + " block.");
             })),
             new MenuItem("Remove this.",new EventHandler(delegate(object s,EventArgs ea){
                 c.SetBlock(bp,0x00);
                 mcc.Render();
                 mcc.Refresh();
             })),
             new MenuItem("-"),
             new MenuItem("Replace..."),//,new EventHandler(delegate(object s,EventArgs ea){})),
             new MenuItem("Paint..."),//,new EventHandler(delegate(object s,EventArgs ea){})),
             new MenuItem("Generate...",new EventHandler(delegate(object s,EventArgs ea){
                 int fa;
                 Map.Generate(Map, mcc.AssignedChunk.X,mcc.AssignedChunk.Y);
                 Map.LoadChunk(mcc.AssignedChunk.X, mcc.AssignedChunk.Y);
                 mcc.Render();
                 mcc.Refresh();
             })),
             new MenuItem("-"),
             new MenuItem("Delete Chunk...",new EventHandler(delegate(object s,EventArgs ea){
                 Map.LoadChunk(mcc.AssignedChunk.X, mcc.AssignedChunk.Y);
                 c.Delete();
                 mcc.Render();
                 mcc.Refresh();
             })),
             new MenuItem("Refresh",new EventHandler(delegate(object s,EventArgs ea){
                 mcc.Render();
                 mcc.Refresh();
             })),
             new MenuItem("Chunk Properties...",new EventHandler(delegate(object s,EventArgs ea){
                 dlgChunk chunkdlg = new dlgChunk(_Map, mcc.AssignedChunk);
                 chunkdlg.ShowDialog();
             })),
         });
         cmnu.Show(mcc, new Point(0, 0));
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Copy the essential values of the other tree object into self.
 /// </summary>
 /// <param name="other"></param>
 public virtual void Copy(Tree other)
 {
     Pos    = other.Pos;
     Height = other.Height;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// travel from cord along vec and return how far it was to a point of matidx
 ///
 ///the distance is returned in number of iterations.  If the edge of the map
 ///is reached, then return the number of iterations as well.
 ///if invert == True, search for anything other than matidx
 /// </summary>
 /// <param name="cord"></param>
 /// <param name="vec"></param>
 /// <param name="matidx"></param>
 /// <param name="invert"></param>
 /// <returns></returns>
 public double DistanceToMaterial(Vector3i cord, Vector3i vec, byte matidx, bool invert = false)
 {
     Vector3i curcord = cord + .5;
     int iterations = 0;
     while (curcord.Y > 0 && curcord.Y < ChunkScale.Y)
     {
         byte mat = GetBlockAt(curcord.X, curcord.Y, curcord.Z);
         if (mat == matidx && invert == false) break;
         else if (mat != matidx && invert) break;
         else
         {
             curcord = curcord + vec;
             iterations++;
         }
     }
     return iterations;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Perform map layout stuff.
        /// </summary>
        void DoLayout()
        {
            if (InvokeRequired)
            {
                Invoke(new LayoutDelegate(DoLayout));
                return;
            }
            if(_Map==null) return;

            Vector3i Sides = new Vector3i(_Map.ChunkScale.X * ZoomLevel, _Map.ChunkScale.Y * ZoomLevel, _Map.ChunkScale.Z * ZoomLevel);
            Vector3i min = new Vector3i(CurrentPosition.X - ((Width / 2) / ZoomLevel), CurrentPosition.Y - ((Height / 2) / ZoomLevel), 0);
            Vector3i max = new Vector3i(CurrentPosition.X + ((Width / 2) / ZoomLevel), CurrentPosition.Y + ((Height / 2) / ZoomLevel), 0);

            min.X = Math.Max(min.X, _Map.MapMin.X);
            max.X = Math.Min(max.X, _Map.MapMax.X);

            min.Y = Math.Max(min.Y, _Map.MapMin.Y);
            max.Y = Math.Min(max.Y, _Map.MapMax.Y);

            min.Z = Math.Max(min.Z, _Map.MapMin.Z);
            max.Z = Math.Min(max.Z, _Map.MapMax.Z);

            //Console.WriteLine("DoLayout(): {0} - {1}", min, max);
            foreach (KeyValuePair<Vector3i, MapChunkControl> k in Chunks)
            {
                Controls.Remove(k.Value);
            }
            Chunks.Clear();

            foreach (Button b in EntityControls)
            {
                Controls.Remove(b);
            }
            EntityControls.Clear();

            switch (ViewingAngle)
            {
                case ViewAngle.FrontSlice:  // Slice N-S?
                    LayoutXY(Sides, min, max);
                    break;
                case ViewAngle.TopDown: // Top Down
                    LayoutTopdown(Sides, min, max);
                    break;
                case ViewAngle.SideSlice: // Slice E-W?
                    LayoutYZ(Sides, min, max);
                    break;
            }
            LayoutControls();
            foreach (KeyValuePair<Vector3i, MapChunkControl> chunk in Chunks)
            {
                chunk.Value.Refresh();
            }
            Refresh();
        }
Ejemplo n.º 26
0
 public abstract Vector3i GetMousePos(Vector3i p, int scale, ViewAngle viewAngle);
Ejemplo n.º 27
0
 /// <summary>
 /// Only version that works correctly atm.
 /// </summary>
 /// <param name="Sides"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 private void LayoutTopdown(Vector3i Sides, Vector3i min, Vector3i max)
 {
     for (int x = 0; x < Width/Sides.X; x++)
     {
         for (int y = 0; y <Height/Sides.Y; y++)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X),y + (CurrentPosition.Y / _Map.ChunkScale.Y), (min.Y / _Map.ChunkScale.Z));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.MouseClick += new MouseEventHandler(ChunkRightClicked);
                 mcc.SendToBack();
                 mcc.SetBounds((int)(x * _Map.ChunkScale.X)*ZoomLevel+6, (int)(y * _Map.ChunkScale.Y)*ZoomLevel+6, (int)(_Map.ChunkScale.X)*ZoomLevel, (int)(_Map.ChunkScale.Y)*ZoomLevel);
                 //Console.WriteLine("Added chunk to {0},{1}", mcc.Top, mcc.Left);
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(x * _Map.ChunkScale.X) * ZoomLevel+6, (int)(y * _Map.ChunkScale.Y) * ZoomLevel+6, (int)(_Map.ChunkScale.X) * ZoomLevel, (int)(_Map.ChunkScale.Y) * ZoomLevel);
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
         }
     }
     /*
     foreach (KeyValuePair<Guid, Entity> k in _Map.Entities)
     {
         Entity e = k.Value;
         if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
         {
             Button b = new Button();
             float x = (float)e.Pos.X + (float)min.X;
             float y = (float)e.Pos.Y + (float)min.Y;
             //b.SetBounds((int)y * ZoomLevel - 2, (int)y * ZoomLevel - 2, 16, 16);
             b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel, (int)(e.Pos.Y - min.Y) * ZoomLevel, 16, 16);
             b.Image = e.Image;
             b.UseVisualStyleBackColor = true;
             b.BackColor = Color.Transparent;
             b.FlatStyle = FlatStyle.Flat;
             b.ImageAlign = ContentAlignment.MiddleCenter;
             b.FlatAppearance.BorderSize = 1;
             b.FlatAppearance.BorderColor = Color.Black;
             b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             b.Click += new EventHandler(OnEntityClicked);
             b.Tag = e;
             Controls.Add(b);
             EntityControls.Add(b);
             b.Show();
             b.BringToFront();
             Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
         }
     }
     foreach (KeyValuePair<Guid, TileEntity> k in _Map.TileEntities)
     {
         TileEntity e = k.Value;
         if (e.Pos.X > min.X && e.Pos.X < max.X && e.Pos.Y > min.Y && e.Pos.Y < max.Y)
         {
             Button b = new Button();
             b.SetBounds((int)(e.Pos.X - min.X) * ZoomLevel + 6, (int)(e.Pos.Y - min.Y) * ZoomLevel + 6, 16, 16);
             b.Image = e.Image;
             b.UseVisualStyleBackColor = true;
             b.BackColor = Color.Transparent;
             b.FlatStyle = FlatStyle.Flat;
             b.ImageAlign = ContentAlignment.MiddleCenter;
             b.FlatAppearance.BorderSize = 1;
             b.FlatAppearance.BorderColor = Color.Black;
             b.FlatAppearance.MouseOverBackColor = Color.Transparent;
             b.Click += new EventHandler(OnTileEntityClicked);
             b.Tag = e;
             Controls.Add(b);
             EntityControls.Add(b);
             b.Show();
             b.BringToFront();
             Console.WriteLine("{0} {1} added to pos {2},{3}", e, e.UUID, b.Top, b.Left);
         }
     }*/
 }
Ejemplo n.º 28
0
 public abstract Vector3i Global2Local(Vector3i global, out int CX, out int CZ);
Ejemplo n.º 29
0
 private void LayoutXY(Vector3i Sides, Vector3i min, Vector3i max)
 {
     for (int x = 0; x < (Width/Sides.X); x++)
     {
         for (int y = 0; y < (Height/Sides.Y); y++)
         {
             Vector3i cc = new Vector3i(x + (min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(cc.X * _Map.ChunkScale.X), (int)(cc.Y * _Map.ChunkScale.Y), (int)(_Map.ChunkScale.X), (int)(_Map.ChunkScale.Y));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
         }
     }
 }
Ejemplo n.º 30
0
 public Tree(long x, long y, long z, int h)
 {
     Pos = new Vector3i(x, y, z);
     Height=h;
 }
Ejemplo n.º 31
0
 private void LayoutYZ(Vector3i Sides, Vector3i min, Vector3i max)
 {
     Console.WriteLine("long y = {0}; y < {1}; y += {2}", min.Y / Sides.Y, max.Y / Sides.Y, _Map.ChunkScale.Y / Sides.Y);
     for (long y = min.Y / Sides.Y; y < max.Y / Sides.Y; y += _Map.ChunkScale.Y / Sides.Y)
     {
         for (long x = min.X / Sides.X; x < max.X / Sides.X; x += _Map.ChunkScale.X/Sides.X)
         {
             Vector3i cc = new Vector3i(x+(min.X / _Map.ChunkScale.X), y + (min.Y / _Map.ChunkScale.Y), (CurrentPosition.Z / _Map.ChunkScale.X));
             if (!Chunks.ContainsKey(cc))
             {
                 MapChunkControl mcc = new MapChunkControl(this, cc, _Map.ChunkScale);
                 mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y)+6, (int)(cc.Z * _Map.ChunkScale.Z)+6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);
             }
             else
             {
                 /*
                 MapChunkControl mcc = Chunks[cc];
                 mcc.SetBounds((int)(cc.Y * _Map.ChunkScale.Y)+6, (int)(cc.Z * _Map.ChunkScale.Z)+6, (int)(_Map.ChunkScale.Y), (int)(_Map.ChunkScale.Z));
                 Controls.Add(mcc);
                 Chunks.Add(cc, mcc);*/
             }
         }
     }
 }
Ejemplo n.º 32
0
        private void generateTerrainToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild != null)
            {
                if ((ActiveMdiChild as frmMap).Map != null)
                {
                    dlgTerrainGen terragen = new dlgTerrainGen((ActiveMdiChild as frmMap).Map);
                    if(terragen.ShowDialog() == DialogResult.Cancel)
                    {
                        ResetStatus();
                        return;
                    }
                    DialogResult dr = MessageBox.Show("This could DELETE EVERYTHING. ARE YOU SURE?", "ARE YOU NUTS", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.No)
                    {
                        ResetStatus();
                        return;
                    }
                    IMapGenerator mg = (IMapGenerator)terragen.pgMapGen.SelectedObject;

                    (ActiveMdiChild as frmMap).Map.Generator = mg;
                    dlgLongTask dlt = new dlgLongTask();
                    dlt.Start(delegate()
                    {
                        // ACTIVATE AUTOREPAIR
                        (ActiveMdiChild as frmMap).Map.Autorepair = true;

                        /////////////////////////////////////////////////////////////////
                        // UI Stuff
                        /////////////////////////////////////////////////////////////////
                        dlt.SetMarquees(true, true);
                        dlt.VocabSubtask = "chunk";
                        dlt.VocabSubtasks = "chunks";
                        dlt.Title = "Generating chunks.";
                        dlt.Subtitle = "This will take a while.  Go take a break.";
                        dlt.SetMarquees(false, false);
                        dlt.CurrentTask = "Replacing stuff in chunks...";
                        dlt.TasksComplete = 0;
                        dlt.TasksTotal = 1;
                        dlt.SubtasksTotal = 1;

                        int numchunks = 0;
                        // Generate terrain
                        // Drop soil
                        // Add pbarriers
                        // Add dungeons
                        // Add trees
                        // Fix fluids
                        // Fix lava

                        int stage = 0;
                        int numstages = 1;
                        ForEachProgressHandler feph = new ForEachProgressHandler(delegate(int Total, int Progress)
                        {
                            numchunks = Total;
                            dlt.TasksTotal = numchunks * numstages;
                            dlt.TasksComplete = Progress + (stage * numchunks);
                            dlt.SubtasksComplete = Progress;
                            dlt.SubtasksTotal = Total;
                        });
                        ForEachProgressHandler fl_feph = new ForEachProgressHandler(delegate(int Total, int Progress)
                        {
                            numchunks = Total;
                            dlt.TasksTotal = numchunks * numstages;
                            dlt.TasksComplete = Progress + (stage * numchunks);
                            dlt.SubtasksComplete = Progress;
                            dlt.SubtasksTotal = Total;

                            dlt.perfChart.AddValue((ActiveMdiChild as frmMap).Map.ChunksLoaded);
                        });

                        Vector3i Max = new Vector3i(0,0,0);
                        Vector3i Min = new Vector3i(int.MaxValue, int.MaxValue, int.MaxValue);
                        dlt.CurrentTask = "Determining map scale...";
                        (ActiveMdiChild as frmMap).Map.ForEachProgress += feph;
                        dlt.ShowPerfChart(true);
                        dlt.perfChart.Clear();
                        dlt.perfChart.ScaleMode = SpPerfChart.ScaleMode.Relative;
                        (ActiveMdiChild as frmMap).Map.ForEachChunk(delegate(IMapHandler _mh, long X, long Z)
                        {
                            if (Min.X > X) Min.X = X;
                            if (Max.X < X) Max.X = X;
                            if (Min.Z > Z) Min.Z = Z;
                            if (Max.Z < Z) Max.Z = Z;
                            dlt.CurrentSubtask = string.Format("Map Scale: ({0},{1})", Max.X - Min.X, Max.Z - Min.Z);
                            _mh.SaveAll();
                        });

                        (ActiveMdiChild as frmMap).Map.Cache.Enabled = false;

                        int total = (int)((Max.X - Min.X) * (Max.Z - Min.Z));
                        int completed = 0;
                        (ActiveMdiChild as frmMap).Map.ForEachKnownChunk(0,delegate(IMapHandler _mh, long X, long Z)
                        {
                            if (dlt.STOP) return;
                            dlt.CurrentSubtask = string.Format("Generating chunk ({0},{1})", X, Z);
                            double min, max;
                            (ActiveMdiChild as frmMap).Map.Generate(X, Z, out min, out max);
                            dlt.grpPerformance.Text = string.Format("Terrain Profile [{0},{1}]m", (int)(min * 100), (int)(max * 100));
                            dlt.perfChart.AddValue((decimal)max);
                            feph(total, completed++);
                        });

                        if ((ActiveMdiChild as frmMap).Map.Generator.GenerateCaves)
                        {
                            dlt.CurrentTask = "Generating caves...";
                            dlt.grpPerformance.Text = "Generation time (ms)";
                            Random rand = new Random((int)(ActiveMdiChild as frmMap).Map.RandomSeed);
                            Profiler profCaves = new Profiler("Cave");
                            (ActiveMdiChild as frmMap).Map.ForEachKnownChunk(0, delegate(IMapHandler _mh, long X, long Z)
                            {
                                if (dlt.STOP) return;
                                dlt.CurrentSubtask = string.Format("Generating caves in chunk ({0},{1})", X, Z);
                                if (rand.Next(3) != 0)
                                {
                                    int xo = (int)(X * _mh.ChunkScale.X);
                                    int zo = (int)(Z * _mh.ChunkScale.Z);
                                    int x = rand.Next((int)_mh.ChunkScale.X - 1);
                                    int z = rand.Next((int)_mh.ChunkScale.Z - 1);
                                    int y = rand.Next((int)(_mh.GetHeightAt(x, z) * 127) + 5);
                                    profCaves.Start();
                                    new Cave(ref rand, ref _mh, new Vector3i(x + xo, y, z + zo));
                                    Console.WriteLine("LOLDONE");
                                    dlt.perfChart.AddValue(profCaves.Stop());
                                    feph(total, completed++);
                                }
                            });
                        }
                        completed = 0;
                        /*
                        Profiler profTrees = new Profiler("Trees");
                        for (int X = (int)Min.X; X < Max.X + 1; X++)
                        {
                            for (int Z = (int)Min.Z; Z < Max.Z + 1; Z++)
                            {
                                profTrees.Start();
                                if (dlt.STOP) return;
                                dlt.CurrentSubtask = string.Format("Adding trees to chunk ({0},{1})", X, Z);
                                (ActiveMdiChild as frmMap).Map.Populate(X, Z);
                                dlt.grpPerformance.Text = "Performance";
                                profTrees.Stop();
                                dlt.perfChart.AddValue(profTrees.Stop());
                                feph(total, completed++);
                            }
                        }
                        */
                        /*
                        stage++;
                        dlt.CurrentTask = "Eroding chunk surfaces...";
                        (ActiveMdiChild as frmMap).Map.ForEachProgress += feph;
                        (ActiveMdiChild as frmMap).Map.ForEachChunk(delegate(IMapHandler _mh, long X, long Y)
                        {
                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, thermal)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.ErodeThermal(5, 10, (int)X, (int)Y);

                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, hydraulic)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.Erode(5, 10, (int)X, (int)Y);

                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, silt)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.Silt(63,true, (int)X, (int)Y);

                            dlt.grpPerformance.Text = string.Format("Chunks in-memory ({0})", _mh.ChunksLoaded);
                            dlt.perfChart.AddValue(_mh.ChunksLoaded);
                        });
                        */

                        dlt.CurrentSubtask = "SAVING CHUNKS";
                        (ActiveMdiChild as frmMap).Map.SaveAll();
                        dlt.SetMarquees(false,false);
                        dlt.Done();
                        ClearReport();
                        (ActiveMdiChild as frmMap).Map.Time = 0;
                        //Utils.FixPlayerPlacement(ref (ActiveMdiChild as frmMap).Map);
                        (ActiveMdiChild as frmMap).Map.Save();

                        (ActiveMdiChild as frmMap).Map.Cache.Enabled = true;

                        MessageBox.Show("Done.  Keep in mind that loading may initially be slow.");

                        // DEACTIVATE AUTOREPAIR
                        (ActiveMdiChild as frmMap).Map.Autorepair = false;
                    });
                    dlt.ShowDialog();
                }
            }
        }
Ejemplo n.º 33
0
 private void AddPoint(Vector3i lolwut)
 {
     Points.Add(lolwut);
     delta_t = 1d / (double)Points.Count;
 }
Ejemplo n.º 34
0
 public Vector3i(Vector3i a)
 {
     this.X = a.X;
     this.Y = a.Y;
     this.Z = a.Z;
 }
Ejemplo n.º 35
0
 private void AddPoint(Vector3i lolwut)
 {
     Points.Add(lolwut);
     delta_t = 1d / (double)Points.Count;
 }