initial commit, lordsawar source, slightly modified
[lordsawar] / src / bridgelist.h
1 //  Copyright (C) 2007, 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef BRIDGELIST_H
19 #define BRIDGELIST_H
20
21 #include <sigc++/trackable.h>
22 #include "LocationList.h"
23
24 class Bridge;
25 class XML_Helper;
26
27 //! A list of Bridge objects located on the game map.
28 /** 
29  * The bridgelist keeps track of the bridges located on the game map. It
30  * is implemented as a singleton because many classes use it for looking up
31  * bridges.
32  */
33 class Bridgelist : public LocationList<Bridge*>, public sigc::trackable
34 {
35     public:
36         //! The xml tag of this object in a saved-game file.
37         static std::string d_tag; 
38
39         // Methods that operate on the class data but do not modify the class.
40
41         //! Saves the list of Bridge objects to the opened saved-game file.
42         bool save(XML_Helper* helper) const;
43
44         //! Determines what the right Bridge::Type should be for the given tile.
45         /**
46          * Scans the surrounding tiles to see which bridge picture fits best.
47          *
48          * @param tile  The position on the game map to calculate a bridge type
49          *              for.
50          *
51          * @return The Bridge::Type that makes the most sense for the given 
52          *         tile.
53          */
54         int calculateType(Vector<int> t) const;
55
56
57         // Static Methods
58
59         //! Return the singleton instance.  Create a new one if needed.
60         static Bridgelist* getInstance();
61
62         //! Load the singleton instance from the opened saved-game file.
63         static Bridgelist* getInstance(XML_Helper* helper);
64
65         //! Explicitly delete the singleton instance.
66         static void deleteInstance();
67
68     protected:
69         //! Default constructor.
70         Bridgelist();
71
72         //! Loading constructor.
73         /**
74          * Load the list of Bridge objects from the opened saved-game file.
75          *
76          * @param helper  The opened saved-game file to load the Bridge objects
77          *                from.
78          */
79         Bridgelist(XML_Helper* helper);
80
81     private:
82         //! Callback for loading Bridge objects into the list of bridges.
83         bool load(std::string tag, XML_Helper* helper);
84
85         // DATA
86
87         //! A static pointer for the singleton instance.
88         static Bridgelist* s_instance;
89 };
90
91 #endif