public void Event_Noise(Position pos, NoiseType type) { long range = NoiseRanges[type]; foreach (Entitys.Entity e in GetEntitys_Range(pos, range)) { e.Event_Noise(pos, 1 - pos.Distance(e.Pos) / range); } }
public Chunk GetChunk(Position chunkpos) { Chunk c; if (LoadedChunks.TryGetValue(chunkpos, out c)) { return LoadedChunks[chunkpos]; } else { c = Chunk.LoadFromFile(chunkpos); if (c == null) { LoadedChunks[chunkpos] = WorldGen.Generate(chunkpos); } return LoadedChunks[chunkpos]; } }
public static Chunk LoadFromFile(Position chunkpos) { //TODO return null; }
public void SetTile(Position pos, Tile tile) { Position chunkpos = GetChunkPosition(pos); Position chunkindex = GetChunkTileIndex(pos, chunkpos); Chunk c = GetChunk(chunkpos); c.Idle = 0; c.Tiles[chunkindex.x, chunkindex.y, chunkindex.z] = tile; }
public Chunk(Position pos) { this.Pos = pos; }
public Tile GetTile(Position pos) { Position chunkpos = GetChunkPosition(pos); Position chunkindex = GetChunkTileIndex(pos, chunkpos); Chunk c = GetChunk(chunkpos); c.Idle = 0; return c.Tiles[chunkindex.x, chunkindex.y, chunkindex.z]; }
public void MoveEntity(Entitys.Entity e, Position dest) { Position chunkpos_before = GetChunkPosition(e.Pos); e.Pos = dest; Position chunkpos_after = GetChunkPosition(e.Pos); if (chunkpos_before != chunkpos_after) { GetChunk(chunkpos_before).Entitys.Remove(e); GetChunk(chunkpos_after).Entitys.Add(e); } }
public List<Entitys.Entity> GetEntitys(Position chunkpos) { Chunk c = GetChunk(chunkpos); c.Idle = 0; return c.Entitys; }
public List<Entitys.Entity> GetEntitys_Range(Position pos, long range) { List<Entitys.Entity> Entitys = new List<Entitys.Entity>(); List<Position> ChunksInRange = new List<Position>(); Position Chunk_Start = GetChunkPosition(pos.translate(-range, -range, -range)); Position Chunk_End = GetChunkPosition(pos.translate(range, range, range)); //Get all chunks in range for (long x = Chunk_Start.x; x <= Chunk_End.x; x++) { for (long y = Chunk_Start.y; y <= Chunk_End.y; y++) { for (long z = Chunk_Start.z; z <= Chunk_End.z; z++) { ChunksInRange.Add(new Position(x, y, z)); } } } //Get all entitys in range foreach (Position p in ChunksInRange) { List<Entitys.Entity> ChunkEntitys = GetChunk(p).Entitys; foreach (Entitys.Entity e in ChunkEntitys) { if (pos.Distance(e.Pos) <= range) { Entitys.Add(e); } } } return Entitys; }
public Position GetChunkTileIndex(Position tilepos, Position chunkpos) { long x = tilepos.x - chunkpos.x * Chunk.Size; long y = tilepos.y - chunkpos.y * Chunk.Size; long z = tilepos.z - chunkpos.z * Chunk.Size; if (tilepos.x < 0) x = -(x - Chunk.Size); if (tilepos.y < 0) y = -(y - Chunk.Size); if (tilepos.z < 0) z = -(z - Chunk.Size); return new Position(x, y, z); }
public Position GetChunkPosition(Position tilepos) { long x = tilepos.x / Chunk.Size; long y = tilepos.y / Chunk.Size; long z = tilepos.z / Chunk.Size; if (tilepos.x < 0) x--; if (tilepos.y < 0) y--; if (tilepos.z < 0) z--; return new Position(x, y, z); }
public double Distance(Position c) { return Distance(this, c); }
public static double Distance(Position c1, Position c2) { return Math.Sqrt(Math.Pow(c2.x - c1.x, 2) + Math.Pow(c2.y - c1.y, 2) + Math.Pow(c2.z - c1.z, 2)); }
public bool Intersects(Position p) { return ((p.x >= X && p.x <= X + W) && (p.y >= Y && p.y < Y + H)); }