diff --git a/projects/atlanti/bin/runjava b/projects/atlanti/bin/runjava index cb3d148e..3a397e35 100755 --- a/projects/atlanti/bin/runjava +++ b/projects/atlanti/bin/runjava @@ -1,12 +1,8 @@ #!/usr/bin/perl -w -# -# $Id: runjava,v 1.1 2001/10/09 20:27:35 mdb Exp $ -# -# Invokes java with the necessary classpath and parameters. use Getopt::Std; -my $usage = "Usage: $0 [-p pid_file] [-r server_root] args\n"; +my $usage = "Usage: $0 [-p pid_file] [-r root_directory] args\n"; # locations of stuff chomp($location = `dirname $0`); @@ -16,8 +12,9 @@ chomp($location = `dirname $0`); pop(@parts); my $root = join("/", @parts); -# make sure JAVA_HOME is set my $jhome = $ENV{"JAVA_HOME"}; + +# make sure JAVA_HOME is set if (!defined $jhome) { warn "$0: Error: No JAVA_HOME specified!\n"; warn "\n"; @@ -55,22 +52,32 @@ if (defined $libpath) { } # put everything in our class path -my $classpath = "-classpath $jlib:$root/dist/classes"; +my $classpath = "-classpath $root/dist/classes"; -# any zip or jar files in our lib/ directory get added to the class path -if (opendir(DIR, "$root/lib")) { - foreach $lib (grep { /.(zip|jar)/ && -f "$root/lib/$_" } readdir(DIR)) { - $classpath .= ":$root/lib/$lib"; +# add zip and jar files from our lib/ directory and the system lib/ directory +my @dirs = ( "$root/lib", $ENV{"JAVA_LIBS"} ); +foreach $dir (@dirs) { + next unless (defined $dir); + if (opendir(DIR, $dir)) { + foreach $lib (grep { /.(zip|jar)/ && -f "$dir/$_" } readdir(DIR)) { + $classpath .= ":$dir/$lib"; + } + closedir DIR; } - closedir DIR; } +# finally add the standard classes +$classpath = "$classpath:$jlib"; + +# specify our application root (the resource manager needs this) +my $rootarg = "-Dresource_url=file:$root/rsrc"; + my $pid_file = undef; my $i = 0; -# strip out the args (we'd use getopt() but the damned thing provides no -# way of escaping arguments so that we can pass args to runjava that get -# passed down to the JVM) +# strip out the -p and -r args (we'd use getopt() but the damned thing +# provides no way of escaping arguments so that we can pass args to +# runjava that get passed down to the JVM) for ($i = 0; $i < @ARGV; $i++) { my $arg = $ARGV[$i]; @@ -84,12 +91,17 @@ for ($i = 0; $i < @ARGV; $i++) { $pid_file = $ARGV[$i+1]; splice(@ARGV, $i, 2); $i -= 1; # decrement i so that things stay in sync + + } elsif ($arg eq "-r") { + $rootarg = "-DDapplication.root=" . $ARGV[$i+1]; + splice(@ARGV, $i, 2); + $i -= 1; # decrement i so that things stay in sync } } # log the pid file if requested to do so print `echo $$ > $pid_file` if (defined $pid_file); -my $cmd = "$java $classpath " . join(" ", @ARGV); +my $cmd = "$java -mx256M $classpath $rootarg " . join(" ", @ARGV); # print "$cmd\n"; exec($cmd); diff --git a/projects/atlanti/build.xml b/projects/atlanti/build.xml index 668b3d24..7a70bfef 100644 --- a/projects/atlanti/build.xml +++ b/projects/atlanti/build.xml @@ -8,12 +8,14 @@ + - - - - + + + + + @@ -22,8 +24,16 @@ + + + + + + + + - + diff --git a/projects/atlanti/rsrc/i18n/atlanti.properties b/projects/atlanti/rsrc/i18n/atlanti.properties new file mode 100644 index 00000000..7e384cae --- /dev/null +++ b/projects/atlanti/rsrc/i18n/atlanti.properties @@ -0,0 +1,4 @@ +# +# $Id: atlanti.properties,v 1.1 2002/05/21 04:45:09 mdb Exp $ +# +# Translation messages diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiBoard.java b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiBoard.java index d520d0e5..58bf3d6b 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiBoard.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiBoard.java @@ -1,5 +1,5 @@ // -// $Id: AtlantiBoard.java,v 1.16 2001/11/24 08:25:04 shaper Exp $ +// $Id: AtlantiBoard.java,v 1.17 2002/05/21 04:45:10 mdb Exp $ package com.threerings.venison; @@ -65,7 +65,7 @@ public class VenisonBoard _tiles.clear(); // copy the tiles from the set into our local list - CollectionUtil.addAll(_tiles, tset.elements()); + CollectionUtil.addAll(_tiles, tset.entries()); // sort the list Collections.sort(_tiles); @@ -84,7 +84,7 @@ public class VenisonBoard public void setPiecens (DSet piecens) { // just iterate over the set placing each of the piecens in turn - Iterator iter = piecens.elements(); + Iterator iter = piecens.entries(); while (iter.hasNext()) { placePiecen((Piecen)iter.next()); } @@ -616,7 +616,7 @@ public class VenisonBoard // set a feature group to test propagation List tiles = new ArrayList(); - CollectionUtil.addAll(tiles, set.elements()); + CollectionUtil.addAll(tiles, set.entries()); Collections.sort(tiles); zero.setPiecen(new Piecen(Piecen.GREEN, 0, 0, 2), tiles); diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiController.java b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiController.java index 38e6f1a5..d90c55f0 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiController.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiController.java @@ -8,9 +8,9 @@ import com.samskivert.util.ListUtil; import com.threerings.presents.dobj.AttributeChangedEvent; import com.threerings.presents.dobj.DSet; -import com.threerings.presents.dobj.ElementAddedEvent; -import com.threerings.presents.dobj.ElementRemovedEvent; -import com.threerings.presents.dobj.ElementUpdatedEvent; +import com.threerings.presents.dobj.EntryAddedEvent; +import com.threerings.presents.dobj.EntryRemovedEvent; +import com.threerings.presents.dobj.EntryUpdatedEvent; import com.threerings.presents.dobj.MessageEvent; import com.threerings.presents.dobj.SetListener; @@ -18,18 +18,30 @@ import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.client.PlaceView; +import com.threerings.parlor.game.GameController; import com.threerings.parlor.turn.TurnGameController; +import com.threerings.parlor.turn.TurnGameControllerDelegate; import com.threerings.parlor.util.ParlorContext; +import com.threerings.micasa.util.MiCasaContext; + import com.threerings.venison.Log; /** * The main coordinator of user interface activities on the client-side of * the Venison game. */ -public class VenisonController - extends TurnGameController implements VenisonCodes, SetListener +public class VenisonController extends GameController + implements TurnGameController, VenisonCodes, SetListener { + /** + * Creates our controller and prepares it for operation. + */ + public VenisonController () + { + addDelegate(_delegate = new TurnGameControllerDelegate(this)); + } + // documentation inherited protected void didInit () { @@ -42,7 +54,7 @@ public class VenisonController // documentation inherited protected PlaceView createPlaceView () { - _panel = new VenisonPanel(_ctx, this); + _panel = new VenisonPanel((MiCasaContext)_ctx, this); return _panel; } @@ -67,16 +79,14 @@ public class VenisonController _panel.board.setPiecens(_venobj.piecens); // if it's our turn, set the tile to be placed - if (isOurTurn()) { + if (_delegate.isOurTurn()) { _panel.board.setTileToBePlaced(_venobj.currentTile); } } // documentation inherited - protected void turnDidChange (String turnHolder) + public void turnDidChange (String turnHolder) { - super.turnDidChange(turnHolder); - // if it's our turn, set the tile to be placed if (turnHolder.equals(_self.username)) { _panel.board.setTileToBePlaced(_venobj.currentTile); @@ -98,28 +108,28 @@ public class VenisonController } // documentation inherited - public void elementAdded (ElementAddedEvent event) + public void entryAdded (EntryAddedEvent event) { // we care about additions to TILES and PIECENS if (event.getName().equals(VenisonObject.TILES)) { // a tile was added, add it to the board - VenisonTile tile = (VenisonTile)event.getElement(); + VenisonTile tile = (VenisonTile)event.getEntry(); _panel.board.addTile(tile); } else if (event.getName().equals(VenisonObject.PIECENS)) { // a piecen was added, place it on the board - Piecen piecen = (Piecen)event.getElement(); + Piecen piecen = (Piecen)event.getEntry(); _panel.board.placePiecen(piecen); } } // documentation inherited - public void elementUpdated (ElementUpdatedEvent event) + public void entryUpdated (EntryUpdatedEvent event) { } // documentation inherited - public void elementRemoved (ElementRemovedEvent event) + public void entryRemoved (EntryRemovedEvent event) { if (event.getName().equals(VenisonObject.PIECENS)) { // a piecen was removed, update the board @@ -190,6 +200,9 @@ public class VenisonController return true; } + /** Our turn game delegate. */ + protected TurnGameControllerDelegate _delegate; + /** A reference to our game panel. */ protected VenisonPanel _panel; diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiPanel.java b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiPanel.java index e7d9b06e..aaab53c6 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiPanel.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/client/AtlantiPanel.java @@ -24,8 +24,8 @@ import com.threerings.media.tile.TileManager; import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.client.PlaceView; -import com.threerings.parlor.util.ParlorContext; import com.threerings.micasa.client.ChatPanel; +import com.threerings.micasa.util.MiCasaContext; /** * The top-level user interface component for the Venison game display. @@ -42,7 +42,7 @@ public class VenisonPanel /** * Constructs a new Venison game display. */ - public VenisonPanel (ParlorContext ctx, VenisonController controller) + public VenisonPanel (MiCasaContext ctx, VenisonController controller) { // give ourselves a wee bit of a border setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/client/PlayerInfoView.java b/projects/atlanti/src/java/com/samskivert/atlanti/client/PlayerInfoView.java index fccd765e..dad2d7cc 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/client/PlayerInfoView.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/client/PlayerInfoView.java @@ -1,5 +1,5 @@ // -// $Id: PlayerInfoView.java,v 1.3 2001/10/18 20:53:53 mdb Exp $ +// $Id: PlayerInfoView.java,v 1.4 2002/05/21 04:45:09 mdb Exp $ package com.threerings.venison; @@ -13,9 +13,9 @@ import javax.swing.JPanel; import com.threerings.presents.dobj.AttributeChangeListener; import com.threerings.presents.dobj.AttributeChangedEvent; import com.threerings.presents.dobj.SetListener; -import com.threerings.presents.dobj.ElementAddedEvent; -import com.threerings.presents.dobj.ElementUpdatedEvent; -import com.threerings.presents.dobj.ElementRemovedEvent; +import com.threerings.presents.dobj.EntryAddedEvent; +import com.threerings.presents.dobj.EntryUpdatedEvent; +import com.threerings.presents.dobj.EntryRemovedEvent; import com.threerings.crowd.client.PlaceView; import com.threerings.crowd.data.PlaceObject; @@ -115,18 +115,18 @@ public class PlayerInfoView } // documentation inherited - public void elementAdded (ElementAddedEvent event) + public void entryAdded (EntryAddedEvent event) { updatePiecenCount(); } // documentation inherited - public void elementUpdated (ElementUpdatedEvent event) + public void entryUpdated (EntryUpdatedEvent event) { } // documentation inherited - public void elementRemoved (ElementRemovedEvent event) + public void entryRemoved (EntryRemovedEvent event) { updatePiecenCount(); } diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiCodes.java b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiCodes.java index 674d3d6f..dc80a345 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiCodes.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiCodes.java @@ -1,5 +1,5 @@ // -// $Id: AtlantiCodes.java,v 1.4 2001/10/24 03:24:20 mdb Exp $ +// $Id: AtlantiCodes.java,v 1.5 2002/05/21 04:45:10 mdb Exp $ package com.threerings.venison; @@ -8,6 +8,9 @@ package com.threerings.venison; */ public interface VenisonCodes { + /** The message bundle identifier for translation messages. */ + public static final String VENISON_MESSAGE_BUNDLE = "venison"; + /** The number of piecens provided to each player. */ public static final int PIECENS_PER_PLAYER = 7; diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.dobj b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.dobj new file mode 100644 index 00000000..e2f6e5d1 --- /dev/null +++ b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.dobj @@ -0,0 +1,46 @@ +// +// $Id: AtlantiObject.dobj,v 1.1 2002/05/21 04:45:10 mdb Exp $ + +package com.threerings.venison; + +import com.samskivert.util.StringUtil; +import com.threerings.presents.dobj.DSet; +import com.threerings.parlor.game.GameObject; +import com.threerings.parlor.turn.TurnGameObject; + +/** + * The distributed object used to maintain state for the Venison game. + */ +public class VenisonObject extends GameObject + implements TurnGameObject +{ + /** The username of the current turn holder. */ + public String turnHolder; + + /** A set containing all of the tiles that are in play in this + * game. */ + public DSet tiles = new DSet(VenisonTile.class); + + /** The tile being placed by the current turn holder. This value is + * only valid while it is someone's turn. */ + public VenisonTile currentTile = VenisonTile.STARTING_TILE; + + /** A set containing all of the piecens that are placed on the + * board. */ + public DSet piecens = new DSet(Piecen.class); + + /** The scores for each player. */ + public int[] scores; + + // documentation inherited from interface + public String getTurnHolderFieldName () + { + return TURN_HOLDER; + } + + // documentation inherited from interface + public String getTurnHolder () + { + return turnHolder; + } +} diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.java b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.java index d622eef4..84550ef9 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiObject.java @@ -1,17 +1,22 @@ // -// $Id: AtlantiObject.java,v 1.7 2001/10/17 04:34:14 mdb Exp $ +// $Id: AtlantiObject.java,v 1.8 2002/05/21 04:45:10 mdb Exp $ package com.threerings.venison; import com.samskivert.util.StringUtil; import com.threerings.presents.dobj.DSet; +import com.threerings.parlor.game.GameObject; import com.threerings.parlor.turn.TurnGameObject; /** * The distributed object used to maintain state for the Venison game. */ -public class VenisonObject extends TurnGameObject +public class VenisonObject extends GameObject + implements TurnGameObject { + /** The field name of the turnHolder field. */ + public static final String TURN_HOLDER = "turnHolder"; + /** The field name of the tiles field. */ public static final String TILES = "tiles"; @@ -24,6 +29,9 @@ public class VenisonObject extends TurnGameObject /** The field name of the scores field. */ public static final String SCORES = "scores"; + /** The username of the current turn holder. */ + public String turnHolder; + /** A set containing all of the tiles that are in play in this * game. */ public DSet tiles = new DSet(VenisonTile.class); @@ -39,103 +47,163 @@ public class VenisonObject extends TurnGameObject /** The scores for each player. */ public int[] scores; - /** - * Requests that the tiles field be set to the specified - * value. - */ - public void setTiles (DSet value) + // documentation inherited from interface + public String getTurnHolderFieldName () { - requestAttributeChange(TILES, value); + return TURN_HOLDER; + } + + // documentation inherited from interface + public String getTurnHolder () + { + return turnHolder; } /** - * Requests that the specified element be added to the - * tiles set. + * Requests that the turnHolder field be set to the specified + * value. The local value will be updated immediately and an event + * will be propagated through the system to notify all listeners that + * the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. */ - public void addToTiles (DSet.Element elem) + public void setTurnHolder (String turnHolder) { - requestElementAdd(TILES, elem); + this.turnHolder = turnHolder; + requestAttributeChange(TURN_HOLDER, turnHolder); } /** - * Requests that the element matching the supplied key be removed from - * the tiles set. + * Requests that the specified entry be added to the + * tiles set. The set will not change until the event is + * actually propagated through the system. + */ + public void addToTiles (DSet.Entry elem) + { + requestEntryAdd(TILES, elem); + } + + /** + * Requests that the entry matching the supplied key be removed from + * the tiles set. The set will not change until the + * event is actually propagated through the system. */ public void removeFromTiles (Object key) { - requestElementRemove(TILES, key); + requestEntryRemove(TILES, key); } /** - * Requests that the specified element be updated in the - * tiles set. + * Requests that the specified entry be updated in the + * tiles set. The set will not change until the event is + * actually propagated through the system. */ - public void updateTiles (DSet.Element elem) + public void updateTiles (DSet.Entry elem) { - requestElementUpdate(TILES, elem); + requestEntryUpdate(TILES, elem); } /** - * Requests that the currentTile field be set to the - * specified value. + * Requests that the tiles field be set to the + * specified value. Generally one only adds, updates and removes + * entries of a distributed set, but certain situations call for a + * complete replacement of the set value. The local value will be + * updated immediately and an event will be propagated through the + * system to notify all listeners that the attribute did + * change. Proxied copies of this object (on clients) will apply the + * value change when they received the attribute changed notification. */ - public void setCurrentTile (VenisonTile value) + public void setTiles (DSet tiles) { - requestAttributeChange(CURRENT_TILE, value); + this.tiles = tiles; + requestAttributeChange(TILES, tiles); } /** - * Requests that the piecens field be set to the specified - * value. + * Requests that the currentTile field be set to the specified + * value. The local value will be updated immediately and an event + * will be propagated through the system to notify all listeners that + * the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. */ - public void setPiecens (DSet value) + public void setCurrentTile (VenisonTile currentTile) { - requestAttributeChange(PIECENS, value); + this.currentTile = currentTile; + requestAttributeChange(CURRENT_TILE, currentTile); } /** - * Requests that the specified element be added to the - * piecens set. + * Requests that the specified entry be added to the + * piecens set. The set will not change until the event is + * actually propagated through the system. */ - public void addToPiecens (DSet.Element elem) + public void addToPiecens (DSet.Entry elem) { - requestElementAdd(PIECENS, elem); + requestEntryAdd(PIECENS, elem); } /** - * Requests that the element matching the supplied key be removed from - * the piecens set. + * Requests that the entry matching the supplied key be removed from + * the piecens set. The set will not change until the + * event is actually propagated through the system. */ public void removeFromPiecens (Object key) { - requestElementRemove(PIECENS, key); + requestEntryRemove(PIECENS, key); } /** - * Requests that the specified element be updated in the - * piecens set. + * Requests that the specified entry be updated in the + * piecens set. The set will not change until the event is + * actually propagated through the system. */ - public void updatePiecens (DSet.Element elem) + public void updatePiecens (DSet.Entry elem) { - requestElementUpdate(PIECENS, elem); + requestEntryUpdate(PIECENS, elem); + } + + /** + * Requests that the piecens field be set to the + * specified value. Generally one only adds, updates and removes + * entries of a distributed set, but certain situations call for a + * complete replacement of the set value. The local value will be + * updated immediately and an event will be propagated through the + * system to notify all listeners that the attribute did + * change. Proxied copies of this object (on clients) will apply the + * value change when they received the attribute changed notification. + */ + public void setPiecens (DSet piecens) + { + this.piecens = piecens; + requestAttributeChange(PIECENS, piecens); } /** * Requests that the scores field be set to the specified - * value. + * value. The local value will be updated immediately and an event + * will be propagated through the system to notify all listeners that + * the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. */ - public void setScores (int[] value) + public void setScores (int[] scores) { - requestAttributeChange(SCORES, value); + this.scores = scores; + requestAttributeChange(SCORES, scores); } - // documentation inherited - protected void toString (StringBuffer buf) + /** + * Requests that the indexth element of + * scores field be set to the specified value. The local + * value will be updated immediately and an event will be propagated + * through the system to notify all listeners that the attribute did + * change. Proxied copies of this object (on clients) will apply the + * value change when they received the attribute changed notification. + */ + public void setScoresAt (int value, int index) { - super.toString(buf); - buf.append(", tiles=").append(tiles); - buf.append(", currentTile=").append(currentTile); - buf.append(", piecens=").append(piecens); - buf.append(", scores=").append(StringUtil.toString(scores)); + this.scores[index] = value; + requestElementUpdate(SCORES, new Integer(value), index); } } diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiTile.java b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiTile.java index 1a1e015d..274ac49c 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiTile.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/data/AtlantiTile.java @@ -1,5 +1,5 @@ // -// $Id: AtlantiTile.java,v 1.13 2001/12/18 11:58:54 mdb Exp $ +// $Id: AtlantiTile.java,v 1.14 2002/05/21 04:45:10 mdb Exp $ package com.threerings.venison; @@ -21,7 +21,6 @@ import java.util.List; import com.samskivert.util.IntTuple; import com.samskivert.util.StringUtil; -import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.Tile; import com.threerings.media.tile.TileManager; import com.threerings.media.tile.UniformTileSet; @@ -32,7 +31,7 @@ import com.threerings.presents.dobj.DSet; * Represents a single tile in play on the Venison game board. */ public class VenisonTile - implements DSet.Element, TileCodes, Cloneable, Comparable + implements DSet.Entry, TileCodes, Cloneable, Comparable { /** The starting tile. */ public static final VenisonTile STARTING_TILE = @@ -476,18 +475,7 @@ public class VenisonTile } // fetch the tile - try { - Tile tile = _tset.getTile(type-1); - if (tile != null) { - return tile.getImage(); - } - - } catch (NoSuchTileException nste) { - // fall through - } - - Log.warning("Unable to load tile image [type=" + type + "]."); - return null; + return _tset.getTileImage(type-1); } /** @@ -506,14 +494,7 @@ public class VenisonTile } // fetch the tile - try { - return _stset.getTileImage(0); - } catch (NoSuchTileException nste) { - // fall through - } - - Log.warning("Unable to load shield image!"); - return null; + return _stset.getTileImage(0); } /** The tile image that we use to render this tile. */ diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/data/Piecen.java b/projects/atlanti/src/java/com/samskivert/atlanti/data/Piecen.java index 78157828..90b8f016 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/data/Piecen.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/data/Piecen.java @@ -1,5 +1,5 @@ // -// $Id: Piecen.java,v 1.2 2001/10/17 23:27:52 mdb Exp $ +// $Id: Piecen.java,v 1.3 2002/05/21 04:45:09 mdb Exp $ package com.threerings.venison; @@ -25,7 +25,7 @@ import com.threerings.presents.dobj.DSet; * points for the group. */ public class Piecen - implements DSet.Element + implements DSet.Entry { /** A color constant. */ public static final int RED = 0; diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManager.java b/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManager.java index 972edc75..b1080566 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManager.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManager.java @@ -1,5 +1,5 @@ // -// $Id: AtlantiManager.java,v 1.22 2002/01/29 23:46:37 mdb Exp $ +// $Id: AtlantiManager.java,v 1.23 2002/05/21 04:45:10 mdb Exp $ package com.threerings.venison; @@ -12,34 +12,50 @@ import java.util.List; import com.samskivert.util.HashIntMap; import com.samskivert.util.StringUtil; -import com.threerings.presents.dobj.ElementAddedEvent; -import com.threerings.presents.dobj.ElementRemovedEvent; -import com.threerings.presents.dobj.ElementUpdatedEvent; +import com.threerings.presents.dobj.EntryAddedEvent; +import com.threerings.presents.dobj.EntryRemovedEvent; +import com.threerings.presents.dobj.EntryUpdatedEvent; import com.threerings.presents.dobj.DSet; import com.threerings.presents.dobj.SetListener; import com.threerings.presents.dobj.MessageEvent; -import com.threerings.crowd.chat.ChatMessageHandler; +import com.threerings.presents.dobj.MessageEvent; + import com.threerings.crowd.chat.ChatProvider; +import com.threerings.crowd.data.PlaceObject; + +import com.threerings.crowd.chat.ChatMessageHandler; import com.threerings.crowd.chat.ChatService; +import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.server.PlaceManager; +import com.threerings.parlor.game.GameManager; import com.threerings.parlor.turn.TurnGameManager; /** * The main coordinator of the Venison game on the server side. */ -public class VenisonManager - extends TurnGameManager implements VenisonCodes, SetListener +public class VenisonManager extends GameManager + implements TurnGameManager, VenisonCodes, SetListener { + public VenisonManager () + { + addDelegate(_delegate = new VenisonManagerDelegate(this)); + } + // documentation inherited protected Class getPlaceObjectClass () { return VenisonObject.class; } + public int getTilesInBox () + { + return _tilesInBox.size(); + } + // documentation inherited - protected void didInit () + public void didInit () { super.didInit(); @@ -54,7 +70,7 @@ public class VenisonManager } // documentation inherited - protected void didStartup () + public void didStartup () { super.didStartup(); @@ -98,52 +114,35 @@ public class VenisonManager _tiles.add(start); } - protected void turnWillStart () + // documentation inherited + public void turnWillStart () { - super.turnWillStart(); - // let the players know what the next tile is that should be // played VenisonTile tile = (VenisonTile)_tilesInBox.remove(0); _venobj.setCurrentTile(tile); } - protected void turnDidEnd () + // documentation inherited + public void turnDidEnd () { - super.turnDidEnd(); - // if there are no tiles left, we end the game if (_tilesInBox.size() == 0) { endGame(); } } - /** - * Continue the game until we're out of tiles. - */ - protected void setNextTurnHolder () - { - // if we have tiles left, we move to the next player as normal - if (_tilesInBox.size() > 0) { - super.setNextTurnHolder(); - } else { - // if we don't, we ensure that a new turn isn't started by - // setting _turnIdx to -1 - _turnIdx = -1; - } - } - /** * At the end of the game, we need to compute the final scores. */ protected void gameDidEnd () { super.gameDidEnd(); - + // compute the final scores by iterating over each tile and // scoring its features Piecen[] piecens = getPiecens(); - Iterator iter = _venobj.tiles.elements(); + Iterator iter = _venobj.tiles.entries(); while (iter.hasNext()) { VenisonTile tile = (VenisonTile)iter.next(); scoreFeatures(tile, piecens, true); @@ -165,7 +164,7 @@ public class VenisonManager { // create a piecen array that we can manipulate while scoring Piecen[] piecens = new Piecen[_venobj.piecens.size()]; - Iterator iter = _venobj.piecens.elements(); + Iterator iter = _venobj.piecens.entries(); for (int i = 0; iter.hasNext(); i++) { piecens[i] = (Piecen)iter.next(); } @@ -177,7 +176,7 @@ public class VenisonManager * * @param tile the tile whose features should be scored. * @param piecens an array of the pieces on the board which we can - * manipulate directly without having to wait for element removed + * manipulate directly without having to wait for entry removed * events to be dispatched. * @param finalTally during the final tally, we score differently and * we don't remove piecens from the board as we score them. @@ -236,7 +235,8 @@ public class VenisonManager String message = qual + " " + TileCodes.FEATURE_NAMES[f.type] + " scored " + score + " points for " + names + "."; - ChatProvider.sendSystemMessage(_venobj.getOid(), message); + ChatProvider.sendSystemMessage( + _venobj.getOid(), VENISON_MESSAGE_BUNDLE, message); Log.info("New scores: " + StringUtil.toString(_venobj.scores)); @@ -309,7 +309,7 @@ public class VenisonManager String message = _players[p.owner] + " scored " + score + " points for " + qual + " temple."; ChatProvider.sendSystemMessage( - _venobj.getOid(), message); + _venobj.getOid(), VENISON_MESSAGE_BUNDLE, message); // add the score to the owning player _venobj.scores[p.owner] += score; @@ -413,7 +413,7 @@ public class VenisonManager int[] pcount = new int[_players.length]; int max = 0; - Iterator piter = _venobj.piecens.elements(); + Iterator piter = _venobj.piecens.entries(); while (piter.hasNext()) { Piecen p = (Piecen)piter.next(); // see if the piecen is on any of the farms @@ -456,7 +456,8 @@ public class VenisonManager _venobj.scores[i] += cityScores[i]; String message = _players[i] + " scores " + cityScores[i] + " points for fisheries."; - ChatProvider.sendSystemMessage(_venobj.getOid(), message); + ChatProvider.sendSystemMessage( + _venobj.getOid(), VENISON_MESSAGE_BUNDLE, message); } } } @@ -523,7 +524,7 @@ public class VenisonManager // if this isn't the final tally, we also clear 'em from the board if (!finalTally) { - Iterator iter = _venobj.piecens.elements(); + Iterator iter = _venobj.piecens.entries(); while (iter.hasNext()) { Piecen p = (Piecen)iter.next(); if (p.claimGroup == claimGroup) { @@ -561,7 +562,7 @@ public class VenisonManager } // documentation inherited - public void elementAdded (ElementAddedEvent event) + public void entryAdded (EntryAddedEvent event) { // we react to piecen additions by potentially scoring the placed // piecen. we allow the piecen to be added to the piecens set @@ -569,7 +570,7 @@ public class VenisonManager // their screen and then disappear with a scoring notice rather // than never show up at all; plus it simplifies our code if (event.getName().equals(VenisonObject.PIECENS)) { - Piecen piecen = (Piecen)event.getElement(); + Piecen piecen = (Piecen)event.getEntry(); // make sure this is a valid placement VenisonTile tile = (VenisonTile)_venobj.tiles.get(piecen.getKey()); @@ -584,64 +585,133 @@ public class VenisonManager } // now that we've scored the piecen, we can end the turn - endTurn(); + _delegate.endTurn(); } } // documentation inherited - public void elementUpdated (ElementUpdatedEvent event) + public void entryUpdated (EntryUpdatedEvent event) { } // documentation inherited - public void elementRemoved (ElementRemovedEvent event) + public void entryRemoved (EntryRemovedEvent event) { } + /** + * Called when the user requests to place a tile. + */ + protected void handlePlaceTileRequest (MessageEvent event) + { + VenisonTile tile = (VenisonTile)event.getArgs()[0]; + int pidx = _delegate.getTurnHolderIndex(); + + // make sure it's this player's turn + if (_playerOids[pidx] != event.getSourceOid()) { + Log.warning("Requested to place tile by non-turn holder " + + "[event=" + event + + ", turnHolder=" + _venobj.turnHolder + "]."); + + // make sure this is a valid placement + } else if (TileUtil.isValidPlacement(_tiles, tile)) { + // add the tile to the list and resort it + _tiles.add(tile); + Collections.sort(_tiles); + + // inherit its claim groups + TileUtil.inheritClaims(_tiles, tile); + + // add the tile to the tiles set + _venobj.addToTiles(tile); + + // placing a piece may have completed road or city + // features. if it did, we score them now + scoreFeatures(tile, getPiecens(), false); + + Log.info("Placed tile " + tile + "."); + + // if the player has no free piecens or if there are no + // unclaimed features on this tile, we end their turn + // straight away + int pcount = TileUtil.countPiecens(_venobj.piecens, pidx); + if (pcount >= PIECENS_PER_PLAYER || + !tile.hasUnclaimedFeature()) { + _delegate.endTurn(); + } + + } else { + Log.warning("Received invalid placement " + event + "."); + } + } + + /** + * Called when the user requests to place a piecen. + */ + protected void handlePlacePiecenRequest (MessageEvent event) + { + Piecen piecen = (Piecen)event.getArgs()[0]; + VenisonTile tile = (VenisonTile)_venobj.tiles.get(piecen.getKey()); + int pidx = _delegate.getTurnHolderIndex(); + int pcount = TileUtil.countPiecens(_venobj.piecens, pidx); + + // make sure it's this player's turn + if (_playerOids[pidx] != event.getSourceOid()) { + Log.warning("Requested to place piecen by non-turn holder " + + "[event=" + event + + ", turnHolder=" + _venobj.turnHolder + "]."); + + // do some checking before we place the piecen + } else if (pcount >= PIECENS_PER_PLAYER) { + Log.warning("Requested to place piecen for player that " + + "has all of their piecens in play " + + "[event=" + event + "]."); + + } else if (tile == null) { + Log.warning("Can't find tile for requested piecen " + + "placement " + piecen + "."); + + } else if (tile.claims[piecen.featureIndex] != 0) { + Log.warning("Requested to place piecen on claimed feature " + + "[tile=" + tile + ", piecen=" + piecen + "]."); + + } else { + // otherwise stick the piece in the tile to update the + // claim groups + tile.setPiecen(piecen, _tiles); + + // and add the piecen to the game object. when we receive + // the piecen added event, we'll score it and then end the + // turn + _venobj.addToPiecens(piecen); + } + } + + /** + * Called when the user requests to forgo their piecen placement for + * this turn. + */ + protected void handlePlaceNothingRequest (MessageEvent event) + { + int pidx = _delegate.getTurnHolderIndex(); + if (_playerOids[pidx] != event.getSourceOid()) { + Log.warning("Requested to place nothing by non-turn holder " + + "[event=" + event + + ", turnHolder=" + _venobj.turnHolder + "]."); + + } else { + // player doesn't want to place anything, so we just end + // the turn + _delegate.endTurn(); + } + } + /** Handles place tile requests. */ protected class PlaceTileHandler implements MessageHandler { public void handleEvent (MessageEvent event, PlaceManager pmgr) { - VenisonTile tile = (VenisonTile)event.getArgs()[0]; - int pidx = getTurnHolderIndex(); - - // make sure it's this player's turn - if (_playerOids[pidx] != event.getSourceOid()) { - Log.warning("Requested to place tile by non-turn holder " + - "[event=" + event + - ", turnHolder=" + _venobj.turnHolder + "]."); - - // make sure this is a valid placement - } else if (TileUtil.isValidPlacement(_tiles, tile)) { - // add the tile to the list and resort it - _tiles.add(tile); - Collections.sort(_tiles); - - // inherit its claim groups - TileUtil.inheritClaims(_tiles, tile); - - // add the tile to the tiles set - _venobj.addToTiles(tile); - - // placing a piece may have completed road or city - // features. if it did, we score them now - scoreFeatures(tile, getPiecens(), false); - - Log.info("Placed tile " + tile + "."); - - // if the player has no free piecens or if there are no - // unclaimed features on this tile, we end their turn - // straight away - int pcount = TileUtil.countPiecens(_venobj.piecens, pidx); - if (pcount >= PIECENS_PER_PLAYER || - !tile.hasUnclaimedFeature()) { - endTurn(); - } - - } else { - Log.warning("Received invalid placement " + event + "."); - } + handlePlaceTileRequest(event); } } @@ -650,41 +720,7 @@ public class VenisonManager { public void handleEvent (MessageEvent event, PlaceManager pmgr) { - Piecen piecen = (Piecen)event.getArgs()[0]; - VenisonTile tile = (VenisonTile)_venobj.tiles.get(piecen.getKey()); - int pidx = getTurnHolderIndex(); - int pcount = TileUtil.countPiecens(_venobj.piecens, pidx); - - // make sure it's this player's turn - if (_playerOids[pidx] != event.getSourceOid()) { - Log.warning("Requested to place piecen by non-turn holder " + - "[event=" + event + - ", turnHolder=" + _venobj.turnHolder + "]."); - - // do some checking before we place the piecen - } else if (pcount >= PIECENS_PER_PLAYER) { - Log.warning("Requested to place piecen for player that " + - "has all of their piecens in play " + - "[event=" + event + "]."); - - } else if (tile == null) { - Log.warning("Can't find tile for requested piecen " + - "placement " + piecen + "."); - - } else if (tile.claims[piecen.featureIndex] != 0) { - Log.warning("Requested to place piecen on claimed feature " + - "[tile=" + tile + ", piecen=" + piecen + "]."); - - } else { - // otherwise stick the piece in the tile to update the - // claim groups - tile.setPiecen(piecen, _tiles); - - // and add the piecen to the game object. when we receive - // the piecen added event, we'll score it and then end the - // turn - _venobj.addToPiecens(piecen); - } + handlePlacePiecenRequest(event); } } @@ -693,20 +729,13 @@ public class VenisonManager { public void handleEvent (MessageEvent event, PlaceManager pmgr) { - int pidx = getTurnHolderIndex(); - if (_playerOids[pidx] != event.getSourceOid()) { - Log.warning("Requested to place nothing by non-turn holder " + - "[event=" + event + - ", turnHolder=" + _venobj.turnHolder + "]."); - - } else { - // player doesn't want to place anything, so we just end - // the turn - endTurn(); - } + handlePlaceNothingRequest(event); } } + /** Our turn game delegate. */ + protected VenisonManagerDelegate _delegate; + /** A casted reference to our Venison game object. */ protected VenisonObject _venobj; diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManagerDelegate.java b/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManagerDelegate.java new file mode 100644 index 00000000..57094c46 --- /dev/null +++ b/projects/atlanti/src/java/com/samskivert/atlanti/server/AtlantiManagerDelegate.java @@ -0,0 +1,40 @@ +// +// $Id: AtlantiManagerDelegate.java,v 1.1 2002/05/21 04:45:10 mdb Exp $ + +package com.threerings.venison; + +import com.threerings.parlor.turn.TurnGameManagerDelegate; + +/** + * Handles the turn-based gameplay. + */ +public class VenisonManagerDelegate extends TurnGameManagerDelegate + implements VenisonCodes +{ + /** + * Constructs the delegate and prepares it for operation. + */ + public VenisonManagerDelegate (VenisonManager vmgr) + { + super(vmgr); + _vmgr = vmgr; + } + + /** + * Continue the game until we're out of tiles. + */ + protected void setNextTurnHolder () + { + // if we have tiles left, we move to the next player as normal + if (_vmgr.getTilesInBox() > 0) { + super.setNextTurnHolder(); + } else { + // if we don't, we ensure that a new turn isn't started by + // setting _turnIdx to -1 + _turnIdx = -1; + } + } + + /** The manager for whom we're delegating. */ + protected VenisonManager _vmgr; +} diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/util/PiecenUtil.java b/projects/atlanti/src/java/com/samskivert/atlanti/util/PiecenUtil.java index 3ff9f045..6b71f671 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/util/PiecenUtil.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/util/PiecenUtil.java @@ -1,5 +1,5 @@ // -// $Id: PiecenUtil.java,v 1.1 2001/12/18 11:59:09 mdb Exp $ +// $Id: PiecenUtil.java,v 1.2 2002/05/21 04:45:09 mdb Exp $ package com.threerings.venison; @@ -8,7 +8,6 @@ import java.awt.Image; import com.threerings.media.tile.Tile; import com.threerings.media.tile.TileManager; import com.threerings.media.tile.UniformTileSet; -import com.threerings.media.tile.NoSuchTileException; public class PiecenUtil { @@ -28,11 +27,7 @@ public class PiecenUtil // fetch the tile images _images = new Image[PIECEN_TYPES]; for (int i = 0; i < PIECEN_TYPES; i++) { - try { - _images[i] = piecenSet.getTileImage(i); - } catch (NoSuchTileException nste) { - Log.warning("Unable to obtain piecen tile [id=" + i + "]."); - } + _images[i] = piecenSet.getTileImage(i); } } diff --git a/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java b/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java index 5dbf1608..7f31f4ff 100644 --- a/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java +++ b/projects/atlanti/src/java/com/samskivert/atlanti/util/TileUtil.java @@ -1,5 +1,5 @@ // -// $Id: TileUtil.java,v 1.15 2001/11/08 08:00:22 mdb Exp $ +// $Id: TileUtil.java,v 1.16 2002/05/21 04:45:09 mdb Exp $ package com.threerings.venison; @@ -571,7 +571,7 @@ public class TileUtil implements TileCodes public static int countPiecens (DSet piecens, int playerIndex) { int count = 0; - Iterator iter = piecens.elements(); + Iterator iter = piecens.entries(); while (iter.hasNext()) { if (((Piecen)iter.next()).owner == playerIndex) { count++;