Back to index

supertuxkart  0.5+dfsg1
stk_config.cpp
Go to the documentation of this file.
00001 //  $Id: stk_config.cpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include "stk_config.hpp"
00021 #include "file_manager.hpp"
00022 
00023 STKConfig* stk_config=0;
00024 
00025 //-----------------------------------------------------------------------------
00026 void STKConfig::load(const std::string filename)
00027 {
00028 
00029     // Use the kart properties loader to read in the default kart
00030     // values, but don't try to load any models or materials       */
00031     KartProperties::load(filename, "config",
00032                         /*dont_load_models   */ true,
00033                         /*dont_load_materials*/ true  );
00034 
00035     // Check that all necessary values are indeed set 
00036     // -----------------------------------------------
00037 
00038 #define CHECK_NEG(  a,strA) if(a<-99) {                                \
00039         fprintf(stderr,"Missing default value for '%s' in '%s'.\n",    \
00040                 strA,filename.c_str());exit(-1);                       \
00041     }
00042     if(m_gear_switch_ratio.size()==0)
00043     {
00044         fprintf(stderr,"Missing default value for 'gear-switch-ratio' in '%s'.\n",
00045                 filename.c_str());
00046         exit(-1);
00047     }
00048     if(m_gear_power_increase.size()==0)
00049     {
00050         fprintf(stderr,"Missing default value for 'gear-power-increase' in '%s'.\n",
00051                 filename.c_str());
00052         exit(-1);
00053     }
00054     if(m_gear_switch_ratio.size()!=m_gear_power_increase.size())    {
00055         fprintf(stderr,"Number of entries for 'gear-switch-ratio' and 'gear-power-increase");
00056         fprintf(stderr,"in '%s' must be equal.\n", filename.c_str());
00057         exit(-1);
00058     }
00059 
00060     if(m_scores.size()==0 || (int)m_scores.size()!=m_max_karts)
00061     {
00062         fprintf(stderr,"Not or not enough scores defined in stk_config");
00063         exit(-1);
00064     }
00065     if(m_leader_intervals.size()==0)
00066     {
00067         fprintf(stderr,"No follow leader interval(s) defined in stk_config");
00068         exit(-1);
00069     }
00070     CHECK_NEG(m_max_karts,               "max-karts"                    );
00071     CHECK_NEG(m_grid_order,              "grid-order"                   );
00072 
00073     CHECK_NEG(m_mass,                    "mass"                         );
00074     CHECK_NEG(m_height_cog,              "heightCOG"                    );
00075     CHECK_NEG(m_wheel_base,              "wheel-base"                   );
00076     CHECK_NEG(m_engine_power,            "engine-power"                 );
00077     CHECK_NEG(m_max_steer_angle,         "max-steer-angle"              );
00078     CHECK_NEG(m_brake_factor,            "brake-factor"                 );
00079 
00080     CHECK_NEG(m_wheelie_max_speed_ratio, "wheelie-max-speed-ratio"      );
00081     CHECK_NEG(m_wheelie_max_pitch,       "wheelie-max-pitch"            );
00082     CHECK_NEG(m_wheelie_pitch_rate,      "wheelie-pitch-rate"           );
00083     CHECK_NEG(m_wheelie_restore_rate,    "wheelie-restore-rate"         );
00084     CHECK_NEG(m_wheelie_speed_boost,     "wheelie-speed-boost"          );
00085     CHECK_NEG(m_wheelie_lean_recovery,   "wheelie-lean-recovery"        );
00086     CHECK_NEG(m_wheelie_balance_recovery,"wheelie-balance-recovery"     );
00087     CHECK_NEG(m_wheelie_step,            "wheelie-step"                 );
00088     CHECK_NEG(m_wheelie_power_boost,     "wheelie-power-boost"          );
00089 
00090     CHECK_NEG(m_parachute_friction,        "parachute-friction"         );
00091     CHECK_NEG(m_parachute_done_fraction,   "parachute-done-fraction"    );
00092     CHECK_NEG(m_parachute_time,            "parachute-time"             );
00093     CHECK_NEG(m_parachute_time_other,      "parachute-time-other"       );
00094 
00095     CHECK_NEG(m_time_full_steer,           "time-full-steer"            );
00096 
00097     //bullet physics data
00098     CHECK_NEG(m_suspension_stiffness,      "suspension-stiffness"       );
00099     CHECK_NEG(m_wheel_damping_relaxation,  "wheel-damping-relaxation"   );
00100     CHECK_NEG(m_wheel_damping_compression, "wheel-damping-compression"  );
00101     CHECK_NEG(m_friction_slip,             "friction-slip"              );
00102     CHECK_NEG(m_roll_influence,            "roll-influence"             );
00103     CHECK_NEG(m_wheel_radius,              "wheel-radius"               );
00104     CHECK_NEG(m_wheel_width,               "wheel-width"                );
00105     CHECK_NEG(m_chassis_linear_damping,    "chassis-linear-damping"     );
00106     CHECK_NEG(m_chassis_angular_damping,   "chassis-angular-damping"    );
00107     CHECK_NEG(m_maximum_speed,             "maximum-speed"              );
00108     CHECK_NEG(m_max_speed_reverse_ratio,   "max-speed-reverse-ratio"    );
00109     CHECK_NEG(m_gravity_center_shift,      "gravity-center-shift"       );
00110     CHECK_NEG(m_bomb_time,                 "bomb-time"                  );
00111     CHECK_NEG(m_bomb_time_increase,        "bomb-time-increase"         );
00112     CHECK_NEG(m_anvil_time,                "anvil-time"                 );
00113     CHECK_NEG(m_anvil_weight,              "anvil-weight"               );
00114     CHECK_NEG(m_zipper_time,               "zipper-time"                );
00115     CHECK_NEG(m_zipper_force,              "zipper-force"               );
00116     CHECK_NEG(m_zipper_speed_gain,         "zipper-speed-gain"          );
00117     CHECK_NEG(m_shortcut_segments,         "shortcut-skipped-segments"  );
00118     CHECK_NEG(m_suspension_rest,           "suspension-rest"            );
00119     CHECK_NEG(m_jump_velocity,             "jump-velocity"              );
00120     CHECK_NEG(m_explosion_impulse,         "explosion-impulse"          );
00121     CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects"  );
00122     CHECK_NEG(m_upright_tolerance,         "upright-tolerance"          );
00123     CHECK_NEG(m_upright_max_force,         "upright-max-force"          );
00124     CHECK_NEG(m_camera_max_accel,          "camera-max-accel"           );
00125     CHECK_NEG(m_camera_max_brake,          "camera-max-brake"           );
00126     CHECK_NEG(m_camera_distance,           "camera-distance"            );
00127 
00128 }   // load
00129 
00130 // -----------------------------------------------------------------------------
00135 void STKConfig::init_defaults()
00136 {
00137     m_wheel_base   = m_height_cog      = m_mass = m_max_steer_angle =
00138     m_anvil_weight    = m_parachute_friction =
00139     m_parachute_time = m_parachute_done_fraction = m_parachute_time_other = 
00140     m_engine_power = m_brake_factor =
00141     m_anvil_speed_factor = m_time_full_steer = m_wheelie_max_pitch =
00142     m_wheelie_max_speed_ratio = m_wheelie_pitch_rate = 
00143     m_wheelie_restore_rate = m_wheelie_speed_boost = 
00144     m_bomb_time = m_bomb_time_increase= m_anvil_time = 
00145     m_zipper_time = m_zipper_force = m_zipper_speed_gain = 
00146     m_shortcut_segments =
00147     //bullet physics data
00148     m_suspension_stiffness = m_wheel_damping_relaxation = 
00149     m_wheel_damping_compression = m_friction_slip = m_roll_influence = 
00150     m_wheel_radius = m_wheel_width = m_wheelie_lean_recovery = 
00151     m_wheelie_step = m_wheelie_balance_recovery =m_wheelie_power_boost = 
00152     m_chassis_linear_damping = m_chassis_angular_damping = 
00153     m_maximum_speed = m_gravity_center_shift = m_suspension_rest =
00154     m_max_speed_reverse_ratio = m_explosion_impulse = m_jump_velocity = 
00155     m_explosion_impulse_objects = m_upright_tolerance = m_upright_max_force =
00156     // Camera
00157     m_camera_max_accel = m_camera_max_brake = m_camera_distance = -99.9f;
00158 
00159     m_max_karts            = -100;
00160     m_grid_order           = -100;
00161     m_title_music          = NULL;
00162     m_scores.clear();
00163     m_leader_intervals.clear();
00164 }   // init_defaults
00165 
00166 //-----------------------------------------------------------------------------
00167 void STKConfig::getAllData(const lisp::Lisp* lisp)
00168 {
00169 
00170     // Get the values which are not part of the default KartProperties
00171     // ---------------------------------------------------------------
00172     lisp->get("anvil-weight",                 m_anvil_weight             );
00173     lisp->get("shortcut-skipped-segments",    m_shortcut_segments        );
00174     lisp->get("anvil-speed-factor",           m_anvil_speed_factor       );
00175     lisp->get("parachute-friction",           m_parachute_friction       );
00176     lisp->get("parachute-time",               m_parachute_time           );
00177     lisp->get("parachute-time-other",         m_parachute_time_other     );
00178     lisp->get("parachute-done-fraction",      m_parachute_done_fraction  );
00179     lisp->get("bomb-time",                    m_bomb_time                );
00180     lisp->get("bomb-time-increase",           m_bomb_time_increase       );
00181     lisp->getVector("leader-intervals",       m_leader_intervals         );
00182     lisp->get("anvil-time",                   m_anvil_time               );
00183     lisp->get("zipper-time",                  m_zipper_time              );
00184     lisp->get("zipper-force",                 m_zipper_force             );
00185     lisp->get("zipper-speed-gain",            m_zipper_speed_gain        );
00186     lisp->get("explosion-impulse",            m_explosion_impulse        );
00187     lisp->get("explosion-impulse-objects",    m_explosion_impulse_objects);
00188     lisp->get("max-karts",                    m_max_karts                );
00189     lisp->get("grid-order",                   m_grid_order               );
00190     lisp->getVector("scores",                 m_scores);
00191     std::string title_music;
00192     lisp->get("title-music",                  title_music                );
00193     m_title_music = new MusicInformation(file_manager->getMusicFile(title_music));
00194 
00195     // Get the default KartProperties
00196     // ------------------------------
00197     KartProperties::getAllData(lisp->getLisp("kart-defaults"));
00198 }   // getAllData