From 9f61c9e6ac6b1ac5692cf6352d2ebbd47a31a686 Mon Sep 17 00:00:00 2001 From: claude-bot Date: Mon, 13 Jul 2026 12:27:07 +0000 Subject: Import Cai1Hsu/re3 @ miami (reVC / GTA:VC decompilation) Snapshot import (no upstream history) into git.ancap.in.ua/claude, per @lzcnt. Source: https://github.com/Cai1Hsu/re3 branch miami. --- src/control/AutoPilot.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/control/AutoPilot.cpp (limited to 'src/control/AutoPilot.cpp') diff --git a/src/control/AutoPilot.cpp b/src/control/AutoPilot.cpp new file mode 100644 index 0000000..d3de6ac --- /dev/null +++ b/src/control/AutoPilot.cpp @@ -0,0 +1,134 @@ +#include "common.h" + +#include "AutoPilot.h" + +#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]; + float currentPathLinkForwardX = m_nCurrentDirection * ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo].GetDirX(); + float currentPathLinkForwardY = m_nCurrentDirection * ThePaths.m_carPathLinks[m_nCurrentPathNodeInfo].GetDirY(); + float nextPathLinkForwardX = m_nNextDirection * ThePaths.m_carPathLinks[m_nNextPathNodeInfo].GetDirX(); + float nextPathLinkForwardY = m_nNextDirection * ThePaths.m_carPathLinks[m_nNextPathNodeInfo].GetDirY(); + CVector positionOnCurrentLinkIncludingLane( + pCurrentLink->GetX() + ((m_nCurrentLane + 0.5f) * LANE_WIDTH) * currentPathLinkForwardY, + pCurrentLink->GetY() - ((m_nCurrentLane + 0.5f) * LANE_WIDTH) * currentPathLinkForwardX, + 0.0f); + CVector positionOnNextLinkIncludingLane( + pNextLink->GetX() + ((m_nNextLane + 0.5f) * LANE_WIDTH) * nextPathLinkForwardY, + pNextLink->GetY() - ((m_nNextLane + 0.5f) * LANE_WIDTH) * nextPathLinkForwardX, + 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 + m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nTimeToSpendOnCurrentCurve; +#endif +} + +void CAutoPilot::RemoveOnePathNode() +{ + --m_nPathFindNodesCount; + for (int i = 0; i < m_nPathFindNodesCount; i++) + m_aPathFindNodesInfo[i] = m_aPathFindNodesInfo[i + 1]; +} + +#ifdef COMPATIBLE_SAVES +void CAutoPilot::Save(uint8*& buf) +{ + WriteSaveBuf(buf, m_nCurrentRouteNode); + WriteSaveBuf(buf, m_nNextRouteNode); + WriteSaveBuf(buf, m_nPrevRouteNode); + WriteSaveBuf(buf, m_nTimeEnteredCurve); + WriteSaveBuf(buf, m_nTimeToSpendOnCurrentCurve); + WriteSaveBuf(buf, m_nCurrentPathNodeInfo); + WriteSaveBuf(buf, m_nNextPathNodeInfo); + WriteSaveBuf(buf, m_nPreviousPathNodeInfo); + WriteSaveBuf(buf, m_nAntiReverseTimer); + WriteSaveBuf(buf, m_nTimeToStartMission); + WriteSaveBuf(buf, m_nPreviousDirection); + WriteSaveBuf(buf, m_nCurrentDirection); + WriteSaveBuf(buf, m_nNextDirection); + WriteSaveBuf(buf, m_nCurrentLane); + WriteSaveBuf(buf, m_nNextLane); + WriteSaveBuf(buf, m_nDrivingStyle); + WriteSaveBuf(buf, m_nCarMission); + WriteSaveBuf(buf, m_nTempAction); + WriteSaveBuf(buf, m_nTimeTempAction); + WriteSaveBuf(buf, m_fMaxTrafficSpeed); + WriteSaveBuf(buf, m_nCruiseSpeed); + WriteSaveBuf(buf, m_nCruiseSpeedMultiplierType); + SkipSaveBuf(buf, 2); + WriteSaveBuf(buf, m_fCruiseSpeedMultiplier); + uint8 flags = 0; + if (m_bSlowedDownBecauseOfCars) flags |= BIT(0); + if (m_bSlowedDownBecauseOfPeds) flags |= BIT(1); + if (m_bStayInCurrentLevel) flags |= BIT(2); + if (m_bStayInFastLane) flags |= BIT(3); + if (m_bIgnorePathfinding) flags |= BIT(4); + WriteSaveBuf(buf, flags); + WriteSaveBuf(buf, m_nSwitchDistance); + SkipSaveBuf(buf, 2); + WriteSaveBuf(buf, m_vecDestinationCoors.x); + WriteSaveBuf(buf, m_vecDestinationCoors.y); + WriteSaveBuf(buf, m_vecDestinationCoors.z); + SkipSaveBuf(buf, 32); + WriteSaveBuf(buf, m_nPathFindNodesCount); + SkipSaveBuf(buf, 6); +} + +void CAutoPilot::Load(uint8*& buf) +{ + m_nCurrentRouteNode = ReadSaveBuf(buf); + m_nNextRouteNode = ReadSaveBuf(buf); + m_nPrevRouteNode = ReadSaveBuf(buf); + m_nTimeEnteredCurve = ReadSaveBuf(buf); + m_nTimeToSpendOnCurrentCurve = ReadSaveBuf(buf); + m_nCurrentPathNodeInfo = ReadSaveBuf(buf); + m_nNextPathNodeInfo = ReadSaveBuf(buf); + m_nPreviousPathNodeInfo = ReadSaveBuf(buf); + m_nAntiReverseTimer = ReadSaveBuf(buf); + m_nTimeToStartMission = ReadSaveBuf(buf); + m_nPreviousDirection = ReadSaveBuf(buf); + m_nCurrentDirection = ReadSaveBuf(buf); + m_nNextDirection = ReadSaveBuf(buf); + m_nCurrentLane = ReadSaveBuf(buf); + m_nNextLane = ReadSaveBuf(buf); + m_nDrivingStyle = ReadSaveBuf(buf); + m_nCarMission = ReadSaveBuf(buf); + m_nTempAction = ReadSaveBuf(buf); + m_nTimeTempAction = ReadSaveBuf(buf); + m_fMaxTrafficSpeed = ReadSaveBuf(buf); + m_nCruiseSpeed = ReadSaveBuf(buf); + m_nCruiseSpeedMultiplierType = ReadSaveBuf(buf); + SkipSaveBuf(buf, 2); + m_fCruiseSpeedMultiplier = ReadSaveBuf(buf); + uint8 flags = ReadSaveBuf(buf); + m_bSlowedDownBecauseOfCars = !!(flags & BIT(0)); + m_bSlowedDownBecauseOfPeds = !!(flags & BIT(1)); + m_bStayInCurrentLevel = !!(flags & BIT(2)); + m_bStayInFastLane = !!(flags & BIT(3)); + m_bIgnorePathfinding = !!(flags & BIT(4)); + m_nSwitchDistance = ReadSaveBuf(buf); + SkipSaveBuf(buf, 2); + m_vecDestinationCoors.x = ReadSaveBuf(buf); + m_vecDestinationCoors.y = ReadSaveBuf(buf); + m_vecDestinationCoors.z = ReadSaveBuf(buf); + SkipSaveBuf(buf, 32); + m_nPathFindNodesCount = ReadSaveBuf(buf); + SkipSaveBuf(buf, 6); +} +#endif \ No newline at end of file -- cgit v1.2.3