private void GenerateObjects() { for (int i = 0; i < objectsMap.Height; ++i) { for (int j = 0; j < objectsMap.Width; j++) { BiomModel biom = map[i, j].GetBiomModel(); if (objectsMap.IsTileEmpty(new Vector2Int(j, i)) && biom.Objects.Any() && random.Next(10000) / 100f < biom.ObjectsIntensity) { ObjectModel objectModel = rouletteWheelSelector.RouletteWheelSelection(biom.Objects); AwaitingObject awaitingObject = new AwaitingObject() { AbstractObject = objectModel.AbstractObject, Position = new Vector2Float(j, i) }; awaitingObjects.Add(awaitingObject); objectsMap.MarkTiles(new Vector2Int(j, i), ObjectsMap.ObjectType.Object); } } } }
private void GenerateTrees() { for (int i = 0; i < objectsMap.Height; ++i) { for (int j = 0; j < objectsMap.Width; j++) { if (objectsMap.AreNeighboringTilesEmpty(new Vector2Int(j, i)) && map[i, j].GetBiomModel().Trees.Any() && random.Next(10000) / 100f < map[i, j].GetBiomModel().TreesIntensity) { TreeModel model = rouletteWheelSelector.RouletteWheelSelection(map[i, j].GetBiomModel().Trees); AwaitingObject awaitingObject = new AwaitingObject() { AbstractObject = model.AbstractObject, Position = new Vector2Float(j, i), Scale = random.Next((int)(model.MinScale * 100), (int)(model.MaxScale * 100)) / 100f }; awaitingObjects.Add(awaitingObject); objectsMap.MarkTiles(new Vector2Int(j, i), ObjectsMap.ObjectType.Tree); } } } }
private void GenerateBigObjects(LocationInstance location) { List <PriorityModel <BigObjectModel> > bigObjectPossibleToGenerate = new List <PriorityModel <BigObjectModel> >(location.Template.BigObjects); Dictionary <BigObjectModel, int> bigObjectModelCountDictionaty = new Dictionary <BigObjectModel, int>(); bigObjectPossibleToGenerate.ForEach(model => bigObjectModelCountDictionaty[model.Model] = model.MaxCount); foreach (Vector2Int pos in location.Shape.SpaceTilesPositions) { if (bigObjectPossibleToGenerate.Any() && random.RandomByThreshold(location.Template.BigObjectsIntensity)) { BigObjectModel prefab = rouletteWheelSelector.RouletteWheelSelection(bigObjectPossibleToGenerate); List <Vector2Int> positions = SelectPositions(pos, new Vector2Int(pos.X + prefab.TileWidthCount - 1, pos.Y + prefab.TileHeightCount - 1)).ToList(); if (objectsMap.AreTilesEmpty(positions) && positions.All(p => location.Shape.ShapeMap[p.Y, p.X] == LocationTileType.Space)) { bigObjectModelCountDictionaty[prefab]--; if (bigObjectModelCountDictionaty[prefab] == 0) { bigObjectPossibleToGenerate.Remove(bigObjectPossibleToGenerate.Find(x => x.Model == prefab)); } AwaitingObject awaitingObject = new AwaitingObject() { AbstractObject = prefab.AbstractObject, Position = new Vector2Float(pos.X + (prefab.TileWidthCount - 1) / 2f, pos.Y) }; location.BigObjects.Add(awaitingObject); objectsMap.MarkTiles(pos, new Vector2Int(pos.X + prefab.TileWidthCount - 1, pos.Y + prefab.TileHeightCount - 1), ObjectsMap.ObjectType.BigObject); } } } }
private void GenerateObjects(LocationInstance location) { foreach (Vector2Int blockPos in location.Shape.SpaceTilesPositions) { if (objectsMap.IsTileEmpty(blockPos) && location.Template.Objects.Any() && random.RandomByThreshold(location.Template.ObjectsIntensity)) { ObjectModel prefab = rouletteWheelSelector.RouletteWheelSelection(location.Template.Objects); AwaitingObject awaitingObject = new AwaitingObject() { AbstractObject = prefab.AbstractObject, Position = new Vector2Float(blockPos.X, blockPos.Y) }; location.Objects.Add(awaitingObject); objectsMap.MarkTiles(blockPos, ObjectsMap.ObjectType.Object); } } }
private void GenerateFence(LocationInstance location) { LocationEntranceGenerator locationEnteranceGenerator = new LocationEntranceGenerator(random, location.Shape); if (locationEnteranceGenerator.IsFenceGenerated) { FenceModel fence = rouletteWheelSelector.RouletteWheelSelection(location.Template.Fences); foreach (var borderTile in locationEnteranceGenerator.BorderTiles) { AwaitingObject awaitingObject = new AwaitingObject() { AbstractObject = fence.GetFancePart(borderTile.NeighboursArray).AbstractObject, Position = new Vector2Float(borderTile.Position.X, borderTile.Position.Y) }; location.Fence.Add(awaitingObject); objectsMap.MarkTiles(borderTile.Position, ObjectsMap.ObjectType.Fance); } } }