megamek.common
Class Report

java.lang.Object
  extended by megamek.common.Report
All Implemented Interfaces:
java.io.Serializable

public class Report
extends java.lang.Object
implements java.io.Serializable

This class defines a single server report. It holds information such as the report ID, who the report is about, who should see the report, and some formatting information.

Typically, the report will be created by the relevant section in the Server, and added to the phase report vector. The actual text of the report must also be added to the report-messages.properties file.

Example:

Report r = new Report(3455);\n r.subject = entity.getId();\n r.indent();\n r.addDesc(entity);\n r.add(6);\n r.choose(true);\n vPhaseReport.addElement(r);

Then the following line would be added to report-messages.properties:

3455::<data> (<data>) does <data> damage to the <msg:3456,3457>.\n 3456::tank\n 3457::building

When the client parses the report, it will fill in the <data> tags with the values that were given to the add methods called on the report object.

The example above might produce a report such as this when the getText method was called:

" Crusader (Bob) does 6 damage to the tank."

Since:
0.30
Version:
$Revision: 7561 $
Author:
Ryan McConnell (oscarmm)
See Also:
Serialized Form

Field Summary
static int HIDDEN
          Report is only visible to those players who can see the subject.
 int messageId
          Required - associates this object with its text.
 int newlines
          The number of newlines to add at the end of this report.
static int OBSCURED
          Report is visible to all players, but all data marked for obscuration remains hidden.
static java.lang.String OBSCURED_STRING
          The string that appears in the report to obscure certain information.
 int player
          the player this report concerns, if applicable.
static int PLAYER
          messages which should be sent only to the player indicated by "player"
static int PUBLIC
          Report is visible to all players.
 int subject
          The entity this report concerns, if applicable.
static int TESTING
          Testing only - remove me later.
 int type
          How this report is handled when double-blind play is in effect.
 
Constructor Summary
Report()
          Default constructor, note that using this means the messageId field must be explicitly set.
Report(int id)
          Create a new report associated with the given report text.
Report(int id, int type)
          Create a new report associated with the given report text and having the given type.
Report(Report r)
          Create a new report which is an exact copy of the given report.
 
Method Summary
 void add(int data)
          Add the given int to the list of data that will be substituted for the <data> tags in the report.
 void add(int data, boolean obscure)
          Add the given int to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information if obscure is true.
 void add(java.lang.String data)
          Add the given String to the list of data that will be substituted for the <data> tags in the report.
 void add(java.lang.String data, boolean obscure)
          Add the given String to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information if obscure is true.
 void addDesc(Entity entity)
          Shortcut method for adding entity name and owner data at the same time.
static void addNewline(java.util.Vector<Report> v)
          Adds a newline to the last report in the given Vector.
 void addObscuredRecipient(java.lang.String playerName)
          Internal method.
 void choose(boolean choice)
          Indicate which of two possible messages should be substituted for the <msg:n,m> tag.
 int dataCount()
          Internal method.
 java.lang.String getText()
          Get the report in its final form, with all the necessary substitutions made.
 void hideData(int index)
          Internal method.
 void indent()
          Indent the report.
 void indent(int n)
          Indent the report n times.
static void indentAll(java.util.Vector<Report> vDesc, int amount)
           
 boolean isObscuredRecipient(java.lang.String playerName)
          Internal method.
 boolean isValueObscured(int index)
          Internal method.
 void markForTesting()
          DEBUG method - do not use
 java.lang.String toString()
          Useful for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

messageId

public int messageId
Required - associates this object with its text.


newlines

public int newlines
The number of newlines to add at the end of this report. Defaults to one.


type

public transient int type
How this report is handled when double-blind play is in effect. See constants below for more details.


PUBLIC

public static final int PUBLIC
Report is visible to all players.

See Also:
Constant Field Values

OBSCURED

public static final int OBSCURED
Report is visible to all players, but all data marked for obscuration remains hidden. Note: Not used at this time, since all reports are considered obscured unless explicitly marked public.

See Also:
Constant Field Values

HIDDEN

public static final int HIDDEN
Report is only visible to those players who can see the subject. Note: Not used at this time, since all reports are considered obscured unless explicitly marked public.

See Also:
Constant Field Values

TESTING

public static final int TESTING
Testing only - remove me later.

See Also:
Constant Field Values

PLAYER

public static final int PLAYER
messages which should be sent only to the player indicated by "player"

See Also:
Constant Field Values

subject

public transient int subject
The entity this report concerns, if applicable. If this is left blank, then the report will be considered public.


player

public transient int player
the player this report concerns, if applicable. This should be filled in if this report is not public and still does not belong to a specific visible entity


OBSCURED_STRING

public static final java.lang.String OBSCURED_STRING
The string that appears in the report to obscure certain information.

See Also:
Constant Field Values
Constructor Detail

Report

public Report()
Default constructor, note that using this means the messageId field must be explicitly set.


Report

public Report(int id)
Create a new report associated with the given report text.

Parameters:
id - the int value of the report from report-messages.properties

Report

public Report(int id,
              int type)
Create a new report associated with the given report text and having the given type.

Parameters:
id - the int value of the report from report-messages.properties
type - the constant specifying the visibility of the report (PUBLIC, OBSCURED, or HIDDEN)

Report

public Report(Report r)
Create a new report which is an exact copy of the given report.

Parameters:
r - the report to be copied
Method Detail

add

public void add(int data)
Add the given int to the list of data that will be substituted for the <data> tags in the report. The order in which items are added must match the order of the tags in the report text.

Parameters:
data - the int to be substituted

add

public void add(int data,
                boolean obscure)
Add the given int to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information if obscure is true. The order in which items are added must match the order of the tags in the report text.

Parameters:
data - the int to be substituted
obscure - boolean indicating whether the data is double-blind sensitive

add

public void add(java.lang.String data)
Add the given String to the list of data that will be substituted for the <data> tags in the report. The order in which items are added must match the order of the tags in the report text.

Parameters:
data - the String to be substituted

add

public void add(java.lang.String data,
                boolean obscure)
Add the given String to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information if obscure is true. The order in which items are added must match the order of the tags in the report text.

Parameters:
data - the String to be substituted
obscure - boolean indicating whether the data is double-blind sensitive

choose

public void choose(boolean choice)
Indicate which of two possible messages should be substituted for the <msg:n,m> tag. An argument of true would select message n while an argument of false would select m. In the future, this capability may be expanded to support more than two choices.

Parameters:
choice - boolean indicating which message to substitute

addDesc

public void addDesc(Entity entity)
Shortcut method for adding entity name and owner data at the same time. Assumes that the entity name should be obscured, but the owner should not.

Parameters:
entity - the entity you wish to add

isValueObscured

public boolean isValueObscured(int index)
Internal method. Not for typical use.

Tests wheter the data value at the given index has been marked as obscured.

Parameters:
index - position of data value (indexes are chronological and start at zero)
Returns:
true if the data value was marked obscured

hideData

public void hideData(int index)
Internal method. Not for typical use.

Remove the data value from the report. This operation is irreversible.

Parameters:
index - position of data value (indexes are chronological and start at zero

indent

public void indent()
Indent the report.


indent

public void indent(int n)
Indent the report n times.

Parameters:
n - the number of times to indent the report

dataCount

public int dataCount()
Internal method. Not for typical use.

Get the total number of data values associated with this report. Note that this includes the true/false values added for <msg> tags as well.

Returns:
the number of data values

getText

public java.lang.String getText()
Get the report in its final form, with all the necessary substitutions made.

Returns:
a String with the final report

addNewline

public static void addNewline(java.util.Vector<Report> v)
Adds a newline to the last report in the given Vector.

Parameters:
v - a Vector of Report objects

addObscuredRecipient

public void addObscuredRecipient(java.lang.String playerName)
Internal method. Not for typical use.

Adds the given player name to the report's list of players who received an obscured version of this report from the server at some time in the past.

Parameters:
playerName - the String containing the player's name

isObscuredRecipient

public boolean isObscuredRecipient(java.lang.String playerName)
Internal method. Not for typical use.

Tests whether the given player name is on the report's list of players who received an obscured version of this report from the server at some time in the past.

Parameters:
playerName - the String containing the player's name
Returns:
true if the player was sent an obscured version of this report

toString

public java.lang.String toString()
Useful for debugging purposes.

Overrides:
toString in class java.lang.Object
Returns:
a String of the form "Report(messageId=n)"

markForTesting

public void markForTesting()
DEBUG method - do not use


indentAll

public static void indentAll(java.util.Vector<Report> vDesc,
                             int amount)