Class History


  • public class History
    extends java.lang.Object
    Stores game history as XML.
    Author:
    David Ripton
    • Field Summary

      Fields 
      Modifier and Type Field Description
      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

      Constructors 
      Constructor Description
      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"
    • 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)
      • 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)
      • legionUndoMoveEvent

        void legionUndoMoveEvent​(Legion legion)
      • 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)