Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResupplyTaskCreator.c
Go to the documentation of this file.
3{
4 [Attribute("1", desc: "If enabled, resupply tasks are created for ALL playable factions and the Faction Keys list is ignored. If disabled, resupply tasks are created only for factions listed in Faction Keys.")]
6
7 [Attribute(desc: "List of faction keys eligible for resupply tasks. Only used if 'CreateForAllPlayableFactions' is disabled.")]
8 protected ref array<FactionKey> m_aFactionKeys;
9
12
13 protected static const string CAMPAIGN_RESUPPLY_TASK_ID = "%1_CampaignResupplyTask_%2";
14
15 //------------------------------------------------------------------------------------------------
16 override void Init(SCR_TaskCreatorComponent taskCreatorComponent)
17 {
18 super.Init(taskCreatorComponent);
19
20 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
21 if (!campaign)
22 return;
23
24 m_MilitaryBaseManager = campaign.GetBaseManager();
26 return;
27
28 array<SCR_CampaignMilitaryBaseComponent> bases = {};
29 m_MilitaryBaseManager.GetBases(bases);
31 {
33 }
34
35 m_MilitaryBaseManager.GetOnBaseBuilt().Insert(OnBaseBuilt);
36 m_MilitaryBaseManager.GetOnSignalChanged().Insert(OnSignalChanged);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 override void Deinit()
43 {
45 {
46 m_MilitaryBaseManager.GetOnBaseBuilt().Remove(OnBaseBuilt);
47 m_MilitaryBaseManager.GetOnSignalChanged().Remove(OnSignalChanged);
48 }
49
50 foreach (SCR_ResourceConsumer resourceConsumer, SCR_CampaignMilitaryBaseComponent campaignBase : m_mBaseToResourceConsumer)
51 {
52 UnsubscribeFromBaseEvents(campaignBase);
53 }
54
56 if (militaryBaseSystem)
57 {
58 militaryBaseSystem.GetOnBaseFactionChanged().Remove(OnBaseFactionChanged);
59 militaryBaseSystem.GetInstance().GetOnBaseUnregistered().Remove(UnsubscribeFromBaseEvents);
60 }
61
62 super.Deinit();
63 }
64
65 //------------------------------------------------------------------------------------------------
67 {
68 if (!campaignBase)
69 return;
70
71 if (campaignBase.GetType() != SCR_ECampaignBaseType.BASE)
72 return;
73
74 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(campaignBase.GetFaction());
75 if (!faction)
76 return;
77
78 if (!campaignBase.IsHQRadioTrafficPossible(faction, SCR_ERadioCoverageStatus.BOTH_WAYS))
79 return;
80
82
83 SCR_ResourceConsumer resourceConsumer = campaignBase.GetResourceConsumer();
84 if (!resourceConsumer)
85 return;
86
87 if (!m_mBaseToResourceConsumer.Contains(resourceConsumer))
88 m_mBaseToResourceConsumer.Insert(resourceConsumer, campaignBase);
89
90 resourceConsumer.GetOnResourcesChanged().Insert(OnResourcesChanged);
91 resourceConsumer.GetOnMaxResourcesChanged().Insert(OnResourcesChanged);
92 }
93
94 //------------------------------------------------------------------------------------------------
95 protected void UnsubscribeFromBaseEvents(SCR_MilitaryBaseComponent base)
96 {
98 if (!campaignBase)
99 return;
100
101 if (campaignBase.GetType() != SCR_ECampaignBaseType.BASE)
102 return;
103
104 campaignBase.GetOnSupplyLimitChanged().Remove(OnSuppliesLimitChanged);
105
106 SCR_ResourceConsumer resourceConsumer = campaignBase.GetResourceConsumer();
107 if (!resourceConsumer)
108 return;
109
110 resourceConsumer.GetOnResourcesChanged().Remove(OnResourcesChanged);
111 resourceConsumer.GetOnMaxResourcesChanged().Remove(OnResourcesChanged);
112
113 m_mBaseToResourceConsumer.Remove(resourceConsumer);
114 }
115
116 //------------------------------------------------------------------------------------------------
118 {
119 if (!campaignBase || !campaignBase.IsInitialized())
120 return;
121
122 if (campaignBase.GetType() != SCR_ECampaignBaseType.BASE)
123 return;
124
125 SCR_CampaignFaction faction = campaignBase.GetCampaignFaction();
126 if (!faction || !faction.IsPlayable())
127 return;
128
129 SCR_GroupTaskManagerComponent groupTaskManager = SCR_GroupTaskManagerComponent.GetInstance();
130 if (!groupTaskManager || !groupTaskManager.CanCreateNewTaskWithResourceName(m_sTaskPrefab, faction))
131 return;
132
133 if (!m_bCreateForAllPlayableFactions && !m_aFactionKeys.Contains(faction.GetFactionKey()))
134 return;
135
136 if (!campaignBase.IsHQRadioTrafficPossible(faction, SCR_ERadioCoverageStatus.RECEIVE))
137 return;
138
139 if (!campaignBase.IsResupplyTaskCreationEnabled() || !campaignBase.IsResupplyNeeded())
140 return;
141
142 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
143 if (!taskSystem)
144 return;
145
146 string taskId = string.Format(CAMPAIGN_RESUPPLY_TASK_ID, faction.GetFactionKey(), campaignBase.GetCallsign());
147 if (SCR_TaskSystem.GetTaskFromTaskID(taskId, false))
148 return;
149
150 vector position = campaignBase.GetOwner().GetOrigin() + {10, 0, 10}; // quick fix - set 10m offset
151 SCR_ResupplyCampaignMilitaryBaseTaskEntity newTask = SCR_ResupplyCampaignMilitaryBaseTaskEntity.Cast(taskSystem.CreateTask(
152 m_sTaskPrefab, taskId, "", "", position
153 ));
154
155 if (!newTask)
156 return;
157
158 newTask.SetMilitaryBaseCallSign(campaignBase.GetCallsign());
159 taskSystem.SetTaskOwnership(newTask, SCR_ETaskOwnership.EXECUTOR);
160 taskSystem.SetTaskVisibility(newTask, SCR_ETaskVisibility.GROUP);
161 taskSystem.AddTaskFaction(newTask, faction.GetFactionKey());
162
163 SCR_TaskUIInfo taskUIInfo = newTask.GetTaskUIInfo();
164 if (!taskUIInfo)
165 return;
166
167 newTask.SetTaskName(taskUIInfo.GetName(), { campaignBase.GetFormattedBaseNameWithCallsign(faction) });
168
169 groupTaskManager.SetGroupTask(newTask, 0);
170 }
171
172 //------------------------------------------------------------------------------------------------
173 protected void OnSuppliesLimitChanged(SCR_CampaignMilitaryBaseComponent campaignBase, float supplyLimit)
174 {
175 TryCreateResupplyTaskDelayed(campaignBase);
176 }
177
178 //------------------------------------------------------------------------------------------------
179 protected void OnResourcesChanged(SCR_ResourceInteractor resourceInteractor, float value)
180 {
181 SCR_ResourceConsumer resourceConsumer = SCR_ResourceConsumer.Cast(resourceInteractor);
182 if (!resourceConsumer)
183 return;
184
185 SCR_CampaignMilitaryBaseComponent campaignBase = m_mBaseToResourceConsumer.Get(resourceConsumer);
186 TryCreateResupplyTaskDelayed(campaignBase);
187 }
188
189 //------------------------------------------------------------------------------------------------
190 protected void OnBaseBuilt(SCR_CampaignMilitaryBaseComponent campaignBase, Faction faction)
191 {
192 if (!campaignBase)
193 return;
194
195 TryCreateResupplyTaskDelayed(campaignBase);
196
197 SubscribeToBaseEvents(campaignBase);
198 }
199
200 //------------------------------------------------------------------------------------------------
202 {
203 if (!campaignBase)
204 return;
205
206 TryCreateResupplyTaskDelayed(campaignBase);
207
208 SubscribeToBaseEvents(campaignBase);
209 }
210
211 //------------------------------------------------------------------------------------------------
212 protected void OnBaseFactionChanged (SCR_MilitaryBaseComponent base, Faction faction)
213 {
215 if (!campaignBase)
216 return;
217
218 TryCreateResupplyTaskDelayed(campaignBase);
219 }
220
222 {
223 // I give up - there is so many calllaters in original implementation that I will just use them as well
224 GetGame().GetCallqueue().CallLater(TryCreateResuplyTask, SCR_GameModeCampaign.MEDIUM_DELAY, false, campaignBase);
225 }
226}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
vector position
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ETaskVisibility
Definition SCR_Task.c:24
SCR_ECampaignBaseType GetType()
Returns type of this base.
bool IsHQRadioTrafficPossible(notnull SCR_CampaignFaction faction, SCR_ERadioCoverageStatus direction=SCR_ERadioCoverageStatus.RECEIVE)
SCR_CampaignFaction GetCampaignFaction()
Returns the owning faction.
OnBaseFactionChangedInvoker GetOnBaseFactionChanged()
static SCR_MilitaryBaseSystem GetInstance()
OnBaseUnregisteredInvoker GetOnBaseUnregistered()
void TryCreateResupplyTaskDelayed(SCR_CampaignMilitaryBaseComponent campaignBase)
void OnSignalChanged(SCR_CampaignMilitaryBaseComponent campaignBase)
void OnBaseFactionChanged(SCR_MilitaryBaseComponent base, Faction faction)
void OnSuppliesLimitChanged(SCR_CampaignMilitaryBaseComponent campaignBase, float supplyLimit)
void SubscribeToBaseEvents(SCR_CampaignMilitaryBaseComponent campaignBase)
override void Init(SCR_TaskCreatorComponent taskCreatorComponent)
void OnResourcesChanged(SCR_ResourceInteractor resourceInteractor, float value)
static const string CAMPAIGN_RESUPPLY_TASK_ID
void OnBaseBuilt(SCR_CampaignMilitaryBaseComponent campaignBase, Faction faction)
void TryCreateResuplyTask(SCR_CampaignMilitaryBaseComponent campaignBase)
SCR_CampaignMilitaryBaseManager m_MilitaryBaseManager
void UnsubscribeFromBaseEvents(SCR_MilitaryBaseComponent base)
ref array< FactionKey > m_aFactionKeys
ref map< SCR_ResourceConsumer, SCR_CampaignMilitaryBaseComponent > m_mBaseToResourceConsumer
ResourceName m_sTaskPrefab
Definition Types.c:486
SCR_FieldOfViewSettings Attribute