package electrosphere.server.terrain.generation;

import electrosphere.server.terrain.generation.interfaces.ChunkGenerator;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
import electrosphere.server.terrain.models.TerrainModel;

/**
 * An arena terrain chunk generator
 */
public class DefaultChunkGenerator implements ChunkGenerator {

    @Override
    public ServerTerrainChunk generateChunk(int worldX, int worldY, int worldZ) {
        //Each chunk also needs custody of the next chunk's first values so that they can perfectly overlap.
        //Hence, width should actually be chunk dimension + 1
        float[][][] weights = new float[ServerTerrainChunk.CHUNK_DIMENSION][ServerTerrainChunk.CHUNK_DIMENSION][ServerTerrainChunk.CHUNK_DIMENSION];
        int[][][] values = new int[ServerTerrainChunk.CHUNK_DIMENSION][ServerTerrainChunk.CHUNK_DIMENSION][ServerTerrainChunk.CHUNK_DIMENSION];
        for(int inc = 0; inc < ServerTerrainChunk.CHUNK_DIMENSION; inc++){
            for(int weightX = 0; weightX < ServerTerrainChunk.CHUNK_DIMENSION; weightX++){
                for(int weightZ = 0; weightZ < ServerTerrainChunk.CHUNK_DIMENSION; weightZ++){
                    weights[weightX][inc][weightZ] = -1;
                    values[weightX][inc][weightZ] = 0;
                }
            }
        }
        if(worldY < 1){
            for(int weightX = 0; weightX < ServerTerrainChunk.CHUNK_DIMENSION; weightX++){
                for(int weightZ = 0; weightZ < ServerTerrainChunk.CHUNK_DIMENSION; weightZ++){
                    weights[weightX][0][weightZ] = 0.1f;
                    values[weightX][0][weightZ] = 1;
                }
            }
        }
        ServerTerrainChunk rVal = new ServerTerrainChunk(worldX, worldY, worldZ, weights, values);
        return rVal;
    }

    @Override
    public void setModel(TerrainModel model) {
        //Does nothing as the arena is not based on a terrain model
    }
    
}
