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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user