2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004-2005 Ingo Ruhnke <grumbel@gmx.de>
|
|
|
|
// Copyright (C) 2006 Joerg Henrichs, Ingo Ruhnke <grumbel@gmx.de>
|
|
|
|
//
|
|
|
|
// 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 <iostream>
|
|
|
|
#include <stdexcept>
|
2008-02-29 22:18:53 -05:00
|
|
|
#include "file_manager.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
#include "lisp/parser.hpp"
|
|
|
|
#include "lisp/lisp.hpp"
|
|
|
|
#include "cup_data.hpp"
|
2008-07-29 00:30:44 -04:00
|
|
|
#include "string_utils.hpp"
|
|
|
|
#include "track_manager.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-07-29 00:30:44 -04:00
|
|
|
CupData::CupData(const std::string filename)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-07-29 00:30:44 -04:00
|
|
|
m_filename = filename;
|
|
|
|
m_id = StringUtils::without_extension(filename);
|
2007-05-27 12:01:53 -04:00
|
|
|
const lisp::Lisp* lisp = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lisp::Parser parser;
|
2008-02-29 22:18:53 -05:00
|
|
|
lisp = parser.parse(file_manager->getConfigFile(m_filename));
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
lisp = lisp->getLisp("supertuxkart-cup");
|
|
|
|
if(!lisp)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("No supertuxkart-cup node");
|
|
|
|
}
|
|
|
|
|
|
|
|
lisp->get ("name", m_name );
|
|
|
|
lisp->get ("description", m_description );
|
|
|
|
lisp->get ("herring", m_herring_style);
|
|
|
|
lisp->getVector("tracks", m_tracks );
|
2007-12-06 15:57:42 -05:00
|
|
|
lisp->getVector("laps", m_laps );
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
catch(std::exception& err)
|
|
|
|
{
|
2008-07-29 00:30:44 -04:00
|
|
|
fprintf(stderr, "Error while reading cup file '%s'\n", filename.c_str());
|
2007-05-27 12:01:53 -04:00
|
|
|
fprintf(stderr, err.what());
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete lisp;
|
|
|
|
}
|
2008-07-29 00:30:44 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool CupData::checkConsistency()
|
|
|
|
{
|
|
|
|
bool correct=true;
|
|
|
|
for(unsigned int i=0; i<m_tracks.size(); i++)
|
|
|
|
{
|
|
|
|
if(!track_manager->getTrack(m_tracks[i]))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Grand Prix '%s': Track '%s' does not exist!",
|
|
|
|
m_name.c_str(), m_tracks[i]);
|
|
|
|
correct=false;
|
|
|
|
}
|
|
|
|
} // for i
|
|
|
|
return correct;
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
/* EOF */
|