Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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.")]
2 class SCR_TireReplacementManagerComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class 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")]
20  protected vector m_WheelTraceOffset;
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;
51  {
52  VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(ownerEntity.FindComponent(VehicleWheeledSimulation));
53  if(!simulation)
54  return;
55 
56  wheelCount = simulation.WheelCount();
57  }
58  else
59  {
60  VehicleWheeledSimulation_SA simulation = VehicleWheeledSimulation_SA.Cast(ownerEntity.FindComponent(VehicleWheeledSimulation_SA));
61  if(!simulation)
62  return;
63 
64  wheelCount = simulation.WheelCount();
65  }
66 
67  m_aDestructionTires.Resize(wheelCount);
68  m_aDestructionTireEntities.Resize(wheelCount);
69 
70  array<Managed> slots = {};
71  ownerEntity.FindComponents(BaseSlotComponent, slots);
72 
73  BaseSlotComponent slot;
74  GenericEntity slotEntity;
75  SCR_WheelSlotComponent wheelSlotComponent;
76  SCR_SpareTireComponent spareTire;
77  foreach (Managed component : slots)
78  {
79  slot = BaseSlotComponent.Cast(component);
80  if (!slot)
81  continue;
82 
83  slotEntity = GenericEntity.Cast(slot.GetAttachedEntity());
84  if (!slotEntity)
85  continue;
86 
87  wheelSlotComponent = SCR_WheelSlotComponent.Cast(slot);
88  if(wheelSlotComponent)
89  {
90  if(wheelSlotComponent.m_iWheelIndex < 0 || wheelSlotComponent.m_iWheelIndex >= wheelCount)
91  {
92  Print("Wheel Index out of bounds. Index: " + wheelSlotComponent.m_iWheelIndex + ". WheelCount: " + wheelCount, LogLevel.NORMAL);
93  continue;
94  }
95 
96  m_aDestructionTires.Set(wheelSlotComponent.m_iWheelIndex, SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent)));
97  m_aDestructionTireEntities.Set(wheelSlotComponent.m_iWheelIndex, slotEntity);
98  }
99 
100  if(m_SpareTireComponent)
101  continue;
102 
103  spareTire = SCR_SpareTireComponent.Cast(slotEntity.FindComponent(SCR_SpareTireComponent));
104  if(spareTire)
105  {
106  m_SpareTireComponent = spareTire;
107  m_SpareTireEntity = slotEntity;
108  m_SpareDestructionTire = SCR_DestructionTireComponent.Cast(slotEntity.FindComponent(SCR_DestructionTireComponent));
109  continue;
110  }
111 
112  }
113  }
114 
115  //------------------------------------------------------------------------------------------------
119  bool CanTireBeReplaced(int pWheelIndex)
120  {
121  if (m_aDestructionTires.IsIndexValid(pWheelIndex))
122  return false;
123 
124  SCR_DestructionTireComponent destructionTire = m_aDestructionTires.Get(pWheelIndex);
125  if(!destructionTire)
126  return false;
127 
128  bool canBeShown = destructionTire.GetDamagePhase() > m_SpareDestructionTire.GetDamagePhase();
129  canBeShown |= (destructionTire.GetDamagePhase() == m_SpareDestructionTire.GetDamagePhase() && destructionTire.GetHealth() < m_SpareDestructionTire.GetHealth());
130 
131  return canBeShown;
132  }
133 
134  //------------------------------------------------------------------------------------------------
139  bool IsWheelAreaClear(int pWheelIndex, notnull IEntity pActionUser)
140  {
141  IEntity wheelEntity = m_aDestructionTireEntities.Get(pWheelIndex);
142  vector mins, maxs, mat[4];
143  pActionUser.GetWorldTransform(mat);
144  wheelEntity.GetBounds(mins, maxs);
145 
146  TraceSphere param = new TraceSphere();
147  param.Radius = m_WheelTraceRadius;
148  param.Start = wheelEntity.CoordToParent(m_WheelTraceOffset);
149  param.Flags = TraceFlags.ENTS;
150  array<IEntity> excludeArray = { pActionUser, m_Owner };
151  param.ExcludeArray = excludeArray;
152 
153  float traceResult = wheelEntity.GetWorld().TracePosition(param, null);
154 
155  #ifdef DEBUG_VEHICLES
156  int color;
157  if(traceResult >= 0)
158  color = Color.GREEN;
159  else
160  color = Color.RED;
161 
162  m_DebugShape = Shape.CreateSphere(color, ShapeFlags.VISIBLE|ShapeFlags.NOOUTLINE, wheelEntity.CoordToParent(-vector.Right * 1), 1);
163  #endif
164 
165  return traceResult >=0;
166  }
167 
168  //------------------------------------------------------------------------------------------------
171  void InitReplace(int pWheelIndex)
172  {
173  SCR_DestructionTireComponent destructionTireComponent = m_aDestructionTires.Get(pWheelIndex);
174  if(!destructionTireComponent)
175  return;
176 
177  int myDamagePhase = destructionTireComponent.GetDamagePhase();
178  float myHealth = destructionTireComponent.GetHealth();
179 
180  //TODO @Zguba Level1: Properly implement damage here. This makes no sense.
181  destructionTireComponent.GoToDamagePhase(m_SpareDestructionTire.GetDamagePhase());
182  destructionTireComponent.SetHitZoneDamage(0);
183  destructionTireComponent.GetDefaultHitZone().HandleDamage(m_SpareDestructionTire.GetHealth());
184 
185  m_SpareDestructionTire.GoToDamagePhase(myDamagePhase);
186  m_SpareDestructionTire.SetHitZoneDamage(0);
187  m_SpareDestructionTire.GetDefaultHitZone().HandleDamage(myDamage);
188  }
189  #endif
190 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_WheelTraceRadius
protected float m_WheelTraceRadius
Definition: SCR_TireReplacementManagerComponent.c:17
Attribute
SCR_TireReplacementManagerComponentClass ScriptComponentClass Attribute("0", UIWidgets.CheckBox, "If true, the user can replace an active wheel by a more damaged wheel", category:"Replacement Conditions")] protected bool m_bAllowMoreDamagedTire
SCR_TireReplacementManagerComponentClass
Definition: SCR_TireReplacementManagerComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetIsClientAuthority
override bool GetIsClientAuthority()
Definition: game.c:268
m_WheelTraceOffset
protected vector m_WheelTraceOffset
Definition: SCR_TireReplacementManagerComponent.c:20
SCR_WheelSlotComponent
Definition: SCR_WheelSlotComponent.c:7
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AIConfigComponent.c:72
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_AIConfigComponent.c:79
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180