From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java CGRFormationRound.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** CGRFormationRound.java 15 Apr 2010 19:49:50 -0000 1.34 --- CGRFormationRound.java 15 May 2010 16:36:09 -0000 1.35 *************** *** 72,76 **** // Collect companies having loans ! for (PublicCompanyI company : getOperatingCompanies()) { if (company.getCurrentNumberOfLoans() > 0) { if (companiesToRepayLoans == null) { --- 72,76 ---- // Collect companies having loans ! for (PublicCompanyI company : setOperatingCompanies()) { if (company.getCurrentNumberOfLoans() > 0) { if (companiesToRepayLoans == null) { Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** OperatingRound_1856.java 22 Apr 2010 19:09:58 -0000 1.35 --- OperatingRound_1856.java 15 May 2010 16:36:09 -0000 1.36 *************** *** 47,105 **** protected boolean setNextOperatingCompany(boolean initial) { ! ! if (operatingCompanyIndexObject == null) { ! operatingCompanyIndexObject = ! new IntegerState("OperatingCompanyIndex"); ! } ! while (true) { ! if (initial) { ! operatingCompanyIndexObject.set(0); initial = false; } else { ! operatingCompanyIndexObject.add(1); } ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); ! ! if (operatingCompanyIndex >= operatingCompanyArray.length) { ! return false; ! } else { ! operatingCompany = operatingCompanyArray[operatingCompanyIndex]; ! // 1856 special: check if the company has sold enough shares to operate ! // This check does not apply to the CGR ! if (operatingCompany instanceof PublicCompany_CGR) return true; ! ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { ! int soldPercentage = getSoldPercentage (operatingCompany); ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); ! int trainNumber; ! try { ! trainNumber = Integer.parseInt(nextAvailableTrain.getName()); ! } catch (NumberFormatException e) { ! trainNumber = 6; // Diesel! ! } ! int floatPercentage = 10 * trainNumber; ! log.debug ("Float percentage is "+floatPercentage ! +" sold percentage is "+soldPercentage); - if (soldPercentage < floatPercentage) { - DisplayBuffer.add(LocalText.getText("MayNotYetOperate", - operatingCompany.getName(), - String.valueOf(soldPercentage), - String.valueOf(floatPercentage) - )); - // Company may not yet operate - continue; - } } - return true; } } } --- 47,97 ---- protected boolean setNextOperatingCompany(boolean initial) { ! //log.debug("+++ old OC is "+(operatingCompany!=null?operatingCompany.getName():"null")); while (true) { ! if (initial || operatingCompany == null || operatingCompanyObject == null) { ! setOperatingCompany(operatingCompanies.get(0)); initial = false; } else { ! int index = operatingCompanies.indexOf(operatingCompany); ! if (++index >= operatingCompanies.size()) { ! return false; ! } ! setOperatingCompany(operatingCompanies.get(index)); } ! // 1856 special: check if the company has sold enough shares to operate ! // This check does not apply to the CGR ! if (operatingCompany instanceof PublicCompany_CGR) return true; ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { ! int soldPercentage = getSoldPercentage (operatingCompany); ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); ! int trainNumber; ! try { ! trainNumber = Integer.parseInt(nextAvailableTrain.getName()); ! } catch (NumberFormatException e) { ! trainNumber = 6; // Diesel! ! } ! int floatPercentage = 10 * trainNumber; + log.debug ("Float percentage is "+floatPercentage + +" sold percentage is "+soldPercentage); + if (soldPercentage < floatPercentage) { + DisplayBuffer.add(LocalText.getText("MayNotYetOperate", + operatingCompany.getName(), + String.valueOf(soldPercentage), + String.valueOf(floatPercentage) + )); + // Company may not yet operate + continue; } } + //log.debug("+++ new OC is "+(operatingCompany!=null?operatingCompany.getName():"null")); + return true; } } *************** *** 278,282 **** List<PublicCompanyI> possibleDestinations = new ArrayList<PublicCompanyI>(); ! for (PublicCompanyI comp : operatingCompanyArray) { if (comp.hasDestination() && ((PublicCompany_1856)comp).getTrainNumberAvailableAtStart() < 5 --- 270,274 ---- List<PublicCompanyI> possibleDestinations = new ArrayList<PublicCompanyI>(); ! for (PublicCompanyI comp : operatingCompanies) { if (comp.hasDestination() && ((PublicCompany_1856)comp).getTrainNumberAvailableAtStart() < 5 *************** *** 473,477 **** if (!resetOperatingCompanies(mergingCompanies)) return; ! if (operatingCompany != null) { setStep(GameDef.OrStep.INITIAL); } else { --- 465,469 ---- if (!resetOperatingCompanies(mergingCompanies)) return; ! if (getOperatingCompany() != null) { setStep(GameDef.OrStep.INITIAL); } else { *************** *** 483,490 **** private boolean resetOperatingCompanies(List<PublicCompanyI> mergingCompanies) { - List<PublicCompanyI> companies - = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); PublicCompanyI cgr = companyManager.getPublicCompany(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); for (PublicCompanyI company : mergingCompanies) { --- 475,481 ---- private boolean resetOperatingCompanies(List<PublicCompanyI> mergingCompanies) { PublicCompanyI cgr = companyManager.getPublicCompany(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); + boolean roundFinished = false; for (PublicCompanyI company : mergingCompanies) { *************** *** 494,499 **** // Find the first company that has not yet operated // and is not closed. ! while (setNextOperatingCompany(false) ! && operatingCompany.isClosed()); // Remove closed companies from the operating company list --- 485,490 ---- // Find the first company that has not yet operated // and is not closed. ! //while (setNextOperatingCompany(false) ! // && operatingCompany.isClosed()); // Remove closed companies from the operating company list *************** *** 510,514 **** //} ! for (PublicCompanyI c : companies) { if (c.isClosed()) { log.info(c.getName()+" is closed"); --- 501,505 ---- //} ! for (PublicCompanyI c : operatingCompanies) { if (c.isClosed()) { log.info(c.getName()+" is closed"); *************** *** 519,536 **** String message; ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); if (cgr.hasStarted()) { if (cgrCanOperate) { operatingCompanyIndex = Math.max (0, operatingCompanyIndex); ! companies.add(operatingCompanyIndex, cgr); ! operatingCompany = cgr; ! operatingCompanyIndex = companies.indexOf(operatingCompany); message = LocalText.getText("CanOperate", cgr.getName()); } else { message = LocalText.getText("CannotOperate", cgr.getName()); ! // Find the first company that has not yet operated ! // and is not closed. ! while (setNextOperatingCompany(false) ! && operatingCompany.isClosed()); } } else { --- 510,523 ---- String message; ! int operatingCompanyIndex = getOperatingCompanyIndex(); if (cgr.hasStarted()) { if (cgrCanOperate) { operatingCompanyIndex = Math.max (0, operatingCompanyIndex); ! operatingCompanies.add(operatingCompanyIndex, cgr); ! setOperatingCompany(cgr); message = LocalText.getText("CanOperate", cgr.getName()); } else { message = LocalText.getText("CannotOperate", cgr.getName()); ! roundFinished = !setNextOperatingCompany(false); } } else { *************** *** 543,550 **** DisplayBuffer.add(message); ! operatingCompanyArray = companies.toArray(new PublicCompanyI[0]); ! ! if (operatingCompanyIndex < operatingCompanyArray.length) { ! operatingCompanyIndexObject.set(operatingCompanyIndex); log.debug ("Next operating company: "+operatingCompany.getName()); } else { --- 530,536 ---- DisplayBuffer.add(message); ! // Find the first company that has not yet operated ! // and is not closed. ! if (!roundFinished) { log.debug ("Next operating company: "+operatingCompany.getName()); } else { |