Be more robust about selecting random components.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1158 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: CastUtil.java,v 1.7 2002/03/27 20:31:11 mdb Exp $
|
// $Id: CastUtil.java,v 1.8 2002/03/27 21:48:41 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.cast.util;
|
package com.threerings.cast.util;
|
||||||
|
|
||||||
@@ -33,12 +33,23 @@ public class CastUtil
|
|||||||
for (int i = 0; i < CLASSES.length; i++) {
|
for (int i = 0; i < CLASSES.length; i++) {
|
||||||
String cname = gender + "/" + CLASSES[i];
|
String cname = gender + "/" + CLASSES[i];
|
||||||
ComponentClass cclass = crepo.getComponentClass(cname);
|
ComponentClass cclass = crepo.getComponentClass(cname);
|
||||||
|
|
||||||
|
// make sure the component class exists
|
||||||
if (cclass == null) {
|
if (cclass == null) {
|
||||||
Log.warning("Missing definition for component class " +
|
Log.warning("Missing definition for component class " +
|
||||||
"[class=" + cname + "].");
|
"[class=" + cname + "].");
|
||||||
} else {
|
continue;
|
||||||
classes.add(cclass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure there are some components in this class
|
||||||
|
Iterator iter = crepo.enumerateComponentIds(cclass);
|
||||||
|
if (!iter.hasNext()) {
|
||||||
|
Log.info("Skipping class for which we have no components " +
|
||||||
|
"[class=" + cclass + "].");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
classes.add(cclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select the components
|
// select the components
|
||||||
@@ -53,8 +64,12 @@ public class CastUtil
|
|||||||
CollectionUtil.addAll(choices, iter);
|
CollectionUtil.addAll(choices, iter);
|
||||||
|
|
||||||
// choose a random component
|
// choose a random component
|
||||||
int idx = RandomUtil.getInt(choices.size());
|
if (choices.size() > 0) {
|
||||||
components[ii] = ((Integer)choices.get(idx)).intValue();
|
int idx = RandomUtil.getInt(choices.size());
|
||||||
|
components[ii] = ((Integer)choices.get(idx)).intValue();
|
||||||
|
} else {
|
||||||
|
Log.info("Have no components in class [class=" + cclass + "].");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CharacterDescriptor(components, null);
|
return new CharacterDescriptor(components, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user