initial commit, lordsawar source, slightly modified
[lordsawar] / src / roadlist.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 ROADLIST_H
19 #define ROADLIST_H
20
21 #include "LocationList.h"
22 #include <sigc++/trackable.h>
23
24 class XML_Helper;
25 class Road;
26 //! A list of Road objects on the game map.
27 /** 
28  * The roadlist keeps track of the roads located on the game map. It
29  * is implemented as a singleton because many classes use it for looking up
30  * roads.
31  */
32 class Roadlist : public LocationList<Road*>, public sigc::trackable
33 {
34     public:
35         //! The xml tag of this object in a saved-game file.
36         static std::string d_tag; 
37
38         // Methods that operate on the class data but do not modify the class.
39
40         //! Saves the list of roads to the opened saved-game file.
41         bool save(XML_Helper* helper) const;
42
43         //! Determines what the right Road::Type should be for the given tile.
44         /**
45          * Scans the surrounding tiles to see which road picture fits best.
46          *
47          * @param tile  The position on the game map to calculate a road type
48          *              for.
49          *
50          * @return The Road::Type that makes the most sense for the given tile.
51          */
52         int calculateType (Vector<int> tile) const;
53
54         // Static Methods
55
56         //! Return the singleton instance.  Create a new one if needed.
57         static Roadlist* getInstance();
58
59         //! Load the singleton instance from the opened saved-game file.
60         static Roadlist* getInstance(XML_Helper* helper);
61
62         //! Explicitly delete the singleton instance.
63         static void deleteInstance();
64         
65     protected:
66         //! Default constructor.
67         Roadlist();
68
69         //! Loading constructor.
70         /**
71          * Make a new roadlist object by loading it from the opened saved-game
72          * file.
73          *
74          * @param helper  The opened saved game file to load the list of roads
75          *                from.
76          */
77         Roadlist(XML_Helper* helper);
78
79     private:
80         //! Callback for loading road objects into the list.
81         bool load(std::string tag, XML_Helper* helper);
82
83         //! A static pointer for the singleton instance.
84         static Roadlist* s_instance;
85 };
86
87 #endif