Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingCompositionComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "Game/Building", description: "Component attached to compositions.")]
3{
4 [Attribute(defvalue: "-1", desc: "This value defines length of a trace for placement obstruction check in meters. This value will be used for all entities in composition that has it's center bellow terrain level. Mainly composition foundations.")]
5 protected float m_fCustomObstructionValue;
6
7 //------------------------------------------------------------------------------------------------
8 static float GetProtectionRadius(notnull IEntityComponentSource componentSource)
9 {
10 float val;
11 componentSource.Get("m_fCustomObstructionValue", val);
12 return val;
13 }
14
15 //------------------------------------------------------------------------------------------------
17 {
18 int componentsCount = entitySource.GetComponentCount();
19 for (int i = 0; i < componentsCount; i++)
20 {
21 IEntityComponentSource componentSource = entitySource.GetComponent(i);
22 if (componentSource.GetClassName().ToType().IsInherited(SCR_CampaignBuildingCompositionComponent))
23 return componentSource;
24 }
25 return null;
26 }
27}
28
29class SCR_CampaignBuildingCompositionComponent : ScriptComponent
30{
31 [Attribute()]
32 protected ref SCR_AudioSourceConfiguration m_AudioSourceConfigurationSpawn;
33
34 [Attribute()]
35 protected ref SCR_AudioSourceConfiguration m_AudioSourceConfigurationDespawn;
36
37 // Could be for example a base to which this composition belongs to.
39 protected RplId m_RplCompId;
40 private SCR_EditorModeEntity m_EditorModeEntity;
41 protected int m_iBuilderId = INVALID_PLAYER_ID;
42 protected int m_iCost;
43 protected int m_iPrefabId;
44 protected bool m_bInteractionLock;
45
46 [RplProp()]
47 protected bool m_bPlaySoundOnDeletion;
48
49 [RplProp(onRplName: "OnCompositionSpawned")]
51
54
55 protected SCR_CampaignBuildingLayoutComponent m_CompositionLayout;
56
57 protected static const int INVALID_PLAYER_ID = 0;
58
59 //------------------------------------------------------------------------------------------------
60 override void OnPostInit(IEntity owner)
61 {
62 SetEventMask(owner, EntityEvent.INIT);
63
64 SCR_EditorLinkComponent linkComponent = SCR_EditorLinkComponent.Cast(owner.FindComponent(SCR_EditorLinkComponent));
65 if (!linkComponent || !linkComponent.IsSpawningIgnored())
66 {
67 m_bInteractionLock = true;
68 return;
69 }
70
71 if (IsProxy())
72 return;
73
74 BaseGameMode gameMode = GetGame().GetGameMode();
75 if (!gameMode)
76 return;
77
78 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
79 if (!buildingManagerComponent)
80 return;
81
83 if (!editableEntity)
84 return;
85
86 ResourceName resName = editableEntity.GetPrefab();
87 if (resName.IsEmpty())
88 return;
89
90 int prefabId = buildingManagerComponent.GetCompositionId(resName);
91 if (prefabId == -1)
92 return;
93
94 SpawnCompositionLayout(prefabId, editableEntity);
95 }
96
97 //------------------------------------------------------------------------------------------------
102 {
103 if (!entity)
104 return;
105
106 Resource compositionOutlineResource = Resource.Load(GetOutlineToSpawn(entity));
107 if (!compositionOutlineResource.IsValid())
108 return;
109
110 EntitySpawnParams spawnParams = new EntitySpawnParams();
111 spawnParams.TransformMode = ETransformMode.WORLD;
112 spawnParams.Parent = entity.GetOwner();
113
114 IEntity compositionLayout = GetGame().SpawnEntityPrefab(compositionOutlineResource, GetGame().GetWorld(), spawnParams);
115 if (!compositionLayout)
116 return;
117
118 m_CompositionLayout = SCR_CampaignBuildingLayoutComponent.Cast(compositionLayout.FindComponent(SCR_CampaignBuildingLayoutComponent));
120 return;
121
122 SCR_CampaignBuildingCompositionComponent compositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(entity.GetOwner().FindComponent(SCR_CampaignBuildingCompositionComponent));
123 if (!compositionComponent)
124 return;
125
126 // If the spawned composition has a service component, mark service as "under construction"
127 SCR_ServicePointComponent serviceComponent = SCR_ServicePointComponent.Cast(entity.GetOwner().FindComponent(SCR_ServicePointComponent));
128 if (serviceComponent)
129 serviceComponent.SetServiceState(SCR_EServicePointStatus.UNDER_CONSTRUCTION);
130
131 m_CompositionLayout.SetPrefabId(prefabId);
132 compositionComponent.SetPrefabId(prefabId);
133 }
134
135 //------------------------------------------------------------------------------------------------
138 {
139 BaseGameMode gameMode = GetGame().GetGameMode();
140 if (!gameMode)
141 return string.Empty;
142
143 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
144 if (!buildingManagerComponent)
145 return string.Empty;
146
147 SCR_CampaignBuildingCompositionOutlineManager outlineManager = buildingManagerComponent.GetOutlineManager();
148 if (!outlineManager)
149 return string.Empty;
150
151 return outlineManager.GetCompositionOutline(entity);
152 }
153
154 //------------------------------------------------------------------------------------------------
155 SCR_CampaignBuildingLayoutComponent GetCompositionLayout()
156 {
157 return m_CompositionLayout;
158 }
159
160 //------------------------------------------------------------------------------------------------
161 override void EOnInit(IEntity owner)
162 {
163 // Check for play mode again in case init event was set from outside of this class
164 if (!GetGame().InPlayMode())
165 return;
166
167 BaseGameMode gameMode = GetGame().GetGameMode();
168 if (!gameMode)
169 return;
170
171 SCR_EditorLinkComponent linkComponent = SCR_EditorLinkComponent.Cast(owner.FindComponent(SCR_EditorLinkComponent));
172 if (!linkComponent)
173 {
174 // A composition that spawns but does not have SCR_EditorLinkComponent must be set to already spawned
176 return;
177 }
178
180 if (!editableEnt)
181 return;
182
183 SetCompositionCost(editableEnt);
184
185 linkComponent.GetOnLinkedEntitiesSpawned().Insert(SetIsCompositionSpawned);
186
187 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
188 if (!buildingManagerComponent)
189 return;
190
191 buildingManagerComponent.RegisterComposition(this);
192 }
193
194 //------------------------------------------------------------------------------------------------
197 {
199 return;
200
201 IEntity child = GetOwner().GetChildren();
202 while (child)
203 {
204 // The preview exist at this moment but will be deleted, skip it.
205 SCR_BasePreviewEntity previewEnt = SCR_BasePreviewEntity.Cast(child);
206 if (previewEnt)
207 {
208 child = child.GetSibling();
209 continue;
210 }
211
212 // The layout of the composition wasn't deleted yet in this frame. Skip it.
213 SCR_CampaignBuildingLayoutComponent layoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(child.FindComponent(SCR_CampaignBuildingLayoutComponent));
214 if (layoutComponent)
215 {
216 child = child.GetSibling();
217 continue;
218 }
219
220 // Look for all childs with destruction component among childs of root entity. If there is at least one entity without this component, we don't have to continue, as the root entity will never stay alone - so there isn't need to delete it.
221 SCR_DestructionMultiPhaseComponent destructionComponent = SCR_DestructionMultiPhaseComponent.Cast(child.FindComponent(SCR_DestructionMultiPhaseComponent));
222 if (!destructionComponent)
223 return;
224
225 child = child.GetSibling();
226 }
227
228 SCR_DestructionDamageManagerComponent.GetOnDestructibleDestroyedInvoker().Insert(DestructibleEntityDestroyed);
229 }
230
231 //------------------------------------------------------------------------------------------------
234 void DestructibleEntityDestroyed(SCR_DestructionMultiPhaseComponent component)
235 {
236 // Calling one frame later as by the end of this one, the entity that triggered this can still exist.
237 GetGame().GetCallqueue().CallLater(CheckExistingChild, 1, false);
238 }
239
240 //------------------------------------------------------------------------------------------------
243 {
244 if (SCR_EntityHelper.GetChildrenCount(GetOwner()) == 0)
245 SCR_EntityHelper.DeleteEntityAndChildren(GetOwner());
246 }
247
248 //------------------------------------------------------------------------------------------------
249 // Called when the composition is spawned (gradual building)
250 protected void SetIsCompositionSpawned()
251 {
253 Replication.BumpMe();
254
255 if (m_iBuilderId != INVALID_PLAYER_ID)
257
258 if (!IsProxy())
259 {
261 if (editable)
262 editable.SetEntityFlag(EEditableEntityFlag.SPAWN_UNFINISHED, false);
263
265 }
266
268 m_OnCompositionSpawned.Invoke(true);
269 }
270
271 //------------------------------------------------------------------------------------------------
273 protected void OnCompositionSpawned()
274 {
276
278 m_OnCompositionSpawned.Invoke(true);
279 }
280
281 //------------------------------------------------------------------------------------------------
290
291 //------------------------------------------------------------------------------------------------
294 protected void SetCompositionCost(notnull SCR_EditableEntityComponent editableEnt)
295 {
296 array<ref SCR_EntityBudgetValue> outBudgets = {};
297 editableEnt.GetEntityBudgetCost(outBudgets, GetOwner());
298 foreach (SCR_EntityBudgetValue budgetEnt : outBudgets)
299 {
300 if (budgetEnt.GetBudgetType() == EEditableEntityBudget.CAMPAIGN)
301 {
302 m_iCost = budgetEnt.GetBudgetValue();
303 return;
304 }
305 }
306 }
307
308 //------------------------------------------------------------------------------------------------
310 // Set composition ID which is used to identify composition by building mode.
311 void SetPrefabId(int prefabId)
312 {
313 m_iPrefabId = prefabId;
314 }
315
316 //------------------------------------------------------------------------------------------------
319 {
320 return m_iCost;
321 }
322
323 //------------------------------------------------------------------------------------------------
326 {
327 return m_iPrefabId;
328 }
329
330 //------------------------------------------------------------------------------------------------
334 {
336 }
337
338 //------------------------------------------------------------------------------------------------
347
348 //------------------------------------------------------------------------------------------------
351 {
352 m_ProviderEntity = newOwner;
353 if (m_OnBuilderSet)
354 m_OnBuilderSet.Invoke();
355 }
356
357 //------------------------------------------------------------------------------------------------
360 {
361 return m_ProviderEntity;
362 }
363
364 //------------------------------------------------------------------------------------------------
367 {
368 m_ProviderEntity = null;
369 }
370
371 //------------------------------------------------------------------------------------------------
373 void SetBuilderId(int id)
374 {
376
378 if (!editableEntity)
379 return;
380
381 editableEntity.SetAuthor(id);
382 }
383
384 //------------------------------------------------------------------------------------------------
387 {
388 return m_iBuilderId;
389 }
390
391 //------------------------------------------------------------------------------------------------
394 void SetInteractionLock(bool lockState)
395 {
396 m_bInteractionLock = lockState;
397 AfterLockChanged(lockState);
398 }
399
400 //------------------------------------------------------------------------------------------------
402 void SetInteractionLockServer(bool lockState)
403 {
404 SetInteractionLock(lockState);
405 Rpc(RpcDo_SetCompositionLock, lockState);
406 }
407
408 //------------------------------------------------------------------------------------------------
411 {
412 return m_bInteractionLock;
413 }
414
415 //------------------------------------------------------------------------------------------------
418 // Run evaluation if the entity still pass the given filter.
419 void AfterLockChanged(bool lockState)
420 {
422 if (!entity)
423 return;
424
426 if (filter)
427 filter.Validate(entity);
428
429 // ignore the following code if the compositino was locked
430 if (lockState)
431 return;
432
434 if (!core)
435 return;
436
437 SCR_EditorManagerEntity editorManager = core.GetEditorManager();
438 if (!editorManager)
439 return;
440
441 SCR_EditorModeEntity modeEntity = editorManager.FindModeEntity(EEditorMode.BUILDING);
442 if (!modeEntity)
443 return;
444
445 SCR_CampaignBuildingTransformingEditorComponent transformComponent = SCR_CampaignBuildingTransformingEditorComponent.Cast(modeEntity.FindComponent(SCR_CampaignBuildingTransformingEditorComponent));
446 if (!transformComponent)
447 return;
448
449 transformComponent.ReleaseLastRejectedPivot();
450 }
451
452 //------------------------------------------------------------------------------------------------
455 {
456 SetProviderEntity(newOwner);
457
458 RplId id = RplId.Invalid();
459
460 if (newOwner)
461 {
462 RplComponent comp = RplComponent.Cast(newOwner.FindComponent(RplComponent));
463 if (comp)
464 id = comp.Id();
465 }
466
468 }
469
470 //------------------------------------------------------------------------------------------------
473 {
475 if (m_EditorModeEntity)
476 m_EditorModeEntity.GetOnClosedServer().Remove(RemoveProviderEntityServer);
478 }
479
480 //------------------------------------------------------------------------------------------------
484 {
485 m_EditorModeEntity = ent;
486 ent.GetOnClosedServer().Insert(RemoveProviderEntityServer);
487 }
488
489 //------------------------------------------------------------------------------------------------
492 {
493 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(m_RplCompId));
494 if (!rplComp)
495 return;
496
497 SCR_CampaignBuildingProviderComponent.GetOnProviderCreated().Remove(SetProviderFromRplID);
498 SetProviderEntity(rplComp.GetEntity());
499 }
500
501 //------------------------------------------------------------------------------------------------
504 {
505 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), m_AudioSourceConfigurationSpawn);
506 }
507
508 //------------------------------------------------------------------------------------------------
509 protected bool IsProxy()
510 {
511 RplComponent rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
512 return (rplComponent && rplComponent.IsProxy());
513 }
514
515 //------------------------------------------------------------------------------------------------
517 {
519 }
520
521 //------------------------------------------------------------------------------------------------
522 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
524 {
526 }
527
528 //------------------------------------------------------------------------------------------------
529 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
530 protected void RpcDo_SetProviderEntity(RplId rplCompId)
531 {
532 IEntity newOwner = null;
533
534 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(rplCompId));
535 if (rplComp)
536 newOwner = rplComp.GetEntity();
537
538 SetProviderEntity(newOwner);
539 }
540
541 //------------------------------------------------------------------------------------------------
542 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
543 protected void RpcDo_SetCompositionLock(bool lockState)
544 {
545 SetInteractionLock(lockState);
546 }
547
548 //------------------------------------------------------------------------------------------------
549 override bool RplSave(ScriptBitWriter writer)
550 {
551 writer.WriteBool(m_bInteractionLock);
552
553 if (!m_ProviderEntity)
554 {
555 writer.WriteBool(0);
556 return true;
557 }
558
559 RplComponent rplComp = RplComponent.Cast(m_ProviderEntity.FindComponent(RplComponent));
560 if (!rplComp)
561 {
562 writer.WriteBool(0);
563 return true;
564 }
565
566 writer.WriteBool(1);
567 writer.WriteRplId(rplComp.Id());
568 writer.WriteInt(m_iBuilderId);
569 return true;
570 }
571
572 //------------------------------------------------------------------------------------------------
573 override bool RplLoad(ScriptBitReader reader)
574 {
575 reader.ReadBool(m_bInteractionLock);
576
577 bool providerExist;
578 reader.ReadBool(providerExist);
579 if (!providerExist)
580 return true;
581
582 reader.ReadRplId(m_RplCompId);
583 reader.ReadInt(m_iBuilderId);
584 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(m_RplCompId));
585 if (!rplComp)
586 {
587 SCR_CampaignBuildingProviderComponent.GetOnProviderCreated().Insert(SetProviderFromRplID);
588 return true;
589 }
590
591 SetProviderEntity(rplComp.GetEntity());
592
593 return true;
594 }
595
596 //------------------------------------------------------------------------------------------------
597 override void OnDelete(IEntity owner)
598 {
599 BaseGameMode gameMode = GetGame().GetGameMode();
600 if (gameMode)
601 {
602 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
603 if (buildingManagerComponent)
604 buildingManagerComponent.UnregisterComposition(this);
605 }
606
607 if (!owner || !m_bPlaySoundOnDeletion)
608 return;
609
610 SCR_SoundManagerModule.CreateAndPlayAudioSource(owner, m_AudioSourceConfigurationDespawn);
611 }
612}
AddonBuildInfoTool id
EEditableEntityBudget
ArmaReforgerScripted GetGame()
Definition game.c:1398
override bool RplLoad(ScriptBitReader reader)
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
override bool RplSave(ScriptBitWriter writer)
void RpcDo_SetCompositionLock(bool lockState)
SCR_CampaignBuildingLayoutComponent GetCompositionLayout()
void RemoveProviderEntityServer()
Remove provider entity when the provider is not a base and the building mode was terminated....
ref ScriptInvokerBool m_OnCompositionSpawned
void SetClearProviderEvent(notnull SCR_EditorModeEntity ent)
void AfterLockChanged(bool lockState)
void DestructibleEntityDestroyed(SCR_DestructionMultiPhaseComponent component)
ref ScriptInvokerVoid m_OnBuilderSet
ScriptInvokerBool GetOnCompositionSpawned()
void SetProviderEntity(IEntity newOwner)
ScriptInvokerVoid GetOnBuilderSet()
void SetProviderFromRplID()
Set a provider, loaded from RPL ID.
SCR_CampaignBuildingLayoutComponent m_CompositionLayout
void SetCanPlaySoundOnDeletion(bool val)
void SetProviderEntityServer(IEntity newOwner)
void OnCompositionSpawned()
An event called on proxi when composition is spawned.
void SetInteractionLock(bool lockState)
void SetInteractionLockServer(bool lockState)
void CompositionBuildSound()
Play the sound when the composition is fully spawned.
void SpawnCompositionLayout(int prefabId, SCR_EditableEntityComponent entity)
void RpcDo_SetProviderEntity(RplId rplCompId)
void SetPrefabId(int prefabId)
ref SCR_AudioSourceConfiguration m_AudioSourceConfigurationDespawn
void RemoveProviderEntity()
Remove provider entity when the provider is not a base and the building mode was terminated.
SCR_CampaignBuildingCompositionComponentClass ScriptComponentClass Attribute()] protected ref SCR_AudioSourceConfiguration m_AudioSourceConfigurationSpawn
void CheckExistingChild()
Check if this entity doesn't have any child. If so, delete it.
void SetCompositionCost(notnull SCR_EditableEntityComponent editableEnt)
void SetDestroyEvents()
Set the destroy event to root entity, when all direct child are destructible.
ResourceName GetOutlineToSpawn(notnull SCR_EditableEntityComponent entity)
Search for the outline that is assigned to this composition to be spawned.
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external IEntity GetSibling()
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
static SCR_BaseEditableEntityFilter GetInstance(EEditableEntityState state, bool showError=false)
bool Validate(SCR_EditableEntityComponent entity)
static IEntityComponentSource GetCampaignBuildingCompositionSource(notnull IEntitySource entitySource)
static float GetProtectionRadius(notnull IEntityComponentSource componentSource)
ResourceName GetCompositionOutline(notnull SCR_EditableEntityComponent entity)
Search all SCR_CampaignBuildingCompositionLayoutManager entry and try to find a matching composition....
ResourceName GetPrefab(bool shorten=false)
void SetEntityFlag(EEditableEntityFlag flag, bool toSet)
Core component to manage SCR_EditorManagerEntity.
SCR_EditorManagerEntity GetEditorManager()
static IEntity GetMainParent(IEntity entity, bool self=false)
proto external GenericEntity GetOwner()
Get owner entity.
void EntitySpawnParams()
Definition gameLib.c:130
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
EEditableEntityFlag
Unique flags of the entity.
EEditableEntityState
SCR_FieldOfViewSettings Attribute
EEditorMode
Editor mode that defines overall functionality.
Definition EEditorMode.c:6
EntityEvent
Various entity events.
Definition EntityEvent.c:14
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