From: Erik V. <ev...@us...> - 2010-01-26 19:50:38
|
Update of /cvsroot/rails/18xx/rails/game/action In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv8810/rails/game/action Modified Files: BuyTrain.java Log Message: Fixed instantiation problem for 2nd etc. copy of unlimited quantity trains Index: BuyTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/BuyTrain.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** BuyTrain.java 24 Jan 2010 16:21:29 -0000 1.14 --- BuyTrain.java 26 Jan 2010 19:50:28 -0000 1.15 *************** *** 117,121 **** --- 117,132 ---- } + /** + * To be used for all usage of train, also within this class. + * After reloading the 2nd copy etc. of a train with unlimited quantity, + * the train attribute will be null (because readObject() is called and the + * train is initiated before the actions have been executed - the second + * train is in this case only created after buying the first one). + * @return + */ public TrainI getTrain() { + if (train == null) { + train = GameManager.getInstance().getTrainManager().getTrainByUniqueId(trainUniqueId); + } return train; } *************** *** 158,166 **** public Portfolio getHolder() { ! return train.getHolder(); } public CashHolder getOwner() { ! return train.getOwner(); } --- 169,177 ---- public Portfolio getHolder() { ! return getTrain().getHolder(); } public CashHolder getOwner() { ! return getTrain().getOwner(); } *************** *** 196,200 **** StringBuffer b = new StringBuffer(); b.append(company.getName()); ! b.append(": buy ").append(train.getName()); b.append("-train from ").append(from.getName()); if (fixedCost > 0) { --- 207,211 ---- StringBuffer b = new StringBuffer(); b.append(company.getName()); ! b.append(": buy ").append(getTrain().getName()); b.append("-train from ").append(from.getName()); if (fixedCost > 0) { *************** *** 224,228 **** if (!(action instanceof BuyTrain)) return false; BuyTrain a = (BuyTrain) action; ! return a.train == train && a.from == from && a.fixedCost == fixedCost && a.trainsForExchange == trainsForExchange; } --- 235,239 ---- if (!(action instanceof BuyTrain)) return false; BuyTrain a = (BuyTrain) action; ! return a.getTrain() == getTrain() && a.from == from && a.fixedCost == fixedCost && a.trainsForExchange == trainsForExchange; } *************** *** 254,257 **** --- 265,269 ---- train = trainManager.getTrainByUniqueId(trainUniqueId); + log.debug("--- Train with uid="+trainUniqueId+" is "+train, new Exception ("X")); from = gameManager.getPortfolioByName(fromName); if (trainsForExchangeUniqueIds != null |