On 17.10.2012 12:32, Michael T. Pope wrote:

On Wed, 17 Oct 2012 06:43:42 AM Michael Vehrs wrote:

> One possible simplification of the OptionGroup class would be to remove

> its hash map. We rarely retrieve a value from an option group directly,

> and could easily stop doing that. Instead, we usually retrieve options

> from their top-level containers, namely the specification and the client

> options. The specification already contains an option map, and such a

> map could be easily added to the client options, too. Better yet, both

> the specification and the client options could be derived from a common

> "option container" class.

Sounds worth doing. It would certainly be cleaner.

Rolling back to the previous post...

> I think it would be better to check whether the difficulty levels

> contain further option groups, and to add the new options as a group, or

> singly, depending on the result of this check.

OK, the policy then is to try to follow the style of the loaded client options when adding fixup options.

Cheers,

Mike Pope


I tried starting a new game, loading an ancient game and loading a recent game. In all cases, the game started and I was able to display the difficulty level correctly. However, YMMV.

Regards

Michael

Index: src/net/sf/freecol/server/FreeColServer.java
===================================================================
--- src/net/sf/freecol/server/FreeColServer.java	(revision 10223)
+++ src/net/sf/freecol/server/FreeColServer.java	(working copy)
@@ -1237,7 +1237,11 @@
 
     private void addOptionGroup(String id, boolean difficulty) {
         Specification spec = game.getSpecification();
-        spec.fixOptionGroup(new OptionGroup(id, spec), difficulty);
+        try {
+            spec.getOptionGroup(id);
+        } catch(Exception e) {
+            spec.fixOptionGroup(new OptionGroup(id, spec), difficulty);
+        }
     }
 
     private void addBooleanOption(String id, String gr, boolean defaultValue,
@@ -1270,7 +1274,11 @@
             spec.addAbstractOption(option);
             if (difficulty) {
                 for (OptionGroup level : spec.getDifficultyLevels()) {
-                    level.getOptionGroup(option.getGroup()).add(option);
+                    if (level.hasOptionGroup()) {
+                        level.getOptionGroup(option.getGroup()).add(option);
+                    } else {
+                        level.add(option);
+                    }
                 }
             } else {
                 spec.getOptionGroup(option.getGroup()).add(option);
Index: src/net/sf/freecol/common/model/Specification.java
===================================================================
--- src/net/sf/freecol/common/model/Specification.java	(revision 10223)
+++ src/net/sf/freecol/common/model/Specification.java	(working copy)
@@ -691,7 +691,14 @@
             for (Option option : allOptionGroups.get("difficultyLevels")
                      .getOptions()) {
                 if (option instanceof OptionGroup) {
-                    ((OptionGroup)option).add(optionGroup);
+                    OptionGroup level = (OptionGroup) option;
+                    if (level.hasOptionGroup()) {
+                        level.add(optionGroup);
+                    } else {
+                        for (Option o : optionGroup.getOptions()) {
+                            level.add(o);
+                        }
+                    }
                 }
             }
         } else {
@@ -700,7 +707,7 @@
             }
         }
     }
-        
+
     /**
      * Adds an <code>OptionGroup</code> to the specification
      *
Index: src/net/sf/freecol/common/option/OptionGroup.java
===================================================================
--- src/net/sf/freecol/common/option/OptionGroup.java	(revision 10223)
+++ src/net/sf/freecol/common/option/OptionGroup.java	(working copy)
@@ -126,6 +126,15 @@
         return optionMap.get(id);
     }
 
+    public boolean hasOptionGroup() {
+        for (Option o : options) {
+            if (o instanceof OptionGroup) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Gets the value of an option as an option group.
      *
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Freecol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to