Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignMilitaryBaseComponentSerializer.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
4 override static typename GetTargetType()
5 {
7 }
8
9 //------------------------------------------------------------------------------------------------
10 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
11 {
13
14 const bool isHQ = militaryBase.IsHQ();
15 const UUID buildingId = GetSystem().GetId(militaryBase.GetBaseBuildingComposition());
16 const int callsign = militaryBase.GetCallsign();
17 const bool builtByPlayers = militaryBase.GetBuiltByPlayers();
18 const FactionKey builtFaction = militaryBase.GetBuiltFaction();
19
20 if (!isHQ && buildingId.IsNull() && callsign == SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN && !builtByPlayers && builtFaction.IsEmpty())
21 return ESerializeResult.DEFAULT;
22
23 context.WriteValue("version", 1);
24 context.WriteDefault(isHQ, false);
25 context.WriteDefault(buildingId, UUID.NULL_UUID);
26 context.WriteDefault(callsign, SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN);
27 context.WriteDefault(builtByPlayers, false);
28 context.WriteDefault(builtFaction, FactionKey.Empty);
29
30 return ESerializeResult.OK;
31 }
32
33 //------------------------------------------------------------------------------------------------
34 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
35 {
37
38 int version;
39 context.Read(version);
40
41 bool isHQ;
42 if (context.Read(isHQ))
43 militaryBase.SetAsHQ(isHQ);
44
45 UUID buildingId;
46 if (context.Read(buildingId) && !buildingId.IsNull())
47 {
50 GetSystem().WhenAvailable(buildingId, task);
51 }
52
53 int callsign;
54 context.Read(callsign);
55 militaryBase.SetCallsignIndex(callsign);
56
57 bool builtByPlayers;
58 if (context.Read(builtByPlayers))
59 militaryBase.SetBuiltByPlayers(builtByPlayers);
60
61 FactionKey builtFaction;
62 if (context.Read(builtFaction))
63 {
64 const Faction faction = GetGame().GetFactionManager().GetFactionByKey(builtFaction);
65 if (faction)
66 militaryBase.SetBuiltFaction(faction);
67 }
68
69 militaryBase.Initialize();
70
71 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
72 if (campaign)
73 campaign.GetBaseManager().UpdateBases();
74
75 return true;
76 }
77
78 //------------------------------------------------------------------------------------------------
79 protected static void OnBuildingAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
80 {
81 auto building = IEntity.Cast(instance);
82 if (!building)
83 return;
84
85 auto ctx = Tuple1<SCR_CampaignMilitaryBaseComponent>.Cast(context);
86 if (ctx.param1)
87 ctx.param1.SetBaseBuildingComposition(building);
88 }
89}
class SCR_PersistentThreatSector GetTargetType()
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
static void OnBuildingAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
Definition UUID.c:28
ESerializeResult
void Tuple1(T1 p1)
Definition tuple.c:37