Ejemplo n.º 1
0
        private bool NewZonePlacementCallback(bool cancelled, Point location, object arg)
        {
            NewZoneData zoneData = (NewZoneData)arg;

            if (!cancelled)
            {
                // Check to see if the new zone overlaps any existing tiles
                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);
                        MapTile tile      = worldMap.GetTile(tileCoord);
                        if (tile != null)
                        {
                            // overlaps existing tiles
                            return(false);
                        }
                    }
                }

                MapZone zone = worldMap.CreateZone(zoneData.ZoneName);

                int samplesPerTile = WorldMap.metersPerTile / zoneData.MetersPerSample;

                ValueMapLayer heightFieldLayer = worldMap.HeightFieldLayer as ValueMapLayer;

                for (int z = 0; z < zoneData.TilesHeight; z++)
                {
                    int dz = z + gridOffset.z + location.Y;
                    for (int x = 0; x < zoneData.TilesWidth; x++)
                    {
                        int dx = x + gridOffset.x + location.X;

                        CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize);

                        MapBuffer tileHeightmap = heightFieldLayer.CreateCompatibleMapBuffer(zoneData.Heightmap, zoneData.MetersPerSample,
                                                                                             x * samplesPerTile, z * samplesPerTile, samplesPerTile, zoneData.MinHeight, zoneData.MaxHeight);

                        MapTile tile = worldMap.CreateTile(tileCoord);
                        tile.Zone = zone;

                        if (tileHeightmap.MetersPerSample != heightFieldLayer.MetersPerSample)
                        {
                            tileHeightmap = tileHeightmap.Scale(worldMap.MetersPerTile / heightFieldLayer.MetersPerSample);
                        }

                        heightFieldLayer.CopyIn(tileCoord, tileHeightmap);

                        ImageGridCell cell = imageGrid.CreateCell(x + location.X, z + location.Y);

                        cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize);
                    }
                }

                AddZone(zone);
            }
            return(true);
        }