Skip to content

Instantly share code, notes, and snippets.

@macalinao
Created December 22, 2011 06:04
Show Gist options
  • Save macalinao/1509150 to your computer and use it in GitHub Desktop.
Save macalinao/1509150 to your computer and use it in GitHub Desktop.
package org.getspout.api.entity;
import org.getspout.api.entity.ai.AI;
import org.getspout.api.plugin.Plugin;
/**
* Represents an entity that can have AI.
*/
public interface AIable<T extends Entity> {
/**
* Gets the current AI of the entity.
* @return The entity's AI
*/
public AI getAI();
/**
* Registers an AI with this entity.
* @param ai
* @param priority
* @param plugin
*/
public void registerAI(AI<T> ai, AI.Priority priority, Plugin plugin);
}
package org.getspout.api.entity.ai;
import java.util.List;
import org.getspout.api.entity.Entity;
public abstract class AI<T extends Entity> {
/**
* Returns true if the AI should run.
* @return True if the AI should run.
*/
public abstract boolean shouldRun();
/**
* Updates the entity's AI.
* @param entity The entity's AI.
*/
public abstract void pulse(T entity);
/**
* Pulses a list of entites associated with the AI.
* @param entities The entities to pulse.
*/
public final void pulse(List<? extends T> entities) {
for (T entity : entities) {
pulse(entity);
}
}
/**
* An enum holding the priority of this AI's execution.
*/
public enum Priority {
/**
* AI of the lowest priority. This AI will be executed first.
*/
Lowest,
/**
* AI of low priority.
*/
Low,
/**
* AI of normal priority.
*/
Normal,
/**
* AI of high priority.
*/
High,
/**
* AI of highest priority. This will be run last.
*/
Highest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment