From: Erik V. <ev...@us...> - 2009-01-03 18:25:03
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv9873/rails/game Modified Files: Train.java OperatingRound.java TrainTypeI.java City.java TrainType.java Log Message: Fixed bug that disabled buying more than 1 "infinite quantity" train. Also fixed missing code in StartCompany_18EU deserialization. Index: TrainTypeI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainTypeI.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TrainTypeI.java 4 Jun 2008 19:00:30 -0000 1.6 --- TrainTypeI.java 3 Jan 2009 18:24:53 -0000 1.7 *************** *** 98,101 **** --- 98,103 ---- public void setRustedTrainType(TrainTypeI rustedTrainType); + + public TrainI cloneTrain(); } Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** OperatingRound.java 23 Dec 2008 19:56:40 -0000 1.48 --- OperatingRound.java 3 Jan 2009 18:24:53 -0000 1.49 *************** *** 1120,1124 **** int actualPresidentCash = 0; Player currentPlayer = operatingCompany.getPresident(); - ; // Dummy loop to enable a quick jump out. --- 1120,1123 ---- *************** *** 1243,1247 **** operatingCompany.buyTrain(train, price); ! if (oldHolder == Bank.getIpo()) train.getType().addToBoughtFromIPO(); if (oldHolder.getOwner() instanceof Bank) { trainsBoughtThisTurn.add(train.getType()); --- 1242,1253 ---- operatingCompany.buyTrain(train, price); ! if (oldHolder == Bank.getIpo()) { ! train.getType().addToBoughtFromIPO(); ! // Clone the train if infinitely available ! if (train.getType().hasInfiniteAmount()) { ! Bank.getIpo().addTrain(train.getType().cloneTrain()); ! } ! ! } if (oldHolder.getOwner() instanceof Bank) { trainsBoughtThisTurn.add(train.getType()); Index: TrainType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainType.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** TrainType.java 4 Jun 2008 19:00:31 -0000 1.19 --- TrainType.java 3 Jan 2009 18:24:53 -0000 1.20 *************** *** 60,63 **** --- 60,65 ---- protected ArrayList<TrainI> trains = null; + + protected int lastIndex = 0; protected BooleanState available; *************** *** 197,225 **** * of this type is bought. */ ! try { ! train = trainClass.newInstance(); ! } catch (InstantiationException e) { ! throw new ConfigurationException( ! "Cannot instantiate class " + trainClassName, e); ! } catch (IllegalAccessException e) { ! throw new ConfigurationException("Cannot access class " ! + trainClassName ! + "constructor", e); ! } ! train.init(this, 0); trains.add(train); } else { for (int i = 0; i < amount; i++) { ! try { ! train = trainClass.newInstance(); ! } catch (InstantiationException e) { ! throw new ConfigurationException( ! "Cannot instantiate class " + trainClassName, e); ! } catch (IllegalAccessException e) { ! throw new ConfigurationException("Cannot access class " ! + trainClassName ! + "constructor", e); ! } ! train.init(this, i); trains.add(train); } --- 199,207 ---- * of this type is bought. */ ! train = createTrain(); trains.add(train); } else { for (int i = 0; i < amount; i++) { ! train = createTrain (); trains.add(train); } *************** *** 232,235 **** --- 214,249 ---- rusted = new BooleanState(name + "-trains_Rusted", false); } + + protected TrainI createTrain () throws ConfigurationException { + + TrainI train; + try { + train = trainClass.newInstance(); + } catch (InstantiationException e) { + throw new ConfigurationException( + "Cannot instantiate class " + trainClassName, e); + } catch (IllegalAccessException e) { + throw new ConfigurationException("Cannot access class " + + trainClassName + + "constructor", e); + } + train.init(this, lastIndex++); + return train; + } + + /** Create train without throwing exceptions. + * To be used <b>after</b> completing initialization, + * i.e. in cloning infinitely available trains. + */ + + public TrainI cloneTrain () { + TrainI train = null; + try { + train = createTrain(); + } catch (ConfigurationException e) { + log.warn("Unexpected exception", e); + } + return train; + } /** Index: City.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/City.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** City.java 29 Nov 2008 21:50:58 -0000 1.6 --- City.java 3 Jan 2009 18:24:53 -0000 1.7 *************** *** 50,54 **** public String getName() { ! return "City " + number + " on Hex " + mapHex.getName(); } --- 50,55 ---- public String getName() { ! return mapHex.getName() + "/" + number; ! } Index: Train.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Train.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Train.java 4 Jun 2008 19:00:32 -0000 1.11 --- Train.java 3 Jan 2009 18:24:53 -0000 1.12 *************** *** 137,140 **** --- 137,141 ---- new ObjectMove(this, holder, to); + } |