From: <ste...@us...> - 2011-07-07 04:57:01
|
Revision: 1608 http://rails.svn.sourceforge.net/rails/?rev=1608&view=rev Author: stefanfrey Date: 2011-07-07 04:56:55 +0000 (Thu, 07 Jul 2011) Log Message: ----------- Added support for Rights in Revenue Calculation. Important ToDo: Still hardcoded rights location. Modified Paths: -------------- trunk/18xx/data/1830/Game.xml trunk/18xx/rails/game/PublicCompany.java trunk/18xx/rails/game/special/SpecialRight.java Modified: trunk/18xx/data/1830/Game.xml =================================================================== --- trunk/18xx/data/1830/Game.xml 2011-07-07 04:53:35 UTC (rev 1607) +++ trunk/18xx/data/1830/Game.xml 2011-07-07 04:56:55 UTC (rev 1608) @@ -240,4 +240,7 @@ <Tiles colour="yellow,green,brown"/> </Phase> </Component> + <Component name="RevenueManager" class="rails.algorithms.RevenueManager"> +<!-- Required for coalfield rights '--> + </Component> </ComponentManager> \ No newline at end of file Modified: trunk/18xx/rails/game/PublicCompany.java =================================================================== --- trunk/18xx/rails/game/PublicCompany.java 2011-07-07 04:53:35 UTC (rev 1607) +++ trunk/18xx/rails/game/PublicCompany.java 2011-07-07 04:56:55 UTC (rev 1608) @@ -768,6 +768,8 @@ // Initialize rights here to prevent overhead if not used, // but if rights are used, the GUI needs it from the start. if (rights == null) rights = new HashMapState<String, String>(name+"_Rights"); + // TODO: This is only a workaround for the missing finishConfiguration of special properties (SFY) + sp.finishConfiguration(gameManager); } } } Modified: trunk/18xx/rails/game/special/SpecialRight.java =================================================================== --- trunk/18xx/rails/game/special/SpecialRight.java 2011-07-07 04:53:35 UTC (rev 1607) +++ trunk/18xx/rails/game/special/SpecialRight.java 2011-07-07 04:56:55 UTC (rev 1608) @@ -1,13 +1,19 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/special/SpecialRight.java,v 1.19 2010/05/05 21:37:18 evos Exp $ */ package rails.game.special; +import java.util.Set; + +import rails.algorithms.NetworkVertex; +import rails.algorithms.RevenueAdapter; +import rails.algorithms.RevenueBonus; +import rails.algorithms.RevenueStaticModifier; import rails.common.LocalText; import rails.common.parser.ConfigurationException; import rails.common.parser.Tag; import rails.game.*; import rails.util.*; -public class SpecialRight extends SpecialProperty { +public class SpecialRight extends SpecialProperty implements RevenueStaticModifier { /** The public company of which a share can be obtained. */ protected String rightName; @@ -35,6 +41,14 @@ cost = rightTag.getAttributeAsInteger("cost", 0); } + @Override + public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { + super.finishConfiguration(gameManager); + + // add them to the call list of the RevenueManager + gameManager.getRevenueManager().addStaticModifier(this); + } + public boolean isExecutionable() { return originalCompany.getPortfolio().getOwner() instanceof Player; @@ -76,4 +90,18 @@ public String getInfo() { return toMenu(); } + + /** + * modify revenue calculation of the + * TODO: rights is missing a location field, currently hardcoded for 1830 coalfields + */ + public void modifyCalculator(RevenueAdapter revenueAdapter) { + // 1. check operating company if it has the right then it is excluded from the removal + if (revenueAdapter.getCompany().hasRight(rightName)) return; + + // 2. find vertices to hex and remove those + MapHex hex = GameManager.getInstance().getMapManager().getHex("L10"); + Set<NetworkVertex> verticesToRemove = NetworkVertex.getVerticesByHex(revenueAdapter.getVertices(), hex); + revenueAdapter.getGraph().removeAllVertices(verticesToRemove); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |