From: Stefan F. <ste...@us...> - 2012-06-30 04:57:13
|
junit/rails/game/state/ChangeStackTest.java | 117 +++++++++ src/rails/algorithms/RevenueManager.java | 26 -- src/rails/common/GuiHints.java | 17 - src/rails/common/parser/ComponentManager.java | 6 src/rails/common/parser/GameFileParser.java | 4 src/rails/game/Bank.java | 32 -- src/rails/game/BankPortfolio.java | 21 - src/rails/game/BaseToken.java | 21 - src/rails/game/BonusToken.java | 19 - src/rails/game/Company.java | 15 - src/rails/game/CompanyManager.java | 10 src/rails/game/CompanyType.java | 17 - src/rails/game/EndOfGameRound.java | 12 - src/rails/game/Game.java | 6 src/rails/game/GameManager.java | 70 ++--- src/rails/game/MapHex.java | 30 +- src/rails/game/MapManager.java | 11 src/rails/game/OperatingRound.java | 39 +-- src/rails/game/PhaseManager.java | 18 - src/rails/game/Player.java | 122 ++++------ src/rails/game/PlayerManager.java | 13 - src/rails/game/PrivateCompany.java | 15 - src/rails/game/PublicCertificate.java | 9 src/rails/game/PublicCompany.java | 154 +++++-------- src/rails/game/Round.java | 23 - src/rails/game/ShareSellingRound.java | 35 -- src/rails/game/StartItem.java | 33 +- src/rails/game/StartPacket.java | 23 + src/rails/game/StartRound.java | 22 - src/rails/game/StartRound_1830.java | 14 - src/rails/game/StartRound_1835.java | 27 -- src/rails/game/StockMarket.java | 14 - src/rails/game/StockRound.java | 39 +-- src/rails/game/StockSpace.java | 30 -- src/rails/game/Stop.java | 26 -- src/rails/game/SwitchableUIRound.java | 6 src/rails/game/Tile.java | 10 src/rails/game/TileManager.java | 15 - src/rails/game/Token.java | 36 --- src/rails/game/Train.java | 17 - src/rails/game/TrainCertificateType.java | 24 -- src/rails/game/TrainManager.java | 28 +- src/rails/game/TreasuryShareRound.java | 33 -- src/rails/game/correct/CashCorrectionManager.java | 17 - src/rails/game/correct/CorrectionManager.java | 23 - src/rails/game/correct/CorrectionManagerI.java | 3 src/rails/game/correct/CorrectionType.java | 4 src/rails/game/correct/MapCorrectionManager.java | 14 - src/rails/game/model/BaseTokensModel.java | 27 -- src/rails/game/model/BonusModel.java | 11 src/rails/game/model/CalculatedMoneyModel.java | 22 - src/rails/game/model/CashMoneyModel.java | 25 -- src/rails/game/model/CertificateCountModel.java | 28 -- src/rails/game/model/CertificatesModel.java | 31 +- src/rails/game/model/MoneyModel.java | 10 src/rails/game/model/PortfolioModel.java | 46 +-- src/rails/game/model/PresidentModel.java | 22 - src/rails/game/model/PriceModel.java | 29 -- src/rails/game/model/PrivatesModel.java | 24 -- src/rails/game/model/TrainsModel.java | 24 -- src/rails/game/round/Activity.java | 4 src/rails/game/round/RoundContext.java | 9 src/rails/game/special/ExchangeForShare.java | 13 - src/rails/game/special/LocatedBonus.java | 13 - src/rails/game/special/SellBonusToken.java | 20 - src/rails/game/special/SpecialProperty.java | 15 + src/rails/game/special/SpecialRight.java | 11 src/rails/game/special/SpecialTileLay.java | 13 - src/rails/game/special/SpecialTokenLay.java | 11 src/rails/game/special/SpecialTrainBuy.java | 14 - src/rails/game/specific/_1825/OperatingRound_1825.java | 10 src/rails/game/specific/_1825/PublicCompany_1825.java | 12 - src/rails/game/specific/_1825/StartRound_1825.java | 13 - src/rails/game/specific/_1825/StockRound_1825.java | 17 - src/rails/game/specific/_1835/OperatingRound_1835.java | 24 -- src/rails/game/specific/_1835/PrussianFormationRound.java | 11 src/rails/game/specific/_1835/StockRound_1835.java | 16 - src/rails/game/specific/_1851/StartRound_1851.java | 19 - src/rails/game/specific/_1856/CGRFormationRound.java | 23 - src/rails/game/specific/_1856/OperatingRound_1856.java | 17 - src/rails/game/specific/_1856/PublicCompany_1856.java | 17 - src/rails/game/specific/_1856/PublicCompany_CGR.java | 16 - src/rails/game/specific/_1856/ShareSellingRound_1856.java | 21 - src/rails/game/specific/_1856/StockRound_1856.java | 18 - src/rails/game/specific/_1880/Investor_1880.java | 18 - src/rails/game/specific/_1880/OperatingRound_1880.java | 23 - src/rails/game/specific/_1880/PublicCompany_1880.java | 23 - src/rails/game/specific/_1880/StartRound_1880.java | 43 --- src/rails/game/specific/_1880/StockRound_1880.java | 16 - src/rails/game/specific/_1889/OperatingRound_1889.java | 26 -- src/rails/game/specific/_18AL/NameTrains.java | 10 src/rails/game/specific/_18AL/NameableTrain.java | 14 - src/rails/game/specific/_18AL/NamedTrainToken.java | 16 - src/rails/game/specific/_18AL/OperatingRound_18AL.java | 10 src/rails/game/specific/_18EU/FinalMinorExchangeRound.java | 11 src/rails/game/specific/_18EU/GameManager_18EU.java | 9 src/rails/game/specific/_18EU/OperatingRound_18EU.java | 17 - src/rails/game/specific/_18EU/StartRound_18EU.java | 34 -- src/rails/game/specific/_18EU/StockRound_18EU.java | 28 -- src/rails/game/specific/_18GA/OperatingRound_18GA.java | 10 src/rails/game/specific/_18TN/OperatingRound_18TN.java | 15 - src/rails/game/specific/_18TN/PublicCompany_18TN.java | 12 - src/rails/game/state/AbstractItem.java | 38 --- src/rails/game/state/ArrayListChange.java | 12 - src/rails/game/state/ArrayListMultimapState.java | 10 src/rails/game/state/ArrayListState.java | 18 - src/rails/game/state/BooleanChange.java | 11 src/rails/game/state/BooleanState.java | 11 src/rails/game/state/Change.java | 16 - src/rails/game/state/ChangeStack.java | 27 +- src/rails/game/state/Context.java | 126 ---------- src/rails/game/state/GenericState.java | 13 - src/rails/game/state/GenericStateChange.java | 14 - src/rails/game/state/HashMapChange.java | 14 - src/rails/game/state/HashMapState.java | 21 - src/rails/game/state/HashMultimapState.java | 10 src/rails/game/state/HashSetChange.java | 13 - src/rails/game/state/HashSetState.java | 18 - src/rails/game/state/IntegerChange.java | 13 - src/rails/game/state/IntegerState.java | 13 - src/rails/game/state/Item.java | 20 - src/rails/game/state/Manager.java | 110 +++++++++ src/rails/game/state/Model.java | 4 src/rails/game/state/MultimapChange.java | 13 - src/rails/game/state/MultimapState.java | 4 src/rails/game/state/Observable.java | 8 src/rails/game/state/OwnableItem.java | 5 src/rails/game/state/OwnableManager.java | 5 src/rails/game/state/Portfolio.java | 18 - src/rails/game/state/PortfolioChange.java | 8 src/rails/game/state/PortfolioList.java | 8 src/rails/game/state/PortfolioManager.java | 15 - src/rails/game/state/PortfolioMap.java | 8 src/rails/game/state/Root.java | 101 ++++---- src/rails/game/state/State.java | 16 - src/rails/game/state/StateManager.java | 45 +-- src/rails/game/state/StringChange.java | 9 src/rails/game/state/StringState.java | 13 - src/rails/game/state/Wallet.java | 8 src/rails/game/state/WalletChange.java | 13 - src/rails/game/state/WalletManager.java | 11 141 files changed, 1436 insertions(+), 1715 deletions(-) New commits: commit 5ac0e9a3f06f1e9cce6ba3ecabd24f401082447b Author: Stefan Frey <ste...@we...> Date: Sat Jun 30 06:56:17 2012 +0200 Modified approach to Root, Manager and Context objects diff --git a/src/rails/common/parser/ComponentManager.java b/src/rails/common/parser/ComponentManager.java index daa7f30..3e0d57f 100644 --- a/src/rails/common/parser/ComponentManager.java +++ b/src/rails/common/parser/ComponentManager.java @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory; import rails.common.LocalText; import rails.common.parser.XMLTags; -import rails.game.state.Context; +import rails.game.state.Manager; /** * ComponentManage - an implementation of ComponentManagerI, which handles the @@ -28,7 +28,7 @@ public class ComponentManager { private Map<String, ConfigurableComponent> mComponentMap = new HashMap<String, ConfigurableComponent>(); - public ComponentManager(Context context, String gameName, Tag tag, Map<String, String> gameOptions) + public ComponentManager(Manager context, String gameName, Tag tag, Map<String, String> gameOptions) throws ConfigurationException { this.gameName = gameName; @@ -41,7 +41,7 @@ public class ComponentManager { } } - private void configureComponent(Context context, Tag componentTag) + private void configureComponent(Manager context, Tag componentTag) throws ConfigurationException { // Extract the attributes of the Component diff --git a/src/rails/common/parser/GameFileParser.java b/src/rails/common/parser/GameFileParser.java index 528892e..f4ebe84 100644 --- a/src/rails/common/parser/GameFileParser.java +++ b/src/rails/common/parser/GameFileParser.java @@ -15,7 +15,7 @@ import rails.game.PlayerManager; import rails.game.StockMarket; import rails.game.TileManager; import rails.game.TrainManager; -import rails.game.state.Context; +import rails.game.state.Manager; public class GameFileParser extends XMLParser { private static String GAME_XML_FILE = "Game.xml"; @@ -34,7 +34,7 @@ public class GameFileParser extends XMLParser { private RevenueManager revenueManager; private Bank bank; - public GameFileParser(Context context, String name, Map<String, String> gameOptions) { + public GameFileParser(Manager context, String name, Map<String, String> gameOptions) { directories.add("data/" + name); diff --git a/src/rails/game/Game.java b/src/rails/game/Game.java index 3279b26..b71533c 100644 --- a/src/rails/game/Game.java +++ b/src/rails/game/Game.java @@ -11,9 +11,7 @@ import rails.common.DisplayBuffer; import rails.common.LocalText; import rails.common.parser.*; import rails.game.action.PossibleAction; -import rails.game.state.Context; import rails.game.state.Root; -import rails.game.state.StateManager; import rails.util.GameFileIO; public class Game { @@ -79,10 +77,9 @@ public class Game { public boolean setup() { // first define root GameContext to be able to define states - StateManager stateManager = StateManager.create(parent, id) - Context context = Root.create(parent); + Root root = Root.create("states"); - GameFileParser gfp = new GameFileParser(context, name, gameOptions); + GameFileParser gfp = new GameFileParser(root, name, gameOptions); playerManager = gfp.getPlayerManager(); companyManager = gfp.getCompanyManager(); trainManager = gfp.getTrainManager(); diff --git a/src/rails/game/round/Activity.java b/src/rails/game/round/Activity.java index bea0143..812b7ca 100644 --- a/src/rails/game/round/Activity.java +++ b/src/rails/game/round/Activity.java @@ -3,7 +3,7 @@ package rails.game.round; import java.util.List; import rails.game.action.PossibleAction; -import rails.game.state.Context; +import rails.game.state.Manager; interface Activity { @@ -11,7 +11,7 @@ interface Activity { * creation based on a specific context * @param context */ - public void create(Context context); + public void create(Manager context); /** * @return true if activity is active diff --git a/src/rails/game/state/AbstractItem.java b/src/rails/game/state/AbstractItem.java index 7a8b0ac..e76ec25 100644 --- a/src/rails/game/state/AbstractItem.java +++ b/src/rails/game/state/AbstractItem.java @@ -32,8 +32,8 @@ public abstract class AbstractItem implements Item { } public Context getContext() { - if (parent instanceof Context) { - return (Context)parent; + if (parent instanceof Manager) { + return (Manager)parent; } else { // recursive definition return parent.getContext(); @@ -41,7 +41,7 @@ public abstract class AbstractItem implements Item { } public String getURI() { - if (parent instanceof Context) { + if (parent instanceof Manager) { return id; } else { // recursive definition diff --git a/src/rails/game/state/Context.java b/src/rails/game/state/Context.java index b4d5ae4..487e1e3 100644 --- a/src/rails/game/state/Context.java +++ b/src/rails/game/state/Context.java @@ -1,96 +1,15 @@ package rails.game.state; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - /** - * Contexts allow location of other items + * A context describe a service that allows to locate items */ -public class Context implements Item { - // standard item fields - protected final String id; - protected final Item parent; - // context reference to the root - protected final Root root; +public interface Context extends Item { - // storage of items - protected final HashMapState<String, Item> items = HashMapState.create(this, "items"); + public Item localize(String uri); - protected Context(Item parent, String id) { - // check arguments - checkNotNull(parent, "Parent cannot be null"); - checkNotNull(id, "Id cannot be null"); - checkArgument(id != Root.ID, "Id cannot equal " + Root.ID); - - // standard fields - this.parent = parent; - this.id = id; - - // find root and add context there - root = parent.getContext().getRoot(); - root.addItemToRoot(this); - } - - public static Context create(Item parent, String id) { - return new Context(parent, id); - } - - public String getId() { - return id; - } + public void addItem(Item item); - public Item getParent() { - return parent; - } + public void removeItem(Item item); - public Context getContext() { - return this; - } + public Root getRoot(); - public String getURI() { - if (parent instanceof Context) { - return id; - } else { - // recursive definition - return parent.getURI() + Item.SEP + id; - } - } - - public String getFullURI() { - // recursive definition - return parent.getFullURI() + Item.SEP + id; - } - - // Context methods - public Item localize(String uri) { - // either item can be found in the map - if (items.containsKey(uri)) { - return items.get(uri); - } else { - // otherwise search in root - return root.localize(uri); - } - } - - void addItem(AbstractItem item) { - // check if this context is the containing one - checkArgument(item.getContext() == this, "Context is not the container of the item to add"); - // check if it already exists - checkArgument(items.containsKey(item.getURI()), "Context already contains item with identical URI"); - - // all preconditions ok => add item - items.put(item.getURI(), item); - - // add item to root - root.addItemToRoot(item); - } - - public Root getRoot() { - return root; - } - - @Override - public String toString() { - return parent.toString(); - } } diff --git a/src/rails/game/state/Item.java b/src/rails/game/state/Item.java index f076822..be16c84 100644 --- a/src/rails/game/state/Item.java +++ b/src/rails/game/state/Item.java @@ -14,7 +14,7 @@ package rails.game.state; */ public interface Item { - static final char SEP = '.'; + public static final char SEP = '/'; String getId(); diff --git a/src/rails/game/state/Manager.java b/src/rails/game/state/Manager.java new file mode 100644 index 0000000..11d5a3b --- /dev/null +++ b/src/rails/game/state/Manager.java @@ -0,0 +1,110 @@ +package rails.game.state; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * A Manager is an abstract implementation of a Context + */ +public abstract class Manager implements Context { + + // standard item fields + private final String id; + private final Item parent; + + protected final Root root; + + // storage of items + protected final HashMapState<String, Item> items = HashMapState.create(this, "items"); + + protected Manager(Item parent, String id) { + checkNotNull(id, "Id cannot be null"); + this.id = id; + + if (this instanceof Root) { + this.parent = null; + this.root = null; + return; + } + + // check arguments, parent can only be null for Root + checkNotNull(parent, "Parent cannot be null"); + this.parent = parent; + + // find root and add context there + root = parent.getContext().getRoot(); + root.addItem(this); + } + + public String getId() { + return id; + } + + public Item getParent() { + return parent; + } + + public Context getContext() { + return this; + } + + public String getURI() { + if (parent instanceof Manager) { + return id; + } else { + // recursive definition + return parent.getURI() + Item.SEP + id; + } + } + + public String getFullURI() { + // recursive definition + return parent.getFullURI() + Item.SEP + id; + } + + // Context methods + public Item localize(String uri) { + // either item can be found in the map + if (items.containsKey(uri)) { + return items.get(uri); + } else { + // otherwise search in root + return root.localize(uri); + } + } + + public void addItem(Item item) { + // check if this context is the containing one + checkArgument(item.getContext() == this, "Context is not the container of the item to add"); + // check if it already exists + checkArgument(items.containsKey(item.getURI()), "Context already contains item with identical URI"); + + // all preconditions ok => add item + items.put(item.getURI(), item); + + // add item to root + root.addItem(item); + } + + public void removeItem(Item item) { + // check if this context is the containing one + checkArgument(item.getContext() == this, "Context is not the container of the item to add"); + // check if it is stored + checkArgument(!items.containsKey(item.getURI()), "Context does not contain item with that URI"); + + // all preconditions ok => remove item + items.remove(item.getURI()); + + // remove item from root + root.removeItem(item); + } + + public Root getRoot() { + return root; + } + + @Override + public String toString() { + return parent.toString(); + } +} diff --git a/src/rails/game/state/Root.java b/src/rails/game/state/Root.java index d7fc154..5f5a47d 100644 --- a/src/rails/game/state/Root.java +++ b/src/rails/game/state/Root.java @@ -1,41 +1,64 @@ package rails.game.state; import static com.google.common.base.Preconditions.checkArgument; - /** - * Root is a context that serves as the top node - - * It also contains the StateManager if the object tree - * should be able to contain states + * Root is the top node of the context/item hierachy */ -public final class Root extends Context { +public final class Root extends Manager { + + public final static String ID = "/"; + + private StateManager stateManager; + + private Root() { + super(null, ID); + } /** - * The reserved id for a root + * @param stateManagerId for the embedded StateManager + * @return a Root object with initialized StateManager embedded */ - public static final String ID = "root"; - - private Root(StateManager parent) { - super(parent, ID); + public static Root create(String stateManagerId) { + Root root = new Root(); + StateManager stateManager = StateManager.create(root, stateManagerId); + root.addStateManager(stateManager); + return root; } - + + private void addStateManager(StateManager stateManager) { + this.stateManager = stateManager; + } + + public StateManager getStateManager() { + return stateManager; + } + /** - * @param the game used for this hierarchy + * @throws UnsupportedOperationsException + * Not supported for Root */ - public static Root create(Game parent) { - return new Root(parent); + @Override + public Item getParent() { + throw new UnsupportedOperationException(); } + /** + * @return this + */ @Override - public StateManager getParent() { - return null; + public Context getContext() { + return this; } + /** + * @return this + */ @Override - public Context getContext() { - return null; + public Root getRoot() { + return this; } + @Override public String getURI() { return ID; @@ -52,16 +75,25 @@ public final class Root extends Context { return items.get(uri); } - // Root methods - void addItemToRoot(Item item) { + @Override + public void addItem(Item item) { // check if it already exists checkArgument(items.containsKey(item.getFullURI()), "Root already contains item with identical fullURI"); - // all preconditions ok + // all preconditions ok => add items.put(item.getFullURI(), item); } @Override + public void removeItem(Item item) { + // check if it already exists + checkArgument(!items.containsKey(item.getFullURI()), "Root does not contain item with that fullURI"); + + // all preconditions ok => remove + items.remove(item.getFullURI()); + } + + @Override public String toString() { return ID; } diff --git a/src/rails/game/state/StateManager.java b/src/rails/game/state/StateManager.java index cd7391c..4526712 100644 --- a/src/rails/game/state/StateManager.java +++ b/src/rails/game/state/StateManager.java @@ -13,7 +13,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -public final class StateManager extends AbstractItem { +public final class StateManager extends Manager { protected static Logger log = LoggerFactory.getLogger(StateManager.class.getPackage().getName()); commit 16dee2d210cab07db6e73a10e3a5f70eeec1e39b Author: Stefan Frey <ste...@we...> Date: Fri Jun 22 12:38:31 2012 +0200 refactored Item interface again diff --git a/junit/rails/game/state/ChangeStackTest.java b/junit/rails/game/state/ChangeStackTest.java new file mode 100644 index 0000000..04dbb87 --- /dev/null +++ b/junit/rails/game/state/ChangeStackTest.java @@ -0,0 +1,117 @@ +package rails.game.state; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.mockito.Mock; + +public class ChangeStackTest { + + @Mock + private StateManager sm; + + @Test + public void testCreate() { + ChangeStack stack = ChangeStack.create(sm); + assertNotNull(stack); + } + + @Test + public void testEnable() { + ChangeStack stack = ChangeStack.create(sm); + assertFalse(stack.isEnabled()); + stack.enable(); + assertTrue(stack.isEnabled()); + } + + @Test + public void testIsEnabled() { + fail("Not yet implemented"); + } + + @Test + public void testGetAvailableChangeSet() { + fail("Not yet implemented"); + } + + @Test + public void testGetAvailableChangeSetBoolean() { + fail("Not yet implemented"); + } + + @Test + public void testStart() { + fail("Not yet implemented"); + } + + @Test + public void testFinish() { + fail("Not yet implemented"); + } + + @Test + public void testCancel() { + fail("Not yet implemented"); + } + + @Test + public void testAddChange() { + fail("Not yet implemented"); + } + + @Test + public void testIsUndoableByPlayer() { + fail("Not yet implemented"); + } + + @Test + public void testIsUndoableByManager() { + fail("Not yet implemented"); + } + + @Test + public void testIsOpen() { + fail("Not yet implemented"); + } + + @Test + public void testGetIndex() { + fail("Not yet implemented"); + } + + @Test + public void testSize() { + fail("Not yet implemented"); + } + + @Test + public void testGetCurrentIndex() { + fail("Not yet implemented"); + } + + @Test + public void testGotoIndex() { + fail("Not yet implemented"); + } + + @Test + public void testIsRedoable() { + fail("Not yet implemented"); + } + + @Test + public void testRedoMoveSet() { + fail("Not yet implemented"); + } + + @Test + public void testUndo() { + fail("Not yet implemented"); + } + + @Test + public void testAdd() { + fail("Not yet implemented"); + } + +} diff --git a/src/rails/algorithms/RevenueManager.java b/src/rails/algorithms/RevenueManager.java index 0c14e5d..6c70b91 100644 --- a/src/rails/algorithms/RevenueManager.java +++ b/src/rails/algorithms/RevenueManager.java @@ -22,11 +22,7 @@ import rails.game.state.Item; * which are permanent. * The conversion of Rails elements is in the responsibility of the RevenueAdapter. * For each GameManager instance only one RevenueManager is created. - * - * @author freystef - * */ - public final class RevenueManager extends AbstractItem implements ConfigurableComponent { protected static Logger log = @@ -34,15 +30,21 @@ public final class RevenueManager extends AbstractItem implements ConfigurableCo private final HashSet<ConfigurableComponent> configurableModifiers = new HashSet<ConfigurableComponent>(); - private final ArrayListState<NetworkGraphModifier> graphModifiers = ArrayListState.create(); - private final ArrayListState<RevenueStaticModifier> staticModifiers = ArrayListState.create(); - private final ArrayListState<RevenueDynamicModifier> dynamicModifiers = ArrayListState.create(); + private final ArrayListState<NetworkGraphModifier> graphModifiers = ArrayListState.create(this, "graphModifiers"); + private final ArrayListState<RevenueStaticModifier> staticModifiers = ArrayListState.create(this, "staticModifiers"); + private final ArrayListState<RevenueDynamicModifier> dynamicModifiers = ArrayListState.create(this, "dynamicModifiers"); private final ArrayList<RevenueStaticModifier> activeStaticModifiers = new ArrayList<RevenueStaticModifier>(); private final ArrayList<RevenueDynamicModifier> activeDynamicModifiers = new ArrayList<RevenueDynamicModifier>(); private RevenueDynamicModifier activeCalculator; - public RevenueManager() {} + private RevenueManager(Item parent, String id) { + super(parent, id); + } + + public static RevenueManager create(Item parent, String id){ + return new RevenueManager(parent, id); + } public void configureFromXML(Tag tag) throws ConfigurationException { @@ -94,14 +96,6 @@ public final class RevenueManager extends AbstractItem implements ConfigurableCo } - @Override - public void init(Item parent, String id) { - super.init(parent, id); - graphModifiers.init(this, "NetworkGraphModifiers"); - staticModifiers.init(this, "RevenueStaticModifiers"); - dynamicModifiers.init(this, "RevenueDynamicModifiers"); - } - public void finishConfiguration(GameManager parent) throws ConfigurationException { for (ConfigurableComponent modifier:configurableModifiers) { diff --git a/src/rails/common/GuiHints.java b/src/rails/common/GuiHints.java index a40d4ac..ddd3d1b 100644 --- a/src/rails/common/GuiHints.java +++ b/src/rails/common/GuiHints.java @@ -17,24 +17,25 @@ import rails.game.state.Item; * @author VosE * */ -public class GuiHints extends AbstractItem implements Serializable{ +public final class GuiHints extends AbstractItem implements Serializable{ public static final long serialVersionUID = 1L; /** What round type is currently active in the engine? */ - private GenericState<Class<? extends Round>> currentRoundType = GenericState.create(); + private GenericState<Class<? extends Round>> currentRoundType = GenericState.create(this, "currentRoundType"); /** Which windows should be visible? */ private List<VisibilityHint> visibilityHints; /** Which window type is active and should be on top? */ - private GenericState<GuiDef.Panel> activePanel = GenericState.create(); + private GenericState<GuiDef.Panel> activePanel = GenericState.create(this, "activePanel"); - @Override - public void init(Item parent, String id){ - super.init(parent, id); - currentRoundType.init(this, "CurrentRoundType"); - activePanel.init(this, "ActivePanel"); + private GuiHints(Item parent, String id) { + super(parent, id); + } + + public static GuiHints create(Item parent, String id){ + return new GuiHints(parent, id); } public Class<? extends Round> getCurrentRoundType() { diff --git a/src/rails/game/Bank.java b/src/rails/game/Bank.java index 392c62c..66b9d09 100644 --- a/src/rails/game/Bank.java +++ b/src/rails/game/Bank.java @@ -33,19 +33,19 @@ public class Bank extends AbstractItem implements CashOwner, ConfigurableCompone private static final String DEFAULT_MONEY_FORMAT = "$@"; /** The Bank's amount of cash */ - private final CashMoneyModel cash = CashMoneyModel.create(); + private final CashMoneyModel cash = CashMoneyModel.create(this, "cash", false); /** The IPO */ - private final BankPortfolio ipo = BankPortfolio.create(); + private final BankPortfolio ipo = BankPortfolio.create(this, IPO_NAME); /** The Bank Pool */ - private final BankPortfolio pool = BankPortfolio.create(); + private final BankPortfolio pool = BankPortfolio.create(this, POOL_NAME); /** Collection of items that will (may) become available in the future */ - private final BankPortfolio unavailable = BankPortfolio.create(); + private final BankPortfolio unavailable = BankPortfolio.create(this, UNAVAILABLE_NAME); /** Collection of items that have been discarded (but are kept to allow Undo) */ - private final BankPortfolio scrapHeap = BankPortfolio.create(); + private final BankPortfolio scrapHeap = BankPortfolio.create(this, SCRAPHEAP_NAME); /** Is the bank broken */ - private final BooleanState broken = BooleanState.create(); + private final BooleanState broken = BooleanState.create(this, "broken"); /** * The money format template. '@' is replaced by the numeric amount, the @@ -56,8 +56,8 @@ public class Bank extends AbstractItem implements CashOwner, ConfigurableCompone protected static Logger log = LoggerFactory.getLogger(Bank.class.getPackage().getName()); - public Bank() { - super(); + protected Bank(Item parent, String id) { + super(parent, id); instance = this; String configFormat = Config.get("money_format"); @@ -65,19 +65,9 @@ public class Bank extends AbstractItem implements CashOwner, ConfigurableCompone moneyFormat = configFormat; } } - - @Override - public void init(Item parent, String id) { - super.init(parent, id); - - cash.init(this, "cash"); - broken.init(this, "broken"); - - // Init the IPO and the Bank Pool. - ipo.init(this, IPO_NAME); - pool.init(this, POOL_NAME); - unavailable.init(this, UNAVAILABLE_NAME); - scrapHeap.init(this, SCRAPHEAP_NAME); + + public static Bank create(Item parent, String id) { + return new Bank(parent, id); } /** diff --git a/src/rails/game/BankPortfolio.java b/src/rails/game/BankPortfolio.java index ce62f23..fd92cba 100644 --- a/src/rails/game/BankPortfolio.java +++ b/src/rails/game/BankPortfolio.java @@ -10,29 +10,28 @@ import rails.game.state.Item; */ public class BankPortfolio extends AbstractItem implements PortfolioOwner { - - private final PortfolioModel portfolio = PortfolioModel.create(); - private BankPortfolio() {} + private final PortfolioModel portfolio = PortfolioModel.create(this); - public static BankPortfolio create() { - BankPortfolio bp = new BankPortfolio(); - return bp; + protected BankPortfolio(Item parent, String id) { + super (parent, id); } /** - * parent is restricted to Bank + * @param parent restricted to bank */ + public static BankPortfolio create(Bank parent, String id) { + return new BankPortfolio(parent, id); + } + @Override - public void init(Item parent, String id) { - super.checkedInit(parent, id, Bank.class); - portfolio.init(this, "portfolio"); + public Bank getParent() { + return (Bank)super.getParent(); } // PortfolioOwner methods public PortfolioModel getPortfolioModel() { return portfolio; } - } diff --git a/src/rails/game/BaseToken.java b/src/rails/game/BaseToken.java index 253bad1..d2ccde2 100644 --- a/src/rails/game/BaseToken.java +++ b/src/rails/game/BaseToken.java @@ -1,7 +1,5 @@ package rails.game; -import rails.game.state.Item; - /** * A BaseToken object represents a token that a operating public company can * place on the map to act as a rail building and train running starting point. @@ -9,25 +7,20 @@ import rails.game.state.Item; * rails.game program as it most closely the function of such a token: to act as * a base from which a company can operate. Other names used in various games * and discussions are "railhead", "station", "garrison", or just "token". - * - * @author Erik Vos */ + +// FIXME: Check if PublicCompany is the parent of a token public final class BaseToken extends Token { - private BaseToken() {}; + private BaseToken(PublicCompany parent, String id) { + super(parent, id); + } public static BaseToken create(PublicCompany company) { - BaseToken token = new BaseToken(); - token.init(company); - return token; + String uniqueId = Token.createUniqueId(); + return new BaseToken(company, uniqueId); } - - @Override - public void init(Item parent) { - super.checkedInit(parent, null, PublicCompany.class); - } - @Override public PublicCompany getParent() { return (PublicCompany)super.getParent(); diff --git a/src/rails/game/BonusToken.java b/src/rails/game/BonusToken.java index acfcfe7..ce92c8e 100644 --- a/src/rails/game/BonusToken.java +++ b/src/rails/game/BonusToken.java @@ -3,7 +3,6 @@ package rails.game; import rails.common.parser.ConfigurableComponent; import rails.common.parser.ConfigurationException; import rails.common.parser.Tag; -import rails.game.state.Item; import rails.util.Util; /** @@ -11,10 +10,9 @@ import rails.util.Util; * place on the map to gain extra revenue or other privileges. * <p>Such tokens are usually not placed in city slots, * which are intended for base tokens, but on some unoccupied part of a tile. - * - * @author Erik Vos */ +//FIXME: Check if PublicCompany is the parent of a token public final class BonusToken extends Token implements Closeable, ConfigurableComponent { private int value; @@ -22,20 +20,17 @@ public final class BonusToken extends Token implements Closeable, ConfigurableCo private String removingObjectDesc = null; private Object removingObject = null; private PublicCompany user = null; - - private BonusToken() {}; + + private BonusToken(PublicCompany parent, String id) { + super(parent, id); + } public static BonusToken create(PublicCompany company) { - BonusToken token = new BonusToken(); - token.init(company); + String uniqueId = Token.createUniqueId(); + BonusToken token = new BonusToken(company, uniqueId); return token; } - @Override - public void init(Item parent) { - super.checkedInit(parent, null, PublicCompany.class); - } - public void configureFromXML(Tag tag) throws ConfigurationException { Tag bonusTokenTag = tag.getChild("BonusToken"); if (bonusTokenTag == null) { diff --git a/src/rails/game/Company.java b/src/rails/game/Company.java index 04f9658..c80d0dd 100644 --- a/src/rails/game/Company.java +++ b/src/rails/game/Company.java @@ -14,11 +14,12 @@ import rails.game.special.SpecialProperty; import rails.game.state.BooleanState; import rails.game.state.AbstractItem; import rails.game.state.Item; +import rails.game.state.PortfolioHolder; import rails.game.state.PortfolioList; import rails.util.Util; public abstract class Company extends AbstractItem implements ConfigurableComponent, -Cloneable, Comparable<Company> { +Cloneable, Comparable<Company>, PortfolioHolder { /** The name of the XML tag used to configure a company. */ public static final String COMPANY_ELEMENT_ID = "Company"; @@ -49,21 +50,17 @@ Cloneable, Comparable<Company> { protected int certLimitCount = 2; /** Closed state */ - protected final BooleanState closedObject = BooleanState.create(false); + protected final BooleanState closedObject = BooleanState.create(this, "closed", false); // Moved here from PrivayeCOmpany on behalf of 1835 - protected final PortfolioList<SpecialProperty> specialProperties = PortfolioList.create(); + protected final PortfolioList<SpecialProperty> specialProperties = PortfolioList.create(this, "specialProperties"); protected static Logger log = LoggerFactory.getLogger(Company.class.getPackage().getName()); - @Override - public void init(Item parent, String id) { - super.init(parent, id); - closedObject.init(this, "closed"); - specialProperties.init(this, "specialProperties"); + protected Company(Item parent, String id) { + super(parent, id); } - public void initType(CompanyType type) { this.type = type; } diff --git a/src/rails/game/CompanyManager.java b/src/rails/game/CompanyManager.java index 399e514..c91456c 100644 --- a/src/rails/game/CompanyManager.java +++ b/src/rails/game/CompanyManager.java @@ -13,6 +13,7 @@ import rails.common.parser.ConfigurableComponent; import rails.common.parser.ConfigurationException; import rails.common.parser.Tag; import rails.game.state.AbstractItem; +import rails.game.state.Item; public class CompanyManager extends AbstractItem implements ConfigurableComponent { @@ -62,13 +63,16 @@ public class CompanyManager extends AbstractItem implements ConfigurableComponen protected GameManager gameManager; + protected CompanyManager(Item parent, String id) { + super(parent, id); + } + /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ - public CompanyManager() { } /** * @see rails.common.parser.ConfigurableComponent#configureFromXML(org.w3c.dom.Element) @@ -174,7 +178,7 @@ public class CompanyManager extends AbstractItem implements ConfigurableComponen if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component - String name = packetTag.getAttributeAsString("name", StartPacket.DEFAULT_NAME); + String name = packetTag.getAttributeAsString("name", StartPacket.DEFAULT_ID); String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { @@ -182,7 +186,7 @@ public class CompanyManager extends AbstractItem implements ConfigurableComponen "StartPacketHasNoClass", name)); } - StartPacket sp = new StartPacket(name, roundClass); + StartPacket sp = StartPacket.create(this, name, roundClass); startPackets.add(sp); startPacketMap.put(name, sp); diff --git a/src/rails/game/CompanyType.java b/src/rails/game/CompanyType.java index cae1e49..8025848 100644 --- a/src/rails/game/CompanyType.java +++ b/src/rails/game/CompanyType.java @@ -43,23 +43,18 @@ public class CompanyType extends AbstractItem { protected List<Company> companies = new ArrayList<Company>(); - /** - * The constructor. - * - */ - private CompanyType(String className) { + protected CompanyType(Item parent, String id, String className) { + super(parent, id); this.className = className; } /** - * @param name Company type name ("Private", "Public", "Minor" etc.). + * @param id Company type name ("Private", "Public", "Minor" etc.). * @param className Name of the class that will instantiate this type of * company. */ - public static CompanyType create(Item parent, String id, String className) { - CompanyType type = new CompanyType(className); - type.init(parent, id); - return type; + public static CompanyType create(CompanyManager parent, String id, String className) { + return new CompanyType(parent, id, className); } /** @@ -82,7 +77,7 @@ public class CompanyType extends AbstractItem { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", className), e); } - newCompany.init(this, name); + // newCompany.init(this, name); newCompany.configureFromXML(typeTag); newCompany.configureFromXML(tag); companies.add(newCompany); diff --git a/src/rails/game/EndOfGameRound.java b/src/rails/game/EndOfGameRound.java index 3b2326c..aa4773d 100644 --- a/src/rails/game/EndOfGameRound.java +++ b/src/rails/game/EndOfGameRound.java @@ -11,13 +11,17 @@ import rails.common.LocalText; * * */ -public class EndOfGameRound extends Round { +public final class EndOfGameRound extends Round { - public EndOfGameRound(GameManager gameManager) { - super(gameManager); + public EndOfGameRound(GameManager parent, String id) { + super(parent, id); guiHints.setVisibilityHint(GuiDef.Panel.MAP, true); guiHints.setActivePanel(GuiDef.Panel.STATUS); - } + } + + public static EndOfGameRound create(GameManager parent, String id) { + return new EndOfGameRound(parent, id); + } @Override public boolean setPossibleActions() { diff --git a/src/rails/game/Game.java b/src/rails/game/Game.java index 961c7b2..3279b26 100644 --- a/src/rails/game/Game.java +++ b/src/rails/game/Game.java @@ -12,6 +12,8 @@ import rails.common.LocalText; import rails.common.parser.*; import rails.game.action.PossibleAction; import rails.game.state.Context; +import rails.game.state.Root; +import rails.game.state.StateManager; import rails.util.GameFileIO; public class Game { @@ -77,7 +79,8 @@ public class Game { public boolean setup() { // first define root GameContext to be able to define states - Context context = Context.create(); + StateManager stateManager = StateManager.create(parent, id) + Context context = Root.create(parent); GameFileParser gfp = new GameFileParser(context, name, gameOptions); playerManager = gfp.getPlayerManager(); diff --git a/src/rails/game/GameManager.java b/src/rails/game/GameManager.java index 779fd84..9fa593e 100644 --- a/src/rails/game/GameManager.java +++ b/src/rails/game/GameManager.java @@ -27,7 +27,7 @@ import rails.util.Util; * This class manages the playing rounds by supervising all implementations of * Round. Currently everything is hardcoded à la 1830. */ -public class GameManager extends AbstractItem implements ConfigurableComponent { +public class GameManager extends AbstractItem implements ConfigurableComponent, PortfolioHolder { /** Version ID of the Save file header, as written in save() */ private static final long saveFileHeaderVersionID = 3L; /** @@ -71,8 +71,9 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { protected List<Player> players; protected List<String> playerNames; protected int numberOfPlayers; - protected final GenericState<Player> currentPlayer = GenericState.create(); - protected final GenericState<Player> priorityPlayer = GenericState.create(); + protected final GenericState<Player> currentPlayer = GenericState.create(this, "currentPlayer"); + protected final GenericState<Player> priorityPlayer = GenericState.create(this, "priorityPlayer"); + /** Map relating portfolio names and objects, to enable deserialization. * OBSOLETE since Rails 1.3.1, but still required to enable reading old saved files */ @@ -82,7 +83,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { protected final Map<String, PortfolioModel> portfolioUniqueNameMap = new HashMap<String, PortfolioModel> (); - protected final IntegerState playerCertificateLimit = IntegerState.create(); + protected final IntegerState playerCertificateLimit = IntegerState.create(this, "playerCertificateLimit"); protected int currentNumberOfOperatingRounds = 1; protected boolean skipFirstStockRound = false; protected boolean showCompositeORNumber = true; @@ -107,21 +108,21 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { * been sold, it finishes by starting an Operating Round, which handles the * privates payout and then immediately starts a new Start Round. */ - protected final GenericState<Round> currentRound = GenericState.create(); + protected final GenericState<Round> currentRound = GenericState.create(this, "currentRound"); protected Round interruptedRound = null; - protected final IntegerState srNumber = IntegerState.create(); + protected final IntegerState srNumber = IntegerState.create(this, "srNumber"); - protected final IntegerState absoluteORNumber = IntegerState.create(); - protected final IntegerState relativeORNumber = IntegerState.create(); - protected final IntegerState numOfORs = IntegerState.create(); + protected final IntegerState absoluteORNumber = IntegerState.create(this, "absoluteORNUmber"); + protected final IntegerState relativeORNumber = IntegerState.create(this, "relativeORNumber"); + protected final IntegerState numOfORs = IntegerState.create(this, "numOfORs"); /** GameOver pending, a last OR or set of ORs must still be completed */ - protected final BooleanState gameOverPending = BooleanState.create(); + protected final BooleanState gameOverPending = BooleanState.create(this, "gameOverPending"); /** GameOver is executed, no more moves */ - protected final BooleanState gameOver = BooleanState.create(); + protected final BooleanState gameOver = BooleanState.create(this, "gameOver"); protected Boolean gameOverReportedUI = false; - protected final BooleanState endedByBankruptcy = BooleanState.create(); + protected final BooleanState endedByBankruptcy = BooleanState.create(this, "endedByBankruptcy"); /** UI display hints */ protected GuiHints guiHints; @@ -166,9 +167,10 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { /** * The MoveSet stack is maintained to enable Undo and Redo throughout the game. + * FIXME: ChangeStack moved to StateManager */ @Deprecated - protected final ChangeStack changeStack = ChangeStack.create(); + protected final ChangeStack changeStack = null; /** * The DisplayBuffer instance collects messages to be displayed in the UI. @@ -177,7 +179,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { /** * nextPlayerMessages collects all messages to be displayed to the next player */ - protected final ArrayListState<String> nextPlayerMessages = ArrayListState.create(); + protected final ArrayListState<String> nextPlayerMessages = ArrayListState.create(this, "nextPlayerMessages"); /** * The ReportBuffer collects messages to be shown in the Game Report. @@ -191,7 +193,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { protected PossibleActions possibleActions = PossibleActions.getInstance(); - protected final ArrayListState<PossibleAction> executedActions = ArrayListState.create(); + protected final ArrayListState<PossibleAction> executedActions = ArrayListState.create(this, "executedActions"); /** Special properties that can be used by other players or companies * than just the owner (such as buyable bonus tokens as in 1856). @@ -227,7 +229,9 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { protected static Logger log = LoggerFactory.getLogger(GameManager.class.getPackage().getName()); + // FIXME: This has to be rewritten public GameManager() { + super(null, GM_NAME); // TODO: fix that gmName = GM_NAME; gmKey = GM_KEY; // NDC.clear(); @@ -235,7 +239,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { gameManagerMap.put(GM_KEY, this); displayBuffer = new DisplayBuffer(); reportBuffer = new ReportBuffer(); - guiHints = new GuiHints(); + guiHints = GuiHints.create(this, "guiHints"); } public void configureFromXML(Tag tag) throws ConfigurationException { @@ -495,24 +499,6 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { } } - @Override - public void init(Item parent, String id){ - super.init(parent, id); - currentPlayer.init(this, "CurrentPlayer"); - priorityPlayer.init(this, "PriorityPlayer"); - playerCertificateLimit.init(this, "PlayerCertificateLimit"); - currentRound.init(this, "CurrentRound"); - srNumber.init(this, "SRNumber"); - absoluteORNumber.init(this, "AbsoluteORNUmber"); - relativeORNumber.init(this, "RelativeORNumber"); - numOfORs.init(this, "numOfORs"); - gameOverPending.init(this, "GameOverPending"); - gameOver.init(this, "GameOver"); - endedByBankruptcy.init(this, "EndedByBankruptcy"); - nextPlayerMessages.init(this, "nextPlayerMessages"); - executedActions.init(this, "executedActions"); - } - public void finishConfiguration (GameManager gameManager) {} /** Check if a classname can be instantiated. @@ -570,7 +556,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { setGuiParameters(); if (startPacket == null) - startPacket = companyManager.getStartPacket(StartPacket.DEFAULT_NAME); + startPacket = companyManager.getStartPacket(StartPacket.DEFAULT_ID); if (startPacket != null && !startPacket.areAllSold()) { startPacket.init(this); @@ -1711,8 +1697,7 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { public boolean addSpecialProperty(SpecialProperty property) { if (commonSpecialProperties == null) { - commonSpecialProperties = PortfolioList.create(); - commonSpecialProperties.init(this, "CommonSpecialProperties"); + commonSpecialProperties = PortfolioList.create(this, "CommonSpecialProperties"); } return commonSpecialProperties.moveInto(property); } @@ -1886,6 +1871,16 @@ public class GameManager extends AbstractItem implements ConfigurableComponent { objectStorage = new HashMap<String, Object>(); storageIds = new HashMap<String, Integer>(); } + + /** + * get storage id + * @param name to identify the type of the object to retrieve + */ + public int getStorageId(String typeName) { + Integer id = storageIds.get(typeName); + if (id == null) id = 0; + return id; + } /** * store element in storage diff --git a/src/rails/game/MapHex.java b/src/rails/game/MapHex.java index e338c10..43168b4 100644 --- a/src/rails/game/MapHex.java +++ b/src/rails/game/MapHex.java @@ -22,7 +22,6 @@ import rails.game.model.CashMoneyModel; import rails.game.model.PortfolioModel; import rails.game.state.BooleanState; -import rails.game.state.Item; import rails.game.state.Observer; import rails.game.state.Portfolio; import rails.game.state.PortfolioHolder; @@ -110,7 +109,7 @@ StationHolder { * changed to state variable to fix undo bug #2954645 * null as default implies false - see isBlocked() */ - private final BooleanState isBlockedForTileLays = BooleanState.create(); + private final BooleanState isBlockedForTileLays = BooleanState.create(this, "isBlockedForTileLays"); /** * Is the hex initially blocked for token lays (e.g. when a home base @@ -121,13 +120,13 @@ StationHolder { * the absence of a PR token does not block the third slot * when the green tile is laid. */ - private final BooleanState isBlockedForTokenLays = BooleanState.create(); + private final BooleanState isBlockedForTokenLays = BooleanState.create(this, "isBlockedForTokenLays"); protected Map<PublicCompany, Stop> homes; protected List<PublicCompany> destinations; /** Tokens that are not bound to a Station (City), such as Bonus tokens */ - protected final PortfolioList<Token> offStationTokens = PortfolioList.create(); + protected final PortfolioList<Token> offStationTokens = PortfolioList.create(this, "offStationTokens"); /** Storage of revenueBonus that are bound to the hex */ protected List<RevenueBonusTemplate> revenueBonuses = null; @@ -176,22 +175,17 @@ StationHolder { protected static Logger log = LoggerFactory.getLogger(MapHex.class.getPackage().getName()); - // TODO: Rewrite the creation process of MapHex - - // public constructor - public MapHex() {} + private MapHex(MapManager parent, String id) { + super(parent, id); + } - /** - * MapHex only accepts MapManagers as parent - */ - @Override - public void init(Item parent, String id) { - super.checkedInit(parent, id, MapManager.class); - - isBlockedForTileLays.init(this, name+"_IsBlockedForTileLays"); - isBlockedForTokenLays.init(this, name+"_IsBlockedForTokenLays"); + public static MapHex create(MapManager parent, Tag tag) throws ConfigurationException { + // TODO: Rewrite the creation process of MapHex + MapHex hex = new MapHex(parent, null); + hex.configureFromXML(tag); + return hex; } - + /** * @see rails.common.parser.ConfigurableComponent#configureFromXML(org.w3c.dom.Element) */ diff --git a/src/rails/game/MapManager.java b/src/rails/game/MapManager.java index de07282..7593568 100644 --- a/src/rails/game/MapManager.java +++ b/src/rails/game/MapManager.java @@ -64,7 +64,12 @@ public class MapManager extends AbstractItem implements ConfigurableComponent { protected static Logger log = LoggerFactory.getLogger(MapManager.class.getPackage().getName()); - public MapManager() { + private MapManager(GameManager parent, String id) { + super(parent, id); + } + + public static MapManager create(GameManager parent, String id) { + return new MapManager(parent, id); } /** @@ -121,9 +126,7 @@ public class MapManager extends AbstractItem implements ConfigurableComponent { maxX = maxY = maxCol = maxRow = Integer.MIN_VALUE; possibleTileCosts = new TreeSet<Integer>(); for (Tag hexTag : hexTags) { - hex = new MapHex(); - hex.configureFromXML(hexTag); - hex.init(this, hex.getName()); + hex = MapHex.create(this, hexTag); mHexes.put(hex.getId(), hex); minX = Math.min(minX, hex.getX()); minY = Math.min(minY, hex.getY()); diff --git a/src/rails/game/OperatingRound.java b/src/rails/game/OperatingRound.java index c15acdc..4e2c305 100644 --- a/src/rails/game/OperatingRound.java +++ b/src/rails/game/OperatingRound.java @@ -1,6 +1,5 @@ package rails.game; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -30,12 +29,13 @@ import rails.util.SequenceUtil; public class OperatingRound extends Round implements Observer { /* Transient memory (per round only) */ - protected final GenericState<GameDef.OrStep> stepObject = GenericState.create(GameDef.OrStep.INITIAL); + protected final GenericState<GameDef.OrStep> stepObject = GenericState.create( + this, "ORStep", GameDef.OrStep.INITIAL); protected boolean actionPossible = true; - /* sfy: using rails without map support */ - protected boolean noMapMode = false; + /* flag for using rails without map support */ + protected final boolean noMapMode; // TODO: Check if thi... [truncated message content] |