Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoiterUserAction.c
Go to the documentation of this file.
12
13class SCR_LoiterUserAction: SCR_UserActionWithOccupancy
14{
15 [Attribute( defvalue: "0", uiwidget: UIWidgets.EditBox, desc: "Provide index of related SmartActionSentinel" )]
16 protected int m_iSmartActionId;
17
18 protected bool m_isValid;
19 protected bool m_bHolsterWeapon;
21 protected vector m_targetPosition[4]
22
23 //-------------------------------------------------------------------------
25 //\param[out] vector with the position
26 protected void GetLoiteringPosition(SCR_AISmartActionSentinelComponent smartAction, out vector loiteringPosition[4])
27 {
28 IEntity owner = GetOwner();
29
30 vector mat[4];
31 owner.GetWorldTransform(mat);
32
33 //--- Position of the action
34 vector desiredPos = mat[3] + smartAction.GetActionOffset().Multiply3(mat);
35
36 //--- Position to rotate to
37 vector desiredLookPos = mat[3] + smartAction.GetLookPosition().Multiply3(mat);
38
39 //--- Up vector of entity that owns the action
40 vector actionEntityUp = mat[1];
41
42 //--- Now I have rotation of entity to look towards desiredLookPos
43 Math3D.DirectionAndUpMatrix(desiredLookPos - desiredPos, actionEntityUp, loiteringPosition);
44
45 //--- Standing at desired desiredPos
46 loiteringPosition[3] = desiredPos;
47 }
48
49 //-------------------------------------------------------------------------
50 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
51 {
52 //if (!GetGame().InPlayMode())
53 // return;
54 // ...
55 }
56
57 //------------------------------------------------------------------------------------------------
58 override void StartAction(IEntity pUserEntity)
59 {
60 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(pUserEntity);
61 if (!character)
62 return;
63
64 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
65 if (!controller)
66 return;
67
68 if (!m_isValid)
69 return;
70 m_isValid = false; // consume validity of this message
71
72 controller.StartLoitering(GetOwner(), m_eLoiteringType, m_bHolsterWeapon, true, true, m_targetPosition);
73 }
74
75 //------------------------------------------------------------------------------------------------
76 override void StopAction(IEntity pUserEntity)
77 {
78 bool stopFast = false;
79 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(pUserEntity);
80 if (!character)
81 return;
82
83 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
84 if (!controller)
85 return;
86
87 AIControlComponent aiController = controller.GetAIControlComponent();
88 if (aiController)
89 {
90 SCR_ChimeraAIAgent agent = SCR_ChimeraAIAgent.Cast(aiController.GetAIAgent());
91 if (agent)
92 stopFast = agent.ShouldAbortLoiterFast();
93 }
94 controller.StopLoitering(stopFast);
95 }
96
97 //------------------------------------------------------------------------------------------------
98 override bool CanBeShownScript(IEntity user)
99 {
100 return true;
101 }
102
103 //------------------------------------------------------------------------------------------------
104 override bool CanBePerformedScript(IEntity user)
105 {
106 return !m_Occupant || m_Occupant == user;
107 }
108
109 //------------------------------------------------------------------------------------------------
110 override bool GetActionNameScript(out string outName)
111 {
112 outName = ("#AR-UserAction_Loiter");
113 return true;
114 }
115
116 //------------------------------------------------------------------------------------------------
118 {
119 return false;
120 }
121
122 //------------------------------------------------------------------------------------------------
124 {
125 return true;
126 }
127
128 //------------------------------------------------------------------------------------------------
129 override bool CanBroadcastScript()
130 {
131 // Technically this should not be a broadcast action as it requires the rpl owner to initiate and complete it.
132 // However, to keep things simple and because this is such a rare action, we allow this to be true for the sake
133 // of simplicity.
134 // Basically what happens is following:
135 // 1) Owner sends a request to the server.
136 // 2) The server fills the data which only it has.
137 // 2a) if the owner is also the serverit will start loitering now
138 // 3) The server broadcasts the action with the data.
139 // 4) If (1) was not the server but a client, it will reach out to the server and start loitering now.
140 return true;
141 }
142
143 //------------------------------------------------------------------------------------------------
144 override protected bool OnSaveActionData(ScriptBitWriter writer)
145 {
146 // Smart actions exist only on the server. Therefore, the server needs to indentify if the action setup is correct
147 // and store necessary values in the buffer. When this buffer is replicated clients read it and do stuff based on the result.
148
149 IEntity owner = GetOwner();
150 array<Managed> aComponents = {};
152
153 m_isValid = aComponents.IsIndexValid(m_iSmartActionId);
154 if (!m_isValid)
155 {
156 Print(string.Format("Invalid SmartAction id at SCR_LoiterUserAction! Components=%1, id=%2", aComponents.Count(), m_iSmartActionId), LogLevel.WARNING);
157 return false;
158 }
159
160 SCR_AISmartActionSentinelComponent smartAction = SCR_AISmartActionSentinelComponent.Cast(aComponents[m_iSmartActionId]);
161 if (!smartAction)
162 return false;
163
164 if (m_Occupant)
165 {
167 if (!charCtrl || !charCtrl.IsLoiteringOnEntity(owner))
168 m_Occupant = null; // the character is not loitering anymore but he didn't free the action?
169 }
170
171 bool hasOccupant = SaveOccupant(writer);
172 if (hasOccupant)
173 return true;
174
175 GetLoiteringPosition(smartAction, m_targetPosition);
176
177 writer.WriteInt((int)smartAction.GetLoiterAnimation());
178 writer.WriteBool(smartAction.GetHolsterWeapon());
179
180 writer.WriteVector(m_targetPosition[0]);
181 writer.WriteVector(m_targetPosition[1]);
182 writer.WriteVector(m_targetPosition[2]);
183 writer.WriteVector(m_targetPosition[3]);
184
185 return true;
186 }
187
188 //------------------------------------------------------------------------------------------------
189 override protected bool OnLoadActionData(ScriptBitReader reader)
190 {
191 bool hasOccupant = LoadOccupant(reader);
192 if (hasOccupant)
193 {
194 m_isValid = false;
195 return true;
196 }
197
198 reader.ReadInt(m_eLoiteringType);
199 reader.ReadBool(m_bHolsterWeapon);
200
201 for (int i = 0; i < 4; i++)
202 {
203 vector value;
204 reader.ReadVector(value);
205 m_targetPosition[i] = value;
206 }
207
208 m_isValid = true;
209 return true;
210 }
211}
override void Init()
ELoiteringType m_eLoiteringType
override bool CanBroadcastScript()
override bool CanBeShownScript(IEntity user)
override bool CanBePerformedScript(IEntity user)
void GetLoiteringPosition(SCR_AISmartActionSentinelComponent smartAction, out vector loiteringPosition[4])
Calculates the position of loitering.
override bool GetActionNameScript(out string outName)
override bool CheckOnServerFirstScript()
override bool HasLocalEffectOnlyScript()
bool m_isValid
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
bool OnLoadActionData(ScriptBitReader reader)
proto external IEntity GetOwner()
Returns the parent entity of this action.
bool OnSaveActionData(ScriptBitWriter writer)
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external int FindComponents(typename typeName, notnull array< Managed > outComponents)
void StartLoitering(IEntity loiterEntity, int loiteringType, bool holsterWeapon, bool allowRootMotion, bool alignToPosition, vector targetPosition[4]={ "1 0 0", "0 1 0", "0 0 1", "0 0 0" }, bool disableInput=false, SCR_LoiterCustomAnimData customAnimData=SCR_LoiterCustomAnimData.Default)
bool LoadOccupant(ScriptBitReader reader)
void StopAction(IEntity pUserEntity)
bool SaveOccupant(ScriptBitWriter writer)
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
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
@ StartAction
@ CUSTOM
Mesh created through MeshObject::Create.