~ubuntu-branches/ubuntu/precise/supertuxkart/precise

« back to all changes in this revision

Viewing changes to src/kart_properties.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gonéri Le Bouder, Gonéri Le Bouder, Eddy Petrişor
  • Date: 2006-09-08 22:59:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060908225925-3spug0pnh9ekwlpw
Tags: 0.2-1
[ Gonéri Le Bouder ]
* new upstream release candidate
 + Closes: #388021
 + remove supertuxkart.sh
 + add supertuxkart(|-data).install
 + clean up
 + remove deps on ${shlibs:Depends}, ${misc:Depends} for supertuxkart-data
* fix French comment was tagged de_DE
* fix not-binnmuable-any-depends-all
* fix FTBFS on 64bit arch
 + Closes: #370810

[ Eddy Petrişor ]
* added Romanian translation to desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: kart_properties.cpp 702 2006-08-31 03:17:18Z hiker $
 
2
//
 
3
//  SuperTuxKart - a fun racing game with go-kart
 
4
//  Copyright (C) 2006 SuperTuxKart-Team
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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.
 
19
 
 
20
#include <iostream>
 
21
#include <stdexcept>
 
22
#include <plib/ssg.h>
 
23
#include "material_manager.hpp"
 
24
#include "lisp/parser.hpp"
 
25
#include "lisp/lisp.hpp"
 
26
#include "loader.hpp"
 
27
#include "preprocessor.hpp"
 
28
#include "string_utils.hpp"
 
29
#include "kart_properties.hpp"
 
30
#include "physics_parameters.hpp"
 
31
 
 
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) {
 
41
}   // KartProperties
 
42
 
 
43
// -----------------------------------------------------------------------------
 
44
void KartProperties::load(const char* filename, char *node) {
 
45
 
 
46
  init_defaults();
 
47
 
 
48
  const lisp::Lisp* root = 0;
 
49
  ident = StringUtils::basename(StringUtils::without_extension(filename));
 
50
 
 
51
  try {
 
52
    lisp::Parser parser;
 
53
    root = parser.parse(loader->getPath(filename));
 
54
    
 
55
    const lisp::Lisp* lisp = root->getLisp(node);
 
56
    if(!lisp) {
 
57
      std::string s="No '";
 
58
      s+=node;
 
59
      s+="' node found";
 
60
      throw std::runtime_error(s);
 
61
    }
 
62
    getAllData(lisp);
 
63
  } catch(std::exception& err) {
 
64
    std::cout << "Error while parsing KartProperties '" << filename
 
65
              << ": " << err.what() << "\n";
 
66
  }
 
67
  delete root;
 
68
 
 
69
  // Load material
 
70
  icon_material = material_manager->getMaterial(icon_file.c_str());
 
71
 
 
72
  // Load model
 
73
  if(model_file.length()>0) {
 
74
    //JH    model         = ssgLoadAC ( ("models/"+model_file).c_str(), loader ) ;
 
75
    model         = ssgLoadAC ( model_file.c_str(), loader ) ;
 
76
 
 
77
    ssgStripify(model);
 
78
 
 
79
    preProcessObj(model, 0);
 
80
    model->ref();
 
81
  }
 
82
 
 
83
}   // load
 
84
 
 
85
// -----------------------------------------------------------------------------
 
86
KartProperties::~KartProperties() {
 
87
  ssgDeRefDelete(model);
 
88
}   // ~KartProperties
 
89
 
 
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]);
 
99
 
 
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   );
 
118
}   // getAllData
 
119
// -----------------------------------------------------------------------------
 
120
void KartProperties::init_defaults() {
 
121
 
 
122
  name          = "Tux";
 
123
  ident         = "tux";
 
124
  model_file    = "tuxkart.ac";
 
125
  icon_file     = "tuxicon.png";
 
126
  shadow_file   = "tuxkartshadow.png";
 
127
 
 
128
  color[0] = 1.0f; color[1] = 0.0f; color[2] = 0.0f;
 
129
 
 
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;
 
148
}   // init_defaults
 
149
 
 
150
// -----------------------------------------------------------------------------
 
151
/* EOF */