From 0765e643cf84539062726b18afc24856359a471a Mon Sep 17 00:00:00 2001 From: auria Date: Tue, 30 Sep 2008 01:54:09 +0000 Subject: [PATCH] fixed shortcut detection git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2312 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/modes/linear_world.cpp | 26 ++++++++++++-------------- src/modes/linear_world.hpp | 2 +- src/modes/world.cpp | 16 ++++++++-------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 9489651a3..f6afd2821 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -40,8 +40,8 @@ LinearWorld::LinearWorld() : World() { KartInfo info; info.m_track_sector = Track::UNKNOWN_SECTOR; + info.m_last_valid_sector = Track::UNKNOWN_SECTOR; info.m_lap_start_time = -1.0f; - info.m_shortcut_sector = Track::UNKNOWN_SECTOR; RaceManager::getTrack()->findRoadSector(m_kart[n]->getXYZ(), &info.m_track_sector); //If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of @@ -81,8 +81,8 @@ void LinearWorld::restartRace() { KartInfo& info = m_kart_info[n]; info.m_track_sector = Track::UNKNOWN_SECTOR; + info.m_last_valid_sector = Track::UNKNOWN_SECTOR; info.m_lap_start_time = -1.0f; - info.m_shortcut_sector = Track::UNKNOWN_SECTOR; RaceManager::getTrack()->findRoadSector(m_kart[n]->getXYZ(), &info.m_track_sector); //If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of @@ -129,11 +129,8 @@ void LinearWorld::update(float delta) for(unsigned int n=0; nhasFinishedRace()) updateRacePosition(kart, kart_info); + if(!m_kart[n]->hasFinishedRace()) updateRacePosition(m_kart[n], m_kart_info[n]); } for(unsigned int n=0; nisRescue() ) - { - kart_info.m_shortcut_sector = kart_info.m_track_sector; - } + // update sector variables int prev_sector = kart_info.m_track_sector; + if(!kart->isRescue()) RaceManager::getTrack()->findRoadSector( kart->getXYZ(), &kart_info.m_track_sector); // Check if the kart is taking a shortcut (if it's not already doing one): - if(!kart->isRescue() && RaceManager::getTrack()->isShortcut(prev_sector, kart_info.m_track_sector)) + if(!kart->isRescue() && kart_info.m_last_valid_sector != Track::UNKNOWN_SECTOR && + RaceManager::getTrack()->isShortcut(kart_info.m_last_valid_sector, kart_info.m_track_sector)) { forceRescue(kart, kart_info, /*is shortcut*/ true); // bring karts back to where they left the track. if(kart->isPlayerKart()) @@ -166,6 +160,9 @@ void LinearWorld::update(float delta) return; } + if(kart_info.m_track_sector != Track::UNKNOWN_SECTOR && !kart->isRescue()) kart_info.m_last_valid_sector = kart_info.m_track_sector; + + // check if kart is on the road - if not, find the closest sector if (kart_info.m_track_sector == Track::UNKNOWN_SECTOR && !kart->isRescue()) { kart_info.m_on_road = false; @@ -185,6 +182,7 @@ void LinearWorld::update(float delta) kart_info.m_on_road = true; } + // get position (progression) within track RaceManager::getTrack()->spatialToTrack( kart_info.m_curr_track_coords /* out */, kart->getXYZ(), kart_info.m_track_sector ); @@ -454,7 +452,7 @@ void LinearWorld::forceRescue(Kart* kart, KartInfo& kart_info, bool shortcut) // flag, so that this shortcut is not counted! if(shortcut) { - kart_info.m_track_sector = kart_info.m_shortcut_sector; + kart_info.m_track_sector = kart_info.m_last_valid_sector; } kart->forceRescue(); diff --git a/src/modes/linear_world.hpp b/src/modes/linear_world.hpp index 9597bf92b..beb0c3e95 100644 --- a/src/modes/linear_world.hpp +++ b/src/modes/linear_world.hpp @@ -32,9 +32,9 @@ struct KartInfo int m_race_lap; // number of finished(!) laps float m_time_at_last_lap; // time at finishing last lap float m_lap_start_time; // Time at start of a new lap - int m_shortcut_sector; // segment on which the shortcut was started int m_track_sector; // index in driveline, special values // e.g. UNKNOWN_SECTOR can be negative! + int m_last_valid_sector; Vec3 m_curr_track_coords; Vec3 m_last_track_coords; diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 1dd5ecc2c..99eb29815 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -326,21 +326,21 @@ void World::updateHighscores() for(unsigned int pos=0; posgetPosition()); } - } #endif - - // no kart claimed to be in this position - // FIXME - find why after some race resets kart positions are messed up - if(index[pos] == 999) continue; + continue; + } // Only record times for player karts if(!m_kart[index[pos]]->isPlayerKart()) continue;