Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseDeployableSpawnPointComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/DeployableItems", description: "")]
3 {
4 }
5 
7 class SCR_BaseDeployableSpawnPointComponent : SCR_BaseDeployableInventoryItemComponent
8 {
9  protected static ref array<SCR_BaseDeployableSpawnPointComponent> s_aActiveDeployedSpawnPoints = {};
10 
11  protected static ref ScriptInvokerInt s_OnSpawnPointDismantled;
12 
13  [Attribute("{84680168E273774F}Prefabs/MP/Spawning/DeployableItemSpawnPoint_Base.et")]
14  protected ResourceName m_sSpawnPointPrefab;
15 
16  [Attribute()]
17  protected ResourceName m_sReplacementPrefab;
18 
19  [Attribute()]
20  protected FactionKey m_FactionKey;
21 
22  [Attribute(defvalue: "1")]
23  protected bool m_bEnableSounds;
24 
26 
27  protected IEntity m_ReplacementEntity;
28 
29  protected vector m_aOriginalTransform[4];
30 
31  protected static bool s_bDeployableSpawnPointsEnabled;
32 
33  //------------------------------------------------------------------------------------------------
34  static ScriptInvokerInt GetOnSpawnPointDismantled()
35  {
36  if (!s_OnSpawnPointDismantled)
37  s_OnSpawnPointDismantled = new ScriptInvokerInt();
38 
39  return s_OnSpawnPointDismantled;
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
44  protected void RPC_SetTransformBroadcast(vector transform[4])
45  {
46  GetOwner().SetTransform(transform);
47  }
48 
49  //------------------------------------------------------------------------------------------------
50  [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)]
51  protected void RPC_PlaySoundOnDeployBroadcast(bool deploy)
52  {
53  SoundComponent soundComp = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
54  if (!soundComp)
55  return;
56 
57  if (deploy)
58  soundComp.SoundEvent(SCR_SoundEvent.SOUND_DEPLOYED_RADIO_DEPLOY);
59  else
60  soundComp.SoundEvent(SCR_SoundEvent.SOUND_DEPLOYED_RADIO_UNDEPLOY);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  protected void ToggleRadioChatter(bool enable)
65  {
66  SignalsManagerComponent signalsManagerComp = SignalsManagerComponent.Cast(GetOwner().FindComponent(SignalsManagerComponent));
67  if (!signalsManagerComp)
68  return;
69 
70  int radioChatter = signalsManagerComp.FindSignal("DeployableRadioChatter");
71 
72  if (enable)
73  signalsManagerComp.SetSignalValue(radioChatter, 1);
74  else
75  signalsManagerComp.SetSignalValue(radioChatter, 0);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  protected void OnCompositionDestroyed(IEntity instigator)
80  {
81  Dismantle(instigator);
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  protected override void OnRplDeployed()
86  {
87  if (m_bEnableSounds)
89  }
90 
91  //------------------------------------------------------------------------------------------------
94  override void Deploy(IEntity userEntity = null)
95  {
96  //~ Not allowed to deploy
97  if (!s_bDeployableSpawnPointsEnabled)
98  return;
99 
100  if (!m_RplComponent || m_RplComponent.IsProxy())
101  return;
102 
103  vector transform[4];
104  IEntity owner = GetOwner();
105  SCR_TerrainHelper.GetTerrainBasis(owner.GetOrigin(), transform, GetGame().GetWorld(), false, new TraceParam());
106 
107  m_aOriginalTransform = transform;
108 
109  EntitySpawnParams params = new EntitySpawnParams();
110  params.Transform = transform;
111  params.TransformMode = ETransformMode.WORLD;
112 
113  Resource resource = Resource.Load(m_sReplacementPrefab);
114  if (!resource.IsValid())
115  return;
116 
117  m_ReplacementEntity = GetGame().SpawnEntityPrefab(resource, GetGame().GetWorld(), params);
118  if (!m_ReplacementEntity)
119  return;
120 
121  RplComponent rplCompReplacementEntity = RplComponent.Cast(m_ReplacementEntity.FindComponent(RplComponent));
122  if (!rplCompReplacementEntity)
123  return;
124 
126  if (!replacementComp)
127  return;
128 
129  vector compositionTransform[4], combinedTransform[4];
130  replacementComp.GetItemTransform(compositionTransform);
131  Math3D.MatrixMultiply4(transform, compositionTransform, combinedTransform);
132 
133  RPC_SetTransformBroadcast(combinedTransform);
134  Rpc(RPC_SetTransformBroadcast, combinedTransform);
135 
136  replacementComp.GetOnCompositionDestroyed().Insert(OnCompositionDestroyed);
137 
138  resource = Resource.Load(m_sSpawnPointPrefab);
139  if (!resource.IsValid())
140  return;
141 
142  m_SpawnPoint = SCR_DeployableSpawnPoint.Cast(GetGame().SpawnEntityPrefab(resource, GetGame().GetWorld(), params));
143  if (!m_SpawnPoint)
144  return;
145 
146  RplComponent rplCompSpawnpoint = RplComponent.Cast(m_SpawnPoint.FindComponent(RplComponent));
147  if (!rplCompSpawnpoint)
148  return;
149 
150  m_SpawnPoint.SetDeployableSpawnPointComponent(this);
151  m_SpawnPoint.SetFactionKey(m_FactionKey);
152 
153  m_bIsDeployed = true;
154  Replication.BumpMe();
155 
156  if (userEntity)
157  m_iItemOwnerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(userEntity);
158 
159  s_aActiveDeployedSpawnPoints.Insert(this);
160 
161  if (m_bEnableSounds)
162  {
163  ToggleRadioChatter(true);
166  }
167 
168  auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(owner);
169  if (garbageSystem)
170  garbageSystem.Withdraw(owner);
171  }
172 
173  //------------------------------------------------------------------------------------------------
176  override void Dismantle(IEntity userEntity = null)
177  {
178  if (!m_RplComponent || m_RplComponent.IsProxy())
179  return;
180 
181  RplComponent rplComp;
182  if (m_SpawnPoint)
183  {
184  rplComp = RplComponent.Cast(m_SpawnPoint.FindComponent(RplComponent));
185  if (!rplComp)
186  return;
187 
188  rplComp.DeleteRplEntity(m_SpawnPoint, false);
189  }
190 
192  {
193  rplComp = RplComponent.Cast(m_ReplacementEntity.FindComponent(RplComponent));
194  if (!rplComp)
195  return;
196 
197  rplComp.DeleteRplEntity(m_ReplacementEntity, false);
198  }
199 
202 
203  m_bIsDeployed = false;
204  Replication.BumpMe();
205 
206  m_iItemOwnerID = -1;
207 
208  s_aActiveDeployedSpawnPoints.RemoveItem(this);
209 
210  int userID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(userEntity);
211  if (s_OnSpawnPointDismantled)
212  s_OnSpawnPointDismantled.Invoke(userID);
213 
214  if (m_bEnableSounds)
215  {
216  ToggleRadioChatter(false);
218  Rpc(RPC_PlaySoundOnDeployBroadcast, false);
219  }
220 
221  IEntity owner = GetOwner();
222  auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(owner);
223  if (garbageSystem)
224  garbageSystem.Insert(owner);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  protected static void OnSpawnPointDeployingEnabledChanged(bool enabled)
229  {
230  s_bDeployableSpawnPointsEnabled = enabled;
231 
232  if (enabled)
233  return;
234 
235  foreach (SCR_BaseDeployableSpawnPointComponent spawnPointComp : s_aActiveDeployedSpawnPoints)
236  {
237  spawnPointComp.Dismantle();
238  }
239  }
240 
241  //------------------------------------------------------------------------------------------------
243  static array<SCR_BaseDeployableSpawnPointComponent> GetActiveDeployedSpawnPoints()
244  {
246  }
247 
248  //------------------------------------------------------------------------------------------------
251  {
252  return m_SpawnPoint;
253  }
254 
255  //------------------------------------------------------------------------------------------------
258  void Update(float timeSlice);
259 
260  //------------------------------------------------------------------------------------------------
262  {
263  World world = GetOwner().GetWorld();
265  if (!updateSystem)
266  return;
267 
268  updateSystem.Register(this);
269  }
270 
271  //------------------------------------------------------------------------------------------------
273  {
274  World world = GetOwner().GetWorld();
276  if (!updateSystem)
277  return;
278 
279  updateSystem.Unregister(this);
280  }
281 
282  //------------------------------------------------------------------------------------------------
283  override void EOnInit(IEntity owner)
284  {
285  super.EOnInit(owner);
286 
287  BaseGameMode gameMode = GetGame().GetGameMode();
288  if (!gameMode)
289  return;
290 
291  SCR_PlayerSpawnPointManagerComponent playerSpawnPointManager = SCR_PlayerSpawnPointManagerComponent.Cast(gameMode.FindComponent(SCR_PlayerSpawnPointManagerComponent));
292  if (!playerSpawnPointManager)
293  {
294  OnSpawnPointDeployingEnabledChanged(true);
295  return;
296  }
297 
298  OnSpawnPointDeployingEnabledChanged(playerSpawnPointManager.IsDeployingSpawnPointsEnabled());
299  playerSpawnPointManager.GetOnSpawnPointDeployingEnabledChanged().Insert(OnSpawnPointDeployingEnabledChanged);
300  }
301 
302  //------------------------------------------------------------------------------------------------
303  // destructor
305  {
306  BaseGameMode gameMode = GetGame().GetGameMode();
307  if (gameMode)
308  {
309  SCR_PlayerSpawnPointManagerComponent playerSpawnPointManager = SCR_PlayerSpawnPointManagerComponent.Cast(gameMode.FindComponent(SCR_PlayerSpawnPointManagerComponent));
310  if (playerSpawnPointManager)
311  playerSpawnPointManager.GetOnSpawnPointDeployingEnabledChanged().Remove(OnSpawnPointDeployingEnabledChanged);
312  }
313 
314  if (m_bIsDeployed && Replication.IsServer())
315  s_aActiveDeployedSpawnPoints.RemoveItem(this);
316  }
317 }
SCR_TerrainHelper
Definition: SCR_TerrainHelper.c:1
m_sReplacementPrefab
protected ResourceName m_sReplacementPrefab
Definition: SCR_BaseDeployableSpawnPointComponent.c:17
RPC_SetTransformBroadcast
protected void RPC_SetTransformBroadcast(vector transform[4])
Definition: SCR_BaseDeployableSpawnPointComponent.c:44
SCR_BaseDeployableSpawnPointComponentClass
Definition: SCR_BaseDeployableSpawnPointComponent.c:2
m_bEnableSounds
protected bool m_bEnableSounds
Definition: SCR_BaseDeployableSpawnPointComponent.c:23
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
m_bIsDeployed
protected bool m_bIsDeployed
Definition: SCR_CampaignMobileAssemblyComponent.c:39
ScriptInvokerInt
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
Definition: SCR_ScriptInvokerHelper.c:24
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Deploy
override void Deploy(IEntity userEntity=null)
Definition: SCR_BaseDeployableSpawnPointComponent.c:94
~SCR_BaseDeployableSpawnPointComponent
void ~SCR_BaseDeployableSpawnPointComponent()
Definition: SCR_BaseDeployableSpawnPointComponent.c:304
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
GetSpawnPoint
SCR_SpawnPoint GetSpawnPoint()
Definition: SCR_BaseDeployableSpawnPointComponent.c:250
ToggleRadioChatter
protected void ToggleRadioChatter(bool enable)
Definition: SCR_BaseDeployableSpawnPointComponent.c:64
m_sSpawnPointPrefab
protected ResourceName m_sSpawnPointPrefab
Definition: SCR_BaseDeployableSpawnPointComponent.c:14
OnRplDeployed
protected override void OnRplDeployed()
Definition: SCR_BaseDeployableSpawnPointComponent.c:85
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_SpawnPoint
protected SCR_DeployableSpawnPoint m_SpawnPoint
Definition: SCR_BaseDeployableSpawnPointComponent.c:25
ConnectToDeployableSpawnPointSystem
protected void ConnectToDeployableSpawnPointSystem()
Definition: SCR_BaseDeployableSpawnPointComponent.c:261
DisconnectFromDeployableSpawnPointSystem
protected void DisconnectFromDeployableSpawnPointSystem()
Definition: SCR_BaseDeployableSpawnPointComponent.c:272
OnCompositionDestroyed
protected void OnCompositionDestroyed(IEntity instigator)
Definition: SCR_BaseDeployableSpawnPointComponent.c:79
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_GarbageSystem
Script entry for garbage system modding.
Definition: SCR_GarbageSystem.c:2
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_BaseDeployableSpawnPointComponent.c:283
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
SCR_BaseDeployableInventoryItemComponentClass
Definition: SCR_BaseDeployableInventoryItemComponent.c:2
m_FactionKey
protected FactionKey m_FactionKey
Definition: SCR_BaseDeployableSpawnPointComponent.c:20
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
Update
void Update(float timeSlice)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:28
RPC_PlaySoundOnDeployBroadcast
protected void RPC_PlaySoundOnDeployBroadcast(bool deploy)
Definition: SCR_BaseDeployableSpawnPointComponent.c:51
SCR_DeployableInventoryItemReplacementComponent
Holds Position of where the deployable item will be attached to.
Definition: SCR_DeployableInventoryItemReplacementComponent.c:11
SCR_DeployableSpawnPointSystem
Definition: SCR_DeployableSpawnPointSystem.c:1
Dismantle
override void Dismantle(IEntity userEntity=null)
Definition: SCR_BaseDeployableSpawnPointComponent.c:176
m_aOriginalTransform
protected vector m_aOriginalTransform[4]
Definition: SCR_BaseDeployableSpawnPointComponent.c:29
m_ReplacementEntity
protected IEntity m_ReplacementEntity
Definition: SCR_BaseDeployableSpawnPointComponent.c:27
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_DeployableSpawnPoint
Definition: SCR_DeployableSpawnPoint.c:11
s_aActiveDeployedSpawnPoints
SCR_BaseDeployableSpawnPointComponentClass s_aActiveDeployedSpawnPoints
Base class which all deployable spawn points / radios inherit from.