Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIVehicleUsageComponent.c
Go to the documentation of this file.
4 INVALID, // Default value when not configured
6 GROUND_VEHICLE_WHEELED, // All wheeled ground vehicles, with weapon or not
7 GROUND_VEHICLE_TRACKED, // All tracked ground vehicles, with weapon or not
9 STATIC_WEAPON, // Static weapons which shoot directly, like static MGs
10 STATIC_ARTILLERY, // Static mortars
11
12 AIRCRAFT_HELICOPTER, // Helicopters
13 AIRCRAFT_PLANE // Planes
14}
15
16class SCR_AIVehicleUsageComponentClass : ScriptComponentClass
17{
18}
19
22
25
30{
31 [Attribute("0", UIWidgets.ComboBox, "Vehicle type from point view of AI usage", enums: ParamEnumArray.FromEnum(EAIVehicleType))]
33
34 [Attribute("1", UIWidgets.CheckBox, "Can be AI a pilot of this vehicle")]
35 protected bool m_bCanBePiloted;
36
37 protected ref ScriptInvokerBase<SCR_AIOnVehicleDeleted> m_OnDeleted;
38 protected ref ScriptInvokerBase<SCR_AIOnVehicleDamageStateChanged> m_OnDamageStateChanged;
41 protected SCR_DamageManagerComponent m_DamageManager;
42
43 //------------------------------------------------------------------------------
44 ScriptInvokerBase<SCR_AIOnVehicleDeleted> GetOnDeleted()
45 {
46 if (!m_OnDeleted)
47 m_OnDeleted = new ScriptInvokerBase<SCR_AIOnVehicleDeleted>();
48
49 return m_OnDeleted;
50 }
51
52 //------------------------------------------------------------------------------
53 ScriptInvokerBase<SCR_AIOnVehicleDamageStateChanged> GetOnDamageStateChanged()
54 {
56 m_OnDamageStateChanged = new ScriptInvokerBase<SCR_AIOnVehicleDamageStateChanged>();
57
59 }
60
65
70
71 //------------------------------------------------------------------------------
74 {
75 return m_bCanBePiloted;
76 }
77
78 //------------------------------------------------------------------------------
83
84 //------------------------------------------------------------------------------
86 {
87 return m_eVehicleType != EAIVehicleType.INVALID;
88 }
89
90 //------------------------------------------------------------------------------------------------
94 bool IsOccupiedByGroup(notnull SCR_AIGroup aiGroup)
95 {
96 array<AIAgent> members = {};
97 aiGroup.GetAgents(members);
98 foreach (AIAgent agent : members)
99 {
100 if (IsOccupiedBy(agent.GetControlledEntity()))
101 return true;
102 }
103
104 return false;
105 }
106
107 //------------------------------------------------------------------------------------------------
112 {
113 SCR_BaseCompartmentManagerComponent compartmentMananager = SCR_BaseCompartmentManagerComponent.Cast(GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
114 if (!compartmentMananager)
115 return false;
116
117 array<BaseCompartmentSlot> compartmentSlots = {};
118 compartmentMananager.GetCompartments(compartmentSlots);
119 foreach (BaseCompartmentSlot slot : compartmentSlots)
120 {
121 if (slot.GetOccupant() == entity)
122 return true;
123 }
124
125 return false;
126 }
127
128 //------------------------------------------------------------------------------------------------
130 {
131 if (!m_DamageManager)
132 return EDamageState.UNDAMAGED;
133
134 return m_DamageManager.GetState();
135 }
136
137 //---------------------------------------------------------------------------------------------------
140 static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
141 {
142 SCR_AIVehicleUsageComponent comp = null;
143
144 while (!comp && ent)
145 {
146 comp = SCR_AIVehicleUsageComponent.Cast(ent.FindComponent(SCR_AIVehicleUsageComponent));
147 componentOwner = ent;
148 ent = ent.GetParent();
149 }
150
151 return comp;
152 }
153
154 //---------------------------------------------------------------------------------------------------
155 // PROTECTED / INTERNAL
156
157 //------------------------------------------------------------------------------
158 protected void OnDamageStateChanged(EDamageState damageState)
159 {
161 return;
162
163 m_OnDamageStateChanged.Invoke(this, damageState);
164 }
165
166 //------------------------------------------------------------------------------
168 {
169 if (m_DamageManager)
170 m_DamageManager.GetOnDamageStateChanged().Remove(OnDamageStateChanged);
171
172 if (m_OnDeleted)
173 m_OnDeleted.Invoke(this);
174 }
175
176 //------------------------------------------------------------------------------
177 protected override void OnPostInit(IEntity owner)
178 {
179 SetEventMask(owner, EntityEvent.INIT);
180
181 if (!IsVehicleTypeValid())
182 ErrorIncorrectType(owner);
183 }
184
185 //------------------------------------------------------------------------------
186 protected override void EOnInit(IEntity owner)
187 {
188 m_DamageManager = SCR_DamageManagerComponent.Cast(owner.FindComponent(SCR_DamageManagerComponent));
189 if (m_DamageManager)
190 m_DamageManager.GetOnDamageStateChanged().Insert(OnDamageStateChanged);
191
192 // find pilot & turret slots
193 SCR_BaseCompartmentManagerComponent compartmentMan = SCR_BaseCompartmentManagerComponent.Cast(owner.FindComponent(SCR_BaseCompartmentManagerComponent));
194 if (compartmentMan)
195 {
196 array<BaseCompartmentSlot> compartmentSlots = {};
197 compartmentMan.GetCompartments(compartmentSlots);
198 foreach (BaseCompartmentSlot slot : compartmentSlots)
199 {
200 TurretCompartmentSlot turretComp = TurretCompartmentSlot.Cast(slot);
201 PilotCompartmentSlot pilotComp = PilotCompartmentSlot.Cast(slot);
202 if (turretComp)
203 m_TurretSlot = turretComp;
204 if (pilotComp)
205 m_PilotSlot = pilotComp;
206 }
207 }
208 }
209
210 //------------------------------------------------------------------------------
211 static void ErrorNoComponent(notnull IEntity entity)
212 {
213 Print(string.Format("SCR_AIVehicleUsageComponent not found on entity: %1", entity), LogLevel.ERROR);
214 }
215
216 //------------------------------------------------------------------------------
217 static void ErrorIncorrectType(notnull IEntity entity)
218 {
219 Print(string.Format("SCR_AIVehicleUsageComponent has incorrect type on entity: %1", entity), LogLevel.ERROR);
220 }
221}
func SCR_AIOnVehicleDeleted
EAIVehicleType
Vehicle type from point view of AI usage.
func SCR_AIOnVehicleDamageStateChanged
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
TurretCompartmentSlot GetTurretCompartmentSlot()
static void ErrorIncorrectType(notnull IEntity entity)
ScriptInvokerBase< SCR_AIOnVehicleDamageStateChanged > GetOnDamageStateChanged()
ScriptInvokerBase< SCR_AIOnVehicleDeleted > GetOnDeleted()
override void EOnInit(IEntity owner)
bool CanBePiloted()
AI can use the pilot compartments on this vehicle.
bool IsOccupiedByGroup(notnull SCR_AIGroup aiGroup)
static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
static void ErrorNoComponent(notnull IEntity entity)
ref ScriptInvokerBase< SCR_AIOnVehicleDeleted > m_OnDeleted
SCR_DamageManagerComponent m_DamageManager
void OnDamageStateChanged(EDamageState damageState)
override void OnPostInit(IEntity owner)
ref ScriptInvokerBase< SCR_AIOnVehicleDamageStateChanged > m_OnDamageStateChanged
PilotCompartmentSlot GetPilotCompartmentSlot()
proto external GenericEntity GetOwner()
Get owner entity.
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
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EDamageState
@ INVALID
Missing components, or obstruction test was not possible.