merge latest trunk

This commit is contained in:
myk
2013-03-09 06:34:18 +00:00
12 changed files with 123 additions and 52 deletions

View File

@@ -86,6 +86,17 @@ public class RepeatEachAi extends SpellAbilityAi {
}
tgt.addTarget(list.get(0));
} else if ("BalanceLands".equals(logic)) {
if (CardLists.filter(aiPlayer.getCardsIn(ZoneType.Battlefield), Presets.LANDS).size() >= 5) {
return false;
}
List<Player> opponents = aiPlayer.getOpponents();
for(Player opp : opponents) {
if (CardLists.filter(opp.getCardsIn(ZoneType.Battlefield), Presets.LANDS).size() < 4) {
return false;
}
}
}
// TODO Add some normal AI variability here

View File

@@ -0,0 +1,41 @@
package forge.game;
import forge.error.BugReporter;
import forge.gui.match.controllers.CMessage;
/**
* TODO: Write javadoc for this type.
*
*/
public final class GameInputUpdatesThread extends Thread {
private final MatchController match;
private final GameState game;
private boolean wasChangedRecently;
/**
* TODO: Write javadoc for Constructor.
* @param match
* @param game
*/
public GameInputUpdatesThread(MatchController match, GameState game) {
this.match = match;
this.game = game;
}
public void run(){
while(!game.isGameOver()) {
boolean needsNewInput = CMessage.SINGLETON_INSTANCE.getInputControl().isValid() == false;
if ( needsNewInput ) {
match.getInput().setNewInput(game);
wasChangedRecently = true;
}
try {
Thread.sleep(wasChangedRecently ? 2 : 40);
wasChangedRecently = false;
} catch (InterruptedException e) {
BugReporter.reportException(e);
break;
}
}
}
}

View File

@@ -25,7 +25,6 @@ import forge.card.trigger.TriggerType;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.error.BugReporter;
import forge.game.event.FlipCoinEvent;
import forge.game.phase.PhaseHandler;
import forge.game.player.AIPlayer;
@@ -33,7 +32,6 @@ import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType;
import forge.gui.match.controllers.CMessage;
import forge.gui.match.views.VAntes;
import forge.item.CardPrinted;
import forge.item.IPaperCard;
@@ -48,43 +46,6 @@ import forge.util.MyRandom;
*/
public class GameNew {
/**
* TODO: Write javadoc for this type.
*
*/
public static final class GameInputUpdatesThread extends Thread {
private final MatchController match;
private final GameState game;
private boolean wasChangedRecently;
/**
* TODO: Write javadoc for Constructor.
* @param match
* @param game
*/
public GameInputUpdatesThread(MatchController match, GameState game) {
this.match = match;
this.game = game;
}
public void run(){
while(!game.isGameOver()) {
boolean needsNewInput = CMessage.SINGLETON_INSTANCE.getInputControl().isValid() == false;
if ( needsNewInput ) {
match.getInput().setNewInput(game);
wasChangedRecently = true;
}
try {
Thread.sleep(wasChangedRecently ? 2 : 40);
wasChangedRecently = false;
} catch (InterruptedException e) {
BugReporter.reportException(e);
break;
}
}
}
}
public static final ForgePreferences preferences = Singletons.getModel().getPreferences();
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
@@ -233,10 +194,6 @@ public class GameNew {
for (final Player p1 : game.getPlayers()) {
p1.drawCards(p1.getMaxHandSize());
}
Thread thGame = new GameInputUpdatesThread(match, game);
thGame.setName("Game input updater");
thGame.start();
}
// ultimate of Karn the Liberated

View File

@@ -287,7 +287,7 @@ public class GameState {
/**
* @return the gameOver
*/
public boolean isGameOver() {
public synchronized boolean isGameOver() {
return gameOver;
}
@@ -295,7 +295,7 @@ public class GameState {
* @param reason
* @param go the gameOver to set
*/
public void setGameOver(GameEndReason reason) {
public synchronized void setGameOver(GameEndReason reason) {
this.gameOver = true;
for (Player p : roIngamePlayers) {
p.onGameOver();

View File

@@ -157,6 +157,10 @@ public class MatchController {
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
GameNew.newGame(this, startConditions, currentGame, canRandomFoil);
Thread thGame = new GameInputUpdatesThread(this, currentGame);
thGame.setName("Game input updater");
thGame.start();
// TODO restore this functionality!!!
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
for (final VField field : VMatchUI.SINGLETON_INSTANCE.getFieldViews()) {

View File

@@ -38,10 +38,10 @@ public class InputProxy extends MyObservable implements Observer {
/** The input. */
private Input input;
private volatile boolean valid = false;
private boolean valid = false;
@Override
public final void update(final Observable observable, final Object obj) {
public final synchronized void update(final Observable observable, final Object obj) {
valid = false;
}
/**
@@ -52,7 +52,7 @@ public class InputProxy extends MyObservable implements Observer {
* @param in
* a {@link forge.control.input.Input} object.
*/
public final void setInput(final Input in) {
public final synchronized void setInput(final Input in) {
valid = true;
this.input = in;
this.input.showMessage(); // this call may invalidate the input by the time it returns
@@ -114,7 +114,7 @@ public class InputProxy extends MyObservable implements Observer {
}
public boolean isValid() {
public synchronized boolean isValid() {
return valid;
}
}