2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2006 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "stk_config.hpp"
|
2008-10-16 20:05:59 -04:00
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdio.h>
|
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
|
|
|
# define snprintf _snprintf
|
|
|
|
#endif
|
2008-10-16 19:49:27 -04:00
|
|
|
|
2008-03-14 05:49:17 -04:00
|
|
|
#include "file_manager.hpp"
|
2008-10-16 19:49:27 -04:00
|
|
|
#include "lisp/parser.hpp"
|
|
|
|
#include "translation.hpp"
|
2008-09-17 23:24:19 -04:00
|
|
|
#include "audio/music_information.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
STKConfig* stk_config=0;
|
2008-07-16 21:33:49 -04:00
|
|
|
float STKConfig::UNDEFINED = -99.9f;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-16 19:49:27 -04:00
|
|
|
/** Loads the stk configuration file. After loading it checks if all necessary
|
|
|
|
* values are actually defined, otherwise an error message is printed and STK
|
|
|
|
* is aborted.
|
|
|
|
* /param filename Name of the configuration file to load.
|
|
|
|
*/
|
|
|
|
void STKConfig::load(const std::string &filename)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-10-16 20:05:59 -04:00
|
|
|
const lisp::Lisp* root = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lisp::Parser parser;
|
|
|
|
root = parser.parse(filename);
|
|
|
|
|
|
|
|
const lisp::Lisp* const LISP = root->getLisp("config");
|
|
|
|
if(!LISP)
|
|
|
|
{
|
|
|
|
char msg[MAX_ERROR_MESSAGE_LENGTH];
|
|
|
|
snprintf(msg, sizeof(msg), "No 'config' node found.");
|
|
|
|
throw std::runtime_error(msg);
|
|
|
|
}
|
|
|
|
getAllData(LISP);
|
|
|
|
}
|
|
|
|
catch(std::exception& err)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error while parsing KartProperties '%s':\n",
|
|
|
|
filename.c_str());
|
|
|
|
fprintf(stderr, err.what());
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
delete root;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-04-28 23:29:28 -04:00
|
|
|
// Check that all necessary values are indeed set
|
|
|
|
// -----------------------------------------------
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-10-06 09:40:11 -04:00
|
|
|
#define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \
|
2007-05-27 12:01:53 -04:00
|
|
|
fprintf(stderr,"Missing default value for '%s' in '%s'.\n", \
|
|
|
|
strA,filename.c_str());exit(-1); \
|
|
|
|
}
|
2008-01-01 09:30:39 -05:00
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
if(m_scores.size()==0 || (int)m_scores.size()!=m_max_karts)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"Not or not enough scores defined in stk_config");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2008-04-15 09:57:18 -04:00
|
|
|
if(m_leader_intervals.size()==0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"No follow leader interval(s) defined in stk_config");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2008-10-06 09:40:11 -04:00
|
|
|
if(m_menu_background.size()==0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"No menu background defined in stk_config");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2009-01-11 19:49:25 -05:00
|
|
|
if(m_mainmenu_background.size()==0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"No mainmenu background defined in stk_config");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2008-10-16 19:49:27 -04:00
|
|
|
CHECK_NEG(m_max_karts, "max-karts" );
|
|
|
|
CHECK_NEG(m_grid_order, "grid-order" );
|
2008-03-06 08:32:51 -05:00
|
|
|
CHECK_NEG(m_parachute_friction, "parachute-friction" );
|
|
|
|
CHECK_NEG(m_parachute_done_fraction, "parachute-done-fraction" );
|
|
|
|
CHECK_NEG(m_parachute_time, "parachute-time" );
|
|
|
|
CHECK_NEG(m_parachute_time_other, "parachute-time-other" );
|
2007-05-27 12:01:53 -04:00
|
|
|
CHECK_NEG(m_bomb_time, "bomb-time" );
|
|
|
|
CHECK_NEG(m_bomb_time_increase, "bomb-time-increase" );
|
|
|
|
CHECK_NEG(m_anvil_time, "anvil-time" );
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
CHECK_NEG(m_anvil_weight, "anvil-weight" );
|
2008-01-01 09:30:39 -05:00
|
|
|
CHECK_NEG(m_zipper_time, "zipper-time" );
|
|
|
|
CHECK_NEG(m_zipper_force, "zipper-force" );
|
2008-03-05 08:22:00 -05:00
|
|
|
CHECK_NEG(m_zipper_speed_gain, "zipper-speed-gain" );
|
2008-10-15 20:20:49 -04:00
|
|
|
CHECK_NEG(m_shortcut_length, "shortcut-length" );
|
2009-01-12 19:16:09 -05:00
|
|
|
CHECK_NEG(m_offroad_tolerance, "offroad-tolerance" );
|
2009-01-14 06:44:33 -05:00
|
|
|
CHECK_NEG(m_final_camera_time, "final-camera-time" );
|
2007-08-21 10:50:45 -04:00
|
|
|
CHECK_NEG(m_explosion_impulse, "explosion-impulse" );
|
2008-02-05 06:56:21 -05:00
|
|
|
CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" );
|
2008-10-06 09:40:11 -04:00
|
|
|
CHECK_NEG(m_max_history, "max-history" );
|
2008-12-07 20:07:16 -05:00
|
|
|
CHECK_NEG(m_max_skidmarks, "max-skidmarks" );
|
2009-01-05 19:20:23 -05:00
|
|
|
CHECK_NEG(m_skid_fadeout_time, "skid-fadeout-time" );
|
2009-01-05 21:39:30 -05:00
|
|
|
CHECK_NEG(m_slowdown_factor, "slowdown-factor" );
|
2008-10-06 09:40:11 -04:00
|
|
|
CHECK_NEG(m_delay_finish_time, "delay-finish-time" );
|
|
|
|
CHECK_NEG(m_music_credit_time, "music-credit-time" );
|
2008-10-16 19:49:27 -04:00
|
|
|
m_kart_properties.checkAllSet(filename);
|
2007-05-27 12:01:53 -04:00
|
|
|
} // load
|
|
|
|
|
2008-02-11 23:35:39 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
2007-05-27 12:01:53 -04:00
|
|
|
/** Init all values with invalid defaults, which are tested later. This
|
|
|
|
* guarantees that all parameters will indeed be initialised, and helps
|
|
|
|
* finding typos.
|
|
|
|
*/
|
|
|
|
void STKConfig::init_defaults()
|
|
|
|
{
|
2008-10-16 19:49:27 -04:00
|
|
|
m_anvil_weight = m_parachute_friction =
|
|
|
|
m_parachute_time = m_parachute_done_fraction =
|
|
|
|
m_parachute_time_other = m_anvil_speed_factor =
|
|
|
|
m_bomb_time = m_bomb_time_increase =
|
|
|
|
m_anvil_time = m_zipper_time =
|
|
|
|
m_zipper_force = m_zipper_speed_gain =
|
|
|
|
m_explosion_impulse = m_explosion_impulse_objects =
|
|
|
|
m_shortcut_length = m_music_credit_time =
|
2009-01-05 19:20:23 -05:00
|
|
|
m_delay_finish_time = m_skid_fadeout_time =
|
2009-01-12 19:16:09 -05:00
|
|
|
m_slowdown_factor = m_offroad_tolerance =
|
2009-01-14 06:44:33 -05:00
|
|
|
m_final_camera_time =
|
2008-10-16 19:49:27 -04:00
|
|
|
UNDEFINED;
|
|
|
|
m_max_karts = -100;
|
|
|
|
m_grid_order = -100;
|
|
|
|
m_max_history = -100;
|
2008-12-07 20:07:16 -05:00
|
|
|
m_max_skidmarks = -100;
|
2008-10-16 19:49:27 -04:00
|
|
|
m_title_music = NULL;
|
2008-12-10 20:41:22 -05:00
|
|
|
m_enable_networking = true;
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_scores.clear();
|
2008-04-15 09:57:18 -04:00
|
|
|
m_leader_intervals.clear();
|
2007-05-27 12:01:53 -04:00
|
|
|
} // init_defaults
|
|
|
|
|
2009-01-12 07:29:31 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const std::string &STKConfig::getMainMenuPicture(int n)
|
|
|
|
{
|
|
|
|
if(n>=0 && n<(int)m_mainmenu_background.size())
|
|
|
|
return m_mainmenu_background[n];
|
|
|
|
else
|
|
|
|
return m_mainmenu_background[0];
|
|
|
|
} // getMainMenuPicture
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const std::string &STKConfig::getBackgroundPicture(int n)
|
|
|
|
{
|
|
|
|
if(n>=0 && n<(int)m_menu_background.size())
|
|
|
|
return m_menu_background[n];
|
|
|
|
else
|
|
|
|
return m_menu_background[0];
|
|
|
|
} // getBackgroundPicture
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-16 19:49:27 -04:00
|
|
|
/** Extracts the actual information from a lisp file.
|
|
|
|
* \param lisp Pointer to the lisp data structure.
|
|
|
|
*/
|
2007-05-27 12:01:53 -04:00
|
|
|
void STKConfig::getAllData(const lisp::Lisp* lisp)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Get the values which are not part of the default KartProperties
|
|
|
|
// ---------------------------------------------------------------
|
2008-03-06 08:32:51 -05:00
|
|
|
lisp->get("anvil-weight", m_anvil_weight );
|
2009-01-12 19:16:09 -05:00
|
|
|
lisp->get("shortcut-length", m_shortcut_length );
|
|
|
|
lisp->get("offroad-tolerance", m_offroad_tolerance );
|
2009-01-14 06:44:33 -05:00
|
|
|
lisp->get("final-camera-time", m_final_camera_time );
|
2008-03-06 08:32:51 -05:00
|
|
|
lisp->get("anvil-speed-factor", m_anvil_speed_factor );
|
|
|
|
lisp->get("parachute-friction", m_parachute_friction );
|
|
|
|
lisp->get("parachute-time", m_parachute_time );
|
|
|
|
lisp->get("parachute-time-other", m_parachute_time_other );
|
|
|
|
lisp->get("parachute-done-fraction", m_parachute_done_fraction );
|
|
|
|
lisp->get("bomb-time", m_bomb_time );
|
|
|
|
lisp->get("bomb-time-increase", m_bomb_time_increase );
|
2008-04-15 09:57:18 -04:00
|
|
|
lisp->getVector("leader-intervals", m_leader_intervals );
|
2008-03-06 08:32:51 -05:00
|
|
|
lisp->get("anvil-time", m_anvil_time );
|
|
|
|
lisp->get("zipper-time", m_zipper_time );
|
|
|
|
lisp->get("zipper-force", m_zipper_force );
|
|
|
|
lisp->get("zipper-speed-gain", m_zipper_speed_gain );
|
|
|
|
lisp->get("explosion-impulse", m_explosion_impulse );
|
2008-02-05 06:56:21 -05:00
|
|
|
lisp->get("explosion-impulse-objects", m_explosion_impulse_objects);
|
2008-03-06 08:32:51 -05:00
|
|
|
lisp->get("max-karts", m_max_karts );
|
|
|
|
lisp->get("grid-order", m_grid_order );
|
2008-10-06 09:40:11 -04:00
|
|
|
lisp->getVector("scores", m_scores );
|
|
|
|
lisp->get("max-history", m_max_history );
|
2008-12-07 20:07:16 -05:00
|
|
|
lisp->get("max-skidmarks", m_max_skidmarks );
|
2009-01-05 19:20:23 -05:00
|
|
|
lisp->get("skid-fadeout-time", m_skid_fadeout_time );
|
2009-01-05 21:39:30 -05:00
|
|
|
lisp->get("slowdown-factor", m_slowdown_factor );
|
2008-10-06 09:40:11 -04:00
|
|
|
lisp->get("delay-finish-time", m_delay_finish_time );
|
|
|
|
lisp->get("music-credit-time", m_music_credit_time );
|
2009-01-12 07:29:31 -05:00
|
|
|
lisp->getVector("menu-background", m_menu_background );
|
|
|
|
lisp->getVector("mainmenu-background", m_mainmenu_background );
|
2008-12-10 20:41:22 -05:00
|
|
|
lisp->get("enable_networking", m_enable_networking );
|
2008-03-14 05:49:17 -04:00
|
|
|
std::string title_music;
|
|
|
|
lisp->get("title-music", title_music );
|
|
|
|
m_title_music = new MusicInformation(file_manager->getMusicFile(title_music));
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
// Get the default KartProperties
|
|
|
|
// ------------------------------
|
2008-10-16 19:49:27 -04:00
|
|
|
m_kart_properties.getAllData(lisp->getLisp("kart-defaults"));
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
} // getAllData
|