@@ -43,7 +43,6 @@ static const int SpeedFractionSteps = 16; // acceleration is in 1/16 pixel per t
4343static const int SpeedChangeTicks = 4 ;
4444static const int MaxLookAhead = 3 ; // blocks
4545static const int BusLookAhead = 8 ; // pixels, bus tests road further ahead
46- static const float RestTurnSpeed = 1 .0f ; // degrees per second, car that turns slower is at rest
4746
4847static int WrapDirection (int direction)
4948{
@@ -279,8 +278,7 @@ static const MapBlockInfo* GetGroundBlockAt(const glm::ivec2& position, Vehicle*
279278
280279void AiTrafficDriver::Start (Vehicle* car)
281280{
282- mPosition = MetersToFixed (car->mTransform .GetPosition2 ());
283- mHeading = Convert::AngleToFix16 (-car->mTransform .mOrientation );
281+ SetPositionFromCar (car);
284282 mFrontDirection = mHeading ;
285283 mSteer = 0 ;
286284 mCompass = GetCompass (mHeading );
@@ -291,27 +289,25 @@ void AiTrafficDriver::Start(Vehicle* car)
291289 mSpeedFraction = 0 ;
292290 mSpeedTicks = 0 ;
293291 mLookAhead = 0 ;
292+ }
293+
294+ void AiTrafficDriver::SetPositionFromCar (Vehicle* car)
295+ {
296+ mPosition = MetersToFixed (car->mTransform .GetPosition2 ());
297+ mHeading = Convert::AngleToFix16 (-car->mTransform .mOrientation );
294298 mPrevPosition = mPosition ;
295299 mPrevHeading = mHeading ;
296300 mTickTime = 0 .0f ;
297- mIsStarted = true ;
298301}
299302
300303void AiTrafficDriver::UpdateFrame (Vehicle* car)
301304{
302305 // take over driving when car stops after hit
303306 if (car->IsOutOfControl ())
304307 {
305- mIsStarted = false ;
306- if ((car->GetSpeedPixels () > 0 ) || (std::fabs (car->mPhysicsBody ->GetAngularVelocity ().to_degrees ()) > RestTurnSpeed))
307- return ;
308-
309- car->SetOutOfControl (false );
310- }
311-
312- if (!mIsStarted )
313- {
314- Start (car);
308+ SetPositionFromCar (car);
309+ mSpeed = 0 ;
310+ return ;
315311 }
316312
317313 const float tickTime = 1 .0f / GTA_TICKS_PER_SECOND ;
0 commit comments