Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TireReplacementManagerComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Destruction", description: "Tire destruction manager component, manages replacing destructible tires with a present spare tire.")]
5
6class SCR_TireReplacementManagerComponent : ScriptComponent
7{
8 #ifdef DEBUG_VEHICLES
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;
11 #endif
12
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;
15
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")]
17 protected float m_WheelTraceRadius;
18
19 [Attribute("", UIWidgets.Auto, "The radius of the tracesphere, used to check whether or not the area is clear for replacing", category: "Replacement Conditions")]
21
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 = {};
26
27 protected SCR_SpareTireComponent m_SpareTireComponent;
28 protected SCR_DestructionTireComponent m_SpareDestructionTire;
29 protected GenericEntity m_SpareTireEntity;
30
31 protected IEntity m_Owner;
32
33 //------------------------------------------------------------------------------------------------
34 override void OnPostInit(IEntity owner)
35 {
36 super.OnPostInit(owner);
37
38 SetEventMask(owner, EntityEvent.INIT);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 override void EOnInit(IEntity owner)
43 {
44 m_Owner = owner;
45 GenericEntity ownerEntity = GenericEntity.Cast(owner);
46 if(!ownerEntity)
47 return;
48
49 int wheelCount = 0;
50
51 VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(ownerEntity.FindComponent(VehicleWheeledSimulation));
52 if(!simulation)
53 return;
54
55 wheelCount = simulation.WheelCount();
56
57 m_aDestructionTires.Resize(wheelCount);
58 m_aDestructionTireEntities.Resize(wheelCount);
59
60 array<Managed> slots = {};
61 ownerEntity.FindComponents(BaseSlotComponent, slots);
62
63 BaseSlotComponent slot;
64 GenericEntity slotEntity;
65 SCR_WheelSlotComponent wheelSlotComponent;
66 SCR_SpareTireComponent spareTire;
67 foreach (Managed component : slots)
68 {
69 slot = BaseSlotComponent.Cast(component);
70 if (!slot)
71 continue;
72
73 slotEntity = GenericEntity.Cast(slot.GetAttachedEntity());
74 if (!slotEntity)
75 continue;
76
77 wheelSlotComponent = SCR_WheelSlotComponent.Cast(slot);
78 if(wheelSlotComponent)
79 {
80 if(wheelSlotComponent.m_iWheelIndex < 0 || wheelSlotComponent.m_iWheelIndex >= wheelCount)
81 {
82 Print("Wheel Index out of bounds. Index: " + wheelSlotComponent.m_iWheelIndex + ". WheelCount: " + wheelCount, LogLevel.NORMAL);
83 continue;
84 }
85
86 m_aDestructionTires.Set(wheelSlotComponent.m_iWheelIndex, SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent)));
87 m_aDestructionTireEntities.Set(wheelSlotComponent.m_iWheelIndex, slotEntity);
88 }
89
90 if(m_SpareTireComponent)
91 continue;
92
93 spareTire = SCR_SpareTireComponent.Cast(slotEntity.FindComponent(SCR_SpareTireComponent));
94 if(spareTire)
95 {
96 m_SpareTireComponent = spareTire;
97 m_SpareTireEntity = slotEntity;
98 m_SpareDestructionTire = SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent));
99 continue;
100 }
101
102 }
103 }
104
105 //------------------------------------------------------------------------------------------------
109 bool CanTireBeReplaced(int pWheelIndex)
110 {
111 if (m_aDestructionTires.IsIndexValid(pWheelIndex))
112 return false;
113
114 SCR_DestructionTireComponent destructionTire = m_aDestructionTires.Get(pWheelIndex);
115 if(!destructionTire)
116 return false;
117
118 bool canBeShown = destructionTire.GetDamagePhase() > m_SpareDestructionTire.GetDamagePhase();
119 canBeShown |= (destructionTire.GetDamagePhase() == m_SpareDestructionTire.GetDamagePhase() && destructionTire.GetHealth() < m_SpareDestructionTire.GetHealth());
120
121 return canBeShown;
122 }
123
124 //------------------------------------------------------------------------------------------------
129 bool IsWheelAreaClear(int pWheelIndex, notnull IEntity pActionUser)
130 {
131 IEntity wheelEntity = m_aDestructionTireEntities.Get(pWheelIndex);
132 vector mins, maxs, mat[4];
133 pActionUser.GetWorldTransform(mat);
134 wheelEntity.GetBounds(mins, maxs);
135
136 TraceSphere param = new TraceSphere();
137 param.Radius = m_WheelTraceRadius;
138 param.Start = wheelEntity.CoordToParent(m_WheelTraceOffset);
139 param.Flags = TraceFlags.ENTS;
140 array<IEntity> excludeArray = { pActionUser, m_Owner };
141 param.ExcludeArray = excludeArray;
142
143 float traceResult = wheelEntity.GetWorld().TracePosition(param, null);
144
145 #ifdef DEBUG_VEHICLES
146 int color;
147 if(traceResult >= 0)
148 color = Color.GREEN;
149 else
150 color = Color.RED;
151
152 m_DebugShape = Shape.CreateSphere(color, ShapeFlags.VISIBLE|ShapeFlags.NOOUTLINE, wheelEntity.CoordToParent(-vector.Right * 1), 1);
153 #endif
154
155 return traceResult >=0;
156 }
157
158 //------------------------------------------------------------------------------------------------
161 void InitReplace(int pWheelIndex)
162 {
163 SCR_DestructionTireComponent destructionTireComponent = m_aDestructionTires.Get(pWheelIndex);
164 if(!destructionTireComponent)
165 return;
166
167 int myDamagePhase = destructionTireComponent.GetDamagePhase();
168 float myHealth = destructionTireComponent.GetHealth();
169
170 //TODO @Zguba Level1: Properly implement damage here. This makes no sense.
171 destructionTireComponent.GoToDamagePhase(m_SpareDestructionTire.GetDamagePhase());
172 destructionTireComponent.SetHitZoneDamage(0);
173 destructionTireComponent.GetDefaultHitZone().HandleDamage(m_SpareDestructionTire.GetHealth());
174
175 m_SpareDestructionTire.GoToDamagePhase(myDamagePhase);
176 m_SpareDestructionTire.SetHitZoneDamage(0);
177 m_SpareDestructionTire.GetDefaultHitZone().HandleDamage(myDamage);
178 }
179 #endif
180}
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
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.
Definition Shape.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
TraceFlags
Definition TraceFlags.c:13