1 /******************************************************************************
2  *  Warmux is a convivial mass murder game.
3  *  Copyright (C) 2001-2011 Warmux Team.
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 2 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 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  * Game mode : duration of a turn, weapons configurations, max number of character
20  * per team, etc.
21  *****************************************************************************/
22 
23 #ifndef GAME_MODE_H
24 #define GAME_MODE_H
25 
26 #include <string>
27 #include <vector>
28 #include <WARMUX_singleton.h>
29 #include <WARMUX_base.h>
30 #include "weapon/weapon_cfg.h"
31 #include "tool/xml_document.h"
32 
33 typedef struct _xmlNode xmlNode;
34 
35 class GameMode : public Singleton<GameMode>
36 {
37 public:
38   std::string rules;
39 
40   uint nb_characters;
41   uint max_teams;
42   uint duration_turn;
43   uint duration_move_player;
44   uint duration_exchange_player;
45   uint duration_before_death_mode;
46   uint damage_per_turn_during_death_mode;
47   Double gravity;
48   Double safe_fall ;
49   Double damage_per_fall_unit ;
50   ExplosiveWeaponConfig death_explosion_cfg;
51   ExplosiveWeaponConfig barrel_explosion_cfg;
52   ExplosiveWeaponConfig bonus_box_explosion_cfg;
53 
54   struct s_character
55   {
56     uint init_energy;
57     uint max_energy;
58     uint mass;
59     Double air_resist_factor;
60     Double jump_strength;
61     Double jump_angle;
62     Double super_jump_strength;
63     Double super_jump_angle;
64     Double back_jump_strength;
65     Double back_jump_angle;
66     uint walking_pause;
67   } character;
68 
69   bool auto_change_character;
70 
71   typedef enum {
72     ALWAYS = 0,
73     BEFORE_FIRST_ACTION,
74     NEVER
75   } manual_change_character_t;
76 
77   manual_change_character_t allow_character_selection;
78   XmlReader doc;
79 
80 private:
81   std::string m_current;
82 
83   XmlReader* doc_objects;
84   const xmlNode* weapons_xml;
85 
86   void LoadDefaultValues();
87 
88   bool LoadXml (const xmlNode* xml);
89   bool ExportFileToString(const std::string& filename, std::string& contents) const;
90 
91   std::string GetFilename() const;
92 
93   std::string GetDefaultObjectsFilename() const;
94   std::string GetObjectsFilename() const;
95 
96 public:
GetName()97   const std::string& GetName() const { return m_current; }
98 
GetWeaponsXml()99   const xmlNode* GetWeaponsXml() { return weapons_xml; }
GetMaxTeamsPerNetworkPlayer()100   int GetMaxTeamsPerNetworkPlayer() { return max_teams -1; }
101 
102   bool Load(void);
103 
104   // mode: xml text of data/game_mode/<mode>.xml
105   // mode_objects: xml text of data/game_mode/<mode>_objects.xml
106   bool LoadFromString(const std::string& game_mode_name,
107                       const std::string& mode,
108                       const std::string& mode_objects);
109 
110   bool ExportToString(std::string& mode,
111                       std::string& mode_objects) const;
112 
GetXmlObjects()113   const XmlReader* GetXmlObjects() const { return doc_objects; }
114 
115   bool AllowCharacterSelection() const;
116 
117   static std::vector<std::pair<std::string, std::string> > ListGameModes();
118 
119 protected:
120   friend class Singleton<GameMode>;
121   GameMode();
122   ~GameMode();
123 };
124 
125 #endif /* GAME_MODE_H */
126