net.sf.colossus.xmlparser
Class TerrainRecruitLoader

java.lang.Object
  extended by net.sf.colossus.xmlparser.TerrainRecruitLoader
All Implemented Interfaces:
IVariantInitializer

public class TerrainRecruitLoader
extends java.lang.Object
implements IVariantInitializer

TerrainRecruitLoader load the terrains and recruits descriptions. TODO check if any of the methods still needs the "String terrain" parameter TODO we still use plenty of strings in here since the creatures are mixed with the special recruit requirements such as Anything/Lord/AnyNonLord or the custom recruits marked by the "Special:" keyword

Author:
Romain Dolbeau
See Also:
CreatureType

Nested Class Summary
private  class TerrainRecruitLoader.CreatureAndNumber
          Helper class, associating a Creature and a number.
static class TerrainRecruitLoader.NullTerrainRecruitLoader
           
private  class TerrainRecruitLoader.RecruitNumber
          Used internally to associate a creature name and the number of creatures needed to recruit it.
private  class TerrainRecruitLoader.StartingNumber
          Used internally to associate a creature name and the number received when starting a game.
 
Field Summary
private static java.util.List<Variant.AcquirableData> acquirableList
          The list of Acquirable Creature, as acquirableData.
private  int aquirableRecruitmentsValue
           
private  AllCreatureType creatureTypes
          The AllCreatureType object to use, needed to convert from String (name) to the actual CreatureType.
private static RecruitGraph graph
          Representation of the Recruiting Graph (for use) (sometimes called Recruiting Tree).
static java.lang.String Keyword_AnyNonLord
           
static java.lang.String Keyword_Anything
           
static java.lang.String Keyword_DemiLord
           
static java.lang.String Keyword_Lord
           
static java.lang.String Keyword_Special
           
private static java.util.logging.Logger LOGGER
           
private static java.util.Map<java.lang.String,CustomRecruitBase> nameToInstance
          support for the custom recruiting functions ; map the class name to an instance of the class.
private static java.util.Map<MasterBoardTerrain,java.lang.Boolean> strToBelow
          Map a terrain to a boolean, telling if a Creature can recruit in the usual way or not.
private static java.util.Map<MasterBoardTerrain,java.util.List<TerrainRecruitLoader.RecruitNumber>> strToRecruits
          Map a terrain to a list of recruits.
private static java.util.Map<MasterBoardTerrain,java.lang.String> strToRnd
          Map a terrain to an optional BattlelandsRandomizer filename.
private static java.util.Map<MasterBoardTerrain,java.util.List<TerrainRecruitLoader.StartingNumber>> strToStarters
          Map a terrain to a list of recruits.
private static java.util.Map<java.lang.String,MasterBoardTerrain> terrains
          A map from the terrain names to the terrains.
private  int titanImprove
          Base amount of points needed for Titan improvement.
private  int titanTeleport
          Amount of points needed for Titan Teleport.
 
Constructor Summary
TerrainRecruitLoader(java.io.InputStream terIS, AllCreatureType creatureTypes)
           
 
Method Summary
private static void addToGraph(java.util.List<TerrainRecruitLoader.RecruitNumber> rl, MasterBoardTerrain t)
          Add an entire terrain recruiting list to the Recruiting Graph.
static boolean anonymousRecruitLegal(CreatureType recruit, MasterBoardTerrain terrain, MasterHex hex)
           
private  RecruitingSubTree buildRecruitingSubTree(java.util.List<TerrainRecruitLoader.RecruitNumber> rl, boolean regularRecruit)
           
 java.util.List<Variant.AcquirableData> getAcquirablesList()
           
static ICustomRecruitBase getCustomRecruitBase(java.lang.String specialString)
           
static java.util.List<CreatureType> getPossibleRecruiters(MasterBoardTerrain terrain, MasterHex hex)
          Give a modifiable list of the possible recruiters in a terrain.
static java.util.List<CreatureType> getPossibleRecruits(MasterBoardTerrain terrain, MasterHex hex)
          Give a modifiable list of the possible recruits in a terrain.
static RecruitGraph getRecruitGraph()
          to obtain the recruit graph
static CreatureType[] getStartingCreatures(MasterHex hex)
          Give an array of the starting creatures, those available in the first turn and in a particular kind of Tower.
protected static MasterBoardTerrain getTerrainById(java.lang.String id)
           
static java.lang.String getTerrainRandomName(MasterBoardTerrain masterBoardTerrain)
          Give the name of the random filename to use to generate this terrain, or null if it's a static Battlelands.
 java.util.Collection<MasterBoardTerrain> getTerrains()
          Return a collection of all possible terrains.
 int getTitanImprovementValue()
          To obtain the base amount of points needed for Titan improvement.
 int getTitanTeleportValue()
          To obtain the amount of points needed for Titan teleport.
private  void handleAcquirable(org.jdom.Element el)
           
private  void handleAlias(org.jdom.Element el)
           
private  void handleTerrain(org.jdom.Element el)
           
private static boolean isConcreteCreature(java.lang.String name)
           
static boolean isStartCreature(CreatureType type)
          Tell whether given type is in the loaded variant a start creature, i.e.
static int numberOfRecruiterNeeded(CreatureType recruiter, CreatureType recruit, MasterBoardTerrain terrain, MasterHex hex)
          Give the number of a given recruiters needed to recruit a given Creature.
static void setCaretaker(Caretaker caretaker)
          set the Caretaker used by the graph (needed to know what creatures are still available)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

Keyword_Anything

public static final java.lang.String Keyword_Anything
See Also:
Constant Field Values

Keyword_AnyNonLord

public static final java.lang.String Keyword_AnyNonLord
See Also:
Constant Field Values

Keyword_Lord

public static final java.lang.String Keyword_Lord
See Also:
Constant Field Values

Keyword_DemiLord

public static final java.lang.String Keyword_DemiLord
See Also:
Constant Field Values

Keyword_Special

public static final java.lang.String Keyword_Special
See Also:
Constant Field Values

aquirableRecruitmentsValue

private int aquirableRecruitmentsValue

titanImprove

private int titanImprove
Base amount of points needed for Titan improvement.


titanTeleport

private int titanTeleport
Amount of points needed for Titan Teleport.


strToRecruits

private static java.util.Map<MasterBoardTerrain,java.util.List<TerrainRecruitLoader.RecruitNumber>> strToRecruits
Map a terrain to a list of recruits. TODO integrate into MasterBoardTerrain


strToStarters

private static java.util.Map<MasterBoardTerrain,java.util.List<TerrainRecruitLoader.StartingNumber>> strToStarters
Map a terrain to a list of recruits. TODO integrate into MasterBoardTerrain


strToBelow

private static java.util.Map<MasterBoardTerrain,java.lang.Boolean> strToBelow
Map a terrain to a boolean, telling if a Creature can recruit in the usual way or not. TODO integrate into MasterBoardTerrain


strToRnd

private static java.util.Map<MasterBoardTerrain,java.lang.String> strToRnd
Map a terrain to an optional BattlelandsRandomizer filename. TODO integrate into MasterBoardTerrain


terrains

private static java.util.Map<java.lang.String,MasterBoardTerrain> terrains
A map from the terrain names to the terrains.


acquirableList

private static java.util.List<Variant.AcquirableData> acquirableList
The list of Acquirable Creature, as acquirableData.

See Also:
Variant.AcquirableData

nameToInstance

private static java.util.Map<java.lang.String,CustomRecruitBase> nameToInstance
support for the custom recruiting functions ; map the class name to an instance of the class.


graph

private static RecruitGraph graph
Representation of the Recruiting Graph (for use) (sometimes called Recruiting Tree). TODO the VariantKnower is meant only as temporary solution; when variant loading and all this stuff here is not static any more, variant should be passed in or set afterwards or something...


creatureTypes

private final AllCreatureType creatureTypes
The AllCreatureType object to use, needed to convert from String (name) to the actual CreatureType.

Constructor Detail

TerrainRecruitLoader

public TerrainRecruitLoader(java.io.InputStream terIS,
                            AllCreatureType creatureTypes)
Method Detail

setCaretaker

public static void setCaretaker(Caretaker caretaker)
set the Caretaker used by the graph (needed to know what creatures are still available)


isConcreteCreature

private static boolean isConcreteCreature(java.lang.String name)

addToGraph

private static void addToGraph(java.util.List<TerrainRecruitLoader.RecruitNumber> rl,
                               MasterBoardTerrain t)
Add an entire terrain recruiting list to the Recruiting Graph.

Parameters:
rl - The list of RecruitNumber to add to the graph.

handleTerrain

private void handleTerrain(org.jdom.Element el)
                    throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

buildRecruitingSubTree

private RecruitingSubTree buildRecruitingSubTree(java.util.List<TerrainRecruitLoader.RecruitNumber> rl,
                                                 boolean regularRecruit)

handleAlias

private void handleAlias(org.jdom.Element el)
                  throws ParseException
Throws:
ParseException

handleAcquirable

private void handleAcquirable(org.jdom.Element el)
                       throws org.jdom.JDOMException,
                              ParseException
Throws:
org.jdom.JDOMException
ParseException

getTerrains

public java.util.Collection<MasterBoardTerrain> getTerrains()
Return a collection of all possible terrains. NOTE: Only meant to be used for Variant Initialization! In normal cases this list should be get from variant object.

Specified by:
getTerrains in interface IVariantInitializer
Returns:
A collection containing all instances of MasterBoardTerrain.

getTerrainById

protected static MasterBoardTerrain getTerrainById(java.lang.String id)

getCustomRecruitBase

public static ICustomRecruitBase getCustomRecruitBase(java.lang.String specialString)

getStartingCreatures

public static CreatureType[] getStartingCreatures(MasterHex hex)
Give an array of the starting creatures, those available in the first turn and in a particular kind of Tower. TODO this heuristic (first 3 creatures in the tower) should be replaced by a real entry in the Tower terrain (similar to startlist).

Parameters:
hex - The specific Tower considered.
Returns:
an array of Creature representing the starting creatures.
See Also:
CreatureType

isStartCreature

public static boolean isStartCreature(CreatureType type)
Tell whether given type is in the loaded variant a start creature, i.e. one of those one gets in the initial legion in the tower (any tower). I plan to use this for e.g. HexRecruitTreePanel, to show there how one can get to have a certain creature: start creature -or- acquirable -or- recruitable by N of from prev. in tree, -or- recruitable by any/Lord/DemiLord/anyNonLord -or- recruitable by N of something else (e.g. Titan=>Warlock)

Parameters:
type -
Returns:
true if this is a start creature in the loaded variant

getTerrainRandomName

public static java.lang.String getTerrainRandomName(MasterBoardTerrain masterBoardTerrain)
Give the name of the random filename to use to generate this terrain, or null if it's a static Battlelands.

Parameters:
masterBoardTerrain - A master board terrain.
Returns:
The name of the random source file as a String

getPossibleRecruits

public static java.util.List<CreatureType> getPossibleRecruits(MasterBoardTerrain terrain,
                                                               MasterHex hex)
Give a modifiable list of the possible recruits in a terrain.

Parameters:
terrain - The terrain to consider.
hex - The specific hex to consider. It shouldn't be null during the actual recruiting, but it can be null when doing evaluation (it's only used for special recruiting in custom variants).
Returns:
List of Creatures that can be recruited in the terrain.
See Also:
CreatureType

getPossibleRecruiters

public static java.util.List<CreatureType> getPossibleRecruiters(MasterBoardTerrain terrain,
                                                                 MasterHex hex)
Give a modifiable list of the possible recruiters in a terrain. TODO if clients need to modify they should make copies themselves, it seems better if have this class return an unmodifiable list

Parameters:
terrain - String representing a terrain.
Returns:
List of Creatures that can recruit in the terrain.
See Also:
CreatureType

numberOfRecruiterNeeded

public static int numberOfRecruiterNeeded(CreatureType recruiter,
                                          CreatureType recruit,
                                          MasterBoardTerrain terrain,
                                          MasterHex hex)
Give the number of a given recruiters needed to recruit a given Creature. TODO do we need the terrain parameter

Parameters:
recruiter - The Creature that wish to recruit.
recruit - The Creature that is to be recruited.
terrain - String representing a terrain, in which the recruiting occurs.
Returns:
Number of recruiter needed.
See Also:
CreatureType

anonymousRecruitLegal

public static boolean anonymousRecruitLegal(CreatureType recruit,
                                            MasterBoardTerrain terrain,
                                            MasterHex hex)

getTitanImprovementValue

public int getTitanImprovementValue()
To obtain the base amount of points needed for Titan improvement.

Specified by:
getTitanImprovementValue in interface IVariantInitializer
Returns:
The base amount of points needed for Titan improvement.

getTitanTeleportValue

public int getTitanTeleportValue()
To obtain the amount of points needed for Titan teleport.

Specified by:
getTitanTeleportValue in interface IVariantInitializer
Returns:
The amount of points needed for Titan teleport.

getRecruitGraph

public static RecruitGraph getRecruitGraph()
to obtain the recruit graph


getAcquirablesList

public java.util.List<Variant.AcquirableData> getAcquirablesList()
Specified by:
getAcquirablesList in interface IVariantInitializer