Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignMobileAssemblyComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Campaign", description: "Allow respawning at this vehicle in Campaign", color: "0 0 255 255")]
3{
4 [Attribute("{6D282026AB95FC81}Prefabs/MP/Campaign/CampaignMobileAssemblySpawnpoint.et", UIWidgets.ResourceNamePicker, "", "et")]
6
7 //------------------------------------------------------------------------------------------------
13}
14
15class SCR_CampaignMobileAssemblyComponent : ScriptComponent
16{
17 static const float MAX_WATER_DEPTH = 2.5;
18
19 protected RplComponent m_RplComponent;
20
21 protected bool m_bIsInRadioRange;
22
24
25 protected SCR_CampaignMobileAssemblyStandaloneComponent m_StandaloneComponent;
26
27 [RplProp(onRplName: "OnSpawnpointCreated")]
28 protected int m_iSpawnpointId = RplId.Invalid();
29
30 [RplProp(onRplName: "OnDeployChanged")]
31 protected bool m_bIsDeployed;
32
33 //------------------------------------------------------------------------------------------------
34 override void OnPostInit(IEntity owner)
35 {
36 if (!GetGame().InPlayMode())
37 return;
38
39 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
40
41 if (!campaign)
42 return;
43
44 super.OnPostInit(owner);
45
46 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
47
48 GetGame().GetCallqueue().CallLater(UpdateRadioCoverage, 1000, true);
49
50 if (IsProxy())
51 {
52 campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Insert(OnDeployChanged);
53 }
54 }
55
56 //------------------------------------------------------------------------------------------------
57 override void OnDelete(IEntity owner)
58 {
59 super.OnDelete(owner);
60
61 GetGame().GetCallqueue().Remove(UpdateRadioCoverage);
62
63 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
64
65 if (!campaign)
66 return;
67
68 campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Remove(OnDeployChanged);
69 }
70
71 //------------------------------------------------------------------------------------------------
72 protected bool IsProxy()
73 {
74 return (m_RplComponent && m_RplComponent.IsProxy());
75 }
76
77 //------------------------------------------------------------------------------------------------
79 {
80 const IEntity parent = GetOwner().GetParent();
81 if (!parent)
82 return null;
83
85 const FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(parent.FindComponent(FactionAffiliationComponent));
86 return SCR_CampaignFaction.Cast(factionAffiliation.GetDefaultAffiliatedFaction());
87 }
88
89 //------------------------------------------------------------------------------------------------
92 {
93 IEntity truck = GetOwner().GetParent();
94
95 if (!truck)
96 return 0;
97
98 BaseRadioComponent comp = BaseRadioComponent.Cast(truck.FindComponent(BaseRadioComponent));
99
100 if (!comp)
101 return 0;
102
103 BaseTransceiver tsv = comp.GetTransceiver(0);
104
105 if (!tsv)
106 return 0;
107
108 return tsv.GetRange();
109 }
110
111 //------------------------------------------------------------------------------------------------
116 bool Deploy(SCR_EMobileAssemblyStatus status, int playerId = 0, bool silent = false)
117 {
118 if (!m_bIsInRadioRange && status == SCR_EMobileAssemblyStatus.DEPLOYED)
119 return false;
120
122 if (!faction)
123 return false;
124
125 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
126 if (!campaign)
127 return false;
128
129 if (faction.GetMobileAssembly() && status == SCR_EMobileAssemblyStatus.DEPLOYED)
130 return false;
131
132 if (status == SCR_EMobileAssemblyStatus.DEPLOYED)
133 {
135 m_bIsDeployed = true;
136 }
137 else
138 {
139 m_bIsDeployed = false;
140
141 if (m_SpawnPoint)
142 RplComponent.DeleteRplEntity(m_SpawnPoint, false);
143 }
144
146 Replication.BumpMe();
147
148 if (!silent)
149 campaign.BroadcastMHQFeedback(status, playerId, GetGame().GetFactionManager().GetFactionIndex(faction));
150
151 return true;
152 }
153
154 //------------------------------------------------------------------------------------------------
156 {
157 // No need for SFX on headless
158 if (!System.IsConsoleApp())
159 {
161
162 if (sndComp)
163 {
164 if (m_bIsDeployed)
165 sndComp.SoundEvent(SCR_SoundEvent.SOUND_MHQ_DEPLOY);
166 else
167 sndComp.SoundEvent(SCR_SoundEvent.SOUND_MHQ_DISMANTLE);
168 }
169 }
170
171 if (IsProxy())
172 return;
173
174 if (m_bIsDeployed)
175 GetGame().GetCallqueue().CallLater(CheckStatus, 500, true);
176 else
177 GetGame().GetCallqueue().Remove(CheckStatus);
178
179 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
180 if (!campaign)
181 return;
182
183 SCR_CampaignMilitaryBaseManager baseManager = campaign.GetBaseManager();
184 if (!baseManager)
185 return;
186
187 baseManager.DelayedEvaluateControlPoints(0);
188 }
189
190 //------------------------------------------------------------------------------------------------
193 {
194 IEntity truck = GetOwner().GetParent();
195
196 if (!truck)
197 return;
198
199 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
200
201 if (!campaign)
202 return;
203
205
206 // Destroyed?
207 if (damageComponent && damageComponent.GetState() == EDamageState.DESTROYED)
208 {
210
211 return;
212 }
213
214 // Moved?
215 Physics physicsComponent = truck.GetPhysics();
216
217 if (!physicsComponent)
218 return;
219
220 vector vel = physicsComponent.GetVelocity();
221 vel[1] = 0;
222
223 if (vel.LengthSq() <= 0.01)
224 return;
225
227 }
228
229 //------------------------------------------------------------------------------------------------
231 {
232 // Delay so spawnpoint has time to be streamed in for clients
233 GetGame().GetCallqueue().CallLater(RegisterSpawnpoint, 1000);
234 }
235
236 //------------------------------------------------------------------------------------------------
239 {
240 // On server the assignment is done in CreateSpawnpoint()
241 if (!IsProxy())
242 return;
243
245
246 if (!m_SpawnPoint)
247 return;
248
249 m_StandaloneComponent = SCR_CampaignMobileAssemblyStandaloneComponent.Cast(m_SpawnPoint.FindComponent(SCR_CampaignMobileAssemblyStandaloneComponent));
250 }
251
252 //------------------------------------------------------------------------------------------------
255 {
256 return m_SpawnPoint;
257 }
258
259 //------------------------------------------------------------------------------------------------
261 SCR_CampaignMobileAssemblyStandaloneComponent GetStandaloneComponent()
262 {
264 }
265
266 //------------------------------------------------------------------------------------------------
269 {
270 return m_bIsDeployed;
271 }
272
273 //------------------------------------------------------------------------------------------------
276 {
277 return m_bIsInRadioRange;
278 }
279
280 //------------------------------------------------------------------------------------------------
283 {
285 if (!faction)
286 return;
287
288 m_bIsInRadioRange = SCR_GameModeCampaign.GetInstance().GetBaseManager().IsEntityInFactionRadioSignal(GetOwner(), faction);
289 }
290
291 //------------------------------------------------------------------------------------------------
294 {
296 if (!componentData)
297 return;
298
299 Resource spawnpointResource = Resource.Load(componentData.GetSpawnpointPrefab());
300 if (!spawnpointResource || !spawnpointResource.IsValid())
301 return;
302
304 params.TransformMode = ETransformMode.WORLD;
305 GetOwner().GetTransform(params.Transform);
306 m_SpawnPoint = SCR_SpawnPoint.Cast(GetGame().SpawnEntityPrefab(spawnpointResource, null, params));
307 if (!m_SpawnPoint)
308 return;
309
310 m_StandaloneComponent = SCR_CampaignMobileAssemblyStandaloneComponent.Cast(m_SpawnPoint.FindComponent(SCR_CampaignMobileAssemblyStandaloneComponent));
312 {
313 m_StandaloneComponent.SetRadioRange(GetRadioRange());
315
317 if (faction)
318 m_StandaloneComponent.SetParentFactionID(GetGame().GetFactionManager().GetFactionIndex(faction));
319 }
320
323 Replication.BumpMe();
324 }
325
326 //------------------------------------------------------------------------------------------------
327 // destructor
329 {
330 if (Replication.IsClient())
331 return;
332
333 if (m_SpawnPoint)
334 RplComponent.DeleteRplEntity(m_SpawnPoint, false);
335
336 if (IsDeployed())
338 }
339}
340
ArmaReforgerScripted GetGame()
Definition game.c:1398
int GetFactionIndex()
@ DESTROYED
engine is destroyed
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
RplComponent m_RplComponent
SCR_CampaignMobileAssemblyComponentClass MAX_WATER_DEPTH
SCR_CampaignMobileAssemblyStandaloneComponent m_StandaloneComponent
void ~SCR_CampaignMobileAssemblyComponent()
SCR_SpawnPoint m_SpawnPoint
SCR_CampaignMobileAssemblyStandaloneComponent GetStandaloneComponent()
SCR_SpawnPoint GetSpawnPoint()
bool Deploy(SCR_EMobileAssemblyStatus status, int playerId=0, bool silent=false)
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_VehicleSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
proto external Physics GetPhysics()
proto external void GetTransform(out vector mat[])
proto external IEntity GetParent()
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
SCR_CampaignMobileAssemblyStandaloneComponent GetMobileAssembly()
static IEntity GetMainParent(IEntity entity, bool self=false)
Spawn point entity defines positions on which players can possibly spawn.
proto external GenericEntity GetOwner()
Get owner entity.
void EntitySpawnParams()
Definition gameLib.c:130
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_CampaignFaction GetAffiliatedFaction()
Returns the affiliated faction or null if none.
SCR_FieldOfViewSettings Attribute
EDamageState