package org.apollo.game.model.area.collision;

import org.apollo.game.model.entity.Entity.EntityType;

/**
 * A type of flag in a {@link CollisionMatrix}.
 *
 * @author Major
 */
public enum CollisionFlag {

	/**
	 * The walk east flag.
	 */
	MOB_EAST(1),

	/**
	 * The walk north flag.
	 */
	MOB_NORTH(0),

	/**
	 * The walk south flag.
	 */
	MOB_SOUTH(2),

	/**
	 * The walk west flag.
	 */
	MOB_WEST(3),

	/**
	 * The projectile east flag.
	 */
	PROJECTILE_EAST(5),

	/**
	 * The projectile north flag.
	 */
	PROJECTILE_NORTH(4),

	/**
	 * The projectile south flag.
	 */
	PROJECTILE_SOUTH(6),

	/**
	 * The projectile west flag.
	 */
	PROJECTILE_WEST(7);

	/**
	 * Returns an array of CollisionFlags that indicate if the specified {@link EntityType} can be positioned on a tile.
	 * 
	 * @param type The EntityType.
	 * @return The array of CollisionFlags.
	 */
	public static CollisionFlag[] forType(EntityType type) {
		return (type == EntityType.PROJECTILE) ? projectiles() : mobs();
	}

	/**
	 * Returns an array of CollisionFlags that indicate if a Mob can be positioned on a tile.
	 * 
	 * @return The array of CollisionFlags.
	 */
	public static CollisionFlag[] mobs() {
		return new CollisionFlag[] { MOB_NORTH, MOB_EAST, MOB_SOUTH, MOB_WEST };
	}

	/**
	 * Returns an array of CollisionFlags that indicate if a Projectile can be positioned on a tile.
	 * 
	 * @return The array of CollisionFlags.
	 */
	public static CollisionFlag[] projectiles() {
		return new CollisionFlag[] { PROJECTILE_NORTH, PROJECTILE_EAST, PROJECTILE_SOUTH, PROJECTILE_WEST };
	}

	/**
	 * The index of the bit this flag is stored in.
	 */
	private final int bit;

	/**
	 * Creates the CollisionFlag.
	 *
	 * @param bit The index of the bit this flag is stored in.
	 */
	private CollisionFlag(int bit) {
		this.bit = bit;
	}

	/**
	 * Gets this CollisionFlag, as a {@code byte}.
	 * 
	 * @return The value, as a {@code byte}.
	 */
	public byte asByte() {
		return (byte) (1 << bit);
	}

	/**
	 * Gets the index of the bit this flag is stored in.
	 * 
	 * @return The index of the bit.
	 */
	public int getBit() {
		return bit;
	}

}
@@ -219,20 +219,21 @@
 he walk 
-east
+north
  flag.%0A%09
@@ -245,14 +245,15 @@
 MOB_
-EAST(1
+NORTH(0
 ),%0A%0A
@@ -262,37 +262,36 @@
 **%0A%09 * The walk 
-north
+east
  flag.%0A%09 */%0A%09MOB
@@ -283,39 +283,38 @@
 flag.%0A%09 */%0A%09MOB_
-NORTH(0
+EAST(1
 ),%0A%0A%09/**%0A%09 * The
@@ -425,20 +425,21 @@
 jectile 
-east
+north
  flag.%0A%09
@@ -458,14 +458,15 @@
 ILE_
-EAST(5
+NORTH(4
 ),%0A%0A
@@ -481,37 +481,36 @@
  The projectile 
-north
+east
  flag.%0A%09 */%0A%09PRO
@@ -509,39 +509,38 @@
  */%0A%09PROJECTILE_
-NORTH(4
+EAST(5
 ),%0A%0A%09/**%0A%09 * The

Order CollisionFlags.