Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkSystemSerializer.c
Go to the documentation of this file.
2class SCR_ScenarioFrameworkSystemData : PersistentState
3{
4}
5
6class SCR_ScenarioFrameworkSystemSerializer : ScriptedStateSerializer
7{
8 //------------------------------------------------------------------------------------------------
9 override static typename GetTargetType()
10 {
12 }
13
14 //------------------------------------------------------------------------------------------------
15 override ESerializeResult Serialize(notnull Managed instance, notnull SaveContext context)
16 {
18 if (!scenarioFrameworkSystem)
19 return ESerializeResult.DEFAULT;
20
21 if (scenarioFrameworkSystem.GetIsMatchOver())
22 {
23 context.WriteValue("version", 1);
24 context.WriteValue("matchOver", true);
25 }
26
27 const EGameOverTypes gameOverType = scenarioFrameworkSystem.m_eGameOverType;
28
29 // Area data
30 array<ref SCR_ScenarioFrameworkAreaSave> areas();
31 StoreAreaStates(GetSystem(), scenarioFrameworkSystem, areas);
32
33 // After Tasks Init Actions
34 array<ref SCR_ScenarioFrameworkActionSave> afterTasksInitActions();
35 SCR_ScenarioFrameworkActionSave.ReadActions(GetSystem(), scenarioFrameworkSystem.m_aAfterTasksInitActions, afterTasksInitActions);
36
37 if ((gameOverType == EGameOverTypes.COMBATPATROL_DRAW) &&
38 areas.IsEmpty() &&
39 afterTasksInitActions.IsEmpty() &&
40 scenarioFrameworkSystem.m_mVariableMap.IsEmpty())
41 return ESerializeResult.DEFAULT;
42
43 context.WriteValue("version", 1);
44 context.WriteValueDefault("matchOver", false, false);
45 context.WriteDefault(gameOverType, EGameOverTypes.COMBATPATROL_DRAW);
46
47 if (!context.CanSeekMembers() || !areas.IsEmpty())
48 context.Write(areas);
49
50 if (!context.CanSeekMembers() || !afterTasksInitActions.IsEmpty())
51 context.Write(afterTasksInitActions);
52
53 if (!context.CanSeekMembers() || !scenarioFrameworkSystem.m_mVariableMap.IsEmpty())
54 context.WriteValue("variables", scenarioFrameworkSystem.m_mVariableMap);
55
56 return ESerializeResult.OK;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 override bool Deserialize(notnull Managed instance, notnull LoadContext context)
61 {
63 if (!scenarioFrameworkSystem)
64 return true; // SF system no longer present, so we can ignore it.
65
66 scenarioFrameworkSystem.m_bIsSaveGameLoad = true;
67
68 int version;
69 context.Read(version);
70
71 bool matchOver;
72 context.ReadDefault(matchOver, false);
73
74 EGameOverTypes gameOverType;
75 if (context.Read(gameOverType))
76 scenarioFrameworkSystem.m_eGameOverType = gameOverType;
77
78 array<ref SCR_ScenarioFrameworkAreaSave> areas();
79 if (!context.Read(areas) && !context.CanSeekMembers())
80 return false;
81
82 LoadAreaStates(GetSystem(), scenarioFrameworkSystem, areas);
83
84 array<ref SCR_ScenarioFrameworkActionSave> afterTasksInitActions();
85 if (!context.Read(afterTasksInitActions) && !context.CanSeekMembers())
86 return false;
87
88 foreach (auto action : afterTasksInitActions)
89 {
90 action.Write(GetSystem(), scenarioFrameworkSystem, scenarioFrameworkSystem.m_aAfterTasksInitActions);
91 }
92
93 context.ReadValue("variables", scenarioFrameworkSystem.m_mVariableMap);
94
95 return true;
96 }
97
98 //------------------------------------------------------------------------------------------------
99 protected void StoreAreaStates(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, out array<ref SCR_ScenarioFrameworkAreaSave> saves)
100 {
101 for (int i = scenarioFrameworkSystem.m_aAreas.Count() - 1; i >= 0; i--)
102 {
103 SCR_ScenarioFrameworkAreaSave save();
104 save.Read(persistence, scenarioFrameworkSystem.m_aAreas[i]);
105 if (!save.IsDefault())
106 saves.Insert(save);
107 }
108 }
109
110 //------------------------------------------------------------------------------------------------
111 protected void LoadAreaStates(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, array<ref SCR_ScenarioFrameworkAreaSave> saves)
112 {
113 foreach (SCR_ScenarioFrameworkAreaSave areaSave : saves)
114 {
115 auto entity = GetGame().GetWorld().FindEntityByName(areaSave.m_sName);
116 if (!entity)
117 continue;
118
119 auto area = SCR_ScenarioFrameworkArea.Cast(entity.FindComponent(SCR_ScenarioFrameworkArea));
120 if (!area)
121 continue;
122
123 areaSave.Write(persistence, scenarioFrameworkSystem, area);
124 }
125 }
126}
127
129{
130 string m_sName;
131 bool m_bIsTerminated;
132 int m_iActivationType;
133 int m_iRepeatedSpawnNumber;
134 ref array<string> m_aRandomlySpawnedChildren = {};
135 ref array<ref SCR_ScenarioFrameworkLogicSave> m_aLogics = {};
136 ref array<ref SCR_ScenarioFrameworkLayerSave> m_aChildLayers = {};
137 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActivationActions = {};
138 ref array<ref SCR_ScenarioFrameworkPluginSave> m_aPlugins = {};
139
140 //------------------------------------------------------------------------------------------------
142 {
143 if (layer.IsInherited(SCR_ScenarioFrameworkLayerTaskDefend))
145
146 if (layer.IsInherited(SCR_ScenarioFrameworkLayerTask))
147 return new SCR_ScenarioFrameworkLayerTaskSave();
148
149 if (layer.IsInherited(SCR_ScenarioFrameworkSlotAI))
151
152 if (layer.IsInherited(SCR_ScenarioFrameworkSlotTaskAI))
154
155 if (layer.IsInherited(SCR_ScenarioFrameworkSlotTask))
156 return new SCR_ScenarioFrameworkSlotTaskSave();
157
158 if (layer.IsInherited(SCR_ScenarioFrameworkSlotTrigger))
159 return new SCR_ScenarioFrameworkSlotTriggerSave();
160
161 if (layer.IsInherited(SCR_ScenarioFrameworkSlotBase))
162 return new SCR_ScenarioFrameworkSlotSave();
163
164 if (layer.IsInherited(SCR_ScenarioFrameworkArea))
165 return new SCR_ScenarioFrameworkAreaSave();
166
168 }
169
170 //------------------------------------------------------------------------------------------------
172 {
173 m_sName = layer.GetName();
174
175 m_iActivationType = layer.GetActivationType();
176 if (m_iActivationType == layer.m_eActivationTypeDefault)
177 m_iActivationType = -1; // Default
178
179 m_bIsTerminated = layer.GetIsTerminated();
180
181 m_iRepeatedSpawnNumber = layer.GetRepeatedSpawnNumber();
182 if (m_iRepeatedSpawnNumber == layer.m_iRepeatedSpawnNumberDefault)
183 m_iRepeatedSpawnNumber = 0;
184
185 // Logics
186 array<SCR_ScenarioFrameworkLogic> logics();
187 layer.GetLogics(logics);
188 foreach (SCR_ScenarioFrameworkLogic logic : logics)
189 {
190 auto logicCounter = SCR_ScenarioFrameworkLogicCounter.Cast(logic);
191 if (!logicCounter)
192 continue;
193
194 SCR_ScenarioFrameworkLogicCounterSave logicSave();
195 logicSave.Read(persistence, logicCounter);
196 if (!logicSave.IsDefault())
197 m_aLogics.Insert(logicSave);
198 }
199
200 // Randomization
201 if (layer.GetSpawnChildrenType() != SCR_EScenarioFrameworkSpawnChildrenType.ALL)
202 {
203 foreach (auto randomlayer : layer.GetRandomlySpawnedChildren())
204 {
205 m_aRandomlySpawnedChildren.Insert(randomlayer.GetName());
206 }
207 }
208
209 // Children
210 array<SCR_ScenarioFrameworkLayerBase> children();
211 layer.GetChildren(children);
212 foreach (auto childLayer : children)
213 {
214 auto childSave = GetLayerTypeSave(childLayer);
215 childSave.Read(persistence, childLayer);
216 if (!childSave.IsDefault())
217 m_aChildLayers.Insert(childSave);
218 }
219
220 // Activation Actions
221 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layer.GetActivationActions(), m_aActivationActions);
222
223 // Plugins
224 auto plugins = layer.GetSpawnedPlugins();
225 foreach (SCR_ScenarioFrameworkPlugin plugin : plugins)
226 {
227 auto pluginSave = SCR_ScenarioFrameworkPluginSave.GetSaveType(plugin);
228 pluginSave.Read(persistence, layer, plugin);
229 if (!pluginSave.IsDefault())
230 m_aPlugins.Insert(pluginSave);
231 }
232 }
233
234 //------------------------------------------------------------------------------------------------
235 bool IsDefault()
236 {
237 return
238 m_aChildLayers.IsEmpty() &&
239 m_aLogics.IsEmpty() &&
240 m_aRandomlySpawnedChildren.IsEmpty() &&
241 m_iActivationType == -1 &&
242 m_bIsTerminated == false &&
243 m_iRepeatedSpawnNumber == 0 &&
244 m_aActivationActions.IsEmpty() &&
245 m_aPlugins.IsEmpty();
246 }
247
248 //------------------------------------------------------------------------------------------------
250 {
251 if (m_iRepeatedSpawnNumber != 0)
252 {
253 layer.SetEnableRepeatedSpawn(true);
254 layer.SetRepeatedSpawnNumber(m_iRepeatedSpawnNumber);
255 }
256
257 if (m_iActivationType != -1)
258 layer.SetActivationType(m_iActivationType);
259
260 layer.SetIsTerminated(m_bIsTerminated);
261
262 if (!m_aRandomlySpawnedChildren.IsEmpty())
263 layer.SetRandomlySpawnedChildren(m_aRandomlySpawnedChildren);
264
265 foreach (auto logic : m_aLogics)
266 {
267 logic.Write(persistence, scenarioFrameworkSystem);
268 }
269
270 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActivationActions, layer.GetActivationActions());
271
272 foreach (auto plugin : m_aPlugins)
273 {
274 plugin.Write(persistence, scenarioFrameworkSystem, layer, layer.GetSpawnedPlugins());
275 }
276
277 BaseWorld world = GetGame().GetWorld();
278 foreach (auto saveData : m_aChildLayers)
279 {
280 IEntity entity = world.FindEntityByName(saveData.m_sName);
281 if (!entity)
282 continue;
283
285 if (childlayer)
286 saveData.Write(persistence, scenarioFrameworkSystem, childlayer);
287 }
288 }
289
290 //------------------------------------------------------------------------------------------------
291 bool SerializationSave(SaveContext context)
292 {
293 context.Write(m_sName);
294
295 if (!context.CanSeekMembers() || !m_aChildLayers.IsEmpty())
296 context.Write(m_aChildLayers);
297
298 if (!context.CanSeekMembers() || !m_aLogics.IsEmpty())
299 context.Write(m_aLogics);
300
301 if (!context.CanSeekMembers() || !m_aRandomlySpawnedChildren.IsEmpty())
302 context.Write(m_aRandomlySpawnedChildren);
303
304 context.WriteDefault(m_iActivationType, -1);
305 context.WriteDefault(m_iRepeatedSpawnNumber, 0);
306 context.WriteDefault(m_bIsTerminated, false);
307
308 if (!context.CanSeekMembers() || !m_aActivationActions.IsEmpty())
309 context.Write(m_aActivationActions);
310
311 if (!context.CanSeekMembers() || !m_aPlugins.IsEmpty())
312 context.Write(m_aPlugins);
313
314 return true;
315 }
316
317 //------------------------------------------------------------------------------------------------
318 bool SerializationLoad(LoadContext context)
319 {
320 context.Read(m_sName);
321
322 if (!context.Read(m_aChildLayers) && !context.CanSeekMembers())
323 return false;
324
325 if (!context.Read(m_aLogics) && !context.CanSeekMembers())
326 return false;
327
328 if (!context.Read(m_aRandomlySpawnedChildren) && !context.CanSeekMembers())
329 return false;
330
331 context.ReadDefault(m_iActivationType, -1);
332 context.ReadDefault(m_iRepeatedSpawnNumber, 0);
333 context.ReadDefault(m_bIsTerminated, false);
334
335 if (!context.Read(m_aActivationActions) && !context.CanSeekMembers())
336 return false;
337
338 if (!context.Read(m_aPlugins) && !context.CanSeekMembers())
339 return false;
340
341 return true;
342 }
343}
344
345class SCR_ScenarioFrameworkAreaSave : SCR_ScenarioFrameworkLayerSave
346{
351 ref array<ref SCR_ScenarioFrameworkActionSave> m_aTriggerActions = {};
352
353 //------------------------------------------------------------------------------------------------
355 {
356 super.Read(persistence, layer);
357
358 auto area = SCR_ScenarioFrameworkArea.Cast(layer);
359 m_bAreaSelected = area.GetIsAreaSelected();
360 m_sTriggerId = persistence.GetId(area.GetTrigger());
361
362 m_sItemDeliveryPointName = area.GetDeliveryPointName();
363 if (area.GetLayerTask())
364 m_sLayerTaskName = area.GetLayerTaskName();
365
366 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, area.m_aTriggerActions, m_aTriggerActions);
367 }
368
369 //------------------------------------------------------------------------------------------------
370 override bool IsDefault()
371 {
372 return
373 super.IsDefault() &&
375 m_sTriggerId.IsNull() &&
376 m_sItemDeliveryPointName.IsEmpty() &&
377 m_sLayerTaskName.IsEmpty() &&
378 m_aTriggerActions.IsEmpty();
379 }
380
381 //------------------------------------------------------------------------------------------------
383 {
384 super.Write(persistence, scenarioFrameworkSystem, layer);
385
386 auto area = SCR_ScenarioFrameworkArea.Cast(layer);
387
388 if (m_bAreaSelected)
389 {
390 scenarioFrameworkSystem.m_aAreasTasksToSpawn.Insert(m_sName);
391 scenarioFrameworkSystem.m_aLayersTaskToSpawn.Insert(m_sLayerTaskName);
392 }
393
394 if (!m_sTriggerId.IsNull())
395 {
396 Tuple1<SCR_ScenarioFrameworkArea> triggerContext(area);
397 PersistenceWhenAvailableTask triggerTask(OnTriggerAvailable, triggerContext);
398 persistence.WhenAvailable(m_sTriggerId, triggerTask);
399 }
400
402 area.StoreDeliveryPoint(m_sItemDeliveryPointName);
403
404 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aTriggerActions, area.m_aTriggerActions);
405 }
406
407 //------------------------------------------------------------------------------------------------
408 protected static void OnTriggerAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
409 {
410 auto trigger = SCR_BaseTriggerEntity.Cast(instance);
411 if (!trigger)
412 return;
413
414 auto ctx = Tuple1<SCR_ScenarioFrameworkArea>.Cast(context);
415 if (ctx.param1)
416 ctx.param1.m_Trigger = trigger;
417 }
418
419 //------------------------------------------------------------------------------------------------
420 override bool SerializationSave(SaveContext context)
421 {
422 if (!super.SerializationSave(context))
423 return false;
424
425 context.WriteDefault(m_bAreaSelected, false);
426 context.WriteDefault(m_sTriggerId, UUID.NULL_UUID);
427 context.WriteDefault(m_sItemDeliveryPointName, string.Empty);
428 context.WriteDefault(m_sLayerTaskName, string.Empty);
429
430 if (!context.CanSeekMembers() || !m_aTriggerActions.IsEmpty())
431 context.Write(m_aTriggerActions);
432
433 return true;
434 }
435
436 //------------------------------------------------------------------------------------------------
437 override bool SerializationLoad(LoadContext context)
438 {
439 if (!super.SerializationLoad(context))
440 return false;
441
442 context.ReadDefault(m_bAreaSelected, false);
443 context.ReadDefault(m_sTriggerId, UUID.NULL_UUID);
444 context.ReadDefault(m_sItemDeliveryPointName, string.Empty);
445 context.ReadDefault(m_sLayerTaskName, string.Empty);
446
447 if (!context.Read(m_aTriggerActions) && !context.CanSeekMembers())
448 return false;
449
450 return true;
451 }
452}
453
455{
456 ref SCR_ScenarioFrameworkLayerTaskSave Save;
457 SCR_ScenarioFrameworkLayerTask Task;
458}
459
460class SCR_ScenarioFrameworkLayerTaskSave : SCR_ScenarioFrameworkLayerSave
461{
462 private bool m_bTaskActive;
463 ref array<ref SCR_ScenarioFrameworkActionSave> m_aTriggerActionsOnFinish = {};
464 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnCreated = {};
465 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnFailed = {};
466 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnCancelled = {};
467 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnProgress = {};
468 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnAssigned = {};
469
470 //------------------------------------------------------------------------------------------------
471 override void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLayerBase layer)
472 {
473 super.Read(persistence, layer);
474
475 auto layerTask = SCR_ScenarioFrameworkLayerTask.Cast(layer);
476 m_bTaskActive = layerTask.m_Task != null;
477
478 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aTriggerActionsOnFinish, m_aTriggerActionsOnFinish);
479 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aActionsOnCreated, m_aActionsOnCreated);
480 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aActionsOnFailed, m_aActionsOnFailed);
481 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aActionsOnCancelled, m_aActionsOnCancelled);
482 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aActionsOnProgress, m_aActionsOnProgress);
483 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, layerTask.m_aActionsOnAssigned, m_aActionsOnAssigned);
484 }
485
486 //------------------------------------------------------------------------------------------------
487 override bool IsDefault()
488 {
489 return
490 super.IsDefault() &&
491 !m_bTaskActive &&
492 m_aTriggerActionsOnFinish.IsEmpty() &&
493 m_aActionsOnCreated.IsEmpty() &&
494 m_aActionsOnFailed.IsEmpty() &&
495 m_aActionsOnCancelled.IsEmpty() &&
496 m_aActionsOnProgress.IsEmpty() &&
497 m_aActionsOnAssigned.IsEmpty();
498 }
499
500 //------------------------------------------------------------------------------------------------
501 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
502 {
503 super.Write(persistence, scenarioFrameworkSystem, layer);
504
505 const UUID taskSystemId = persistence.GetId(persistence.GetPersistentState(SCR_TaskSystemData));
506 if (taskSystemId.IsNull())
507 return;
508
509 SCR_ScenarioFrameworkLayerTaskSaveLoadContext context();
510 context.Save = this;
511 context.Task = SCR_ScenarioFrameworkLayerTask.Cast(layer);
512 PersistenceWhenAvailableTask taskSystemDataHandler(OnTaskDataAvailable, context);
513 persistence.WhenAvailable(taskSystemId, taskSystemDataHandler);
514 }
515
516 //------------------------------------------------------------------------------------------------
517 protected static void OnTaskDataAvailable(Managed instance, PersistenceDeferredDeserializeTask deserializeTask, bool expired, Managed context)
518 {
519 auto taskSystem = SCR_TaskSystem.GetInstance();
520 if (!taskSystem || !instance)
521 return;
522
523 auto ctx = SCR_ScenarioFrameworkLayerTaskSaveLoadContext.Cast(context);
524 if (!ctx.Save || !ctx.Task)
525 return;
526
527 auto task = SCR_ScenarioFrameworkTask.Cast(taskSystem.GetTaskFromTaskID(ctx.Task.GetName()));
528 if (!task)
529 return;
530
531 ctx.Task.m_Task = task;
532 task.SetLayerTask(ctx.Task);
533
534 const PersistenceSystem persistence = PersistenceSystem.GetInstance();
535 const SCR_ScenarioFrameworkSystem scenarioFrameworkSystem = SCR_ScenarioFrameworkSystem.GetInstance();
536 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aTriggerActionsOnFinish, ctx.Task.m_aTriggerActionsOnFinish);
537 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aActionsOnCreated, ctx.Task.m_aActionsOnCreated);
538 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aActionsOnFailed, ctx.Task.m_aActionsOnFailed);
539 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aActionsOnCancelled, ctx.Task.m_aActionsOnCancelled);
540 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aActionsOnProgress, ctx.Task.m_aActionsOnProgress);
541 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, ctx.Save.m_aActionsOnAssigned, ctx.Task.m_aActionsOnAssigned);
542 }
543
544 //------------------------------------------------------------------------------------------------
545 override bool SerializationSave(SaveContext context)
546 {
547 if (!super.SerializationSave(context))
548 return false;
549
550 if (!context.CanSeekMembers() || !m_aTriggerActionsOnFinish.IsEmpty())
551 context.Write(m_aTriggerActionsOnFinish);
552
553 if (!context.CanSeekMembers() || !m_aActionsOnCreated.IsEmpty())
554 context.Write(m_aActionsOnCreated);
555
556 if (!context.CanSeekMembers() || !m_aActionsOnFailed.IsEmpty())
557 context.Write(m_aActionsOnFailed);
558
559 if (!context.CanSeekMembers() || !m_aActionsOnCancelled.IsEmpty())
560 context.Write(m_aActionsOnCancelled);
561
562 if (!context.CanSeekMembers() || !m_aActionsOnProgress.IsEmpty())
563 context.Write(m_aActionsOnProgress);
564
565 if (!context.CanSeekMembers() || !m_aActionsOnAssigned.IsEmpty())
566 context.Write(m_aActionsOnAssigned);
567
568 return true;
569 }
570
571 //------------------------------------------------------------------------------------------------
572 override bool SerializationLoad(LoadContext context)
573 {
574 if (!super.SerializationLoad(context))
575 return false;
576
577 if (!context.Read(m_aTriggerActionsOnFinish) && !context.CanSeekMembers())
578 return false;
579
580 if (!context.Read(m_aActionsOnCreated) && !context.CanSeekMembers())
581 return false;
582
583 if (!context.Read(m_aActionsOnFailed) && !context.CanSeekMembers())
584 return false;
585
586 if (!context.Read(m_aActionsOnCancelled) && !context.CanSeekMembers())
587 return false;
588
589 if (!context.Read(m_aActionsOnProgress) && !context.CanSeekMembers())
590 return false;
591
592 if (!context.Read(m_aActionsOnAssigned) && !context.CanSeekMembers())
593 return false;
594
595 return true;
596 }
597}
598
599class SCR_ScenarioFrameworkLayerTaskDefendSave : SCR_ScenarioFrameworkLayerTaskSave
600{
601 float m_fSecondsRemaining = -1.0;
602
603 //------------------------------------------------------------------------------------------------
605 {
606 super.Read(persistence, layer);
607
608 auto layerTaskDefend = SCR_ScenarioFrameworkLayerTaskDefend.Cast(layer);
609 m_fSecondsRemaining = layerTaskDefend.GetSecondsRemaining();
610 const float defendTime = layerTaskDefend.GetDefendTime();
611 if (float.AlmostEqual(m_fSecondsRemaining, defendTime))
612 m_fSecondsRemaining = -1.0; // Default tiime
613 }
614
615 //------------------------------------------------------------------------------------------------
616 override bool IsDefault()
617 {
618 return super.IsDefault() && float.AlmostEqual(m_fSecondsRemaining, -1.0);
619 }
620
621 //------------------------------------------------------------------------------------------------
622 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
623 {
624 super.Write(persistence, scenarioFrameworkSystem, layer);
625
626 auto layerTaskDefend = SCR_ScenarioFrameworkLayerTaskDefend.Cast(layer);
627 layerTaskDefend.SetSecondsRemaining(m_fSecondsRemaining);
628 }
629
630 //------------------------------------------------------------------------------------------------
631 override bool SerializationSave(SaveContext context)
632 {
633 if (!super.SerializationSave(context))
634 return false;
635
636 context.WriteDefault(m_fSecondsRemaining, -1.0);
637 return true;
638 }
639
640 //------------------------------------------------------------------------------------------------
641 override bool SerializationLoad(LoadContext context)
642 {
643 if (!super.SerializationLoad(context))
644 return false;
645
646 context.ReadDefault(m_fSecondsRemaining, -1.0);
647 return true;
648 }
649}
650
651class SCR_ScenarioFrameworkSlotSave : SCR_ScenarioFrameworkLayerSave
652{
655 ref array<UUID> m_aMiscEntities = {};
656
657 //------------------------------------------------------------------------------------------------
658 override void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLayerBase layer)
659 {
660 super.Read(persistence, layer);
661
662 auto slot = SCR_ScenarioFrameworkSlotBase.Cast(layer);
663 m_sRandomlySpawnedObject = slot.GetRandomlySpawnedObject();
664 auto spawnedEntity = slot.GetSpawnedEntity();
665 m_sSlotEntity = persistence.GetId(spawnedEntity);
666 foreach (auto entity : slot.m_aSpawnedEntities)
667 {
668 if (entity == spawnedEntity)
669 continue;
670
671 const UUID id = persistence.GetId(entity);
672 if (!id.IsNull())
673 m_aMiscEntities.Insert(id);
674 }
675 }
676
677 //------------------------------------------------------------------------------------------------
678 override bool IsDefault()
679 {
680 return
681 super.IsDefault() &&
682 m_sRandomlySpawnedObject.IsEmpty() &&
683 m_sSlotEntity.IsNull() &&
684 m_aMiscEntities.IsEmpty();
685 }
686
687 //------------------------------------------------------------------------------------------------
688 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
689 {
690 super.Write(persistence, scenarioFrameworkSystem, layer);
691
692 auto slot = SCR_ScenarioFrameworkSlotBase.Cast(layer);
693
695 slot.SetRandomlySpawnedObject(m_sRandomlySpawnedObject);
696
697 if (!m_sSlotEntity.IsNull())
698 {
699 Tuple2<SCR_ScenarioFrameworkSlotBase, bool> entityContext(slot, true);
700 PersistenceWhenAvailableTask slotEntityTask(OnEntityAvailable, entityContext);
701 persistence.WhenAvailable(m_sSlotEntity, slotEntityTask);
702 }
703
704 foreach (auto miscEntity : m_aMiscEntities)
705 {
706 Tuple2<SCR_ScenarioFrameworkSlotBase, bool> entityContext(slot, false);
707 PersistenceWhenAvailableTask slotEntityTask(OnEntityAvailable, entityContext);
708 persistence.WhenAvailable(miscEntity, slotEntityTask);
709 }
710 }
711
712 //------------------------------------------------------------------------------------------------
713 protected static void OnEntityAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
714 {
715 auto entity = IEntity.Cast(instance);
716 if (!entity)
717 return;
718
719 auto entityContext = Tuple2<SCR_ScenarioFrameworkSlotBase, bool>.Cast(context);
720 if (!entityContext.param1)
721 return;
722
723 if (entityContext.param2)
724 {
725 entityContext.param1.SetEntity(entity);
726
727 auto slotWP = SCR_ScenarioFrameworkSlotWaypoint.Cast(entityContext.param1);
728 if (slotWP && slotWP.m_Waypoint)
729 {
730 slotWP.m_Waypoint.m_SlotWaypoint = slotWP;
731 slotWP.m_Waypoint.SetupWaypoint(entity);
732 }
733 }
734 else
735 {
736 entityContext.param1.m_aSpawnedEntities.Insert(entity);
737 }
738 }
739
740 //------------------------------------------------------------------------------------------------
741 override bool SerializationSave(SaveContext context)
742 {
743 if (!super.SerializationSave(context))
744 return false;
745
746 context.WriteDefault(m_sRandomlySpawnedObject, ResourceName.Empty);
747 context.WriteDefault(m_sSlotEntity, UUID.NULL_UUID);
748
749 if (!context.CanSeekMembers() || !m_aMiscEntities.IsEmpty())
750 context.Write(m_aMiscEntities);
751
752 return true;
753 }
754
755 //------------------------------------------------------------------------------------------------
756 override bool SerializationLoad(LoadContext context)
757 {
758 if (!super.SerializationLoad(context))
759 return false;
760
761 context.ReadDefault(m_sRandomlySpawnedObject, ResourceName.Empty);
762 context.ReadDefault(m_sSlotEntity, UUID.NULL_UUID);
763
764 if (!context.Read(m_aMiscEntities) && !context.CanSeekMembers())
765 return false;
766
767 return true;
768 }
769}
770
771class SCR_ScenarioFrameworkSlotAISave : SCR_ScenarioFrameworkSlotSave
772{
773 UUID m_sGroupId;
774
775 //------------------------------------------------------------------------------------------------
777 {
778 super.Read(persistence, layer);
779
780 auto slot = SCR_ScenarioFrameworkSlotAI.Cast(layer);
781 m_sGroupId = persistence.GetId(slot.m_AIGroup);
782 }
783
784 //------------------------------------------------------------------------------------------------
785 override bool IsDefault()
786 {
787 return super.IsDefault() && m_sGroupId.IsNull();
788 }
789
790 //------------------------------------------------------------------------------------------------
791 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
792 {
793 super.Write(persistence, scenarioFrameworkSystem, layer);
794
795 if (m_sGroupId.IsNull())
796 return;
797
798 auto slot = SCR_ScenarioFrameworkSlotAI.Cast(layer);
799 Tuple1<SCR_ScenarioFrameworkSlotAI> groupContext(slot);
800 PersistenceWhenAvailableTask slotGroupTask(OnGroupAvailable, groupContext);
801 persistence.WhenAvailable(m_sGroupId, slotGroupTask);
802 }
803
804 //------------------------------------------------------------------------------------------------
805 protected static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
806 {
807 auto group = SCR_AIGroup.Cast(instance);
808 if (!group)
809 return;
810
811 auto groupContext = Tuple1<SCR_ScenarioFrameworkSlotAI>.Cast(context);
812 if (!groupContext.param1)
813 return;
814
815 groupContext.param1.m_AIGroup = group;
816 if (group.GetCurrentWaypoint())
817 groupContext.param1.m_bWaypointsInitialized = true;
818 }
819
820 //------------------------------------------------------------------------------------------------
821 override bool SerializationSave(SaveContext context)
822 {
823 if (!super.SerializationSave(context))
824 return false;
825
826 context.WriteDefault(m_sGroupId, UUID.NULL_UUID);
827 return true;
828 }
829
830 //------------------------------------------------------------------------------------------------
831 override bool SerializationLoad(LoadContext context)
832 {
833 if (!super.SerializationLoad(context))
834 return false;
835
836 context.ReadDefault(m_sGroupId, UUID.NULL_UUID);
837 return true;
838 }
839}
840
841class SCR_ScenarioFrameworkSlotTaskSave : SCR_ScenarioFrameworkSlotSave
842{
843 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnFinished = {};
844 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnCreated = {};
845 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnFailed = {};
846 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnCancelled = {};
847 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnProgress = {};
848 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnAssigned = {};
849
850 //------------------------------------------------------------------------------------------------
851 override void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLayerBase layer)
852 {
853 super.Read(persistence, layer);
854
855 auto slot = SCR_ScenarioFrameworkSlotTask.Cast(layer);
856 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnFinished, m_aActionsOnFinished);
857 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnCreated, m_aActionsOnCreated);
858 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnFailed, m_aActionsOnFailed);
859 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnCancelled, m_aActionsOnCancelled);
860 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnProgress, m_aActionsOnProgress);
861 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aActionsOnAssigned, m_aActionsOnAssigned);
862 }
863
864 //------------------------------------------------------------------------------------------------
865 override bool IsDefault()
866 {
867 return super.IsDefault() &&
868 m_aActionsOnFinished.IsEmpty() &&
869 m_aActionsOnCreated.IsEmpty() &&
870 m_aActionsOnFailed.IsEmpty() &&
871 m_aActionsOnCancelled.IsEmpty() &&
872 m_aActionsOnProgress.IsEmpty() &&
873 m_aActionsOnAssigned.IsEmpty();
874 }
875
876 //------------------------------------------------------------------------------------------------
877 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
878 {
879 super.Write(persistence, scenarioFrameworkSystem, layer);
880
881 auto slot = SCR_ScenarioFrameworkSlotTask.Cast(layer);
882 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnFinished, slot.m_aActionsOnFinished);
883 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnCreated, slot.m_aActionsOnCreated);
884 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnFailed, slot.m_aActionsOnFailed);
885 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnCancelled, slot.m_aActionsOnCancelled);
886 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnProgress, slot.m_aActionsOnProgress);
887 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnAssigned, slot.m_aActionsOnAssigned);
888 }
889
890 //------------------------------------------------------------------------------------------------
891 override bool SerializationSave(SaveContext context)
892 {
893 if (!super.SerializationSave(context))
894 return false;
895
896 if (!context.CanSeekMembers() || !m_aActionsOnFinished.IsEmpty())
897 context.Write(m_aActionsOnFinished);
898
899 if (!context.CanSeekMembers() || !m_aActionsOnCreated.IsEmpty())
900 context.Write(m_aActionsOnCreated);
901
902 if (!context.CanSeekMembers() || !m_aActionsOnFailed.IsEmpty())
903 context.Write(m_aActionsOnFailed);
904
905 if (!context.CanSeekMembers() || !m_aActionsOnCancelled.IsEmpty())
906 context.Write(m_aActionsOnCancelled);
907
908 if (!context.CanSeekMembers() || !m_aActionsOnProgress.IsEmpty())
909 context.Write(m_aActionsOnProgress);
910
911 if (!context.CanSeekMembers() || !m_aActionsOnAssigned.IsEmpty())
912 context.Write(m_aActionsOnAssigned);
913
914 return true;
915 }
916
917 //------------------------------------------------------------------------------------------------
918 override bool SerializationLoad(LoadContext context)
919 {
920 if (!super.SerializationLoad(context))
921 return false;
922
923 if (!context.Read(m_aActionsOnFinished) && !context.CanSeekMembers())
924 return false;
925
926 if (!context.Read(m_aActionsOnCreated) && !context.CanSeekMembers())
927 return false;
928
929 if (!context.Read(m_aActionsOnFailed) && !context.CanSeekMembers())
930 return false;
931
932 if (!context.Read(m_aActionsOnCancelled) && !context.CanSeekMembers())
933 return false;
934
935 if (!context.Read(m_aActionsOnProgress) && !context.CanSeekMembers())
936 return false;
937
938 if (!context.Read(m_aActionsOnAssigned) && !context.CanSeekMembers())
939 return false;
940
941 return true;
942 }
943}
944
945class SCR_ScenarioFrameworkSlotTaskAISave : SCR_ScenarioFrameworkSlotTaskSave
946{
947 UUID m_sGroupId;
948
949 //------------------------------------------------------------------------------------------------
951 {
952 super.Read(persistence, layer);
953
954 auto slot = SCR_ScenarioFrameworkSlotTaskAI.Cast(layer);
955 m_sGroupId = persistence.GetId(slot.m_AIGroup);
956 }
957
958 //------------------------------------------------------------------------------------------------
959 override bool IsDefault()
960 {
961 return super.IsDefault() && m_sGroupId.IsNull();
962 }
963
964 //------------------------------------------------------------------------------------------------
965 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
966 {
967 super.Write(persistence, scenarioFrameworkSystem, layer);
968
969 if (m_sGroupId.IsNull())
970 return;
971
972 auto slot = SCR_ScenarioFrameworkSlotTaskAI.Cast(layer);
974 PersistenceWhenAvailableTask slotGroupTask(OnGroupAvailable, groupContext);
975 persistence.WhenAvailable(m_sGroupId, slotGroupTask);
976 }
977
978 //------------------------------------------------------------------------------------------------
979 protected static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
980 {
981 auto group = SCR_AIGroup.Cast(instance);
982 if (!group)
983 return;
984
985 auto groupContext = Tuple1<SCR_ScenarioFrameworkSlotTaskAI>.Cast(context);
986 if (!groupContext.param1)
987 return;
988
989 groupContext.param1.m_AIGroup = group;
990 if (group.GetCurrentWaypoint())
991 groupContext.param1.m_bWaypointsInitialized = true;
992 }
993
994 //------------------------------------------------------------------------------------------------
995 override bool SerializationSave(SaveContext context)
996 {
997 if (!super.SerializationSave(context))
998 return false;
999
1000 context.WriteDefault(m_sGroupId, UUID.NULL_UUID);
1001 return true;
1002 }
1003
1004 //------------------------------------------------------------------------------------------------
1005 override bool SerializationLoad(LoadContext context)
1006 {
1007 if (!super.SerializationLoad(context))
1008 return false;
1009
1010 context.ReadDefault(m_sGroupId, UUID.NULL_UUID);
1011 return true;
1012 }
1013}
1014
1015class SCR_ScenarioFrameworkSlotTriggerSave : SCR_ScenarioFrameworkSlotSave
1016{
1017 ref array<ref SCR_ScenarioFrameworkActionSave> m_aTriggerActions = {};
1018
1019 //------------------------------------------------------------------------------------------------
1020 override void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLayerBase layer)
1021 {
1022 super.Read(persistence, layer);
1023
1024 auto slot = SCR_ScenarioFrameworkSlotTrigger.Cast(layer);
1025 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, slot.m_aTriggerActions, m_aTriggerActions);
1026 }
1027
1028 //------------------------------------------------------------------------------------------------
1029 override bool IsDefault()
1030 {
1031 return super.IsDefault() && m_aTriggerActions.IsEmpty();
1032 }
1033
1034 //------------------------------------------------------------------------------------------------
1035 override void Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, SCR_ScenarioFrameworkLayerBase layer)
1036 {
1037 super.Write(persistence, scenarioFrameworkSystem, layer);
1038
1039 auto slot = SCR_ScenarioFrameworkSlotTrigger.Cast(layer);
1040 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aTriggerActions, slot.m_aTriggerActions);
1041 }
1042
1043 //------------------------------------------------------------------------------------------------
1044 override bool SerializationSave(SaveContext context)
1045 {
1046 if (!super.SerializationSave(context))
1047 return false;
1048
1049 if (!context.CanSeekMembers() || !m_aTriggerActions.IsEmpty())
1050 context.Write(m_aTriggerActions);
1051
1052 return true;
1053 }
1054
1055 //------------------------------------------------------------------------------------------------
1056 override bool SerializationLoad(LoadContext context)
1057 {
1058 if (!super.SerializationLoad(context))
1059 return false;
1060
1061 if (!context.Read(m_aTriggerActions) && !context.CanSeekMembers())
1062 return false;
1063
1064 return true;
1065 }
1066}
1067
1069{
1070 string m_sName;
1071 bool m_bIsTerminated;
1072 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActions = {};
1073
1074 //------------------------------------------------------------------------------------------------
1075 void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLogic logic)
1076 {
1077 m_sName = logic.GetName();
1078 m_bIsTerminated = logic.GetIsTerminated();
1079 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, logic.m_aActions, m_aActions);
1080 }
1081
1082 //------------------------------------------------------------------------------------------------
1083 bool IsDefault()
1084 {
1085 return !m_bIsTerminated && m_aActions.IsEmpty();
1086 }
1087
1088 //------------------------------------------------------------------------------------------------
1089 SCR_ScenarioFrameworkLogic Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem)
1090 {
1091 if (m_sName.IsEmpty())
1092 return null;
1093
1094 auto logic = SCR_ScenarioFrameworkLogic.Cast(GetGame().GetWorld().FindEntityByName(m_sName));
1095 if (logic && m_bIsTerminated)
1096 logic.SetIsTerminated(true);
1097
1098 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActions, logic.m_aActions);
1099
1100 return logic;
1101 }
1102
1103 //------------------------------------------------------------------------------------------------
1104 bool SerializationSave(SaveContext context)
1105 {
1106 context.Write(m_sName);
1107 context.WriteDefault(m_bIsTerminated, false);
1108
1109 if (!context.CanSeekMembers() || !m_aActions.IsEmpty())
1110 context.Write(m_aActions);
1111
1112 return true;
1113 }
1114
1115 //------------------------------------------------------------------------------------------------
1116 bool SerializationLoad(LoadContext context)
1117 {
1118 context.Read(m_sName);
1119 context.ReadDefault(m_bIsTerminated, false);
1120
1121 if (!context.Read(m_aActions) && !context.CanSeekMembers())
1122 return false;
1123
1124 return true;
1125 }
1126}
1127
1128class SCR_ScenarioFrameworkLogicCounterSave : SCR_ScenarioFrameworkLogicSave
1129{
1131
1132 //------------------------------------------------------------------------------------------------
1133 override void Read(PersistenceSystem persistence, SCR_ScenarioFrameworkLogic logic)
1134 {
1135 super.Read(persistence, logic);
1136
1137 m_iCounterValue = SCR_ScenarioFrameworkLogicCounter.Cast(logic).GetCounterValue();
1138 }
1139
1140 //------------------------------------------------------------------------------------------------
1141 override bool IsDefault()
1142 {
1143 return super.IsDefault() && m_iCounterValue == 0;
1144 }
1145
1146 //------------------------------------------------------------------------------------------------
1147 override SCR_ScenarioFrameworkLogic Write(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem)
1148 {
1149 auto logic = super.Write(persistence, scenarioFrameworkSystem);
1150 auto counter = SCR_ScenarioFrameworkLogicCounter.Cast(logic);
1151 if (counter)
1152 counter.SetCounterValue(m_iCounterValue);
1153
1154 return logic;
1155 }
1156
1157 //------------------------------------------------------------------------------------------------
1158 override bool SerializationSave(SaveContext context)
1159 {
1160 if (!super.SerializationSave(context))
1161 return false;
1162
1163 context.WriteDefault(m_iCounterValue, 0);
1164 return true;
1165 }
1166
1167 //------------------------------------------------------------------------------------------------
1168 override bool SerializationLoad(LoadContext context)
1169 {
1170 if (!super.SerializationLoad(context))
1171 return false;
1172
1173 context.ReadDefault(m_iCounterValue, 0);
1174 return true;
1175 }
1176}
1177
1179{
1180 string m_sStoreName;
1181 int m_iNumberOfActivations;
1182 ref array<ref SCR_ScenarioFrameworkActionSave> m_aSubActions = {};
1183
1184 //------------------------------------------------------------------------------------------------
1186 {
1187 if (action.IsInherited(SCR_ScenarioFrameworkActionWaitAndExecute))
1188 return new SCR_ScenarioFrameworkActionWaitAndExecuteSave();
1189
1190 if (action.IsInherited(SCR_ScenarioFrameworkActionLimiter))
1192
1193 if (action.IsInherited(SCR_ScenarioFrameworkActionOnUserActionEvent))
1194 return new SCR_ScenarioFrameworkActionOnUserActionEventSave();
1195
1197 }
1198
1199 //------------------------------------------------------------------------------------------------
1200 static void ReadActions(
1201 PersistenceSystem persistence,
1202 notnull array<ref SCR_ScenarioFrameworkActionBase> sourceActions,
1203 notnull array<ref SCR_ScenarioFrameworkActionSave> savesholder)
1204 {
1205 foreach (SCR_ScenarioFrameworkActionBase action : sourceActions)
1206 {
1207 auto actionSave = SCR_ScenarioFrameworkActionSave.GetSaveType(action);
1208 actionSave.Read(persistence, action);
1209 if (!actionSave.IsDefault())
1210 savesholder.Insert(actionSave);
1211 }
1212 }
1213
1214 //------------------------------------------------------------------------------------------------
1215 static void WriteActions(
1216 PersistenceSystem persistence,
1217 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1218 notnull array<ref SCR_ScenarioFrameworkActionSave> savesholder,
1219 notnull array<ref SCR_ScenarioFrameworkActionBase> sourceActions)
1220 {
1221 foreach (auto action : savesholder)
1222 {
1223 action.Write(persistence, scenarioFrameworkSystem, sourceActions);
1224 }
1225 }
1226
1227 //------------------------------------------------------------------------------------------------
1228 void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkActionBase action)
1229 {
1230 m_sStoreName = action.GetStoreName();
1231
1232 auto subActions = action.GetSubActions();
1233 if (subActions)
1234 ReadActions(persistence, subActions, m_aSubActions);
1235
1236 if (action.m_iMaxNumberOfActivations == -1)
1237 return; // Consider default
1238
1239 m_iNumberOfActivations = action.m_iNumberOfActivations;
1240 }
1241
1242 //------------------------------------------------------------------------------------------------
1243 bool IsDefault()
1244 {
1245 return m_iNumberOfActivations == 0 && m_aSubActions.IsEmpty();
1246 }
1247
1248 //------------------------------------------------------------------------------------------------
1250 PersistenceSystem persistence,
1251 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1252 array<ref SCR_ScenarioFrameworkActionBase> actions)
1253 {
1254 foreach (SCR_ScenarioFrameworkActionBase action : actions)
1255 {
1256 if (action.GetStoreName() == m_sStoreName)
1257 {
1258 action.m_iNumberOfActivations = m_iNumberOfActivations;
1259
1260 auto subActions = action.GetSubActions();
1261 if (subActions)
1262 WriteActions(persistence, scenarioFrameworkSystem, m_aSubActions, subActions);
1263
1264 return action;
1265 }
1266 }
1267
1268 return null;
1269 }
1270
1271 //------------------------------------------------------------------------------------------------
1272 bool SerializationSave(SaveContext context)
1273 {
1274 context.Write(m_sStoreName);
1275 context.WriteDefault(m_iNumberOfActivations, 0);
1276
1277 if (!context.CanSeekMembers() || !m_aSubActions.IsEmpty())
1278 context.Write(m_aSubActions);
1279
1280 return true;
1281 }
1282
1283 //------------------------------------------------------------------------------------------------
1284 bool SerializationLoad(LoadContext context)
1285 {
1286 context.Read(m_sStoreName);
1287 context.ReadDefault(m_iNumberOfActivations, 0);
1288
1289 if (!context.Read(m_aSubActions) && !context.CanSeekMembers())
1290 return false;
1291
1292 return true;
1293 }
1294}
1295
1296class SCR_ScenarioFrameworkActionWaitAndExecuteSave : SCR_ScenarioFrameworkActionSave
1297{
1300
1301 //------------------------------------------------------------------------------------------------
1302 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkActionBase action)
1303 {
1304 super.Read(persistence, action);
1305
1307 m_iTimeRemaining = SCR_ScenarioFrameworkSystem.GetCallQueuePausable().GetRemainingTime(waitAndExecuteAction.ExecuteActions);
1308 if (!waitAndExecuteAction.m_Entity)
1309 return;
1310
1311 const UUID persistentId = persistence.GetId(waitAndExecuteAction.m_Entity);
1312 if (!persistentId.IsNull())
1313 {
1314 m_EntityId = persistentId;
1315 return;
1316 }
1317
1318 m_EntityId = waitAndExecuteAction.m_Entity.GetName();
1319 }
1320
1321 //------------------------------------------------------------------------------------------------
1322 override bool IsDefault()
1323 {
1324 return super.IsDefault() && m_iTimeRemaining == -1;
1325 }
1326
1327 //------------------------------------------------------------------------------------------------
1329 PersistenceSystem persistence,
1330 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1331 array<ref SCR_ScenarioFrameworkActionBase> actions)
1332 {
1333 SCR_ScenarioFrameworkActionWaitAndExecute waitAndExecuteAction = SCR_ScenarioFrameworkActionWaitAndExecute.Cast(super.Write(persistence, scenarioFrameworkSystem, actions));
1334 if (waitAndExecuteAction)
1335 {
1336 if (UUID.IsUUID(m_EntityId))
1337 {
1338 Tuple2<SCR_ScenarioFrameworkActionWaitAndExecute, int> actionContext(waitAndExecuteAction, m_iTimeRemaining);
1339 PersistenceWhenAvailableTask entityTask(OnEntityAvailable, actionContext);
1340 persistence.WhenAvailable(m_EntityId, entityTask);
1341 }
1342 else
1343 {
1344 IEntity object;
1345 if (m_EntityId) // There might be a name, for loaded entites or dynamically spawned who are not using persistence itself, but we still want to invoke for.
1346 object = persistence.GetWorld().FindEntityByName(m_EntityId);
1347
1348 SCR_ScenarioFrameworkSystem.GetCallQueuePausable().CallLater(waitAndExecuteAction.ExecuteActions, m_iTimeRemaining, false, object);
1349 }
1350 }
1351 return waitAndExecuteAction;
1352 }
1353
1354 //------------------------------------------------------------------------------------------------
1355 protected static void OnEntityAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
1356 {
1357 auto entity = IEntity.Cast(instance);
1358
1359 auto entityContext = Tuple2<SCR_ScenarioFrameworkActionWaitAndExecute, int>.Cast(context);
1360 if (!entityContext.param1)
1361 return;
1362
1363 SCR_ScenarioFrameworkSystem.GetCallQueuePausable().CallLater(entityContext.param1.ExecuteActions, entityContext.param2, false, entity);
1364 }
1365
1366 //------------------------------------------------------------------------------------------------
1367 override bool SerializationSave(SaveContext context)
1368 {
1369 if (!super.SerializationSave(context))
1370 return false;
1371
1372 context.WriteDefault(m_iTimeRemaining, -1);
1373 context.WriteDefault(m_EntityId, string.Empty);
1374 return true;
1375 }
1376
1377 //------------------------------------------------------------------------------------------------
1378 override bool SerializationLoad(LoadContext context)
1379 {
1380 if (!super.SerializationLoad(context))
1381 return false;
1382
1383 context.ReadDefault(m_iTimeRemaining, -1);
1384 context.ReadDefault(m_EntityId, string.Empty);
1385 return true;
1386 }
1387}
1388
1390{
1391 float m_fLimitRemaining;
1392
1393 //------------------------------------------------------------------------------------------------
1394 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkActionBase action)
1395 {
1396 super.Read(persistence, action);
1397
1399 if (!limiterAction.m_LimitedUntil)
1400 return;
1401
1402 const WorldTimestamp currentTimestamp = GetGame().GetWorld().GetTimestamp(); // 110
1403 m_fLimitRemaining = limiterAction.m_LimitedUntil.DiffMilliseconds(currentTimestamp) // 150 - 110 = 40
1404 }
1405
1406 //------------------------------------------------------------------------------------------------
1407 override bool IsDefault()
1408 {
1409 return super.IsDefault() && m_fLimitRemaining == 0.0;
1410 }
1411
1412 //------------------------------------------------------------------------------------------------
1414 PersistenceSystem persistence,
1415 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1416 array<ref SCR_ScenarioFrameworkActionBase> actions)
1417 {
1418 SCR_ScenarioFrameworkActionLimiter limiterAction = SCR_ScenarioFrameworkActionLimiter.Cast(super.Write(persistence, scenarioFrameworkSystem, actions));
1419 if (limiterAction)
1420 {
1421 limiterAction.m_LimitedUntil = GetGame().GetWorld().GetTimestamp().PlusMilliseconds(m_fLimitRemaining);
1422 }
1423 return limiterAction;
1424 }
1425
1426 //------------------------------------------------------------------------------------------------
1427 override bool SerializationSave(SaveContext context)
1428 {
1429 if (!super.SerializationSave(context))
1430 return false;
1431
1432 context.WriteDefault(m_fLimitRemaining, 0.0);
1433 return true;
1434 }
1435
1436 //------------------------------------------------------------------------------------------------
1437 override bool SerializationLoad(LoadContext context)
1438 {
1439 if (!super.SerializationLoad(context))
1440 return false;
1441
1442 context.ReadDefault(m_fLimitRemaining, 0.0);
1443 return true;
1444 }
1445}
1446
1447class SCR_ScenarioFrameworkActionOnUserActionEventSave : SCR_ScenarioFrameworkActionSave
1448{
1450 ref array<UUID> m_aUserEntitiyIds = {};
1451
1452 //------------------------------------------------------------------------------------------------
1453 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkActionBase action)
1454 {
1455 super.Read(persistence, action);
1456
1457 const SCR_ScenarioFrameworkActionOnUserActionEvent listenerAction = SCR_ScenarioFrameworkActionOnUserActionEvent.Cast(action);
1458 m_sActionHolderId = persistence.GetId(listenerAction.m_ActionHolder);
1459 if (!listenerAction.m_aUserEntities)
1460 return;
1461
1462 foreach (IEntity user : listenerAction.m_aUserEntities)
1463 {
1464 const UUID id = persistence.GetId(user);
1465 if (!id.IsNull())
1466 m_aUserEntitiyIds.Insert(id);
1467 }
1468 }
1469
1470 //------------------------------------------------------------------------------------------------
1471 override bool IsDefault()
1472 {
1473 return super.IsDefault() && m_sActionHolderId.IsNull() && m_aUserEntitiyIds.IsEmpty();
1474 }
1475
1476 //------------------------------------------------------------------------------------------------
1477 override SCR_ScenarioFrameworkActionBase Write(
1478 PersistenceSystem persistence,
1479 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1480 array<ref SCR_ScenarioFrameworkActionBase> actions)
1481 {
1482 auto listenerAction = SCR_ScenarioFrameworkActionOnUserActionEvent.Cast(super.Write(persistence, scenarioFrameworkSystem, actions));
1483 if (listenerAction)
1484 {
1485 if (!m_sActionHolderId.IsNull())
1486 {
1487 Tuple2<SCR_ScenarioFrameworkActionOnUserActionEvent, bool> actionContext(listenerAction, true);
1488 PersistenceWhenAvailableTask entityTask(OnEntityAvailable, actionContext);
1489 persistence.WhenAvailable(m_sActionHolderId, entityTask);
1490 }
1491
1492 if (!m_aUserEntitiyIds.IsEmpty())
1493 {
1494 Tuple2<SCR_ScenarioFrameworkActionOnUserActionEvent, bool> actionContext(listenerAction, false);
1495 PersistenceWhenAvailableTask entityTask(OnEntityAvailable, actionContext);
1496 foreach (UUID user : m_aUserEntitiyIds)
1497 {
1498 persistence.WhenAvailable(user, entityTask);
1499 }
1500 }
1501 }
1502 return listenerAction;
1503 }
1504
1505 //------------------------------------------------------------------------------------------------
1506 protected static void OnEntityAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
1507 {
1508 auto entity = IEntity.Cast(instance);
1509
1510 auto entityContext = Tuple2<SCR_ScenarioFrameworkActionOnUserActionEvent, bool>.Cast(context);
1511 if (!entityContext.param1)
1512 return;
1513
1514 if (!entityContext.param2)
1515 {
1516 entityContext.param1.m_aUserEntities.Insert(entity);
1517 return;
1518 }
1519
1520 BaseActionsManagerComponent actionsManager = BaseActionsManagerComponent.Cast(entity.FindComponent(BaseActionsManagerComponent));
1521 if (!actionsManager)
1522 return;
1523
1524 ScriptedUserAction scriptedUserAction = ScriptedUserAction.Cast(actionsManager.FindAction(entityContext.param1.m_iActionID));
1525 if (!scriptedUserAction)
1526 return;
1527
1528 actionsManager.AddUserActionEventListener(scriptedUserAction, entityContext.param1.OnInvoked);
1529 }
1530
1531 //------------------------------------------------------------------------------------------------
1532 override bool SerializationSave(SaveContext context)
1533 {
1534 if (!super.SerializationSave(context))
1535 return false;
1536
1537 context.WriteDefault(m_sActionHolderId, UUID.NULL_UUID);
1538
1539 if (!context.CanSeekMembers() || !m_aUserEntitiyIds.IsEmpty())
1540 context.Write(m_aUserEntitiyIds);
1541
1542 return true;
1543 }
1544
1545 //------------------------------------------------------------------------------------------------
1546 override bool SerializationLoad(LoadContext context)
1547 {
1548 if (!super.SerializationLoad(context))
1549 return false;
1550
1551 context.ReadDefault(m_sActionHolderId, UUID.NULL_UUID);
1552
1553 if (!context.Read(m_aUserEntitiyIds) && !context.CanSeekMembers())
1554 return false;
1555
1556 return true;
1557 }
1558}
1559
1561{
1562 string m_sStoreName;
1563
1564 //------------------------------------------------------------------------------------------------
1565 static SCR_ScenarioFrameworkPluginSave GetSaveType(const SCR_ScenarioFrameworkPlugin plugin)
1566 {
1567 if (plugin.IsInherited(SCR_ScenarioFrameworkPluginTrigger))
1568 return new SCR_ScenarioFrameworkPluginTriggerSave();
1569
1570 if (plugin.IsInherited(SCR_ScenarioFrameworkPluginSpawnPoint))
1572
1573 if (plugin.IsInherited(SCR_ScenarioFrameworkPluginOnInventoryChange))
1574 return new SCR_ScenarioFrameworkPluginOnInventoryChangeSave();
1575
1576 if (plugin.IsInherited(SCR_ScenarioFrameworkPluginOnDestroyEvent))
1578
1580 }
1581
1582 //------------------------------------------------------------------------------------------------
1584 {
1585 m_sStoreName = plugin.GetStoreName();
1586 }
1587
1588 //------------------------------------------------------------------------------------------------
1589 bool IsDefault()
1590 {
1591 return true;
1592 }
1593
1594 //------------------------------------------------------------------------------------------------
1596 PersistenceSystem persistence,
1597 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1599 array<ref SCR_ScenarioFrameworkPlugin> plugins)
1600 {
1601 foreach (SCR_ScenarioFrameworkPlugin plugin : plugins)
1602 {
1603 if (plugin.GetStoreName() == m_sStoreName)
1604 {
1605 return plugin;
1606 }
1607 }
1608
1609 return null;
1610 }
1611
1612 //------------------------------------------------------------------------------------------------
1613 bool SerializationSave(SaveContext context)
1614 {
1615 context.Write(m_sStoreName);
1616 return true;
1617 }
1618
1619 //------------------------------------------------------------------------------------------------
1620 bool SerializationLoad(LoadContext context)
1621 {
1622 context.Read(m_sStoreName);
1623 return true;
1624 }
1625}
1626
1627class SCR_ScenarioFrameworkPluginTriggerSave : SCR_ScenarioFrameworkPluginSave
1628{
1629 ref array<ref SCR_ScenarioFrameworkActionSave> m_aEntityEnteredActions = {};
1630 ref array<ref SCR_ScenarioFrameworkActionSave> m_aEntityLeftActions = {};
1631 ref array<ref SCR_ScenarioFrameworkActionSave> m_aFinishedActions = {};
1632
1633 //------------------------------------------------------------------------------------------------
1634 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkLayerBase layer, const SCR_ScenarioFrameworkPlugin plugin)
1635 {
1636 super.Read(persistence, layer, plugin);
1637
1639
1640 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, triggerPlugin.m_aEntityEnteredActions, m_aEntityEnteredActions);
1641 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, triggerPlugin.m_aEntityLeftActions, m_aEntityLeftActions);
1642 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, triggerPlugin.m_aFinishedActions, m_aFinishedActions);
1643 }
1644
1645 //------------------------------------------------------------------------------------------------
1646 override bool IsDefault()
1647 {
1648 return
1649 super.IsDefault() &&
1650 m_aEntityEnteredActions.IsEmpty() &&
1651 m_aEntityLeftActions.IsEmpty() &&
1652 m_aFinishedActions.IsEmpty();
1653 }
1654
1655 //------------------------------------------------------------------------------------------------
1657 PersistenceSystem persistence,
1658 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1660 array<ref SCR_ScenarioFrameworkPlugin> plugins)
1661 {
1662 SCR_ScenarioFrameworkPluginTrigger pluginTrigger = SCR_ScenarioFrameworkPluginTrigger.Cast(super.Write(persistence, scenarioFrameworkSystem, layer, plugins));
1663 if (pluginTrigger)
1664 {
1665 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aEntityEnteredActions, pluginTrigger.m_aEntityEnteredActions);
1666 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aEntityLeftActions, pluginTrigger.m_aEntityLeftActions);
1667 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aFinishedActions, pluginTrigger.m_aFinishedActions);
1668 }
1669 return pluginTrigger;
1670 }
1671
1672 //------------------------------------------------------------------------------------------------
1673 override bool SerializationSave(SaveContext context)
1674 {
1675 if (!super.SerializationSave(context))
1676 return false;
1677
1678 if (!context.CanSeekMembers() || !m_aEntityEnteredActions.IsEmpty())
1679 context.Write(m_aEntityEnteredActions);
1680
1681 if (!context.CanSeekMembers() || !m_aEntityLeftActions.IsEmpty())
1682 context.Write(m_aEntityLeftActions);
1683
1684 if (!context.CanSeekMembers() || !m_aFinishedActions.IsEmpty())
1685 context.Write(m_aFinishedActions);
1686
1687 return true;
1688 }
1689
1690 //------------------------------------------------------------------------------------------------
1691 override bool SerializationLoad(LoadContext context)
1692 {
1693 if (!super.SerializationLoad(context))
1694 return false;
1695
1696 if (!context.Read(m_aEntityEnteredActions) && !context.CanSeekMembers())
1697 return false;
1698
1699 if (!context.Read(m_aEntityLeftActions) && !context.CanSeekMembers())
1700 return false;
1701
1702 if (!context.Read(m_aFinishedActions) && !context.CanSeekMembers())
1703 return false;
1704
1705 return true;
1706 }
1707}
1708
1710{
1711 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnSpawnPointUsed = {};
1712
1713 //------------------------------------------------------------------------------------------------
1714 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkLayerBase layer, const SCR_ScenarioFrameworkPlugin plugin)
1715 {
1716 super.Read(persistence, layer, plugin);
1717
1719 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, spawnpointPlugin.m_aActionsOnSpawnPointUsed, m_aActionsOnSpawnPointUsed);
1720 }
1721
1722 //------------------------------------------------------------------------------------------------
1723 override bool IsDefault()
1724 {
1725 return super.IsDefault() && m_aActionsOnSpawnPointUsed.IsEmpty();
1726 }
1727
1728 //------------------------------------------------------------------------------------------------
1730 PersistenceSystem persistence,
1731 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1733 array<ref SCR_ScenarioFrameworkPlugin> plugins)
1734 {
1735 SCR_ScenarioFrameworkPluginSpawnPoint spawnpointPlugin = SCR_ScenarioFrameworkPluginSpawnPoint.Cast(super.Write(persistence, scenarioFrameworkSystem, layer, plugins));
1736 if (spawnpointPlugin)
1737 {
1738 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnSpawnPointUsed, spawnpointPlugin.m_aActionsOnSpawnPointUsed);
1739 }
1740 return spawnpointPlugin;
1741 }
1742
1743 //------------------------------------------------------------------------------------------------
1744 override bool SerializationSave(SaveContext context)
1745 {
1746 if (!super.SerializationSave(context))
1747 return false;
1748
1749 if (!context.CanSeekMembers() || !m_aActionsOnSpawnPointUsed.IsEmpty())
1750 context.Write(m_aActionsOnSpawnPointUsed);
1751
1752 return true;
1753 }
1754
1755 //------------------------------------------------------------------------------------------------
1756 override bool SerializationLoad(LoadContext context)
1757 {
1758 if (!super.SerializationLoad(context))
1759 return false;
1760
1761 if (!context.Read(m_aActionsOnSpawnPointUsed) && !context.CanSeekMembers())
1762 return false;
1763 return true;
1764 }
1765}
1766
1767class SCR_ScenarioFrameworkPluginOnInventoryChangeSave : SCR_ScenarioFrameworkPluginSave
1768{
1769 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnItemAdded = {};
1770 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnItemRemoved = {};
1771
1772 //------------------------------------------------------------------------------------------------
1773 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkLayerBase layer, const SCR_ScenarioFrameworkPlugin plugin)
1774 {
1775 super.Read(persistence, layer, plugin);
1776
1777 const SCR_ScenarioFrameworkPluginOnInventoryChange inventoryChangePlugin = SCR_ScenarioFrameworkPluginOnInventoryChange.Cast(plugin);
1778 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, inventoryChangePlugin.m_aActionsOnItemAdded, m_aActionsOnItemAdded);
1779 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, inventoryChangePlugin.m_aActionsOnItemRemoved, m_aActionsOnItemRemoved);
1780 }
1781
1782 //------------------------------------------------------------------------------------------------
1783 override bool IsDefault()
1784 {
1785 return
1786 super.IsDefault() &&
1787 m_aActionsOnItemAdded.IsEmpty() &&
1788 m_aActionsOnItemRemoved.IsEmpty();
1789 }
1790
1791 //------------------------------------------------------------------------------------------------
1792 override SCR_ScenarioFrameworkPlugin Write(
1793 PersistenceSystem persistence,
1794 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1796 array<ref SCR_ScenarioFrameworkPlugin> plugins)
1797 {
1798 SCR_ScenarioFrameworkPluginOnInventoryChange inventoryChangePlugin = SCR_ScenarioFrameworkPluginOnInventoryChange.Cast(super.Write(persistence, scenarioFrameworkSystem, layer, plugins));
1799 if (inventoryChangePlugin)
1800 {
1801 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnItemAdded, inventoryChangePlugin.m_aActionsOnItemAdded);
1802 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnItemRemoved, inventoryChangePlugin.m_aActionsOnItemRemoved);
1803 }
1804 return inventoryChangePlugin;
1805 }
1806
1807 //------------------------------------------------------------------------------------------------
1808 override bool SerializationSave(SaveContext context)
1809 {
1810 if (!super.SerializationSave(context))
1811 return false;
1812
1813 if (!context.CanSeekMembers() || !m_aActionsOnItemAdded.IsEmpty())
1814 context.Write(m_aActionsOnItemAdded);
1815
1816 if (!context.CanSeekMembers() || !m_aActionsOnItemRemoved.IsEmpty())
1817 context.Write(m_aActionsOnItemRemoved);
1818
1819 return true;
1820 }
1821
1822 //------------------------------------------------------------------------------------------------
1823 override bool SerializationLoad(LoadContext context)
1824 {
1825 if (!super.SerializationLoad(context))
1826 return false;
1827
1828 if (!context.Read(m_aActionsOnItemAdded) && !context.CanSeekMembers())
1829 return false;
1830
1831 if (!context.Read(m_aActionsOnItemRemoved) && !context.CanSeekMembers())
1832 return false;
1833
1834 return true;
1835 }
1836}
1837
1839{
1840 ref array<ref SCR_ScenarioFrameworkActionSave> m_aActionsOnDestroy = {};
1841
1842 //------------------------------------------------------------------------------------------------
1843 override void Read(const PersistenceSystem persistence, const SCR_ScenarioFrameworkLayerBase layer, const SCR_ScenarioFrameworkPlugin plugin)
1844 {
1845 super.Read(persistence, layer, plugin);
1846
1848 SCR_ScenarioFrameworkActionSave.ReadActions(persistence, destroyEventPlugin.m_aActionsOnDestroy, m_aActionsOnDestroy);
1849 }
1850
1851 //------------------------------------------------------------------------------------------------
1852 override bool IsDefault()
1853 {
1854 return super.IsDefault() && m_aActionsOnDestroy.IsEmpty();
1855 }
1856
1857 //------------------------------------------------------------------------------------------------
1859 PersistenceSystem persistence,
1860 SCR_ScenarioFrameworkSystem scenarioFrameworkSystem,
1862 array<ref SCR_ScenarioFrameworkPlugin> plugins)
1863 {
1864 SCR_ScenarioFrameworkPluginOnDestroyEvent destroyEventPlugin = SCR_ScenarioFrameworkPluginOnDestroyEvent.Cast(super.Write(persistence, scenarioFrameworkSystem, layer, plugins));
1865 if (destroyEventPlugin)
1866 {
1867 SCR_ScenarioFrameworkActionSave.WriteActions(persistence, scenarioFrameworkSystem, m_aActionsOnDestroy, destroyEventPlugin.m_aActionsOnDestroy);
1868 }
1869 return destroyEventPlugin;
1870 }
1871
1872 //------------------------------------------------------------------------------------------------
1873 override bool SerializationSave(SaveContext context)
1874 {
1875 if (!super.SerializationSave(context))
1876 return false;
1877
1878 if (!context.CanSeekMembers() || !m_aActionsOnDestroy.IsEmpty())
1879 context.Write(m_aActionsOnDestroy);
1880
1881 return true;
1882 }
1883
1884 //------------------------------------------------------------------------------------------------
1885 override bool SerializationLoad(LoadContext context)
1886 {
1887 if (!super.SerializationLoad(context))
1888 return false;
1889
1890 if (!context.Read(m_aActionsOnDestroy) && !context.CanSeekMembers())
1891 return false;
1892 return true;
1893 }
1894}
class SCR_PersistentThreatSector GetTargetType()
EGameOverTypes
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
LocalizedString m_sName
SCR_EScenarioFrameworkSpawnChildrenType
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_ScenarioFrameworkSlotBase(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_ScenarioFrameworkSlotWaypoint(IEntityComponentSource src, IEntity ent, IEntity parent)
ref array< UUID > m_aUserEntitiyIds
ref array< ref SCR_ScenarioFrameworkActionSave > m_aTriggerActions
ref array< UUID > m_aMiscEntities
class SCR_ScenarioFrameworkActionSave m_iTimeRemaining
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnCancelled
void StoreAreaStates(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, out array< ref SCR_ScenarioFrameworkAreaSave > saves)
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnCreated
SCR_ScenarioFrameworkSlotAISave m_aActionsOnFinished
ref array< ref SCR_ScenarioFrameworkActionSave > m_aFinishedActions
SCR_ScenarioFrameworkLayerTaskDefendSave m_sRandomlySpawnedObject
class SCR_ScenarioFrameworkLogicSave m_iCounterValue
class SCR_ScenarioFrameworkPluginSave m_aEntityEnteredActions
class SCR_ScenarioFrameworkLayerTaskSaveLoadContext m_bTaskActive
override bool IsDefault()
ref array< ref SCR_ScenarioFrameworkActionSave > m_aEntityLeftActions
SCR_ScenarioFrameworkActionLimiterSave m_sActionHolderId
void LoadAreaStates(PersistenceSystem persistence, SCR_ScenarioFrameworkSystem scenarioFrameworkSystem, array< ref SCR_ScenarioFrameworkAreaSave > saves)
class SCR_ScenarioFrameworkLayerSave m_bAreaSelected
ref array< ref SCR_ScenarioFrameworkActionSave > m_aTriggerActionsOnFinish
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnItemRemoved
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnAssigned
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnFailed
override bool SerializationLoad(LoadContext context)
ref array< ref SCR_ScenarioFrameworkActionSave > m_aActionsOnProgress
SCR_ScenarioFrameworkPluginSpawnPointSave m_aActionsOnItemAdded
override bool SerializationSave(SaveContext context)
proto bool Write(void value_out)
proto bool Read(void value_in)
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
override bool SerializationSave(SaveContext context)
static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
override bool SerializationLoad(LoadContext context)
static void OnGroupAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
Dummy state proxy to access scenario framework system instance.
static ScriptCallQueue GetCallQueuePausable()
static SCR_ScenarioFrameworkSystem GetInstance()
ref array< SCR_ScenarioFrameworkArea > m_aAreas
ref map< string, string > m_mVariableMap
bool Deserialize(notnull Managed instance, notnull LoadContext context)
ESerializeResult Serialize(notnull Managed instance, notnull SaveContext context)
Definition UUID.c:28
ESerializeResult
void Tuple1(T1 p1)
Definition tuple.c:37