Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WaypointGroupCommand.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 [Attribute(desc: "Prefab of the AI waypoint used in this command", params: "et class=AIWaypoint")]
7
8 [Attribute(defvalue: "1", desc: "Will the command override all previous commands?")]
10
11 [Attribute(defvalue: "0", desc: "Will the command be automatically set to players position?")]
12 protected bool m_bTargetSelf;
13
14 [Attribute(defvalue: "0", desc: "Will the command override autonomous group behavior?")]
15 protected bool m_bForceCommand;
16
17 [Attribute(defvalue: "5", desc: "Completion radius of command")]
18 protected float m_fCompletionRadius;
19
20 [Attribute("0", UIWidgets.CheckBox, desc: "Optionally, execution of this command can set combat mode of the group.")]
22
23 [Attribute(typename.EnumToString(EAIGroupCombatMode, EAIGroupCombatMode.FIRE_AT_WILL), UIWidgets.ComboBox, desc: "New combat mode value", enums: ParamEnumArray.FromEnum(EAIGroupCombatMode))]
25
26 [Attribute(desc: "Handler which is going to be called to manipualte the waypoint when it is created as well as when it is assigned to the group.")]
28
29 //------------------------------------------------------------------------------------------------
30 override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
31 {
32 SCR_ChimeraCharacter user = SCR_ChimeraCharacter.Cast(GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID));
33 if (user && !CanBePerformed(user))
34 return false;//verify that at the moment of execution player can actually do that
35
36 if (isClient && playerID == SCR_PlayerController.GetLocalPlayerId())
37 {
38 SpawnWPVisualization(targetPosition, playerID);
39 return true;
40 }
41
42 SpawnWPVisualization(targetPosition, playerID);
43 if (!m_sWaypointPrefab || !target || !targetPosition)
44 return false;
45
46 bool waypointCreated = SetWaypointForAIGroup(target, targetPosition, playerID);
47
48 if (!waypointCreated)
49 return false;
50
51 // Set combat mode
54
55 return true;
56 }
57
58 //------------------------------------------------------------------------------------------------
59 bool SetWaypointForAIGroup(IEntity target, vector targetPosition, int playerID)
60 {
61 SCR_AIGroup slaveGroup = SCR_AIGroup.Cast(target);
62 if (!slaveGroup)
63 return false;
64
65 array<AIWaypoint> currentWaypoints = {};
66 slaveGroup.GetWaypoints(currentWaypoints);
67 foreach(AIWaypoint currentwp : currentWaypoints)
68 {
69 slaveGroup.RemoveWaypoint(currentwp);
70 }
71
72 Resource waypointPrefab = Resource.Load(GetWaypointPrefab());
73 if (!waypointPrefab.IsValid())
74 {
75 //add custom error
76 return false;
77 }
78
80 position = GetTargetPosition(playerID, targetPosition);
81
83 params.TransformMode = ETransformMode.WORLD;
84 params.Transform[3] = position;
85
86 CheckPreviousWaypoints(slaveGroup);
87
88 SCR_AIWaypoint wp = SCR_AIWaypoint.Cast(GetGame().SpawnEntityPrefabLocal(waypointPrefab, null, params));
89 if (!wp)
90 return false;
91
93 m_WaypointCommandHandler.OnWaypointCreated(wp);
94
96 wp.SetPriorityLevel(SCR_AIActionBase.PRIORITY_LEVEL_PLAYER);
97
98 wp.SetCompletionRadius(m_fCompletionRadius);
99 slaveGroup.AddWaypoint(wp);
101 m_WaypointCommandHandler.OnWaypointIssued(wp, slaveGroup);
102
103 return true;
104 }
105
106 //------------------------------------------------------------------------------------------------
107 void SpawnWPVisualization(vector targetPosition, int playerID)
108 {
109 PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerID);
110 if (!controller)
111 return;
112
113 SCR_PlayerControllerCommandingComponent commandingComp = SCR_PlayerControllerCommandingComponent.Cast(controller.FindComponent(SCR_PlayerControllerCommandingComponent));
114 if (!commandingComp)
115 return;
116
117 commandingComp.DrawWaypointVisualization(targetPosition, m_fCompletionRadius);
118 }
119
120 //------------------------------------------------------------------------------------------------
125
126 //------------------------------------------------------------------------------------------------
128 {
129 m_sWaypointPrefab = wpPrefab;
130 }
131
132 //------------------------------------------------------------------------------------------------
137
138 //------------------------------------------------------------------------------------------------
139 void SetOverridePreviousCommands(bool overridePrevious)
140 {
141 m_bOverridePreviousCommands = overridePrevious;
142 }
143
144 //----------------------------------------------------------------------------------------------
145 vector GetTargetPosition(int playerID, vector targetPosition)
146 {
147 if (m_bTargetSelf)
148 {
149 SCR_PlayerController orderingPlayerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(playerID));
150 IEntity playerEntity = orderingPlayerController.GetControlledEntity();
151 if (!playerEntity)
152 return vector.Zero;
153 return playerEntity.GetOrigin();
154 }
155 else
156 return targetPosition;
157 }
158
159 //-------------------------------------------------------------------------------------------------
161 {
163 return;
164
165 array<AIWaypoint> currentWaypoints = {};
166 slaveGroup.GetWaypoints(currentWaypoints);
167 foreach(AIWaypoint currentwp : currentWaypoints)
168 {
169 slaveGroup.RemoveWaypoint(currentwp);
170 }
171 AIGroupMovementComponent slaveGroupMovementComp = AIGroupMovementComponent.Cast(slaveGroup.FindComponent(AIGroupMovementComponent));
172 if (slaveGroupMovementComp)
173 slaveGroupMovementComp.SetFormationDisplacement(0);
174 }
175
176 //------------------------------------------------------------------------------------------------
177 override bool CanShowOnMap()
178 {
179 return CanBeShown();
180 }
181
182 //------------------------------------------------------------------------------------------------
183 override bool CanBeShown()
184 {
186 return false;
187
188 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
189 return groupController && CanRoleShow();
190 }
191
192 //------------------------------------------------------------------------------------------------
193 void SetCombatMode(IEntity target, EAIGroupCombatMode combatMode)
194 {
195 SCR_AIGroup slaveGroup = SCR_AIGroup.Cast(target);
196 if (!slaveGroup)
197 return;
198
199 SCR_AIGroupUtilityComponent groupUtility = SCR_AIGroupUtilityComponent.Cast(slaveGroup.FindComponent(SCR_AIGroupUtilityComponent));
200
201 groupUtility.SetCombatMode(combatMode);
202 }
203}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
override vector GetTargetPosition()
vector position
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external vector GetOrigin()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void SetCombatMode(EAIGroupCombatMode combatMode)
Sets combat mode as desired by external means, such as scenario, or commanding, or game master.
void SetPriorityLevel(float priority)
override bool CanBeShownInCurrentLifeState()
bool CanBePerformed(notnull SCR_ChimeraCharacter user)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
void SetWaypointPrefab(ResourceName wpPrefab)
override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient)
vector GetTargetPosition(int playerID, vector targetPosition)
void CheckPreviousWaypoints(SCR_AIGroup slaveGroup)
void SetOverridePreviousCommands(bool overridePrevious)
bool SetWaypointForAIGroup(IEntity target, vector targetPosition, int playerID)
void SetCombatMode(IEntity target, EAIGroupCombatMode combatMode)
ref SCR_BaseWaypointCommandHandler m_WaypointCommandHandler
void SpawnWPVisualization(vector targetPosition, int playerID)
void EntitySpawnParams()
Definition gameLib.c:130
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()