Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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
3class SCR_AirstrikePrototypeClass: GenericEntityClass
4{
5};
6
7class SCR_AirstrikePrototype: GenericEntity
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);
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
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);
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;
112
113 if(!m_RplComponent || !m_RplComponent.IsProxy())
115 }
116
117 protected void ReadyProjectile()
118 {
119 ref Resource prefab = m_LoadedPrefabs[m_CurrentProjectilePrefab];
120
122
123 m_RemainingProjectiles--;
124
125 if (!prefab)
126 return;
127
128 ref EntitySpawnParams spawnParams = new EntitySpawnParams();
129 spawnParams.TransformMode = ETransformMode.WORLD;
130
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
183 {
184 IEntity spawnedProjectile = GetGame().SpawnEntityPrefab(prefab, GetWorld(), spawnParams);
185
186 m_lastSpawnedProjectile = spawnedProjectile;
187 m_direction = direction;
188 }
189
190 //------------------------------------------------------------------------------------------------
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)]
203 {
204 RplComponent rocketRplComp = RplComponent.Cast(Replication.FindItem(id));
205
206 LaunchMissile(rocketRplComp.GetEntity(), direction);
207 }
208
209 //------------------------------------------------------------------------------------------------
211 {
212 if(!rocket)
213 return;
214
216
217 if(!moveComp)
218 return;
219
220 moveComp.Launch(direction, vector.Zero, 1, rocket, null, null, null, null);
221 }
222
223 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
236 {
237 }
238};
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector direction
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external Managed FindComponent(typename typeName)
proto external EntityEvent ClearEventMask(EntityEvent e)
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external void GetTransform(out vector mat[])
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
void LaunchMissile(IEntity rocket, vector direction)
void Do_LaunchMissile(vector direction)
void RpcLaunchMissile_BC(RplId id, vector direction)
void ComputeProjectileTransform(out vector transform[4], out vector direction, vector missileTarget)
void EOnFrame(IEntity owner, float timeSlice)
void FireProjectile(Resource prefab, EntitySpawnParams spawnParams, vector direction)
void EntitySpawnParams()
Definition gameLib.c:130
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
RespawnSystemComponentClass GameComponentClass vector vector rotation
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14