1042 {
1043 super.OnInput(dt);
1044
1045#ifdef DIAG_DEVELOPER
1046 if (m_eDebugMode == ECarDebugMode.NONE)
1047 return;
1048
1051 {
1053 {
1056 }
1058 {
1060 }
1061
1062 return;
1063 }
1064
1066
1067 float longitudinalWanted = 0.0;
1068 float throttleWanted = 0.0;
1069 float steeringWanted = 0.0;
1070
1071 bool attemptSpeed = false;
1072 float speedWanted = 0;
1073
1074 string text = "";
1075
1076 switch (m_eDebugMode)
1077 {
1078 case ECarDebugMode.FORWARD_10:
1079 attemptSpeed = true;
1080 speedWanted = 3;
1081 break;
1082 case ECarDebugMode.FORWARD_50:
1083 attemptSpeed = true;
1084 speedWanted = 50;
1085 break;
1086 case ECarDebugMode.RANDOM_DRIVING:
1087 attemptSpeed = true;
1088
1089 m_DebugParams.param1 -= dt;
1090 if (m_DebugParams.param1 <= 0)
1091 {
1092 m_DebugParams.param1 = Math.RandomFloatInclusive(0.01, 1.0);
1093
1094 speedWanted = speedWanted + Math.RandomFloatInclusive(-25, 25);
1095
1096 speedWanted = Math.Clamp(speedWanted, -20, 100);
1097
1098 steeringWanted = Math.RandomFloatInclusive(-1, 1);
1099
1100 float steeringWantedSign = (steeringWanted > 0) - (steeringWanted < 0);
1101 steeringWanted = steeringWantedSign * Math.Pow(Math.AbsFloat(steeringWanted), 0.5);
1102
1103 if (Math.AbsFloat(speedWanted - currentSpeed) > 15)
1104 {
1105 steeringWanted *= 0.1;
1106 }
1107
1108 m_DebugParams.param2 = steeringWanted;
1109 m_DebugParams.param3 = speedWanted;
1110 }
1111
1112 steeringWanted = m_DebugParams.param2;
1113 speedWanted = m_DebugParams.param3;
1114
1115 text += "\nTarget Steering: " + steeringWanted;
1116 text += "\nTarget Speed: " + speedWanted;
1117 text += "\nCurrent Speed: " + currentSpeed;
1118
1119 break;
1120 case ECarDebugMode.PREDEFINED_PATH:
1121 attemptSpeed = true;
1122 speedWanted = 50;
1123 break;
1124 }
1125
1126 if (!
GetGame().IsDedicatedServer())
1127 {
1128 vector transform[4];
1129 GetTransform(transform);
1131 }
1132
1133 if (attemptSpeed)
1134 {
1135 longitudinalWanted = speedWanted - currentSpeed;
1136
1137 if (speedWanted > 0.1 && currentSpeed > 0.1)
1138 {
1139 longitudinalWanted = Math.Max(longitudinalWanted, 0.1);
1140 }
1141 else if (speedWanted < 0.1 && currentSpeed < 0.1)
1142 {
1143 longitudinalWanted = Math.Min(longitudinalWanted, -0.1);
1144 }
1145 }
1146
1149 hillFactor += 1.0;
1150 hillFactor = Math.Clamp(hillFactor, 0.5, 5.0);
1151
1154 throttleWanted = 1.0 - throttleWanted;
1155 throttleWanted *= Math.AbsFloat(longitudinalWanted);
1156 throttleWanted *= hillFactor;
1157 throttleWanted = Math.Clamp(throttleWanted, 0.0, 1.0);
1158
1160 bool isReverse =
GetGear() == CarGear.REVERSE;
1161
1162 if (isManual)
1163 {
1164 float thrustWantedAbs = Math.AbsFloat(throttleWanted);
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1186 {
1187 if (thrustWantedAbs > 0.1)
1188 {
1190 }
1191 }
1192 else if (
GetGear() > CarGear.FIRST && thrustWantedAbs < 0.1)
1193 {
1195 }
1196 else if (
GetGear() < CarGear.FIRST || (throttleWanted > 0.0 && Math.AbsFloat(currentSpeed) < 5.0))
1197 {
1199 }
1200 }
1201
1206 SetBrakesActivateWithoutDriver(false);
1207#endif
1208 }
CarGearboxType
Enumerated gearbox types. (native, do not change or extend)
proto native void ShiftTo(int gear)
Shifts the future gear to selected gear, triggering gearbox simulation.
proto native void SetThrottle(float value)
Sets the future throttle value.
proto native float EngineGetRPMRedline()
Returns engine's maximal working rpm without damaging the engine.
proto native void SetHandbrake(float value)
Sets the future front brake value.
proto native CarGearboxType GearboxGetType()
Returns gearbox type. See CarGearboxType enum for more info.
proto native void EngineStop()
Stops the engine.
proto native void SetBrake(float value)
Sets the future rear brake value.
proto native bool EngineIsOn()
Returns true when engine is running, false otherwise.
proto native float EngineGetRPMIdle()
Returns engine's idle rpm before engine stalls.
proto native void ShiftDown()
Shifts the future gear down, triggering gearbox simulation.
proto native void ShiftUp()
Shifts the future gear up, triggering gearbox simulation.
proto native void EngineStart()
Starts the engine.
proto native float EngineGetRPM()
Returns engine's rpm value.
float GetSpeedometer()
Returns the current speed of the vehicle in km/h.
proto native float EngineGetRPMMin()
Returns engine's min operating rpm.
proto native void SetSteering(float value)
Sets the future steering value.
proto native int GetGear()
Returns the index of the future gear, -1 if there is no engine.