From 9d4a41f54fec009317da794363bf91f4ee185b46 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Thu, 19 Jul 2007 19:07:50 +0000 Subject: [PATCH] Widen up some drop puzzle code, and break the board filling action out into its own function so puzzles wanting fancier fill logic can override it as needed. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@370 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../drop/server/DropManagerDelegate.java | 3 +- .../puzzle/drop/util/PieceDropLogic.java | 14 ++--- .../puzzle/drop/util/PieceDropper.java | 51 +++++++++++-------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java b/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java index f6b8dc38..94a5c210 100644 --- a/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java +++ b/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java @@ -58,8 +58,7 @@ import com.threerings.puzzle.drop.util.PieceDropper; * for checking things like whether the game is over, whether a player is * still active in the game, and so forth. * - *

Derived classes are likely to want to override {@link - * #getPieceDropLogic}. + *

Derived classes are likely to want to override {@link #getPieceDropLogic}. */ public abstract class DropManagerDelegate extends PuzzleManagerDelegate implements PuzzleCodes, DropCodes diff --git a/src/java/com/threerings/puzzle/drop/util/PieceDropLogic.java b/src/java/com/threerings/puzzle/drop/util/PieceDropLogic.java index 980b400d..fe033a68 100644 --- a/src/java/com/threerings/puzzle/drop/util/PieceDropLogic.java +++ b/src/java/com/threerings/puzzle/drop/util/PieceDropLogic.java @@ -44,8 +44,7 @@ public interface PieceDropLogic public boolean isDroppablePiece (int piece); /** - * Returns whether the given piece has constraints upon it that - * impact its droppability. + * Returns whether the given piece has constraints upon it that impact its droppability. */ public boolean isConstrainedPiece (int piece); @@ -59,16 +58,13 @@ public interface PieceDropLogic * @param pre whether the climbability check is being performed * before the height is incremented, or after. */ - public boolean isClimbablePiece ( - boolean allowConst, int piece, boolean pre); + public boolean isClimbablePiece (boolean allowConst, int piece, boolean pre); /** - * Returns the x-axis coordinate of the specified edge of the - * given constrained piece. + * Returns the x-axis coordinate of the specified edge of the given constrained piece. * - *

TODO: This should go away once the sword and sail games - * have standardized on WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to - * reference block edges. + *

TODO: This should go away once the sword and sail games have standardized on + * WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to reference block edges. * * @param board the board to search. * @param col the column of the constrained piece. diff --git a/src/java/com/threerings/puzzle/drop/util/PieceDropper.java b/src/java/com/threerings/puzzle/drop/util/PieceDropper.java index d76c3f7e..2e9d50ea 100644 --- a/src/java/com/threerings/puzzle/drop/util/PieceDropper.java +++ b/src/java/com/threerings/puzzle/drop/util/PieceDropper.java @@ -38,8 +38,7 @@ public class PieceDropper implements DropPieceCodes { /** - * A class to hold information detailing the pieces to be dropped - * in a particular column. + * A class to hold information detailing the pieces to be dropped in a particular column. */ public static class PieceDropInfo { @@ -92,8 +91,7 @@ public class PieceDropper /** * Effects any drops possible on the supplied board (modifying the - * board in the progress) and notifying the supplied drop observer of - * those drops. + * board in the progress) and notifying the supplied drop observer of those drops. * * @return the number of pieces dropped. */ @@ -106,18 +104,32 @@ public class PieceDropper } } - // if the board wants pieces to be dropped in to fill the gaps, do - // that now + // if the board wants pieces to be dropped in to fill the gaps, do that now if (_logic.boardAlwaysFilled()) { - for (int xx = 0; xx < bwid; xx++) { - int dist = board.getDropDistance(xx, -1); - for (int ii = 0; ii < dist; ii++) { - int yy = (-1 - ii); - int piece = board.getNextPiece(); - if (piece != PIECE_NONE) { - drop(board, piece, xx, yy, yy + dist, drobs); - dropped++; - } + dropped += fillBoard(board, drobs); + } + + return dropped; + } + + /** + * Drops new pieces onto the board to fill the gaps. + * + * @return the number of pieces dropped. + */ + public int fillBoard (DropBoard board, DropObserver drobs) + { + int dropped = 0; + int bwid = board.getWidth(); + + for (int xx = 0; xx < bwid; xx++) { + int dist = board.getDropDistance(xx, -1); + for (int ii = 0; ii < dist; ii++) { + int yy = (-1 - ii); + int piece = board.getNextPiece(); + if (piece != PIECE_NONE) { + drop(board, piece, xx, yy, yy + dist, drobs); + dropped++; } } } @@ -127,11 +139,9 @@ public class PieceDropper /** * Computes and effects the drop for the specified piece and any - * associated attached pieces. The supplied observer is notified of - * all drops. + * associated attached pieces. The supplied observer is notified of all drops. */ - protected int dropPieces ( - DropBoard board, int xx, int yy, DropObserver drobs) + protected int dropPieces (DropBoard board, int xx, int yy, DropObserver drobs) { // skip empty or fixed pieces int piece = board.getPiece(xx, yy); @@ -147,8 +157,7 @@ public class PieceDropper int bwid = board.getWidth(); if (start < 0 || end >= bwid) { Log.warning("Board reported bogus constrained edge " + - "[x=" + xx + ", y=" + yy + - ", start=" + start + ", end=" + end + "]."); + "[x=" + xx + ", y=" + yy + ", start=" + start + ", end=" + end + "]."); board.dump(); start = Math.max(start, 0); end = Math.min(end, bwid);