Fix rescue code in tutorial mode, fixes #2279
This commit is contained in:
parent
bc67f4f503
commit
6529381acd
@ -26,3 +26,29 @@ TutorialWorld::TutorialWorld()
|
||||
{
|
||||
m_stop_music_when_dialog_open = false;
|
||||
} // TutorialWorld
|
||||
|
||||
unsigned int TutorialWorld::getRescuePositionIndex(AbstractKart *kart)
|
||||
{
|
||||
const int start_spots_amount = getTrack()->getNumberOfStartPositions();
|
||||
assert(start_spots_amount > 0);
|
||||
|
||||
float closest_distance = 999999.0f;
|
||||
int closest_id_found = 0;
|
||||
|
||||
Vec3 kart_pos = kart->getFrontXYZ();
|
||||
|
||||
for (int n = 0; n<start_spots_amount; n++)
|
||||
{
|
||||
const btTransform &s = getStartTransform(n);
|
||||
const Vec3 &v = s.getOrigin();
|
||||
float distance = (v - kart_pos).length2_2d();
|
||||
|
||||
if (n == 0 || distance < closest_distance)
|
||||
{
|
||||
closest_id_found = n;
|
||||
closest_distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closest_id_found;
|
||||
}
|
||||
|
@ -35,12 +35,7 @@ public:
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Determines the rescue position index of the specified kart. */
|
||||
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
|
||||
{
|
||||
// Don't use LinearWorld's function, but WorldWithRank, since the
|
||||
// latter is based on rescuing to start positions
|
||||
return WorldWithRank::getRescuePositionIndex(kart);
|
||||
}
|
||||
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the bullet transformation for the specified rescue index. */
|
||||
virtual btTransform getRescueTransform(unsigned int index) const OVERRIDE
|
||||
@ -50,6 +45,8 @@ public:
|
||||
return WorldWithRank::getRescueTransform(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}; // class TutorialWorld
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user