Responsible for damaging the car according to contact events from OnContact.
1280 {
1281 int contactZonesCount = m_ContactCache.Count();
1282
1283 if (contactZonesCount == 0)
1284 return;
1285
1286 for (int i = 0; i < contactZonesCount; ++i)
1287 {
1288 string zoneName = m_ContactCache.GetKey(i);
1289 array<ref VehicleContactData> data = m_ContactCache[zoneName];
1290
1291 float dmg = Math.AbsInt(data[0].m_Impulse * m_dmgContactCoef);
1292 float crewDmgBase = Math.AbsInt((data[0].m_Impulse /
dBodyGetMass(
this)) * 1000 * m_dmgContactCoef);
1293
1294 #ifdef DIAG_DEVELOPER
1295 CrashDebugData.m_CrashDataPoint = new CrashDebugData();
1296 CrashDebugData.m_CrashDataPoint.m_VehicleType =
GetDisplayName();
1297 CrashDebugData.m_CrashDataPoint.m_Damage = dmg;
1298 CrashDebugData.m_CrashDataPoint.m_Zone = zoneName;
1299 CrashDebugData.m_CrashDataPoint.m_MomentumCurr = GetMomentum();
1300 CrashDebugData.m_CrashDataPoint.m_MomentumPrev = m_MomentumPrevTick;
1301 CrashDebugData.m_CrashDataPoint.m_MomentumDelta = data[0].m_Impulse;
1302 CrashDebugData.m_CrashDataPoint.m_SpeedWorld =
GetVelocity(
this).
Length() * 3.6;
1303 CrashDebugData.m_CrashDataPoint.m_SpeedWorldPrev = m_VelocityPrevTick.Length() * 3.6;
1304 CrashDebugData.m_CrashDataPoint.m_SpeedWorldDelta = (m_VelocityPrevTick.Length() -
GetVelocity(
this).Length()) * 3.6;
1305 CrashDebugData.m_CrashDataPoint.m_VelocityCur =
GetVelocity(
this);
1306 CrashDebugData.m_CrashDataPoint.m_VelocityPrev = m_VelocityPrevTick;
1307 CrashDebugData.m_CrashDataPoint.m_VelocityDot = vector.Dot(m_VelocityPrevTick.Normalized(),
GetVelocity(
this).Normalized());
1308 CrashDebugData.m_CrashDataPoint.m_Time =
g_Game.GetTime();
1309
1310 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_CONSIDERED)
1311 {
1312 Debug.Log(
"--------------------------------------------------");
1314 Debug.Log(
"DMG: " + dmg);
1315 Debug.Log(
"zoneName : "+ zoneName);
1316 Debug.Log(
"momentumCurr : "+ GetMomentum());
1317 Debug.Log(
"momentumPrev : "+ m_MomentumPrevTick);
1318 Debug.Log(
"momentumDelta : "+ data[0].m_Impulse);
1320 Debug.Log(
"speedPrev(km/h): "+ m_VelocityPrevTick.Length() * 3.6);
1321 Debug.Log(
"speedDelta(km/h) : "+ (m_VelocityPrevTick.Length() -
GetVelocity(
this).Length()) * 3.6);
1323 Debug.Log(
"velocityPrev.): "+ m_VelocityPrevTick);
1324 Debug.Log(
"velocityDot): "+ vector.Dot(m_VelocityPrevTick.Normalized(),
GetVelocity(
this).Normalized()));
1325 Debug.Log(
"g_Game.GetTime(): "+
g_Game.GetTime());
1326 Debug.Log(
"--------------------------------------------------");
1327 }
1328 #endif
1329 if ( dmg < GameConstants.CARS_CONTACT_DMG_MIN )
1330 continue;
1331
1332 int pddfFlags;
1333 #ifdef DIAG_DEVELOPER
1334 CrashDebugData.m_CrashData.Insert(CrashDebugData.m_CrashDataPoint);
1335 CrashDebugData.m_CrashDataPoint.m_Speedometer =
GetSpeedometer();
1336
1337 #endif
1338 if (dmg < GameConstants.CARS_CONTACT_DMG_THRESHOLD)
1339 {
1340 #ifdef DIAG_DEVELOPER
1341 CrashDebugData.m_CrashDataPoint.m_DamageType = "Small";
1342 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1343 Debug.Log(
string.Format(
"[Vehiles:Damage]:: DMG %1 to the %2 zone is SMALL (threshold: %3), SPEEDOMETER: %4, TIME: %5", dmg, zoneName, GameConstants.CARS_CONTACT_DMG_MIN,
GetSpeedometer(),
g_Game.GetTime() ));
1344 #endif
1345 SynchCrashLightSound(true);
1347 }
1348 else
1349 {
1350 #ifdef DIAG_DEVELOPER
1351 CrashDebugData.m_CrashDataPoint.m_DamageType = "Big";
1352 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1353 Debug.Log(
string.Format(
"[Vehiles:Damage]:: DMG %1 to the %2 zone is BIG (threshold: %3), SPEED: %4, TIME: %5", dmg, zoneName, GameConstants.CARS_CONTACT_DMG_THRESHOLD,
GetSpeedometer(),
g_Game.GetTime() ));
1354 #endif
1356 SynchCrashHeavySound(true);
1357 pddfFlags = 0;
1358 }
1359
1360 #ifdef DEVELOPER
1361 m_DebugContactDamageMessage += string.Format("%1: %2\n", zoneName, dmg);
1362 #endif
1363
1364 ProcessDirectDamage(
DamageType.CUSTOM, null, zoneName,
"EnviroDmg",
"0 0 0", dmg, pddfFlags);
1365 }
1366
1369
1370 m_ContactCache.Clear();
1371 }
DamageType
exposed from C++ (do not change)
static string GetDisplayName(int liquid_type)
float GetSpeedometer()
Returns the current speed of the vehicle in km/h.
void UpdateHeadlightState()
void DamageCrew(float dmg)
Responsible for damaging crew in a car crash.
override void UpdateLights(int new_gear=-1)
proto native float Length()
Returns length of vector (magnitude)
proto native vector GetVelocity(notnull IEntity ent)
Returns linear velocity.
proto native float dBodyGetMass(notnull IEntity ent)