net.sf.colossus.server
Class History

java.lang.Object
  extended by net.sf.colossus.server.History

public class History
extends java.lang.Object

Stores game history as XML.

Author:
David Ripton

Field Summary
private  boolean isRedo
           
private  org.jdom.Element loadedRedoLog
           
private  boolean loading
          Set to true during the processing of fireEventsFromXML(Server) to avoid triggering events we just restored again.
private static java.util.logging.Logger LOGGER
           
private  java.util.List<org.jdom.Element> recentEvents
          History elements/events that happened since the last commit/"snapshot".
private  org.jdom.Element root
          History: events that happened before last commit point
 
Constructor Summary
History()
          Stores the surviving legions (this variable is not needed any more) While the history should contain all information to reproduce the game state, the last set of legions is currently still loaded upfront since they contain the battle-specific information.
History(org.jdom.Element loadGameRoot)
          Constructor used by "LoadGame"
 
Method Summary
(package private)  void addCreatureEvent(AddCreatureAction event, int turn, java.lang.String reason)
          TODO reconsider name TODO decide if we should move it all into one big handleEvent(GameEvent) method
(package private)  void fireEventFromElement(Server server, org.jdom.Element el)
           
(package private)  void fireEventsFromXML(Server server)
           
(package private)  void flushRecentToRoot()
          Reached a commit point: append all recent events to the history, clear list of recent events; caller should do this together with creating the next snapshot.
(package private)  org.jdom.Element getCopy()
          All events before last commit
(package private)  org.jdom.Element getNewRedoLogElement()
           
(package private)  void legionMoveEvent(Legion legion, MasterHex newHex, EntrySide entrySide, boolean teleport, CreatureType lord)
           
(package private)  void legionUndoMoveEvent(Legion legion)
           
(package private)  void mergeEvent(java.lang.String splitoffId, java.lang.String survivorId, int turn)
           
(package private)  void movementRollEvent(Player player, int roll)
           
(package private)  void playerElimEvent(Player player, Player slayer, int turn)
           
(package private)  void processRedoLog(Server server)
          Fire all events from redoLog.
(package private)  void recruitEvent(Legion legion, CreatureType recruit, CreatureType recruiter)
           
(package private)  void relocateLegionEvent(Legion legion)
           
(package private)  void removeCreatureEvent(Legion legion, CreatureType creature, int turn, java.lang.String reason)
           
(package private)  void revealEvent(boolean allPlayers, java.util.List<Player> players, Legion legion, java.util.List<CreatureType> creatures, int turn, java.lang.String reason)
           
(package private)  void splitEvent(Legion parent, Legion child, java.util.List<CreatureType> splitoffs, int turn)
           
(package private)  void undoRecruitEvent(Legion legion)
           
 
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

root

private final org.jdom.Element root
History: events that happened before last commit point


recentEvents

private final java.util.List<org.jdom.Element> recentEvents
History elements/events that happened since the last commit/"snapshot".


loading

private boolean loading
Set to true during the processing of fireEventsFromXML(Server) to avoid triggering events we just restored again.


loadedRedoLog

private final org.jdom.Element loadedRedoLog

isRedo

private boolean isRedo
Constructor Detail

History

public History()
Stores the surviving legions (this variable is not needed any more) While the history should contain all information to reproduce the game state, the last set of legions is currently still loaded upfront since they contain the battle-specific information. This collides with replaying the game from history... Now, since 08/2008, they are not stored as "survivorlegions" any more. Instead, they are backed up internally (done inside PlayerServerSide), all the history is replayed. This creates proper split prediction data in all clients. After that, backup data is compared with result of replay. E.g. Legion count, their content, players eliminated must be in sync. Then the replayed ones are discarded and the backedup ones restored - which have the right legion state (moved, donor, summoned, ...) TODO align the history replay more with the original gameplay so we don't need this anymore; 08/2008:==> this is now to some part done. Still replay events could be closer to original events (split, summon, acquire, teleport, ...) , not just the "result" of that event (reveal,add,remove effects). TODO instead: model the actual events instead of just result, or at least add relevant info to history elements, so that all replayed events carry all needed data so that they could also be processed by event viewer (currently EV does not process anything during replay).


History

public History(org.jdom.Element loadGameRoot)
Constructor used by "LoadGame"

Method Detail

getCopy

org.jdom.Element getCopy()
All events before last commit


flushRecentToRoot

void flushRecentToRoot()
Reached a commit point: append all recent events to the history, clear list of recent events; caller should do this together with creating the next snapshot.


getNewRedoLogElement

org.jdom.Element getNewRedoLogElement()
Returns:
A Redo Element, containing all events since last commit i.e. which need to be REDOne on top of last commit point/snapshot

addCreatureEvent

void addCreatureEvent(AddCreatureAction event,
                      int turn,
                      java.lang.String reason)
TODO reconsider name TODO decide if we should move it all into one big handleEvent(GameEvent) method


removeCreatureEvent

void removeCreatureEvent(Legion legion,
                         CreatureType creature,
                         int turn,
                         java.lang.String reason)

relocateLegionEvent

void relocateLegionEvent(Legion legion)

splitEvent

void splitEvent(Legion parent,
                Legion child,
                java.util.List<CreatureType> splitoffs,
                int turn)

mergeEvent

void mergeEvent(java.lang.String splitoffId,
                java.lang.String survivorId,
                int turn)

revealEvent

void revealEvent(boolean allPlayers,
                 java.util.List<Player> players,
                 Legion legion,
                 java.util.List<CreatureType> creatures,
                 int turn,
                 java.lang.String reason)

playerElimEvent

void playerElimEvent(Player player,
                     Player slayer,
                     int turn)

movementRollEvent

void movementRollEvent(Player player,
                       int roll)

legionMoveEvent

void legionMoveEvent(Legion legion,
                     MasterHex newHex,
                     EntrySide entrySide,
                     boolean teleport,
                     CreatureType lord)

legionUndoMoveEvent

void legionUndoMoveEvent(Legion legion)

recruitEvent

void recruitEvent(Legion legion,
                  CreatureType recruit,
                  CreatureType recruiter)

undoRecruitEvent

void undoRecruitEvent(Legion legion)

processRedoLog

void processRedoLog(Server server)
Fire all events from redoLog. Elements from RedoLog are processed one by one and the corresponding method is called on the Server object, pretty much as if a ClientHandler would call it when receiving such a request from Client. Note that in some cases overriding the processingCH is necessary (because technically, this all currently happens while still the connecting of last joining player is processed, so processingCH is set to his ClientHandler). Note that "loading" is not set to true, so they DO GET ADDED to the recentEvents list again.

Parameters:
server - The server on which to call all the actions to be redone

fireEventsFromXML

void fireEventsFromXML(Server server)

fireEventFromElement

void fireEventFromElement(Server server,
                          org.jdom.Element el)