1) Fix #1011 by re-implementing the bubblegum not as a

damping of velocity, but as a max_speed restriction.
2) Bubblegum parameters are now fully configurable in
   stk_config.xml.
3) Apply slowdown fraction also to speed increases
   (e.g. previously a max speed of 23 with a zipper
   giving a 15  additional speed with a slowdown of
   0.3 would end up as: 23*0.3 + 15 = 21.9.
   Now it is (23+15)*0.3 = 11.4. While this was done
   mainly for bubble gums, it can affect other items
   as well.
4) Used bubblegum as one word consistenly in variable
   names and xml files.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12995 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-06-27 22:25:36 +00:00
parent 8275d8a7a5
commit 674be5b6d0
9 changed files with 106 additions and 31 deletions

View File

@ -114,8 +114,8 @@
nolok-bubble-gum, easter egg -->
<switch time="5" items="1 0 4 4 2 5 2 7"/>
<!-- How often bubble gum get driven over before it disappears. -->
<bubble-gum disappear-counter="1"/>
<!-- How often bubblegum get driven over before it disappears. -->
<bubblegum disappear-counter="1"/>
<!-- explosion-impulse-objects is the impulse that pushes physical objects
away if there is an explosion. -->
@ -179,6 +179,14 @@
<nitro engine-force="500" consumption="1" small-container="1" big-container="3"
max-speed-increase="5" duration="1" fade-out-time="2" max="16"/>
<!-- Bubble gum data:
time: How long the bubblegum lasts.
speed-fraction: To what fraction of top-speed the speed is reduced.
torque: To rotate the kart somewhat.
fade-in-time: How quick the slowdown takes effect.
-->
<bubblegum time="1" speed-fraction="0.3" torque="500" fade-in-time="0.01"/>
<!-- time: Time a zipper is active.
force: Additional zipper force.
speed-gain: One time additional speed.

View File

@ -117,7 +117,7 @@ void STKConfig::load(const std::string &filename)
CHECK_NEG(m_anvil_time, "anvil-time" );
CHECK_NEG(m_anvil_weight, "anvil-weight" );
CHECK_NEG(m_item_switch_time, "item-switch-time" );
CHECK_NEG(m_bubble_gum_counter, "bubblegum disappear counter");
CHECK_NEG(m_bubblegum_counter, "bubblegum disappear counter");
CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" );
CHECK_NEG(m_max_history, "max-history" );
CHECK_NEG(m_max_skidmarks, "max-skidmarks" );
@ -158,7 +158,7 @@ void STKConfig::init_defaults()
m_near_ground = m_item_switch_time =
m_smooth_angle_limit =
m_penalty_time = m_explosion_impulse_objects = UNDEFINED;
m_bubble_gum_counter = -100;
m_bubblegum_counter = -100;
m_max_karts = -100;
m_max_history = -100;
m_max_skidmarks = -100;
@ -333,9 +333,9 @@ void STKConfig::getAllData(const XMLNode * root)
switch_node->get("time", &m_item_switch_time);
}
if(const XMLNode *bubble_gum_node= root->getNode("bubble-gum"))
if(const XMLNode *bubblegum_node= root->getNode("bubblegum"))
{
bubble_gum_node->get("disappear-counter", &m_bubble_gum_counter);
bubblegum_node->get("disappear-counter", &m_bubblegum_counter);
}
if(const XMLNode *explosion_node= root->getNode("explosion"))

View File

@ -74,7 +74,7 @@ public:
passed on. */
float m_anvil_time; /**<Time an anvil is active. */
float m_item_switch_time; /**< Time items will be switched. */
int m_bubble_gum_counter; /**< How many times bananas must be eaten
int m_bubblegum_counter; /**< How many times bananas must be eaten
before they disappear. */
float m_explosion_impulse_objects;/**<Impulse of explosion on moving
objects, e.g. road cones, ... */

View File

@ -115,7 +115,7 @@ void Item::initItem(ItemType type, const Vec3 &xyz)
switch(m_type)
{
case ITEM_BUBBLEGUM:
m_disappear_counter = stk_config->m_bubble_gum_counter; break;
m_disappear_counter = stk_config->m_bubblegum_counter; break;
case ITEM_EASTER_EGG:
m_disappear_counter = -1; break;
default:
@ -247,7 +247,7 @@ void Item::reset()
switch(m_type)
{
case ITEM_BUBBLEGUM:
m_disappear_counter = stk_config->m_bubble_gum_counter; break;
m_disappear_counter = stk_config->m_bubblegum_counter; break;
case ITEM_EASTER_EGG:
m_disappear_counter = -1; break;
default:

View File

@ -306,10 +306,8 @@ void Kart::reset()
// undo bubblegum effect
if (m_bubblegum_time > 0.0f)
{
m_bubblegum_time = 0.0f;
m_bubblegum_time = 0.0f;
m_bubblegum_torque = 0.0f;
m_body->setDamping(m_kart_properties->getChassisLinearDamping(),
m_kart_properties->getChassisAngularDamping() );
}
// If the controller was replaced (e.g. replaced by end controller),
@ -346,6 +344,10 @@ void Kart::reset()
m_current_lean = 0.0f;
m_view_blocked_by_plunger = 0.0f;
m_has_caught_nolok_bubblegum = false;
// In case that the kart was in the air, in which case its
// linear damping is 0
m_body->setDamping(m_kart_properties->getChassisLinearDamping(),
m_kart_properties->getChassisAngularDamping() );
if(m_terrain_sound)
{
@ -857,12 +859,18 @@ void Kart::collectedItem(Item *item, int add_info)
break;
}
case Item::ITEM_BUBBLEGUM:
m_has_caught_nolok_bubblegum = (item->getEmitter() != NULL && item->getEmitter()->getIdent() == "nolok");
m_has_caught_nolok_bubblegum = (item->getEmitter() != NULL &&
item->getEmitter()->getIdent() == "nolok");
// slow down
m_bubblegum_time = 1.0f;
m_bubblegum_torque = (rand()%2) ? 500.0f : -500.0f;
m_body->setDamping(0.8f, 0.8f);
m_bubblegum_time = m_kart_properties->getBubblegumTime();
m_bubblegum_torque = (rand()%2)
? m_kart_properties->getBubblegumTorque()
: -m_kart_properties->getBubblegumTorque();
m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_BUBBLE,
m_kart_properties->getBubblegumSpeedFraction(),
m_kart_properties->getBubblegumFadeInTime(),
m_bubblegum_time);
m_goo_sound->position(getXYZ());
m_goo_sound->play();
// Play appropriate custom character sound
@ -982,19 +990,14 @@ void Kart::update(float dt)
if(m_squash_time<=0)
{
m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f));
m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_SQUASH,
/*slowdown*/1.0f, /*fade in*/0.0f);
}
}
} // if squashed
if (m_bubblegum_time > 0.0f)
{
m_bubblegum_time -= dt;
if (m_bubblegum_time <= 0.0f)
{
// undo bubblegum effect
m_body->setDamping(m_kart_properties->getChassisLinearDamping(),
m_kart_properties->getChassisAngularDamping() );
m_bubblegum_torque = 0.0f;
}
}
@ -1208,7 +1211,8 @@ void Kart::update(float dt)
{
m_isTimeFlying = false;
printf(" [sam] Temps en l'air: %f \n", m_timeFlying);
m_hitGround = new Explosion(this->getXYZ(), "jump", "jump_explosion.xml");
m_hitGround = new Explosion(getXYZ(), "jump",
"jump_explosion.xml");
projectile_manager->addHitEffect(m_hitGround);
m_timeFlying = 0;
}
@ -1250,7 +1254,8 @@ void Kart::setSquash(float time, float slowdown)
return;
}
m_node->setScale(core::vector3df(1.0f, 0.5f, 1.0f));
m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_SQUASH, slowdown, 0.1f);
m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_SQUASH, slowdown,
0.1f, time);
m_squash_time = time;
} // setSquash

View File

@ -88,7 +88,9 @@ KartProperties::KartProperties(const std::string &filename)
m_rescue_time = m_rescue_height = m_explosion_time =
m_explosion_radius = m_max_lean = m_lean_speed =
m_swatter_distance2 = m_swatter_duration = m_squash_slowdown =
m_squash_duration = m_downward_impulse_factor = UNDEFINED;
m_squash_duration = m_downward_impulse_factor =
m_bubblegum_fade_in_time = m_bubblegum_speed_fraction =
m_bubblegum_time = m_bubblegum_torque = UNDEFINED;
m_engine_power.resize(RaceManager::DIFFICULTY_COUNT, UNDEFINED);
m_max_speed.resize(RaceManager::DIFFICULTY_COUNT, UNDEFINED);
@ -310,6 +312,14 @@ void KartProperties::getAllData(const XMLNode * root)
nitro_node->get("max", &m_nitro_max );
}
if(const XMLNode *bubble_node = root->getNode("bubblegum"))
{
bubble_node->get("time", &m_bubblegum_time );
bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction);
bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time );
bubble_node->get("torque", &m_bubblegum_torque );
}
if(const XMLNode *rescue_node = root->getNode("rescue"))
{
rescue_node->get("vert-offset", &m_rescue_vert_offset);
@ -659,6 +669,11 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_nitro_duration, "nitro duration" );
CHECK_NEG(m_nitro_fade_out_time, "nitro fade-out-time" );
CHECK_NEG(m_nitro_max, "nitro max" );
CHECK_NEG(m_bubblegum_time, "bubblegum time" );
CHECK_NEG(m_bubblegum_speed_fraction, "bubblegum speed-fraction" );
CHECK_NEG(m_bubblegum_fade_in_time , "bubblegum fade-in-time" );
CHECK_NEG(m_bubblegum_torque, "bubblegum torque" );
CHECK_NEG(m_swatter_distance2, "swatter distance" );
CHECK_NEG(m_swatter_duration, "swatter duration" );
CHECK_NEG(m_squash_duration, "swatter squash-duration" );

View File

@ -215,6 +215,16 @@ private:
float m_nitro_fade_out_time;
/** Maximum nitro a kart can collect. */
float m_nitro_max;
/** Bubble gum diration. */
float m_bubblegum_time;
/** Torque to add when a bubble gum was hit in order to make the kart go
* sideways a bit. */
float m_bubblegum_torque;
/** Fraction of top speed that can be reached maximum after hitting a
* bubble gum. */
float m_bubblegum_speed_fraction;
/** How long to fade in the slowdown for a bubble gum. */
float m_bubblegum_fade_in_time;
/** Square of the maximum distance a swatter can operate. */
float m_swatter_distance2;
/** How long the swatter lasts. */
@ -568,7 +578,19 @@ public:
// ------------------------------------------------------------------------
/** Returns the maximum amount of nitro a kart can store. */
float getNitroMax () const {return m_nitro_max; }
// ------------------------------------------------------------------------
/** Returns how long a bubble gum is active. */
float getBubblegumTime() const { return m_bubblegum_time; }
// ------------------------------------------------------------------------
/** Returns the torque to add when a bubble gum was hit . */
float getBubblegumTorque() const { return m_bubblegum_torque; }
// ------------------------------------------------------------------------
/** Returns the fraction of top speed that can be reached maximum after
* hitting a bubble gum. */
float getBubblegumSpeedFraction() const {return m_bubblegum_speed_fraction;}
// ------------------------------------------------------------------------
/** Returns how long to fade in the slowdown for a bubble gum. */
float getBubblegumFadeInTime() const { return m_bubblegum_fade_in_time; }
// ------------------------------------------------------------------------
/** Returns a shift of the center of mass (lowering the center of mass
* makes the karts more stable. */

View File

@ -157,13 +157,17 @@ void MaxSpeed::SpeedIncrease::update(float dt)
* \param category The category for which the speed is increased.
* \param max_speed_fraction Fraction of top speed to allow only.
* \param fade_in_time How long till maximum speed is capped.
* \param duration How long the effect will lasts. The value of -1 (default)
* indicates that this effect stays active forever (i.e. till its
* value is changed to something else).
*/
void MaxSpeed::setSlowdown(unsigned int category, float max_speed_fraction,
float fade_in_time)
float fade_in_time, float duration)
{
assert(category>=MS_DECREASE_MIN && category <MS_DECREASE_MAX);
m_speed_decrease[category].m_max_speed_fraction = max_speed_fraction;
m_speed_decrease[category].m_fade_in_time = fade_in_time;
m_speed_decrease[category].m_duration = duration;
} // setSlowdown
// ----------------------------------------------------------------------------
@ -172,6 +176,19 @@ void MaxSpeed::setSlowdown(unsigned int category, float max_speed_fraction,
*/
void MaxSpeed::SpeedDecrease::update(float dt)
{
if(m_duration>-1.0f)
{
// It's a timed slowdown
m_duration -= dt;
if(m_duration<0)
{
m_duration = 0;
m_current_fraction = 1.0f;
m_max_speed_fraction = 1.0f;
return;
}
}
float diff = m_current_fraction - m_max_speed_fraction;
if(diff > 0)
{
@ -206,16 +223,17 @@ void MaxSpeed::update(float dt)
// First compute the minimum max-speed fraction, which
// determines the overall decrease of maximum speed.
// ---------------------------------------------------
float f = 1.0f;
float slowdown_factor = 1.0f;
for(unsigned int i=MS_DECREASE_MIN; i<MS_DECREASE_MAX; i++)
{
SpeedDecrease &slowdown = m_speed_decrease[i];
slowdown.update(dt);
f = std::min(f, slowdown.getSlowdownFraction());
slowdown_factor = std::min(slowdown_factor,
slowdown.getSlowdownFraction());
}
m_add_engine_force = 0;
m_current_max_speed = m_kart->getKartProperties()->getMaxSpeed() * f;
m_current_max_speed = m_kart->getKartProperties()->getMaxSpeed();
// Then add the speed increase from each category
// ----------------------------------------------
@ -226,6 +244,7 @@ void MaxSpeed::update(float dt)
m_current_max_speed += speedup.getSpeedIncrease();
m_add_engine_force += speedup.getEngineForce();
}
m_current_max_speed *= slowdown_factor;
// Then cap the current speed of the kart
// --------------------------------------

View File

@ -42,6 +42,7 @@ public:
enum {MS_DECREASE_MIN,
MS_DECREASE_TERRAIN = MS_DECREASE_MIN,
MS_DECREASE_AI,
MS_DECREASE_BUBBLE,
MS_DECREASE_SQUASH,
MS_DECREASE_MAX};
@ -115,6 +116,10 @@ private:
* into account. */
float m_current_fraction;
/** How long the effect should last. A -1.0f as value indicates
* that this effect stays active till it is changed back. */
float m_duration;
/** The constructor initialises the data with data that won't
* affect top speed at all. */
SpeedDecrease()
@ -122,6 +127,7 @@ private:
m_max_speed_fraction = 1.0f;
m_fade_in_time = 0.0f;
m_current_fraction = 1.0f;
m_duration = -1.0f;
} // SpeedDecrease
void update(float dt);
// --------------------------------------------------------------------
@ -150,7 +156,7 @@ public:
float engine_force, float duration,
float fade_out_time/*=1.0f*/);
void setSlowdown(unsigned int category, float max_speed_fraction,
float fade_in_time);
float fade_in_time, float duration=-1.0f);
float getSpeedIncreaseTimeLeft(unsigned int category);
void update(float dt);
void reset();