|
From: <boo...@us...> - 2006-11-01 04:33:55
|
Revision: 1566
http://svn.sourceforge.net/pcgen/?rev=1566&view=rev
Author: boomer70
Date: 2006-10-31 20:33:42 -0800 (Tue, 31 Oct 2006)
Log Message:
-----------
NPC Generator v 0.002
* Fixed a few bugs in picking skills
* Added support for Deity/Domain selection (not in data file yet).
Modified Paths:
--------------
Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassData.java
Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassDataParser.java
Trunk/pcgen/code/src/java/pcgen/core/npcgen/Configuration.java
Trunk/pcgen/code/src/java/pcgen/core/npcgen/NPCGenerator.java
Trunk/pcgen/code/src/java/pcgen/core/npcgen/SkillChoice.java
Trunk/pcgen/code/src/java/pcgen/gui/NPCGeneratorDlg.java
Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties
Trunk/pcgen/code/src/java/pcgen/util/WeightedList.java
Trunk/pcgen/code/src/java/pcgen/util/chooser/RandomChooser.java
Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassData.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassData.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassData.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -29,6 +29,8 @@
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.Categorisable;
+import pcgen.core.Deity;
+import pcgen.core.Domain;
import pcgen.core.Globals;
import pcgen.core.PCStat;
import pcgen.core.SettingsHandler;
@@ -50,6 +52,8 @@
private WeightedList<String> theStatWeights = null;
private WeightedList<SkillChoice> theSkillWeights = null;
private Map<AbilityCategory, WeightedList<Ability>> theAbilityWeights = null;
+ private WeightedList<Deity> theDeityWeights = null;
+ private Map<String, WeightedList<Domain>> theDomainWeights = null;
/**
* Creates an empty <tt>ClassData</tt> object
@@ -93,7 +97,7 @@
{
if ( theStatWeights == null || theStatWeights.contains(stat.getAbb()) == false )
{
- theStatWeights.add(1, stat.getAbb());
+ addStat(stat.getAbb(), 1);
}
}
return theStatWeights;
@@ -209,4 +213,62 @@
}
return theAbilityWeights.get(aCategory);
}
+
+ public void addDeity( final Deity aDeity, final int aWeight )
+ {
+ if ( theDeityWeights == null )
+ {
+ theDeityWeights = new WeightedList<Deity>();
+ }
+
+ theDeityWeights.add(aWeight, aDeity);
+ }
+
+ public WeightedList<Deity> getDeityWeights()
+ {
+ if ( theDeityWeights == null )
+ {
+ for ( final Deity deity : Globals.getDeityList() )
+ {
+ addDeity(deity, 1);
+ }
+ }
+ return theDeityWeights;
+ }
+
+ public void addDomain( final String aDeityKey, final Domain aDomain, final int aWeight )
+ {
+ if ( theDomainWeights == null )
+ {
+ theDomainWeights = new HashMap<String, WeightedList<Domain>>();
+ }
+ WeightedList<Domain> domains = theDomainWeights.get(aDeityKey);
+ if ( domains == null )
+ {
+ domains = new WeightedList<Domain>();
+ theDomainWeights.put( aDeityKey, domains );
+ }
+ domains.add(aWeight, aDomain);
+ }
+
+ public WeightedList<Domain> getDomainWeights( final String aDeityKey )
+ {
+ if ( theDomainWeights == null )
+ {
+ theDomainWeights = new HashMap<String, WeightedList<Domain>>();
+ }
+ WeightedList<Domain> domains = theDomainWeights.get(aDeityKey);
+ if ( domains == null )
+ {
+ domains = new WeightedList<Domain>();
+
+ final Deity deity = Globals.getDeityKeyed(aDeityKey);
+ final List<Domain> deityDomains = deity.getDomainList();
+ for ( final Domain domain : deityDomains )
+ {
+ domains.add(1, domain);
+ }
+ }
+ return domains;
+ }
}
Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassDataParser.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassDataParser.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/ClassDataParser.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -39,7 +39,6 @@
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.Categorisable;
-import pcgen.core.Constants;
import pcgen.core.GameMode;
import pcgen.core.Globals;
import pcgen.core.PCClass;
@@ -62,9 +61,9 @@
private GameMode theMode;
/**
- * Creates a new OptionsParser for the specified game mode.
+ * Creates a new <tt>ClassDataParser</tt> for the specified game mode.
*
- * @param aMode The game mode to parse options for.
+ * @param aMode The game mode to parse class options for.
*
* @throws ParserConfigurationException
* @throws SAXException
@@ -80,8 +79,13 @@
}
/**
+ * Parses a XML class data options file.
+ *
* @param aFileName File to parse.
- * @return
+ *
+ * @return A <tt>List</tt> of <tt>ClassData</tt> objects representing the
+ * options in the file.
+ *
* @throws SAXException
* @throws IOException
*/
@@ -102,6 +106,14 @@
}
}
+/**
+ * This is the parsing event handler class. The methods in this class are
+ * called by the SAX parser as it finds various elements in the XML file.
+ *
+ * @author boomer70 <boo...@ya...>
+ *
+ * @since 5.11.1
+ */
class ClassDataHandler extends DefaultHandler
{
private List<ClassData> theList;
@@ -109,7 +121,21 @@
private GameMode theGameMode = null;
private boolean theValidFlag = false;
- private enum ParserState { INIT, CLASSDATA, STATDATA, SKILLDATA, ABILITYDATA };
+ /** An enum for the current state in the state machine the parser is in */
+ private enum ParserState
+ {
+ /** The initial state of the parser */
+ INIT,
+ /** Found a class tag */
+ CLASSDATA,
+ /** Found stat data */
+ STATDATA,
+ /** Found skill data */
+ SKILLDATA,
+ /** Found Ability data */
+ ABILITYDATA
+ }
+
private ParserState theState = ParserState.INIT;
private ClassData theCurrentData = null;
@@ -120,6 +146,12 @@
private int remainingWeight = -1;
private List<String> removeList = new ArrayList<String>();
+ /**
+ * Constructs the handler
+ *
+ * @param aMode The game mode to expect the file to be for.
+ * @param aList The list of <tt>ClassData</tt> objects to fill
+ */
public ClassDataHandler( final GameMode aMode, final List<ClassData> aList )
{
theGameMode = aMode;
@@ -208,7 +240,7 @@
if ( anAttrs != null )
{
final int weight = getWeight(anAttrs);
- final String statAbbr = anAttrs.getValue("value");
+ final String statAbbr = anAttrs.getValue("value"); //$NON-NLS-1$
if ( statAbbr != null )
{
theCurrentData.addStat(statAbbr, weight);
@@ -247,7 +279,7 @@
Logging.debugPrint("NPCGenerator: Skill not found (" + key + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- if ( weight > 0 )
+ if ( weight > 0 && !key.equals("*") ) //$NON-NLS-1$
{
theCurrentData.addSkill(key, weight);
}
@@ -324,8 +356,11 @@
}
}
+ /**
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
public void endElement(final String uri, final String localName, final String qName)
- throws SAXException
{
if ( "skills".equals(qName) && theState == ParserState.SKILLDATA ) //$NON-NLS-1$
{
@@ -349,7 +384,7 @@
removeList = new ArrayList<String>();
theState = ParserState.CLASSDATA;
}
- else if ( "abilities".equals(qName) && theState == ParserState.ABILITYDATA )
+ else if ( "abilities".equals(qName) && theState == ParserState.ABILITYDATA ) //$NON-NLS-1$
{
if ( remainingWeight > 0 )
{
@@ -373,12 +408,12 @@
theCurrentCategory = null;
theState = ParserState.CLASSDATA;
}
- else if ( "class".equals(qName) )
+ else if ( "class".equals(qName) ) //$NON-NLS-1$
{
theList.add(theCurrentData);
theState = ParserState.INIT;
}
- else if ( "stats".equals(qName) )
+ else if ( "stats".equals(qName) ) //$NON-NLS-1$
{
theState = ParserState.CLASSDATA;
}
Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/Configuration.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/npcgen/Configuration.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/Configuration.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -32,6 +32,8 @@
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.Constants;
+import pcgen.core.Deity;
+import pcgen.core.Domain;
import pcgen.core.GameMode;
import pcgen.core.Globals;
import pcgen.core.PCClass;
@@ -240,21 +242,41 @@
public WeightedList<SkillChoice> getSkillWeights(final String aKey)
{
- final ClassData data = theClassData.get(aKey);
- if ( data != null )
+ ClassData data = theClassData.get(aKey);
+ if ( data == null )
{
- return data.getSkillWeights();
+ data = new ClassData(Constants.EMPTY_STRING);
}
- return null;
+ return data.getSkillWeights();
}
public WeightedList<Ability> getAbilityWeights( final String aKey, final AbilityCategory aCategory )
{
- final ClassData data = theClassData.get(aKey);
- if ( data != null )
+ ClassData data = theClassData.get(aKey);
+ if ( data == null )
{
- return data.getAbilityWeights(aCategory);
+ data = new ClassData(Constants.EMPTY_STRING);
}
- return null;
+ return data.getAbilityWeights(aCategory);
}
+
+ public WeightedList<Deity> getDeityWeights( final String aKey )
+ {
+ ClassData data = theClassData.get( aKey );
+ if ( data == null )
+ {
+ data = new ClassData(Constants.EMPTY_STRING);
+ }
+ return data.getDeityWeights();
+ }
+
+ public WeightedList<Domain> getDomainWeights(final String aDeityKey, final String aClassKey )
+ {
+ ClassData data = theClassData.get( aClassKey );
+ if ( data == null )
+ {
+ data = new ClassData(Constants.EMPTY_STRING);
+ }
+ return data.getDomainWeights(aDeityKey);
+ }
}
Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/NPCGenerator.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/npcgen/NPCGenerator.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/NPCGenerator.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -22,23 +22,18 @@
*/
package pcgen.core.npcgen;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.AbilityUtilities;
import pcgen.core.Categorisable;
+import pcgen.core.CharacterDomain;
import pcgen.core.Constants;
+import pcgen.core.Deity;
+import pcgen.core.Domain;
import pcgen.core.GameMode;
import pcgen.core.Globals;
import pcgen.core.PCAlignment;
@@ -69,10 +64,6 @@
private static final NPCGenerator theInstance = new NPCGenerator();
private Configuration theConfiguration = null;
-
-// private Map<String, WeightedList<SkillChoice>> skillListMap = new HashMap<String, WeightedList<SkillChoice>>();
-// private HashMap statWeightMap = new HashMap();
-// private HashMap<String, WeightedList<Ability>> featListMap = new HashMap<String, WeightedList<Ability>>();
// Rule options
private int theSubSkillWeightAdd = 10;
@@ -320,8 +311,7 @@
}
}
- private WeightedList<Ability> getFeatWeights(final PCClass aClass,
- final PlayerCharacter aPC)
+ private WeightedList<Ability> getFeatWeights(final PCClass aClass)
{
WeightedList<Ability> weightedList = theConfiguration.getAbilityWeights(aClass.getKeyName(), AbilityCategory.FEAT);
if (weightedList == null)
@@ -339,7 +329,7 @@
{
continue;
}
- if (ability.isType("GENERAL"))
+ if (ability.isType("GENERAL")) //$NON-NLS-1$
{
weight = 5;
}
@@ -349,33 +339,92 @@
return weightedList;
}
- private void selectFeats(final PlayerCharacter aPC, final List aFeatList, final PCClass aClass, final int aLevel)
+ private void selectFeats(final PlayerCharacter aPC, final List<Ability> aFeatList)
{
while ((int)aPC.getFeats() > 0)
{
- final Object obj = aFeatList.get(Globals.getRandomInt(aFeatList.
- size()));
+ final Ability ability = aFeatList.get(Globals.getRandomInt(aFeatList.size()));
- Ability feat = null;
- if (obj instanceof WeightedList)
+ if (!PrereqHandler.passesAll(ability.getPreReqList(), aPC, ability))
{
- final WeightedList subList = (WeightedList) obj;
- feat = (Ability) subList.get(Globals.getRandomInt(aFeatList.
- size()));
+ // We will leave the feat because we may qualify later.
+ continue;
}
- else
+ AbilityUtilities.modFeat(aPC, null, ability.getKeyName(), true, false);
+ }
+ }
+
+ private void selectDeity( final PlayerCharacter aPC, final PCClass aClass )
+ {
+ // Copy the list since we may modify it
+ final List<Deity> deities = new WeightedList<Deity>(theConfiguration.getDeityWeights(aClass.getKeyName()));
+ boolean selected = false;
+ while ( deities.size() > 0 )
+ {
+ final Deity deity = deities.get(Globals.getRandomInt(deities.size()));
+ if ( aPC.canSelectDeity(deity))
{
- feat = (Ability) obj;
+ aPC.setDeity(deity);
+ selected = true;
+ break;
}
- if (!PrereqHandler.passesAll(feat.getPreReqList(), aPC, feat))
+ deities.remove(deity);
+ }
+ if ( selected == false )
+ {
+ Logging.errorPrintLocalised("NPCGen.Errors.CantSelectDeity"); //$NON-NLS-1$
+ }
+ }
+
+ private void selectDomains( final PlayerCharacter aPC, final PCClass aClass )
+ {
+ while (aPC.getCharacterDomainUsed() < aPC.getMaxCharacterDomains())
+ {
+ final List<Domain> domains = theConfiguration.getDomainWeights(aPC.getDeity().getKeyName(), aClass.getKeyName());
+ final Domain domain = domains.get(Globals.getRandomInt(domains.size()));
+ if ( ! domain.qualifiesForDomain(aPC) )
{
- // We will leave the feat because we may qualify later.
continue;
}
- AbilityUtilities.modFeat(aPC, null, feat.getKeyName(), true, false);
+
+ CharacterDomain aCD = aPC.getCharacterDomainForDomain(domain.getKeyName());
+
+ if (aCD == null)
+ {
+ aCD = aPC.getNewCharacterDomain();
+ }
+
+ // TODO - This seems kind of silly. How would this ever happen?
+ final Domain existingDomain = aCD.getDomain();
+
+ if ((existingDomain != null) && existingDomain.equals(domain))
+ {
+ aPC.removeCharacterDomain(aCD);
+ }
+
+ // space remains for another domain, so add it
+ if (existingDomain == null)
+ {
+ domain.setIsLocked(true, aPC);
+ aCD.setDomain(domain, aPC);
+ aPC.addCharacterDomain(aCD);
+
+ aPC.calcActiveBonuses();
+ }
}
}
-
+
+ /**
+ * Generate a new NPC
+ *
+ * @param aPC The PlayerCharacter to fill in options for
+ * @param align Alignment options to choose from
+ * @param aRace Race options to choose from
+ * @param aGender Gender options to choose from
+ * @param classList <tt>List</tt> of class options to choose from
+ * @param levels <tt>List</tt> of
+ * @param aRollMethod
+ */
public void generate( final PlayerCharacter aPC,
final AlignGeneratorOption align,
final RaceGeneratorOption aRace,
@@ -455,30 +504,38 @@
if (i == 0)
{
generateStats(aPC, aClass, aRollMethod);
+ selectDeity(aPC, aClass);
}
// Make a copy of the list because we are going to modify it.
- List skillList = new WeightedList(getSkillWeights(aClass, aPC));
- List featList = new WeightedList(getFeatWeights(aClass, aPC));
+ List<SkillChoice> skillList = new WeightedList<SkillChoice>(getSkillWeights(aClass, aPC));
+ List<Ability> featList = new WeightedList<Ability>(getFeatWeights(aClass));
for (int j = 0; j < numLevels; j++)
{
aPC.incrementClassLevel(1, aClass, true);
+ final PCClass pcClass = aPC.getClassKeyed(aClass.getKeyName());
selectSkills(aPC, skillList, aClass, j + 1);
- selectFeats(aPC, featList, aClass, j + 1);
+ selectFeats(aPC, featList);
+
+ selectDomains( aPC, aClass );
+
if ( !aClass.getSpellType().equals( Constants.s_NONE ) )
{
// This is a spellcasting class. We may have to select
// spells of some sort (known or prepared).
if ( aClass.getKnownList().size() > 0 || aClass.hasKnownSpells(aPC) )
{
- Logging.debugPrint("NPCGenerator: known spells to select");
+ Logging.debugPrint("NPCGenerator: known spells to select"); //$NON-NLS-1$
int highestSpellLevel = aClass.getHighestLevelSpell(aPC);
for (int lvl = 0; lvl <= highestSpellLevel; ++lvl)
{
- if (aPC.availableSpells(lvl, aClass, Globals.getDefaultSpellBook(), true, true))
+ if (aPC.availableSpells(lvl, pcClass, Globals.getDefaultSpellBook(), true, true))
{
- Logging.debugPrint("NPCGenerator: known spells to select");
+ final int a = pcClass.getKnownForLevel(pcClass.getLevel(), lvl, aPC);
+ final int bonus = pcClass.getSpecialtyKnownForLevel(pcClass
+ .getLevel(), lvl, aPC);
+ Logging.debugPrint("NPCGenerator: " + a + "known spells to select"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/SkillChoice.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/npcgen/SkillChoice.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/SkillChoice.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -29,6 +29,14 @@
import pcgen.util.WeightedList;
/**
+ * This class represents a potential skill choice. The class is needed because
+ * PCGen does not treat skill groups specially in the code but the user expects
+ * to treat them special.
+ *
+ * <p>As an example, if the user specifies that TYPE.Profession skills are to
+ * have a certain weight the assumption is that that weight applies to picking
+ * a single Profession skill and not to each Profession skill individually.
+ *
* @author boomer70 <boo...@ya...>
*
* @since 5.11.1
@@ -38,10 +46,18 @@
private String theKey = null;
private List<Skill> theSkillList = new WeightedList<Skill>();
+ /**
+ * Creates a new SkillChoice.
+ *
+ * <p>If the key passed in starts with "<code>TYPE.</code>", the
+ * group of skills of that type will be stored as this chice.
+ *
+ * @param aKey A Skill key or TYPE.<skill type>
+ */
public SkillChoice(final String aKey)
{
theKey = aKey;
- if ( theKey.startsWith("TYPE") )
+ if ( theKey.startsWith("TYPE") ) //$NON-NLS-1$
{
final List<Skill> subSkills = Globals.getSkillsByType(theKey.substring(5));
theSkillList.addAll( subSkills );
@@ -52,6 +68,12 @@
}
}
+ /**
+ * Gets the skill associated with this chioce. If this choice is a group
+ * of choices, the specific skill will be selected randomly.
+ *
+ * @return A <tt>Skill</tt>
+ */
public Skill getSkill()
{
final Skill skill = theSkillList.get(Globals.getRandomInt(theSkillList.size()));
@@ -59,6 +81,15 @@
return skill;
}
+ /**
+ * Checks if this <tt>SkillChoice</tt> has the specified skill as an option.
+ * That is, if this skill represents the same skill or if the skill is in
+ * the list of possible skill choices.
+ *
+ * @param aKey The Skill key to check.
+ *
+ * @return <tt>true</tt> if this choice contains the skill.
+ */
public boolean hasSkill( final String aKey )
{
if ( theKey.equals(aKey) )
@@ -85,6 +116,10 @@
return false;
}
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
public String toString()
{
return theSkillList.toString();
Modified: Trunk/pcgen/code/src/java/pcgen/gui/NPCGeneratorDlg.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/gui/NPCGeneratorDlg.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/gui/NPCGeneratorDlg.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -32,7 +32,6 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import javax.swing.Box;
@@ -46,7 +45,6 @@
import pcgen.core.Constants;
import pcgen.core.GameMode;
-import pcgen.core.Globals;
import pcgen.core.SettingsHandler;
import pcgen.core.npcgen.AlignGeneratorOption;
import pcgen.core.npcgen.ClassGeneratorOption;
@@ -58,6 +56,25 @@
import pcgen.core.system.GameModeRollMethod;
import pcgen.util.PropertyFactory;
+/**
+ * This class implements a dialog to present the configurable options for
+ * generating a random NPC.
+ *
+ * <p>It includes dropdowns for Alignment, Race, Gender, Classes and Levels,
+ * and rolling method.
+ *
+ * <ul>
+ * <li>TODO - Implement Edit buttons</li>
+ * <li>TODO - Only display Alignment panel if Alignment is used by the Game Mode</li>
+ * <li>TODO - Add interface to the random name generator (which one?) </li>
+ * </ul>
+ *
+ * @author boomer70 <boo...@ya...>
+ *
+ * @since 5.11.1
+ *
+ */
+@SuppressWarnings("serial")
public class NPCGeneratorDlg extends JDialog
{
JButton okButton = new JButton();
Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-11-01 04:33:42 UTC (rev 1566)
@@ -3305,7 +3305,7 @@
Ability.Info.Multiple=Can be taken more than once
Ability.Info.Stacks=Stacks
-AbilityInfo.Title={0} Info
+InfoAbility.Title={0} Info
InfoAbility.Remaining.Label={0}s remaining:
InfoAbility.Pool.Description=How many {0}s you have left to choose.
in_abilities=Abilities
@@ -3322,3 +3322,4 @@
NPCGen.Options.AlignNotFound=The specified alignment ({0}) not found.
NPCGen.Options.ClassNotFound=The specified class ({0}) not found.
+NPCGen.Errors.CantSelectDeity=Unable to select deity. Character does not qualify for any deities.
Modified: Trunk/pcgen/code/src/java/pcgen/util/WeightedList.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/util/WeightedList.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/util/WeightedList.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -89,7 +89,11 @@
}
else
{
- theData = new ArrayList<WeightedItem<E>>(wl.theData);
+ theData = new ArrayList<WeightedItem<E>>(wl.theData.size());
+ for ( final WeightedItem<E> item : wl.theData )
+ {
+ theData.add( new WeightedItem<E>(item.getElement(), item.getWeight()) );
+ }
}
}
@@ -603,6 +607,8 @@
* <tt>WeightedList</tt> and its weight.
*
* @author boomer70
+ *
+ * @param <T>
*/
class WeightedItem<T>
{
@@ -627,7 +633,7 @@
*
* @return The object this item wraps
*/
- public T getElement()
+ public final T getElement()
{
return theElement;
}
@@ -637,7 +643,7 @@
*
* @return The weight of this item
*/
- public int getWeight()
+ public final int getWeight()
{
return theWeight;
}
@@ -687,6 +693,7 @@
private class Itr implements Iterator<E>
{
+ /** An iterator that iterates over the raw data elements. */
Iterator<WeightedItem<E>> realIterator = theData.iterator();
/**
@@ -728,6 +735,7 @@
private class ListItr implements ListIterator<E>
{
+ /** An Iterator that iterates over the raw data elements */
ListIterator<WeightedItem<E>> realIterator = null;
/**
@@ -879,8 +887,28 @@
}
}
+/**
+ * A class that implements the SubList functionality for a WeightedList.
+ *
+ * @author boomer70 <boo...@ya...>
+ *
+ * @see WeightedList#subList(int, int)
+ *
+ * @param <E>
+ */
class WeightedSubList<E> extends WeightedList<E>
{
+ /**
+ * Constructs a new List that is a view of a portion of the List passed in.
+ *
+ * @param list The backing List
+ * @param fromIndex The starting index of the new list
+ * @param toIndex The ending index of the new list.
+ *
+ * @throws IndexOutOfBoundsException if either index is outside the range
+ * of indexes in the backing list.
+ * @throws IllegalArgumentException if the fromIndex is greater than toIndex
+ */
@SuppressWarnings("nls")
WeightedSubList(final WeightedList<E> list, final int fromIndex, final int toIndex)
{
Modified: Trunk/pcgen/code/src/java/pcgen/util/chooser/RandomChooser.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/util/chooser/RandomChooser.java 2006-10-31 04:15:53 UTC (rev 1565)
+++ Trunk/pcgen/code/src/java/pcgen/util/chooser/RandomChooser.java 2006-11-01 04:33:42 UTC (rev 1566)
@@ -41,12 +41,11 @@
/** The list of unique items */
private List theUniqueList = new ArrayList();
- private boolean canGoNegative = false;
-
/** Whether or not to allow duplicate choices */
private boolean theAllowDuplicatesFlag = false;
/** Whether or not to force mPool=0 when closing */
+ // TODO - Should this be used?
private boolean theZeroPoolFlag = true;
/** The column containing the cost for an item */
@@ -103,7 +102,7 @@
public void setNegativeAllowed(final boolean argFlag)
{
- canGoNegative = argFlag;
+ // This is not used.
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|