Increase max speed if a rubber band is being used. Settings can

be adjusted in stk_config.xml.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6703 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-11-23 10:41:13 +00:00
parent 6fa0eea7b4
commit 4696f1b323
7 changed files with 53 additions and 29 deletions

View File

@ -280,6 +280,7 @@
the force a plunger/rubber band applies to the kart(s).
duration is the duration a rubber band acts. -->
<plunger band-max-length="50" band-force="1500" band-duration="1"
band-speed-increase="7" band-fade-out-time="3"
in-face-time="5 7 10"/>
<!-- Kart-specific explosion parameters. Height: how high this

View File

@ -112,7 +112,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, PowerupManager::POWERUP_PLUNGER)
m_rubber_band = NULL;
else
{
m_rubber_band = new RubberBand(this, *kart);
m_rubber_band = new RubberBand(this, kart);
}
m_keep_alive = -1;
} // Plunger

View File

@ -58,7 +58,7 @@ const wchar_t* getPlungerString()
* can trigger an explosion)
* \param kart Reference to the kart.
*/
RubberBand::RubberBand(Plunger *plunger, const Kart &kart) :
RubberBand::RubberBand(Plunger *plunger, Kart *kart) :
m_plunger(plunger), m_owner(kart)
{
video::SColor color(77, 179, 0, 0);
@ -75,7 +75,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart) :
updatePosition();
m_node = irr_driver->addMesh(m_mesh);
#ifdef DEBUG
std::string debug_name = m_owner.getIdent()+" (rubber-band)";
std::string debug_name = m_owner->getIdent()+" (rubber-band)";
m_node->setName(debug_name.c_str());
#endif
@ -101,7 +101,7 @@ RubberBand::~RubberBand()
*/
void RubberBand::updatePosition()
{
const Vec3 &k = m_owner.getXYZ();
const Vec3 &k = m_owner->getXYZ();
// Get the position to which the band is attached
// ----------------------------------------------
@ -137,7 +137,7 @@ void RubberBand::updatePosition()
*/
void RubberBand::update(float dt)
{
if(m_owner.isEliminated())
if(m_owner->isEliminated())
{
// Rubber band snaps
m_plunger->hit(NULL);
@ -147,12 +147,12 @@ void RubberBand::update(float dt)
}
updatePosition();
const Vec3 &k = m_owner.getXYZ();
const Vec3 &k = m_owner->getXYZ();
// Check for rubber band snapping
// ------------------------------
float l = (m_end_position-k).length2();
float max_len = m_owner.getKartProperties()->getRubberBandMaxLength();
float max_len = m_owner->getKartProperties()->getRubberBandMaxLength();
if(l>max_len*max_len)
{
// Rubber band snaps
@ -165,7 +165,7 @@ void RubberBand::update(float dt)
// ----------------------------
if(m_attached_state!=RB_TO_PLUNGER)
{
float force = m_owner.getKartProperties()->getRubberBandForce();
float force = m_owner->getKartProperties()->getRubberBandForce();
Vec3 diff = m_end_position-k;
// detach rubber band if kart gets very close to hit point
@ -179,7 +179,11 @@ void RubberBand::update(float dt)
}
diff.normalize(); // diff can't be zero here
m_owner.getBody()->applyCentralForce(diff*force);
m_owner->getBody()->applyCentralForce(diff*force);
m_owner->increaseMaxSpeed(MaxSpeed::MS_INCREASE_RUBBER,
m_owner->getKartProperties()->getRubberBandSpeedIncrease(),
/*duration*/0.1f,
m_owner->getKartProperties()->getRubberBandFadeOutTime());
if(m_attached_state==RB_TO_KART)
m_hit_kart->getBody()->applyCentralForce(diff*(-force));
}
@ -198,19 +202,19 @@ void RubberBand::checkForHit(const Vec3 &k, const Vec3 &p)
short int old_kart_group=0;
// If the owner is being rescued, the broadphase handle does not exist!
if(m_owner.getBody()->getBroadphaseHandle())
old_kart_group = m_owner.getBody()->getBroadphaseHandle()->m_collisionFilterGroup;
if(m_owner->getBody()->getBroadphaseHandle())
old_kart_group = m_owner->getBody()->getBroadphaseHandle()->m_collisionFilterGroup;
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
if(m_owner.getBody()->getBroadphaseHandle())
m_owner.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
if(m_owner->getBody()->getBroadphaseHandle())
m_owner->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
// Do the raycast
World::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(k, p,
ray_callback);
// Reset collision groups
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group;
if(m_owner.getBody()->getBroadphaseHandle())
m_owner.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_kart_group;
if(m_owner->getBody()->getBroadphaseHandle())
m_owner->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_kart_group;
if(ray_callback.HasHit())
{
Vec3 pos(ray_callback.m_hitPointWorld);
@ -246,7 +250,7 @@ void RubberBand::hit(Kart *kart_hit, const Vec3 *track_xyz)
irr::core::stringw hit_message;
hit_message += StringUtils::insertValues(getPlungerString(),
kart_hit->getName().c_str(),
m_owner.getName().c_str()
m_owner->getName().c_str()
).c_str();
gui->addMessage(hit_message, NULL, 3.0f, 40, video::SColor(255, 255, 255, 255), false);
return;

View File

@ -44,7 +44,7 @@ private:
/** The plunger the rubber band is attached to. */
Plunger *m_plunger;
/** The kart who shot this plunger. */
const Kart &m_owner;
Kart *m_owner;
/** The scene node for the rubber band. */
scene::ISceneNode *m_node;
@ -63,7 +63,7 @@ private:
void updatePosition();
public:
RubberBand(Plunger *plunger, const Kart &kart);
RubberBand(Plunger *plunger, Kart *kart);
~RubberBand();
void update(float dt);
void hit(Kart *kart_hit, const Vec3 *track_xyz=NULL);

View File

@ -74,7 +74,8 @@ KartProperties::KartProperties(const std::string &filename)
m_track_connection_accel = m_min_speed_turn = m_angle_at_min =
m_max_speed_turn = m_angle_at_max =
m_rubber_band_max_length = m_rubber_band_force =
m_rubber_band_duration = m_plunger_in_face_duration[0] =
m_rubber_band_duration = m_rubber_band_speed_increase =
m_rubber_band_fade_out_time = m_plunger_in_face_duration[0] =
m_plunger_in_face_duration[1] = m_plunger_in_face_duration[2] =
m_zipper_time = m_zipper_force = m_zipper_speed_gain =
m_zipper_max_speed_increase = m_zipper_fade_out_time =
@ -404,9 +405,11 @@ void KartProperties::getAllData(const XMLNode * root)
if(const XMLNode *plunger_node= root->getNode("plunger"))
{
plunger_node->get("band-max-length", &m_rubber_band_max_length );
plunger_node->get("band-force", &m_rubber_band_force );
plunger_node->get("band-duration", &m_rubber_band_duration );
plunger_node->get("band-max-length", &m_rubber_band_max_length );
plunger_node->get("band-force", &m_rubber_band_force );
plunger_node->get("band-duration", &m_rubber_band_duration );
plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase);
plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time );
std::vector<float> v;
plunger_node->get("in-face-time", &v);
if(v.size()!=3)
@ -543,12 +546,14 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_upright_tolerance, "upright tolerance" );
CHECK_NEG(m_upright_max_force, "upright max-force" );
CHECK_NEG(m_track_connection_accel, "track-connection-accel" );
CHECK_NEG(m_rubber_band_max_length, "rubber-band max-length" );
CHECK_NEG(m_plunger_in_face_duration[0],"plunger: in-face-time[0]" );
CHECK_NEG(m_plunger_in_face_duration[1],"plunger: in-face-time[1]" );
CHECK_NEG(m_plunger_in_face_duration[2],"plunger: in-face-time[2]" );
CHECK_NEG(m_rubber_band_force, "rubber-band force" );
CHECK_NEG(m_rubber_band_duration, "rubber-band duration" );
CHECK_NEG(m_plunger_in_face_duration[0],"plunger in-face-time[0]" );
CHECK_NEG(m_plunger_in_face_duration[1],"plunger in-face-time[1]" );
CHECK_NEG(m_plunger_in_face_duration[2],"plunger in-face-time[2]" );
CHECK_NEG(m_rubber_band_max_length, "plunger band-max-length" );
CHECK_NEG(m_rubber_band_force, "plunger band-force" );
CHECK_NEG(m_rubber_band_duration, "plunger band-duration" );
CHECK_NEG(m_rubber_band_speed_increase, "plunger band-speed-increase" );
CHECK_NEG(m_rubber_band_fade_out_time, "plunger band-fade-out-time" );
CHECK_NEG(m_zipper_time, "zipper-time" );
CHECK_NEG(m_zipper_fade_out_time, "zipper-fade-out-time" );
CHECK_NEG(m_zipper_force, "zipper-force" );

View File

@ -159,7 +159,12 @@ private:
/** Force of an attached rubber band. */
/** Duration a rubber band works. */
float m_rubber_band_force;
/** How long the rubber band will fly. */
float m_rubber_band_duration;
/** Increase of maximum speed of the kart when the rubber band pulls. */
float m_rubber_band_speed_increase;
/** Fade out time when the rubber band is removed. */
float m_rubber_band_fade_out_time;
/**Duration of plunger in face depending on difficulty. */
float m_plunger_in_face_duration[3];
/** Wheel base of the kart. */
@ -465,6 +470,14 @@ public:
/** Returns the duration a rubber band is active for. */
float getRubberBandDuration () const {return m_rubber_band_duration; }
/** Returns the increase of maximum speed while a rubber band is
* pulling. */
float getRubberBandSpeedIncrease() const {return m_rubber_band_speed_increase;}
/** Return the fade out time once a rubber band is removed. */
float getRubberBandFadeOutTime () const {return m_rubber_band_fade_out_time;}
/** Returns duration of a plunger in your face. */
float getPlungerInFaceTime () const
{return m_plunger_in_face_duration[race_manager->getDifficulty()];}

View File

@ -28,11 +28,12 @@ class MaxSpeed
{
public:
/** The categories to use for increasing the speed of a kart:
* Increase due to zipper, slipstream, nitro usage. */
* Increase due to zipper, slipstream, nitro, rubber band usage. */
enum {MS_INCREASE_MIN,
MS_INCREASE_ZIPPER = MS_INCREASE_MIN,
MS_INCREASE_SLIPSTREAM,
MS_INCREASE_NITRO,
MS_INCREASE_RUBBER,
MS_INCREASE_MAX};
/** The categories to use for decreasing the speed of a kart: