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;
29 protected GenericEntity m_SpareTireEntity;
36 super.OnPostInit(owner);
45 GenericEntity ownerEntity = GenericEntity.Cast(owner);
51 VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(ownerEntity.
FindComponent(VehicleWheeledSimulation));
55 wheelCount = simulation.WheelCount();
57 m_aDestructionTires.Resize(wheelCount);
58 m_aDestructionTireEntities.Resize(wheelCount);
60 array<Managed> slots = {};
63 BaseSlotComponent slot;
64 GenericEntity slotEntity;
65 SCR_WheelSlotComponent wheelSlotComponent;
66 SCR_SpareTireComponent spareTire;
67 foreach (Managed component : slots)
69 slot = BaseSlotComponent.Cast(component);
73 slotEntity = GenericEntity.Cast(slot.GetAttachedEntity());
77 wheelSlotComponent = SCR_WheelSlotComponent.Cast(slot);
78 if(wheelSlotComponent)
80 if(wheelSlotComponent.m_iWheelIndex < 0 || wheelSlotComponent.m_iWheelIndex >= wheelCount)
82 Print(
"Wheel Index out of bounds. Index: " + wheelSlotComponent.m_iWheelIndex +
". WheelCount: " + wheelCount,
LogLevel.NORMAL);
86 m_aDestructionTires.Set(wheelSlotComponent.m_iWheelIndex, SCR_DestructionTireComponent.Cast(slotEntity.
FindComponent(SCR_DestructionTireComponent)));
87 m_aDestructionTireEntities.Set(wheelSlotComponent.m_iWheelIndex, slotEntity);
90 if(m_SpareTireComponent)
93 spareTire = SCR_SpareTireComponent.Cast(slotEntity.
FindComponent(SCR_SpareTireComponent));
96 m_SpareTireComponent = spareTire;
97 m_SpareTireEntity = slotEntity;
98 m_SpareDestructionTire = SCR_DestructionTireComponent.Cast(slotEntity.
FindComponent(SCR_DestructionTireComponent));
109 bool CanTireBeReplaced(
int pWheelIndex)
111 if (m_aDestructionTires.IsIndexValid(pWheelIndex))
114 SCR_DestructionTireComponent destructionTire = m_aDestructionTires.Get(pWheelIndex);
118 bool canBeShown = destructionTire.GetDamagePhase() > m_SpareDestructionTire.GetDamagePhase();
119 canBeShown |= (destructionTire.GetDamagePhase() == m_SpareDestructionTire.GetDamagePhase() && destructionTire.GetHealth() < m_SpareDestructionTire.GetHealth());
129 bool IsWheelAreaClear(
int pWheelIndex, notnull
IEntity pActionUser)
131 IEntity wheelEntity = m_aDestructionTireEntities.Get(pWheelIndex);
132 vector mins, maxs, mat[4];
133 pActionUser.GetWorldTransform(mat);
136 TraceSphere param =
new TraceSphere();
140 array<IEntity> excludeArray = { pActionUser,
m_Owner };
141 param.ExcludeArray = excludeArray;
143 float traceResult = wheelEntity.
GetWorld().TracePosition(param, null);
145 #ifdef DEBUG_VEHICLES
155 return traceResult >=0;
161 void InitReplace(
int pWheelIndex)
163 SCR_DestructionTireComponent destructionTireComponent = m_aDestructionTires.Get(pWheelIndex);
164 if(!destructionTireComponent)
167 int myDamagePhase = destructionTireComponent.GetDamagePhase();
168 float myHealth = destructionTireComponent.GetHealth();
171 destructionTireComponent.GoToDamagePhase(m_SpareDestructionTire.GetDamagePhase());
172 destructionTireComponent.SetHitZoneDamage(0);
173 destructionTireComponent.GetDefaultHitZone().HandleDamage(m_SpareDestructionTire.GetHealth());
175 m_SpareDestructionTire.GoToDamagePhase(myDamagePhase);
176 m_SpareDestructionTire.SetHitZoneDamage(0);
177 m_SpareDestructionTire.GetDefaultHitZone().HandleDamage(myDamage);
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
vector m_WheelTraceOffset
enum EVehicleType IEntity
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
proto external void GetBounds(out vector mins, out vector maxs)
proto external BaseWorld GetWorld()
proto external int FindComponents(typename typeName, notnull array< Managed > outComponents)
proto external vector CoordToParent(vector coord)
void EOnInit(IEntity owner)
Instance of created debug visualizer.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.