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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449

//!	Car's sound controller list. (native, do not change or extend)
enum CarSoundCtrl
{
	// simulation
	ENGINE, //!< indicates if engine is ON
	RPM,    //!< engine's RPM
	SPEED,  //!< speed of the car in km/h

	// miscellaneous
	DOORS, //!< indicates if doors are open
	PLAYER //!< indicates if driver is controlled by player
};



//!	Type of vehicle's fluid. (native, do not change or extend)
enum CarFluid
{
	FUEL,
	OIL,
	BRAKE,
	COOLANT,

	USER1, //!< reserved for user / modding support
	USER2, //!< reserved for user / modding support
	USER3, //!< reserved for user / modding support
	USER4  //!< reserved for user / modding support
};



//!	Enumerated gearbox types. (native, do not change or extend)
enum CarGearboxType
{
	MANUAL,   //!< classic manual transmission with friction plates between engine and gearbox
	AUTOMATIC //!< automatic transmission with torque converter between engine and gearbox
}



//!	Enumerated vehicle's gears. (native, do not change or extend)
enum CarGear
{
	REVERSE,
	NEUTRAL,
	FIRST,
	SECOND,
	THIRD,
	FOURTH,
	FIFTH,
	SIXTH,
	SEVENTH,
	EIGTH,
	NINTH,
	TENTH,
	ELEVENTH,
	TWELFTH,
	THIRTEENTH,
	FOURTEENTH,
	FIFTEENTH,
	SIXTEENTH
};



//!	Enumerated automatic gearbox modes. (native, do not change or extend)
enum CarAutomaticGearboxMode
{
	P, //!< park
	R, //!< reverse
	N, //!< neutral
	D  //!< drive
};



//!	Base native class for all motorized wheeled vehicles.
class Car extends Transport
{
	//!	DEPRECATED, left for backwards compatibility, the methods of this class are now directly accessible on Car itself
	proto native CarController GetController();
	
	//!	Returns the current speed of the vehicle in km/h.
	proto native float GetSpeedometer();
	
	//! Returns the current speed of the vehicle in km/h. Value is absolute
	float GetSpeedometerAbsolute()
	{
		return Math.AbsFloat(GetSpeedometer());
	}

	override bool IsAreaAtDoorFree( int currentSeat, float maxAllowedObjHeight = 0.5, float horizontalExtents = 0.5, float playerHeight = 1.7 )
	{
		vector transform[4];
		
		vector extents;
		
		extents[0] = horizontalExtents;
		extents[1] = playerHeight;
		extents[2] = horizontalExtents;

		float speed = GetSpeedometerAbsolute();
		if (speed > 8)
			extents[2] = extents[2] * 6;
		if (speed > 8)
			extents[0] = 2;
		
		return IsAreaAtDoorFree( currentSeat, maxAllowedObjHeight, extents, transform );
	}
	
	override Shape DebugFreeAreaAtDoor( int currentSeat, float maxAllowedObjHeight = 0.5, float horizontalExtents = 0.5, float playerHeight = 1.7 )
	{
		int color = ARGB(20, 0, 255, 0);
		
		vector transform[4];
		
		vector extents;
		
		extents[0] = horizontalExtents;
		extents[1] = playerHeight;
		extents[2] = horizontalExtents;

		float speed = GetSpeedometerAbsolute();
		if (speed > 8)
			extents[2] = extents[2] * 6;
		if (speed > 8)
			extents[0] = 2;
		
		if (!IsAreaAtDoorFree( currentSeat, maxAllowedObjHeight, extents, transform ))
		{
			color = ARGB(20, 255, 0, 0);
		}
		
		Shape shape = Debug.DrawBox(-extents * 0.5, extents * 0.5, color);
		shape.SetMatrix(transform);
		return shape;
	}
	
	override int GetHideIconMask()
	{
		return EInventoryIconVisibility.HIDE_VICINITY;
	}

//-----------------------------------------------------------------------------
// controls

	//!	Returns the current steering value in range <-1, 1>.
	proto native float GetSteering();
	/*!
		Sets the steering value.

		\param in     should be in range <-1, 1>
		\param analog indicates if the input value was taken from analog controller
	*/
	proto native void SetSteering( float in, bool analog = false );

	//!	Returns the current thrust turbo modifier value in range <0, 1>.
	proto native float GetThrustTurbo();
	//!	Returns the current thrust gentle modifier value in range <0, 1>.
	proto native float GetThrustGentle();
	//!	Returns the current thrust value in range <0, 1>.
	proto native float GetThrust();
	/*!
		Sets the thrust value.

		\param in     should be in range <0, 1>
		\param gentle should be in range <0, 1>, thrust modifier
		\param turbo  should be in range <0, 1>, thrust modifier
	*/
	proto native void SetThrust( float in, float gentle = 0, float turbo = 0 );

	//! Returns the current brake value in range <0, 1>.
	proto native float GetBrake();
	/*!
		Sets the brake value.

		\param in should be in range <0, 1>
		\param panic should be in range <0, 1>
	*/
	proto native void SetBrake( float in, float panic = 0, bool gentle = false );
	
	//! Returns the current handbrake value in range <0, 1>.
	proto native float GetHandbrake();
	/*!
		Sets the handbrake value.

		\param in should be in range <0, 1>
	*/
	proto native void SetHandbrake( float in );
	
	/*!
		Sets if brakes should activate without a driver present
	*/
	proto native void SetBrakesActivateWithoutDriver( bool activate = true );
	
	//! Returns the current clutch value in range <0, 1>.
	proto native float GetClutch();
	/*!
		Sets the clutch state.
	*/
	proto native void SetClutchState( bool in );

	//!	Returns index of the current gear.
	proto native int GetGear();

	proto native void ShiftUp();
	proto native void ShiftTo( CarGear gear );
	proto native void ShiftDown();

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// fluids

	/*!
		Returns tank capacity for the specified vehicle's fluid.

		\param fluid the specified fluid type
	*/
	proto native float GetFluidCapacity( CarFluid fluid );

	/*!
		Returns fraction value (in range <0, 1>)
		of the current state of the specified vehicle's fluid.

		\param[in] fluid the specified fluid type
	*/
	proto native float GetFluidFraction( CarFluid fluid );

	//! Removes from the specified fluid the specified amount.
	proto native void Leak( CarFluid fluid, float amount );

	//! Removes all the specified fluid from vehicle.
	proto native void LeakAll( CarFluid fluid );

	//! Adds to the specified fluid the specified amount.
	proto native void Fill( CarFluid fluid, float amount );

	/*!
		Is called every time when the specified vehicle's fluid level
		changes eg. when car is consuming fuel.

		\param[in] fluid fluid identifier, \see CarFluid
		\param[in] newValue new fluid level
		\param[in] oldValue previous fluid level before change
	*/
	void OnFluidChanged( CarFluid fluid, float newValue, float oldValue ) {}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// engine

	//! Returns engine's min operating rpm
	proto native float EngineGetRPMMin();
	
	//! Returns engine's idle rpm before engine stalls.
	proto native float EngineGetRPMIdle();
	
	//! Returns engine's max rpm before engine blows up.
	proto native float EngineGetRPMMax();

	//! Returns engine's maximal working rpm without damaging the engine.
	proto native float EngineGetRPMRedline();

	//! Returns engine's rpm value.
	proto native float EngineGetRPM();

	//! Returns true when engine is running, false otherwise.
	proto native bool EngineIsOn();

	//! Starts the engine.
	proto native void EngineStart();

	/*!
		Is called every time the game wants to start the engine.

		\return true if the engine can start, false otherwise.
	*/
	bool OnBeforeEngineStart()
	{
		// engine can start by default
		return true;
	}

	//! Is called every time the engine starts.
	void OnEngineStart() {}

	//! Stops the engine.
	proto native void EngineStop();

	//! Is called every time the engine stops.
	void OnEngineStop() {}

	//! Get actual position of engine (model space)
	proto native vector GetEnginePos();
	//! Override the position of engine (model space)
	proto native void SetEnginePos(vector pos);

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// gearbox

	//! Returns total number of gears.
	proto native int GetGearsCount();

	//! Returns gearbox type. See CarGearboxType enum for more info.
	proto native CarGearboxType GearboxGetType();

	//! Returns gearbox mode. This is useful when car has automatic gearbox.
	proto native CarAutomaticGearboxMode GearboxGetMode();

	/*!
		Is called every time when the simulation changed gear.

		\param[in] newGear new gear level
		\param[in] oldGear previous gear level before gear shift
	*/
	void OnGearChanged( int newGear, int oldGear )
	{
	}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// wheels

	//! Returns true if any of the wheels are locked in terms of its movement.
	proto native bool WheelIsAnyLocked();
	/*!
		Returns true if given wheel is locked in terms of its movement.

		\param[in] wheelIdx index of the wheel, they are counted from left-front to rear-right
	*/
	proto native bool WheelIsLocked( int wheelIdx );
	
	//! How many wheel can be attached to a car (hubs only)
	proto native int WheelCount();
	
	//! Number of actually attached wheels (hubs only)
	proto native int WheelCountPresent();

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// events

	/*!
		Is called every time when vehicle collides with other object.

		\param[in] zoneName configured vehicle's zone that was hit
		\param[in] localPos position where the vehicle was hit in vehicle's space
		\param[in] other object with which the vehicle is colliding
		\param[in] data contact properties
	*/
	void OnContact( string zoneName, vector localPos, IEntity other, Contact data ) {}

	/*!
		Is called every sound simulation step.
		In this callback, user can modify behaviour of sound controllers.

		\param[in] ctrl sound controller identifier, \see CarSoundCtrl
		\param[in] oldValue already computed value by the game code
		\return new value of the specified sound controller.
	*/
	float OnSound( CarSoundCtrl ctrl, float oldValue )
	{
		// just use the computed value by the game code
		return oldValue;
	}

	/*!
		Is called after every input simulation step.

		Note that the player character and other systems can always change the internal state.
		It is highly recommended to store state of custom inputs elsewhere and call Setters here.

		\param[in] dt frame time in seconds
	*/
	void OnInput( float dt ) {}

	/*!
		Is called every game frame.
		\param[in] dt frame time in seconds
	*/
	void OnUpdate( float dt ) {}
//-----------------------------------------------------------------------------


	// implemented only in internal configuration
	proto native void ForcePosition( vector pos );
	// implemented only in internal configuration
	proto native void ForceDirection( vector dir );
};



//! DEPRECATED class left for backwards compatibility, methods are available on car itself now
class CarController
{
	private void CarController() {}
	private void ~CarController() {}
	
	//!	Returns the current steering value in range <-1, 1>.
	proto float GetSteering();
	/*!
		Sets the steering value.

		\param in     should be in range <-1, 1>
		\param analog indicates if the input value was taken from analog controller
	*/
	proto void SetSteering( float in, bool analog = false );

	//!	Returns the current thrust turbo modifier value in range <0, 1>.
	proto float GetThrustTurbo();
	//!	Returns the current thrust gentle modifier value in range <0, 1>.
	proto float GetThrustGentle();
	//!	Returns the current thrust value in range <0, 1>.
	proto float GetThrust();
	/*!
		Sets the thrust value.

		\param in     should be in range <0, 1>
		\param gentle should be in range <0, 1>, thrust modifier
		\param turbo  should be in range <0, 1>, thrust modifier
	*/
	proto void SetThrust( float in, float gentle = 0, float turbo = 0 );

	//! Returns the current brake value in range <0, 1>.
	proto float GetBrake();
	/*!
		Sets the brake value.

		\param in should be in range <0, 1>
		\param panic should be in range <0, 1>
	*/
	proto void SetBrake( float in, float panic = 0 );

	//!	Returns index of the current gear.
	proto int GetGear();

	proto void ShiftUp();
	proto void ShiftTo( CarGear gear );
	proto void ShiftDown();
};