/// <summary> /// Transforms global world coordinates to chunk indices relative to grid origin. /// </summary> /// <param name="localPos">The position in the world.</param> /// <returns></returns> public Indices WorldToChunk(LocalCoordinates posWorld) { var local = posWorld.ConvertToGrid(this); var x = (int)Math.Floor(local.X / (TileSize * ChunkSize)); var y = (int)Math.Floor(local.Y / (TileSize * ChunkSize)); return(new Indices(x, y)); }
public bool InRange(LocalCoordinates localpos, float range) { if (localpos.MapID != MapID) { return(false); } return((localpos.ToWorld().Position - ToWorld().Position).LengthSquared < range * range); }
/// <summary> /// Updates a single tile from the network message. /// </summary> /// <param name="message">The message containing the info.</param> private void HandleTileUpdate(MsgMap message) { Debug.Assert(_netManager.IsClient, "Why is the server calling this?"); var x = message.SingleTurf.X; var y = message.SingleTurf.Y; var tile = (Tile)message.SingleTurf.Tile; var pos = new LocalCoordinates(x, y, message.GridIndex, message.MapIndex); pos.Grid.SetTile(pos, tile); }
/// <inheritdoc /> public TileRef GetTile(LocalCoordinates worldPos) { var chunkIndices = WorldToChunk(worldPos); var gridTileIndices = WorldToTile(worldPos); Chunk output; if (_chunks.TryGetValue(chunkIndices, out output)) { var chunkTileIndices = output.GridTileToChunkTile(gridTileIndices); return(output.GetTile((ushort)chunkTileIndices.X, (ushort)chunkTileIndices.Y)); } return(new TileRef(MapID, Index, gridTileIndices.X, gridTileIndices.Y, default(Tile))); }
/// <inheritdoc /> public IMapGrid FindGridAt(LocalCoordinates worldPos) { var pos = worldPos.ToWorld().Position; IMapGrid grid = GetDefaultGrid(); foreach (var kvGrid in _grids) { if (kvGrid.Value.AABBWorld.Contains(pos) && kvGrid.Value.Index != GridId.DefaultGrid) { grid = kvGrid.Value; } } return(grid); }
/// <inheritdoc /> public LocalCoordinates LocalToWorld(LocalCoordinates local) { return(new LocalCoordinates(local.Position + WorldPosition, 0, local.MapID)); }
/// <inheritdoc /> public void SetTile(LocalCoordinates worldPos, ushort tileId, ushort tileData = 0) { SetTile(worldPos, new Tile(tileId, tileData)); }
/// <inheritdoc /> public void SetTile(LocalCoordinates worldPos, Tile tile) { var localTile = WorldToTile(worldPos); SetTile(localTile.X, localTile.Y, tile); }
/// <inheritdoc /> public LocalCoordinates LocalToWorld(LocalCoordinates posLocal) { return(new LocalCoordinates(posLocal.Position + WorldPosition, GridId.DefaultGrid, posLocal.MapID)); }
public bool InRange(LocalCoordinates localpos, int range) { return(InRange(localpos, (float)range)); }