1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2006-2015 Joerg Henrichs
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 #ifndef HEADER_HISTORY_HPP
20 #define HEADER_HISTORY_HPP
21 
22 
23 #include "input/input.hpp"
24 #include "karts/controller/kart_control.hpp"
25 
26 #include <string>
27 #include <vector>
28 
29 class Kart;
30 
31 /**
32   * \ingroup race
33   */
34 class History
35 {
36 private:
37     /** True if a history should be replayed, */
38     bool m_replay_history;
39 
40     /** Points to the last used input event index. */
41     unsigned int m_event_index;
42 
43     /** The identities of the karts to use. */
44     std::vector<std::string> m_kart_ident;
45 
46     // ------------------------------------------------------------------------
47     struct InputEvent
48     {
49         /* Time at which this event occurred. */
50         int m_world_ticks;
51         /** For which kart the event was. */
52         int m_kart_index;
53         /** Which action it was. */
54         PlayerAction m_action;
55         /** The value to use. */
56         int m_value;
57     };   // InputEvent
58     // ------------------------------------------------------------------------
59 
60     /** All input events. */
61     std::vector<InputEvent> m_all_input_events;
62 
63     void  allocateMemory(int size=-1);
64 public:
65     static bool m_online_history_replay;
66           History        ();
67     void  initRecording  ();
68     void  Save           ();
69     void  Load           ();
70     void  updateReplay(int world_ticks);
71     void  addEvent(int kart_id, PlayerAction pa, int value);
72 
73     // -------------------I-----------------------------------------------------
74     /** Returns the identifier of the n-th kart. */
getKartIdent(unsigned int n)75     const std::string& getKartIdent(unsigned int n)
76     {
77         return m_kart_ident[n];
78     }   // getKartIdent
79     // ------------------------------------------------------------------------
80     /** Returns if a history is replayed, i.e. the history mode is not none. */
replayHistory() const81     bool  replayHistory() const { return m_replay_history; }
82     // ------------------------------------------------------------------------
83     /** Set if replay is enabled or not. */
setReplayHistory(bool b)84     void  setReplayHistory(bool b) { m_replay_history=b;  }
85 };
86 
87 extern History* history;
88 
89 #endif
90