net.sf.colossus.server
Class BattleServerSide

java.lang.Object
  extended by net.sf.colossus.game.Battle
      extended by net.sf.colossus.server.BattleServerSide

public final class BattleServerSide
extends Battle

Class Battle holds data about a Titan battle. It has utility functions related to incrementing the phase, managing moves, and managing strikes.

Author:
David Ripton, Romain Dolbeau

Nested Class Summary
static class BattleServerSide.AngelSummoningStates
           
private  class BattleServerSide.BattlePhaseAdvancer
           
static class BattleServerSide.LegionTags
           
 
Field Summary
private  BattleServerSide.LegionTags activeLegionTag
           
private  boolean attackerElim
           
private  boolean attackerEntered
           
private  boolean battleOver
           
private  int carryDamage
           
private  java.util.Set<BattleHex> carryTargets
          Set of hexes for valid carry targets
private  boolean conceded
           
private  boolean defenderElim
           
private  boolean driftDamageApplied
           
private static java.util.logging.Logger LOGGER
           
private  BattlePhase phase
           
private  PhaseAdvancer phaseAdvancer
           
private  int pointsScored
           
private  Server server
           
private  BattleServerSide.AngelSummoningStates summonState
           
private  int turnNumber
           
 
Fields inherited from class net.sf.colossus.game.Battle
attacker, defender, game
 
Constructor Summary
BattleServerSide(GameServerSide game, Legion attacker, Legion defender, BattleServerSide.LegionTags activeLegionTag, MasterHex masterHex, int turnNumber, BattlePhase phase)
           
 
Method Summary
(package private)  void addCarryTarget(BattleHex hex)
           
private  void advancePhase()
           
(package private)  void applyCarries(CreatureServerSide target)
           
private  void applyDriftDamage()
           
private  void checkForElimination()
           
 void cleanRefs()
           
private  void cleanup()
           
private  void cleanupOneDeadCritter(Creature critter)
           
(package private)  void clearCarryTargets()
           
private  void commitMoves()
           
private  void commitStrikes()
           
(package private)  void concede(Player player)
          Mark all of the conceding player's critters as dead.
(package private)  int countBrambleHexes(BattleHex hex1, BattleHex hex2)
          Deprecated. 
private  int countBrambleHexesDir(BattleHex hex1, BattleHex hex2, boolean left, int previousCount)
          Deprecated. another function with explicit reference to Bramble that should be fixed.
(package private)  boolean doMove(int tag, BattleHex hex)
          If legal, move critter to hex and return true.
(package private)  void doneReinforcing()
          Needs to be called when reinforcement is done.
(package private)  void doneWithMoves()
           
(package private)  boolean doneWithStrikes()
          Return true if okay, or false if forced strikes remain.
private  java.util.Set<BattleHex> findMoves(BattleHex hex, CreatureServerSide critter, boolean flies, int movesLeft, int cameFrom, boolean ignoreMobileAllies, boolean first)
          Recursively find moves from this hex.
(package private)  java.util.Set<java.lang.String> findStrikes(CreatureServerSide critter, boolean rangestrike)
          Return a set of hex labels for hexes containing targets that the critter may strike.
private  java.util.Set<BattleHex> findUnoccupiedStartlistHexes(boolean ignoreMobileAllies, MasterBoardTerrain terrain)
          This method is called by the defender on turn 1 in a Startlisted Terrain, so we know that there are no enemies on board, and all allies are mobile.
(package private)  void finishSummoningAngel(boolean placeNewChit)
          Called from Game after the SummonAngel finishes.
(package private)  LegionServerSide getActiveLegion()
           
(package private)  Player getActivePlayer()
           
private  java.util.List<CreatureServerSide> getAllCritters()
          Return a list of all critters in the battle.
 LegionServerSide getAttackingLegion()
          Override with covariant return type to ease transition into new model.
(package private)  BattlePhase getBattlePhase()
           
(package private)  int getCarryDamage()
           
(package private)  java.util.Set<java.lang.String> getCarryTargetDescriptions()
           
(package private)  java.util.Set<BattleHex> getCarryTargets()
          Return the set of hexes with valid carry targets.
(package private)  CreatureServerSide getCritter(BattleHex hex)
           
 LegionServerSide getDefendingLegion()
          Override with covariant return type to ease transition into new model.
 GameServerSide getGame()
          Override with covariant return type to ease transition into new model.
private  LegionServerSide getInactiveLegion()
           
private  LegionServerSide getLegion(BattleServerSide.LegionTags legionTag)
           
(package private)  BattleServerSide.AngelSummoningStates getSummonState()
           
(package private)  int getTurnNumber()
           
(package private)  void init()
          We need to do two-stage construction so that game.battle is non-null earlier.
private  void initBattleChits(LegionServerSide legion)
           
(package private)  boolean isDriftDamageApplied()
           
private  boolean isForcedStrikeRemaining()
           
protected  boolean isOccupied(BattleHex hex)
          Whether the hex is occupied by a critter/creature/chit/...
private  boolean isOccupied(java.lang.String hexLabel)
           
private  boolean isOver()
           
(package private)  void leaveCarryMode()
           
private  void placeCritter(CreatureServerSide critter)
           
private  void placeLegion(Legion legion)
           
private  boolean recruitReinforcement()
           
private  void removeDeadCreatures()
           
private  void removeDeadCreaturesFromLegion(LegionServerSide legion)
           
private  void removeOffboardCreatures()
          If any creatures were left off-board, kill them.
(package private)  void setCarryDamage(int carryDamage)
           
(package private)  void setCarryTargets(java.util.Set<BattleHex> carryTargets)
           
(package private)  void setDriftDamageApplied(boolean driftDamageApplied)
           
 void setServer(Server server)
           
(package private)  void setSummonState(BattleServerSide.AngelSummoningStates summonState)
           
private  boolean setupFight()
           
private  boolean setupMove()
           
private  boolean setupRecruit()
           
private  boolean setupSummon()
           
private  java.util.Set<BattleHex> showMoves(CreatureServerSide critter, boolean ignoreMobileAllies)
          Find all legal moves for this critter.
(package private)  void undoMove(BattleHex hex)
           
 
Methods inherited from class net.sf.colossus.game.Battle
computeSkillPenaltyRangestrikeThrough, getDirection, getLegionByPlayer, getLocation, getRange, isLOSBlocked, isLOSBlockedDir, isRangestrikePossible, toLeft
 
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

server

private Server server

activeLegionTag

private BattleServerSide.LegionTags activeLegionTag

turnNumber

private int turnNumber

phase

private BattlePhase phase

summonState

private BattleServerSide.AngelSummoningStates summonState

carryDamage

private int carryDamage

attackerElim

private boolean attackerElim

defenderElim

private boolean defenderElim

battleOver

private boolean battleOver

attackerEntered

private boolean attackerEntered

conceded

private boolean conceded

driftDamageApplied

private boolean driftDamageApplied

carryTargets

private final java.util.Set<BattleHex> carryTargets
Set of hexes for valid carry targets


phaseAdvancer

private final PhaseAdvancer phaseAdvancer

pointsScored

private int pointsScored
Constructor Detail

BattleServerSide

BattleServerSide(GameServerSide game,
                 Legion attacker,
                 Legion defender,
                 BattleServerSide.LegionTags activeLegionTag,
                 MasterHex masterHex,
                 int turnNumber,
                 BattlePhase phase)
Method Detail

setServer

public void setServer(Server server)

cleanRefs

public void cleanRefs()

placeLegion

private void placeLegion(Legion legion)

placeCritter

private void placeCritter(CreatureServerSide critter)

initBattleChits

private void initBattleChits(LegionServerSide legion)

init

void init()
We need to do two-stage construction so that game.battle is non-null earlier.


getGame

public GameServerSide getGame()
Override with covariant return type to ease transition into new model.

Overrides:
getGame in class Battle

getActivePlayer

Player getActivePlayer()

getAttackingLegion

public LegionServerSide getAttackingLegion()
Override with covariant return type to ease transition into new model.

Overrides:
getAttackingLegion in class Battle

getDefendingLegion

public LegionServerSide getDefendingLegion()
Override with covariant return type to ease transition into new model.

Overrides:
getDefendingLegion in class Battle

getActiveLegion

LegionServerSide getActiveLegion()

getInactiveLegion

private LegionServerSide getInactiveLegion()

getLegion

private LegionServerSide getLegion(BattleServerSide.LegionTags legionTag)

getBattlePhase

BattlePhase getBattlePhase()

getTurnNumber

int getTurnNumber()

isOver

private boolean isOver()

advancePhase

private void advancePhase()

setupSummon

private boolean setupSummon()

setupRecruit

private boolean setupRecruit()

setupMove

private boolean setupMove()

setupFight

private boolean setupFight()

getSummonState

BattleServerSide.AngelSummoningStates getSummonState()

setSummonState

void setSummonState(BattleServerSide.AngelSummoningStates summonState)

finishSummoningAngel

void finishSummoningAngel(boolean placeNewChit)
Called from Game after the SummonAngel finishes.


recruitReinforcement

private boolean recruitReinforcement()

doneReinforcing

void doneReinforcing()
Needs to be called when reinforcement is done.


getCarryDamage

int getCarryDamage()

setCarryDamage

void setCarryDamage(int carryDamage)

findMoves

private java.util.Set<BattleHex> findMoves(BattleHex hex,
                                           CreatureServerSide critter,
                                           boolean flies,
                                           int movesLeft,
                                           int cameFrom,
                                           boolean ignoreMobileAllies,
                                           boolean first)
Recursively find moves from this hex. Return a set of string hex IDs for all legal destinations. Do not double back. If ignoreMobileAllies is true, pretend that allied creatures that can move out of the way are not there.


findUnoccupiedStartlistHexes

private java.util.Set<BattleHex> findUnoccupiedStartlistHexes(boolean ignoreMobileAllies,
                                                              MasterBoardTerrain terrain)
This method is called by the defender on turn 1 in a Startlisted Terrain, so we know that there are no enemies on board, and all allies are mobile.


showMoves

private java.util.Set<BattleHex> showMoves(CreatureServerSide critter,
                                           boolean ignoreMobileAllies)
Find all legal moves for this critter.


undoMove

void undoMove(BattleHex hex)

concede

void concede(Player player)
Mark all of the conceding player's critters as dead.


removeOffboardCreatures

private void removeOffboardCreatures()
If any creatures were left off-board, kill them. If they were newly summoned or recruited, unsummon or unrecruit them instead.


commitMoves

private void commitMoves()

doneWithMoves

void doneWithMoves()

applyDriftDamage

private void applyDriftDamage()

isDriftDamageApplied

boolean isDriftDamageApplied()

setDriftDamageApplied

void setDriftDamageApplied(boolean driftDamageApplied)

leaveCarryMode

void leaveCarryMode()

removeDeadCreatures

private void removeDeadCreatures()

removeDeadCreaturesFromLegion

private void removeDeadCreaturesFromLegion(LegionServerSide legion)

cleanupOneDeadCritter

private void cleanupOneDeadCritter(Creature critter)

checkForElimination

private void checkForElimination()

commitStrikes

private void commitStrikes()

isForcedStrikeRemaining

private boolean isForcedStrikeRemaining()

doneWithStrikes

boolean doneWithStrikes()
Return true if okay, or false if forced strikes remain.


findStrikes

java.util.Set<java.lang.String> findStrikes(CreatureServerSide critter,
                                            boolean rangestrike)
Return a set of hex labels for hexes containing targets that the critter may strike. Only include rangestrikes if rangestrike is true.


getCarryTargets

java.util.Set<BattleHex> getCarryTargets()
Return the set of hexes with valid carry targets.


getCarryTargetDescriptions

java.util.Set<java.lang.String> getCarryTargetDescriptions()

clearCarryTargets

void clearCarryTargets()

setCarryTargets

void setCarryTargets(java.util.Set<BattleHex> carryTargets)

addCarryTarget

void addCarryTarget(BattleHex hex)

applyCarries

void applyCarries(CreatureServerSide target)

countBrambleHexesDir

@Deprecated
private int countBrambleHexesDir(BattleHex hex1,
                                            BattleHex hex2,
                                            boolean left,
                                            int previousCount)
Deprecated. another function with explicit reference to Bramble that should be fixed.

Return the number of intervening bramble hexes. If LOS is along a hexspine, go left if argument left is true, right otherwise. If LOS is blocked, return a large number.


countBrambleHexes

@Deprecated
int countBrambleHexes(BattleHex hex1,
                                 BattleHex hex2)
Deprecated. 


doMove

boolean doMove(int tag,
               BattleHex hex)
If legal, move critter to hex and return true. Else return false.


cleanup

private void cleanup()

getAllCritters

private java.util.List<CreatureServerSide> getAllCritters()
Return a list of all critters in the battle.


isOccupied

private boolean isOccupied(java.lang.String hexLabel)

isOccupied

protected boolean isOccupied(BattleHex hex)
Description copied from class: Battle
Whether the hex is occupied by a critter/creature/chit/... This is abstract because the specific information about critter/... is currently kept in the subclass, but this information is required by several helper function located in the Battle class.

Specified by:
isOccupied in class Battle
Parameters:
hex - The hex whose occupancy is being checked
Returns:
Whether the hex is occupied by a critter/creature/chit/...

getCritter

CreatureServerSide getCritter(BattleHex hex)