From: <wak...@us...> - 2011-02-01 17:27:13
|
Revision: 1478 http://rails.svn.sourceforge.net/rails/?rev=1478&view=rev Author: wakko666 Date: 2011-02-01 17:27:05 +0000 (Tue, 01 Feb 2011) Log Message: ----------- Tag v1.4.1 Added Paths: ----------- tags/rails_1_4_1/ tags/rails_1_4_1/18xx/build.xml tags/rails_1_4_1/18xx/rails/game/Game.java tags/rails_1_4_1/18xx/rails.bat tags/rails_1_4_1/18xx/rails.sh Removed Paths: ------------- tags/rails_1_4_1/18xx/build.xml tags/rails_1_4_1/18xx/rails/game/Game.java tags/rails_1_4_1/18xx/rails.bat tags/rails_1_4_1/18xx/rails.sh Deleted: tags/rails_1_4_1/18xx/build.xml =================================================================== --- trunk/18xx/build.xml 2011-01-29 16:48:22 UTC (rev 1476) +++ tags/rails_1_4_1/18xx/build.xml 2011-02-01 17:27:05 UTC (rev 1478) @@ -1,160 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- WARNING: Eclipse auto-generated file. - Any modifications will be overwritten. - To include a user specific buildfile here, simply create one in the same - directory with the processing instruction <?eclipse.ant.import?> - as the first entry and export the buildfile again. --> -<project basedir="." default="build" name="18xx"> - <property environment="env"/> - <property name="debuglevel" value="source,lines,vars"/> - <property name="target" value="1.5"/> - <property name="source" value="1.5"/> - <property name="version" value="1.4"/> - <taskdef name="jarbundler" - classpath="tools/lib/jarbundler-2.1.0.jar" - classname="net.sourceforge.jarbundler.JarBundler" /> - <path id="18xx.classpath"> - <pathelement location="classes"/> - <pathelement location="lib/log4j-1.2/log4j-1.2.14.jar"/> - <pathelement location="lib/batik-1.6/batik-rasterizer.jar"/> - <pathelement location="lib/batik-1.6/batik.jar"/> - <pathelement location="lib/jgraph5/jgraph.jar"/> - <pathelement location="lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar"/> - <pathelement location="lib/junit_3.8.2/junit.jar"/> - </path> - <target depends="clean" name="init"> - <mkdir dir="classes"/> - <copy includeemptydirs="false" todir="classes"> - <fileset dir="."> - <exclude name="**/*.launch"/> - <exclude name="**/*.java"/> - <exclude name="tools/**"/> - <exclude name="images/**"/> - </fileset> - </copy> - </target> - <target name="clean"> - <delete dir="classes"/> - <delete dir="jar"/> - </target> - <target depends="clean" name="cleanall"> - <delete dir="rails-${version}"/> - <delete dir="rails-mac-${version}"/> - <delete file="18xx.log"/> - </target> - <target depends="build-subprojects,build-project,build-release" name="build"/> - <target name="build-subprojects"/> - <target depends="init" name="build-project"> - <echo message="${ant.project.name}: ${ant.file}"/> - <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}"> - <src path="."/> - <classpath refid="18xx.classpath"/> - </javac> - </target> - <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/> - <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler"> - <copy todir="${ant.library.dir}"> - <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> - </copy> - <unzip dest="${ant.library.dir}"> - <patternset includes="jdtCompilerAdapter.jar"/> - <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> - </unzip> - </target> - <target description="compile project with Eclipse compiler" name="build-eclipse-compiler"> - <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> - <antcall target="build"/> - </target> - <target name="build-release"> - <mkdir dir="jar"/> - <copy includeemptydirs="false" todir="jar"> - <fileset dir="classes"> - <exclude name="**/*.launch"/> - <exclude name="**/*.java"/> - <exclude name="rails/test/*"/> - <exclude name="18xx.log"/> - <exclude name="build.xml"/> - <exclude name="buildinfo.xml"/> - <exclude name="manifest"/> - <exclude name="doc/*"/> - <exclude name="html/*"/> - <exclude name="lib/**"/> - <exclude name="rails-${version}/**"/> - <exclude name="rails-*-${version}/**"/> - <exclude name="rails.bat"/> - <exclude name="rails.sh"/> - <exclude name=".project"/> - <exclude name=".classpath"/> - <exclude name="**/CVS/*"/> - <exclude name="**/.settings/*"/> - <exclude name="**/rails-${version}.jar"/> - </fileset> - </copy> - <mkdir dir="rails-${version}"/> - <copy includeemptydirs="false" todir="rails-${version}"> - <fileset dir="."> - <include name="LICENSE"/> - <include name="README"/> - <include name="AUTHORS"/> - <include name="rails.bat"/> - <include name="rails.sh"/> - <include name="my.properties"/> - <include name="LocalisedText.properties"/> - <include name="games.properties"/> - <include name="lib/**"/> - </fileset> - </copy> - <jar destfile="rails-${version}/rails-${version}.jar" basedir="jar" duplicate="preserve"> - <manifest> - <attribute name="Main-Class" value="rails.util.RunGame" /> - <attribute name="Class-Path" value="./my.properties ./LocalisedText.properties ./lib/log4j-1.2/log4j-1.2.14.jar ./lib/batik-1.6/lib/batik-transcoder.jar ./lib/batik-1.6/batik.jar ./lib/batik-1.6/lib/batik-util.jar ./lib/batik-1.6/lib/batik-script.jar ./lib/batik-1.6/lib/batik-bridge.jar ./lib/batik-1.6/lib/batik-ext.jar ./lib/batik-1.6/lib/batik-awt-util.jar ./lib/batik-1.6/lib/batik-dom.jar ./lib/batik-1.6/lib/batik-gvt.jar ./lib/jgraph5/jgraph.jar ./lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar" /> - </manifest> - </jar> - </target> - <target name="build-mac"> - <mkdir dir="rails-mac-${version}" /> - <copy includeemptydirs="false" todir="rails-mac-${version}"> - <fileset dir="."> - <include name="LICENSE"/> - <include name="README"/> - <include name="AUTHORS"/> - <include name="my.properties"/> - </fileset> - </copy> - <jarbundler dir="rails-mac-${version}" - name="Rails" - mainclass="rails.util.RunGame" - icon="images/icon/rails.icns" - version="${version}"> - <jarfileset dir="rails-${version}"> - <include name="rails-${version}.jar"/> - <include name="lib/**"/> - </jarfileset> - <javaproperty name="apple.laf.useScreenMenuBar" value="true"/> - </jarbundler> - </target> - <target name="RunGame"> - <java classname="rails.util.RunGame" failonerror="true" fork="yes"> - <classpath refid="18xx.classpath"/> - </java> - </target> - <target name="TestGames"> - <property name="test.xml.dir" value="test/xml"/> - <property name="test.report.dir" value="test/report"/> - <mkdir dir="${test.xml.dir}"/> - <mkdir dir="${test.report.dir}"/> - <junit> - <classpath refid="18xx.classpath"/> - <formatter type="brief" usefile="false" /> - <formatter type="xml" /> - <test name ="test.TestGameBuilder" todir="${test.xml.dir}"/> - </junit> - <junitreport todir="${test.xml.dir}"> - <fileset dir="${test.xml.dir}"> - <include name="TEST-*.xml"/> - </fileset> - <report format="noframes" todir="${test.report.dir}"/> - </junitreport> - </target> - -</project> Copied: tags/rails_1_4_1/18xx/build.xml (from rev 1477, trunk/18xx/build.xml) =================================================================== --- tags/rails_1_4_1/18xx/build.xml (rev 0) +++ tags/rails_1_4_1/18xx/build.xml 2011-02-01 17:27:05 UTC (rev 1478) @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- WARNING: Eclipse auto-generated file. + Any modifications will be overwritten. + To include a user specific buildfile here, simply create one in the same + directory with the processing instruction <?eclipse.ant.import?> + as the first entry and export the buildfile again. --> +<project basedir="." default="build" name="18xx"> + <property environment="env"/> + <property name="debuglevel" value="source,lines,vars"/> + <property name="target" value="1.5"/> + <property name="source" value="1.5"/> + <property name="version" value="1.4.1"/> + <taskdef name="jarbundler" + classpath="tools/lib/jarbundler-2.1.0.jar" + classname="net.sourceforge.jarbundler.JarBundler" /> + <path id="18xx.classpath"> + <pathelement location="classes"/> + <pathelement location="lib/log4j-1.2/log4j-1.2.14.jar"/> + <pathelement location="lib/batik-1.6/batik-rasterizer.jar"/> + <pathelement location="lib/batik-1.6/batik.jar"/> + <pathelement location="lib/jgraph5/jgraph.jar"/> + <pathelement location="lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar"/> + <pathelement location="lib/junit_3.8.2/junit.jar"/> + </path> + <target depends="clean" name="init"> + <mkdir dir="classes"/> + <copy includeemptydirs="false" todir="classes"> + <fileset dir="."> + <exclude name="**/*.launch"/> + <exclude name="**/*.java"/> + <exclude name="tools/**"/> + <exclude name="images/**"/> + </fileset> + </copy> + </target> + <target name="clean"> + <delete dir="classes"/> + <delete dir="jar"/> + </target> + <target depends="clean" name="cleanall"> + <delete dir="rails-${version}"/> + <delete dir="rails-mac-${version}"/> + <delete file="18xx.log"/> + </target> + <target depends="build-subprojects,build-project,build-release" name="build"/> + <target name="build-subprojects"/> + <target depends="init" name="build-project"> + <echo message="${ant.project.name}: ${ant.file}"/> + <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}"> + <src path="."/> + <classpath refid="18xx.classpath"/> + </javac> + </target> + <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/> + <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler"> + <copy todir="${ant.library.dir}"> + <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> + </copy> + <unzip dest="${ant.library.dir}"> + <patternset includes="jdtCompilerAdapter.jar"/> + <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> + </unzip> + </target> + <target description="compile project with Eclipse compiler" name="build-eclipse-compiler"> + <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> + <antcall target="build"/> + </target> + <target name="build-release"> + <mkdir dir="jar"/> + <copy includeemptydirs="false" todir="jar"> + <fileset dir="classes"> + <exclude name="**/*.launch"/> + <exclude name="**/*.java"/> + <exclude name="rails/test/*"/> + <exclude name="18xx.log"/> + <exclude name="build.xml"/> + <exclude name="buildinfo.xml"/> + <exclude name="manifest"/> + <exclude name="doc/*"/> + <exclude name="html/*"/> + <exclude name="lib/**"/> + <exclude name="rails-${version}/**"/> + <exclude name="rails-*-${version}/**"/> + <exclude name="rails.bat"/> + <exclude name="rails.sh"/> + <exclude name=".project"/> + <exclude name=".classpath"/> + <exclude name="**/CVS/*"/> + <exclude name="**/.settings/*"/> + <exclude name="**/rails-${version}.jar"/> + </fileset> + </copy> + <mkdir dir="rails-${version}"/> + <copy includeemptydirs="false" todir="rails-${version}"> + <fileset dir="."> + <include name="LICENSE"/> + <include name="README"/> + <include name="AUTHORS"/> + <include name="rails.bat"/> + <include name="rails.sh"/> + <include name="my.properties"/> + <include name="LocalisedText.properties"/> + <include name="games.properties"/> + <include name="lib/**"/> + </fileset> + </copy> + <jar destfile="rails-${version}/rails-${version}.jar" basedir="jar" duplicate="preserve"> + <manifest> + <attribute name="Main-Class" value="rails.util.RunGame" /> + <attribute name="Class-Path" value="./my.properties ./LocalisedText.properties ./lib/log4j-1.2/log4j-1.2.14.jar ./lib/batik-1.6/lib/batik-transcoder.jar ./lib/batik-1.6/batik.jar ./lib/batik-1.6/lib/batik-util.jar ./lib/batik-1.6/lib/batik-script.jar ./lib/batik-1.6/lib/batik-bridge.jar ./lib/batik-1.6/lib/batik-ext.jar ./lib/batik-1.6/lib/batik-awt-util.jar ./lib/batik-1.6/lib/batik-dom.jar ./lib/batik-1.6/lib/batik-gvt.jar ./lib/jgraph5/jgraph.jar ./lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar" /> + </manifest> + </jar> + </target> + <target name="build-mac"> + <mkdir dir="rails-mac-${version}" /> + <copy includeemptydirs="false" todir="rails-mac-${version}"> + <fileset dir="."> + <include name="LICENSE"/> + <include name="README"/> + <include name="AUTHORS"/> + <include name="my.properties"/> + </fileset> + </copy> + <jarbundler dir="rails-mac-${version}" + name="Rails" + mainclass="rails.util.RunGame" + icon="images/icon/rails.icns" + version="${version}"> + <jarfileset dir="rails-${version}"> + <include name="rails-${version}.jar"/> + <include name="lib/**"/> + </jarfileset> + <javaproperty name="apple.laf.useScreenMenuBar" value="true"/> + </jarbundler> + </target> + <target name="RunGame"> + <java classname="rails.util.RunGame" failonerror="true" fork="yes"> + <classpath refid="18xx.classpath"/> + </java> + </target> + <target name="TestGames"> + <property name="test.xml.dir" value="test/xml"/> + <property name="test.report.dir" value="test/report"/> + <mkdir dir="${test.xml.dir}"/> + <mkdir dir="${test.report.dir}"/> + <junit> + <classpath refid="18xx.classpath"/> + <formatter type="brief" usefile="false" /> + <formatter type="xml" /> + <test name ="test.TestGameBuilder" todir="${test.xml.dir}"/> + </junit> + <junitreport todir="${test.xml.dir}"> + <fileset dir="${test.xml.dir}"> + <include name="TEST-*.xml"/> + </fileset> + <report format="noframes" todir="${test.report.dir}"/> + </junitreport> + </target> + +</project> Deleted: tags/rails_1_4_1/18xx/rails/game/Game.java =================================================================== --- trunk/18xx/rails/game/Game.java 2011-01-29 16:48:22 UTC (rev 1476) +++ tags/rails_1_4_1/18xx/rails/game/Game.java 2011-02-01 17:27:05 UTC (rev 1478) @@ -1,342 +0,0 @@ -/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/Game.java,v 1.56 2010/06/06 13:01:00 evos Exp $ */ -package rails.game; - -import java.io.*; -import java.util.*; - -import org.apache.log4j.Logger; - -import rails.algorithms.RevenueManager; -import rails.game.action.PossibleAction; -import rails.game.special.SpecialProperty; -import rails.util.LocalText; -import rails.util.Tag; - -public class Game { - public static final String version = "1.4+"; - - /** The component Manager */ - protected ComponentManager componentManager; - protected GameManager gameManager; - protected CompanyManagerI companyManager; - protected PlayerManager playerManager; - protected PhaseManager phaseManager; - protected TrainManager trainManager; - protected StockMarketI stockMarket; - protected MapManager mapManager; - protected TileManager tileManager; - protected RevenueManager revenueManager; - protected Bank bank; - protected String name; - protected Tag componentManagerTag; - protected static String GAME_XML_FILE = "Game.xml"; - protected List<String> directories = new ArrayList<String>(); - protected Map<String, String> gameOptions; - - protected List<String> players; - - protected static Logger log = - Logger.getLogger(Game.class.getPackage().getName()); - - // The new Game entry point - public Game(String name, List<String> players, Map<String, String> options) { - - this.name = name; - this.gameOptions = options; - - gameOptions.put(GameOption.NUMBER_OF_PLAYERS, - String.valueOf(players.size())); - - for (String playerName : players) { - log.debug("Player: " + playerName); - } - for (String optionName : gameOptions.keySet()) { - log.debug("Option: " + optionName + "=" - + gameOptions.get(optionName)); - } - directories.add("data"); - directories.add("data/" + name); - - this.players = players; - } - - public String start() { - - if (players.size() < playerManager.minPlayers - || players.size() > playerManager.maxPlayers) { - return name+" is not configured to be played with "+players.size()+" players\n" - + "Please enter a valid number of players, or add a <Players> entry to data/"+name+"/Game.xml"; - } - - gameManager.startGame(gameOptions); - return null; - } - - public boolean setup() { - - try { - componentManagerTag = - Tag.findTopTagInFile(GAME_XML_FILE, directories, - ComponentManager.ELEMENT_ID); - if (componentManagerTag == null) { - throw new ConfigurationException( - "No Game XML element found in file " + GAME_XML_FILE); - } - - componentManagerTag.setGameOptions(gameOptions); - componentManager = - ComponentManager.configureInstance(name, componentManagerTag, gameOptions); - - log.info("========== Start of rails.game " + name + " =========="); - log.info("Rails version "+version); - ReportBuffer.add(LocalText.getText("GameIs", name)); - - // set special properties and token static variables - SpecialProperty.init(); - Token.init(); - - // Have the ComponentManager work through the other rails.game files - componentManager.finishPreparation(); - - playerManager = (PlayerManager) componentManager.findComponent("PlayerManager"); - if (playerManager == null) { - throw new ConfigurationException( - "No PlayerManager XML element found in file " + GAME_XML_FILE); - } - - bank = (Bank) componentManager.findComponent("Bank"); - if (bank == null) { - throw new ConfigurationException( - "No Bank XML element found in file " + GAME_XML_FILE); - } - - companyManager = - (CompanyManagerI) componentManager.findComponent(CompanyManagerI.COMPONENT_NAME); - if (companyManager == null) { - throw new ConfigurationException( - "No CompanyManager XML element found in file " - + GAME_XML_FILE); - } - stockMarket = - (StockMarketI) componentManager.findComponent(StockMarketI.COMPONENT_NAME); - if (stockMarket == null) { - throw new ConfigurationException( - "No StockMarket XML element found in file " - + GAME_XML_FILE); - } - gameManager = - (GameManager) componentManager.findComponent("GameManager"); - if (gameManager == null) { - throw new ConfigurationException( - "No GameManager XML element found in file " - + GAME_XML_FILE); - } - - phaseManager = - (PhaseManager) componentManager.findComponent("PhaseManager"); - if (phaseManager == null) { - throw new ConfigurationException( - "No PhaseManager XML element found in file " - + GAME_XML_FILE); - } - - trainManager = - (TrainManager) componentManager.findComponent("TrainManager"); - if (trainManager == null) { - throw new ConfigurationException( - "No TrainManager XML element found in file " - + GAME_XML_FILE); - } - - mapManager = - (MapManager) componentManager.findComponent("Map"); - if (mapManager == null) { - throw new ConfigurationException( - "No Map XML element found in file " - + GAME_XML_FILE); - } - - tileManager = - (TileManager) componentManager.findComponent("TileManager"); - if (tileManager == null) { - throw new ConfigurationException( - "No TileManager XML element found in file " - + GAME_XML_FILE); - } - - revenueManager = - (RevenueManager) componentManager.findComponent("RevenueManager"); - // revenueManager is optional so far -// if (revenueManager == null) { -// throw new ConfigurationException( -// "No RevenueManager XML element found in file " -// + GAME_XML_FILE); -// } - - /* - * Initialisations that involve relations between components can - * only be done after all XML has been processed. - */ - playerManager.setPlayers(players, bank); - gameManager.init(name, playerManager, companyManager, - phaseManager, trainManager, stockMarket, mapManager, - tileManager, revenueManager, bank); - - companyManager.finishConfiguration(gameManager); - trainManager.finishConfiguration(gameManager); - phaseManager.finishConfiguration(gameManager); - mapManager.finishConfiguration(gameManager); - bank.finishConfiguration(gameManager); - stockMarket.finishConfiguration(gameManager); - tileManager.finishConfiguration(gameManager); - if (revenueManager != null) - revenueManager.finishConfiguration(gameManager); - } catch (Exception e) { - String message = - LocalText.getText("GameSetupFailed", GAME_XML_FILE); - log.fatal(message, e); - System.out.println(e.getMessage()); - e.printStackTrace(); - DisplayBuffer.add(message + ":\n " + e.getMessage()); - return false; - } - - return true; - } - - @SuppressWarnings("unchecked") - public static Game load(String filepath) { - - Game game = null; - - log.debug("Loading game from file " + filepath); - String filename = filepath.replaceAll(".*[/\\\\]", ""); - - try { - ObjectInputStream ois = - new ObjectInputStream(new FileInputStream( - new File(filepath))); - - // New in 1.0.7: Rails version & save date/time. - // Allow for older saved file versions. - Object object = ois.readObject(); - if (object instanceof String) { - log.info("Reading Rails "+(String)object+" saved file "+filename); - object = ois.readObject(); - } else { - log.info("Reading Rails (pre-1.0.7) saved file "+filename); - } - if (object instanceof String) { - log.info("File was saved at "+(String)object); - object = ois.readObject(); - } - - long versionID = (Long) object; - log.debug("Saved versionID="+versionID+" (object="+object+")"); - long saveFileVersionID = GameManager.saveFileVersionID; - if (versionID != saveFileVersionID) { - throw new Exception("Save version " + versionID - + " is incompatible with current version " - + saveFileVersionID); - } - String name = (String) ois.readObject(); - log.debug("Saved game="+name); - Map<String, String> selectedGameOptions = - (Map<String, String>) ois.readObject(); - List<String> playerNames = (List<String>) ois.readObject(); - - game = new Game(name, playerNames, selectedGameOptions); - - if (!game.setup()) { - throw new ConfigurationException("Error in setting up " + name); - } - - String startError = game.start(); - if (startError != null) { - DisplayBuffer.add(startError); - return null; - } - GameManagerI gameManager = game.getGameManager(); - int numberOfActions = 0; - - log.debug("Starting to execute loaded actions"); - - gameManager.setReloading(true); - - Object actionObject = null; - while (true) { // Single-pass loop. - try { - actionObject = ois.readObject(); - } catch (EOFException e) { - // Allow saved file at start of game (with no actions). - break; - } - if (actionObject instanceof List) { - // Old-style: one List of PossibleActions - List<PossibleAction> executedActions = - (List<PossibleAction>) actionObject; - numberOfActions = executedActions.size(); - for (PossibleAction action : executedActions) { - if (!gameManager.processOnReload(action)) { - log.error ("Load interrupted"); - DisplayBuffer.add(LocalText.getText("LoadInterrupted")); - break; - } - } - } else if (actionObject instanceof PossibleAction) { - // New style: separate PossibleActionsObjects, since Rails 1.3.1 - while (actionObject instanceof PossibleAction) { - numberOfActions++; - if (!gameManager.processOnReload((PossibleAction)actionObject)) { - log.error ("Load interrupted"); - DisplayBuffer.add(LocalText.getText("LoadInterrupted")); - break; - } - try { - actionObject = ois.readObject(); - } catch (EOFException e) { - break; - } - } - } - break; - } - - // load user comments (is the last - if (actionObject instanceof SortedMap) { - ReportBuffer.setCommentItems((SortedMap<Integer, String>) actionObject); - log.debug("Found sorted map"); - } else { - try { - object = ois.readObject(); - if (object instanceof SortedMap) { - ReportBuffer.setCommentItems((SortedMap<Integer, String>) object); - } - } catch (IOException e) { - // continue without comments, if any IOException occurs - // sometimes not only the EOF Exception is raised - // but also the java.io.StreamCorruptedException: invalid type code - } - } - - ois.close(); - - gameManager.setReloading(false); - gameManager.finishLoading(); - return game; - - } catch (Exception e) { - log.error("Load failed", e); - DisplayBuffer.add(LocalText.getText("LoadFailed", e.getMessage())); - } - - return null; - } - - /*----- Getters -----*/ - - public GameManagerI getGameManager() { - return gameManager; - } - -} Copied: tags/rails_1_4_1/18xx/rails/game/Game.java (from rev 1477, trunk/18xx/rails/game/Game.java) =================================================================== --- tags/rails_1_4_1/18xx/rails/game/Game.java (rev 0) +++ tags/rails_1_4_1/18xx/rails/game/Game.java 2011-02-01 17:27:05 UTC (rev 1478) @@ -0,0 +1,342 @@ +/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/Game.java,v 1.56 2010/06/06 13:01:00 evos Exp $ */ +package rails.game; + +import java.io.*; +import java.util.*; + +import org.apache.log4j.Logger; + +import rails.algorithms.RevenueManager; +import rails.game.action.PossibleAction; +import rails.game.special.SpecialProperty; +import rails.util.LocalText; +import rails.util.Tag; + +public class Game { + public static final String version = "1.4.1"; + + /** The component Manager */ + protected ComponentManager componentManager; + protected GameManager gameManager; + protected CompanyManagerI companyManager; + protected PlayerManager playerManager; + protected PhaseManager phaseManager; + protected TrainManager trainManager; + protected StockMarketI stockMarket; + protected MapManager mapManager; + protected TileManager tileManager; + protected RevenueManager revenueManager; + protected Bank bank; + protected String name; + protected Tag componentManagerTag; + protected static String GAME_XML_FILE = "Game.xml"; + protected List<String> directories = new ArrayList<String>(); + protected Map<String, String> gameOptions; + + protected List<String> players; + + protected static Logger log = + Logger.getLogger(Game.class.getPackage().getName()); + + // The new Game entry point + public Game(String name, List<String> players, Map<String, String> options) { + + this.name = name; + this.gameOptions = options; + + gameOptions.put(GameOption.NUMBER_OF_PLAYERS, + String.valueOf(players.size())); + + for (String playerName : players) { + log.debug("Player: " + playerName); + } + for (String optionName : gameOptions.keySet()) { + log.debug("Option: " + optionName + "=" + + gameOptions.get(optionName)); + } + directories.add("data"); + directories.add("data/" + name); + + this.players = players; + } + + public String start() { + + if (players.size() < playerManager.minPlayers + || players.size() > playerManager.maxPlayers) { + return name+" is not configured to be played with "+players.size()+" players\n" + + "Please enter a valid number of players, or add a <Players> entry to data/"+name+"/Game.xml"; + } + + gameManager.startGame(gameOptions); + return null; + } + + public boolean setup() { + + try { + componentManagerTag = + Tag.findTopTagInFile(GAME_XML_FILE, directories, + ComponentManager.ELEMENT_ID); + if (componentManagerTag == null) { + throw new ConfigurationException( + "No Game XML element found in file " + GAME_XML_FILE); + } + + componentManagerTag.setGameOptions(gameOptions); + componentManager = + ComponentManager.configureInstance(name, componentManagerTag, gameOptions); + + log.info("========== Start of rails.game " + name + " =========="); + log.info("Rails version "+version); + ReportBuffer.add(LocalText.getText("GameIs", name)); + + // set special properties and token static variables + SpecialProperty.init(); + Token.init(); + + // Have the ComponentManager work through the other rails.game files + componentManager.finishPreparation(); + + playerManager = (PlayerManager) componentManager.findComponent("PlayerManager"); + if (playerManager == null) { + throw new ConfigurationException( + "No PlayerManager XML element found in file " + GAME_XML_FILE); + } + + bank = (Bank) componentManager.findComponent("Bank"); + if (bank == null) { + throw new ConfigurationException( + "No Bank XML element found in file " + GAME_XML_FILE); + } + + companyManager = + (CompanyManagerI) componentManager.findComponent(CompanyManagerI.COMPONENT_NAME); + if (companyManager == null) { + throw new ConfigurationException( + "No CompanyManager XML element found in file " + + GAME_XML_FILE); + } + stockMarket = + (StockMarketI) componentManager.findComponent(StockMarketI.COMPONENT_NAME); + if (stockMarket == null) { + throw new ConfigurationException( + "No StockMarket XML element found in file " + + GAME_XML_FILE); + } + gameManager = + (GameManager) componentManager.findComponent("GameManager"); + if (gameManager == null) { + throw new ConfigurationException( + "No GameManager XML element found in file " + + GAME_XML_FILE); + } + + phaseManager = + (PhaseManager) componentManager.findComponent("PhaseManager"); + if (phaseManager == null) { + throw new ConfigurationException( + "No PhaseManager XML element found in file " + + GAME_XML_FILE); + } + + trainManager = + (TrainManager) componentManager.findComponent("TrainManager"); + if (trainManager == null) { + throw new ConfigurationException( + "No TrainManager XML element found in file " + + GAME_XML_FILE); + } + + mapManager = + (MapManager) componentManager.findComponent("Map"); + if (mapManager == null) { + throw new ConfigurationException( + "No Map XML element found in file " + + GAME_XML_FILE); + } + + tileManager = + (TileManager) componentManager.findComponent("TileManager"); + if (tileManager == null) { + throw new ConfigurationException( + "No TileManager XML element found in file " + + GAME_XML_FILE); + } + + revenueManager = + (RevenueManager) componentManager.findComponent("RevenueManager"); + // revenueManager is optional so far +// if (revenueManager == null) { +// throw new ConfigurationException( +// "No RevenueManager XML element found in file " +// + GAME_XML_FILE); +// } + + /* + * Initialisations that involve relations between components can + * only be done after all XML has been processed. + */ + playerManager.setPlayers(players, bank); + gameManager.init(name, playerManager, companyManager, + phaseManager, trainManager, stockMarket, mapManager, + tileManager, revenueManager, bank); + + companyManager.finishConfiguration(gameManager); + trainManager.finishConfiguration(gameManager); + phaseManager.finishConfiguration(gameManager); + mapManager.finishConfiguration(gameManager); + bank.finishConfiguration(gameManager); + stockMarket.finishConfiguration(gameManager); + tileManager.finishConfiguration(gameManager); + if (revenueManager != null) + revenueManager.finishConfiguration(gameManager); + } catch (Exception e) { + String message = + LocalText.getText("GameSetupFailed", GAME_XML_FILE); + log.fatal(message, e); + System.out.println(e.getMessage()); + e.printStackTrace(); + DisplayBuffer.add(message + ":\n " + e.getMessage()); + return false; + } + + return true; + } + + @SuppressWarnings("unchecked") + public static Game load(String filepath) { + + Game game = null; + + log.debug("Loading game from file " + filepath); + String filename = filepath.replaceAll(".*[/\\\\]", ""); + + try { + ObjectInputStream ois = + new ObjectInputStream(new FileInputStream( + new File(filepath))); + + // New in 1.0.7: Rails version & save date/time. + // Allow for older saved file versions. + Object object = ois.readObject(); + if (object instanceof String) { + log.info("Reading Rails "+(String)object+" saved file "+filename); + object = ois.readObject(); + } else { + log.info("Reading Rails (pre-1.0.7) saved file "+filename); + } + if (object instanceof String) { + log.info("File was saved at "+(String)object); + object = ois.readObject(); + } + + long versionID = (Long) object; + log.debug("Saved versionID="+versionID+" (object="+object+")"); + long saveFileVersionID = GameManager.saveFileVersionID; + if (versionID != saveFileVersionID) { + throw new Exception("Save version " + versionID + + " is incompatible with current version " + + saveFileVersionID); + } + String name = (String) ois.readObject(); + log.debug("Saved game="+name); + Map<String, String> selectedGameOptions = + (Map<String, String>) ois.readObject(); + List<String> playerNames = (List<String>) ois.readObject(); + + game = new Game(name, playerNames, selectedGameOptions); + + if (!game.setup()) { + throw new ConfigurationException("Error in setting up " + name); + } + + String startError = game.start(); + if (startError != null) { + DisplayBuffer.add(startError); + return null; + } + GameManagerI gameManager = game.getGameManager(); + int numberOfActions = 0; + + log.debug("Starting to execute loaded actions"); + + gameManager.setReloading(true); + + Object actionObject = null; + while (true) { // Single-pass loop. + try { + actionObject = ois.readObject(); + } catch (EOFException e) { + // Allow saved file at start of game (with no actions). + break; + } + if (actionObject instanceof List) { + // Old-style: one List of PossibleActions + List<PossibleAction> executedActions = + (List<PossibleAction>) actionObject; + numberOfActions = executedActions.size(); + for (PossibleAction action : executedActions) { + if (!gameManager.processOnReload(action)) { + log.error ("Load interrupted"); + DisplayBuffer.add(LocalText.getText("LoadInterrupted")); + break; + } + } + } else if (actionObject instanceof PossibleAction) { + // New style: separate PossibleActionsObjects, since Rails 1.3.1 + while (actionObject instanceof PossibleAction) { + numberOfActions++; + if (!gameManager.processOnReload((PossibleAction)actionObject)) { + log.error ("Load interrupted"); + DisplayBuffer.add(LocalText.getText("LoadInterrupted")); + break; + } + try { + actionObject = ois.readObject(); + } catch (EOFException e) { + break; + } + } + } + break; + } + + // load user comments (is the last + if (actionObject instanceof SortedMap) { + ReportBuffer.setCommentItems((SortedMap<Integer, String>) actionObject); + log.debug("Found sorted map"); + } else { + try { + object = ois.readObject(); + if (object instanceof SortedMap) { + ReportBuffer.setCommentItems((SortedMap<Integer, String>) object); + } + } catch (IOException e) { + // continue without comments, if any IOException occurs + // sometimes not only the EOF Exception is raised + // but also the java.io.StreamCorruptedException: invalid type code + } + } + + ois.close(); + + gameManager.setReloading(false); + gameManager.finishLoading(); + return game; + + } catch (Exception e) { + log.error("Load failed", e); + DisplayBuffer.add(LocalText.getText("LoadFailed", e.getMessage())); + } + + return null; + } + + /*----- Getters -----*/ + + public GameManagerI getGameManager() { + return gameManager; + } + +} Deleted: tags/rails_1_4_1/18xx/rails.bat =================================================================== (Binary files differ) Copied: tags/rails_1_4_1/18xx/rails.bat (from rev 1477, trunk/18xx/rails.bat) =================================================================== (Binary files differ) Deleted: tags/rails_1_4_1/18xx/rails.sh =================================================================== --- trunk/18xx/rails.sh 2011-01-29 16:48:22 UTC (rev 1476) +++ tags/rails_1_4_1/18xx/rails.sh 2011-02-01 17:27:05 UTC (rev 1478) @@ -1,3 +0,0 @@ -#!/bin/bash - -java -jar ./rails-1.4.jar $1 \ No newline at end of file Copied: tags/rails_1_4_1/18xx/rails.sh (from rev 1477, trunk/18xx/rails.sh) =================================================================== --- tags/rails_1_4_1/18xx/rails.sh (rev 0) +++ tags/rails_1_4_1/18xx/rails.sh 2011-02-01 17:27:05 UTC (rev 1478) @@ -0,0 +1,3 @@ +#!/bin/bash + +java -jar ./rails-1.4.1.jar $1 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |