private Filtvalcells updtvalidcells(Filtvalcells source, Filtvalcells target)//add from one filtlist to another { target.bestcells.AddRange(source.bestcells); target.normdcells.AddRange(source.normdcells); target.badcells.AddRange(source.badcells); return(target); }
private Filtvalcells createfvc(List <MapTile> src)//creating filtred by quality lists of cells { Filtvalcells fvc = new Filtvalcells(); fvc.bestcells = new List <MapTile>(); fvc.normdcells = new List <MapTile>(); fvc.badcells = new List <MapTile>(); src = filtrtiles(src); setcellqual(src); for (int i = 0; i < src.Count; i++) { if (src[i].qual == 0) { fvc.bestcells.Add(src[i]); } else if (src[i].qual == 1) { fvc.normdcells.Add(src[i]); } else if (src[i].qual == 2) { fvc.badcells.Add(src[i]); } } return(fvc); }
private void tmakechild(Tunneler t, Filtvalcells fvc)//creating tunnel offsprings { int childr = (t.allcells.Count / t.wide) / 20; Random r = new Random(); int ren = r.Next(0, 10); if (ren == 0 && childr > 1) { cmakechild(fvc); childr--; fvc = filtvalcell(fvc); } for (int i = 0; i < childr; i++) { if (floorcur < floornum) { if (fvc.bestcells.Count > 0) { tunnelermade(fvc.bestcells); } else { return; } fvc = filtvalcell(fvc); } else { Thread.CurrentThread.Abort(); } } }
private Filtvalcells filtvalcell(Filtvalcells vc)//refresh existing Filtrcells { if (vc.bestcells.Count > 0) { vc.bestcells = filtrtiles(vc.bestcells); setcellqual(vc.bestcells); for (int i = 0; i < vc.bestcells.Count; i++) { if (vc.bestcells[i].qual == 0) { } else if (vc.bestcells[i].qual == 1 && !valcells.normdcells.Exists(x => x == vc.bestcells[i])) { valcells.normdcells.Add(vc.bestcells[i]); vc.bestcells.RemoveAt(i); i--; } else if (vc.bestcells[i].qual == 2 && !valcells.badcells.Exists(x => x == vc.bestcells[i])) { valcells.badcells.Add(vc.bestcells[i]); vc.bestcells.RemoveAt(i); i--; } else { vc.bestcells.RemoveAt(i); i--; } } } if (vc.bestcells.Count == 0 && vc.normdcells.Count > 0) { vc.normdcells = filtrtiles(vc.normdcells); setcellqual(vc.normdcells); for (int i = 0; i < vc.normdcells.Count; i++) { if (vc.normdcells[i].qual == 1) { } else if (vc.normdcells[i].qual == 2 && !valcells.badcells.Exists(x => x == vc.normdcells[i])) { valcells.badcells.Add(vc.normdcells[i]); vc.normdcells.RemoveAt(i); i--; } else { vc.normdcells.RemoveAt(i); i--; } } } else { vc.badcells = filtrtiles(vc.badcells); } return(vc); }
public void generatemap(int deep)//creating new map { valcells = new Filtvalcells(); valcells.bestcells = new List <MapTile>(); valcells.normdcells = new List <MapTile>(); valcells.badcells = new List <MapTile>(); floornum = 0; floorcur = 0; plst = 1;//setting plaer pos to the entrnc. no use in mapgen Random r = new Random(); sethw(deep); cavesize = getmaxcavesize(); widtun = getmaxtunwidth(); tiles = new MapTile[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { tiles[i, j] = new MapTile(); tiles[i, j].neighbours = new MapTile[4]; } } iniccells(); int entdp = (height - 3) * (width - 3); for (int i = 1; i < height - 2; i++) { for (int j = 1; j < width - 2; j++) { if (entdp > 0) { int t = r.Next(0, entdp); if (t == 0 || entdp == 1) { tiles[i, j].type = 1; tiles[i, j].qual = 0; floorcur++; updtallcells(); valcells.bestcells.Add(tiles[i, j]); tiles[i, j].backgrnd = Brushes.Red; Account.maptile.x = i; Account.maptile.y = j; //randomly selecting entrance position from non border cells entdp = 0; createmap(); //aand starting mapgen i = height; j = width; } entdp = entdp - 1; } } } }
private void cmakechild(Filtvalcells fvc)//creating child cave { if (fvc.bestcells.Count > 0) { Random rnd = new Random(); int t = rnd.Next(0, fvc.bestcells.Count); int size = rnd.Next(5, cavesize + 1); int dir = choosetdir(fvc.bestcells[t], 1); MapTile b = fvc.bestcells[t].neighbours[dir]; MapTile a = fvc.bestcells[t].neighbours[dir].neighbours[dir]; cavemade(a, b, size); } }
public Map(int d)//map constructor. ingame maps generates when its created. Here is needed just to make aomething in begining { valcells = new Filtvalcells(); valcells.bestcells = new List <MapTile>(); valcells.normdcells = new List <MapTile> (); valcells.badcells = new List <MapTile>(); height = 6; width = 6; floornum = 0; floorcur = 0; //map generation MapTile[,] t = new MapTile[6, 6]; tiles = t; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { tiles[i, j] = new MapTile(); } } iniccells(); }
public void generatemap(int de)//creating new map { deep = de; valcells = new Filtvalcells(); valcells.bestcells = new List <MapTile>(); valcells.normdcells = new List <MapTile>(); valcells.badcells = new List <MapTile>(); floornum = 0; floorcur = 0; Random r = new Random(); sethw(deep); cavesize = getmaxcavesize(); widtun = getmaxtunwidth(); tiles = new MapTile[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { tiles[i, j] = new MapTile(); tiles[i, j].neighbours = new MapTile[4]; } } iniccells(); int entdp = (height - 3) * (width - 3); for (int i = 1; i < height - 2; i++) { for (int j = 1; j < width - 2; j++) { if (entdp > 0) { int t = r.Next(0, entdp); if (t == 0 || entdp == 1) { tiles[i, j].type = 1; tiles[i, j].qual = 0; floorcur++; updtallcells(); valcells.bestcells.Add(tiles[i, j]); //tiles[i, j].backgrnd = Brushes.Red; tiles[i, j].contains.Add("enter"); enter.y = i; enter.x = j; entdp = 0; createmap(); //aand starting mapgen while (exit.x == 0) //sometimes exit doesnt created. there must be some fixable issue but i dont want to adress it right now, so just try until it creates(FIX LATER!) { makeexit(tiles[i, j], 0, 1, new List <MapTile>() { tiles[i, j] }); } i = height; j = width; } entdp = entdp - 1; } } } }
private void tunnelerlife(Tunneler t)//tunnel behavior logic { while (t.lenght > 0 && floorcur < floornum) { //updtallcells();//this and others commented updtallcells may(or may not) have influence on quality of tunnels built. more updtallcels=less performance if (t.prev == null) { int d = choosetdir(t.cur, 0); if (d < 0) { t.lenght = 0; } else { t.prev = t.cur; t.prev.type = 1; floorcur = floorcur + 1; t.lenght--; t.cur = t.prev.neighbours[d]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght--; t.allcells.Add(t.prev); t.allcells.Add(t.cur); if (t.wide > 1) { widetun(t, 1); } } } else { bool straight = true; bool turning = true; t.prevactsuc = false; while (straight || turning) { Random r = new Random(); int act = r.Next(0, 100); int d = tnextstep(t); if ((act > t.turns || turning == false) && straight == true) { straight = false; if (cellvalid(t.cur.neighbours[d])) { t = acttunneler(t, 0); } else { t = acttunneler(t, 2); } } else if ((act <= t.turns || straight == false) && turning == true) { turning = false; int turn = choosetdir(t.cur, 0); if (turn < 0) { t = acttunneler(t, 3); } else { t = acttunneler(t, 1); } } if (t.prevactsuc) { break; } } if (t.prevactsuc == false) { t.lenght = 0; } else { t.allcells.Add(t.cur); } } if (t.wide > 1 && t.prev != null) { t = widetun(t, 0); } //updtallcells();//_______________________________________________________________________________________________________________ } if (floorcur < floornum) { Filtvalcells fvc = createfvc(t.allcells); tmakechild(t, fvc); fvc = filtvalcell(fvc); updtvalidcells(fvc, valcells); } else { Thread.CurrentThread.Abort(); } }