Example #1
0
        private Region LoadOrGenerateRegion(Coordinates2D coordinates, bool generate = true)
        {
            if (Regions.ContainsKey(coordinates))
            {
                return((Region)Regions[coordinates]);
            }
            if (!generate)
            {
                return(null);
            }
            Region region;

            if (BaseDirectory != null)
            {
                var file = Path.Combine(BaseDirectory, Region.GetRegionFileName(coordinates));
                if (File.Exists(file))
                {
                    region = new Region(coordinates, this, file);
                }
                else
                {
                    region = new Region(coordinates, this);
                }
            }
            else
            {
                region = new Region(coordinates, this);
            }
            lock (Regions)
                Regions[coordinates] = region;
            return(region);
        }
Example #2
0
        public static Coordinates2D GetRelativeChunkPosition(Coordinates2D coordinates)
        {
            int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0);
            int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0);

            return(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
        }
Example #3
0
        public static void HandleChunkPreamble(IPacket _packet, MultiplayerClient client)
        {
            var packet = (ChunkPreamblePacket)_packet;
            var coords = new Coordinates2D(packet.X, packet.Z);

            client.World.SetChunk(coords, new Chunk(coords));
        }
Example #4
0
 public Model(Coordinates2D min, Coordinates2D max, int wolfCount, int preyCount)
 {
     this.min = min;
     this.max = max;
     this.wolfCount = wolfCount;
     this.preyCount = preyCount;
 }
Example #5
0
 public IChunk GenerateChunk(IWorld world, Coordinates2D position)
 {
     var chunk = new Chunk(position);
     int y = 0;
     for (int i = 0; i < Layers.Count; i++)
     {
         int height = y + Layers[i].Height;
         while (y < height)
         {
             for (int x = 0; x < 16; x++)
             {
                 for (int z = 0; z < 16; z++)
                 {
                     chunk.SetBlockID(new Coordinates3D(x, y, z), Layers[i].BlockId);
                     chunk.SetMetadata(new Coordinates3D(x, y, z), Layers[i].Metadata);
                 }
             }
             y++;
         }
     }
     for (int i = 0; i < chunk.Biomes.Length; i++)
         chunk.Biomes[i] = (byte)Biome;
     chunk.TerrainPopulated = true;
     chunk.UpdateHeightMap();
     return chunk;
 }
Example #6
0
 public static bool IsCuboidCorner(Coordinates2D location, Coordinates3D start, Vector3 size)
 {
     return(location.X.Equals(start.X) && location.Z.Equals(start.Z) ||
            location.X.Equals(start.X) && location.Z.Equals(start.Z + (int)size.Z - 1) ||
            location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z) ||
            location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z + (int)size.Z - 1));
 }
        public IChunk GenerateChunk(IWorld world, Coordinates2D position)
        {
            var chunk = new Chunk(position);
            int y     = 0;

            for (int i = 0; i < Layers.Count; i++)
            {
                int height = y + Layers[i].Height;
                while (y < height)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        for (int z = 0; z < 16; z++)
                        {
                            chunk.SetBlockID(new Coordinates3D(x, y, z), Layers[i].BlockId);
                            chunk.SetMetadata(new Coordinates3D(x, y, z), Layers[i].Metadata);
                        }
                    }
                    y++;
                }
            }
            for (int i = 0; i < chunk.Biomes.Length; i++)
            {
                chunk.Biomes[i] = (byte)Biome;
            }
            chunk.TerrainPopulated = true;
            chunk.UpdateHeightMap();
            return(chunk);
        }
        private Cell <LangtonsAntCellMetadata> ProgressCell(Cell <LangtonsAntCellMetadata> currentCell, Direction2D direction)
        {
            var newCoordinates = new Coordinates2D(currentCell.Coordinates.X, currentCell.Coordinates.Y);

            switch (direction)
            {
            case Direction2D.Up:
                newCoordinates.Y -= 1;
                break;

            case Direction2D.Right:
                newCoordinates.X += 1;
                break;

            case Direction2D.Down:
                newCoordinates.Y += 1;
                break;

            case Direction2D.Left:
                newCoordinates.X -= 1;
                break;

            default:
                throw new InvalidOperationException("Invalid direction.");
            }

            if (newCoordinates.X < 0 || newCoordinates.X >= _grid.Dimensions.Width ||
                newCoordinates.Y < 0 || newCoordinates.Y >= _grid.Dimensions.Height)
            {
                return(null);
            }

            return(_grid[newCoordinates]);
        }
Example #9
0
        public Chunk GenerateChunk(Coordinates2D position)
        {
            var chunk = new Chunk(position);
            int y     = 0;

            for (int i = 0; i < Layers.Count; i++)
            {
                int height = y + Layers[i].Height;
                while (y < height)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        for (int z = 0; z < 16; z++)
                        {
                            chunk.SetBlockId(new Coordinates3D(x, y, z), Layers[i].BlockId);
                            chunk.SetMetadata(new Coordinates3D(x, y, z), Layers[i].Metadata);
                        }
                    }
                    y++;
                }
            }
            for (int i = 0; i < chunk.Biomes.Length; i++)
            {
                chunk.Biomes[i] = (byte)Biome;
            }
            return(chunk);
        }
Example #10
0
 internal void RemoveChunk(Coordinates2D coordinates)
 {
     if (UnloadChunks)
     {
         World.UnloadChunk(coordinates);
     }
 }
Example #11
0
        public void DamageChunk(Coordinates2D coords)
        {
            int x = coords.X / Region.Width - ((coords.X < 0) ? 1 : 0);
            int z = coords.Z / Region.Depth - ((coords.Z < 0) ? 1 : 0);

            DirtyChunks.Add(new Coordinates2D(coords.X - x * 32, coords.Z - z * 32));
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Coordinates = Coordinates2D.FromReaderInt(reader);
            RecordList = RecordList.FromReader(reader);

            return this;
        }
Example #13
0
 /// <summary>
 ///  Sets the chunk at the specified local position to the given value.
 /// </summary>
 public void SetChunk(Coordinates2D position, IChunk chunk)
 {
     Chunks[position] = chunk;
     chunk.IsModified = true;
     DirtyChunks.Add(position);
     chunk.ParentRegion = this;
 }
 static void Main(string[] args)
 {
     //connect to mongodb
     new DB("test");
     //create a geo2dsphere index
     DB.Index<Place>()
       .Key(x => x.Location, KeyType.Geo2DSphere)
       .Option(x => x.Background = false)
       .Create();
     //create and save a place
     var paris = new Place
     {
         Name = "paris",
         Location = new Coordinates2D(48.8539241, 2.2913515),
         Date = DateTime.UtcNow
     };
     paris.Save();
    
     var eiffelTower = new Coordinates2D(48.857908, 2.295243);
     //find all places within 1km of eiffel tower.
     var places = DB.GeoNear<Place>(
                       NearCoordinates: eiffelTower,
                       DistanceField: x => x.DistanceMeters,
                       MaxDistance: 1000)
                    .SortByDescending(x=>x.Date)
                    .ToList();
 }
Example #15
0
        private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
        {
            var coordinates = new Coordinates2D(x, z);
            var relativePosition = GetRelativeChunkPosition(coordinates);
            var chunk = new Chunk(relativePosition);
            var sectionCount = GetSectionCount(primaryBitMap);

            // Run through the sections
            // TODO: Support block IDs >255
            for (int y = 0; y < 16; y++)
            {
                if ((primaryBitMap & (1 << y)) > 0)
                {
                    // Blocks
                    Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
                    // Metadata
                    Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
                    // Light
                    Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
                    // Sky light
                    if (lightIncluded)
                    {
                        Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                            chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
                    }
                }
            }
            if (groundUp)
                Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
            client.World.SetChunk(coordinates, chunk);
            //client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
        }
Example #16
0
        public void DamageChunk(Coordinates2D coords)
        {
            var x = coords.X / Width - (coords.X < 0 ? 1 : 0);
            var z = coords.Z / Depth - (coords.Z < 0 ? 1 : 0);

            DirtyChunks.Add(new Coordinates2D(coords.X - x * 32, coords.Z - z * 32));
        }
Example #17
0
 public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location)
 {
     double temp = Math.Abs(TempNoise.Value2D(location.X, location.Z));
     double rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
     byte ID = biomes.GetBiome(temp, rainfall).ID;
     return ID;
 }
Example #18
0
        public static Coordinates2D ChunkCoordinatesToWorld(Coordinates2D coordinates)
        {
            var chunkX = coordinates.X * Chunk.Width;
            var chunkZ = coordinates.Z * Chunk.Depth;

            return(new Coordinates2D(chunkX, chunkZ));
        }
Example #19
0
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Coordinates = Coordinates2D.FromReaderInt(reader);
            RecordList  = RecordList.FromReader(reader);

            return(this);
        }
Example #20
0
 public static bool IsCuboidCorner(Coordinates2D location, Coordinates3D start, Vector3 size)
 {
     return location.X.Equals(start.X) && location.Z.Equals(start.Z)
         || location.X.Equals(start.X) && location.Z.Equals(start.Z + (int)size.Z - 1)
         || location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z)
         || location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z + (int)size.Z - 1);
 }
Example #21
0
        public void FindNearestIntersectionPoint_NoMove_from_50_50()
        {
            _initialCoordinates        = new BallCoordinates(50, 50, DateTime.Now);
            _initialCoordinates.Vector = new Vector2D(0, 0);

            Coordinates2D actualResult = _testAsset.FindNearestIntersectionPoint(_initialCoordinates);
        }
 static void Main(string[] args)
 {
     new DB("test");
     DB.Index <Announcement>()
     .Key(a => a.CollectionLocation, KeyType.Geo2DSphere)
     .Create();
     DB.Index <Announcement>()
     .Key(a => a.DepositLocation, KeyType.Geo2DSphere)
     .Create();
     (new Announcement
     {
         DepositLocation = new Coordinates2D(48.8539241, 2.2913515),
         CollectionLocation = new Coordinates2D(48.796964, 2.137456)
     }).Save();
     var searchPointA = new Coordinates2D(48.796964, 2.137456);
     var queryA       = DB.GeoNear <Announcement>(
         NearCoordinates: searchPointA,
         DistanceField: a => a.DistanceMeters,
         IndexKey: "CollectionLocation",
         MaxDistance: 10);
     var searchPointB = new Coordinates2D(48.8539241, 2.2913515);
     var queryB       = DB.GeoNear <Announcement>(
         NearCoordinates: searchPointB,
         DistanceField: a => a.DistanceMeters,
         IndexKey: "DepositLocation",
         MaxDistance: 10);
     var resultA = queryA.ToList();
     var resultB = queryB.ToList();
     var common  = resultA.Where(a => resultB.Any(b => b.ID == a.ID)).ToArray();
 }
Example #23
0
        public void GenerateChunk(Coordinates2D coordinates)
        {
            int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0);
            int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0);

            var region = LoadOrGenerateRegion(new Coordinates2D(regionX, regionZ));
            region.GenerateChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
        }
Example #24
0
 public static Position GetSectionCoordinates(Position coordinates, Coordinates2D chunkCoordinates)
 {
     return(new Position(
                Math.Abs(coordinates.X - (chunkCoordinates.X * 16)),
                coordinates.Y % 16,
                coordinates.Z % chunkCoordinates.Z
                ));
 }
Example #25
0
        public void GenerateChunk(Coordinates2D coordinates)
        {
            var regionPosition = ChunkCoordinatesToRegion(coordinates);

            var region = LoadOrGenerateRegion(regionPosition);

            region.GenerateChunk(new Coordinates2D(coordinates.X - regionPosition.X * 32, coordinates.Z - regionPosition.Z * 32));
        }
Example #26
0
        public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location, bool spawn)
        {
            var temp     = Math.Abs(TempNoise.Value2D(location.X, location.Z));
            var rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
            var Id       = biomes.GetBiome(temp, rainfall, spawn).Id;

            return(Id);
        }
 public LangtonsAntIterationCellGenerator(LangtonsAnt game, Grid <LangtonsAntCellMetadata> grid, IGridRenderer <LangtonsAntCellMetadata> gridRenderer, Coordinates2D antCoordinates, Direction2D antDirection)
 {
     _game          = game;
     _grid          = grid;
     _gridRenderer  = gridRenderer;
     AntCoordinates = antCoordinates;
     AntDirection   = antDirection;
 }
Example #28
0
 public void UnloadRegion(Coordinates2D coordinates)
 {
     lock (Regions)
     {
         Regions[coordinates].Save(Path.Combine(BaseDirectory, Region.GetRegionFileName(coordinates)));
         Regions.Remove(coordinates);
     }
 }
Example #29
0
        public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location)
        {
            double temp     = Math.Abs(TempNoise.Value2D(location.X, location.Z));
            double rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
            byte   ID       = biomes.GetBiome(temp, rainfall).ID;

            return(ID);
        }
Example #30
0
 byte GetBiome(IWorld world, Coordinates2D location)
 {
     if (SingleBiome)
     {
         return(GenerationBiome);
     }
     return(world.BiomeDiagram.GetBiome(location));
 }
Example #31
0
 /// <summary>
 /// Sets the chunk at the specified local position to the given value.
 /// </summary>
 public void SetChunk(Coordinates2D position, IChunk chunk)
 {
     if (!Chunks.ContainsKey(position))
     {
         Chunks.Add(position, chunk);
     }
     chunk.IsModified = true;
     Chunks[position] = chunk;
 }
Example #32
0
 public CellGraphic getCell(Coordinates coord)
 {
     if (coord.GetType() == typeof(Coordinates2D))
     {
         Coordinates2D c = (Coordinates2D)coord;
         return(cells[c.getX(), c.getY()]);
     }
     return(null);
 }
Example #33
0
        public void GenerateChunk(Coordinates2D coordinates)
        {
            int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0);
            int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0);

            var region = LoadOrGenerateRegion(new Coordinates2D(regionX, regionZ));

            region.GenerateChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
        }
Example #34
0
 public void FindIntersectionVector_LeftBorder()
 {
     Coordinates2D intersection = new Coordinates2D(XMIN, 200);
     Vector2D vector = new Vector2D(-140, -20);
     Vector2D actualVector = _testAsset.FindIntersectionVector(vector, intersection);
     Vector2D expectedVector = new Vector2D(140 * RICOCHE, -20 * RICOCHE);
     Assert.AreEqual(expectedVector.X, actualVector.X);
     Assert.AreEqual(expectedVector.Y, actualVector.Y);
 }
Example #35
0
 public void FindIntersectionVector_UpperBorder()
 {
     Coordinates2D intersection = new Coordinates2D(500, YMAX);
     Vector2D vector = new Vector2D(-100,50);
     Vector2D actualVector = _testAsset.FindIntersectionVector(vector, intersection);
     Vector2D expectedVector = new Vector2D(-100 * RICOCHE, -50 * RICOCHE);
     Assert.AreEqual(expectedVector.X, actualVector.X);
     Assert.AreEqual(expectedVector.Y, actualVector.Y);
 }
Example #36
0
 public void FindIntersectionVector_ButtomBorder()
 {
     Coordinates2D intersection = new Coordinates2D(750, YMIN);
     Vector2D vector = new Vector2D(50, -300);
     Vector2D actualVector = _testAsset.FindIntersectionVector(vector, intersection);
     Vector2D expectedVector = new Vector2D(50 * RICOCHE, 300 * RICOCHE);
     Assert.AreEqual(expectedVector.X, actualVector.X);
     Assert.AreEqual(expectedVector.Y, actualVector.Y);
 }
Example #37
0
        public void GenerateChunk(Coordinates2D position)
        {
            var globalPosition = (Position * new Coordinates2D(Width, Depth)) + position;
            var chunk          = World.ChunkProvider.GenerateChunk(World, globalPosition);

            chunk.IsModified  = true;
            chunk.Coordinates = globalPosition;
            Chunks.Add(position, (IChunk)chunk);
        }
Example #38
0
        public static Chunk FromReader(IMinecraftDataReader reader)
        {
            var overWorld     = true;// TODO: From World class
            var coordinates   = new Coordinates2D(reader.ReadInt(), reader.ReadInt());
            var groundUp      = reader.ReadBoolean();
            var primaryBitMap = reader.ReadUShort();

            var value = new Chunk(coordinates);

            value.OverWorld     = overWorld;
            value.GroundUp      = groundUp;
            value.PrimaryBitMap = primaryBitMap;

            var size = reader.ReadVarInt();
            var data = reader.ReadByteArray(size);

            var sectionCount = GetSectionCount(value.PrimaryBitMap);

            var chunkRawBlocks      = new byte[sectionCount * TwoByteData];
            var chunkRawBlocksLight = new byte[sectionCount * HalfByteData];
            var chunkRawSkylight    = new byte[sectionCount * HalfByteData];

            Array.Copy(data, 0, chunkRawBlocks, 0, chunkRawBlocks.Length);
            Array.Copy(data, chunkRawBlocks.Length, chunkRawBlocksLight, 0, chunkRawBlocksLight.Length);
            Array.Copy(data, chunkRawBlocks.Length + chunkRawBlocksLight.Length, chunkRawSkylight, 0, chunkRawSkylight.Length);

            for (int y = 0, i = 0; y < 16; y++)
            {
                if ((value.PrimaryBitMap & (1 << y)) > 0)
                {
                    // Blocks & Metadata
                    var rawBlocks = new byte[TwoByteData];
                    Array.Copy(chunkRawBlocks, i * rawBlocks.Length, rawBlocks, 0, rawBlocks.Length);

                    // Light, convert to 1 byte per block
                    var rawBlockLight = new byte[HalfByteData];
                    Array.Copy(chunkRawSkylight, i * rawBlockLight.Length, rawBlockLight, 0, rawBlockLight.Length);

                    // Sky light, convert to 1 byte per block
                    var rawSkyLight = new byte[HalfByteData];
                    if (value.OverWorld)
                    {
                        Array.Copy(chunkRawSkylight, i * rawSkyLight.Length, rawSkyLight, 0, rawSkyLight.Length);
                    }

                    value.Sections[i].BuildFromRawData(rawBlocks, rawBlockLight, rawSkyLight);
                    i++;
                }
            }
            if (value.GroundUp)
            {
                Array.Copy(data, data.Length - value.Biomes.Length, value.Biomes, 0, value.Biomes.Length);
            }

            return(value);
        }
Example #39
0
 /// <summary>
 /// Retrieves the requested chunk from the region, or
 /// generates it if a world generator is provided.
 /// </summary>
 /// <param name="position">The position of the requested local chunk coordinates.</param>
 public IChunk GetChunk(Coordinates2D position, bool generate = true)
 {
     // TODO: This could use some refactoring
     lock (Chunks)
     {
         if (!Chunks.ContainsKey(position))
         {
             if (regionFile != null)
             {
                 // Search the stream for that region
                 lock (regionFile)
                 {
                     var chunkData = GetChunkFromTable(position);
                     if (chunkData == null)
                     {
                         if (World.ChunkProvider == null)
                             throw new ArgumentException("The requested chunk is not loaded.", "position");
                         if (generate)
                             GenerateChunk(position);
                         else
                             return null;
                         return Chunks[position];
                     }
                     regionFile.Seek(chunkData.Item1, SeekOrigin.Begin);
                     /*int length = */
                     new MinecraftStream(regionFile).ReadInt32(); // TODO: Avoid making new objects here, and in the WriteInt32
                     int compressionMode = regionFile.ReadByte();
                     switch (compressionMode)
                     {
                         case 1: // gzip
                             throw new NotImplementedException("gzipped chunks are not implemented");
                         case 2: // zlib
                             var nbt = new NbtFile();
                             nbt.LoadFromStream(regionFile, NbtCompression.ZLib, null);
                             var chunk = Chunk.FromNbt(nbt);
                             Chunks.Add(position, chunk);
                             World.OnChunkLoaded(new ChunkLoadedEventArgs(chunk));
                             break;
                         default:
                             throw new InvalidDataException("Invalid compression scheme provided by region file.");
                     }
                 }
             }
             else if (World.ChunkProvider == null)
                 throw new ArgumentException("The requested chunk is not loaded.", "position");
             else
             {
                 if (generate)
                     GenerateChunk(position);
                 else
                     return null;
             }
         }
         return Chunks[position];
     }
 }
Example #40
0
        public void GenerateChunk(Coordinates2D position)
        {
            var globalPosition = (Position * new Coordinates2D(Width, Depth)) + position;
            var chunk          = World.ChunkProvider.GenerateChunk(World, globalPosition);

            chunk.IsModified  = true;
            chunk.Coordinates = globalPosition;
            Chunks.Add(position, chunk);
            World.OnChunkGenerated(new ChunkLoadedEventArgs(chunk));
        }
Example #41
0
        public Chunk GetChunkWithoutGeneration(Coordinates2D coordinates)
        {
            int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0);
            int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0);

            var regionPosition = new Coordinates2D(regionX, regionZ);
            if (!Regions.ContainsKey(regionPosition)) return null;
            return Regions[regionPosition].GetChunkWithoutGeneration(
                new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32));
        }
Example #42
0
 /// <summary>
 /// Creates a region from the given region file.
 /// </summary>
 public Region(Coordinates2D position, World world, string file) : this(position, world)
 {
     if (File.Exists(file))
         regionFile = File.Open(file, FileMode.OpenOrCreate);
     else
     {
         regionFile = File.Open(file, FileMode.OpenOrCreate);
         CreateRegionHeader();
     }
 }
Example #43
0
    private void InitUnit(Hex land)
    {
        GameObject unit       = Instantiate(unitPrefab);
        Unit       unitScript = unit.GetComponent <Unit> ();

        unitScript.setUnitID(numberOfUnits);
        numberOfUnits++;
        unit.transform.SetParent(gameState.GetHex(Coordinates2D.convertToXY(land.GetCoordinates())).transform);
        unit.transform.position = land.Position();
    }
        public int GetChunkIndex(Coordinates2D coordinates)
        {
            foreach (var chunk in Chunks)
            {
                if (chunk.Coordinates == coordinates)
                    return Chunks.IndexOf(chunk);
            }

            return -1;
        }
Example #45
0
 public Chunk(Coordinates2D coordinates)
     : this()
 {
     X = coordinates.X;
     Z = coordinates.Z;
     const int size = Width * Height * Depth;
     Blocks = new byte[size];
     Metadata = new NibbleArray(size);
     BlockLight = new NibbleArray(size);
     SkyLight = new NibbleArray(size);
 }
Example #46
0
 internal IChunk FindChunk(Coordinates2D coordinates)
 {
     try
     {
         return World.FindChunk(new Coordinates3D(coordinates.X, 0, coordinates.Z));
     }
     catch
     {
         return null;
     }
 }
 protected override IEnumerable<Coordinates2D> GetNeighbours(Coordinates2D coord)
 {
     if(coord.x > TopLeft.x)
         yield return new Coordinates2D(coord.x - 1, coord.y);
     if(coord.x < BottomRight.x)
         yield return new Coordinates2D(coord.x + 1, coord.y);
     if(coord.y > TopLeft.y)
         yield return new Coordinates2D(coord.x, coord.y - 1);
     if(coord.y < BottomRight.y)
         yield return new Coordinates2D(coord.x, coord.y + 1);
 }
Example #48
0
        public void SetChunk(Coordinates2D coordinates, Chunk chunk)
        {
            int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0);
            int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0);

            var region = LoadOrGenerateRegion(new Coordinates2D(regionX, regionZ));
            lock (region)
            {
                chunk.IsModified = true;
                region.SetChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32), chunk);
            }
        }
Example #49
0
 /*
  * The distance to the closest biome cell point to the specified location(uses the Chebyshev distance function).
  */
 public double ClosestCellPoint(Coordinates2D location)
 {
     var distance = double.MaxValue;
     foreach (BiomeCell C in BiomeCells)
     {
         var _distance = Distance(location, C.CellPoint);
         if (_distance < distance)
         {
             distance = _distance;
         }
     }
     return distance;
 }
 protected void InitializeWorld(Coordinates2D min, Coordinates2D max)
 {
     ILogManager logManager;
     world = SystemBuilder
         .Create<Coordinates2D, EmptyData, EmptyData>()
         .WithDefaultLog(out logManager)
         .WithTopology(new FourConnectedSurfaceTopology(min, max))
         .WithSurfaceMap()
         .WithEmptyNodeData()
         .WithEmptyEdgeData()
         .Build();
     journal = logManager.Journal;
     world = runner.World;
     runner = new Runner<Coordinates2D, EmptyData, EmptyData>(world);
 }
Example #51
0
 /*
  * The closest biome cell to the specified location(uses the Chebyshev distance function).
  */
 public BiomeCell ClosestCell(Coordinates2D location)
 {
     BiomeCell cell = null;
     var distance = double.MaxValue;
     foreach (BiomeCell C in BiomeCells)
     {
         var _distance = Distance(location, C.CellPoint);
         if (_distance < distance)
         {
             distance = _distance;
             cell = C;
         }
     }
     return cell;
 }
 private static Ellipse BuildCycle(bool isWolf, Coordinates2D point, SolidColorBrush solidColorBrush)
 {
     int modifier = isWolf ? 1 : -1;
     return new Ellipse
            {
            	Margin = new Thickness
            	         {
            	         	Top = 2 * point.y * stepY + 0.25 * stepY * modifier,
            	         	Left = 2 * point.x * stepX + 0.25 * stepX * modifier
            	         },
            	Stroke = solidColorBrush,
            	Width = stepX / 2,
            	Height = stepY / 2,
            	StrokeThickness = 2
            };
 }
        protected override IEnumerable<Coordinates2D> GetNeighbours(Coordinates2D coord)
        {
            var neighbourX = new List<int> { coord.x };
            if(coord.x < BottomRight.x)
                neighbourX.Add(coord.x + 1);
            if(coord.x > TopLeft.x)
                neighbourX.Add(coord.x - 1);

            var neighbourY = new List<int> { coord.y };
            if(coord.y < BottomRight.y)
                neighbourY.Add(coord.y + 1);
            if(coord.y > TopLeft.y)
                neighbourY.Add(coord.y - 1);

            return neighbourX
                .SetMultiply(neighbourY, (x, y) => new Coordinates2D(x, y))
                .Where(x => !x.Equals(coord))
                .ToArray();
        }
Example #54
0
 public Chunk GenerateChunk(Coordinates2D position)
 {
     var chunk = new Chunk(position);
     int y = 0;
     for (int i = 0; i < Layers.Count; i++)
     {
         int height = y + Layers[i].Height;
         while (y < height)
         {
             for (int x = 0; x < 16; x++)
             {
                 for (int z = 0; z < 16; z++)
                 {
                     chunk.SetBlockId(new Coordinates3D(x, y, z), Layers[i].BlockId);
                     chunk.SetMetadata(new Coordinates3D(x, y, z), Layers[i].Metadata);
                 }
             }
             y++;
         }
     }
     for (int i = 0; i < chunk.Biomes.Length; i++)
         chunk.Biomes[i] = (byte)Biome;
     return chunk;
 }
Example #55
0
 /// <summary>
 /// Unloads the given chunk on the client.
 /// </summary>
 public virtual void UnloadChunk(Coordinates2D position)
 {
     var dataPacket = new ChunkDataPacket();
     dataPacket.AddBitMap = 0;
     dataPacket.GroundUpContinuous = true;
     dataPacket.PrimaryBitMap = 0;
     dataPacket.X = (int)position.X;
     dataPacket.Z = (int)position.Z;
     dataPacket.Data = ChunkHelper.ChunkRemovalSequence;
     SendPacket(dataPacket);
     LoadedChunks.Remove(position);
 }
Example #56
0
 /// <summary>
 /// Loads the given chunk on the client.
 /// </summary>
 public virtual void LoadChunk(Coordinates2D position)
 {
     var chunk = Entity.World.GetChunk(position);
     SendPacket(ChunkHelper.CreatePacket(chunk));
     // TODO: Tile entities
     foreach (var entity in chunk.TileEntities)
     {
         // ...
     }
     LoadedChunks.Add(position);
 }
Example #57
0
 internal void UnloadChunk(Coordinates2D position)
 {
     QueuePacket(new ChunkPreamblePacket(position.X, position.Z, false));
     LoadedChunks.Remove(position);
 }
Example #58
0
 internal void LoadChunk(Coordinates2D position)
 {
     var chunk = World.GetChunk(position);
     chunk.LastAccessed = DateTime.UtcNow;
     QueuePacket(new ChunkPreamblePacket(chunk.Coordinates.X, chunk.Coordinates.Z));
     QueuePacket(CreatePacket(chunk));
     LoadedChunks.Add(position);
     foreach (var kvp in chunk.TileEntities)
     {
         var coords = kvp.Key;
         var descriptor = new BlockDescriptor
         {
             Coordinates = coords + new Coordinates3D(chunk.X, 0, chunk.Z),
             Metadata = chunk.GetMetadata(coords),
             ID = chunk.GetBlockID(coords),
             BlockLight = chunk.GetBlockLight(coords),
             SkyLight = chunk.GetSkyLight(coords)
         };
         var provider = Server.BlockRepository.GetBlockProvider(descriptor.ID);
         provider.TileEntityLoadedForClient(descriptor, World, kvp.Value, this);
     }
 }
Example #59
0
 internal void RemoveChunk(Coordinates2D coordinates)
 {
     if (UnloadChunks)
         World.UnloadChunk(coordinates);
 }
Example #60
0
 internal void SetChunk(Coordinates2D coordinates, Chunk chunk)
 {
     World.SetChunk(coordinates, chunk);
 }