Remove trailing whitespace throughout, and then widen/vararg/foreachize some
card game stuff that we were looking at. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@804 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -34,8 +34,7 @@ import com.threerings.parlor.turn.client.TurnGameController;
|
||||
import static com.threerings.parlor.card.Log.log;
|
||||
|
||||
/**
|
||||
* A controller class for card games. Handles common functions like
|
||||
* accepting dealt hands.
|
||||
* A controller class for card games. Handles common functions like accepting dealt hands.
|
||||
*/
|
||||
public abstract class CardGameController extends GameController
|
||||
implements TurnGameController, CardCodes, CardGameReceiver
|
||||
@@ -50,8 +49,7 @@ public abstract class CardGameController extends GameController
|
||||
Thread.dumpStack();
|
||||
}
|
||||
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(
|
||||
new CardGameDecoder(this));
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(new CardGameDecoder(this));
|
||||
|
||||
super.willEnterPlace(plobj);
|
||||
}
|
||||
@@ -61,8 +59,7 @@ public abstract class CardGameController extends GameController
|
||||
{
|
||||
super.didLeavePlace(plobj);
|
||||
|
||||
_ctx.getClient().getInvocationDirector().unregisterReceiver(
|
||||
CardGameDecoder.RECEIVER_CODE);
|
||||
_ctx.getClient().getInvocationDirector().unregisterReceiver(CardGameDecoder.RECEIVER_CODE);
|
||||
}
|
||||
|
||||
// Documentation inherited.
|
||||
@@ -80,8 +77,8 @@ public abstract class CardGameController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server deals the client a new hand of cards. Default
|
||||
* implementation does nothing.
|
||||
* Called when the server deals the client a new hand of cards. Default implementation does
|
||||
* nothing.
|
||||
*
|
||||
* @param hand the hand dealt to the user
|
||||
*/
|
||||
@@ -89,8 +86,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when it has received a set of cards
|
||||
* from another player. Default implementation does nothing.
|
||||
* Dispatched to the client when it has received a set of cards from another player. Default
|
||||
* implementation does nothing.
|
||||
*
|
||||
* @param plidx the index of the player providing the cards
|
||||
* @param cards the cards received
|
||||
@@ -99,9 +96,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when the server has forced it to send
|
||||
* a set of cards to another player. Default implementation does
|
||||
* nothing.
|
||||
* Dispatched to the client when the server has forced it to send a set of cards to another
|
||||
* player. Default implementation does nothing.
|
||||
*
|
||||
* @param plidx the index of the player to which the cards were sent
|
||||
* @param cards the cards sent
|
||||
@@ -110,8 +106,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when a set of cards is transferred between
|
||||
* two other players in the game. Default implementation does nothing.
|
||||
* Dispatched to the client when a set of cards is transferred between two other players in
|
||||
* the game. Default implementation does nothing.
|
||||
*
|
||||
* @param fromidx the index of the player sending the cards
|
||||
* @param toidx the index of the player receiving the cards
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param hand the received hand
|
||||
*/
|
||||
public void receivedHand (int oid, Hand hand);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when it has received a set of cards
|
||||
* from another player.
|
||||
@@ -48,7 +48,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param cards the cards received
|
||||
*/
|
||||
public void receivedCardsFromPlayer (int plidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when the server has forced it to send
|
||||
* a set of cards to another player.
|
||||
@@ -57,7 +57,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param cards the cards sent
|
||||
*/
|
||||
public void sentCardsToPlayer (int plidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when a set of cards is transferred between
|
||||
* two other players in the game.
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the drag
|
||||
*/
|
||||
public void cardSpriteClicked (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user moved the mouse pointer onto
|
||||
* a card sprite.
|
||||
@@ -44,7 +44,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the entrance
|
||||
*/
|
||||
public void cardSpriteEntered (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user moved the mouse pointer off of
|
||||
* a card sprite.
|
||||
@@ -53,7 +53,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the exit
|
||||
*/
|
||||
public void cardSpriteExited (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user dragged a card sprite to a new
|
||||
* location.
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
*/
|
||||
public Card ()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
@@ -46,10 +46,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
_value = (byte)((suit << 5) | number);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the card, either from 2 to 11 or
|
||||
* KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER.
|
||||
* Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or
|
||||
* BLACK_JOKER.
|
||||
*
|
||||
* @return the value of the card
|
||||
*/
|
||||
@@ -57,10 +57,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return (_value & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or
|
||||
* CLUBS. If the card is the joker, the suit is undefined.
|
||||
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS. If the card is the joker,
|
||||
* the suit is undefined.
|
||||
*
|
||||
* @return the suit of the card
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return (_value >> 5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a number card (2 to 10).
|
||||
*
|
||||
@@ -77,10 +77,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isNumber ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number >= 2 && number <= 10;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a face card (KING, QUEEN, or JACK).
|
||||
*
|
||||
@@ -89,10 +89,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isFace ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number == KING || number == QUEEN || number == JACK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is an ace.
|
||||
*
|
||||
@@ -102,7 +102,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return getNumber() == ACE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a joker.
|
||||
*
|
||||
@@ -111,41 +111,41 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isJoker ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number == RED_JOKER || number == BLACK_JOKER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether or not this card is valid. The no-arg public
|
||||
* constructor for deserialization creates an invalid card.
|
||||
* Checks whether or not this card is valid. The no-arg public constructor for deserialization
|
||||
* creates an invalid card.
|
||||
*
|
||||
* @return true if this card is valid, false if not
|
||||
*/
|
||||
public boolean isValid ()
|
||||
{
|
||||
int number = getNumber(), suit = getSuit();
|
||||
|
||||
|
||||
return number == RED_JOKER || number == BLACK_JOKER ||
|
||||
(number >= 2 && number <= ACE &&
|
||||
suit >= SPADES && suit <= DIAMONDS);
|
||||
}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
if (_key == null) {
|
||||
_key = Byte.valueOf(_value);
|
||||
}
|
||||
|
||||
|
||||
return _key;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode ()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other)
|
||||
{
|
||||
@@ -156,21 +156,20 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares this card to another. The card order is the same as the
|
||||
* initial deck ordering: two through ten, jack, queen, king, ace for
|
||||
* spades, hearts, clubs, and diamonds, then the red joker and the
|
||||
* black joker.
|
||||
* Compares this card to another. The card order is the same as the initial deck ordering: two
|
||||
* through ten, jack, queen, king, ace for spades, hearts, clubs, and diamonds, then the red
|
||||
* joker and the black joker.
|
||||
*
|
||||
* @param other the other card to compare this to
|
||||
* @return -1, 0, or +1, depending on whether this card is less than,
|
||||
* equal to, or greater than the other card
|
||||
* @return -1, 0, or +1, depending on whether this card is less than, equal to, or greater
|
||||
* than the other card
|
||||
*/
|
||||
public int compareTo (Card other)
|
||||
{
|
||||
int otherValue = other._value;
|
||||
|
||||
|
||||
if (_value > otherValue) {
|
||||
return +1;
|
||||
} else if(_value < otherValue) {
|
||||
@@ -179,12 +178,12 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
if (number == RED_JOKER) {
|
||||
return "RJ";
|
||||
}
|
||||
@@ -193,7 +192,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
}
|
||||
else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
if (number >= 2 && number <= 9) {
|
||||
sb.append(Integer.toString(number));
|
||||
}
|
||||
@@ -207,7 +206,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
default: sb.append('?'); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (getSuit()) {
|
||||
case SPADES: sb.append('s'); break;
|
||||
case HEARTS: sb.append('h'); break;
|
||||
@@ -215,14 +214,14 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
case DIAMONDS: sb.append('d'); break;
|
||||
default: sb.append('?'); break;
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** The number of the card. */
|
||||
protected byte _value;
|
||||
|
||||
|
||||
/** The comparison key. */
|
||||
@ActionScript(omit=true)
|
||||
protected transient Byte _key;
|
||||
|
||||
@@ -30,31 +30,31 @@ public interface CardCodes extends InvocationCodes
|
||||
{
|
||||
/** The suit of spades. */
|
||||
public static final int SPADES = 0;
|
||||
|
||||
|
||||
/** The suit of hearts. */
|
||||
public static final int HEARTS = 1;
|
||||
|
||||
|
||||
/** The suit of clubs. */
|
||||
public static final int CLUBS = 2;
|
||||
|
||||
|
||||
/** The suit of diamonds. */
|
||||
public static final int DIAMONDS = 3;
|
||||
|
||||
|
||||
/** The number of the jack. */
|
||||
public static final int JACK = 11;
|
||||
|
||||
|
||||
/** The number of the queen. */
|
||||
public static final int QUEEN = 12;
|
||||
|
||||
|
||||
/** The number of the king. */
|
||||
public static final int KING = 13;
|
||||
|
||||
|
||||
/** The number of the ace. */
|
||||
public static final int ACE = 14;
|
||||
|
||||
|
||||
/** The number of the red joker. */
|
||||
public static final int RED_JOKER = 15;
|
||||
|
||||
|
||||
/** The number of the black joker. */
|
||||
public static final int BLACK_JOKER = 16;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,16 @@ public class PlayerCard implements Streamable
|
||||
{
|
||||
/** The index of the player. */
|
||||
public int pidx;
|
||||
|
||||
|
||||
/** The card that the player played. */
|
||||
public Card card;
|
||||
|
||||
|
||||
/**
|
||||
* No-argument constructor for deserialization.
|
||||
*/
|
||||
public PlayerCard ()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new player card.
|
||||
*
|
||||
|
||||
@@ -36,8 +36,8 @@ import com.threerings.parlor.game.server.GameManager;
|
||||
import com.threerings.parlor.turn.server.TurnGameManager;
|
||||
|
||||
/**
|
||||
* A manager class for card games. Handles common functions like dealing
|
||||
* hands of cards to all players.
|
||||
* A manager class for card games. Handles common functions like dealing hands of cards to all
|
||||
* players.
|
||||
*/
|
||||
public class CardGameManager extends GameManager
|
||||
implements TurnGameManager, CardCodes
|
||||
@@ -48,15 +48,15 @@ public class CardGameManager extends GameManager
|
||||
super.didStartup();
|
||||
_cardgameobj = (CardGameObject)_gameobj;
|
||||
}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnWillStart ()
|
||||
{}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnDidStart ()
|
||||
{}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnDidEnd ()
|
||||
{}
|
||||
@@ -72,9 +72,8 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be called to start a rematched game. It just starts the
|
||||
* current game anew, but provides a mechanism for derived classes to
|
||||
* do special things when there is a rematch.
|
||||
* This should be called to start a rematched game. It just starts the current game anew, but
|
||||
* provides a mechanism for derived classes to do special things when there is a rematch.
|
||||
*/
|
||||
public void rematchGame ()
|
||||
{
|
||||
@@ -86,10 +85,9 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes can override this method and take any action needed
|
||||
* prior to a game rematch. If the rematch needs to be vetoed for any
|
||||
* reason, they can return false from this method and the rematch will
|
||||
* be aborted.
|
||||
* Derived classes can override this method and take any action needed prior to a game
|
||||
* rematch. If the rematch needs to be vetoed for any reason, they can return false from this
|
||||
* method and the rematch will be aborted.
|
||||
*/
|
||||
protected boolean gameWillRematch ()
|
||||
{
|
||||
@@ -97,14 +95,13 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Deals a hand of cards to the player at the specified index from
|
||||
* the given Deck.
|
||||
* Deals a hand of cards to the player at the specified index from the given Deck.
|
||||
*
|
||||
* @param deck the deck from which to deal
|
||||
* @param size the size of the hand to deal
|
||||
* @param playerIndex the index of the target player
|
||||
* @return the hand dealt to the player, or null if the deal
|
||||
* was canceled because the deck did not contain enough cards
|
||||
* @return the hand dealt to the player, or null if the deal was canceled because the deck did
|
||||
* not contain enough cards
|
||||
*/
|
||||
public Hand dealHand (Deck deck, int size, int playerIndex)
|
||||
{
|
||||
@@ -122,16 +119,14 @@ public class CardGameManager extends GameManager
|
||||
return hand;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deals a hand of cards to each player from the specified
|
||||
* Deck.
|
||||
* Deals a hand of cards to each player from the specified Deck.
|
||||
*
|
||||
* @param deck the deck from which to deal
|
||||
* @param size the size of the hands to deal
|
||||
* @return the array of hands dealt to each player, or null if
|
||||
* the deal was canceled because the deck did not contain enough
|
||||
* cards
|
||||
* @return the array of hands dealt to each player, or null if the deal was canceled because
|
||||
* the deck did not contain enough cards
|
||||
*/
|
||||
public Hand[] dealHands (Deck deck, int size)
|
||||
{
|
||||
@@ -140,20 +135,18 @@ public class CardGameManager extends GameManager
|
||||
|
||||
} else {
|
||||
Hand[] hands = new Hand[_playerCount];
|
||||
|
||||
|
||||
for (int i=0;i<_playerCount;i++) {
|
||||
hands[i] = dealHand(deck, size, i);
|
||||
hands[i] = dealHand(deck, size, i);
|
||||
}
|
||||
|
||||
|
||||
return hands;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player index of the specified client object, or -1
|
||||
* if the client object does not represent a player. If the game has ended,
|
||||
* looks through the players of the now-ended game.
|
||||
*
|
||||
* Gets the player index of the specified client object, or -1 if the client object does not
|
||||
* represent a player. If the game has ended, looks through the players of the now-ended game.
|
||||
*/
|
||||
public int getPlayerIndex (ClientObject client)
|
||||
{
|
||||
@@ -167,21 +160,21 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the client object corresponding to the specified player index,
|
||||
* or null if the position is not occupied by a player.
|
||||
* Returns the client object corresponding to the specified player index, or null if the
|
||||
* position is not occupied by a player.
|
||||
*/
|
||||
public ClientObject getClientObject (int pidx)
|
||||
{
|
||||
if (_playerOids[pidx] != 0) {
|
||||
return (ClientObject)_omgr.getObject(_playerOids[pidx]);
|
||||
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a set of cards from one player to another.
|
||||
*
|
||||
@@ -197,51 +190,47 @@ public class CardGameManager extends GameManager
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards);
|
||||
}
|
||||
|
||||
|
||||
// Notify the receiver with the cards
|
||||
ClientObject toClient = getClientObject(toPlayerIdx);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx,
|
||||
cards);
|
||||
}
|
||||
|
||||
|
||||
// and everybody else in the room other than the sender and the
|
||||
// receiver with the number of cards sent
|
||||
notifyCardsTransferred(fromPlayerIdx, toPlayerIdx, cards.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends sets of cards between players simultaneously. Each player is
|
||||
* guaranteed to receive the notification of cards received after the
|
||||
* notification of cards sent. The length of the arrays passed must
|
||||
* be equal to the player count.
|
||||
* Sends sets of cards between players simultaneously. Each player is guaranteed to receive
|
||||
* the notification of cards received after the notification of cards sent. The length of the
|
||||
* arrays passed must be equal to the player count.
|
||||
*
|
||||
* @param toPlayerIndices for each player, the index of the player to
|
||||
* transfer cards to
|
||||
* @param toPlayerIndices for each player, the index of the player to transfer cards to
|
||||
* @param cards for each player, the cards to transfer
|
||||
*/
|
||||
public void transferCardsBetweenPlayers (int[] toPlayerIndices,
|
||||
Card[][] cards)
|
||||
public void transferCardsBetweenPlayers (int[] toPlayerIndices, Card[][] cards)
|
||||
{
|
||||
// Send all removal notices
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
ClientObject fromClient = getClientObject(i);
|
||||
for (int ii = 0; ii < _playerCount; ii++) {
|
||||
ClientObject fromClient = getClientObject(ii);
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient,
|
||||
toPlayerIndices[i], cards[i]);
|
||||
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIndices[ii], cards[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send all addition notices and notify everyone else
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
ClientObject toClient = getClientObject(toPlayerIndices[i]);
|
||||
for (int ii = 0; ii < _playerCount; ii++) {
|
||||
ClientObject toClient = getClientObject(toPlayerIndices[ii]);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]);
|
||||
CardGameSender.sendCardsFromPlayer(toClient, ii, cards[ii]);
|
||||
}
|
||||
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
|
||||
notifyCardsTransferred(ii, toPlayerIndices[ii], cards[ii].length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notifies everyone in the room (other than the sender and the receiver) that a set of cards
|
||||
* have been transferred.
|
||||
@@ -250,8 +239,8 @@ public class CardGameManager extends GameManager
|
||||
* @param toPlayerIdx the index of the player receiving the cards
|
||||
* @param cards the number of cards sent
|
||||
*/
|
||||
protected void notifyCardsTransferred (final int fromPlayerIdx,
|
||||
final int toPlayerIdx, final int cards)
|
||||
protected void notifyCardsTransferred (
|
||||
final int fromPlayerIdx, final int toPlayerIdx, final int cards)
|
||||
{
|
||||
final int senderOid = _playerOids[fromPlayerIdx],
|
||||
receiverOid = _playerOids[toPlayerIdx];
|
||||
@@ -269,7 +258,7 @@ public class CardGameManager extends GameManager
|
||||
};
|
||||
applyToOccupants(op);
|
||||
}
|
||||
|
||||
|
||||
/** The card game object. */
|
||||
protected CardGameObject _cardgameobj;
|
||||
|
||||
|
||||
+3
-5
@@ -25,8 +25,7 @@ import com.threerings.parlor.card.client.CardGameController;
|
||||
import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
|
||||
|
||||
/**
|
||||
* A card game controller delegate for trick-based card games, such as
|
||||
* Spades and Hearts.
|
||||
* A card game controller delegate for trick-based card games, such as Spades and Hearts.
|
||||
*/
|
||||
public class TrickCardGameControllerDelegate
|
||||
extends TurnGameControllerDelegate
|
||||
@@ -36,13 +35,12 @@ public class TrickCardGameControllerDelegate
|
||||
*
|
||||
* @param controller the game controller
|
||||
*/
|
||||
public TrickCardGameControllerDelegate (CardGameController
|
||||
controller)
|
||||
public TrickCardGameControllerDelegate (CardGameController controller)
|
||||
{
|
||||
super(controller);
|
||||
_cgctrl = controller;
|
||||
}
|
||||
|
||||
|
||||
/** The card game controller. */
|
||||
protected CardGameController _cgctrl;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface TrickCardGameService extends InvocationService
|
||||
* @param cards the cards to send
|
||||
*/
|
||||
public void sendCardsToPlayer (Client client, int toidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Plays a card in the trick.
|
||||
*
|
||||
@@ -49,7 +49,7 @@ public interface TrickCardGameService extends InvocationService
|
||||
* that the request is for the current trick
|
||||
*/
|
||||
public void playCard (Client client, Card card, int handSize);
|
||||
|
||||
|
||||
/**
|
||||
* A request for a rematch.
|
||||
*
|
||||
|
||||
@@ -30,13 +30,13 @@ public interface TrickCardCodes extends CardCodes
|
||||
{
|
||||
/** For four-player games, the bottom (own) player. */
|
||||
public static final int BOTTOM = 0;
|
||||
|
||||
|
||||
/** For four-player games, the player on the left. */
|
||||
public static final int LEFT = 1;
|
||||
|
||||
|
||||
/** For four-player games, the top (opposite) player. */
|
||||
public static final int TOP = 2;
|
||||
|
||||
|
||||
/** For four-player games, the player on the right. */
|
||||
public static final int RIGHT = 3;
|
||||
}
|
||||
|
||||
@@ -33,25 +33,25 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
{
|
||||
/** The state that indicates the game is currently between hands. */
|
||||
public static final int BETWEEN_HANDS = 0;
|
||||
|
||||
|
||||
/** The state that indicates the game is currently playing a hand. */
|
||||
public static final int PLAYING_HAND = 1;
|
||||
|
||||
|
||||
/** The state that indicates the game is currently playing a trick. */
|
||||
public static final int PLAYING_TRICK = 2;
|
||||
|
||||
|
||||
/** The number of states defined for the base trick card game object. */
|
||||
public static final int TRICK_STATE_COUNT = 3;
|
||||
|
||||
|
||||
/** Indicates that the player has not requested or accepted a rematch. */
|
||||
public static final int NO_REQUEST = 0;
|
||||
|
||||
|
||||
/** Indicates that the player has requested a rematch. */
|
||||
public static final int REQUESTS_REMATCH = 1;
|
||||
|
||||
|
||||
/** Indicates that the player has accepted the rematch request. */
|
||||
public static final int ACCEPTS_REMATCH = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the trick card game service used to make
|
||||
* requests to the server.
|
||||
@@ -59,7 +59,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return a reference to the trick card game service
|
||||
*/
|
||||
public TrickCardGameMarshaller getTrickCardGameService ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the reference to the trick card game service.
|
||||
*
|
||||
@@ -67,7 +67,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
*/
|
||||
public void setTrickCardGameService (TrickCardGameMarshaller
|
||||
trickCardGameService);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the trick state: between
|
||||
* hands, playing a hand, or playing a trick.
|
||||
@@ -75,7 +75,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the trickState field
|
||||
*/
|
||||
public String getTrickStateFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the trick state: between hands, playing a hand, or playing a
|
||||
* trick.
|
||||
@@ -88,9 +88,9 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* Sets the trick state.
|
||||
*
|
||||
* @param trickState the trick state
|
||||
*/
|
||||
*/
|
||||
public void setTrickState (int trickState);
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the turn duration scales for each player.
|
||||
* Turn duration scales decrease each time players time out.
|
||||
@@ -98,14 +98,14 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the array of turn duration scales
|
||||
*/
|
||||
public float[] getTurnDurationScales ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of turn duration scales.
|
||||
*
|
||||
* @param turnDurationScales the array of turn duration scales
|
||||
*/
|
||||
public void setTurnDurationScales (float[] turnDurationScales);
|
||||
|
||||
|
||||
/**
|
||||
* Sets an element of the array of turn duration scales.
|
||||
*
|
||||
@@ -113,13 +113,13 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param index the index of the turn duration scale
|
||||
*/
|
||||
public void setTurnDurationScalesAt (float turnDurationScale, int index);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the duration of the current turn, which may depend on the state
|
||||
* of the game as well as the duration scale of the active player.
|
||||
*/
|
||||
public long getTurnDuration ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the history of the trick
|
||||
* in terms of the cards played by each player.
|
||||
@@ -127,7 +127,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the cardsPlayed field
|
||||
*/
|
||||
public String getCardsPlayedFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the history of the trick in terms of the
|
||||
* cards played by each player.
|
||||
@@ -135,7 +135,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the cards played so far in the trick
|
||||
*/
|
||||
public PlayerCard[] getCardsPlayed ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of cards played by each player.
|
||||
*
|
||||
@@ -150,7 +150,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the lastCardsPlayed field
|
||||
*/
|
||||
public String getLastCardsPlayedFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the history of the last trick in terms of
|
||||
* the cards played by each player.
|
||||
@@ -158,35 +158,35 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the cards played in the last trick
|
||||
*/
|
||||
public PlayerCard[] getLastCardsPlayed ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the last array of cards played by each player.
|
||||
*
|
||||
* @param lastCardsPlayed the last array of cards played
|
||||
*/
|
||||
public void setLastCardsPlayed (PlayerCard[] lastCardsPlayed);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the rematch requests.
|
||||
*
|
||||
* @return the name of the rematchRequests field
|
||||
*/
|
||||
public String getRematchRequestsFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the array of rematch requests.
|
||||
*
|
||||
* @return the array of rematch requests
|
||||
*/
|
||||
public int[] getRematchRequests ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of rematch requests.
|
||||
*
|
||||
* @param rematchRequests the array of rematch requests
|
||||
*/
|
||||
public void setRematchRequests (int[] rematchRequests);
|
||||
|
||||
|
||||
/**
|
||||
* Sets an element of the rematch request array.
|
||||
*
|
||||
@@ -194,7 +194,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param index the index at which to set the value
|
||||
*/
|
||||
public void setRematchRequestsAt (int rematchRequest, int index);
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a user can play the specified card at this time.
|
||||
*
|
||||
@@ -202,7 +202,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param card the card that the user would like to play
|
||||
*/
|
||||
public boolean isCardPlayable (Hand hand, Card card);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the card of the player who took the current trick.
|
||||
*/
|
||||
|
||||
+12
-17
@@ -28,8 +28,6 @@ import java.util.List;
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.RandomUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -215,15 +213,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure they're actually a player
|
||||
int fromidx = _cgmgr.getPlayerIndex(client);
|
||||
if (fromidx == -1) {
|
||||
log.warning("Send request from non-player [username=" +
|
||||
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
|
||||
log.warning("Send request from non-player",
|
||||
"username", ((BodyObject)client).who(), "cards", cards);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure they have the cards
|
||||
if (!_hands[fromidx].containsAll(cards)) {
|
||||
log.warning("Tried to send cards not held [username=" +
|
||||
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
|
||||
log.warning("Tried to send cards not held",
|
||||
"username", ((BodyObject)client).who(), "cards", cards);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,15 +251,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
|
||||
// make sure their hand contains the specified card
|
||||
if (!_hands[pidx].contains(card)) {
|
||||
log.warning("Tried to play card not held [username=" + username +
|
||||
", card=" + card + "].");
|
||||
log.warning("Tried to play card not held", "username", username, "card", card);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the card is legal to play
|
||||
if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) {
|
||||
log.warning("Tried to play illegal card [username=" + username +
|
||||
", card=" + card + "].");
|
||||
log.warning("Tried to play illegal card", "username", username, "card", card);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -281,14 +277,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure the requester is one of the players
|
||||
int pidx = _cgmgr.getPlayerIndex(client);
|
||||
if (pidx == -1) {
|
||||
log.warning("Rematch request from non-player [username=" +
|
||||
((BodyObject)client).who() + "].");
|
||||
log.warning("Rematch request from non-player", "username", ((BodyObject)client).who());
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the player hasn't already requested
|
||||
if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) {
|
||||
log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "].");
|
||||
log.warning("Repeated rematch request", "username", ((BodyObject)client).who());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -361,8 +356,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
{
|
||||
int[] rematchRequests = _trickCardGame.getRematchRequests();
|
||||
int count = 0;
|
||||
for (int i = 0; i < rematchRequests.length; i++) {
|
||||
if (rematchRequests[i] != TrickCardGameObject.NO_REQUEST) {
|
||||
for (int rematchRequest : rematchRequests) {
|
||||
if (rematchRequest != TrickCardGameObject.NO_REQUEST) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -562,8 +557,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
*/
|
||||
protected boolean anyHandsEmpty ()
|
||||
{
|
||||
for (int i = 0; i < _hands.length; i++) {
|
||||
if (_hands[i].isEmpty()) {
|
||||
for (Hand _hand : _hands) {
|
||||
if (_hand.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ public class TrickCardGameUtil
|
||||
implements TrickCardCodes
|
||||
{
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the player's team.
|
||||
* For four-player games with fixed partnerships, this returns the index of the player's team.
|
||||
*
|
||||
* @param pidx the player index
|
||||
*/
|
||||
@@ -42,10 +41,9 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return pidx & 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the other team.
|
||||
* For four-player games with fixed partnerships, this returns the index of the other team.
|
||||
*
|
||||
* @param tidx the index of the team
|
||||
*/
|
||||
@@ -53,19 +51,19 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return tidx ^ 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the player's partner.
|
||||
* For four-player games with fixed partnerships, this returns the index of the player's
|
||||
* partner.
|
||||
*/
|
||||
public static int getPartnerIndex (int pidx)
|
||||
{
|
||||
return pidx ^ 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of one of the members of a team.
|
||||
* For four-player games with fixed partnerships, this returns the index of one of the members
|
||||
* of a team.
|
||||
*
|
||||
* @param tidx the index of the team
|
||||
* @param midx the index of the player within the team
|
||||
@@ -74,10 +72,10 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return (midx << 1) | tidx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, this returns the index of the player after the
|
||||
* specified player going clockwise around the table.
|
||||
* For four-player games, this returns the index of the player after the specified player
|
||||
* going clockwise around the table.
|
||||
*/
|
||||
public static int getNextInClockwiseSequence (int pidx)
|
||||
{
|
||||
@@ -86,10 +84,10 @@ public class TrickCardGameUtil
|
||||
// 0
|
||||
return (pidx + 1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the
|
||||
* relative location of one player from the point of view of another.
|
||||
* For four-player games with fixed partnerships, this returns the relative location of one
|
||||
* player from the point of view of another.
|
||||
*
|
||||
* @param pidx1 the index of the player to whom the location is relative
|
||||
* @param pidx2 the index of the player whose location is desired
|
||||
@@ -99,34 +97,32 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return (pidx2 - pidx1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player to the left of
|
||||
* the specified player.
|
||||
* For four-player games, returns the index of the player to the left of the specified player.
|
||||
*/
|
||||
public static int getLeftIndex (int pidx)
|
||||
{
|
||||
return (pidx + 1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player to the right of
|
||||
* the specified player.
|
||||
* For four-player games, returns the index of the player to the right of the specified
|
||||
* player.
|
||||
*/
|
||||
public static int getRightIndex (int pidx)
|
||||
{
|
||||
return (pidx + 3) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player across from the
|
||||
* specified player.
|
||||
* For four-player games, returns the index of the player across from the specified player.
|
||||
*/
|
||||
public static int getOppositeIndex (int pidx)
|
||||
{
|
||||
return pidx ^ 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the player can follow the suit lead with the hand given.
|
||||
*/
|
||||
@@ -134,35 +130,34 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return hand.getSuitMemberCount(cardsPlayed[0].card.getSuit()) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the specified array contains the given card.
|
||||
*/
|
||||
public static boolean containsCard (PlayerCard[] cards, Card card)
|
||||
{
|
||||
for (int i = 0; i < cards.length; i++) {
|
||||
if (cards[i].card.equals(card)) {
|
||||
for (PlayerCard pc : cards) {
|
||||
if (pc.card.equals(card)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines the number of cards that belong to the specified suit within
|
||||
* the array given.
|
||||
* Determines the number of cards that belong to the specified suit within the array given.
|
||||
*/
|
||||
public static int countSuitMembers (PlayerCard[] cards, int suit)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < cards.length; i++) {
|
||||
if (cards[i].card.getSuit() == suit) {
|
||||
for (PlayerCard pc : cards) {
|
||||
if (pc.card.getSuit() == suit) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the proposed card follows the suit lead.
|
||||
*/
|
||||
@@ -170,23 +165,21 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return cardsPlayed[0].card.getSuit() == card.getSuit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the highest card (according to the standard A,K,...,2 ordering)
|
||||
* in the suit lead, with an optional trump suit.
|
||||
* Returns the highest card (according to the standard A,K,...,2 ordering) in the suit lead,
|
||||
* with an optional trump suit.
|
||||
*
|
||||
* @param trumpSuit the trump suit, or -1 for none
|
||||
*/
|
||||
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed,
|
||||
int trumpSuit)
|
||||
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed, int trumpSuit)
|
||||
{
|
||||
PlayerCard highest = cardsPlayed[0];
|
||||
for (int i = 1; i < cardsPlayed.length; i++) {
|
||||
PlayerCard other = cardsPlayed[i];
|
||||
if ((other.card.getSuit() == highest.card.getSuit() &&
|
||||
other.card.compareTo(highest.card) > 0) ||
|
||||
(other.card.getSuit() == trumpSuit &&
|
||||
highest.card.getSuit() != trumpSuit)) {
|
||||
(other.card.getSuit() == trumpSuit && highest.card.getSuit() != trumpSuit)) {
|
||||
highest = other;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class TableConfigurator
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, the TableConfigurator is empty, which doesn't mean that
|
||||
* If true, the TableConfigurator is empty, which doesn't mean that
|
||||
* it will not return a TableConfig object (for it must), but rather
|
||||
* that there are no user-editable options being presented in the
|
||||
* config interface.
|
||||
|
||||
@@ -303,7 +303,7 @@ public class TableManager
|
||||
} else if ( ! _allowBooting) {
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
int position = ListUtil.indexOf(table.players, target);
|
||||
if (position < 0) {
|
||||
throw new InvocationException(NOT_AT_TABLE);
|
||||
|
||||
@@ -24,7 +24,7 @@ package com.threerings.parlor.tourney.data;
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
|
||||
/**
|
||||
* Extensible class that specifies the prize for a tourney.
|
||||
* Extensible class that specifies the prize for a tourney.
|
||||
*/
|
||||
public abstract class Prize extends SimpleStreamableObject
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.threerings.io.SimpleStreamableObject;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
/**
|
||||
* Stores tournament configuration data.
|
||||
* Stores tournament configuration data.
|
||||
*/
|
||||
public class TourneyConfig extends SimpleStreamableObject
|
||||
{
|
||||
|
||||
@@ -73,7 +73,7 @@ public abstract class TourniesManager
|
||||
}
|
||||
|
||||
// from interface TourniesService
|
||||
public void createTourney (ClientObject caller, TourneyConfig config,
|
||||
public void createTourney (ClientObject caller, TourneyConfig config,
|
||||
final InvocationService.ResultListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ public interface StageSceneService extends InvocationService
|
||||
*/
|
||||
public void addObject (Client client, ObjectInfo info,
|
||||
ConfirmListener listener);
|
||||
|
||||
|
||||
/**
|
||||
* Requests to remove the supplied objects from the current scene.
|
||||
*/
|
||||
|
||||
@@ -34,10 +34,10 @@ public class ModifyObjectsUpdate extends SceneUpdate
|
||||
{
|
||||
/** The objects added to the scene (or <code>null</code> for none). */
|
||||
public ObjectInfo[] added;
|
||||
|
||||
|
||||
/** The objects removed from the scene (or <code>null</code> for none). */
|
||||
public ObjectInfo[] removed;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes this update with all necessary data.
|
||||
*
|
||||
|
||||
@@ -82,7 +82,7 @@ public class DirectionButton extends AbstractButton
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class DirectionButton extends AbstractButton
|
||||
double rads = Math.PI * 2 * ii / num;
|
||||
|
||||
// 0 radians specifies EAST, so we offset
|
||||
int dir = (ii + DirectionCodes.EAST) % num;
|
||||
int dir = (ii + DirectionCodes.EAST) % num;
|
||||
|
||||
_coords[dir][0] = mid + ((int) (mid * Math.cos(rads)));
|
||||
_coords[dir][1] = mid + ((int) (mid * Math.sin(rads)));
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ObjectEditorDialog extends EditorDialog
|
||||
/**
|
||||
* Prepare the dialog for display. This method should be called before <code>display()</code>
|
||||
* is called.
|
||||
*
|
||||
*
|
||||
* @param scobj the object to edit.
|
||||
*/
|
||||
public void prepare (SceneObject scobj)
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PortalDialog extends EditorDialog
|
||||
{
|
||||
super("Edit Portal", ctx, panel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addComponents(JComponent top){
|
||||
// add the dialog instruction text
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PreferencesDialog extends JInternalFrame
|
||||
{
|
||||
JFileChooser chooser;
|
||||
|
||||
// figure out which
|
||||
// figure out which
|
||||
File f = new File(button.getText());
|
||||
if (!f.exists()) {
|
||||
chooser = new JFileChooser();
|
||||
|
||||
@@ -91,7 +91,7 @@ public class EditorDialogUtil
|
||||
center(parent, dialog);
|
||||
parent.getLayeredPane().add(dialog, JLayeredPane.POPUP_LAYER);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the supplied dialog from its parent container, but does not
|
||||
|
||||
@@ -167,7 +167,7 @@ public class ViewerApp
|
||||
public KeyDispatcher getKeyDispatcher () {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface
|
||||
public String xlate (String message) {
|
||||
return message;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PlacementConstraints
|
||||
_tilemgr = tilemgr;
|
||||
_scene = scene;
|
||||
_mmodel = StageMisoSceneModel.getSceneModel(scene.getSceneModel());
|
||||
|
||||
|
||||
// add all the objects in the scene
|
||||
StageMisoSceneModel.ObjectVisitor visitor =
|
||||
new StageMisoSceneModel.ObjectVisitor() {
|
||||
@@ -81,7 +81,7 @@ public class PlacementConstraints
|
||||
};
|
||||
_mmodel.visitObjects(visitor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the constraints allow the specified object to be
|
||||
* added to the scene.
|
||||
@@ -95,7 +95,7 @@ public class PlacementConstraints
|
||||
return allowModifyObjects(new ObjectInfo[] { info },
|
||||
new ObjectInfo[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the specified object through the constraints.
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ public class PlacementConstraints
|
||||
_objectData.put(info, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the constraints allow the specified object to be
|
||||
* removed from the scene.
|
||||
@@ -121,7 +121,7 @@ public class PlacementConstraints
|
||||
return allowModifyObjects(new ObjectInfo[0],
|
||||
new ObjectInfo[] { info });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the specified object through the constraints.
|
||||
*/
|
||||
@@ -130,7 +130,7 @@ public class PlacementConstraints
|
||||
_scene.removeObject(info);
|
||||
_objectData.remove(info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the constraints allow the specified objects to be
|
||||
* added and removed simultaneously.
|
||||
@@ -149,12 +149,12 @@ public class PlacementConstraints
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ObjectData[] removedData = getObjectDataFromInfo(removed);
|
||||
if (removedData == null) {
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return allowModifyObjects(addedData, removedData);
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the constraints allow the specified objects to be
|
||||
* added and removed simultaneously. Subclasses that wish to define
|
||||
@@ -192,62 +192,62 @@ public class PlacementConstraints
|
||||
ObjectData[] removed)
|
||||
{
|
||||
DirectionHeight dirheight = new DirectionHeight();
|
||||
|
||||
|
||||
for (int i = 0; i < added.length; i++) {
|
||||
if (added[i].tile.hasConstraint(ObjectTileSet.ON_SURFACE) &&
|
||||
!isOnSurface(added[i], added, removed)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.not_on_surface");
|
||||
}
|
||||
|
||||
|
||||
int dir = getConstraintDirection(added[i], ObjectTileSet.ON_WALL);
|
||||
if (dir != NONE && !isOnWall(added[i], added, removed, dir)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.not_on_wall");
|
||||
}
|
||||
|
||||
|
||||
if (getConstraintDirectionHeight(added[i], ObjectTileSet.ATTACH,
|
||||
dirheight) && !isAttached(added[i], added, removed,
|
||||
dirheight.dir, dirheight.low)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.not_attached");
|
||||
}
|
||||
|
||||
|
||||
dir = getConstraintDirection(added[i], ObjectTileSet.SPACE);
|
||||
if (dir != NONE && !hasSpace(added[i], added, removed, dir)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.no_space");
|
||||
}
|
||||
|
||||
|
||||
if (hasSpaceConstrainedAdjacent(added[i], added, removed)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.no_space_adj");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < removed.length; i++) {
|
||||
if (removed[i].tile.hasConstraint(ObjectTileSet.SURFACE) &&
|
||||
hasOnSurface(removed[i], added, removed)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.has_on_surface");
|
||||
}
|
||||
|
||||
|
||||
int dir = getConstraintDirection(removed[i], ObjectTileSet.WALL);
|
||||
if (dir != NONE) {
|
||||
if (hasOnWall(removed[i], added, removed, dir)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.has_on_wall");
|
||||
|
||||
|
||||
} else if (hasAttached(removed[i], added, removed, dir)) {
|
||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||
"m.has_attached");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified surface has anything on it that won't
|
||||
* be held up if the surface is removed.
|
||||
@@ -265,7 +265,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified wall has anything on it that won't be
|
||||
* held up if the wall is removed.
|
||||
@@ -283,7 +283,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified wall has anything attached to it that
|
||||
* won't be held up if the wall is removed.
|
||||
@@ -292,7 +292,7 @@ public class PlacementConstraints
|
||||
ObjectData[] removed, int dir)
|
||||
{
|
||||
DirectionHeight dirheight = new DirectionHeight();
|
||||
|
||||
|
||||
List<ObjectData> objects = getObjectData(getAdjacentEdge(data.bounds,
|
||||
DirectionUtil.getOpposite(dir)), added, removed);
|
||||
for (int i = 0, size = objects.size(); i < size; i++) {
|
||||
@@ -305,7 +305,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that the objects adjacent to the given object will still have
|
||||
* their space constraints met if the object is added.
|
||||
@@ -316,7 +316,7 @@ public class PlacementConstraints
|
||||
Rectangle r = data.bounds;
|
||||
// grow the ObjectData bounds 1 square in each direction
|
||||
_constrainRect.setBounds(r.x - 1, r.y - 1, r.width + 2, r.height + 2);
|
||||
|
||||
|
||||
List<ObjectData> objects = getObjectData(_constrainRect, added, removed);
|
||||
for (int i = 0, size = objects.size(); i < size; i++) {
|
||||
ObjectData odata = objects.get(i);
|
||||
@@ -327,7 +327,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified object has empty space in the specified
|
||||
* direction.
|
||||
@@ -338,7 +338,7 @@ public class PlacementConstraints
|
||||
return getObjectData(getAdjacentEdge(data.bounds, dir), added,
|
||||
removed).size() == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified object is on a surface.
|
||||
*/
|
||||
@@ -348,7 +348,7 @@ public class PlacementConstraints
|
||||
return isCovered(data.bounds, added, removed, ObjectTileSet.SURFACE,
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified object is on a wall facing the
|
||||
* specified direction.
|
||||
@@ -359,7 +359,7 @@ public class PlacementConstraints
|
||||
return isCovered(data.bounds, added, removed,
|
||||
getDirectionalConstraint(ObjectTileSet.WALL, dir), null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the specified object is attached to another object in
|
||||
* the specified direction and at the specified height.
|
||||
@@ -371,7 +371,7 @@ public class PlacementConstraints
|
||||
getDirectionalConstraint(ObjectTileSet.WALL, dir), low ?
|
||||
getDirectionalConstraint(ObjectTileSet.WALL, dir, true) : null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a rectangle, determines whether all of the tiles within
|
||||
* the rectangle intersect an object. If the constraint parameter is
|
||||
@@ -402,7 +402,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and returns a rectangle that covers the specified rectangle's
|
||||
* adjacent edge (the squares one tile beyond the bounds) in the specified
|
||||
@@ -413,23 +413,23 @@ public class PlacementConstraints
|
||||
switch (dir) {
|
||||
case NORTH:
|
||||
return new Rectangle(rect.x - 1, rect.y, 1, rect.height);
|
||||
|
||||
|
||||
case EAST:
|
||||
return new Rectangle(rect.x, rect.y - 1, rect.width, 1);
|
||||
|
||||
|
||||
case SOUTH:
|
||||
return new Rectangle(rect.x + rect.width, rect.y, 1,
|
||||
rect.height);
|
||||
|
||||
|
||||
case WEST:
|
||||
return new Rectangle(rect.x, rect.y + rect.height,
|
||||
rect.width, 1);
|
||||
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the direction in which the specified object is constrained by
|
||||
* appending "[NESW]" to the given constraint prefix. Returns
|
||||
@@ -441,7 +441,7 @@ public class PlacementConstraints
|
||||
return getConstraintDirectionHeight(data, prefix, dirheight) ?
|
||||
dirheight.dir : NONE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populates the supplied {@link DirectionHeight} object with the direction
|
||||
* and height of the constraint identified by the given prefix.
|
||||
@@ -456,7 +456,7 @@ public class PlacementConstraints
|
||||
if (constraints == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < constraints.length; i++) {
|
||||
if (constraints[i].startsWith(prefix)) {
|
||||
int fromidx = prefix.length(),
|
||||
@@ -470,7 +470,7 @@ public class PlacementConstraints
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a constraint prefix and a direction, returns the directional
|
||||
* constraint.
|
||||
@@ -479,7 +479,7 @@ public class PlacementConstraints
|
||||
{
|
||||
return getDirectionalConstraint(prefix, dir, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a constraint prefix, direction, and height, returns the
|
||||
* directional constraint.
|
||||
@@ -490,7 +490,7 @@ public class PlacementConstraints
|
||||
return prefix + DirectionUtil.toShortString(dir) +
|
||||
(low ? ObjectTileSet.LOW : "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all objects whose bounds intersect the given rectangle and
|
||||
* returns a list containing their {@link ObjectData} elements.
|
||||
@@ -502,7 +502,7 @@ public class PlacementConstraints
|
||||
ObjectData[] removed)
|
||||
{
|
||||
List<ObjectData> list = Lists.newArrayList();
|
||||
|
||||
|
||||
for (Iterator<ObjectData> it = _objectData.values().iterator(); it.hasNext(); ) {
|
||||
ObjectData data = it.next();
|
||||
if (rect.intersects(data.bounds) && !ListUtil.contains(removed,
|
||||
@@ -510,16 +510,16 @@ public class PlacementConstraints
|
||||
list.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < added.length; i++) {
|
||||
if (rect.intersects(added[i].bounds)) {
|
||||
list.add(added[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Using the tile manager, computes and returns the specified object's
|
||||
* data.
|
||||
@@ -532,42 +532,42 @@ public class PlacementConstraints
|
||||
tile.getBaseHeight());
|
||||
bounds.translate(1 - bounds.width, 1 - bounds.height);
|
||||
return new ObjectData(bounds, tile);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warning("Error retrieving tile for object [info=" + info + "].", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Contains information about an object used in checking constraints. */
|
||||
protected class ObjectData
|
||||
{
|
||||
public Rectangle bounds;
|
||||
public ObjectTile tile;
|
||||
|
||||
|
||||
public ObjectData (Rectangle bounds, ObjectTile tile)
|
||||
{
|
||||
this.bounds = bounds;
|
||||
this.tile = tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Contains the direction and height of a constraint. */
|
||||
protected class DirectionHeight
|
||||
{
|
||||
public int dir;
|
||||
public boolean low;
|
||||
}
|
||||
|
||||
|
||||
/** The tile manager to use for object dimensions and constraints. */
|
||||
protected TileManager _tilemgr;
|
||||
|
||||
|
||||
/** The scene being checked for constraints. */
|
||||
protected StageScene _scene;
|
||||
|
||||
|
||||
/** The Miso scene model. */
|
||||
protected StageMisoSceneModel _mmodel;
|
||||
|
||||
|
||||
/** For all objects in the scene, maps {@link ObjectInfo}s to
|
||||
* {@link ObjectData}s. */
|
||||
protected HashMap<ObjectInfo,ObjectData> _objectData = new HashMap<ObjectInfo,ObjectData>();
|
||||
|
||||
@@ -82,7 +82,7 @@ public interface StageContext
|
||||
* Returns a reference to the colorization repository.
|
||||
*/
|
||||
public ColorPository getColorPository ();
|
||||
|
||||
|
||||
/**
|
||||
* Translates the specified message using the default bundle.
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@ public class StageSceneUtil
|
||||
* should use the object's orientation.
|
||||
*/
|
||||
public static final int OBJECT_ORIENTATION = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the scene metrics we use to do our calculations.
|
||||
*/
|
||||
@@ -87,7 +87,7 @@ public class StageSceneUtil
|
||||
/**
|
||||
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||
* location is.
|
||||
*
|
||||
*
|
||||
* @param orient - the orientation to use in the returned location, or
|
||||
* {@link #OBJECT_ORIENTATION} if the object's orientation should be used
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ public class StageSceneUtil
|
||||
/**
|
||||
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||
* location is.
|
||||
*
|
||||
*
|
||||
* @param tilemgr a tile manager that can be used to look up the tile information.
|
||||
* @param tileId the fully qualified tile id of the object tile.
|
||||
* @param tx the object's x tile coordinate.
|
||||
@@ -114,7 +114,7 @@ public class StageSceneUtil
|
||||
/**
|
||||
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||
* location is.
|
||||
*
|
||||
*
|
||||
* @param tilemgr a tile manager that can be used to look up the tile information.
|
||||
* @param tileId the fully qualified tile id of the object tile.
|
||||
* @param tx the object's x tile coordinate.
|
||||
@@ -335,7 +335,7 @@ public class StageSceneUtil
|
||||
* will be used to override the "natural" orientation of the spot
|
||||
* which is facing toward the footprint.
|
||||
*
|
||||
* @return the closest spot to the
|
||||
* @return the closest spot to the
|
||||
*/
|
||||
public static StageLocation findStandingSpot (
|
||||
Rectangle foot, int dist, AStarPathUtil.TraversalPred pred,
|
||||
|
||||
@@ -208,7 +208,7 @@ public class SpotSceneManager extends SceneManager
|
||||
{
|
||||
return new SceneLocation(entry.getOppLocation(), body.getOid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move the specified body to the default portal, if possible.
|
||||
*/
|
||||
@@ -400,11 +400,11 @@ public class SpotSceneManager extends SceneManager
|
||||
{
|
||||
handleClusterMessageRequest(sourceOid, new UserMessage(source, bundle, message, mode));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by the {@link SpotProvider} when we receive a cluster message request.
|
||||
*/
|
||||
protected void handleClusterMessageRequest (int sourceOid, UserMessage message)
|
||||
protected void handleClusterMessageRequest (int sourceOid, UserMessage message)
|
||||
{
|
||||
ClusterRecord clrec = getCluster(sourceOid);
|
||||
if (clrec == null) {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class UpdateList
|
||||
if (_updates.size() == 0 || _updates.get(0).getSceneVersion() > fromVersion) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
List<SceneUpdate> updates = Lists.newArrayList();
|
||||
for (SceneUpdate update : _updates) {
|
||||
if (update.getSceneVersion() >= fromVersion) {
|
||||
|
||||
Reference in New Issue
Block a user