Mitigate AI-related edge cases of original fx

This commit is contained in:
auria.mg 2018-04-08 20:47:24 -04:00
parent 9250e66ff2
commit 61469a6806
8 changed files with 25 additions and 19 deletions

View File

@ -636,8 +636,8 @@ void RubberBall::updateDistanceToTarget()
const LinearWorld *world = dynamic_cast<LinearWorld*>(World::getWorld()); const LinearWorld *world = dynamic_cast<LinearWorld*>(World::getWorld());
float target_distance = float target_distance =
world->getDistanceDownTrackForKart(m_target->getWorldKartId()); world->getDistanceDownTrackForKart(m_target->getWorldKartId(), true);
float ball_distance = getDistanceFromStart(); float ball_distance = getDistanceFromStart(true);
m_distance_to_target = target_distance - ball_distance; m_distance_to_target = target_distance - ball_distance;
if(m_distance_to_target < 0) if(m_distance_to_target < 0)

View File

@ -94,7 +94,7 @@ float MainLoop::getLimitedDt()
{ {
Log::verbose("fps", "time %f distance %f dt %f fps %f", Log::verbose("fps", "time %f distance %f dt %f fps %f",
lw->getTime(), lw->getTime(),
lw->getDistanceDownTrackForKart(0), lw->getDistanceDownTrackForKart(0, true),
dt*0.001f, 1000.0f / dt); dt*0.001f, 1000.0f / dt);
} }
else else

View File

@ -108,7 +108,7 @@ void LinearWorld::reset()
for(unsigned int i=0; i<kart_amount; i++) for(unsigned int i=0; i<kart_amount; i++)
{ {
m_distance_increase = std::min(m_distance_increase, m_distance_increase = std::min(m_distance_increase,
getDistanceDownTrackForKart(i)); getDistanceDownTrackForKart(i, false));
} }
// Track length - minimum distance is how much the track length must // Track length - minimum distance is how much the track length must
// be increased to avoid negative values in estimateFinishTimeForKart // be increased to avoid negative values in estimateFinishTimeForKart
@ -190,7 +190,7 @@ void LinearWorld::update(float dt)
getTrackSector(n)->update(kart->getFrontXYZ()); getTrackSector(n)->update(kart->getFrontXYZ());
kart_info.m_overall_distance = kart_info.m_race_lap kart_info.m_overall_distance = kart_info.m_race_lap
* Track::getCurrentTrack()->getTrackLength() * Track::getCurrentTrack()->getTrackLength()
+ getDistanceDownTrackForKart(kart->getWorldKartId()); + getDistanceDownTrackForKart(kart->getWorldKartId(), true);
} // for n } // for n
// Update all positions. This must be done after _all_ karts have // Update all positions. This must be done after _all_ karts have
@ -281,7 +281,7 @@ void LinearWorld::newLap(unsigned int kart_index)
m_kart_info[kart_index].m_overall_distance = m_kart_info[kart_index].m_overall_distance =
m_kart_info[kart_index].m_race_lap m_kart_info[kart_index].m_race_lap
* Track::getCurrentTrack()->getTrackLength() * Track::getCurrentTrack()->getTrackLength()
+ getDistanceDownTrackForKart(kart->getWorldKartId()); + getDistanceDownTrackForKart(kart->getWorldKartId(), true);
} }
// Last lap message (kart_index's assert in previous block already) // Last lap message (kart_index's assert in previous block already)
if (raceHasLaps() && kart_info.m_race_lap+1 == lap_count) if (raceHasLaps() && kart_info.m_race_lap+1 == lap_count)
@ -390,9 +390,9 @@ void LinearWorld::newLap(unsigned int kart_index)
* crossing the start line.. * crossing the start line..
* \param kart_id Index of the kart. * \param kart_id Index of the kart.
*/ */
float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const float LinearWorld::getDistanceDownTrackForKart(const int kart_id, bool account_for_checklines) const
{ {
return getTrackSector(kart_id)->getDistanceFromStart(); return getTrackSector(kart_id)->getDistanceFromStart(account_for_checklines);
} // getDistanceDownTrackForKart } // getDistanceDownTrackForKart
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -114,7 +114,7 @@ public:
virtual ~LinearWorld(); virtual ~LinearWorld();
virtual void update(float delta) OVERRIDE; virtual void update(float delta) OVERRIDE;
float getDistanceDownTrackForKart(const int kart_id) const; float getDistanceDownTrackForKart(const int kart_id, bool account_for_checklines) const;
float getDistanceToCenterForKart(const int kart_id) const; float getDistanceToCenterForKart(const int kart_id) const;
float getEstimatedFinishTime(const int kart_id) const; float getEstimatedFinishTime(const int kart_id) const;
int getLapForKart(const int kart_id) const; int getLapForKart(const int kart_id) const;

View File

@ -770,7 +770,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
{ {
LinearWorld *linear_world = (LinearWorld*)(World::getWorld()); LinearWorld *linear_world = (LinearWorld*)(World::getWorld());
float distance = linear_world->getDistanceDownTrackForKart(kart_id) float distance = linear_world->getDistanceDownTrackForKart(kart_id, true)
+ Track::getCurrentTrack()->getTrackLength()*lap; + Track::getCurrentTrack()->getTrackLength()*lap;
if ((position>1) && if ((position>1) &&
(previous_distance-distance<m_dist_show_overlap) && (previous_distance-distance<m_dist_show_overlap) &&

View File

@ -69,7 +69,7 @@ bool CheckLap::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
// has check defined. // has check defined.
if(!lin_world) if(!lin_world)
return false; return false;
float current_distance = lin_world->getDistanceDownTrackForKart(kart_index); float current_distance = lin_world->getDistanceDownTrackForKart(kart_index, false);
bool result = (m_previous_distance[kart_index]>0.95f*track_length && bool result = (m_previous_distance[kart_index]>0.95f*track_length &&
current_distance<7.0f); current_distance<7.0f);

View File

@ -109,14 +109,12 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
// Now determine the 'track' coords, i.e. ow far from the start of the // Now determine the 'track' coords, i.e. ow far from the start of the
// track, and how far to the left or right of the center driveline. // track, and how far to the left or right of the center driveline.
if (isValidQuad || m_last_valid_graph_node == Graph::UNKNOWN_SECTOR) DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz,
m_current_graph_node);
if (m_last_valid_graph_node != Graph::UNKNOWN_SECTOR)
{ {
DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz, DriveGraph::get()->spatialToTrack(&m_latest_valid_track_coords, xyz,
m_current_graph_node);
}
else
{
DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz,
m_last_valid_graph_node); m_last_valid_graph_node);
} }
} // update } // update

View File

@ -48,6 +48,8 @@ private:
* of the center driveline. */ * of the center driveline. */
Vec3 m_current_track_coords; Vec3 m_current_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. */
bool m_on_road; bool m_on_road;
@ -61,7 +63,13 @@ 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() const { return m_current_track_coords.getZ();} float getDistanceFromStart(bool account_for_checklines) const
{
if (account_for_checklines)
return m_latest_valid_track_coords.getZ();
else
return m_current_track_coords.getZ();
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the distance to the centre driveline. */ /** Returns the distance to the centre driveline. */
float getDistanceToCenter() const { return m_current_track_coords.getX(); } float getDistanceToCenter() const { return m_current_track_coords.getX(); }