initial commit, lordsawar source, slightly modified
[lordsawar] / src / counter.h
1 // Copyright (C) 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008 Ben Asselstine
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef FL_COUNTER_H
21 #define FL_COUNTER_H
22
23 #include <gtkmm.h>
24 #include <string>
25 #include <sigc++/trackable.h>
26
27 class XML_Helper;
28
29 /** The purpose of this class is very simple. Each object (player etc.) has a
30   * unique id by which it may be accessed (this isn't important for now, but
31   * becomes crucial as soon as you play e.g. over the network). Therefore, each 
32   * important game object queries this class for an id and gets a unique
33   * identifier. The current counter position is saved together with a game.
34   *
35   * The implementation with the global variable could be changed in favour of
36   * static functions...
37   */
38
39 class FL_Counter : public sigc::trackable
40 {
41     public:
42         //! The xml tag of this object in a saved-game file.
43         static std::string d_tag; 
44
45         //! Initialise the counter with a start value
46         FL_Counter(guint32 start = 0);
47
48         //! Load the counter. See XML_Helper for details.
49         FL_Counter(XML_Helper* helper);
50         ~FL_Counter();
51
52         //! Returns a unique id
53         guint32 getNextId();
54
55         void syncToId(guint32 id);
56
57         //! Saves the current counter position
58         bool save(XML_Helper* helper);
59
60     private:
61         guint32 d_curID;
62 };
63
64 extern FL_Counter* fl_counter;
65 #endif