Fix distances when off-road, keep rescue to last on-road node

This commit is contained in:
Alayan 2018-09-27 20:40:40 +02:00 committed by auriamg
parent ce4e005447
commit 02859b673e
2 changed files with 29 additions and 10 deletions

View File

@ -41,6 +41,7 @@ void TrackSector::reset()
{ {
m_current_graph_node = Graph::UNKNOWN_SECTOR; m_current_graph_node = Graph::UNKNOWN_SECTOR;
m_last_valid_graph_node = Graph::UNKNOWN_SECTOR; m_last_valid_graph_node = Graph::UNKNOWN_SECTOR;
m_estimated_valid_graph_node = Graph::UNKNOWN_SECTOR;
m_on_road = false; m_on_road = false;
m_last_triggered_checkline = -1; m_last_triggered_checkline = -1;
} // reset } // reset
@ -84,12 +85,15 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
} }
// keep the current quad as the latest valid one IF the player has one // keep the current quad as the latest valid one IF the player has one
// of the required checklines // of the required checklines AND is on road
// The on-road condition isn't required for the estimated valid node
// used for distances.
const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node); const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node);
const std::vector<int>& checkline_requirements = dn->getChecklineRequirements(); const std::vector<int>& checkline_requirements = dn->getChecklineRequirements();
if (checkline_requirements.size() == 0) if (checkline_requirements.size() == 0)
{ {
m_estimated_valid_graph_node = m_current_graph_node;
if (m_on_road) if (m_on_road)
m_last_valid_graph_node = m_current_graph_node; m_last_valid_graph_node = m_current_graph_node;
} }
@ -97,16 +101,17 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
{ {
for (unsigned int i=0; i<checkline_requirements.size(); i++) for (unsigned int i=0; i<checkline_requirements.size(); i++)
{ {
if (m_last_triggered_checkline == checkline_requirements[i]) if (m_last_triggered_checkline >= checkline_requirements[i])
{ {
//has_prerequisite = true; //has_prerequisite = true;
m_estimated_valid_graph_node = m_current_graph_node;
if (m_on_road) if (m_on_road)
m_last_valid_graph_node = m_current_graph_node; m_last_valid_graph_node = m_current_graph_node;
break; break;
} }
} }
// TODO: show a message when we detect a user cheated. // TODO: show a message when we detect a user missed a checkline.
} }
@ -120,6 +125,12 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
DriveGraph::get()->spatialToTrack(&m_latest_valid_track_coords, xyz, DriveGraph::get()->spatialToTrack(&m_latest_valid_track_coords, xyz,
m_last_valid_graph_node); m_last_valid_graph_node);
} }
if (m_estimated_valid_graph_node != Graph::UNKNOWN_SECTOR)
{
DriveGraph::get()->spatialToTrack(&m_estimated_valid_track_coords, xyz,
m_estimated_valid_graph_node);
}
} // update } // update
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -139,6 +150,7 @@ void TrackSector::rescue()
->getPredecessor(0); ->getPredecessor(0);
m_last_valid_graph_node = DriveGraph::get()->getNode(m_current_graph_node) m_last_valid_graph_node = DriveGraph::get()->getNode(m_current_graph_node)
->getPredecessor(0); ->getPredecessor(0);
m_estimated_valid_graph_node = m_current_graph_node;
} // rescue } // rescue
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -41,7 +41,10 @@ private:
/** The graph node the object is on. */ /** The graph node the object is on. */
int m_current_graph_node; int m_current_graph_node;
/** The index of the last valid graph node. */ /** The index of the estimated valid graph node. Used for distance. */
int m_estimated_valid_graph_node;
/** The index of the last valid graph node. Used for rescue */
int m_last_valid_graph_node; int m_last_valid_graph_node;
/** The coordinates of this object on the track, i.e. how far from /** The coordinates of this object on the track, i.e. how far from
@ -49,6 +52,8 @@ private:
* of the center driveline. */ * of the center driveline. */
Vec3 m_current_track_coords; Vec3 m_current_track_coords;
Vec3 m_estimated_valid_track_coords;
Vec3 m_latest_valid_track_coords; Vec3 m_latest_valid_track_coords;
/** True if the object is on the road (driveline), or not. */ /** True if the object is on the road (driveline), or not. */
@ -64,10 +69,12 @@ public:
float getRelativeDistanceToCenter() const; float getRelativeDistanceToCenter() const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns how far the the object is from the start line. */ /** Returns how far the the object is from the start line. */
float getDistanceFromStart(bool account_for_checklines) const float getDistanceFromStart(bool account_for_checklines, bool strict=false) const
{ {
if (account_for_checklines) if (account_for_checklines && strict)
return m_latest_valid_track_coords.getZ(); return m_latest_valid_track_coords.getZ();
else if (account_for_checklines)
return m_estimated_valid_track_coords.getZ();
else else
return m_current_track_coords.getZ(); return m_current_track_coords.getZ();
} }