Assign KartProperties to a variable instead of fetching it every time
This commit is contained in:
parent
12a1227f20
commit
dbecbc3840
@ -361,6 +361,8 @@ void SlipStream::setDebugColor(const video::SColor &color)
|
|||||||
*/
|
*/
|
||||||
void SlipStream::update(float dt)
|
void SlipStream::update(float dt)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
// Low level AIs should not do any slipstreaming.
|
// Low level AIs should not do any slipstreaming.
|
||||||
if(m_kart->getController()->disableSlipstreamBonus())
|
if(m_kart->getController()->disableSlipstreamBonus())
|
||||||
return;
|
return;
|
||||||
@ -387,7 +389,7 @@ void SlipStream::update(float dt)
|
|||||||
// not moving. This is useful for debugging the graphics of SS-ing.
|
// not moving. This is useful for debugging the graphics of SS-ing.
|
||||||
//#define DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
//#define DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
||||||
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
||||||
if(m_kart->getSpeed() < m_kart->getKartProperties()->getSlipstreamMinSpeed())
|
if(m_kart->getSpeed() < kp->getSlipstreamMinSpeed())
|
||||||
{
|
{
|
||||||
setIntensity(0, NULL);
|
setIntensity(0, NULL);
|
||||||
m_slipstream_mode = SS_NONE;
|
m_slipstream_mode = SS_NONE;
|
||||||
@ -428,8 +430,7 @@ void SlipStream::update(float dt)
|
|||||||
// entirely sure if this makes sense, but it makes it easier to
|
// entirely sure if this makes sense, but it makes it easier to
|
||||||
// give karts different slipstream properties.
|
// give karts different slipstream properties.
|
||||||
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
|
||||||
if(m_target_kart->getSpeed() <
|
if (m_target_kart->getSpeed() < kp->getSlipstreamMinSpeed())
|
||||||
m_kart->getKartProperties()->getSlipstreamMinSpeed())
|
|
||||||
{
|
{
|
||||||
if(UserConfigParams::m_slipstream_debug &&
|
if(UserConfigParams::m_slipstream_debug &&
|
||||||
m_kart->getController()->isPlayerController())
|
m_kart->getController()->isPlayerController())
|
||||||
@ -443,7 +444,7 @@ void SlipStream::update(float dt)
|
|||||||
// slipstream length+0.5*kart_length()+0.5*target_kart_length
|
// slipstream length+0.5*kart_length()+0.5*target_kart_length
|
||||||
// away from the other kart
|
// away from the other kart
|
||||||
Vec3 delta = m_kart->getXYZ() - m_target_kart->getXYZ();
|
Vec3 delta = m_kart->getXYZ() - m_target_kart->getXYZ();
|
||||||
float l = m_kart->getKartProperties()->getSlipstreamLength()
|
float l = kp->getSlipstreamLength()
|
||||||
+ 0.5f*( m_target_kart->getKartLength()
|
+ 0.5f*( m_target_kart->getKartLength()
|
||||||
+m_kart->getKartLength() );
|
+m_kart->getKartLength() );
|
||||||
if(delta.length2_2d() > l*l)
|
if(delta.length2_2d() > l*l)
|
||||||
@ -483,8 +484,7 @@ void SlipStream::update(float dt)
|
|||||||
{
|
{
|
||||||
m_slipstream_mode = SS_USE;
|
m_slipstream_mode = SS_USE;
|
||||||
m_kart->handleZipper();
|
m_kart->handleZipper();
|
||||||
m_slipstream_time =
|
m_slipstream_time = kp->getSlipstreamCollectTime();
|
||||||
m_kart->getKartProperties()->getSlipstreamCollectTime();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,7 +505,7 @@ void SlipStream::update(float dt)
|
|||||||
setIntensity(m_slipstream_time, m_target_kart);
|
setIntensity(m_slipstream_time, m_target_kart);
|
||||||
|
|
||||||
m_slipstream_mode = SS_COLLECT;
|
m_slipstream_mode = SS_COLLECT;
|
||||||
if(m_slipstream_time>m_kart->getKartProperties()->getSlipstreamCollectTime())
|
if (m_slipstream_time > kp->getSlipstreamCollectTime())
|
||||||
{
|
{
|
||||||
setIntensity(1.0f, m_target_kart);
|
setIntensity(1.0f, m_target_kart);
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,9 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scale the values so they look better
|
// Scale the values so they look better
|
||||||
|
// The scaling factor and offset were found by trial and error.
|
||||||
|
// It should look nice and you should be able to see the difference between
|
||||||
|
// different masses or velocities.
|
||||||
m_skills[SKILL_MASS]->setValue((int)
|
m_skills[SKILL_MASS]->setValue((int)
|
||||||
((props->getCombinedCharacteristic()->getMass() - 20) / 4));
|
((props->getCombinedCharacteristic()->getMass() - 20) / 4));
|
||||||
m_skills[SKILL_MASS]->setLabel(_("WEIGHT"));
|
m_skills[SKILL_MASS]->setLabel(_("WEIGHT"));
|
||||||
|
@ -225,6 +225,7 @@ void Attachment::clear()
|
|||||||
*/
|
*/
|
||||||
void Attachment::hitBanana(Item *item, int new_attachment)
|
void Attachment::hitBanana(Item *item, int new_attachment)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
const StateManager::ActivePlayer *const ap = m_kart->getController()
|
const StateManager::ActivePlayer *const ap = m_kart->getController()
|
||||||
->getPlayer();
|
->getPlayer();
|
||||||
if(ap && ap->getConstProfile()==PlayerManager::getCurrentPlayer())
|
if(ap && ap->getConstProfile()==PlayerManager::getCurrentPlayer())
|
||||||
@ -266,8 +267,7 @@ void Attachment::hitBanana(Item *item, int new_attachment)
|
|||||||
// default time. This is necessary to avoid that a kart lands on the
|
// default time. This is necessary to avoid that a kart lands on the
|
||||||
// same banana again once the explosion animation is finished, giving
|
// same banana again once the explosion animation is finished, giving
|
||||||
// the kart the same penalty twice.
|
// the kart the same penalty twice.
|
||||||
float f = std::max(item->getDisableTime(),
|
float f = std::max(item->getDisableTime(), kp->getExplosionDuration() + 2.0f);
|
||||||
m_kart->getKartProperties()->getExplosionDuration() + 2.0f);
|
|
||||||
item->setDisableTime(f);
|
item->setDisableTime(f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -295,8 +295,7 @@ void Attachment::hitBanana(Item *item, int new_attachment)
|
|||||||
switch (new_attachment)
|
switch (new_attachment)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
set(ATTACH_PARACHUTE, m_kart->getKartProperties()->
|
set(ATTACH_PARACHUTE, kp->getParachuteDuration() + leftover_time);
|
||||||
getParachuteDuration() + leftover_time);
|
|
||||||
m_initial_speed = m_kart->getSpeed();
|
m_initial_speed = m_kart->getSpeed();
|
||||||
|
|
||||||
// if going very slowly or backwards,
|
// if going very slowly or backwards,
|
||||||
@ -310,13 +309,12 @@ void Attachment::hitBanana(Item *item, int new_attachment)
|
|||||||
// sound -> playSfx ( SOUND_SHOOMF ) ;
|
// sound -> playSfx ( SOUND_SHOOMF ) ;
|
||||||
break ;
|
break ;
|
||||||
case 2:
|
case 2:
|
||||||
set(ATTACH_ANVIL, m_kart->getKartProperties()->
|
set(ATTACH_ANVIL, kp->getAnvilDuration() + leftover_time);
|
||||||
getAnvilDuration() + leftover_time);
|
|
||||||
// if ( m_kart == m_kart[0] )
|
// if ( m_kart == m_kart[0] )
|
||||||
// sound -> playSfx ( SOUND_SHOOMF ) ;
|
// sound -> playSfx ( SOUND_SHOOMF ) ;
|
||||||
// Reduce speed once (see description above), all other changes are
|
// Reduce speed once (see description above), all other changes are
|
||||||
// handled in Kart::updatePhysics
|
// handled in Kart::updatePhysics
|
||||||
m_kart->adjustSpeed(m_kart->getKartProperties()->getAnvilSpeedFactor());
|
m_kart->adjustSpeed(kp->getAnvilSpeedFactor());
|
||||||
m_kart->updateWeight();
|
m_kart->updateWeight();
|
||||||
break ;
|
break ;
|
||||||
} // switch
|
} // switch
|
||||||
@ -421,12 +419,14 @@ void Attachment::update(float dt)
|
|||||||
// This percentage is based on the ratio of
|
// This percentage is based on the ratio of
|
||||||
// initial_speed / initial_max_speed
|
// initial_speed / initial_max_speed
|
||||||
|
|
||||||
float f = m_initial_speed / m_kart->getKartProperties()->getParachuteMaxSpeed();
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
|
float f = m_initial_speed / kp->getParachuteMaxSpeed();
|
||||||
if (f > 1.0f) f = 1.0f; // cap fraction
|
if (f > 1.0f) f = 1.0f; // cap fraction
|
||||||
if (m_kart->getSpeed() <= m_initial_speed *
|
if (m_kart->getSpeed() <= m_initial_speed *
|
||||||
(m_kart->getKartProperties()->getParachuteLboundFraction() +
|
(kp->getParachuteLboundFraction() +
|
||||||
f * ( m_kart->getKartProperties()->getParachuteUboundFraction()
|
f * (kp->getParachuteUboundFraction()
|
||||||
- m_kart->getKartProperties()->getParachuteLboundFraction())))
|
- kp->getParachuteLboundFraction())))
|
||||||
{
|
{
|
||||||
m_time_left = -1;
|
m_time_left = -1;
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,8 @@ void Powerup::adjustSound()
|
|||||||
*/
|
*/
|
||||||
void Powerup::use()
|
void Powerup::use()
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_owner->getKartProperties();
|
||||||
|
|
||||||
// The player gets an achievement point for using a powerup
|
// The player gets an achievement point for using a powerup
|
||||||
StateManager::ActivePlayer * player = m_owner->getController()->getPlayer();
|
StateManager::ActivePlayer * player = m_owner->getController()->getPlayer();
|
||||||
if (m_type != PowerupManager::POWERUP_NOTHING &&
|
if (m_type != PowerupManager::POWERUP_NOTHING &&
|
||||||
@ -221,8 +223,7 @@ void Powerup::use()
|
|||||||
|
|
||||||
case PowerupManager::POWERUP_SWATTER:
|
case PowerupManager::POWERUP_SWATTER:
|
||||||
m_owner->getAttachment()
|
m_owner->getAttachment()
|
||||||
->set(Attachment::ATTACH_SWATTER,
|
->set(Attachment::ATTACH_SWATTER, kp->getSwatterDuration());
|
||||||
m_owner->getKartProperties()->getSwatterDuration());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PowerupManager::POWERUP_BUBBLEGUM:
|
case PowerupManager::POWERUP_BUBBLEGUM:
|
||||||
@ -257,12 +258,12 @@ void Powerup::use()
|
|||||||
if (m_owner->getIdent() == "nolok")
|
if (m_owner->getIdent() == "nolok")
|
||||||
{
|
{
|
||||||
m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
|
m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
|
||||||
m_owner->getKartProperties()->getBubblegumShieldDuration());
|
kp->getBubblegumShieldDuration());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
|
m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
|
||||||
m_owner->getKartProperties()->getBubblegumShieldDuration());
|
kp->getBubblegumShieldDuration());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // using a bubble gum while still having a shield
|
else // using a bubble gum while still having a shield
|
||||||
@ -270,12 +271,12 @@ void Powerup::use()
|
|||||||
if (m_owner->getIdent() == "nolok")
|
if (m_owner->getIdent() == "nolok")
|
||||||
{
|
{
|
||||||
m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
|
m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD,
|
||||||
m_owner->getKartProperties()->getBubblegumShieldDuration() + m_owner->getShieldTime());
|
kp->getBubblegumShieldDuration() + m_owner->getShieldTime());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
|
m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD,
|
||||||
m_owner->getKartProperties()->getBubblegumShieldDuration() + m_owner->getShieldTime());
|
kp->getBubblegumShieldDuration() + m_owner->getShieldTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,9 +300,9 @@ void Powerup::use()
|
|||||||
if(kart->getPosition() == 1)
|
if(kart->getPosition() == 1)
|
||||||
{
|
{
|
||||||
kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
|
kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
|
||||||
m_owner->getKartProperties()->getAnvilDuration());
|
kp->getAnvilDuration());
|
||||||
kart->updateWeight();
|
kart->updateWeight();
|
||||||
kart->adjustSpeed(m_owner->getKartProperties()->getAnvilSpeedFactor() * 0.5f);
|
kart->adjustSpeed(kp->getAnvilSpeedFactor() * 0.5f);
|
||||||
|
|
||||||
// should we position the sound at the kart that is hit,
|
// should we position the sound at the kart that is hit,
|
||||||
// or the kart "throwing" the anvil? Ideally it should be both.
|
// or the kart "throwing" the anvil? Ideally it should be both.
|
||||||
@ -336,9 +337,8 @@ void Powerup::use()
|
|||||||
}
|
}
|
||||||
if(m_owner->getPosition() > kart->getPosition())
|
if(m_owner->getPosition() > kart->getPosition())
|
||||||
{
|
{
|
||||||
kart->getAttachment()
|
kart->getAttachment()->set(Attachment::ATTACH_PARACHUTE,
|
||||||
->set(Attachment::ATTACH_PARACHUTE,
|
kp->getParachuteDurationOther());
|
||||||
m_owner->getKartProperties()->getParachuteDurationOther());
|
|
||||||
|
|
||||||
if(kart->getController()->isPlayerController())
|
if(kart->getController()->isPlayerController())
|
||||||
player_kart = kart;
|
player_kart = kart;
|
||||||
|
@ -134,6 +134,8 @@ void RubberBand::updatePosition()
|
|||||||
*/
|
*/
|
||||||
void RubberBand::update(float dt)
|
void RubberBand::update(float dt)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_owner->getKartProperties();
|
||||||
|
|
||||||
if(m_owner->isEliminated())
|
if(m_owner->isEliminated())
|
||||||
{
|
{
|
||||||
// Rubber band snaps
|
// Rubber band snaps
|
||||||
@ -149,7 +151,7 @@ void RubberBand::update(float dt)
|
|||||||
// Check for rubber band snapping
|
// Check for rubber band snapping
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
float l = (m_end_position-k).length2();
|
float l = (m_end_position-k).length2();
|
||||||
float max_len = m_owner->getKartProperties()->getPlungerBandMaxLength();
|
float max_len = kp->getPlungerBandMaxLength();
|
||||||
if(l>max_len*max_len)
|
if(l>max_len*max_len)
|
||||||
{
|
{
|
||||||
// Rubber band snaps
|
// Rubber band snaps
|
||||||
@ -162,7 +164,7 @@ void RubberBand::update(float dt)
|
|||||||
// ----------------------------
|
// ----------------------------
|
||||||
if(m_attached_state!=RB_TO_PLUNGER)
|
if(m_attached_state!=RB_TO_PLUNGER)
|
||||||
{
|
{
|
||||||
float force = m_owner->getKartProperties()->getPlungerBandForce();
|
float force = kp->getPlungerBandForce();
|
||||||
Vec3 diff = m_end_position-k;
|
Vec3 diff = m_end_position-k;
|
||||||
|
|
||||||
// detach rubber band if kart gets very close to hit point
|
// detach rubber band if kart gets very close to hit point
|
||||||
@ -178,10 +180,10 @@ void RubberBand::update(float dt)
|
|||||||
diff.normalize(); // diff can't be zero here
|
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->increaseMaxSpeed(MaxSpeed::MS_INCREASE_RUBBER,
|
||||||
m_owner->getKartProperties()->getPlungerBandSpeedIncrease(),
|
kp->getPlungerBandSpeedIncrease(),
|
||||||
/*engine_force*/ 0.0f,
|
/*engine_force*/ 0.0f,
|
||||||
/*duration*/0.1f,
|
/*duration*/0.1f,
|
||||||
m_owner->getKartProperties()->getPlungerBandFadeOutTime());
|
kp->getPlungerBandFadeOutTime());
|
||||||
if(m_attached_state==RB_TO_KART)
|
if(m_attached_state==RB_TO_KART)
|
||||||
m_hit_kart->getBody()->applyCentralForce(diff*(-force));
|
m_hit_kart->getBody()->applyCentralForce(diff*(-force));
|
||||||
}
|
}
|
||||||
|
@ -1030,6 +1030,8 @@ void SkiddingAI::evaluateItems(const Item *item, float kart_aim_angle,
|
|||||||
std::vector<const Item *> *items_to_avoid,
|
std::vector<const Item *> *items_to_avoid,
|
||||||
std::vector<const Item *> *items_to_collect)
|
std::vector<const Item *> *items_to_collect)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
// Ignore items that are currently disabled
|
// Ignore items that are currently disabled
|
||||||
if(item->getDisableTime()>0) return;
|
if(item->getDisableTime()>0) return;
|
||||||
|
|
||||||
@ -1050,18 +1052,16 @@ void SkiddingAI::evaluateItems(const Item *item, float kart_aim_angle,
|
|||||||
// Positive items: try to collect
|
// Positive items: try to collect
|
||||||
case Item::ITEM_NITRO_BIG:
|
case Item::ITEM_NITRO_BIG:
|
||||||
// Only collect nitro, if it can actually be stored.
|
// Only collect nitro, if it can actually be stored.
|
||||||
if(m_kart->getEnergy() +
|
if (m_kart->getEnergy() + kp->getNitroBigContainer()
|
||||||
m_kart->getKartProperties()->getNitroBigContainer()
|
> kp->getNitroMax())
|
||||||
> m_kart->getKartProperties()->getNitroMax())
|
|
||||||
return;
|
return;
|
||||||
// fall through: if we have enough space to store a big
|
// fall through: if we have enough space to store a big
|
||||||
// container, we can also store a small container, and
|
// container, we can also store a small container, and
|
||||||
// finally fall through to the bonus box code.
|
// finally fall through to the bonus box code.
|
||||||
case Item::ITEM_NITRO_SMALL: avoid = false;
|
case Item::ITEM_NITRO_SMALL: avoid = false;
|
||||||
// Only collect nitro, if it can actually be stored.
|
// Only collect nitro, if it can actually be stored.
|
||||||
if (m_kart->getEnergy() +
|
if (m_kart->getEnergy() + kp->getNitroSmallContainer()
|
||||||
m_kart->getKartProperties()->getNitroSmallContainer()
|
> kp->getNitroMax())
|
||||||
> m_kart->getKartProperties()->getNitroMax())
|
|
||||||
return;
|
return;
|
||||||
case Item::ITEM_BONUS_BOX:
|
case Item::ITEM_BONUS_BOX:
|
||||||
break;
|
break;
|
||||||
@ -1091,7 +1091,7 @@ void SkiddingAI::evaluateItems(const Item *item, float kart_aim_angle,
|
|||||||
// be if the kart would need to turn sharper, therefore stops
|
// be if the kart would need to turn sharper, therefore stops
|
||||||
// skidding, and will get the bonus speed.
|
// skidding, and will get the bonus speed.
|
||||||
bool high_speed = (m_kart->getCurrentMaxSpeed() >
|
bool high_speed = (m_kart->getCurrentMaxSpeed() >
|
||||||
m_kart->getKartProperties()->getEngineMaxSpeed() ) ||
|
kp->getEngineMaxSpeed() ) ||
|
||||||
m_kart->getSkidding()->getSkidBonusReady();
|
m_kart->getSkidding()->getSkidBonusReady();
|
||||||
float max_angle = high_speed
|
float max_angle = high_speed
|
||||||
? m_ai_properties->m_max_item_angle_high_speed
|
? m_ai_properties->m_max_item_angle_high_speed
|
||||||
|
@ -2137,7 +2137,7 @@ void Kart::updatePhysics(float dt)
|
|||||||
// Only apply if near ground instead of purely based on speed avoiding
|
// Only apply if near ground instead of purely based on speed avoiding
|
||||||
// the "parachute on top" look.
|
// the "parachute on top" look.
|
||||||
const Vec3 &v = m_body->getLinearVelocity();
|
const Vec3 &v = m_body->getLinearVelocity();
|
||||||
if(/*isNearGround() &&*/ v.getY() < - m_kart_properties->getSuspensionTravel() * 0.01f * 60)
|
if(/*isNearGround() &&*/ v.getY() < - m_kart_properties->getSuspensionTravel() * 60)
|
||||||
{
|
{
|
||||||
Vec3 v_clamped = v;
|
Vec3 v_clamped = v;
|
||||||
// clamp the speed to 99% of the maxium falling speed.
|
// clamp the speed to 99% of the maxium falling speed.
|
||||||
|
@ -47,7 +47,8 @@ Skidding::Skidding(Kart *kart)
|
|||||||
m_actual_curve->setVisible(false);
|
m_actual_curve->setVisible(false);
|
||||||
#endif
|
#endif
|
||||||
m_kart = kart;
|
m_kart = kart;
|
||||||
m_skid_reduce_turn_delta = m_kart->getKartProperties()->getSkidReduceTurnMax() - m_kart->getKartProperties()->getSkidReduceTurnMin();
|
m_skid_reduce_turn_delta = m_kart->getKartProperties()->getSkidReduceTurnMax()
|
||||||
|
- m_kart->getKartProperties()->getSkidReduceTurnMin();
|
||||||
reset();
|
reset();
|
||||||
} // Skidding
|
} // Skidding
|
||||||
|
|
||||||
@ -94,13 +95,15 @@ void Skidding::reset()
|
|||||||
*/
|
*/
|
||||||
void Skidding::updateSteering(float steer, float dt)
|
void Skidding::updateSteering(float steer, float dt)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
switch(m_skid_state)
|
switch(m_skid_state)
|
||||||
{
|
{
|
||||||
case SKID_SHOW_GFX_LEFT:
|
case SKID_SHOW_GFX_LEFT:
|
||||||
case SKID_SHOW_GFX_RIGHT:
|
case SKID_SHOW_GFX_RIGHT:
|
||||||
case SKID_NONE:
|
case SKID_NONE:
|
||||||
m_real_steering = steer;
|
m_real_steering = steer;
|
||||||
if (m_skid_time < m_kart->getKartProperties()->getSkidVisualTime() && m_skid_time > 0)
|
if (m_skid_time < kp->getSkidVisualTime() && m_skid_time > 0)
|
||||||
{
|
{
|
||||||
float f = m_visual_rotation - m_visual_rotation*dt/m_skid_time;
|
float f = m_visual_rotation - m_visual_rotation*dt/m_skid_time;
|
||||||
// Floating point errors when m_skid_time is very close to 0
|
// Floating point errors when m_skid_time is very close to 0
|
||||||
@ -124,27 +127,27 @@ void Skidding::updateSteering(float steer, float dt)
|
|||||||
case SKID_ACCUMULATE_RIGHT:
|
case SKID_ACCUMULATE_RIGHT:
|
||||||
{
|
{
|
||||||
float f = (1.0f+steer)*0.5f; // map [-1,1] --> [0, 1]
|
float f = (1.0f+steer)*0.5f; // map [-1,1] --> [0, 1]
|
||||||
m_real_steering = m_kart->getKartProperties()->getSkidReduceTurnMin()
|
m_real_steering = kp->getSkidReduceTurnMin()
|
||||||
+ m_skid_reduce_turn_delta * f;
|
+ m_skid_reduce_turn_delta * f;
|
||||||
if(m_skid_time < m_kart->getKartProperties()->getSkidVisualTime())
|
if(m_skid_time < kp->getSkidVisualTime())
|
||||||
m_visual_rotation = m_kart->getKartProperties()->getSkidVisual()
|
m_visual_rotation = kp->getSkidVisual()
|
||||||
* m_real_steering * m_skid_time
|
* m_real_steering * m_skid_time
|
||||||
/ m_kart->getKartProperties()->getSkidVisualTime();
|
/ kp->getSkidVisualTime();
|
||||||
else
|
else
|
||||||
m_visual_rotation = m_kart->getKartProperties()->getSkidVisual() * m_real_steering;
|
m_visual_rotation = kp->getSkidVisual() * m_real_steering;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SKID_ACCUMULATE_LEFT:
|
case SKID_ACCUMULATE_LEFT:
|
||||||
{
|
{
|
||||||
float f = (-1.0f+steer)*0.5f; // map [-1,1] --> [-1, 0]
|
float f = (-1.0f+steer)*0.5f; // map [-1,1] --> [-1, 0]
|
||||||
m_real_steering = -m_kart->getKartProperties()->getSkidReduceTurnMin()
|
m_real_steering = -kp->getSkidReduceTurnMin()
|
||||||
+ m_skid_reduce_turn_delta * f;
|
+ m_skid_reduce_turn_delta * f;
|
||||||
if(m_skid_time < m_kart->getKartProperties()->getSkidVisualTime())
|
if(m_skid_time < kp->getSkidVisualTime())
|
||||||
m_visual_rotation = m_kart->getKartProperties()->getSkidVisual()
|
m_visual_rotation = kp->getSkidVisual()
|
||||||
* m_real_steering * m_skid_time
|
* m_real_steering * m_skid_time
|
||||||
/ m_kart->getKartProperties()->getSkidVisualTime();
|
/ kp->getSkidVisualTime();
|
||||||
else
|
else
|
||||||
m_visual_rotation = m_kart->getKartProperties()->getSkidVisual() * m_real_steering;
|
m_visual_rotation = kp->getSkidVisual() * m_real_steering;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +202,8 @@ float Skidding::getSteeringWhenSkidding(float steering) const
|
|||||||
void Skidding::update(float dt, bool is_on_ground,
|
void Skidding::update(float dt, bool is_on_ground,
|
||||||
float steering, KartControl::SkidControl skidding)
|
float steering, KartControl::SkidControl skidding)
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
// If a kart animation is shown, stop all skidding bonuses.
|
// If a kart animation is shown, stop all skidding bonuses.
|
||||||
if(m_kart->getKartAnimation())
|
if(m_kart->getKartAnimation())
|
||||||
{
|
{
|
||||||
@ -213,7 +218,7 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// No skidding backwards or while stopped
|
// No skidding backwards or while stopped
|
||||||
if(m_kart->getSpeed() < m_kart->getKartProperties()->getSkidMinSpeed() &&
|
if(m_kart->getSpeed() < kp->getSkidMinSpeed() &&
|
||||||
m_skid_state != SKID_NONE && m_skid_state != SKID_BREAK)
|
m_skid_state != SKID_NONE && m_skid_state != SKID_BREAK)
|
||||||
{
|
{
|
||||||
m_skid_state = SKID_BREAK;
|
m_skid_state = SKID_BREAK;
|
||||||
@ -225,15 +230,15 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
if (is_on_ground)
|
if (is_on_ground)
|
||||||
{
|
{
|
||||||
if ((fabs(steering) > 0.001f) &&
|
if ((fabs(steering) > 0.001f) &&
|
||||||
m_kart->getSpeed() > m_kart->getKartProperties()->getSkidMinSpeed() &&
|
m_kart->getSpeed() > kp->getSkidMinSpeed() &&
|
||||||
(skidding == KartControl::SC_LEFT || skidding == KartControl::SC_RIGHT))
|
(skidding == KartControl::SC_LEFT || skidding == KartControl::SC_RIGHT))
|
||||||
{
|
{
|
||||||
m_skid_factor += m_kart->getKartProperties()->getSkidIncrease()
|
m_skid_factor += kp->getSkidIncrease()
|
||||||
* dt / m_kart->getKartProperties()->getSkidTimeTillMax();
|
* dt / kp->getSkidTimeTillMax();
|
||||||
}
|
}
|
||||||
else if (m_skid_factor > 1.0f)
|
else if (m_skid_factor > 1.0f)
|
||||||
{
|
{
|
||||||
m_skid_factor *= m_kart->getKartProperties()->getSkidDecrease();
|
m_skid_factor *= kp->getSkidDecrease();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -241,8 +246,8 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
m_skid_factor = 1.0f; // Lose any skid factor as soon as we fly
|
m_skid_factor = 1.0f; // Lose any skid factor as soon as we fly
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_skid_factor > m_kart->getKartProperties()->getSkidMax())
|
if (m_skid_factor > kp->getSkidMax())
|
||||||
m_skid_factor = m_kart->getKartProperties()->getSkidMax();
|
m_skid_factor = kp->getSkidMax();
|
||||||
else
|
else
|
||||||
if (m_skid_factor < 1.0f) m_skid_factor = 1.0f;
|
if (m_skid_factor < 1.0f) m_skid_factor = 1.0f;
|
||||||
|
|
||||||
@ -291,7 +296,7 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
// Don't allow skidding while the kart is (apparently)
|
// Don't allow skidding while the kart is (apparently)
|
||||||
// still in the air, or when the kart is too slow
|
// still in the air, or when the kart is too slow
|
||||||
if (m_remaining_jump_time > 0 ||
|
if (m_remaining_jump_time > 0 ||
|
||||||
m_kart->getSpeed() < m_kart->getKartProperties()->getSkidMinSpeed())
|
m_kart->getSpeed() < kp->getSkidMinSpeed())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_skid_state = skidding==KartControl::SC_RIGHT
|
m_skid_state = skidding==KartControl::SC_RIGHT
|
||||||
@ -303,14 +308,14 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
// Then use this speed to determine the impulse necessary to
|
// Then use this speed to determine the impulse necessary to
|
||||||
// reach this speed.
|
// reach this speed.
|
||||||
float v = World::getWorld()->getTrack()->getGravity()
|
float v = World::getWorld()->getTrack()->getGravity()
|
||||||
* 0.5f * m_kart->getKartProperties()->getSkidPhysicalJumpTime();
|
* 0.5f * kp->getSkidPhysicalJumpTime();
|
||||||
btVector3 imp(0, v / m_kart->getBody()->getInvMass(),0);
|
btVector3 imp(0, v / m_kart->getBody()->getInvMass(),0);
|
||||||
m_kart->getVehicle()->getRigidBody()->applyCentralImpulse(imp);
|
m_kart->getVehicle()->getRigidBody()->applyCentralImpulse(imp);
|
||||||
|
|
||||||
// Some karts might use a graphical-only jump. Set it up:
|
// Some karts might use a graphical-only jump. Set it up:
|
||||||
m_jump_speed = World::getWorld()->getTrack()->getGravity()
|
m_jump_speed = World::getWorld()->getTrack()->getGravity()
|
||||||
* 0.5f * m_kart->getKartProperties()->getSkidGraphicalJumpTime();
|
* 0.5f * kp->getSkidGraphicalJumpTime();
|
||||||
m_remaining_jump_time = m_kart->getKartProperties()->getSkidGraphicalJumpTime();
|
m_remaining_jump_time = kp->getSkidGraphicalJumpTime();
|
||||||
|
|
||||||
#ifdef SKID_DEBUG
|
#ifdef SKID_DEBUG
|
||||||
#define SPEED 20.0f
|
#define SPEED 20.0f
|
||||||
@ -321,13 +326,13 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
m_predicted_curve->setVisible(true);
|
m_predicted_curve->setVisible(true);
|
||||||
m_predicted_curve->setPosition(m_kart->getXYZ());
|
m_predicted_curve->setPosition(m_kart->getXYZ());
|
||||||
m_predicted_curve->setHeading(m_kart->getHeading());
|
m_predicted_curve->setHeading(m_kart->getHeading());
|
||||||
float angle = m_kart->getKartProperties()
|
float angle = kp
|
||||||
->getMaxSteerAngle(m_kart->getSpeed())
|
->getMaxSteerAngle(m_kart->getSpeed())
|
||||||
* fabsf(getSteeringFraction());
|
* fabsf(getSteeringFraction());
|
||||||
angle = m_kart->getKartProperties()
|
angle = kp
|
||||||
->getMaxSteerAngle(SPEED)
|
->getMaxSteerAngle(SPEED)
|
||||||
* fabsf(getSteeringFraction());
|
* fabsf(getSteeringFraction());
|
||||||
float r = m_kart->getKartProperties()->getWheelBase()
|
float r = kp->getWheelBase()
|
||||||
/ asin(angle)*1.0f;
|
/ asin(angle)*1.0f;
|
||||||
|
|
||||||
const int num_steps = 50;
|
const int num_steps = 50;
|
||||||
@ -338,7 +343,7 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
{
|
{
|
||||||
float real_x = m_skid_state==SKID_ACCUMULATE_LEFT ? -x : x;
|
float real_x = m_skid_state==SKID_ACCUMULATE_LEFT ? -x : x;
|
||||||
Vec3 xyz(real_x, 0.2f, sqrt(r*r-(r-x)*(r-x))*(1.0f+SPEED/150.0f)
|
Vec3 xyz(real_x, 0.2f, sqrt(r*r-(r-x)*(r-x))*(1.0f+SPEED/150.0f)
|
||||||
*(1+(angle/m_kart->getKartProperties()->getMaxSteerAngle(SPEED)-0.6f)*0.1f));
|
*(1+(angle/kp->getMaxSteerAngle(SPEED)-0.6f)*0.1f));
|
||||||
Vec3 xyz1=m_kart->getTrans()(xyz);
|
Vec3 xyz1=m_kart->getTrans()(xyz);
|
||||||
Log::debug("Skidding", "predict %f %f %f speed %f angle %f",
|
Log::debug("Skidding", "predict %f %f %f speed %f angle %f",
|
||||||
xyz1.getX(), xyz1.getY(), xyz1.getZ(),
|
xyz1.getX(), xyz1.getY(), xyz1.getZ(),
|
||||||
@ -371,7 +376,7 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
Log::debug("Skidding", "actual %f %f %f turn %f speed %f angle %f",
|
Log::debug("Skidding", "actual %f %f %f turn %f speed %f angle %f",
|
||||||
m_kart->getXYZ().getX(),m_kart->getXYZ().getY(),m_kart->getXYZ().getZ(),
|
m_kart->getXYZ().getX(),m_kart->getXYZ().getY(),m_kart->getXYZ().getZ(),
|
||||||
m_real_steering, m_kart->getSpeed(),
|
m_real_steering, m_kart->getSpeed(),
|
||||||
m_kart->getKartProperties()->getMaxSteerAngle(m_kart->getSpeed()));
|
kp->getMaxSteerAngle(m_kart->getSpeed()));
|
||||||
#endif
|
#endif
|
||||||
m_skid_time += dt;
|
m_skid_time += dt;
|
||||||
float bonus_time, bonus_speed, bonus_force;
|
float bonus_time, bonus_speed, bonus_force;
|
||||||
@ -391,11 +396,11 @@ void Skidding::update(float dt, bool is_on_ground,
|
|||||||
m_skid_state = m_skid_state == SKID_ACCUMULATE_LEFT
|
m_skid_state = m_skid_state == SKID_ACCUMULATE_LEFT
|
||||||
? SKID_SHOW_GFX_LEFT
|
? SKID_SHOW_GFX_LEFT
|
||||||
: SKID_SHOW_GFX_RIGHT;
|
: SKID_SHOW_GFX_RIGHT;
|
||||||
float t = std::min(m_skid_time, m_kart->getKartProperties()->getSkidVisualTime());
|
float t = std::min(m_skid_time, kp->getSkidVisualTime());
|
||||||
t = std::min(t, m_kart->getKartProperties()->getSkidRevertVisualTime());
|
t = std::min(t, kp->getSkidRevertVisualTime());
|
||||||
|
|
||||||
float vso = getVisualSkidRotation();
|
float vso = getVisualSkidRotation();
|
||||||
btVector3 rot(0, vso * m_kart->getKartProperties()->getSkidPostSkidRotateFactor(), 0);
|
btVector3 rot(0, vso * kp->getSkidPostSkidRotateFactor(), 0);
|
||||||
m_kart->getVehicle()->setTimedRotation(t, rot);
|
m_kart->getVehicle()->setTimedRotation(t, rot);
|
||||||
// skid_time is used to count backwards for the GFX
|
// skid_time is used to count backwards for the GFX
|
||||||
m_skid_time = t;
|
m_skid_time = t;
|
||||||
@ -455,17 +460,19 @@ unsigned int Skidding::getSkidBonus(float *bonus_time,
|
|||||||
float *bonus_speed,
|
float *bonus_speed,
|
||||||
float *bonus_force) const
|
float *bonus_force) const
|
||||||
{
|
{
|
||||||
|
const KartProperties *kp = m_kart->getKartProperties();
|
||||||
|
|
||||||
*bonus_time = 0;
|
*bonus_time = 0;
|
||||||
*bonus_speed = 0;
|
*bonus_speed = 0;
|
||||||
*bonus_force = 0;
|
*bonus_force = 0;
|
||||||
for (unsigned int i = 0; i < m_kart->getKartProperties()->getSkidBonusSpeed().size(); i++)
|
for (unsigned int i = 0; i < kp->getSkidBonusSpeed().size(); i++)
|
||||||
{
|
{
|
||||||
if (m_skid_time <= m_kart->getKartProperties()->getSkidTimeTillBonus()[i])
|
if (m_skid_time <= kp->getSkidTimeTillBonus()[i])
|
||||||
return i;
|
return i;
|
||||||
*bonus_speed = m_kart->getKartProperties()->getSkidBonusSpeed()[i];
|
*bonus_speed = kp->getSkidBonusSpeed()[i];
|
||||||
*bonus_time = m_kart->getKartProperties()->getSkidBonusTime()[i];
|
*bonus_time = kp->getSkidBonusTime()[i];
|
||||||
*bonus_force = m_kart->getKartProperties()->getSkidBonusForce()[i];
|
*bonus_force = kp->getSkidBonusForce()[i];
|
||||||
}
|
}
|
||||||
return (unsigned int) m_kart->getKartProperties()->getSkidBonusSpeed().size();
|
return (unsigned int) kp->getSkidBonusSpeed().size();
|
||||||
} // getSkidBonusForce
|
} // getSkidBonusForce
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user