@Override
	public int distance(GeneralAIUnit unit, GeneralAI ai) {
		// ensure unit can build this guy
		if (unit.stats.isBuilding() && !def.is_building) {
			if (!unit.stats.getProduce().contains(id)) {
				return GeneralAI.DISTANCE_IGNORE; // can't even build
			}
		} else if (!(unit.stats.isWorker() && def.is_building)){
			return GeneralAI.DISTANCE_IGNORE;
		}
		for (int i = 0; i < def.cost.size(); i++) {
			if (ai.money.get(i) < def.cost.get(i)) {
				return GeneralAI.DISTANCE_IGNORE;
			}
		}
		if (def.is_worker) {
			return priority-GeneralAI.DISTANCE_IGNORE; // special priority for workers
		} else if (priority == GeneralAI.DISTANCE_IGNORE) {
			return GeneralAI.DISTANCE_IGNORE;
		}
		int distance = (unit.stats.getX()-x)*(unit.stats.getX()-x)+(unit.stats.getY()-y)*(unit.stats.getY()-y);
		return (int)(priority*cost_ratio*def.produce_speed)+distance;
	}