11 static string particle_attribute_descriptions =
"Select particle effect for driving on this surface type.";
12 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
14 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
15 ResourceName m_Gravel;
16 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
18 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
19 ResourceName m_Default;
20 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
22 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
23 ResourceName m_Asphalt;
24 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
26 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
28 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
30 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
31 ResourceName m_Concrete;
32 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
34 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
36 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
37 ResourceName m_Rubber;
38 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
40 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
42 [
Attribute(
"", UIWidgets.ResourceNamePicker, particle_attribute_descriptions )]
43 ResourceName m_Plastic;
45 [
Attribute(
"", UIWidgets.Coords,
"Orientation of the effect relative to the vehicle" )]
46 vector m_vLocalOrientation;
48 [
Attribute(
"", UIWidgets.Coords,
"Position of the effect relative to the object" )]
49 vector m_vLocalOffset;
51 [
Attribute(
"", UIWidgets.EditBox,
"Minimal speed (km/h) which triggers the dust effect and its interpolation from 0%" )]
52 float m_fDustStartSpeed;
54 [
Attribute(
"", UIWidgets.EditBox,
"Speed (km/h) which tops the effect's interpolation at 100% values" )]
55 float m_fDustTopSpeed;
56 VehicleWheeledSimulation m_VehicleWheeledSimulation;
59 SignalsManagerComponent m_SignalManagerComp;
60 ref map<int, ResourceName> surface_particles =
new map<int, ResourceName>();
61 int m_iCurrentSurfaceID;
62 int m_iSurfaceSignalID = -1;
66 float m_fCurrentUpdateDelay;
67 const float TICK_TIME_DELAY_MAX = 2;
68 const float TICK_DELAY_RANGE_START = 15;
69 const float TICK_DELAY_RANGE_END = 100;
71 override void OnPostInit(IEntity owner)
73 super.OnPostInit(owner);
76 if (System.IsConsoleApp())
81 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
85 override void EOnInit(IEntity owner)
90 if (surface_particles.Count() == 0)
91 RegisterSurfaceTypes();
98 m_SignalManagerComp = SignalsManagerComponent.Cast(generic_entity.FindComponent(SignalsManagerComponent));
100 m_VehicleWheeledSimulation = VehicleWheeledSimulation.Cast(generic_entity.FindComponent(VehicleWheeledSimulation));
110 owner.GetTransform(mat);
111 m_Effect.SetTransform(mat);
112 owner.AddChild(m_Effect, 0);
119 void RegisterSurfaceTypes()
123 surface_particles.Insert(31, m_Grass);
124 surface_particles.Insert(21, m_Dirt);
125 surface_particles.Insert(25, m_Gravel);
126 surface_particles.Insert(51, m_Wood);
127 surface_particles.Insert(11, m_Asphalt);
128 surface_particles.Insert(41, m_Snow);
129 surface_particles.Insert(28, m_Sand);
130 surface_particles.Insert(61, m_Metal);
131 surface_particles.Insert(12, m_Concrete);
132 surface_particles.Insert(23, m_Soil);
133 surface_particles.Insert(15, m_Stone);
134 surface_particles.Insert(27, m_Stone);
135 surface_particles.Insert(72, m_Rubber);
136 surface_particles.Insert(91, m_Flesh);
137 surface_particles.Insert(71, m_Glass);
138 surface_particles.Insert(73, m_Plastic);
141 override void EOnFrame(IEntity owner,
float timeSlice)
146 vector camera_transform[4];
147 GetGame().GetWorld().GetCurrentCamera(camera_transform);
148 vector camera_world_pos = camera_transform[3];
149 vector relative_pos = camera_world_pos - owner.GetOrigin();
150 float distance = relative_pos.Length();
171 void UpdateEffect(IEntity owner)
175 float speed =
m_Physics.GetVelocity().Length();
178 if (speed >= m_fDustStartSpeed && m_fDustStartSpeed > 0 && m_fDustTopSpeed >= m_fDustStartSpeed)
180 int previousSurfaceID = m_iCurrentSurfaceID;
183 if (m_iSurfaceSignalID < 0)
188 if (!surface_particles)
189 RegisterSurfaceTypes();
194 m_iCurrentSurfaceID = m_iCurrentSurfaceID/100;
195 if (m_iCurrentSurfaceID >= 0 && surface_particles.Contains(m_iCurrentSurfaceID))
196 surface_type = surface_particles.Get(m_iCurrentSurfaceID);
200 if (m_Effect && previousSurfaceID == m_iCurrentSurfaceID)
203 m_Effect.UpdateVehicleDustEffect(speed, m_fDustStartSpeed, m_fDustTopSpeed);
208 m_Effect.StopEmission();
210 if (surface_type.Length() > 0)
212 ParticleEffectEntitySpawnParams spawnParams();
214 Math3D.AnglesToMatrix(m_vLocalOrientation, spawnParams.Transform);
215 spawnParams.Transform[3] = m_vLocalOffset;
216 spawnParams.Parent = owner;
217 spawnParams.UseFrameEvent =
true;
219 m_Effect =
VehicleBodyEffectBase.Cast(ParticleEffectEntity.SpawnParticleEffect(surface_type, spawnParams));
220 m_Effect.UpdateVehicleDustEffect(speed, m_fDustStartSpeed*3.6, m_fDustTopSpeed);
227 m_Effect.StopEmission();