1 [
ComponentEditorProps(
category:
"GameScripted/Destruction", description:
"Tire destruction manager component, manages replacing destructible tires with a present spare tire.")]
9 [
Attribute(
"0", UIWidgets.CheckBox,
"If true, gizmos will be shown indicating whether or not the raycast hit any entities",
category:
"Debug")]
10 protected bool m_bDebugCanReplace;
13 [
Attribute(
"0", UIWidgets.CheckBox,
"If true, the user can replace an active wheel by a more damaged wheel",
category:
"Replacement Conditions")]
14 protected bool m_bAllowMoreDamagedTire;
16 [
Attribute(
"1", UIWidgets.Auto,
"The radius of the tracesphere, used to check whether or not the area is clear for replacing",
category:
"Replacement Conditions")]
19 [
Attribute(
"", UIWidgets.Auto,
"The radius of the tracesphere, used to check whether or not the area is clear for replacing",
category:
"Replacement Conditions")]
22 #ifdef ENABLE_DESTRUCTION
23 protected ref Shape m_DebugShape;
24 protected ref array<SCR_DestructionTireComponent> m_aDestructionTires = {};
25 protected ref array<GenericEntity> m_aDestructionTireEntities = {};
27 protected SCR_SpareTireComponent m_SpareTireComponent;
28 protected SCR_DestructionTireComponent m_SpareDestructionTire;
36 super.OnPostInit(owner);
38 SetEventMask(owner, EntityEvent.INIT);
42 override void EOnInit(IEntity owner)
52 VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(ownerEntity.FindComponent(VehicleWheeledSimulation));
56 wheelCount = simulation.WheelCount();
60 VehicleWheeledSimulation_SA simulation = VehicleWheeledSimulation_SA.Cast(ownerEntity.FindComponent(VehicleWheeledSimulation_SA));
64 wheelCount = simulation.WheelCount();
67 m_aDestructionTires.Resize(wheelCount);
68 m_aDestructionTireEntities.Resize(wheelCount);
70 array<Managed> slots = {};
71 ownerEntity.FindComponents(BaseSlotComponent, slots);
73 BaseSlotComponent slot;
76 SCR_SpareTireComponent spareTire;
77 foreach (Managed component : slots)
79 slot = BaseSlotComponent.Cast(component);
88 if(wheelSlotComponent)
90 if(wheelSlotComponent.m_iWheelIndex < 0 || wheelSlotComponent.m_iWheelIndex >= wheelCount)
92 Print(
"Wheel Index out of bounds. Index: " + wheelSlotComponent.m_iWheelIndex +
". WheelCount: " + wheelCount, LogLevel.NORMAL);
96 m_aDestructionTires.Set(wheelSlotComponent.m_iWheelIndex, SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent)));
97 m_aDestructionTireEntities.Set(wheelSlotComponent.m_iWheelIndex, slotEntity);
100 if(m_SpareTireComponent)
103 spareTire = SCR_SpareTireComponent.Cast(slotEntity.FindComponent(SCR_SpareTireComponent));
106 m_SpareTireComponent = spareTire;
107 m_SpareTireEntity = slotEntity;
108 m_SpareDestructionTire = SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent));
119 bool CanTireBeReplaced(
int pWheelIndex)
121 if (m_aDestructionTires.IsIndexValid(pWheelIndex))
124 SCR_DestructionTireComponent destructionTire = m_aDestructionTires.Get(pWheelIndex);
128 bool canBeShown = destructionTire.GetDamagePhase() > m_SpareDestructionTire.GetDamagePhase();
129 canBeShown |= (destructionTire.GetDamagePhase() == m_SpareDestructionTire.GetDamagePhase() && destructionTire.GetHealth() < m_SpareDestructionTire.GetHealth());
139 bool IsWheelAreaClear(
int pWheelIndex, notnull IEntity pActionUser)
141 IEntity wheelEntity = m_aDestructionTireEntities.Get(pWheelIndex);
142 vector mins, maxs, mat[4];
143 pActionUser.GetWorldTransform(mat);
144 wheelEntity.GetBounds(mins, maxs);
146 TraceSphere param =
new TraceSphere();
149 param.Flags = TraceFlags.ENTS;
150 array<IEntity> excludeArray = { pActionUser,
m_Owner };
151 param.ExcludeArray = excludeArray;
153 float traceResult = wheelEntity.GetWorld().TracePosition(param,
null);
155 #ifdef DEBUG_VEHICLES
162 m_DebugShape = Shape.CreateSphere(color, ShapeFlags.VISIBLE|ShapeFlags.NOOUTLINE, wheelEntity.CoordToParent(-vector.Right * 1), 1);
165 return traceResult >=0;
171 void InitReplace(
int pWheelIndex)
173 SCR_DestructionTireComponent destructionTireComponent = m_aDestructionTires.Get(pWheelIndex);
174 if(!destructionTireComponent)
177 int myDamagePhase = destructionTireComponent.GetDamagePhase();
178 float myHealth = destructionTireComponent.GetHealth();
181 destructionTireComponent.GoToDamagePhase(m_SpareDestructionTire.GetDamagePhase());
182 destructionTireComponent.SetHitZoneDamage(0);
183 destructionTireComponent.GetDefaultHitZone().HandleDamage(m_SpareDestructionTire.GetHealth());
185 m_SpareDestructionTire.GoToDamagePhase(myDamagePhase);
186 m_SpareDestructionTire.SetHitZoneDamage(0);
187 m_SpareDestructionTire.GetDefaultHitZone().HandleDamage(myDamage);