wyvern.lib
Interface AI

All Known Implementing Classes:
AbstractAI

public interface AI

Monster AIs control monsters and think for them.

Version:
1.0, Sep 27, 1997
Author:
Steve Yegge

Field Summary
static int DEFAULT_MONSTER_INERTIA
          If a monster is moving randomly, since there's nothing to do, we have them sit still this percentage of the time, to cut down on CPU load.
static int DEFAULT_WANDER_RANGE
          If a monster has a "stay-near" property but doesn't specify a "wander-range" property, this is the value that will be used.
 
Method Summary
 void addCommandable(Commandable m)
          Adds a Commandable to this AI's sphere of influence.
 void addToHateList(Commandable hater, Commandable hated)
          Adds someone to a monster's I-hate-you list.
 Command getCommand(CommandEvent cmd, Commandable agent)
          Returns the Command that will handle the specified command for a commandable.
 boolean isControlling(Commandable m)
          Returns true if the AI is producing for the specified Commandable's queue (i.e. it thinks it's controlling the commandable).
 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 m)
          Removes a Commandable from this AI's control.
 void requestEvent(EventQueue q)
          Notifies the AI that a queue is ready to be serviced.
 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.
 

Field Detail

DEFAULT_WANDER_RANGE

public static final int DEFAULT_WANDER_RANGE
If a monster has a "stay-near" property but doesn't specify a "wander-range" property, this is the value that will be used.

See Also:
Constant Field Values

DEFAULT_MONSTER_INERTIA

public static final int DEFAULT_MONSTER_INERTIA
If a monster is moving randomly, since there's nothing to do, we have them sit still this percentage of the time, to cut down on CPU load. You can override it with an "inertia" int property on the monster.

See Also:
Constant Field Values
Method Detail

registerCommand

public void registerCommand(java.lang.String command,
                            Command handler,
                            Commandable agent)
Registers a command with the AI.

Parameters:
command - the command to register
handler - the Command object who's registering it
agent - the agent for which to register the command

unregisterCommand

public void unregisterCommand(java.lang.String command,
                              Command handler,
                              Commandable agent)
Unregisters a command with the AI.

Parameters:
command - the command to unregister
handler - the Command object who's unregistering it
agent - the agent that used to have the command registered

getCommand

public Command getCommand(CommandEvent cmd,
                          Commandable agent)
Returns the Command that will handle the specified command for a commandable.

Parameters:
agent - the Commandable who is being commanded
cmd - the command the Commandable is trying to perform
Returns:
the Command object to handle the command

requestEvent

public void requestEvent(EventQueue q)
Notifies the AI that a queue is ready to be serviced.

Parameters:
q - the EventQueue that's ready for an event

think

public void think(Commandable m,
                  EventQueue q)
Decides what to do next. Subclasses must override this and put a command in the queue, even if it's just a WaitCommand.

Parameters:
m - the Commandable to think for
q - the Commandable's event queue, for convenience (it's the same as the one returned by m.getQueue() );

thinkForQueue

public void thinkForQueue(EventQueue q)
Takes a queue and puts something in it, based on properties of the owner of the queue. Don't call this. It's called when the AI's thread pool runs the queue.

Parameters:
q - the Commandable's event queue, for convenience (it's the same as the one returned by m.getQueue() );

addCommandable

public void addCommandable(Commandable m)
Adds a Commandable to this AI's sphere of influence.

Parameters:
m - a Commandable to add.

removeCommandable

public void removeCommandable(Commandable m)
Removes a Commandable from this AI's control.

Parameters:
m - the Commandable to remove
Throws:
java.lang.IllegalArgumentException - if the Commandable isn't under this AI's control

isControlling

public boolean isControlling(Commandable m)
Returns true if the AI is producing for the specified Commandable's queue (i.e. it thinks it's controlling the commandable).

Parameters:
m - the Commandable to check
Returns:
true if it's in this AI's list

notifyAttacked

public void notifyAttacked(Commandable defender,
                           Commandable attacker)
When a monster is attacked, it sends this message to its AI. The AI can do whatever it likes with the information. Most AIs make the monster hostile towards the attacker.

Parameters:
defender - the monster under the AI's control
attacker - whoever attacked the monster

addToHateList

public void addToHateList(Commandable hater,
                          Commandable hated)
Adds someone to a monster's I-hate-you list.

Parameters:
hater - the monster who now hates someone
hated - the player or monster the hater hates