示例#1
0
        public static WfcGraphTile <WorldData> CreateRoadTile(string roadName, Blackboard initialBlackboard)
        {
            Graph  roadGraph  = Graph.CreatePlaceholder(roadName);
            Entity roadEntity = new Entity(roadName, roadGraph);

            roadGraph.Entities.Add(roadEntity);
            var blackboardRoadCountKey = IncrementBlackboardCount(roadName, initialBlackboard);

            WfcGraphTile <WorldData> roadTile = new WfcGraphTile <WorldData>(roadGraph, (thisModule, thisCell, wfcSpace) =>
            {
                bool isTileAvailable = wfcSpace.Blackboard.IsGreaterZero(blackboardRoadCountKey);

                var neighbors = wfcSpace.GetNeighbors(thisCell);
                if (!CanConnect(thisModule, neighbors))
                {
                    return(false);
                }

                return(isTileAvailable);
            });

            roadTile.TileDescriptor.AddBorderEntity(roadEntity, 2, 2);
            roadTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.Road);

            return(roadTile);
        }
示例#2
0
        private static bool CanConnect(WfcGraphTile <WorldData> thisModule, List <WfcCell <WfcGraphTile <WorldData>, int> > neighbors)
        {
            uint availableTotalConnections = thisModule.TileDescriptor.BorderEntities
                                             .Select(bn => bn.TotalConnections)
                                             .Aggregate((c1, c2) => c1 + c2);

            if (neighbors.Count > availableTotalConnections)
            {
                return(false);
            }

            uint availableMandatoryConnections = thisModule.TileDescriptor.BorderEntities
                                                 .Select(bn => bn.MandatoryConnections)
                                                 .Aggregate((c1, c2) => c1 + c2);

            if (neighbors.Count < availableMandatoryConnections)
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        public static WfcGraphTile <WorldData> CreateCityTile(string cityName, Blackboard initialBlackboard)
        {
            var cityGraph  = Graph.CreatePlaceholder(cityName);
            var cityEntity = new Entity(cityName, cityGraph);

            cityGraph.Entities.Add(cityEntity);
            var blackboardCityCountKey = IncrementBlackboardCount(cityName, initialBlackboard);

            var cityTile = new WfcGraphTile <WorldData>(cityGraph, (thisModule, thisCell, wfcSpace) =>
            {
                if (!wfcSpace.Blackboard.IsGreaterZero(blackboardCityCountKey))
                {
                    return(false);
                }

                var neighbors = wfcSpace.GetNeighbors(thisCell);
                if (!CanConnect(thisModule, neighbors))
                {
                    return(false);
                }

                foreach (var neighbor in neighbors)
                {
                    if (!NeighborHasRoadLikeStructure(neighbor))
                    {
                        return(false);
                    }
                }

                return(true);
            });

            cityTile.TileDescriptor.AddBorderEntity(cityEntity, 1, 3);
            cityTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.City);

            return(cityTile);
        }
示例#4
0
        public static WfcGraphTile <WorldData> CreateSpecialTile(string tileName, Blackboard initialBlackboard, uint mandatoryConnections = 1, uint optionalConnections = 0)
        {
            var specialGraph  = Graph.CreatePlaceholder(tileName);
            var specialEntity = new Entity(tileName, specialGraph);

            specialGraph.Entities.Add(specialEntity);
            var blackboardTileCountKey = IncrementBlackboardCount(tileName, initialBlackboard);

            var specialTile = new WfcGraphTile <WorldData>(specialGraph, (thisModule, thisCell, wfcSpace) =>
            {
                if (!wfcSpace.Blackboard.IsGreaterZero(blackboardTileCountKey))
                {
                    return(false);
                }

                var neighbors = wfcSpace.GetNeighbors(thisCell);
                if (!CanConnect(thisModule, neighbors))
                {
                    return(false);
                }

                foreach (var neighbor in neighbors)
                {
                    if (!NeighborHasRoadLikeStructure(neighbor))
                    {
                        return(false);
                    }
                }

                return(true);
            });

            specialTile.TileDescriptor.AddBorderEntity(specialEntity, mandatoryConnections, optionalConnections);
            specialTile.TileDescriptor.AdditionalTileData = new WorldData(TileType.City);

            return(specialTile);
        }