Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignFactionCommanderPlayerComponent.c
Go to the documentation of this file.
1
2[ComponentEditorProps(category: "GameScripted/Commander", description: "Handles interactions for the faction Commander role in Conflict. Should be attached to player controller.")]
4{
5 [Attribute("{EA5C18CC750579E2}Configs/Campaign/CommanderGraphLinesConfig.conf", category: "Lines")]
7
8 //------------------------------------------------------------------------------------------------
13}
14
15class SCR_CampaignFactionCommanderPlayerComponent : SCR_FactionCommanderPlayerComponent
16{
19
21
22 protected ref array<MapLink> m_aMapLinks = {};
23
24 static const string CAMPAIGN_MILITARY_BASE_TASK_ID = "%1_CampaignMilitaryBaseTask_%2_%3";
25
26 //------------------------------------------------------------------------------------------------
27 static SCR_CampaignFactionCommanderPlayerComponent GetLocalCampaignCommanderComponent()
28 {
29 return SCR_CampaignFactionCommanderPlayerComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_CampaignFactionCommanderPlayerComponent));
30 }
31
32 //------------------------------------------------------------------------------------------------
34 {
35 IEntity owner = GetOwner();
36
37 if (!owner)
38 return null;
39
41
42 if (!componentData)
43 return null;
44
45 return componentData.GetGraphLinesData();
46 }
47
48 //------------------------------------------------------------------------------------------------
49 override void OnMapOpen(MapConfiguration config)
50 {
51 super.OnMapOpen(config);
52
53 m_HoveredBase = null;
54
55 if (!m_MapEntity)
56 return;
57
58 SCR_MapCampaignUI mapCampaignUI = SCR_MapCampaignUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapCampaignUI));
59 if (mapCampaignUI)
60 mapCampaignUI.GetOnBaseHovered().Insert(OnBaseHovered);
61
62 }
63
64 //------------------------------------------------------------------------------------------------
65 override void OnMapClose(MapConfiguration config)
66 {
67 super.OnMapClose(config);
68
69 m_HoveredBase = null;
70 if (m_MapEntity)
71 {
72 SCR_MapCampaignUI mapCampaignUI = SCR_MapCampaignUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapCampaignUI));
73 if (mapCampaignUI)
74 mapCampaignUI.GetOnBaseHovered().Remove(OnBaseHovered);
75 }
76 }
77
78 //------------------------------------------------------------------------------------------------
80 {
82
84
85 if (base)
86 m_CurrentHoveredEntity = base.GetOwner();
87 else
89 }
90
91 //------------------------------------------------------------------------------------------------
96
97 //------------------------------------------------------------------------------------------------
99 override protected void OnRadialMenuBeforeOpen()
100 {
101 super.OnRadialMenuBeforeOpen();
102
105 }
106
107 //------------------------------------------------------------------------------------------------
108 override void ClearRadialMenu()
109 {
110 super.ClearRadialMenu();
111
113
115 m_HoveredBase = null;
116
118
119 }
120
121 //------------------------------------------------------------------------------------------------
123 override void OnEntryHovered(SCR_SelectionMenuEntry entry, int id)
124 {
125 super.OnEntryHovered(entry, id);
126
128
129 if (!m_HoveredBase || !entry)
130 return;
131
132 Faction faction = SCR_FactionManager.SGetLocalPlayerFaction();
133
134 if (!faction)
135 return;
136
138
139 if (!groupsManager)
140 return;
141
142 SCR_AIGroup selectedGroup = m_mEntryGroups.Get(entry);
143
144 if (selectedGroup)
145 {
146 // Draw a link to selected group
147 LinkBaseWithGroup(selectedGroup);
148 }
149 }
150
151 //------------------------------------------------------------------------------------------------
153 protected void LinkBaseWithGroup(notnull SCR_AIGroup group)
154 {
155 IEntity leader = GetGame().GetPlayerManager().GetPlayerControlledEntity(group.GetLeaderID());
156
157 if (!leader || leader == SCR_PlayerController.GetLocalControlledEntity())
158 return;
159
161
162 if (!desc)
163 return;
164
165 MapItem item = desc.Item();
166
167 if (!item)
168 return;
169
171
172 if (!baseDesc)
173 return;
174
175 MapItem baseItem = baseDesc.Item();
176
177 if (!baseItem)
178 return;
179
180 MapLink link = baseItem.LinkTo(item);
181 m_aMapLinks.Insert(link);
182 MapLinkProps props = link.GetMapLinkProps();
183
184 if (!props)
185 return;
186
188
189 if (!linesData)
190 return;
191
192 props.SetLineWidth(linesData.GetLineWidth());
193 props.SetLineColor(linesData.GetColor());
194 }
195
196 //------------------------------------------------------------------------------------------------
198 protected void ClearAllLinks()
199 {
200 if (!m_HoveredBase)
201 return;
202
204
205 if (!baseDesc)
206 return;
207
208 MapItem baseItem = baseDesc.Item();
209
210 if (!baseItem)
211 return;
212
213 foreach (MapLink link : m_aMapLinks)
214 {
215 baseItem.UnLink(link.Target());
216 }
217
218 m_aMapLinks.Clear();
219 }
220
221 //------------------------------------------------------------------------------------------------
223 {
224 if (!base)
225 return false;
226
227 SCR_Faction faction = SCR_Faction.Cast(base.GetFaction(true));
228 if (!faction)
229 return false;
230
231 PlayerController sender = PlayerController.Cast(GetOwner());
232 return sender && faction.IsPlayerCommander(sender.GetPlayerId());
233 }
234
235 //------------------------------------------------------------------------------------------------
242 void CreateCampaignMilitaryBaseTask(ResourceName taskPrefab, SCR_AIGroup group, int playerId, vector positionOffset = vector.Zero)
243 {
244 int groupId = -1;
245
246 if (group)
247 groupId = group.GetGroupID();
248
249 int baseCallsign = SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN;
250
251 if (m_HoveredBase)
252 baseCallsign = m_HoveredBase.GetCallsign();
253
254 if (baseCallsign == SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN)
255 return;
256
257 Rpc(RpcAsk_CreateCampaignMilitaryBaseTask, taskPrefab, groupId, GetGame().GetFactionManager().GetFactionIndex(SCR_FactionManager.SGetLocalPlayerFaction()), playerId, baseCallsign, positionOffset);
258 }
259
260 //------------------------------------------------------------------------------------------------
261 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
262 protected void RpcAsk_CreateCampaignMilitaryBaseTask(ResourceName taskPrefab, int assigneeId, int factionIndex, int playerId, int baseCallsign, vector positionOffset)
263 {
264 PlayerController sender = PlayerController.Cast(GetOwner());
265 if (!sender)
266 return;
267
268 SCR_Faction faction = SCR_Faction.Cast(GetGame().GetFactionManager().GetFactionByIndex(factionIndex));
269 if (!faction || !faction.IsPlayerCommander(sender.GetPlayerId()))
270 return;
271
272 if (!m_GroupTaskManager.CanCreateNewTaskWithResourceName(taskPrefab, faction))
273 return;
274
275 SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseCallsign);
276 if (!base)
277 return;
278
279 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
280 if (!taskSystem)
281 return;
282
283 string taskID = string.Format(CAMPAIGN_MILITARY_BASE_TASK_ID, faction.GetFactionKey(), base.GetCallsign(), GenerateTaskID());
284
285 if (SCR_TaskSystem.GetTaskFromTaskID(taskID, false))
286 return;
287
288 SCR_CampaignMilitaryBaseTaskEntity task = SCR_CampaignMilitaryBaseTaskEntity.Cast(taskSystem.CreateTask(
289 taskPrefab,
290 taskID,
291 "",
292 "",
293 base.GetOwner().GetOrigin() + positionOffset,
294 playerId
295 ));
296
297 if (!task)
298 {
299 Print("Task was not created", LogLevel.ERROR);
300 return;
301 }
302
303 string title;
304 string description;
305
306 if (SCR_SeizeCampaignMilitaryBaseTaskEntity.Cast(task))
307 {
308 if (base.GetType() == SCR_ECampaignBaseType.RELAY)
309 {
310 title = SCR_CampaignFactionCommanderHandlerComponent.SEIZE_TASK_RELAY_NAME;
311 description = SCR_CampaignFactionCommanderHandlerComponent.SEIZE_TASK_RELAY_DESC;
312 }
313 else
314 {
315 title = SCR_CampaignFactionCommanderHandlerComponent.SEIZE_TASK_NAME;
316 description = SCR_CampaignFactionCommanderHandlerComponent.SEIZE_TASK_DESC;
317 }
318
319 task.SetTaskName(title, {base.GetFormattedBaseNameWithCallsign(faction)});
320 task.SetTaskDescription(description);
321 }
322 else
323 {
324 SCR_TaskUIInfo taskUIInfo = task.GetTaskUIInfo();
325 if (!taskUIInfo)
326 return;
327
328 task.SetTaskName(taskUIInfo.GetName(), {base.GetFormattedBaseNameWithCallsign(faction)});
329 }
330
331 task.SetMilitaryBaseCallSign(baseCallsign);
332 taskSystem.SetTaskOwnership(task, SCR_ETaskOwnership.EXECUTOR);
333 taskSystem.SetTaskVisibility(task, SCR_ETaskVisibility.GROUP);
334 taskSystem.AddTaskFaction(task, faction.GetFactionKey());
335
337 m_GroupTaskManager.SetGroupTask(task, playerId);
338
339 if (assigneeId > -1)
340 taskSystem.AssignTask(task, SCR_TaskExecutorGroup.FromGroup(assigneeId), true, playerId); // force assign
341 }
342
343#ifdef ENABLE_DIAG
344 //------------------------------------------------------------------------------------------------
346 void CheatCommander()
347 {
348 int playerId = m_PlayerController.GetPlayerId();
349 if (playerId == 0)
350 return;
351
352 Rpc(RpcAsk_CheatCommander, playerId);
353 }
354#endif
355
356 //------------------------------------------------------------------------------------------------
357 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
358 protected void RpcAsk_CheatCommander(int playerId)
359 {
360 if (!GetGame().IsDev())
361 return;
362
363 SCR_Faction playerFaction = SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(playerId));
364 if (!playerFaction)
365 return;
366
367 SCR_CampaignFactionCommanderHandlerComponent handler = SCR_CampaignFactionCommanderHandlerComponent.Cast(SCR_CampaignFactionCommanderHandlerComponent.GetInstance());
368 if (!handler)
369 return;
370
371 handler.SetFactionCommander(playerFaction, playerId);
372 }
373
374 //------------------------------------------------------------------------------------------------
379 {
380 Rpc(RpcAsk_SetSuppliesLimit, base.GetCallsign(), value);
381 }
382
383 //------------------------------------------------------------------------------------------------
384 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
385 protected void RpcAsk_SetSuppliesLimit(int baseCallsign, float value)
386 {
387 SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseCallsign);
388 if (!IsValidRequest(base))
389 return;
390
391 base.SetSupplyLimit(value);
392 }
393
394 //------------------------------------------------------------------------------------------------
399 {
400 Rpc(RpcAsk_SetReservedSupplyAmount, base.GetCallsign(), value);
401 }
402
403 //------------------------------------------------------------------------------------------------
404 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
405 protected void RpcAsk_SetReservedSupplyAmount(int baseCallsign, float value)
406 {
407 SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseCallsign);
408 if (!IsValidRequest(base))
409 return;
410
411 base.SetReservedSupplyAmount(value);
412 }
413
414 //------------------------------------------------------------------------------------------------
419 {
420 Rpc(RpcAsk_SetSupplyRequestExecutionPriority, base.GetCallsign(), priority);
421 }
422
423 //------------------------------------------------------------------------------------------------
424 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
425 protected void RpcAsk_SetSupplyRequestExecutionPriority(int baseCallsign, int priority)
426 {
427 SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseCallsign);
428 if (!IsValidRequest(base))
429 return;
430
431 base.SetSupplyRequestExecutionPriority(priority);
432 }
433}
ArmaReforgerScripted GetGame()
Definition game.c:1398
int GetFactionIndex()
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_EditableEntityComponent m_HoveredEntity
SCR_BaseGameMode GetGameMode()
void LinkBaseWithGroup(notnull SCR_AIGroup group)
Draw a map link from a base to a group leader.
void SetSuppliesLimit(notnull SCR_CampaignMilitaryBaseComponent base, float value)
void RpcAsk_SetSupplyRequestExecutionPriority(int baseCallsign, int priority)
override void OnEntryHovered(SCR_SelectionMenuEntry entry, int id)
Triggered when a radial menu entry is hovered on.
void RpcAsk_CheatCommander(int playerId)
SCR_CampaignMilitaryBaseComponent m_CurrentHoveredBase
void CreateCampaignMilitaryBaseTask(ResourceName taskPrefab, SCR_AIGroup group, int playerId, vector positionOffset=vector.Zero)
void OnRadialMenuBeforeOpen()
Called each time the radial menu is before open in the map.
SCR_CampaignMilitaryBaseComponent GetHoveredBase()
void ClearAllLinks()
Remove all existing map links.
void RpcAsk_SetSuppliesLimit(int baseCallsign, float value)
SCR_CampaignFactionCommanderPlayerComponentClass m_HoveredBase
bool IsValidRequest(SCR_CampaignMilitaryBaseComponent base)
ref array< MapLink > m_aMapLinks
void RpcAsk_CreateCampaignMilitaryBaseTask(ResourceName taskPrefab, int assigneeId, int factionIndex, int playerId, int baseCallsign, vector positionOffset)
void RpcAsk_SetReservedSupplyAmount(int baseCallsign, float value)
void OnMapClose(MapConfiguration config)
void OnMapOpen(MapConfiguration config)
void OnBaseHovered(SCR_CampaignMilitaryBaseComponent base)
void SetSupplyRequestExecutionPriority(SCR_ESupplyRequestExecutionPriority priority)
void SetReservedSupplyAmount(float value)
SCR_CharacterSoundComponentClass GetComponentData()
SCR_GroupTaskManagerComponent m_GroupTaskManager
ref map< SCR_SelectionMenuEntry, SCR_AIGroup > m_mEntryGroups
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_FastTravelComponentClass m_PlayerController
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_MapEntity m_MapEntity
SCR_GraphLinesData GetGraphLinesData()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ETaskVisibility
Definition SCR_Task.c:24
proto external Managed FindComponent(typename typeName)
int GetGroupID()
Handles interactions for the faction Commander role in Conflict. Should be attached to player control...
Handles interactions for the faction Commander role. Should be attached to player controller.
bool IsPlayerCommander(int playerId)
BaseHoveredInvoker GetOnBaseHovered()
static IEntity GetLocalControlledEntity()
IEntity GetOwner()
Owner entity of the fuel tank.
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
SCR_FieldOfViewSettings Attribute
proto external Faction GetFactionByIndex(int index)
proto external PlayerController GetPlayerController()
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14