Beispiel #1
0
        public static IntermediateMap CreateMap(ParcelJsonConfiguration configuration)
        {
            IntermediateMap emptyMap = new IntermediateMap(configuration.primaryParcel.sizeX, configuration.primaryParcel.sizeY, configuration.primaryParcel.sizeZ, Block.AIR, new Palette(0));

            List <Parcel> loadedParcels = createDivisionParcels(configuration.plotDivisions);

            loadedParcels.AddRange(configuration.insertParcels);

            FillParcel(emptyMap, configuration.primaryParcel, loadedParcels, 0, 0, 0, false, configuration);
            return(emptyMap);
        }
Beispiel #2
0
        static Parcel findMatchingParcel(Plot plot, List <Plot> otherPlots, List <Parcel> parcels, ParcelJsonConfiguration configuration)
        {
            List <string> connectionsNamesMatch = new List <string>();

            for (int i = 0; i < 6; i++)
            {
                string connectionName = plot.connections.connectionNames[i];
                if (configuration.connections.Exists(candidate => candidate.name == connectionName))
                {
                    connectionsNamesMatch.Add(connectionName);
                }
                else
                {
                    Plot adjacentPlot = otherPlots.Find(candidate => candidate.plotID == connectionName);
                    if (adjacentPlot == null)
                    {
                        Console.WriteLine("Plot had connection that matched no connection name or plot ID: " + connectionName);
                        throw new Exception("Plot had connection that matched no connection name or plot ID: " + connectionName);
                    }
                    else
                    {
                        int matchingDirection;
                        if (i % 2 == 0)
                        {
                            matchingDirection = i + 1;
                        }
                        else
                        {
                            matchingDirection = i - 1;
                        }
                        string matchingName = adjacentPlot.connections.connectionNames[matchingDirection];
                        if (matchingName == plot.plotID)
                        {
                            connectionsNamesMatch.Add("");
                        }
                        else
                        {
                            connectionsNamesMatch.Add(matchingName);
                        }
                    }
                }
            }
            Connections matchingConnections = new Connections(connectionsNamesMatch);

            List <Parcel> candidates = parcels.FindAll(candidate => matchingConnections.matchesParcel(candidate.connections) &&
                                                       candidate.sizeX == plot.sizeX && candidate.sizeY == plot.sizeY && candidate.sizeZ == plot.sizeZ);

            if (candidates.Count == 0)
            {
                Console.WriteLine("Found no parcel matching plot size X" + plot.sizeX + "Y" + plot.sizeY + "Z" + plot.sizeZ +
                                  " Connections " + plot.connections.ToString());
                throw new Exception("No matching parcel!");
            }

            var    random       = new Random();
            int    index        = random.Next(candidates.Count);
            Parcel chosenParcel = candidates[index];

            plot.connections.addParcelConnections(chosenParcel.connections);
            return(chosenParcel);
        }
Beispiel #3
0
        static void FillParcel(IntermediateMap map, Parcel parcel, List <Parcel> loadedParcels, int offsetX, int offsetY, int offsetZ, bool hasDonePalette, ParcelJsonConfiguration configuration)
        {
            //If no sourcefile, skip, well, sourcefile! and just plop in plots
            if (!emptySourceFileNames.Contains(parcel.sourceFile))
            {
                ParcelVoxReader parcelReader = new ParcelVoxReader();
                VoxReader       r            = new VoxReader(parcel.sourceFile, parcelReader);
                r.Read();

                parcelReader.insertReadParcel(map, offsetX, offsetY, offsetZ);

                //Do the palette
                if (!hasDonePalette)
                {
                    hasDonePalette = loadPalette(map, parcelReader.palette);
                }
            }

            foreach (Plot plot in parcel.parcelPlots)
            {
                Parcel insertParcel = findMatchingParcel(plot, parcel.parcelPlots, loadedParcels, configuration);

                FillParcel(map, insertParcel, loadedParcels, offsetX + plot.offsetX, offsetY + plot.offsetY, offsetZ + plot.offsetZ, hasDonePalette, configuration);
            }
        }