|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.game.SOCVersionedItem soc.game.SOCScenario
public class SOCScenario
Scenarios for game rules and options on the large sea board
.
Chooseable at game creation.
This class holds the known scenarios, at the client or server,
in a static dictionary of known scenarios; see getAllKnownScenarios()
for the current list of all known scenarios.
For information about adding or changing game scenarios in a
later version of JSettlers, please see initAllScenarios()
.
Scenarios use SOCGameOption
s to change the game to the scenario's concept.
Each scenario's scOpts
field gives the scenario's option names and values.
The game also knows its scenario by setting SOCGameOption
"SC" = key
.
Scenario name keys must start with a letter and contain only ASCII uppercase
letters ('A' through 'Z'), underscore ('_'), and digits ('0' through '9'), in order to normalize
handling and network message formats. This is enforced in constructors via
SOCVersionedItem.isAlphanumericUpcaseAscii(String)
.
For the same reason, descriptions must not contain
certain characters or span more than 1 line; this is checked by calling
SOCMessage.isSingleLineAndSafe(String)
within constructors and setters.
The "known scenarios" are initialized via initAllScenarios()
. See that
method's description for more details on adding or changing a scenario.
Version negotiation:
Game options were introduced in 1.1.07; check server, client versions against
SOCNewGameWithOptions.VERSION_FOR_NEWGAMEWITHOPTIONS
.
Scenarios were introduced in 2.0.00, and negotiate the same way.
Each scenario has version information, because scenarios can be added or changed
with new versions of JSettlers. Since games run on the server, the server is
authoritative about game scenarios and options: If the client is newer, it must defer to the
server's older set of known scenarios and options. At client connect, the client compares its
JSettlers version number to the server's, and asks for any changes if
their versions differ.
I18N:
Game scenario names and descriptions are also stored as gamescen.*.n
, .p
in server/strings/toClient_*.properties
to be sent to clients if needed.
A scenario's text can be localized with setDesc(String, String)
.
Field Summary | |
---|---|
private static java.util.Map<java.lang.String,SOCScenario> |
allScenarios
Set of "known scenarios". |
static java.lang.String |
K_SC_4ISL
Scenario key SC_4ISL for The Four Islands. |
static java.lang.String |
K_SC_CLVI
Scenario key SC_CLVI for SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE :
Cloth Trade with neutral villages . |
static java.lang.String |
K_SC_FOG
Scenario key SC_FOG for SOCScenarioGameEvent.SGE_FOG_HEX_REVEALED (The Fog Islands scenario). |
static java.lang.String |
K_SC_FTRI
Scenario key SC_FTRI for the Forgotten Tribe. |
static java.lang.String |
K_SC_NSHO
Scenario key SC_NSHO for New Shores. |
static java.lang.String |
K_SC_PIRI
Scenario key SC_PIRI for Pirate Islands and fortresses . |
static java.lang.String |
K_SC_TTD
Scenario key SC_TTD for Through The Desert. |
static java.lang.String |
K_SC_WOND
Scenario key SC_WOND for Wonders. |
private java.lang.String |
scLongDesc
Detailed text for the scenario description and special rules, or null. |
java.lang.String |
scOpts
Scenario's SOCGameOption s, as a formatted string
from SOCGameOption.packOptionsToString(Map, boolean) . |
static int |
VERSION_FOR_SCENARIOS
Version 2.0.00 (2000) introduced game scenarios. |
Fields inherited from class soc.game.SOCVersionedItem |
---|
desc, isKnown, key, lastModVersion, minVersion |
Constructor Summary | |
---|---|
private |
SOCScenario(boolean isKnown,
java.lang.String key,
int minVers,
int lastModVers,
java.lang.String desc,
java.lang.String longDesc,
java.lang.String opts)
Create a new game scenario - common constructor. |
|
SOCScenario(java.lang.String key)
Create a new unknown scenario ( isKnown false). |
|
SOCScenario(java.lang.String key,
int minVers,
int lastModVers,
java.lang.String desc,
java.lang.String longDesc,
java.lang.String opts)
Create a new known game scenario. |
Method Summary | |
---|---|
static boolean |
addKnownScenario(SOCScenario scNew)
Add a new known scenario (received from a server having a newer or older version), or update the scenario's information. |
static void |
addScenario(java.util.Map<java.lang.String,SOCScenario> newScens,
java.lang.String scKey)
If a set of scenarios doesn't already include this known scenario, clone and add it. |
static java.lang.StringBuilder |
adjustScenariosToKnown(java.util.Map<java.lang.String,SOCScenario> newScens,
java.util.Map<java.lang.String,SOCScenario> knownScenarios,
boolean doServerPreadjust)
Compare a set of scenarios with known-good values. |
static java.util.Map<java.lang.String,SOCScenario> |
cloneScenarios(java.util.Map<java.lang.String,SOCScenario> scens)
Clone this scenario map and its contents. |
int |
compareTo(java.lang.Object other)
Compare two scenarios, for display purposes. |
boolean |
equals(java.lang.Object other)
Test if this scenario equals another object. |
static java.util.Set<java.lang.String> |
getAllKnownScenarioKeynames()
Get the key names for all known scenarios. |
static java.util.Map<java.lang.String,SOCScenario> |
getAllKnownScenarios()
Get all known scenario objects, mapping from their key names (such as SC_4ISL ). |
java.lang.String |
getLongDesc()
Detailed text for the scenario description and special rules, or null. |
static SOCScenario |
getScenario(java.lang.String key)
Get the scenario information about this known scenario. |
int |
hashCode()
Return this scenario's hashCode for comparison purposes, which is its key 's String.hashCode() . |
private static java.util.Map<java.lang.String,SOCScenario> |
initAllScenarios()
Create a set of the known scenarios. |
static java.lang.String |
packKnownScenariosToString()
Utility - build a string of known scenario key names from the known scenarios . |
static java.lang.String |
packScenariosToString(java.util.Map<java.lang.String,SOCScenario> scMap)
Utility - build a string of known scenario names. |
static java.lang.String |
packScenariosToString(java.util.Map<java.lang.String,SOCScenario> scMap,
int cliVers)
Utility - build a string of known scenario names, adjusting for old clients if necessary. |
static java.util.Map<java.lang.String,SOCScenario> |
parseScenariosToMap(java.lang.String scstr)
Utility - build a map by parsing a list of scenario names. |
static void |
removeUnknownScenario(java.lang.String scKey)
Remove a scenario from known scenarios, based on info received from a server having an older or newer version. |
void |
setDesc(java.lang.String desc,
java.lang.String longDesc)
For i18n, update the scenario's description text fields: The name/short description ( SOCVersionedItem.getDesc() ) and optional long description (getLongDesc() ). |
java.lang.String |
toString()
Get this scenario's description, for use in user-facing displays and GUI elements. |
Methods inherited from class soc.game.SOCVersionedItem |
---|
findUnknowns, getDesc, getMinVersion, implItemsVersionCheck, isAlphanumericUpcaseAscii, itemsForVersion, itemsMinimumVersion, itemsMinimumVersion, itemsNewerThanVersion, setDesc |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int VERSION_FOR_SCENARIOS
private static java.util.Map<java.lang.String,SOCScenario> allScenarios
isKnown
flag set true.
To add or change a scenario, see initAllScenarios()
.
public static final java.lang.String K_SC_NSHO
SC_NSHO
for New Shores.
Board layout is the standard 4- or 6-player board, or a smaller 3-player main island, plus small
outlying islands. No main option or special rules, only the board layout and 2 SVP for reaching each island.
public static final java.lang.String K_SC_4ISL
SC_4ISL
for The Four Islands.
No main option or special rules, only a board layout and SVP.
public static final java.lang.String K_SC_FOG
SC_FOG
for SOCScenarioGameEvent.SGE_FOG_HEX_REVEALED
(The Fog Islands scenario).
Main option is SOCGameOption.K_SC_FOG
.
public static final java.lang.String K_SC_TTD
SC_TTD
for Through The Desert.
No main option or special rules, only a board layout and SVP.
public static final java.lang.String K_SC_CLVI
SC_CLVI
for SOCScenarioPlayerEvent.CLOTH_TRADE_ESTABLISHED_VILLAGE
:
Cloth Trade with neutral villages
.
Main option is SOCGameOption.K_SC_CLVI
.
public static final java.lang.String K_SC_PIRI
SC_PIRI
for Pirate Islands and fortresses
.
Main option is SOCGameOption.K_SC_PIRI
.
A pirate fleet circulates on a predefined path, stealing resources from weak players with adjacent settlements/cities until the player upgrades their ships to warships. To win, the player must build ships directly to the Fortress with their color, and defeat it several times using warships. Also, ship routes can't branch in different directions in this scenario, only extend from their ends.
public static final java.lang.String K_SC_FTRI
SC_FTRI
for the Forgotten Tribe.
Main option is "_SC_FTRI"
.
Far areas of the board have small habitations of a "forgotten tribe" of settlers. When players reach them (with a ship adjacent to various edge coordinates), they are greeted with "gifts" of a development card or Special Victory Point.
Trade ports at these far areas can be claimed by players and must be moved adjacent to one of their coastal settlements/cities, unless they have none that isn't at least separated 1 edge from an existing port. If that's the case, the claimed port is "set aside" for the player to place later when they have such a coastal settlement.
When a player reaches a Special Edge and is awarded a gift, the game clears that edge's special
type, then fires a SOCScenarioPlayerEvent.DEV_CARD_REACHED_SPECIAL_EDGE
or
SOCScenarioPlayerEvent.SVP_REACHED_SPECIAL_EDGE
event.
When a player reaches a "gift" trade port, either the port is added to their inventory
as a SOCInventoryItem
for later placement, or they must immediately place it:
SOCGame.setPlacingItem(SOCInventoryItem)
is called, state becomes SOCGame.PLACING_INV_ITEM
.
public static final java.lang.String K_SC_WOND
SC_WOND
for Wonders.
Main option is "_SC_WOND"
.
The pirate ship is not used in this scenario.
Players must choose a unique Wonder and build all 4 of its levels. Each Wonder has its own requirements before they may start it, such as a harbor location or number of cities built.
When a player starts to build a wonder, it's added to their Special Items for visibility; see below.
To win, the player must complete their Wonder's 4 levels, or reach 10 VP and complete more levels than any other player.
Certain sets of nodes are special in this scenario's board layout.
Node sets are retrieved from SOCBoardLarge.getAddedLayoutPart(String)
by key:
"N1"
: Desert Wasteland (for Great Wall wonder)
"N2"
: Strait (for Great Bridge wonder)
"N3"
: Adjacent to Strait (N2
); initial placement not allowed here
(this set is emptied after initial placement)
"AL"
to specify that the nodes in N1, N2,
and N3
become legal locations for settlements after initial placement.
The Wonders are stored as per-game Special Items: There are (1 + SOCGame.maxPlayers
) wonders available,
held in game Special Item indexes 1 - n, with type key SOCGameOption.K_SC_WOND
,
initialized in SOCGame.updateAtBoardLayout()
. When a player starts to build a Wonder, a reference
to its SOCSpecialItem
is placed into index 0 of their Special Items:
pl.setSpecialItem("_SC_WOND", 0, item)
.
The player's request to build must use player item index (pi) 0, game item index (gi) 1 to n.
public java.lang.String scOpts
SOCGameOption
s, as a formatted string
from SOCGameOption.packOptionsToString(Map, boolean)
.
private java.lang.String scLongDesc
getLongDesc()
for more info and requirements.
Constructor Detail |
---|
public SOCScenario(java.lang.String key) throws java.lang.IllegalArgumentException
isKnown
false).
Minimum version will be Integer.MAX_VALUE
.
scDesc and scOpts will be an empty string.
key
- Alphanumeric key name for this option;
see SOCVersionedItem.isAlphanumericUpcaseAscii(String)
for format.
java.lang.IllegalArgumentException
- if key length is > 8 or not alphanumericpublic SOCScenario(java.lang.String key, int minVers, int lastModVers, java.lang.String desc, java.lang.String longDesc, java.lang.String opts) throws java.lang.IllegalArgumentException
key
- Alphanumeric key name for this scenario;
see SOCVersionedItem.isAlphanumericUpcaseAscii(String)
for format.minVers
- Minimum client version supporting this scenario, or -1.
Same format as Version.versionNumber()
.
If not -1, minVers
must be at least 2000 (VERSION_FOR_SCENARIOS
).
To calculate the minimum version of a set of game options which might include a scenario,
use SOCVersionedItem.itemsMinimumVersion(opts)
.
That calculation won't be done automatically by this constructor.lastModVers
- Last-modified version for this scenario, or version which added it.
This is the last change to the scenario itself as declared in getAllKnownScenarios()
:
Ignore changes to opts
last-modified versions, because changed option info
is sent separately and automatically when the client connects.desc
- Descriptive brief text, to appear in the scenarios dialog.
Desc must not contain SOCMessage.sep_char
or SOCMessage.sep2_char
,
and must evaluate true from SOCMessage.isSingleLineAndSafe(String)
.longDesc
- Longer descriptive text, or null; see getLongDesc()
for requirements.opts
- Scenario's SOCGameOption
s, as a formatted string
from SOCGameOption.packOptionsToString(Map, boolean)
.
Never "" or null
.
java.lang.IllegalArgumentException
- if key length is > 8 or not alphanumeric,
or if opts is null
or the empty string "",
or if desc contains SOCMessage.sep_char
or SOCMessage.sep2_char
or fail their described requirements,
or if minVers or lastModVers is under 2000 but not -1private SOCScenario(boolean isKnown, java.lang.String key, int minVers, int lastModVers, java.lang.String desc, java.lang.String longDesc, java.lang.String opts) throws java.lang.IllegalArgumentException
isKnown
- True if scenario is known here (isKnown
true)key
- Alphanumeric uppercase code for this scenario;
see SOCVersionedItem.isAlphanumericUpcaseAscii(String)
for format.
Keys can be up to 8 characters long.minVers
- Minimum client version supporting this scenario, or -1.
Same format as Version.versionNumber()
.
If not -1, minVers
must be at least 2000 (VERSION_FOR_SCENARIOS
).
To calculate the minimum version of a set of game options which might include a scenario,
use SOCVersionedItem.itemsMinimumVersion(opts)
.
That calculation won't be done automatically by this constructor.lastModVers
- Last-modified version for this scenario, or version which added it.
This is the last change to the scenario itself as declared in getAllKnownScenarios()
:
Ignore changes to opts
last-modified versions, because changed option info
is sent separately and automatically when the client connects.desc
- Descriptive brief text, to appear in the scenarios dialog.
Desc must not contain SOCMessage.sep_char
or SOCMessage.sep2_char
,
and must evaluate true from SOCMessage.isSingleLineAndSafe(String)
.longDesc
- Longer descriptive text, or null; see getLongDesc()
for requirements.opts
- Scenario's SOCGameOption
s, as a formatted string
from SOCGameOption.packOptionsToString(Map, boolean)
.
Never "" or null
.
java.lang.IllegalArgumentException
- if key is not alphanumeric or length is > 8,
or if desc contains SOCMessage.sep_char
or SOCMessage.sep2_char
,
or if opts is null
or the empty string "",
or if minVers or lastModVers is under 2000 but not -1Method Detail |
---|
private static java.util.Map<java.lang.String,SOCScenario> initAllScenarios()
allScenarios
field.
See getAllKnownScenarios()
for the current list of known scenarios.
"SC_FOG"
for Fog Islands.
The list of already-used key names is here within initAllScenarios().
scOpts
, be sure the scenario's declared
minimum version is >= those options' minimum versions; this won't be validated at runtime.
SOCGameOption
s to change the rules or game behavior,
create and test those; scenario game options all start with "_SC_".
See SOCGameOption.initAllOptions()
for details.
If the new scenario has a new game option just for itself, instead of a reusable one like
_SC_SANY
, the option name is "_" + scenario name:
"_SC_PIRI"
for scenario SC_PIRI
.
SOCGame.canChooseMovePirate()
or SOCGame.rollDice()
.
SC_TTD
has only a board layout,
and doesn't change any game behavior from standard, so there is no "_SC_TTD"
SOCGameOption.
K_SC_FOG
.
Put a short description in the javadoc there and in getAllKnownScenarios()
javadoc's scenario list.
allSc.put
here in initAllScenarios.
Use the current version for the "last modified" field.
SOCBoardLargeAtServer
javadoc.
SOCGame
, don't change any code based on the scenario name;
game behavior changes are based only on the SOCGameOption
s implementing the scenario.
description
long description
options
initAllScenarios()
), the client won't be
allowed to ask for it. Any obsolete scenario should be kept around as commented-out code.
See SOCGameOption.initAllOptions()
for things to think about when removing
game options used only in the obsolete scenario.
public static java.util.Map<java.lang.String,SOCScenario> getAllKnownScenarios()
SC_4ISL
).
SC_NSHO
New Shores
SC_4ISL
The Four Islands (Six on the 6-player board)
SC_FOG
A hex has been revealed from behind fog:
SOCScenarioGameEvent.SGE_FOG_HEX_REVEALED
SC_TTD
Through The Desert
SC_CLVI
Cloth trade with neutral villages
SC_PIRI
Pirate Islands and fortresses
SC_FTRI
The Forgotten Tribe
SC_WOND
Wonders
getAllKnownScenarioKeynames()
,
addKnownScenario(SOCScenario)
public static java.util.Set<java.lang.String> getAllKnownScenarioKeynames()
getAllKnownScenarios()
.
SC_4ISL
.
Please treat the returned set as read-only.getAllKnownScenarios()
public static boolean addKnownScenario(SOCScenario scNew)
scNew
- New scenario, or a changed version of one we already know.
getAllKnownScenarios()
,
removeUnknownScenario(String)
public static void removeUnknownScenario(java.lang.String scKey)
scKey
isn't a known scenario, does nothing.
scKey
- Scenario key marked as unknown by the servergetAllKnownScenarios()
,
addKnownScenario(SOCScenario)
public static java.util.Map<java.lang.String,SOCScenario> cloneScenarios(java.util.Map<java.lang.String,SOCScenario> scens)
scens
- a map of SOCScenario
s, or null
public static SOCScenario getScenario(java.lang.String key)
key
- Scenario key name, such as SC_4ISL
, from getAllKnownScenarios()
public static java.lang.String packKnownScenariosToString()
known scenarios
.
packScenariosToString(Map)
;
any scenarios with isKnown
false will not be
part of the string.parseScenariosToMap(String)
public static java.lang.String packScenariosToString(java.util.Map<java.lang.String,SOCScenario> scMap)
parseScenariosToMap(String)
.
scMap
- Map of scenarios, or null
public static java.lang.String packScenariosToString(java.util.Map<java.lang.String,SOCScenario> scMap, int cliVers)
parseScenariosToMap(String)
.
See packScenariosToString(Map)
javadoc for details.
scMap
- Map of SOCScenarios, or nullcliVers
- Client version; assumed >= 2000 (VERSION_FOR_SCENARIOS
).
If any game's scenarios can't be sent to an older client, skip them.
packScenariosToString(Map)
javadoc for details.public static java.util.Map<java.lang.String,SOCScenario> parseScenariosToMap(java.lang.String scstr)
scstr
- string of key names, as created by
packScenariosToString(Map)
.
A leading comma is OK (possible artifact of StringTokenizer
coming from over the network).
If scstr=="-", the map will be null.
isKnown
false.public static java.lang.StringBuilder adjustScenariosToKnown(java.util.Map<java.lang.String,SOCScenario> newScens, java.util.Map<java.lang.String,SOCScenario> knownScenarios, boolean doServerPreadjust)
newScens
- Set of SOCScenarios to check against knownScenarios;
Must not be null.knownScenarios
- Set of known SOCScenarios to check against, or null to use
the server's static copy
null
if all are known; or, a human-readable problem description if:
newScens
are unknown
SOCVersionedItem.lastModVersion
differs from in knownScenarios
public static void addScenario(java.util.Map<java.lang.String,SOCScenario> newScens, java.lang.String scKey) throws java.lang.NullPointerException
newScens
- Set to set scKey
withinscKey
- Key name for scenario to include
java.lang.NullPointerException
- if scKey
isn't in newScens
and doesn't exist in the set of known scenariospublic java.lang.String getLongDesc()
SOCMessage.sep_char
; SOCMessage.sep2_char
is okay.
Must pass SOCMessage.isSingleLineAndSafe(String, true)
.
Don't include the description of any scenario game option, such as SOCGameOption.K_SC_SANY
;
those will be taken from SOCGameOption.desc
and shown in the reminder message.
To update this field use setDesc(String, String)
.
public void setDesc(java.lang.String desc, java.lang.String longDesc) throws java.lang.IllegalArgumentException
SOCVersionedItem.getDesc()
) and optional long description (getLongDesc()
).
desc
- Descriptive brief text, to appear in the scenarios dialog. Not null.
Desc must not contain SOCMessage.sep_char
or SOCMessage.sep2_char
,
and must evaluate true from SOCMessage.isSingleLineAndSafe(String)
.longDesc
- Longer descriptive text, or null; see getLongDesc()
for requirements.
java.lang.IllegalArgumentException
- if desc contains SOCMessage.sep_char
or SOCMessage.sep2_char
,
or desc or longDesc fails SOCMessage.isSingleLineAndSafe(String, boolean)
SOCVersionedItem.setDesc(String)
public java.lang.String toString()
SOCVersionedItem.key
instead.
toString
in class java.lang.Object
desc
public int compareTo(java.lang.Object other)
Comparable
interface)
Two game scenarios are considered equal if they have the same key
.
Greater/lesser is determined by
getDesc()
.compareTo()
.
compareTo
in interface java.lang.Comparable<java.lang.Object>
other
- A SOCScenario to compare, or another object; if other isn't a
scenario, the hashCode()
s are compared.equals(Object)
public boolean equals(java.lang.Object other)
key
.
equals
in class java.lang.Object
other
- A SOCScenario to compare, or another object; if other isn't a
scenario, calls Object.equals(other)
.compareTo(Object)
,
hashCode()
public int hashCode()
key
's String.hashCode()
.
hashCode
in class java.lang.Object
equals(Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |