1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2006-2015 Joerg Henrichs
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (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 #ifndef HEADER_STK_CONFIG_HPP
20 #define HEADER_STK_CONFIG_HPP
21 
22 /**
23  * \defgroup config
24  * This module handles the user configuration, the supertuxkart configuration
25  * file (which contains options usually not edited by the player) and the input
26  * configuration file.
27  */
28 
29 #include "network/remote_kart_info.hpp"
30 #include "utils/interpolation_array.hpp"
31 #include "utils/no_copy.hpp"
32 
33 #include "utils/constants.hpp"
34 #include <map>
35 #include <set>
36 #include <string>
37 #include <vector>
38 
39 class KartProperties;
40 class MusicInformation;
41 class XMLNode;
42 
43 /**
44  * \brief Global STK configuration information.
45  * Parameters here can be tuned without recompilation, but the user shouldn't actually modify
46  * them. It also includes the list of default kart physics parameters which are used for
47  * each kart (but which can be overwritten for each kart, too).
48  * \ingroup config
49  */
50 class STKConfig : public NoCopy
51 {
52 protected:
53     /** Default kart properties. */
54     KartProperties *m_default_kart_properties;
55     std::map<std::string, KartProperties*> m_kart_properties;
56 
57 public:
58     /** What to do if a kart already has a powerup when it hits a bonus box:
59      *  - NEW:  give it a random new bonx box.
60      *  - SAME: give it one more item of the type it currently has.
61      *  - ONLY_IF_SAME: only give it one more item if the randomly chosen item
62      *          has the same type as the currently held item. */
63     enum {
64         POWERUP_MODE_NEW,
65         POWERUP_MODE_SAME,
66         POWERUP_MODE_ONLY_IF_SAME
67     }
68     m_same_powerup_mode;
69 
70     static float UNDEFINED;
71     float m_bomb_time;                 /**<Time before a bomb explodes.        */
72     float m_bomb_time_increase;        /**<Time added to bomb timer when it's
73                                            passed on.                          */
74     int   m_item_switch_ticks;          /**< Time items will be switched.       */
75     int   m_bubblegum_counter;         /**< How many times bubble gums must be
76                                             driven over before they disappear. */
77     bool  m_shield_restrict_weapons;   /**<Wether weapon usage is punished. */
78     float m_explosion_impulse_objects; /**<Impulse of explosion on moving
79                                             objects, e.g. road cones, ...      */
80     int   m_penalty_ticks;              /**< Penalty time when starting too
81                                             early.                             */
82     float m_delay_finish_time;         /**<Delay after a race finished before
83                                            the results are displayed.          */
84     float m_music_credit_time;         /**<Time the music credits are
85                                            displayed.                          */
86     int   m_max_karts;                 /**<Maximum number of karts.            */
87     bool  m_smooth_normals;            /**< If normals for raycasts for wheels
88                                            should be interpolated.             */
89 
90     /** Prevent early explosive items before this world time. */
91     float m_no_explosive_items_timeout;
92 
93     /** Maximum number of moveable objects in a track when networking is on. */
94     int m_max_moveable_objects;
95 
96     /** In case of a network race, remote karts will get their steering somewhat
97      *  reduced each frame. This reduces stutter when a kart only does small
98      *  steering adjustments. */
99     float m_network_steering_reduction;
100 
101     /** If the angle between a normal on a vertex and the normal of the
102      *  triangle are more than this value, the physics will use the normal
103      *  of the triangle in smoothing normal. */
104     float m_smooth_angle_limit;
105 
106     /** Default friction for the track and any track/library object. */
107     float m_default_track_friction;
108 
109     /** Default friction to be used for any moveable, e.g. karts, balls. */
110     float m_default_moveable_friction;
111 
112     /** Number of solver iterations. */
113     int m_solver_iterations;
114 
115     /** If position and velocity constraints are solved separately. */
116     bool m_solver_split_impulse;
117 
118     /** Threshold when to use the split impulse approach. */
119     float m_solver_split_impulse_thresh;
120 
121     /** Bit flags to modify the solver mode. Bits set in set_flags are
122      *  added to the solver mode, bits set in reset_flags are removed. */
123     int m_solver_set_flags, m_solver_reset_flags;
124 
125     int   m_max_skidmarks;           /**<Maximum number of skid marks/kart.  */
126     float m_skid_fadeout_time;       /**<Time till skidmarks fade away.      */
127     float m_near_ground;             /**<Determines when a kart is not near
128                                       *  ground anymore and the upright
129                                       *  constraint is disabled to allow for
130                                       *  more violent explosions.            */
131     int   m_min_kart_version,        /**<The minimum and maximum .kart file  */
132         m_max_kart_version;        /**<version supported by this binary.   */
133     int   m_min_track_version,       /**<The minimum and maximum .track file */
134         m_max_track_version;       /**<version supported by this binary.   */
135     int   m_min_server_version,       /**<The minimum and maximum server */
136         m_max_server_version;       /**<version supported by this binary.   */
137     int   m_max_display_news;        /**<How often a news message is displayed
138                                          before it is ignored. */
139 
140     /** Disable steering if skidding is stopped. This can help in making
141      *  skidding more controllable (since otherwise when trying to steer while
142      *  steering is reset to match the graphics it often results in the kart
143      *  crashing). */
144     bool m_disable_steer_while_unskid;
145 
146     /** If true the camera will stay behind the kart, potentially making it
147      *  easier to see where the kart is going to after the skid. */
148     bool m_camera_follow_skid;
149 
150     float m_ai_acceleration;         /**<Between 0 and 1, default being 1, can be
151                                          used to give a handicap to AIs */
152 
153     std::vector<float>
154         m_leader_intervals;        /**<Interval in follow the leader till
155                                        last kart is reomved.               */
156     float m_leader_time_per_kart;    /**< Additional time to each leader
157                                           interval for each additional kart. */
158     std::vector<int> m_switch_items; /**< How to switch items.               */
159     /** The number of points a kart on position X has more than the
160      *  next kart. From this the actual number of points for each
161      *  position is computed. */
162     std::vector<int> m_score_increase;
163 
164     /** Filename of the title music to play.*/
165     MusicInformation *m_title_music;
166 
167     /** Filename of the music that is played when the track's music was not found */
168     MusicInformation *m_default_music;
169 
170     /** Maximum number of transform events of a replay. */
171     int m_replay_max_frames;
172 
173     /** Maximum time between consecutive saved tranform events.  */
174     float m_replay_dt;
175 
176     /** If the speed difference with the last transform event
177      *  is larger than this, a new event is generated. */
178     float m_replay_delta_speed;
179 
180     /** A steering difference of more than that will trigger a new event to
181      *  be generated. */
182     float m_replay_delta_steering;
183 
184     /** The minimap size */
185     float m_minimap_size;
186 
187     /* The size of icons for AIs and human players, respectively */
188     float m_minimap_ai_icon;
189     float m_minimap_player_icon;
190 
191     /** The field of view for 1, 2, 3, 4 player split screen. */
192     float m_camera_fov[MAX_PLAYER_COUNT];
193 
194     float m_cutscene_fov;
195 
196     unsigned m_max_skinning_bones;
197 
198     unsigned m_tc_quality;
199 
200     /** Client and server port use random ports if enabled in user config. */
201     uint16_t m_server_discovery_port;
202     uint16_t m_client_port;
203     uint16_t m_server_port;
204 
205     /* URLs for donating and reseting the password */
206     std::string m_donate_url;
207     std::string m_password_reset_url;
208     std::string m_assets_download_url;
209 
210     /* SRV records for stun server lists created */
211     std::string m_stun_ipv4;
212     std::string m_stun_ipv6;
213 
214     /** Lists of TTF files used in STK. */
215     std::vector<std::string> m_normal_ttf;
216     std::vector<std::string> m_digit_ttf;
217     std::string m_color_emoji_ttf;
218 
219     /** Configurable values used in SmoothNetworkBody class. */
220     float m_snb_min_adjust_length, m_snb_max_adjust_length,
221         m_snb_min_adjust_speed, m_snb_max_adjust_time,
222         m_snb_adjust_length_threshold;
223 
224     /** URL for the server used for the API multiplayer. */
225     std::string m_server_api;
226 
227     /** Version of the server API to use */
228     uint32_t m_server_api_version = 0;
229 
230     /** URL for the server used for the addons management. */
231     std::string m_server_addons;
232 
233     /** URL for the server used for hardware reporting statistics */
234     std::string m_server_hardware_report;
235 
236     /** If true we allow all the server urls to be redirected by the news.xml. */
237     bool m_allow_news_redirects = true;
238 
239     /** List of network capabilities to handle different servers with same
240      *  version. */
241     std::set<std::string> m_network_capabilities;
242 
243 private:
244     /** True if stk_config has been loaded. This is necessary if the
245      *  --stk-config command line parameter has been specified to avoid
246      *  that stk loads the default configuration after already having
247      *  loaded a user specified config file. */
248     bool  m_has_been_loaded;
249 
250     /** Default FPS rate for physics. */
251     int m_physics_fps;
252 
253     std::string m_title_music_file;
254     std::string m_default_music_file;
255 public:
256     STKConfig();
257     ~STKConfig();
258     void init_defaults();
259     void getAllData(const XMLNode * root);
260     void load(const std::string &filename);
261     const std::string &getMainMenuPicture(int n);
262     const std::string &getBackgroundPicture(int n);
263     void initMusicFiles();
264     void  getAllScores(std::vector<int> *all_scores, int num_karts);
265     // ------------------------------------------------------------------------
266     /** Returns the default kart properties for each kart. */
267     const KartProperties &
getDefaultKartProperties() const268         getDefaultKartProperties() const { return *m_default_kart_properties; }
269 
270     // ------------------------------------------------------------------------
271     /** Returns the kart properties for a certain type of kart.
272      *  \throw out_of_range if there is no data for 'type'.
273      *  \param type Type of kart (e.g. heavy, medium, ...).
274      */
getKartProperties(const std::string & type)275     const KartProperties& getKartProperties(const std::string &type)
276     {
277         return *m_kart_properties.at(type);
278     }   // getKartProperties
279     // ------------------------------------------------------------------------
280     /** Converts a tick value (in physics time step size) into seconds. */
ticks2Time(int ticks)281     float ticks2Time(int ticks) { return float(ticks)/m_physics_fps; }
282     // ------------------------------------------------------------------------
283     /** Converts a time value into ticks (of physics time steps). */
time2Ticks(float t)284     int time2Ticks(float t) { return int(t * m_physics_fps);  }
285     // ------------------------------------------------------------------------
286     /** Returns the physics frame per seconds rate. */
getPhysicsFPS() const287     int getPhysicsFPS() const { return m_physics_fps; }
288 }
289 ;   // STKConfig
290 
291 extern STKConfig* stk_config;
292 #endif
293