Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Protocol;
- using Json;
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Reflection;
- using System.Diagnostics;
- using System.IO;
- using Igor;
- using System.Drawing;
- namespace CdbTest
- {
- public partial class Form1 : Form
- {
- //int sizex = 100;
- //int sizey = 36;
- //int sizez = 40;
- int sizex = 36;
- int sizey = 100;
- int sizez = 36;
- BlockMap3D importedmap;
- static List<Color> ColorArray = new List<Color>();
- public static readonly Random random = new Random();
- public Form1()
- {
- InitializeComponent();
- source.Lines = @"C:\bnl\UserData\CustomMaps\map_sr2_maze.bnlbin".Split('▀');
- save_to.Lines = @"C:\bnl\UserData\CustomMaps\map_generated.bnlbin".Split('▀');
- textBox4.Lines = @"140.png".Split('▀');
- numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
- }
- public class BlockArrayMap3D2 : global::BlockMap3D
- {
- //private global::Block[][][] storage;
- public Block[][][] storage { get; set; }
- public BlockArrayMap3D2(global::Vector3s size) : this((int)size.x, (int)size.y, (int)size.z)
- {
- }
- public BlockArrayMap3D2(int sizeX, int sizeY, int sizeZ) : base(sizeX, sizeY, sizeZ)
- {
- this.storage = new global::Block[base.SizeX][][];
- for (int i = 0; i < base.SizeX; i++)
- {
- this.storage[i] = new global::Block[base.SizeY][];
- for (int j = 0; j < base.SizeY; j++)
- {
- this.storage[i][j] = new global::Block[base.SizeZ];
- }
- }
- }
- protected override global::Block Get(int x, int y, int z)
- {
- return this.storage[x][y][z];
- }
- protected override void Set(int x, int y, int z, global::Block block)
- {
- this.storage[x][y][z] = block;
- }
- public global::Block Get2(int x, int y, int z)
- {
- return this.storage[x][y][z];
- }
- public void Set2(int x, int y, int z, global::Block block)
- {
- // Debug.WriteLine("set2 params: " + x + " " + z);
- this.storage[x][y][z] = block;
- }
- public void Set3(int x, int y, int z, global::Block block)
- {
- // Debug.WriteLine("set2 params: " + x + " " + z);
- //if (this.storage[x][y][z].Id == 18 && block.Id == 10) { throw new Exception(); }
- //if (this.storage[x][y][z].Id == 16) { Console.WriteLine("jumppad"); throw new Exception(); }
- if (this.storage[x][y][z].Id == 53) { throw new Exception(); }
- if (this.storage[x][y][z].Id == 0 || this.storage[x][y][z].Id == 10)
- this.storage[x][y][z] = block;
- //if (this.storage[x][y][z].Id != 0) { throw new Exception(); }
- //this.storage[x][y][z] = block;
- }
- public void Set4(int x, int y, int z, global::Block block)
- {
- // Debug.WriteLine("set2 params: " + x + " " + z);
- //if (this.storage[x][y][z].Id == 18 && block.Id == 10) { throw new Exception(); }
- //if (this.storage[x][y][z].Id == 16) { Console.WriteLine("jumppad"); throw new Exception(); }
- if (this.storage[x][y][z].Id == 53) { throw new Exception(); }
- //if (this.storage[x][y][z].Id != 0) { throw new Exception(); }
- this.storage[x][y][z] = block;
- }
- }
- // MapGenerator
- public static BlockArrayMap3D2 GenerateRandom(global::Vector3s size, int air)
- {
- global::MapGenerator.FixSize(ref size);
- Random rand = new Random();
- BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- if (rand.Next(0, 100) < air)
- {
- block.Id = 0;
- }
- else
- {
- byte next = utils.whitelist();
- //if(pos.x % 4 == 0 && pos.y % 4 == 0 && pos.z % 4 == 0)
- //{
- // Debug.WriteLine("" + pos.x + pos.y + pos.z);
- //}
- block.Id = next;
- }
- });
- return blockArrayMap3D;
- }
- // MapGenerator
- public BlockArrayMap3D2 GenerateTerrain(global::Vector3s size, float feature)
- {
- float towerfeature = (float)numericUpDown14.Value;
- OpenSimplexNoise osn = new OpenSimplexNoise();
- MapGenerator.FixSize(ref size);
- BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- //double something = osn.Evaluate(pos.x, pos.y, pos.z);
- //int id = (int)((something + 1) * (size.y / 2));
- //Debug.WriteLine(id);
- //block.Id = (byte)id;
- block.Id = 0;
- });
- int whileHeight = 0;
- for (int x = 0; x < size.x - 1; x++)
- {
- for (int z = 0; z < size.z - 1; z++)
- {
- Block turf = new Block();
- turf.Id = 5;
- double something = osn.Evaluate(x / feature, z / feature);
- int height = (int)((something + 1) * (size.y / 2));
- blockArrayMap3D.Set2(x, height, z, turf);
- //stuff below
- while (blockArrayMap3D.Get2(x, whileHeight, z).Id != 5)
- {
- Block stone = new Block();
- stone.Id = 3;
- blockArrayMap3D.Set2(x, whileHeight, z, stone);
- whileHeight++;
- }
- Block dirt = new Block();
- dirt.Id = 1;
- if (whileHeight - 1 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 1, z, dirt); } catch { }
- if (whileHeight - 2 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 2, z, dirt); } catch { }
- if (whileHeight - 3 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 3, z, dirt); } catch { }
- if (whileHeight - 4 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 4, z, dirt); } catch { }
- whileHeight = 0;
- }
- whileHeight = 0;
- }
- for (int towers = 0; towers < numericUpDown16.Value; towers++)
- {
- int sizeOfTower = (int)numericUpDown14.Value;
- int randomx = random.Next(size.x - sizeOfTower);
- int randomz = random.Next(size.z - sizeOfTower);
- for (int x = randomx; x < randomx + sizeOfTower; x++)
- {
- for (int z = randomz; z < randomz + sizeOfTower; z++)
- {
- Block towerBlock = new Block();
- towerBlock.Id = (byte)numericUpDown13.Value;
- double something = osn.Evaluate(x / towerfeature, z / towerfeature);
- int height = (int)((something + 1) * (size.y / 1.7));
- Debug.WriteLine(height);
- for (int e = height; e > 0; e--)
- {
- try { blockArrayMap3D.Set2(x, e, z, towerBlock); } catch { }
- }
- //mirror test
- //float average = 18;
- //Debug.WriteLine(average);
- //float howMuchHigherIsIt = height - average;
- //Debug.WriteLine(howMuchHigherIsIt);
- //try { blockArrayMap3D.Set2(x, (int)(height - howMuchHigherIsIt*2), z, dirt); } catch { Debug.WriteLine(x + " " + (int)(average - howMuchHigherIsIt) + " " + z); }
- }
- }
- }
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- double something = osn.Evaluate(pos.x / feature, pos.y / feature, pos.z / feature);
- //Debug.WriteLine(something);
- if (something > ((float.Parse(textBox2.Lines[0]) - 50) / 50) && block.Id == 3) { block.Id = 0; }// else { block.Id = 0; }
- });
- return blockArrayMap3D;
- }
- // MapGenerator
- public BlockArrayMap3D2 GenerateDerpTerrain(global::Vector3s size, float feature)
- {
- double tresh = float.Parse(textBox3.Lines[0]);
- OpenSimplexNoise osn = new OpenSimplexNoise();
- MapGenerator.FixSize(ref size);
- BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
- BlockArrayMap3D2 imported = new BlockArrayMap3D2(new Vector3s(36, 36, 36));
- //make a map out of air
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- block.Id = 0;
- });
- //stone
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- //double something = osn.Evaluate(pos.x, pos.y, pos.z);
- //int id = (int)((something + 1) * (size.y / 2));
- //Debug.WriteLine(id);
- //block.Id = (byte)id;
- //float noise2 = (float)osn.Evaluate(pos.x / feature / 2, pos.y / feature / 2, pos.z / feature / 2);
- //(float.Parse(textBox2.Lines[0]) - 50) / 50;
- //double tresh2 = utils.Remap(noise2, -1, 1, -0.5f, 0.5f);
- //double avg = (tresh + tresh2) / 2;
- //Debug.WriteLine(something);
- //double tresh = utils.Remap(pos.y, 0, size.y, -0.5f, 0.5f);
- //double tresh = utils.Remap(pos.y, 0, size.y, -1f, 1f);
- double noise = osn.Evaluate(pos.x / feature, pos.y / feature, pos.z / feature);
- noise *= noise;
- //if (pos.y < size.y / 2 + 20 && pos.y > size.y / 2 -5)
- //{
- if (noise < tresh)
- {
- //block.Id = 27;
- //Console.WriteLine(block.Id);
- }
- else
- {
- //block.Id = 0;
- }
- //}
- });
- importedmap.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- imported.Set2(pos.x, pos.y, pos.z, block);
- });
- Console.WriteLine(imported.Get2(1, 1, 1).Id);
- Genheightmap(ref blockArrayMap3D, size);
- //AddTrees(ref blockArrayMap3D, size);
- for (int i = 0; i < 100; i++)
- {
- int objectx = random.Next(size.x - 37);
- int objecty = random.Next(size.y - 37);
- int objectz = random.Next(size.z - 37);
- for (int x = 0; x < 35; x++)
- {
- for (int y = 0; y < 35; y++)
- {
- for (int z = 0; z < 35; z++)
- {
- Block a = imported.Get2(x, y, z);
- if (a.Id != 0 && a.Id != 46)
- {
- blockArrayMap3D.Set2(objectx + x, objecty + y, objectz + z, a);
- }
- }
- }
- }
- }
- return blockArrayMap3D;
- }
- // MapGenerator
- public static BlockArrayMap3D RandomizeMap(global::Vector3s size, BlockMap3D blockArrayMap3D)
- {
- global::MapGenerator.FixSize(ref size);
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- if (block.Id == 7 || block.Id == 53 || block.Id == 9 || block.Id == 17 || block.Id == 58 || block.Id == 1 || block.Id == 46 || block.Id == 5 || block.Id == 61 || block.Id == 4 || block.Id == 10 || block.Id == 14 || block.Id == 27 || block.Id == 2 || block.Id == 21 || block.Id == 60 || block.Id == 3 || block.Id == 11 || block.Id == 8)
- {
- byte next = utils.whitelistgrid();
- block.Id = next;
- }
- else
- {
- // Debug.WriteLine(block.Id);
- }
- });
- return (BlockArrayMap3D)blockArrayMap3D;
- }
- // MapGenerator
- public static BlockArrayMap3D2 GeneratePixelArt(global::Vector3s size, Bitmap bmp)
- {
- bool cube = false;
- bool maze = false;
- Block lol = new Block();
- lol.Id = 10;
- global::MapGenerator.FixSize(ref size);
- //size.x++;
- //size.x++;
- //size.x++;
- BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
- for (int x = 0; x < bmp.Width; x++)
- {
- for (int y = 0; y < bmp.Height; y++)
- {
- }
- }
- //make a map out of air
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- block.Id = 0;
- block.Color = 1;
- });
- for (int x = 0; x < bmp.Width-1; x++)
- {
- for (int y = 0; y < bmp.Height-1; y++)
- {
- Color clr = bmp.GetPixel(x, y);
- int red = clr.R;
- int gre = clr.G;
- int blu = clr.B;
- //Console.WriteLine("Slow: " + red1 + " " + green + " " + blue);
- Block a = new Block();
- //string pixel = pixels[x + y * width];
- //string[] colors = pixel.Split(",".ToCharArray());
- //int red = int.Parse(colors[0]);
- //int gre = int.Parse(colors[1]);
- //int blu = int.Parse(colors[2]);
- //if(red + gre + blu > 384)
- //{
- // a.Id = 5;
- //} else
- //{
- // a.Id = 4;
- //}
- //float id = utils.Remap(red + gre + blu, 0, 765, 1, 11);
- //int id2 = (int)id;
- a.Id = 53;
- //ConsoleColor cc = utils.ClosestConsoleColor((byte)red, (byte)gre, (byte)blu);
- Color cc = Color.FromArgb((byte)red, (byte)gre, (byte)blu);
- var closest = utils.GetClosestColor(ColorArray.ToArray(), cc);
- cc = closest;
- a.Color = 0;
- //Console.WriteLine(cc.ToKnownColor());
- //if (2 == 3) { } else if (cc.ToString() == "Black") { a.Color = 0; } else if (cc.ToString() == "DarkBlue") { a.Color = 1; } else if (cc.ToString() == "DarkGreen") { a.Color = 2; } else if (cc.ToString() == "DarkCyan") { a.Color = 3; } else if (cc.ToString() == "DarkRed") { a.Color = 4; } else if (cc.ToString() == "DarkMagenta") { a.Color = 5; } else if (cc.ToString() == "DarkYellow") { a.Color = 6; } else if (cc.ToString() == "Gray") { a.Color = 7; } else if (cc.ToString() == "DarkGray") { a.Color = 8; } else if (cc.ToString() == "Blue") { a.Color = 9; } else if (cc.ToString() == "Green") { a.Color = 10; } else if (cc.ToString() == "Cyan") { a.Color = 11; } else if (cc.ToString() == "Red") { a.Color = 12; } else if (cc.ToString() == "Magenta") { a.Color = 13; } else if (cc.ToString() == "Yellow") { a.Color = 14; } else if (cc.ToString() == "White") { a.Color = 15; }
- if (false) { } else if (cc.Name == "Transparent") { a.Color = 0; } else if (cc.Name == "AliceBlue") { a.Color = 1; } else if (cc.Name == "AntiqueWhite") { a.Color = 2; } else if (cc.Name == "Aqua") { a.Color = 3; } else if (cc.Name == "Aquamarine") { a.Color = 4; } else if (cc.Name == "Azure") { a.Color = 5; } else if (cc.Name == "Beige") { a.Color = 6; } else if (cc.Name == "Bisque") { a.Color = 7; } else if (cc.Name == "Black") { a.Color = 8; } else if (cc.Name == "BlanchedAlmond") { a.Color = 9; } else if (cc.Name == "Blue") { a.Color = 10; } else if (cc.Name == "BlueViolet") { a.Color = 11; } else if (cc.Name == "Brown") { a.Color = 12; } else if (cc.Name == "BurlyWood") { a.Color = 13; } else if (cc.Name == "CadetBlue") { a.Color = 14; } else if (cc.Name == "Chartreuse") { a.Color = 15; } else if (cc.Name == "Chocolate") { a.Color = 16; } else if (cc.Name == "Coral") { a.Color = 17; } else if (cc.Name == "CornflowerBlue") { a.Color = 18; } else if (cc.Name == "Cornsilk") { a.Color = 19; } else if (cc.Name == "Crimson") { a.Color = 20; } else if (cc.Name == "Cyan") { a.Color = 21; } else if (cc.Name == "DarkBlue") { a.Color = 22; } else if (cc.Name == "DarkCyan") { a.Color = 23; } else if (cc.Name == "DarkGoldenrod") { a.Color = 24; } else if (cc.Name == "DarkGray") { a.Color = 25; } else if (cc.Name == "DarkGreen") { a.Color = 26; } else if (cc.Name == "DarkKhaki") { a.Color = 27; } else if (cc.Name == "DarkMagenta") { a.Color = 28; } else if (cc.Name == "DarkOliveGreen") { a.Color = 29; } else if (cc.Name == "DarkOrange") { a.Color = 30; } else if (cc.Name == "DarkOrchid") { a.Color = 31; } else if (cc.Name == "DarkRed") { a.Color = 32; } else if (cc.Name == "DarkSalmon") { a.Color = 33; } else if (cc.Name == "DarkSeaGreen") { a.Color = 34; } else if (cc.Name == "DarkSlateBlue") { a.Color = 35; } else if (cc.Name == "DarkSlateGray") { a.Color = 36; } else if (cc.Name == "DarkTurquoise") { a.Color = 37; } else if (cc.Name == "DarkViolet") { a.Color = 38; } else if (cc.Name == "DeepPink") { a.Color = 39; } else if (cc.Name == "DeepSkyBlue") { a.Color = 40; } else if (cc.Name == "DimGray") { a.Color = 41; } else if (cc.Name == "DodgerBlue") { a.Color = 42; } else if (cc.Name == "Firebrick") { a.Color = 43; } else if (cc.Name == "FloralWhite") { a.Color = 44; } else if (cc.Name == "ForestGreen") { a.Color = 45; } else if (cc.Name == "Fuchsia") { a.Color = 46; } else if (cc.Name == "Gainsboro") { a.Color = 47; } else if (cc.Name == "GhostWhite") { a.Color = 48; } else if (cc.Name == "Gold") { a.Color = 49; } else if (cc.Name == "Goldenrod") { a.Color = 50; } else if (cc.Name == "Gray") { a.Color = 51; } else if (cc.Name == "Green") { a.Color = 52; } else if (cc.Name == "GreenYellow") { a.Color = 53; } else if (cc.Name == "Honeydew") { a.Color = 54; } else if (cc.Name == "HotPink") { a.Color = 55; } else if (cc.Name == "IndianRed") { a.Color = 56; } else if (cc.Name == "Indigo") { a.Color = 57; } else if (cc.Name == "Ivory") { a.Color = 58; } else if (cc.Name == "Khaki") { a.Color = 59; } else if (cc.Name == "Lavender") { a.Color = 60; } else if (cc.Name == "LavenderBlush") { a.Color = 61; } else if (cc.Name == "LawnGreen") { a.Color = 62; } else if (cc.Name == "LemonChiffon") { a.Color = 63; } else if (cc.Name == "LightBlue") { a.Color = 64; } else if (cc.Name == "LightCoral") { a.Color = 65; } else if (cc.Name == "LightCyan") { a.Color = 66; } else if (cc.Name == "LightGoldenrodYellow") { a.Color = 67; } else if (cc.Name == "LightGreen") { a.Color = 68; } else if (cc.Name == "LightGray") { a.Color = 69; } else if (cc.Name == "LightPink") { a.Color = 70; } else if (cc.Name == "LightSalmon") { a.Color = 71; } else if (cc.Name == "LightSeaGreen") { a.Color = 72; } else if (cc.Name == "LightSkyBlue") { a.Color = 73; } else if (cc.Name == "LightSlateGray") { a.Color = 74; } else if (cc.Name == "LightSteelBlue") { a.Color = 75; } else if (cc.Name == "LightYellow") { a.Color = 76; } else if (cc.Name == "Lime") { a.Color = 77; } else if (cc.Name == "LimeGreen") { a.Color = 78; } else if (cc.Name == "Linen") { a.Color = 79; } else if (cc.Name == "Magenta") { a.Color = 80; } else if (cc.Name == "Maroon") { a.Color = 81; } else if (cc.Name == "MediumAquamarine") { a.Color = 82; } else if (cc.Name == "MediumBlue") { a.Color = 83; } else if (cc.Name == "MediumOrchid") { a.Color = 84; } else if (cc.Name == "MediumPurple") { a.Color = 85; } else if (cc.Name == "MediumSeaGreen") { a.Color = 86; } else if (cc.Name == "MediumSlateBlue") { a.Color = 87; } else if (cc.Name == "MediumSpringGreen") { a.Color = 88; } else if (cc.Name == "MediumTurquoise") { a.Color = 89; } else if (cc.Name == "MediumVioletRed") { a.Color = 90; } else if (cc.Name == "MidnightBlue") { a.Color = 91; } else if (cc.Name == "MintCream") { a.Color = 92; } else if (cc.Name == "MistyRose") { a.Color = 93; } else if (cc.Name == "Moccasin") { a.Color = 94; } else if (cc.Name == "NavajoWhite") { a.Color = 95; } else if (cc.Name == "Navy") { a.Color = 96; } else if (cc.Name == "OldLace") { a.Color = 97; } else if (cc.Name == "Olive") { a.Color = 98; } else if (cc.Name == "OliveDrab") { a.Color = 99; } else if (cc.Name == "Orange") { a.Color = 100; } else if (cc.Name == "OrangeRed") { a.Color = 101; } else if (cc.Name == "Orchid") { a.Color = 102; } else if (cc.Name == "PaleGoldenrod") { a.Color = 103; } else if (cc.Name == "PaleGreen") { a.Color = 104; } else if (cc.Name == "PaleTurquoise") { a.Color = 105; } else if (cc.Name == "PaleVioletRed") { a.Color = 106; } else if (cc.Name == "PapayaWhip") { a.Color = 107; } else if (cc.Name == "PeachPuff") { a.Color = 108; } else if (cc.Name == "Peru") { a.Color = 109; } else if (cc.Name == "Pink") { a.Color = 110; } else if (cc.Name == "Plum") { a.Color = 111; } else if (cc.Name == "PowderBlue") { a.Color = 112; } else if (cc.Name == "Purple") { a.Color = 113; } else if (cc.Name == "Red") { a.Color = 114; } else if (cc.Name == "RosyBrown") { a.Color = 115; } else if (cc.Name == "RoyalBlue") { a.Color = 116; } else if (cc.Name == "SaddleBrown") { a.Color = 117; } else if (cc.Name == "Salmon") { a.Color = 118; } else if (cc.Name == "SandyBrown") { a.Color = 119; } else if (cc.Name == "SeaGreen") { a.Color = 120; } else if (cc.Name == "SeaShell") { a.Color = 121; } else if (cc.Name == "Sienna") { a.Color = 122; } else if (cc.Name == "Silver") { a.Color = 123; } else if (cc.Name == "SkyBlue") { a.Color = 124; } else if (cc.Name == "SlateBlue") { a.Color = 125; } else if (cc.Name == "SlateGray") { a.Color = 126; } else if (cc.Name == "Snow") { a.Color = 127; } else if (cc.Name == "SpringGreen") { a.Color = 128; } else if (cc.Name == "SteelBlue") { a.Color = 129; } else if (cc.Name == "Tan") { a.Color = 130; } else if (cc.Name == "Teal") { a.Color = 131; } else if (cc.Name == "Thistle") { a.Color = 132; } else if (cc.Name == "Tomato") { a.Color = 133; } else if (cc.Name == "Turquoise") { a.Color = 134; } else if (cc.Name == "Violet") { a.Color = 135; } else if (cc.Name == "Wheat") { a.Color = 136; } else if (cc.Name == "White") { a.Color = 137; } else if (cc.Name == "WhiteSmoke") { a.Color = 138; } else if (cc.Name == "Yellow") { a.Color = 139; } else if (cc.Name == "YellowGreen") { a.Color = 140; }
- //Console.WriteLine(cc.Name);
- //Console.WriteLine(a.Color);
- a.Color++;
- //Console.WriteLine(closest.Name);
- int s = 1;
- int inv = size.y - 1 - y;
- Block metal = new Block();
- metal.Id = 10;
- if (cube)
- {
- blockArrayMap3D.Set2(y, s, x, metal);
- blockArrayMap3D.Set2(y, size.y - s, x, a);
- blockArrayMap3D.Set2(s, inv, x, a);
- blockArrayMap3D.Set2(size.x - s, inv, x, a);
- blockArrayMap3D.Set2(x, inv, s, a);
- blockArrayMap3D.Set2(x, inv, size.z - s, a);
- }
- else
- {
- blockArrayMap3D.Set2(y, 7, x, a);
- }
- if (cc.ToString() == "Black" && maze)
- {
- blockArrayMap3D.Set2(y, 8, x, a);
- blockArrayMap3D.Set2(y, 9, x, a);
- blockArrayMap3D.Set2(y, 10, x, a);
- blockArrayMap3D.Set2(y, 11, x, a);
- }
- }
- }
- //BlockArrayMap3D2 test1 = new BlockArrayMap3D2(size);
- //test1.Set2(30, 30, 30, lol);
- //BlockArrayMap3D2 test2 = new BlockArrayMap3D2(size);
- //test1.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- //{
- // test2.Set2(pos.x, pos.y, pos.z, block);
- //});
- //test2 = test1;
- //test1.Set2(30, 30, 31, lol);
- //test1.Set2(30, 30, 32, lol);
- //return test2;
- return blockArrayMap3D;
- }
- public static void up(ref BlockArrayMap3D2 blockArrayMap3D, int dir, int leng)
- {
- }
- // MapGenerator
- public static BlockArrayMap3D2 GenerateGrid(global::Vector3s size)
- {
- global::MapGenerator.FixSize(ref size);
- Random rand = new Random();
- BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
- blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
- {
- byte next = utils.whitelistgrid();
- //Debug.WriteLine(next.ToString());
- if (pos.x % 4 == 0 && pos.y % 4 == 0 && pos.z % 4 == 0)
- {
- block.Id = next;
- }
- else
- {
- // Debug.WriteLine("" + pos.x + pos.y + pos.z);
- block.Id = 0;
- }
- });
- return blockArrayMap3D;
- }
- //Button
- private void genmap_click(object sender, EventArgs e)
- {
- sizex = (int)numericUpDown1.Value;
- sizey = (int)numericUpDown2.Value;
- sizez = (int)numericUpDown3.Value;
- string json2 = MapStoreUtils.Decode(File.ReadAllBytes(@"original_map.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json2);
- json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(sizex);
- json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(sizey);
- json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(sizez);
- json.Object["name"] = Json.Write.String("generated map");
- BlockArrayMap3D2 map = GenerateRandom(new Vector3s(sizex, sizey, sizez), (int)numericUpDown4.Value);
- int unitcount = 0;
- int blockcount = map.SizeX * map.SizeY * map.SizeZ;
- string units = "[";// = json.Object["map"].Object["units"].ToString();
- for (int i = 0; i < map.SizeX; i++)
- {
- for (int j = 0; j < map.SizeY; j++)
- {
- for (int k = 0; k < map.SizeZ; k++)
- {
- // Debug.WriteLine("" + map.Get2(i, j, k).Id + map.Get2(i, j, k).Damage + map.Get2(i, j, k).Ldata + map.Get2(i, j, k).Vdata);
- if (random.Next(blockcount / 90) == 50 && map.Get2(i, j, k).Id == 0)
- {
- unitcount++;
- //Debug.WriteLine(rand.Next(2));
- // Debug.WriteLine(map.Get2(i, j, k).Id);
- units = units + ",{\"position\":{\"x\":" + i + ".5,\"y\":" + j + ".5,\"z\":" + k + ".5},\"rotation\":{\"x\":0,\"y\":0,\"z\":0},\"unit_key\":\"" + utils.heal_or_radar_or_ammo() + "\",\"team\":\"" + utils.random_team() + "\"}";
- }
- }
- }
- }
- Debug.WriteLine(unitcount);
- textBox1.Lines = unitcount.ToString().Split('a');
- json.Object["map"].Object["units"] = Json.Write.String(units + "]");
- //Debug.WriteLine(units);
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(map));
- string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- //Button
- private void gengrid_click(object sender, EventArgs e)
- {
- sizex = (int)numericUpDown9.Value;
- sizey = (int)numericUpDown10.Value;
- sizez = (int)numericUpDown11.Value;
- string json2 = MapStoreUtils.Decode(File.ReadAllBytes(@"original_map.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json2);
- json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(sizex);
- json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(sizey);
- json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(sizez);
- json.Object["name"] = Json.Write.String("generated map");
- BlockArrayMap3D2 map = GenerateGrid(new Vector3s(sizex, sizey, sizez));
- int unitcount = 0;
- int blockcount = map.SizeX * map.SizeY * map.SizeZ;
- string units = "[";// = json.Object["map"].Object["units"].ToString();
- for (int i = 0; i < map.SizeX; i++)
- {
- for (int j = 0; j < map.SizeY; j++)
- {
- for (int k = 0; k < map.SizeZ; k++)
- {
- // Debug.WriteLine("" + map.Get2(i, j, k).Id + map.Get2(i, j, k).Damage + map.Get2(i, j, k).Ldata + map.Get2(i, j, k).Vdata);
- if (random.Next(blockcount / 1800) == 50 && map.Get2(i, j, k).Id == 0)
- {
- if (i % 4 == 0 && k % 4 == 0)
- {
- unitcount++;
- //Debug.WriteLine(rand.Next(2));
- // Debug.WriteLine(map.Get2(i, j, k).Id);
- units = units + ",{\"position\":{\"x\":" + i + ".5,\"y\":" + j + ".5,\"z\":" + k + ".5},\"rotation\":{\"x\":0,\"y\":0,\"z\":0},\"unit_key\":\"" + utils.heal_or_radar_or_ammo() + "\",\"team\":\"" + utils.random_team() + "\"}";
- }
- }
- }
- }
- }
- Debug.WriteLine(unitcount);
- textBox1.Lines = unitcount.ToString().Split('a');
- json.Object["map"].Object["units"] = Json.Write.String(units + "]");
- Debug.WriteLine(units);
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(map));
- string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.Create(@"uncompressed").Close();
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- //Button
- private void randomize_existing_map_click(object sender, EventArgs e)
- {
- string json_orig = MapStoreUtils.Decode(File.ReadAllBytes(source.Lines[0]));
- Json.JsonData json = Json.JsonParser.Parse(json_orig);
- Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
- MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
- BlockMap3D orig_blocks = mb.ToMap3D();
- BlockMap3D new_blocks = RandomizeMap(size, orig_blocks);
- //save the map
- json.Object["name"] = Json.Write.String("generated map");
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
- string json_fixed = json.ToString();
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- //Button
- private void genterrain_click(object sender, EventArgs e)
- {
- string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("original_map.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json_orig);
- Vector3s size = new Vector3s((int)numericUpDown6.Value, (int)numericUpDown7.Value, (int)numericUpDown8.Value);
- json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
- json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
- json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
- BlockMap3D new_blocks = GenerateTerrain(size, (float)numericUpDown5.Value);
- //save the map
- json.Object["name"] = Json.Write.String("generated map");
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
- json.Object["map"].Object["units"] = Json.Write.String("[,]");
- string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- //Browse
- private void button4_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- // bmp, gif, jpg, png, tif and dds
- ofd.Filter = "map|*.bnlbin";
- ofd.CheckFileExists = true;
- ofd.Title = "Open map";
- if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
- {
- // Debug.WriteLine(ofd.FileName);
- //textBox3.Lines[0] = "2"; //ofd.FileName;
- source.Lines = ofd.FileName.Split("?".ToCharArray());
- }
- }
- //Browse
- private void button5_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- // bmp, gif, jpg, png, tif and dds
- ofd.Filter = "map|*.bnlbin";
- ofd.CheckFileExists = false;
- ofd.Title = "Open map";
- if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
- {
- // Debug.WriteLine(ofd.FileName);
- //textBox3.Lines[0] = "2"; //ofd.FileName;
- save_to.Lines = ofd.FileName.Split("?".ToCharArray());
- }
- }
- private void numericUpDown6_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
- }
- private void numericUpDown7_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
- }
- private void numericUpDown8_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
- }
- private void derp_terrain_click(object sender, EventArgs e)
- {
- string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("original_map.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json_orig);
- Vector3s size = new Vector3s((int)numericUpDown6.Value, (int)numericUpDown7.Value, (int)numericUpDown8.Value);
- json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
- json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
- json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
- BlockMap3D new_blocks = GenerateDerpTerrain(size, (float)numericUpDown5.Value);
- //save the map
- json.Object["name"] = Json.Write.String("generated map");
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
- json.Object["map"].Object["units"] = Json.Write.String("[,]");
- string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- private void numericUpDown14_ValueChanged(object sender, EventArgs e)
- {
- }
- public BlockArrayMap3D2 AddTrees(ref BlockArrayMap3D2 blockArrayMap3D, Vector3s size)
- {
- int trunksize = 5;
- Block towerBlock = new Block();
- towerBlock.Id = (byte)numericUpDown13.Value;
- float towerfeature = (float)numericUpDown14.Value;
- int sizeOfTower = (int)numericUpDown14.Value;
- int sizeOfTower2 = (int)Math.Floor(sizeOfTower * 0.5);
- int whileHeight = 0;
- for (int towers = 0; towers < numericUpDown16.Value; towers++)
- {
- whileHeight = size.y - 1;
- int randomx = random.Next(size.x - sizeOfTower);
- int randomz = random.Next(size.z - sizeOfTower);
- int trunkx = randomx + sizeOfTower2;
- int trunkz = randomz + sizeOfTower2;
- while (blockArrayMap3D.Get2(trunkx, whileHeight, trunkz).Id == 0)
- {
- whileHeight--;
- }
- int height = whileHeight + trunksize + sizeOfTower;
- if (height > size.y - 1)
- {
- continue;
- }
- for (int x = randomx; x < randomx + sizeOfTower; x++)
- {
- for (int z = randomz; z < randomz + sizeOfTower; z++)
- {
- //Debug.WriteLine(height);
- for (int e = height; e > height - sizeOfTower; e--)
- {
- try { blockArrayMap3D.Set2(x, e, z, towerBlock); } catch { Console.WriteLine("error at " + e); }
- }
- }
- }
- for (int x = 0; x < trunksize + 1; x++)
- {
- try { blockArrayMap3D.Set2(trunkx, whileHeight + x, trunkz, towerBlock); } catch { }
- }
- }
- return blockArrayMap3D;
- }
- public BlockArrayMap3D2 Genheightmap(ref BlockArrayMap3D2 blockArrayMap3D, Vector3s size)
- {
- float towerfeature = (float)numericUpDown14.Value;
- float feature = (float)numericUpDown17.Value;
- OpenSimplexNoise osn = new OpenSimplexNoise();
- MapGenerator.FixSize(ref size);
- int whileHeight = 0;
- for (int x = 0; x < size.x; x++)
- {
- for (int z = 0; z < size.z; z++)
- {
- Block turf = new Block();
- turf.Id = 5;
- double something = osn.Evaluate(x / feature, z / feature);
- int height = (int)((something + 1) * (size.y / 3));
- blockArrayMap3D.Set2(x, height, z, turf);
- //stuff below
- while (blockArrayMap3D.Get2(x, whileHeight, z).Id != 5)
- {
- Block stone = new Block();
- stone.Id = 3;
- blockArrayMap3D.Set2(x, whileHeight, z, stone);
- whileHeight++;
- }
- Block air = new Block();
- air.Id = 0;
- for (int i = whileHeight + 30; i < size.y; i++)
- {
- try { blockArrayMap3D.Set2(x, i, z, air); } catch { }
- }
- Block dirt = new Block();
- dirt.Id = 1;
- if (whileHeight - 1 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 1, z, dirt); } catch { }
- if (whileHeight - 2 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 2, z, dirt); } catch { }
- if (whileHeight - 3 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 3, z, dirt); } catch { }
- if (whileHeight - 4 > -1)
- try { blockArrayMap3D.Set2(x, whileHeight - 4, z, dirt); } catch { }
- whileHeight = 0;
- }
- whileHeight = 0;
- }
- return blockArrayMap3D;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- string json_orig = MapStoreUtils.Decode(File.ReadAllBytes(@"C:\bnl\UserData\CustomMaps\object.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json_orig);
- Console.WriteLine(json);
- //Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
- //MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
- Vector3s size = new Vector3s(Json.Read.Int(json.Object["size"].Object["x"]), Json.Read.Int(json.Object["size"].Object["y"]), Json.Read.Int(json.Object["size"].Object["z"]));
- MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["blocks_data"]), size);
- BlockMap3D orig_blocks = mb.ToMap3D();
- importedmap = orig_blocks;
- //BlockMap3D new_blocks = RandomizeMap(size, orig_blocks);
- }
- private void button8_Click(object sender, EventArgs e)
- {
- string pal = "[";
- string ifcode = "if(false ){}";
- var colors = utils.GetStaticPropertyBag(typeof(Color));
- int i = 0;
- foreach (KeyValuePair<string, object> colorPair in colors)
- {
- //Console.WriteLine(colorPair.Key);
- Color c = (Color)colorPair.Value;
- pal += "{\"r\":" + c.R + ",\"g\":" + c.G + ",\"b\":" + c.B + ",\"a\":255},";
- ColorArray.Add(c);
- ifcode += "else if(cc.Name == \"" + c.Name + "\"){a.Color = " + i + ";}";
- i++;
- }
- //Console.WriteLine(pal);
- //foreach (var n in Enum.GetNames(typeof(ConsoleColor)))
- //{
- // Color c = Color.FromName(n);
- // pal += "{\"r\":" + c.R + ",\"g\":" + c.G + ",\"b\":" + c.B + ",\"a\":255},";
- // ifcode += "else if(cc.ToString() == \"" + n + "\"){a.Color = " + i + ";}";
- // i++;
- //}
- //Console.WriteLine(pal);
- //Console.WriteLine(ifcode);
- //load img
- System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(textBox4.Lines[0]);
- string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("pixelart.bnlbin"));
- Json.JsonData json = Json.JsonParser.Parse(json_orig);
- //Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
- Vector3s size = new Vector3s(bmp.Height, 36, bmp.Width);//height should be 36
- //MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
- //BlockMap3D orig_blocks = mb.ToMap3D();
- Console.WriteLine(size.x);
- BlockMap3D new_blocks = GeneratePixelArt(size, bmp);
- byte[] colors2 = global::MapBinary.EncodeColors(new_blocks);
- //save the map
- json.Object["name"] = Json.Write.String("generated map");
- json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
- json.Object["map"].Object["colors_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(colors2);
- //size
- json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
- json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
- json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
- //colors shit
- json.Object["map"].Object["color_palette"] = Json.Write.String(pal + "]");
- string json_fixed = json.ToString().Replace("\\", "").Replace("\"color_palette\":\"[", "\"color_palette\":[").Replace(",]\",\"spawn", "],\"spawn");
- byte[] compressed = MapStoreUtils.Encode(json_fixed);
- File.Create(save_to.Lines[0]).Close();
- File.WriteAllBytes(save_to.Lines[0], compressed);
- File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
- //release
- File.Create(@"map-generated.bnlbin").Close();
- File.WriteAllBytes(@"map-generated.bnlbin", compressed);
- }
- private void button9_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- // bmp, gif, jpg, png, tif and dds
- ofd.Filter = "map|*.*";
- ofd.CheckFileExists = true;
- ofd.Title = "Open map";
- if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
- {
- // Debug.WriteLine(ofd.FileName);
- //textBox3.Lines[0] = "2"; //ofd.FileName;
- textBox4.Lines = ofd.FileName.Split("?".ToCharArray());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement