From: <ste...@us...> - 2010-08-12 18:46:15
|
Revision: 1380 http://rails.svn.sourceforge.net/rails/?rev=1380&view=rev Author: stefanfrey Date: 2010-08-12 18:46:08 +0000 (Thu, 12 Aug 2010) Log Message: ----------- Added 1856 THB option for token lay and changed blocked hex token lay implementation Modified Paths: -------------- trunk/18xx/data/1830/CompanyManager.xml trunk/18xx/data/1830/Map.xml trunk/18xx/data/1856/CompanyManager.xml trunk/18xx/data/1856/Game.xml trunk/18xx/rails/game/MapHex.java trunk/18xx/rails/game/PublicCompany.java trunk/18xx/rails/game/PublicCompanyI.java Modified: trunk/18xx/data/1830/CompanyManager.xml =================================================================== --- trunk/18xx/data/1830/CompanyManager.xml 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/data/1830/CompanyManager.xml 2010-08-12 18:46:08 UTC (rev 1380) @@ -87,7 +87,9 @@ </Company> <Company name="Erie" type="Public" tokens="3" fgColour="000000" bgColour="FFFF00" longname="Erie Railroad"> - <Home hex="E11"/> + <!-- city = 0 implies that this is not yet decided (OO-tiles), blocks means that + in each city one slot has to be available --> + <Home hex="E11" city="0" AllCitiesBlocked="yes"/> </Company> <Company name="B&M" type="Public" tokens="2" fgColour="000000" bgColour="60E060" longname="Boston & Maine"> @@ -104,7 +106,7 @@ <IfOption name="Variant" value="Pere Marquette"> <Company name="PM" type="Public" tokens="3" fgColour="FFFF00" bgColour="000080" longname="Pere Marquette"> - <Home hex="E5"/> + <Home hex="E5" city="0" AllCitiesBlocked="yes" /> </Company> </IfOption> <StartPacket roundClass="rails.game.StartRound_1830"> Modified: trunk/18xx/data/1830/Map.xml =================================================================== --- trunk/18xx/data/1830/Map.xml 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/data/1830/Map.xml 2010-08-12 18:46:08 UTC (rev 1380) @@ -36,7 +36,7 @@ <Hex name="E5" tile="-20" label="OO" cost="80"/> <Hex name="E7" tile="-1" impassable="F8"/> <Hex name="E9" tile="-7" orientation="4"/> - <Hex name="E11" tile="-20" label="OO" unlaidHomeBlocksTokens="yes"/> + <Hex name="E11" tile="-20" label="OO"/> <Hex name="E13" tile="0"/> <Hex name="E15" tile="0"/> <Hex name="E17" tile="0" cost="120"/> Modified: trunk/18xx/data/1856/CompanyManager.xml =================================================================== --- trunk/18xx/data/1856/CompanyManager.xml 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/data/1856/CompanyManager.xml 2010-08-12 18:46:08 UTC (rev 1380) @@ -113,7 +113,12 @@ <Destination hex="K8"/> </Company> <Company name="THB" type="Public" tokens="2" fgColour="000000" bgColour="B0B040"> - <Home hex="L15" city="0"/><!-- City to be selected in first turn--> + <IfOption name="1856THBHomeBlocked" value="yes"> + <Home hex="L15" city="0" blockedForAllCities = "yes" /> + </IfOption> + <IfOption name="1856THBHomeBlocked" value="no"> + <Home hex="L15" city="0" blockedForAllCities = "no" /> + </IfOption> <Destination hex="J11"/> </Company> <Company name="BBG" type="Public" tokens="3" fgColour="000000" bgColour="FF8080"> Modified: trunk/18xx/data/1856/Game.xml =================================================================== --- trunk/18xx/data/1856/Game.xml 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/data/1856/Game.xml 2010-08-12 18:46:08 UTC (rev 1380) @@ -9,7 +9,7 @@ <GameOption name="UnlimitedTiles" type="toggle" default="no"/> <GameOption name="LeaveAuctionOnPass" type="toggle" default="no"/> <GameOption name="SeparateSalesAtSamePrice" type="toggle" default="yes"/> - <GameOption name="1856THBHomeBlocked" type="toggle" default="no" /> + <GameOption name="1856THBHomeBlocked" type="toggle" default="yes" /> <GameParameters> <StockRound class="rails.game.specific._1856.StockRound_1856" sequence="SellBuyOrBuySell"> Modified: trunk/18xx/rails/game/MapHex.java =================================================================== --- trunk/18xx/rails/game/MapHex.java 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/rails/game/MapHex.java 2010-08-12 18:46:08 UTC (rev 1380) @@ -1012,46 +1012,60 @@ /** * @return Returns false if no base tokens may yet be laid on this hex and station. + * * NOTE: this method currently only checks for prohibitions caused * by the presence of unlaid home base tokens. * It does NOT (yet) check for free space. * - * Remark: There are the following cases to check - * A) isBlockedForTokenLays is active for the MapHex => return the state of this - * (Example: Erie home base in 1830) - * otherwise - * B) City is decided => check the city if a slot is left (standard) - * C) City is undecided => check all cities if there is a slot left + * + * There are the following cases to check for each company located there + * + * A) City is decided or there is only one city + * => check if the city has a free slot or not + * (examples: NYNH in 1830 for a two city tile, NYC for a one city tile) + * B) City is not decided (example: Erie in 1830) + * two subcases depending on isHomeBlockedForAllCities + * - (true): all cities of the hex have remaining slots available + * - (false): no city of the hex has remaining slots available + * C) Or the company does not block its home city at all (example:Pr in 1835) + * then isBlockedForTokenLays attribute is used + * + * NOTE: It assumes that not two company share the same home city. + * Undecided companies cannot share the same hex with any other company. + * + * Previously used was the variable isBlockedForTokenLays + * which is set to yes to block the whole hex for the token lays + * until the (home) company laid their token + * */ public boolean isBlockedForTokenLays(PublicCompanyI company, int cityNumber) { - if (isHomeFor(company)) + if (isHomeFor(company)) { // Company can always lay a home base return false; - else if (isBlockedForTokenLays != null) { // case A) - // if true: token lay blocked because a required home base is not yet laid - // if false: token lay allowed if there is any free space - // Free space is not checked here (yet) + } else if (isBlockedForTokenLays != null) { + // Return MapHex attribute if defined return isBlockedForTokenLays.booleanValue(); } else if (homes != null && !homes.isEmpty()) { // Check if this token lay does not block an unlaid home base for (PublicCompanyI comp : homes.keySet()) { if (comp.hasLaidHomeBaseTokens() || comp.isClosed()) continue; + // home base not laid yet, define list of cities to check + List<City> citiesToCheck = new ArrayList<City>(); City homeCity = homes.get(comp); - if (homeCity != null) { // case B) - if (cityNumber == homeCity.getNumber() - // Assume that a city is never home to more than one company - && homeCity.getTokens().isEmpty() - && homeCity.getTokenSlotsLeft() < 2) { - return true; + if (homeCity != null) { + citiesToCheck.add(homeCity); + } else { + citiesToCheck.addAll(cities); + } + int tokenSlotsLeft = 0; + for (City city:cities) { + tokenSlotsLeft += city.getTokenSlotsLeft(); + if (comp.isHomeBlockedForAllCities() & city.getTokenSlotsLeft() < 2) { + return true; } - } else { // case C) - int tokenSlotsLeft = 0; - for (City city:cities) { - tokenSlotsLeft += city.getTokenSlotsLeft(); - } - if (tokenSlotsLeft < 2) return true; // not enough tokens left, assume only one company } + if (tokenSlotsLeft < 2) return true; // not enough tokens left, assume only one company } } return false; Modified: trunk/18xx/rails/game/PublicCompany.java =================================================================== --- trunk/18xx/rails/game/PublicCompany.java 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/rails/game/PublicCompany.java 2010-08-12 18:46:08 UTC (rev 1380) @@ -59,6 +59,7 @@ protected String homeHexName = null; protected MapHex homeHex = null; protected int homeCityNumber = 1; + protected boolean homeAllCitiesBlocked = false; /** Destination hex * */ protected String destinationHexName = null; @@ -320,6 +321,7 @@ if (homeBaseTag != null) { homeHexName = homeBaseTag.getAttributeAsString("hex"); homeCityNumber = homeBaseTag.getAttributeAsInteger("city", 1); + homeAllCitiesBlocked = homeBaseTag.getAttributeAsBoolean("allCitiesBlocked", false); } Tag destinationTag = tag.getChild("Destination"); @@ -827,6 +829,15 @@ public void setHomeCityNumber(int number) { this.homeCityNumber = number; } + + /** + * @return true -> requires an open slot in each city of the hex, false -> one slot on the hex + * + */ + public boolean isHomeBlockedForAllCities() { + return homeAllCitiesBlocked; + } + /** * @return Returns the destinationHex. Modified: trunk/18xx/rails/game/PublicCompanyI.java =================================================================== --- trunk/18xx/rails/game/PublicCompanyI.java 2010-08-11 23:21:59 UTC (rev 1379) +++ trunk/18xx/rails/game/PublicCompanyI.java 2010-08-12 18:46:08 UTC (rev 1380) @@ -330,6 +330,7 @@ public int getHomeCityNumber(); public void setHomeCityNumber(int homeCityNumber); + public boolean isHomeBlockedForAllCities(); public MapHex getDestinationHex(); public boolean hasDestination (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |