Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditableEntityComponent.c
Go to the documentation of this file.
1
2
8
14{
15 [Attribute("1", UIWidgets.ComboBox, category: "Editable Entity", desc: "Decide whether the entity should be registered automatically to the list of editable entities.", enums: ParamEnumArray.FromEnum(EEditableEntityRegister))]
17
18 [Attribute("", UIWidgets.Auto, category: "Visualization", desc: "Icon offset (m) from entity's origin.")]
19 protected vector m_vIconPos;
20
21 [RplProp()]
23
24 [RplProp(onRplName: "OnRplVisibilityChanged", condition: RplCondition.Custom, customConditionName: "CanReplicateVisibility"), Attribute("1", category: "Visualization", desc: "Set entity's visibility setting. Apart from this custom value, visibility of an entitymay be influenced by other factors like distance to the camera or active layer.")]
25 protected bool m_bVisible;
26
27 [Attribute(category: "Visualization", desc: "Mark entity as static. When static, entity's position is not calculated each frame. Instead, cached position is used.")]
28 protected bool m_bStatic;
29
30 [Attribute("0", category: "Visualization", desc: "Max distance in which the entity is drawn.\nWhen 0 or below, default for given type is used.")]
31 protected float m_fMaxDrawDistance;
32
33 [Attribute("1", UIWidgets.Flags, category: "Editable Entity", desc: "For editor users to edit or even see the entity, at least one of their editor keys must match entity's keys.\nFOr example, if the entity has KEY_1 and KEY_2, while the editor has KEY_2 and KEY_8, the entity will be available, since both have KEY_2.", enums: ParamEnumArray.FromEnum(EEditableEntityAccessKey))]
35
36 [Attribute("", UIWidgets.Flags, category: "Editable Entity", desc: "Set unique flags.", enumType: EEditableEntityFlag)]
38
43 protected ref set<SCR_EditableEntityComponent> m_Entities;
45 protected int m_iIconBoneIndex = -1;
47
48 protected ref SCR_EditableEntityAuthor m_Author;
49 protected int m_iAuthorLastUpdated;
50
51 protected ref set<SCR_EditableEntityComponent> m_aAttachedEntities;
52
53 //------------------------------------------------------------------------------------------------
58 {
59 string displayName;
60
61 //--- Get GUI name
62 SCR_UIInfo info = GetInfo();
63 if (info)
64 displayName = info.GetName();
65
66 if (!displayName.IsEmpty() || !m_Owner)
67 return displayName;
68
69 //--- Get entity name
70 displayName = m_Owner.GetName();
71 if (!displayName.IsEmpty())
72 return "[" + displayName + "]";
73
74 //--- Get class name
75 return "{" + m_Owner.Type().ToString() + "}";
76 }
77
78 //------------------------------------------------------------------------------------------------
82 ResourceName GetPrefab(bool shorten = false)
83 {
84 if (!m_Owner)
85 return ResourceName.Empty;
86
87 EntityPrefabData prefabData = m_Owner.GetPrefabData();
88 if (!prefabData)
89 return ResourceName.Empty;
90
91 ResourceName prefab = prefabData.GetPrefabName();
92 if (!prefab)
93 prefab = SCR_BaseContainerTools.GetPrefabResourceName(prefabData.GetPrefab()); //--- Modified instance, find prefab in ancestors
94
95 if (shorten && prefab)
96 {
97 "{"; // fix indent
98 int guidIndex = prefab.LastIndexOf("}");
99 if (guidIndex >= 0)
100 prefab = prefab.Substring(0, guidIndex + 1);
101 }
102
103 return prefab;
104 }
105
106 //------------------------------------------------------------------------------------------------
111 {
112 if (owner)
114 else if (m_Owner)
116 else
117 return null;
118 }
119
120 //------------------------------------------------------------------------------------------------
128 {
130 if (prefabData)
131 return prefabData.GetEntityType();
132 else
133 return EEditableEntityType.GENERIC;
134 }
135
136 //------------------------------------------------------------------------------------------------
140 {
142 if (prefabData)
143 return prefabData.GetEntityInteraction();
144 else
145 return null;
146 }
147
148 //------------------------------------------------------------------------------------------------
152 {
153 //--- From instance
155 return m_UIInfoInstance;
156
157 //--- From prefab
159 if (prefabData)
160 return prefabData.GetInfo();
161 else
162 return null;
163 }
164
165 //------------------------------------------------------------------------------------------------
171 {
172 if (!m_OnDeleted)
174
175 return m_OnDeleted;
176 }
177
178 //------------------------------------------------------------------------------------------------
183 {
184 m_UIInfoInstance = info;
185 }
186
187 //------------------------------------------------------------------------------------------------
191 bool IsReplicated(out RplId replicationID = -1)
192 {
193 //--- Never considered replicated when flagged as LOCAL
195 return false;
196
197 replicationID = Replication.FindItemId(this);
198 if (replicationID == -1)
199 {
200 //Print(string.Format("Replication ID not found for '%1'!", GetDisplayName()), LogLevel.ERROR);
201 return false;
202 }
203 return true;
204 }
205
206 //------------------------------------------------------------------------------------------------
212 [Obsolete("Only used for backwards compatiblity for GM saves. Will be removed entirely.")]
213 bool Serialize(out SCR_EditableEntityComponent outTarget = null, out int outTargetIndex = -1, out EEditableEntitySaveFlag outSaveFlags = 0)
214 {
215 if (IsDestroyed())
216 outSaveFlags |= EEditableEntitySaveFlag.DESTROYED;
217
218 //--- Children are spawned by the link component, but they were not spawned yet (e.g., in building mode)
219 if ((m_Flags & EEditableEntityFlag.LINKED_CHILDREN) && !SCR_EditorLinkComponent.IsSpawned(this))
220 outSaveFlags |= EEditableEntitySaveFlag.NOT_SPAWNED;
221
222 return !(m_Flags & EEditableEntityFlag.LOCAL) && !(m_Flags & EEditableEntityFlag.NON_SERIALIZABLE);
223 }
224
225 //------------------------------------------------------------------------------------------------
229 [Obsolete("Only used for backwards compatiblity for GM saves. Will be removed entirely.")]
230 void Deserialize(SCR_EditableEntityComponent target, int targetValue)
231 {
232 if (target)
233 SetParentEntity(target);
234 }
235
236 //------------------------------------------------------------------------------------------------
237 protected bool IsServer()
238 {
239 //--- Do we have server rights (LOCAL entities have always full rights)
240 return Replication.IsServer() || Replication.Loadtime() || HasEntityFlag(EEditableEntityFlag.LOCAL);
241 }
242
243 //------------------------------------------------------------------------------------------------
244 protected bool CanRpc()
245 {
246 //--- Check if replication is possible (e.g., not when the game is shutting down) or allowed (e.g., not when flagged as LOCAL)
247 return Replication.IsRunning() && !HasEntityFlag(EEditableEntityFlag.LOCAL);
248 }
249
250 //------------------------------------------------------------------------------------------------
253 {
254 return m_Owner;
255 }
256
257 //------------------------------------------------------------------------------------------------
261 bool GetPos(out vector pos)
262 {
263 if (!m_Owner)
264 return false;
265
266 if (m_bStatic)
267 {
268 //--- Cached position
269 pos = m_vStaticPos;
270 return true;
271 }
272 else if (m_iIconBoneIndex == -1)
273 {
274 //--- Offset position
275 pos = m_Owner.CoordToParent(m_vIconPos);
276 return true;
277 }
278 else
279 {
280 //--- Bone position
281 if (m_Owner.GetAnimation())
282 {
283 vector transform[4];
284 m_Owner.GetAnimation().GetBoneMatrix(m_iIconBoneIndex, transform);
285 pos = m_Owner.CoordToParent(transform[3] + m_vIconPos);
286 }
287 else
288 {
289 pos = m_Owner.CoordToParent(m_vIconPos);
290 }
291 return true;
292 }
293 return false;
294 }
295
296 //------------------------------------------------------------------------------------------------
300 {
301 return m_vIconPos;
302 }
303
304 //------------------------------------------------------------------------------------------------
307 bool GetTransform(out vector outTransform[4])
308 {
309 if (!m_Owner)
310 return false;
311
312 m_Owner.GetTransform(outTransform);
313 return true;
314 }
315
316 //------------------------------------------------------------------------------------------------
319 bool GetLocalTransform(out vector outTransform[4])
320 {
321 if (!m_Owner)
322 return false;
323
324 if (m_Owner.GetParent())
325 {
326 //--- Use engine hierarchy
327 m_Owner.GetLocalTransform(outTransform);
328 }
329 else
330 {
331 //--- Calculate relative trandform towards editor hierarchy parent
332 m_Owner.GetTransform(outTransform);
333 if (m_ParentEntity)
334 {
335 vector parentTransform[4];
336 if (m_ParentEntity.GetTransform(parentTransform))
337 Math3D.MatrixInvMultiply4(parentTransform, outTransform, outTransform);
338 }
339 }
340 return true;
341 }
342
343 //------------------------------------------------------------------------------------------------
347 {
348 return 0;
349 }
350
351 //------------------------------------------------------------------------------------------------
354 void SetAuthor(int playerID)
355 {
356 if (!m_Author)
357 m_Author = new SCR_EditableEntityAuthor();
358
359 m_Author.m_iAuthorID = playerID;
360 m_iAuthorLastUpdated = System.GetUnixTime();
361
362 Rpc(OnAuthorChangedServer, m_Author.m_sAuthorUID, m_Author.m_iAuthorID, "", -1, m_iAuthorLastUpdated);
363 }
364
365 //------------------------------------------------------------------------------------------------
368 void SetAuthor(SCR_EditableEntityAuthor author)
369 {
370 m_Author = author;
371 }
372
373 //------------------------------------------------------------------------------------------------
374 SCR_EditableEntityAuthor GetAuthor()
375 {
376 return m_Author;
377 }
378
379 //------------------------------------------------------------------------------------------------
383 {
384 if (!m_Author)
385 return string.Empty;
386
387 return m_Author.m_sAuthorUID;
388 }
389
390 //------------------------------------------------------------------------------------------------
394 {
395 if (!m_Author)
396 return string.Empty;
397
398 return m_Author.m_sAuthorPlatformID;
399 }
400
401 //------------------------------------------------------------------------------------------------
405 {
406 if (!m_Author)
407 return 0;
408
409 return m_Author.m_iAuthorID;
410 }
411
412 //------------------------------------------------------------------------------------------------
416 {
417 if (!m_Author)
418 return -1;
419
421 }
422
423 //------------------------------------------------------------------------------------------------
426 {
427 if (!m_Author)
428 return PlatformKind.NONE;
429
430 return m_Author.m_ePlatform;
431 }
432
433 //------------------------------------------------------------------------------------------------
436 void SetAuthorUID(string authorUID)
437 {
438 if (!m_Author)
439 return;
440
441 m_Author.m_sAuthorUID = authorUID;
442 }
443
444 //------------------------------------------------------------------------------------------------
445 void SetAuthorPlatformID(string authorPlatformID)
446 {
447 if (!m_Author)
448 return;
449
450 m_Author.m_sAuthorPlatformID = authorPlatformID;
451 }
452
453 //------------------------------------------------------------------------------------------------
456 void SetAuthorUpdatedTime(int updatedLast)
457 {
458 m_iAuthorLastUpdated = updatedLast;
459 }
460
461 //------------------------------------------------------------------------------------------------
462 void SetAuthorPlatform(PlatformKind authorPlatform)
463 {
464 if (!m_Author)
465 return;
466
467 m_Author.m_ePlatform = authorPlatform;
468 }
469
470 //------------------------------------------------------------------------------------------------
474 {
475 return null;
476 }
477
478 //------------------------------------------------------------------------------------------------
483 {
484 return null;
485 }
486
487 //------------------------------------------------------------------------------------------------
492 {
493 return null;
494 }
495
496 //------------------------------------------------------------------------------------------------
500 {
501 return null;
502 }
503
504 //------------------------------------------------------------------------------------------------
508 {
509 return null;
510 }
511
512 //------------------------------------------------------------------------------------------------
516 {
517 return null;
518 }
519
520 //------------------------------------------------------------------------------------------------
525 // to be overridden
526 int GetCrew(out notnull array<CompartmentAccessComponent> crewCompartmentAccess, bool ignorePlayers = true);
527
528 //------------------------------------------------------------------------------------------------
531 float GetHealth()
532 {
533 if (!m_Owner)
534 return 0;
535
537 if (damageManager)
538 return damageManager.GetHealthScaled();
539 else
540 return 1;
541 }
542
543 //------------------------------------------------------------------------------------------------
546 {
548 return damageManager && damageManager.IsDamageHandlingEnabled();
549 }
550
551 //------------------------------------------------------------------------------------------------
555 {
556 if (!m_Owner)
557 return true;
558
560 if (damageManager)
561 return damageManager.GetState() == EDamageState.DESTROYED;
562 else
563 return false;
564 }
565
566 //------------------------------------------------------------------------------------------------
574 void SetStatic(bool isStatic)
575 {
576 if (isStatic && m_Owner.GetFlags() & EntityFlags.ACTIVE)
577 {
578 Print(string.Format("Cannot mark '%1' as static, it's marked as EntityFlags.ACTIVE!", m_Owner), LogLevel.WARNING);
579 return;
580 }
581
582 m_bStatic = isStatic;
583 if (m_bStatic)
585 }
586
587 //------------------------------------------------------------------------------------------------
591 {
592 return m_bStatic;
593 }
594
595 //------------------------------------------------------------------------------------------------
599 {
600 if (!m_bStatic)
601 return;
602
603 m_bStatic = false; //--- Set to false so GetPos() below returns actual position
605 m_bStatic = true;
606 }
607
608 //------------------------------------------------------------------------------------------------
612 {
613 if (!IsServer()) //--- Server-only flag
614 return;
615
617 while (parent)
618 {
619 parent.SetHierarchyAsDirty();
620 parent = parent.GetParentEntity();
621 }
622 }
623
624 //------------------------------------------------------------------------------------------------
628 {
629 m_Flags |= EEditableEntityFlag.DIRTY_HIERARCHY;
630 }
631
632 //------------------------------------------------------------------------------------------------
636 {
637 if (!m_Owner || !IsServer())
638 return;
639
641 SCR_RefPreviewEntity.SpawnAndApplyReference(this, params);
642 }
643
644 //------------------------------------------------------------------------------------------------
648 bool SetTransform(vector transform[4], bool changedByUser = false)
649 {
650 if (!IsServer() || !m_Owner)
651 return false;
652
653 vector position = transform[3];
655 {
656 Physics phys = m_Owner.GetPhysics();
657 float terrainY = m_Owner.GetWorld().GetSurfaceY(position[0], position[2]);
658 if (phys && (phys.IsDynamic() || phys.IsKinematic()) && position[1] > terrainY || float.AlmostEqual(position[1], terrainY, 0.01))
659 return false; // we dont allow for placing of dynamic objects outside of world bounds
660
661 transform[3][1] = terrainY; // if it was only Y that was wrong, then we can snap it to the surface
662 }
663
664 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(m_Owner);
665 if (resourceComponent)
666 {
667 SCR_ResourceGrid resourceGrid = GetGame().GetResourceGrid();
668
669 resourceGrid.IncreaseGridUpdateId();
670 resourceGrid.UpdateResourceItem(resourceComponent);
671 }
672
673 //Inform Scheduler
674 RplComponent rpl = RplComponent.Cast(m_Owner.FindComponent(RplComponent));
675 vector prevTransform[4];
676
677 m_Owner.GetWorldTransform(prevTransform);
678
679 //--- Entities modified by user are always to be serialized.
680 if (changedByUser)
682
683 //--- Not ideal to hard-code speific classes, but we can no longer use BaseGameEntity as it's also used for interactive lights
684 //BaseGameEntity baseGameEntity = BaseGameEntity.Cast(m_Owner);
685 if(!System.IsCLIParam("clientVehicles"))
686 {
687 if (m_Owner.IsInherited(ChimeraCharacter))
688 {
689 //--- Execute on owner, even server doesn't have the authority to do so
690 Rpc(SetTransformOwner, transform);
691 }
692 else if (m_Owner.GetPhysics() && m_Owner.IsInherited(Vehicle))
693 {
694 // TODO: Managed by NwkVehicleMovementComponent if teleportation causes chaotic prediction
695 if (CanRpc()) Rpc(SetTransformOwner, transform);
696 //--- Execute also on server if Vehicle
697 SetTransformOwner(transform);
698 }
699 else
700 {
701 SetTransformBroadcast(transform);
702 if (CanRpc()) Rpc(SetTransformBroadcast, transform);
703 }
704 }
705 else
706 {
707 if (m_Owner.GetPhysics() && (m_Owner.IsInherited(ChimeraCharacter) || m_Owner.IsInherited(Vehicle)))
708 {
709 //--- Execute on owner, even server doesn't have the authority to do so
710 Rpc(SetTransformOwner, transform);
711 }
712 else
713 {
714 SetTransformBroadcast(transform);
715 if (CanRpc()) Rpc(SetTransformBroadcast, transform);
716 }
717 }
718
719 //Sends out on transform changed on server
721 if (core)
722 {
723 core.Event_OnEntityTransformChangedServer.Invoke(this, prevTransform);
724 }
725
726 rpl.ForceNodeMovement(prevTransform[3]);
727 return true;
728 }
729
730 //------------------------------------------------------------------------------------------------
731 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
732 protected void SetTransformOwner(vector transform[4])
733 {
734 BaseGameEntity baseGameEntity = BaseGameEntity.Cast(m_Owner);
735 if (baseGameEntity)
736 {
737 baseGameEntity.Teleport(transform);
738 //baseGameEntity.Update(); //--- Don't call Update, it would make characters fall through ground!
739
740 Physics phys = baseGameEntity.GetPhysics();
741 if (phys)
742 {
743 phys.SetVelocity(vector.Zero);
744 phys.SetAngularVelocity(vector.Zero);
745 }
746 }
747 }
748
749 //------------------------------------------------------------------------------------------------
750 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
751 protected void SetTransformBroadcast(vector transform[4])
752 {
753 if (!m_Owner)
754 return;
755
756 float scale = m_Owner.GetScale();
757 m_Owner.SetWorldTransform(transform);
758 m_Owner.SetScale(scale);
759 m_Owner.Update();
760 m_Owner.OnTransformReset();
762
764 if (core)
765 core.Event_OnEntityTransformChanged.Invoke(this);
766 }
767
768 //------------------------------------------------------------------------------------------------
769 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
770 protected void OnAuthorChangedServer(string authorUID, int authorID, string authorPlatformID, int platform, int lastUpdated)
771 {
772 UUID oldAuthor = m_Author.m_sAuthorUID;
773 UUID newAuthor;
774
776
777 BackendApi backendApi = GetGame().GetBackendApi();
778 if (backendApi)
779 {
780 newAuthor = SCR_PlayerIdentityUtils.GetPlayerIdentityId(authorID);
781
782 if (entityCore && newAuthor != m_Author.m_sAuthorUID && !m_Author.m_sAuthorUID.IsEmpty() && !newAuthor.IsEmpty())
784
785 m_Author.m_ePlatform = backendApi.GetPlayerPlatformKind(authorID);
786 m_Author.m_sAuthorPlatformID = backendApi.GetPlayerPlatformId(authorID);
787 }
788 m_Author.m_iAuthorID = authorID;
789 m_iAuthorLastUpdated = lastUpdated;
790 m_Author.m_sAuthorUID = newAuthor;
791
792 if (entityCore && oldAuthor != m_Author.m_sAuthorUID)
793 entityCore.RegisterAuthorServer(m_Author);
794
795 Rpc(OnAuthorChanged, m_Author.m_sAuthorUID, m_Author.m_iAuthorID, m_Author.m_sAuthorPlatformID, m_Author.m_ePlatform, m_iAuthorLastUpdated);
796 }
797
798 //------------------------------------------------------------------------------------------------
799 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
800 protected void OnAuthorChanged(string authorUID, int authorID, string authorPlatformID, int platform, int lastUpdated)
801 {
802 m_Author.m_ePlatform = platform;
803 m_Author.m_sAuthorPlatformID = authorPlatformID;
804 m_Author.m_sAuthorUID = authorUID;
805 m_Author.m_iAuthorID = authorID;
806 m_iAuthorLastUpdated = lastUpdated;
807 }
808
809 //------------------------------------------------------------------------------------------------
812 bool Destroy(int editorPlayerID = 0)
813 {
814 if (IsServer())
815 {
816 if (!IsDestroyed() && CanDestroy())
817 {
819 Instigator instigator = Instigator.CreateInstigatorGM(editorPlayerID);
820 damageManager.SetAndReplicateInstigator(instigator);
821
822 SCR_DamageManagerComponent scrDamageManager = SCR_DamageManagerComponent.Cast(damageManager);
823 if (scrDamageManager)
824 {
825 scrDamageManager.Kill(instigator);
826 }
827 else
828 {
829 return false;
830 }
831 return true;
832 }
833 }
834 return IsDestroyed();
835 }
836
837 //------------------------------------------------------------------------------------------------
842 bool Delete(bool changedByUser = false, bool updateNavmesh = false)
843 {
844 if (!IsServer())
845 return false;
846
847 //--- Skip if the entity is already being deleted
848 if (!m_Owner || m_Owner.IsDeleted())
849 return true;
850
851 //--- Skip when deleting is disabled
852 if (HasEntityFlag(EEditableEntityFlag.NON_DELETABLE))
853 return false;
854
855 //--- Update navmesh
856 if (updateNavmesh)
857 {
858 SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
859 if (aiWorld)
860 {
861 array<ref Tuple2<vector, vector>> areas = {}; // min, max
862 array<bool> redoAreas = {};
863 aiWorld.GetNavmeshRebuildAreas(GetOwner(), areas, redoAreas);
864 GetGame().GetCallqueue().CallLater(aiWorld.RequestNavmeshRebuildAreas, 1000, false, areas, redoAreas); //--- Called *before* the entity is deleted with a delay, ensures the regeneration doesn't accidentaly get anything from the entity prior to full destruction
865 }
866 }
867
868 //--- Mark parents as dirty
869 if (changedByUser)
871
873
874 if (entityCore && m_Author && !m_Author.m_sAuthorUID.IsEmpty())
876
877 //--- Delete the entity
878 RplComponent.DeleteRplEntity(m_Owner, false);
879
880 return true;
881 }
882
883 //------------------------------------------------------------------------------------------------
886 {
887 RplComponent rpl = GetRplComponent();
888 if (rpl)
889 return rpl.Id();
890 else
891 return RplId.Invalid();
892 }
893
894 //------------------------------------------------------------------------------------------------
898 {
899 return m_fMaxDrawDistance;
900 }
901
902 //------------------------------------------------------------------------------------------------
905 void SetMaxDrawDistance(float maxDrawDistance)
906 {
907 if (maxDrawDistance <= 0)
908 return; //--- ToDo: Load from core?
909
910 m_fMaxDrawDistance = maxDrawDistance * maxDrawDistance;
911 }
912
913 //------------------------------------------------------------------------------------------------
920 {
921 if (owner)
923 else
924 return null;
925 }
926
927 //------------------------------------------------------------------------------------------------
932 bool GetEntityBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
933 {
934 SCR_EditableEntityUIInfo editableEntityUIInfo = SCR_EditableEntityUIInfo.Cast(GetInfo(owner));
935 if (editableEntityUIInfo)
936 editableEntityUIInfo.GetEntityBudgetCost(outBudgets);
937
938 return !outBudgets.IsEmpty();
939 }
940
941 //------------------------------------------------------------------------------------------------
946 bool GetEntityChildrenBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
947 {
948 SCR_EditableEntityUIInfo editableEntityUIInfo = SCR_EditableEntityUIInfo.Cast(GetInfo(owner));
949 if (editableEntityUIInfo)
950 {
951 editableEntityUIInfo.GetEntityChildrenBudgetCost(outBudgets);
952 }
953 return !outBudgets.IsEmpty();
954 }
955
956 //------------------------------------------------------------------------------------------------
959 bool GetEntityAndChildrenBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
960 {
961 SCR_EditableEntityUIInfo editableEntityUIInfo = SCR_EditableEntityUIInfo.Cast(GetInfo(owner));
962 if (editableEntityUIInfo)
963 editableEntityUIInfo.GetEntityAndChildrenBudgetCost(outBudgets);
964
965 return !outBudgets.IsEmpty();
966 }
967
968 //------------------------------------------------------------------------------------------------
971 {
973
974 if(!editableEntityUIInfo)
975 return false;
976
977 //for some goddamn reason turrets have prop budget, but consume vehicle budgets
978 if(budgetToFind == EEditableEntityBudget.VEHICLES)
979 {
980 if(SCR_EditableVehicleUIInfo.Cast(editableEntityUIInfo))
981 return true;
982 }
983
985
986 if(core.GetBudgetForEntityType(editableEntityUIInfo.GetEntityType()) == budgetToFind)
987 return true;
988
989 array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
990
991 GetEntityAndChildrenBudgetCost(entityBudgetCosts, GetOwner());
992
993 //if the entity has the budget we want to find, return true
994 foreach (SCR_EntityBudgetValue budgetCost : entityBudgetCosts)
995 {
996 if(budgetCost.GetBudgetType() != budgetToFind)
997 continue;
998
999 return true;
1000 }
1001
1002 return false;
1003 }
1004
1005 //------------------------------------------------------------------------------------------------
1010 bool CanDuplicate(out notnull set<SCR_EditableEntityComponent> outRecipients)
1011 {
1012 if (HasEntityFlag(EEditableEntityFlag.NON_INTERACTIVE))
1013 return false;
1014
1016 if (factionAffiliationComponent)
1017 {
1018 Faction faction = factionAffiliationComponent.GetAffiliatedFaction();
1020 if (delegateFactionManager)
1021 {
1022 SCR_EditableFactionComponent factionDelegate = delegateFactionManager.GetFactionDelegate(faction);
1023 if (factionDelegate)
1024 outRecipients.Insert(factionDelegate);
1025 }
1026 }
1027 return true;
1028 }
1029
1031 //--- Parent / child management
1033
1038
1039 //------------------------------------------------------------------------------------------------
1044 {
1046 if (!interaction)
1047 return false;
1048
1049 //--- Assumed defaults. ToDo: Receive from client
1051
1052 if (!IsDestroyed())
1053 interactionFlags |= EEditableEntityInteractionFlag.ALIVE;
1054
1055 if (GetPlayerID() == 0)
1056 interactionFlags |= EEditableEntityInteractionFlag.NON_PLAYABLE;
1057
1058 return interaction.CanSetParent(parentEntity, interactionFlags);
1059 }
1060
1061 //------------------------------------------------------------------------------------------------
1069 {
1070 //--- Not on server or not replicated, ignore
1071 if (!IsServer()/* || !IsReplicated()*/)
1072 return parentEntity;
1073
1074 //--- No change, ignore
1075 if (parentEntity == m_ParentEntity)
1076 return parentEntity;
1077
1078 //--- When trying to add the entity to a existing group, if that group is inactive (eg: all entities are neutralized)
1079 //--- returns the already existing parent, thus not adding to the new group (which is inactive)
1080 if (parentEntity && SCR_ChimeraCharacter.Cast(parentEntity.GetOwner()) && parentEntity.IsDestroyed())
1081 return m_ParentEntity;
1082
1083 if (parentEntity)
1084 {
1085 //--- Setting to itself, ignore and notify
1086 if (parentEntity == this)
1087 {
1088 Log("Cannot set parent to itself!", true, LogLevel.WARNING);
1089 return parentEntity;
1090 }
1091
1092 //--- Setting to itself, ignore and notify
1093 if (parentEntity.IsChildOf(this))
1094 {
1095 Log(string.Format("Cannot set parent to its own child %1!", parentEntity), true, LogLevel.WARNING);
1096 return parentEntity;
1097 }
1098 }
1099
1100 //--- Check if changing parent is allowed
1101 if (!CanSetParent(parentEntity))
1102 {
1103 //Log(string.Format("Cannot set parent to %1, interaction condition not met!", parentEntity), true, LogLevel.WARNING);
1104 return parentEntity; //--- ToDo: Notification for the user
1105 }
1106
1107 //--- Set and broadcast
1109 SetParentEntityBroadcast(parentEntity, parentPrev, changedByUser);
1110 if (CanRpc())
1111 Rpc(SetParentEntityBroadcastReceive, Replication.FindItemId(parentEntity), Replication.FindItemId(parentPrev), changedByUser);
1112
1113 return parentEntity;
1114 }
1115
1116 //------------------------------------------------------------------------------------------------
1120 {
1121 //--- Not on server or not replicated, ignore
1122 if (!IsServer()/* || !IsReplicated()*/)
1123 return;
1124
1126 if (CanRpc())
1127 {
1128 int parentEntityID = Replication.FindItemId(m_ParentEntity);
1129 Rpc(SetParentEntityBroadcastReceive, parentEntityID, parentEntityID, false);
1130 }
1131 }
1132
1133 //------------------------------------------------------------------------------------------------
1138 {
1139 //--- Not on server or not replicated, ignore
1140 if (!IsServer()/* || !IsReplicated()*/)
1141 return;
1142
1143 if (IsRegistered())
1144 {
1145 OnRegistrationChanged(false);
1146 if (CanRpc())
1147 Rpc(OnRegistrationChanged, false);
1148 }
1149 }
1150
1151 //------------------------------------------------------------------------------------------------
1158
1159 //------------------------------------------------------------------------------------------------
1162 void GetParentEntities(out notnull array<SCR_EditableEntityComponent> entities)
1163 {
1164 entities.Clear();
1166 while (parent)
1167 {
1168 entities.Insert(parent);
1169 parent = parent.GetParentEntity();
1170 }
1171 }
1172
1173 //------------------------------------------------------------------------------------------------
1178 {
1180 while (parent)
1181 {
1182 if (parent == entity)
1183 return true;
1184
1185 parent = parent.GetParentEntity();
1186 }
1187 return false;
1188 }
1189
1190 //------------------------------------------------------------------------------------------------
1195 set<SCR_EditableEntityComponent> GetChildrenRef()
1196 {
1197 return m_Entities;
1198 }
1199
1200 //------------------------------------------------------------------------------------------------
1206 void GetChildren(out notnull set<SCR_EditableEntityComponent> entities, bool onlyDirect = false, bool skipIgnored = false)
1207 {
1208 if (!m_Entities)
1209 return;
1210
1211 foreach (SCR_EditableEntityComponent entity : m_Entities)
1212 {
1213 if (!entity || (skipIgnored && entity.HasEntityFlag(EEditableEntityFlag.IGNORE_LAYERS)))
1214 continue;
1215
1216 entities.Insert(entity);
1217 if (!onlyDirect)
1218 entity.GetChildren(entities, onlyDirect, skipIgnored);
1219 }
1220 }
1221
1222 //------------------------------------------------------------------------------------------------
1227 void GetChildren(out notnull set<SCR_EditableEntityComponent> entities, bool onlyDirect, EEditableEntityAccessKey accessKey)
1228 {
1229 if (!m_Entities)
1230 return;
1231
1232 entities.Clear();
1233 foreach (SCR_EditableEntityComponent entity : m_Entities)
1234 {
1235 if (!entity)
1236 continue;
1237
1238 if (entity.HasAccessSelf(accessKey))
1239 {
1240 entities.Insert(entity);
1241 if (!onlyDirect)
1242 entity.GetChildren(entities, onlyDirect, accessKey);
1243 }
1244 }
1245 }
1246
1247 //------------------------------------------------------------------------------------------------
1251 int GetChildrenCount(bool onlyDirect = false)
1252 {
1253 if (!m_Entities)
1254 return 0;
1255
1256 if (onlyDirect)
1257 {
1258 return m_Entities.Count();
1259 }
1260 else
1261 {
1262 int count = m_Entities.Count();
1263 foreach (SCR_EditableEntityComponent child : m_Entities)
1264 {
1265 if (!child) //--- TODO: unsure why this is triggered
1266 continue;
1267
1268 count += child.GetChildrenCount(onlyDirect);
1269 }
1270 return count;
1271 }
1272 }
1273
1274 //------------------------------------------------------------------------------------------------
1279 {
1280 if (!m_Entities.IsIndexValid(index))
1281 return null;
1282
1283 return m_Entities[index];
1284 }
1285
1286 //------------------------------------------------------------------------------------------------
1289 bool IsLayer()
1290 {
1291 return m_Entities && !m_Entities.IsEmpty();
1292 }
1293
1294 //------------------------------------------------------------------------------------------------
1299 bool CanEnterLayer(SCR_LayersEditorComponent layersManager = null, bool toExtreme = false)
1300 {
1301 if (!layersManager)
1302 {
1304
1305 if (!layersManager)
1306 return false;
1307 }
1308
1309 return this != layersManager.GetCurrentLayer() //--- Entity is not the current layer
1310 && HasEntityFlag(EEditableEntityFlag.LAYER) //--- Entity is layer
1311 && (!toExtreme || GetParentEntity() != layersManager.GetCurrentLayer());
1312 }
1313
1314 //------------------------------------------------------------------------------------------------
1319 {
1320 return m_bAutoRegister == -1;
1321 }
1322
1323
1324 //------------------------------------------------------------------------------------------------
1327 // to be overridden
1328 void ForceVehicleCompartments(notnull array<ECompartmentType> forceVehicleCompartments);
1329
1330 //------------------------------------------------------------------------------------------------
1331 protected void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
1332 {
1333 m_ParentEntity = parentEntity;
1334
1335 if (parentEntity != parentEntityPrev)
1336 RemoveFromParent(parentEntityPrev, changedByUser);
1337
1338 AddToParent(parentEntity, changedByUser);
1339
1341 if (core)
1342 core.Event_OnParentEntityChanged.Invoke(this, parentEntity, parentEntityPrev);
1343 }
1344
1345 //------------------------------------------------------------------------------------------------
1346 protected void SetParentEntityBroadcast(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser = false, bool isAutoRegistration = false)
1347 {
1348 //if (!CanSetParent(parentEntity)) //--- Prevents players from being registered. ToDo: Fix
1349 // return;
1350
1351 //--- Not registered, do it first (when allowed) and exit. This function will be called again from Register()
1352 if (!IsRegistered())
1353 {
1354 //--- Only when auto-registration is set to ALWAYS, not NEVER
1355 if (!isAutoRegistration || m_bAutoRegister <= EEditableEntityRegister.ALWAYS)
1356 {
1357 m_ParentEntity = parentEntity;
1359 }
1360 return;
1361 }
1362
1363 //--- Modify entity's parent when...
1364 if (
1365 //--- ...parent is root and entity is registered
1366 (!parentEntity && IsRegistered())
1367 ||
1368 //--- ...parent is an entity and it has the same registration as this entity (so that registration doesn't change)
1369 (parentEntity && parentEntity.IsRegistered() == IsRegistered())
1370 )
1371 {
1372 OnParentEntityChanged(parentEntity, parentEntityPrev, changedByUser);
1373 }
1374 }
1375
1376 //------------------------------------------------------------------------------------------------
1377 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1378 protected void SetParentEntityBroadcastReceive(RplId parentEntityID, RplId parentEntityPrevID, bool changedByUser)
1379 {
1380 SCR_EditableEntityComponent parentEntity = SCR_EditableEntityComponent.Cast(Replication.FindItem(parentEntityID));
1381 SCR_EditableEntityComponent parentEntityPrev = SCR_EditableEntityComponent.Cast(Replication.FindItem(parentEntityPrevID));
1382
1383 //--- When parent entity was not streamed in yet, register this entity as an orphan that will be fully registered after the parent is initialized
1384 if (
1385 (parentEntityID.IsValid() && !parentEntity) //--- Parent expected, but not found
1386 || (parentEntity && !parentEntity.IsRegistered()) //--- Parent found, but not registered yet (e.g., when Replication order is different)
1387 )
1388 {
1390 core.AddOrphan(parentEntityID, Replication.FindItemId(this));
1391 }
1392 else
1393 {
1394 SetParentEntityBroadcast(parentEntity, parentEntityPrev, changedByUser);
1395 }
1396 }
1397
1398 //------------------------------------------------------------------------------------------------
1399 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1400 protected void OnRegistrationChanged(bool toRegister)
1401 {
1402 set<SCR_EditableEntityComponent> children = new set<SCR_EditableEntityComponent>();
1403 GetChildren(children);
1404
1405 if (toRegister)
1406 {
1407 Register();
1408 foreach (SCR_EditableEntityComponent child : children)
1409 {
1410 child.Register();
1411 }
1412 }
1413 else
1414 {
1415 Unregister();
1416 foreach (SCR_EditableEntityComponent child : children)
1417 {
1418 child.Unregister();
1419 }
1420 }
1421 }
1422
1423 //------------------------------------------------------------------------------------------------
1425 {
1426 return m_bAutoRegister;
1427 }
1428
1429 //------------------------------------------------------------------------------------------------
1430 protected void Register()
1431 {
1432 if (GetGame().GetWorld() != m_Owner.GetWorld())
1433 return;
1434
1435 if (IsRegistered())
1436 return;
1437
1438 m_bAutoRegister = -1; //--- Mark as registered locally
1440 if (core)
1441 core.RegisterEntity(this);
1442
1444
1445 //--- Restore orphaned entites belonging to this parent
1446 array<SCR_EditableEntityComponent> orphans = {};
1447 for (int i = 0, count = core.RemoveOrphans(Replication.FindItemId(this), orphans); i < count; i++)
1448 {
1449 orphans[i].SetParentEntityBroadcast(this, orphans[i].GetParentEntity());
1450 Print(string.Format("Editor parent %1 restored for orphan %2", this, orphans[i]), LogLevel.VERBOSE);
1451 }
1452 }
1453
1454 //------------------------------------------------------------------------------------------------
1455 protected void Unregister(IEntity owner = null)
1456 {
1457 if (!IsRegistered())
1458 return;
1459
1460 m_bAutoRegister = EEditableEntityRegister.ALWAYS; //--- Mark as unregistered locally
1461
1463 if (core)
1464 core.UnRegisterEntity(this, owner);
1465 }
1466
1467 //------------------------------------------------------------------------------------------------
1469 // to be overridden
1470 void OnCreatedServer(notnull SCR_PlacingEditorComponent placedEditorComponent);
1471
1472 //------------------------------------------------------------------------------------------------
1473 protected void AddToParent(SCR_EditableEntityComponent parentEntity, bool changedByUser)
1474 {
1475 if (parentEntity)
1476 {
1477 parentEntity.AddChild(this);
1478
1479 //--- Mark a dirty
1480 if (changedByUser)
1482 }
1483 else
1484 {
1486 if (core)
1487 core.AddToRoot(this);
1488 }
1489 }
1490
1491 //------------------------------------------------------------------------------------------------
1492 protected void RemoveFromParent(SCR_EditableEntityComponent parentEntity, bool changedByUser)
1493 {
1494 if (parentEntity)
1495 {
1496 //--- Mark a dirty
1497 if (changedByUser)
1499
1500 parentEntity.RemoveChild(this);
1501 }
1502 else
1503 {
1505 if (core)
1506 core.RemoveFromRoot(this);
1507 }
1508 }
1509
1510 //------------------------------------------------------------------------------------------------
1512 {
1513 if (entity.GetParentEntity() != this)
1514 return;
1515
1516 //--- Add to editor hierarchy
1517 if (!m_Entities)
1518 m_Entities = new set<SCR_EditableEntityComponent>();
1519 m_Entities.Insert(entity);
1520
1521 //--- Add to game hierarchy as well
1522 if (entity.HasEntityFlag(EEditableEntityFlag.GAME_HIERARCHY))
1523 UpdateGameHierarchy(m_Owner, entity.GetOwner(), true);
1524
1525 entity.SetEntityFlag(EEditableEntityFlag.VIRTUAL, true);
1526
1527 OnChildEntityChanged(entity, true);
1528 }
1529
1530 //------------------------------------------------------------------------------------------------
1532 {
1533 if (entity.GetParentEntity() == this || !m_Entities)
1534 return;
1535
1536 //--- Not a child of this entity, ignore
1537 int index = m_Entities.Find(entity);
1538 if (index == -1)
1539 return;
1540
1541 //--- Remove from editor hierarchy
1542 m_Entities.Remove(index);
1543 if (m_Entities.IsEmpty())
1544 m_Entities = null;
1545
1546 //--- Remove from game hierarchy
1547 if (entity.HasEntityFlag(EEditableEntityFlag.GAME_HIERARCHY))
1548 UpdateGameHierarchy(m_Owner, entity.m_Owner, false); //--- Don't use entity.GetOwner(), would cause a crash when closing the game
1549
1550 OnChildEntityChanged(entity, false);
1551 }
1552
1553 //------------------------------------------------------------------------------------------------
1554 protected void UpdateGameHierarchy(IEntity parent, IEntity child, bool toAdd)
1555 {
1556 if (!parent || !child)
1557 return;
1558
1559 if (parent && parent.IsDeleted())
1560 return;
1561 if (child && child.IsDeleted())
1562 return;
1563
1564 //--- Modify the hierarchy (on clients as well; ToDo: Rely on AutoHierarchy in RplComponent)
1565 if (toAdd)
1566 {
1567 parent.AddChild(child, -1, EAddChildFlags.AUTO_TRANSFORM | EAddChildFlags.RECALC_LOCAL_TRANSFORM);
1568 }
1569 else
1570 {
1571 vector transform[4];
1572 child.GetWorldTransform(transform);
1573 parent.RemoveChild(child);
1574 child.SetWorldTransform(transform);
1575 }
1576 }
1577
1578 //------------------------------------------------------------------------------------------------
1579 //--- To be overloaded by inherited classes
1580 protected void OnChildEntityChanged(SCR_EditableEntityComponent child, bool isAdded);
1581
1583 //--- State (local)
1585
1586 //------------------------------------------------------------------------------------------------
1591 {
1592 return (m_EntityState & state) == state;
1593 }
1594
1595 //------------------------------------------------------------------------------------------------
1602
1603 //------------------------------------------------------------------------------------------------
1609 void SetEntityState(EEditableEntityState state, bool toSet)
1610 {
1611 if (toSet)
1612 {
1613 if (m_EntityState & state)
1614 return;
1615
1616 m_EntityState = m_EntityState | state;
1617 }
1618 else
1619 {
1620 if (!(m_EntityState & state))
1621 return;
1622
1623 m_EntityState = m_EntityState &~ state;
1624 }
1625
1627 SetEntityStateInChildren(m_Owner, state, toSet);
1628
1629 //--- Global event call disabled, takes too much performance when editor mode is being initialized
1630 //SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore));
1631 //if (core) core.Event_OnEntityStateChanged.Invoke(this, state, toSet);
1632 }
1633
1634 //------------------------------------------------------------------------------------------------
1637 {
1639 m_EntityState = 0;
1640
1642 SetEntityStateInChildren(m_Owner, state, false);
1643
1644// //--- Deconstruct state flags and call handlers on each individual flag
1645// SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore));
1646// int state = 1;
1647// while (m_EntityState > 0 && state < int.MAX)
1648// {
1649// if (m_EntityState & state)
1650// {
1651// SetEntityStateInChildren(m_Owner, state, false);
1652// //if (core) core.Event_OnEntityStateChanged.Invoke(this, state, false);
1653// m_EntityState -= state;
1654// }
1655// state *= 2;
1656// }
1657 }
1658
1659 //------------------------------------------------------------------------------------------------
1664 {
1665 return (m_Flags & flag) == flag;
1666 }
1667
1668 //------------------------------------------------------------------------------------------------
1672 {
1673 return m_Flags;
1674 }
1675
1676 //------------------------------------------------------------------------------------------------
1680 void SetEntityFlag(EEditableEntityFlag flag, bool toSet)
1681 {
1682 if (toSet)
1683 {
1684 if (m_Flags & flag)
1685 return;
1686
1687 m_Flags = m_Flags | flag;
1688 }
1689 else
1690 {
1691 if (!(m_Flags & flag))
1692 return;
1693
1694 m_Flags = m_Flags &~ flag;
1695 }
1696 }
1697
1698 //------------------------------------------------------------------------------------------------
1705
1706 //------------------------------------------------------------------------------------------------
1707 protected void SetEntityStateInChildren(IEntity owner, EEditableEntityState state, bool toSet, out array<Managed> components = null)
1708 {
1709 if (!owner)
1710 return;
1711
1712 //~ Get editable entity
1714
1715 //~ Stop on editable entity that is not owner and does not have the VIRTUAL flag
1716 if (owner != m_Owner && editableEntity && !SCR_Enum.HasFlag(editableEntity.GetEntityFlags(), EEditableEntityFlag.VIRTUAL))
1717 return;
1718
1719 //--- Call event on all SCR_EditableEntityBaseChildComponent on this entity
1720 if (!components)
1721 components = {};
1722
1723 int componentsCount = owner.FindComponents(SCR_EditableEntityBaseChildComponent, components);
1724 for (int i = 0; i < componentsCount; i++)
1725 {
1727 if (component && component.CanApply(state))
1728 component.EOnStateChanged(GetEntityStates(), state, toSet);
1729 }
1730
1731 //--- Go deeper
1732 IEntity child = owner.GetChildren();
1733 while (child)
1734 {
1735 SetEntityStateInChildren(child, state, toSet, components);
1736 child = child.GetSibling();
1737 }
1738 }
1739
1741 //--- Visibility (local)
1743
1744 //------------------------------------------------------------------------------------------------
1745 protected void OnVisibilityChanged()
1746 {
1748 if (core)
1749 core.Event_OnEntityVisibilityChanged.Invoke(this);
1750 }
1751
1756
1757 //------------------------------------------------------------------------------------------------
1761 void SetVisible(bool show)
1762 {
1763 m_bVisible = show;
1765
1766 RplComponent rpl = GetRplComponent();
1767 if (rpl && !rpl.IsProxy())
1768 Replication.BumpMe();
1769 }
1770
1771 //------------------------------------------------------------------------------------------------
1775 {
1776 RplComponent rpl = GetRplComponent();
1777 if (!rpl || rpl.IsProxy())
1778 return;
1779
1781 Replication.BumpMe();
1782 }
1783
1784 //------------------------------------------------------------------------------------------------
1790
1791 //------------------------------------------------------------------------------------------------
1794 {
1796 }
1797
1798 //------------------------------------------------------------------------------------------------
1802 {
1803 //return HasEntityState(EEditableEntityState.VISIBLE);
1804 return m_bVisible;
1805 }
1806
1807 //------------------------------------------------------------------------------------------------
1811 {
1812 if (m_ParentEntity)
1813 return m_ParentEntity.GetVisibleInHierarchy();
1814 else
1815 return GetVisibleSelf();
1816 }
1817
1818
1820 //--- Access key
1822
1823 //------------------------------------------------------------------------------------------------
1824 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
1826 {
1827 m_AccessKey = accessKey;
1828
1830 if (!core)
1831 return;
1832
1833 core.Event_OnEntityAccessKeyChanged.Invoke(this);
1834
1835 //--- Execute handler also on all children
1836 SCR_AccessKeysEditorComponent accessKeysComponent = SCR_AccessKeysEditorComponent.Cast(SCR_AccessKeysEditorComponent.GetInstance(SCR_AccessKeysEditorComponent));
1837 EEditableEntityAccessKey editorAccessKey = -1;
1838 if (accessKeysComponent)
1839 editorAccessKey = accessKeysComponent.GetAccessKey();
1840
1841 set<SCR_EditableEntityComponent> children = new set<SCR_EditableEntityComponent>;
1842 GetChildren(children, false, editorAccessKey);
1843 foreach (SCR_EditableEntityComponent child : children)
1844 {
1845 core.Event_OnEntityAccessKeyChanged.Invoke(child);
1846 }
1847 }
1848
1849 //------------------------------------------------------------------------------------------------
1857
1862 {
1863 if (!IsServer()/* || !IsReplicated()*/ || HasAccessSelf(accessKey))
1864 return;
1865
1866 m_AccessKey = m_AccessKey | accessKey;
1868 if (CanRpc())
1870 }
1871
1872 //------------------------------------------------------------------------------------------------
1877 {
1878 if (!IsServer()/* || !IsReplicated()*/ || !HasAccessSelf(accessKey))
1879 return;
1880 m_AccessKey = m_AccessKey &~ accessKey;
1882 if (CanRpc())
1884 }
1885
1886 //------------------------------------------------------------------------------------------------
1890 {
1891 if (!IsServer()/* || !IsReplicated()*/)
1892 return;
1893
1894 m_AccessKey = 0;
1896 if (CanRpc())
1898 }
1899
1900 //------------------------------------------------------------------------------------------------
1907
1908 //------------------------------------------------------------------------------------------------
1913 {
1914 return m_AccessKey & accessKey;// || accessKey == int.MAX; //--- Enable this to let admin see also entities without any key
1915 }
1916
1917 //------------------------------------------------------------------------------------------------
1922 {
1923 if (m_ParentEntity)
1924 return m_ParentEntity.HasAccessInHierarchy(accessKey);
1925 else
1926 return HasAccessSelf(accessKey);
1927 }
1928
1929 //------------------------------------------------------------------------------------------------
1933 {
1934 SCR_AccessKeysEditorComponent accessKeysComponent = SCR_AccessKeysEditorComponent.Cast(SCR_AccessKeysEditorComponent.GetInstance(SCR_AccessKeysEditorComponent));
1935 if (!accessKeysComponent)
1936 return true;
1937
1938 return HasAccessSelf(accessKeysComponent.GetAccessKey());
1939 }
1940
1941 //------------------------------------------------------------------------------------------------
1946 {
1947 SCR_AccessKeysEditorComponent accessKeysComponent = SCR_AccessKeysEditorComponent.Cast(SCR_AccessKeysEditorComponent.GetInstance(SCR_AccessKeysEditorComponent));
1948 if (!accessKeysComponent)
1949 return true;
1950
1951 return HasAccessInHierarchy(accessKeysComponent.GetAccessKey());
1952 }
1953
1954
1956 //--- Support Functions
1958
1959 //------------------------------------------------------------------------------------------------
1960 //--- Will send event for GUI to refresh instantly, to be called from inherited classes in case initialization takes a bit longer.
1961 protected void Refresh()
1962 {
1964 if (core)
1965 core.Event_OnEntityRefreshed.Invoke(this);
1966 }
1967
1968 //------------------------------------------------------------------------------------------------
1969 protected RplComponent GetRplComponent()
1970 {
1971 return RplComponent.Cast(GetOwner().FindComponent(RplComponent));
1972 }
1973
1974 //------------------------------------------------------------------------------------------------
1975 protected bool ValidateType()
1976 {
1977 switch (GetEntityType())
1978 {
1979 case EEditableEntityType.CHARACTER:
1980 return m_Owner.IsInherited(ChimeraCharacter) || m_Owner.FindComponent(SCR_EditablePlayerDelegateComponent) != null;
1981
1982 //--- No longer valid, tripods are considered vehicles even when not inheriting from class Vehicle
1983 //case EEditableEntityType.VEHICLE:
1984 // return m_Owner.IsInherited(Vehicle);
1985
1986 case EEditableEntityType.GROUP:
1987 return m_Owner.IsInherited(AIGroup);
1988
1989 case EEditableEntityType.WAYPOINT:
1990 return m_Owner.IsInherited(AIWaypoint);
1991
1992 case EEditableEntityType.COMMENT:
1993 return this.IsInherited(SCR_EditableCommentComponent);
1994
1995 case EEditableEntityType.ITEM:
1996 return m_Owner.FindComponent(InventoryItemComponent) != null;
1997 }
1998 return true;
1999 }
2000
2002 //--- Log
2004
2005 //------------------------------------------------------------------------------------------------
2008 string GetLogText(string prefix = "")
2009 {
2010 string displayName = GetDisplayName();
2011 string prefabName;
2012 EntityPrefabData prefabData = m_Owner.GetPrefabData();
2013 if (prefabData)
2014 prefabName = FilePath.StripPath(prefabData.GetPrefabName());
2015
2016 string space = " ";
2017 for (int i = 0; i < 50 - prefix.Length() - displayName.Length(); i++)
2018 {
2019 space += " ";
2020 }
2021
2022 return string.Format("%1%2 | entity: %3, prefab: '%4', pos: %5, flags: %6", displayName, space, m_Owner, prefabName, m_Owner.GetOrigin(), SCR_Enum.FlagsToString(EEditableEntityFlag, m_Flags));
2023 }
2024
2025 //------------------------------------------------------------------------------------------------
2030 void Log(string prefix = "", bool onlyDirect = false, LogLevel logLevel = LogLevel.DEBUG)
2031 {
2032 if (!m_Owner)
2033 {
2034 Print(string.Format(prefix + " - Error: Null m_Owner in %1", this), LogLevel.WARNING);
2035 return;
2036 }
2037
2038 if (m_Entities && !m_Entities.IsEmpty())
2039 {
2040 Print(prefix + "+ " + GetLogText(prefix), logLevel);
2041 if (onlyDirect)
2042 return;
2043
2044 foreach (SCR_EditableEntityComponent entity : m_Entities)
2045 {
2046 if (entity)
2047 entity.Log(prefix + " ");
2048 else
2049 Log(string.Format(prefix + " - Error: Null child in %1!", this), true, LogLevel.WARNING)
2050 }
2051 }
2052 else
2053 {
2054 Print(prefix + "- " + GetLogText(prefix), logLevel);
2055 }
2056 }
2057
2058 //------------------------------------------------------------------------------------------------
2062 void Log(string prefix, EEditableEntityAccessKey accessKey)
2063 {
2064 if (!m_Owner)
2065 return;
2066
2067 if (m_Entities && !m_Entities.IsEmpty())
2068 {
2069 Print(prefix + "+ " + GetLogText(prefix), LogLevel.DEBUG);
2070 foreach (SCR_EditableEntityComponent entity : m_Entities)
2071 {
2072 if (entity.HasAccessSelf(m_AccessKey))
2073 entity.Log(prefix + " ", accessKey);
2074 }
2075 }
2076 else
2077 {
2078 Print(prefix + "- " + GetLogText(prefix), LogLevel.DEBUG);
2079 }
2080 }
2081
2082 //------------------------------------------------------------------------------------------------
2085 {
2086 string output = "";
2087 typename enumType = EEditableEntityAccessKey;
2088 int enumCount = enumType.GetVariableCount();
2089 for (int i = 0; i < enumCount; i++)
2090 {
2091 int val;
2092 if (enumType.GetVariableType(i) == int && enumType.GetVariableValue(null, i, val))
2093 {
2094 if (HasAccessSelf(val))
2095 {
2096 if (!output.IsEmpty())
2097 output += ", ";
2098
2099 output += enumType.GetVariableName(i);
2100 }
2101 }
2102 }
2103 Print(string.Format("%1 access key: %2", GetDisplayName(), output), LogLevel.DEBUG);
2104 }
2105
2107 //--- External events
2109
2110 //------------------------------------------------------------------------------------------------
2119 {
2120 return this;
2121 }
2122
2123 //------------------------------------------------------------------------------------------------
2127 {
2128 SCR_AIWorld aiWorld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
2129 if (aiWorld)
2131 }
2132
2134 //--- Default functions
2136
2137 //------------------------------------------------------------------------------------------------
2138 //--- JIP on server
2139 override bool RplSave(ScriptBitWriter writer)
2140 {
2141 string authorUID, authorPlatformID;
2142 int platform, authorID;
2143
2144 writer.Write(m_AccessKey, 32);
2145 if (m_Author)
2146 {
2147 authorUID = m_Author.m_sAuthorUID;
2148 authorID = m_Author.m_iAuthorID;
2149 authorPlatformID = m_Author.m_sAuthorPlatformID;
2150 platform = m_Author.m_ePlatform;
2151 }
2152 writer.WriteString(authorUID);
2153 writer.WriteString(authorPlatformID);
2154 writer.WriteInt(platform);
2155 writer.WriteInt(authorID);
2156 writer.WriteInt(m_iAuthorLastUpdated);
2157
2158 RplId parentID = Replication.FindItemId(m_ParentEntity);
2159 writer.WriteRplId(parentID);
2160
2161 return true;
2162 }
2163
2164 //------------------------------------------------------------------------------------------------
2165 //--- JIP on client
2166 override bool RplLoad(ScriptBitReader reader)
2167 {
2168 string authorUID, authorPlatformID;
2169 int platform, authorID;
2170
2171 reader.Read(m_AccessKey, 32);
2172 reader.ReadString(authorUID);
2173 reader.ReadString(authorPlatformID);
2174 reader.ReadInt(platform);
2175 reader.ReadInt(authorID);
2176 reader.ReadInt(m_iAuthorLastUpdated);
2177
2178 m_Author = new SCR_EditableEntityAuthor();
2179 m_Author.Initialize(authorUID, authorPlatformID, platform, authorID);
2180
2181 RplId parentID;
2182 reader.ReadRplId(parentID);
2183
2184 SetParentEntityBroadcastReceive(parentID, parentID, false);
2185
2186 return true;
2187 }
2188
2189 //------------------------------------------------------------------------------------------------
2190 override void OnDelete(IEntity owner)
2191 {
2192 //--- Marked as -1 in constructor when edit mode is active
2193 if (m_EntityState == -1)
2194 return;
2195
2196 if (m_OnDeleted)
2197 m_OnDeleted.Invoke(owner);
2198
2199 //--- Delete entities in editor hierarchy
2200 if (IsServer() && m_Entities)
2201 {
2203 for (int i = m_Entities.Count() - 1; i >= 0; i--)
2204 {
2205 entity = m_Entities[i];
2206 if (!entity.HasEntityFlag(EEditableEntityFlag.GAME_HIERARCHY))
2207 entity.Delete(false);
2208 }
2209 }
2210
2211 //--- Unregister
2213 m_ParentEntity = null; //--- Clear the variable, otherise condition in RemoveChild() would ignore this
2214 RemoveFromParent(parentEntity, false);
2215 Unregister(owner);
2216 }
2217
2218 //------------------------------------------------------------------------------------------------
2219 override void OnPostInit(IEntity owner)
2220 {
2221 if (!m_Owner)
2222 return;
2223
2224 //--- Determine entity type
2225#ifdef WORKBENCH
2226 if (!ValidateType())
2227 Log(string.Format("Wrong type %1 used!", typename.EnumToString(EEditableEntityType, GetEntityType())), true, LogLevel.WARNING);
2228#endif
2229
2230 //--- Update static pos
2232
2233 //--- Exit in edit mode, can wreck havoc when WB thumbnails of editable entities are loaded while the game is running
2234 if (SCR_Global.IsEditMode(owner))
2235 return;
2236
2237 //--- Check for presence of RplComponent. Entity cannot be editable without it.
2238 RplComponent rpl = RplComponent.Cast(m_Owner.FindComponent(RplComponent));
2240 {
2241 if (rpl)
2242 {
2243 Print(string.Format("Editable entity @\"%1\" is flagged as LOCAL, but contains RplComponent!", GetPrefab()), LogLevel.ERROR);
2244 m_Owner = null;
2245 return;
2246 }
2247 }
2248 else
2249 {
2250 if (!rpl)
2251 {
2252 Print(string.Format("Editable entity @\"%1\" is missing RplComponent! Maybe try regenerating it again.", GetPrefab()), LogLevel.ERROR);
2253 m_Owner = null;
2254 return;
2255 }
2256 }
2257
2258 //--- Make sure distance value is squared
2259 if (m_fMaxDrawDistance != 0)
2261
2262 //--- Register to the system
2263 if (IsServer())
2264 SetParentEntityBroadcast(m_ParentEntity, m_ParentEntity, isAutoRegistration: true);
2265
2266 // Register the various entities from catalog that we do not want to put persistence component on all the base prefabs manually.
2268 {
2269 auto persistence = SCR_PersistenceSystem.GetByEntityWorld(owner);
2270 if (persistence)
2271 persistence.StartTracking(owner);
2272 }
2273 }
2274
2275 //------------------------------------------------------------------------------------------------
2276 // constructor
2281 {
2282 if (DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE))
2283 return;
2284
2285 m_Owner = GenericEntity.Cast(ent);
2286
2287 //--- Ignore when not in run-time
2288 if (!GetGame() || SCR_Global.IsEditMode(ent))
2289 {
2290 m_EntityState = -1; //--- Tell destructor and OnDelete to terminate
2291 return;
2292 }
2293
2294 //--- Get bone index on which the icon will be rendered
2296 if (prefabData)
2297 {
2298 string boneName = prefabData.GetIconBoneName();
2299 if (!boneName.IsEmpty())
2300 m_iIconBoneIndex = m_Owner.GetAnimation().GetBoneIndex(boneName);
2301 }
2302
2303 //--- Get parent entity
2304 if (parent)
2305 {
2306 GenericEntity genericParent = GenericEntity.Cast(parent);
2307 SCR_EditableEntityComponent parentEntity;
2308 if (genericParent)
2309 {
2310 parentEntity = SCR_EditableEntityComponent.Cast(genericParent.FindComponent(SCR_EditableEntityComponent));
2311 if (parentEntity)
2312 {
2313 //--- Cannot have worse auto-registration settings than parent (to make sure child entities are registered)
2315 m_bAutoRegister = Math.Min(m_bAutoRegister, parentEntity.GetAutoRegister());
2316
2317 //--- Cannot be marked as registered yet (registered value is -1, see Register())
2319 }
2320 }
2321 m_ParentEntity = parentEntity;
2322 }
2323
2324 //--- When spawned dynamically, change auto-registration WHEN_SPAWNED to ALWAYS
2325 if (m_bAutoRegister == EEditableEntityRegister.WHEN_SPAWNED && !m_Owner.IsLoaded())
2327
2328 //--- Initialize attached entities
2329 m_aAttachedEntities = new set<SCR_EditableEntityComponent>();
2330 }
2331
2332 //------------------------------------------------------------------------------------------------
2335 void Attach(notnull SCR_EditableEntityComponent attachable)
2336 {
2337 if (m_aAttachedEntities.Count() <= EditorConstants.MAX_ATTACHED_ENTITIES)
2338 m_aAttachedEntities.Insert(attachable);
2339 }
2340
2341 //------------------------------------------------------------------------------------------------
2344 void Detach(notnull SCR_EditableEntityComponent attachable)
2345 {
2346 m_aAttachedEntities.RemoveItem(attachable);
2347 }
2348
2349 //------------------------------------------------------------------------------------------------
2352 set<SCR_EditableEntityComponent> GetAttachedEntities()
2353 {
2354 set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
2355
2357 {
2358 entities.Insert(entity);
2359 }
2360
2361 return entities;
2362 }
2363
2364 //------------------------------------------------------------------------------------------------
2368 {
2369 return false;
2370 }
2371
2372 //------------------------------------------------------------------------------------------------
2376 {
2377 return false;
2378 }
2379
2380 //------------------------------------------------------------------------------------------------
2384 {
2385 return null;
2386 }
2387}
2388
2389class SCR_EditableEntityAuthor
2390{
2391 string m_sAuthorUID; // Author's Player UUID
2392 string m_sAuthorPlatformID; // Author's Platform ID
2394 int m_iAuthorID; // Author's Player ID (PlayerManager PlayerID), if the value is -1 it means it was loaded from a save.
2396
2397 //------------------------------------------------------------------------------------------------
2398 void Initialize(string authorUID, string platformID, PlatformKind platform, int authorID)
2399 {
2400 m_sAuthorUID = authorUID;
2401 m_sAuthorPlatformID = platformID;
2402 m_ePlatform = platform;
2403 m_iAuthorID = authorID;
2404 }
2405
2406 //------------------------------------------------------------------------------------------------
2407 int GetAllOwnedEntities(out notnull set<SCR_EditableEntityComponent> entities)
2408 {
2410 if (!core)
2411 {
2412 Print("GetAllOwnedEntities(): SCR_EditableEntityCore was not found!", LogLevel.ERROR);
2413 return 0;
2414 }
2415
2416 return core.GetAllEntitiesByAuthorUID(entities, m_sAuthorUID);
2417 }
2418
2419 //------------------------------------------------------------------------------------------------
2424 static bool Extract(SCR_EditableEntityAuthor instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
2425 {
2426 snapshot.SerializeString(instance.m_sAuthorUID);
2427 snapshot.SerializeString(instance.m_sAuthorPlatformID);
2428 snapshot.SerializeInt(instance.m_ePlatform);
2429 snapshot.SerializeInt(instance.m_iAuthorID);
2430 snapshot.SerializeInt(instance.m_iEntityCount);
2431 return true;
2432 }
2433
2434 //------------------------------------------------------------------------------------------------
2439 static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_EditableEntityAuthor instance)
2440 {
2441 snapshot.SerializeString(instance.m_sAuthorUID);
2442 snapshot.SerializeString(instance.m_sAuthorPlatformID);
2443 snapshot.SerializeInt(instance.m_ePlatform);
2444 snapshot.SerializeInt(instance.m_iAuthorID);
2445 snapshot.SerializeInt(instance.m_iEntityCount);
2446 return true;
2447 }
2448
2449 //------------------------------------------------------------------------------------------------
2453 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
2454 {
2455 snapshot.EncodeString(packet); // m_sAuthorUID
2456 snapshot.EncodeString(packet); // m_sAuthorPlatformID
2457 snapshot.EncodeInt(packet); // m_ePlatform
2458 snapshot.EncodeInt(packet); // m_iAuthorID
2459 snapshot.EncodeInt(packet); // m_iEntityCount
2460 }
2461
2462 //------------------------------------------------------------------------------------------------
2467 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
2468 {
2469 snapshot.DecodeString(packet); // m_sAuthorUID
2470 snapshot.DecodeString(packet); // m_sAuthorPlatformID
2471 snapshot.DecodeInt(packet); // m_ePlatform
2472 snapshot.DecodeInt(packet); // m_iAuthorID
2473 snapshot.DecodeInt(packet); // m_iEntityCount
2474 return true;
2475 }
2476
2477 //------------------------------------------------------------------------------------------------
2482 static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
2483 {
2484 return lhs.CompareStringSnapshots(rhs); // m_sAuthorUID
2485 }
2486
2487 //------------------------------------------------------------------------------------------------
2492 static bool PropCompare(SCR_EditableEntityAuthor instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
2493 {
2494 return snapshot.CompareString(instance.m_sAuthorUID);
2495 }
2496}
SCR_EAIThreatSectorFlags flags
vector scale
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
EEditableEntityBudget
EEditorPlacingFlags
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_CharacterSoundComponentClass GetComponentData()
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_EditableEntityBaseChildComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
string m_sAuthorPlatformID
int GetAllOwnedEntities(out notnull set< SCR_EditableEntityComponent > entities)
PlatformKind m_ePlatform
override SCR_UIInfo GetInfo()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerEntityMethod > ScriptInvokerEntity
override void Log()
proto native external bool IsInherited(typename type)
Backend Api instance.
Definition BackendApi.c:14
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external GenericComponent FindComponent(typename typeName)
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)
proto external Managed FindComponent(typename typeName)
proto external int AddChild(notnull IEntity child, TNodeId pivot, EAddChildFlags flags=EAddChildFlags.AUTO_TRANSFORM)
Add Entity to hierarchy. Pivot is pivot index, or -1 for center of parent.
proto external IEntity GetChildren()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external int FindComponents(typename typeName, notnull array< Managed > outComponents)
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
proto external void RemoveChild(notnull IEntity child, bool keepTransform=false)
Remove Entity from hierarchy.
proto external IEntity GetSibling()
proto external bool IsDeleted()
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
void GetNavmeshRebuildAreas(IEntity entity, out notnull array< ref Tuple2< vector, vector > > outAreas, out notnull array< bool > redoRoads)
void RequestNavmeshRebuildAreas(notnull array< ref Tuple2< vector, vector > > areas, notnull array< bool > redoRoads)
void RequestNavmeshRebuildEntity(IEntity entity)
static Managed GetInstance(typename type, bool showError=false, bool modeFirst=false)
SCR_EditableFactionComponent GetFactionDelegate(Faction faction)
static SCR_DelegateFactionManagerComponent GetInstance()
SCR_EditableEntityInteraction GetEntityInteraction()
bool IsChildOf(SCR_EditableEntityComponent entity)
void SetTransformBroadcast(vector transform[4])
bool Serialize(out SCR_EditableEntityComponent outTarget=null, out int outTargetIndex=-1, out EEditableEntitySaveFlag outSaveFlags=0)
override void OnDelete(IEntity owner)
void GetChildren(out notnull set< SCR_EditableEntityComponent > entities, bool onlyDirect=false, bool skipIgnored=false)
bool EntityHasBudgetOfType(EEditableEntityBudget budgetToFind)
Returns true if the entity consumes this type of budget.
void SetAuthorPlatformID(string authorPlatformID)
SCR_EditableEntityComponentClass GetEditableEntityData(IEntity owner=null)
ResourceName GetPrefab(bool shorten=false)
EEditableEntityAccessKey GetAccessKey()
void LogAccessKey()
Print out entity's access key.
bool HasEntityFlag(EEditableEntityFlag flag)
bool HasAccessInHierarchy(EEditableEntityAccessKey accessKey)
bool SetTransform(vector transform[4], bool changedByUser=false)
SCR_EditableEntityComponent GetChild(int index)
set< SCR_EditableEntityComponent > GetChildrenRef()
void SetParentEntityBroadcastReceive(RplId parentEntityID, RplId parentEntityPrevID, bool changedByUser)
override void OnPostInit(IEntity owner)
void RemoveAccessKey(EEditableEntityAccessKey accessKey)
ref set< SCR_EditableEntityComponent > m_aAttachedEntities
void GetParentEntities(out notnull array< SCR_EditableEntityComponent > entities)
void Log(string prefix="", bool onlyDirect=false, LogLevel logLevel=LogLevel.DEBUG)
void SetAuthorPlatform(PlatformKind authorPlatform)
SCR_EditableEntityComponent EOnEditorPlace(out SCR_EditableEntityComponent parent, SCR_EditableEntityComponent recipient, EEditorPlacingFlags flags, bool isQueue, int playerID=0)
bool GetEntityAndChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
SCR_EditableEntityComponent GetAttachedTo()
void ForceVehicleCompartments(notnull array< ECompartmentType > forceVehicleCompartments)
void SetTransformOwner(vector transform[4])
SCR_EditableEntityComponent m_ParentEntity
void ResetEntityStates()
Reset all entity states.
void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
void OnAccessKeyChanged(EEditableEntityAccessKey accessKey)
SCR_EditableEntityComponent GetAIEntity()
void SetEntityState(EEditableEntityState state, bool toSet)
void SetMaxDrawDistance(float maxDrawDistance)
void SCR_EditableEntityComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
bool GetLocalTransform(out vector outTransform[4])
bool HasEntityState(EEditableEntityState state)
SCR_EditableEntityComponent GetVehicle()
bool Delete(bool changedByUser=false, bool updateNavmesh=false)
static SCR_EditableEntityComponent GetEditableEntity(IEntity owner)
void SetAuthor(SCR_EditableEntityAuthor author)
void SetEntityStateInChildren(IEntity owner, EEditableEntityState state, bool toSet, out array< Managed > components=null)
void EOnEditorSessionLoad(SCR_EditableEntityComponent parent)
EEditableEntityType GetEntityType(IEntity owner=null)
int GetChildrenCount(bool onlyDirect=false)
bool CanEnterLayer(SCR_LayersEditorComponent layersManager=null, bool toExtreme=false)
void AddAccessKey(EEditableEntityAccessKey accessKey)
void Detach(notnull SCR_EditableEntityComponent attachable)
bool CanSetParent(SCR_EditableEntityComponent parentEntity)
void RemoveFromParent(SCR_EditableEntityComponent parentEntity, bool changedByUser)
bool GetTransform(out vector outTransform[4])
bool GetEntityChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
void CopyEntityFlags(EEditableEntityFlag flags)
SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
EEditableEntityRegister GetAutoRegister()
void UpdateGameHierarchy(IEntity parent, IEntity child, bool toAdd)
override bool RplLoad(ScriptBitReader reader)
void GetChildren(out notnull set< SCR_EditableEntityComponent > entities, bool onlyDirect, EEditableEntityAccessKey accessKey)
int GetCrew(out notnull array< CompartmentAccessComponent > crewCompartmentAccess, bool ignorePlayers=true)
bool IsReplicated(out RplId replicationID=-1)
set< SCR_EditableEntityComponent > GetAttachedEntities()
void SetParentEntityBroadcast(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser=false, bool isAutoRegistration=false)
void SetTransformWithChildren(vector transform[4])
void Log(string prefix, EEditableEntityAccessKey accessKey)
void OnAuthorChanged(string authorUID, int authorID, string authorPlatformID, int platform, int lastUpdated)
ref set< SCR_EditableEntityComponent > m_Entities
void SetEntityFlag(EEditableEntityFlag flag, bool toSet)
bool HasAccessSelf(EEditableEntityAccessKey accessKey)
void AddToParent(SCR_EditableEntityComponent parentEntity, bool changedByUser)
void OnChildEntityChanged(SCR_EditableEntityComponent child, bool isAdded)
bool CanDuplicate(out notnull set< SCR_EditableEntityComponent > outRecipients)
SCR_EditableEntityInteraction GetEntityInteraction(IEntity owner=null)
override bool RplSave(ScriptBitWriter writer)
ref SCR_EditableEntityAuthor m_Author
void Attach(notnull SCR_EditableEntityComponent attachable)
void OnAuthorChangedServer(string authorUID, int authorID, string authorPlatformID, int platform, int lastUpdated)
void Deserialize(SCR_EditableEntityComponent target, int targetValue)
void OnCreatedServer(notnull SCR_PlacingEditorComponent placedEditorComponent)
SCR_UIInfo GetInfo(IEntity owner=null)
void RemoveChild(SCR_EditableEntityComponent entity)
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
void AddChild(SCR_EditableEntityComponent entity)
SCR_EditableEntityComponent GetParentEntity()
SCR_EditableEntityComponent GetAIGroup()
EEditableEntityBudget GetBudgetForEntityType(EEditableEntityType entityType)
void RemoveFromRoot(SCR_EditableEntityComponent entity)
int RemoveOrphans(RplId parentId, out notnull array< SCR_EditableEntityComponent > outOrphans)
void RegisterEntity(SCR_EditableEntityComponent entity)
void UnRegisterEntity(SCR_EditableEntityComponent entity, IEntity owner=null)
void AddOrphan(RplId parentId, RplId orphanId)
int GetAllEntitiesByAuthorUID(out notnull set< SCR_EditableEntityComponent > entities, string playerUID)
void RegisterAuthorServer(SCR_EditableEntityAuthor newAuthor)
void AuthorEntityRemovedServer(SCR_EditableEntityAuthor newAuthor)
void AddToRoot(SCR_EditableEntityComponent entity)
sealed bool CanSetParent(SCR_EditableEntityComponent parentEntity, EEditableEntityInteractionFlag interactionFlags=int.MAX)
void GetEntityAndChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get Entity and its children budgets.
EEditableEntityType GetEntityType()
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
void GetEntityChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get only Entity's children budget costs, i.e. cost of entities inside a composition entitiy.
Network packet of variables for entity placing and transformation.
static SCR_EditorPreviewParams CreateParams(vector transform[4], RplId parentID=Replication.INVALID_ID, EEditorTransformVertical verticalMode=EEditorTransformVertical.SEA, bool isUnderwater=false, SCR_EditableEntityComponent target=null, EEditableEntityInteraction targetInteraction=EEditableEntityInteraction.NONE)
static bool IsPositionWithinTerrainBounds(vector pos)
Definition Functions.c:1981
static bool IsEditMode()
Definition Functions.c:1566
static sealed SCR_PersistenceSystem GetByEntityWorld(IEntity entity)
void UpdateResourceItem(notnull SCR_ResourceComponent item)
proto external GenericEntity GetOwner()
Get owner entity.
Definition UUID.c:28
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
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
EEditableEntityRegister
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
SCR_EditableEntityComponent m_sAuthorUID
EEditableEntityAccessKey
EEditableEntitySaveFlag
EEditableEntityFlag
Unique flags of the entity.
EEditableEntityState
SCR_FieldOfViewSettings Attribute
EEditorTransformVertical
Vertical transformation mode.
EEditableEntityInteractionFlag
Details of entity interaction.
EAddChildFlags
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EDamageState
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134