Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AirstrikePrototype.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Entities", description: "This entity will create airstrikes on the map")]
2 
3 class SCR_AirstrikePrototypeClass: GenericEntityClass
4 {
5 };
6 
8 {
9  [Attribute("", UIWidgets.ResourceAssignArray, "Generated projectiles will loop through the projectiles on this array", "et")]
10  private ref array<ResourceName> m_ProjectilesToTrigger;
11 
12  //Initial values
13  [Attribute("0", UIWidgets.EditBox, "Number of projectiles to create. 0 = until time ends")]
14  int m_NumProjectiles;
15 
16  [Attribute("0", UIWidgets.EditBox, "Time until this entity creates a new projectile.")]
17  float m_TimeBetweenProjectiles;
18 
19  [Attribute("0", UIWidgets.EditBox, "Size of zone around the point where the airstrike will take place")]
20  float m_AirstrikeRadius;
21 
22  [Attribute("0", UIWidgets.CheckBox, "If true, even if there is a random radius it will have a bias towards the original airstrike target")]
23  bool m_BiasTowardsCenter;
24 
25  [Attribute("0", UIWidgets.Range, "Random delay [0,X] applied to the time between projectiles to make it more believable. Ignore Z parameter, 2D vectors are not supported by script")]
26  vector m_RandomDelayBetweenRockets;
27 
28  [Attribute("0", UIWidgets.Range, "Initial delay for the beginning of the airstrike")]
29  float m_InitialDelay;
30 
31  // current values
32  private ref array<ref Resource> m_LoadedPrefabs = new array<ref Resource>();
33 
34 
35  int m_RemainingProjectiles = 0;
36  float m_TimeUntilNextProjectile = 0;
37 
38  //keeps track of what projectile prefab will be used
39  private int m_CurrentProjectilePrefab = 0;
40  private int m_PreviousProjectilePrefab = 0;
41 
42  private ref RandomGenerator m_RandomGenerator = new RandomGenerator;
43 
44  //audio variables
45  private BaseSoundComponent m_SoundComponent;
46  private int m_SoundShotIndex = 0;
47 
48  private vector m_direction;
49  private vector m_spawnPos;
50  private IEntity m_lastSpawnedProjectile = null;
51 
52 
53  private IEntity m_owner = null;
54  private RplComponent m_RplComponent = null;
55  //------------------------------------------------------------------------------------------------
56  void SCR_AirstrikePrototype(IEntitySource src, IEntity parent)
57  {
58  SetFlags(EntityFlags.ACTIVE, false);
59  SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);
60 
61  for(int i = 0; i < m_ProjectilesToTrigger.Count(); i++)
62  {
63  if(!m_ProjectilesToTrigger[i])
64  continue;
65 
66  Resource projectile = Resource.Load(m_ProjectilesToTrigger[i]);
67  if(projectile)
68  m_LoadedPrefabs.Insert(projectile);
69  }
70 
71  m_RemainingProjectiles = m_NumProjectiles;
72  m_TimeUntilNextProjectile = m_TimeBetweenProjectiles;
73 
74  AddRandomDelayToNextProjectile();
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override protected void EOnInit(IEntity owner)
79  {
80  m_owner = owner;
81  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
82 
83  m_TimeUntilNextProjectile += m_InitialDelay;
84  }
85  //------------------------------------------------------------------------------------------------
86  override protected void EOnFrame(IEntity owner, float timeSlice) //EntityEvent.FRAME
87  {
88  if(m_lastSpawnedProjectile)
89  {
90  Do_LaunchMissile(m_direction);
91 
92  m_lastSpawnedProjectile = null;
93  }
94 
95  //end conditions, no need to keep updating the object
96  if (m_RemainingProjectiles <= 0)
97  {
98  ClearFlags(EntityFlags.ACTIVE, false);
99  ClearEventMask(EntityEvent.FRAME);
100  return;
101  }
102 
103  m_TimeUntilNextProjectile -= timeSlice;
104 
105  //no projectile
106  if (m_TimeUntilNextProjectile > 0)
107  return;
108 
109  //added instead of assigned to ensure accuracy
110  m_TimeUntilNextProjectile += m_TimeBetweenProjectiles;
111  AddRandomDelayToNextProjectile();
112 
113  if(!m_RplComponent || !m_RplComponent.IsProxy())
114  ReadyProjectile();
115  }
116 
117  protected void ReadyProjectile()
118  {
119  ref Resource prefab = m_LoadedPrefabs[m_CurrentProjectilePrefab];
120 
121  AdvanceProjectilePrefab();
122 
123  m_RemainingProjectiles--;
124 
125  if (!prefab)
126  return;
127 
128  ref EntitySpawnParams spawnParams = new EntitySpawnParams();
129  spawnParams.TransformMode = ETransformMode.WORLD;
130 
131  vector direction;
132  vector missileTarget = ComputeMissileTarget();
133 
134  ComputeProjectileTransform(spawnParams.Transform, direction, missileTarget);
135 
136  FireProjectile(prefab, spawnParams, direction);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  protected void AdvanceProjectilePrefab()
141  {
142  m_PreviousProjectilePrefab = m_CurrentProjectilePrefab;
143  ++m_CurrentProjectilePrefab;
144 
145  if (m_CurrentProjectilePrefab >= m_LoadedPrefabs.Count())
146  m_CurrentProjectilePrefab = 0;
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected vector ComputeMissileTarget()
151  {
152  vector ownerTransform[4];
153  GetTransform(ownerTransform);
154 
155  if(m_AirstrikeRadius == 0)
156  return ownerTransform[3];
157 
158  vector missileTarget = m_RandomGenerator.GenerateRandomPointInRadius(0, m_AirstrikeRadius, ownerTransform[3], !m_BiasTowardsCenter);
159  missileTarget[1] = ownerTransform[3][1];
160 
161  return missileTarget;
162  }
163  //------------------------------------------------------------------------------------------------
164  protected void ComputeProjectileTransform(out vector transform[4], out vector direction, vector missileTarget)
165  {
166  vector mat[4];
167  vector rotation[4];
168 
169  GetTransform(mat);
170 
171  m_spawnPos = mat[3];
172  m_spawnPos[1] = m_spawnPos[1] + 100;
173 
174  direction = vector.Direction(m_spawnPos, missileTarget);
175  direction.Normalize();
176 
177  Math3D.MatrixFromForwardVec(direction, transform);
178  transform[3] = m_spawnPos;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  void FireProjectile(Resource prefab, EntitySpawnParams spawnParams, vector direction)
183  {
184  IEntity spawnedProjectile = GetGame().SpawnEntityPrefab(prefab, GetWorld(), spawnParams);
185 
186  m_lastSpawnedProjectile = spawnedProjectile;
187  m_direction = direction;
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  void Do_LaunchMissile(vector direction)
192  {
193  RplComponent rplComp = RplComponent.Cast(m_lastSpawnedProjectile.FindComponent(RplComponent));
194 
195  Rpc(RpcLaunchMissile_BC, rplComp.Id(), direction);
196 
197  LaunchMissile(m_lastSpawnedProjectile, direction);
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
202  void RpcLaunchMissile_BC(RplId id, vector direction)
203  {
204  RplComponent rocketRplComp = RplComponent.Cast(Replication.FindItem(id));
205 
206  LaunchMissile(rocketRplComp.GetEntity(), direction);
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  void LaunchMissile(IEntity rocket, vector direction)
211  {
212  if(!rocket)
213  return;
214 
215  BaseMoveComponent moveComp = BaseMoveComponent.Cast(rocket.FindComponent(BaseMoveComponent));
216 
217  if(!moveComp)
218  return;
219 
220  moveComp.Launch(direction, vector.Zero, 1, rocket, null, null, null, null);
221  }
222 
223  //------------------------------------------------------------------------------------------------
224  protected void AddRandomDelayToNextProjectile()
225  {
226  if(m_RandomDelayBetweenRockets[0] >= m_RandomDelayBetweenRockets[1])
227  return;
228 
229  float delay = m_RandomGenerator.RandFloatXY(m_RandomDelayBetweenRockets[0], m_RandomDelayBetweenRockets[1]);
230 
231  m_TimeUntilNextProjectile += delay;
232 
233  }
234  //------------------------------------------------------------------------------------------------
235  void ~SCR_AirstrikePrototype()
236  {
237  }
238 };
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
m_owner
protected IEntity m_owner
Definition: SCR_CharacterRegistrationComponent.c:10
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseMoveComponent
Definition: BaseMoveComponent.c:12
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
SCR_AirstrikePrototype
Definition: SCR_AirstrikePrototype.c:7
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
SCR_AirstrikePrototypeClass
Definition: SCR_AirstrikePrototype.c:3
m_RandomGenerator
ref RandomGenerator m_RandomGenerator
Definition: SCR_BuildingDestructionManagerComponent.c:21
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180