net.sourceforge.worldsaver.rp
Class Action

java.lang.Object
  |
  +--net.sourceforge.worldsaver.rp.RpBase
        |
        +--net.sourceforge.worldsaver.rp.Action
All Implemented Interfaces:
MiscUtils, Saveable
Direct Known Subclasses:
Adventure, Campaign, RandomEncounter

public abstract class Action
extends RpBase
implements MiscUtils, Saveable

This is the abstract superclass of all actions. The subclasses must provide the methods isRunnable(), execute(), step() and createActionTree(). Since the creation of the action class is the most complicated task in this framework, it's better to put even slightly different actions in extra classes. It makes the communication and the handling greatly easier.

Version:
Feb 16 2001
Author:
Andreas Schmitz

Fields inherited from interface net.sourceforge.worldsaver.util.MiscUtils
CONSOLE_WIDTH, NEWLINE, RANDOM
 
Constructor Summary
Action(java.util.HashMap loaded)
          Creates a new action of a loaded String.
Action(RpBase father, java.lang.String name)
          Creates a new action with a father and a name.
 
Method Summary
abstract  void createActionTree(ActionParticle top)
          Sets the ActionTree that shall be used for the action.
abstract  void execute()
          Prepares the action for execution.
protected  ActionParticle getActionTree()
          Returns the top of the actiontree (used for saving purposes).
 java.lang.String[] getDecisionMessage()
          If the action is running, this gets the current decision messages.
 Area getLocation()
          This returns the current location the running action takes place.
 void getReferencesRight(java.util.HashMap pool, IDGenerator gen)
          Must set the references right by getting the real objects out of the pool.
 java.lang.String getSaveableString()
          Returns a saveable String describing this object.
 Area getStartLocation()
          Returns the current start location.
 java.lang.String getText()
          This returns (when running) the text explaining the current situation.
abstract  boolean isRunnable()
          Returns whether the action is prepared to be executed.
 boolean isRunning()
          If the execute() method is invoked and running, this returns true.
 void setStartLocation(Area loc)
          Sets the new location where the action starts. loc may be null if the location doesn't matter.
abstract  void step(int index)
          Causes the action to do a step in a specific direction.
 
Methods inherited from class net.sourceforge.worldsaver.rp.RpBase
addChild, addDescription, copy, getChilds, getDescription, getFather, getID, getName, setDescription, setFather, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Action

public Action(RpBase father,
              java.lang.String name)
Creates a new action with a father and a name.
Parameters:
father - the father object
name - the name

Action

public Action(java.util.HashMap loaded)
Creates a new action of a loaded String.
Parameters:
loaded - the HashMap containing the values
gen - the ID-Generator
See Also:
RpBase.RpBase(net.sourceforge.worldsaver.rp.RpBase, java.lang.String)
Method Detail

getReferencesRight

public void getReferencesRight(java.util.HashMap pool,
                               IDGenerator gen)
Description copied from interface: Saveable
Must set the references right by getting the real objects out of the pool. The Pool contains keys as unique Long values.
Specified by:
getReferencesRight in interface Saveable
Overrides:
getReferencesRight in class RpBase
Following copied from interface: net.sourceforge.worldsaver.rp.Saveable
Parameters:
pool - the objects that could be referenced
gen - the ID-Generator for this object

getSaveableString

public java.lang.String getSaveableString()
                                   throws java.io.IOException
Returns a saveable String describing this object. The String which is actually returned from a non-abstract subclass is ready to be saved to file.
Specified by:
getSaveableString in interface Saveable
Overrides:
getSaveableString in class RpBase
Returns:
the String
Throws:
java.io.IOException - if the objects are not valid
See Also:
RpBase.getSaveableString()

isRunning

public boolean isRunning()
If the execute() method is invoked and running, this returns true. If the action has come to an end, this returns false.
Returns:
true if running, and false if not running/at the end

setStartLocation

public void setStartLocation(Area loc)
Sets the new location where the action starts. loc may be null if the location doesn't matter.
Parameters:
loc - the new start location or null

getStartLocation

public Area getStartLocation()
Returns the current start location. Returns null if no start location is specified.
Returns:
the location or null

getDecisionMessage

public java.lang.String[] getDecisionMessage()
If the action is running, this gets the current decision messages. You should do a step() afterwards with the index of the decision that has been chosen. IsRunning() will return false, when the Action has reached an end.
Returns:
the String[] with the messages

getText

public java.lang.String getText()
This returns (when running) the text explaining the current situation. When a thread finished, this returns a final message, perhaps explaining why the party sucks etc.
Returns:
the text

getLocation

public Area getLocation()
This returns the current location the running action takes place. You can use this to get a visualization of the current location.
Returns:
the location

getActionTree

protected ActionParticle getActionTree()
Returns the top of the actiontree (used for saving purposes).
Returns:
the particle

isRunnable

public abstract boolean isRunnable()
Returns whether the action is prepared to be executed.
Returns:
true when ready to be executed

execute

public abstract void execute()
Prepares the action for execution. The first situation (the first step) is executed in this method.

step

public abstract void step(int index)
Causes the action to do a step in a specific direction. The index is the index of the step the party has chosen.
Parameters:
index - the index

createActionTree

public abstract void createActionTree(ActionParticle top)
Sets the ActionTree that shall be used for the action. The action tree should be ready before you insert it here. Depending of its correctness, the action becomes runnable or not.
Parameters:
top - the ActionParticle that builds the top of the tree