package worldGen;

import engine.Game;
import interfaces.Biomes;
import mobs.Goblin;
import mobs.Rabbit;
import utils.Stack;
import utils.Utils;
import world.Boulder;
import world.Debris;
import world.DroppedItem;
import world.Flower;
import world.Sapling;
import world.TallGrass;
import world.Tile;
import world.Tree;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

final class EntityGenerator implements Biomes {
	
	public static final void generate(final Stack<Tile> tiles) {
		if(tiles == null || tiles.isEmpty()) return;
		
		final int NUM_OF_BIOMES = 17;
		
		final int TYPES_OF_ENTITIES = 10;
		final int DEBRIS=0,TREE=1,BOULDER=2,FLOWER=3,TALLGRASS=4,SAPLING=5,RABBIT=6, ROCKS=7, STICKS=8,
				  GOBLIN=9;
		
		final float[][] biomes = new float[NUM_OF_BIOMES][TYPES_OF_ENTITIES];

		// OCEAN = no chances
		// RIVER = no chances
		// LAKE = no chances
		
		biomes[COASTLINE][DEBRIS] = 1/2000f;
		
		biomes[BEACH][DEBRIS] = 1/1650f;
		biomes[BEACH][ROCKS] = 1/5000f;
		biomes[BEACH][STICKS] = 1/4500f;
		
		biomes[GRASS1][DEBRIS] = 1/800f;
		biomes[GRASS1][TREE] = 1/2550f;
		biomes[GRASS1][BOULDER] = 1/3500f;
		biomes[GRASS1][FLOWER] = 1/400f;
		biomes[GRASS1][TALLGRASS] = 1/500f;
		biomes[GRASS1][SAPLING] = 1/600f;
		biomes[GRASS1][RABBIT] = 1/400f;
		biomes[GRASS1][ROCKS] = 1/800f;
		biomes[GRASS1][GOBLIN] = 1/1000f;

		biomes[GRASS2][DEBRIS] = 1/800f;
		biomes[GRASS2][TREE] = 1/2550f;
		biomes[GRASS2][BOULDER] = 1/3500f;
		biomes[GRASS2][FLOWER] = 1/250f;
		biomes[GRASS2][TALLGRASS] = 1/500f;
		biomes[GRASS2][SAPLING] = 1/600f;
		biomes[GRASS2][RABBIT] = 1/400f;
		biomes[GRASS2][ROCKS] = 1/800f;
		biomes[GRASS2][GOBLIN] = 1/1000f;
		
		biomes[GRASS3][DEBRIS] = 1/800f;
		biomes[GRASS3][TREE] = 1/2550f;
		biomes[GRASS3][BOULDER] = 1/3500f;
		biomes[GRASS3][FLOWER] = 1/250f;
		biomes[GRASS3][TALLGRASS] = 1/500f;
		biomes[GRASS3][SAPLING] = 1/600f;
		biomes[GRASS3][RABBIT] = 1/400f;
		biomes[GRASS3][ROCKS] = 1/800f;
		biomes[GRASS3][GOBLIN] = 1/1000f;
		
		biomes[GRASS4][DEBRIS] = 1/800f;
		biomes[GRASS4][TREE] = 1/2550f;
		biomes[GRASS4][BOULDER] = 1/3500f;
		biomes[GRASS4][FLOWER] = 1/250f;
		biomes[GRASS4][TALLGRASS] = 1/500f;
		biomes[GRASS4][SAPLING] = 1/600f;
		biomes[GRASS4][RABBIT] = 1/400f;
		biomes[GRASS4][ROCKS] = 1/800f;
		biomes[GRASS4][GOBLIN] = 1/1000f;

		biomes[FOREST][DEBRIS] = 1/175f;
		biomes[FOREST][TREE] = 1/25f;
		biomes[FOREST][BOULDER] = 1/500f;
		biomes[FOREST][FLOWER] = 1/900f;
		biomes[FOREST][TALLGRASS] = 1/1500f;
		biomes[FOREST][SAPLING] = 1/700f;
		biomes[FOREST][RABBIT] = 1/3000f;
		biomes[FOREST][ROCKS] = 1/475f;
		biomes[FOREST][STICKS] = 1/2000f;
		biomes[FOREST][GOBLIN] = 1/200f;
		
		biomes[DESERT][DEBRIS] = 1/3000f;
		biomes[DESERT][BOULDER] = 1/500f;
		biomes[DESERT][TALLGRASS] = 1/200f;
 		biomes[DESERT][SAPLING] = 1/1500f;
 		biomes[DESERT][RABBIT] = 1/400f;
 		biomes[DESERT][ROCKS] = 1/200f;
		biomes[DESERT][GOBLIN] = 0f;
 		
 		biomes[TAIGA][DEBRIS] = 1/2000f;
		biomes[TAIGA][BOULDER] = 1/1250f;
		biomes[TAIGA][TALLGRASS] = 1/300f;
 		biomes[TAIGA][SAPLING] = 1/1200f;
 		biomes[TAIGA][RABBIT] = 1/400f;
		biomes[TAIGA][GOBLIN] = 0f;
 		
 		biomes[BARREN_ROCK][DEBRIS] = 1/1000f;
		biomes[BARREN_ROCK][BOULDER] = 1/50f;
 		biomes[BARREN_ROCK][SAPLING] = 1/2500f;
 		biomes[BARREN_ROCK][ROCKS] = 1/100f;
		biomes[BARREN_ROCK][GOBLIN] = 0f;

 		
 		int xOffset = 0, yOffset= 0; final int FOURTH_TILE = Game.TILE_SIZE/4;
 		for(final Tile t : tiles){
 			
 			switch(t.biome){
 				case OCEAN: continue;
 				case LAKE: continue;
 				case RIVER: continue;
 			}
 			
 			xOffset = Utils.rand.nextInt(FOURTH_TILE);
 			yOffset = Utils.rand.nextInt(FOURTH_TILE);
 				
 			if(Utils.COIN_FLIP()) xOffset *= -1;
 			if(Utils.COIN_FLIP()) yOffset *= -1;
 				
			
 			if(biomes[t.biome][DEBRIS] > Utils.rand.nextFloat()) new Debris(t.x + xOffset, t.y + yOffset);
 			if(biomes[t.biome][TREE] > Utils.rand.nextFloat()) new Tree(t.x + xOffset, t.y + yOffset);
 			if(biomes[t.biome][BOULDER] > Utils.rand.nextFloat()) new Boulder(t.x + xOffset, t.y + yOffset);
			if(biomes[t.biome][FLOWER] > Utils.rand.nextFloat()) new Flower(t.x + xOffset, t.y + yOffset);
			if(biomes[t.biome][TALLGRASS] > Utils.rand.nextFloat()) new TallGrass(t.x + xOffset, t.y + yOffset);
			if(biomes[t.biome][SAPLING] > Utils.rand.nextFloat()) new Sapling(t.x + xOffset, t.y + yOffset);
			if(biomes[t.biome][RABBIT] > Utils.rand.nextFloat()) new Rabbit(t.x + xOffset, t.y + yOffset);
			if(biomes[t.biome][ROCKS] > Utils.rand.nextFloat()) new DroppedItem(t.x + xOffset, t.y + yOffset, 6);
			if(biomes[t.biome][STICKS] > Utils.rand.nextFloat()) new DroppedItem(t.x + xOffset, t.y + yOffset, 7);
			if(biomes[t.biome][GOBLIN] > Utils.rand.nextFloat()) new Goblin(t.x + xOffset, t.y + yOffset);

 		}
	}

}
