package CK.IA;

public class Goal implements Comparable<Goal> {
	private static int id_counter = 0;
	private Vector3d complete_position;
	private Entity entity;
	private int id;
	private int owner;
	private int priority;
	private boolean shared;
	private GoalStatus status;
	private int team;
	private GoalType type;

	/**
	 * 
	 * @param type
	 * @param related
	 * @param priority
	 * @param team
	 * @param status
	 * @param shared
	 * @param default_owner
	 */
	public Goal(GoalType type, Entity related, int priority, int team, GoalStatus status, boolean shared, int default_owner) {
		this.id = id_counter;
		id_counter++;
		this.type = type;
		this.priority = priority;
		this.team = team;
		this.entity = related;
		// carry and roam goals can't be shared
		this.shared = (type == GoalType.CARRY || type == GoalType.ROAM) ? false : shared;
		this.owner = default_owner;
		this.status = status;
	}

	public int compareTo(Goal o) {
		int my_id = this.getId();
		int others_id = o.getId();
		if (my_id < others_id)
			return -1;
		else if (my_id == others_id)
			return 0;
		else
			return +1;
	}

	public boolean equals(Goal g) {
		return this.getId() == g.getId();
	}

	public Vector3d getCompletePosition() {
		return complete_position;
	}

	public Entity getEntity() {
		return entity;
	}

	public int getId() {
		return id;
	}

	public int getOwner() {
		return owner;
	}

	public float getPriority() {
		return priority;
	}

	public GoalStatus getStatus() {
		return status;
	}

	public int getTeam() {
		return team;
	}

	public GoalType getType() {
		return type;
	}

	public int hashCode() {
		return this.getId();
	}

	public boolean isAssigned() {
		return this.getOwner() >= 0;
	}

	public boolean isShared() {
		return shared;
	}

	public void setCompletePosition(Vector3d complete_position) {
		this.complete_position = complete_position;
	}

	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	public void setOwner(int id2) {
		this.owner = id2;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public void setStatus(GoalStatus status) {
		this.status = status;
	}

	public void setTeam(int team) {
		this.team = team;
	}

	public String toString() {
		return "Goal:" + this.getId() + " Type:" + this.getType() + " Priority:" + this.getPriority() + " Team:" + this.getTeam() + " Shared:"
				+ this.isShared() + " Status:" + this.getStatus() + " Assigned:" + this.isAssigned() + " Owner:" + this.getOwner()
				+ " Complete position:" + this.getCompletePosition() + " |Entity:" + this.getEntity() + "|";
	}
}
