Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIOpenDoor.c
Go to the documentation of this file.
2{
3 static const string PORT_DOOR_ENTITY = "DoorEntity";
4 static const float STATE_EPSILON = 0.01;
5
6 [Attribute("0")]
7 protected bool m_bOpenSiblingDoors;
8
9 //------------------------------------------------------------------------------------------------
10 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
11 {
12 IEntity doorEntity;
13 GetVariableIn(PORT_DOOR_ENTITY, doorEntity);
14
15 if (!doorEntity)
16 return ENodeResult.FAIL;
17
18 array<ScriptedUserAction> doorActions = {};
19 FindDoorActions(doorEntity, doorActions, m_bOpenSiblingDoors);
20
21 if (doorActions.IsEmpty())
22 return ENodeResult.FAIL;
23
24 IEntity actionPerformer = owner.GetControlledEntity();
25 if (!actionPerformer)
26 actionPerformer = owner;
27
28 bool isOpened = true;
29
30 foreach (ScriptedUserAction action : doorActions)
31 {
32 IEntity actionOwner = action.GetOwner();
33 if (!actionOwner)
34 continue;
35 DoorComponent doorComp = DoorComponent.Cast(actionOwner.FindComponent(DoorComponent));
36 if (!doorComp)
37 continue;
38
39 bool isTotallyOpen = Math.AbsFloat(doorComp.GetNormalizedDoorState()) > 1.0 - STATE_EPSILON;
40
41 if (!isTotallyOpen && !doorComp.IsOpening())
42 {
43 action.PerformAction(actionOwner, actionPerformer);
44 isOpened = false
45 }
46 }
47 if (isOpened)
48 return ENodeResult.SUCCESS;
49 else
50 return ENodeResult.RUNNING;
51 }
52
53 //------------------------------------------------------------------------------------------------
55 static void FindDoorActions(notnull IEntity doorEntity, notnull array<ScriptedUserAction> outActions, bool includeSiblings)
56 {
57 outActions.Clear();
58
59 IEntity doorParent = doorEntity.GetParent();
60 if (!doorParent || !includeSiblings)
61 {
62 // Door is in world root, or we don't care for siblings
63 ScriptedUserAction action = FindDoorUserAction(doorEntity);
64 if (action)
65 outActions.Insert(action);
66 return;
67 }
68
69 IEntity doorSibling = doorParent.GetChildren();
70
71 // Door is in some hierarchy, check all children of parent of the door
72 while (doorSibling)
73 {
74 ScriptedUserAction action = FindDoorUserAction(doorSibling);
75 if (action)
76 outActions.Insert(action);
77
78 doorSibling = doorSibling.GetSibling();
79 }
80 }
81
82 //------------------------------------------------------------------------------------------------
84 {
85 ActionsManagerComponent actionsMgr = ActionsManagerComponent.Cast(entity.FindComponent(ActionsManagerComponent));
86
87 if (!actionsMgr)
88 return null;
89
90 array<BaseUserAction> actions = {};
91 actionsMgr.GetActionsList(actions);
92 foreach (BaseUserAction action : actions)
93 {
94 SCR_DoorUserAction doorAction = SCR_DoorUserAction.Cast(action);
95 if (doorAction)
96 return doorAction;
97 }
98
99 return null;
100 }
101
102 //------------------------------------------------------------------------------------------------
103 protected static override bool VisibleInPalette() { return true; }
104
105 protected static override string GetOnHoverDescription() { return "Opens the given door. Can also open its sibling doors"; }
106
107 protected static ref TStringArray s_aVarsIn = { PORT_DOOR_ENTITY };
108 override TStringArray GetVariablesIn() { return s_aVarsIn; }
109};
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
proto external IEntity GetParent()
proto external IEntity GetSibling()
Definition Math.c:13
proto bool GetVariableIn(string name, out void val)
static SCR_DoorUserAction FindDoorUserAction(notnull IEntity entity)
static ref TStringArray s_aVarsIn
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
override TStringArray GetVariablesIn()
static void FindDoorActions(notnull IEntity doorEntity, notnull array< ScriptedUserAction > outActions, bool includeSiblings)
Searches doorEntity and all its siblings (children of same parent) for SCR_DoorUserAction.
static override string GetOnHoverDescription()
static override bool VisibleInPalette()
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385