Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkLayerTaskDefend.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/ScenarioFramework/Layer", description: "")]
5
6class SCR_ScenarioFrameworkLayerTaskDefend : SCR_ScenarioFrameworkLayerTask
7{
8 [Attribute(desc: "Will use trigger that is named for Defend params calculations", category: "Task")]
9 protected string m_sTriggerName;
10
11 [Attribute(uiwidget: UIWidgets.LocaleEditBox, desc: "Text that will be displayed above the countdown number", category: "Defend params")]
12 protected LocalizedString m_sCountdownTitleText;
13
14 [Attribute(defvalue: "-1", UIWidgets.Slider, desc: "For how long you have to Defend the objective of the task. Value -1 is for indefinitely.", params: "-1 86400 1", category: "Defend params")]
15 protected float m_fDefendTime;
16
17 [Attribute(defvalue: "1", desc: "When enabled, it will display the text and how much time remains for the Task Defend", category: "Defend params")]
18 protected bool m_bDisplayCountdownHUD;
19
20 [Attribute(defvalue: "{47864BB47AB0B1F4}UI/layouts/HUD/CampaignMP/CampaignMainHUD.layout", category: "Defend params")]
21 protected ResourceName m_sCountdownHUD;
22
23 [Attribute(category: "Defend params")]
24 protected ref array<ref SCR_ScenarioFrameworkTaskDefendFactionSettings> m_aFactionSettings;
25
26 [Attribute(uiwidget: UIWidgets.Slider, desc: "When compared to the number of attackers, minimum of how much of the characters present in the task area must be from defending side to successfully complete the objective on evaluation", params: "0 1 0.01", precision: 2, category: "Defend params")]
28
29 [Attribute(uiwidget: UIWidgets.EditBox, desc: "Layer containing attacker forces. Can be more layers, but these layers must include only AI units/groups and nothing else.", category: "Defend params")]
30 protected ref array<string> m_aAttackerLayerNames;
31
32 [Attribute(desc: "When enabled, it will can finish the task earlier than the countdown when all attackers are eliminated", category: "Defend params")]
33 protected bool m_bEarlierEvaluation;
34
35 [Attribute(desc: "When enabled, evaluation will be delayed and defenders will need to eliminate all attackers in order for the task to be succesfully completed", category: "Defend params")]
36 protected bool m_bDelayedEvaluation;
37
38 [Attribute(desc: "When enabled, it will display the text to inform players that they have to eliminate all attacker units", category: "Defend params")]
40
41 [Attribute(uiwidget: UIWidgets.LocaleEditBox, desc: "Text that will be displayed to inform players that they have to eliminate all attacker units", category: "Defend params")]
43
44 protected SCR_CharacterTriggerEntity m_CharacterTriggerEntity;
45
46 protected float m_fTempCountdown = m_fDefendTime;
47
48 protected string m_sFormattedCountdownTitle = string.Format(WidgetManager.Translate("<color rgba=\"226, 168, 80, 255\">%1</color>", m_sCountdownTitleText));
49 protected string m_sFormattedDelayedEvaluationText = string.Format(WidgetManager.Translate("<color rgba=\"226, 168, 80, 255\">%1</color>", m_sDelayedEvaluationText));
50
51 protected ref array<SCR_ScenarioFrameworkLayerBase> m_aAttackerLayer = {};
52
53 protected float m_fTempTimeSlice;
54 protected bool m_bTaskEvaluated;
55 protected bool m_bEvaluationSet;
58
59 protected Widget m_wRoot;
64
65 //------------------------------------------------------------------------------------------------
68 {
69 return m_fDefendTime;
70 }
71
72 //------------------------------------------------------------------------------------------------
74 void SetDefendTime(float time)
75 {
76 m_fDefendTime = time;
77 }
78
79 //------------------------------------------------------------------------------------------------
81 SCR_CharacterTriggerEntity GetCharacterTriggerEntity()
82 {
84 }
85
86 //------------------------------------------------------------------------------------------------
89 {
90 IEntity foundEntity = GetGame().GetWorld().FindEntityByName(m_sTriggerName);
91 if (!foundEntity)
92 return;
93
94 SCR_ScenarioFrameworkSlotTrigger slotTrigger = SCR_ScenarioFrameworkSlotTrigger.Cast(foundEntity.FindComponent(SCR_ScenarioFrameworkSlotTrigger));
95 if (!slotTrigger)
96 return;
97
98 SCR_CharacterTriggerEntity trigger = SCR_CharacterTriggerEntity.Cast(slotTrigger.GetSpawnedEntity());
99 if (!trigger)
100 return;
101
102 m_CharacterTriggerEntity = trigger;
103 }
104
105 //------------------------------------------------------------------------------------------------
109 protected void CountAttackerDefenderNumbers(out int defenderCount, out int attackerCount)
110 {
111 for (int i = 0, count = m_aFactionSettings.Count(); i < count; i++)
112 {
113 SCR_ScenarioFrameworkTaskDefendDefendingFaction defender = SCR_ScenarioFrameworkTaskDefendDefendingFaction.Cast(m_aFactionSettings[i]);
114 if (defender)
115 {
116 if (defender.GetCountOnlyPlayers())
117 defenderCount += m_CharacterTriggerEntity.GetPlayersCountByFactionInsideTrigger(defender.GetFaction());
118 else
119 defenderCount += m_CharacterTriggerEntity.GetCharacterCountByFactionInsideTrigger(defender.GetFaction());
120 }
121
122 SCR_ScenarioFrameworkTaskDefendAttackingFaction attacker = SCR_ScenarioFrameworkTaskDefendAttackingFaction.Cast(m_aFactionSettings[i]);
123 if (attacker)
124 {
125 if (attacker.GetCountOnlyPlayers())
126 attackerCount += m_CharacterTriggerEntity.GetPlayersCountByFactionInsideTrigger(attacker.GetFaction());
127 else
128 attackerCount += m_CharacterTriggerEntity.GetCharacterCountByFactionInsideTrigger(attacker.GetFaction());
129 }
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
136 {
137 m_bTaskEvaluated = true;
138
139 if (!m_Task)
140 {
141 SCR_ScenarioFrameworkTask taskToFind;
142 array<SCR_Task> activeTasks = {};
143 m_TaskSystem.GetTasks(activeTasks);
144
145 foreach (SCR_Task task : activeTasks)
146 {
147 taskToFind = SCR_ScenarioFrameworkTask.Cast(task);
148 if (!taskToFind)
149 continue;
150
151 if (taskToFind.GetLayerTask() == this)
152 {
153 m_Task = taskToFind;
154 break;
155 }
156 }
157 }
158
159 if (!m_Task)
160 {
162 return;
163 }
164
165 if (!m_CharacterTriggerEntity && !m_sTriggerName.IsEmpty())
167
169 {
170 int defenderCount = 0;
171 int attackerCount = 0;
172 CountAttackerDefenderNumbers(defenderCount, attackerCount);
173
174 if (m_fMinDefenderPercentageRatio == 0 || attackerCount == 0)
175 {
178 return;
179 }
180
181 float defenderRatioEval = defenderCount / attackerCount;
182 if (defenderRatioEval < m_fMinDefenderPercentageRatio)
183 {
186 return;
187 }
188 }
189
192 }
193
194 //------------------------------------------------------------------------------------------------
197 {
198 SCR_ScenarioFrameworkLayerBase attackerLayer;
199 IEntity attackerLayerEntity;
200 foreach (string layerName : m_aAttackerLayerNames)
201 {
202 attackerLayerEntity = GetGame().GetWorld().FindEntityByName(layerName);
203 if (!attackerLayerEntity)
204 continue;
205
206 attackerLayer = SCR_ScenarioFrameworkLayerBase.Cast(attackerLayerEntity.FindComponent(SCR_ScenarioFrameworkLayerBase));
207 if (!attackerLayer)
208 continue;
209
210 m_aAttackerLayer.Insert(attackerLayer);
211 }
212 }
213
214 //------------------------------------------------------------------------------------------------
217 {
218 if (m_fTempCountdown > 0)
219 {
220 ChimeraWorld world = GetOwner().GetWorld();
221 m_fEvaluateTimeStart = world.GetServerTimestamp();
223 m_bEvaluationSet = true;
224 }
225
228
229 //If trigger is already set via the Trigger Name attribute, we don't need to search for it
231 return;
232
233 foreach (SCR_ScenarioFrameworkLayerBase layerBase : m_aChildren)
234 {
235 if (!layerBase)
236 continue;
237
238 SCR_CharacterTriggerEntity charTrigger;
239 array<IEntity> spawnedEntities = layerBase.GetSpawnedEntities();
240 foreach (IEntity spawnedEntity : spawnedEntities)
241 {
242 charTrigger = SCR_CharacterTriggerEntity.Cast(spawnedEntity);
243 if (charTrigger)
244 m_CharacterTriggerEntity = charTrigger; // TODO: break?
245 }
246 }
247 }
248
249 //------------------------------------------------------------------------------------------------
254 override void RestoreToDefault(bool includeChildren = false, bool reinitAfterRestoration = false, bool affectRandomization = true, bool deleteSpawnedEntities = true)
255 {
257 m_fTempCountdown = m_fDefendTime;
259 m_bTaskEvaluated = false;
260 m_bEvaluationSet = false;
261 m_wRoot = null;
262 m_wInfoOverlay = null;
263 m_wCountdownOverlay = null;
264 m_wCountdown = null;
265 m_wFlavour = null;
266
267 m_aAttackerLayer.Clear();
268
269 super.RestoreToDefault(includeChildren, reinitAfterRestoration, affectRandomization, deleteSpawnedEntities);
270 }
271
272 //------------------------------------------------------------------------------------------------
278
279 //------------------------------------------------------------------------------------------------
283 {
284 super.AfterAllChildrenSpawned(layer);
285
286 if (!m_sTriggerName.IsEmpty())
288
289 InitHUD();
292 }
293
294 //------------------------------------------------------------------------------------------------
296 override void OnPostInit(IEntity owner)
297 {
298 super.OnPostInit(owner);
299 if (m_bInitiated)
300 {
301 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
302 }
303 }
304
305 //------------------------------------------------------------------------------------------------
307 void InitHUD()
308 {
310 if (!hudManager)
311 return;
312
313 m_wRoot = hudManager.CreateLayout(m_sCountdownHUD, EHudLayers.MEDIUM, 0);
314 if (!m_wRoot)
315 return;
316
317 m_wInfoOverlay = m_wRoot.FindAnyWidget("Info");
318 m_wCountdownOverlay = m_wRoot.FindAnyWidget("Countdown");
319 ImageWidget leftFlag = ImageWidget.Cast(m_wRoot.FindAnyWidget("FlagSideBlue"));
320 ImageWidget rightFlag = ImageWidget.Cast(m_wRoot.FindAnyWidget("FlagSideRed"));
321 RichTextWidget leftScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ScoreBlue"));
322 RichTextWidget rightScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ScoreRed"));
323 RichTextWidget winScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("TargetScore"));
324 m_wCountdown = RichTextWidget.Cast(m_wRoot.FindAnyWidget("CountdownWin"));
325 m_wFlavour = RichTextWidget.Cast(m_wRoot.FindAnyWidget("FlavourText"));
326 ImageWidget winScoreSideLeft = ImageWidget.Cast(m_wRoot.FindAnyWidget("ObjectiveLeft"));
327 ImageWidget winScoreSideRight = ImageWidget.Cast(m_wRoot.FindAnyWidget("ObjectiveRight"));
328
329 m_wInfoOverlay.SetVisible(false);
330 leftFlag.SetVisible(false);
331 rightFlag.SetVisible(false);
332 leftScore.SetVisible(false);
333 rightScore.SetVisible(false);
334 winScore.SetVisible(false);
335 winScoreSideLeft.SetVisible(false);
336 winScoreSideRight.SetVisible(false);
337
338 string shownTime = SCR_FormatHelper.GetTimeFormatting(m_fTempCountdown, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES);
339 m_wCountdown.SetText(shownTime);
340
342
343 if (!m_bDisplayCountdownHUD)
344 m_wRoot.SetVisible(false);
345 }
346
347 //------------------------------------------------------------------------------------------------
350 {
353
355
356 if (!m_wRoot)
357 return;
358
359 if (m_fTempCountdown < 0 || !m_Task || !m_bDisplayCountdownHUD)
360 {
362 {
364 m_wRoot.SetVisible(true);
365 m_wCountdownOverlay.SetVisible(false);
366 return;
367 }
368
369 m_wRoot.SetVisible(false);
370 return;
371 }
372
373 if (m_Task.GetTaskState() == SCR_ETaskState.FAILED || m_Task.GetTaskState() == SCR_ETaskState.COMPLETED)
374 {
375 m_wRoot.SetVisible(false);
376 return;
377 }
378
379 string shownTime = SCR_FormatHelper.GetTimeFormatting(m_fTempCountdown, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES);
380 m_wCountdown.SetText(shownTime);
381
383 m_wRoot.SetVisible(true);
384 }
385
388 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
389 void RpcDo_UpdateHUD(float countdown)
390 {
391 m_fTempCountdown = countdown;
392
393 if (!m_wRoot)
394 {
395 InitHUD();
396 if (!m_wRoot)
397 return;
398 }
399
400 if (m_fTempCountdown < 0 || !m_Task || !m_bDisplayCountdownHUD)
401 {
403 {
405 m_wRoot.SetVisible(true);
406 m_wCountdownOverlay.SetVisible(false);
407 return;
408 }
409
410 m_wRoot.SetVisible(false);
411 return;
412 }
413
414 if (m_Task.GetTaskState() == SCR_ETaskState.FAILED || m_Task.GetTaskState() == SCR_ETaskState.COMPLETED)
415 {
416 m_wRoot.SetVisible(false);
417 return;
418 }
419
420 string shownTime = SCR_FormatHelper.GetTimeFormatting(m_fTempCountdown, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES);
421 m_wCountdown.SetText(shownTime);
422
424 m_wRoot.SetVisible(true);
425 }
426
427 //------------------------------------------------------------------------------------------------
430 {
432 foreach (SCR_ScenarioFrameworkLayerBase attackerLayer : m_aAttackerLayer)
433 {
434 if (attackerLayer.GetEnableRepeatedSpawn() && attackerLayer.GetRepeatedSpawnNumber() > 1)
435 return;
436
437 array<IEntity> spawnedEntities = attackerLayer.GetSpawnedEntities();
438 SCR_ChimeraCharacter character;
439 DamageManagerComponent damageManager;
440 foreach (IEntity entity : spawnedEntities)
441 {
442 character = SCR_ChimeraCharacter.Cast(entity);
443 if (!character)
444 {
445 SCR_AIGroup group = SCR_AIGroup.Cast(entity);
446 if (group)
447 return;
448 else
449 continue;
450 }
451
452 damageManager = character.GetDamageManager();
453 if (!damageManager.IsDestroyed())
454 return;
455 }
456 }
457
459 }
460
461 //------------------------------------------------------------------------------------------------
470
471 //------------------------------------------------------------------------------------------------
475 override void EOnFrame(IEntity owner, float timeSlice)
476 {
477 if (!m_bInitiated)
478 return;
479
480 super.EOnFrame(owner, timeSlice);
481
482 m_fTempTimeSlice += timeSlice;
483 if (m_fTempTimeSlice >= 1 && m_fTempCountdown >= 0)
484 {
485 UpdateHUD();
488 }
489 else if (m_bEarlierEvaluation && m_fTempTimeSlice >= 5)
490 {
492 }
493
494 ChimeraWorld world = owner.GetWorld();
495 if (!m_bTaskEvaluated && m_bEvaluationSet && world.GetServerTimestamp().GreaterEqual(m_fEvaluateTimeEnd))
496 {
499
502 }
503 }
504
505 //------------------------------------------------------------------------------------------------
507 {
508 return m_fTempCountdown;
509 }
510
511 //------------------------------------------------------------------------------------------------
512 void SetSecondsRemaining(float seconds)
513 {
514 m_fTempCountdown = seconds;
515 }
516}
517
518//------------------------------------------------------------------------------------------------
521{
522 [Attribute(defvalue: "", UIWidgets.EditBox, desc: "Faction Name", category: "")]
524
525 [Attribute(defvalue: "0", UIWidgets.EditBox, desc: "When disabled, all units from this faction will be counted with for other Task Defend conditions", category: "")]
526 protected bool m_bCountOnlyPlayers;
527
528 //------------------------------------------------------------------------------------------------
531 {
532 FactionManager factionManager = GetGame().GetFactionManager();
533 if (factionManager)
534 return factionManager.GetFactionByKey(m_sFactionKey);
535
536 return null;
537 }
538
539 //------------------------------------------------------------------------------------------------
541 void SetFactionKey(FactionKey factionKey)
542 {
543 m_sFactionKey = factionKey;
544 }
545
546 //------------------------------------------------------------------------------------------------
549 {
550 return m_bCountOnlyPlayers;
551 }
552}
553
554//------------------------------------------------------------------------------------------------
555class SCR_ScenarioFrameworkTaskDefendDefendingFactionTitle : BaseContainerCustomTitle
556{
557 //------------------------------------------------------------------------------------------------
562 override bool _WB_GetCustomTitle(BaseContainer source, out string title)
563 {
564 title = "Defending faction";
565 return true;
566 }
568
569//------------------------------------------------------------------------------------------------
572 //------------------------------------------------------------------------------------------------
577 override bool _WB_GetCustomTitle(BaseContainer source, out string title)
578 {
579 title = "Attacking faction";
580 return true;
581 }
583
584//------------------------------------------------------------------------------------------------
585[BaseContainerProps(), SCR_ScenarioFrameworkTaskDefendDefendingFactionTitle()]
586class SCR_ScenarioFrameworkTaskDefendDefendingFaction : SCR_ScenarioFrameworkTaskDefendFactionSettings
587{
588}
590//------------------------------------------------------------------------------------------------
592class SCR_ScenarioFrameworkTaskDefendAttackingFaction : SCR_ScenarioFrameworkTaskDefendFactionSettings
593{
594}
ETimeFormatParam
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
params precision
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Widget m_wRoot
override void EOnFrame(IEntity owner, float timeSlice)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref array< SCR_ScenarioFrameworkLayerBase > m_aChildren
bool m_bShowDebugShapesDuringRuntime
void AfterAllChildrenSpawned(SCR_ScenarioFrameworkLayerBase layer)
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
void DynamicDespawn(SCR_ScenarioFrameworkLayerBase layer)
void ProcessLayerTaskState(SCR_ETaskState state, bool forced=false, bool calledFromSubtask=false)
RichTextWidget m_wCountdown
ref array< SCR_ScenarioFrameworkLayerBase > m_aAttackerLayer
void SetSecondsRemaining(float seconds)
void SetupEvaluation()
Sets up evaluation time, triggers attacker layer, and checks for character trigger entities in scenar...
LocalizedString m_sDelayedEvaluationText
SCR_CharacterTriggerEntity GetCharacterTriggerEntity()
void EvaluateStatus()
Evaluates task status.
void UpdateHUD()
Updates HUD based on task state, displays countdown or delayed evaluation text, hides HUD if task is ...
void SetupAttackerLayer()
Sets up attacker layers from given names in the world.
void SetDefendTime(float time)
SCR_CharacterTriggerEntity m_CharacterTriggerEntity
string m_sFormattedDelayedEvaluationText
UI layouts HUD CampaignMP CampaignMainHUD category
ref array< ref SCR_ScenarioFrameworkTaskDefendFactionSettings > m_aFactionSettings
ref array< string > m_aAttackerLayerNames
void RemovePeriodicUpdates()
Removes periodic updates and clears debug shapes during runtime if not shown.
void RpcDo_UpdateHUD(float countdown)
void CountAttackerDefenderNumbers(out int defenderCount, out int attackerCount)
WorldTimestamp m_fEvaluateTimeEnd
SCR_ScenarioFrameworkTaskDefendAttackingFactionTitle BaseContainerCustomTitle BaseContainerProps()
void InitHUD()
Initializes HUD layout, sets visibility of widgets, sets countdown time, and sets flavor text.
void CheckAttackerLayers()
Checks if attacker layers have repeated spawns, then iterates through spawned entities,...
void FindCharacterTriggerEntity()
Finds character trigger entity by name.
RichTextWidget m_wFlavour
WorldTimestamp m_fEvaluateTimeStart
void RestoreToDefault()
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
SCR_TaskSystem m_TaskSystem
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
static SCR_HUDManagerComponent GetHUDManager()
Widget CreateLayout(ResourceName path, EHudLayers layer, int zOrder=0)
SCR_ScenarioFrameworkLayerTask GetLayerTask()
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_EditableTaskComponentClass m_Task
Editable SCR_BaseTask.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
class SCR_BaseManualCameraComponent _WB_GetCustomTitle(BaseContainer source, out string title)
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