Hey,
So we have fixed one of the bugs we explicitly said we were going to fix, which 
was the hammers carrying-over.
We have added an option "model.option.clearHammersOnConstructionSwitch" (feel 
free to rename) in FreeColServer.fixGameOptions. When this is true, if you 
remove the first buildable in the buildQueue, it will pop up a dialog if you 
are sure, and if you are, it will remove the buildable and reset your hammers 
to 0. We're a bit unsure how to get this as an option in the specifications XML 
file.
You mentioned that this was a minor fix, but it actually took us a decent 
amount of time (I guess just to learn the code base wellenough). What we did 
was in BuildQueuePanel.java, in the BuildQueueMouseAdapter class's 
mousePressed, we check if we are aboutto remove the currentlyBuilding object. 
If so, we prompt with the dialog, and if they hit ok, we set the colony's 
hammers to 0. Interestinglywe have to do this again in ColonyWas, for the 
change to take effect once we exit the buildQueuePanel. Do you know why this 
is? But otherwiseit works perfectly.
-Saagar and Charlie                                       
Index: src/net/sf/freecol/server/FreeColServer.java
===================================================================
--- src/net/sf/freecol/server/FreeColServer.java        (revision 10243)
+++ src/net/sf/freecol/server/FreeColServer.java        (working copy)
@@ -1233,6 +1233,8 @@
             "gameOptions.colony", false, false);
         addIntegerOption(GameOptions.NATURAL_DISASTERS,
             "gameOptions.colony", 0, false);
+        addBooleanOption(GameOptions.CLEAR_HAMMERS_ON_CONSTRUCTION_SWITCH,
+                       "gameOptions.colony", true, false);
         // Introduced: SAVEGAME_VERSION == 12
         addOptionGroup("model.difficulty.cheat", true);
         addIntegerOption("model.option.liftBoycottCheat",
Index: src/net/sf/freecol/common/model/GameOptions.java
===================================================================
--- src/net/sf/freecol/common/model/GameOptions.java    (revision 10243)
+++ src/net/sf/freecol/common/model/GameOptions.java    (working copy)
@@ -133,4 +133,7 @@
     public static final String ENABLE_UPKEEP = "model.option.enableUpkeep";
 
     public static final String NATURAL_DISASTERS = 
"model.option.naturalDisasters";
+    
+    public static final String CLEAR_HAMMERS_ON_CONSTRUCTION_SWITCH = 
+                                               
"model.option.clearHammersOnConstructionSwitch";
 }
Index: src/net/sf/freecol/common/model/ColonyWas.java
===================================================================
--- src/net/sf/freecol/common/model/ColonyWas.java      (revision 10243)
+++ src/net/sf/freecol/common/model/ColonyWas.java      (working copy)
@@ -68,6 +68,32 @@
                 newProductionBonus);
         }
         List<BuildableType> newBuildQueue = colony.getBuildQueue();
+        /*
+         * If we removed the first thing in our queue, then we should reset to 
+         * 0 hammers. But only if the option is set. 
+         * 
+         * Mysteriously, we have to do this twice, once here, and once 
+         * in BuildQueuePanel. 
+         * 
+         * If we don't do it here, than the changes to hammers won't be saved 
+         * after editing the build queue. If we don't do it in BuildQueuePanel,
+         * then the changes in hammers won't be displayed until after you exit 
+         * the buildqueue window. 
+         */
+        if (colony.getGame().getSpecification().getBoolean(
+                       "model.option.clearHammersOnConstructionSwitch")) {
+               if (newBuildQueue.size() == 0 || buildQueue.size() == 0 || 
+                       !newBuildQueue.get(0).equals(buildQueue.get(0))) {
+                       for (Goods good : colony.getGoods()) {
+                               if 
(good.getNameKey().equals("model.goods.hammers.name")) {
+                                       //is there a way to not hardcode this ^ 
?
+                                       colony.removeGoods(good.getType(), 
good.getAmount());
+                               }
+                               }
+               }
+        }
+        
+        
         if (!newBuildQueue.equals(buildQueue)) {
             String pc = ColonyChangeEvent.BUILD_QUEUE_CHANGE.toString();
             colony.firePropertyChange(pc, buildQueue, newBuildQueue);
Index: src/net/sf/freecol/client/gui/panel/BuildQueuePanel.java
===================================================================
--- src/net/sf/freecol/client/gui/panel/BuildQueuePanel.java    (revision 10243)
+++ src/net/sf/freecol/client/gui/panel/BuildQueuePanel.java    (working copy)
@@ -73,11 +73,13 @@
 import net.sf.freecol.common.model.Colony;
 import net.sf.freecol.common.model.FeatureContainer;
 import net.sf.freecol.common.model.FreeColGameObjectType;
+import net.sf.freecol.common.model.Goods;
 import net.sf.freecol.common.model.Limit;
 import net.sf.freecol.common.model.StringTemplate;
 import net.sf.freecol.common.model.UnitType;
 import net.sf.freecol.common.resources.ResourceManager;
 import net.sf.freecol.common.util.Utils;
+import net.sf.freecol.server.FreeColServer;
 
 
 public class BuildQueuePanel extends FreeColPanel implements ActionListener, 
ItemListener {
@@ -107,6 +109,12 @@
     private Set<BuildableType> unbuildableTypes = new HashSet<BuildableType>();
 
     /**
+     * Only used to show a warning box when we might clear hammers when 
+     * abandoning construction of the first thing in the build queue. 
+     */
+    private GUI gui;
+    
+    /**
      * A list of unit types that can be build. Most unit types are
      * human and can never be built.
      */
@@ -116,6 +124,7 @@
     public BuildQueuePanel(FreeColClient freeColClient, GUI gui, Colony 
colony) {
 
         super(freeColClient, gui, new MigLayout("wrap 3", "[260:][390:, 
fill][260:]", "[][][300:400:][]"));
+        this.gui = gui;
         this.colony = colony;
         this.unitCount = colony.getUnitCount();
         featureContainer = new FeatureContainer();
@@ -1024,11 +1033,32 @@
                         if (source.getSelectedIndex() == -1) {
                             
source.setSelectedIndex(source.locationToIndex(e.getPoint()));
                         }
-                        for (Object type : source.getSelectedValues()) {
+                        for (int i : source.getSelectedIndices()) {
+                               Object type = source.getModel().getElementAt(i);
                             if (add) {
                                 model.addElement(type);
                             } else {
-                                model.removeElement(type);
+                               
+                               if (i == 0 && 
getGame().getSpecification().getBoolean(
+                                               
"model.option.clearHammersOnConstructionSwitch")) {
+                                       boolean confirm = 
gui.getCanvas().showConfirmDialog(
+                                                                         
"Warning: By removing this from your build" +
+                                                                         
"queue you will forfeit all hammers that " +
+                                                                         "went 
towards building it.", 
+                                                                         
"REMOVE", "CANCEL");
+                                       if (confirm) {
+                                               model.removeElementAt(i);
+                                               for (Goods good : 
colony.getGoods()) {
+                                               if 
(good.getNameKey().equals("model.goods.hammers.name")) {
+                                                       //is there a way to not 
hardcode this ^ ?
+                                                       
colony.removeGoods(good.getType(), good.getAmount());
+                                               }
+                                               }
+                                       }
+                               }else {
+                                       model.removeElementAt(i);
+                               }
+                                
                             }
                         }
                         updateAllLists();
------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Freecol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to