From 3d71bd858a6e95ca521221bdc3dac0579cd43f02 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 25 Jun 2002 01:41:59 +0000 Subject: [PATCH] added a getUnoccupiedLocation() that only gets a location within a specified cluster. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1540 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../whirled/spot/util/SpotSceneUtil.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/whirled/spot/util/SpotSceneUtil.java b/src/java/com/threerings/whirled/spot/util/SpotSceneUtil.java index d9ab05d8f..9ca9abfd9 100644 --- a/src/java/com/threerings/whirled/spot/util/SpotSceneUtil.java +++ b/src/java/com/threerings/whirled/spot/util/SpotSceneUtil.java @@ -1,5 +1,5 @@ // -// $Id: SpotSceneUtil.java,v 1.1 2002/06/20 22:14:58 mdb Exp $ +// $Id: SpotSceneUtil.java,v 1.2 2002/06/25 01:41:59 ray Exp $ package com.threerings.whirled.spot.util; @@ -87,6 +87,38 @@ public class SpotSceneUtil } } + /** + * Return an unoccupied location within the specified cluster. + */ + public static int getUnoccupiedLocation ( + SpotSceneModel model, DSet occupantInfo, int clusterId) + { + ArrayIntSet locs = new ArrayIntSet(); + + // only add locations with a valid cluster Id + for (int ii=0; ii < model.locationIds.length; ii++) { + if (model.locationClusters[ii] == clusterId) { + locs.add(model.locationIds[ii]); + } + } + + // remove any occupied locations + Iterator iter = occupantInfo.entries(); + while (iter.hasNext()) { + SpotOccupantInfo yoi = (SpotOccupantInfo)iter.next(); + locs.remove(yoi.locationId); + } + + // if there are locations left, pick one at random + int size = locs.size(); + if (size > 0) { + return locs.get(RandomUtil.getInt(size)); + + } else { + return -1; // we didn't find anything. + } + } + /** Used by {@link #getUnoccupiedLocation}. */ protected static ArrayIntSet getStartSet ( SpotSceneModel model, boolean preferClusters)