wyvern.lib.classes
Class Vehicle

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.kernel.commands.AbstractCommandable
              extended bywyvern.lib.classes.Vehicle
All Implemented Interfaces:
Applyable, Broadcaster, Command, Commandable, GameObject, Hookable, HookCallback, MethodHookable, MethodHookCallback, PropertyList, RemoteAudio
Direct Known Subclasses:
Ship

public class Vehicle
extends AbstractCommandable
implements Applyable, Command, HookCallback, MethodHookCallback

This class implements a generic vehicle that can be boarded and piloted around.

Version:
1.0, Dec 08, 1998
Author:
Steve Yegge

Field Summary
 
Fields inherited from class wyvern.kernel.commands.AbstractCommandable
hookList_, queue_, started_
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Fields inherited from interface wyvern.common.net.RemoteAudio
DEFAULT_ALERT_GAIN, DEFAULT_ALERT_REPEAT_DELAY, DEFAULT_ALERT_REPEATS, DEFAULT_GAIN, DEFAULT_REPEAT_DELAY, DEFAULT_REPEATS
 
Constructor Summary
Vehicle()
           
 
Method Summary
 void addCamera(Camera cam)
          Adds a camera to our control-list.
 void addHooks(Player p)
          Adds hooks to be notified before & after moves.
 void addPilot(Commandable agent)
          Adds the passed Commandable as a pilot of the vehicle.
protected  boolean adjacentTo(java.util.List alocs, Point p, java.util.List locs)
          Checks whether the proposed destination would put the agent within one square of the vehicle.
 void apply(Commandable agent)
          The vehicle is being applied/boarded.
 boolean boardPassenger(Commandable agent)
          Puts a passenger in the vehicle, if there's room.
 void createCommandList()
          Creates a CommandList holding the built-in game commands that we respond to.
 CommandEvent createEvent(CommandEvent initialInfo)
          Creates a CommandEvent that encapsulates the command.
protected  GameMap createInteriorMap()
          This method is called from initialize() to create the interior of the vehicle.
 boolean disembark(Commandable agent)
          Removes a passenger from the vehicle.
protected  void ensureAI()
          We have no AI.
 boolean execute(CommandEvent event)
          Executes the specified CommandEvent.
 Point findDisembarkLocation(Commandable agent)
          Looks for a place to dump the player upon disembarking.
 Point getCameraPos()
          Returns the position at which to place cameras viewing the vehicle from the outside.
 Command getCommand(CommandEvent event)
          Returns the Command to handle our commands.
 GameMap getInteriorMap()
          Returns the vehicle-interior map.
 void grabCamera(Player p)
          Puts a player's camera outside the vehicle so they can see where it's going.
protected  boolean handleExit(CommandEvent event)
          Player wants out.
 void handleFailedPostMove(CommandEvent event)
          Handles notifying the player, after we moved, if something went wrong.
 void handleLookXY(CommandEvent event)
          Handles mouse-click for looking at an object.
 void handleMouse(CommandEvent ev)
          Handles mouse clicks while player is in the vehicle.
protected  boolean handlePilot(CommandEvent event)
          Turns vehicle piloting (i.e. overriding moves to move the vehicle) on or off.
 void handlePreMove(CommandEvent event)
          Figures out whether to move the vehicle instead of the agent.
 void handleTeleport(CommandEvent event)
          See if we can intercept teleporting out of the vehicle.
protected  boolean handleView(CommandEvent event)
          Handles the "view" command, by way of which the user can put their camera inside or outside the vehicle.
 void hookEvent(java.lang.String hookName, CommandEvent event)
          Hooks motion events.
 void initialize()
          Initializes the object's default properties.
 boolean isPilot(Commandable agent)
          Returns true if the agent is listed among the vehicles's pilots.
 boolean isValidDir(int dir)
          Returns whether the passed direction (interpreted as a wyvern.lib.Direction constant) is a valid direction for this vehicle.
 boolean knowsCommand(java.lang.String command)
          Returns true if we want to handle the command.
 void methodCalled(java.lang.String hookName, MethodHookable target, java.lang.Object data)
          Shuts down the ship if the map is unloading.
 void printWelcome(Commandable agent)
          Prints the welcome message when the agent boards the vessel.
 void relinquishCamera(Player p)
          Puts the camera back under the control of the player.
 void remove()
          Removes from the map.
 void removeCamera(Camera cam)
          Removes a camera from our control-list.
 void removeHooks(Player p)
          Removes ourself from any hooks we got on.
 void removePilot(Commandable agent)
          Removes the specified agent from the pilot-list.
 void setMap(GameMap map, int x, int y)
          Puts the vehicle in a new map.
 void teleport(int x, int y)
          Teleports the object to a completely new map location.
 void toggleView(Player p)
          Toggles the player's camera from inside to out & vice-versa.
 Point translateToThisMap(Point p, Player player)
          Translates the point from the agent's coordinate space into our coordinate space.
 void unhookPlayer(Commandable agent)
          Removes any hooks, commands and camera-manipulation stuff that were added when the player boarded.
 void updateMapLocation(java.util.List oldpos, java.util.List newpos)
          Translates the object to a new relative location.
 boolean viewingInside(Player p)
          Returns true if the player is looking inside the vehicle.
 
Methods inherited from class wyvern.kernel.commands.AbstractCommandable
addAttack, addHook, addMessageListener, addMethodHook, checkAnimated, command, command, commandNow, destroy, ensureEventQueue, fireMessageReceived, getAI, getCapName, getCombatQueue, getEncumbrance, getFiringPoint, getHookList, getHooks, getInventory, getName, getQueue, isCommandable, isStarted, isTelnet, message, message, message, pauseSound, playAlert, playAlert, playDefaultMusic, playPriorityMusic, playPriorityMusic, playSound, playSound, registerCommand, removeAttack, removeHook, removeMessageListener, removeMethodHook, resumeSound, runFailedPostHook, runMethodHook, runPostHook, runPreHook, sendPicture, sendPicture, setAI, setEncumbrance, setMusicGain, setName, setSoundGain, start, stop, stopAllSounds, stopMusic, stopSound, unregisterCommand
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, toString
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.GameObject
addContainerChangeListener, addMapChangeListener, addMapMotionListener, addMotionTracker, addObjectTracker, addPrefix, addSuffix, bless, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, externalize, getAlpha, getAppearance, getArchetype, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, inContainer, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, removeContainerChangeListener, removeMapChangeListener, removeMapMotionListener, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from interface wyvern.lib.Broadcaster
broadcast, broadcast, broadcast, broadcast, broadcast
 

Constructor Detail

Vehicle

public Vehicle()
Method Detail

initialize

public void initialize()
Description copied from interface: GameObject
Initializes the object's default properties. Any GameObject implementation that wishes to initialize itself should do so here, rather than in the constructor. This is because nearly all game objects inherit from an archetype, and the archetype parent pointer isn't set until the object's constructor finishes. This is a good place to add any class-default properties for an object - properties that the object gets regardless of which archetype it inherits from. WARNING: don't forget to call the superclass' initialize() method, or the object may not function properly. For instance, it won't become animated even if it specifies animation parameters in the archetype.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class MapObject

ensureAI

protected void ensureAI()
We have no AI.

Overrides:
ensureAI in class AbstractCommandable

createInteriorMap

protected GameMap createInteriorMap()
This method is called from initialize() to create the interior of the vehicle. Subclasses (e.g. horses) need not create interiors and can override this method to do nothing.

It's possible for a vehicle to specify a predefined map for its interior. The map is specified in a property called "interior", the map referenced by the property is loaded by the MapLoader and used by the vehicle for depositing players. The dimensions of the map determine how many people will fit in the vehicle.

Vehicle subclasses are also free to create their interior maps during construction, by overriding this method, ignoring any "interior" or "template" property, and instantiating a GameMap implementation directly.


apply

public void apply(Commandable agent)
The vehicle is being applied/boarded.

Specified by:
apply in interface Applyable
Parameters:
agent - the boarder

boardPassenger

public boolean boardPassenger(Commandable agent)
Puts a passenger in the vehicle, if there's room.

Parameters:
agent - the passenger to board
Returns:
true if they were boarded successfully

disembark

public boolean disembark(Commandable agent)
Removes a passenger from the vehicle.

Parameters:
agent - the agent to remove
Returns:
true if the agent disembarked successfully

findDisembarkLocation

public Point findDisembarkLocation(Commandable agent)
Looks for a place to dump the player upon disembarking.

Parameters:
agent - the person disembarking
Returns:
a point to put them, or null if there isn't a place

adjacentTo

protected boolean adjacentTo(java.util.List alocs,
                             Point p,
                             java.util.List locs)
Checks whether the proposed destination would put the agent within one square of the vehicle.

Parameters:
alocs - the agent relative location list
p - the proposed reference location
locs - our location list
Returns:
true if the agent would be adjacent to (or overlap with) us

unhookPlayer

public void unhookPlayer(Commandable agent)
Removes any hooks, commands and camera-manipulation stuff that were added when the player boarded. Doesn't kick the player out of the vehicle, though.

Parameters:
agent - the person leaving the vehicle

printWelcome

public void printWelcome(Commandable agent)
Prints the welcome message when the agent boards the vessel. Looks for a String property called "welcome-msg"; failing that, it prints some default help text.


addCamera

public void addCamera(Camera cam)
Adds a camera to our control-list. When we move, we update all cameras in this list. If the player toggles their camera to the interior of the vehicle, we take it out of the list.


removeCamera

public void removeCamera(Camera cam)
Removes a camera from our control-list.

Parameters:
cam - the camera to remove. Does nothing if the camera wasn't in the list.

updateMapLocation

public void updateMapLocation(java.util.List oldpos,
                              java.util.List newpos)
Translates the object to a new relative location. E.g. to move an object right one square, call obj.move ( 1, 0 ). Use teleport() to move the object to a new absolute position.

The preferred way to move an object is to command() it with command ( "move <direction>" ). This will ensure that the object only moves as fast as it can, and will run the pre- and post-move hooks so that others can participate in the event, possibly vetoing it if it's not allowed.

Overrides:
updateMapLocation in class MapObject
Parameters:
oldpos - previous position
newpos - new position

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Puts the vehicle in a new map.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject
Parameters:
map - the GameMap we're going to.

remove

public void remove()
Removes from the map.

Specified by:
remove in interface GameObject
Overrides:
remove in class MapObject

methodCalled

public void methodCalled(java.lang.String hookName,
                         MethodHookable target,
                         java.lang.Object data)
Shuts down the ship if the map is unloading.

Specified by:
methodCalled in interface MethodHookCallback
Parameters:
hookName - the name of the hook being run
target - the object on which the method was invoked: a GameMap or GameObject.
data - a method-specific data object; can be null. Check the documentation for the method hook to see if any data is passed to the callbacks.

teleport

public void teleport(int x,
                     int y)
Teleports the object to a completely new map location. The old position is ignored and no translation happens. The point you pass is where it winds up.

Specified by:
teleport in interface GameObject
Overrides:
teleport in class MapObject
Parameters:
x - the new x location for the object.
y - the new y location for the object.

relinquishCamera

public void relinquishCamera(Player p)
Puts the camera back under the control of the player.

Parameters:
p - the player whose camera to move

grabCamera

public void grabCamera(Player p)
Puts a player's camera outside the vehicle so they can see where it's going.

Parameters:
p - the player whose camera to move

getCameraPos

public Point getCameraPos()
Returns the position at which to place cameras viewing the vehicle from the outside.

Returns:
a Point roughly at the center of the vehicle

getInteriorMap

public GameMap getInteriorMap()
Returns the vehicle-interior map.

Returns:
the map, or null if the vehicle has no interior map

addHooks

public void addHooks(Player p)
Adds hooks to be notified before & after moves.


removeHooks

public void removeHooks(Player p)
Removes ourself from any hooks we got on.


getCommand

public Command getCommand(CommandEvent event)
Returns the Command to handle our commands. We handle most of our commands, but we do respond to some built-in game commands.

Specified by:
getCommand in interface Commandable
Overrides:
getCommand in class AbstractCommandable
Parameters:
event - the event with the command to execute
Returns:
the Command that will handle the command

createCommandList

public void createCommandList()
Creates a CommandList holding the built-in game commands that we respond to. Mostly it's for motion commands.


knowsCommand

public boolean knowsCommand(java.lang.String command)
Returns true if we want to handle the command.

Subclasses often need to override this method. It's always a good idea to check the command arguments and make sure the command was really intended for us.

Specified by:
knowsCommand in interface Command
Parameters:
command - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent initialInfo)
Creates a CommandEvent that encapsulates the command.

Specified by:
createEvent in interface Command
Parameters:
initialInfo - a "blank" CommandEvent containing only the command text and the agent who's performing the command.
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Executes the specified CommandEvent. The CommandEvent contains all the parameters and state required to execute the command; the parameters have been filtered through hook objects, so they may not be the same as when the event was created.

Specified by:
execute in interface Command
Parameters:
event - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.

handlePilot

protected boolean handlePilot(CommandEvent event)
Turns vehicle piloting (i.e. overriding moves to move the vehicle) on or off.

Parameters:
event - the "pilot" command event
Returns:
false if we couldn't parse the argument

handleExit

protected boolean handleExit(CommandEvent event)
Player wants out.

Parameters:
event - the "exit" command event
Returns:
true if the agent exited successfully

handleView

protected boolean handleView(CommandEvent event)
Handles the "view" command, by way of which the user can put their camera inside or outside the vehicle.

Parameters:
event - the "view" command event
Returns:
true if the event completed successfully

toggleView

public void toggleView(Player p)
Toggles the player's camera from inside to out & vice-versa.

Parameters:
p - the player whose camera we should toggle

viewingInside

public boolean viewingInside(Player p)
Returns true if the player is looking inside the vehicle.

Parameters:
p - the player
Returns:
true if the camera is in the vehicle, following the player. false if it's outside, viewing the vehicle.

hookEvent

public void hookEvent(java.lang.String hookName,
                      CommandEvent event)
Hooks motion events.

Specified by:
hookEvent in interface HookCallback
Parameters:
hookName - the name of the hook, such as "movePreHook".
event - the CommandEvent encapsulating the event parameters

handleTeleport

public void handleTeleport(CommandEvent event)
See if we can intercept teleporting out of the vehicle.


handlePreMove

public void handlePreMove(CommandEvent event)
Figures out whether to move the vehicle instead of the agent. If so, the event is modified so that upon execution, the vehicle will try to move in the direction.

Parameters:
event - the MoveEvent about to take place

handleFailedPostMove

public void handleFailedPostMove(CommandEvent event)
Handles notifying the player, after we moved, if something went wrong.


handleLookXY

public void handleLookXY(CommandEvent event)
Handles mouse-click for looking at an object. If the player is currently viewing outside the ship, we change the target of the lookxy event to be the object they clicked on at the coordinates outside the ship.


translateToThisMap

public Point translateToThisMap(Point p,
                                Player player)
Translates the point from the agent's coordinate space into our coordinate space.


isPilot

public boolean isPilot(Commandable agent)
Returns true if the agent is listed among the vehicles's pilots. Being in this list allows the agent to move the vehicle by issuing normal movement commands.

Parameters:
agent - the agent to check
Returns:
true if they're currently "piloting" the vehicle; i.e., the vehicle moves when the agent moves.

addPilot

public void addPilot(Commandable agent)
Adds the passed Commandable as a pilot of the vehicle. A pilot's normal motion commands get converted into commands to move the vehicle.

Parameters:
agent - the new pilot

removePilot

public void removePilot(Commandable agent)
Removes the specified agent from the pilot-list. The agent's move commands will move the agent around inside the vehicle rather than moving the vehicle.


isValidDir

public boolean isValidDir(int dir)
Returns whether the passed direction (interpreted as a wyvern.lib.Direction constant) is a valid direction for this vehicle.


handleMouse

public void handleMouse(CommandEvent ev)
Handles mouse clicks while player is in the vehicle.