wyvern.lib
Class Search

java.lang.Object
  extended bywyvern.lib.Search

public class Search
extends java.lang.Object

Contains a whole bunch of common ways to look for objects.

Version:
1.0, Oct 20, 2003
Author:
Steve Yegge

Method Summary
static Predicate createVisiblePredicate(Predicate p, Commandable agent)
          Takes a predicate and wraps it with another predicate that makes sure the returned object isn't invisible to the agent.
static java.util.List findAllMatches(Commandable agent, Predicate p)
          Finds all objects in the map, adjacent to or beneath the agent, that match the passed predicate.
static GameObject findInMap(Commandable agent, Predicate p)
          Searches for an object matching the specified predicate.
static GameObject findNeighbor(Commandable agent, Predicate p)
          Searches the locations around an agent for an object matching the specified predicate.
static GameObject findObject(Commandable agent, Predicate p)
          Looks for the specified object in the vicinity of the agent.
static GameObject findTarget(Commandable agent, Predicate match)
          This utility method looks first in the agent's inventory, then on the ground beneath the agent, for an object that passes the specified predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findNeighbor

public static GameObject findNeighbor(Commandable agent,
                                      Predicate p)
Searches the locations around an agent for an object matching the specified predicate. Looks at the locations occupied by the agent as well, so that the agent could conceivably be its own target. If you want to exclude the agent, make sure the predicate doesn't accept the agent.

Parameters:
agent - the GameObject to look around
p - a Predicate to use for searching the map

findObject

public static GameObject findObject(Commandable agent,
                                    Predicate p)
Looks for the specified object in the vicinity of the agent. First checks the agent's inventory, then the ground beneath the agent, then all locations immediately adjacent to the agent. Works even for non-rectangular (disjoint) agents.

Unlike findNeighbor, this method gives preference to objects beneath the agent. So if you say "find wand", and there are two of them, it'll return the one beneath you and not the one next to you.

Parameters:
agent - the agent to check (must be in a map)
p - the predicate used to tell which object to grab.

findTarget

public static GameObject findTarget(Commandable agent,
                                    Predicate match)
This utility method looks first in the agent's inventory, then on the ground beneath the agent, for an object that passes the specified predicate. Unlike findObject() and findNeighbor(), this method doesn't look in squares adjacent the agent.

Parameters:
agent - agent
match - predicate to match with

findInMap

public static GameObject findInMap(Commandable agent,
                                   Predicate p)
Searches for an object matching the specified predicate. Only looks in the map immediately beneath the agent.

Parameters:
agent - the agent to check (must be in a map)
p - the predicate used to tell which object to grab.
Returns:
the first matching object, or null if not found

createVisiblePredicate

public static Predicate createVisiblePredicate(Predicate p,
                                               Commandable agent)
Takes a predicate and wraps it with another predicate that makes sure the returned object isn't invisible to the agent.

Parameters:
p - the original predicate
agent - the agent trying to find something

findAllMatches

public static java.util.List findAllMatches(Commandable agent,
                                            Predicate p)
Finds all objects in the map, adjacent to or beneath the agent, that match the passed predicate.

Parameters:
agent - the agent to check (must be in a map)
p - the predicate used to tell which object to grab.
Returns:
all matching objects, or an empty list if none are found