Content-Type: multipart/mixed; boundary=Apple-Mail-3--823611500 --Apple-Mail-3--823611500 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii See the earlier discussions about the turnbased = tech patch on this list...

Op 21 aug 2010, om = 23:27 heeft Kevin het volgende geschreven:

I would like to add a unit = attachment which will allow certain units to be designated as "special" = where value=3Dturn#. I need a way to prevent the AI from purchasing the = special units in NWO prior to turn 4. This seems like the best way to do = it, unless someone can think of a better way. Thanks.
 
Kevin = Moore
---------------------------------------------------------= ---------------------
This SF.net email is sponsored by 

Make an app they = can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev _____________________________= __________________
Triplea-developers mailing list
Triplea-developer= s@lists.sourceforge.net
h= ttps://lists.sourceforge.net/lists/listinfo/triplea-developers
= --Apple-Mail-3--823611500 Content-Disposition: attachment; filename=TurnBasedTech.patch Content-Type: application/octet-stream; name="TurnBasedTech.patch" Content-Transfer-Encoding: 7bit ### Eclipse Workspace Patch 1.0 #P triplea Index: src/games/strategy/triplea/Properties.java =================================================================== --- src/games/strategy/triplea/Properties.java (revision 2702) +++ src/games/strategy/triplea/Properties.java (working copy) @@ -673,10 +673,13 @@ } } - - - - + public static int getActivateTechOnTurn(GameData data,String techName, String playerName) { + try { + return Integer.parseInt((String) data.getProperties().get("Activate "+techName+" for "+ playerName +" on turn")); + } catch (NumberFormatException e) { + return -1; + } + } private Properties() { } Index: src/games/strategy/triplea/delegate/TurnbasedTechActivationDelegate.java =================================================================== --- src/games/strategy/triplea/delegate/TurnbasedTechActivationDelegate.java (revision 0) +++ src/games/strategy/triplea/delegate/TurnbasedTechActivationDelegate.java (revision 0) @@ -0,0 +1,154 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * TurnBasedTechActivationDelegate.java + * + * Created on February 18th 2010 + */ + +package games.strategy.triplea.delegate; + +import games.strategy.engine.data.*; +import games.strategy.triplea.Properties; +import games.strategy.engine.delegate.*; +import games.strategy.engine.message.IRemote; + +import java.io.Serializable; +import java.util.*; + +/** + * Logic for activating tech based on the turn of the game the player is in. + * + * You can control the turn in which a certain + * + * @author Edwin van der Wal + * @version 0.1 + */ +public class TurnbasedTechActivationDelegate implements IDelegate +{ + + private String m_name; + private String m_displayName; + private GameData m_data; + private IDelegateBridge m_bridge; + private PlayerID m_player; + + /** Creates new TechActivationDelegate */ + public TurnbasedTechActivationDelegate() + { + } + + public void initialize(String name, String displayName) + { + m_name = name; + m_displayName = displayName; + } + + /** + * Called before the delegate will run. In this class, this does all the + * work. + */ + public void start(IDelegateBridge aBridge, GameData gameData) + { + m_bridge = aBridge; + m_data = gameData; + m_player = aBridge.getPlayerID(); + List advances = new ArrayList(); + Iterator allAdvances = TechAdvance.getTechAdvances(gameData).iterator(); + + while(allAdvances.hasNext()) { + TechAdvance advance = allAdvances.next(); + if(Properties.getActivateTechOnTurn(gameData,advance.getProperty(),m_player.getName()) == gameData.getSequence().getRound()) + advances.add(advance); + } + + if ((advances != null) && (advances.size() > 0)) + { + // Start event + m_bridge.getHistoryWriter().startEvent(m_player.getName() + " activating " + advancesAsString(advances)); + + Iterator techsIter = advances.iterator(); + while (techsIter.hasNext()) + { + TechAdvance advance = techsIter.next(); + advance.perform(m_bridge.getPlayerID(), m_bridge, m_data); + TechTracker.addAdvance(m_player, m_data, m_bridge, advance); + } + } + } + + + // Return string representing all advances in collection + private String advancesAsString(Collection advances) + { + Iterator iter = advances.iterator(); + int count = advances.size(); + StringBuilder text = new StringBuilder(); + + while (iter.hasNext()) + { + TechAdvance advance = (TechAdvance) iter.next(); + text.append(advance.getName()); + count--; + if (count > 1) + text.append(", "); + if (count == 1) + text.append(" and "); + } + return text.toString(); + } + + public String getName() + { + return m_name; + } + + public String getDisplayName() + { + return m_displayName; + } + + /** + * Called before the delegate will stop running. + */ + public void end() + { + } + + /** + * Returns the state of the Delegate. + */ + public Serializable saveState() + { + return null; + } + + /** + * Loads the delegates state + */ + public void loadState(Serializable state) + { + + } + + /* + * @see games.strategy.engine.delegate.IDelegate#getRemoteType() + */ + public Class getRemoteType() + { + return null; + } + +} \ No newline at end of file --Apple-Mail-3--823611500 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
--Apple-Mail-3--823611500--