1
// $Id: kart_properties.cpp 702 2006-08-31 03:17:18Z hiker $
3
// SuperTuxKart - a fun racing game with go-kart
4
// Copyright (C) 2006 SuperTuxKart-Team
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "material_manager.hpp"
24
#include "lisp/parser.hpp"
25
#include "lisp/lisp.hpp"
27
#include "preprocessor.hpp"
28
#include "string_utils.hpp"
29
#include "kart_properties.hpp"
30
#include "physics_parameters.hpp"
32
// This constructor would be a bit more useful, nicer, if we could call
33
// init_defaults() and load from here. Unfortunately, this object is used
34
// as a base class for PhysicsParameters, which has to overwrite
35
// init_defaults() and getAllData(). But during the call of this constructor,
36
// the PhysicsParameters object does not (yet) exist, so the overwriting
37
// functions do NOT get called, only the virtual functions here would be
38
// called. Therefore, a two step initialisation is necessary: the constructor
39
// doing not much, but then in load the overwriting functions can be used.
40
KartProperties::KartProperties() : icon_material(0), model(0) {
43
// -----------------------------------------------------------------------------
44
void KartProperties::load(const char* filename, char *node) {
48
const lisp::Lisp* root = 0;
49
ident = StringUtils::basename(StringUtils::without_extension(filename));
53
root = parser.parse(loader->getPath(filename));
55
const lisp::Lisp* lisp = root->getLisp(node);
60
throw std::runtime_error(s);
63
} catch(std::exception& err) {
64
std::cout << "Error while parsing KartProperties '" << filename
65
<< ": " << err.what() << "\n";
70
icon_material = material_manager->getMaterial(icon_file.c_str());
73
if(model_file.length()>0) {
74
//JH model = ssgLoadAC ( ("models/"+model_file).c_str(), loader ) ;
75
model = ssgLoadAC ( model_file.c_str(), loader ) ;
79
preProcessObj(model, 0);
85
// -----------------------------------------------------------------------------
86
KartProperties::~KartProperties() {
87
ssgDeRefDelete(model);
90
// -----------------------------------------------------------------------------
91
void KartProperties::getAllData(const lisp::Lisp* lisp) {
92
lisp->get("name", name);
93
lisp->get("model-file", model_file);
94
lisp->get("icon-file", icon_file);
95
lisp->get("shadow-file", shadow_file);
96
lisp->get("red", color[0]);
97
lisp->get("green", color[1]);
98
lisp->get("blue", color[2]);
100
lisp->get("wheel-base", wheel_base);
101
lisp->get("heightCOG", heightCOG);
102
lisp->get("engine-power", engine_power);
103
lisp->get("time-full-steer", time_full_steer);
104
lisp->get("brake-factor", brake_factor);
105
lisp->get("roll-resistance", roll_resistance);
106
lisp->get("mass", mass);
107
lisp->get("air-resistance", air_resistance);
108
lisp->get("tire-grip", tire_grip);
109
lisp->get("max-steer-angle", max_steer_angle);
110
lisp->get("corn-f", corn_f);
111
lisp->get("corn-r", corn_r);
112
lisp->get("inertia", inertia);
113
lisp->get("wheelie-max-speed-ratio", wheelieMaxSpeedRatio);
114
lisp->get("wheelie-max-pitch", wheelieMaxPitch );
115
lisp->get("wheelie-pitch-rate", wheeliePitchRate );
116
lisp->get("wheelie-restore-rate", wheelieRestoreRate );
117
lisp->get("wheelie-speed-boost", wheelieSpeedBoost );
119
// -----------------------------------------------------------------------------
120
void KartProperties::init_defaults() {
124
model_file = "tuxkart.ac";
125
icon_file = "tuxicon.png";
126
shadow_file = "tuxkartshadow.png";
128
color[0] = 1.0f; color[1] = 0.0f; color[2] = 0.0f;
130
wheel_base = physicsParameters->wheel_base;
131
heightCOG = physicsParameters->heightCOG;
132
engine_power = physicsParameters->engine_power;
133
time_full_steer = physicsParameters->time_full_steer;
134
brake_factor = physicsParameters->brake_factor;
135
roll_resistance = physicsParameters->roll_resistance;
136
mass = physicsParameters->mass;
137
air_resistance = physicsParameters->air_resistance;
138
tire_grip = physicsParameters->tire_grip;
139
max_steer_angle = physicsParameters->max_steer_angle;
140
corn_f = physicsParameters->corn_f;
141
corn_r = physicsParameters->corn_r;
142
inertia = physicsParameters->inertia;
143
wheelieMaxSpeedRatio = physicsParameters->wheelieMaxSpeedRatio;
144
wheelieMaxPitch = physicsParameters->wheelieMaxPitch;
145
wheeliePitchRate = physicsParameters->wheeliePitchRate;
146
wheelieRestoreRate = physicsParameters->wheelieRestoreRate;
147
wheelieSpeedBoost = physicsParameters->wheelieSpeedBoost;
150
// -----------------------------------------------------------------------------