Fix a number of problems with options, making sure they get sent to the client in the updated spec. Also add an option to allow founding father recruitment to continue after declaring independence.

This commit is contained in:
Mike Pope 2011-07-30 07:20:46 +00:00
parent e8233d5020
commit 33c92cfa9b
7 changed files with 110 additions and 60 deletions

View File

@ -1903,6 +1903,10 @@
<!-- Missionaries grant visibility and enhance trade and training -->
<booleanOption id="model.option.enhancedMissionaries"
defaultValue="false"/>
<!-- Founding father recruitment continues after declaring
independence -->
<booleanOption id="model.option.continueFoundingFatherRecruitment"
defaultValue="false"/>
</optionGroup>
<optionGroup id="gameOptions.colony">
<!-- Does the Custom House sell boycotted goods -->

View File

@ -29,6 +29,11 @@ New features should in general not be added before we reach
FreeCol 1.0.0, unless they are implemented as optional features
using the class "GameOptions".
(Note that if you add a game option, add a default value setting in
FreeColServer.fixGameOptions so that use of the option does not break
old games. The same applies to client-options,
in ClientOptions.fixClientOptions.)
The big exception to this rule is the our client-server model that
will allow players from all over the world to compete in a game
of FreeCol.

View File

@ -44,6 +44,7 @@ import net.sf.freecol.common.model.ModelMessage;
import net.sf.freecol.common.model.Player;
import net.sf.freecol.common.model.Unit;
import net.sf.freecol.common.option.BooleanOption;
import net.sf.freecol.common.option.IntegerOption;
import net.sf.freecol.common.option.ListOption;
import net.sf.freecol.common.option.ListOptionSelector;
import net.sf.freecol.common.option.Option;
@ -734,6 +735,41 @@ public class ClientOptions extends OptionGroup {
return (BooleanOption) getOption(message.getMessageType().getOptionName());
}
/**
* Perform backward compatibility fixups on new client options as
* they are introduced. Annotate with introduction version so we
* can clean these up as they become standard.
*/
public void fixClientOptions() {
// Introduced: 0.10.0, remove when 0.9.x is obsolete
addBooleanOption("model.option.guiShowDemands",
"clientOptions.messages", true);
// Introduced: 0.10.0, remove when 0.9.x is obsolete
addBooleanOption("model.option.guiShowGifts",
"clientOptions.messages", true);
// Introduced: 0.10.0, remove when 0.9.x is obsolete
addBooleanOption("model.option.guiShowGoodsMovement",
"clientOptions.messages", true);
// Introduced: 0.10.1, remove when 0.9.x is obsolete
addIntegerOption(COLONY_REPORT,
"clientOptions.messages", 0);
}
private void addBooleanOption(String id, String gr, boolean val) {
BooleanOption op = new BooleanOption(id);
op.setGroup(gr);
op.setValue(val);
add(op);
}
private void addIntegerOption(String id, String gr, int val) {
IntegerOption op = new IntegerOption(id);
op.setGroup(gr);
op.setValue(val);
add(op);
}
protected boolean isCorrectTagName(String tagName) {
return getXMLElementTagName().equals(tagName);
}

View File

@ -397,8 +397,10 @@ public final class ConnectController {
// Reload the client options saved with this game.
try {
freeColClient.getClientOptions().updateOptions(fis.getInputStream(fis.CLIENT_OPTIONS));
} catch(FileNotFoundException e) {
ClientOptions options = freeColClient.getClientOptions();
options.updateOptions(fis.getInputStream(fis.CLIENT_OPTIONS));
options.fixClientOptions();
} catch (FileNotFoundException e) {
// no client options, we don't care
}
final int sgo = freeColClient.getClientOptions().getInteger(ClientOptions.SHOW_SAVEGAME_SETTINGS);

View File

@ -150,7 +150,7 @@ public final class ReportColonyPanel extends ReportPanel
colonies = getSortedColonies();
try {
useCompact = getClientOptions().getInteger(ClientOptions.LABOUR_REPORT)
useCompact = getClientOptions().getInteger(ClientOptions.COLONY_REPORT)
== ClientOptions.COLONY_REPORT_COMPACT;
} catch (Exception e) {
useCompact = false;

View File

@ -241,6 +241,7 @@ public final class FreeColServer {
game = new ServerGame(specification);
game.setNationOptions(new NationOptions(specification, advantages));
fixGameOptions();
mapGenerator = new SimpleMapGenerator(random, specification);
try {
@ -822,12 +823,12 @@ public final class FreeColServer {
while (playerIterator.hasNext()) {
ServerPlayer player = (ServerPlayer) playerIterator.next();
if (player.isAI()) {
DummyConnection theConnection = new DummyConnection(
"Server-Server-" + player.getName(),
getInGameInputHandler());
DummyConnection aiConnection = new DummyConnection(
"Server-AI-" + player.getName(),
new AIInGameInputHandler(this, player, aiMain));
DummyConnection theConnection
= new DummyConnection("Server-Server-" + player.getName(),
getInGameInputHandler());
DummyConnection aiConnection
= new DummyConnection("Server-AI-" + player.getName(),
new AIInGameInputHandler(this, player, aiMain));
aiConnection.setOutgoingMessageHandler(theConnection);
theConnection.setOutgoingMessageHandler(aiConnection);
getServer().addDummyConnection(theConnection);
@ -837,51 +838,7 @@ public final class FreeColServer {
}
xs.close();
// Add a default value for options new to each version
// that are not part of the difficulty settings.
// Annotate with save format version where introduced
// so we can remove this backward compatibility code in future.
if (specification == null) {
specification = getSpecification();
}
if (!specification.hasOption("model.option.monarchSupport")) {
// Introduced: SAVEGAME_VERSION == 11
addIntegerOption("model.option.monarchSupport", 2);
}
if (!specification.hasOption("model.option.buildOnNativeLand")) {
// Introduced: SAVEGAME_VERSION == 11
addStringOption("model.option.buildOnNativeLand",
"model.option.buildOnNativeLand.never");
}
if (!specification.hasOption("model.option.guiShowDemands")) {
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.guiShowDemands", true);
}
if (!specification.hasOption("model.option.guiShowGifts")) {
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.guiShowGifts", true);
}
if (!specification.hasOption("model.option.guiShowGoodsMovement")) {
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.guiShowGoodsMovement", false);
}
if (!specification.hasOption("model.option.amphibiousMoves")) {
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.amphibiousMoves", false);
game.getSpecification()
.addModifier(new Modifier("model.modifier.amphibiousAttack",
Specification.AMPHIBIOUS_ATTACK_PENALTY_SOURCE,
-75.0f,
Modifier.Type.PERCENTAGE));
}
if (!specification.hasOption("model.option.settlementActionsContactChief")) {
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.settlementActionsContactChief", false);
}
if (!specification.hasOption("model.option.enhancedMissionaries")) {
// Introduced: SAVEGAME_VERSION == 12
addBooleanOption("model.option.enhancedMissionaries", false);
}
fixGameOptions();
// Now units are all present, set active unit.
setActiveUnit((active == null || game == null) ? null
@ -909,28 +866,65 @@ public final class FreeColServer {
}
}
private void addBooleanOption(String id, boolean defaultValue) {
private void fixGameOptions() {
// Add a default value for options new to each version
// that are not part of the difficulty settings.
// Annotate with save format version where introduced
// so we can remove this backward compatibility code in future.
Specification spec = game.getSpecification();
// Introduced: SAVEGAME_VERSION == 11
addIntegerOption("model.option.monarchSupport", "", 2);
// Introduced: SAVEGAME_VERSION == 11
addStringOption("model.option.buildOnNativeLand", "",
"model.option.buildOnNativeLand.never");
// Introduced: SAVEGAME_VERSION == 11
if (!spec.hasOption("model.option.amphibiousMoves")) {
addBooleanOption("model.option.amphibiousMoves",
"gameOptions.map", false);
spec.addModifier(new Modifier("model.modifier.amphibiousAttack",
Specification.AMPHIBIOUS_ATTACK_PENALTY_SOURCE,
-75.0f,
Modifier.Type.PERCENTAGE));
}
// Introduced: SAVEGAME_VERSION == 11
addBooleanOption("model.option.settlementActionsContactChief",
"gameOptions.map", false);
// Introduced: SAVEGAME_VERSION == 12
addBooleanOption("model.option.enhancedMissionaries",
"gameOptions.map", false);
// Introduced: SAVEGAME_VERSION == 12
addBooleanOption("model.option.continueFoundingFatherRecruitment",
"gameOptions.map", false);
}
private void addBooleanOption(String id, String gr, boolean defaultValue) {
Specification spec = game.getSpecification();
if (!spec.hasOption(id)) {
BooleanOption op = new BooleanOption(id);
op.setGroup(gr);
op.setValue(defaultValue);
spec.addAbstractOption(op);
spec.getOptionGroup(gr).add(op);
}
}
private void addIntegerOption(String id, int defaultValue) {
private void addIntegerOption(String id, String gr, int defaultValue) {
Specification spec = game.getSpecification();
if (!spec.hasOption(id)) {
IntegerOption op = new IntegerOption(id);
op.setGroup(gr);
op.setValue(defaultValue);
spec.addAbstractOption(op);
spec.getOptionGroup(gr).add(op);
}
}
private void addStringOption(String id, String defaultValue) {
private void addStringOption(String id, String gr, String defaultValue) {
Specification spec = game.getSpecification();
if (!spec.hasOption(id)) {
StringOption op = new StringOption(id);
op.setGroup(gr);
op.setValue(defaultValue);
spec.addAbstractOption(op);
}

View File

@ -656,9 +656,18 @@ public class ServerPlayer extends Player implements ServerModelObject {
* @return True if a new father should be chosen.
*/
public boolean canRecruitFoundingFather() {
return getPlayerType() == PlayerType.COLONIAL
&& canHaveFoundingFathers()
&& currentFather == null
switch (getPlayerType()) {
case COLONIAL:
break;
case REBEL: case INDEPENDENT:
if (!getSpecification()
.getBoolean("model.option.continueFoundingFatherRecruitment"))
return false;
break;
default:
return false;
}
return canHaveFoundingFathers() && currentFather == null
&& !getSettlements().isEmpty();
}