|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread wyvern.kernel.commands.AbstractAI
Common superclass all AI objects. An AbstractAI has several functions:
For (2), the AbstractAI keeps a CommandList containing the standard game commands, which are all coded to work for commandables.
For (3), the AI has a thread managing a queue of EventQueues. When a commandable's EventQueue is finished waiting from the previous command, the queue notifies the AI. The AI puts the commandable's queue in its internal queue, and puts commands into the queues ("think") as fast as it can.
Field Summary | |
protected java.util.Set |
commandables_
This is a self-synchronized set of the Commandable objects under this AI's control. |
protected CommandList |
commandList_
This is a list of built-in game commands. |
protected java.util.List |
queues_
This is a self-synchronized list of the empty queues that the AI currently needs to produce (or "think") for. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Fields inherited from interface wyvern.lib.AI |
DEFAULT_MONSTER_INERTIA, DEFAULT_WANDER_RANGE |
Constructor Summary | |
AbstractAI()
Constructs a new AbstractAI with the default thread name. |
|
AbstractAI(java.lang.String name)
Constructs a new AbstractAI with the specified thread name. |
Method Summary | |
void |
addCommandable(Commandable m)
Adds a Commandable to this AI's sphere of influence. |
void |
addToHateList(Commandable defender,
Commandable attacker)
Adds someone to a monster's I-hate-you list. |
java.lang.String |
chooseRandomDir()
Chooses a random direction for the commandable. |
static int |
getAverageTime(java.lang.String classname)
Returns average wall-clock time spent in think() for a given AI class. |
Command |
getCommand(CommandEvent cmd,
Commandable agent)
Returns the Command that will handle the specified command for a commandable. |
static int |
getNumThinks(java.lang.String classname)
Returns the total number of times think() has been invoked for a given AI class. |
static java.lang.String |
getProfilingInfo()
Returns profiling information across all AIs active in the game. |
static int |
getTotalTime(java.lang.String classname)
Returns total time spent in think() for a given AI class. |
boolean |
isControlling(Commandable c)
Returns true if the AI is producing for the specified Commandable's queue (i.e. it thinks it's controlling the commandable). |
void |
moveRandomly(Commandable agent)
Moves the monster in a random direction, possibly pausing. |
void |
notifyAttacked(Commandable defender,
Commandable attacker)
When a monster is attacked, it sends this message to its AI. |
void |
registerCommand(java.lang.String command,
Command handler,
Commandable agent)
Registers a command with the AI. |
void |
removeCommandable(Commandable c)
Removes a Commandable from this AI's control. |
void |
requestEvent(EventQueue q)
Notifies the AI that a queue is ready to be serviced. |
void |
run()
Starts the AbstractAI thread. |
protected void |
serviceQueues()
"Think" for all the ready commandables. |
abstract void |
think(Commandable m,
EventQueue q)
Decides what to do next. |
void |
thinkForQueue(EventQueue q)
Takes a queue and puts something in it, based on properties of the owner of the queue. |
void |
unregisterCommand(java.lang.String command,
Command handler,
Commandable agent)
Unregisters a command with the AI. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.util.Set commandables_
protected CommandList commandList_
protected java.util.List queues_
Constructor Detail |
public AbstractAI()
public AbstractAI(java.lang.String name)
This constructor creates the table of commandables (often monsters) under its control, the list of queues to produce commands for, and a list of builtin command handlers for common commands that monsters use.
Method Detail |
public void addCommandable(Commandable m)
AI
addCommandable
in interface AI
m
- a Commandable to add.public void removeCommandable(Commandable c)
AI
removeCommandable
in interface AI
c
- the Commandable to removepublic void registerCommand(java.lang.String command, Command handler, Commandable agent)
AI
registerCommand
in interface AI
command
- the command to registerhandler
- the Command object who's registering itagent
- the agent for which to register the commandpublic void unregisterCommand(java.lang.String command, Command handler, Commandable agent)
AI
unregisterCommand
in interface AI
command
- the command to unregisterhandler
- the Command object who's unregistering itagent
- the agent that used to have the command registeredpublic Command getCommand(CommandEvent cmd, Commandable agent)
AI
getCommand
in interface AI
agent
- the Commandable who is being commandedcmd
- the command the Commandable is trying to perform
public abstract void think(Commandable m, EventQueue q)
AI
think
in interface AI
m
- the Commandable to think forq
- the Commandable's event queue, for convenience
(it's the same as the one returned by m.getQueue() );public boolean isControlling(Commandable c)
AI
isControlling
in interface AI
c
- the Commandable to check
public void run()
run
in interface java.lang.Runnable
protected void serviceQueues()
public void thinkForQueue(EventQueue q)
AI
thinkForQueue
in interface AI
q
- the Commandable's event queue, for convenience
(it's the same as the one returned by m.getQueue() );public void requestEvent(EventQueue q)
AI
requestEvent
in interface AI
q
- the EventQueue that's ready for an eventpublic java.lang.String chooseRandomDir()
public void notifyAttacked(Commandable defender, Commandable attacker)
AI
notifyAttacked
in interface AI
defender
- the monster under the AI's controlattacker
- whoever attacked the monsterpublic void moveRandomly(Commandable agent)
agent
- the monster to commandpublic void addToHateList(Commandable defender, Commandable attacker)
AI
addToHateList
in interface AI
defender
- the monster who now hates someoneattacker
- the player or monster the hater hatespublic static int getTotalTime(java.lang.String classname)
classname
- something like wyvern.kernel.monsters.StandardAI
public static int getNumThinks(java.lang.String classname)
classname
- something like wyvern.kernel.monsters.StandardAI
public static int getAverageTime(java.lang.String classname)
classname
- something like wyvern.kernel.monsters.StandardAI
public static java.lang.String getProfilingInfo()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |