Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignDefendTaskSupportEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Tasks", description: "Campaign defend task support entity.", color: "0 0 255 255")]
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
8 void OnCharacterDeath(SCR_ChimeraCharacter character);
10 typedef ScriptInvokerBase<OnCharacterDeath> OnCharacterDeathInvoker;
11 
12 //------------------------------------------------------------------------------------------------
14 {
15  [Attribute("300", desc: "From how far can an ally request reinforcements. (in m)")]
16  protected float m_fMinAllyDistance;
17 
18  [Attribute("400", desc: "How far an ally can be to receive rewards for this task. (in m)")]
19  protected float m_fMaxAllyDistance;
20 
21  [Attribute("300", desc: "How far an enemy has to be, for an ally to be able to request reinforcements. (in m)")]
22  protected float m_fMinEnemyDistance;
23 
24  [Attribute("400", desc: "How far an enemy has to be, to be outside of the radius of an existing defend task. (in m)")]
25  protected float m_fMaxEnemyDistance;
26 
27  // This only holds living characters, no need to check whether they are alive!!
28  protected ref map<SCR_CampaignFaction, ref array<SCR_ChimeraCharacter>> m_mFactionSortedCharacters = new map<SCR_CampaignFaction, ref array<SCR_ChimeraCharacter>>();
29 
30  protected ref OnCharacterDeathInvoker m_OnCharacterDeath;
31 
32  protected SCR_CampaignMilitaryBaseComponent m_ClosestBase;
33 
34  //------------------------------------------------------------------------------------------------
35  OnCharacterDeathInvoker GetOnCharacterDeath()
36  {
37  if (!m_OnCharacterDeath)
38  m_OnCharacterDeath = new OnCharacterDeathInvoker();
39 
40  return m_OnCharacterDeath;
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  override bool CanRequest()
45  {
47  if (!playerController)
48  return false;
49 
50  if (!SCR_CampaignDefendTask.CheckDefendRequestConditions(playerController, m_ClosestBase))
51  return false;
52 
53  return true;
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  override void Request()
58  {
59  PlayerController playerController = GetGame().GetPlayerController();
60  if (!playerController)
61  return;
62 
63  SCR_UIRequestEvacTaskComponent.RequestReinforcements(playerController);
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  override void SetRequestButtonText(notnull TextWidget textWidget)
68  {
69  if (!m_ClosestBase)
70  return;
71 
72  textWidget.SetTextFormat(m_sRequestButtonText, m_ClosestBase.GetBaseName());
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
77  void RPC_SetTargetBase(int taskID, int baseID)
78  {
79  if (!GetTaskManager())
80  return;
81 
83  if (!task)
84  return;
85 
86  SCR_CampaignMilitaryBaseComponent base = SCR_GameModeCampaign.GetInstance().GetBaseManager().FindBaseByCallsign(baseID);
87  if (!base)
88  return;
89 
90  task.SetTargetBase(base);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  void SetTargetBase(notnull SCR_CampaignBaseTask task, notnull SCR_CampaignMilitaryBaseComponent base)
95  {
96  if (!GetTaskManager())
97  return;
98 
99  int taskID, baseID;
100 
101  taskID = task.GetTaskID();
102  baseID = base.GetCallsign();
103 
104  Rpc(RPC_SetTargetBase, taskID, baseID);
105  RPC_SetTargetBase(taskID, baseID);
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  void CreateCampaignDefendTask(SCR_CampaignMilitaryBaseComponent targetBase, Faction targetFaction)
110  {
111  if (!GetTaskManager())
112  return;
113 
115  if (!defendTask)
116  return;
117 
118  SetTargetBase(defendTask, targetBase); // Replicated internally
119  SetTargetFaction(defendTask, targetFaction); // Replicated internally
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  void OnControllableCreated(IEntity controllable)
124  {
125  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(controllable);
126  if (!character)
127  return;
128 
129  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
130  if (!faction)
131  return;
132 
133  array<SCR_ChimeraCharacter> factionCharacters = GetCharactersByFaction(faction);
134  if (!factionCharacters)
135  {
136  factionCharacters = new array<SCR_ChimeraCharacter>();
137  m_mFactionSortedCharacters.Insert(faction, factionCharacters);
138  }
139 
140  factionCharacters.Insert(character);
141 
142  SCR_CharacterControllerComponent characterControllerComponent = SCR_CharacterControllerComponent.Cast(character.FindComponent(SCR_CharacterControllerComponent));
143  if (!characterControllerComponent)
144  return;
145 
146  characterControllerComponent.GetOnPlayerDeathWithParam().Insert(OnCharacterDeath);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  void OnCharacterDeath(SCR_CharacterControllerComponent characterControllerComponent, IEntity killerEntity, Instigator killer)
151  {
152  SCR_ChimeraCharacter character = characterControllerComponent.GetCharacter();
153  if (!character)
154  return;
155 
156  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
157  if (!faction)
158  return;
159 
160  array<SCR_ChimeraCharacter> factionCharacters = m_mFactionSortedCharacters.Get(faction);
161  if (!factionCharacters)
162  return;
163 
164  factionCharacters.RemoveItem(character);
165 
166  if (m_OnCharacterDeath)
167  m_OnCharacterDeath.Invoke(character);
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  //Only for cases when character is removed before dying
172  void OnControllableDeleted(IEntity controllable)
173  {
174  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(controllable);
175  if (!character)
176  return;
177 
178  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
179  if (!faction)
180  return;
181 
182  array<SCR_ChimeraCharacter> factionCharacters = m_mFactionSortedCharacters.Get(faction);
183  if (!factionCharacters)
184  return;
185 
186  if (factionCharacters.Find(character) > -1)
187  factionCharacters.RemoveItem(character);
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  array<SCR_ChimeraCharacter> GetCharactersByFaction(SCR_CampaignFaction faction)
192  {
193  array<SCR_ChimeraCharacter> characters = m_mFactionSortedCharacters.Get(faction);
194 
195  if (!characters)
196  return characters;
197 
198  // TODO matousvoj1: Proper removal of these items once OnDelete is called on entities
199  // Added to avoid nulls in arrays
200  for (int i = characters.Count() - 1; i >= 0; i--)
201  {
202  if (!characters[i])
203  characters.Remove(i);
204  }
205 
206  return characters;
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  float GetMinAllyDistance()
211  {
212  return m_fMinAllyDistance;
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  float GetMaxAllyDistance()
217  {
218  return m_fMaxAllyDistance;
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  float GetMinEnemyDistance()
223  {
224  return m_fMinEnemyDistance;
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  float GetMaxEnemyDistance()
229  {
230  return m_fMaxEnemyDistance;
231  }
232 
233  //------------------------------------------------------------------------------------------------
234  override void OnTaskListOpen(notnull SCR_UITaskManagerComponent uiTaskManagerComponent)
235  {
236  if (!CanRequest())
237  return;
238 
239  if (!m_ClosestBase)
240  return;
241 
242  array<Widget> widgets = uiTaskManagerComponent.GetWidgetsArray();
243  if (!widgets)
244  return;
245 
246  Widget button = CreateButtonAndSetPadding(uiTaskManagerComponent.GetParentWidget(), widgets);
247  if (!button)
248  return;
249 
250  TextWidget textWidget = TextWidget.Cast(button.FindAnyWidget("Text"));
251  if (textWidget)
252  SetRequestButtonText(textWidget);
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  override void Initialize()
257  {
259  if (!gameMode)
260  return;
261 
262  gameMode.GetOnControllableSpawned().Insert(OnControllableCreated);
263  gameMode.GetOnControllableDeleted().Insert(OnControllableDeleted);
264  }
265 
266  //------------------------------------------------------------------------------------------------
268  {
270  if (gameMode)
271  {
272  gameMode.GetOnControllableSpawned().Remove(OnControllableCreated);
273  gameMode.GetOnControllableDeleted().Remove(OnControllableDeleted);
274  }
275 
276  SCR_CharacterControllerComponent characterControllerComponent;
277  array<SCR_ChimeraCharacter> characters;
278  for (int i = m_mFactionSortedCharacters.Count() - 1; i >= 0; i--)
279  {
280  characters = m_mFactionSortedCharacters.GetElement(i);
281  if (!characters)
282  continue;
283 
284  for (int j = characters.Count() - 1; j >= 0; j--)
285  {
286  if (!characters[j])
287  continue;
288 
289  characterControllerComponent = SCR_CharacterControllerComponent.Cast(characters[j].FindComponent(SCR_CharacterControllerComponent));
290  if (!characterControllerComponent)
291  return;
292 
293  characterControllerComponent.GetOnPlayerDeathWithParam().Remove(OnCharacterDeath);
294  }
295  }
296  }
297 };
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_CampaignBaseTask
Definition: SCR_CampaignBaseTask.c:9
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_RequestedTaskSupportEntityClass
Definition: SCR_RequestedTaskSupportEntity.c:3
SCR_UIRequestEvacTaskComponent
Definition: SCR_UIRequestEvacTaskComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_RequestedTaskSupportEntity
Definition: SCR_RequestedTaskSupportEntity.c:8
SCR_CampaignDefendTaskSupportEntity
Definition: SCR_CampaignDefendTaskSupportEntity.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetTask
SCR_ScenarioFrameworkTask GetTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:65
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
Instigator
Definition: Instigator.c:6
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
Attribute
typedef Attribute
Post-process effect of scripted camera.
OnCharacterDeathInvoker
ScriptInvokerBase< OnCharacterDeath > OnCharacterDeathInvoker
Definition: SCR_CampaignDefendTaskSupportEntity.c:10
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
Faction
Definition: Faction.c:12
OnCharacterDeath
func OnCharacterDeath
Definition: SCR_CampaignDefendTaskSupportEntity.c:9
SCR_CampaignDefendTaskSupportEntityClass
Definition: SCR_CampaignDefendTaskSupportEntity.c:3
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
CreateTask
protected bool CreateTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:389
SCR_CampaignDefendTask
Definition: SCR_CampaignDefendTask.c:7
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180