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 GenerateLocations() { LocationGenerator locationGenerator = new LocationGenerator(map, locationsMap, objectsMap, random); int minX = (int)(objectsMap.Width * 0.05), maxX = (int)(objectsMap.Width * 0.95); int minY = (int)(objectsMap.Height * 0.05), maxY = (int)(objectsMap.Height * 0.95); for (int i = minY; i < maxY; ++i) { for (int j = minX; j < maxX; ++j) { BiomModel biom = map[i, j].GetBiomModel(); if (biom.Locations.Any() && locationsMap.CanGenerateIn(new Vector2Int(j, i)) && random.Next(10000) / 100f < biom.LocationsIntensity) { LocationModel locationDataModel = rouletteWheelSelector.RouletteWheelSelection(biom.Locations); LocationInstance location = locationGenerator.GenerateLocation(locationDataModel, new Vector2Int(j, i)); if (location != null) { awaitingObjects.AddRange(location.BigObjects); awaitingObjects.AddRange(location.Objects); awaitingObjects.AddRange(location.Fence); locationsMap.MarkLocation(location); } } } } }
public bool[,] RandomLocationShape(Vector2Int startingPos, int locationSize) { this.startingPos = startingPos; bool[,] locationShapeMap = new bool[locationsMap.Height, locationsMap.Width]; possibleBlocksPositions = new List <PriorityModel <Vector2Int> >() { new PriorityModel <Vector2Int> { Priority = 1, Model = startingPos } }; while (locationSize > 0 && possibleBlocksPositions.Count > 0) { Vector2Int selectedPosition = rouletteWheelSelector.RouletteWheelSelection(possibleBlocksPositions); locationShapeMap[selectedPosition.Y, selectedPosition.X] = true; AddNeighbors(locationShapeMap, selectedPosition); possibleBlocksPositions.Remove(possibleBlocksPositions.Find(b => b.Model.Equals(selectedPosition))); locationSize--; } return(locationShapeMap); }