Moved wrong-way timer from kart into linear world.

This commit is contained in:
hiker
2018-03-31 00:16:47 +11:00
parent a3f68f621f
commit 7e3fc660f1
5 changed files with 18 additions and 29 deletions

View File

@@ -457,10 +457,6 @@ public:
/** Set a text that is displayed on top of a kart.
*/
virtual void setOnScreenText(const wchar_t *text) = 0;
// -------------------------------------------------------------------------
/** Counter which is used for displaying wrong way message after a delay */
virtual float getWrongwayTimer() = 0;
virtual void setWrongwayTimer(float timer) = 0;
// ------------------------------------------------------------------------
/** Returns whether this kart wins or loses. */
virtual bool getRaceResult() const = 0;

View File

@@ -141,7 +141,6 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
m_is_jumping = false;
m_min_nitro_ticks = 0;
m_fire_clicked = 0;
m_wrongway_timer = 0;
m_type = RaceManager::KT_AI;
m_view_blocked_by_plunger = 0;

View File

@@ -158,10 +158,6 @@ protected:
/** True if fire button was pushed and not released */
bool m_fire_clicked;
/** Timer which is used for displaying wrong way message after a delay */
float m_wrongway_timer;
// Bullet physics parameters
// -------------------------
btCompoundShape m_kart_chassis;
@@ -463,11 +459,6 @@ public:
/** For debugging only: check if a kart is flying. */
bool isFlying() const { return m_flying; }
// ------------------------------------------------------------------------
/** Timer which is used for displaying wrong way message after a delay */
float getWrongwayTimer() { return m_wrongway_timer; }
// ------------------------------------------------------------------------
void setWrongwayTimer(float timer) { m_wrongway_timer = timer; }
// ------------------------------------------------------------------------
/** Returns whether this kart wins or loses. */
virtual bool getRaceResult() const { return m_race_result; }
// ------------------------------------------------------------------------

View File

@@ -96,7 +96,6 @@ void LinearWorld::reset()
for(unsigned int i=0; i<kart_amount; i++)
{
m_kart_info[i].reset();
m_karts[i]->setWrongwayTimer(0);
} // next kart
// At the moment the last kart would be the one that is furthest away
@@ -867,7 +866,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
if (!m_karts[i]->getController()->isLocalPlayerController())
return;
float wrongway_timer = m_karts[i]->getWrongwayTimer();
KartInfo &ki = m_kart_info[i];
const AbstractKart *kart=m_karts[i];
// If the kart can go in more than one directions from the current track
@@ -888,39 +887,38 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
else if (angle_diff < -M_PI)
angle_diff += 2*M_PI;
// Display a warning message if the kart is going back way (unless
// the kart has already finished the race).
// Display a warning message if the kart is going back way, i.e. if angle
// is too big(unless the kart has already finished the race).
if ((angle_diff > DEGREE_TO_RAD * 120.0f ||
angle_diff < -DEGREE_TO_RAD * 120.0f) &&
kart->getVelocityLC().getY() > 0.0f &&
!kart->hasFinishedRace())
{
wrongway_timer += dt;
ki.m_wrong_way_timer += dt;
if (wrongway_timer > 2.0f)
wrongway_timer = 2.0f;
if (ki.m_wrong_way_timer> 2.0f)
ki.m_wrong_way_timer= 2.0f;
}
else
{
wrongway_timer -= dt;
ki.m_wrong_way_timer -= dt;
if (wrongway_timer < 0)
wrongway_timer = 0;
if (ki.m_wrong_way_timer < 0)
ki.m_wrong_way_timer = 0;
}
if (kart->getKartAnimation())
wrongway_timer = 0;
ki.m_wrong_way_timer = 0;
if (wrongway_timer > 1.0f)
if (ki.m_wrong_way_timer > 1.0f)
{
m_race_gui->addMessage(_("WRONG WAY!"), kart,
/* time */ -1.0f,
video::SColor(255,255,255,255),
/*important*/ true,
/*big font*/ true);
} // if angle is too big
}
m_karts[i]->setWrongwayTimer(wrongway_timer);
} // checkForWrongDirection
//-----------------------------------------------------------------------------

View File

@@ -78,17 +78,22 @@ private:
* track-length plus distance-along-track). */
float m_overall_distance;
/** Accumulates the time a kart has been driving in the wrong
* direction so that a message can be displayed. */
float m_wrong_way_timer;
/** Initialises all fields. */
KartInfo() { reset(); }
// --------------------------------------------------------------------
/** Re-initialises all data. */
void reset()
{
m_finished_laps = -1;
m_finished_laps = -1;
m_lap_start_ticks = 0;
m_ticks_at_last_lap = INT_MAX;
m_estimated_finish = -1.0f;
m_overall_distance = 0.0f;
m_wrong_way_timer = 0.0f;
} // reset
};
// ------------------------------------------------------------------------