net.sf.colossus.server
Class LegionServerSide

java.lang.Object
  extended by net.sf.colossus.game.Legion
      extended by net.sf.colossus.server.LegionServerSide
All Implemented Interfaces:
java.lang.Comparable<LegionServerSide>

public final class LegionServerSide
extends Legion
implements java.lang.Comparable<LegionServerSide>

Class Legion represents a Titan stack of Creatures and its stack marker.

Author:
David Ripton, Romain Dolbeau

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.colossus.game.Legion
Legion.AcquirableDecision
 
Field Summary
private  int battleTally
          TODO this should be a Creature or CreatureType
private  GameServerSide game
           
private static java.util.logging.Logger LOGGER
           
private  Legion parent
           
private  MasterHex startingHex
          The label of the starting hex of the last move.
 
Fields inherited from class net.sf.colossus.game.Legion
angelsToAcquire, decisions, ORDER_TITAN_THEN_POINTS, ORDER_TITAN_THEN_POINTS_THEN_MARKER
 
Constructor Summary
LegionServerSide(java.lang.String markerId, Legion parent, MasterHex currentHex, MasterHex startingHex, Player player, GameServerSide game, CreatureType... creatureTypes)
          Creates a new Legion instance.
 
Method Summary
(package private)  void addAngel(CreatureType angelType)
           
(package private)  void addBattleTallyToPoints()
           
 void addCreature(CreatureType type)
           
(package private)  boolean addCreature(CreatureType creature, boolean takeFromStack)
          Add a creature to this legion.
(package private)  void addCritter(CreatureServerSide critter)
           
(package private)  void addToBattleTally(int points)
           
 void askAcquirablesDecisions()
          For each acquirable decision, ask the client to choose one of the possible acquirables.
(package private)  boolean canRecruit()
          hasMoved() is a separate check, so that this function can be used in battle as well as during the muster phase.
(package private)  boolean canSummonAngel()
          Return true if this legion can summon.
(package private)  void clearBattleInfo()
           
(package private)  void clearBattleTally()
           
(package private)  void commitMove()
          Called at end of player turn.
 int compareTo(LegionServerSide other)
          Legions are sorted in descending order of total point value, with the titan legion always coming first.
(package private)  int getBattleTally()
           
 java.util.List<CreatureServerSide> getCreatures()
          TODO should be an unmodifiable List, but can't at the moment since both derived classes and users might still expect to change it TODO should be List, but subtypes are still covariant
(package private)  Creature getCritter(CreatureType creatureType)
          Gets the first critter in this legion with the same creature type as the passed creature.
(package private)  CreatureServerSide getCritter(int i)
          TODO avoid index-based access
(package private)  CreatureServerSide getCritterByTag(int tag)
          Return the first critter with a matching tag.
 java.lang.String getLongMarkerName()
           
static java.lang.String getLongMarkerName(java.lang.String markerId)
           
 java.lang.String getMarkerName()
           
static java.lang.String getMarkerName(java.lang.String markerId)
           
 Legion getParent()
           
 PlayerServerSide getPlayer()
          Retrieves the player this legion belongs to.
 int getPointValue()
          TODO unify between the two derived classes if possible -- the handling of Titans is quite different, although it should have the same result
(package private)  MasterHex getStartingHex()
           
(package private)  boolean hasConventionalMove()
           
(package private)  java.util.List<CreatureType> listTeleportingLords(MasterHex hex)
          List the lords eligible to teleport this legion to hexLabel.
(package private)  void moveToHex(MasterHex hex, EntrySide entrySide, boolean teleported, CreatureType teleportingLord)
           
(package private)  boolean moveToTop(CreatureServerSide critter)
          Move critter to the first position in the critters list.
(package private)  void prepareToRemove(boolean returnCrittersToStacks, boolean updateHistory)
          Do the cleanup required before this legion can be removed.
(package private)  void prepareToRemoveCritter(Creature critter, boolean returnToStacks, boolean updateHistory)
          Do the cleanup associated with removing the critter from this legion.
(package private)  void recombine(Legion legion, boolean remove)
          Recombine this legion into another legion.
(package private)  void remove()
           
(package private)  void remove(boolean returnCrittersToStacks, boolean updateHistory)
          Eliminate this legion.
 void removeCreature(CreatureType type)
           
(package private)  CreatureType removeCreature(CreatureType creature, boolean returnImmortalToStack, boolean disbandIfEmpty)
          Remove the first creature matching the passed creature's type from the legion.
(package private)  CreatureType removeCreature(int i, boolean returnToStack, boolean disbandIfEmpty)
          Remove the creature in position i in the legion.
(package private)  void sortCritters()
          Sort critters into descending order of importance.
(package private)  LegionServerSide split(java.util.List<CreatureType> creatures, java.lang.String newMarkerId)
          Split off creatures into a new legion using legion marker markerId.
(package private)  void undoMove()
           
(package private)  void undoRecruit()
           
(package private)  void undoReinforcement()
           
 
Methods inherited from class net.sf.colossus.game.Legion
canFlee, contains, equals, findEligibleAngels, getCreatureTypes, getCurrentHex, getEntrySide, getHeight, getMarkerId, getRecruit, hashCode, hasMoved, hasRecruited, hasSummonable, hasTeleported, hasTitan, numCreature, numLords, numRangestrikers, setCurrentHex, setEntrySide, setMoved, setRecruit, setTeleported, setupAcquirableDecisions, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

parent

private final Legion parent

startingHex

private MasterHex startingHex
The label of the starting hex of the last move.


battleTally

private int battleTally
TODO this should be a Creature or CreatureType


game

private final GameServerSide game
Constructor Detail

LegionServerSide

public LegionServerSide(java.lang.String markerId,
                        Legion parent,
                        MasterHex currentHex,
                        MasterHex startingHex,
                        Player player,
                        GameServerSide game,
                        CreatureType... creatureTypes)
Creates a new Legion instance. Not that this class does not constraint the number of creatures. In a normal Titan game it is between 0 and 8 creatures, but this class does not enforce this. TODO the game parameter should be redundant since it should be the same as player.getGame()

Method Detail

getPointValue

public int getPointValue()
Description copied from class: Legion
TODO unify between the two derived classes if possible -- the handling of Titans is quite different, although it should have the same result

Specified by:
getPointValue in class Legion

askAcquirablesDecisions

public void askAcquirablesDecisions()
For each acquirable decision, ask the client to choose one of the possible acquirables.


addAngel

void addAngel(CreatureType angelType)

getBattleTally

int getBattleTally()

clearBattleTally

void clearBattleTally()

clearBattleInfo

void clearBattleInfo()

addToBattleTally

void addToBattleTally(int points)

addBattleTallyToPoints

void addBattleTallyToPoints()

getMarkerName

public java.lang.String getMarkerName()

getMarkerName

public static java.lang.String getMarkerName(java.lang.String markerId)

getLongMarkerName

public static java.lang.String getLongMarkerName(java.lang.String markerId)

getLongMarkerName

public java.lang.String getLongMarkerName()

getParent

public Legion getParent()

getPlayer

public PlayerServerSide getPlayer()
Description copied from class: Legion
Retrieves the player this legion belongs to.

Overrides:
getPlayer in class Legion
Returns:
The matching player. Never null.

remove

void remove(boolean returnCrittersToStacks,
            boolean updateHistory)
Eliminate this legion.


remove

void remove()

prepareToRemove

void prepareToRemove(boolean returnCrittersToStacks,
                     boolean updateHistory)
Do the cleanup required before this legion can be removed.


moveToHex

void moveToHex(MasterHex hex,
               EntrySide entrySide,
               boolean teleported,
               CreatureType teleportingLord)

hasConventionalMove

boolean hasConventionalMove()

undoMove

void undoMove()

commitMove

void commitMove()
Called at end of player turn.


canRecruit

boolean canRecruit()
hasMoved() is a separate check, so that this function can be used in battle as well as during the muster phase. TODO move up


undoRecruit

void undoRecruit()

undoReinforcement

void undoReinforcement()

canSummonAngel

boolean canSummonAngel()
Return true if this legion can summon. TODO likely candidate for pulling up


getStartingHex

MasterHex getStartingHex()

addCreature

boolean addCreature(CreatureType creature,
                    boolean takeFromStack)
Add a creature to this legion. If takeFromStack is true, then do this only if such a creature remains in the stacks, and decrement the number of this creature type remaining.


removeCreature

CreatureType removeCreature(int i,
                            boolean returnToStack,
                            boolean disbandIfEmpty)
Remove the creature in position i in the legion. Return the removed creature. Put immortal creatures back on the stack and others to the Graveyard if returnImmortalToStack is true.


removeCreature

CreatureType removeCreature(CreatureType creature,
                            boolean returnImmortalToStack,
                            boolean disbandIfEmpty)
Remove the first creature matching the passed creature's type from the legion. Return the removed creature.


prepareToRemoveCritter

void prepareToRemoveCritter(Creature critter,
                            boolean returnToStacks,
                            boolean updateHistory)
Do the cleanup associated with removing the critter from this legion. Do not actually remove it, to prevent co-modification errors. Do not disband the legion if empty, since the critter has not actually been removed.


getCreatures

public java.util.List<CreatureServerSide> getCreatures()
Description copied from class: Legion
TODO should be an unmodifiable List, but can't at the moment since both derived classes and users might still expect to change it TODO should be List, but subtypes are still covariant

Overrides:
getCreatures in class Legion

getCritter

CreatureServerSide getCritter(int i)
TODO avoid index-based access


addCritter

void addCritter(CreatureServerSide critter)

getCritterByTag

CreatureServerSide getCritterByTag(int tag)
Return the first critter with a matching tag.


moveToTop

boolean moveToTop(CreatureServerSide critter)
Move critter to the first position in the critters list. Return true if it was moved.


getCritter

Creature getCritter(CreatureType creatureType)
Gets the first critter in this legion with the same creature type as the passed creature.


sortCritters

void sortCritters()
Sort critters into descending order of importance. TODO maybe a SortedSet would be better instead of sorting every now and then


recombine

void recombine(Legion legion,
               boolean remove)
Recombine this legion into another legion. Only remove this legion from the Player if remove is true. If it's false, the caller is responsible for removing this legion, which can avoid concurrent access problems. Someone needs to call MasterBoard.alignLegions() on the remaining legion's hexLabel after the recombined legion is actually removed.


split

LegionServerSide split(java.util.List<CreatureType> creatures,
                       java.lang.String newMarkerId)
Split off creatures into a new legion using legion marker markerId. (Or the first available marker, if markerId is null.) Return the new legion, or null if there's an error.


listTeleportingLords

java.util.List<CreatureType> listTeleportingLords(MasterHex hex)
List the lords eligible to teleport this legion to hexLabel.


compareTo

public int compareTo(LegionServerSide other)
Legions are sorted in descending order of total point value, with the titan legion always coming first. TODO This is inconsistent with equals() which means the Comparable contract is not fulfilled. Probably better of in a Comparator in any case.

Specified by:
compareTo in interface java.lang.Comparable<LegionServerSide>

addCreature

public void addCreature(CreatureType type)
Specified by:
addCreature in class Legion

removeCreature

public void removeCreature(CreatureType type)
Specified by:
removeCreature in class Legion