package electrosphere.game.server.world;

import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.datacell.ServerDataCell;
import java.util.List;
import org.joml.Vector3f;

/**
 *
 * @author amaterasu
 */
public class ServerWorldData {
    
    public static enum WorldType {
        GAME_WORLD,
        ARENA_WORLD,
    }
    
    WorldType type;
    
    
    /*
    
                       world max
    +---------------------+
    |                     |
    |                     |
    |                     |
    |                     |
    |                     |
    +---------------------+
 world min
    
    
    basically we're saying what the maximum and minimum x and z something can occupy are
    
    FOR THE TIME BEING DOES NOT ACCOUNT FOR Y
    */
    Vector3f worldMinPoint;
    Vector3f worldMaxPoint;
    
    int worldSizeDiscrete;
    int dynamicInterpolationRatio;
    float randomDampener;
    boolean isArena = false;
    
    public static ServerWorldData createArenaWorld(){
        ServerWorldData rVal = new ServerWorldData();
        rVal.type = WorldType.ARENA_WORLD;
        rVal.worldMinPoint = new Vector3f(0,0,0);
        rVal.worldMaxPoint = new Vector3f(200,0,200);
        rVal.dynamicInterpolationRatio = 100;
        rVal.worldSizeDiscrete = 2;
        rVal.randomDampener = 0.0f;
        rVal.isArena = true;
        return rVal;
    }
    
    public static ServerWorldData createGameWorld(ServerTerrainManager terrainManager){
        ServerWorldData rVal = new ServerWorldData();
        rVal.type = WorldType.GAME_WORLD;
        
        rVal.worldMinPoint = new Vector3f(0,0,0);
        int worldDim = terrainManager.getWorldDiscreteSize() * terrainManager.getChunkWidth();
        rVal.worldMaxPoint = new Vector3f(worldDim,0,worldDim);
        
        rVal.dynamicInterpolationRatio = terrainManager.getDynamicInterpolationRatio();
        rVal.worldSizeDiscrete = terrainManager.getWorldDiscreteSize();
        rVal.randomDampener = terrainManager.getRandomDampener();
        
        return rVal;
    }
    
    
    public Vector3f getWorldBoundMin(){
        return worldMinPoint;
    }
    
    public Vector3f getWorldBoundMax(){
        return worldMaxPoint;
    }

    public int getWorldSizeDiscrete() {
        return worldSizeDiscrete;
    }

    public int getDynamicInterpolationRatio() {
        return dynamicInterpolationRatio;
    }

    public float getRandomDampener() {
        return randomDampener;
    }
    
    public int convertRealToChunkSpace(double real){
        return (int)Math.floor(real / dynamicInterpolationRatio);
    }
    
    public double getRelativeLocation(double real, int world){
        return real - (world * dynamicInterpolationRatio);
    }

    public boolean isArena() {
        return isArena;
    }
    
    
    
}
