Added new 'has-skidmarks' property which defaults to true.

If it is set to false, the kart will have neither skid marks
nor skiddinf sfx. Currently used for the gnu kart.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3001 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-01-20 13:51:08 +00:00
parent d0c7f12cac
commit 7e02093329
4 changed files with 279 additions and 267 deletions

View File

@@ -352,7 +352,7 @@ void Kart::reset()
m_vehicle->applyEngineForce (0.0f, 3);
Moveable::reset();
m_skidmarks->reset();
if(m_skidmarks) m_skidmarks->reset();
for(int j=0; j<m_vehicle->getNumWheels(); j++)
{
m_vehicle->updateWheelTransform(j, true);
@@ -636,7 +636,8 @@ void Kart::update(float dt)
// Check if any item was hit.
item_manager->hitItem(this);
m_skidmarks->update(dt);
if(m_kart_properties->hasSkidmarks())
m_skidmarks->update(dt);
// Remove the shadow if the kart is not on the ground (if a kart
// is rescued isOnGround might still be true, since the kart rigid
@@ -862,7 +863,8 @@ void Kart::updatePhysics (float dt)
}
if(m_skidding>1.0f)
{
if(m_skid_sound->getStatus() != SFXManager::SFX_PLAYING)
if(m_skid_sound->getStatus() != SFXManager::SFX_PLAYING &&
m_kart_properties->hasSkidmarks())
m_skid_sound->play();
}
else if(m_skid_sound->getStatus() == SFXManager::SFX_PLAYING)
@@ -993,7 +995,8 @@ void Kart::loadData()
m_nitro = new Nitro(this);
m_nitro->ref();
m_skidmarks = new SkidMarks(*this);
if(m_kart_properties->hasSkidmarks())
m_skidmarks = new SkidMarks(*this);
m_shadow = createShadow(m_kart_properties->getShadowFile(), -1, 1, -1, 1);
m_shadow->ref();

View File

@@ -1,57 +1,57 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// 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 "kart_properties.hpp"
#include <iostream>
#include <stdexcept>
#include <plib/ssg.h>
#include "material_manager.hpp"
#include "loader.hpp"
#include "file_manager.hpp"
#include "string_utils.hpp"
#include "stk_config.hpp"
#include "translation.hpp"
#include "user_config.hpp"
#include "karts/kart_model.hpp"
#include "lisp/parser.hpp"
#include "lisp/lisp.hpp"
#include "utils/ssg_help.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// 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 "kart_properties.hpp"
#include <iostream>
#include <stdexcept>
#include <plib/ssg.h>
#include "material_manager.hpp"
#include "loader.hpp"
#include "file_manager.hpp"
#include "string_utils.hpp"
#include "stk_config.hpp"
#include "translation.hpp"
#include "user_config.hpp"
#include "karts/kart_model.hpp"
#include "lisp/parser.hpp"
#include "lisp/lisp.hpp"
#include "utils/ssg_help.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
float KartProperties::UNDEFINED = -99.9f;
/** The constructor initialises all values with invalid values. It can later
* then be checked (for STKConfig) that all values are indeed defined.
* Otherwise the defaults are taken from STKConfig (and since they are all
* defined, it is guaranteed that each kart has well defined physics values.
*/
KartProperties::KartProperties() : m_icon_material(0)
{
m_name = "Tux";
m_ident = "tux";
m_icon_file = "tuxicon.png";
m_shadow_file = "tuxkartshadow.png";
m_groups.clear();
/** The constructor initialises all values with invalid values. It can later
* then be checked (for STKConfig) that all values are indeed defined.
* Otherwise the defaults are taken from STKConfig (and since they are all
* defined, it is guaranteed that each kart has well defined physics values.
*/
KartProperties::KartProperties() : m_icon_material(0)
{
m_name = "Tux";
m_ident = "tux";
m_icon_file = "tuxicon.png";
m_shadow_file = "tuxkartshadow.png";
m_groups.clear();
// Set all other values to undefined, so that it can later be tested
// if everything is defined properly.
@@ -72,81 +72,82 @@ KartProperties::KartProperties() : m_icon_material(0)
m_rubber_band_duration = m_time_till_max_skid =
m_skid_decrease = m_skid_increase = m_skid_visual = m_skid_max =
m_camera_max_accel = m_camera_max_brake =
m_camera_distance = UNDEFINED;
m_gravity_center_shift = Vec3(UNDEFINED);
m_version = 0;
m_camera_distance = UNDEFINED;
m_gravity_center_shift = Vec3(UNDEFINED);
m_has_skidmarks = true;
m_version = 0;
m_color.setValue(1.0f, 0.0f, 0.0f);
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
} // KartProperties
//-----------------------------------------------------------------------------
/** Destructor, dereferences the kart model. */
KartProperties::~KartProperties()
{
} // ~KartProperties
//-----------------------------------------------------------------------------
/** Loads the kart properties from a file.
* \param filename Filename to load.
* \param node Name of the lisp node to load the data from
* (default: tuxkart-kart)
* \param dont_load_models If set does not load the actual kart models, used
* when only printing kart information to stdout.
*/
void KartProperties::load(const std::string &filename, const std::string &node,
bool dont_load_models)
{
// Get the default values from STKConfig:
*this = stk_config->getDefaultKartProperties();
const lisp::Lisp* root = 0;
m_ident = StringUtils::basename(StringUtils::without_extension(filename));
try
{
lisp::Parser parser;
root = parser.parse(filename);
const lisp::Lisp* const LISP = root->getLisp(node);
if(!LISP)
{
char msg[MAX_ERROR_MESSAGE_LENGTH];
snprintf(msg, sizeof(msg), "No '%s' node found.", node.c_str());
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;
// Set a default group (that has to happen after init_default and load)
if(m_groups.size()==0)
m_groups.push_back("standard");
// Load material
std::string materials_file = file_manager->getKartFile("materials.dat",getIdent());
file_manager->pushModelSearchPath(file_manager->getKartFile("", getIdent()));
file_manager->pushTextureSearchPath(file_manager->getKartFile("", getIdent()));
// addShared makes sure that these textures/material infos stay in memory
material_manager->addSharedMaterial(materials_file);
m_icon_material = material_manager->getMaterial(m_icon_file);
// Load model, except when called as part of --list-karts
if(!dont_load_models)
{
// Only load the model if the .kart file has the appropriate version,
// otherwise warnings are printed.
if(m_version>=1)
m_kart_model.loadModels();
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
} // KartProperties
//-----------------------------------------------------------------------------
/** Destructor, dereferences the kart model. */
KartProperties::~KartProperties()
{
} // ~KartProperties
//-----------------------------------------------------------------------------
/** Loads the kart properties from a file.
* \param filename Filename to load.
* \param node Name of the lisp node to load the data from
* (default: tuxkart-kart)
* \param dont_load_models If set does not load the actual kart models, used
* when only printing kart information to stdout.
*/
void KartProperties::load(const std::string &filename, const std::string &node,
bool dont_load_models)
{
// Get the default values from STKConfig:
*this = stk_config->getDefaultKartProperties();
const lisp::Lisp* root = 0;
m_ident = StringUtils::basename(StringUtils::without_extension(filename));
try
{
lisp::Parser parser;
root = parser.parse(filename);
const lisp::Lisp* const LISP = root->getLisp(node);
if(!LISP)
{
char msg[MAX_ERROR_MESSAGE_LENGTH];
snprintf(msg, sizeof(msg), "No '%s' node found.", node.c_str());
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;
// Set a default group (that has to happen after init_default and load)
if(m_groups.size()==0)
m_groups.push_back("standard");
// Load material
std::string materials_file = file_manager->getKartFile("materials.dat",getIdent());
file_manager->pushModelSearchPath(file_manager->getKartFile("", getIdent()));
file_manager->pushTextureSearchPath(file_manager->getKartFile("", getIdent()));
// addShared makes sure that these textures/material infos stay in memory
material_manager->addSharedMaterial(materials_file);
m_icon_material = material_manager->getMaterial(m_icon_file);
// Load model, except when called as part of --list-karts
if(!dont_load_models)
{
// Only load the model if the .kart file has the appropriate version,
// otherwise warnings are printed.
if(m_version>=1)
m_kart_model.loadModels();
if(m_gravity_center_shift.getX()==UNDEFINED)
{
m_gravity_center_shift.setX(0);
@@ -160,42 +161,42 @@ void KartProperties::load(const std::string &filename, const std::string &node,
-m_kart_model.getWheelPhysicsPosition(2).getY());
m_angle_at_min = asinf(m_wheel_base/m_min_radius);
m_angle_at_max = asinf(m_wheel_base/m_max_radius);
if(m_max_speed_turn == m_min_speed_turn)
m_speed_angle_increase = 0.0;
else
m_speed_angle_increase = (m_angle_at_min - m_angle_at_max)
/ (m_max_speed_turn - m_min_speed_turn);
// Useful when tweaking kart parameters
if(user_config->m_print_kart_sizes)
printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),
m_kart_model.getWidth(), m_kart_model.getLength(),
m_kart_model.getHeight());
} // if
file_manager->popTextureSearchPath();
file_manager->popModelSearchPath();
} // load
//-----------------------------------------------------------------------------
void KartProperties::getAllData(const lisp::Lisp* lisp)
{
lisp->get("version", m_version);
// Only load the kart_model data if the .kart file has the appropriate
if(m_version>=1)
m_kart_model.loadInfo(lisp);
lisp->get("name", m_name);
lisp->get("icon-file", m_icon_file);
lisp->get("shadow-file", m_shadow_file);
lisp->get("rgb", m_color);
lisp->get("engine-power", m_engine_power);
lisp->get("time-full-steer", m_time_full_steer);
lisp->get("time-full-steer-ai", m_time_full_steer_ai);
lisp->get("brake-factor", m_brake_factor);
if(m_max_speed_turn == m_min_speed_turn)
m_speed_angle_increase = 0.0;
else
m_speed_angle_increase = (m_angle_at_min - m_angle_at_max)
/ (m_max_speed_turn - m_min_speed_turn);
// Useful when tweaking kart parameters
if(user_config->m_print_kart_sizes)
printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),
m_kart_model.getWidth(), m_kart_model.getLength(),
m_kart_model.getHeight());
} // if
file_manager->popTextureSearchPath();
file_manager->popModelSearchPath();
} // load
//-----------------------------------------------------------------------------
void KartProperties::getAllData(const lisp::Lisp* lisp)
{
lisp->get("version", m_version);
// Only load the kart_model data if the .kart file has the appropriate
if(m_version>=1)
m_kart_model.loadInfo(lisp);
lisp->get("name", m_name);
lisp->get("icon-file", m_icon_file);
lisp->get("shadow-file", m_shadow_file);
lisp->get("rgb", m_color);
lisp->get("engine-power", m_engine_power);
lisp->get("time-full-steer", m_time_full_steer);
lisp->get("time-full-steer-ai", m_time_full_steer_ai);
lisp->get("brake-factor", m_brake_factor);
lisp->get("mass", m_mass);
std::string sfx_type_string;
@@ -207,88 +208,89 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
else if(sfx_type_string == "small")
{
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
}
std::vector<float> v;
if(lisp->getVector("max-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect max-speed-angle specifications for kart '%s'\n",
getIdent().c_str());
else
{
m_max_speed_turn = v[0];
m_max_radius = v[1];
}
}
v.clear();
if(lisp->getVector("min-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect min-speed-angle specifications for kart '%s'\n",
getIdent().c_str());
else
{
m_min_speed_turn = v[0];
m_min_radius = v[1];
}
}
lisp->get("nitro-power-boost", m_nitro_power_boost );
//bullet physics data
lisp->get("suspension-stiffness", m_suspension_stiffness );
lisp->get("wheel-damping-relaxation", m_wheel_damping_relaxation );
lisp->get("wheel-damping-compression", m_wheel_damping_compression);
lisp->get("friction-slip", m_friction_slip );
lisp->get("roll-influence", m_roll_influence );
lisp->get("wheel-radius", m_wheel_radius );
lisp->get("chassis-linear-damping", m_chassis_linear_damping );
lisp->get("chassis-angular-damping", m_chassis_angular_damping );
lisp->get("max-speed-reverse-ratio", m_max_speed_reverse_ratio );
lisp->get("max-speed", m_max_speed );
lisp->get("gravity-center-shift", m_gravity_center_shift );
lisp->get("suspension-rest", m_suspension_rest );
lisp->get("suspension-travel-cm", m_suspension_travel_cm );
lisp->get("jump-velocity", m_jump_velocity );
lisp->get("upright-tolerance", m_upright_tolerance );
lisp->get("upright-max-force", m_upright_max_force );
lisp->get("track-connection-accel", m_track_connection_accel );
lisp->get("rubber-band-max-length", m_rubber_band_max_length );
lisp->get("rubber-band-force", m_rubber_band_force );
lisp->get("rubber-band-duration", m_rubber_band_duration );
lisp->get("skid-increase", m_skid_increase );
lisp->get("skid-decrease", m_skid_decrease );
lisp->get("time-till-max-skid", m_time_till_max_skid );
lisp->get("skid-max", m_skid_max );
lisp->get("skid-visual", m_skid_visual );
lisp->getVector("groups", m_groups );
// getVector appends to existing vectors, so a new one must be used to load
std::vector<float> temp;
lisp->getVector("gear-switch-ratio", temp);
if(temp.size()>0) m_gear_switch_ratio = temp;
temp.clear();
lisp->getVector("gear-power-increase", temp);
if(temp.size()>0) m_gear_power_increase = temp;
// Camera
lisp->get("camera-max-accel", m_camera_max_accel);
lisp->get("camera-max-brake", m_camera_max_brake);
lisp->get("camera-distance", m_camera_distance );
} // getAllData
//-----------------------------------------------------------------------------
/** Checks if all necessary physics values are indeed defines. This helps
* finding bugs early, e.g. missing default in stk_config.dat file.
* \param filename File from which the data was read (only used to print
* meaningful error messages).
*/
void KartProperties::checkAllSet(const std::string &filename)
{
}
std::vector<float> v;
if(lisp->getVector("max-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect max-speed-angle specifications for kart '%s'\n",
getIdent().c_str());
else
{
m_max_speed_turn = v[0];
m_max_radius = v[1];
}
}
v.clear();
if(lisp->getVector("min-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect min-speed-angle specifications for kart '%s'\n",
getIdent().c_str());
else
{
m_min_speed_turn = v[0];
m_min_radius = v[1];
}
}
lisp->get("nitro-power-boost", m_nitro_power_boost );
//bullet physics data
lisp->get("suspension-stiffness", m_suspension_stiffness );
lisp->get("wheel-damping-relaxation", m_wheel_damping_relaxation );
lisp->get("wheel-damping-compression", m_wheel_damping_compression);
lisp->get("friction-slip", m_friction_slip );
lisp->get("roll-influence", m_roll_influence );
lisp->get("wheel-radius", m_wheel_radius );
lisp->get("chassis-linear-damping", m_chassis_linear_damping );
lisp->get("chassis-angular-damping", m_chassis_angular_damping );
lisp->get("max-speed-reverse-ratio", m_max_speed_reverse_ratio );
lisp->get("max-speed", m_max_speed );
lisp->get("gravity-center-shift", m_gravity_center_shift );
lisp->get("suspension-rest", m_suspension_rest );
lisp->get("suspension-travel-cm", m_suspension_travel_cm );
lisp->get("jump-velocity", m_jump_velocity );
lisp->get("upright-tolerance", m_upright_tolerance );
lisp->get("upright-max-force", m_upright_max_force );
lisp->get("track-connection-accel", m_track_connection_accel );
lisp->get("rubber-band-max-length", m_rubber_band_max_length );
lisp->get("rubber-band-force", m_rubber_band_force );
lisp->get("rubber-band-duration", m_rubber_band_duration );
lisp->get("skid-increase", m_skid_increase );
lisp->get("skid-decrease", m_skid_decrease );
lisp->get("time-till-max-skid", m_time_till_max_skid );
lisp->get("has-skidmarks", m_has_skidmarks );
lisp->get("skid-max", m_skid_max );
lisp->get("skid-visual", m_skid_visual );
lisp->getVector("groups", m_groups );
// getVector appends to existing vectors, so a new one must be used to load
std::vector<float> temp;
lisp->getVector("gear-switch-ratio", temp);
if(temp.size()>0) m_gear_switch_ratio = temp;
temp.clear();
lisp->getVector("gear-power-increase", temp);
if(temp.size()>0) m_gear_power_increase = temp;
// Camera
lisp->get("camera-max-accel", m_camera_max_accel);
lisp->get("camera-max-brake", m_camera_max_brake);
lisp->get("camera-distance", m_camera_distance );
} // getAllData
//-----------------------------------------------------------------------------
/** Checks if all necessary physics values are indeed defines. This helps
* finding bugs early, e.g. missing default in stk_config.dat file.
* \param filename File from which the data was read (only used to print
* meaningful error messages).
*/
void KartProperties::checkAllSet(const std::string &filename)
{
if(m_gear_switch_ratio.size()==0)
{
fprintf(stderr,"Missing default value for 'gear-switch-ratio' in '%s'.\n",
@@ -355,16 +357,16 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_camera_max_accel, "camera-max-accel" );
CHECK_NEG(m_camera_max_brake, "camera-max-brake" );
CHECK_NEG(m_camera_distance, "camera-distance" );
} // checkAllSet
// ----------------------------------------------------------------------------
float KartProperties::getMaxSteerAngle(float speed) const
{
if(speed<=m_min_speed_turn) return m_angle_at_min;
if(speed>=m_max_speed_turn) return m_angle_at_max;
return m_angle_at_min - (speed-m_min_speed_turn)*m_speed_angle_increase;
} // getMaxSteerAngle
/* EOF */
} // checkAllSet
// ----------------------------------------------------------------------------
float KartProperties::getMaxSteerAngle(float speed) const
{
if(speed<=m_min_speed_turn) return m_angle_at_min;
if(speed>=m_max_speed_turn) return m_angle_at_max;
return m_angle_at_min - (speed-m_min_speed_turn)*m_speed_angle_increase;
} // getMaxSteerAngle
/* EOF */

View File

@@ -17,8 +17,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_KARTPROPERTIES_H
#define HEADER_KARTPROPERTIES_H
#ifndef HEADER_KART_PROPERTIES_HPP
#define HEADER_KART_PROPERTIES_HPP
#include <string>
#include <vector>
@@ -139,6 +139,8 @@ private:
* not skidding to decrease to 1.0. */
float m_time_till_max_skid; /**< Time till maximum skidding is
* reached. */
bool m_has_skidmarks; /**< Kart leaves skid marks. */
// Camera related setting
// ----------------------
float m_camera_max_accel; // maximum acceleration of camera
@@ -226,6 +228,8 @@ public:
/** Returns the time (in seconds) of drifting till the maximum skidding
* is reached. */
float getTimeTillMaxSkid () const {return m_time_till_max_skid; }
/** Returns if the kart leaves skidmarks or not. */
bool hasSkidmarks () const {return m_has_skidmarks; }
const std::vector<float>&
getGearSwitchRatio () const {return m_gear_switch_ratio; }
const std::vector<float>&

View File

@@ -237,7 +237,7 @@ bool KartPropertiesManager::kartAvailable(int kartid)
const KartProperties *kartprop=getKartById(kartid);
if(unlock_manager->isLocked(kartprop->getIdent())) return false;
return true;
} // testAndSetKart
} // kartAvailable
//-----------------------------------------------------------------------------
/** Sets a kart to be selected by specifying the identifier (name) of the kart.
@@ -285,7 +285,8 @@ std::vector<std::string> KartPropertiesManager::getRandomKartList(int count,
// (i.e. locked or not available on all clients)
for(unsigned int i=0; i<karts.size();)
{
if(used[karts[i]] || !m_kart_available[karts[i]])
if(used[karts[i]] || !m_kart_available[karts[i]] ||
unlock_manager->isLocked(m_karts_properties[karts[i]]->getIdent()))
karts.erase(karts.begin()+i);
else
i++;
@@ -310,7 +311,9 @@ std::vector<std::string> KartPropertiesManager::getRandomKartList(int count,
karts.clear();
for(unsigned int i=0; i<getNumberOfKarts(); i++)
{
if(!used[i] && m_kart_available[i]) karts.push_back(i);
if(!used[i] && m_kart_available[i] &&
!unlock_manager->isLocked(m_karts_properties[i]->getIdent()) )
karts.push_back(i);
}
std::random_shuffle(karts.begin(), karts.end());
// Then fill up the remaining empty spaces