initial commit, lordsawar source, slightly modified
[lordsawar] / src / herotemplates.h
1 //  Copyright (C) 2007, 2008, 2009 Ben Asselstine
2 //  Copyright (C) 2008 Ole Laursen
3 //
4 //  This program is free software; you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation; either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU Library General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
17 //  02110-1301, USA.
18
19 #ifndef HERO_TEMPLATES_H
20 #define HERO_TEMPLATES_H
21
22 #include <vector>
23 #include "defs.h"
24 #include "hero.h"
25
26 class ArmyProto;
27 class HeroProto;
28 class XML_Helper;
29
30 //! A list of Item objects.
31 /** 
32  * The HeroTemplates holds all hero templates together.
33  * 
34  * It is implemented as a singleton. Upon creation, it reads the hero
35  * description file and initialises an internal list.
36  */
37 class HeroTemplates
38 {
39     public:
40         //! Returns the singleton instance.
41         static HeroTemplates* getInstance();
42
43         //! Explicitely deletes the singleton instance.
44         static void deleteInstance();
45
46         HeroProto *getRandomHero(int player_id);
47
48         HeroProto *getRandomHero(Hero::Gender gender, int player_id);
49         
50     protected:
51         //! Default constructor. The function reads in the heronames file and produces a set of hero templates to be randomly selected from.
52         HeroTemplates();
53         //! Destructor.
54         ~HeroTemplates();
55
56         bool load(std::string tag, XML_Helper *helper);
57
58     private:
59         /* the contents of the heronames data file */
60         std::vector<HeroProto*> d_herotemplates[MAX_PLAYERS];
61
62         //a list of male hero prototypes contained in the the army set.
63         std::vector<const ArmyProto*> d_male_heroes;
64         //a list of female hero prototypes contained in the the army set.
65         std::vector<const ArmyProto*> d_female_heroes;
66
67         static HeroTemplates* d_instance;
68
69         int loadHeroTemplates();
70 };
71
72 #endif