public BanditArea CreateNewBand(MapData NewMapData, int BandID) { BanditArea newBand = new BanditArea(); newBand.Coverage = Random.Range(1, 4); CreateInCircle Borders = new CreateInCircle(); Borders.MapColumn = NewMapData.GenerateIndexes.Columns; Borders.MapRow = NewMapData.GenerateIndexes.Row; if (newBand.Coverage == 1) { int GetRandomTile = Random.Range(0, NewMapData.GenerateIndexes.Columns * NewMapData.GenerateIndexes.Row - 1); newBand.Coordinates = NewMapData.Tiles[GetRandomTile].TileID; } if (newBand.Coverage == 2) { int GetRandomTile = Random.Range(0, NewMapData.GenerateIndexes.Columns * NewMapData.GenerateIndexes.Row - 1); newBand.Coordinates = NewMapData.Tiles[GetRandomTile].TileID; Borders.TakeCell = newBand.Coordinates; Borders.GetBorders(); if (Borders.IdentifyRow == 1) { newBand.Coordinates += NewMapData.GenerateIndexes.Row; } if (Borders.IdentifyRow == NewMapData.GenerateIndexes.Row) { newBand.Coordinates -= NewMapData.GenerateIndexes.Row; } if (Borders.IdentifyColumn == 1) { newBand.Coordinates += 1; } if (Borders.IdentifyColumn == NewMapData.GenerateIndexes.Columns) { newBand.Coordinates -= 1; } } if (newBand.Coverage == 3) { int GetRandomTile = Random.Range(0, NewMapData.GenerateIndexes.Columns * NewMapData.GenerateIndexes.Row - 1); newBand.Coordinates = NewMapData.Tiles[GetRandomTile].TileID; Borders.TakeCell = newBand.Coordinates; Borders.GetBorders(); if (Borders.IdentifyRow < 3) { newBand.Coordinates += 2 * NewMapData.GenerateIndexes.Row; } if (Borders.IdentifyRow > NewMapData.GenerateIndexes.Row - 3) { newBand.Coordinates -= 2 * NewMapData.GenerateIndexes.Row; } if (Borders.IdentifyColumn < 3) { newBand.Coordinates += 2; } if (Borders.IdentifyColumn > NewMapData.GenerateIndexes.Columns - 3) { newBand.Coordinates -= 2; } } CreateInCircle circ = new CreateInCircle(); circ.TakeCell = newBand.Coordinates; circ.Radius = newBand.Coverage; circ.MapRow = NewMapData.GenerateIndexes.Row; circ.MapColumn = NewMapData.GenerateIndexes.Columns; circ.TakeRadius(); bool CheckCollision = false; foreach (int cell in circ.FullTiles) { if (NewMapData.Tiles[cell - 1].Empty == true) { CheckCollision = true; } else { CheckCollision = false; break; } } if (CheckCollision == true) { foreach (MapTileSample Tile in NewMapData.Tiles) { foreach (int Cell in circ.FullTiles) { if (Tile.TileID == Cell) { Tile.Empty = false; } } } int band = Random.Range(1, 4); if (band == 1) { newBand.Clan = "Trumans'"; } if (band == 2) { newBand.Clan = "Knackers"; } if (band == 3) { newBand.Clan = "Horde"; } int Populate = 0; if (newBand.Coverage == 1) { Populate = Random.Range(1, 5); newBand.Population = Populate; } if (newBand.Coverage == 2) { Populate = Random.Range(5, 10); newBand.Population = Populate; } if (newBand.Coverage == 3) { Populate = Random.Range(10, 15); newBand.Population = Populate; } newBand.NumberOfArea = BandID; return(newBand); } else { return(null); } }
public void GenerateMap() { MapData NewMapData = new MapData(); NewMapData.GenerateIndexes.Columns = 20; NewMapData.GenerateIndexes.Row = 20; StoreStack StoresStack = new StoreStack(); int TileID = 1; float Xcoord = -0.64f * (NewMapData.GenerateIndexes.Columns / 2) + 0.32f; float Ycoord = 0.64f * (NewMapData.GenerateIndexes.Row / 2) - 0.32f; for (int c = 1; c < NewMapData.GenerateIndexes.Columns + 1; c++) { for (int r = 1; r < NewMapData.GenerateIndexes.Row + 1; r++) { MapTileSample newTile = new MapTileSample(); newTile.TileID = TileID; newTile.Skin = Random.Range(0, 6); for (int a = 0; a < newTile.Smokes.Length; a++) { newTile.Smokes[a] = true; } newTile.Coordinates = new Vector3(Xcoord, Ycoord, 0.0f); newTile.Empty = true; NewMapData.Tiles.Add(newTile); Xcoord += 0.64f; TileID += 1; } Xcoord = -0.64f * (NewMapData.GenerateIndexes.Columns / 2) + 0.32f; Ycoord -= 0.64f; } int StoresNum = 20; for (int s = 0; s < StoresNum; s++) { string Type = ""; if (s == 0) { Type = "Slaves"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s == 1) { Type = "Stuff"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s == 2) { Type = "Bullets"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s == 3) { Type = "Guns"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s == 4) { Type = "Recycling"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s >= 5 && s < 10) { Type = "Stuff"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s >= 10 && s < 15) { Type = "Bullets"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (s >= 15) { int randNum = Random.Range(1, 6); if (randNum == 1) { Type = "Slaves"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (randNum == 2) { Type = "Guns"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (randNum == 3) { Type = "Bullets"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (randNum == 4) { Type = "Stuff"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } if (randNum == 5) { Type = "Recycling"; Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false); if (newstore != null) { NewMapData.GenerateIndexes.Stores.Add(newstore); } else { s -= 1; } } } } for (int a = 0; a < 10; a++) { BanditArea NewBand = CreateNewBand(NewMapData, a); if (NewBand != null) { NewMapData.GenerateIndexes.Bandits.Add(NewBand); } else { a -= 1; } } for (int o = 0; o < 10; o++) { int randPlace = Random.Range(0, NewMapData.Tiles.Count); if (NewMapData.Tiles[randPlace].Empty == true) { Obstacle newObst = new Obstacle(); newObst.Skin = Random.Range(1, 4); newObst.Place = randPlace; NewMapData.GenerateIndexes.Obstacles.Add(newObst); } else { o -= 1; } } string SaveData = JsonUtility.ToJson(NewMapData); StreamWriter WriteData = new StreamWriter(Application.persistentDataPath + "/MapData.json"); WriteData.Write(SaveData); WriteData.Close(); string SaveStores = JsonUtility.ToJson(StoresStack); StreamWriter WriteStores = new StreamWriter(Application.persistentDataPath + "/StoresStack.json"); WriteStores.Write(SaveStores); WriteStores.Close(); }