private bool IsBlockOnShapeBorder(Vector2Int pos) { bool blockOnShapeBorder = false; for (int i = pos.Y - 1; i <= pos.Y + 1; ++i) { for (int j = pos.X - 1; j <= pos.X + 1; ++j) { if (locationsMap.IsOnMap(new Vector2Int(j, i))) { LocationInstance location = locationsMap.GetTileLocation(new Vector2Int(j, i)); if (location != null && !NeighboringLocations.Contains(location)) { NeighboringLocations.Add(location); } if (!locationShapeMap[i, j]) { blockOnShapeBorder = true; } } } } return(blockOnShapeBorder); }
public void MarkLocation(LocationInstance location) { foreach (Vector2Int tilePosition in location.Tiles) { locationsTiles[tilePosition.Y, tilePosition.X].SetLocation(location); } }
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); } } } } }
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); } } } }
public LocationInstance GenerateLocation(LocationModel locationTemplate, Vector2Int startingPosition) { LocationInstance location = new LocationInstance(locationTemplate); int size = random.Next(locationTemplate.MinSize, locationTemplate.MaxSize); location.Shape = new LocationShape(tilesMap, locationsMap, random, startingPosition, size); if (location.Shape.AllTilesPositions.Count >= locationTemplate.MinSize) { location.Tiles.AddRange(location.Shape.AllTilesPositions); GenerateBigObjects(location); GenerateObjects(location); if (locationTemplate.Fences.Any() && random.RandomByThreshold(locationTemplate.ChanceForFence) && location.BigObjects.Any() && location.Shape.IsShapeCorrect() && location.Shape.NeighboringLocations.All(l => !l.HasFence)) { GenerateFence(location); } return(location); } return(null); }
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); } } }
public void SetLocation(LocationInstance location) { LocationTileType = LocationTileType.Location; Location = location; }