Move handleNitroAndZipper in handleAcceleration

This commit is contained in:
Alayan 2018-09-18 12:40:29 +02:00
parent 1f514727d5
commit ab1e86d796
2 changed files with 22 additions and 8 deletions

View File

@ -328,8 +328,6 @@ void SkiddingAI::update(int ticks)
checkCrashes(m_kart->getXYZ()); checkCrashes(m_kart->getXYZ());
determineTrackDirection(); determineTrackDirection();
int item_skill = computeSkill(ITEM_SKILL);
// Special behaviour if we have a bomb attach: try to hit the kart ahead // Special behaviour if we have a bomb attach: try to hit the kart ahead
// of us. // of us.
bool commands_set = false; bool commands_set = false;
@ -341,7 +339,7 @@ void SkiddingAI::update(int ticks)
if ( m_kart_ahead != m_kart->getAttachment()->getPreviousOwner()) if ( m_kart_ahead != m_kart->getAttachment()->getPreviousOwner())
{ {
// Use nitro if the kart is far ahead, or faster than this kart // Use nitro if the kart is far ahead, or faster than this kart
handleNitroAndZipper(item_skill); handleNitroAndZipper(50 /*don't check for safe speed */);
// If we are close enough, try to hit this kart // If we are close enough, try to hit this kart
if(m_distance_ahead<=10) if(m_distance_ahead<=10)
@ -370,9 +368,6 @@ void SkiddingAI::update(int ticks)
handleAccelerationAndBraking(ticks); handleAccelerationAndBraking(ticks);
handleSteering(dt); handleSteering(dt);
handleRescue(dt); handleRescue(dt);
// If a bomb is attached, nitro might already be set.
if(!m_controls->getNitro())
handleNitroAndZipper(item_skill);
} }
// Make sure that not all AI karts use the zipper at the same // Make sure that not all AI karts use the zipper at the same
@ -2010,6 +2005,15 @@ void SkiddingAI::handleAccelerationAndBraking(int ticks)
return; return;
} }
// Step 3 : handle nitro and zipper
// If a bomb is attached, nitro might already be set.
// FIXME : the bomb situation should be merged here
if(!m_controls->getNitro())
handleNitroAndZipper(max_turn_speed);
// Step 4 : handle plunger effect
if(m_kart->getBlockedByPlungerTicks()>0) if(m_kart->getBlockedByPlungerTicks()>0)
{ {
int item_skill = computeSkill(ITEM_SKILL); int item_skill = computeSkill(ITEM_SKILL);
@ -2172,9 +2176,10 @@ void SkiddingAI::handleRescue(const float dt)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Decides wether to use nitro and zipper or not. /** Decides wether to use nitro and zipper or not.
*/ */
void SkiddingAI::handleNitroAndZipper(int item_skill) void SkiddingAI::handleNitroAndZipper(float max_safe_speed)
{ {
int nitro_skill = computeSkill(NITRO_SKILL); int nitro_skill = computeSkill(NITRO_SKILL);
int item_skill = computeSkill(ITEM_SKILL);
//Nitro continue to be advantageous during the fadeout //Nitro continue to be advantageous during the fadeout
int nitro_ticks = m_kart->getSpeedIncreaseTicksLeft(MaxSpeed::MS_INCREASE_NITRO); int nitro_ticks = m_kart->getSpeedIncreaseTicksLeft(MaxSpeed::MS_INCREASE_NITRO);
@ -2242,6 +2247,15 @@ void SkiddingAI::handleNitroAndZipper(int item_skill)
} }
} }
// Don't use nitro or zipper if it would make the kart go too fast
if(m_kart->getSpeed() + m_kart->getKartProperties()->getNitroMaxSpeedIncrease() > max_safe_speed)
nitro_skill = 0;
// FIXME : as the zipper can give +15, but only gives +5 instant, this may be too conservative
if(m_kart->getSpeed() + m_kart->getKartProperties()->getZipperMaxSpeedIncrease() > max_safe_speed)
item_skill = 0;
// If a parachute or anvil is attached, the nitro and zipper don't give much // If a parachute or anvil is attached, the nitro and zipper don't give much
// benefit. Better wait till later. // benefit. Better wait till later.
const bool has_slowdown_attachment = const bool has_slowdown_attachment =

View File

@ -265,7 +265,7 @@ private:
const std::vector<const Item *> &items_to_avoid); const std::vector<const Item *> &items_to_avoid);
void handleRescue(const float dt); void handleRescue(const float dt);
void handleBraking(float max_turn_speed, float min_speed); void handleBraking(float max_turn_speed, float min_speed);
void handleNitroAndZipper(int item_skill); void handleNitroAndZipper(float max_safe_speed);
void computeNearestKarts(); void computeNearestKarts();
void handleItemCollectionAndAvoidance(Vec3 *aim_point, void handleItemCollectionAndAvoidance(Vec3 *aim_point,
int last_node); int last_node);