package projectzombie.util.math.astar;

import gl_engine.MathHelpers;
import gl_engine.vec.Vec2i;
import projectzombie.util.TileState;
import projectzombie.world.layer.Layer;

public class AStarSearcher implements AStarSearch
{
	private boolean crossUnwalkable;
	private Layer layer;
	
	public AStarSearcher(Layer layer, boolean crossUnwalkable) {
		this.crossUnwalkable = crossUnwalkable;
		this.layer = layer;
	}
	
	public AStarSearcher(Layer layer) {
		this(layer, false);
	}

	@Override
	public int getWeight(int x, int y)
	{
		Vec2i tpos = new Vec2i(x, y);
		TileState tsf = layer.getFrontTile(tpos);
		TileState tsb = layer.getBackTile(tpos);
		
		if(!crossUnwalkable) {
			if(!tsf.tile.tileWalkable || !tsb.tile.tileWalkable) {
				return 0;
			}
		}
		
		if(tsf.tile.tileHitbox > 0 || tsb.tile.tileHitbox > 0) {
			return 80;
		}
		
		if(tsf.tile.tileSolid || tsb.tile.tileSolid) {
			return 100;
		}
		
		if(tsf.tile.slowness > 0 || tsb.tile.slowness > 0) {
			return (int)(MathHelpers.biggest(tsf.tile.slowness, tsb.tile.slowness) * 100);
		}
		
		return 0;
	}

}
