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 void tunnelermade(List <MapTile> tiles)//creating tunnels { Random r = new Random(); int chance = r.Next(0, tiles.Count); int d = choosetdir(tiles[chance], 1); if (d < 0) { return; } Tunneler t = new Tunneler(); t.lenght = r.Next(2, (int)(((height + width) / 2) + 3)); t.turns = t.lenght / 10; if (t.turns > 20) { t.turns = 20; } t.cur = tiles[chance].neighbours[d]; t.left = t.cur; t.right = t.cur; t.allcells = new List <MapTile>(); t.wide = gettwidth(); tunnelerlife(t); }
void Update() { InfiniteSource source = (InfiniteSource)cavernSource; Tunneler.TunnelClips(ref source.Intro, intro, intro3D, ref introClipHash); Tunneler.TunnelClips(ref source.LoopClip, loopClip, loopClip3D, ref loopClipHash); SourceUpdate(); }
private int tnextstep(Tunneler t)//returns neighbour index for moving straight { //updtallcells();//_______________________________________________________________________________________________________________ int d = -1; for (int i = 0; i < 4; i++) { if (t.prev.neighbours[i] == t.cur) { d = i; break; } } return(d); }
private GameObject boardHolder; // GameObject that acts as a container for all other tiles. // Commence stewmaking void Start() { float startUp = Time.realtimeSinceStartup; boardHolder = new GameObject("BoardHolder"); SetUpBoard(ROWS, ROW_LENGTH); Tunneler tunnelLad = new Tunneler(100, 25); tunnelLad.Dig(ref tiles); for (int i = 0; i < RoomDiggers.Count; i++) { //Debug.Log (RoomDiggers [i] [0] + " " + RoomDiggers [i] [1]); RoomTunneler roomTunnel = new RoomTunneler(RoomDiggers [i] [0], RoomDiggers [i] [1]); roomTunnel.Activate(ref tiles); } print("Execution time of all board-gen scripts took " + (Time.realtimeSinceStartup - startUp) + " seconds."); }
// Dig out a (dimension * 2 + 1) x (dimension * 2 + 1) area from current position. // dimensions: 0 = 1x1 area // dimensions: 1 = 3x3 area // dimensions: 2 = 5x5 area // dimensions: 3 = 7x7 area public void DigArea(ref Tile[][] board, int curY, int curX, int dimensions) { for (int i = -dimensions; i < dimensions + 1; i++) { for (int j = -dimensions; j < dimensions + 1; j++) { if (board [curY + j] [curX + i].property == Tile.TileState.IS_WALL) { board [curY + j] [curX + i].property = Tile.TileState.IS_FLOOR; if (rng.Next(0, 100) < CHANCE_SPAWN_ROOM_TUNNELER) { BoardGenerator.RoomDiggers.Add(new int[] { this.x, this.y }); } } } } if (dimensions >= 2) { // Newly spawned tunnelers have 0.5x lifespan compared to their parent's lifespan. Tunneler babyTunneler = new Tunneler(this.x, this.y, (int)Math.Round(this.lifespan * NEW_TUNNELER_LIFESPAN)); babyTunneler.Dig(ref board); BoardGenerator.RoomDiggers.Add(new int[] { this.x, this.y }); } }
private Tunneler acttunneler(Tunneler t, int action)//action: 0-move straight, 1-turn, 2-cross other tunnel, 3-stepback&turn { updtallcells(); int d = tnextstep(t); t.prevactsuc = false; if (action == 0) { if (d == 1 || d == 3) { if (t.cur.neighbours[d].neighbours[0].type == 0 && t.cur.neighbours[d].neighbours[2].type == 0 && cellvalid(t.cur.neighbours[d])) { t.prev = t.cur; t.cur = t.prev.neighbours[d]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght--; t.prevactsuc = true; } } else if (d == 2 || d == 0) { if (t.cur.neighbours[d].neighbours[1].type == 0 && t.cur.neighbours[d].neighbours[3].type == 0 && cellvalid(t.cur.neighbours[d])) { t.prev = t.cur; t.cur = t.prev.neighbours[d]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght--; t.prevactsuc = true; } } } if (action == 1) { if (t.wide == 1) { int turn = choosetdir(t.cur, 0); if (turn < 0) { t.prevactsuc = false; } else { t.prev = t.cur; t.cur = t.cur.neighbours[turn]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght = t.lenght - 1; t.prevactsuc = true; } } else { bool l = true; bool r = true; Random rnd = new Random(); while (r || l) { int c = rnd.Next(0, 2); if (c == 0 || r == false) { l = false; int turn = choosetdir(t.left, 0); if (turn < 0) { t.prevactsuc = false; } else { t.prev = t.left; t.cur = t.left.neighbours[turn]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght = t.lenght - 1; t.prevactsuc = true; r = false; break; } } else { r = false; int turn = choosetdir(t.right, 0); if (turn < 0) { t.prevactsuc = false; } else { t.prev = t.right; t.cur = t.right.neighbours[turn]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght = t.lenght - 1; t.prevactsuc = true; l = false; break; } } } } } if (action == 2) { for (int i = 0; i < 5; i++) { t.prev = t.cur; t.cur = t.prev.neighbours[d]; if (t.cur.neighbours[d].type == 0) { t.prevactsuc = true; t = acttunneler(t, 0); break; } if (t.cur.type == 0) { break; } } } if (action == 3) { MapTile temp = t.cur; t.cur = t.prev; t.prev = temp; int turn = choosetdir(t.cur, 0); if (turn < 0) { t.prevactsuc = false; } else { Random r = new Random(); int ra = r.Next(0, 2); if (ra == 0) { t.prev.type = 0; floorcur = floorcur - 1; } else { widetun(t, 1); } t.prev = t.cur; t.cur = t.prev.neighbours[turn]; t.cur.type = 1; floorcur = floorcur + 1; t.lenght = t.lenght - 1; t.prevactsuc = true; } } return(t); }
private Tunneler widetun(Tunneler t, int type)//wide out tunnels//type- 0=regular, 1=wideprev, 2=widestraight(for making straight nit "cavelike" tunnels)(not implemented) { updtallcells(); int d = tnextstep(t); Random rnd = new Random(); if (d == 1 || d == 3) { int w = t.wide; MapTile left = t.cur; MapTile right = t.cur; if (type == 1) { left = t.prev; right = t.prev; } bool r = true; bool l = true; while ((l || r) && w > 1) { int chose = rnd.Next(0, 2); if (chose == 0) { if (cellvalid(left.neighbours[0]) && left.neighbours[0].neighbours[0].type == 0) { left = left.neighbours[0]; left.type = 1; t.left = left; w--; floorcur++; t.allcells.Add(left); } else { l = false; } } else { if (cellvalid(right.neighbours[2]) && right.neighbours[2].neighbours[2].type == 0) { right = right.neighbours[2]; right.type = 1; t.right = right; w--; floorcur++; t.allcells.Add(right); } else { r = false; } } } } else { int w = t.wide; MapTile left = t.cur; MapTile right = t.cur; if (type == 1) { left = t.prev; right = t.prev; } bool r = true; bool l = true; while ((l || r) && w > 1) { int chose = rnd.Next(0, 2); if (chose == 0) { if (cellvalid(left.neighbours[1]) && left.neighbours[1].neighbours[1].type == 0) { left = left.neighbours[1]; left.type = 1; t.left = left; w--; floorcur++; t.allcells.Add(left); } else { l = false; } } else { if (cellvalid(right.neighbours[3]) && right.neighbours[3].neighbours[3].type == 0) { right = right.neighbours[3]; right.type = 1; t.right = right; w--; floorcur++; t.allcells.Add(right); } else { r = false; } } } } return(t); }
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(); } }