DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
CarScript.c
Go to the documentation of this file.
2{
7
8enum CarHeadlightBulbsState
9{
13 BOTH
14}
15
16enum CarRearLightType
17{
18 NONE,
21 BRAKES_AND_REVERSE
22}
23
24enum CarEngineSoundState
25{
26 NONE,
33 STOP_NO_FUEL
34}
35
36enum ECarHornState
37{
38 OFF = 0,
39 SHORT = 1,
40 LONG = 2
41}
42#ifdef DIAG_DEVELOPER
43enum EVehicleDebugOutputType
44{
45 NONE,
46 DAMAGE_APPLIED = 1,
47 DAMAGE_CONSIDERED = 2,
48 CONTACT = 4
49 //OTHER = 8
50 //OTHER = 16
51}
52
53class CrashDebugData
54{
55 static ref array<ref CrashDebugData> m_CrashData = new array<ref CrashDebugData>;
56 static ref CrashDebugData m_CrashDataPoint;
57 //data is recorded on server, upon request, sent to the client
58 static void SendData(PlayerBase player)
59 {
60 /*
61 m_CrashData.Clear();
62 CrashDebugData fakeData = new CrashDebugData();
63 fakeData.m_VehicleType = "FakeVehicle";
64 m_CrashData.Insert(fakeData);
65 */
66 GetGame().RPCSingleParam(player, ERPCs.DIAG_VEHICLES_DUMP_CRASH_DATA_CONTENTS, new Param1<array<ref CrashDebugData>>(m_CrashData), true, player.GetIdentity());
67 }
68
69 //this is client requesting to dump the data it previously received from the server
70 static void DumpDataArray(array<ref CrashDebugData> dataArray)
71 {
72 Print("Vehicle; DamageType; Damage; Zone; Momentum; Momentum Prev; Momentum Delta; Speedometer; SpeedWorld; SpeedWorld Prev; SpeedWorld Delta; Velocity; Velocity Prev; Velocity Dot; TimeStamp (ms); CrewDamageBase; ShockTemp; DMGHealth; DMGShock");
73 foreach (CrashDebugData data:dataArray)
74 {
75 DumpData(data);
76 }
77 }
78
79 static void DumpData(CrashDebugData data)
80 {
81 string output = data.m_VehicleType+";"+data.m_DamageType+";"+data.m_Damage+";"+data.m_Zone+";"+data.m_MomentumCurr+";"+data.m_MomentumPrev+";"+data.m_MomentumDelta+";"+data.m_Speedometer;
82 output += ";"+data.m_SpeedWorld+";"+data.m_SpeedWorldPrev+";"+data.m_SpeedWorldDelta+";"+data.m_VelocityCur;
83 output += ";"+data.m_VelocityPrev+";"+data.m_VelocityDot+";"+data.m_Time+";"+data.m_CrewDamageBase+";"+data.m_ShockTemp+";"+data.m_DMGHealth+";"+data.m_DMGShock;
84 Print(output);
85 }
86
87 string m_VehicleType;
88 string m_DamageType;
89 float m_Damage;
90 string m_Zone;
91 float m_MomentumCurr;
92 float m_MomentumPrev;
93 float m_MomentumDelta;
94 float m_Speedometer;
95 float m_SpeedWorld;
96 float m_SpeedWorldPrev;
97 float m_SpeedWorldDelta;
98 vector m_VelocityCur;
99 vector m_VelocityPrev;
100 float m_VelocityDot;
101 float m_Time;
102 float m_CrewDamageBase;
103 float m_ShockTemp;
104 float m_DMGHealth;
105 float m_DMGShock;
106}
107
108#endif
109class CarContactData
110{
111 vector localPos;
112 IEntity other;
113 float impulse;
114
115 void CarContactData(vector _localPos, IEntity _other, float _impulse)
116 {
117 localPos = _localPos;
118 other = _other;
119 impulse = _impulse;
120 }
121}
122
124
125#ifdef DEVELOPER
126CarScript _car;
127#endif
128
132class CarScript extends Car
133{
134 #ifdef DIAG_DEVELOPER
135 static EVehicleDebugOutputType DEBUG_OUTPUT_TYPE;
136 bool m_ContactCalled;
137 #endif
141 protected float m_MomentumPrevTick;
143 ref CarContactCache m_ContactCache;
144
145 protected float m_Time;
146
147 static float DROWN_ENGINE_THRESHOLD = 0.5;
148 static float DROWN_ENGINE_DAMAGE = 350.0;
149
150 static const string MEMORY_POINT_NAME_CAR_HORN = "pos_carHorn";
151
153 protected float m_FuelAmmount;
154 protected float m_CoolantAmmount;
155 protected float m_OilAmmount;
156 protected float m_BrakeAmmount;
157
159 //protected float m_dmgContactCoef = 0.023;
160 protected float m_dmgContactCoef = 0.058;
162
164 protected float m_DrownTime;
166
168 protected float m_EngineHealth;
169 protected float m_RadiatorHealth;
170 protected float m_FuelTankHealth;
171 protected float m_BatteryHealth;
172 protected float m_PlugHealth;
173
175
176 protected float m_BatteryConsume = 15; //Battery energy consumption upon engine start
177 protected float m_BatteryContinuousConsume = 0.25; //Battery consumption with lights on and engine is off
178 protected float m_BatteryRecharge = 0.15; //Battery recharge rate when engine is on
179 private float m_BatteryTimer = 0; //Used to factor energy consumption / recharging
180 private const float BATTERY_UPDATE_DELAY = 100;
181 protected float m_BatteryEnergyStartMin = 5.0; // Minimal energy level of battery required for start
182
187
188 protected int m_enginePtcFx;
189 protected int m_coolantPtcFx;
190 protected int m_exhaustPtcFx;
191
196
197 protected vector m_fuelPos;
198
201 protected vector m_backPos;
206
208 string m_EngineStartOK = "";
210 string m_EngineStartPlug = "";
211 string m_EngineStartFuel = "";
212 string m_EngineStopFuel = "";
213
218
221
227
229 protected ref NoiseParams m_NoisePar;
231
232 protected bool m_PlayCrashSoundLight;
233 protected bool m_PlayCrashSoundHeavy;
234
235 protected bool m_HeadlightsOn;
236 protected bool m_HeadlightsState;
237 protected bool m_BrakesArePressed;
238 protected bool m_RearLightType;
239
240 protected bool m_ForceUpdateLights;
241 protected bool m_EngineStarted;
242 protected bool m_EngineDestroyed;
243
244 protected int m_CarHornState;
245
248
249 // Memory points
250 static string m_ReverseLightPoint = "light_reverse";
251 static string m_LeftHeadlightPoint = "light_left";
252 static string m_RightHeadlightPoint = "light_right";
253 static string m_LeftHeadlightTargetPoint = "light_left_dir";
254 static string m_RightHeadlightTargetPoint = "light_right_dir";
255 static string m_DrownEnginePoint = "drown_engine";
256
257 // Model selection IDs for texture/material changes
258 // If each car needs different IDs, then feel free to remove the 'static' flag and overwrite these numbers down the hierarchy
259 static const int SELECTION_ID_FRONT_LIGHT_L = 0;
260 static const int SELECTION_ID_FRONT_LIGHT_R = 1;
261 static const int SELECTION_ID_BRAKE_LIGHT_L = 2;
262 static const int SELECTION_ID_BRAKE_LIGHT_R = 3;
263 static const int SELECTION_ID_REVERSE_LIGHT_L = 4;
264 static const int SELECTION_ID_REVERSE_LIGHT_R = 5;
265 static const int SELECTION_ID_TAIL_LIGHT_L = 6;
266 static const int SELECTION_ID_TAIL_LIGHT_R = 7;
267 static const int SELECTION_ID_DASHBOARD_LIGHT = 8;
268
269 protected bool m_EngineBeforeStart;
270 protected bool m_EngineStartDoOnce;
271
273
274 #ifdef DEVELOPER
275 private const int DEBUG_MESSAGE_CLEAN_TIME_SECONDS = 10;
276 private float m_DebugMessageCleanTime;
277 private string m_DebugContactDamageMessage;
278 #endif
279
281 {
282#ifdef DEVELOPER
283 _car = this;
284#endif
285
286 SetEventMask(/*EntityEvent.CONTACT |*/ EntityEvent.POSTSIMULATE);
287
288 m_ContactCache = new CarContactCache;
289
290 m_Time = 0;
291 // sets max health for all components at init
292 m_EngineHealth = 1;
294 m_RadiatorHealth = -1;
295 m_BatteryHealth = -1;
296 m_PlugHealth = -1;
297
298 m_enginePtcFx = -1;
299 m_coolantPtcFx = -1;
300 m_exhaustPtcFx = -1;
301
303
304 m_PlayCrashSoundLight = false;
305 m_PlayCrashSoundHeavy = false;
306
307 m_CarHornState = ECarHornState.OFF;
308
309 RegisterNetSyncVariableBool("m_HeadlightsOn");
310 RegisterNetSyncVariableBool("m_BrakesArePressed");
311 RegisterNetSyncVariableBool("m_ForceUpdateLights");
312 RegisterNetSyncVariableBool("m_EngineZoneReceivedHit");
313 RegisterNetSyncVariableBoolSignal("m_PlayCrashSoundLight");
314 RegisterNetSyncVariableBoolSignal("m_PlayCrashSoundHeavy");
315 RegisterNetSyncVariableInt("m_CarHornState", ECarHornState.OFF, ECarHornState.LONG);
316
317 if ( MemoryPointExists("ptcExhaust_end") )
318 {
319 m_exhaustPtcPos = GetMemoryPointPos("ptcExhaust_end");
320 if ( MemoryPointExists("ptcExhaust_start") )
321 {
322 vector exhaustStart = GetMemoryPointPos("ptcExhaust_start");
323 vector tempOri = vector.Direction( exhaustStart, m_exhaustPtcPos);
324
325 m_exhaustPtcDir[0] = -tempOri[2];
326 m_exhaustPtcDir[1] = tempOri[1];
327 m_exhaustPtcDir[2] = tempOri[0];
328
330 }
331 }
332 else
333 {
334 m_exhaustPtcPos = "0 0 0";
335 m_exhaustPtcDir = "1 1 1";
336 }
337
338 if ( MemoryPointExists("ptcEnginePos") )
339 m_enginePtcPos = GetMemoryPointPos("ptcEnginePos");
340 else
341 m_enginePtcPos = "0 0 0";
342
343 if ( MemoryPointExists("ptcCoolantPos") )
344 m_coolantPtcPos = GetMemoryPointPos("ptcCoolantPos");
345 else
346 m_coolantPtcPos = "0 0 0";
347
348 if ( MemoryPointExists("refill") )
349 m_fuelPos = GetMemoryPointPos("refill");
350 else
351 m_fuelPos = "0 0 0";
352
353 if ( MemoryPointExists("drown_engine") )
354 m_DrownEnginePos = GetMemoryPointPos("drown_engine");
355 else
356 m_DrownEnginePos = "0 0 0";
357
358 if ( MemoryPointExists("dmgZone_engine") )
359 m_enginePos = GetMemoryPointPos("dmgZone_engine");
360 else
361 m_enginePos = "0 0 0";
362
363 if ( MemoryPointExists("dmgZone_front") )
364 m_frontPos = GetMemoryPointPos("dmgZone_front");
365 else
366 m_frontPos = "0 0 0";
367
368 if ( MemoryPointExists("dmgZone_back") )
369 m_backPos = GetMemoryPointPos("dmgZone_back");
370 else
371 m_backPos = "0 0 0";
372
373 if ( MemoryPointExists("dmgZone_fender_1_1") )
374 m_side_1_1Pos = GetMemoryPointPos("dmgZone_fender_1_1");
375 else
376 m_side_1_1Pos = "0 0 0";
377
378 if ( MemoryPointExists("dmgZone_fender_1_2") )
379 m_side_1_2Pos = GetMemoryPointPos("dmgZone_fender_1_2");
380 else
381 m_side_1_2Pos = "0 0 0";
382
383 if ( MemoryPointExists("dmgZone_fender_2_1") )
384 m_side_2_1Pos = GetMemoryPointPos("dmgZone_fender_2_1");
385 else
386 m_side_2_1Pos = "0 0 0";
387
388 if ( MemoryPointExists("dmgZone_fender_2_2") )
389 m_side_2_2Pos = GetMemoryPointPos("dmgZone_fender_2_2");
390 else
391 m_side_2_2Pos = "0 0 0";
392 }
393
394 override void EEInit()
395 {
396 super.EEInit();
397
398 if (GetGame().IsServer())
399 {
402 {
403 m_NoisePar = new NoiseParams();
404 m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseCarHorn");
405 }
406 }
407 }
408
409 #ifdef DIAG_DEVELOPER
410 void Repair()
411 {
412 if (GetGame().IsServer())
413 {
415 //server and single
416 FixEntity();
417 if (!GetGame().IsMultiplayer())
418 {
419 //single
421 }
422 }
423 else
424 {
425 //MP client
427 }
428
429 }
430 #endif
431
432
434 {
435 return ModelToWorld( m_DrownEnginePos );
436 }
437
439 {
440 return ModelToWorld( m_coolantPtcPos );
441 }
442
444 {
445 return ModelToWorld( m_fuelPos );
446 }
447
449 {
450 return ModelToWorld( m_enginePos );
451 }
453 {
454 return ModelToWorld( m_frontPos );
455 }
457 {
458 return ModelToWorld( m_backPos );
459 }
461 {
462 return ModelToWorld( m_side_1_1Pos );
463 }
465 {
466 return ModelToWorld( m_side_1_2Pos );
467 }
469 {
470 return ModelToWorld( m_side_2_1Pos );
471 }
473 {
474 return ModelToWorld( m_side_2_2Pos );
475 }
476
477 override float GetLiquidThroughputCoef()
478 {
480 }
481
482 //here we should handle the damage dealt in OnContact event, but maybe we will react even in that event
483 override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
484 {
485 super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
486
489
490 SetEngineZoneReceivedHit(dmgZone == "Engine");
491 }
492
493 override void EEDelete(EntityAI parent)
494 {
495 #ifndef SERVER
497 #endif
498 }
499
501 {
502 #ifndef SERVER
504 #endif
505 }
506
508 {
512
513 if (m_Headlight)
514 m_Headlight.Destroy();
515
516 if (m_RearLight)
517 m_RearLight.Destroy();
518
524 }
525
527 {
529 }
530
532 {
533 super.OnVariablesSynchronized();
534
535 if (GetCrashHeavySound())
536 {
538 }
539 else if (GetCrashLightSound())
540 {
542 }
543
545
546 UpdateLights();
547 }
548
550 {
551 if ( !SEffectManager.IsEffectExist( m_enginePtcFx ) && GetGame().GetWaterDepth( GetEnginePosWS() ) <= 0 )
552 {
556 }
557 }
558
559 override void EEItemAttached(EntityAI item, string slot_name)
560 {
561 super.EEItemAttached(item, slot_name);
562
563 switch (slot_name)
564 {
565 case "Reflector_1_1":
566 if (GetGame().IsServer())
567 {
568 SetHealth("Reflector_1_1", "Health", item.GetHealth());
569 }
570 break;
571 case "Reflector_2_1":
572 if (GetGame().IsServer())
573 {
574 SetHealth("Reflector_2_1", "Health", item.GetHealth());
575 }
576 break;
577 case "CarBattery":
578 case "TruckBattery":
579 if (GetGame().IsServer())
580 {
581 m_BatteryHealth = item.GetHealth01();
582 }
583 break;
584 case "SparkPlug":
585 case "GlowPlug":
586 if (GetGame().IsServer())
587 {
588 m_PlugHealth = item.GetHealth01();
589 }
590 break;
591 case "CarRadiator":
592 if (GetGame().IsServer())
593 {
594 m_RadiatorHealth = item.GetHealth01();
595 }
596
597 m_Radiator = item;
598 break;
599 }
600
601 if (GetGame().IsServer())
602 {
603 Synchronize();
604 }
605
607 UpdateLights();
608 }
609
610 // Updates state of attached headlight bulbs for faster access
612 {
613 EntityAI bulb_L = FindAttachmentBySlotName("Reflector_1_1");
614 EntityAI bulb_R = FindAttachmentBySlotName("Reflector_2_1");
615
616 if (bulb_L && !bulb_L.IsRuined() && bulb_R && !bulb_R.IsRuined())
617 {
618 m_HeadlightsState = CarHeadlightBulbsState.BOTH;
619 }
620 else if (bulb_L && !bulb_L.IsRuined())
621 {
622 m_HeadlightsState = CarHeadlightBulbsState.LEFT;
623 }
624 else if (bulb_R && !bulb_R.IsRuined())
625 {
626 m_HeadlightsState = CarHeadlightBulbsState.RIGHT;
627 }
628 else if ((!bulb_L || bulb_L.IsRuined()) && (!bulb_R || bulb_R.IsRuined()))
629 {
630 m_HeadlightsState = CarHeadlightBulbsState.NONE;
631 }
632 }
633
634 override void EEItemDetached(EntityAI item, string slot_name)
635 {
636 switch (slot_name)
637 {
638 case "CarBattery":
639 case "TruckBattery":
640 m_BatteryHealth = -1;
641 if (GetGame().IsServer())
642 {
643 if (EngineIsOn())
644 {
645 EngineStop();
646 }
647
648 if (IsScriptedLightsOn())
649 {
651 }
652 }
653 break;
654 case "SparkPlug":
655 case "GlowPlug":
656 m_PlugHealth = -1;
657 if (GetGame().IsServer() && EngineIsOn())
658 {
659 EngineStop();
660 }
661 break;
662 case "CarRadiator":
663 m_Radiator = null;
664 if (GetGame().IsServer())
665 {
666 LeakAll(CarFluid.COOLANT);
667
668 if (m_DamageZoneMap.Contains("Radiator"))
669 {
670 SetHealth("Radiator", "Health", 0);
671 }
672 }
673 break;
674 }
675
676 if (GetGame().IsServer())
677 {
678 Synchronize();
679 }
680
682 UpdateLights();
683 }
684
685 override void OnAttachmentRuined(EntityAI attachment)
686 {
687 super.OnAttachmentRuined(attachment);
688
690 UpdateLights();
691 }
692
693 override bool CanReceiveAttachment(EntityAI attachment, int slotId)
694 {
695 if (!super.CanReceiveAttachment(attachment, slotId))
696 return false;
697
698 InventoryLocation attachmentInventoryLocation = new InventoryLocation();
699 attachment.GetInventory().GetCurrentInventoryLocation(attachmentInventoryLocation);
700 if (attachmentInventoryLocation.GetParent() == null)
701 {
702 return true;
703 }
704
705 if (attachment && attachment.Type().IsInherited(CarWheel))
706 {
707 string slotSelectionName;
708 InventorySlots.GetSelectionForSlotId(slotId, slotSelectionName);
709
710 switch (slotSelectionName)
711 {
712 case "wheel_spare_1":
713 case "wheel_spare_2":
714 return CanManipulateSpareWheel(slotSelectionName);
715 break;
716 }
717 }
718
719 return true;
720 }
721
722 override bool CanReleaseAttachment(EntityAI attachment)
723 {
724 if (!super.CanReleaseAttachment(attachment))
725 {
726 return false;
727 }
728
729 if (EngineIsOn() && IsMoving())
730 {
731 return false;
732 }
733
734 if (attachment && attachment.Type().IsInherited(CarWheel))
735 {
736 InventoryLocation attachmentInventoryLocation = new InventoryLocation();
737 attachment.GetInventory().GetCurrentInventoryLocation(attachmentInventoryLocation);
738
739 string slotSelectionName;
740 InventorySlots.GetSelectionForSlotId(attachmentInventoryLocation.GetSlot(), slotSelectionName);
741
742 switch (slotSelectionName)
743 {
744 case "wheel_spare_1":
745 case "wheel_spare_2":
746 return CanManipulateSpareWheel(slotSelectionName);
747 break;
748 }
749 }
750
751 return true;
752 }
753
754 protected bool CanManipulateSpareWheel(string slotSelectionName)
755 {
756 return false;
757 }
758
759 override void EOnPostSimulate(IEntity other, float timeSlice)
760 {
761 m_Time += timeSlice;
762
763 if (GetGame().IsServer())
764 {
765 #ifdef DIAG_DEVELOPER
766 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.CONTACT)
767 {
768 if (m_ContactCalled)
769 {
770 Debug.Log("Momentum delta: " + (GetMomentum() - m_MomentumPrevTick));
771 Debug.Log("--------------------------------------------------------------------");
772 m_ContactCalled = false;
773 }
774 }
775 #endif
776
777
781 #ifdef DEVELOPER
782 m_DebugMessageCleanTime += timeSlice;
783 if (m_DebugMessageCleanTime >= DEBUG_MESSAGE_CLEAN_TIME_SECONDS)
784 {
785 m_DebugMessageCleanTime = 0;
786 m_DebugContactDamageMessage = "";
787 }
788 #endif
789 }
790
792 {
793 m_Time = 0;
794
796
797 //First of all check if the car should stop the engine
798 if (GetGame().IsServer() && EngineIsOn())
799 {
800 if ( GetFluidFraction(CarFluid.FUEL) <= 0 || m_EngineHealth <= 0 )
801 EngineStop();
802
803 CheckVitalItem(IsVitalCarBattery(), "CarBattery");
804 CheckVitalItem(IsVitalTruckBattery(), "TruckBattery");
805 CheckVitalItem(IsVitalSparkPlug(), "SparkPlug");
806 CheckVitalItem(IsVitalGlowPlug(), "GlowPlug");
807 }
808
809 if (GetGame().IsServer())
810 {
811 if (IsVitalFuelTank())
812 {
814 {
815 SetHealth("Engine", "Health", GameConstants.DAMAGE_RUINED_VALUE);
816 }
817 }
818 }
819
821 if ( EngineIsOn() )
822 {
823 if ( GetGame().IsServer() )
824 {
825 float dmg;
826
827 if ( EngineGetRPM() >= EngineGetRPMRedline() )
828 {
829 if (EngineGetRPM() > EngineGetRPMMax())
830 AddHealth( "Engine", "Health", -GetMaxHealth("Engine", "") * 0.05 ); //CAR_RPM_DMG
831
832 dmg = EngineGetRPM() * 0.001 * Math.RandomFloat( 0.02, 1.0 ); //CARS_TICK_DMG_MIN; //CARS_TICK_DMG_MAX
833 ProcessDirectDamage(DamageType.CUSTOM, null, "Engine", "EnviroDmg", vector.Zero, dmg);
835 }
836 else
837 {
839 }
840
842 if ( IsVitalRadiator() )
843 {
844 if ( GetFluidFraction(CarFluid.COOLANT) > 0 && m_RadiatorHealth < 0.5 ) //CARS_LEAK_THRESHOLD
845 LeakFluid( CarFluid.COOLANT );
846 }
847
848 if ( GetFluidFraction(CarFluid.FUEL) > 0 && m_FuelTankHealth < GameConstants.DAMAGE_DAMAGED_VALUE )
849 LeakFluid( CarFluid.FUEL );
850
851 if ( GetFluidFraction(CarFluid.BRAKE) > 0 && m_EngineHealth < GameConstants.DAMAGE_DAMAGED_VALUE )
852 LeakFluid( CarFluid.BRAKE );
853
854 if ( GetFluidFraction(CarFluid.OIL) > 0 && m_EngineHealth < GameConstants.DAMAGE_DAMAGED_VALUE )
855 LeakFluid( CarFluid.OIL );
856
857 if ( m_EngineHealth < 0.25 )
858 LeakFluid( CarFluid.OIL );
859
860 if ( IsVitalRadiator() )
861 {
862 if ( GetFluidFraction( CarFluid.COOLANT ) < 0.5 && GetFluidFraction( CarFluid.COOLANT ) >= 0 )
863 {
864 dmg = ( 1 - GetFluidFraction(CarFluid.COOLANT) ) * Math.RandomFloat( 0.02, 10.00 ); //CARS_DMG_TICK_MIN_COOLANT; //CARS_DMG_TICK_MAX_COOLANT
865 AddHealth( "Engine", "Health", -dmg );
867 }
868 }
869 }
870
871 //FX only on Client and in Single
872 if (!GetGame().IsDedicatedServer())
873 {
875 {
879 }
880
881 if (IsVitalRadiator() && GetFluidFraction(CarFluid.COOLANT) < 0.5)
882 {
884 {
887 }
888
889 if (m_coolantFx)
890 {
891 if (GetFluidFraction(CarFluid.COOLANT) > 0)
893 else
895 }
896 }
897 else
898 {
901 }
902 }
903 }
904 else
905 {
906 //FX only on Client and in Single
907 if ( !GetGame().IsDedicatedServer() )
908 {
910 {
912 m_exhaustPtcFx = -1;
913 }
914
916 {
918 m_coolantPtcFx = -1;
919 }
920 }
921 }
922 }
923 }
924
926 {
927 UpdateLights();
928 }
929
931 {
932 UpdateLights();
933 }
934
935 override void OnUpdate( float dt )
936 {
937 if ( GetGame().IsServer() )
938 {
939 ItemBase battery = GetBattery();
940 if ( battery )
941 {
942 if ( EngineIsOn() )
943 {
944 m_BatteryTimer += dt;
946 {
947 battery.GetCompEM().ConsumeEnergy(GetBatteryRechargeRate() * m_BatteryTimer);
948 m_BatteryTimer = 0;
949 }
950 }
951 else if ( !EngineIsOn() && IsScriptedLightsOn() )
952 {
953 m_BatteryTimer += dt;
955 {
956 battery.GetCompEM().ConsumeEnergy(GetBatteryRuntimeConsumption() * m_BatteryTimer);
957 m_BatteryTimer = 0;
958
959 if ( battery.GetCompEM().GetEnergy() <= 0 )
960 {
962 }
963 }
964 }
965 }
966
967 if ( GetGame().GetWaterDepth( GetEnginePosWS() ) > 0 )
968 {
969 m_DrownTime += dt;
971 {
972 // *dt to get damage per second
973 AddHealth( "Engine", "Health", -DROWN_ENGINE_DAMAGE * dt);
975 }
976 }
977 else
978 {
979 m_DrownTime = 0;
980 }
981 }
982
983 // For visualisation of brake lights for all players
984 float brake_coef = GetBrake();
985 if ( brake_coef > 0 )
986 {
987 if ( !m_BrakesArePressed )
988 {
989 m_BrakesArePressed = true;
990 SetSynchDirty();
992 }
993 }
994 else
995 {
996 if ( m_BrakesArePressed )
997 {
998 m_BrakesArePressed = false;
999 SetSynchDirty();
1001 }
1002 }
1003
1004 if ( (!GetGame().IsDedicatedServer()) && m_ForceUpdateLights )
1005 {
1006 UpdateLights();
1007 m_ForceUpdateLights = false;
1008 }
1009 }
1010
1011 override void EEKilled(Object killer)
1012 {
1013 super.EEKilled(killer);
1014 m_EngineDestroyed = true;
1015 }
1016
1018 override void OnContact( string zoneName, vector localPos, IEntity other, Contact data )
1019 {
1020 if (GetGame().IsServer())
1021 {
1022 #ifdef DIAG_DEVELOPER
1023 m_ContactCalled = true;
1024 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.CONTACT)
1025 {
1026 string output = "Zone: " + zoneName + " | Impulse:" + data.Impulse;
1027 Debug.Log(output);
1028 }
1029 #endif
1030 if (m_ContactCache.Count() == 0)
1031 {
1033 m_ContactCache.Insert(zoneName, ccd);
1034 float momentumDelta = GetMomentum() - m_MomentumPrevTick;
1035 float dot = vector.Dot(m_VelocityPrevTick.Normalized(), GetVelocity(this).Normalized());
1036 if (dot < 0)
1037 {
1038 momentumDelta = m_MomentumPrevTick;
1039 }
1040
1041 ccd.Insert(new CarContactData(localPos, other, momentumDelta));
1042 }
1043 }
1044 }
1045
1048 {
1049
1050 int contactZonesCount = m_ContactCache.Count();
1051
1052 if (contactZonesCount == 0)
1053 return;
1054
1055
1056 for (int i = 0; i < contactZonesCount; ++i)
1057 {
1058 string zoneName = m_ContactCache.GetKey(i);
1060
1061 float dmg = Math.AbsInt(data[0].impulse * m_dmgContactCoef);
1062 float crewDmgBase = Math.AbsInt((data[0].impulse / dBodyGetMass(this)) * 1000 * m_dmgContactCoef);// calculates damage as if the object's weight was 1000kg instead of its actual weight
1063
1064 #ifdef DIAG_DEVELOPER
1065 CrashDebugData.m_CrashDataPoint = new CrashDebugData();
1066 CrashDebugData.m_CrashDataPoint.m_VehicleType = GetDisplayName();
1067 CrashDebugData.m_CrashDataPoint.m_Damage = dmg;
1068 CrashDebugData.m_CrashDataPoint.m_Zone = zoneName;
1069 CrashDebugData.m_CrashDataPoint.m_MomentumCurr = GetMomentum();
1070 CrashDebugData.m_CrashDataPoint.m_MomentumPrev = m_MomentumPrevTick;
1071 CrashDebugData.m_CrashDataPoint.m_MomentumDelta = data[0].impulse;
1072 CrashDebugData.m_CrashDataPoint.m_SpeedWorld = GetVelocity(this).Length() * 3.6;
1073 CrashDebugData.m_CrashDataPoint.m_SpeedWorldPrev = m_VelocityPrevTick.Length() * 3.6;
1074 CrashDebugData.m_CrashDataPoint.m_SpeedWorldDelta = (m_VelocityPrevTick.Length() - GetVelocity(this).Length()) * 3.6;
1075 CrashDebugData.m_CrashDataPoint.m_VelocityCur = GetVelocity(this);
1076 CrashDebugData.m_CrashDataPoint.m_VelocityPrev = m_VelocityPrevTick;
1077 CrashDebugData.m_CrashDataPoint.m_VelocityDot = vector.Dot(m_VelocityPrevTick.Normalized(), GetVelocity(this).Normalized());
1078 CrashDebugData.m_CrashDataPoint.m_Time = GetGame().GetTime();
1079
1080
1081
1082 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_CONSIDERED)
1083 {
1084 Debug.Log("--------------------------------------------------");
1085 Debug.Log("Vehicle:" + GetDisplayName());
1086 Debug.Log("DMG: " + dmg);
1087 Debug.Log("zoneName : "+ zoneName);
1088 Debug.Log("momentumCurr : "+ GetMomentum());
1089 Debug.Log("momentumPrev : "+ m_MomentumPrevTick);
1090 Debug.Log("momentumDelta : "+ data[0].impulse);
1091 Debug.Log("speed(km/h): "+ GetVelocity(this).Length() * 3.6);
1092 Debug.Log("speedPrev(km/h): "+ m_VelocityPrevTick.Length() * 3.6);
1093 Debug.Log("speedDelta(km/h) : "+ (m_VelocityPrevTick.Length() - GetVelocity(this).Length()) * 3.6);
1094 Debug.Log("velocityCur.): "+ GetVelocity(this));
1095 Debug.Log("velocityPrev.): "+ m_VelocityPrevTick);
1096 Debug.Log("velocityDot): "+ vector.Dot(m_VelocityPrevTick.Normalized(), GetVelocity(this).Normalized()));
1097 Debug.Log("GetGame().GetTime(): "+ GetGame().GetTime());
1098 Debug.Log("--------------------------------------------------");
1099 }
1100 #endif
1102 continue;
1103
1104 int pddfFlags;
1105 #ifdef DIAG_DEVELOPER
1106 CrashDebugData.m_CrashData.Insert(CrashDebugData.m_CrashDataPoint);
1107 CrashDebugData.m_CrashDataPoint.m_Speedometer = GetSpeedometer();
1108 //Print("Crash data recorded");
1109 #endif
1111 {
1112 #ifdef DIAG_DEVELOPER
1113 CrashDebugData.m_CrashDataPoint.m_DamageType = "Small";
1114 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1115 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(), GetGame().GetTime() ));
1116 #endif
1118 pddfFlags = ProcessDirectDamageFlags.NO_TRANSFER;
1119 }
1120 else
1121 {
1122 #ifdef DIAG_DEVELOPER
1123 CrashDebugData.m_CrashDataPoint.m_DamageType = "Big";
1124 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1125 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(), GetGame().GetTime() ));
1126 #endif
1127 DamageCrew(crewDmgBase);
1129 pddfFlags = 0;
1130 }
1131
1132 #ifdef DEVELOPER
1133 m_DebugContactDamageMessage += string.Format("%1: %2\n", zoneName, dmg);
1134 #endif
1135
1136 ProcessDirectDamage(DT_CUSTOM, null, zoneName, "EnviroDmg", "0 0 0", dmg, pddfFlags);
1137 }
1138
1140 UpdateLights();
1141
1142 m_ContactCache.Clear();
1143
1144 }
1145
1147 void DamageCrew(float dmg)
1148 {
1149 for ( int c = 0; c < CrewSize(); ++c )
1150 {
1151 Human crew = CrewMember( c );
1152 if ( !crew )
1153 continue;
1154
1155 PlayerBase player;
1156 if ( Class.CastTo(player, crew ) )
1157 {
1159 {
1160 #ifdef DIAG_DEVELOPER
1161 CrashDebugData.m_CrashDataPoint.m_CrewDamageBase = dmg;
1162 CrashDebugData.m_CrashDataPoint.m_DMGHealth = -100;
1163 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1164 {
1165 Debug.Log("--------------------------------------------------");
1166 Debug.Log("Killing the player");
1167 Debug.Log("Crew DMG Base: " + dmg);
1168 Debug.Log("--------------------------------------------------");
1169
1170 }
1171 #endif
1172 player.SetHealth(0.0);
1173 }
1174 else
1175 {
1177 shockTemp = Math.Clamp(shockTemp,0,1);
1178 float shock = Math.Lerp( 50, 150, shockTemp );
1179 float hp = Math.Lerp( 2, 100, shockTemp );
1180
1181 #ifdef DIAG_DEVELOPER
1182 CrashDebugData.m_CrashDataPoint.m_CrewDamageBase = dmg;
1183 CrashDebugData.m_CrashDataPoint.m_ShockTemp = shockTemp;
1184 CrashDebugData.m_CrashDataPoint.m_DMGHealth = hp;
1185 CrashDebugData.m_CrashDataPoint.m_DMGShock = shock;
1186 if (DEBUG_OUTPUT_TYPE & EVehicleDebugOutputType.DAMAGE_APPLIED)
1187 {
1188 Debug.Log("--------------------------------------------------");
1189 Debug.Log("Crew DMG Base: " + dmg);
1190 Debug.Log("Crew shockTemp: " + shockTemp);
1191 Debug.Log("Crew DMG Health: " + hp);
1192 Debug.Log("Crew DMG Shock: " + shock);
1193 Debug.Log("--------------------------------------------------");
1194 }
1195 #endif
1196
1197 player.AddHealth("", "Shock", -shock );
1198 player.AddHealth("", "Health", -hp );
1199 }
1200 }
1201 }
1202 }
1203
1209 override float OnSound( CarSoundCtrl ctrl, float oldValue )
1210 {
1211 switch (ctrl)
1212 {
1213 case CarSoundCtrl.ENGINE:
1214 if (!m_EngineStarted)
1215 {
1216 return 0.0;
1217 }
1218 break;
1219 }
1220
1221 return oldValue;
1222 }
1223
1224 override void OnAnimationPhaseStarted(string animSource, float phase)
1225 {
1226 #ifndef SERVER
1227 HandleDoorsSound(animSource, phase);
1228 HandleSeatAdjustmentSound(animSource, phase);
1229 #endif
1230 }
1231
1232 protected void HandleDoorsSound(string animSource, float phase)
1233 {
1234 switch (animSource)
1235 {
1236 case "doorsdriver":
1237 case "doorscodriver":
1238 case "doorscargo1":
1239 case "doorscargo2":
1240 case "doorshood":
1241 case "doorstrunk":
1242 EffectSound sound;
1243 if (phase == 0)
1245 else
1247
1248 if (sound)
1249 sound.SetAutodestroy(true);
1250
1251 break;
1252 }
1253 }
1254
1255 protected void HandleSeatAdjustmentSound(string animSource, float phase)
1256 {
1257 switch (animSource)
1258 {
1259 case "seatdriver":
1260 case "seatcodriver":
1261 EffectSound sound;
1262 if (phase == 0)
1264 else
1266
1267 if (sound)
1268 sound.SetAutodestroy(true);
1269
1270 break;
1271 }
1272 }
1273
1274
1275 protected void HandleCarHornSound(ECarHornState pState)
1276 {
1277 switch (pState)
1278 {
1279 case ECarHornState.SHORT:
1280 PlaySoundSet(m_CarHornSoundEffect, m_CarHornShortSoundName, 0, 0, false);
1281 break;
1282 case ECarHornState.LONG:
1283 PlaySoundSet(m_CarHornSoundEffect, m_CarHornLongSoundName, 0, 0, true);
1284 break;
1285 default:
1287 break;
1288 }
1289 }
1290
1291 void HandleEngineSound(CarEngineSoundState state)
1292 {
1293 #ifndef SERVER
1294 PlayerBase player = null;
1295 EffectSound sound = null;
1296 WaveKind waveKind = WaveKind.WAVEEFFECT;
1297
1298 switch (state)
1299 {
1300 case CarEngineSoundState.STARTING:
1301 m_PreStartSound = SEffectManager.PlaySound("Offroad_02_Starting_SoundSet", ModelToWorld(GetEnginePos()));
1303 break;
1304 case CarEngineSoundState.START_OK:
1305 // play different sound based on selected camera
1306 if (Class.CastTo(player, CrewMember(0)))
1307 {
1308 if (!player.IsCameraInsideVehicle())
1309 {
1310 waveKind = WaveKind.WAVEEFFECTEX;
1311 }
1312
1313 sound = SEffectManager.CreateSound(m_EngineStartOK, ModelToWorld(GetEnginePos()));
1314 if (sound)
1315 {
1316 sound.SetSoundWaveKind(waveKind);
1317 sound.SoundPlay();
1318 sound.SetAutodestroy(true);
1319 }
1320 }
1321
1324 break;
1325
1326 case CarEngineSoundState.START_NO_FUEL:
1327 sound = SEffectManager.PlaySound("offroad_engine_failed_start_fuel_SoundSet", ModelToWorld(GetEnginePos()));
1328 sound.SetAutodestroy(true);
1329 break;
1330
1331 case CarEngineSoundState.START_NO_BATTERY:
1332 sound = SEffectManager.PlaySound("offroad_engine_failed_start_battery_SoundSet", ModelToWorld(GetEnginePos()));
1333 sound.SetAutodestroy(true);
1334 break;
1335
1336 case CarEngineSoundState.START_NO_SPARKPLUG:
1337 sound = SEffectManager.PlaySound("offroad_engine_failed_start_sparkplugs_SoundSet", ModelToWorld(GetEnginePos()));
1338 sound.SetAutodestroy(true);
1339 break;
1340
1341 case CarEngineSoundState.STOP_OK:
1342 case CarEngineSoundState.STOP_NO_FUEL:
1343 // play different sound based on selected camera
1344 if (Class.CastTo(player, CrewMember(0)))
1345 {
1346 if (!player.IsCameraInsideVehicle())
1347 {
1348 waveKind = WaveKind.WAVEEFFECTEX;
1349 }
1350
1351 sound = SEffectManager.CreateSound(m_EngineStopFuel, ModelToWorld(GetEnginePos()));
1352 if (sound)
1353 {
1354 sound.SetSoundWaveKind(waveKind);
1355 sound.SoundPlay();
1356 sound.SetAutodestroy(true);
1357 }
1358 }
1359
1360 SetEngineStarted(false);
1361 break;
1362 }
1363 #endif
1364 }
1365
1368
1375 override void OnFluidChanged(CarFluid fluid, float newValue, float oldValue)
1376 {
1377 switch ( fluid )
1378 {
1379 case CarFluid.FUEL:
1380 m_FuelAmmount = newValue;
1381 break;
1382
1383 case CarFluid.OIL:
1384 m_OilAmmount = newValue;
1385 break;
1386
1387 case CarFluid.BRAKE:
1388 m_BrakeAmmount = newValue;
1389 break;
1390
1391 case CarFluid.COOLANT:
1392 m_CoolantAmmount = newValue;
1393 break;
1394 }
1395 }
1396
1403 override bool OnBeforeEngineStart()
1404 {
1405 EntityAI item = null;
1406
1408 {
1409 m_EngineStartDoOnce = false;
1410 return m_EngineBeforeStart;
1411 }
1412
1413 if (GetFluidFraction(CarFluid.FUEL) <= 0)
1414 {
1415 HandleEngineSound(CarEngineSoundState.START_NO_FUEL);
1416 return false;
1417 }
1418
1420 {
1421 item = GetBattery();
1422 if (!item || (item && (item.IsRuined() || item.GetCompEM().GetEnergy() < m_BatteryEnergyStartMin)))
1423 {
1424 m_EngineStartDoOnce = true;
1425 HandleEngineSound(CarEngineSoundState.START_NO_BATTERY);
1426 return false;
1427 }
1428 }
1429
1430 if (IsVitalSparkPlug())
1431 {
1432 item = FindAttachmentBySlotName("SparkPlug");
1433 if (!item || (item && item.IsRuined()))
1434 {
1435 m_EngineStartDoOnce = true;
1436 HandleEngineSound(CarEngineSoundState.START_NO_SPARKPLUG);
1437 return false;
1438 }
1439 }
1440
1441 if (IsVitalGlowPlug())
1442 {
1443 item = FindAttachmentBySlotName("GlowPlug");
1444 if (!item || (item && item.IsRuined()))
1445 {
1446 m_EngineStartDoOnce = true;
1447 HandleEngineSound(CarEngineSoundState.START_NO_SPARKPLUG);
1448 return false;
1449 }
1450 }
1451
1453 {
1454 m_EngineBeforeStart = true;
1455 HandleEngineSound(CarEngineSoundState.STARTING);
1456 }
1457
1458 return true;
1459 }
1460
1461 override void OnGearChanged(int newGear, int oldGear)
1462 {
1463 //Debug.Log(string.Format("OnGearChanged newGear=%1,oldGear=%2", newGear, oldGear));
1464 UpdateLights(newGear);
1465 }
1466
1468 override void OnEngineStart()
1469 {
1470 ItemBase battery = GetBattery();
1471 if (GetGame().IsServer() && battery)
1472 {
1473 battery.GetCompEM().ConsumeEnergy(GetBatteryConsumption());
1474 }
1475
1476 UpdateLights();
1477
1478 HandleEngineSound(CarEngineSoundState.START_OK);
1479
1480 m_EngineBeforeStart = false;
1481 }
1482
1484 override void OnEngineStop()
1485 {
1486 UpdateLights();
1487
1488 HandleEngineSound(CarEngineSoundState.STOP_OK);
1490
1491 m_EngineBeforeStart = false;
1492 }
1493
1498 bool OnBeforeSwitchLights( bool toOn )
1499 {
1500 return true;
1501 }
1502
1505 {
1506 return m_HeadlightsOn;
1507 }
1508
1511 {
1513 SetSynchDirty();
1514 }
1515
1516 void UpdateLights(int new_gear = -1)
1517 {
1518 #ifndef SERVER
1519 UpdateLightsClient(new_gear);
1520 #endif
1521 UpdateLightsServer(new_gear);
1522 }
1523
1524 void UpdateLightsClient(int newGear = -1)
1525 {
1526 int gear;
1527
1528 if (newGear == -1)
1529 {
1530 gear = GetGear();
1531 }
1532 else
1533 {
1534 gear = newGear;
1535 }
1536
1537 if (m_HeadlightsOn)
1538 {
1539 if (!m_Headlight && m_HeadlightsState != CarHeadlightBulbsState.NONE)
1540 {
1542 }
1543
1544 if (m_Headlight)
1545 {
1546 switch (m_HeadlightsState)
1547 {
1548 case CarHeadlightBulbsState.LEFT:
1550 m_Headlight.SegregateLight();
1551 break;
1552 case CarHeadlightBulbsState.RIGHT:
1554 m_Headlight.SegregateLight();
1555 break;
1556 case CarHeadlightBulbsState.BOTH:
1557 vector local_pos_left = GetMemoryPointPos(m_LeftHeadlightPoint);
1558 vector local_pos_right = GetMemoryPointPos(m_RightHeadlightPoint);
1559
1560 vector local_pos_middle = (local_pos_left + local_pos_right) * 0.5;
1561 m_Headlight.AttachOnObject(this, local_pos_middle);
1562 m_Headlight.AggregateLight();
1563 break;
1564 default:
1565 m_Headlight.FadeOut();
1566 m_Headlight = null;
1567 }
1568 }
1569 }
1570 else
1571 {
1572 if (m_Headlight)
1573 {
1574 m_Headlight.FadeOut();
1575 m_Headlight = null;
1576 }
1577 }
1578
1579 // brakes & reverse
1580 switch (gear)
1581 {
1582 case CarGear.REVERSE:
1585 m_RearLightType = CarRearLightType.BRAKES_AND_REVERSE;
1586 else
1587 m_RearLightType = CarRearLightType.REVERSE_ONLY;
1588 break;
1589 default:
1591 m_RearLightType = CarRearLightType.BRAKES_ONLY;
1592 else
1593 m_RearLightType = CarRearLightType.NONE;
1594 }
1595
1596 //Debug.Log(string.Format("m_BrakesArePressed=%1, m_RearLightType=%2", m_BrakesArePressed.ToString(), EnumTools.EnumToString(CarRearLightType, m_RearLightType)));
1597
1598 if (!m_RearLight && m_RearLightType != CarRearLightType.NONE && m_HeadlightsState != CarHeadlightBulbsState.NONE)
1599 {
1600 if (EngineIsOn() || m_RearLightType == CarRearLightType.BRAKES_ONLY || m_RearLightType == CarRearLightType.BRAKES_AND_REVERSE)
1601 {
1603 vector localPos = GetMemoryPointPos(m_ReverseLightPoint);
1604 m_RearLight.AttachOnObject(this, localPos, "180 0 0");
1605 }
1606 }
1607
1608 // rear lights
1609 if (m_RearLight && m_RearLightType != CarRearLightType.NONE && m_HeadlightsState != CarHeadlightBulbsState.NONE)
1610 {
1611 switch (m_RearLightType)
1612 {
1613 case CarRearLightType.BRAKES_ONLY:
1615 break;
1616 case CarRearLightType.REVERSE_ONLY:
1617 if (EngineIsOn())
1619 else
1620 NoRearLight();
1621
1622 break;
1623 case CarRearLightType.BRAKES_AND_REVERSE:
1624 if (EngineIsOn())
1626 else
1628
1629 break;
1630 default:
1631 NoRearLight();
1632 }
1633 }
1634 else
1635 {
1636 if (m_RearLight)
1637 {
1638 NoRearLight();
1639 }
1640 }
1641 }
1642
1643 void UpdateLightsServer(int newGear = -1)
1644 {
1645 int gear;
1646
1647 if (newGear == -1)
1648 {
1649 gear = GetGear();
1650 if (GearboxGetType() == CarGearboxType.AUTOMATIC)
1651 {
1652 gear = GearboxGetMode();
1653 }
1654 }
1655 else
1656 {
1657 gear = newGear;
1658 }
1659
1660 if (m_HeadlightsOn)
1661 {
1664
1665 switch (m_HeadlightsState)
1666 {
1667 case CarHeadlightBulbsState.LEFT:
1670 break;
1671 case CarHeadlightBulbsState.RIGHT:
1674 break;
1675 case CarHeadlightBulbsState.BOTH:
1678 break;
1679 default:
1682 }
1683
1684 //Debug.Log(string.Format("m_HeadlightsOn=%1, m_HeadlightsState=%2", m_HeadlightsOn.ToString(), EnumTools.EnumToString(CarHeadlightBulbsState, m_HeadlightsState)));
1685 }
1686 else
1687 {
1692 }
1693
1694
1695 // brakes & reverse
1696 switch (gear)
1697 {
1698 case CarGear.REVERSE:
1701 m_RearLightType = CarRearLightType.BRAKES_AND_REVERSE;
1702 else
1703 m_RearLightType = CarRearLightType.REVERSE_ONLY;
1704 break;
1705 default:
1707 m_RearLightType = CarRearLightType.BRAKES_ONLY;
1708 else
1709 m_RearLightType = CarRearLightType.NONE;
1710 }
1711
1712 //Debug.Log(string.Format("m_BrakesArePressed=%1, m_RearLightType=%2", m_BrakesArePressed.ToString(), EnumTools.EnumToString(CarRearLightType, m_RearLightType)));
1713
1714
1715 // rear lights
1716 if (m_RearLightType != CarRearLightType.NONE && m_HeadlightsState != CarHeadlightBulbsState.NONE)
1717 {
1718 switch (m_RearLightType)
1719 {
1720 case CarRearLightType.BRAKES_ONLY:
1723 break;
1724 case CarRearLightType.REVERSE_ONLY:
1725 if (EngineIsOn())
1726 {
1729 }
1730 else
1731 {
1734 }
1735 break;
1736 case CarRearLightType.BRAKES_AND_REVERSE:
1737 if (EngineIsOn())
1738 {
1741 }
1742 else
1743 {
1746 }
1747 break;
1748 default:
1751 }
1752 }
1753 else
1754 {
1757 }
1758 }
1759
1760 protected void BrakesRearLight()
1761 {
1762 m_RearLight.SetAsSegregatedBrakeLight();
1763 }
1764
1765 protected void ReverseRearLight()
1766 {
1767 m_RearLight.SetAsSegregatedReverseLight();
1768 }
1769
1771 {
1772 m_RearLight.AggregateLight();
1773 m_RearLight.SetFadeOutTime(1);
1774 }
1775
1776 protected void NoRearLight()
1777 {
1778 m_RearLight.FadeOut();
1779 m_RearLight = null;
1780 }
1781
1782 protected void LeftFrontLightShineOn()
1783 {
1784 string material = ConfigGetString("frontReflectorMatOn");
1785
1786 if (material)
1787 {
1788 SetObjectMaterial(SELECTION_ID_FRONT_LIGHT_L, material);
1789 }
1790 }
1791
1792 protected void RightFrontLightShineOn()
1793 {
1794 string material = ConfigGetString("frontReflectorMatOn");
1795
1796 if (material)
1797 {
1798 SetObjectMaterial(SELECTION_ID_FRONT_LIGHT_R, material);
1799 }
1800 }
1801
1802 protected void LeftFrontLightShineOff()
1803 {
1804 string material = ConfigGetString("frontReflectorMatOff");
1805
1806 if (material)
1807 {
1808 SetObjectMaterial(SELECTION_ID_FRONT_LIGHT_L, material);
1809 }
1810 }
1811
1813 {
1814 string material = ConfigGetString("frontReflectorMatOff");
1815
1816 if (material)
1817 {
1818 SetObjectMaterial(SELECTION_ID_FRONT_LIGHT_R, material);
1819 }
1820 }
1821
1822 protected void ReverseLightsShineOn()
1823 {
1824 string material = ConfigGetString("ReverseReflectorMatOn");
1825
1826 if (material)
1827 {
1828 SetObjectMaterial(SELECTION_ID_REVERSE_LIGHT_L, material);
1829 SetObjectMaterial(SELECTION_ID_REVERSE_LIGHT_R, material);
1830 }
1831 }
1832
1833 protected void ReverseLightsShineOff()
1834 {
1835 string material = ConfigGetString("ReverseReflectorMatOff");
1836
1837 if (material)
1838 {
1839 SetObjectMaterial(SELECTION_ID_REVERSE_LIGHT_L, material);
1840 SetObjectMaterial(SELECTION_ID_REVERSE_LIGHT_R, material);
1841 }
1842 }
1843
1844 protected void BrakeLightsShineOn()
1845 {
1846 string material = ConfigGetString("brakeReflectorMatOn");
1847
1848 if (material)
1849 {
1850 SetObjectMaterial(SELECTION_ID_BRAKE_LIGHT_L, material);
1851 SetObjectMaterial(SELECTION_ID_BRAKE_LIGHT_R, material);
1852 }
1853 }
1854
1855 protected void BrakeLightsShineOff()
1856 {
1857 string material = ConfigGetString("brakeReflectorMatOff");
1858
1859 if (material)
1860 {
1861 SetObjectMaterial(SELECTION_ID_BRAKE_LIGHT_L, material);
1862 SetObjectMaterial(SELECTION_ID_BRAKE_LIGHT_R, material);
1863 }
1864 }
1865
1866 protected void TailLightsShineOn()
1867 {
1868 string material = ConfigGetString("TailReflectorMatOn");
1869 string materialOff = ConfigGetString("TailReflectorMatOff");
1870
1871 if (material && materialOff)
1872 {
1873 if (m_HeadlightsState == CarHeadlightBulbsState.LEFT)
1874 {
1875 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_L, material);
1876 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_R, materialOff);
1877 }
1878 else if (m_HeadlightsState == CarHeadlightBulbsState.RIGHT)
1879 {
1880 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_L, materialOff);
1881 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_R, material);
1882 }
1883 else if (m_HeadlightsState == CarHeadlightBulbsState.BOTH)
1884 {
1885 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_L, material);
1886 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_R, material);
1887 }
1888 }
1889 }
1890
1891 protected void TailLightsShineOff()
1892 {
1893 string material = ConfigGetString("TailReflectorMatOff");
1894
1895 if (material)
1896 {
1897 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_L, material);
1898 SetObjectMaterial(SELECTION_ID_TAIL_LIGHT_R, material);
1899 }
1900 }
1901
1902 protected void DashboardShineOn()
1903 {
1904 string material = ConfigGetString("dashboardMatOn");
1905
1906 if (material)
1907 {
1908 SetObjectMaterial(SELECTION_ID_DASHBOARD_LIGHT, material);
1909 }
1910 }
1911
1912 protected void DashboardShineOff()
1913 {
1914 string material = ConfigGetString("dashboardMatOff");
1915
1916 if (material)
1917 {
1918 SetObjectMaterial(SELECTION_ID_DASHBOARD_LIGHT, material);
1919 }
1920 }
1921
1922 // Override this for a car-specific light type
1924 {
1925 return CarRearLightBase.Cast(ScriptedLightBase.CreateLight(OffroadHatchbackFrontLight));
1926 }
1927
1928 // Override this for a car-specific light type
1930 {
1931 return CarLightBase.Cast(ScriptedLightBase.CreateLight(OffroadHatchbackFrontLight));
1932 }
1933
1934 protected void CheckVitalItem( bool isVital, string itemName )
1935 {
1936 if ( !isVital )
1937 return;
1938
1939 EntityAI item = FindAttachmentBySlotName(itemName);
1940
1941 if ( !item )
1942 EngineStop();
1943 else if ( item.IsRuined() )
1944 EngineStop();
1945 }
1946
1947 protected void LeakFluid(CarFluid fluid)
1948 {
1949 float ammount = 0;
1950
1951 switch (fluid)
1952 {
1953 case CarFluid.COOLANT:
1954 ammount = (1- m_RadiatorHealth) * Math.RandomFloat(0.02, 0.05);//CARS_LEAK_TICK_MIN; CARS_LEAK_TICK_MAX
1955 Leak(fluid, ammount);
1956 break;
1957
1958 case CarFluid.OIL:
1959 ammount = ( 1 - m_EngineHealth ) * Math.RandomFloat(0.02, 1.0);//CARS_LEAK_OIL_MIN; CARS_LEAK_OIL_MAX
1960 Leak(fluid, ammount);
1961 break;
1962
1963 case CarFluid.FUEL:
1964 ammount = ( 1 - m_FuelTankHealth ) * Math.RandomFloat(0.02, 0.05);//CARS_LEAK_TICK_MIN; CARS_LEAK_TICK_MAX
1965 Leak(fluid, ammount);
1966 break;
1967 }
1968 }
1969
1970 protected void CarPartsHealthCheck()
1971 {
1972 if (GetGame().IsServer())
1973 {
1974 if (HasRadiator())
1975 {
1976 m_RadiatorHealth = GetRadiator().GetHealth01("", "");
1977 }
1978 else
1979 {
1980 m_RadiatorHealth = 0;
1981 }
1982
1983 m_EngineHealth = GetHealth01("Engine", "");
1984 m_FuelTankHealth = GetHealth01("FuelTank", "");
1985 }
1986 }
1987
1989 {
1990 return m_PlayCrashSoundLight;
1991 }
1992
1993 void SynchCrashLightSound(bool play)
1994 {
1995 if (m_PlayCrashSoundLight != play)
1996 {
1997 m_PlayCrashSoundLight = play;
1998 SetSynchDirty();
1999 }
2000 }
2001
2003 {
2004 PlaySoundEx("offroad_hit_light_SoundSet", m_CrashSoundLight, m_PlayCrashSoundLight);
2005 }
2006
2008 {
2009 return m_PlayCrashSoundHeavy;
2010 }
2011
2012 void SynchCrashHeavySound(bool play)
2013 {
2014 if (m_PlayCrashSoundHeavy != play)
2015 {
2016 m_PlayCrashSoundHeavy = play;
2017 SetSynchDirty();
2018 }
2019 }
2020
2022 {
2023 PlaySoundEx("offroad_hit_heavy_SoundSet", m_CrashSoundHeavy, m_PlayCrashSoundHeavy);
2024 }
2025
2026 void PlaySoundEx(string soundset, EffectSound sound, out bool soundbool)
2027 {
2028 #ifndef SERVER
2029 if (!sound)
2030 {
2032 if( sound )
2033 {
2034 sound.SetAutodestroy(true);
2035 }
2036 }
2037 else
2038 {
2039 if (!sound.IsSoundPlaying())
2040 {
2041 sound.SetPosition(GetPosition());
2042 sound.SoundPlay();
2043 }
2044 }
2045
2046 soundbool = false;
2047 #endif
2048 }
2049
2050 void PlaySound(string soundset, ref EffectSound sound, out bool soundbool)
2051 {
2052 PlaySoundEx(soundset, sound, soundbool);
2053 }
2054
2055 string GetAnimSourceFromSelection( string selection )
2056 {
2057 return "";
2058 }
2059
2060 string GetDoorConditionPointFromSelection( string selection )
2061 {
2062 switch( selection )
2063 {
2064 case "seat_driver":
2065 return "seat_con_1_1";
2066 break;
2067 case "seat_codriver":
2068 return "seat_con_2_1";
2069 break;
2070 case "seat_cargo1":
2071 return "seat_con_1_2";
2072 break;
2073 case "seat_cargo2":
2074 return "seat_con_2_2";
2075 break;
2076 }
2077
2078 return "";
2079 }
2080
2082 {
2083 return "";
2084 }
2085
2087 {
2088 return "";
2089 }
2090
2091 int GetCrewIndex( string selection )
2092 {
2093 return -1;
2094 }
2095
2096 override bool CanReachSeatFromDoors( string pSeatSelection, vector pFromPos, float pDistance = 1.0 )
2097 {
2098 string conPointName = GetDoorConditionPointFromSelection(pSeatSelection);
2099 if (conPointName.Length() > 0)
2100 {
2101 if ( MemoryPointExists(conPointName) )
2102 {
2103 vector conPointMS = GetMemoryPointPos(conPointName);
2104 vector conPointWS = ModelToWorld(conPointMS);
2105
2107 conPointWS[1] = 0;
2108 pFromPos[1] = 0;
2109
2110 if (vector.Distance(pFromPos, conPointWS) <= pDistance)
2111 {
2112 return true;
2113 }
2114 }
2115 }
2116
2117 return false;
2118 }
2119
2121 {
2122 return true;
2123 }
2124
2126 {
2127 return true;
2128 }
2129
2131 {
2132 return true;
2133 }
2134
2136 {
2137 return true;
2138 }
2139
2141 {
2142 return true;
2143 }
2144
2146 {
2147 return true;
2148 }
2149
2151 {
2152 return true;
2153 }
2154
2156 {
2157 return m_Radiator != null;
2158 }
2159
2161 {
2162 return m_Radiator;
2163 }
2164
2166 {
2167 return GetSpeedometerAbsolute() > 3.5;
2168 }
2169
2171 {
2172 return GetHandbrake() > 0.0;
2173 }
2174
2177 {
2179
2180 }
2181
2182 void SetEngineStarted(bool started)
2183 {
2184 m_EngineStarted = started;
2185 }
2186
2187 int GetCarDoorsState(string slotType)
2188 {
2189 return -1;
2190 }
2191
2193 {
2194 if (GetAnimationPhase(animation) > 0.5)
2195 {
2196 return CarDoorState.DOORS_OPEN;
2197 }
2198 else
2199 {
2200 return CarDoorState.DOORS_CLOSED;
2201 }
2202 }
2203
2205 {
2206 return "radiator";
2207 }
2208
2210 {
2211 return 2.0;
2212 }
2213
2215 {
2216 return "refill";
2217 }
2218
2220 {
2221 return 1.5;
2222 }
2223
2225 {
2226 return "carradiator";
2227 }
2228
2230 {
2231 return 2.0;
2232 }
2233
2235 {
2236 return "carradiator";
2237 }
2238
2240 {
2241 return 2.0;
2242 }
2243
2245 {
2247 if (!m_InputActionMap)
2248 {
2250 m_InputActionMap = iam;
2251 SetActions();
2252 m_CarTypeActionsMap.Insert(this.Type(), m_InputActionMap);
2253 }
2254 }
2255
2256 override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
2257 {
2259 {
2260 m_ActionsInitialize = true;
2262 }
2263
2264 actions = m_InputActionMap.Get(action_input_type);
2265 }
2266
2268 {
2275 }
2276
2277 void AddAction(typename actionName)
2278 {
2279 ActionBase action = ActionManagerBase.GetAction(actionName);
2280
2281 if (!action)
2282 {
2283 Debug.LogError("Action " + actionName + " dosn't exist!");
2284 return;
2285 }
2286
2287 typename ai = action.GetInputType();
2288 if (!ai)
2289 {
2290 m_ActionsInitialize = false;
2291 return;
2292 }
2293 array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
2294
2295 if (!action_array)
2296 {
2297 action_array = new array<ActionBase_Basic>;
2298 m_InputActionMap.Insert(ai, action_array);
2299 }
2300
2302 {
2303 Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action" );
2304 }
2305 action_array.Insert(action);
2306 }
2307
2308 void RemoveAction(typename actionName)
2309 {
2310 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
2311 ActionBase action = player.GetActionManager().GetAction(actionName);
2312 typename ai = action.GetInputType();
2313 array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai);
2314
2315 if (action_array)
2316 {
2317 action_array.RemoveItem(action);
2318 }
2319 }
2320
2321 override bool IsInventoryVisible()
2322 {
2323 return ( GetGame().GetPlayer() && ( !GetGame().GetPlayer().GetCommand_Vehicle() || GetGame().GetPlayer().GetCommand_Vehicle().GetTransport() == this ) );
2324 }
2325
2326 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
2327 {
2328 super.EEHealthLevelChanged(oldLevel,newLevel,zone);
2329
2330 if (newLevel == GameConstants.STATE_RUINED && oldLevel != newLevel)
2331 {
2332 bool dummy;
2333 switch ( zone )
2334 {
2335 case "WindowLR":
2336 case "WindowRR":
2337 if (m_Initialized)
2338 {
2339 PlaySoundEx("offroad_hit_window_small_SoundSet", m_WindowSmall, dummy);
2340 }
2341 break;
2342
2343 case "WindowFront":
2344 case "WindowBack":
2345 case "WindowFrontLeft":
2346 case "WindowFrontRight":
2347 if (m_Initialized)
2348 {
2349 PlaySoundEx("offroad_hit_window_large_SoundSet", m_WindowLarge, dummy);
2350 }
2351 break;
2352
2353 case "Engine":
2354 #ifndef SERVER
2356 #endif
2357 break;
2358 }
2359 }
2360 }
2361
2362 override void EEOnCECreate()
2363 {
2364
2365 float maxVolume = GetFluidCapacity( CarFluid.FUEL );
2366 float amount = Math.RandomFloat(0.0, maxVolume * 0.35 );
2367
2368 Fill( CarFluid.FUEL, amount );
2369 }
2370
2372 {
2374 {
2375 m_ForceUpdateLights = true;
2376 SetSynchDirty();
2377 }
2378 }
2379
2381 {
2383 {
2384 m_ForceUpdateLights = false;
2385 SetSynchDirty();
2386 }
2387 }
2388
2389 //Get the engine start battery consumption
2391 {
2392 return m_BatteryConsume;
2393 }
2394
2396 {
2398 }
2399
2401 {
2402 return -m_BatteryRecharge;
2403 }
2404
2406 {
2407 if (IsVitalCarBattery())
2408 {
2409 return ItemBase.Cast(FindAttachmentBySlotName("CarBattery"));
2410 }
2411 else if (IsVitalTruckBattery())
2412 {
2413 return ItemBase.Cast(FindAttachmentBySlotName("TruckBattery"));
2414 }
2415
2416 return null;
2417 }
2418
2419 void SetCarHornState(int pState)
2420 {
2421 m_CarHornState = pState;
2422 SetSynchDirty();
2423
2424 if (GetGame().IsServer())
2425 {
2426 GenerateCarHornAINoise(pState);
2427 }
2428 }
2429
2430 protected void GenerateCarHornAINoise(int pState)
2431 {
2432 if (pState != ECarHornState.OFF)
2433 {
2435 {
2436 float noiseMultiplier = 1.0;
2437 if (pState == ECarHornState.LONG)
2438 noiseMultiplier = 2.0;
2439
2440 m_NoiseSystem.AddNoiseTarget(GetPosition(), 5, m_NoisePar, noiseMultiplier);
2441 }
2442 }
2443 }
2444
2446 {
2447 return vector.Zero;
2448 }
2449
2451 {
2452 m_EngineZoneReceivedHit = pState;
2453 SetSynchDirty();
2454 }
2455
2457 {
2459 }
2460
2462 {
2463 return GetVelocity(this).Length() * dBodyGetMass(this);
2464 }
2465
2466#ifdef DEVELOPER
2467 override protected string GetDebugText()
2468 {
2469 string debug_output = super.GetDebugText();
2470 if (GetGame().IsServer())
2471 {
2472 debug_output += m_DebugContactDamageMessage + "\n";
2473 }
2474 debug_output += "Entity momentum: " + GetMomentum();
2475
2476 return debug_output;
2477 }
2478#endif
2479
2480 protected void SpawnUniversalParts()
2481 {
2482 GetInventory().CreateInInventory("HeadlightH7");
2483 GetInventory().CreateInInventory("HeadlightH7");
2484 GetInventory().CreateInInventory("HeadlightH7");
2485 GetInventory().CreateInInventory("HeadlightH7");
2486
2487 if (IsVitalCarBattery())
2488 {
2489 GetInventory().CreateInInventory("CarBattery");
2490 GetInventory().CreateInInventory("CarBattery");
2491 }
2492
2493 if (IsVitalTruckBattery())
2494 {
2495 GetInventory().CreateInInventory("TruckBattery");
2496 GetInventory().CreateInInventory("TruckBattery");
2497 }
2498
2499 if (IsVitalRadiator())
2500 {
2501 GetInventory().CreateInInventory("CarRadiator");
2502 GetInventory().CreateInInventory("CarRadiator");
2503 }
2504
2505 if (IsVitalSparkPlug())
2506 {
2507 GetInventory().CreateInInventory("SparkPlug");
2508 GetInventory().CreateInInventory("SparkPlug");
2509 }
2510
2511 if (IsVitalGlowPlug())
2512 {
2513 GetInventory().CreateInInventory("GlowPlug");
2514 GetInventory().CreateInInventory("GlowPlug");
2515 }
2516 }
2517
2518 protected void SpawnAdditionalItems()
2519 {
2520 GetInventory().CreateInInventory("Wrench");
2521 GetInventory().CreateInInventory("LugWrench");
2522 GetInventory().CreateInInventory("Screwdriver");
2523 GetInventory().CreateInInventory("EpoxyPutty");
2524
2525 GetInventory().CreateInInventory("CanisterGasoline");
2526
2527 EntityAI ent;
2528 ItemBase container;
2529 ent = GetInventory().CreateInInventory("CanisterGasoline");
2530 if (Class.CastTo(container, ent))
2531 {
2532 container.SetLiquidType(LIQUID_WATER, true);
2533 }
2534
2535 ent = GetInventory().CreateInInventory("Blowtorch");
2536 if (ent)
2537 {
2538 ent.GetInventory().CreateInInventory("LargeGasCanister");
2539 }
2540
2541 ent = GetInventory().CreateInInventory("Blowtorch");
2542 if (ent)
2543 {
2544 ent.GetInventory().CreateInInventory("LargeGasCanister");
2545 }
2546 }
2547
2548 protected void FillUpCarFluids()
2549 {
2550 Fill(CarFluid.FUEL, 200.0);
2551 Fill(CarFluid.COOLANT, 200.0);
2552 Fill(CarFluid.OIL, 200.0);
2553 }
2554}
eBleedingSourceType GetType()
void ActionBase()
Definition ActionBase.c:73
CarHornActionData ActionData ActionCarHornShort()
void ActionManagerBase(PlayerBase player)
map< typename, ref array< ActionBase_Basic > > TInputActionMap
ref NoiseParams m_NoisePar
TInputActionMap m_InputActionMap
void AddAction(typename actionName)
override void GetActions(typename action_input_type, out array< ActionBase_Basic > actions)
bool m_ActionsInitialize
class PASBroadcaster extends AdvancedCommunication IsInventoryVisible
void RemoveAction(typename actionName)
void InitializeActions()
int m_DamageType
override void EEItemDetached(EntityAI item, string slot_name)
override void EEItemAttached(EntityAI item, string slot_name)
CarAutomaticGearboxMode
Enumerated automatic gearbox modes. (native, do not change or extend)
Definition Car.c:69
CarSoundCtrl
Car's sound controller list. (native, do not change or extend)
Definition Car.c:4
CarFluid
Type of vehicle's fluid. (native, do not change or extend)
Definition Car.c:19
CarGearboxType
Enumerated gearbox types. (native, do not change or extend)
Definition Car.c:35
protected vector m_exhaustPtcDir
Definition CarScript.c:193
void CreateCarDestroyedEffect()
Definition CarScript.c:549
protected vector m_side_1_1Pos
Definition CarScript.c:202
void SetEngineStarted(bool started)
Definition CarScript.c:2182
void OnBrakesPressed()
Definition CarScript.c:925
static const int SELECTION_ID_TAIL_LIGHT_R
Definition CarScript.c:266
protected void CheckVitalItem(bool isVital, string itemName)
Definition CarScript.c:1934
string m_CarSeatShiftInSound
Definition CarScript.c:216
enum CarDoorState START_NO_BATTERY
enum CarDoorState START_NO_FUEL
CarDoorState TranslateAnimationPhaseToCarDoorState(string animation)
Definition CarScript.c:2192
protected bool m_EngineBeforeStart
Definition CarScript.c:269
float GetEnviroHeatComfortOverride()
DEPRECATED
ItemBase GetBattery()
Definition CarScript.c:2405
private ref EffectSound m_PreStartSound
Definition CarScript.c:226
protected bool m_EngineStartDoOnce
Definition CarScript.c:270
CarDoorState
Definition CarScript.c:2
@ DOORS_CLOSED
Definition CarScript.c:5
@ DOORS_MISSING
Definition CarScript.c:3
@ DOORS_OPEN
Definition CarScript.c:4
protected void BrakesRearLight()
Definition CarScript.c:1760
protected vector m_side_2_1Pos
Definition CarScript.c:204
protected void SpawnUniversalParts()
Definition CarScript.c:2480
protected void TailLightsShineOn()
Definition CarScript.c:1866
float GetActionDistanceBrakes()
Definition CarScript.c:2239
string m_EngineStartOK
Sounds.
Definition CarScript.c:208
protected void BrakeLightsShineOff()
Definition CarScript.c:1855
void PlayCrashHeavySound()
Definition CarScript.c:2021
vector GetEnginePosWS()
Definition CarScript.c:433
static string m_RightHeadlightPoint
Definition CarScript.c:252
protected void LeakFluid(CarFluid fluid)
Definition CarScript.c:1947
enum CarDoorState m_CarTypeActionsMap
override int Get3rdPersonCameraType()
camera type
Definition CarScript.c:2176
protected vector m_exhaustPtcPos
Definition CarScript.c:192
protected bool m_PlayCrashSoundHeavy
Definition CarScript.c:233
protected void RightFrontLightShineOff()
Definition CarScript.c:1812
protected void RightFrontLightShineOn()
Definition CarScript.c:1792
float GetBatteryRuntimeConsumption()
Definition CarScript.c:2395
enum CarDoorState NONE
protected void TailLightsShineOff()
Definition CarScript.c:1891
float GetBatteryConsumption()
Definition CarScript.c:2390
protected float m_FuelAmmount
keeps ammount of each fluid
Definition CarScript.c:153
protected vector m_coolantPtcPos
Definition CarScript.c:195
void UpdateLightsServer(int newGear=-1)
Definition CarScript.c:1643
protected ref EffVehicleSmoke m_coolantFx
Particles.
Definition CarScript.c:184
static string m_DrownEnginePoint
Definition CarScript.c:255
override bool OnBeforeEngineStart()
Definition CarScript.c:1403
protected void FillUpCarFluids()
Definition CarScript.c:2548
string m_CarDoorCloseSound
Definition CarScript.c:215
void ~CarScript()
Definition CarScript.c:500
void SetEngineZoneReceivedHit(bool pState)
Definition CarScript.c:2450
ref EffectSound m_WindowLarge
Definition CarScript.c:225
enum CarDoorState LONG
static string m_LeftHeadlightPoint
Definition CarScript.c:251
protected float m_BrakeAmmount
Definition CarScript.c:156
protected float m_DrownTime
Definition CarScript.c:164
void ForceUpdateLightsStart()
Definition CarScript.c:2371
void PlayCrashLightSound()
Definition CarScript.c:2002
static string m_ReverseLightPoint
Definition CarScript.c:250
void DamageCrew(float dmg)
Responsible for damaging crew in a car crash.
Definition CarScript.c:1147
static const int SELECTION_ID_BRAKE_LIGHT_R
Definition CarScript.c:262
void ForceUpdateLightsEnd()
Definition CarScript.c:2380
void CleanupSound(EffectSound sound)
Definition CarScript.c:526
ref EffectSound m_WindowSmall
Definition CarScript.c:224
static const int SELECTION_ID_REVERSE_LIGHT_L
Definition CarScript.c:263
string m_EngineStartBattery
Definition CarScript.c:209
protected bool m_EngineStarted
Definition CarScript.c:241
protected void ReverseLightsShineOff()
Definition CarScript.c:1833
protected int m_CarHornState
Definition CarScript.c:244
protected int m_exhaustPtcFx
Definition CarScript.c:190
enum CarDoorState STOP_OK
protected float m_BatteryContinuousConsume
Definition CarScript.c:177
protected float m_FuelTankHealth
Definition CarScript.c:170
static string m_LeftHeadlightTargetPoint
Definition CarScript.c:253
protected vector m_enginePtcPos
Definition CarScript.c:194
enum CarDoorState SHORT
enum CarDoorState LEFT
protected float m_OilAmmount
Definition CarScript.c:155
vector GetRefillPointPosWS()
Definition CarScript.c:443
protected vector m_enginePos
Definition CarScript.c:199
bool GetCrashHeavySound()
Definition CarScript.c:2007
string GetActionCompNameCoolant()
Definition CarScript.c:2204
protected vector m_backPos
Definition CarScript.c:201
protected bool m_HeadlightsState
Definition CarScript.c:236
void CheckContactCache()
Responsible for damaging the car according to contact events from OnContact.
Definition CarScript.c:1047
static float DROWN_ENGINE_DAMAGE
Definition CarScript.c:148
string GetActionCompNameBrakes()
Definition CarScript.c:2234
protected void HandleDoorsSound(string animSource, float phase)
Definition CarScript.c:1232
string m_EngineStartPlug
Definition CarScript.c:210
protected void GenerateCarHornAINoise(int pState)
Definition CarScript.c:2430
protected void BrakeLightsShineOn()
Definition CarScript.c:1844
protected float m_EnviroHeatComfortOverride
Definition CarScript.c:161
protected void SpawnAdditionalItems()
Definition CarScript.c:2518
protected bool m_ForceUpdateLights
Definition CarScript.c:240
ref EffectSound m_CrashSoundHeavy
Definition CarScript.c:223
void SetCarHornState(int pState)
Definition CarScript.c:2419
static const int SELECTION_ID_BRAKE_LIGHT_L
Definition CarScript.c:261
override void OnFluidChanged(CarFluid fluid, float newValue, float oldValue)
Definition CarScript.c:1375
override vector GetDefaultHitPosition()
Definition CarScript.c:2445
bool IsHandbrakeActive()
Definition CarScript.c:2170
void UpdateLightsClient(int newGear=-1)
Definition CarScript.c:1524
bool IsMoving()
Definition CarScript.c:2165
vector Get_1_2PointPosWS()
Definition CarScript.c:464
string m_EngineStartFuel
Definition CarScript.c:211
void CleanupEffects()
Definition CarScript.c:507
void PlaySoundEx(string soundset, EffectSound sound, out bool soundbool)
Definition CarScript.c:2026
protected void ReverseLightsShineOn()
Definition CarScript.c:1822
protected EntityAI m_Radiator
Definition CarScript.c:174
string m_CarHornShortSoundName
Definition CarScript.c:219
protected bool m_EngineZoneReceivedHit
Definition CarScript.c:272
static const int SELECTION_ID_FRONT_LIGHT_R
Definition CarScript.c:260
vector Get_2_2PointPosWS()
Definition CarScript.c:472
protected bool m_RearLightType
Definition CarScript.c:238
protected void LeftFrontLightShineOff()
Definition CarScript.c:1802
protected float m_dmgContactCoef
Definition CarScript.c:160
protected float m_BatteryHealth
Definition CarScript.c:171
protected vector m_side_1_2Pos
Definition CarScript.c:203
void UpdateLights(int new_gear=-1)
Definition CarScript.c:1516
bool HasRadiator()
Definition CarScript.c:2155
static float DROWN_ENGINE_THRESHOLD
Definition CarScript.c:147
static const int SELECTION_ID_FRONT_LIGHT_L
Definition CarScript.c:259
float GetMomentum()
Definition CarScript.c:2461
static string m_RightHeadlightTargetPoint
Definition CarScript.c:254
protected float m_PlugHealth
Definition CarScript.c:172
vector Get_1_1PointPosWS()
Definition CarScript.c:460
enum CarDoorState STARTING
float GetActionDistanceFuel()
Definition CarScript.c:2219
protected void LeftFrontLightShineOn()
Definition CarScript.c:1782
protected bool m_HeadlightsOn
Definition CarScript.c:235
override void OnGearChanged(int newGear, int oldGear)
Definition CarScript.c:1461
private const float BATTERY_UPDATE_DELAY
Definition CarScript.c:180
float GetActionDistanceOil()
Definition CarScript.c:2229
string GetActionCompNameOil()
Definition CarScript.c:2224
bool HasEngineZoneReceivedHit()
Definition CarScript.c:2456
float GetActionDistanceCoolant()
Definition CarScript.c:2209
static const string MEMORY_POINT_NAME_CAR_HORN
Definition CarScript.c:150
protected int m_enginePtcFx
Definition CarScript.c:188
vector GetEnginePointPosWS()
Definition CarScript.c:448
vector GetCoolantPtcPosWS()
Definition CarScript.c:438
protected int m_coolantPtcFx
Definition CarScript.c:189
static const int SELECTION_ID_TAIL_LIGHT_L
Definition CarScript.c:265
enum CarDoorState OFF
vector GetFrontPointPosWS()
Definition CarScript.c:452
void ToggleHeadlights()
Switches headlights on/off, including the illumination of the control panel and synchronizes this cha...
Definition CarScript.c:1510
enum CarDoorState REVERSE_ONLY
protected void HandleSeatAdjustmentSound(string animSource, float phase)
Definition CarScript.c:1255
float GetBatteryRechargeRate()
Definition CarScript.c:2400
protected float m_EngineHealth
Definition CarScript.c:168
enum CarDoorState START_OK
protected void BrakeAndReverseRearLight()
Definition CarScript.c:1770
protected void CarPartsHealthCheck()
Definition CarScript.c:1970
protected void ReverseRearLight()
Definition CarScript.c:1765
protected float m_CoolantAmmount
Definition CarScript.c:154
protected ref EffVehicleSmoke m_engineFx
Definition CarScript.c:185
override bool CanReachSeatFromDoors(string pSeatSelection, vector pFromPos, float pDistance=1.0)
Definition CarScript.c:2096
string m_CarHornLongSoundName
Definition CarScript.c:220
protected bool m_EngineDestroyed
Definition CarScript.c:242
protected vector m_side_2_2Pos
Definition CarScript.c:205
protected void DashboardShineOn()
Definition CarScript.c:1902
override void OnContact(string zoneName, vector localPos, IEntity other, Contact data)
WARNING: Can be called very frequently in one frame, use with caution.
Definition CarScript.c:1018
vector GetBackPointPosWS()
Definition CarScript.c:456
enum CarDoorState RIGHT
CarRearLightBase m_RearLight
Definition CarScript.c:247
enum CarDoorState BRAKES_ONLY
protected ref EffectSound m_CarHornSoundEffect
Definition CarScript.c:228
protected ref EffVehicleSmoke m_exhaustFx
Definition CarScript.c:186
ref EffectSound m_CrashSoundLight
Definition CarScript.c:222
string m_EngineStopFuel
Definition CarScript.c:212
bool OnBeforeSwitchLights(bool toOn)
Definition CarScript.c:1498
protected float m_RadiatorHealth
Definition CarScript.c:169
string GetActionCompNameFuel()
Definition CarScript.c:2214
void SynchCrashHeavySound(bool play)
Definition CarScript.c:2012
private float m_BatteryTimer
Definition CarScript.c:179
protected float m_MomentumPrevTick
Definition CarScript.c:141
protected void DashboardShineOff()
Definition CarScript.c:1912
void OnBrakesReleased()
Definition CarScript.c:930
protected vector m_fuelPos
Definition CarScript.c:197
protected bool m_BrakesArePressed
Definition CarScript.c:237
EntityAI GetRadiator()
Definition CarScript.c:2160
void UpdateHeadlightState()
Definition CarScript.c:611
void SynchCrashLightSound(bool play)
Definition CarScript.c:1993
bool GetCrashLightSound()
Definition CarScript.c:1988
protected vector m_VelocityPrevTick
Definition CarScript.c:142
protected float m_BatteryEnergyStartMin
Definition CarScript.c:181
vector Get_2_1PointPosWS()
Definition CarScript.c:468
override float GetLiquidThroughputCoef()
Definition CarScript.c:477
string m_CarSeatShiftOutSound
Definition CarScript.c:217
protected NoiseSystem m_NoiseSystem
Definition CarScript.c:230
static const int SELECTION_ID_DASHBOARD_LIGHT
Definition CarScript.c:267
protected float m_BatteryRecharge
Definition CarScript.c:178
protected void HandleCarHornSound(ECarHornState pState)
Definition CarScript.c:1275
protected void NoRearLight()
Definition CarScript.c:1776
void HandleEngineSound(CarEngineSoundState state)
Definition CarScript.c:1291
enum CarDoorState START_NO_SPARKPLUG
static const int SELECTION_ID_REVERSE_LIGHT_R
Definition CarScript.c:264
bool IsScriptedLightsOn()
Propper way to get if light is swiched on. Use instead of IsLightsOn().
Definition CarScript.c:1504
protected bool m_PlayCrashSoundLight
Definition CarScript.c:232
string m_CarDoorOpenSound
Definition CarScript.c:214
protected float m_BatteryConsume
Definition CarScript.c:176
bool IsVitalFuelTank()
Definition CarScript.c:2150
static vector m_DrownEnginePos
Definition CarScript.c:165
ref CarContactCache m_ContactCache
Definition CarScript.c:143
protected vector m_frontPos
Definition CarScript.c:200
CarLightBase m_Headlight
Definition CarScript.c:246
void Synchronize()
DamageType
exposed from C++ (do not change)
ERPCs
Definition ERPCs.c:2
override void EEKilled(Object killer)
override void EEDelete(EntityAI parent)
override void OnAttachmentRuined(EntityAI attachment)
void PlaySound()
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight)
Definition ItemBase.c:7044
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition ItemBase.c:6447
override void EEOnCECreate()
Called when entity is being created as new by CE/ Debug.
Definition ItemBase.c:8594
override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
Definition ItemBase.c:6015
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition ItemBase.c:8662
string Type
override void OnVariablesSynchronized()
PlayerBase GetPlayer()
string GetDebugText()
class NoiseSystem NoiseParams()
Definition Noise.c:15
float GetTime()
ProcessDirectDamageFlags
Definition Object.c:2
WaveKind
Definition Sound.c:2
protected float m_Time
protected bool m_Initialized
class JsonUndergroundAreaTriggerData GetPosition
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
void RPCSingleParam(Object target, int rpc_type, Param param, bool guaranteed, PlayerIdentity recipient=null)
see CGame.RPC
Definition Game.c:882
proto native NoiseSystem GetNoiseSystem()
proto int GetTime()
returns mission time in milliseconds
override int GetCarDoorsState(string slotType)
override void EOnPostSimulate(IEntity other, float timeSlice)
override bool IsVitalCarBattery()
override bool IsVitalGlowPlug()
override bool IsVitalRadiator()
Definition Offroad_02.c:385
override CarLightBase CreateFrontLight()
override CarRearLightBase CreateRearLight()
override void EEInit()
override float OnSound(CarSoundCtrl ctrl, float oldValue)
override bool IsVitalTruckBattery()
override int GetCrewIndex(string selection)
override bool CanReleaseAttachment(EntityAI attachment)
override void OnEngineStart()
override string GetAnimSourceFromSelection(string selection)
override protected bool CanManipulateSpareWheel(string slotSelectionName)
override string GetDoorConditionPointFromSelection(string selection)
override bool IsVitalSparkPlug()
Definition Offroad_02.c:380
override string GetDoorSelectionNameFromSeatPos(int posIdx)
override string GetDoorInvSlotNameFromSeatPos(int posIdx)
override bool IsVitalEngineBelt()
override void OnAnimationPhaseStarted(string animSource, float phase)
override void SetActions()
override void OnEngineStop()
Super root of all classes in Enforce script.
Definition EnScript.c:11
static const int DAYZCAMERA_3RD_VEHICLE
generic vehicle 3rd person
Definition Debug.c:14
static void ActionLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:138
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:235
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
void SetParticleStateHeavy()
void SetParticleStateLight()
Definition VehicleSmoke.c:9
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
bool SoundPlay()
Plays sound.
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
InventoryLocation.
proto native EntityAI GetParent()
returns parent of current inventory location
proto native int GetSlot()
returns slot id if current type is Attachment
provides access to slot configuration
static proto bool GetSelectionForSlotId(int slot_Id, out string selection)
static bool IsActionLogEnable()
Definition Debug.c:590
Definition EnMath.c:7
proto void AddNoiseTarget(vector pos, float lifetime, NoiseParams noise_params, float external_strength_multiplier=1.0)
Will make a noise at that position which the AI will "see" for the duration of 'lifetime'.
Manager class for managing Effect (EffectParticle, EffectSound)
static void Stop(int effect_id)
Stops the Effect.
static int PlayOnObject(notnull Effect eff, Object obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_relative_to_world=false)
Play an Effect.
static EffectSound CreateSound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false, bool enviroment=false)
Create an EffectSound.
static EffectSound PlaySoundCachedParams(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound, using or creating cached SoundParams.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
static bool IsEffectExist(int effect_id)
Checks whether an Effect ID is registered in SEffectManager.
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
proto void CallLater(func fn, int delay=0, bool repeat=false, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto vector Normalized()
return normalized vector (keeps orginal vector untouched)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
static const vector Zero
Definition EnConvert.c:110
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
static vector Direction(vector p1, vector p2)
Returns direction vector from point p1 to point p2.
Definition EnConvert.c:220
proto native float Length()
Returns length of vector (magnitude)
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271
proto native CGame GetGame()
const float CARS_CONTACT_DMG_MIN
Definition constants.c:733
const float CARS_CONTACT_DMG_KILLCREW
Definition constants.c:734
const float CARS_CONTACT_DMG_THRESHOLD
Definition constants.c:732
const int CARS_FLUIDS_TICK
Definition constants.c:721
float Impulse
Definition EnPhysics.c:314
proto void Print(void var)
Prints content of variable to console/log.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:45
@ CONTACT
Definition EnEntity.c:97
const float DAMAGE_RUINED_VALUE
Definition constants.c:758
const float DAMAGE_DAMAGED_VALUE
Definition constants.c:756
const int STATE_RUINED
Definition constants.c:742
const float LIQUID_THROUGHPUT_CAR_DEFAULT
Definition constants.c:511
const int LIQUID_WATER
Definition constants.c:489
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto int AbsInt(int i)
Returns absolute value.
proto native vector GetVelocity(notnull IEntity ent)
Returns linear velocity.
proto native float dBodyGetMass(notnull IEntity ent)
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
proto native int Length()
Returns length of string.
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
proto native void OnUpdate()
Definition tools.c:338
proto native HumanCommandVehicle GetCommand_Vehicle()