2019-08-11 19:11:54 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-08-11 19:11:54 +02:00
|
|
|
#include "AutoPilot.h"
|
|
|
|
|
2019-09-15 12:29:38 +02:00
|
|
|
#include "CarCtrl.h"
|
|
|
|
#include "Curves.h"
|
|
|
|
#include "PathFind.h"
|
|
|
|
|
|
|
|
void CAutoPilot::ModifySpeed(float speed)
|
|
|
|
{
|
|
|
|
m_fMaxTrafficSpeed = max(0.01f, speed);
|
|
|
|
float positionBetweenNodes = (float)(CTimer::GetTimeInMilliseconds() - m_nTimeEnteredCurve) / m_nTimeToSpendOnCurrentCurve;
|
|
|
|
CCarPathLink* pCurrentLink = &ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo];
|
|
|
|
CCarPathLink* pNextLink = &ThePaths.m_carPathLinks[m_nNextPathNodeInfo];
|
2020-04-10 18:36:39 +02:00
|
|
|
float currentPathLinkForwardX = m_nCurrentDirection * ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo].dir.x;
|
|
|
|
float currentPathLinkForwardY = m_nCurrentDirection * ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo].dir.y;
|
|
|
|
float nextPathLinkForwardX = m_nNextDirection * ThePaths.m_carPathLinks[m_nNextPathNodeInfo].dir.x;
|
|
|
|
float nextPathLinkForwardY = m_nNextDirection * ThePaths.m_carPathLinks[m_nNextPathNodeInfo].dir.y;
|
2019-09-15 12:29:38 +02:00
|
|
|
CVector positionOnCurrentLinkIncludingLane(
|
2020-04-10 18:36:39 +02:00
|
|
|
pCurrentLink->pos.x + ((m_nCurrentLane + 0.5f) * LANE_WIDTH) * currentPathLinkForwardY,
|
|
|
|
pCurrentLink->pos.y - ((m_nCurrentLane + 0.5f) * LANE_WIDTH) * currentPathLinkForwardX,
|
2019-09-15 12:29:38 +02:00
|
|
|
0.0f);
|
|
|
|
CVector positionOnNextLinkIncludingLane(
|
2020-04-10 18:36:39 +02:00
|
|
|
pNextLink->pos.x + ((m_nNextLane + 0.5f) * LANE_WIDTH) * nextPathLinkForwardY,
|
|
|
|
pNextLink->pos.y - ((m_nNextLane + 0.5f) * LANE_WIDTH) * nextPathLinkForwardX,
|
2019-09-15 12:29:38 +02:00
|
|
|
0.0f);
|
|
|
|
m_nTimeToSpendOnCurrentCurve = CCurves::CalcSpeedScaleFactor(
|
|
|
|
&positionOnCurrentLinkIncludingLane,
|
|
|
|
&positionOnNextLinkIncludingLane,
|
|
|
|
currentPathLinkForwardX, currentPathLinkForwardY,
|
|
|
|
nextPathLinkForwardX, nextPathLinkForwardY
|
|
|
|
) * (1000.0f / m_fMaxTrafficSpeed);
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
/* Casting timer to float is very unwanted, and in this case even causes crashes. */
|
|
|
|
m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() -
|
|
|
|
(uint32)(positionBetweenNodes * m_nTimeToSpendOnCurrentCurve);
|
|
|
|
#else
|
2020-04-15 07:03:53 +02:00
|
|
|
m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nTimeToSpendOnCurrentCurve;
|
2019-09-15 12:29:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAutoPilot::RemoveOnePathNode()
|
|
|
|
{
|
|
|
|
--m_nPathFindNodesCount;
|
|
|
|
for (int i = 0; i < m_nPathFindNodesCount; i++)
|
|
|
|
m_aPathFindNodesInfo[i] = m_aPathFindNodesInfo[i + 1];
|
|
|
|
}
|